Browse code

core: support for parsing the Reason header

Andrei Pelinescu-Onciul authored on 18/02/2010 20:20:07
Showing 8 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,71 @@
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_reas.h
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2010-02-18  initial version (andrei)
24
+*/
25
+
26
+/** Parser :: Reason Header Name Parsing Macros.
27
+ * @file 
28
+ *
29
+ * @ingroup parser
30
+ */
31
+#ifndef __case_reas_h
32
+#define __case_reas_h
33
+
34
+
35
+#define ON_CASE							\
36
+	switch(LOWER_DWORD(val)) {			\
37
+		case _on1_:						\
38
+			hdr->type = HDR_REASON_T;	\
39
+			hdr->name.len = 6;			\
40
+			return (p + 3);				\
41
+		case _on2_:						\
42
+			hdr->type = HDR_REASON_T;	\
43
+			hdr->name.len = 7;			\
44
+			return (p + 4);				\
45
+		case _on3_:						\
46
+			hdr->type = HDR_REASON_T;	\
47
+			p+=4;						\
48
+			goto dc_end;				\
49
+	}									\
50
+	if ((LOWER_DWORD(val)&0x00ffffff) ==\
51
+				(_on1_&0x00ffffff)){	\
52
+			hdr->type = HDR_REASON_T;	\
53
+			hdr->name.len = 6;			\
54
+			return (p+3);				\
55
+	}
56
+
57
+
58
+
59
+#define reas_CASE		\
60
+	p += 4;				\
61
+	val = READ(p);		\
62
+	ON_CASE;			\
63
+	goto other;
64
+
65
+
66
+
67
+
68
+#endif /*__case_reas_h*/
69
+
70
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -33,10 +33,9 @@
33 33
  * 2007-07-27 added HDR_RETRY_AFTER_T (andrei)
34 34
  */
35 35
 
36
-/*! \file 
37
- * \brief Parser :: 
38
- *
39
- * \ingroup parser
36
+/** Parser :: parse header files
37
+ * @file
38
+ * @ingroup parser
40 39
  */
41 40
 
42 41
 
... ...
@@ -61,8 +60,7 @@
61 61
 #include "parse_allow.h"
62 62
 #include "../ut.h"
63 63
 
64
-/*! \brief
65
- * Frees a hdr_field structure,
64
+/** Frees a hdr_field structure.
66 65
  * WARNING: it frees only parsed (and not name.s, body.s)
67 66
  */
68 67
 void clean_hdr_field(struct hdr_field* hf)
... ...
@@ -220,6 +218,7 @@ void clean_hdr_field(struct hdr_field* hf)
220 220
 		case HDR_PROXY_AUTHENTICATE_T:
221 221
 		case HDR_PATH_T:
222 222
 		case HDR_PRIVACY_T:
223
+		case HDR_REASON_T:
223 224
 			break;
224 225
 
225 226
 		case HDR_PPI_T:
... ...
@@ -239,8 +238,7 @@ void clean_hdr_field(struct hdr_field* hf)
239 239
 }
240 240
 
241 241
 
242
-/*! \brief
243
- * Frees a hdr_field list,
242
+/** Frees a hdr_field list.
244 243
  * WARNING: frees only ->parsed and ->next*/
245 244
 void free_hdr_field_lst(struct hdr_field* hf)
246 245
 {
... ...
@@ -35,10 +35,10 @@
35 35
  * 2007-07-27 HDR_RETRY_AFTER_[TF] added (andrei)
36 36
  */
37 37
 
38
-/*! \file 
39
- * \brief Parser :: ???
38
+/** Parser :: parse headers.
39
+ * @file 
40 40
  *
41
- * \ingroup parser
41
+ * @ingroup parser
42 42
  */
43 43
 
44 44
 
... ...
@@ -51,9 +51,9 @@
51 51
 
52 52
 
53 53
 
54
-/*! \brief header type enum
54
+/** header types enum.
55 55
  * 
56
- * \note
56
+ * @note
57 57
  * if you add a new type:
58 58
  *  - make sure it's not greater than 63
59 59
  *  - make sure you add the corresponding flag to the hdr_flags_t defs below
... ...
@@ -116,25 +116,26 @@ enum _hdr_types_t {
116 116
 	HDR_IDENTITY_T			       /*!< Identity header field */,
117 117
 	HDR_IDENTITY_INFO_T		       /*!< Identity-info header field */,
118 118
 	HDR_RETRY_AFTER_T		           /*!< Retry-After header field */,
119
-	HDR_PPI_T                          /*!< P-Preferred-Identity header field */,
120
-	HDR_PAI_T                          /*!< P-Asserted-Identity header field */,
119
+	HDR_PPI_T                          /*!< P-Preferred-Identity header field*/,
120
+	HDR_PAI_T                          /*!< P-Asserted-Identity header field*/,
121 121
 	HDR_PATH_T                         /*!< Path header field */,
122 122
 	HDR_PRIVACY_T				       /*!< Privacy header field */,
123
+	HDR_REASON_T				       /**< Reason header field */,
123 124
 	HDR_EOH_T					       /*!< End of message header */
124 125
 };
