Browse code

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 authored on 17/12/2002 18:14:32
Showing 11 changed files
... ...
@@ -125,7 +125,7 @@ int do_action(struct action* a, struct sip_msg* msg)
125 125
 							goto error_fwd_uri;
126 126
 				}
127 127
 				/* create a temporary proxy*/
128
-				p=mk_proxy(u->host.s, port);
128
+				p=mk_proxy(&u->host, port);
129 129
 				if (p==0){
130 130
 					LOG(L_ERR, "ERROR:  bad host name in uri,"
131 131
 							" dropping packet\n");
... ...
@@ -329,10 +329,7 @@ int do_action(struct action* a, struct sip_msg* msg)
329 329
 				pkg_free(msg->new_uri.s);
330 330
 				msg->new_uri.len=0;
331 331
 				msg->new_uri.s=0;
332
-				if (msg->parsed_uri_ok){
333
-					msg->parsed_uri_ok=0; /* invalidate current parsed uri*/
334
-					free_uri(&msg->parsed_uri);
335
-				}
332
+				msg->parsed_uri_ok=0; /* invalidate current parsed uri*/
336 333
 			};
337 334
 			ret=1;
338 335
 			break;
... ...
@@ -362,10 +359,7 @@ int do_action(struct action* a, struct sip_msg* msg)
362 362
 							pkg_free(msg->new_uri.s);
363 363
 							msg->new_uri.len=0;
364 364
 					}
365
-					if (msg->parsed_uri_ok){
366
-							msg->parsed_uri_ok=0;
367
-							free_uri(&msg->parsed_uri);
368
-					}
365
+					msg->parsed_uri_ok=0;
369 366
 					len=strlen(a->p1.string);
370 367
 					msg->new_uri.s=pkg_malloc(len+1);
371 368
 					if (msg->new_uri.s==0){
... ...
@@ -400,7 +394,6 @@ int do_action(struct action* a, struct sip_msg* msg)
400 400
 					LOG(L_ERR, "ERROR: do_action: memory allocation "
401 401
 								" failure\n");
402 402
 					ret=E_OUT_OF_MEM;
403
-					free_uri(&uri);
404 403
 					break;
405 404
 				}
406 405
 				end=new_uri+MAX_URI_SIZE;
... ...
@@ -426,7 +419,7 @@ int do_action(struct action* a, struct sip_msg* msg)
426 426
 				} else if (a->type==STRIP_T) {
427 427
 					if (a->p1.number>uri.user.len) {
428 428
 						LOG(L_WARN, "Error: too long strip asked; deleting username: "
429
-							"%d of %s\n", a->p1.number, uri.user.s );
429
+							"%d of <%.*s>\n", a->p1.number, uri.user.len, uri.user.s );
430 430
 						len=0;
431 431
 					} else if (a->p1.number==uri.user.len) {
432 432
 						len=0;
... ...
@@ -451,7 +444,7 @@ int do_action(struct action* a, struct sip_msg* msg)
451 451
 				if (tmp){
452 452
 					len=strlen(":"); if(crt+len>end) goto error_uri;
453 453
 					memcpy(crt,":",len);crt+=len;
454
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
454
+					len=uri.passwd.len; if(crt+len>end) goto error_uri;
455 455
 					memcpy(crt,tmp,len);crt+=len;
456 456
 				}
457 457
 				/* host */
... ...
@@ -459,18 +452,26 @@ int do_action(struct action* a, struct sip_msg* msg)
459 459
 					len=strlen("@"); if(crt+len>end) goto error_uri;
460 460
 					memcpy(crt,"@",len);crt+=len;
461 461
 				}
462
-				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T))
462
+				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) {
463 463
 					tmp=a->p1.string;
464
-				else
464
+					if (tmp) len = strlen(tmp);
465
+				} else {
465 466
 					tmp=uri.host.s;
467
+					len = uri.host.len;
468
+				}
466 469
 				if (tmp){
467
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
470
+					if(crt+len>end) goto error_uri;
468 471
 					memcpy(crt,tmp,len);crt+=len;
469 472
 				}
