Changeset 43


Ignore:
Timestamp:
Nov 11, 2005 7:01:31 PM (18 years ago)
Author:
bennylp
Message:

First clean compile of pjsip

Location:
pjproject/main
Files:
1 added
2 deleted
70 edited
1 moved

Legend:

Unmodified
Added
Removed
  • pjproject/main/RELNOTES.txt

    r1 r43  
     1Version 0.3 
     2PJLIB 
     3        - Correct error reporting in the whole library. No more vague -1 errors! 
     4        - New super portable socket abstraction. 
     5        - Other headers were made super portable too. 
     6        - Ioqueue supports multiple pending operations in a single socket! 
     7        - No more floating point. 
     8        - Ported to new platforms: 
     9                - i386/linux kernel (!) 
     10                - Sparc/Solaris 
     11                - Alpha/Linux 
     12PJSIP 
     13        - Correct error reporting in the whole library. No more -1 errors! 
     14        - Rewrote event, now much more readable. 
     15        - Per object tracing. 
     16 
     17 
    118Version 0.2.9 - 2005/06/19 
    219Core: 
  • pjproject/main/pjlib-util/include/pjlib-util/scanner.h

    r29 r43  
    11/* $Id$ 
    2  * 
    3  */ 
    4  
    5 #ifndef __PJ_PARSER_H__ 
    6 #define __PJ_PARSER_H__ 
     2 */ 
     3#ifndef __PJ_SCANNER_H__ 
     4#define __PJ_SCANNER_H__ 
    75 
    86/** 
     
    2018 * @brief 
    2119 * Text scanning utility. 
    22  */ 
    23  
    24 /** 
    25  * @defgroup PJ_CHARSPEC Character Filter Specification 
    26  * @ingroup PJ_SCAN 
    27  * @brief 
    28  * The type pj_char_spec is a specification of character set used in 
    29  * scanner. Application can define multiple character specs, such as to 
    30  * scan alpha numerics, numbers, tokens, etc. 
     20 * 
    3121 * @{ 
    3222 */ 
     
    3424/** 
    3525 * This describes the type of individual character specification in 
    36  * #pj_char_spec. 
    37  */ 
    38 typedef pj_uint8_t pj_char_spec_element_t; 
    39  
    40 /** 
    41  * The character specification is implemented as array of boolean flags. Each 
    42  * flag indicates the membership of the character in the spec. If the flag 
    43  * at one position is non-zero, then the character at that position belongs 
    44  * to the specification, and vice versa. 
    45  */ 
    46 typedef pj_char_spec_element_t pj_char_spec[256]; 
    47 // Note: it's got to be 256 (not 128) to cater for extended character in input. 
    48  
    49 /** 
    50  * Initialize character spec. 
    51  * @param cs the scanner character specification. 
    52  */ 
    53 PJ_DECL(void) pj_cs_init( pj_char_spec cs); 
    54  
    55 /** 
    56  * Set the membership of the specified character to TRUE. 
    57  * @param cs the scanner character specification. 
    58  * @param c the character. 
    59  */ 
    60 PJ_DECL(void) pj_cs_set( pj_char_spec cs, int c); 
     26 * #pj_cis_buf_t. Basicly the number of bits here 
     27 */ 
     28#ifndef PJ_CIS_ELEM_TYPE 
     29#   define PJ_CIS_ELEM_TYPE pj_uint32_t 
     30#endif 
     31 
     32/** 
     33 * This describes the type of individual character specification in 
     34 * #pj_cis_buf_t. 
     35 */ 
     36typedef PJ_CIS_ELEM_TYPE pj_cis_elem_t; 
     37 
     38/** 
     39 * Maximum number of input specification in a buffer. 
     40 * Effectively this means the number of bits in pj_cis_elem_t. 
     41 */ 
     42#define PJ_CIS_MAX_INDEX   (sizeof(pj_cis_elem_t) << 3) 
     43 
     44/** 
     45 * The scanner input specification buffer. 
     46 */ 
     47typedef struct pj_cis_buf_t 
     48{ 
     49    pj_cis_elem_t    cis_buf[256];  /**< Must be 256 (not 128)! */ 
     50    pj_cis_elem_t    use_mask;      /**< To keep used indexes.  */ 
     51} pj_cis_buf_t; 
     52 
     53/** 
     54 * Character input specification. 
     55 */ 
     56typedef struct pj_cis_t 
     57{ 
     58    pj_cis_elem_t   *cis_buf;       /**< Pointer to buffer.     */ 
     59    int              cis_id;        /**< Id.                    */ 
     60} pj_cis_t; 
     61 
     62/** 
     63 * Initialize scanner input specification buffer. 
     64 * 
     65 * @param cs_buf    The scanner character specification. 
     66 */ 
     67PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf); 
     68 
     69/** 
     70 * Create a new input specification. 
     71 * 
     72 * @param cs_buf    Specification buffer. 
     73 * @param cis       Character input specification to be initialized. 
     74 * 
     75 * @return          PJ_SUCCESS if new specification has been successfully 
     76 *                  created, or PJ_ETOOMANY if there are already too many 
     77 *                  specifications in the buffer. 
     78 */ 
     79PJ_DECL(pj_status_t) pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis); 
     80 
     81/** 
     82 * Create a new input specification based on an existing specification. 
     83 * 
     84 * @param new_cis   The new specification to be initialized. 
     85 * @param existing  The existing specification, from which the input 
     86 *                  bitmask will be copied to the new specification. 
     87 * 
     88 * @return          PJ_SUCCESS if new specification has been successfully 
     89 *                  created, or PJ_ETOOMANY if there are already too many 
     90 *                  specifications in the buffer. 
     91 */ 
     92PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing); 
     93 
     94/** 
     95 * Set the membership of the specified character. 
     96 * Note that this is a macro, and arguments may be evaluated more than once. 
     97 * 
     98 * @param cis       Pointer to character input specification. 
     99 * @param c         The character. 
     100 */ 
     101#define PJ_CIS_SET(cis,c)   ((cis)->cis_buf[(c)] |= (1 << (cis)->cis_id)) 
     102 
     103/** 
     104 * Remove the membership of the specified character. 
     105 * Note that this is a macro, and arguments may be evaluated more than once. 
     106 * 
     107 * @param cis       Pointer to character input specification. 
     108 * @param c         The character to be removed from the membership. 
     109 */ 
     110#define PJ_CIS_CLR(cis,c)   ((cis)->cis_buf[c] &= ~(1 << (cis)->cis_id)) 
     111 
     112/** 
     113 * Check the membership of the specified character. 
     114 * Note that this is a macro, and arguments may be evaluated more than once. 
     115 * 
     116 * @param cis       Pointer to character input specification. 
     117 * @param c         The character. 
     118 */ 
     119#define PJ_CIS_ISSET(cis,c) ((cis)->cis_buf[c] & (1 << (cis)->cis_id)) 
    61120 
    62121/** 
    63122 * Add the characters in the specified range '[cstart, cend)' to the  
    64123 * specification (the last character itself ('cend') is not added). 
    65  * @param cs the scanner character specification. 
    66  * @param cstart the first character in the range. 
    67  * @param cend the next character after the last character in the range. 
    68  */ 
    69 PJ_DECL(void) pj_cs_add_range( pj_char_spec cs, int cstart, int cend); 
     124 * 
     125 * @param cis       The scanner character specification. 
     126 * @param cstart    The first character in the range. 
     127 * @param cend      The next character after the last character in the range. 
     128 */ 
     129PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend); 
    70130 
    71131/** 
    72132 * Add alphabetic characters to the specification. 
    73  * @param cs the scanner character specification. 
    74  */ 
    75 PJ_DECL(void) pj_cs_add_alpha( pj_char_spec cs); 
     133 * 
     134 * @param cis       The scanner character specification. 
     135 */ 
     136PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis); 
    76137 
    77138/** 
    78139 * Add numeric characters to the specification. 
    79  * @param cs the scanner character specification. 
    80  */ 
    81 PJ_DECL(void) pj_cs_add_num( pj_char_spec cs); 
     140 * 
     141 * @param cis       The scanner character specification. 
     142 */ 
     143PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis); 
    82144 
    83145/** 
    84146 * Add the characters in the string to the specification. 
    85  * @param cs the scanner character specification. 
    86  * @param str the string. 
    87  */ 
    88 PJ_DECL(void) pj_cs_add_str( pj_char_spec cs, const char *str); 
     147 * 
     148 * @param cis       The scanner character specification. 
     149 * @param str       The string. 
     150 */ 
     151PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str); 
    89152 
    90153/** 
    91154 * Delete characters in the specified range from the specification. 
    92  * @param cs the scanner character specification. 
    93  * @param cstart the first character in the range. 
    94  * @param cend the next character after the last character in the range. 
    95  */ 
    96 PJ_DECL(void) pj_cs_del_range( pj_char_spec cs, int cstart, int cend); 
     155 * 
     156 * @param cis       The scanner character specification. 
     157 * @param cstart    The first character in the range. 
     158 * @param cend      The next character after the last character in the range. 
     159 */ 
     160PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend); 
    97161 
    98162/** 
    99163 * Delete characters in the specified string from the specification. 
    100  * @param cs the scanner character specification. 
    101  * @param str the string. 
    102  */ 
    103 PJ_DECL(void) pj_cs_del_str( pj_char_spec cs, const char *str); 
     164 * 
     165 * @param cis       The scanner character specification. 
     166 * @param str       The string. 
     167 */ 
     168PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str); 
    104169 
    105170/** 
    106171 * Invert specification. 
    107  * @param cs the scanner character specification. 
    108  */ 
    109 PJ_DECL(void) pj_cs_invert( pj_char_spec cs ); 
     172 * 
     173 * @param cis       The scanner character specification. 
     174 */ 
     175PJ_DECL(void) pj_cis_invert( pj_cis_t *cis ); 
    110176 
    111177/** 
    112178 * Check whether the specified character belongs to the specification. 
    113  * @param cs the scanner character specification. 
    114  * @param c the character to check for matching. 
    115  */ 
    116 PJ_INLINE(int) pj_cs_match( const pj_char_spec cs, int c ) 
    117 { 
    118     return cs[c]; 
     179 * 
     180 * @param cis       The scanner character specification. 
     181 * @param c         The character to check for matching. 
     182 */ 
     183PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, int c ) 
     184{ 
     185    return PJ_CIS_ISSET(cis, c); 
    119186} 
    120187 
    121 /** 
    122  * @} 
    123  */ 
    124  
    125 /** 
    126  * @defgroup PJ_SCANNER Text Scanner 
    127  * @ingroup PJ_SCAN 
    128  * @{ 
    129  */ 
    130188 
    131189/** 
     
    157215 * The callback function type to be called by the scanner when it encounters 
    158216 * syntax error. 
    159  * @param scanner   The scanner instance that calls the callback . 
     217 * 
     218 * @param scanner       The scanner instance that calls the callback . 
    160219 */ 
    161220typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner); 
     
    245304 */ 
    246305PJ_DECL(int) pj_scan_peek( pj_scanner *scanner, 
    247                             const pj_char_spec spec, pj_str_t *out); 
     306                           const pj_cis_t *spec, pj_str_t *out); 
    248307 
    249308 
     
    262321 */ 
    263322PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner, 
    264                               pj_size_t len, pj_str_t *out); 
     323                             pj_size_t len, pj_str_t *out); 
    265324 
    266325 
     
    278337 */ 
    279338PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner, 
    280                                   const pj_char_spec spec,  
    281                                   pj_str_t *out); 
     339                                 const pj_cis_t *spec,  
     340                                 pj_str_t *out); 
    282341 
    283342 
     
    294353 */ 
    295354PJ_DECL(void) pj_scan_get( pj_scanner *scanner, 
    296                             const pj_char_spec spec, pj_str_t *out); 
     355                           const pj_cis_t *spec, pj_str_t *out); 
    297356 
    298357 
     
    318377 */ 
    319378PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner, 
    320                               unsigned N, pj_str_t *out); 
     379                             unsigned N, pj_str_t *out); 
    321380 
    322381 
     
    326385 * @param scanner   The scanner. 
    327386 * 
    328  * @return (unknown) 
     387 * @return The character. 
    329388 */ 
    330389PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner ); 
     
    349408 */ 
    350409PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner, 
    351                                   const pj_char_spec spec, pj_str_t *out); 
     410                                 const pj_cis_t *spec, pj_str_t *out); 
    352411 
    353412 
     
    361420 */ 
    362421PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,  
    363                                      int until_char, pj_str_t *out); 
     422                                    int until_char, pj_str_t *out); 
    364423 
    365424 
     
    373432 */ 
    374433PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner, 
    375                                       const char *until_spec, pj_str_t *out); 
     434                                     const char *until_spec, pj_str_t *out); 
    376435 
    377436/**  
     
    385444 */ 
    386445PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner, 
    387                                   unsigned N, pj_bool_t skip); 
     446                                 unsigned N, pj_bool_t skip); 
    388447 
    389448 
     
    446505 */ 
    447506 
    448 #if PJ_FUNCTIONS_ARE_INLINED 
    449 #  include "scanner_i.h" 
     507 
     508PJ_END_DECL 
     509 
    450510#endif 
    451511 
    452  
    453 PJ_END_DECL 
    454  
    455 #endif 
    456  
  • pjproject/main/pjlib-util/src/pjlib-util/scanner.c

    r32 r43  
    55#include <pj/except.h> 
    66#include <pj/os.h> 
     7#include <pj/errno.h> 
    78 
    89#define PJ_SCAN_IS_SPACE(c)     ((c)==' ' || (c)=='\t') 
     
    1617} 
    1718 
    18 PJ_DEF(void) pj_cs_init( pj_char_spec cs) 
    19 { 
    20     PJ_CHECK_STACK(); 
    21     memset(cs, 0, sizeof(cs)); 
    22 } 
    23  
    24 PJ_DEF(void) pj_cs_set( pj_char_spec cs, int c) 
    25 { 
    26     PJ_CHECK_STACK(); 
    27     cs[c] = 1; 
    28 } 
    29  
    30 PJ_DEF(void) pj_cs_add_range( pj_char_spec cs, int cstart, int cend) 
    31 { 
    32     PJ_CHECK_STACK(); 
    33     while (cstart != cend) 
    34         cs[cstart++] = 1; 
    35 } 
    36  
    37 PJ_DEF(void) pj_cs_add_alpha( pj_char_spec cs) 
    38 { 
    39     pj_cs_add_range( cs, 'a', 'z'+1); 
    40     pj_cs_add_range( cs, 'A', 'Z'+1); 
    41 } 
    42  
    43 PJ_DEF(void) pj_cs_add_num( pj_char_spec cs) 
    44 { 
    45     pj_cs_add_range( cs, '0', '9'+1); 
    46 } 
    47  
    48 PJ_DEF(void) pj_cs_add_str( pj_char_spec cs, const char *str) 
    49 { 
    50     PJ_CHECK_STACK(); 
     19PJ_DEF(void) pj_cis_buf_init( pj_cis_buf_t *cis_buf) 
     20{ 
     21    pj_memset(cis_buf->cis_buf, 0, sizeof(cis_buf->cis_buf)); 
     22    cis_buf->use_mask = 0; 
     23} 
     24 
     25PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis) 
     26{ 
     27    unsigned i; 
     28 
     29    cis->cis_buf = cis_buf->cis_buf; 
     30 
     31    for (i=0; i<PJ_CIS_MAX_INDEX; ++i) { 
     32        if ((cis_buf->use_mask & (1 << i)) == 0) { 
     33            cis->cis_index = i; 
     34            return PJ_SUCCESS; 
     35        } 
     36    } 
     37 
     38    cis->cis_index = PJ_CIS_MAX_INDEX; 
     39    return PJ_ETOOMANY; 
     40} 
     41 
     42PJ_DEF(pj_status_t) pj_cis_dup( pj_cis_t *new_cis, pj_cis_t *existing) 
     43{ 
     44    pj_status_t status; 
     45    unsigned i; 
     46 
     47    status = pj_cis_init(existing->cis_buf, new_cis); 
     48    if (status != PJ_SUCCESS) 
     49        return status; 
     50 
     51    for (i=0; i<256; ++i) { 
     52        if (PJ_CIS_ISSET(existing, i)) 
     53            PJ_CIS_SET(new_cis, i); 
     54        else 
     55            PJ_CIS_CLR(new_cis, i); 
     56    } 
     57 
     58    return PJ_SUCCESS; 
     59} 
     60 
     61PJ_DEF(void) pj_cis_add_range(pj_cis_t *cis, int cstart, int cend) 
     62{ 
     63    while (cstart != cend) { 
     64        PJ_CIS_SET(cis, cstart); 
     65        ++cstart; 
     66    } 
     67} 
     68 
     69PJ_DEF(void) pj_cis_add_alpha(pj_cis_t *cis) 
     70{ 
     71    pj_cis_add_range( cis, 'a', 'z'+1); 
     72    pj_cis_add_range( cis, 'A', 'Z'+1); 
     73} 
     74 
     75PJ_DEF(void) pj_cis_add_num(pj_cis_t *cis) 
     76{ 
     77    pj_cis_add_range( cis, '0', '9'+1); 
     78} 
     79 
     80PJ_DEF(void) pj_cis_add_str( pj_cis_t *cis, const char *str) 
     81{ 
    5182    while (*str) { 
    52         cs[(int)*str] = 1; 
     83        PJ_CIS_SET(cis, *str); 
    5384        ++str; 
    5485    } 
    5586} 
    5687 
    57 PJ_DEF(void) pj_cs_del_range( pj_char_spec cs, int cstart, int cend) 
    58 { 
    59     PJ_CHECK_STACK(); 
    60     while (cstart != cend) 
    61         cs[cstart++] = 0; 
    62 } 
    63  
    64 PJ_DEF(void) pj_cs_del_str( pj_char_spec cs, const char *str) 
    65 { 
    66     PJ_CHECK_STACK(); 
     88PJ_DEF(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend) 
     89{ 
     90    while (cstart != cend) { 
     91        PJ_CIS_CLR(cis, cstart); 
     92        cstart++; 
     93    } 
     94} 
     95 
     96PJ_DEF(void) pj_cis_del_str( pj_cis_t *cis, const char *str) 
     97{ 
    6798    while (*str) { 
    68         cs[(int)*str] = 0; 
     99        PJ_CIS_CLR(cis, *str); 
    69100        ++str; 
    70101    } 
    71102} 
    72103 
    73 PJ_DEF(void) pj_cs_invert( pj_char_spec cs ) 
     104PJ_DEF(void) pj_cis_invert( pj_cis_t *cis ) 
    74105{ 
    75106    unsigned i; 
    76     PJ_CHECK_STACK(); 
    77     for (i=0; i<sizeof(pj_char_spec)/sizeof(cs[0]); ++i) { 
    78         cs[i] = (pj_char_spec_element_t) !cs[i]; 
     107    for (i=0; i<256; ++i) { 
     108        if (PJ_CIS_ISSET(cis,i)) 
     109            PJ_CIS_CLR(cis,i); 
     110        else 
     111            PJ_CIS_SET(cis,i); 
    79112    } 
    80113} 
     
    166199 
    167200PJ_DEF(int) pj_scan_peek( pj_scanner *scanner, 
    168                            const pj_char_spec spec, pj_str_t *out) 
     201                          const pj_cis_t *spec, pj_str_t *out) 
    169202{ 
    170203    register char *s = scanner->curptr; 
     
    178211    } 
    179212 
    180     while (PJ_SCAN_CHECK_EOF(s) && pj_cs_match(spec, *s)) 
     213    while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)) 
    181214        ++s; 
    182215 
     
    204237 
    205238PJ_DEF(int) pj_scan_peek_until( pj_scanner *scanner, 
    206                                   const pj_char_spec spec,  
    207                                   pj_str_t *out) 
     239                                const pj_cis_t *spec,  
     240                                pj_str_t *out) 
    208241{ 
    209242    register char *s = scanner->curptr; 
     
    217250    } 
    218251 
    219     while (PJ_SCAN_CHECK_EOF(s) && !pj_cs_match( spec, *s)) 
     252    while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match( spec, *s)) 
    220253        ++s; 
    221254 
     
    226259 
    227260PJ_DEF(void) pj_scan_get( pj_scanner *scanner, 
    228                            const pj_char_spec spec, pj_str_t *out) 
     261                          const pj_cis_t *spec, pj_str_t *out) 
    229262{ 
    230263    register char *s = scanner->curptr; 
     
    234267    PJ_CHECK_STACK(); 
    235268 
    236     if (pj_scan_is_eof(scanner) || !pj_cs_match(spec, *s)) { 
     269    if (pj_scan_is_eof(scanner) || !pj_cis_match(spec, *s)) { 
    237270        pj_scan_syntax_err(scanner); 
    238271        return; 
     
    241274    do { 
    242275        ++s; 
    243     } while (PJ_SCAN_CHECK_EOF(s) && pj_cs_match(spec, *s)); 
     276    } while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)); 
    244277 
    245278    pj_strset3(out, scanner->curptr, s); 
     
    396429 
    397430PJ_DEF(void) pj_scan_get_until( pj_scanner *scanner, 
    398                                  const pj_char_spec spec, pj_str_t *out) 
     431                                const pj_cis_t *spec, pj_str_t *out) 
    399432{ 
    400433    register char *s = scanner->curptr; 
     
    409442    } 
    410443 
    411     while (PJ_SCAN_CHECK_EOF(s) && !pj_cs_match(spec, *s)) { 
     444    while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match(spec, *s)) { 
    412445        ++s; 
    413446    } 
     
    425458 
    426459PJ_DEF(void) pj_scan_get_until_ch( pj_scanner *scanner,  
    427                                     int until_char, pj_str_t *out) 
     460                                   int until_char, pj_str_t *out) 
    428461{ 
    429462    register char *s = scanner->curptr; 
  • pjproject/main/pjlib/build/pjlib.dsw

    r36 r43  
    2424Package=<4> 
    2525{{{ 
     26}}} 
     27 
     28############################################################################### 
     29 
     30Project: "pjlib++_test"=".\pjlib++-test.dsp" - Package Owner=<4> 
     31 
     32Package=<5> 
     33{{{ 
     34}}} 
     35 
     36Package=<4> 
     37{{{ 
     38    Begin Project Dependency 
     39    Project_Dep_Name pjlib 
     40    End Project Dependency 
     41    Begin Project Dependency 
     42    Project_Dep_Name pjlib++ 
     43    End Project Dependency 
    2644}}} 
    2745 
     
    5876############################################################################### 
    5977 
    60 Project: "pjlib++_test"=.\pjlib++-test.dsp - Package Owner=<4> 
    61  
    62 Package=<5> 
    63 {{{ 
    64 }}} 
    65  
    66 Package=<4> 
    67 {{{ 
    68     Begin Project Dependency 
    69     Project_Dep_Name pjlib 
    70     End Project Dependency 
    71     Begin Project Dependency 
    72     Project_Dep_Name pjlib++ 
    73     End Project Dependency 
    74 }}} 
    75  
    76 ############################################################################### 
    77  
    7878Global: 
    7979 
  • pjproject/main/pjlib/include/pj++/file.hpp

    r36 r43  
    1 /* $Id$ */ 
    2  
     1/* $Id$  
     2 */ 
    33#ifndef __PJPP_FILE_HPP__ 
    44#define __PJPP_FILE_HPP__ 
  • pjproject/main/pjlib/include/pj++/hash.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_HASH_H__ 
    4 #define __PJPP_HASH_H__ 
     3#ifndef __PJPP_HASH_HPP__ 
     4#define __PJPP_HASH_HPP__ 
    55 
    66#include <pj++/types.hpp> 
     
    136136 
    137137 
    138 #endif  /* __PJPP_HASH_H__ */ 
     138#endif  /* __PJPP_HASH_HPP__ */ 
    139139 
  • pjproject/main/pjlib/include/pj++/list.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_LIST_H__ 
    4 #define __PJPP_LIST_H__ 
     3#ifndef __PJPP_LIST_HPP__ 
     4#define __PJPP_LIST_HPP__ 
    55 
    66#include <pj/list.h> 
     
    308308 
    309309 
    310 #endif  /* __PJPP_LIST_H__ */ 
     310#endif  /* __PJPP_LIST_HPP__ */ 
     311 
  • pjproject/main/pjlib/include/pj++/lock.hpp

    r36 r43  
    1 /* $Id$ */ 
    2 #ifndef __PJPP_LOCK_H__ 
    3 #define __PJPP_LOCK_H__ 
     1/* $Id$  
     2 */ 
     3#ifndef __PJPP_LOCK_HPP__ 
     4#define __PJPP_LOCK_HPP__ 
    45 
    56#include <pj++/types.hpp> 
     
    128129 
    129130 
    130 #endif  /* __PJPP_LOCK_H__ */ 
     131#endif  /* __PJPP_LOCK_HPP__ */ 
    131132 
  • pjproject/main/pjlib/include/pj++/os.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_OS_H__ 
    4 #define __PJPP_OS_H__ 
     3#ifndef __PJPP_OS_HPP__ 
     4#define __PJPP_OS_HPP__ 
    55 
    66#include <pj/os.h> 
     
    785785} 
    786786 
    787 #endif  /* __PJPP_OS_H__ */ 
     787#endif  /* __PJPP_OS_HPP__ */ 
     788 
  • pjproject/main/pjlib/include/pj++/pool.hpp

    r37 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_POOL_H__ 
    4 #define __PJPP_POOL_H__ 
     3#ifndef __PJPP_POOL_HPP__ 
     4#define __PJPP_POOL_HPP__ 
    55 
    66#include <pj/pool.h> 
     
    251251 
    252252 
    253 #endif  /* __PJPP_POOL_H__ */ 
     253#endif  /* __PJPP_POOL_HPP__ */ 
     254 
  • pjproject/main/pjlib/include/pj++/proactor.hpp

    r37 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_PROACTOR_H__ 
    4 #define __PJPP_PROACTOR_H__ 
     3#ifndef __PJPP_PROACTOR_HPP__ 
     4#define __PJPP_PROACTOR_HPP__ 
    55 
    66#include <pj/ioqueue.h> 
     
    3030        : handler_(NULL) 
    3131    { 
     32        pj_ioqueue_op_key_init(this, sizeof(*this)); 
    3233    } 
    3334 
     
    3839        : handler_(handler) 
    3940    { 
    40         pj_memset(this, 0, sizeof(pj_ioqueue_op_key_t)); 
     41        pj_ioqueue_op_key_init(this, sizeof(*this)); 
    4142    } 
    4243 
     
    498499}; 
    499500 
    500 #endif  /* __PJPP_PROACTOR_H__ */ 
     501#endif  /* __PJPP_PROACTOR_HPP__ */ 
     502 
  • pjproject/main/pjlib/include/pj++/scanner.hpp

    r36 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    4 #ifndef __PJPP_SCANNER_H__ 
    5 #define __PJPP_SCANNER_H__ 
     3#ifndef __PJPP_SCANNER_HPP__ 
     4#define __PJPP_SCANNER_HPP__ 
    65 
    76#include <pjlib-util/scanner.h> 
     
    171170}; 
    172171 
    173 #endif  /* __PJPP_SCANNER_H__ */ 
     172#endif  /* __PJPP_SCANNER_HPP__ */ 
     173 
  • pjproject/main/pjlib/include/pj++/sock.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_SOCK_H__ 
    4 #define __PJPP_SOCK_H__ 
     3#ifndef __PJPP_SOCK_HPP__ 
     4#define __PJPP_SOCK_HPP__ 
    55 
    66#include <pj/sock.h> 
     
    424424 
    425425 
    426 #endif  /* __PJPP_SOCK_H__ */ 
     426#endif  /* __PJPP_SOCK_HPP__ */ 
     427 
  • pjproject/main/pjlib/include/pj++/string.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_STRING_H__ 
    4 #define __PJPP_STRING_H__ 
     3#ifndef __PJPP_STRING_HPP__ 
     4#define __PJPP_STRING_HPP__ 
    55 
    66#include <pj/string.h> 
     
    406406}; 
    407407 
    408 #endif  /* __PJPP_STRING_H__ */ 
     408#endif  /* __PJPP_STRING_HPP__ */ 
     409 
  • pjproject/main/pjlib/include/pj++/timer.hpp

    r36 r43  
    11/* $Id$ 
    22 */ 
    3 #ifndef __PJPP_TIMER_H__ 
    4 #define __PJPP_TIMER_H__ 
     3#ifndef __PJPP_TIMER_HPP__ 
     4#define __PJPP_TIMER_HPP__ 
    55 
    66#include <pj/timer.h> 
     
    178178}; 
    179179 
    180 #endif  /* __PJPP_TIMER_H__ */ 
     180#endif  /* __PJPP_TIMER_HPP__ */ 
     181 
  • pjproject/main/pjlib/include/pj++/tree.hpp

    r36 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    4 #ifndef __PJPP_TREE_H__ 
    5 #define __PJPP_TREE_H__ 
     3#ifndef __PJPP_TREE_HPP__ 
     4#define __PJPP_TREE_HPP__ 
    65 
    76#include <pj/rbtree.h> 
     
    110109}; 
    111110 
    112 #endif  /* __PJPP_TREE_H__ */ 
     111#endif  /* __PJPP_TREE_HPP__ */ 
     112 
  • pjproject/main/pjlib/include/pj++/types.hpp

    r36 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    4 #ifndef __PJPP_TYPES_H__ 
    5 #define __PJPP_TYPES_H__ 
     3#ifndef __PJPP_TYPES_HPP__ 
     4#define __PJPP_TYPES_HPP__ 
    65 
    76#include <pj/types.h> 
     
    142141}; 
    143142 
    144 #endif  /* __PJPP_TYPES_H__ */ 
     143#endif  /* __PJPP_TYPES_HPP__ */ 
     144 
  • pjproject/main/pjlib/include/pj/compat/string.h

    r4 r43  
    4141 
    4242 
     43#define pj_native_strcmp        strcmp 
     44#define pj_native_strlen        strlen 
     45#define pj_native_strcpy        strcpy 
     46#define pj_native_strstr        strstr 
     47#define pj_native_strchr        strchr 
     48#define pj_native_strcasecmp    strcasecmp 
     49#define pj_native_strncasecmp   strncasecmp 
     50 
     51 
    4352#endif  /* __PJ_COMPAT_STRING_H__ */ 
  • pjproject/main/pjlib/include/pj/config.h

    r35 r43  
    148148 */ 
    149149#ifndef PJ_LOG_MAX_LEVEL 
    150 #  define PJ_LOG_MAX_LEVEL   4 
     150#  define PJ_LOG_MAX_LEVEL   5 
    151151#endif 
    152152 
     
    404404#endif 
    405405 
     406/** 
     407 * Function attributes to inform that the function may throw exception. 
     408 * 
     409 * @param x     The exception list, enclosed in parenthesis. 
     410 */ 
     411#define __pj_throw__(x) 
     412 
    406413 
    407414/******************************************************************** 
  • pjproject/main/pjlib/include/pj/errno.h

    r36 r43  
    216216 */ 
    217217#define PJ_ECANCELLED       (PJ_ERRNO_START_STATUS + 14) 
     218/** 
     219 * @hideinitializer 
     220 * Object already exists. 
     221 */ 
     222#define PJ_EEXISTS          (PJ_ERRNO_START_STATUS + 14) 
    218223 
    219224/** @} */   /* pj_errnum */ 
  • pjproject/main/pjlib/include/pj/except.h

    r4 r43  
    184184PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id); 
    185185 
     186 
    186187/** @} */ 
    187188 
  • pjproject/main/pjlib/include/pj/hash.h

    r4 r43  
    4545                                  const void *key, unsigned keylen); 
    4646 
     47 
     48/** 
     49 * Convert the key to lowercase and calculate the hash value. The resulting 
     50 * string is stored in \c result. 
     51 * 
     52 * @param hval      The initial hash value, normally zero. 
     53 * @param result    Buffer to store the result, which must be enough to hold 
     54 *                  the string. 
     55 * @param key       The input key to be converted and calculated. 
     56 * 
     57 * @return          The hash value. 
     58 */ 
     59PJ_DECL(pj_uint32_t) pj_hash_calc_tolower(pj_uint32_t hval, 
     60                                          char *result, 
     61                                          const pj_str_t *key); 
    4762 
    4863/** 
  • pjproject/main/pjlib/include/pj/ioqueue.h

    r36 r43  
    342342 
    343343/** 
     344 * Initialize operation key. 
     345 * 
     346 * @param op_key    The operation key to be initialied. 
     347 * @param size      The size of the operation key. 
     348 */ 
     349PJ_DECL(void) pj_ioqueue_op_key_init( pj_ioqueue_op_key_t *op_key, 
     350                                      pj_size_t size ); 
     351 
     352/** 
    344353 * Check if operation is pending on the specified operation key. 
    345  * The \c op_key must have been submitted as pending operation before, 
    346  * or otherwise the result is undefined. 
     354 * The \c op_key must have been initialized with #pj_ioqueue_op_key_init()  
     355 * or submitted as pending operation before, or otherwise the result  
     356 * is undefined. 
    347357 * 
    348358 * @param key       The key. 
  • pjproject/main/pjlib/include/pj/string.h

    r4 r43  
    1313#include <pj/types.h> 
    1414#include <pj/compat/string.h> 
     15#include <pj/compat/sprintf.h> 
     16#include <pj/compat/vsprintf.h> 
     17 
    1518 
    1619PJ_BEGIN_DECL 
  • pjproject/main/pjlib/src/pj/errno.c

    r36 r43  
    3131    { PJ_ENOTSUP,       "Option/operation is not supported"}, 
    3232    { PJ_EINVALIDOP,    "Invalid operation"}, 
    33     { PJ_ECANCELLED,    "Operation cancelled"} 
     33    { PJ_ECANCELLED,    "Operation cancelled"}, 
     34    { PJ_EEXISTS,       "Object already exists" } 
    3435}; 
    3536 
  • pjproject/main/pjlib/src/pj/hash.c

    r6 r43  
    5050    } 
    5151    return hash; 
     52} 
     53 
     54PJ_DEF(pj_uint32_t) pj_hash_calc_tolower( pj_uint32_t hval, 
     55                                          char *result, 
     56                                          const pj_str_t *key) 
     57{ 
     58    long i; 
     59 
     60    for (i=0; i<key->slen; ++i) { 
     61        result[i] = (char)pj_tolower(key->ptr[i]); 
     62        hval = hval * PJ_HASH_MULTIPLIER + result[i]; 
     63    } 
     64 
     65    return hval; 
    5266} 
    5367 
  • pjproject/main/pjlib/src/pj/ioqueue_common_abs.c

    r36 r43  
    834834#endif  /* PJ_HAS_TCP */ 
    835835 
     836 
     837PJ_DEF(void) pj_ioqueue_op_key_init( pj_ioqueue_op_key_t *op_key, 
     838                                     pj_size_t size ) 
     839{ 
     840    pj_memset(op_key, 0, size); 
     841} 
     842 
     843 
    836844/* 
    837845 * pj_ioqueue_is_pending() 
  • pjproject/main/pjlib/src/pj/ioqueue_winnt.c

    r36 r43  
    893893 
    894894 
     895PJ_DEF(void) pj_ioqueue_op_key_init( pj_ioqueue_op_key_t *op_key, 
     896                                     pj_size_t size ) 
     897{ 
     898    pj_memset(op_key, 0, size); 
     899} 
    895900 
    896901PJ_DEF(pj_bool_t) pj_ioqueue_is_pending( pj_ioqueue_key_t *key, 
  • pjproject/main/pjsip/bin

    • Property svn:ignore set to
      *
  • pjproject/main/pjsip/build

    • Property svn:ignore
      •  

        old new  
        22*.ncb 
        33*.plg 
         4TODO-LIST.TXT 
  • pjproject/main/pjsip/build/output

    • Property svn:ignore set to
      *
  • pjproject/main/pjsip/build/pjsip_core.dsp

    r1 r43  
    3333# PROP BASE Use_MFC 0 
    3434# PROP BASE Use_Debug_Libraries 0 
    35 # PROP BASE Output_Dir "Release" 
    36 # PROP BASE Intermediate_Dir "Release" 
     35# PROP BASE Output_Dir ".\output\pjsip-core-i386-win32-vc6-release" 
     36# PROP BASE Intermediate_Dir ".\output\pjsip-core-i386-win32-vc6-release" 
    3737# PROP BASE Target_Dir "" 
    3838# PROP Use_MFC 0 
    3939# PROP Use_Debug_Libraries 0 
    40 # PROP Output_Dir ".\output\pjsip_core_vc6_Release" 
    41 # PROP Intermediate_Dir ".\output\pjsip_core_vc6_Release" 
     40# PROP Output_Dir ".\output\pjsip-core-i386-win32-vc6-release" 
     41# PROP Intermediate_Dir ".\output\pjsip-core-i386-win32-vc6-release" 
    4242# PROP Target_Dir "" 
    4343# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    44 # ADD CPP /nologo /MD /W4 /Zi /O2 /I "../src" /I "../../pjlib/src" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FR /FD /c 
     44# ADD CPP /nologo /MD /W4 /Zi /O2 /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /c 
    4545# SUBTRACT CPP /YX 
    4646# ADD BASE RSC /l 0x409 /d "NDEBUG" 
     
    5151LIB32=link.exe -lib 
    5252# ADD BASE LIB32 /nologo 
    53 # ADD LIB32 /nologo /out:"../lib/pjsip_core_vc6s.lib" 
     53# ADD LIB32 /nologo /out:"../lib/pjsip-core-i386-win32-vc6-release.lib" 
    5454 
    5555!ELSEIF  "$(CFG)" == "pjsip_core - Win32 Debug" 
     
    5757# PROP BASE Use_MFC 0 
    5858# PROP BASE Use_Debug_Libraries 1 
    59 # PROP BASE Output_Dir "Debug" 
    60 # PROP BASE Intermediate_Dir "Debug" 
     59# PROP BASE Output_Dir ".\output\pjsip-core-i386-win32-vc6-debug" 
     60# PROP BASE Intermediate_Dir ".\output\pjsip-core-i386-win32-vc6-debug" 
    6161# PROP BASE Target_Dir "" 
    6262# PROP Use_MFC 0 
    6363# PROP Use_Debug_Libraries 1 
    64 # PROP Output_Dir ".\output\pjsip_core_vc6_Debug" 
    65 # PROP Intermediate_Dir ".\output\pjsip_core_vc6_Debug" 
     64# PROP Output_Dir ".\output\pjsip-core-i386-win32-vc6-debug" 
     65# PROP Intermediate_Dir ".\output\pjsip-core-i386-win32-vc6-debug" 
    6666# PROP Target_Dir "" 
    6767# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    68 # ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../src" /I "../../pjlib/src" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /c 
     68# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /GZ /c 
    6969# SUBTRACT CPP /YX 
    7070# ADD BASE RSC /l 0x409 /d "_DEBUG" 
     
    7575LIB32=link.exe -lib 
    7676# ADD BASE LIB32 /nologo 
    77 # ADD LIB32 /nologo /out:"../lib/pjsip_core_vc6sd.lib" 
     77# ADD LIB32 /nologo /out:"../lib/pjsip-core-i386-win32-vc6-debug.lib" 
    7878 
    7979!ENDIF  
     
    136136# Begin Source File 
    137137 
    138 SOURCE=..\src\pjsip_core.h 
    139 # End Source File 
    140 # Begin Source File 
    141  
    142 SOURCE=..\src\pjsip\print.h 
    143 # End Source File 
    144 # Begin Source File 
    145  
    146 SOURCE=..\src\pjsip\sip_auth.h 
    147 # End Source File 
    148 # Begin Source File 
    149  
    150 SOURCE=..\src\pjsip\sip_auth_msg.h 
    151 # End Source File 
    152 # Begin Source File 
    153  
    154 SOURCE=..\src\pjsip\sip_auth_parser.h 
    155 # End Source File 
    156 # Begin Source File 
    157  
    158 SOURCE=..\src\pjsip\sip_config.h 
    159 # End Source File 
    160 # Begin Source File 
    161  
    162 SOURCE=..\src\pjsip\sip_endpoint.h 
    163 # End Source File 
    164 # Begin Source File 
    165  
    166 SOURCE=..\src\pjsip\sip_event.h 
    167 # End Source File 
    168 # Begin Source File 
    169  
    170 SOURCE=..\src\pjsip\sip_misc.h 
    171 # End Source File 
    172 # Begin Source File 
    173  
    174 SOURCE=..\src\pjsip\sip_module.h 
    175 # End Source File 
    176 # Begin Source File 
    177  
    178 SOURCE=..\src\pjsip\sip_msg.h 
    179 # End Source File 
    180 # Begin Source File 
    181  
    182 SOURCE=..\src\pjsip\sip_parser.h 
    183 # End Source File 
    184 # Begin Source File 
    185  
    186 SOURCE=..\src\pjsip\sip_private.h 
    187 # End Source File 
    188 # Begin Source File 
    189  
    190 SOURCE=..\src\pjsip\sip_resolve.h 
    191 # End Source File 
    192 # Begin Source File 
    193  
    194 SOURCE=..\src\pjsip\sip_transaction.h 
    195 # End Source File 
    196 # Begin Source File 
    197  
    198 SOURCE=..\src\pjsip\sip_transport.h 
    199 # End Source File 
    200 # Begin Source File 
    201  
    202 SOURCE=..\src\pjsip\sip_types.h 
    203 # End Source File 
    204 # Begin Source File 
    205  
    206 SOURCE=..\src\pjsip\sip_uri.h 
     138SOURCE=..\include\pjsip_core.h 
     139# End Source File 
     140# Begin Source File 
     141 
     142SOURCE=..\include\pjsip\print_util.h 
     143# End Source File 
     144# Begin Source File 
     145 
     146SOURCE=..\include\pjsip\sip_auth.h 
     147# End Source File 
     148# Begin Source File 
     149 
     150SOURCE=..\include\pjsip\sip_auth_msg.h 
     151# End Source File 
     152# Begin Source File 
     153 
     154SOURCE=..\include\pjsip\sip_auth_parser.h 
     155# End Source File 
     156# Begin Source File 
     157 
     158SOURCE=..\include\pjsip\sip_config.h 
     159# End Source File 
     160# Begin Source File 
     161 
     162SOURCE=..\include\pjsip\sip_endpoint.h 
     163# End Source File 
     164# Begin Source File 
     165 
     166SOURCE=..\include\pjsip\sip_errno.h 
     167# End Source File 
     168# Begin Source File 
     169 
     170SOURCE=..\include\pjsip\sip_event.h 
     171# End Source File 
     172# Begin Source File 
     173 
     174SOURCE=..\include\pjsip\sip_misc.h 
     175# End Source File 
     176# Begin Source File 
     177 
     178SOURCE=..\include\pjsip\sip_module.h 
     179# End Source File 
     180# Begin Source File 
     181 
     182SOURCE=..\include\pjsip\sip_msg.h 
     183# End Source File 
     184# Begin Source File 
     185 
     186SOURCE=..\include\pjsip\sip_parser.h 
     187# End Source File 
     188# Begin Source File 
     189 
     190SOURCE=..\include\pjsip\sip_private.h 
     191# End Source File 
     192# Begin Source File 
     193 
     194SOURCE=..\include\pjsip\sip_resolve.h 
     195# End Source File 
     196# Begin Source File 
     197 
     198SOURCE=..\include\pjsip\sip_transaction.h 
     199# End Source File 
     200# Begin Source File 
     201 
     202SOURCE=..\include\pjsip\sip_transport.h 
     203# End Source File 
     204# Begin Source File 
     205 
     206SOURCE=..\include\pjsip\sip_types.h 
     207# End Source File 
     208# Begin Source File 
     209 
     210SOURCE=..\include\pjsip\sip_uri.h 
    207211# End Source File 
    208212# End Group 
     
    212216# Begin Source File 
    213217 
    214 SOURCE=..\src\pjsip\sip_msg_i.h 
     218SOURCE=..\include\pjsip\sip_msg_i.h 
    215219# End Source File 
    216220# End Group 
  • pjproject/main/pjsip/build/pjsip_ua.dsp

    r1 r43  
    8888# Begin Source File 
    8989 
    90 SOURCE=..\src\pjsip_mod_ua\sip_dialog.c 
     90SOURCE="..\src\pjsip-ua\sip_dialog.c" 
    9191# End Source File 
    9292# Begin Source File 
    9393 
    94 SOURCE=..\src\pjsip_mod_ua\sip_reg.c 
     94SOURCE="..\src\pjsip-ua\sip_reg.c" 
    9595# End Source File 
    9696# Begin Source File 
    9797 
    98 SOURCE=..\src\pjsip_mod_ua\sip_ua.c 
     98SOURCE="..\src\pjsip-ua\sip_ua.c" 
     99# End Source File 
     100# Begin Source File 
     101 
     102SOURCE="..\src\pjsip-ua\sip_ua_private.h" 
    99103# End Source File 
    100104# End Group 
  • pjproject/main/pjsip/docs

    • Property svn:ignore set to
      html
      latex
      rtf
  • pjproject/main/pjsip/include/pjsip/print_util.h

    • Property svn:keywords set to Id
    r35 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_PRINT_H__ 
  • pjproject/main/pjsip/include/pjsip/sip_auth.h

    • Property svn:keywords set to Id
    r42 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_AUTH_SIP_AUTH_H__ 
     
    6160typedef struct pjsip_cached_auth_hdr 
    6261{ 
    63     PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr) 
     62    PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr); 
    6463 
    6564    pjsip_method             method; 
     
    8180typedef struct pjsip_auth_session 
    8281{ 
    83     PJ_DECL_LIST_MEMBER(struct pjsip_auth_session) 
     82    PJ_DECL_LIST_MEMBER(struct pjsip_auth_session); 
    8483 
    8584    pj_str_t                     realm; 
  • pjproject/main/pjsip/include/pjsip/sip_auth_msg.h

    • Property svn:keywords set to Id
    r42 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_AUTH_SIP_AUTH_MSG_H__ 
     
    6968struct pjsip_authorization_hdr 
    7069{ 
    71     PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr) 
     70    PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr); 
    7271    pj_str_t scheme; 
    7372    union 
     
    158157struct pjsip_www_authenticate_hdr 
    159158{ 
    160     PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr) 
     159    PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr); 
    161160    pj_str_t    scheme; 
    162161    union 
  • pjproject/main/pjsip/include/pjsip/sip_auth_parser.h

    • Property svn:keywords set to Id
    r42 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_AUTH_SIP_AUTH_PARSER_H__ 
     
    2524 * such as Authorization, WWW-Authenticate, Proxy-Authorizization, and  
    2625 * Proxy-Authenticate headers. 
     26 * 
     27 * @return      PJ_SUCCESS or the appropriate status code. 
    2728 */ 
    28 PJ_DECL(void) pjsip_auth_init_parser(); 
     29PJ_DECL(pj_status_t) pjsip_auth_init_parser(void); 
    2930 
    3031/** 
  • pjproject/main/pjsip/include/pjsip/sip_config.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_CONFIG_H__ 
     
    134133 
    135134#include <pj/config.h> 
    136 #include <pj/compat.h> 
    137135 
    138136 
  • pjproject/main/pjsip/include/pjsip/sip_endpoint.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_ENDPOINT_H__ 
     
    2928 * all SIP objects in an application. It performs the following roles: 
    3029 *  - it manages the allocation/deallocation of memory pools for all objects. 
    31  *  - it manages listeners and transports, and how they are used by transactions. 
     30 *  - it manages listeners and transports, and how they are used by  
     31 *    transactions. 
    3232 *  - it owns transaction hash table. 
    3333 *  - it receives incoming messages from transport layer and automatically 
     
    3535 *  - it has a single instance of timer management (timer heap). 
    3636 *  - it manages modules, which is the primary means of extending the library. 
    37  *  - it provides single polling function for all objects and distributes events. 
     37 *  - it provides single polling function for all objects and distributes  
     38 *    events. 
    3839 *  - it provides SIP policy such as which outbound proxy to use for all 
    3940 *    outgoing SIP request messages. 
     
    5051/** 
    5152 * Create an instance of SIP endpoint from the specified pool factory. 
    52  * The pool factory reference then will be kept by the endpoint, so that future 
    53  * memory allocations by SIP components will be taken from the same pool factory. 
    54  * 
    55  * @param pf    Pool factory that will be used for the lifetime of endpoint. 
    56  * 
    57  * @return the endpoint instance on success. 
    58  */ 
    59 PJ_DECL(pjsip_endpoint*) pjsip_endpt_create(pj_pool_factory *pf); 
     53 * The pool factory reference then will be kept by the endpoint, so that  
     54 * future memory allocations by SIP components will be taken from the same 
     55 * pool factory. 
     56 * 
     57 * @param pf            Pool factory that will be used for the lifetime of  
     58 *                      endpoint. 
     59 * @param name          Optional name to be specified for the endpoint. 
     60 *                      If this parameter is NULL, then the name will use 
     61 *                      local host name. 
     62 * @param endpt         Pointer to receive endpoint instance. 
     63 * 
     64 * @return              PJ_SUCCESS on success. 
     65 */ 
     66PJ_DECL(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf, 
     67                                        pjsip_endpoint **endpt); 
    6068 
    6169/** 
     
    6775 */ 
    6876PJ_DECL(void) pjsip_endpt_destroy(pjsip_endpoint *endpt); 
     77 
     78/** 
     79 * Get endpoint name. 
     80 * 
     81 * @param endpt         The SIP endpoint instance. 
     82 * 
     83 * @return              Endpoint name, as was registered during endpoint 
     84 *                      creation. The string is NULL terminated. 
     85 */ 
     86PJ_DECL(const pj_str_t*) pjsip_endpt_name(const pjsip_endpoint *endpt); 
    6987 
    7088/** 
     
    155173 * 
    156174 * @param endpt     The SIP endpoint. 
    157  * @return          The new transaction, or NULL on failure. 
    158  */ 
    159 PJ_DECL(pjsip_transaction*) pjsip_endpt_create_tsx(pjsip_endpoint *endpt); 
     175 * @param p_tsx     Pointer to receive the transaction. 
     176 * 
     177 * @return          PJ_SUCCESS or the appropriate error code. 
     178 */ 
     179PJ_DECL(pj_status_t) pjsip_endpt_create_tsx(pjsip_endpoint *endpt, 
     180                                            pjsip_transaction **p_tsx); 
    160181 
    161182/** 
     
    188209 * This function, like all other endpoint functions, is thread safe. 
    189210 * 
    190  * @param endpt the endpoint. 
    191  * @return new transmit data. 
    192  */ 
    193 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_tdata( pjsip_endpoint *endpt ); 
     211 * @param endpt     The endpoint. 
     212 * @param p_tdata    Pointer to receive transmit data buffer. 
     213 * 
     214 * @return          PJ_SUCCESS or the appropriate error code. 
     215 */ 
     216PJ_DECL(pj_status_t) pjsip_endpt_create_tdata( pjsip_endpoint *endpt, 
     217                                               pjsip_tx_data **p_tdata); 
    194218 
    195219/** 
     
    333357 
    334358/** 
     359 * Log an error. 
     360 */ 
     361PJ_DECL(void) pjsip_endpt_log_error( pjsip_endpoint *endpt, 
     362                                     const char *sender, 
     363                                     pj_status_t error_code, 
     364                                     const char *format, 
     365                                     ... ); 
     366 
     367#define PJSIP_ENDPT_LOG_ERROR(expr)   \ 
     368            pjsip_endpt_log_error expr 
     369 
     370#define PJSIP_ENDPT_TRACE(tracing,expr) \ 
     371            do {                        \ 
     372                if ((tracing))          \ 
     373                    PJ_LOG(4,expr);     \ 
     374            } while (0) 
     375 
     376/** 
    335377 * @} 
    336378 */ 
  • pjproject/main/pjsip/include/pjsip/sip_event.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_EVENT_H__ 
     
    2625{ 
    2726    /** Unidentified event. */ 
    28     PJSIP_EVENT_UNIDENTIFIED, 
     27    PJSIP_EVENT_UNKNOWN, 
    2928 
    3029    /** Timer event, normally only used internally in transaction. */ 
     
    4140 
    4241    /** Transaction state changed event. */ 
    43     PJSIP_EVENT_TSX_STATE_CHANGED, 
     42    PJSIP_EVENT_TSX_STATE, 
    4443 
    4544    /** 2xx response received event. */ 
    46     PJSIP_EVENT_RX_200_RESPONSE, 
     45    PJSIP_EVENT_RX_200_MSG, 
    4746 
    4847    /** ACK request received event. */ 
     
    5655 
    5756    /** On before transmitting message. */ 
    58     PJSIP_EVENT_BEFORE_TX, 
     57    PJSIP_EVENT_PRE_TX_MSG, 
    5958 
    6059} pjsip_event_id_e; 
     
    7776{ 
    7877    /** This is necessary so that we can put events as a list. */ 
    79     PJ_DECL_LIST_MEMBER(struct pjsip_event) 
     78    PJ_DECL_LIST_MEMBER(struct pjsip_event); 
    8079 
    8180    /** The event type, can be any value of \b pjsip_event_id_e. 
    82      *  @see pjsip_event_id_e 
    8381     */ 
    8482    pjsip_event_id_e type; 
    8583 
    86     /** This field determines what is the content of \b src (source data).  
    87      */ 
    88     pjsip_event_id_e src_type; 
    89  
    90     /** Source data, which content is dependent on \b src_type. 
    91      *  - if src_type==PJSIP_EVENT_RX_MSG, src.rdata is valid. 
    92      *  - if src_type==PJSIP_EVENT_TX_MSG, src.tdata is valid. 
    93      *  - if src_type==PJSIP_EVENT_TIMER, src.timer is valid. 
     84    /* 
     85     * The event body. 
     86     * By convention, the first member of each struct in the union must be 
     87     * the pointer which is relevant to the event. 
    9488     */ 
    9589    union 
    9690    { 
    97         pjsip_rx_data   *rdata; 
    98         pjsip_tx_data   *tdata; 
    99         pj_timer_entry  *timer; 
    100         void            *data; 
    101         unsigned long    udata; 
    102     } src; 
    103  
    104     /** The object that generates this event. */ 
    105     union 
    106     { 
    107         pjsip_transaction  *tsx; 
    108         void               *ptr; 
    109         unsigned long       udata; 
    110     } obj; 
    111  
    112     /** Other data. */ 
    113     union 
    114     { 
    115         long                long_data; 
    116         void *              ptr_data; 
    117     } data; 
     91        /** Timer event. */ 
     92        struct 
     93        { 
     94            pj_timer_entry *entry;      /**< The timer entry.           */ 
     95        } timer; 
     96 
     97        /** Transaction state has changed event. */ 
     98        struct 
     99        { 
     100            union 
     101            { 
     102                pjsip_rx_data   *rdata; /**< The incoming message.      */ 
     103                pjsip_tx_data   *tdata; /**< The outgoing message.      */ 
     104                pj_timer_entry  *timer; /**< The timer.                 */ 
     105                pj_status_t      status;/**< Transport error status.    */ 
     106                void            *data;  /**< Generic data.              */ 
     107            } src; 
     108            pjsip_transaction   *tsx;   /**< The transaction.           */ 
     109            pjsip_event_id_e    type;   /**< Type of event source:       
     110                                         *      - PJSIP_EVENT_TX_MSG 
     111                                         *      - PJSIP_EVENT_RX_MSG, 
     112                                         *      - PJSIP_EVENT_TRANSPORT_ERROR 
     113                                         *      - PJSIP_EVENT_TIMER 
     114                                         *      - PJSIP_EVENT_USER 
     115                                         */ 
     116        } tsx_state; 
     117 
     118        /** Message transmission event. */ 
     119        struct 
     120        { 
     121            pjsip_tx_data       *tdata; /**< The transmit data buffer.  */ 
     122            pjsip_transaction   *tsx;   /**< The transaction.           */ 
     123 
     124        } tx_msg; 
     125 
     126        /** Pre-transmission event. */ 
     127        struct 
     128        { 
     129            pjsip_tx_data       *tdata; /**< Msg to be transmitted.     */ 
     130            pjsip_transaction   *tsx;   /**< The transaction.           */ 
     131            int                  retcnt;/**< Retransmission count.      */ 
     132        } pre_tx_msg; 
     133 
     134        /** Transmission error event. */ 
     135        struct 
     136        { 
     137            pjsip_tx_data       *tdata; /**< The transmit data.         */ 
     138            pjsip_transaction   *tsx;   /**< The transaction.           */ 
     139        } tx_error; 
     140 
     141        /** Message arrival event. */ 
     142        struct 
     143        { 
     144            pjsip_rx_data       *rdata; /**< The receive data buffer.   */ 
     145            pjsip_transaction   *tsx;   /**< The transaction.           */ 
     146        } rx_msg; 
     147 
     148        /** Receipt of 200/INVITE response. */ 
     149        struct 
     150        { 
     151            pjsip_rx_data       *rdata; /**< The 200 response msg.      */ 
     152        } rx_200_msg; 
     153 
     154        /** Receipt of ACK message. */ 
     155        struct 
     156        { 
     157            pjsip_rx_data       *rdata; /**< The ack message.           */ 
     158        } rx_ack_msg; 
     159 
     160        /** Notification that endpoint has discarded a message. */ 
     161        struct 
     162        { 
     163            pjsip_rx_data       *rdata; /**< The discarded message.     */ 
     164            pj_status_t          reason;/**< The reason.                */ 
     165        } discard_msg; 
     166 
     167        /** User event. */ 
     168        struct 
     169        { 
     170            void                *user1; /**< User data 1.               */ 
     171            void                *user2; /**< User data 2.               */ 
     172            void                *user3; /**< User data 3.               */ 
     173            void                *user4; /**< User data 4.               */ 
     174        } user; 
     175 
     176    } body; 
    118177}; 
     178 
     179/** 
     180 * Init timer event. 
     181 */ 
     182#define PJSIP_EVENT_INIT_TIMER(event,pentry)            \ 
     183        do { \ 
     184            (event).type = PJSIP_EVENT_TIMER;           \ 
     185            (event).body.timer.entry = pentry;          \ 
     186        } while (0) 
     187 
     188/** 
     189 * Init tsx state event. 
     190 */ 
     191#define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata)   \ 
     192        do { \ 
     193            (event).type = PJSIP_EVENT_TSX_STATE;           \ 
     194            (event).body.tsx_state.tsx = ptsx;              \ 
     195            (event).body.tsx_state.type = ptype;            \ 
     196            (event).body.tsx_state.src.data = pdata;        \ 
     197        } while (0) 
     198 
     199/** 
     200 * Init tx msg event. 
     201 */ 
     202#define PJSIP_EVENT_INIT_TX_MSG(event,ptsx,ptdata)      \ 
     203        do { \ 
     204            (event).type = PJSIP_EVENT_TX_MSG;          \ 
     205            (event).body.tx_msg.tsx = ptsx;             \ 
     206            (event).body.tx_msg.tdata = ptdata;         \ 
     207        } while (0) 
     208 
     209/** 
     210 * Init rx msg event. 
     211 */ 
     212#define PJSIP_EVENT_INIT_RX_MSG(event,ptsx,prdata)      \ 
     213        do { \ 
     214            (event).type = PJSIP_EVENT_RX_MSG;          \ 
     215            (event).body.rx_msg.tsx = ptsx;             \ 
     216            (event).body.rx_msg.rdata = prdata;         \ 
     217        } while (0) 
     218 
     219/** 
     220 * Init transport error event. 
     221 */ 
     222#define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata)   \ 
     223        do { \ 
     224            (event).type = PJSIP_EVENT_TRANSPORT_ERROR; \ 
     225            (event).body.tx_error.tsx = ptsx;           \ 
     226            (event).body.tx_error.tdata = ptdata;       \ 
     227        } while (0) 
     228 
     229/** 
     230 * Init rx 200/INVITE event. 
     231 */ 
     232#define PJSIP_EVENT_INIT_RX_200_MSG(event,prdata)       \ 
     233        do { \ 
     234            (event).type = PJSIP_EVENT_RX_200_MSG;      \ 
     235            (event).body.rx_200_msg.rdata = prdata;     \ 
     236        } while (0) 
     237 
     238/** 
     239 * Init rx ack msg event. 
     240 */ 
     241#define PJSIP_EVENT_INIT_RX_ACK_MSG(event,prdata)       \ 
     242        do { \ 
     243            (event).type = PJSIP_EVENT_RX_ACK_MSG;      \ 
     244            (event).body.rx_ack_msg.rdata = prdata;     \ 
     245        } while (0) 
     246 
     247/** 
     248 * Init discard msg event. 
     249 */ 
     250#define PJSIP_EVENT_INIT_DISCARD_MSG(event,prdata,preason)  \ 
     251        do { \ 
     252            (event).type = PJSIP_EVENT_DISCARD_MSG;         \ 
     253            (event).body.discard_msg.rdata = prdata;        \ 
     254            (event).body.discard_msg.reason = preason;      \ 
     255        } while (0) 
     256 
     257/** 
     258 * Init user event. 
     259 */ 
     260#define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4)    \ 
     261        do { \ 
     262            (event).type = PJSIP_EVENT_USER;        \ 
     263            (event).body.user.user1 = (void*)u1;     \ 
     264            (event).body.user.user2 = (void*)u2;     \ 
     265            (event).body.user.user3 = (void*)u3;     \ 
     266            (event).body.user.user4 = (void*)u4;     \ 
     267        } while (0) 
     268 
     269/** 
     270 * Init pre tx msg event. 
     271 */ 
     272#define PJSIP_EVENT_INIT_PRE_TX_MSG(event,ptsx,ptdata,pretcnt) \ 
     273        do { \ 
     274            (event).type = PJSIP_EVENT_PRE_TX_MSG;      \ 
     275            (event).body.pre_tx_msg.tsx = ptsx;         \ 
     276            (event).body.pre_tx_msg.tdata = ptdata;     \ 
     277            (event).body.pre_tx_msg.retcnt = pretcnt;   \ 
     278        } while (0) 
     279 
    119280 
    120281/** 
  • pjproject/main/pjsip/include/pjsip/sip_misc.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_MISC_H__ 
     
    3130 * @param cseq      Optional CSeq (put -1 to generate random CSeq). 
    3231 * @param text      Optional text body (put NULL to omit body). 
     32 * @param p_tdata   Pointer to receive the transmit data. 
    3333 * 
    34  * @return          The transmit data. 
     34 * @return          PJ_SUCCESS, or the appropriate error code. 
    3535 */ 
    36 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_request( pjsip_endpoint *endpt,  
    37                                                     const pjsip_method *method, 
    38                                                     const pj_str_t *target, 
    39                                                     const pj_str_t *from, 
    40                                                     const pj_str_t *to,  
    41                                                     const pj_str_t *contact, 
    42                                                     const pj_str_t *call_id, 
    43                                                     int cseq,  
    44                                                     const pj_str_t *text); 
     36PJ_DECL(pj_status_t) pjsip_endpt_create_request( pjsip_endpoint *endpt,  
     37                                                 const pjsip_method *method, 
     38                                                 const pj_str_t *target, 
     39                                                 const pj_str_t *from, 
     40                                                 const pj_str_t *to,  
     41                                                 const pj_str_t *contact, 
     42                                                 const pj_str_t *call_id, 
     43                                                 int cseq,  
     44                                                 const pj_str_t *text, 
     45                                                 pjsip_tx_data **p_tdata); 
    4546 
    4647/** 
     
    5960 * @param cseq      Optional CSeq (put -1 to generate random CSeq). 
    6061 * @param text      Optional text body (put NULL to omit body). 
     62 * @param p_tdata   Pointer to receive the transmit data. 
    6163 * 
    62  * @return          The transmit data. 
     64 * @return          PJ_SUCCESS, or the appropriate error code. 
    6365 */ 
    64 PJ_DECL(pjsip_tx_data*) 
     66PJ_DECL(pj_status_t) 
    6567pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, 
    6668                                     const pjsip_method *method, 
     
    7173                                     const pjsip_cid_hdr *call_id, 
    7274                                     int cseq, 
    73                                      const pj_str_t *text ); 
     75                                     const pj_str_t *text, 
     76                                     pjsip_tx_data **p_tdata); 
    7477 
    7578/** 
     
    9093 *                  the completion of the transaction. 
    9194 * 
    92  * @return          Zero if transaction is started successfully. 
     95 * @return          PJ_SUCCESS, or the appropriate error code. 
    9396 */ 
    9497PJ_DECL(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, 
     
    108111 * @param rdata     The request receive data. 
    109112 * @param code      Status code to be put in the response. 
     113 * @param p_tdata   Pointer to receive the transmit data. 
    110114 * 
    111  * @return          Transmit data. 
     115 * @return          PJ_SUCCESS, or the appropriate error code. 
    112116 */ 
    113 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_response(pjsip_endpoint *endpt, 
    114                                                     const pjsip_rx_data *rdata, 
    115                                                     int code); 
     117PJ_DECL(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, 
     118                                                  const pjsip_rx_data *rdata, 
     119                                                  int code, 
     120                                                  pjsip_tx_data **p_tdata); 
    116121 
    117122/** 
     
    137142 * @param endpt     The endpoint. 
    138143 * @param tdata     The transmit buffer for the request being cancelled. 
     144 * @param p_tdata   Pointer to receive the transmit data. 
    139145 * 
    140  * @return          Cancel request. 
     146 * @return          PJ_SUCCESS, or the appropriate error code. 
    141147 */ 
    142 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
    143                                                    pjsip_tx_data *tdata ); 
     148PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
     149                                                pjsip_tx_data *tdata, 
     150                                                pjsip_tx_data **p_tdata); 
    144151 
    145152 
     
    160167                                             pjsip_host_port *addr); 
    161168 
    162  
    163169/** 
    164170 * @} 
  • pjproject/main/pjsip/include/pjsip/sip_module.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_MODULE_H__ 
  • pjproject/main/pjsip/include/pjsip/sip_msg.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_MSG_H__ 
     
    261260#define PJSIP_DECL_HDR_MEMBER(hdr)   \ 
    262261    /** List members. */        \ 
    263     PJ_DECL_LIST_MEMBER(hdr)    \ 
     262    PJ_DECL_LIST_MEMBER(hdr);   \ 
    264263    /** Header type */          \ 
    265264    pjsip_hdr_e     type;       \ 
     
    269268    pj_str_t        sname;              \ 
    270269    /** Virtual function table. */      \ 
    271     pjsip_hdr_vptr *vptr; 
     270    pjsip_hdr_vptr *vptr 
    272271 
    273272 
     
    276275 * message. All header fields can be typecasted to this type. 
    277276 */ 
    278 typedef struct pjsip_hdr 
    279 { 
    280     PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr) 
    281 } pjsip_hdr; 
     277struct pjsip_hdr 
     278{ 
     279    PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr); 
     280}; 
    282281 
    283282 
     
    688687 *              value if the message is too large for the specified buffer. 
    689688 */ 
    690 PJ_DECL(int) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size); 
     689PJ_DECL(pj_ssize_t) pjsip_msg_print(pjsip_msg *msg, char *buf, pj_size_t size); 
    691690 
    692691/** 
     
    708707typedef struct pjsip_generic_string_hdr 
    709708{ 
    710     PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_string_hdr) /**< Standard header field. */ 
     709    PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_string_hdr); /**< Standard header field. */ 
    711710    pj_str_t hvalue;                                /**< hvalue */ 
    712711} pjsip_generic_string_hdr; 
     
    757756typedef struct pjsip_generic_int_hdr 
    758757{ 
    759     PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr) /**< Standard header field. */ 
     758    PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr); /**< Standard header field. */ 
    760759    pj_int32_t ivalue;                              /**< ivalue */ 
    761760} pjsip_generic_int_hdr; 
     
    806805typedef struct pjsip_generic_array_hdr 
    807806{ 
    808     PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr) 
     807    PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr); 
    809808    unsigned    count;                                  /**< Number of elements. */ 
    810809    pj_str_t    values[PJSIP_GENERIC_ARRAY_MAX_COUNT];  /**< Elements.           */ 
     
    887886typedef struct pjsip_cid_hdr 
    888887{ 
    889     PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr) 
     888    PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr); 
    890889    pj_str_t id;            /**< Call-ID string. */ 
    891890} pjsip_cid_hdr; 
     
    918917typedef struct pjsip_clen_hdr 
    919918{ 
    920     PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr) 
     919    PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr); 
    921920    int len;    /**< Content length. */ 
    922921} pjsip_clen_hdr; 
     
    946945typedef struct pjsip_cseq_hdr 
    947946{ 
    948     PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr) 
     947    PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr); 
    949948    int             cseq;       /**< CSeq number. */ 
    950949    pjsip_method    method;     /**< CSeq method. */ 
     
    978977typedef struct pjsip_contact_hdr 
    979978{ 
    980     PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr) 
     979    PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr); 
    981980    int             star;           /**< The contact contains only a '*' character */ 
    982981    pjsip_uri *uri;         /**< URI in the contact. */ 
     
    10111010typedef struct pjsip_ctype_hdr 
    10121011{ 
    1013     PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr) 
     1012    PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr); 
    10141013    pjsip_media_type media; /**< Media type. */ 
    10151014} pjsip_ctype_hdr; 
     
    10621061typedef struct pjsip_fromto_hdr 
    10631062{ 
    1064     PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr) 
     1063    PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr); 
    10651064    pjsip_uri  *uri;        /**< URI in From/To header. */ 
    10661065    pj_str_t         tag;           /**< Header "tag" parameter. */ 
     
    11711170typedef struct pjsip_routing_hdr 
    11721171{ 
    1173     PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr)  /**< Generic header fields. */ 
     1172    PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr);  /**< Generic header fields. */ 
    11741173    pjsip_name_addr  name_addr;   /**< The URL in the Route/Record-Route header. */ 
    11751174    pj_str_t         other_param; /** Other parameter. */ 
     
    13281327typedef struct pjsip_via_hdr 
    13291328{ 
    1330     PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr) 
     1329    PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr); 
    13311330    pj_str_t         transport;     /**< Transport type. */ 
    13321331    pjsip_host_port  sent_by;       /**< Host and optional port */ 
  • pjproject/main/pjsip/include/pjsip/sip_msg_i.h

    • Property svn:keywords set to Id
  • pjproject/main/pjsip/include/pjsip/sip_parser.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_PARSER_H__ 
     
    1110 
    1211#include <pjsip/sip_types.h> 
    13 #include <pj/scanner.h> 
     12#include <pjlib-util/scanner.h> 
    1413#include <pj/list.h> 
    1514 
     
    5251typedef struct pjsip_parser_err_report 
    5352{ 
    54     PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report) 
     53    PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report); 
    5554    int         exception_code; /**< Error exception (e.g. PJSIP_SYN_ERR_EXCEPTION) */ 
    5655    int         line;           /**< Line number. */ 
     
    5857    pj_str_t    hname;          /**< Header name, if any. */ 
    5958} pjsip_parser_err_report; 
     59 
     60 
     61/** 
     62 * Parsing context, the default argument for parsing functions. 
     63 */ 
     64typedef struct pjsip_parse_ctx 
     65{ 
     66    pj_scanner      *scanner;   /**< The scanner.       */ 
     67    pj_pool_t       *pool;      /**< The pool.          */ 
     68    pjsip_rx_data   *rdata;     /**< Optional rdata.    */ 
     69} pjsip_parse_ctx; 
    6070 
    6171 
     
    7787 *        can be terminated when seeing EOF. 
    7888 */ 
    79 typedef void* (pjsip_parse_hdr_func)(pj_scanner *scanner, pj_pool_t *pool); 
     89typedef pjsip_hdr* (pjsip_parse_hdr_func)(pjsip_parse_ctx *context); 
    8090 
    8191/** 
     
    95105 * @param fptr          The pointer to function to parser the header. 
    96106 * 
    97  * @return              zero if success. 
    98  * @see pjsip_parse_hdr_func 
     107 * @return              PJ_SUCCESS if success, or the appropriate error code. 
    99108 */ 
    100109PJ_DECL(pj_status_t) pjsip_register_hdr_parser( const char *hname, 
     
    186195 
    187196/** 
     197 * Parse a packet buffer and build a rdata. The resulting message will be 
     198 * stored in \c msg field in the \c rdata. This behaves pretty much like 
     199 * #pjsip_parse_msg(), except that it will also initialize the header fields 
     200 * in the \c rdata. 
     201 * 
     202 * This function is normally called by the transport layer. 
     203 * 
     204 * @param buf           The input buffer 
     205 * @param buf           The input buffer, which size must be at least (size+1) 
     206 *                      because the function will temporarily put NULL  
     207 *                      termination at the end of the buffer during parsing. 
     208 * @param size          The length of the string (not counting NULL terminator). 
     209 * @param rdata         The receive data buffer to store the message and 
     210 *                      its elements. 
     211 * 
     212 * @return              The message inside the rdata if successfull, or NULL. 
     213 */ 
     214PJ_DECL(pjsip_msg *) pjsip_parse_rdata( char *buf, pj_size_t size, 
     215                                        pjsip_rx_data *rdata ); 
     216 
     217/** 
    188218 * Check incoming packet to see if a (probably) valid SIP message has been  
    189219 * received. 
     
    194224 *                      the size of the SIP message (including body, if any). 
    195225 * 
    196  * @return              PJ_TRUE (1) if a message is found. 
    197  */ 
    198 PJ_DECL(pj_bool_t) pjsip_find_msg( const char *buf, pj_size_t size,  
    199                                    pj_bool_t is_datagram, pj_size_t *msg_size); 
     226 * @return              PJ_SUCCESS if a message is found, or an error code. 
     227 */ 
     228PJ_DECL(pj_status_t) pjsip_find_msg(const char *buf,  
     229                                    pj_size_t size,  
     230                                    pj_bool_t is_datagram,  
     231                                    pj_size_t *msg_size); 
    200232 
    201233/** 
     
    248280 */ 
    249281extern 
    250 pj_char_spec    pjsip_HOST_SPEC,            /* For scanning host part. */ 
     282pj_cis_t        pjsip_HOST_SPEC,            /* For scanning host part. */ 
    251283                pjsip_DIGIT_SPEC,           /* Decimal digits */ 
    252284                pjsip_ALPHA_SPEC,           /* Alpha (A-Z, a-z) */ 
  • pjproject/main/pjsip/include/pjsip/sip_private.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_PRIVATE_H__ 
     
    2726 * @param cb Callback to be called to receive messages from transport. 
    2827 */ 
    29 PJ_DECL(pjsip_transport_mgr*) pjsip_transport_mgr_create( pj_pool_t *pool, 
    30                                                           pjsip_endpoint *endpt, 
    31                                                           void (*cb)(pjsip_endpoint *,pjsip_rx_data *)); 
     28PJ_DECL(pj_status_t) pjsip_transport_mgr_create( pj_pool_t *pool, 
     29                                                 pjsip_endpoint *endpt, 
     30                                                 void (*cb)(pjsip_endpoint *, 
     31                                                            pjsip_rx_data *), 
     32                                                 pjsip_transport_mgr **); 
    3233 
    3334 
     
    3637 * @param mgr Transport manager to be destroyed. 
    3738 */ 
    38 PJ_DECL(void) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ); 
     39PJ_DECL(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ); 
    3940 
    4041/** 
  • pjproject/main/pjsip/include/pjsip/sip_resolve.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_RESOLVE_H__ 
  • pjproject/main/pjsip/include/pjsip/sip_transaction.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_TRANSACTION_H__ 
     
    1211#include <pjsip/sip_msg.h> 
    1312#include <pjsip/sip_resolve.h> 
    14 //#include <pjsip/sip_config.h> 
    15 //#include <pjsip/sip_endpoint.h> 
    1613#include <pj/timer.h> 
    1714 
     
    2421 */ 
    2522 
     23/* Forward decl. */ 
    2624struct pjsip_transaction; 
    2725 
     
    6260struct pjsip_transaction 
    6361{ 
    64     pj_pool_t                  *pool; 
    65     pjsip_endpoint             *endpt; 
    66     char                        obj_name[PJ_MAX_OBJ_NAME]; 
    67     pjsip_role_e                role; 
    68     int                         status_code; 
    69     pjsip_tsx_state_e           state; 
    70     int (*state_handler)(struct pjsip_transaction *, pjsip_event *); 
    71  
    72     pj_mutex_t                 *mutex; 
    73     pjsip_method                method; 
    74     int                         cseq; 
    75     pj_str_t                    transaction_key; 
    76     pj_str_t                    branch; 
    77  
    78     pjsip_tsx_transport_state_e transport_state; 
    79     pjsip_host_port             dest_name; 
    80     int                         current_addr; 
    81     pjsip_server_addresses      remote_addr; 
    82     pjsip_transport_t          *transport; 
    83  
    84     pjsip_tx_data              *last_tx; 
    85     int                         has_unsent_msg; 
    86     int                         handle_ack; 
    87     int                         retransmit_count; 
    88  
    89     pj_timer_entry              retransmit_timer; 
    90     pj_timer_entry              timeout_timer; 
     62    /* 
     63     * Administrivia 
     64     */ 
     65    pj_pool_t                  *pool;           /**< Pool owned by the tsx. */ 
     66    pjsip_endpoint             *endpt;          /**< Endpoint instance.     */ 
     67    pj_mutex_t                 *mutex;          /**< Mutex for this tsx.    */ 
     68    char                        obj_name[PJ_MAX_OBJ_NAME];  /**< Tsx name.  */ 
     69    int                         tracing;        /**< Tracing enabled?       */ 
     70 
     71    /* 
     72     * Transaction identification. 
     73     */ 
     74    pjsip_role_e                role;           /**< Role (UAS or UAC)      */ 
     75    pjsip_method                method;         /**< The method.            */ 
     76    int                         cseq;           /**< The CSeq               */ 
     77    pj_str_t                    transaction_key;/**< hash table key.        */ 
     78    pj_str_t                    branch;         /**< The branch Id.         */ 
     79 
     80    /* 
     81     * State and status. 
     82     */ 
     83    int                         status_code;    /**< Last status code seen. */ 
     84    pjsip_tsx_state_e           state;          /**< State.                 */ 
     85    int                         handle_ack;     /**< Should we handle ACK?  */ 
     86 
     87    /** Handler according to current state. */ 
     88    pj_status_t (*state_handler)(struct pjsip_transaction *, pjsip_event *); 
     89 
     90    /* 
     91     * Transport. 
     92     */ 
     93    pjsip_tsx_transport_state_e transport_state;/**< Transport's state.     */ 
     94    pjsip_host_port             dest_name;      /**< Destination address.   */ 
     95    pjsip_server_addresses      remote_addr;    /**< Addresses resolved.    */ 
     96    int                         current_addr;   /**< Address currently used. */ 
     97 
     98    pjsip_transport_t          *transport;      /**< Transport to use.      */ 
     99 
     100    /* 
     101     * Messages and timer. 
     102     */ 
     103    pjsip_tx_data              *last_tx;        /**< Msg kept for retrans.  */ 
     104    int                         has_unsent_msg; /**< Non-zero if tsx need to  
     105                                                     transmit msg once resolver 
     106                                                     completes.             */ 
     107    int                         retransmit_count;/**< Retransmission count. */ 
     108    pj_timer_entry              retransmit_timer;/**< Retransmit timer.     */ 
     109    pj_timer_entry              timeout_timer;  /**< Timeout timer.         */ 
     110 
     111    /** Module specific data. */ 
    91112    void                       *module_data[PJSIP_MAX_MODULE]; 
    92113}; 
     
    94115 
    95116/**  
    96  * Init transaction as UAC. 
    97  * @param tsx the transaction. 
    98  * @param tdata the transmit data. 
    99  * @return PJ_SUCCESS if successfull. 
     117 * Init transaction as UAC from the specified transmit data (\c tdata). 
     118 * The transmit data must have a valid \c Request-Line and \c CSeq header. 
     119 * If \c Route headers are present, it will be used to calculate remote 
     120 * destination. 
     121 * 
     122 * If \c Via header does not exist, it will be created along with a unique 
     123 * \c branch parameter. If it exists and contains branch parameter, then 
     124 * the \c branch parameter will be used as is as the transaction key. 
     125 * 
     126 * The \c Route headers in the transmit data, if present, are used to  
     127 * calculate remote destination. 
     128 * 
     129 * At the end of the function, the transaction will start resolving the 
     130 * addresses of remote server to contact. Transport will be acquired as soon 
     131 * as the resolving job completes. 
     132 * 
     133 * @param tsx       The transaction. 
     134 * @param tdata     The transmit data. 
     135 * 
     136 * @return          PJ_SUCCESS if successfull. 
    100137 */ 
    101138PJ_DECL(pj_status_t) pjsip_tsx_init_uac( pjsip_transaction *tsx,  
     
    104141/** 
    105142 * Init transaction as UAS. 
    106  * @param tsx the transaction to be initialized. 
    107  * @param rdata the received incoming request. 
     143 * 
     144 * @param tsx       The transaction to be initialized. 
     145 * @param rdata     The received incoming request. 
     146 * 
    108147 * @return PJ_SUCCESS if successfull. 
    109148 */ 
     
    113152/** 
    114153 * Process incoming message for this transaction. 
    115  * @param tsx the transaction. 
    116  * @param rdata the incoming message. 
     154 * 
     155 * @param tsx       The transaction. 
     156 * @param rdata     The incoming message. 
    117157 */ 
    118158PJ_DECL(void) pjsip_tsx_on_rx_msg( pjsip_transaction *tsx, 
     
    121161/** 
    122162 * Transmit message with this transaction. 
    123  * @param tsx the transaction. 
    124  * @param tdata the outgoing message. 
     163 * 
     164 * @param tsx       The transaction. 
     165 * @param tdata     The outgoing message. 
    125166 */ 
    126167PJ_DECL(void) pjsip_tsx_on_tx_msg( pjsip_transaction *tsx, 
     
    135176 * transaction will comply with RFC-3261, i.e. it will set itself to  
    136177 * TERMINATED state when it receives 2xx/INVITE. 
    137  * @param tsx The transaction. 
    138  * @param tdata The ACK request. 
     178 * 
     179 * @param tsx       The transaction. 
     180 * @param tdata     The ACK request. 
    139181 */ 
    140182PJ_DECL(void) pjsip_tsx_on_tx_ack( pjsip_transaction *tsx, 
     
    142184 
    143185/** 
    144  * Forcely terminate transaction. 
    145  * @param tsx the transaction. 
    146  * @param code the status code to report. 
     186 * Force terminate transaction. 
     187 * 
     188 * @param tsx       The transaction. 
     189 * @param code      The status code to report. 
    147190 */ 
    148191PJ_DECL(void) pjsip_tsx_terminate( pjsip_transaction *tsx, 
     
    152195 * Create transaction key, which is used to match incoming requests  
    153196 * or response (retransmissions) against transactions. 
    154  * @param pool The pool 
    155  * @param key Output key. 
    156  * @param role The role of the transaction. 
    157  * @param method The method to be put as a key.  
    158  * @param rdata The received data to calculate. 
    159  */ 
    160 PJ_DECL(void) pjsip_tsx_create_key( pj_pool_t *pool, 
    161                                     pj_str_t *key, 
    162                                     pjsip_role_e role, 
    163                                     const pjsip_method *method, 
    164                                     const pjsip_rx_data *rdata ); 
     197 * 
     198 * @param pool      The pool 
     199 * @param key       Output key. 
     200 * @param role      The role of the transaction. 
     201 * @param method    The method to be put as a key.  
     202 * @param rdata     The received data to calculate. 
     203 * 
     204 * @return          PJ_SUCCESS or the appropriate error code. 
     205 */ 
     206PJ_DECL(pj_status_t) pjsip_tsx_create_key( pj_pool_t *pool, 
     207                                           pj_str_t *key, 
     208                                           pjsip_role_e role, 
     209                                           const pjsip_method *method, 
     210                                           const pjsip_rx_data *rdata ); 
     211 
    165212 
    166213/** 
     
    184231 
    185232/* Thread Local Storage ID for transaction lock (initialized by endpoint) */ 
    186 extern int pjsip_tsx_lock_tls_id; 
     233extern long pjsip_tsx_lock_tls_id; 
    187234 
    188235PJ_END_DECL 
  • pjproject/main/pjsip/include/pjsip/sip_transport.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_TRANSPORT_H__ 
     
    1413#include <pj/sock.h> 
    1514#include <pj/list.h> 
     15#include <pj/ioqueue.h> 
    1616 
    1717PJ_BEGIN_DECL 
     
    3737struct pjsip_rx_data 
    3838{ 
    39     PJ_DECL_LIST_MEMBER(struct pjsip_rx_data) 
     39    //PJ_DECL_LIST_MEMBER(struct pjsip_rx_data); 
    4040 
    4141    /** Memory pool for this buffer. */ 
    4242    pj_pool_t           *pool; 
     43 
     44    /** Ioqueue op key. */ 
     45    pj_ioqueue_op_key_t  op_key; 
    4346 
    4447    /** Time when the message was received. */ 
     
    7477    pjsip_from_hdr      *from; 
    7578 
    76     /** The tag in the From header as found in the message. */ 
    77     pj_str_t             from_tag; 
    78  
    7979    /** The To header as found in the message. */ 
    8080    pjsip_to_hdr        *to; 
    8181 
    82     /** The To tag header as found in the message. */ 
    83     pj_str_t             to_tag; 
    84  
    8582    /** The topmost Via header as found in the message. */ 
    8683    pjsip_via_hdr       *via; 
     
    8885    /** The CSeq header as found in the message. */ 
    8986    pjsip_cseq_hdr      *cseq; 
     87 
     88    /** Max forwards header. */ 
     89    pjsip_max_forwards_hdr *max_fwd; 
     90 
     91    /** The first route header. */ 
     92    pjsip_route_hdr     *route; 
     93 
     94    /** The first record-route header. */ 
     95    pjsip_rr_hdr        *record_route; 
     96 
     97    /** Content-type header. */ 
     98    pjsip_ctype_hdr     *ctype; 
     99 
     100    /** Content-length header. */ 
     101    pjsip_clen_hdr      *clen; 
     102 
     103    /** The first Require header. */ 
     104    pjsip_require_hdr   *require; 
    90105 
    91106    /** The list of error generated by the parser when parsing this message. */ 
     
    110125struct pjsip_tx_data 
    111126{ 
    112     PJ_DECL_LIST_MEMBER(struct pjsip_tx_data) 
     127    PJ_DECL_LIST_MEMBER(struct pjsip_tx_data); 
    113128 
    114129    /** Memory pool for this buffer. */ 
     
    127142    /** The transport manager for this buffer. */ 
    128143    pjsip_transport_mgr *mgr; 
     144 
     145    /** Ioqueue asynchronous operation key. */ 
     146    pj_ioqueue_op_key_t  op_key; 
    129147 
    130148    /** The message in this buffer. */ 
     
    357375 * @param tdata         The outgoing message buffer. 
    358376 * @param addr          The remote address. 
    359  * 
    360  * @return              The number of bytes sent, or zero if the connection  
    361  *                      has closed, or -1 on error. 
    362  */ 
    363 PJ_DECL(int) pjsip_transport_send_msg( pjsip_transport_t *tr,  
    364                                        pjsip_tx_data *tdata, 
    365                                        const pj_sockaddr_in *addr); 
     377 * @param sent          If not null, it will be filled up with the length of 
     378 *                      data sent. 
     379 * 
     380 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     381 */ 
     382PJ_DECL(pj_status_t) pjsip_transport_send_msg( pjsip_transport_t *tr,  
     383                                               pjsip_tx_data *tdata, 
     384                                               const pj_sockaddr_in *addr, 
     385                                               pj_ssize_t *sent); 
    366386 
    367387 
     
    387407 * @return              The transmit buffer data, or NULL on error. 
    388408 */ 
    389 pjsip_tx_data* pjsip_tx_data_create( pjsip_transport_mgr *mgr ); 
     409pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr, 
     410                                  pjsip_tx_data **tdata ); 
    390411 
    391412 
  • pjproject/main/pjsip/include/pjsip/sip_types.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_TYPES_H__ 
     
    7473 
    7574/** 
     75 * Forward declaration for header field (sip_msg.h). 
     76 */ 
     77typedef struct pjsip_hdr pjsip_hdr; 
     78 
     79/** 
    7680 * Forward declaration for URI (sip_uri.h). 
    7781 */ 
     
    135139 
    136140 
     141/** 
     142 * Convert exception ID into pj_status_t status. 
     143 * 
     144 * @param exception_id  Exception Id. 
     145 * 
     146 * @return              Error code for the specified exception Id. 
     147 */ 
     148PJ_DECL(pj_status_t) pjsip_exception_to_status(int exception_id); 
     149 
     150/** 
     151 * Return standard pj_status_t status from current exception. 
     152 */ 
     153#define PJSIP_RETURN_EXCEPTION() pjsip_exception_to_status(PJ_GET_EXCEPTION()) 
     154 
     155/** 
     156 * Attributes to inform that the function may throw exceptions. 
     157 */ 
     158#define PJSIP_THROW_SPEC(list) 
     159 
    137160#endif  /* __PJSIP_SIP_TYPES_H__ */ 
    138161 
  • pjproject/main/pjsip/include/pjsip/sip_uri.h

    • Property svn:keywords set to Id
    r38 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_SIP_URI_H__ 
  • pjproject/main/pjsip/include/pjsip_auth.h

    • Property svn:keywords set to Id
  • pjproject/main/pjsip/include/pjsip_core.h

    • Property svn:keywords set to Id
    r42 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#ifndef __PJSIP_CORE_H__ 
  • pjproject/main/pjsip/include/pjsip_simple.h

    • Property svn:keywords set to Id
  • pjproject/main/pjsip/include/pjsip_ua.h

    • Property svn:keywords set to Id
  • pjproject/main/pjsip/lib

    • Property svn:ignore set to
      *
  • pjproject/main/pjsip/src/pjsip/sip_auth.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_auth.h> 
     
    65#include <pjsip/sip_transport.h> 
    76#include <pjsip/sip_endpoint.h> 
    8 #include <pj/md5.h> 
     7#include <pjlib-util/md5.h> 
    98#include <pj/log.h> 
    109#include <pj/string.h> 
    1110#include <pj/pool.h> 
    1211#include <pj/guid.h> 
     12#include <pj/assert.h> 
     13#include <pj/ctype.h> 
    1314 
    1415/* Length of digest string. */ 
     
    147148    p = qop.ptr; 
    148149    while (*p) { 
    149         *p = (char)tolower(*p); 
     150        *p = (char)pj_tolower(*p); 
    150151        ++p; 
    151152    } 
     
    218219        cred->qop = pjsip_AUTH_STR; 
    219220        cred->nc.ptr = pj_pool_alloc(pool, 16); 
    220         sprintf(cred->nc.ptr, "%06u", nc); 
     221        pj_snprintf(cred->nc.ptr, 16, "%06u", nc); 
    221222 
    222223        if (cnonce && cnonce->slen) { 
     
    485486{ 
    486487    unsigned i; 
    487     PJ_UNUSED_ARG(scheme) 
     488    PJ_UNUSED_ARG(scheme); 
    488489    for (i=0; i<count; ++i) { 
    489490        if (pj_stricmp(&cred[i].realm, realm) == 0) 
     
    716717    pjsip_via_hdr *via; 
    717718 
    718     PJ_UNUSED_ARG(endpt) 
     719    PJ_UNUSED_ARG(endpt); 
    719720 
    720721    pj_assert(rdata->msg->type == PJSIP_RESPONSE_MSG); 
  • pjproject/main/pjsip/src/pjsip/sip_auth_msg.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_auth_msg.h> 
     
    76#include <pj/list.h> 
    87#include <pj/string.h> 
    9 #include <pjsip/print.h> 
     8#include <pj/assert.h> 
     9#include <pjsip/print_util.h> 
    1010 
    1111/////////////////////////////////////////////////////////////////////////////// 
     
    6868static int print_pgp_credential(pjsip_pgp_credential *cred, char *buf, pj_size_t size) 
    6969{ 
    70     PJ_UNUSED_ARG(cred) 
    71     PJ_UNUSED_ARG(buf) 
    72     PJ_UNUSED_ARG(size) 
     70    PJ_UNUSED_ARG(cred); 
     71    PJ_UNUSED_ARG(buf); 
     72    PJ_UNUSED_ARG(size); 
    7373    return -1; 
    7474} 
     
    213213                                char *buf, pj_size_t size) 
    214214{ 
    215     PJ_UNUSED_ARG(chal) 
    216     PJ_UNUSED_ARG(buf) 
    217     PJ_UNUSED_ARG(size) 
     215    PJ_UNUSED_ARG(chal); 
     216    PJ_UNUSED_ARG(buf); 
     217    PJ_UNUSED_ARG(size); 
    218218    return -1; 
    219219} 
  • pjproject/main/pjsip/src/pjsip/sip_auth_parser.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_auth_parser.h> 
    54#include <pjsip/sip_auth_msg.h> 
    65#include <pjsip/sip_parser.h> 
     6#include <pj/assert.h> 
    77#include <pj/string.h> 
    88#include <pj/except.h> 
    99 
    10 static pjsip_authorization_hdr*       parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool); 
    11 static pjsip_proxy_authorization_hdr* parse_hdr_proxy_authorization( pj_scanner *scanner, pj_pool_t *pool); 
    12 static pjsip_www_authenticate_hdr*    parse_hdr_www_authenticate( pj_scanner *scanner, pj_pool_t *pool); 
    13 static pjsip_proxy_authenticate_hdr*  parse_hdr_proxy_authenticate( pj_scanner *scanner, pj_pool_t *pool); 
    14  
    15 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred); 
    16 static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred); 
    17 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal); 
    18 static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal); 
     10static pjsip_hdr* parse_hdr_authorization       ( pjsip_parse_ctx *ctx ); 
     11static pjsip_hdr* parse_hdr_proxy_authorization ( pjsip_parse_ctx *ctx ); 
     12static pjsip_hdr* parse_hdr_www_authenticate    ( pjsip_parse_ctx *ctx ); 
     13static pjsip_hdr* parse_hdr_proxy_authenticate  ( pjsip_parse_ctx *ctx ); 
     14 
     15static void parse_digest_credential ( pj_scanner *scanner, pj_pool_t *pool,  
     16                                      pjsip_digest_credential *cred); 
     17static void parse_pgp_credential    ( pj_scanner *scanner, pj_pool_t *pool,  
     18                                      pjsip_pgp_credential *cred); 
     19static void parse_digest_challenge  ( pj_scanner *scanner, pj_pool_t *pool,  
     20                                      pjsip_digest_challenge *chal); 
     21static void parse_pgp_challenge     ( pj_scanner *scanner, pj_pool_t *pool, 
     22                                      pjsip_pgp_challenge *chal); 
    1923 
    2024const pj_str_t  pjsip_USERNAME_STR =        { "username", 8 }, 
     
    4448 
    4549 
    46 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred) 
     50static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool,  
     51                                     pjsip_digest_credential *cred) 
    4752{ 
    4853    for (;;) { 
    4954        pj_str_t name, value; 
    5055 
    51         pjsip_parse_param_imp(scanner, &name, &value, PJSIP_PARSE_REMOVE_QUOTE); 
     56        pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 
    5257 
    5358        if (!pj_stricmp(&name, &pjsip_USERNAME_STR)) { 
     
    8287 
    8388        } else { 
    84             pjsip_concat_param_imp(&cred->other_param, pool, &name, &value, ','); 
     89            pjsip_concat_param_imp(&cred->other_param,pool,&name,&value, ','); 
    8590        } 
    8691 
    8792        /* Eat comma */ 
    88         if (!pj_scan_is_eof(scanner) && *scanner->current == ',') 
     93        if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 
    8994            pj_scan_get_char(scanner); 
    9095        else 
     
    9398} 
    9499 
    95 static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred) 
    96 { 
    97     PJ_UNUSED_ARG(scanner) 
    98     PJ_UNUSED_ARG(pool) 
    99     PJ_UNUSED_ARG(cred) 
     100static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool,  
     101                                  pjsip_pgp_credential *cred) 
     102{ 
     103    PJ_UNUSED_ARG(scanner); 
     104    PJ_UNUSED_ARG(pool); 
     105    PJ_UNUSED_ARG(cred); 
    100106 
    101107    PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
    102108} 
    103109 
    104 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal) 
     110static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool,  
     111                                    pjsip_digest_challenge *chal) 
    105112{ 
    106113    for (;;) { 
    107114        pj_str_t name, value; 
    108115 
    109         pjsip_parse_param_imp(scanner, &name, &value, PJSIP_PARSE_REMOVE_QUOTE); 
     116        pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 
    110117 
    111118        if (!pj_stricmp(&name, &pjsip_REALM_STR)) { 
     
    122129 
    123130        } else if (!pj_stricmp(&name, &pjsip_STALE_STR)) { 
    124             if (!pj_stricmp(&value, &pjsip_TRUE_STR) || !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) 
     131            if (!pj_stricmp(&value, &pjsip_TRUE_STR) ||  
     132                !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) 
     133            { 
    125134                chal->stale = 1; 
     135            } 
    126136 
    127137        } else if (!pj_stricmp(&name, &pjsip_ALGORITHM_STR)) { 
     
    133143 
    134144        } else { 
    135             pjsip_concat_param_imp(&chal->other_param, pool, &name, &value, ','); 
     145            pjsip_concat_param_imp(&chal->other_param, pool,  
     146                                   &name, &value, ','); 
    136147        } 
    137148 
    138149        /* Eat comma */ 
    139         if (!pj_scan_is_eof(scanner) && *scanner->current == ',') 
     150        if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 
    140151            pj_scan_get_char(scanner); 
    141152        else 
     
    144155} 
    145156 
    146 static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal) 
    147 { 
    148     PJ_UNUSED_ARG(scanner) 
    149     PJ_UNUSED_ARG(pool) 
    150     PJ_UNUSED_ARG(chal) 
     157static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool,  
     158                                 pjsip_pgp_challenge *chal) 
     159{ 
     160    PJ_UNUSED_ARG(scanner); 
     161    PJ_UNUSED_ARG(pool); 
     162    PJ_UNUSED_ARG(chal); 
    151163 
    152164    PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
    153165} 
    154166 
    155 static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool,  
     167static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, 
    156168                                         pjsip_authorization_hdr *hdr) 
    157169{ 
    158     if (*scanner->current == '"') { 
     170    if (*scanner->curptr == '"') { 
    159171        pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 
    160172        hdr->scheme.ptr++; 
    161173        hdr->scheme.slen -= 2; 
    162174    } else { 
    163         pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme); 
     175        pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 
    164176    } 
    165177 
     
    182194                                        pjsip_www_authenticate_hdr *hdr) 
    183195{ 
    184     if (*scanner->current == '"') { 
     196    if (*scanner->curptr == '"') { 
    185197        pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 
    186198        hdr->scheme.ptr++; 
    187199        hdr->scheme.slen -= 2; 
    188200    } else { 
    189         pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme); 
     201        pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 
    190202    } 
    191203 
     
    206218 
    207219 
    208 static pjsip_authorization_hdr *parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool) 
    209 { 
    210     pjsip_authorization_hdr *hdr = pjsip_authorization_hdr_create(pool); 
    211     int_parse_hdr_authorization(scanner, pool, hdr); 
    212     return hdr; 
    213 } 
    214  
    215 static pjsip_proxy_authorization_hdr *parse_hdr_proxy_authorization( pj_scanner *scanner, pj_pool_t *pool) 
    216 { 
    217     pjsip_proxy_authorization_hdr *hdr = pjsip_proxy_authorization_hdr_create(pool); 
    218     int_parse_hdr_authorization(scanner, pool, hdr); 
    219     return hdr; 
    220 } 
    221  
    222 static pjsip_www_authenticate_hdr *parse_hdr_www_authenticate( pj_scanner *scanner, pj_pool_t *pool) 
    223 { 
    224     pjsip_www_authenticate_hdr *hdr = pjsip_www_authenticate_hdr_create(pool); 
    225     int_parse_hdr_authenticate(scanner, pool, hdr); 
    226     return hdr; 
    227 } 
    228  
    229 static pjsip_proxy_authenticate_hdr *parse_hdr_proxy_authenticate( pj_scanner *scanner, pj_pool_t *pool) 
    230 { 
    231     pjsip_proxy_authenticate_hdr *hdr = pjsip_proxy_authenticate_hdr_create(pool); 
    232     int_parse_hdr_authenticate(scanner, pool, hdr); 
    233     return hdr; 
    234 } 
    235  
    236  
    237 PJ_DEF(void) pjsip_auth_init_parser() 
    238 { 
    239     pjsip_register_hdr_parser( "Authorization", NULL, (pjsip_parse_hdr_func*) &parse_hdr_authorization); 
    240     pjsip_register_hdr_parser( "Proxy-Authorization", NULL, (pjsip_parse_hdr_func*) &parse_hdr_proxy_authorization); 
    241     pjsip_register_hdr_parser( "WWW-Authenticate", NULL, (pjsip_parse_hdr_func*) &parse_hdr_www_authenticate); 
    242     pjsip_register_hdr_parser( "Proxy-Authenticate", NULL, (pjsip_parse_hdr_func*) &parse_hdr_proxy_authenticate); 
     220static pjsip_hdr* parse_hdr_authorization( pjsip_parse_ctx *ctx ) 
     221{ 
     222    pjsip_authorization_hdr *hdr = pjsip_authorization_hdr_create(ctx->pool); 
     223    int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); 
     224    return (pjsip_hdr*)hdr; 
     225} 
     226 
     227static pjsip_hdr* parse_hdr_proxy_authorization( pjsip_parse_ctx *ctx ) 
     228{ 
     229    pjsip_proxy_authorization_hdr *hdr =  
     230        pjsip_proxy_authorization_hdr_create(ctx->pool); 
     231    int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); 
     232    return (pjsip_hdr*)hdr; 
     233} 
     234 
     235static pjsip_hdr* parse_hdr_www_authenticate( pjsip_parse_ctx *ctx ) 
     236{ 
     237    pjsip_www_authenticate_hdr *hdr =  
     238        pjsip_www_authenticate_hdr_create(ctx->pool); 
     239    int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); 
     240    return (pjsip_hdr*)hdr; 
     241} 
     242 
     243static pjsip_hdr* parse_hdr_proxy_authenticate( pjsip_parse_ctx *ctx ) 
     244{ 
     245    pjsip_proxy_authenticate_hdr *hdr =  
     246        pjsip_proxy_authenticate_hdr_create(ctx->pool); 
     247    int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); 
     248    return (pjsip_hdr*)hdr; 
     249} 
     250 
     251 
     252PJ_DEF(pj_status_t) pjsip_auth_init_parser() 
     253{ 
     254    pj_status_t status; 
     255 
     256    status = pjsip_register_hdr_parser( "Authorization", NULL,  
     257                                        &parse_hdr_authorization); 
     258    PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 
     259    status = pjsip_register_hdr_parser( "Proxy-Authorization", NULL,  
     260                                        &parse_hdr_proxy_authorization); 
     261    PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 
     262    status = pjsip_register_hdr_parser( "WWW-Authenticate", NULL,  
     263                                        &parse_hdr_www_authenticate); 
     264    PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 
     265    status = pjsip_register_hdr_parser( "Proxy-Authenticate", NULL,  
     266                                        &parse_hdr_proxy_authenticate); 
     267    PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 
     268 
     269    return PJ_SUCCESS; 
    243270} 
    244271 
  • pjproject/main/pjsip/src/pjsip/sip_endpoint.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_endpoint.h> 
     
    98#include <pjsip/sip_module.h> 
    109#include <pjsip/sip_misc.h> 
     10#include <pjsip/sip_errno.h> 
    1111#include <pj/except.h> 
    1212#include <pj/log.h> 
     
    1515#include <pj/pool.h> 
    1616#include <pj/hash.h> 
     17#include <pj/assert.h> 
     18#include <pj/errno.h> 
    1719 
    1820 
    1921#define PJSIP_EX_NO_MEMORY  PJ_NO_MEMORY_EXCEPTION 
    20 #define LOG_THIS            "endpoint..." 
     22#define THIS_FILE           "endpoint" 
    2123 
    2224#define MAX_METHODS   32 
     
    8587 * Defined in sip_transaction.c 
    8688 */ 
    87 pjsip_transaction * pjsip_tsx_create( pj_pool_t *pool, pjsip_endpoint *endpt); 
     89pj_status_t pjsip_tsx_create( pj_pool_t *pool, pjsip_endpoint *endpt, 
     90                              pjsip_transaction **tsx ); 
    8891 
    8992/* 
     
    9598static void pool_callback( pj_pool_t *pool, pj_size_t size ) 
    9699{ 
    97     PJ_UNUSED_ARG(pool) 
    98     PJ_UNUSED_ARG(size) 
     100    PJ_UNUSED_ARG(pool); 
     101    PJ_UNUSED_ARG(size); 
    99102 
    100103    PJ_THROW(PJSIP_EX_NO_MEMORY); 
     
    112115    extern pjsip_module aux_tsx_module; 
    113116 
    114     PJ_LOG(5, (LOG_THIS, "init_modules()")); 
     117    PJ_LOG(5, (THIS_FILE, "init_modules()")); 
    115118 
    116119    /* Load static modules. */ 
     
    165168                    endpt->methods[endpt->method_cnt++] = mod->methods[j]; 
    166169                } else { 
    167                     PJ_LOG(1,(LOG_THIS, "Too many methods")); 
     170                    PJ_LOG(1,(THIS_FILE, "Too many methods")); 
    168171                    return -1; 
    169172                } 
     
    201204                                      pjsip_transaction *tsx) 
    202205{ 
    203     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_destroy_tsx(%s)", tsx->obj_name)); 
     206    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_destroy_tsx(%s)", tsx->obj_name)); 
    204207 
    205208    pj_assert(tsx->state == PJSIP_TSX_STATE_DESTROYED); 
     
    227230    pj_pool_release(tsx->pool); 
    228231 
    229     PJ_LOG(4, (LOG_THIS, "tsx%p destroyed", tsx)); 
     232    PJ_LOG(4, (THIS_FILE, "tsx%p destroyed", tsx)); 
    230233} 
    231234 
     
    248251 
    249252    /* Destroy transaction if it is terminated. */ 
    250     if (evt->type == PJSIP_EVENT_TSX_STATE_CHANGED &&  
    251         evt->obj.tsx->state == PJSIP_TSX_STATE_DESTROYED)  
     253    if (evt->type == PJSIP_EVENT_TSX_STATE &&  
     254        evt->body.tsx_state.tsx->state == PJSIP_TSX_STATE_DESTROYED)  
    252255    { 
    253256        /* No need to lock mutex. Mutex is locked inside the destroy function */ 
    254         pjsip_endpt_destroy_tsx( endpt, evt->obj.tsx ); 
     257        pjsip_endpt_destroy_tsx( endpt, evt->body.tsx_state.tsx ); 
    255258    } 
    256259} 
     
    262265void pjsip_endpt_send_tsx_event( pjsip_endpoint *endpt, pjsip_event *evt ) 
    263266{ 
     267    // Need to protect this with try/catch? 
    264268    endpt_do_event(endpt, evt); 
    265269} 
     
    302306        if (!hdr) { 
    303307            pj_mutex_unlock(endpt->mutex); 
    304             PJ_LOG(4,(LOG_THIS, "Invalid URL %s in proxy URL", dup)); 
     308            PJ_LOG(4,(THIS_FILE, "Invalid URL %s in proxy URL", dup)); 
    305309            return -1; 
    306310        } 
     
    328332 * Initialize endpoint. 
    329333 */ 
    330 PJ_DEF(pjsip_endpoint*) pjsip_endpt_create(pj_pool_factory *pf) 
     334PJ_DEF(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf, 
     335                                       pjsip_endpoint **p_endpt) 
    331336{ 
    332337    pj_status_t status; 
     
    335340    pjsip_max_forwards_hdr *mf_hdr; 
    336341 
    337     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create()")); 
     342    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create()")); 
     343 
     344    *p_endpt = NULL; 
    338345 
    339346    /* Create pool */ 
     
    342349                          &pool_callback); 
    343350    if (!pool) 
    344         return NULL; 
     351        return PJ_ENOMEM; 
    345352 
    346353    /* Create endpoint. */ 
     
    350357 
    351358    /* Create mutex for the events, etc. */ 
    352     endpt->mutex = pj_mutex_create( endpt->pool, "ept%p", 0 ); 
    353     if (!endpt->mutex) { 
    354         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating endpoint mutex")); 
     359    status = pj_mutex_create_recursive( endpt->pool, "ept%p", &endpt->mutex ); 
     360    if (status != PJ_SUCCESS) { 
    355361        goto on_error; 
    356362    } 
    357363 
    358364    /* Create mutex for the transaction table. */ 
    359     endpt->tsx_table_mutex = pj_mutex_create( endpt->pool, "mtbl%p", 0); 
    360     if (!endpt->tsx_table_mutex) { 
    361         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating endpoint mutex(2)")); 
     365    status = pj_mutex_create_recursive( endpt->pool, "mtbl%p",  
     366                                        &endpt->tsx_table_mutex); 
     367    if (status != PJ_SUCCESS) { 
    362368        goto on_error; 
    363369    } 
     
    366372    endpt->tsx_table = pj_hash_create( endpt->pool, PJSIP_MAX_TSX_COUNT ); 
    367373    if (!endpt->tsx_table) { 
    368         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating tsx hash table")); 
     374        status = PJ_ENOMEM; 
    369375        goto on_error; 
    370376    } 
    371377 
    372378    /* Create timer heap to manage all timers within this endpoint. */ 
    373     endpt->timer_heap = pj_timer_heap_create( endpt->pool, PJSIP_MAX_TIMER_COUNT, 0); 
    374     if (!endpt->timer_heap) { 
    375         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating timer heap")); 
     379    status = pj_timer_heap_create( endpt->pool, PJSIP_MAX_TIMER_COUNT,  
     380                                   &endpt->timer_heap); 
     381    if (status != PJ_SUCCESS) { 
    376382        goto on_error; 
    377383    } 
    378384 
    379385    /* Create transport manager. */ 
    380     endpt->transport_mgr = pjsip_transport_mgr_create( endpt->pool, 
    381                                                       endpt, 
    382                                                        &endpt_transport_callback); 
    383     if (!endpt->transport_mgr) { 
    384         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating transport mgr")); 
     386    status = pjsip_transport_mgr_create( endpt->pool, 
     387                                        endpt, 
     388                                         &endpt_transport_callback, 
     389                                         &endpt->transport_mgr); 
     390    if (status != PJ_SUCCESS) { 
    385391        goto on_error; 
    386392    } 
     
    389395    endpt->resolver = pjsip_resolver_create(endpt->pool); 
    390396    if (!endpt->resolver) { 
    391         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating resolver")); 
     397        PJ_LOG(4, (THIS_FILE, "pjsip_endpt_init(): error creating resolver")); 
    392398        goto on_error; 
    393399    } 
    394400 
    395401    /* Initialize TLS ID for transaction lock. */ 
    396     pjsip_tsx_lock_tls_id = pj_thread_local_alloc(); 
    397     if (pjsip_tsx_lock_tls_id == -1) { 
    398         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error allocating TLS")); 
     402    status = pj_thread_local_alloc(&pjsip_tsx_lock_tls_id); 
     403    if (status != PJ_SUCCESS) { 
    399404        goto on_error; 
    400405    } 
     
    415420    status = init_modules(endpt); 
    416421    if (status != PJ_SUCCESS) { 
    417         PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error in init_modules()")); 
    418         return NULL; 
     422        PJ_LOG(4, (THIS_FILE, "pjsip_endpt_init(): error in init_modules()")); 
     423        return status; 
    419424    } 
    420425 
    421426    /* Done. */ 
    422     return endpt; 
     427    *p_endpt = endpt; 
     428    return status; 
    423429 
    424430on_error: 
     
    437443    pj_pool_release( endpt->pool ); 
    438444 
    439     PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init() failed")); 
    440     return NULL; 
     445    PJ_LOG(4, (THIS_FILE, "pjsip_endpt_init() failed")); 
     446    return status; 
    441447} 
    442448 
     
    446452PJ_DEF(void) pjsip_endpt_destroy(pjsip_endpoint *endpt) 
    447453{ 
    448     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_destroy()")); 
     454    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_destroy()")); 
    449455 
    450456    /* Shutdown and destroy all transports. */ 
     
    471477    pj_pool_t *pool; 
    472478 
    473     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create_pool()")); 
     479    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_pool()")); 
    474480 
    475481    /* Lock endpoint mutex. */ 
     
    484490 
    485491    if (pool) { 
    486         PJ_LOG(5, (LOG_THIS, "   pool %s created", pj_pool_getobjname(pool))); 
     492        PJ_LOG(5, (THIS_FILE, "   pool %s created", pj_pool_getobjname(pool))); 
    487493    } else { 
    488         PJ_LOG(4, (LOG_THIS, "Unable to create pool %s!", pool_name)); 
     494        PJ_LOG(4, (THIS_FILE, "Unable to create pool %s!", pool_name)); 
    489495    } 
    490496 
     
    498504PJ_DEF(void) pjsip_endpt_destroy_pool( pjsip_endpoint *endpt, pj_pool_t *pool ) 
    499505{ 
    500     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_destroy_pool(%s)", pj_pool_getobjname(pool))); 
     506    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_destroy_pool(%s)", pj_pool_getobjname(pool))); 
    501507 
    502508    pj_mutex_lock(endpt->mutex); 
     
    514520    int i; 
    515521 
    516     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_handle_events()")); 
     522    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_handle_events()")); 
    517523 
    518524    /* Poll the timer. The timer heap has its own mutex for better  
     
    544550                                                const pj_time_val *delay ) 
    545551{ 
    546     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_schedule_timer(entry=%p, delay=%u.%u)", 
     552    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_schedule_timer(entry=%p, delay=%u.%u)", 
    547553                         entry, delay->sec, delay->msec)); 
    548554    return pj_timer_heap_schedule( endpt->timer_heap, entry, delay ); 
     
    555561                                       pj_timer_entry *entry ) 
    556562{ 
    557     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_cancel_timer(entry=%p)", entry)); 
     563    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_cancel_timer(entry=%p)", entry)); 
    558564    pj_timer_heap_cancel( endpt->timer_heap, entry ); 
    559565} 
     
    564570 * register it to the hash table. 
    565571 */ 
    566 PJ_DEF(pjsip_transaction*) pjsip_endpt_create_tsx(pjsip_endpoint *endpt) 
     572PJ_DEF(pj_status_t) pjsip_endpt_create_tsx(pjsip_endpoint *endpt, 
     573                                           pjsip_transaction **p_tsx) 
    567574{ 
    568575    pj_pool_t *pool; 
    569     pjsip_transaction *tsx; 
    570  
    571     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create_tsx()")); 
     576 
     577    PJ_ASSERT_RETURN(endpt && p_tsx, PJ_EINVAL); 
     578 
     579    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_tsx()")); 
    572580 
    573581    /* Request one pool for the transaction. Mutex is locked there. */ 
     
    575583                                      PJSIP_POOL_LEN_TSX, PJSIP_POOL_INC_TSX); 
    576584    if (pool == NULL) { 
    577         PJ_LOG(2, (LOG_THIS, "failed to create transaction (no pool)")); 
    578         return NULL; 
     585        return PJ_ENOMEM; 
    579586    } 
    580587 
    581588    /* Create the transaction. */ 
    582     tsx = pjsip_tsx_create(pool, endpt); 
    583  
    584     /* Return */ 
    585     return tsx; 
     589    return pjsip_tsx_create(pool, endpt, p_tsx); 
    586590} 
    587591 
     
    595599                                       pjsip_transaction *tsx) 
    596600{ 
    597     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_register_tsx(%s)", tsx->obj_name)); 
     601    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_register_tsx(%s)", tsx->obj_name)); 
    598602 
    599603    pj_assert(tsx->transaction_key.slen != 0); 
     
    619623    pjsip_transaction *tsx; 
    620624 
    621     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_find_tsx()")); 
     625    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_find_tsx()")); 
    622626 
    623627    /* Start lock mutex in the endpoint. */ 
     
    659663    pj_bool_t a_new_transaction_just_been_created = PJ_FALSE; 
    660664 
    661     PJ_LOG(5, (LOG_THIS, "endpt_transport_callback(rdata=%p)", rdata)); 
     665    PJ_LOG(5, (THIS_FILE, "endpt_transport_callback(rdata=%p)", rdata)); 
    662666 
    663667    /* For response, check that the value in Via sent-by match the transport. 
     
    676680        } 
    677681        addr = pjsip_transport_get_addr_name(rdata->transport); 
    678         addr_addr = pj_sockaddr_get_str_addr(addr); 
     682        addr_addr = pj_inet_ntoa(addr->sin_addr); 
    679683        if (pj_strcmp2(&rdata->via->sent_by.host, addr_addr) != 0) 
    680684            mismatch = PJ_TRUE; 
    681         else if (port != pj_sockaddr_get_port(addr)) { 
     685        else if (port != pj_ntohs(addr->sin_port)) { 
    682686            /* Port or address mismatch, we should discard response */ 
    683687            /* But we saw one implementation (we don't want to name it to  
     
    687691             * both the port in sent-by and rport. We try to be lenient here! 
    688692             */ 
    689             if (rdata->via->rport_param != pj_sockaddr_get_port(addr)) 
     693            if (rdata->via->rport_param != pj_sockaddr_in_get_port(addr)) 
    690694                mismatch = PJ_TRUE; 
    691695            else { 
    692                 PJ_LOG(4,(LOG_THIS, "Response %p has mismatch port in sent-by" 
     696                PJ_LOG(4,(THIS_FILE, "Response %p has mismatch port in sent-by" 
    693697                                    " but the rport parameter is correct", 
    694698                                    rdata)); 
     
    699703            pjsip_event e; 
    700704 
    701             PJ_LOG(3, (LOG_THIS, "Response %p discarded: sent-by mismatch", 
    702                                  rdata)); 
    703  
    704             e.type = PJSIP_EVENT_DISCARD_MSG; 
    705             e.src_type = PJSIP_EVENT_RX_MSG; 
    706             e.src.rdata = rdata; 
    707             e.obj.ptr = NULL; 
     705            PJSIP_EVENT_INIT_DISCARD_MSG(e, rdata, PJSIP_EINVALIDVIA); 
    708706            endpt_do_event( endpt, &e ); 
    709707            return; 
     
    715713 
    716714    /* Find the transaction for the received message. */ 
    717     PJ_LOG(5, (LOG_THIS, "finding tsx with key=%.*s",  
     715    PJ_LOG(5, (THIS_FILE, "finding tsx with key=%.*s",  
    718716                         rdata->key.slen, rdata->key.ptr)); 
    719717 
     
    748746                pj_assert(0); 
    749747 
    750                 e.type = PJSIP_EVENT_RX_200_RESPONSE; 
    751                 e.src_type = PJSIP_EVENT_RX_MSG; 
    752                 e.src.rdata = rdata; 
    753                 e.obj.ptr = NULL; 
     748                PJSIP_EVENT_INIT_RX_200_MSG(e, rdata); 
    754749                endpt_do_event( endpt, &e ); 
    755750 
     
    758753                pjsip_event e; 
    759754 
    760                 PJ_LOG(3, (LOG_THIS, "Response %p discarded: transaction not found", 
    761                            rdata)); 
    762  
    763                 e.type = PJSIP_EVENT_DISCARD_MSG; 
    764                 e.src_type = PJSIP_EVENT_RX_MSG; 
    765                 e.src.rdata = rdata; 
    766                 e.obj.ptr = NULL; 
     755                PJSIP_EVENT_INIT_DISCARD_MSG(e, rdata,  
     756                    PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_CALL_TSX_DOES_NOT_EXIST)); 
    767757                endpt_do_event( endpt, &e ); 
    768758            } 
     
    772762         */ 
    773763        } else if (rdata->msg->line.req.method.id != PJSIP_ACK_METHOD) { 
     764 
     765            pj_status_t status; 
     766 
    774767            /* Create transaction, mutex is locked there. */ 
    775             tsx = pjsip_endpt_create_tsx(endpt); 
    776             if (!tsx) 
     768            status = pjsip_endpt_create_tsx(endpt, &tsx); 
     769            if (status != PJ_SUCCESS) { 
     770                PJSIP_ENDPT_LOG_ERROR((endpt, THIS_FILE, status, 
     771                                       "Unable to create transaction")); 
    777772                return; 
     773            } 
    778774 
    779775            /* Initialize transaction as UAS. */ 
     
    803799        pjsip_event event; 
    804800 
    805         event.type = PJSIP_EVENT_RX_ACK_MSG; 
    806         event.src_type = PJSIP_EVENT_RX_MSG; 
    807         event.src.rdata = rdata; 
    808         event.obj.ptr = NULL; 
     801        PJSIP_EVENT_INIT_RX_ACK_MSG(event,rdata); 
    809802        endpt_do_event( endpt, &event ); 
    810803    } 
     
    835828             */ 
    836829            pjsip_tx_data *tdata; 
     830            pj_status_t status; 
    837831             
    838832            if (tsx->method.id == PJSIP_OPTIONS_METHOD) { 
    839                 tdata = pjsip_endpt_create_response(endpt, rdata, 200); 
     833                status = pjsip_endpt_create_response(endpt, rdata, 200,  
     834                                                     &tdata); 
    840835            } else { 
    841                 tdata = pjsip_endpt_create_response(endpt, rdata,  
    842                                                     PJSIP_SC_METHOD_NOT_ALLOWED); 
    843             } 
     836                status = pjsip_endpt_create_response(endpt, rdata,  
     837                                                     PJSIP_SC_METHOD_NOT_ALLOWED, 
     838                                                     &tdata); 
     839            } 
     840 
     841            if (status != PJ_SUCCESS) { 
     842                PJSIP_ENDPT_LOG_ERROR((endpt, THIS_FILE, status, 
     843                                       "Unable to create response")); 
     844                return; 
     845            } 
     846 
    844847            if (endpt->allow_hdr) { 
    845848                pjsip_msg_add_hdr( tdata->msg,  
     
    856859             */ 
    857860            pjsip_tx_data *tdata; 
    858             tdata = pjsip_endpt_create_response(endpt, rdata, 500); 
     861            pj_status_t status; 
     862 
     863            status = pjsip_endpt_create_response(endpt, rdata, 500, &tdata); 
     864            if (status != PJ_SUCCESS) { 
     865                PJSIP_ENDPT_LOG_ERROR((endpt, THIS_FILE, status, 
     866                                       "Unable to create response")); 
     867                return; 
     868            } 
     869 
    859870            pjsip_tsx_on_tx_msg(tsx, tdata); 
    860871        } 
     
    865876 * Create transmit data buffer. 
    866877 */ 
    867 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_tdata( pjsip_endpoint *endpt ) 
    868 { 
    869     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create_tdata()")); 
    870     return pjsip_tx_data_create(endpt->transport_mgr); 
     878PJ_DEF(pj_status_t) pjsip_endpt_create_tdata(  pjsip_endpoint *endpt, 
     879                                               pjsip_tx_data **p_tdata) 
     880{ 
     881    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_tdata()")); 
     882    return pjsip_tx_data_create(endpt->transport_mgr, p_tdata); 
    871883} 
    872884 
     
    880892                                  pjsip_resolver_callback *cb) 
    881893{ 
    882     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_resolve()")); 
     894    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_resolve()")); 
    883895    pjsip_resolve( endpt->resolver, pool, target, token, cb); 
    884896} 
     
    894906                                        pjsip_transport_completion_callback *cb) 
    895907{ 
    896     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_get_transport()")); 
     908    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_get_transport()")); 
    897909    pjsip_transport_get( endpt->transport_mgr, pool, type, 
    898910                         remote, token, cb); 
     
    905917                                                 const pj_sockaddr_in *addr_name) 
    906918{ 
    907     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create_listener()")); 
     919    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_listener()")); 
    908920    return pjsip_create_listener( endpt->transport_mgr, type, addr, addr_name ); 
    909921} 
     
    913925                                                     const pj_sockaddr_in *addr_name) 
    914926{ 
    915     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create_udp_listener()")); 
     927    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_udp_listener()")); 
    916928    return pjsip_create_udp_listener( endpt->transport_mgr, sock, addr_name ); 
    917929} 
     
    924936    pj_hash_iterator_t *itr; 
    925937 
    926     PJ_LOG(5, (LOG_THIS, "pjsip_endpt_dump()")); 
     938    PJ_LOG(5, (THIS_FILE, "pjsip_endpt_dump()")); 
    927939 
    928940    /* Lock mutex. */ 
    929941    pj_mutex_lock(endpt->mutex); 
    930942 
    931     PJ_LOG(3, (LOG_THIS, "Dumping endpoint %p:", endpt)); 
     943    PJ_LOG(3, (THIS_FILE, "Dumping endpoint %p:", endpt)); 
    932944     
    933945    /* Dumping pool factory. */ 
     
    935947 
    936948    /* Pool health. */ 
    937     PJ_LOG(3, (LOG_THIS," Endpoint pool capacity=%u, used_size=%u", 
     949    PJ_LOG(3, (THIS_FILE," Endpoint pool capacity=%u, used_size=%u", 
    938950               pj_pool_get_capacity(endpt->pool), 
    939951               pj_pool_get_used_size(endpt->pool))); 
     
    941953    /* Transaction tables. */ 
    942954    count = pj_hash_count(endpt->tsx_table); 
    943     PJ_LOG(3, (LOG_THIS, " Number of transactions: %u", count)); 
     955    PJ_LOG(3, (THIS_FILE, " Number of transactions: %u", count)); 
    944956 
    945957    if (count && detail) { 
     
    948960        pj_time_val now; 
    949961 
    950         PJ_LOG(3, (LOG_THIS, " Dumping transaction tables:")); 
     962        PJ_LOG(3, (THIS_FILE, " Dumping transaction tables:")); 
    951963 
    952964        pj_gettimeofday(&now); 
     
    975987            } 
    976988 
    977             PJ_LOG(3, (LOG_THIS, "  %s %s %10.*s %.9u %s t=%ds",  
     989            PJ_LOG(3, (THIS_FILE, "  %s %s %10.*s %.9u %s t=%ds",  
    978990                       tsx->obj_name, role,  
    979991                       tsx->method.name.slen, tsx->method.name.ptr, 
     
    9921004    itr = pjsip_transport_first( endpt->transport_mgr, &itr_val ); 
    9931005    if (itr) { 
    994         PJ_LOG(3, (LOG_THIS, " Dumping transports:")); 
     1006        PJ_LOG(3, (THIS_FILE, " Dumping transports:")); 
    9951007 
    9961008        do { 
     
    10021014            t = pjsip_transport_this(endpt->transport_mgr, itr); 
    10031015            addr = pjsip_transport_get_local_addr(t); 
    1004             strcpy(src_addr, pj_sockaddr_get_str_addr(addr)); 
    1005             src_port = pj_sockaddr_get_port(addr); 
     1016            pj_native_strcpy(src_addr, pj_inet_ntoa(addr->sin_addr)); 
     1017            src_port = pj_ntohs(addr->sin_port); 
    10061018 
    10071019            addr = pjsip_transport_get_remote_addr(t); 
    1008             strcpy(dst_addr, pj_sockaddr_get_str_addr(addr)); 
    1009             dst_port = pj_sockaddr_get_port(addr); 
    1010  
    1011             PJ_LOG(3, (LOG_THIS, "  %s %s %s:%d --> %s:%d (refcnt=%d)",  
     1020            pj_native_strcpy(dst_addr, pj_inet_ntoa(addr->sin_addr)); 
     1021            dst_port = pj_ntohs(addr->sin_port); 
     1022 
     1023            PJ_LOG(3, (THIS_FILE, "  %s %s %s:%d --> %s:%d (refcnt=%d)",  
    10121024                       pjsip_transport_get_type_name(t), 
    10131025                       pjsip_transport_get_obj_name(t), 
     
    10211033 
    10221034    /* Timer. */ 
    1023     PJ_LOG(3,(LOG_THIS, " Timer heap has %u entries",  
     1035    PJ_LOG(3,(THIS_FILE, " Timer heap has %u entries",  
    10241036                        pj_timer_heap_count(endpt->timer_heap))); 
    10251037 
     
    10271039    pj_mutex_unlock(endpt->mutex); 
    10281040#else 
    1029     PJ_LOG(3,(LOG_THIS, "pjsip_end_dump: can't dump because it's disabled.")); 
     1041    PJ_LOG(3,(THIS_FILE, "pjsip_end_dump: can't dump because it's disabled.")); 
    10301042#endif 
    10311043} 
  • pjproject/main/pjsip/src/pjsip/sip_misc.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_misc.h> 
     
    1413#include <pj/pool.h> 
    1514#include <pj/except.h> 
    16  
    17 #define LOG_THIS    "endpoint..." 
     15#include <pj/rand.h> 
     16#include <pj/assert.h> 
     17#include <pj/errno.h> 
     18 
     19#define THIS_FILE    "endpoint" 
    1820 
    1921static const char *event_str[] =  
     
    4547                                 struct pjsip_module *mod, pj_uint32_t id ) 
    4648{ 
    47     PJ_UNUSED_ARG(endpt) 
    48     PJ_UNUSED_ARG(mod) 
     49    PJ_UNUSED_ARG(endpt); 
     50    PJ_UNUSED_ARG(mod); 
    4951 
    5052    aux_mod_id = id; 
     
    5456static void aux_tsx_handler( struct pjsip_module *mod, pjsip_event *event ) 
    5557{ 
    56     pjsip_transaction *tsx = event->obj.tsx; 
     58    pjsip_transaction *tsx; 
    5759    struct aux_tsx_data *tsx_data; 
    5860 
    59     PJ_UNUSED_ARG(mod) 
    60  
    61     if (event->type != PJSIP_EVENT_TSX_STATE_CHANGED) 
     61    PJ_UNUSED_ARG(mod); 
     62 
     63    if (event->type != PJSIP_EVENT_TSX_STATE) 
    6264        return; 
     65 
     66    pj_assert(event->body.tsx_state.tsx != NULL); 
     67    tsx = event->body.tsx_state.tsx; 
    6368    if (tsx == NULL) 
    6469        return; 
     
    101106    pjsip_transaction *tsx; 
    102107    struct aux_tsx_data *tsx_data; 
    103  
    104     tsx = pjsip_endpt_create_tsx(endpt); 
     108    pj_status_t status; 
     109 
     110    status = pjsip_endpt_create_tsx(endpt, &tsx); 
    105111    if (!tsx) { 
    106112        pjsip_tx_data_dec_ref(tdata); 
     
    135141 * this function. 
    136142 */ 
    137 static void init_request_throw( pjsip_tx_data *tdata,  
     143static void init_request_throw( pjsip_endpoint *endpt, 
     144                                pjsip_tx_data *tdata,  
    138145                                pjsip_method *method, 
    139146                                pjsip_uri *param_target, 
     
    147154    pjsip_msg *msg; 
    148155    pjsip_msg_body *body; 
     156    const pjsip_hdr *endpt_hdr; 
    149157 
    150158    /* Create the message. */ 
     
    154162    pj_memcpy(&msg->line.req.method, method, sizeof(*method)); 
    155163    msg->line.req.uri = param_target; 
     164 
     165    /* Add additional request headers from endpoint. */ 
     166    endpt_hdr = pjsip_endpt_get_request_headers(endpt)->next; 
     167    while (endpt_hdr != pjsip_endpt_get_request_headers(endpt)) { 
     168        pjsip_hdr *hdr = pjsip_hdr_shallow_clone(tdata->pool, endpt_hdr); 
     169        pjsip_msg_add_hdr( tdata->msg, hdr ); 
     170        endpt_hdr = endpt_hdr->next; 
     171    } 
    156172 
    157173    /* Add From header. */ 
     
    190206 * Create arbitrary request. 
    191207 */ 
    192 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_request(  pjsip_endpoint *endpt,  
    193                                                     const pjsip_method *method, 
    194                                                     const pj_str_t *param_target, 
    195                                                     const pj_str_t *param_from, 
    196                                                     const pj_str_t *param_to,  
    197                                                     const pj_str_t *param_contact, 
    198                                                     const pj_str_t *param_call_id, 
    199                                                     int param_cseq,  
    200                                                     const pj_str_t *param_text) 
     208PJ_DEF(pj_status_t) pjsip_endpt_create_request(  pjsip_endpoint *endpt,  
     209                                                 const pjsip_method *method, 
     210                                                 const pj_str_t *param_target, 
     211                                                 const pj_str_t *param_from, 
     212                                                 const pj_str_t *param_to,  
     213                                                 const pj_str_t *param_contact, 
     214                                                 const pj_str_t *param_call_id, 
     215                                                 int param_cseq,  
     216                                                 const pj_str_t *param_text, 
     217                                                 pjsip_tx_data **p_tdata) 
    201218{ 
    202219    pjsip_uri *target; 
     
    208225    pjsip_cid_hdr *call_id; 
    209226    pj_str_t tmp; 
     227    pj_status_t status; 
    210228    PJ_USE_EXCEPTION; 
    211229 
    212     PJ_LOG(5,(LOG_THIS, "Entering pjsip_endpt_create_request()")); 
    213  
    214     tdata = pjsip_endpt_create_tdata(endpt); 
    215     if (!tdata) 
    216         return NULL; 
     230    PJ_LOG(5,(THIS_FILE, "Entering pjsip_endpt_create_request()")); 
     231 
     232    status = pjsip_endpt_create_tdata(endpt, &tdata); 
     233    if (status != PJ_SUCCESS) 
     234        return status; 
    217235 
    218236    /* Init reference counter to 1. */ 
     
    224242        target = pjsip_parse_uri( tdata->pool, tmp.ptr, tmp.slen, 0); 
    225243        if (target == NULL) { 
    226             PJ_LOG(4,(LOG_THIS, "Error creating request: invalid target %s",  
     244            PJ_LOG(4,(THIS_FILE, "Error creating request: invalid target %s",  
    227245                      tmp.ptr)); 
    228246            goto on_error; 
     
    235253                                     PJSIP_PARSE_URI_AS_NAMEADDR); 
    236254        if (from->uri == NULL) { 
    237             PJ_LOG(4,(LOG_THIS, "Error creating request: invalid 'From' URI '%s'", 
     255            PJ_LOG(4,(THIS_FILE, "Error creating request: invalid 'From' URI '%s'", 
    238256                                tmp.ptr)); 
    239257            goto on_error; 
     
    247265                                   PJSIP_PARSE_URI_AS_NAMEADDR); 
    248266        if (to->uri == NULL) { 
    249             PJ_LOG(4,(LOG_THIS, "Error creating request: invalid 'To' URI '%s'", 
     267            PJ_LOG(4,(THIS_FILE, "Error creating request: invalid 'To' URI '%s'", 
    250268                                tmp.ptr)); 
    251269            goto on_error; 
     
    259277                                            PJSIP_PARSE_URI_AS_NAMEADDR); 
    260278            if (contact->uri == NULL) { 
    261                 PJ_LOG(4,(LOG_THIS,  
     279                PJ_LOG(4,(THIS_FILE,  
    262280                          "Error creating request: invalid 'Contact' URI '%s'", 
    263281                          tmp.ptr)); 
     
    286304 
    287305        /* Create the request. */ 
    288         init_request_throw( tdata, &cseq->method, target, from, to, contact,  
    289                             call_id, cseq, param_text); 
     306        init_request_throw( endpt, tdata, &cseq->method, target, from, to,  
     307                            contact, call_id, cseq, param_text); 
    290308    } 
    291309    PJ_DEFAULT { 
    292         PJ_LOG(4,(LOG_THIS, "Caught exception %d when creating request",  
    293                             PJ_GET_EXCEPTION())); 
     310        status = PJ_ENOMEM; 
    294311        goto on_error; 
    295312    } 
    296313    PJ_END 
    297314 
    298     PJ_LOG(4,(LOG_THIS, "Request %s (%d %.*s) created.",  
     315    PJ_LOG(4,(THIS_FILE, "Request %s (%d %.*s) created.",  
    299316                        tdata->obj_name,  
    300317                        cseq->cseq,  
     
    302319                        cseq->method.name.ptr)); 
    303320 
    304     return tdata; 
     321    *p_tdata = tdata; 
     322    return PJ_SUCCESS; 
    305323 
    306324on_error: 
    307325    pjsip_tx_data_dec_ref(tdata); 
    308     return NULL; 
    309 } 
    310  
    311 PJ_DEF(pjsip_tx_data*) 
     326    return status; 
     327} 
     328 
     329PJ_DEF(pj_status_t) 
    312330pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, 
    313331                                     const pjsip_method *method, 
     
    318336                                     const pjsip_cid_hdr *param_call_id, 
    319337                                     int param_cseq, 
    320                                      const pj_str_t *param_text ) 
     338                                     const pj_str_t *param_text, 
     339                                     pjsip_tx_data **p_tdata) 
    321340{ 
    322341    pjsip_uri *target; 
     
    327346    pjsip_cid_hdr *call_id; 
    328347    pjsip_cseq_hdr *cseq = NULL; /* The NULL because warning in VC6 */ 
     348    pj_status_t status; 
    329349    PJ_USE_EXCEPTION; 
    330350 
    331     PJ_LOG(5,(LOG_THIS, "Entering pjsip_endpt_create_request_from_hdr()")); 
    332  
    333     tdata = pjsip_endpt_create_tdata(endpt); 
    334     if (!tdata) 
    335         return NULL; 
     351    PJ_LOG(5,(THIS_FILE, "Entering pjsip_endpt_create_request_from_hdr()")); 
     352 
     353    status = pjsip_endpt_create_tdata(endpt, &tdata); 
     354    if (status != PJ_SUCCESS) 
     355        return status; 
    336356 
    337357    pjsip_tx_data_add_ref(tdata); 
     
    355375        pjsip_method_copy(tdata->pool, &cseq->method, method); 
    356376 
    357         init_request_throw(tdata, &cseq->method, target, from, to, contact,  
    358                           call_id, cseq, param_text); 
     377        init_request_throw(endpt, tdata, &cseq->method, target, from, to,  
     378                           contact, call_id, cseq, param_text); 
    359379    } 
    360380    PJ_DEFAULT { 
    361         PJ_LOG(4,(LOG_THIS, "Caught exception %d when creating request",  
    362                             PJ_GET_EXCEPTION())); 
     381        status = PJ_ENOMEM; 
    363382        goto on_error; 
    364383    } 
    365384    PJ_END; 
    366385 
    367     PJ_LOG(4,(LOG_THIS, "Request %s (%d %.*s) created.",  
     386    PJ_LOG(4,(THIS_FILE, "Request %s (%d %.*s) created.",  
    368387                        tdata->obj_name,  
    369388                        cseq->cseq,  
    370389                        cseq->method.name.slen, 
    371390                        cseq->method.name.ptr)); 
    372     return tdata; 
     391 
     392    *p_tdata = tdata; 
     393    return PJ_SUCCESS; 
    373394 
    374395on_error: 
    375396    pjsip_tx_data_dec_ref(tdata); 
    376     return NULL; 
     397    return status; 
    377398} 
    378399 
     
    380401 * Construct a minimal response message for the received request. 
    381402 */ 
    382 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_response( pjsip_endpoint *endpt, 
    383                                                     const pjsip_rx_data *rdata, 
    384                                                     int code) 
     403PJ_DEF(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, 
     404                                                 const pjsip_rx_data *rdata, 
     405                                                 int code, 
     406                                                 pjsip_tx_data **p_tdata) 
    385407{ 
    386408    pjsip_tx_data *tdata; 
     
    389411    pjsip_via_hdr *via; 
    390412    pjsip_rr_hdr *rr; 
     413    pj_status_t status; 
    391414 
    392415    /* rdata must be a request message. */ 
     
    395418 
    396419    /* Log this action. */ 
    397     PJ_LOG(5,(LOG_THIS, "pjsip_endpt_create_response(rdata=%p, code=%d)",  
     420    PJ_LOG(5,(THIS_FILE, "pjsip_endpt_create_response(rdata=%p, code=%d)",  
    398421                         rdata, code)); 
    399422 
    400423    /* Create a new transmit buffer. */ 
    401     tdata = pjsip_endpt_create_tdata( endpt ); 
    402     if (!tdata) 
    403         return NULL; 
     424    status = pjsip_endpt_create_tdata( endpt, &tdata); 
     425    if (status != PJ_SUCCESS) 
     426        return status; 
    404427 
    405428    /* Create new response message. */ 
     
    452475 
    453476    /* All done. */ 
    454     return tdata; 
     477    *p_tdata = tdata; 
     478    return PJ_SUCCESS; 
    455479} 
    456480 
     
    479503 
    480504    /* Log this action. */ 
    481     PJ_LOG(5,(LOG_THIS, "pjsip_endpt_create_ack(rdata=%p)", rdata)); 
     505    PJ_LOG(5,(THIS_FILE, "pjsip_endpt_create_ack(rdata=%p)", rdata)); 
    482506 
    483507    /* Create new request message. */ 
     
    503527    to = (pjsip_to_hdr*)pjsip_msg_find_remove_hdr( invite_msg,  
    504528                                                   PJSIP_H_TO, NULL); 
    505     pj_strdup(tdata->pool, &to->tag, &rdata->to_tag); 
     529    pj_strdup(tdata->pool, &to->tag, &rdata->to->tag); 
    506530    pjsip_msg_add_hdr( ack_msg, (pjsip_hdr*)to ); 
    507531 
     
    543567 * chapter 9.1 of RFC3261. 
    544568 */ 
    545 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
    546                                                   pjsip_tx_data *req_tdata ) 
     569PJ_DEF(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
     570                                               pjsip_tx_data *req_tdata, 
     571                                               pjsip_tx_data **p_tdata) 
    547572{ 
    548573    pjsip_msg *req_msg; /* the original request. */ 
     
    552577    pjsip_cseq_hdr *req_cseq, *cseq; 
    553578    pjsip_uri *req_uri; 
     579    pj_status_t status; 
    554580 
    555581    /* Log this action. */ 
    556     PJ_LOG(5,(LOG_THIS, "pjsip_endpt_create_cancel(tdata=%p)", req_tdata)); 
     582    PJ_LOG(5,(THIS_FILE, "pjsip_endpt_create_cancel(tdata=%p)", req_tdata)); 
    557583 
    558584    /* Get the original request. */ 
     
    560586 
    561587    /* The transmit buffer must INVITE request. */ 
    562     pj_assert(req_msg->type == PJSIP_REQUEST_MSG && 
    563               req_msg->line.req.method.id == PJSIP_INVITE_METHOD ); 
     588    PJ_ASSERT_RETURN(req_msg->type == PJSIP_REQUEST_MSG && 
     589                     req_msg->line.req.method.id == PJSIP_INVITE_METHOD, 
     590                     PJ_EINVAL); 
    564591 
    565592    /* Create new transmit buffer. */ 
    566     cancel_tdata = pjsip_endpt_create_tdata( endpt ); 
    567     if (!cancel_tdata) { 
    568         return NULL; 
     593    status = pjsip_endpt_create_tdata( endpt, &cancel_tdata); 
     594    if (status != PJ_SUCCESS) { 
     595        return status; 
    569596    } 
    570597 
     
    624651     * Return the transmit buffer containing the CANCEL request. 
    625652     */ 
    626     return cancel_tdata; 
     653    *p_tdata = cancel_tdata; 
     654    return PJ_SUCCESS; 
    627655} 
    628656 
     
    651679        remote_addr = pjsip_transport_get_remote_addr(req_transport); 
    652680        pj_strdup2(pool, &send_addr->host,  
    653                    pj_sockaddr_get_str_addr(remote_addr)); 
    654         send_addr->port = pj_sockaddr_get_port(remote_addr); 
     681                   pj_inet_ntoa(remote_addr->sin_addr)); 
     682        send_addr->port = pj_sockaddr_in_get_port(remote_addr); 
    655683 
    656684    } else { 
  • pjproject/main/pjsip/src/pjsip/sip_msg.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_msg.h> 
    5 #include <pjsip/print.h> 
     4#include <pjsip/print_util.h> 
    65#include <pj/string.h> 
    76#include <pj/pool.h> 
     
    265264} 
    266265 
    267 PJ_DEF(int) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size) 
     266PJ_DEF(pj_ssize_t) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size) 
    268267{ 
    269268    char *p=buf, *end=buf+size; 
  • pjproject/main/pjsip/src/pjsip/sip_parser.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_parser.h> 
     
    65#include <pjsip/sip_msg.h> 
    76#include <pjsip/sip_auth_parser.h> 
    8 #include <pj/scanner.h> 
     7#include <pjsip/sip_errno.h> 
     8#include <pjsip/sip_transport.h>        /* rdata structure */ 
     9#include <pjlib-util/scanner.h> 
    910#include <pj/except.h> 
    1011#include <pj/log.h> 
     
    1314#include <pj/pool.h> 
    1415#include <pj/string.h> 
    15 #include <ctype.h>      /* tolower() */ 
     16#include <pj/ctype.h> 
     17#include <pj/assert.h> 
    1618 
    1719#define RESERVED    ";/?:@&=+$," 
     
    2022#define USER        "&=+$,;?/" 
    2123#define PASS        "&=+$," 
    22 #define TOKEN       "-.!%*_=`'~+"   /* '+' is because of application/pidf+xml in Content-Type! */ 
     24#define TOKEN       "-.!%*_=`'~+"   /* '+' is because of application/pidf+xml 
     25                                     * in Content-Type! */ 
    2326#define HOST        "_-." 
    2427#define HEX_DIGIT   "abcdefABCDEF" 
     
    4649 * Global vars (also extern). 
    4750 */ 
    48 const pj_str_t  pjsip_USER_STR = { "user", 4}; 
    49 const pj_str_t  pjsip_METHOD_STR = { "method", 6}; 
     51const pj_str_t  pjsip_USER_STR      = { "user", 4}; 
     52const pj_str_t  pjsip_METHOD_STR    = { "method", 6}; 
    5053const pj_str_t  pjsip_TRANSPORT_STR = { "transport", 9}; 
    51 const pj_str_t  pjsip_MADDR_STR = { "maddr", 5 }; 
    52 const pj_str_t  pjsip_LR_STR = { "lr", 2 }; 
    53 const pj_str_t  pjsip_SIP_STR = { "sip", 3 }; 
    54 const pj_str_t  pjsip_SIPS_STR = { "sips", 4 }; 
    55 const pj_str_t  pjsip_TEL_STR = { "tel", 3 }; 
    56 const pj_str_t  pjsip_BRANCH_STR = { "branch", 6 }; 
    57 const pj_str_t  pjsip_TTL_STR = { "ttl", 3 }; 
    58 const pj_str_t  pjsip_PNAME_STR = { "received", 8 }; 
    59 const pj_str_t  pjsip_Q_STR = { "q", 1 }; 
    60 const pj_str_t  pjsip_EXPIRES_STR = { "expires", 7 }; 
    61 const pj_str_t  pjsip_TAG_STR = { "tag", 3 }; 
    62 const pj_str_t  pjsip_RPORT_STR = { "rport", 5}; 
    63  
    64 pj_char_spec    pjsip_HOST_SPEC,            /* For scanning host part. */ 
    65                 pjsip_DIGIT_SPEC,           /* Decimal digits */ 
    66                 pjsip_ALPHA_SPEC,           /* Alpha (A-Z, a-z) */ 
    67                 pjsip_ALNUM_SPEC,           /* Decimal + Alpha. */ 
    68                 pjsip_TOKEN_SPEC,           /* Token. */ 
    69                 pjsip_HEX_SPEC,             /* Hexadecimal digits. */ 
    70                 pjsip_PARAM_CHAR_SPEC,      /* For scanning pname (or pvalue when it's not quoted.) */ 
    71                 pjsip_PROBE_USER_HOST_SPEC, /* Hostname characters. */ 
    72                 pjsip_PASSWD_SPEC,          /* Password. */ 
    73                 pjsip_USER_SPEC,            /* User */ 
    74                 pjsip_ARRAY_ELEMENTS,       /* Array separator. */ 
    75                 pjsip_NEWLINE_OR_EOF_SPEC,  /* For eating up header.*/ 
    76                 pjsip_DISPLAY_SCAN_SPEC;    /* Used when searching for display name in URL. */ 
     54const pj_str_t  pjsip_MADDR_STR     = { "maddr", 5 }; 
     55const pj_str_t  pjsip_LR_STR        = { "lr", 2 }; 
     56const pj_str_t  pjsip_SIP_STR       = { "sip", 3 }; 
     57const pj_str_t  pjsip_SIPS_STR      = { "sips", 4 }; 
     58const pj_str_t  pjsip_TEL_STR       = { "tel", 3 }; 
     59const pj_str_t  pjsip_BRANCH_STR    = { "branch", 6 }; 
     60const pj_str_t  pjsip_TTL_STR       = { "ttl", 3 }; 
     61const pj_str_t  pjsip_PNAME_STR     = { "received", 8 }; 
     62const pj_str_t  pjsip_Q_STR         = { "q", 1 }; 
     63const pj_str_t  pjsip_EXPIRES_STR   = { "expires", 7 }; 
     64const pj_str_t  pjsip_TAG_STR       = { "tag", 3 }; 
     65const pj_str_t  pjsip_RPORT_STR     = { "rport", 5}; 
     66 
     67/* Character Input Specification buffer. */ 
     68static pj_cis_buf_t cis_buf; 
     69 
     70/* Character Input Specifications. */ 
     71pj_cis_t    pjsip_HOST_SPEC,            /* For scanning host part. */ 
     72            pjsip_DIGIT_SPEC,           /* Decimal digits */ 
     73            pjsip_ALPHA_SPEC,           /* Alpha (A-Z, a-z) */ 
     74            pjsip_ALNUM_SPEC,           /* Decimal + Alpha. */ 
     75            pjsip_TOKEN_SPEC,           /* Token. */ 
     76            pjsip_HEX_SPEC,             /* Hexadecimal digits. */ 
     77            pjsip_PARAM_CHAR_SPEC,      /* For scanning pname (or pvalue when 
     78                                         * it's not quoted.) */ 
     79            pjsip_PROBE_USER_HOST_SPEC, /* Hostname characters. */ 
     80            pjsip_PASSWD_SPEC,          /* Password. */ 
     81            pjsip_USER_SPEC,            /* User */ 
     82            pjsip_ARRAY_ELEMENTS,       /* Array separator. */ 
     83            pjsip_NEWLINE_OR_EOF_SPEC,  /* For eating up header.*/ 
     84            pjsip_DISPLAY_SCAN_SPEC;    /* Used when searching for display name 
     85                                         * in URL. */ 
    7786 
    7887 
     
    8089 * Forward decl. 
    8190 */ 
    82 static pjsip_msg *        int_parse_msg( pj_scanner *scanner,  
    83                                          pj_pool_t *pool,  
    84                                          pjsip_parser_err_report *err_list); 
    85 static void               int_parse_param( pj_scanner *scanner,  
    86                                            pj_str_t *pname,  
    87                                            pj_str_t *pvalue); 
    88 static void               int_parse_req_line( pj_scanner *scanner,  
    89                                               pj_pool_t *pool, 
    90                                               pjsip_request_line *req_line); 
    91 static int                int_is_next_user( pj_scanner *scanner); 
    92 static void               int_parse_status_line( pj_scanner *scanner,  
    93                                                  pjsip_status_line *line); 
    94 static void               int_parse_user_pass( pj_scanner *scanner,  
    95                                                pj_str_t *user,  
    96                                                pj_str_t *pass); 
    97 static void               int_parse_uri_host_port( pj_scanner *scanner,  
    98                                                    pj_str_t *p_host,  
    99                                                    int *p_port); 
    100 static pjsip_uri *        int_parse_uri_or_name_addr( pj_scanner *scanner,  
    101                                             pj_pool_t *pool, unsigned option); 
    102 static pjsip_url *        int_parse_sip_url( pj_scanner *scanner,  
    103                                              pj_pool_t *pool, 
    104                                              pj_bool_t parse_params); 
    105 static pjsip_name_addr*   int_parse_name_addr( pj_scanner *scanner,  
    106                                                pj_pool_t *pool ); 
    107 static void               parse_hdr_end( pj_scanner *scanner ); 
    108 static pjsip_accept_hdr*  parse_hdr_accept( pj_scanner *scanner,  
    109                                             pj_pool_t *pool); 
    110 static pjsip_allow_hdr*   parse_hdr_allow( pj_scanner *scanner,  
    111                                            pj_pool_t *pool); 
    112 static pjsip_cid_hdr*     parse_hdr_call_id( pj_scanner *scanner,  
    113                                              pj_pool_t *pool); 
    114 static pjsip_contact_hdr* parse_hdr_contact( pj_scanner *scanner,  
    115                                              pj_pool_t *pool); 
    116 static pjsip_clen_hdr*    parse_hdr_content_length( pj_scanner *scanner,  
    117                                                     pj_pool_t *pool); 
    118 static pjsip_ctype_hdr*   parse_hdr_content_type( pj_scanner *scanner,  
    119                                                   pj_pool_t *pool); 
    120 static pjsip_cseq_hdr*    parse_hdr_cseq( pj_scanner *scanner,  
    121                                           pj_pool_t *pool); 
    122 static pjsip_expires_hdr* parse_hdr_expires( pj_scanner *scanner,  
    123                                           pj_pool_t *pool); 
    124 static pjsip_from_hdr*    parse_hdr_from( pj_scanner *scanner,  
    125                                           pj_pool_t *pool); 
    126 static pjsip_max_forwards_hdr*  parse_hdr_max_forwards( pj_scanner *scanner,  
    127                                         pj_pool_t *pool); 
    128 static pjsip_min_expires_hdr*  parse_hdr_min_expires( pj_scanner *scanner,  
    129                                         pj_pool_t *pool); 
    130 static pjsip_rr_hdr*      parse_hdr_rr( pj_scanner *scanner,  
    131                                         pj_pool_t *pool); 
    132 static pjsip_route_hdr*   parse_hdr_route( pj_scanner *scanner,  
    133                                            pj_pool_t *pool); 
    134 static pjsip_require_hdr* parse_hdr_require( pj_scanner *scanner,  
    135                                         pj_pool_t *pool); 
    136 static pjsip_retry_after_hdr* parse_hdr_retry_after( pj_scanner *scanner,  
    137                                         pj_pool_t *pool); 
    138 static pjsip_supported_hdr* parse_hdr_supported( pj_scanner *scanner,  
    139                                         pj_pool_t *pool); 
    140 static pjsip_to_hdr*      parse_hdr_to( pj_scanner *scanner,  
    141                                         pj_pool_t *pool); 
    142 static pjsip_unsupported_hdr* parse_hdr_unsupported( pj_scanner *scanner,  
    143                                         pj_pool_t *pool); 
    144 static pjsip_via_hdr*     parse_hdr_via( pj_scanner *scanner,  
    145                                          pj_pool_t *pool); 
    146 static pjsip_generic_string_hdr* parse_hdr_generic_string( pj_scanner *scanner,  
    147                                              pj_pool_t *pool); 
     91static pjsip_msg *  int_parse_msg( pjsip_parse_ctx *ctx,  
     92                                   pjsip_parser_err_report *err_list); 
     93static void         int_parse_param( pj_scanner *scanner,  
     94                                     pj_str_t *pname,  
     95                                     pj_str_t *pvalue); 
     96static void         int_parse_req_line( pj_scanner *scanner,  
     97                                        pj_pool_t *pool, 
     98                                        pjsip_request_line *req_line); 
     99static int          int_is_next_user( pj_scanner *scanner); 
     100static void         int_parse_status_line( pj_scanner *scanner,  
     101                                           pjsip_status_line *line); 
     102static void         int_parse_user_pass( pj_scanner *scanner,  
     103                                         pj_str_t *user,  
     104                                         pj_str_t *pass); 
     105static void         int_parse_uri_host_port( pj_scanner *scanner,  
     106                                             pj_str_t *p_host,  
     107                                             int *p_port); 
     108static pjsip_uri *  int_parse_uri_or_name_addr( pj_scanner *scanner,  
     109                                                pj_pool_t *pool,  
     110                                                unsigned option); 
     111static pjsip_url *  int_parse_sip_url( pj_scanner *scanner,  
     112                                       pj_pool_t *pool, 
     113                                       pj_bool_t parse_params); 
     114static pjsip_name_addr * 
     115                    int_parse_name_addr( pj_scanner *scanner,  
     116                                         pj_pool_t *pool ); 
     117static void         parse_hdr_end( pj_scanner *scanner ); 
     118 
     119static pjsip_hdr*   parse_hdr_accept( pjsip_parse_ctx *ctx ); 
     120static pjsip_hdr*   parse_hdr_allow( pjsip_parse_ctx *ctx ); 
     121static pjsip_hdr*   parse_hdr_call_id( pjsip_parse_ctx *ctx); 
     122static pjsip_hdr*   parse_hdr_contact( pjsip_parse_ctx *ctx); 
     123static pjsip_hdr*   parse_hdr_content_len( pjsip_parse_ctx *ctx ); 
     124static pjsip_hdr*   parse_hdr_content_type( pjsip_parse_ctx *ctx ); 
     125static pjsip_hdr*   parse_hdr_cseq( pjsip_parse_ctx *ctx ); 
     126static pjsip_hdr*   parse_hdr_expires( pjsip_parse_ctx *ctx ); 
     127static pjsip_hdr*   parse_hdr_from( pjsip_parse_ctx *ctx ); 
     128static pjsip_hdr*   parse_hdr_max_forwards( pjsip_parse_ctx *ctx); 
     129static pjsip_hdr*   parse_hdr_min_expires( pjsip_parse_ctx *ctx ); 
     130static pjsip_hdr*   parse_hdr_rr( pjsip_parse_ctx *ctx ); 
     131static pjsip_hdr*   parse_hdr_route( pjsip_parse_ctx *ctx ); 
     132static pjsip_hdr*   parse_hdr_require( pjsip_parse_ctx *ctx ); 
     133static pjsip_hdr*   parse_hdr_retry_after( pjsip_parse_ctx *ctx ); 
     134static pjsip_hdr*   parse_hdr_supported( pjsip_parse_ctx *ctx ); 
     135static pjsip_hdr*   parse_hdr_to( pjsip_parse_ctx *ctx ); 
     136static pjsip_hdr*   parse_hdr_unsupported( pjsip_parse_ctx *ctx ); 
     137static pjsip_hdr*   parse_hdr_via( pjsip_parse_ctx *ctx ); 
     138static pjsip_hdr*   parse_hdr_generic_string( pjsip_parse_ctx *ctx); 
    148139 
    149140/* Convert non NULL terminated string to integer. */ 
    150 static unsigned long pj_strtoul_mindigit(const pj_str_t *str, unsigned mindig) 
     141static unsigned long pj_strtoul_mindigit(const pj_str_t *str,  
     142                                         unsigned mindig) 
    151143{ 
    152144    unsigned long value; 
     
    164156 
    165157/* Case insensitive comparison */ 
    166 #define parser_stricmp(str1, str2)  \ 
    167             (str1.slen != str2.slen ? -1 : \ 
    168                 !(memcmp(str1.ptr, str2.ptr, str1.slen)==0 || stricmp(str1.ptr, str2.ptr)==0)) 
     158#define parser_stricmp(str1, str2)  pj_stricmp(&str1, &str2) 
     159 
    169160 
    170161/* Syntax error handler for parser. */ 
    171162static void on_syntax_error(pj_scanner *scanner) 
    172163{ 
    173     PJ_UNUSED_ARG(scanner) 
     164    PJ_UNUSED_ARG(scanner); 
    174165    PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
    175166} 
     
    177168/* Concatenate unrecognized params into single string. */ 
    178169void pjsip_concat_param_imp( pj_str_t *param, pj_pool_t *pool,  
    179                              const pj_str_t *pname, const pj_str_t *pvalue, int sepchar) 
     170                             const pj_str_t *pname, const pj_str_t *pvalue,  
     171                             int sepchar) 
    180172{ 
    181173    char *new_param, *p; 
     
    214206 
    215207/* Initialize static properties of the parser. */ 
    216 static void init_parser() 
     208static pj_status_t init_parser() 
    217209{ 
    218210    static int initialized; 
     211    pj_status_t status; 
    219212 
    220213    if (initialized) 
    221         return; 
     214        return PJ_SUCCESS; 
    222215 
    223216    initialized = 1; 
    224217 
    225     pj_cs_add_num( pjsip_DIGIT_SPEC ); 
    226     pj_cs_add_alpha( pjsip_ALPHA_SPEC ); 
     218    pj_cis_buf_init(&cis_buf); 
     219 
     220    status = pj_cis_init(&cis_buf, &pjsip_DIGIT_SPEC); 
     221    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     222    pj_cis_add_num(&pjsip_DIGIT_SPEC); 
    227223     
    228     pj_cs_add_alpha( pjsip_ALNUM_SPEC ); 
    229     pj_cs_add_num( pjsip_ALNUM_SPEC ); 
    230  
    231     pj_cs_add_str(pjsip_NEWLINE_OR_EOF_SPEC, "\r\n"); 
     224    status = pj_cis_init(&cis_buf, &pjsip_ALPHA_SPEC); 
     225    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     226    pj_cis_add_alpha( &pjsip_ALPHA_SPEC ); 
     227     
     228    status = pj_cis_init(&cis_buf, &pjsip_ALNUM_SPEC); 
     229    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     230    pj_cis_add_alpha( &pjsip_ALNUM_SPEC ); 
     231    pj_cis_add_num( &pjsip_ALNUM_SPEC ); 
     232 
     233    status = pj_cis_init(&cis_buf, &pjsip_NEWLINE_OR_EOF_SPEC); 
     234    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     235    pj_cis_add_str(&pjsip_NEWLINE_OR_EOF_SPEC, "\r\n"); 
    232236    //pj_cs_set(pjsip_NEWLINE_OR_EOF_SPEC, 0); 
    233237 
    234     pj_cs_add_str( pjsip_ARRAY_ELEMENTS, ",\r\n"); 
    235  
    236     pj_memcpy(pjsip_TOKEN_SPEC, pjsip_ALNUM_SPEC, sizeof(pj_char_spec)); 
    237     pj_cs_add_str( pjsip_TOKEN_SPEC, TOKEN); 
    238  
    239     pj_memcpy(pjsip_HOST_SPEC, pjsip_ALNUM_SPEC, sizeof(pj_char_spec)); 
    240     pj_cs_add_str( pjsip_HOST_SPEC, HOST); 
    241  
    242     pj_memcpy(pjsip_HEX_SPEC, pjsip_DIGIT_SPEC, sizeof(pj_char_spec)); 
    243     pj_cs_add_str( pjsip_HEX_SPEC, HEX_DIGIT); 
    244  
    245     pj_memcpy(pjsip_PARAM_CHAR_SPEC, pjsip_ALNUM_SPEC, sizeof(pj_char_spec)); 
    246     pj_cs_add_str( pjsip_PARAM_CHAR_SPEC, PARAM_CHAR); 
    247  
    248     pj_memcpy(pjsip_USER_SPEC, pjsip_ALNUM_SPEC, sizeof(pj_char_spec)); 
    249     pj_cs_add_str( pjsip_USER_SPEC, MARK ESCAPED USER ); 
    250  
    251     pj_memcpy(pjsip_PASSWD_SPEC, pjsip_ALNUM_SPEC, sizeof(pj_char_spec)); 
    252     pj_cs_add_str( pjsip_PASSWD_SPEC, MARK ESCAPED PASS); 
    253  
    254     pj_cs_add_str( pjsip_PROBE_USER_HOST_SPEC, "@ \n>"); 
    255     pj_cs_invert( pjsip_PROBE_USER_HOST_SPEC ); 
    256  
    257     pj_cs_add_str( pjsip_DISPLAY_SCAN_SPEC, ":\r\n<"); 
    258  
    259     pjsip_register_hdr_parser( "Accept", NULL, (pjsip_parse_hdr_func*) &parse_hdr_accept); 
    260     pjsip_register_hdr_parser( "Allow", NULL, (pjsip_parse_hdr_func*) &parse_hdr_allow); 
    261     pjsip_register_hdr_parser( "Call-ID", NULL, (pjsip_parse_hdr_func*) &parse_hdr_call_id); 
    262     pjsip_register_hdr_parser( "Contact", "m", (pjsip_parse_hdr_func*) &parse_hdr_contact); 
    263     pjsip_register_hdr_parser( "Content-Length", NULL, (pjsip_parse_hdr_func*) &parse_hdr_content_length); 
    264     pjsip_register_hdr_parser( "Content-Type", NULL, (pjsip_parse_hdr_func*) &parse_hdr_content_type); 
    265     pjsip_register_hdr_parser( "CSeq", NULL, (pjsip_parse_hdr_func*) &parse_hdr_cseq); 
    266     pjsip_register_hdr_parser( "Expires", NULL, (pjsip_parse_hdr_func*) &parse_hdr_expires); 
    267     pjsip_register_hdr_parser( "From", "f", (pjsip_parse_hdr_func*) &parse_hdr_from); 
    268     pjsip_register_hdr_parser( "Max-Forwards", NULL, (pjsip_parse_hdr_func*) &parse_hdr_max_forwards); 
    269     pjsip_register_hdr_parser( "Min-Expires", NULL, (pjsip_parse_hdr_func*) &parse_hdr_min_expires); 
    270     pjsip_register_hdr_parser( "Record-Route", NULL, (pjsip_parse_hdr_func*) &parse_hdr_rr); 
    271     pjsip_register_hdr_parser( "Route", NULL, (pjsip_parse_hdr_func*) &parse_hdr_route); 
    272     pjsip_register_hdr_parser( "Require", NULL, (pjsip_parse_hdr_func*) &parse_hdr_require); 
    273     pjsip_register_hdr_parser( "Retry-After", NULL, (pjsip_parse_hdr_func*) &parse_hdr_retry_after); 
    274     pjsip_register_hdr_parser( "Supported", "k", (pjsip_parse_hdr_func*) &parse_hdr_supported); 
    275     pjsip_register_hdr_parser( "To", "t", (pjsip_parse_hdr_func*) &parse_hdr_to); 
    276     pjsip_register_hdr_parser( "Unsupported", NULL, (pjsip_parse_hdr_func*) &parse_hdr_unsupported); 
    277     pjsip_register_hdr_parser( "Via", NULL, (pjsip_parse_hdr_func*) &parse_hdr_via); 
     238    status = pj_cis_init(&cis_buf, &pjsip_ARRAY_ELEMENTS); 
     239    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     240    pj_cis_add_str( &pjsip_ARRAY_ELEMENTS, ",\r\n"); 
     241 
     242    status = pj_cis_dup(&pjsip_TOKEN_SPEC, &pjsip_ALNUM_SPEC); 
     243    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     244    pj_cis_add_str( &pjsip_TOKEN_SPEC, TOKEN); 
     245 
     246    status = pj_cis_dup(&pjsip_HOST_SPEC, &pjsip_ALNUM_SPEC); 
     247    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     248    pj_cis_add_str( &pjsip_HOST_SPEC, HOST); 
     249 
     250    status = pj_cis_dup(&pjsip_HEX_SPEC, &pjsip_DIGIT_SPEC); 
     251    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     252    pj_cis_add_str( &pjsip_HEX_SPEC, HEX_DIGIT); 
     253 
     254    status = pj_cis_dup(&pjsip_PARAM_CHAR_SPEC, &pjsip_ALNUM_SPEC); 
     255    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     256    pj_cis_add_str(&pjsip_PARAM_CHAR_SPEC, PARAM_CHAR); 
     257 
     258    status = pj_cis_dup(&pjsip_USER_SPEC, &pjsip_ALNUM_SPEC); 
     259    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     260    pj_cis_add_str( &pjsip_USER_SPEC, MARK ESCAPED USER ); 
     261 
     262    status = pj_cis_dup(&pjsip_PASSWD_SPEC, &pjsip_ALNUM_SPEC); 
     263    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     264    pj_cis_add_str( &pjsip_PASSWD_SPEC, MARK ESCAPED PASS); 
     265 
     266    status = pj_cis_init(&cis_buf, &pjsip_PROBE_USER_HOST_SPEC); 
     267    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     268    pj_cis_add_str( &pjsip_PROBE_USER_HOST_SPEC, "@ \n>"); 
     269    pj_cis_invert( &pjsip_PROBE_USER_HOST_SPEC ); 
     270 
     271    status = pj_cis_init(&cis_buf, &pjsip_DISPLAY_SCAN_SPEC); 
     272    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     273    pj_cis_add_str( &pjsip_DISPLAY_SCAN_SPEC, ":\r\n<"); 
     274 
     275    status = pjsip_register_hdr_parser( "Accept", NULL, &parse_hdr_accept); 
     276    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     277 
     278    status = pjsip_register_hdr_parser( "Allow", NULL, &parse_hdr_allow); 
     279    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     280 
     281    status = pjsip_register_hdr_parser( "Call-ID", NULL, &parse_hdr_call_id); 
     282    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     283 
     284    status = pjsip_register_hdr_parser( "Contact", "m", &parse_hdr_contact); 
     285    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     286 
     287    status = pjsip_register_hdr_parser( "Content-Length", NULL,  
     288                                        &parse_hdr_content_len); 
     289    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     290 
     291    status = pjsip_register_hdr_parser( "Content-Type", NULL,  
     292                                        &parse_hdr_content_type); 
     293    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     294 
     295    status = pjsip_register_hdr_parser( "CSeq", NULL, &parse_hdr_cseq); 
     296    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     297 
     298    status = pjsip_register_hdr_parser( "Expires", NULL, &parse_hdr_expires); 
     299    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     300 
     301    status = pjsip_register_hdr_parser( "From", "f", &parse_hdr_from); 
     302    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     303 
     304    status = pjsip_register_hdr_parser( "Max-Forwards", NULL,  
     305                                        &parse_hdr_max_forwards); 
     306    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     307 
     308    status = pjsip_register_hdr_parser( "Min-Expires", NULL,  
     309                                        &parse_hdr_min_expires); 
     310    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     311 
     312    status = pjsip_register_hdr_parser( "Record-Route", NULL, &parse_hdr_rr); 
     313    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     314 
     315    status = pjsip_register_hdr_parser( "Route", NULL, &parse_hdr_route); 
     316    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     317 
     318    status = pjsip_register_hdr_parser( "Require", NULL, &parse_hdr_require); 
     319    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     320 
     321    status = pjsip_register_hdr_parser( "Retry-After", NULL,  
     322                                        &parse_hdr_retry_after); 
     323    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     324 
     325    status = pjsip_register_hdr_parser( "Supported", "k",  
     326                                        &parse_hdr_supported); 
     327    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     328 
     329    status = pjsip_register_hdr_parser( "To", "t", &parse_hdr_to); 
     330    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     331 
     332    status = pjsip_register_hdr_parser( "Unsupported", NULL,  
     333                                        &parse_hdr_unsupported); 
     334    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     335 
     336    status = pjsip_register_hdr_parser( "Via", NULL, &parse_hdr_via); 
     337    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    278338 
    279339    /* Register auth parser. */ 
    280     pjsip_auth_init_parser(); 
    281  
    282 } 
    283  
    284 static void init_sip_parser() 
     340    status = pjsip_auth_init_parser(); 
     341 
     342    return status; 
     343} 
     344 
     345static void init_sip_parser(void) 
    285346{ 
    286347    if (!parser_is_initialized) { 
     
    318379 
    319380    /* Equal length and equal hash. compare the strings. */ 
    320     return strcmp(r1->hname, name); 
     381    return pj_native_strcmp(r1->hname, name); 
    321382} 
    322383 
    323384/* Register one handler for one header name. */ 
    324 static int int_register_parser( const char *name, pjsip_parse_hdr_func *fptr ) 
     385static pj_status_t int_register_parser( const char *name,  
     386                                        pjsip_parse_hdr_func *fptr ) 
    325387{ 
    326388    unsigned    pos; 
     
    329391 
    330392    if (handler_count >= PJ_ARRAY_SIZE(handler)) { 
    331         return -1; 
     393        return PJ_ETOOMANY; 
    332394    } 
    333395 
     
    336398    rec.hname_len = strlen(name); 
    337399    if (rec.hname_len >= sizeof(rec.hname)) { 
    338         return -1; 
     400        return PJ_ENAMETOOLONG; 
    339401    } 
    340402    /* Name is copied in lowercase. */ 
    341403    for (i=0; i<rec.hname_len; ++i) { 
    342         rec.hname[i] = (char)tolower(name[i]); 
     404        rec.hname[i] = (char)pj_tolower(name[i]); 
    343405    } 
    344406    rec.hname[i] = '\0'; 
     
    349411    for (pos=0; pos < handler_count; ++pos) { 
    350412        int d; 
    351         d = compare_handler(&handler[pos], rec.hname, rec.hname_len, rec.hname_hash); 
     413        d = compare_handler(&handler[pos], rec.hname, rec.hname_len,  
     414                            rec.hname_hash); 
    352415        if (d == 0) { 
    353416            pj_assert(0); 
    354             return -1; 
     417            return PJ_EEXISTS; 
    355418        } 
    356419        if (d > 0) { 
     
    361424    /* Shift handlers. */ 
    362425    if (pos != handler_count) { 
    363         pj_memmove( &handler[pos+1], &handler[pos], (handler_count-pos)*sizeof(handler_rec)); 
     426        pj_memmove( &handler[pos+1], &handler[pos],  
     427                    (handler_count-pos)*sizeof(handler_rec)); 
    364428    } 
    365429    /* Add new handler. */ 
     
    367431    ++handler_count; 
    368432 
    369     return 0; 
     433    return PJ_SUCCESS; 
    370434} 
    371435 
     
    377441                                               pjsip_parse_hdr_func *fptr) 
    378442{ 
    379     if (int_register_parser(hname, fptr)) { 
    380         return -1; 
    381     } 
    382     if (hshortname && int_register_parser(hshortname, fptr)) { 
    383         return -1; 
    384     } 
    385     return 0; 
     443    pj_status_t status; 
     444 
     445    status = int_register_parser(hname, fptr); 
     446    if (status != PJ_SUCCESS) { 
     447        return status; 
     448    } 
     449    if (hshortname) { 
     450        status = int_register_parser(hshortname, fptr); 
     451        if (status != PJ_SUCCESS)  
     452            return status; 
     453    } 
     454    return PJ_SUCCESS; 
    386455} 
    387456 
     
    393462    pj_uint32_t  hash; 
    394463    int          comp; 
    395     unsigned     i, n; 
     464    unsigned     n; 
     465 
     466    if (hname->slen >= PJSIP_MAX_HNAME_LEN) { 
     467        pj_assert(!"Header name is too long!"); 
     468        return NULL; 
     469    } 
    396470 
    397471    /* Calculate hash value while converting the header to lowercase.  
    398472     * Don't assume that 'hname' is NULL terminated. 
    399473     */ 
    400     hash = 0; 
    401     for (i=0; i<(unsigned)hname->slen; ++i) { 
    402         hname_copy[i] = (char)tolower(hname->ptr[i]); 
    403         hash = hash * PJ_HASH_MULTIPLIER + hname_copy[i]; 
    404     } 
    405     hname_copy[i] = '\0'; 
     474    hash = pj_hash_calc_tolower(0, hname_copy, hname); 
     475    hname_copy[hname->slen] = '\0'; 
    406476 
    407477    /* Binary search for the handler. */ 
     
    429499 
    430500/* Public function to parse SIP message. */ 
    431 PJ_DEF(pjsip_msg*) pjsip_parse_msg( pj_pool_t *pool, char *buf, pj_size_t size, 
     501PJ_DEF(pjsip_msg*) pjsip_parse_msg( pj_pool_t *pool,  
     502                                    char *buf, pj_size_t size, 
    432503                                    pjsip_parser_err_report *err_list) 
    433504{ 
    434505    pjsip_msg *msg = NULL; 
    435506    pj_scanner scanner; 
     507    pjsip_parse_ctx context; 
    436508    PJ_USE_EXCEPTION; 
    437509 
    438510    init_sip_parser(); 
    439511 
    440     pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER, &on_syntax_error); 
     512    pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER,  
     513                 &on_syntax_error); 
     514 
     515    context.scanner = &scanner; 
     516    context.pool = pool; 
     517    context.rdata = NULL; 
    441518 
    442519    PJ_TRY { 
    443         msg = int_parse_msg(&scanner, pool, err_list); 
     520        msg = int_parse_msg(&context, err_list); 
    444521    }  
    445522    PJ_DEFAULT { 
     
    450527    pj_scan_fini(&scanner); 
    451528    return msg; 
     529} 
     530 
     531/* Public function to parse as rdata.*/ 
     532PJ_DEF(pjsip_msg *) pjsip_parse_rdata( char *buf, pj_size_t size, 
     533                                       pjsip_rx_data *rdata ) 
     534{ 
     535    pj_scanner scanner; 
     536    pjsip_parse_ctx context; 
     537    PJ_USE_EXCEPTION; 
     538 
     539    init_sip_parser(); 
     540 
     541    pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER,  
     542                 &on_syntax_error); 
     543 
     544    context.scanner = &scanner; 
     545    context.pool = rdata->pool; 
     546    context.rdata = rdata; 
     547 
     548    PJ_TRY { 
     549        rdata->msg = int_parse_msg(&context, &rdata->parse_err); 
     550    }  
     551    PJ_DEFAULT { 
     552        rdata->msg = NULL; 
     553    } 
     554    PJ_END 
     555 
     556    pj_scan_fini(&scanner); 
     557    return rdata->msg; 
    452558} 
    453559 
     
    467573    /* For datagram, the whole datagram IS the message. */ 
    468574    if (is_datagram) { 
    469         return PJ_TRUE; 
     575        return PJ_SUCCESS; 
    470576    } 
    471577 
    472578 
    473579    /* Find the end of header area by finding an empty line. */ 
    474     if ((pos = strstr(buf, "\n\r\n")) == NULL) { 
    475         return PJ_FALSE; 
     580    if ((pos = pj_native_strstr(buf, "\n\r\n")) == NULL) { 
     581        return PJSIP_EPARTIALMSG; 
    476582    } 
    477583 
     
    480586 
    481587    /* Find "Content-Length" header the hard way. */ 
    482     line = strchr(buf, '\n'); 
     588    line = pj_native_strchr(buf, '\n'); 
    483589    while (line && line < hdr_end-14) { 
    484590        ++line; 
    485         if ( ((*line=='C' || *line=='c') && strncasecmp(line, "Content-Length", 14) == 0) || 
    486              ((*line=='l' || *line=='L') && (*(line+1)==' ' || *(line+1)=='\t' || *(line+1)==':'))) 
     591        if ( ((*line=='C' || *line=='c') &&  
     592              pj_native_strncasecmp(line, "Content-Length", 14) == 0) || 
     593             ((*line=='l' || *line=='L') &&  
     594              (*(line+1)==' ' || *(line+1)=='\t' || *(line+1)==':'))) 
    487595        { 
    488596            /* Try to parse the header. */ 
     
    510618 
    511619                /* Get number */ 
    512                 pj_scan_get(&scanner, pjsip_DIGIT_SPEC, &str_clen); 
     620                pj_scan_get(&scanner, &pjsip_DIGIT_SPEC, &str_clen); 
    513621 
    514622                /* Get newline. */ 
     
    528636 
    529637        /* Go to next line. */ 
    530         line = strchr(line, '\n'); 
     638        line = pj_native_strchr(line, '\n'); 
    531639    } 
    532640 
    533641    /* Found Content-Length? */ 
    534642    if (content_length == -1) { 
    535         PJ_LOG(4, ("sipparser", "pjsip_find_msg: incoming TCP packet has missing " 
    536                              "Content-Length header, treated as incomplete.")); 
    537         return PJ_FALSE; 
     643        return PJSIP_EMISSINGHDR; 
    538644    } 
    539645 
    540646    /* Enough packet received? */ 
    541647    *msg_size = (body_start - buf) + content_length; 
    542     return (*msg_size) <= size; 
     648    return (*msg_size) <= size ? PJ_SUCCESS : PJSIP_EPARTIALMSG; 
    543649#else 
    544     PJ_UNUSED_ARG(buf) 
    545     PJ_UNUSED_ARG(is_datagram) 
     650    PJ_UNUSED_ARG(buf); 
     651    PJ_UNUSED_ARG(is_datagram); 
    546652    *msg_size = size; 
    547     return 1; 
     653    return PJ_SUCCESS; 
    548654#endif 
    549655} 
     
    558664    pjsip_uri *uri = NULL; 
    559665 
    560     if (!parser_is_initialized) { 
    561         init_parser(); 
    562         parser_is_initialized = 1; 
    563     } 
     666    init_sip_parser(); 
    564667 
    565668    pj_scan_init(&scanner, buf, size, 0, &on_syntax_error); 
     
    572675 
    573676    /* Must have exhausted all inputs. */ 
    574     if (pj_scan_is_eof(&scanner) || *scanner.current=='\r' || *scanner.current=='\n') { 
     677    if (pj_scan_is_eof(&scanner) || *scanner.curptr=='\r' ||  
     678                       *scanner.curptr=='\n')  
     679    { 
    575680        /* Success. */ 
    576681        pj_scan_fini(&scanner); 
     
    587692 * actual body is laid. 
    588693 */ 
    589 static int generic_print_body (pjsip_msg_body *msg_body, char *buf, pj_size_t size) 
     694static int generic_print_body (pjsip_msg_body *msg_body,  
     695                               char *buf, pj_size_t size) 
    590696{ 
    591697    pjsip_msg_body *body = msg_body; 
     
    598704 
    599705/* Internal function to parse SIP message */ 
    600 static pjsip_msg *int_parse_msg( pj_scanner *scanner, pj_pool_t *pool,  
     706static pjsip_msg *int_parse_msg( pjsip_parse_ctx *ctx, 
    601707                                 pjsip_parser_err_report *err_list) 
    602708{ 
     
    605711    pjsip_msg *msg; 
    606712    pjsip_ctype_hdr *ctype_hdr = NULL; 
     713    pj_scanner *scanner = ctx->scanner; 
     714    pj_pool_t *pool = ctx->pool; 
    607715 
    608716    /* Skip leading newlines. */ 
    609     ch = *scanner->current; 
     717    ch = *scanner->curptr; 
    610718    while (ch=='\r' || ch=='\n') { 
    611719        pj_scan_get_char(scanner); 
    612         ch = *scanner->current; 
     720        ch = *scanner->curptr; 
    613721    } 
    614722 
     
    631739 
    632740        /* Get hname. */ 
    633         pj_scan_get( scanner, pjsip_TOKEN_SPEC, &hname); 
     741        pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &hname); 
    634742        ch = pj_scan_get_char( scanner ); 
    635743        if (ch != ':') { 
     
    646754             */ 
    647755            if (handler) { 
    648                 hdr = (*handler)(scanner, pool); 
     756                hdr = (*handler)(ctx); 
    649757            } else { 
    650                 pjsip_generic_string_hdr *ghdr = parse_hdr_generic_string(scanner, pool); 
    651                 ghdr->type = PJSIP_H_OTHER; 
    652                 ghdr->name = ghdr->sname = hname; 
    653                 hdr = (pjsip_hdr*)ghdr; 
     758                hdr = parse_hdr_generic_string(ctx); 
     759                hdr->type = PJSIP_H_OTHER; 
     760                hdr->name = hdr->sname = hname; 
    654761            } 
    655762 
     
    669776            hdr = NULL; 
    670777 
    671             PJ_LOG(4,("sipparser", "Syntax error in line %d col %d (hname=%.*s)", 
    672                       scanner->line, scanner->col, hname.slen, hname.ptr)); 
     778            //PJ_LOG(4,("sipparser",  
     779            //          "Syntax error in line %d col %d (hname=%.*s)", 
     780            //        scanner->line, scanner->col, hname.slen, hname.ptr)); 
    673781 
    674782            if (err_list) { 
     
    685793 
    686794            if (!pj_scan_is_eof(scanner)) { 
    687                 pj_scan_get_until(scanner, pjsip_NEWLINE_OR_EOF_SPEC, &token); 
     795                pj_scan_get_until(scanner, &pjsip_NEWLINE_OR_EOF_SPEC, &token); 
    688796                parse_hdr_end(scanner); 
    689797            } 
     
    703811        /* Parse until EOF or an empty line is found. */ 
    704812    } while (!pj_scan_is_eof(scanner) &&  
    705               *scanner->current != '\r' && *scanner->current != '\n'); 
     813              *scanner->curptr != '\r' && *scanner->curptr != '\n'); 
    706814 
    707815    /* If empty line is found, eat it. */ 
    708816    if (!pj_scan_is_eof(scanner)) { 
    709         if (*scanner->current=='\r' || *scanner->current=='\n') { 
     817        if (*scanner->curptr=='\r' || *scanner->curptr=='\n') { 
    710818            pj_scan_get_newline(scanner); 
    711819        } 
    712820    } 
    713821 
    714     /* If we have Content-Type header, treat the rest of the message as body. */ 
     822    /* If we have Content-Type header, treat the rest of the message as body.*/ 
    715823    if (ctype_hdr) { 
    716824        pjsip_msg_body *body = pj_pool_alloc(pool, sizeof(pjsip_msg_body)); 
    717         pj_strdup (pool, &body->content_type.type, &ctype_hdr->media.type); 
    718         pj_strdup (pool, &body->content_type.subtype, &ctype_hdr->media.subtype); 
    719         pj_strdup (pool, &body->content_type.param, &ctype_hdr->media.param); 
    720         body->data = scanner->current; 
    721         body->len = scanner->end - scanner->current; 
     825        pj_strdup(pool, &body->content_type.type, &ctype_hdr->media.type); 
     826        pj_strdup(pool, &body->content_type.subtype, &ctype_hdr->media.subtype); 
     827        pj_strdup(pool, &body->content_type.param, &ctype_hdr->media.param); 
     828        body->data = scanner->curptr; 
     829        body->len = scanner->end - scanner->curptr; 
    722830        body->print_body = &generic_print_body; 
    723831 
     
    734842{ 
    735843    /* pname */ 
    736     pj_scan_get(scanner, pjsip_PARAM_CHAR_SPEC, pname); 
     844    pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pname); 
    737845 
    738846    /* pvalue, if any */ 
    739     if (*scanner->current == '=') { 
     847    if (*scanner->curptr == '=') { 
    740848        pj_scan_get_char(scanner); 
    741849        /* pvalue can be a quoted string. */ 
    742         if (*scanner->current == '"') { 
     850        if (*scanner->curptr == '"') { 
    743851            pj_scan_get_quote( scanner, '"', '"', pvalue); 
    744852            if (option & PJSIP_PARSE_REMOVE_QUOTE) { 
     
    747855            } 
    748856        } else { 
    749             pj_scan_get(scanner, pjsip_PARAM_CHAR_SPEC, pvalue); 
     857            pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 
    750858        } 
    751859    } else { 
     
    770878                                     pj_str_t *host, int *p_port) 
    771879{ 
    772     pj_scan_get( scanner, pjsip_HOST_SPEC, host); 
    773     if (*scanner->current == ':') { 
     880    pj_scan_get( scanner, &pjsip_HOST_SPEC, host); 
     881    if (*scanner->curptr == ':') { 
    774882        pj_str_t port; 
    775883        pj_scan_get_char(scanner); 
    776         pj_scan_get(scanner, pjsip_DIGIT_SPEC, &port); 
     884        pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &port); 
    777885        *p_port = pj_strtoul(&port); 
    778886    } else { 
     
    790898     * must be a username. 
    791899     */ 
    792     if (pj_scan_peek( scanner, pjsip_PROBE_USER_HOST_SPEC, &dummy) == '@') 
     900    if (pj_scan_peek( scanner, &pjsip_PROBE_USER_HOST_SPEC, &dummy) == '@') 
    793901        is_user = 1; 
    794902    else 
     
    802910                                 pj_str_t *user, pj_str_t *pass) 
    803911{ 
    804     pj_scan_get( scanner, pjsip_USER_SPEC, user); 
    805     if ( *scanner->current == ':') { 
     912    pj_scan_get( scanner, &pjsip_USER_SPEC, user); 
     913    if ( *scanner->curptr == ':') { 
    806914        pj_scan_get_char( scanner ); 
    807         pj_scan_get( scanner, pjsip_PASSWD_SPEC, pass); 
     915        pj_scan_get( scanner, &pjsip_PASSWD_SPEC, pass); 
    808916    } else { 
    809917        pass->ptr = NULL; 
     
    816924 
    817925/* Parse all types of URI. */ 
    818 static pjsip_uri *int_parse_uri_or_name_addr(pj_scanner *scanner, pj_pool_t *pool, 
    819                                                   unsigned option) 
     926static pjsip_uri *int_parse_uri_or_name_addr( pj_scanner *scanner, pj_pool_t *pool, 
     927                                              unsigned opt) 
    820928{ 
    821929    pjsip_uri *uri; 
    822930    int is_name_addr = 0; 
    823931 
    824     if (*scanner->current=='"' || *scanner->current=='<') { 
     932    if (*scanner->curptr=='"' || *scanner->curptr=='<') { 
    825933        uri = (pjsip_uri*)int_parse_name_addr( scanner, pool ); 
    826934        is_name_addr = 1; 
     
    831939 
    832940        pj_scan_save_state( scanner, &backtrack); 
    833         pj_scan_get( scanner, pjsip_TOKEN_SPEC, &scheme); 
     941        pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &scheme); 
    834942        colon = pj_scan_get_char( scanner ); 
    835943        pj_scan_restore_state( scanner, &backtrack); 
    836944 
    837         if (colon==':' && (parser_stricmp(scheme, pjsip_SIP_STR)==0 || parser_stricmp(scheme, pjsip_SIPS_STR)==0))  
     945        if (colon==':' &&  
     946            (parser_stricmp(scheme, pjsip_SIP_STR)==0 ||  
     947             parser_stricmp(scheme, pjsip_SIPS_STR)==0))  
    838948        { 
    839             uri = (pjsip_uri*)int_parse_sip_url( scanner, pool,  
    840                                         (option & PJSIP_PARSE_URI_IN_FROM_TO_HDR) == 0 ); 
     949            uri = (pjsip_uri*) 
     950                int_parse_sip_url( scanner, pool,  
     951                                   (opt & PJSIP_PARSE_URI_IN_FROM_TO_HDR)== 0); 
    841952 
    842953        } else if (colon==':' && parser_stricmp( scheme, pjsip_TEL_STR)==0) { 
     
    853964 
    854965    /* Should we return the URI object as name address? */ 
    855     if (option & PJSIP_PARSE_URI_AS_NAMEADDR) { 
     966    if (opt & PJSIP_PARSE_URI_AS_NAMEADDR) { 
    856967        if (is_name_addr == 0) { 
    857968            pjsip_name_addr *name_addr; 
     
    871982                                pj_bool_t parse_params) 
    872983{ 
    873     if (*scanner->current=='"' || *scanner->current=='<') { 
     984    if (*scanner->curptr=='"' || *scanner->curptr=='<') { 
    874985        return (pjsip_uri*)int_parse_name_addr( scanner, pool ); 
    875986    } else { 
     
    878989 
    879990        /* Get scheme. */ 
    880         colon = pj_scan_peek(scanner, pjsip_TOKEN_SPEC, &scheme); 
     991        colon = pj_scan_peek(scanner, &pjsip_TOKEN_SPEC, &scheme); 
    881992        if (colon != ':') { 
    882993            PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 
    883994        } 
    884995 
    885         if ((parser_stricmp(scheme, pjsip_SIP_STR)==0 || parser_stricmp(scheme, pjsip_SIPS_STR)==0))  
     996        if ((parser_stricmp(scheme, pjsip_SIP_STR)==0 ||  
     997            parser_stricmp(scheme, pjsip_SIPS_STR)==0))  
    886998        { 
    887             return (pjsip_uri*)int_parse_sip_url( scanner, pool, parse_params ); 
     999            return (pjsip_uri*)int_parse_sip_url( scanner, pool, parse_params); 
    8881000 
    8891001        } else if (parser_stricmp(scheme, pjsip_TEL_STR)==0) { 
     
    9091021    scanner->skip_ws = 0; 
    9101022 
    911     pj_scan_get(scanner, pjsip_TOKEN_SPEC, &scheme); 
     1023    pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &scheme); 
    9121024    colon = pj_scan_get_char(scanner); 
    9131025    if (colon != ':') { 
     
    9381050 
    9391051    /* Get URL parameters. */ 
    940     while ( parse_params && *scanner->current == ';' ) { 
     1052    while ( parse_params && *scanner->curptr == ';' ) { 
    9411053        pj_str_t pname, pvalue; 
    9421054 
     
    9491061            url->method_param = pvalue; 
    9501062 
    951         } else if (!parser_stricmp(pname, pjsip_TRANSPORT_STR) && pvalue.slen) { 
     1063        } else if (!parser_stricmp(pname,pjsip_TRANSPORT_STR) && pvalue.slen) { 
    9521064            url->transport_param = pvalue; 
    9531065 
     
    9671079 
    9681080    /* Get header params. */ 
    969     if (parse_params && *scanner->current == '?') { 
    970         pj_scan_get_until(scanner, pjsip_NEWLINE_OR_EOF_SPEC, &url->header_param); 
     1081    if (parse_params && *scanner->curptr == '?') { 
     1082        pj_scan_get_until(scanner, &pjsip_NEWLINE_OR_EOF_SPEC,  
     1083                          &url->header_param); 
    9711084    } 
    9721085 
     
    9851098    name_addr = pjsip_name_addr_create(pool); 
    9861099 
    987     if (*scanner->current == '"') { 
     1100    if (*scanner->curptr == '"') { 
    9881101        pj_scan_get_quote( scanner, '"', '"', &name_addr->display); 
    9891102 
    990     } else if (*scanner->current != '<') { 
     1103    } else if (*scanner->curptr != '<') { 
    9911104        int next; 
    9921105        pj_str_t dummy; 
     
    9971110         * will be parser later. 
    9981111         */ 
    999         next = pj_scan_peek_until(scanner, pjsip_DISPLAY_SCAN_SPEC, &dummy); 
     1112        next = pj_scan_peek_until(scanner, &pjsip_DISPLAY_SCAN_SPEC, &dummy); 
    10001113        if (next == '<') { 
    10011114            /* Ok, this is what we're looking for, a display name. */ 
     
    10091122 
    10101123    /* Get the SIP-URL */ 
    1011     has_bracket = (*scanner->current == '<'); 
     1124    has_bracket = (*scanner->curptr == '<'); 
    10121125    if (has_bracket) 
    10131126        pj_scan_get_char(scanner); 
     
    10261139    pj_str_t token; 
    10271140 
    1028     pj_scan_get( scanner, pjsip_TOKEN_SPEC, &token); 
     1141    pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &token); 
    10291142    pjsip_method_init_np( &req_line->method, &token); 
    10301143 
     
    10461159    pj_scan_advance_n( scanner, 7, 1); 
    10471160 
    1048     pj_scan_get( scanner, pjsip_DIGIT_SPEC, &token); 
     1161    pj_scan_get( scanner, &pjsip_DIGIT_SPEC, &token); 
    10491162    status_line->code = pj_strtoul(&token); 
    1050     pj_scan_get_until( scanner, pjsip_NEWLINE_OR_EOF_SPEC, &status_line->reason); 
     1163    pj_scan_get_until( scanner, &pjsip_NEWLINE_OR_EOF_SPEC,  
     1164                       &status_line->reason); 
    10511165    pj_scan_get_newline( scanner ); 
    10521166} 
     
    10571171    if (pj_scan_is_eof(scanner)) { 
    10581172        ;   /* Do nothing. */ 
    1059     } else if (*scanner->current == '&') { 
     1173    } else if (*scanner->curptr == '&') { 
    10601174        pj_scan_get_char(scanner); 
    10611175    } else { 
     
    10741188                                     pj_scanner *scanner) 
    10751189{ 
    1076     pj_scan_get_until( scanner, pjsip_ARRAY_ELEMENTS, &hdr->values[0]); 
     1190    pj_scan_get_until( scanner, &pjsip_ARRAY_ELEMENTS, &hdr->values[0]); 
    10771191    hdr->count++; 
    10781192 
    1079     while (*scanner->current == ',') { 
     1193    while (*scanner->curptr == ',') { 
    10801194        pj_scan_get_char(scanner); 
    1081         pj_scan_get_until( scanner, pjsip_ARRAY_ELEMENTS, &hdr->values[hdr->count]); 
     1195        pj_scan_get_until( scanner, &pjsip_ARRAY_ELEMENTS,  
     1196                           &hdr->values[hdr->count]); 
    10821197        hdr->count++; 
    10831198    } 
     
    10891204                                      pj_scanner *scanner ) 
    10901205{ 
    1091     pj_scan_get_until( scanner, pjsip_NEWLINE_OR_EOF_SPEC, &hdr->hvalue); 
     1206    pj_scan_get_until( scanner, &pjsip_NEWLINE_OR_EOF_SPEC, &hdr->hvalue); 
    10921207    parse_hdr_end(scanner); 
    10931208} 
     
    10981213{ 
    10991214    pj_str_t tmp; 
    1100     pj_scan_get_until( scanner, pjsip_NEWLINE_OR_EOF_SPEC, &tmp); 
     1215    pj_scan_get_until( scanner, &pjsip_NEWLINE_OR_EOF_SPEC, &tmp); 
    11011216    hdr->ivalue = pj_strtoul(&tmp); 
    11021217    parse_hdr_end(scanner); 
     
    11051220 
    11061221/* Parse Accept header. */ 
    1107 static pjsip_accept_hdr* parse_hdr_accept( pj_scanner *scanner,  
    1108                                             pj_pool_t *pool) 
    1109 { 
    1110     pjsip_accept_hdr *accept = pjsip_accept_hdr_create(pool); 
    1111     parse_generic_array_hdr(accept, scanner); 
    1112     return accept; 
     1222static pjsip_hdr* parse_hdr_accept(pjsip_parse_ctx *ctx) 
     1223{ 
     1224    pjsip_accept_hdr *accept = pjsip_accept_hdr_create(ctx->pool); 
     1225    parse_generic_array_hdr(accept, ctx->scanner); 
     1226    return (pjsip_hdr*)accept; 
    11131227} 
    11141228 
    11151229/* Parse Allow header. */ 
    1116 static pjsip_allow_hdr*   parse_hdr_allow( pj_scanner *scanner,  
    1117                                            pj_pool_t *pool) 
    1118 { 
    1119     pjsip_allow_hdr *allow = pjsip_allow_hdr_create(pool); 
    1120     parse_generic_array_hdr(allow, scanner); 
    1121     return allow; 
     1230static pjsip_hdr* parse_hdr_allow(pjsip_parse_ctx *ctx) 
     1231{ 
     1232    pjsip_allow_hdr *allow = pjsip_allow_hdr_create(ctx->pool); 
     1233    parse_generic_array_hdr(allow, ctx->scanner); 
     1234    return (pjsip_hdr*)allow; 
    11221235} 
    11231236 
    11241237/* Parse Call-ID header. */ 
    1125 static pjsip_cid_hdr* parse_hdr_call_id( pj_scanner *scanner,  
    1126                                           pj_pool_t *pool) 
    1127 { 
    1128     pjsip_cid_hdr *hdr = pjsip_cid_hdr_create(pool); 
    1129     pj_scan_get_until( scanner, pjsip_NEWLINE_OR_EOF_SPEC, &hdr->id); 
    1130     parse_hdr_end(scanner); 
    1131     return hdr; 
     1238static pjsip_hdr* parse_hdr_call_id(pjsip_parse_ctx *ctx) 
     1239{ 
     1240    pjsip_cid_hdr *hdr = pjsip_cid_hdr_create(ctx->pool); 
     1241    pj_scan_get_until( ctx->scanner, &pjsip_NEWLINE_OR_EOF_SPEC, &hdr->id); 
     1242    parse_hdr_end(ctx->scanner); 
     1243 
     1244    if (ctx->rdata) 
     1245        ctx->rdata->call_id = hdr->id; 
     1246 
     1247    return (pjsip_hdr*)hdr; 
    11321248} 
    11331249 
     
    11371253                                     pj_pool_t *pool) 
    11381254{ 
    1139     while ( *scanner->current == ';' ) { 
     1255    while ( *scanner->curptr == ';' ) { 
    11401256        pj_str_t pname, pvalue; 
    11411257 
     
    11601276 
    11611277/* Parse Contact header. */ 
    1162 PJ_DEF(pjsip_contact_hdr*) parse_hdr_contact( pj_scanner *scanner,  
    1163                                               pj_pool_t *pool) 
     1278static pjsip_hdr* parse_hdr_contact( pjsip_parse_ctx *ctx ) 
    11641279{ 
    11651280    pjsip_contact_hdr *first = NULL; 
     1281    pj_scanner *scanner = ctx->scanner; 
    11661282     
    11671283    do { 
    1168         pjsip_contact_hdr *hdr = pjsip_contact_hdr_create(pool); 
     1284        pjsip_contact_hdr *hdr = pjsip_contact_hdr_create(ctx->pool); 
    11691285        if (first == NULL) 
    11701286            first = hdr; 
     
    11721288            pj_list_insert_before(first, hdr); 
    11731289 
    1174         if (*scanner->current == '*') { 
     1290        if (*scanner->curptr == '*') { 
    11751291            pj_scan_get_char(scanner); 
    11761292            hdr->star = 1; 
     
    11781294        } else { 
    11791295            hdr->star = 0; 
    1180             hdr->uri = int_parse_uri_or_name_addr(scanner, pool, PJSIP_PARSE_URI_AS_NAMEADDR); 
    1181  
    1182             int_parse_contact_param(hdr, scanner, pool); 
    1183         } 
    1184  
    1185         if (*scanner->current != ',') 
     1296            hdr->uri = int_parse_uri_or_name_addr(scanner, ctx->pool,  
     1297                                                  PJSIP_PARSE_URI_AS_NAMEADDR); 
     1298 
     1299            int_parse_contact_param(hdr, scanner, ctx->pool); 
     1300        } 
     1301 
     1302        if (*scanner->curptr != ',') 
    11861303            break; 
    11871304 
     
    11911308 
    11921309    parse_hdr_end(scanner); 
    1193     return first; 
     1310 
     1311    return (pjsip_hdr*)first; 
    11941312} 
    11951313 
    11961314/* Parse Content-Length header. */ 
    1197 PJ_DEF(pjsip_clen_hdr*) parse_hdr_content_length( pj_scanner *scanner,  
    1198                                                   pj_pool_t *pool) 
     1315static pjsip_hdr* parse_hdr_content_len( pjsip_parse_ctx *ctx ) 
    11991316{ 
    12001317    pj_str_t digit; 
    12011318    pjsip_clen_hdr *hdr; 
    12021319 
    1203     hdr = pjsip_clen_hdr_create(pool); 
    1204     pj_scan_get(scanner, pjsip_DIGIT_SPEC, &digit); 
     1320    hdr = pjsip_clen_hdr_create(ctx->pool); 
     1321    pj_scan_get(ctx->scanner, &pjsip_DIGIT_SPEC, &digit); 
    12051322    hdr->len = pj_strtoul(&digit); 
    1206     parse_hdr_end(scanner); 
    1207     return hdr; 
     1323    parse_hdr_end(ctx->scanner); 
     1324 
     1325    if (ctx->rdata) 
     1326        ctx->rdata->clen = hdr; 
     1327 
     1328    return (pjsip_hdr*)hdr; 
    12081329} 
    12091330 
    12101331/* Parse Content-Type header. */ 
    1211 PJ_DEF(pjsip_ctype_hdr*) parse_hdr_content_type( pj_scanner *scanner,  
    1212                                                  pj_pool_t *pool) 
     1332static pjsip_hdr* parse_hdr_content_type( pjsip_parse_ctx *ctx ) 
    12131333{ 
    12141334    pjsip_ctype_hdr *hdr; 
    1215  
    1216     hdr = pjsip_ctype_hdr_create(pool); 
     1335    pj_scanner *scanner = ctx->scanner; 
     1336 
     1337    hdr = pjsip_ctype_hdr_create(ctx->pool); 
    12171338     
    12181339    /* Parse media type and subtype. */ 
    1219     pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->media.type); 
     1340    pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->media.type); 
    12201341    pj_scan_get_char(scanner); 
    1221     pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->media.subtype); 
     1342    pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->media.subtype); 
    12221343 
    12231344    /* Parse media parameters */ 
    1224     while (*scanner->current == ';') { 
     1345    while (*scanner->curptr == ';') { 
    12251346        pj_str_t pname, pvalue; 
    12261347        int_parse_param(scanner, &pname, &pvalue); 
    1227         concat_param(&hdr->media.param, pool, &pname, &pvalue); 
    1228     } 
    1229  
    1230     parse_hdr_end(scanner); 
    1231     return hdr; 
     1348        concat_param(&hdr->media.param, ctx->pool, &pname, &pvalue); 
     1349    } 
     1350 
     1351    parse_hdr_end(ctx->scanner); 
     1352 
     1353    if (ctx->rdata) 
     1354        ctx->rdata->ctype = hdr; 
     1355 
     1356    return (pjsip_hdr*)hdr; 
    12321357} 
    12331358 
    12341359/* Parse CSeq header. */ 
    1235 PJ_DEF(pjsip_cseq_hdr*) parse_hdr_cseq( pj_scanner *scanner,  
    1236                                         pj_pool_t *pool) 
     1360static pjsip_hdr* parse_hdr_cseq( pjsip_parse_ctx *ctx ) 
    12371361{ 
    12381362    pj_str_t cseq, method; 
    12391363    pjsip_cseq_hdr *hdr; 
    12401364 
    1241     hdr = pjsip_cseq_hdr_create(pool); 
    1242     pj_scan_get( scanner, pjsip_DIGIT_SPEC, &cseq); 
     1365    hdr = pjsip_cseq_hdr_create(ctx->pool); 
     1366    pj_scan_get( ctx->scanner, &pjsip_DIGIT_SPEC, &cseq); 
    12431367    hdr->cseq = pj_strtoul(&cseq); 
    12441368 
    1245     pj_scan_get( scanner, pjsip_TOKEN_SPEC, &method); 
     1369    pj_scan_get( ctx->scanner, &pjsip_TOKEN_SPEC, &method); 
    12461370    pjsip_method_init_np(&hdr->method, &method); 
    12471371 
    1248     parse_hdr_end( scanner ); 
    1249     return hdr; 
     1372    parse_hdr_end( ctx->scanner ); 
     1373 
     1374    if (ctx->rdata) 
     1375        ctx->rdata->cseq = hdr; 
     1376 
     1377    return (pjsip_hdr*)hdr; 
    12501378} 
    12511379 
    12521380/* Parse Expires header. */ 
    1253 static pjsip_expires_hdr* parse_hdr_expires(pj_scanner *scanner,  
    1254                                             pj_pool_t *pool) 
    1255 { 
    1256     pjsip_expires_hdr *hdr = pjsip_expires_hdr_create(pool); 
    1257     parse_generic_int_hdr(hdr, scanner); 
    1258     return hdr; 
     1381static pjsip_hdr* parse_hdr_expires(pjsip_parse_ctx *ctx) 
     1382{ 
     1383    pjsip_expires_hdr *hdr = pjsip_expires_hdr_create(ctx->pool); 
     1384    parse_generic_int_hdr(hdr, ctx->scanner); 
     1385    return (pjsip_hdr*)hdr; 
    12591386} 
    12601387 
     
    12681395                                          PJSIP_PARSE_URI_IN_FROM_TO_HDR); 
    12691396 
    1270     while ( *scanner->current == ';' ) { 
     1397    while ( *scanner->curptr == ';' ) { 
    12711398        pj_str_t pname, pvalue; 
    12721399 
     
    12851412 
    12861413/* Parse From: header. */ 
    1287 PJ_DEF(pjsip_from_hdr*) parse_hdr_from( pj_scanner *scanner,  
    1288                                         pj_pool_t *pool) 
    1289 { 
    1290     pjsip_from_hdr *hdr = pjsip_from_hdr_create(pool); 
    1291     parse_hdr_fromto(scanner, pool, hdr); 
    1292     return hdr; 
     1414static pjsip_hdr* parse_hdr_from( pjsip_parse_ctx *ctx ) 
     1415{ 
     1416    pjsip_from_hdr *hdr = pjsip_from_hdr_create(ctx->pool); 
     1417    parse_hdr_fromto(ctx->scanner, ctx->pool, hdr); 
     1418    if (ctx->rdata) 
     1419        ctx->rdata->from = hdr; 
     1420 
     1421    return (pjsip_hdr*)hdr; 
    12931422} 
    12941423 
    12951424/* Parse Require: header. */ 
    1296 static pjsip_require_hdr* parse_hdr_require( pj_scanner *scanner,  
    1297                                              pj_pool_t *pool) 
    1298 { 
    1299     pjsip_require_hdr *hdr = pjsip_require_hdr_create(pool); 
    1300     parse_generic_array_hdr(hdr, scanner); 
    1301     return hdr; 
     1425static pjsip_hdr* parse_hdr_require( pjsip_parse_ctx *ctx ) 
     1426{ 
     1427    pjsip_require_hdr *hdr = pjsip_require_hdr_create(ctx->pool); 
     1428    parse_generic_array_hdr(hdr, ctx->scanner); 
     1429 
     1430    if (ctx->rdata && ctx->rdata->require == NULL) 
     1431        ctx->rdata->require = hdr; 
     1432 
     1433    return (pjsip_hdr*)hdr; 
    13021434} 
    13031435 
    13041436/* Parse Retry-After: header. */ 
    1305 static pjsip_retry_after_hdr* parse_hdr_retry_after(pj_scanner *scanner,  
    1306                                                     pj_pool_t *pool) 
     1437static pjsip_hdr* parse_hdr_retry_after(pjsip_parse_ctx *ctx) 
    13071438{ 
    13081439    pjsip_retry_after_hdr *hdr; 
    1309     hdr = pjsip_retry_after_hdr_create(pool); 
    1310     parse_generic_int_hdr(hdr, scanner); 
    1311     return hdr; 
     1440    hdr = pjsip_retry_after_hdr_create(ctx->pool); 
     1441    parse_generic_int_hdr(hdr, ctx->scanner); 
     1442    return (pjsip_hdr*)hdr; 
    13121443} 
    13131444 
    13141445/* Parse Supported: header. */ 
    1315 static pjsip_supported_hdr* parse_hdr_supported(pj_scanner *scanner,  
    1316                                                 pj_pool_t *pool) 
    1317 { 
    1318     pjsip_supported_hdr *hdr = pjsip_supported_hdr_create(pool); 
    1319     parse_generic_array_hdr(hdr, scanner); 
    1320     return hdr; 
     1446static pjsip_hdr* parse_hdr_supported(pjsip_parse_ctx *ctx) 
     1447{ 
     1448    pjsip_supported_hdr *hdr = pjsip_supported_hdr_create(ctx->pool); 
     1449    parse_generic_array_hdr(hdr, ctx->scanner); 
     1450    return (pjsip_hdr*)hdr; 
    13211451} 
    13221452 
    13231453 
    13241454/* Parse To: header. */ 
    1325 PJ_DEF(pjsip_to_hdr*) parse_hdr_to( pj_scanner *scanner,  
    1326                                     pj_pool_t *pool) 
    1327 { 
    1328     pjsip_to_hdr *hdr = pjsip_to_hdr_create(pool); 
    1329     parse_hdr_fromto(scanner, pool, hdr); 
    1330     return hdr; 
     1455static pjsip_hdr* parse_hdr_to( pjsip_parse_ctx *ctx ) 
     1456{ 
     1457    pjsip_to_hdr *hdr = pjsip_to_hdr_create(ctx->pool); 
     1458    parse_hdr_fromto(ctx->scanner, ctx->pool, hdr); 
     1459 
     1460    if (ctx->rdata) 
     1461        ctx->rdata->to = hdr; 
     1462 
     1463    return (pjsip_hdr*)hdr; 
    13311464} 
    13321465 
    13331466/* Parse Unsupported: header. */ 
    1334 static pjsip_unsupported_hdr* parse_hdr_unsupported(pj_scanner *scanner,  
    1335                                                     pj_pool_t *pool) 
    1336 { 
    1337     pjsip_unsupported_hdr *hdr = pjsip_unsupported_hdr_create(pool); 
    1338     parse_generic_array_hdr(hdr, scanner); 
    1339     return hdr; 
     1467static pjsip_hdr* parse_hdr_unsupported(pjsip_parse_ctx *ctx) 
     1468{ 
     1469    pjsip_unsupported_hdr *hdr = pjsip_unsupported_hdr_create(ctx->pool); 
     1470    parse_generic_array_hdr(hdr, ctx->scanner); 
     1471    return (pjsip_hdr*)hdr; 
    13401472} 
    13411473 
     
    13441476                                 pj_pool_t *pool) 
    13451477{ 
    1346     while ( *scanner->current == ';' ) { 
     1478    while ( *scanner->curptr == ';' ) { 
    13471479        pj_str_t pname, pvalue; 
    13481480 
     
    13741506 
    13751507/* Parse Max-Forwards header. */ 
    1376 static pjsip_max_forwards_hdr* parse_hdr_max_forwards( pj_scanner *scanner,  
    1377                                                        pj_pool_t *pool) 
     1508static pjsip_hdr* parse_hdr_max_forwards( pjsip_parse_ctx *ctx ) 
    13781509{ 
    13791510    pjsip_max_forwards_hdr *hdr; 
    1380     hdr = pjsip_max_forwards_hdr_create(pool); 
    1381     parse_generic_int_hdr(hdr, scanner); 
    1382     return hdr; 
     1511    hdr = pjsip_max_forwards_hdr_create(ctx->pool); 
     1512    parse_generic_int_hdr(hdr, ctx->scanner); 
     1513 
     1514    if (ctx->rdata) 
     1515        ctx->rdata->max_fwd = hdr; 
     1516 
     1517    return (pjsip_hdr*)hdr; 
    13831518} 
    13841519 
    13851520/* Parse Min-Expires header. */ 
    1386 static pjsip_min_expires_hdr*  parse_hdr_min_expires(pj_scanner *scanner,  
    1387                                                      pj_pool_t *pool) 
     1521static pjsip_hdr* parse_hdr_min_expires(pjsip_parse_ctx *ctx) 
    13881522{ 
    13891523    pjsip_min_expires_hdr *hdr; 
    1390     hdr = pjsip_min_expires_hdr_create(pool); 
    1391     parse_generic_int_hdr(hdr, scanner); 
    1392     return hdr; 
     1524    hdr = pjsip_min_expires_hdr_create(ctx->pool); 
     1525    parse_generic_int_hdr(hdr, ctx->scanner); 
     1526    return (pjsip_hdr*)hdr; 
    13931527} 
    13941528 
     
    14011535 
    14021536    pj_memcpy(&hdr->name_addr, temp, sizeof(*temp)); 
    1403     if (*scanner->current == ';') { 
    1404         pj_scan_get_until(scanner, pjsip_NEWLINE_OR_EOF_SPEC, &hdr->other_param); 
     1537    if (*scanner->curptr == ';') { 
     1538        pj_scan_get_until(scanner, &pjsip_NEWLINE_OR_EOF_SPEC,  
     1539                          &hdr->other_param); 
    14051540    } 
    14061541} 
    14071542 
    14081543/* Parse Record-Route header. */ 
    1409 PJ_DEF(pjsip_rr_hdr*) parse_hdr_rr( pj_scanner *scanner, pj_pool_t *pool) 
     1544static pjsip_hdr* parse_hdr_rr( pjsip_parse_ctx *ctx) 
    14101545{ 
    14111546    pjsip_rr_hdr *first = NULL; 
     1547    pj_scanner *scanner = ctx->scanner; 
    14121548 
    14131549    do { 
    1414         pjsip_rr_hdr *hdr = pjsip_rr_hdr_create(pool); 
     1550        pjsip_rr_hdr *hdr = pjsip_rr_hdr_create(ctx->pool); 
    14151551        if (!first) { 
    14161552            first = hdr; 
     
    14181554            pj_list_insert_before(first, hdr); 
    14191555        } 
    1420         parse_hdr_rr_route(scanner, pool, hdr); 
    1421         if (*scanner->current == ',') { 
     1556        parse_hdr_rr_route(scanner, ctx->pool, hdr); 
     1557        if (*scanner->curptr == ',') { 
    14221558            pj_scan_get_char(scanner); 
    14231559        } else { 
     
    14261562    } while (1); 
    14271563    parse_hdr_end(scanner); 
    1428     return first; 
     1564 
     1565    if (ctx->rdata && ctx->rdata->record_route==NULL) 
     1566        ctx->rdata->record_route = first; 
     1567 
     1568    return (pjsip_hdr*)first; 
    14291569} 
    14301570 
    14311571/* Parse Route: header. */ 
    1432 PJ_DEF(pjsip_route_hdr*) parse_hdr_route( pj_scanner *scanner,  
    1433                                           pj_pool_t *pool) 
     1572static pjsip_hdr* parse_hdr_route( pjsip_parse_ctx *ctx ) 
    14341573{ 
    14351574    pjsip_route_hdr *first = NULL; 
     1575    pj_scanner *scanner = ctx->scanner; 
    14361576 
    14371577    do { 
    1438         pjsip_route_hdr *hdr = pjsip_route_hdr_create(pool); 
     1578        pjsip_route_hdr *hdr = pjsip_route_hdr_create(ctx->pool); 
    14391579        if (!first) { 
    14401580            first = hdr; 
     
    14421582            pj_list_insert_before(first, hdr); 
    14431583        } 
    1444         parse_hdr_rr_route(scanner, pool, hdr); 
    1445         if (*scanner->current == ',') { 
     1584        parse_hdr_rr_route(scanner, ctx->pool, hdr); 
     1585        if (*scanner->curptr == ',') { 
    14461586            pj_scan_get_char(scanner); 
    14471587        } else { 
     
    14501590    } while (1); 
    14511591    parse_hdr_end(scanner); 
    1452     return first; 
     1592 
     1593    if (ctx->rdata && ctx->rdata->route==NULL) 
     1594        ctx->rdata->route = first; 
     1595 
     1596    return (pjsip_hdr*)first; 
    14531597} 
    14541598 
    14551599/* Parse Via: header. */ 
    1456 PJ_DEF(pjsip_via_hdr*) parse_hdr_via( pj_scanner *scanner, pj_pool_t *pool) 
     1600static pjsip_hdr* parse_hdr_via( pjsip_parse_ctx *ctx ) 
    14571601{ 
    14581602    pjsip_via_hdr *first = NULL; 
     1603    pj_scanner *scanner = ctx->scanner; 
    14591604 
    14601605    do { 
    1461         pjsip_via_hdr *hdr = pjsip_via_hdr_create(pool); 
     1606        pjsip_via_hdr *hdr = pjsip_via_hdr_create(ctx->pool); 
    14621607        if (!first) 
    14631608            first = hdr; 
     
    14701615        pj_scan_advance_n( scanner, 8, 1); 
    14711616 
    1472         pj_scan_get( scanner, pjsip_TOKEN_SPEC, &hdr->transport); 
    1473         pj_scan_get( scanner, pjsip_HOST_SPEC, &hdr->sent_by.host); 
    1474  
    1475         if (*scanner->current==':') { 
     1617        pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &hdr->transport); 
     1618        pj_scan_get( scanner, &pjsip_HOST_SPEC, &hdr->sent_by.host); 
     1619 
     1620        if (*scanner->curptr==':') { 
    14761621            pj_str_t digit; 
    14771622            pj_scan_get_char(scanner); 
    1478             pj_scan_get(scanner, pjsip_DIGIT_SPEC, &digit); 
     1623            pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &digit); 
    14791624            hdr->sent_by.port = pj_strtoul(&digit); 
    14801625        } else { 
     
    14821627        } 
    14831628         
    1484         int_parse_via_param(hdr, scanner, pool); 
    1485  
    1486         if (*scanner->current == '(') { 
     1629        int_parse_via_param(hdr, scanner, ctx->pool); 
     1630 
     1631        if (*scanner->curptr == '(') { 
    14871632            pj_scan_get_char(scanner); 
    14881633            pj_scan_get_until_ch( scanner, ')', &hdr->comment); 
     
    14901635        } 
    14911636 
    1492         if (*scanner->current != ',') 
     1637        if (*scanner->curptr != ',') 
    14931638            break; 
    14941639 
     
    14981643 
    14991644    parse_hdr_end(scanner); 
    1500     return first; 
     1645 
     1646    if (ctx->rdata && ctx->rdata->via == NULL) 
     1647        ctx->rdata->via = first; 
     1648 
     1649    return (pjsip_hdr*)first; 
    15011650} 
    15021651 
    15031652/* Parse generic header. */ 
    1504 PJ_DEF(pjsip_generic_string_hdr*) parse_hdr_generic_string( pj_scanner *scanner,  
    1505                                                 pj_pool_t *pool) 
     1653static pjsip_hdr* parse_hdr_generic_string( pjsip_parse_ctx *ctx ) 
    15061654{ 
    15071655    pjsip_generic_string_hdr *hdr; 
    15081656 
    1509     hdr = pjsip_generic_string_hdr_create(pool, NULL); 
    1510     parse_generic_string_hdr(hdr, scanner); 
    1511     return hdr; 
     1657    hdr = pjsip_generic_string_hdr_create(ctx->pool, NULL); 
     1658    parse_generic_string_hdr(hdr, ctx->scanner); 
     1659    return (pjsip_hdr*)hdr; 
    15121660 
    15131661} 
     
    15191667    pj_scanner scanner; 
    15201668    pjsip_hdr *hdr = NULL; 
     1669    pjsip_parse_ctx context; 
    15211670    PJ_USE_EXCEPTION; 
    15221671 
    15231672    init_sip_parser(); 
    15241673 
    1525     pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER, &on_syntax_error); 
     1674    pj_scan_init(&scanner, buf, size, PJ_SCAN_AUTOSKIP_WS_HEADER,  
     1675                 &on_syntax_error); 
     1676 
     1677    context.scanner = &scanner; 
     1678    context.pool = pool; 
     1679    context.rdata = NULL; 
    15261680 
    15271681    PJ_TRY { 
    15281682        pjsip_parse_hdr_func *handler = find_handler(hname); 
    15291683        if (handler) { 
    1530             hdr = (*handler)(&scanner, pool); 
     1684            hdr = (*handler)(&context); 
    15311685        } else { 
    1532             pjsip_generic_string_hdr *ghdr = parse_hdr_generic_string(&scanner, pool); 
    1533             ghdr->type = PJSIP_H_OTHER; 
    1534             pj_strdup(pool, &ghdr->name, hname); 
    1535             ghdr->sname = ghdr->name; 
    1536             hdr = (pjsip_hdr*)ghdr; 
     1686            hdr = parse_hdr_generic_string(&context); 
     1687            hdr->type = PJSIP_H_OTHER; 
     1688            pj_strdup(pool, &hdr->name, hname); 
     1689            hdr->sname = hdr->name; 
    15371690        } 
    15381691 
     
    15441697 
    15451698    if (parsed_len) { 
    1546         *parsed_len = (scanner.current - scanner.begin); 
     1699        *parsed_len = (scanner.curptr - scanner.begin); 
    15471700    } 
    15481701 
  • pjproject/main/pjsip/src/pjsip/sip_resolve.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43 
     
    65#include <pjsip/sip_transport.h> 
    76#include <pj/pool.h> 
    8 #include <ctype.h> 
     7#include <pj/ctype.h> 
     8#include <pj/assert.h> 
    99 
    1010struct pjsip_resolver_t 
     
    2222PJ_DEF(void) pjsip_resolver_destroy(pjsip_resolver_t *resolver) 
    2323{ 
    24     PJ_UNUSED_ARG(resolver) 
     24    PJ_UNUSED_ARG(resolver); 
    2525} 
    2626 
     
    3131 
    3232    while (p != end) { 
    33         if (isdigit(*p) || *p=='.') { 
     33        if (pj_isdigit(*p) || *p=='.') { 
    3434            ++p; 
    3535        } else { 
     
    5151    pjsip_transport_type_e type = target->type; 
    5252 
    53     PJ_UNUSED_ARG(resolver) 
    54     PJ_UNUSED_ARG(pool) 
     53    PJ_UNUSED_ARG(resolver); 
     54    PJ_UNUSED_ARG(pool); 
    5555 
    5656    /* We only do synchronous resolving at this moment. */ 
     
    9595    /* Resolve hostname. */ 
    9696    if (!is_ip_addr) { 
    97         status = pj_sockaddr_init(&svr_addr.entry[0].addr, &target->host, target->port); 
     97        status = pj_sockaddr_in_init(&svr_addr.entry[0].addr, &target->host,  
     98                                     (pj_uint16_t)target->port); 
    9899    } else { 
    99         status = pj_sockaddr_init(&svr_addr.entry[0].addr, &target->host, target->port); 
     100        status = pj_sockaddr_in_init(&svr_addr.entry[0].addr, &target->host,  
     101                                     (pj_uint16_t)target->port); 
    100102        pj_assert(status == PJ_SUCCESS); 
    101103    } 
  • pjproject/main/pjsip/src/pjsip/sip_transaction.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_transaction.h> 
     
    87#include <pjsip/sip_event.h> 
    98#include <pjsip/sip_endpoint.h> 
     9#include <pjsip/sip_errno.h> 
    1010#include <pj/log.h> 
    1111#include <pj/string.h> 
     
    1313#include <pj/guid.h> 
    1414#include <pj/pool.h> 
     15#include <pj/assert.h> 
    1516 
    1617/* Thread Local Storage ID for transaction lock (initialized by endpoint) */ 
    17 int pjsip_tsx_lock_tls_id; 
     18long pjsip_tsx_lock_tls_id; 
    1819 
    1920/* State names */ 
     
    4445} tsx_lock_data; 
    4546 
     47 
    4648/* Timer timeout value constants */ 
    47 static const pj_time_val t1_timer_val = { PJSIP_T1_TIMEOUT/1000, PJSIP_T1_TIMEOUT%1000 }; 
    48 static const pj_time_val t4_timer_val = { PJSIP_T4_TIMEOUT/1000, PJSIP_T4_TIMEOUT%1000 }; 
    49 static const pj_time_val td_timer_val = { PJSIP_TD_TIMEOUT/1000, PJSIP_TD_TIMEOUT%1000 }; 
     49static const pj_time_val t1_timer_val = { PJSIP_T1_TIMEOUT/1000,  
     50                                          PJSIP_T1_TIMEOUT%1000 }; 
     51static const pj_time_val t4_timer_val = { PJSIP_T4_TIMEOUT/1000,  
     52                                          PJSIP_T4_TIMEOUT%1000 }; 
     53static const pj_time_val td_timer_val = { PJSIP_TD_TIMEOUT/1000,  
     54                                          PJSIP_TD_TIMEOUT%1000 }; 
    5055static const pj_time_val timeout_timer_val = { (64*PJSIP_T1_TIMEOUT)/1000, 
    5156                                               (64*PJSIP_T1_TIMEOUT)%1000 }; 
     
    5964 
    6065/* Function Prototypes */ 
    61 static int  pjsip_tsx_on_state_null( pjsip_transaction *tsx,  
    62                                      pjsip_event *event); 
    63 static int  pjsip_tsx_on_state_calling( pjsip_transaction *tsx,  
    64                                         pjsip_event *event); 
    65 static int  pjsip_tsx_on_state_trying( pjsip_transaction *tsx,  
    66                                        pjsip_event *event); 
    67 static int  pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx,  
    68                                                pjsip_event *event); 
    69 static int  pjsip_tsx_on_state_proceeding_uac( pjsip_transaction *tsx,  
    70                                                pjsip_event *event); 
    71 static int  pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx,  
    72                                               pjsip_event *event); 
    73 static int  pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx,  
    74                                               pjsip_event *event); 
    75 static int  pjsip_tsx_on_state_confirmed( pjsip_transaction *tsx,  
    76                                           pjsip_event *event); 
    77 static int  pjsip_tsx_on_state_terminated( pjsip_transaction *tsx,  
    78                                            pjsip_event *event); 
    79 static int  pjsip_tsx_on_state_destroyed( pjsip_transaction *tsx,  
    80                                           pjsip_event *event); 
    81 static void tsx_timer_callback( pj_timer_heap_t *theap,  
    82                                 pj_timer_entry *entry); 
    83 static int  tsx_send_msg( pjsip_transaction *tsx, pjsip_tx_data *tdata); 
    84 static void lock_tsx( pjsip_transaction *tsx, struct tsx_lock_data *lck ); 
    85 static pj_status_t unlock_tsx( pjsip_transaction *tsx, struct tsx_lock_data *lck ); 
     66static pj_status_t pjsip_tsx_on_state_null(     pjsip_transaction *tsx,  
     67                                                pjsip_event *event); 
     68static pj_status_t pjsip_tsx_on_state_calling(  pjsip_transaction *tsx,  
     69                                                pjsip_event *event); 
     70static pj_status_t pjsip_tsx_on_state_trying(   pjsip_transaction *tsx,  
     71                                                pjsip_event *event); 
     72static pj_status_t pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx,  
     73                                                pjsip_event *event); 
     74static pj_status_t pjsip_tsx_on_state_proceeding_uac( pjsip_transaction *tsx, 
     75                                                pjsip_event *event); 
     76static pj_status_t pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx,  
     77                                                pjsip_event *event); 
     78static pj_status_t pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, 
     79                                                pjsip_event *event); 
     80static pj_status_t pjsip_tsx_on_state_confirmed(pjsip_transaction *tsx,  
     81                                                pjsip_event *event); 
     82static pj_status_t pjsip_tsx_on_state_terminated(pjsip_transaction *tsx,  
     83                                                pjsip_event *event); 
     84static pj_status_t pjsip_tsx_on_state_destroyed(pjsip_transaction *tsx,  
     85                                                pjsip_event *event); 
     86 
     87static void         tsx_timer_callback( pj_timer_heap_t *theap,  
     88                                        pj_timer_entry *entry); 
     89static int          tsx_send_msg( pjsip_transaction *tsx,  
     90                                  pjsip_tx_data *tdata); 
     91static void         lock_tsx( pjsip_transaction *tsx, struct  
     92                               tsx_lock_data *lck ); 
     93static pj_status_t  unlock_tsx( pjsip_transaction *tsx,  
     94                               struct tsx_lock_data *lck ); 
    8695 
    8796/* State handlers for UAC, indexed by state */ 
    88 static int  (*tsx_state_handler_uac[PJSIP_TSX_STATE_MAX])(pjsip_transaction *tsx, 
    89                                                           pjsip_event *event ) =  
     97static int  (*tsx_state_handler_uac[PJSIP_TSX_STATE_MAX])(pjsip_transaction *, 
     98                                                          pjsip_event *) =  
    9099{ 
    91100    &pjsip_tsx_on_state_null, 
     
    100109 
    101110/* State handlers for UAS */ 
    102 static int  (*tsx_state_handler_uas[PJSIP_TSX_STATE_MAX])(pjsip_transaction *tsx,  
    103                                                           pjsip_event *event ) =  
     111static int  (*tsx_state_handler_uas[PJSIP_TSX_STATE_MAX])(pjsip_transaction *,  
     112                                                          pjsip_event *) =  
    104113{ 
    105114    &pjsip_tsx_on_state_null, 
     
    154163 * components. Additional comparison is needed to fully match a transaction. 
    155164 */ 
    156 void create_tsx_key_2543( pj_pool_t *pool, 
    157                           pj_str_t *str, 
    158                           pjsip_role_e role, 
    159                           const pjsip_method *method, 
    160                           const pjsip_rx_data *rdata ) 
     165static pj_status_t create_tsx_key_2543( pj_pool_t *pool, 
     166                                        pj_str_t *str, 
     167                                        pjsip_role_e role, 
     168                                        const pjsip_method *method, 
     169                                        const pjsip_rx_data *rdata ) 
    161170{ 
    162171#define SEPARATOR   '$' 
     
    167176    pj_str_t *host; 
    168177 
     178    PJ_ASSERT_RETURN(pool && str && method && rdata, PJ_EINVAL); 
     179    PJ_ASSERT_RETURN(rdata->msg, PJ_EINVAL); 
     180    PJ_ASSERT_RETURN(rdata->via, PJSIP_EMISSINGHDR); 
     181    PJ_ASSERT_RETURN(rdata->cseq, PJSIP_EMISSINGHDR); 
     182    PJ_ASSERT_RETURN(rdata->from, PJSIP_EMISSINGHDR); 
     183 
    169184    host = &rdata->via->sent_by.host; 
    170185    req_uri = (pjsip_uri*)rdata->msg->line.req.uri; 
    171186 
    172187    /* Calculate length required. */ 
    173     len_required = PJSIP_MAX_URL_SIZE +     /* URI */ 
    174                    9 +                      /* CSeq number */ 
    175                    rdata->from_tag.slen +   /* From tag. */ 
     188    len_required = 9 +                      /* CSeq number */ 
     189                   rdata->from->tag.slen +   /* From tag. */ 
    176190                   rdata->call_id.slen +    /* Call-ID */ 
    177191                   host->slen +             /* Via host. */ 
    178192                   9 +                      /* Via port. */ 
    179                    32;                      /* Separator+Allowance. */ 
     193                   16;                      /* Separator+Allowance. */ 
    180194    key = p = pj_pool_alloc(pool, len_required); 
    181195    end = p + len_required; 
     
    224238     * request retransmissions will contain the same port. 
    225239     */ 
    226     if ((end-p) < host->slen + 12) { 
    227         goto on_error; 
    228     } 
    229240    pj_memcpy(p, host->ptr, host->slen); 
    230241    p += host->slen; 
     
    241252    str->slen = p-key; 
    242253 
    243     return; 
    244  
    245 on_error: 
    246     PJ_LOG(2,("tsx........", "Not enough buffer (%d) for transaction key", 
    247               len_required)); 
    248     pj_assert(0); 
    249     str->ptr = NULL; 
    250     str->slen = 0; 
     254    return PJ_SUCCESS; 
    251255} 
    252256 
     
    254258 * Create transaction key for RFC3161 compliant system. 
    255259 */ 
    256 void create_tsx_key_3261( pj_pool_t *pool, 
    257                           pj_str_t *key, 
    258                           pjsip_role_e role, 
    259                           const pjsip_method *method, 
    260                           const pj_str_t *branch ) 
     260static pj_status_t create_tsx_key_3261( pj_pool_t *pool, 
     261                                        pj_str_t *key, 
     262                                        pjsip_role_e role, 
     263                                        const pjsip_method *method, 
     264                                        const pj_str_t *branch) 
    261265{ 
    262266    char *p; 
     267 
     268    PJ_ASSERT_RETURN(pool && key && method && branch, PJ_EINVAL); 
    263269 
    264270    p = key->ptr = pj_pool_alloc(pool, branch->slen + method->name.slen + 4 ); 
     
    281287    /* Set length */ 
    282288    key->slen = p - key->ptr; 
     289 
     290    return PJ_SUCCESS; 
    283291} 
    284292 
     
    287295 * in the transaction hash table. 
    288296 */ 
    289 PJ_DEF(void) pjsip_tsx_create_key( pj_pool_t *pool, pj_str_t *key,  
    290                                    pjsip_role_e role,  
    291                                    const pjsip_method *method,  
    292                                    const pjsip_rx_data *rdata ) 
    293 { 
    294     pj_str_t rfc3261_branch = {PJSIP_RFC3261_BRANCH_ID, PJSIP_RFC3261_BRANCH_LEN}; 
     297PJ_DEF(pj_status_t) pjsip_tsx_create_key( pj_pool_t *pool, pj_str_t *key,  
     298                                          pjsip_role_e role,  
     299                                          const pjsip_method *method,  
     300                                          const pjsip_rx_data *rdata) 
     301{ 
     302    pj_str_t rfc3261_branch = {PJSIP_RFC3261_BRANCH_ID,  
     303                               PJSIP_RFC3261_BRANCH_LEN}; 
     304 
    295305 
    296306    /* Get the branch parameter in the top-most Via. 
     
    301311    const pj_str_t *branch = &rdata->via->branch_param; 
    302312 
    303     if (pj_strncmp(branch, &rfc3261_branch, PJSIP_RFC3261_BRANCH_LEN) == 0) { 
     313    if (pj_strncmp(branch,&rfc3261_branch,PJSIP_RFC3261_BRANCH_LEN)==0) { 
    304314 
    305315        /* Create transaction key. */ 
    306         create_tsx_key_3261(pool, key, role, method, branch); 
     316        return create_tsx_key_3261(pool, key, role, method, branch); 
    307317 
    308318    } else { 
    309         /* Create the key for the message. This key will be matched up with the 
    310          * transaction key. For RFC2563 transactions, the transaction key 
    311          * was created by the same function, so it will match the message. 
     319        /* Create the key for the message. This key will be matched up  
     320         * with the transaction key. For RFC2563 transactions, the  
     321         * transaction key was created by the same function, so it will  
     322         * match the message. 
    312323         */ 
    313         create_tsx_key_2543( pool, key, role, method, rdata ); 
     324        return create_tsx_key_2543( pool, key, role, method, rdata ); 
    314325    } 
    315326} 
     
    319330 * Create new transaction. 
    320331 */ 
    321 PJ_DEF(pjsip_transaction *) pjsip_tsx_create(pj_pool_t *pool, 
    322                                              pjsip_endpoint *endpt) 
     332pj_status_t pjsip_tsx_create( pj_pool_t *pool, 
     333                              pjsip_endpoint *endpt, 
     334                              pjsip_transaction **p_tsx) 
    323335{ 
    324336    pjsip_transaction *tsx; 
     337    pj_status_t status; 
    325338 
    326339    tsx = pj_pool_calloc(pool, 1, sizeof(pjsip_transaction)); 
     
    336349    tsx->timeout_timer.user_data = tsx; 
    337350    tsx->timeout_timer.cb = &tsx_timer_callback; 
    338     sprintf(tsx->obj_name, "tsx%p", tsx); 
    339     tsx->mutex = pj_mutex_create(pool, "mtsx%p", 0); 
    340     if (!tsx->mutex) { 
    341         return NULL; 
    342     } 
    343  
    344     return tsx; 
     351    pj_sprintf(tsx->obj_name, "tsx%p", tsx); 
     352    status = pj_mutex_create_recursive(pool, "mtsx%p", &tsx->mutex); 
     353    if (status != PJ_SUCCESS) { 
     354        return status; 
     355    } 
     356 
     357    *p_tsx = tsx; 
     358    return PJ_SUCCESS; 
    345359} 
    346360 
     
    353367 
    354368    pj_mutex_lock(tsx->mutex); 
    355     prev_data = (struct tsx_lock_data *) pj_thread_local_get(pjsip_tsx_lock_tls_id); 
     369    prev_data = (struct tsx_lock_data *)  
     370                    pj_thread_local_get(pjsip_tsx_lock_tls_id); 
    356371    lck->prev = prev_data; 
    357372    lck->tsx = tsx; 
     
    368383 * will be set to zero. 
    369384 */ 
    370 static pj_status_t unlock_tsx(pjsip_transaction *tsx, struct tsx_lock_data *lck) 
     385static pj_status_t unlock_tsx( pjsip_transaction *tsx,  
     386                               struct tsx_lock_data *lck) 
    371387{ 
    372388    pj_assert( (void*)pj_thread_local_get(pjsip_tsx_lock_tls_id) == lck); 
     
    376392        pj_mutex_unlock(tsx->mutex); 
    377393 
    378     return lck->is_alive ? 0 : -1; 
     394    return lck->is_alive ? PJ_SUCCESS : PJSIP_ETSXDESTROYED; 
    379395} 
    380396 
     
    384400static void tsx_set_state( pjsip_transaction *tsx, 
    385401                           pjsip_tsx_state_e state, 
    386                            const pjsip_event *event ) 
     402                           pjsip_event_id_e event_src_type, 
     403                           void *event_src ) 
    387404{ 
    388405    pjsip_event e; 
    389406 
    390     PJ_LOG(4, (tsx->obj_name, "STATE %s-->%s, ev=%s (src:%s)",  
    391                state_str[tsx->state], state_str[state], pjsip_event_str(event->type), 
    392                pjsip_event_str(event->src_type))); 
     407    PJ_LOG(4, (tsx->obj_name, "STATE %s-->%s, cause = %s", 
     408               state_str[tsx->state], state_str[state],  
     409               pjsip_event_str(event_src_type))); 
    393410 
    394411    /* Change state. */ 
     
    403420 
    404421    /* Inform TU */ 
    405     pj_memcpy(&e, event, sizeof(*event)); 
    406     e.type = PJSIP_EVENT_TSX_STATE_CHANGED; 
    407     e.obj.tsx = tsx; 
     422    PJSIP_EVENT_INIT_TSX_STATE(e, tsx, event_src_type, event_src); 
    408423    pjsip_endpt_send_tsx_event( tsx->endpt, &e  ); 
    409424 
     
    414429 
    415430        /* Decrement transport reference counter. */ 
    416         if (tsx->transport && tsx->transport_state == PJSIP_TSX_TRANSPORT_STATE_FINAL) { 
     431        if (tsx->transport &&  
     432            tsx->transport_state == PJSIP_TSX_TRANSPORT_STATE_FINAL)  
     433        { 
    417434            pjsip_transport_dec_ref( tsx->transport ); 
    418435            tsx->transport = NULL; 
     
    484501        while (last_route_hdr->next != (void*)&tdata->msg->hdr) { 
    485502            pjsip_route_hdr *hdr; 
    486             hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, last_route_hdr->next); 
     503            hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE,  
     504                                     last_route_hdr->next); 
    487505            if (!hdr) 
    488506                break; 
     
    564582        pj_strdup(tdata->pool, &send_addr->host, &url->host); 
    565583        send_addr->port = url->port; 
    566         send_addr->type = pjsip_transport_get_type_from_name(&url->transport_param); 
     584        send_addr->type =  
     585            pjsip_transport_get_type_from_name(&url->transport_param); 
    567586 
    568587    } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) { 
     
    571590        pj_strdup(tdata->pool, &send_addr->host, &url->host); 
    572591        send_addr->port = url->port; 
    573         send_addr->type = pjsip_transport_get_type_from_name(&url->transport_param); 
     592        send_addr->type =  
     593            pjsip_transport_get_type_from_name(&url->transport_param); 
    574594#if PJ_HAS_TCP 
    575595        if (send_addr->type == PJSIP_TRANSPORT_TCP ||  
     
    580600#endif 
    581601    } else { 
    582         PJ_LOG(2, (tsx->obj_name, "Unable to lookup destination address for " 
    583                                   "non SIP-URL"));    
    584         return -1; 
     602        pj_assert(!"Unsupported URI scheme!"); 
     603        return PJSIP_EINVALIDSCHEME; 
    585604    } 
    586605 
     
    599618 
    600619    /* Success. */ 
    601     return 0 
     620    return PJ_SUCCESS 
    602621} 
    603622 
     
    625644                                  addr, tsx->dest_name.port)); 
    626645    } else { 
    627         PJ_LOG(3, (tsx->obj_name, "%s unable to connect to %s:%d, status=%d",  
     646        PJ_LOG(4, (tsx->obj_name, "%s unable to connect to %s:%d, status=%d",  
    628647                                  pjsip_transport_get_type_name(tr), 
    629648                                  addr, tsx->dest_name.port, status)); 
     
    634653 
    635654    if (status != PJ_SUCCESS) { 
    636         pjsip_event event; 
    637          
    638         event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    639         event.src_type = PJSIP_EVENT_TX_MSG; 
    640         event.src.tdata = tsx->last_tx; 
    641  
    642655        tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 
    643656        tsx->status_code = PJSIP_SC_TSX_TRANSPORT_ERROR; 
    644         tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     657 
     658        tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED, 
     659                      PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
    645660 
    646661        /* Unlock transaction. */ 
     
    649664    } 
    650665 
    651     /* See if transaction has already been terminated. If so, schedule to destroy 
    652      * the transaction. 
     666    /* See if transaction has already been terminated.  
     667     * If so, schedule to destroy the transaction. 
    653668     */ 
    654669    if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 
     
    691706 
    692707    if (status != PJ_SUCCESS || addr->count == 0) { 
    693         pjsip_event event; 
    694          
    695         event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    696         event.src_type = PJSIP_EVENT_TX_MSG; 
    697         event.src.tdata = tsx->last_tx; 
    698  
    699708        lock_tsx(tsx, &lck); 
    700709        tsx->status_code = PJSIP_SC_TSX_RESOLVE_ERROR; 
    701         tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     710        tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED,  
     711                      PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
    702712        unlock_tsx(tsx, &lck); 
    703713        return; 
     
    712722    /* Create/find the transport for the remote address. */ 
    713723    PJ_LOG(5,(tsx->obj_name, "tsx getting transport for %s:%d", 
    714                              pj_sockaddr_get_str_addr(&addr->entry[0].addr), 
    715                              pj_sockaddr_get_port(&addr->entry[0].addr))); 
     724                             pj_inet_ntoa(addr->entry[0].addr.sin_addr), 
     725                             pj_ntohs(addr->entry[0].addr.sin_port))); 
    716726 
    717727    tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_CONNECTING; 
     
    739749    pjsip_cseq_hdr *cseq; 
    740750    pjsip_via_hdr *via; 
     751    pj_status_t status; 
    741752    struct tsx_lock_data lck; 
    742     const pjsip_hdr *endpt_hdr; 
    743753 
    744754    PJ_LOG(4,(tsx->obj_name, "initializing tsx as UAC (tdata=%p)", tdata)); 
     
    756766    pjsip_method_copy( tsx->pool, &tsx->method, &msg->line.req.method); 
    757767 
    758     /* Generate branch parameter if it doesn't exist. */ 
     768    /* Generate Via header if it doesn't exist. */ 
    759769    via = pjsip_msg_find_hdr(msg, PJSIP_H_VIA, NULL); 
    760770    if (via == NULL) { 
     
    772782        tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN; 
    773783        pj_generate_unique_string( &tmp ); 
    774     } 
    775  
    776     /* Copy branch parameter. */ 
    777     tsx->branch = via->branch_param; 
    778  
    779     /* Add additional request headers from endpoint. */ 
    780     endpt_hdr = pjsip_endpt_get_request_headers(tsx->endpt)->next; 
    781     while (endpt_hdr != pjsip_endpt_get_request_headers(tsx->endpt)) { 
    782         pjsip_hdr *hdr = pjsip_hdr_shallow_clone(tdata->pool, endpt_hdr); 
    783         pjsip_msg_add_hdr( tdata->msg, hdr ); 
    784         endpt_hdr = endpt_hdr->next; 
    785     } 
     784 
     785        /* Save branch parameter. */ 
     786        tsx->branch = via->branch_param; 
     787    } else { 
     788        /* Copy branch parameter. */ 
     789        pj_strdup(tsx->pool, &tsx->branch, &via->branch_param); 
     790    } 
     791 
    786792 
    787793    /* Generate transaction key. */ 
    788     create_tsx_key_3261( tsx->pool, &tsx->transaction_key, 
    789                          PJSIP_ROLE_UAC, &tsx->method,  
    790                          &via->branch_param); 
     794    status = create_tsx_key_3261( tsx->pool, &tsx->transaction_key, 
     795                                  PJSIP_ROLE_UAC, &tsx->method,  
     796                                  &via->branch_param); 
     797    if (status != PJ_SUCCESS) { 
     798        unlock_tsx(tsx, &lck); 
     799        return status; 
     800    } 
    791801 
    792802    PJ_LOG(6, (tsx->obj_name, "tsx_key=%.*s", tsx->transaction_key.slen, 
     
    796806    cseq = pjsip_msg_find_hdr(msg, PJSIP_H_CSEQ, NULL); 
    797807    if (!cseq) { 
    798         PJ_LOG(4,(tsx->obj_name, "CSeq header not present in outgoing message!")); 
    799         return -1; 
     808        pj_assert(!"CSeq header not present in outgoing message!"); 
     809        unlock_tsx(tsx, &lck); 
     810        return PJSIP_EMISSINGHDR; 
    800811    } 
    801812    tsx->cseq = cseq->cseq; 
     
    806817     */ 
    807818    tsx->state = PJSIP_TSX_STATE_NULL; 
    808     tsx->state_handler = pjsip_tsx_on_state_null; 
     819    tsx->state_handler = &pjsip_tsx_on_state_null; 
    809820 
    810821    /* Get destination name from the message. */ 
    811     if (tsx_process_route(tsx, tdata, &tsx->dest_name) != 0) { 
    812         pjsip_event event; 
    813         PJ_LOG(3,(tsx->obj_name, "Error: unable to get destination address for request")); 
    814          
    815         event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    816         event.src_type = PJSIP_EVENT_TX_MSG; 
    817         event.src.tdata = tsx->last_tx; 
    818  
     822    status = tsx_process_route(tsx, tdata, &tsx->dest_name); 
     823    if (status != PJ_SUCCESS) { 
    819824        tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 
    820825        tsx->status_code = PJSIP_SC_TSX_TRANSPORT_ERROR; 
    821         tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     826        tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED,  
     827                      PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
    822828        unlock_tsx(tsx, &lck); 
    823         return -1; 
     829        return status; 
    824830    } 
    825831 
     
    859865    pj_str_t *branch; 
    860866    pjsip_cseq_hdr *cseq; 
     867    pj_status_t status; 
    861868    struct tsx_lock_data lck; 
    862869 
     
    878885     * create transaction key. 
    879886     */ 
    880     pjsip_tsx_create_key(tsx->pool, &tsx->transaction_key, PJSIP_ROLE_UAS,  
    881                          &tsx->method, rdata); 
     887    status = pjsip_tsx_create_key(tsx->pool, &tsx->transaction_key,  
     888                                  PJSIP_ROLE_UAS, &tsx->method, rdata); 
     889    if (status != PJ_SUCCESS) { 
     890        unlock_tsx(tsx, &lck); 
     891        return status; 
     892    } 
    882893 
    883894    /* Duplicate branch parameter for transaction. */ 
     
    914925        tsx->current_addr = 0; 
    915926        tsx->remote_addr.count = 1; 
    916         tsx->remote_addr.entry[0].type = pjsip_transport_get_type(tsx->transport); 
     927        tsx->remote_addr.entry[0].type =  
     928                pjsip_transport_get_type(tsx->transport); 
    917929        pj_memcpy(&tsx->remote_addr.entry[0].addr,  
    918930                  &rdata->addr, rdata->addr_len); 
     
    924936                                         rdata->via, &tsx->dest_name); 
    925937        if (status != PJ_SUCCESS) { 
    926             pjsip_event event; 
    927             PJ_LOG(2,(tsx->obj_name, "Unable to get destination address " 
    928                                      "for response")); 
    929              
    930             event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    931             event.src_type = PJSIP_EVENT_TX_MSG; 
    932             event.src.tdata = tsx->last_tx; 
    933  
    934938            tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 
    935939            tsx->status_code = PJSIP_SC_TSX_TRANSPORT_ERROR; 
    936             tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     940            tsx_set_state(tsx, PJSIP_TSX_STATE_TERMINATED,  
     941                          PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
    937942            unlock_tsx(tsx, &lck); 
    938943            return status; 
     
    944949         */ 
    945950        PJ_LOG(5,(tsx->obj_name, "tsx resolving destination %.*s:%d", 
    946                                  tsx->dest_name.host.slen, tsx->dest_name.host.ptr, 
     951                                 tsx->dest_name.host.slen,  
     952                                 tsx->dest_name.host.ptr, 
    947953                                 tsx->dest_name.port)); 
    948954 
     
    976982 
    977983    PJ_LOG(5,(tsx->obj_name, "got timer event (%s timer)",  
    978              (entry->id == TSX_TIMER_RETRANSMISSION ? "Retransmit" : "Timeout"))); 
    979  
    980     event.type = event.src_type = PJSIP_EVENT_TIMER; 
    981     event.src.timer = (entry->id == TSX_TIMER_RETRANSMISSION ?  
    982         &tsx->retransmit_timer : &tsx->timeout_timer); 
     984             (entry->id==TSX_TIMER_RETRANSMISSION ? "Retransmit" : "Timeout"))); 
     985 
     986 
     987    if (entry->id == TSX_TIMER_RETRANSMISSION) { 
     988        PJSIP_EVENT_INIT_TIMER(event, &tsx->retransmit_timer); 
     989    } else { 
     990        PJSIP_EVENT_INIT_TIMER(event, &tsx->timeout_timer); 
     991    } 
    983992 
    984993    /* Dispatch event to transaction. */ 
     
    10001009    pjsip_msg *msg; 
    10011010    pjsip_host_port dest_addr; 
    1002     pjsip_event event; 
    10031011    pjsip_via_hdr *via; 
    10041012    struct tsx_lock_data lck; 
    1005  
     1013    pj_status_t status = PJ_SUCCESS; 
     1014 
     1015    /* Lock tsx. */ 
    10061016    lock_tsx(tsx, &lck); 
    10071017 
     
    10241034 
    10251035    /* Get destination name from the message. */ 
    1026     if (tsx_process_route(tsx, tdata, &dest_addr) != 0){ 
    1027         PJ_LOG(2,(tsx->obj_name, "Unable to get destination address for request")); 
     1036    status = tsx_process_route(tsx, tdata, &dest_addr); 
     1037    if (status != 0){ 
    10281038        goto on_error; 
    10291039    } 
     
    10891099     */ 
    10901100    tsx->status_code = PJSIP_SC_TSX_TRANSPORT_ERROR; 
    1091     event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    1092     event.src_type = PJSIP_EVENT_TX_MSG; 
    1093     event.src.tdata = tdata; 
    1094     tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     1101 
     1102    tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1103                   PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
    10951104 
    10961105    unlock_tsx(tsx, &lck); 
     
    11061115    pjsip_event event; 
    11071116    struct tsx_lock_data lck; 
    1108  
    1109     PJ_LOG(5,(tsx->obj_name, "on transmit msg (tdata=%p)", tdata)); 
    1110  
    1111     event.type = event.src_type = PJSIP_EVENT_TX_MSG; 
    1112     event.src.tdata = tdata; 
    1113  
    1114     PJ_LOG(5,(tsx->obj_name, "on state %s (ev=%s, src=%s, data=%p)",  
    1115               state_str[tsx->state], pjsip_event_str(event.type),  
    1116               pjsip_event_str(event.src_type), event.src.data)); 
     1117    pj_status_t status; 
     1118 
     1119    PJ_LOG(5,(tsx->obj_name, "Request to transmit msg on state %s (tdata=%p)", 
     1120                             state_str[tsx->state], tdata)); 
     1121 
     1122    PJSIP_EVENT_INIT_TX_MSG(event, tsx, tdata); 
    11171123 
    11181124    /* Dispatch to transaction. */ 
    11191125    lock_tsx(tsx, &lck); 
    1120     (*tsx->state_handler)(tsx, &event); 
     1126    status = (*tsx->state_handler)(tsx, &event); 
    11211127    unlock_tsx(tsx, &lck); 
    11221128} 
     
    11311137    pjsip_event event; 
    11321138    struct tsx_lock_data lck; 
    1133  
    1134     event.type = event.src_type = PJSIP_EVENT_RX_MSG; 
    1135     event.src.rdata = rdata; 
    1136  
    1137     PJ_LOG(5,(tsx->obj_name, "on state %s (ev=%s, src=%s, data=%p)",  
    1138               state_str[tsx->state], pjsip_event_str(event.type),  
    1139               pjsip_event_str(event.src_type), event.src.data)); 
     1139    pj_status_t status; 
     1140 
     1141    PJ_LOG(5,(tsx->obj_name, "Incoming msg on state %s (rdata=%p)",  
     1142              state_str[tsx->state], rdata)); 
     1143 
     1144    PJSIP_EVENT_INIT_RX_MSG(event, tsx, rdata); 
    11401145 
    11411146    /* Dispatch to transaction. */ 
    11421147    lock_tsx(tsx, &lck); 
    1143     (*tsx->state_handler)(tsx, &event); 
     1148    status = (*tsx->state_handler)(tsx, &event); 
    11441149    unlock_tsx(tsx, &lck); 
    11451150} 
     
    11501155PJ_DEF(void) pjsip_tsx_terminate( pjsip_transaction *tsx, int code ) 
    11511156{ 
    1152     pjsip_event event; 
    11531157    struct tsx_lock_data lck; 
    11541158 
    11551159    lock_tsx(tsx, &lck); 
    1156  
    11571160    tsx->status_code = code; 
    1158     event.type = PJSIP_EVENT_USER; 
    1159     event.src_type = PJSIP_EVENT_USER; 
    1160     event.src.data = 0; 
    1161     event.obj.tsx = tsx; 
    1162     tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
     1161    tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1162                   PJSIP_EVENT_USER, NULL); 
    11631163 
    11641164    unlock_tsx(tsx, &lck); 
     
    11701170 * transmitted when transport connection completion callback is called. 
    11711171 */ 
    1172 static int tsx_send_msg( pjsip_transaction *tsx, pjsip_tx_data *tdata) 
    1173 { 
    1174     pjsip_event event; 
     1172static pj_status_t tsx_send_msg( pjsip_transaction *tsx,  
     1173                                 pjsip_tx_data *tdata) 
     1174{ 
     1175    pj_status_t status = PJ_SUCCESS; 
    11751176 
    11761177    PJ_LOG(5,(tsx->obj_name, "sending msg (tdata=%p)", tdata)); 
    11771178 
    11781179    if (tsx->transport_state == PJSIP_TSX_TRANSPORT_STATE_FINAL) { 
    1179         int sent; 
     1180        pj_ssize_t sent; 
    11801181        pjsip_event before_tx_event; 
    11811182 
     
    12001201                        pjsip_transport_get_type_name(tsx->transport)); 
    12011202                pj_strdup2(tdata->pool, &via->sent_by.host,  
    1202                         pj_sockaddr_get_str_addr(addr_name)); 
    1203                 via->sent_by.port = pj_sockaddr_get_port(addr_name); 
     1203                           pj_inet_ntoa(addr_name->sin_addr)); 
     1204                via->sent_by.port = pj_ntohs(addr_name->sin_port); 
    12041205            } 
    12051206        } 
    12061207 
    12071208        /* Notify everybody we're about to send message. */ 
    1208         before_tx_event.type = PJSIP_EVENT_BEFORE_TX; 
    1209         before_tx_event.src_type = PJSIP_EVENT_TX_MSG; 
    1210         before_tx_event.obj.tsx = tsx; 
    1211         before_tx_event.src.tdata = tdata; 
    1212         before_tx_event.data.long_data = tsx->retransmit_count; 
    1213         pjsip_endpt_send_tsx_event( tsx->endpt, &before_tx_event  ); 
     1209        PJSIP_EVENT_INIT_PRE_TX_MSG(before_tx_event, tsx, tdata,  
     1210                                    tsx->retransmit_count); 
     1211        pjsip_endpt_send_tsx_event( tsx->endpt, &before_tx_event ); 
    12141212 
    12151213        tsx->has_unsent_msg = 0; 
    1216         sent = pjsip_transport_send_msg( 
    1217                 tsx->transport, tdata, 
    1218                 &tsx->remote_addr.entry[tsx->current_addr].addr 
    1219                 ); 
    1220         if (sent < 1) { 
     1214        status = pjsip_transport_send_msg( 
     1215                        tsx->transport, tdata, 
     1216                        &tsx->remote_addr.entry[tsx->current_addr].addr, 
     1217                        &sent); 
     1218        if (status != PJ_SUCCESS) { 
    12211219            goto on_error; 
    12221220        } 
     
    12291227on_error: 
    12301228    tsx->status_code = PJSIP_SC_TSX_TRANSPORT_ERROR; 
    1231     event.type = PJSIP_EVENT_TRANSPORT_ERROR; 
    1232     event.src_type = PJSIP_EVENT_TX_MSG; 
    1233     event.src.tdata = tdata; 
    1234     tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, &event); 
    1235     return -1; 
     1229    tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1230                   PJSIP_EVENT_TRANSPORT_ERROR, (void*)status); 
     1231    return status; 
    12361232} 
    12371233 
     
    12421238                                         int should_restart_timer) 
    12431239{ 
     1240    pj_status_t status; 
     1241 
    12441242    PJ_LOG(4,(tsx->obj_name, "retransmiting (tdata=%p, count=%d, restart?=%d)",  
    12451243              tsx->last_tx, tsx->retransmit_count, should_restart_timer)); 
     
    12491247    ++tsx->retransmit_count; 
    12501248 
    1251     if (tsx_send_msg( tsx, tsx->last_tx) != 0) { 
    1252         return -1; 
     1249    status = tsx_send_msg( tsx, tsx->last_tx); 
     1250    if (status != PJ_SUCCESS) { 
     1251        return status; 
    12531252    } 
    12541253     
     
    12581257        int msec_time = (1 << (tsx->retransmit_count)) * PJSIP_T1_TIMEOUT; 
    12591258 
    1260         if (tsx->method.id != PJSIP_INVITE_METHOD && msec_time > PJSIP_T2_TIMEOUT)  
     1259        if (tsx->method.id!=PJSIP_INVITE_METHOD && msec_time>PJSIP_T2_TIMEOUT)  
    12611260            msec_time = PJSIP_T2_TIMEOUT; 
    12621261 
    12631262        timeout.sec = msec_time / 1000; 
    12641263        timeout.msec = msec_time % 1000; 
    1265         pjsip_endpt_schedule_timer( tsx->endpt, &tsx->retransmit_timer, &timeout); 
     1264        pjsip_endpt_schedule_timer( tsx->endpt, &tsx->retransmit_timer,  
     1265                                    &timeout); 
    12661266    } 
    12671267 
     
    12721272 * Handler for events in state Null. 
    12731273 */ 
    1274 static int  pjsip_tsx_on_state_null( pjsip_transaction *tsx, pjsip_event *event ) 
    1275 { 
     1274static pj_status_t pjsip_tsx_on_state_null( pjsip_transaction *tsx,  
     1275                                            pjsip_event *event ) 
     1276{ 
     1277    pj_status_t status; 
     1278 
    12761279    pj_assert( tsx->state == PJSIP_TSX_STATE_NULL); 
    12771280    pj_assert( tsx->last_tx == NULL ); 
     
    12821285        /* Set state to Trying. */ 
    12831286        pj_assert(event->type == PJSIP_EVENT_RX_MSG); 
    1284         tsx_set_state( tsx, PJSIP_TSX_STATE_TRYING, event); 
     1287        tsx_set_state( tsx, PJSIP_TSX_STATE_TRYING,  
     1288                       PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
    12851289 
    12861290    } else { 
    1287         pjsip_tx_data *tdata = event->src.tdata; 
     1291        pjsip_tx_data *tdata = event->body.tx_msg.tdata; 
    12881292 
    12891293        /* Save the message for retransmission. */ 
     
    12921296 
    12931297        /* Send the message. */ 
    1294         if (tsx_send_msg( tsx, tdata) != 0) { 
    1295             return -1; 
     1298        status = tsx_send_msg( tsx, tdata); 
     1299        if (status != PJ_SUCCESS) { 
     1300            return status; 
    12961301        } 
    12971302 
     
    12991304         * timeout. 
    13001305         */ 
    1301         pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &timeout_timer_val); 
     1306        pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer,  
     1307                                    &timeout_timer_val); 
    13021308 
    13031309        /* Start Timer A (or timer E) for retransmission only if unreliable  
     
    13071313            PJSIP_TRANSPORT_IS_RELIABLE(tsx->transport)==0)  
    13081314        { 
    1309             pjsip_endpt_schedule_timer(tsx->endpt, &tsx->retransmit_timer, &t1_timer_val); 
     1315            pjsip_endpt_schedule_timer(tsx->endpt, &tsx->retransmit_timer,  
     1316                                       &t1_timer_val); 
    13101317            tsx->retransmit_count = 0; 
    13111318        } 
    13121319 
    13131320        /* Move state. */ 
    1314         tsx_set_state( tsx, PJSIP_TSX_STATE_CALLING, event); 
     1321        tsx_set_state( tsx, PJSIP_TSX_STATE_CALLING,  
     1322                       PJSIP_EVENT_TX_MSG, tdata); 
    13151323    } 
    13161324 
     
    13221330 * is received. 
    13231331 */ 
    1324 static int pjsip_tsx_on_state_calling( pjsip_transaction *tsx,  
    1325                                         pjsip_event *event) 
     1332static pj_status_t pjsip_tsx_on_state_calling( pjsip_transaction *tsx,  
     1333                                               pjsip_event *event ) 
    13261334{ 
    13271335    pj_assert(tsx->state == PJSIP_TSX_STATE_CALLING); 
     
    13291337 
    13301338    if (event->type == PJSIP_EVENT_TIMER &&  
    1331         event->src.timer == &tsx->retransmit_timer)  
     1339        event->body.timer.entry == &tsx->retransmit_timer)  
    13321340    { 
     1341        pj_status_t status; 
    13331342 
    13341343        /* Retransmit the request. */ 
    1335         if (pjsip_tsx_retransmit( tsx, 1 ) != 0) { 
    1336             return -1; 
     1344        status = pjsip_tsx_retransmit( tsx, 1 ); 
     1345        if (status != PJ_SUCCESS) { 
     1346            return status; 
    13371347        } 
    13381348 
    13391349    } else if (event->type == PJSIP_EVENT_TIMER &&  
    1340               event->src.timer == &tsx->timeout_timer)  
     1350               event->body.timer.entry == &tsx->timeout_timer)  
    13411351    { 
    13421352 
     
    13501360 
    13511361        /* Inform TU. */ 
    1352         tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event ); 
     1362        tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1363                       PJSIP_EVENT_TIMER, &tsx->timeout_timer); 
    13531364 
    13541365        /* Transaction is destroyed */ 
    1355         return -1; 
     1366        return PJSIP_ETSXDESTROYED; 
    13561367 
    13571368    } else if (event->type == PJSIP_EVENT_RX_MSG) { 
     
    13701381         */ 
    13711382        /* Keep last_tx for authorization. */ 
    1372         code = event->src.rdata->msg->line.status.code; 
     1383        code = event->body.rx_msg.rdata->msg->line.status.code; 
    13731384        if (tsx->method.id != PJSIP_INVITE_METHOD && code!=401 && code!=407) { 
    13741385            pjsip_tx_data_dec_ref(tsx->last_tx); 
     
    13811392    } else { 
    13821393        pj_assert(0); 
     1394        return PJ_EBUG; 
    13831395    } 
    13841396 
     
    13921404 *       non-INVITE client transaction (bug in RFC?). 
    13931405 */ 
    1394 static int  pjsip_tsx_on_state_trying( pjsip_transaction *tsx, pjsip_event *event) 
    1395 { 
    1396     int result; 
     1406static pj_status_t pjsip_tsx_on_state_trying( pjsip_transaction *tsx,  
     1407                                              pjsip_event *event) 
     1408{ 
     1409    pj_status_t status; 
    13971410 
    13981411    pj_assert(tsx->state == PJSIP_TSX_STATE_TRYING); 
     
    14151428     * "Proceeding" state. 
    14161429     */ 
    1417     result = pjsip_tsx_on_state_proceeding_uas( tsx, event); 
     1430    status = pjsip_tsx_on_state_proceeding_uas( tsx, event); 
    14181431 
    14191432    /* Inform the TU of the state transision if state is still State_Trying */ 
    1420     if (result==0 && tsx->state == PJSIP_TSX_STATE_TRYING) { 
    1421         tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING, event); 
    1422     } 
    1423  
    1424     return result; 
     1433    if (status==PJ_SUCCESS && tsx->state == PJSIP_TSX_STATE_TRYING) { 
     1434        tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING,  
     1435                       PJSIP_EVENT_TX_MSG, event->body.tx_msg.tdata); 
     1436    } 
     1437 
     1438    return status; 
    14251439} 
    14261440 
     
    14291443 * This state happens after the TU sends provisional response. 
    14301444 */ 
    1431 static int pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx, pjsip_event *event) 
     1445static pj_status_t pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx, 
     1446                                                      pjsip_event *event) 
    14321447{ 
    14331448    pj_assert(tsx->state == PJSIP_TSX_STATE_PROCEEDING ||  
     
    14401455    if (event->type == PJSIP_EVENT_RX_MSG) { 
    14411456 
     1457        pj_status_t status; 
     1458 
    14421459        /* Send last response. */ 
    1443         if (pjsip_tsx_retransmit( tsx, 0 ) != 0) { 
    1444             return -1; 
     1460        status = pjsip_tsx_retransmit( tsx, 0 ); 
     1461        if (status != PJ_SUCCESS) { 
     1462            return status; 
    14451463        } 
    14461464         
    14471465    } else if (event->type == PJSIP_EVENT_TX_MSG ) { 
    1448         pjsip_tx_data *tdata = event->src.tdata; 
     1466        pjsip_tx_data *tdata = event->body.tx_msg.tdata; 
     1467        pj_status_t status; 
    14491468 
    14501469        /* The TU sends response message to the request. Save this message so 
     
    14721491 
    14731492        /* Send the message. */ 
    1474         if (tsx_send_msg(tsx, tdata) != 0) { 
    1475             return -1; 
     1493        status = tsx_send_msg(tsx, tdata); 
     1494        if (status != PJ_SUCCESS) { 
     1495            return status; 
    14761496        } 
    14771497 
     
    14861506                pjsip_tx_data_add_ref( tdata ); 
    14871507            } 
    1488             tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING, event); 
     1508            tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING,  
     1509                           PJSIP_EVENT_TX_MSG, tdata ); 
    14891510 
    14901511        } else if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code, 200)) { 
     
    14921513            if (tsx->method.id == PJSIP_INVITE_METHOD && tsx->handle_ack==0) { 
    14931514 
    1494                 /* 2xx class message is not saved, because retransmission is handled 
    1495                  * by the TU. 
     1515                /* 2xx class message is not saved, because retransmission  
     1516                 * is handled by TU. 
    14961517                 */ 
    1497                 tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
     1518                tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1519                               PJSIP_EVENT_TX_MSG, tdata ); 
    14981520 
    14991521                /* Transaction is destroyed. */ 
    1500                 return -1; 
     1522                return PJSIP_ETSXDESTROYED; 
    15011523 
    15021524            } else { 
     
    15051527                if (tsx->method.id == PJSIP_INVITE_METHOD) { 
    15061528                    tsx->retransmit_count = 0; 
    1507                     pjsip_endpt_schedule_timer( tsx->endpt, &tsx->retransmit_timer,  
     1529                    pjsip_endpt_schedule_timer( tsx->endpt,  
     1530                                                &tsx->retransmit_timer,  
    15081531                                                &t1_timer_val); 
    15091532                } 
     
    15261549                } 
    15271550 
    1528                 pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &timeout); 
     1551                pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer,  
     1552                                            &timeout); 
    15291553 
    15301554                /* Set state to "Completed" */ 
    1531                 tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED, event); 
     1555                tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED,  
     1556                               PJSIP_EVENT_TX_MSG, tdata ); 
    15321557            } 
    15331558 
    15341559        } else if (tsx->status_code >= 300) { 
    15351560 
    1536             /* 3xx-6xx class message causes transaction to move to "Completed" state. */ 
     1561            /* 3xx-6xx class message causes transaction to move to  
     1562             * "Completed" state.  
     1563             */ 
    15371564            if (tsx->last_tx != tdata) { 
    15381565                tsx->last_tx = tdata; 
     
    15411568 
    15421569            /* Start timer H for transaction termination */ 
    1543             pjsip_endpt_schedule_timer(tsx->endpt,&tsx->timeout_timer,&timeout_timer_val); 
     1570            pjsip_endpt_schedule_timer(tsx->endpt,&tsx->timeout_timer, 
     1571                                       &timeout_timer_val); 
    15441572 
    15451573            /* For INVITE, if unreliable transport is used, retransmission  
     
    15471575             */ 
    15481576            if (PJSIP_TRANSPORT_IS_RELIABLE(tsx->transport)==0) { 
    1549                 pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr( msg, PJSIP_H_CSEQ, NULL); 
     1577                pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr( msg, PJSIP_H_CSEQ, 
     1578                                                           NULL); 
    15501579                if (cseq->method.id == PJSIP_INVITE_METHOD) { 
    15511580                    tsx->retransmit_count = 0; 
    1552                     pjsip_endpt_schedule_timer(tsx->endpt, &tsx->retransmit_timer,  
     1581                    pjsip_endpt_schedule_timer(tsx->endpt,  
     1582                                               &tsx->retransmit_timer,  
    15531583                                               &t1_timer_val); 
    15541584                } 
     
    15561586 
    15571587            /* Inform TU */ 
    1558             tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED, event); 
     1588            tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED,  
     1589                           PJSIP_EVENT_TX_MSG, tdata ); 
    15591590 
    15601591        } else { 
     
    15641595 
    15651596    } else if (event->type == PJSIP_EVENT_TIMER &&  
    1566                event->src.timer == &tsx->retransmit_timer) { 
     1597               event->body.timer.entry == &tsx->retransmit_timer) { 
    15671598        /* Retransmission timer elapsed. */ 
     1599        pj_status_t status; 
    15681600 
    15691601        /* Must have last response to retransmit. */ 
     
    15711603 
    15721604        /* Retransmit the last response. */ 
    1573         if (pjsip_tsx_retransmit( tsx, 1 ) != 0) { 
    1574             return -1; 
     1605        status = pjsip_tsx_retransmit( tsx, 1 ); 
     1606        if (status != PJ_SUCCESS) { 
     1607            return status; 
    15751608        } 
    15761609 
    15771610    } else if (event->type == PJSIP_EVENT_TIMER &&  
    1578                event->src.timer == &tsx->timeout_timer) { 
     1611               event->body.timer.entry == &tsx->timeout_timer) { 
    15791612 
    15801613        /* Timeout timer. should not happen? */ 
     
    15831616        tsx->status_code = PJSIP_SC_TSX_TIMEOUT; 
    15841617 
    1585         tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
    1586  
    1587         return -1; 
     1618        tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1619                       PJSIP_EVENT_TIMER, &tsx->timeout_timer); 
     1620 
     1621        return PJ_EBUG; 
    15881622 
    15891623    } else { 
    15901624        pj_assert(0); 
    1591     } 
    1592  
    1593     return 0; 
     1625        return PJ_EBUG; 
     1626    } 
     1627 
     1628    return PJ_SUCCESS; 
    15941629} 
    15951630 
     
    15991634 * UAS. 
    16001635 */ 
    1601 static int pjsip_tsx_on_state_proceeding_uac( pjsip_transaction *tsx, pjsip_event *event) 
     1636static pj_status_t pjsip_tsx_on_state_proceeding_uac(pjsip_transaction *tsx,  
     1637                                                     pjsip_event *event) 
    16021638{ 
    16031639 
     
    16111647        pj_assert(event->type == PJSIP_EVENT_RX_MSG); 
    16121648        if (event->type != PJSIP_EVENT_RX_MSG) { 
    1613             return 0; 
    1614         } 
    1615  
    1616         tsx->status_code = event->src.rdata->msg->line.status.code; 
     1649            return PJ_EINVALIDOP; 
     1650        } 
     1651 
     1652        tsx->status_code = event->body.rx_msg.rdata->msg->line.status.code; 
    16171653    } else { 
    16181654        tsx->status_code = PJSIP_SC_TSX_TIMEOUT; 
     
    16221658 
    16231659        /* Inform the message to TU. */ 
    1624         tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING, event); 
     1660        tsx_set_state( tsx, PJSIP_TSX_STATE_PROCEEDING,  
     1661                       PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
    16251662 
    16261663    } else if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code,200)) { 
     
    16331670         */ 
    16341671        if (tsx->method.id == PJSIP_INVITE_METHOD && tsx->handle_ack == 0) { 
    1635             tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
    1636             return -1; 
     1672            tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1673                           PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
     1674            return PJSIP_ETSXDESTROYED; 
    16371675 
    16381676        } else { 
     
    16501688                timeout.sec = timeout.msec = 0; 
    16511689            } 
    1652             pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &timeout); 
     1690            pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer,  
     1691                                        &timeout); 
    16531692 
    16541693            /* Move state to Completed, inform TU. */ 
    1655             tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED, event); 
     1694            tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED,  
     1695                           PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
    16561696        } 
    16571697 
    16581698    } else if (tsx->status_code >= 300 && tsx->status_code <= 699) { 
    16591699        pj_time_val timeout; 
     1700        pj_status_t status; 
    16601701 
    16611702        /* Stop timer B. */ 
     
    16641705        /* Generate and send ACK for INVITE. */ 
    16651706        if (tsx->method.id == PJSIP_INVITE_METHOD) { 
    1666             pjsip_endpt_create_ack( tsx->endpt, tsx->last_tx, event->src.rdata ); 
    1667             if (tsx_send_msg( tsx, tsx->last_tx) != 0) { 
    1668                 return -1; 
     1707            pjsip_endpt_create_ack( tsx->endpt, tsx->last_tx,  
     1708                                    event->body.rx_msg.rdata ); 
     1709            status = tsx_send_msg( tsx, tsx->last_tx); 
     1710            if (status != PJ_SUCCESS) { 
     1711                return status; 
    16691712            } 
    16701713        } 
     
    16831726 
    16841727        /* Inform TU. */ 
    1685         tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED, event); 
     1728        tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED,  
     1729                       PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
    16861730 
    16871731    } else { 
    16881732        // Shouldn't happen because there's no timer for this state. 
    16891733        pj_assert(0); 
     1734        return PJ_EBUG; 
    16901735    } 
    16911736 
     
    16961741 * Handler for events in Completed state for UAS 
    16971742 */ 
    1698 static int pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx, pjsip_event *event) 
     1743static pj_status_t pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx,  
     1744                                                     pjsip_event *event) 
    16991745{ 
    17001746    pj_assert(tsx->state == PJSIP_TSX_STATE_COMPLETED); 
    17011747 
    17021748    if (event->type == PJSIP_EVENT_RX_MSG) { 
    1703         pjsip_msg *msg = event->src.rdata->msg; 
     1749        pjsip_msg *msg = event->body.rx_msg.rdata->msg; 
    17041750        pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr( msg, PJSIP_H_CSEQ, NULL ); 
    17051751 
    17061752        /* On receive request retransmission, retransmit last response. */ 
    17071753        if (cseq->method.id != PJSIP_ACK_METHOD) { 
    1708             if (pjsip_tsx_retransmit( tsx, 0 ) != 0) { 
    1709                 return -1; 
     1754            pj_status_t status; 
     1755 
     1756            status = pjsip_tsx_retransmit( tsx, 0 ); 
     1757            if (status != PJ_SUCCESS) { 
     1758                return status; 
    17101759            } 
    17111760 
     
    17181767            /* Start timer I in T4 interval (transaction termination). */ 
    17191768            pjsip_endpt_cancel_timer( tsx->endpt, &tsx->timeout_timer ); 
    1720             pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &t4_timer_val); 
     1769            pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer,  
     1770                                        &t4_timer_val); 
    17211771 
    17221772            /* Move state to "Confirmed" */ 
    1723             tsx_set_state( tsx, PJSIP_TSX_STATE_CONFIRMED, event); 
     1773            tsx_set_state( tsx, PJSIP_TSX_STATE_CONFIRMED,  
     1774                           PJSIP_EVENT_RX_MSG, event->body.rx_msg.rdata ); 
    17241775        }        
    17251776 
    17261777    } else if (event->type == PJSIP_EVENT_TIMER) { 
    17271778 
    1728         if (event->src.timer == &tsx->retransmit_timer) { 
     1779        if (event->body.timer.entry == &tsx->retransmit_timer) { 
    17291780            /* Retransmit message. */ 
    1730             if (pjsip_tsx_retransmit( tsx, 1 ) != 0) { 
    1731                 return -1; 
     1781            pj_status_t status; 
     1782 
     1783            status = pjsip_tsx_retransmit( tsx, 1 ); 
     1784            if (status != PJ_SUCCESS) { 
     1785                return status; 
    17321786            } 
    17331787 
     
    17411795                tsx->status_code = PJSIP_SC_TSX_TIMEOUT; 
    17421796 
    1743                 tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
    1744  
    1745                 return -1; 
     1797                tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1798                               PJSIP_EVENT_TIMER, &tsx->timeout_timer ); 
     1799 
     1800                return PJSIP_ETSXDESTROYED; 
    17461801 
    17471802            } else { 
    17481803                /* Transaction terminated, it can now be deleted. */ 
    1749                 tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
    1750                 return -1; 
     1804                tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1805                               PJSIP_EVENT_TIMER, &tsx->timeout_timer ); 
     1806                return PJSIP_ETSXDESTROYED; 
    17511807            } 
    17521808        } 
     
    17541810    } else { 
    17551811        /* Ignore request to transmit. */ 
    1756         pj_assert(event->src.tdata == tsx->last_tx); 
     1812        pj_assert(event->body.tx_msg.tdata == tsx->last_tx); 
    17571813    } 
    17581814 
     
    17631819 * Handler for events in Completed state for UAC transaction. 
    17641820 */ 
    1765 static int pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, pjsip_event *event) 
     1821static pj_status_t pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, 
     1822                                                     pjsip_event *event) 
    17661823{ 
    17671824    pj_assert(tsx->state == PJSIP_TSX_STATE_COMPLETED); 
     
    17691826    if (event->type == PJSIP_EVENT_TIMER) { 
    17701827        /* Must be the timeout timer. */ 
    1771         pj_assert(event->src.timer == &tsx->timeout_timer); 
     1828        pj_assert(event->body.timer.entry == &tsx->timeout_timer); 
    17721829 
    17731830        /* Move to Terminated state. */ 
    1774         tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
     1831        tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1832                       PJSIP_EVENT_TIMER, event->body.timer.entry ); 
    17751833 
    17761834        /* Transaction has been destroyed. */ 
    1777         return -1; 
     1835        return PJSIP_ETSXDESTROYED; 
    17781836 
    17791837    } else if (event->type == PJSIP_EVENT_RX_MSG) { 
     
    17821840             * TU doesn't need to be informed. 
    17831841             */ 
    1784             pjsip_msg *msg = event->src.rdata->msg; 
     1842            pjsip_msg *msg = event->body.rx_msg.rdata->msg; 
    17851843            pj_assert(msg->type == PJSIP_RESPONSE_MSG); 
    17861844            if (msg->type==PJSIP_RESPONSE_MSG && 
    17871845                msg->line.status.code >= 200) 
    17881846            { 
    1789                 if (pjsip_tsx_retransmit( tsx, 0 ) != 0) { 
    1790                     return -1; 
     1847                pj_status_t status; 
     1848 
     1849                status = pjsip_tsx_retransmit( tsx, 0 ); 
     1850                if (status != PJ_SUCCESS) { 
     1851                    return status; 
    17911852                } 
    17921853            } else { 
     
    17991860    } else if (tsx->method.id == PJSIP_INVITE_METHOD && 
    18001861               event->type == PJSIP_EVENT_TX_MSG && 
    1801                event->src.tdata->msg->line.req.method.id == PJSIP_ACK_METHOD) { 
     1862               event->body.tx_msg.tdata->msg->line.req.method.id==PJSIP_ACK_METHOD) { 
     1863 
     1864        pj_status_t status; 
    18021865 
    18031866        /* Set last transmitted message. */ 
    1804         if (tsx->last_tx != event->src.tdata) { 
     1867        if (tsx->last_tx != event->body.tx_msg.tdata) { 
    18051868            pjsip_tx_data_dec_ref( tsx->last_tx ); 
    1806             tsx->last_tx = event->src.tdata; 
     1869            tsx->last_tx = event->body.tx_msg.tdata; 
    18071870            pjsip_tx_data_add_ref( tsx->last_tx ); 
    18081871        } 
     
    18111874         * Must notify now, so app has chance to put SDP in outgoing ACK msg. 
    18121875         */ 
    1813         tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED, event ); 
     1876        tsx_set_state( tsx, PJSIP_TSX_STATE_COMPLETED,  
     1877                       PJSIP_EVENT_TX_MSG, event->body.tx_msg.tdata ); 
    18141878 
    18151879        /* Send msg */ 
    1816         tsx_send_msg(tsx, event->src.tdata); 
     1880        status = tsx_send_msg(tsx, event->body.tx_msg.tdata); 
     1881        if (status != PJ_SUCCESS) 
     1882            return status; 
    18171883 
    18181884    } else { 
    18191885        pj_assert(0); 
    1820     } 
    1821  
    1822     return 0; 
     1886        return PJ_EBUG; 
     1887    } 
     1888 
     1889    return PJ_SUCCESS; 
    18231890} 
    18241891 
     
    18261893 * Handler for events in state Confirmed. 
    18271894 */ 
    1828 static int pjsip_tsx_on_state_confirmed( pjsip_transaction *tsx, pjsip_event *event) 
     1895static pj_status_t pjsip_tsx_on_state_confirmed( pjsip_transaction *tsx, 
     1896                                                 pjsip_event *event) 
    18291897{ 
    18301898    pj_assert(tsx->state == PJSIP_TSX_STATE_CONFIRMED); 
     
    18361904    /* Absorb any ACK received. */ 
    18371905    if (event->type == PJSIP_EVENT_RX_MSG) { 
     1906 
     1907        pjsip_method_e method_id =  
     1908            event->body.rx_msg.rdata->msg->line.req.method.id; 
     1909 
    18381910        /* Must be a request message. */ 
    1839         pj_assert(event->src.rdata->msg->type == PJSIP_REQUEST_MSG); 
     1911        pj_assert(event->body.rx_msg.rdata->msg->type == PJSIP_REQUEST_MSG); 
    18401912 
    18411913        /* Must be an ACK request or a late INVITE retransmission. */ 
    1842         pj_assert(event->src.rdata->msg->line.req.method.id == PJSIP_ACK_METHOD || 
    1843                   event->src.rdata->msg->line.req.method.id == PJSIP_INVITE_METHOD); 
     1914        pj_assert(method_id == PJSIP_ACK_METHOD || 
     1915                  method_id == PJSIP_INVITE_METHOD); 
     1916 
     1917        /* Just so that compiler won't complain about unused vars when 
     1918         * building release code. 
     1919         */ 
     1920        PJ_UNUSED_ARG(method_id); 
    18441921 
    18451922    } else if (event->type == PJSIP_EVENT_TIMER) { 
    18461923        /* Must be from timeout_timer_. */ 
    1847         pj_assert(event->src.timer == &tsx->timeout_timer); 
     1924        pj_assert(event->body.timer.entry == &tsx->timeout_timer); 
    18481925 
    18491926        /* Move to Terminated state. */ 
    1850         tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED, event); 
     1927        tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,  
     1928                       PJSIP_EVENT_TIMER, &tsx->timeout_timer ); 
    18511929 
    18521930        /* Transaction has been destroyed. */ 
    1853         return -1; 
     1931        return PJSIP_ETSXDESTROYED; 
    18541932 
    18551933    } else { 
    18561934        pj_assert(0); 
     1935        return PJ_EBUG; 
    18571936    } 
    18581937 
     
    18631942 * Handler for events in state Terminated. 
    18641943 */ 
    1865 static int pjsip_tsx_on_state_terminated( pjsip_transaction *tsx, pjsip_event *event) 
     1944static pj_status_t pjsip_tsx_on_state_terminated( pjsip_transaction *tsx, 
     1945                                                  pjsip_event *event) 
    18661946{ 
    18671947    pj_assert(tsx->state == PJSIP_TSX_STATE_TERMINATED); 
    18681948 
    1869     PJ_UNUSED_ARG(event) 
     1949    PJ_UNUSED_ARG(event); 
    18701950 
    18711951    /* Destroy this transaction */ 
    1872     tsx_set_state(tsx, PJSIP_TSX_STATE_DESTROYED, event); 
     1952    tsx_set_state(tsx, PJSIP_TSX_STATE_DESTROYED,  
     1953                  event->type, event->body.user.user1 ); 
    18731954 
    18741955    return PJ_SUCCESS; 
     
    18761957 
    18771958 
    1878 static int pjsip_tsx_on_state_destroyed( pjsip_transaction *tsx, pjsip_event *event) 
    1879 { 
    1880     PJ_UNUSED_ARG(tsx) 
    1881     PJ_UNUSED_ARG(event) 
     1959static pj_status_t pjsip_tsx_on_state_destroyed(pjsip_transaction *tsx, 
     1960                                                pjsip_event *event) 
     1961{ 
     1962    PJ_UNUSED_ARG(tsx); 
     1963    PJ_UNUSED_ARG(event); 
    18821964    return PJ_SUCCESS; 
    18831965} 
  • pjproject/main/pjsip/src/pjsip/sip_transport.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_transport.h> 
     
    76#include <pjsip/sip_msg.h> 
    87#include <pjsip/sip_private.h> 
     8#include <pjsip/sip_errno.h> 
    99#include <pj/os.h> 
    1010#include <pj/log.h> 
     
    1313#include <pj/string.h> 
    1414#include <pj/pool.h> 
     15#include <pj/assert.h> 
    1516 
    1617#define MGR_IDLE_CHECK_INTERVAL 30 
     
    4546     *  listener list.  
    4647     */ 
    47     PJ_DECL_LIST_MEMBER(struct pjsip_transport_t) 
     48    PJ_DECL_LIST_MEMBER(struct pjsip_transport_t); 
    4849 
    4950    /** Transport's pool. */ 
     
    6768    /** I/O Queue key */ 
    6869    pj_ioqueue_key_t    *key; 
     70 
     71    /** Accept key. */ 
     72    pj_ioqueue_op_key_t  accept_op; 
    6973 
    7074    /** Receive data buffer */ 
     
    116120    pj_ioqueue_t    *ioqueue; 
    117121    pj_time_val      next_idle_check; 
     122    pj_size_t        send_buf_size; 
     123    pj_size_t        recv_buf_size; 
    118124    void           (*message_callback)(pjsip_endpoint*, pjsip_rx_data *rdata); 
    119125}; 
     
    145151struct transport_callback 
    146152{ 
    147     PJ_DECL_LIST_MEMBER(struct transport_callback) 
     153    PJ_DECL_LIST_MEMBER(struct transport_callback); 
    148154 
    149155    /** User defined token to be passed to the callback. */ 
     
    174180}; 
    175181 
    176 static void on_ioqueue_read(pj_ioqueue_key_t *key, pj_ssize_t bytes_read); 
    177 static void on_ioqueue_write(pj_ioqueue_key_t *key, pj_ssize_t bytes_sent); 
    178 static void on_ioqueue_accept(pj_ioqueue_key_t *key, int status); 
    179 static void on_ioqueue_connect(pj_ioqueue_key_t *key, int status); 
     182static void on_ioqueue_read(pj_ioqueue_key_t *key,  
     183                            pj_ioqueue_op_key_t *op_key,  
     184                            pj_ssize_t bytes_read); 
     185static void on_ioqueue_write(pj_ioqueue_key_t *key,  
     186                             pj_ioqueue_op_key_t *op_key,  
     187                             pj_ssize_t bytes_sent); 
     188static void on_ioqueue_accept(pj_ioqueue_key_t *key,  
     189                              pj_ioqueue_op_key_t *op_key,  
     190                              pj_sock_t newsock, 
     191                              int status); 
     192static void on_ioqueue_connect(pj_ioqueue_key_t *key,  
     193                               int status); 
    180194 
    181195static pj_ioqueue_callback ioqueue_transport_callback =  
     
    195209    key->type = (pj_uint8_t)tr->type; 
    196210    key->zero = 0; 
    197     key->addr = pj_sockaddr_get_addr(&tr->remote_addr); 
    198     key->port = pj_sockaddr_get_port(&tr->remote_addr); 
     211    key->addr = pj_sockaddr_in_get_addr(&tr->remote_addr).s_addr; 
     212    key->port = pj_sockaddr_in_get_port(&tr->remote_addr); 
    199213    /* 
    200214    if (key->port == 0) { 
    201         key->port = pj_sockaddr_get_port(&tr->local_addr); 
     215        key->port = pj_sockaddr_in_get_port(&tr->local_addr); 
    202216    } 
    203217    */ 
     
    213227    key->type = (pj_uint8_t)type; 
    214228    key->zero = 0; 
    215     key->addr = pj_sockaddr_get_addr(addr); 
    216     key->port = pj_sockaddr_get_port(addr); 
     229    key->addr = pj_sockaddr_in_get_addr(addr).s_addr; 
     230    key->port = pj_sockaddr_in_get_port(addr); 
    217231} 
    218232#endif 
     
    221235                          const pj_sockaddr_in *addr) 
    222236{ 
    223     PJ_UNUSED_ARG(addr) 
     237    PJ_UNUSED_ARG(addr); 
    224238 
    225239    /* This is to detect alignment problems. */ 
     
    237251        pj_sockaddr_in addr; 
    238252        pj_sockaddr_set_str_addr(&addr, &localaddr); 
    239         key->addr = pj_sockaddr_get_addr(&addr); 
     253        key->addr = pj_sockaddr_in_get_addr(&addr); 
    240254    } 
    241255#endif 
     
    298312 * Create new transmit buffer. 
    299313 */ 
    300 pjsip_tx_data* pjsip_tx_data_create( pjsip_transport_mgr *mgr ) 
     314pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr, 
     315                                  pjsip_tx_data **p_tdata ) 
    301316{ 
    302317    pj_pool_t *pool; 
    303318    pjsip_tx_data *tdata; 
     319    pj_status_t status; 
    304320 
    305321    PJ_LOG(5, ("", "pjsip_tx_data_create")); 
     322 
     323    PJ_ASSERT_RETURN(mgr && p_tdata, PJ_EINVAL); 
    306324 
    307325    pool = pjsip_endpt_create_pool( mgr->endpt, "ptdt%p", 
     
    309327                                    PJSIP_POOL_INC_TDATA ); 
    310328    if (!pool) { 
    311         return NULL; 
     329        return PJ_ENOMEM; 
    312330    } 
    313331    tdata = pj_pool_calloc(pool, 1, sizeof(pjsip_tx_data)); 
    314332    tdata->pool = pool; 
    315333    tdata->mgr = mgr; 
    316     sprintf(tdata->obj_name,"txd%p", tdata); 
    317  
    318     tdata->ref_cnt = pj_atomic_create(tdata->pool, 0); 
    319     if (!tdata->ref_cnt) { 
     334    pj_sprintf(tdata->obj_name,"txd%p", tdata); 
     335 
     336    status = pj_atomic_create(tdata->pool, 0, &tdata->ref_cnt); 
     337    if (status != PJ_SUCCESS) { 
    320338        pjsip_endpt_destroy_pool( mgr->endpt, tdata->pool ); 
    321         return NULL; 
     339        return status; 
    322340    } 
    323341     
    324     return tdata; 
     342    *p_tdata = tdata; 
     343    return PJ_SUCCESS; 
    325344} 
    326345 
     
    340359{ 
    341360    pj_assert( pj_atomic_get(tdata->ref_cnt) > 0); 
    342     if (pj_atomic_dec(tdata->ref_cnt) <= 0) { 
     361    if (pj_atomic_dec_and_get(tdata->ref_cnt) <= 0) { 
    343362        PJ_LOG(6,(tdata->obj_name, "destroying txdata")); 
    344363        pj_atomic_destroy( tdata->ref_cnt ); 
     
    376395    } else  
    377396#else 
    378     PJ_UNUSED_ARG(flag) 
     397    PJ_UNUSED_ARG(flag); 
    379398#endif 
    380399    { 
     
    453472{ 
    454473    pj_assert(tr->ref_cnt > 0); 
    455     if (pj_atomic_dec(tr->ref_cnt) == 0) { 
     474    if (pj_atomic_dec_and_get(tr->ref_cnt) == 0) { 
    456475        pj_gettimeofday(&tr->close_time); 
    457476        tr->close_time.sec += PJSIP_TRANSPORT_CLOSE_TIMEOUT; 
     
    462481 * Open the underlying transport. 
    463482 */ 
    464 static pj_sock_t create_socket( pjsip_transport_type_e type, 
    465                                 pj_sockaddr_in *local ) 
     483static pj_status_t create_socket( pjsip_transport_type_e type, 
     484                                  pj_sockaddr_in *local, 
     485                                  pj_sock_t *p_sock) 
    466486{ 
    467487    int sock_family; 
     
    469489    int sock_proto; 
    470490    int len; 
     491    pj_status_t status; 
    471492    pj_sock_t sock; 
    472493 
     
    484505#endif 
    485506    } else { 
    486         PJ_LOG(2,("", "create_socket: unsupported transport type %s", 
    487                   get_type_name(type))); 
    488         return PJ_INVALID_SOCKET; 
     507        return PJ_EINVAL; 
    489508    } 
    490509 
    491510    /* Create socket. */ 
    492     sock = pj_sock_socket( sock_family, sock_type, sock_proto, PJ_SOCK_ASYNC); 
    493     if (sock == PJ_INVALID_SOCKET) { 
    494         PJ_PERROR((THIS_FILE, "%s socket()", get_type_name(type))); 
    495         return PJ_INVALID_SOCKET; 
    496     } 
     511    status = pj_sock_socket( sock_family, sock_type, sock_proto, &sock); 
     512    if (status != PJ_SUCCESS) 
     513        return status; 
    497514 
    498515    /* Bind the socket to the requested address, or if no address is 
     
    501518    if (/*local->sin_addr.s_addr != 0 &&*/ local->sin_port != 0) { 
    502519        /* Bind to the requested address. */ 
    503         if (pj_sock_bind(sock, local, sizeof(*local)) != 0) { 
    504             PJ_PERROR((THIS_FILE, "bind() to %s %s:%d", 
    505                                   get_type_name(type), 
    506                                   pj_sockaddr_get_str_addr(local), 
    507                                   pj_sockaddr_get_port(local))); 
     520        status = pj_sock_bind(sock, local, sizeof(*local)); 
     521        if (status != PJ_SUCCESS) { 
    508522            pj_sock_close(sock); 
    509             return PJ_INVALID_SOCKET; 
     523            return status; 
    510524        } 
    511525    } else if (type == PJSIP_TRANSPORT_UDP) { 
     
    517531        pj_memset(local, 0, sizeof(*local)); 
    518532        local->sin_family = PJ_AF_INET; 
    519         if (pj_sock_bind(sock, local, sizeof(*local)) != 0) { 
    520             PJ_PERROR((THIS_FILE, "bind() to %s 0.0.0.0:0", get_type_name(type))); 
     533        status = pj_sock_bind(sock, local, sizeof(*local)); 
     534        if (status != PJ_SUCCESS) { 
    521535            pj_sock_close(sock); 
    522             return PJ_INVALID_SOCKET; 
     536            return status; 
    523537        } 
    524538 
    525539        /* Get the local address. */ 
    526540        len = sizeof(pj_sockaddr_in); 
    527         if (pj_sock_getsockname(sock, local, &len)) { 
    528             PJ_PERROR((THIS_FILE, "getsockname()")); 
     541        status = pj_sock_getsockname(sock, local, &len); 
     542        if (status != PJ_SUCCESS) { 
    529543            pj_sock_close(sock); 
    530             return -1; 
    531         } 
    532     } 
    533  
    534     return sock; 
     544            return status; 
     545        } 
     546    } 
     547 
     548    *p_sock = sock; 
     549    return PJ_SUCCESS; 
    535550} 
    536551 
     
    548563 * Create a new transport object. 
    549564 */ 
    550 static pjsip_transport_t* create_transport( pjsip_transport_mgr *mgr, 
    551                                             pjsip_transport_type_e type, 
    552                                             pj_sock_t sock_hnd, 
    553                                             const pj_sockaddr_in *local_addr, 
    554                                             const pj_sockaddr_in *addr_name) 
     565static pj_status_t create_transport( pjsip_transport_mgr *mgr, 
     566                                     pjsip_transport_type_e type, 
     567                                     pj_sock_t sock_hnd, 
     568                                     const pj_sockaddr_in *local_addr, 
     569                                     const pj_sockaddr_in *addr_name, 
     570                                     pjsip_transport_t **p_transport ) 
    555571{ 
    556572    pj_pool_t *tr_pool=NULL, *rdata_pool=NULL; 
    557573    pjsip_transport_t *tr = NULL; 
     574    pj_status_t status; 
    558575 
    559576    /* Allocate pool for transport from endpoint. */ 
     
    563580                                       PJSIP_POOL_INC_TRANSPORT ); 
    564581    if (!tr_pool) { 
     582        status = PJ_ENOMEM; 
    565583        goto on_error; 
    566584    } 
     
    572590                                             PJSIP_POOL_INC_RDATA ); 
    573591    if (!rdata_pool) { 
     592        status = PJ_ENOMEM; 
    574593        goto on_error; 
    575594    } 
     
    583602    pj_memcpy(&tr->local_addr, local_addr, sizeof(pj_sockaddr_in)); 
    584603    pj_list_init(&tr->cb_list); 
    585     sprintf(tr->obj_name, transport_get_name_format(type), tr); 
     604    pj_sprintf(tr->obj_name, transport_get_name_format(type), tr); 
    586605 
    587606    if (type != PJSIP_TRANSPORT_UDP) { 
     
    596615 
    597616    /* Create atomic */ 
    598     tr->ref_cnt = pj_atomic_create(tr_pool, 0); 
    599     if (!tr->ref_cnt) { 
     617    status = pj_atomic_create(tr_pool, 0, &tr->ref_cnt); 
     618    if (status != PJ_SUCCESS) 
    600619        goto on_error; 
    601     } 
    602620     
    603621    /* Init rdata in the transport. */ 
     
    608626     
    609627    /* Init transport mutex. */ 
    610     tr->tr_mutex = pj_mutex_create(tr_pool, "mtr%p", 0); 
    611     if (!tr->tr_mutex) { 
    612         PJ_PERROR((tr->obj_name, "pj_mutex_create()")); 
     628    status = pj_mutex_create_recursive(tr_pool, "mtr%p", &tr->tr_mutex); 
     629    if (status != PJ_SUCCESS) 
    613630        goto on_error; 
    614     } 
    615631 
    616632    /* Register to I/O Queue */ 
    617     tr->key = pj_ioqueue_register(tr_pool, mgr->ioqueue,  
    618                                   (pj_oshandle_t)tr->sock, tr, 
    619                                   &ioqueue_transport_callback); 
    620     if (tr->key == NULL) { 
    621         PJ_PERROR((tr->obj_name, "pj_ioqueue_register()")); 
     633    status = pj_ioqueue_register_sock( tr_pool, mgr->ioqueue,  
     634                                       tr->sock, tr, 
     635                                       &ioqueue_transport_callback, 
     636                                       &tr->key); 
     637    if (status != PJ_SUCCESS) 
    622638        goto on_error; 
    623     } 
    624  
    625     return tr; 
     639 
     640    *p_transport = tr; 
     641    return PJ_SUCCESS; 
    626642 
    627643on_error: 
     
    635651        pjsip_endpt_destroy_pool(mgr->endpt, rdata_pool); 
    636652    } 
    637     return NULL; 
     653    return status; 
    638654} 
    639655 
     
    641657 * Destroy transport. 
    642658 */ 
    643 static void destroy_transport( pjsip_transport_mgr *mgr, pjsip_transport_t *tr ) 
     659static void destroy_transport( pjsip_transport_mgr *mgr, pjsip_transport_t *tr) 
    644660{ 
    645661    transport_key hash_key; 
    646662 
    647663    /* Remove from I/O queue. */ 
    648     pj_ioqueue_unregister( mgr->ioqueue, tr->key ); 
     664    pj_ioqueue_unregister( tr->key ); 
    649665 
    650666    /* Remove from hash table */ 
     
    669685 
    670686 
    671 static int transport_send_msg( pjsip_transport_t *tr, pjsip_tx_data *tdata, 
    672                                const pj_sockaddr_in *addr) 
     687static pj_status_t transport_send_msg( pjsip_transport_t *tr,  
     688                                       pjsip_tx_data *tdata, 
     689                                       const pj_sockaddr_in *addr,  
     690                                       pj_ssize_t *p_sent) 
    673691{ 
    674692    const char *buf = tdata->buf.start; 
    675     int sent; 
    676     int len; 
     693    pj_ssize_t size; 
     694    pj_status_t status; 
     695 
     696    /* Can only send if tdata is not being sent! */ 
     697    if (pj_ioqueue_is_pending(tr->key, &tdata->op_key)) 
     698        return PJSIP_EPENDINGTX; 
    677699 
    678700    /* Allocate buffer if necessary. */ 
     
    685707    /* Print the message if it's not printed */ 
    686708    if (tdata->buf.cur <= tdata->buf.start) { 
    687         len = pjsip_msg_print(tdata->msg, tdata->buf.start,  
    688                               tdata->buf.end - tdata->buf.start); 
    689         if (len < 1) { 
    690             return len; 
    691         } 
    692         tdata->buf.cur += len; 
    693         tdata->buf.cur[len] = '\0'; 
    694     } 
    695  
    696     /* BUG BUG BUG */ 
    697     /* MUST CHECK THAT THE SOCKET IS READY TO SEND (IOQueue)! */ 
    698     PJ_TODO(BUG_BUG_BUG___SENDING_DATAGRAM_WHILE_SOCKET_IS_PENDING__) 
     709        size = pjsip_msg_print( tdata->msg, tdata->buf.start,  
     710                                tdata->buf.end - tdata->buf.start); 
     711        if (size < 0) { 
     712            return PJSIP_EMSGTOOLONG; 
     713        } 
     714        pj_assert(size != 0); 
     715        tdata->buf.cur += size; 
     716        tdata->buf.cur[size] = '\0'; 
     717    } 
    699718 
    700719    /* Send the message. */ 
    701720    buf = tdata->buf.start; 
    702     len = tdata->buf.cur - tdata->buf.start; 
     721    size = tdata->buf.cur - tdata->buf.start; 
    703722 
    704723    if (tr->type == PJSIP_TRANSPORT_UDP) { 
     
    707726                  "%s" 
    708727                  "------------ end msg -------------", 
    709                   pj_sockaddr_get_str_addr(addr),  
    710                   pj_sockaddr_get_port(addr), 
    711                   len, buf)); 
    712  
    713         sent = pj_ioqueue_sendto( tr->mgr->ioqueue, tr->key, 
    714                                   buf, len, addr, sizeof(*addr)); 
     728                  pj_inet_ntoa(addr->sin_addr),  
     729                  pj_sockaddr_in_get_port(addr), 
     730                  size, buf)); 
     731 
     732        status = pj_ioqueue_sendto( tr->key, &tdata->op_key, 
     733                                    buf, &size, 0, addr, sizeof(*addr)); 
    715734    }  
    716735#if PJ_HAS_TCP 
     
    720739                  "%s" 
    721740                  "------------ end msg -------------", 
    722                   len, buf)); 
    723  
    724         sent = pj_ioqueue_write (tr->mgr->ioqueue, tr->key, buf, len); 
     741                  size, buf)); 
     742 
     743        status = pj_ioqueue_send(tr->key, &tdata->op_key, buf, &size, 0); 
    725744    } 
    726745#else 
    727746    else { 
    728         pj_assert(0); 
    729         sent = -1; 
     747        pj_assert(!"Unsupported transport"); 
     748        status = PJSIP_EUNSUPTRANSPORT; 
    730749    } 
    731750#endif 
    732751 
    733     if (sent == len || sent == PJ_IOQUEUE_PENDING) { 
    734         return len; 
    735     } 
    736  
    737     /* On error, clear the flag. */ 
    738     PJ_PERROR((tr->obj_name, tr->type == PJSIP_TRANSPORT_UDP ? "pj_ioqueue_sendto()" : "pj_ioqueue_write()")); 
    739     return -1; 
     752    *p_sent = size; 
     753    return status; 
    740754} 
    741755 
     
    744758 * in the outgoing data. 
    745759 */ 
    746 PJ_DEF(int) pjsip_transport_send_msg( pjsip_transport_t *tr,  
    747                                       pjsip_tx_data *tdata, 
    748                                       const pj_sockaddr_in *addr) 
    749 { 
    750     int sent; 
    751  
     760PJ_DEF(pj_status_t) pjsip_transport_send_msg( pjsip_transport_t *tr, 
     761                                              pjsip_tx_data *tdata, 
     762                                              const pj_sockaddr_in *addr, 
     763                                              pj_ssize_t *sent) 
     764{ 
    752765    PJ_LOG(5, (tr->obj_name, "pjsip_transport_send_msg(tdata=%s)", tdata->obj_name)); 
    753766 
    754     sent = transport_send_msg(tr, tdata, addr ); 
    755     return sent; 
     767    return transport_send_msg(tr, tdata, addr, sent ); 
    756768} 
    757769 
     
    761773 * Create a new transport manager. 
    762774 */ 
    763 PJ_DEF(pjsip_transport_mgr*)  
    764 pjsip_transport_mgr_create( pj_pool_t *pool, 
    765                             pjsip_endpoint * endpt, 
    766                             void (*cb)(pjsip_endpoint*,pjsip_rx_data *) ) 
     775PJ_DEF(pj_status_t) pjsip_transport_mgr_create( pj_pool_t *pool, 
     776                                                pjsip_endpoint * endpt, 
     777                                                void (*cb)(pjsip_endpoint*, 
     778                                                           pjsip_rx_data *), 
     779                                                pjsip_transport_mgr **p_mgr) 
    767780{ 
    768781    pjsip_transport_mgr *mgr; 
     782    pj_status_t status; 
    769783 
    770784    PJ_LOG(5, (LOG_TRANSPORT_MGR, "pjsip_transport_mgr_create()")); 
     
    773787    mgr->endpt = endpt; 
    774788    mgr->message_callback = cb; 
    775      
     789    mgr->send_buf_size = DEFAULT_SO_SNDBUF; 
     790    mgr->recv_buf_size = DEFAULT_SO_RCVBUF; 
     791 
    776792    mgr->transport_table = pj_hash_create(pool, MGR_HASH_TABLE_SIZE); 
    777793    if (!mgr->transport_table) { 
    778         PJ_LOG(3, (LOG_TRANSPORT_MGR, "error creating transport manager hash table")); 
    779         return NULL; 
    780     } 
    781     mgr->ioqueue = pj_ioqueue_create(pool, PJSIP_MAX_TRANSPORTS); 
    782     if (!mgr->ioqueue) { 
    783         PJ_LOG(3, (LOG_TRANSPORT_MGR, "error creating IO queue")); 
    784         return NULL; 
    785     } 
    786     mgr->mutex = pj_mutex_create(pool, "tmgr%p", 0); 
    787     if (!mgr->mutex) { 
    788         PJ_LOG(3, (LOG_TRANSPORT_MGR, "error creating mutex")); 
     794        return PJ_ENOMEM; 
     795    } 
     796    status = pj_ioqueue_create(pool, PJSIP_MAX_TRANSPORTS, &mgr->ioqueue); 
     797    if (status != PJ_SUCCESS) { 
     798        return status; 
     799    } 
     800    status = pj_mutex_create_recursive(pool, "tmgr%p", &mgr->mutex); 
     801    if (status != PJ_SUCCESS) { 
    789802        pj_ioqueue_destroy(mgr->ioqueue); 
    790         return NULL; 
     803        return status; 
    791804    } 
    792805    pj_gettimeofday(&mgr->next_idle_check); 
    793806    mgr->next_idle_check.sec += MGR_IDLE_CHECK_INTERVAL; 
    794     return mgr; 
     807 
     808    *p_mgr = mgr; 
     809    return status; 
    795810} 
    796811 
     
    798813 * Destroy transport manager. 
    799814 */ 
    800 PJ_DEF(void) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ) 
     815PJ_DEF(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ) 
    801816{ 
    802817    pj_hash_iterator_t itr_val; 
     
    824839 
    825840    pj_mutex_unlock(mgr->mutex); 
     841 
     842    return PJ_SUCCESS; 
    826843} 
    827844 
     
    837854    pjsip_transport_t *tr; 
    838855    struct transport_key *hash_key; 
    839     int opt_val; 
    840  
    841     opt_val = DEFAULT_SO_SNDBUF; 
    842     if (pj_sock_setsockopt( sock_hnd, SOL_SOCKET, SO_SNDBUF, &opt_val, sizeof(opt_val)) != PJ_SUCCESS) { 
    843         PJ_LOG(3, (LOG_TRANSPORT_MGR, "create listener: error setting SNDBUF to %d", DEFAULT_SO_SNDBUF)); 
    844         // Just ignore the error. 
    845     } 
    846  
    847     opt_val = DEFAULT_SO_RCVBUF; 
    848     if (pj_sock_setsockopt( sock_hnd, SOL_SOCKET, SO_RCVBUF, &opt_val, sizeof(opt_val)) != PJ_SUCCESS) { 
    849         PJ_LOG(3, (LOG_TRANSPORT_MGR, "create listener: error setting RCVBUF to %d", DEFAULT_SO_SNDBUF)); 
    850         // Just ignore the error 
    851     } 
    852  
    853     tr = create_transport(mgr, type, sock_hnd, local_addr, addr_name); 
    854     if (!tr) { 
     856    const pj_str_t loopback_addr = { "127.0.0.1", 9 }; 
     857    pj_status_t status; 
     858 
     859    if (mgr->send_buf_size != 0) { 
     860        int opt_val = mgr->send_buf_size; 
     861        status = pj_sock_setsockopt( sock_hnd, PJ_SOL_SOCKET,  
     862                                     PJ_SO_SNDBUF,  
     863                                     &opt_val, sizeof(opt_val)); 
     864 
     865        if (status != PJ_SUCCESS) { 
     866            return status; 
     867        } 
     868    } 
     869 
     870    if (mgr->recv_buf_size != 0) { 
     871        int opt_val = mgr->recv_buf_size; 
     872        status = pj_sock_setsockopt( sock_hnd, PJ_SOL_SOCKET,  
     873                                     PJ_SO_RCVBUF,  
     874                                     &opt_val, sizeof(opt_val)); 
     875        if (status != PJ_SUCCESS) { 
     876            return status; 
     877        } 
     878    } 
     879 
     880    status = create_transport(mgr, type, sock_hnd, local_addr, addr_name, &tr); 
     881    if (status != PJ_SUCCESS) { 
    855882        pj_sock_close(sock_hnd); 
    856         return -1; 
     883        return status; 
    857884    } 
    858885#if PJ_HAS_TCP 
    859886    if (type == PJSIP_TRANSPORT_TCP) { 
    860         pj_status_t status; 
    861  
    862         if (pj_sock_listen(tr->sock, BACKLOG) != 0) { 
    863             PJ_PERROR((tr->obj_name, "listen()")); 
     887 
     888        status = pj_sock_listen(tr->sock, BACKLOG); 
     889        if (status != 0) { 
    864890            destroy_transport(mgr, tr); 
    865             return -1; 
    866         } 
    867         tr->accept_data.addrlen = sizeof(tr->accept_data.local); 
    868         status = pj_ioqueue_accept(mgr->ioqueue, tr->key,  
    869                                    &tr->accept_data.sock,  
    870                                    &tr->accept_data.local,  
    871                                    &tr->accept_data.remote, 
    872                                    &tr->accept_data.addrlen); 
    873         if (status != PJ_IOQUEUE_PENDING) { 
    874             PJ_PERROR((tr->obj_name, "pj_ioqueue_accept()")); 
    875             destroy_transport(mgr, tr); 
    876             return -1; 
    877         } 
     891            return status; 
     892        } 
     893         
     894        /* Discard immediate connections. */ 
     895        do { 
     896            tr->accept_data.addrlen = sizeof(tr->accept_data.local); 
     897            status = pj_ioqueue_accept(tr->key, &tr->accept_op, 
     898                                       &tr->accept_data.sock,  
     899                                       &tr->accept_data.local,  
     900                                       &tr->accept_data.remote, 
     901                                       &tr->accept_data.addrlen); 
     902            if (status==PJ_SUCCESS) { 
     903                pj_sock_close(tr->accept_data.sock); 
     904            } else if (status != PJ_EPENDING) { 
     905                destroy_transport(mgr, tr); 
     906                return status; 
     907            } 
     908        } while (status==PJ_SUCCESS); 
    878909 
    879910    } else  
    880911#endif 
    881912    if (type == PJSIP_TRANSPORT_UDP) { 
    882         pj_status_t status; 
    883  
    884         tr->rdata->addr_len = sizeof(tr->rdata->addr); 
    885         status = pj_ioqueue_recvfrom( mgr->ioqueue, tr->key,  
    886                                       tr->rdata->packet, PJSIP_MAX_PKT_LEN, 
    887                                       &tr->rdata->addr,  
    888                                       &tr->rdata->addr_len); 
    889         if (status != PJ_IOQUEUE_PENDING) { 
    890             PJ_PERROR((tr->obj_name, "pj_ioqueue_recvfrom()")); 
    891             destroy_transport(mgr, tr); 
    892             return -1; 
    893         } 
     913        pj_ssize_t bytes; 
     914 
     915        /* Discard immediate data. */ 
     916        do { 
     917            tr->rdata->addr_len = sizeof(tr->rdata->addr); 
     918            bytes = PJSIP_MAX_PKT_LEN; 
     919            status = pj_ioqueue_recvfrom( tr->key, &tr->rdata->op_key, 
     920                                          tr->rdata->packet, &bytes, 0, 
     921                                          &tr->rdata->addr,  
     922                                          &tr->rdata->addr_len); 
     923            if (status == PJ_SUCCESS) { 
     924                ; 
     925            } else if (status != PJ_EPENDING) { 
     926                destroy_transport(mgr, tr); 
     927                return status; 
     928            } 
     929        } while (status == PJ_SUCCESS); 
    894930    } 
    895931 
     
    902938     * See further comments on struct pjsip_transport_t definition. 
    903939     */ 
    904     if (type == PJSIP_TRANSPORT_UDP && local_addr->sin_addr.s_addr == inet_addr("127.0.0.1")) { 
     940    if (type == PJSIP_TRANSPORT_UDP &&  
     941        local_addr->sin_addr.s_addr == pj_inet_addr(&loopback_addr).s_addr) 
     942    { 
    905943        pj_str_t localaddr = pj_str("127.0.0.1"); 
    906         pj_sockaddr_set_str_addr( &tr->remote_addr, &localaddr); 
     944        pj_sockaddr_in_set_str_addr( &tr->remote_addr, &localaddr); 
    907945    } 
    908946    hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); 
     
    910948 
    911949    pj_mutex_lock(mgr->mutex); 
    912     pj_hash_set(tr->pool, mgr->transport_table, hash_key, sizeof(transport_key), tr); 
     950    pj_hash_set(tr->pool, mgr->transport_table,  
     951                hash_key, sizeof(transport_key), tr); 
    913952    pj_mutex_unlock(mgr->mutex); 
    914953 
    915954    PJ_LOG(4,(tr->obj_name, "Listening at %s %s:%d",  
    916955                         get_type_name(tr->type),  
    917                          pj_sockaddr_get_str_addr(&tr->local_addr), 
    918                          pj_sockaddr_get_port(&tr->local_addr))); 
     956                         pj_inet_ntoa(tr->local_addr.sin_addr), 
     957                         pj_sockaddr_in_get_port(&tr->local_addr))); 
    919958    PJ_LOG(4,(tr->obj_name, "Listener public address is at %s %s:%d",  
    920959                         get_type_name(tr->type),  
    921                          pj_sockaddr_get_str_addr(&tr->addr_name), 
    922                          pj_sockaddr_get_port(&tr->addr_name))); 
     960                         pj_inet_ntoa(tr->addr_name.sin_addr), 
     961                         pj_sockaddr_in_get_port(&tr->addr_name))); 
    923962    return PJ_SUCCESS; 
    924963} 
     
    933972{ 
    934973    pj_sock_t sock_hnd; 
     974    pj_status_t status; 
    935975 
    936976    PJ_LOG(5, (LOG_TRANSPORT_MGR, "pjsip_create_listener(type=%d)", type)); 
    937977 
    938     sock_hnd = create_socket(type, local_addr); 
    939     if (sock_hnd == PJ_INVALID_SOCKET) { 
    940         return -1; 
     978    status = create_socket(type, local_addr, &sock_hnd); 
     979    if (status != PJ_SUCCESS) { 
     980        return status; 
    941981    } 
    942982 
     
    952992{ 
    953993    pj_sockaddr_in local_addr; 
     994    pj_status_t status; 
    954995    int addrlen = sizeof(local_addr); 
    955996 
    956     if (pj_sock_getsockname(sock, (pj_sockaddr_t*)&local_addr, &addrlen) != 0) 
    957         return -1; 
    958  
    959     return create_listener(mgr, PJSIP_TRANSPORT_UDP, sock, &local_addr, addr_name); 
     997    status = pj_sock_getsockname(sock, (pj_sockaddr_t*)&local_addr, &addrlen); 
     998    if (status != PJ_SUCCESS) 
     999        return status; 
     1000 
     1001    return create_listener(mgr, PJSIP_TRANSPORT_UDP, sock,  
     1002                           &local_addr, addr_name); 
    9601003} 
    9611004 
     
    9741017    pjsip_transport_t *tr; 
    9751018    pj_sockaddr_in local; 
    976     int sock_hnd; 
     1019    pj_sock_t sock_hnd; 
    9771020    pj_status_t status; 
    9781021    struct transport_callback *cb_rec; 
     
    10301073    pj_memset(&local, 0, sizeof(local)); 
    10311074    local.sin_family = PJ_AF_INET; 
    1032     sock_hnd = create_socket(type, &local); 
    1033     if (sock_hnd == PJ_INVALID_SOCKET) { 
     1075    status = create_socket(type, &local, &sock_hnd); 
     1076    if (status != PJ_SUCCESS) { 
    10341077        pj_mutex_unlock(mgr->mutex); 
    1035         (*cb_rec->cb)(NULL, cb_rec->token, -1); 
     1078        (*cb_rec->cb)(NULL, cb_rec->token, status); 
    10361079        return; 
    10371080    } 
    1038     tr = create_transport(mgr, type, sock_hnd, &local, NULL); 
    1039     if (!tr) { 
     1081    status = create_transport(mgr, type, sock_hnd, &local, NULL, &tr); 
     1082    if (status != PJ_SUCCESS) { 
    10401083        pj_mutex_unlock(mgr->mutex); 
    1041         (*cb_rec->cb)(NULL, cb_rec->token, -1); 
     1084        (*cb_rec->cb)(NULL, cb_rec->token, status); 
    10421085        return; 
    10431086    } 
     
    10461089    if (type == PJSIP_TRANSPORT_TCP) { 
    10471090        pj_memcpy(&tr->remote_addr, remote, sizeof(pj_sockaddr_in)); 
    1048         status = pj_ioqueue_connect(mgr->ioqueue, tr->key,  
    1049                                     &tr->remote_addr, sizeof(pj_sockaddr_in)); 
     1091        status = pj_ioqueue_connect(tr->key, &tr->remote_addr,  
     1092                                    sizeof(pj_sockaddr_in)); 
    10501093        pj_assert(status != 0); 
    1051         if (status != PJ_IOQUEUE_PENDING) { 
    1052             PJ_PERROR((tr->obj_name, "pj_ioqueue_connect()")); 
     1094        if (status != PJ_EPENDING) { 
     1095            PJ_TODO(HANDLE_IMMEDIATE_CONNECT); 
    10531096            destroy_transport(mgr, tr); 
    10541097            pj_mutex_unlock(mgr->mutex); 
    1055             (*cb_rec->cb)(NULL, cb_rec->token, -1); 
     1098            (*cb_rec->cb)(NULL, cb_rec->token, status); 
    10561099            return; 
    10571100        } 
     
    10591102#endif 
    10601103    if (type == PJSIP_TRANSPORT_UDP) { 
    1061         int len; 
     1104        pj_ssize_t size; 
    10621105 
    10631106        do { 
    10641107            tr->rdata->addr_len = sizeof(tr->rdata->addr); 
    1065             len = pj_ioqueue_recvfrom( mgr->ioqueue, tr->key,  
    1066                                        tr->rdata->packet, PJSIP_MAX_PKT_LEN, 
    1067                                        &tr->rdata->addr,  
    1068                                        &tr->rdata->addr_len); 
    1069             pj_assert(len < 0); 
    1070             if (len != PJ_IOQUEUE_PENDING) { 
    1071                 PJ_PERROR((tr->obj_name, "pj_ioqueue_recvfrom()")); 
     1108            size = PJSIP_MAX_PKT_LEN; 
     1109            status = pj_ioqueue_recvfrom( tr->key, &tr->rdata->op_key, 
     1110                                          tr->rdata->packet, &size, 0, 
     1111                                          &tr->rdata->addr,  
     1112                                          &tr->rdata->addr_len); 
     1113            if (status == PJ_SUCCESS) 
     1114                ; 
     1115            else if (status != PJ_EPENDING) { 
    10721116                destroy_transport(mgr, tr); 
    10731117                pj_mutex_unlock(mgr->mutex); 
    1074                 (*cb_rec->cb)(NULL, cb_rec->token, -1); 
     1118                (*cb_rec->cb)(NULL, cb_rec->token, status); 
    10751119                return; 
    10761120            } 
     
    10831127            PJ_TODO(FIXED_BUG_ON_IMMEDIATE_TRANSPORT_DATA); 
    10841128 
    1085         } while (len != PJ_IOQUEUE_PENDING); 
     1129        } while (status == PJ_SUCCESS); 
    10861130 
    10871131        //Bug: cb will never be called! 
     
    10931137    } else { 
    10941138        pj_mutex_unlock(mgr->mutex); 
    1095         (*cb_rec->cb)(NULL, cb_rec->token, -1); 
     1139        (*cb_rec->cb)(NULL, cb_rec->token, PJSIP_EUNSUPTRANSPORT); 
    10961140        return; 
    10971141    } 
    10981142 
    1099     pj_assert(status==PJ_IOQUEUE_PENDING || status==PJ_SUCCESS); 
     1143    pj_assert(status==PJ_EPENDING || status==PJ_SUCCESS); 
    11001144    pj_mutex_lock(tr->tr_mutex); 
    11011145    hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); 
    11021146    pj_memcpy(hash_key, &search_key, sizeof(transport_key)); 
    1103     pj_hash_set(tr->pool, mgr->transport_table, hash_key, sizeof(transport_key), tr); 
     1147    pj_hash_set(tr->pool, mgr->transport_table,  
     1148                hash_key, sizeof(transport_key), tr); 
    11041149    if (status == PJ_SUCCESS) { 
    11051150        pj_mutex_unlock(tr->tr_mutex); 
     
    11251170    pjsip_transport_t *tr; 
    11261171    transport_key *hash_key; 
     1172    pj_ssize_t size; 
    11271173 
    11281174    pj_assert (listener->type == PJSIP_TRANSPORT_TCP); 
    11291175 
    11301176    if (status != PJ_SUCCESS) { 
    1131         PJ_PERROR((listener->obj_name, "accept() returned error")); 
    1132         return; 
     1177        PJSIP_ENDPT_LOG_ERROR((mgr->endpt, listener->obj_name, status, 
     1178                               "Error in accept() completion")); 
     1179        goto on_return; 
    11331180    } 
    11341181 
    11351182    PJ_LOG(4,(listener->obj_name, "incoming tcp connection from %s:%d", 
    1136               pj_sockaddr_get_str_addr(&listener->accept_data.remote), 
    1137               pj_sockaddr_get_port(&listener->accept_data.remote))); 
    1138  
    1139     tr = create_transport(mgr, listener->type,  
    1140                           listener->accept_data.sock, 
    1141                           &listener->accept_data.local, 
    1142                           NULL); 
    1143     if (!tr) { 
     1183              pj_inet_ntoa(listener->accept_data.remote.sin_addr), 
     1184              pj_sockaddr_in_get_port(&listener->accept_data.remote))); 
     1185 
     1186    status = create_transport(mgr, listener->type,  
     1187                              listener->accept_data.sock, 
     1188                              &listener->accept_data.local, 
     1189                              NULL, &tr); 
     1190    if (status != PJ_SUCCESS) { 
     1191        PJSIP_ENDPT_LOG_ERROR((mgr->endpt, listener->obj_name, status, 
     1192                               "Error in creating new incoming TCP")); 
    11441193        goto on_return; 
    11451194    } 
     
    11551204    tr->rdata->addr_len = listener->accept_data.addrlen; 
    11561205 
    1157     status = pj_ioqueue_read (mgr->ioqueue, tr->key, tr->rdata->packet, PJSIP_MAX_PKT_LEN); 
    1158     if (status != PJ_IOQUEUE_PENDING) { 
    1159         PJ_PERROR((tr->obj_name, "pj_ioqueue_read()")); 
     1206    size = PJSIP_MAX_PKT_LEN; 
     1207    status = pj_ioqueue_recv(tr->key, &tr->rdata->op_key,  
     1208                             tr->rdata->packet, &size, 0); 
     1209    if (status != PJ_EPENDING) { 
     1210        PJSIP_ENDPT_LOG_ERROR((mgr->endpt, listener->obj_name, status, 
     1211                               "Error in receiving data")); 
     1212        PJ_TODO(IMMEDIATE_DATA); 
    11601213        destroy_transport(mgr, tr); 
    11611214        goto on_return; 
    11621215    } 
    11631216 
    1164     pj_memcpy(&tr->remote_addr, &listener->accept_data.remote, listener->accept_data.addrlen); 
     1217    pj_memcpy(&tr->remote_addr, &listener->accept_data.remote,  
     1218              listener->accept_data.addrlen); 
    11651219    hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); 
    11661220    init_key_from_transport(hash_key, tr); 
    11671221 
    11681222    pj_mutex_lock(mgr->mutex); 
    1169     pj_hash_set(tr->pool, mgr->transport_table, hash_key, sizeof(transport_key), tr); 
     1223    pj_hash_set(tr->pool, mgr->transport_table, hash_key,  
     1224                sizeof(transport_key), tr); 
    11701225    pj_mutex_unlock(mgr->mutex); 
    11711226 
     
    11731228    /* Re-initiate asynchronous accept() */ 
    11741229    listener->accept_data.addrlen = sizeof(listener->accept_data.local); 
    1175     status = pj_ioqueue_accept(mgr->ioqueue, listener->key,  
     1230    status = pj_ioqueue_accept(listener->key, &listener->accept_op, 
    11761231                               &listener->accept_data.sock,  
    11771232                               &listener->accept_data.local,  
    11781233                               &listener->accept_data.remote, 
    11791234                               &listener->accept_data.addrlen); 
    1180     if (status != PJ_IOQUEUE_PENDING) { 
    1181         PJ_PERROR((listener->obj_name, "pj_ioqueue_accept()")); 
     1235    if (status != PJ_EPENDING) { 
     1236        PJSIP_ENDPT_LOG_ERROR((mgr->endpt, listener->obj_name, status, 
     1237                               "Error in receiving data")); 
     1238        PJ_TODO(IMMEDIATE_ACCEPT); 
    11821239        return; 
    11831240    } 
     
    11941251    struct transport_callback new_list; 
    11951252    struct transport_callback *cb_rec; 
    1196  
    1197     PJ_UNUSED_ARG(mgr) 
     1253    pj_ssize_t recv_size; 
     1254 
     1255    PJ_UNUSED_ARG(mgr); 
    11981256 
    11991257    /* On connect completion, we must call all registered callbacks in 
     
    12221280    if (status == PJ_SUCCESS) { 
    12231281        int addrlen = sizeof(tr->local_addr); 
    1224         int rc; 
    1225         if ((rc=pj_sock_getsockname(tr->sock, (pj_sockaddr_t*)&tr->local_addr, &addrlen)) == 0) { 
     1282         
     1283        status = pj_sock_getsockname(tr->sock,  
     1284                                     (pj_sockaddr_t*)&tr->local_addr,  
     1285                                     &addrlen); 
     1286        if (status == PJ_SUCCESS) { 
    12261287            pj_memcpy(&tr->addr_name, &tr->local_addr, sizeof(tr->addr_name)); 
    1227         } else { 
    1228             PJ_LOG(4,(tr->obj_name, "Unable to get local address (getsockname=%d)", rc)); 
    12291288        } 
    12301289    } 
     
    12451304    if (status != PJ_SUCCESS) { 
    12461305        destroy_transport(mgr, tr); 
     1306        PJ_TODO(WTF); 
    12471307        return; 
    12481308    } 
    12491309 
    12501310    /* Initiate read operation to socket. */ 
    1251     status = pj_ioqueue_read (mgr->ioqueue, tr->key, tr->rdata->packet, PJSIP_MAX_PKT_LEN); 
    1252     if (status != PJ_IOQUEUE_PENDING) { 
    1253         PJ_PERROR((tr->obj_name, "pj_ioqueue_read()")); 
     1311    recv_size = PJSIP_MAX_PKT_LEN; 
     1312    status = pj_ioqueue_recv( tr->key, &tr->rdata->op_key, tr->rdata->packet,  
     1313                              &recv_size, 0); 
     1314    if (status != PJ_EPENDING) { 
    12541315        destroy_transport(mgr, tr); 
     1316        PJ_TODO(IMMEDIATE_DATA); 
    12551317        return; 
    12561318    } 
     
    12701332{ 
    12711333    pjsip_msg *msg; 
    1272     pjsip_cid_hdr *call_id; 
    12731334    pjsip_rx_data *rdata = tr->rdata; 
    12741335    pj_pool_t *rdata_pool; 
     
    13161377 
    13171378    /* Get source address and port for logging purpose. */ 
    1318     src_addr = pj_sockaddr_get_str_addr(&rdata->addr); 
    1319     src_port = pj_sockaddr_get_port(&rdata->addr); 
     1379    src_addr = pj_inet_ntoa(rdata->addr.sin_addr); 
     1380    src_port = pj_sockaddr_in_get_port(&rdata->addr); 
    13201381 
    13211382    /* Print the whole data to the log. */ 
     
    13341395        /* For TCP transport, check if the whole message has been received. */ 
    13351396        if (tr->type != PJSIP_TRANSPORT_UDP) { 
    1336             pj_bool_t is_complete; 
    1337             is_complete = pjsip_find_msg(rdata->packet, rdata->len, PJ_FALSE, &msg_fragment_size); 
    1338             if (!is_complete) { 
     1397            pj_status_t msg_status; 
     1398            msg_status = pjsip_find_msg(rdata->packet, rdata->len, PJ_FALSE,  
     1399                                        &msg_fragment_size); 
     1400            if (msg_status != PJ_SUCCESS) { 
    13391401                if (rdata->len == PJSIP_MAX_PKT_LEN) { 
    1340                     PJ_LOG(1,(tr->obj_name,  
    1341                               "Transport buffer full (%d bytes) for TCP socket %s:%d " 
    1342                               "(probably too many invalid fragments received). " 
    1343                               "Buffer will be discarded.", 
    1344                               PJSIP_MAX_PKT_LEN, src_addr, src_port)); 
     1402                    PJSIP_ENDPT_LOG_ERROR((mgr->endpt, tr->obj_name,  
     1403                                           PJSIP_EOVERFLOW, 
     1404                                           "Buffer discarded for %s:%d", 
     1405                                           src_addr, src_port)); 
    13451406                    goto on_return; 
    13461407                } else { 
     
    13581419                src_addr, src_port)); 
    13591420 
    1360         msg = pjsip_parse_msg( rdata->pool, rdata->packet, msg_fragment_size,  
    1361                                &rdata->parse_err); 
     1421        msg = pjsip_parse_rdata( rdata->packet, msg_fragment_size, rdata); 
    13621422        if (msg == NULL) { 
    13631423            PJ_LOG(3,(tr->obj_name, "Bad message (%d bytes from %s:%d)", msg_fragment_size, 
     
    13661426        } 
    13671427 
    1368         /* Attach newly created message to rdata. */ 
    1369         rdata->msg = msg; 
    1370  
    1371         /* Extract Call-ID, From and To header and tags, topmost Via, and CSeq 
    1372         * header from the message. 
    1373         */ 
    1374         call_id = pjsip_msg_find_hdr( msg, PJSIP_H_CALL_ID, NULL); 
    1375         rdata->from = pjsip_msg_find_hdr( msg, PJSIP_H_FROM, NULL); 
    1376         rdata->to = pjsip_msg_find_hdr( msg, PJSIP_H_TO, NULL); 
    1377         rdata->via = pjsip_msg_find_hdr( msg, PJSIP_H_VIA, NULL); 
    1378         rdata->cseq = pjsip_msg_find_hdr( msg, PJSIP_H_CSEQ, NULL); 
    1379  
    1380         if (call_id == NULL || rdata->from == NULL || rdata->to == NULL || 
    1381             rdata->via == NULL || rdata->cseq == NULL)  
     1428        /* Perform basic header checking. */ 
     1429        if (rdata->call_id.ptr == NULL || rdata->from == NULL ||  
     1430            rdata->to == NULL || rdata->via == NULL || rdata->cseq == NULL)  
    13821431        { 
    13831432            PJ_LOG(3,(tr->obj_name, "Bad message from %s:%d: missing some header",  
     
    13851434            goto finish_process_fragment; 
    13861435        } 
    1387         rdata->call_id = call_id->id; 
    1388         rdata->from_tag = rdata->from->tag; 
    1389         rdata->to_tag = rdata->to->tag; 
    13901436 
    13911437        /* If message is received from address that's different from the sent-by, 
     
    14021448         */ 
    14031449        if (rdata->via->rport_param == 0) { 
    1404             rdata->via->rport_param = pj_sockaddr_get_port(&rdata->addr); 
     1450            rdata->via->rport_param = pj_sockaddr_in_get_port(&rdata->addr); 
    14051451        } 
    14061452 
     
    14091455        if (msg->type == PJSIP_RESPONSE_MSG) { 
    14101456            hdr = (pjsip_hdr*)rdata->via->next; 
    1411             if (hdr) { 
     1457            if (hdr != &rdata->msg->hdr) { 
    14121458                hdr = pjsip_msg_find_hdr(msg, PJSIP_H_VIA, hdr); 
    14131459                if (hdr) { 
     
    14461492    rdata->addr_len = sizeof(rdata->addr); 
    14471493    if (tr->type == PJSIP_TRANSPORT_UDP) { 
    1448         pj_ioqueue_recvfrom( tr->mgr->ioqueue, tr->key, 
    1449                             tr->rdata->packet, PJSIP_MAX_PKT_LEN, 
     1494        pj_ssize_t size = PJSIP_MAX_PKT_LEN; 
     1495        pj_ioqueue_recvfrom(tr->key, &tr->rdata->op_key, 
     1496                            tr->rdata->packet, &size, 0,  
    14501497                            &rdata->addr, &rdata->addr_len); 
     1498        PJ_TODO(HANDLE_IMMEDIATE_DATA); 
    14511499    } 
    14521500 
     
    14571505tcp_read_packet: 
    14581506    if (tr->type == PJSIP_TRANSPORT_TCP) { 
    1459         pj_ioqueue_read( tr->mgr->ioqueue, tr->key,  
     1507        pj_ssize_t size = PJSIP_MAX_PKT_LEN - tr->rdata->len; 
     1508        pj_ioqueue_recv( tr->key, &tr->rdata->op_key, 
    14601509                         tr->rdata->packet + tr->rdata->len, 
    1461                          PJSIP_MAX_PKT_LEN - tr->rdata->len); 
     1510                         &size, 0); 
     1511        PJ_TODO(HANDLE_IMMEDIATE_DATA_1); 
    14621512    } 
    14631513#endif 
     
    15081558} 
    15091559 
    1510 static void on_ioqueue_read(pj_ioqueue_key_t *key, pj_ssize_t bytes_read) 
     1560static void on_ioqueue_read(pj_ioqueue_key_t *key,  
     1561                            pj_ioqueue_op_key_t *op_key,  
     1562                            pj_ssize_t bytes_read) 
    15111563{ 
    15121564    pjsip_transport_t *t; 
     
    15161568} 
    15171569 
    1518 static void on_ioqueue_write(pj_ioqueue_key_t *key, pj_ssize_t bytes_sent) 
    1519 { 
    1520     PJ_UNUSED_ARG(key) 
    1521     PJ_UNUSED_ARG(bytes_sent) 
     1570static void on_ioqueue_write(pj_ioqueue_key_t *key,  
     1571                             pj_ioqueue_op_key_t *op_key,  
     1572                             pj_ssize_t bytes_sent) 
     1573{ 
     1574    PJ_UNUSED_ARG(key); 
     1575    PJ_UNUSED_ARG(bytes_sent); 
    15221576 
    15231577    /* Completion of write operation.  
     
    15261580} 
    15271581 
    1528 static void on_ioqueue_accept(pj_ioqueue_key_t *key, int status) 
     1582static void on_ioqueue_accept(pj_ioqueue_key_t *key,  
     1583                              pj_ioqueue_op_key_t *op_key,  
     1584                              pj_sock_t newsock, 
     1585                              int status) 
    15291586{ 
    15301587#if PJ_HAS_TCP 
     
    15341591    handle_new_connection( t->mgr, t, status ); 
    15351592#else 
    1536     PJ_UNUSED_ARG(key) 
    1537     PJ_UNUSED_ARG(status) 
     1593    PJ_UNUSED_ARG(key); 
     1594    PJ_UNUSED_ARG(status); 
    15381595#endif 
    15391596} 
     
    15471604    handle_connect_completion( t->mgr, t, status); 
    15481605#else 
    1549     PJ_UNUSED_ARG(key) 
    1550     PJ_UNUSED_ARG(status) 
     1606    PJ_UNUSED_ARG(key); 
     1607    PJ_UNUSED_ARG(status); 
    15511608#endif 
    15521609} 
  • pjproject/main/pjsip/src/pjsip/sip_uri.c

    • Property svn:keywords set to Id
    r3 r43  
    11/* $Id$ 
    2  * 
    32 */ 
    43#include <pjsip/sip_uri.h> 
    54#include <pjsip/sip_msg.h> 
    6 #include <pjsip/print.h> 
     5#include <pjsip/print_util.h> 
    76#include <pj/string.h> 
    87#include <pj/pool.h> 
     8#include <pj/assert.h> 
    99 
    1010#define IS_SIPS(url)    ((url)->vptr==&sips_url_vptr) 
     
    6969static const pj_str_t *pjsip_url_get_scheme(const pjsip_url *url) 
    7070{ 
    71     PJ_UNUSED_ARG(url) 
     71    PJ_UNUSED_ARG(url); 
    7272    return &sip_str; 
    7373} 
     
    7575static const pj_str_t *pjsips_url_get_scheme(const pjsip_url *url) 
    7676{ 
    77     PJ_UNUSED_ARG(url) 
     77    PJ_UNUSED_ARG(url); 
    7878    return &sips_str; 
    7979} 
     
    254254    } 
    255255 
    256     if (strcmp(str_url1, str_url2)) { 
     256    if (pj_native_strcmp(str_url1, str_url2)) { 
    257257        /* Not equal */ 
    258258        return -1; 
  • pjproject/main/pjsip/src/pjsua/getopt.c

    r3 r43  
    279279   in GCC.  */ 
    280280#include <string.h> 
    281 #define my_index        strchr 
     281#define my_index        pj_native_strchr 
    282282#else 
    283283 
     
    645645         then skip everything else like a non-option.  */ 
    646646 
    647       if (optind != argc && !strcmp (argv[optind], "--")) 
     647      if (optind != argc && !pj_native_strcmp(argv[optind], "--")) 
    648648        { 
    649649          optind++; 
  • pjproject/main/pjsip/src/pjsua/main.c

    r3 r43  
    251251    urllen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->from->uri, url, sizeof(url)-1); 
    252252    if (urllen < 1) { 
    253         strcpy(url, "<unknown>"); 
     253        pj_native_strcpy(url, "<unknown>"); 
    254254    } else { 
    255255        url[urllen] = '\0'; 
     
    11041104     
    11051105    if (global.user_id[0]=='\0') { 
    1106         strcpy(global.user_id, "user"); 
     1106        pj_native_strcpy(global.user_id, "user"); 
    11071107    } 
    11081108 
     
    12341234                           rdata->from->uri, from, sizeof(from)); 
    12351235    if (len > 0) from[len] = '\0'; 
    1236     else strcpy(from, "<URL too long..>"); 
     1236    else pj_native_strcpy(from, "<URL too long..>"); 
    12371237 
    12381238    len = pjsip_uri_print( PJSIP_URI_IN_CONTACT_HDR,  
    12391239                           rdata->to->uri, to, sizeof(to)); 
    12401240    if (len > 0) to[len] = '\0'; 
    1241     else strcpy(to, "<URL too long..>"); 
     1241    else pj_native_strcpy(to, "<URL too long..>"); 
    12421242 
    12431243    PJ_LOG(3,(THIS_FILE, "Incoming instant message:")); 
  • pjproject/main/pjsip/src/pjsua/misc.c

    r3 r43  
    342342            break; 
    343343        case OPT_USE_STUN1:   /* STUN server 1 */ 
    344             p = strchr(optarg, ':'); 
     344            p = pj_native_strchr(optarg, ':'); 
    345345            if (p) { 
    346346                *p = '\0'; 
     
    357357            break; 
    358358        case OPT_USE_STUN2:   /* STUN server 2 */ 
    359             p = strchr(optarg, ':'); 
     359            p = pj_native_strchr(optarg, ':'); 
    360360            if (p) { 
    361361                *p = '\0'; 
Note: See TracChangeset for help on using the changeset viewer.