aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-03-23 16:37:20 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-03-23 16:37:20 +0100
commitfe79c7ba875a9203020e72e82fa3524fd2fb74d2 (patch)
tree6439d725c771575cb8a668c82e6d99cc2bbe6f9f
parent2b1bd19ee26f4ee5b2010d830cdabed952a37be4 (diff)
session: removes file handling
Change-Id: Ib26a93bae5ef824fc570e634cf124b364b03fced Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--include/proto-def.h2
-rw-r--r--src/main.c2
-rw-r--r--src/session.c96
3 files changed, 53 insertions, 47 deletions
diff --git a/include/proto-def.h b/include/proto-def.h
index 3650fce7..877fafe9 100644
--- a/include/proto-def.h
+++ b/include/proto-def.h
@@ -43,10 +43,12 @@ extern void initPlugins (AFB_session *session);
extern AFB_plugin* pluginRegister ();
// Session handling
+#if defined(ALLOWS_SESSION_FILES)
extern AFB_error sessionCheckdir (AFB_session *session);
extern json_object *sessionList (AFB_session *session, AFB_request *request);
extern json_object *sessionToDisk (AFB_session *session, AFB_request *request, char *name,json_object *jsonSession);
extern json_object *sessionFromDisk (AFB_session *session, AFB_request *request, char *name);
+#endif
extern AFB_error ctxTokenRefresh (AFB_clientCtx *clientCtx, AFB_request *request);
extern AFB_error ctxTokenCreate (AFB_clientCtx *clientCtx, AFB_request *request);
diff --git a/src/main.c b/src/main.c
index fdf8a34b..f73cfac0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -532,11 +532,13 @@ int main(int argc, char *argv[]) {
// let's not take the risk to run as ROOT
//if (getuid() == 0) goto errorNoRoot;
+#if defined(ALLOWS_SESSION_FILES)
// check session dir and create if it does not exist
if (sessionCheckdir (session) != AFB_SUCCESS) {
fprintf (stderr,"\nERR: AFB-daemon cannot read/write session dir\n\n");
exit (1);
}
+#endif
if (verbose) fprintf (stderr, "AFB: notice Init config done\n");
// ---- run in foreground mode --------------------
diff --git a/src/session.c b/src/session.c
index 66876cd9..9d03d0a7 100644
--- a/src/session.c
+++ b/src/session.c
@@ -31,14 +31,6 @@
#include <search.h>
-#define AFB_SESSION_JTYPE "AFB_session"
-#define AFB_SESSION_JLIST "AFB_sessions.hash"
-#define AFB_SESSION_JINFO "AFB_infos"
-
-
-#define AFB_CURRENT_SESSION "active-session" // file link name within sndcard dir
-#define AFB_DEFAULT_SESSION "current-session" // should be in sync with UI
-
// Session UUID are store in a simple array [for 10 sessions this should be enough]
static struct {
pthread_mutex_t mutex; // declare a mutex to protect hash table
@@ -47,30 +39,15 @@ static struct {
int max;
} sessions;
-// verify we can read/write in session dir
-PUBLIC AFB_error sessionCheckdir (AFB_session *session) {
-
- int err;
-
- // in case session dir would not exist create one
- if (verbose) fprintf (stderr, "AFB:notice checking session dir [%s]\n", session->config->sessiondir);
- mkdir(session->config->sessiondir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+#if defined(ALLOWS_SESSION_FILES)
- // change for session directory
- err = chdir(session->config->sessiondir);
- if (err) {
- fprintf(stderr,"AFB: Fail to chdir to %s error=%s\n", session->config->sessiondir, strerror(err));
- return err;
- }
+#define AFB_SESSION_JTYPE "AFB_session"
+#define AFB_SESSION_JLIST "AFB_sessions.hash"
+#define AFB_SESSION_JINFO "AFB_infos"
- // verify we can write session in directory
- json_object *dummy= json_object_new_object();
- json_object_object_add (dummy, "checked" , json_object_new_int (getppid()));
- err = json_object_to_file ("./AFB-probe.json", dummy);
- if (err < 0) return err;
- return AFB_SUCCESS;
-}
+#define AFB_CURRENT_SESSION "active-session" // file link name within sndcard dir
+#define AFB_DEFAULT_SESSION "current-session" // should be in sync with UI
// let's return only sessions.hash files
STATIC int fileSelect (const struct dirent *entry) {
@@ -103,6 +80,48 @@ STATIC json_object *checkCardDirExit (AFB_session *session, AFB_request *reques
return NULL;
}
+// Create a link toward last used sessionname within sndcard directory
+STATIC void makeSessionLink (const char *cardname, const char *sessionname) {
+ char linkname [256], filename [256];
+ int err;
+ // create a link to keep track of last uploaded sessionname for this card
+ strncpy (filename, sessionname, sizeof(filename));
+ strncat (filename, ".afb", sizeof(filename));
+
+ strncpy (linkname, cardname, sizeof(linkname));
+ strncat (linkname, "/", sizeof(filename));
+ strncat (linkname, AFB_CURRENT_SESSION, sizeof(linkname));
+ strncat (linkname, ".afb", sizeof(filename));
+ unlink (linkname); // remove previous link if any
+ err = symlink (filename, linkname);
+ if (err < 0) fprintf (stderr, "Fail to create link %s->%s error=%s\n", linkname, filename, strerror(errno));
+}
+
+// verify we can read/write in session dir
+PUBLIC AFB_error sessionCheckdir (AFB_session *session) {
+
+ int err;
+
+ // in case session dir would not exist create one
+ if (verbose) fprintf (stderr, "AFB:notice checking session dir [%s]\n", session->config->sessiondir);
+ mkdir(session->config->sessiondir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+
+ // change for session directory
+ err = chdir(session->config->sessiondir);
+ if (err) {
+ fprintf(stderr,"AFB: Fail to chdir to %s error=%s\n", session->config->sessiondir, strerror(err));
+ return err;
+ }
+
+ // verify we can write session in directory
+ json_object *dummy= json_object_new_object();
+ json_object_object_add (dummy, "checked" , json_object_new_int (getppid()));
+ err = json_object_to_file ("./AFB-probe.json", dummy);
+ if (err < 0) return err;
+
+ return AFB_SUCCESS;
+}
+
// create a session in current directory
PUBLIC json_object *sessionList (AFB_session *session, AFB_request *request) {
json_object *sessionsJ, *ajgResponse;
@@ -163,23 +182,6 @@ PUBLIC json_object *sessionList (AFB_session *session, AFB_request *request) {
return (ajgResponse);
}
-// Create a link toward last used sessionname within sndcard directory
-STATIC void makeSessionLink (const char *cardname, const char *sessionname) {
- char linkname [256], filename [256];
- int err;
- // create a link to keep track of last uploaded sessionname for this card
- strncpy (filename, sessionname, sizeof(filename));
- strncat (filename, ".afb", sizeof(filename));
-
- strncpy (linkname, cardname, sizeof(linkname));
- strncat (linkname, "/", sizeof(filename));
- strncat (linkname, AFB_CURRENT_SESSION, sizeof(linkname));
- strncat (linkname, ".afb", sizeof(filename));
- unlink (linkname); // remove previous link if any
- err = symlink (filename, linkname);
- if (err < 0) fprintf (stderr, "Fail to create link %s->%s error=%s\n", linkname, filename, strerror(errno));
-}
-
// Load Json session object from disk
PUBLIC json_object *sessionFromDisk (AFB_session *session, AFB_request *request, char *name) {
json_object *jsonSession, *jtype, *response;
@@ -313,7 +315,7 @@ OnErrorExit:
json_object_put (jsonSession);
return response;
}
-
+#endif
// Free context [XXXX Should be protected again memory abort XXXX]
STATIC void ctxUuidFreeCB (AFB_clientCtx *client) {