Browse Source

parse_uri cleanup:
- It does no create copy of strings anymore
- Fields are not zero terminated
- Prototype of some low-level functions changed to accept str* instead of char*,
that includes: mk_proxy, sip_resolvehost, str2ip, str2ip6, ip_addr2he
- All modules updated (hopefully)

Jan Janak 23 năm trước cách đây
mục cha
commit
a6982b85d8
11 tập tin đã thay đổi với 116 bổ sung189 xóa
  1. 21 25
      action.c
  2. 5 20
      forward.c
  3. 2 3
      ip_addr.h
  4. 0 1
      parser/msg_parser.c
  5. 18 83
      parser/parse_uri.c
  6. 0 2
      parser/parse_uri.h
  7. 6 6
      proxy.c
  8. 4 3
      proxy.h
  9. 19 15
      resolve.c
  10. 37 30
      resolve.h
  11. 4 1
      route.c

+ 21 - 25
action.c

@@ -125,7 +125,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 							goto error_fwd_uri;
 				}
 				/* create a temporary proxy*/
-				p=mk_proxy(u->host.s, port);
+				p=mk_proxy(&u->host, port);
 				if (p==0){
 					LOG(L_ERR, "ERROR:  bad host name in uri,"
 							" dropping packet\n");
@@ -329,10 +329,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				pkg_free(msg->new_uri.s);
 				msg->new_uri.len=0;
 				msg->new_uri.s=0;
-				if (msg->parsed_uri_ok){
-					msg->parsed_uri_ok=0; /* invalidate current parsed uri*/
-					free_uri(&msg->parsed_uri);
-				}
+				msg->parsed_uri_ok=0; /* invalidate current parsed uri*/
 			};
 			ret=1;
 			break;
@@ -362,10 +359,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 							pkg_free(msg->new_uri.s);
 							msg->new_uri.len=0;
 					}
-					if (msg->parsed_uri_ok){
-							msg->parsed_uri_ok=0;
-							free_uri(&msg->parsed_uri);
-					}
+					msg->parsed_uri_ok=0;
 					len=strlen(a->p1.string);
 					msg->new_uri.s=pkg_malloc(len+1);
 					if (msg->new_uri.s==0){
@@ -400,7 +394,6 @@ int do_action(struct action* a, struct sip_msg* msg)
 					LOG(L_ERR, "ERROR: do_action: memory allocation "
 								" failure\n");
 					ret=E_OUT_OF_MEM;
-					free_uri(&uri);
 					break;
 				}
 				end=new_uri+MAX_URI_SIZE;
@@ -426,7 +419,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				} else if (a->type==STRIP_T) {
 					if (a->p1.number>uri.user.len) {
 						LOG(L_WARN, "Error: too long strip asked; deleting username: "
-							"%d of %s\n", a->p1.number, uri.user.s );
+							"%d of <%.*s>\n", a->p1.number, uri.user.len, uri.user.s );
 						len=0;
 					} else if (a->p1.number==uri.user.len) {
 						len=0;
@@ -451,7 +444,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					memcpy(crt,":",len);crt+=len;
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
+					len=uri.passwd.len; if(crt+len>end) goto error_uri;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				/* host */
@@ -459,18 +452,26 @@ int do_action(struct action* a, struct sip_msg* msg)
 					len=strlen("@"); if(crt+len>end) goto error_uri;
 					memcpy(crt,"@",len);crt+=len;
 				}
