... | ... |
@@ -24,12 +24,16 @@ |
24 | 24 |
* You should have received a copy of the GNU General Public License |
25 | 25 |
* along with this program; if not, write to the Free Software |
26 | 26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 |
+ * |
|
28 |
+ * History: |
|
29 |
+ * --------- |
|
30 |
+ * 2003-01-27 t_uac deprecated (jiri) |
|
27 | 31 |
*/ |
28 | 32 |
|
29 | 33 |
|
30 | 34 |
#ifndef _TM_DEFS_H |
31 | 35 |
#define _TM_DEFS_H |
32 | 36 |
|
33 |
-#undef DEPRECATE_OLD_STUFF |
|
37 |
+#define DEPRECATE_OLD_STUFF |
|
34 | 38 |
|
35 | 39 |
#endif |
... | ... |
@@ -51,7 +51,8 @@ |
51 | 51 |
* |
52 | 52 |
* History: |
53 | 53 |
* ---------- |
54 |
- * 2003-01-23 options for disabling r-uri matching introduced |
|
54 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
55 |
+ * 2003-01-23 options for disabling r-uri matching introduced (jiri) |
|
55 | 56 |
*/ |
56 | 57 |
|
57 | 58 |
|
... | ... |
@@ -59,6 +60,7 @@ |
59 | 60 |
|
60 | 61 |
|
61 | 62 |
#include <assert.h> |
63 |
+#include "../../comp_defs.h" |
|
62 | 64 |
#include "../../dprint.h" |
63 | 65 |
#include "../../config.h" |
64 | 66 |
#include "../../parser/parser_f.h" |
... | ... |
@@ -94,7 +96,11 @@ |
94 | 96 |
(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\ |
95 | 97 |
)==0 ) |
96 | 98 |
|
99 |
+#ifdef PRESERVE_ZT |
|
97 | 100 |
#define HF_LEN(_hf) ((_hf)->body.s+(_hf)->body.len-(_hf)->name.s) |
101 |
+#else |
|
102 |
+#define HF_LEN(_hf) ((_hf)->len) |
|
103 |
+#endif |
|
98 | 104 |
|
99 | 105 |
/* should be request-uri matching used as a part of pre-3261 |
100 | 106 |
* transaction matching, as the standard wants us to do so |
... | ... |
@@ -25,11 +25,17 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * |
|
30 |
+ * History: |
|
31 |
+ * ---------- |
|
32 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 33 |
*/ |
29 | 34 |
|
30 | 35 |
#include "defs.h" |
31 | 36 |
|
32 | 37 |
|
38 |
+#include "../../comp_defs.h" |
|
33 | 39 |
#include "../../hash_func.h" |
34 | 40 |
#include "../../globals.h" |
35 | 41 |
#include "t_funcs.h" |
... | ... |
@@ -95,18 +101,28 @@ char *build_local(struct cell *Trans,unsigned int branch, |
95 | 101 |
} |
96 | 102 |
*len+= via_len; |
97 | 103 |
/*headers*/ |
104 |
+#ifdef PRESERVE_ZT |
|
98 | 105 |
*len+=Trans->from.len+CRLF_LEN |
99 | 106 |
+Trans->callid.len+CRLF_LEN |
100 | 107 |
+to->len+CRLF_LEN |
101 | 108 |
/* CSeq: 101 CANCEL */ |
102 | 109 |
+Trans->cseq_n.len+1+method_len+CRLF_LEN; |
110 |
+#else |
|
111 |
+ *len+=Trans->from.len+Trans->callid.len+to->len+ |
|
112 |
+ +Trans->cseq_n.len+1+method_len+CRLF_LEN; |
|
113 |
+#endif |
|
114 |
+ |
|
103 | 115 |
|
104 | 116 |
/* copy'n'paste Route headers */ |
105 | 117 |
if (!Trans->local) { |
106 | 118 |
for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next ) |
107 | 119 |
if (hdr->type==HDR_ROUTE) |
120 |
+#ifdef PRESERVE_ZT |
|
108 | 121 |
*len+=((hdr->body.s+hdr->body.len ) - hdr->name.s ) + |
109 | 122 |
CRLF_LEN ; |
123 |
+#else |
|
124 |
+ *len+=hdr->len; |
|
125 |
+#endif |
|
110 | 126 |
} |
111 | 127 |
|
112 | 128 |
/* User Agent */ |
... | ... |
@@ -133,12 +149,18 @@ char *build_local(struct cell *Trans,unsigned int branch, |
133 | 149 |
append_mem_block(p,via,via_len); |
134 | 150 |
|
135 | 151 |
/*other headers*/ |
152 |
+#ifdef PRESERVE_ZT |
|
136 | 153 |
append_str( p, Trans->from ); |
137 | 154 |
append_mem_block( p, CRLF, CRLF_LEN ); |
138 | 155 |
append_str( p, Trans->callid ); |
139 | 156 |
append_mem_block( p, CRLF, CRLF_LEN ); |
140 | 157 |
append_str( p, *to ); |
141 | 158 |
append_mem_block( p, CRLF, CRLF_LEN ); |
159 |
+#else |
|
160 |
+ append_str( p, Trans->from ); |
|
161 |
+ append_str( p, Trans->callid ); |
|
162 |
+ append_str( p, *to ); |
|
163 |
+#endif |
|
142 | 164 |
append_str( p, Trans->cseq_n ); |
143 | 165 |
append_mem_block( p, " ", 1 ); |
144 | 166 |
append_mem_block( p, method, method_len ); |
... | ... |
@@ -147,9 +169,13 @@ char *build_local(struct cell *Trans,unsigned int branch, |
147 | 169 |
if (!Trans->local) { |
148 | 170 |
for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next ) |
149 | 171 |
if(hdr->type==HDR_ROUTE) { |
172 |
+#ifdef PRESERVE_ZT |
|
150 | 173 |
append_mem_block(p, hdr->name.s, |
151 | 174 |
hdr->body.s+hdr->body.len-hdr->name.s ); |
152 | 175 |
append_mem_block(p, CRLF, CRLF_LEN ); |
176 |
+#else |
|
177 |
+ append_mem_block(p, hdr->name.s, hdr->len ); |
|
178 |
+#endif |
|
153 | 179 |
} |
154 | 180 |
} |
155 | 181 |
|
... | ... |
@@ -27,11 +27,13 @@ |
27 | 27 |
* |
28 | 28 |
* History: |
29 | 29 |
* -------- |
30 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
30 | 31 |
* 2003-01-19 faked lump list created in on_reply handlers |
31 | 32 |
*/ |
32 | 33 |
|
33 | 34 |
#include "defs.h" |
34 | 35 |
|
36 |
+#include "../../comp_defs.h" |
|
35 | 37 |
|
36 | 38 |
#include "../../hash_func.h" |
37 | 39 |
#include "t_funcs.h" |
... | ... |
@@ -106,8 +108,13 @@ static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch, |
106 | 108 |
"cannot generate a HBH ACK if key HFs in reply missing\n"); |
107 | 109 |
return NULL; |
108 | 110 |
} |
111 |
+#ifdef PRESERVE_ZT |
|
109 | 112 |
to.len=rpl->to->body.s+rpl->to->body.len-rpl->to->name.s; |
110 | 113 |
to.s=rpl->orig+(rpl->to->name.s-rpl->buf); |
114 |
+#else |
|
115 |
+ to.s=rpl->to->name.s; |
|
116 |
+ to.len=rpl->to->len; |
|
117 |
+#endif |
|
111 | 118 |
return build_local( trans, branch, ret_len, |
112 | 119 |
ACK, ACK_LEN, &to ); |
113 | 120 |
} |
... | ... |
@@ -265,7 +265,7 @@ struct module_exports exports= { |
265 | 265 |
#ifndef DEPRECATE_OLD_STUFF |
266 | 266 |
1+ |
267 | 267 |
#endif |
268 |
- 11, /* Number of module paramers */ |
|
268 |
+ 10, /* Number of module paramers */ |
|
269 | 269 |
|
270 | 270 |
mod_init, /* module initialization function */ |
271 | 271 |
(response_function) t_on_reply, |
... | ... |
@@ -44,6 +44,7 @@ |
44 | 44 |
* |
45 | 45 |
* History: |
46 | 46 |
* -------- |
47 |
+ * 2003-01-27 fifo:t_uac_dlg completed (jiri) |
|
47 | 48 |
* 2003-01-23 t_uac_dlg now uses get_out_socket (jiri) |
48 | 49 |
*/ |
49 | 50 |
|
... | ... |
@@ -80,6 +81,12 @@ |
80 | 81 |
#include "t_msgbuilder.h" |
81 | 82 |
#include "uac.h" |
82 | 83 |
|
84 |
+/* header fields which are explicitely processed and are not copied |
|
85 |
+ * from FIFO line-by-line |
|
86 |
+ */ |
|
87 |
+#define skip_hf(_hf) (((_hf)->type==HDR_FROM) || ((_hf)->type==HDR_TO) \ |
|
88 |
+ || ((_hf)->type==HDR_CALLID) || ((_hf)->type==HDR_CSEQ)) |
|
89 |
+ |
|
83 | 90 |
/* Call-ID has the following form: <callid_nr>-<pid>@<ip> |
84 | 91 |
* callid_nr is initialized as a random number and continually |
85 | 92 |
* increases; -<pid>@<ip> is kept in callid_suffix |
... | ... |
@@ -97,6 +104,11 @@ |
97 | 104 |
/* length of FROM tags */ |
98 | 105 |
#define FROM_TAG_LEN (MD5_LEN +1 /* - */ + CRC16_LEN) |
99 | 106 |
|
107 |
+struct str_list { |
|
108 |
+ str s; |
|
109 |
+ struct str_list *next; |
|
110 |
+}; |
|
111 |
+ |
|
100 | 112 |
static unsigned long callid_nr; |
101 | 113 |
static char *callid_suffix; |
102 | 114 |
static int callid_suffix_len; |
... | ... |
@@ -330,6 +342,34 @@ done: |
330 | 342 |
} |
331 | 343 |
#endif |
332 | 344 |
|
345 |
+static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su ) |
|
346 |
+{ |
|
347 |
+ struct proxy_l *proxy; |
|
348 |
+ struct socket_info* send_sock; |
|
349 |
+ |
|
350 |
+ proxy = uri2proxy(uri); |
|
351 |
+ if (proxy == 0) { |
|
352 |
+ ser_error = E_BAD_ADDRESS; |
|
353 |
+ LOG(L_ERR, "ERROR: uri2sock: Can't create a dst proxy\n"); |
|
354 |
+ return 0; |
|
355 |
+ } |
|
356 |
+ |
|
357 |
+ hostent2su(to_su, &proxy->host, proxy->addr_idx, |
|
358 |
+ (proxy->port) ? htons(proxy->port) : htons(SIP_PORT)); |
|
359 |
+ send_sock=get_out_socket(to_su, PROTO_UDP); |
|
360 |
+ if (send_sock == 0) { |
|
361 |
+ LOG(L_ERR, "ERROR: uri2sock: no corresponding socket for af %d\n", |
|
362 |
+ to_su->s.sa_family ); |
|
363 |
+ ser_error = E_NO_SOCKET; |
|
364 |
+ } |
|
365 |
+ |
|
366 |
+ |
|
367 |
+ free_proxy(proxy); |
|
368 |
+ free(proxy); |
|
369 |
+ return send_sock; |
|
370 |
+} |
|
371 |
+ |
|
372 |
+ |
|
333 | 373 |
|
334 | 374 |
/* |
335 | 375 |
* Send a request within a dialog |
... | ... |
@@ -404,11 +444,10 @@ int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OP |
404 | 444 |
unsigned int req_len; |
405 | 445 |
char *buf; |
406 | 446 |
struct cell *new_cell; |
407 |
- struct proxy_l *proxy; |
|
408 |
- union sockaddr_union to_su; |
|
409 | 447 |
struct socket_info* send_sock; |
410 | 448 |
struct retr_buf *request; |
411 | 449 |
str callid_s, ftag, tmp; |
450 |
+ union sockaddr_union to_su; |
|
412 | 451 |
|
413 | 452 |
/* make -Wall shut up */ |
414 | 453 |
ret=0; |
... | ... |
@@ -423,22 +462,13 @@ int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OP |
423 | 462 |
goto done; |
424 | 463 |
} |
425 | 464 |
|
426 |
- proxy = uri2proxy((dst) ? (dst) : ruri); |
|
427 |
- if (proxy == 0) { |
|
428 |
- ser_error = ret = E_BAD_ADDRESS; |
|
429 |
- LOG(L_ERR, "ERROR: t_uac_dlg: Can't create a dst proxy\n"); |
|
430 |
- goto done; |
|
465 |
+ send_sock=uri2sock( dst? dst: ruri, &to_su ); |
|
466 |
+ if (send_sock==0) { |
|
467 |
+ LOG(L_ERR, "ERROR: t_uac_dlg: no socket found\n"); |
|
468 |
+ goto error00; |
|
431 | 469 |
} |
432 | 470 |
|
433 | 471 |
branch=0; |
434 |
- hostent2su(&to_su, &proxy->host, proxy->addr_idx, (proxy->port) ? htons(proxy->port) : htons(SIP_PORT)); |
|
435 |
- send_sock=get_out_socket(&to_su, PROTO_UDP); |
|
436 |
- if (send_sock == 0) { |
|
437 |
- LOG(L_ERR, "ERROR: t_uac_dlg: no corresponding listening socket for af %d\n", to_su.s.sa_family ); |
|
438 |
- ret = E_NO_SOCKET; |
|
439 |
- goto error00; |
|
440 |
- } |
|
441 |
- |
|
442 | 472 |
/* No Call-ID given, calculate it */ |
443 | 473 |
if (cid == 0) { |
444 | 474 |
callid_nr++; |
... | ... |
@@ -513,8 +543,10 @@ int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OP |
513 | 543 |
request->buffer_len = req_len; |
514 | 544 |
new_cell->nr_of_outgoings++; |
515 | 545 |
|
546 |
+/* |
|
516 | 547 |
proxy->tx++; |
517 | 548 |
proxy->tx_bytes += req_len; |
549 |
+*/ |
|
518 | 550 |
|
519 | 551 |
if (SEND_BUFFER(request) == -1) { |
520 | 552 |
if (dst) { |
... | ... |
@@ -523,8 +555,10 @@ int t_uac_dlg(str* msg, /* Type of the message - MESSAGE, OP |
523 | 555 |
tmp = *ruri; |
524 | 556 |
} |
525 | 557 |
LOG(L_ERR, "ERROR: t_uac: UAC sending to \'%.*s\' failed\n", tmp.len, tmp.s); |
558 |
+/* |
|
526 | 559 |
proxy->errors++; |
527 | 560 |
proxy->ok = 0; |
561 |
+*/ |
|
528 | 562 |
} |
529 | 563 |
|
530 | 564 |
start_retr(request); |
... | ... |
@@ -539,8 +573,10 @@ error01: |
539 | 573 |
free_cell(new_cell); |
540 | 574 |
|
541 | 575 |
error00: |
576 |
+/* |
|
542 | 577 |
free_proxy(proxy); |
543 | 578 |
free(proxy); |
579 |
+*/ |
|
544 | 580 |
|
545 | 581 |
done: |
546 | 582 |
/* if we did not install cbp, release it now */ |
... | ... |
@@ -574,14 +610,16 @@ static void fifo_callback( struct cell *t, struct sip_msg *msg, |
574 | 610 |
DBG("DEBUG: fifo_callback sucesssfuly completed\n"); |
575 | 611 |
} |
576 | 612 |
|
613 |
+#ifndef DEPRECATE_OLD_STUFF |
|
614 |
+ |
|
577 | 615 |
/* to be obsoleted in favor of fifo_uac_from */ |
578 | 616 |
int fifo_uac( FILE *stream, char *response_file ) |
579 | 617 |
{ |
580 |
- char method[MAX_METHOD]; |
|
618 |
+ str sm, sh, sb, sd; /* method, header, body, dst(outbound) */ |
|
619 |
+ char method[MAX_METHOD]; /* read buffers for these ... */ |
|
581 | 620 |
char header[MAX_HEADER]; |
582 | 621 |
char body[MAX_BODY]; |
583 | 622 |
char dst[MAX_DST]; |
584 |
- str sm, sh, sb, sd; |
|
585 | 623 |
char *shmem_file; |
586 | 624 |
int fn_len; |
587 | 625 |
int ret; |
... | ... |
@@ -652,7 +690,6 @@ int fifo_uac( FILE *stream, char *response_file ) |
652 | 690 |
return 1; |
653 | 691 |
} |
654 | 692 |
|
655 |
-#ifndef DEPRECATE_OLD_STUFF |
|
656 | 693 |
|
657 | 694 |
/* syntax: |
658 | 695 |
|
... | ... |
@@ -762,6 +799,123 @@ int fifo_uac_from( FILE *stream, char *response_file ) |
762 | 799 |
|
763 | 800 |
#endif |
764 | 801 |
|
802 |
+static struct str_list *new_str(char *s, int len, struct str_list **last, int *total) |
|
803 |
+{ |
|
804 |
+ struct str_list *new; |
|
805 |
+ new=pkg_malloc(sizeof(struct str_list)); |
|
806 |
+ if (!new) { |
|
807 |
+ LOG(L_ERR, "ERROR: get_hfblock: not enough mem\n"); |
|
808 |
+ return 0; |
|
809 |
+ } |
|
810 |
+ new->s.s=s; |
|
811 |
+ new->s.len=len; |
|
812 |
+ new->next=0; |
|
813 |
+ |
|
814 |
+ (*last)->next=new; |
|
815 |
+ *last=new; |
|
816 |
+ *total+=len; |
|
817 |
+ |
|
818 |
+ return new; |
|
819 |
+} |
|
820 |
+ |
|
821 |
+ |
|
822 |
+static char *get_hfblock(str *uri, struct hdr_field *hf, int *l) |
|
823 |
+{ |
|
824 |
+ struct str_list sl, *last, *new, *i, *foo; |
|
825 |
+ int hf_avail, frag_len, total_len; |
|
826 |
+ char *begin, *needle, *dst, *ret, *d; |
|
827 |
+ str *sock_name, *portname; |
|
828 |
+ union sockaddr_union to_su; |
|
829 |
+ struct socket_info* send_sock; |
|
830 |
+ |
|
831 |
+ ret=0; /* pesimist: assume failure */ |
|
832 |
+ total_len=0; |
|
833 |
+ last=&sl; |
|
834 |
+ last->next=0; |
|
835 |
+ portname=sock_name=0; |
|
836 |
+ |
|
837 |
+ for (; hf; hf=hf->next) { |
|
838 |
+ if (skip_hf(hf)) continue; |
|
839 |
+ |
|
840 |
+ begin=needle=hf->name.s; |
|
841 |
+ hf_avail=hf->len; |
|
842 |
+ |
|
843 |
+ /* substitution loop */ |
|
844 |
+ while(hf_avail) { |
|
845 |
+ d=memchr(needle, SUBST_CHAR, hf_avail); |
|
846 |
+ if (!d || d+1>=needle+hf_avail) { /* nothing to substitute */ |
|
847 |
+ new=new_str(begin, hf_avail, &last, &total_len); |
|
848 |
+ if (!new) goto error; |
|
849 |
+ break; |
|
850 |
+ } else { |
|
851 |
+ frag_len=d-begin; |
|
852 |
+ d++; /* d not at the second substitution char */ |
|
853 |
+ switch(*d) { |
|
854 |
+ case SUBST_CHAR: /* double SUBST_CHAR: IP */ |
|
855 |
+ /* string before substitute */ |
|
856 |
+ new=new_str(begin, frag_len, &last, &total_len); |
|
857 |
+ if (!new) goto error; |
|
858 |
+ /* substitute */ |
|
859 |
+ if (!sock_name) { |
|
860 |
+ send_sock=uri2sock( uri, &to_su ); |
|
861 |
+ if (!send_sock) { |
|
862 |
+ LOG(L_ERR, "ERROR: get_hf_block: send_sock failed\n"); |
|
863 |
+ goto error; |
|
864 |
+ } |
|
865 |
+ sock_name=&send_sock->address_str; |
|
866 |
+ portname=&send_sock->port_no_str; |
|
867 |
+ } |
|
868 |
+ new=new_str(sock_name->s, sock_name->len, |
|
869 |
+ &last, &total_len ); |
|
870 |
+ if (!new) goto error; |
|
871 |
+ new=new_str(portname->s, portname->len, |
|
872 |
+ &last, &total_len ); |
|
873 |
+ if (!new) goto error; |
|
874 |
+ /* keep going ... */ |
|
875 |
+ begin=needle=d+1;hf_avail-=frag_len+2; |
|
876 |
+ continue; |
|
877 |
+ default: |
|
878 |
+ /* no valid substitution char -- keep going */ |
|
879 |
+ hf_avail-=frag_len+1; |
|
880 |
+ needle=d; |
|
881 |
+ } |
|
882 |
+ } /* possible substitute */ |
|
883 |
+ } /* substitution loop */ |
|
884 |
+ /* proceed to next header */ |
|
885 |
+ /* new=new_str(CRLF, CRLF_LEN, &last, &total_len ); |
|
886 |
+ if (!new) goto error; */ |
|
887 |
+ DBG("DEBUG: get_hf_block: one more hf processed\n"); |
|
888 |
+ } /* header loop */ |
|
889 |
+ |
|
890 |
+ |
|
891 |
+ /* construct a single header block now */ |
|
892 |
+ ret=pkg_malloc(total_len); |
|
893 |
+ if (!ret) { |
|
894 |
+ LOG(L_ERR, "ERROR: get_hf_block no pkg mem for hf block\n"); |
|
895 |
+ goto error; |
|
896 |
+ } |
|
897 |
+ i=sl.next; |
|
898 |
+ dst=ret; |
|
899 |
+ while(i) { |
|
900 |
+ foo=i; |
|
901 |
+ i=i->next; |
|
902 |
+ memcpy(dst, foo->s.s, foo->s.len); |
|
903 |
+ dst+=foo->s.len; |
|
904 |
+ pkg_free(foo); |
|
905 |
+ } |
|
906 |
+ *l=total_len; |
|
907 |
+ return ret; |
|
908 |
+ |
|
909 |
+error: |
|
910 |
+ i=sl.next; |
|
911 |
+ while(i) { |
|
912 |
+ foo=i; |
|
913 |
+ i=i->next; |
|
914 |
+ pkg_free(foo); |
|
915 |
+ } |
|
916 |
+ *l=0; |
|
917 |
+ return 0; |
|
918 |
+} |
|
765 | 919 |
|
766 | 920 |
static void fifo_uac_error(char *reply_fifo, int code, char *msg) |
767 | 921 |
{ |
... | ... |
@@ -784,6 +938,37 @@ static void fifo_uac_error(char *reply_fifo, int code, char *msg) |
784 | 938 |
[body] |
785 | 939 |
.EOL |
786 | 940 |
|
941 |
+ |
|
942 |
+ there is also the possibility to have server placed its |
|
943 |
+ hostname:portnumber in header fields -- just put double |
|
944 |
+ exclamation mark in any of the optional header fields |
|
945 |
+ (i.e., any but From/To/CallID,CSeq), they will be |
|
946 |
+ substituted hn:pn |
|
947 |
+ |
|
948 |
+Example: |
|
949 |
+ |
|
950 |
+sc fifo t_uac_dlg MESSAGE sip:joe@192.168.2.1 \ |
|
951 |
+ . \ # no outbound proxy |
|
952 |
+ 'From:sender@iptel.org;tagd=123' \ # no to-tag -> ephemeral |
|
953 |
+ 'To:sender@iptel.org' \ |
|
954 |
+ 'Foo: sip:user@!! ' \ # expansion here |
|
955 |
+ 'CSEQ: 11 MESSAGE ' \ |
|
956 |
+ . \ # EoH |
|
957 |
+ . # empty body |
|
958 |
+--- |
|
959 |
+U 192.168.2.16:5060 -> 192.168.2.1:5060 |
|
960 |
+MESSAGE sip:joe@192.168.2.1 SIP/2.0.. |
|
961 |
+Via: SIP/2.0/UDP 192.168.2.16;branch=z9hG4bK760c.922ea6a1.0.. |
|
962 |
+To: sender@iptel.org.. |
|
963 |
+From: sender@iptel.org;tagd=123;tag=5405e669bc2980663aed2624dc31396f-fa77.. |
|
964 |
+CSeq: 11 MESSAGE.. |
|
965 |
+Call-ID: e863bf56-22255@192.168.2.16.. |
|
966 |
+Content-Length: 0.. |
|
967 |
+User-Agent: Sip EXpress router (0.8.11pre4-tcp1-locking (i386/linux)).. |
|
968 |
+Foo: sip:user@192.168.2.16:5060.. |
|
969 |
+.. |
|
970 |
+ |
|
971 |
+ |
|
787 | 972 |
*/ |
788 | 973 |
|
789 | 974 |
int fifo_uac_dlg( FILE *stream, char *response_file ) |
... | ... |
@@ -794,6 +979,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file ) |
794 | 979 |
char header_buf[MAX_HEADER]; |
795 | 980 |
char body_buf[MAX_BODY]; |
796 | 981 |
str method, ruri, outbound, header, body; |
982 |
+ str hfb; /* header field block */ |
|
797 | 983 |
struct sip_uri parsed_ruri, parsed_outbound; |
798 | 984 |
str dummy_empty; |
799 | 985 |
int fromtag; |
... | ... |
@@ -925,7 +1111,12 @@ int fifo_uac_dlg( FILE *stream, char *response_file ) |
925 | 1111 |
} |
926 | 1112 |
} |
927 | 1113 |
|
928 |
- |
|
1114 |
+ hfb.s=get_hfblock(outbound.len ? &outbound : &ruri, |
|
1115 |
+ faked_msg.headers, &hfb.len); |
|
1116 |
+ if (!hfb.s) { |
|
1117 |
+ fifo_uac_error(response_file, 500, "no mem for hf block"); |
|
1118 |
+ goto error; |
|
1119 |
+ } |
|
929 | 1120 |
|
930 | 1121 |
|
931 | 1122 |
DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n"); |
... | ... |
@@ -935,7 +1126,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file ) |
935 | 1126 |
shmem_file=shm_malloc(fn_len); |
936 | 1127 |
if (shmem_file==0) { |
937 | 1128 |
fifo_uac_error(response_file, 500, "no shmem"); |
938 |
- goto error; |
|
1129 |
+ goto error01; |
|
939 | 1130 |
} |
940 | 1131 |
memcpy(shmem_file, response_file, fn_len ); |
941 | 1132 |
} else { |
... | ... |
@@ -959,7 +1150,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file ) |
959 | 1150 |
faked_msg.callid ? |
960 | 1151 |
&faked_msg.callid->body: |
961 | 1152 |
0, |
962 |
- 0, /* headers -- TBD */ |
|
1153 |
+ &hfb, /* headers -- TBD */ |
|
963 | 1154 |
&body, |
964 | 1155 |
fifo_callback, shmem_file ); |
965 | 1156 |
|
... | ... |
@@ -980,6 +1171,9 @@ int fifo_uac_dlg( FILE *stream, char *response_file ) |
980 | 1171 |
} |
981 | 1172 |
} |
982 | 1173 |
|
1174 |
+error01: |
|
1175 |
+ pkg_free(hfb.s); |
|
1176 |
+ |
|
983 | 1177 |
error: |
984 | 1178 |
/* free_sip_msg(&faked_msg); */ |
985 | 1179 |
if (faked_msg.headers) free_hdr_field_lst(faked_msg.headers); |
... | ... |
@@ -35,6 +35,7 @@ |
35 | 35 |
* 2003-01-24 added i param to via of outgoing requests (used by tcp), |
36 | 36 |
* modified via_builder params (andrei) |
37 | 37 |
* 2003-01-27 more rport fixes (make use of new via_param->start) (andrei) |
38 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
38 | 39 |
* |
39 | 40 |
*/ |
40 | 41 |
|
... | ... |
@@ -47,6 +48,7 @@ |
47 | 48 |
#include <stdio.h> |
48 | 49 |
#include <stdlib.h> |
49 | 50 |
|
51 |
+#include "comp_defs.h" |
|
50 | 52 |
#include "msg_translator.h" |
51 | 53 |
#include "globals.h" |
52 | 54 |
#include "error.h" |
... | ... |
@@ -61,17 +63,14 @@ |
61 | 63 |
#include "pt.h" |
62 | 64 |
|
63 | 65 |
|
64 |
-#define append_str(_dest,_src,_len,_msg) \ |
|
66 |
+#define append_str(_dest,_src,_len) \ |
|
65 | 67 |
do{\ |
66 | 68 |
memcpy( (_dest) , (_src) , (_len) );\ |
67 | 69 |
(_dest) += (_len) ;\ |
68 | 70 |
}while(0); |
69 | 71 |
|
70 | 72 |
#define append_str_trans(_dest,_src,_len,_msg) \ |
71 |
- do{\ |
|
72 |
- memcpy( (_dest) , (_msg)->orig+((_src)-(_msg)->buf) , (_len) );\ |
|
73 |
- (_dest) += (_len) ;\ |
|
74 |
- }while(0); |
|
73 |
+ append_str( (_dest), (_msg)->orig+((_src)-(_msg)->buf) , (_len) ); |
|
75 | 74 |
|
76 | 75 |
extern char version[]; |
77 | 76 |
extern int version_len; |
... | ... |
@@ -647,6 +646,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, |
647 | 646 |
len=msg->len; |
648 | 647 |
new_buf=0; |
649 | 648 |
/* we must remove the first via */ |
649 |
+#ifdef PRESERVE_ZT |
|
650 | 650 |
via_len=msg->via1->bsize; |
651 | 651 |
via_offset=msg->via1->hdr.s-buf; |
652 | 652 |
DBG("via len: %d, initial via offset: %d\n", via_len, via_offset); |
... | ... |
@@ -659,6 +659,15 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, |
659 | 659 |
/* add hdr size ("Via:")*/ |
660 | 660 |
via_len+=msg->via1->hdr.len+1; |
661 | 661 |
} |
662 |
+#else |
|
663 |
+ if (msg->via1->next) { |
|
664 |
+ via_len=msg->via1->bsize; |
|
665 |
+ via_offset=msg->h_via1->body.s-buf; |
|
666 |
+ } else { |
|
667 |
+ via_len=msg->h_via1->len; |
|
668 |
+ via_offset=msg->h_via1->name.s-buf; |
|
669 |
+ } |
|
670 |
+#endif |
|
662 | 671 |
/* remove the first via*/ |
663 | 672 |
if (del_lump( &(msg->repl_add_rm), via_offset, via_len, HDR_VIA)==0){ |
664 | 673 |
LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first" |
... | ... |
@@ -713,6 +722,9 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
713 | 722 |
char *warning; |
714 | 723 |
unsigned int warning_len; |
715 | 724 |
int r; |
725 |
+#ifndef PRESERVE_ZT |
|
726 |
+ char *after_body; |
|
727 |
+#endif |
|
716 | 728 |
str to_tag; |
717 | 729 |
|
718 | 730 |
received_buf=0; |
... | ... |
@@ -772,6 +784,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
772 | 784 |
else |
773 | 785 |
len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/; |
774 | 786 |
} |
787 |
+#ifndef PRESERVE_ZT |
|
788 |
+ else { |
|
789 |
+ len+=hdr->len; |
|
790 |
+ continue; |
|
791 |
+ } |
|
792 |
+#endif |
|
775 | 793 |
} else if (hdr->type==HDR_VIA) { |
776 | 794 |
if (hdr==msg->h_via1) len += received_len+rport_len; |
777 | 795 |
} else if (hdr->type==HDR_RECORDROUTE) { |
... | ... |
@@ -782,7 +800,11 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
782 | 800 |
|| hdr->type==HDR_CSEQ)) { |
783 | 801 |
continue; |
784 | 802 |
} |
803 |
+#ifdef PRESERVE_ZT |
|
785 | 804 |
len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN; |
805 |
+#else |
|
806 |
+ len += hdr->len; |
|
807 |
+#endif |
|
786 | 808 |
} |
787 | 809 |
len-=delete_len; |
788 | 810 |
/*lumps length*/ |
... | ... |
@@ -829,26 +851,6 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
829 | 851 |
for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) |
830 | 852 |
switch (hdr->type) |
831 | 853 |
{ |
832 |
- case HDR_TO: |
|
833 |
- if (new_tag){ |
|
834 |
- if (to_tag.s ) { |
|
835 |
- append_str_trans( p, hdr->name.s , |
|
836 |
- to_tag.s-hdr->name.s,msg); |
|
837 |
- append_str( p, new_tag,new_tag_len,msg); |
|
838 |
- append_str_trans( p,to_tag.s+to_tag.len, |
|
839 |
- ((hdr->body.s+hdr->body.len )- |
|
840 |
- (to_tag.s+to_tag.len)),msg); |
|
841 |
- append_str( p, CRLF,CRLF_LEN,msg); |
|
842 |
- }else{ |
|
843 |
- append_str_trans( p, hdr->name.s , |
|
844 |
- ((hdr->body.s+hdr->body.len )-hdr->name.s ), |
|
845 |
- msg); |
|
846 |
- append_str( p, TOTAG_TOKEN,TOTAG_TOKEN_LEN,msg); |
|
847 |
- append_str( p, new_tag,new_tag_len,msg); |
|
848 |
- append_str( p, CRLF,CRLF_LEN,msg); |
|
849 |
- } |
|
850 |
- break; |
|
851 |
- } |
|
852 | 854 |
case HDR_VIA: |
853 | 855 |
if (hdr==msg->h_via1){ |
854 | 856 |
if (rport_buf){ |
... | ... |
@@ -856,7 +858,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
856 | 858 |
append_str_trans( p, hdr->name.s , |
857 | 859 |
msg->via1->rport->start-hdr->name.s-1,msg); |
858 | 860 |
/* copy new rport */ |
859 |
- append_str(p, rport_buf, rport_len, msg); |
|
861 |
+ append_str(p, rport_buf, rport_len); |
|
860 | 862 |
/* copy the rest of the via */ |
861 | 863 |
append_str_trans(p, msg->via1->rport->start+ |
862 | 864 |
msg->via1->rport->size, |
... | ... |
@@ -866,26 +868,72 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text, |
866 | 868 |
}else{ |
867 | 869 |
/* normal whole via copy */ |
868 | 870 |
append_str_trans( p, hdr->name.s , |
869 |
- ((hdr->body.s+hdr->body.len )-hdr->name.s ),msg); |
|
871 |
+ ((hdr->body.s+hdr->body.len )-hdr->name.s ), msg); |
|
870 | 872 |
} |
871 | 873 |
if (received_buf) |
872 |
- append_str( p, received_buf, received_len, msg); |
|
874 |
+ append_str( p, received_buf, received_len); |
|
873 | 875 |
}else{ |
874 | 876 |
/* normal whole via copy */ |
875 | 877 |
append_str_trans( p, hdr->name.s , |
876 | 878 |
((hdr->body.s+hdr->body.len )-hdr->name.s ),msg); |
877 | 879 |
} |
878 |
- append_str( p, CRLF,CRLF_LEN,msg); |
|
880 |
+ append_str( p, CRLF,CRLF_LEN); |
|
879 | 881 |
break; |
880 | 882 |
case HDR_RECORDROUTE: |
881 | 883 |
/* RR only for 1xx and 2xx replies */ |
882 | 884 |
if (code<180 || code>=300) break; |
885 |
+ case HDR_TO: |
|
886 |
+ if (new_tag){ |
|
887 |
+ if (to_tag.s ) { /* replacement */ |
|
888 |
+#ifdef PRESERVE_ZT |
|
889 |
+ /* before to-tag */ |
|
890 |
+ append_str_trans( p, hdr->name.s , |
|
891 |
+ to_tag.s-hdr->name.s,msg); |
|
892 |
+ /* to tag replacement */ |
|
893 |
+ append_str( p, new_tag,new_tag_len); |
|
894 |
+ /* the rest after to-tag */ |
|
895 |
+ append_str_trans( p,to_tag.s+to_tag.len, |
|
896 |
+ ((hdr->body.s+hdr->body.len )- |
|
897 |
+ (to_tag.s+to_tag.len)),msg); |
|
898 |
+ append_str( p, CRLF,CRLF_LEN); |
|
899 |
+#else |
|
900 |
+ /* before to-tag */ |
|
901 |
+ append_str( p, hdr->name.s, to_tag.s-hdr->name.s); |
|
902 |
+ /* to tag replacement */ |
|
903 |
+ append_str( p, new_tag,new_tag_len); |
|
904 |
+ /* the rest after to-tag */ |
|
905 |
+ append_str( p, to_tag.s+to_tag.len, |
|
906 |
+ hdr->name.s+hdr->len-(to_tag.s+to_tag.len)); |
|
907 |
+#endif |
|
908 |
+ }else{ /* adding a new to-tag */ |
|
909 |
+#ifdef PRESERVE_ZT |
|
910 |
+ append_str_trans( p, hdr->name.s , |
|
911 |
+ ((hdr->body.s+hdr->body.len )-hdr->name.s ), |
|
912 |
+ msg); |
|
913 |
+ append_str( p, TOTAG_TOKEN,TOTAG_TOKEN_LEN); |
|
914 |
+ append_str( p, new_tag,new_tag_len); |
|
915 |
+ append_str( p, CRLF,CRLF_LEN); |
|
916 |
+#else |
|
917 |
+ after_body=hdr->body.s+hdr->body.len; |
|
918 |
+ append_str( p, hdr->name.s, after_body-hdr->name.s); |
|
919 |
+ append_str(p, TOTAG_TOKEN, TOTAG_TOKEN_LEN); |
|
920 |
+ append_str( p, new_tag,new_tag_len); |
|
921 |
+ append_str( p, after_body, |
|
922 |
+ hdr->name.s+hdr->len-after_body); |
|
923 |
+#endif |
|
924 |
+ } |
|
925 |
+ break; |
|
926 |
+ } /* no new to-tag -- proceed to 1:1 copying */ |
|
883 | 927 |
case HDR_FROM: |
884 | 928 |
case HDR_CALLID: |
885 | 929 |
case HDR_CSEQ: |
930 |
+#ifdef PRESERVE_ZT |
|
886 | 931 |
append_str_trans( p, hdr->name.s , |
887 | 932 |
((hdr->body.s+hdr->body.len )-hdr->name.s ),msg); |
888 |
- append_str( p, CRLF,CRLF_LEN,msg); |
|
933 |
+ append_str( p, CRLF,CRLF_LEN); |
|
934 |
+#else |
|
935 |
+ append_str(p, hdr->name.s, hdr->len); |
|
936 |
+#endif |
|
889 | 937 |
} /* for switch */ |
890 | 938 |
/*lumps*/ |
891 | 939 |
for(lump=msg->reply_lump;lump;lump=lump->next) |
... | ... |
@@ -25,19 +25,24 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * ---------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_CALL_H |
32 | 36 |
#define CASE_CALL_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
34 | 39 |
|
35 | 40 |
#define ID_CASE \ |
36 | 41 |
switch(LOWER_DWORD(val)) { \ |
37 | 42 |
case __id1_: \ |
38 | 43 |
hdr->type = HDR_CALLID; \ |
39 | 44 |
hdr->name.len = 7; \ |
40 |
- *(p + 3) = '\0'; \ |
|
45 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 46 |
return (p + 4); \ |
42 | 47 |
\ |
43 | 48 |
case __id2_: \ |
... | ... |
@@ -25,19 +25,24 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * ---------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_CONT_H |
32 | 36 |
#define CASE_CONT_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
34 | 39 |
|
35 | 40 |
#define TH_CASE \ |
36 | 41 |
switch(LOWER_DWORD(val)) { \ |
37 | 42 |
case _th12_: \ |
38 | 43 |
hdr->type = HDR_CONTENTLENGTH; \ |
39 | 44 |
hdr->name.len = 14; \ |
40 |
- *(p + 3) = '\0'; \ |
|
45 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 46 |
return (p + 4); \ |
42 | 47 |
} \ |
43 | 48 |
\ |
... | ... |
@@ -71,7 +76,7 @@ |
71 | 76 |
case _act1_: \ |
72 | 77 |
hdr->type = HDR_CONTACT; \ |
73 | 78 |
hdr->name.len = 7; \ |
74 |
- *(p + 3) = '\0'; \ |
|
79 |
+ SET_ZT(*(p + 3)); \ |
|
75 | 80 |
return (p + 4); \ |
76 | 81 |
\ |
77 | 82 |
case _act2_: \ |
... | ... |
@@ -86,7 +91,6 @@ |
86 | 91 |
goto other; \ |
87 | 92 |
} |
88 | 93 |
|
89 |
- |
|
90 | 94 |
#define cont_CASE \ |
91 | 95 |
p += 4; \ |
92 | 96 |
val = READ(p); \ |
... | ... |
@@ -25,19 +25,24 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * --------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_EXPI_H |
32 | 36 |
#define CASE_EXPI_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
34 | 39 |
|
35 | 40 |
#define EXPI_RES_CASE \ |
36 | 41 |
switch(LOWER_DWORD(val)) { \ |
37 | 42 |
case _res1_: \ |
38 | 43 |
hdr->type = HDR_EXPIRES; \ |
39 | 44 |
hdr->name.len = 7; \ |
40 |
- *(p + 3) = '\0'; \ |
|
45 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 46 |
return (p + 4); \ |
42 | 47 |
\ |
43 | 48 |
case _res2_: \ |
... | ... |
@@ -25,19 +25,24 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * -------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_PROX_H |
32 | 36 |
#define CASE_PROX_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
34 | 39 |
|
35 | 40 |
#define ION_CASE \ |
36 | 41 |
switch(LOWER_DWORD(val)) { \ |
37 | 42 |
case _ion1_: \ |
38 | 43 |
hdr->type = HDR_PROXYAUTH; \ |
39 | 44 |
hdr->name.len = 19; \ |
40 |
- *(p + 3) = '\0'; \ |
|
45 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 46 |
return (p + 4); \ |
42 | 47 |
\ |
43 | 48 |
case _ion2_: \ |
... | ... |
@@ -46,6 +51,9 @@ |
46 | 51 |
goto dc_end; \ |
47 | 52 |
} |
48 | 53 |
|
54 |
+#define IZAT_CASE \ |
|
55 |
+ switch(LOWER_DWORD(val)) { \ |
|
56 |
+ |
|
49 | 57 |
|
50 | 58 |
#define IZAT_CASE \ |
51 | 59 |
switch(LOWER_DWORD(val)) { \ |
... | ... |
@@ -25,19 +25,25 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * ------------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_REQU_H |
32 | 36 |
#define CASE_REQU_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
39 |
+ |
|
34 | 40 |
|
35 | 41 |
#define IRE_CASE \ |
36 | 42 |
switch(LOWER_DWORD(val)) { \ |
37 | 43 |
case _ire1_: \ |
38 | 44 |
hdr->type = HDR_REQUIRE; \ |
39 | 45 |
hdr->name.len = 7; \ |
40 |
- *(p + 3) = '\0'; \ |
|
46 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 47 |
return (p + 4); \ |
42 | 48 |
\ |
43 | 49 |
case _ire2_: \ |
... | ... |
@@ -25,17 +25,22 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * --------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
31 | 35 |
#ifndef CASE_TO_H |
32 | 36 |
#define CASE_TO_H |
33 | 37 |
|
38 |
+#include "../comp_defs.h" |
|
34 | 39 |
|
35 | 40 |
#define to12_CASE \ |
36 | 41 |
hdr->type = HDR_TO; \ |
37 | 42 |
hdr->name.len = 2; \ |
38 |
- *(p + 2) = '\0'; \ |
|
43 |
+ SET_ZT(*(p + 2)); \ |
|
39 | 44 |
return (p + 4); |
40 | 45 |
|
41 | 46 |
|
... | ... |
@@ -25,19 +25,23 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 31 |
*/ |
29 | 32 |
|
30 | 33 |
|
31 | 34 |
#ifndef CASE_UNSU_H |
32 | 35 |
#define CASE_UNSU_H |
33 | 36 |
|
37 |
+#include "../comp_defs.h" |
|
34 | 38 |
|
35 | 39 |
#define TED_CASE \ |
36 | 40 |
switch(LOWER_DWORD(val)) { \ |
37 | 41 |
case _ted1_: \ |
38 | 42 |
hdr->type = HDR_UNSUPPORTED; \ |
39 | 43 |
hdr->name.len = 11; \ |
40 |
- *(p + 3) = '\0'; \ |
|
44 |
+ SET_ZT(*(p + 3)); \ |
|
41 | 45 |
return (p + 4); \ |
42 | 46 |
\ |
43 | 47 |
case _ted2_: \ |
... | ... |
@@ -31,14 +31,14 @@ |
31 | 31 |
#ifndef CASE_VIA_H |
32 | 32 |
#define CASE_VIA_H |
33 | 33 |
|
34 |
+#include "../comp_defs.h" |
|
34 | 35 |
|
35 | 36 |
#define via1_CASE \ |
36 | 37 |
hdr->type = HDR_VIA; \ |
37 | 38 |
hdr->name.len = 3; \ |
38 |
- *(p + 3) = '\0'; \ |
|
39 |
+ SET_ZT(*(p + 3)); \ |
|
39 | 40 |
return (p + 4) |
40 | 41 |
|
41 |
- |
|
42 | 42 |
#define via2_CASE \ |
43 | 43 |
hdr->type = HDR_VIA; \ |
44 | 44 |
p += 4; \ |
... | ... |
@@ -23,6 +23,10 @@ |
23 | 23 |
* You should have received a copy of the GNU General Public License |
24 | 24 |
* along with this program; if not, write to the Free Software |
25 | 25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
26 |
+ * |
|
27 |
+ * History: |
|
28 |
+ * --------- |
|
29 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
26 | 30 |
*/ |
27 | 31 |
|
28 | 32 |
|
... | ... |
@@ -30,6 +34,7 @@ |
30 | 34 |
#define HF_H |
31 | 35 |
|
32 | 36 |
#include "../str.h" |
37 |
+#include "../comp_defs.h" |
|
33 | 38 |
|
34 | 39 |
|
35 | 40 |
/* Header types and flags */ |
... | ... |
@@ -68,6 +73,9 @@ struct hdr_field { |
68 | 73 |
int type; /* Header field type */ |
69 | 74 |
str name; /* Header field name */ |
70 | 75 |
str body; /* Header field body */ |
76 |
+#ifndef PRESERVE_ZT |
|
77 |
+ int len; /* length from body until EoHF (incl. CRLF) */ |
|
78 |
+#endif |
|
71 | 79 |
void* parsed; /* Parsed data structures */ |
72 | 80 |
struct hdr_field* next; /* Next header field in the list */ |
73 | 81 |
}; |
... | ... |
@@ -26,12 +26,17 @@ |
26 | 26 |
* You should have received a copy of the GNU General Public License |
27 | 27 |
* along with this program; if not, write to the Free Software |
28 | 28 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 |
+ * |
|
30 |
+ * History: |
|
31 |
+ * --------- |
|
32 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
29 | 33 |
*/ |
30 | 34 |
|
31 | 35 |
|
32 | 36 |
#include <string.h> |
33 | 37 |
#include <stdlib.h> |
34 | 38 |
|
39 |
+#include "../comp_defs.h" |
|
35 | 40 |
#include "msg_parser.h" |
36 | 41 |
#include "parser_f.h" |
37 | 42 |
#include "../ut.h" |
... | ... |
@@ -79,6 +84,22 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr) |
79 | 84 |
LOG(L_ERR, "ERROR: get_hdr_field: bad header\n"); |
80 | 85 |
goto error; |
81 | 86 |
} |
87 |
+ |
|
88 |
+#ifndef PRESERVE_ZT |
|
89 |
+ /* eliminate leading whitespace */ |
|
90 |
+ tmp=eat_lws_end(tmp, end); |
|
91 |
+ if (tmp>=end) { |
|
92 |
+ LOG(L_ERR, "ERROR: get_hdr_field: HF empty\n"); |
|
93 |
+ goto error; |
|
94 |
+ } |
|
95 |
+#else |
|
96 |
+ ; |
|
97 |
+#endif |
|
98 |
+ |
|
99 |
+ /* if header-field well-known, parse it, find its end otherwise ; |
|
100 |
+ * after leaving the hdr->type switch, tmp should be set to the |
|
101 |
+ * next header field |
|
102 |
+ */ |
|
82 | 103 |
switch(hdr->type){ |
83 | 104 |
case HDR_VIA: |
84 | 105 |
/* keep number of vias parsed -- we want to report it in |
... | ... |
@@ -118,8 +139,10 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr) |
118 | 139 |
} |
119 | 140 |
hdr->parsed=cseq_b; |
120 | 141 |
hdr->body.len=tmp-hdr->body.s; |
121 |
- DBG("get_hdr_field: cseq <%s>: <%s> <%s>\n", |
|
122 |
- hdr->name.s, cseq_b->number.s, cseq_b->method.s); |
|
142 |
+ DBG("get_hdr_field: cseq <%.*s>: <%.*s> <%.*s>\n", |
|
143 |
+ hdr->name.len, hdr->name.s, |
|
144 |
+ cseq_b->number.len, cseq_b->number.s, |
|
145 |
+ cseq_b->method.len, cseq_b->method.s); |
|
123 | 146 |
break; |
124 | 147 |
case HDR_TO: |
125 | 148 |
to_b=pkg_malloc(sizeof(struct to_body)); |
... | ... |
@@ -137,8 +160,9 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr) |
137 | 160 |
} |
138 | 161 |
hdr->parsed=to_b; |
139 | 162 |
hdr->body.len=tmp-hdr->body.s; |
140 |
- DBG("DEBUG: get_hdr_field: <%s> [%d]; uri=[%.*s] \n", |
|
141 |
- hdr->name.s, hdr->body.len, to_b->uri.len,to_b->uri.s); |
|
163 |
+ DBG("DEBUG: get_hdr_field: <%.*s> [%d]; uri=[%.*s] \n", |
|
164 |
+ hdr->name.len, hdr->name.s, |
|
165 |
+ hdr->body.len, to_b->uri.len,to_b->uri.s); |
|
142 | 166 |
DBG("DEBUG: to body [%.*s]\n",to_b->body.len,to_b->body.s); |
143 | 167 |
break; |
144 | 168 |
case HDR_CONTENTLENGTH: |
... | ... |
@@ -188,7 +212,11 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr) |
188 | 212 |
} |
189 | 213 |
tmp=match; |
190 | 214 |
}while( match<end &&( (*match==' ')||(*match=='\t') ) ); |
215 |
+#ifdef PRESERVE_ZT |
|
191 | 216 |
*(match-1)=0; /*null terminate*/ |
217 |
+#else |
|
218 |
+ tmp=match; |
|
219 |
+#endif |
|
192 | 220 |
hdr->body.len=match-hdr->body.s; |
193 | 221 |
break; |
194 | 222 |
default: |
... | ... |
@@ -198,10 +226,16 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr) |
198 | 226 |
} |
199 | 227 |
/* jku: if \r covered by current length, shrink it */ |
200 | 228 |
trim_r( hdr->body ); |
229 |
+#ifndef PRESERVE_ZT |
|
230 |
+ hdr->len=tmp-hdr->name.s; |
|
231 |
+#endif |
|
201 | 232 |
return tmp; |
202 | 233 |
error: |
203 | 234 |
DBG("get_hdr_field: error exit\n"); |
204 | 235 |
hdr->type=HDR_ERROR; |
236 |
+#ifndef PRESERVE_ZT |
|
237 |
+ hdr->len=tmp-hdr->name.s; |
|
238 |
+#endif |
|
205 | 239 |
return tmp; |
206 | 240 |
} |
207 | 241 |
|
... | ... |
@@ -23,9 +23,14 @@ |
23 | 23 |
* You should have received a copy of the GNU General Public License |
24 | 24 |
* along with this program; if not, write to the Free Software |
25 | 25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
26 |
+ * |
|
27 |
+ * History: |
|
28 |
+ * -------- |
|
29 |
+ * 2003-01-22 zero-termination in CSeq eliminated (jiri) |
|
26 | 30 |
*/ |
27 | 31 |
|
28 | 32 |
|
33 |
+#include "../comp_defs.h" |
|
29 | 34 |
#include "parse_cseq.h" |
30 | 35 |
#include "parser_f.h" /* eat_space_end and so on */ |
31 | 36 |
#include "../dprint.h" |
... | ... |
@@ -40,21 +45,32 @@ |
40 | 45 |
char* parse_cseq(char *buf, char* end, struct cseq_body* cb) |
41 | 46 |
{ |
42 | 47 |
char *t, *m, *m_end; |
48 |
+#ifdef PRESERVE_ZT |
|
43 | 49 |
char c; |
50 |
+#endif |
|
44 | 51 |
|
45 | 52 |
cb->error=PARSE_ERROR; |
53 |
+#ifdef PRESERVE_ZT /* already called in calling function */ |
|
46 | 54 |
t=eat_space_end(buf, end); |
47 | 55 |
if (t>=end) goto error; |
56 |
+#else |
|
57 |
+ t=buf; |
|
58 |
+#endif |
|
48 | 59 |
|
49 | 60 |
cb->number.s=t; |
50 | 61 |
t=eat_token_end(t, end); |
51 | 62 |
if (t>=end) goto error; |
63 |
+ cb->number.len=t-cb->number.s; |
|
64 |
+ |
|
52 | 65 |
m=eat_space_end(t, end); |
53 | 66 |
m_end=eat_token_end(m, end); |
54 |
- *t=0; /*null terminate it*/ |
|
55 |
- cb->number.len=t-cb->number.s; |
|
67 |
+ SET_ZT(*t); |
|
56 | 68 |
|
57 |
- if (m_end>=end) goto error; |
|
69 |
+ if (m_end>=end) { |
|
70 |
+ LOG(L_ERR, "ERROR: parse_cseq: " |
|
71 |
+ "method terminated unexpectedly\n"); |
|
72 |
+ goto error; |
|
73 |
+ } |
|
58 | 74 |
if (m_end==m){ |
59 | 75 |
/* null method*/ |
60 | 76 |
LOG(L_ERR, "ERROR:parse_cseq: no method found\n"); |
... | ... |
@@ -62,9 +78,11 @@ char* parse_cseq(char *buf, char* end, struct cseq_body* cb) |
62 | 78 |
} |
63 | 79 |
cb->method.s=m; |
64 | 80 |
t=m_end; |
81 |
+ cb->method.len=t-cb->method.s; |
|
82 |
+ |
|
83 |
+#ifdef PRESERVE_ZT |
|
65 | 84 |
c=*t; |
66 | 85 |
*t=0; /*null terminate it*/ |
67 |
- cb->method.len=t-cb->method.s; |
|
68 | 86 |
t++; |
69 | 87 |
/*check if the header ends here*/ |
70 | 88 |
if (c=='\n') goto check_continue; |
... | ... |
@@ -80,9 +98,28 @@ char* parse_cseq(char *buf, char* end, struct cseq_body* cb) |
80 | 98 |
check_continue: |
81 | 99 |
; |
82 | 100 |
}while( (t<end) && ((*t==' ')||(*t=='\t')) ); |
83 |
- |
|
84 | 101 |
cb->error=PARSE_OK; |
85 | 102 |
return t; |
103 |
+#else |
|
104 |
+ /* there may be trailing LWS |
|
105 |
+ * (it was not my idea to put it in SIP; -jiri ) |
|
106 |
+ */ |
|
107 |
+ t=eat_lws_end(t, end); |
|
108 |
+ /*check if the header ends here*/ |
|
109 |
+ if (t>=end) { |
|
110 |
+ LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n"); |
|
111 |
+ goto error; |
|
112 |
+ } |
|
113 |
+ if (*t=='\r' && t+1<end && *(t+1)=='\n') { |
|
114 |
+ cb->error=PARSE_OK; |
|
115 |
+ return t+2; |
|
116 |
+ } |
|
117 |
+ if (*t=='\n') { |
|
118 |
+ cb->error=PARSE_OK; |
|
119 |
+ return t+1; |
|
120 |
+ } |
|
121 |
+ LOG(L_ERR, "ERROR: CSeq EoL expected\n"); |
|
122 |
+#endif |
|
86 | 123 |
error: |
87 | 124 |
LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n"); |
88 | 125 |
return t; |
... | ... |
@@ -25,9 +25,14 @@ |
25 | 25 |
* You should have received a copy of the GNU General Public License |
26 | 26 |
* along with this program; if not, write to the Free Software |
27 | 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
+ * |
|
29 |
+ * History: |
|
30 |
+ * -------- |
|
31 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
28 | 32 |
*/ |
29 | 33 |
|
30 | 34 |
|
35 |
+#include "../comp_defs.h" |
|
31 | 36 |
#include "parse_hname2.h" |
32 | 37 |
#include "keys.h" |
33 | 38 |
#include "../ut.h" /* q_memchr */ |
... | ... |
@@ -109,7 +114,7 @@ static inline char* skip_ws(char* p, unsigned int size) |
109 | 114 |
case ':': \ |
110 | 115 |
hdr->type = id; \ |
111 | 116 |
hdr->name.len = 1; \ |
112 |
- *(p + 1) = '\0'; \ |
|
117 |
+ SET_ZT(*(p + 1)); \ |
|
113 | 118 |
return (p + 2); \ |
114 | 119 |
} |
115 | 120 |
|
... | ... |
@@ -145,7 +150,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr) |
145 | 150 |
case ':': |
146 | 151 |
hdr->type = HDR_TO; |
147 | 152 |
hdr->name.len = 1; |
148 |
- *(p + 1) = '\0'; |
|
153 |
+ SET_ZT(*(p+1)); |
|
149 | 154 |
return (p + 2); |
150 | 155 |
} |
151 | 156 |
break; |
... | ... |
@@ -169,7 +174,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr) |
169 | 174 |
goto other; |
170 | 175 |
} else { |
171 | 176 |
hdr->name.len = p - hdr->name.s; |
172 |
- *p = '\0'; |
|
177 |
+ SET_ZT(*p); |
|
173 | 178 |
return (p + 1); |
174 | 179 |
} |
175 | 180 |
|
... | ... |
@@ -183,7 +188,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr) |
183 | 188 |
return 0; |
184 | 189 |
} else { |
185 | 190 |
hdr->type = HDR_OTHER; |
186 |
- *p = '\0'; |
|
191 |
+ SET_ZT(*p); |
|
187 | 192 |
hdr->name.len = p - hdr->name.s; |
188 | 193 |
return (p + 1); |
189 | 194 |
} |
... | ... |
@@ -26,6 +26,10 @@ |
26 | 26 |
* You should have received a copy of the GNU General Public License |
27 | 27 |
* along with this program; if not, write to the Free Software |
28 | 28 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 |
+ * |
|
30 |
+ * History: |
|
31 |
+ * --------- |
|
32 |
+ * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri) |
|
29 | 33 |
*/ |
30 | 34 |
|
31 | 35 |
|
... | ... |
@@ -29,16 +29,32 @@ |
29 | 29 |
#ifndef parser_f_h |
30 | 30 |
#define parser_f_h |
31 | 31 |
|
32 |
+#include "../comp_defs.h" |
|
33 |
+ |
|
32 | 34 |
char* eat_line(char* buffer, unsigned int len); |
33 | 35 |
|
34 | 36 |
/* turn the most frequently called functions into inline functions */ |
35 | 37 |
|
36 |
- |
|
37 | 38 |
inline static char* eat_space_end(char* p, char* pend) |
38 | 39 |
{ |
39 | 40 |
for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++); |
40 | 41 |
return p; |
41 | 42 |
} |
43 |
+#ifndef PRESERVE_ZT |
|
44 |
+#define SP(_c) ((_c)=='\t' || (_c)==' ') |
|
45 |
+inline static char* eat_lws_end(char* p, char* pend) |
|
46 |
+{ |
|
47 |
+ while(p<pend) { |
|
48 |
+ if (SP(*p)) p++; |
|
49 |
+ /* btw--I really dislike line folding; -jiri */ |
|
50 |
+ else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2; |
|
51 |
+ else if (*p=='\r' && p+2<pend && *(p+1)=='\n' |
|
52 |
+ && SP(*(p+2))) p+=3; |
|
53 |
+ else break; /* no whitespace encountered */ |
|
54 |
+ } |
|
55 |
+ return p; |
|
56 |
+} |
|
57 |
+#endif |
|
42 | 58 |
|
43 | 59 |
|
44 | 60 |
|