afb-stub-ws: Safe handling of deconnections
[src/app-framework-binder.git] / src / wrap-json.c
index 6e60476..6bf6f4f 100644 (file)
@@ -815,7 +815,7 @@ int wrap_json_check(struct json_object *object, const char *desc, ...)
        va_list args;
 
        va_start(args, desc);
-       rc = vunpack(object, desc, args, 0);
+       rc = wrap_json_vcheck(object, desc, args);
        va_end(args);
        return rc;
 }
@@ -831,9 +831,9 @@ int wrap_json_match(struct json_object *object, const char *desc, ...)
        va_list args;
 
        va_start(args, desc);
-       rc = vunpack(object, desc, args, 0);
+       rc = wrap_json_vmatch(object, desc, args);
        va_end(args);
-       return !rc;
+       return rc;
 }
 
 int wrap_json_vunpack(struct json_object *object, const char *desc, va_list args)
@@ -992,9 +992,13 @@ struct json_object *wrap_json_clone_depth(struct json_object *item, int depth)
 }
 
 /**
- * Clones the 'object': returns a copy of it. But doen't clones
+ * Clones the 'object': returns a copy of it. But doesn't clones
  * the content. Synonym of wrap_json_clone_depth(object, 1).
  *
+ * Be aware that this implementation doesn't clones content that is deeper
+ * than 1 but it does link these contents to the original object and
+ * increments their use count. So, everything deeper that 1 is still available.
+ *
  * @param object the object to clone
  *
  * @return a copy of the object.
@@ -1247,6 +1251,9 @@ int wrap_json_contains(struct json_object *x, struct json_object *y)
 
 #if defined(WRAP_JSON_TEST)
 #include <stdio.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
 
 void tclone(struct json_object *object)
 {
@@ -1254,12 +1261,12 @@ void tclone(struct json_object *object)
 
        o = wrap_json_clone(object);
        if (!wrap_json_equal(object, o))
-               printf("ERROR in clone or equal: %s VERSUS %s\n", json_object_to_json_string(object), json_object_to_json_string(o));
+               printf("ERROR in clone or equal: %s VERSUS %s\n", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), json_object_to_json_string_ext(o, JSON_C_TO_STRING_NOSLASHESCAPE));
        json_object_put(o);
 
        o = wrap_json_clone_deep(object);
        if (!wrap_json_equal(object, o))
-               printf("ERROR in clone_deep or equal: %s VERSUS %s\n", json_object_to_json_string(object), json_object_to_json_string(o));
+               printf("ERROR in clone_deep or equal: %s VERSUS %s\n", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), json_object_to_json_string_ext(o, JSON_C_TO_STRING_NOSLASHESCAPE));
        json_object_put(o);
 }
 
@@ -1273,7 +1280,7 @@ void p(const char *desc, ...)
        rc = wrap_json_vpack(&result, desc, args);
        va_end(args);
        if (!rc)
-               printf("  SUCCESS %s\n\n", json_object_to_json_string(result));
+               printf("  SUCCESS %s\n\n", json_object_to_json_string_ext(result, JSON_C_TO_STRING_NOSLASHESCAPE));
        else
                printf("  ERROR[char %d err %d] %s\n\n", wrap_json_get_error_position(rc), wrap_json_get_error_code(rc), wrap_json_get_error_string(rc));
        tclone(result);
@@ -1327,8 +1334,8 @@ void u(const char *value, const char *desc, ...)
                        case 'I': printf(" I:%lld", *va_arg(args, int64_t*)); k = m&1; break;
                        case 'f': printf(" f:%f", *va_arg(args, double*)); k = m&1; break;
                        case 'F': printf(" F:%f", *va_arg(args, double*)); k = m&1; break;
-                       case 'o': printf(" o:%s", json_object_to_json_string(*va_arg(args, struct json_object**))); k = m&1; break;
-                       case 'O': o = *va_arg(args, struct json_object**); printf(" O:%s", json_object_to_json_string(o)); json_object_put(o); k = m&1; break;
+                       case 'o': printf(" o:%s", json_object_to_json_string_ext(*va_arg(args, struct json_object**), JSON_C_TO_STRING_NOSLASHESCAPE)); k = m&1; break;
+                       case 'O': o = *va_arg(args, struct json_object**); printf(" O:%s", json_object_to_json_string_ext(o, JSON_C_TO_STRING_NOSLASHESCAPE)); json_object_put(o); k = m&1; break;
                        case 'y':
                        case 'Y': {
                                uint8_t *p = *va_arg(args, uint8_t**);