Changeset 65 for pjproject/trunk/pjsip/src/test-pjsip/uri.c
- Timestamp:
- Nov 21, 2005 1:55:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/uri.c
- Property svn:eol-style set to native
r64 r65 26 26 "0123456789" 27 27 #define MARK "-_.!~*'()" 28 #define USER "&=+$,;?/%" 29 #define PASS "&=+$,%" 30 #define PARAM_CHAR "[]/:&+$" MARK "%" 31 32 #define POOL_SIZE 4096 33 34 static pj_uint32_t parse_len, parse_time, print_time; 28 #define USER_CHAR ALPHANUM MARK "&=+$,;?/" 29 #define PASS_CHAR ALPHANUM MARK "&=+$," 30 #define PARAM_CHAR ALPHANUM MARK "[]/:&+$" 31 32 #define POOL_SIZE 4000 33 #define LOOP_COUNT 1000 34 #define AVERAGE_URL_LEN 80 35 #define THREAD_COUNT 4 36 37 static pj_uint32_t parse_len; 38 static pj_timestamp parse_time, print_time; 35 39 36 40 37 41 /* URI creator functions. */ 42 static pjsip_uri *create_uri0( pj_pool_t *pool ); 38 43 static pjsip_uri *create_uri1( pj_pool_t *pool ); 39 44 static pjsip_uri *create_uri2( pj_pool_t *pool ); … … 53 58 static pjsip_uri *create_uri16( pj_pool_t *pool ); 54 59 static pjsip_uri *create_uri17( pj_pool_t *pool ); 55 static pjsip_uri *create_uri18( pj_pool_t *pool );56 static pjsip_uri *create_uri19( pj_pool_t *pool );57 60 static pjsip_uri *create_dummy( pj_pool_t *pool ); 58 61 … … 71 74 PJ_SUCCESS, 72 75 "sip:localhost", 76 &create_uri0 77 }, 78 { 79 PJ_SUCCESS, 80 "sip:user@localhost", 73 81 &create_uri1 74 82 }, 75 83 { 76 84 PJ_SUCCESS, 77 "sip:user@localhost",78 &create_uri279 },80 {81 PJ_SUCCESS,82 85 "sip:user:password@localhost:5060", 83 &create_uri 3,86 &create_uri2, 84 87 }, 85 88 { … … 87 90 ERR_NOT_EQUAL, 88 91 "sip:localhost:5060", 92 &create_uri3 93 }, 94 { 95 /* All recognized parameters. */ 96 PJ_SUCCESS, 97 "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK", 89 98 &create_uri4 90 },91 {92 /* All recognized parameters. */93 PJ_SUCCESS,94 "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK",95 &create_uri596 99 }, 97 100 { … … 100 103 "sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry" 101 104 "?Subject=Hello%20There&Server=SIP%20Server", 102 &create_uri 6105 &create_uri5 103 106 }, 104 107 { … … 106 109 PJ_SUCCESS, 107 110 "sips:localhost", 108 &create_uri 7,111 &create_uri6, 109 112 }, 110 113 { … … 112 115 PJ_SUCCESS, 113 116 "<sip:localhost>", 114 &create_uri 8117 &create_uri7 115 118 }, 116 119 { … … 120 123 PJ_SUCCESS, 121 124 " Power Administrator <sips:localhost>", 125 &create_uri8 126 }, 127 { 128 /* Name address. */ 129 PJ_SUCCESS, 130 " \"User\" <sip:user@localhost:5071>", 122 131 &create_uri9 123 132 }, 124 133 { 125 /* Name address. */126 PJ_SUCCESS,127 " \"User\" <sip:user@localhost:5071>",128 &create_uri10129 },130 {131 134 /* Escaped sequence in display name (display=Strange User\"\\\"). */ 132 135 PJ_SUCCESS, 133 136 " \"Strange User\\\"\\\\\\\"\" <sip:localhost>", 137 &create_uri10, 138 }, 139 { 140 /* Errorneous escaping in display name. */ 141 ERR_SYNTAX_ERR, 142 " \"Rogue User\\\" <sip:localhost>", 134 143 &create_uri11, 135 144 }, 136 145 { 137 /* Errorneous escaping in display name. */138 ERR_SYNTAX_ERR,139 " \"Rogue User\\\" <sip:localhost>",146 /* Dangling quote in display name, but that should be OK. */ 147 PJ_SUCCESS, 148 "Strange User\" <sip:localhost>", 140 149 &create_uri12, 141 150 }, 142 151 { 143 /* Dangling quote in display name, but that should be OK. */144 PJ_SUCCESS, 145 " Strange User\" <sip:localhost>",152 /* Special characters in parameter value must be quoted. */ 153 PJ_SUCCESS, 154 "sip:localhost;pvalue=\"hello world\"", 146 155 &create_uri13, 147 },148 {149 /* Special characters in parameter value must be quoted. */150 PJ_SUCCESS,151 "sip:localhost;pvalue=\"hello world\"",152 &create_uri14,153 156 }, 154 157 { … … 157 160 */ 158 161 PJ_SUCCESS, 159 "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:% 09a&Zz=+$,@"162 "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@" 160 163 "my_proxy09.MY-domain.com:9801>", 164 &create_uri14, 165 }, 166 { 167 /* Another excercise to the allowed character sets to the hostname. */ 168 PJ_SUCCESS, 169 "sip:" ALPHANUM "-_.com", 161 170 &create_uri15, 162 },163 {164 /* Another excercise to the allowed character sets to the hostname. */165 PJ_SUCCESS,166 "sip:" ALPHANUM "-_.com",167 &create_uri16,168 171 }, 169 172 { … … 172 175 */ 173 176 PJ_SUCCESS, 174 "sip:" ALPHANUM USER ":" ALPHANUM PASS"@host",175 &create_uri1 7,177 "sip:" USER_CHAR ":" PASS_CHAR "@host", 178 &create_uri16, 176 179 }, 177 180 { … … 180 183 */ 181 184 PJ_SUCCESS, 182 "sip:host;user=ip;" ALPHANUM PARAM_CHAR "=" ALPHANUM PARAM_CHAR185 "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21" 183 186 ";lr;other=1;transport=sctp;other2", 184 &create_uri1 8,185 }, 186 { 187 /* This should trigger syntax error. */187 &create_uri17, 188 }, 189 { 190 /* 18: This should trigger syntax error. */ 188 191 ERR_SYNTAX_ERR, 189 192 "sip:", … … 191 194 }, 192 195 { 193 /* Syntax error: whitespace after scheme. */196 /* 19: Syntax error: whitespace after scheme. */ 194 197 ERR_SYNTAX_ERR, 195 198 "sip :host", … … 197 200 }, 198 201 { 199 /* Syntax error: whitespace before hostname. */202 /* 20: Syntax error: whitespace before hostname. */ 200 203 ERR_SYNTAX_ERR, 201 204 "sip: host", … … 203 206 }, 204 207 { 205 /* Syntax error: invalid port. */208 /* 21: Syntax error: invalid port. */ 206 209 ERR_SYNTAX_ERR, 207 210 "sip:user:password", … … 209 212 }, 210 213 { 211 /* Syntax error: no host. */214 /* 22: Syntax error: no host. */ 212 215 ERR_SYNTAX_ERR, 213 216 "sip:user@", … … 215 218 }, 216 219 { 217 /* Syntax error: no user/host. */220 /* 23: Syntax error: no user/host. */ 218 221 ERR_SYNTAX_ERR, 219 222 "sip:@", … … 221 224 }, 222 225 { 223 /* Syntax error: empty string. */226 /* 24: Syntax error: empty string. */ 224 227 ERR_SYNTAX_ERR, 225 228 "", … … 228 231 }; 229 232 230 static pjsip_uri *create_uri 1(pj_pool_t *pool)233 static pjsip_uri *create_uri0(pj_pool_t *pool) 231 234 { 232 235 /* "sip:localhost" */ … … 237 240 } 238 241 239 static pjsip_uri *create_uri 2(pj_pool_t *pool)242 static pjsip_uri *create_uri1(pj_pool_t *pool) 240 243 { 241 244 /* "sip:user@localhost" */ … … 248 251 } 249 252 250 static pjsip_uri *create_uri 3(pj_pool_t *pool)253 static pjsip_uri *create_uri2(pj_pool_t *pool) 251 254 { 252 255 /* "sip:user:password@localhost:5060" */ … … 261 264 } 262 265 263 static pjsip_uri *create_uri 4(pj_pool_t *pool)266 static pjsip_uri *create_uri3(pj_pool_t *pool) 264 267 { 265 268 /* Like: "sip:localhost:5060", but without the port. */ … … 270 273 } 271 274 272 static pjsip_uri *create_uri 5(pj_pool_t *pool)275 static pjsip_uri *create_uri4(pj_pool_t *pool) 273 276 { 274 277 /* "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK" */ … … 286 289 } 287 290 288 static pjsip_uri *create_uri6(pj_pool_t *pool) 291 #define param_add(list,pname,pvalue) \ 292 do { \ 293 pjsip_param *param; \ 294 param=pj_pool_alloc(pool, sizeof(pjsip_param)); \ 295 param->name = pj_str(pname); \ 296 param->value = pj_str(pvalue); \ 297 pj_list_insert_before(&list, param); \ 298 } while (0) 299 300 static pjsip_uri *create_uri5(pj_pool_t *pool) 289 301 { 290 302 /* "sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry" … … 295 307 pj_strdup2(pool, &url->host, "localhost"); 296 308 pj_strdup2(pool, &url->user_param, "phone"); 297 pj_strdup2(pool, &url->other_param, ";pickup=hurry;message=I%20am%20sorry"); 298 pj_strdup2(pool, &url->header_param, "?Subject=Hello%20There&Server=SIP%20Server"); 299 return (pjsip_uri*)url; 300 301 } 302 303 static pjsip_uri *create_uri7(pj_pool_t *pool) 309 310 //pj_strdup2(pool, &url->other_param, ";pickup=hurry;message=I%20am%20sorry"); 311 param_add(url->other_param, "pickup", "hurry"); 312 param_add(url->other_param, "message", "I am sorry"); 313 314 //pj_strdup2(pool, &url->header_param, "?Subject=Hello%20There&Server=SIP%20Server"); 315 param_add(url->header_param, "Subject", "Hello There"); 316 param_add(url->header_param, "Server", "SIP Server"); 317 return (pjsip_uri*)url; 318 319 } 320 321 static pjsip_uri *create_uri6(pj_pool_t *pool) 304 322 { 305 323 /* "sips:localhost" */ … … 310 328 } 311 329 312 static pjsip_uri *create_uri 8(pj_pool_t *pool)330 static pjsip_uri *create_uri7(pj_pool_t *pool) 313 331 { 314 332 /* "<sip:localhost>" */ … … 323 341 } 324 342 325 static pjsip_uri *create_uri 9(pj_pool_t *pool)343 static pjsip_uri *create_uri8(pj_pool_t *pool) 326 344 { 327 345 /* " Power Administrator <sips:localhost>" */ … … 337 355 } 338 356 339 static pjsip_uri *create_uri 10(pj_pool_t *pool)357 static pjsip_uri *create_uri9(pj_pool_t *pool) 340 358 { 341 359 /* " \"User\" <sip:user@localhost:5071>" */ … … 346 364 name_addr->uri = (pjsip_uri*) url; 347 365 348 pj_strdup2(pool, &name_addr->display, " \"User\"");366 pj_strdup2(pool, &name_addr->display, "User"); 349 367 pj_strdup2(pool, &url->user, "user"); 350 368 pj_strdup2(pool, &url->host, "localhost"); … … 353 371 } 354 372 355 static pjsip_uri *create_uri1 1(pj_pool_t *pool)373 static pjsip_uri *create_uri10(pj_pool_t *pool) 356 374 { 357 375 /* " \"Strange User\\\"\\\\\\\"\" <sip:localhost>" */ … … 362 380 name_addr->uri = (pjsip_uri*) url; 363 381 364 pj_strdup2(pool, &name_addr->display, " \"Strange User\\\"\\\\\\\"\"");382 pj_strdup2(pool, &name_addr->display, "Strange User\\\"\\\\\\\""); 365 383 pj_strdup2(pool, &url->host, "localhost"); 366 384 return (pjsip_uri*)name_addr; 367 385 } 368 386 369 static pjsip_uri *create_uri1 2(pj_pool_t *pool)387 static pjsip_uri *create_uri11(pj_pool_t *pool) 370 388 { 371 389 /* " \"Rogue User\\\" <sip:localhost>" */ … … 376 394 name_addr->uri = (pjsip_uri*) url; 377 395 378 pj_strdup2(pool, &name_addr->display, " \"Rogue User\\\"");396 pj_strdup2(pool, &name_addr->display, "Rogue User\\"); 379 397 pj_strdup2(pool, &url->host, "localhost"); 380 398 return (pjsip_uri*)name_addr; 381 399 } 382 400 383 static pjsip_uri *create_uri1 3(pj_pool_t *pool)401 static pjsip_uri *create_uri12(pj_pool_t *pool) 384 402 { 385 403 /* "Strange User\" <sip:localhost>" */ … … 395 413 } 396 414 415 static pjsip_uri *create_uri13(pj_pool_t *pool) 416 { 417 /* "sip:localhost;pvalue=\"hello world\"" */ 418 pjsip_url *url; 419 url = pjsip_url_create(pool, 0); 420 pj_strdup2(pool, &url->host, "localhost"); 421 //pj_strdup2(pool, &url->other_param, ";pvalue=\"hello world\""); 422 param_add(url->other_param, "pvalue", "hello world"); 423 return (pjsip_uri*)url; 424 } 425 397 426 static pjsip_uri *create_uri14(pj_pool_t *pool) 398 427 { 399 /* "sip:localhost;pvalue=\"hello world\"" */ 400 pjsip_url *url; 401 url = pjsip_url_create(pool, 0); 402 pj_strdup2(pool, &url->host, "localhost"); 403 pj_strdup2(pool, &url->other_param, ";pvalue=\"hello world\""); 404 return (pjsip_uri*)url; 405 } 406 407 static pjsip_uri *create_uri15(pj_pool_t *pool) 408 { 409 /* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%09a&Zz=+$,@my_proxy09.my-domain.com:9801>" */ 428 /* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@my_proxy09.my-domain.com:9801>" */ 410 429 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 411 430 pjsip_url *url; … … 415 434 416 435 pj_strdup2(pool, &name_addr->display, "This is -. !% *_+`'~ me"); 417 pj_strdup2(pool, &url->user, "a19A&=+$,;?/ %2c");418 pj_strdup2(pool, &url->passwd, " %09a&Zz=+$,");436 pj_strdup2(pool, &url->user, "a19A&=+$,;?/,"); 437 pj_strdup2(pool, &url->passwd, "@a&Zz=+$,"); 419 438 pj_strdup2(pool, &url->host, "my_proxy09.MY-domain.com"); 420 439 url->port = 9801; … … 422 441 } 423 442 443 static pjsip_uri *create_uri15(pj_pool_t *pool) 444 { 445 /* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */ 446 pjsip_url *url; 447 url = pjsip_url_create(pool, 0); 448 pj_strdup2(pool, &url->host, ALPHANUM "-_.com"); 449 return (pjsip_uri*)url; 450 } 451 424 452 static pjsip_uri *create_uri16(pj_pool_t *pool) 425 453 { 426 /* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */ 427 pjsip_url *url; 428 url = pjsip_url_create(pool, 0); 429 pj_strdup2(pool, &url->host, ALPHANUM "-_.com"); 454 /* "sip:" USER_CHAR ":" PASS_CHAR "@host" */ 455 pjsip_url *url; 456 url = pjsip_url_create(pool, 0); 457 pj_strdup2(pool, &url->user, USER_CHAR); 458 pj_strdup2(pool, &url->passwd, PASS_CHAR); 459 pj_strdup2(pool, &url->host, "host"); 430 460 return (pjsip_uri*)url; 431 461 } … … 433 463 static pjsip_uri *create_uri17(pj_pool_t *pool) 434 464 { 435 /* "sip:" ALPHANUM USER ":" ALPHANUM PASS "@host" */ 436 pjsip_url *url; 437 url = pjsip_url_create(pool, 0); 438 pj_strdup2(pool, &url->user, ALPHANUM USER); 439 pj_strdup2(pool, &url->passwd, ALPHANUM PASS); 440 pj_strdup2(pool, &url->host, "host"); 441 return (pjsip_uri*)url; 442 } 443 444 static pjsip_uri *create_uri18(pj_pool_t *pool) 445 { 446 /* "sip:host;user=ip;" ALPHANUM PARAM_CHAR "=" ALPHANUM PARAM_CHAR ";lr;other=1;transport=sctp;other2" */ 465 /* "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21;lr;other=1;transport=sctp;other2" */ 447 466 pjsip_url *url; 448 467 url = pjsip_url_create(pool, 0); … … 450 469 pj_strdup2(pool, &url->user_param, "ip"); 451 470 pj_strdup2(pool, &url->transport_param, "sctp"); 452 pj_strdup2(pool, &url->other_param, ";" ALPHANUM PARAM_CHAR "=" ALPHANUM PARAM_CHAR ";other=1;other2"); 471 param_add(url->other_param, PARAM_CHAR "!", PARAM_CHAR "!"); 472 param_add(url->other_param, "other", "1"); 473 param_add(url->other_param, "other2", ""); 453 474 url->lr_param = 1; 454 475 return (pjsip_uri*)url; … … 485 506 */ 486 507 status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10; 508 if (status != 0) { 509 PJ_LOG(3,("", " uri parse error!\n" 510 " uri='%s'\n", 511 entry->str)); 512 } 487 513 goto on_return; 488 514 } 489 515 pj_get_timestamp(&t2); 490 parse_time += t2.u32.lo - t1.u32.lo; 516 pj_sub_timestamp(&t2, &t1); 517 pj_add_timestamp(&parse_time, &t2); 491 518 492 519 /* Create the reference URI. */ … … 503 530 goto on_return; 504 531 } 532 s1.ptr[len] = '\0'; 505 533 s1.slen = len; 534 535 pj_get_timestamp(&t2); 536 pj_sub_timestamp(&t2, &t1); 537 pj_add_timestamp(&print_time, &t2); 506 538 507 539 len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE); … … 510 542 goto on_return; 511 543 } 544 s2.ptr[len] = '\0'; 512 545 s2.slen = len; 513 pj_get_timestamp(&t2);514 print_time += t2.u32.lo - t1.u32.lo;515 546 516 547 /* Full comparison of parsed URI with reference URI. */ 517 if (pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri) != 0) { 548 status = pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri); 549 if (status != 0) { 518 550 /* Not equal. See if this is the expected status. */ 519 551 status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40; 552 if (status != 0) { 553 PJ_LOG(3,("", " uri comparison mismatch, status=%d:\n" 554 " uri1='%s'\n" 555 " uri2='%s'", 556 status, s1.ptr, s2.ptr)); 557 } 520 558 goto on_return; 521 559 … … 540 578 pj_status_t uri_test() 541 579 { 542 unsigned i ;580 unsigned i, loop; 543 581 pj_pool_t *pool; 544 582 pj_status_t status; 545 546 pool = pjsip_endpt_create_pool(endpt, "", 4000, 4000); 547 583 pj_timestamp zero; 584 pj_highprec_t avg_parse, avg_print; 585 586 zero.u32.hi = zero.u32.lo = 0; 587 588 PJ_LOG(3,("", " simple test")); 589 pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE); 548 590 for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { 549 591 status = do_uri_test(pool, &uri_test_array[i]); … … 551 593 PJ_LOG(3,("uri_test", " error %d when testing entry %d", 552 594 status, i)); 553 break;595 goto on_return; 554 596 } 555 597 } 556 598 pjsip_endpt_destroy_pool(endpt, pool); 599 600 PJ_LOG(3,("", " benchmarking...")); 601 parse_len = 0; 602 parse_time.u32.hi = parse_time.u32.lo = 0; 603 print_time.u32.hi = print_time.u32.lo = 0; 604 pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE); 605 for (loop=0; loop<LOOP_COUNT; ++loop) { 606 for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { 607 status = do_uri_test(pool, &uri_test_array[i]); 608 if (status != PJ_SUCCESS) { 609 PJ_LOG(3,("uri_test", " error %d when testing entry %d", 610 status, i)); 611 goto on_return; 612 } 613 } 614 } 615 616 avg_parse = pj_elapsed_usec(&zero, &parse_time); 617 pj_highprec_mul(avg_parse, AVERAGE_URL_LEN); 618 pj_highprec_div(avg_parse, parse_len); 619 avg_parse = 1000000 / avg_parse; 620 621 avg_print = pj_elapsed_usec(&zero, &print_time); 622 pj_highprec_mul(avg_print, AVERAGE_URL_LEN); 623 pj_highprec_div(avg_print, parse_len); 624 avg_print = 1000000 / avg_print; 625 626 PJ_LOG(3,("", " done. Average parse=%d url/sec, print=%d url/sec", 627 (unsigned)avg_parse, (unsigned)avg_print)); 628 629 PJ_LOG(3,("", " multithreaded test")); 630 631 632 on_return: 557 633 pjsip_endpt_destroy_pool(endpt, pool); 558 634 return status;
Note: See TracChangeset
for help on using the changeset viewer.