[sr-dev] git:master: core: PAI & PPI header names parser fixes

Andrei Pelinescu-Onciul andrei at iptel.org
Fri Feb 19 12:01:03 CET 2010


Module: sip-router
Branch: master
Commit: 0cf3f38542375fd83d8071cd3cfa0571cf8984fb
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0cf3f38542375fd83d8071cd3cfa0571cf8984fb

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Fri Feb 19 11:55:44 2010 +0100

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).

---

 parser/case_p_as.h    |   87 +++++++++++++++++++++++++++++++++++++++++++++++++
 parser/case_p_pr.h    |   83 ++++++++++++++++++++++++++++++++++++++++++++++
 parser/keys.h         |   20 +++++++++++
 parser/parse_hname2.c |   13 +++++--
 4 files changed, 199 insertions(+), 4 deletions(-)

diff --git a/parser/case_p_as.h b/parser/case_p_as.h
new file mode 100644
index 0000000..46d929b
--- /dev/null
+++ b/parser/case_p_as.h
@@ -0,0 +1,87 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2010 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * parser/case_p_as.h
+ */
+/*
+ * History:
+ * --------
+ *  2010-02-19  initial version (andrei)
+*/
+
+/** Parser :: Reason Header Name Parsing Macros.
+ * @file 
+ *
+ * @ingroup parser
+ */
+
+#ifndef __case_p_as_h
+#define __case_p_as_h
+
+
+#define SERT_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _sert_:					\
+			p += 4;						\
+			val = READ(p);				\
+			ED_I_CASE;					\
+	}									
+
+
+#define ED_I_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _ed_i_:					\
+			p += 4;						\
+			val = READ(p);				\
+			DENT_CASE;					\
+	}									
+
+
+#define DENT_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _dent_:					\
+			p += 4;						\
+			val = READ(p);				\
+			ITY_CASE;					\
+	}									
+
+#define ITY_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _ity1_:					\
+			hdr->type = HDR_PAI_T;		\
+			hdr->name.len = 19;			\
+			return (p + 4);				\
+		case _ity2_:					\
+			hdr->type = HDR_PAI_T;		\
+			p+=4;						\
+			goto dc_end;				\
+	}									
+
+
+
+#define p_as_CASE		\
+	p += 4;				\
+	val = READ(p);		\
+	SERT_CASE;			\
+	goto other;
+
+
+
+#endif /*__case_p_as_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/parser/case_p_pr.h b/parser/case_p_pr.h
new file mode 100644
index 0000000..7f43a64
--- /dev/null
+++ b/parser/case_p_pr.h
@@ -0,0 +1,83 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2010 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * parser/case_p_pr.h
+ */
+/*
+ * History:
+ * --------
+ *  2010-02-19  initial version (andrei)
+*/
+
+/** Parser :: Reason Header Name Parsing Macros.
+ * @file 
+ *
+ * @ingroup parser
+ */
+
+#ifndef __case_p_pr_h
+#define __case_p_pr_h
+
+
+#define EFER_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _efer_:					\
+			p += 4;						\
+			val = READ(p);				\
+			RED__CASE;					\
+	}									
+
+
+#define RED__CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _red__:					\
+			p += 4;						\
+			val = READ(p);				\
+			IDEN_CASE;					\
+	}									
+
+
+#define IDEN_CASE						\
+	switch(LOWER_DWORD(val)) {			\
+		case _iden_:					\
+			p += 4;						\
+			val = READ(p);				\
+			TITY_p_pr_CASE;				\
+	}									
+
+#define TITY_p_pr_CASE					\
+	switch(LOWER_DWORD(val)) {			\
+		case _tity_:					\
+			hdr->type = HDR_PPI_T;		\
+			p+=4;						\
+			goto dc_end;				\
+	}									
+
+
+
+#define p_pr_CASE		\
+	p += 4;				\
+	val = READ(p);		\
+	EFER_CASE;			\
+	goto other;
+
+
+
+#endif /*__case_p_pr_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/parser/keys.h b/parser/keys.h
index 3fb8441..74bab82 100644
--- a/parser/keys.h
+++ b/parser/keys.h
@@ -43,6 +43,13 @@
  * 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
 \endverbatim
  *
+ * A quick way to generate the hex string is:
+ *  perl -e '$_=lc shift; print "0x".unpack("H*",reverse)."\n";' 4_char_str
+ * or to generate the define list:
+    perl -e '$s=lc shift; $s.=" "x(4-(length $s)%4);
+             print map("#define _". reverse ."_ 0x". (unpack "H*")."\n",
+                       reverse unpack("(a[4])*", reverse $s));'  string
+ * Note that some editing is still needed (replace spaces and account for ':').
  * Test manually/visually if dword is intended string using:
  * 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
  *
@@ -194,6 +201,19 @@
 #define _on2_ 0x3a206e6f  /* "on :" */
 #define _on3_ 0x20206e6f  /* "on  " */
 
+#define _p_as_ 0x73612d70 /* "p-as" */
+#define _sert_ 0x74726573 /* "sert" */
+#define _ed_i_ 0x692d6465 /* "ed-i" */
+#define _dent_ 0x746e6564 /* "dent" */
+#define _ity1_ 0x3a797469 /* "ity:" */
+#define _ity2_ 0x20797469 /* "ity " */
+
+#define _p_pr_ 0x72702d70 /* "p-pr" */
+#define _efer_ 0x72656665 /* "efer" */
+#define _red__ 0x2d646572 /* "red-" */
+/* _iden_ is already defined */
+/* _tity_ is already defined */
+
 /*!} */
 
 #endif /* KEYS_H */
diff --git a/parser/parse_hname2.c b/parser/parse_hname2.c
index 5e799ce..d541a4c 100644
--- a/parser/parse_hname2.c
+++ b/parser/parse_hname2.c
@@ -103,7 +103,9 @@ static inline char* skip_ws(char* p, unsigned int size)
 #include "case_retr.h"     /* Retry-After */
 #include "case_path.h"     /* Path */
 #include "case_priv.h"
-#include "case_reas.h"
+#include "case_reas.h"     /* Reason */
+#include "case_p_as.h"     /* P-Asserted-Identity */
+#include "case_p_pr.h"     /* P-Preferred-Identity */
 
 /*@} */
 
@@ -152,7 +154,9 @@ static inline char* skip_ws(char* p, unsigned int size)
 	case _retr_: retr_CASE; \
 	case _path_: path_CASE; \
 	case _priv_: priv_CASE; \
-	case _reas_: reas_CASE;
+	case _reas_: reas_CASE; \
+	case _p_as_: p_as_CASE; \
+	case _p_pr_: p_pr_CASE;
 
 
 #define PARSE_COMPACT(id)          \
@@ -168,7 +172,7 @@ static inline char* skip_ws(char* p, unsigned int size)
 	        return (p + 2);    \
         }
 
-
+#if 0
 int hdr_update_type(struct hdr_field* hdr)
 {
 	if(hdr==0 || hdr->name.s==0)
@@ -186,6 +190,7 @@ int hdr_update_type(struct hdr_field* hdr)
 
 	return 0;
 }
+#endif
 
 char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
 {
@@ -266,7 +271,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
 	} else {
 		hdr->type = HDR_OTHER_T;
 		hdr->name.len = p - hdr->name.s;
-		hdr_update_type(hdr);
+		/*hdr_update_type(hdr);*/
 		return (p + 1);
 	}
 }




More information about the sr-dev mailing list