Switch to unique token model
authorFulup Ar Foll <fulup@iot.bzh>
Tue, 29 Dec 2015 01:15:07 +0000 (02:15 +0100)
committerManuel Bachmann <manuel.bachmann@iot.bzh>
Tue, 29 Dec 2015 01:15:26 +0000 (02:15 +0100)
Token/Session Plugin is now able to issue a globally-valid
token (re-useable with all Plugins, so that an application
using multiple plugins is not forced to manage multiple
tokens anymore).

Adapt Audio & Radio Plugins to this model (init functions
do not create a token anymore, check for a prior existing
one).

Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
Author: Fulup Ar Foll <fulup@iot.bzh>
Author: Manuel Bachmann <manuel.bachmann@iot.bzh>

plugins/audio/audio-api.c
plugins/radio/radio-api.c
src/rest-api.c

index 4c7df8b..3877ce5 100644 (file)
@@ -58,7 +58,7 @@ STATIC void freeAudio (void *context) {
 
 /* ------ PUBLIC PLUGIN FUNCTIONS --------- */
 
-STATIC json_object* init (AFB_request *request) {       /* AFB_SESSION_CREATE */
+STATIC json_object* init (AFB_request *request) {        /* AFB_SESSION_CHECK */
 
     json_object *jresp;
     int idx;
@@ -225,7 +225,7 @@ STATIC json_object* ping (AFB_request *request) {         /* AFB_SESSION_NONE */
 }
 
 STATIC AFB_restapi pluginApis[]= {
-  {"init"    , AFB_SESSION_CREATE, (AFB_apiCB)init      , "Audio API - init"},
+  {"init"    , AFB_SESSION_CHECK,  (AFB_apiCB)init      , "Audio API - init"},
   {"volume"  , AFB_SESSION_CHECK,  (AFB_apiCB)volume    , "Audio API - volume"},
   {"channels", AFB_SESSION_CHECK,  (AFB_apiCB)channels  , "Audio API - channels"},
   {"mute"    , AFB_SESSION_CHECK,  (AFB_apiCB)mute      , "Audio API - mute"},
index 1cbf314..b09cea8 100644 (file)
@@ -126,7 +126,7 @@ STATIC void freeRadio (void *context, void *handle) {
 
 /* ------ PUBLIC PLUGIN FUNCTIONS --------- */
 
-STATIC json_object* init (AFB_request *request) {       /* AFB_SESSION_CREATE */
+STATIC json_object* init (AFB_request *request) {        /* AFB_SESSION_CHECK */
 
     json_object *jresp;
 
@@ -306,7 +306,7 @@ STATIC json_object* ping (AFB_request *request) {         /* AFB_SESSION_NONE */
 
 
 STATIC AFB_restapi pluginApis[]= {
-  {"init"   , AFB_SESSION_CREATE, (AFB_apiCB)init       , "Radio API - init"},
+  {"init"   , AFB_SESSION_CHECK,  (AFB_apiCB)init       , "Radio API - init"},
   {"power"  , AFB_SESSION_CHECK,  (AFB_apiCB)power      , "Radio API - power"},
   {"mode"   , AFB_SESSION_CHECK,  (AFB_apiCB)mode       , "Radio API - mode"},
   {"freq"   , AFB_SESSION_CHECK,  (AFB_apiCB)freq       , "Radio API - freq"},
index 398ba57..2596f30 100644 (file)
@@ -510,7 +510,7 @@ ProcessApiCall:
     // client did not pass token on URI let's use cookies 
     if ((!request->restfull) && (request->context != NULL)) {
        char cookie[64]; 
-       snprintf (cookie, sizeof (cookie), "%s=%s", COOKIE_NAME,  request->uuid); 
+       snprintf (cookie, sizeof (cookie), "%s=%s;path=/api;max-age=%d", COOKIE_NAME, request->uuid, request->config->cntxTimeout); 
        MHD_add_response_header (webResponse, MHD_HTTP_HEADER_SET_COOKIE, cookie);
     }