Browse code

- forward uri now works for secure uris (sips:blbalba) - parse_uri now parses sips uris; lr=something, r2|r2=something added to the parse_uri recognized parameters - resolver now sets the default port properly (5061 for tls, 5060 for others)

Andrei Pelinescu-Onciul authored on 03/07/2003 15:41:07
Showing 6 changed files
... ...
@@ -40,7 +40,7 @@ export makefile_defs
40 40
 VERSION = 0
41 41
 PATCHLEVEL = 8
42 42
 SUBLEVEL =   12
43
-EXTRAVERSION = dev-t03
43
+EXTRAVERSION = dev-t04
44 44
 
45 45
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
46 46
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -163,11 +163,22 @@ int do_action(struct action* a, struct sip_msg* msg)
163 163
 						proto=u->proto;
164 164
 						break;
165 165
 					default:
166
-						LOG(L_ERR,"ERROR: do action: forward: bad uri protocol"
167
-								" %d\n", u->proto);
166
+						LOG(L_ERR,"ERROR: do action: forward: bad uri"
167
+								" transport %d\n", u->proto);
168 168
 						ret=E_BAD_PROTO;
169 169
 						goto error_fwd_uri;
170 170
 				}
171
+#ifdef USE_TLS
172
+				if (u->secure){
173
+					if (u->proto==PROTO_UDP){
174
+						LOG(L_ERR, "ERROR: do_action: forward: secure uri"
175
+								" incompatible with transport %d\n", u->proto);
176
+						ret=E_BAD_PROTO;
177
+						goto error_fwd_uri;
178
+					}
179
+					proto=PROTO_TLS;
180
+				}
181
+#endif
171 182
 				/* create a temporary proxy*/
172 183
 				p=mk_proxy(&u->host, port, proto);
173 184
 				if (p==0){
... ...
@@ -42,7 +42,7 @@
42 42
 #define E_BAD_TUPEL		-9
43 43
 /* script programming error */
44 44
 #define E_SCRIPT		-10
45
-/* error in exceution of external tools */
45
+/* error in excecution of external tools */
46 46
 #define E_EXEC			-11
47 47
 /* too many branches demanded */
48 48
 #define E_TOO_MANY_BRANCHES -12
... ...
@@ -124,6 +124,7 @@ struct sip_uri {
124 124
 	str headers;  
125 125
 	unsigned short port_no;
126 126
 	unsigned short proto; /* from transport */
127
+	int secure; /* 1 if is a sips, 0 otherwise */
127 128
 	/* parameters */
128 129
 	str transport;
129 130
 	str ttl;
... ...
@@ -131,12 +132,15 @@ struct sip_uri {
131 131
 	str maddr;
132 132
 	str method;
133 133
 	str lr;
134
+	str r2; /* ser specific rr parameter */
134 135
 	/* values */
135 136
 	str transport_val;
136 137
 	str ttl_val;
137 138
 	str user_param_val;
138 139
 	str maddr_val;
139 140
 	str method_val;
141
+	str lr_val; /* lr value placeholder for lr=on a.s.o*/
142
+	str r2_val;
140 143
 };
141 144
 
142 145
 
... ...
@@ -32,6 +32,7 @@
32 32
  *              works in one pass) (andrei)
33 33
  * 2003-04-11  ser_error is now set in parse_uri (andrei)
34 34
  * 2003-04-26  ZSW (jiri)
35
+ * 2003-07-03  sips:, r2, lr=on support added (andrei)
35 36
  */
36 37
 
37 38
 
... ...
@@ -67,7 +68,10 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
67 67
 					/* maddr */
68 68
 					      PMA_A, PMA_D, PMA_D2, PMA_R, PMA_eq,
69 69
 					/* lr */
70
-					PLR_L, PLR_R_FIN,
70
+					PLR_L, PLR_R_FIN, PLR_eq,
71
+					/* r2 */
72
+					PR2_R, PR2_2_FIN, PR2_eq,
73
+					
71 74
 					/* transport values */
72 75
 					/* udp */
73 76
 					VU_U, VU_D, VU_P_FIN,
... ...
@@ -312,9 +316,14 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
312 312
 	state=URI_INIT;
313 313
 	memset(uri, 0, sizeof(struct sip_uri)); /* zero it all, just to be sure*/
314 314
 	/*look for sip:*/
315
-	if (len<4) goto error_too_short;
316
-	if (! ( ((buf[0]|0x20)=='s')&&((buf[1]|0x20)=='i')&&((buf[2]|0x20)=='p')&&
317
-		     (buf[3]==':') ) ) goto error_bad_uri;
315
+	if (len<5) goto error_too_short;
316
+	if (! ( ((buf[0]|0x20)=='s')&&((buf[1]|0x20)=='i')&&((buf[2]|0x20)=='p')))
317
+		goto error_bad_uri;
318
+	if (buf[3]!=':'){
319
+		/* parse also sips: */
320
+		if  (((buf[3]|0x20)=='s')&&(buf[4]==':')) {p++; uri->secure=1;}
321
+		else goto error_bad_uri;
322
+	}
318 323
 	
319 324
 	s=p;
320 325
 	for(;p<end; p++){
... ...
@@ -549,13 +558,17 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
549 549
 						b=p;
550 550
 						state=PLR_L;
551 551
 						break;
552
+					case 'r':
553
+					case 'R':
554
+						b=p;
555
+						state=PR2_R;
552 556
 					default:
553 557
 						state=URI_PARAM_P;
554 558
 				}
555 559
 				break;
556 560
 			case URI_PARAM_P: /* ignore current param */
557 561
 				/* supported params:
558
-				 *  maddr, transport, ttl, lr, user, method  */
562
+				 *  maddr, transport, ttl, lr, user, method, r2  */
559 563
 				switch(*p){
560 564
 					param_common_cases;
561 565
 				};
... ...
@@ -691,6 +704,9 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
691 691
 					case '@':
692 692
 						still_at_user; 
693 693
 						break;
694
+					case '=':
695
+						state=PLR_eq;
696
+						break;
694 697
 					semicolon_case; 
695 698
 						uri->lr.s=b;
696 699
 						uri->lr.len=(p-b);
... ...
@@ -705,7 +721,52 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
705 705
 						state=URI_PARAM_P;
706 706
 				}
