aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2015-12-22 20:15:13 +0100
committerFulup Ar Foll <fulup@iot.bzh>2015-12-22 20:15:13 +0100
commit1398adf363c182f25603f7d0c1ff52c5be8267b2 (patch)
treecc2d4007f3d35df79d1ce4ed7acc0bac34c16306
parent6d575b22b86ebfac5e2b4c9d672f45805a5b63ce (diff)
Does not compile
-rw-r--r--include/local-def.h12
-rw-r--r--include/proto-def.h2
-rw-r--r--nbproject/configurations.xml36
-rw-r--r--src/rest-api.c4
-rw-r--r--src/session.c19
5 files changed, 35 insertions, 38 deletions
diff --git a/include/local-def.h b/include/local-def.h
index 22a3608b..abbbd61f 100644
--- a/include/local-def.h
+++ b/include/local-def.h
@@ -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;
diff --git a/include/proto-def.h b/include/proto-def.h
index df26ce1b..7f6fc065 100644
--- a/include/proto-def.h
+++ b/include/proto-def.h
@@ -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);
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index a04af66c..f87ca56e 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -259,21 +259,19 @@
</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>
@@ -314,21 +312,19 @@
</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>
@@ -366,21 +362,19 @@
</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>
diff --git a/src/rest-api.c b/src/rest-api.c
index 8146e144..69271398 100644
--- a/src/rest-api.c
+++ b/src/rest-api.c
@@ -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;
}
diff --git a/src/session.c b/src/session.c
index 4877acf7..b5316d06 100644
--- a/src/session.c
+++ b/src/session.c
@@ -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);
}