Browse code

- fixed all rport & via param parsing bugs (hopefully): added a new member (start) to via_param modified parse_via to set new via_param->start member and via->params more rport fixes (make use of new via_param->start)

[ if somebody else is interested in playing with via params I will elaborate ]

Andrei Pelinescu-Onciul authored on 27/01/2003 14:22:07
Showing 4 changed files
... ...
@@ -8,7 +8,7 @@
8 8
 VERSION = 0
9 9
 PATCHLEVEL = 8
10 10
 SUBLEVEL =   11
11
-EXTRAVERSION = pre4-tcp1-locking
11
+EXTRAVERSION = pre5-tcp1-locking
12 12
 
13 13
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 14
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -34,6 +34,7 @@
34 34
  *             (andrei)
35 35
  * 2003-01-24 added i param to via of outgoing requests (used by tcp),
36 36
  *             modified via_builder params (andrei)
37
+ * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
37 38
  *
38 39
  */
39 40
 
... ...
@@ -566,7 +567,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
566 567
 	}
567 568
 	/* if rport needs to be updated, delete it and add it's value */
568 569
 	if (rport_len){
569
-		anchor=del_lump(&(msg->add_rm), msg->via1->rport->name.s-buf-1, /*';'*/
570
+		anchor=del_lump(&(msg->add_rm), msg->via1->rport->start-buf-1, /*';'*/
570 571
 							msg->via1->rport->size+1 /* ; */, HDR_VIA);
571 572
 		if (anchor==0) goto error03; /* free rport_buf*/
572 573
 		if (insert_new_lump_after(anchor, rport_buf, rport_len, HDR_VIA)==0)
... ...
@@ -853,14 +854,14 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
853 854
 					if (rport_buf){
854 855
 						/* copy until rport */
855 856
 						append_str_trans( p, hdr->name.s ,
856
-							msg->via1->rport->name.s-hdr->name.s-1,msg);
857
+							msg->via1->rport->start-hdr->name.s-1,msg);
857 858
 						/* copy new rport */
858 859
 						append_str(p, rport_buf, rport_len, msg);
859 860
 						/* copy the rest of the via */
860
-						append_str_trans(p, msg->via1->rport->name.s+
861
+						append_str_trans(p, msg->via1->rport->start+
861 862
 											msg->via1->rport->size, 
862 863
 											hdr->body.s+hdr->body.len-
863
-											msg->via1->rport->name.s-
864
+											msg->via1->rport->start-
864 865
 											msg->via1->rport->size, msg);
865 866
 					}else{
866 867
 						/* normal whole via copy */
... ...
@@ -37,6 +37,8 @@
37 37
  *               by tcp to identify the sending socket, by andrei
38 38
  *  2003-01-23  fixed rport parsing code to accept rport w/o any value,
39 39
  *               by andrei
40
+ *  2003-01-27  modified parse_via to set new via_param->start member and
41
+ *               via->params.s (andrei)
40 42
  */
41 43
 
42 44
 
... ...
@@ -103,6 +105,8 @@ enum {
103 105
  * state=F_{LF,CR,CRLF}!
104 106
  * output state = L_PARAM or F_PARAM or END_OF_HEADER
105 107
  * (and saved_state= last state); everything else => error 
108
+ * WARNING: param->start must be filled before, it's used in param->size 
109
+ * computation.
106 110
  */
107 111
 static /*inline*/ char* parse_via_param(char* p, char* end,
108 112
 										unsigned char* pstate, 
... ...
@@ -159,10 +163,10 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
159 163
 			case '\n':
160 164
 				switch(state){
161 165
 					case FIN_HIDDEN:
162
-					case FIN_RPORT:
163 166
 						*tmp=0;
164 167
 						param->type=state;
165 168
 						param->name.len=tmp-param->name.s;
169
+						param->size=tmp-param->start; 
166 170
 						saved_state=L_PARAM;
167 171
 						state=F_LF;
168 172
 						goto endofparam;
... ...
@@ -171,9 +175,11 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
171 175
 					case FIN_MADDR:
172 176
 					case FIN_RECEIVED:
173 177
 					case FIN_I:
178
+					case FIN_RPORT:
174 179
 						*tmp=0;
175 180
 						param->type=state;
176 181
 						param->name.len=tmp-param->name.s;
182
+						param->size=tmp-param->start; 
177 183
 						saved_state=L_VALUE;
178 184
 						state=F_LF;
179 185
 						goto find_value;
... ...
@@ -194,6 +200,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
194 200
 						param->type=GEN_PARAM;
195 201
 						saved_state=L_VALUE;
196 202
 						param->name.len=tmp-param->name.s;
203
+						param->size=tmp-param->start; 
197 204
 						state=F_LF;
198 205
 						goto find_value;
199 206
 				}
... ...
@@ -201,10 +208,10 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
201 208
 			case '\r':
202 209
 				switch(state){
203 210
 					case FIN_HIDDEN:
204
-					case FIN_RPORT:
205 211
 						*tmp=0;
206 212
 						param->type=state;
207 213
 						param->name.len=tmp-param->name.s;
214
+						param->size=tmp-param->start; 
208 215
 						saved_state=L_PARAM;
209 216
 						state=F_CR;
210 217
 						goto endofparam;
... ...
@@ -213,9 +220,11 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
213 220
 					case FIN_MADDR:
214 221
 					case FIN_RECEIVED:
215 222
 					case FIN_I:
223
+					case FIN_RPORT:
216 224
 						*tmp=0;
217 225
 						param->type=state;
218 226
 						param->name.len=tmp-param->name.s;
227
+						param->size=tmp-param->start; 
219 228
 						saved_state=L_VALUE;
220 229
 						state=F_CR;
221 230
 						goto find_value;
... ...
@@ -232,6 +241,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
232 241
 						*tmp=0;
233 242
 						param->type=GEN_PARAM;
234 243
 						param->name.len=tmp-param->name.s;
244
+						param->size=tmp-param->start; 
235 245
 						saved_state=L_VALUE;
236 246
 						state=F_CR;
237 247
 						goto find_value;
... ...
@@ -732,6 +742,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
732 742
 					case F_VALUE: /*eat space*/
733 743
 					case P_STRING:
734 744
 						saved_state=state;
745
+						param->size=tmp-param->start;
735 746
 						state=F_LF;
736 747
 						break;
737 748
 					case P_VALUE:
... ...
@@ -759,6 +770,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
759 770
 					case F_VALUE: /*eat space*/
760 771
 					case P_STRING:
761 772
 						saved_state=state;
773
+						param->size=tmp-param->start;
762 774
 						state=F_CR;
763 775
 						break;
764 776
 					case P_VALUE:
... ...
@@ -908,7 +920,8 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
908 920
 	
909 921
  endofparam:
910 922
  endofvalue:
911
-	param->size=tmp-p;
923
+	param->size=tmp-param->start;
924
+normal_exit:
912 925
 	*pstate=state;
913 926
 	*psaved_state=saved_state;
914 927
 	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type,
... ...
@@ -923,7 +936,8 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
923 936
 	if ((param->type==GEN_PARAM)||(param->type==PARAM_RPORT)){
924 937
 		saved_state=L_PARAM; /* change the saved_state, we have an unknown
925 938
 		                        param. w/o a value */
926
-		goto endofparam;
939
+		/* param->size should be computed before */
940
+		goto normal_exit;
927 941
 	}
928 942
 	*pstate=state;
929 943
 	*psaved_state=saved_state;
... ...
@@ -943,6 +957,7 @@ static /*inline*/ char* parse_via_param(char* p, char* end,
943 957
 char* parse_via(char* buffer, char* end, struct via_body *vb)
944 958
 {
945 959
 	char* tmp;
960
+	char* param_start;
946 961
 	unsigned char state;
947 962
 	unsigned char saved_state;
948 963
 	int c_nest;
... ...
@@ -954,6 +969,7 @@ parse_again:
954 969
 	vb->error=PARSE_ERROR;
955 970
 	/* parse start of via ( SIP/2.0/UDP    )*/
956 971
 	state=F_SIP;
972
+	param_start=0;
957 973
 	for(tmp=buffer;tmp<end;tmp++){
958 974
 		switch(*tmp){
959 975
 			case ' ':
... ...
@@ -1476,6 +1492,7 @@ parse_again:
1476 1492
 						*tmp=0;
1477 1493
 						vb->host.len=tmp-vb->host.s;
1478 1494
 						state=F_PARAM;
1495
+						param_start=tmp+1;
1479 1496
 						break;
1480 1497
 					case P_PORT:
1481 1498
 						*tmp=0; /*mark the end*/
... ...
@@ -1483,6 +1500,7 @@ parse_again:
1483 1500
 					case L_PORT:
1484 1501
 					case L_PARAM:
1485 1502
 						state=F_PARAM;
1503
+						param_start=tmp+1;
1486 1504
 						break;
1487 1505
 					case F_PORT:
1488 1506
 						LOG(L_ERR, "ERROR:parse_via:"
... ...
@@ -1496,6 +1514,7 @@ parse_again:
1496 1514
 					case P_PARAM:
1497 1515
 						/*hmm next, param?*/
1498 1516
 						state=F_PARAM;
1517
+						param_start=tmp+1;
1499 1518
 						break;
1500 1519
 					case L_VIA:
1501 1520
 					case F_VIA:
... ...
@@ -1744,7 +1763,7 @@ parse_again:
1744 1763
 						break;
1745 1764
 					case F_PARAM:
1746 1765
 						/*state=P_PARAM*/;
1747
-						if(vb->params.s==0) vb->params.s=tmp;
1766
+						if(vb->params.s==0) vb->params.s=param_start;
1748 1767
 						param=pkg_malloc(sizeof(struct via_param));
1749 1768
 						if (param==0){
1750 1769
 							LOG(L_ERR, "ERROR:parse_via: mem. allocation"
... ...
@@ -1752,21 +1771,25 @@ parse_again:
1752 1771
 							goto error;
1753 1772
 						}
1754 1773
 						memset(param,0, sizeof(struct via_param));
1774
+						param->start=param_start;
1755 1775
 						tmp=parse_via_param(tmp, end, &state, &saved_state,
1756 1776
 											param);
1757 1777
 
1758 1778
 						switch(state){
1759
-							case L_PARAM:
1760 1779
 							case F_PARAM:
1780
+								param_start=tmp+1;
1781
+							case L_PARAM:
1761 1782
 							case F_LF:
1762 1783
 							case F_CR:
1763 1784
 								break;
1764 1785
 							case F_VIA:
1765
-								vb->params.len=tmp-vb->params.s;
1786
+								vb->params.len=param->start+param->size
1787
+												-vb->params.s;
1766 1788
 								*tmp=0;
1767 1789
 								break;
1768 1790
 							case END_OF_HEADER:
1769
-								vb->params.len=tmp-vb->params.s;
1791
+								vb->params.len=param->start+param->size
1792
+												-vb->params.s;
1770 1793
 								break;
1771 1794
 							case PARAM_ERROR:
1772 1795
 								pkg_free(param);
... ...
@@ -30,6 +30,7 @@
30 30
  *               Maxim Sobolev  <sobomax@FreeBSD.org>
31 31
  *  2003-01-21  added extra via param parsing code (i=...), used
32 32
  *               by tcp to identify the sending socket, by andrei
33
+ *  2003-01-27  added a new member (start) to via_param, by andrei
33 34
  */
34 35
 
35 36
 
... ...
@@ -54,7 +55,10 @@ struct via_param {
54 55
 	int type;               /* Type of the parameter */
55 56
 	str name;               /* Name of the parameter */
56 57
 	str value;              /* Value of the parameter */
57
-	int size;               /* total size*/
58
+	char* start;            /* Pointer to param start, just after ';',
59
+							 * (it can be diff. from name.s!) */
60
+	int size;               /* total size, including preceding and trailing
61
+							 * white space */
58 62
 	struct via_param* next; /* Next parameter in the list */
59 63
 };
60 64