Module: sems Branch: master Commit: 55444166c0a7df21100dcde6a628592ee725923d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=55444166c0a7df21100dcde6a628592ee725923d
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Tue Feb 7 10:35:56 2012 +0100 sip: use better constants for SIP version parser. --- core/sip/parse_common.cpp | 18 +----------------- core/sip/parse_common.h | 11 ++++++++++- core/sip/parse_via.cpp | 2 +- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/core/sip/parse_common.cpp b/core/sip/parse_common.cpp index 0150f96..8380ddf 100644 --- a/core/sip/parse_common.cpp +++ b/core/sip/parse_common.cpp @@ -36,23 +36,12 @@ #include <memory> using std::auto_ptr; -// -// SIP version constants -// - -const char* SIP = "SIP"; -#define SIP_len 3 - -const char* SUP_SIPVER = "2.0"; -#define SUP_SIPVER_len 3 - - int parse_sip_version(const char* beg, int len) { const char* c = beg; //char* end = c+len; - if(len!=7){ + if(len!=SIPVER_len){ DBG("SIP-Version string length != SIPVER_len\n"); return MALFORMED_SIP_MSG; } @@ -66,11 +55,6 @@ int parse_sip_version(const char* beg, int len) } c += SIP_len; - if(*c++ != '/'){ - DBG("SIP-Version has no \"/\" after \"SIP\"\n"); - return MALFORMED_SIP_MSG; - } - if(memcmp(c,SUP_SIPVER,SUP_SIPVER_len) != 0){ DBG("Unsupported or malformed SIP-Version\n"); return MALFORMED_SIP_MSG; diff --git a/core/sip/parse_common.h b/core/sip/parse_common.h index 493159d..722fac3 100644 --- a/core/sip/parse_common.h +++ b/core/sip/parse_common.h @@ -91,8 +91,17 @@ using std::list; #define IS_USER(c) \ (IS_UNRESERVED(c) || IS_USER_UNRESERVED(c)) // Escaped chars missing -#define SIPVER_len 7 // "SIP" "/" 1*DIGIT 1*DIGIT +// +// SIP version constants +// + +#define SIP_str "SIP" +#define SUP_SIPVER "/2.0" + +#define SIP_len (sizeof(SIP_str)-/*0-term*/1) +#define SUP_SIPVER_len (sizeof(SUP_SIPVER)-/*0-term*/1) +#define SIPVER_len (SIP_len+SUP_SIPVER_len) // // Common states: (>100) diff --git a/core/sip/parse_via.cpp b/core/sip/parse_via.cpp index 477d7e1..f7cf853 100644 --- a/core/sip/parse_via.cpp +++ b/core/sip/parse_via.cpp @@ -95,7 +95,7 @@ static int parse_transport(sip_transport* t, const char** c, int len) TR_OTHER }; - if(len < SIPVER_len + 2){ // at least "SIP/2.0/?" + if(len < (int)SIPVER_len + 2){ // at least "SIP/2.0/?" DBG("Transport protocol is too small\n"); return MALFORMED_SIP_MSG; } _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
