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
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);
#include "local-def.h"
#include "afb-apis.h"
+#include "session.h"
#if !defined(PLUGIN_INSTALL_DIR)
#error "you should define PLUGIN_INSTALL_DIR"
#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 {
}
// 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;
ctxStoreDel (clientCtx);
clientCtx = NULL;
} else {
- request->context = clientCtx->contexts[apiidx];
- request->uuid = uuid;
return clientCtx;
}
}
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;
}
--- /dev/null
+/*
+ * 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);
+