- Timestamp:
- Jul 17, 2008 1:53:41 PM (16 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip-simple/evsub.h
r2121 r2149 347 347 348 348 /** 349 * Get subscription termination reason, if any. If remote did not 350 * send termination reason, this function will return empty string. 351 * 352 * @param sub Event subscription instance. 353 * 354 * @return NULL terminated string. 355 */ 356 PJ_DECL(const pj_str_t*) pjsip_evsub_get_termination_reason(pjsip_evsub *sub); 357 358 359 /** 349 360 * Call this function to create request to initiate subscription, to 350 361 * refresh subcription, or to request subscription termination. -
pjproject/trunk/pjsip/src/pjsip-simple/evsub.c
r2147 r2149 222 222 pjsip_evsub_state dst_state; /**< Pending state to be set. */ 223 223 pj_str_t dst_state_str;/**< Pending state to be set. */ 224 pj_str_t term_reason; /**< Termination reason. */ 224 225 pjsip_method method; /**< Method that established subscr.*/ 225 226 pjsip_event_hdr *event; /**< Event description. */ … … 551 552 */ 552 553 static void set_state( pjsip_evsub *sub, pjsip_evsub_state state, 553 const pj_str_t *state_str, pjsip_event *event) 554 const pj_str_t *state_str, pjsip_event *event, 555 const pj_str_t *reason) 554 556 { 555 557 pjsip_evsub_state prev_state = sub->state; … … 562 564 else 563 565 sub->state_str = evsub_state_names[state]; 566 567 if (reason && sub->term_reason.slen==0) 568 pj_strdup(sub->pool, &sub->term_reason, reason); 564 569 565 570 PJ_LOG(4,(sub->obj_name, … … 639 644 case TIMER_TYPE_UAC_TERMINATE: 640 645 { 646 pj_str_t timeout = {"timeout", 7}; 647 641 648 PJ_LOG(5,(sub->obj_name, "Timeout waiting for final NOTIFY. " 642 649 "Terminating..")); 643 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL); 650 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, 651 &timeout); 644 652 } 645 653 break; … … 913 921 914 922 sub->call_cb = notify; 915 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL );923 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, NULL); 916 924 917 925 pjsip_dlg_dec_lock(sub->dlg); … … 935 943 } 936 944 945 /* 946 * Get termination reason. 947 */ 948 PJ_DEF(const pj_str_t*) pjsip_evsub_get_termination_reason(pjsip_evsub *sub) 949 { 950 return &sub->term_reason; 951 } 937 952 938 953 /* … … 1086 1101 case PJSIP_EVSUB_STATE_NULL: 1087 1102 case PJSIP_EVSUB_STATE_SENT: 1088 case PJSIP_EVSUB_STATE_ACCEPTED:1089 1103 pj_assert(!"Invalid state!"); 1090 1104 /* Treat as pending */ 1091 1105 1106 case PJSIP_EVSUB_STATE_ACCEPTED: 1092 1107 case PJSIP_EVSUB_STATE_PENDING: 1093 1108 sub_state->sub_state = STR_PENDING; … … 1156 1171 pjsip_auth_clt_init_req( &sub->dlg->auth_sess, tdata ); 1157 1172 1158 1173 /* Update reason */ 1174 if (reason) 1175 pj_strdup(sub->dlg->pool, &sub->term_reason, reason); 1159 1176 1160 1177 /* Save destination state. */ … … 1219 1236 set_state(sub, sub->dst_state, 1220 1237 (sub->dst_state_str.slen ? &sub->dst_state_str : NULL), 1221 NULL );1238 NULL, NULL); 1222 1239 1223 1240 sub->dst_state = PJSIP_EVSUB_STATE_NULL; … … 1547 1564 tsx->state == PJSIP_TSX_STATE_CALLING) 1548 1565 { 1549 set_state(sub, PJSIP_EVSUB_STATE_SENT, NULL, event );1566 set_state(sub, PJSIP_EVSUB_STATE_SENT, NULL, event, NULL); 1550 1567 return; 1551 1568 } … … 1588 1605 /* Authentication failed! */ 1589 1606 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, 1590 NULL, 1591 event); 1607 NULL, event, &tsx->status_text); 1592 1608 return; 1593 1609 } … … 1647 1663 pj_assert(sub->state != PJSIP_EVSUB_STATE_NULL); 1648 1664 if (sub->state == PJSIP_EVSUB_STATE_SENT) { 1649 set_state(sub, PJSIP_EVSUB_STATE_ACCEPTED, NULL, event );1665 set_state(sub, PJSIP_EVSUB_STATE_ACCEPTED, NULL, event, NULL); 1650 1666 } 1651 1667 … … 1686 1702 /* Set state to TERMINATED */ 1687 1703 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, 1688 NULL, event );1704 NULL, event, &tsx->status_text); 1689 1705 1690 1706 } … … 1772 1788 set_timer(sub, TIMER_TYPE_UAC_WAIT_NOTIFY, timeout); 1773 1789 } else { 1774 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL); 1790 char errmsg[PJ_ERR_MSG_SIZE]; 1791 pj_str_t reason; 1792 1793 reason = pj_strerror(status, errmsg, sizeof(errmsg)); 1794 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, 1795 &reason); 1775 1796 } 1776 1797 … … 1816 1837 /* Set the state */ 1817 1838 if (status == PJ_SUCCESS) { 1818 set_state(sub, new_state, new_state_str, event); 1839 set_state(sub, new_state, new_state_str, event, 1840 &sub_state->reason_param); 1819 1841 } else { 1820 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event); 1842 char errmsg[PJ_ERR_MSG_SIZE]; 1843 pj_str_t reason; 1844 1845 reason = pj_strerror(status, errmsg, sizeof(errmsg)); 1846 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event, 1847 &reason); 1821 1848 } 1822 1849 … … 1859 1886 pjsip_evsub_state old_state; 1860 1887 pj_str_t old_state_str; 1888 pj_str_t reason = { NULL, 0 }; 1861 1889 pj_status_t status; 1862 1890 … … 1945 1973 1946 1974 if (sub->expires->ivalue == 0) { 1947 set_state(sub, sub->state, NULL, event );1975 set_state(sub, sub->state, NULL, event, &reason); 1948 1976 } else if (sub->state == PJSIP_EVSUB_STATE_NULL) { 1949 set_state(sub, sub->state, NULL, event );1977 set_state(sub, sub->state, NULL, event, &reason); 1950 1978 } 1951 1979 … … 1981 2009 if (status != PJ_SUCCESS) { 1982 2010 /* Can't authenticate. Terminate session (?) */ 1983 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL); 2011 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, 2012 &tsx->status_text); 1984 2013 return; 1985 2014 } … … 1994 2023 tsx->status_code/100 == 7)) 1995 2024 { 1996 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event); 2025 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event, 2026 &tsx->status_text); 1997 2027 return; 1998 2028 } -
pjproject/trunk/pjsip/src/pjsip-simple/evsub_msg.c
r2039 r2149 20 20 #include <pjsip/print_util.h> 21 21 #include <pjsip/sip_parser.h> 22 #include <pjlib-util/string.h> 22 23 #include <pj/pool.h> 23 24 #include <pj/string.h> … … 167 168 *p++ = ' '; 168 169 169 copy_advance(p, hdr->sub_state); 170 copy_advance_pair(p, ";reason=", 8, hdr->reason_param); 170 copy_advance_escape(p, hdr->sub_state, pc->pjsip_TOKEN_SPEC); 171 copy_advance_pair_escape(p, ";reason=", 8, hdr->reason_param, 172 pc->pjsip_TOKEN_SPEC); 171 173 if (hdr->expires_param >= 0) { 172 174 pj_memcpy(p, ";expires=", 9); -
pjproject/trunk/pjsip/src/pjsip-simple/presence.c
r2039 r2149 462 462 PJ_ASSERT_RETURN(pres != NULL, PJSIP_SIMPLE_ENOPRESENCE); 463 463 464 /* Must have at least one presence info. */ 465 PJ_ASSERT_RETURN(pres->status.info_cnt > 0, PJSIP_SIMPLE_ENOPRESENCEINFO); 464 /* Must have at least one presence info, unless state is 465 * PJSIP_EVSUB_STATE_TERMINATED. This could happen if subscription 466 * has not been active (e.g. we're waiting for user authorization) 467 * and remote cancels the subscription. 468 */ 469 PJ_ASSERT_RETURN(state==PJSIP_EVSUB_STATE_TERMINATED || 470 pres->status.info_cnt > 0, PJSIP_SIMPLE_ENOPRESENCEINFO); 466 471 467 472 … … 475 480 476 481 477 /* Create message body to reflect the presence status. */ 478 status = pres_create_msg_body( pres, tdata ); 479 if (status != PJ_SUCCESS) 480 goto on_return; 481 482 /* Create message body to reflect the presence status. 483 * Only do this if we have presence status info to send (see above). 484 */ 485 if (pres->status.info_cnt > 0) { 486 status = pres_create_msg_body( pres, tdata ); 487 if (status != PJ_SUCCESS) 488 goto on_return; 489 } 482 490 483 491 /* Done. */ … … 508 516 PJ_ASSERT_RETURN(pres != NULL, PJSIP_SIMPLE_ENOPRESENCE); 509 517 510 /* Must have at least one presence info. */ 511 PJ_ASSERT_RETURN(pres->status.info_cnt > 0, PJSIP_SIMPLE_ENOPRESENCEINFO); 518 /* We may not have a presence info yet, e.g. when we receive SUBSCRIBE 519 * to refresh subscription while we're waiting for user authorization. 520 */ 521 //PJ_ASSERT_RETURN(pres->status.info_cnt > 0, 522 // PJSIP_SIMPLE_ENOPRESENCEINFO); 512 523 513 524 … … 522 533 523 534 /* Create message body to reflect the presence status. */ 524 status = pres_create_msg_body( pres, tdata ); 525 if (status != PJ_SUCCESS) 526 goto on_return; 527 535 if (pres->status.info_cnt > 0) { 536 status = pres_create_msg_body( pres, tdata ); 537 if (status != PJ_SUCCESS) 538 goto on_return; 539 } 528 540 529 541 /* Done. */
Note: See TracChangeset
for help on using the changeset viewer.