Changeset 5097
- Timestamp:
- May 18, 2015 4:42:42 AM (9 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r4775 r5097 1514 1514 1515 1515 /** 1516 * Structure of dropped received data. 1517 */ 1518 typedef struct pjsip_tp_dropped_data 1519 { 1520 /** 1521 * The transport receiving the data. 1522 */ 1523 pjsip_transport *tp; 1524 1525 /** 1526 * The data. 1527 */ 1528 void *data; 1529 1530 /** 1531 * The data length. 1532 * If the status field below indicates an invalid SIP message 1533 * (PJSIP_EINVALIDMSG) and application detects a SIP message 1534 * at position p, it can pass the data back to PJSIP to be processed 1535 * by setting the len to p. This can be useful for apps which 1536 * wishes to use the same transport for SIP signalling and non-SIP 1537 * purposes (such as SIP outbound using STUN message). 1538 */ 1539 pj_size_t len; 1540 1541 /** 1542 * The status or reason of drop. For example, a leading newlines (common 1543 * keep-alive packet) will be dropped with status PJ_EIGNORED, an invalid 1544 * SIP message will have status PJSIP_EINVALIDMSG, a SIP message overflow 1545 * will have status PJSIP_ERXOVERFLOW. 1546 */ 1547 pj_status_t status; 1548 1549 } pjsip_tp_dropped_data; 1550 1551 1552 /** 1553 * Type of callback to data dropping notifications. 1554 * 1555 * @param data The dropped data. 1556 */ 1557 typedef void (*pjsip_tp_on_rx_dropped_cb)(pjsip_tp_dropped_data *data); 1558 1559 1560 /** 1561 * Set callback of data dropping. The caller will be notified whenever any 1562 * received data is dropped (due to leading newlines or keep-alive packet or 1563 * invalid SIP message). This callback can be useful for application, 1564 * for example, to implement custom keep-alive mechanism or connection 1565 * availability detection. 1566 * 1567 * @param mgr Transport manager. 1568 * @param cb The callback function, set to NULL to reset the callback. 1569 * 1570 * @return PJ_SUCCESS on success, or the appropriate error code. 1571 */ 1572 PJ_DECL(pj_status_t) pjsip_tpmgr_set_drop_data_cb(pjsip_tpmgr *mgr, 1573 pjsip_tp_on_rx_dropped_cb cb); 1574 1575 1576 /** 1516 1577 * @} 1517 1578 */ -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r4988 r5097 100 100 pj_status_t (*on_tx_msg)(pjsip_endpoint*, pjsip_tx_data*); 101 101 pjsip_tp_state_callback tp_state_cb; 102 pjsip_tp_on_rx_dropped_cb tp_drop_data_cb; 102 103 103 104 /* Transmit data list, for transmit data cleanup when transport manager … … 1694 1695 remaining_len -= (p - current_pkt); 1695 1696 total_processed += (p - current_pkt); 1697 1698 /* Notify application about the dropped newlines */ 1699 if (mgr->tp_drop_data_cb) { 1700 pjsip_tp_dropped_data dd; 1701 pj_bzero(&dd, sizeof(dd)); 1702 dd.tp = tr; 1703 dd.data = current_pkt; 1704 dd.len = p - current_pkt; 1705 dd.status = PJ_EIGNORED; 1706 (*mgr->tp_drop_data_cb)(&dd); 1707 } 1708 1696 1709 current_pkt = p; 1697 1710 if (remaining_len == 0) { … … 1720 1733 if (remaining_len == PJSIP_MAX_PKT_LEN) { 1721 1734 mgr->on_rx_msg(mgr->endpt, PJSIP_ERXOVERFLOW, rdata); 1735 1736 /* Notify application about the message overflow */ 1737 if (mgr->tp_drop_data_cb) { 1738 pjsip_tp_dropped_data dd; 1739 pj_bzero(&dd, sizeof(dd)); 1740 dd.tp = tr; 1741 dd.data = current_pkt; 1742 dd.len = msg_fragment_size; 1743 dd.status = PJSIP_ERXOVERFLOW; 1744 (*mgr->tp_drop_data_cb)(&dd); 1745 } 1746 1722 1747 /* Exhaust all data. */ 1723 1748 return rdata->pkt_info.len; … … 1784 1809 } 1785 1810 1811 /* Notify application about the dropped data (syntax error) */ 1812 if (tmp.slen && mgr->tp_drop_data_cb) { 1813 pjsip_tp_dropped_data dd; 1814 pj_bzero(&dd, sizeof(dd)); 1815 dd.tp = tr; 1816 dd.data = current_pkt; 1817 dd.len = msg_fragment_size; 1818 dd.status = PJSIP_EINVALIDMSG; 1819 (*mgr->tp_drop_data_cb)(&dd); 1820 1821 if (dd.len > 0 && dd.len < msg_fragment_size) 1822 msg_fragment_size = dd.len; 1823 } 1824 1786 1825 goto finish_process_fragment; 1787 1826 } … … 2266 2305 return PJ_SUCCESS; 2267 2306 } 2307 2308 /* 2309 * Set callback of data dropping. 2310 */ 2311 PJ_DEF(pj_status_t) pjsip_tpmgr_set_drop_data_cb(pjsip_tpmgr *mgr, 2312 pjsip_tp_on_rx_dropped_cb cb) 2313 { 2314 PJ_ASSERT_RETURN(mgr, PJ_EINVAL); 2315 2316 mgr->tp_drop_data_cb = cb; 2317 2318 return PJ_SUCCESS; 2319 }
Note: See TracChangeset
for help on using the changeset viewer.