#define _MAXEXP_ ((time_t)(~(time_t)0))
#define _MAXEXP2_ ((time_t)((((unsigned long long)_MAXEXP_) >> 1)))
#define MAX_EXPIRATION (_MAXEXP_ >= 0 ? _MAXEXP_ : _MAXEXP2_)
-#define NOW (time(NULL))
+#define NOW (time_now())
struct cookie
{
time_t expiration; // expiration time of the token
pthread_mutex_t mutex;
struct cookie *cookies[COOKEYCOUNT];
+ char autoclose;
char idx;
char uuid[SIZEUUID]; // long term authentication of remote client
char token[SIZEUUID]; // short term authentication of remote client
char initok[SIZEUUID];
} sessions;
+/* Get the actual raw time */
+static inline time_t time_now()
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+ return ts.tv_sec;
+}
+
/* generate a uuid */
static void new_uuid(char uuid[SIZEUUID])
{
assert(session->refcount != 0);
if (!__atomic_sub_fetch(&session->refcount, 1, __ATOMIC_RELAXED)) {
pthread_mutex_lock(&session->mutex);
- if (session->uuid[0] == 0)
+ if (session->autoclose || session->uuid[0] == 0)
destroy (session);
else
pthread_mutex_unlock(&session->mutex);
pthread_mutex_unlock(&session->mutex);
}
+/* set the autoclose flag */
+void afb_session_set_autoclose(struct afb_session *session, int autoclose)
+{
+ assert(session != NULL);
+ session->autoclose = (char)!!autoclose;
+}
+
// is the session active?
int afb_session_is_active (struct afb_session *session)
{