Module: sip-router
Branch: master
Commit: bc8b005ba4d4c89afa6152dd212eda9b6689bb86
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bc8b005ba4d4c89afa6152dd212eda9b6689bb86

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Sat Jan  5 23:36:43 2013 +0100

msrp: added rpc command to list active connections

---

 modules/msrp/README             |   33 ++++++++++--
 modules/msrp/doc/msrp_admin.xml |   20 ++++++++
 modules/msrp/msrp_cmap.c        |  103 +++++++++++++++++++++++++++++++++++++++
 modules/msrp/msrp_cmap.h        |    1 +
 modules/msrp/msrp_mod.c         |    6 ++
 5 files changed, 157 insertions(+), 6 deletions(-)

diff --git a/modules/msrp/README b/modules/msrp/README
index 0d3c0b5..7a50456 100644
--- a/modules/msrp/README
+++ b/modules/msrp/README
@@ -50,8 +50,12 @@ Alex Balashov
               4.9. msrp_cmap_lookup()
 
         5. Pseudo Variables
-        6. Event Routes
-        7. Usage
+        6. RPC Commands
+
+              6.1. msrp.cmaplist
+
+        7. Event Routes
+        8. Usage
 
    List of Examples
 
@@ -102,8 +106,12 @@ Chapter 1. Admin Guide
         4.9. msrp_cmap_lookup()
 
    5. Pseudo Variables
-   6. Event Routes
-   7. Usage
+   6. RPC Commands
+
+        6.1. msrp.cmaplist
+
+   7. Event Routes
+   8. Usage
 
 1. Overview
 
