Browse code

cnxcc: build fake msg for event route before terminating the dialog

- dialog structure can be deleted in between
- reported by GH#324

Daniel-Constantin Mierla authored on 20/09/2015 21:16:35
Showing 1 changed files
... ...
@@ -118,7 +118,7 @@ static int __add_call_by_cid(str *cid, call_t *call, 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,
120 120
 		                                 double cost_per_second, int initial_pulse, int final_pulse);
121
-static void __notify_call_termination(sip_data_t *data);
121
+static void __notify_call_termination(sip_msg_t *msg);
122 122
 static void __free_call(call_t *call);
123 123
 static int __has_to_tag(struct sip_msg *msg);
124 124
 static credit_data_t *__alloc_new_credit_data(str *client_id, credit_type_t type);
... ...
@@ -454,18 +454,8 @@ static void __dialog_terminated_callback(struct dlg_cell *cell, int type, struct
454 454
 	__stop_billing(&cell->callid);
455 455
 }
456 456
 
457
-static void __notify_call_termination(sip_data_t *data) {
457
+static void __notify_call_termination(sip_msg_t *msg) {
458 458
 	struct run_act_ctx ra_ctx;
459
-	struct sip_msg *msg;
460
-
461
-	if (_data.cs_route_number < 0)
462
-		return;
463
-
464
-	if (faked_msg_init_with_dlg_info(&data->callid, &data->from_uri, &data->from_tag,
465
-					&data->to_uri, &data->to_tag, &msg) != 0) {
466
-		LM_ERR("[%.*s]: error generating faked sip message\n", data->callid.len, data->callid.s);
467
-		return;
468
-	}
469 459
 
470 460
 	init_run_actions_ctx(&ra_ctx);
471 461
 	//run_top_route(event_rt.rlist[_data.cs_route_number], msg, &ra_ctx);
... ...
@@ -958,6 +948,9 @@ static int __shm_str_hash_alloc(struct str_hash_table *ht, int size) {
958 958
 }
959 959
 
960 960
 int terminate_call(call_t *call) {
961
+	sip_msg_t *dmsg = NULL;
962
+	sip_data_t *data = NULL;
963
+
961 964
 	LM_DBG("Got kill signal for call [%.*s] client [%.*s] h_id [%u] h_entry [%u]. Dropping it now\n",
962 965
 		call->sip_data.callid.len,
963 966
 		call->sip_data.callid.s,
... ...
@@ -970,6 +963,14 @@ int terminate_call(call_t *call) {
970 970
 	struct mi_node *node, *node1	= NULL;
971 971
 	struct mi_cmd *end_dlg_cmd		= NULL;
972 972
 
973
+	if (_data.cs_route_number >= 0) {
974
+		data = &call->sip_data;
975
+		if (faked_msg_init_with_dlg_info(&data->callid, &data->from_uri, &data->from_tag,
976
+					&data->to_uri, &data->to_tag, &dmsg) != 0) {
977
+			LM_ERR("[%.*s]: error generating faked sip message\n", data->callid.len, data->callid.s);
978
+			dmsg = NULL;
979
+		}
980
+	}
973 981
 	root	= init_mi_tree(0, 0, 0);
974 982
 	if (root == NULL) {
975 983
 		LM_ERR("Error initializing tree to terminate call\n");
... ...
@@ -1006,7 +1007,7 @@ int terminate_call(call_t *call) {
1006 1006
 		free_mi_tree(root);
1007 1007
 		free_mi_tree(result);
1008 1008
 
1009
-		__notify_call_termination(&call->sip_data);
1009
+		if(dmsg) __notify_call_termination(dmsg);
1010 1010
 		return 0;
1011 1011
 	}
1012 1012