Module: sems
Branch: master
Commit: 61a968e9f1336801184962ce167d3c24748c38a3
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=61a968e9f1336801184962ce167d3c24748c38a3

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Tue Apr 24 12:02:11 2012 +0200

b/f: getHeader: find correct hdr also if it's substring of another hdr

reported by Andrew Pogrebennyk

---

 core/AmSipMsg.cpp           |   12 ++++++++++--
 core/tests/test_headers.cpp |   23 +++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/core/AmSipMsg.cpp b/core/AmSipMsg.cpp
index 4ea9415..7e16cdf 100644
--- a/core/AmSipMsg.cpp
+++ b/core/AmSipMsg.cpp
@@ -66,8 +66,16 @@ bool findHeader(const string& hdrs,const string& hdr_name, 
const size_t skip,
       hdrs_c++;
     }
 
-    if(hdr_c == hdr_end)
-      break;
+    if(hdr_c == hdr_end) {
+      // matched whole of needle.
+      // ...all of current header?
+      const char* srccol = hdrs_c;
+      while (*srccol==' ' || *srccol=='\t')
+       srccol++;
+      if (*srccol == ':')
+       break; // was end of current hdr
+      // current hdr just starts with hdr, continue search
+    }
 
     while((hdrs_c != hdrs_end) && (*hdrs_c != '\n'))
       hdrs_c++;
diff --git a/core/tests/test_headers.cpp b/core/tests/test_headers.cpp
index 5805534..e1790ee 100644
--- a/core/tests/test_headers.cpp
+++ b/core/tests/test_headers.cpp
@@ -59,6 +59,29 @@ FCTMF_SUITE_BGN(test_headers) {
       fct_chk(get_header_keyvalue("u=sayer;d=iptel.org;p=abcdef", "d") == 
"iptel.org");
     } FCT_TEST_END();
 
+
+    FCT_TEST_BGN(getHeader_allow) {
+      fct_chk(getHeader("Subject: Performance Test\n"
+                       "Allow: 
INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH",
 "Allow") == 
"INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH");
+    } FCT_TEST_END();
+
+    FCT_TEST_BGN(getHeader_allow_substr) {
+      fct_chk(getHeader("Subject: Performance Test\n"
+                       "Allow-Events: telephone-event,refer\n"
+                       "Allow: 
INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH",
 "Allow") == 
"INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH");
+    } FCT_TEST_END();
+
+    FCT_TEST_BGN(getHeader_allow3) {
+      fct_chk(getHeader("Subject: Performance Test\n"
+                       "Allow  : 
INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH",
 "Allow") == 
"INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH");
+    } FCT_TEST_END();
+
+    FCT_TEST_BGN(getHeader_allow4) {
+      fct_chk(getHeader("Subject: Performance Test\n"
+                       "Allow-Events : telephone-event,refer\n"
+                       "Allow  : 
INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH",
 "Allow") == 
"INVITE,ACK,OPTIONS,CANCEL,BYE,UPDATE,PRACK,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,PUBLISH");
+    } FCT_TEST_END();
+
     FCT_TEST_BGN(addOptionTag) {
       string hdrs =
        "Supported: timer" CRLF

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to