From patchwork Wed Jan 17 16:00:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 862343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::239; helo=mail-wm0-x239.google.com; envelope-from=swupdate+bncbcxploxj6ikrbn7g7xjakgqemp6pb6y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="gBhxzsu5"; dkim-atps=neutral Received: from mail-wm0-x239.google.com (mail-wm0-x239.google.com [IPv6:2a00:1450:400c:c09::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zMBdk2Rzlz9s7G for ; Thu, 18 Jan 2018 03:00:58 +1100 (AEDT) Received: by mail-wm0-x239.google.com with SMTP id z83sf4212020wmc.5 for ; Wed, 17 Jan 2018 08:00:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516204855; cv=pass; d=google.com; s=arc-20160816; b=wPRYMvbFUO73f1xjLiS+dd4CONnlpnpiSXYAaIFMy/DCDW+PctNBq9xkQZdfYmVBXk bQd5c3A36fuTzgq5r27YO1z0wS2gW4CE9BdJpU5+TYDV+eFuVZGXt4Fe8nfKrBlDEaSl EhmpsO0J3ehrXMl2a0ymo+ILvqIXcc35gEUkOzC+HEfCCK0r33caZV5sNER28lkJ22Ty 7WSDP5h0mNFpAEn7b+NDqZuVTKF+BCyqG8Ze7NpXN5RTNQXZF4ZTOzejGHZqAFM3SzMv QRJhBc91fg6E+DyVq4jLwvnXZCuL0bXgpzxdznBrV16/Qphhsy6fKJfxscI55hb75UDP PjQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=zJlmTKFZI3VjQikLmuRpsZ7QkVExYtSkHez3DWmeTRs=; b=wzjDg9JRTKGtyYR4W2G2BPGmtJKch0svJrFctZdA+7TlS7tfz+Wm3pCQTcqJ2BHHib aCSqPwCOy8il8lMnbWduasSxAunpQJsgodiJE6d/f5HAq5JRSRI1yURjBvMyK15jOId0 9NJ50m0cRjjyaG8AX2wJRXeicUnkcNxHDgGqufc/79cJaEb4p+6309OCUrM9BDqAnkB6 U26SlNdyA6oROqA/q1A/au9S1I7Rd9kbBrCQwZbwx+eBn3RjmAMTgwrbyD5ALc4NROH8 HZ9/xGkH5t2Glk9gQIeYtellJPxdbEu5qQJNM18zUNbYZkwk69uFyZX2JedPhDOTyCw0 SJLg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=zJlmTKFZI3VjQikLmuRpsZ7QkVExYtSkHez3DWmeTRs=; b=gBhxzsu5qf8qpP/mbzXQYYR/X4gWPq7eSPgsIkgih+25JYrUT9I+yP8bo/3CWCBibq /38eNQlyFp6iByEfNZWctrFd/nqKBOiU+jZWFbv5x3ZPhiblvfhfiCXN2eK3ht369AK1 Chh0J5k2LjED34yIDHW+GheunNihf6Oys/STBhZe2r2Q6fewcOUvLNJihmbZWh//8lPE WxaNRnRuFEylbQ27z7zt+1pjJpuOcgFYgDKXUTq08ItTnKbdV24gAWqqRTp8dRljW2uO BOp/DVlHEX+zW/A7cnndDdTbe3by3zOZ2c7Z9MOFygvtjmZl+q00ZEZ14gyFQlIia+qA HSPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=zJlmTKFZI3VjQikLmuRpsZ7QkVExYtSkHez3DWmeTRs=; b=GMj9WRlZl6eSeiWqrhhT95stc7AcwSaKefX7joaQPoXTJJreVBkWi9jooaTO9dT478 evmQloHU7WZuRCpqdKZdXKRe4hSggkWlWSg0qLpkwpQFDZ+l+1QVJNOreLB0gunP5Bfb bfHxH4V20/9FYrZGcG9yFJRiiyNpxlDH5r8TveG5ZLztxqvhKFcDTMvP79O8vd5Fpxzb PydLYL/KGTzhdclXTSQE+m0wAB0W4tadd25hKsSZTasOR8KtR3CPNmXTHkSTUjPTrqIE CcwbTBdQbAg1VVP5odUtv0m1M6lYGFaHzjNBMvJ5mTdafRdupQe1v1AKvX7vKAUqYgn1 2rnw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytezm+7f06sXW6EH52PQQTQ+Bqgu68I1rNmxqWUmp8SHOEpWRFgc fSeP+4q4v6z5CjS6p9TMcwA= X-Google-Smtp-Source: ACJfBouD3n9Cr1Bzz2O7ZtJz+8yqiHc1w7TfnlBbABmuVxdfhnVRtdQaOXflP18uaw2FcN5D+JcEyg== X-Received: by 10.28.216.209 with SMTP id p200mr38013wmg.2.1516204855707; Wed, 17 Jan 2018 08:00:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.139.199 with SMTP id w7ls1753682wra.5.gmail; Wed, 17 Jan 2018 08:00:55 -0800 (PST) X-Received: by 10.223.195.204 with SMTP id d12mr374212wrg.0.1516204855240; Wed, 17 Jan 2018 08:00:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516204855; cv=none; d=google.com; s=arc-20160816; b=QQkvZdI5wSzz4TerQoxSZgYUoLNvO2YiYMCBisBioNSCexu1qb4naRXwPbxPvNBShH 6CePy4wa5IIx3YTrpVsdUeS/Sv6T29tEXBfqqtZnYUQyPEPcz2KkNBm1HWd9PXGthZue 95VhujWkZg2OAZfGtlsj6BI13g3YrRMeqYxZp06tgZzbpAP+moQa6+nabsQLmcRRV6RQ yOIFscB3swSTjtBA4O2KLJgmMQ0TojJothjkYWHVIB7ArWauGuirTHNLARxr7571CwzF iQ+qhJD+TXrGcgtYCACuiCjqU3qU1BPZ5u/+dxMDsmrmdD6r4a8XoDItk0woX8VCNXsB gv5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=lzdlJg+plKGo99QO5CL7Yj71+VHrcIh1+rj6Zq4mXJs=; b=Oy4FqXsrbwCR1ldxMSeshIBZr1vK+3leW2rOQ+1SZhXbk3qrDL1QKbQfwBZ0NQzijy 6vftVdsj9PqEUaaN7+QRjVGe+gaRh2TkAUb/G+N2V0RgzOlCkrE3tdo5JC7SOvWiMh3p 7pu8cp+N/t5AhX6PsHzkgfCqNmjwlprjiG9S1voP1ArDOLVBr4cmFoTs9exBAGe/9WcX Dj/82r0Amb4QNSGKu2InSwRzG8w8zblt1ekZglNPVoyvmJWRD2oMGAi3WT5DE+tMSAjU 4ujKHLcPirwmv3SIaPj+nTYJ1E1FWE9u8tV1Huw+yOjevxHm368xLqM+awP/RzgbW9H3 8yFw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id i75si318853wmg.1.2018.01.17.08.00.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 08:00:55 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3zMBdg05qFz1qtPB; Wed, 17 Jan 2018 17:00:55 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3zMBdf70C5z1svMQ; Wed, 17 Jan 2018 17:00:54 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id uXlic4iuAZWK; Wed, 17 Jan 2018 17:00:54 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Wed, 17 Jan 2018 17:00:54 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 91B9B454062C; Wed, 17 Jan 2018 17:00:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id As4rf3x6lyET; Wed, 17 Jan 2018 17:00:51 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 08657454062D; Wed, 17 Jan 2018 17:00:50 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/4] parser: factorize parsing of common attributes Date: Wed, 17 Jan 2018 17:00:45 +0100 Message-Id: <1516204847-24082-2-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516204847-24082-1-git-send-email-sbabic@denx.de> References: <1516204847-24082-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Stefano Babic --- parser/parser.c | 125 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/parser/parser.c b/parser/parser.c index 0f3eed3..0b190b8 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -229,6 +229,51 @@ static int run_embscript(parsertype p, void *elem, struct img_type *img, return lua_parser_fn(L, embfcn, img); } +static int parse_common_attributes(parsertype p, void *elem, struct img_type *image) +{ + char seek_str[MAX_SEEK_STRING_SIZE]; + char *endp = NULL; + + /* + * GET_FIELD_STRING does not touch the passed string if it is not + * found, be sure that it is empty + */ + seek_str[0] = '\0'; + + GET_FIELD_STRING(p, elem, "name", image->id.name); + GET_FIELD_STRING(p, elem, "version", image->id.version); + GET_FIELD_STRING(p, elem, "filename", image->fname); + GET_FIELD_STRING(p, elem, "path", image->path); + GET_FIELD_STRING(p, elem, "volume", image->volname); + GET_FIELD_STRING(p, elem, "device", image->device); + GET_FIELD_STRING(p, elem, "mtdname", image->path); + GET_FIELD_STRING(p, elem, "filesystem", image->filesystem); + GET_FIELD_STRING(p, elem, "type", image->type); + GET_FIELD_STRING(p, elem, "offset", seek_str); + GET_FIELD_STRING(p, elem, "data", image->type_data); + get_hash_value(p, elem, image->sha256); + + /* convert the offset handling multiplicative suffixes */ + if (strnlen(seek_str, MAX_SEEK_STRING_SIZE) != 0) { + errno = 0; + image->seek = ustrtoull(seek_str, &endp, 0); + if (seek_str == endp || (image->seek == ULLONG_MAX && \ + errno == ERANGE)) { + ERROR("offset argument: ustrtoull failed"); + return -1; + } + } else + image->seek = 0; + + get_field(p, elem, "compressed", &image->compressed); + get_field(p, elem, "installed-directly", &image->install_directly); + get_field(p, elem, "preserve-attributes", &image->preserve_attributes); + get_field(p, elem, "install-if-different", &image->id.install_if_different); + get_field(p, elem, "encrypted", &image->is_encrypted); + + return 0; +} + static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg) { void *setting, *elem; @@ -317,12 +362,10 @@ static int parse_scripts(parsertype p, void *cfg, struct swupdate_cfg *swcfg) return -ENOMEM; } - GET_FIELD_STRING(p, elem, "filename", script->fname); - GET_FIELD_STRING(p, elem, "type", script->type); - GET_FIELD_STRING(p, elem, "data", script->type_data); - get_hash_value(p, elem, script->sha256); - - get_field(p, elem, "encrypted", &script->is_encrypted); + if (parse_common_attributes(p, elem, script) < 0) { + free(script); + return -1; + } /* Scripts as default call the Lua interpreter */ if (!strlen(script->type)) { @@ -390,12 +433,12 @@ static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg) ERROR( "No memory: malloc failed\n"); return -ENOMEM; } - GET_FIELD_STRING(p, elem, "filename", script->fname); - GET_FIELD_STRING(p, elem, "type", script->type); - GET_FIELD_STRING(p, elem, "data", script->type_data); - get_hash_value(p, elem, script->sha256); - get_field(p, elem, "encrypted", &script->is_encrypted); - get_field(p, elem, "compressed", &script->compressed); + + if (parse_common_attributes(p, elem, script) < 0) { + free(script); + return -1; + } + script->is_script = 1; LIST_INSERT_HEAD(&swcfg->bootscripts, script, next); @@ -412,8 +455,6 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua void *setting, *elem; int count, i; struct img_type *image; - char seek_str[MAX_SEEK_STRING_SIZE]; - char *endp = NULL; setting = find_node(p, cfg, "images", swcfg); @@ -442,35 +483,10 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua return -ENOMEM; } - /* - * GET_FIELD_STRING does not touch the passed string if it is not - * found, be sure that it is empty - */ - seek_str[0] = '\0'; - - GET_FIELD_STRING(p, elem, "name", image->id.name); - GET_FIELD_STRING(p, elem, "version", image->id.version); - GET_FIELD_STRING(p, elem, "filename", image->fname); - GET_FIELD_STRING(p, elem, "volume", image->volname); - GET_FIELD_STRING(p, elem, "device", image->device); - GET_FIELD_STRING(p, elem, "mtdname", image->path); - GET_FIELD_STRING(p, elem, "type", image->type); - GET_FIELD_STRING(p, elem, "offset", seek_str); - GET_FIELD_STRING(p, elem, "data", image->type_data); - get_hash_value(p, elem, image->sha256); - - /* convert the offset handling multiplicative suffixes */ - if (strnlen(seek_str, MAX_SEEK_STRING_SIZE) != 0) { - errno = 0; - image->seek = ustrtoull(seek_str, &endp, 0); - if (seek_str == endp || (image->seek == ULLONG_MAX && \ - errno == ERANGE)) { - ERROR("offset argument: ustrtoull failed"); - free(image); - return -1; - } - } else - image->seek = 0; + if (parse_common_attributes(p, elem, image) < 0) { + free(image); + return -1; + } /* if the handler is not explicit set, try to find the right one */ if (!strlen(image->type)) { @@ -480,11 +496,6 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua strcpy(image->type, "raw"); } - get_field(p, elem, "compressed", &image->compressed); - get_field(p, elem, "installed-directly", &image->install_directly); - get_field(p, elem, "install-if-different", &image->id.install_if_different); - get_field(p, elem, "encrypted", &image->is_encrypted); - add_properties(p, elem, image); if (run_embscript(p, elem, image, L, swcfg->embscript)) { @@ -546,24 +557,14 @@ static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_ return -ENOMEM; } - GET_FIELD_STRING(p, elem, "name", file->id.name); - GET_FIELD_STRING(p, elem, "version", file->id.version); - GET_FIELD_STRING(p, elem, "filename", file->fname); - GET_FIELD_STRING(p, elem, "path", file->path); - GET_FIELD_STRING(p, elem, "device", file->device); - GET_FIELD_STRING(p, elem, "filesystem", file->filesystem); - GET_FIELD_STRING(p, elem, "type", file->type); - GET_FIELD_STRING(p, elem, "data", file->type_data); - get_hash_value(p, elem, file->sha256); + if (parse_common_attributes(p, elem, file) < 0) { + free(file); + return -1; + } if (!strlen(file->type)) { strcpy(file->type, "rawfile"); } - get_field(p, elem, "compressed", &file->compressed); - get_field(p, elem, "preserve-attributes", &file->preserve_attributes); - get_field(p, elem, "installed-directly", &file->install_directly); - get_field(p, elem, "install-if-different", &file->id.install_if_different); - get_field(p, elem, "encrypted", &file->is_encrypted); add_properties(p, elem, file);