707 707
 				break;
708
-						
708
+				/* handle lr=something case */
709
+			case PLR_eq:
710
+				param=&uri->lr;
711
+				param_val=&uri->lr_val;
712
+				switch(*p){
713
+					param_common_cases;
714
+					default:
715
+						v=p;
716
+						state=URI_VAL_P;
717
+				}
718
+				break;
719
+			/* r2 */
720
+			param_switch1(PR2_R,  '2', PR2_2_FIN);
721
+			case PR2_2_FIN:
722
+				switch(*p){
723
+					case '@':
724
+						still_at_user; 
725
+						break;
726
+					case '=':
727
+						state=PR2_eq;
728
+						break;
729
+					semicolon_case; 
730
+						uri->r2.s=b;
731
+						uri->r2.len=(p-b);
732
+						break;
733
+					question_case; 
734
+						uri->r2.s=b;
735
+						uri->r2.len=(p-b);
736
+						break;
737
+					colon_case;
738
+						break;
739
+					default:
740
+						state=URI_PARAM_P;
741
+				}
742
+				break;
743
+				/* handle lr=something case */
744
+			case PR2_eq:
745
+				param=&uri->r2;
746
+				param_val=&uri->r2_val;
747
+				switch(*p){
748
+					param_common_cases;
749
+					default:
750
+						v=p;
751
+						state=URI_VAL_P;
752
+				}
753
+				break;
709 754
 				
710 755
 				
711 756
 			case URI_HEADERS:
... ...
@@ -814,16 +875,25 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
814 814
 		case PM_D:
815 815
 		case PM_eq:
816 816
 		case PLR_L: /* lr */
817
+		case PR2_R:  /* r2 */
817 818
 			uri->params.s=s;
818 819
 			uri->params.len=p-s;
819 820
 			break;
820 821
 		/* fin param states */
821 822
 		case PLR_R_FIN:
823
+		case PLR_eq:
822 824
 			uri->params.s=s;
823 825
 			uri->params.len=p-s;
824 826
 			uri->lr.s=b;
825 827
 			uri->lr.len=p-b;
826 828
 			break;
829
+		case PR2_2_FIN:
830
+		case PR2_eq:
831
+			uri->params.s=s;
832
+			uri->params.len=p-s;
833
+			uri->r2.s=b;
834
+			uri->r2.len=p-b;
835
+			break;
827 836
 		case URI_VAL_P:
828 837
 		/* intermediate value states */
829 838
 		case VU_U:
... ...
@@ -28,6 +28,7 @@
28 28
  * History:
29 29
  * -------
30 30
  *  2003-02-13  added proto to sip_resolvehost, for SRV lookups (andrei)
31
+ *  2003-07-03  default port value set according to proto (andrei)
31 32
  */ 
32 33
 
33 34
 
... ...
@@ -469,7 +470,8 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto)
469 469
 
470 470
 	/* try SRV if no port specified (draft-ietf-sip-srv-06) */
471 471
 	if ((port)&&(*port==0)){
472
-		*port=SIP_PORT; /* just in case we don't find another */
472
+		*port=(proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case we don't
473
+														find another */
473 474
 		if ((name->len+SRV_PREFIX_LEN+1)>MAX_DNS_NAME){
474 475
 			LOG(L_WARN, "WARNING: sip_resolvehost: domain name too long (%d),"
475 476
 						" unable to perform SRV lookup\n", name->len);