470 473
 				/* port */
471 474
 				if (a->type==SET_HOSTPORT_T) tmp=0;
472
-				else if (a->type==SET_PORT_T) tmp=a->p1.string;
473
-				else tmp=uri.port.s;
475
+				else if (a->type==SET_PORT_T) {
476
+					tmp=a->p1.string;
477
+					if (tmp) len = strlen(tmp);
478
+				} else {
479
+					tmp=uri.port.s;
480
+					len = uri.port.len;
481
+				}
474 482
 				if (tmp){
475 483
 					len=strlen(":"); if(crt+len>end) goto error_uri;
476 484
 					memcpy(crt,":",len);crt+=len;
... ...
@@ -482,7 +483,7 @@ int do_action(struct action* a, struct sip_msg* msg)
482 482
 				if (tmp){
483 483
 					len=strlen(";"); if(crt+len>end) goto error_uri;
484 484
 					memcpy(crt,";",len);crt+=len;
485
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
485
+					len=uri.params.len; if(crt+len>end) goto error_uri;
486 486
 					memcpy(crt,tmp,len);crt+=len;
487 487
 				}
488 488
 				/* headers */
... ...
@@ -490,7 +491,7 @@ int do_action(struct action* a, struct sip_msg* msg)
490 490
 				if (tmp){
491 491
 					len=strlen("?"); if(crt+len>end) goto error_uri;
492 492
 					memcpy(crt,"?",len);crt+=len;
493
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
493
+					len=uri.headers.len; if(crt+len>end) goto error_uri;
494 494
 					memcpy(crt,tmp,len);crt+=len;
495 495
 				}
496 496
 				*crt=0; /* null terminate the thing */
... ...
@@ -498,11 +499,7 @@ int do_action(struct action* a, struct sip_msg* msg)
498 498
 				if (msg->new_uri.s) pkg_free(msg->new_uri.s);
499 499
 				msg->new_uri.s=new_uri;
500 500
 				msg->new_uri.len=crt-new_uri;
501
-				if (msg->parsed_uri_ok){
502
-					msg->parsed_uri_ok=0;
503
-					free_uri(&msg->parsed_uri);
504
-				}
505
-				free_uri(&uri);
501
+				msg->parsed_uri_ok=0;
506 502
 				ret=1;
507 503
 				break;
508 504
 		case IF_T:
... ...
@@ -546,7 +543,6 @@ int do_action(struct action* a, struct sip_msg* msg)
546 546
 	
547 547
 error_uri:
548 548
 	LOG(L_ERR, "ERROR: do_action: set*: uri too long\n");
549
-	free_uri(&uri);
550 549
 	if (new_uri) free(new_uri);
551 550
 	return E_UNSPEC;
552 551
 error_fwd_uri:
... ...
@@ -289,7 +289,6 @@ int update_sock_struct_from_via( union sockaddr_union* to,
289 289
 								 struct via_body* via )
290 290
 {
291 291
 	struct hostent* he;
292
-	char *host_copy;
293 292
 	str* name;
294 293
 	unsigned short port;
295 294
 
... ...
@@ -311,28 +310,14 @@ int update_sock_struct_from_via( union sockaddr_union* to,
311 311
 	   (host.s[len] will always be ok for a via)
312 312
 	    BTW: when is via->host.s non null terminated? tm copy? - andrei 
313 313
 	    Yes -- it happened on generating a 408 by TM; -jiri
314
+	    sip_resolvehost now accepts str -janakj
314 315
 	*/
315
-	if (name->s[name->len]){
316
-		host_copy=pkg_malloc( name->len+1 );
317
-		if (!host_copy) {
318
-			LOG(L_NOTICE, "ERROR: update_sock_struct_from_via:"
319
-							" not enough memory\n");
320
-			return -1;
321
-		}
322
-		memcpy(host_copy, name->s, name->len );
323
-		host_copy[name->len]=0;
324
-		DBG("update_sock_struct_from_via: trying SRV lookup\n");
325
-		he=sip_resolvehost(host_copy, &port);
326
-		
327
-		pkg_free( host_copy );
328
-	}else{
329
-		DBG("update_sock_struct_from_via: trying SRV lookup\n");
330
-		he=sip_resolvehost(name->s, &port);
331
-	}
316
+	DBG("update_sock_struct_from_via: trying SRV lookup\n");
317
+	he=sip_resolvehost(name, &port);
332 318
 	
333 319
 	if (he==0){
334
-		LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%s) failure\n",
335
-				name->s);
320
+		LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%.*s) failure\n",
321
+				name->len, name->s);
336 322
 		return -1;
