Bläddra i källkod

msrp: added rpc command to list active connections

Daniel-Constantin Mierla 12 år sedan
förälder
incheckning
bc8b005ba4
5 ändrade filer med 157 tillägg och 6 borttagningar
  1. 27 6
      modules/msrp/README
  2. 20 0
      modules/msrp/doc/msrp_admin.xml
  3. 103 0
      modules/msrp/msrp_cmap.c
  4. 1 0
      modules/msrp/msrp_cmap.h
  5. 6 0
      modules/msrp/msrp_mod.c

+ 27 - 6
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

+ 20 - 0
modules/msrp/doc/msrp_admin.xml

@@ -451,6 +451,26 @@ event_route[msrp:frame-in] {
 		</para>
 	</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>

+ 103 - 0
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;
+}

+ 1 - 0
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

+ 6 - 0
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;