- req = afb_hook_req_call(req, context, api, lenapi, verb, lenverb);
- a = apis_array;
- for (i = 0 ; i < apis_count ; i++, a++) {
- if (a->namelen == lenapi && !strncasecmp(a->name, api, lenapi)) {
- context->api_index = i;
- a->api.call(a->api.closure, req, context, verb, lenverb);
- return;
+ /* init hooking the request */
+ req = afb_hook_req_call(req, context, api, verb);
+
+ /* dichotomic search of the api */
+ /* initial slice */
+ lo = 0;
+ up = apis_count;
+ for (;;) {
+ /* check remaining slice */
+ if (lo >= up) {
+ /* empty ?! */
+ afb_req_fail(req, "fail", "api not found");
+ break;
+ }
+ /* check the mid of the slice */
+ i = (lo + up) >> 1;
+ a = &apis_array[i];
+ c = strcasecmp(a->name, api);
+ if (c == 0) {
+ /* api found */
+ context->api_key = a->api.closure;
+ a->api.call(a->api.closure, req, context, verb);
+ break;