337 323
 	}
338 324
 	hostent2su(to, he, 0, htons(port));
... ...
@@ -475,8 +475,7 @@ static inline char* ip_addr2a(struct ip_addr* ip)
475 475
 
476 476
 /* converts an ip_addr structure to a hostent, returns pointer to internal
477 477
  * statical structure */
478
-static inline struct hostent* ip_addr2he(char* name, int len,
479
-											struct ip_addr* ip)
478
+static inline struct hostent* ip_addr2he(str* name, struct ip_addr* ip)
480 479
 {
481 480
 	static struct hostent he;
482 481
 	static char hostname[256];
... ...
@@ -487,7 +486,7 @@ static inline struct hostent* ip_addr2he(char* name, int len,
487 487
 	p_aliases[0]=0; /* no aliases*/
488 488
 	p_addr[1]=0; /* only one address*/
489 489
 	p_addr[0]=address;
490
-	strncpy(hostname, name, (len<256)?len+1:256);
490
+	strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256);
491 491
 	if (ip->len>16) return 0;
492 492
 	memcpy(address, ip->u.addr, ip->len);
493 493
 	
... ...
@@ -511,7 +511,6 @@ void free_sip_msg(struct sip_msg* msg)
511 511
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
512 512
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
513 513
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
514
-	if (msg->parsed_uri_ok) free_uri(&msg->parsed_uri);
515 514
 	pkg_free(msg->orig);
516 515
 	/* don't free anymore -- now a pointer to a static buffer */
517 516
 #	ifdef DYN_BUF
... ...
@@ -27,7 +27,6 @@
27 27
 
28 28
 
29 29
 #include "parse_uri.h"
30
-#include "../mem/mem.h"
31 30
 #include <string.h>
32 31
 #include "../dprint.h"
33 32
 #include "../ut.h"    /* q_memchr */
... ...
@@ -52,16 +51,16 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
52 52
 	memset(uri, 0, sizeof(struct sip_uri)); /* zero it all, just to be sure */
53 53
 	/* look for "sip:"*/;
54 54
 	next=q_memchr(buf, ':',  len);
55
-	if ((next==0)||(strncmp(buf,"sip",next-buf)!=0)){
55
+	if ((next==0)||(strncasecmp(buf,"sip",next-buf)!=0)){
56 56
 		LOG(L_DBG, "ERROR: parse_uri: bad sip uri\n");
57 57
 		ser_error=ret=E_BAD_URI;
58
-		goto error;
58
+		return ret;
59 59
 	}
60 60
 	buf=next+1; /* next char after ':' */
61 61
 	if (buf>end){
62 62
 		LOG(L_DBG, "ERROR: parse_uri: uri too short\n");
63 63
 		ser_error=ret=E_BAD_URI;
64
-		goto error;
64
+		return ret;
65 65
 	}
66 66
 	/*look for '@' */
67 67
 	next=q_memchr(buf,'@', end-buf);
... ...
@@ -78,36 +77,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
78 78
 		if (passwd==0){
79 79
 			/* no ':' found => no password */
80 80
 			uri->passwd.s=0;
81
-			uri->user.s=(char*)pkg_malloc(next-user+1);
82
-			if (uri->user.s==0){
83
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
84
-				ser_error=ret=E_OUT_OF_MEM;
85
-				goto error;
86
-			}
87
-			memcpy(uri->user.s, user, next-user);
81
+			uri->user.s=user;
88 82
 			uri->user.len=next-user;
89
-			uri->user.s[next-user]=0; /* null terminate it, 
90
-									   usefull for easy printing*/
91 83
 		}else{
92
-			uri->user.s=(char*)pkg_malloc(passwd-user+1);
93
-			if (uri->user.s==0){
94
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
95
-				ser_error=ret=E_OUT_OF_MEM;
96
-				goto error;
97
-			}
98
-			memcpy(uri->user.s, user, passwd-user);
84
+			uri->user.s=user;
99 85
 			uri->user.len=passwd-user;
100
-			uri->user.s[passwd-user]=0;
101 86
 			passwd++; /*skip ':' */
102
-			uri->passwd.s=(char*)pkg_malloc(next-passwd+1);
103
-			if (uri->passwd.s==0){
104
-				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
105
-				ser_error=ret=E_OUT_OF_MEM;
106
-				goto error;
107
-			}
108
-			memcpy(uri->passwd.s, passwd, next-passwd);
87
+			uri->passwd.s=passwd;
109 88
 			uri->passwd.len=next-passwd;
110
-			uri->passwd.s[next-passwd]=0;
111 89
 		}
112 90
 		host=next+1; /* skip '@' */
113 91
 	}
... ...
@@ -115,7 +92,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
115 115
 	if(host>=end){
116 116
 		LOG(L_DBG, "ERROR: parse_uri: missing hostport\n");
117 117
 		ser_error=ret=E_UNSPEC;
118
-		goto error;
118
+		return ret;
119 119
 	}
120 120
 	next=host;
121 121
 	ipv6=q_memchr(host, '[', end-host);
... ...
@@ -124,14 +101,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
124 124
 		if (host>=end){
125 125
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri\n");
126 126
 			ret=E_UNSPEC;
127
-			goto error;
127
+			return ret;
128 128
 		}
129 129
 		ipv6=q_memchr(host, ']', end-host);
130 130
 		if ((ipv6==0)||(ipv6==host)){
131 131
 			LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri - null address"
132 132
 					" or missing ']'\n");
133 133
 			ret=E_UNSPEC;
134
-			goto error;
134
+			return ret;
135 135
 		}
