Browse code

core: PAI & PPI header names parser fixes

Changed to the usual "case" construct. This also fixes the case
when spaces were present between the header name and ':'
(e.g. "P-Preferred-Identity : ..." was not recognized).

Andrei Pelinescu-Onciul authored on 19/02/2010 10:55:44
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,87 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * parser/case_p_as.h
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2010-02-19  initial version (andrei)
24
+*/
25
+
26
+/** Parser :: Reason Header Name Parsing Macros.
27
+ * @file 
28
+ *
29
+ * @ingroup parser
30
+ */
31
+
32
+#ifndef __case_p_as_h
33
+#define __case_p_as_h
34
+
35
+
36
+#define SERT_CASE						\
37
+	switch(LOWER_DWORD(val)) {			\
38
+		case _sert_:					\
39
+			p += 4;						\
40
+			val = READ(p);				\
41
+			ED_I_CASE;					\
42
+	}									
43
+
44
+
45
+#define ED_I_CASE						\
46
+	switch(LOWER_DWORD(val)) {			\
47
+		case _ed_i_:					\
48
+			p += 4;						\
49
+			val = READ(p);				\
50
+			DENT_CASE;					\
51
+	}									
52
+
53
+
54
+#define DENT_CASE						\
55
+	switch(LOWER_DWORD(val)) {			\
56
+		case _dent_:					\
57
+			p += 4;						\
58
+			val = READ(p);				\
59
+			ITY_CASE;					\
60
+	}									
61
+
62
+#define ITY_CASE						\
63
+	switch(LOWER_DWORD(val)) {			\
64
+		case _ity1_:					\
65
+			hdr->type = HDR_PAI_T;		\
66
+			hdr->name.len = 19;			\
67
+			return (p + 4);				\
68
+		case _ity2_:					\
69
+			hdr->type = HDR_PAI_T;		\
70
+			p+=4;						\
71
+			goto dc_end;				\
72
+	}									
73
+
74
+
75
+
76
+#define p_as_CASE		\
77
+	p += 4;				\
78
+	val = READ(p);		\
79
+	SERT_CASE;			\
80
+	goto other;
81
+
82
+
83
+
84
+#endif /*__case_p_as_h*/
85
+
86
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
0 87
new file mode 100644
... ...
@@ -0,0 +1,83 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * parser/case_p_pr.h
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2010-02-19  initial version (andrei)
24
+*/
25
+
26
+/** Parser :: Reason Header Name Parsing Macros.
27
+ * @file 
28
+ *
29
+ * @ingroup parser
30
+ */
31
+
32
+#ifndef __case_p_pr_h
33
+#define __case_p_pr_h
34
+
35
+
36
+#define EFER_CASE						\
37
+	switch(LOWER_DWORD(val)) {			\
38
+		case _efer_:					\
39
+			p += 4;						\
40
+			val = READ(p);				\
41
+			RED__CASE;					\
42
+	}									
43
+
44
+
45
+#define RED__CASE						\
46
+	switch(LOWER_DWORD(val)) {			\
47
+		case _red__:					\
48
+			p += 4;						\
49
+			val = READ(p);				\
50
+			IDEN_CASE;					\
51
+	}									
52
+
53
+
54
+#define IDEN_CASE						\
55
+	switch(LOWER_DWORD(val)) {			\
56
+		case _iden_:					\
57
+			p += 4;						\
58
+			val = READ(p);				\
59
+			TITY_p_pr_CASE;				\
60
+	}									
61
+
62
+#define TITY_p_pr_CASE					\
63
+	switch(LOWER_DWORD(val)) {			\
64
+		case _tity_:					\
65
+			hdr->type = HDR_PPI_T;		\
66
+			p+=4;						\
67
+			goto dc_end;				\
68
+	}									
69
+
70
+
71
+
72
+#define p_pr_CASE		\
73
+	p += 4;				\
74
+	val = READ(p);		\
75
+	EFER_CASE;			\
76
+	goto other;
77
+
78
+
79
+
80
+#endif /*__case_p_pr_h*/
81
+
82
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -43,6 +43,13 @@
43 43
  * 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 3a 20  2d
