Browse code

cnxcc: use of pseudo-variables in *cnxcc:call-shutdown* event route

- Ticket FS#450
- Patch contributed by Guillaume Bour

Carlos Ruiz Diaz authored on 20/07/2014 13:40:22
Showing 4 changed files
... ...
@@ -110,14 +110,14 @@ static int set_max_channels(struct sip_msg* msg, char* str_pv_client, char* str_
110 110
 static int get_channel_count(struct sip_msg* msg, char* str_pv_client, char* str_pv_max_chan);
111 111
 static int terminate_all(struct sip_msg* msg, char* str_pv_client);
112 112
 
113
-static void start_billing(str *callid, str tags[2]);
113
+static void start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]);
114 114
 static void setup_billing(str *callid, unsigned int h_entry, unsigned int h_id);
115 115
 static void stop_billing(str *callid);
116 116
 static int add_call_by_cid(str *cid, call_t *call, credit_type_t type);
117 117
 static credit_data_t *get_or_create_credit_data_entry(str *client_id, credit_type_t type);
118 118
 static call_t *alloc_new_call_by_time(credit_data_t *credit_data, struct sip_msg *msg, int max_secs);
119 119
 static call_t *alloc_new_call_by_money(credit_data_t *credit_data, struct sip_msg *msg, double credit, double cost_per_second, int initial_pulse, int final_pulse);
120
-static void notify_call_termination(str *callid, str *from_tag, str *to_tag);
120
+static void notify_call_termination(sip_data_t *data);
121 121
 static void free_call(call_t *call);
122 122
 static int has_to_tag(struct sip_msg *msg);
123 123
 
... ...
@@ -388,7 +388,7 @@ static void dialog_confirmed_callback(struct dlg_cell *cell, int type, struct dl
388 388
 {
389 389
 	LM_DBG("Dialog confirmed for CID [%.*s]\n", cell->callid.len, cell->callid.s);
390 390
 
391
-	start_billing(&cell->callid, cell->tag);
391
+	start_billing(&cell->callid, &cell->from_uri, &cell->to_uri, cell->tag);
392 392
 }
393 393
 
394 394
 static void dialog_terminated_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params)
... ...
@@ -398,7 +398,7 @@ static void dialog_terminated_callback(struct dlg_cell *cell, int type, struct d
398 398
 	stop_billing(&cell->callid);
399 399
 }
400 400
 
401
-static void notify_call_termination(str *callid, str *from_tag, str *to_tag)
401
+static void notify_call_termination(sip_data_t *data)
402 402
 {
403 403
 	struct run_act_ctx ra_ctx;
404 404
 	struct sip_msg *msg;
... ...
@@ -406,9 +406,10 @@ static void notify_call_termination(str *callid, str *from_tag, str *to_tag)
406 406
 	if (_data.cs_route_number < 0)
407 407
 		return;
408 408
 
409
-	if (faked_msg_init_with_dlg_info(callid, from_tag, to_tag,  &msg) != 0)
409
+	if (faked_msg_init_with_dlg_info(&data->callid, &data->from_uri, &data->from_tag,
410
+				&data->to_uri, &data->to_tag, &msg) != 0)
410 411
 	{
411
-		LM_ERR("[%.*s]: error generating faked sip message\n", callid->len, callid->s);
412
+		LM_ERR("[%.*s]: error generating faked sip message\n", data->callid.len, data->callid.s);
412 413
 		return;
413 414
 	}
414 415
 
... ...
@@ -662,8 +663,8 @@ static void stop_billing(str *callid)
662 662
 
663 663
 static void setup_billing(str *callid, unsigned int h_entry, unsigned int h_id)
664 664
 {
665
-	call_t *call						= NULL;
666
-	hash_tables_t *hts					= NULL;
665
+	call_t *call		= NULL;
666
+	hash_tables_t *hts	= NULL;
667 667
 
668 668
 	LM_DBG("Creating dialog for [%.*s], h_id [%u], h_entry [%u]\n", callid->len, callid->s, h_id, h_entry);
669 669
 
... ...
@@ -710,12 +711,12 @@ static void setup_billing(str *callid, unsigned int h_entry, unsigned int h_id)
710 710
 	lock_release(&call->lock);
711 711
 }
712 712
 
713
-static void start_billing(str *callid, str tags[2])
713
+static void start_billing(str *callid, str *from_uri, str *to_uri, str tags[2])
714 714
 {
715 715
 	struct str_hash_entry *cd_entry		= NULL;
716
-	call_t *call						= NULL;
717
-	hash_tables_t *hts					= NULL;
718
-	credit_data_t *credit_data			= NULL;
716
+	call_t *call				= NULL;
717
+	hash_tables_t *hts			= NULL;
718
+	credit_data_t *credit_data		= NULL;
719 719
 
720 720
 	LM_DBG("Billing started for call [%.*s]\n", callid->len, callid->s);
721 721
 
... ...
@@ -815,10 +816,22 @@ static void start_billing(str *callid, str tags[2])
815 815
 		goto exit;
816 816
 	}
817 817
 
818
+	if(shm_str_dup(&call->sip_data.from_uri, from_uri) != 0 ||
819
+	   shm_str_dup(&call->sip_data.to_uri  , to_uri)   != 0)
820
+	{
821
+		LM_ERR("No more pkg memory\n");
822
+		goto exit;
823
+	}
824
+
818 825
 	call->start_timestamp	= get_current_timestamp();
819 826
 	call->confirmed			= TRUE;
820 827
 
821
-	LM_DBG("Call [%.*s] from client [%.*s], confirmed\n", callid->len, callid->s, call->client_id.len, call->client_id.s);
828
+	LM_DBG("Call [%.*s] from client [%.*s], confirmed. from=<%.*s>;tag=%.*s, to=<%.*s>;tag=%.*s\n",
829
+			callid->len, callid->s, call->client_id.len, call->client_id.s,
830
+			call->sip_data.from_uri.len, call->sip_data.from_uri.s,
831
+			call->sip_data.from_tag.len, call->sip_data.from_tag.s,
832
+			call->sip_data.to_uri.len, call->sip_data.to_uri.s,
833
+			call->sip_data.to_tag.len, call->sip_data.to_tag.s);
822 834
 
823 835
 exit:
824 836
 	lock_release(&call->lock);
... ...
@@ -1060,8 +1073,7 @@ int terminate_call(call_t *call)
1060 1060
 		free_mi_tree(root);
1061 1061
 		free_mi_tree(result);
1062 1062
 		
1063
-		notify_call_termination(&call->sip_data.callid, &call->sip_data.from_tag, &call->sip_data.to_tag);
1064
-
1063
+		notify_call_termination(&call->sip_data);
1065 1064
 		return 0;
1066 1065
 	}