136 136
 		host_len=ipv6-host;
137 137
 		next=ipv6;
... ...
@@ -146,15 +123,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
146 146
 				end-host;
147 147
 	}
148 148
 	/* get host */
149
-	uri->host.s=pkg_malloc(host_len+1);
150
-	if (uri->host.s==0){
151
-		LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
152
-		ret=E_OUT_OF_MEM;
153
-		goto error;
154
-	}
155
-	memcpy(uri->host.s, host, host_len);
149
+	uri->host.s=host;
156 150
 	uri->host.len=host_len;
157
-	uri->host.s[host_len]=0;
151
+
158 152
 	/* get port*/
159 153
 	if ((port)&&(port+1<end)){
160 154
 		port++;
... ...
@@ -162,18 +133,11 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
162 162
 			/* error -> invalid uri we found ';' or '?' before ':' */
163 163
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
164 164
 			ser_error=ret=E_BAD_URI;
165
-			goto error;
165
+			return ret;
166 166
 		}
167 167
 		port_len=(params)?params-port:(headers)?headers-port:end-port;
168
-		uri->port.s=pkg_malloc(port_len+1);
169
-		if (uri->port.s==0){
170
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
171
-			ser_error=ret=E_OUT_OF_MEM;
172
-			goto error;
173
-		}
174
-		memcpy(uri->port.s, port, port_len);
168
+		uri->port.s=port;
175 169
 		uri->port.len=port_len;
176
-		uri->port.s[port_len]=0;
177 170
 	}else uri->port.s=0;
178 171
 	/* get params */
179 172
 	if ((params)&&(params+1<end)){
... ...
@@ -182,32 +146,18 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
182 182
 			/* error -> invalid uri we found '?' or '?' before ';' */
183 183
 			LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n");
184 184
 			ser_error=ret=E_BAD_URI;
185
-			goto error;
185
+			return ret;
186 186
 		}
187 187
 		params_len=(headers)?headers-params:end-params;