-				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T))
+				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) {
 					tmp=a->p1.string;
-				else
+					if (tmp) len = strlen(tmp);
+				} else {
 					tmp=uri.host.s;
+					len = uri.host.len;
+				}
 				if (tmp){
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
+					if(crt+len>end) goto error_uri;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				/* port */
 				if (a->type==SET_HOSTPORT_T) tmp=0;
-				else if (a->type==SET_PORT_T) tmp=a->p1.string;
-				else tmp=uri.port.s;
+				else if (a->type==SET_PORT_T) {
+					tmp=a->p1.string;
+					if (tmp) len = strlen(tmp);
+				} else {
+					tmp=uri.port.s;
+					len = uri.port.len;
+				}
 				if (tmp){
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					memcpy(crt,":",len);crt+=len;
@@ -482,7 +483,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 					len=strlen(";"); if(crt+len>end) goto error_uri;
 					memcpy(crt,";",len);crt+=len;
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
+					len=uri.params.len; if(crt+len>end) goto error_uri;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				/* headers */
@@ -490,7 +491,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 					len=strlen("?"); if(crt+len>end) goto error_uri;
 					memcpy(crt,"?",len);crt+=len;
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
+					len=uri.headers.len; if(crt+len>end) goto error_uri;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				*crt=0; /* null terminate the thing */
@@ -498,11 +499,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (msg->new_uri.s) pkg_free(msg->new_uri.s);
 				msg->new_uri.s=new_uri;
 				msg->new_uri.len=crt-new_uri;
-				if (msg->parsed_uri_ok){
-					msg->parsed_uri_ok=0;
-					free_uri(&msg->parsed_uri);
-				}
-				free_uri(&uri);
+				msg->parsed_uri_ok=0;
 				ret=1;
 				break;
 		case IF_T:
@@ -546,7 +543,6 @@ int do_action(struct action* a, struct sip_msg* msg)
 	
 error_uri:
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
-	free_uri(&uri);
 	if (new_uri) free(new_uri);
 	return E_UNSPEC;
 error_fwd_uri:

+ 5 - 20
forward.c

@@ -289,7 +289,6 @@ int update_sock_struct_from_via( union sockaddr_union* to,
 								 struct via_body* via )
 {
 	struct hostent* he;
-	char *host_copy;
 	str* name;
 	unsigned short port;
 
@@ -311,28 +310,14 @@ int update_sock_struct_from_via( union sockaddr_union* to,
 	   (host.s[len] will always be ok for a via)
 	    BTW: when is via->host.s non null terminated? tm copy? - andrei 
 	    Yes -- it happened on generating a 408 by TM; -jiri
+	    sip_resolvehost now accepts str -janakj
 	*/
-	if (name->s[name->len]){
-		host_copy=pkg_malloc( name->len+1 );
-		if (!host_copy) {
-			LOG(L_NOTICE, "ERROR: update_sock_struct_from_via:"
-							" not enough memory\n");
-			return -1;
-		}
-		memcpy(host_copy, name->s, name->len );
-		host_copy[name->len]=0;
-		DBG("update_sock_struct_from_via: trying SRV lookup\n");
-		he=sip_resolvehost(host_copy, &port);
-		
-		pkg_free( host_copy );
-	}else{
-		DBG("update_sock_struct_from_via: trying SRV lookup\n");
-		he=sip_resolvehost(name->s, &port);
-	}
+	DBG("update_sock_struct_from_via: trying SRV lookup\n");
+	he=sip_resolvehost(name, &port);
 	
 	if (he==0){
-		LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%s) failure\n",
-				name->s);
+		LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%.*s) failure\n",
+				name->len, name->s);
 		return -1;
 	}
 	hostent2su(to, he, 0, htons(port));

+ 2 - 3
ip_addr.h

@@ -475,8 +475,7 @@ static inline char* ip_addr2a(struct ip_addr* ip)
 
 /* converts an ip_addr structure to a hostent, returns pointer to internal
  * statical structure */
