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