X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fsamples%2FSamplePost.c;h=24ee5385e3b72c0e037b406ab0628caa2fa5d62f;hb=1205c90cccd3144bab24b4b5fd8dcbf0d0e6b570;hp=9828349a4dbe4a6d70a2e00ade99c93c6f9ef942;hpb=b2247ca634420ed0d5ecc1743834ea4e0666aa2a;p=src%2Fapp-framework-binder.git diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c index 9828349a..24ee5385 100644 --- a/plugins/samples/SamplePost.c +++ b/plugins/samples/SamplePost.c @@ -19,21 +19,35 @@ #include "local-def.h" +// Sample Generic Ping Debug API +static json_object* getPingTest(AFB_request *request) { + static int pingcount = 0; + json_object *response; + char query [8000]; + int len; + + // request all query key/value + len = getQueryAll (request, query, sizeof(query)); + if (len == 0) strncpy (query, "NoSearchQueryList", sizeof(query)); + + // return response to caller + response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon count=%d uuid=%s query={%s}" + , pingcount++, request->uuid, query); + return (response); +} + // With content-type=json data are directly avaliable in request->post->data STATIC json_object* GetJsonByPost (AFB_request *request) { json_object* jresp; - char query [256]; + char query [8000]; int len; - // check if we have some post data - if (request->post == NULL) request->post->data="NoData"; - // Get all query string [Note real app should probably use value=getQueryValue(request,"key")] len = getQueryAll (request, query, sizeof(query)); if (len == 0) strncpy (query, "NoSearchQueryList", sizeof(query)); // for debug/test return response to caller - jresp = jsonNewMessage(AFB_SUCCESS, "GetJsonByPost query={%s} PostData: [%s]", query, request->post->data); + jresp = jsonNewMessage(AFB_SUCCESS, "GetJsonByPost query={%s}", query); return (jresp); } @@ -47,14 +61,10 @@ STATIC json_object* UploadAppli (AFB_request *request, AFB_PostItem *item) { // This is called after PostForm and then after DonePostForm if (item == NULL) { - AFB_PostCtx *postFileCtx = getPostContext(request); - if (postFileCtx != NULL) { - - // Do something intelligent here to install application - - postFileCtx->errcode = MHD_HTTP_OK; // or error is something went wrong; - postFileCtx->jresp = jsonNewMessage(AFB_SUCCESS,"UploadFile Post Appli=%s done", getPostPath (request)); - } + // Do something intelligent here to install application + request->errcode = MHD_HTTP_OK; // or error is something went wrong; + request->jresp = jsonNewMessage(AFB_SUCCESS,"UploadFile Post Appli=%s done", getPostPath (request)); + // Note: should not return here in order getPostedFile to clear Post resources. } // upload multi iteration logic is handle by getPostedFile @@ -76,17 +86,12 @@ STATIC json_object* UploadImage (AFB_request *request, AFB_PostItem *item) { char *destination = "images"; // This is called after PostForm and then after DonePostForm - if (item == NULL) { - AFB_PostCtx *postFileCtx = getPostContext(request); - - // if postFileCtx == NULL then an error happen [getPostedFile automatically reports errors] - if (postFileCtx != NULL) { - // Do something with your newly upload filepath=postFileCtx->path - request->errcode = MHD_HTTP_OK; - request->jresp = jsonNewMessage(AFB_FAIL,"UploadFile Post Image done"); - - // Note: should not return here in order getPostedFile to clear Post resources. - } + if (item == NULL && getPostPath (request) != NULL) { + // Do something with your newly upload filepath=postFileCtx->path + request->errcode = MHD_HTTP_OK; + request->jresp = jsonNewMessage(AFB_SUCCESS,"UploadFile Post Image done"); + + // Note: should not return here in order getPostedFile to clear Post resources. } // upload multi iteration logic is handle by getPostedFile @@ -111,7 +116,6 @@ PUBLIC AFB_plugin *pluginRegister () { plugin->info = "Sample with Post Upload Files"; plugin->prefix= "post"; // url base plugin->apis = pluginApis; - plugin->handle= (void*) "What ever you want"; return (plugin); };