-static inline struct hostent* ip_addr2he(char* name, int len,
-											struct ip_addr* ip)
+static inline struct hostent* ip_addr2he(str* name, struct ip_addr* ip)
 {
 	static struct hostent he;
 	static char hostname[256];
@@ -487,7 +486,7 @@ static inline struct hostent* ip_addr2he(char* name, int len,
 	p_aliases[0]=0; /* no aliases*/
 	p_addr[1]=0; /* only one address*/
 	p_addr[0]=address;
-	strncpy(hostname, name, (len<256)?len+1:256);
+	strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256);
 	if (ip->len>16) return 0;
 	memcpy(address, ip->u.addr, ip->len);
 	

+ 0 - 1
parser/msg_parser.c

@@ -511,7 +511,6 @@ void free_sip_msg(struct sip_msg* msg)
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
-	if (msg->parsed_uri_ok) free_uri(&msg->parsed_uri);
 	pkg_free(msg->orig);
 	/* don't free anymore -- now a pointer to a static buffer */
 #	ifdef DYN_BUF

+ 18 - 83
parser/parse_uri.c

@@ -27,7 +27,6 @@
 
 
 #include "parse_uri.h"
-#include "../mem/mem.h"
 #include <string.h>
 #include "../dprint.h"
 #include "../ut.h"    /* q_memchr */
@@ -52,16 +51,16 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 	memset(uri, 0, sizeof(struct sip_uri)); /* zero it all, just to be sure */
 	/* look for "sip:"*/;
 	next=q_memchr(buf, ':',  len);
-	if ((next==0)||(strncmp(buf,"sip",next-buf)!=0)){
+	if ((next==0)||(strncasecmp(buf,"sip",next-buf)!=0)){
 		LOG(L_DBG, "ERROR: parse_uri: bad sip uri\n");
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
 	buf=next+1; /* next char after ':' */
 	if (buf>end){
 		LOG(L_DBG, "ERROR: parse_uri: uri too short\n");
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
 	/*look for '@' */
 	next=q_memchr(buf,'@', end-buf);
@@ -78,36 +77,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 		if (passwd==0){
 			/* no ':' found => no password */
 			uri->passwd.s=0;
-			uri->user.s=(char*)pkg_malloc(next-user+1);
-			if (uri->user.s==0){
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
-				ser_error=ret=E_OUT_OF_MEM;
-				goto error;
-			}
-			memcpy(uri->user.s, user, next-user);
+			uri->user.s=user;
 			uri->user.len=next-user;
-			uri->user.s[next-user]=0; /* null terminate it, 
-									   usefull for easy printing*/
 		}else{
-			uri->user.s=(char*)pkg_malloc(passwd-user+1);
-			if (uri->user.s==0){
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
-				ser_error=ret=E_OUT_OF_MEM;
-				goto error;
-			}
-			memcpy(uri->user.s, user, passwd-user);
+			uri->user.s=user;
 			uri->user.len=passwd-user;
-			uri->user.s[passwd-user]=0;
 			passwd++; /*skip ':' */
-			uri->passwd.s=(char*)pkg_malloc(next-passwd+1);
-			if (uri->passwd.s==0){
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
-				ser_error=ret=E_OUT_OF_MEM;
-				goto error;
-			}
-			memcpy(uri->passwd.s, passwd, next-passwd);
+			uri->passwd.s=passwd;
 			uri->passwd.len=next-passwd;
-			uri->passwd.s[next-passwd]=0;
 		}
 		host=next+1; /* skip '@' */
 	}
@@ -115,7 +92,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 	if(host>=end){
 		LOG(L_DBG, "ERROR: parse_uri: missing hostport\n");
 		ser_error=ret=E_UNSPEC;
-		goto error;
+		return ret;
 	}
 	next=host;
 	ipv6=q_memchr(host, '[', end-host);
@@ -124,14 +101,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 		if (host>=end){
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri\n");
 			ret=E_UNSPEC;
-			goto error;
+			return ret;
 		}
 		ipv6=q_memchr(host, ']', end-host);
 		if ((ipv6==0)||(ipv6==host)){
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri - null address"
 					" or missing ']'\n");
 			ret=E_UNSPEC;
-			goto error;
+			return ret;
 		}
 		host_len=ipv6-host;
 		next=ipv6;
@@ -146,15 +123,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 				end-host;
 	}
 	/* get host */
-	uri->host.s=pkg_malloc(host_len+1);
-	if (uri->host.s==0){
-		LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
-		ret=E_OUT_OF_MEM;
-		goto error;
-	}
-	memcpy(uri->host.s, host, host_len);
+	uri->host.s=host;
 	uri->host.len=host_len;
-	uri->host.s[host_len]=0;
+
 	/* get port*/
 	if ((port)&&(port+1<end)){
 		port++;
@@ -162,18 +133,11 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 			/* error -> invalid uri we found ';' or '?' before ':' */
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			ser_error=ret=E_BAD_URI;
-			goto error;
+			return ret;
 		}
 		port_len=(params)?params-port:(headers)?headers-port:end-port;
-		uri->port.s=pkg_malloc(port_len+1);
-		if (uri->port.s==0){
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
-			ser_error=ret=E_OUT_OF_MEM;
-			goto error;
-		}
-		memcpy(uri->port.s, port, port_len);
+		uri->port.s=port;
 		uri->port.len=port_len;
-		uri->port.s[port_len]=0;
 	}else uri->port.s=0;
 	/* get params */
 	if ((params)&&(params+1<end)){
@@ -182,32 +146,18 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 			/* error -> invalid uri we found '?' or '?' before ';' */
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			ser_error=ret=E_BAD_URI;
-			goto error;
+			return ret;
 		}
 		params_len=(headers)?headers-params:end-params;
