Browse code

Merge pull request #806 from adubovikov/master

modules/sipcapture: added custom fields

Alexandr Dubovikov authored on 30/09/2016 11:51:42 • GitHub committed on 30/09/2016 11:51:42
Showing 2 changed files
... ...
@@ -95,7 +95,7 @@ MODULE_VERSION
95 95
 
96 96
 #define TABLE_LEN 256
97 97
 
98
-#define NR_KEYS 41
98
+#define NR_KEYS 44
99 99
 #define RTCP_NR_KEYS 12
100 100
 
101 101
 #define MAX_HEADERS 16
... ...
@@ -205,9 +205,16 @@ static str family_column 	= str_init("family");
205 205
 static str type_column 		= str_init("type");
206 206
 static str node_column 		= str_init("node");
207 207
 static str msg_column 		= str_init("msg");
208
+static str custom_field1_column = str_init("custom_field1");
209
+static str custom_field2_column = str_init("custom_field2");
210
+static str custom_field3_column = str_init("custom_field3");
208 211
 static str capture_node 	= str_init("homer01");
209 212
 static str star_contact		= str_init("*");
210 213
 static str callid_aleg_header   = str_init("X-CID");
214
+static str custom_field1_header   = str_init("Mac");
215
+static str custom_field2_header   = str_init("IP");
216
+static str custom_field3_header   = str_init("Port");
217
+
211 218
 
212 219
 int raw_sock_desc = -1; /* raw socket used for ip packets */
213 220
 unsigned int raw_sock_children = 1;
... ...
@@ -341,6 +348,9 @@ static param_export_t params[] = {
341 348
 	{"type_column",			PARAM_STR, &type_column  },
342 349
 	{"node_column",			PARAM_STR, &node_column  },
343 350
 	{"msg_column",			PARAM_STR, &msg_column   },
351
+	{"custom_field1_column",	PARAM_STR, &custom_field1_column   },
352
+	{"custom_field2_column",	PARAM_STR, &custom_field2_column   },
353
+	{"custom_field3_column",	PARAM_STR, &custom_field3_column   },
344 354
 	{"capture_on",           	INT_PARAM, &capture_on          },
345 355
 	{"capture_node",     		PARAM_STR, &capture_node     	},
346 356
 	{"raw_sock_children",  		INT_PARAM, &raw_sock_children   },
... ...
@@ -353,6 +363,9 @@ static param_export_t params[] = {
353 363
 	{"promiscious_on",  		INT_PARAM, &promisc_on   },
354 364
 	{"raw_moni_bpf_on",  		INT_PARAM, &bpf_on   },
355 365
 	{"callid_aleg_header",          PARAM_STR, &callid_aleg_header},
366
+	{"custom_field1_header",        PARAM_STR, &custom_field1_header},
367
+	{"custom_field2_header",        PARAM_STR, &custom_field2_header},
368
+	{"custom_field3_header",        PARAM_STR, &custom_field3_header},
356 369
 	{"capture_mode",		PARAM_STRING|USE_FUNC_PARAM, (void *)capture_mode_param},
357 370
 	{"insert_retries",   		INT_PARAM, &insert_retries },
358 371
 	{"insert_retry_timeout",	INT_PARAM, &insert_retry_timeout },
... ...
@@ -1508,6 +1521,21 @@ static int sip_capture_store(struct _sipcapture_object *sco, str *dtable, _captu
1508 1521
 	tmp.len = sco->msg.len;
1509 1522
 
1510 1523
 	db_vals[40].val.blob_val = tmp;
1524
+	
1525
+	db_keys[41] = &custom_field1_column;
1526
+	db_vals[41].type = DB1_STR;
1527
+	db_vals[41].nul = 0;
1528
+	db_vals[41].val.str_val = sco->custom1;
1529
+	
1530
+	db_keys[42] = &custom_field2_column;
1531
+	db_vals[42].type = DB1_STR;
1532
+	db_vals[42].nul = 0;
1533
+	db_vals[42].val.str_val = sco->custom2;
1534
+	
1535
+	db_keys[43] = &custom_field3_column;
1536
+	db_vals[43].type = DB1_STR;
1537
+	db_vals[43].nul = 0;
1538
+	db_vals[43].val.str_val = sco->custom3;
1511 1539
 
1512 1540
 	if (dtable){
1513 1541
 		table = dtable;
... ...
@@ -1597,7 +1625,7 @@ static int sip_capture(struct sip_msg *msg, str *_table, _capture_mode_data_t *
1597 1625
 	struct _sipcapture_object sco;
1598 1626
 	struct sip_uri from, to, contact;
1599 1627
 	struct hdr_field *hook1 = NULL;
1600
-	hdr_field_t *tmphdr[4];
1628
+	hdr_field_t *tmphdr[7];
1601 1629
 	contact_body_t*  cb=0;
1602 1630
 	char buf_ip[IP_ADDR_MAX_STR_SIZE+12];
1603 1631
 	char *port_str = NULL, *tmp = NULL;
... ...
@@ -1869,6 +1897,24 @@ static int sip_capture(struct sip_msg *msg, str *_table, _capture_mode_data_t *
1869 1897
 		sco.rtp_stat =  tmphdr[3]->body;
1870 1898
 	}
1871 1899
 	else { EMPTY_STR(sco.rtp_stat); }
1900
+	
1901
+	/* Custom - field1 */
1902
+	if(custom_field1_header.len > 0 && (tmphdr[4] = get_hdr_by_name(msg,custom_field1_header.s, custom_field1_header.len)) != NULL) {
1903
+		sco.custom1 =  tmphdr[4]->body;
1904
+	}
1905
+	else { EMPTY_STR(sco.custom1); }
1906
+	
1907
+	/* Custom - field2 */
1908
+	if(custom_field3_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) {
1909
+		sco.custom2 =  tmphdr[5]->body;
1910
+	}
1911
+	else { EMPTY_STR(sco.custom2); }
1912
+	
1913
+	/* Custom - field3 */
1914
+	if(custom_field3_header.len > 0 && (tmphdr[6] = get_hdr_by_name(msg,custom_field3_header.s, custom_field3_header.len)) != NULL) {
1915
+		sco.custom3 =  tmphdr[6]->body;
1916
+	}
1917
+	else { EMPTY_STR(sco.custom3); }
1872 1918
 
1873 1919
 	/* PROTO TYPE */
1874 1920
 	sco.proto = msg->rcv.proto;
... ...
@@ -65,6 +65,9 @@ struct _sipcapture_object {
65 65
 	long timestamp;
66 66
 	str node;
67 67
 	str msg;
68
+	str custom1;
69
+	str custom2;
70
+	str custom3;
68 71
 #ifdef STATISTICS
69 72
 	stat_var *stat;
70 73
 #endif