summaryrefslogtreecommitdiff
path: root/mesh/mesh-config-json.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2020-05-08 17:00:22 -0700
committerBrian Gix <brian.gix@intel.com>2020-05-14 09:12:56 -0700
commitb91f6f0be34386d4e5e0deebf32ec5a4301e5303 (patch)
tree919f5daff4474aa929ace03b874260bd84ab9343 /mesh/mesh-config-json.c
parent17dc8d1fd803896c22d0611f0c9e1800cae875d6 (diff)
downloadbluez-b91f6f0be34386d4e5e0deebf32ec5a4301e5303.tar.gz
mesh: Avoid saving duplicate fields in node config
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.
Diffstat (limited to 'mesh/mesh-config-json.c')
-rw-r--r--mesh/mesh-config-json.c24
1 files 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;
}