-static void client_on_reply_fail(struct afb_proto_ws *protows, struct readbuf *rb)
-{
- struct client_call *call;
- const char *info, *status;
-
- if (!client_msg_call_get(protows, rb, &call))
- return;
-
-
- if (readbuf_string(rb, &status, NULL) && readbuf_string(rb, &info, NULL)) {
- protows->client_itf->on_reply_fail(protows->closure, call->request, status, info);
- } else {
- protows->client_itf->on_reply_fail(protows->closure, call->request, "proto-error", "can't process fail");
- }
- client_call_destroy(call);
-}
-
-/* send a subcall reply */
-static int client_send_subcall_reply(struct afb_proto_ws *protows, uint32_t subcallid, int status, json_object *object)
-{
- struct writebuf wb = { .count = 0 };
- char ie = status < 0;
- int rc;
-
- if (writebuf_char(&wb, CHAR_FOR_SUBCALL_REPLY)
- && writebuf_uint32(&wb, subcallid)
- && writebuf_char(&wb, ie)
- && writebuf_object(&wb, object)) {
- pthread_mutex_lock(&protows->mutex);
- rc = afb_ws_binary_v(protows->ws, wb.iovec, wb.count);
- pthread_mutex_unlock(&protows->mutex);
- if (rc >= 0)
- return 0;
- }
- return -1;
-}
-
-/* callback for subcall reply */
-int afb_proto_ws_subcall_reply(struct afb_proto_ws_subcall *subcall, int status, struct json_object *result)
-{
- int rc = client_send_subcall_reply(subcall->protows, subcall->subcallid, status, result);
- afb_proto_ws_unref(subcall->protows);
- free(subcall->buffer);
- free(subcall);
- return rc;
-}
-
-/* received a subcall request */
-static void client_on_subcall(struct afb_proto_ws *protows, struct readbuf *rb)
-{
- struct afb_proto_ws_subcall *subcall;
- struct client_call *call;
- const char *api, *verb;
- uint32_t subcallid;
- struct json_object *object;
-
- /* get the subcallid */
- if (!readbuf_uint32(rb, &subcallid))
- return;
-
- /* if not expected drop it */
- if (!protows->client_itf->on_subcall)
- goto error;
-
- /* retrieve the message data */
- if (!client_msg_call_get(protows, rb, &call))
- goto error;
-
- /* allocation of the subcall */
- subcall = malloc(sizeof *subcall);
- if (!subcall)
- goto error;
-
- /* make the call */
- if (readbuf_string(rb, &api, NULL)
- && readbuf_string(rb, &verb, NULL)
- && readbuf_object(rb, &object)) {
- afb_proto_ws_addref(protows);
- subcall->protows = protows;
- subcall->subcallid = subcallid;
- subcall->buffer = rb->base;
- rb->base = NULL;
- protows->client_itf->on_subcall(protows->closure, subcall, call->request, api, verb, object);
- return;
- }
- free(subcall);
-error:
- client_send_subcall_reply(protows, subcallid, 1, NULL);
-}
-