@@ -401,12 +409,25 @@ event_route[msrp:frame-in] {
    These are documented in the appropriate Wiki pages hosted on the
    project web site.
 
-6. Event Routes
+6. RPC Commands
+
+   6.1. msrp.cmaplist
+
+6.1. msrp.cmaplist
+
+   List active MSRP connections.
+
+   Example:
+...
+kamcmd msrp.cmaplist
+...
+
+7. Event Routes
 
    For each MSRP frame received from the network, the module executes
    event_route[msrp:frame-in] block in the config file.
 
-7. Usage
+8. Usage
 
    When 'sipmsg' parameter is set to 1 (which is default), the module
    internally builds a SIP request from the MSRP frame and exposes it to
diff --git a/modules/msrp/doc/msrp_admin.xml b/modules/msrp/doc/msrp_admin.xml
index 451ebe6..58621d3 100644
--- a/modules/msrp/doc/msrp_admin.xml
+++ b/modules/msrp/doc/msrp_admin.xml
@@ -452,6 +452,26 @@ event_route[msrp:frame-in] {
        </section>
 
        <section>
+       <title>RPC Commands</title>
+       <section>
+               <title>
+               <function moreinfo="none">msrp.cmaplist</function>
+               </title>
+               <para>
+               List active MSRP connections.
+               </para>
+               <para>
+               Example:
+               </para>
+<programlisting  format="linespecific">
+...
+&sercmd; msrp.cmaplist
+...
+</programlisting>
+    </section>
+    </section>
+
+       <section>
                <title>Event Routes</title>
                <para>
                        For each MSRP frame received from the network, the 
module executes
diff --git a/modules/msrp/msrp_cmap.c b/modules/msrp/msrp_cmap.c
index e8c4f19..887274e 100644
--- a/modules/msrp/msrp_cmap.c
+++ b/modules/msrp/msrp_cmap.c
@@ -29,6 +29,8 @@
 #include "../../ut.h"
 
 #include "../../lib/srutils/sruid.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
 
 #include "msrp_netio.h"
 #include "msrp_env.h"
@@ -403,3 +405,104 @@ int msrp_cmap_clean(void)
 
        return 0;
 }
+
+static const char* msrp_cmap_rpc_list_doc[2] = {
+       "Return the content of dispatcher sets",
+       0
+};
+
+
+/*
+ * RPC command to print connections map table
+ */
+static void msrp_cmap_rpc_list(rpc_t* rpc, void* ctx)
+{
+       void* th;
+       void* ih;
+       void* vh;
+       msrp_citem_t *it;
+       int i;
+       int n;
+       str edate;
+
+       if(_msrp_cmap_head==NULL)
+       {
+               LM_ERR("no connections map table\n");
+               rpc->fault(ctx, 500, "No Connections Map Table");
+               return;
+       }
+
+       /* add entry node */
+       if (rpc->add(ctx, "{", &th) < 0)
+       {
+               rpc->fault(ctx, 500, "Internal error root reply");
+               return;
+       }
+
+       if(rpc->struct_add(th, "d{",
+                               "MAP_SIZE", _msrp_cmap_head->mapsize,
+                               "CONLIST",  &ih)<0)
+       {
+               rpc->fault(ctx, 500, "Internal error set structure");
+               return;
+       }
+       n = 0;
+       for(i=0; i<_msrp_cmap_head->mapsize; i++)
+       {
+               lock_get(&_msrp_cmap_head->cslots[i].lock);
+               for(it=_msrp_cmap_head->cslots[i].first; it; it=it->next)
+               {
+                       if(rpc->struct_add(ih, "{",
+                                               "CONDATA", &vh)<0)
+                       {
+                               rpc->fault(ctx, 500, "Internal error creating 
connection");
+                               lock_release(&_msrp_cmap_head->cslots[i].lock);
+                               return;
+                       }
+                       edate.s = ctime(&it->expires);
+                       edate.len = 24;
+                       if(rpc->struct_add(vh, "dSSSSSdd",
+                                               "CITEMID", it->citemid,
+                                               "SESSIONID", &it->sessionid,
+                                               "PEER", &it->peer,
+                                               "ADDR", &it->addr,
+                                               "SOCK", &it->sock,
+                                               "EXPIRES", &edate,
+                                               "CONID", it->conid,
+                                               "FLAGS", it->cflags)<0)
+                       {
+                               rpc->fault(ctx, 500, "Internal error creating 
dest struct");
+                               lock_release(&_msrp_cmap_head->cslots[i].lock);
+                               return;
+                       }
+                       n++;
+               }
+               lock_release(&_msrp_cmap_head->cslots[i].lock);
+       }
+       if(rpc->struct_add(th, "d", "CONCOUNT", n)<0)
+       {
+               rpc->fault(ctx, 500, "Internal error connection counter");
+               return;
+       }
+       return;
+}
+
+rpc_export_t msrp_cmap_rpc_cmds[] = {
+       {"msrp.cmaplist",   msrp_cmap_rpc_list,
+               msrp_cmap_rpc_list_doc,   0},
+       {0, 0, 0, 0}
+};
+
+/**
+ *
+ */
+int msrp_cmap_init_rpc(void)
+{
+       if (rpc_register_array(msrp_cmap_rpc_cmds)!=0)
+       {
+               LM_ERR("failed to register RPC commands\n");
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/modules/msrp/msrp_cmap.h b/modules/msrp/msrp_cmap.h
index 6ec4464..871067d 100644
--- a/modules/msrp/msrp_cmap.h
+++ b/modules/msrp/msrp_cmap.h
@@ -70,4 +70,5 @@ int msrp_cmap_lookup(msrp_frame_t *mf);
 
 int msrp_sruid_init(void);
 
+int msrp_cmap_init_rpc(void);
 #endif
diff --git a/modules/msrp/msrp_mod.c b/modules/msrp/msrp_mod.c
index 432b7e7..4ff4559 100644
--- a/modules/msrp/msrp_mod.c
+++ b/modules/msrp/msrp_mod.c
@@ -146,6 +146,12 @@ static int mod_init(void)
                return -1;
        }
 
+       if(msrp_cmap_init_rpc()<0)
+       {
+               LM_ERR("failed to register cmap RPC commands\n");
+               return -1;
+       }
+
        if(msrp_cmap_size>0) {
                if(msrp_cmap_size>16)
                        msrp_cmap_size = 16;


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to