Browse code

xhttp: clang format code

(cherry picked from commit d620aab9d2bc16e7785d5be0ddecd016329055de)

Daniel-Constantin Mierla authored on 16/12/2020 07:29:41
Showing 4 changed files
... ...
@@ -18,21 +18,23 @@
18 18
  * along with this program; if not, write to the Free Software
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 20
  */
21
-		       
21
+
22 22
 #ifndef _XHTTP_API_H_
23 23
 #define _XHTTP_API_H_
24 24
 
25 25
 #include "../../core/sr_module.h"
26 26
 
27
-typedef int (*xhttp_reply_f)(sip_msg_t *msg, int code, str *reason,
28
-		str *ctype, str *body);
27
+typedef int (*xhttp_reply_f)(
28
+		sip_msg_t *msg, int code, str *reason, str *ctype, str *body);
29 29
 
30
+/* clang-format off */
30 31
 typedef struct xhttp_api {
31 32
 	xhttp_reply_f reply;
32 33
 } xhttp_api_t;
34
+/* clang-format on */
33 35
 
34
-typedef int (*bind_xhttp_f)(xhttp_api_t* api);
35
-int bind_xhttp(xhttp_api_t* api);
36
+typedef int (*bind_xhttp_f)(xhttp_api_t *api);
37
+int bind_xhttp(xhttp_api_t *api);
36 38
 
37 39
 /**
38 40
  * @brief Load the XHTTP API
... ...
@@ -46,8 +48,7 @@ static inline int xhttp_load_api(xhttp_api_t *api)
46 48
 		LM_ERR("cannot find bind_xhttp\n");
47 49
 		return -1;
48 50
 	}
49
-	if(bindxhttp(api)<0)
50
-	{
51
+	if(bindxhttp(api) < 0) {
51 52
 		LM_ERR("cannot bind xhttp api\n");
52 53
 		return -1;
53 54
 	}
... ...
@@ -48,20 +48,19 @@
48 48
 
49 49
 MODULE_VERSION
50 50
 
51
-static int xhttp_handler(sip_msg_t* msg);
52
-static int w_xhttp_send_reply(sip_msg_t* msg, char* pcode, char* preason,
53
-		char *pctype, char* pbody);
51
+static int xhttp_handler(sip_msg_t *msg);
52
+static int w_xhttp_send_reply(
53
+		sip_msg_t *msg, char *pcode, char *preason, char *pctype, char *pbody);
54 54
 static int mod_init(void);
55 55
 
56
-static int fixup_xhttp_reply(void** param, int param_no);
56
+static int fixup_xhttp_reply(void **param, int param_no);
57 57
 
58
-static int pv_get_huri(struct sip_msg *msg, pv_param_t *param,
59
-		pv_value_t *res);
58
+static int pv_get_huri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
60 59
 
61
-static int xhttp_route_no=DEFAULT_RT;
62
-static char* xhttp_url_match = NULL;
60
+static int xhttp_route_no = DEFAULT_RT;
61
+static char *xhttp_url_match = NULL;
63 62
 static regex_t xhttp_url_match_regexp;
64
-static char* xhttp_url_skip = NULL;
63
+static char *xhttp_url_skip = NULL;
65 64
 static regex_t xhttp_url_skip_regexp;
66 65
 
67 66
 /** SL API structure */
... ...
@@ -69,14 +68,7 @@ sl_api_t slb;
69 68
 
70 69
 static str xhttp_event_callback = STR_NULL;
71 70
 
