Changeset 43
- Timestamp:
- Nov 11, 2005 7:01:31 PM (19 years ago)
- Location:
- pjproject/main
- Files:
-
- 1 added
- 2 deleted
- 70 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/main/RELNOTES.txt
r1 r43 1 Version 0.3 2 PJLIB 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 12 PJSIP 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 1 18 Version 0.2.9 - 2005/06/19 2 19 Core: -
pjproject/main/pjlib-util/include/pjlib-util/scanner.h
r29 r43 1 1 /* $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__ 7 5 8 6 /** … … 20 18 * @brief 21 19 * 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 * 31 21 * @{ 32 22 */ … … 34 24 /** 35 25 * 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 */ 36 typedef 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 */ 47 typedef 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 */ 56 typedef 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 */ 67 PJ_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 */ 79 PJ_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 */ 92 PJ_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)) 61 120 62 121 /** 63 122 * Add the characters in the specified range '[cstart, cend)' to the 64 123 * 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 */ 129 PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend); 70 130 71 131 /** 72 132 * 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 */ 136 PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis); 76 137 77 138 /** 78 139 * 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 */ 143 PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis); 82 144 83 145 /** 84 146 * 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 */ 151 PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str); 89 152 90 153 /** 91 154 * 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 */ 160 PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend); 97 161 98 162 /** 99 163 * 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 */ 168 PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str); 104 169 105 170 /** 106 171 * 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 */ 175 PJ_DECL(void) pj_cis_invert( pj_cis_t *cis ); 110 176 111 177 /** 112 178 * 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 */ 183 PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, int c ) 184 { 185 return PJ_CIS_ISSET(cis, c); 119 186 } 120 187 121 /**122 * @}123 */124 125 /**126 * @defgroup PJ_SCANNER Text Scanner127 * @ingroup PJ_SCAN128 * @{129 */130 188 131 189 /** … … 157 215 * The callback function type to be called by the scanner when it encounters 158 216 * syntax error. 159 * @param scanner The scanner instance that calls the callback . 217 * 218 * @param scanner The scanner instance that calls the callback . 160 219 */ 161 220 typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner); … … 245 304 */ 246 305 PJ_DECL(int) pj_scan_peek( pj_scanner *scanner, 247 const pj_char_specspec, pj_str_t *out);306 const pj_cis_t *spec, pj_str_t *out); 248 307 249 308 … … 262 321 */ 263 322 PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner, 264 323 pj_size_t len, pj_str_t *out); 265 324 266 325 … … 278 337 */ 279 338 PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner, 280 const pj_char_specspec,281 339 const pj_cis_t *spec, 340 pj_str_t *out); 282 341 283 342 … … 294 353 */ 295 354 PJ_DECL(void) pj_scan_get( pj_scanner *scanner, 296 const pj_char_specspec, pj_str_t *out);355 const pj_cis_t *spec, pj_str_t *out); 297 356 298 357 … … 318 377 */ 319 378 PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner, 320 379 unsigned N, pj_str_t *out); 321 380 322 381 … … 326 385 * @param scanner The scanner. 327 386 * 328 * @return (unknown)387 * @return The character. 329 388 */ 330 389 PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner ); … … 349 408 */ 350 409 PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner, 351 const pj_char_specspec, pj_str_t *out);410 const pj_cis_t *spec, pj_str_t *out); 352 411 353 412 … … 361 420 */ 362 421 PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner, 363 422 int until_char, pj_str_t *out); 364 423 365 424 … … 373 432 */ 374 433 PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner, 375 434 const char *until_spec, pj_str_t *out); 376 435 377 436 /** … … 385 444 */ 386 445 PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner, 387 446 unsigned N, pj_bool_t skip); 388 447 389 448 … … 446 505 */ 447 506 448 #if PJ_FUNCTIONS_ARE_INLINED 449 # include "scanner_i.h" 507 508 PJ_END_DECL 509 450 510 #endif 451 511 452 453 PJ_END_DECL454 455 #endif456 -
pjproject/main/pjlib-util/src/pjlib-util/scanner.c
r32 r43 5 5 #include <pj/except.h> 6 6 #include <pj/os.h> 7 #include <pj/errno.h> 7 8 8 9 #define PJ_SCAN_IS_SPACE(c) ((c)==' ' || (c)=='\t') … … 16 17 } 17 18 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(); 19 PJ_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 25 PJ_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 42 PJ_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 61 PJ_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 69 PJ_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 75 PJ_DEF(void) pj_cis_add_num(pj_cis_t *cis) 76 { 77 pj_cis_add_range( cis, '0', '9'+1); 78 } 79 80 PJ_DEF(void) pj_cis_add_str( pj_cis_t *cis, const char *str) 81 { 51 82 while (*str) { 52 cs[(int)*str] = 1;83 PJ_CIS_SET(cis, *str); 53 84 ++str; 54 85 } 55 86 } 56 87 57 PJ_DEF(void) pj_c s_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(); 88 PJ_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 96 PJ_DEF(void) pj_cis_del_str( pj_cis_t *cis, const char *str) 97 { 67 98 while (*str) { 68 cs[(int)*str] = 0;99 PJ_CIS_CLR(cis, *str); 69 100 ++str; 70 101 } 71 102 } 72 103 73 PJ_DEF(void) pj_c s_invert( pj_char_spec cs )104 PJ_DEF(void) pj_cis_invert( pj_cis_t *cis ) 74 105 { 75 106 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); 79 112 } 80 113 } … … 166 199 167 200 PJ_DEF(int) pj_scan_peek( pj_scanner *scanner, 168 const pj_char_specspec, pj_str_t *out)201 const pj_cis_t *spec, pj_str_t *out) 169 202 { 170 203 register char *s = scanner->curptr; … … 178 211 } 179 212 180 while (PJ_SCAN_CHECK_EOF(s) && pj_c s_match(spec, *s))213 while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)) 181 214 ++s; 182 215 … … 204 237 205 238 PJ_DEF(int) pj_scan_peek_until( pj_scanner *scanner, 206 const pj_char_specspec,207 239 const pj_cis_t *spec, 240 pj_str_t *out) 208 241 { 209 242 register char *s = scanner->curptr; … … 217 250 } 218 251 219 while (PJ_SCAN_CHECK_EOF(s) && !pj_c s_match( spec, *s))252 while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match( spec, *s)) 220 253 ++s; 221 254 … … 226 259 227 260 PJ_DEF(void) pj_scan_get( pj_scanner *scanner, 228 const pj_char_specspec, pj_str_t *out)261 const pj_cis_t *spec, pj_str_t *out) 229 262 { 230 263 register char *s = scanner->curptr; … … 234 267 PJ_CHECK_STACK(); 235 268 236 if (pj_scan_is_eof(scanner) || !pj_c s_match(spec, *s)) {269 if (pj_scan_is_eof(scanner) || !pj_cis_match(spec, *s)) { 237 270 pj_scan_syntax_err(scanner); 238 271 return; … … 241 274 do { 242 275 ++s; 243 } while (PJ_SCAN_CHECK_EOF(s) && pj_c s_match(spec, *s));276 } while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)); 244 277 245 278 pj_strset3(out, scanner->curptr, s); … … 396 429 397 430 PJ_DEF(void) pj_scan_get_until( pj_scanner *scanner, 398 const pj_char_specspec, pj_str_t *out)431 const pj_cis_t *spec, pj_str_t *out) 399 432 { 400 433 register char *s = scanner->curptr; … … 409 442 } 410 443 411 while (PJ_SCAN_CHECK_EOF(s) && !pj_c s_match(spec, *s)) {444 while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match(spec, *s)) { 412 445 ++s; 413 446 } … … 425 458 426 459 PJ_DEF(void) pj_scan_get_until_ch( pj_scanner *scanner, 427 460 int until_char, pj_str_t *out) 428 461 { 429 462 register char *s = scanner->curptr; -
pjproject/main/pjlib/build/pjlib.dsw
r36 r43 24 24 Package=<4> 25 25 {{{ 26 }}} 27 28 ############################################################################### 29 30 Project: "pjlib++_test"=".\pjlib++-test.dsp" - Package Owner=<4> 31 32 Package=<5> 33 {{{ 34 }}} 35 36 Package=<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 26 44 }}} 27 45 … … 58 76 ############################################################################### 59 77 60 Project: "pjlib++_test"=.\pjlib++-test.dsp - Package Owner=<4>61 62 Package=<5>63 {{{64 }}}65 66 Package=<4>67 {{{68 Begin Project Dependency69 Project_Dep_Name pjlib70 End Project Dependency71 Begin Project Dependency72 Project_Dep_Name pjlib++73 End Project Dependency74 }}}75 76 ###############################################################################77 78 78 Global: 79 79 -
pjproject/main/pjlib/include/pj++/file.hpp
r36 r43 1 /* $Id$ */2 1 /* $Id$ 2 */ 3 3 #ifndef __PJPP_FILE_HPP__ 4 4 #define __PJPP_FILE_HPP__ -
pjproject/main/pjlib/include/pj++/hash.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_HASH_H __4 #define __PJPP_HASH_H __3 #ifndef __PJPP_HASH_HPP__ 4 #define __PJPP_HASH_HPP__ 5 5 6 6 #include <pj++/types.hpp> … … 136 136 137 137 138 #endif /* __PJPP_HASH_H __ */138 #endif /* __PJPP_HASH_HPP__ */ 139 139 -
pjproject/main/pjlib/include/pj++/list.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_LIST_H __4 #define __PJPP_LIST_H __3 #ifndef __PJPP_LIST_HPP__ 4 #define __PJPP_LIST_HPP__ 5 5 6 6 #include <pj/list.h> … … 308 308 309 309 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__ 4 5 5 6 #include <pj++/types.hpp> … … 128 129 129 130 130 #endif /* __PJPP_LOCK_H __ */131 #endif /* __PJPP_LOCK_HPP__ */ 131 132 -
pjproject/main/pjlib/include/pj++/os.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_OS_H __4 #define __PJPP_OS_H __3 #ifndef __PJPP_OS_HPP__ 4 #define __PJPP_OS_HPP__ 5 5 6 6 #include <pj/os.h> … … 785 785 } 786 786 787 #endif /* __PJPP_OS_H__ */ 787 #endif /* __PJPP_OS_HPP__ */ 788 -
pjproject/main/pjlib/include/pj++/pool.hpp
r37 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_POOL_H __4 #define __PJPP_POOL_H __3 #ifndef __PJPP_POOL_HPP__ 4 #define __PJPP_POOL_HPP__ 5 5 6 6 #include <pj/pool.h> … … 251 251 252 252 253 #endif /* __PJPP_POOL_H__ */ 253 #endif /* __PJPP_POOL_HPP__ */ 254 -
pjproject/main/pjlib/include/pj++/proactor.hpp
r37 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_PROACTOR_H __4 #define __PJPP_PROACTOR_H __3 #ifndef __PJPP_PROACTOR_HPP__ 4 #define __PJPP_PROACTOR_HPP__ 5 5 6 6 #include <pj/ioqueue.h> … … 30 30 : handler_(NULL) 31 31 { 32 pj_ioqueue_op_key_init(this, sizeof(*this)); 32 33 } 33 34 … … 38 39 : handler_(handler) 39 40 { 40 pj_memset(this, 0, sizeof(pj_ioqueue_op_key_t));41 pj_ioqueue_op_key_init(this, sizeof(*this)); 41 42 } 42 43 … … 498 499 }; 499 500 500 #endif /* __PJPP_PROACTOR_H__ */ 501 #endif /* __PJPP_PROACTOR_HPP__ */ 502 -
pjproject/main/pjlib/include/pj++/scanner.hpp
r36 r43 1 1 /* $Id$ 2 *3 2 */ 4 #ifndef __PJPP_SCANNER_H __5 #define __PJPP_SCANNER_H __3 #ifndef __PJPP_SCANNER_HPP__ 4 #define __PJPP_SCANNER_HPP__ 6 5 7 6 #include <pjlib-util/scanner.h> … … 171 170 }; 172 171 173 #endif /* __PJPP_SCANNER_H__ */ 172 #endif /* __PJPP_SCANNER_HPP__ */ 173 -
pjproject/main/pjlib/include/pj++/sock.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_SOCK_H __4 #define __PJPP_SOCK_H __3 #ifndef __PJPP_SOCK_HPP__ 4 #define __PJPP_SOCK_HPP__ 5 5 6 6 #include <pj/sock.h> … … 424 424 425 425 426 #endif /* __PJPP_SOCK_H__ */ 426 #endif /* __PJPP_SOCK_HPP__ */ 427 -
pjproject/main/pjlib/include/pj++/string.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_STRING_H __4 #define __PJPP_STRING_H __3 #ifndef __PJPP_STRING_HPP__ 4 #define __PJPP_STRING_HPP__ 5 5 6 6 #include <pj/string.h> … … 406 406 }; 407 407 408 #endif /* __PJPP_STRING_H__ */ 408 #endif /* __PJPP_STRING_HPP__ */ 409 -
pjproject/main/pjlib/include/pj++/timer.hpp
r36 r43 1 1 /* $Id$ 2 2 */ 3 #ifndef __PJPP_TIMER_H __4 #define __PJPP_TIMER_H __3 #ifndef __PJPP_TIMER_HPP__ 4 #define __PJPP_TIMER_HPP__ 5 5 6 6 #include <pj/timer.h> … … 178 178 }; 179 179 180 #endif /* __PJPP_TIMER_H__ */ 180 #endif /* __PJPP_TIMER_HPP__ */ 181 -
pjproject/main/pjlib/include/pj++/tree.hpp
r36 r43 1 1 /* $Id$ 2 *3 2 */ 4 #ifndef __PJPP_TREE_H __5 #define __PJPP_TREE_H __3 #ifndef __PJPP_TREE_HPP__ 4 #define __PJPP_TREE_HPP__ 6 5 7 6 #include <pj/rbtree.h> … … 110 109 }; 111 110 112 #endif /* __PJPP_TREE_H__ */ 111 #endif /* __PJPP_TREE_HPP__ */ 112 -
pjproject/main/pjlib/include/pj++/types.hpp
r36 r43 1 1 /* $Id$ 2 *3 2 */ 4 #ifndef __PJPP_TYPES_H __5 #define __PJPP_TYPES_H __3 #ifndef __PJPP_TYPES_HPP__ 4 #define __PJPP_TYPES_HPP__ 6 5 7 6 #include <pj/types.h> … … 142 141 }; 143 142 144 #endif /* __PJPP_TYPES_H__ */ 143 #endif /* __PJPP_TYPES_HPP__ */ 144 -
pjproject/main/pjlib/include/pj/compat/string.h
r4 r43 41 41 42 42 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 43 52 #endif /* __PJ_COMPAT_STRING_H__ */ -
pjproject/main/pjlib/include/pj/config.h
r35 r43 148 148 */ 149 149 #ifndef PJ_LOG_MAX_LEVEL 150 # define PJ_LOG_MAX_LEVEL 4150 # define PJ_LOG_MAX_LEVEL 5 151 151 #endif 152 152 … … 404 404 #endif 405 405 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 406 413 407 414 /******************************************************************** -
pjproject/main/pjlib/include/pj/errno.h
r36 r43 216 216 */ 217 217 #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) 218 223 219 224 /** @} */ /* pj_errnum */ -
pjproject/main/pjlib/include/pj/except.h
r4 r43 184 184 PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id); 185 185 186 186 187 /** @} */ 187 188 -
pjproject/main/pjlib/include/pj/hash.h
r4 r43 45 45 const void *key, unsigned keylen); 46 46 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 */ 59 PJ_DECL(pj_uint32_t) pj_hash_calc_tolower(pj_uint32_t hval, 60 char *result, 61 const pj_str_t *key); 47 62 48 63 /** -
pjproject/main/pjlib/include/pj/ioqueue.h
r36 r43 342 342 343 343 /** 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 */ 349 PJ_DECL(void) pj_ioqueue_op_key_init( pj_ioqueue_op_key_t *op_key, 350 pj_size_t size ); 351 352 /** 344 353 * 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. 347 357 * 348 358 * @param key The key. -
pjproject/main/pjlib/include/pj/string.h
r4 r43 13 13 #include <pj/types.h> 14 14 #include <pj/compat/string.h> 15 #include <pj/compat/sprintf.h> 16 #include <pj/compat/vsprintf.h> 17 15 18 16 19 PJ_BEGIN_DECL -
pjproject/main/pjlib/src/pj/errno.c
r36 r43 31 31 { PJ_ENOTSUP, "Option/operation is not supported"}, 32 32 { PJ_EINVALIDOP, "Invalid operation"}, 33 { PJ_ECANCELLED, "Operation cancelled"} 33 { PJ_ECANCELLED, "Operation cancelled"}, 34 { PJ_EEXISTS, "Object already exists" } 34 35 }; 35 36 -
pjproject/main/pjlib/src/pj/hash.c
r6 r43 50 50 } 51 51 return hash; 52 } 53 54 PJ_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; 52 66 } 53 67 -
pjproject/main/pjlib/src/pj/ioqueue_common_abs.c
r36 r43 834 834 #endif /* PJ_HAS_TCP */ 835 835 836 837 PJ_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 836 844 /* 837 845 * pj_ioqueue_is_pending() -
pjproject/main/pjlib/src/pj/ioqueue_winnt.c
r36 r43 893 893 894 894 895 PJ_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 } 895 900 896 901 PJ_DEF(pj_bool_t) pj_ioqueue_is_pending( pj_ioqueue_key_t *key, -
pjproject/main/pjsip/bin
-
Property
svn:ignore
set to
*
-
Property
svn:ignore
set to
-
pjproject/main/pjsip/build
- Property svn:ignore
-
old new 2 2 *.ncb 3 3 *.plg 4 TODO-LIST.TXT
-
- Property svn:ignore
-
pjproject/main/pjsip/build/output
-
Property
svn:ignore
set to
*
-
Property
svn:ignore
set to
-
pjproject/main/pjsip/build/pjsip_core.dsp
r1 r43 33 33 # PROP BASE Use_MFC 0 34 34 # 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" 37 37 # PROP BASE Target_Dir "" 38 38 # PROP Use_MFC 0 39 39 # 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" 42 42 # PROP Target_Dir "" 43 43 # 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 /c44 # 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 45 45 # SUBTRACT CPP /YX 46 46 # ADD BASE RSC /l 0x409 /d "NDEBUG" … … 51 51 LIB32=link.exe -lib 52 52 # 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" 54 54 55 55 !ELSEIF "$(CFG)" == "pjsip_core - Win32 Debug" … … 57 57 # PROP BASE Use_MFC 0 58 58 # 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" 61 61 # PROP BASE Target_Dir "" 62 62 # PROP Use_MFC 0 63 63 # 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" 66 66 # PROP Target_Dir "" 67 67 # 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 /c68 # 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 69 69 # SUBTRACT CPP /YX 70 70 # ADD BASE RSC /l 0x409 /d "_DEBUG" … … 75 75 LIB32=link.exe -lib 76 76 # 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" 78 78 79 79 !ENDIF … … 136 136 # Begin Source File 137 137 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 138 SOURCE=..\include\pjsip_core.h 139 # End Source File 140 # Begin Source File 141 142 SOURCE=..\include\pjsip\print_util.h 143 # End Source File 144 # Begin Source File 145 146 SOURCE=..\include\pjsip\sip_auth.h 147 # End Source File 148 # Begin Source File 149 150 SOURCE=..\include\pjsip\sip_auth_msg.h 151 # End Source File 152 # Begin Source File 153 154 SOURCE=..\include\pjsip\sip_auth_parser.h 155 # End Source File 156 # Begin Source File 157 158 SOURCE=..\include\pjsip\sip_config.h 159 # End Source File 160 # Begin Source File 161 162 SOURCE=..\include\pjsip\sip_endpoint.h 163 # End Source File 164 # Begin Source File 165 166 SOURCE=..\include\pjsip\sip_errno.h 167 # End Source File 168 # Begin Source File 169 170 SOURCE=..\include\pjsip\sip_event.h 171 # End Source File 172 # Begin Source File 173 174 SOURCE=..\include\pjsip\sip_misc.h 175 # End Source File 176 # Begin Source File 177 178 SOURCE=..\include\pjsip\sip_module.h 179 # End Source File 180 # Begin Source File 181 182 SOURCE=..\include\pjsip\sip_msg.h 183 # End Source File 184 # Begin Source File 185 186 SOURCE=..\include\pjsip\sip_parser.h 187 # End Source File 188 # Begin Source File 189 190 SOURCE=..\include\pjsip\sip_private.h 191 # End Source File 192 # Begin Source File 193 194 SOURCE=..\include\pjsip\sip_resolve.h 195 # End Source File 196 # Begin Source File 197 198 SOURCE=..\include\pjsip\sip_transaction.h 199 # End Source File 200 # Begin Source File 201 202 SOURCE=..\include\pjsip\sip_transport.h 203 # End Source File 204 # Begin Source File 205 206 SOURCE=..\include\pjsip\sip_types.h 207 # End Source File 208 # Begin Source File 209 210 SOURCE=..\include\pjsip\sip_uri.h 207 211 # End Source File 208 212 # End Group … … 212 216 # Begin Source File 213 217 214 SOURCE=..\ src\pjsip\sip_msg_i.h218 SOURCE=..\include\pjsip\sip_msg_i.h 215 219 # End Source File 216 220 # End Group -
pjproject/main/pjsip/build/pjsip_ua.dsp
r1 r43 88 88 # Begin Source File 89 89 90 SOURCE= ..\src\pjsip_mod_ua\sip_dialog.c90 SOURCE="..\src\pjsip-ua\sip_dialog.c" 91 91 # End Source File 92 92 # Begin Source File 93 93 94 SOURCE= ..\src\pjsip_mod_ua\sip_reg.c94 SOURCE="..\src\pjsip-ua\sip_reg.c" 95 95 # End Source File 96 96 # Begin Source File 97 97 98 SOURCE=..\src\pjsip_mod_ua\sip_ua.c 98 SOURCE="..\src\pjsip-ua\sip_ua.c" 99 # End Source File 100 # Begin Source File 101 102 SOURCE="..\src\pjsip-ua\sip_ua_private.h" 99 103 # End Source File 100 104 # End Group -
pjproject/main/pjsip/docs
-
Property
svn:ignore
set to
html
latex
rtf
-
Property
svn:ignore
set to
-
pjproject/main/pjsip/include/pjsip/print_util.h
- Property svn:keywords set to Id
r35 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_PRINT_H__ -
pjproject/main/pjsip/include/pjsip/sip_auth.h
- Property svn:keywords set to Id
r42 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_AUTH_SIP_AUTH_H__ … … 61 60 typedef struct pjsip_cached_auth_hdr 62 61 { 63 PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr) 62 PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr); 64 63 65 64 pjsip_method method; … … 81 80 typedef struct pjsip_auth_session 82 81 { 83 PJ_DECL_LIST_MEMBER(struct pjsip_auth_session) 82 PJ_DECL_LIST_MEMBER(struct pjsip_auth_session); 84 83 85 84 pj_str_t realm; -
pjproject/main/pjsip/include/pjsip/sip_auth_msg.h
- Property svn:keywords set to Id
r42 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_AUTH_SIP_AUTH_MSG_H__ … … 69 68 struct pjsip_authorization_hdr 70 69 { 71 PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr) 70 PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr); 72 71 pj_str_t scheme; 73 72 union … … 158 157 struct pjsip_www_authenticate_hdr 159 158 { 160 PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr) 159 PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr); 161 160 pj_str_t scheme; 162 161 union -
pjproject/main/pjsip/include/pjsip/sip_auth_parser.h
- Property svn:keywords set to Id
r42 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_AUTH_SIP_AUTH_PARSER_H__ … … 25 24 * such as Authorization, WWW-Authenticate, Proxy-Authorizization, and 26 25 * Proxy-Authenticate headers. 26 * 27 * @return PJ_SUCCESS or the appropriate status code. 27 28 */ 28 PJ_DECL( void) pjsip_auth_init_parser();29 PJ_DECL(pj_status_t) pjsip_auth_init_parser(void); 29 30 30 31 /** -
pjproject/main/pjsip/include/pjsip/sip_config.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_CONFIG_H__ … … 134 133 135 134 #include <pj/config.h> 136 #include <pj/compat.h>137 135 138 136 -
pjproject/main/pjsip/include/pjsip/sip_endpoint.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_ENDPOINT_H__ … … 29 28 * all SIP objects in an application. It performs the following roles: 30 29 * - 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. 32 32 * - it owns transaction hash table. 33 33 * - it receives incoming messages from transport layer and automatically … … 35 35 * - it has a single instance of timer management (timer heap). 36 36 * - 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. 38 39 * - it provides SIP policy such as which outbound proxy to use for all 39 40 * outgoing SIP request messages. … … 50 51 /** 51 52 * 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 */ 66 PJ_DECL(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf, 67 pjsip_endpoint **endpt); 60 68 61 69 /** … … 67 75 */ 68 76 PJ_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 */ 86 PJ_DECL(const pj_str_t*) pjsip_endpt_name(const pjsip_endpoint *endpt); 69 87 70 88 /** … … 155 173 * 156 174 * @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 */ 179 PJ_DECL(pj_status_t) pjsip_endpt_create_tsx(pjsip_endpoint *endpt, 180 pjsip_transaction **p_tsx); 160 181 161 182 /** … … 188 209 * This function, like all other endpoint functions, is thread safe. 189 210 * 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 */ 216 PJ_DECL(pj_status_t) pjsip_endpt_create_tdata( pjsip_endpoint *endpt, 217 pjsip_tx_data **p_tdata); 194 218 195 219 /** … … 333 357 334 358 /** 359 * Log an error. 360 */ 361 PJ_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 /** 335 377 * @} 336 378 */ -
pjproject/main/pjsip/include/pjsip/sip_event.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_EVENT_H__ … … 26 25 { 27 26 /** Unidentified event. */ 28 PJSIP_EVENT_UN IDENTIFIED,27 PJSIP_EVENT_UNKNOWN, 29 28 30 29 /** Timer event, normally only used internally in transaction. */ … … 41 40 42 41 /** Transaction state changed event. */ 43 PJSIP_EVENT_TSX_STATE _CHANGED,42 PJSIP_EVENT_TSX_STATE, 44 43 45 44 /** 2xx response received event. */ 46 PJSIP_EVENT_RX_200_ RESPONSE,45 PJSIP_EVENT_RX_200_MSG, 47 46 48 47 /** ACK request received event. */ … … 56 55 57 56 /** On before transmitting message. */ 58 PJSIP_EVENT_ BEFORE_TX,57 PJSIP_EVENT_PRE_TX_MSG, 59 58 60 59 } pjsip_event_id_e; … … 77 76 { 78 77 /** 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); 80 79 81 80 /** The event type, can be any value of \b pjsip_event_id_e. 82 * @see pjsip_event_id_e83 81 */ 84 82 pjsip_event_id_e type; 85 83 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. 94 88 */ 95 89 union 96 90 { 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; 118 177 }; 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 119 280 120 281 /** -
pjproject/main/pjsip/include/pjsip/sip_misc.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_MISC_H__ … … 31 30 * @param cseq Optional CSeq (put -1 to generate random CSeq). 32 31 * @param text Optional text body (put NULL to omit body). 32 * @param p_tdata Pointer to receive the transmit data. 33 33 * 34 * @return The transmit data.34 * @return PJ_SUCCESS, or the appropriate error code. 35 35 */ 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); 36 PJ_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); 45 46 46 47 /** … … 59 60 * @param cseq Optional CSeq (put -1 to generate random CSeq). 60 61 * @param text Optional text body (put NULL to omit body). 62 * @param p_tdata Pointer to receive the transmit data. 61 63 * 62 * @return The transmit data.64 * @return PJ_SUCCESS, or the appropriate error code. 63 65 */ 64 PJ_DECL(pj sip_tx_data*)66 PJ_DECL(pj_status_t) 65 67 pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, 66 68 const pjsip_method *method, … … 71 73 const pjsip_cid_hdr *call_id, 72 74 int cseq, 73 const pj_str_t *text ); 75 const pj_str_t *text, 76 pjsip_tx_data **p_tdata); 74 77 75 78 /** … … 90 93 * the completion of the transaction. 91 94 * 92 * @return Zero if transaction is started successfully.95 * @return PJ_SUCCESS, or the appropriate error code. 93 96 */ 94 97 PJ_DECL(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, … … 108 111 * @param rdata The request receive data. 109 112 * @param code Status code to be put in the response. 113 * @param p_tdata Pointer to receive the transmit data. 110 114 * 111 * @return Transmit data.115 * @return PJ_SUCCESS, or the appropriate error code. 112 116 */ 113 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_response(pjsip_endpoint *endpt, 114 const pjsip_rx_data *rdata, 115 int code); 117 PJ_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); 116 121 117 122 /** … … 137 142 * @param endpt The endpoint. 138 143 * @param tdata The transmit buffer for the request being cancelled. 144 * @param p_tdata Pointer to receive the transmit data. 139 145 * 140 * @return Cancel request.146 * @return PJ_SUCCESS, or the appropriate error code. 141 147 */ 142 PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 143 pjsip_tx_data *tdata ); 148 PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 149 pjsip_tx_data *tdata, 150 pjsip_tx_data **p_tdata); 144 151 145 152 … … 160 167 pjsip_host_port *addr); 161 168 162 163 169 /** 164 170 * @} -
pjproject/main/pjsip/include/pjsip/sip_module.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_MODULE_H__ -
pjproject/main/pjsip/include/pjsip/sip_msg.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_MSG_H__ … … 261 260 #define PJSIP_DECL_HDR_MEMBER(hdr) \ 262 261 /** List members. */ \ 263 PJ_DECL_LIST_MEMBER(hdr) \262 PJ_DECL_LIST_MEMBER(hdr); \ 264 263 /** Header type */ \ 265 264 pjsip_hdr_e type; \ … … 269 268 pj_str_t sname; \ 270 269 /** Virtual function table. */ \ 271 pjsip_hdr_vptr *vptr ;270 pjsip_hdr_vptr *vptr 272 271 273 272 … … 276 275 * message. All header fields can be typecasted to this type. 277 276 */ 278 typedefstruct pjsip_hdr279 { 280 PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr) 281 } pjsip_hdr;277 struct pjsip_hdr 278 { 279 PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr); 280 }; 282 281 283 282 … … 688 687 * value if the message is too large for the specified buffer. 689 688 */ 690 PJ_DECL( int) pjsip_msg_print(pjsip_msg *msg, char *buf, pj_size_t size);689 PJ_DECL(pj_ssize_t) pjsip_msg_print(pjsip_msg *msg, char *buf, pj_size_t size); 691 690 692 691 /** … … 708 707 typedef struct pjsip_generic_string_hdr 709 708 { 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. */ 711 710 pj_str_t hvalue; /**< hvalue */ 712 711 } pjsip_generic_string_hdr; … … 757 756 typedef struct pjsip_generic_int_hdr 758 757 { 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. */ 760 759 pj_int32_t ivalue; /**< ivalue */ 761 760 } pjsip_generic_int_hdr; … … 806 805 typedef struct pjsip_generic_array_hdr 807 806 { 808 PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr) 807 PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr); 809 808 unsigned count; /**< Number of elements. */ 810 809 pj_str_t values[PJSIP_GENERIC_ARRAY_MAX_COUNT]; /**< Elements. */ … … 887 886 typedef struct pjsip_cid_hdr 888 887 { 889 PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr) 888 PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr); 890 889 pj_str_t id; /**< Call-ID string. */ 891 890 } pjsip_cid_hdr; … … 918 917 typedef struct pjsip_clen_hdr 919 918 { 920 PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr) 919 PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr); 921 920 int len; /**< Content length. */ 922 921 } pjsip_clen_hdr; … … 946 945 typedef struct pjsip_cseq_hdr 947 946 { 948 PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr) 947 PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr); 949 948 int cseq; /**< CSeq number. */ 950 949 pjsip_method method; /**< CSeq method. */ … … 978 977 typedef struct pjsip_contact_hdr 979 978 { 980 PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr) 979 PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr); 981 980 int star; /**< The contact contains only a '*' character */ 982 981 pjsip_uri *uri; /**< URI in the contact. */ … … 1011 1010 typedef struct pjsip_ctype_hdr 1012 1011 { 1013 PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr) 1012 PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr); 1014 1013 pjsip_media_type media; /**< Media type. */ 1015 1014 } pjsip_ctype_hdr; … … 1062 1061 typedef struct pjsip_fromto_hdr 1063 1062 { 1064 PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr) 1063 PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr); 1065 1064 pjsip_uri *uri; /**< URI in From/To header. */ 1066 1065 pj_str_t tag; /**< Header "tag" parameter. */ … … 1171 1170 typedef struct pjsip_routing_hdr 1172 1171 { 1173 PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr) /**< Generic header fields. */1172 PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr); /**< Generic header fields. */ 1174 1173 pjsip_name_addr name_addr; /**< The URL in the Route/Record-Route header. */ 1175 1174 pj_str_t other_param; /** Other parameter. */ … … 1328 1327 typedef struct pjsip_via_hdr 1329 1328 { 1330 PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr) 1329 PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr); 1331 1330 pj_str_t transport; /**< Transport type. */ 1332 1331 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 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_PARSER_H__ … … 11 10 12 11 #include <pjsip/sip_types.h> 13 #include <pj /scanner.h>12 #include <pjlib-util/scanner.h> 14 13 #include <pj/list.h> 15 14 … … 52 51 typedef struct pjsip_parser_err_report 53 52 { 54 PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report) 53 PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report); 55 54 int exception_code; /**< Error exception (e.g. PJSIP_SYN_ERR_EXCEPTION) */ 56 55 int line; /**< Line number. */ … … 58 57 pj_str_t hname; /**< Header name, if any. */ 59 58 } pjsip_parser_err_report; 59 60 61 /** 62 * Parsing context, the default argument for parsing functions. 63 */ 64 typedef 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; 60 70 61 71 … … 77 87 * can be terminated when seeing EOF. 78 88 */ 79 typedef void* (pjsip_parse_hdr_func)(pj_scanner *scanner, pj_pool_t *pool);89 typedef pjsip_hdr* (pjsip_parse_hdr_func)(pjsip_parse_ctx *context); 80 90 81 91 /** … … 95 105 * @param fptr The pointer to function to parser the header. 96 106 * 97 * @return zero if success. 98 * @see pjsip_parse_hdr_func 107 * @return PJ_SUCCESS if success, or the appropriate error code. 99 108 */ 100 109 PJ_DECL(pj_status_t) pjsip_register_hdr_parser( const char *hname, … … 186 195 187 196 /** 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 */ 214 PJ_DECL(pjsip_msg *) pjsip_parse_rdata( char *buf, pj_size_t size, 215 pjsip_rx_data *rdata ); 216 217 /** 188 218 * Check incoming packet to see if a (probably) valid SIP message has been 189 219 * received. … … 194 224 * the size of the SIP message (including body, if any). 195 225 * 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 */ 228 PJ_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); 200 232 201 233 /** … … 248 280 */ 249 281 extern 250 pj_c har_specpjsip_HOST_SPEC, /* For scanning host part. */282 pj_cis_t pjsip_HOST_SPEC, /* For scanning host part. */ 251 283 pjsip_DIGIT_SPEC, /* Decimal digits */ 252 284 pjsip_ALPHA_SPEC, /* Alpha (A-Z, a-z) */ -
pjproject/main/pjsip/include/pjsip/sip_private.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_PRIVATE_H__ … … 27 26 * @param cb Callback to be called to receive messages from transport. 28 27 */ 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 *)); 28 PJ_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 **); 32 33 33 34 … … 36 37 * @param mgr Transport manager to be destroyed. 37 38 */ 38 PJ_DECL( void) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr );39 PJ_DECL(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ); 39 40 40 41 /** -
pjproject/main/pjsip/include/pjsip/sip_resolve.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_RESOLVE_H__ -
pjproject/main/pjsip/include/pjsip/sip_transaction.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_TRANSACTION_H__ … … 12 11 #include <pjsip/sip_msg.h> 13 12 #include <pjsip/sip_resolve.h> 14 //#include <pjsip/sip_config.h>15 //#include <pjsip/sip_endpoint.h>16 13 #include <pj/timer.h> 17 14 … … 24 21 */ 25 22 23 /* Forward decl. */ 26 24 struct pjsip_transaction; 27 25 … … 62 60 struct pjsip_transaction 63 61 { 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. */ 91 112 void *module_data[PJSIP_MAX_MODULE]; 92 113 }; … … 94 115 95 116 /** 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. 100 137 */ 101 138 PJ_DECL(pj_status_t) pjsip_tsx_init_uac( pjsip_transaction *tsx, … … 104 141 /** 105 142 * 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 * 108 147 * @return PJ_SUCCESS if successfull. 109 148 */ … … 113 152 /** 114 153 * 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. 117 157 */ 118 158 PJ_DECL(void) pjsip_tsx_on_rx_msg( pjsip_transaction *tsx, … … 121 161 /** 122 162 * 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. 125 166 */ 126 167 PJ_DECL(void) pjsip_tsx_on_tx_msg( pjsip_transaction *tsx, … … 135 176 * transaction will comply with RFC-3261, i.e. it will set itself to 136 177 * 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. 139 181 */ 140 182 PJ_DECL(void) pjsip_tsx_on_tx_ack( pjsip_transaction *tsx, … … 142 184 143 185 /** 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. 147 190 */ 148 191 PJ_DECL(void) pjsip_tsx_terminate( pjsip_transaction *tsx, … … 152 195 * Create transaction key, which is used to match incoming requests 153 196 * 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 */ 206 PJ_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 165 212 166 213 /** … … 184 231 185 232 /* Thread Local Storage ID for transaction lock (initialized by endpoint) */ 186 extern intpjsip_tsx_lock_tls_id;233 extern long pjsip_tsx_lock_tls_id; 187 234 188 235 PJ_END_DECL -
pjproject/main/pjsip/include/pjsip/sip_transport.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_TRANSPORT_H__ … … 14 13 #include <pj/sock.h> 15 14 #include <pj/list.h> 15 #include <pj/ioqueue.h> 16 16 17 17 PJ_BEGIN_DECL … … 37 37 struct pjsip_rx_data 38 38 { 39 PJ_DECL_LIST_MEMBER(struct pjsip_rx_data)39 //PJ_DECL_LIST_MEMBER(struct pjsip_rx_data); 40 40 41 41 /** Memory pool for this buffer. */ 42 42 pj_pool_t *pool; 43 44 /** Ioqueue op key. */ 45 pj_ioqueue_op_key_t op_key; 43 46 44 47 /** Time when the message was received. */ … … 74 77 pjsip_from_hdr *from; 75 78 76 /** The tag in the From header as found in the message. */77 pj_str_t from_tag;78 79 79 /** The To header as found in the message. */ 80 80 pjsip_to_hdr *to; 81 81 82 /** The To tag header as found in the message. */83 pj_str_t to_tag;84 85 82 /** The topmost Via header as found in the message. */ 86 83 pjsip_via_hdr *via; … … 88 85 /** The CSeq header as found in the message. */ 89 86 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; 90 105 91 106 /** The list of error generated by the parser when parsing this message. */ … … 110 125 struct pjsip_tx_data 111 126 { 112 PJ_DECL_LIST_MEMBER(struct pjsip_tx_data) 127 PJ_DECL_LIST_MEMBER(struct pjsip_tx_data); 113 128 114 129 /** Memory pool for this buffer. */ … … 127 142 /** The transport manager for this buffer. */ 128 143 pjsip_transport_mgr *mgr; 144 145 /** Ioqueue asynchronous operation key. */ 146 pj_ioqueue_op_key_t op_key; 129 147 130 148 /** The message in this buffer. */ … … 357 375 * @param tdata The outgoing message buffer. 358 376 * @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 */ 382 PJ_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); 366 386 367 387 … … 387 407 * @return The transmit buffer data, or NULL on error. 388 408 */ 389 pjsip_tx_data* pjsip_tx_data_create( pjsip_transport_mgr *mgr ); 409 pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr, 410 pjsip_tx_data **tdata ); 390 411 391 412 -
pjproject/main/pjsip/include/pjsip/sip_types.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #ifndef __PJSIP_SIP_TYPES_H__ … … 74 73 75 74 /** 75 * Forward declaration for header field (sip_msg.h). 76 */ 77 typedef struct pjsip_hdr pjsip_hdr; 78 79 /** 76 80 * Forward declaration for URI (sip_uri.h). 77 81 */ … … 135 139 136 140 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 */ 148 PJ_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 137 160 #endif /* __PJSIP_SIP_TYPES_H__ */ 138 161 -
pjproject/main/pjsip/include/pjsip/sip_uri.h
- Property svn:keywords set to Id
r38 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #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 1 1 /* $Id$ 2 *3 2 */ 4 3 #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
*
-
Property
svn:ignore
set to
-
pjproject/main/pjsip/src/pjsip/sip_auth.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_auth.h> … … 6 5 #include <pjsip/sip_transport.h> 7 6 #include <pjsip/sip_endpoint.h> 8 #include <pj /md5.h>7 #include <pjlib-util/md5.h> 9 8 #include <pj/log.h> 10 9 #include <pj/string.h> 11 10 #include <pj/pool.h> 12 11 #include <pj/guid.h> 12 #include <pj/assert.h> 13 #include <pj/ctype.h> 13 14 14 15 /* Length of digest string. */ … … 147 148 p = qop.ptr; 148 149 while (*p) { 149 *p = (char) tolower(*p);150 *p = (char)pj_tolower(*p); 150 151 ++p; 151 152 } … … 218 219 cred->qop = pjsip_AUTH_STR; 219 220 cred->nc.ptr = pj_pool_alloc(pool, 16); 220 sprintf(cred->nc.ptr, "%06u", nc);221 pj_snprintf(cred->nc.ptr, 16, "%06u", nc); 221 222 222 223 if (cnonce && cnonce->slen) { … … 485 486 { 486 487 unsigned i; 487 PJ_UNUSED_ARG(scheme) 488 PJ_UNUSED_ARG(scheme); 488 489 for (i=0; i<count; ++i) { 489 490 if (pj_stricmp(&cred[i].realm, realm) == 0) … … 716 717 pjsip_via_hdr *via; 717 718 718 PJ_UNUSED_ARG(endpt) 719 PJ_UNUSED_ARG(endpt); 719 720 720 721 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 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_auth_msg.h> … … 7 6 #include <pj/list.h> 8 7 #include <pj/string.h> 9 #include <pjsip/print.h> 8 #include <pj/assert.h> 9 #include <pjsip/print_util.h> 10 10 11 11 /////////////////////////////////////////////////////////////////////////////// … … 68 68 static int print_pgp_credential(pjsip_pgp_credential *cred, char *buf, pj_size_t size) 69 69 { 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); 73 73 return -1; 74 74 } … … 213 213 char *buf, pj_size_t size) 214 214 { 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); 218 218 return -1; 219 219 } -
pjproject/main/pjsip/src/pjsip/sip_auth_parser.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_auth_parser.h> 5 4 #include <pjsip/sip_auth_msg.h> 6 5 #include <pjsip/sip_parser.h> 6 #include <pj/assert.h> 7 7 #include <pj/string.h> 8 8 #include <pj/except.h> 9 9 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); 10 static pjsip_hdr* parse_hdr_authorization ( pjsip_parse_ctx *ctx ); 11 static pjsip_hdr* parse_hdr_proxy_authorization ( pjsip_parse_ctx *ctx ); 12 static pjsip_hdr* parse_hdr_www_authenticate ( pjsip_parse_ctx *ctx ); 13 static pjsip_hdr* parse_hdr_proxy_authenticate ( pjsip_parse_ctx *ctx ); 14 15 static void parse_digest_credential ( pj_scanner *scanner, pj_pool_t *pool, 16 pjsip_digest_credential *cred); 17 static void parse_pgp_credential ( pj_scanner *scanner, pj_pool_t *pool, 18 pjsip_pgp_credential *cred); 19 static void parse_digest_challenge ( pj_scanner *scanner, pj_pool_t *pool, 20 pjsip_digest_challenge *chal); 21 static void parse_pgp_challenge ( pj_scanner *scanner, pj_pool_t *pool, 22 pjsip_pgp_challenge *chal); 19 23 20 24 const pj_str_t pjsip_USERNAME_STR = { "username", 8 }, … … 44 48 45 49 46 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred) 50 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, 51 pjsip_digest_credential *cred) 47 52 { 48 53 for (;;) { 49 54 pj_str_t name, value; 50 55 51 pjsip_parse_param_imp(scanner, &name, &value, 56 pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 52 57 53 58 if (!pj_stricmp(&name, &pjsip_USERNAME_STR)) { … … 82 87 83 88 } else { 84 pjsip_concat_param_imp(&cred->other_param, pool, &name,&value, ',');89 pjsip_concat_param_imp(&cred->other_param,pool,&name,&value, ','); 85 90 } 86 91 87 92 /* Eat comma */ 88 if (!pj_scan_is_eof(scanner) && *scanner->cur rent== ',')93 if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 89 94 pj_scan_get_char(scanner); 90 95 else … … 93 98 } 94 99 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) 100 static 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); 100 106 101 107 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 102 108 } 103 109 104 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal) 110 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, 111 pjsip_digest_challenge *chal) 105 112 { 106 113 for (;;) { 107 114 pj_str_t name, value; 108 115 109 pjsip_parse_param_imp(scanner, &name, &value, 116 pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 110 117 111 118 if (!pj_stricmp(&name, &pjsip_REALM_STR)) { … … 122 129 123 130 } 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 { 125 134 chal->stale = 1; 135 } 126 136 127 137 } else if (!pj_stricmp(&name, &pjsip_ALGORITHM_STR)) { … … 133 143 134 144 } else { 135 pjsip_concat_param_imp(&chal->other_param, pool, &name, &value, ','); 145 pjsip_concat_param_imp(&chal->other_param, pool, 146 &name, &value, ','); 136 147 } 137 148 138 149 /* Eat comma */ 139 if (!pj_scan_is_eof(scanner) && *scanner->cur rent== ',')150 if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 140 151 pj_scan_get_char(scanner); 141 152 else … … 144 155 } 145 156 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) 157 static 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); 151 163 152 164 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 153 165 } 154 166 155 static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, 167 static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, 156 168 pjsip_authorization_hdr *hdr) 157 169 { 158 if (*scanner->cur rent== '"') {170 if (*scanner->curptr == '"') { 159 171 pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 160 172 hdr->scheme.ptr++; 161 173 hdr->scheme.slen -= 2; 162 174 } else { 163 pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme);175 pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 164 176 } 165 177 … … 182 194 pjsip_www_authenticate_hdr *hdr) 183 195 { 184 if (*scanner->cur rent== '"') {196 if (*scanner->curptr == '"') { 185 197 pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 186 198 hdr->scheme.ptr++; 187 199 hdr->scheme.slen -= 2; 188 200 } else { 189 pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme);201 pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 190 202 } 191 203 … … 206 218 207 219 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); 220 static 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 227 static 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 235 static 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 243 static 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 252 PJ_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; 243 270 } 244 271 -
pjproject/main/pjsip/src/pjsip/sip_endpoint.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_endpoint.h> … … 9 8 #include <pjsip/sip_module.h> 10 9 #include <pjsip/sip_misc.h> 10 #include <pjsip/sip_errno.h> 11 11 #include <pj/except.h> 12 12 #include <pj/log.h> … … 15 15 #include <pj/pool.h> 16 16 #include <pj/hash.h> 17 #include <pj/assert.h> 18 #include <pj/errno.h> 17 19 18 20 19 21 #define PJSIP_EX_NO_MEMORY PJ_NO_MEMORY_EXCEPTION 20 #define LOG_THIS "endpoint..."22 #define THIS_FILE "endpoint" 21 23 22 24 #define MAX_METHODS 32 … … 85 87 * Defined in sip_transaction.c 86 88 */ 87 pjsip_transaction * pjsip_tsx_create( pj_pool_t *pool, pjsip_endpoint *endpt); 89 pj_status_t pjsip_tsx_create( pj_pool_t *pool, pjsip_endpoint *endpt, 90 pjsip_transaction **tsx ); 88 91 89 92 /* … … 95 98 static void pool_callback( pj_pool_t *pool, pj_size_t size ) 96 99 { 97 PJ_UNUSED_ARG(pool) 98 PJ_UNUSED_ARG(size) 100 PJ_UNUSED_ARG(pool); 101 PJ_UNUSED_ARG(size); 99 102 100 103 PJ_THROW(PJSIP_EX_NO_MEMORY); … … 112 115 extern pjsip_module aux_tsx_module; 113 116 114 PJ_LOG(5, ( LOG_THIS, "init_modules()"));117 PJ_LOG(5, (THIS_FILE, "init_modules()")); 115 118 116 119 /* Load static modules. */ … … 165 168 endpt->methods[endpt->method_cnt++] = mod->methods[j]; 166 169 } else { 167 PJ_LOG(1,( LOG_THIS, "Too many methods"));170 PJ_LOG(1,(THIS_FILE, "Too many methods")); 168 171 return -1; 169 172 } … … 201 204 pjsip_transaction *tsx) 202 205 { 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)); 204 207 205 208 pj_assert(tsx->state == PJSIP_TSX_STATE_DESTROYED); … … 227 230 pj_pool_release(tsx->pool); 228 231 229 PJ_LOG(4, ( LOG_THIS, "tsx%p destroyed", tsx));232 PJ_LOG(4, (THIS_FILE, "tsx%p destroyed", tsx)); 230 233 } 231 234 … … 248 251 249 252 /* 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) 252 255 { 253 256 /* 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 ); 255 258 } 256 259 } … … 262 265 void pjsip_endpt_send_tsx_event( pjsip_endpoint *endpt, pjsip_event *evt ) 263 266 { 267 // Need to protect this with try/catch? 264 268 endpt_do_event(endpt, evt); 265 269 } … … 302 306 if (!hdr) { 303 307 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)); 305 309 return -1; 306 310 } … … 328 332 * Initialize endpoint. 329 333 */ 330 PJ_DEF(pjsip_endpoint*) pjsip_endpt_create(pj_pool_factory *pf) 334 PJ_DEF(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf, 335 pjsip_endpoint **p_endpt) 331 336 { 332 337 pj_status_t status; … … 335 340 pjsip_max_forwards_hdr *mf_hdr; 336 341 337 PJ_LOG(5, (LOG_THIS, "pjsip_endpt_create()")); 342 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create()")); 343 344 *p_endpt = NULL; 338 345 339 346 /* Create pool */ … … 342 349 &pool_callback); 343 350 if (!pool) 344 return NULL;351 return PJ_ENOMEM; 345 352 346 353 /* Create endpoint. */ … … 350 357 351 358 /* 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) { 355 361 goto on_error; 356 362 } 357 363 358 364 /* 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) { 362 368 goto on_error; 363 369 } … … 366 372 endpt->tsx_table = pj_hash_create( endpt->pool, PJSIP_MAX_TSX_COUNT ); 367 373 if (!endpt->tsx_table) { 368 PJ_LOG(4, (LOG_THIS, "pjsip_endpt_init(): error creating tsx hash table"));374 status = PJ_ENOMEM; 369 375 goto on_error; 370 376 } 371 377 372 378 /* 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) { 376 382 goto on_error; 377 383 } 378 384 379 385 /* Create transport manager. */ 380 endpt->transport_mgr= pjsip_transport_mgr_create( endpt->pool,381 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) { 385 391 goto on_error; 386 392 } … … 389 395 endpt->resolver = pjsip_resolver_create(endpt->pool); 390 396 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")); 392 398 goto on_error; 393 399 } 394 400 395 401 /* 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) { 399 404 goto on_error; 400 405 } … … 415 420 status = init_modules(endpt); 416 421 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; 419 424 } 420 425 421 426 /* Done. */ 422 return endpt; 427 *p_endpt = endpt; 428 return status; 423 429 424 430 on_error: … … 437 443 pj_pool_release( endpt->pool ); 438 444 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; 441 447 } 442 448 … … 446 452 PJ_DEF(void) pjsip_endpt_destroy(pjsip_endpoint *endpt) 447 453 { 448 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_destroy()"));454 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_destroy()")); 449 455 450 456 /* Shutdown and destroy all transports. */ … … 471 477 pj_pool_t *pool; 472 478 473 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_create_pool()"));479 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_pool()")); 474 480 475 481 /* Lock endpoint mutex. */ … … 484 490 485 491 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))); 487 493 } 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)); 489 495 } 490 496 … … 498 504 PJ_DEF(void) pjsip_endpt_destroy_pool( pjsip_endpoint *endpt, pj_pool_t *pool ) 499 505 { 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))); 501 507 502 508 pj_mutex_lock(endpt->mutex); … … 514 520 int i; 515 521 516 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_handle_events()"));522 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_handle_events()")); 517 523 518 524 /* Poll the timer. The timer heap has its own mutex for better … … 544 550 const pj_time_val *delay ) 545 551 { 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)", 547 553 entry, delay->sec, delay->msec)); 548 554 return pj_timer_heap_schedule( endpt->timer_heap, entry, delay ); … … 555 561 pj_timer_entry *entry ) 556 562 { 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)); 558 564 pj_timer_heap_cancel( endpt->timer_heap, entry ); 559 565 } … … 564 570 * register it to the hash table. 565 571 */ 566 PJ_DEF(pjsip_transaction*) pjsip_endpt_create_tsx(pjsip_endpoint *endpt) 572 PJ_DEF(pj_status_t) pjsip_endpt_create_tsx(pjsip_endpoint *endpt, 573 pjsip_transaction **p_tsx) 567 574 { 568 575 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()")); 572 580 573 581 /* Request one pool for the transaction. Mutex is locked there. */ … … 575 583 PJSIP_POOL_LEN_TSX, PJSIP_POOL_INC_TSX); 576 584 if (pool == NULL) { 577 PJ_LOG(2, (LOG_THIS, "failed to create transaction (no pool)")); 578 return NULL; 585 return PJ_ENOMEM; 579 586 } 580 587 581 588 /* 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); 586 590 } 587 591 … … 595 599 pjsip_transaction *tsx) 596 600 { 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)); 598 602 599 603 pj_assert(tsx->transaction_key.slen != 0); … … 619 623 pjsip_transaction *tsx; 620 624 621 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_find_tsx()"));625 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_find_tsx()")); 622 626 623 627 /* Start lock mutex in the endpoint. */ … … 659 663 pj_bool_t a_new_transaction_just_been_created = PJ_FALSE; 660 664 661 PJ_LOG(5, ( LOG_THIS, "endpt_transport_callback(rdata=%p)", rdata));665 PJ_LOG(5, (THIS_FILE, "endpt_transport_callback(rdata=%p)", rdata)); 662 666 663 667 /* For response, check that the value in Via sent-by match the transport. … … 676 680 } 677 681 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); 679 683 if (pj_strcmp2(&rdata->via->sent_by.host, addr_addr) != 0) 680 684 mismatch = PJ_TRUE; 681 else if (port != pj_ sockaddr_get_port(addr)) {685 else if (port != pj_ntohs(addr->sin_port)) { 682 686 /* Port or address mismatch, we should discard response */ 683 687 /* But we saw one implementation (we don't want to name it to … … 687 691 * both the port in sent-by and rport. We try to be lenient here! 688 692 */ 689 if (rdata->via->rport_param != pj_sockaddr_ get_port(addr))693 if (rdata->via->rport_param != pj_sockaddr_in_get_port(addr)) 690 694 mismatch = PJ_TRUE; 691 695 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" 693 697 " but the rport parameter is correct", 694 698 rdata)); … … 699 703 pjsip_event e; 700 704 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); 708 706 endpt_do_event( endpt, &e ); 709 707 return; … … 715 713 716 714 /* 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", 718 716 rdata->key.slen, rdata->key.ptr)); 719 717 … … 748 746 pj_assert(0); 749 747 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); 754 749 endpt_do_event( endpt, &e ); 755 750 … … 758 753 pjsip_event e; 759 754 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)); 767 757 endpt_do_event( endpt, &e ); 768 758 } … … 772 762 */ 773 763 } else if (rdata->msg->line.req.method.id != PJSIP_ACK_METHOD) { 764 765 pj_status_t status; 766 774 767 /* 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")); 777 772 return; 773 } 778 774 779 775 /* Initialize transaction as UAS. */ … … 803 799 pjsip_event event; 804 800 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); 809 802 endpt_do_event( endpt, &event ); 810 803 } … … 835 828 */ 836 829 pjsip_tx_data *tdata; 830 pj_status_t status; 837 831 838 832 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); 840 835 } 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 844 847 if (endpt->allow_hdr) { 845 848 pjsip_msg_add_hdr( tdata->msg, … … 856 859 */ 857 860 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 859 870 pjsip_tsx_on_tx_msg(tsx, tdata); 860 871 } … … 865 876 * Create transmit data buffer. 866 877 */ 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); 878 PJ_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); 871 883 } 872 884 … … 880 892 pjsip_resolver_callback *cb) 881 893 { 882 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_resolve()"));894 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_resolve()")); 883 895 pjsip_resolve( endpt->resolver, pool, target, token, cb); 884 896 } … … 894 906 pjsip_transport_completion_callback *cb) 895 907 { 896 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_get_transport()"));908 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_get_transport()")); 897 909 pjsip_transport_get( endpt->transport_mgr, pool, type, 898 910 remote, token, cb); … … 905 917 const pj_sockaddr_in *addr_name) 906 918 { 907 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_create_listener()"));919 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_listener()")); 908 920 return pjsip_create_listener( endpt->transport_mgr, type, addr, addr_name ); 909 921 } … … 913 925 const pj_sockaddr_in *addr_name) 914 926 { 915 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_create_udp_listener()"));927 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_create_udp_listener()")); 916 928 return pjsip_create_udp_listener( endpt->transport_mgr, sock, addr_name ); 917 929 } … … 924 936 pj_hash_iterator_t *itr; 925 937 926 PJ_LOG(5, ( LOG_THIS, "pjsip_endpt_dump()"));938 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_dump()")); 927 939 928 940 /* Lock mutex. */ 929 941 pj_mutex_lock(endpt->mutex); 930 942 931 PJ_LOG(3, ( LOG_THIS, "Dumping endpoint %p:", endpt));943 PJ_LOG(3, (THIS_FILE, "Dumping endpoint %p:", endpt)); 932 944 933 945 /* Dumping pool factory. */ … … 935 947 936 948 /* 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", 938 950 pj_pool_get_capacity(endpt->pool), 939 951 pj_pool_get_used_size(endpt->pool))); … … 941 953 /* Transaction tables. */ 942 954 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)); 944 956 945 957 if (count && detail) { … … 948 960 pj_time_val now; 949 961 950 PJ_LOG(3, ( LOG_THIS, " Dumping transaction tables:"));962 PJ_LOG(3, (THIS_FILE, " Dumping transaction tables:")); 951 963 952 964 pj_gettimeofday(&now); … … 975 987 } 976 988 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", 978 990 tsx->obj_name, role, 979 991 tsx->method.name.slen, tsx->method.name.ptr, … … 992 1004 itr = pjsip_transport_first( endpt->transport_mgr, &itr_val ); 993 1005 if (itr) { 994 PJ_LOG(3, ( LOG_THIS, " Dumping transports:"));1006 PJ_LOG(3, (THIS_FILE, " Dumping transports:")); 995 1007 996 1008 do { … … 1002 1014 t = pjsip_transport_this(endpt->transport_mgr, itr); 1003 1015 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); 1006 1018 1007 1019 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)", 1012 1024 pjsip_transport_get_type_name(t), 1013 1025 pjsip_transport_get_obj_name(t), … … 1021 1033 1022 1034 /* Timer. */ 1023 PJ_LOG(3,( LOG_THIS, " Timer heap has %u entries",1035 PJ_LOG(3,(THIS_FILE, " Timer heap has %u entries", 1024 1036 pj_timer_heap_count(endpt->timer_heap))); 1025 1037 … … 1027 1039 pj_mutex_unlock(endpt->mutex); 1028 1040 #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.")); 1030 1042 #endif 1031 1043 } -
pjproject/main/pjsip/src/pjsip/sip_misc.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_misc.h> … … 14 13 #include <pj/pool.h> 15 14 #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" 18 20 19 21 static const char *event_str[] = … … 45 47 struct pjsip_module *mod, pj_uint32_t id ) 46 48 { 47 PJ_UNUSED_ARG(endpt) 48 PJ_UNUSED_ARG(mod) 49 PJ_UNUSED_ARG(endpt); 50 PJ_UNUSED_ARG(mod); 49 51 50 52 aux_mod_id = id; … … 54 56 static void aux_tsx_handler( struct pjsip_module *mod, pjsip_event *event ) 55 57 { 56 pjsip_transaction *tsx = event->obj.tsx;58 pjsip_transaction *tsx; 57 59 struct aux_tsx_data *tsx_data; 58 60 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) 62 64 return; 65 66 pj_assert(event->body.tsx_state.tsx != NULL); 67 tsx = event->body.tsx_state.tsx; 63 68 if (tsx == NULL) 64 69 return; … … 101 106 pjsip_transaction *tsx; 102 107 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); 105 111 if (!tsx) { 106 112 pjsip_tx_data_dec_ref(tdata); … … 135 141 * this function. 136 142 */ 137 static void init_request_throw( pjsip_tx_data *tdata, 143 static void init_request_throw( pjsip_endpoint *endpt, 144 pjsip_tx_data *tdata, 138 145 pjsip_method *method, 139 146 pjsip_uri *param_target, … … 147 154 pjsip_msg *msg; 148 155 pjsip_msg_body *body; 156 const pjsip_hdr *endpt_hdr; 149 157 150 158 /* Create the message. */ … … 154 162 pj_memcpy(&msg->line.req.method, method, sizeof(*method)); 155 163 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 } 156 172 157 173 /* Add From header. */ … … 190 206 * Create arbitrary request. 191 207 */ 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) 208 PJ_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) 201 218 { 202 219 pjsip_uri *target; … … 208 225 pjsip_cid_hdr *call_id; 209 226 pj_str_t tmp; 227 pj_status_t status; 210 228 PJ_USE_EXCEPTION; 211 229 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; 217 235 218 236 /* Init reference counter to 1. */ … … 224 242 target = pjsip_parse_uri( tdata->pool, tmp.ptr, tmp.slen, 0); 225 243 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", 227 245 tmp.ptr)); 228 246 goto on_error; … … 235 253 PJSIP_PARSE_URI_AS_NAMEADDR); 236 254 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'", 238 256 tmp.ptr)); 239 257 goto on_error; … … 247 265 PJSIP_PARSE_URI_AS_NAMEADDR); 248 266 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'", 250 268 tmp.ptr)); 251 269 goto on_error; … … 259 277 PJSIP_PARSE_URI_AS_NAMEADDR); 260 278 if (contact->uri == NULL) { 261 PJ_LOG(4,( LOG_THIS,279 PJ_LOG(4,(THIS_FILE, 262 280 "Error creating request: invalid 'Contact' URI '%s'", 263 281 tmp.ptr)); … … 286 304 287 305 /* Create the request. */ 288 init_request_throw( tdata, &cseq->method, target, from, to, contact,289 306 init_request_throw( endpt, tdata, &cseq->method, target, from, to, 307 contact, call_id, cseq, param_text); 290 308 } 291 309 PJ_DEFAULT { 292 PJ_LOG(4,(LOG_THIS, "Caught exception %d when creating request", 293 PJ_GET_EXCEPTION())); 310 status = PJ_ENOMEM; 294 311 goto on_error; 295 312 } 296 313 PJ_END 297 314 298 PJ_LOG(4,( LOG_THIS, "Request %s (%d %.*s) created.",315 PJ_LOG(4,(THIS_FILE, "Request %s (%d %.*s) created.", 299 316 tdata->obj_name, 300 317 cseq->cseq, … … 302 319 cseq->method.name.ptr)); 303 320 304 return tdata; 321 *p_tdata = tdata; 322 return PJ_SUCCESS; 305 323 306 324 on_error: 307 325 pjsip_tx_data_dec_ref(tdata); 308 return NULL;309 } 310 311 PJ_DEF(pj sip_tx_data*)326 return status; 327 } 328 329 PJ_DEF(pj_status_t) 312 330 pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, 313 331 const pjsip_method *method, … … 318 336 const pjsip_cid_hdr *param_call_id, 319 337 int param_cseq, 320 const pj_str_t *param_text ) 338 const pj_str_t *param_text, 339 pjsip_tx_data **p_tdata) 321 340 { 322 341 pjsip_uri *target; … … 327 346 pjsip_cid_hdr *call_id; 328 347 pjsip_cseq_hdr *cseq = NULL; /* The NULL because warning in VC6 */ 348 pj_status_t status; 329 349 PJ_USE_EXCEPTION; 330 350 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; 336 356 337 357 pjsip_tx_data_add_ref(tdata); … … 355 375 pjsip_method_copy(tdata->pool, &cseq->method, method); 356 376 357 init_request_throw( tdata, &cseq->method, target, from, to, contact,358 377 init_request_throw(endpt, tdata, &cseq->method, target, from, to, 378 contact, call_id, cseq, param_text); 359 379 } 360 380 PJ_DEFAULT { 361 PJ_LOG(4,(LOG_THIS, "Caught exception %d when creating request", 362 PJ_GET_EXCEPTION())); 381 status = PJ_ENOMEM; 363 382 goto on_error; 364 383 } 365 384 PJ_END; 366 385 367 PJ_LOG(4,( LOG_THIS, "Request %s (%d %.*s) created.",386 PJ_LOG(4,(THIS_FILE, "Request %s (%d %.*s) created.", 368 387 tdata->obj_name, 369 388 cseq->cseq, 370 389 cseq->method.name.slen, 371 390 cseq->method.name.ptr)); 372 return tdata; 391 392 *p_tdata = tdata; 393 return PJ_SUCCESS; 373 394 374 395 on_error: 375 396 pjsip_tx_data_dec_ref(tdata); 376 return NULL;397 return status; 377 398 } 378 399 … … 380 401 * Construct a minimal response message for the received request. 381 402 */ 382 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_response( pjsip_endpoint *endpt, 383 const pjsip_rx_data *rdata, 384 int code) 403 PJ_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) 385 407 { 386 408 pjsip_tx_data *tdata; … … 389 411 pjsip_via_hdr *via; 390 412 pjsip_rr_hdr *rr; 413 pj_status_t status; 391 414 392 415 /* rdata must be a request message. */ … … 395 418 396 419 /* 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)", 398 421 rdata, code)); 399 422 400 423 /* 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; 404 427 405 428 /* Create new response message. */ … … 452 475 453 476 /* All done. */ 454 return tdata; 477 *p_tdata = tdata; 478 return PJ_SUCCESS; 455 479 } 456 480 … … 479 503 480 504 /* 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)); 482 506 483 507 /* Create new request message. */ … … 503 527 to = (pjsip_to_hdr*)pjsip_msg_find_remove_hdr( invite_msg, 504 528 PJSIP_H_TO, NULL); 505 pj_strdup(tdata->pool, &to->tag, &rdata->to _tag);529 pj_strdup(tdata->pool, &to->tag, &rdata->to->tag); 506 530 pjsip_msg_add_hdr( ack_msg, (pjsip_hdr*)to ); 507 531 … … 543 567 * chapter 9.1 of RFC3261. 544 568 */ 545 PJ_DEF(pjsip_tx_data*) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 546 pjsip_tx_data *req_tdata ) 569 PJ_DEF(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 570 pjsip_tx_data *req_tdata, 571 pjsip_tx_data **p_tdata) 547 572 { 548 573 pjsip_msg *req_msg; /* the original request. */ … … 552 577 pjsip_cseq_hdr *req_cseq, *cseq; 553 578 pjsip_uri *req_uri; 579 pj_status_t status; 554 580 555 581 /* 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)); 557 583 558 584 /* Get the original request. */ … … 560 586 561 587 /* 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); 564 591 565 592 /* 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; 569 596 } 570 597 … … 624 651 * Return the transmit buffer containing the CANCEL request. 625 652 */ 626 return cancel_tdata; 653 *p_tdata = cancel_tdata; 654 return PJ_SUCCESS; 627 655 } 628 656 … … 651 679 remote_addr = pjsip_transport_get_remote_addr(req_transport); 652 680 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); 655 683 656 684 } else { -
pjproject/main/pjsip/src/pjsip/sip_msg.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_msg.h> 5 #include <pjsip/print .h>4 #include <pjsip/print_util.h> 6 5 #include <pj/string.h> 7 6 #include <pj/pool.h> … … 265 264 } 266 265 267 PJ_DEF( int) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size)266 PJ_DEF(pj_ssize_t) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size) 268 267 { 269 268 char *p=buf, *end=buf+size; -
pjproject/main/pjsip/src/pjsip/sip_parser.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_parser.h> … … 6 5 #include <pjsip/sip_msg.h> 7 6 #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> 9 10 #include <pj/except.h> 10 11 #include <pj/log.h> … … 13 14 #include <pj/pool.h> 14 15 #include <pj/string.h> 15 #include <ctype.h> /* tolower() */ 16 #include <pj/ctype.h> 17 #include <pj/assert.h> 16 18 17 19 #define RESERVED ";/?:@&=+$," … … 20 22 #define USER "&=+$,;?/" 21 23 #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! */ 23 26 #define HOST "_-." 24 27 #define HEX_DIGIT "abcdefABCDEF" … … 46 49 * Global vars (also extern). 47 50 */ 48 const pj_str_t pjsip_USER_STR = { "user", 4};49 const pj_str_t pjsip_METHOD_STR = { "method", 6};51 const pj_str_t pjsip_USER_STR = { "user", 4}; 52 const pj_str_t pjsip_METHOD_STR = { "method", 6}; 50 53 const 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. */ 54 const pj_str_t pjsip_MADDR_STR = { "maddr", 5 }; 55 const pj_str_t pjsip_LR_STR = { "lr", 2 }; 56 const pj_str_t pjsip_SIP_STR = { "sip", 3 }; 57 const pj_str_t pjsip_SIPS_STR = { "sips", 4 }; 58 const pj_str_t pjsip_TEL_STR = { "tel", 3 }; 59 const pj_str_t pjsip_BRANCH_STR = { "branch", 6 }; 60 const pj_str_t pjsip_TTL_STR = { "ttl", 3 }; 61 const pj_str_t pjsip_PNAME_STR = { "received", 8 }; 62 const pj_str_t pjsip_Q_STR = { "q", 1 }; 63 const pj_str_t pjsip_EXPIRES_STR = { "expires", 7 }; 64 const pj_str_t pjsip_TAG_STR = { "tag", 3 }; 65 const pj_str_t pjsip_RPORT_STR = { "rport", 5}; 66 67 /* Character Input Specification buffer. */ 68 static pj_cis_buf_t cis_buf; 69 70 /* Character Input Specifications. */ 71 pj_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. */ 77 86 78 87 … … 80 89 * Forward decl. 81 90 */ 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); 91 static pjsip_msg * int_parse_msg( pjsip_parse_ctx *ctx, 92 pjsip_parser_err_report *err_list); 93 static void int_parse_param( pj_scanner *scanner, 94 pj_str_t *pname, 95 pj_str_t *pvalue); 96 static void int_parse_req_line( pj_scanner *scanner, 97 pj_pool_t *pool, 98 pjsip_request_line *req_line); 99 static int int_is_next_user( pj_scanner *scanner); 100 static void int_parse_status_line( pj_scanner *scanner, 101 pjsip_status_line *line); 102 static void int_parse_user_pass( pj_scanner *scanner, 103 pj_str_t *user, 104 pj_str_t *pass); 105 static void int_parse_uri_host_port( pj_scanner *scanner, 106 pj_str_t *p_host, 107 int *p_port); 108 static pjsip_uri * int_parse_uri_or_name_addr( pj_scanner *scanner, 109 pj_pool_t *pool, 110 unsigned option); 111 static pjsip_url * int_parse_sip_url( pj_scanner *scanner, 112 pj_pool_t *pool, 113 pj_bool_t parse_params); 114 static pjsip_name_addr * 115 int_parse_name_addr( pj_scanner *scanner, 116 pj_pool_t *pool ); 117 static void parse_hdr_end( pj_scanner *scanner ); 118 119 static pjsip_hdr* parse_hdr_accept( pjsip_parse_ctx *ctx ); 120 static pjsip_hdr* parse_hdr_allow( pjsip_parse_ctx *ctx ); 121 static pjsip_hdr* parse_hdr_call_id( pjsip_parse_ctx *ctx); 122 static pjsip_hdr* parse_hdr_contact( pjsip_parse_ctx *ctx); 123 static pjsip_hdr* parse_hdr_content_len( pjsip_parse_ctx *ctx ); 124 static pjsip_hdr* parse_hdr_content_type( pjsip_parse_ctx *ctx ); 125 static pjsip_hdr* parse_hdr_cseq( pjsip_parse_ctx *ctx ); 126 static pjsip_hdr* parse_hdr_expires( pjsip_parse_ctx *ctx ); 127 static pjsip_hdr* parse_hdr_from( pjsip_parse_ctx *ctx ); 128 static pjsip_hdr* parse_hdr_max_forwards( pjsip_parse_ctx *ctx); 129 static pjsip_hdr* parse_hdr_min_expires( pjsip_parse_ctx *ctx ); 130 static pjsip_hdr* parse_hdr_rr( pjsip_parse_ctx *ctx ); 131 static pjsip_hdr* parse_hdr_route( pjsip_parse_ctx *ctx ); 132 static pjsip_hdr* parse_hdr_require( pjsip_parse_ctx *ctx ); 133 static pjsip_hdr* parse_hdr_retry_after( pjsip_parse_ctx *ctx ); 134 static pjsip_hdr* parse_hdr_supported( pjsip_parse_ctx *ctx ); 135 static pjsip_hdr* parse_hdr_to( pjsip_parse_ctx *ctx ); 136 static pjsip_hdr* parse_hdr_unsupported( pjsip_parse_ctx *ctx ); 137 static pjsip_hdr* parse_hdr_via( pjsip_parse_ctx *ctx ); 138 static pjsip_hdr* parse_hdr_generic_string( pjsip_parse_ctx *ctx); 148 139 149 140 /* Convert non NULL terminated string to integer. */ 150 static unsigned long pj_strtoul_mindigit(const pj_str_t *str, unsigned mindig) 141 static unsigned long pj_strtoul_mindigit(const pj_str_t *str, 142 unsigned mindig) 151 143 { 152 144 unsigned long value; … … 164 156 165 157 /* 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 169 160 170 161 /* Syntax error handler for parser. */ 171 162 static void on_syntax_error(pj_scanner *scanner) 172 163 { 173 PJ_UNUSED_ARG(scanner) 164 PJ_UNUSED_ARG(scanner); 174 165 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 175 166 } … … 177 168 /* Concatenate unrecognized params into single string. */ 178 169 void 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) 180 172 { 181 173 char *new_param, *p; … … 214 206 215 207 /* Initialize static properties of the parser. */ 216 static voidinit_parser()208 static pj_status_t init_parser() 217 209 { 218 210 static int initialized; 211 pj_status_t status; 219 212 220 213 if (initialized) 221 return ;214 return PJ_SUCCESS; 222 215 223 216 initialized = 1; 224 217 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); 227 223 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"); 232 236 //pj_cs_set(pjsip_NEWLINE_OR_EOF_SPEC, 0); 233 237 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); 278 338 279 339 /* 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 345 static void init_sip_parser(void) 285 346 { 286 347 if (!parser_is_initialized) { … … 318 379 319 380 /* Equal length and equal hash. compare the strings. */ 320 return strcmp(r1->hname, name);381 return pj_native_strcmp(r1->hname, name); 321 382 } 322 383 323 384 /* Register one handler for one header name. */ 324 static int int_register_parser( const char *name, pjsip_parse_hdr_func *fptr ) 385 static pj_status_t int_register_parser( const char *name, 386 pjsip_parse_hdr_func *fptr ) 325 387 { 326 388 unsigned pos; … … 329 391 330 392 if (handler_count >= PJ_ARRAY_SIZE(handler)) { 331 return -1;393 return PJ_ETOOMANY; 332 394 } 333 395 … … 336 398 rec.hname_len = strlen(name); 337 399 if (rec.hname_len >= sizeof(rec.hname)) { 338 return -1;400 return PJ_ENAMETOOLONG; 339 401 } 340 402 /* Name is copied in lowercase. */ 341 403 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]); 343 405 } 344 406 rec.hname[i] = '\0'; … … 349 411 for (pos=0; pos < handler_count; ++pos) { 350 412 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); 352 415 if (d == 0) { 353 416 pj_assert(0); 354 return -1;417 return PJ_EEXISTS; 355 418 } 356 419 if (d > 0) { … … 361 424 /* Shift handlers. */ 362 425 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)); 364 428 } 365 429 /* Add new handler. */ … … 367 431 ++handler_count; 368 432 369 return 0;433 return PJ_SUCCESS; 370 434 } 371 435 … … 377 441 pjsip_parse_hdr_func *fptr) 378 442 { 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; 386 455 } 387 456 … … 393 462 pj_uint32_t hash; 394 463 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 } 396 470 397 471 /* Calculate hash value while converting the header to lowercase. 398 472 * Don't assume that 'hname' is NULL terminated. 399 473 */ 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'; 406 476 407 477 /* Binary search for the handler. */ … … 429 499 430 500 /* Public function to parse SIP message. */ 431 PJ_DEF(pjsip_msg*) pjsip_parse_msg( pj_pool_t *pool, char *buf, pj_size_t size, 501 PJ_DEF(pjsip_msg*) pjsip_parse_msg( pj_pool_t *pool, 502 char *buf, pj_size_t size, 432 503 pjsip_parser_err_report *err_list) 433 504 { 434 505 pjsip_msg *msg = NULL; 435 506 pj_scanner scanner; 507 pjsip_parse_ctx context; 436 508 PJ_USE_EXCEPTION; 437 509 438 510 init_sip_parser(); 439 511 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; 441 518 442 519 PJ_TRY { 443 msg = int_parse_msg(& scanner, pool, err_list);520 msg = int_parse_msg(&context, err_list); 444 521 } 445 522 PJ_DEFAULT { … … 450 527 pj_scan_fini(&scanner); 451 528 return msg; 529 } 530 531 /* Public function to parse as rdata.*/ 532 PJ_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; 452 558 } 453 559 … … 467 573 /* For datagram, the whole datagram IS the message. */ 468 574 if (is_datagram) { 469 return PJ_ TRUE;575 return PJ_SUCCESS; 470 576 } 471 577 472 578 473 579 /* 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; 476 582 } 477 583 … … 480 586 481 587 /* Find "Content-Length" header the hard way. */ 482 line = strchr(buf, '\n');588 line = pj_native_strchr(buf, '\n'); 483 589 while (line && line < hdr_end-14) { 484 590 ++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)==':'))) 487 595 { 488 596 /* Try to parse the header. */ … … 510 618 511 619 /* Get number */ 512 pj_scan_get(&scanner, pjsip_DIGIT_SPEC, &str_clen);620 pj_scan_get(&scanner, &pjsip_DIGIT_SPEC, &str_clen); 513 621 514 622 /* Get newline. */ … … 528 636 529 637 /* Go to next line. */ 530 line = strchr(line, '\n');638 line = pj_native_strchr(line, '\n'); 531 639 } 532 640 533 641 /* Found Content-Length? */ 534 642 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; 538 644 } 539 645 540 646 /* Enough packet received? */ 541 647 *msg_size = (body_start - buf) + content_length; 542 return (*msg_size) <= size ;648 return (*msg_size) <= size ? PJ_SUCCESS : PJSIP_EPARTIALMSG; 543 649 #else 544 PJ_UNUSED_ARG(buf) 545 PJ_UNUSED_ARG(is_datagram) 650 PJ_UNUSED_ARG(buf); 651 PJ_UNUSED_ARG(is_datagram); 546 652 *msg_size = size; 547 return 1;653 return PJ_SUCCESS; 548 654 #endif 549 655 } … … 558 664 pjsip_uri *uri = NULL; 559 665 560 if (!parser_is_initialized) { 561 init_parser(); 562 parser_is_initialized = 1; 563 } 666 init_sip_parser(); 564 667 565 668 pj_scan_init(&scanner, buf, size, 0, &on_syntax_error); … … 572 675 573 676 /* 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 { 575 680 /* Success. */ 576 681 pj_scan_fini(&scanner); … … 587 692 * actual body is laid. 588 693 */ 589 static int generic_print_body (pjsip_msg_body *msg_body, char *buf, pj_size_t size) 694 static int generic_print_body (pjsip_msg_body *msg_body, 695 char *buf, pj_size_t size) 590 696 { 591 697 pjsip_msg_body *body = msg_body; … … 598 704 599 705 /* Internal function to parse SIP message */ 600 static pjsip_msg *int_parse_msg( pj _scanner *scanner, pj_pool_t *pool,706 static pjsip_msg *int_parse_msg( pjsip_parse_ctx *ctx, 601 707 pjsip_parser_err_report *err_list) 602 708 { … … 605 711 pjsip_msg *msg; 606 712 pjsip_ctype_hdr *ctype_hdr = NULL; 713 pj_scanner *scanner = ctx->scanner; 714 pj_pool_t *pool = ctx->pool; 607 715 608 716 /* Skip leading newlines. */ 609 ch = *scanner->cur rent;717 ch = *scanner->curptr; 610 718 while (ch=='\r' || ch=='\n') { 611 719 pj_scan_get_char(scanner); 612 ch = *scanner->cur rent;720 ch = *scanner->curptr; 613 721 } 614 722 … … 631 739 632 740 /* Get hname. */ 633 pj_scan_get( scanner, pjsip_TOKEN_SPEC, &hname);741 pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &hname); 634 742 ch = pj_scan_get_char( scanner ); 635 743 if (ch != ':') { … … 646 754 */ 647 755 if (handler) { 648 hdr = (*handler)( scanner, pool);756 hdr = (*handler)(ctx); 649 757 } 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; 654 761 } 655 762 … … 669 776 hdr = NULL; 670 777 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)); 673 781 674 782 if (err_list) { … … 685 793 686 794 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); 688 796 parse_hdr_end(scanner); 689 797 } … … 703 811 /* Parse until EOF or an empty line is found. */ 704 812 } while (!pj_scan_is_eof(scanner) && 705 *scanner->cur rent != '\r' && *scanner->current!= '\n');813 *scanner->curptr != '\r' && *scanner->curptr != '\n'); 706 814 707 815 /* If empty line is found, eat it. */ 708 816 if (!pj_scan_is_eof(scanner)) { 709 if (*scanner->cur rent=='\r' || *scanner->current=='\n') {817 if (*scanner->curptr=='\r' || *scanner->curptr=='\n') { 710 818 pj_scan_get_newline(scanner); 711 819 } 712 820 } 713 821 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.*/ 715 823 if (ctype_hdr) { 716 824 pjsip_msg_body *body = pj_pool_alloc(pool, sizeof(pjsip_msg_body)); 717 pj_strdup 718 pj_strdup 719 pj_strdup 720 body->data = scanner->cur rent;721 body->len = scanner->end - scanner->cur rent;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; 722 830 body->print_body = &generic_print_body; 723 831 … … 734 842 { 735 843 /* pname */ 736 pj_scan_get(scanner, pjsip_PARAM_CHAR_SPEC, pname);844 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pname); 737 845 738 846 /* pvalue, if any */ 739 if (*scanner->cur rent== '=') {847 if (*scanner->curptr == '=') { 740 848 pj_scan_get_char(scanner); 741 849 /* pvalue can be a quoted string. */ 742 if (*scanner->cur rent== '"') {850 if (*scanner->curptr == '"') { 743 851 pj_scan_get_quote( scanner, '"', '"', pvalue); 744 852 if (option & PJSIP_PARSE_REMOVE_QUOTE) { … … 747 855 } 748 856 } else { 749 pj_scan_get(scanner, pjsip_PARAM_CHAR_SPEC, pvalue);857 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 750 858 } 751 859 } else { … … 770 878 pj_str_t *host, int *p_port) 771 879 { 772 pj_scan_get( scanner, pjsip_HOST_SPEC, host);773 if (*scanner->cur rent== ':') {880 pj_scan_get( scanner, &pjsip_HOST_SPEC, host); 881 if (*scanner->curptr == ':') { 774 882 pj_str_t port; 775 883 pj_scan_get_char(scanner); 776 pj_scan_get(scanner, pjsip_DIGIT_SPEC, &port);884 pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &port); 777 885 *p_port = pj_strtoul(&port); 778 886 } else { … … 790 898 * must be a username. 791 899 */ 792 if (pj_scan_peek( scanner, pjsip_PROBE_USER_HOST_SPEC, &dummy) == '@')900 if (pj_scan_peek( scanner, &pjsip_PROBE_USER_HOST_SPEC, &dummy) == '@') 793 901 is_user = 1; 794 902 else … … 802 910 pj_str_t *user, pj_str_t *pass) 803 911 { 804 pj_scan_get( scanner, pjsip_USER_SPEC, user);805 if ( *scanner->cur rent== ':') {912 pj_scan_get( scanner, &pjsip_USER_SPEC, user); 913 if ( *scanner->curptr == ':') { 806 914 pj_scan_get_char( scanner ); 807 pj_scan_get( scanner, pjsip_PASSWD_SPEC, pass);915 pj_scan_get( scanner, &pjsip_PASSWD_SPEC, pass); 808 916 } else { 809 917 pass->ptr = NULL; … … 816 924 817 925 /* 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)926 static pjsip_uri *int_parse_uri_or_name_addr( pj_scanner *scanner, pj_pool_t *pool, 927 unsigned opt) 820 928 { 821 929 pjsip_uri *uri; 822 930 int is_name_addr = 0; 823 931 824 if (*scanner->cur rent=='"' || *scanner->current=='<') {932 if (*scanner->curptr=='"' || *scanner->curptr=='<') { 825 933 uri = (pjsip_uri*)int_parse_name_addr( scanner, pool ); 826 934 is_name_addr = 1; … … 831 939 832 940 pj_scan_save_state( scanner, &backtrack); 833 pj_scan_get( scanner, pjsip_TOKEN_SPEC, &scheme);941 pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &scheme); 834 942 colon = pj_scan_get_char( scanner ); 835 943 pj_scan_restore_state( scanner, &backtrack); 836 944 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)) 838 948 { 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); 841 952 842 953 } else if (colon==':' && parser_stricmp( scheme, pjsip_TEL_STR)==0) { … … 853 964 854 965 /* Should we return the URI object as name address? */ 855 if (opt ion& PJSIP_PARSE_URI_AS_NAMEADDR) {966 if (opt & PJSIP_PARSE_URI_AS_NAMEADDR) { 856 967 if (is_name_addr == 0) { 857 968 pjsip_name_addr *name_addr; … … 871 982 pj_bool_t parse_params) 872 983 { 873 if (*scanner->cur rent=='"' || *scanner->current=='<') {984 if (*scanner->curptr=='"' || *scanner->curptr=='<') { 874 985 return (pjsip_uri*)int_parse_name_addr( scanner, pool ); 875 986 } else { … … 878 989 879 990 /* Get scheme. */ 880 colon = pj_scan_peek(scanner, pjsip_TOKEN_SPEC, &scheme);991 colon = pj_scan_peek(scanner, &pjsip_TOKEN_SPEC, &scheme); 881 992 if (colon != ':') { 882 993 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 883 994 } 884 995 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)) 886 998 { 887 return (pjsip_uri*)int_parse_sip_url( scanner, pool, parse_params 999 return (pjsip_uri*)int_parse_sip_url( scanner, pool, parse_params); 888 1000 889 1001 } else if (parser_stricmp(scheme, pjsip_TEL_STR)==0) { … … 909 1021 scanner->skip_ws = 0; 910 1022 911 pj_scan_get(scanner, pjsip_TOKEN_SPEC, &scheme);1023 pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &scheme); 912 1024 colon = pj_scan_get_char(scanner); 913 1025 if (colon != ':') { … … 938 1050 939 1051 /* Get URL parameters. */ 940 while ( parse_params && *scanner->cur rent== ';' ) {1052 while ( parse_params && *scanner->curptr == ';' ) { 941 1053 pj_str_t pname, pvalue; 942 1054 … … 949 1061 url->method_param = pvalue; 950 1062 951 } else if (!parser_stricmp(pname, 1063 } else if (!parser_stricmp(pname,pjsip_TRANSPORT_STR) && pvalue.slen) { 952 1064 url->transport_param = pvalue; 953 1065 … … 967 1079 968 1080 /* 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); 971 1084 } 972 1085 … … 985 1098 name_addr = pjsip_name_addr_create(pool); 986 1099 987 if (*scanner->cur rent== '"') {1100 if (*scanner->curptr == '"') { 988 1101 pj_scan_get_quote( scanner, '"', '"', &name_addr->display); 989 1102 990 } else if (*scanner->cur rent!= '<') {1103 } else if (*scanner->curptr != '<') { 991 1104 int next; 992 1105 pj_str_t dummy; … … 997 1110 * will be parser later. 998 1111 */ 999 next = pj_scan_peek_until(scanner, pjsip_DISPLAY_SCAN_SPEC, &dummy);1112 next = pj_scan_peek_until(scanner, &pjsip_DISPLAY_SCAN_SPEC, &dummy); 1000 1113 if (next == '<') { 1001 1114 /* Ok, this is what we're looking for, a display name. */ … … 1009 1122 1010 1123 /* Get the SIP-URL */ 1011 has_bracket = (*scanner->cur rent== '<');1124 has_bracket = (*scanner->curptr == '<'); 1012 1125 if (has_bracket) 1013 1126 pj_scan_get_char(scanner); … … 1026 1139 pj_str_t token; 1027 1140 1028 pj_scan_get( scanner, pjsip_TOKEN_SPEC, &token);1141 pj_scan_get( scanner, &pjsip_TOKEN_SPEC, &token); 1029 1142 pjsip_method_init_np( &req_line->method, &token); 1030 1143 … … 1046 1159 pj_scan_advance_n( scanner, 7, 1); 1047 1160 1048 pj_scan_get( scanner, pjsip_DIGIT_SPEC, &token);1161 pj_scan_get( scanner, &pjsip_DIGIT_SPEC, &token); 1049 1162 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); 1051 1165 pj_scan_get_newline( scanner ); 1052 1166 } … … 1057 1171 if (pj_scan_is_eof(scanner)) { 1058 1172 ; /* Do nothing. */ 1059 } else if (*scanner->cur rent== '&') {1173 } else if (*scanner->curptr == '&') { 1060 1174 pj_scan_get_char(scanner); 1061 1175 } else { … … 1074 1188 pj_scanner *scanner) 1075 1189 { 1076 pj_scan_get_until( scanner, pjsip_ARRAY_ELEMENTS, &hdr->values[0]);1190 pj_scan_get_until( scanner, &pjsip_ARRAY_ELEMENTS, &hdr->values[0]); 1077 1191 hdr->count++; 1078 1192 1079 while (*scanner->cur rent== ',') {1193 while (*scanner->curptr == ',') { 1080 1194 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]); 1082 1197 hdr->count++; 1083 1198 } … … 1089 1204 pj_scanner *scanner ) 1090 1205 { 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); 1092 1207 parse_hdr_end(scanner); 1093 1208 } … … 1098 1213 { 1099 1214 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); 1101 1216 hdr->ivalue = pj_strtoul(&tmp); 1102 1217 parse_hdr_end(scanner); … … 1105 1220 1106 1221 /* 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; 1222 static 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; 1113 1227 } 1114 1228 1115 1229 /* 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; 1230 static 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; 1122 1235 } 1123 1236 1124 1237 /* 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; 1238 static 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; 1132 1248 } 1133 1249 … … 1137 1253 pj_pool_t *pool) 1138 1254 { 1139 while ( *scanner->cur rent== ';' ) {1255 while ( *scanner->curptr == ';' ) { 1140 1256 pj_str_t pname, pvalue; 1141 1257 … … 1160 1276 1161 1277 /* Parse Contact header. */ 1162 PJ_DEF(pjsip_contact_hdr*) parse_hdr_contact( pj_scanner *scanner, 1163 pj_pool_t *pool) 1278 static pjsip_hdr* parse_hdr_contact( pjsip_parse_ctx *ctx ) 1164 1279 { 1165 1280 pjsip_contact_hdr *first = NULL; 1281 pj_scanner *scanner = ctx->scanner; 1166 1282 1167 1283 do { 1168 pjsip_contact_hdr *hdr = pjsip_contact_hdr_create( pool);1284 pjsip_contact_hdr *hdr = pjsip_contact_hdr_create(ctx->pool); 1169 1285 if (first == NULL) 1170 1286 first = hdr; … … 1172 1288 pj_list_insert_before(first, hdr); 1173 1289 1174 if (*scanner->cur rent== '*') {1290 if (*scanner->curptr == '*') { 1175 1291 pj_scan_get_char(scanner); 1176 1292 hdr->star = 1; … … 1178 1294 } else { 1179 1295 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 != ',') 1186 1303 break; 1187 1304 … … 1191 1308 1192 1309 parse_hdr_end(scanner); 1193 return first; 1310 1311 return (pjsip_hdr*)first; 1194 1312 } 1195 1313 1196 1314 /* Parse Content-Length header. */ 1197 PJ_DEF(pjsip_clen_hdr*) parse_hdr_content_length( pj_scanner *scanner, 1198 pj_pool_t *pool) 1315 static pjsip_hdr* parse_hdr_content_len( pjsip_parse_ctx *ctx ) 1199 1316 { 1200 1317 pj_str_t digit; 1201 1318 pjsip_clen_hdr *hdr; 1202 1319 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); 1205 1322 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; 1208 1329 } 1209 1330 1210 1331 /* Parse Content-Type header. */ 1211 PJ_DEF(pjsip_ctype_hdr*) parse_hdr_content_type( pj_scanner *scanner, 1212 pj_pool_t *pool) 1332 static pjsip_hdr* parse_hdr_content_type( pjsip_parse_ctx *ctx ) 1213 1333 { 1214 1334 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); 1217 1338 1218 1339 /* 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); 1220 1341 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); 1222 1343 1223 1344 /* Parse media parameters */ 1224 while (*scanner->cur rent== ';') {1345 while (*scanner->curptr == ';') { 1225 1346 pj_str_t pname, pvalue; 1226 1347 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; 1232 1357 } 1233 1358 1234 1359 /* Parse CSeq header. */ 1235 PJ_DEF(pjsip_cseq_hdr*) parse_hdr_cseq( pj_scanner *scanner, 1236 pj_pool_t *pool) 1360 static pjsip_hdr* parse_hdr_cseq( pjsip_parse_ctx *ctx ) 1237 1361 { 1238 1362 pj_str_t cseq, method; 1239 1363 pjsip_cseq_hdr *hdr; 1240 1364 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); 1243 1367 hdr->cseq = pj_strtoul(&cseq); 1244 1368 1245 pj_scan_get( scanner,pjsip_TOKEN_SPEC, &method);1369 pj_scan_get( ctx->scanner, &pjsip_TOKEN_SPEC, &method); 1246 1370 pjsip_method_init_np(&hdr->method, &method); 1247 1371 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; 1250 1378 } 1251 1379 1252 1380 /* 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; 1381 static 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; 1259 1386 } 1260 1387 … … 1268 1395 PJSIP_PARSE_URI_IN_FROM_TO_HDR); 1269 1396 1270 while ( *scanner->cur rent== ';' ) {1397 while ( *scanner->curptr == ';' ) { 1271 1398 pj_str_t pname, pvalue; 1272 1399 … … 1285 1412 1286 1413 /* 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; 1414 static 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; 1293 1422 } 1294 1423 1295 1424 /* 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; 1425 static 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; 1302 1434 } 1303 1435 1304 1436 /* Parse Retry-After: header. */ 1305 static pjsip_retry_after_hdr* parse_hdr_retry_after(pj_scanner *scanner, 1306 pj_pool_t *pool) 1437 static pjsip_hdr* parse_hdr_retry_after(pjsip_parse_ctx *ctx) 1307 1438 { 1308 1439 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; 1312 1443 } 1313 1444 1314 1445 /* 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; 1446 static 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; 1321 1451 } 1322 1452 1323 1453 1324 1454 /* 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; 1455 static 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; 1331 1464 } 1332 1465 1333 1466 /* 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; 1467 static 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; 1340 1472 } 1341 1473 … … 1344 1476 pj_pool_t *pool) 1345 1477 { 1346 while ( *scanner->cur rent== ';' ) {1478 while ( *scanner->curptr == ';' ) { 1347 1479 pj_str_t pname, pvalue; 1348 1480 … … 1374 1506 1375 1507 /* Parse Max-Forwards header. */ 1376 static pjsip_max_forwards_hdr* parse_hdr_max_forwards( pj_scanner *scanner, 1377 pj_pool_t *pool) 1508 static pjsip_hdr* parse_hdr_max_forwards( pjsip_parse_ctx *ctx ) 1378 1509 { 1379 1510 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; 1383 1518 } 1384 1519 1385 1520 /* Parse Min-Expires header. */ 1386 static pjsip_min_expires_hdr* parse_hdr_min_expires(pj_scanner *scanner, 1387 pj_pool_t *pool) 1521 static pjsip_hdr* parse_hdr_min_expires(pjsip_parse_ctx *ctx) 1388 1522 { 1389 1523 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; 1393 1527 } 1394 1528 … … 1401 1535 1402 1536 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); 1405 1540 } 1406 1541 } 1407 1542 1408 1543 /* Parse Record-Route header. */ 1409 PJ_DEF(pjsip_rr_hdr*) parse_hdr_rr( pj_scanner *scanner, pj_pool_t *pool)1544 static pjsip_hdr* parse_hdr_rr( pjsip_parse_ctx *ctx) 1410 1545 { 1411 1546 pjsip_rr_hdr *first = NULL; 1547 pj_scanner *scanner = ctx->scanner; 1412 1548 1413 1549 do { 1414 pjsip_rr_hdr *hdr = pjsip_rr_hdr_create( pool);1550 pjsip_rr_hdr *hdr = pjsip_rr_hdr_create(ctx->pool); 1415 1551 if (!first) { 1416 1552 first = hdr; … … 1418 1554 pj_list_insert_before(first, hdr); 1419 1555 } 1420 parse_hdr_rr_route(scanner, pool, hdr);1421 if (*scanner->cur rent== ',') {1556 parse_hdr_rr_route(scanner, ctx->pool, hdr); 1557 if (*scanner->curptr == ',') { 1422 1558 pj_scan_get_char(scanner); 1423 1559 } else { … … 1426 1562 } while (1); 1427 1563 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; 1429 1569 } 1430 1570 1431 1571 /* Parse Route: header. */ 1432 PJ_DEF(pjsip_route_hdr*) parse_hdr_route( pj_scanner *scanner, 1433 pj_pool_t *pool) 1572 static pjsip_hdr* parse_hdr_route( pjsip_parse_ctx *ctx ) 1434 1573 { 1435 1574 pjsip_route_hdr *first = NULL; 1575 pj_scanner *scanner = ctx->scanner; 1436 1576 1437 1577 do { 1438 pjsip_route_hdr *hdr = pjsip_route_hdr_create( pool);1578 pjsip_route_hdr *hdr = pjsip_route_hdr_create(ctx->pool); 1439 1579 if (!first) { 1440 1580 first = hdr; … … 1442 1582 pj_list_insert_before(first, hdr); 1443 1583 } 1444 parse_hdr_rr_route(scanner, pool, hdr);1445 if (*scanner->cur rent== ',') {1584 parse_hdr_rr_route(scanner, ctx->pool, hdr); 1585 if (*scanner->curptr == ',') { 1446 1586 pj_scan_get_char(scanner); 1447 1587 } else { … … 1450 1590 } while (1); 1451 1591 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; 1453 1597 } 1454 1598 1455 1599 /* Parse Via: header. */ 1456 PJ_DEF(pjsip_via_hdr*) parse_hdr_via( pj_scanner *scanner, pj_pool_t *pool)1600 static pjsip_hdr* parse_hdr_via( pjsip_parse_ctx *ctx ) 1457 1601 { 1458 1602 pjsip_via_hdr *first = NULL; 1603 pj_scanner *scanner = ctx->scanner; 1459 1604 1460 1605 do { 1461 pjsip_via_hdr *hdr = pjsip_via_hdr_create( pool);1606 pjsip_via_hdr *hdr = pjsip_via_hdr_create(ctx->pool); 1462 1607 if (!first) 1463 1608 first = hdr; … … 1470 1615 pj_scan_advance_n( scanner, 8, 1); 1471 1616 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->cur rent==':') {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==':') { 1476 1621 pj_str_t digit; 1477 1622 pj_scan_get_char(scanner); 1478 pj_scan_get(scanner, pjsip_DIGIT_SPEC, &digit);1623 pj_scan_get(scanner, &pjsip_DIGIT_SPEC, &digit); 1479 1624 hdr->sent_by.port = pj_strtoul(&digit); 1480 1625 } else { … … 1482 1627 } 1483 1628 1484 int_parse_via_param(hdr, scanner, pool);1485 1486 if (*scanner->cur rent== '(') {1629 int_parse_via_param(hdr, scanner, ctx->pool); 1630 1631 if (*scanner->curptr == '(') { 1487 1632 pj_scan_get_char(scanner); 1488 1633 pj_scan_get_until_ch( scanner, ')', &hdr->comment); … … 1490 1635 } 1491 1636 1492 if (*scanner->cur rent!= ',')1637 if (*scanner->curptr != ',') 1493 1638 break; 1494 1639 … … 1498 1643 1499 1644 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; 1501 1650 } 1502 1651 1503 1652 /* Parse generic header. */ 1504 PJ_DEF(pjsip_generic_string_hdr*) parse_hdr_generic_string( pj_scanner *scanner, 1505 pj_pool_t *pool) 1653 static pjsip_hdr* parse_hdr_generic_string( pjsip_parse_ctx *ctx ) 1506 1654 { 1507 1655 pjsip_generic_string_hdr *hdr; 1508 1656 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; 1512 1660 1513 1661 } … … 1519 1667 pj_scanner scanner; 1520 1668 pjsip_hdr *hdr = NULL; 1669 pjsip_parse_ctx context; 1521 1670 PJ_USE_EXCEPTION; 1522 1671 1523 1672 init_sip_parser(); 1524 1673 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; 1526 1680 1527 1681 PJ_TRY { 1528 1682 pjsip_parse_hdr_func *handler = find_handler(hname); 1529 1683 if (handler) { 1530 hdr = (*handler)(& scanner, pool);1684 hdr = (*handler)(&context); 1531 1685 } 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; 1537 1690 } 1538 1691 … … 1544 1697 1545 1698 if (parsed_len) { 1546 *parsed_len = (scanner.cur rent- scanner.begin);1699 *parsed_len = (scanner.curptr - scanner.begin); 1547 1700 } 1548 1701 -
pjproject/main/pjsip/src/pjsip/sip_resolve.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 … … 6 5 #include <pjsip/sip_transport.h> 7 6 #include <pj/pool.h> 8 #include <ctype.h> 7 #include <pj/ctype.h> 8 #include <pj/assert.h> 9 9 10 10 struct pjsip_resolver_t … … 22 22 PJ_DEF(void) pjsip_resolver_destroy(pjsip_resolver_t *resolver) 23 23 { 24 PJ_UNUSED_ARG(resolver) 24 PJ_UNUSED_ARG(resolver); 25 25 } 26 26 … … 31 31 32 32 while (p != end) { 33 if ( isdigit(*p) || *p=='.') {33 if (pj_isdigit(*p) || *p=='.') { 34 34 ++p; 35 35 } else { … … 51 51 pjsip_transport_type_e type = target->type; 52 52 53 PJ_UNUSED_ARG(resolver) 54 PJ_UNUSED_ARG(pool) 53 PJ_UNUSED_ARG(resolver); 54 PJ_UNUSED_ARG(pool); 55 55 56 56 /* We only do synchronous resolving at this moment. */ … … 95 95 /* Resolve hostname. */ 96 96 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); 98 99 } 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); 100 102 pj_assert(status == PJ_SUCCESS); 101 103 } -
pjproject/main/pjsip/src/pjsip/sip_transaction.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_transaction.h> … … 8 7 #include <pjsip/sip_event.h> 9 8 #include <pjsip/sip_endpoint.h> 9 #include <pjsip/sip_errno.h> 10 10 #include <pj/log.h> 11 11 #include <pj/string.h> … … 13 13 #include <pj/guid.h> 14 14 #include <pj/pool.h> 15 #include <pj/assert.h> 15 16 16 17 /* Thread Local Storage ID for transaction lock (initialized by endpoint) */ 17 intpjsip_tsx_lock_tls_id;18 long pjsip_tsx_lock_tls_id; 18 19 19 20 /* State names */ … … 44 45 } tsx_lock_data; 45 46 47 46 48 /* 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 }; 49 static const pj_time_val t1_timer_val = { PJSIP_T1_TIMEOUT/1000, 50 PJSIP_T1_TIMEOUT%1000 }; 51 static const pj_time_val t4_timer_val = { PJSIP_T4_TIMEOUT/1000, 52 PJSIP_T4_TIMEOUT%1000 }; 53 static const pj_time_val td_timer_val = { PJSIP_TD_TIMEOUT/1000, 54 PJSIP_TD_TIMEOUT%1000 }; 50 55 static const pj_time_val timeout_timer_val = { (64*PJSIP_T1_TIMEOUT)/1000, 51 56 (64*PJSIP_T1_TIMEOUT)%1000 }; … … 59 64 60 65 /* 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 ); 66 static pj_status_t pjsip_tsx_on_state_null( pjsip_transaction *tsx, 67 pjsip_event *event); 68 static pj_status_t pjsip_tsx_on_state_calling( pjsip_transaction *tsx, 69 pjsip_event *event); 70 static pj_status_t pjsip_tsx_on_state_trying( pjsip_transaction *tsx, 71 pjsip_event *event); 72 static pj_status_t pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx, 73 pjsip_event *event); 74 static pj_status_t pjsip_tsx_on_state_proceeding_uac( pjsip_transaction *tsx, 75 pjsip_event *event); 76 static pj_status_t pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx, 77 pjsip_event *event); 78 static pj_status_t pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, 79 pjsip_event *event); 80 static pj_status_t pjsip_tsx_on_state_confirmed(pjsip_transaction *tsx, 81 pjsip_event *event); 82 static pj_status_t pjsip_tsx_on_state_terminated(pjsip_transaction *tsx, 83 pjsip_event *event); 84 static pj_status_t pjsip_tsx_on_state_destroyed(pjsip_transaction *tsx, 85 pjsip_event *event); 86 87 static void tsx_timer_callback( pj_timer_heap_t *theap, 88 pj_timer_entry *entry); 89 static int tsx_send_msg( pjsip_transaction *tsx, 90 pjsip_tx_data *tdata); 91 static void lock_tsx( pjsip_transaction *tsx, struct 92 tsx_lock_data *lck ); 93 static pj_status_t unlock_tsx( pjsip_transaction *tsx, 94 struct tsx_lock_data *lck ); 86 95 87 96 /* 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) =97 static int (*tsx_state_handler_uac[PJSIP_TSX_STATE_MAX])(pjsip_transaction *, 98 pjsip_event *) = 90 99 { 91 100 &pjsip_tsx_on_state_null, … … 100 109 101 110 /* State handlers for UAS */ 102 static int (*tsx_state_handler_uas[PJSIP_TSX_STATE_MAX])(pjsip_transaction * tsx,103 pjsip_event * event) =111 static int (*tsx_state_handler_uas[PJSIP_TSX_STATE_MAX])(pjsip_transaction *, 112 pjsip_event *) = 104 113 { 105 114 &pjsip_tsx_on_state_null, … … 154 163 * components. Additional comparison is needed to fully match a transaction. 155 164 */ 156 voidcreate_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 )165 static 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 ) 161 170 { 162 171 #define SEPARATOR '$' … … 167 176 pj_str_t *host; 168 177 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 169 184 host = &rdata->via->sent_by.host; 170 185 req_uri = (pjsip_uri*)rdata->msg->line.req.uri; 171 186 172 187 /* 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. */ 176 190 rdata->call_id.slen + /* Call-ID */ 177 191 host->slen + /* Via host. */ 178 192 9 + /* Via port. */ 179 32; /* Separator+Allowance. */193 16; /* Separator+Allowance. */ 180 194 key = p = pj_pool_alloc(pool, len_required); 181 195 end = p + len_required; … … 224 238 * request retransmissions will contain the same port. 225 239 */ 226 if ((end-p) < host->slen + 12) {227 goto on_error;228 }229 240 pj_memcpy(p, host->ptr, host->slen); 230 241 p += host->slen; … … 241 252 str->slen = p-key; 242 253 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; 251 255 } 252 256 … … 254 258 * Create transaction key for RFC3161 compliant system. 255 259 */ 256 voidcreate_tsx_key_3261( pj_pool_t *pool,257 258 259 260 const pj_str_t *branch)260 static 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) 261 265 { 262 266 char *p; 267 268 PJ_ASSERT_RETURN(pool && key && method && branch, PJ_EINVAL); 263 269 264 270 p = key->ptr = pj_pool_alloc(pool, branch->slen + method->name.slen + 4 ); … … 281 287 /* Set length */ 282 288 key->slen = p - key->ptr; 289 290 return PJ_SUCCESS; 283 291 } 284 292 … … 287 295 * in the transaction hash table. 288 296 */ 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}; 297 PJ_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 295 305 296 306 /* Get the branch parameter in the top-most Via. … … 301 311 const pj_str_t *branch = &rdata->via->branch_param; 302 312 303 if (pj_strncmp(branch, &rfc3261_branch, PJSIP_RFC3261_BRANCH_LEN) ==0) {313 if (pj_strncmp(branch,&rfc3261_branch,PJSIP_RFC3261_BRANCH_LEN)==0) { 304 314 305 315 /* Create transaction key. */ 306 create_tsx_key_3261(pool, key, role, method, branch);316 return create_tsx_key_3261(pool, key, role, method, branch); 307 317 308 318 } 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. 312 323 */ 313 create_tsx_key_2543( pool, key, role, method, rdata );324 return create_tsx_key_2543( pool, key, role, method, rdata ); 314 325 } 315 326 } … … 319 330 * Create new transaction. 320 331 */ 321 PJ_DEF(pjsip_transaction *) pjsip_tsx_create(pj_pool_t *pool, 322 pjsip_endpoint *endpt) 332 pj_status_t pjsip_tsx_create( pj_pool_t *pool, 333 pjsip_endpoint *endpt, 334 pjsip_transaction **p_tsx) 323 335 { 324 336 pjsip_transaction *tsx; 337 pj_status_t status; 325 338 326 339 tsx = pj_pool_calloc(pool, 1, sizeof(pjsip_transaction)); … … 336 349 tsx->timeout_timer.user_data = tsx; 337 350 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; 345 359 } 346 360 … … 353 367 354 368 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); 356 371 lck->prev = prev_data; 357 372 lck->tsx = tsx; … … 368 383 * will be set to zero. 369 384 */ 370 static pj_status_t unlock_tsx(pjsip_transaction *tsx, struct tsx_lock_data *lck) 385 static pj_status_t unlock_tsx( pjsip_transaction *tsx, 386 struct tsx_lock_data *lck) 371 387 { 372 388 pj_assert( (void*)pj_thread_local_get(pjsip_tsx_lock_tls_id) == lck); … … 376 392 pj_mutex_unlock(tsx->mutex); 377 393 378 return lck->is_alive ? 0 : -1;394 return lck->is_alive ? PJ_SUCCESS : PJSIP_ETSXDESTROYED; 379 395 } 380 396 … … 384 400 static void tsx_set_state( pjsip_transaction *tsx, 385 401 pjsip_tsx_state_e state, 386 const pjsip_event *event ) 402 pjsip_event_id_e event_src_type, 403 void *event_src ) 387 404 { 388 405 pjsip_event e; 389 406 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))); 393 410 394 411 /* Change state. */ … … 403 420 404 421 /* 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); 408 423 pjsip_endpt_send_tsx_event( tsx->endpt, &e ); 409 424 … … 414 429 415 430 /* 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 { 417 434 pjsip_transport_dec_ref( tsx->transport ); 418 435 tsx->transport = NULL; … … 484 501 while (last_route_hdr->next != (void*)&tdata->msg->hdr) { 485 502 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); 487 505 if (!hdr) 488 506 break; … … 564 582 pj_strdup(tdata->pool, &send_addr->host, &url->host); 565 583 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); 567 586 568 587 } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) { … … 571 590 pj_strdup(tdata->pool, &send_addr->host, &url->host); 572 591 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); 574 594 #if PJ_HAS_TCP 575 595 if (send_addr->type == PJSIP_TRANSPORT_TCP || … … 580 600 #endif 581 601 } 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; 585 604 } 586 605 … … 599 618 600 619 /* Success. */ 601 return 0;620 return PJ_SUCCESS; 602 621 } 603 622 … … 625 644 addr, tsx->dest_name.port)); 626 645 } 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", 628 647 pjsip_transport_get_type_name(tr), 629 648 addr, tsx->dest_name.port, status)); … … 634 653 635 654 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 642 655 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 643 656 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); 645 660 646 661 /* Unlock transaction. */ … … 649 664 } 650 665 651 /* See if transaction has already been terminated. If so, schedule to destroy652 * the transaction.666 /* See if transaction has already been terminated. 667 * If so, schedule to destroy the transaction. 653 668 */ 654 669 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { … … 691 706 692 707 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 699 708 lock_tsx(tsx, &lck); 700 709 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); 702 712 unlock_tsx(tsx, &lck); 703 713 return; … … 712 722 /* Create/find the transport for the remote address. */ 713 723 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))); 716 726 717 727 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_CONNECTING; … … 739 749 pjsip_cseq_hdr *cseq; 740 750 pjsip_via_hdr *via; 751 pj_status_t status; 741 752 struct tsx_lock_data lck; 742 const pjsip_hdr *endpt_hdr;743 753 744 754 PJ_LOG(4,(tsx->obj_name, "initializing tsx as UAC (tdata=%p)", tdata)); … … 756 766 pjsip_method_copy( tsx->pool, &tsx->method, &msg->line.req.method); 757 767 758 /* Generate branch parameter if it doesn't exist. */768 /* Generate Via header if it doesn't exist. */ 759 769 via = pjsip_msg_find_hdr(msg, PJSIP_H_VIA, NULL); 760 770 if (via == NULL) { … … 772 782 tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN; 773 783 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 786 792 787 793 /* 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 } 791 801 792 802 PJ_LOG(6, (tsx->obj_name, "tsx_key=%.*s", tsx->transaction_key.slen, … … 796 806 cseq = pjsip_msg_find_hdr(msg, PJSIP_H_CSEQ, NULL); 797 807 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; 800 811 } 801 812 tsx->cseq = cseq->cseq; … … 806 817 */ 807 818 tsx->state = PJSIP_TSX_STATE_NULL; 808 tsx->state_handler = pjsip_tsx_on_state_null;819 tsx->state_handler = &pjsip_tsx_on_state_null; 809 820 810 821 /* 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) { 819 824 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 820 825 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); 822 828 unlock_tsx(tsx, &lck); 823 return -1;829 return status; 824 830 } 825 831 … … 859 865 pj_str_t *branch; 860 866 pjsip_cseq_hdr *cseq; 867 pj_status_t status; 861 868 struct tsx_lock_data lck; 862 869 … … 878 885 * create transaction key. 879 886 */ 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 } 882 893 883 894 /* Duplicate branch parameter for transaction. */ … … 914 925 tsx->current_addr = 0; 915 926 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); 917 929 pj_memcpy(&tsx->remote_addr.entry[0].addr, 918 930 &rdata->addr, rdata->addr_len); … … 924 936 rdata->via, &tsx->dest_name); 925 937 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 934 938 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_FINAL; 935 939 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); 937 942 unlock_tsx(tsx, &lck); 938 943 return status; … … 944 949 */ 945 950 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, 947 953 tsx->dest_name.port)); 948 954 … … 976 982 977 983 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 } 983 992 984 993 /* Dispatch event to transaction. */ … … 1000 1009 pjsip_msg *msg; 1001 1010 pjsip_host_port dest_addr; 1002 pjsip_event event;1003 1011 pjsip_via_hdr *via; 1004 1012 struct tsx_lock_data lck; 1005 1013 pj_status_t status = PJ_SUCCESS; 1014 1015 /* Lock tsx. */ 1006 1016 lock_tsx(tsx, &lck); 1007 1017 … … 1024 1034 1025 1035 /* 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){ 1028 1038 goto on_error; 1029 1039 } … … 1089 1099 */ 1090 1100 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); 1095 1104 1096 1105 unlock_tsx(tsx, &lck); … … 1106 1115 pjsip_event event; 1107 1116 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); 1117 1123 1118 1124 /* Dispatch to transaction. */ 1119 1125 lock_tsx(tsx, &lck); 1120 (*tsx->state_handler)(tsx, &event);1126 status = (*tsx->state_handler)(tsx, &event); 1121 1127 unlock_tsx(tsx, &lck); 1122 1128 } … … 1131 1137 pjsip_event event; 1132 1138 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); 1140 1145 1141 1146 /* Dispatch to transaction. */ 1142 1147 lock_tsx(tsx, &lck); 1143 (*tsx->state_handler)(tsx, &event);1148 status = (*tsx->state_handler)(tsx, &event); 1144 1149 unlock_tsx(tsx, &lck); 1145 1150 } … … 1150 1155 PJ_DEF(void) pjsip_tsx_terminate( pjsip_transaction *tsx, int code ) 1151 1156 { 1152 pjsip_event event;1153 1157 struct tsx_lock_data lck; 1154 1158 1155 1159 lock_tsx(tsx, &lck); 1156 1157 1160 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); 1163 1163 1164 1164 unlock_tsx(tsx, &lck); … … 1170 1170 * transmitted when transport connection completion callback is called. 1171 1171 */ 1172 static int tsx_send_msg( pjsip_transaction *tsx, pjsip_tx_data *tdata) 1173 { 1174 pjsip_event event; 1172 static pj_status_t tsx_send_msg( pjsip_transaction *tsx, 1173 pjsip_tx_data *tdata) 1174 { 1175 pj_status_t status = PJ_SUCCESS; 1175 1176 1176 1177 PJ_LOG(5,(tsx->obj_name, "sending msg (tdata=%p)", tdata)); 1177 1178 1178 1179 if (tsx->transport_state == PJSIP_TSX_TRANSPORT_STATE_FINAL) { 1179 int sent;1180 pj_ssize_t sent; 1180 1181 pjsip_event before_tx_event; 1181 1182 … … 1200 1201 pjsip_transport_get_type_name(tsx->transport)); 1201 1202 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); 1204 1205 } 1205 1206 } 1206 1207 1207 1208 /* 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 ); 1214 1212 1215 1213 tsx->has_unsent_msg = 0; 1216 s ent= pjsip_transport_send_msg(1217 tsx->transport, tdata,1218 &tsx->remote_addr.entry[tsx->current_addr].addr1219 1220 if (s ent < 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) { 1221 1219 goto on_error; 1222 1220 } … … 1229 1227 on_error: 1230 1228 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; 1236 1232 } 1237 1233 … … 1242 1238 int should_restart_timer) 1243 1239 { 1240 pj_status_t status; 1241 1244 1242 PJ_LOG(4,(tsx->obj_name, "retransmiting (tdata=%p, count=%d, restart?=%d)", 1245 1243 tsx->last_tx, tsx->retransmit_count, should_restart_timer)); … … 1249 1247 ++tsx->retransmit_count; 1250 1248 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; 1253 1252 } 1254 1253 … … 1258 1257 int msec_time = (1 << (tsx->retransmit_count)) * PJSIP_T1_TIMEOUT; 1259 1258 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) 1261 1260 msec_time = PJSIP_T2_TIMEOUT; 1262 1261 1263 1262 timeout.sec = msec_time / 1000; 1264 1263 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); 1266 1266 } 1267 1267 … … 1272 1272 * Handler for events in state Null. 1273 1273 */ 1274 static int pjsip_tsx_on_state_null( pjsip_transaction *tsx, pjsip_event *event ) 1275 { 1274 static pj_status_t pjsip_tsx_on_state_null( pjsip_transaction *tsx, 1275 pjsip_event *event ) 1276 { 1277 pj_status_t status; 1278 1276 1279 pj_assert( tsx->state == PJSIP_TSX_STATE_NULL); 1277 1280 pj_assert( tsx->last_tx == NULL ); … … 1282 1285 /* Set state to Trying. */ 1283 1286 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 ); 1285 1289 1286 1290 } else { 1287 pjsip_tx_data *tdata = event-> src.tdata;1291 pjsip_tx_data *tdata = event->body.tx_msg.tdata; 1288 1292 1289 1293 /* Save the message for retransmission. */ … … 1292 1296 1293 1297 /* 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; 1296 1301 } 1297 1302 … … 1299 1304 * timeout. 1300 1305 */ 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); 1302 1308 1303 1309 /* Start Timer A (or timer E) for retransmission only if unreliable … … 1307 1313 PJSIP_TRANSPORT_IS_RELIABLE(tsx->transport)==0) 1308 1314 { 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); 1310 1317 tsx->retransmit_count = 0; 1311 1318 } 1312 1319 1313 1320 /* 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); 1315 1323 } 1316 1324 … … 1322 1330 * is received. 1323 1331 */ 1324 static intpjsip_tsx_on_state_calling( pjsip_transaction *tsx,1325 pjsip_event *event)1332 static pj_status_t pjsip_tsx_on_state_calling( pjsip_transaction *tsx, 1333 pjsip_event *event ) 1326 1334 { 1327 1335 pj_assert(tsx->state == PJSIP_TSX_STATE_CALLING); … … 1329 1337 1330 1338 if (event->type == PJSIP_EVENT_TIMER && 1331 event-> src.timer== &tsx->retransmit_timer)1339 event->body.timer.entry == &tsx->retransmit_timer) 1332 1340 { 1341 pj_status_t status; 1333 1342 1334 1343 /* 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; 1337 1347 } 1338 1348 1339 1349 } else if (event->type == PJSIP_EVENT_TIMER && 1340 event->src.timer== &tsx->timeout_timer)1350 event->body.timer.entry == &tsx->timeout_timer) 1341 1351 { 1342 1352 … … 1350 1360 1351 1361 /* 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); 1353 1364 1354 1365 /* Transaction is destroyed */ 1355 return -1;1366 return PJSIP_ETSXDESTROYED; 1356 1367 1357 1368 } else if (event->type == PJSIP_EVENT_RX_MSG) { … … 1370 1381 */ 1371 1382 /* 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; 1373 1384 if (tsx->method.id != PJSIP_INVITE_METHOD && code!=401 && code!=407) { 1374 1385 pjsip_tx_data_dec_ref(tsx->last_tx); … … 1381 1392 } else { 1382 1393 pj_assert(0); 1394 return PJ_EBUG; 1383 1395 } 1384 1396 … … 1392 1404 * non-INVITE client transaction (bug in RFC?). 1393 1405 */ 1394 static int pjsip_tsx_on_state_trying( pjsip_transaction *tsx, pjsip_event *event) 1395 { 1396 int result; 1406 static pj_status_t pjsip_tsx_on_state_trying( pjsip_transaction *tsx, 1407 pjsip_event *event) 1408 { 1409 pj_status_t status; 1397 1410 1398 1411 pj_assert(tsx->state == PJSIP_TSX_STATE_TRYING); … … 1415 1428 * "Proceeding" state. 1416 1429 */ 1417 result= pjsip_tsx_on_state_proceeding_uas( tsx, event);1430 status = pjsip_tsx_on_state_proceeding_uas( tsx, event); 1418 1431 1419 1432 /* 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; 1425 1439 } 1426 1440 … … 1429 1443 * This state happens after the TU sends provisional response. 1430 1444 */ 1431 static int pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx, pjsip_event *event) 1445 static pj_status_t pjsip_tsx_on_state_proceeding_uas( pjsip_transaction *tsx, 1446 pjsip_event *event) 1432 1447 { 1433 1448 pj_assert(tsx->state == PJSIP_TSX_STATE_PROCEEDING || … … 1440 1455 if (event->type == PJSIP_EVENT_RX_MSG) { 1441 1456 1457 pj_status_t status; 1458 1442 1459 /* 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; 1445 1463 } 1446 1464 1447 1465 } 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; 1449 1468 1450 1469 /* The TU sends response message to the request. Save this message so … … 1472 1491 1473 1492 /* 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; 1476 1496 } 1477 1497 … … 1486 1506 pjsip_tx_data_add_ref( tdata ); 1487 1507 } 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 ); 1489 1510 1490 1511 } else if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code, 200)) { … … 1492 1513 if (tsx->method.id == PJSIP_INVITE_METHOD && tsx->handle_ack==0) { 1493 1514 1494 /* 2xx class message is not saved, because retransmission is handled1495 * by theTU.1515 /* 2xx class message is not saved, because retransmission 1516 * is handled by TU. 1496 1517 */ 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 ); 1498 1520 1499 1521 /* Transaction is destroyed. */ 1500 return -1;1522 return PJSIP_ETSXDESTROYED; 1501 1523 1502 1524 } else { … … 1505 1527 if (tsx->method.id == PJSIP_INVITE_METHOD) { 1506 1528 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, 1508 1531 &t1_timer_val); 1509 1532 } … … 1526 1549 } 1527 1550 1528 pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &timeout); 1551 pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, 1552 &timeout); 1529 1553 1530 1554 /* 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 ); 1532 1557 } 1533 1558 1534 1559 } else if (tsx->status_code >= 300) { 1535 1560 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 */ 1537 1564 if (tsx->last_tx != tdata) { 1538 1565 tsx->last_tx = tdata; … … 1541 1568 1542 1569 /* 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); 1544 1572 1545 1573 /* For INVITE, if unreliable transport is used, retransmission … … 1547 1575 */ 1548 1576 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); 1550 1579 if (cseq->method.id == PJSIP_INVITE_METHOD) { 1551 1580 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, 1553 1583 &t1_timer_val); 1554 1584 } … … 1556 1586 1557 1587 /* 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 ); 1559 1590 1560 1591 } else { … … 1564 1595 1565 1596 } else if (event->type == PJSIP_EVENT_TIMER && 1566 event-> src.timer== &tsx->retransmit_timer) {1597 event->body.timer.entry == &tsx->retransmit_timer) { 1567 1598 /* Retransmission timer elapsed. */ 1599 pj_status_t status; 1568 1600 1569 1601 /* Must have last response to retransmit. */ … … 1571 1603 1572 1604 /* 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; 1575 1608 } 1576 1609 1577 1610 } else if (event->type == PJSIP_EVENT_TIMER && 1578 event-> src.timer== &tsx->timeout_timer) {1611 event->body.timer.entry == &tsx->timeout_timer) { 1579 1612 1580 1613 /* Timeout timer. should not happen? */ … … 1583 1616 tsx->status_code = PJSIP_SC_TSX_TIMEOUT; 1584 1617 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; 1588 1622 1589 1623 } else { 1590 1624 pj_assert(0); 1591 } 1592 1593 return 0; 1625 return PJ_EBUG; 1626 } 1627 1628 return PJ_SUCCESS; 1594 1629 } 1595 1630 … … 1599 1634 * UAS. 1600 1635 */ 1601 static int pjsip_tsx_on_state_proceeding_uac( pjsip_transaction *tsx, pjsip_event *event) 1636 static pj_status_t pjsip_tsx_on_state_proceeding_uac(pjsip_transaction *tsx, 1637 pjsip_event *event) 1602 1638 { 1603 1639 … … 1611 1647 pj_assert(event->type == PJSIP_EVENT_RX_MSG); 1612 1648 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; 1617 1653 } else { 1618 1654 tsx->status_code = PJSIP_SC_TSX_TIMEOUT; … … 1622 1658 1623 1659 /* 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 ); 1625 1662 1626 1663 } else if (PJSIP_IS_STATUS_IN_CLASS(tsx->status_code,200)) { … … 1633 1670 */ 1634 1671 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; 1637 1675 1638 1676 } else { … … 1650 1688 timeout.sec = timeout.msec = 0; 1651 1689 } 1652 pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, &timeout); 1690 pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, 1691 &timeout); 1653 1692 1654 1693 /* 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 ); 1656 1696 } 1657 1697 1658 1698 } else if (tsx->status_code >= 300 && tsx->status_code <= 699) { 1659 1699 pj_time_val timeout; 1700 pj_status_t status; 1660 1701 1661 1702 /* Stop timer B. */ … … 1664 1705 /* Generate and send ACK for INVITE. */ 1665 1706 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; 1669 1712 } 1670 1713 } … … 1683 1726 1684 1727 /* 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 ); 1686 1730 1687 1731 } else { 1688 1732 // Shouldn't happen because there's no timer for this state. 1689 1733 pj_assert(0); 1734 return PJ_EBUG; 1690 1735 } 1691 1736 … … 1696 1741 * Handler for events in Completed state for UAS 1697 1742 */ 1698 static int pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx, pjsip_event *event) 1743 static pj_status_t pjsip_tsx_on_state_completed_uas( pjsip_transaction *tsx, 1744 pjsip_event *event) 1699 1745 { 1700 1746 pj_assert(tsx->state == PJSIP_TSX_STATE_COMPLETED); 1701 1747 1702 1748 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; 1704 1750 pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr( msg, PJSIP_H_CSEQ, NULL ); 1705 1751 1706 1752 /* On receive request retransmission, retransmit last response. */ 1707 1753 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; 1710 1759 } 1711 1760 … … 1718 1767 /* Start timer I in T4 interval (transaction termination). */ 1719 1768 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); 1721 1771 1722 1772 /* 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 ); 1724 1775 } 1725 1776 1726 1777 } else if (event->type == PJSIP_EVENT_TIMER) { 1727 1778 1728 if (event-> src.timer== &tsx->retransmit_timer) {1779 if (event->body.timer.entry == &tsx->retransmit_timer) { 1729 1780 /* 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; 1732 1786 } 1733 1787 … … 1741 1795 tsx->status_code = PJSIP_SC_TSX_TIMEOUT; 1742 1796 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; 1746 1801 1747 1802 } else { 1748 1803 /* 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; 1751 1807 } 1752 1808 } … … 1754 1810 } else { 1755 1811 /* Ignore request to transmit. */ 1756 pj_assert(event-> src.tdata == tsx->last_tx);1812 pj_assert(event->body.tx_msg.tdata == tsx->last_tx); 1757 1813 } 1758 1814 … … 1763 1819 * Handler for events in Completed state for UAC transaction. 1764 1820 */ 1765 static int pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, pjsip_event *event) 1821 static pj_status_t pjsip_tsx_on_state_completed_uac( pjsip_transaction *tsx, 1822 pjsip_event *event) 1766 1823 { 1767 1824 pj_assert(tsx->state == PJSIP_TSX_STATE_COMPLETED); … … 1769 1826 if (event->type == PJSIP_EVENT_TIMER) { 1770 1827 /* Must be the timeout timer. */ 1771 pj_assert(event-> src.timer== &tsx->timeout_timer);1828 pj_assert(event->body.timer.entry == &tsx->timeout_timer); 1772 1829 1773 1830 /* 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 ); 1775 1833 1776 1834 /* Transaction has been destroyed. */ 1777 return -1;1835 return PJSIP_ETSXDESTROYED; 1778 1836 1779 1837 } else if (event->type == PJSIP_EVENT_RX_MSG) { … … 1782 1840 * TU doesn't need to be informed. 1783 1841 */ 1784 pjsip_msg *msg = event-> src.rdata->msg;1842 pjsip_msg *msg = event->body.rx_msg.rdata->msg; 1785 1843 pj_assert(msg->type == PJSIP_RESPONSE_MSG); 1786 1844 if (msg->type==PJSIP_RESPONSE_MSG && 1787 1845 msg->line.status.code >= 200) 1788 1846 { 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; 1791 1852 } 1792 1853 } else { … … 1799 1860 } else if (tsx->method.id == PJSIP_INVITE_METHOD && 1800 1861 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; 1802 1865 1803 1866 /* Set last transmitted message. */ 1804 if (tsx->last_tx != event-> src.tdata) {1867 if (tsx->last_tx != event->body.tx_msg.tdata) { 1805 1868 pjsip_tx_data_dec_ref( tsx->last_tx ); 1806 tsx->last_tx = event-> src.tdata;1869 tsx->last_tx = event->body.tx_msg.tdata; 1807 1870 pjsip_tx_data_add_ref( tsx->last_tx ); 1808 1871 } … … 1811 1874 * Must notify now, so app has chance to put SDP in outgoing ACK msg. 1812 1875 */ 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 ); 1814 1878 1815 1879 /* 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; 1817 1883 1818 1884 } else { 1819 1885 pj_assert(0); 1820 } 1821 1822 return 0; 1886 return PJ_EBUG; 1887 } 1888 1889 return PJ_SUCCESS; 1823 1890 } 1824 1891 … … 1826 1893 * Handler for events in state Confirmed. 1827 1894 */ 1828 static int pjsip_tsx_on_state_confirmed( pjsip_transaction *tsx, pjsip_event *event) 1895 static pj_status_t pjsip_tsx_on_state_confirmed( pjsip_transaction *tsx, 1896 pjsip_event *event) 1829 1897 { 1830 1898 pj_assert(tsx->state == PJSIP_TSX_STATE_CONFIRMED); … … 1836 1904 /* Absorb any ACK received. */ 1837 1905 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 1838 1910 /* 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); 1840 1912 1841 1913 /* 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); 1844 1921 1845 1922 } else if (event->type == PJSIP_EVENT_TIMER) { 1846 1923 /* Must be from timeout_timer_. */ 1847 pj_assert(event-> src.timer== &tsx->timeout_timer);1924 pj_assert(event->body.timer.entry == &tsx->timeout_timer); 1848 1925 1849 1926 /* 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 ); 1851 1929 1852 1930 /* Transaction has been destroyed. */ 1853 return -1;1931 return PJSIP_ETSXDESTROYED; 1854 1932 1855 1933 } else { 1856 1934 pj_assert(0); 1935 return PJ_EBUG; 1857 1936 } 1858 1937 … … 1863 1942 * Handler for events in state Terminated. 1864 1943 */ 1865 static int pjsip_tsx_on_state_terminated( pjsip_transaction *tsx, pjsip_event *event) 1944 static pj_status_t pjsip_tsx_on_state_terminated( pjsip_transaction *tsx, 1945 pjsip_event *event) 1866 1946 { 1867 1947 pj_assert(tsx->state == PJSIP_TSX_STATE_TERMINATED); 1868 1948 1869 PJ_UNUSED_ARG(event) 1949 PJ_UNUSED_ARG(event); 1870 1950 1871 1951 /* 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 ); 1873 1954 1874 1955 return PJ_SUCCESS; … … 1876 1957 1877 1958 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) 1959 static 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); 1882 1964 return PJ_SUCCESS; 1883 1965 } -
pjproject/main/pjsip/src/pjsip/sip_transport.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_transport.h> … … 7 6 #include <pjsip/sip_msg.h> 8 7 #include <pjsip/sip_private.h> 8 #include <pjsip/sip_errno.h> 9 9 #include <pj/os.h> 10 10 #include <pj/log.h> … … 13 13 #include <pj/string.h> 14 14 #include <pj/pool.h> 15 #include <pj/assert.h> 15 16 16 17 #define MGR_IDLE_CHECK_INTERVAL 30 … … 45 46 * listener list. 46 47 */ 47 PJ_DECL_LIST_MEMBER(struct pjsip_transport_t) 48 PJ_DECL_LIST_MEMBER(struct pjsip_transport_t); 48 49 49 50 /** Transport's pool. */ … … 67 68 /** I/O Queue key */ 68 69 pj_ioqueue_key_t *key; 70 71 /** Accept key. */ 72 pj_ioqueue_op_key_t accept_op; 69 73 70 74 /** Receive data buffer */ … … 116 120 pj_ioqueue_t *ioqueue; 117 121 pj_time_val next_idle_check; 122 pj_size_t send_buf_size; 123 pj_size_t recv_buf_size; 118 124 void (*message_callback)(pjsip_endpoint*, pjsip_rx_data *rdata); 119 125 }; … … 145 151 struct transport_callback 146 152 { 147 PJ_DECL_LIST_MEMBER(struct transport_callback) 153 PJ_DECL_LIST_MEMBER(struct transport_callback); 148 154 149 155 /** User defined token to be passed to the callback. */ … … 174 180 }; 175 181 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); 182 static void on_ioqueue_read(pj_ioqueue_key_t *key, 183 pj_ioqueue_op_key_t *op_key, 184 pj_ssize_t bytes_read); 185 static void on_ioqueue_write(pj_ioqueue_key_t *key, 186 pj_ioqueue_op_key_t *op_key, 187 pj_ssize_t bytes_sent); 188 static 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); 192 static void on_ioqueue_connect(pj_ioqueue_key_t *key, 193 int status); 180 194 181 195 static pj_ioqueue_callback ioqueue_transport_callback = … … 195 209 key->type = (pj_uint8_t)tr->type; 196 210 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); 199 213 /* 200 214 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); 202 216 } 203 217 */ … … 213 227 key->type = (pj_uint8_t)type; 214 228 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); 217 231 } 218 232 #endif … … 221 235 const pj_sockaddr_in *addr) 222 236 { 223 PJ_UNUSED_ARG(addr) 237 PJ_UNUSED_ARG(addr); 224 238 225 239 /* This is to detect alignment problems. */ … … 237 251 pj_sockaddr_in addr; 238 252 pj_sockaddr_set_str_addr(&addr, &localaddr); 239 key->addr = pj_sockaddr_ get_addr(&addr);253 key->addr = pj_sockaddr_in_get_addr(&addr); 240 254 } 241 255 #endif … … 298 312 * Create new transmit buffer. 299 313 */ 300 pjsip_tx_data* pjsip_tx_data_create( pjsip_transport_mgr *mgr ) 314 pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr, 315 pjsip_tx_data **p_tdata ) 301 316 { 302 317 pj_pool_t *pool; 303 318 pjsip_tx_data *tdata; 319 pj_status_t status; 304 320 305 321 PJ_LOG(5, ("", "pjsip_tx_data_create")); 322 323 PJ_ASSERT_RETURN(mgr && p_tdata, PJ_EINVAL); 306 324 307 325 pool = pjsip_endpt_create_pool( mgr->endpt, "ptdt%p", … … 309 327 PJSIP_POOL_INC_TDATA ); 310 328 if (!pool) { 311 return NULL;329 return PJ_ENOMEM; 312 330 } 313 331 tdata = pj_pool_calloc(pool, 1, sizeof(pjsip_tx_data)); 314 332 tdata->pool = pool; 315 333 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) { 320 338 pjsip_endpt_destroy_pool( mgr->endpt, tdata->pool ); 321 return NULL;339 return status; 322 340 } 323 341 324 return tdata; 342 *p_tdata = tdata; 343 return PJ_SUCCESS; 325 344 } 326 345 … … 340 359 { 341 360 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) { 343 362 PJ_LOG(6,(tdata->obj_name, "destroying txdata")); 344 363 pj_atomic_destroy( tdata->ref_cnt ); … … 376 395 } else 377 396 #else 378 PJ_UNUSED_ARG(flag) 397 PJ_UNUSED_ARG(flag); 379 398 #endif 380 399 { … … 453 472 { 454 473 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) { 456 475 pj_gettimeofday(&tr->close_time); 457 476 tr->close_time.sec += PJSIP_TRANSPORT_CLOSE_TIMEOUT; … … 462 481 * Open the underlying transport. 463 482 */ 464 static pj_sock_t create_socket( pjsip_transport_type_e type, 465 pj_sockaddr_in *local ) 483 static pj_status_t create_socket( pjsip_transport_type_e type, 484 pj_sockaddr_in *local, 485 pj_sock_t *p_sock) 466 486 { 467 487 int sock_family; … … 469 489 int sock_proto; 470 490 int len; 491 pj_status_t status; 471 492 pj_sock_t sock; 472 493 … … 484 505 #endif 485 506 } 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; 489 508 } 490 509 491 510 /* 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; 497 514 498 515 /* Bind the socket to the requested address, or if no address is … … 501 518 if (/*local->sin_addr.s_addr != 0 &&*/ local->sin_port != 0) { 502 519 /* 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) { 508 522 pj_sock_close(sock); 509 return PJ_INVALID_SOCKET;523 return status; 510 524 } 511 525 } else if (type == PJSIP_TRANSPORT_UDP) { … … 517 531 pj_memset(local, 0, sizeof(*local)); 518 532 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) { 521 535 pj_sock_close(sock); 522 return PJ_INVALID_SOCKET;536 return status; 523 537 } 524 538 525 539 /* Get the local address. */ 526 540 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) { 529 543 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; 535 550 } 536 551 … … 548 563 * Create a new transport object. 549 564 */ 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) 565 static 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 ) 555 571 { 556 572 pj_pool_t *tr_pool=NULL, *rdata_pool=NULL; 557 573 pjsip_transport_t *tr = NULL; 574 pj_status_t status; 558 575 559 576 /* Allocate pool for transport from endpoint. */ … … 563 580 PJSIP_POOL_INC_TRANSPORT ); 564 581 if (!tr_pool) { 582 status = PJ_ENOMEM; 565 583 goto on_error; 566 584 } … … 572 590 PJSIP_POOL_INC_RDATA ); 573 591 if (!rdata_pool) { 592 status = PJ_ENOMEM; 574 593 goto on_error; 575 594 } … … 583 602 pj_memcpy(&tr->local_addr, local_addr, sizeof(pj_sockaddr_in)); 584 603 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); 586 605 587 606 if (type != PJSIP_TRANSPORT_UDP) { … … 596 615 597 616 /* 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) 600 619 goto on_error; 601 }602 620 603 621 /* Init rdata in the transport. */ … … 608 626 609 627 /* 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) 613 630 goto on_error; 614 }615 631 616 632 /* 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) 622 638 goto on_error; 623 } 624 625 return tr;639 640 *p_transport = tr; 641 return PJ_SUCCESS; 626 642 627 643 on_error: … … 635 651 pjsip_endpt_destroy_pool(mgr->endpt, rdata_pool); 636 652 } 637 return NULL;653 return status; 638 654 } 639 655 … … 641 657 * Destroy transport. 642 658 */ 643 static void destroy_transport( pjsip_transport_mgr *mgr, pjsip_transport_t *tr 659 static void destroy_transport( pjsip_transport_mgr *mgr, pjsip_transport_t *tr) 644 660 { 645 661 transport_key hash_key; 646 662 647 663 /* Remove from I/O queue. */ 648 pj_ioqueue_unregister( mgr->ioqueue,tr->key );664 pj_ioqueue_unregister( tr->key ); 649 665 650 666 /* Remove from hash table */ … … 669 685 670 686 671 static int transport_send_msg( pjsip_transport_t *tr, pjsip_tx_data *tdata, 672 const pj_sockaddr_in *addr) 687 static 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) 673 691 { 674 692 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; 677 699 678 700 /* Allocate buffer if necessary. */ … … 685 707 /* Print the message if it's not printed */ 686 708 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 } 699 718 700 719 /* Send the message. */ 701 720 buf = tdata->buf.start; 702 len= tdata->buf.cur - tdata->buf.start;721 size = tdata->buf.cur - tdata->buf.start; 703 722 704 723 if (tr->type == PJSIP_TRANSPORT_UDP) { … … 707 726 "%s" 708 727 "------------ end msg -------------", 709 pj_ sockaddr_get_str_addr(addr),710 pj_sockaddr_ get_port(addr),711 len, buf));712 713 s ent = 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)); 715 734 } 716 735 #if PJ_HAS_TCP … … 720 739 "%s" 721 740 "------------ end msg -------------", 722 len, buf));723 724 s ent = 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); 725 744 } 726 745 #else 727 746 else { 728 pj_assert( 0);729 s ent = -1;747 pj_assert(!"Unsupported transport"); 748 status = PJSIP_EUNSUPTRANSPORT; 730 749 } 731 750 #endif 732 751 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; 740 754 } 741 755 … … 744 758 * in the outgoing data. 745 759 */ 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 760 PJ_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 { 752 765 PJ_LOG(5, (tr->obj_name, "pjsip_transport_send_msg(tdata=%s)", tdata->obj_name)); 753 766 754 sent = transport_send_msg(tr, tdata, addr ); 755 return sent; 767 return transport_send_msg(tr, tdata, addr, sent ); 756 768 } 757 769 … … 761 773 * Create a new transport manager. 762 774 */ 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 *) ) 775 PJ_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) 767 780 { 768 781 pjsip_transport_mgr *mgr; 782 pj_status_t status; 769 783 770 784 PJ_LOG(5, (LOG_TRANSPORT_MGR, "pjsip_transport_mgr_create()")); … … 773 787 mgr->endpt = endpt; 774 788 mgr->message_callback = cb; 775 789 mgr->send_buf_size = DEFAULT_SO_SNDBUF; 790 mgr->recv_buf_size = DEFAULT_SO_RCVBUF; 791 776 792 mgr->transport_table = pj_hash_create(pool, MGR_HASH_TABLE_SIZE); 777 793 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) { 789 802 pj_ioqueue_destroy(mgr->ioqueue); 790 return NULL;803 return status; 791 804 } 792 805 pj_gettimeofday(&mgr->next_idle_check); 793 806 mgr->next_idle_check.sec += MGR_IDLE_CHECK_INTERVAL; 794 return mgr; 807 808 *p_mgr = mgr; 809 return status; 795 810 } 796 811 … … 798 813 * Destroy transport manager. 799 814 */ 800 PJ_DEF( void) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr )815 PJ_DEF(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ) 801 816 { 802 817 pj_hash_iterator_t itr_val; … … 824 839 825 840 pj_mutex_unlock(mgr->mutex); 841 842 return PJ_SUCCESS; 826 843 } 827 844 … … 837 854 pjsip_transport_t *tr; 838 855 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) { 855 882 pj_sock_close(sock_hnd); 856 return -1;883 return status; 857 884 } 858 885 #if PJ_HAS_TCP 859 886 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) { 864 890 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); 878 909 879 910 } else 880 911 #endif 881 912 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); 894 930 } 895 931 … … 902 938 * See further comments on struct pjsip_transport_t definition. 903 939 */ 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 { 905 943 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); 907 945 } 908 946 hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); … … 910 948 911 949 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); 913 952 pj_mutex_unlock(mgr->mutex); 914 953 915 954 PJ_LOG(4,(tr->obj_name, "Listening at %s %s:%d", 916 955 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))); 919 958 PJ_LOG(4,(tr->obj_name, "Listener public address is at %s %s:%d", 920 959 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))); 923 962 return PJ_SUCCESS; 924 963 } … … 933 972 { 934 973 pj_sock_t sock_hnd; 974 pj_status_t status; 935 975 936 976 PJ_LOG(5, (LOG_TRANSPORT_MGR, "pjsip_create_listener(type=%d)", type)); 937 977 938 s ock_hnd = create_socket(type, local_addr);939 if (s ock_hnd == PJ_INVALID_SOCKET) {940 return -1;978 status = create_socket(type, local_addr, &sock_hnd); 979 if (status != PJ_SUCCESS) { 980 return status; 941 981 } 942 982 … … 952 992 { 953 993 pj_sockaddr_in local_addr; 994 pj_status_t status; 954 995 int addrlen = sizeof(local_addr); 955 996 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); 960 1003 } 961 1004 … … 974 1017 pjsip_transport_t *tr; 975 1018 pj_sockaddr_in local; 976 int sock_hnd;1019 pj_sock_t sock_hnd; 977 1020 pj_status_t status; 978 1021 struct transport_callback *cb_rec; … … 1030 1073 pj_memset(&local, 0, sizeof(local)); 1031 1074 local.sin_family = PJ_AF_INET; 1032 s ock_hnd = create_socket(type, &local);1033 if (s ock_hnd == PJ_INVALID_SOCKET) {1075 status = create_socket(type, &local, &sock_hnd); 1076 if (status != PJ_SUCCESS) { 1034 1077 pj_mutex_unlock(mgr->mutex); 1035 (*cb_rec->cb)(NULL, cb_rec->token, -1);1078 (*cb_rec->cb)(NULL, cb_rec->token, status); 1036 1079 return; 1037 1080 } 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) { 1040 1083 pj_mutex_unlock(mgr->mutex); 1041 (*cb_rec->cb)(NULL, cb_rec->token, -1);1084 (*cb_rec->cb)(NULL, cb_rec->token, status); 1042 1085 return; 1043 1086 } … … 1046 1089 if (type == PJSIP_TRANSPORT_TCP) { 1047 1090 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)); 1050 1093 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); 1053 1096 destroy_transport(mgr, tr); 1054 1097 pj_mutex_unlock(mgr->mutex); 1055 (*cb_rec->cb)(NULL, cb_rec->token, -1);1098 (*cb_rec->cb)(NULL, cb_rec->token, status); 1056 1099 return; 1057 1100 } … … 1059 1102 #endif 1060 1103 if (type == PJSIP_TRANSPORT_UDP) { 1061 int len;1104 pj_ssize_t size; 1062 1105 1063 1106 do { 1064 1107 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) { 1072 1116 destroy_transport(mgr, tr); 1073 1117 pj_mutex_unlock(mgr->mutex); 1074 (*cb_rec->cb)(NULL, cb_rec->token, -1);1118 (*cb_rec->cb)(NULL, cb_rec->token, status); 1075 1119 return; 1076 1120 } … … 1083 1127 PJ_TODO(FIXED_BUG_ON_IMMEDIATE_TRANSPORT_DATA); 1084 1128 1085 } while ( len != PJ_IOQUEUE_PENDING);1129 } while (status == PJ_SUCCESS); 1086 1130 1087 1131 //Bug: cb will never be called! … … 1093 1137 } else { 1094 1138 pj_mutex_unlock(mgr->mutex); 1095 (*cb_rec->cb)(NULL, cb_rec->token, -1);1139 (*cb_rec->cb)(NULL, cb_rec->token, PJSIP_EUNSUPTRANSPORT); 1096 1140 return; 1097 1141 } 1098 1142 1099 pj_assert(status==PJ_ IOQUEUE_PENDING || status==PJ_SUCCESS);1143 pj_assert(status==PJ_EPENDING || status==PJ_SUCCESS); 1100 1144 pj_mutex_lock(tr->tr_mutex); 1101 1145 hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); 1102 1146 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); 1104 1149 if (status == PJ_SUCCESS) { 1105 1150 pj_mutex_unlock(tr->tr_mutex); … … 1125 1170 pjsip_transport_t *tr; 1126 1171 transport_key *hash_key; 1172 pj_ssize_t size; 1127 1173 1128 1174 pj_assert (listener->type == PJSIP_TRANSPORT_TCP); 1129 1175 1130 1176 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; 1133 1180 } 1134 1181 1135 1182 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")); 1144 1193 goto on_return; 1145 1194 } … … 1155 1204 tr->rdata->addr_len = listener->accept_data.addrlen; 1156 1205 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); 1160 1213 destroy_transport(mgr, tr); 1161 1214 goto on_return; 1162 1215 } 1163 1216 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); 1165 1219 hash_key = pj_pool_alloc(tr->pool, sizeof(transport_key)); 1166 1220 init_key_from_transport(hash_key, tr); 1167 1221 1168 1222 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); 1170 1225 pj_mutex_unlock(mgr->mutex); 1171 1226 … … 1173 1228 /* Re-initiate asynchronous accept() */ 1174 1229 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, 1176 1231 &listener->accept_data.sock, 1177 1232 &listener->accept_data.local, 1178 1233 &listener->accept_data.remote, 1179 1234 &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); 1182 1239 return; 1183 1240 } … … 1194 1251 struct transport_callback new_list; 1195 1252 struct transport_callback *cb_rec; 1196 1197 PJ_UNUSED_ARG(mgr) 1253 pj_ssize_t recv_size; 1254 1255 PJ_UNUSED_ARG(mgr); 1198 1256 1199 1257 /* On connect completion, we must call all registered callbacks in … … 1222 1280 if (status == PJ_SUCCESS) { 1223 1281 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) { 1226 1287 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));1229 1288 } 1230 1289 } … … 1245 1304 if (status != PJ_SUCCESS) { 1246 1305 destroy_transport(mgr, tr); 1306 PJ_TODO(WTF); 1247 1307 return; 1248 1308 } 1249 1309 1250 1310 /* 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) { 1254 1315 destroy_transport(mgr, tr); 1316 PJ_TODO(IMMEDIATE_DATA); 1255 1317 return; 1256 1318 } … … 1270 1332 { 1271 1333 pjsip_msg *msg; 1272 pjsip_cid_hdr *call_id;1273 1334 pjsip_rx_data *rdata = tr->rdata; 1274 1335 pj_pool_t *rdata_pool; … … 1316 1377 1317 1378 /* 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); 1320 1381 1321 1382 /* Print the whole data to the log. */ … … 1334 1395 /* For TCP transport, check if the whole message has been received. */ 1335 1396 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) { 1339 1401 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)); 1345 1406 goto on_return; 1346 1407 } else { … … 1358 1419 src_addr, src_port)); 1359 1420 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); 1362 1422 if (msg == NULL) { 1363 1423 PJ_LOG(3,(tr->obj_name, "Bad message (%d bytes from %s:%d)", msg_fragment_size, … … 1366 1426 } 1367 1427 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) 1382 1431 { 1383 1432 PJ_LOG(3,(tr->obj_name, "Bad message from %s:%d: missing some header", … … 1385 1434 goto finish_process_fragment; 1386 1435 } 1387 rdata->call_id = call_id->id;1388 rdata->from_tag = rdata->from->tag;1389 rdata->to_tag = rdata->to->tag;1390 1436 1391 1437 /* If message is received from address that's different from the sent-by, … … 1402 1448 */ 1403 1449 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); 1405 1451 } 1406 1452 … … 1409 1455 if (msg->type == PJSIP_RESPONSE_MSG) { 1410 1456 hdr = (pjsip_hdr*)rdata->via->next; 1411 if (hdr ) {1457 if (hdr != &rdata->msg->hdr) { 1412 1458 hdr = pjsip_msg_find_hdr(msg, PJSIP_H_VIA, hdr); 1413 1459 if (hdr) { … … 1446 1492 rdata->addr_len = sizeof(rdata->addr); 1447 1493 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, 1450 1497 &rdata->addr, &rdata->addr_len); 1498 PJ_TODO(HANDLE_IMMEDIATE_DATA); 1451 1499 } 1452 1500 … … 1457 1505 tcp_read_packet: 1458 1506 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, 1460 1509 tr->rdata->packet + tr->rdata->len, 1461 PJSIP_MAX_PKT_LEN - tr->rdata->len); 1510 &size, 0); 1511 PJ_TODO(HANDLE_IMMEDIATE_DATA_1); 1462 1512 } 1463 1513 #endif … … 1508 1558 } 1509 1559 1510 static void on_ioqueue_read(pj_ioqueue_key_t *key, pj_ssize_t bytes_read) 1560 static void on_ioqueue_read(pj_ioqueue_key_t *key, 1561 pj_ioqueue_op_key_t *op_key, 1562 pj_ssize_t bytes_read) 1511 1563 { 1512 1564 pjsip_transport_t *t; … … 1516 1568 } 1517 1569 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) 1570 static 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); 1522 1576 1523 1577 /* Completion of write operation. … … 1526 1580 } 1527 1581 1528 static void on_ioqueue_accept(pj_ioqueue_key_t *key, int status) 1582 static 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) 1529 1586 { 1530 1587 #if PJ_HAS_TCP … … 1534 1591 handle_new_connection( t->mgr, t, status ); 1535 1592 #else 1536 PJ_UNUSED_ARG(key) 1537 PJ_UNUSED_ARG(status) 1593 PJ_UNUSED_ARG(key); 1594 PJ_UNUSED_ARG(status); 1538 1595 #endif 1539 1596 } … … 1547 1604 handle_connect_completion( t->mgr, t, status); 1548 1605 #else 1549 PJ_UNUSED_ARG(key) 1550 PJ_UNUSED_ARG(status) 1606 PJ_UNUSED_ARG(key); 1607 PJ_UNUSED_ARG(status); 1551 1608 #endif 1552 1609 } -
pjproject/main/pjsip/src/pjsip/sip_uri.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_uri.h> 5 4 #include <pjsip/sip_msg.h> 6 #include <pjsip/print .h>5 #include <pjsip/print_util.h> 7 6 #include <pj/string.h> 8 7 #include <pj/pool.h> 8 #include <pj/assert.h> 9 9 10 10 #define IS_SIPS(url) ((url)->vptr==&sips_url_vptr) … … 69 69 static const pj_str_t *pjsip_url_get_scheme(const pjsip_url *url) 70 70 { 71 PJ_UNUSED_ARG(url) 71 PJ_UNUSED_ARG(url); 72 72 return &sip_str; 73 73 } … … 75 75 static const pj_str_t *pjsips_url_get_scheme(const pjsip_url *url) 76 76 { 77 PJ_UNUSED_ARG(url) 77 PJ_UNUSED_ARG(url); 78 78 return &sips_str; 79 79 } … … 254 254 } 255 255 256 if ( strcmp(str_url1, str_url2)) {256 if (pj_native_strcmp(str_url1, str_url2)) { 257 257 /* Not equal */ 258 258 return -1; -
pjproject/main/pjsip/src/pjsua/getopt.c
r3 r43 279 279 in GCC. */ 280 280 #include <string.h> 281 #define my_index strchr281 #define my_index pj_native_strchr 282 282 #else 283 283 … … 645 645 then skip everything else like a non-option. */ 646 646 647 if (optind != argc && ! strcmp(argv[optind], "--"))647 if (optind != argc && !pj_native_strcmp(argv[optind], "--")) 648 648 { 649 649 optind++; -
pjproject/main/pjsip/src/pjsua/main.c
r3 r43 251 251 urllen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->from->uri, url, sizeof(url)-1); 252 252 if (urllen < 1) { 253 strcpy(url, "<unknown>");253 pj_native_strcpy(url, "<unknown>"); 254 254 } else { 255 255 url[urllen] = '\0'; … … 1104 1104 1105 1105 if (global.user_id[0]=='\0') { 1106 strcpy(global.user_id, "user");1106 pj_native_strcpy(global.user_id, "user"); 1107 1107 } 1108 1108 … … 1234 1234 rdata->from->uri, from, sizeof(from)); 1235 1235 if (len > 0) from[len] = '\0'; 1236 else strcpy(from, "<URL too long..>");1236 else pj_native_strcpy(from, "<URL too long..>"); 1237 1237 1238 1238 len = pjsip_uri_print( PJSIP_URI_IN_CONTACT_HDR, 1239 1239 rdata->to->uri, to, sizeof(to)); 1240 1240 if (len > 0) to[len] = '\0'; 1241 else strcpy(to, "<URL too long..>");1241 else pj_native_strcpy(to, "<URL too long..>"); 1242 1242 1243 1243 PJ_LOG(3,(THIS_FILE, "Incoming instant message:")); -
pjproject/main/pjsip/src/pjsua/misc.c
r3 r43 342 342 break; 343 343 case OPT_USE_STUN1: /* STUN server 1 */ 344 p = strchr(optarg, ':');344 p = pj_native_strchr(optarg, ':'); 345 345 if (p) { 346 346 *p = '\0'; … … 357 357 break; 358 358 case OPT_USE_STUN2: /* STUN server 2 */ 359 p = strchr(optarg, ':');359 p = pj_native_strchr(optarg, ':'); 360 360 if (p) { 361 361 *p = '\0';
Note: See TracChangeset
for help on using the changeset viewer.