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 years ago
parent
commit
a6982b85d8
11 changed files with 116 additions and 189 deletions
  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;
 							goto error_fwd_uri;
 				}
 				}
 				/* create a temporary proxy*/
 				/* create a temporary proxy*/
-				p=mk_proxy(u->host.s, port);
+				p=mk_proxy(&u->host, port);
 				if (p==0){
 				if (p==0){
 					LOG(L_ERR, "ERROR:  bad host name in uri,"
 					LOG(L_ERR, "ERROR:  bad host name in uri,"
 							" dropping packet\n");
 							" dropping packet\n");
@@ -329,10 +329,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				pkg_free(msg->new_uri.s);
 				pkg_free(msg->new_uri.s);
 				msg->new_uri.len=0;
 				msg->new_uri.len=0;
 				msg->new_uri.s=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;
 			ret=1;
 			break;
 			break;
@@ -362,10 +359,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 							pkg_free(msg->new_uri.s);
 							pkg_free(msg->new_uri.s);
 							msg->new_uri.len=0;
 							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);
 					len=strlen(a->p1.string);
 					msg->new_uri.s=pkg_malloc(len+1);
 					msg->new_uri.s=pkg_malloc(len+1);
 					if (msg->new_uri.s==0){
 					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 "
 					LOG(L_ERR, "ERROR: do_action: memory allocation "
 								" failure\n");
 								" failure\n");
 					ret=E_OUT_OF_MEM;
 					ret=E_OUT_OF_MEM;
-					free_uri(&uri);
 					break;
 					break;
 				}
 				}
 				end=new_uri+MAX_URI_SIZE;
 				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) {
 				} else if (a->type==STRIP_T) {
 					if (a->p1.number>uri.user.len) {
 					if (a->p1.number>uri.user.len) {
 						LOG(L_WARN, "Error: too long strip asked; deleting username: "
 						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;
 						len=0;
 					} else if (a->p1.number==uri.user.len) {
 					} else if (a->p1.number==uri.user.len) {
 						len=0;
 						len=0;
@@ -451,7 +444,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 				if (tmp){
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					memcpy(crt,":",len);crt+=len;
 					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;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				}
 				/* host */
 				/* host */
@@ -459,18 +452,26 @@ int do_action(struct action* a, struct sip_msg* msg)
 					len=strlen("@"); if(crt+len>end) goto error_uri;
 					len=strlen("@"); if(crt+len>end) goto error_uri;
 					memcpy(crt,"@",len);crt+=len;
 					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;
 					tmp=a->p1.string;
-				else
+					if (tmp) len = strlen(tmp);
+				} else {
 					tmp=uri.host.s;
 					tmp=uri.host.s;
+					len = uri.host.len;
+				}
 				if (tmp){
 				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;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				}
 				/* port */
 				/* port */
 				if (a->type==SET_HOSTPORT_T) tmp=0;
 				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){
 				if (tmp){
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					len=strlen(":"); if(crt+len>end) goto error_uri;
 					memcpy(crt,":",len);crt+=len;
 					memcpy(crt,":",len);crt+=len;
@@ -482,7 +483,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 				if (tmp){
 					len=strlen(";"); if(crt+len>end) goto error_uri;
 					len=strlen(";"); if(crt+len>end) goto error_uri;
 					memcpy(crt,";",len);crt+=len;
 					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;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				}
 				/* headers */
 				/* headers */
@@ -490,7 +491,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if (tmp){
 				if (tmp){
 					len=strlen("?"); if(crt+len>end) goto error_uri;
 					len=strlen("?"); if(crt+len>end) goto error_uri;
 					memcpy(crt,"?",len);crt+=len;
 					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;
 					memcpy(crt,tmp,len);crt+=len;
 				}
 				}
 				*crt=0; /* null terminate the thing */
 				*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);
 				if (msg->new_uri.s) pkg_free(msg->new_uri.s);
 				msg->new_uri.s=new_uri;
 				msg->new_uri.s=new_uri;
 				msg->new_uri.len=crt-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;
 				ret=1;
 				break;
 				break;
 		case IF_T:
 		case IF_T:
@@ -546,7 +543,6 @@ int do_action(struct action* a, struct sip_msg* msg)
 	
 	
 error_uri:
 error_uri:
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
-	free_uri(&uri);
 	if (new_uri) free(new_uri);
 	if (new_uri) free(new_uri);
 	return E_UNSPEC;
 	return E_UNSPEC;
 error_fwd_uri:
 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 via_body* via )
 {
 {
 	struct hostent* he;
 	struct hostent* he;
-	char *host_copy;
 	str* name;
 	str* name;
 	unsigned short port;
 	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)
 	   (host.s[len] will always be ok for a via)
 	    BTW: when is via->host.s non null terminated? tm copy? - andrei 
 	    BTW: when is via->host.s non null terminated? tm copy? - andrei 
 	    Yes -- it happened on generating a 408 by TM; -jiri
 	    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){
 	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;
 		return -1;
 	}
 	}
 	hostent2su(to, he, 0, htons(port));
 	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
 /* converts an ip_addr structure to a hostent, returns pointer to internal
  * statical structure */
  * 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 struct hostent he;
 	static char hostname[256];
 	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_aliases[0]=0; /* no aliases*/
 	p_addr[1]=0; /* only one address*/
 	p_addr[1]=0; /* only one address*/
 	p_addr[0]=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;
 	if (ip->len>16) return 0;
 	memcpy(address, ip->u.addr, ip->len);
 	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->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->repl_add_rm) free_lump_list(msg->repl_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->reply_lump)   free_reply_lump(msg->reply_lump);
