Add computation of credentials
[src/app-framework-binder.git] / src / afb-api-ws.c
index 663170e..8be74c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 #include "afb-common.h"
 
-#include "session.h"
+#include "afb-session.h"
+#include "afb-cred.h"
 #include "afb-ws.h"
 #include "afb-msg-json.h"
 #include "afb-apis.h"
 #include "afb-api-so.h"
 #include "afb-context.h"
 #include "afb-evt.h"
-#include "afb-subcall.h"
+#include "afb-xreq.h"
 #include "verbose.h"
+#include "sd-fds.h"
 
 struct api_ws_memo;
 struct api_ws_event;
@@ -124,6 +126,9 @@ struct api_ws_client
 
        /* websocket */
        struct afb_ws *ws;
+
+       /* credentials */
+       struct afb_cred *cred;
 };
 
 /******************* websocket interface for client part **********************************/
@@ -146,44 +151,26 @@ static const struct afb_ws_itf api_ws_server_ws_itf =
  * structure for a ws request
  */
 struct api_ws_server_req {
-       struct afb_context context;     /* the context, should be THE FIRST */
+       struct afb_xreq xreq;           /* the xreq */
        struct api_ws_client *client;   /* the client of the request */
        char *rcvdata;                  /* the received data to free */
-       struct json_object *json;       /* the readen request as object */
        const char *request;            /* the readen request as string */
        size_t lenreq;                  /* the length of the request */
-       int refcount;                   /* reference count of the request */
        uint32_t msgid;                 /* the incoming request msgid */
 };
 
-static struct json_object *api_ws_server_req_json(struct api_ws_server_req *wreq);
-static struct afb_arg api_ws_server_req_get(struct api_ws_server_req *wreq, const char *name);
-static void api_ws_server_req_success(struct api_ws_server_req *wreq, struct json_object *obj, const char *info);
-static void api_ws_server_req_fail(struct api_ws_server_req *wreq, const char *status, const char *info);
-static const char *api_ws_server_req_raw(struct api_ws_server_req *wreq, size_t *size);
-static void api_ws_server_req_send(struct api_ws_server_req *wreq, const char *buffer, size_t size);
-static void api_ws_server_req_addref(struct api_ws_server_req *wreq);
-static void api_ws_server_req_unref(struct api_ws_server_req *wreq);
-static int api_ws_server_req_subscribe(struct api_ws_server_req *wreq, struct afb_event event);
-static int api_ws_server_req_unsubscribe(struct api_ws_server_req *wreq, struct afb_event event);
-static void api_ws_server_req_subcall(struct api_ws_server_req *wreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure);
-
-const struct afb_req_itf afb_api_ws_req_itf = {
-       .json = (void*)api_ws_server_req_json,
-       .get = (void*)api_ws_server_req_get,
-       .success = (void*)api_ws_server_req_success,
-       .fail = (void*)api_ws_server_req_fail,
-       .raw = (void*)api_ws_server_req_raw,
-       .send = (void*)api_ws_server_req_send,
-       .context_get = (void*)afb_context_get,
-       .context_set = (void*)afb_context_set,
-       .addref = (void*)api_ws_server_req_addref,
-       .unref = (void*)api_ws_server_req_unref,
-       .session_close = (void*)afb_context_close,
-       .session_set_LOA = (void*)afb_context_change_loa,
-       .subscribe = (void*)api_ws_server_req_subscribe,
-       .unsubscribe = (void*)api_ws_server_req_unsubscribe,
-       .subcall = (void*)api_ws_server_req_subcall
+static void api_ws_server_req_success_cb(void *closure, struct json_object *obj, const char *info);
+static void api_ws_server_req_fail_cb(void *closure, const char *status, const char *info);
+static void api_ws_server_req_destroy_cb(void *closure);
+static int api_ws_server_req_subscribe_cb(void *closure, struct afb_event event);
+static int api_ws_server_req_unsubscribe_cb(void *closure, struct afb_event event);
+
+const struct afb_xreq_query_itf afb_api_ws_xreq_itf = {
+       .success = api_ws_server_req_success_cb,
+       .fail = api_ws_server_req_fail_cb,
+       .unref = api_ws_server_req_destroy_cb,
+       .subscribe = api_ws_server_req_subscribe_cb,
+       .unsubscribe = api_ws_server_req_unsubscribe_cb
 };
 
 /******************* common part **********************************/
@@ -205,12 +192,14 @@ static struct api_ws *api_ws_make(const char *path)
        }
 
        /* path is copied after the struct */
