From d5836c2c45c63cb627d1a72591e1f47f8e229aad Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Tue, 26 Jan 2016 16:35:37 +0100 Subject: fixe getPostPath for afm-mail plugin --- nbproject/configurations.xml | 133 ++++++++++++------------------ plugins/afm-main-plugin/afm-main-plugin.c | 29 ++++--- plugins/samples/SamplePost.c | 17 ++-- src/helper-api.c | 4 +- 4 files changed, 78 insertions(+), 105 deletions(-) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 93b861c7..40d93459 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -103,31 +103,28 @@ - plugins/afm-main-plugin + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa + build/plugins/afm-main-plugin PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 - afm_main_api_EXPORTS=1 + afm_main_api_EXPORTS - plugins/audio + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/plugins/audio PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 - audio_api_EXPORTS=1 + audio_api_EXPORTS @@ -144,6 +141,12 @@ + + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa + build/plugins/samples + PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" @@ -152,16 +155,14 @@ - plugins/session + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/plugins/session PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 - token_api_EXPORTS=1 + token_api_EXPORTS @@ -169,32 +170,22 @@ ex="false" tool="0" flavor2="2"> - - - build/plugins/afm-main-plugin - + - - - /usr/lib64/dbus-1.0/include/dbus - /usr/include/dbus-1.0/dbus - /usr/include/dbus-1.0 - /usr/lib64/dbus-1.0/include - build/plugins/afm-main-plugin - + - + - + @@ -206,50 +197,28 @@ - - - plugins/samples - build/plugins/samples - + - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 - clientCtx_api_EXPORTS=1 + clientCtx_api_EXPORTS - - - plugins/samples - build/plugins/samples - + - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 - helloWorld_api_EXPORTS=1 + helloWorld_api_EXPORTS - - /usr/include/dbus-1.0 - /usr/lib64/dbus-1.0/include - /usr/include/alsa - build/plugins/samples - samplePost_api_EXPORTS - + @@ -281,20 +250,18 @@ - + - src - /usr/include/json-c include + /usr/include/json-c /usr/include/uuid + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/src PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 @@ -329,31 +296,34 @@ - + - src - /usr/include/json-c include + /usr/include/json-c /usr/include/uuid + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/src + + PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" + - + - src - /usr/include/json-c include + /usr/include/json-c /usr/include/uuid + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/src PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" - __PIC__=2 - __REGISTER_PREFIX__= - __USER_LABEL_PREFIX__= - __pic__=2 @@ -392,14 +362,19 @@ - + - src + include /usr/include/json-c /usr/include/uuid - include + /usr/include/dbus-1.0 + /usr/lib64/dbus-1.0/include + /usr/include/alsa build/src + + PLUGIN_INSTALL_DIR="/usr/local/lib64/afb" + diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index 12bd9f33..5315da9d 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -127,20 +127,23 @@ static struct json_object *call_file__appid(AFB_request *request, AFB_PostItem * struct json_object *obj; char *query; const char *filename = getPostPath(request); - request->jresp = NULL; - if (0 >= asprintf(&query, "\"%s\"", filename)) - request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; - else { - obj = jbus_call_sj_sync(jbus, request->api, query); - free(query); - if (obj) - request->jresp = embed(request, _id_, obj); - else - request->errcode = MHD_HTTP_FAILED_DEPENDENCY; - } - unlink(filename); + + if (filename != NULL) { + request->jresp = NULL; + if (0 >= asprintf(&query, "\"%s\"", filename)) + request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; + else { + obj = jbus_call_sj_sync(jbus, request->api, query); + free(query); + if (obj) + request->jresp = embed(request, _id_, obj); + else + request->errcode = MHD_HTTP_FAILED_DEPENDENCY; + } + unlink(filename); + } } - return getPostFile (request, item, "/tmp"); + return getPostFile (request, item, "/tmp/upload"); } static AFB_restapi plug_apis[] = diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c index e419be45..88949736 100644 --- a/plugins/samples/SamplePost.c +++ b/plugins/samples/SamplePost.c @@ -72,17 +72,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 diff --git a/src/helper-api.c b/src/helper-api.c index ad0daf69..4c07c779 100644 --- a/src/helper-api.c +++ b/src/helper-api.c @@ -126,7 +126,7 @@ PUBLIC json_object* getPostFile (AFB_request *request, AFB_PostItem *item, char* // We have a context but last Xform iteration fail or application set a message if (request->jresp != NULL) { jresp = request->jresp; // retrieve previous error from postCtx - } else jresp = jsonNewMessage(AFB_FAIL,"getPostFile Post Request done"); + } else jresp = jsonNewMessage(AFB_SUCCESS,"getPostFile Post Request done"); // Error or not let's free all resources close(postFileCtx->fd); @@ -188,7 +188,7 @@ PUBLIC json_object* getPostFile (AFB_request *request, AFB_PostItem *item, char* postFileCtx->path = strdup (filepath); if (verbose) fprintf(stderr, "getPostFile path=%s\n", filepath); - + if((postFileCtx->fd = open(filepath, O_RDWR |O_CREAT, S_IRWXU|S_IRGRP)) <= 0) { postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"Fail to Create destination File=[%s] error=%s\n", filepath, strerror(errno)); goto ExitOnError; -- cgit 1.2.3-korg