summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-08 15:14:59 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-08 15:14:59 +0200
commit56f9ef4581d567248b6f83a3b15f39a0aca42895 (patch)
tree607fddaf6c62515126768b86d3e7e7df1112153a /plugins
parent6ea1d50ab6571551e1d0379940349911956c97ee (diff)
refactoring req interface
Change-Id: I6fc9246099c34f62c82e060cf014a63b0e8f63d8 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c8
-rw-r--r--plugins/samples/HelloWorld.c18
-rw-r--r--plugins/samples/SamplePost.c25
3 files changed, 8 insertions, 43 deletions
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index a23b1971..b026fd80 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -91,7 +91,7 @@ static void call_appid(struct afb_req request, const char *method)
{
struct json_object *obj;
char *sid;
- const char *id = afb_req_argument(request, _id_);
+ const char *id = afb_req_value(request, _id_);
if (id == NULL) {
afb_req_fail(request, "bad-request", "missing 'id'");
return;
@@ -114,7 +114,7 @@ static void call_appid(struct afb_req request, const char *method)
static void call_runid(struct afb_req request, const char *method)
{
struct json_object *obj;
- const char *id = afb_req_argument(request, _runid_);
+ const char *id = afb_req_value(request, _runid_);
if (id == NULL) {
afb_req_fail(request, "bad-request", "missing 'runid'");
return;
@@ -151,13 +151,13 @@ static void start(struct afb_req request)
int rc;
/* get the id */
- id = afb_req_argument(request, _id_);
+ id = afb_req_value(request, _id_);
if (id == NULL) {
afb_req_fail(request, "bad-request", "missing 'id'");
return;
}
/* get the mode */
- mode = afb_req_argument(request, _mode_);
+ mode = afb_req_value(request, _mode_);
if (mode == NULL || !strcmp(mode, _auto_)) {
mode = interface->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
}
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 7d99f6df..946f4b01 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -23,27 +23,11 @@
#include "afb-plugin.h"
#include "afb-req-itf.h"
-static int fillargs(json_object *args, struct afb_arg arg)
-{
- json_object *obj;
-
- obj = json_object_new_object();
- json_object_object_add (obj, "value", json_object_new_string(arg.value));
- if (arg.path != NULL)
- json_object_object_add (obj, "path", json_object_new_string(arg.path));
- json_object_object_add (obj, "size", json_object_new_int64((int64_t)arg.size));
- json_object_object_add (args, arg.name && *arg.name ? arg.name : "<empty-string>", obj);
- return 1; /* continue to iterate */
-}
-
// Sample Generic Ping Debug API
static void ping(struct afb_req request, json_object *jresp, const char *tag)
{
static int pingcount = 0;
- json_object *query;
-
- query = json_object_new_object();
- afb_req_iterate(request, (void*)fillargs, query);
+ json_object *query = afb_req_json(request);
afb_req_success_f(request, jresp, "Ping Binder Daemon tag=%s count=%d query=%s", tag, ++pingcount, json_object_to_json_string(query));
}
diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c
index 8a1b477a..e5a7235f 100644
--- a/plugins/samples/SamplePost.c
+++ b/plugins/samples/SamplePost.c
@@ -25,27 +25,11 @@
#include "afb-req-itf.h"
-static int fillargs(json_object *args, struct afb_arg arg)
-{
- json_object *obj;
-
- obj = json_object_new_object();
- json_object_object_add (obj, "value", json_object_new_string(arg.value));
- if (arg.path != NULL)
- json_object_object_add (obj, "path", json_object_new_string(arg.path));
- json_object_object_add (obj, "size", json_object_new_int64((int64_t)arg.size));
- json_object_object_add (args, arg.name && *arg.name ? arg.name : "<empty-string>", obj);
- return 1; /* continue to iterate */
-}
-
// Sample Generic Ping Debug API
static void getPingTest(struct afb_req request)
{
static int pingcount = 0;
- json_object *query;
-
- query = json_object_new_object();
- afb_req_iterate(request, (void*)fillargs, query);
+ json_object *query = afb_req_json(request);
afb_req_success_f(request, query, "Ping Binder Daemon count=%d", ++pingcount);
}
@@ -53,12 +37,9 @@ static void getPingTest(struct afb_req request)
// With content-type=json data are directly avaliable in request->post->data
static void GetJsonByPost (struct afb_req request)
{
- json_object* jresp;
- json_object *query;
struct afb_arg arg;
-
- query = json_object_new_object();
- afb_req_iterate(request, (void*)fillargs, query);
+ json_object* jresp;
+ json_object *query = afb_req_json(request);
arg = afb_req_get(request, "");
jresp = arg.value ? json_tokener_parse(arg.value) : NULL;