From 60b9c9d919fd22339105f8e1835cb5cd7ff16d9c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 3 Sep 2013 12:21:09 +0200 Subject: [PATCH] session: introduce api to register session create and destroy callbacks --- session.c | 23 +++++++++++++++++++++++ session.h | 9 +++++++++ 2 files changed, 32 insertions(+) diff --git a/session.c b/session.c index d970d45..6cc4ffe 100644 --- a/session.c +++ b/session.c @@ -27,6 +27,9 @@ static struct avl_tree sessions; static struct blob_buf buf; +static LIST_HEAD(create_callbacks); +static LIST_HEAD(destroy_callbacks); + static const struct blobmsg_policy new_policy = { .name = "timeout", .type = BLOBMSG_TYPE_INT32 }; @@ -200,6 +203,10 @@ rpc_session_destroy(struct rpc_session *ses) struct rpc_session_acl *acl, *nacl; struct rpc_session_acl_scope *acl_scope, *nacl_scope; struct rpc_session_data *data, *ndata; + struct rpc_session_cb *cb; + + list_for_each_entry(cb, &destroy_callbacks, list) + cb->cb(ses, cb->priv); uloop_timeout_cancel(&ses->t); @@ -230,6 +237,7 @@ static struct rpc_session * rpc_session_create(int timeout) { struct rpc_session *ses; + struct rpc_session_cb *cb; ses = calloc(1, sizeof(*ses)); if (!ses) @@ -246,6 +254,9 @@ rpc_session_create(int timeout) ses->t.cb = rpc_session_timeout; rpc_touch_session(ses); + list_for_each_entry(cb, &create_callbacks, list) + cb->cb(ses, cb->priv); + return ses; } @@ -720,3 +731,15 @@ bool rpc_session_access(const char *sid, const char *scope, return rpc_session_acl_allowed(ses, scope, object, function); } + +void rpc_session_create_cb(struct rpc_session_cb *cb) +{ + if (cb && cb->cb) + list_add(&cb->list, &create_callbacks); +} + +void rpc_session_destroy_cb(struct rpc_session_cb *cb) +{ + if (cb && cb->cb) + list_add(&cb->list, &destroy_callbacks); +} diff --git a/session.h b/session.h index bcdcb96..59b2864 100644 --- a/session.h +++ b/session.h @@ -59,4 +59,13 @@ int rpc_session_api_init(struct ubus_context *ctx); bool rpc_session_access(const char *sid, const char *scope, const char *object, const char *function); +struct rpc_session_cb { + struct list_head list; + void (*cb)(struct rpc_session *, void *); + void *priv; +}; + +void rpc_session_create_cb(struct rpc_session_cb *cb); +void rpc_session_destroy_cb(struct rpc_session_cb *cb); + #endif -- 2.25.1