get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 116139,
    "url": "http://patchwork.dpdk.org/api/patches/116139/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20220909093523.471727-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": "<20220909093523.471727-13-bruce.richardson@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220909093523.471727-13-bruce.richardson@intel.com",
    "date": "2022-09-09T09:35:22",
    "name": "[v3,12/13] telemetry: eliminate duplicate code for json output",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "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": 24651,
        "url": "http://patchwork.dpdk.org/api/users/24651/?format=api",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20220909093523.471727-13-bruce.richardson@intel.com/mbox/",
    "series": [
        {
            "id": 24617,
            "url": "http://patchwork.dpdk.org/api/series/24617/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=24617",
            "date": "2022-09-09T09:35:13",
            "name": "telemetry JSON escaping and other enhancements",
            "version": 3,
            "mbox": "http://patchwork.dpdk.org/series/24617/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/116139/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/116139/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 906B9A0540;\n\tFri,  9 Sep 2022 11:36:57 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 9B89E42B9B;\n\tFri,  9 Sep 2022 11:35:58 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n by mails.dpdk.org (Postfix) with ESMTP id D21DD42B83\n for <dev@dpdk.org>; Fri,  9 Sep 2022 11:35:54 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 09 Sep 2022 02:35:54 -0700",
            "from silpixa00401385.ir.intel.com ([10.237.214.161])\n by orsmga004.jf.intel.com with ESMTP; 09 Sep 2022 02:35:53 -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=1662716155; x=1694252155;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=VQAGXAJSVEJmt//LQD1buGWpxsCyKtStxK8yQanehtU=;\n b=d16XN6GRgiffSUEvgHRnFLFNVsbQ0vz8SE3XlLY5cXpEmoqq2czrE2Js\n F9x9yHhANPIxD27qVG+y3rw1zdtzTbSKGb1rmu6il5jXPmNMvvaJW+V5k\n Rlj357NdxITs5a+e93342vX9/aqpRYdMSAO0GIRsmbxZg2TYBx3JX9PBK\n rgJCeApkDv6IvahM4Xxsnqq+/6NIRqQPmK0AlrfXxj44RCXxxtWFz+5/7\n /TJEGddecVIYkdSPrGgJlvolfN9Deyi30/RX0mHa7+MhpmzLyrq3B6tfo\n iOSsp9G5LbQBTkYE7nyWZgQpRf5nnu8ifw70f91933hknns0alBzkzPdA g==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6500,9779,10464\"; a=\"297437156\"",
            "E=Sophos;i=\"5.93,302,1654585200\"; d=\"scan'208\";a=\"297437156\"",
            "E=Sophos;i=\"5.93,302,1654585200\"; d=\"scan'208\";a=\"740996453\""
        ],
        "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>,\n =?utf-8?q?Morten_Br=C3=B8rup?= <mb@smartsharesystems.com>",
        "Subject": "[PATCH v3 12/13] telemetry: eliminate duplicate code for json output",
        "Date": "Fri,  9 Sep 2022 10:35:22 +0100",
        "Message-Id": "<20220909093523.471727-13-bruce.richardson@intel.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220909093523.471727-1-bruce.richardson@intel.com>",
        "References": "<20220623164245.561371-1-bruce.richardson@intel.com>\n <20220909093523.471727-1-bruce.richardson@intel.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "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>\nAcked-by: Ciara Power <ciara.power@intel.com>\nAcked-by: Morten Brørup <mb@smartsharesystems.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 69ca8b6c6f..d92667a527 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": [
        "v3",
        "12/13"
    ]
}