Browse code

IP_HACK added for forward_uri

Bogdan-Andrei Iancu authored on 25/01/2002 17:43:18
Showing 2 changed files
... ...
@@ -476,7 +476,6 @@ int t_on_reply_received( struct sip_msg  *p_msg )
476 476
 	return 0;
477 477
 
478 478
 error:
479
-	/* t_unref( p_msg, NULL, NULL ); */
480 479
 	T_UNREF( T );
481 480
 	T->inbound_response[branch]=NULL;
482 481
 	sip_msg_free( clone );
... ...
@@ -554,15 +553,16 @@ int t_on_request_received( struct sip_msg  *p_msg , unsigned int ip , unsigned i
554 553
 
555 554
 int t_on_request_received_uri( struct sip_msg  *p_msg )
556 555
 {
557
-   unsigned int     ip, port;
556
+	unsigned int     ip, port;
558 557
 
559
-   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
560
-   {
561
-      LOG( L_ERR , "ERROR: t_on_request_received_uri: unable to extract ip and port from uri!\n" );
562
-      return -1;
563
-   }
558
+	if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
559
+	{
560
+		LOG( L_ERR , "ERROR: t_on_request_received_uri: \
561
+		    unable to extract ip and port from uri!\n" );
562
+		return -1;
563
+	}
564 564
 
565
-   return t_on_request_received( p_msg , ip , port );
565
+	return t_on_request_received( p_msg , ip , port );
566 566
 }
567 567
 
568 568
 
... ...
@@ -1124,54 +1124,69 @@ void delete_cell( struct cell *p_cell )
1124 1124
 */
1125 1125
 int get_ip_and_port_from_uri( struct sip_msg* p_msg , unsigned int *param_ip, unsigned int *param_port)
1126 1126
 {
1127
-   struct hostent  *nhost;
1128
-   unsigned int     ip, port;
1129
-   struct sip_uri    parsed_uri;
1130
-   str                      uri;
1131
-   int                      err;
1132
-
1133
-   /* the original uri has been changed? */
1134
-   if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
1135
-     uri = p_msg->first_line.u.request.uri;
1136
-   else
1137
-     uri = p_msg->new_uri;
1127
+	struct hostent  *nhost;
1128
+	unsigned int      ip, port;
1129
+	struct sip_uri    parsed_uri;
1130
+	str                      uri;
1131
+	int                      err;
1132
+#ifdef DNS_IP_HACK
1133
+	int                      len;
1134
+#endif
1138 1135
 
1139
-   /* parsing the request uri in order to get host and port */
1140
-   if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
1141
-   {
1142
-        LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: unable to parse destination uri\n");
1143
-        return  -1;
1144
-   }
1136
+	/* the original uri has been changed? */
1137
+	if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
1138
+		uri = p_msg->first_line.u.request.uri;
1139
+	else
1140
+		uri = p_msg->new_uri;
1145 1141
 
1146
-   /* getting host address*/
1147
-   nhost = gethostbyname( parsed_uri.host.s );
1142
+	/* parsing the request uri in order to get host and port */
1143
+	if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
1144
+	{
1145
+		LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: "
1146
+		   "unable to parse destination uri\n");
1147
+		goto error;
1148
+	}
1148 1149
 
1149
-   if ( !nhost )
1150
-   {
1151
-      LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: cannot resolve host\n");
1152
-      return -1;
1153
-   }
1154
-   memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
1150
+	/* getting the port */
1151
+	if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
1152
+		port = SIP_PORT;
1153
+	else{
1154
+		port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
1155
+		if ( err<0 ){
1156
+			LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: "
1157
+			  "converting port from str to int failed; using default SIP port\n");
1158
+			port = SIP_PORT;
1159
+		}
1160
+	}
1161
+	port = htons( port );
1162
+
1163
+	/* getting host address*/
1164
+#ifdef DNS_IP_HACK
1165
+	len=strlen( parsed_uri.host.s );
1166
+	ip=str2ip(parsed_uri.host.s, len, &err);
1167
+	if (err==0)
1168
+		goto success;
1169
+#endif
1170
+	/* fail over to normal lookup */
1171
+	nhost = gethostbyname( parsed_uri.host.s );
1172
+	if ( !nhost )
1173
+	{
1174
+		LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: "
1175
+		  "cannot resolve host\n");
1176
+		goto error;
1177
+	}
1178
+	memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
1155 1179
 
1156
-   /* getting the port */
1157
-   if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
1158
-      port = SIP_PORT;
1159
-   else
1160
-   {
1161
-       port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
1162
-       if ( err<0 )
1163
-       {
1164
-           LOG(L_ERR, "ERROR: get_ip_and_port_from_uri: converting port from str to int failed; using default SIP port\n");
1165
-           port = SIP_PORT;
1166
-       }
1167
-   }
1168
-   port = htons( port );
1169 1180
 
1170
-   free_uri( &parsed_uri );
1181
+success:
1182
+	*param_ip = ip;
1183
+	*param_port = port;
1184
+	return 0;
1171 1185
 
1172
-   *param_ip = ip;
1173
-   *param_port = port;
1174
-   return 0;
1186
+error:
1187
+	*param_ip = 0;
1188
+	*param_port = 0;
1189
+	return -1;
1175 1190
 }
1176 1191
 
1177 1192
 
... ...
@@ -470,8 +470,8 @@ error:
470 470
 
471 471
 
472 472
 
473
-char * build_res_buf_from_sip_res(	struct sip_msg* msg,
474
-									unsigned int *returned_len)
473
+char * build_res_buf_from_sip_res( struct sip_msg* msg,
474
+				unsigned int *returned_len)
475 475
 {
476 476
 	unsigned int new_len, via_len,r;
477 477
 	char* new_buf;
... ...
@@ -480,10 +480,6 @@ char * build_res_buf_from_sip_res(	struct sip_msg* msg,
480 480
 	char* orig;
481 481
 	char* buf;
482 482
 	unsigned int len;
483
-#ifdef DNS_IP_HACK
484
-	int err;
485
-#endif
486
-
487 483
 
488 484
 	orig=msg->orig;
489 485
 	buf=msg->buf;