Module: sip-router Branch: master Commit: bd0029313d302677fe1663eea4fa43b133f4620f URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bd002931...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Apr 17 00:33:43 2009 +0200
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
---
parser/msg_parser.h | 22 ++++++++++++++++++---- parser/parse_methods.c | 24 ++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/parser/msg_parser.h b/parser/msg_parser.h index dd1b327..b8edc6b 100644 --- a/parser/msg_parser.h +++ b/parser/msg_parser.h @@ -76,10 +76,24 @@ #define SIP_MSG_START(m) ((m)->first_line.u.request.method.s)
/* number methods as power of two to allow bitmap matching */ -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_REFER = 4096, METHOD_OTHER=8192 }; +enum request_method { + METHOD_UNDEF=0, /* 0 - --- */ + METHOD_INVITE=1, /* 1 - 2^0 */ + METHOD_CANCEL=2, /* 2 - 2^1 */ + METHOD_ACK=4, /* 3 - 2^2 */ + METHOD_BYE=8, /* 4 - 2^3 */ + METHOD_INFO=16, /* 5 - 2^4 */ + METHOD_REGISTER=32, /* 6 - 2^5 */ + METHOD_SUBSCRIBE=64, /* 7 - 2^6 */ + METHOD_NOTIFY=128, /* 8 - 2^7 */ + METHOD_MESSAGE=256, /* 9 - 2^8 */ + METHOD_OPTIONS=512, /* 10 - 2^9 */ + METHOD_PRACK=1024, /* 11 - 2^10 */ + METHOD_UPDATE=2048, /* 12 - 2^11 */ + METHOD_REFER=4096, /* 13 - 2^12 */ + METHOD_PUBLISH=8192, /* 14 - 2^13 */ + METHOD_OTHER=16384 /* 15 - 2^14 */ +};
#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 aeadee8..3ba42ce 100644 --- a/parser/parse_methods.c +++ b/parser/parse_methods.c @@ -155,9 +155,14 @@ int parse_method(str* _next, enum request_method* _method) _next->len -= 5; _next->s += 5; return 1; - } else { - goto unknown; } + if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) { + *_method = METHOD_PUBLISH; + _next->len -= 7; + _next->s += 7; + return 1; + } + goto unknown;
case 'R': case 'r': @@ -221,7 +226,7 @@ int parse_method(str* _next, enum request_method* _method)
/* * Parse comma separated list of methods pointed by _body and assign their - * enum bits to _methods. Returns 1 on success and 0 on failure. + * enum bits to _methods. Returns 0 on success and -1 on failure. */ int parse_methods(str* _body, unsigned int* _methods) { @@ -232,7 +237,7 @@ int parse_method(str* _next, enum request_method* _method)
if (!_body || !_methods) { LOG(L_ERR, "parse_methods: Invalid parameter value\n"); - return 0; + return -1; }
next.len = _body->len; @@ -240,19 +245,18 @@ int parse_method(str* _next, enum request_method* _method)
trim_leading(&next);
+ *_methods = 0; + if (next.len == 0) { - LOG(L_ERR, "ERROR: parse_methods: Empty body\n"); return 0; }
- *_methods = 0; - while (1) { if (parse_method(&next, &method)) { *_methods |= method; } else { LOG(L_ERR, "ERROR: parse_methods: Invalid method\n"); - return 0; + return -1; } trim_leading(&next); @@ -267,12 +271,12 @@ int parse_method(str* _next, enum request_method* _method) } } else { LOG(L_ERR, "ERROR: parse_methods: Comma expected\n"); - return 0; + return -1; } } else { break; } }
- return 1; + return 0; }