- afb_apis_call(req, context, api, strlen(api), verb, strlen(verb));
+ int i, c, up, lo;
+ const struct api_desc *a;
+
+ /* dichotomic search of the api */
+ /* initial slice */
+ lo = 0;
+ up = apis_count;
+ for (;;) {
+ /* check remaining slice */
+ if (lo >= up) {
+ /* not found */
+ return NULL;
+ }
+ /* check the mid of the slice */
+ i = (lo + up) >> 1;
+ a = &apis_array[i];
+ c = strcasecmp(a->name, api);
+ if (c == 0) {
+ /* found */
+ return a;
+ }
+ /* update the slice */
+ if (c < 0)
+ lo = i + 1;
+ else
+ up = i;
+ }
+}
+
+/**
+ * Dispatch the request 'req' with the 'context' to the
+ * method of 'api' and 'verb'.
+ * @param req the request to dispatch
+ * @param context the context of the request
+ * @param api the api of the verb
+ * @param verb the verb within the api
+ */
+void afb_apis_call(struct afb_req req, struct afb_context *context, const char *api, const char *verb)
+{
+ const struct api_desc *a;
+
+ /* init hooking the request */
+ req = afb_hook_req_call(req, context, api, verb);
+
+ /* search the api */
+ a = search(api);
+ if (!a)
+ afb_req_fail(req, "fail", "api not found");
+ else {
+ context->api_key = a->api.closure;
+ a->api.call(a->api.closure, req, context, verb);
+ }