aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-context.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-22 00:29:22 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-22 00:29:22 +0200
commit457c879ff89bc7f1a8864304974999dba54af9ae (patch)
tree5d18a69c237fac35896911bda1711a147b05fa98 /src/afb-context.c
parented4e7e3b0690680d963bc722bc259a424099e7e5 (diff)
Fix AFB_SESSION_CREATE behaviour
This commit allows to call methods having AFB_SESSION_CREATE at any time. This commit prepares the future LOA (level of authorization) implementation that wille soon replace the deprecated mechanism of AFB_SESSION_CREATE. Change-Id: Ia3e99186e012fcd55a6c81a7067ab5b4aca21e4d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-context.c')
-rw-r--r--src/afb-context.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/afb-context.c b/src/afb-context.c
index b00224e4..48787f79 100644
--- a/src/afb-context.c
+++ b/src/afb-context.c
@@ -31,6 +31,7 @@ static void init_context(struct afb_context *context, struct AFB_clientCtx *sess
context->session = session;
context->flags = 0;
context->api_index = -1;
+ context->loa_in = ctxClientGetLOA(session) & 7;
/* check the token */
if (token != NULL) {
@@ -55,19 +56,30 @@ int afb_context_connect(struct afb_context *context, const char *uuid, const cha
if (session == NULL)
return -1;
init_context(context, session, token);
- if (created)
+ if (created) {
context->created = 1;
+ context->refreshing = 1;
+ }
return 0;
}
void afb_context_disconnect(struct afb_context *context)
{
if (context->session != NULL) {
- if (context->closing && !context->closed) {
- context->closed = 1;
+ if (context->refreshing && !context->refreshed) {
+ ctxTokenNew (context->session);
+ context->refreshed = 1;
+ }
+ if (context->loa_changing && !context->loa_changed) {
+ ctxClientSetLOA (context->session, context->loa_out);
+ context->loa_changed = 1;
+ }
+ if (!context->closed) {
ctxClientClose(context->session);
+ context->closed = 1;
}
ctxClientUnref(context->session);
+ context->session = NULL;
}
}
@@ -75,7 +87,7 @@ const char *afb_context_sent_token(struct afb_context *context)
{
if (context->session == NULL || context->closing)
return NULL;
- if (!(context->created || context->refreshing))
+ if (!context->refreshing)
return NULL;
if (!context->refreshed) {
ctxTokenNew (context->session);
@@ -112,6 +124,7 @@ void afb_context_close(struct afb_context *context)
void afb_context_refresh(struct afb_context *context)
{
+ assert(context->validated);
context->refreshing = 1;
}
@@ -120,7 +133,21 @@ int afb_context_check(struct afb_context *context)
return context->validated;
}
-int afb_context_create(struct afb_context *context)
+int afb_context_check_loa(struct afb_context *context, unsigned loa)
+{
+ return context->loa_in >= loa;
+}
+
+void afb_context_change_loa(struct afb_context *context, unsigned loa)
{
- return context->created;
+ assert(context->validated);
+
+ if (loa == context->loa_in)
+ context->loa_changing = 0;
+ else {
+ context->loa_changing = 1;
+ context->loa_out = loa & 7;
+ }
}
+
+