Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | 844653c | 2008-12-23 17:27:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) |
Benny Prijono | 32177c0 | 2008-06-20 22:44:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #include "test.h" |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 21 | #include <pjsip.h> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 22 | #include <pjlib.h> |
| 23 | |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 24 | #define POOL_SIZE 8000 |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 25 | #if defined(PJ_DEBUG) && PJ_DEBUG!=0 |
| 26 | # define LOOP 10000 |
| 27 | #else |
| 28 | # define LOOP 100000 |
| 29 | #endif |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 30 | #define AVERAGE_MSG_LEN 800 |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 31 | #define THIS_FILE "msg_test.c" |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 32 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 33 | static pjsip_msg *create_msg0(pj_pool_t *pool); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 34 | static pjsip_msg *create_msg1(pj_pool_t *pool); |
| 35 | |
| 36 | #define STATUS_PARTIAL 1 |
| 37 | #define STATUS_SYNTAX_ERROR 2 |
| 38 | |
| 39 | #define FLAG_DETECT_ONLY 1 |
| 40 | #define FLAG_PARSE_ONLY 4 |
| 41 | #define FLAG_PRINT_ONLY 8 |
| 42 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 43 | struct test_msg |
| 44 | { |
| 45 | char msg[1024]; |
| 46 | pjsip_msg *(*creator)(pj_pool_t *pool); |
| 47 | pj_size_t len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 48 | int expected_status; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 49 | } test_array[] = |
| 50 | { |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 51 | { |
| 52 | /* 'Normal' message with all headers. */ |
| 53 | "INVITE sip:user@foo SIP/2.0\n" |
Benny Prijono | b6eab2c | 2006-07-03 22:08:47 +0000 | [diff] [blame] | 54 | "from: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r" |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 55 | "To: Fellow User <sip:user@foo.bar.domain.com>\r\n" |
| 56 | "Call-ID: 12345678901234567890@bar\r\n" |
| 57 | "Content-Length: 0\r\n" |
| 58 | "CSeq: 123456 INVITE\n" |
| 59 | "Contact: <sip:joe@bar> ; q=0.5;expires=3600,sip:user@host;q=0.500\r" |
| 60 | " ,sip:user2@host2\n" |
| 61 | "Content-Type: text/html ; charset=ISO-8859-4\r" |
| 62 | "Route: <sip:bigbox3.site3.atlanta.com;lr>,\r\n" |
| 63 | " <sip:server10.biloxi.com;lr>\r" |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 64 | "Record-Route: <sip:server10.biloxi.com>,\r\n" /* multiple routes+folding*/ |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 65 | " <sip:bigbox3.site3.atlanta.com;lr>\n" |
Benny Prijono | 69f73fe | 2007-03-19 10:27:13 +0000 | [diff] [blame] | 66 | "v: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n" |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 67 | "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n" /* folding. */ |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 68 | " ;received=192.0.2.1\r\n" |
| 69 | "Via: SIP/2.0/UDP 10.2.1.1, SIP/2.0/TCP 192.168.1.1\n" |
| 70 | "Organization: \r" |
| 71 | "Max-Forwards: 70\n" |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 72 | "X-Header: \r\n" /* empty header */ |
| 73 | "P-Associated-URI:\r\n" /* empty header without space */ |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 74 | "\r\n", |
| 75 | &create_msg0, |
Benny Prijono | 713587c | 2009-03-18 18:24:40 +0000 | [diff] [blame] | 76 | 0, |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 77 | PJ_SUCCESS |
| 78 | }, |
| 79 | { |
| 80 | /* Typical response message. */ |
| 81 | "SIP/2.0 200 OK\r\n" |
Benny Prijono | 4cf8d1c | 2007-04-28 15:37:49 +0000 | [diff] [blame] | 82 | "Via: SIP/2.0/SCTP server10.biloxi.com;branch=z9hG4bKnashds8;rport;received=192.0.2.1\r\n" |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 83 | "Via: SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1;received=192.0.2.2\r\n" |
| 84 | "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds ;received=192.0.2.3\r\n" |
| 85 | "Route: <sip:proxy.sipprovider.com>\r\n" |
| 86 | "Route: <sip:proxy.supersip.com:5060>\r\n" |
| 87 | "Max-Forwards: 70\r\n" |
| 88 | "To: Bob <sip:bob@biloxi.com>;tag=a6c85cf\r\n" |
| 89 | "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n" |
| 90 | "Call-ID: a84b4c76e66710@pc33.atlanta.com\r\n" |
| 91 | "CSeq: 314159 INVITE\r\n" |
| 92 | "Contact: <sips:bob@192.0.2.4>\r\n" |
| 93 | "Content-Type: application/sdp\r\n" |
| 94 | "Content-Length: 150\r\n" |
| 95 | "\r\n" |
| 96 | "v=0\r\n" |
| 97 | "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n" |
| 98 | "s=-\r\n" |
| 99 | "t=0 0\r\n" |
| 100 | "c=IN IP4 pc33.atlanta.com\r\n" |
| 101 | "m=audio 3456 RTP/AVP 0 1 3 99\r\n" |
| 102 | "a=rtpmap:0 PCMU/8000\r\n", |
| 103 | &create_msg1, |
Benny Prijono | 713587c | 2009-03-18 18:24:40 +0000 | [diff] [blame] | 104 | 0, |
| 105 | PJ_SUCCESS |
| 106 | }, |
| 107 | { |
| 108 | /* Torture message from RFC 4475 |
| 109 | * 3.1.1.1 A short tortuous INVITE |
| 110 | */ |
| 111 | "INVITE sip:vivekg@chair-dnrc.example.com;unknownparam SIP/2.0\n" |
| 112 | "TO :\n" |
| 113 | " sip:vivekg@chair-dnrc.example.com ; tag = 1918181833n\n" |
| 114 | "from : \"J Rosenberg \\\\\\\"\" <sip:jdrosen@example.com>\n" |
| 115 | " ;\n" |
| 116 | " tag = 98asjd8\n" |
| 117 | "MaX-fOrWaRdS: 0068\n" |
| 118 | "Call-ID: wsinv.ndaksdj@192.0.2.1\n" |
| 119 | "Content-Length : 150\n" |
| 120 | "cseq: 0009\n" |
| 121 | " INVITE\n" |
| 122 | "Via : SIP / 2.0\n" |
| 123 | " /UDP\n" |
| 124 | " 192.0.2.2;rport;branch=390skdjuw\n" |
| 125 | "s :\n" |
| 126 | "NewFangledHeader: newfangled value\n" |
| 127 | " continued newfangled value\n" |
| 128 | "UnknownHeaderWithUnusualValue: ;;,,;;,;\n" |
| 129 | "Content-Type: application/sdp\n" |
| 130 | "Route:\n" |
| 131 | " <sip:services.example.com;lr;unknownwith=value;unknown-no-value>\n" |
| 132 | "v: SIP / 2.0 / TCP spindle.example.com ;\n" |
| 133 | " branch = z9hG4bK9ikj8 ,\n" |
| 134 | " SIP / 2.0 / UDP 192.168.255.111 ; branch=\n" |
| 135 | " z9hG4bK30239\n" |
| 136 | "m:\"Quoted string \\\"\\\"\" <sip:jdrosen@example.com> ; newparam =\n" |
| 137 | " newvalue ;\n" |
| 138 | " secondparam ; q = 0.33\r\n" |
| 139 | "\r\n" |
| 140 | "v=0\r\n" |
| 141 | "o=mhandley 29739 7272939 IN IP4 192.0.2.3\r\n" |
| 142 | "s=-\r\n" |
| 143 | "c=IN IP4 192.0.2.4\r\n" |
| 144 | "t=0 0\r\n" |
| 145 | "m=audio 49217 RTP/AVP 0 12\r\n" |
| 146 | "m=video 3227 RTP/AVP 31\r\n" |
| 147 | "a=rtpmap:31 LPC\r\n", |
| 148 | NULL, |
| 149 | 0, |
| 150 | PJ_SUCCESS |
| 151 | }, |
| 152 | { |
| 153 | /* Torture message from RFC 4475 |
| 154 | * 3.1.1.2 Wide Range of Valid Characters |
| 155 | */ |
| 156 | "!interesting-Method0123456789_*+`.%indeed'~ sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*:&it+has=1,weird!*pas$wo~d_too.(doesn't-it)@example.com SIP/2.0\n" |
| 157 | "Via: SIP/2.0/UDP host1.example.com;rport;branch=z9hG4bK-.!%66*_+`'~\n" |
| 158 | "To: \"BEL:\\\x07 NUL:\\\x00 DEL:\\\x7F\" <sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*@example.com>\n" |
| 159 | "From: token1~` token2'+_ token3*%!.- <sip:mundane@example.com> ;fromParam''~+*_!.-%=\"\xD1\x80\xD0\xB0\xD0\xB1\xD0\xBE\xD1\x82\xD0\xB0\xD1\x8E\xD1\x89\xD0\xB8\xD0\xB9\";tag=_token~1'+`*%!-.\n" |
| 160 | "Call-ID: intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{\n" |
| 161 | "CSeq: 139122385 !interesting-Method0123456789_*+`.%indeed'~\n" |
| 162 | "Max-Forwards: 255\n" |
| 163 | "extensionHeader-!.%*+_`'~: \xEF\xBB\xBF\xE5\xA4\xA7\xE5\x81\x9C\xE9\x9B\xBB\n" |
| 164 | "Content-Length: 0\r\n\r\n", |
| 165 | NULL, |
| 166 | 641, |
| 167 | PJ_SUCCESS |
| 168 | }, |
| 169 | { |
| 170 | /* Torture message from RFC 4475 |
| 171 | * 3.1.1.3 Valid Use of the % Escaping Mechanism |
| 172 | */ |
| 173 | "INVITE sip:sips%3Auser%40example.com@example.net SIP/2.0\n" |
| 174 | "To: sip:%75se%72@example.com\n" |
| 175 | "From: <sip:I%20have%20spaces@example.net>;tag=1234\n" |
| 176 | "Max-Forwards: 87\n" |
| 177 | "i: esc01.239409asdfakjkn23onasd0-3234\n" |
| 178 | "CSeq: 234234 INVITE\n" |
| 179 | "Via: SIP/2.0/UDP host5.example.net;rport;branch=z9hG4bKkdjuw\n" |
| 180 | "C: application/sdp\n" |
| 181 | "Contact:\n" |
| 182 | " <sip:cal%6Cer@192.168.0.2:5060;%6C%72;n%61me=v%61lue%25%34%31>\n" |
| 183 | "Content-Length: 150\r\n" |
| 184 | "\r\n" |
| 185 | "v=0\r\n" |
| 186 | "o=mhandley 29739 7272939 IN IP4 192.0.2.1\r\n" |
| 187 | "s=-\r\n" |
| 188 | "c=IN IP4 192.0.2.1\r\n" |
| 189 | "t=0 0\r\n" |
| 190 | "m=audio 49217 RTP/AVP 0 12\r\n" |
| 191 | "m=video 3227 RTP/AVP 31\r\n" |
| 192 | "a=rtpmap:31 LPC\r\n", |
| 193 | NULL, |
| 194 | 0, |
| 195 | PJ_SUCCESS |
| 196 | }, |
| 197 | { |
| 198 | /* Torture message from RFC 4475 |
| 199 | * 3.1.1.4 Escaped Nulls in URIs |
| 200 | */ |
| 201 | "REGISTER sip:example.com SIP/2.0\r\n" |
| 202 | "To: sip:null-%00-null@example.com\r\n" |
| 203 | "From: sip:null-%00-null@example.com;tag=839923423\r\n" |
| 204 | "Max-Forwards: 70\r\n" |
| 205 | "Call-ID: escnull.39203ndfvkjdasfkq3w4otrq0adsfdfnavd\r\n" |
| 206 | "CSeq: 14398234 REGISTER\r\n" |
| 207 | "Via: SIP/2.0/UDP host5.example.com;rport;branch=z9hG4bKkdjuw\r\n" |
| 208 | "Contact: <sip:%00@host5.example.com>\r\n" |
| 209 | "Contact: <sip:%00%00@host5.example.com>\r\n" |
| 210 | "L:0\r\n" |
| 211 | "\r\n", |
| 212 | NULL, |
| 213 | 0, |
| 214 | PJ_SUCCESS |
| 215 | }, |
| 216 | { |
| 217 | /* Torture message from RFC 4475 |
| 218 | * 3.1.1.5 Use of % When It Is Not an Escape |
| 219 | */ |
| 220 | "RE%47IST%45R sip:registrar.example.com SIP/2.0\r\n" |
| 221 | "To: \"%Z%45\" <sip:resource@example.com>\r\n" |
| 222 | "From: \"%Z%45\" <sip:resource@example.com>;tag=f232jadfj23\r\n" |
| 223 | "Call-ID: esc02.asdfnqwo34rq23i34jrjasdcnl23nrlknsdf\r\n" |
| 224 | "Via: SIP/2.0/TCP host.example.com;rport;branch=z9hG4bK209%fzsnel234\r\n" |
| 225 | "CSeq: 29344 RE%47IST%45R\r\n" |
| 226 | "Max-Forwards: 70\r\n" |
| 227 | "Contact: <sip:alias1@host1.example.com>\r\n" |
| 228 | "C%6Fntact: <sip:alias2@host2.example.com>\r\n" |
| 229 | "Contact: <sip:alias3@host3.example.com>\r\n" |
| 230 | "l: 0\r\n" |
| 231 | "\r\n", |
| 232 | NULL, |
| 233 | 0, |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 234 | PJ_SUCCESS |
| 235 | } |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 238 | static struct |
| 239 | { |
| 240 | int flag; |
| 241 | pj_highprec_t detect_len, parse_len, print_len; |
| 242 | pj_timestamp detect_time, parse_time, print_time; |
| 243 | } var; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 244 | |
| 245 | static pj_status_t test_entry( pj_pool_t *pool, struct test_msg *entry ) |
| 246 | { |
Benny Prijono | e960bb5 | 2007-01-21 17:53:39 +0000 | [diff] [blame] | 247 | pjsip_msg *parsed_msg, *ref_msg = NULL; |
Benny Prijono | cec5f4a | 2005-11-22 23:51:50 +0000 | [diff] [blame] | 248 | static pjsip_msg *print_msg; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 249 | pj_status_t status = PJ_SUCCESS; |
| 250 | int len; |
| 251 | pj_str_t str1, str2; |
| 252 | pjsip_hdr *hdr1, *hdr2; |
| 253 | pj_timestamp t1, t2; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 254 | pjsip_parser_err_report err_list; |
| 255 | pj_size_t msg_size; |
| 256 | char msgbuf1[PJSIP_MAX_PKT_LEN]; |
| 257 | char msgbuf2[PJSIP_MAX_PKT_LEN]; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 258 | enum { BUFLEN = 512 }; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 259 | |
Benny Prijono | 713587c | 2009-03-18 18:24:40 +0000 | [diff] [blame] | 260 | if (entry->len==0) |
| 261 | entry->len = pj_ansi_strlen(entry->msg); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 262 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 263 | if (var.flag & FLAG_PARSE_ONLY) |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 264 | goto parse_msg; |
Benny Prijono | cec5f4a | 2005-11-22 23:51:50 +0000 | [diff] [blame] | 265 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 266 | if (var.flag & FLAG_PRINT_ONLY) { |
Benny Prijono | cec5f4a | 2005-11-22 23:51:50 +0000 | [diff] [blame] | 267 | if (print_msg == NULL) |
| 268 | print_msg = entry->creator(pool); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 269 | goto print_msg; |
Benny Prijono | cec5f4a | 2005-11-22 23:51:50 +0000 | [diff] [blame] | 270 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 271 | |
| 272 | /* Detect message. */ |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 273 | var.detect_len = var.detect_len + entry->len; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 274 | pj_get_timestamp(&t1); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 275 | status = pjsip_find_msg(entry->msg, entry->len, PJ_FALSE, &msg_size); |
| 276 | if (status != PJ_SUCCESS) { |
| 277 | if (status!=PJSIP_EPARTIALMSG || |
| 278 | entry->expected_status!=STATUS_PARTIAL) |
| 279 | { |
| 280 | app_perror(" error: unable to detect message", status); |
| 281 | return -5; |
| 282 | } |
| 283 | } |
| 284 | if (msg_size != entry->len) { |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 285 | PJ_LOG(3,(THIS_FILE, " error: size mismatch")); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 286 | return -6; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 287 | } |
| 288 | pj_get_timestamp(&t2); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 289 | pj_sub_timestamp(&t2, &t1); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 290 | pj_add_timestamp(&var.detect_time, &t2); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 291 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 292 | if (var.flag & FLAG_DETECT_ONLY) |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 293 | return PJ_SUCCESS; |
| 294 | |
| 295 | /* Parse message. */ |
| 296 | parse_msg: |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 297 | var.parse_len = var.parse_len + entry->len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 298 | pj_get_timestamp(&t1); |
| 299 | pj_list_init(&err_list); |
| 300 | parsed_msg = pjsip_parse_msg(pool, entry->msg, entry->len, &err_list); |
| 301 | if (parsed_msg == NULL) { |
| 302 | if (entry->expected_status != STATUS_SYNTAX_ERROR) { |
| 303 | status = -10; |
| 304 | if (err_list.next != &err_list) { |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 305 | PJ_LOG(3,(THIS_FILE, " Syntax error in line %d col %d", |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 306 | err_list.next->line, err_list.next->col)); |
| 307 | } |
| 308 | goto on_return; |
| 309 | } |
| 310 | } |
| 311 | pj_get_timestamp(&t2); |
| 312 | pj_sub_timestamp(&t2, &t1); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 313 | pj_add_timestamp(&var.parse_time, &t2); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 314 | |
Benny Prijono | 713587c | 2009-03-18 18:24:40 +0000 | [diff] [blame] | 315 | if ((var.flag & FLAG_PARSE_ONLY) || entry->creator==NULL) |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 316 | return PJ_SUCCESS; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 317 | |
| 318 | /* Create reference message. */ |
| 319 | ref_msg = entry->creator(pool); |
| 320 | |
| 321 | /* Create buffer for comparison. */ |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 322 | str1.ptr = (char*)pj_pool_alloc(pool, BUFLEN); |
| 323 | str2.ptr = (char*)pj_pool_alloc(pool, BUFLEN); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 324 | |
| 325 | /* Compare message type. */ |
| 326 | if (parsed_msg->type != ref_msg->type) { |
| 327 | status = -20; |
| 328 | goto on_return; |
| 329 | } |
| 330 | |
| 331 | /* Compare request or status line. */ |
| 332 | if (parsed_msg->type == PJSIP_REQUEST_MSG) { |
| 333 | pjsip_method *m1 = &parsed_msg->line.req.method; |
| 334 | pjsip_method *m2 = &ref_msg->line.req.method; |
| 335 | |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 336 | if (pjsip_method_cmp(m1, m2) != 0) { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 337 | status = -30; |
| 338 | goto on_return; |
| 339 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 340 | status = pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI, |
| 341 | parsed_msg->line.req.uri, |
| 342 | ref_msg->line.req.uri); |
| 343 | if (status != PJ_SUCCESS) { |
| 344 | app_perror(" error: request URI mismatch", status); |
| 345 | status = -31; |
| 346 | goto on_return; |
| 347 | } |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 348 | } else { |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 349 | if (parsed_msg->line.status.code != ref_msg->line.status.code) { |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 350 | PJ_LOG(3,(THIS_FILE, " error: status code mismatch")); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 351 | status = -32; |
| 352 | goto on_return; |
| 353 | } |
| 354 | if (pj_strcmp(&parsed_msg->line.status.reason, |
| 355 | &ref_msg->line.status.reason) != 0) |
| 356 | { |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 357 | PJ_LOG(3,(THIS_FILE, " error: status text mismatch")); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 358 | status = -33; |
| 359 | goto on_return; |
| 360 | } |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* Compare headers. */ |
| 364 | hdr1 = parsed_msg->hdr.next; |
| 365 | hdr2 = ref_msg->hdr.next; |
| 366 | |
| 367 | while (hdr1 != &parsed_msg->hdr && hdr2 != &ref_msg->hdr) { |
Benny Prijono | 329d638 | 2009-05-29 13:04:03 +0000 | [diff] [blame] | 368 | len = pjsip_hdr_print_on(hdr1, str1.ptr, BUFLEN); |
| 369 | if (len < 0) { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 370 | status = -40; |
| 371 | goto on_return; |
| 372 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 373 | str1.ptr[len] = '\0'; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 374 | str1.slen = len; |
| 375 | |
Benny Prijono | 329d638 | 2009-05-29 13:04:03 +0000 | [diff] [blame] | 376 | len = pjsip_hdr_print_on(hdr2, str2.ptr, BUFLEN); |
| 377 | if (len < 0) { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 378 | status = -50; |
| 379 | goto on_return; |
| 380 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 381 | str2.ptr[len] = '\0'; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 382 | str2.slen = len; |
| 383 | |
| 384 | if (pj_strcmp(&str1, &str2) != 0) { |
| 385 | status = -60; |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 386 | PJ_LOG(3,(THIS_FILE, " error: header string mismatch:\n" |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 387 | " h1='%s'\n" |
| 388 | " h2='%s'\n", |
| 389 | str1.ptr, str2.ptr)); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 390 | goto on_return; |
| 391 | } |
| 392 | |
| 393 | hdr1 = hdr1->next; |
| 394 | hdr2 = hdr2->next; |
| 395 | } |
| 396 | |
| 397 | if (hdr1 != &parsed_msg->hdr || hdr2 != &ref_msg->hdr) { |
| 398 | status = -70; |
| 399 | goto on_return; |
| 400 | } |
| 401 | |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 402 | /* Compare body? */ |
| 403 | if (parsed_msg->body==NULL && ref_msg->body==NULL) |
| 404 | goto print_msg; |
| 405 | |
| 406 | /* Compare msg body length. */ |
| 407 | if (parsed_msg->body->len != ref_msg->body->len) { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 408 | status = -80; |
| 409 | goto on_return; |
| 410 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 411 | |
| 412 | /* Compare msg body content type. */ |
| 413 | if (pj_strcmp(&parsed_msg->body->content_type.type, |
| 414 | &ref_msg->body->content_type.type) != 0) { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 415 | status = -90; |
| 416 | goto on_return; |
| 417 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 418 | if (pj_strcmp(&parsed_msg->body->content_type.subtype, |
| 419 | &ref_msg->body->content_type.subtype) != 0) { |
| 420 | status = -100; |
| 421 | goto on_return; |
| 422 | } |
| 423 | |
| 424 | /* Compare body content. */ |
| 425 | str1.slen = parsed_msg->body->print_body(parsed_msg->body, |
| 426 | msgbuf1, sizeof(msgbuf1)); |
| 427 | if (str1.slen < 1) { |
| 428 | status = -110; |
| 429 | goto on_return; |
| 430 | } |
| 431 | str1.ptr = msgbuf1; |
| 432 | |
| 433 | str2.slen = ref_msg->body->print_body(ref_msg->body, |
| 434 | msgbuf2, sizeof(msgbuf2)); |
| 435 | if (str2.slen < 1) { |
| 436 | status = -120; |
| 437 | goto on_return; |
| 438 | } |
| 439 | str2.ptr = msgbuf2; |
| 440 | |
| 441 | if (pj_strcmp(&str1, &str2) != 0) { |
| 442 | status = -140; |
| 443 | goto on_return; |
| 444 | } |
| 445 | |
| 446 | /* Print message. */ |
| 447 | print_msg: |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 448 | var.print_len = var.print_len + entry->len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 449 | pj_get_timestamp(&t1); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 450 | if (var.flag && FLAG_PRINT_ONLY) |
Benny Prijono | cec5f4a | 2005-11-22 23:51:50 +0000 | [diff] [blame] | 451 | ref_msg = print_msg; |
| 452 | len = pjsip_msg_print(ref_msg, msgbuf1, PJSIP_MAX_PKT_LEN); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 453 | if (len < 1) { |
| 454 | status = -150; |
| 455 | goto on_return; |
| 456 | } |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 457 | pj_get_timestamp(&t2); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 458 | pj_sub_timestamp(&t2, &t1); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 459 | pj_add_timestamp(&var.print_time, &t2); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 460 | |
| 461 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 462 | status = PJ_SUCCESS; |
| 463 | |
| 464 | on_return: |
| 465 | return status; |
| 466 | } |
| 467 | |
| 468 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 469 | static pjsip_msg *create_msg0(pj_pool_t *pool) |
| 470 | { |
| 471 | |
| 472 | pjsip_msg *msg; |
| 473 | pjsip_name_addr *name_addr; |
Benny Prijono | 0c2bc61 | 2006-01-10 13:31:40 +0000 | [diff] [blame] | 474 | pjsip_sip_uri *url; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 475 | pjsip_fromto_hdr *fromto; |
| 476 | pjsip_cid_hdr *cid; |
| 477 | pjsip_clen_hdr *clen; |
| 478 | pjsip_cseq_hdr *cseq; |
| 479 | pjsip_contact_hdr *contact; |
| 480 | pjsip_ctype_hdr *ctype; |
| 481 | pjsip_routing_hdr *routing; |
| 482 | pjsip_via_hdr *via; |
| 483 | pjsip_generic_string_hdr *generic; |
Benny Prijono | 1e5a08b | 2010-08-01 09:24:58 +0000 | [diff] [blame] | 484 | pjsip_param *prm; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 485 | pj_str_t str; |
| 486 | |
| 487 | msg = pjsip_msg_create(pool, PJSIP_REQUEST_MSG); |
| 488 | |
| 489 | /* "INVITE sip:user@foo SIP/2.0\n" */ |
| 490 | pjsip_method_set(&msg->line.req.method, PJSIP_INVITE_METHOD); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 491 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 492 | msg->line.req.uri = (pjsip_uri*)url; |
| 493 | pj_strdup2(pool, &url->user, "user"); |
| 494 | pj_strdup2(pool, &url->host, "foo"); |
| 495 | |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 496 | /* "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r" */ |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 497 | fromto = pjsip_from_hdr_create(pool); |
| 498 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)fromto); |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 499 | pj_strdup2(pool, &fromto->tag, "123457890123456"); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 500 | name_addr = pjsip_name_addr_create(pool); |
| 501 | fromto->uri = (pjsip_uri*)name_addr; |
| 502 | pj_strdup2(pool, &name_addr->display, "Hi I'm Joe"); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 503 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 504 | name_addr->uri = (pjsip_uri*)url; |
| 505 | pj_strdup2(pool, &url->user, "joe.user"); |
| 506 | pj_strdup2(pool, &url->host, "bar.otherdomain.com"); |
| 507 | |
| 508 | /* "To: Fellow User <sip:user@foo.bar.domain.com>\r\n" */ |
| 509 | fromto = pjsip_to_hdr_create(pool); |
| 510 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)fromto); |
| 511 | name_addr = pjsip_name_addr_create(pool); |
| 512 | fromto->uri = (pjsip_uri*)name_addr; |
| 513 | pj_strdup2(pool, &name_addr->display, "Fellow User"); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 514 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 515 | name_addr->uri = (pjsip_uri*)url; |
| 516 | pj_strdup2(pool, &url->user, "user"); |
| 517 | pj_strdup2(pool, &url->host, "foo.bar.domain.com"); |
| 518 | |
| 519 | /* "Call-ID: 12345678901234567890@bar\r\n" */ |
| 520 | cid = pjsip_cid_hdr_create(pool); |
| 521 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)cid); |
| 522 | pj_strdup2(pool, &cid->id, "12345678901234567890@bar"); |
| 523 | |
| 524 | /* "Content-Length: 0\r\n" */ |
| 525 | clen = pjsip_clen_hdr_create(pool); |
| 526 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)clen); |
| 527 | clen->len = 0; |
| 528 | |
| 529 | /* "CSeq: 123456 INVITE\n" */ |
| 530 | cseq = pjsip_cseq_hdr_create(pool); |
| 531 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)cseq); |
| 532 | cseq->cseq = 123456; |
| 533 | pjsip_method_set(&cseq->method, PJSIP_INVITE_METHOD); |
| 534 | |
| 535 | /* "Contact: <sip:joe@bar>;q=0.5;expires=3600*/ |
| 536 | contact = pjsip_contact_hdr_create(pool); |
| 537 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)contact); |
| 538 | contact->q1000 = 500; |
| 539 | contact->expires = 3600; |
| 540 | name_addr = pjsip_name_addr_create(pool); |
| 541 | contact->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 542 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 543 | name_addr->uri = (pjsip_uri*)url; |
| 544 | pj_strdup2(pool, &url->user, "joe"); |
| 545 | pj_strdup2(pool, &url->host, "bar"); |
| 546 | |
| 547 | /*, sip:user@host;q=0.500\r" */ |
| 548 | contact = pjsip_contact_hdr_create(pool); |
| 549 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)contact); |
| 550 | contact->q1000 = 500; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 551 | name_addr = pjsip_name_addr_create(pool); |
| 552 | contact->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 553 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 554 | name_addr->uri = (pjsip_uri*)url; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 555 | pj_strdup2(pool, &url->user, "user"); |
| 556 | pj_strdup2(pool, &url->host, "host"); |
| 557 | |
| 558 | /* " ,sip:user2@host2\n" */ |
| 559 | contact = pjsip_contact_hdr_create(pool); |
| 560 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)contact); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 561 | name_addr = pjsip_name_addr_create(pool); |
| 562 | contact->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 563 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 564 | name_addr->uri = (pjsip_uri*)url; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 565 | pj_strdup2(pool, &url->user, "user2"); |
| 566 | pj_strdup2(pool, &url->host, "host2"); |
| 567 | |
| 568 | /* "Content-Type: text/html; charset=ISO-8859-4\r" */ |
| 569 | ctype = pjsip_ctype_hdr_create(pool); |
| 570 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)ctype); |
| 571 | pj_strdup2(pool, &ctype->media.type, "text"); |
| 572 | pj_strdup2(pool, &ctype->media.subtype, "html"); |
Benny Prijono | 1e5a08b | 2010-08-01 09:24:58 +0000 | [diff] [blame] | 573 | prm = PJ_POOL_ALLOC_T(pool, pjsip_param); |
| 574 | prm->name = pj_str("charset"); |
| 575 | prm->value = pj_str("ISO-8859-4"); |
| 576 | pj_list_push_back(&ctype->media.param, prm); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 577 | |
| 578 | /* "Route: <sip:bigbox3.site3.atlanta.com;lr>,\r\n" */ |
| 579 | routing = pjsip_route_hdr_create(pool); |
| 580 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)routing); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 581 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 582 | routing->name_addr.uri = (pjsip_uri*)url; |
| 583 | pj_strdup2(pool, &url->host, "bigbox3.site3.atlanta.com"); |
| 584 | url->lr_param = 1; |
| 585 | |
| 586 | /* " <sip:server10.biloxi.com;lr>\r" */ |
| 587 | routing = pjsip_route_hdr_create(pool); |
| 588 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)routing); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 589 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 590 | routing->name_addr.uri = (pjsip_uri*)url; |
| 591 | pj_strdup2(pool, &url->host, "server10.biloxi.com"); |
| 592 | url->lr_param = 1; |
| 593 | |
| 594 | /* "Record-Route: <sip:server10.biloxi.com>,\r\n" */ |
| 595 | routing = pjsip_rr_hdr_create(pool); |
| 596 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)routing); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 597 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 598 | routing->name_addr.uri = (pjsip_uri*)url; |
| 599 | pj_strdup2(pool, &url->host, "server10.biloxi.com"); |
| 600 | url->lr_param = 0; |
| 601 | |
| 602 | /* " <sip:bigbox3.site3.atlanta.com;lr>\n" */ |
| 603 | routing = pjsip_rr_hdr_create(pool); |
| 604 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)routing); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 605 | url = pjsip_sip_uri_create(pool, 0); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 606 | routing->name_addr.uri = (pjsip_uri*)url; |
| 607 | pj_strdup2(pool, &url->host, "bigbox3.site3.atlanta.com"); |
| 608 | url->lr_param = 1; |
| 609 | |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 610 | /* "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n" */ |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 611 | via = pjsip_via_hdr_create(pool); |
| 612 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 613 | pj_strdup2(pool, &via->transport, "SCTP"); |
| 614 | pj_strdup2(pool, &via->sent_by.host, "bigbox3.site3.atlanta.com"); |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 615 | pj_strdup2(pool, &via->branch_param, "z9hG4bK77ef4c230"); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 616 | |
| 617 | /* "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n" |
| 618 | " ;received=192.0.2.1\r\n" */ |
| 619 | via = pjsip_via_hdr_create(pool); |
| 620 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 621 | pj_strdup2(pool, &via->transport, "UDP"); |
| 622 | pj_strdup2(pool, &via->sent_by.host, "pc33.atlanta.com"); |
| 623 | pj_strdup2(pool, &via->branch_param, "z9hG4bKnashds8"); |
| 624 | pj_strdup2(pool, &via->recvd_param, "192.0.2.1"); |
| 625 | |
| 626 | |
| 627 | /* "Via: SIP/2.0/UDP 10.2.1.1, */ |
| 628 | via = pjsip_via_hdr_create(pool); |
| 629 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 630 | pj_strdup2(pool, &via->transport, "UDP"); |
| 631 | pj_strdup2(pool, &via->sent_by.host, "10.2.1.1"); |
| 632 | |
| 633 | |
| 634 | /*SIP/2.0/TCP 192.168.1.1\n" */ |
| 635 | via = pjsip_via_hdr_create(pool); |
| 636 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 637 | pj_strdup2(pool, &via->transport, "TCP"); |
| 638 | pj_strdup2(pool, &via->sent_by.host, "192.168.1.1"); |
| 639 | |
| 640 | /* "Organization: \r" */ |
| 641 | str.ptr = "Organization"; |
| 642 | str.slen = 12; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 643 | generic = pjsip_generic_string_hdr_create(pool, &str, NULL); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 644 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic); |
| 645 | generic->hvalue.ptr = NULL; |
| 646 | generic->hvalue.slen = 0; |
| 647 | |
| 648 | /* "Max-Forwards: 70\n" */ |
| 649 | str.ptr = "Max-Forwards"; |
| 650 | str.slen = 12; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 651 | generic = pjsip_generic_string_hdr_create(pool, &str, NULL); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 652 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic); |
| 653 | str.ptr = "70"; |
| 654 | str.slen = 2; |
| 655 | generic->hvalue = str; |
| 656 | |
| 657 | /* "X-Header: \r\n" */ |
| 658 | str.ptr = "X-Header"; |
| 659 | str.slen = 8; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 660 | generic = pjsip_generic_string_hdr_create(pool, &str, NULL); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 661 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic); |
| 662 | str.ptr = NULL; |
| 663 | str.slen = 0; |
| 664 | generic->hvalue = str; |
| 665 | |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 666 | /* P-Associated-URI:\r\n */ |
| 667 | str.ptr = "P-Associated-URI"; |
| 668 | str.slen = 16; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 669 | generic = pjsip_generic_string_hdr_create(pool, &str, NULL); |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 670 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic); |
| 671 | str.ptr = NULL; |
| 672 | str.slen = 0; |
| 673 | generic->hvalue = str; |
| 674 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 675 | return msg; |
| 676 | } |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 677 | |
| 678 | static pjsip_msg *create_msg1(pj_pool_t *pool) |
| 679 | { |
| 680 | pjsip_via_hdr *via; |
| 681 | pjsip_route_hdr *route; |
| 682 | pjsip_name_addr *name_addr; |
Benny Prijono | 0c2bc61 | 2006-01-10 13:31:40 +0000 | [diff] [blame] | 683 | pjsip_sip_uri *url; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 684 | pjsip_max_fwd_hdr *max_fwd; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 685 | pjsip_to_hdr *to; |
| 686 | pjsip_from_hdr *from; |
| 687 | pjsip_contact_hdr *contact; |
| 688 | pjsip_ctype_hdr *ctype; |
| 689 | pjsip_cid_hdr *cid; |
| 690 | pjsip_clen_hdr *clen; |
| 691 | pjsip_cseq_hdr *cseq; |
| 692 | pjsip_msg *msg = pjsip_msg_create(pool, PJSIP_RESPONSE_MSG); |
| 693 | pjsip_msg_body *body; |
| 694 | |
| 695 | //"SIP/2.0 200 OK\r\n" |
| 696 | msg->line.status.code = 200; |
| 697 | msg->line.status.reason = pj_str("OK"); |
| 698 | |
Benny Prijono | 4cf8d1c | 2007-04-28 15:37:49 +0000 | [diff] [blame] | 699 | //"Via: SIP/2.0/SCTP server10.biloxi.com;branch=z9hG4bKnashds8;rport;received=192.0.2.1\r\n" |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 700 | via = pjsip_via_hdr_create(pool); |
| 701 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 702 | via->transport = pj_str("SCTP"); |
| 703 | via->sent_by.host = pj_str("server10.biloxi.com"); |
| 704 | via->branch_param = pj_str("z9hG4bKnashds8"); |
| 705 | via->rport_param = 0; |
| 706 | via->recvd_param = pj_str("192.0.2.1"); |
| 707 | |
| 708 | //"Via: SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1;received=192.0.2.2\r\n" |
| 709 | via = pjsip_via_hdr_create(pool); |
| 710 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 711 | via->transport = pj_str("UDP"); |
| 712 | via->sent_by.host = pj_str("bigbox3.site3.atlanta.com"); |
| 713 | via->branch_param = pj_str("z9hG4bK77ef4c2312983.1"); |
| 714 | via->recvd_param = pj_str("192.0.2.2"); |
| 715 | |
| 716 | //"Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds ;received=192.0.2.3\r\n" |
| 717 | via = pjsip_via_hdr_create(pool); |
| 718 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)via); |
| 719 | via->transport = pj_str("UDP"); |
| 720 | via->sent_by.host = pj_str("pc33.atlanta.com"); |
| 721 | via->branch_param = pj_str("z9hG4bK776asdhds"); |
| 722 | via->recvd_param = pj_str("192.0.2.3"); |
| 723 | |
| 724 | //"Route: <sip:proxy.sipprovider.com>\r\n" |
| 725 | route = pjsip_route_hdr_create(pool); |
| 726 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)route); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 727 | url = pjsip_sip_uri_create(pool, PJ_FALSE); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 728 | route->name_addr.uri = (pjsip_uri*)url; |
| 729 | url->host = pj_str("proxy.sipprovider.com"); |
| 730 | |
| 731 | //"Route: <sip:proxy.supersip.com:5060>\r\n" |
| 732 | route = pjsip_route_hdr_create(pool); |
| 733 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)route); |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 734 | url = pjsip_sip_uri_create(pool, PJ_FALSE); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 735 | route->name_addr.uri = (pjsip_uri*)url; |
| 736 | url->host = pj_str("proxy.supersip.com"); |
| 737 | url->port = 5060; |
| 738 | |
| 739 | //"Max-Forwards: 70\r\n" |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 740 | max_fwd = pjsip_max_fwd_hdr_create(pool, 70); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 741 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)max_fwd); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 742 | |
| 743 | //"To: Bob <sip:bob@biloxi.com>;tag=a6c85cf\r\n" |
| 744 | to = pjsip_to_hdr_create(pool); |
| 745 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)to); |
| 746 | name_addr = pjsip_name_addr_create(pool); |
| 747 | name_addr->display = pj_str("Bob"); |
| 748 | to->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 749 | url = pjsip_sip_uri_create(pool, PJ_FALSE); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 750 | name_addr->uri = (pjsip_uri*)url; |
| 751 | url->user = pj_str("bob"); |
| 752 | url->host = pj_str("biloxi.com"); |
| 753 | to->tag = pj_str("a6c85cf"); |
| 754 | |
| 755 | //"From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n" |
| 756 | from = pjsip_from_hdr_create(pool); |
| 757 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)from); |
| 758 | name_addr = pjsip_name_addr_create(pool); |
| 759 | name_addr->display = pj_str("Alice"); |
| 760 | from->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 761 | url = pjsip_sip_uri_create(pool, PJ_FALSE); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 762 | name_addr->uri = (pjsip_uri*)url; |
| 763 | url->user = pj_str("alice"); |
| 764 | url->host = pj_str("atlanta.com"); |
| 765 | from->tag = pj_str("1928301774"); |
| 766 | |
| 767 | //"Call-ID: a84b4c76e66710@pc33.atlanta.com\r\n" |
| 768 | cid = pjsip_cid_hdr_create(pool); |
| 769 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)cid); |
| 770 | cid->id = pj_str("a84b4c76e66710@pc33.atlanta.com"); |
| 771 | |
| 772 | //"CSeq: 314159 INVITE\r\n" |
| 773 | cseq = pjsip_cseq_hdr_create(pool); |
| 774 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)cseq); |
| 775 | cseq->cseq = 314159; |
| 776 | pjsip_method_set(&cseq->method, PJSIP_INVITE_METHOD); |
| 777 | |
| 778 | //"Contact: <sips:bob@192.0.2.4>\r\n" |
| 779 | contact = pjsip_contact_hdr_create(pool); |
| 780 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)contact); |
| 781 | name_addr = pjsip_name_addr_create(pool); |
| 782 | contact->uri = (pjsip_uri*)name_addr; |
Benny Prijono | 40f2f64 | 2006-01-30 18:40:05 +0000 | [diff] [blame] | 783 | url = pjsip_sip_uri_create(pool, PJ_TRUE); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 784 | name_addr->uri = (pjsip_uri*)url; |
| 785 | url->user = pj_str("bob"); |
| 786 | url->host = pj_str("192.0.2.4"); |
| 787 | |
| 788 | //"Content-Type: application/sdp\r\n" |
| 789 | ctype = pjsip_ctype_hdr_create(pool); |
| 790 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)ctype); |
| 791 | ctype->media.type = pj_str("application"); |
| 792 | ctype->media.subtype = pj_str("sdp"); |
| 793 | |
| 794 | //"Content-Length: 150\r\n" |
| 795 | clen = pjsip_clen_hdr_create(pool); |
| 796 | pjsip_msg_add_hdr(msg, (pjsip_hdr*)clen); |
| 797 | clen->len = 150; |
| 798 | |
| 799 | // Body |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 800 | body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 801 | msg->body = body; |
| 802 | body->content_type.type = pj_str("application"); |
| 803 | body->content_type.subtype = pj_str("sdp"); |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 804 | body->data = (void*) |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 805 | "v=0\r\n" |
| 806 | "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n" |
| 807 | "s=-\r\n" |
| 808 | "t=0 0\r\n" |
| 809 | "c=IN IP4 pc33.atlanta.com\r\n" |
| 810 | "m=audio 3456 RTP/AVP 0 1 3 99\r\n" |
| 811 | "a=rtpmap:0 PCMU/8000\r\n"; |
Nanang Izzuddin | 7d1ac29 | 2008-09-16 17:02:48 +0000 | [diff] [blame] | 812 | body->len = pj_ansi_strlen((const char*) body->data); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 813 | body->print_body = &pjsip_print_text_body; |
| 814 | |
| 815 | return msg; |
| 816 | } |
| 817 | |
| 818 | /*****************************************************************************/ |
| 819 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 820 | static pj_status_t simple_test(void) |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 821 | { |
Benny Prijono | c6ff4b8 | 2009-05-12 15:55:09 +0000 | [diff] [blame] | 822 | char stbuf[] = "SIP/2.0 180 Ringing like it never rings before"; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 823 | unsigned i; |
Benny Prijono | c6ff4b8 | 2009-05-12 15:55:09 +0000 | [diff] [blame] | 824 | pjsip_status_line st_line; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 825 | pj_status_t status; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 826 | |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 827 | PJ_LOG(3,(THIS_FILE, " simple test..")); |
Benny Prijono | c6ff4b8 | 2009-05-12 15:55:09 +0000 | [diff] [blame] | 828 | |
| 829 | status = pjsip_parse_status_line(stbuf, pj_ansi_strlen(stbuf), &st_line); |
| 830 | if (status != PJ_SUCCESS) |
| 831 | return status; |
| 832 | |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 833 | for (i=0; i<PJ_ARRAY_SIZE(test_array); ++i) { |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 834 | pj_pool_t *pool; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 835 | pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE); |
| 836 | status = test_entry( pool, &test_array[i] ); |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 837 | pjsip_endpt_release_pool(endpt, pool); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 838 | |
| 839 | if (status != PJ_SUCCESS) |
| 840 | return status; |
| 841 | } |
| 842 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 843 | return PJ_SUCCESS; |
| 844 | } |
| 845 | |
| 846 | |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 847 | #if INCLUDE_BENCHMARKS |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 848 | static int msg_benchmark(unsigned *p_detect, unsigned *p_parse, |
| 849 | unsigned *p_print) |
| 850 | { |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 851 | pj_pool_t *pool; |
| 852 | int i, loop; |
| 853 | pj_timestamp zero; |
| 854 | pj_time_val elapsed; |
| 855 | pj_highprec_t avg_detect, avg_parse, avg_print, kbytes; |
Nanang Izzuddin | 2e4f03f | 2009-04-27 19:18:38 +0000 | [diff] [blame] | 856 | pj_status_t status = PJ_SUCCESS; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 857 | |
Benny Prijono | ac623b3 | 2006-07-03 15:19:31 +0000 | [diff] [blame] | 858 | pj_bzero(&var, sizeof(var)); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 859 | zero.u64 = 0; |
| 860 | |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 861 | for (loop=0; loop<LOOP; ++loop) { |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 862 | for (i=0; i<(int)PJ_ARRAY_SIZE(test_array); ++i) { |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 863 | pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE); |
| 864 | status = test_entry( pool, &test_array[i] ); |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 865 | pjsip_endpt_release_pool(endpt, pool); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 866 | |
| 867 | if (status != PJ_SUCCESS) |
| 868 | return status; |
| 869 | } |
| 870 | } |
| 871 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 872 | kbytes = var.detect_len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 873 | pj_highprec_mod(kbytes, 1000000); |
| 874 | pj_highprec_div(kbytes, 100000); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 875 | elapsed = pj_elapsed_time(&zero, &var.detect_time); |
| 876 | avg_detect = pj_elapsed_usec(&zero, &var.detect_time); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 877 | pj_highprec_mul(avg_detect, AVERAGE_MSG_LEN); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 878 | pj_highprec_div(avg_detect, var.detect_len); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 879 | avg_detect = 1000000 / avg_detect; |
| 880 | |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 881 | PJ_LOG(3,(THIS_FILE, |
| 882 | " %u.%u MB detected in %d.%03ds (avg=%d msg detection/sec)", |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 883 | (unsigned)(var.detect_len/1000000), (unsigned)kbytes, |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 884 | elapsed.sec, elapsed.msec, |
| 885 | (unsigned)avg_detect)); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 886 | *p_detect = (unsigned)avg_detect; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 887 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 888 | kbytes = var.parse_len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 889 | pj_highprec_mod(kbytes, 1000000); |
| 890 | pj_highprec_div(kbytes, 100000); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 891 | elapsed = pj_elapsed_time(&zero, &var.parse_time); |
| 892 | avg_parse = pj_elapsed_usec(&zero, &var.parse_time); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 893 | pj_highprec_mul(avg_parse, AVERAGE_MSG_LEN); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 894 | pj_highprec_div(avg_parse, var.parse_len); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 895 | avg_parse = 1000000 / avg_parse; |
| 896 | |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 897 | PJ_LOG(3,(THIS_FILE, |
| 898 | " %u.%u MB parsed in %d.%03ds (avg=%d msg parsing/sec)", |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 899 | (unsigned)(var.parse_len/1000000), (unsigned)kbytes, |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 900 | elapsed.sec, elapsed.msec, |
| 901 | (unsigned)avg_parse)); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 902 | *p_parse = (unsigned)avg_parse; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 903 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 904 | kbytes = var.print_len; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 905 | pj_highprec_mod(kbytes, 1000000); |
| 906 | pj_highprec_div(kbytes, 100000); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 907 | elapsed = pj_elapsed_time(&zero, &var.print_time); |
| 908 | avg_print = pj_elapsed_usec(&zero, &var.print_time); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 909 | pj_highprec_mul(avg_print, AVERAGE_MSG_LEN); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 910 | pj_highprec_div(avg_print, var.print_len); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 911 | avg_print = 1000000 / avg_print; |
| 912 | |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 913 | PJ_LOG(3,(THIS_FILE, |
| 914 | " %u.%u MB printed in %d.%03ds (avg=%d msg print/sec)", |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 915 | (unsigned)(var.print_len/1000000), (unsigned)kbytes, |
Benny Prijono | 85598d9 | 2006-01-07 18:44:25 +0000 | [diff] [blame] | 916 | elapsed.sec, elapsed.msec, |
| 917 | (unsigned)avg_print)); |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 918 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 919 | *p_print = (unsigned)avg_print; |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 920 | return status; |
| 921 | } |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 922 | #endif /* INCLUDE_BENCHMARKS */ |
Benny Prijono | 3818c93 | 2005-11-22 01:06:33 +0000 | [diff] [blame] | 923 | |
| 924 | /*****************************************************************************/ |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 925 | /* Test various header parsing and production */ |
| 926 | static int hdr_test_success(pjsip_hdr *h); |
| 927 | static int hdr_test_accept0(pjsip_hdr *h); |
| 928 | static int hdr_test_accept1(pjsip_hdr *h); |
| 929 | static int hdr_test_accept2(pjsip_hdr *h); |
| 930 | static int hdr_test_allow0(pjsip_hdr *h); |
| 931 | static int hdr_test_authorization(pjsip_hdr *h); |
| 932 | static int hdr_test_cid(pjsip_hdr *h); |
| 933 | static int hdr_test_contact0(pjsip_hdr *h); |
| 934 | static int hdr_test_contact1(pjsip_hdr *h); |
Benny Prijono | 123fad7 | 2008-06-11 11:18:04 +0000 | [diff] [blame] | 935 | static int hdr_test_contact_q0(pjsip_hdr *h); |
| 936 | static int hdr_test_contact_q1(pjsip_hdr *h); |
| 937 | static int hdr_test_contact_q2(pjsip_hdr *h); |
| 938 | static int hdr_test_contact_q3(pjsip_hdr *h); |
| 939 | static int hdr_test_contact_q4(pjsip_hdr *h); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 940 | static int hdr_test_content_length(pjsip_hdr *h); |
| 941 | static int hdr_test_content_type(pjsip_hdr *h); |
| 942 | static int hdr_test_from(pjsip_hdr *h); |
| 943 | static int hdr_test_proxy_authenticate(pjsip_hdr *h); |
| 944 | static int hdr_test_record_route(pjsip_hdr *h); |
| 945 | static int hdr_test_supported(pjsip_hdr *h); |
| 946 | static int hdr_test_to(pjsip_hdr *h); |
| 947 | static int hdr_test_via(pjsip_hdr *h); |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 948 | static int hdr_test_via_ipv6_1(pjsip_hdr *h); |
| 949 | static int hdr_test_via_ipv6_2(pjsip_hdr *h); |
| 950 | static int hdr_test_via_ipv6_3(pjsip_hdr *h); |
Benny Prijono | 054c5df | 2008-05-15 10:07:36 +0000 | [diff] [blame] | 951 | static int hdr_test_retry_after1(pjsip_hdr *h); |
Benny Prijono | 3c97d9b | 2008-09-21 22:01:46 +0000 | [diff] [blame] | 952 | static int hdr_test_subject_utf(pjsip_hdr *h); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 953 | |
| 954 | |
| 955 | #define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3" |
| 956 | #define GENERIC_PARAM_PARSED "p0=a;p1=\"ab:;cd\";p2=ab:cd;p3" |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 957 | #define PARAM_CHAR "][/:&+$" |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 958 | #define SIMPLE_ADDR_SPEC "sip:host" |
Benny Prijono | 8fcbe2d | 2007-04-29 18:07:53 +0000 | [diff] [blame] | 959 | #define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\"" |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 960 | #define NAME_ADDR "<" ADDR_SPEC ">" |
| 961 | |
| 962 | #define HDR_FLAG_PARSE_FAIL 1 |
| 963 | #define HDR_FLAG_DONT_PRINT 2 |
| 964 | |
| 965 | struct hdr_test_t |
| 966 | { |
| 967 | char *hname; |
| 968 | char *hshort_name; |
Benny Prijono | d661f57 | 2009-01-28 14:17:14 +0000 | [diff] [blame] | 969 | char *hcontent; |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 970 | int (*test)(pjsip_hdr*); |
| 971 | unsigned flags; |
| 972 | } hdr_test_data[] = |
| 973 | { |
| 974 | { |
| 975 | /* Empty Accept */ |
| 976 | "Accept", NULL, |
| 977 | "", |
| 978 | &hdr_test_accept0 |
| 979 | }, |
| 980 | |
| 981 | { |
| 982 | /* Overflowing generic string header */ |
| 983 | "Accept", NULL, |
| 984 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 985 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 986 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 987 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 988 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 989 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 990 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, " \ |
| 991 | "a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a", |
| 992 | &hdr_test_success, |
| 993 | HDR_FLAG_PARSE_FAIL |
| 994 | }, |
| 995 | |
| 996 | { |
| 997 | /* Normal Accept */ |
| 998 | "Accept", NULL, |
| 999 | "application/*, text/plain", |
| 1000 | &hdr_test_accept1 |
| 1001 | }, |
| 1002 | |
| 1003 | { |
| 1004 | /* Accept with params */ |
| 1005 | "Accept", NULL, |
| 1006 | "application/*;p1=v1, text/plain", |
| 1007 | &hdr_test_accept2 |
| 1008 | }, |
| 1009 | |
| 1010 | { |
| 1011 | /* Empty Allow */ |
| 1012 | "Allow", NULL, |
| 1013 | "", |
| 1014 | &hdr_test_allow0, |
| 1015 | }, |
| 1016 | |
| 1017 | { |
| 1018 | /* Authorization, testing which params should be quoted */ |
| 1019 | "Authorization", NULL, |
| 1020 | "Digest username=\"username\", realm=\"realm\", nonce=\"nonce\", " \ |
| 1021 | "uri=\"sip:domain\", response=\"RESPONSE\", algorithm=MD5, " \ |
| 1022 | "cnonce=\"CNONCE\", opaque=\"OPAQUE\", qop=auth, nc=00000001", |
| 1023 | &hdr_test_authorization |
| 1024 | }, |
| 1025 | |
| 1026 | { |
| 1027 | /* Call ID */ |
| 1028 | "Call-ID", "i", |
| 1029 | "-.!%*_+`'~()<>:\\\"/[]?{}", |
| 1030 | &hdr_test_cid, |
| 1031 | }, |
| 1032 | |
| 1033 | { |
| 1034 | /* Parameter belong to hparam */ |
| 1035 | "Contact", "m", |
| 1036 | SIMPLE_ADDR_SPEC ";p1=v1", |
| 1037 | &hdr_test_contact0, |
| 1038 | HDR_FLAG_DONT_PRINT |
| 1039 | }, |
| 1040 | |
| 1041 | { |
| 1042 | /* generic-param in Contact header */ |
| 1043 | "Contact", "m", |
| 1044 | NAME_ADDR ";" GENERIC_PARAM, |
| 1045 | &hdr_test_contact1 |
| 1046 | }, |
| 1047 | |
| 1048 | { |
Benny Prijono | 123fad7 | 2008-06-11 11:18:04 +0000 | [diff] [blame] | 1049 | /* q=0 parameter in Contact header */ |
| 1050 | "Contact", "m", |
| 1051 | NAME_ADDR ";q=0", |
| 1052 | &hdr_test_contact_q0, |
| 1053 | HDR_FLAG_DONT_PRINT |
| 1054 | }, |
| 1055 | |
| 1056 | { |
| 1057 | /* q=0.5 parameter in Contact header */ |
| 1058 | "Contact", "m", |
| 1059 | NAME_ADDR ";q=0.5", |
| 1060 | &hdr_test_contact_q1 |
| 1061 | }, |
| 1062 | |
| 1063 | { |
| 1064 | /* q=1 parameter in Contact header */ |
| 1065 | "Contact", "m", |
| 1066 | NAME_ADDR ";q=1", |
| 1067 | &hdr_test_contact_q2 |
| 1068 | }, |
| 1069 | |
| 1070 | { |
| 1071 | /* q=1.0 parameter in Contact header */ |
| 1072 | "Contact", "m", |
| 1073 | NAME_ADDR ";q=1.0", |
| 1074 | &hdr_test_contact_q3, |
| 1075 | HDR_FLAG_DONT_PRINT |
| 1076 | }, |
| 1077 | |
| 1078 | { |
| 1079 | /* q=1.1 parameter in Contact header */ |
| 1080 | "Contact", "m", |
| 1081 | NAME_ADDR ";q=1.15", |
| 1082 | &hdr_test_contact_q4 |
| 1083 | }, |
| 1084 | |
| 1085 | { |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1086 | /* Content-Length */ |
| 1087 | "Content-Length", "l", |
| 1088 | "10", |
| 1089 | &hdr_test_content_length |
| 1090 | }, |
| 1091 | |
| 1092 | { |
| 1093 | /* Content-Type, with generic-param */ |
| 1094 | "Content-Type", "c", |
| 1095 | "application/sdp" ";" GENERIC_PARAM, |
| 1096 | &hdr_test_content_type, |
| 1097 | HDR_FLAG_DONT_PRINT |
| 1098 | }, |
| 1099 | |
| 1100 | { |
| 1101 | /* From, testing parameters and generic-param */ |
| 1102 | "From", "f", |
| 1103 | NAME_ADDR ";" GENERIC_PARAM, |
| 1104 | &hdr_test_from |
| 1105 | }, |
| 1106 | |
| 1107 | { |
| 1108 | /* Proxy-Authenticate, testing which params should be quoted */ |
| 1109 | "Proxy-Authenticate", NULL, |
| 1110 | "Digest realm=\"realm\",domain=\"sip:domain\",nonce=\"nonce\"," \ |
| 1111 | "opaque=\"opaque\",stale=true,algorithm=MD5,qop=\"auth\"", |
| 1112 | &hdr_test_proxy_authenticate |
| 1113 | }, |
| 1114 | |
| 1115 | { |
| 1116 | /* Record-Route, param belong to header */ |
| 1117 | "Record-Route", NULL, |
| 1118 | NAME_ADDR ";" GENERIC_PARAM, |
| 1119 | &hdr_test_record_route |
| 1120 | }, |
| 1121 | |
| 1122 | { |
| 1123 | /* Empty Supported */ |
| 1124 | "Supported", "k", |
| 1125 | "", |
| 1126 | &hdr_test_supported, |
| 1127 | }, |
| 1128 | |
| 1129 | { |
| 1130 | /* To */ |
| 1131 | "To", "t", |
| 1132 | NAME_ADDR ";" GENERIC_PARAM, |
| 1133 | &hdr_test_to |
| 1134 | }, |
| 1135 | |
| 1136 | { |
| 1137 | /* Via */ |
| 1138 | "Via", "v", |
| 1139 | "SIP/2.0/XYZ host" ";" GENERIC_PARAM, |
| 1140 | &hdr_test_via |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 1141 | }, |
| 1142 | |
| 1143 | { |
| 1144 | /* Via with IPv6 */ |
| 1145 | "Via", "v", |
| 1146 | "SIP/2.0/UDP [::1]", |
| 1147 | &hdr_test_via_ipv6_1 |
| 1148 | }, |
| 1149 | |
| 1150 | { |
| 1151 | /* Via with IPv6 */ |
| 1152 | "Via", "v", |
| 1153 | "SIP/2.0/UDP [::1]:5061", |
| 1154 | &hdr_test_via_ipv6_2 |
| 1155 | }, |
| 1156 | |
| 1157 | { |
| 1158 | /* Via with IPv6 */ |
| 1159 | "Via", "v", |
| 1160 | "SIP/2.0/UDP [::1];rport=5061;received=::2", |
| 1161 | &hdr_test_via_ipv6_3 |
Benny Prijono | 054c5df | 2008-05-15 10:07:36 +0000 | [diff] [blame] | 1162 | }, |
| 1163 | |
| 1164 | { |
| 1165 | /* Retry-After header with comment */ |
| 1166 | "Retry-After", NULL, |
| 1167 | "10(Already Pending Register)", |
| 1168 | &hdr_test_retry_after1 |
Benny Prijono | 3c97d9b | 2008-09-21 22:01:46 +0000 | [diff] [blame] | 1169 | }, |
| 1170 | |
| 1171 | { |
| 1172 | /* Non-ASCII UTF-8 characters in Subject */ |
| 1173 | "Subject", NULL, |
| 1174 | "\xC0\x81", |
| 1175 | &hdr_test_subject_utf |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1176 | } |
| 1177 | }; |
| 1178 | |
| 1179 | static int hdr_test_success(pjsip_hdr *h) |
| 1180 | { |
| 1181 | PJ_UNUSED_ARG(h); |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | /* "" */ |
| 1186 | static int hdr_test_accept0(pjsip_hdr *h) |
| 1187 | { |
| 1188 | pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; |
| 1189 | |
| 1190 | if (h->type != PJSIP_H_ACCEPT) |
| 1191 | return -1010; |
| 1192 | |
| 1193 | if (hdr->count != 0) |
| 1194 | return -1020; |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1199 | /* "application/ *, text/plain\r\n" */ |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1200 | static int hdr_test_accept1(pjsip_hdr *h) |
| 1201 | { |
| 1202 | pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; |
| 1203 | |
| 1204 | if (h->type != PJSIP_H_ACCEPT) |
| 1205 | return -1110; |
| 1206 | |
| 1207 | if (hdr->count != 2) |
| 1208 | return -1120; |
| 1209 | |
| 1210 | if (pj_strcmp2(&hdr->values[0], "application/*")) |
| 1211 | return -1130; |
| 1212 | |
| 1213 | if (pj_strcmp2(&hdr->values[1], "text/plain")) |
| 1214 | return -1140; |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1219 | /* "application/ *;p1=v1, text/plain\r\n" */ |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1220 | static int hdr_test_accept2(pjsip_hdr *h) |
| 1221 | { |
| 1222 | pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)h; |
| 1223 | |
| 1224 | if (h->type != PJSIP_H_ACCEPT) |
| 1225 | return -1210; |
| 1226 | |
| 1227 | if (hdr->count != 2) |
| 1228 | return -1220; |
| 1229 | |
| 1230 | if (pj_strcmp2(&hdr->values[0], "application/*;p1=v1")) |
| 1231 | return -1230; |
| 1232 | |
| 1233 | if (pj_strcmp2(&hdr->values[1], "text/plain")) |
| 1234 | return -1240; |
| 1235 | |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | /* "" */ |
| 1240 | static int hdr_test_allow0(pjsip_hdr *h) |
| 1241 | { |
| 1242 | pjsip_allow_hdr *hdr = (pjsip_allow_hdr*)h; |
| 1243 | |
| 1244 | if (h->type != PJSIP_H_ALLOW) |
| 1245 | return -1310; |
| 1246 | |
| 1247 | if (hdr->count != 0) |
| 1248 | return -1320; |
| 1249 | |
| 1250 | return 0; |
| 1251 | |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | /* |
| 1256 | "Digest username=\"username\", realm=\"realm\", nonce=\"nonce\", " \ |
| 1257 | "uri=\"sip:domain\", response=\"RESPONSE\", algorithm=MD5, " \ |
| 1258 | "cnonce=\"CNONCE\", opaque=\"OPAQUE\", qop=auth, nc=00000001", |
| 1259 | */ |
| 1260 | static int hdr_test_authorization(pjsip_hdr *h) |
| 1261 | { |
| 1262 | pjsip_authorization_hdr *hdr = (pjsip_authorization_hdr*)h; |
| 1263 | |
| 1264 | if (h->type != PJSIP_H_AUTHORIZATION) |
| 1265 | return -1410; |
| 1266 | |
| 1267 | if (pj_strcmp2(&hdr->scheme, "Digest")) |
| 1268 | return -1420; |
| 1269 | |
| 1270 | if (pj_strcmp2(&hdr->credential.digest.username, "username")) |
| 1271 | return -1421; |
| 1272 | |
| 1273 | if (pj_strcmp2(&hdr->credential.digest.realm, "realm")) |
| 1274 | return -1422; |
| 1275 | |
| 1276 | if (pj_strcmp2(&hdr->credential.digest.nonce, "nonce")) |
| 1277 | return -1423; |
| 1278 | |
| 1279 | if (pj_strcmp2(&hdr->credential.digest.uri, "sip:domain")) |
| 1280 | return -1424; |
| 1281 | |
| 1282 | if (pj_strcmp2(&hdr->credential.digest.response, "RESPONSE")) |
| 1283 | return -1425; |
| 1284 | |
| 1285 | if (pj_strcmp2(&hdr->credential.digest.algorithm, "MD5")) |
| 1286 | return -1426; |
| 1287 | |
| 1288 | if (pj_strcmp2(&hdr->credential.digest.cnonce, "CNONCE")) |
| 1289 | return -1427; |
| 1290 | |
| 1291 | if (pj_strcmp2(&hdr->credential.digest.opaque, "OPAQUE")) |
| 1292 | return -1428; |
| 1293 | |
| 1294 | if (pj_strcmp2(&hdr->credential.digest.qop, "auth")) |
| 1295 | return -1429; |
| 1296 | |
| 1297 | if (pj_strcmp2(&hdr->credential.digest.nc, "00000001")) |
| 1298 | return -1430; |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | /* |
| 1305 | "-.!%*_+`'~()<>:\\\"/[]?{}\r\n" |
| 1306 | */ |
| 1307 | static int hdr_test_cid(pjsip_hdr *h) |
| 1308 | { |
| 1309 | pjsip_cid_hdr *hdr = (pjsip_cid_hdr*)h; |
| 1310 | |
| 1311 | if (h->type != PJSIP_H_CALL_ID) |
| 1312 | return -1510; |
| 1313 | |
Benny Prijono | 91a5a3a | 2007-09-24 21:16:48 +0000 | [diff] [blame] | 1314 | if (pj_strcmp2(&hdr->id, "-.!%*_+`'~()<>:\\\"/[]?{}")) |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1315 | return -1520; |
| 1316 | |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
| 1320 | /* |
| 1321 | #define SIMPLE_ADDR_SPEC "sip:host" |
| 1322 | */ |
| 1323 | static int test_simple_addr_spec(pjsip_uri *uri) |
| 1324 | { |
| 1325 | pjsip_sip_uri *sip_uri = (pjsip_sip_uri *)pjsip_uri_get_uri(uri); |
| 1326 | |
| 1327 | if (!PJSIP_URI_SCHEME_IS_SIP(uri)) |
| 1328 | return -900; |
| 1329 | |
| 1330 | if (pj_strcmp2(&sip_uri->host, "host")) |
| 1331 | return -910; |
| 1332 | |
| 1333 | if (sip_uri->port != 0) |
| 1334 | return -920; |
| 1335 | |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
| 1339 | /* |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 1340 | #define PARAM_CHAR "][/:&+$" |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1341 | #define SIMPLE_ADDR_SPEC "sip:host" |
Benny Prijono | 8fcbe2d | 2007-04-29 18:07:53 +0000 | [diff] [blame] | 1342 | #define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\"" |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1343 | #define NAME_ADDR "<" ADDR_SPEC ">" |
| 1344 | */ |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1345 | static int nameaddr_test(void *uri) |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1346 | { |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1347 | pjsip_sip_uri *sip_uri=(pjsip_sip_uri *)pjsip_uri_get_uri((pjsip_uri*)uri); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1348 | pjsip_param *param; |
| 1349 | int rc; |
| 1350 | |
| 1351 | if (!PJSIP_URI_SCHEME_IS_SIP(uri)) |
| 1352 | return -930; |
| 1353 | |
| 1354 | rc = test_simple_addr_spec((pjsip_uri*)sip_uri); |
| 1355 | if (rc != 0) |
| 1356 | return rc; |
| 1357 | |
Benny Prijono | 8fcbe2d | 2007-04-29 18:07:53 +0000 | [diff] [blame] | 1358 | if (pj_list_size(&sip_uri->other_param) != 2) |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1359 | return -940; |
| 1360 | |
| 1361 | param = sip_uri->other_param.next; |
| 1362 | |
| 1363 | if (pj_strcmp2(¶m->name, PARAM_CHAR)) |
| 1364 | return -942; |
| 1365 | |
| 1366 | if (pj_strcmp2(¶m->value, PARAM_CHAR)) |
| 1367 | return -943; |
| 1368 | |
Benny Prijono | 8fcbe2d | 2007-04-29 18:07:53 +0000 | [diff] [blame] | 1369 | param = param->next; |
| 1370 | if (pj_strcmp2(¶m->name, "p1")) |
| 1371 | return -942; |
| 1372 | if (pj_strcmp2(¶m->value, "\";\"")) |
| 1373 | return -943; |
| 1374 | |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | #define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3" |
| 1380 | */ |
| 1381 | static int generic_param_test(pjsip_param *param_head) |
| 1382 | { |
| 1383 | pjsip_param *param; |
| 1384 | |
| 1385 | if (pj_list_size(param_head) != 4) |
| 1386 | return -950; |
| 1387 | |
| 1388 | param = param_head->next; |
| 1389 | |
| 1390 | if (pj_strcmp2(¶m->name, "p0")) |
| 1391 | return -952; |
| 1392 | if (pj_strcmp2(¶m->value, "a")) |
| 1393 | return -953; |
| 1394 | |
| 1395 | param = param->next; |
| 1396 | if (pj_strcmp2(¶m->name, "p1")) |
| 1397 | return -954; |
| 1398 | if (pj_strcmp2(¶m->value, "\"ab:;cd\"")) |
| 1399 | return -955; |
| 1400 | |
| 1401 | param = param->next; |
| 1402 | if (pj_strcmp2(¶m->name, "p2")) |
| 1403 | return -956; |
| 1404 | if (pj_strcmp2(¶m->value, "ab:cd")) |
| 1405 | return -957; |
| 1406 | |
| 1407 | param = param->next; |
| 1408 | if (pj_strcmp2(¶m->name, "p3")) |
| 1409 | return -958; |
| 1410 | if (pj_strcmp2(¶m->value, "")) |
| 1411 | return -959; |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | /* |
| 1419 | SIMPLE_ADDR_SPEC ";p1=v1\r\n" |
| 1420 | */ |
| 1421 | static int hdr_test_contact0(pjsip_hdr *h) |
| 1422 | { |
| 1423 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1424 | pjsip_param *param; |
| 1425 | int rc; |
| 1426 | |
| 1427 | if (h->type != PJSIP_H_CONTACT) |
| 1428 | return -1610; |
| 1429 | |
| 1430 | rc = test_simple_addr_spec(hdr->uri); |
| 1431 | if (rc != 0) |
| 1432 | return rc; |
| 1433 | |
| 1434 | if (pj_list_size(&hdr->other_param) != 1) |
| 1435 | return -1620; |
| 1436 | |
| 1437 | param = hdr->other_param.next; |
| 1438 | |
| 1439 | if (pj_strcmp2(¶m->name, "p1")) |
| 1440 | return -1630; |
| 1441 | |
| 1442 | if (pj_strcmp2(¶m->value, "v1")) |
| 1443 | return -1640; |
| 1444 | |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | NAME_ADDR GENERIC_PARAM "\r\n", |
| 1450 | */ |
| 1451 | static int hdr_test_contact1(pjsip_hdr *h) |
| 1452 | { |
| 1453 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1454 | int rc; |
| 1455 | |
| 1456 | if (h->type != PJSIP_H_CONTACT) |
| 1457 | return -1710; |
| 1458 | |
| 1459 | rc = nameaddr_test(hdr->uri); |
| 1460 | if (rc != 0) |
| 1461 | return rc; |
| 1462 | |
| 1463 | rc = generic_param_test(&hdr->other_param); |
| 1464 | if (rc != 0) |
| 1465 | return rc; |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | /* |
Benny Prijono | 123fad7 | 2008-06-11 11:18:04 +0000 | [diff] [blame] | 1471 | NAME_ADDR ";q=0" |
| 1472 | */ |
| 1473 | static int hdr_test_contact_q0(pjsip_hdr *h) |
| 1474 | { |
| 1475 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1476 | int rc; |
| 1477 | |
| 1478 | if (h->type != PJSIP_H_CONTACT) |
| 1479 | return -1710; |
| 1480 | |
| 1481 | rc = nameaddr_test(hdr->uri); |
| 1482 | if (rc != 0) |
| 1483 | return rc; |
| 1484 | |
| 1485 | if (hdr->q1000 != 0) |
| 1486 | return -1711; |
| 1487 | |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
| 1491 | /* |
| 1492 | NAME_ADDR ";q=0.5" |
| 1493 | */ |
| 1494 | static int hdr_test_contact_q1(pjsip_hdr *h) |
| 1495 | { |
| 1496 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1497 | int rc; |
| 1498 | |
| 1499 | if (h->type != PJSIP_H_CONTACT) |
| 1500 | return -1710; |
| 1501 | |
| 1502 | rc = nameaddr_test(hdr->uri); |
| 1503 | if (rc != 0) |
| 1504 | return rc; |
| 1505 | |
| 1506 | if (hdr->q1000 != 500) |
| 1507 | return -1712; |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | /* |
| 1513 | NAME_ADDR ";q=1" |
| 1514 | */ |
| 1515 | static int hdr_test_contact_q2(pjsip_hdr *h) |
| 1516 | { |
| 1517 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1518 | int rc; |
| 1519 | |
| 1520 | if (h->type != PJSIP_H_CONTACT) |
| 1521 | return -1710; |
| 1522 | |
| 1523 | rc = nameaddr_test(hdr->uri); |
| 1524 | if (rc != 0) |
| 1525 | return rc; |
| 1526 | |
| 1527 | if (hdr->q1000 != 1000) |
| 1528 | return -1713; |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | /* |
| 1534 | NAME_ADDR ";q=1.0" |
| 1535 | */ |
| 1536 | static int hdr_test_contact_q3(pjsip_hdr *h) |
| 1537 | { |
| 1538 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1539 | int rc; |
| 1540 | |
| 1541 | if (h->type != PJSIP_H_CONTACT) |
| 1542 | return -1710; |
| 1543 | |
| 1544 | rc = nameaddr_test(hdr->uri); |
| 1545 | if (rc != 0) |
| 1546 | return rc; |
| 1547 | |
| 1548 | if (hdr->q1000 != 1000) |
| 1549 | return -1714; |
| 1550 | |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | /* |
| 1555 | NAME_ADDR ";q=1.15" |
| 1556 | */ |
| 1557 | static int hdr_test_contact_q4(pjsip_hdr *h) |
| 1558 | { |
| 1559 | pjsip_contact_hdr *hdr = (pjsip_contact_hdr*)h; |
| 1560 | int rc; |
| 1561 | |
| 1562 | if (h->type != PJSIP_H_CONTACT) |
| 1563 | return -1710; |
| 1564 | |
| 1565 | rc = nameaddr_test(hdr->uri); |
| 1566 | if (rc != 0) |
| 1567 | return rc; |
| 1568 | |
| 1569 | if (hdr->q1000 != 1150) |
| 1570 | return -1715; |
| 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1576 | "10" |
| 1577 | */ |
| 1578 | static int hdr_test_content_length(pjsip_hdr *h) |
| 1579 | { |
| 1580 | pjsip_clen_hdr *hdr = (pjsip_clen_hdr*)h; |
| 1581 | |
| 1582 | if (h->type != PJSIP_H_CONTENT_LENGTH) |
| 1583 | return -1810; |
| 1584 | |
| 1585 | if (hdr->len != 10) |
| 1586 | return -1820; |
| 1587 | |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
| 1591 | /* |
| 1592 | "application/sdp" GENERIC_PARAM, |
| 1593 | */ |
| 1594 | static int hdr_test_content_type(pjsip_hdr *h) |
| 1595 | { |
| 1596 | pjsip_ctype_hdr *hdr = (pjsip_ctype_hdr*)h; |
Benny Prijono | 1e5a08b | 2010-08-01 09:24:58 +0000 | [diff] [blame] | 1597 | const pjsip_param *prm; |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1598 | |
| 1599 | if (h->type != PJSIP_H_CONTENT_TYPE) |
| 1600 | return -1910; |
| 1601 | |
| 1602 | if (pj_strcmp2(&hdr->media.type, "application")) |
| 1603 | return -1920; |
| 1604 | |
| 1605 | if (pj_strcmp2(&hdr->media.subtype, "sdp")) |
| 1606 | return -1930; |
| 1607 | |
| 1608 | /* Currently, if the media parameter contains escaped characters, |
| 1609 | * pjsip will print the parameter unescaped. |
| 1610 | */ |
Benny Prijono | 1e5a08b | 2010-08-01 09:24:58 +0000 | [diff] [blame] | 1611 | prm = hdr->media.param.next; |
| 1612 | if (prm == &hdr->media.param) return -1940; |
| 1613 | if (pj_strcmp2(&prm->name, "p0")) return -1941; |
| 1614 | if (pj_strcmp2(&prm->value, "a")) return -1942; |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1615 | |
Benny Prijono | 1e5a08b | 2010-08-01 09:24:58 +0000 | [diff] [blame] | 1616 | prm = prm->next; |
| 1617 | if (prm == &hdr->media.param) return -1950; |
| 1618 | if (pj_strcmp2(&prm->name, "p1")) { PJ_LOG(3,("", "%.*s", (int)prm->name.slen, prm->name.ptr)); return -1951; } |
| 1619 | if (pj_strcmp2(&prm->value, "\"ab:;cd\"")) { PJ_LOG(3,("", "%.*s", (int)prm->value.slen, prm->value.ptr)); return -1952; } |
| 1620 | |
| 1621 | prm = prm->next; |
| 1622 | if (prm == &hdr->media.param) return -1960; |
| 1623 | if (pj_strcmp2(&prm->name, "p2")) return -1961; |
| 1624 | if (pj_strcmp2(&prm->value, "ab:cd")) return -1962; |
| 1625 | |
| 1626 | prm = prm->next; |
| 1627 | if (prm == &hdr->media.param) return -1970; |
| 1628 | if (pj_strcmp2(&prm->name, "p3")) return -1971; |
| 1629 | if (pj_strcmp2(&prm->value, "")) return -1972; |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1630 | |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
| 1634 | /* |
| 1635 | NAME_ADDR GENERIC_PARAM, |
| 1636 | */ |
| 1637 | static int hdr_test_from(pjsip_hdr *h) |
| 1638 | { |
| 1639 | pjsip_from_hdr *hdr = (pjsip_from_hdr*)h; |
| 1640 | int rc; |
| 1641 | |
| 1642 | if (h->type != PJSIP_H_FROM) |
| 1643 | return -2010; |
| 1644 | |
| 1645 | rc = nameaddr_test(hdr->uri); |
| 1646 | if (rc != 0) |
| 1647 | return rc; |
| 1648 | |
| 1649 | rc = generic_param_test(&hdr->other_param); |
| 1650 | if (rc != 0) |
| 1651 | return rc; |
| 1652 | |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | /* |
| 1657 | "Digest realm=\"realm\", domain=\"sip:domain\", nonce=\"nonce\", " \ |
| 1658 | "opaque=\"opaque\", stale=true, algorithm=MD5, qop=\"auth\"", |
| 1659 | */ |
| 1660 | static int hdr_test_proxy_authenticate(pjsip_hdr *h) |
| 1661 | { |
| 1662 | pjsip_proxy_authenticate_hdr *hdr = (pjsip_proxy_authenticate_hdr*)h; |
| 1663 | |
| 1664 | if (h->type != PJSIP_H_PROXY_AUTHENTICATE) |
| 1665 | return -2110; |
| 1666 | |
| 1667 | if (pj_strcmp2(&hdr->scheme, "Digest")) |
| 1668 | return -2120; |
| 1669 | |
| 1670 | if (pj_strcmp2(&hdr->challenge.digest.realm, "realm")) |
| 1671 | return -2130; |
| 1672 | |
| 1673 | if (pj_strcmp2(&hdr->challenge.digest.domain, "sip:domain")) |
| 1674 | return -2140; |
| 1675 | |
| 1676 | if (pj_strcmp2(&hdr->challenge.digest.nonce, "nonce")) |
| 1677 | return -2150; |
| 1678 | |
| 1679 | if (pj_strcmp2(&hdr->challenge.digest.opaque, "opaque")) |
| 1680 | return -2160; |
| 1681 | |
| 1682 | if (hdr->challenge.digest.stale != 1) |
| 1683 | return -2170; |
| 1684 | |
| 1685 | if (pj_strcmp2(&hdr->challenge.digest.algorithm, "MD5")) |
| 1686 | return -2180; |
| 1687 | |
| 1688 | if (pj_strcmp2(&hdr->challenge.digest.qop, "auth")) |
| 1689 | return -2190; |
| 1690 | |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | /* |
| 1695 | NAME_ADDR GENERIC_PARAM, |
| 1696 | */ |
| 1697 | static int hdr_test_record_route(pjsip_hdr *h) |
| 1698 | { |
| 1699 | pjsip_rr_hdr *hdr = (pjsip_rr_hdr*)h; |
| 1700 | int rc; |
| 1701 | |
| 1702 | if (h->type != PJSIP_H_RECORD_ROUTE) |
| 1703 | return -2210; |
| 1704 | |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1705 | rc = nameaddr_test(&hdr->name_addr); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1706 | if (rc != 0) |
| 1707 | return rc; |
| 1708 | |
| 1709 | rc = generic_param_test(&hdr->other_param); |
| 1710 | if (rc != 0) |
| 1711 | return rc; |
| 1712 | |
| 1713 | return 0; |
| 1714 | |
| 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | " \r\n" |
| 1719 | */ |
| 1720 | static int hdr_test_supported(pjsip_hdr *h) |
| 1721 | { |
| 1722 | pjsip_supported_hdr *hdr = (pjsip_supported_hdr*)h; |
| 1723 | |
| 1724 | if (h->type != PJSIP_H_SUPPORTED) |
| 1725 | return -2310; |
| 1726 | |
| 1727 | if (hdr->count != 0) |
| 1728 | return -2320; |
| 1729 | |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
| 1733 | /* |
| 1734 | NAME_ADDR GENERIC_PARAM, |
| 1735 | */ |
| 1736 | static int hdr_test_to(pjsip_hdr *h) |
| 1737 | { |
| 1738 | pjsip_to_hdr *hdr = (pjsip_to_hdr*)h; |
| 1739 | int rc; |
| 1740 | |
| 1741 | if (h->type != PJSIP_H_TO) |
| 1742 | return -2410; |
| 1743 | |
| 1744 | rc = nameaddr_test(hdr->uri); |
| 1745 | if (rc != 0) |
| 1746 | return rc; |
| 1747 | |
| 1748 | rc = generic_param_test(&hdr->other_param); |
| 1749 | if (rc != 0) |
| 1750 | return rc; |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | "SIP/2.0 host" GENERIC_PARAM |
| 1757 | */ |
| 1758 | static int hdr_test_via(pjsip_hdr *h) |
| 1759 | { |
| 1760 | pjsip_via_hdr *hdr = (pjsip_via_hdr*)h; |
| 1761 | int rc; |
| 1762 | |
| 1763 | if (h->type != PJSIP_H_VIA) |
| 1764 | return -2510; |
| 1765 | |
| 1766 | if (pj_strcmp2(&hdr->transport, "XYZ")) |
| 1767 | return -2515; |
| 1768 | |
| 1769 | if (pj_strcmp2(&hdr->sent_by.host, "host")) |
| 1770 | return -2520; |
| 1771 | |
| 1772 | if (hdr->sent_by.port != 0) |
| 1773 | return -2530; |
| 1774 | |
| 1775 | rc = generic_param_test(&hdr->other_param); |
| 1776 | if (rc != 0) |
| 1777 | return rc; |
| 1778 | |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
| 1782 | |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 1783 | /* |
| 1784 | "SIP/2.0/UDP [::1]" |
| 1785 | */ |
| 1786 | static int hdr_test_via_ipv6_1(pjsip_hdr *h) |
| 1787 | { |
| 1788 | pjsip_via_hdr *hdr = (pjsip_via_hdr*)h; |
| 1789 | |
| 1790 | if (h->type != PJSIP_H_VIA) |
| 1791 | return -2610; |
| 1792 | |
| 1793 | if (pj_strcmp2(&hdr->transport, "UDP")) |
| 1794 | return -2615; |
| 1795 | |
| 1796 | if (pj_strcmp2(&hdr->sent_by.host, "::1")) |
| 1797 | return -2620; |
| 1798 | |
| 1799 | if (hdr->sent_by.port != 0) |
| 1800 | return -2630; |
| 1801 | |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
| 1805 | /* "SIP/2.0/UDP [::1]:5061" */ |
| 1806 | static int hdr_test_via_ipv6_2(pjsip_hdr *h) |
| 1807 | { |
| 1808 | pjsip_via_hdr *hdr = (pjsip_via_hdr*)h; |
| 1809 | |
| 1810 | if (h->type != PJSIP_H_VIA) |
| 1811 | return -2710; |
| 1812 | |
| 1813 | if (pj_strcmp2(&hdr->transport, "UDP")) |
| 1814 | return -2715; |
| 1815 | |
| 1816 | if (pj_strcmp2(&hdr->sent_by.host, "::1")) |
| 1817 | return -2720; |
| 1818 | |
| 1819 | if (hdr->sent_by.port != 5061) |
| 1820 | return -2730; |
| 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | /* "SIP/2.0/UDP [::1];rport=5061;received=::2" */ |
| 1826 | static int hdr_test_via_ipv6_3(pjsip_hdr *h) |
| 1827 | { |
| 1828 | pjsip_via_hdr *hdr = (pjsip_via_hdr*)h; |
| 1829 | |
| 1830 | if (h->type != PJSIP_H_VIA) |
| 1831 | return -2810; |
| 1832 | |
| 1833 | if (pj_strcmp2(&hdr->transport, "UDP")) |
| 1834 | return -2815; |
| 1835 | |
| 1836 | if (pj_strcmp2(&hdr->sent_by.host, "::1")) |
| 1837 | return -2820; |
| 1838 | |
| 1839 | if (hdr->sent_by.port != 0) |
| 1840 | return -2830; |
| 1841 | |
| 1842 | if (pj_strcmp2(&hdr->recvd_param, "::2")) |
| 1843 | return -2840; |
| 1844 | |
| 1845 | if (hdr->rport_param != 5061) |
| 1846 | return -2850; |
| 1847 | |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
Benny Prijono | 054c5df | 2008-05-15 10:07:36 +0000 | [diff] [blame] | 1851 | /* "10(Already Pending Register)" */ |
| 1852 | static int hdr_test_retry_after1(pjsip_hdr *h) |
| 1853 | { |
| 1854 | pjsip_retry_after_hdr *hdr = (pjsip_retry_after_hdr*)h; |
| 1855 | |
| 1856 | if (h->type != PJSIP_H_RETRY_AFTER) |
| 1857 | return -2910; |
| 1858 | |
| 1859 | if (hdr->ivalue != 10) |
| 1860 | return -2920; |
| 1861 | |
| 1862 | if (pj_strcmp2(&hdr->comment, "Already Pending Register")) |
| 1863 | return -2930; |
| 1864 | |
| 1865 | return 0; |
| 1866 | } |
| 1867 | |
Benny Prijono | 3c97d9b | 2008-09-21 22:01:46 +0000 | [diff] [blame] | 1868 | /* Subject: \xC0\x81 */ |
| 1869 | static int hdr_test_subject_utf(pjsip_hdr *h) |
| 1870 | { |
| 1871 | pjsip_subject_hdr *hdr = (pjsip_subject_hdr*)h; |
| 1872 | |
| 1873 | if (pj_strcmp2(&h->name, "Subject")) |
| 1874 | return -2950; |
| 1875 | |
| 1876 | if (pj_strcmp2(&hdr->hvalue, "\xC0\x81")) |
| 1877 | return -2960; |
| 1878 | |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1882 | static int hdr_test(void) |
| 1883 | { |
| 1884 | unsigned i; |
| 1885 | |
| 1886 | PJ_LOG(3,(THIS_FILE, " testing header parsing..")); |
| 1887 | |
| 1888 | for (i=0; i<PJ_ARRAY_SIZE(hdr_test_data); ++i) { |
| 1889 | struct hdr_test_t *test = &hdr_test_data[i]; |
| 1890 | pj_str_t hname; |
| 1891 | int len, parsed_len; |
| 1892 | pj_pool_t *pool; |
| 1893 | pjsip_hdr *parsed_hdr1=NULL, *parsed_hdr2=NULL; |
| 1894 | char *input, *output; |
Benny Prijono | d661f57 | 2009-01-28 14:17:14 +0000 | [diff] [blame] | 1895 | #if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0 |
| 1896 | static char hcontent[1024]; |
| 1897 | #else |
| 1898 | char *hcontent; |
| 1899 | #endif |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1900 | int rc; |
| 1901 | |
| 1902 | pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE); |
| 1903 | |
| 1904 | /* Parse the header */ |
| 1905 | hname = pj_str(test->hname); |
| 1906 | len = strlen(test->hcontent); |
Benny Prijono | d661f57 | 2009-01-28 14:17:14 +0000 | [diff] [blame] | 1907 | #if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0 |
| 1908 | PJ_ASSERT_RETURN(len < sizeof(hcontent), PJSIP_EMSGTOOLONG); |
| 1909 | strcpy(hcontent, test->hcontent); |
| 1910 | #else |
| 1911 | hcontent = test->hcontent; |
| 1912 | #endif |
| 1913 | |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 1914 | parsed_hdr1 = (pjsip_hdr*) pjsip_parse_hdr(pool, &hname, |
Benny Prijono | d661f57 | 2009-01-28 14:17:14 +0000 | [diff] [blame] | 1915 | hcontent, len, |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 1916 | &parsed_len); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1917 | if (parsed_hdr1 == NULL) { |
| 1918 | if (test->flags & HDR_FLAG_PARSE_FAIL) { |
| 1919 | pj_pool_release(pool); |
| 1920 | continue; |
| 1921 | } |
| 1922 | PJ_LOG(3,(THIS_FILE, " error parsing header %s: %s", test->hname, test->hcontent)); |
| 1923 | return -500; |
| 1924 | } |
| 1925 | |
| 1926 | /* Test the parsing result */ |
| 1927 | if (test->test && (rc=test->test(parsed_hdr1)) != 0) { |
| 1928 | PJ_LOG(3,(THIS_FILE, " validation failed for header %s: %s", test->hname, test->hcontent)); |
| 1929 | PJ_LOG(3,(THIS_FILE, " error code is %d", rc)); |
| 1930 | return -502; |
| 1931 | } |
| 1932 | |
Benny Prijono | 64898b5 | 2007-05-01 06:36:15 +0000 | [diff] [blame] | 1933 | #if 1 |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1934 | /* Parse with hshortname, if present */ |
| 1935 | if (test->hshort_name) { |
| 1936 | hname = pj_str(test->hshort_name); |
| 1937 | len = strlen(test->hcontent); |
Benny Prijono | d661f57 | 2009-01-28 14:17:14 +0000 | [diff] [blame] | 1938 | #if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0 |
| 1939 | PJ_ASSERT_RETURN(len < sizeof(hcontent), PJSIP_EMSGTOOLONG); |
| 1940 | strcpy(hcontent, test->hcontent); |
| 1941 | #else |
| 1942 | hcontent = test->hcontent; |
| 1943 | #endif |
| 1944 | |
| 1945 | parsed_hdr2 = (pjsip_hdr*) pjsip_parse_hdr(pool, &hname, hcontent, len, &parsed_len); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1946 | if (parsed_hdr2 == NULL) { |
| 1947 | PJ_LOG(3,(THIS_FILE, " error parsing header %s: %s", test->hshort_name, test->hcontent)); |
| 1948 | return -510; |
| 1949 | } |
| 1950 | } |
| 1951 | #endif |
| 1952 | |
| 1953 | if (test->flags & HDR_FLAG_DONT_PRINT) { |
| 1954 | pj_pool_release(pool); |
| 1955 | continue; |
| 1956 | } |
| 1957 | |
| 1958 | /* Print the original header */ |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 1959 | input = (char*) pj_pool_alloc(pool, 1024); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1960 | len = pj_ansi_snprintf(input, 1024, "%s: %s", test->hname, test->hcontent); |
| 1961 | if (len < 1 || len >= 1024) |
| 1962 | return -520; |
| 1963 | |
| 1964 | /* Print the parsed header*/ |
Benny Prijono | a1e6968 | 2007-05-11 15:14:34 +0000 | [diff] [blame] | 1965 | output = (char*) pj_pool_alloc(pool, 1024); |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1966 | len = pjsip_hdr_print_on(parsed_hdr1, output, 1024); |
Benny Prijono | 329d638 | 2009-05-29 13:04:03 +0000 | [diff] [blame] | 1967 | if (len < 0 || len >= 1024) { |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 1968 | PJ_LOG(3,(THIS_FILE, " header too long: %s: %s", test->hname, test->hcontent)); |
| 1969 | return -530; |
| 1970 | } |
| 1971 | output[len] = 0; |
| 1972 | |
| 1973 | if (strcmp(input, output) != 0) { |
| 1974 | PJ_LOG(3,(THIS_FILE, " header character by character comparison failed.")); |
| 1975 | PJ_LOG(3,(THIS_FILE, " original header=|%s|", input)); |
| 1976 | PJ_LOG(3,(THIS_FILE, " parsed header =|%s|", output)); |
| 1977 | return -540; |
| 1978 | } |
| 1979 | |
| 1980 | pj_pool_release(pool); |
| 1981 | } |
| 1982 | |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | /*****************************************************************************/ |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 1988 | |
| 1989 | int msg_test(void) |
| 1990 | { |
Benny Prijono | d4791af | 2007-06-19 08:46:02 +0000 | [diff] [blame] | 1991 | enum { COUNT = 1, DETECT=0, PARSE=1, PRINT=2 }; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 1992 | struct { |
| 1993 | unsigned detect; |
| 1994 | unsigned parse; |
| 1995 | unsigned print; |
| 1996 | } run[COUNT]; |
| 1997 | unsigned i, max, avg_len; |
| 1998 | char desc[250]; |
| 1999 | pj_status_t status; |
| 2000 | |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 2001 | status = hdr_test(); |
| 2002 | if (status != 0) |
| 2003 | return status; |
| 2004 | |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 2005 | status = simple_test(); |
| 2006 | if (status != PJ_SUCCESS) |
| 2007 | return status; |
| 2008 | |
| 2009 | #if INCLUDE_BENCHMARKS |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 2010 | for (i=0; i<COUNT; ++i) { |
| 2011 | PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)..", i+1, COUNT)); |
| 2012 | status = msg_benchmark(&run[i].detect, &run[i].parse, &run[i].print); |
| 2013 | if (status != PJ_SUCCESS) |
| 2014 | return status; |
| 2015 | } |
| 2016 | |
| 2017 | /* Calculate average message length */ |
| 2018 | for (i=0, avg_len=0; i<PJ_ARRAY_SIZE(test_array); ++i) { |
| 2019 | avg_len += test_array[i].len; |
| 2020 | } |
| 2021 | avg_len /= PJ_ARRAY_SIZE(test_array); |
| 2022 | |
| 2023 | |
| 2024 | /* Print maximum detect/sec */ |
| 2025 | for (i=0, max=0; i<COUNT; ++i) |
| 2026 | if (run[i].detect > max) max = run[i].detect; |
| 2027 | |
| 2028 | PJ_LOG(3,("", " Maximum message detection/sec=%u", max)); |
| 2029 | |
| 2030 | pj_ansi_sprintf(desc, "Number of SIP messages " |
| 2031 | "can be pre-parse by <tt>pjsip_find_msg()</tt> " |
| 2032 | "per second (tested with %d message sets with " |
| 2033 | "average message length of " |
Benny Prijono | 7db431e | 2006-07-23 14:38:49 +0000 | [diff] [blame] | 2034 | "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 2035 | report_ival("msg-detect-per-sec", max, "msg/sec", desc); |
| 2036 | |
| 2037 | /* Print maximum parse/sec */ |
| 2038 | for (i=0, max=0; i<COUNT; ++i) |
| 2039 | if (run[i].parse > max) max = run[i].parse; |
| 2040 | |
| 2041 | PJ_LOG(3,("", " Maximum message parsing/sec=%u", max)); |
| 2042 | |
| 2043 | pj_ansi_sprintf(desc, "Number of SIP messages " |
| 2044 | "can be <b>parsed</b> by <tt>pjsip_parse_msg()</tt> " |
| 2045 | "per second (tested with %d message sets with " |
| 2046 | "average message length of " |
Benny Prijono | 7db431e | 2006-07-23 14:38:49 +0000 | [diff] [blame] | 2047 | "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 2048 | report_ival("msg-parse-per-sec", max, "msg/sec", desc); |
| 2049 | |
| 2050 | /* Msg parsing bandwidth */ |
| 2051 | report_ival("msg-parse-bandwidth-mb", avg_len*max/1000000, "MB/sec", |
| 2052 | "Message parsing bandwidth in megabytes (number of megabytes" |
| 2053 | " worth of SIP messages that can be parsed per second). " |
| 2054 | "The value is derived from msg-parse-per-sec above."); |
| 2055 | |
| 2056 | |
| 2057 | /* Print maximum print/sec */ |
| 2058 | for (i=0, max=0; i<COUNT; ++i) |
| 2059 | if (run[i].print > max) max = run[i].print; |
| 2060 | |
| 2061 | PJ_LOG(3,("", " Maximum message print/sec=%u", max)); |
| 2062 | |
| 2063 | pj_ansi_sprintf(desc, "Number of SIP messages " |
| 2064 | "can be <b>printed</b> by <tt>pjsip_msg_print()</tt>" |
| 2065 | " per second (tested with %d message sets with " |
| 2066 | "average message length of " |
Benny Prijono | 7db431e | 2006-07-23 14:38:49 +0000 | [diff] [blame] | 2067 | "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 2068 | |
| 2069 | report_ival("msg-print-per-sec", max, "msg/sec", desc); |
| 2070 | |
| 2071 | /* Msg print bandwidth */ |
| 2072 | report_ival("msg-printed-bandwidth-mb", avg_len*max/1000000, "MB/sec", |
| 2073 | "Message print bandwidth in megabytes (total size of " |
| 2074 | "SIP messages printed per second). " |
| 2075 | "The value is derived from msg-print-per-sec above."); |
| 2076 | |
Benny Prijono | d0bd498 | 2007-12-02 15:40:52 +0000 | [diff] [blame] | 2077 | #endif /* INCLUDE_BENCHMARKS */ |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 2078 | |
| 2079 | return PJ_SUCCESS; |
| 2080 | } |
| 2081 | |
Benny Prijono | 8aea0d9 | 2007-04-29 06:23:11 +0000 | [diff] [blame] | 2082 | |
| 2083 | |
| 2084 | |