From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6356DA0093; Thu, 23 Jun 2022 18:43:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3691E42824; Thu, 23 Jun 2022 18:43:04 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 0270A427ED for ; Thu, 23 Jun 2022 18:43:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656002581; x=1687538581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TeOUnYCpYeTAYv70jBTxhM9hwZjqFuPDJh+53UbReAY=; b=TSfZRRh7gqDzG6VkmkCu26uGoJRoL6mMRa6URHRqlfnqFW5+qzAk1xcw YkvTr8hKGYBRBWmJmRittJyUFvLvkny2CKW4rvxeZVboooAUUP+N93TlX cADIYtwZGSy40DF/L1RosYOpZ3rACKJO7ZudeuBvNCcP7l2K8FM5lYyu1 tCGs+9e/SAllMUzePDmLhesqyzOK0fbbFGBlZdWqjoisafTgh33vGuaEc UeencYZPkCnHVDhdBGG0zp5CDhMRa3L74Xn0Jwe60MK6+8SUS+bJ8tz+D x23PVMLrXk0wZSYd4qZ60UpGP5sYBClN6Lf7q9gC26JCWBpLmgvLvfPtZ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10386"; a="260589088" X-IronPort-AV: E=Sophos;i="5.92,216,1650956400"; d="scan'208";a="260589088" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2022 09:43:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,216,1650956400"; d="scan'208";a="915267934" Received: from silpixa00401385.ir.intel.com (HELO silpixa00401385.ger.corp.intel.com.) ([10.237.223.125]) by fmsmga005.fm.intel.com with ESMTP; 23 Jun 2022 09:42:59 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, fengchengwen@huawei.com, mb@smartsharesystems.com, Bruce Richardson Subject: [RFC PATCH 3/6] telemetry: use json string function for string outputs Date: Thu, 23 Jun 2022 17:42:42 +0100 Message-Id: <20220623164245.561371-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220623164245.561371-1-bruce.richardson@intel.com> References: <20220623164245.561371-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When returning just a string in response to a query, use the proper json string printing function to escape characters rather than just snprintf. Signed-off-by: Bruce Richardson --- lib/telemetry/telemetry.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index c6fd03a5ab..7188b1905c 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -232,9 +232,14 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) MAX_CMD_LEN, cmd ? cmd : "none"); break; case RTE_TEL_STRING: - used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":\"%.*s\"}", - MAX_CMD_LEN, cmd, - RTE_TEL_MAX_SINGLE_STRING_LEN, d->data.str); + prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":", + MAX_CMD_LEN, cmd); + cb_data_buf = &out_buf[prefix_used]; + buf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */ + + used = rte_tel_json_str(cb_data_buf, buf_len, 0, d->data.str); + used += prefix_used; + used += strlcat(out_buf + used, "}", sizeof(out_buf) - used); break; case RTE_TEL_DICT: prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":", -- 2.34.1