Browse code

Allow parser syn'ced with kamailio version

Sync'ed parse_allow_header() prototype name with implementation. New
parse_allow() function that work over sim_msg structure

Signed-off-by: Jan Janak <jan@iptel.org>

Daniel-Constantin Mierla authored on 20/03/2009 16:19:22
Showing 3 changed files
... ...
@@ -52,6 +52,7 @@
52 52
 #include "parse_subscription_state.h"
53 53
 #include "contact/parse_contact.h"
54 54
 #include "parse_disposition.h"
55
+#include "parse_allow.h"
55 56
 #include "../ut.h"
56 57
 
57 58
 
... ...
@@ -138,6 +139,7 @@ void clean_hdr_field(struct hdr_field* hf)
138 138
 			break;
139 139
 
140 140
 		case HDR_ALLOW_T:
141
+			free_allow_header(hf);
141 142
 			break;
142 143
 
143 144
 		case HDR_EVENT_T:
... ...
@@ -43,41 +43,88 @@
43 43
  */
44 44
 int parse_allow_header(struct hdr_field* _hf)
45 45
 {
46
-	unsigned int* methods;
47
-	
46
+	struct allow_body* ab = 0;
47
+
48 48
 	if (!_hf) {
49 49
 		LOG(L_ERR, "parse_allow_header: Invalid parameter value\n");
50 50
 		return -1;
51 51
 	}
52 52
 	
53
-	     /* maybe the header is already parsed! */
53
+	/* maybe the header is already parsed! */
54 54
  	if (_hf->parsed) {
55 55
  		return 0;
56 56
 	}
57 57
 
58
-	     /* bad luck! :-( - we have to parse it */
59
-	methods = pkg_malloc(sizeof(unsigned int));
60
- 	if (methods == 0) {
61
- 		LOG(L_ERR, "ERROR:parse_allow_header: Out of pkg_memory\n");
62
- 		return -1;
63
- 	}
58
+	ab = (struct allow_body*)pkg_malloc(sizeof(struct allow_body));
59
+	if (ab == 0) {
60
+		LOG(L_ERR, "ERROR:parse_allow_header: out of pkg_memory\n");
61
+		return -1;
62
+	}
63
+	memset(ab,'\0', sizeof(struct allow_body));
64
+	
65
+	if (parse_methods(&(_hf->body), &(ab->allow)) !=0 ) {
66
+		LOG(L_ERR, "ERROR:parse_allow_header: bad allow body header\n");		
67
+		goto error;
68
+	}
69
+	
70
+	ab->allow_all = 0;	
71
+	_hf->parsed = (void*)ab;
72
+ 	return 0;
73
+
74
+error:
75
+	if (ab) pkg_free(ab);
76
+	return -1;
77
+}
78
+
79
+/*!
80
+ * \brief This method is used to parse all Allow HF body.
81
+ * \param msg sip msg
82
+ * \return 0 on success,-1 on failure.
83
+ */
84
+int parse_allow(struct sip_msg *msg)
85
+{       
86
+	unsigned int allow;
87
+	struct hdr_field  *hdr;
88
+
89
+	/* maybe the header is already parsed! */
90
+	if (msg->allow && msg->allow->parsed) {
91
+		return 0;
92
+	}
64 93
 
65
-	if (!parse_methods(&(_hf->body), methods)) {
66
- 		LOG(L_ERR, "ERROR:parse_allow_header: Bad allow header\n"); 
67
- 		pkg_free(methods);
94
+	/* parse to the end in order to get all ALLOW headers */
95
+	if (parse_headers(msg,HDR_EOH_F,0)==-1 || !msg->allow) {
68 96
 		return -1;
69
- 	}
97
+	}
98
+	allow = 0;
70 99
 
71
- 	_hf->parsed = methods;
72
- 	return 0;
100
+	for(hdr = msg->allow ; hdr ; hdr = next_sibling_hdr(hdr)) {
101
+		if (hdr->parsed == 0) {
102
+			if(parse_allow_header(hdr) < 0) {
103
+				return -1;
104
+			}
105
+		}
106
+
107
+		allow |= ((struct allow_body*)hdr->parsed)->allow;
108
+	}
109
+	
110
+	((struct allow_body*)msg->allow->parsed)->allow_all = allow;
111
+    return 0;
73 112
 }
74 113
 
75 114
 
76 115
 /*
77 116
  * Release memory
78 117
  */
79
-void free_allow(unsigned int** _methods)
118
+void free_allow_body(struct allow_body **ab)
119
+{
120
+	if (ab && *ab) {	
121
+		pkg_free(*ab);		
122
+		*ab = 0;
123
+	}
124
+}
125
+
126
+
127
+void free_allow_header(struct hdr_field* hf)
80 128
 {
81
-	if (_methods && *_methods) pkg_free(*_methods);
82
-	*_methods = 0;
129
+	free_allow_body((struct allow_body**)(void*)(&(hf->parsed)));
83 130
 }
... ...
@@ -29,23 +29,43 @@
29 29
 #define PARSE_ALLOW_H
30 30
  
31 31
 #include "hf.h"
32
+#include "msg_parser.h"
32 33
 
33 34
  
34 35
 /* 
35
- * casting macro for accessing RPID body 
36
+ * casting macro for accessing Allow body 
36 37
  */
37
-#define get_allow_methods(p_msg) (unsigned int)(p_msg)->allow->parsed)
38
+#define get_allow_methods(p_msg)							\
39
+	(((struct allow_body*)(p_msg)->allow->parsed)->allow_all)
40
+
41
+
42
+struct allow_body {
43
+	unsigned int allow;     /* allow mask for the current hdr */
44
+	unsigned int allow_all; /* allow mask for the all allow hdr - it's
45
+							 * set only for the first hdr in sibling
46
+							 * list*/
47
+};
48
+
49
+
50
+/*
51
+ * Parse all Allow HFs
52
+ */
53
+int parse_allow(struct sip_msg *msg);
38 54
 
39 55
 
40 56
 /*
41 57
  * Parse Allow HF body
42 58
  */
43
-int parse_allow(struct hdr_field* _h);
59
+int parse_allow_header(struct hdr_field* _h);
44 60
 
45 61
 
46 62
 /*
47 63
  * Release memory
48 64
  */
49
-void free_allow(unsigned int** _methods);
65
+void free_allow_body(struct allow_body **ab);
66
+
67
+void free_allow_header(struct hdr_field* hf);
68
+
69
+
50 70
 
51 71
 #endif /* PARSE_ALLOW_H */