aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-07 00:05:11 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-07 00:05:11 +0200
commitfc19b7d7974f9c64dffc40e180464d595a9805cd (patch)
treeef56c871e6598a441ed541ea40d555eaede44233 /plugins
parentc0453c34a58aac8150300ab829149a0ca4d9e5ee (diff)
improves file handling
Change-Id: I285cb6333d939a8afed07d8388d1d7850e50fe28 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c4
-rw-r--r--plugins/samples/HelloWorld.c51
-rw-r--r--plugins/samples/SamplePost.c2
3 files changed, 19 insertions, 38 deletions
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index d86e9263..a23b1971 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -221,8 +221,8 @@ static void install(struct afb_req request)
/* get the argument */
arg = afb_req_get(request, "widget");
- filename = arg.value;
- if (filename == NULL || !arg.is_file) {
+ filename = arg.path;
+ if (filename == NULL) {
afb_req_fail(request, "bad-request", "missing 'widget' file");
return;
}
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 72ad0b34..fd780e20 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -23,47 +23,28 @@
#include "afb-plugin.h"
#include "afb-req-itf.h"
-typedef struct queryHandleT {
- char *msg;
- size_t idx;
- size_t len;
-} queryHandleT;
-
-static int getQueryCB (queryHandleT *query, struct afb_arg arg) {
- if (query->idx >= query->len)
- return 0;
- query->idx += (unsigned)snprintf (&query->msg[query->idx], query->len-query->idx, " %s: %s\'%s\',", arg.name, arg.is_file?"FILE=":"", arg.value);
- return 1; /* continue to iterate */
-}
+static int fillargs(json_object *args, struct afb_arg arg)
+{
+ json_object *obj;
-// Helper to retrieve argument from connection
-static size_t getQueryAll(struct afb_req request, char *buffer, size_t len) {
- queryHandleT query;
- buffer[0] = '\0'; // start with an empty string
- query.msg = buffer;
- query.len = len;
- query.idx = 0;
-
- afb_req_iterate(request, (void*)getQueryCB, &query);
- buffer[len-1] = 0;
- return query.idx >= len ? len - 1 : query.idx;
+ obj = json_object_new_object();
+ json_object_object_add (obj, "value", json_object_new_string(arg.value));
+ 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 */
}
-static void ping (struct afb_req request, json_object *jresp)
+// Sample Generic Ping Debug API
+static void ping(struct afb_req request, json_object *jresp)
{
static int pingcount = 0;
- char query [512];
- size_t len;
+ json_object *query;
- // request all query key/value
- len = getQueryAll (request, query, sizeof(query));
- if (len == 0) strcpy (query,"NoSearchQueryList");
-
- // return response to caller
-// response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon %d query={%s}", pingcount++, query);
- afb_req_success_f(request, jresp, "Ping Binder Daemon %d query={%s}", pingcount++, query);
-
- fprintf(stderr, "%d: \n", pingcount);
+ query = json_object_new_object();
+ afb_req_iterate(request, (void*)fillargs, query);
+
+ afb_req_success_f(request, jresp, "Ping Binder Daemon count=%d query=%s", ++pingcount, json_object_to_json_string(query));
}
static void pingSample (struct afb_req request)
diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c
index aab54e91..58a2a8b8 100644
--- a/plugins/samples/SamplePost.c
+++ b/plugins/samples/SamplePost.c
@@ -31,8 +31,8 @@ static int fillargs(json_object *args, struct afb_arg arg)
obj = json_object_new_object();
json_object_object_add (obj, "value", json_object_new_string(arg.value));
+ 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 (obj, "is_file", json_object_new_boolean(arg.is_file));
json_object_object_add (args, arg.name && *arg.name ? arg.name : "<empty-string>", obj);
return 1; /* continue to iterate */
}