split api handling
[src/app-framework-binder.git] / src / afb-websock.c
index 797724c..878df04 100644 (file)
 #include <json.h>
 
 #include <openssl/sha.h>
-/*
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-*/
 
 #include "websock.h"
 
-#include "local-def.h"
-
 #include "afb-req-itf.h"
 #include "afb-method.h"
 #include "afb-hreq.h"
@@ -373,9 +367,7 @@ static int aws_handle_json(struct afb_websock *aws, struct json_object *obj)
 
        r.data = wsreq;
        r.itf = &wsreq_itf;
-       rc = afb_apis_handle(r, aws->context, api, lenapi, verb, lenverb);
-       if (rc == 0)
-               wsreq_fail(wsreq, "ail", "api not found");
+       afb_apis_call(r, aws->context, api, lenapi, verb, lenverb);
        return 1;
 
 error:
@@ -420,12 +412,13 @@ static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name)
        if (json_object_object_get_ex(wsreq->request, name, &value)) {
                arg.name = name;
                arg.value = json_object_get_string(value);
+               arg.size = strlen(arg.value);
        } else {
                arg.name = NULL;
                arg.value = NULL;
+               arg.size = 0;
        }
-       arg.size = 0;
-       arg.is_file = 0;
+       arg.path = NULL;
        return arg;
 }
 
@@ -436,7 +429,7 @@ static void wsreq_iterate(struct afb_wsreq *wsreq, int (*iterator)(void *closure
        struct json_object_iterator end = json_object_iter_end(wsreq->request);
 
        arg.size = 0;
-       arg.is_file = 0;
+       arg.path = NULL;
        while(!json_object_iter_equal(&it, &end)) {
                arg.name = json_object_iter_peek_name(&it);
                arg.value = json_object_get_string(json_object_iter_peek_value(&it));
@@ -509,6 +502,7 @@ static void wsreq_reply(struct afb_wsreq *wsreq, int retcode, const char *status
        /* emits the reply */
        message = json_object_to_json_string(reply);
        websock_text(wsreq->aws->ws, message, strlen(message));
+       json_object_put(reply);
 
        /* TODO eliminates the wsreq */
 }