Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,3097 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
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
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- *
20
- *
21
- *
22
- */
23
-/** Via special params:
24
- * requests:
25
- * - if the address in via is different from the src_ip or an existing
26
- *   received=something is found, received=src_ip is added (and any preexisting
27
- *   received is deleted). received is added as the first via parameter if no
28
- *   receive is previously present or over the old receive.
29
- * - if the original via contains rport / rport=something or msg->msg_flags
30
- *   FL_FORCE_RPORT is set (e.g. script force_rport() cmd) rport=src_port
31
- *   is added (over previous rport / as first via param or after received
32
- *   if no received was present and received is added too)
33
- * local replies:
34
- *    (see also sl_send_reply)
35
- *  - rport and received are added in mostly the same way as for requests, but
36
- *    in the reverse order (first rport and then received). See also
37
- *    limitations.
38
- *  - if reply_to_via is set (default off) the local reply will be sent to
39
- *    the address in via (received is ignored since it was not set by us). The
40
- *    destination port is either the message source port if via contains rport
41
- *    or the FL_FORCE_RPORT flag is set or the port from the via. If either
42
- *    port or rport are present a normal dns lookup (instead of a srv lookup)
43
- *    is performed on the address. If no port is present and a srv lookup is
44
- *    performed the port is taken from the srv lookup. If the srv lookup failed
45
- *    or it was not performed, the port is set to the default sip port (5060).
46
- *  - if reply_to_via is off (default) the local reply is sent to the message
47
- *    source ip address. The destination port is set to the source port if
48
- *    rport is present or FL_FORCE_RPORT flag is set, to the via port or to
49
- *    the default sip port (5060) if neither rport or via port are present.
50
- * "normal" replies:
51
- *  - if received is present the message is sent to the received address else
52
- *    if no port is present (neither a normal via port or rport) a dns srv
53
- *    lookup is performed on the host part and the reply is sent to the
54
- *    resulting ip. If a port is present or the host part is an ip address
55
- *    the dns lookup will be a "normal" one (A or AAAA).
56
- *  - if rport is present, it's value will be used as the destination port
57
- *   (and this will also disable srv lookups)
58
- *  - if no port is present the destination port will be taken from the srv
59
- *    lookup. If the srv lookup fails or is not performed (e.g. ip address
60
- *    in host) the destination port will be set to the default sip port (5060).
61
- *
62
- * Known limitations:
63
- * - when locally replying to a message, rport and received will be appended to
64
- *   the via header parameters (for forwarded requests they are inserted at the
65
- *   beginning).
66
- * - a locally generated reply might get two received via parameters if a
67
- *   received is already present in the original message (this should not
68
- *   happen though, but ...)
69
- *
70
- *--andrei
71
-*/
72
-
73
-/*!
74
- * \file
75
- * \brief Kamailio core :: Message translations
76
- * \ingroup core
77
- * Module: \ref core
78
- */
79
-
80
-#include <sys/types.h>
81
-#include <sys/socket.h>
82
-#include <netdb.h>
83
-#include <string.h>
84
-#include <stdio.h>
85
-#include <stdlib.h>
86
-
87
-#include "comp_defs.h"
88
-#include "msg_translator.h"
89
-#include "globals.h"
90
-#include "error.h"
91
-#include "mem/mem.h"
92
-#include "dprint.h"
93
-#include "config.h"
94
-#include "md5utils.h"
95
-#include "data_lump.h"
96
-#include "data_lump_rpl.h"
97
-#include "ip_addr.h"
98
-#include "resolve.h"
99
-#include "ut.h"
100
-#include "pt.h"
101
-#include "cfg/cfg.h"
102
-#include "parser/parse_to.h"
103
-#include "parser/parse_param.h"
104
-#include "forward.h"
105
-#include "str_list.h"
106
-#include "rand/kam_rand.h"
107
-
108
-#define append_str_trans(_dest,_src,_len,_msg) \
109
-	append_str( (_dest), (_src), (_len) );
110
-
111
-extern char version[];
112
-extern int version_len;
113
-
114
-
115
-
116
-/** per process fixup function for global_req_flags.
117
-  * It should be called from the configuration framework.
118
-  */
119
-void fix_global_req_flags(str* gname, str* name)
120
-{
121
-	global_req_flags=0;
122
-	switch(cfg_get(core, core_cfg, udp_mtu_try_proto)){
123
-		case PROTO_NONE:
124
-		case PROTO_UDP:
125
-			/* do nothing */
126
-			break;
127
-		case PROTO_TCP:
128
-			global_req_flags|=FL_MTU_TCP_FB;
129
-			break;
130
-		case PROTO_TLS:
131
-			global_req_flags|=FL_MTU_TLS_FB;
132
-			break;
133
-		case PROTO_SCTP:
134
-			global_req_flags|=FL_MTU_SCTP_FB;
135
-			break;
136
-	}
137
-	if (cfg_get(core, core_cfg, force_rport))
138
-		global_req_flags|=FL_FORCE_RPORT;
139
-}
140
-
141
-
142
-
143
-/* checks if ip is in host(name) and ?host(ip)=name?
144
- * ip must be in network byte order!
145
- *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
146
- * return 0 if equal */
147
-static int check_via_address(struct ip_addr* ip, str *name,
148
-				unsigned short port, int resolver)
149
-{
150
-	struct hostent* he;
151
-	int i;
152
-	char* s;
153
-	int len;
154
-	char lproto;
155
-
156
-	/* maybe we are lucky and name it's an ip */
157
-	s=ip_addr2a(ip);
158
-	if (s){
159
-		LM_DBG("(%s, %.*s, %d)\n", s, name->len, name->s, resolver);
160
-
161
-		len=strlen(s);
162
-
163
-		/* check if name->s is an ipv6 address or an ipv6 address ref. */
164
-		if ((ip->af==AF_INET6) &&
165
-				(	((len==name->len)&&(strncasecmp(name->s, s, name->len)==0))
166
-					||
167
-					((len==(name->len-2))&&(name->s[0]=='[')&&
168
-						(name->s[name->len-1]==']')&&
169
-						(strncasecmp(name->s+1, s, len)==0))
170
-				)
171
-		   )
172
-			return 0;
173
-		else
174
-
175
-			if (strncmp(name->s, s, name->len)==0)
176
-				return 0;
177
-	}else{
178
-		LM_CRIT("could not convert ip address\n");
179
-		return -1;
180
-	}
181
-
182
-	if (port==0) port=SIP_PORT;
183
-	if (resolver&DO_DNS){
184
-		LM_DBG("doing dns lookup\n");
185
-		/* try all names ips */
186
-		lproto = PROTO_NONE;
187
-		he=sip_resolvehost(name, &port, &lproto); /* don't use naptr */
188
-		if (he && ip->af==he->h_addrtype){
189
-			for(i=0;he && he->h_addr_list[i];i++){
190
-				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
191
-					return 0;
192
-			}
193
-		}
194
-	}
195
-	if (resolver&DO_REV_DNS){
196
-		LM_DBG("doing rev. dns lookup\n");
197
-		/* try reverse dns */
198
-		he=rev_resolvehost(ip);
199
-		if (he && (strncmp(he->h_name, name->s, name->len)==0))
200
-			return 0;
201
-		for (i=0; he && he->h_aliases[i];i++){
202
-			if (strncmp(he->h_aliases[i],name->s, name->len)==0)
203
-				return 0;
204
-		}
205
-	}
206
-	return -1;
207
-}
208
-
209
-
210
-/* check if IP address in Via != source IP address of signaling,
211
- * or the sender requires adding rport or received values */
212
-int received_test( struct sip_msg *msg )
213
-{
214
-	int rcvd;
215
-
216
-	rcvd=msg->via1->received || msg->via1->rport
217
-			|| check_via_address(&msg->rcv.src_ip, &msg->via1->host,
218
-							msg->via1->port, received_dns);
219
-	return rcvd;
220
-}
221
-
222
-/* check if IP address in Via != source IP address of signaling */
223
-int received_via_test( struct sip_msg *msg )
224
-{
225
-	int rcvd;
226
-
227
-	rcvd = (check_via_address(&msg->rcv.src_ip, &msg->via1->host,
228
-							msg->via1->port, received_dns)!=0);
229
-	return rcvd;
230
-}
231
-
232
-static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
233
-{
234
-	static char buf[MAX_WARNING_LEN];
235
-	str *foo;
236
-	int print_len, l;
237
-	int clen;
238
-	char* t;
239
-
240
-#define str_print(string, string_len) \
241
-		do{ \
242
-			l=(string_len); \
243
-			if ((clen+l)>MAX_WARNING_LEN) \
244
-				goto error_overflow; \
245
-			memcpy(buf+clen, (string), l); \
246
-			clen+=l; \
247
-		}while(0)
248
-
249
-#define str_lenpair_print(string, string_len, string2, string2_len) \
250
-		do{ \
251
-			str_print(string, string_len); \
252
-			str_print(string2, string2_len);\
253
-		}while(0)
254
-
255
-#define str_pair_print( string, string2, string2_len) \
256
-		str_lenpair_print((string), strlen((string)), (string2), (string2_len))
257
-
258
-#define str_int_print(string, intval)\
259
-		do{\
260
-			t=int2str((intval), &print_len); \
261
-			str_pair_print(string, t, print_len);\
262
-		} while(0)
263
-
264
-#define str_su_print(sockaddr)\
265
-		do{\
266
-			t=su2a(&sockaddr, sizeof(sockaddr)); \
267
-			print_len=strlen(t); \
268
-			str_print(t, print_len); \
269
-		} while(0)
270
-
271
-#define str_ipaddr_print(string, ipaddr_val)\
272
-		do{\
273
-			t=ip_addr2a((ipaddr_val)); \
274
-			print_len=strlen(t); \
275
-			str_pair_print(string, t, print_len);\
276
-		} while(0)
277
-
278
-	clen=0;
279
-	str_print(WARNING, WARNING_LEN);
280
-	str_su_print(msg->rcv.bind_address->su);
281
-	str_print(WARNING_PHRASE, WARNING_PHRASE_LEN);
282
-
283
-	/*adding out_uri*/
284
-	if (msg->new_uri.s)
285
-		foo=&(msg->new_uri);
286
-	else
287
-		foo=&(msg->first_line.u.request.uri);
288
-	/* pid= */
289
-	str_int_print(" pid=", my_pid());
290
-	/* req_src_ip= */
291
-	str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
292
-	str_int_print(" req_src_port=", msg->rcv.src_port);
293
-	str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
294
-								msg->first_line.u.request.uri.len);
295
-	str_pair_print(" out_uri=", foo->s, foo->len);
296
-	str_pair_print(" via_cnt",
297
-					(msg->parsed_flag & HDR_EOH_F)==HDR_EOH_F ? "=" : ">", 1);
298
-	str_int_print("=", via_cnt);
299
-	if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; }
300
-	else goto error_overflow;
301
-
302
-
303
-	*returned_len=clen;
304
-	return buf;
305
-error_overflow:
306
-	LM_NOTICE("buffer size exceeded (probably too long URI)\n");
307
-	*returned_len=0;
308
-	return 0;
309
-}
310
-
311
-
312
-
313
-
314
-char* received_builder(struct sip_msg *msg, unsigned int *received_len)
315
-{
316
-	char *buf;
317
-	int  len;
318
-	struct ip_addr *source_ip;
319
-	char *tmp;
320
-	int  tmp_len;
321
-
322
-	source_ip=&msg->rcv.src_ip;
323
-
324
-	buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE);
325
-	if (buf==0){
326
-		ser_error=E_OUT_OF_MEM;
327
-		LM_ERR("out of memory\n");
328
-		return 0;
329
-	}
330
-	memcpy(buf, RECEIVED, RECEIVED_LEN);
331
-	if ( (tmp=ip_addr2a(source_ip))==0) {
332
-		pkg_free(buf);
333
-		return 0; /* error*/
334
-	}
335
-	tmp_len=strlen(tmp);
336
-	len=RECEIVED_LEN+tmp_len;
337
-
338
-	memcpy(buf+RECEIVED_LEN, tmp, tmp_len);
339
-	buf[len]=0; /*null terminate it */
340
-
341
-	*received_len = len;
342
-	return buf;
343
-}
344
-
345
-
346
-
347
-char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
348
-{
349
-	char* buf;
350
-	char* tmp;
351
-	int tmp_len;
352
-	int len;
353
-
354
-	tmp_len=0;
355
-	tmp=int2str(msg->rcv.src_port, &tmp_len);
356
-	len=RPORT_LEN+tmp_len;
357
-	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
358
-	if (buf==0){
359
-		ser_error=E_OUT_OF_MEM;
360
-		LM_ERR("out of memory\n");
361
-		return 0;
362
-	}
363
-	memcpy(buf, RPORT, RPORT_LEN);
364
-	memcpy(buf+RPORT_LEN, tmp, tmp_len);
365
-	buf[len]=0; /*null terminate it*/
366
-
367
-	*rport_len=len;
368
-	return buf;
369
-}
370
-
371
-
372
-
373
-char* id_builder(struct sip_msg* msg, unsigned int *id_len)
374
-{
375
-	char* buf;
376
-	int len, value_len;
377
-	char revhex[sizeof(int)*2];
378
-	char* p;
379
-	int size;
380
-
381
-	size=sizeof(int)*2;
382
-	p=&revhex[0];
383
-	if (int2reverse_hex(&p, &size, msg->rcv.proto_reserved1)==-1){
384
-		LM_CRIT("not enough space for id\n");
385
-		return 0;
386
-	}
387
-	value_len=p-&revhex[0];
388
-	len=ID_PARAM_LEN+value_len;
389
-	buf=pkg_malloc(sizeof(char)*(len+1));/* place for ending \0 */
390
-	if (buf==0){
391
-		ser_error=E_OUT_OF_MEM;
392
-		LM_ERR("out of memory\n");
393
-		return 0;
394
-	}
395
-	memcpy(buf, ID_PARAM, ID_PARAM_LEN);
396
-	memcpy(buf+ID_PARAM_LEN, revhex, value_len);
397
-	buf[len]=0; /* null terminate it */
398
-	*id_len=len;
399
-	return buf;
400
-}
401
-
402
-
403
-
404
-char* clen_builder(	struct sip_msg* msg, int *clen_len, int diff,
405
-					int body_only)
406
-{
407
-	char* buf;
408
-	int len;
409
-	int value;
410
-	char* value_s;
411
-	int value_len;
412
-	char* body;
413
-
414
-
415
-	body=get_body(msg);
416
-	if (body==0){
417
-		ser_error=E_BAD_REQ;
418
-		LM_ERR("no message body found (missing crlf?) [[%.*s]]\n",
419
-				msg->len, msg->buf);
420
-		return 0;
421
-	}
422
-	value=msg->len-(int)(body-msg->buf)+diff;
423
-	value_s=int2str(value, &value_len);
424
-	LM_DBG("content-length: %d (%s)\n", value, value_s);
425
-
426
-	if (body_only) {
427
-		len=value_len;
428
-	}
429
-	else {
430
-		len=CONTENT_LENGTH_LEN+value_len+CRLF_LEN;
431
-	}
432
-	buf=pkg_malloc(sizeof(char)*(len+1));
433
-	if (buf==0){
434
-		ser_error=E_OUT_OF_MEM;
435
-		LM_ERR("out of memory\n");
436
-		return 0;
437
-	}
438
-	if (body_only) {
439
-		memcpy(buf, value_s, value_len);
440
-	}
441
-	else {
442
-		memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
443
-		memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len);
444
-		memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN);
445
-	}
446
-	buf[len]=0; /* null terminate it */
447
-	*clen_len=len;
448
-	return buf;
449
-}
450
-
451
-
452
-
453
-/* checks if a lump opt condition
454
- * returns 1 if cond is true, 0 if false */
455
-static inline int lump_check_opt(	struct lump *l,
456
-									struct sip_msg* msg,
457
-									struct dest_info* snd_i
458
-									)
459
-{
460
-	struct ip_addr* ip;
461
-	unsigned short port;
462
-	int proto;
463
-
464
-#define get_ip_port_proto \
465
-			if ((snd_i==0) || (snd_i->send_sock==0)){ \
466
-				LM_CRIT("null send socket\n"); \
467
-				return 1; /* we presume they are different :-) */ \
468
-			} \
469
-			if (msg->rcv.bind_address){ \
470
-				ip=&msg->rcv.bind_address->address; \
471
-				port=msg->rcv.bind_address->port_no; \
472
-				proto=msg->rcv.bind_address->proto; \
473
-			}else{ \
474
-				ip=&msg->rcv.dst_ip; \
475
-				port=msg->rcv.dst_port; \
476
-				proto=msg->rcv.proto; \
477
-			} \
478
-
479
-	switch(l->u.cond){
480
-		case COND_FALSE:
481
-			return 0;
482
-		case COND_TRUE:
483
-			LUMP_SET_COND_TRUE(l);
484
-			return 1;
485
-		case COND_IF_DIFF_REALMS:
486
-			get_ip_port_proto;
487
-			/* faster tests first */
488
-			if ((port==snd_i->send_sock->port_no) && 
489
-					(proto==snd_i->send_sock->proto) &&
490
-#ifdef USE_COMP
491
-					(msg->rcv.comp==snd_i->comp) &&
492
-#endif
493
-					(ip_addr_cmp(ip, &snd_i->send_sock->address)))
494
-				return 0;
495
-			else {
496
-				LUMP_SET_COND_TRUE(l);
497
-				return 1;
498
-			}
499
-		case COND_IF_DIFF_AF:
500
-			get_ip_port_proto;
501
-			if (ip->af!=snd_i->send_sock->address.af) {
502
-				LUMP_SET_COND_TRUE(l);
503
-				return 1;
504
-			} else return 0;
505
-		case COND_IF_DIFF_PROTO:
506
-			get_ip_port_proto;
507
-			if (proto!=snd_i->send_sock->proto) {
508
-				LUMP_SET_COND_TRUE(l);
509
-				return 1;
510
-			} else return 0;
511
-		case COND_IF_DIFF_PORT:
512
-			get_ip_port_proto;
513
-			if (port!=snd_i->send_sock->port_no) {
514
-				LUMP_SET_COND_TRUE(l);
515
-				return 1;
516
-			} else return 0;
517
-		case COND_IF_DIFF_IP:
518
-			get_ip_port_proto;
519
-			if (ip_addr_cmp(ip, &snd_i->send_sock->address)) return 0;
520
-			else {
521
-				LUMP_SET_COND_TRUE(l);
522
-				return 1;
523
-			}
524
-		case COND_IF_RAND:
525
-			if(kam_rand()>=KAM_RAND_MAX/2) {
526
-				LUMP_SET_COND_TRUE(l);
527
-				return 1;
528
-			} else return 0;
529
-		default:
530
-			LM_CRIT("unknown lump condition %d\n", l->u.cond);
531
-	}
532
-	return 0; /* false */
533
-}
534
-
535
-
536
-
537
-/* computes the "unpacked" len of a lump list,
538
-   code moved from build_req_from_req */
539
-static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, 
540
-								struct dest_info* send_info)
541
-{
542
-	int s_offset;
543
-	int new_len;
544
-	struct lump* t;
545
-	struct lump* r;
546
-	str* send_address_str;
547
-	str* send_port_str;
548
-	str* recv_address_str = NULL;
549
-	str* recv_port_str = NULL;
550
-	int  recv_port_no = 0;
551
-	struct socket_info* send_sock;
552
-	
553
-
554
-#ifdef USE_COMP
555
-	#define RCVCOMP_LUMP_LEN \
556
-						/* add;comp=xxx */ \
557
-					switch(msg->rcv.comp){ \
558
-						case COMP_NONE: \
559
-								break; \
560
-						case COMP_SIGCOMP: \
561
-								new_len+=COMP_PARAM_LEN+SIGCOMP_NAME_LEN; \
562
-								break; \
563
-						case COMP_SERGZ: \
564
-								new_len+=COMP_PARAM_LEN+SERGZ_NAME_LEN ; \
565
-								break; \
566
-						default: \
567
-						LM_CRIT("unknown comp %d\n", msg->rcv.comp); \
568
-					}
569
-
570
-	#define SENDCOMP_LUMP_LEN \
571
-					/* add;comp=xxx */ \
572
-					switch(send_info->comp){ \
573
-						case COMP_NONE: \
574
-								break; \
575
-						case COMP_SIGCOMP: \
576
-								new_len+=COMP_PARAM_LEN+SIGCOMP_NAME_LEN; \
577
-								break; \
578
-						case COMP_SERGZ: \
579
-								new_len+=COMP_PARAM_LEN+SERGZ_NAME_LEN ; \
580
-								break; \
581
-						default: \
582
-						LM_CRIT("unknown comp %d\n", send_info->comp); \
583
-					}
584
-#else
585
-	#define RCVCOMP_LUMP_LEN
586
-	#define SENDCOMP_LUMP_LEN
587
-#endif /*USE_COMP */
588
-	
589
-#define SUBST_LUMP_LEN(subst_l) \
590
-		switch((subst_l)->u.subst){ \
591
-			case SUBST_RCV_IP: \
592
-				if (msg->rcv.bind_address){ \
593
-					new_len+=recv_address_str->len; \
594
-					if (msg->rcv.bind_address->address.af!=AF_INET) \
595
-						new_len+=2; \
596
-				}else{ \
597
-					/* FIXME */ \
598
-					LM_CRIT("FIXME: null bind_address\n"); \
599
-				}; \
600
-				break; \
601
-			case SUBST_RCV_PORT: \
602
-				if (msg->rcv.bind_address){ \
603
-					new_len+=recv_port_str->len; \
604
-				}else{ \
605
-					/* FIXME */ \
606
-					LM_CRIT("FIXME: null bind_address\n"); \
607
-				}; \
608
-				break; \
609
-			case SUBST_RCV_PROTO: \
610
-				if (msg->rcv.bind_address){ \
611
-					switch(msg->rcv.bind_address->proto){ \
612
-						case PROTO_NONE: \
613
-						case PROTO_UDP: \
614
-							new_len+=3; \
615
-							break; \
616
-						case PROTO_TCP: \
617
-						case PROTO_TLS: \
618
-							switch(msg->rcv.proto){ \
619
-								case PROTO_WS: \
620
-								case PROTO_WSS: \
621
-									new_len+=2; \
622
-									break; \
623
-								default: \
624
-									new_len+=3; \
625
-									break; \
626
-							} \
627
-							break; \
628
-						case PROTO_SCTP: \
629
-							new_len+=4; \
630
-							break; \
631
-						default: \
632
-						LM_CRIT("unknown proto %d\n", msg->rcv.bind_address->proto); \
633
-					}\
634
-				}else{ \
635
-					/* FIXME */ \
636
-					LM_CRIT("FIXME: null bind_address\n"); \
637
-				}; \
638
-				break; \
639
-			case SUBST_RCV_ALL: \
640
-				if (msg->rcv.bind_address){ \
641
-					new_len+=recv_address_str->len; \
642
-					if (msg->rcv.bind_address->address.af!=AF_INET) \
643
-						new_len+=2; \
644
-					if (recv_port_no!=SIP_PORT){ \
645
-						/* add :port_no */ \
646
-						new_len+=1+recv_port_str->len; \
647
-					}\
648
-						/*add;transport=xxx*/ \
649
-					switch(msg->rcv.bind_address->proto){ \
650
-						case PROTO_NONE: \
651
-						case PROTO_UDP: \
652
-							break; /* udp is the default */ \
653
-						case PROTO_TCP: \
654
-						case PROTO_TLS: \
655
-							switch(msg->rcv.proto){ \
656
-								case PROTO_WS: \
657
-								case PROTO_WSS: \
658
-									new_len+=TRANSPORT_PARAM_LEN+2; \
659
-									break; \
660
-								default: \
661
-									new_len+=TRANSPORT_PARAM_LEN+3; \
662
-									break; \
663
-							} \
664
-							break; \
665
-						case PROTO_SCTP: \
666
-							new_len+=TRANSPORT_PARAM_LEN+4; \
667
-							break; \
668
-						default: \
669
-						LM_CRIT("unknown proto %d\n", \
670
-								msg->rcv.bind_address->proto); \
671
-					}\
672
-					RCVCOMP_LUMP_LEN \
673
-				}else{ \
674
-					/* FIXME */ \
675
-					LM_CRIT("FIXME: null bind_address\n"); \
676
-				}; \
677
-				break; \
678
-			case SUBST_SND_IP: \
679
-				if (send_sock){ \
680
-					new_len+=send_address_str->len; \
681
-					if (send_sock->address.af!=AF_INET && \
682
-							send_address_str==&(send_sock->address_str)) \
683
-						new_len+=2; \
684
-				}else{ \
685
-					LM_CRIT("FIXME: null send_sock\n"); \
686
-				}; \
687
-				break; \
688
-			case SUBST_SND_PORT: \
689
-				if (send_sock){ \
690
-					new_len+=send_port_str->len; \
691
-				}else{ \
692
-					LM_CRIT("FIXME: null send_sock\n"); \
693
-				}; \
694
-				break; \
695
-			case SUBST_SND_PROTO: \
696
-				if (send_sock){ \
697
-					switch(send_sock->proto){ \
698
-						case PROTO_NONE: \
699
-						case PROTO_UDP: \
700
-							new_len+=3; \
701
-							break; \
702
-						case PROTO_TCP: \
703
-						case PROTO_TLS: \
704
-							switch(send_info->proto){ \
705
-								case PROTO_WS: \
706
-								case PROTO_WSS: \
707
-									new_len+=2; \
708
-									break; \
709
-								default: \
710
-									new_len+=3; \
711
-									break; \
712
-							} \
713
-							break; \
714
-						case PROTO_SCTP: \
715
-							new_len+=4; \
716
-							break; \
717
-						default: \
718
-						LM_CRIT("unknown proto %d\n", send_sock->proto); \
719
-					}\
720
-				}else{ \
721
-					LM_CRIT("FIXME: null send_sock\n"); \
722
-				}; \
723
-				break; \
724
-			case SUBST_SND_ALL: \
725
-				if (send_sock){ \
726
-					new_len+=send_address_str->len; \
727
-					if ((send_sock->address.af!=AF_INET) && \
728
-							(send_address_str==&(send_sock->address_str))) \
729
-						new_len+=2; \
730
-					if ((send_sock->port_no!=SIP_PORT) || \
731
-							(send_port_str!=&(send_sock->port_no_str))){ \
732
-						/* add :port_no */ \
733
-						new_len+=1+send_port_str->len; \
734
-					}\
735
-					/*add;transport=xxx*/ \
736
-					switch(send_sock->proto){ \
737
-						case PROTO_NONE: \
738
-						case PROTO_UDP: \
739
-							break; /* udp is the default */ \
740
-						case PROTO_TCP: \
741
-						case PROTO_TLS: \
742
-							switch(send_info->proto){ \
743
-								case PROTO_WS: \
744
-								case PROTO_WSS: \
745
-									new_len+=TRANSPORT_PARAM_LEN+2; \
746
-									break; \
747
-								default: \
748
-									new_len+=TRANSPORT_PARAM_LEN+3; \
749
-									break; \
750
-							} \
751
-							break; \
752
-						case PROTO_SCTP: \
753
-							new_len+=TRANSPORT_PARAM_LEN+4; \
754
-							break; \
755
-						default: \
756
-						LM_CRIT("unknown proto %d\n", send_sock->proto); \
757
-					}\
758
-					SENDCOMP_LUMP_LEN \
759
-				}else{ \
760
-					/* FIXME */ \
761
-					LM_CRIT("FIXME: null send_sock\n"); \
762
-				}; \
763
-				break; \
764
-			case SUBST_NOP: /* do nothing */ \
765
-				break; \
766
-			default: \
767
-				LM_CRIT("unknown subst type %d\n", (subst_l)->u.subst); \
768
-		}
769
-	
770
-	if (send_info){
771
-		send_sock=send_info->send_sock;
772
-	}else{
773
-		send_sock=0;
774
-	};
775
-	s_offset=0;
776
-	new_len=0;
777
-	/* init send_address_str & send_port_str */
778
-	if(send_sock && send_sock->useinfo.name.len>0)
779
-		send_address_str=&(send_sock->useinfo.name);
780
-	else if (msg->set_global_address.len)
781
-		send_address_str=&(msg->set_global_address);
782
-	else
783
-		send_address_str=&(send_sock->address_str);
784
-	if(send_sock && send_sock->useinfo.port_no>0)
785
-		send_port_str=&(send_sock->useinfo.port_no_str);
786
-	else if (msg->set_global_port.len)
787
-		send_port_str=&(msg->set_global_port);
788
-	else
789
-		send_port_str=&(send_sock->port_no_str);
790
-	/* init recv_address_str, recv_port_str & recv_port_no */
791
-	if(msg->rcv.bind_address) {
792
-		if(msg->rcv.bind_address->useinfo.name.len>0)
793
-			recv_address_str=&(msg->rcv.bind_address->useinfo.name);
794
-		else
795
-			recv_address_str=&(msg->rcv.bind_address->address_str);
796
-		if(msg->rcv.bind_address->useinfo.port_no>0) {
797
-			recv_port_str=&(msg->rcv.bind_address->useinfo.port_no_str);
798
-			recv_port_no = msg->rcv.bind_address->useinfo.port_no;
799
-		} else {
800
-			recv_port_str=&(msg->rcv.bind_address->port_no_str);
801
-			recv_port_no = msg->rcv.bind_address->port_no;
802
-		}
803
-	}
804
-
805
-	for(t=lumps;t;t=t->next){
806
-		/* skip if this is an OPT lump and the condition is not satisfied */
807
-		if ((t->op==LUMP_ADD_OPT)&& !lump_check_opt(t, msg, send_info))
808
-			continue;
809
-		for(r=t->before;r;r=r->before){
810
-			switch(r->op){
811
-				case LUMP_ADD:
812
-					new_len+=r->len;
813
-					break;
814
-				case LUMP_ADD_SUBST:
815
-					SUBST_LUMP_LEN(r);
816
-					break;
817
-				case LUMP_ADD_OPT:
818
-					/* skip if this is an OPT lump and the condition is
819
-					 * not satisfied */
820
-					if (!lump_check_opt(r, msg, send_info))
821
-						goto skip_before;
822
-					break;
823
-				default:
824
-					/* only ADD allowed for before/after */
825
-						LM_CRIT("invalid op for data lump (%x)\n", r->op);
826
-			}
827
-		}
828
-skip_before:
829
-		switch(t->op){
830
-			case LUMP_ADD:
831
-				new_len+=t->len;
832
-				break;
833
-			case LUMP_ADD_SUBST:
834
-				SUBST_LUMP_LEN(t);
835
-				break;
836
-			case LUMP_ADD_OPT:
837
-				/* we don't do anything here, it's only a condition for
838
-				 * before & after */
839
-				break;
840
-			case LUMP_DEL:
841
-				/* fix overlapping deleted zones */
842
-				if (t->u.offset < s_offset){
843
-					/* change len */
844
-					if (t->len>s_offset-t->u.offset)
845
-							t->len-=s_offset-t->u.offset;
846
-					else t->len=0;
847
-					t->u.offset=s_offset;
848
-				}
849
-				s_offset=t->u.offset+t->len;
850
-				new_len-=t->len;
851
-				break;
852
-			case LUMP_NOP:
853
-				/* fix offset if overlapping on a deleted zone */
854
-				if (t->u.offset < s_offset){
855
-					t->u.offset=s_offset;
856
-				}else
857
-					s_offset=t->u.offset;
858
-				/* do nothing */
859
-				break;
860
-			default:
861
-				LM_CRIT("invalid op for data lump (%x)\n", r->op);
862
-		}
863
-		for (r=t->after;r;r=r->after){
864
-			switch(r->op){
865
-				case LUMP_ADD:
866
-					new_len+=r->len;
867
-					break;
868
-				case LUMP_ADD_SUBST:
869
-					SUBST_LUMP_LEN(r);
870
-					break;
871
-				case LUMP_ADD_OPT:
872
-					/* skip if this is an OPT lump and the condition is
873
-					 * not satisfied */
874
-					if (!lump_check_opt(r, msg, send_info))
875
-						goto skip_after;
876
-					break;
877
-				default:
878
-					/* only ADD allowed for before/after */
879
-					LM_CRIT("invalid op for data lump (%x)\n", r->op);
880
-			}
881
-		}
882
-skip_after:
883
-		; /* to make gcc 3.* happy */
884
-	}
885
-	return new_len;
886
-#undef RCVCOMP_LUMP_LEN
887
-#undef SENDCOMP_LUMP_LEN
888
-}
889
-
890
-
891
-
892
-/* another helper functions, adds/Removes the lump,
893
-	code moved form build_req_from_req  */
894
-
895
-void process_lumps( struct sip_msg* msg,
896
-                    struct lump* lumps,
897
-                    char* new_buf,
898
-                    unsigned int* new_buf_offs,
899
-                    unsigned int* orig_offs,
900
-                    struct dest_info* send_info,
901
-                    int flag)
902
-{
903
-	struct lump *t;
904
-	struct lump *r;