188
-		uri->params.s=pkg_malloc(params_len+1);
189
-		if (uri->params.s==0){
190
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
191
-			ser_error=ret=E_OUT_OF_MEM;
192
-			goto error;
193
-		}
194
-		memcpy(uri->params.s, params, params_len);
188
+		uri->params.s=params;
195 189
 		uri->params.len=params_len;
196
-		uri->params.s[params_len]=0;
197 190
 	}else uri->params.s=0;
198 191
 	/*get headers */
199 192
 	if ((headers)&&(headers+1<end)){
200 193
 		headers++;
201 194
 		headers_len=end-headers;
202
-		uri->headers.s=pkg_malloc(headers_len+1);
203
-		if(uri->headers.s==0){
204
-			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
205
-			ser_error=ret=E_OUT_OF_MEM;
206
-			goto error;
207
-		}
208
-		memcpy(uri->headers.s, headers, headers_len);
195
+		uri->headers.s=headers;
209 196
 		uri->headers.len=headers_len;
210
-		uri->headers.s[headers_len]=0;
211 197
 	}else uri->headers.s=0;
212 198
 
213 199
 	err=0;
... ...
@@ -216,11 +166,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
216 216
 		LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n",
217 217
 				uri->port.s);
218 218
 		ser_error=ret=E_BAD_URI;
219
-		goto error;
219
+		return ret;
220 220
 	}
221
-	return ret;
222
-error:
223
-	free_uri(uri);
221
+
224 222
 	return ret;
225 223
 }
226 224
 
... ...
@@ -250,16 +198,3 @@ int parse_sip_msg_uri(struct sip_msg* msg)
250 250
 	}
251 251
 }
252 252
 
253
-
254
-
255
-void free_uri(struct sip_uri* u)
256
-{
257
-	if (u) {
258
-		if (u->user.s)    pkg_free(u->user.s);
259
-		if (u->passwd.s)  pkg_free(u->passwd.s);
260
-		if (u->host.s)    pkg_free(u->host.s);
261
-		if (u->port.s)    pkg_free(u->port.s);
262
-		if (u->params.s)  pkg_free(u->params.s);
263
-		if (u->headers.s) pkg_free(u->headers.s);
264
-	}
265
-}
... ...
@@ -46,6 +46,4 @@
46 46
 int parse_uri(char *buf, int len, struct sip_uri* uri);
47 47
 int parse_sip_msg_uri(struct sip_msg* msg);
48 48
 
49
-void free_uri(struct sip_uri* u);
50
-
51 49
 #endif /* PARSE_URI_H */
... ...
@@ -57,11 +57,11 @@ struct proxy_l* proxies=0;
57 57
 
58 58
 /* searches for the proxy named 'name', on port 'port'
59 59
    returns: pointer to proxy_l on success or 0 if not found */ 
60
-static struct proxy_l* find_proxy(char *name, unsigned short port)
60
+static struct proxy_l* find_proxy(str *name, unsigned short port)
61 61
 {
62 62
 	struct proxy_l* t;
63 63
 	for(t=proxies; t; t=t->next)
64
-		if ((strcasecmp(t->name, name)==0) && (t->port==port))
64
+		if (((t->name.len == name->len) && (strncasecmp(t->name.s, name->s, name->len)==0)) && (t->port==port))
65 65
 			break;
66 66
 	return t;
67 67
 }
... ...
@@ -169,7 +169,7 @@ void free_hostent(struct hostent *dst)
169 169
 
170 170
 
171 171
 
172
-struct proxy_l* add_proxy(char* name, unsigned short port)
172
+struct proxy_l* add_proxy(str* name, unsigned short port)
173 173
 {
174 174
 	struct proxy_l* p;
175 175
 	
... ...
@@ -190,7 +190,7 @@ error:
190 190
 /* same as add_proxy, but it doesn't add the proxy to the list
191 191
  * uses also SRV if possible (quick hack) */
192 192
 
193
-struct proxy_l* mk_proxy(char* name, unsigned short port)
193
+struct proxy_l* mk_proxy(str* name, unsigned short port)
194 194
 {
195 195
 	struct proxy_l* p;
196 196
 	struct hostent* he;
... ...
@@ -202,7 +202,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
202 202
 		goto error;
203 203
 	}
204 204
 	memset(p,0,sizeof(struct proxy_l));
205
-	p->name=name;
205
+	p->name=*name;
206 206
 	p->port=port;
207 207
 
208 208
 	DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
... ...
@@ -210,7 +210,7 @@ struct proxy_l* mk_proxy(char* name, unsigned short port)
210 210
 	if (he==0){
211 211
 		ser_error=E_BAD_ADDRESS;
212 212
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
213
-					" \"%s\"\n", name);
213
+					" \"%.*s\"\n", name->len, name->s);
214 214
 		free(p);