1067 1066
 
... ...
@@ -89,8 +89,10 @@ typedef struct data
89 89
 typedef struct sip_data
90 90
 {
91 91
 	str callid;
92
-	str to_tag;
92
+	str from_uri;
93 93
 	str from_tag;
94
+	str to_uri;
95
+	str to_tag;
94 96
 } sip_data_t;
95 97
 
96 98
 typedef struct money_spec_data
... ...
@@ -27,21 +27,23 @@
27 27
 
28 28
 #include <sys/socket.h>
29 29
 
30
-#define FAKED_SIP_MSG_FORMAT "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <you@kamailio.org>;tag=%.*s\r\nTo: <you@kamailio.org>;tag=%.*s\r\nCall-ID: %.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
30
+#define FAKED_SIP_MSG_FORMAT "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: %.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
31 31
 
32 32
 #define FAKED_SIP_MSG_BUF_LEN	1024
33 33
 char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
34 34
 
35 35
 static struct sip_msg _faked_msg;
36 36
 
37
-int faked_msg_init_with_dlg_info(str *callid, str *from_tag, str *to_tag,  struct sip_msg **msg)
37
+int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg)
38 38
 {
39 39
 	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
40 40
 
41
-	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT, from_tag->len, from_tag->s,
42
-													  to_tag->len, to_tag->s,
43
-													  callid->len, callid->s);
41
+	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT,
42
+				from_uri->len, from_uri->s, from_tag->len, from_tag->s,
43
+				to_uri->len, to_uri->s, to_tag->len, to_tag->s,
44
+				callid->len, callid->s);
44 45
 
46
+	LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf);
45 47
 	memset(&_faked_msg, 0, sizeof(struct sip_msg));
46 48
 
47 49
 	_faked_msg.buf = _faked_sip_msg_buf;
... ...
@@ -52,8 +54,8 @@ int faked_msg_init_with_dlg_info(str *callid, str *from_tag, str *to_tag,  struc
52 52
 
53 53
 	if (parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg) != 0)
54 54
 	{
55
-			LM_ERR("parse_msg failed\n");
56
-			return -1;
55
+		LM_ERR("parse_msg failed\n");
56
+		return -1;
57 57
 	}
58 58
 
59 59
 	_faked_msg.rcv.proto = PROTO_UDP;
... ...
@@ -24,6 +24,6 @@
24 24
 #ifndef CNXCC_SIP_MSG_FAKER_H_
25 25
 #define CNXCC_SIP_MSG_FAKER_H_
26 26
 
27
-int faked_msg_init_with_dlg_info(str *callid, str *from_tag, str *to_tag,  struct sip_msg **msg);
27
+int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg);
28 28
 
29 29
 #endif /* CNXCC_SIP_MSG_FAKER_H_ */