Răsfoiți Sursa

sipcapture Add RPC command to turn on/off or check status

Kamailio RPC rocks - much more than IMS ;-)
Olle E. Johansson 12 ani în urmă
părinte
comite
8ebf2dbe6c

+ 33 - 10
modules/sipcapture/README

@@ -10,9 +10,9 @@ Alexandr Dubovikov
 
 
    <[email protected]>
    <[email protected]>
 
 
-   Copyright © 2011 QSC AG
+   Copyright © 2011 QSC AG
 
 
-   Copyright © 2011 http://www.qsc.de
+   Copyright © 2011 http://www.qsc.de
      __________________________________________________________________
      __________________________________________________________________
 
 
    Table of Contents
    Table of Contents
@@ -47,8 +47,12 @@ Alexandr Dubovikov
 
 
               4.1. sip_capture
               4.1. sip_capture
 
 
-        5. Database setup
-        6. Limitation
+        5. RPC Commands
+
+              5.1. sipcapture.status param
+
+        6. Database setup
+        7. Limitation
 
 
    List of Examples
    List of Examples
 
 
@@ -100,8 +104,12 @@ Chapter 1. Admin Guide
 
 
         4.1. sip_capture
         4.1. sip_capture
 
 
-   5. Database setup
-   6. Limitation
+   5. RPC Commands
+
+        5.1. sipcapture.status param
+
+   6. Database setup
+   7. Limitation
 
 
 1. Overview
 1. Overview
 
 
@@ -113,7 +121,7 @@ Chapter 1. Admin Guide
      * Monitoring/mirroring port.
      * Monitoring/mirroring port.
      * Homer encapsulation protocol mode (HEP v1, v2, v3).
      * Homer encapsulation protocol mode (HEP v1, v2, v3).
 
 
-   The capturing can be turned on/off using fifo commad.
+   The capturing can be turned on/off using mi or rpc commands. Example:
 
 
    kamctl fifo sip_capture on
    kamctl fifo sip_capture on
 
 
@@ -361,7 +369,7 @@ modparam("sipcapture", "capture_node", "homer03")
           + on
           + on
           + off
           + off
        The parameter is optional - if missing, the command will return the
        The parameter is optional - if missing, the command will return the
-       status of the SIP message capturing (as string “on� or “off� )
+       status of the SIP message capturing (as string "on" or "off" )
        without changing anything.
        without changing anything.
 
 
    MI FIFO Command Format:
    MI FIFO Command Format:
@@ -369,7 +377,22 @@ modparam("sipcapture", "capture_node", "homer03")
                 capture_mode
                 capture_mode
                 _empty_line_
                 _empty_line_
 
 
-5. Database setup
+5. RPC Commands
+
+   5.1. sipcapture.status param
+
+5.1.  sipcapture.status param
+
+   Name: sipcapture.status
+
+   Parameters:
+     * on or off: turns on/off SIP message capturing. Possible values are:
+          + on
+          + off
+     * "check" does not change sipcapture status, just reports the current
+       status.
+
+6. Database setup
 
 
    Before running Kamailio with sipcapture, you have to setup the database
    Before running Kamailio with sipcapture, you have to setup the database
    tables where the module will store the data. For that, if the table
    tables where the module will store the data. For that, if the table
@@ -379,7 +402,7 @@ modparam("sipcapture", "capture_node", "homer03")
    find the complete database documentation on the project webpage,
    find the complete database documentation on the project webpage,
    http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
    http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
 
 
-6. Limitation
+7. Limitation
 
 
    1. Only one capturing mode on RAW socket is supported: IPIP or
    1. Only one capturing mode on RAW socket is supported: IPIP or
    monitoring/mirroring port. Don't activate both at the same time. 2. By
    monitoring/mirroring port. Don't activate both at the same time. 2. By

+ 29 - 1
modules/sipcapture/doc/sipcapture_admin.xml

@@ -40,7 +40,7 @@
 	</para>
 	</para>
 
 
 	<para>
 	<para>
-	The capturing can be turned on/off using fifo commad.
+	The capturing can be turned on/off using mi or rpc commands. Example:
 	</para>
 	</para>
 	<para>
 	<para>
 	&ctltool; fifo sip_capture on
 	&ctltool; fifo sip_capture on