125 126
 
126 127
 
127 128
 typedef unsigned long long hdr_flags_t;
128 129
 
129
-/*! \brief type to flag conversion
130
+/** type to flag conversion.
130 131
  * WARNING: HDR_ERROR_T has no corresponding FLAG ! */
131 132
 #define HDR_T2F(type)	\
132 133
 		(((type)!=HDR_EOH_T)?((hdr_flags_t)1<<(type)):(~(hdr_flags_t)0))
133 134
 
134
-/*! \brief helper macro for easy defining and keeping in sync. the flags enum */
135
+/** helper macro for easy defining and keeping in sync the flags enum. */
135 136
 #define HDR_F_DEF(name)		HDR_T2F(HDR_##name##_T)
136 137
 
137
-/*! \name flags definitions
138
+/** @name flags definitions.
138 139
  * (enum won't work with all the compiler (e.g. icc) due to the 64bit size) */
139 140
 /*!{ */
140 141
 #define HDR_EOH_F					HDR_F_DEF(EOH)
... ...
@@ -192,6 +193,7 @@ typedef unsigned long long hdr_flags_t;
192 192
 #define HDR_PAI_F                   HDR_F_DEF(PAI)
193 193
 #define HDR_PATH_F                  HDR_F_DEF(PATH)
194 194
 #define HDR_PRIVACY_F               HDR_F_DEF(PRIVACY)
195
+#define HDR_REASON_F				HDR_F_DEF(REASON)
195 196
 
196 197
 #define HDR_OTHER_F					HDR_F_DEF(OTHER)
197 198
 
... ...
@@ -199,8 +201,7 @@ typedef unsigned long long hdr_flags_t;
199 199
 
200 200
 typedef enum _hdr_types_t hdr_types_t;
201 201
 
202
-/*! \brief
203
- * Format: name':' body
202
+/** Format: name':' body.
204 203
  */
