json_object_object_add(jcall, "status", json_object_new_string ("fail"));
json_object_object_add(jcall, "info", json_object_new_string ("Setting Timeout Handler Failed"));
json_object_object_add(jreqt, "request", jcall);
- return AFB_DONE;
+ goto ExitOnDone;
}
}
// Trigger a timer to protect from unacceptable long time execution
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 !!!"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
};
if (verbose) fprintf(stderr, "Plugin=[%s] Api=[%s] Middleware=[%d] Client=[0x%x] Uuid=[%s] Token=[%s]\n"
switch(plugin->apis[idx].session) {
- case AFB_SESSION_CREATE:
- if (clientCtx->token[0] != '\0') {
+ case AFB_SESSION_CREATE:
+ if (clientCtx->token[0] != '\0' && request->config->token[0] != '\0') {
request->errcode=MHD_HTTP_UNAUTHORIZED;
json_object_object_add(jcall, "status", json_object_new_string ("exist"));
json_object_object_add(jcall, "info", json_object_new_string ("AFB_SESSION_CREATE Session already exist"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
}
if (AFB_SUCCESS != ctxTokenCreate (clientCtx, request)) {
json_object_object_add(jcall, "status", json_object_new_string ("fail"));
json_object_object_add(jcall, "info", json_object_new_string ("AFB_SESSION_CREATE Invalid Initial Token"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
} else {
json_object_object_add(jcall, "uuid", json_object_new_string (clientCtx->uuid));
json_object_object_add(jcall, "token", json_object_new_string (clientCtx->token));
json_object_object_add(jcall, "status", json_object_new_string ("fail"));
json_object_object_add(jcall, "info", json_object_new_string ("AFB_SESSION_REFRESH Broken Exchange Token Chain"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
} else {
json_object_object_add(jcall, "uuid", json_object_new_string (clientCtx->uuid));
json_object_object_add(jcall, "token", json_object_new_string (clientCtx->token));
json_object_object_add(jcall, "status", json_object_new_string ("empty"));
json_object_object_add(jcall, "info", json_object_new_string ("AFB_SESSION_CLOSE Not a Valid Access Token"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
} else {
json_object_object_add(jcall, "uuid", json_object_new_string (clientCtx->uuid));
}
json_object_object_add(jcall, "status", json_object_new_string ("fail"));
json_object_object_add(jcall, "info", json_object_new_string ("AFB_SESSION_CHECK Invalid Active Token"));
json_object_object_add(jreqt, "request", jcall);
- return (AFB_DONE);
+ goto ExitOnDone;
}
break;
}
// Effectively CALL PLUGIN API with a subset of the context
jresp = plugin->apis[idx].callback(request, context);
- // prefix response with request object;
- request->jresp = jreqt;
-
// Store context in case it was updated by plugins
if (request->context != NULL) clientCtx->contexts[plugidx] = request->context;
// API should return NULL of a valid Json Object
if (jresp == NULL) {
json_object_object_add(jcall, "status", json_object_new_string ("null"));
- json_object_object_add(request->jresp, "request", jcall);
+ json_object_object_add(jreqt, "request", jcall);
request->errcode = MHD_HTTP_NO_RESPONSE;
} else {
json_object_object_add(jcall, "status", json_object_new_string ("processed"));
- json_object_object_add(request->jresp, "request", jcall);
- json_object_object_add(request->jresp, "response", jresp);
+ json_object_object_add(jreqt, "request", jcall);
+ json_object_object_add(jreqt, "response", jresp);
}
// cancel timeout and plugin signal handle before next call
if (request->config->apiTimeout > 0) {
}
}
}
- return (AFB_DONE);
+ goto ExitOnDone;
}
}
return (AFB_FAIL);
+
+ExitOnDone:
+ request->jresp = jreqt;
+ return (AFB_DONE);
}
STATIC AFB_error findAndCallApi (AFB_request *request, void *context) {
AFB_request *request = (AFB_request*)postHandle->privatebuf;
AFB_PostRequest postRequest;
- fprintf (stderr, "postHandle key=%s filename=%s len=%d mime=%s\n", key, filename, size, mimetype);
+ if (verbose)
+ fprintf (stderr, "postHandle key=%s filename=%s len=%d mime=%s\n", key, filename, size, mimetype);
// Create and Item value for Plugin API
item.kind = kind;
// client did not pass token on URI let's use cookies
if ((!request->restfull) && (request->context != NULL)) {
char cookie[256];
- snprintf (cookie, sizeof (cookie), "%s=%s;path=%s;max-age=%d", COOKIE_NAME, request->uuid, request->config->rootapi,request->config->cntxTimeout);
+ snprintf (cookie, sizeof (cookie), "%s-%d=%s; Path=%s; Max-Age=%d; HttpOnly", COOKIE_NAME, request->config->httpdPort, request->uuid, request->config->rootapi,request->config->cntxTimeout);
MHD_add_response_header (webResponse, MHD_HTTP_HEADER_SET_COOKIE, cookie);
}