X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Fsamples%2FSamplePost.c;h=d29fb05abe14d9c02ca452b4b6e056910591b787;hb=ca208671cc79bbc05c574df788035878e5d39382;hp=56c3f24b22a773f3d80c16d5489bdf4f1d7068cd;hpb=e76dff6729fb9acd1638019507e7edbbd8af23f5;p=src%2Fapp-framework-binder.git diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c index 56c3f24b..d29fb05a 100644 --- a/plugins/samples/SamplePost.c +++ b/plugins/samples/SamplePost.c @@ -19,6 +19,27 @@ #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 [256]; + char session[256]; + int len; + + // request all query key/value + len = getQueryAll (request, query, sizeof(query)); + if (len == 0) strncpy (query, "NoSearchQueryList", sizeof(query)); + + // check if we have some post data + if (request->post == NULL) request->post->data="NoData"; + + // return response to caller + response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon count=%d uuid=%s query={%s} session={0x%x} PostData: [%s] " + , pingcount++, request->uuid, query, session, request->post->data); + return (response); +} + // With content-type=json data are directly avaliable in request->post->data STATIC json_object* GetJsonByPost (AFB_request *request) { json_object* jresp; @@ -47,14 +68,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) { - - // request Application Framework to install application - - request->errcode = MHD_HTTP_OK; // or error is something went wrong; - request->jresp = jsonNewMessage(AFB_FAIL,"UploadFile Post Request file=[%s] done", postFileCtx->path); - } + // 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 @@ -64,10 +81,8 @@ STATIC json_object* UploadAppli (AFB_request *request, AFB_PostItem *item) { // Simples Upload case just upload a file STATIC json_object* UploadMusic (AFB_request *request, AFB_PostItem *item) { - char *destination = "musics"; - // upload multi iteration logic is handle by getPostedFile - return (getPostFile (request, item, destination)); + return (getPostFile (request, item, "musics")); } // PostForm callback is called multiple times (one or each key within form, or once per file buffer) @@ -78,17 +93,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 Request file=[%s] done", postFileCtx->path); - - // 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 @@ -110,10 +120,9 @@ STATIC AFB_restapi pluginApis[]= { PUBLIC AFB_plugin *pluginRegister () { AFB_plugin *plugin = malloc (sizeof (AFB_plugin)); plugin->type = AFB_PLUGIN_JSON; - plugin->info = "Application Framework Binder Service"; + plugin->info = "Sample with Post Upload Files"; plugin->prefix= "post"; // url base plugin->apis = pluginApis; - plugin->handle= (void*) "What ever you want"; return (plugin); };