-		uri->params.s=pkg_malloc(params_len+1);
-		if (uri->params.s==0){
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
-			ser_error=ret=E_OUT_OF_MEM;
-			goto error;
-		}
-		memcpy(uri->params.s, params, params_len);
+		uri->params.s=params;
 		uri->params.len=params_len;
-		uri->params.s[params_len]=0;
 	}else uri->params.s=0;
 	/*get headers */
 	if ((headers)&&(headers+1<end)){
 		headers++;
 		headers_len=end-headers;
-		uri->headers.s=pkg_malloc(headers_len+1);
-		if(uri->headers.s==0){
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
-			ser_error=ret=E_OUT_OF_MEM;
-			goto error;
-		}
-		memcpy(uri->headers.s, headers, headers_len);
+		uri->headers.s=headers;
 		uri->headers.len=headers_len;
-		uri->headers.s[headers_len]=0;
 	}else uri->headers.s=0;
 
 	err=0;
@@ -216,11 +166,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n",
 				uri->port.s);
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
-	return ret;
-error:
-	free_uri(uri);
+
 	return ret;
 }
 
@@ -250,16 +198,3 @@ int parse_sip_msg_uri(struct sip_msg* msg)
 	}
 }
 
-
-
-void free_uri(struct sip_uri* u)
-{
-	if (u) {
-		if (u->user.s)    pkg_free(u->user.s);
-		if (u->passwd.s)  pkg_free(u->passwd.s);
-		if (u->host.s)    pkg_free(u->host.s);
-		if (u->port.s)    pkg_free(u->port.s);
-		if (u->params.s)  pkg_free(u->params.s);
-		if (u->headers.s) pkg_free(u->headers.s);
-	}
-}

+ 0 - 2
parser/parse_uri.h

@@ -46,6 +46,4 @@
 int parse_uri(char *buf, int len, struct sip_uri* uri);
 int parse_sip_msg_uri(struct sip_msg* msg);
 
-void free_uri(struct sip_uri* u);
-
 #endif /* PARSE_URI_H */

+ 6 - 6
proxy.c

@@ -57,11 +57,11 @@ struct proxy_l* proxies=0;
 
 /* searches for the proxy named 'name', on port 'port'
    returns: pointer to proxy_l on success or 0 if not found */ 
-static struct proxy_l* find_proxy(char *name, unsigned short port)
+static struct proxy_l* find_proxy(str *name, unsigned short port)
 {
 	struct proxy_l* t;
 	for(t=proxies; t; t=t->next)
-		if ((strcasecmp(t->name, name)==0) && (t->port==port))
+		if (((t->name.len == name->len) && (strncasecmp(t->name.s, name->s, name->len)==0)) && (t->port==port))
 			break;
 	return t;
 }
@@ -169,7 +169,7 @@ void free_hostent(struct hostent *dst)
 
 
 
-struct proxy_l* add_proxy(char* name, unsigned short port)
+struct proxy_l* add_proxy(str* name, unsigned short port)
 {
 	struct proxy_l* p;
 	
@@ -190,7 +190,7 @@ error:
 /* same as add_proxy, but it doesn't add the proxy to the list
  * uses also SRV if possible (quick hack) */
 
-struct proxy_l* mk_proxy(char* name, unsigned short port)
+struct proxy_l* mk_proxy(str* name, unsigned short port)
 {
 	struct proxy_l* p;
 	struct hostent* he;
@@ -202,7 +202,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
 		goto error;
 	}
 	memset(p,0,sizeof(struct proxy_l));
-	p->name=name;
+	p->name=*name;
 	p->port=port;
 
 	DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
@@ -210,7 +210,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
 	if (he==0){
 		ser_error=E_BAD_ADDRESS;
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
-					" \"%s\"\n", name);
+					" \"%.*s\"\n", name->len, name->s);
 		free(p);
 		goto error;
 	}

+ 4 - 3
proxy.h

@@ -32,10 +32,11 @@
 
 #include <netdb.h>
 #include "ip_addr.h"
