- static char sep[] = ":";
- char *ps, *p;
- int rc;
-
- ps = strdupa(pathset);
- for (;;) {
- p = strsep(&ps, sep);
- if (!p)
- return 0;
- rc = afb_apis_add_path(p);
- };
-}
-
-// Check of apiurl is declare in this plugin and call it
-extern __thread sigjmp_buf *error_handler;
-static void trapping_handle(struct afb_req req, void(*cb)(struct afb_req))
-{
- volatile int signum, timerset;
- timer_t timerid;
- sigjmp_buf jmpbuf, *older;
- struct sigevent sevp;
- struct itimerspec its;
-
- // save context before calling the API
- timerset = 0;
- older = error_handler;
- signum = setjmp(jmpbuf);
- if (signum != 0) {
- afb_req_fail_f(req, "aborted", "signal %d caught", signum);
- }
- else {
- error_handler = &jmpbuf;
- if (api_timeout > 0) {
- timerset = 1; /* TODO: check statuses */
- sevp.sigev_notify = SIGEV_THREAD_ID;
- sevp.sigev_signo = SIGALRM;
-#if defined(sigev_notify_thread_id)
- sevp.sigev_notify_thread_id = (pid_t)syscall(SYS_gettid);
-#else
- sevp._sigev_un._tid = (pid_t)syscall(SYS_gettid);
-#endif
- timer_create(CLOCK_THREAD_CPUTIME_ID, &sevp, &timerid);
- its.it_interval.tv_sec = 0;
- its.it_interval.tv_nsec = 0;
- its.it_value.tv_sec = api_timeout;
- its.it_value.tv_nsec = 0;
- timer_settime(timerid, 0, &its, NULL);
- }
-
- cb(req);
- }
- if (timerset)
- timer_delete(timerid);
- error_handler = older;
-}
-
-static void handle(struct afb_req req, const struct AFB_restapi *verb)
-{
- switch(verb->session) {
- case AFB_SESSION_CREATE:
- if (!afb_req_session_create(req))
- return;
- break;
- case AFB_SESSION_RENEW:
- if (!afb_req_session_check(req, 1))
- return;
- break;
- case AFB_SESSION_CLOSE:
- case AFB_SESSION_CHECK:
- if (!afb_req_session_check(req, 0))
- return;
- break;
- case AFB_SESSION_NONE:
- default:
- break;
- }
- trapping_handle(req, verb->callback);
-
- if (verb->session == AFB_SESSION_CLOSE)
- afb_req_session_close(req);
-}
-
-int afb_apis_handle(struct afb_req req, struct AFB_clientCtx *context, const char *api, size_t lenapi, const char *verb, size_t lenverb)
-{
- int i, j;