Browse code

- removed msg->repl_add_rm (msg->add_rm is used now both for replies & requests) - tcp code now always tries to add bind address info even for temporary "sending" sockets (it tries to find first match in the listening sockets list) - new lump function: insert_subst_lump_after, insert_subst_lump_before (you can add now lumps that will be substituted with the rcv/sending ip addr, port or proto: see SUBST_{SND,RCV}_{IP,PORT,PROTO})

Andrei Pelinescu-Onciul authored on 31/03/2003 19:51:10
Showing 8 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 VERSION = 0
19 19
 PATCHLEVEL = 8
20 20
 SUBLEVEL =   11
21
-EXTRAVERSION = pre8-mem
21
+EXTRAVERSION = pre9-repl_add_rm
22 22
 
23 23
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
24 24
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -16,6 +16,8 @@ x (different way) add request header bitmap field for the modules
16 16
 - ? variable number of params functions in script (no longer limited to 2)?
17 17
 - kill bind_idx
18 18
 - fix bind_address for tcp (in some  way)
19
+- add conflict in debs/rpms/etc (conflict w/ older ser-mysql, ser-jabber)
20
+- new packages ser-radius etc
19 21
 
20 22
 
21 23
 High priority:
... ...
@@ -26,7 +26,8 @@
26 26
  *
27 27
  * History:
28 28
  * --------
29
- * 2003-01-19 support for duplication lump lists added (jiri)
29
+ *  2003-01-19  support for duplication lump lists added (jiri)
30
+ *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
30 31
  */
31 32
 
32 33
 
