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;
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");
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;
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;
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);
</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>
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 !!!"));
// complete plugins and save them within current sessions
session->plugins = RegisterJsonPlugins(plugins);
- session->pluginCount = num;
+ session->config->pluginCount = num;
}
}
-
-
// 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);
}
}
// 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;
}
// 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);
}
// 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);
}