72
-static cmd_export_t cmds[] = {
73
-	{"xhttp_reply",    (cmd_function)w_xhttp_send_reply,
74
-		4, fixup_xhttp_reply,  0, REQUEST_ROUTE},
75
-	{"bind_xhttp",     (cmd_function)bind_xhttp,
76
-		0, 0, 0, ANY_ROUTE},
77
-	{0, 0, 0, 0, 0}
78
-};
79
-
71
+/* clang-format off */
80 72
 static pv_export_t mod_pvs[] = {
81 73
 	{{"hu", (sizeof("hu")-1)}, /* */
82 74
 		PVT_OTHER, pv_get_huri, 0,
... ...
@@ -85,6 +77,13 @@ static pv_export_t mod_pvs[] = {
85 77
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
86 78
 };
87 79
 
80
+static tr_export_t mod_trans[] = {
81
+	{ {"url", sizeof("url")-1},
82
+		xhttp_tr_parse_url },
83
+
84
+	{ { 0, 0 }, 0 }
85
+};
86
+
88 87
 static param_export_t params[] = {
89 88
 	{"url_match",       PARAM_STRING, &xhttp_url_match},
90 89
 	{"url_skip",        PARAM_STRING, &xhttp_url_skip},
... ...
@@ -92,6 +91,14 @@ static param_export_t params[] = {
92 91
 	{0, 0, 0}
93 92
 };
94 93
 
94
+static cmd_export_t cmds[] = {
95
+	{"xhttp_reply",    (cmd_function)w_xhttp_send_reply,
96
+		4, fixup_xhttp_reply,  0, REQUEST_ROUTE},
97
+	{"bind_xhttp",     (cmd_function)bind_xhttp,
98
+		0, 0, 0, ANY_ROUTE},
99
+	{0, 0, 0, 0, 0}
100
+};
101
+
95 102
 /** module exports */
96 103
 struct module_exports exports= {
97 104
 	"xhttp",         /* module name */
... ...
@@ -105,13 +112,7 @@ struct module_exports exports= {
105 112
 	0,               /* per-child init function */
106 113
 	0                /* module destroy function */
107 114
 };
108
-
109
-static tr_export_t mod_trans[] = {
110
-	{ {"url", sizeof("url")-1},
111
-		xhttp_tr_parse_url },
112
-
113
-	{ { 0, 0 }, 0 }
114
-};
115
+/* clang-format on */
115 116
 
116 117
 /**
117 118
  *
... ...
@@ -122,29 +123,27 @@ static int mod_init(void)
122 123
 	int route_no;
123 124
 	sr_kemi_eng_t *keng = NULL;
124 125
 
125
-	if(xhttp_event_callback.s!=NULL && xhttp_event_callback.len>0) {
126
+	if(xhttp_event_callback.s != NULL && xhttp_event_callback.len > 0) {
126 127
 		keng = sr_kemi_eng_get();
127
-		if(keng==NULL) {
128
+		if(keng == NULL) {
128 129
 			LM_ERR("failed to find kemi engine\n");
129 130
 			return -1;
130 131
 		}
131
-		xhttp_route_no=-1;
132
+		xhttp_route_no = -1;
132 133
 	} else {
133
-		route_no=route_lookup(&event_rt, "xhttp:request");
134
-		if (route_no==-1)
135
-		{
134
+		route_no = route_lookup(&event_rt, "xhttp:request");
135
+		if(route_no == -1) {
136 136
 			LM_ERR("failed to find event_route[xhttp:request]\n");
137 137
 			return -1;
138 138
 		}
139
-		if (event_rt.rlist[route_no]==0)
140
-		{
139
+		if(event_rt.rlist[route_no] == 0) {
141 140
 			LM_WARN("event_route[xhttp:request] is empty\n");
142 141
 		}
143
-		xhttp_route_no=route_no;
142
+		xhttp_route_no = route_no;
144 143
 	}
145
-	
144
+
146 145
 	/* bind the SL API */
147
-	if (sl_load_api(&slb)!=0) {
146
+	if(sl_load_api(&slb) != 0) {
148 147
 		LM_ERR("cannot bind to SL API\n");
149 148
 		return -1;
150 149
 	}
... ...
@@ -154,24 +153,22 @@ static int mod_init(void)
154 153
 	nsh.name = "xhttp";
155 154
 	nsh.destroy = 0;
156 155
 	nsh.on_nonsip_req = xhttp_handler;
157
-	if (register_nonsip_msg_hook(&nsh)<0)
158
-	{
156
+	if(register_nonsip_msg_hook(&nsh) < 0) {
159 157
 		LM_ERR("Failed to register non sip msg hooks\n");
160 158
 		return -1;
161 159
 	}
162 160
 
163
-	if(xhttp_url_match!=NULL)
164
-	{
161
+	if(xhttp_url_match != NULL) {
165 162
 		memset(&xhttp_url_match_regexp, 0, sizeof(regex_t));
166
-		if (regcomp(&xhttp_url_match_regexp, xhttp_url_match, REG_EXTENDED)!=0) {
163
+		if(regcomp(&xhttp_url_match_regexp, xhttp_url_match, REG_EXTENDED)
164
+				!= 0) {
167 165
 			LM_ERR("bad match re %s\n", xhttp_url_match);
168 166
 			return E_BAD_RE;
169 167
 		}
170 168
 	}
171
-	if(xhttp_url_skip!=NULL)
172
-	{
169
+	if(xhttp_url_skip != NULL) {
173 170
 		memset(&xhttp_url_skip_regexp, 0, sizeof(regex_t));
174
-		if (regcomp(&xhttp_url_skip_regexp, xhttp_url_skip, REG_EXTENDED)!=0) {
171
+		if(regcomp(&xhttp_url_skip_regexp, xhttp_url_skip, REG_EXTENDED) != 0) {
175 172
 			LM_ERR("bad skip re %s\n", xhttp_url_skip);
176 173
 			return E_BAD_RE;
177 174
 		}
... ...
@@ -180,30 +177,29 @@ static int mod_init(void)
180 177
 }
181 178
 
182 179
 
183
-/** 
184
- * 
180
+/**
181
+ *
185 182
  */
186
-static int pv_get_huri(struct sip_msg *msg, pv_param_t *param,
187
-		pv_value_t *res)
183
+static int pv_get_huri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
188 184
 {
189
-	if(msg==NULL || res==NULL)
185
+	if(msg == NULL || res == NULL)
190 186
 		return -1;
191 187
 
192 188
 	return pv_get_strval(msg, param, res, &msg->first_line.u.request.uri);
193 189
 }
194 190
 
195 191
 
196
-/** 
197
- * 
192
+/**
193
+ *
198 194
  */
199
-static char* xhttp_to_sip(sip_msg_t* msg, int* new_msg_len)
195
+static char *xhttp_to_sip(sip_msg_t *msg, int *new_msg_len)
200 196
 {
201 197
 	unsigned int len, via_len;
202
-	char* via, *new_msg, *p;
198
+	char *via, *new_msg, *p;
203 199
 	str ip, port;
204 200
 	struct hostport hp;
205 201
 	struct dest_info dst;
206
-	
202
+
207 203
 	ip.s = ip_addr2strz(&msg->rcv.src_ip);
208 204
 	ip.len = strlen(ip.s);
209 205
 	port.s = int2str(msg->rcv.src_port, &port.len);
... ...
@@ -211,32 +207,29 @@ static char* xhttp_to_sip(sip_msg_t* msg, int* new_msg_len)
211 207
 	hp.port = &port;
212 208
 	init_dst_from_rcv(&dst, &msg->rcv);
213 209
 	via = via_builder(&via_len, NULL, &dst, 0, 0, &hp);
214
-	if (via == 0)
215
-	{
210
+	if(via == 0) {
216 211
 		LM_DBG("failed to build via\n");
217 212
 		return 0;
218 213
 	}
219 214
 	len = via_len + msg->len;
220 215
 	p = new_msg = pkg_malloc(len + 1);
221
-	if (new_msg == 0)
222
-	{
216
+	if(new_msg == 0) {
223 217
 		PKG_MEM_ERROR_FMT(" (%d bytes)\n", len);
224 218
 		pkg_free(via);
225 219
 		return 0;
226 220
 	}
227 221
 
228 222
 	/* new message:
229
-	 * <orig first line> 
223
+	 * <orig first line>
230 224
 	 * Via: <faked via>
231 225
 	 * <orig http message w/o the first line>
232 226
 	 */
233
-	memcpy(p, msg->first_line.u.request.method.s, 
234
-		   msg->first_line.len);
227
+	memcpy(p, msg->first_line.u.request.method.s, msg->first_line.len);
235 228
 	p += msg->first_line.len;
236 229
 	memcpy(p, via, via_len);
237 230
 	p += via_len;
238
-	memcpy(p,  SIP_MSG_START(msg) + msg->first_line.len, 
239
-		   msg->len - msg->first_line.len);
231
+	memcpy(p, SIP_MSG_START(msg) + msg->first_line.len,
232
+			msg->len - msg->first_line.len);
240 233
 	new_msg[len] = 0;
241 234
 	pkg_free(via);
242 235
 	*new_msg_len = len;
... ...
@@ -244,11 +237,11 @@ static char* xhttp_to_sip(sip_msg_t* msg, int* new_msg_len)
244 237
 }
245 238
 
246 239
 
247
-/** 
248
- * 
240
+/**
241
+ *
249 242
  */
250
-static int xhttp_process_request(sip_msg_t* orig_msg, 
251
-							  char* new_buf, unsigned int new_len)
243
+static int xhttp_process_request(
244
+		sip_msg_t *orig_msg, char *new_buf, unsigned int new_len)
252 245
 {
253 246
 	int ret;
254 247
 	int backup_rt;
... ...
@@ -257,10 +250,9 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
257 250
 	sr_kemi_eng_t *keng = NULL;
258 251
 	str evrtname = str_init("xhttp:request");
259 252
 
260
-	ret=0;
253
+	ret = 0;
261 254
 	backup_rt = get_route_type();
262
-	if (new_buf && new_len)
263
-	{
255
+	if(new_buf && new_len) {
264 256
 		memset(&tmp_msg, 0, sizeof(sip_msg_t));
265 257
 		tmp_msg.buf = new_buf;
266 258
 		tmp_msg.len = new_len;
... ...
@@ -268,8 +260,7 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
268 260
 		tmp_msg.id = orig_msg->id;
269 261
 		tmp_msg.set_global_address = orig_msg->set_global_address;
270 262
 		tmp_msg.set_global_port = orig_msg->set_global_port;
271
-		if (parse_msg(new_buf, new_len, &tmp_msg) != 0)
272
-		{
263
+		if(parse_msg(new_buf, new_len, &tmp_msg) != 0) {
273 264
 			LM_ERR("parse_msg failed\n");
274 265
 			goto error;
275 266
 		}
... ...
@@ -277,33 +268,31 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
277 268
 	} else {
278 269
 		msg = orig_msg;
279 270
 	}
280
-	
281
-	if ((msg->first_line.type != SIP_REQUEST) || (msg->via1 == 0) ||
282
-		(msg->via1->error != PARSE_OK))
283
-	{
271
+
272
+	if((msg->first_line.type != SIP_REQUEST) || (msg->via1 == 0)
273
+			|| (msg->via1->error != PARSE_OK)) {
284 274
 		LM_CRIT("strange message: %.*s\n", msg->len, msg->buf);
285 275
 		goto error;
286 276
 	}
287 277
 
288 278
 	set_route_type(EVENT_ROUTE);
289
-	if (exec_pre_script_cb(msg, REQUEST_CB_TYPE) == 0)
290
-	{
279
+	if(exec_pre_script_cb(msg, REQUEST_CB_TYPE) == 0) {
291 280
 		goto done;
292 281
 	}
293 282
 
294 283
 	init_run_actions_ctx(&ra_ctx);
295
-	if(xhttp_route_no>=0) {
296
-		if (run_actions(&ra_ctx, event_rt.rlist[xhttp_route_no], msg) < 0)
297
-		{
298
-			ret=-1;
284
+	if(xhttp_route_no >= 0) {
285
+		if(run_actions(&ra_ctx, event_rt.rlist[xhttp_route_no], msg) < 0) {
286
+			ret = -1;
299 287
 			LM_DBG("error while trying script\n");
300 288
 			goto done;
301 289
 		}
302 290
 	} else {
303 291
 		keng = sr_kemi_eng_get();
304
-		if(keng!=NULL) {
305
-			if(sr_kemi_route(keng, msg, EVENT_ROUTE,
306
-						&xhttp_event_callback, &evrtname)<0) {
292
+		if(keng != NULL) {
293
+			if(sr_kemi_route(
294
+					   keng, msg, EVENT_ROUTE, &xhttp_event_callback, &evrtname)
295
+					< 0) {
307 296
 				LM_ERR("error running event route kemi callback\n");
308 297
 			}
309 298
 		} else {
... ...
@@ -313,8 +302,7 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
313 302
 
314 303
 done:
315 304
 	exec_post_script_cb(msg, REQUEST_CB_TYPE);
316
-	if (msg != orig_msg)
317
-	{
305
+	if(msg != orig_msg) {
318 306
 		free_sip_msg(msg);
319 307
 	}
320 308
 	set_route_type(backup_rt);
... ...
@@ -325,72 +313,68 @@ error:
325 313
 }
326 314
 
327 315
 
328
-/** 
329
- * 
316
+/**
317
+ *
330 318
  */
331
-static int xhttp_handler(sip_msg_t* msg)
319
+static int xhttp_handler(sip_msg_t *msg)
332 320
 {
333 321
 	int ret;
334
-	char* fake_msg;
322
+	char *fake_msg;
335 323
 	int fake_msg_len;
336 324
 	regmatch_t pmatch;
337 325
 	char c;
338 326
 
339
-	ret=NONSIP_MSG_DROP;
327
+	ret = NONSIP_MSG_DROP;
340 328
 
341
-	if(!IS_HTTP(msg))
342
-	{
329
+	if(!IS_HTTP(msg)) {
343 330
 		/* oly http msg type */
344 331
 		return NONSIP_MSG_PASS;
345 332
 	}
346 333
 
347
-	if(xhttp_url_skip!=NULL || xhttp_url_match!=NULL)
348
-	{
334
+	if(xhttp_url_skip != NULL || xhttp_url_match != NULL) {
349 335
 		c = msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len];
350
-		msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len]
351
-			= '\0';
352
-		if (xhttp_url_skip!=NULL &&
353
-			regexec(&xhttp_url_skip_regexp, msg->first_line.u.request.uri.s,
354
-					1, &pmatch, 0)==0)
355
-		{
336
+		msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] =
337
+				'\0';
338
+		if(xhttp_url_skip != NULL
339
+				&& regexec(&xhttp_url_skip_regexp,
340
+						   msg->first_line.u.request.uri.s, 1, &pmatch, 0)
341
+						   == 0) {
356 342
 			LM_DBG("URL matched skip re\n");
357
-			msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len]
358
-				= c;
343
+			msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] =
344
+					c;
359 345
 			return NONSIP_MSG_PASS;
360 346
 		}
361
-		if (xhttp_url_match!=NULL &&
362
-			regexec(&xhttp_url_match_regexp, msg->first_line.u.request.uri.s,
363
-					1, &pmatch, 0)!=0)
364
-		{
347
+		if(xhttp_url_match != NULL
348
+				&& regexec(&xhttp_url_match_regexp,
349
+						   msg->first_line.u.request.uri.s, 1, &pmatch, 0)
350
+						   != 0) {
365 351
 			LM_DBG("URL not matched\n");
366
-			msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len]
367
-				= c;
352
+			msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] =
353
+					c;
368 354
 			return NONSIP_MSG_PASS;
369 355
 		}
370 356
 		msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] = c;
371 357
 	}
372 358
 
373
-	if (msg->via1 == 0)
374
-	{
359
+	if(msg->via1 == 0) {
375 360
 		fake_msg = xhttp_to_sip(msg, &fake_msg_len);
376
-		if (fake_msg == 0)
377
-		{
361
+		if(fake_msg == 0) {
378 362
 			LM_ERR("out of memory\n");
379
-			ret=NONSIP_MSG_ERROR;
363
+			ret = NONSIP_MSG_ERROR;
380 364
 		} else {
381
-			DBG("new fake msg created (%d bytes):\n<%.*s>\n",
382
-					fake_msg_len, fake_msg_len, fake_msg);
383
-			if (xhttp_process_request(msg, fake_msg, fake_msg_len)<0) {
384
-				ret=NONSIP_MSG_ERROR;
365
+			DBG("new fake msg created (%d bytes):\n<%.*s>\n", fake_msg_len,
366
+					fake_msg_len, fake_msg);
367
+			if(xhttp_process_request(msg, fake_msg, fake_msg_len) < 0) {
368
+				ret = NONSIP_MSG_ERROR;
385 369
 			}
386 370
 			pkg_free(fake_msg);
387 371
 		}
388 372
 		return ret;
389 373
 	} else {
390
-		LM_DBG("http msg unchanged (%d bytes):\n<%.*s>\n",
391
-				msg->len, msg->len, msg->buf);
392
-		if (xhttp_process_request(msg, 0, 0)<0)
393
-			ret=NONSIP_MSG_ERROR;
374
+		LM_DBG("http msg unchanged (%d bytes):\n<%.*s>\n", msg->len, msg->len,
375
+				msg->buf);
376
+		if(xhttp_process_request(msg, 0, 0) < 0)
377
+			ret = NONSIP_MSG_ERROR;
394 378
 		return ret;
395 379
 	}
396 380
 }
... ...
@@ -399,28 +383,25 @@ static int xhttp_handler(sip_msg_t* msg)
399 383
 /**
400 384
  *
401 385
  */
402
-static int xhttp_send_reply(sip_msg_t *msg, int code, str *reason,
403
-		str *ctype, str *body)
386
+static int xhttp_send_reply(
387
+		sip_msg_t *msg, int code, str *reason, str *ctype, str *body)
404 388
 {
405 389
 	str tbuf;
406 390
 
407
-	if(ctype!=NULL && ctype->len>0)
408
-	{
391
+	if(ctype != NULL && ctype->len > 0) {
409 392
 		/* add content-type */
410
-		tbuf.len=sizeof("Content-Type: ") - 1 + ctype->len + CRLF_LEN;
411
-		tbuf.s=pkg_malloc(sizeof(char)*(tbuf.len));
393
+		tbuf.len = sizeof("Content-Type: ") - 1 + ctype->len + CRLF_LEN;
394
+		tbuf.s = pkg_malloc(sizeof(char) * (tbuf.len));
412 395
 
413
-		if (tbuf.s==0)
414
-		{
396
+		if(tbuf.s == 0) {
415 397
 			PKG_MEM_ERROR;
416 398
 			return -1;
417 399
 		}
418 400
 		memcpy(tbuf.s, "Content-Type: ", sizeof("Content-Type: ") - 1);
419
-		memcpy(tbuf.s+sizeof("Content-Type: ") - 1, ctype->s, ctype->len);
420
-		memcpy(tbuf.s+sizeof("Content-Type: ") - 1 + ctype->len,
421
-				CRLF, CRLF_LEN);
422
-		if (add_lump_rpl(msg, tbuf.s, tbuf.len, LUMP_RPL_HDR) == 0)
423
-		{
401
+		memcpy(tbuf.s + sizeof("Content-Type: ") - 1, ctype->s, ctype->len);
402
+		memcpy(tbuf.s + sizeof("Content-Type: ") - 1 + ctype->len, CRLF,
403
+				CRLF_LEN);
404
+		if(add_lump_rpl(msg, tbuf.s, tbuf.len, LUMP_RPL_HDR) == 0) {
424 405
 			LM_ERR("failed to insert content-type lump\n");
425 406
 			pkg_free(tbuf.s);
426 407
 			return -1;
... ...
@@ -429,18 +410,15 @@ static int xhttp_send_reply(sip_msg_t *msg, int code, str *reason,
429 410
 		LM_DBG("response with content-type: %.*s\n", ctype->len, ctype->s);
430 411
 	}
431 412
 
432
-	if(body!=NULL && body->len>0)
433
-	{
434
-		if (add_lump_rpl(msg, body->s, body->len, LUMP_RPL_BODY) == 0)
435
-		{
413
+	if(body != NULL && body->len > 0) {
414
+		if(add_lump_rpl(msg, body->s, body->len, LUMP_RPL_BODY) == 0) {
436 415
 			LM_ERR("Error while adding reply lump\n");
437 416
 			return -1;
438 417
 		}
439 418
 		LM_DBG("response with body: %.*s\n", body->len, body->s);
440 419
 	}
441 420
 	LM_DBG("sending out response: %d %.*s\n", code, reason->len, reason->s);
442
-	if (slb.sreply(msg, code, reason) < 0)
443
-	{
421
+	if(slb.sreply(msg, code, reason) < 0) {
444 422
 		LM_ERR("Error while sending reply\n");
445 423
 		return -1;
446 424
 	}
... ...
@@ -450,83 +428,74 @@ static int xhttp_send_reply(sip_msg_t *msg, int code, str *reason,
450 428
 /**
451 429
  *
452 430
  */
453
-static int w_xhttp_send_reply(sip_msg_t* msg, char* pcode, char* preason,
454
-		char *pctype, char* pbody)
431
+static int w_xhttp_send_reply(
432
+		sip_msg_t *msg, char *pcode, char *preason, char *pctype, char *pbody)
455 433
 {
456 434
 	str body = {0, 0};
457 435
 	str reason = {"OK", 2};
458 436
 	str ctype = {"text/plain", 10};
459 437
 	int code = 200;
460 438
 
461
-	if(pcode==0 || preason==0 || pctype==0 || pbody==0)
462
-	{
439
+	if(pcode == 0 || preason == 0 || pctype == 0 || pbody == 0) {
463 440
 		LM_ERR("invalid parameters\n");
464 441
 		return -1;
465 442
 	}
466 443
 
467
-	if(fixup_get_ivalue(msg, (gparam_p)pcode, &code)!=0)
468
-	{
444
+	if(fixup_get_ivalue(msg, (gparam_p)pcode, &code) != 0) {
469 445
 		LM_ERR("no reply code value\n");
470 446
 		return -1;
471 447
 	}
472
-	if(code<100 || code>700)
473
-	{
448
+	if(code < 100 || code > 700) {
474 449
 		LM_ERR("invalid code parameter\n");
475 450
 		return -1;
476 451
 	}
477 452
 
478
-	if(fixup_get_svalue(msg, (gparam_p)preason, &reason)!=0)
479
-	{
453
+	if(fixup_get_svalue(msg, (gparam_p)preason, &reason) != 0) {
480 454
 		LM_ERR("unable to get reason\n");
481 455
 		return -1;
482 456
 	}
483
-	if(reason.s==NULL || reason.len == 0)
484
-	{
457
+	if(reason.s == NULL || reason.len == 0) {
485 458
 		LM_ERR("invalid reason parameter\n");
486 459
 		return -1;
487 460
 	}
488 461
 
489
-	if(fixup_get_svalue(msg, (gparam_p)pctype, &ctype)!=0)
490
-	{
462
+	if(fixup_get_svalue(msg, (gparam_p)pctype, &ctype) != 0) {
491 463
 		LM_ERR("unable to get content type\n");
492 464
 		return -1;
493 465
 	}
494
-	if(ctype.s==NULL)
495
-	{
466
+	if(ctype.s == NULL) {
496 467
 		LM_ERR("invalid content-type parameter\n");
497 468
 		return -1;
498 469
 	}
499 470
 
500
-	if(fixup_get_svalue(msg, (gparam_p)pbody, &body)!=0)
501
-	{
471
+	if(fixup_get_svalue(msg, (gparam_p)pbody, &body) != 0) {
502 472
 		LM_ERR("unable to get body\n");
503 473
 		return -1;
504 474
 	}
505
-	if(body.s==NULL)
506
-	{
475
+	if(body.s == NULL) {
507 476
 		LM_ERR("invalid body parameter\n");
508 477
 		return -1;
509 478
 	}
510 479
 
511
-	if(xhttp_send_reply(msg, code, &reason, &ctype, &body)<0)
480
+	if(xhttp_send_reply(msg, code, &reason, &ctype, &body) < 0)
512 481
 		return -1;
513 482
 	return 1;
514 483
 }
515 484
 
516 485
 
517
-/** 
518
- * 
486
+/**
487
+ *
519 488
  */
520
-static int fixup_xhttp_reply(void** param, int param_no)
489
+static int fixup_xhttp_reply(void **param, int param_no)
521 490
 {
522
-	if (param_no == 1) {
523
-	    return fixup_igp_null(param, 1);
524
-	} else if (param_no == 2) {
525
-	    return fixup_spve_null(param, 1);
526
-	} else if (param_no == 3) {
527
-	    return fixup_spve_null(param, 1);
528
-	} else if (param_no == 4) {
529
-	    return fixup_spve_null(param, 1);
491
+	if(param_no == 1) {
492
+		return fixup_igp_null(param, 1);
493
+	} else if(param_no == 2) {
494
+		return fixup_spve_null(param, 1);
495
+	} else if(param_no == 3) {
496
+		return fixup_spve_null(param, 1);
497
+	} else if(param_no == 4) {
498
+		return fixup_spve_null(param, 1);
530 499
 	}
531 500
 	return 0;
532 501
 }
... ...
@@ -534,9 +503,9 @@ static int fixup_xhttp_reply(void** param, int param_no)
534 503
 /**
535 504
  *
536 505
  */
537
-int bind_xhttp(xhttp_api_t* api)
506
+int bind_xhttp(xhttp_api_t *api)
538 507
 {
539
-	if (!api) {
508
+	if(!api) {
540 509
 		ERR("Invalid parameter value\n");
541 510
 		return -1;
542 511
 	}
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2013 Crocodile RCS Ltd
3 3
  *
4 4
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
... ...
@@ -23,39 +23,48 @@
23 23
 #include "../../core/trim.h"
24 24
 #include "xhttp_trans.h"
25 25
 
26
-enum _tr_xhttp_type { TR_XHTTP_NONE = 0, TR_XHTTPURL, TR_XHTTPURLQUERYSTRING };
27
-enum _tr_xhttpurl_subtype { TR_XHTTPURL_NONE = 0, TR_XHTTPURL_PATH,
28
-	TR_XHTTPURL_QUERYSTRING};
29
-enum _tr_xhttpquerystring_subtype { TR_XHTTPUTLQUERYSTRING_NONE = 0,
30
-	TR_XHTTPURLQUERYSTRING_VALUE};
26
+enum _tr_xhttp_type
27
+{
28
+	TR_XHTTP_NONE = 0,
29
+	TR_XHTTPURL,
30
+	TR_XHTTPURLQUERYSTRING
31
+};
32
+enum _tr_xhttpurl_subtype
33
+{
34
+	TR_XHTTPURL_NONE = 0,
35
+	TR_XHTTPURL_PATH,
36
+	TR_XHTTPURL_QUERYSTRING
37
+};
38
+enum _tr_xhttpquerystring_subtype
39
+{
40
+	TR_XHTTPUTLQUERYSTRING_NONE = 0,
41
+	TR_XHTTPURLQUERYSTRING_VALUE
42
+};
31 43
 
32 44
 static str _httpurl_str = {0, 0};
33 45
 static int _httpurl_querystring_pos = 0;
34 46
 
35
-int xhttp_tr_eval_xhttpurl(struct sip_msg *msg, tr_param_t *tp, int subtype,
36
-		pv_value_t *val)
47
+int xhttp_tr_eval_xhttpurl(
48
+		struct sip_msg *msg, tr_param_t *tp, int subtype, pv_value_t *val)
37 49
 {
38 50
 	int pos = 0;
39 51
 
40
-	if (val == NULL || val->flags & PV_VAL_NULL)
52
+	if(val == NULL || val->flags & PV_VAL_NULL)
41 53
 		return -1;
42 54
 
43
-	if (!(val->flags & PV_VAL_STR))
44
-	{
55
+	if(!(val->flags & PV_VAL_STR)) {
45 56
 		val->rs.s = int2str(val->ri, &val->rs.len);
46 57
 		val->flags = PV_VAL_STR;
47 58
 	}
48 59
 
49
-	if (_httpurl_str.len == 0 || _httpurl_str.len != val->rs.len
50
-		|| strncmp(_httpurl_str.s, val->rs.s, val->rs.len) != 0)
51
-	{
52
-		if (val->rs.len > _httpurl_str.len)
53
-		{
54
-			if (_httpurl_str.s) pkg_free(_httpurl_str.s);
55
-			_httpurl_str.s = (char *) pkg_malloc(
56
-					(val->rs.len + 1) * sizeof(char));
57
-			if (_httpurl_str.s == NULL)
58
-			{
60
+	if(_httpurl_str.len == 0 || _httpurl_str.len != val->rs.len
61
+			|| strncmp(_httpurl_str.s, val->rs.s, val->rs.len) != 0) {
62
+		if(val->rs.len > _httpurl_str.len) {
63
+			if(_httpurl_str.s)
64
+				pkg_free(_httpurl_str.s);
65
+			_httpurl_str.s =
66
+					(char *)pkg_malloc((val->rs.len + 1) * sizeof(char));
67
+			if(_httpurl_str.s == NULL) {
59 68
 				PKG_MEM_ERROR;
60 69
 				memset(&_httpurl_str.s, 0, sizeof(str));
61 70
 				return -1;
... ...
@@ -64,32 +73,32 @@ int xhttp_tr_eval_xhttpurl(struct sip_msg *msg, tr_param_t *tp, int subtype,
64 73
 		_httpurl_str.len = val->rs.len;
65 74
 		memcpy(_httpurl_str.s, val->rs.s, val->rs.len);
66 75
 
67
-		while (pos < val->rs.len && val->rs.s[pos] != '?') pos++;
76
+		while(pos < val->rs.len && val->rs.s[pos] != '?')
77
+			pos++;
68 78
 		_httpurl_querystring_pos = (pos >= val->rs.len) ? 0 : pos + 1;
69 79
 	}
70 80
 
71
-	switch (subtype)
72
-	{
73
-	case TR_XHTTPURL_PATH:
74
-		val->rs.len = (_httpurl_querystring_pos == 0)
75
-				? val->rs.len : _httpurl_querystring_pos - 1;
76
-		break;
77
-
78
-	case TR_XHTTPURL_QUERYSTRING:
79
-		if (_httpurl_querystring_pos == 0)
80
-		{
81
-			val->rs.s[0] = '\0';
82
-			val->rs.len = 0;
81
+	switch(subtype) {
82
+		case TR_XHTTPURL_PATH:
83
+			val->rs.len = (_httpurl_querystring_pos == 0)
84
+								  ? val->rs.len
85
+								  : _httpurl_querystring_pos - 1;
83 86
 			break;
84
-		}
85 87
 
86
-		val->rs.s = &val->rs.s[_httpurl_querystring_pos];
87
-		val->rs.len = val->rs.len - _httpurl_querystring_pos;
88
-		break;
88
+		case TR_XHTTPURL_QUERYSTRING:
89
+			if(_httpurl_querystring_pos == 0) {
90
+				val->rs.s[0] = '\0';
91
+				val->rs.len = 0;
92
+				break;
93
+			}
94
+
95
+			val->rs.s = &val->rs.s[_httpurl_querystring_pos];
96
+			val->rs.len = val->rs.len - _httpurl_querystring_pos;
97
+			break;
89 98
 
90
-	default:
91
-		LM_ERR("unknown subtype %d\n", subtype);
92
-		return -1;
99
+		default:
100
+			LM_ERR("unknown subtype %d\n", subtype);
101
+			return -1;
93 102
 	}
94 103
 
95 104
 	return 0;
... ...
@@ -100,7 +109,7 @@ char *xhttp_tr_parse_url(str *in, trans_t *t)
100 109
 	char *p;
101 110
 	str name;
102 111
 
103
-	if (in == NULL || in->s == NULL || t == NULL)
112
+	if(in == NULL || in->s == NULL || t == NULL)
104 113
 		return NULL;
105 114
 
106 115
 	p = in->s;
... ...
@@ -108,33 +117,28 @@ char *xhttp_tr_parse_url(str *in, trans_t *t)
108 117
 	t->type = TR_XHTTPURL;
109 118
 	t->trf = xhttp_tr_eval_xhttpurl;
110 119
 
111
-        /* find next token */
112
-        while (is_in_str(p, in) && *p != TR_PARAM_MARKER && *p != TR_RBRACKET)
113
-	{
120
+	/* find next token */
121
+	while(is_in_str(p, in) && *p != TR_PARAM_MARKER && *p != TR_RBRACKET) {
114 122
 		p++;
115 123
 	}
116 124
 
117
-        if (*p == '\0')
118
-        {
119
-                LM_ERR("invalid transformation: %.*s\n", in->len, in->s);
120
-                goto error;
121
-        }
122
-        name.len = p - name.s;
123
-        trim(&name);
125
+	if(*p == '\0') {
126
+		LM_ERR("invalid transformation: %.*s\n", in->len, in->s);
127
+		goto error;
128
+	}
129
+	name.len = p - name.s;
130
+	trim(&name);
124 131
 
125
-	if (name.len == 4 && strncasecmp(name.s, "path", 4) == 0)
126
-	{
132
+	if(name.len == 4 && strncasecmp(name.s, "path", 4) == 0) {
127 133
 		t->subtype = TR_XHTTPURL_PATH;
128 134
 		goto done;
129
-	}
130
-	else if (name.len == 11 && strncasecmp(name.s, "querystring", 11) == 0)
131
-	{
135
+	} else if(name.len == 11 && strncasecmp(name.s, "querystring", 11) == 0) {
132 136
 		t->subtype = TR_XHTTPURL_QUERYSTRING;
133 137
 		goto done;
134 138
 	}
135 139
 
136
-	LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s,
137
-			name.len, name.s, name.len);
140
+	LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s, name.len,
141
+			name.s, name.len);
138 142
 error:
139 143
 	return NULL;
140 144
 
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2013 Crocodile RCS Ltd
3 3
  *
4 4
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20