Changeset 283 for pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
- Timestamp:
- Mar 5, 2006 11:53:36 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
r267 r283 125 125 pjsip_event *e) 126 126 { 127 pjsip_inv_state prev_state = inv->state; 128 129 /* Set state. */ 127 130 inv->state = state; 128 if (mod_inv.cb.on_state_changed) 131 132 /* If state is DISCONNECTED, cause code MUST have been set. */ 133 pj_assert(inv->state != PJSIP_INV_STATE_DISCONNECTED || 134 inv->cause != 0); 135 136 /* Call on_state_changed() callback. */ 137 if (mod_inv.cb.on_state_changed && inv->notify) 129 138 (*mod_inv.cb.on_state_changed)(inv, e); 130 139 131 if (inv->state == PJSIP_INV_STATE_DISCONNECTED) 140 /* Only decrement when previous state is not already DISCONNECTED */ 141 if (inv->state == PJSIP_INV_STATE_DISCONNECTED && 142 prev_state != PJSIP_INV_STATE_DISCONNECTED) 143 { 132 144 pjsip_dlg_dec_session(inv->dlg, &mod_inv.mod); 145 } 133 146 } 134 147 … … 291 304 292 305 /* Call on_tsx_state */ 293 if (mod_inv.cb.on_tsx_state_changed )306 if (mod_inv.cb.on_tsx_state_changed && inv->notify) 294 307 (*mod_inv.cb.on_tsx_state_changed)(inv, tsx, e); 295 308 … … 379 392 inv->dlg = dlg; 380 393 inv->options = options; 394 inv->notify = PJ_TRUE; 395 inv->cause = 0; 381 396 382 397 /* Object name will use the same dialog pointer. */ … … 775 790 inv->dlg = dlg; 776 791 inv->options = options; 792 inv->notify = PJ_TRUE; 793 inv->cause = 0; 777 794 778 795 /* Object name will use the same dialog pointer. */ … … 834 851 } 835 852 853 /* 854 * Forcefully terminate the session. 855 */ 856 PJ_DEF(pj_status_t) pjsip_inv_terminate( pjsip_inv_session *inv, 857 int st_code, 858 pj_bool_t notify) 859 { 860 PJ_ASSERT_RETURN(inv, PJ_EINVAL); 861 862 /* Lock dialog. */ 863 pjsip_dlg_inc_lock(inv->dlg); 864 865 /* Set callback notify flag. */ 866 inv->notify = notify; 867 868 /* If there's pending transaction, terminate the transaction. 869 * This may subsequently set the INVITE session state to 870 * disconnected. 871 */ 872 if (inv->invite_tsx && 873 inv->invite_tsx->state <= PJSIP_TSX_STATE_COMPLETED) 874 { 875 pjsip_tsx_terminate(inv->invite_tsx, st_code); 876 877 } 878 879 /* Set cause. */ 880 inv->cause = st_code; 881 882 /* Forcefully terminate the session if state is not DISCONNECTED */ 883 if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { 884 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, NULL); 885 } 886 887 /* Done. 888 * The dec_lock() below will actually destroys the dialog if it 889 * has no other session. 890 */ 891 pjsip_dlg_dec_lock(inv->dlg); 892 893 return PJ_SUCCESS; 894 } 895 896 836 897 static void *clone_sdp(pj_pool_t *pool, const void *data, unsigned len) 837 898 { … … 975 1036 PJ_LOG(5,(inv->obj_name, "SDP negotiation done, status=%d", status)); 976 1037 977 if (mod_inv.cb.on_media_update )1038 if (mod_inv.cb.on_media_update && inv->notify) 978 1039 (*mod_inv.cb.on_media_update)(inv, status); 979 1040 … … 1064 1125 /* Inform application about remote offer. */ 1065 1126 1066 if (mod_inv.cb.on_rx_offer ) {1127 if (mod_inv.cb.on_rx_offer && inv->notify) { 1067 1128 1068 1129 (*mod_inv.cb.on_rx_offer)(inv, sdp); … … 1305 1366 PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); 1306 1367 1368 /* Set cause code. */ 1369 if (inv->cause==0) inv->cause = st_code; 1370 1307 1371 /* Create appropriate message. */ 1308 1372 switch (inv->state) { … … 1359 1423 case PJSIP_INV_STATE_DISCONNECTED: 1360 1424 /* No need to do anything. */ 1361 PJ_TODO(RETURN_A_PROPER_STATUS_CODE_HERE); 1362 return PJ_EINVALIDOP; 1425 return PJSIP_ESESSIONTERMINATED; 1363 1426 1364 1427 default: … … 1613 1676 /* Terminate session: */ 1614 1677 1615 if (inv->state != PJSIP_INV_STATE_DISCONNECTED) 1678 if (inv->state != PJSIP_INV_STATE_DISCONNECTED) { 1679 if (inv->cause==0) inv->cause=PJSIP_SC_OK; 1616 1680 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1681 } 1617 1682 } 1618 1683 … … 1628 1693 1629 1694 if (e->body.tsx_state.type != PJSIP_EVENT_RX_MSG) { 1695 if (inv->cause==0) inv->cause=PJSIP_SC_OK; 1630 1696 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1631 1697 return; … … 1647 1713 * End the session anyway. 1648 1714 */ 1715 if (inv->cause==0) inv->cause=PJSIP_SC_OK; 1649 1716 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1650 1717 … … 1657 1724 1658 1725 /* End the session. */ 1659 1726 if (inv->cause==0) inv->cause=PJSIP_SC_OK; 1660 1727 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1661 1728 } … … 1775 1842 * End the session. 1776 1843 */ 1844 if (inv->cause==0) inv->cause = tsx->status_code; 1777 1845 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1778 1846 … … 1789 1857 } else { 1790 1858 1859 if (inv->cause==0) inv->cause = tsx->status_code; 1791 1860 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1792 1861 … … 1816 1885 1817 1886 } else { 1887 if (inv->cause==0) inv->cause = tsx->status_code; 1818 1888 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1819 1889 } … … 1838 1908 PJSIP_SC_TSX_TRANSPORT_ERROR) 1839 1909 { 1910 if (inv->cause==0) inv->cause = tsx->status_code; 1840 1911 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1841 1912 } … … 1878 1949 * Transaction sent final response. 1879 1950 */ 1880 if (tsx->status_code/100 == 2) 1951 if (tsx->status_code/100 == 2) { 1881 1952 inv_set_state(inv, PJSIP_INV_STATE_CONNECTING, e); 1882 else 1953 } else { 1954 if (inv->cause==0) inv->cause = tsx->status_code; 1883 1955 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1956 } 1884 1957 break; 1885 1958 … … 1889 1962 * response) 1890 1963 */ 1964 if (inv->cause==0) inv->cause = tsx->status_code; 1891 1965 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1892 1966 break; … … 1949 2023 } 1950 2024 1951 } else 2025 } else { 2026 if (inv->cause==0) inv->cause = tsx->status_code; 1952 2027 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 2028 } 1953 2029 break; 1954 2030 … … 1982 2058 1983 2059 } else { 2060 if (inv->cause==0) inv->cause = tsx->status_code; 1984 2061 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 1985 2062 } … … 2017 2094 PJSIP_SC_TSX_TRANSPORT_ERROR) 2018 2095 { 2096 if (inv->cause==0) inv->cause = tsx->status_code; 2019 2097 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 2020 2098 } … … 2050 2128 */ 2051 2129 if (tsx->status_code/100 != 2) { 2130 if (inv->cause==0) inv->cause = tsx->status_code; 2052 2131 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 2053 2132 } … … 2241 2320 * Handle responses that terminates dialog. 2242 2321 */ 2322 if (inv->cause==0) inv->cause = tsx->status_code; 2243 2323 inv_set_state(inv, PJSIP_INV_STATE_DISCONNECTED, e); 2244 2324 }
Note: See TracChangeset
for help on using the changeset viewer.