Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2224589/?format=api
{ "id": 2224589, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2224589/?format=api", "web_url": "http://patchwork.ozlabs.org/project/swupdate/patch/20260417155704.2758672-4-hyyoxhk@163.com/", "project": { "id": 58, "url": "http://patchwork.ozlabs.org/api/1.2/projects/58/?format=api", "name": "swupdate development", "link_name": "swupdate", "list_id": "swupdate.googlegroups.com", "list_email": "swupdate@googlegroups.com", "web_url": "https://github.com/sbabic/swupdate", "scm_url": "git://github.com/sbabic/swupdate", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260417155704.2758672-4-hyyoxhk@163.com>", "list_archive_url": null, "date": "2026-04-17T15:57:03", "name": "[v1,3/4] corelib: refactor Lua image attribute parsing", "commit_ref": null, "pull_url": null, "state": "not-applicable", "archived": false, "hash": "ffb88059704ba3e3a8e045f477c65dcc096506b6", "submitter": { "id": 79707, "url": "http://patchwork.ozlabs.org/api/1.2/people/79707/?format=api", "name": "He Yong", "email": "hyyoxhk@163.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/swupdate/patch/20260417155704.2758672-4-hyyoxhk@163.com/mbox/", "series": [ { "id": 500374, "url": "http://patchwork.ozlabs.org/api/1.2/series/500374/?format=api", "web_url": "http://patchwork.ozlabs.org/project/swupdate/list/?series=500374", "date": "2026-04-17T15:57:01", "name": "Refactor image parsing and add LZ4 support", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/500374/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2224589/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2224589/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<swupdate+bncBAABB4OGRHHQMGQEILHTFNY@googlegroups.com>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=googlegroups.com header.i=@googlegroups.com\n header.a=rsa-sha256 header.s=20251104 header.b=n9l7j8I5;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com\n (client-ip=2607:f8b0:4864:20::840; helo=mail-qt1-x840.google.com;\n envelope-from=swupdate+bncbaabb4ogrhhqmgqeilhtfny@googlegroups.com;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from mail-qt1-x840.google.com (mail-qt1-x840.google.com\n [IPv6:2607:f8b0:4864:20::840])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fy1213V80z1yJ8\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 02:44:41 +1000 (AEST)", "by mail-qt1-x840.google.com with SMTP id\n d75a77b69052e-50e160d5fd3sf21558981cf.1\n for <incoming@patchwork.ozlabs.org>;\n Fri, 17 Apr 2026 09:44:41 -0700 (PDT)", "by 2002:ac8:5f0f:0:b0:50b:3cb6:163a with SMTP id\n d75a77b69052e-50e254f13f6ls33063951cf.0.-pod-prod-05-us;\n Fri, 17 Apr 2026 09:44:33 -0700 (PDT)", "by 2002:a05:620a:a0dc:20b0:8b2:e5d4:9264 with SMTP id\n af79cd13be357-8e659d6f840ms85a;\n Fri, 17 Apr 2026 08:57:12 -0700 (PDT)", "from m16.mail.163.com (m16.mail.163.com. [117.135.210.4])\n by gmr-mx.google.com with ESMTPS id\n a1e0cc1a2514c-95890b89c4fsi75137241.3.2026.04.17.08.57.10\n for <swupdate@googlegroups.com>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 17 Apr 2026 08:57:12 -0700 (PDT)", "from nh50.. (unknown [])\n\tby gzga-smtp-mtada-g0-1 (Coremail) with SMTP id\n _____wAXpIlQWOJpw1HjAA--.43368S5;\n\tFri, 17 Apr 2026 23:57:05 +0800 (CST)" ], "ARC-Seal": [ "i=2; a=rsa-sha256; t=1776444274; cv=pass;\n d=google.com; s=arc-20240605;\n b=gmERUJUSBhK56MWQMElZT5pJUV5OIDWPv/+pjxKFO0xnFoxesPtdXJsiial9CxjbSS\n FiQAh5BHn6H8Ixoyishe9gl81UkGnv7oJBmXYMyF4lnbjWX0LPmsOL5H7YwyjIG+GkoP\n dwJB0j3kesscqkQ5uTqp2b7IuRvEbTHpPVzbQhmPQUwxj9KK4TXqanlKMFoT+kP4lZ6n\n ELUtXFSOvlLO+ySLTy9C+PQbdwyYQqKbiTuGKlORG6oMW3DxOQt/8D/nZwF/3fTBPv99\n cr4uRSyX/g+yG6Cqozj8GAdTZ7R7OsW++Veurmz19EACmP9GjHsGrpR8kLX6wPRNsA1M\n ri0Q==", "i=1; a=rsa-sha256; t=1776441432; cv=none;\n d=google.com; s=arc-20240605;\n b=A7MP2DWaPGyIerj5+GGbTiNAiMUiNRhA03pRYksh4vLW9ZYWlwLi96MEUd2ELb7lWK\n 9SVaivsatZI1MUZyNCWbkZCuwn3bkjUvGONoobDPZd0BsMgSXJ0W0Ay7HQYrWXtbCeDJ\n B4rmlqMu3GK4B03G6v3WwgsODAKzlJ2/XPYuqM0kYO1Yl9cRdEiyZFYseOpGd6jRKB5I\n 4WJ1PG9oyLS2dA1mm40if1xM2DND8P8Vn7lGUJjLZIJ8qCnzKduUwqGOodD29PweWHEz\n zyHtx4VAflL6XrQVxO2o2nIrxfEf2siqxUZQsnpzMRi3GnXnrKHL7OOBWvnGDlsqnO3b\n hChw==" ], "ARC-Message-Signature": [ "i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :list-id:mailing-list:precedence:mime-version:references:in-reply-to\n :message-id:date:subject:to:from:sender:dkim-signature;\n bh=7DJChULGfAyqTiucv7N+ZoDCMHipXrySgLOyvXPUSes=;\n fh=9wf6vMhymlIxpeVqEDjkCgFGfD+XEIXlk+gXHWyRoSA=;\n b=CjYMEC8YaAT44gkiTlZktCWK3RbFjuvV33oPFOlPuy3m/8wntXNKTasNiVfB6vxnY5\n vLoynGncPicxJWmGVpuC2ThDOHmX5gBcSIlLLIriAPwWh5xy9sB0Qyl0TQIeu/IkHqOi\n qZRdgeG2ndPJwx+3KLYqlkvWDDSCzg8RgxZ0iLgZJxFfztm8Us8v9btwXz2tdlQy7dd/\n eUdCPFyU0Nx0FzMniaIBh/yIGhAAN285khtamQYTwhvu3fupEcbfF5MoXqJsLCfcRXXm\n QZyxCxXFeAQuNnKnKBizKUbZkw58F6kkCpyks8m1AlxTiOzNN3p76WrUMbPhhD/HOf+b\n fcvg==;\n darn=patchwork.ozlabs.org", "i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:to:from:dkim-signature;\n bh=w90eoyBVpYWAwt4sySRVcyg5wH9ByCOTu/ZFmg9722U=;\n fh=nvZsCFpxgpf+fsVXzjnWA8g1K3V/kNbRAKogjNDW4HY=;\n b=lw+S/G2Rli9cYFD8D1Zl5Fr4KfNsOgQUuby03aPcGB30ybHELah+43BVd7XKhPgt8Y\n bxtPsdH+7U1zuVJe22OnNR6StWBaQXz+LtnfJRatooD4sGhM55brP+XREq8o4XNEK9QD\n 8t9zTxoazU0rnhVX5bYOwRINgMwA+ByvxtHa9yn2HmALFGzPtYP+ICsaytgnU92UuGqw\n u8i4eX12lWsGwPQKqLvwfazV+3Wa8XQFVdxPPnC7uatZv+Phfe+03T8kRTMhBAZ1EYj1\n f51wLIc3F7/JwZm4RzHDaU+4uJIm/IYwIwogEOdKza3Qcv5D79sDPA0QXV8Lw/MhhgH2\n 48oA==;\n dara=google.com" ], "ARC-Authentication-Results": [ "i=2; gmr-mx.google.com;\n dkim=pass header.i=@163.com header.s=s110527 header.b=\"d2DR9/NH\";\n spf=pass (google.com: domain of hyyoxhk@163.com designates\n 117.135.210.4 as permitted sender) smtp.mailfrom=hyyoxhk@163.com;\n dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com", "i=1; gmr-mx.google.com;\n dkim=pass header.i=@163.com header.s=s110527 header.b=\"d2DR9/NH\";\n spf=pass (google.com: domain of hyyoxhk@163.com designates\n 117.135.210.4 as permitted sender) smtp.mailfrom=hyyoxhk@163.com;\n dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=googlegroups.com; s=20251104; t=1776444274; x=1777049074;\n darn=patchwork.ozlabs.org;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :list-id:mailing-list:precedence:x-original-authentication-results\n :x-original-sender:mime-version:references:in-reply-to:message-id\n :date:subject:to:from:sender:from:to:cc:subject:date:message-id\n :reply-to;\n bh=7DJChULGfAyqTiucv7N+ZoDCMHipXrySgLOyvXPUSes=;\n b=n9l7j8I5GVbUS3xS95pH0uepGGw6FbcH4rnvB70FT3c2o0mstWk2bN8QEFQunHKP0W\n 120lKQ2S49q9s3fKpXuCAbCB+0X9yxBqa6nNqIbS53Lr56hoorFZ12SDxX66Mh/Moir4\n wS2d/vBk5o6lhn8EvHK4uJP/CQSLCBZ7koBpDkpKmotT5cg8PpWGyWJEqnnD7FDeBl3Q\n ak9ogWitnlyj3YCDQPPIuqVZbrJmDtL1rx8fbTMtpoQIyWQ/sE/CiiLSYfGHSk/Gli8N\n NuHTylJsh0av6D1RSFvGdrt/9wej2wIHTFMWxs1n6pBGejoCEY+wAkL5+scVMwCOznrf\n qDvA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776444274; x=1777049074;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :list-id:mailing-list:precedence:x-original-authentication-results\n :x-original-sender:mime-version:references:in-reply-to:message-id\n :date:subject:to:from:x-beenthere:x-gm-message-state:sender:from:to\n :cc:subject:date:message-id:reply-to;\n bh=7DJChULGfAyqTiucv7N+ZoDCMHipXrySgLOyvXPUSes=;\n b=CCqQx9gBJ43ei9o/ukoVPpZG/KjoWesLaE4W3htH2Ur3pCGOJ1JpAgJifUSEoGnqfd\n 0BODVAugbr8S+MWpvf6EDzyZ3KaWsQcn1DczM4BaPLRO8W8VZyKRNnmBWG544WJcAazD\n sd0Qthj/YHdyPfW4G1IzCA9bWJa1uTcj8twO4QQY45pai6/3sLDlEG6fL/onYu2FZYxr\n HS8iPbPOEtY5NZEu1/4bDdL/Mt+RiCz3kikdacH7DHmCdayuYszAwMW1cLxevi6I8pu9\n yNLV1dnTPLQ8B19j+xOOUQ+mZoVQ1su6D0XmFnOO+tAcfCOWNJyF1voISiDccqIKawPo\n ilbQ==", "Sender": "swupdate@googlegroups.com", "X-Forwarded-Encrypted": "i=2;\n AFNElJ9bJiNKF4opEyJ/OwFxnAn1HBwLDSivBKH/Mob407vjg16upm3rIs9FNLnXrugSXcpDgYo+od11xQ==@patchwork.ozlabs.org", "X-Gm-Message-State": "AOJu0YwsW+Y6YsULjsFIFjjbAmnPi43LULlrRuN/+KaRagbc7E9ShvQm\n\tvwDSQb7YxihLEX3csGN7zhTM4m1Kviic/+bNxiSIfmj3ond6GlOcjFnL", "X-Received": [ "by 2002:a05:622a:586:b0:50d:a898:a149 with SMTP id\n d75a77b69052e-50e36b7301amr51339681cf.16.1776444274454;\n Fri, 17 Apr 2026 09:44:34 -0700 (PDT)", "by 2002:a67:e703:0:b0:600:11e1:2a49 with SMTP id\n ada2fe7eead31-616f67c79d6mr1839652137.7.1776444272848;\n Fri, 17 Apr 2026 09:44:32 -0700 (PDT)", "by 2002:a05:6122:6e05:b0:559:5ef5:b196 with SMTP id\n 71dfb90a1353d-56fa5a22014mr1960644e0c.13.1776441432103;\n Fri, 17 Apr 2026 08:57:12 -0700 (PDT)" ], "X-BeenThere": "swupdate@googlegroups.com;\n h=\"AYAyTiLIoc2hDWi4H/Pr4/sezadNps1VH9fhzDfv83Yi0v8nlQ==\"", "Received-SPF": "pass (google.com: domain of hyyoxhk@163.com designates\n 117.135.210.4 as permitted sender) client-ip=117.135.210.4;", "From": "He Yong <hyyoxhk@163.com>", "To": "swupdate@googlegroups.com", "Subject": "[swupdate] [PATCH v1 3/4] corelib: refactor Lua image attribute\n parsing", "Date": "Fri, 17 Apr 2026 23:57:03 +0800", "Message-ID": "<20260417155704.2758672-4-hyyoxhk@163.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20260417155704.2758672-1-hyyoxhk@163.com>", "References": "<20260417155704.2758672-1-hyyoxhk@163.com>", "MIME-Version": "1.0", "X-CM-TRANSID": "_____wAXpIlQWOJpw1HjAA--.43368S5", "X-Coremail-Antispam": "1Uf129KBjvJXoW3GryUWF1fur18Ww1DuF1rZwb_yoWfuFWUpF\n\tZ5W34YkrWxJrs2ka9xAa1xWr18Wr1xGw1UGFn7Krn8Za13KryFqFy29rZIkFZrJFyv9rn8\n\turWjqry5WrW5tFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jrb1bUUUUU=", "X-Originating-IP": "[2408:8266:bb01:57f4:788f:a08d:bbc4:eabb]", "X-CM-SenderInfo": "pk1105lkn6il2tof0z/xtbC0BE9EGniWFEZkAAA3n", "X-Original-Sender": "hyyoxhk@163.com", "X-Original-Authentication-Results": "gmr-mx.google.com; dkim=pass\n header.i=@163.com header.s=s110527 header.b=\"d2DR9/NH\"; spf=pass\n (google.com: domain of hyyoxhk@163.com designates 117.135.210.4 as permitted\n sender) smtp.mailfrom=hyyoxhk@163.com; dmarc=pass (p=NONE sp=NONE\n dis=NONE) header.from=163.com", "Content-Type": "text/plain; charset=\"UTF-8\"", "Precedence": "list", "Mailing-list": "list swupdate@googlegroups.com;\n contact swupdate+owners@googlegroups.com", "List-ID": "<swupdate.googlegroups.com>", "X-Google-Group-Id": "605343134186", "List-Post": "<https://groups.google.com/group/swupdate/post>,\n <mailto:swupdate@googlegroups.com>", "List-Help": "<https://groups.google.com/support/>,\n <mailto:swupdate+help@googlegroups.com>", "List-Archive": "<https://groups.google.com/group/swupdate", "List-Subscribe": "<https://groups.google.com/group/swupdate/subscribe>,\n <mailto:swupdate+subscribe@googlegroups.com>", "List-Unsubscribe": "\n <mailto:googlegroups-manage+605343134186+unsubscribe@googlegroups.com>,\n <https://groups.google.com/group/swupdate/subscribe>" }, "content": "Lua image parsing currently relies on repeated key comparisons across\nstring, bool, and number handlers. This duplicates logic, scatters\nfield assignments, and makes new attributes error-prone to add.\n\nSwitch to table-driven key dispatch with dedicated setter helpers,\nreuse common setter macros for bounded copies and typed assignments,\nand keep conversion code centralized for better consistency and\nmaintainability.\n\nSigned-off-by: He Yong <hyyoxhk@163.com>\n---\n corelib/lua_interface.c | 218 ++++++++++++++++++++++++----------------\n 1 file changed, 131 insertions(+), 87 deletions(-)", "diff": "diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c\nindex 6543dff7..63703075 100644\n--- a/corelib/lua_interface.c\n+++ b/corelib/lua_interface.c\n@@ -267,116 +267,157 @@ int run_lua_script(lua_State *L, const char *script, bool load, const char *func\n \treturn ret;\n }\n \n+typedef void (*lua_img_string_handler_fn)(struct img_type *img, const char *value);\n+typedef void (*lua_img_bool_handler_fn)(struct img_type *img, bool val);\n+typedef void (*lua_img_number_handler_fn)(struct img_type *img, double val);\n+\n+struct lua_img_string_handler_entry {\n+\tconst char *key;\n+\tlua_img_string_handler_fn handler;\n+};\n+\n+struct lua_img_bool_handler_entry {\n+\tconst char *key;\n+\tlua_img_bool_handler_fn handler;\n+};\n+\n+struct lua_img_number_handler_entry {\n+\tconst char *key;\n+\tlua_img_number_handler_fn handler;\n+};\n+\n+static void lua_set_compressed_string(struct img_type *img, const char *value)\n+{\n+\tif (compressed_string_to_type(value, &img->compressed) < 0) {\n+\t\tERROR(\"compressed argument: '%s' invalid\", value);\n+\t\timg->compressed = COMPRESSED_FALSE;\n+\t}\n+}\n+\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_name, id.name)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_version, id.version)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_filename, fname)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_volume, volname)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_type, type)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_device, device)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_mtdname, mtdname)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_path, path)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_data, type_data)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_filesystem, filesystem)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_ivt, ivt_ascii)\n+DEFINE_IMG_STRLCPY_SETTER(lua_set_aes_key, aes_ascii)\n+\n+static void lua_set_sha256(struct img_type *img, const char *value)\n+{\n+\tascii_to_hash(img->sha256, value);\n+}\n+\n+static void lua_set_offset_string(struct img_type *img, const char *value)\n+{\n+\tchar seek_str[MAX_SEEK_STRING_SIZE];\n+\n+\tstrlcpy(seek_str, value, sizeof(seek_str));\n+\t/* convert the offset handling multiplicative suffixes */\n+\terrno = 0;\n+\timg->seek = ustrtoull(seek_str, NULL, 0);\n+\tif (errno) {\n+\t\tERROR(\"offset argument: ustrtoull failed\");\n+\t}\n+}\n+\n+static const struct lua_img_string_handler_entry lua_string_handlers[] = {\n+\t{ \"compressed\", lua_set_compressed_string },\n+\t{ \"name\", lua_set_name },\n+\t{ \"version\", lua_set_version },\n+\t{ \"filename\", lua_set_filename },\n+\t{ \"volume\", lua_set_volume },\n+\t{ \"type\", lua_set_type },\n+\t{ \"device\", lua_set_device },\n+\t{ \"mtdname\", lua_set_mtdname },\n+\t{ \"path\", lua_set_path },\n+\t{ \"data\", lua_set_data },\n+\t{ \"filesystem\", lua_set_filesystem },\n+\t{ \"sha256\", lua_set_sha256 },\n+\t{ \"ivt\", lua_set_ivt },\n+\t{ \"aes-key\", lua_set_aes_key },\n+\t{ \"offset\", lua_set_offset_string },\n+};\n+\n /**\n * @brief convert an image description struct to a lua table\n *\n * @param L [inout] the Lua stack\n * @param software [in] the software struct\n */\n-\n static void lua_string_to_img(struct img_type *img, const char *key,\n \t const char *value)\n {\n-\tconst char offset[] = \"offset\";\n-\tchar seek_str[MAX_SEEK_STRING_SIZE];\n+\tsize_t i;\n \n-\tif (!strcmp(key, \"compressed\")) {\n-\t\tif (!strcmp(value, \"zlib\")) {\n-\t\t\timg->compressed = COMPRESSED_ZLIB;\n-\t\t} else if (!strcmp(value, \"xz\")) {\n-\t\t\timg->compressed = COMPRESSED_XZ;\n-\t\t} else if (!strcmp(value, \"zstd\")) {\n-\t\t\timg->compressed = COMPRESSED_ZSTD;\n-\t\t} else {\n-\t\t\tERROR(\"compressed argument: '%s' invalid\", value);\n-\t\t\timg->compressed = COMPRESSED_FALSE;\n-\t\t}\n-\t}\n-\tif (!strcmp(key, \"name\")) {\n-\t\tstrncpy(img->id.name, value,\n-\t\t\tsizeof(img->id.name));\n-\t}\n-\tif (!strcmp(key, \"version\")) {\n-\t\tstrncpy(img->id.version, value,\n-\t\t\tsizeof(img->id.version));\n-\t}\n-\tif (!strcmp(key, \"filename\")) {\n-\t\tstrncpy(img->fname, value,\n-\t\t\tsizeof(img->fname));\n-\t}\n-\tif (!strcmp(key, \"volume\"))\n-\t\tstrncpy(img->volname, value,\n-\t\t\tsizeof(img->volname));\n-\tif (!strcmp(key, \"type\"))\n-\t\tstrncpy(img->type, value,\n-\t\t\tsizeof(img->type));\n-\tif (!strcmp(key, \"device\"))\n-\t\tstrncpy(img->device, value,\n-\t\t\tsizeof(img->device));\n-\tif (!strcmp(key, \"mtdname\"))\n-\t\tstrncpy(img->mtdname, value,\n-\t\t\tsizeof(img->mtdname));\n-\tif (!strcmp(key, \"path\"))\n-\t\tstrncpy(img->path, value,\n-\t\t\tsizeof(img->path));\n-\tif (!strcmp(key, \"data\"))\n-\t\tstrncpy(img->type_data, value,\n-\t\t\tsizeof(img->type_data));\n-\tif (!strcmp(key, \"filesystem\"))\n-\t\tstrncpy(img->filesystem, value,\n-\t\t\tsizeof(img->filesystem));\n-\tif (!strcmp(key, \"sha256\"))\n-\t\tascii_to_hash(img->sha256, value);\n-\tif (!strcmp(key, \"ivt\"))\n-\t\tstrncpy(img->ivt_ascii, value,\n-\t\t\tsizeof(img->ivt_ascii));\n-\tif (!strcmp(key, \"aes-key\"))\n-\t\tstrncpy(img->aes_ascii, value,\n-\t\t\tsizeof(img->aes_ascii));\n-\tif (!strncmp(key, offset, sizeof(offset))) {\n-\t\tstrncpy(seek_str, value,\n-\t\t\tsizeof(seek_str));\n-\t\t/* convert the offset handling multiplicative suffixes */\n-\t\timg->seek = ustrtoull(seek_str, NULL, 0);\n-\t\tif (errno){\n-\t\t\tERROR(\"offset argument: ustrtoull failed\");\n+\tfor (i = 0; i < ARRAY_SIZE(lua_string_handlers); i++) {\n+\t\tif (!strcmp(key, lua_string_handlers[i].key)) {\n+\t\t\tlua_string_handlers[i].handler(img, value);\n+\t\t\treturn;\n \t\t}\n \t}\n }\n \n+DEFINE_IMG_BOOL_SETTER(lua_set_compressed_bool, compressed)\n+DEFINE_IMG_BOOL_SETTER(lua_set_installed_directly, install_directly)\n+DEFINE_IMG_BOOL_SETTER(lua_set_install_if_different, id.install_if_different)\n+DEFINE_IMG_BOOL_SETTER(lua_set_install_if_higher, id.install_if_higher)\n+DEFINE_IMG_BOOL_SETTER(lua_set_encrypted, is_encrypted)\n+DEFINE_IMG_BOOL_SETTER(lua_set_partition, is_partitioner)\n+DEFINE_IMG_BOOL_SETTER(lua_set_script, is_script)\n+DEFINE_IMG_BOOL_SETTER(lua_set_preserve_attributes, preserve_attributes)\n+\n+static const struct lua_img_bool_handler_entry lua_bool_handlers[] = {\n+\t{ \"compressed\", lua_set_compressed_bool },\n+\t{ \"installed_directly\", lua_set_installed_directly },\n+\t{ \"install_if_different\", lua_set_install_if_different },\n+\t{ \"install_if_higher\", lua_set_install_if_higher },\n+\t{ \"encrypted\", lua_set_encrypted },\n+\t{ \"partition\", lua_set_partition },\n+\t{ \"script\", lua_set_script },\n+\t{ \"preserve_attributes\", lua_set_preserve_attributes },\n+};\n \n static void lua_bool_to_img(struct img_type *img, const char *key,\n \t bool val)\n {\n-\tif (!strcmp(key, \"compressed\"))\n-\t\timg->compressed = (bool)val;\n-\tif (!strcmp(key, \"installed_directly\"))\n-\t\timg->install_directly = (bool)val;\n-\tif (!strcmp(key, \"install_if_different\"))\n-\t\timg->id.install_if_different = (bool)val;\n-\tif (!strcmp(key, \"install_if_higher\"))\n-\t\timg->id.install_if_higher = (bool)val;\n-\tif (!strcmp(key, \"encrypted\"))\n-\t\timg->is_encrypted = (bool)val;\n-\tif (!strcmp(key, \"partition\"))\n-\t\timg->is_partitioner = (bool)val;\n-\tif (!strcmp(key, \"script\"))\n-\t\timg->is_script = (bool)val;\n-\tif (!strcmp(key, \"preserve_attributes\"))\n-\t\timg->preserve_attributes = (bool)val;\n+\tsize_t i;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(lua_bool_handlers); i++) {\n+\t\tif (!strcmp(key, lua_bool_handlers[i].key)) {\n+\t\t\tlua_bool_handlers[i].handler(img, val);\n+\t\t\treturn;\n+\t\t}\n+\t}\n }\n \n+DEFINE_IMG_NUMBER_SETTER(lua_set_offset_number, seek, unsigned long long)\n+DEFINE_IMG_NUMBER_SETTER(lua_set_size, size, long long)\n+DEFINE_IMG_NUMBER_SETTER(lua_set_checksum, checksum, unsigned int)\n+DEFINE_IMG_NUMBER_SETTER(lua_set_skip, skip, unsigned int)\n+\n+static const struct lua_img_number_handler_entry lua_number_handlers[] = {\n+\t{ \"offset\", lua_set_offset_number },\n+\t{ \"size\", lua_set_size },\n+\t{ \"checksum\", lua_set_checksum },\n+\t{ \"skip\", lua_set_skip },\n+};\n+\n static void lua_number_to_img(struct img_type *img, const char *key,\n \t double val)\n {\n-\tif (!strcmp(key, \"offset\"))\n-\t\timg->seek = (unsigned long long)val;\n-\tif (!strcmp(key, \"size\"))\n-\t\timg->size = (long long)val;\n-\tif (!strcmp(key, \"checksum\"))\n-\t\timg->checksum = (unsigned int)val;\n-\tif (!strcmp(key, \"skip\"))\n-\t\timg->skip = (unsigned int)val;\n+\tsize_t i;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(lua_number_handlers); i++) {\n+\t\tif (!strcmp(key, lua_number_handlers[i].key)) {\n+\t\t\tlua_number_handlers[i].handler(img, val);\n+\t\t\treturn;\n+\t\t}\n+\t}\n }\n \n static int l_copy2file(lua_State *L)\n@@ -541,6 +582,9 @@ static void update_table(lua_State* L, struct img_type *img)\n \t\t\tcase COMPRESSED_ZSTD:\n \t\t\t\tLUA_PUSH_IMG_STRING_VALUE(img, \"compressed\", \"zstd\");\n \t\t\t\tbreak;\n+\t\t\tcase COMPRESSED_LZ4:\n+\t\t\t\tLUA_PUSH_IMG_STRING_VALUE(img, \"compressed\", \"lz4\");\n+\t\t\t\tbreak;\n \t\t\tdefault:\n \t\t\t\tLUA_PUSH_IMG_BOOL(img, \"compressed\", compressed);\n \t\t\t\tbreak;\n", "prefixes": [ "v1", "3/4" ] }