Browse code

core: AmUriParser: fix headers in nameaddr_str, added parse_nameaddr function alias

Conflicts:

core/AmUriParser.cpp
core/AmUriParser.h
core/tests/test_uriparser.cpp

Stefan Sayer authored on 14/08/2013 16:46:27
Showing 3 changed files
... ...
@@ -263,8 +263,6 @@ bool AmUriParser::parse_uri() {
263 263
 
264 264
     case uSHDR: {
265 265
       switch (c) {
266
-      case ';': { uri_headers = uri.substr(p1+1, pos-p1-1);
267
-	  st = uSPARAM; p1 = pos; }; break; 
268 266
       case '>': { uri_headers = uri.substr(p1+1, pos-p1-1);
269 267
       st = uS6; p1 = pos; } break;
270 268
       case '\t':
... ...
@@ -394,8 +392,8 @@ bool AmUriParser::parse_params(const string& line, int& pos) {
394 392
 }
395 393
 
396 394
 bool AmUriParser::parse_nameaddr(const string& line) {
397
-  size_t end;
398
-  return parse_contact(line, 0, end);
395
+  size_t pos=0; size_t end=0;
396
+  return parse_contact(line, pos, end);
399 397
 }
400 398
 
401 399
 bool AmUriParser::parse_contact(const string& line, size_t pos, size_t& end) {
... ...
@@ -505,12 +503,16 @@ string AmUriParser::uri_str() const
505 503
     res += ";" + uri_param;
506 504
   }
507 505
 
506
+  if (!uri_headers.empty()) {
507
+    res+="?" + uri_headers;
508
+  }
509
+
508 510
   return res;
509 511
 }
510 512
 
511 513
 string AmUriParser::canon_uri_str() const
512 514
 {
513
-  string res = "sip:";
515
+  string res = "sip:"; // fixme: always SIP...
514 516
   if(!uri_user.empty()) {
515 517
     res += uri_user + "@";
516 518
   }
... ...
@@ -46,12 +46,13 @@ struct AmUriParser {
46 46
   map<string, string> params; 	// <sip:user;@host>;params
47 47
 
48 48
   bool isEqual(const AmUriParser& c) const;
49
-  /** @return true on success */
50
-  bool parse_nameaddr(const string& line);
51 49
   /** parse nameaddr from pos
52 50
        @return true on success
53 51
        @return end of current nameaddr */
54 52
   bool parse_contact(const string& line, size_t pos, size_t& end);
53
+  /** parse a name-addr @return true on success */
54
+  bool parse_nameaddr(const string& line);
55
+
55 56
   /** @return true on success */
56 57
   bool parse_uri();
57 58
   bool parse_params(const string& line, int& pos);
... ...
@@ -101,5 +101,28 @@ FCTMF_SUITE_BGN(test_uriparser) {
101 101
       fct_chk( p.uri_host=="bell-telephone.com");
102 102
     } FCT_TEST_END();
103 103
 
104
+    FCT_TEST_BGN(uriparser_headers) {
105
+      AmUriParser p;
106
+      size_t end;
107
+      fct_chk(p.parse_contact("\"Mr. Watson\" <mailto:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd> ;q=0.1", 0, end));
108
+      fct_chk( p.display_name=="Mr. Watson");
109
+      fct_chk( p.uri_user=="watson");
110
+      fct_chk( p.uri_host=="bell-telephone.com");
111
+      fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
112
+    } FCT_TEST_END();
113
+
114
+    FCT_TEST_BGN(uriparser_headers_str) {
115
+      AmUriParser p;
116
+      string orig_str = "\"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd>;q=0.1";
117
+      fct_chk(p.parse_nameaddr(orig_str));
118
+      fct_chk( p.display_name=="Mr. Watson");
119
+      fct_chk( p.uri_user=="watson");
120
+      fct_chk( p.uri_host=="bell-telephone.com");
121
+      fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
122
+      string a_str = p.nameaddr_str();
123
+      // DBG(" >>%s<< => >>%s<<\n", orig_str.c_str(), a_str.c_str());
124
+      fct_chk(orig_str == a_str);
125
+    } FCT_TEST_END();
126
+
104 127
 
105 128
 } FCTMF_SUITE_END();