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