Changeset 82 for pjproject/trunk/pjsip/src/pjsip/sip_parser.c
- Timestamp:
- Nov 23, 2005 8:56:30 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_parser.c
r80 r82 50 50 51 51 #define PJSIP_VERSION "SIP/2.0" 52 #define PJSIP_SYN_ERR_EXCEPTION 153 52 54 53 #define UNREACHED(expr) 55 54 56 //#define IS_NEWLINE(c) ((c)=='\r' || (c)=='\n') 57 #define IS_NEWLINE(c) ((c)=='\r') 55 #define IS_NEWLINE(c) ((c)=='\r' || (c)=='\n') 58 56 #define IS_SPACE(c) ((c)==' ' || (c)=='\t') 59 57 58 /* 59 * Header parser records. 60 */ 60 61 typedef struct handler_rec 61 62 { … … 66 67 } handler_rec; 67 68 68 static handler_rec handler[ 127];69 static handler_rec handler[PJSIP_MAX_HEADER_TYPES]; 69 70 static unsigned handler_count; 70 71 static int parser_is_initialized; 72 73 /* 74 * URI parser records. 75 */ 76 typedef struct uri_parser_rec 77 { 78 pj_str_t scheme; 79 pjsip_parse_uri_func *parse; 80 } uri_parser_rec; 81 82 static uri_parser_rec uri_handler[PJSIP_MAX_URI_TYPES]; 83 static unsigned uri_handler_count; 71 84 72 85 /* 73 86 * Global vars (also extern). 74 87 */ 88 int PJSIP_SYN_ERR_EXCEPTION; 89 75 90 const pj_str_t pjsip_USER_STR = { "user", 4}; 76 91 const pj_str_t pjsip_METHOD_STR = { "method", 6}; … … 247 262 initialized = 1; 248 263 264 /* 265 * Syntax error exception number. 266 */ 267 status = pj_exception_id_alloc("PJSIP: syntax error", 268 &PJSIP_SYN_ERR_EXCEPTION); 269 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 270 271 /* 272 * Init character input spec (cis) 273 */ 274 249 275 pj_cis_buf_init(&cis_buf); 250 276 … … 310 336 pj_cis_invert(&pjsip_DISPLAY_SPEC); 311 337 338 /* 339 * Register URI parsers. 340 */ 341 342 status = pjsip_register_uri_parser("sip", &int_parse_sip_url); 343 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 344 345 status = pjsip_register_uri_parser("sips", &int_parse_sip_url); 346 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 347 348 /* 349 * Register header parsers. 350 */ 351 312 352 status = pjsip_register_hdr_parser( "Accept", NULL, &parse_hdr_accept); 313 353 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); … … 374 414 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 375 415 376 /* Register auth parser. */ 416 /* 417 * Register auth parser. 418 */ 419 377 420 status = pjsip_auth_init_parser(); 378 421 … … 383 426 { 384 427 if (!parser_is_initialized) { 385 /* Prevent race cond. */386 pj_enter_critical_section();387 428 if (!parser_is_initialized) { 388 429 init_parser(); 389 430 parser_is_initialized = 1; 390 431 } 391 pj_leave_critical_section();392 432 } 393 433 } … … 399 439 */ 400 440 PJ_INLINE(int) compare_handler( const handler_rec *r1, 401 402 403 441 const char *name, 442 pj_size_t name_len, 443 pj_uint32_t hash ) 404 444 { 405 445 PJ_UNUSED_ARG(name_len); … … 539 579 } 540 580 581 /* Find URI handler. */ 582 static pjsip_parse_uri_func* find_uri_handler(const pj_str_t *scheme) 583 { 584 unsigned i; 585 for (i=0; i<uri_handler_count; ++i) { 586 if (pj_stricmp_alnum(&uri_handler[i].scheme, scheme)==0) 587 return uri_handler[i].parse; 588 } 589 return NULL; 590 } 591 592 /* Register URI parser. */ 593 PJ_DEF(pj_status_t) pjsip_register_uri_parser( char *scheme, 594 pjsip_parse_uri_func *func) 595 { 596 if (uri_handler_count >= PJ_ARRAY_SIZE(uri_handler)) 597 return PJ_ETOOMANY; 598 599 uri_handler[uri_handler_count].scheme = pj_str((char*)scheme); 600 uri_handler[uri_handler_count].parse = func; 601 ++uri_handler_count; 602 603 return PJ_SUCCESS; 604 } 605 541 606 /* Public function to parse SIP message. */ 542 607 PJ_DEF(pjsip_msg*) pjsip_parse_msg( pj_pool_t *pool, … … 548 613 pjsip_parse_ctx context; 549 614 550 init_sip_parser();551 552 615 pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER, 553 616 &on_syntax_error); … … 569 632 pj_scanner scanner; 570 633 pjsip_parse_ctx context; 571 572 init_sip_parser();573 634 574 635 pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER, … … 626 687 PJ_USE_EXCEPTION; 627 688 628 init_sip_parser();629 630 689 pj_scan_init(&scanner, (char*)line, hdr_end-line, 631 690 PJ_SCAN_AUTOSKIP_WS_HEADER, &on_syntax_error); … … 694 753 pjsip_uri *uri = NULL; 695 754 PJ_USE_EXCEPTION; 696 697 init_sip_parser();698 755 699 756 pj_scan_init(&scanner, buf, size, 0, &on_syntax_error); … … 872 929 } 873 930 931 /* Restore flag. Flag may be set in int_parse_sip_url() */ 932 scanner->skip_ws = PJ_SCAN_AUTOSKIP_WS_HEADER; 933 934 /* Continue parse next header, if any. */ 874 935 if (!pj_scan_is_eof(scanner) && !IS_NEWLINE(*scanner->curptr)) { 875 936 goto parse_headers; … … 1019 1080 next_ch = pj_scan_peek( scanner, &pjsip_DISPLAY_SPEC, &scheme); 1020 1081 1021 if (next_ch==':' && 1022 (parser_stricmp(scheme, pjsip_SIP_STR)==0 || 1023 parser_stricmp(scheme, pjsip_SIPS_STR)==0)) 1024 { 1025 uri = (pjsip_uri*) 1026 int_parse_sip_url( scanner, pool, 1027 (opt & PJSIP_PARSE_URI_IN_FROM_TO_HDR)== 0); 1028 1029 } else if (next_ch==':') { 1030 1031 /* Not supported. */ 1032 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 1033 UNREACHED({return NULL; /* Not reached. */}); 1082 if (next_ch==':') { 1083 pjsip_parse_uri_func *func = find_uri_handler(&scheme); 1084 1085 if (func == NULL) { 1086 /* Unsupported URI scheme */ 1087 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 1088 } 1089 1090 uri = (*func)( scanner, pool, 1091 (opt & PJSIP_PARSE_URI_IN_FROM_TO_HDR)== 0); 1092 1034 1093 1035 1094 } else { … … 1063 1122 pj_str_t scheme; 1064 1123 int colon; 1124 pjsip_parse_uri_func *func; 1065 1125 1066 1126 /* Get scheme. */ … … 1070 1130 } 1071 1131 1072 if ((parser_stricmp(scheme, pjsip_SIP_STR)==0 || 1073 parser_stricmp(scheme, pjsip_SIPS_STR)==0)) 1074 { 1075 return (pjsip_uri*)int_parse_sip_url( scanner, pool, parse_params); 1076 1077 } else if (parser_stricmp(scheme, pjsip_TEL_STR)==0) { 1078 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 1079 UNREACHED({ return NULL; /* Not reached. */ }) 1132 func = find_uri_handler(&scheme); 1133 if (func) { 1134 return (pjsip_uri*)(*func)(scanner, pool, parse_params); 1080 1135 1081 1136 } else { 1137 /* Unsupported URI scheme */ 1082 1138 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 1083 1139 UNREACHED({ return NULL; /* Not reached. */ }) … … 1774 1830 PJ_USE_EXCEPTION; 1775 1831 1776 init_sip_parser();1777 1778 1832 pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER, 1779 1833 &on_syntax_error);
Note: See TracChangeset
for help on using the changeset viewer.