X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-session.c;h=f0cf07440c22ebd4ac6d3fc3502046f5e45895c3;hb=350f165da982685f2ea7c6d0899e9711b2c35982;hp=6b6ad634170cc1c7820d301e11f64e3db0b83bc0;hpb=e1b255b4c6486b0d2df5cd8b2aad8b817876ddf2;p=src%2Fapp-framework-binder.git diff --git a/src/afb-session.c b/src/afb-session.c index 6b6ad634..f0cf0744 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -33,8 +33,8 @@ #define SIZEUUID 37 #define HEADCOUNT 16 -#define COOKEYCOUNT 8 -#define COOKEYMASK (COOKEYCOUNT - 1) +#define COOKIECOUNT 8 +#define COOKIEMASK (COOKIECOUNT - 1) #define _MAXEXP_ ((time_t)(~(time_t)0)) #define _MAXEXP2_ ((time_t)((((unsigned long long)_MAXEXP_) >> 1))) @@ -56,7 +56,7 @@ struct afb_session int timeout; time_t expiration; // expiration time of the token pthread_mutex_t mutex; - struct cookie *cookies[COOKEYCOUNT]; + struct cookie *cookies[COOKIECOUNT]; char autoclose; char idx; char uuid[SIZEUUID]; // long term authentication of remote client @@ -98,7 +98,7 @@ static void close_session(struct afb_session *session) struct cookie *cookie; /* free cookies */ - for (idx = 0 ; idx < COOKEYCOUNT ; idx++) { + for (idx = 0 ; idx < COOKIECOUNT ; idx++) { while ((cookie = session->cookies[idx])) { session->cookies[idx] = cookie->next; if (cookie->freecb != NULL) @@ -124,8 +124,16 @@ static int pearson4(const char *text) return r; // % HEADCOUNT; } -// Create a new store in RAM, not that is too small it will be automatically extended -void afb_session_init (int max_session_count, int timeout, const char *initok) +/** + * Initialize the session manager with a 'max_session_count', + * an initial common 'timeout' and an initial common token 'initok'. + * + * @param max_session_count maximum allowed session count in the same time + * @param timeout the initial default timeout of sessions + * @param initok the initial default token of sessions + * + */ +int afb_session_init (int max_session_count, int timeout, const char *initok) { pthread_mutex_init(&sessions.mutex, NULL); sessions.max = max_session_count; @@ -137,8 +145,10 @@ void afb_session_init (int max_session_count, int timeout, const char *initok) strcpy(sessions.initok, initok); else { ERROR("initial token '%s' too long (max length %d)", initok, ((int)(sizeof sessions.initok)) - 1); - exit(1); + errno = EINVAL; + return -1; } + return 0; } const char *afb_session_initial_token() @@ -458,7 +468,7 @@ static int cookeyidx(const void *key) { intptr_t x = (intptr_t)key; unsigned r = (unsigned)((x >> 5) ^ (x >> 15)); - return r & COOKEYMASK; + return r & COOKIEMASK; } /**