-       api->path = (void*)(api+1);
+       api->path = (char*)(api+1);
        memcpy(api->path, path, length + 1);
 
        /* api name is at the end of the path */
-       api->api = strrchr(api->path, '/');
-       if (api->api == NULL || !afb_apis_is_valid_api_name(++api->api)) {
+       while (length && path[length - 1] != '/' && path[length - 1] != ':')
+               length = length - 1;
+       api->api = &api->path[length];
+       if (api->api == NULL || !afb_apis_is_valid_api_name(api->api)) {
                errno = EINVAL;
                goto error2;
        }
@@ -281,7 +270,7 @@ static int api_ws_socket_inet(const char *path, int server)
        rc = getaddrinfo(host, service, &hint, &rai);
        if (rc != 0) {
                errno = EINVAL;
-               return NULL;
+               return -1;
        }
 
        /* get the socket */
@@ -311,21 +300,29 @@ static int api_ws_socket(const char *path, int server)
 {
        int fd, rc;
 
-       /* check for unix socket */
-       if (0 == strncmp(path, "unix:", 5))
-               fd = api_ws_socket_unix(path + 5, server);
-       else
-               fd = api_ws_socket_inet(path, server);
-
-       if (fd >= 0) {
-               fcntl(fd, F_SETFD, FD_CLOEXEC);
-               fcntl(fd, F_SETFL, O_NONBLOCK);
-               if (server) {
+       /* check for systemd socket */
+       if (0 == strncmp(path, "sd:", 3))
+               fd = sd_fds_for(path + 3);
+       else {
+               /* check for unix socket */
+               if (0 == strncmp(path, "unix:", 5))
+                       /* unix socket */
+                       fd = api_ws_socket_unix(path + 5, server);
+               else
+                       /* inet socket */
+                       fd = api_ws_socket_inet(path, server);
+
+               if (fd >= 0 && server) {
                        rc = 1;
                        setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc);
                        rc = listen(fd, 5);
                }
        }
+       /* configure the socket */
+       if (fd >= 0) {
+               fcntl(fd, F_SETFD, FD_CLOEXEC);
+               fcntl(fd, F_SETFL, O_NONBLOCK);
+       }
        return fd;
 }
 
@@ -417,12 +414,6 @@ static int api_ws_write_uint32(struct writebuf *wb, uint32_t value)
        return 1;
 }
 
-static int api_ws_write_string_nz(struct writebuf *wb, const char *value, size_t length)
-{
-       uint32_t len = (uint32_t)length;
-       return (size_t)len == length && ++len && api_ws_write_uint32(wb, len) && api_ws_write_put(wb, value, length) && api_ws_write_char(wb, '\0');
-}
-
 static int api_ws_write_string_length(struct writebuf *wb, const char *value, size_t length)
 {
        uint32_t len = (uint32_t)++length;
@@ -451,8 +442,11 @@ static int api_ws_write_object(struct writebuf *wb, struct json_object *object)
 struct api_ws_memo {
        struct api_ws_memo *next;               /* the next memo */
        struct api_ws *api;             /* the ws api */
+       struct afb_xreq *xreq;          /* the request handle */
+#if 0
        struct afb_req req;             /* the request handle */
        struct afb_context *context;    /* the context of the query */
+#endif
        uint32_t msgid;                 /* the message identifier */
 };
 
@@ -490,15 +484,14 @@ static struct api_ws_event *api_ws_client_event_search(struct api_ws *api, uint3
 
 
 /* allocates and init the memorizing data */
-static struct api_ws_memo *api_ws_client_memo_make(struct api_ws *api, struct afb_req req, struct afb_context *context)
+static struct api_ws_memo *api_ws_client_memo_make(struct api_ws *api, struct afb_xreq *xreq)
 {
        struct api_ws_memo *memo;
 
        memo = malloc(sizeof *memo);
        if (memo != NULL) {
-               afb_req_addref(req);
-               memo->req = req;
-               memo->context = context;
+               afb_xreq_addref(xreq);
+               memo->xreq = xreq;
                do { memo->msgid = ++api->client.id; } while(api_ws_client_memo_search(api, memo->msgid) != NULL);
                memo->api = api;
                memo->next = api->client.memos;
@@ -521,7 +514,7 @@ static void api_ws_client_memo_destroy(struct api_ws_memo *memo)
                prv = &(*prv)->next;
        }
 
-       afb_req_unref(memo->req);
+       afb_xreq_unref(memo->xreq);
        free(memo);
 }
 
@@ -651,7 +644,7 @@ static void api_ws_client_event_subscribe(struct api_ws *api, struct readbuf *rb
 
        if (api_ws_client_msg_subscription_get(api, rb, &ev, &memo)) {
                /* subscribe the request from the event */
-               if (afb_req_subscribe(memo->req, ev->event) < 0)
+               if (afb_xreq_subscribe(memo->xreq, ev->event) < 0)
                        ERROR("can't subscribe: %m");
        }
 }
@@ -664,7 +657,7 @@ static void api_ws_client_event_unsubscribe(struct api_ws *api, struct readbuf *
 
        if (api_ws_client_msg_subscription_get(api, rb, &ev, &memo)) {
                /* unsubscribe the request from the event */
-               if (afb_req_unsubscribe(memo->req, ev->event) < 0)
+               if (afb_xreq_unsubscribe(memo->xreq, ev->event) < 0)
                        ERROR("can't unsubscribe: %m");
        }
 }
@@ -707,11 +700,11 @@ static void api_ws_client_reply_success(struct api_ws *api, struct readbuf *rb)
        if (api_ws_read_uint32(rb, &flags)
         && api_ws_read_string(rb, &info, NULL)
         && api_ws_read_object(rb, &object)) {
-               memo->context->flags = (unsigned)flags;
-               afb_req_success(memo->req, object, *info ? info : NULL);
+               memo->xreq->context.flags = (unsigned)flags;
+               afb_xreq_success(memo->xreq, object, *info ? info : NULL);
        } else {
                /* failing to have the answer */
-               afb_req_fail(memo->req, "error", "ws error");
+               afb_xreq_fail(memo->xreq, "error", "ws error");
        }
        api_ws_client_memo_destroy(memo);
 }
@@ -729,33 +722,11 @@ static void api_ws_client_reply_fail(struct api_ws *api, struct readbuf *rb)
        if (api_ws_read_uint32(rb, &flags)
         && api_ws_read_string(rb, &status, NULL)
         && api_ws_read_string(rb, &info, NULL)) {
-               memo->context->flags = (unsigned)flags;
-               afb_req_fail(memo->req, status, *info ? info : NULL);
-       } else {
-               /* failing to have the answer */
-               afb_req_fail(memo->req, "error", "ws error");
-       }
-       api_ws_client_memo_destroy(memo);
-}
-
-static void api_ws_client_reply_send(struct api_ws *api, struct readbuf *rb)
-{
-       struct api_ws_memo *memo;
-       const char *data;
-       size_t length;
-       uint32_t flags;
-
-       /* retrieve the message data */
-       if (!api_ws_client_msg_memo_get(api, rb, &memo))
-               return;
-
-       if (api_ws_read_uint32(rb, &flags)
-        && api_ws_read_string(rb, &data, &length)) {
-               memo->context->flags = (unsigned)flags;
-               afb_req_send(memo->req, data, length);
+               memo->xreq->context.flags = (unsigned)flags;
+               afb_xreq_fail(memo->xreq, status, *info ? info : NULL);
        } else {
                /* failing to have the answer */
-               afb_req_fail(memo->req, "error", "ws error");
+               afb_xreq_fail(memo->xreq, "error", "ws error");
        }
        api_ws_client_memo_destroy(memo);
 }
@@ -772,9 +743,6 @@ static void api_ws_client_on_binary(void *closure, char *data, size_t size)
                case 'F': /* fail */
                        api_ws_client_reply_fail(closure, &rb);
                        break;
-               case 'X': /* send */
-                       api_ws_client_reply_send(closure, &rb);
-                       break;
                case '*': /* broadcast */
                        api_ws_client_event_broadcast(closure, &rb);
                        break;
@@ -797,32 +765,34 @@ static void api_ws_client_on_binary(void *closure, char *data, size_t size)
                        break;
                }
        }
