Browse code

parser: added METHOD_PUBLISH

- new bit flag allocated for PUBLISH
- parse_method() supports now METHOD_PUBLISH
- parse_methods() returns 0 on success and -1 on error as it is expected
by all use cases

Daniel-Constantin Mierla authored on 16/04/2009 22:33:43
Showing 2 changed files
... ...
@@ -76,10 +76,24 @@
76 76
 #define SIP_MSG_START(m)	((m)->first_line.u.request.method.s)
77 77
 
78 78
 /* number methods as power of two to allow bitmap matching */
79
-enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4,
80
-	METHOD_BYE=8, METHOD_INFO=16, METHOD_REGISTER=32, METHOD_SUBSCRIBE=64,
81
-	METHOD_NOTIFY=128, METHOD_MESSAGE=256, METHOD_OPTIONS=512,
82
-	METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_REFER = 4096, METHOD_OTHER=8192 };
79
+enum request_method {
80
+	METHOD_UNDEF=0,           /* 0 - --- */
81
+	METHOD_INVITE=1,          /* 1 - 2^0 */
82
+	METHOD_CANCEL=2,          /* 2 - 2^1 */
83
+	METHOD_ACK=4,             /* 3 - 2^2 */
84
+	METHOD_BYE=8,             /* 4 - 2^3 */
85
+	METHOD_INFO=16,           /* 5 - 2^4 */
86
+	METHOD_REGISTER=32,       /* 6 - 2^5 */
87
+	METHOD_SUBSCRIBE=64,      /* 7 - 2^6 */
88
+	METHOD_NOTIFY=128,        /* 8 - 2^7 */
89
+	METHOD_MESSAGE=256,       /* 9 - 2^8 */
90
+	METHOD_OPTIONS=512,       /* 10 - 2^9 */
91
+	METHOD_PRACK=1024,        /* 11 - 2^10 */
92
+	METHOD_UPDATE=2048,       /* 12 - 2^11 */
93
+	METHOD_REFER=4096,        /* 13 - 2^12 */
94
+	METHOD_PUBLISH=8192,      /* 14 - 2^13 */
95
+	METHOD_OTHER=16384        /* 15 - 2^14 */
96
+};
83 97
 
84 98
 #define FL_FORCE_RPORT  (1 << 0)  /* force rport */
85 99
 #define FL_FORCE_ACTIVE (1 << 1)  /* force active SDP */
... ...
@@ -155,9 +155,14 @@ int parse_method(str* _next, enum request_method* _method)
155 155
  			_next->len -= 5;
156 156
  			_next->s += 5;
157 157
  			return 1;
158
- 		} else {
159
- 			goto unknown;
160 158
  		}
159
+ 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) {
160
+ 			*_method = METHOD_PUBLISH;
161
+ 			_next->len -= 7;
162
+ 			_next->s += 7;
163
+ 			return 1;
164
+ 		}
165
+ 		goto unknown;
161 166
 
162 167
  	case 'R':
163 168
  	case 'r':
... ...
@@ -221,7 +226,7 @@ int parse_method(str* _next, enum request_method* _method)
221 221
  
222 222
  /* 
223 223
   * Parse comma separated list of methods pointed by _body and assign their
224
-  * enum bits to _methods.  Returns 1 on success and 0 on failure.
224
+  * enum bits to _methods.  Returns 0 on success and -1 on failure.
225 225
   */
226 226
  int parse_methods(str* _body, unsigned int* _methods)
227 227
  {
... ...
@@ -232,7 +237,7 @@ int parse_method(str* _next, enum request_method* _method)
232 232
  
233 233
 	if (!_body || !_methods) {
234 234
 		LOG(L_ERR, "parse_methods: Invalid parameter value\n");
235
-		return 0;
235
+		return -1;
236 236
 	}
237 237
 
238 238
 	next.len = _body->len;
... ...
@@ -240,19 +245,18 @@ int parse_method(str* _next, enum request_method* _method)
240 240
  
241 241
  	trim_leading(&next);
242 242
  
243
+  	*_methods = 0;
244
+ 
243 245
  	if (next.len == 0) {
244
- 		LOG(L_ERR, "ERROR: parse_methods: Empty body\n");
245 246
  		return 0;
246 247
  	}
247 248
 
248
-  	*_methods = 0;
249
- 
250 249
  	while (1) {
251 250
  		if (parse_method(&next, &method)) {
252 251
  			*_methods |= method;
253 252
  		} else {
254 253
  			LOG(L_ERR, "ERROR: parse_methods: Invalid method\n");
255
- 			return 0;
254
+ 			return -1;
256 255
  		}
257 256
 		
258 257
  		trim_leading(&next);
... ...
@@ -267,12 +271,12 @@ int parse_method(str* _next, enum request_method* _method)
267 267
  				}
268 268
  			} else {
269 269
  				LOG(L_ERR, "ERROR: parse_methods: Comma expected\n");
270
- 				return 0;
270
+ 				return -1;
271 271
  			}
272 272
  		} else {
273 273
  			break;
274 274
  		}
275 275
  	}
276 276
 
277
- 	return 1;
277
+ 	return 0;
278 278
  }