#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"
/* 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)
#include <json-c/json.h>
+#include <afb/afb-req-itf.h>
+
#include "afb-msg-json.h"
#include "afb-context.h"
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;
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);
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);
+
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)
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)