... ...
@@ -149,6 +150,57 @@ struct lump* insert_new_lump_before( struct lump* before, char* new_hdr,
149 149
 
150 150
 
151 151
 
152
+/* inserts a  subst lump immediately after hdr 
153
+ * returns pointer on success, 0 on error */
154
+struct lump* insert_subst_lump_after( struct lump* after, enum lump_subst subst,
155
+										int type)
156
+{
157
+	struct lump* tmp;
158
+
159
+	tmp=pkg_malloc(sizeof(struct lump));
160
+	if (tmp==0){
161
+		ser_error=E_OUT_OF_MEM;
162
+		LOG(L_ERR, "ERROR: insert_new_lump_after: out of memory\n");
163
+		return 0;
164
+	}
165
+	memset(tmp,0,sizeof(struct lump));
166
+	tmp->after=after->after;
167
+	tmp->type=type;
168
+	tmp->op=LUMP_ADD_SUBST;
169
+	tmp->u.subst=subst;
170
+	tmp->len=0;
171
+	after->after=tmp;
172
+	return tmp;
173
+}
174
+
175
+
176
+
177
+/* inserts a  subst lump immediately before "before" 
178
+ * returns pointer on success, 0 on error */
179
+struct lump* insert_subst_lump_before(	struct lump* before, 
180
+										enum lump_subst subst,
181
+										int type)
182
+{
183
+	struct lump* tmp;
184
+
185
+	tmp=pkg_malloc(sizeof(struct lump));
186
+	if (tmp==0){
187
+		ser_error=E_OUT_OF_MEM;
188
+		LOG(L_ERR,"ERROR: insert_new_lump_before: out of memory\n");
189
+		return 0;
190
+	}
191
+	memset(tmp,0,sizeof(struct lump));
192
+	tmp->before=before->before;
193
+	tmp->type=type;
194
+	tmp->op=LUMP_ADD_SUBST;
195
+	tmp->u.subst=subst;
196
+	tmp->len=0;
197
+	before->before=tmp;
198
+	return tmp;
199
+}
200
+
201
+
202
+
152 203
 /* removes an already existing header/data lump */
153 204
 struct lump* del_lump(struct lump** list, int offset, int len, int type)
154 205
 {
... ...
@@ -25,8 +25,11 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
- *
29
- * 2003-01-29 s/int/enum ... more convenient for gdb (jiri)
28
+ */
29
+/* History:
30
+ * --------
31
+ *  2003-01-29  s/int/enum ... more convenient for gdb (jiri)
32
+ *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
30 33
  */
31 34
 
32 35
 
... ...
@@ -34,7 +37,12 @@
34 34
 #define data_lump_h
35 35
 
36 36
 
37
-enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
37
+enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST };
38
+enum lump_subst{ SUBST_NOP=0,
39
+				 SUBST_RCV_IP,    SUBST_SND_IP,
40
+				 SUBST_RCV_PORT,  SUBST_SND_PORT,
41
+				 SUBST_RCV_PROTO, SUBST_SND_PROTO
42
+				};
38 43
 enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
39 44
 
40 45
 struct lump{
... ...
@@ -43,6 +51,7 @@ struct lump{
43 43
 	
44 44
 	union{
45 45
 		int offset; /* used for DEL, MODIFY */
46
+		enum lump_subst subst; /*what to subst: ip addr, port, proto*/
46 47
 		char * value; /* used for ADD */
47 48
 	}u;
48 49
 	int len; /* length of this header field */
... ...
@@ -89,6 +98,11 @@ struct lump* insert_new_lump_after(struct lump* after,
89 89
 									char* new_hdr, int len, int type);
90 90
 struct lump* insert_new_lump_before(struct lump* before, char* new_hdr,
91 91
 									int len,int type);
92
+/* substitutions (replace with ip address, port etc) */
93
+struct lump* insert_subst_lump_after(struct lump* after,  enum lump_subst subst,
94
+									int type);
95
+struct lump* insert_subst_lump_before(struct lump* before,enum lump_subst subst,
96
+									int type);
92 97
 
93 98
 
94 99
 /* removes an already existing header */
... ...
@@ -42,6 +42,7 @@
42 42
  * 2003-01-27  more rport fixes (make use of new via_param->start)  (andrei)
43 43
  * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
44 44
  * 2003-01-29  scratchpad removed (jiri)
45
+ * 2003-03-31  added subst lump support (andrei)
45 46
  *
46 47
  */
47 48
 
... ...
@@ -357,24 +358,89 @@ char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
357 357
 
358 358
 /* computes the "unpacked" len of a lump list,
359 359
    code moved from build_req_from_req */
360
-static inline int lumps_len(struct lump* l)
360
+static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
361 361
 {
362 362
 	int s_offset;
363 363
 	int new_len;
364 364
 	struct lump* t;
365 365
 	struct lump* r;
366 366
 
367
+#define SUBST_LUMP_LEN(subst_l) \
368
+		switch((subst_l)->u.subst){ \
369
+			case SUBST_RCV_IP: \
370
+				if (msg->rcv.bind_address){ \
371
+					new_len+=msg->rcv.bind_address->address_str.len; \
372
+					if (msg->rcv.bind_address->address.af!=AF_INET) \
373
+						new_len+=2; \
374
+				}else{ \
375
+					/* FIXME */ \
376
+					LOG(L_CRIT, "FIXME: null bind_address\n"); \
377
+				}; \
378
+				break; \
379
+			case SUBST_RCV_PORT: \
380
+				if (msg->rcv.bind_address){ \
381
+					new_len+=msg->rcv.bind_address->port_no_str.len; \
382
+				}else{ \
383
+					/* FIXME */ \
384
+					LOG(L_CRIT, "FIXME: null bind_address\n"); \
385
+				}; \
386
+				break; \
387
+			case SUBST_RCV_PROTO: \
388
+				if (msg->rcv.bind_address){ \
389
+					new_len+=send_sock->port_no_str.len; \
390
+				}else{ \
391
+					/* FIXME */ \
392
+					LOG(L_CRIT, "FIXME: null bind_address\n"); \
393
+				}; \
394
+				break; \
395
+			case SUBST_SND_IP: \
396
+				if (send_sock){ \
397
+					new_len+=send_sock->address_str.len; \
398
+					if (send_sock->address.af!=AF_INET) \
399
+						new_len+=2; \
400
+				}else{ \
401
+					LOG(L_CRIT, "FIXME: lumps_len called with" \
402
+							" null send_sock\n"); \
403
+				}; \
404
+				break; \
405
+			case SUBST_SND_PORT: \
406
+				if (send_sock){ \
407
+					new_len+=send_sock->port_no_str.len; \
408
+				}else{ \
409
+					LOG(L_CRIT, "FIXME: lumps_len called with" \
410
+							" null send_sock\n"); \
411
+				}; \
412
+				break; \
413
+			case SUBST_SND_PROTO: \
414
+				if (send_sock){ \
415
+					new_len+=3; /* tcp, udp or tls*/ \
416
+				}else{ \
417
+					LOG(L_CRIT, "FIXME: lumps_len called with" \
418
+							" null send_sock\n"); \
419
+				}; \
420
+				break; \
421
+			case SUBST_NOP: /* do nothing */ \
422
+				break; \
423
+			default: \
424
+				LOG(L_CRIT, "BUG: unknown subst type %d\n", \
425
+						(subst_l)->u.subst); \
426
+		}
427
+	
367 428
 	s_offset=0;
368 429
 	new_len=0;
369
-	for(t=l;t;t=t->next){
430
+	
431
+	for(t=msg->add_rm;t;t=t->next){
370 432
 		for(r=t->before;r;r=r->before){
371 433
 			switch(r->op){
372 434
 				case LUMP_ADD:
373 435
 					new_len+=r->len;
374 436
 					break;
437
+				case LUMP_ADD_SUBST:
438
+					SUBST_LUMP_LEN(r);
439
+					break;
375 440
 				default:
376 441
 					/* only ADD allowed for before/after */
377
-					LOG(L_CRIT, "BUG: lumps_len: invalid op "
442
+						LOG(L_CRIT, "BUG: lumps_len: invalid op "
378 443
 							"for data lump (%x)\n", r->op);
379 444
 			}
380 445
 		}
... ...
@@ -382,6 +448,9 @@ static inline int lumps_len(struct lump* l)
382 382
 			case LUMP_ADD:
383 383
 				new_len+=t->len;
384 384
 				break;
385
+			case LUMP_ADD_SUBST:
386
+				SUBST_LUMP_LEN(t);
387
+				break;
385 388
 			case LUMP_DEL:
386 389
 				/* fix overlapping deleted zones */
387 390
 				if (t->u.offset < s_offset){
... ...
@@ -411,6 +480,9 @@ static inline int lumps_len(struct lump* l)
411 411
 				case LUMP_ADD:
412 412
 					new_len+=r->len;
413 413
 					break;
414
+				case LUMP_ADD_SUBST:
415
+					SUBST_LUMP_LEN(r);
416
+					break;
414 417
 				default:
415 418
 					/* only ADD allowed for before/after */
416 419
 					LOG(L_CRIT, "BUG:lumps_len: invalid"
... ...
@@ -426,22 +498,130 @@ static inline int lumps_len(struct lump* l)
426 426
 /* another helper functions, adds/Removes the lump,
427 427
 	code moved form build_req_from_req  */
428 428
 
429
-static inline void process_lumps(	struct lump* l,	char* new_buf, 
430
-									unsigned int* new_buf_offs, char* orig,
431
-									unsigned int* orig_offs)
429
+static inline void process_lumps(	struct sip_msg* msg,	
430
+									char* new_buf, 
431
+									unsigned int* new_buf_offs, 
432
+									unsigned int* orig_offs,
433
+									struct socket_info* send_sock)
432 434
 {
433 435
 	struct lump *t;
434 436
 	struct lump *r;
437
+	char* orig;
435 438
 	int size;
436 439
 	int offset;
437 440
 	int s_offset;
441
+
442
+#define SUBST_LUMP(subst_l) \
443
+	switch((subst_l)->u.subst){ \
444
+		case SUBST_RCV_IP: \
445
+			if (msg->rcv.bind_address){  \
446
+				memcpy(new_buf+offset, msg->rcv.bind_address->address_str.s, \
447
+						msg->rcv.bind_address->address_str.len); \
448
+				offset+=msg->rcv.bind_address->address_str.len; \
449
+			}else{  \
450
+				/*FIXME*/ \
451
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
452
+			}; \
453
+			break; \
454
+		case SUBST_RCV_PORT: \
455
+			if (msg->rcv.bind_address){  \
456
+				memcpy(new_buf+offset, msg->rcv.bind_address->port_no_str.s, \
457
+						msg->rcv.bind_address->port_no_str.len); \
458
+				offset+=msg->rcv.bind_address->port_no_str.len; \
459
+			}else{  \
460
+				/*FIXME*/ \
461
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
462
+			}; \
463
+			break; \
464
+		case SUBST_SND_IP: \
465
+			if (send_sock){  \
466
+				memcpy(new_buf+offset, send_sock->address_str.s, \
467
+									send_sock->address_str.len); \
468
+				offset+=send_sock->address_str.len; \
469
+			}else{  \
470
+				/*FIXME*/ \
471
+				LOG(L_CRIT, "FIXME: process_lumps: called with" \
472
+							" null send_sock\n"); \
473
+			}; \
474
+			break; \
475
+		case SUBST_SND_PORT: \
476
+			if (send_sock){  \
477
+				memcpy(new_buf+offset, send_sock->port_no_str.s, \
478
+									send_sock->port_no_str.len); \
479
+				offset+=send_sock->port_no_str.len; \
480
+			}else{  \
481
+				/*FIXME*/ \
482
+				LOG(L_CRIT, "FIXME: process_lumps: called with" \
483
+						" null send_sock\n"); \
484
+			}; \
485
+			break; \
486
+		case SUBST_RCV_PROTO: \
487
+			if (msg->rcv.bind_address){ \
488
+				switch(msg->rcv.bind_address->proto){ \
489
+					case PROTO_NONE: \
490
+					case PROTO_UDP: \
491
+						memcpy(new_buf+offset, "udp", 3); \
492
+						offset+=3; \
493
+						break; \
494
+					case PROTO_TCP: \
495
+						memcpy(new_buf+offset, "tcp", 3); \
496
+						offset+=3; \
497
+						break; \
498
+					case PROTO_TLS: \
499
+						memcpy(new_buf+offset, "tls", 3); \
500
+						offset+=3; \
501
+						break; \
502
+					default: \
503
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
504
+								msg->rcv.bind_address->proto); \
505
+				} \
506
+			}else{  \
507
+				/*FIXME*/ \
508
+				LOG(L_CRIT, "FIXME: process lumps: null bind_address\n"); \
509
+			}; \
510
+			break; \
511
+		case  SUBST_SND_PROTO: \
512
+			if (send_sock){ \
513
+				switch(send_sock->proto){ \
514
+					case PROTO_NONE: \
515
+					case PROTO_UDP: \
516
+						memcpy(new_buf+offset, "udp", 3); \
517
+						offset+=3; \
518
+						break; \
519
+					case PROTO_TCP: \
520
+						memcpy(new_buf+offset, "tcp", 3); \
521
+						offset+=3; \
522
+						break; \
523
+					case PROTO_TLS: \
524
+						memcpy(new_buf+offset, "tls", 3); \
525
+						offset+=3; \
526
+						break; \
527
+					default: \
528
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
529
+								send_sock->proto); \
530
+				} \
531
+			}else{  \
532
+				/*FIXME*/ \
533
+				LOG(L_CRIT, "FIXME: process_lumps: called with null" \
534
+							" send_sock \n"); \
535
+			}; \
536
+			break; \
537
+		default: \
538
+					LOG(L_CRIT, "BUG: process_lumps: unknown subst type %d\n", \
539
+							(subst_l)->u.subst); \
540
+	} \
541
+ \
542
+	
543
+	
438 544
 	
545
+	orig=msg->buf;
439 546
 	offset=*new_buf_offs;
440 547
 	s_offset=*orig_offs;
441 548
 	
442
-	for (t=l;t;t=t->next){
549
+	for (t=msg->add_rm;t;t=t->next){
443 550
 		switch(t->op){
444 551
 			case LUMP_ADD:
552
+			case LUMP_ADD_SUBST:
445 553
 				/* just add it here! */
446 554
 				/* process before  */
447 555
 				for(r=t->before;r;r=r->before){
... ...
@@ -451,6 +631,9 @@ static inline void process_lumps(	struct lump* l,	char* new_buf,
451 451
 							memcpy(new_buf+offset, r->u.value, r->len);
452 452
 							offset+=r->len;
453 453
 							break;
454
+						case LUMP_ADD_SUBST:
455
+							SUBST_LUMP(r);
456
+							break;
454 457
 						default:
455 458
 							/* only ADD allowed for before/after */
456 459
 							LOG(L_CRIT, "BUG:process_lumps: "
... ...
@@ -458,8 +641,12 @@ static inline void process_lumps(	struct lump* l,	char* new_buf,
458 458
 					}
459 459
 				}
460 460
 				/* copy "main" part */
461
-				memcpy(new_buf+offset, t->u.value, t->len);
462
-				offset+=t->len;
461
+				if(t->op==LUMP_ADD){
462
+					memcpy(new_buf+offset, t->u.value, t->len);
463
+					offset+=t->len;
464
+				}else{
465
+					SUBST_LUMP(t);
466
+				}
463 467
 				/* process after */
464 468
 				for(r=t->after;r;r=r->after){
465 469
 					switch (r->op){
... ...
@@ -468,6 +655,9 @@ static inline void process_lumps(	struct lump* l,	char* new_buf,
468 468
 							memcpy(new_buf+offset, r->u.value, r->len);
469 469
 							offset+=r->len;
470 470
 							break;
471
+						case LUMP_ADD_SUBST:
472
+							SUBST_LUMP(r);
473
+							break;
471 474
 						default:
472 475
 							/* only ADD allowed for before/after */
473 476
 							LOG(L_CRIT, "BUG:process_lumps: "
... ...
@@ -499,6 +689,9 @@ static inline void process_lumps(	struct lump* l,	char* new_buf,
499 499
 							memcpy(new_buf+offset, r->u.value, r->len);
500 500
 							offset+=r->len;
501 501
 							break;
502
+						case LUMP_ADD_SUBST:
503
+							SUBST_LUMP(r);
504
+							break;
502 505
 						default:
503 506
 							/* only ADD allowed for before/after */
504 507
 							LOG(L_CRIT, "BUG:process_lumps: "
... ...
@@ -518,6 +711,9 @@ static inline void process_lumps(	struct lump* l,	char* new_buf,
518 518
 							memcpy(new_buf+offset, r->u.value, r->len);
519 519
 							offset+=r->len;
520 520
 							break;
521
+						case LUMP_ADD_SUBST:
522
+							SUBST_LUMP(r);
523
+							break;
521 524
 						default:
522 525
 							/* only ADD allowed for before/after */
523 526
 							LOG(L_CRIT, "BUG:process_lumps: "
... ...
@@ -686,7 +882,7 @@ skip_clen:
686 686
 #endif
687 687
 
688 688
 	/* compute new msg len and fix overlapping zones*/
689
-	new_len=len+lumps_len(msg->add_rm);
689
+	new_len=len+lumps_len(msg, send_sock);
690 690
 
691 691
 	if (msg->new_uri.s){
692 692
 		uri_len=msg->new_uri.len;
... ...
@@ -713,7 +909,7 @@ skip_clen:
713 713
 	}
714 714
 	new_buf[new_len]=0;
715 715
 	/* copy msg adding/removing lumps */
716
-	process_lumps(msg->add_rm, new_buf, &offset, buf, &s_offset);
716
+	process_lumps(msg, new_buf, &offset, &s_offset, send_sock);
717 717
 	/* copy the rest of the message */
718 718
 	memcpy(new_buf+offset, buf+s_offset, len-s_offset);
719 719
 	new_buf[new_len]=0;
... ...
@@ -802,7 +998,7 @@ skip_clen:
802 802
 #endif
803 803
 	
804 804
 	/* remove the first via*/
805
-	if (del_lump( &(msg->repl_add_rm), via_offset, via_len, HDR_VIA)==0){
805
+	if (del_lump( &(msg->add_rm), via_offset, via_len, HDR_VIA)==0){
806 806
 		LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
807 807
 					"via\n");
808 808
 		goto error;
... ...
@@ -812,7 +1008,7 @@ skip_clen:
812 812
 	if (clen_len){
813 813
 		/* msg->unparsed should point just before the final crlf,
814 814
 		 * parse_headers is called from clen_builder */
815
-		anchor=anchor_lump(&(msg->repl_add_rm), msg->unparsed-buf, 0, 
815
+		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0, 
816 816
 							HDR_CONTENTLENGTH);
817 817
 		DBG("build_res_from_sip_res: adding content-length: %.*s\n",
818 818
 				(int)clen_len, clen_buf);
... ...
@@ -822,8 +1018,8 @@ skip_clen:
822 822
 			goto error_clen; /* free clen_buf*/
823 823
 	}
824 824
 #endif
825
-	new_len=len+lumps_len(msg->repl_add_rm);
826
-
825
+	new_len=len+lumps_len(msg, 0); /*FIXME: we don't know the send sock */
826
+	
827 827
 	DBG(" old size: %d, new size: %d\n", len, new_len);
828 828
 	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging 
829 829
 											 (\0 to print it )*/
... ...
@@ -833,9 +1029,7 @@ skip_clen:
833 833
 	}
834 834
 	new_buf[new_len]=0; /* debug: print the message */
835 835
 	offset=s_offset=0;
836
-	process_lumps(msg->repl_add_rm, new_buf, &offset, 
837
-		buf,
838
-		&s_offset);
836
+	process_lumps(msg, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
839 837
 	/* copy the rest of the message */
840 838
 	memcpy(new_buf+offset,
841 839
 		buf+s_offset, 
... ...
@@ -29,9 +29,10 @@
29 29
  *
30 30
  * History:
31 31
  * ---------
32
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
33
- * 2003-01-29 scrathcpad removed (jiri)
34
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
32
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
33
+ *  2003-01-29  scrathcpad removed (jiri)
34
+ *  2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
35
+ *  2003-03-31  removed msg->repl_add_rm (andrei)
35 36
  */
36 37
 
37 38
 
... ...
@@ -553,7 +554,6 @@ void free_sip_msg(struct sip_msg* msg)
553 553
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
554 554
 	if (msg->headers)     free_hdr_field_lst(msg->headers);
555 555
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
556
-	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
557 556
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
558 557
 	/* don't free anymore -- now a pointer to a static buffer */
559 558
 #	ifdef DYN_BUF
... ...
@@ -26,10 +26,11 @@
26 26
  *
27 27
  * History
28 28
  * -------
29
- * 2003-03-06 enum_request_method changed to begin with 1;
30
- *            0 reserved for invalid values; (jiri)
31
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
32
- * 2003-01-28 removed scratchpad (jiri)
29
+ *  2003-03-06  enum_request_method changed to begin with 1;
30
+ *             0 reserved for invalid values; (jiri)
31
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
32
+ *  2003-01-28  removed scratchpad (jiri)
33
+ *  2003-03-31  removed sip_msg->repl_add_rm (andrei)
33 34
  */
34 35
 
35 36
 
... ...
@@ -141,8 +142,7 @@ struct sip_msg {
141 141
 	int parsed_uri_ok; /* 1 if parsed_uri is valid, 0 if not */
142 142
 	struct sip_uri parsed_uri; /* speed-up > keep here the parsed uri*/
143 143
 	
144
-	struct lump* add_rm;         /* used for all the forwarded requests */
145
-	struct lump* repl_add_rm;    /* used for all the forwarded replies */
144
+	struct lump* add_rm;       /* used for all the forwarded requests/replies */
146 145
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/
147 146
 
148 147
 	/* str add_to_branch; 
... ...
@@ -34,7 +34,10 @@
34 34
  *  2003-02-25  Nagle is disabled if -DDISABLE_NAGLE (andrei)
35 35
  *  2003-03-29  SO_REUSEADDR before calling bind to allow
36 36
  *              server restart, Nagle set on the (hopefuly) 
37
- *              correct socket
37
+ *              correct socket (jiri)
38
+ *  2003-03-31  always try to find the corresponding tcp listen socket for
39
+ *               a temp. socket and store in in *->bind_address: added
40
+ *               find_tcp_si, modified tcpconn_connect (andrei)
38 41
  */
39 42
 
40 43
 
... ...
@@ -149,9 +152,28 @@ error:
149 149
 
150 150
 
151 151
 
152
+
153
+struct socket_info* find_tcp_si(union sockaddr_union* s)
154
+{
155
+	int r;
156
+	struct ip_addr ip;
157
+	
158
+	su2ip_addr(&ip, s);
159
+	for (r=0; r<sock_no; r++)
160
+		if (ip_addr_cmp(&ip, &tcp_info[r].address)){
161
+			/* found it, we use first match */
162
+			return &tcp_info[r];
163
+		}
164
+	return 0; /* no match */
165
+}
166
+
167
+
152 168
 struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
153 169
 {
154 170
 	int s;
171
+	struct socket_info* si;
172
+	union sockaddr_union my_name;
173
+	int my_name_len;
155 174
 #ifdef DISABLE_NAGLE
156 175
 	int flag;
157 176
 #endif
... ...
@@ -179,7 +201,22 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
179 179
 				errno, strerror(errno));
180 180
 		goto error;
181 181
 	}
182
-	return tcpconn_new(s, server, 0); /*FIXME: set sock idx! */
182
+	my_name_len=sizeof(my_name);
183
+	if (getsockname(s, &my_name.s, &my_name_len)!=0){
184
+		LOG(L_ERR, "ERROR: tcp_connect: getsockname failed: %s(%d)\n",
185
+				strerror(errno), errno);
186
+		si=0; /* try to go on */
187
+	}
188
+	si=find_tcp_si(&my_name);
189
+	if (si==0){
190
+		LOG(L_ERR, "ERROR: tcp_connect: could not find coresponding"
191
+				" listening socket, using default...\n");
192
+		if (server->s.sa_family==AF_INET) si=sendipv4_tcp;
193
+#ifdef USE_IPV6
194
+		else si=sendipv6_tcp;
195
+#endif
196
+	}
197
+	return tcpconn_new(s, server, si); /*FIXME: set sock idx! */
183 198
 error:
184 199
 	return 0;
185 200
 }