Module: sip-router Branch: master Commit: 8ebf2dbe6cc0e51b47c423227f5dcff14c7af4c3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8ebf2dbe...
Author: Olle E. Johansson oej@edvina.net Committer: Olle E. Johansson oej@edvina.net Date: Wed Jan 9 18:37:43 2013 +0100
sipcapture Add RPC command to turn on/off or check status
Kamailio RPC rocks - much more than IMS ;-)
---
modules/sipcapture/README | 43 +++++++++++++++----- modules/sipcapture/doc/sipcapture_admin.xml | 30 +++++++++++++- modules/sipcapture/sipcapture.c | 58 +++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 11 deletions(-)
diff --git a/modules/sipcapture/README b/modules/sipcapture/README index 872d477..d83d88d 100644 --- a/modules/sipcapture/README +++ b/modules/sipcapture/README @@ -10,9 +10,9 @@ Alexandr Dubovikov
- Copyright © 2011 QSC AG + Copyright � 2011 QSC AG
- Copyright © 2011 http://www.qsc.de + Copyright � 2011 http://www.qsc.de __________________________________________________________________
Table of Contents @@ -47,8 +47,12 @@ Alexandr Dubovikov
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
@@ -100,8 +104,12 @@ Chapter 1. Admin Guide
4.1. sip_capture
- 5. Database setup - 6. Limitation + 5. RPC Commands + + 5.1. sipcapture.status param + + 6. Database setup + 7. Limitation
1. Overview
@@ -113,7 +121,7 @@ Chapter 1. Admin Guide * Monitoring/mirroring port. * 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
@@ -361,7 +369,7 @@ modparam("sipcapture", "capture_node", "homer03") + on + off 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.
MI FIFO Command Format: @@ -369,7 +377,22 @@ modparam("sipcapture", "capture_node", "homer03") capture_mode _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 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, 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 monitoring/mirroring port. Don't activate both at the same time. 2. By diff --git a/modules/sipcapture/doc/sipcapture_admin.xml b/modules/sipcapture/doc/sipcapture_admin.xml index b81fa52..0504a1e 100644 --- a/modules/sipcapture/doc/sipcapture_admin.xml +++ b/modules/sipcapture/doc/sipcapture_admin.xml @@ -40,7 +40,7 @@ </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> &ctltool; fifo sip_capture on @@ -425,7 +425,35 @@ modparam("sipcapture", "capture_node", "homer03") _empty_line_ </programlisting> </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><!-- MI commands --> <section> <title>Database setup</title> diff --git a/modules/sipcapture/sipcapture.c b/modules/sipcapture/sipcapture.c index 7ae94b9..dc74a3b 100644 --- a/modules/sipcapture/sipcapture.c +++ b/modules/sipcapture/sipcapture.c @@ -60,6 +60,8 @@ #include "../../mem/mem.h" #include "../../mem/shm_mem.h" #include "../../lib/kmi/mi.h" +#include "../../rpc.h" +#include "../../rpc_lookup.h" #include "../../lib/srdb1/db.h" #include "../../parser/contact/parse_contact.h" #include "../../parser/parse_content.h" @@ -95,6 +97,7 @@ MODULE_VERSION
/* module function prototypes */ static int mod_init(void); +static int sipcapture_init_rpc(void); static int child_init(int rank); static void destroy(void); 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"); return -1; } + if(sipcapture_init_rpc()!=0) + { + LM_ERR("failed to register RPC commands\n"); + return -1; + }
db_url.len = strlen(db_url.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; }
+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; +}