-	if (msg->parsed_uri_ok) free_uri(&msg->parsed_uri);
 	pkg_free(msg->orig);
 	pkg_free(msg->orig);
 	/* don't free anymore -- now a pointer to a static buffer */
 	/* don't free anymore -- now a pointer to a static buffer */
 #	ifdef DYN_BUF
 #	ifdef DYN_BUF

+ 18 - 83
parser/parse_uri.c

@@ -27,7 +27,6 @@
 
 
 
 
 #include "parse_uri.h"
 #include "parse_uri.h"
-#include "../mem/mem.h"
 #include <string.h>
 #include <string.h>
 #include "../dprint.h"
 #include "../dprint.h"
 #include "../ut.h"    /* q_memchr */
 #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 */
 	memset(uri, 0, sizeof(struct sip_uri)); /* zero it all, just to be sure */
 	/* look for "sip:"*/;
 	/* look for "sip:"*/;
 	next=q_memchr(buf, ':',  len);
 	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");
 		LOG(L_DBG, "ERROR: parse_uri: bad sip uri\n");
 		ser_error=ret=E_BAD_URI;
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
 	}
 	buf=next+1; /* next char after ':' */
 	buf=next+1; /* next char after ':' */
 	if (buf>end){
 	if (buf>end){
 		LOG(L_DBG, "ERROR: parse_uri: uri too short\n");
 		LOG(L_DBG, "ERROR: parse_uri: uri too short\n");
 		ser_error=ret=E_BAD_URI;
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
 	}
 	/*look for '@' */
 	/*look for '@' */
 	next=q_memchr(buf,'@', end-buf);
 	next=q_memchr(buf,'@', end-buf);
@@ -78,36 +77,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 		if (passwd==0){
 		if (passwd==0){
 			/* no ':' found => no password */
 			/* no ':' found => no password */
 			uri->passwd.s=0;
 			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.len=next-user;
-			uri->user.s[next-user]=0; /* null terminate it, 
-									   usefull for easy printing*/
 		}else{
 		}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.len=passwd-user;
-			uri->user.s[passwd-user]=0;
 			passwd++; /*skip ':' */
 			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.len=next-passwd;
-			uri->passwd.s[next-passwd]=0;
 		}
 		}
 		host=next+1; /* skip '@' */
 		host=next+1; /* skip '@' */
 	}
 	}
@@ -115,7 +92,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 	if(host>=end){
 	if(host>=end){
 		LOG(L_DBG, "ERROR: parse_uri: missing hostport\n");
 		LOG(L_DBG, "ERROR: parse_uri: missing hostport\n");
 		ser_error=ret=E_UNSPEC;
 		ser_error=ret=E_UNSPEC;
-		goto error;
+		return ret;
 	}
 	}
 	next=host;
 	next=host;
 	ipv6=q_memchr(host, '[', end-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){
 		if (host>=end){
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri\n");
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri\n");
 			ret=E_UNSPEC;
 			ret=E_UNSPEC;
-			goto error;
+			return ret;
 		}
 		}
 		ipv6=q_memchr(host, ']', end-host);
 		ipv6=q_memchr(host, ']', end-host);
 		if ((ipv6==0)||(ipv6==host)){
 		if ((ipv6==0)||(ipv6==host)){
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri - null address"
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri - null address"
 					" or missing ']'\n");
 					" or missing ']'\n");
 			ret=E_UNSPEC;
 			ret=E_UNSPEC;
-			goto error;
+			return ret;
 		}
 		}
 		host_len=ipv6-host;
 		host_len=ipv6-host;
 		next=ipv6;
 		next=ipv6;
@@ -146,15 +123,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 				end-host;
 				end-host;
 	}
 	}
 	/* get 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.len=host_len;
-	uri->host.s[host_len]=0;
+
 	/* get port*/
 	/* get port*/
 	if ((port)&&(port+1<end)){
 	if ((port)&&(port+1<end)){
 		port++;
 		port++;
@@ -162,18 +133,11 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 			/* error -> invalid uri we found ';' or '?' before ':' */
 			/* error -> invalid uri we found ';' or '?' before ':' */
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			ser_error=ret=E_BAD_URI;
 			ser_error=ret=E_BAD_URI;
-			goto error;
+			return ret;
 		}
 		}
 		port_len=(params)?params-port:(headers)?headers-port:end-port;
 		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.len=port_len;
