Changeset 64 for pjproject/trunk/pjsip/src/pjsip/sip_parser.c
- Timestamp:
- Nov 20, 2005 7:58:10 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_parser.c
r54 r64 24 24 #include <pjsip/sip_transport.h> /* rdata structure */ 25 25 #include <pjlib-util/scanner.h> 26 #include <pjlib-util/string.h> 26 27 #include <pj/except.h> 27 28 #include <pj/log.h> … … 33 34 #include <pj/assert.h> 34 35 35 #define RESERVED ";/?:@&=+$," 36 #define MARK "-_.!~*'()" 37 #define ESCAPED "%" 38 #define USER "&=+$,;?/" 39 #define PASS "&=+$," 40 #define TOKEN "-.!%*_=`'~+" /* '+' is because of application/pidf+xml 41 * in Content-Type! */ 42 #define HOST "_-." 43 #define HEX_DIGIT "abcdefABCDEF" 44 #define PARAM_CHAR "[]/:&+$" MARK "%" 36 #define ALNUM 37 #define RESERVED ";/?:@&=+$," 38 #define MARK "-_.!~*'()" 39 #define UNRESERVED ALNUM MARK 40 #define ESCAPED "%" 41 #define USER_UNRESERVED "&=+$,;?/" 42 #define PASS "&=+$," 43 #define TOKEN "-.!%*_=`'~+" /* '+' is because of app/pidf+xml 44 * in Content-Type! */ 45 #define HOST "_-." 46 #define HEX_DIGIT "abcdefABCDEF" 47 #define PARAM_CHAR "[]/:&+$" UNRESERVED ESCAPED 48 #define HNV_UNRESERVED "[]/?:+$" 49 #define HDR_CHAR HNV_UNRESERVED UNRESERVED ESCAPED 45 50 46 51 #define PJSIP_VERSION "SIP/2.0" … … 93 98 pjsip_PARAM_CHAR_SPEC, /* For scanning pname (or pvalue when 94 99 * it's not quoted.) */ 100 pjsip_HDR_CHAR_SPEC, /* Chars in hname or hvalue */ 95 101 pjsip_PROBE_USER_HOST_SPEC, /* Hostname characters. */ 96 102 pjsip_PASSWD_SPEC, /* Password. */ … … 110 116 pj_str_t *pname, 111 117 pj_str_t *pvalue); 118 static void int_parse_hparam( pj_scanner *scanner, 119 pj_str_t *hname, 120 pj_str_t *hvalue ); 112 121 static void int_parse_req_line( pj_scanner *scanner, 113 122 pj_pool_t *pool, … … 272 281 pj_cis_add_str(&pjsip_PARAM_CHAR_SPEC, PARAM_CHAR); 273 282 283 status = pj_cis_dup(&pjsip_HDR_CHAR_SPEC, &pjsip_ALNUM_SPEC); 284 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 285 pj_cis_add_str(&pjsip_HDR_CHAR_SPEC, HDR_CHAR); 286 274 287 status = pj_cis_dup(&pjsip_USER_SPEC, &pjsip_ALNUM_SPEC); 275 288 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 276 pj_cis_add_str( &pjsip_USER_SPEC, MARK ESCAPED USER);289 pj_cis_add_str( &pjsip_USER_SPEC, ESCAPED USER_UNRESERVED ); 277 290 278 291 status = pj_cis_dup(&pjsip_PASSWD_SPEC, &pjsip_ALNUM_SPEC); … … 859 872 /* pname */ 860 873 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pname); 874 pj_str_unescape(pname); 861 875 862 876 /* pvalue, if any */ … … 872 886 } else { 873 887 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 888 pj_str_unescape(pvalue); 874 889 } 875 890 } else { … … 890 905 } 891 906 907 /* Parse header parameter. */ 908 static void int_parse_hparam( pj_scanner *scanner, 909 pj_str_t *hname, pj_str_t *hvalue ) 910 { 911 /* Get '?' or '&' character. */ 912 pj_scan_get_char(scanner); 913 914 /* hname */ 915 pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hname); 916 pj_str_unescape(hname); 917 918 /* pvalue, if any */ 919 if (*scanner->curptr == '=') { 920 pj_scan_get_char(scanner); 921 pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hvalue); 922 pj_str_unescape(hvalue); 923 } else { 924 hvalue->ptr = NULL; 925 hvalue->slen = 0; 926 } 927 } 928 892 929 /* Parse host:port in URI. */ 893 930 static void int_parse_uri_host_port( pj_scanner *scanner, … … 895 932 { 896 933 pj_scan_get( scanner, &pjsip_HOST_SPEC, host); 934 /* RFC3261 section 19.1.2: host don't need to be unescaped */ 897 935 if (*scanner->curptr == ':') { 898 936 pj_str_t port; 899 937 pj_scan_get_char(scanner); 900 938 pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &port); 939 pj_str_unescape(&port); 901 940 *p_port = pj_strtoul(&port); 902 941 } else { … … 927 966 { 928 967 pj_scan_get( scanner, &pjsip_USER_SPEC, user); 968 pj_str_unescape(user); 969 929 970 if ( *scanner->curptr == ':') { 930 971 pj_scan_get_char( scanner ); 931 972 pj_scan_get( scanner, &pjsip_PASSWD_SPEC, pass); 973 pj_str_unescape(pass); 932 974 } else { 933 975 pass->ptr = NULL; … … 945 987 pjsip_uri *uri; 946 988 int is_name_addr = 0; 989 990 /* Exhaust any whitespaces. */ 991 pj_scan_skip_whitespace(scanner); 947 992 948 993 if (*scanner->curptr=='"' || *scanner->curptr=='<') { … … 1035 1080 int colon; 1036 1081 int skip_ws = scanner->skip_ws; 1082 int hsep = '?'; 1037 1083 scanner->skip_ws = 0; 1038 1084 … … 1090 1136 1091 1137 } else { 1092 concat_param(&url->other_param, pool, &pname, &pvalue); 1138 pjsip_param *p = pj_pool_alloc(pool, sizeof(pjsip_param)); 1139 p->name = pname; 1140 p->value = pvalue; 1141 pj_list_insert_before(&url->other_param, p); 1093 1142 } 1094 1143 } 1095 1144 1096 1145 /* Get header params. */ 1097 if (parse_params && *scanner->curptr == '?') { 1098 pj_scan_get_until(scanner, &pjsip_NEWLINE_OR_EOF_SPEC, 1099 &url->header_param); 1146 while (parse_params && *scanner->curptr == hsep) { 1147 pjsip_param *param; 1148 param = pj_pool_alloc(pool, sizeof(pjsip_param)); 1149 int_parse_hparam(scanner, ¶m->name, ¶m->value); 1150 pj_list_insert_before(&url->header_param, param); 1151 hsep = '&'; 1100 1152 } 1101 1153
Note: See TracChangeset
for help on using the changeset viewer.