... | ... |
@@ -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 | 359 |
pkg_free(msg->new_uri.s); |
363 | 360 |
msg->new_uri.len=0; |
364 | 361 |
} |
365 |
- if (msg->parsed_uri_ok){ |
|
366 |
- msg->parsed_uri_ok=0; |
|
367 |
- free_uri(&msg->parsed_uri); |
|
368 |
- } |
|
362 |
+ msg->parsed_uri_ok=0; |
|
369 | 363 |
len=strlen(a->p1.string); |
370 | 364 |
msg->new_uri.s=pkg_malloc(len+1); |
371 | 365 |
if (msg->new_uri.s==0){ |
... | ... |
@@ -400,7 +394,6 @@ int do_action(struct action* a, struct sip_msg* msg) |
400 | 394 |
LOG(L_ERR, "ERROR: do_action: memory allocation " |
401 | 395 |
" failure\n"); |
402 | 396 |
ret=E_OUT_OF_MEM; |
403 |
- free_uri(&uri); |
|
404 | 397 |
break; |
405 | 398 |
} |
406 | 399 |
end=new_uri+MAX_URI_SIZE; |
... | ... |
@@ -426,7 +419,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
426 | 419 |
} else if (a->type==STRIP_T) { |
427 | 420 |
if (a->p1.number>uri.user.len) { |
428 | 421 |
LOG(L_WARN, "Error: too long strip asked; deleting username: " |
429 |
- "%d of %s\n", a->p1.number, uri.user.s ); |
|
422 |
+ "%d of <%.*s>\n", a->p1.number, uri.user.len, uri.user.s ); |
|
430 | 423 |
len=0; |
431 | 424 |
} else if (a->p1.number==uri.user.len) { |
432 | 425 |
len=0; |
... | ... |
@@ -451,7 +444,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
451 | 444 |
if (tmp){ |
452 | 445 |
len=strlen(":"); if(crt+len>end) goto error_uri; |
453 | 446 |
memcpy(crt,":",len);crt+=len; |
454 |
- len=strlen(tmp); if(crt+len>end) goto error_uri; |
|
447 |
+ len=uri.passwd.len; if(crt+len>end) goto error_uri; |
|
455 | 448 |
memcpy(crt,tmp,len);crt+=len; |
456 | 449 |
} |
457 | 450 |
/* host */ |
... | ... |
@@ -459,18 +452,26 @@ int do_action(struct action* a, struct sip_msg* msg) |
459 | 452 |
len=strlen("@"); if(crt+len>end) goto error_uri; |
460 | 453 |
memcpy(crt,"@",len);crt+=len; |
461 | 454 |
} |
462 |
- if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) |
|
455 |
+ if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) { |
|
463 | 456 |
tmp=a->p1.string; |
464 |
- else |
|
457 |
+ if (tmp) len = strlen(tmp); |
|
458 |
+ } else { |
|
465 | 459 |
tmp=uri.host.s; |
460 |
+ len = uri.host.len; |
|
461 |
+ } |
|
466 | 462 |
if (tmp){ |
467 |
- len=strlen(tmp); if(crt+len>end) goto error_uri; |
|
463 |
+ if(crt+len>end) goto error_uri; |
|
468 | 464 |
memcpy(crt,tmp,len);crt+=len; |
469 | 465 |
} |
470 | 466 |
/* port */ |
471 | 467 |
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; |
|
468 |
+ else if (a->type==SET_PORT_T) { |
|
469 |
+ tmp=a->p1.string; |
|
470 |
+ if (tmp) len = strlen(tmp); |
|
471 |
+ } else { |
|
472 |
+ tmp=uri.port.s; |
|
473 |
+ len = uri.port.len; |
|
474 |
+ } |
|
474 | 475 |
if (tmp){ |
475 | 476 |
len=strlen(":"); if(crt+len>end) goto error_uri; |
476 | 477 |
memcpy(crt,":",len);crt+=len; |
... | ... |
@@ -482,7 +483,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
482 | 483 |
if (tmp){ |
483 | 484 |
len=strlen(";"); if(crt+len>end) goto error_uri; |
484 | 485 |
memcpy(crt,";",len);crt+=len; |
485 |
- len=strlen(tmp); if(crt+len>end) goto error_uri; |
|
486 |
+ len=uri.params.len; if(crt+len>end) goto error_uri; |
|
486 | 487 |
memcpy(crt,tmp,len);crt+=len; |
487 | 488 |
} |
488 | 489 |
/* headers */ |
... | ... |
@@ -490,7 +491,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
490 | 491 |
if (tmp){ |
491 | 492 |
len=strlen("?"); if(crt+len>end) goto error_uri; |
492 | 493 |
memcpy(crt,"?",len);crt+=len; |
493 |
- len=strlen(tmp); if(crt+len>end) goto error_uri; |
|
494 |
+ len=uri.headers.len; if(crt+len>end) goto error_uri; |
|
494 | 495 |
memcpy(crt,tmp,len);crt+=len; |
495 | 496 |
} |
496 | 497 |
*crt=0; /* null terminate the thing */ |
... | ... |
@@ -498,11 +499,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
498 | 499 |
if (msg->new_uri.s) pkg_free(msg->new_uri.s); |
499 | 500 |
msg->new_uri.s=new_uri; |
500 | 501 |
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); |
|
502 |
+ msg->parsed_uri_ok=0; |
|
506 | 503 |
ret=1; |
507 | 504 |
break; |
508 | 505 |
case IF_T: |
... | ... |
@@ -546,7 +543,6 @@ int do_action(struct action* a, struct sip_msg* msg) |
546 | 543 |
|
547 | 544 |
error_uri: |
548 | 545 |
LOG(L_ERR, "ERROR: do_action: set*: uri too long\n"); |
549 |
- free_uri(&uri); |
|
550 | 546 |
if (new_uri) free(new_uri); |
551 | 547 |
return E_UNSPEC; |
552 | 548 |
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 | 310 |
(host.s[len] will always be ok for a via) |
312 | 311 |
BTW: when is via->host.s non null terminated? tm copy? - andrei |
313 | 312 |
Yes -- it happened on generating a 408 by TM; -jiri |
313 |
+ sip_resolvehost now accepts str -janakj |
|
314 | 314 |
*/ |
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 |
- } |
|
315 |
+ DBG("update_sock_struct_from_via: trying SRV lookup\n"); |
|
316 |
+ he=sip_resolvehost(name, &port); |
|
332 | 317 |
|
333 | 318 |
if (he==0){ |
334 |
- LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%s) failure\n", |
|
335 |
- name->s); |
|
319 |
+ LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%.*s) failure\n", |
|
320 |
+ name->len, name->s); |
|
336 | 321 |
return -1; |
337 | 322 |
} |
338 | 323 |
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 | 486 |
p_aliases[0]=0; /* no aliases*/ |
488 | 487 |
p_addr[1]=0; /* only one address*/ |
489 | 488 |
p_addr[0]=address; |
490 |
- strncpy(hostname, name, (len<256)?len+1:256); |
|
489 |
+ strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256); |
|
491 | 490 |
if (ip->len>16) return 0; |
492 | 491 |
memcpy(address, ip->u.addr, ip->len); |
493 | 492 |
|
... | ... |
@@ -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 | 51 |
memset(uri, 0, sizeof(struct sip_uri)); /* zero it all, just to be sure */ |
53 | 52 |
/* look for "sip:"*/; |
54 | 53 |
next=q_memchr(buf, ':', len); |
55 |
- if ((next==0)||(strncmp(buf,"sip",next-buf)!=0)){ |
|
54 |
+ if ((next==0)||(strncasecmp(buf,"sip",next-buf)!=0)){ |
|
56 | 55 |
LOG(L_DBG, "ERROR: parse_uri: bad sip uri\n"); |
57 | 56 |
ser_error=ret=E_BAD_URI; |
58 |
- goto error; |
|
57 |
+ return ret; |
|
59 | 58 |
} |
60 | 59 |
buf=next+1; /* next char after ':' */ |
61 | 60 |
if (buf>end){ |
62 | 61 |
LOG(L_DBG, "ERROR: parse_uri: uri too short\n"); |
63 | 62 |
ser_error=ret=E_BAD_URI; |
64 |
- goto error; |
|
63 |
+ return ret; |
|
65 | 64 |
} |
66 | 65 |
/*look for '@' */ |
67 | 66 |
next=q_memchr(buf,'@', end-buf); |
... | ... |
@@ -78,36 +77,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
78 | 77 |
if (passwd==0){ |
79 | 78 |
/* no ':' found => no password */ |
80 | 79 |
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); |
|
80 |
+ uri->user.s=user; |
|
88 | 81 |
uri->user.len=next-user; |
89 |
- uri->user.s[next-user]=0; /* null terminate it, |
|
90 |
- usefull for easy printing*/ |
|
91 | 82 |
}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); |
|
83 |
+ uri->user.s=user; |
|
99 | 84 |
uri->user.len=passwd-user; |
100 |
- uri->user.s[passwd-user]=0; |
|
101 | 85 |
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); |
|
86 |
+ uri->passwd.s=passwd; |
|
109 | 87 |
uri->passwd.len=next-passwd; |
110 |
- uri->passwd.s[next-passwd]=0; |
|
111 | 88 |
} |
112 | 89 |
host=next+1; /* skip '@' */ |
113 | 90 |
} |
... | ... |
@@ -115,7 +92,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
115 | 92 |
if(host>=end){ |
116 | 93 |
LOG(L_DBG, "ERROR: parse_uri: missing hostport\n"); |
117 | 94 |
ser_error=ret=E_UNSPEC; |
118 |
- goto error; |
|
95 |
+ return ret; |
|
119 | 96 |
} |
120 | 97 |
next=host; |
121 | 98 |
ipv6=q_memchr(host, '[', end-host); |
... | ... |
@@ -124,14 +101,14 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
124 | 101 |
if (host>=end){ |
125 | 102 |
LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri\n"); |
126 | 103 |
ret=E_UNSPEC; |
127 |
- goto error; |
|
104 |
+ return ret; |
|
128 | 105 |
} |
129 | 106 |
ipv6=q_memchr(host, ']', end-host); |
130 | 107 |
if ((ipv6==0)||(ipv6==host)){ |
131 | 108 |
LOG(L_DBG, "ERROR: parse_uri: bad ipv6 uri - null address" |
132 | 109 |
" or missing ']'\n"); |
133 | 110 |
ret=E_UNSPEC; |
134 |
- goto error; |
|
111 |
+ return ret; |
|
135 | 112 |
} |
136 | 113 |
host_len=ipv6-host; |
137 | 114 |
next=ipv6; |
... | ... |
@@ -146,15 +123,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
146 | 123 |
end-host; |
147 | 124 |
} |
148 | 125 |
/* 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); |
|
126 |
+ uri->host.s=host; |
|
156 | 127 |
uri->host.len=host_len; |
157 |
- uri->host.s[host_len]=0; |
|
128 |
+ |
|
158 | 129 |
/* get port*/ |
159 | 130 |
if ((port)&&(port+1<end)){ |
160 | 131 |
port++; |
... | ... |
@@ -162,18 +133,11 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
162 | 133 |
/* error -> invalid uri we found ';' or '?' before ':' */ |
163 | 134 |
LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n"); |
164 | 135 |
ser_error=ret=E_BAD_URI; |
165 |
- goto error; |
|
136 |
+ return ret; |
|
166 | 137 |
} |
167 | 138 |
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); |
|
139 |
+ uri->port.s=port; |
|
175 | 140 |
uri->port.len=port_len; |
176 |
- uri->port.s[port_len]=0; |
|
177 | 141 |
}else uri->port.s=0; |
178 | 142 |
/* get params */ |
179 | 143 |
if ((params)&&(params+1<end)){ |
... | ... |
@@ -182,32 +146,18 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
182 | 146 |
/* error -> invalid uri we found '?' or '?' before ';' */ |
183 | 147 |
LOG(L_DBG, "ERROR: parse_uri: malformed sip uri\n"); |
184 | 148 |
ser_error=ret=E_BAD_URI; |
185 |
- goto error; |
|
149 |
+ return ret; |
|
186 | 150 |
} |
187 | 151 |
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); |
|
152 |
+ uri->params.s=params; |
|
195 | 153 |
uri->params.len=params_len; |
196 |
- uri->params.s[params_len]=0; |
|
197 | 154 |
}else uri->params.s=0; |
198 | 155 |
/*get headers */ |
199 | 156 |
if ((headers)&&(headers+1<end)){ |
200 | 157 |
headers++; |
201 | 158 |
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); |
|
159 |
+ uri->headers.s=headers; |
|
209 | 160 |
uri->headers.len=headers_len; |
210 |
- uri->headers.s[headers_len]=0; |
|
211 | 161 |
}else uri->headers.s=0; |
212 | 162 |
|
213 | 163 |
err=0; |
... | ... |
@@ -216,11 +166,9 @@ int parse_uri(char *buf, int len, struct sip_uri* uri) |
216 | 166 |
LOG(L_DBG, "ERROR: parse_uri: bad port number in sip uri: %s\n", |
217 | 167 |
uri->port.s); |
218 | 168 |
ser_error=ret=E_BAD_URI; |
219 |
- goto error; |
|
169 |
+ return ret; |
|
220 | 170 |
} |
221 |
- return ret; |
|
222 |
-error: |
|
223 |
- free_uri(uri); |
|
171 |
+ |
|
224 | 172 |
return ret; |
225 | 173 |
} |
226 | 174 |
|
... | ... |
@@ -250,16 +198,3 @@ int parse_sip_msg_uri(struct sip_msg* msg) |
250 | 198 |
} |
251 | 199 |
} |
252 | 200 |
|
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 |
-} |
... | ... |
@@ -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 | 53 |
|
53 | 54 |
extern struct proxy_l* proxies; |
54 | 55 |
|
55 |
-struct proxy_l* add_proxy(char* name, unsigned short port); |
|
56 |
-struct proxy_l* mk_proxy(char* name, unsigned short port); |
|
56 |
+struct proxy_l* add_proxy(str* name, unsigned short port); |
|
57 |
+struct proxy_l* mk_proxy(str* name, unsigned short port); |
|
57 | 58 |
struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port); |
58 | 59 |
void free_proxy(struct proxy_l* p); |
59 | 60 |
|
... | ... |
@@ -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 | 500 |
return he; |
502 | 501 |
} |
503 | 502 |
} |
504 |
- DBG("sip_resolvehost: not SRV record found for %s," |
|
505 |
- " trying 'normal' lookup...\n", name); |
|
503 |
+ DBG("sip_resolvehost: not SRV record found for %.*s," |
|
504 |
+ " trying 'normal' lookup...\n", name->len, name->s); |
|
506 | 505 |
} |
507 | 506 |
} |
508 |
- he=resolvehost(name); |
|
507 |
+ |
|
508 |
+ if (name->len >= MAX_DNS_NAME) { |
|
509 |
+ LOG(L_ERR, "sip_resolvehost: domain name too long\n"); |
|
510 |
+ return 0; |
|
511 |
+ } |
|
512 |
+ memcpy(tmp, name->s, name->len); |
|
513 |
+ tmp[name->len] = '\0'; |
|
514 |
+ he=resolvehost(tmp); |
|
509 | 515 |
return he; |
510 | 516 |
} |
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 | 157 |
|
157 | 158 |
return &ip; |
158 | 159 |
|
160 |
+ |
|
161 |
+ /* FIXME: janakj - is this correct ?, we return always 0 here |
|
162 |
+ * Also we could use different loglevels here |
|
163 |
+ */ |
|
159 | 164 |
error_dots: |
160 |
- DBG("str2ip: ERROR: too many dots in [%.*s]\n", (int)len, init); |
|
165 |
+ DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s); |
|
161 | 166 |
return 0; |
162 |
-error_char: |
|
163 |
- DBG("str2ip: WARNING: unexpected char %c in %.*s\n", *str,(int)len, init); |
|
167 |
+ error_char: |
|
168 |
+ DBG("str2ip: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, st->s); |
|
164 | 169 |
return 0; |
165 | 170 |
} |
166 | 171 |
|
... | ... |
@@ -168,7 +173,7 @@ error_char: |
168 | 173 |
|
169 | 174 |
/* returns an ip_addr struct.; on error returns 0 |
170 | 175 |
* 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) |
|
176 |
+static inline struct ip_addr* str2ip6(str* st) |
|
172 | 177 |
{ |
173 | 178 |
int i, idx1, rest; |
174 | 179 |
int no_colons; |
... | ... |
@@ -179,10 +184,10 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len) |
179 | 184 |
unsigned short addr_end[8]; |
180 | 185 |
unsigned short* addr; |
181 | 186 |
unsigned char* limit; |
182 |
- unsigned char* init; |
|
187 |
+ unsigned char* s; |
|
183 | 188 |
|
184 | 189 |
/* init */ |
185 |
- init=str; |
|
190 |
+ s=st->s; |
|
186 | 191 |
i=idx1=rest=0; |
187 | 192 |
double_colon=0; |
188 | 193 |
no_colons=0; |
... | ... |
@@ -190,11 +195,11 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len) |
190 | 195 |
ip.len=16; |
191 | 196 |
addr_start=ip.u.addr16; |
192 | 197 |
addr=addr_start; |
193 |
- limit=str+len; |
|
198 |
+ limit=st->s+st->len; |
|
194 | 199 |
memset(addr_start, 0 , 8*sizeof(unsigned short)); |
195 | 200 |
memset(addr_end, 0 , 8*sizeof(unsigned short)); |
196 |
- for (; str<limit; str++){ |
|
197 |
- if (*str==':'){ |
|
201 |
+ for (; s<limit; s++){ |
|
202 |
+ if (*s==':'){ |
|
198 | 203 |
no_colons++; |
199 | 204 |
if (no_colons>7) goto error_too_many_colons; |
200 | 205 |
if (double_colon){ |
... | ... |
@@ -207,7 +212,7 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len) |
207 | 212 |
addr[i]=htons(addr[i]); |
208 | 213 |
i++; |
209 | 214 |
} |
210 |
- }else if ((hex=HEX2I(*str))>=0){ |
|
215 |
+ }else if ((hex=HEX2I(*s))>=0){ |
|
211 | 216 |
addr[i]=addr[i]*16+hex; |
212 | 217 |
double_colon=0; |
213 | 218 |
}else{ |
... | ... |
@@ -236,26 +241,26 @@ static inline struct ip_addr* str2ip6(unsigned char* str, unsigned int len) |
236 | 241 |
return &ip; |
237 | 242 |
|
238 | 243 |
error_too_many_colons: |
239 |
- DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init); |
|
244 |
+ DBG("str2ip6: ERROR: too many colons in [%.*s]\n", st->len, st->s); |
|
240 | 245 |
return 0; |
241 | 246 |
|
242 | 247 |
error_too_few_colons: |
243 |
- DBG("str2ip6: ERROR: too few colons in [%.*s]\n", (int) len, init); |
|
248 |
+ DBG("str2ip6: ERROR: too few colons in [%.*s]\n", st->len, st->s); |
|
244 | 249 |
return 0; |
245 | 250 |
|
246 | 251 |
error_colons: |
247 |
- DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init); |
|
252 |
+ DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", st->len, st->s); |
|
248 | 253 |
return 0; |
249 | 254 |
|
250 | 255 |
error_char: |
251 |
- DBG("str2ip6: WARNING: unexpected char %c in [%.*s]\n", *str, (int) len, |
|
252 |
- init); |
|
256 |
+ DBG("str2ip6: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, |
|
257 |
+ st->s); |
|
253 | 258 |
return 0; |
254 | 259 |
} |
255 | 260 |
|
256 | 261 |
|
257 | 262 |
|
258 |
-struct hostent* sip_resolvehost(char* name, unsigned short* port); |
|
263 |
+struct hostent* sip_resolvehost(str* name, unsigned short* port); |
|
259 | 264 |
|
260 | 265 |
|
261 | 266 |
|
... | ... |
@@ -271,17 +276,19 @@ static inline struct hostent* resolvehost(const char* name) |
271 | 276 |
#endif |
272 | 277 |
#ifdef DNS_IP_HACK |
273 | 278 |
struct ip_addr* ip; |
274 |
- int len; |
|
275 |
- |
|
276 |
- len=strlen(name); |
|
279 |
+ str s; |
|
280 |
+ |
|
281 |
+ s.s = (char*)name; |
|
282 |
+ s.len = strlen(name); |
|
283 |
+ |
|
277 | 284 |
/* check if it's an ip address */ |
278 |
- if ( ((ip=str2ip((unsigned char*)name, len))!=0) |
|
285 |
+ if ( ((ip=str2ip(&s))!=0) |
|
279 | 286 |
#ifdef USE_IPV6 |
280 |
- || ((ip=str2ip6((unsigned char*)name, len))!=0) |
|
287 |
+ || ((ip=str2ip6(&s))!=0) |
|
281 | 288 |
#endif |
282 | 289 |
){ |
283 | 290 |
/* we are lucky, this is an ip address */ |
284 |
- return ip_addr2he(( char*)name, len, ip); |
|
291 |
+ return ip_addr2he(&s, ip); |
|
285 | 292 |
} |
286 | 293 |
|
287 | 294 |
#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 | 163 |
t->p1.string=tmp; |
163 | 164 |
/* no break */ |
164 | 165 |
case STRING_ST: |
165 |
- p=add_proxy(t->p1.string, t->p2.number); |
|
166 |
+ s.s = t->p1.string; |
|
167 |
+ s.len = strlen(s.s); |
|
168 |
+ p=add_proxy(&s, t->p2.number); |
|
166 | 169 |
if (p==0) return E_BAD_ADDRESS; |
167 | 170 |
t->p1.data=p; |
168 | 171 |
t->p1_type=PROXY_ST; |