Changeset 2044
- Timestamp:
- Jun 21, 2008 5:51:31 PM (16 years ago)
- Location:
- pjproject/trunk/pjnath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/include/pjnath/stun_msg.h
r2041 r2044 1226 1226 1227 1227 /** 1228 * Initialize a generic STUN message. 1229 * 1230 * @param msg The message structure to be initialized. 1231 * @param msg_type The 14bit message type (see pj_stun_msg_type 1232 * constants). 1233 * @param magic Magic value to be put to the mesage; for requests, 1234 * the value normally should be PJ_STUN_MAGIC. 1235 * @param tsx_id Optional transaction ID, or NULL to let the 1236 * function generates a random transaction ID. 1237 * 1238 * @return PJ_SUCCESS on success. 1239 */ 1240 PJ_DECL(pj_status_t) pj_stun_msg_init(pj_stun_msg *msg, 1241 unsigned msg_type, 1242 pj_uint32_t magic, 1243 const pj_uint8_t tsx_id[12]); 1244 1245 /** 1228 1246 * Create a generic STUN message. 1229 1247 * … … 1436 1454 1437 1455 /** 1456 * Initialize generic STUN IP address attribute. The \a addr_len and 1457 * \a addr parameters specify whether the address is IPv4 or IPv4 1458 * address. 1459 * 1460 * @param attr The socket address attribute to initialize. 1461 * @param attr_type Attribute type, from #pj_stun_attr_type. 1462 * @param xor_ed If non-zero, the port and address will be XOR-ed 1463 * with magic, to make the XOR-MAPPED-ADDRESS attribute. 1464 * @param addr A pj_sockaddr_in or pj_sockaddr_in6 structure. 1465 * @param addr_len Length of \a addr parameter. 1466 * 1467 * @return PJ_SUCCESS on success or the appropriate error code. 1468 */ 1469 PJ_DECL(pj_status_t) pj_stun_sockaddr_attr_init(pj_stun_sockaddr_attr *attr, 1470 int attr_type, 1471 pj_bool_t xor_ed, 1472 const pj_sockaddr_t *addr, 1473 unsigned addr_len); 1474 1475 /** 1438 1476 * Create a generic STUN IP address attribute. The \a addr_len and 1439 1477 * \a addr parameters specify whether the address is IPv4 or IPv4 … … 1481 1519 1482 1520 /** 1521 * Initialize a STUN generic string attribute. 1522 * 1523 * @param attr The string attribute to be initialized. 1524 * @param pool Pool to duplicate the value into the attribute, 1525 * if value is not NULL or empty. 1526 * @param attr_type Attribute type, from #pj_stun_attr_type. 1527 * @param value The string value to be assigned to the attribute. 1528 * 1529 * @return PJ_SUCCESS on success or the appropriate error code. 1530 */ 1531 PJ_DECL(pj_status_t) pj_stun_string_attr_init(pj_stun_string_attr *attr, 1532 pj_pool_t *pool, 1533 int attr_type, 1534 const pj_str_t *value); 1535 1536 /** 1483 1537 * Create a STUN generic string attribute. 1484 1538 * … … 1657 1711 unsigned attr_cnt, 1658 1712 const pj_uint16_t attr[]); 1713 1714 /** 1715 * Initialize STUN binary attribute. 1716 * 1717 * @param attr The attribute to be initialized. 1718 * @param pool Pool to copy data, if the data and length are set. 1719 * @param attr_type The attribute type, from #pj_stun_attr_type. 1720 * @param data Data to be coped to the attribute, or NULL 1721 * if no data to be copied now. 1722 * @param length Length of data, or zero if no data is to be 1723 * copied now. 1724 * 1725 * @return PJ_SUCCESS on success or the appropriate error code. 1726 */ 1727 PJ_DECL(pj_status_t) pj_stun_binary_attr_init(pj_stun_binary_attr *attr, 1728 pj_pool_t *pool, 1729 int attr_type, 1730 const pj_uint8_t *data, 1731 unsigned length); 1659 1732 1660 1733 /** -
pjproject/trunk/pjnath/src/pjnath/stun_msg.c
r2041 r2044 713 713 714 714 /* 715 * Init sockaddr attr 716 */ 717 PJ_DEF(pj_status_t) pj_stun_sockaddr_attr_init( pj_stun_sockaddr_attr *attr, 718 int attr_type, 719 pj_bool_t xor_ed, 720 const pj_sockaddr_t *addr, 721 unsigned addr_len) 722 { 723 PJ_ASSERT_RETURN(attr && addr_len && addr, PJ_EINVAL); 724 PJ_ASSERT_RETURN(addr_len == sizeof(pj_sockaddr_in) || 725 addr_len == sizeof(pj_sockaddr_in6), PJ_EINVAL); 726 727 INIT_ATTR(attr, attr_type, STUN_GENERIC_IP_ADDR_LEN); 728 729 pj_memcpy(&attr->sockaddr, addr, addr_len); 730 attr->xor_ed = xor_ed; 731 732 return PJ_SUCCESS; 733 } 734 735 736 /* 715 737 * Create a generic STUN IP address attribute for IPv4 address. 716 738 */ … … 724 746 pj_stun_sockaddr_attr *attr; 725 747 726 PJ_ASSERT_RETURN(pool && addr_len && addr && p_attr, PJ_EINVAL); 727 PJ_ASSERT_RETURN(addr_len == sizeof(pj_sockaddr_in) || 728 addr_len == sizeof(pj_sockaddr_in6), PJ_EINVAL); 729 748 PJ_ASSERT_RETURN(pool && p_attr, PJ_EINVAL); 730 749 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_sockaddr_attr); 731 INIT_ATTR(attr, attr_type, STUN_GENERIC_IP_ADDR_LEN);732 733 pj_memcpy(&attr->sockaddr, addr, addr_len);734 attr->xor_ed = xor_ed;735 736 750 *p_attr = attr; 737 738 return PJ_SUCCESS;751 return pj_stun_sockaddr_attr_init(attr, attr_type, xor_ed, 752 addr, addr_len); 739 753 } 740 754 … … 898 912 899 913 /* 914 * Initialize a STUN generic string attribute. 915 */ 916 PJ_DEF(pj_status_t) pj_stun_string_attr_init( pj_stun_string_attr *attr, 917 pj_pool_t *pool, 918 int attr_type, 919 const pj_str_t *value) 920 { 921 INIT_ATTR(attr, attr_type, value->slen); 922 if (value && value->slen) 923 pj_strdup(pool, &attr->value, value); 924 else 925 attr->value.slen = 0; 926 return PJ_SUCCESS; 927 } 928 929 930 /* 900 931 * Create a STUN generic string attribute. 901 932 */ … … 910 941 911 942 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_string_attr); 912 INIT_ATTR(attr, attr_type, value->slen);913 pj_strdup(pool, &attr->value, value);914 915 943 *p_attr = attr; 916 944 917 return PJ_SUCCESS;945 return pj_stun_string_attr_init(attr, pool, attr_type, value); 918 946 } 919 947 … … 1642 1670 1643 1671 /* 1672 * Initialize STUN binary attribute. 1673 */ 1674 PJ_DEF(pj_status_t) pj_stun_binary_attr_init( pj_stun_binary_attr *attr, 1675 pj_pool_t *pool, 1676 int attr_type, 1677 const pj_uint8_t *data, 1678 unsigned length) 1679 { 1680 PJ_ASSERT_RETURN(attr_type, PJ_EINVAL); 1681 1682 INIT_ATTR(attr, attr_type, length); 1683 1684 attr->magic = PJ_STUN_MAGIC; 1685 1686 if (data && length) { 1687 attr->length = length; 1688 attr->data = (pj_uint8_t*) pj_pool_alloc(pool, length); 1689 pj_memcpy(attr->data, data, length); 1690 } else { 1691 attr->data = NULL; 1692 attr->length = 0; 1693 } 1694 1695 return PJ_SUCCESS; 1696 } 1697 1698 1699 /* 1644 1700 * Create a blank binary attribute. 1645 1701 */ … … 1653 1709 1654 1710 PJ_ASSERT_RETURN(pool && attr_type && p_attr, PJ_EINVAL); 1655 1656 1711 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_binary_attr); 1657 INIT_ATTR(attr, attr_type, length);1658 1659 attr->magic = PJ_STUN_MAGIC;1660 1661 if (data && length) {1662 attr->length = length;1663 attr->data = (pj_uint8_t*) pj_pool_alloc(pool, length);1664 pj_memcpy(attr->data, data, length);1665 }1666 1667 1712 *p_attr = attr; 1668 1669 return PJ_SUCCESS; 1713 return pj_stun_binary_attr_init(attr, pool, attr_type, data, length); 1670 1714 } 1671 1715 … … 1754 1798 1755 1799 /* 1756 * Create a blank STUN message. 1757 */ 1758 PJ_DEF(pj_status_t) pj_stun_msg_create( pj_pool_t *pool, 1759 unsigned msg_type, 1760 pj_uint32_t magic, 1761 const pj_uint8_t tsx_id[12], 1762 pj_stun_msg **p_msg) 1763 { 1764 pj_stun_msg *msg; 1765 1766 PJ_ASSERT_RETURN(pool && msg_type && p_msg, PJ_EINVAL); 1767 1768 msg = PJ_POOL_ZALLOC_T(pool, pj_stun_msg); 1800 * Initialize a generic STUN message. 1801 */ 1802 PJ_DEF(pj_status_t) pj_stun_msg_init( pj_stun_msg *msg, 1803 unsigned msg_type, 1804 pj_uint32_t magic, 1805 const pj_uint8_t tsx_id[12]) 1806 { 1807 PJ_ASSERT_RETURN(msg && msg_type, PJ_EINVAL); 1808 1769 1809 msg->hdr.type = (pj_uint16_t) msg_type; 1810 msg->hdr.length = 0; 1770 1811 msg->hdr.magic = magic; 1812 msg->attr_count = 0; 1771 1813 1772 1814 if (tsx_id) { … … 1781 1823 static pj_uint32_t pj_stun_tsx_id_counter; 1782 1824 1825 if (!pj_stun_tsx_id_counter) 1826 pj_stun_tsx_id_counter = pj_rand(); 1827 1783 1828 id.proc_id = pj_getpid(); 1784 1829 id.random = pj_rand(); … … 1788 1833 } 1789 1834 1835 return PJ_SUCCESS; 1836 } 1837 1838 1839 /* 1840 * Create a blank STUN message. 1841 */ 1842 PJ_DEF(pj_status_t) pj_stun_msg_create( pj_pool_t *pool, 1843 unsigned msg_type, 1844 pj_uint32_t magic, 1845 const pj_uint8_t tsx_id[12], 1846 pj_stun_msg **p_msg) 1847 { 1848 pj_stun_msg *msg; 1849 1850 PJ_ASSERT_RETURN(pool && msg_type && p_msg, PJ_EINVAL); 1851 1852 msg = PJ_POOL_ZALLOC_T(pool, pj_stun_msg); 1790 1853 *p_msg = msg; 1791 1792 return PJ_SUCCESS; 1854 return pj_stun_msg_init(msg, msg_type, magic, tsx_id); 1793 1855 } 1794 1856
Note: See TracChangeset
for help on using the changeset viewer.