fixe getPostPath for afm-mail plugin
authorFulup Ar Foll <fulup@iot.bzh>
Tue, 26 Jan 2016 15:35:37 +0000 (16:35 +0100)
committerFulup Ar Foll <fulup@iot.bzh>
Tue, 26 Jan 2016 15:35:37 +0000 (16:35 +0100)
nbproject/configurations.xml
plugins/afm-main-plugin/afm-main-plugin.c
plugins/samples/SamplePost.c
src/helper-api.c

index 93b861c..40d9345 100644 (file)
       <folder path="0/plugins/afm-main-plugin">
         <cTool>
           <incDir>
-            <pElem>plugins/afm-main-plugin</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
+            <pElem>build/plugins/afm-main-plugin</pElem>
           </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
-            <Elem>afm_main_api_EXPORTS=1</Elem>
+            <Elem>afm_main_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </folder>
       <folder path="0/plugins/audio">
         <cTool>
           <incDir>
-            <pElem>plugins/audio</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/plugins/audio</pElem>
           </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
-            <Elem>audio_api_EXPORTS=1</Elem>
+            <Elem>audio_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </folder>
       </folder>
       <folder path="0/plugins/samples">
         <cTool>
+          <incDir>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
+            <pElem>build/plugins/samples</pElem>
+          </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
           </preprocessorList>
       <folder path="0/plugins/session">
         <cTool>
           <incDir>
-            <pElem>plugins/session</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/plugins/session</pElem>
           </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
-            <Elem>token_api_EXPORTS=1</Elem>
+            <Elem>token_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </folder>
             ex="false"
             tool="0"
             flavor2="2">
-        <cTool flags="2">
-          <incDir>
-            <pElem>build/plugins/afm-main-plugin</pElem>
-          </incDir>
+        <cTool flags="0">
         </cTool>
       </item>
       <item path="plugins/afm-main-plugin/utils-jbus.c"
             ex="false"
             tool="0"
             flavor2="2">
-        <cTool flags="2">
-          <incDir>
-            <pElem>/usr/lib64/dbus-1.0/include/dbus</pElem>
-            <pElem>/usr/include/dbus-1.0/dbus</pElem>
-            <pElem>/usr/include/dbus-1.0</pElem>
-            <pElem>/usr/lib64/dbus-1.0/include</pElem>
-            <pElem>build/plugins/afm-main-plugin</pElem>
-          </incDir>
+        <cTool flags="0">
         </cTool>
       </item>
       <item path="plugins/audio/audio-alsa.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
         </cTool>
       </item>
       <item path="plugins/audio/audio-api.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
         </cTool>
       </item>
       <item path="plugins/radio/radio-api.c" ex="false" tool="0" flavor2="2">
         </cTool>
       </item>
       <item path="plugins/samples/ClientCtx.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
-          <incDir>
-            <pElem>plugins/samples</pElem>
-            <pElem>build/plugins/samples</pElem>
-          </incDir>
+        <cTool flags="0">
           <preprocessorList>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
-            <Elem>clientCtx_api_EXPORTS=1</Elem>
+            <Elem>clientCtx_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </item>
       <item path="plugins/samples/HelloWorld.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
-          <incDir>
-            <pElem>plugins/samples</pElem>
-            <pElem>build/plugins/samples</pElem>
-          </incDir>
+        <cTool flags="0">
           <preprocessorList>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
-            <Elem>helloWorld_api_EXPORTS=1</Elem>
+            <Elem>helloWorld_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </item>
       <item path="plugins/samples/SamplePost.c" ex="false" tool="0" flavor2="2">
         <cTool flags="0">
-          <incDir>
-            <pElem>/usr/include/dbus-1.0</pElem>
-            <pElem>/usr/lib64/dbus-1.0/include</pElem>
-            <pElem>/usr/include/alsa</pElem>
-            <pElem>build/plugins/samples</pElem>
-          </incDir>
           <preprocessorList>
             <Elem>samplePost_api_EXPORTS</Elem>
           </preprocessorList>
         </cTool>
       </item>
       <item path="plugins/session/token-api.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
         </cTool>
       </item>
       <item path="src/afbs-api.c" ex="false" tool="0" flavor2="2">
         </cTool>
       </item>
       <item path="src/config.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
           <incDir>
-            <pElem>src</pElem>
-            <pElem>/usr/include/json-c</pElem>
             <pElem>include</pElem>
+            <pElem>/usr/include/json-c</pElem>
             <pElem>/usr/include/uuid</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/src</pElem>
           </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
           </preprocessorList>
         </cTool>
       </item>
         </cTool>
       </item>
       <item path="src/http-svc.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
           <incDir>
-            <pElem>src</pElem>
-            <pElem>/usr/include/json-c</pElem>
             <pElem>include</pElem>
+            <pElem>/usr/include/json-c</pElem>
             <pElem>/usr/include/uuid</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/src</pElem>
           </incDir>
+          <preprocessorList>
+            <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
+          </preprocessorList>
         </cTool>
       </item>
       <item path="src/main.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
           <incDir>
-            <pElem>src</pElem>
-            <pElem>/usr/include/json-c</pElem>
             <pElem>include</pElem>
+            <pElem>/usr/include/json-c</pElem>
             <pElem>/usr/include/uuid</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/src</pElem>
           </incDir>
           <preprocessorList>
             <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
-            <Elem>__PIC__=2</Elem>
-            <Elem>__REGISTER_PREFIX__=</Elem>
-            <Elem>__USER_LABEL_PREFIX__=</Elem>
-            <Elem>__pic__=2</Elem>
           </preprocessorList>
         </cTool>
       </item>
         </cTool>
       </item>
       <item path="src/session.c" ex="false" tool="0" flavor2="2">
-        <cTool flags="2">
+        <cTool flags="0">
           <incDir>
-            <pElem>src</pElem>
+            <pElem>include</pElem>
             <pElem>/usr/include/json-c</pElem>
             <pElem>/usr/include/uuid</pElem>
-            <pElem>include</pElem>
+            <pElem>/usr/include/dbus-1.0</pElem>
+            <pElem>/usr/lib64/dbus-1.0/include</pElem>
+            <pElem>/usr/include/alsa</pElem>
             <pElem>build/src</pElem>
           </incDir>
+          <preprocessorList>
+            <Elem>PLUGIN_INSTALL_DIR="/usr/local/lib64/afb"</Elem>
+          </preprocessorList>
         </cTool>
       </item>
     </conf>
index 12bd9f3..5315da9 100644 (file)
@@ -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[] =
index e419be4..8894973 100644 (file)
@@ -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
index ad0daf6..4c07c77 100644 (file)
@@ -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;