taskwarrior: moved to github
[openwrt.org/packages.git] / libs / 01-jansson-add-jason_object_deep_update.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
This patch adds a function which can be used to update
json key values on all levels, not just one, automagically
adding new keys to objects which do not exist in old object.
 
Signed-off-by: Roman Yeryomin <roman@advem.lv>
 
--- a/src/value.c      2011-04-21 13:15:58.000000000 +0300
+++ b/src/value.c      2011-07-01 00:23:05.105103308 +0300
@@ -215,6 +215,41 @@
     return 0;
 }
 
+int json_object_deep_update(json_t *object, json_t *other)
+{
+    void *iter;
+
+    if(!json_is_object(object) || !json_is_object(other))
+        return -1;
+
+    iter = json_object_iter(other);
+    while(iter) {
+        const char *key;
+        json_t *value;
+
+        key = json_object_iter_key(iter);
+        value = json_object_iter_value(iter);
+
+        if (!json_is_object(value)) {
+            if ( json_object_set_nocheck( object, key, value ) )
+                return -1;
+        } else {
+            json_t *subobj = json_object_get(object, key);
+            if (!subobj) {
+                json_object_set_nocheck( object, key, value );
+                iter = json_object_iter_next(other, iter);
+                continue;
+            }
+            if (json_object_deep_update( subobj, value ) == -1)
+                return -1;
+        }
+
+        iter = json_object_iter_next(other, iter);
+    }
+
+    return 0;
+}
+
 void *json_object_iter(json_t *json)
 {
     json_object_t *object;
 
comments