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