summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afb-api-dbus.c10
-rw-r--r--src/afb-config.c3
-rw-r--r--src/afb-export.c6
-rw-r--r--src/afb-hook.c45
-rw-r--r--src/afb-hreq.c7
-rw-r--r--src/afb-trace.c11
-rw-r--r--src/afb-wsj1.c9
-rw-r--r--src/afb-xreq.c5
-rw-r--r--src/main-afb-client-demo.c21
-rw-r--r--src/tests/wrap-json/test-wrap-json.c13
-rw-r--r--src/wrap-json.c13
11 files changed, 89 insertions, 54 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index a2c9b086..227658f4 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -27,6 +27,9 @@
#include <systemd/sd-bus.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include <afb/afb-event-x2.h>
@@ -43,6 +46,7 @@
#include "afb-xreq.h"
#include "verbose.h"
+
static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
struct dbus_memo;
@@ -810,7 +814,7 @@ void dbus_req_raw_reply(struct afb_xreq *xreq, struct json_object *obj, const ch
int rc;
rc = sd_bus_reply_method_return(dreq->message, "sss",
- obj ? json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN) : "",
+ obj ? json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE) : "",
error ? : "",
info ? : "");
if (rc < 0)
@@ -892,7 +896,7 @@ static void afb_api_dbus_server_event_remove(void *closure, const char *event, i
static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object)
{
- const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
+ const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE);
afb_api_dbus_server_event_send(closure, '!', event, eventid, data, 0);
json_object_put(object);
}
@@ -904,7 +908,7 @@ static void afb_api_dbus_server_event_broadcast(void *closure, const char *event
api = closure;
rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, "broadcast",
- "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN));
+ "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE));
if (rc < 0)
ERROR("error while broadcasting event %s", event);
json_object_put(object);
diff --git a/src/afb-config.c b/src/afb-config.c
index 7beabaff..60788700 100644
--- a/src/afb-config.c
+++ b/src/afb-config.c
@@ -26,6 +26,9 @@
#include <ctype.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include "verbose.h"
#include "afb-config.h"
diff --git a/src/afb-export.c b/src/afb-export.c
index b40dd079..811ecb5e 100644
--- a/src/afb-export.c
+++ b/src/afb-export.c
@@ -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;
}
diff --git a/src/afb-hook.c b/src/afb-hook.c
index 6956a837..6b655301 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -26,6 +26,9 @@
#include <sys/uio.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include <afb/afb-req-x1.h>
#include <afb/afb-event-x2.h>
@@ -245,7 +248,7 @@ static void hook_xreq_end_cb(void *closure, const struct afb_hookid *hookid, con
static void hook_xreq_json_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj)
{
- _hook_xreq_(xreq, "json() -> %s", json_object_to_json_string(obj));
+ _hook_xreq_(xreq, "json() -> %s", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_xreq_get_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *name, struct afb_arg arg)
@@ -255,7 +258,7 @@ static void hook_xreq_get_cb(void *closure, const struct afb_hookid *hookid, con
static void hook_xreq_reply_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *obj, const char *error, const char *info)
{
- _hook_xreq_(xreq, "reply[%s](%s, %s)", error?:"success", json_object_to_json_string(obj), info);
+ _hook_xreq_(xreq, "reply[%s](%s, %s)", error?:"success", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE), info);
}
static void hook_xreq_legacy_context_get_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, void *value)
@@ -300,22 +303,22 @@ static void hook_xreq_unsubscribe_cb(void *closure, const struct afb_hookid *hoo
static void hook_xreq_subcall_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
{
- _hook_xreq_(xreq, "subcall(%s/%s, %s) ...", api, verb, json_object_to_json_string(args));
+ _hook_xreq_(xreq, "subcall(%s/%s, %s) ...", api, verb, json_object_to_json_string_ext(args, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_xreq_subcall_result_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *object, const char *error, const char *info)
{
- _hook_xreq_(xreq, " ...subcall... [%s] -> %s (%s)", error?:"success", json_object_to_json_string(object), info?:"");
+ _hook_xreq_(xreq, " ...subcall... [%s] -> %s (%s)", error?:"success", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), info?:"");
}
static void hook_xreq_subcallsync_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
{
- _hook_xreq_(xreq, "subcallsync(%s/%s, %s) ...", api, verb, json_object_to_json_string(args));
+ _hook_xreq_(xreq, "subcallsync(%s/%s, %s) ...", api, verb, json_object_to_json_string_ext(args, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_xreq_subcallsync_result_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int status, struct json_object *object, const char *error, const char *info)
{
- _hook_xreq_(xreq, " ...subcallsync... %d [%s] -> %s (%s)", status, error?:"success", json_object_to_json_string(object), info?:"");
+ _hook_xreq_(xreq, " ...subcallsync... %d [%s] -> %s (%s)", status, error?:"success", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), info?:"");
}
static void hook_xreq_vverbose_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
@@ -368,7 +371,7 @@ static void hook_xreq_get_uid_cb(void *closure, const struct afb_hookid *hookid,
static void hook_xreq_get_client_info_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct json_object *result)
{
- _hook_xreq_(xreq, "get_client_info() -> %s", json_object_to_json_string(result));
+ _hook_xreq_(xreq, "get_client_info() -> %s", json_object_to_json_string_ext(result, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static struct afb_hook_xreq_itf hook_xreq_default_itf = {
@@ -687,12 +690,12 @@ static void _hook_api_(const struct afb_export *export, const char *format, ...)
static void hook_api_event_broadcast_before_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object)
{
- _hook_api_(export, "event_broadcast.before(%s, %s)....", name, json_object_to_json_string(object));
+ _hook_api_(export, "event_broadcast.before(%s, %s)....", name, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_event_broadcast_after_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct json_object *object, int result)
{
- _hook_api_(export, "event_broadcast.after(%s, %s) -> %d", name, json_object_to_json_string(object), result);
+ _hook_api_(export, "event_broadcast.after(%s, %s) -> %d", name, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), result);
}
static void hook_api_get_event_loop_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_event *result)
@@ -802,32 +805,32 @@ static void hook_api_start_after_cb(void *closure, const struct afb_hookid *hook
static void hook_api_on_event_before_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object)
{
- _hook_api_(export, "on_event.before(%s, %d, %s)", event, event_x2, json_object_to_json_string(object));
+ _hook_api_(export, "on_event.before(%s, %d, %s)", event, event_x2, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_on_event_after_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object)
{
- _hook_api_(export, "on_event.after(%s, %d, %s)", event, event_x2, json_object_to_json_string(object));
+ _hook_api_(export, "on_event.after(%s, %d, %s)", event, event_x2, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_call_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args)
{
- _hook_api_(export, "call(%s/%s, %s) ...", api, verb, json_object_to_json_string(args));
+ _hook_api_(export, "call(%s/%s, %s) ...", api, verb, json_object_to_json_string_ext(args, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_call_result_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct json_object *object, const char *error, const char *info)
{
- _hook_api_(export, " ...call... [%s] -> %s (%s)", error?:"success", json_object_to_json_string(object), info?:"");
+ _hook_api_(export, " ...call... [%s] -> %s (%s)", error?:"success", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), info?:"");
}
static void hook_api_callsync_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *verb, struct json_object *args)
{
- _hook_api_(export, "callsync(%s/%s, %s) ...", api, verb, json_object_to_json_string(args));
+ _hook_api_(export, "callsync(%s/%s, %s) ...", api, verb, json_object_to_json_string_ext(args, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_callsync_result_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int status, struct json_object *object, const char *error, const char *info)
{
- _hook_api_(export, " ...callsync... %d [%s] -> %s (%s)", status, error?:"success", json_object_to_json_string(object), info?:"");
+ _hook_api_(export, " ...callsync... %d [%s] -> %s (%s)", status, error?:"success", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE), info?:"");
}
static void hook_api_new_api_before_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *api, const char *info, int noconcurrency)
@@ -902,12 +905,12 @@ static void hook_api_delete_api_cb(void *closure, const struct afb_hookid *hooki
static void hook_api_on_event_handler_before_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern)
{
- _hook_api_(export, "on_event_handler[%s].before(%s, %d, %s)", pattern, event, event_x2, json_object_to_json_string(object));
+ _hook_api_(export, "on_event_handler[%s].before(%s, %d, %s)", pattern, event, event_x2, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_api_on_event_handler_after_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *event, int event_x2, struct json_object *object, const char *pattern)
{
- _hook_api_(export, "on_event_handler[%s].after(%s, %d, %s)", pattern, event, event_x2, json_object_to_json_string(object));
+ _hook_api_(export, "on_event_handler[%s].after(%s, %d, %s)", pattern, event, event_x2, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static struct afb_hook_api_itf hook_api_default_itf = {
@@ -1291,23 +1294,23 @@ static void hook_evt_create_cb(void *closure, const struct afb_hookid *hookid, c
static void hook_evt_push_before_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj)
{
- _hook_evt_(evt, id, "push.before(%s)", json_object_to_json_string(obj));
+ _hook_evt_(evt, id, "push.before(%s)", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_evt_push_after_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result)
{
- _hook_evt_(evt, id, "push.after(%s) -> %d", json_object_to_json_string(obj), result);
+ _hook_evt_(evt, id, "push.after(%s) -> %d", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE), result);
}
static void hook_evt_broadcast_before_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj)
{
- _hook_evt_(evt, id, "broadcast.before(%s)", json_object_to_json_string(obj));
+ _hook_evt_(evt, id, "broadcast.before(%s)", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE));
}
static void hook_evt_broadcast_after_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result)
{
- _hook_evt_(evt, id, "broadcast.after(%s) -> %d", json_object_to_json_string(obj), result);
+ _hook_evt_(evt, id, "broadcast.after(%s) -> %d", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE), result);
}
static void hook_evt_name_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id, const char *result)
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index 54c097e0..495bf06c 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -27,6 +27,9 @@
#include <microhttpd.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#if defined(USE_MAGIC_MIME_TYPE)
#include <magic.h>
@@ -897,7 +900,7 @@ static struct json_object *req_json(struct afb_xreq *xreq)
static ssize_t send_json_cb(json_object *obj, uint64_t pos, char *buf, size_t max)
{
- ssize_t len = stpncpy(buf, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)+pos, max) - buf;
+ ssize_t len = stpncpy(buf, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE)+pos, max) - buf;
return len ? : (ssize_t)MHD_CONTENT_READER_END_OF_STREAM;
}
@@ -918,7 +921,7 @@ static void req_reply(struct afb_xreq *xreq, struct json_object *object, const c
if (reqid != NULL && json_object_object_get_ex(reply, "request", &sub))
json_object_object_add(sub, "reqid", json_object_new_string(reqid));
- response = MHD_create_response_from_callback((uint64_t)strlen(json_object_to_json_string_ext(reply, JSON_C_TO_STRING_PLAIN)), SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put);
+ response = MHD_create_response_from_callback((uint64_t)strlen(json_object_to_json_string_ext(reply, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE)), SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put);
afb_hreq_reply(hreq, MHD_HTTP_OK, response, NULL);
}
diff --git a/src/afb-trace.c b/src/afb-trace.c
index 7d4c81e3..d81e09c2 100644
--- a/src/afb-trace.c
+++ b/src/afb-trace.c
@@ -27,6 +27,9 @@
#include <pthread.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 3
#include <afb/afb-binding.h>
@@ -1487,7 +1490,7 @@ static void add_flags(void *closure, struct json_object *object, enum trace_type
if (wrap_json_unpack(object, "s", &name))
ctxt_error(&desc->context->errors, "unexpected %s value %s",
abstracting[type].name,
- json_object_to_json_string(object));
+ json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
else {
queried = (name[0] == '*' && !name[1]) ? "all" : name;
value = abstracting[type].get_flag(queried);
@@ -1627,7 +1630,7 @@ static void drop_tag(void *closure, struct json_object *object)
rc = wrap_json_unpack(object, "s", &name);
if (rc)
- ctxt_error(&context->errors, "unexpected tag value %s", json_object_to_json_string(object));
+ ctxt_error(&context->errors, "unexpected tag value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
else {
tag = trace_get_tag(context->trace, name, 0);
if (!tag)
@@ -1647,7 +1650,7 @@ static void drop_event(void *closure, struct json_object *object)
rc = wrap_json_unpack(object, "s", &name);
if (rc)
- ctxt_error(&context->errors, "unexpected event value %s", json_object_to_json_string(object));
+ ctxt_error(&context->errors, "unexpected event value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
else {
event = trace_get_event(context->trace, name, 0);
if (!event)
@@ -1667,7 +1670,7 @@ static void drop_session(void *closure, struct json_object *object)
rc = wrap_json_unpack(object, "s", &uuid);
if (rc)
- ctxt_error(&context->errors, "unexpected session value %s", json_object_to_json_string(object));
+ ctxt_error(&context->errors, "unexpected session value %s", json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
else {
session = trace_get_session_by_uuid(context->trace, uuid, 0);
if (!session)
diff --git a/src/afb-wsj1.c b/src/afb-wsj1.c
index 466b58ad..f2b4a084 100644
--- a/src/afb-wsj1.c
+++ b/src/afb-wsj1.c
@@ -26,6 +26,9 @@
#include <pthread.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include "afb-ws.h"
#include "afb-wsj1.h"
@@ -473,7 +476,7 @@ static int wsj1_send_issot(struct afb_wsj1 *wsj1, int i1, const char *s1, const
int afb_wsj1_send_event_j(struct afb_wsj1 *wsj1, const char *event, struct json_object *object)
{
- const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
+ const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE);
int rc = afb_wsj1_send_event_s(wsj1, event, objstr);
json_object_put(object);
return rc;
@@ -486,7 +489,7 @@ int afb_wsj1_send_event_s(struct afb_wsj1 *wsj1, const char *event, const char *
int afb_wsj1_call_j(struct afb_wsj1 *wsj1, const char *api, const char *verb, struct json_object *object, void (*on_reply)(void *closure, struct afb_wsj1_msg *msg), void *closure)
{
- const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
+ const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE);
int rc = afb_wsj1_call_s(wsj1, api, verb, objstr, on_reply, closure);
json_object_put(object);
return rc;
@@ -520,7 +523,7 @@ int afb_wsj1_call_s(struct afb_wsj1 *wsj1, const char *api, const char *verb, co
int afb_wsj1_reply_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token, int iserror)
{
- const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
+ const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN|JSON_C_TO_STRING_NOSLASHESCAPE);
int rc = afb_wsj1_reply_s(msg, objstr, token, iserror);
json_object_put(object);
return rc;
diff --git a/src/afb-xreq.c b/src/afb-xreq.c
index 8f246b3c..ba6660e6 100644
--- a/src/afb-xreq.c
+++ b/src/afb-xreq.c
@@ -24,6 +24,9 @@
#include <stdarg.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include <afb/afb-binding-v1.h>
#include <afb/afb-binding-v2.h>
@@ -666,7 +669,7 @@ void afb_xreq_reply_f(struct afb_xreq *xreq, struct json_object *obj, const char
const char *afb_xreq_raw(struct afb_xreq *xreq, size_t *size)
{
struct json_object *obj = xreq_json_cb(xreq_to_req_x2(xreq));
- const char *result = json_object_to_json_string(obj);
+ const char *result = json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE);
if (size != NULL)
*size = strlen(result);
return result;
diff --git a/src/main-afb-client-demo.c b/src/main-afb-client-demo.c
index bd0bbc40..54b6c9e8 100644
--- a/src/main-afb-client-demo.c
+++ b/src/main-afb-client-demo.c
@@ -30,6 +30,9 @@
#include <systemd/sd-event.h>
#include <json-c/json.h>
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
#include "afb-wsj1.h"
#include "afb-ws-client.h"
@@ -267,7 +270,7 @@ static void on_wsj1_call(void *closure, const char *api, const char *verb, struc
if (human)
printf("ON-CALL %s/%s:\n%s\n", api, verb,
json_object_to_json_string_ext(afb_wsj1_msg_object_j(msg),
- JSON_C_TO_STRING_PRETTY));
+ JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
rc = afb_wsj1_reply_error_s(msg, "\"unimplemented\"", NULL);
if (rc < 0)
@@ -282,7 +285,7 @@ static void on_wsj1_event(void *closure, const char *event, struct afb_wsj1_msg
if (human)
printf("ON-EVENT %s:\n%s\n", event,
json_object_to_json_string_ext(afb_wsj1_msg_object_j(msg),
- JSON_C_TO_STRING_PRETTY));
+ JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
}
@@ -295,7 +298,7 @@ static void on_wsj1_reply(void *closure, struct afb_wsj1_msg *msg)
printf("ON-REPLY %s: %s\n%s\n", (char*)closure,
afb_wsj1_msg_is_reply_ok(msg) ? "OK" : "ERROR",
json_object_to_json_string_ext(afb_wsj1_msg_object_j(msg),
- JSON_C_TO_STRING_PRETTY));
+ JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
free(closure);
dec_callcount();
@@ -461,11 +464,11 @@ static void on_pws_reply(void *closure, void *request, struct json_object *resul
if (result)
json_object_object_add(x, "response", json_object_get(result));
- printf("%s\n", json_object_to_json_string(x));
+ printf("%s\n", json_object_to_json_string_ext(x, JSON_C_TO_STRING_NOSLASHESCAPE));
json_object_put(x);
}
if (human)
- printf("ON-REPLY %s: %s %s\n%s\n", (char*)request, error, info ?: "", json_object_to_json_string_ext(result, JSON_C_TO_STRING_PRETTY));
+ printf("ON-REPLY %s: %s %s\n%s\n", (char*)request, error, info ?: "", json_object_to_json_string_ext(result, JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
free(request);
dec_callcount();
@@ -498,18 +501,18 @@ static void on_pws_event_unsubscribe(void *closure, void *request, const char *e
static void on_pws_event_push(void *closure, const char *event_name, int event_id, struct json_object *data)
{
if (raw)
- printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, 0));
+ printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
if (human)
- printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY));
+ printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
}
static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data)
{
if (raw)
- printf("ON-EVENT-BROADCAST: [%s]\n%s\n", event_name, json_object_to_json_string_ext(data, 0));
+ printf("ON-EVENT-BROADCAST: [%s]\n%s\n", event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
if (human)
- printf("ON-EVENT-BROADCAST: [%s]\n%s\n", event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY));
+ printf("ON-EVENT-BROADCAST: [%s]\n%s\n", event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
}
diff --git a/src/tests/wrap-json/test-wrap-json.c b/src/tests/wrap-json/test-wrap-json.c
index 83ed3156..8e22433e 100644
--- a/src/tests/wrap-json/test-wrap-json.c
+++ b/src/tests/wrap-json/test-wrap-json.c
@@ -21,6 +21,9 @@
#include <stdio.h>
#include "wrap-json.h"
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
void tclone(struct json_object *object)
@@ -29,12 +32,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);
}
@@ -48,7 +51,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);
@@ -102,8 +105,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**);
diff --git a/src/wrap-json.c b/src/wrap-json.c
index 6e604769..a1fcb22d 100644
--- a/src/wrap-json.c
+++ b/src/wrap-json.c
@@ -1247,6 +1247,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 +1257,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 +1276,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 +1330,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**);