/* interface for the request */
const struct afb_request_itf *itf;
- /* current dynapi if dynapi (is NULL for bindings v1 and v2) */
+ /* current dynapi (if any) */
struct afb_dynapi *dynapi;
/* closure associated with the callback processing the verb of the request
* as given at its declaration */
void *vcbdata;
+
+ /* the name of the called verb */
+ const char *api;
+
+ /* the name of the called verb */
+ const char *verb;
};
/*
/* creates the message */
msg = NULL;
- rc = sd_bus_message_new_method_call(api->sdbus, &msg, api->name, api->path, api->name, xreq->verb);
+ rc = sd_bus_message_new_method_call(api->sdbus, &msg, api->name, api->path, api->name, xreq->request.verb);
if (rc < 0)
goto error;
dreq->json = json_object_new_string(dreq->request);
}
dreq->listener = listener;
- dreq->xreq.api = api->api;
- dreq->xreq.verb = method;
+ dreq->xreq.request.api = api->api;
+ dreq->xreq.request.verb = method;
afb_xreq_process(&dreq->xreq, api->server.apiset);
return 1;
int i;
const char *name;
- name = xreq->verb;
+ name = xreq->request.verb;
xreq->request.dynapi = (void*)dynapi->export; /* hack: this avoids to export afb_export structure */
/* look first in dyna mic verbs */
const struct afb_verb_desc_v1 *verb;
struct api_so_v1 *desc = closure;
- verb = search(desc, xreq->verb);
+ xreq->request.dynapi = (void*)desc->export; /* hack: this avoids to export afb_export structure */
+ verb = search(desc, xreq->request.verb);
afb_xreq_call_verb_v1(xreq, verb);
}
struct api_so_v2 *desc = closure;
const struct afb_verb_v2 *verb;
- verb = search(desc, xreq->verb);
+ xreq->request.dynapi = (void*)desc->export; /* hack: this avoids to export afb_export structure */
+ verb = search(desc, xreq->request.verb);
afb_xreq_call_verb_v2(xreq, verb);
}
callreq->xreq.context.validated = 1;
copy = (char*)&callreq[1];
memcpy(copy, api, lenapi);
- callreq->xreq.api = copy;
+ callreq->xreq.request.api = copy;
copy = ©[lenapi];
memcpy(copy, verb, lenverb);
- callreq->xreq.verb = copy;
+ callreq->xreq.request.verb = copy;
callreq->xreq.listener = export->listener;
callreq->xreq.json = args;
callreq->export = export;
{
va_list ap;
va_start(ap, format);
- _hook_("xreq-%06d:%s/%s", format, ap, xreq->hookindex, xreq->api, xreq->verb);
+ _hook_("xreq-%06d:%s/%s", format, ap, xreq->hookindex, xreq->request.api, xreq->request.verb);
va_end(ap);
}
if (hook->itf->hook_xreq_##what \
&& (hook->flags & afb_hook_flag_req_##what) != 0 \
&& (!hook->session || hook->session == xreq->context.session) \
- && (!hook->api || !strcasecmp(hook->api, xreq->api)) \
- && (!hook->verb || !strcasecmp(hook->verb, xreq->verb))) { \
+ && (!hook->api || !strcasecmp(hook->api, xreq->request.api)) \
+ && (!hook->verb || !strcasecmp(hook->verb, xreq->request.verb))) { \
hook->itf->hook_xreq_##what(hook->closure, &hookid, __VA_ARGS__); \
} \
hook = hook->next; \
f = hook->flags & afb_hook_flags_req_all;
add = f != 0
&& (!hook->session || hook->session == xreq->context.session)
- && (!hook->api || !strcasecmp(hook->api, xreq->api))
- && (!hook->verb || !strcasecmp(hook->verb, xreq->verb));
+ && (!hook->api || !strcasecmp(hook->api, xreq->request.api))
+ && (!hook->verb || !strcasecmp(hook->verb, xreq->request.verb));
if (add)
flags |= f;
hook = hook->next;
}
afb_context_disconnect(&hreq->xreq.context);
json_object_put(hreq->json);
- free((char*)hreq->xreq.api);
- free((char*)hreq->xreq.verb);
+ free((char*)hreq->xreq.request.api);
+ free((char*)hreq->xreq.request.verb);
afb_cred_unref(hreq->xreq.cred);
free(hreq);
}
void afb_hreq_call(struct afb_hreq *hreq, struct afb_apiset *apiset, const char *api, size_t lenapi, const char *verb, size_t lenverb)
{
- hreq->xreq.api = strndup(api, lenapi);
- hreq->xreq.verb = strndup(verb, lenverb);
- if (hreq->xreq.api == NULL || hreq->xreq.verb == NULL) {
+ hreq->xreq.request.api = strndup(api, lenapi);
+ hreq->xreq.request.verb = strndup(verb, lenverb);
+ if (hreq->xreq.request.api == NULL || hreq->xreq.request.verb == NULL) {
ERROR("Out of memory");
afb_hreq_reply_error(hreq, MHD_HTTP_INTERNAL_SERVER_ERROR);
} else if (afb_hreq_init_context(hreq) < 0) {
{
struct afb_stub_ws *stubws = closure;
- afb_proto_ws_client_call(stubws->proto, xreq->verb, afb_xreq_json(xreq), afb_session_uuid(xreq->context.session), xreq);
+ afb_proto_ws_client_call(stubws->proto, xreq->request.verb, afb_xreq_json(xreq), afb_session_uuid(xreq->context.session), xreq);
afb_xreq_unhooked_addref(xreq);
}
/* makes the call */
wreq->xreq.cred = afb_cred_addref(stubws->cred);
- wreq->xreq.api = stubws->apiname;
- wreq->xreq.verb = verb;
+ wreq->xreq.request.api = stubws->apiname;
+ wreq->xreq.request.verb = verb;
wreq->xreq.json = args;
afb_xreq_process(&wreq->xreq, stubws->apiset);
return;
va_start(ap, format);
emit(closure, hookid, "request", "{si ss ss ss so* ss*}", format, ap,
"index", xreq->hookindex,
- "api", xreq->api,
- "verb", xreq->verb,
+ "api", xreq->request.api,
+ "verb", xreq->request.verb,
"action", action,
"credentials", cred,
"session", session);
afb_wsj1_msg_addref(msg);
wsreq->msgj1 = msg;
wsreq->xreq.cred = afb_cred_addref(ws->cred);
- wsreq->xreq.api = api;
- wsreq->xreq.verb = verb;
+ wsreq->xreq.request.api = api;
+ wsreq->xreq.request.verb = verb;
wsreq->xreq.json = afb_wsj1_msg_object_j(wsreq->msgj1);
wsreq->aws = afb_ws_json1_addref(ws);
wsreq->xreq.listener = wsreq->aws->listener;
afb_context_subinit(&subcall->xreq.context, &caller->context);
subcall->xreq.cred = afb_cred_addref(caller->cred);
subcall->xreq.json = args;
- subcall->xreq.api = api;
- subcall->xreq.verb = verb;
+ subcall->xreq.request.api = api;
+ subcall->xreq.request.verb = verb;
subcall->xreq.caller = caller;
afb_xreq_unhooked_addref(caller);
}
subcall->completion = completion;
if (subcall->xreq.caller->queryitf->subcall) {
subcall->xreq.caller->queryitf->subcall(
- subcall->xreq.caller, subcall->xreq.api, subcall->xreq.verb,
+ subcall->xreq.caller, subcall->xreq.request.api, subcall->xreq.request.verb,
subcall->xreq.json, subcall_reply_direct_cb, &subcall->xreq);
} else {
afb_xreq_unhooked_addref(&subcall->xreq);
if (!fmt || vasprintf(&p, fmt, args) < 0)
vverbose(level, file, line, func, fmt, args);
else {
- verbose(level, file, line, func, "[REQ/API %s] %s", xreq->api, p);
+ verbose(level, file, line, func, "[REQ/API %s] %s", xreq->request.api, p);
free(p);
}
}
void afb_xreq_fail_unknown_api(struct afb_xreq *xreq)
{
- afb_xreq_fail_f(xreq, "unknown-api", "api %s not found (for verb %s)", xreq->api, xreq->verb);
+ afb_xreq_fail_f(xreq, "unknown-api", "api %s not found (for verb %s)", xreq->request.api, xreq->request.verb);
}
void afb_xreq_fail_unknown_verb(struct afb_xreq *xreq)
{
- afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->verb, xreq->api);
+ afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->request.verb, xreq->request.api);
}
static void init_hooking(struct afb_xreq *xreq)
/* lookup at the api */
xreq->apiset = apiset;
- api = afb_apiset_lookup_started(apiset, xreq->api, 1);
+ api = afb_apiset_lookup_started(apiset, xreq->request.api, 1);
if (!api) {
if (errno == ENOENT)
- early_failure(xreq, "unknown-api", "api %s not found (for verb %s)", xreq->api, xreq->verb);
+ early_failure(xreq, "unknown-api", "api %s not found (for verb %s)", xreq->request.api, xreq->request.verb);
else
- early_failure(xreq, "bad-api-state", "api %s not started correctly: %m", xreq->api);
+ early_failure(xreq, "bad-api-state", "api %s not started correctly: %m", xreq->request.api);
goto end;
}
xreq->context.api_key = api;
while (caller) {
if (((const struct afb_api *)caller->context.api_key)->group == api->group) {
/* noconcurrency lock detected */
- ERROR("self-lock detected in call stack for API %s", xreq->api);
- early_failure(xreq, "self-locked", "recursive self lock, API %s", xreq->api);
+ ERROR("self-lock detected in call stack for API %s", xreq->request.api);
+ early_failure(xreq, "self-locked", "recursive self lock, API %s", xreq->request.api);
goto end;
}
caller = caller->caller;
struct afb_request request; /**< exported request */
struct afb_context context; /**< context of the request */
struct afb_apiset *apiset; /**< apiset of the xreq */
- const char *api; /**< the requested API */
- const char *verb; /**< the requested VERB */
struct json_object *json; /**< the json object (or NULL) */
const struct afb_xreq_query_itf *queryitf; /**< interface of xreq implmentation functions */
int refcount; /**< current ref count */
sreq->xreq.context.validated = 1;
sreq->api = strndup(api, verb - api);
sreq->verb = strndup(verb + 1, json - verb - 1);
- sreq->xreq.api = sreq->api;
- sreq->xreq.verb = sreq->verb;
+ sreq->xreq.request.api = sreq->api;
+ sreq->xreq.request.verb = sreq->verb;
sreq->xreq.json = json_tokener_parse(json + 1);
if (sreq->api && sreq->verb && sreq->xreq.json) {
afb_xreq_process(&sreq->xreq, main_apiset);