Browse code

Merge pull request #806 from adubovikov/master

modules/sipcapture: added custom fields

Alexandr Dubovikov authored 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 341
 	{"type_column",			PARAM_STR, &type_column  },
342 342
 	{"node_column",			PARAM_STR, &node_column  },
343 343
 	{"msg_column",			PARAM_STR, &msg_column   },
344
+	{"custom_field1_column",	PARAM_STR, &custom_field1_column   },
345
+	{"custom_field2_column",	PARAM_STR, &custom_field2_column   },
346
+	{"custom_field3_column",	PARAM_STR, &custom_field3_column   },
344 347
 	{"capture_on",           	INT_PARAM, &capture_on          },
345 348
 	{"capture_node",     		PARAM_STR, &capture_node     	},
346 349
 	{"raw_sock_children",  		INT_PARAM, &raw_sock_children   },
... ...
@@ -353,6 +363,9 @@ static param_export_t params[] = {
353 353
 	{"promiscious_on",  		INT_PARAM, &promisc_on   },
354 354
 	{"raw_moni_bpf_on",  		INT_PARAM, &bpf_on   },
355 355
 	{"callid_aleg_header",          PARAM_STR, &callid_aleg_header},
356
+	{"custom_field1_header",        PARAM_STR, &custom_field1_header},
357
+	{"custom_field2_header",        PARAM_STR, &custom_field2_header},
358
+	{"custom_field3_header",        PARAM_STR, &custom_field3_header},
356 359
 	{"capture_mode",		PARAM_STRING|USE_FUNC_PARAM, (void *)capture_mode_param},
357 360
 	{"insert_retries",   		INT_PARAM, &insert_retries },
358 361
 	{"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 1508
 	tmp.len = sco->msg.len;
1509 1509
 
1510 1510
 	db_vals[40].val.blob_val = tmp;
1511
+	
1512
+	db_keys[41] = &custom_field1_column;
1513
+	db_vals[41].type = DB1_STR;
1514
+	db_vals[41].nul = 0;
1515
+	db_vals[41].val.str_val = sco->custom1;
1516
+	
1517
+	db_keys[42] = &custom_field2_column;
1518
+	db_vals[42].type = DB1_STR;
1519
+	db_vals[42].nul = 0;
1520
+	db_vals[42].val.str_val = sco->custom2;
1521
+	
1522
+	db_keys[43] = &custom_field3_column;
1523
+	db_vals[43].type = DB1_STR;
1524
+	db_vals[43].nul = 0;
1525
+	db_vals[43].val.str_val = sco->custom3;
1511 1526
 
1512 1527
 	if (dtable){
1513 1528
 		table = dtable;
... ...
@@ -1597,7 +1625,7 @@ static int sip_capture(struct sip_msg *msg, str *_table, _capture_mode_data_t *
1597 1597
 	struct _sipcapture_object sco;
1598 1598
 	struct sip_uri from, to, contact;
1599 1599
 	struct hdr_field *hook1 = NULL;
1600
-	hdr_field_t *tmphdr[4];
1600
+	hdr_field_t *tmphdr[7];
1601 1601
 	contact_body_t*  cb=0;
1602 1602
 	char buf_ip[IP_ADDR_MAX_STR_SIZE+12];
1603 1603
 	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 1869
 		sco.rtp_stat =  tmphdr[3]->body;
1870 1870
 	}
1871 1871
 	else { EMPTY_STR(sco.rtp_stat); }
1872
+	
1873
+	/* Custom - field1 */
1874
+	if(custom_field1_header.len > 0 && (tmphdr[4] = get_hdr_by_name(msg,custom_field1_header.s, custom_field1_header.len)) != NULL) {
1875
+		sco.custom1 =  tmphdr[4]->body;
1876
+	}
1877
+	else { EMPTY_STR(sco.custom1); }
1878
+	
1879
+	/* Custom - field2 */
1880
+	if(custom_field3_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) {
1881
+		sco.custom2 =  tmphdr[5]->body;
1882
+	}
1883
+	else { EMPTY_STR(sco.custom2); }
1884
+	
1885
+	/* Custom - field3 */
1886
+	if(custom_field3_header.len > 0 && (tmphdr[6] = get_hdr_by_name(msg,custom_field3_header.s, custom_field3_header.len)) != NULL) {
1887
+		sco.custom3 =  tmphdr[6]->body;
1888
+	}
1889
+	else { EMPTY_STR(sco.custom3); }
1872 1890
 
1873 1891
 	/* PROTO TYPE */
1874 1892
 	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