Browse code

- more tls add-ons (via parser, srv lookup, forward_tls a.s.o) - fixed inivite1.sip content-length

Andrei Pelinescu-Onciul authored on 02/07/2003 20:26:49
Showing 10 changed files
... ...
@@ -106,6 +106,9 @@ int do_action(struct action* a, struct sip_msg* msg)
106 106
 #ifdef USE_TCP
107 107
 		case FORWARD_TCP_T:
108 108
 #endif
109
+#ifdef USE_TLS
110
+		case FORWARD_TLS_T:
111
+#endif
109 112
 		case FORWARD_UDP_T:
110 113
 
111 114
 			if (a->type==FORWARD_UDP_T) proto=PROTO_UDP;
... ...
@@ -106,6 +106,7 @@
106 106
 
107 107
 #define SRV_UDP_PREFIX "_sip._udp."
108 108
 #define SRV_TCP_PREFIX "_sip._tcp."
109
+#define SRV_TLS_PREFIX "_sip._tls."
109 110
 #define SRV_PREFIX_LEN 10
110 111
 
111 112
 /*used only if PKG_MALLOC is defined*/
... ...
@@ -64,6 +64,9 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
64 64
 #ifdef USE_TCP
65 65
                                case PROTO_TCP:
66 66
 #endif
67
+#ifdef USE_TLS
68
+                               case PROTO_TLS:
69
+#endif
67 70
                                        return u->proto;
68 71
                                default:
69 72
                                        LOG(L_ERR, "ERROR: get_proto: unsupported transport: %d\n",
... ...
@@ -74,6 +77,9 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
74 74
 #ifdef USE_TCP
75 75
                case PROTO_TCP:
76 76
 #endif
77
+#ifdef USE_TLS
78
+               case PROTO_TLS:
79
+#endif
77 80
                        return force_proto;
78 81
                default:
79 82
                        LOG(L_ERR, "ERROR: get_proto: unsupported forced protocol: "
... ...
@@ -1174,6 +1174,8 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1174 1174
 							" id_builder failed\n");
1175 1175
 			goto error01; /* free everything */
1176 1176
 		}
1177
+		DBG("build_req_from_req: id added: <%.*s>, rcv proto=%d\n",
1178
+				id_len, id_buf, msg->rcv.proto);
1177 1179
 		extra_params.s=id_buf;
1178 1180
 		extra_params.len=id_len;
1179 1181
 	}
... ...
@@ -1183,6 +1185,8 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1183 1183
 			|| proto==PROTO_TLS
1184 1184
 #endif