215 215
 		goto error;
216 216
 	}
... ...
@@ -32,10 +32,11 @@
32 32
 
33 33
 #include <netdb.h>
34 34
 #include "ip_addr.h"
35
+#include "str.h"
35 36
 
36 37
 struct proxy_l{
37 38
 	struct proxy_l* next;
38
-	char* name; /* original name */
39
+	str name; /* original name */
39 40
 	struct hostent host; /* addresses */
40 41
 	unsigned short port;
41 42
 	unsigned short reserved; /*align*/
... ...
@@ -52,8 +53,8 @@ struct proxy_l{
52 52
 
53 53
 extern struct proxy_l* proxies;
54 54
 
55
-struct proxy_l* add_proxy(char* name, unsigned short port);
56
-struct proxy_l* mk_proxy(char* name, unsigned short port);
55
+struct proxy_l* add_proxy(str* name, unsigned short port);
56
+struct proxy_l* mk_proxy(str* name, unsigned short port);
57 57
 struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port);
58 58
 void free_proxy(struct proxy_l* p);
59 59
 
... ...
@@ -451,7 +451,7 @@ not_found:
451 451
  * returns: hostent struct & *port filled with the port from the SRV record;
452 452
  *  0 on error
453 453
  */
454
-struct hostent* sip_resolvehost(char* name, unsigned short* port)
454
+struct hostent* sip_resolvehost(str* name, unsigned short* port)
455 455
 {
456 456
 	struct hostent* he;
457 457
 	struct rdata* head;
... ...
@@ -459,29 +459,28 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
459 459
 	struct srv_rdata* srv;
460 460
 	struct ip_addr* ip;
461 461
 	static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups */
462
-	int len;
463 462
 
464 463
 	/* try SRV if no port specified (draft-ietf-sip-srv-06) */
465 464
 	if ((port)&&(*port==0)){
466 465
 		*port=SIP_PORT; /* just in case we don't find another */
467
-		len=strlen(name);
468
-		if ((len+SRV_PREFIX_LEN+1)>MAX_DNS_NAME){
466
+		if ((name->len+SRV_PREFIX_LEN+1)>MAX_DNS_NAME){
469 467
 			LOG(L_WARN, "WARNING: sip_resolvehost: domain name too long (%d),"
470
-						" unable to perform SRV lookup\n", len);
468
+						" unable to perform SRV lookup\n", name->len);
471 469
 		}else{
472 470
 			/* check if it's an ip address */
473
-			if ( ((ip=str2ip((unsigned char*)name, len))!=0)
471
+			if ( ((ip=str2ip(name))!=0)
474 472
 #ifdef	USE_IPV6
475
-				  || ((ip=str2ip6((unsigned char*)name, len))!=0)
473
+				  || ((ip=str2ip6(name))!=0)
476 474
 #endif
477 475
 				){
478 476
 				/* we are lucky, this is an ip address */
479
-				return ip_addr2he(name,len,ip);
477
+				return ip_addr2he(name,ip);
480 478
 			}
481 479
 			
482 480
 			memcpy(tmp, SRV_PREFIX, SRV_PREFIX_LEN);
483
-			memcpy(tmp+SRV_PREFIX_LEN, name, len+1); /*include the ending 0*/
484
-			
481
+			memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
482
+			tmp[SRV_PREFIX_LEN + name->len] = '\0';
483
+
485 484
 			head=get_record(tmp, T_SRV);
486 485
 			for(l=head; l; l=l->next){
487 486
 				if (l->type!=T_SRV) continue; /*should never happen*/
... ...
@@ -501,12 +500,17 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port)
501 501
 					return he;
502 502
 				}
503 503
 			}
504
-			DBG("sip_resolvehost: not SRV record found for %s," 
505
-					" trying 'normal' lookup...\n", name);
504
+			DBG("sip_resolvehost: not SRV record found for %.*s," 
505
+					" trying 'normal' lookup...\n", name->len, name->s);
506 506
 		}
507 507
 	}
508
-	he=resolvehost(name);
508
+
509
+	if (name->len >= MAX_DNS_NAME) {
510
+		LOG(L_ERR, "sip_resolvehost: domain name too long\n");
511
+		return 0;
512
+	}
513
+	memcpy(tmp, name->s, name->len);
514
+	tmp[name->len] = '\0';
515
+	he=resolvehost(tmp);
509 516
 	return he;
510 517
 }
