X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-apis.c;h=ca42743748292e650a3c48570dd567a093a64f8b;hb=1205c90cccd3144bab24b4b5fd8dcbf0d0e6b570;hp=3dcad65156fa668d46779299bd4909cefb51e983;hpb=cc4b56b6710624c069642d1a510d0060949fe5b9;p=src%2Fapp-framework-binder.git diff --git a/src/afb-apis.c b/src/afb-apis.c index 3dcad651..ca427437 100644 --- a/src/afb-apis.c +++ b/src/afb-apis.c @@ -35,6 +35,7 @@ #include "../include/local-def.h" +#include "afb-req-itf.h" #include "afb-apis.h" struct api_desc { @@ -278,3 +279,85 @@ int afb_apis_add_pathset(const char *pathset) }; } +/* +// Check of apiurl is declare in this plugin and call it +extern __thread sigjmp_buf *error_handler; +static int callPluginApi(AFB_request * request) +{ + sigjmp_buf jmpbuf, *older; + + // save context before calling the API + status = setjmp(jmpbuf); + if (status != 0) { + return 0; + } + + // Trigger a timer to protect from unacceptable long time execution + if (request->config->apiTimeout > 0) + alarm((unsigned)request->config->apiTimeout); + + older = error_handler; + error_handler = &jmpbuf; + doCallPluginApi(request, apiidx, verbidx, context); + error_handler = older; + + // cancel timeout and plugin signal handle before next call + alarm(0); + return 1; +} +*/ + +static void handle(struct afb_req req, const struct api_desc *api, const struct AFB_restapi *verb) +{ + AFB_request request; + + request.uuid = request.url = "fake"; + request.prefix = api->prefix; + request.method = verb->name; + request.context = NULL; + request.restfull = 0; + request.errcode = 0; + request.config = NULL; + request.areq = &req; + + switch(verb->session) { + case AFB_SESSION_CREATE: + case AFB_SESSION_RENEW: + /*if (check) new*/ + break; + case AFB_SESSION_CLOSE: + case AFB_SESSION_CHECK: + /*check*/ + break; + case AFB_SESSION_NONE: + default: + break; + } + verb->callback(&request, NULL); + + if (verb->session == AFB_SESSION_CLOSE) + /*del*/; +} + +int afb_apis_handle(struct afb_req req, const char *api, size_t lenapi, const char *verb, size_t lenverb) +{ + int i, j; + const struct api_desc *a; + const struct AFB_restapi *v; + + a = apis_array; + for (i = 0 ; i < apis_count ; i++, a++) { + if (a->prefixlen == lenapi && !strcasecmp(a->prefix, api)) { + v = a->plugin->apis; + for (j = 0 ; v->name ; j++, v++) { + if (!strncasecmp(v->name, verb, lenverb) && !v->name[lenverb]) { + handle(req, a, v); + return 1; + } + } + break; + } + } + return 0; +} +