+       free(data);
 }
 
 /* on call, propagate it to the ws service */
-static void api_ws_client_call(struct api_ws *api, struct afb_req req, struct afb_context *context, const char *verb, size_t lenverb)
+static void api_ws_client_call_cb(void * closure, struct afb_xreq *xreq)
 {
        int rc;
        struct api_ws_memo *memo;
        struct writebuf wb = { .count = 0 };
        const char *raw;
        size_t szraw;
+       struct api_ws *api = closure;
 
        /* create the recording data */
-       memo = api_ws_client_memo_make(api, req, context);
+       memo = api_ws_client_memo_make(api, xreq);
        if (memo == NULL) {
-               afb_req_fail(req, "error", "out of memory");
+               afb_xreq_fail_f(xreq, "error", "out of memory");
                return;
        }
 
        /* creates the call message */
-       raw = afb_req_raw(req, &szraw);
+       raw = afb_xreq_raw(xreq, &szraw);
        if (raw == NULL)
                goto internal_error;
        if (!api_ws_write_uint32(&wb, memo->msgid)
-        || !api_ws_write_uint32(&wb, (uint32_t)context->flags)
-        || !api_ws_write_string_nz(&wb, verb, lenverb)
-        || !api_ws_write_string(&wb, ctxClientGetUuid(context->session))
+        || !api_ws_write_uint32(&wb, (uint32_t)xreq->context.flags)
+        || !api_ws_write_string(&wb, xreq->verb)
+        || !api_ws_write_string(&wb, afb_session_uuid(xreq->context.session))
         || !api_ws_write_string_length(&wb, raw, szraw))
                goto overflow;
 
@@ -833,22 +803,24 @@ static void api_ws_client_call(struct api_ws *api, struct afb_req req, struct af
        return;
 
 ws_send_error:
-       afb_req_fail(req, "error", "websocket sending error");
+       afb_xreq_fail(xreq, "error", "websocket sending error");
        goto clean_memo;
 
 internal_error:
-       afb_req_fail(req, "error", "internal: raw is NULL!");
+       afb_xreq_fail(xreq, "error", "internal: raw is NULL!");
        goto clean_memo;
 
 overflow:
-       afb_req_fail(req, "error", "overflow: size doesn't match 32 bits!");
+       afb_xreq_fail(xreq, "error", "overflow: size doesn't match 32 bits!");
 
 clean_memo:
        api_ws_client_memo_destroy(memo);
 }
 
-static int api_ws_service_start(struct api_ws *api, int share_session, int onneed)
+static int api_ws_service_start_cb(void *closure, int share_session, int onneed)
 {
+       struct api_ws *api = closure;
+
        /* not an error when onneed */
        if (onneed != 0)
                return 0;
@@ -888,6 +860,11 @@ static int api_ws_client_connect(struct api_ws *api)
        return -1;
 }
 
+static struct afb_api_itf ws_api_itf = {
+       .call = api_ws_client_call_cb,
+       .service_start = api_ws_service_start_cb
+};
+
 /* adds a afb-ws-service client api */
 int afb_api_ws_add_client(const char *path)
 {
@@ -909,8 +886,7 @@ int afb_api_ws_add_client(const char *path)
 
        /* record it as an API */
        afb_api.closure = api;
-       afb_api.call = (void*)api_ws_client_call;
-       afb_api.service_start = (void*)api_ws_service_start;
+       afb_api.itf = &ws_api_itf;
        if (afb_apis_add(api->api, afb_api) < 0)
                goto error3;
 
@@ -931,6 +907,7 @@ static void api_ws_server_client_unref(struct api_ws_client *client)
        if (!--client->refcount) {
                afb_evt_listener_unref(client->listener);
                afb_ws_destroy(client->ws);
+               afb_cred_unref(client->cred);
                free(client);
        }
 }
@@ -939,7 +916,6 @@ static void api_ws_server_client_unref(struct api_ws_client *client)
 static void api_ws_server_called(struct api_ws_client *client, struct readbuf *rb, char *data, size_t size)
 {
        struct api_ws_server_req *wreq;
-       struct afb_req areq;
        const char *uuid, *verb;
        uint32_t flags;
 
@@ -952,7 +928,6 @@ static void api_ws_server_called(struct api_ws_client *client, struct readbuf *r
 
        wreq->client = client;
        wreq->rcvdata = data;
-       wreq->refcount = 1;
 
        /* reads the call message data */
        if (!api_ws_read_uint32(rb, &wreq->msgid)
@@ -962,16 +937,24 @@ static void api_ws_server_called(struct api_ws_client *client, struct readbuf *r
         || !api_ws_read_string(rb, &wreq->request, &wreq->lenreq))
                goto overflow;
 
+       wreq->xreq.json = json_tokener_parse(wreq->request);
+       if (wreq->xreq.json == NULL && strcmp(wreq->request, "null")) {
+               wreq->xreq.json = json_object_new_string(wreq->request);
+       }
+
        /* init the context */
-       if (afb_context_connect(&wreq->context, uuid, NULL) < 0)
+       if (afb_context_connect(&wreq->xreq.context, uuid, NULL) < 0)
                goto out_of_memory;
-       wreq->context.flags = flags;
+       wreq->xreq.context.flags = flags;
 
        /* makes the call */
-       areq.itf = &afb_api_ws_req_itf;
-       areq.closure = wreq;
-       afb_apis_call_(areq, &wreq->context, client->api, verb);
-       api_ws_server_req_unref(wreq);
+       wreq->xreq.refcount = 1;
+       wreq->xreq.api = client->api;
+       wreq->xreq.verb = verb;
+       wreq->xreq.query = wreq;
+       wreq->xreq.queryitf = &afb_api_ws_xreq_itf;
+       afb_apis_call(&wreq->xreq);
+       afb_xreq_unref(&wreq->xreq);
        return;
 
 out_of_memory:
@@ -1016,12 +999,16 @@ static void api_ws_server_accept(struct api_ws *api)
                        lenaddr = (socklen_t)sizeof addr;
                        client->fd = accept(api->fd, &addr, &lenaddr);
                        if (client->fd >= 0) {
+                               client->cred = afb_cred_create_for_socket(client->fd);
+                               fcntl(client->fd, F_SETFD, FD_CLOEXEC);
+                               fcntl(client->fd, F_SETFL, O_NONBLOCK);
                                client->ws = afb_ws_create(afb_common_get_event_loop(), client->fd, &api_ws_server_ws_itf, client);
                                if (client->ws != NULL) {
                                        client->api = api->api;
                                        client->refcount = 1;
                                        return;
                                }
+                               afb_cred_unref(client->cred);
                                close(client->fd);
                        }
                        afb_evt_listener_unref(client->listener);
@@ -1083,52 +1070,27 @@ static void api_ws_server_event_broadcast(void *closure, const char *event, int
 
 /******************* ws request part for server *****************/
 
-/* increment the reference count of the request */
-static void api_ws_server_req_addref(struct api_ws_server_req *wreq)
-{
-       wreq->refcount++;
-}
-
 /* decrement the reference count of the request and free/release it on falling to null */
-static void api_ws_server_req_unref(struct api_ws_server_req *wreq)
+static void api_ws_server_req_destroy_cb(void *closure)
 {
-       if (wreq == NULL || --wreq->refcount)
-               return;
+       struct api_ws_server_req *wreq = closure;
 
-       afb_context_disconnect(&wreq->context);
-       json_object_put(wreq->json);
+       afb_context_disconnect(&wreq->xreq.context);
+       json_object_put(wreq->xreq.json);
        free(wreq->rcvdata);
        api_ws_server_client_unref(wreq->client);
        free(wreq);
 }
 
-/* get the object of the request */
-static struct json_object *api_ws_server_req_json(struct api_ws_server_req *wreq)
-{
-       if (wreq->json == NULL) {
-               wreq->json = json_tokener_parse(wreq->request);
-               if (wreq->json == NULL && strcmp(wreq->request, "null")) {
-                       /* lazy error detection of json request. Is it to improve? */
-                       wreq->json = json_object_new_string(wreq->request);
-               }
-       }
-       return wreq->json;
-}
-
-/* get the argument of the request of 'name' */
-static struct afb_arg api_ws_server_req_get(struct api_ws_server_req *wreq, const char *name)
-{
-       return afb_msg_json_get_arg(api_ws_server_req_json(wreq), name);
-}
-
-static void api_ws_server_req_success(struct api_ws_server_req *wreq, struct json_object *obj, const char *info)
+static void api_ws_server_req_success_cb(void *closure, struct json_object *obj, const char *info)
 {
        int rc;
        struct writebuf wb = { .count = 0 };
+       struct api_ws_server_req *wreq = closure;
 
        if (api_ws_write_char(&wb, 'T')
         && api_ws_write_uint32(&wb, wreq->msgid)
-        && api_ws_write_uint32(&wb, (uint32_t)wreq->context.flags)
+        && api_ws_write_uint32(&wb, (uint32_t)wreq->xreq.context.flags)
         && api_ws_write_string(&wb, info ? : "")
         && api_ws_write_object(&wb, obj)) {
                rc = afb_ws_binary_v(wreq->client->ws, wb.iovec, wb.count);
@@ -1140,14 +1102,15 @@ success:
        json_object_put(obj);
 }
 
-static void api_ws_server_req_fail(struct api_ws_server_req *wreq, const char *status, const char *info)
+static void api_ws_server_req_fail_cb(void *closure, const char *status, const char *info)
 {
        int rc;
        struct writebuf wb = { .count = 0 };
+       struct api_ws_server_req *wreq = closure;
 
        if (api_ws_write_char(&wb, 'F')
         && api_ws_write_uint32(&wb, wreq->msgid)
-        && api_ws_write_uint32(&wb, (uint32_t)wreq->context.flags)
+        && api_ws_write_uint32(&wb, (uint32_t)wreq->xreq.context.flags)
         && api_ws_write_string(&wb, status)
         && api_ws_write_string(&wb, info ? : "")) {
                rc = afb_ws_binary_v(wreq->client->ws, wb.iovec, wb.count);
@@ -1157,34 +1120,11 @@ static void api_ws_server_req_fail(struct api_ws_server_req *wreq, const char *s
        ERROR("error while sending fail");
 }
 
-static const char *api_ws_server_req_raw(struct api_ws_server_req *wreq, size_t *size)
-{
-       if (size != NULL)
-               *size = wreq->lenreq;
-       return wreq->request;
-}
-
-static void api_ws_server_req_send(struct api_ws_server_req *wreq, const char *buffer, size_t size)
-{
-       /* TODO: how to put sized buffer as strings? things aren't clear here!!! */
-       int rc;
-       struct writebuf wb = { .count = 0 };
-
-       if (api_ws_write_char(&wb, 'X')
-        && api_ws_write_uint32(&wb, wreq->msgid)
-        && api_ws_write_uint32(&wb, (uint32_t)wreq->context.flags)
-        && api_ws_write_string_length(&wb, buffer, size)) {
-               rc = afb_ws_binary_v(wreq->client->ws, wb.iovec, wb.count);
-               if (rc >= 0)
-                       return;
-       }
-       ERROR("error while sending raw");
-}
-
-static int api_ws_server_req_subscribe(struct api_ws_server_req *wreq, struct afb_event event)
+static int api_ws_server_req_subscribe_cb(void *closure, struct afb_event event)
 {
        int rc, rc2;
        struct writebuf wb = { .count = 0 };
+       struct api_ws_server_req *wreq = closure;
 
        rc = afb_evt_add_watch(wreq->client->listener, event);
        if (rc < 0)
@@ -1203,10 +1143,11 @@ success:
        return rc;
 }
 
-static int api_ws_server_req_unsubscribe(struct api_ws_server_req *wreq, struct afb_event event)
+static int api_ws_server_req_unsubscribe_cb(void *closure, struct afb_event event)
 {
        int rc, rc2;
        struct writebuf wb = { .count = 0 };
+       struct api_ws_server_req *wreq = closure;
 
        if (api_ws_write_char(&wb, 'U')
         && api_ws_write_uint32(&wb, wreq->msgid)
@@ -1222,11 +1163,6 @@ success:
        return rc;
 }
 
-static void api_ws_server_req_subcall(struct api_ws_server_req *wreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure)
-{
-       afb_subcall(&wreq->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_api_ws_req_itf, .closure = wreq });
-}
-
 /******************* server part **********************************/
 
 static int api_ws_server_connect(struct api_ws *api);