-		uri->port.s[port_len]=0;
 	}else uri->port.s=0;
 	}else uri->port.s=0;
 	/* get params */
 	/* get params */
 	if ((params)&&(params+1<end)){
 	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 ';' */
 			/* error -> invalid uri we found '?' or '?' before ';' */
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
 			ser_error=ret=E_BAD_URI;
 			ser_error=ret=E_BAD_URI;
-			goto error;
+			return ret;
 		}
 		}
 		params_len=(headers)?headers-params:end-params;
 		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.len=params_len;
-		uri->params.s[params_len]=0;
 	}else uri->params.s=0;
 	}else uri->params.s=0;
 	/*get headers */
 	/*get headers */
 	if ((headers)&&(headers+1<end)){
 	if ((headers)&&(headers+1<end)){
 		headers++;
 		headers++;
 		headers_len=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.len=headers_len;
-		uri->headers.s[headers_len]=0;
 	}else uri->headers.s=0;
 	}else uri->headers.s=0;
 
 
 	err=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",
 		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n",
 				uri->port.s);
 				uri->port.s);
 		ser_error=ret=E_BAD_URI;
 		ser_error=ret=E_BAD_URI;
-		goto error;
+		return ret;
 	}
 	}
-	return ret;
-error:
-	free_uri(uri);
+
 	return ret;
 	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_uri(char *buf, int len, struct sip_uri* uri);
 int parse_sip_msg_uri(struct sip_msg* msg);
 int parse_sip_msg_uri(struct sip_msg* msg);
 
 
-void free_uri(struct sip_uri* u);
-
 #endif /* PARSE_URI_H */
 #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'
 /* searches for the proxy named 'name', on port 'port'
    returns: pointer to proxy_l on success or 0 if not found */ 
    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;
 	struct proxy_l* t;
 	for(t=proxies; t; t=t->next)
 	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;
 			break;
 	return t;
 	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;
 	struct proxy_l* p;
 	
 	
@@ -190,7 +190,7 @@ error:
 /* same as add_proxy, but it doesn't add the proxy to the list
 /* same as add_proxy, but it doesn't add the proxy to the list
  * uses also SRV if possible (quick hack) */
  * 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 proxy_l* p;
 	struct hostent* he;
 	struct hostent* he;
@@ -202,7 +202,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
 		goto error;
 		goto error;
 	}
 	}
 	memset(p,0,sizeof(struct proxy_l));
 	memset(p,0,sizeof(struct proxy_l));
-	p->name=name;
+	p->name=*name;
 	p->port=port;
 	p->port=port;
 
 
 	DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
 	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){
 	if (he==0){
 		ser_error=E_BAD_ADDRESS;
 		ser_error=E_BAD_ADDRESS;
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
-					" \"%s\"\n", name);
+					" \"%.*s\"\n", name->len, name->s);
 		free(p);
 		free(p);
 		goto error;
 		goto error;
 	}
 	}

+ 4 - 3
proxy.h

@@ -32,10 +32,11 @@
 
 
 #include <netdb.h>
 #include <netdb.h>
 #include "ip_addr.h"
 #include "ip_addr.h"
