Changeset 64


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

More compliant URI parser, comparison, etc.

Location:
pjproject/trunk/pjsip
Files:
1 added
24 edited
4 moved

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/build/pjsip.dsw

    r60 r64  
    5858############################################################################### 
    5959 
    60 Project: "test_pjsip"=.\test_pjsip.dsp - Package Owner=<4> 
    61  
    62 Package=<5> 
    63 {{{ 
    64 }}} 
    65  
    66 Package=<4> 
    67 {{{ 
    68 }}} 
    69  
    70 ############################################################################### 
    71  
    7260Project: "pjsip_ua"=.\pjsip_ua.dsp - Package Owner=<4> 
    7361 
     
    10997############################################################################### 
    11098 
     99Project: "test_pjsip"=.\test_pjsip.dsp - Package Owner=<4> 
     100 
     101Package=<5> 
     102{{{ 
     103}}} 
     104 
     105Package=<4> 
     106{{{ 
     107    Begin Project Dependency 
     108    Project_Dep_Name pjlib 
     109    End Project Dependency 
     110    Begin Project Dependency 
     111    Project_Dep_Name pjsip_core 
     112    End Project Dependency 
     113}}} 
     114 
     115############################################################################### 
     116 
    111117Global: 
    112118 
  • pjproject/trunk/pjsip/build/pjsip_core.dsp

    r58 r64  
    104104# Begin Source File 
    105105 
    106 SOURCE=..\src\pjsip\sip_misc.c 
     106SOURCE=..\src\pjsip\sip_errno.c 
    107107# End Source File 
    108108# Begin Source File 
     
    133133 
    134134SOURCE=..\src\pjsip\sip_uri.c 
     135# End Source File 
     136# Begin Source File 
     137 
     138SOURCE=..\src\pjsip\sip_util.c 
    135139# End Source File 
    136140# End Group 
     
    176180# Begin Source File 
    177181 
    178 SOURCE=..\include\pjsip\sip_misc.h 
    179 # End Source File 
    180 # Begin Source File 
    181  
    182182SOURCE=..\include\pjsip\sip_module.h 
    183183# End Source File 
     
    217217 
    218218SOURCE=..\include\pjsip\sip_uri.h 
     219# End Source File 
     220# Begin Source File 
     221 
     222SOURCE=..\include\pjsip\sip_util.h 
    219223# End Source File 
    220224# End Group 
  • pjproject/trunk/pjsip/build/test_pjsip.dsp

    r60 r64  
    5252LINK32=link.exe 
    5353# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 
    54 # ADD LINK32 wsock32.lib kernel32.lib netapi32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /map /debug /machine:I386 /out:"..\bin\test-pjsip-i386-win32-vc6-release.exe" 
     54# ADD LINK32 dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib netapi32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /map /debug /machine:I386 /out:"..\bin\test-pjsip-i386-win32-vc6-release.exe" 
    5555 
    5656!ELSEIF  "$(CFG)" == "test_pjsip - Win32 Debug" 
     
    7777LINK32=link.exe 
    7878# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 
    79 # ADD LINK32 wsock32.lib kernel32.lib netapi32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"..\bin\test-pjsip-i386-win32-vc6-debug.exe" /pdbtype:sept 
     79# ADD LINK32 dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib netapi32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"..\bin\test-pjsip-i386-win32-vc6-debug.exe" /pdbtype:sept 
    8080 
    8181!ENDIF  
     
    9494# Begin Source File 
    9595 
    96 SOURCE="..\src\test-pjsip\test_msg.c" 
     96SOURCE="..\src\test-pjsip\msg.c" 
    9797# End Source File 
    9898# Begin Source File 
    9999 
    100 SOURCE="..\src\test-pjsip\test_uri.c" 
     100SOURCE="..\src\test-pjsip\test.c" 
     101# End Source File 
     102# Begin Source File 
     103 
     104SOURCE="..\src\test-pjsip\uri.c" 
    101105# End Source File 
    102106# End Group 
  • pjproject/trunk/pjsip/include/pjsip/print_util.h

    r60 r64  
    2020#define __PJSIP_PRINT_H__ 
    2121 
     22/* Minimum space left in the buffer */ 
     23#define MIN_SPACE       10 
     24 
    2225#define copy_advance_check(buf,str)   \ 
    2326        do { \ 
    24             if ((str).slen+10 >= (endbuf-buf)) return -1;       \ 
     27            if ((str).slen+MIN_SPACE >= (endbuf-buf)) return -1;        \ 
    2528            pj_memcpy(buf, (str).ptr, (str).slen); \ 
    2629            buf += (str).slen; \ 
     
    3235    if (str2->slen) { 
    3336        int printed = len1+str2->slen; 
    34         if (printed+10 >= (endbuf-buf)) return NULL; 
     37        if (printed+MIN_SPACE >= (endbuf-buf)) return NULL; 
    3538        pj_memcpy(buf,str1,len1); 
    3639        pj_memcpy(buf+len1, str2->ptr, str2->slen); 
     
    4548            if (str2.slen) { \ 
    4649                printed = len1+str2.slen; \ 
    47                 if (printed+10 >= (endbuf-buf)) return -1;      \ 
     50                if (printed+MIN_SPACE >= (endbuf-buf)) return -1;       \ 
    4851                pj_memcpy(buf,str1,len1); \ 
    4952                pj_memcpy(buf+len1, str2.ptr, str2.slen); \ 
     
    6366            if (str2.slen) { \ 
    6467                printed = len1+str2.slen+2; \ 
    65                 if (printed+10 >= (endbuf-buf)) return -1;      \ 
     68                if (printed+MIN_SPACE >= (endbuf-buf)) return -1;       \ 
    6669                pj_memcpy(buf,str1,len1); \ 
    6770                *(buf+len1)=quotebegin; \ 
     
    7275        } while (0) 
    7376 
     77#define copy_advance_pair_escape(buf,str1,len1,str2,unres)      \ 
     78        do { \ 
     79            if (str2.slen) { \ 
     80                pj_ssize_t esc_len; \ 
     81                if (len1+str2.slen+MIN_SPACE >= (endbuf-buf)) return -1; \ 
     82                pj_memcpy(buf,str1,len1); \ 
     83                buf += len1; \ 
     84                esc_len=pj_strncpy2_escape(buf, &str2, (endbuf-buf), &unres); \ 
     85                if (esc_len < 0) return -1; \ 
     86                buf += esc_len; \ 
     87                if (endbuf-buf < MIN_SPACE) return -1; \ 
     88            } \ 
     89        } while (0) 
     90 
     91 
    7492#define copy_advance_no_check(buf,str)   \ 
    75         pj_memcpy(buf, (str).ptr, (str).slen); \ 
    76         buf += (str).slen; 
     93        do { \ 
     94            pj_memcpy(buf, (str).ptr, (str).slen); \ 
     95            buf += (str).slen; \ 
     96        } while (0) 
     97 
     98#define copy_advance_escape(buf,str,unres)    \ 
     99        do { \ 
     100            pj_ssize_t len = \ 
     101                pj_strncpy2_escape(buf, &(str), (endbuf-buf), &(unres)); \ 
     102            if (len < 0) return -1; \ 
     103            buf += len; \ 
     104            if (endbuf-buf < MIN_SPACE) return -1; \ 
     105        } while (0) 
    77106 
    78107#define copy_advance_pair_no_check(buf,str1,len1,str2)   \ 
  • pjproject/trunk/pjsip/include/pjsip/sip_errno.h

    r60 r64  
    2222#include <pj/errno.h> 
    2323 
     24PJ_BEGIN_DECL 
     25 
     26/* 
     27 * PJSIP error codes occupies 170000 - 219000, and mapped as follows: 
     28 *  - 170100 - 170799: mapped to SIP status code in response msg. 
     29 *  - 171000 - 171999: mapped to errors generated from PJSIP core. 
     30 */ 
     31 
     32/** 
     33 * Get error message for the specified error code. 
     34 * 
     35 * @param status    The error code. 
     36 * @param buffer    The buffer where to put the error message. 
     37 * @param bufsize   Size of the buffer. 
     38 * 
     39 * @return          The error message as NULL terminated string, 
     40 *                  wrapped with pj_str_t. 
     41 */ 
     42PJ_DECL(pj_str_t) pjsip_strerror( pj_status_t status, char *buffer, 
     43                                  pj_size_t bufsize); 
     44 
    2445/** 
    2546 * Start of error code relative to PJ_ERRNO_START_USER. 
    2647 */ 
    27 #define PJSIP_ERRNO_START       (PJ_ERRNO_START_USER+10000) 
     48#define PJSIP_ERRNO_START       (PJ_ERRNO_START_USER) 
    2849 
    2950/** 
     
    4465#define PJSIP_ERRNO_TO_SIP_STATUS(status)               \ 
    4566         ((status>=PJSIP_ERRNO_FROM_SIP_STATUS(100) &&  \ 
    46            status<PJSIP_ERRNO_FROM_SIP_STATUS(999)) ?   \ 
     67           status<PJSIP_ERRNO_FROM_SIP_STATUS(800)) ?   \ 
    4768          status-PJSIP_ERRNO_FROM_SIP_STATUS(0) : 599) 
    4869 
     
    5172 * Start of PJSIP generated error code values. 
    5273 */ 
    53 #define PJSIP_ERRNO_START_PJSIP (PJSIP_ERRNO_START + 10000) 
    54  
     74#define PJSIP_ERRNO_START_PJSIP (PJSIP_ERRNO_START + 1000) 
     75 
     76/************************************************************ 
     77 * GENERIC SIP ERRORS 
     78 ***********************************************************/ 
     79/** 
     80 * @hideinitializer 
     81 * SIP object is busy. 
     82 */ 
     83#define PJSIP_EBUSY             (PJSIP_ERRNO_START_PJSIP + 1)   /* 171001 */ 
     84/** 
     85 * @hideinitializer 
     86 * SIP object with the same type already exists. 
     87 */ 
     88#define PJSIP_ETYPEEXISTS       (PJSIP_ERRNO_START_PJSIP + 2)   /* 171002 */ 
     89 
     90 
     91/************************************************************ 
     92 * MESSAGING ERRORS 
     93 ***********************************************************/ 
    5594/** 
    5695 * @hideinitializer 
    5796 * Invalid message (syntax error) 
    5897 */ 
    59 #define PJSIP_EINVALIDMSG       (PJSIP_ERRNO_START_PJSIP + 0) 
     98#define PJSIP_EINVALIDMSG       (PJSIP_ERRNO_START_PJSIP + 20)  /* 171020 */ 
     99/** 
     100 * @hideinitializer 
     101 * Unsupported URL scheme. 
     102 */ 
     103#define PJSIP_EINVALIDSCHEME    (PJSIP_ERRNO_START_PJSIP + 21)  /* 171021 */ 
     104/** 
     105 * @hideinitializer 
     106 * Message too long. See also PJSIP_ERXOVERFLOW. 
     107 */ 
     108#define PJSIP_EMSGTOOLONG       (PJSIP_ERRNO_START_PJSIP + 22)  /* 171022 */ 
     109/** 
     110 * @hideinitializer 
     111 * Message not completely received. 
     112 */ 
     113#define PJSIP_EPARTIALMSG       (PJSIP_ERRNO_START_PJSIP + 23)  /* 171023 */ 
    60114/** 
    61115 * @hideinitializer 
    62116 * Missing required header(s). 
    63117 */ 
    64 #define PJSIP_EMISSINGHDR       (PJSIP_ERRNO_START_PJSIP + 1) 
    65 /** 
    66  * @hideinitializer 
    67  * Unsupported URL scheme. 
    68  */ 
    69 #define PJSIP_EINVALIDSCHEME    (PJSIP_ERRNO_START_PJSIP + 2) 
     118#define PJSIP_EMISSINGHDR       (PJSIP_ERRNO_START_PJSIP + 24)  /* 171024 */ 
     119/** 
     120 * @hideinitializer 
     121 * Invalid Via header in response (sent-by, etc). 
     122 */ 
     123#define PJSIP_EINVALIDVIA       (PJSIP_ERRNO_START_PJSIP + 25)  /* 171025 */ 
     124/** 
     125 * @hideinitializer 
     126 * Multiple Via headers in response. 
     127 */ 
     128#define PJSIP_EMULTIPLEVIA      (PJSIP_ERRNO_START_PJSIP + 26)  /* 171026 */ 
     129 
     130/************************************************************ 
     131 * TRANSPORT ERRORS 
     132 ***********************************************************/ 
     133/** 
     134 * @hideinitializer 
     135 * Unsupported transport type. 
     136 */ 
     137#define PJSIP_EUNSUPTRANSPORT   (PJSIP_ERRNO_START_PJSIP + 40)  /* 171040 */ 
     138/** 
     139 * @hideinitializer 
     140 * Buffer is being sent, operation still pending. 
     141 */ 
     142#define PJSIP_EPENDINGTX        (PJSIP_ERRNO_START_PJSIP + 41)  /* 171041 */ 
     143/** 
     144 * @hideinitializer 
     145 * Rx buffer overflow. See also PJSIP_EMSGTOOLONG. 
     146 */ 
     147#define PJSIP_ERXOVERFLOW         (PJSIP_ERRNO_START_PJSIP + 42)/* 171042 */ 
     148 
     149 
     150/************************************************************ 
     151 * TRANSACTION ERRORS 
     152 ***********************************************************/ 
    70153/** 
    71154 * @hideinitializer 
    72155 * Transaction has just been destroyed. 
    73156 */ 
    74 #define PJSIP_ETSXDESTROYED     (PJSIP_ERRNO_START_PJSIP + 3) 
    75 /** 
    76  * @hideinitializer 
    77  * Buffer overflow. See also PJSIP_EMSGTOOLONG. 
    78  */ 
    79 #define PJSIP_EOVERFLOW         (PJSIP_ERRNO_START_PJSIP + 4) 
    80 /** 
    81  * @hideinitializer 
    82  * Message not completely received. 
    83  */ 
    84 #define PJSIP_EPARTIALMSG       (PJSIP_ERRNO_START_PJSIP + 5) 
    85 /** 
    86  * @hideinitializer 
    87  * Message too long. See also PJSIP_EOVERFLOW. 
    88  */ 
    89 #define PJSIP_EMSGTOOLONG       (PJSIP_ERRNO_START_PJSIP + 6) 
    90 /** 
    91  * @hideinitializer 
    92  * Buffer is being sent, operation still pending. 
    93  */ 
    94 #define PJSIP_EPENDINGTX        (PJSIP_ERRNO_START_PJSIP + 7) 
    95 /** 
    96  * @hideinitializer 
    97  * Unsupported transport type. 
    98  */ 
    99 #define PJSIP_EUNSUPTRANSPORT   (PJSIP_ERRNO_START_PJSIP + 8) 
    100 /** 
    101  * @hideinitializer 
    102  * Invalid Via header in response (sent-by, etc). 
    103  */ 
    104 #define PJSIP_EINVALIDVIA       (PJSIP_ERRNO_START_PJSIP + 9) 
    105 /** 
    106  * @hideinitializer 
    107  * Multiple Via headers in response. 
    108  */ 
    109 #define PJSIP_EMULTIPLEVIA      (PJSIP_ERRNO_START_PJSIP + 9) 
    110 /** 
    111  * @hideinitializer 
    112  * SIP object is busy. 
    113  */ 
    114 #define PJSIP_EBUSY             (PJSIP_ERRNO_START_PJSIP + 10) 
    115 /** 
    116  * @hideinitializer 
    117  * SIP object with the same type already exists. 
    118  */ 
    119 #define PJSIP_ETYPEEXISTS       (PJSIP_ERRNO_START_PJSIP + 11) 
    120  
    121  
     157#define PJSIP_ETSXDESTROYED     (PJSIP_ERRNO_START_PJSIP + 60)  /* 171060 */ 
     158 
     159 
     160/************************************************************ 
     161 * URI COMPARISON RESULTS 
     162 ***********************************************************/ 
     163/** 
     164 * @hideinitializer 
     165 * Scheme mismatch. 
     166 */ 
     167#define PJSIP_ECMPSCHEME        (PJSIP_ERRNO_START_PJSIP + 80)  /* 171080 */ 
     168/** 
     169 * @hideinitializer 
     170 * User part mismatch. 
     171 */ 
     172#define PJSIP_ECMPUSER          (PJSIP_ERRNO_START_PJSIP + 81)  /* 171081 */ 
     173/** 
     174 * @hideinitializer 
     175 * Password part mismatch. 
     176 */ 
     177#define PJSIP_ECMPPASSWD        (PJSIP_ERRNO_START_PJSIP + 82)  /* 171082 */ 
     178/** 
     179 * @hideinitializer 
     180 * Host part mismatch. 
     181 */ 
     182#define PJSIP_ECMPHOST          (PJSIP_ERRNO_START_PJSIP + 83)  /* 171083 */ 
     183/** 
     184 * @hideinitializer 
     185 * Port part mismatch. 
     186 */ 
     187#define PJSIP_ECMPPORT          (PJSIP_ERRNO_START_PJSIP + 84)  /* 171084 */ 
     188/** 
     189 * @hideinitializer 
     190 * Transport parameter part mismatch. 
     191 */ 
     192#define PJSIP_ECMPTRANSPORTPRM  (PJSIP_ERRNO_START_PJSIP + 85)  /* 171085 */ 
     193/** 
     194 * @hideinitializer 
     195 * TTL parameter part mismatch. 
     196 */ 
     197#define PJSIP_ECMPTTLPARAM      (PJSIP_ERRNO_START_PJSIP + 86)  /* 171086 */ 
     198/** 
     199 * @hideinitializer 
     200 * User parameter part mismatch. 
     201 */ 
     202#define PJSIP_ECMPUSERPARAM     (PJSIP_ERRNO_START_PJSIP + 87)  /* 171087 */ 
     203/** 
     204 * @hideinitializer 
     205 * Method parameter part mismatch. 
     206 */ 
     207#define PJSIP_ECMPMETHODPARAM   (PJSIP_ERRNO_START_PJSIP + 88)  /* 171088 */ 
     208/** 
     209 * @hideinitializer 
     210 * Maddr parameter part mismatch. 
     211 */ 
     212#define PJSIP_ECMPMADDRPARAM    (PJSIP_ERRNO_START_PJSIP + 89)  /* 171089 */ 
     213/** 
     214 * @hideinitializer 
     215 * Parameter part in other_param mismatch. 
     216 */ 
     217#define PJSIP_ECMPOTHERPARAM    (PJSIP_ERRNO_START_PJSIP + 90)  /* 171090 */ 
     218/** 
     219 * @hideinitializer 
     220 * Parameter part in header_param mismatch. 
     221 */ 
     222#define PJSIP_ECMPHEADERPARAM   (PJSIP_ERRNO_START_PJSIP + 91)  /* 171091 */ 
     223 
     224 
     225 
     226PJ_END_DECL 
    122227 
    123228#endif  /* __PJSIP_SIP_ERRNO_H__ */ 
  • pjproject/trunk/pjsip/include/pjsip/sip_event.h

    r60 r64  
    298298 * Get the event string from the event ID. 
    299299 * @param e the event ID. 
    300  * @notes defined in sip_misc.c 
     300 * @notes defined in sip_util.c 
    301301 */ 
    302302PJ_DEF(const char *) pjsip_event_str(pjsip_event_id_e e); 
  • pjproject/trunk/pjsip/include/pjsip/sip_parser.h

    r60 r64  
    295295 * parsers. 
    296296 */ 
    297 extern 
    298 pj_cis_t        pjsip_HOST_SPEC,            /* For scanning host part. */ 
    299                 pjsip_DIGIT_SPEC,           /* Decimal digits */ 
    300                 pjsip_ALPHA_SPEC,           /* Alpha (A-Z, a-z) */ 
    301                 pjsip_ALNUM_SPEC,           /* Decimal + Alpha. */ 
    302                 pjsip_TOKEN_SPEC,           /* Token. */ 
    303                 pjsip_HEX_SPEC,             /* Hexadecimal digits. */ 
    304                 pjsip_PARAM_CHAR_SPEC,      /* For scanning pname (or pvalue when it's not quoted.) */ 
    305                 pjsip_PROBE_USER_HOST_SPEC, /* Hostname characters. */ 
    306                 pjsip_PASSWD_SPEC,          /* Password. */ 
    307                 pjsip_USER_SPEC,            /* User */ 
    308                 pjsip_NEWLINE_OR_EOF_SPEC,  /* For eating up header.*/ 
    309                 pjsip_DISPLAY_SCAN_SPEC;    /* Used when searching for display name in URL. */ 
     297extern pj_cis_t     
     298    pjsip_HOST_SPEC,            /**< For scanning host part. */ 
     299    pjsip_DIGIT_SPEC,           /**< Decimal digits */ 
     300    pjsip_ALPHA_SPEC,           /**< Alpha (A-Z, a-z) */ 
     301    pjsip_ALNUM_SPEC,           /**< Decimal + Alpha. */ 
     302    pjsip_TOKEN_SPEC,           /**< Token. */ 
     303    pjsip_HEX_SPEC,             /**< Hexadecimal digits. */ 
     304    pjsip_PARAM_CHAR_SPEC,      /**< For scanning pname (or pvalue when it's  
     305                                     not quoted.) */ 
     306    pjsip_HDR_CHAR_SPEC,        /**< Chars in hname/havalue in URL. */ 
     307    pjsip_PROBE_USER_HOST_SPEC, /**< Hostname characters. */ 
     308    pjsip_PASSWD_SPEC,          /**< Password. */ 
     309    pjsip_USER_SPEC,            /**< User */ 
     310    pjsip_NEWLINE_OR_EOF_SPEC,  /**< For eating up header.*/ 
     311    pjsip_DISPLAY_SCAN_SPEC;    /**< Used when searching for display name. */ 
    310312 
    311313/* 
  • pjproject/trunk/pjsip/include/pjsip/sip_transaction.h

    r60 r64  
    130130 
    131131 
     132/** 
     133 * Create new transaction. Application would normally use  
     134 * #pjsip_endpt_create_tsx rather than this function. 
     135 * 
     136 * @param pool      Pool to use by the transaction. 
     137 * @param endpt     Endpoint. 
     138 * @param p_tsx     Pointer to return the transaction. 
     139 * 
     140 * @return          PJ_SUCCESS or the appropriate error code. 
     141 * 
     142 * @see pjsip_endpt_create_tsx 
     143 * 
     144 */ 
     145PJ_DEF(pj_status_t) pjsip_tsx_create( pj_pool_t *pool, 
     146                                      pjsip_endpoint *endpt, 
     147                                      pjsip_transaction **p_tsx); 
     148 
    132149/**  
    133150 * Init transaction as UAC from the specified transmit data (\c tdata). 
  • pjproject/trunk/pjsip/include/pjsip/sip_uri.h

    r60 r64  
    2727#include <pjsip/sip_types.h> 
    2828#include <pjsip/sip_config.h> 
     29#include <pj/list.h> 
    2930 
    3031PJ_BEGIN_DECL 
     
    3738 * @{ 
    3839 */ 
     40 
     41/** 
     42 * Generic parameter, normally used in other_param or header_param. 
     43 */ 
     44typedef struct pjsip_param 
     45{ 
     46    PJ_DECL_LIST_MEMBER(struct pjsip_param);    /**< Generic list member.   */ 
     47    pj_str_t        name;                       /**< Param/header name.     */ 
     48    pj_str_t        value;                      /**< Param/header value.    */ 
     49} pjsip_param; 
     50 
     51 
     52/** 
     53 * Find the specified parameter name in the list. The name will be compared 
     54 * in case-insensitive comparison. 
     55 * 
     56 * @param param_list    List of parameters to find. 
     57 * @param name          Parameter/header name to find. 
     58 * 
     59 * @return              The parameter if found, or NULL. 
     60 */ 
     61PJ_DECL(pjsip_param*) pjsip_param_find( pjsip_param *param_list, 
     62                                        const pj_str_t *name ); 
     63 
     64 
     65/** 
     66 * Find the specified parameter name in the list. The name will be compared 
     67 * in case-insensitive comparison. 
     68 * 
     69 * @param param_list    List of parameters to find. 
     70 * @param name          Parameter/header name to find. 
     71 * 
     72 * @return              The parameter if found, or NULL. 
     73 */ 
     74PJ_DECL(const pjsip_param*) pjsip_param_cfind(const pjsip_param *param_list, 
     75                                              const pj_str_t *name ); 
     76 
     77 
     78/** 
     79 * Duplicate the parameters. 
     80 * 
     81 * @param pool          Pool to allocate memory from. 
     82 * @param dst_list      Destination list. 
     83 * @param src_list      Source list. 
     84 */ 
     85PJ_DECL(void) pjsip_param_clone(pj_pool_t *pool, pjsip_param *dst_list, 
     86                                const pjsip_param *src_list); 
    3987 
    4088/** 
     
    90138     * @param uri1 the first URI (self). 
    91139     * @param uri2 the second URI. 
    92      * @return zero if equal. 
    93      */ 
    94     int (*p_compare)(pjsip_uri_context_e context,  
    95                      const void *uri1, const void *uri2); 
     140     * @return PJ_SUCCESS if equal, or otherwise the error status which 
     141     *              should point to the mismatch part. 
     142     */ 
     143    pj_status_t (*p_compare)(pjsip_uri_context_e context,  
     144                             const void *uri1, const void *uri2); 
    96145 
    97146    /**  
     
    138187#define PJSIP_URI_SCHEME_IS_TEL(url)    \ 
    139188    (pj_strnicmp2(pjsip_uri_get_scheme(url), "tel", 3)==0) 
    140  
    141189 
    142190 
     
    157205    int             lr_param;           /**< Optional loose routing param, or zero */ 
    158206    pj_str_t        maddr_param;        /**< Optional maddr param */ 
    159     pj_str_t        other_param;        /**< Other parameters grouped together. */ 
    160     pj_str_t        header_param;       /**< Optional header parameter. */ 
     207    pjsip_param     other_param;        /**< Other parameters grouped together. */ 
     208    pjsip_param     header_param;       /**< Optional header parameter. */ 
    161209} pjsip_url; 
    162210 
     
    208256 * @param uri1      The first URI. 
    209257 * @param uri2      The second URI. 
    210  * @return          Zero if equal. 
    211  */ 
    212 PJ_INLINE(int) pjsip_uri_cmp(pjsip_uri_context_e context,  
    213                              const void *uri1, const void *uri2) 
     258 * @return          PJ_SUCCESS if equal, or otherwise the error status which 
     259 *                  should point to the mismatch part. 
     260 */ 
     261PJ_INLINE(pj_status_t) pjsip_uri_cmp(pjsip_uri_context_e context,  
     262                                     const void *uri1, const void *uri2) 
    214263{ 
    215264    return (*((const pjsip_uri*)uri1)->vptr->p_compare)(context, uri1, uri2); 
  • pjproject/trunk/pjsip/include/pjsip_core.h

    r51 r64  
    2121 
    2222#include <pjsip/sip_types.h> 
     23#include <pjsip/sip_auth.h> 
    2324#include <pjsip/sip_endpoint.h> 
     25#include <pjsip/sip_errno.h> 
    2426#include <pjsip/sip_event.h> 
    25 #include <pjsip/sip_misc.h> 
    2627#include <pjsip/sip_module.h> 
    2728#include <pjsip/sip_msg.h> 
     
    3132#include <pjsip/sip_transport.h> 
    3233#include <pjsip/sip_uri.h> 
    33 #include <pjsip/sip_auth.h> 
     34#include <pjsip/sip_util.h> 
    3435 
    3536#endif  /* __PJSIP_CORE_H__ */ 
  • pjproject/trunk/pjsip/src/pjsip-simple/event_notify.c

    r51 r64  
    1919#include <pjsip_simple/event_notify.h> 
    2020#include <pjsip/sip_msg.h> 
    21 #include <pjsip/sip_misc.h> 
     21#include <pjsip/sip_util.h> 
    2222#include <pjsip/sip_endpoint.h> 
    2323#include <pjsip/sip_module.h> 
  • pjproject/trunk/pjsip/src/pjsip-simple/messaging.c

    r51 r64  
    2323#include <pjsip/sip_event.h> 
    2424#include <pjsip/sip_module.h> 
    25 #include <pjsip/sip_misc.h> 
     25#include <pjsip/sip_util.h> 
    2626#include <pj/string.h> 
    2727#include <pj/pool.h> 
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_dialog.c

    r54 r64  
    2525#include <pjsip/sip_endpoint.h> 
    2626#include <pjsip/sip_uri.h> 
    27 #include <pjsip/sip_misc.h> 
     27#include <pjsip/sip_util.h> 
    2828#include <pjsip/sip_module.h> 
    2929#include <pjsip/sip_event.h> 
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c

    r51 r64  
    2323#include <pjsip/sip_transaction.h> 
    2424#include <pjsip/sip_event.h> 
    25 #include <pjsip/sip_misc.h> 
     25#include <pjsip/sip_util.h> 
    2626#include <pjsip/sip_auth_msg.h> 
    2727#include <pj/pool.h> 
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_ua.c

    r51 r64  
    2222#include <pjsip/sip_module.h> 
    2323#include <pjsip/sip_event.h> 
    24 #include <pjsip/sip_misc.h> 
     24#include <pjsip/sip_util.h> 
    2525#include <pjsip/sip_endpoint.h> 
    2626#include <pjsip/sip_transaction.h> 
  • pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c

    r57 r64  
    2323#include <pjsip/sip_resolve.h> 
    2424#include <pjsip/sip_module.h> 
    25 #include <pjsip/sip_misc.h> 
     25#include <pjsip/sip_util.h> 
    2626#include <pjsip/sip_errno.h> 
    2727#include <pj/except.h> 
     
    107107 
    108108/* 
    109  * Create transaction. 
    110  * Defined in sip_transaction.c 
    111  */ 
    112 pj_status_t pjsip_tsx_create( pj_pool_t *pool, pjsip_endpoint *endpt, 
    113                               pjsip_transaction **tsx ); 
    114  
    115 /* 
    116109 * This is the global handler for memory allocation failure, for pools that 
    117110 * are created by the endpoint (by default, all pools ARE allocated by  
     
    295288 * Get "Allow" header. 
    296289 */ 
    297 PJ_DECL(const pjsip_allow_hdr*) pjsip_endpt_get_allow_hdr( pjsip_endpoint *endpt ) 
     290PJ_DEF(const pjsip_allow_hdr*) pjsip_endpt_get_allow_hdr( pjsip_endpoint *endpt ) 
    298291{ 
    299292    return endpt->allow_hdr; 
     
    672665 * Find transaction by the key. 
    673666 */ 
    674 PJ_DECL(pjsip_transaction*) pjsip_endpt_find_tsx( pjsip_endpoint *endpt, 
     667PJ_DEF(pjsip_transaction*) pjsip_endpt_find_tsx( pjsip_endpoint *endpt, 
    675668                                                  const pj_str_t *key ) 
    676669{ 
     
    981974 * Find/create transport. 
    982975 */ 
    983 PJ_DECL(pj_status_t) pjsip_endpt_alloc_transport( pjsip_endpoint *endpt, 
     976PJ_DEF(pj_status_t) pjsip_endpt_alloc_transport( pjsip_endpoint *endpt, 
    984977                                                  pjsip_transport_type_e type, 
    985978                                                  const pj_sockaddr_in *remote, 
     
    992985 
    993986 
     987/* 
     988 * Report error. 
     989 */ 
     990PJ_DEF(void) pjsip_endpt_log_error(  pjsip_endpoint *endpt, 
     991                                     const char *sender, 
     992                                     pj_status_t error_code, 
     993                                     const char *format, 
     994                                     ... ) 
     995{ 
     996    char newformat[256]; 
     997    int len; 
     998    va_list marker; 
     999 
     1000    va_start(marker, format); 
     1001 
     1002    PJ_UNUSED_ARG(endpt); 
     1003 
     1004    len = pj_native_strlen(format); 
     1005    if (len < sizeof(newformat)-30) { 
     1006        pj_str_t errstr; 
     1007 
     1008        pj_native_strcpy(newformat, format); 
     1009        pj_snprintf(newformat+len, sizeof(newformat)-len-1, 
     1010                    ": [err %d] ", error_code); 
     1011        len += pj_native_strlen(newformat+len); 
     1012 
     1013        errstr = pjsip_strerror(error_code, newformat+len,  
     1014                                sizeof(newformat)-len-1); 
     1015 
     1016        len += errstr.slen; 
     1017        newformat[len] = '\0'; 
     1018 
     1019        pj_log(sender, 1, newformat, marker); 
     1020    } else { 
     1021        pj_log(sender, 1, format, marker); 
     1022    } 
     1023 
     1024    va_end(marker); 
     1025} 
     1026 
     1027 
     1028/* 
     1029 * Dump endpoint. 
     1030 */ 
    9941031PJ_DEF(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail ) 
    9951032{ 
  • 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 
  • pjproject/trunk/pjsip/src/pjsip/sip_transaction.c

    r58 r64  
    2020#include <pjsip/sip_transport.h> 
    2121#include <pjsip/sip_config.h> 
    22 #include <pjsip/sip_misc.h> 
     22#include <pjsip/sip_util.h> 
    2323#include <pjsip/sip_event.h> 
    2424#include <pjsip/sip_endpoint.h> 
     
    346346 * Create new transaction. 
    347347 */ 
    348 pj_status_t pjsip_tsx_create( pj_pool_t *pool, 
    349                               pjsip_endpoint *endpt, 
    350                               pjsip_transaction **p_tsx) 
     348PJ_DEF(pj_status_t) pjsip_tsx_create( pj_pool_t *pool, 
     349                                      pjsip_endpoint *endpt, 
     350                                      pjsip_transaction **p_tsx) 
    351351{ 
    352352    pjsip_transaction *tsx; 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r58 r64  
    648648            if (msg_status != PJ_SUCCESS) { 
    649649                if (remaining_len == PJSIP_MAX_PKT_LEN) { 
    650                     mgr->msg_cb(mgr->endpt, PJSIP_EOVERFLOW, rdata); 
     650                    mgr->msg_cb(mgr->endpt, PJSIP_ERXOVERFLOW, rdata); 
    651651                    /* Exhaust all data. */ 
    652652                    return rdata->pkt_info.len; 
  • pjproject/trunk/pjsip/src/pjsip/sip_uri.c

    r51 r64  
    1919#include <pjsip/sip_uri.h> 
    2020#include <pjsip/sip_msg.h> 
     21#include <pjsip/sip_parser.h> 
    2122#include <pjsip/print_util.h> 
     23#include <pjsip/sip_errno.h> 
     24#include <pjlib-util/string.h> 
    2225#include <pj/string.h> 
    2326#include <pj/pool.h> 
    2427#include <pj/assert.h> 
    2528 
     29/* 
     30 * Generic parameter manipulation. 
     31 */ 
     32PJ_DEF(pjsip_param*) pjsip_param_find(  pjsip_param *param_list, 
     33                                        const pj_str_t *name ) 
     34{ 
     35    pjsip_param *p = param_list->next; 
     36    while (p != param_list) { 
     37        if (pj_stricmp(&p->name, name)==0) 
     38            return p; 
     39        p = p->next; 
     40    } 
     41    return NULL; 
     42} 
     43 
     44PJ_DEF(const pjsip_param*) pjsip_param_cfind( const pjsip_param *param_list, 
     45                                              const pj_str_t *name ) 
     46{ 
     47    const pjsip_param *p = param_list->next; 
     48    while (p != param_list) { 
     49        if (pj_stricmp(&p->name, name)==0) 
     50            return p; 
     51        p = p->next; 
     52    } 
     53    return NULL; 
     54} 
     55 
     56PJ_DEF(void) pjsip_param_clone( pj_pool_t *pool, pjsip_param *dst_list, 
     57                                const pjsip_param *src_list) 
     58{ 
     59    const pjsip_param *p = src_list->next; 
     60 
     61    pj_list_init(dst_list); 
     62    while (p != src_list) { 
     63        pjsip_param *new_param = pj_pool_alloc(pool, sizeof(pjsip_param)); 
     64        pj_strdup(pool, &new_param->name, &p->name); 
     65        pj_strdup(pool, &new_param->value, &p->value); 
     66        pj_list_insert_before(dst_list, new_param); 
     67        p = p->next; 
     68    } 
     69} 
     70 
     71/* 
     72 * URI stuffs 
     73 */ 
    2674#define IS_SIPS(url)    ((url)->vptr==&sips_url_vptr) 
    2775 
     
    110158    url->ttl_param = -1; 
    111159    url->vptr = secure ? &sips_url_vptr : &sip_url_vptr; 
     160    pj_list_init(&url->other_param); 
     161    pj_list_init(&url->header_param); 
    112162} 
    113163 
     
    124174{ 
    125175    int printed; 
    126     pj_size_t size_required; 
    127176    char *startbuf = buf; 
     177    char *endbuf = buf+size; 
    128178    const pj_str_t *scheme; 
     179    pjsip_param *param; 
     180    char hparam_char = '?'; 
     181 
    129182    *buf = '\0'; 
    130  
    131     /* Check the buffer length. */ 
    132     size_required = 6 + url->host.slen + 10 + 
    133                     url->user.slen + url->passwd.slen + 2 + 
    134                     url->user_param.slen + 6 + 
    135                     url->method_param.slen + 8 + 
    136                     url->transport_param.slen + 11 + 
    137                     9 + 5 + 
    138                     url->maddr_param.slen + 7 + 
    139                     3 + 
    140                     url->other_param.slen + 
    141                     url->header_param.slen; 
    142     if (size < size_required) { 
    143         return -1; 
    144     } 
    145183 
    146184    /* Print scheme ("sip:" or "sips:") */ 
    147185    scheme = pjsip_uri_get_scheme(url); 
    148     copy_advance_no_check(buf, *scheme); 
     186    copy_advance_check(buf, *scheme); 
    149187    *buf++ = ':'; 
    150188 
    151189    /* Print "user:password@", if any. */ 
    152190    if (url->user.slen) { 
    153         copy_advance_no_check(buf, url->user); 
     191        copy_advance_escape(buf, url->user, pjsip_USER_SPEC); 
    154192        if (url->passwd.slen) { 
    155193            *buf++ = ':'; 
    156             copy_advance_no_check(buf, url->passwd); 
     194            copy_advance_escape(buf, url->passwd, pjsip_PASSWD_SPEC); 
    157195        } 
    158196 
     
    162200    /* Print host. */ 
    163201    pj_assert(url->host.slen != 0); 
    164     copy_advance_no_check(buf, url->host); 
     202    copy_advance_check(buf, url->host); 
    165203 
    166204    /* Only print port if it is explicitly specified.  
     
    171209     * UA has sent us port, so we'll just send the port indiscrimately 
    172210     */ 
    173     PJ_TODO(SHOULD_DISALLOW_URI_PORT_IN_FROM_TO_HEADER) 
    174     if (url->port /*&& context != PJSIP_URI_IN_FROMTO_HDR*/) { 
     211    //PJ_TODO(SHOULD_DISALLOW_URI_PORT_IN_FROM_TO_HEADER) 
     212    if (url->port && context != PJSIP_URI_IN_FROMTO_HDR) { 
    175213        *buf++ = ':'; 
    176214        printed = pj_utoa(url->port, buf); 
     
    179217 
    180218    /* User param is allowed in all contexes */ 
    181     copy_advance_pair_no_check(buf, ";user=", 6, url->user_param); 
     219    copy_advance_pair_check(buf, ";user=", 6, url->user_param); 
    182220 
    183221    /* Method param is only allowed in external/other context. */ 
    184222    if (context == PJSIP_URI_IN_OTHER) { 
    185         copy_advance_pair_no_check(buf, ";method=", 8, url->method_param); 
     223        copy_advance_pair_escape(buf, ";method=", 8, url->method_param,  
     224                                 pjsip_PARAM_CHAR_SPEC); 
    186225    } 
    187226 
    188227    /* Transport is not allowed in From/To header. */ 
    189228    if (context != PJSIP_URI_IN_FROMTO_HDR) { 
    190         copy_advance_pair_no_check(buf, ";transport=", 11, url->transport_param); 
     229        copy_advance_pair_escape(buf, ";transport=", 11, url->transport_param, 
     230                                 pjsip_PARAM_CHAR_SPEC); 
    191231    } 
    192232 
    193233    /* TTL param is not allowed in From, To, Route, and Record-Route header. */ 
    194234    if (url->ttl_param >= 0 && context != PJSIP_URI_IN_FROMTO_HDR && 
    195         context != PJSIP_URI_IN_ROUTING_HDR)  
     235        context != PJSIP_URI_IN_ROUTING_HDR && (endbuf-buf) > 15)  
    196236    { 
    197237        pj_memcpy(buf, ";ttl=", 5); 
     
    202242    /* maddr param is not allowed in From and To header. */ 
    203243    if (context != PJSIP_URI_IN_FROMTO_HDR) { 
    204         copy_advance_pair_no_check(buf, ";maddr=", 7, url->maddr_param); 
     244        copy_advance_pair_escape(buf, ";maddr=", 7, url->maddr_param, 
     245                                 pjsip_PARAM_CHAR_SPEC); 
    205246    } 
    206247 
     
    210251    { 
    211252        pj_str_t lr = { ";lr", 3 }; 
    212         copy_advance_no_check(buf, lr); 
     253        copy_advance_check(buf, lr); 
    213254    } 
    214255 
    215256    /* Other param. */ 
    216     if (url->other_param.slen) { 
    217         copy_advance_no_check(buf, url->other_param); 
     257    param = url->other_param.next; 
     258    while (param != &url->other_param) { 
     259        *buf++ = ';'; 
     260        copy_advance_escape(buf, param->name, pjsip_PARAM_CHAR_SPEC); 
     261        if (param->value.slen) { 
     262            *buf++ = '='; 
     263            copy_advance_escape(buf, param->value, pjsip_PARAM_CHAR_SPEC); 
     264        } 
     265        param = param->next; 
    218266    } 
    219267 
    220268    /* Header param. */ 
    221     if (url->header_param.slen) { 
    222         copy_advance_no_check(buf, url->header_param); 
     269    param = url->header_param.next; 
     270    while (param != &url->header_param) { 
     271        *buf++ = hparam_char; 
     272        copy_advance_escape(buf, param->name, pjsip_HDR_CHAR_SPEC); 
     273        if (param->value.slen) { 
     274            *buf++ = '='; 
     275            copy_advance_escape(buf, param->value, pjsip_HDR_CHAR_SPEC); 
     276        } 
     277        param = param->next; 
     278        hparam_char = '&'; 
    223279    } 
    224280 
     
    227283} 
    228284 
    229 static int pjsip_url_compare( pjsip_uri_context_e context, 
    230                               const pjsip_url *url1, const pjsip_url *url2) 
    231 { 
    232     /* The easiest (and probably the most efficient) way to compare two URLs 
    233        are to print them, and compare them bytes per bytes. This technique 
    234        works quite well with RFC3261, as the RFC (unlike RFC2543) defines that 
    235        components specified in one URL does NOT match its default value if 
    236        it is not specified in the second URL. For example, parameter "user=ip" 
    237        does NOT match if it is omited in second URL. 
    238  
    239        HOWEVER, THE SAME CAN NOT BE APPLIED FOR other-param NOR header-param. 
    240        For these, each of the parameters must be compared one by one. Parameter 
    241        that exists in one URL will match the comparison. But parameter that 
    242        exists in both URLs and doesn't match wont match the URL comparison. 
    243  
    244        The solution for this is to compare 'standard' URL components with 
    245        bytes-to-bytes comparison, and compare other-param and header-param with 
    246        more intelligent comparison. 
    247      */ 
    248     char str_url1[PJSIP_MAX_URL_SIZE]; 
    249     char str_url2[PJSIP_MAX_URL_SIZE]; 
    250     int len1, len2; 
    251  
    252     /* Must compare scheme first, as the second URI may not be SIP URL. */ 
    253     if (pj_stricmp(pjsip_uri_get_scheme(url1), pjsip_uri_get_scheme(url2))) 
    254         return -1; 
    255  
    256     len1 = pjsip_url_print(context, url1, str_url1, sizeof(str_url1)); 
    257     if (len1 < 1) { 
    258         pj_assert(0); 
    259         return -1; 
    260     } 
    261     len2 = pjsip_url_print(context, url2, str_url2, sizeof(str_url2)); 
    262     if (len2 < 1) { 
    263         pj_assert(0); 
    264         return -1; 
    265     } 
    266  
    267     if (len1 != len2) { 
    268         /* Not equal. */ 
    269         return -1; 
    270     } 
    271  
    272     if (pj_native_strcmp(str_url1, str_url2)) { 
    273         /* Not equal */ 
    274         return -1; 
    275     } 
    276  
    277     /* TODO: compare other-param and header-param in more intelligent manner. */ 
    278     PJ_TODO(HPARAM_AND_OTHER_PARAM_COMPARISON_IN_URL_COMPARISON) 
    279  
    280     if (pj_strcmp(&url1->other_param, &url2->other_param)) { 
    281         /* Not equal. */ 
    282         return -1; 
    283     } 
    284     if (pj_strcmp(&url1->header_param, &url2->header_param)) { 
    285         /* Not equal. */ 
    286         return -1; 
    287     } 
    288  
    289     /* Seems to be equal, isn't it. */ 
    290     return 0; 
     285static pj_status_t pjsip_url_compare( pjsip_uri_context_e context, 
     286                                      const pjsip_url *url1,  
     287                                      const pjsip_url *url2) 
     288{ 
     289    const pjsip_param *p1; 
     290 
     291    /* 
     292     * Compare two SIP URL's according to Section 19.1.4 of RFC 3261. 
     293     */ 
     294 
     295    /* SIP and SIPS URI are never equivalent.  
     296     * Note: just compare the vptr to avoid string comparison.  
     297     *       Pretty neat huh!! 
     298     */ 
     299    if (url1->vptr != url2->vptr) 
     300        return PJSIP_ECMPSCHEME; 
     301 
     302    /* Comparison of the userinfo of SIP and SIPS URIs is case-sensitive.  
     303     * This includes userinfo containing passwords or formatted as  
     304     * telephone-subscribers. 
     305     */ 
     306    if (pj_strcmp(&url1->user, &url2->user) != 0) 
     307        return PJSIP_ECMPUSER; 
     308    if (pj_strcmp(&url1->passwd, &url2->passwd) != 0) 
     309        return PJSIP_ECMPPASSWD; 
    291310     
     311    /* Comparison of all other components of the URI is 
     312     * case-insensitive unless explicitly defined otherwise. 
     313     */ 
     314 
     315    /* The ordering of parameters and header fields is not significant  
     316     * in comparing SIP and SIPS URIs. 
     317     */ 
     318 
     319    /* Characters other than those in the “reserved” set (see RFC 2396 [5]) 
     320     * are equivalent to their “encoding. 
     321     */ 
     322 
     323    /* An IP address that is the result of a DNS lookup of a host name  
     324     * does not match that host name. 
     325     */ 
     326    if (pj_stricmp(&url1->host, &url2->host) != 0) 
     327        return PJSIP_ECMPHOST; 
     328 
     329    /* A URI omitting any component with a default value will not match a URI 
     330     * explicitly containing that component with its default value.  
     331     * For instance, a URI omitting the optional port component will not match 
     332     * a URI explicitly declaring port 5060.  
     333     * The same is true for the transport-parameter, ttl-parameter,  
     334     * user-parameter, and method components. 
     335     */ 
     336 
     337    /* Port is not allowed in To and From header. 
     338     */ 
     339    if (context != PJSIP_URI_IN_FROMTO_HDR) { 
     340        if (url1->port != url2->port) 
     341            return PJSIP_ECMPPORT; 
     342    } 
     343    /* Transport is not allowed in From/To header. */ 
     344    if (context != PJSIP_URI_IN_FROMTO_HDR) { 
     345        if (pj_stricmp(&url1->transport_param, &url2->transport_param) != 0) 
     346            return PJSIP_ECMPTRANSPORTPRM; 
     347    } 
     348    /* TTL param is not allowed in From, To, Route, and Record-Route header. */ 
     349    if (context != PJSIP_URI_IN_FROMTO_HDR && 
     350        context != PJSIP_URI_IN_ROUTING_HDR) 
     351    { 
     352        if (url1->ttl_param != url2->ttl_param) 
     353            return PJSIP_ECMPTTLPARAM; 
     354    } 
     355    /* User param is allowed in all contexes */ 
     356    if (pj_stricmp(&url1->user_param, &url2->user_param) != 0) 
     357        return PJSIP_ECMPUSERPARAM; 
     358    /* Method param is only allowed in external/other context. */ 
     359    if (context == PJSIP_URI_IN_OTHER) { 
     360        if (pj_stricmp(&url1->method_param, &url2->method_param) != 0) 
     361            return PJSIP_ECMPMETHODPARAM; 
     362    } 
     363    /* maddr param is not allowed in From and To header. */ 
     364    if (context != PJSIP_URI_IN_FROMTO_HDR) { 
     365        if (pj_stricmp(&url1->maddr_param, &url2->maddr_param) != 0) 
     366            return PJSIP_ECMPMADDRPARAM; 
     367    } 
     368 
     369    /* lr parameter is ignored (?) */ 
     370    /* lr param is not allowed in From, To, and Contact header. */ 
     371 
     372 
     373    /* All other uri-parameters appearing in only one URI are ignored when  
     374     * comparing the URIs. 
     375     */ 
     376    p1 = url1->other_param.next; 
     377    while (p1 != &url1->other_param) { 
     378        const pjsip_param *p2; 
     379        p2 = pjsip_param_cfind(&url2->other_param, &p1->name); 
     380        if (p2 ) { 
     381            if (pj_stricmp(&p1->value, &p2->value) != 0) 
     382                return PJSIP_ECMPOTHERPARAM; 
     383        } 
     384 
     385        p1 = p1->next; 
     386    } 
     387 
     388    /* URI header components are never ignored. Any present header component 
     389     * MUST be present in both URIs and match for the URIs to match.  
     390     * The matching rules are defined for each header field in Section 20. 
     391     */ 
     392    p1 = url1->header_param.next; 
     393    while (p1 != &url1->header_param) { 
     394        const pjsip_param *p2; 
     395        p2 = pjsip_param_cfind(&url2->header_param, &p1->name); 
     396        if (p2) { 
     397            /* It seems too much to compare two header params according to 
     398             * the rule of each header. We'll just compare them string to 
     399             * string.. 
     400             */ 
     401            PJ_TODO(MORE_COMPLIANT_HEADER_PARAM_COMPARISON_IN_URL); 
     402 
     403            if (pj_stricmp(&p1->value, &p2->value) != 0) 
     404                return PJSIP_ECMPHEADERPARAM; 
     405        } else { 
     406            return PJSIP_ECMPHEADERPARAM; 
     407        } 
     408        p1 = p1->next; 
     409    } 
     410 
     411    /* Equal!! Pheuww.. */ 
     412    return PJ_SUCCESS; 
    292413} 
    293414 
     
    305426    url->ttl_param = rhs->ttl_param; 
    306427    pj_strdup( pool, &url->maddr_param, &rhs->maddr_param); 
    307     pj_strdup( pool, &url->other_param, &rhs->other_param); 
    308     pj_strdup( pool, &url->header_param, &rhs->header_param); 
     428    pjsip_param_clone(pool, &url->other_param, &rhs->other_param); 
     429    pjsip_param_clone(pool, &url->header_param, &rhs->header_param); 
    309430    url->lr_param = rhs->lr_param; 
    310431} 
  • pjproject/trunk/pjsip/src/pjsip/sip_util.c

    r58 r64  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #include <pjsip/sip_misc.h> 
     19#include <pjsip/sip_util.h> 
    2020#include <pjsip/sip_transport.h> 
    2121#include <pjsip/sip_msg.h> 
  • pjproject/trunk/pjsip/src/test-pjsip/main.c

    r61 r64  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
     19#include "test.h" 
     20 
     21int main(void) 
     22{ 
     23    return test_main(); 
     24} 
  • pjproject/trunk/pjsip/src/test-pjsip/msg.c

    r61 r64  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #include <pjsip/sip_msg.h> 
    20 #include <pjsip/sip_parser.h> 
    21 #include <pj/os.h> 
    22 #include <pj/pool.h> 
    23 #include <pj/string.h> 
    24 #include <stdlib.h> 
    25 #include <stdio.h> 
    2619#include "test.h" 
    27  
    28 #define ERR_SYNTAX_ERR  (-2) 
    29 #define ERR_NOT_EQUAL   (-3) 
    30 #define ERR_SYSTEM      (-4) 
    31  
     20#include <pjsip_core.h> 
     21#include <pjlib.h> 
    3222 
    3323static pjsip_msg *create_msg0(pj_pool_t *pool); 
     
    6757}; 
    6858 
    69 static pj_caching_pool cp; 
    70 static pj_pool_factory *pf = &cp.factory; 
    7159static pj_uint32_t parse_len, parse_time, print_time; 
    7260 
    73 static void pool_error(pj_pool_t *pool, pj_size_t sz) 
    74 { 
    75     PJ_UNUSED_ARG(pool) 
    76     PJ_UNUSED_ARG(sz) 
    77  
    78     pj_assert(0); 
    79     exit(1); 
    80 } 
    81  
    82 static const char *STATUS_STR(pj_status_t status) 
    83 { 
    84     switch (status) { 
    85     case 0: return "OK"; 
    86     case ERR_SYNTAX_ERR: return "Syntax Error"; 
    87     case ERR_NOT_EQUAL: return "Not Equal"; 
    88     case ERR_SYSTEM: return "System Error"; 
    89     } 
    90     return "???"; 
    91 } 
    92  
    93 static pj_status_t test_entry( struct test_msg *entry ) 
     61static pj_status_t test_entry( pj_pool_t *pool, struct test_msg *entry ) 
    9462{ 
    9563    pjsip_msg *parsed_msg, *ref_msg; 
    96     pj_pool_t *pool; 
    9764    pj_status_t status = PJ_SUCCESS; 
    9865    int len; 
    9966    pj_str_t str1, str2; 
    10067    pjsip_hdr *hdr1, *hdr2; 
    101     pj_hr_timestamp t1, t2; 
     68    pj_timestamp t1, t2; 
    10269    char *msgbuf; 
    10370 
    10471    enum { BUFLEN = 512 }; 
    10572     
    106     pool = pj_pool_create( pf, "",  
    107                            PJSIP_POOL_LEN_RDATA*2, PJSIP_POOL_INC_RDATA,  
    108                            &pool_error); 
    109  
    110     if (entry->len == 0) { 
    111         entry->len = strlen(entry->msg); 
    112     } 
    113  
    11473    /* Parse message. */ 
    11574    parse_len += entry->len; 
    116     pj_hr_gettimestamp(&t1); 
     75    pj_get_timestamp(&t1); 
    11776    parsed_msg = pjsip_parse_msg(pool, entry->msg, entry->len, NULL); 
    11877    if (parsed_msg == NULL) { 
    119         status = ERR_SYNTAX_ERR; 
    120         goto on_return; 
    121     } 
    122     pj_hr_gettimestamp(&t2); 
     78        status = -10; 
     79        goto on_return; 
     80    } 
     81    pj_get_timestamp(&t2); 
    12382    parse_time += t2.u32.lo - t1.u32.lo; 
    124  
    125 #if IS_PROFILING 
    126     goto print_msg; 
    127 #endif 
    12883 
    12984    /* Create reference message. */ 
     
    13691    /* Compare message type. */ 
    13792    if (parsed_msg->type != ref_msg->type) { 
    138         status = ERR_NOT_EQUAL; 
     93        status = -20; 
    13994        goto on_return; 
    14095    } 
     
    146101 
    147102        if (m1->id != m2->id || pj_strcmp(&m1->name, &m2->name)) { 
    148             status = ERR_NOT_EQUAL; 
     103            status = -30; 
    149104            goto on_return; 
    150105        } 
     
    160115        len = hdr1->vptr->print_on(hdr1, str1.ptr, BUFLEN); 
    161116        if (len < 1) { 
    162             status = ERR_SYSTEM; 
     117            status = -40; 
    163118            goto on_return; 
    164119        } 
     
    167122        len = hdr2->vptr->print_on(hdr2, str2.ptr, BUFLEN); 
    168123        if (len < 1) { 
    169             status = ERR_SYSTEM; 
     124            status = -50; 
    170125            goto on_return; 
    171126        } 
    172127        str2.slen = len; 
    173128 
    174         if (!SILENT) { 
    175             printf("hdr1='%.*s'\n" 
    176                    "hdr2='%.*s'\n\n", 
    177                    str1.slen, str1.ptr, 
    178                    str2.slen, str2.ptr); 
    179         } 
    180129        if (pj_strcmp(&str1, &str2) != 0) { 
    181             status = ERR_NOT_EQUAL; 
     130            status = -60; 
    182131            goto on_return; 
    183132        } 
     
    188137 
    189138    if (hdr1 != &parsed_msg->hdr || hdr2 != &ref_msg->hdr) { 
    190         status = ERR_NOT_EQUAL; 
     139        status = -70; 
    191140        goto on_return; 
    192141    } 
    193142 
    194143    /* Print message. */ 
    195 #if IS_PROFILING 
    196 print_msg: 
    197 #endif 
    198144    msgbuf = pj_pool_alloc(pool, PJSIP_MAX_PKT_LEN); 
    199145    if (msgbuf == NULL) { 
    200         status = ERR_SYSTEM; 
    201         goto on_return; 
    202     } 
    203     pj_hr_gettimestamp(&t1); 
     146        status = -80; 
     147        goto on_return; 
     148    } 
     149    pj_get_timestamp(&t1); 
    204150    len = pjsip_msg_print(parsed_msg, msgbuf, PJSIP_MAX_PKT_LEN); 
    205151    if (len < 1) { 
    206         status = ERR_SYSTEM; 
    207         goto on_return; 
    208     } 
    209     pj_hr_gettimestamp(&t2); 
     152        status = -90; 
     153        goto on_return; 
     154    } 
     155    pj_get_timestamp(&t2); 
    210156    print_time += t2.u32.lo - t1.u32.lo; 
    211157    status = PJ_SUCCESS; 
    212158 
    213159on_return: 
    214     pj_pool_release(pool); 
    215160    return status; 
    216161} 
    217162 
    218 static void warm_up() 
    219 { 
     163 
     164pj_status_t msg_test(void) 
     165{ 
     166    pj_status_t status; 
    220167    pj_pool_t *pool; 
    221     pool = pj_pool_create( pf, "",  
    222                            PJSIP_POOL_LEN_RDATA*2, PJSIP_POOL_INC_RDATA,  
    223                            &pool_error); 
    224     pj_pool_release(pool); 
    225 } 
    226  
    227  
    228 pj_status_t test_msg(void) 
    229 { 
    230     pj_status_t status; 
    231     unsigned i; 
    232  
    233     pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 
    234     warm_up(); 
    235  
    236     for (i=0; i<LOOP; ++i) { 
    237         status = test_entry( &test_array[0] ); 
    238     } 
    239     printf("%s\n", STATUS_STR(status)); 
    240  
    241     printf("Total bytes: %u, parse time=%f/char, print time=%f/char\n",  
    242            parse_len,  
    243            parse_time*1.0/parse_len, 
    244            print_time*1.0/parse_len); 
    245     return PJ_SUCCESS; 
     168 
     169    pool = pjsip_endpt_create_pool(endpt, NULL, 4000, 4000); 
     170 
     171    status = test_entry( pool, &test_array[0] ); 
     172 
     173    pjsip_endpt_destroy(endpt); 
     174    return status; 
    246175} 
    247176 
  • pjproject/trunk/pjsip/src/test-pjsip/test.c

    • Property svn:keyword set to Id
    r61 r64  
    4747} 
    4848 
     49pj_status_t register_static_modules(pj_size_t *count, pjsip_module **modules) 
     50{ 
     51    *count = 0; 
     52    return PJ_SUCCESS; 
     53} 
    4954 
    50  
    51 int main() 
     55int test_main(void) 
    5256{ 
    5357    pj_status_t rc; 
     58    pj_caching_pool caching_pool; 
     59    const char *filename; 
     60    int line; 
     61 
     62    pj_log_set_level(3); 
     63    pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |  
     64                     PJ_LOG_HAS_MICRO_SEC); 
    5465 
    5566    if ((rc=pj_init()) != PJ_SUCCESS) { 
    5667        app_perror("pj_init", rc); 
     68        return rc; 
    5769    } 
    5870 
    59     DO_TEST(parse_uri()); 
    60     DO_TEST(parse_msg()); 
     71    pj_dump_config(); 
     72 
     73    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); 
     74 
     75    rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt); 
     76    if (rc != PJ_SUCCESS) { 
     77        app_perror("pjsip_endpt_create", rc); 
     78        pj_caching_pool_destroy(&caching_pool); 
     79        return rc; 
     80    } 
     81 
     82    PJ_LOG(3,("","")); 
     83 
     84    DO_TEST(uri_test()); 
    6185 
    6286on_return: 
     87 
     88    pjsip_endpt_destroy(endpt); 
     89    pj_caching_pool_destroy(&caching_pool); 
     90 
     91    PJ_LOG(3,("test", "")); 
     92  
     93    pj_thread_get_stack_info(pj_thread_this(), &filename, &line); 
     94    PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",  
     95                      pj_thread_get_stack_max_usage(pj_thread_this()), 
     96                      filename, line)); 
     97    if (rc == 0) 
     98        PJ_LOG(3,("test", "Looks like everything is okay!..")); 
     99    else 
     100        PJ_LOG(3,("test", "Test completed with error(s)")); 
     101 
    63102    return 0; 
    64103} 
  • pjproject/trunk/pjsip/src/test-pjsip/test.h

    r61 r64  
    2222#include <pjsip/sip_types.h> 
    2323 
    24 #define SILENT          1 
    25 #define IS_PROFILING    1 
    26 #define LOOP            2000 
    27  
    2824extern pjsip_endpoint *endpt; 
    2925 
    30 pj_status_t parse_uri(void); 
    31 pj_status_t parse_msg(void); 
     26pj_status_t uri_test(void); 
     27pj_status_t msg_test(void); 
    3228 
     29int  test_main(void); 
    3330void app_perror(const char *msg, pj_status_t status); 
    3431 
  • pjproject/trunk/pjsip/src/test-pjsip/uri.c

    r61 r64  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #include <pjsip/sip_parser.h> 
    20 #include <pjsip/sip_uri.h> 
    21 #include <pj/os.h> 
    22 #include <pj/pool.h> 
    23 #include <pj/string.h> 
    24 #include <stdlib.h> 
    25 #include <stdio.h> 
    2619#include "test.h" 
    27  
    28 #define ERR_SYNTAX_ERR  (-2) 
    29 #define ERR_NOT_EQUAL   (-3) 
     20#include <pjsip_core.h> 
     21#include <pjlib.h> 
     22 
    3023 
    3124#define ALPHANUM    "abcdefghijklmnopqrstuvwxyz" \ 
     
    3932#define POOL_SIZE       4096 
    4033 
    41 static const char *STATUS_STR(pj_status_t status) 
    42 { 
    43     switch (status) { 
    44     case 0: return "OK"; 
    45     case ERR_SYNTAX_ERR: return "Syntax Error"; 
    46     case ERR_NOT_EQUAL: return "Not Equal"; 
    47     } 
    48     return "???"; 
    49 } 
    50  
    5134static pj_uint32_t parse_len, parse_time, print_time; 
    52 static pj_caching_pool cp; 
    5335 
    5436 
     
    7557static pjsip_uri *create_dummy( pj_pool_t *pool ); 
    7658 
     59#define ERR_NOT_EQUAL   -1001 
     60#define ERR_SYNTAX_ERR  -1002 
     61 
    7762struct uri_test 
    7863{ 
     
    240225        "", 
    241226        &create_dummy, 
    242     }, 
    243     { 
    244         PJ_SUCCESS, 
    245         "", 
    246         NULL, 
    247     }, 
     227    } 
    248228}; 
    249229 
     
    477457static pjsip_uri *create_dummy(pj_pool_t *pool) 
    478458{ 
    479     PJ_UNUSED_ARG(pool) 
     459    PJ_UNUSED_ARG(pool); 
    480460    return NULL; 
    481461} 
    482462 
    483463/*****************************************************************************/ 
    484  
    485 static void pool_error(pj_pool_t *pool, pj_size_t sz) 
    486 { 
    487     PJ_UNUSED_ARG(pool) 
    488     PJ_UNUSED_ARG(sz) 
    489  
    490     pj_assert(0); 
    491     exit(1); 
    492 } 
    493464 
    494465/* 
    495466 * Test one test entry. 
    496467 */ 
    497 static pj_status_t test_entry(struct uri_test *entry) 
     468static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry) 
    498469{ 
    499470    pj_status_t status; 
    500     pj_pool_t *pool; 
    501471    int len; 
    502472    pjsip_uri *parsed_uri, *ref_uri; 
    503473    pj_str_t s1 = {NULL, 0}, s2 = {NULL, 0}; 
    504     pj_hr_timestamp t1, t2; 
    505  
    506     pool = (*cp.factory.create_pool)( &cp.factory, "", POOL_SIZE, 0, &pool_error); 
     474    pj_timestamp t1, t2; 
     475 
     476    entry->len = pj_native_strlen(entry->str); 
    507477 
    508478    /* Parse URI text. */ 
    509     pj_hr_gettimestamp(&t1); 
     479    pj_get_timestamp(&t1); 
    510480    parse_len += entry->len; 
    511481    parsed_uri = pjsip_parse_uri(pool, entry->str, entry->len, 0); 
     
    514484         * return OK. 
    515485         */ 
    516         status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : ERR_SYNTAX_ERR; 
     486        status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10; 
    517487        goto on_return; 
    518488    } 
    519     pj_hr_gettimestamp(&t2); 
     489    pj_get_timestamp(&t2); 
    520490    parse_time += t2.u32.lo - t1.u32.lo; 
    521491 
     
    527497    s2.ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 
    528498 
    529     pj_hr_gettimestamp(&t1); 
     499    pj_get_timestamp(&t1); 
    530500    len = pjsip_uri_print( PJSIP_URI_IN_OTHER, parsed_uri, s1.ptr, PJSIP_MAX_URL_SIZE); 
    531501    if (len < 1) { 
    532         status = -1; 
     502        status = -20; 
    533503        goto on_return; 
    534504    } 
     
    537507    len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE); 
    538508    if (len < 1) { 
    539         status = -1; 
     509        status = -30; 
    540510        goto on_return; 
    541511    } 
    542512    s2.slen = len; 
    543     pj_hr_gettimestamp(&t2); 
     513    pj_get_timestamp(&t2); 
    544514    print_time += t2.u32.lo - t1.u32.lo; 
    545515 
     
    547517    if (pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri) != 0) { 
    548518        /* Not equal. See if this is the expected status. */ 
    549         status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : ERR_NOT_EQUAL; 
     519        status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40; 
    550520        goto on_return; 
    551521 
    552522    } else { 
    553523        /* Equal. See if this is the expected status. */ 
    554         status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -1; 
     524        status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -50; 
    555525        if (status != PJ_SUCCESS) { 
    556526            goto on_return; 
     
    561531    if (pj_strcmp(&s1, &s2) != 0) { 
    562532        /* Not equal. */ 
    563         status = ERR_NOT_EQUAL; 
     533        status = -60; 
    564534    } 
    565535 
    566536on_return: 
    567     if (!SILENT) { 
    568         printf("%.2d %s (expected status=%s)\n" 
    569                "   str=%s\n" 
    570                "   uri=%.*s\n" 
    571                "   ref=%.*s\n\n",  
    572                entry-uri_test_array,  
    573                STATUS_STR(status),  
    574                STATUS_STR(entry->status),  
    575                entry->str,  
    576                (int)s1.slen, s1.ptr, (int)s2.slen, s2.ptr); 
    577     } 
    578  
    579     pj_pool_release(pool); 
    580537    return status; 
    581538} 
    582539 
    583 static void warm_up(pj_pool_factory *pf) 
    584 { 
     540pj_status_t uri_test() 
     541{ 
     542    unsigned i; 
    585543    pj_pool_t *pool; 
    586     struct uri_test *entry; 
    587  
    588     pool = pj_pool_create(pf, "", POOL_SIZE, 0, &pool_error); 
    589     pjsip_parse_uri(pool, "sip:host", 8, 0); 
    590     entry = &uri_test_array[0]; 
    591     while (entry->creator) { 
    592         entry->len = strlen(entry->str); 
    593         ++entry; 
    594     } 
    595     pj_pool_release(pool); 
    596 } 
    597  
    598 //#if !IS_PROFILING 
    599 #if 1 
    600 pj_status_t test_uri() 
    601 { 
    602     struct uri_test *entry; 
    603     int i=0, err=0; 
    604544    pj_status_t status; 
    605     pj_hr_timestamp t1, t2; 
    606     pj_uint32_t total_time; 
    607  
    608     pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 
    609     warm_up(&cp.factory); 
    610  
    611     pj_hr_gettimestamp(&t1); 
    612     for (i=0; i<LOOP; ++i) { 
    613         entry = &uri_test_array[0]; 
    614         while (entry->creator) { 
    615             status = test_entry(entry); 
    616             if (status != PJ_SUCCESS) { 
    617                 ++err; 
    618             } 
    619             ++entry; 
     545 
     546    pool = pjsip_endpt_create_pool(endpt, "", 4000, 4000); 
     547 
     548    for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { 
     549        status = do_uri_test(pool, &uri_test_array[i]); 
     550        if (status != PJ_SUCCESS) { 
     551            PJ_LOG(3,("uri_test", "  error %d when testing entry %d", 
     552                      status, i)); 
     553            break; 
    620554        } 
    621555    } 
    622     pj_hr_gettimestamp(&t2); 
    623     total_time = t2.u32.lo - t1.u32.lo; 
    624  
    625     printf("Error=%d\n", err); 
    626     printf("Total parse len:  %u bytes\n", parse_len); 
    627     printf("Total parse time: %u (%f/char), print time: %u (%f/char)\n",  
    628             parse_time, parse_time*1.0/parse_len, 
    629             print_time, print_time*1.0/parse_len); 
    630     printf("Total time: %u (%f/char)\n", total_time, total_time*1.0/parse_len); 
    631     return err; 
    632 } 
    633  
    634 #else 
    635  
    636 pj_status_t test_uri() 
    637 { 
    638     struct uri_test *entry; 
    639     unsigned i; 
    640  
    641     warm_up(); 
    642     pj_caching_pool_init(&cp, 1024*1024); 
    643  
    644     for (i=0; i<LOOP; ++i) { 
    645         entry = &uri_test_array[0]; 
    646         while (entry->creator) { 
    647             pj_pool_t *pool; 
    648             pjsip_uri *uri1, *uri2; 
    649  
    650             pool = pj_pool_create( &cp.factory, "", POOL_SIZE, 0, &pool_error); 
    651             uri1 = pjsip_parse_uri(pool, entry->str, strlen(entry->str)); 
    652             pj_pool_release(pool); 
    653             ++entry; 
    654         } 
    655     } 
    656  
    657     return 0; 
    658 } 
    659  
    660 #endif 
     556 
     557    pjsip_endpt_destroy_pool(endpt, pool); 
     558    return status; 
     559} 
     560 
Note: See TracChangeset for help on using the changeset viewer.