diff options
author | Jose Bollo <jose.bollo@iot.bzh> | 2018-10-22 12:09:58 +0200 |
---|---|---|
committer | Jose Bollo <jose.bollo@iot.bzh> | 2018-10-22 12:36:34 +0200 |
commit | 61a01510306f60422df3cd3e67513d3c7b585524 (patch) | |
tree | ea66a471f921ef84573f99730fe132737840834c | |
parent | c1c4973d1d584b659aae493c9f03232f6ccd5c5a (diff) |
afb-session: Add language to session
Bug-AGL: SPEC-1827
Change-Id: Icfb9e2ee76186ac677ff2fbb37be28cd83dd3b6b
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-session.c | 36 | ||||
-rw-r--r-- | src/afb-session.h | 2 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/afb-session.c b/src/afb-session.c index 00aac69d..2cfbff99 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -65,6 +65,7 @@ struct afb_session time_t expiration; /**< expiration time of the token */ pthread_mutex_t mutex; /**< mutex of the session */ struct cookie *cookies[COOKIECOUNT]; /**< cookies of the session */ + char *lang; /**< current language setting for the session */ uint8_t closed: 1; /**< is the session closed ? */ uint8_t autoclose: 1; /**< close the session when unreferenced */ uint8_t notinset: 1; /**< session removed from the set of sessions */ @@ -259,6 +260,7 @@ static void session_destroy (struct afb_session *session) { afb_hook_session_destroy(session); pthread_mutex_destroy(&session->mutex); + free(session->lang); free(session); } @@ -738,3 +740,37 @@ int afb_session_set_cookie(struct afb_session *session, const void *key, void *v return -(value != afb_session_cookie(session, key, NULL, freecb, value, 1)); } +/** + * Set the language attached to the session + * + * @param session the session to set + * @param lang the language specifiction to set to session + * + * @return 0 in case of success or -1 in case of error + */ +int afb_session_set_language(struct afb_session *session, const char *lang) +{ + char *oldl, *newl; + + newl = strdup(lang); + if (newl == NULL) + return -1; + + oldl = session->lang; + session->lang = newl; + free(oldl); + return 0; +} + +/** + * Get the language attached to the session + * + * @param session the session to query + * @param lang a default language specifiction + * + * @return the langauage specification to use for session + */ +const char *afb_session_get_language(struct afb_session *session, const char *lang) +{ + return session->lang ?: lang; +} diff --git a/src/afb-session.h b/src/afb-session.h index 12b30c41..bad07eeb 100644 --- a/src/afb-session.h +++ b/src/afb-session.h @@ -50,3 +50,5 @@ extern void *afb_session_get_cookie(struct afb_session *session, const void *key extern void *afb_session_cookie(struct afb_session *session, const void *key, void *(*makecb)(void *closure), void (*freecb)(void *item), void *closure, int replace); extern int afb_session_set_cookie(struct afb_session *session, const void *key, void *value, void (*freecb)(void*)); +extern int afb_session_set_language(struct afb_session *session, const char *lang); +extern const char *afb_session_get_language(struct afb_session *session, const char *lang); |