Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp11989ybk; Fri, 8 May 2020 17:00:59 -0700 (PDT) X-Google-Smtp-Source: APiQypIpmOTPUfGRI93ZofWbWeMgYPmvxcNtxKeASOo470aqBB/WclUnFkXaAor9CE0LO54+7c8S X-Received: by 2002:aa7:ce0f:: with SMTP id d15mr4423182edv.327.1588982459412; Fri, 08 May 2020 17:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588982459; cv=none; d=google.com; s=arc-20160816; b=mPAC6rVLT3A91X43ndt40TR+GIAv0nNQ06LevOGxYZttJxKIE1SQfJmgJ18oAbqCWJ HZixvtuqDz0S7E0NZH9QbQlztTnm36a951gLwbsxG7g7pSRh3xOBVTM2g4IDZOrjT45m ewrN+LkIEyYJ4fpbD88By0Oc+GzU+LPjMrDnU1e55vv7FQvsWPcXB0VLZ+nLS51ExJVD SAT3VlTQSDCq9nfpiGG0tb6fZLaQkryxBcxDpfsEtIXszEnMmg9+vMPe02YrodLYwd7g r2DMOEl22yqpxuEURaP5x8FpDDzpC7LjUUCXopkuk0wCcoiNDV8OfZVstxWdkgkAhrG4 VupQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=khCSREIit6XVsrMZHXf24wR98RQgChiC9hn8C1onvZ8=; b=ltxmhL8D/L+EMLFDpp25SV27mY0lYrwJLToVdZyUJPRiL5mH6iU8STCBi26h7X/jwv dB0HNP/w3/FP+/PumcynGwHxJOXqKdRY/nRmUY6ndTf0K2N2067/Jo9ZU1ungFYV4y84 smYmYcAp0ptWqHvhgwkVqAVKs9kYhCR452wPAt28cVYgRcmr0ceXacWLCYR2quTwru3a 7ioy7bpmDPnYDOCsUO685raMyOIVjsEUijJnSuSiz782GxzH26TzFtJz29g3OBcfu6h2 Fykm5HnsEaBB4OYWbbuqBQmI2NQPHI6SrY6BAv3CafvzK3/KBb7oSQMYt3EqnI8ez+q/ KFBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si1918909ejs.138.2020.05.08.17.00.35; Fri, 08 May 2020 17:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbgEIAA2 (ORCPT + 99 others); Fri, 8 May 2020 20:00:28 -0400 Received: from mga04.intel.com ([192.55.52.120]:65492 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbgEIAA1 (ORCPT ); Fri, 8 May 2020 20:00:27 -0400 IronPort-SDR: XHREUZgc6FakBlPi0kI2yLuTFXacmII+qBrddVpxDVr6uUsjHSzfhD0Y9ZyH/tzj4cnaLbYdg/ gkb0QwQ2ZxWA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2020 17:00:27 -0700 IronPort-SDR: D/TLFg/HW1FsLUGamigzTDQWTPcv8ap8LPTy5y2UVG+nDo2ZfiMt7/Q09PubXjtjGrf/cMSZ+A mlHfeBYM1JTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,369,1583222400"; d="scan'208";a="408275096" Received: from ingas-nuc1.sea.intel.com ([10.254.110.242]) by orsmga004.jf.intel.com with ESMTP; 08 May 2020 17:00:26 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 2/4] mesh: Avoid saving duplicate fields in node config Date: Fri, 8 May 2020 17:00:22 -0700 Message-Id: <20200509000024.5704-3-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200509000024.5704-1-inga.stotland@intel.com> References: <20200509000024.5704-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This modifies miscellaneous utility functions in mesh-config-json.c: when writing a new value to a node configuration file, delete the existing field containing an old value first. --- mesh/mesh-config-json.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index 7362112f2..ce7058b5a 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -105,7 +105,7 @@ static bool get_int(json_object *jobj, const char *keyword, int *value) return true; } -static bool add_u64_value(json_object *jobject, const char *desc, +static bool add_u64_value(json_object *jobj, const char *desc, const uint8_t u64[8]) { json_object *jstring; @@ -116,11 +116,12 @@ static bool add_u64_value(json_object *jobject, const char *desc, if (!jstring) return false; - json_object_object_add(jobject, desc, jstring); + json_object_object_del(jobj, desc); + json_object_object_add(jobj, desc, jstring); return true; } -static bool add_key_value(json_object *jobject, const char *desc, +static bool add_key_value(json_object *jobj, const char *desc, const uint8_t key[16]) { json_object *jstring; @@ -131,7 +132,8 @@ static bool add_key_value(json_object *jobject, const char *desc, if (!jstring) return false; - json_object_object_add(jobject, desc, jstring); + json_object_object_del(jobj, desc); + json_object_object_add(jobj, desc, jstring); return true; } @@ -1398,6 +1400,7 @@ static bool write_uint16_hex(json_object *jobj, const char *desc, if (!jstring) return false; + json_object_object_del(jobj, desc); json_object_object_add(jobj, desc, jstring); return true; } @@ -1412,21 +1415,21 @@ static bool write_uint32_hex(json_object *jobj, const char *desc, uint32_t val) if (!jstring) return false; + json_object_object_del(jobj, desc); json_object_object_add(jobj, desc, jstring); return true; } -static bool write_int(json_object *jobj, const char *keyword, int val) +static bool write_int(json_object *jobj, const char *desc, int val) { json_object *jvalue; - json_object_object_del(jobj, keyword); - jvalue = json_object_new_int(val); if (!jvalue) return false; - json_object_object_add(jobj, keyword, jvalue); + json_object_object_del(jobj, desc); + json_object_object_add(jobj, desc, jvalue); return true; } @@ -1442,7 +1445,7 @@ static const char *mode_to_string(int mode) } } -static bool write_mode(json_object *jobj, const char *keyword, int value) +static bool write_mode(json_object *jobj, const char *desc, int value) { json_object *jstring; @@ -1451,7 +1454,8 @@ static bool write_mode(json_object *jobj, const char *keyword, int value) if (!jstring) return false; - json_object_object_add(jobj, keyword, jstring); + json_object_object_del(jobj, desc); + json_object_object_add(jobj, desc, jstring); return true; } -- 2.21.3