init_context(context, session, token);
if (created) {
context->created = 1;
- /* context->refreshing = 1; */
}
return 0;
}
void afb_context_disconnect(struct afb_context *context)
{
if (context->session && !context->super) {
- if (context->refreshing && !context->refreshed) {
- afb_session_new_token (context->session);
- context->refreshed = 1;
- }
if (context->closing && !context->closed) {
afb_context_change_loa(context, 0);
afb_context_set(context, NULL, NULL);
{
if (context->session == NULL || context->closing || context->super)
return NULL;
- if (!context->refreshing)
- return NULL;
- if (!context->refreshed) {
- afb_session_new_token (context->session);
- context->refreshed = 1;
- }
return afb_session_token(context->session);
}
context->closing = 1;
}
-void afb_context_refresh(struct afb_context *context)
-{
- if (context->super)
- afb_context_refresh(context->super);
- else {
- assert(context->validated);
- context->refreshing = 1;
- if (!context->refreshed) {
- afb_session_new_token (context->session);
- context->refreshed = 1;
- }
- }
-}
-
int afb_context_check(struct afb_context *context)
{
if (context->super)
unsigned created: 1;
unsigned validated: 1;
unsigned invalidated: 1;
- unsigned refreshing: 1;
- unsigned refreshed: 1;
unsigned closing: 1;
unsigned closed: 1;
};
extern void *afb_context_make(struct afb_context *context, int replace, void *(*make_value)(void *closure), void (*free_value)(void *item), void *closure);
extern void afb_context_close(struct afb_context *context);
-extern void afb_context_refresh(struct afb_context *context);
extern int afb_context_check(struct afb_context *context);
extern int afb_context_check_loa(struct afb_context *context, unsigned loa);
extern int afb_context_change_loa(struct afb_context *context, unsigned loa);
{ "common", afb_hook_flags_session_common },
{ "create", afb_hook_flag_session_create },
{ "destroy", afb_hook_flag_session_destroy },
- { "renew", afb_hook_flag_session_renew },
{ "unref", afb_hook_flag_session_unref },
};
_hook_session_(session, "destroy");
}
-static void hook_session_renew_cb(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
-{
- _hook_session_(session, "renew -> token=%s", afb_session_token(session));
-}
-
static void hook_session_addref_cb(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
{
_hook_session_(session, "addref");
.hook_session_create = hook_session_create_cb,
.hook_session_close = hook_session_close_cb,
.hook_session_destroy = hook_session_destroy_cb,
- .hook_session_renew = hook_session_renew_cb,
.hook_session_addref = hook_session_addref_cb,
.hook_session_unref = hook_session_unref_cb
};
_HOOK_SESSION_(destroy, session);
}
-void afb_hook_session_renew(struct afb_session *session)
-{
- _HOOK_SESSION_(renew, session);
-}
-
void afb_hook_session_addref(struct afb_session *session)
{
_HOOK_SESSION_(addref, session);
#define afb_hook_flag_session_create 0x000001
#define afb_hook_flag_session_close 0x000002
#define afb_hook_flag_session_destroy 0x000004
-#define afb_hook_flag_session_renew 0x000008
-#define afb_hook_flag_session_addref 0x000010
-#define afb_hook_flag_session_unref 0x000020
+#define afb_hook_flag_session_addref 0x000008
+#define afb_hook_flag_session_unref 0x000010
-#define afb_hook_flags_session_common (afb_hook_flag_session_create|afb_hook_flag_session_close\
- |afb_hook_flag_session_renew)
+#define afb_hook_flags_session_common (afb_hook_flag_session_create|afb_hook_flag_session_close)
#define afb_hook_flags_session_all (afb_hook_flags_session_common|afb_hook_flag_session_destroy\
|afb_hook_flag_session_addref|afb_hook_flag_session_unref)
void (*hook_session_create)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
void (*hook_session_close)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
void (*hook_session_destroy)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
- void (*hook_session_renew)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
void (*hook_session_addref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
void (*hook_session_unref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
};
extern void afb_hook_session_create(struct afb_session *session);
extern void afb_hook_session_close(struct afb_session *session);
extern void afb_hook_session_destroy(struct afb_session *session);
-extern void afb_hook_session_renew(struct afb_session *session);
extern void afb_hook_session_addref(struct afb_session *session);
extern void afb_hook_session_unref(struct afb_session *session);
static const char _verbosity_[] = "verbosity";
static const char _apis_[] = "apis";
-static const char _refresh_token_[] = "refresh-token";
static void f_get(afb_req_t req)
{
static void f_session(afb_req_t req)
{
struct json_object *r = NULL;
- int refresh = 0;
struct afb_xreq *xreq = xreq_from_req_x2(req);
/* check right to call it */
return;
}
- /* renew the token if required */
- wrap_json_unpack(afb_req_json(req), "{s?:b}", _refresh_token_, &refresh);
- if (refresh)
- afb_context_refresh(&xreq->context);
-
/* make the result */
wrap_json_pack(&r, "{s:s,s:s,s:i,s:i}",
"uuid", afb_session_uuid(xreq->context.session),
return r;
}
-/* generate a new token and update client context */
-void afb_session_new_token (struct afb_session *session)
-{
- int rc;
- uuid_stringz_t uuid;
- struct afb_token *previous, *next;
- session_lock(session);
- uuid_new_stringz(uuid);
- rc = afb_token_get(&next, uuid);
- if (rc < 0)
- ERROR("can't renew token");
- else {
- previous = session->token;
- session->token = next;
- session_update_expiration(session, NOW);
-#if WITH_AFB_HOOK
- afb_hook_session_renew(session);
-#endif
- afb_token_unref(previous);
- }
- session_unlock(session);
-}
-
/* Returns the uuid of 'session' */
const char *afb_session_uuid (struct afb_session *session)
{
extern int afb_session_is_closed (struct afb_session *session);
extern int afb_session_check_token(struct afb_session *session, const char *token);
-extern void afb_session_new_token(struct afb_session *session);
extern const char *afb_session_token(struct afb_session *session);
extern int afb_session_timeout(struct afb_session *session);
extern int afb_session_what_remains(struct afb_session *session);
hook_session(closure, hookid, session, "destroy", NULL);
}
-static void hook_session_renew(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
-{
- hook_session(closure, hookid, session, "renew", "{ss}", "token", afb_session_token(session));
-}
-
static void hook_session_addref(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
{
hook_session(closure, hookid, session, "addref", NULL);
.hook_session_create = hook_session_create,
.hook_session_close = hook_session_close,
.hook_session_destroy = hook_session_destroy,
- .hook_session_renew = hook_session_renew,
.hook_session_addref = hook_session_addref,
.hook_session_unref = hook_session_unref
};
}
}
- if ((sessionflags & AFB_SESSION_RENEW_X1) != 0) {
- afb_context_refresh(&xreq->context);
- }
if ((sessionflags & AFB_SESSION_CLOSE_X1) != 0) {
afb_context_change_loa(&xreq->context, 0);
afb_context_close(&xreq->context);
return -1;
}
- if ((sessionflags & AFB_SESSION_REFRESH_X2) != 0) {
- afb_context_refresh(&xreq->context);
- }
if ((sessionflags & AFB_SESSION_CLOSE_X2) != 0) {
afb_context_close(&xreq->context);
}
ck_assert(afb_session_check_token(s, GOOD_UUID));
ck_assert(afb_session_check_token(s, afb_session_token(s)));
- /* token can be renewed */
- afb_session_new_token(s);
- ck_assert(strcmp(afb_session_token(s), GOOD_UUID));
- ck_assert(!afb_session_check_token(s, GOOD_UUID));
- ck_assert(afb_session_check_token(s, afb_session_token(s)));
-
/* query the session */
uuid = strdup(afb_session_uuid(s));
x = afb_session_search(uuid);