511
-
512
-
... ...
@@ -127,25 +127,26 @@ void free_rdata_list(struct rdata* head);
127 127
 
128 128
 /* converts a str to an ipv4 address, returns the address or 0 on error
129 129
    Warning: the result is a pointer to a statically allocated structure */
130
-static inline struct ip_addr* str2ip(unsigned char* str, unsigned int len)
130
+static inline struct ip_addr* str2ip(str* st)
131 131
 {
132 132
 	int i;
133 133
 	unsigned char *limit;
134
-	unsigned char *init;
135 134
 	static struct ip_addr ip;
135
+	unsigned char* s;
136
+
137
+	s = st->s;
136 138
 
137 139
 	/*init*/
138 140
 	ip.u.addr32[0]=0;
139 141
 	i=0;
140
-	limit=str+len;
141
-	init=str;
142
+	limit=st->s + st->len;
142 143
 
143
-	for(;str<limit ;str++){
144
-		if (*str=='.'){
144
+	for(;s<limit ;s++){
145
+		if (*s=='.'){
145 146
 				i++;
146 147
 				if (i>3) goto error_dots;
147
-		}else if ( (*str <= '9' ) && (*str >= '0') ){
148
-				ip.u.addr[i]=ip.u.addr[i]*10+*str-'0';
148
+		}else if ( (*s <= '9' ) && (*s >= '0') ){
149
+				ip.u.addr[i]=ip.u.addr[i]*10+*s-'0';
149 150
 		}else{
150 151
 				//error unknown char
151 152
 				goto error_char;
... ...
@@ -156,11 +157,15 @@ static inline struct ip_addr* str2ip(unsigned char* str, unsigned int len)
156 156
 	
157 157
 	return &ip;
158 158
 
159
+
160
+	     /* FIXME: janakj - is this correct ?, we return always 0 here 
161
+	      * Also we could use different loglevels here
162
+	      */
159 163
 error_dots:
160
-	DBG("str2ip: ERROR: too many dots in [%.*s]\n", (int)len, init);
164
+	DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s);
161 165
 	return 0;
162
-error_char:
163
-	DBG("str2ip: WARNING: unexpected char %c in %.*s\n", *str,(int)len, init);
166
+ error_char:
167
+	DBG("str2ip: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, st->s);
164 168
 	return 0;
165 169
 }
166 170
 
... ...
@@ -168,7 +173,7 @@ error_char:
168 168
 
169 169
 /* returns an ip_addr struct.; on error returns 0
170 170
  * the ip_addr struct is static, so subsequent calls will destroy its content*/
171
-static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
171
+static inline struct ip_addr* str2ip6(str* st)
172 172
 {
173 173
 	int i, idx1, rest;
174 174
 	int no_colons;
... ...
@@ -179,10 +184,10 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
179 179
 	unsigned short addr_end[8];
180 180
 	unsigned short* addr;
181 181
 	unsigned char* limit;
182
-	unsigned char* init;
182
+	unsigned char* s;
183 183
 	
184 184
 	/* init */
185
-	init=str;
185
+	s=st->s;
186 186
 	i=idx1=rest=0;
187 187
 	double_colon=0;
188 188
 	no_colons=0;
... ...
@@ -190,11 +195,11 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
190 190
 	ip.len=16;
191 191
 	addr_start=ip.u.addr16;
192 192
 	addr=addr_start;
193
-	limit=str+len;
193
+	limit=st->s+st->len;
194 194
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
195 195
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
196
-	for (; str<limit; str++){
197
-		if (*str==':'){
196
+	for (; s<limit; s++){
197
+		if (*s==':'){
198 198
 			no_colons++;
199 199
 			if (no_colons>7) goto error_too_many_colons;
200 200
 			if (double_colon){
... ...
@@ -207,7 +212,7 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
207 207
 				addr[i]=htons(addr[i]);
208 208
 				i++;
209 209
 			}
210
-		}else if ((hex=HEX2I(*str))>=0){
210
+		}else if ((hex=HEX2I(*s))>=0){
211 211
 				addr[i]=addr[i]*16+hex;
212 212
 				double_colon=0;
213 213
 		}else{
... ...
@@ -236,26 +241,26 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len)
236 236
 	return &ip;
237 237
 
238 238
 error_too_many_colons:
239
-	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init);
239
+	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", st->len, st->s);
240 240
 	return 0;
241 241
 
242 242
 error_too_few_colons:
243
-	DBG("str2ip6: ERROR: too few colons in [%.*s]\n", (int) len, init);
243
+	DBG("str2ip6: ERROR: too few colons in [%.*s]\n", st->len, st->s);
244 244
 	return 0;
245 245
 
246 246
 error_colons:
247
-	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init);
247
+	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", st->len, st->s);
248 248
 	return 0;
249 249
 
250 250
 error_char:
251
-	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *str, (int) len,
252
-			init);
251
+	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *s, st->len,
252
+			st->s);
253 253
 	return 0;
254 254
 }
255 255
 
256 256
 
257 257
 
258
-struct hostent* sip_resolvehost(char* name, unsigned short* port);
258
+struct hostent* sip_resolvehost(str* name, unsigned short* port);
259 259
 
260 260
 
261 261
 
... ...
@@ -271,17 +276,19 @@ static inline struct hostent* resolvehost(const char* name)
271 271
 #endif
272 272
 #ifdef DNS_IP_HACK
273 273
 	struct ip_addr* ip;
274
-	int len;
275
-	
276
-	len=strlen(name);
274
+	str s;
275
+
276
+	s.s = (char*)name;
277
+	s.len = strlen(name);
278
+
277 279
 	/* check if it's an ip address */
278
-	if ( ((ip=str2ip((unsigned char*)name, len))!=0)
280
+	if ( ((ip=str2ip(&s))!=0)
279 281
 #ifdef	USE_IPV6
280
-		  || ((ip=str2ip6((unsigned char*)name, len))!=0)
282
+		  || ((ip=str2ip6(&s))!=0)
281 283
 #endif
282 284
 		){
283 285
 		/* we are lucky, this is an ip address */
284
-		return ip_addr2he(( char*)name, len, ip);
286
+		return ip_addr2he(&s, ip);
285 287
 	}
286 288
 	
287 289
 #endif
... ...
@@ -137,6 +137,7 @@ static int fix_actions(struct action* a)
137 137
 	char *tmp;
138 138
 	int ret,r;
139 139
 	struct sr_module* mod;
140
+	str s;
140 141
 	
141 142
 	if (a==0){
142 143
 		LOG(L_CRIT,"BUG: fix_actions: null pointer\n");
... ...
@@ -162,7 +163,9 @@ static int fix_actions(struct action* a)
162 162
 							t->p1.string=tmp;
163 163
 							/* no break */
164 164
 						case STRING_ST:
165
-							p=add_proxy(t->p1.string, t->p2.number);
165
+							s.s = t->p1.string;
166
+							s.len = strlen(s.s);
167
+							p=add_proxy(&s, t->p2.number);
166 168
 							if (p==0) return E_BAD_ADDRESS;
167 169
 							t->p1.data=p;
168 170
 							t->p1_type=PROXY_ST;