1185 1185
 			){
1186
+		DBG("build_req_from_req: checking for clen; proto=%d, rcv->proto=%d\n",
1187
+				proto, msg->rcv.proto);
1186 1188
 		/* first of all parse content-length */
1187 1189
 		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
1188 1190
 			LOG(L_ERR, "build_req_buf_from_sip_req:"
... ...
@@ -1885,7 +1889,7 @@ char* via_builder( unsigned int *len,
1885 1885
 	}else if (proto==PROTO_TCP){
1886 1886
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
1887 1887
 	}else if (proto==PROTO_TLS){
1888
-		memcpy(line_buf+MY_VIA_LEN-4, "TLS", 4);
1888
+		memcpy(line_buf+MY_VIA_LEN-4, "TLS ", 4);
1889 1889
 	}else{
1890 1890
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
1891 1891
 		return 0;
... ...
@@ -43,6 +43,7 @@
43 43
  *  2003-02-28  scratchpad compatibility abandoned (jiri)
44 44
  *  2003-04-26  ZSW (jiri)
45 45
  *  2003-06-23  fixed  parse_via_param [op].* param. parsing bug (andrei)
46
+ *  2003-07-02  added support for TLS parsing in via (andrei)
46 47
  */
47 48
 
48 49
 
... ...
@@ -81,7 +82,8 @@ enum {
81 81
 	L_VER, F_VER,
82 82
 	VER1, VER2, FIN_VER,
83 83
 	UDP1, UDP2, FIN_UDP,
84
-	TCP1, TCP2, FIN_TCP,
84
+	TCP_TLS1, TCP2, FIN_TCP,
85
+	          TLS2, FIN_TLS,
85 86
 	L_PROTO, F_PROTO
86 87
 };
87 88
 
... ...
@@ -985,6 +987,12 @@ parse_again:
985 985
 						vb->proto=PROTO_TCP;
986 986
 						state=F_HOST; /* start looking for host*/
987 987
 						goto main_via;
988
+					case FIN_TLS:
989
+						/* finished proto parsing */
990
+						vb->transport.len=tmp-vb->transport.s;
991
+						vb->proto=PROTO_TLS;
992
+						state=F_HOST; /* start looking for host*/
993
+						goto main_via;
988 994
 					case FIN_SIP:
989 995
 						vb->name.len=tmp-vb->name.s;
990 996
 						state=L_VER;
... ...
@@ -1026,6 +1034,12 @@ parse_again:
1026 1026
 						state=F_LF;
1027 1027
 						saved_state=F_HOST; /* start looking for host*/
1028 1028
 						goto main_via;
1029
+					case FIN_TLS:
1030
+						vb->transport.len=tmp-vb->transport.s;
1031
+						vb->proto=PROTO_TLS;
1032
+						state=F_LF;
1033
+						saved_state=F_HOST; /* start looking for host*/
1034
+						goto main_via;
1029 1035
 					case FIN_SIP:
1030 1036
 						vb->name.len=tmp-vb->name.s;
1031 1037
 						state=F_LF;
... ...
@@ -1071,6 +1085,12 @@ parse_again:
1071 1071
 						state=F_CR;
1072 1072
 						saved_state=F_HOST;
1073 1073
 						goto main_via;
1074
+					case FIN_TLS:
1075
+						vb->transport.len=tmp-vb->transport.s;
1076
+						vb->proto=PROTO_TLS;
1077
+						state=F_CR;
1078
+						saved_state=F_HOST;
1079
+						goto main_via;
1074 1080
 					case FIN_SIP:
1075 1081
 						vb->name.len=tmp-vb->name.s;
1076 1082
 						state=F_CR;
... ...
@@ -1123,6 +1143,9 @@ parse_again:
1123 1123
 						state=SIP1;
1124 1124
 						vb->name.s=tmp;
1125 1125
 						break;
1126
+					case TLS2:
1127
+						state=FIN_TLS;
1128
+						break;
1126 1129
 					default:
1127 1130
 						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1128 1131
 								" state %d\n", *tmp, state);
... ...
@@ -1189,7 +1212,7 @@ parse_again:
1189 1189
 			case 't':
1190 1190
 				switch(state){
1191 1191
 					case F_PROTO:
1192
-						state=TCP1;
1192
+						state=TCP_TLS1;
1193 1193
 						vb->transport.s=tmp;
1194 1194
 						break;
1195 1195
 					default:
... ...
@@ -1201,7 +1224,7 @@ parse_again:
1201 1201
 			case 'C':
1202 1202
 			case 'c':
1203 1203
 				switch(state){
1204
-					case TCP1:
1204
+					case TCP_TLS1:
1205 1205
 						state=TCP2;
1206 1206
 						break;
1207 1207
 					default:
... ...
@@ -1210,6 +1233,18 @@ parse_again:
1210 1210
 						goto error;
1211 1211
 				}
1212 1212
 				break;
1213
+			case 'L':
1214
+			case 'l':
1215
+				switch(state){
1216
+					case TCP_TLS1:
1217
+						state=TLS2;
1218
+						break;
1219
+					default:
1220
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1221
+								" state %d\n", *tmp, state);
1222
+						goto error;
1223
+				}
1224
+				break;
1213 1225
 			/*match 2.0*/
1214 1226
 			case '2':
1215 1227
 				switch(state){
... ...
@@ -497,6 +497,11 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto)
497 497
 					memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
498 498
 					tmp[SRV_PREFIX_LEN + name->len] = '\0';
499 499
 					break;
500
+				case PROTO_TLS:
501
+					memcpy(tmp, SRV_TLS_PREFIX, SRV_PREFIX_LEN);
502
+					memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
503
+					tmp[SRV_PREFIX_LEN + name->len] = '\0';
504
+					break;
500 505
 				default:
501 506
 					LOG(L_CRIT, "BUG: sip_resolvehost: unknown proto %d\n",
502 507
 							proto);
... ...
@@ -158,6 +158,7 @@ static int fix_actions(struct action* a)
158 158
 	for(t=a; t!=0; t=t->next){
159 159
 		switch(t->type){
160 160
 			case FORWARD_T:
161
+			case FORWARD_TLS_T:
161 162
 			case FORWARD_TCP_T:
162 163
 			case FORWARD_UDP_T:
163 164
 			case SEND_T:
... ...
@@ -141,7 +141,6 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
141 141
 	c->refcnt=0;
142 142
 	su2ip_addr(&c->rcv.src_ip, su);
143 143
 	c->rcv.src_port=su_getport(su);
144
-	c->rcv.proto=PROTO_TCP;
145 144
 	c->rcv.bind_address=ba;
146 145
 	if (ba){
147 146
 		c->rcv.dst_ip=ba->address;
... ...
@@ -793,7 +792,7 @@ void tcp_main_loop()
793 793
 		/* start from 1, the "main" process does not transmit anything*/
794 794
 		for (r=1; r<process_no && n; r++){
795 795
 			if ( (pt[r].unix_sock>0) && FD_ISSET(pt[r].unix_sock, &sel_set)){
796
-				/* (we can't have a fd==0, 0 i s never closed )*/
796
+				/* (we can't have a fd==0, 0 is never closed )*/
797 797
 				n--;
798 798
 				/* errno==EINTR !!! TODO*/
799 799
 read_again:
... ...
@@ -399,14 +399,14 @@ int tcp_read_req(struct tcp_connection* con)
399 399
 #ifdef USE_TLS
400 400
 		if (con->type==PROTO_TLS){
401 401
 			if (con->state==S_CONN_ACCEPT){
402
-				if (tls_accept(con)!=0){
402
+				if (tls_accept(con, 0)!=0){
403 403
 					resp=CONN_ERROR;
404 404
 					goto end_req;
405 405
 				}
406 406
 				if(con->state!=S_CONN_OK) goto end_req; /* not enough data */
407 407
 			}
408 408
 			if(con->state==S_CONN_CONNECT){
409
-				if (tls_connect(con)!=0){
409
+				if (tls_connect(con, 0)!=0){
410 410
 					resp=CONN_ERROR;
411 411
 					goto end_req;
412 412
 				}
... ...
@@ -1,4 +1,4 @@
1
-INVITE sip:p2@195.37.78.126 SIP/2.0
1
+INVITE sip:p2@iptel.org SIP/2.0
2 2
 Via: SIP/2.0/UDP 192.168.99.100:5040
3 3
 From: "GMD FOKUS iptlab" <sip:jiri@iptel.org>;tag=b96b0300ed30f1286-2f5d
4 4
 Call-ID: b96b0300-88d30f-66da-63aa@195.37.78.190
... ...
@@ -9,7 +9,7 @@ User-Agent: Cisco-SIP-IP-Phone/2
9 9
 Accept: application/sdp
10 10
 Contact: sip:jiri@195.37.78.190:5060
11 11
 Content-Type: application/sdp
12
-Content-Length: 225
12
+Content-Length: 218
13 13
 
14 14
 
15 15
 v=0