summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-10 14:29:14 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-10 14:29:14 +0200
commitb69290c369ba67ee804bc5a0a440210c0e5d37a3 (patch)
tree13e8ea4b4d37fd8239b2fc395cb3df6af214da2d
parent17b196f1326d6b6c249d44b8744d73d7bba12d7a (diff)
common code reuse
Change-Id: I5f400a92165bb380ec5f703dd8ca567e90aebca2 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-api-dbus.c15
-rw-r--r--src/afb-msg-json.c19
-rw-r--r--src/afb-msg-json.h3
-rw-r--r--src/afb-subcall.c13
-rw-r--r--src/afb-ws-json1.c14
5 files changed, 26 insertions, 38 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index 905c723d..7452339b 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -32,6 +32,7 @@
#include "afb-common.h"
#include "session.h"
+#include "afb-msg-json.h"
#include "afb-apis.h"
#include "afb-api-so.h"
#include "afb-context.h"
@@ -400,19 +401,7 @@ static struct json_object *dbus_req_json(struct dbus_req *dreq)
/* get the argument of the request of 'name' */
static struct afb_arg dbus_req_get(struct dbus_req *dreq, const char *name)
{
- struct afb_arg arg;
- struct json_object *value, *root;
-
- root = dbus_req_json(dreq);
- if (root != NULL && json_object_object_get_ex(root, name, &value)) {
- arg.name = name;
- arg.value = json_object_get_string(value);
- } else {
- arg.name = NULL;
- arg.value = NULL;
- }
- arg.path = NULL;
- return arg;
+ return afb_msg_json_get_arg(dbus_req_json(dreq), name);
}
static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *first, const char *second)
diff --git a/src/afb-msg-json.c b/src/afb-msg-json.c
index 8f543ff1..59af9d96 100644
--- a/src/afb-msg-json.c
+++ b/src/afb-msg-json.c
@@ -19,6 +19,8 @@
#include <json-c/json.h>
+#include <afb/afb-req-itf.h>
+
#include "afb-msg-json.h"
#include "afb-context.h"
@@ -89,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;
+}
+
+
diff --git a/src/afb-msg-json.h b/src/afb-msg-json.h
index 53ab0861..59827bed 100644
--- a/src/afb-msg-json.h
+++ b/src/afb-msg-json.h
@@ -19,6 +19,7 @@
struct json_object;
struct afb_context;
+struct afb_arg;
extern struct json_object *afb_msg_json_reply(const char *status, const char *info, struct json_object *resp, struct afb_context *context, const char *reqid);
extern struct json_object *afb_msg_json_reply_ok(const char *info, struct json_object *resp, struct afb_context *context, const char *reqid);
@@ -26,3 +27,5 @@ extern struct json_object *afb_msg_json_reply_error(const char *status, const ch
extern struct json_object *afb_msg_json_event(const char *event, struct json_object *object);
+extern struct afb_arg afb_msg_json_get_arg(struct json_object *object, const char *name);
+
diff --git a/src/afb-subcall.c b/src/afb-subcall.c
index 4d18bee7..bf641738 100644
--- a/src/afb-subcall.c
+++ b/src/afb-subcall.c
@@ -99,18 +99,7 @@ static struct json_object *subcall_json(struct afb_subcall *subcall)
static struct afb_arg subcall_get(struct afb_subcall *subcall, const char *name)
{
- struct afb_arg arg;
- struct json_object *value;
-
- if (json_object_object_get_ex(subcall->args, name, &value)) {
- arg.name = name;
- arg.value = json_object_get_string(value);
- } else {
- arg.name = NULL;
- arg.value = NULL;
- }
- arg.path = NULL;
- return arg;
+ return afb_msg_json_get_arg(subcall->args, name);
}
static void subcall_emit(struct afb_subcall *subcall, int iserror, struct json_object *object)
diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c
index 31e9e42e..03e57fd5 100644
--- a/src/afb-ws-json1.c
+++ b/src/afb-ws-json1.c
@@ -224,19 +224,7 @@ static struct json_object *wsreq_json(struct afb_wsreq *wsreq)
static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name)
{
- struct afb_arg arg;
- struct json_object *value, *root;
-
- root = wsreq_json(wsreq);
- if (json_object_object_get_ex(root, name, &value)) {
- arg.name = name;
- arg.value = json_object_get_string(value);
- } else {
- arg.name = NULL;
- arg.value = NULL;
- }
- arg.path = NULL;
- return arg;
+ return afb_msg_json_get_arg(wsreq_json(wsreq), name);
}
static void wsreq_fail(struct afb_wsreq *wsreq, const char *status, const char *info)