json-c: Remove escaping of slashs
[src/app-framework-binder.git] / src / afb-export.c
index 315cc95..811ecb5 100644 (file)
@@ -24,6 +24,9 @@
 #include <ctype.h>
 
 #include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
 
 #define AFB_BINDING_VERSION 0
 #include <afb/afb-binding.h>
@@ -252,7 +255,8 @@ static int event_broadcast_cb(struct afb_api_x3 *closure, const char *name, stru
 
        /* check daemon state */
        if (export->state == Api_State_Pre_Init) {
-               ERROR("[API %s] Bad call to 'afb_daemon_event_broadcast(%s, %s)', must not be in PreInit", export->api.apiname, name, json_object_to_json_string(object));
+               ERROR("[API %s] Bad call to 'afb_daemon_event_broadcast(%s, %s)', must not be in PreInit",
+                       export->api.apiname, name, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
                errno = EINVAL;
                return 0;
        }
@@ -1149,7 +1153,7 @@ int afb_export_event_handler_add(
        }
 
        /* create the event */
-       handler = malloc(strlen(pattern) + strlen(pattern));
+       handler = malloc(strlen(pattern) + sizeof * handler);
        if (!handler) {
                ERROR("[API %s] can't allocate event handler %s", export->api.apiname, pattern);
                errno = ENOMEM;
@@ -1161,7 +1165,7 @@ int afb_export_event_handler_add(
        handler->callback = callback;
        handler->closure = closure;
        strcpy(handler->pattern, pattern);
-       export->event_handlers = handler;
+       *previous = handler;
 
        return 0;
 }
@@ -1552,29 +1556,23 @@ static void do_init(int sig, void *closure)
 };
 
 
-int afb_export_start(struct afb_export *export, int share_session, int onneed)
+int afb_export_start(struct afb_export *export)
 {
        struct init init;
        int rc;
 
        /* check state */
-       if (export->state != Api_State_Pre_Init) {
-               /* not an error when onneed */
-               if (onneed != 0)
-                       goto done;
+       switch (export->state) {
+       case Api_State_Run:
+               return 0;
 
-               /* already started: it is an error */
-               ERROR("Service of API %s already started", export->api.apiname);
+       case Api_State_Init:
+               /* starting in progress: it is an error */
+               ERROR("Service of API %s required started while starting", export->api.apiname);
                return -1;
-       }
 
-       /* unshare the session if asked */
-       if (!share_session) {
-               rc = afb_export_unshare_session(export);
-               if (rc < 0) {
-                       ERROR("Can't unshare the session for %s", export->api.apiname);
-                       return -1;
-               }
+       default:
+               break;
        }
 
        /* set event handling */
@@ -1616,7 +1614,6 @@ int afb_export_start(struct afb_export *export, int share_session, int onneed)
                return rc;
        }
 
-done:
        return 0;
 }
 
@@ -1668,11 +1665,11 @@ static struct json_object *api_describe_cb(void *closure)
        return result;
 }
 
-static int api_service_start_cb(void *closure, int share_session, int onneed)
+static int api_service_start_cb(void *closure)
 {
        struct afb_export *export = closure;
 
-       return afb_export_start(export, share_session, onneed);
+       return afb_export_start(export);
 }
 
 static void api_update_hooks_cb(void *closure)