diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-04-12 17:56:20 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-04-12 17:56:20 +0200 |
commit | a138fda9841c46e28de93e32aee62956e26556b1 (patch) | |
tree | ebb792f5d289f4a027a29b5fb573807ab2240327 | |
parent | 09010fa0093bee944738b728bf3277961d9bd6d7 (diff) |
Add credential data to xreq
This will allow soon to check the credentials when
evaluating calls.
Change-Id: I993216ccbc02538dcd92e49fcb2de0541eeb8c01
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-api-ws.c | 2 | ||||
-rw-r--r-- | src/afb-subcall.c | 3 | ||||
-rw-r--r-- | src/afb-svc.c | 3 | ||||
-rw-r--r-- | src/afb-ws-json1.c | 2 | ||||
-rw-r--r-- | src/afb-xreq.h | 2 | ||||
-rw-r--r-- | src/main.c | 3 |
6 files changed, 15 insertions, 0 deletions
diff --git a/src/afb-api-ws.c b/src/afb-api-ws.c index 472a44d4..3e0b281c 100644 --- a/src/afb-api-ws.c +++ b/src/afb-api-ws.c @@ -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); diff --git a/src/afb-subcall.c b/src/afb-subcall.c index 498f73b5..a75cbdd0 100644 --- a/src/afb-subcall.c +++ b/src/afb-subcall.c @@ -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 ? */ diff --git a/src/afb-svc.c b/src/afb-svc.c index d4932802..6b6b0a53 100644 --- a/src/afb-svc.c +++ b/src/afb-svc.c @@ -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); } diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c index 60a0a801..4e405715 100644 --- a/src/afb-ws-json1.c +++ b/src/afb-ws-json1.c @@ -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); } diff --git a/src/afb-xreq.h b/src/afb-xreq.h index 4cd58209..f9963024 100644 --- a/src/afb-xreq.h +++ b/src/afb-xreq.h @@ -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)))) @@ -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; |