Browse code

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

Kamailio RPC rocks - much more than IMS ;-)

Olle E. Johansson authored on 09/01/2013 17:37:43
Showing 3 changed files
... ...
@@ -10,9 +10,9 @@ Alexandr Dubovikov
10 10
 
11 11
    <alexandr.dubovikov@gmail.com>
12 12
 
13
-   Copyright © 2011 QSC AG
13
+   Copyright � 2011 QSC AG
14 14
 
15
-   Copyright © 2011 http://www.qsc.de
15
+   Copyright � 2011 http://www.qsc.de
16 16
      __________________________________________________________________
17 17
 
18 18
    Table of Contents
... ...
@@ -47,8 +47,12 @@ Alexandr Dubovikov
47 47
 
48 48
               4.1. sip_capture
49 49
 
50
-        5. Database setup
51
-        6. Limitation
50
+        5. RPC Commands
51
+
52
+              5.1. sipcapture.status param
53
+
54
+        6. Database setup
55
+        7. Limitation
52 56
 
53 57
    List of Examples
54 58
 
... ...
@@ -100,8 +104,12 @@ Chapter 1. Admin Guide
100 104
 
101 105
         4.1. sip_capture
102 106
 
103
-   5. Database setup
104
-   6. Limitation
107
+   5. RPC Commands
108
+
109
+        5.1. sipcapture.status param
110
+
111
+   6. Database setup
112
+   7. Limitation
105 113
 
106 114
 1. Overview
107 115
 
... ...
@@ -113,7 +121,7 @@ Chapter 1. Admin Guide
113 121
      * Monitoring/mirroring port.
114 122
      * Homer encapsulation protocol mode (HEP v1, v2, v3).
115 123
 
116
-   The capturing can be turned on/off using fifo commad.
124
+   The capturing can be turned on/off using mi or rpc commands. Example:
117 125
 
118 126
    kamctl fifo sip_capture on
119 127
 
... ...
@@ -361,7 +369,7 @@ modparam("sipcapture", "capture_node", "homer03")
361 369
           + on
362 370
           + off
363 371
        The parameter is optional - if missing, the command will return the
364
-       status of the SIP message capturing (as string “on” or “off” )
372
+       status of the SIP message capturing (as string "on" or "off" )
365 373
        without changing anything.
366 374
 
367 375
    MI FIFO Command Format:
... ...
@@ -369,7 +377,22 @@ modparam("sipcapture", "capture_node", "homer03")
369 377
                 capture_mode
370 378
                 _empty_line_
371 379
 
372
-5. Database setup
380
+5. RPC Commands
381
+
382
+   5.1. sipcapture.status param
383
+
384
+5.1.  sipcapture.status param
385
+
386
+   Name: sipcapture.status
387
+
388
+   Parameters:
389
+     * on or off: turns on/off SIP message capturing. Possible values are:
390
+          + on
391
+          + off
392
+     * "check" does not change sipcapture status, just reports the current
393
+       status.
394
+
395
+6. Database setup
373 396
 
374 397
    Before running Kamailio with sipcapture, you have to setup the database
375 398
    tables where the module will store the data. For that, if the table
... ...
@@ -379,7 +402,7 @@ modparam("sipcapture", "capture_node", "homer03")
379 402
    find the complete database documentation on the project webpage,
380 403
    http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
381 404
 
382
-6. Limitation
405
+7. Limitation
383 406
 
384 407
    1. Only one capturing mode on RAW socket is supported: IPIP or
385 408
    monitoring/mirroring port. Don't activate both at the same time. 2. By
... ...
@@ -40,7 +40,7 @@
40 40
 	</para>
41 41
 
42 42
 	<para>
43
-	The capturing can be turned on/off using fifo commad.
43
+	The capturing can be turned on/off using mi or rpc commands. Example:
44 44
 	</para>
45 45
 	<para>
46 46
 	&ctltool; fifo sip_capture on
... ...
@@ -425,7 +425,35 @@ modparam("sipcapture", "capture_node", "homer03")
425 425
 		_empty_line_
426 426
 		</programlisting>
427 427
 	</section>
