summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto-def.h8
-rw-r--r--src/afb-rest-api.c6
-rw-r--r--src/main.c1
-rw-r--r--src/session.c9
-rw-r--r--src/session.h24
5 files changed, 31 insertions, 17 deletions
diff --git a/include/proto-def.h b/include/proto-def.h
index 87bc63b0..21e03035 100644
--- a/include/proto-def.h
+++ b/include/proto-def.h
@@ -38,14 +38,6 @@ extern void endPostRequest(AFB_PostHandle *posthandle);
extern int doRestApi(struct MHD_Connection *connection, AFB_session *session, const char* url, const char *method
, const char *upload_data, size_t *upload_data_size, void **con_cls);
-// Session handling
-extern AFB_error ctxTokenRefresh (AFB_clientCtx *clientCtx, AFB_request *request);
-extern AFB_error ctxTokenCreate (AFB_clientCtx *clientCtx, AFB_request *request);
-extern AFB_error ctxTokenCheck (AFB_clientCtx *clientCtx, AFB_request *request);
-extern AFB_error ctxTokenReset (AFB_clientCtx *clientCtx, AFB_request *request);
-extern AFB_clientCtx *ctxClientGet (AFB_request *request, int idx);
-extern void ctxStoreInit (int);
-
// Httpd server
diff --git a/src/afb-rest-api.c b/src/afb-rest-api.c
index febe19f8..0de762b1 100644
--- a/src/afb-rest-api.c
+++ b/src/afb-rest-api.c
@@ -79,14 +79,16 @@ static AFB_error doCallPluginApi(AFB_request * request, int apiidx, int verbidx,
if (AFB_SESSION_NONE != session) {
// add client context to request
- clientCtx = ctxClientGet(request, apiidx);
+ clientCtx = ctxClientGet(request);
if (clientCtx == NULL) {
request->errcode = MHD_HTTP_INSUFFICIENT_STORAGE;
json_object_object_add(jcall, "status", json_object_new_string("fail"));
json_object_object_add(jcall, "info", json_object_new_string("Client Session Context Full !!!"));
json_object_object_add(jreqt, "request", jcall);
goto ExitOnDone;
- };
+ }
+ request->context = clientCtx->contexts[apiidx];
+ request->uuid = clientCtx->uuid;
if (verbose)
fprintf(stderr, "Plugin=[%s] Api=[%s] Middleware=[%d] Client=[%p] Uuid=[%s] Token=[%s]\n", request->prefix, request->api, session, clientCtx, clientCtx->uuid, clientCtx->token);
diff --git a/src/main.c b/src/main.c
index b42f2ab6..400a55c0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,6 +27,7 @@
#include "local-def.h"
#include "afb-apis.h"
+#include "session.h"
#if !defined(PLUGIN_INSTALL_DIR)
#error "you should define PLUGIN_INSTALL_DIR"
diff --git a/src/session.c b/src/session.c
index 9569b46c..9504fdbe 100644
--- a/src/session.c
+++ b/src/session.c
@@ -31,6 +31,7 @@
#include <search.h>
#include "afb-apis.h"
+#include "session.h"
// Session UUID are store in a simple array [for 10 sessions this should be enough]
static struct {
@@ -169,7 +170,7 @@ void ctxStoreGarbage (const int timeout)
}
// This function will return exiting client context or newly created client context
-AFB_clientCtx *ctxClientGet (AFB_request *request, int apiidx)
+AFB_clientCtx *ctxClientGet (AFB_request *request)
{
AFB_clientCtx *clientCtx=NULL;
const char *uuid;
@@ -201,8 +202,6 @@ AFB_clientCtx *ctxClientGet (AFB_request *request, int apiidx)
ctxStoreDel (clientCtx);
clientCtx = NULL;
} else {
- request->context = clientCtx->contexts[apiidx];
- request->uuid = uuid;
return clientCtx;
}
}
@@ -225,10 +224,6 @@ AFB_clientCtx *ctxClientGet (AFB_request *request, int apiidx)
free (clientCtx);
return NULL;
}
-
- // if (verbose) fprintf (stderr, "ctxClientGet New uuid=[%s] token=[%s] timestamp=%d\n", clientCtx->uuid, clientCtx->token, clientCtx->timeStamp);
- request->context = clientCtx->contexts[apiidx];
- request->uuid = clientCtx->uuid;
return clientCtx;
}
diff --git a/src/session.h b/src/session.h
new file mode 100644
index 00000000..e3b9b811
--- /dev/null
+++ b/src/session.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016 IoT.bzh
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern AFB_error ctxTokenRefresh (AFB_clientCtx *clientCtx, AFB_request *request);
+extern AFB_error ctxTokenCreate (AFB_clientCtx *clientCtx, AFB_request *request);
+extern AFB_error ctxTokenCheck (AFB_clientCtx *clientCtx, AFB_request *request);
+extern AFB_error ctxTokenReset (AFB_clientCtx *clientCtx, AFB_request *request);
+extern AFB_clientCtx *ctxClientGet (AFB_request *request);
+extern void ctxStoreInit (int);
+