- verbose(level, file, line, "%s {plugin %s}", p, desc->plugin->v1.prefix);
- free(p);
- }
-}
-
-static void monitored_call(int signum, struct monitoring *data)
-{
- if (signum != 0)
- afb_req_fail_f(data->req, "aborted", "signal %s(%d) caught", strsignal(signum), signum);
- else
- data->action(data->req);
-}
-
-static void call_check(struct afb_req req, struct afb_context *context, const struct AFB_verb_desc_v1 *verb)
-{
- struct monitoring data;
-
- int stag = (int)verb->session;
-
- if ((stag & (AFB_SESSION_CREATE|AFB_SESSION_CLOSE|AFB_SESSION_RENEW|AFB_SESSION_CHECK|AFB_SESSION_LOA_EQ)) != 0) {
- if (!afb_context_check(context)) {
- afb_context_close(context);
- afb_req_fail(req, "failed", "invalid token's identity");
- return;
- }
- }
-
- if ((stag & AFB_SESSION_CREATE) != 0) {
- if (afb_context_check_loa(context, 1)) {
- afb_req_fail(req, "failed", "invalid creation state");
- return;
- }
- afb_context_change_loa(context, 1);
- afb_context_refresh(context);
- }
-
- if ((stag & (AFB_SESSION_CREATE | AFB_SESSION_RENEW)) != 0)
- afb_context_refresh(context);
-
- if ((stag & AFB_SESSION_CLOSE) != 0) {
- afb_context_change_loa(context, 0);
- afb_context_close(context);
- }
-
- if ((stag & AFB_SESSION_LOA_GE) != 0) {
- int loa = (stag >> AFB_SESSION_LOA_SHIFT) & AFB_SESSION_LOA_MASK;
- if (!afb_context_check_loa(context, loa)) {
- afb_req_fail(req, "failed", "invalid LOA");
- return;
- }
- }
-
- if ((stag & AFB_SESSION_LOA_LE) != 0) {
- int loa = (stag >> AFB_SESSION_LOA_SHIFT) & AFB_SESSION_LOA_MASK;
- if (afb_context_check_loa(context, loa + 1)) {
- afb_req_fail(req, "failed", "invalid LOA");
- return;
- }
- }
-
- data.req = req;
- data.action = verb->callback;
- afb_sig_monitor((void*)monitored_call, &data, api_timeout);
-}
-
-static void call(struct api_so_desc *desc, struct afb_req req, struct afb_context *context, const char *verb, size_t lenverb)
-{
- const struct AFB_verb_desc_v1 *v;
-
- v = desc->plugin->v1.verbs;
- while (v->name && (strncasecmp(v->name, verb, lenverb) || v->name[lenverb]))
- v++;
- if (v->name)
- call_check(req, context, v);
- else
- afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, verb, desc->plugin->v1.prefix);
-}
-
-static int service_start(struct api_so_desc *desc, int share_session, int onneed)
-{
- int (*init)(struct afb_service service);
- void (*onevent)(const char *event, struct json_object *object);
-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->plugin->v1.prefix);
- return -1;
- }
-
- /* get the initialisation */
- init = dlsym(desc->handle, plugin_service_init_function_v1);
- if (init == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->plugin->v1.prefix);
- return -1;