Browse code

cnxcc: clang format the code

Daniel-Constantin Mierla authored on 24/11/2017 11:37:54
Showing 14 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -32,7 +30,7 @@ double str2double(str *string)
32 32
 {
33 33
 	char buffer[string->len + 1];
34 34
 
35
-	buffer[string->len]	= '\0';
35
+	buffer[string->len] = '\0';
36 36
 	memcpy(buffer, string->s, string->len);
37 37
 
38 38
 	return atof(buffer);
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -27,8 +25,8 @@
27 27
 
28 28
 #include "../../core/str.h"
29 29
 
30
-#define DATETIME_SIZE		sizeof("0001-01-01 00:00:00")
31
-#define DATETIME_LENGTH		DATETIME_SIZE - 1
30
+#define DATETIME_SIZE sizeof("0001-01-01 00:00:00")
31
+#define DATETIME_LENGTH DATETIME_SIZE - 1
32 32
 
33 33
 
34 34
 static inline unsigned int get_current_timestamp()
... ...
@@ -38,14 +36,14 @@ static inline unsigned int get_current_timestamp()
38 38
 
39 39
 static inline int timestamp2isodt(str *dest, unsigned int timestamp)
40 40
 {
41
-	time_t  		tim;
42
-	struct tm 		*tmPtr;
41
+	time_t tim;
42
+	struct tm *tmPtr;
43 43
 
44
-	tim 		= timestamp;
45
-	tmPtr 		= localtime(&tim);
44
+	tim = timestamp;
45
+	tmPtr = localtime(&tim);
46 46
 
47
-	strftime( dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", tmPtr);
48
-	dest->len	= DATETIME_LENGTH;
47
+	strftime(dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", tmPtr);
48
+	dest->len = DATETIME_LENGTH;
49 49
 
50 50
 	return 0;
51 51
 }
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -32,85 +30,106 @@
32 32
 
33 33
 extern data_t _data;
34 34
 
35
-void check_calls_by_money(unsigned int ticks, void *param) {
36
-	struct str_hash_entry *h_entry = NULL,
37
-	                      *tmp = NULL;
35
+void check_calls_by_money(unsigned int ticks, void *param)
36
+{
37
+	struct str_hash_entry *h_entry = NULL, *tmp = NULL;
38 38
 	call_t *tmp_call = NULL;
39 39
 	int i;
40 40
 
41 41
 	cnxcc_lock(_data.money.lock);
42 42
 
43
-	if (_data.money.credit_data_by_client->table)
43
+	if(_data.money.credit_data_by_client->table)
44 44
 		for(i = 0; i < _data.money.credit_data_by_client->size; i++)
45
-			clist_foreach_safe(&_data.money.credit_data_by_client->table[i], h_entry, tmp, next) {
46
-				credit_data_t *credit_data = (credit_data_t *) h_entry->u.p;
45
+			clist_foreach_safe(&_data.money.credit_data_by_client->table[i],
46
+					h_entry, tmp, next)
47
+			{
48
+				credit_data_t *credit_data = (credit_data_t *)h_entry->u.p;
47 49
 				call_t *call = NULL;
48
-				double total_consumed_money = 0, consumption_diff = 0/*, distributed_consumption = 0*/;
50
+				double total_consumed_money = 0,
51
+					   consumption_diff = 0 /*, distributed_consumption = 0*/;
49 52
 
50
-/*				if (i > SAFE_ITERATION_THRESHOLD) {
53
+				/*				if (i > SAFE_ITERATION_THRESHOLD) {
51 54
 					LM_ERR("Too many iterations for this loop: %d\n", i);
52 55
 					break;
53 56
 				}*/
54 57
 
55 58
 				cnxcc_lock(credit_data->lock);
56 59
 
57
-				clist_foreach_safe(credit_data->call_list, call, tmp_call, next) {
60
+				clist_foreach_safe(credit_data->call_list, call, tmp_call, next)
61
+				{
58 62
 					int consumed_time = 0;
59 63
 
60
-					if (!call->confirmed)
64
+					if(!call->confirmed)
61 65
 						continue;
62 66
 
63
-					consumed_time = get_current_timestamp() - call->start_timestamp;
64
-
65
-					if (consumed_time > call->money_based.initial_pulse) {
66
-						call->consumed_amount = (call->money_based.cost_per_second * call->money_based.initial_pulse)
67
-												+
68
-												call->money_based.cost_per_second *
69
-												( (consumed_time - call->money_based.initial_pulse) / call->money_based.final_pulse + 1 ) *
70
-												call->money_based.final_pulse;
67
+					consumed_time =
68
+							get_current_timestamp() - call->start_timestamp;
69
+
70
+					if(consumed_time > call->money_based.initial_pulse) {
71
+						call->consumed_amount =
72
+								(call->money_based.cost_per_second
73
+										* call->money_based.initial_pulse)
74
+								+ call->money_based.cost_per_second
75
+										  * ((consumed_time
76
+													 - call->money_based
77
+															   .initial_pulse)
78
+															/ call->money_based
79
+																	  .final_pulse
80
+													+ 1)
81
+										  * call->money_based.final_pulse;
71 82
 					}
72 83
 
73 84
 					total_consumed_money += call->consumed_amount;
74 85
 
75
-					if (call->consumed_amount > call->max_amount) {
76
-						LM_ALERT("[%.*s] call has exhausted its credit. Breaking the loop\n", call->sip_data.callid.len, call->sip_data.callid.s);
86
+					if(call->consumed_amount > call->max_amount) {
87
+						LM_ALERT("[%.*s] call has exhausted its credit. "
88
+								 "Breaking the loop\n",
89
+								call->sip_data.callid.len,
90
+								call->sip_data.callid.s);
77 91
 						break;
78 92
 					}
79 93
 
80
-					LM_DBG("CID [%.*s], start_timestamp [%d], seconds alive [%d], consumed credit [%f]\n",
81
-																			call->sip_data.callid.len, call->sip_data.callid.s,
82
-																			call->start_timestamp,
83
-																			consumed_time,
84
-																			call->consumed_amount
85
-																			);
94
+					LM_DBG("CID [%.*s], start_timestamp [%d], seconds alive "
95
+						   "[%d], consumed credit [%f]\n",
96
+							call->sip_data.callid.len, call->sip_data.callid.s,
97
+							call->start_timestamp, consumed_time,
98
+							call->consumed_amount);
86 99
 				}
87 100
 
88
-				if (credit_data->concurrent_calls == 0) {
101
+				if(credit_data->concurrent_calls == 0) {
89 102
 					cnxcc_unlock(credit_data->lock);
90 103
 					continue;
91 104
 				}
92 105
 
93
-				if (_data.redis) {
94
-					LM_DBG("ec=%f, ca=%f, ca2=%f", credit_data->ended_calls_consumed_amount, total_consumed_money, credit_data->consumed_amount);
95
-
96
-					consumption_diff = credit_data->ended_calls_consumed_amount + total_consumed_money - credit_data->consumed_amount;
97
-					if (consumption_diff > 0)
98
-						redis_incr_by_double(credit_data, "consumed_amount", consumption_diff);
106
+				if(_data.redis) {
107
+					LM_DBG("ec=%f, ca=%f, ca2=%f",
108
+							credit_data->ended_calls_consumed_amount,
109
+							total_consumed_money, credit_data->consumed_amount);
110
+
111
+					consumption_diff = credit_data->ended_calls_consumed_amount
112
+									   + total_consumed_money
113
+									   - credit_data->consumed_amount;
114
+					if(consumption_diff > 0)
115
+						redis_incr_by_double(credit_data, "consumed_amount",
116
+								consumption_diff);
99 117
 				}
100 118
 
101
-				credit_data->consumed_amount = credit_data->ended_calls_consumed_amount + total_consumed_money /* + distributed_consumption */;
119
+				credit_data->consumed_amount =
120
+						credit_data->ended_calls_consumed_amount
121
+						+ total_consumed_money /* + distributed_consumption */;
102 122
 
103
-				LM_DBG("Client [%.*s] | Ended-Calls-Credit-Spent: %f  TotalCredit/MaxCredit: %f/%f\n",
104
-							credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
105
-							credit_data->ended_calls_consumed_amount,
106
-							credit_data->consumed_amount,
107
-							credit_data->max_amount);
123
+				LM_DBG("Client [%.*s] | Ended-Calls-Credit-Spent: %f  "
124
+					   "TotalCredit/MaxCredit: %f/%f\n",
125
+						credit_data->call_list->client_id.len,
126
+						credit_data->call_list->client_id.s,
127
+						credit_data->ended_calls_consumed_amount,
128
+						credit_data->consumed_amount, credit_data->max_amount);
108 129
 
109
-				if (credit_data->consumed_amount >= credit_data->max_amount) {
130
+				if(credit_data->consumed_amount >= credit_data->max_amount) {
110 131
 					terminate_all_calls(credit_data);
111 132
 
112 133
 					// make sure the rest of the servers kill the calls belonging to this customer
113
-					if (_data.redis)
134
+					if(_data.redis)
114 135
 						redis_publish_to_kill_list(credit_data);
115 136
 					cnxcc_unlock(credit_data->lock);
116 137
 					break;
... ...
@@ -122,7 +141,8 @@ void check_calls_by_money(unsigned int ticks, void *param) {
122 122
 	cnxcc_unlock(_data.money.lock);
123 123
 }
124 124
 
125
-void check_calls_by_time(unsigned int ticks, void *param) {
125
+void check_calls_by_time(unsigned int ticks, void *param)
126
+{
126 127
 	struct str_hash_entry *h_entry = NULL;
127 128
 	struct str_hash_entry *tmp = NULL;
128 129
 	call_t *tmp_call = NULL;
... ...
@@ -130,13 +150,15 @@ void check_calls_by_time(unsigned int ticks, void *param) {
130 130
 
131 131
 	cnxcc_lock(_data.time.lock);
132 132
 
133
-	if (_data.time.credit_data_by_client->table)
133
+	if(_data.time.credit_data_by_client->table)
134 134
 		for(i = 0; i < _data.time.credit_data_by_client->size; i++)
135
-			clist_foreach_safe(&_data.time.credit_data_by_client->table[i], h_entry, tmp, next) {
136
-				credit_data_t *credit_data = (credit_data_t *) h_entry->u.p;
135
+			clist_foreach_safe(&_data.time.credit_data_by_client->table[i],
136
+					h_entry, tmp, next)
137
+			{
138
+				credit_data_t *credit_data = (credit_data_t *)h_entry->u.p;
137 139
 				call_t *call = NULL;
138 140
 				int total_consumed_secs = 0;
139
-				double consumption_diff = 0/*, distributed_consumption = 0*/;
141
+				double consumption_diff = 0 /*, distributed_consumption = 0*/;
140 142
 
141 143
 				cnxcc_lock(credit_data->lock);
142 144
 
... ...
@@ -146,50 +168,64 @@ void check_calls_by_time(unsigned int ticks, void *param) {
146 146
 					break;
147 147
 				} */
148 148
 
149
-				LM_DBG("Iterating through calls of client [%.*s]\n", credit_data->call_list->client_id.len, credit_data->call_list->client_id.s);
149
+				LM_DBG("Iterating through calls of client [%.*s]\n",
150
+						credit_data->call_list->client_id.len,
151
+						credit_data->call_list->client_id.s);
150 152
 
151
-				clist_foreach_safe(credit_data->call_list, call, tmp_call, next) {
152
-					if (!call->confirmed)
153
+				clist_foreach_safe(credit_data->call_list, call, tmp_call, next)
154
+				{
155
+					if(!call->confirmed)
153 156
 						continue;
154 157
 
155
-					call->consumed_amount = get_current_timestamp() - call->start_timestamp;
156
-					total_consumed_secs	+= call->consumed_amount;
158
+					call->consumed_amount =
159
+							get_current_timestamp() - call->start_timestamp;
160
+					total_consumed_secs += call->consumed_amount;
157 161
 
158
-					if (call->consumed_amount > call->max_amount) {
159
-						LM_ALERT("[%.*s] call has exhausted its time. Breaking the loop\n", call->sip_data.callid.len, call->sip_data.callid.s);
162
+					if(call->consumed_amount > call->max_amount) {
163
+						LM_ALERT("[%.*s] call has exhausted its time. Breaking "
164
+								 "the loop\n",
165
+								call->sip_data.callid.len,
166
+								call->sip_data.callid.s);
160 167
 						break;
161 168
 					}
162 169
 
163
-					LM_DBG("CID [%.*s], start_timestamp [%d], seconds alive [%d]\n",
164
-																			call->sip_data.callid.len, call->sip_data.callid.s,
165
-																			call->start_timestamp,
166
-																			(int) call->consumed_amount
167
-																			);
170
+					LM_DBG("CID [%.*s], start_timestamp [%d], seconds alive "
171
+						   "[%d]\n",
172
+							call->sip_data.callid.len, call->sip_data.callid.s,
173
+							call->start_timestamp, (int)call->consumed_amount);
168 174
 				}
169 175
 
170
-				if (credit_data->concurrent_calls == 0) {
176
+				if(credit_data->concurrent_calls == 0) {
171 177
 					cnxcc_unlock(credit_data->lock);
172 178
 					continue;
173 179
 				}
174 180
 
175
-				if (_data.redis) {
176
-					consumption_diff = credit_data->ended_calls_consumed_amount + total_consumed_secs - credit_data->consumed_amount;
177
-					if (consumption_diff > 0)
178
-						redis_incr_by_double(credit_data, "consumed_amount", consumption_diff);
181
+				if(_data.redis) {
182
+					consumption_diff = credit_data->ended_calls_consumed_amount
183
+									   + total_consumed_secs
184
+									   - credit_data->consumed_amount;
185
+					if(consumption_diff > 0)
186
+						redis_incr_by_double(credit_data, "consumed_amount",
187
+								consumption_diff);
179 188
 				}
180 189
 
181
-				credit_data->consumed_amount = credit_data->ended_calls_consumed_amount + total_consumed_secs /*+ distributed_consumption*/;
190
+				credit_data->consumed_amount =
191
+						credit_data->ended_calls_consumed_amount
192
+						+ total_consumed_secs /*+ distributed_consumption*/;
182 193
 
183
-				LM_DBG("Client [%.*s] | Ended-Calls-Time: %d  TotalTime/MaxTime: %d/%d\n", credit_data->call_list->client_id.len, credit_data->call_list->client_id.s,
184
-																									(int) credit_data->ended_calls_consumed_amount,
185
-																									(int) credit_data->consumed_amount,
186
-																									(int) credit_data->max_amount);
194
+				LM_DBG("Client [%.*s] | Ended-Calls-Time: %d  "
195
+					   "TotalTime/MaxTime: %d/%d\n",
196
+						credit_data->call_list->client_id.len,
197
+						credit_data->call_list->client_id.s,
198
+						(int)credit_data->ended_calls_consumed_amount,
199
+						(int)credit_data->consumed_amount,
200
+						(int)credit_data->max_amount);
187 201
 
188
-				if (credit_data->consumed_amount >= credit_data->max_amount) {
202
+				if(credit_data->consumed_amount >= credit_data->max_amount) {
189 203
 					terminate_all_calls(credit_data);
190 204
 
191 205
 					// make sure the rest of the servers kill the calls belonging to this customer
192
-					if (_data.redis)
206
+					if(_data.redis)
193 207
 						redis_publish_to_kill_list(credit_data);
194 208
 					cnxcc_unlock(credit_data->lock);
195 209
 					break;
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -67,16 +67,16 @@
67 67
 MODULE_VERSION
68 68
 
69 69
 #define HT_SIZE 229
70
-#define MODULE_NAME	"cnxcc"
70
+#define MODULE_NAME "cnxcc"
71 71
 #define NUMBER_OF_TIMERS 2
72 72
 
73
-#define TRUE	1
74
-#define FALSE	!TRUE
73
+#define TRUE 1
74
+#define FALSE !TRUE
75 75
 
76 76
 data_t _data;
77 77
 struct dlg_binds _dlgbinds;
78 78
 
79
-static int __fixup_pvar(void** param, int param_no);
79
+static int __fixup_pvar(void **param, int param_no);
80 80
 
81 81
 /*
82 82
  *  module core functions
... ...
@@ -95,62 +95,77 @@ static void __free_credit_data_hash_entry(struct str_hash_entry *e);
95 95
  * PV management functions
96 96
  */
97 97
 static int __pv_parse_calls_param(pv_spec_p sp, str *in);
98
-static int __pv_get_calls(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
98
+static int __pv_get_calls(
99
+		struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
99 100
 
100 101
 /*
101 102
  * Billing management functions
102 103
  */
103
-static int __set_max_time(struct sip_msg* msg, char* number, char* str2);
104
-static int __update_max_time(struct sip_msg* msg, char* number, char* str2);
105
-static int __set_max_credit(struct sip_msg* msg, char *str_pv_client, char *str_pv_credit,
106
-                            char *str_pv_cps, char *str_pv_inip, char *str_pv_finp);
107
-static int __set_max_channels(struct sip_msg* msg, char* str_pv_client, char* str_pv_max_chan);
108
-static int __get_channel_count(struct sip_msg* msg, char* str_pv_client, char* str_pv_max_chan);
109
-static int __terminate_all(struct sip_msg* msg, char* str_pv_client);
110
-
111
-static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]);
112
-static void __setup_billing(str *callid, unsigned int h_entry, unsigned int h_id);
104
+static int __set_max_time(struct sip_msg *msg, char *number, char *str2);
105
+static int __update_max_time(struct sip_msg *msg, char *number, char *str2);
106
+static int __set_max_credit(struct sip_msg *msg, char *str_pv_client,
107
+		char *str_pv_credit, char *str_pv_cps, char *str_pv_inip,
108
+		char *str_pv_finp);
109
+static int __set_max_channels(
110
+		struct sip_msg *msg, char *str_pv_client, char *str_pv_max_chan);
111
+static int __get_channel_count(
112
+		struct sip_msg *msg, char *str_pv_client, char *str_pv_max_chan);
113
+static int __terminate_all(struct sip_msg *msg, char *str_pv_client);
114
+
115
+static void __start_billing(
116
+		str *callid, str *from_uri, str *to_uri, str tags[2]);
117
+static void __setup_billing(
118
+		str *callid, unsigned int h_entry, unsigned int h_id);
113 119
 static void __stop_billing(str *callid);
114 120
 static int __add_call_by_cid(str *cid, call_t *call, credit_type_t type);
115
-static call_t *__alloc_new_call_by_time(credit_data_t *credit_data, struct sip_msg *msg, int max_secs);
116
-static call_t *__alloc_new_call_by_money(credit_data_t *credit_data, struct sip_msg *msg, double credit,
117
-		                                 double cost_per_second, int initial_pulse, int final_pulse);
121
+static call_t *__alloc_new_call_by_time(
122
+		credit_data_t *credit_data, struct sip_msg *msg, int max_secs);
123
+static call_t *__alloc_new_call_by_money(credit_data_t *credit_data,
124
+		struct sip_msg *msg, double credit, double cost_per_second,
125
+		int initial_pulse, int final_pulse);
118 126
 static void __notify_call_termination(sip_msg_t *msg);
119 127
 static void __free_call(call_t *call);
120 128
 static int __has_to_tag(struct sip_msg *msg);
121
-static credit_data_t *__alloc_new_credit_data(str *client_id, credit_type_t type);
122
-static credit_data_t *__get_or_create_credit_data_entry(str *client_id, credit_type_t type);
129
+static credit_data_t *__alloc_new_credit_data(
130
+		str *client_id, credit_type_t type);
131
+static credit_data_t *__get_or_create_credit_data_entry(
132
+		str *client_id, credit_type_t type);
123 133
 
124 134
 /*
125 135
  * control interface
126 136
  */
127
-void rpc_credit_control_stats(rpc_t* rpc, void* ctx);
137
+void rpc_credit_control_stats(rpc_t *rpc, void *ctx);
128 138
 
129 139
 /*
130 140
  * Dialog management callback functions
131 141
  */
132
-static void __dialog_terminated_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params);
133
-static void __dialog_confirmed_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params);
134
-static void __dialog_created_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params);
135
-
142
+static void __dialog_terminated_callback(
143
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params);
144
+static void __dialog_confirmed_callback(
145
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params);
146
+static void __dialog_created_callback(
147
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params);
148
+
149
+/* clang-format off */
136 150
 static pv_export_t mod_pvs[] = {
137
-	{ {"cnxcc", sizeof("cnxcc")-1 }, PVT_OTHER, __pv_get_calls, 0, __pv_parse_calls_param, 0, 0, 0 },
151
+	{ {"cnxcc", sizeof("cnxcc")-1 }, PVT_OTHER, __pv_get_calls, 0,
152
+			__pv_parse_calls_param, 0, 0, 0 },
138 153
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
139 154
 };
140 155
 
141 156
 static cmd_export_t cmds[] = {
142
-	{"cnxcc_set_max_time", (cmd_function) __set_max_time, 2, fixup_pvar_pvar,
143
-        fixup_free_pvar_pvar, ANY_ROUTE},
144
-    {"cnxcc_update_max_time", (cmd_function) __update_max_time, 2, fixup_pvar_pvar,
145
-        fixup_free_pvar_pvar, ANY_ROUTE},
146
-    {"cnxcc_set_max_credit", (cmd_function) __set_max_credit, 5, __fixup_pvar,
147
-        NULL, ANY_ROUTE},
148
-    {"cnxcc_set_max_channels", (cmd_function) __set_max_channels, 2, fixup_pvar_pvar,
149
-        NULL, ANY_ROUTE},
150
-    {"cnxcc_get_channel_count", (cmd_function) __get_channel_count, 2, fixup_pvar_pvar,
151
-        NULL, ANY_ROUTE},
152
-    {"cnxcc_terminate_all", (cmd_function) __terminate_all, 1, fixup_pvar_null,
153
-        NULL, ANY_ROUTE},
157
+	{"cnxcc_set_max_time", (cmd_function) __set_max_time, 2,
158
+		fixup_pvar_pvar, fixup_free_pvar_pvar, ANY_ROUTE},
159
+	{"cnxcc_update_max_time", (cmd_function) __update_max_time, 2,
160
+		fixup_pvar_pvar, fixup_free_pvar_pvar, ANY_ROUTE},
161
+	{"cnxcc_set_max_credit", (cmd_function) __set_max_credit, 5,
162
+		__fixup_pvar, NULL, ANY_ROUTE},
163
+	{"cnxcc_set_max_channels", (cmd_function) __set_max_channels, 2,
164
+		fixup_pvar_pvar, NULL, ANY_ROUTE},
165
+	{"cnxcc_get_channel_count", (cmd_function) __get_channel_count, 2,
166
+		fixup_pvar_pvar, NULL, ANY_ROUTE},
167
+	{"cnxcc_terminate_all", (cmd_function) __terminate_all, 1,
168
+		fixup_pvar_null, NULL, ANY_ROUTE},
154 169
 	{0,0,0,0,0,0}
155 170
 };
156 171
 
... ...
@@ -160,45 +175,37 @@ static param_export_t params[] = {
160 160
 	{"redis", STR_PARAM, &_data.redis_cnn_str.s },
161 161
 	{ 0, 0, 0 }
162 162
 };
163
+/* clang-format on */
163 164
 
164
-static const char* rpc_active_clients_doc[2] = {
165
-	"List of clients with active calls",
166
-	NULL
167
-};
165
+static const char *rpc_active_clients_doc[2] = {
166
+		"List of clients with active calls", NULL};
168 167
 
169
-static const char* rpc_check_client_stats_doc[2] = {
170
-	"Check specific client calls",
171
-	NULL
172
-};
168
+static const char *rpc_check_client_stats_doc[2] = {
169
+		"Check specific client calls", NULL};
173 170
 
174
-static const char* rpc_kill_call_doc[2] = {
175
-	"Kill call using its call ID",
176
-	NULL
177
-};
178
-
179
-static const char* rpc_credit_control_stats_doc[2] = {
180
-	"List credit control stats",
181
-	NULL
182
-};
171
+static const char *rpc_kill_call_doc[2] = {"Kill call using its call ID", NULL};
183 172
 
173
+static const char *rpc_credit_control_stats_doc[2] = {
174
+		"List credit control stats", NULL};
184 175
 
176
+/* clang-format off */
185 177
 rpc_export_t cnxcc_rpc[] = {
186
-    { "cnxcc.active_clients", rpc_active_clients, rpc_active_clients_doc,	0},
187
-    { "cnxcc.check_client", rpc_check_client_stats, rpc_check_client_stats_doc,	0},
188
-    { "cnxcc.kill_call", rpc_kill_call, rpc_kill_call_doc, 0},
178
+	{ "cnxcc.active_clients", rpc_active_clients, rpc_active_clients_doc,	0},
179
+	{ "cnxcc.check_client", rpc_check_client_stats, rpc_check_client_stats_doc,	0},
180
+	{ "cnxcc.kill_call", rpc_kill_call, rpc_kill_call_doc, 0},
189 181
 	{ "cnxcc.stats", rpc_credit_control_stats, rpc_credit_control_stats_doc, 0},
190
-    { NULL, NULL, NULL, 0}
182
+	{ NULL, NULL, NULL, 0}
191 183
 };
192 184
 
193 185
 /* selects declaration */
194 186
 select_row_t sel_declaration[] = {
195
-        { NULL, SEL_PARAM_STR, STR_STATIC_INIT("cnxcc"), sel_root,
196
-        		SEL_PARAM_EXPECTED},
197
-        { sel_root, SEL_PARAM_STR, STR_STATIC_INIT("channels"), sel_channels,
198
-        		SEL_PARAM_EXPECTED|CONSUME_NEXT_STR|FIXUP_CALL},
199
-        { sel_channels, SEL_PARAM_STR, STR_STATIC_INIT("count"), sel_channels_count,
200
-        		0},
201
-        { NULL, SEL_PARAM_STR, STR_NULL, NULL, 0}
187
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("cnxcc"), sel_root,
188
+		SEL_PARAM_EXPECTED},
189
+	{ sel_root, SEL_PARAM_STR, STR_STATIC_INIT("channels"), sel_channels,
190
+		SEL_PARAM_EXPECTED|CONSUME_NEXT_STR|FIXUP_CALL},
191
+	{ sel_channels, SEL_PARAM_STR, STR_STATIC_INIT("count"), sel_channels_count,
192
+		0},
193
+	{ NULL, SEL_PARAM_STR, STR_NULL, NULL, 0}
202 194
 };
203 195
 
204 196
 /** module exports */
... ...
@@ -216,19 +223,20 @@ struct module_exports exports = {
216 216
 	NULL,
217 217
 	__child_init	/* per-child init function */
218 218
 };
219
+/* clang-format on */
219 220
 
220
-static int __fixup_pvar(void** param, int param_no) {
221
+static int __fixup_pvar(void **param, int param_no)
222
+{
221 223
 	str var;
222 224
 
223
-	var.s	= (char *) *param;
225
+	var.s = (char *)*param;
224 226
 	var.len = strlen(var.s);
225 227
 
226
-	if (fixup_pvar_null(param, 1))
227
-	{
228
+	if(fixup_pvar_null(param, 1)) {
228 229
 		LM_ERR("Invalid PV [%.*s] as parameter\n", var.len, var.s);
229 230
 		return E_CFG;
230 231
 	}
231
-/*
232
+	/*
232 233
 	if (((pv_spec_t*)(*param))->setf == NULL)
233 234
 	{
234 235
 		LM_ERR("[%.*s] has to be writable\n", var.len, var.s);
... ...
@@ -238,7 +246,8 @@ static int __fixup_pvar(void** param, int param_no) {
238 238
 	return 0;
239 239
 }
240 240
 
241
-static int __mod_init(void) {
241
+static int __mod_init(void)
242
+{
242 243
 	int len;
243 244
 	char *chr;
244 245
 
... ...
@@ -246,39 +255,44 @@ static int __mod_init(void) {
246 246
 
247 247
 	_data.cs_route_number = route_get(&event_rt, "cnxcc:call-shutdown");
248 248
 
249
-	if (_data.cs_route_number < 0)
249
+	if(_data.cs_route_number < 0)
250 250
 		LM_INFO("No cnxcc:call-shutdown event route found\n");
251 251
 
252
-	if (_data.cs_route_number > 0 && event_rt.rlist[_data.cs_route_number] == NULL) {
252
+	if(_data.cs_route_number > 0
253
+			&& event_rt.rlist[_data.cs_route_number] == NULL) {
253 254
 		LM_INFO("cnxcc:call-shutdown route is empty\n");
254
-		_data.cs_route_number	= -1;
255
+		_data.cs_route_number = -1;
255 256
 	}
256 257
 
257
-	if (_data.check_period <= 0) {
258
+	if(_data.check_period <= 0) {
258 259
 		LM_INFO("credit_check_period cannot be less than 1 second\n");
259 260
 		return -1;
260 261
 	}
261 262
 
262
-	if (_data.redis_cnn_str.s)
263
+	if(_data.redis_cnn_str.s)
263 264
 		_data.redis_cnn_str.len = strlen(_data.redis_cnn_str.s);
264 265
 
265
-	_data.time.credit_data_by_client = shm_malloc(sizeof(struct str_hash_table));
266
+	_data.time.credit_data_by_client =
267
+			shm_malloc(sizeof(struct str_hash_table));
266 268
 	_data.time.call_data_by_cid = shm_malloc(sizeof(struct str_hash_table));
267
-	_data.money.credit_data_by_client = shm_malloc(sizeof(struct str_hash_table));
269
+	_data.money.credit_data_by_client =
270
+			shm_malloc(sizeof(struct str_hash_table));
268 271
 	_data.money.call_data_by_cid = shm_malloc(sizeof(struct str_hash_table));
269
-	_data.channel.credit_data_by_client	= shm_malloc(sizeof(struct str_hash_table));
272
+	_data.channel.credit_data_by_client =
273
+			shm_malloc(sizeof(struct str_hash_table));
270 274
 	_data.channel.call_data_by_cid = shm_malloc(sizeof(struct str_hash_table));
271 275
 
272 276
 	memset(_data.time.credit_data_by_client, 0, sizeof(struct str_hash_table));
273 277
 	memset(_data.time.call_data_by_cid, 0, sizeof(struct str_hash_table));
274 278
 	memset(_data.money.credit_data_by_client, 0, sizeof(struct str_hash_table));
275 279
 	memset(_data.money.call_data_by_cid, 0, sizeof(struct str_hash_table));
276
-	memset(_data.channel.credit_data_by_client, 0, sizeof(struct str_hash_table));
280
+	memset(_data.channel.credit_data_by_client, 0,
281
+			sizeof(struct str_hash_table));
277 282
 	memset(_data.channel.call_data_by_cid, 0, sizeof(struct str_hash_table));
278 283
 
279
-	_data.stats = (stats_t *) shm_malloc(sizeof(stats_t));
284
+	_data.stats = (stats_t *)shm_malloc(sizeof(stats_t));
280 285
 
281
-	if (!_data.stats) {
286
+	if(!_data.stats) {
282 287
 		LM_ERR("Error allocating shared memory stats\n");
283 288
 		return -1;
284 289
 	}
... ...
@@ -287,22 +301,22 @@ static int __mod_init(void) {
287 287
 	_data.stats->dropped = 0;
288 288
 	_data.stats->total = 0;
289 289
 
290
-	if (__init_hashtable(_data.time.credit_data_by_client) != 0)
290
+	if(__init_hashtable(_data.time.credit_data_by_client) != 0)
291 291
 		return -1;
292 292
 
293
-	if (__init_hashtable(_data.time.call_data_by_cid) != 0)
293
+	if(__init_hashtable(_data.time.call_data_by_cid) != 0)
294 294
 		return -1;
295 295
 
296
-	if (__init_hashtable(_data.money.credit_data_by_client) != 0)
296
+	if(__init_hashtable(_data.money.credit_data_by_client) != 0)
297 297
 		return -1;
298 298
 
299
-	if (__init_hashtable(_data.money.call_data_by_cid) != 0)
299
+	if(__init_hashtable(_data.money.call_data_by_cid) != 0)
300 300
 		return -1;
301 301
 
302
-	if (__init_hashtable(_data.channel.credit_data_by_client) != 0)
302
+	if(__init_hashtable(_data.channel.credit_data_by_client) != 0)
303 303
 		return -1;
304 304
 
305
-	if (__init_hashtable(_data.channel.call_data_by_cid) != 0)
305
+	if(__init_hashtable(_data.channel.call_data_by_cid) != 0)
306 306
 		return -1;
307 307
 
308 308
 
... ...
@@ -318,110 +332,115 @@ static int __mod_init(void) {
318 318
 	 */
319 319
 	register_dummy_timers(NUMBER_OF_TIMERS);
320 320
 
321
-	if (rpc_register_array(cnxcc_rpc) != 0) {
321
+	if(rpc_register_array(cnxcc_rpc) != 0) {
322 322
 		LM_ERR("Failed registering RPC commands\n");
323 323
 		return -1;
324 324
 	}
325 325
 
326
-	if (load_dlg_api(&_dlgbinds) != 0) {
326
+	if(load_dlg_api(&_dlgbinds) != 0) {
327 327
 		LM_ERR("Error loading dialog API\n");
328
-	    return -1;
328
+		return -1;
329 329
 	}
330 330
 
331
-	_dlgbinds.register_dlgcb(NULL, DLGCB_CREATED, __dialog_created_callback, NULL, NULL);
331
+	_dlgbinds.register_dlgcb(
332
+			NULL, DLGCB_CREATED, __dialog_created_callback, NULL, NULL);
332 333
 
333 334
 	register_select_table(sel_declaration);
334 335
 
335 336
 	// redis configuration setup
336
-	if (_data.redis_cnn_str.len <= 0)
337
+	if(_data.redis_cnn_str.len <= 0)
337 338
 		return 0;
338 339
 
339 340
 	// replace ";" for " ", so we can use a simpler pattern in sscanf()
340 341
 	for(chr = _data.redis_cnn_str.s; *chr; chr++)
341
-		if (*chr == ';')
342
+		if(*chr == ';')
342 343
 			*chr = ' ';
343 344
 
344 345
 	memset(_data.redis_cnn_info.host, 0, sizeof(_data.redis_cnn_info.host));
345
-	sscanf(_data.redis_cnn_str.s, "addr=%s port=%d db=%d", _data.redis_cnn_info.host,
346
-                                                           &_data.redis_cnn_info.port,
347
-                                                           &_data.redis_cnn_info.db);
346
+	sscanf(_data.redis_cnn_str.s, "addr=%s port=%d db=%d",
347
+			_data.redis_cnn_info.host, &_data.redis_cnn_info.port,
348
+			&_data.redis_cnn_info.db);
348 349
 
349 350
 	len = strlen(_data.redis_cnn_info.host);
350 351
 	//
351 352
 	// Redis modparam validations
352 353
 	//
353
-	if (len == 0) {
354
+	if(len == 0) {
354 355
 		LM_ERR("invalid host address [%s]", _data.redis_cnn_info.host);
355 356
 		return -1;
356 357
 	}
357 358
 
358
-	if (_data.redis_cnn_info.port <= 0) {
359
+	if(_data.redis_cnn_info.port <= 0) {
359 360
 		LM_ERR("invalid port number [%d]", _data.redis_cnn_info.port);
360 361
 		return -1;
361 362
 	}
362 363
 
363
-	if (_data.redis_cnn_info.db < 0) {
364
-		LM_ERR("invalid db number [%d]",_data.redis_cnn_info.db);
364
+	if(_data.redis_cnn_info.db < 0) {
365
+		LM_ERR("invalid db number [%d]", _data.redis_cnn_info.db);
365 366
 		return -1;
366 367
 	}
367 368
 
368
-	LM_INFO("Redis connection info: ip=[%s], port=[%d], database=[%d]", _data.redis_cnn_info.host,
369
-			                                                            _data.redis_cnn_info.port,
370
-			                                                            _data.redis_cnn_info.db);
369
+	LM_INFO("Redis connection info: ip=[%s], port=[%d], database=[%d]",
370
+			_data.redis_cnn_info.host, _data.redis_cnn_info.port,
371
+			_data.redis_cnn_info.db);
371 372
 
372
-	register_procs(3/* 2 timers + 1 redis async receiver */);
373
+	register_procs(3 /* 2 timers + 1 redis async receiver */);
373 374
 	return 0;
374 375
 }
375 376
 
376
-static int __child_init(int rank) {
377
+static int __child_init(int rank)
378
+{
377 379
 	int pid = 0;
378 380
 
379
-	if (rank!=PROC_INIT && rank!=PROC_MAIN && rank!=PROC_TCP_MAIN) {
380
-		if (_data.redis_cnn_str.len <= 0)
381
+	if(rank != PROC_INIT && rank != PROC_MAIN && rank != PROC_TCP_MAIN) {
382
+		if(_data.redis_cnn_str.len <= 0)
381 383
 			return 0;
382 384
 
383 385
 		_data.redis = redis_connect(_data.redis_cnn_info.host,
384
-                                        _data.redis_cnn_info.port,
385
-                                        _data.redis_cnn_info.db);
386
+				_data.redis_cnn_info.port, _data.redis_cnn_info.db);
386 387
 		return (!_data.redis) ? -1 : 0;
387 388
 	}
388 389
 
389
-	if (rank != PROC_MAIN)
390
+	if(rank != PROC_MAIN)
390 391
 		return 0;
391 392
 
392
-	if(fork_dummy_timer(PROC_TIMER, "CNXCC TB TIMER", 1, check_calls_by_money, NULL, _data.check_period) < 0) {
393
+	if(fork_dummy_timer(PROC_TIMER, "CNXCC TB TIMER", 1, check_calls_by_money,
394
+			   NULL, _data.check_period)
395
+			< 0) {
393 396
 		LM_ERR("Failed registering TB TIMER routine as process\n");
394 397
 		return -1;
395 398
 	}
396 399
 
397
-	if(fork_dummy_timer(PROC_TIMER, "CNXCC MB TIMER", 1, check_calls_by_time, NULL, _data.check_period) < 0) {
400
+	if(fork_dummy_timer(PROC_TIMER, "CNXCC MB TIMER", 1, check_calls_by_time,
401
+			   NULL, _data.check_period)
402
+			< 0) {
398 403
 		LM_ERR("Failed registering MB TIMER routine as process\n");
399 404
 		return -1;
400 405
 	}
401 406
 
402
-	if (_data.redis_cnn_str.len <= 0)
407
+	if(_data.redis_cnn_str.len <= 0)
403 408
 		return 0;
404 409
 
405 410
 
406 411
 	pid = fork_process(PROC_NOCHLDINIT, "Redis Async receiver", 1);
407 412
 
408
-	if (pid < 0) {
413
+	if(pid < 0) {
409 414
 		LM_ERR("error forking Redis receiver\n");
410 415
 		return -1;
411
-	}
412
-	else if (pid == 0) {
416
+	} else if(pid == 0) {
413 417
 		_data.redis = redis_connect_async(_data.redis_cnn_info.host,
414
-                                          _data.redis_cnn_info.port,
415
-                                          _data.redis_cnn_info.db);
418
+				_data.redis_cnn_info.port, _data.redis_cnn_info.db);
416 419
 
417
-		return (!_data.redis) ? -1 : 0;;
420
+		return (!_data.redis) ? -1 : 0;
421
+		;
418 422
 	}
419 423
 
420 424
 	return 0;
421 425
 }
422 426
 
423
-static int __init_hashtable(struct str_hash_table *ht) {
424
-	if (__shm_str_hash_alloc(ht, HT_SIZE) != 0) {
427
+static int __init_hashtable(struct str_hash_table *ht)
428
+{
429
+	if(__shm_str_hash_alloc(ht, HT_SIZE) != 0) {
425 430
 		LM_ERR("Error allocating shared memory hashtable\n");
426 431
 		return -1;
427 432
 	}
... ...
@@ -430,53 +449,66 @@ static int __init_hashtable(struct str_hash_table *ht) {
430 430
 	return 0;
431 431
 }
432 432
 
433
-static void __dialog_created_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params) {
433
+static void __dialog_created_callback(
434
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
435
+{
434 436
 	struct sip_msg *msg = NULL;
435 437
 
436 438
 	msg = params->direction == SIP_REPLY ? params->rpl : params->req;
437 439
 
438
-	if (msg == NULL) {
440
+	if(msg == NULL) {
439 441
 		LM_ERR("Error getting direction of SIP msg\n");
440 442
 		return;
441 443
 	}
442 444
 
443
-	if (isflagset(msg, _data.ctrl_flag) == -1) {
445
+	if(isflagset(msg, _data.ctrl_flag) == -1) {
444 446
 		LM_DBG("Flag is not set for this message. Ignoring\n");
445 447
 		return;
446 448
 	}
447 449
 
448 450
 	LM_DBG("Dialog created for CID [%.*s]\n", cell->callid.len, cell->callid.s);
449 451
 
450
-	_dlgbinds.register_dlgcb(cell, DLGCB_CONFIRMED, __dialog_confirmed_callback, NULL, NULL);
451
-	_dlgbinds.register_dlgcb(cell, DLGCB_TERMINATED|DLGCB_FAILED|DLGCB_EXPIRED, __dialog_terminated_callback, NULL, NULL);
452
+	_dlgbinds.register_dlgcb(
453
+			cell, DLGCB_CONFIRMED, __dialog_confirmed_callback, NULL, NULL);
454
+	_dlgbinds.register_dlgcb(cell,
455
+			DLGCB_TERMINATED | DLGCB_FAILED | DLGCB_EXPIRED,
456
+			__dialog_terminated_callback, NULL, NULL);
452 457
 
453 458
 	__setup_billing(&cell->callid, cell->h_entry, cell->h_id);
454 459
 }
455 460
 
456
-static void __dialog_confirmed_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params) {
457
-	LM_DBG("Dialog confirmed for CID [%.*s]\n", cell->callid.len, cell->callid.s);
461
+static void __dialog_confirmed_callback(
462
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
463
+{
464
+	LM_DBG("Dialog confirmed for CID [%.*s]\n", cell->callid.len,
465
+			cell->callid.s);
458 466
 
459 467
 	__start_billing(&cell->callid, &cell->from_uri, &cell->to_uri, cell->tag);
460 468
 }
461 469
 
462
-static void __dialog_terminated_callback(struct dlg_cell *cell, int type, struct dlg_cb_params *params) {
463
-	LM_DBG("Dialog terminated for CID [%.*s]\n", cell->callid.len, cell->callid.s);
470
+static void __dialog_terminated_callback(
471
+		struct dlg_cell *cell, int type, struct dlg_cb_params *params)
472
+{
473
+	LM_DBG("Dialog terminated for CID [%.*s]\n", cell->callid.len,
474
+			cell->callid.s);
464 475
 
465 476
 	__stop_billing(&cell->callid);
466 477
 }
467 478
 
468
-static void __notify_call_termination(sip_msg_t *msg) {
479
+static void __notify_call_termination(sip_msg_t *msg)
480
+{
469 481
 	struct run_act_ctx ra_ctx;
470 482
 
471 483
 	init_run_actions_ctx(&ra_ctx);
472 484
 	//run_top_route(event_rt.rlist[_data.cs_route_number], msg, &ra_ctx);
473 485
 
474
-	if (run_actions(&ra_ctx, event_rt.rlist[_data.cs_route_number], msg) < 0)
486
+	if(run_actions(&ra_ctx, event_rt.rlist[_data.cs_route_number], msg) < 0)
475 487
 		LM_ERR("Error executing cnxcc:call-shutdown route\n");
476 488
 }
477 489
 
478
-int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data) {
479
-	struct str_hash_entry *cd_entry	= NULL;
490
+int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data)
491
+{
492
+	struct str_hash_entry *cd_entry = NULL;
480 493
 	hash_tables_t *hts = NULL;
481 494
 	*credit_data = NULL;
482 495
 
... ...
@@ -484,10 +516,11 @@ int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data) {
484 484
 	hts = &_data.money;
485 485
 	cnxcc_lock(hts->lock);
486 486
 
487
-	cd_entry = str_hash_get(hts->credit_data_by_client, client_id->s, client_id->len);
487
+	cd_entry = str_hash_get(
488
+			hts->credit_data_by_client, client_id->s, client_id->len);
488 489
 
489
-	if (cd_entry != NULL) {
490
-		*credit_data	= cd_entry->u.p;
490
+	if(cd_entry != NULL) {
491
+		*credit_data = cd_entry->u.p;
491 492
 		cnxcc_unlock(hts->lock);
492 493
 		return 0;
493 494
 	}
... ...
@@ -498,10 +531,11 @@ int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data) {
498 498
 	hts = &_data.time;
499 499
 	cnxcc_lock(hts->lock);
500 500
 
501
-	cd_entry = str_hash_get(hts->credit_data_by_client, client_id->s, client_id->len);
501
+	cd_entry = str_hash_get(
502
+			hts->credit_data_by_client, client_id->s, client_id->len);
502 503
 
503
-	if (cd_entry != NULL) {
504
-		*credit_data	= cd_entry->u.p;
504
+	if(cd_entry != NULL) {
505
+		*credit_data = cd_entry->u.p;
505 506
 		cnxcc_unlock(hts->lock);
506 507
 		return 0;
507 508
 	}
... ...
@@ -512,10 +546,11 @@ int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data) {
512 512
 	hts = &_data.channel;
513 513
 	cnxcc_lock(hts->lock);
514 514
 
515
-	cd_entry = str_hash_get(hts->credit_data_by_client, client_id->s, client_id->len);
515
+	cd_entry = str_hash_get(
516
+			hts->credit_data_by_client, client_id->s, client_id->len);
516 517
 
517
-	if (cd_entry != NULL) {
518
-		*credit_data	= cd_entry->u.p;
518
+	if(cd_entry != NULL) {
519
+		*credit_data = cd_entry->u.p;
519 520
 		cnxcc_unlock(hts->lock);
520 521
 		return 0;
521 522
 	}
... ...
@@ -524,7 +559,8 @@ int try_get_credit_data_entry(str *client_id, credit_data_t **credit_data) {
524 524
 	return -1;
525 525
 }
526 526
 
527
-int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts) {
527
+int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts)
528
+{
528 529
 	struct str_hash_entry *call_entry = NULL;
529 530
 
530 531
 	*call = NULL;
... ...
@@ -535,7 +571,7 @@ int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts) {
535 535
 
536 536
 	call_entry = str_hash_get((*hts)->call_data_by_cid, callid->s, callid->len);
537 537
 
538
-	if (call_entry != NULL) {
538
+	if(call_entry != NULL) {
539 539
 		*call = call_entry->u.p;
540 540
 		cnxcc_unlock((*hts)->lock);
541 541
 		return 0;
... ...
@@ -549,7 +585,7 @@ int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts) {
549 549
 
550 550
 	call_entry = str_hash_get((*hts)->call_data_by_cid, callid->s, callid->len);
551 551
 
552
-	if (call_entry != NULL) {
552
+	if(call_entry != NULL) {
553 553
 		*call = call_entry->u.p;
554 554
 		cnxcc_unlock((*hts)->lock);
555 555
 		return 0;
... ...
@@ -563,7 +599,7 @@ int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts) {
563 563
 
564 564
 	call_entry = str_hash_get((*hts)->call_data_by_cid, callid->s, callid->len);
565 565
 
566
-	if (call_entry != NULL) {
566
+	if(call_entry != NULL) {
567 567
 		*call = call_entry->u.p;
568 568
 		cnxcc_unlock((*hts)->lock);
569 569
 		return 0;
... ...
@@ -573,27 +609,29 @@ int try_get_call_entry(str *callid, call_t **call, hash_tables_t **hts) {
573 573
 	return -1;
574 574
 }
575 575
 
576
-static void __stop_billing(str *callid) {
577
-	struct str_hash_entry *cd_entry	= NULL;
578
-	call_t *call			= NULL;
579
-	hash_tables_t *hts		= NULL;
580
-	credit_data_t *credit_data	= NULL;
576
+static void __stop_billing(str *callid)
577
+{
578
+	struct str_hash_entry *cd_entry = NULL;
579
+	call_t *call = NULL;
580
+	hash_tables_t *hts = NULL;
581
+	credit_data_t *credit_data = NULL;
581 582
 
582 583
 	/*
583 584
 	 * Search call data by call-id
584 585
 	 */
585
-	if (try_get_call_entry(callid, &call, &hts) != 0) {
586
+	if(try_get_call_entry(callid, &call, &hts) != 0) {
586 587
 		LM_ERR("Call [%.*s] not found\n", callid->len, callid->s);
587 588
 		return;
588 589
 	}
589 590
 
590
-	if (call == NULL) {
591
+	if(call == NULL) {
591 592
 		LM_ERR("[%.*s] call pointer is null\n", callid->len, callid->s);
592 593
 		return;
593 594
 	}
594 595
 
595
-	if (hts == NULL) {
596
-		LM_ERR("[%.*s] result hashtable pointer is null\n", callid->len, callid->s);
596
+	if(hts == NULL) {
597
+		LM_ERR("[%.*s] result hashtable pointer is null\n", callid->len,
598
+				callid->s);
597 599
 		return;
598 600
 	}
599 601
 
... ...
@@ -602,17 +640,19 @@ static void __stop_billing(str *callid) {
602 602
 	/*
603 603
 	 * Search credit_data by client_id
604 604
 	 */
605
-	cd_entry = str_hash_get(hts->credit_data_by_client, call->client_id.s, call->client_id.len);
605
+	cd_entry = str_hash_get(
606
+			hts->credit_data_by_client, call->client_id.s, call->client_id.len);
606 607
 
607
-	if (cd_entry == NULL) {
608
-		LM_ERR("Credit data not found for CID [%.*s], client-ID [%.*s]\n", callid->len, callid->s, call->client_id.len, call->client_id.s);
608
+	if(cd_entry == NULL) {
609
+		LM_ERR("Credit data not found for CID [%.*s], client-ID [%.*s]\n",
610
+				callid->len, callid->s, call->client_id.len, call->client_id.s);
609 611
 		cnxcc_unlock(hts->lock);
610 612
 		return;
611 613
 	}
612 614
 
613
-	credit_data = (credit_data_t *) cd_entry->u.p;
615
+	credit_data = (credit_data_t *)cd_entry->u.p;
614 616
 
615
-	if (credit_data == NULL) {
617
+	if(credit_data == NULL) {
616 618
 		LM_ERR("[%.*s]: credit_data pointer is null\n", callid->len, callid->s);
617 619
 		cnxcc_unlock(hts->lock);
618 620
 		return;
... ...
@@ -632,43 +672,48 @@ static void __stop_billing(str *callid) {
632 632
 
633 633
 	cnxcc_lock(credit_data->lock);
634 634
 
635
-	LM_DBG("Call [%.*s] of client-ID [%.*s], ended\n", callid->len, callid->s, call->client_id.len, call->client_id.s);
635
+	LM_DBG("Call [%.*s] of client-ID [%.*s], ended\n", callid->len, callid->s,
636
+			call->client_id.len, call->client_id.s);
636 637
 
637 638
 	/*
638 639
 	 * This call just ended and we need to remove it from the summ.
639 640
 	 */
640
-	if (call->confirmed) {
641
+	if(call->confirmed) {
641 642
 		credit_data->concurrent_calls--;
642 643
 		credit_data->ended_calls_consumed_amount += call->consumed_amount;
643 644
 
644
-		if (_data.redis) {
645
+		if(_data.redis) {
645 646
 			redis_incr_by_int(credit_data, "concurrent_calls", -1);
646
-			redis_incr_by_double(credit_data, "ended_calls_consumed_amount", call->consumed_amount);
647
+			redis_incr_by_double(credit_data, "ended_calls_consumed_amount",
648
+					call->consumed_amount);
647 649
 		}
648 650
 	}
649 651
 
650 652
 	credit_data->number_of_calls--;
651 653
 
652
-	if (_data.redis)
654
+	if(_data.redis)
653 655
 		redis_incr_by_int(credit_data, "number_of_calls", -1);
654 656
 
655
-	if (credit_data->concurrent_calls < 0) {
656
-		LM_ERR("[BUG]: number of concurrent calls dropped to negative value: %d\n", credit_data->concurrent_calls);
657
+	if(credit_data->concurrent_calls < 0) {
658
+		LM_ERR("[BUG]: number of concurrent calls dropped to negative value: "
659
+			   "%d\n",
660
+				credit_data->concurrent_calls);
657 661
 	}
658 662
 
659
-	if (credit_data->number_of_calls < 0) {
660
-		LM_ERR("[BUG]: number of calls dropped to negative value: %d\n", credit_data->number_of_calls);
663
+	if(credit_data->number_of_calls < 0) {
664
+		LM_ERR("[BUG]: number of calls dropped to negative value: %d\n",
665
+				credit_data->number_of_calls);
661 666
 	}
662 667
 
663 668
 	/*
664 669
 	 * Remove (and free) the call from the list of calls of the current credit_data
665 670
 	 */
666 671
 	clist_rm(call, next, prev);
667
-	
672
+
668 673
 	/* return if credit_data is being deallocated.
669 674
 	 * the call and the credit data will be freed by terminate_all_calls()
670 675
 	 */
671
-	if (credit_data->deallocating) {
676
+	if(credit_data->deallocating) {
672 677
 		return;
673 678
 	}
674 679
 
... ...
@@ -678,13 +723,15 @@ static void __stop_billing(str *callid) {
678 678
 	 * This way, we can save memory for useful clients.
679 679
 	 *
680 680
 	 */
681
-	if (credit_data->number_of_calls == 0) {
682
-		LM_DBG("Removing client [%.*s] and its calls from the list\n", credit_data->call_list->client_id.len, credit_data->call_list->client_id.s);
681
+	if(credit_data->number_of_calls == 0) {
682
+		LM_DBG("Removing client [%.*s] and its calls from the list\n",
683
+				credit_data->call_list->client_id.len,
684
+				credit_data->call_list->client_id.s);
683 685
 
684 686
 		credit_data->deallocating = 1;
685 687
 		cnxcc_lock(hts->lock);
686 688
 
687
-		if (_data.redis) {
689
+		if(_data.redis) {
688 690
 			redis_clean_up_if_last(credit_data);
689 691
 			shm_free(credit_data->str_id);
690 692
 		}
... ...
@@ -721,29 +768,33 @@ static void __stop_billing(str *callid) {
721 721
 	cnxcc_unlock(credit_data->lock);
722 722
 }
723 723
 
724
-static void __setup_billing(str *callid, unsigned int h_entry, unsigned int h_id) {
725
-	call_t *call		= NULL;
726
-	hash_tables_t *hts	= NULL;
724
+static void __setup_billing(
725
+		str *callid, unsigned int h_entry, unsigned int h_id)
726
+{
727
+	call_t *call = NULL;
728
+	hash_tables_t *hts = NULL;
727 729
 
728
-	LM_DBG("Creating dialog for [%.*s], h_id [%u], h_entry [%u]\n", callid->len, callid->s, h_id, h_entry);
730
+	LM_DBG("Creating dialog for [%.*s], h_id [%u], h_entry [%u]\n", callid->len,
731
+			callid->s, h_id, h_entry);
729 732
 
730
-//	cnxcc_lock(&_data);
733
+	//	cnxcc_lock(&_data);
731 734
 
732 735
 	/*
733 736
 	 * Search call data by call-id
734 737
 	 */
735
-	if (try_get_call_entry(callid, &call, &hts) != 0) {
738
+	if(try_get_call_entry(callid, &call, &hts) != 0) {
736 739
 		LM_ERR("Call [%.*s] not found\n", callid->len, callid->s);
737 740
 		return;
738 741
 	}
739 742
 
740
-	if (call == NULL) {
743
+	if(call == NULL) {
741 744
 		LM_ERR("[%.*s] call pointer is null\n", callid->len, callid->s);
742 745
 		return;
743 746
 	}
744 747
 
745
-	if (hts == NULL) {
746
-		LM_ERR("[%.*s] result hashtable pointer is null\n", callid->len, callid->s);
748
+	if(hts == NULL) {
749
+		LM_ERR("[%.*s] result hashtable pointer is null\n", callid->len,
750
+				callid->s);
747 751
 		return;
748 752
 	}
749 753
 
... ...
@@ -759,39 +810,43 @@ static void __setup_billing(str *callid, unsigned int h_entry, unsigned int h_id
759 759
 
760 760
 	cnxcc_lock(call->lock);
761 761
 
762
-	call->dlg_h_entry	= h_entry;
763
-	call->dlg_h_id		= h_id;
762
+	call->dlg_h_entry = h_entry;
763
+	call->dlg_h_id = h_id;
764 764
 
765
-	LM_DBG("Call [%.*s] from client [%.*s], created\n", callid->len, callid->s, call->client_id.len, call->client_id.s);
765
+	LM_DBG("Call [%.*s] from client [%.*s], created\n", callid->len, callid->s,
766
+			call->client_id.len, call->client_id.s);
766 767
 
767 768
 	cnxcc_unlock(call->lock);
768 769
 }
769 770
 
770
-static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]) {
771
-	struct str_hash_entry *cd_entry	= NULL;
772
-	call_t *call			= NULL;
773
-	hash_tables_t *hts		= NULL;
774
-	credit_data_t *credit_data	= NULL;
771
+static void __start_billing(
772
+		str *callid, str *from_uri, str *to_uri, str tags[2])
773
+{
774
+	struct str_hash_entry *cd_entry = NULL;
775
+	call_t *call = NULL;
776
+	hash_tables_t *hts = NULL;
777
+	credit_data_t *credit_data = NULL;
775 778
 
776 779
 	LM_DBG("Billing started for call [%.*s]\n", callid->len, callid->s);
777 780
 
778
-//	cnxcc_lock(&_data);
781
+	//	cnxcc_lock(&_data);
779 782
 
780 783
 	/*
781 784
 	 * Search call data by call-id
782 785
 	 */
783
-	if (try_get_call_entry(callid, &call, &hts) != 0) {
786
+	if(try_get_call_entry(callid, &call, &hts) != 0) {
784 787
 		LM_ERR("Call [%.*s] not found\n", callid->len, callid->s);
785 788
 		return;
786 789
 	}
787 790
 
788
-	if (call == NULL) {
791
+	if(call == NULL) {
789 792
 		LM_ERR("[%.*s] call pointer is null\n", callid->len, callid->s);
790 793
 		return;
791 794
 	}
792 795
 
793
-	if (hts == NULL) {
794
-		LM_ERR("[%.*s] result hashtable pointer is null", callid->len, callid->s);
796
+	if(hts == NULL) {
797
+		LM_ERR("[%.*s] result hashtable pointer is null", callid->len,
798
+				callid->s);
795 799
 		return;
796 800
 	}
797 801
 
... ...
@@ -800,17 +855,19 @@ static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]
800 800
 	/*
801 801
 	 * Search credit_data by client_id
802 802
 	 */
803
-	cd_entry = str_hash_get(hts->credit_data_by_client, call->client_id.s, call->client_id.len);
803
+	cd_entry = str_hash_get(
804
+			hts->credit_data_by_client, call->client_id.s, call->client_id.len);
804 805
 
805
-	if (cd_entry == NULL) {
806
-		LM_ERR("Credit data not found for CID [%.*s], client-ID [%.*s]\n", callid->len, callid->s, call->client_id.len, call->client_id.s);
806
+	if(cd_entry == NULL) {
807
+		LM_ERR("Credit data not found for CID [%.*s], client-ID [%.*s]\n",
808
+				callid->len, callid->s, call->client_id.len, call->client_id.s);
807 809
 		cnxcc_unlock(hts->lock);
808 810
 		return;
809 811
 	}
810 812
 
811
-	credit_data = (credit_data_t *) cd_entry->u.p;
813
+	credit_data = (credit_data_t *)cd_entry->u.p;
812 814
 
813
-	if (credit_data == NULL) {
815
+	if(credit_data == NULL) {
814 816
 		LM_ERR("[%.*s]: credit_data pointer is null\n", callid->len, callid->s);
815 817
 		cnxcc_unlock(hts->lock);
816 818
 		return;
... ...
@@ -827,23 +884,27 @@ static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]
827 827
 	 */
828 828
 	credit_data->concurrent_calls++;
829 829
 
830
-	if (_data.redis)
830
+	if(_data.redis)
831 831
 		redis_incr_by_int(credit_data, "concurrent_calls", 1);
832 832
 
833
-	if (credit_data->max_amount == 0) {
834
-		credit_data->max_amount	= call->max_amount; // first time setup
833
+	if(credit_data->max_amount == 0) {
834
+		credit_data->max_amount = call->max_amount; // first time setup
835 835
 
836
-		if (_data.redis)
837
-			redis_insert_double_value(credit_data, "max_amount", credit_data->max_amount);
836
+		if(_data.redis)
837
+			redis_insert_double_value(
838
+					credit_data, "max_amount", credit_data->max_amount);
838 839
 	}
839 840
 
840
-	if (call->max_amount > credit_data->max_amount) {
841
-		LM_ALERT("Maximum-talk-time/credit changed, maybe a credit reload? %f > %f. Client [%.*s]\n", call->max_amount, credit_data->max_amount,
842
-																							call->client_id.len, call->client_id.s);
841
+	if(call->max_amount > credit_data->max_amount) {
842
+		LM_ALERT("Maximum-talk-time/credit changed, maybe a credit reload? %f "
843
+				 "> %f. Client [%.*s]\n",
844
+				call->max_amount, credit_data->max_amount, call->client_id.len,
845
+				call->client_id.s);
843 846
 
844 847
 
845
-		if (_data.redis)
846
-			redis_insert_double_value(credit_data, "max_amount", call->max_amount - credit_data->max_amount);
848
+		if(_data.redis)
849
+			redis_insert_double_value(credit_data, "max_amount",
850
+					call->max_amount - credit_data->max_amount);
847 851
 
848 852
 		credit_data->max_amount += call->max_amount - credit_data->max_amount;
849 853
 	}
... ...
@@ -860,7 +921,7 @@ static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]
860 860
 	/*
861 861
 	 * Store from-tag value
862 862
 	 */
863
-	if (shm_str_dup(&call->sip_data.from_tag, &tags[0]) != 0) {
863
+	if(shm_str_dup(&call->sip_data.from_tag, &tags[0]) != 0) {
864 864
 		LM_ERR("No more pkg memory\n");
865 865
 		goto exit;
866 866
 	}
... ...
@@ -868,21 +929,22 @@ static void __start_billing(str *callid, str *from_uri, str *to_uri, str tags[2]
868 868
 	/*
869 869
 	 * Store to-tag value
870 870
 	 */
871
-	if (shm_str_dup(&call->sip_data.to_tag, &tags[1]) != 0) {
871
+	if(shm_str_dup(&call->sip_data.to_tag, &tags[1]) != 0) {
872 872
 		LM_ERR("No more pkg memory\n");
873 873
 		goto exit;
874 874
 	}
875 875
 
876
-	if(shm_str_dup(&call->sip_data.from_uri, from_uri) != 0 ||
877
-	   shm_str_dup(&call->sip_data.to_uri  , to_uri)   != 0) {
876
+	if(shm_str_dup(&call->sip_data.from_uri, from_uri) != 0
877
+			|| shm_str_dup(&call->sip_data.to_uri, to_uri) != 0) {
878 878
 		LM_ERR("No more pkg memory\n");
879 879
 		goto exit;
880 880
 	}
881 881
 
882
-	call->start_timestamp	= get_current_timestamp();
883
-	call->confirmed		= TRUE;
882
+	call->start_timestamp = get_current_timestamp();
883
+	call->confirmed = TRUE;
884 884
 
885
-	LM_DBG("Call [%.*s] from client [%.*s], confirmed. from=<%.*s>;tag=%.*s, to=<%.*s>;tag=%.*s\n",
885
+	LM_DBG("Call [%.*s] from client [%.*s], confirmed. from=<%.*s>;tag=%.*s, "
886
+		   "to=<%.*s>;tag=%.*s\n",
886 887
 			callid->len, callid->s, call->client_id.len, call->client_id.s,
887 888
 			call->sip_data.from_uri.len, call->sip_data.from_uri.s,
888 889
 			call->sip_data.from_tag.len, call->sip_data.from_tag.s,
... ...
@@ -894,39 +956,40 @@ exit:
894 894
 
895 895
 // must be called with lock held on credit_data
896 896
 /* terminate all calls and remove credit_data */
897
-void terminate_all_calls(credit_data_t *credit_data) {
898
-	call_t *call = NULL,
899
-           *tmp = NULL;
897
+void terminate_all_calls(credit_data_t *credit_data)
898
+{
899
+	call_t *call = NULL, *tmp = NULL;
900 900
 	struct str_hash_entry *cd_entry = NULL;
901
-	hash_tables_t *hts      = NULL;
901
+	hash_tables_t *hts = NULL;
902 902
 
903 903
 	switch(credit_data->type) {
904
-        case CREDIT_MONEY:
905
-            hts =  &_data.money;
906
-            break;
907
-        case CREDIT_TIME:
908
-            hts =  &_data.time;
909
-            break;
910
-        case CREDIT_CHANNEL:
911
-            hts =  &_data.channel;
912
-            break;
913
-        default:
914
-            LM_ERR("BUG: Something went terribly wrong\n");
915
-            return;
916
-    }
904
+		case CREDIT_MONEY:
905
+			hts = &_data.money;
906
+			break;
907
+		case CREDIT_TIME:
908
+			hts = &_data.time;
909
+			break;
910
+		case CREDIT_CHANNEL:
911
+			hts = &_data.channel;
912
+			break;
913
+		default:
914
+			LM_ERR("BUG: Something went terribly wrong\n");
915
+			return;
916
+	}
917 917
 
918 918
 	cd_entry = str_hash_get(hts->credit_data_by_client,
919 919
 			credit_data->call_list->client_id.s,
920 920
 			credit_data->call_list->client_id.len);
921 921
 
922
-	if(cd_entry==NULL) {
922
+	if(cd_entry == NULL) {
923 923
 		LM_WARN("credit data itme not found\n");
924 924
 		return;
925 925
 	}
926 926
 	credit_data->deallocating = 1;
927 927
 
928
-	clist_foreach_safe(credit_data->call_list, call, tmp, next) {
929
-		if(call->sip_data.callid.s!=NULL) {
928
+	clist_foreach_safe(credit_data->call_list, call, tmp, next)
929
+	{
930
+		if(call->sip_data.callid.s != NULL) {
930 931
 			LM_DBG("Killing call with CID [%.*s]\n", call->sip_data.callid.len,
931 932
 					call->sip_data.callid.s);
932 933
 
... ...
@@ -943,7 +1006,7 @@ void terminate_all_calls(credit_data_t *credit_data) {
943 943
 
944 944
 	cnxcc_lock(hts->lock);
945 945
 
946
-	if (_data.redis) {
946
+	if(_data.redis) {
947 947
 		redis_clean_up_if_last(credit_data);
948 948
 		shm_free(credit_data->str_id);
949 949
 	}
... ...
@@ -975,23 +1038,30 @@ void terminate_all_calls(credit_data_t *credit_data) {
975 975
 /*
976 976
  * WARNING: When calling this function, the proper lock should have been acquired
977 977
  */
978
-static void __free_call(call_t *call) {
978
+static void __free_call(call_t *call)
979
+{
979 980
 	struct str_hash_entry *e = NULL;
980 981
 
981
-	if(call->sip_data.callid.s==NULL)
982
+	if(call->sip_data.callid.s == NULL)
982 983
 		return;
983 984
 
984
-	LM_DBG("Freeing call [%.*s]\n", call->sip_data.callid.len, call->sip_data.callid.s);
985
-	e = str_hash_get(_data.money.call_data_by_cid, call->sip_data.callid.s, call->sip_data.callid.len);
985
+	LM_DBG("Freeing call [%.*s]\n", call->sip_data.callid.len,
986
+			call->sip_data.callid.s);
987
+	e = str_hash_get(_data.money.call_data_by_cid, call->sip_data.callid.s,
988
+			call->sip_data.callid.len);
986 989
 
987
-	if (e == NULL) {
988
-		e = str_hash_get(_data.time.call_data_by_cid, call->sip_data.callid.s, call->sip_data.callid.len);
990
+	if(e == NULL) {
991
+		e = str_hash_get(_data.time.call_data_by_cid, call->sip_data.callid.s,
992
+				call->sip_data.callid.len);
989 993
 
990
-		if (e == NULL) {
991
-			e = str_hash_get(_data.channel.call_data_by_cid, call->sip_data.callid.s, call->sip_data.callid.len);
994
+		if(e == NULL) {
995
+			e = str_hash_get(_data.channel.call_data_by_cid,
996
+					call->sip_data.callid.s, call->sip_data.callid.len);
992 997
 
993