Browse code

An update to the methods parser

List if changes:
* METHOD_REFER defined in msg_parser.h
* Changed the prototype of parse_method to use enum request_type
* Define ALL_METHODS macro
* Replace METH_* with METHOD_*

Jan Janak authored on 31/03/2009 11:32:31
Showing 3 changed files
... ...
@@ -79,7 +79,7 @@
79 79
 enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4,
80 80
 	METHOD_BYE=8, METHOD_INFO=16, METHOD_REGISTER=32, METHOD_SUBSCRIBE=64,
81 81
 	METHOD_NOTIFY=128, METHOD_MESSAGE=256, METHOD_OPTIONS=512,
82
-	METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_OTHER=4096 };
82
+	METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_REFER = 4096, METHOD_OTHER=8192 };
83 83
 
84 84
 #define FL_FORCE_RPORT  (1 << 0)  /* force rport */
85 85
 #define FL_FORCE_ACTIVE (1 << 1)  /* force active SDP */
... ...
@@ -49,7 +49,7 @@ static int token_char(char _c)
49 49
   * Parse a method pointed by _next, assign its enum bit to _method, and update
50 50
   * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
51 51
   */
52
-int parse_method(str* _next, unsigned int* _method) 
52
+int parse_method(str* _next, enum request_method* _method) 
53 53
  {
54 54
 	 if (!_next || !_method) {
55 55
 		 LOG(L_ERR, "parse_method: Invalid parameter value\n");
... ...
@@ -65,7 +65,7 @@ int parse_method(str* _next, unsigned int* _method)
65 65
 	 case 'A':
66 66
 	 case 'a':
67 67
 		 if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ck", 2)) {
68
- 			*_method = METH_ACK;
68
+ 			*_method = METHOD_ACK;
69 69
  			_next->len -= 3;
70 70
  			_next->s += 3;
71 71
  			return 1;
... ...
@@ -76,7 +76,7 @@ int parse_method(str* _next, unsigned int* _method)
76 76
  	case 'B':
77 77
  	case 'b':
78 78
  		if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ye", 2)) {
79
- 			*_method = METH_BYE;
79
+ 			*_method = METHOD_BYE;
80 80
  			_next->len -= 3;
81 81
  			_next->s += 3;
82 82
  			return 1;
... ...
@@ -87,7 +87,7 @@ int parse_method(str* _next, unsigned int* _method)
87 87
  	case 'C':
88 88
  	case 'c':
89 89
  		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "ancel", 5)) {
90
- 			*_method = METH_CANCEL;
90
+ 			*_method = METHOD_CANCEL;
91 91
  			_next->len -= 6;
92 92
  			_next->s += 6;
93 93
  			return 1;
... ...
@@ -100,14 +100,14 @@ int parse_method(str* _next, unsigned int* _method)
100 100
  		if ((_next->len > 3) &&
101 101
  		    ((*(_next->s + 1) == 'N') || (*(_next->s + 1) == 'n'))) {
102 102
  			if (!strncasecmp(_next->s + 2, "fo", 2)) {
103
- 				*_method = METH_INFO;
103
+ 				*_method = METHOD_INFO;
104 104
  				_next->len -= 4;
105 105
  				_next->s += 4;
106 106
  				return 1;
107 107
  			}
108 108
 
109 109
  			if ((_next->len > 5) && !strncasecmp(_next->s + 2, "vite", 4)) {
110
- 				*_method = METH_INVITE;
110
+ 				*_method = METHOD_INVITE;
111 111
  				_next->len -= 6;
112 112
  				_next->s += 6;
113 113
  				return 1;
... ...
@@ -118,7 +118,7 @@ int parse_method(str* _next, unsigned int* _method)
118 118
  	case 'M':
119 119
  	case 'm':
120 120
  		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "essage", 6)) {
121
- 			*_method = METH_MESSAGE;
121
+ 			*_method = METHOD_MESSAGE;
122 122
  			_next->len -= 7;
123 123
  			_next->s += 7;
124 124
  			return 1;
... ...
@@ -129,7 +129,7 @@ int parse_method(str* _next, unsigned int* _method)
129 129
  	case 'N':
130 130
  	case 'n':
131 131
  		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "otify", 5)) {
132
- 			*_method = METH_NOTIFY;
132
+ 			*_method = METHOD_NOTIFY;
133 133
  			_next->len -= 6;
134 134
  			_next->s += 6;
135 135
  			return 1;
... ...
@@ -140,7 +140,7 @@ int parse_method(str* _next, unsigned int* _method)
140 140
  	case 'O':
141 141
  	case 'o':
142 142
  		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ptions", 6)) {
143
- 			*_method = METH_OPTIONS;
143
+ 			*_method = METHOD_OPTIONS;
144 144
  			_next->len -= 7;
145 145
  			_next->s += 7;
146 146
  			return 1;
... ...
@@ -151,7 +151,7 @@ int parse_method(str* _next, unsigned int* _method)
151 151
  	case 'P':
152 152
  	case 'p':
153 153
  		if ((_next->len > 4) && !strncasecmp(_next->s + 1, "rack", 4)) {
154
- 			*_method = METH_PRACK;
154
+ 			*_method = METHOD_PRACK;
155 155
  			_next->len -= 5;
156 156
  			_next->s += 5;
157 157
  			return 1;
... ...
@@ -164,14 +164,14 @@ int parse_method(str* _next, unsigned int* _method)
164 164
  		if ((_next->len > 4) &&
165 165
  		    ((*(_next->s + 1) == 'E') || (*(_next->s + 1) == 'e'))) {
166 166
  			if (!strncasecmp(_next->s + 2, "fer", 3)) {
167
- 				*_method = METH_REFER;
167
+ 				*_method = METHOD_REFER;
168 168
  				_next->len -= 5;
169 169
  				_next->s += 5;
170 170
  				return 1;
171 171
  			}
172 172
 
173 173
  			if ((_next->len > 7) && !strncasecmp(_next->s + 2, "gister", 6)) {
174
- 				*_method = METH_REGISTER;
174
+ 				*_method = METHOD_REGISTER;
175 175
  				_next->len -= 8;
176 176
  				_next->s += 8;
177 177
  				return 1;
... ...
@@ -182,7 +182,7 @@ int parse_method(str* _next, unsigned int* _method)
182 182
  	case 'S':
183 183
  	case 's':
184 184
  		if ((_next->len > 8) && !strncasecmp(_next->s + 1, "ubscribe", 8)) {
185
- 			*_method = METH_SUBSCRIBE;
185
+ 			*_method = METHOD_SUBSCRIBE;
186 186
  			_next->len -= 9;
187 187
  			_next->s += 9;
188 188
  			return 1;
... ...
@@ -193,7 +193,7 @@ int parse_method(str* _next, unsigned int* _method)
193 193
  	case 'U':
194 194
  	case 'u':
195 195
  		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "pdate", 5)) {
196
- 			*_method = METH_UPDATE;
196
+ 			*_method = METHOD_UPDATE;
197 197
  			_next->len -= 6;
198 198
  			_next->s += 6;
199 199
  			return 1;
... ...
@@ -211,7 +211,7 @@ int parse_method(str* _next, unsigned int* _method)
211 211
  			_next->s++;
212 212
  			_next->len--;
213 213
  		} while (_next->len && token_char(*(_next->s)));
214
- 		*_method = METH_UNKNOWN;
214
+ 		*_method = METHOD_OTHER;
215 215
  		return 1;
216 216
  	} else {
217 217
  		return 0;
... ...
@@ -29,27 +29,9 @@
29 29
 #define PARSE_METHODS_H
30 30
 
31 31
 #include "../str.h"
32
+#include "msg_parser.h"
32 33
 
33
-/*
34
- * Methods found in methods Contact parameter or Allow header.
35
- */
36
-enum method {
37
-	METH_UNKNOWN = 1, 
38
-	METH_ACK = 2, 
39
-	METH_BYE = 4, 
40
-	METH_CANCEL = 8,
41
-	METH_INFO = 16, 
42
-	METH_INVITE = 32, 
43
-	METH_NOTIFY = 64,
44
-	METH_OPTIONS = 128, 
45
-	METH_PRACK = 256, 
46
-	METH_REGISTER  = 512,
47
-	METH_SUBSCRIBE = 1024, 
48
-	METH_UPDATE = 2048, 
49
-	METH_MESSAGE = 4096,
50
-	METH_REFER = 8192
51
-};
52
-
34
+#define ALL_METHODS 0xffffffff
53 35
 
54 36
 /* 
55 37
  * Parse comma separated list of methods pointed by _body and assign their
... ...
@@ -57,7 +39,7 @@ enum method {
57 57
  */
58 58
 int parse_methods(str* _body, unsigned int* _methods);
59 59
 
60
-int parse_method(str* _next, unsigned int* _method);
60
+int parse_method(str* _next, enum request_method* _method);
61 61
 
62 62
 
63 63
 #endif /* PARSE_METHODS_H */