Module: kamailio
Branch: master
Commit: 9cbebc1d7c0eda71162ce3d90de1ac3110c10bb0
URL: 
https://github.com/kamailio/kamailio/commit/9cbebc1d7c0eda71162ce3d90de1ac3110c10bb0

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2023-02-14T17:13:09+01:00

presence: added presence.watcher_list rpc command

- list the watchers for a presentity uri

---

Modified: src/modules/presence/presence.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/9cbebc1d7c0eda71162ce3d90de1ac3110c10bb0.diff
Patch: 
https://github.com/kamailio/kamailio/commit/9cbebc1d7c0eda71162ce3d90de1ac3110c10bb0.patch

---

diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c
index 5138b1381e..06b73df61d 100644
--- a/src/modules/presence/presence.c
+++ b/src/modules/presence/presence.c
@@ -2029,6 +2029,103 @@ static const char *rpc_presence_presentity_show_doc[2] 
= {
        0
 };
 
+/*! \brief
+ *  rpc cmd: presence.watcher_list
+ *                     \mode - output attributes control
+ *                     \presuri - filter by presentity uri
+ */
+void rpc_presence_watcher_list(rpc_t *rpc, void *ctx)
+{
+       int i = 0;
+       str omode = {0, 0};
+       int imode = 0;
+       str presuri = str_init("");
+       str pempty = str_init("");
+       subs_t *s = NULL;
+       void *th = NULL;
+
+       LM_DBG("listing in memory presentity records\n");
+
+       imode = rpc->scan(ctx, "SS", &omode, &presuri);
+       if(imode < 2) {
+               rpc->fault(ctx, 500, "Not enough parameters");
+               return;
+       }
+       if(omode.len == 4 && strncmp(omode.s, "full", 4)==0) {
+               imode = 1;
+       } else if(omode.len == 5 && strncmp(omode.s, "basic", 5)==0) {
+               imode = 0;
+       } else {
+               rpc->fault(ctx, 500, "Unknown output mode");
+               return;
+       }
+
+       for(i = 0; i < shtable_size; i++) {
+               lock_get(&subs_htable[i].lock);
+               for(s = subs_htable[i].entries->next; s!=NULL; s = s->next) {
+                       if(s->pres_uri.len == presuri.len
+                                       && strncasecmp(s->pres_uri.s, 
presuri.s, presuri.len)==0) {
+                               /* add record node */
+                               if (rpc->add(ctx, "{", &th) < 0) {
+                                       rpc->fault(ctx, 500, "Internal error 
creating response");
+                                       lock_release(&subs_htable[i].lock);
+                                       return;
+                               }
+
+                               /* add common fields */
+                               if(rpc->struct_add(th, "SSSSSSSSSSSuudu",
+                                               "pres_uri",  &s->pres_uri,
+                                               "to_user", &s->to_user,
+                                               "to_domain", &s->to_domain,
+                                               "from_user", &s->from_user,
+                                               "from_domain", &s->from_domain,
+                                               "watcher_user", 
&s->watcher_user,
+                                               "watcher_domain", 
&s->watcher_domain,
+                                               "contact", &s->contact,
+                                               "event_id", &s->event_id,
+                                               "callid", &s->callid,
+                                               "user_agent", 
(s->user_agent.s)?&s->user_agent:&pempty,
+                                               "expires", s->expires,
+                                               "status", s->status,
+                                               "version", s->version,
+                                               "flags", s->flags)<0) {
+                                       rpc->fault(ctx, 500, "Internal error 
adding attributes");
+                                       lock_release(&subs_htable[i].lock);
+                                       return;
+                               }
+                               if(imode==1) {
+                                       /* add extra fields */
+                                       if(rpc->struct_add(th, "SSSSSSSuuddd",
+                                                       "reason", 
(s->reason.s)?&s->reason:&pempty,
+                                                       "to_tag", &s->to_tag,
+                                                       "from_tag", 
&s->from_tag,
+                                                       "socket", 
(s->sockinfo_str.s)?&s->sockinfo_str:&pempty,
+                                                       "local_contact", 
(s->local_contact.s)?&s->local_contact:&pempty,
+                                                       "record_route", 
(s->record_route.s)?&s->record_route:&pempty,
+                                                       "auth_rules", 
(s->auth_rules_doc)?s->auth_rules_doc:&pempty,
+                                                       "remote_cseq", 
s->remote_cseq,
+                                                       "local_cseq", 
s->local_cseq,
+                                                       "recv_event", 
s->recv_event,
+                                                       "updated", s->updated,
+                                                       "updated_winfo", 
s->updated_winfo)<0) {
+                                               rpc->fault(ctx, 500, "Internal 
error adding extra attributes");
+                                               
lock_release(&subs_htable[i].lock);
+                                               return;
+                                       }
+                               }
+
+                       }
+               }
+               lock_release(&subs_htable[i].lock);
+       }
+}
+
+static const char *rpc_presence_watcher_list_doc[2] = {
+       "Show the watcher records for a specific presentity user",
+       0
+};
+
+
 rpc_export_t presence_rpc[] = {
        {"presence.cleanup", rpc_presence_cleanup, rpc_presence_cleanup_doc, 0},
        {"presence.refreshWatchers", rpc_presence_refresh_watchers,
@@ -2039,6 +2136,8 @@ rpc_export_t presence_rpc[] = {
                        rpc_presence_presentity_list_doc, RET_ARRAY},
        {"presence.presentity_show", rpc_presence_presentity_show,
                        rpc_presence_presentity_show_doc, RET_ARRAY},
+       {"presence.watcher_list", rpc_presence_watcher_list,
+                       rpc_presence_watcher_list_doc, RET_ARRAY},
        {0, 0, 0, 0}
 };
 

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to [email protected]

Reply via email to