Changeset 119
- Timestamp:
- Jan 10, 2006 1:31:40 PM (19 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/build/pjsip_core.dsp
r109 r119 125 125 126 126 SOURCE=..\src\pjsip\sip_transaction.c 127 128 !IF "$(CFG)" == "pjsip_core - Win32 Release"129 130 !ELSEIF "$(CFG)" == "pjsip_core - Win32 Debug"131 132 !ENDIF133 134 127 # End Source File 135 128 # Begin Source File … … 258 251 259 252 # PROP Default_Filter "" 260 # Begin Source File261 262 SOURCE=..\include\pjsip\sip_msg_i.h263 # End Source File264 253 # End Group 265 254 # Begin Source File -
pjproject/trunk/pjsip/include/pjsip/sip_msg.h
r109 r119 717 717 * other list (or message). Otherwise Real Bad Thing will happen. 718 718 */ 719 PJ_IDECL(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr ); 719 PJ_INLINE(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr ) 720 { 721 pj_list_insert_before(&msg->hdr, hdr); 722 } 720 723 721 724 /** … … 728 731 * other list (or message). Otherwise Real Bad Thing will happen. 729 732 */ 730 PJ_IDECL(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr ); 733 PJ_INLINE(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr ) 734 { 735 pj_list_insert_after(&msg->hdr, hdr); 736 } 731 737 732 738 /** … … 1552 1558 */ 1553 1559 1554 /*1555 * Include inline definitions.1556 */1557 #if PJ_FUNCTIONS_ARE_INLINED1558 # include <pjsip/sip_msg_i.h>1559 #endif1560 1561 1560 1562 1561 PJ_END_DECL -
pjproject/trunk/pjsip/include/pjsip/sip_uri.h
r82 r119 106 106 * @param pname_unres Specification of allowed characters in pname. 107 107 * @param pvalue_unres Specification of allowed characters in pvalue. 108 * @param sep Separator character (either ';' or ','). 108 * @param sep Separator character (either ';', ',', or '?'). 109 * When separator is set to '?', this function will 110 * automatically adjust the separator character to 111 * '&' after the first parameter is printed. 109 112 * 110 113 * @return The number of bytes printed, or -1 on errr. … … 222 225 * SIP and SIPS URL scheme. 223 226 */ 224 typedef struct pjsip_ url227 typedef struct pjsip_sip_uri 225 228 { 226 229 pjsip_uri_vptr *vptr; /**< Pointer to virtual function table.*/ … … 237 240 pjsip_param other_param; /**< Other parameters grouped together. */ 238 241 pjsip_param header_param; /**< Optional header parameter. */ 239 } pjsip_ url;242 } pjsip_sip_uri; 240 243 241 244 … … 330 333 * @return SIP URL. 331 334 */ 332 PJ_DECL(pjsip_ url*) pjsip_url_create( pj_pool_t *pool, int secure );335 PJ_DECL(pjsip_sip_uri*) pjsip_url_create( pj_pool_t *pool, int secure ); 333 336 334 337 /** … … 337 340 * @return SIPS URL. 338 341 */ 339 PJ_DECL(pjsip_ url*) pjsips_url_create( pj_pool_t *pool );342 PJ_DECL(pjsip_sip_uri*) pjsips_url_create( pj_pool_t *pool ); 340 343 341 344 /** … … 343 346 * @param url The URL. 344 347 */ 345 PJ_DECL(void) pjsip_url_init(pjsip_ url*url, int secure);348 PJ_DECL(void) pjsip_url_init(pjsip_sip_uri *url, int secure); 346 349 347 350 /** … … 351 354 * @param rhs The source URL. 352 355 */ 353 PJ_DECL(void) pjsip_url_assign(pj_pool_t *pool, pjsip_url *url, const pjsip_url *rhs); 356 PJ_DECL(void) pjsip_url_assign(pj_pool_t *pool, pjsip_sip_uri *url, 357 const pjsip_sip_uri *rhs); 354 358 355 359 /** -
pjproject/trunk/pjsip/src/pjsip-ua/sip_dialog.c
r74 r119 413 413 pjsip_contact_hdr *contact; 414 414 pjsip_name_addr *name_addr; 415 pjsip_ url*url;415 pjsip_sip_uri *url; 416 416 unsigned flag; 417 417 pjsip_event event; … … 446 446 name_addr = (pjsip_name_addr *)dlg->local.info->uri; 447 447 dlg->local.contact->uri = (pjsip_uri*) name_addr; 448 url = (pjsip_ url*) name_addr->uri;448 url = (pjsip_sip_uri*) name_addr->uri; 449 449 //url->port = rdata->via->sent_by.port; 450 450 //url->port = pj_sockaddr_get_port( pjsip_transport_get_local_addr(rdata->transport) ); -
pjproject/trunk/pjsip/src/pjsip/sip_msg.c
r109 r119 24 24 #include <pj/pool.h> 25 25 #include <pj/assert.h> 26 27 /*28 * Include inline definitions here if functions are NOT inlined.29 */30 #if PJ_FUNCTIONS_ARE_INLINED==031 # include <pjsip/sip_msg_i.h>32 #endif33 26 34 27 const pjsip_method -
pjproject/trunk/pjsip/src/pjsip/sip_parser.c
r106 r119 155 155 pj_pool_t *pool, 156 156 unsigned option); 157 static pjsip_ url *int_parse_sip_url( pj_scanner *scanner,158 pj_pool_t *pool,159 pj_bool_t parse_params);157 static pjsip_sip_uri* int_parse_sip_url( pj_scanner *scanner, 158 pj_pool_t *pool, 159 pj_bool_t parse_params); 160 160 static pjsip_name_addr * 161 161 int_parse_name_addr( pj_scanner *scanner, … … 954 954 *pname = pj_str_unescape(pool, pname); 955 955 956 /* init pvalue */ 957 pvalue->ptr = NULL; 958 pvalue->slen = 0; 959 956 960 /* pvalue, if any */ 957 961 if (*scanner->curptr == '=') { 958 962 pj_scan_get_char(scanner); 959 /* pvalue can be a quoted string. */ 960 if (*scanner->curptr == '"') { 961 pj_scan_get_quote( scanner, '"', '"', pvalue); 962 if (option & PJSIP_PARSE_REMOVE_QUOTE) { 963 pvalue->ptr++; 964 pvalue->slen -= 2; 963 if (!pj_scan_is_eof(scanner)) { 964 /* pvalue can be a quoted string. */ 965 if (*scanner->curptr == '"') { 966 pj_scan_get_quote( scanner, '"', '"', pvalue); 967 if (option & PJSIP_PARSE_REMOVE_QUOTE) { 968 pvalue->ptr++; 969 pvalue->slen -= 2; 970 } 971 } else if(pj_cis_match(&pjsip_PARAM_CHAR_SPEC, *scanner->curptr)) { 972 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 973 *pvalue = pj_str_unescape(pool, pvalue); 965 974 } 966 } else { 967 pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue); 968 *pvalue = pj_str_unescape(pool, pvalue); 969 } 970 } else { 971 pvalue->ptr = NULL; 972 pvalue->slen = 0; 975 } 973 976 } 974 977 } … … 997 1000 *hname = pj_str_unescape(pool, hname); 998 1001 1002 /* Init hvalue */ 1003 hvalue->ptr = NULL; 1004 hvalue->slen = 0; 1005 999 1006 /* pvalue, if any */ 1000 1007 if (*scanner->curptr == '=') { 1001 1008 pj_scan_get_char(scanner); 1002 pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hvalue); 1003 *hvalue = pj_str_unescape(pool, hvalue); 1004 } else { 1005 hvalue->ptr = NULL; 1006 hvalue->slen = 0; 1009 if (!pj_scan_is_eof(scanner) && 1010 pj_cis_match(&pjsip_HDR_CHAR_SPEC, *scanner->curptr)) 1011 { 1012 pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hvalue); 1013 *hvalue = pj_str_unescape(pool, hvalue); 1014 } 1007 1015 } 1008 1016 } … … 1143 1151 1144 1152 /* Parse "sip:" and "sips:" URI. */ 1145 static pjsip_ url*int_parse_sip_url( pj_scanner *scanner,1146 1147 1153 static pjsip_sip_uri *int_parse_sip_url( pj_scanner *scanner, 1154 pj_pool_t *pool, 1155 pj_bool_t parse_params) 1148 1156 { 1149 1157 pj_str_t scheme; 1150 pjsip_ url*url = NULL;1158 pjsip_sip_uri *url = NULL; 1151 1159 int colon; 1152 1160 int skip_ws = scanner->skip_ws; -
pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
r115 r119 500 500 * Register the transaction to the hash table. 501 501 */ 502 static voidmod_tsx_layer_register_tsx( pjsip_transaction *tsx)502 static pj_status_t mod_tsx_layer_register_tsx( pjsip_transaction *tsx) 503 503 { 504 504 pj_assert(tsx->transaction_key.slen != 0); 505 //pj_assert(tsx->state != PJSIP_TSX_STATE_NULL);506 505 507 506 /* Lock hash table mutex. */ 508 507 pj_mutex_lock(mod_tsx_layer.mutex); 508 509 /* Check if no transaction with the same key exists. */ 510 if (pj_hash_get( mod_tsx_layer.htable, &tsx->transaction_key.ptr, 511 tsx->transaction_key.slen) != NULL) 512 { 513 pj_mutex_unlock(mod_tsx_layer.mutex); 514 return PJ_EEXISTS; 515 } 509 516 510 517 /* Register the transaction to the hash table. */ … … 514 521 /* Unlock mutex. */ 515 522 pj_mutex_unlock(mod_tsx_layer.mutex); 523 524 return PJ_SUCCESS; 516 525 } 517 526 … … 1051 1060 1052 1061 /* Register transaction to hash table. */ 1053 mod_tsx_layer_register_tsx(tsx); 1062 status = mod_tsx_layer_register_tsx(tsx); 1063 if (status != PJ_SUCCESS) { 1064 pj_assert(!"Bug in branch_param generator (i.e. not unique)"); 1065 tsx_destroy(tsx); 1066 return status; 1067 } 1054 1068 1055 1069 … … 1160 1174 1161 1175 /* Register the transaction. */ 1162 mod_tsx_layer_register_tsx(tsx); 1163 1176 status = mod_tsx_layer_register_tsx(tsx); 1177 if (status != PJ_SUCCESS) { 1178 tsx_destroy(tsx); 1179 return status; 1180 } 1164 1181 1165 1182 /* Unlock transaction and return. */ … … 1541 1558 msec_time = (1 << (tsx->retransmit_count)) * PJSIP_T1_TIMEOUT; 1542 1559 1543 if (msec_time>PJSIP_T2_TIMEOUT && tsx->method.id!=PJSIP_INVITE_METHOD) 1544 msec_time = PJSIP_T2_TIMEOUT; 1560 if (tsx->role == PJSIP_ROLE_UAC) { 1561 /* Retransmission for non-INVITE transaction caps-off at T2 */ 1562 if (msec_time>PJSIP_T2_TIMEOUT && tsx->method.id!=PJSIP_INVITE_METHOD) 1563 msec_time = PJSIP_T2_TIMEOUT; 1564 } else { 1565 /* Retransmission of INVITE final response also caps-off at T2 */ 1566 pj_assert(tsx->status_code >= 200); 1567 if (msec_time>PJSIP_T2_TIMEOUT) 1568 msec_time = PJSIP_T2_TIMEOUT; 1569 } 1545 1570 1546 1571 timeout.sec = msec_time / 1000; -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r109 r119 348 348 { 349 349 350 PJ_ASSERT_RETURN(tdata && tdata->msg, "INVALID MSG"); 350 if (tdata==NULL || tdata->msg==NULL) 351 return "INVALID MSG"; 351 352 352 353 if (tdata->info) -
pjproject/trunk/pjsip/src/pjsip/sip_uri.c
r82 r119 112 112 } 113 113 p = p->next; 114 if (sep == '?') sep = '&'; 114 115 } while (p != param_list); 115 116 … … 123 124 #define IS_SIPS(url) ((url)->vptr==&sips_url_vptr) 124 125 125 static const pj_str_t *pjsip_url_get_scheme( const pjsip_ url* );126 static const pj_str_t *pjsips_url_get_scheme( const pjsip_ url* );126 static const pj_str_t *pjsip_url_get_scheme( const pjsip_sip_uri* ); 127 static const pj_str_t *pjsips_url_get_scheme( const pjsip_sip_uri* ); 127 128 static const pj_str_t *pjsip_name_addr_get_scheme( const pjsip_name_addr * ); 128 129 static void *pjsip_get_uri( pjsip_uri *uri ); … … 147 148 const pjsip_name_addr *naddr2); 148 149 static int pjsip_url_print( pjsip_uri_context_e context, 149 const pjsip_ url*url,150 const pjsip_sip_uri *url, 150 151 char *buf, pj_size_t size); 151 152 static int pjsip_url_compare( pjsip_uri_context_e context, 152 const pjsip_url *url1, const pjsip_url *url2); 153 static pjsip_url* pjsip_url_clone(pj_pool_t *pool, const pjsip_url *rhs); 153 const pjsip_sip_uri *url1, 154 const pjsip_sip_uri *url2); 155 static pjsip_sip_uri* pjsip_url_clone(pj_pool_t *pool, 156 const pjsip_sip_uri *rhs); 154 157 155 158 static pjsip_uri_vptr sip_url_vptr = … … 180 183 }; 181 184 182 static const pj_str_t *pjsip_url_get_scheme(const pjsip_ url*url)185 static const pj_str_t *pjsip_url_get_scheme(const pjsip_sip_uri *url) 183 186 { 184 187 PJ_UNUSED_ARG(url); … … 186 189 } 187 190 188 static const pj_str_t *pjsips_url_get_scheme(const pjsip_ url*url)191 static const pj_str_t *pjsips_url_get_scheme(const pjsip_sip_uri *url) 189 192 { 190 193 PJ_UNUSED_ARG(url); … … 202 205 } 203 206 204 PJ_DEF(void) pjsip_url_init(pjsip_ url*url, int secure)207 PJ_DEF(void) pjsip_url_init(pjsip_sip_uri *url, int secure) 205 208 { 206 209 pj_memset(url, 0, sizeof(*url)); … … 211 214 } 212 215 213 PJ_DEF(pjsip_ url*) pjsip_url_create( pj_pool_t *pool, int secure )214 { 215 pjsip_ url *url = pj_pool_alloc(pool, sizeof(pjsip_url));216 PJ_DEF(pjsip_sip_uri*) pjsip_url_create( pj_pool_t *pool, int secure ) 217 { 218 pjsip_sip_uri *url = pj_pool_alloc(pool, sizeof(pjsip_sip_uri)); 216 219 pjsip_url_init(url, secure); 217 220 return url; … … 219 222 220 223 static int pjsip_url_print( pjsip_uri_context_e context, 221 const pjsip_ url*url,224 const pjsip_sip_uri *url, 222 225 char *buf, pj_size_t size) 223 226 { … … 226 229 char *endbuf = buf+size; 227 230 const pj_str_t *scheme; 228 pjsip_param *param;229 char hparam_char = '?';230 231 231 232 *buf = '\0'; … … 318 319 buf += printed; 319 320 320 /* Header param. */ 321 param = url->header_param.next; 322 while (param != &url->header_param) { 323 if (endbuf - buf < param->name.slen+2) 321 /* Header param. 322 * Header param is only allowed in these contexts: 323 * - PJSIP_URI_IN_CONTACT_HDR 324 * - PJSIP_URI_IN_OTHER 325 */ 326 if (context == PJSIP_URI_IN_CONTACT_HDR || context == PJSIP_URI_IN_OTHER) { 327 printed = pjsip_param_print_on(&url->header_param, buf, endbuf-buf, 328 &pjsip_HDR_CHAR_SPEC, 329 &pjsip_HDR_CHAR_SPEC, '?'); 330 if (printed < 0) 324 331 return -1; 325 *buf++ = hparam_char; 326 copy_advance_escape(buf, param->name, pjsip_HDR_CHAR_SPEC); 327 if (param->value.slen) { 328 *buf++ = '='; 329 copy_advance_escape(buf, param->value, pjsip_HDR_CHAR_SPEC); 330 } 331 param = param->next; 332 hparam_char = '&'; 332 buf += printed; 333 333 } 334 334 … … 338 338 339 339 static pj_status_t pjsip_url_compare( pjsip_uri_context_e context, 340 const pjsip_ url*url1,341 const pjsip_ url*url2)340 const pjsip_sip_uri *url1, 341 const pjsip_sip_uri *url2) 342 342 { 343 343 const pjsip_param *p1; … … 466 466 467 467 468 PJ_DEF(void) pjsip_url_assign(pj_pool_t *pool, pjsip_ url*url,469 const pjsip_ url*rhs)468 PJ_DEF(void) pjsip_url_assign(pj_pool_t *pool, pjsip_sip_uri *url, 469 const pjsip_sip_uri *rhs) 470 470 { 471 471 pj_strdup( pool, &url->user, &rhs->user); … … 483 483 } 484 484 485 static pjsip_ url* pjsip_url_clone(pj_pool_t *pool, const pjsip_url*rhs)486 { 487 pjsip_ url *url = pj_pool_alloc(pool, sizeof(pjsip_url));485 static pjsip_sip_uri* pjsip_url_clone(pj_pool_t *pool, const pjsip_sip_uri *rhs) 486 { 487 pjsip_sip_uri *url = pj_pool_alloc(pool, sizeof(pjsip_sip_uri)); 488 488 if (!url) 489 489 return NULL; -
pjproject/trunk/pjsip/src/pjsip/sip_util.c
r109 r119 113 113 pjsip_msg_add_hdr(msg, (void*)param_cseq); 114 114 115 /* Add a blank Via header . */115 /* Add a blank Via header in the front of the message. */ 116 116 via = pjsip_via_hdr_create(tdata->pool); 117 117 via->rport_param = 0; 118 118 pjsip_msg_insert_first_hdr(msg, (void*)via); 119 120 /* Add header params as request headers */ 121 if (PJSIP_URI_SCHEME_IS_SIP(param_target) || 122 PJSIP_URI_SCHEME_IS_SIPS(param_target)) 123 { 124 pjsip_sip_uri *uri = (pjsip_sip_uri*) pjsip_uri_get_uri(param_target); 125 pjsip_param *hparam; 126 127 hparam = uri->header_param.next; 128 while (hparam != &uri->header_param) { 129 pjsip_generic_string_hdr *hdr; 130 131 hdr = pjsip_generic_string_hdr_create_with_text(tdata->pool, 132 &hparam->name, 133 &hparam->value); 134 pjsip_msg_add_hdr(msg, (pjsip_hdr*)hdr); 135 hparam = hparam->next; 136 } 137 } 119 138 120 139 /* Create message body. */ … … 637 656 PJSIP_URI_SCHEME_IS_SIPS(topmost_route_uri)) 638 657 { 639 const pjsip_url *url = pjsip_uri_get_uri((void*)topmost_route_uri); 658 const pjsip_sip_uri *url = 659 pjsip_uri_get_uri((void*)topmost_route_uri); 640 660 has_lr_param = url->lr_param; 641 661 } else { … … 674 694 if (PJSIP_URI_SCHEME_IS_SIPS(target_uri)) { 675 695 pjsip_uri *uri = (pjsip_uri*) target_uri; 676 const pjsip_ url *url = (const pjsip_url*)pjsip_uri_get_uri(uri);696 const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 677 697 dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE); 678 698 pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); … … 683 703 } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) { 684 704 pjsip_uri *uri = (pjsip_uri*) target_uri; 685 const pjsip_ url *url = (const pjsip_url*)pjsip_uri_get_uri(uri);705 const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 686 706 pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 687 707 dest_info->addr.port = url->port; -
pjproject/trunk/pjsip/src/pjsua/main.c
r65 r119 1109 1109 if (uri) { 1110 1110 if (pj_stricmp2(pjsip_uri_get_scheme(uri), "sip")==0) { 1111 pjsip_ url *url = (pjsip_url*)pjsip_uri_get_uri(uri);1111 pjsip_sip_uri *url = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 1112 1112 if (url->user.slen) 1113 1113 strncpy(global.user_id, url->user.ptr, url->user.slen); -
pjproject/trunk/pjsip/src/test-pjsip/msg_test.c
r109 r119 333 333 pjsip_msg *msg; 334 334 pjsip_name_addr *name_addr; 335 pjsip_ url*url;335 pjsip_sip_uri *url; 336 336 pjsip_fromto_hdr *fromto; 337 337 pjsip_cid_hdr *cid; … … 538 538 pjsip_route_hdr *route; 539 539 pjsip_name_addr *name_addr; 540 pjsip_ url*url;540 pjsip_sip_uri *url; 541 541 pjsip_max_forwards_hdr *max_fwd; 542 542 pjsip_to_hdr *to; -
pjproject/trunk/pjsip/src/test-pjsip/tsx_uas_test.c
r117 r119 46 46 ** TEST4_BRANCH_ID 47 47 ** Transaction retransmits last response (if any) without notifying 48 ** transaction user upon receiving request retransmissions on: 49 ** a. TRYING state. 50 ** a. PROCEEDING state. 51 ** b. COMPLETED state. 48 ** transaction user upon receiving request retransmissions on TRYING 49 ** state 52 50 ** 53 51 ** TEST5_BRANCH_ID 54 ** INVITE transaction MUST retransmit final response. (Note: PJSIP also 55 ** retransmit 2xx final response until it's terminated by user). 52 ** As above, in PROCEEDING state. 56 53 ** 57 54 ** TEST6_BRANCH_ID 55 ** As above, in COMPLETED state, with first sending provisional response. 56 ** 57 ** TEST7_BRANCH_ID 58 ** INVITE transaction MUST retransmit non-2xx final response. 59 ** 60 ** TEST8_BRANCH_ID 61 ** As above, for INVITE's 2xx final response (this is PJSIP specific). 62 ** 63 ** TEST9_BRANCH_ID 58 64 ** INVITE transaction MUST cease retransmission of final response when 59 * ACK is received. (Note: PJSIP also retransmit 2xx final response 60 * until it's terminated by user). 61 ** 62 ** TEST7_BRANCH_ID 65 ** ACK is received. (Note: PJSIP also retransmit 2xx final response 66 ** until it's terminated by user). 67 ** Transaction also MUST terminate in T4 seconds. 68 ** 69 ** TEST10_BRANCH_ID 63 70 ** Test where INVITE UAS transaction never receives ACK 64 71 ** 65 ** TEST 8_BRANCH_ID72 ** TEST11_BRANCH_ID 66 73 ** When UAS failed to deliver the response with the selected transport, 67 74 ** it should try contacting the client with other transport or begin … … 73 80 ** c. COMPLETED state. 74 81 ** 75 ** TEST 9_BRANCH_ID82 ** TEST12_BRANCH_ID 76 83 ** Variant of previous test, where transaction fails to deliver the 77 84 ** response using any kind of transports. Transaction should report … … 87 94 static char *TEST6_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test6"; 88 95 static char *TEST7_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test7"; 96 static char *TEST8_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test8"; 97 static char *TEST9_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test9"; 98 static char *TEST10_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test10"; 99 static char *TEST11_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test11"; 100 static char *TEST12_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test12"; 89 101 90 102 #define TEST1_STATUS_CODE 200 … … 92 104 #define TEST3_PROVISIONAL_CODE PJSIP_SC_QUEUED 93 105 #define TEST3_STATUS_CODE 202 94 106 #define TEST4_STATUS_CODE 200 107 #define TEST4_REQUEST_COUNT 2 108 #define TEST5_PROVISIONAL_CODE 100 109 #define TEST5_STATUS_CODE 200 110 #define TEST5_REQUEST_COUNT 2 111 #define TEST5_RESPONSE_COUNT 2 112 #define TEST6_PROVISIONAL_CODE 100 113 #define TEST6_STATUS_CODE 200 /* Must be final */ 114 #define TEST6_REQUEST_COUNT 2 115 #define TEST6_RESPONSE_COUNT 3 116 #define TEST7_STATUS_CODE 301 117 #define TEST8_STATUS_CODE 302 118 119 120 #define TEST4_TITLE "test4: absorbing request retransmission" 121 #define TEST5_TITLE "test5: retransmit last response in PROCEEDING state" 122 #define TEST6_TITLE "test6: retransmit last response in COMPLETED state" 123 124 125 #define TEST_TIMEOUT_ERROR -30 126 #define MAX_ALLOWED_DIFF 150 95 127 96 128 static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e); … … 162 194 }; 163 195 196 /* Timer callback to send response. */ 164 197 static void send_response_timer( pj_timer_heap_t *timer_heap, 165 198 struct pj_timer_entry *entry) … … 180 213 PJ_LOG(3,(THIS_FILE," error: timer unable to send response")); 181 214 pjsip_tx_data_dec_ref(r->tdata); 215 return; 216 } 217 } 218 219 /* Utility to send response. */ 220 static void send_response( pjsip_rx_data *rdata, 221 pjsip_transaction *tsx, 222 int status_code ) 223 { 224 pj_status_t status; 225 pjsip_tx_data *tdata; 226 227 status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 228 &tdata); 229 if (status != PJ_SUCCESS) { 230 app_perror(" error: unable to create response", status); 231 test_complete = -196; 232 return; 233 } 234 235 status = pjsip_tsx_send_msg(tsx, tdata); 236 if (status != PJ_SUCCESS) { 237 app_perror(" error: unable to send response", status); 238 pjsip_tx_data_dec_ref(tdata); 239 test_complete = -197; 182 240 return; 183 241 } … … 222 280 } 223 281 } 282 283 284 /* Find and terminate tsx with the specified key. */ 285 static void terminate_our_tsx(int status_code) 286 { 287 pjsip_transaction *tsx; 288 289 tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE); 290 if (!tsx) { 291 PJ_LOG(3,(THIS_FILE," error: timer unable to find transaction")); 292 return; 293 } 294 295 pjsip_tsx_terminate(tsx, status_code); 296 pj_mutex_unlock(tsx->mutex); 297 } 298 299 /* Timer callback to terminate transaction. */ 300 static void terminate_tsx_timer( pj_timer_heap_t *timer_heap, 301 struct pj_timer_entry *entry) 302 { 303 terminate_our_tsx(entry->id); 304 } 305 306 307 /* Schedule timer to terminate transaction. */ 308 static void schedule_terminate_tsx( pjsip_transaction *tsx, 309 int status_code, 310 int msec_delay ) 311 { 312 pj_time_val delay; 313 314 delay.sec = 0; 315 delay.msec = msec_delay; 316 pj_time_val_normalize(&delay); 317 318 pj_assert(pj_strcmp(&tsx->transaction_key, &tsx_key)==0); 319 timer.user_data = NULL; 320 timer.id = status_code; 321 timer.cb = &terminate_tsx_timer; 322 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 323 } 324 224 325 225 326 /* … … 332 433 } 333 434 435 } else 436 if (pj_strcmp2(&tsx->branch, TEST4_BRANCH_ID)==0) { 437 /* 438 * TEST4_BRANCH_ID tests receiving retransmissions in TRYING state. 439 */ 440 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 441 442 /* Check that status code is status_code. */ 443 if (tsx->status_code != TEST4_STATUS_CODE) { 444 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 445 test_complete = -120; 446 } 447 448 /* Previous state. */ 449 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { 450 PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); 451 test_complete = -121; 452 } 453 454 } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) 455 { 456 PJ_LOG(3,(THIS_FILE, " error: unexpected state")); 457 test_complete = -122; 458 459 } 460 461 462 } else 463 if (pj_strcmp2(&tsx->branch, TEST5_BRANCH_ID)==0) { 464 /* 465 * TEST5_BRANCH_ID tests receiving retransmissions in PROCEEDING state 466 */ 467 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 468 469 /* Check that status code is status_code. */ 470 if (tsx->status_code != TEST5_STATUS_CODE) { 471 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 472 test_complete = -130; 473 } 474 475 /* Previous state. */ 476 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { 477 PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); 478 test_complete = -131; 479 } 480 481 } else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { 482 483 /* Check status code. */ 484 if (tsx->status_code != TEST5_PROVISIONAL_CODE) { 485 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 486 test_complete = -132; 487 } 488 489 } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { 490 PJ_LOG(3,(THIS_FILE, " error: unexpected state")); 491 test_complete = -133; 492 493 } 494 495 } else 496 if (pj_strcmp2(&tsx->branch, TEST6_BRANCH_ID)==0) { 497 /* 498 * TEST6_BRANCH_ID tests receiving retransmissions in COMPLETED state 499 */ 500 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 501 502 /* Check that status code is status_code. */ 503 if (tsx->status_code != TEST6_STATUS_CODE) { 504 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 505 test_complete = -140; 506 } 507 508 /* Previous state. */ 509 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 510 PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); 511 test_complete = -141; 512 } 513 514 } else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && 515 tsx->state != PJSIP_TSX_STATE_COMPLETED && 516 tsx->state != PJSIP_TSX_STATE_DESTROYED) 517 { 518 PJ_LOG(3,(THIS_FILE, " error: unexpected state")); 519 test_complete = -142; 520 521 } 522 523 524 } else 525 if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID)==0 || 526 pj_strcmp2(&tsx->branch, TEST8_BRANCH_ID)==0) 527 { 528 /* 529 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test retransmission of 530 * INVITE final response 531 */ 532 int code; 533 534 if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID) == 0) 535 code = TEST7_STATUS_CODE; 536 else 537 code = TEST8_STATUS_CODE; 538 539 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 540 541 if (test_complete == 0) 542 test_complete = 1; 543 544 /* Check status code. */ 545 if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { 546 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 547 test_complete = -150; 548 } 549 550 /* Previous state. */ 551 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 552 PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); 553 test_complete = -151; 554 } 555 556 } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { 557 558 /* Check that status code is status_code. */ 559 if (tsx->status_code != code) { 560 PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); 561 test_complete = -152; 562 } 563 564 /* Previous state. */ 565 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { 566 PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); 567 test_complete = -153; 568 } 569 570 } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { 571 572 PJ_LOG(3,(THIS_FILE, " error: unexpected state")); 573 test_complete = -154; 574 575 } 576 334 577 } 335 578 … … 344 587 pj_strcpy(&tsx_key, &key); 345 588 } 589 590 #define DIFF(a,b) ((a<b) ? (b-a) : (a-b)) 346 591 347 592 /* … … 372 617 */ 373 618 pjsip_transaction *tsx; 374 pjsip_tx_data *tdata;375 619 376 620 status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); … … 382 626 383 627 save_key(tsx); 384 385 status = pjsip_endpt_create_response(endpt, rdata, 386 status_code, NULL, 387 &tdata); 388 if (status != PJ_SUCCESS) { 389 app_perror(" error: unable to create response", status); 390 test_complete = -111; 391 return PJ_TRUE; 392 } 393 394 status = pjsip_tsx_send_msg(tsx, tdata); 395 if (status != PJ_SUCCESS) { 396 app_perror(" error: unable to send response", status); 397 test_complete = -112; 398 return PJ_TRUE; 399 } 628 send_response(rdata, tsx, status_code); 400 629 401 630 } else { … … 428 657 */ 429 658 pjsip_transaction *tsx; 430 pjsip_tx_data *tdata;431 659 432 660 status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); … … 439 667 save_key(tsx); 440 668 441 status = pjsip_endpt_create_response(endpt, rdata, 442 TEST3_PROVISIONAL_CODE, NULL, 443 &tdata); 444 if (status != PJ_SUCCESS) { 445 app_perror(" error: unable to create response", status); 446 test_complete = -121; 447 return PJ_TRUE; 448 } 449 450 status = pjsip_tsx_send_msg(tsx, tdata); 451 if (status != PJ_SUCCESS) { 452 app_perror(" error: unable to send response", status); 453 test_complete = -122; 454 return PJ_TRUE; 455 } 456 669 send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); 457 670 schedule_send_response(rdata, &tsx->transaction_key, 458 671 TEST3_STATUS_CODE, 2000); … … 483 696 return PJ_TRUE; 484 697 698 } else if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0 || 699 pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0 || 700 pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) 701 { 702 703 /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state. */ 704 /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state. */ 705 /* TEST6_BRANCH_ID: retransmit last response in COMPLETED state. */ 706 707 if (msg->type == PJSIP_REQUEST_MSG) { 708 /* On received response, create UAS. */ 709 pjsip_transaction *tsx; 710 711 status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); 712 if (status != PJ_SUCCESS) { 713 app_perror(" error: unable to create transaction", status); 714 test_complete = -130; 715 return PJ_TRUE; 716 } 717 718 save_key(tsx); 719 720 if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) { 721 722 } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) { 723 send_response(rdata, tsx, TEST5_PROVISIONAL_CODE); 724 725 } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) { 726 send_response(rdata, tsx, TEST6_PROVISIONAL_CODE); 727 send_response(rdata, tsx, TEST6_STATUS_CODE); 728 } 729 730 } else { 731 /* Verify the response received. */ 732 733 ++recv_count; 734 735 if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) { 736 PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); 737 test_complete = -132; 738 739 } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) { 740 741 if (rdata->msg_info.msg->line.status.code!=TEST5_PROVISIONAL_CODE) { 742 PJ_LOG(3,(THIS_FILE, " error: incorrect status code!")); 743 test_complete = -133; 744 745 } 746 if (recv_count > TEST5_RESPONSE_COUNT) { 747 PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); 748 test_complete = -134; 749 } 750 751 } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) { 752 753 int code = rdata->msg_info.msg->line.status.code; 754 755 switch (recv_count) { 756 case 1: 757 if (code != TEST6_PROVISIONAL_CODE) { 758 PJ_LOG(3,(THIS_FILE, " error: invalid code!")); 759 test_complete = -135; 760 } 761 break; 762 case 2: 763 case 3: 764 if (code != TEST6_STATUS_CODE) { 765 PJ_LOG(3,(THIS_FILE, " error: invalid code!")); 766 test_complete = -136; 767 } 768 break; 769 default: 770 PJ_LOG(3,(THIS_FILE, " error: not expecting response")); 771 test_complete = -137; 772 break; 773 } 774 } 775 } 776 return PJ_TRUE; 777 778 779 } else if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0 || 780 pj_strcmp2(&branch_param, TEST8_BRANCH_ID) == 0) 781 { 782 783 /* 784 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test the retransmission 785 * of INVITE final response 786 */ 787 if (msg->type == PJSIP_REQUEST_MSG) { 788 789 /* On received response, create UAS. */ 790 pjsip_transaction *tsx; 791 792 status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); 793 if (status != PJ_SUCCESS) { 794 app_perror(" error: unable to create transaction", status); 795 test_complete = -140; 796 return PJ_TRUE; 797 } 798 799 save_key(tsx); 800 801 if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) { 802 803 send_response(rdata, tsx, TEST7_STATUS_CODE); 804 805 } else { 806 807 send_response(rdata, tsx, TEST8_STATUS_CODE); 808 809 } 810 811 } else { 812 int code; 813 814 ++recv_count; 815 816 if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) 817 code = TEST7_STATUS_CODE; 818 else 819 code = TEST8_STATUS_CODE; 820 821 if (recv_count==1) { 822 823 if (rdata->msg_info.msg->line.status.code != code) { 824 PJ_LOG(3,(THIS_FILE," error: invalid status code")); 825 test_complete = -141; 826 } 827 828 recv_last = rdata->pkt_info.timestamp; 829 830 } else { 831 832 pj_time_val now; 833 unsigned msec, msec_expected; 834 835 now = rdata->pkt_info.timestamp; 836 837 PJ_TIME_VAL_SUB(now, recv_last); 838 839 msec = now.sec*1000 + now.msec; 840 msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT; 841 if (msec_expected > PJSIP_T2_TIMEOUT) 842 msec_expected = PJSIP_T2_TIMEOUT; 843 844 if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { 845 PJ_LOG(3,(THIS_FILE, 846 " error: incorrect retransmission " 847 "time (%d ms expected, %d ms received", 848 msec_expected, msec)); 849 test_complete = -142; 850 } 851 852 if (recv_count > 11) { 853 PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", 854 recv_count)); 855 test_complete = -143; 856 } 857 858 recv_last = rdata->pkt_info.timestamp; 859 } 860 861 } 862 return PJ_TRUE; 863 864 } else if (pj_strcmp2(&branch_param, TEST9_BRANCH_ID)) { 865 866 /* 867 * TEST9_BRANCH_ID tests that the retransmission of INVITE final 868 * response should cease when ACK is received. Transaction also MUST 869 * terminate in T4 seconds. 870 */ 871 if (msg->type == PJSIP_REQUEST_MSG) { 872 873 /* On received response, create UAS. */ 874 pjsip_transaction *tsx; 875 876 status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); 877 if (status != PJ_SUCCESS) { 878 app_perror(" error: unable to create transaction", status); 879 test_complete = -140; 880 return PJ_TRUE; 881 } 882 883 save_key(tsx); 884 885 if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) { 886 887 send_response(rdata, tsx, TEST7_STATUS_CODE); 888 889 } else { 890 891 send_response(rdata, tsx, TEST8_STATUS_CODE); 892 893 } 894 895 } else { 896 int code; 897 898 ++recv_count; 899 900 if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) 901 code = TEST7_STATUS_CODE; 902 else 903 code = TEST8_STATUS_CODE; 904 905 if (recv_count==1) { 906 907 if (rdata->msg_info.msg->line.status.code != code) { 908 PJ_LOG(3,(THIS_FILE," error: invalid status code")); 909 test_complete = -141; 910 } 911 912 recv_last = rdata->pkt_info.timestamp; 913 914 } else { 915 916 pj_time_val now; 917 unsigned msec, msec_expected; 918 919 now = rdata->pkt_info.timestamp; 920 921 PJ_TIME_VAL_SUB(now, recv_last); 922 923 msec = now.sec*1000 + now.msec; 924 msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT; 925 if (msec_expected > PJSIP_T2_TIMEOUT) 926 msec_expected = PJSIP_T2_TIMEOUT; 927 928 if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { 929 PJ_LOG(3,(THIS_FILE, 930 " error: incorrect retransmission " 931 "time (%d ms expected, %d ms received", 932 msec_expected, msec)); 933 test_complete = -142; 934 } 935 936 if (recv_count > 11) { 937 PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", 938 recv_count)); 939 test_complete = -143; 940 } 941 942 recv_last = rdata->pkt_info.timestamp; 943 } 944 945 } 946 return PJ_TRUE; 485 947 } 486 948 … … 493 955 static int perform_test( char *target_uri, char *from_uri, 494 956 char *branch_param, int test_time, 495 const pjsip_method *method ) 957 const pjsip_method *method, 958 int request_cnt, int request_interval_msec, 959 int expecting_timeout) 496 960 { 497 961 pjsip_tx_data *tdata; 498 962 pj_str_t target, from; 499 963 pjsip_via_hdr *via; 500 pj_time_val timeout; 964 pj_time_val timeout, next_send; 965 int sent_cnt; 501 966 pj_status_t status; 502 967 … … 527 992 via->branch_param = pj_str(branch_param); 528 993 529 /* Add additional reference to tdata to prevent transaction from 530 * deleting it. 531 */ 532 pjsip_tx_data_add_ref(tdata); 533 534 /* Send the first message. */ 535 status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL); 536 if (status != PJ_SUCCESS) { 537 app_perror(" Error: unable to send request", status); 538 return -20; 539 } 994 /* Schedule first send. */ 995 sent_cnt = 0; 996 pj_gettimeofday(&next_send); 997 pj_time_val_normalize(&next_send); 540 998 541 999 /* Set test completion time. */ … … 550 1008 551 1009 pj_gettimeofday(&now); 1010 1011 if (sent_cnt < request_cnt && PJ_TIME_VAL_GTE(now, next_send)) { 1012 /* Add additional reference to tdata to prevent transaction from 1013 * deleting it. 1014 */ 1015 pjsip_tx_data_add_ref(tdata); 1016 1017 /* (Re)Send the request. */ 1018 status = pjsip_endpt_send_request_stateless(endpt, tdata, 0, 0); 1019 if (status != PJ_SUCCESS) { 1020 app_perror(" Error: unable to send request", status); 1021 pjsip_tx_data_dec_ref(tdata); 1022 return -20; 1023 } 1024 1025 /* Schedule next send, if any. */ 1026 sent_cnt++; 1027 if (sent_cnt < request_cnt) { 1028 pj_gettimeofday(&next_send); 1029 next_send.msec += request_interval_msec; 1030 pj_time_val_normalize(&next_send); 1031 } 1032 } 1033 552 1034 if (now.sec > timeout.sec) { 553 PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); 1035 if (!expecting_timeout) 1036 PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); 554 1037 pjsip_tx_data_dec_ref(tdata); 555 return -30;1038 return TEST_TIMEOUT_ERROR; 556 1039 } 557 1040 } … … 613 1096 TEST1_BRANCH_ID, 614 1097 33, /* Test duration must be greater than 32 secs */ 615 &pjsip_options_method );1098 &pjsip_options_method, 1, 0, 0); 616 1099 if (status != 0) 617 1100 return status; … … 623 1106 TEST2_BRANCH_ID, 624 1107 33, /* Test duration must be greater than 32 secs */ 625 &pjsip_options_method );1108 &pjsip_options_method, 1, 0, 0); 626 1109 if (status != 0) 627 1110 return status; … … 647 1130 TEST3_BRANCH_ID, 648 1131 35, 649 &pjsip_options_method); 1132 &pjsip_options_method, 1, 0, 0); 1133 650 1134 return status; 651 1135 } 1136 1137 1138 /***************************************************************************** 1139 ** 1140 ** TEST4_BRANCH_ID: Absorbs retransmissions in TRYING state 1141 ** TEST5_BRANCH_ID: Absorbs retransmissions in PROCEEDING state 1142 ** TEST6_BRANCH_ID: Absorbs retransmissions in COMPLETED state 1143 ** 1144 ***************************************************************************** 1145 */ 1146 static int tsx_retransmit_last_response_test(const char *title, 1147 char *branch_id, 1148 int request_cnt, 1149 int status_code) 1150 { 1151 int status; 1152 1153 PJ_LOG(3,(THIS_FILE," %s", title)); 1154 1155 status = perform_test("sip:129.0.0.1;transport=loop-dgram", 1156 "sip:129.0.0.1;transport=loop-dgram", 1157 branch_id, 1158 5, 1159 &pjsip_options_method, 1160 request_cnt, 1000, 1); 1161 if (status && status != TEST_TIMEOUT_ERROR) 1162 return status; 1163 if (!status) { 1164 PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); 1165 return -31; 1166 } 1167 1168 terminate_our_tsx(status_code); 1169 flush_events(100); 1170 1171 if (test_complete != 1) 1172 return test_complete; 1173 1174 flush_events(100); 1175 return 0; 1176 } 1177 1178 /***************************************************************************** 1179 ** 1180 ** TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test 1181 ** TEST8_BRANCH_ID: INVITE 2xx final response retransmission test 1182 ** 1183 ***************************************************************************** 1184 */ 1185 static int tsx_final_response_retransmission_test(void) 1186 { 1187 int status; 1188 1189 PJ_LOG(3,(THIS_FILE, 1190 " test7: INVITE non-2xx final response retransmission")); 1191 1192 status = perform_test("sip:129.0.0.1;transport=loop-dgram", 1193 "sip:129.0.0.1;transport=loop-dgram", 1194 TEST7_BRANCH_ID, 1195 33, /* Test duration must be greater than 32 secs */ 1196 &pjsip_invite_method, 1, 0, 0); 1197 if (status != 0) 1198 return status; 1199 1200 PJ_LOG(3,(THIS_FILE, 1201 " test8: INVITE 2xx final response retransmission")); 1202 1203 status = perform_test("sip:129.0.0.1;transport=loop-dgram", 1204 "sip:129.0.0.1;transport=loop-dgram", 1205 TEST8_BRANCH_ID, 1206 33, /* Test duration must be greater than 32 secs */ 1207 &pjsip_invite_method, 1, 0, 0); 1208 if (status != 0) 1209 return status; 1210 1211 return 0; 1212 } 1213 652 1214 653 1215 … … 690 1252 if (status != 0) 691 1253 return status; 692 #endif693 1254 694 1255 /* TEST3_BRANCH_ID: with provisional response … … 698 1259 return status; 699 1260 1261 /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state 1262 */ 1263 status = tsx_retransmit_last_response_test(TEST4_TITLE, 1264 TEST4_BRANCH_ID, 1265 TEST4_REQUEST_COUNT, 1266 TEST4_STATUS_CODE); 1267 if (status != 0) 1268 return status; 1269 1270 /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state 1271 */ 1272 status = tsx_retransmit_last_response_test(TEST5_TITLE, 1273 TEST5_BRANCH_ID, 1274 TEST5_REQUEST_COUNT, 1275 TEST5_STATUS_CODE); 1276 if (status != 0) 1277 return status; 1278 1279 /* TEST6_BRANCH_ID: retransmit last response in PROCEEDING state 1280 */ 1281 status = tsx_retransmit_last_response_test(TEST6_TITLE, 1282 TEST6_BRANCH_ID, 1283 TEST6_REQUEST_COUNT, 1284 TEST6_STATUS_CODE); 1285 if (status != 0) 1286 return status; 1287 1288 /* TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test 1289 * TEST8_BRANCH_ID: INVITE 2xx final response retransmission test 1290 */ 1291 1292 status = tsx_final_response_retransmission_test(); 1293 if (status != 0) 1294 return status; 1295 1296 #endif 700 1297 701 1298 pjsip_transport_dec_ref(loop); -
pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c
r109 r119 30 30 * This tests various core message creation functions. 31 31 */ 32 inttxdata_test(void)32 static int core_txdata_test(void) 33 33 { 34 34 pj_status_t status; … … 36 36 pjsip_rx_data dummy_rdata; 37 37 pjsip_tx_data *invite, *invite2, *cancel, *response, *ack; 38 39 PJ_LOG(3,(THIS_FILE, " core transmit data test")); 38 40 39 41 /* Create INVITE request. */ … … 322 324 } 323 325 326 /* This tests the request creating functions against the following 327 * requirements: 328 * - header params in URI creates header in the request. 329 * - method and headers params are correctly shown or hidden in 330 * request URI, From, To, and Contact header. 331 */ 332 static int txdata_test_uri_params(void) 333 { 334 char msgbuf[512]; 335 pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201" 336 "?X-Hdr-1=Header%201" 337 "&X-Empty-Hdr="); 338 pj_str_t pname = pj_str("x-param"); 339 pj_str_t hname = pj_str("X-Hdr-1"); 340 pj_str_t hemptyname = pj_str("X-Empty-Hdr"); 341 pjsip_from_hdr *from_hdr; 342 pjsip_to_hdr *to_hdr; 343 pjsip_contact_hdr *contact_hdr; 344 pjsip_generic_string_hdr *hdr; 345 pjsip_tx_data *tdata; 346 pjsip_sip_uri *uri; 347 pjsip_param *param; 348 pjsip_msg *msg; 349 int len; 350 pj_status_t status; 351 352 PJ_LOG(3,(THIS_FILE, " header param in URI to create request")); 353 354 /* Create request with header param in target URI. */ 355 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target, 356 &target, &target, &target, NULL, -1, 357 NULL, &tdata); 358 if (status != 0) { 359 app_perror(" error: Unable to create request", status); 360 return -200; 361 } 362 363 /* Print and parse the request. 364 * We'll check that header params are not present in 365 */ 366 len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf)); 367 if (len < 1) { 368 PJ_LOG(3,(THIS_FILE, " error: printing message")); 369 pjsip_tx_data_dec_ref(tdata); 370 return -250; 371 } 372 msgbuf[len] = '\0'; 373 374 PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n" 375 "%s\n" 376 "--end-msg--", len, msgbuf)); 377 378 /* Now parse the message. */ 379 msg = pjsip_parse_msg( tdata->pool, msgbuf, len, NULL); 380 if (msg == NULL) { 381 app_perror(" error: parsing message message", status); 382 pjsip_tx_data_dec_ref(tdata); 383 return -250; 384 } 385 386 /* Check the existence of port, other_param, and header param. 387 * Port is now allowed in To and From header. 388 */ 389 /* Port in request URI. */ 390 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(msg->line.req.uri); 391 if (uri->port != 5061) { 392 PJ_LOG(3,(THIS_FILE, " error: port not present in request URI")); 393 pjsip_tx_data_dec_ref(tdata); 394 return -260; 395 } 396 /* other_param in request_uri */ 397 param = pjsip_param_find(&uri->other_param, &pname); 398 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 399 PJ_LOG(3,(THIS_FILE, " error: x-param not present in request URI")); 400 pjsip_tx_data_dec_ref(tdata); 401 return -261; 402 } 403 /* header param in request uri. */ 404 if (!pj_list_empty(&uri->header_param)) { 405 PJ_LOG(3,(THIS_FILE, " error: hparam in request URI")); 406 pjsip_tx_data_dec_ref(tdata); 407 return -262; 408 } 409 410 /* Port in From header. */ 411 from_hdr = (pjsip_from_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_FROM, NULL); 412 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(from_hdr->uri); 413 if (uri->port != 0) { 414 PJ_LOG(3,(THIS_FILE, " error: port most not exist in From header")); 415 pjsip_tx_data_dec_ref(tdata); 416 return -270; 417 } 418 /* other_param in From header */ 419 param = pjsip_param_find(&uri->other_param, &pname); 420 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 421 PJ_LOG(3,(THIS_FILE, " error: x-param not present in From header")); 422 pjsip_tx_data_dec_ref(tdata); 423 return -271; 424 } 425 /* header param in From header. */ 426 if (!pj_list_empty(&uri->header_param)) { 427 PJ_LOG(3,(THIS_FILE, " error: hparam in From header")); 428 pjsip_tx_data_dec_ref(tdata); 429 return -272; 430 } 431 432 433 /* Port in To header. */ 434 to_hdr = (pjsip_to_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_TO, NULL); 435 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(to_hdr->uri); 436 if (uri->port != 0) { 437 PJ_LOG(3,(THIS_FILE, " error: port most not exist in To header")); 438 pjsip_tx_data_dec_ref(tdata); 439 return -280; 440 } 441 /* other_param in To header */ 442 param = pjsip_param_find(&uri->other_param, &pname); 443 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 444 PJ_LOG(3,(THIS_FILE, " error: x-param not present in To header")); 445 pjsip_tx_data_dec_ref(tdata); 446 return -281; 447 } 448 /* header param in From header. */ 449 if (!pj_list_empty(&uri->header_param)) { 450 PJ_LOG(3,(THIS_FILE, " error: hparam in To header")); 451 pjsip_tx_data_dec_ref(tdata); 452 return -282; 453 } 454 455 456 457 /* Port in Contact header. */ 458 contact_hdr = (pjsip_contact_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL); 459 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(contact_hdr->uri); 460 if (uri->port != 5061) { 461 PJ_LOG(3,(THIS_FILE, " error: port not present in Contact header")); 462 pjsip_tx_data_dec_ref(tdata); 463 return -290; 464 } 465 /* other_param in Contact header */ 466 param = pjsip_param_find(&uri->other_param, &pname); 467 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 468 PJ_LOG(3,(THIS_FILE, " error: x-param not present in Contact header")); 469 pjsip_tx_data_dec_ref(tdata); 470 return -291; 471 } 472 /* header param in Contact header. */ 473 if (pj_list_empty(&uri->header_param)) { 474 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 475 pjsip_tx_data_dec_ref(tdata); 476 return -292; 477 } 478 /* Check for X-Hdr-1 */ 479 param = pjsip_param_find(&uri->header_param, &hname); 480 if (param == NULL || pj_strcmp2(¶m->value, "Header 1")!=0) { 481 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 482 pjsip_tx_data_dec_ref(tdata); 483 return -293; 484 } 485 /* Check for X-Empty-Hdr */ 486 param = pjsip_param_find(&uri->header_param, &hemptyname); 487 if (param == NULL || pj_strcmp2(¶m->value, "")!=0) { 488 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 489 pjsip_tx_data_dec_ref(tdata); 490 return -294; 491 } 492 493 494 /* Check that headers are present in the request. */ 495 hdr = (pjsip_generic_string_hdr*) 496 pjsip_msg_find_hdr_by_name(msg, &hname, NULL); 497 if (hdr == NULL || pj_strcmp2(&hdr->hvalue, "Header 1")!=0) { 498 PJ_LOG(3,(THIS_FILE, " error: header X-Hdr-1 not created")); 499 pjsip_tx_data_dec_ref(tdata); 500 return -300; 501 } 502 503 hdr = (pjsip_generic_string_hdr*) 504 pjsip_msg_find_hdr_by_name(msg, &hemptyname, NULL); 505 if (hdr == NULL || pj_strcmp2(¶m->value, "")!=0) { 506 PJ_LOG(3,(THIS_FILE, " error: header X-Empty-Hdr not created")); 507 pjsip_tx_data_dec_ref(tdata); 508 return -330; 509 } 510 511 pjsip_tx_data_dec_ref(tdata); 512 return 0; 513 } 514 515 int txdata_test(void) 516 { 517 int status; 518 519 status = core_txdata_test(); 520 if (status != 0) 521 return status; 522 523 524 status = txdata_test_uri_params(); 525 if (status != 0) 526 return status; 527 528 return 0; 529 } -
pjproject/trunk/pjsip/src/test-pjsip/uri_test.c
r109 r119 318 318 { 319 319 /* "sip:localhost" */ 320 pjsip_ url*url = pjsip_url_create(pool, 0);320 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 321 321 322 322 pj_strdup2(pool, &url->host, "localhost"); … … 327 327 { 328 328 /* "sip:user@localhost" */ 329 pjsip_ url*url = pjsip_url_create(pool, 0);329 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 330 330 331 331 pj_strdup2( pool, &url->user, "user"); … … 338 338 { 339 339 /* "sip:user:password@localhost:5060" */ 340 pjsip_ url*url = pjsip_url_create(pool, 0);340 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 341 341 342 342 pj_strdup2( pool, &url->user, "user"); … … 351 351 { 352 352 /* Like: "sip:localhost:5060", but without the port. */ 353 pjsip_ url*url = pjsip_url_create(pool, 0);353 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 354 354 355 355 pj_strdup2(pool, &url->host, "localhost"); … … 360 360 { 361 361 /* "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK" */ 362 pjsip_ url*url = pjsip_url_create(pool, 0);362 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 363 363 364 364 pj_strdup2(pool, &url->host, "localhost"); … … 387 387 "?Subject=Hello%20There&Server=SIP%20Server" 388 388 */ 389 pjsip_ url*url = pjsip_url_create(pool, 0);389 pjsip_sip_uri *url = pjsip_url_create(pool, 0); 390 390 391 391 pj_strdup2(pool, &url->host, "localhost"); … … 406 406 { 407 407 /* "sips:localhost" */ 408 pjsip_ url*url = pjsip_url_create(pool, 1);408 pjsip_sip_uri *url = pjsip_url_create(pool, 1); 409 409 410 410 pj_strdup2(pool, &url->host, "localhost"); … … 416 416 /* "<sip:localhost>" */ 417 417 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 418 pjsip_ url*url;418 pjsip_sip_uri *url; 419 419 420 420 url = pjsip_url_create(pool, 0); … … 429 429 /* " Power Administrator <sips:localhost>" */ 430 430 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 431 pjsip_ url*url;431 pjsip_sip_uri *url; 432 432 433 433 url = pjsip_url_create(pool, 1); … … 443 443 /* " \"User\" <sip:user@localhost:5071>" */ 444 444 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 445 pjsip_ url*url;445 pjsip_sip_uri *url; 446 446 447 447 url = pjsip_url_create(pool, 0); … … 459 459 /* " \"Strange User\\\"\\\\\\\"\" <sip:localhost>" */ 460 460 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 461 pjsip_ url*url;461 pjsip_sip_uri *url; 462 462 463 463 url = pjsip_url_create(pool, 0); … … 473 473 /* " \"Rogue User\\\" <sip:localhost>" */ 474 474 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 475 pjsip_ url*url;475 pjsip_sip_uri *url; 476 476 477 477 url = pjsip_url_create(pool, 0); … … 487 487 /* "Strange User\" <sip:localhost>" */ 488 488 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 489 pjsip_ url*url;489 pjsip_sip_uri *url; 490 490 491 491 url = pjsip_url_create(pool, 0); … … 500 500 { 501 501 /* "sip:localhost;pvalue=\"hello world\"" */ 502 pjsip_ url*url;502 pjsip_sip_uri *url; 503 503 url = pjsip_url_create(pool, 0); 504 504 pj_strdup2(pool, &url->host, "localhost"); … … 512 512 /* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@my_proxy09.my-domain.com:9801>" */ 513 513 pjsip_name_addr *name_addr = pjsip_name_addr_create(pool); 514 pjsip_ url*url;514 pjsip_sip_uri *url; 515 515 516 516 url = pjsip_url_create(pool, 0); … … 528 528 { 529 529 /* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */ 530 pjsip_ url*url;530 pjsip_sip_uri *url; 531 531 url = pjsip_url_create(pool, 0); 532 532 pj_strdup2(pool, &url->host, ALPHANUM "-_.com"); … … 537 537 { 538 538 /* "sip:" USER_CHAR ":" PASS_CHAR "@host" */ 539 pjsip_ url*url;539 pjsip_sip_uri *url; 540 540 url = pjsip_url_create(pool, 0); 541 541 pj_strdup2(pool, &url->user, USER_CHAR); … … 548 548 { 549 549 /* "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21;lr;other=1;transport=sctp;other2" */ 550 pjsip_ url*url;550 pjsip_sip_uri *url; 551 551 url = pjsip_url_create(pool, 0); 552 552 pj_strdup2(pool, &url->host, "host");
Note: See TracChangeset
for help on using the changeset viewer.