+#include "str.h"
 
 
 struct proxy_l{
 struct proxy_l{
 	struct proxy_l* next;
 	struct proxy_l* next;
-	char* name; /* original name */
+	str name; /* original name */
 	struct hostent host; /* addresses */
 	struct hostent host; /* addresses */
 	unsigned short port;
 	unsigned short port;
 	unsigned short reserved; /*align*/
 	unsigned short reserved; /*align*/
@@ -52,8 +53,8 @@ struct proxy_l{
 
 
 extern struct proxy_l* proxies;
 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);
 struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port);
 void free_proxy(struct proxy_l* p);
 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;
  * returns: hostent struct & *port filled with the port from the SRV record;
  *  0 on error
  *  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 hostent* he;
 	struct rdata* head;
 	struct rdata* head;
@@ -459,29 +459,28 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
 	struct srv_rdata* srv;
 	struct srv_rdata* srv;
 	struct ip_addr* ip;
 	struct ip_addr* ip;
 	static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups */
 	static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups */
-	int len;
 
 
 	/* try SRV if no port specified (draft-ietf-sip-srv-06) */
 	/* try SRV if no port specified (draft-ietf-sip-srv-06) */
 	if ((port)&&(*port==0)){
 	if ((port)&&(*port==0)){
 		*port=SIP_PORT; /* just in case we don't find another */
 		*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),"
 			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{
 		}else{
 			/* check if it's an ip address */
 			/* check if it's an ip address */
-			if ( ((ip=str2ip((unsigned char*)name, len))!=0)
+			if ( ((ip=str2ip(name))!=0)
 #ifdef	USE_IPV6
 #ifdef	USE_IPV6
-				  || ((ip=str2ip6((unsigned char*)name, len))!=0)
+				  || ((ip=str2ip6(name))!=0)
 #endif
 #endif
 				){
 				){
 				/* we are lucky, this is an ip address */
 				/* 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, 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);
 			head=get_record(tmp, T_SRV);
 			for(l=head; l; l=l->next){
 			for(l=head; l; l=l->next){
 				if (l->type!=T_SRV) continue; /*should never happen*/
 				if (l->type!=T_SRV) continue; /*should never happen*/
@@ -501,12 +500,17 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
 					return he;
 					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;
 	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
 /* 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 */
    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;
 	int i;
 	unsigned char *limit;
 	unsigned char *limit;
-	unsigned char *init;
 	static struct ip_addr ip;
 	static struct ip_addr ip;
+	unsigned char* s;
+
+	s = st->s;
 
 
 	/*init*/
 	/*init*/
 	ip.u.addr32[0]=0;
 	ip.u.addr32[0]=0;
 	i=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++;
 				i++;
 				if (i>3) goto error_dots;
 				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{
 		}else{
 				//error unknown char
 				//error unknown char
 				goto error_char;
 				goto error_char;
@@ -156,11 +157,15 @@ static inline struct ip_addr* str2ip(unsigned char* str, unsigned int len)
 	
 	
 	return &ip;
 	return &ip;
 
 
+
+	     /* FIXME: janakj - is this correct ?, we return always 0 here 
+	      * Also we could use different loglevels here
+	      */
 error_dots:
 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;
 	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;
 	return 0;
 }
 }
 
 
@@ -168,7 +173,7 @@ error_char:
 
 
 /* returns an ip_addr struct.; on error returns 0
 /* returns an ip_addr struct.; on error returns 0
  * the ip_addr struct is static, so subsequent calls will destroy its content*/
  * 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 i, idx1, rest;
 	int no_colons;
 	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_end[8];
 	unsigned short* addr;
 	unsigned short* addr;
 	unsigned char* limit;
 	unsigned char* limit;
-	unsigned char* init;
+	unsigned char* s;
 	
 	
 	/* init */
 	/* init */
-	init=str;
+	s=st->s;
 	i=idx1=rest=0;
 	i=idx1=rest=0;
 	double_colon=0;
 	double_colon=0;
 	no_colons=0;
 	no_colons=0;
@@ -190,11 +195,11 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 	ip.len=16;
 	ip.len=16;
 	addr_start=ip.u.addr16;
 	addr_start=ip.u.addr16;
 	addr=addr_start;
 	addr=addr_start;
-	limit=str+len;
+	limit=st->s+st->len;
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_end, 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++;
 			no_colons++;
 			if (no_colons>7) goto error_too_many_colons;
 			if (no_colons>7) goto error_too_many_colons;
 			if (double_colon){
 			if (double_colon){
@@ -207,7 +212,7 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 				addr[i]=htons(addr[i]);
 				addr[i]=htons(addr[i]);
 				i++;
 				i++;
 			}
 			}
-		}else if ((hex=HEX2I(*str))>=0){
+		}else if ((hex=HEX2I(*s))>=0){
 				addr[i]=addr[i]*16+hex;
 				addr[i]=addr[i]*16+hex;
 				double_colon=0;
 				double_colon=0;
 		}else{
 		}else{
@@ -236,26 +241,26 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
 	return &ip;
 	return &ip;
 
 
 error_too_many_colons:
 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;
 	return 0;
 
 
 error_too_few_colons:
 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;
 	return 0;
 
 
 error_colons:
 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;
 	return 0;
 
 
 error_char:
 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;
 	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
 #endif
 #ifdef DNS_IP_HACK
 #ifdef DNS_IP_HACK
 	struct ip_addr* ip;
 	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 */
 	/* check if it's an ip address */
-	if ( ((ip=str2ip((unsigned char*)name, len))!=0)
+	if ( ((ip=str2ip(&s))!=0)
 #ifdef	USE_IPV6
 #ifdef	USE_IPV6
-		  || ((ip=str2ip6((unsigned char*)name, len))!=0)
+		  || ((ip=str2ip6(&s))!=0)
 #endif
 #endif
 		){
 		){
 		/* we are lucky, this is an ip address */
 		/* we are lucky, this is an ip address */
-		return ip_addr2he(( char*)name, len, ip);
+		return ip_addr2he(&s, ip);
 	}
 	}
 	
 	
 #endif
 #endif

+ 4 - 1
route.c

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