get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/114172/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 114172,
    "url": "http://patchwork.dpdk.org/api/patches/114172/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20220725163543.875775-13-bruce.richardson@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20220725163543.875775-13-bruce.richardson@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220725163543.875775-13-bruce.richardson@intel.com",
    "date": "2022-07-25T16:35:41",
    "name": "[v2,12/13] telemetry: eliminate duplicate code for json output",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "91f9dff9ece5ba6943ca2373d927d5a315a95098",
    "submitter": {
        "id": 20,
        "url": "http://patchwork.dpdk.org/api/people/20/?format=api",
        "name": "Bruce Richardson",
        "email": "bruce.richardson@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20220725163543.875775-13-bruce.richardson@intel.com/mbox/",
    "series": [
        {
            "id": 24069,
            "url": "http://patchwork.dpdk.org/api/series/24069/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=24069",
            "date": "2022-07-25T16:35:29",
            "name": "telemetry JSON escaping and other enhancements",
            "version": 2,
            "mbox": "http://patchwork.dpdk.org/series/24069/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/114172/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/114172/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 54645A00C4;\n\tMon, 25 Jul 2022 18:37:09 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 9845742B90;\n\tMon, 25 Jul 2022 18:36:36 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n by mails.dpdk.org (Postfix) with ESMTP id 5BF8142B90\n for <dev@dpdk.org>; Mon, 25 Jul 2022 18:36:35 +0200 (CEST)",
            "from orsmga006.jf.intel.com ([10.7.209.51])\n by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 25 Jul 2022 09:36:35 -0700",
            "from silpixa00401385.ir.intel.com (HELO\n silpixa00401385.ger.corp.intel.com.) ([10.237.223.47])\n by orsmga006.jf.intel.com with ESMTP; 25 Jul 2022 09:36:33 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1658766995; x=1690302995;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=8l1EE9X+6YNZwhHtAXzkAYONZuImJwtH8hLQmxTo+5w=;\n b=QpBGcHeexOsijciFyA0tt29F+bZSwqt+SqwXEqkYChbfIb9QkUUbAmBK\n TYhHnWRL6QkVR8TDzjid9eOXsTgXBoPcTm0A4nf/eedaziY6WL+7lpTs4\n V59WhnsovCND3Jsg3A+ze7C3kb6c2DrP958HLeLkAGOoSnIUiIlKYN8IU\n wH0ZBKwW0tIjZNqMnpI57qSQbPqX6X6coUuAHTfRi/MRIBrQzXkCoGdzr\n ModkD81t+o/MX0w0dwReH1TFoBmXVBWJS49rYkYjjT61yoCkX0vadmlwE\n QdNIOYKgICl8atlsw/cDwmgUqcaCJWTVa2d6HyC4Vx+NALTBuT/rZsp1X A==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6400,9594,10419\"; a=\"288499142\"",
            "E=Sophos;i=\"5.93,193,1654585200\"; d=\"scan'208\";a=\"288499142\"",
            "E=Sophos;i=\"5.93,193,1654585200\"; d=\"scan'208\";a=\"575122764\""
        ],
        "X-ExtLoop1": "1",
        "From": "Bruce Richardson <bruce.richardson@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Bruce Richardson <bruce.richardson@intel.com>,\n Ciara Power <ciara.power@intel.com>",
        "Subject": "[PATCH v2 12/13] telemetry: eliminate duplicate code for json output",
        "Date": "Mon, 25 Jul 2022 17:35:41 +0100",
        "Message-Id": "<20220725163543.875775-13-bruce.richardson@intel.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220725163543.875775-1-bruce.richardson@intel.com>",
        "References": "<20220623164245.561371-1-bruce.richardson@intel.com>\n <20220725163543.875775-1-bruce.richardson@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "When preparing the json response to a telemetry socket query, the code\nfor prefixing the command name, and appending the file \"}\" on the end of\nthe response was duplicated for multiple reply types. Taking this code\nout of the switch statement reduces the duplication and makes the code\nmore maintainable.\n\nFor completeness of testing, add in a test case to validate the \"null\"\nresponse type - the only leg of the switch statment not already covered\nby an existing test case in the telemetry_data tests.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n app/test/test_telemetry_data.c |  7 +++++++\n lib/telemetry/telemetry.c      | 35 ++++++++++++----------------------\n 2 files changed, 19 insertions(+), 23 deletions(-)",
    "diff": "diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c\nindex cfa4d636f0..d0fc78474e 100644\n--- a/app/test/test_telemetry_data.c\n+++ b/app/test/test_telemetry_data.c\n@@ -93,6 +93,12 @@ check_output(const char *func_name, const char *expected)\n \treturn strncmp(expected, buf, sizeof(buf));\n }\n \n+static int\n+test_null_return(void)\n+{\n+\treturn CHECK_OUTPUT(\"null\");\n+}\n+\n static int\n test_simple_string(void)\n {\n@@ -419,6 +425,7 @@ telemetry_data_autotest(void)\n \t\treturn -1;\n \n \ttest_case test_cases[] = {\n+\t\t\ttest_null_return,\n \t\t\ttest_simple_string,\n \t\t\ttest_case_array_string,\n \t\t\ttest_case_array_int, test_case_array_u64,\ndiff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c\nindex 03651e947d..cf60d27bd4 100644\n--- a/lib/telemetry/telemetry.c\n+++ b/lib/telemetry/telemetry.c\n@@ -233,27 +233,22 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)\n \n \tRTE_BUILD_BUG_ON(sizeof(out_buf) < MAX_CMD_LEN +\n \t\t\tRTE_TEL_MAX_SINGLE_STRING_LEN + 10);\n+\n+\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\n+\t\t\tMAX_CMD_LEN, cmd);\n+\tcb_data_buf = &out_buf[prefix_used];\n+\tbuf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */\n+\n \tswitch (d->type) {\n \tcase RTE_TEL_NULL:\n-\t\tused = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":null}\",\n-\t\t\t\tMAX_CMD_LEN, cmd ? cmd : \"none\");\n+\t\tused = strlcpy(cb_data_buf, \"null\", buf_len);\n \t\tbreak;\n-\tcase RTE_TEL_STRING:\n-\t\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\n-\t\t\t\tMAX_CMD_LEN, cmd);\n-\t\tcb_data_buf = &out_buf[prefix_used];\n-\t\tbuf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */\n \n+\tcase RTE_TEL_STRING:\n \t\tused = rte_tel_json_str(cb_data_buf, buf_len, 0, d->data.str);\n-\t\tused += prefix_used;\n-\t\tused += strlcat(out_buf + used, \"}\", sizeof(out_buf) - used);\n \t\tbreak;\n-\tcase RTE_TEL_DICT:\n-\t\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\n-\t\t\t\tMAX_CMD_LEN, cmd);\n-\t\tcb_data_buf = &out_buf[prefix_used];\n-\t\tbuf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */\n \n+\tcase RTE_TEL_DICT:\n \t\tused = rte_tel_json_empty_obj(cb_data_buf, buf_len, 0);\n \t\tfor (i = 0; i < d->data_len; i++) {\n \t\t\tconst struct tel_dict_entry *v = &d->data.dict[i];\n@@ -289,18 +284,12 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)\n \t\t\t}\n \t\t\t}\n \t\t}\n-\t\tused += prefix_used;\n-\t\tused += strlcat(out_buf + used, \"}\", sizeof(out_buf) - used);\n \t\tbreak;\n+\n \tcase RTE_TEL_ARRAY_STRING:\n \tcase RTE_TEL_ARRAY_INT:\n \tcase RTE_TEL_ARRAY_U64:\n \tcase RTE_TEL_ARRAY_CONTAINER:\n-\t\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\n-\t\t\t\tMAX_CMD_LEN, cmd);\n-\t\tcb_data_buf = &out_buf[prefix_used];\n-\t\tbuf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */\n-\n \t\tused = rte_tel_json_empty_array(cb_data_buf, buf_len, 0);\n \t\tfor (i = 0; i < d->data_len; i++)\n \t\t\tif (d->type == RTE_TEL_ARRAY_STRING)\n@@ -328,10 +317,10 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)\n \t\t\t\tif (!rec_data->keep)\n \t\t\t\t\trte_tel_data_free(rec_data->data);\n \t\t\t}\n-\t\tused += prefix_used;\n-\t\tused += strlcat(out_buf + used, \"}\", sizeof(out_buf) - used);\n \t\tbreak;\n \t}\n+\tused += prefix_used;\n+\tused += strlcat(out_buf + used, \"}\", sizeof(out_buf) - used);\n \tif (write(s, out_buf, used) < 0)\n \t\tperror(\"Error writing to socket\");\n }\n",
    "prefixes": [
        "v2",
        "12/13"
    ]
}