205 204
 typedef struct hdr_field {
206 205
 	hdr_types_t type;       /*!< Header field type */
... ...
@@ -213,7 +214,7 @@ typedef struct hdr_field {
213 213
 
214 214
 
215 215
 
216
-/*! \brief returns true if the header links allocated memory on parse field */
216
+/** returns true if the header links allocated memory on parse field. */
217 217
 static inline int hdr_allocs_parse(struct hdr_field* hdr)
218 218
 {
219 219
 	switch(hdr->type){
... ...
@@ -239,13 +240,13 @@ static inline int hdr_allocs_parse(struct hdr_field* hdr)
239 239
 	}
240 240
 }
241 241
 
242
-/*! \brief frees a hdr_field structure,
242
+/** frees a hdr_field structure.
243 243
  * WARNING: it frees only parsed (and not name.s, body.s)
244 244
  */
245 245
 void clean_hdr_field(struct hdr_field* hf);
246 246
 
247 247
 
248
-/*! \brief frees a hdr_field list,
248
+/** frees a hdr_field list.
249 249
  * WARNING: frees only ->parsed and ->next
250 250
  */
251 251
 void free_hdr_field_lst(struct hdr_field* hf);
... ...
@@ -29,10 +29,9 @@
29 29
  * 2007-01-26 Macros for Identity, Identity-info, Date added (gergo)
30 30
  */
31 31
 
32
-/*! \file 
33
- * \brief Parser :: Fast 32-bit Header Field Name Parser -- keys
34
- *
35
- * \ingroup parser
32
+/** Parser :: Fast 32-bit Header Field Name Parser -- keys .
33
+ * @file
34
+ * @ingroup parser
36 35
  */
37 36
 
38 37
 #ifndef KEYS_H
... ...
@@ -190,6 +189,11 @@
190 190
 #define _acy2_ 0x20796361   /* "acy " */
191 191
 #define _acy1_ 0x3a796361   /* "acy:" */
192 192
 
193
+#define _reas_ 0x73616572  /* "reas" */
194
+#define _on1_ 0x203a6e6f  /* "on: " */
195
+#define _on2_ 0x3a206e6f  /* "on :" */
196
+#define _on3_ 0x20206e6f  /* "on  " */
197
+
193 198
 /*!} */
194 199
 
195 200
 #endif /* KEYS_H */
... ...
@@ -41,10 +41,9 @@
41 41
  *		header fields (gergo)
42 42
  */
43 43
 
44
-/*! \file 
45
- * \brief Parser :: SIP Message header proxy parser
46
- *
47
- * \ingroup parser
44
+/** Parser :: SIP Message header proxy parser.
45
+ * @file
46
+ * @ingroup parser
48 47
  */
49 48
 
50 49
 /*! \defgroup parser SIP-router SIP message parser
... ...
@@ -254,10 +253,11 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
254 254
 		case HDR_REQUESTDISPOSITION_T:
255 255
 		case HDR_WWW_AUTHENTICATE_T:
256 256
 		case HDR_PROXY_AUTHENTICATE_T:
257
-	    case HDR_PATH_T:
258
-	    case HDR_PRIVACY_T:
259
-	    case HDR_PAI_T:
260
-	    case HDR_PPI_T:
257
+		case HDR_PATH_T:
258
+		case HDR_PRIVACY_T:
259
+		case HDR_PAI_T:
260
+		case HDR_PPI_T:
261
+		case HDR_REASON_T:
261 262
 		case HDR_OTHER_T:
262 263
 			/* just skip over it */
263 264
 			hdr->body.s=tmp;
... ...
@@ -553,6 +553,9 @@ int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next)
553 553
 				if (msg->ppi==0) msg->ppi=hf;
554 554
 				msg->parsed_flag|=HDR_PPI_F;
555 555
 				break;
556
+		    case HDR_REASON_T:
557
+				msg->parsed_flag|=HDR_REASON_F;
558
+				break;
556 559
 			default:
557 560
 				LOG(L_CRIT, "BUG: parse_headers: unknown header type %d\n",
558 561
 							hf->type);
... ...
@@ -35,10 +35,9 @@
35 35
  * 2007-07-27 added support for Retry-After (andrei)
36 36
  */
37 37
 
38
-/*! \file
39
- * \brief Parser :: Fast 32-bit Header Field Name Parser
40
- *
41
- * \ingroup parser
38
+/** Parser :: Fast 32-bit Header Field Name Parser.
39
+ * @file
40
+ * @ingroup parser
42 41
  */
43 42
 
44 43
 #include "../comp_defs.h"
... ...
@@ -49,9 +48,7 @@
49 49
 #define LOWER_BYTE(b) ((b) | 0x20)
50 50
 #define LOWER_DWORD(d) ((d) | 0x20202020)
51 51
 
52
-/*! \brief
53
- * Skip all white-chars and return position of the first
54
- * non-white char
52
+/** Skip all white-chars and return position of the first non-white char.
55 53
  */
56 54
 static inline char* skip_ws(char* p, unsigned int size)
57 55
 {
... ...
@@ -106,6 +103,7 @@ static inline char* skip_ws(char* p, unsigned int size)
106 106
 #include "case_retr.h"     /* Retry-After */
107 107
 #include "case_path.h"     /* Path */
108 108
 #include "case_priv.h"
109
+#include "case_reas.h"
109 110
 
110 111
 /*@} */
111 112
 
... ...
@@ -152,8 +150,9 @@ static inline char* skip_ws(char* p, unsigned int size)
152 152
 	case _date_: date_CASE; \
153 153
 	case _iden_: iden_CASE; \
154 154
 	case _retr_: retr_CASE; \
155
-    case _path_: path_CASE; \
156
-	case _priv_: priv_CASE;
155
+	case _path_: path_CASE; \
156
+	case _priv_: priv_CASE; \
157
+	case _reas_: reas_CASE;
157 158
 
158 159
 
159 160
 #define PARSE_COMPACT(id)          \
... ...
@@ -34,8 +34,8 @@
34 34
 #include "hf.h"
35 35
 
36 36
 
37
-/*! \brief
38
- * Fast 32-bit header field name parser
37
+/** Fast 32-bit header field name parser.
38
+ * @file
39 39
  */
40 40
 char* parse_hname2(char* begin, char* end, struct hdr_field* hdr);
41 41
 
... ...
@@ -24,11 +24,10 @@
24 24
  *  2009-07-22  initial version: functions moved from tm/sip_msg.c (andrei)
25 25
 */
26 26
 
27
-/*!
28
- * \file
29
- * \brief SIP-router core :: 
30
- * \ingroup core
31
- * Module: \ref core
27
+/** SIP-router core :: sip message shared memory cloner.
28
+ * @file
29
+ * @ingroup core
30
+ * Module: @ref core
32 31
  */
33 32
 
34 33
 #include "sip_msg_clone.h"
... ...
@@ -488,6 +487,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
488 488
 		case HDR_PAI_T:
489 489
 		case HDR_PATH_T:
490 490
 		case HDR_PRIVACY_T:
491
+		case HDR_REASON_T:
491 492
 			/* we ignore them for now even if they have something parsed*/
492 493
 			break;
493 494
 		}/*switch*/
... ...
@@ -617,6 +617,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
617 617
 		case HDR_IDENTITY_T:
618 618
 		case HDR_IDENTITY_INFO_T:
619 619
 		case HDR_RETRY_AFTER_T:
620
+		case HDR_REASON_T:
620 621
 			break;
621 622
 
622 623
 		case HDR_VIA_T: