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 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2010 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/*
19
+ * parser/case_p_as.h
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-02-19  initial version (andrei)
25
+*/
26
+
27
+/** Parser :: Reason Header Name Parsing Macros.
28
+ * @file 
29
+ *
30
+ * @ingroup parser
31
+ */
32
+
33
+#ifndef __case_p_as_h
34
+#define __case_p_as_h
35
+
36
+
37
+#define SERT_CASE						\
38
+	switch(LOWER_DWORD(val)) {			\
39
+		case _sert_:					\
40
+			p += 4;						\
41
+			val = READ(p);				\
42
+			ED_I_CASE;					\
43
+	}									
44
+
45
+
46
+#define ED_I_CASE						\
47
+	switch(LOWER_DWORD(val)) {			\
48
+		case _ed_i_:					\
49
+			p += 4;						\
50
+			val = READ(p);				\
51
+			DENT_CASE;					\
52
+	}									
53
+
54
+
55
+#define DENT_CASE						\
56
+	switch(LOWER_DWORD(val)) {			\
57
+		case _dent_:					\
58
+			p += 4;						\
59
+			val = READ(p);				\
60
+			ITY_CASE;					\
61
+	}									
62
+
63
+#define ITY_CASE						\
64
+	switch(LOWER_DWORD(val)) {			\
65
+		case _ity1_:					\
66
+			hdr->type = HDR_PAI_T;		\
67
+			hdr->name.len = 19;			\
68
+			return (p + 4);				\
69
+		case _ity2_:					\
70
+			hdr->type = HDR_PAI_T;		\
71
+			p+=4;						\
72
+			goto dc_end;				\
73
+	}									
74
+
75
+
76
+
77
+#define p_as_CASE		\
78
+	p += 4;				\
79
+	val = READ(p);		\
80
+	SERT_CASE;			\
81
+	goto other;
82
+
83
+
84
+
85
+#endif /*__case_p_as_h*/
86
+
87
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
0 88
new file mode 100644
... ...
@@ -0,0 +1,83 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2010 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/*
19
+ * parser/case_p_pr.h
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-02-19  initial version (andrei)
25
+*/
26
+
27
+/** Parser :: Reason Header Name Parsing Macros.
28
+ * @file 
29
+ *
30
+ * @ingroup parser
31
+ */
32
+
33
+#ifndef __case_p_pr_h
34
+#define __case_p_pr_h
35
+
36
+
37
+#define EFER_CASE						\
38
+	switch(LOWER_DWORD(val)) {			\
39
+		case _efer_:					\
40
+			p += 4;						\
41
+			val = READ(p);				\
42
+			RED__CASE;					\
43
+	}									
44
+
45
+
46
+#define RED__CASE						\
47
+	switch(LOWER_DWORD(val)) {			\
48
+		case _red__:					\
49
+			p += 4;						\
50
+			val = READ(p);				\
51
+			IDEN_CASE;					\
52
+	}									
53
+
54
+
55
+#define IDEN_CASE						\
56
+	switch(LOWER_DWORD(val)) {			\
57
+		case _iden_:					\
58
+			p += 4;						\
59
+			val = READ(p);				\
60
+			TITY_p_pr_CASE;				\
61
+	}									
62
+
63
+#define TITY_p_pr_CASE					\
64
+	switch(LOWER_DWORD(val)) {			\
65
+		case _tity_:					\
66
+			hdr->type = HDR_PPI_T;		\
67
+			p+=4;						\
68
+			goto dc_end;				\
69
+	}									
70
+
71
+
72
+
73
+#define p_pr_CASE		\
74
+	p += 4;				\
75
+	val = READ(p);		\
76
+	EFER_CASE;			\
77
+	goto other;
78
+
79
+
80
+
81
+#endif /*__case_p_pr_h*/
82
+
83
+/* 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 201
 #define _on2_ 0x3a206e6f  /* "on :" */
195 202
 #define _on3_ 0x20206e6f  /* "on  " */
196 203
 
204
+#define _p_as_ 0x73612d70 /* "p-as" */
205
+#define _sert_ 0x74726573 /* "sert" */
206
+#define _ed_i_ 0x692d6465 /* "ed-i" */
207
+#define _dent_ 0x746e6564 /* "dent" */
208
+#define _ity1_ 0x3a797469 /* "ity:" */
209
+#define _ity2_ 0x20797469 /* "ity " */
210
+
211
+#define _p_pr_ 0x72702d70 /* "p-pr" */
212
+#define _efer_ 0x72656665 /* "efer" */
213
+#define _red__ 0x2d646572 /* "red-" */
214
+/* _iden_ is already defined */
215
+/* _tity_ is already defined */
216
+
197 217
 /*!} */
198 218
 
199 219
 #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 154
 	case _retr_: retr_CASE; \
153 155
 	case _path_: path_CASE; \
154 156
 	case _priv_: priv_CASE; \
155
-	case _reas_: reas_CASE;
157
+	case _reas_: reas_CASE; \
158
+	case _p_as_: p_as_CASE; \
159
+	case _p_pr_: p_pr_CASE;
156 160
 
157 161
 
158 162
 #define PARSE_COMPACT(id)          \
... ...
@@ -168,7 +172,7 @@ static inline char* skip_ws(char* p, unsigned int size)
168 172
 	        return (p + 2);    \
169 173
         }
170 174
 
171
-
175
+#if 0
172 176
 int hdr_update_type(struct hdr_field* hdr)
173 177
 {
174 178
 	if(hdr==0 || hdr->name.s==0)
... ...
@@ -186,6 +190,7 @@ int hdr_update_type(struct hdr_field* hdr)
186 190
 
187 191
 	return 0;
188 192
 }
193
+#endif
189 194
 
190 195
 char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
191 196
 {
... ...
@@ -266,7 +271,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
266 271
 	} else {
267 272
 		hdr->type = HDR_OTHER_T;
268 273
 		hdr->name.len = p - hdr->name.s;
269
-		hdr_update_type(hdr);
274
+		/*hdr_update_type(hdr);*/
270 275
 		return (p + 1);
271 276
 	}
272 277
 }