Changeset 606 for pjproject


Ignore:
Timestamp:
Jul 17, 2006 10:04:12 AM (18 years ago)
Author:
bennylp
Message:

Fixed bugs with the parsing (re: allowable chars): (1) Parameters in URI and header should have different spec. URI should use paramchar spec while header should use token spec (thanks Jeroen van Bemmel) (2) The same rule applies when escaping the parameters during printing process (3) While we're on it, also fixed the tel-URI parser to automatically unescape the parameter values.

Location:
pjproject/trunk/pjsip
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_parser.h

    r583 r606  
    315315    pjsip_HEX_SPEC,             /**< Hexadecimal digits. */ 
    316316    pjsip_PARAM_CHAR_SPEC,      /**< For scanning pname (or pvalue when it's  
    317                                      not quoted.) */ 
     317                                     not quoted.) in URI */ 
    318318    pjsip_PARAM_CHAR_SPEC_ESC,  /**< Variant without the escape ('%') char */ 
    319319    pjsip_HDR_CHAR_SPEC,        /**< Chars in hname/havalue in URL. */ 
     
    357357}; 
    358358 
     359/* Parse parameter in header (matching the character as token) */ 
    359360void pjsip_parse_param_imp(  pj_scanner *scanner, pj_pool_t *pool, 
    360361                             pj_str_t *pname, pj_str_t *pvalue, 
    361362                             unsigned opt); 
     363/* Parse parameter in URL (matching the character as paramchar) */ 
     364void pjsip_parse_uri_param_imp(  pj_scanner *scanner, pj_pool_t *pool, 
     365                                 pj_str_t *pname, pj_str_t *pvalue, 
     366                                 unsigned opt); 
    362367void pjsip_concat_param_imp( pj_str_t *param, pj_pool_t *pool,  
    363                          const pj_str_t *pname, const pj_str_t *pvalue, int sepchar); 
     368                             const pj_str_t *pname, const pj_str_t *pvalue,  
     369                             int sepchar); 
    364370void pjsip_parse_end_hdr_imp ( pj_scanner *scanner ); 
    365371 
  • pjproject/trunk/pjsip/src/pjsip-simple/evsub_msg.c

    r197 r606  
    7171     
    7272    printed = pjsip_param_print_on(&hdr->other_param, p, endbuf-p, 
    73                                    &pjsip_PARAM_CHAR_SPEC,  
    74                                    &pjsip_PARAM_CHAR_SPEC, ';'); 
     73                                   &pjsip_TOKEN_SPEC,  
     74                                   &pjsip_TOKEN_SPEC, ';'); 
    7575    if (printed < 0) 
    7676        return printed; 
     
    181181     
    182182    printed = pjsip_param_print_on( &hdr->other_param, p, endbuf-p,  
    183                                     &pjsip_PARAM_CHAR_SPEC, 
    184                                     &pjsip_PARAM_CHAR_SPEC, 
     183                                    &pjsip_TOKEN_SPEC, 
     184                                    &pjsip_TOKEN_SPEC, 
    185185                                    ';'); 
    186186    if (printed < 0) 
  • pjproject/trunk/pjsip/src/pjsip/sip_auth_msg.c

    r82 r606  
    8282     
    8383    printed = pjsip_param_print_on(&cred->other_param, buf, endbuf-buf,  
    84                                    &pjsip_PARAM_CHAR_SPEC,  
    85                                    &pjsip_PARAM_CHAR_SPEC, ','); 
     84                                   &pjsip_TOKEN_SPEC,  
     85                                   &pjsip_TOKEN_SPEC, ','); 
    8686    if (printed < 0) 
    8787        return -1; 
     
    236236     
    237237    printed = pjsip_param_print_on(&chal->other_param, buf, endbuf-buf,  
    238                                    &pjsip_PARAM_CHAR_SPEC,  
    239                                    &pjsip_PARAM_CHAR_SPEC, ','); 
     238                                   &pjsip_TOKEN_SPEC,  
     239                                   &pjsip_TOKEN_SPEC, ','); 
    240240    if (printed < 0) 
    241241        return -1; 
  • pjproject/trunk/pjsip/src/pjsip/sip_msg.c

    r583 r606  
    10401040 
    10411041        printed = pjsip_param_print_on(&hdr->other_param, buf, endbuf-buf, 
    1042                                        &pjsip_PARAM_CHAR_SPEC, 
    1043                                        &pjsip_PARAM_CHAR_SPEC, ';'); 
     1042                                       &pjsip_TOKEN_SPEC, &pjsip_TOKEN_SPEC,  
     1043                                       ';'); 
    10441044        if (printed < 0) 
    10451045            return printed; 
     
    12831283 
    12841284    printed = pjsip_param_print_on(&hdr->other_param, buf, endbuf-buf,  
    1285                                    &pjsip_PARAM_CHAR_SPEC, 
    1286                                    &pjsip_PARAM_CHAR_SPEC, ';'); 
     1285                                   &pjsip_TOKEN_SPEC, 
     1286                                   &pjsip_TOKEN_SPEC, ';'); 
    12871287    if (printed < 0) 
    12881288        return -1; 
     
    14541454 
    14551455    printed = pjsip_param_print_on(&hdr->other_param, buf, endbuf-buf,  
    1456                                    &pjsip_PARAM_CHAR_SPEC,  
    1457                                    &pjsip_PARAM_CHAR_SPEC, ';'); 
     1456                                   &pjsip_TOKEN_SPEC,  
     1457                                   &pjsip_TOKEN_SPEC, ';'); 
    14581458    if (printed < 0) 
    14591459        return -1; 
     
    16731673     
    16741674    printed = pjsip_param_print_on(&hdr->other_param, buf, endbuf-buf,  
    1675                                    &pjsip_PARAM_CHAR_SPEC, 
    1676                                    &pjsip_PARAM_CHAR_SPEC, ';'); 
     1675                                   &pjsip_TOKEN_SPEC, 
     1676                                   &pjsip_TOKEN_SPEC, ';'); 
    16771677    if (printed < 0) 
    16781678        return -1; 
  • pjproject/trunk/pjsip/src/pjsip/sip_parser.c

    r587 r606  
    4141#define USER_UNRESERVED     "&=+$,;?/" 
    4242#define PASS                "&=+$," 
    43 #define TOKEN               "-.!%*_=`'~+"   /* '+' is because of app/pidf+xml 
    44                                              * in Content-Type! */ 
     43#define TOKEN               "-.!%*_`'~+"   /* '=' was removed for parsing  
     44                                            * param */ 
    4545#define HOST                "_-." 
    4646#define HEX_DIGIT           "abcdefABCDEF" 
     
    139139                                     pj_str_t *pname,  
    140140                                     pj_str_t *pvalue); 
     141static void         int_parse_uri_param( pj_scanner *scanner,  
     142                                         pj_pool_t *pool, 
     143                                         pj_str_t *pname,  
     144                                         pj_str_t *pvalue); 
    141145static void         int_parse_hparam( pj_scanner *scanner, 
    142146                                      pj_pool_t *pool, 
     
    325329    pj_cis_add_str( &pjsip_TOKEN_SPEC, TOKEN); 
    326330 
     331    /* TOKEN must not have '%' */ 
     332    pj_assert(pj_cis_match(&pjsip_TOKEN_SPEC, '%')==0); 
     333 
    327334    status = pj_cis_dup(&pjsip_HOST_SPEC, &pjsip_ALNUM_SPEC); 
    328335    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     
    10391046} 
    10401047 
     1048 
    10411049/* Parse parameter (pname ["=" pvalue]). */ 
    1042 void pjsip_parse_param_imp( pj_scanner *scanner, pj_pool_t *pool, 
     1050static void parse_param_imp( pj_scanner *scanner, pj_pool_t *pool, 
    10431051                             pj_str_t *pname, pj_str_t *pvalue, 
     1052                             const pj_cis_t *spec, const pj_cis_t *esc_spec, 
    10441053                             unsigned option) 
    10451054{ 
    10461055    /* pname */ 
    1047     parser_get_and_unescape(scanner, pool, &pjsip_PARAM_CHAR_SPEC, 
    1048                             &pjsip_PARAM_CHAR_SPEC_ESC, pname); 
     1056    parser_get_and_unescape(scanner, pool, spec, esc_spec, pname); 
    10491057 
    10501058    /* init pvalue */ 
     
    10631071                    pvalue->slen -= 2; 
    10641072                } 
    1065             } else if(pj_cis_match(&pjsip_PARAM_CHAR_SPEC, *scanner->curptr)) { 
    1066                 parser_get_and_unescape(scanner, pool, &pjsip_PARAM_CHAR_SPEC,  
    1067                                         &pjsip_PARAM_CHAR_SPEC_ESC, pvalue); 
     1073            } else if(pj_cis_match(spec, *scanner->curptr)) { 
     1074                parser_get_and_unescape(scanner, pool, spec, esc_spec, pvalue); 
    10681075            } 
    10691076        } 
     
    10711078} 
    10721079 
    1073 /* Parse parameter (";" pname ["=" pvalue]). */ 
     1080/* Parse parameter (pname ["=" pvalue]) using token. */ 
     1081void pjsip_parse_param_imp(  pj_scanner *scanner, pj_pool_t *pool, 
     1082                             pj_str_t *pname, pj_str_t *pvalue, 
     1083                             unsigned option) 
     1084{ 
     1085    parse_param_imp(scanner, pool, pname, pvalue, &pjsip_TOKEN_SPEC, 
     1086                    &pjsip_TOKEN_SPEC, option); 
     1087} 
     1088 
     1089 
     1090/* Parse parameter (pname ["=" pvalue]) using paramchar. */ 
     1091void pjsip_parse_uri_param_imp(pj_scanner *scanner, pj_pool_t *pool, 
     1092                               pj_str_t *pname, pj_str_t *pvalue, 
     1093                               unsigned option) 
     1094{ 
     1095    parse_param_imp(scanner, pool, pname, pvalue, &pjsip_PARAM_CHAR_SPEC, 
     1096                    &pjsip_PARAM_CHAR_SPEC_ESC, option); 
     1097} 
     1098 
     1099 
     1100/* Parse parameter (";" pname ["=" pvalue]) in header. */ 
    10741101static void int_parse_param( pj_scanner *scanner, pj_pool_t *pool, 
    10751102                             pj_str_t *pname, pj_str_t *pvalue) 
     
    10821109                          PJSIP_PARSE_REMOVE_QUOTE); 
    10831110} 
     1111 
     1112/* Parse parameter (";" pname ["=" pvalue]) in URI. */ 
     1113static void int_parse_uri_param( pj_scanner *scanner, pj_pool_t *pool, 
     1114                                 pj_str_t *pname, pj_str_t *pvalue) 
     1115{ 
     1116    /* Get ';' character */ 
     1117    pj_scan_get_char(scanner); 
     1118 
     1119    /* Get pname and optionally pvalue */ 
     1120    pjsip_parse_uri_param_imp(scanner, pool, pname, pvalue,  
     1121                              PJSIP_PARSE_REMOVE_QUOTE); 
     1122} 
     1123 
    10841124 
    10851125/* Parse header parameter. */ 
     
    12981338        pj_str_t pname, pvalue; 
    12991339 
    1300         int_parse_param( scanner, pool, &pname, &pvalue); 
     1340        int_parse_uri_param( scanner, pool, &pname, &pvalue); 
    13011341 
    13021342        if (!parser_stricmp(pname, pjsip_USER_STR) && pvalue.slen) { 
  • pjproject/trunk/pjsip/src/pjsip/sip_tel_uri.c

    r583 r606  
    5656static pj_cis_t pjsip_TEL_PNAME_SPEC; 
    5757static pj_cis_t pjsip_TEL_PVALUE_SPEC; 
     58static pj_cis_t pjsip_TEL_PVALUE_SPEC_ESC; 
    5859static pj_cis_t pjsip_TEL_PARSING_PVALUE_SPEC; 
     60static pj_cis_t pjsip_TEL_PARSING_PVALUE_SPEC_ESC; 
    5961 
    6062static pj_str_t pjsip_ISUB_STR = { "isub", 4 }; 
     
    153155    pj_cis_add_str(&pjsip_TEL_PVALUE_SPEC, PARAM_CHAR); 
    154156 
     157    status = pj_cis_dup(&pjsip_TEL_PVALUE_SPEC_ESC, &pjsip_TEL_PVALUE_SPEC); 
     158    pj_cis_del_str(&pjsip_TEL_PVALUE_SPEC_ESC, "%"); 
     159 
    155160    status = pj_cis_dup(&pjsip_TEL_PARSING_PVALUE_SPEC, &pjsip_TEL_URIC_SPEC); 
    156161    PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 
    157162    pj_cis_add_cis(&pjsip_TEL_PARSING_PVALUE_SPEC, &pjsip_TEL_PVALUE_SPEC); 
    158163    pj_cis_add_str(&pjsip_TEL_PARSING_PVALUE_SPEC, "="); 
     164 
     165    status = pj_cis_dup(&pjsip_TEL_PARSING_PVALUE_SPEC_ESC,  
     166                        &pjsip_TEL_PARSING_PVALUE_SPEC); 
     167    pj_cis_del_str(&pjsip_TEL_PVALUE_SPEC_ESC, "%"); 
    159168 
    160169    status = pjsip_register_uri_parser("tel", &tel_uri_parse); 
     
    394403            if (*scanner->curptr == '=') { 
    395404                pj_scan_get_char(scanner); 
    396                 pj_scan_get(scanner, &pjsip_TEL_PARSING_PVALUE_SPEC, &pvalue); 
     405 
     406#               if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0 
     407                    pj_scan_get_unescape( scanner,  
     408                                          &pjsip_TEL_PARSING_PVALUE_SPEC_ESC, 
     409                                          &pvalue); 
     410#               else 
     411                    pj_scan_get(scanner, &pjsip_TEL_PARSING_PVALUE_SPEC,  
     412                                &pvalue); 
     413                    *token = pj_str_unescape(pool, &pvalue); 
     414#               endif 
     415 
    397416            } else { 
    398417                pvalue.slen = 0; 
Note: See TracChangeset for help on using the changeset viewer.