websocket: initial (not integrated)
[src/app-framework-binder.git] / src / rest-api.c
index 756dc6f..12f4a44 100644 (file)
@@ -29,6 +29,8 @@
 
 #define AFB_MSG_JTYPE "AJB_reply"
 
+#define JSON_CONTENT  "application/json"
+#define FORM_CONTENT  "multipart/form-data"  /* TODO: replace with MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA */
 
 
 static json_object     *afbJsonType;
@@ -53,7 +55,7 @@ PUBLIC void endPostRequest(AFB_PostHandle *postHandle) {
 STATIC AFB_error callPluginApi(AFB_request *request, int plugidx, void *context) {
     json_object *jresp, *jcall, *jreqt;
     int idx, status, sig;
-    AFB_clientCtx *clientCtx;
+    AFB_clientCtx *clientCtx = NULL;
     AFB_plugin *plugin = request->plugins[plugidx];
     int signals[]= {SIGALRM, SIGSEGV, SIGFPE, 0};
     
@@ -69,7 +71,7 @@ STATIC AFB_error callPluginApi(AFB_request *request, int plugidx, void *context)
       sigaddset   (&sigset, signum);
       sigprocmask (SIG_UNBLOCK, &sigset, 0);
 
-      fprintf (stderr, "Oops:%s Plugin Api Timeout timeout\n", configTime());
+      fprintf (stderr, "Oops: Plugin Api Timeout timeout\n");
       longjmp (request->checkPluginCall, signum);
     }
 
@@ -368,7 +370,7 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co
     AFB_error status;
     struct MHD_Response *webResponse;
     const char *serialized;
-    AFB_request *request;
+    AFB_request *request = NULL;
     AFB_PostHandle *postHandle;
     AFB_PostRequest postRequest;
     int ret;
@@ -539,7 +541,7 @@ ExitOnError:
 
 // Loop on plugins. Check that they have the right type, prepare a JSON object with prefix
 STATIC AFB_plugin ** RegisterJsonPlugins(AFB_plugin **plugins) {
-    int idx, jdx;
+    int idx;
 
     for (idx = 0; plugins[idx] != NULL; idx++) {
         if (plugins[idx]->type != AFB_PLUGIN_JSON) {
@@ -559,20 +561,6 @@ STATIC AFB_plugin ** RegisterJsonPlugins(AFB_plugin **plugins) {
             plugins[idx]->jtype = json_object_new_string(plugins[idx]->prefix);
             json_object_get(plugins[idx]->jtype); // increase reference count to make it permanent
             plugins[idx]->prefixlen = strlen(plugins[idx]->prefix);
-            
-              
-            // Prebuild each API jtype to boost API json response
-            for (jdx = 0; plugins[idx]->apis[jdx].name != NULL; jdx++) {
-                AFB_privateApi *privateapi = malloc (sizeof (AFB_privateApi));
-                if (plugins[idx]->apis[jdx].privateapi != NULL) {
-                    fprintf (stderr, "WARNING: plugin=%s api=%s private handle should be NULL=%p\n"
-                            ,plugins[idx]->prefix,plugins[idx]->apis[jdx].name, plugins[idx]->apis[jdx].privateapi);
-                }
-                privateapi->len = (int)strlen (plugins[idx]->apis[jdx].name);
-                privateapi->jtype=json_object_new_string(plugins[idx]->apis[jdx].name);
-                json_object_get(privateapi->jtype); // increase reference count to make it permanent
-                plugins[idx]->apis[jdx].privateapi = privateapi;
-            }
         }
     }
     return (plugins);
@@ -669,11 +657,6 @@ void initPlugins(AFB_session *session) {
         close (dirfd);
     }
 
-    if (count == 0) {
-        fprintf(stderr, "No plugins found, afb-daemon is unlikely to work in this configuration, exiting...\n");
-        exit (-1);
-    }
-    
     // downsize structure to effective number of loaded plugins
     plugins = (AFB_plugin **)realloc (plugins, (unsigned)(count+1)*sizeof(AFB_plugin*));
     plugins[count] = NULL;
@@ -682,3 +665,4 @@ void initPlugins(AFB_session *session) {
     session->plugins = RegisterJsonPlugins(plugins);
     session->config->pluginCount = count;
 }
+