Module: kamailio Branch: master Commit: c62e411b116db7f9b9227b9decd37866e62f4378 URL: https://github.com/kamailio/kamailio/commit/c62e411b116db7f9b9227b9decd37866...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-04-21T09:57:30+02:00
presence: implemented rpc command to list presententy records in memory
- presence.presentity_list [mode] - mode is optional and can be 'full' to print all attributes of the presentity record
---
Modified: src/modules/presence/hash.c Modified: src/modules/presence/hash.h Modified: src/modules/presence/presence.c
---
Diff: https://github.com/kamailio/kamailio/commit/c62e411b116db7f9b9227b9decd37866... Patch: https://github.com/kamailio/kamailio/commit/c62e411b116db7f9b9227b9decd37866...
---
diff --git a/src/modules/presence/hash.c b/src/modules/presence/hash.c index 7a58fe5309..6d868e165d 100644 --- a/src/modules/presence/hash.c +++ b/src/modules/presence/hash.c @@ -705,6 +705,11 @@ int update_phtable(presentity_t *presentity, str *pres_uri, str *body)
static ps_ptable_t *_ps_ptable = NULL;
+ps_ptable_t *ps_ptable_get(void) +{ + return _ps_ptable; +} + #define PS_PRESENTITY_FIELD_COPY(field) do { \ if (pt->field.s) { \ ptn->field.s = p; \ @@ -945,6 +950,7 @@ void ps_ptable_destroy(void) } for(i=0; i<_ps_ptable->ssize; i++) { lock_destroy(&_ps_ptable->slots[i].lock); + pt = _ps_ptable->slots[i].plist; while(pt!=NULL) { ptn = pt->next; ps_presentity_free(pt, 0); diff --git a/src/modules/presence/hash.h b/src/modules/presence/hash.h index 96621efe5b..45732426f5 100644 --- a/src/modules/presence/hash.h +++ b/src/modules/presence/hash.h @@ -180,5 +180,6 @@ int ps_ptable_remove(ps_presentity_t *pt); ps_presentity_t *ps_ptable_get_list(str *user, str *domain); ps_presentity_t *ps_ptable_get_item(str *user, str *domain, str *event, str *etag); ps_presentity_t *ps_ptable_get_expired(int eval); +ps_ptable_t *ps_ptable_get(void);
#endif diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c index c0e1912ecd..84997b4230 100644 --- a/src/modules/presence/presence.c +++ b/src/modules/presence/presence.c @@ -1847,6 +1847,83 @@ static const char *rpc_presence_cleanup_doc[3] = { 0 };
+/*! \brief + * rpc cmd: presence.presentity_list + * \mode - output attributes control + * * */ +void rpc_presence_presentity_list(rpc_t *rpc, void *ctx) +{ + str omode = {0, 0}; + int imode = 0; + int i = 0; + ps_ptable_t *ptb = NULL; + ps_presentity_t *ptn = NULL; + void* th = NULL; + str pempty = str_init(""); + + LM_DBG("listing in memory presentity records\n"); + + imode = rpc->scan(ctx, "*S", &omode); + if(imode < 1) { + imode = 0; + } else { + if(omode.len == 4 && strncmp(omode.s, "full", 4)==0) { + imode = 1; + } else { + imode = 0; + } + } + ptb = ps_ptable_get(); + if(ptb == NULL) { + return; + } + + for(i=0; i<ptb->ssize; i++) { + lock_get(&ptb->slots[i].lock); + ptn = ptb->slots[i].plist; + while(ptn!=NULL) { + /* add record node */ + if (rpc->add(ctx, "{", &th) < 0) { + rpc->fault(ctx, 500, "Internal error creating rpc"); + lock_release(&ptb->slots[i].lock); + return; + } + /* add common fields */ + if(rpc->struct_add(th, "SSSSSd", + "user", &ptn->user, + "domain", &ptn->domain, + "event", &ptn->event, + "etag", &ptn->etag, + "sender", (ptn->sender.s)?&ptn->sender:&pempty, + "expires", ptn->expires)<0) { + rpc->fault(ctx, 500, "Internal error adding item"); + lock_release(&ptb->slots[i].lock); + return; + } + if(imode==1) { + /* add extra fields */ + if(rpc->struct_add(th, "ddSSd", + "received_time", ptn->received_time, + "priority", ptn->priority, + "ruid", (ptn->ruid.s)?&ptn->ruid:&pempty, + "body", (ptn->body.s)?&ptn->body:&pempty, + "hashid", ptn->hashid)<0) { + rpc->fault(ctx, 500, "Internal error adding item"); + lock_release(&ptb->slots[i].lock); + return; + } + } + ptn = ptn->next; + } + lock_release(&ptb->slots[i].lock); + } + return; +} + +static const char *rpc_presence_presentity_list_doc[2] = { + "Trigger update of watchers", + 0 +};
rpc_export_t presence_rpc[] = { {"presence.cleanup", rpc_presence_cleanup, rpc_presence_cleanup_doc, 0}, @@ -1854,6 +1931,8 @@ rpc_export_t presence_rpc[] = { rpc_presence_refresh_watchers_doc, 0}, {"presence.updateWatchers", rpc_presence_update_watchers, rpc_presence_update_watchers_doc, 0}, + {"presence.presentity_list", rpc_presence_presentity_list, + rpc_presence_presentity_list_doc, 0}, {0, 0, 0, 0} };