Module: sip-router
Branch: master
Commit: 28e95087c242a0743fb633ce732e45d1f7d40335
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=28e9508…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Tue Mar 31 13:32:31 2009 +0200
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_*
---
parser/msg_parser.h | 2 +-
parser/parse_methods.c | 30 +++++++++++++++---------------
parser/parse_methods.h | 24 +++---------------------
3 files changed, 19 insertions(+), 37 deletions(-)
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 1b250df..8624035 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -79,7 +79,7 @@
enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4,
METHOD_BYE=8, METHOD_INFO=16, METHOD_REGISTER=32, METHOD_SUBSCRIBE=64,
METHOD_NOTIFY=128, METHOD_MESSAGE=256, METHOD_OPTIONS=512,
- METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_OTHER=4096 };
+ METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_REFER = 4096, METHOD_OTHER=8192 };
#define FL_FORCE_RPORT (1 << 0) /* force rport */
#define FL_FORCE_ACTIVE (1 << 1) /* force active SDP */
diff --git a/parser/parse_methods.c b/parser/parse_methods.c
index 8e6aabd..aeadee8 100644
--- a/parser/parse_methods.c
+++ b/parser/parse_methods.c
@@ -49,7 +49,7 @@ static int token_char(char _c)
* Parse a method pointed by _next, assign its enum bit to _method, and update
* _next past the method. Returns 1 if parse succeeded and 0 otherwise.
*/
-int parse_method(str* _next, unsigned int* _method)
+int parse_method(str* _next, enum request_method* _method)
{
if (!_next || !_method) {
LOG(L_ERR, "parse_method: Invalid parameter value\n");
@@ -65,7 +65,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'A':
case 'a':
if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ck",
2)) {
- *_method = METH_ACK;
+ *_method = METHOD_ACK;
_next->len -= 3;
_next->s += 3;
return 1;
@@ -76,7 +76,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'B':
case 'b':
if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ye",
2)) {
- *_method = METH_BYE;
+ *_method = METHOD_BYE;
_next->len -= 3;
_next->s += 3;
return 1;
@@ -87,7 +87,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'C':
case 'c':
if ((_next->len > 5) && !strncasecmp(_next->s + 1, "ancel",
5)) {
- *_method = METH_CANCEL;
+ *_method = METHOD_CANCEL;
_next->len -= 6;
_next->s += 6;
return 1;
@@ -100,14 +100,14 @@ int parse_method(str* _next, unsigned int* _method)
if ((_next->len > 3) &&
((*(_next->s + 1) == 'N') || (*(_next->s + 1) == 'n'))) {
if (!strncasecmp(_next->s + 2, "fo", 2)) {
- *_method = METH_INFO;
+ *_method = METHOD_INFO;
_next->len -= 4;
_next->s += 4;
return 1;
}
if ((_next->len > 5) && !strncasecmp(_next->s + 2, "vite",
4)) {
- *_method = METH_INVITE;
+ *_method = METHOD_INVITE;
_next->len -= 6;
_next->s += 6;
return 1;
@@ -118,7 +118,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'M':
case 'm':
if ((_next->len > 6) && !strncasecmp(_next->s + 1,
"essage", 6)) {
- *_method = METH_MESSAGE;
+ *_method = METHOD_MESSAGE;
_next->len -= 7;
_next->s += 7;
return 1;
@@ -129,7 +129,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'N':
case 'n':
if ((_next->len > 5) && !strncasecmp(_next->s + 1, "otify",
5)) {
- *_method = METH_NOTIFY;
+ *_method = METHOD_NOTIFY;
_next->len -= 6;
_next->s += 6;
return 1;
@@ -140,7 +140,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'O':
case 'o':
if ((_next->len > 6) && !strncasecmp(_next->s + 1,
"ptions", 6)) {
- *_method = METH_OPTIONS;
+ *_method = METHOD_OPTIONS;
_next->len -= 7;
_next->s += 7;
return 1;
@@ -151,7 +151,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'P':
case 'p':
if ((_next->len > 4) && !strncasecmp(_next->s + 1, "rack",
4)) {
- *_method = METH_PRACK;
+ *_method = METHOD_PRACK;
_next->len -= 5;
_next->s += 5;
return 1;
@@ -164,14 +164,14 @@ int parse_method(str* _next, unsigned int* _method)
if ((_next->len > 4) &&
((*(_next->s + 1) == 'E') || (*(_next->s + 1) == 'e'))) {
if (!strncasecmp(_next->s + 2, "fer", 3)) {
- *_method = METH_REFER;
+ *_method = METHOD_REFER;
_next->len -= 5;
_next->s += 5;
return 1;
}
if ((_next->len > 7) && !strncasecmp(_next->s + 2,
"gister", 6)) {
- *_method = METH_REGISTER;
+ *_method = METHOD_REGISTER;
_next->len -= 8;
_next->s += 8;
return 1;
@@ -182,7 +182,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'S':
case 's':
if ((_next->len > 8) && !strncasecmp(_next->s + 1,
"ubscribe", 8)) {
- *_method = METH_SUBSCRIBE;
+ *_method = METHOD_SUBSCRIBE;
_next->len -= 9;
_next->s += 9;
return 1;
@@ -193,7 +193,7 @@ int parse_method(str* _next, unsigned int* _method)
case 'U':
case 'u':
if ((_next->len > 5) && !strncasecmp(_next->s + 1, "pdate",
5)) {
- *_method = METH_UPDATE;
+ *_method = METHOD_UPDATE;
_next->len -= 6;
_next->s += 6;
return 1;
@@ -211,7 +211,7 @@ int parse_method(str* _next, unsigned int* _method)
_next->s++;
_next->len--;
} while (_next->len && token_char(*(_next->s)));
- *_method = METH_UNKNOWN;
+ *_method = METHOD_OTHER;
return 1;
} else {
return 0;
diff --git a/parser/parse_methods.h b/parser/parse_methods.h
index a4d70aa..867484f 100644
--- a/parser/parse_methods.h
+++ b/parser/parse_methods.h
@@ -29,27 +29,9 @@
#define PARSE_METHODS_H
#include "../str.h"
+#include "msg_parser.h"
-/*
- * Methods found in methods Contact parameter or Allow header.
- */
-enum method {
- METH_UNKNOWN = 1,
- METH_ACK = 2,
- METH_BYE = 4,
- METH_CANCEL = 8,
- METH_INFO = 16,
- METH_INVITE = 32,
- METH_NOTIFY = 64,
- METH_OPTIONS = 128,
- METH_PRACK = 256,
- METH_REGISTER = 512,
- METH_SUBSCRIBE = 1024,
- METH_UPDATE = 2048,
- METH_MESSAGE = 4096,
- METH_REFER = 8192
-};
-
+#define ALL_METHODS 0xffffffff
/*
* Parse comma separated list of methods pointed by _body and assign their
@@ -57,7 +39,7 @@ enum method {
*/
int parse_methods(str* _body, unsigned int* _methods);
-int parse_method(str* _next, unsigned int* _method);
+int parse_method(str* _next, enum request_method* _method);
#endif /* PARSE_METHODS_H */