Add credential data to xreq
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 12 Apr 2017 15:56:20 +0000 (17:56 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 12 Apr 2017 15:56:20 +0000 (17:56 +0200)
This will allow soon to check the credentials when
evaluating calls.

Change-Id: I993216ccbc02538dcd92e49fcb2de0541eeb8c01
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-ws.c
src/afb-subcall.c
src/afb-svc.c
src/afb-ws-json1.c
src/afb-xreq.h
src/main.c

index 472a44d..3e0b281 100644 (file)
@@ -949,6 +949,7 @@ static void api_ws_server_called(struct api_ws_client *client, struct readbuf *r
        wreq->xreq.context.flags = flags;
 
        /* makes the call */
+       wreq->xreq.cred = afb_cred_addref(client->cred);
        wreq->xreq.api = client->api;
        wreq->xreq.verb = verb;
        afb_apis_call(&wreq->xreq);
@@ -1074,6 +1075,7 @@ static void api_ws_server_req_destroy_cb(struct afb_xreq *xreq)
        struct api_ws_server_req *wreq = CONTAINER_OF_XREQ(struct api_ws_server_req, xreq);
 
        afb_context_disconnect(&wreq->xreq.context);
+       afb_cred_unref(wreq->xreq.cred);
        json_object_put(wreq->xreq.json);
        free(wreq->rcvdata);
        api_ws_server_client_unref(wreq->client);
index 498f73b..a75cbdd 100644 (file)
@@ -28,6 +28,7 @@
 #include "afb-apis.h"
 #include "afb-context.h"
 #include "afb-xreq.h"
+#include "afb-cred.h"
 #include "verbose.h"
 #include "jobs.h"
 
@@ -58,6 +59,7 @@ static void subcall_destroy(struct afb_xreq *xreq)
        struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
 
        json_object_put(subcall->xreq.json);
+       afb_cred_unref(subcall->xreq.cred);
        afb_xreq_unref(subcall->caller);
        free(subcall);
 }
@@ -95,6 +97,7 @@ static struct subcall *create_subcall(struct afb_xreq *caller, const char *api,
 
        afb_xreq_init(&subcall->xreq, &afb_subcall_xreq_itf);
        afb_context_subinit(&subcall->xreq.context, &caller->context);
+       subcall->xreq.cred = afb_cred_addref(caller->cred);
        subcall->xreq.json = args;
        subcall->xreq.api = api; /* TODO: alloc ? */
        subcall->xreq.verb = verb; /* TODO: alloc ? */
index d493280..6b6b0a5 100644 (file)
@@ -30,6 +30,7 @@
 #include "afb-msg-json.h"
 #include "afb-svc.h"
 #include "afb-xreq.h"
+#include "afb-cred.h"
 #include "afb-apis.h"
 #include "verbose.h"
 
@@ -230,6 +231,7 @@ static void svc_call(void *closure, const char *api, const char *verb, struct js
        afb_xreq_init(&svcreq->xreq, &afb_svc_xreq_itf);
        afb_context_init(&svcreq->xreq.context, svc->session, NULL);
        svcreq->xreq.context.validated = 1;
+       svcreq->xreq.cred = afb_cred_current();
        svcreq->xreq.api = api;
        svcreq->xreq.verb = verb;
        svcreq->xreq.listener = svc->listener;
@@ -247,6 +249,7 @@ static void svcreq_destroy(struct afb_xreq *xreq)
        struct svc_req *svcreq = CONTAINER_OF_XREQ(struct svc_req, xreq);
        afb_context_disconnect(&svcreq->xreq.context);
        json_object_put(svcreq->xreq.json);
+       afb_cred_unref(svcreq->xreq.cred);
        free(svcreq);
 }
 
index 60a0a80..4e40571 100644 (file)
@@ -192,6 +192,7 @@ static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *ve
        /* fill and record the request */
        afb_wsj1_msg_addref(msg);
        wsreq->msgj1 = msg;
+       wsreq->xreq.cred = afb_cred_addref(ws->cred);
        wsreq->xreq.api = api;
        wsreq->xreq.verb = verb;
        wsreq->xreq.json = afb_wsj1_msg_object_j(wsreq->msgj1);
@@ -222,6 +223,7 @@ static void wsreq_destroy(struct afb_xreq *xreq)
 
        afb_context_disconnect(&wsreq->xreq.context);
        afb_wsj1_msg_unref(wsreq->msgj1);
+       afb_cred_unref(wsreq->xreq.cred);
        aws_unref(wsreq->aws);
        free(wsreq);
 }
index 4cd5820..f996302 100644 (file)
@@ -26,6 +26,7 @@
 struct json_object;
 struct afb_evt_listener;
 struct afb_xreq;
+struct afb_cred;
 
 struct afb_xreq_query_itf {
        struct json_object *(*json)(struct afb_xreq *xreq);
@@ -54,6 +55,7 @@ struct afb_xreq
        int hookflags;  /**< flags for hooking */
        int hookindex;  /**< index for hooking */
        struct afb_evt_listener *listener;
+       struct afb_cred *cred;
 };
 
 #define CONTAINER_OF_XREQ(type,x) ((type*)(((intptr_t)(x))-((intptr_t)&(((type*)NULL)->xreq))))
index 4dc6cb8..6684ed5 100644 (file)
@@ -44,6 +44,7 @@
 #include "afb-context.h"
 #include "afb-hreq.h"
 #include "afb-xreq.h"
+#include "afb-cred.h"
 #include "jobs.h"
 #include "afb-session.h"
 #include "verbose.h"
@@ -467,6 +468,7 @@ static void startup_call_unref(struct afb_xreq *xreq)
        free(sreq->api);
        free(sreq->verb);
        json_object_put(sreq->xreq.json);
+       afb_cred_unref(sreq->xreq.cred);
        sreq->current = sreq->current->next;
        if (sreq->current)
                startup_call_current(sreq);
@@ -496,6 +498,7 @@ static void startup_call_current(struct startup_req *sreq)
                        afb_xreq_init(&sreq->xreq, &startup_xreq_itf);
                        afb_context_init(&sreq->xreq.context, sreq->session, NULL);
                        sreq->xreq.context.validated = 1;
+                       sreq->xreq.cred = afb_cred_current();
                        sreq->api = strndup(api, verb - api);
                        sreq->verb = strndup(verb + 1, json - verb - 1);
                        sreq->xreq.api = sreq->api;