From: Fulup Ar Foll Date: Mon, 14 Dec 2015 15:24:26 +0000 (+0100) Subject: Integrated Post for Fileupload Test X-Git-Tag: blowfish_2.0.1~357 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=71f29a4ccfadb0eeed83479e61287252f9804fa7;p=src%2Fapp-framework-binder.git Integrated Post for Fileupload Test --- diff --git a/include/local-def.h b/include/local-def.h index 2f8fd202..a5d48bfd 100644 --- a/include/local-def.h +++ b/include/local-def.h @@ -60,6 +60,7 @@ #define DEFLT_API_TIMEOUT 0 // default Plugin API Timeout #define DEFLT_CACHE_TIMEOUT 100000 // default Static File Chache [Client Side Cache 100000~=1day] #define DEFLT_AUTH_TOKEN NULL // expect for debug should == NULL +#define DEFLT_HTTP_TIMEOUT 15 // Max MibMicroHttp timeout typedef int BOOL; #ifndef FALSE @@ -199,7 +200,8 @@ typedef struct { const char *url; char *plugin; char *api; - char *post; + char *post; // post data in raw format + int len; // post data len json_object *jresp; AFB_clientCtx *client; // needed because libmicrohttp cannot create an empty response int restfull; // request is resfull [uuid token provided] diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 129838ae..7a2bc668 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -61,12 +61,7 @@ include /usr/include/json-c - /usr/include/libusb-1.0 - build/src - - WITH_RADIO_PLUGIN=1 - @@ -77,38 +72,69 @@ + + build/src + + + build/src + + + build/src + + + build/src + + + build/src + + + build/src + - + + + /usr/include/libusb-1.0 + build/src + + + WITH_RADIO_PLUGIN=1 + + + build/src + + + build/src + diff --git a/src/afbs-api.c b/src/afbs-api.c index 344377b2..c974efda 100644 --- a/src/afbs-api.c +++ b/src/afbs-api.c @@ -96,6 +96,8 @@ STATIC json_object* clientContextCheck (AFB_request *request) { return (jresp); } + + // Close and Free context STATIC json_object* clientContextReset (AFB_request *request) { json_object *jresp; @@ -112,6 +114,39 @@ STATIC json_object* clientContextReset (AFB_request *request) { return (jresp); } +// Some file upload sample +STATIC json_object* clientFileUpload (AFB_request *request) { + int fd; + json_object *jresp; + char filepath[512]; + char *filename; + + getQueryValue(request, "filename"); + if (filename == NULL) return (jsonNewMessage(AFB_FAIL, "No Filename provided")); + + // add an error code to respond + if (request->post == NULL) { + request->errcode=MHD_HTTP_UNAUTHORIZED; + return (jsonNewMessage(AFB_FAIL, "Post No Data")); + } + + // This is simple test let's write file in config->session->filename + strncpy (filepath, request->config->configfile, sizeof(filepath)); + strncat (filepath, "/", sizeof(filepath)); + strncat (filepath, "/", sizeof(filepath)); + + + if((fd = open(request->config->configfile, O_RDONLY)) < 0) { + return (jsonNewMessage(AFB_FAIL,"Fail to Upload file [%s] at [%s] error=\n", filename, filepath, strerror(errno))); + }; + + // write file on disk and free fd + write (fd, request->post, request->len); + close(fd); + + return (jresp); +} + // This function is call when Client Session Context is removed // Note: when freeCtxCB==NULL standard free/malloc is called STATIC void clientContextFree(AFB_clientCtx *client) { @@ -125,6 +160,7 @@ STATIC AFB_restapi pluginApis[]= { {"token-refresh" , (AFB_apiCB)clientContextRefresh,"Refresh Client Context Token"}, {"token-check" , (AFB_apiCB)clientContextCheck ,"Check Client Context Token"}, {"token-reset" , (AFB_apiCB)clientContextReset ,"Close Client Context and Free resources"}, + {"file-upload" , (AFB_apiCB)clientFileUpload ,"Demo for file upload"}, {NULL} };