Adds 2017 to copyrights
[src/app-framework-binder.git] / src / afb-msg-json.c
index d5f6f5a..7702eb6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 "IoT.bzh"
+ * Copyright (C) 2016, 2017 "IoT.bzh"
  * Author: José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,8 @@
 
 #include <json-c/json.h>
 
+#include <afb/afb-req-itf.h>
+
 #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,20 @@ 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;
+}
+
+