Ignore:
Timestamp:
Nov 20, 2005 7:58:10 PM (18 years ago)
Author:
bennylp
Message:

More compliant URI parser, comparison, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_parser.c

    r54 r64  
    2424#include <pjsip/sip_transport.h>        /* rdata structure */ 
    2525#include <pjlib-util/scanner.h> 
     26#include <pjlib-util/string.h> 
    2627#include <pj/except.h> 
    2728#include <pj/log.h> 
     
    3334#include <pj/assert.h> 
    3435 
    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 
    4550 
    4651#define PJSIP_VERSION           "SIP/2.0" 
     
    9398            pjsip_PARAM_CHAR_SPEC,      /* For scanning pname (or pvalue when 
    9499                                         * it's not quoted.) */ 
     100            pjsip_HDR_CHAR_SPEC,        /* Chars in hname or hvalue */ 
    95101            pjsip_PROBE_USER_HOST_SPEC, /* Hostname characters. */ 
    96102            pjsip_PASSWD_SPEC,          /* Password. */ 
     
    110116                                     pj_str_t *pname,  
    111117                                     pj_str_t *pvalue); 
     118static void         int_parse_hparam( pj_scanner *scanner, 
     119                                      pj_str_t *hname, 
     120                                      pj_str_t *hvalue ); 
    112121static void         int_parse_req_line( pj_scanner *scanner,  
    113122                                        pj_pool_t *pool, 
     
    272281    pj_cis_add_str(&pjsip_PARAM_CHAR_SPEC, PARAM_CHAR); 
    273282 
     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 
    274287    status = pj_cis_dup(&pjsip_USER_SPEC, &pjsip_ALNUM_SPEC); 
    275288    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 ); 
    277290 
    278291    status = pj_cis_dup(&pjsip_PASSWD_SPEC, &pjsip_ALNUM_SPEC); 
     
    859872    /* pname */ 
    860873    pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pname); 
     874    pj_str_unescape(pname); 
    861875 
    862876    /* pvalue, if any */ 
     
    872886        } else { 
    873887            pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 
     888            pj_str_unescape(pvalue); 
    874889        } 
    875890    } else { 
     
    890905} 
    891906 
     907/* Parse header parameter. */ 
     908static 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 
    892929/* Parse host:port in URI. */ 
    893930static void int_parse_uri_host_port( pj_scanner *scanner,  
     
    895932{ 
    896933    pj_scan_get( scanner, &pjsip_HOST_SPEC, host); 
     934    /* RFC3261 section 19.1.2: host don't need to be unescaped */ 
    897935    if (*scanner->curptr == ':') { 
    898936        pj_str_t port; 
    899937        pj_scan_get_char(scanner); 
    900938        pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &port); 
     939        pj_str_unescape(&port); 
    901940        *p_port = pj_strtoul(&port); 
    902941    } else { 
     
    927966{ 
    928967    pj_scan_get( scanner, &pjsip_USER_SPEC, user); 
     968    pj_str_unescape(user); 
     969 
    929970    if ( *scanner->curptr == ':') { 
    930971        pj_scan_get_char( scanner ); 
    931972        pj_scan_get( scanner, &pjsip_PASSWD_SPEC, pass); 
     973        pj_str_unescape(pass); 
    932974    } else { 
    933975        pass->ptr = NULL; 
     
    945987    pjsip_uri *uri; 
    946988    int is_name_addr = 0; 
     989 
     990    /* Exhaust any whitespaces. */ 
     991    pj_scan_skip_whitespace(scanner); 
    947992 
    948993    if (*scanner->curptr=='"' || *scanner->curptr=='<') { 
     
    10351080    int colon; 
    10361081    int skip_ws = scanner->skip_ws; 
     1082    int hsep = '?'; 
    10371083    scanner->skip_ws = 0; 
    10381084 
     
    10901136 
    10911137        } 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); 
    10931142        } 
    10941143    } 
    10951144 
    10961145    /* 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, &param->name, &param->value); 
     1150        pj_list_insert_before(&url->header_param, param); 
     1151        hsep = '&'; 
    11001152    } 
    11011153 
Note: See TracChangeset for help on using the changeset viewer.