@@ -425,7 +425,35 @@ modparam("sipcapture", "capture_node", "homer03")
 		_empty_line_
 		_empty_line_
 		</programlisting>
 		</programlisting>
 	</section>
 	</section>
+	</section><!-- MI commands -->
+    	<section>
+	<title>RPC Commands</title>
+	<section>
+		<title>
+		<function moreinfo="none">sipcapture.status param</function>
+		</title>
+		<para>
+
+		</para>
+		<para>
+		Name: <emphasis>sipcapture.status</emphasis>
+		</para>
+		<para>Parameters: </para>
+		<itemizedlist>
+			<listitem><para>on or off: turns on/off SIP message capturing.
+			Possible values are:</para>
+			<itemizedlist>
+				<listitem><para>on</para></listitem> 
+				<listitem><para>off</para></listitem>
+			</itemizedlist>
+			</listitem>
+			<listitem><quote>check</quote> does not change 
+			sipcapture status, just reports the current status.</para>
+			</listitem>
+		</itemizedlist>
+
 	</section>
 	</section>
+	</section><!-- MI commands -->
 	
 	
 	<section>
 	<section>
 		<title>Database setup</title>
 		<title>Database setup</title>

+ 58 - 0
modules/sipcapture/sipcapture.c

@@ -60,6 +60,8 @@
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
 #include "../../mem/shm_mem.h"
 #include "../../lib/kmi/mi.h"
 #include "../../lib/kmi/mi.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
 #include "../../lib/srdb1/db.h"
 #include "../../lib/srdb1/db.h"
 #include "../../parser/contact/parse_contact.h"
 #include "../../parser/contact/parse_contact.h"
 #include "../../parser/parse_content.h"
 #include "../../parser/parse_content.h"
@@ -95,6 +97,7 @@ MODULE_VERSION
 
 
 /* module function prototypes */
 /* module function prototypes */
 static int mod_init(void);
 static int mod_init(void);
+static int sipcapture_init_rpc(void);
 static int child_init(int rank);
 static int child_init(int rank);
 static void destroy(void);
 static void destroy(void);
 static int sip_capture(struct sip_msg *msg, char *s1, char *s2);
 static int sip_capture(struct sip_msg *msg, char *s1, char *s2);
@@ -409,6 +412,11 @@ static int mod_init(void) {
 		LM_ERR("failed to register MI commands\n");
 		LM_ERR("failed to register MI commands\n");
 		return -1;
 		return -1;
 	}
 	}
+	if(sipcapture_init_rpc()!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
 
 
 	db_url.len = strlen(db_url.s);
 	db_url.len = strlen(db_url.s);
 	table_name.len = strlen(table_name.s);
 	table_name.len = strlen(table_name.s);
@@ -1564,4 +1572,54 @@ int raw_capture_rcv_loop(int rsock, int port1, int port2, int ipip) {
 	return 0;
 	return 0;
 }
 }
 
 
+static void sipcapture_rpc_status (rpc_t* rpc, void* c) {
+	str status = {0, 0};
+
+	if (rpc->scan(c, "S", &status) < 1) {
+		rpc->fault(c, 500, "Not enough parameters (on, off or check)");
+		return;
+	}
+
+	if(capture_on_flag==NULL) {
+		rpc->fault(c, 500, "Internal error");
+		return;
+	}
+
+	if (strncasecmp(status.s, "on", strlen("on")) == 0) {
+		*capture_on_flag = 1;
+		rpc->printf(c, "Enabled");
+		return;
+	}
+	if (strncasecmp(status.s, "off", strlen("off")) == 0) {
+		*capture_on_flag = 0;
+		rpc->printf(c, "Disabled");
+		return;
+	}
+	if (strncasecmp(status.s, "check", strlen("check")) == 0) {
+		rpc->printf(c, *capture_on_flag ? "Enabled" : "Disabled");
+		return;
+	} 
+	rpc->fault(c, 500, "Bad parameter (on, off or check)");
+	return;
+}
+
+static const char* sipcapture_status_doc[2] = {
+        "Get status or turn on/off sipcapture.",
+        0
+};
+
+rpc_export_t sipcapture_rpc[] = {
+	{"sipcapture.status", sipcapture_rpc_status, sipcapture_status_doc, 0},
+	{0, 0, 0, 0}
+};
+
+static int sipcapture_init_rpc(void)
+{
+	if (rpc_register_array(sipcapture_rpc)!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+	return 0;
+}