+#include "str.h"
 
 struct proxy_l{
 	struct proxy_l* next;
-	char* name; /* original name */
+	str name; /* original name */
 	struct hostent host; /* addresses */
 	unsigned short port;
 	unsigned short reserved; /*align*/
@@ -52,8 +53,8 @@ struct proxy_l{
 
 extern struct proxy_l* proxies;
 
-struct proxy_l* add_proxy(char* name, unsigned short port);
-struct proxy_l* mk_proxy(char* name, unsigned short port);
+struct proxy_l* add_proxy(str* name, unsigned short port);
+struct proxy_l* mk_proxy(str* name, unsigned short port);
 struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port);
 void free_proxy(struct proxy_l* p);
 

+ 19 - 15
resolve.c

@@ -451,7 +451,7 @@ not_found:
  * returns: hostent struct & *port filled with the port from the SRV record;
  *  0 on error
  */
-struct hostent* sip_resolvehost(char* name, unsigned short* port)
+struct hostent* sip_resolvehost(str* name, unsigned short* port)
 {
 	struct hostent* he;
 	struct rdata* head;
@@ -459,29 +459,28 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
 	struct srv_rdata* srv;
 	struct ip_addr* ip;
 	static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups */
-	int len;
 
 	/* try SRV if no port specified (draft-ietf-sip-srv-06) */
 	if ((port)&&(*port==0)){
 		*port=SIP_PORT; /* just in case we don't find another */
-		len=strlen(name);
-		if ((len+SRV_PREFIX_LEN+1)>MAX_DNS_NAME){
+		if ((name->len+SRV_PREFIX_LEN+1)>MAX_DNS_NAME){
 			LOG(L_WARN, "WARNING: sip_resolvehost: domain name too long (%d),"
-						" unable to perform SRV lookup\n", len);
+						" unable to perform SRV lookup\n", name->len);
 		}else{
 			/* check if it's an ip address */
-			if ( ((ip=str2ip((unsigned char*)name, len))!=0)
+			if ( ((ip=str2ip(name))!=0)
 #ifdef	USE_IPV6
-				  || ((ip=str2ip6((unsigned char*)name, len))!=0)
+				  || ((ip=str2ip6(name))!=0)
 #endif
 				){
 				/* we are lucky, this is an ip address */
-				return ip_addr2he(name,len,ip);
+				return ip_addr2he(name,ip);
 			}
 			
 			memcpy(tmp, SRV_PREFIX, SRV_PREFIX_LEN);
-			memcpy(tmp+SRV_PREFIX_LEN, name, len+1); /*include the ending 0*/
-			
+			memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
+			tmp[SRV_PREFIX_LEN + name->len] = '\0';
+
 			head=get_record(tmp, T_SRV);
 			for(l=head; l; l=l->next){
 				if (l->type!=T_SRV) continue; /*should never happen*/
@@ -501,12 +500,17 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
 					return he;
 				}
 			}
-			DBG("sip_resolvehost: not SRV record found for %s," 
-					" trying 'normal' lookup...\n", name);
+			DBG("sip_resolvehost: not SRV record found for %.*s," 
+					" trying 'normal' lookup...\n", name->len, name->s);
 		}
 	}
-	he=resolvehost(name);
+
+	if (name->len >= MAX_DNS_NAME) {
+		LOG(L_ERR, "sip_resolvehost: domain name too long\n");
+		return 0;
+	}
+	memcpy(tmp, name->s, name->len);
+	tmp[name->len] = '\0';
+	he=resolvehost(tmp);
 	return he;
 }
-
-

+ 37 - 30
resolve.h

@@ -127,25 +127,26 @@ void free_rdata_list(struct rdata* head);
 
 /* converts a str to an ipv4 address, returns the address or 0 on error
    Warning: the result is a pointer to a statically allocated structure */
-static inline struct ip_addr* str2ip(unsigned char* str, unsigned int len)
+static inline struct ip_addr* str2ip(str* st)
 {
 	int i;
 	unsigned char *limit;
-	unsigned char *init;
 	static struct ip_addr ip;
+	unsigned char* s;
+
+	s = st->s;
 
 	/*init*/
 	ip.u.addr32[0]=0;
 	i=0;
-	limit=str+len;
-	init=str;
+	limit=st->s + st->len;
 
-	for(;str<limit ;str++){
-		if (*str=='.'){
+	for(;s<limit ;s++){
+		if (*s=='.'){
 				i++;
 				if (i>3) goto error_dots;
-		}else if ( (*str <= '9' ) && (*str >= '0') ){
-				ip.u.addr[i]=ip.u.addr[i]*10+*str-'0';
+		}else if ( (*s <= '9' ) && (*s >= '0') ){
+				ip.u.addr[i]=ip.u.addr[i]*10+*s-'0';
 		}else{
 				//error unknown char
 				goto error_char;
@@ -156,11 +157,15 @@ static inline struct ip_addr* str2ip(unsigned char* str, unsigned int len)
 	
 	return &ip;
 
+
+	     /* FIXME: janakj - is this correct ?, we return always 0 here 
+	      * Also we could use different loglevels here
+	      */
 error_dots:
-	DBG("str2ip: ERROR: too many dots in [%.*s]\n", (int)len, init);
+	DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s);
 	return 0;
-error_char:
-	DBG("str2ip: WARNING: unexpected char %c in %.*s\n", *str,(int)len, init);
+ error_char:
+	DBG("str2ip: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, st->s);
 	return 0;
 }
 
@@ -168,7 +173,7 @@ error_char:
 
 /* returns an ip_addr struct.; on error returns 0
  * the ip_addr struct is static, so subsequent calls will destroy its content*/
-static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
+static inline struct ip_addr* str2ip6(str* st)
 {
 	int i, idx1, rest;
 	int no_colons;
@@ -179,10 +184,10 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 	unsigned short addr_end[8];
 	unsigned short* addr;
 	unsigned char* limit;
-	unsigned char* init;
+	unsigned char* s;
 	
 	/* init */
-	init=str;
+	s=st->s;
 	i=idx1=rest=0;
 	double_colon=0;
 	no_colons=0;
@@ -190,11 +195,11 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 	ip.len=16;
 	addr_start=ip.u.addr16;
 	addr=addr_start;
-	limit=str+len;
+	limit=st->s+st->len;
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
-	for (; str<limit; str++){
-		if (*str==':'){
+	for (; s<limit; s++){
+		if (*s==':'){
 			no_colons++;
 			if (no_colons>7) goto error_too_many_colons;
 			if (double_colon){
@@ -207,7 +212,7 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 				addr[i]=htons(addr[i]);
 				i++;
 			}
-		}else if ((hex=HEX2I(*str))>=0){
+		}else if ((hex=HEX2I(*s))>=0){
 				addr[i]=addr[i]*16+hex;
 				double_colon=0;
 		}else{
@@ -236,26 +241,26 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 	return &ip;
 
 error_too_many_colons:
-	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init);
+	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", st->len, st->s);
 	return 0;
 
 error_too_few_colons:
-	DBG("str2ip6: ERROR: too few colons in [%.*s]\n", (int) len, init);
+	DBG("str2ip6: ERROR: too few colons in [%.*s]\n", st->len, st->s);
 	return 0;
 
 error_colons:
-	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init);
+	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", st->len, st->s);
 	return 0;
 
 error_char:
-	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *str, (int) len,
-			init);
+	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *s, st->len,
+			st->s);
 	return 0;
 }
 
 
 
-struct hostent* sip_resolvehost(char* name, unsigned short* port);
+struct hostent* sip_resolvehost(str* name, unsigned short* port);
 
 
 
@@ -271,17 +276,19 @@ static inline struct hostent* resolvehost(const char* name)
 #endif
 #ifdef DNS_IP_HACK
 	struct ip_addr* ip;
-	int len;
-	
-	len=strlen(name);
+	str s;
+
+	s.s = (char*)name;
+	s.len = strlen(name);
+
 	/* check if it's an ip address */
-	if ( ((ip=str2ip((unsigned char*)name, len))!=0)
+	if ( ((ip=str2ip(&s))!=0)
 #ifdef	USE_IPV6
-		  || ((ip=str2ip6((unsigned char*)name, len))!=0)
+		  || ((ip=str2ip6(&s))!=0)
 #endif
 		){
 		/* we are lucky, this is an ip address */
-		return ip_addr2he(( char*)name, len, ip);
+		return ip_addr2he(&s, ip);
 	}
 	
 #endif

+ 4 - 1
route.c

@@ -137,6 +137,7 @@ static int fix_actions(struct action* a)
 	char *tmp;
 	int ret,r;
 	struct sr_module* mod;
+	str s;
 	
 	if (a==0){
 		LOG(L_CRIT,"BUG: fix_actions: null pointer\n");
@@ -162,7 +163,9 @@ static int fix_actions(struct action* a)
 							t->p1.string=tmp;
 							/* no break */
 						case STRING_ST:
-							p=add_proxy(t->p1.string, t->p2.number);
+							s.s = t->p1.string;
+							s.len = strlen(s.s);
+							p=add_proxy(&s, t->p2.number);
 							if (p==0) return E_BAD_ADDRESS;
 							t->p1.data=p;
 							t->p1_type=PROXY_ST;