Does not compile
authorFulup Ar Foll <fulup@iot.bzh>
Tue, 22 Dec 2015 19:15:13 +0000 (20:15 +0100)
committerFulup Ar Foll <fulup@iot.bzh>
Tue, 22 Dec 2015 19:15:13 +0000 (20:15 +0100)
include/local-def.h
include/proto-def.h
nbproject/configurations.xml
src/rest-api.c
src/session.c

index 22a3608..abbbd61 100644 (file)
@@ -181,6 +181,7 @@ typedef struct {
   int  cacheTimeout;
   int  apiTimeout;
   int  cntxTimeout;        // Client Session Context timeout
+  int  pluginCount;        // loaded plugins count
   AFB_aliasdir *aliasdir;  // alias mapping for icons,apps,...
 } AFB_config;
 
@@ -228,8 +229,8 @@ typedef struct {
   char token[37];       // short term authentication of remote client
   time_t timeStamp;     // last time token was refresh
   int   restfull;       // client does not use cookie
-  void *ctx;            // application specific context
-  AFB_plugin *plugin;   // provide callback and easy access to plugin
+  void **ctx;           // application specific context [one per plugin]]
+  AFB_plugin **plugins; // we need plugins reference to cleanup session outside of call context
 } AFB_clientCtx;
 
 // MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
@@ -239,9 +240,9 @@ typedef struct {
   char *api;
   AFB_PostRequest *post;
   json_object *jresp;
-  AFB_clientCtx *client;      // needed because libmicrohttp cannot create an empty response
-  int   restfull;             // request is resfull [uuid token provided]
-  int   errcode;              // http error code
+  void *context;             // Hold Client Context when using session
+  int  restfull;             // request is resfull [uuid token provided]
+  int  errcode;              // http error code
   sigjmp_buf checkPluginCall; // context save for timeout set/longjmp
   AFB_config *config;         // plugin may need access to config
   struct MHD_Connection *connection;
@@ -261,7 +262,6 @@ typedef struct {
   int  fakemod;           // respond to GET/POST request without interacting with sndboard
   int  forceexit;         // when autoconfig from script force exit before starting server
   AFB_plugin **plugins;   // pointer to REST/API plugins 
-  int pluginCount;        // loaded plugins count
   magic_t  magic;         // Mime type file magic lib
   sigjmp_buf restartCkpt; // context save for restart set/longjmp
 } AFB_session;
index df26ce1..7f6fc06 100644 (file)
@@ -47,7 +47,7 @@ PUBLIC AFB_error ctxTokenRefresh (AFB_request *request);
 PUBLIC AFB_error ctxTokenCreate (AFB_request *request);
 PUBLIC AFB_error ctxTokenCheck (AFB_request *request);
 PUBLIC AFB_error ctxTokenReset (AFB_request *request);
-PUBLIC AFB_error ctxClientGet (AFB_request *request, AFB_plugin *plugin);
+PUBLIC AFB_error ctxClientGet (AFB_request *request, AFB_session *session, int idx);
 PUBLIC void      ctxStoreInit (int);
 
 
index a04af66..f87ca56 100644 (file)
         </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>HAVE_AUDIO_PLUGIN=1</Elem>
             <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/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>HAVE_AUDIO_PLUGIN=1</Elem>
             <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>HAVE_AUDIO_PLUGIN=1</Elem>
             <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>
index 8146e14..6927139 100644 (file)
@@ -116,7 +116,7 @@ STATIC AFB_error callPluginApi(AFB_plugin *plugin, AFB_request *request, void *c
                 if (AFB_SESSION_NONE != plugin->apis[idx].session) {
                     
                     // add client context to request
-                    if (ctxClientGet(request, plugin) != AFB_SUCCESS) {
+                    if (ctxClientGet(request, idx) != AFB_SUCCESS) {
                         request->errcode=MHD_HTTP_INSUFFICIENT_STORAGE;
                         json_object_object_add(jcall, "status", json_object_new_string ("fail"));
                         json_object_object_add(jcall, "info", json_object_new_string ("Client Session Context Full !!!"));
@@ -621,5 +621,5 @@ void initPlugins(AFB_session *session) {
 
     // complete plugins and save them within current sessions    
     session->plugins = RegisterJsonPlugins(plugins);
-    session->pluginCount = num;
+    session->config->pluginCount = num;
 }
index 4877acf..b5316d0 100644 (file)
@@ -315,15 +315,16 @@ OnErrorExit:
 }
 
 
-
-
 // Free context [XXXX Should be protected again memory abort XXXX]
 STATIC void ctxUuidFreeCB (AFB_clientCtx *client) {
   
     // If application add a handle let's free it now
     if (client->ctx != NULL) {
+        int idx;
+        AFB_plugin **plugins = client->plugins;
         
         // Free client handle with a standard Free function, with app callback or ignore it
+        for (idx=0; idx < )
         if (client->plugin->freeCtxCB == NULL) free (client->ctx); 
         else if (client->plugin->freeCtxCB != (void*)-1) client->plugin->freeCtxCB(client); 
     }
@@ -435,7 +436,7 @@ PUBLIC int ctxStoreGarbage (const int timeout) {
 }
 
 // This function will return exiting client context or newly created client context
-PUBLIC AFB_error ctxClientGet (AFB_request *request, AFB_plugin *plugin) {
+PUBLIC AFB_error ctxClientGet (AFB_request *request, int idx) {
   static int cid=0;
   AFB_clientCtx *clientCtx=NULL;
   const char *uuid;
@@ -473,13 +474,15 @@ PUBLIC AFB_error ctxClientGet (AFB_request *request, AFB_plugin *plugin) {
     }
    
     // we have no session let's create one otherwise let's clean any exiting values
-    if (clientCtx == NULL) clientCtx = calloc(1, sizeof(AFB_clientCtx)); // init NULL clientContext
+    if (clientCtx == NULL) {        
+        clientCtx = calloc(1, sizeof(AFB_clientCtx)); // init NULL clientContext
+        clientCtx->ctx = cmalloc (1, request->config->pluginCount * (sizeof (void*)));        
+    }
+    
     uuid_generate(newuuid);         // create a new UUID
     uuid_unparse_lower(newuuid, clientCtx->uuid);
     clientCtx->cid=cid++;   // simple application uniqueID 
-    clientCtx->plugin = plugin;    // provide plugin callbacks a hook to plugin
-    clientCtx->plugin;    // provide plugin callbacks a hook to plugin
-        
+    
     // if table is full at 50% let's clean it up
     if(sessions.count > (sessions.max / 2)) ctxStoreGarbage(request->config->cntxTimeout);
     
@@ -490,7 +493,7 @@ PUBLIC AFB_error ctxClientGet (AFB_request *request, AFB_plugin *plugin) {
     }
     
     // if (verbose) fprintf (stderr, "ctxClientGet New uuid=[%s] token=[%s] timestamp=%d\n", clientCtx->uuid, clientCtx->token, clientCtx->timeStamp);      
-    request->client = clientCtx;
+    request->client = clientCtx->ctx[idx];
 
     return(AFB_SUCCESS);
 }