// WARNING: if you free context resource manually here do not forget to set request->context=NULL;
return (jresp);
}
+// Close and Free context
+STATIC json_object* clientGetPing (AFB_request *request) {
+ static count=0;
+ json_object *jresp;
+
+ jresp = json_object_new_object();
+ json_object_object_add(jresp, "count", json_object_new_int (count ++));
+
+ return (jresp);
+}
// This function is call when Client Session Context is removed
}
STATIC AFB_restapi pluginApis[]= {
- {"ping" , AFB_SESSION_NONE , (AFB_apiCB)getPingTest ,"Ping Rest Test Service"},
+ {"ping" , AFB_SESSION_NONE , (AFB_apiCB)clientGetPing ,"Ping Rest Test Service"},
{"create" , AFB_SESSION_CREATE, (AFB_apiCB)clientContextCreate ,"Request Client Context Creation"},
{"refresh" , AFB_SESSION_RENEW , (AFB_apiCB)clientContextRefresh,"Refresh Client Context Token"},
{"check" , AFB_SESSION_CHECK , (AFB_apiCB)clientContextCheck ,"Check Client Context Token"},
}
// Check of apiurl is declare in this plugin and call it
-STATIC AFB_error callPluginApi(AFB_plugin *plugin, AFB_request *request, void *context) {
+STATIC AFB_error callPluginApi(AFB_request *request, int plugidx, void *context) {
json_object *jresp, *jcall;
int idx, status, sig;
AFB_clientCtx *clientCtx;
+ AFB_plugin *plugin = request->plugins[plugidx];
int signals[]= {SIGALRM, SIGSEGV, SIGFPE, 0};
/*---------------------------------------------------------------
if (AFB_SESSION_NONE != plugin->apis[idx].session) {
// add client context to request
- clientCtx = ctxClientGet(request, idx);
- if (clientCtx != NULL) {
+ clientCtx = ctxClientGet(request, plugidx);
+ if (clientCtx == NULL) {
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 !!!"));
// Search for a plugin with this urlpath
for (idx = 0; request->plugins[idx] != NULL; idx++) {
if (!strcmp(request->plugins[idx]->prefix, request->plugin)) {
- status =callPluginApi(request->plugins[idx], request, context);
+ status =callPluginApi(request, idx, context);
break;
}
}
if (clientCtx == NULL) {
clientCtx = calloc(1, sizeof(AFB_clientCtx)); // init NULL clientContext
clientCtx->contexts = calloc (1, request->config->pluginCount * (sizeof (void*)));
+ clientCtx->plugins = request->plugins;
}
uuid_generate(newuuid); // create a new UUID
PUBLIC AFB_error ctxTokenCheck (AFB_clientCtx *clientCtx, AFB_request *request) {
const char *token;
- if (request->context == NULL) return AFB_EMPTY;
+ if (clientCtx->contexts == NULL) return AFB_EMPTY;
// this time have to extract token from query list
token = MHD_lookup_connection_value(request->connection, MHD_GET_ARGUMENT_KIND, "token");
uuid_unparse_lower(newuuid, clientCtx->token);
// keep track of time for session timeout and further clean up
- clientCtx->timeStamp=time(NULL);
+ clientCtx->timeStamp=time(NULL);
// Token is also store in context but it might be convenient for plugin to access it directly
return (AFB_SUCCESS);