X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-msg-json.c;h=b4ae51b44a5a2b6e5c95095284f1e0e7323f185f;hb=2243a0dd1adc75530bed663db808971789729df3;hp=d5f6f5a5dddc3b01a2cf22f0ad56c0d4a1a6e1f2;hpb=b57505f0f80f6394f04a041df6e808c857b01d4b;p=src%2Fapp-framework-binder.git diff --git a/src/afb-msg-json.c b/src/afb-msg-json.c index d5f6f5a5..b4ae51b4 100644 --- a/src/afb-msg-json.c +++ b/src/afb-msg-json.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,8 @@ #include +#include + #include "afb-msg-json.h" #include "afb-context.h" @@ -47,13 +49,15 @@ struct json_object *afb_msg_json_reply(const char *status, const char *info, str if (reqid != NULL) json_object_object_add(request, "reqid", json_object_new_string(reqid)); - token = afb_context_sent_token(context); - if (token != NULL) - json_object_object_add(request, "token", json_object_new_string(token)); + if (context != NULL) { + token = afb_context_sent_token(context); + if (token != NULL) + json_object_object_add(request, "token", json_object_new_string(token)); - uuid = afb_context_sent_uuid(context); - if (uuid != NULL) - json_object_object_add(request, "uuid", json_object_new_string(uuid)); + uuid = afb_context_sent_uuid(context); + if (uuid != NULL) + json_object_object_add(request, "uuid", json_object_new_string(uuid)); + } return msg; } @@ -87,3 +91,30 @@ struct json_object *afb_msg_json_event(const char *event, struct json_object *ob return msg; } +struct afb_arg afb_msg_json_get_arg(struct json_object *object, const char *name) +{ + struct afb_arg arg; + struct json_object *value; + + if (json_object_object_get_ex(object, name, &value)) { + arg.name = name; + arg.value = json_object_get_string(value); + } else { + arg.name = NULL; + arg.value = NULL; + } + arg.path = NULL; + return arg; +} + +struct json_object *afb_msg_json_internal_error() +{ + static struct json_object *obj; + + if (obj == NULL) + obj = afb_msg_json_reply_error("failed", "internal error", NULL, NULL); + + return obj; +} + +