44 44
 \endverbatim
45 45
  *
46
+ * A quick way to generate the hex string is:
47
+ *  perl -e '$_=lc shift; print "0x".unpack("H*",reverse)."\n";' 4_char_str
48
+ * or to generate the define list:
49
+    perl -e '$s=lc shift; $s.=" "x(4-(length $s)%4);
50
+             print map("#define _". reverse ."_ 0x". (unpack "H*")."\n",
51
+                       reverse unpack("(a[4])*", reverse $s));'  string
52
+ * Note that some editing is still needed (replace spaces and account for ':').
46 53
  * Test manually/visually if dword is intended string using:
47 54
  * awk '/^#define/ {printf("%s \"%c%c%c%c\" ... %s \n",  $3,strtonum("0x" substr($3,9,2)),strtonum("0x" substr($3,7,2)),strtonum("0x" substr($3,5,2)),strtonum("0x" substr($3,3,2)),$5)}' keys.h
48 55
  *
... ...
@@ -194,6 +201,19 @@
194 194
 #define _on2_ 0x3a206e6f  /* "on :" */
195 195
 #define _on3_ 0x20206e6f  /* "on  " */
196 196
 
197
+#define _p_as_ 0x73612d70 /* "p-as" */
198
+#define _sert_ 0x74726573 /* "sert" */
199
+#define _ed_i_ 0x692d6465 /* "ed-i" */
200
+#define _dent_ 0x746e6564 /* "dent" */
201
+#define _ity1_ 0x3a797469 /* "ity:" */
202
+#define _ity2_ 0x20797469 /* "ity " */
203
+
204
+#define _p_pr_ 0x72702d70 /* "p-pr" */
205
+#define _efer_ 0x72656665 /* "efer" */
206
+#define _red__ 0x2d646572 /* "red-" */
207
+/* _iden_ is already defined */
208
+/* _tity_ is already defined */
209
+
197 210
 /*!} */
198 211
 
199 212
 #endif /* KEYS_H */
... ...
@@ -103,7 +103,9 @@ static inline char* skip_ws(char* p, unsigned int size)
103 103
 #include "case_retr.h"     /* Retry-After */
104 104
 #include "case_path.h"     /* Path */
105 105
 #include "case_priv.h"
106
-#include "case_reas.h"
106
+#include "case_reas.h"     /* Reason */
107
+#include "case_p_as.h"     /* P-Asserted-Identity */
108
+#include "case_p_pr.h"     /* P-Preferred-Identity */
107 109
 
108 110
 /*@} */
109 111
 
... ...
@@ -152,7 +154,9 @@ static inline char* skip_ws(char* p, unsigned int size)
152 152
 	case _retr_: retr_CASE; \
153 153
 	case _path_: path_CASE; \
154 154
 	case _priv_: priv_CASE; \
155
-	case _reas_: reas_CASE;
155
+	case _reas_: reas_CASE; \
156
+	case _p_as_: p_as_CASE; \
157
+	case _p_pr_: p_pr_CASE;
156 158
 
157 159
 
158 160
 #define PARSE_COMPACT(id)          \
... ...
@@ -168,7 +172,7 @@ static inline char* skip_ws(char* p, unsigned int size)
168 168
 	        return (p + 2);    \
169 169
         }
170 170
 
171
-
171
+#if 0
172 172
 int hdr_update_type(struct hdr_field* hdr)
173 173
 {
174 174
 	if(hdr==0 || hdr->name.s==0)
... ...
@@ -186,6 +190,7 @@ int hdr_update_type(struct hdr_field* hdr)
186 186
 
187 187
 	return 0;
188 188
 }
189
+#endif
189 190
 
190 191
 char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
191 192
 {
... ...
@@ -266,7 +271,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
266 266
 	} else {
267 267
 		hdr->type = HDR_OTHER_T;
268 268
 		hdr->name.len = p - hdr->name.s;
269
-		hdr_update_type(hdr);
269
+		/*hdr_update_type(hdr);*/
270 270
 		return (p + 1);
271 271
 	}
272 272
 }