blob: a7ce838b5d1fd2e85beeea12b671ce49d16f4fe9 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00005 *
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 Prijono40f2f642006-01-30 18:40:05 +000021#include <pjsip.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000022#include <pjlib.h>
23
Benny Prijono3818c932005-11-22 01:06:33 +000024#define POOL_SIZE 8000
Benny Prijonoe93e2872006-06-28 16:46:49 +000025#if defined(PJ_DEBUG) && PJ_DEBUG!=0
26# define LOOP 10000
27#else
28# define LOOP 100000
29#endif
Benny Prijono3818c932005-11-22 01:06:33 +000030#define AVERAGE_MSG_LEN 800
Benny Prijono85598d92006-01-07 18:44:25 +000031#define THIS_FILE "msg_test.c"
Benny Prijono3818c932005-11-22 01:06:33 +000032
Benny Prijono5dcb38d2005-11-21 01:55:47 +000033static pjsip_msg *create_msg0(pj_pool_t *pool);
Benny Prijono3818c932005-11-22 01:06:33 +000034static 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 Prijono5dcb38d2005-11-21 01:55:47 +000043struct test_msg
44{
45 char msg[1024];
46 pjsip_msg *(*creator)(pj_pool_t *pool);
47 pj_size_t len;
Benny Prijono3818c932005-11-22 01:06:33 +000048 int expected_status;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000049} test_array[] =
50{
Benny Prijono3818c932005-11-22 01:06:33 +000051{
52 /* 'Normal' message with all headers. */
53 "INVITE sip:user@foo SIP/2.0\n"
Benny Prijonob6eab2c2006-07-03 22:08:47 +000054 "from: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r"
Benny Prijono3818c932005-11-22 01:06:33 +000055 "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 Prijonofa73e3e2006-01-05 23:35:46 +000064 "Record-Route: <sip:server10.biloxi.com>,\r\n" /* multiple routes+folding*/
Benny Prijono3818c932005-11-22 01:06:33 +000065 " <sip:bigbox3.site3.atlanta.com;lr>\n"
Benny Prijono69f73fe2007-03-19 10:27:13 +000066 "v: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n"
Benny Prijonofa73e3e2006-01-05 23:35:46 +000067 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n" /* folding. */
Benny Prijono3818c932005-11-22 01:06:33 +000068 " ;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 Prijonofa73e3e2006-01-05 23:35:46 +000072 "X-Header: \r\n" /* empty header */
73 "P-Associated-URI:\r\n" /* empty header without space */
Benny Prijono3818c932005-11-22 01:06:33 +000074 "\r\n",
75 &create_msg0,
Benny Prijono713587c2009-03-18 18:24:40 +000076 0,
Benny Prijono3818c932005-11-22 01:06:33 +000077 PJ_SUCCESS
78},
79{
80 /* Typical response message. */
81 "SIP/2.0 200 OK\r\n"
Benny Prijono4cf8d1c2007-04-28 15:37:49 +000082 "Via: SIP/2.0/SCTP server10.biloxi.com;branch=z9hG4bKnashds8;rport;received=192.0.2.1\r\n"
Benny Prijono3818c932005-11-22 01:06:33 +000083 "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 Prijono713587c2009-03-18 18:24:40 +0000104 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 Prijono3818c932005-11-22 01:06:33 +0000234 PJ_SUCCESS
235}
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000236};
237
Benny Prijonoe93e2872006-06-28 16:46:49 +0000238static 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 Prijono5dcb38d2005-11-21 01:55:47 +0000244
245static pj_status_t test_entry( pj_pool_t *pool, struct test_msg *entry )
246{
Benny Prijonoe960bb52007-01-21 17:53:39 +0000247 pjsip_msg *parsed_msg, *ref_msg = NULL;
Benny Prijonocec5f4a2005-11-22 23:51:50 +0000248 static pjsip_msg *print_msg;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000249 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 Prijono3818c932005-11-22 01:06:33 +0000254 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 Prijono5dcb38d2005-11-21 01:55:47 +0000258 enum { BUFLEN = 512 };
Benny Prijono3818c932005-11-22 01:06:33 +0000259
Benny Prijono713587c2009-03-18 18:24:40 +0000260 if (entry->len==0)
261 entry->len = pj_ansi_strlen(entry->msg);
Benny Prijono3818c932005-11-22 01:06:33 +0000262
Benny Prijonoe93e2872006-06-28 16:46:49 +0000263 if (var.flag & FLAG_PARSE_ONLY)
Benny Prijono3818c932005-11-22 01:06:33 +0000264 goto parse_msg;
Benny Prijonocec5f4a2005-11-22 23:51:50 +0000265
Benny Prijonoe93e2872006-06-28 16:46:49 +0000266 if (var.flag & FLAG_PRINT_ONLY) {
Benny Prijonocec5f4a2005-11-22 23:51:50 +0000267 if (print_msg == NULL)
268 print_msg = entry->creator(pool);
Benny Prijono3818c932005-11-22 01:06:33 +0000269 goto print_msg;
Benny Prijonocec5f4a2005-11-22 23:51:50 +0000270 }
Benny Prijono3818c932005-11-22 01:06:33 +0000271
272 /* Detect message. */
Benny Prijonoe93e2872006-06-28 16:46:49 +0000273 var.detect_len = var.detect_len + entry->len;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000274 pj_get_timestamp(&t1);
Benny Prijono3818c932005-11-22 01:06:33 +0000275 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 Prijono85598d92006-01-07 18:44:25 +0000285 PJ_LOG(3,(THIS_FILE, " error: size mismatch"));
Benny Prijono3818c932005-11-22 01:06:33 +0000286 return -6;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000287 }
288 pj_get_timestamp(&t2);
Benny Prijono3818c932005-11-22 01:06:33 +0000289 pj_sub_timestamp(&t2, &t1);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000290 pj_add_timestamp(&var.detect_time, &t2);
Benny Prijono3818c932005-11-22 01:06:33 +0000291
Benny Prijonoe93e2872006-06-28 16:46:49 +0000292 if (var.flag & FLAG_DETECT_ONLY)
Benny Prijono3818c932005-11-22 01:06:33 +0000293 return PJ_SUCCESS;
294
295 /* Parse message. */
296parse_msg:
Benny Prijonoe93e2872006-06-28 16:46:49 +0000297 var.parse_len = var.parse_len + entry->len;
Benny Prijono3818c932005-11-22 01:06:33 +0000298 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 Prijono85598d92006-01-07 18:44:25 +0000305 PJ_LOG(3,(THIS_FILE, " Syntax error in line %d col %d",
Benny Prijono3818c932005-11-22 01:06:33 +0000306 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 Prijonoe93e2872006-06-28 16:46:49 +0000313 pj_add_timestamp(&var.parse_time, &t2);
Benny Prijono3818c932005-11-22 01:06:33 +0000314
Benny Prijono713587c2009-03-18 18:24:40 +0000315 if ((var.flag & FLAG_PARSE_ONLY) || entry->creator==NULL)
Benny Prijono3818c932005-11-22 01:06:33 +0000316 return PJ_SUCCESS;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000317
318 /* Create reference message. */
319 ref_msg = entry->creator(pool);
320
321 /* Create buffer for comparison. */
Benny Prijonoa1e69682007-05-11 15:14:34 +0000322 str1.ptr = (char*)pj_pool_alloc(pool, BUFLEN);
323 str2.ptr = (char*)pj_pool_alloc(pool, BUFLEN);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000324
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 Prijono3818c932005-11-22 01:06:33 +0000336 if (pjsip_method_cmp(m1, m2) != 0) {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000337 status = -30;
338 goto on_return;
339 }
Benny Prijono3818c932005-11-22 01:06:33 +0000340 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 Prijono5dcb38d2005-11-21 01:55:47 +0000348 } else {
Benny Prijono3818c932005-11-22 01:06:33 +0000349 if (parsed_msg->line.status.code != ref_msg->line.status.code) {
Benny Prijono85598d92006-01-07 18:44:25 +0000350 PJ_LOG(3,(THIS_FILE, " error: status code mismatch"));
Benny Prijono3818c932005-11-22 01:06:33 +0000351 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 Prijono85598d92006-01-07 18:44:25 +0000357 PJ_LOG(3,(THIS_FILE, " error: status text mismatch"));
Benny Prijono3818c932005-11-22 01:06:33 +0000358 status = -33;
359 goto on_return;
360 }
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000361 }
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 Prijono329d6382009-05-29 13:04:03 +0000368 len = pjsip_hdr_print_on(hdr1, str1.ptr, BUFLEN);
369 if (len < 0) {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000370 status = -40;
371 goto on_return;
372 }
Benny Prijono3818c932005-11-22 01:06:33 +0000373 str1.ptr[len] = '\0';
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000374 str1.slen = len;
375
Benny Prijono329d6382009-05-29 13:04:03 +0000376 len = pjsip_hdr_print_on(hdr2, str2.ptr, BUFLEN);
377 if (len < 0) {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000378 status = -50;
379 goto on_return;
380 }
Benny Prijono3818c932005-11-22 01:06:33 +0000381 str2.ptr[len] = '\0';
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000382 str2.slen = len;
383
384 if (pj_strcmp(&str1, &str2) != 0) {
385 status = -60;
Benny Prijono85598d92006-01-07 18:44:25 +0000386 PJ_LOG(3,(THIS_FILE, " error: header string mismatch:\n"
Benny Prijono3818c932005-11-22 01:06:33 +0000387 " h1='%s'\n"
388 " h2='%s'\n",
389 str1.ptr, str2.ptr));
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000390 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 Prijono3818c932005-11-22 01:06:33 +0000402 /* 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 Prijono5dcb38d2005-11-21 01:55:47 +0000408 status = -80;
409 goto on_return;
410 }
Benny Prijono3818c932005-11-22 01:06:33 +0000411
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 Prijono5dcb38d2005-11-21 01:55:47 +0000415 status = -90;
416 goto on_return;
417 }
Benny Prijono3818c932005-11-22 01:06:33 +0000418 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. */
447print_msg:
Benny Prijonoe93e2872006-06-28 16:46:49 +0000448 var.print_len = var.print_len + entry->len;
Benny Prijono3818c932005-11-22 01:06:33 +0000449 pj_get_timestamp(&t1);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000450 if (var.flag && FLAG_PRINT_ONLY)
Benny Prijonocec5f4a2005-11-22 23:51:50 +0000451 ref_msg = print_msg;
452 len = pjsip_msg_print(ref_msg, msgbuf1, PJSIP_MAX_PKT_LEN);
Benny Prijono3818c932005-11-22 01:06:33 +0000453 if (len < 1) {
454 status = -150;
455 goto on_return;
456 }
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000457 pj_get_timestamp(&t2);
Benny Prijono3818c932005-11-22 01:06:33 +0000458 pj_sub_timestamp(&t2, &t1);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000459 pj_add_timestamp(&var.print_time, &t2);
Benny Prijono3818c932005-11-22 01:06:33 +0000460
461
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000462 status = PJ_SUCCESS;
463
464on_return:
465 return status;
466}
467
468
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000469static pjsip_msg *create_msg0(pj_pool_t *pool)
470{
471
472 pjsip_msg *msg;
473 pjsip_name_addr *name_addr;
Benny Prijono0c2bc612006-01-10 13:31:40 +0000474 pjsip_sip_uri *url;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000475 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 Prijono1e5a08b2010-08-01 09:24:58 +0000484 pjsip_param *prm;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000485 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 Prijono40f2f642006-01-30 18:40:05 +0000491 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000492 msg->line.req.uri = (pjsip_uri*)url;
493 pj_strdup2(pool, &url->user, "user");
494 pj_strdup2(pool, &url->host, "foo");
495
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000496 /* "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r" */
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000497 fromto = pjsip_from_hdr_create(pool);
498 pjsip_msg_add_hdr(msg, (pjsip_hdr*)fromto);
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000499 pj_strdup2(pool, &fromto->tag, "123457890123456");
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000500 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 Prijono40f2f642006-01-30 18:40:05 +0000503 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000504 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 Prijono40f2f642006-01-30 18:40:05 +0000514 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000515 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 Prijono40f2f642006-01-30 18:40:05 +0000542 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000543 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 Prijono3818c932005-11-22 01:06:33 +0000551 name_addr = pjsip_name_addr_create(pool);
552 contact->uri = (pjsip_uri*)name_addr;
Benny Prijono40f2f642006-01-30 18:40:05 +0000553 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono3818c932005-11-22 01:06:33 +0000554 name_addr->uri = (pjsip_uri*)url;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000555 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 Prijono3818c932005-11-22 01:06:33 +0000561 name_addr = pjsip_name_addr_create(pool);
562 contact->uri = (pjsip_uri*)name_addr;
Benny Prijono40f2f642006-01-30 18:40:05 +0000563 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono3818c932005-11-22 01:06:33 +0000564 name_addr->uri = (pjsip_uri*)url;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000565 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 Prijono1e5a08b2010-08-01 09:24:58 +0000573 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 Prijono5dcb38d2005-11-21 01:55:47 +0000577
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 Prijono40f2f642006-01-30 18:40:05 +0000581 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000582 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 Prijono40f2f642006-01-30 18:40:05 +0000589 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000590 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 Prijono40f2f642006-01-30 18:40:05 +0000597 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000598 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 Prijono40f2f642006-01-30 18:40:05 +0000605 url = pjsip_sip_uri_create(pool, 0);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000606 routing->name_addr.uri = (pjsip_uri*)url;
607 pj_strdup2(pool, &url->host, "bigbox3.site3.atlanta.com");
608 url->lr_param = 1;
609
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000610 /* "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n" */
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000611 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 Prijonofa73e3e2006-01-05 23:35:46 +0000615 pj_strdup2(pool, &via->branch_param, "z9hG4bK77ef4c230");
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000616
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 Prijono40f2f642006-01-30 18:40:05 +0000643 generic = pjsip_generic_string_hdr_create(pool, &str, NULL);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000644 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 Prijono40f2f642006-01-30 18:40:05 +0000651 generic = pjsip_generic_string_hdr_create(pool, &str, NULL);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000652 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 Prijono40f2f642006-01-30 18:40:05 +0000660 generic = pjsip_generic_string_hdr_create(pool, &str, NULL);
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000661 pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic);
662 str.ptr = NULL;
663 str.slen = 0;
664 generic->hvalue = str;
665
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000666 /* P-Associated-URI:\r\n */
667 str.ptr = "P-Associated-URI";
668 str.slen = 16;
Benny Prijono40f2f642006-01-30 18:40:05 +0000669 generic = pjsip_generic_string_hdr_create(pool, &str, NULL);
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000670 pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic);
671 str.ptr = NULL;
672 str.slen = 0;
673 generic->hvalue = str;
674
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000675 return msg;
676}
Benny Prijono3818c932005-11-22 01:06:33 +0000677
678static 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 Prijono0c2bc612006-01-10 13:31:40 +0000683 pjsip_sip_uri *url;
Benny Prijono40f2f642006-01-30 18:40:05 +0000684 pjsip_max_fwd_hdr *max_fwd;
Benny Prijono3818c932005-11-22 01:06:33 +0000685 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 Prijono4cf8d1c2007-04-28 15:37:49 +0000699 //"Via: SIP/2.0/SCTP server10.biloxi.com;branch=z9hG4bKnashds8;rport;received=192.0.2.1\r\n"
Benny Prijono3818c932005-11-22 01:06:33 +0000700 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 Prijono40f2f642006-01-30 18:40:05 +0000727 url = pjsip_sip_uri_create(pool, PJ_FALSE);
Benny Prijono3818c932005-11-22 01:06:33 +0000728 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 Prijono40f2f642006-01-30 18:40:05 +0000734 url = pjsip_sip_uri_create(pool, PJ_FALSE);
Benny Prijono3818c932005-11-22 01:06:33 +0000735 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 Prijono40f2f642006-01-30 18:40:05 +0000740 max_fwd = pjsip_max_fwd_hdr_create(pool, 70);
Benny Prijono3818c932005-11-22 01:06:33 +0000741 pjsip_msg_add_hdr(msg, (pjsip_hdr*)max_fwd);
Benny Prijono3818c932005-11-22 01:06:33 +0000742
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 Prijono40f2f642006-01-30 18:40:05 +0000749 url = pjsip_sip_uri_create(pool, PJ_FALSE);
Benny Prijono3818c932005-11-22 01:06:33 +0000750 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 Prijono40f2f642006-01-30 18:40:05 +0000761 url = pjsip_sip_uri_create(pool, PJ_FALSE);
Benny Prijono3818c932005-11-22 01:06:33 +0000762 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 Prijono40f2f642006-01-30 18:40:05 +0000783 url = pjsip_sip_uri_create(pool, PJ_TRUE);
Benny Prijono3818c932005-11-22 01:06:33 +0000784 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 Prijonoa1e69682007-05-11 15:14:34 +0000800 body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
Benny Prijono3818c932005-11-22 01:06:33 +0000801 msg->body = body;
802 body->content_type.type = pj_str("application");
803 body->content_type.subtype = pj_str("sdp");
Benny Prijonoa1e69682007-05-11 15:14:34 +0000804 body->data = (void*)
Benny Prijono3818c932005-11-22 01:06:33 +0000805 "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 Izzuddin7d1ac292008-09-16 17:02:48 +0000812 body->len = pj_ansi_strlen((const char*) body->data);
Benny Prijono3818c932005-11-22 01:06:33 +0000813 body->print_body = &pjsip_print_text_body;
814
815 return msg;
816}
817
818/*****************************************************************************/
819
Benny Prijonoe93e2872006-06-28 16:46:49 +0000820static pj_status_t simple_test(void)
Benny Prijono3818c932005-11-22 01:06:33 +0000821{
Benny Prijonoc6ff4b82009-05-12 15:55:09 +0000822 char stbuf[] = "SIP/2.0 180 Ringing like it never rings before";
Benny Prijonoe93e2872006-06-28 16:46:49 +0000823 unsigned i;
Benny Prijonoc6ff4b82009-05-12 15:55:09 +0000824 pjsip_status_line st_line;
Benny Prijono3818c932005-11-22 01:06:33 +0000825 pj_status_t status;
Benny Prijono3818c932005-11-22 01:06:33 +0000826
Benny Prijono85598d92006-01-07 18:44:25 +0000827 PJ_LOG(3,(THIS_FILE, " simple test.."));
Benny Prijonoc6ff4b82009-05-12 15:55:09 +0000828
829 status = pjsip_parse_status_line(stbuf, pj_ansi_strlen(stbuf), &st_line);
830 if (status != PJ_SUCCESS)
831 return status;
832
Benny Prijono3818c932005-11-22 01:06:33 +0000833 for (i=0; i<PJ_ARRAY_SIZE(test_array); ++i) {
Benny Prijonoe93e2872006-06-28 16:46:49 +0000834 pj_pool_t *pool;
Benny Prijono3818c932005-11-22 01:06:33 +0000835 pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
836 status = test_entry( pool, &test_array[i] );
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000837 pjsip_endpt_release_pool(endpt, pool);
Benny Prijono3818c932005-11-22 01:06:33 +0000838
839 if (status != PJ_SUCCESS)
840 return status;
841 }
842
Benny Prijonoe93e2872006-06-28 16:46:49 +0000843 return PJ_SUCCESS;
844}
845
846
Benny Prijonod0bd4982007-12-02 15:40:52 +0000847#if INCLUDE_BENCHMARKS
Benny Prijonoe93e2872006-06-28 16:46:49 +0000848static int msg_benchmark(unsigned *p_detect, unsigned *p_parse,
849 unsigned *p_print)
850{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000851 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 Izzuddin2e4f03f2009-04-27 19:18:38 +0000856 pj_status_t status = PJ_SUCCESS;
Benny Prijonoe93e2872006-06-28 16:46:49 +0000857
Benny Prijonoac623b32006-07-03 15:19:31 +0000858 pj_bzero(&var, sizeof(var));
Benny Prijonoe93e2872006-06-28 16:46:49 +0000859 zero.u64 = 0;
860
Benny Prijono3818c932005-11-22 01:06:33 +0000861 for (loop=0; loop<LOOP; ++loop) {
Benny Prijonoa1e69682007-05-11 15:14:34 +0000862 for (i=0; i<(int)PJ_ARRAY_SIZE(test_array); ++i) {
Benny Prijono3818c932005-11-22 01:06:33 +0000863 pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
864 status = test_entry( pool, &test_array[i] );
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000865 pjsip_endpt_release_pool(endpt, pool);
Benny Prijono3818c932005-11-22 01:06:33 +0000866
867 if (status != PJ_SUCCESS)
868 return status;
869 }
870 }
871
Benny Prijonoe93e2872006-06-28 16:46:49 +0000872 kbytes = var.detect_len;
Benny Prijono3818c932005-11-22 01:06:33 +0000873 pj_highprec_mod(kbytes, 1000000);
874 pj_highprec_div(kbytes, 100000);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000875 elapsed = pj_elapsed_time(&zero, &var.detect_time);
876 avg_detect = pj_elapsed_usec(&zero, &var.detect_time);
Benny Prijono3818c932005-11-22 01:06:33 +0000877 pj_highprec_mul(avg_detect, AVERAGE_MSG_LEN);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000878 pj_highprec_div(avg_detect, var.detect_len);
Benny Prijono3818c932005-11-22 01:06:33 +0000879 avg_detect = 1000000 / avg_detect;
880
Benny Prijono85598d92006-01-07 18:44:25 +0000881 PJ_LOG(3,(THIS_FILE,
882 " %u.%u MB detected in %d.%03ds (avg=%d msg detection/sec)",
Benny Prijonoe93e2872006-06-28 16:46:49 +0000883 (unsigned)(var.detect_len/1000000), (unsigned)kbytes,
Benny Prijono85598d92006-01-07 18:44:25 +0000884 elapsed.sec, elapsed.msec,
885 (unsigned)avg_detect));
Benny Prijonoe93e2872006-06-28 16:46:49 +0000886 *p_detect = (unsigned)avg_detect;
Benny Prijono3818c932005-11-22 01:06:33 +0000887
Benny Prijonoe93e2872006-06-28 16:46:49 +0000888 kbytes = var.parse_len;
Benny Prijono3818c932005-11-22 01:06:33 +0000889 pj_highprec_mod(kbytes, 1000000);
890 pj_highprec_div(kbytes, 100000);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000891 elapsed = pj_elapsed_time(&zero, &var.parse_time);
892 avg_parse = pj_elapsed_usec(&zero, &var.parse_time);
Benny Prijono3818c932005-11-22 01:06:33 +0000893 pj_highprec_mul(avg_parse, AVERAGE_MSG_LEN);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000894 pj_highprec_div(avg_parse, var.parse_len);
Benny Prijono3818c932005-11-22 01:06:33 +0000895 avg_parse = 1000000 / avg_parse;
896
Benny Prijono85598d92006-01-07 18:44:25 +0000897 PJ_LOG(3,(THIS_FILE,
898 " %u.%u MB parsed in %d.%03ds (avg=%d msg parsing/sec)",
Benny Prijonoe93e2872006-06-28 16:46:49 +0000899 (unsigned)(var.parse_len/1000000), (unsigned)kbytes,
Benny Prijono85598d92006-01-07 18:44:25 +0000900 elapsed.sec, elapsed.msec,
901 (unsigned)avg_parse));
Benny Prijonoe93e2872006-06-28 16:46:49 +0000902 *p_parse = (unsigned)avg_parse;
Benny Prijono3818c932005-11-22 01:06:33 +0000903
Benny Prijonoe93e2872006-06-28 16:46:49 +0000904 kbytes = var.print_len;
Benny Prijono3818c932005-11-22 01:06:33 +0000905 pj_highprec_mod(kbytes, 1000000);
906 pj_highprec_div(kbytes, 100000);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000907 elapsed = pj_elapsed_time(&zero, &var.print_time);
908 avg_print = pj_elapsed_usec(&zero, &var.print_time);
Benny Prijono3818c932005-11-22 01:06:33 +0000909 pj_highprec_mul(avg_print, AVERAGE_MSG_LEN);
Benny Prijonoe93e2872006-06-28 16:46:49 +0000910 pj_highprec_div(avg_print, var.print_len);
Benny Prijono3818c932005-11-22 01:06:33 +0000911 avg_print = 1000000 / avg_print;
912
Benny Prijono85598d92006-01-07 18:44:25 +0000913 PJ_LOG(3,(THIS_FILE,
914 " %u.%u MB printed in %d.%03ds (avg=%d msg print/sec)",
Benny Prijonoe93e2872006-06-28 16:46:49 +0000915 (unsigned)(var.print_len/1000000), (unsigned)kbytes,
Benny Prijono85598d92006-01-07 18:44:25 +0000916 elapsed.sec, elapsed.msec,
917 (unsigned)avg_print));
Benny Prijono3818c932005-11-22 01:06:33 +0000918
Benny Prijonoe93e2872006-06-28 16:46:49 +0000919 *p_print = (unsigned)avg_print;
Benny Prijono3818c932005-11-22 01:06:33 +0000920 return status;
921}
Benny Prijonod0bd4982007-12-02 15:40:52 +0000922#endif /* INCLUDE_BENCHMARKS */
Benny Prijono3818c932005-11-22 01:06:33 +0000923
924/*****************************************************************************/
Benny Prijono8aea0d92007-04-29 06:23:11 +0000925/* Test various header parsing and production */
926static int hdr_test_success(pjsip_hdr *h);
927static int hdr_test_accept0(pjsip_hdr *h);
928static int hdr_test_accept1(pjsip_hdr *h);
929static int hdr_test_accept2(pjsip_hdr *h);
930static int hdr_test_allow0(pjsip_hdr *h);
931static int hdr_test_authorization(pjsip_hdr *h);
932static int hdr_test_cid(pjsip_hdr *h);
933static int hdr_test_contact0(pjsip_hdr *h);
934static int hdr_test_contact1(pjsip_hdr *h);
Benny Prijono123fad72008-06-11 11:18:04 +0000935static int hdr_test_contact_q0(pjsip_hdr *h);
936static int hdr_test_contact_q1(pjsip_hdr *h);
937static int hdr_test_contact_q2(pjsip_hdr *h);
938static int hdr_test_contact_q3(pjsip_hdr *h);
939static int hdr_test_contact_q4(pjsip_hdr *h);
Benny Prijono8aea0d92007-04-29 06:23:11 +0000940static int hdr_test_content_length(pjsip_hdr *h);
941static int hdr_test_content_type(pjsip_hdr *h);
942static int hdr_test_from(pjsip_hdr *h);
943static int hdr_test_proxy_authenticate(pjsip_hdr *h);
944static int hdr_test_record_route(pjsip_hdr *h);
945static int hdr_test_supported(pjsip_hdr *h);
946static int hdr_test_to(pjsip_hdr *h);
947static int hdr_test_via(pjsip_hdr *h);
Benny Prijonod0bd4982007-12-02 15:40:52 +0000948static int hdr_test_via_ipv6_1(pjsip_hdr *h);
949static int hdr_test_via_ipv6_2(pjsip_hdr *h);
950static int hdr_test_via_ipv6_3(pjsip_hdr *h);
Benny Prijono054c5df2008-05-15 10:07:36 +0000951static int hdr_test_retry_after1(pjsip_hdr *h);
Benny Prijono3c97d9b2008-09-21 22:01:46 +0000952static int hdr_test_subject_utf(pjsip_hdr *h);
Benny Prijono8aea0d92007-04-29 06:23:11 +0000953
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 Prijonod0bd4982007-12-02 15:40:52 +0000957#define PARAM_CHAR "][/:&+$"
Benny Prijono8aea0d92007-04-29 06:23:11 +0000958#define SIMPLE_ADDR_SPEC "sip:host"
Benny Prijono8fcbe2d2007-04-29 18:07:53 +0000959#define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\""
Benny Prijono8aea0d92007-04-29 06:23:11 +0000960#define NAME_ADDR "<" ADDR_SPEC ">"
961
962#define HDR_FLAG_PARSE_FAIL 1
963#define HDR_FLAG_DONT_PRINT 2
964
965struct hdr_test_t
966{
967 char *hname;
968 char *hshort_name;
Benny Prijonod661f572009-01-28 14:17:14 +0000969 char *hcontent;
Benny Prijono8aea0d92007-04-29 06:23:11 +0000970 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 Prijono123fad72008-06-11 11:18:04 +00001049 /* 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 Prijono8aea0d92007-04-29 06:23:11 +00001086 /* 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 Prijonod0bd4982007-12-02 15:40:52 +00001141 },
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 Prijono054c5df2008-05-15 10:07:36 +00001162 },
1163
1164 {
1165 /* Retry-After header with comment */
1166 "Retry-After", NULL,
1167 "10(Already Pending Register)",
1168 &hdr_test_retry_after1
Benny Prijono3c97d9b2008-09-21 22:01:46 +00001169 },
1170
1171 {
1172 /* Non-ASCII UTF-8 characters in Subject */
1173 "Subject", NULL,
1174 "\xC0\x81",
1175 &hdr_test_subject_utf
Benny Prijono8aea0d92007-04-29 06:23:11 +00001176 }
1177};
1178
1179static int hdr_test_success(pjsip_hdr *h)
1180{
1181 PJ_UNUSED_ARG(h);
1182 return 0;
1183}
1184
1185/* "" */
1186static 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 Prijono64898b52007-05-01 06:36:15 +00001199/* "application/ *, text/plain\r\n" */
Benny Prijono8aea0d92007-04-29 06:23:11 +00001200static 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 Prijono64898b52007-05-01 06:36:15 +00001219/* "application/ *;p1=v1, text/plain\r\n" */
Benny Prijono8aea0d92007-04-29 06:23:11 +00001220static 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/* "" */
1240static 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 */
1260static 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 */
1307static 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 Prijono91a5a3a2007-09-24 21:16:48 +00001314 if (pj_strcmp2(&hdr->id, "-.!%*_+`'~()<>:\\\"/[]?{}"))
Benny Prijono8aea0d92007-04-29 06:23:11 +00001315 return -1520;
1316
1317 return 0;
1318}
1319
1320/*
1321 #define SIMPLE_ADDR_SPEC "sip:host"
1322 */
1323static 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 Prijonod0bd4982007-12-02 15:40:52 +00001340#define PARAM_CHAR "][/:&+$"
Benny Prijono8aea0d92007-04-29 06:23:11 +00001341#define SIMPLE_ADDR_SPEC "sip:host"
Benny Prijono8fcbe2d2007-04-29 18:07:53 +00001342#define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\""
Benny Prijono8aea0d92007-04-29 06:23:11 +00001343#define NAME_ADDR "<" ADDR_SPEC ">"
1344 */
Benny Prijono64898b52007-05-01 06:36:15 +00001345static int nameaddr_test(void *uri)
Benny Prijono8aea0d92007-04-29 06:23:11 +00001346{
Benny Prijono64898b52007-05-01 06:36:15 +00001347 pjsip_sip_uri *sip_uri=(pjsip_sip_uri *)pjsip_uri_get_uri((pjsip_uri*)uri);
Benny Prijono8aea0d92007-04-29 06:23:11 +00001348 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 Prijono8fcbe2d2007-04-29 18:07:53 +00001358 if (pj_list_size(&sip_uri->other_param) != 2)
Benny Prijono8aea0d92007-04-29 06:23:11 +00001359 return -940;
1360
1361 param = sip_uri->other_param.next;
1362
1363 if (pj_strcmp2(&param->name, PARAM_CHAR))
1364 return -942;
1365
1366 if (pj_strcmp2(&param->value, PARAM_CHAR))
1367 return -943;
1368
Benny Prijono8fcbe2d2007-04-29 18:07:53 +00001369 param = param->next;
1370 if (pj_strcmp2(&param->name, "p1"))
1371 return -942;
1372 if (pj_strcmp2(&param->value, "\";\""))
1373 return -943;
1374
Benny Prijono8aea0d92007-04-29 06:23:11 +00001375 return 0;
1376}
1377
1378/*
1379#define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3"
1380 */
1381static 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(&param->name, "p0"))
1391 return -952;
1392 if (pj_strcmp2(&param->value, "a"))
1393 return -953;
1394
1395 param = param->next;
1396 if (pj_strcmp2(&param->name, "p1"))
1397 return -954;
1398 if (pj_strcmp2(&param->value, "\"ab:;cd\""))
1399 return -955;
1400
1401 param = param->next;
1402 if (pj_strcmp2(&param->name, "p2"))
1403 return -956;
1404 if (pj_strcmp2(&param->value, "ab:cd"))
1405 return -957;
1406
1407 param = param->next;
1408 if (pj_strcmp2(&param->name, "p3"))
1409 return -958;
1410 if (pj_strcmp2(&param->value, ""))
1411 return -959;
1412
1413 return 0;
1414}
1415
1416
1417
1418/*
1419 SIMPLE_ADDR_SPEC ";p1=v1\r\n"
1420 */
1421static 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(&param->name, "p1"))
1440 return -1630;
1441
1442 if (pj_strcmp2(&param->value, "v1"))
1443 return -1640;
1444
1445 return 0;
1446}
1447
1448/*
1449 NAME_ADDR GENERIC_PARAM "\r\n",
1450 */
1451static 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 Prijono123fad72008-06-11 11:18:04 +00001471 NAME_ADDR ";q=0"
1472 */
1473static 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 */
1494static 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 */
1515static 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 */
1536static 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 */
1557static 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 Prijono8aea0d92007-04-29 06:23:11 +00001576 "10"
1577 */
1578static 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 */
1594static int hdr_test_content_type(pjsip_hdr *h)
1595{
1596 pjsip_ctype_hdr *hdr = (pjsip_ctype_hdr*)h;
Benny Prijono1e5a08b2010-08-01 09:24:58 +00001597 const pjsip_param *prm;
Benny Prijono8aea0d92007-04-29 06:23:11 +00001598
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 Prijono1e5a08b2010-08-01 09:24:58 +00001611 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 Prijono8aea0d92007-04-29 06:23:11 +00001615
Benny Prijono1e5a08b2010-08-01 09:24:58 +00001616 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 Prijono8aea0d92007-04-29 06:23:11 +00001630
1631 return 0;
1632}
1633
1634/*
1635 NAME_ADDR GENERIC_PARAM,
1636 */
1637static 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 */
1660static 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 */
1697static 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 Prijono64898b52007-05-01 06:36:15 +00001705 rc = nameaddr_test(&hdr->name_addr);
Benny Prijono8aea0d92007-04-29 06:23:11 +00001706 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 */
1720static 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 */
1736static 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 */
1758static 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 Prijonod0bd4982007-12-02 15:40:52 +00001783/*
1784 "SIP/2.0/UDP [::1]"
1785 */
1786static 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" */
1806static 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" */
1826static 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 Prijono054c5df2008-05-15 10:07:36 +00001851/* "10(Already Pending Register)" */
1852static 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 Prijono3c97d9b2008-09-21 22:01:46 +00001868/* Subject: \xC0\x81 */
1869static 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 Prijono8aea0d92007-04-29 06:23:11 +00001882static 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 Prijonod661f572009-01-28 14:17:14 +00001895#if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0
1896 static char hcontent[1024];
1897#else
1898 char *hcontent;
1899#endif
Benny Prijono8aea0d92007-04-29 06:23:11 +00001900 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 Prijonod661f572009-01-28 14:17:14 +00001907#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 Prijonoa1e69682007-05-11 15:14:34 +00001914 parsed_hdr1 = (pjsip_hdr*) pjsip_parse_hdr(pool, &hname,
Benny Prijonod661f572009-01-28 14:17:14 +00001915 hcontent, len,
Benny Prijonoa1e69682007-05-11 15:14:34 +00001916 &parsed_len);
Benny Prijono8aea0d92007-04-29 06:23:11 +00001917 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 Prijono64898b52007-05-01 06:36:15 +00001933#if 1
Benny Prijono8aea0d92007-04-29 06:23:11 +00001934 /* Parse with hshortname, if present */
1935 if (test->hshort_name) {
1936 hname = pj_str(test->hshort_name);
1937 len = strlen(test->hcontent);
Benny Prijonod661f572009-01-28 14:17:14 +00001938#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 Prijono8aea0d92007-04-29 06:23:11 +00001946 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 Prijonoa1e69682007-05-11 15:14:34 +00001959 input = (char*) pj_pool_alloc(pool, 1024);
Benny Prijono8aea0d92007-04-29 06:23:11 +00001960 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 Prijonoa1e69682007-05-11 15:14:34 +00001965 output = (char*) pj_pool_alloc(pool, 1024);
Benny Prijono8aea0d92007-04-29 06:23:11 +00001966 len = pjsip_hdr_print_on(parsed_hdr1, output, 1024);
Benny Prijono329d6382009-05-29 13:04:03 +00001967 if (len < 0 || len >= 1024) {
Benny Prijono8aea0d92007-04-29 06:23:11 +00001968 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 Prijonoe93e2872006-06-28 16:46:49 +00001988
1989int msg_test(void)
1990{
Benny Prijonod4791af2007-06-19 08:46:02 +00001991 enum { COUNT = 1, DETECT=0, PARSE=1, PRINT=2 };
Benny Prijonoe93e2872006-06-28 16:46:49 +00001992 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 Prijono8aea0d92007-04-29 06:23:11 +00002001 status = hdr_test();
2002 if (status != 0)
2003 return status;
2004
Benny Prijonod0bd4982007-12-02 15:40:52 +00002005 status = simple_test();
2006 if (status != PJ_SUCCESS)
2007 return status;
2008
2009#if INCLUDE_BENCHMARKS
Benny Prijonoe93e2872006-06-28 16:46:49 +00002010 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 Prijono7db431e2006-07-23 14:38:49 +00002034 "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len);
Benny Prijonoe93e2872006-06-28 16:46:49 +00002035 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 Prijono7db431e2006-07-23 14:38:49 +00002047 "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len);
Benny Prijonoe93e2872006-06-28 16:46:49 +00002048 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 Prijono7db431e2006-07-23 14:38:49 +00002067 "%d bytes)", (int)PJ_ARRAY_SIZE(test_array), avg_len);
Benny Prijonoe93e2872006-06-28 16:46:49 +00002068
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 Prijonod0bd4982007-12-02 15:40:52 +00002077#endif /* INCLUDE_BENCHMARKS */
Benny Prijonoe93e2872006-06-28 16:46:49 +00002078
2079 return PJ_SUCCESS;
2080}
2081
Benny Prijono8aea0d92007-04-29 06:23:11 +00002082
2083
2084