428
+	</section><!-- MI commands -->
429
+    	<section>
430
+	<title>RPC Commands</title>
431
+	<section>
432
+		<title>
433
+		<function moreinfo="none">sipcapture.status param</function>
434
+		</title>
435
+		<para>
436
+
437
+		</para>
438
+		<para>
439
+		Name: <emphasis>sipcapture.status</emphasis>
440
+		</para>
441
+		<para>Parameters: </para>
442
+		<itemizedlist>
443
+			<listitem><para>on or off: turns on/off SIP message capturing.
444
+			Possible values are:</para>
445
+			<itemizedlist>
446
+				<listitem><para>on</para></listitem> 
447
+				<listitem><para>off</para></listitem>
448
+			</itemizedlist>
449
+			</listitem>
450
+			<listitem><quote>check</quote> does not change 
451
+			sipcapture status, just reports the current status.</para>
452
+			</listitem>
453
+		</itemizedlist>
454
+
428 455
 	</section>
456
+	</section><!-- MI commands -->
429 457
 	
430 458
 	<section>
431 459
 		<title>Database setup</title>
... ...
@@ -60,6 +60,8 @@
60 60
 #include "../../mem/mem.h"
61 61
 #include "../../mem/shm_mem.h"
62 62
 #include "../../lib/kmi/mi.h"
63
+#include "../../rpc.h"
64
+#include "../../rpc_lookup.h"
63 65
 #include "../../lib/srdb1/db.h"
64 66
 #include "../../parser/contact/parse_contact.h"
65 67
 #include "../../parser/parse_content.h"
... ...
@@ -95,6 +97,7 @@ MODULE_VERSION
95 97
 
96 98
 /* module function prototypes */
97 99
 static int mod_init(void);
100
+static int sipcapture_init_rpc(void);
98 101
 static int child_init(int rank);
99 102
 static void destroy(void);
100 103
 static int sip_capture(struct sip_msg *msg, char *s1, char *s2);
... ...
@@ -409,6 +412,11 @@ static int mod_init(void) {
409 412
 		LM_ERR("failed to register MI commands\n");
410 413
 		return -1;
411 414
 	}
415
+	if(sipcapture_init_rpc()!=0)
416
+	{
417
+		LM_ERR("failed to register RPC commands\n");
418
+		return -1;
419
+	}
412 420
 
413 421
 	db_url.len = strlen(db_url.s);
414 422
 	table_name.len = strlen(table_name.s);
... ...
@@ -1564,4 +1572,54 @@ int raw_capture_rcv_loop(int rsock, int port1, int port2, int ipip) {
1564 1572
 	return 0;
1565 1573
 }
1566 1574
 
1575
+static void sipcapture_rpc_status (rpc_t* rpc, void* c) {
1576
+	str status = {0, 0};
1577
+
1578
+	if (rpc->scan(c, "S", &status) < 1) {
1579
+		rpc->fault(c, 500, "Not enough parameters (on, off or check)");
1580
+		return;
1581
+	}
1582
+
1583
+	if(capture_on_flag==NULL) {
1584
+		rpc->fault(c, 500, "Internal error");
1585
+		return;
1586
+	}
1587
+
1588
+	if (strncasecmp(status.s, "on", strlen("on")) == 0) {
1589
+		*capture_on_flag = 1;
1590
+		rpc->printf(c, "Enabled");
1591
+		return;
1592
+	}
1593
+	if (strncasecmp(status.s, "off", strlen("off")) == 0) {
1594
+		*capture_on_flag = 0;
1595
+		rpc->printf(c, "Disabled");
1596
+		return;
1597
+	}
1598
+	if (strncasecmp(status.s, "check", strlen("check")) == 0) {
1599
+		rpc->printf(c, *capture_on_flag ? "Enabled" : "Disabled");
1600
+		return;
1601
+	} 
1602
+	rpc->fault(c, 500, "Bad parameter (on, off or check)");
1603
+	return;
1604
+}
1605
+
1606
+static const char* sipcapture_status_doc[2] = {
1607
+        "Get status or turn on/off sipcapture.",
1608
+        0
1609
+};
1610
+
1611
+rpc_export_t sipcapture_rpc[] = {
1612
+	{"sipcapture.status", sipcapture_rpc_status, sipcapture_status_doc, 0},
1613
+	{0, 0, 0, 0}
1614
+};
1615
+
1616
+static int sipcapture_init_rpc(void)
1617
+{
1618
+	if (rpc_register_array(sipcapture_rpc)!=0)
1619
+	{
1620
+		LM_ERR("failed to register RPC commands\n");
1621
+		return -1;
1622
+	}
1623
+	return 0;
1624
+}
1567 1625