X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Frest-api.c;h=c8a5029534f14e8f98d9ada8c26136f91f4686c9;hb=0d170147150b90678225b55548215d09d8273e6d;hp=06b6ea87a4cb7cb71a1de068e1e1a927cc050d1f;hpb=785a37416c58fb6f86d3d89cbff240ce9f2d7e74;p=src%2Fapp-framework-binder.git diff --git a/src/rest-api.c b/src/rest-api.c index 06b6ea87..c8a50295 100644 --- a/src/rest-api.c +++ b/src/rest-api.c @@ -95,7 +95,7 @@ PUBLIC int getQueryAll(AFB_request * request, char *buffer, size_t len) { PUBLIC void endPostRequest(AFB_PostHandle *postHandle) { if (postHandle->type == AFB_POST_JSON) { - if (verbose) fprintf(stderr, "End PostJson Request UID=%d\n", postHandle->uid); + // if (verbose) fprintf(stderr, "End PostJson Request UID=%d\n", postHandle->uid); } if (postHandle->type == AFB_POST_FORM) { @@ -178,7 +178,13 @@ 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 - ctxClientGet(request, plugin); + if (ctxClientGet(request, plugin) != 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 !!!")); + json_object_object_add(request->jresp, "request", jcall); + return (AFB_DONE); + }; if (verbose) fprintf(stderr, "Plugin=[%s] Api=[%s] Middleware=[%d] Client=[0x%x] Uuid=[%s] Token=[%s]\n" , request->plugin, request->api, plugin->apis[idx].session, request->client, request->client->uuid, request->client->token); @@ -428,6 +434,12 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co // Let make sure we have the right encoding and a valid length encoding = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_TYPE); + + // We are facing an empty post let's process it as a get + if (encoding == NULL) { + request= createRequest (connection, session, url); + goto ProcessApiCall; + } // Form post is handle through a PostProcessor and call API once per form key if (strcasestr(encoding, FORM_CONTENT) != NULL) { @@ -467,7 +479,7 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co postHandle->type = AFB_POST_JSON; postHandle->private = malloc(contentlen + 1); // allocate memory for full POST data + 1 for '\0' enf of string - if (verbose) fprintf(stderr, "Create PostJson[uid=%d] Size=%d\n", postHandle->uid, contentlen); + // if (verbose) fprintf(stderr, "Create PostJson[uid=%d] Size=%d\n", postHandle->uid, contentlen); return MHD_YES; } else { @@ -490,7 +502,7 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co // Process JsonPost request when buffer is completed let's call API if (postHandle->type == AFB_POST_JSON) { - if (verbose) fprintf(stderr, "Updating PostJson[uid=%d]\n", postHandle->uid); + // if (verbose) fprintf(stderr, "Updating PostJson[uid=%d]\n", postHandle->uid); memcpy(&postHandle->private[postHandle->len], upload_data, *upload_data_size); postHandle->len = postHandle->len + *upload_data_size; @@ -509,7 +521,7 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co if (postHandle->type == AFB_POST_JSON) { - if (verbose) fprintf(stderr, "Processing PostJson[uid=%d]\n", postHandle->uid); + // if (verbose) fprintf(stderr, "Processing PostJson[uid=%d]\n", postHandle->uid); param = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH); if (param) sscanf(param, "%i", &contentlen); @@ -526,18 +538,18 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co postRequest.type = postHandle->type; request->post = &postRequest; - if (verbose) fprintf(stderr, "Close Post[%d] Buffer=%s\n", postHandle->uid, request->post->data); + // if (verbose) fprintf(stderr, "Close Post[%d] Buffer=%s\n", postHandle->uid, request->post->data); } } } else { // this is a get we only need a request request= createRequest (connection, session, url); }; - + +ProcessApiCall: // Request is ready let's call API without any extra handle status = findAndCallApi (request, NULL); - -ExitOnResponse: + serialized = json_object_to_json_string(request->jresp); webResponse = MHD_create_response_from_buffer(strlen(serialized), (void*) serialized, MHD_RESPMEM_MUST_COPY); @@ -615,8 +627,10 @@ void initPlugins(AFB_session *session) { int i = 0; plugins[i++] = tokenRegister(session), - plugins[i++] = alsaRegister(session), plugins[i++] = helloWorldRegister(session), +#ifdef HAVE_AUDIO_PLUGIN + plugins[i++] = audioRegister(session), +#endif #ifdef HAVE_RADIO_PLUGIN plugins[i++] = radioRegister(session), #endif