- Timestamp:
- Dec 9, 2006 12:39:42 AM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/build/py_pjsua.dsp
r845 r851 99 99 # Begin Source File 100 100 101 SOURCE=..\src\py_pjsua\pjsua_app.py 102 # PROP Exclude_From_Build 1 103 # End Source File 104 # Begin Source File 105 101 106 SOURCE=..\src\py_pjsua\py_pjsua.c 102 107 # End Source File -
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua.py
r845 r851 8 8 # Create configuration objects 9 9 # 10 ua_cfg = py_pjsua. Config()11 log_cfg = py_pjsua. Logging_Config()12 media_cfg = py_pjsua. Media_Config()10 ua_cfg = py_pjsua.config_default() 11 log_cfg = py_pjsua.logging_config_default() 12 media_cfg = py_pjsua.media_config_default() 13 13 14 14 # … … 18 18 print str, 19 19 20 21 #22 # Initialize configs with default values.23 #24 py_pjsua.config_default(ua_cfg)25 py_pjsua.logging_config_default(log_cfg)26 py_pjsua.media_config_default(media_cfg)27 20 28 21 # … … 47 40 48 41 49 message = py_pjsua. Msg_Data()50 py_pjsua.msg_data_init(message) 42 message = py_pjsua.msg_data_init() 43 51 44 print "identitas object message data :" + `message` 52 45 … … 76 69 77 70 # lib transport 78 stunc = py_pjsua.STUN_Config(); 79 py_pjsua.stun_config_default(stunc); 71 stunc = py_pjsua.stun_config_default(); 80 72 81 tc = py_pjsua.Transport_Config(); 82 py_pjsua.transport_config_default(tc); 73 74 tc = py_pjsua.transport_config_default(); 75 83 76 84 77 py_pjsua.normalize_stun_config(stunc); 85 78 86 id = py_pjsua.Transport_ID(); 87 status = py_pjsua.transport_create(1, tc, id);79 80 status, id = py_pjsua.transport_create(1, tc); 88 81 print "py transport create status " + `status` 89 82 90 t_id = id.transport_id;91 83 ti = py_pjsua.Transport_Info(); 92 status = py_pjsua.transport_get_info(t_id,ti)84 ti = py_pjsua.transport_get_info(id) 93 85 print "py transport get info status " + `status` 94 86 95 status = py_pjsua.transport_set_enable( t_id,1)87 status = py_pjsua.transport_set_enable(id,1) 96 88 print "py transport set enable status " + `status` 97 89 if status != 0 : … … 99 91 100 92 101 status = py_pjsua.transport_close( t_id,1)93 status = py_pjsua.transport_close(id,1) 102 94 print "py transport close status " + `status` 103 95 if status != 0 : … … 108 100 # lib account 109 101 110 accfg = py_pjsua.Acc_Config() 111 py_pjsua.acc_config_default(accfg) 112 accid = py_pjsua.Acc_ID() 113 status = py_pjsua.acc_add(accfg, 1, accid) 102 accfg = py_pjsua.acc_config_default() 103 status, accid = py_pjsua.acc_add(accfg, 1) 114 104 print "py acc add status " + `status` 115 105 if status != 0 : … … 118 108 print "acc count " + `count` 119 109 120 accid .acc_id= py_pjsua.acc_get_default()110 accid = py_pjsua.acc_get_default() 121 111 122 print "acc id default " + `accid .acc_id`112 print "acc id default " + `accid` 123 113 124 114 # end of lib account 115 116 #lib buddy 117 118 bcfg = py_pjsua.Buddy_Config() 119 status, id = py_pjsua.buddy_add(bcfg) 120 print "py buddy add status " + `status` + " id " + `id` 121 bool = py_pjsua.buddy_is_valid(id) 122 print "py buddy is valid " + `bool` 123 count = py_pjsua.get_buddy_count() 124 print "buddy count " + `count` 125 binfo = py_pjsua.buddy_get_info(id) 126 ids = py_pjsua.enum_buddies(3) 127 status = py_pjsua.buddy_del(id) 128 print "py buddy del status " + `status` 129 status = py_pjsua.buddy_subscribe_pres(id, 1) 130 print "py buddy subscribe pres status " + `status` 131 py_pjsua.pres_dump(1) 132 status = py_pjsua.im_send(accid, "fahris@divusi.com", "", "hallo", message, 0) 133 print "py im send status " + `status` 134 status = py_pjsua.im_typing(accid, "fahris@divusi.com", 1, message) 135 print "py im typing status " + `status` 136 #print "binfo " + `binfo` 137 138 #end of lib buddy 125 139 126 140 py_pjsua.perror("saya","hallo",70006) -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r845 r851 237 237 /* 238 238 * Notify application on call being transfered. 239 * !modified @061206 239 240 */ 240 241 static void cb_on_call_transfer_request(pjsua_call_id call_id, … … 242 243 pjsip_status_code *code) 243 244 { 245 PyObject * ret; 246 int cd; 244 247 if (PyCallable_Check(obj_callback->on_call_transfer_request)) 245 248 { 246 PyObject_CallFunctionObjArgs(249 ret = PyObject_CallFunctionObjArgs( 247 250 obj_callback->on_call_transfer_request, 248 251 Py_BuildValue("i",call_id), … … 251 254 NULL 252 255 ); 256 if (ret != NULL) { 257 if (ret != Py_None) { 258 if (PyArg_Parse(ret,"i",&cd)) { 259 *code = cd; 260 } 261 } 262 } 253 263 } 254 264 } … … 260 270 * call transfer request, for example to decide whether to 261 271 * terminate existing call. 272 * !modified @061206 262 273 */ 263 274 static void cb_on_call_transfer_status( pjsua_call_id call_id, … … 267 278 pj_bool_t *p_cont) 268 279 { 280 PyObject * ret; 281 int cnt; 269 282 if (PyCallable_Check(obj_callback->on_call_transfer_status)) 270 283 { 271 PyObject_CallFunctionObjArgs(284 ret = PyObject_CallFunctionObjArgs( 272 285 obj_callback->on_call_transfer_status, 273 286 Py_BuildValue("i",call_id), … … 278 291 NULL 279 292 ); 293 if (ret != NULL) { 294 if (ret != Py_None) { 295 if (PyArg_Parse(ret,"i",&cnt)) { 296 *p_cont = cnt; 297 } 298 } 299 } 280 300 } 281 301 } … … 285 305 * Notify application about incoming INVITE with Replaces header. 286 306 * Application may reject the request by setting non-2xx code. 307 * !modified @061206 287 308 */ 288 309 static void cb_on_call_replace_request( pjsua_call_id call_id, … … 291 312 pj_str_t *st_text) 292 313 { 314 PyObject * ret; 315 PyObject * txt; 316 int cd; 293 317 if (PyCallable_Check(obj_callback->on_call_replace_request)) 294 318 { 295 319 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) 296 320 PyType_GenericNew(&pjsip_rx_data_Type, 297 321 NULL, NULL); 298 299 300 PyObject_CallFunctionObjArgs(322 obj->rdata = rdata; 323 324 ret = PyObject_CallFunctionObjArgs( 301 325 obj_callback->on_call_replace_request, 302 326 Py_BuildValue("i",call_id), … … 306 330 NULL 307 331 ); 332 if (ret != NULL) { 333 if (ret != Py_None) { 334 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) { 335 *st_code = cd; 336 st_text->ptr = PyString_AsString(txt); 337 st_text->slen = strlen(PyString_AsString(txt)); 338 } 339 } 340 } 308 341 } 309 342 } … … 1111 1144 * msg_data_Object 1112 1145 * typewrapper for MessageData class 1146 * !modified @ 061206 1113 1147 */ 1114 1148 typedef struct … … 1116 1150 PyObject_HEAD 1117 1151 /* Type-specific fields go here. */ 1118 pjsip_hdr hdr_list; 1152 /*pjsip_hdr hdr_list;*/ 1153 PyObject * hdr_list; 1119 1154 PyObject * content_type; 1120 1155 PyObject * msg_body; … … 1125 1160 * msg_data_dealloc 1126 1161 * deletes a msg_data 1162 * !modified @ 061206 1127 1163 */ 1128 1164 static void msg_data_dealloc(msg_data_Object* self) 1129 1165 { 1166 Py_XDECREF(self->hdr_list); 1130 1167 Py_XDECREF(self->content_type); 1131 1168 Py_XDECREF(self->msg_body); … … 1137 1174 * msg_data_new 1138 1175 * constructor for msg_data object 1176 * !modified @ 061206 1139 1177 */ 1140 1178 static PyObject * msg_data_new(PyTypeObject *type, PyObject *args, … … 1146 1184 if (self != NULL) 1147 1185 { 1186 Py_INCREF(Py_None); 1187 self->hdr_list = Py_None; 1188 if (self->hdr_list == NULL) 1189 { 1190 Py_DECREF(self); 1191 return NULL; 1192 } 1148 1193 self->content_type = PyString_FromString(""); 1149 1194 if (self->content_type == NULL) … … 1166 1211 /* 1167 1212 * msg_data_members 1213 * !modified @ 061206 1168 1214 */ 1169 1215 static PyMemberDef msg_data_members[] = 1170 1216 { 1171 1217 { 1172 "content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type), 1218 "hdr_list", T_OBJECT_EX, offsetof(msg_data_Object, hdr_list), 1219 0, "Additional message headers as linked list." 1220 }, 1221 { 1222 "content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type), 1173 1223 0, "MIME type of optional message body." 1174 1224 }, … … 1228 1278 }; 1229 1279 1280 /* 1281 * translate_hdr 1282 * internal function 1283 * translate from hdr_list to pjsip_generic_string_hdr 1284 */ 1285 void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list) 1286 { 1287 int i; 1288 1289 if (PyList_Check(py_hdr_list)) { 1290 pj_list_init(hdr); 1291 1292 for (i = 0; i < PyList_Size(py_hdr_list); i++) { 1293 pj_str_t hname, hvalue; 1294 pjsip_generic_string_hdr * new_hdr; 1295 PyObject * tuple = PyList_GetItem(py_hdr_list, i); 1296 1297 if (PyTuple_Check(tuple)) { 1298 hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0)); 1299 hname.slen = strlen(PyString_AsString(PyTuple_GetItem(tuple,0))); 1300 hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1)); 1301 hvalue.slen = strlen(PyString_AsString(PyTuple_GetItem(tuple,1))); 1302 } else { 1303 hname.ptr = ""; 1304 hname.slen = 0; 1305 hvalue.ptr = ""; 1306 hvalue.slen = 0; 1307 } 1308 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue); 1309 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr); 1310 } 1311 } 1312 } 1313 1314 /* 1315 * translate_hdr_rev 1316 * internal function 1317 * translate from pjsip_generic_string_hdr to hdr_list 1318 */ 1319 1320 void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list) 1321 { 1322 int i; 1323 int len; 1324 pjsip_generic_string_hdr * p_hdr; 1325 1326 len = pj_list_size(hdr); 1327 1328 if (len > 0) { 1329 p_hdr = hdr; 1330 Py_XDECREF(py_hdr_list); 1331 py_hdr_list = PyList_New(len); 1332 1333 for (i = 0; i < len && p_hdr != NULL; i++) { 1334 PyObject * tuple; 1335 PyObject * str; 1336 1337 tuple = PyTuple_New(2); 1338 1339 str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen); 1340 PyTuple_SetItem(tuple, 0, str); 1341 str = PyString_FromStringAndSize(hdr->hvalue.ptr, p_hdr->hvalue.slen); 1342 PyTuple_SetItem(tuple, 1, str); 1343 PyList_SetItem(py_hdr_list, i, tuple); 1344 p_hdr = p_hdr->next; 1345 } 1346 } 1347 1348 1349 } 1230 1350 1231 1351 /* … … 1444 1564 return NULL; 1445 1565 } 1446 1566 self->scheme = PyString_FromString(""); 1447 1567 if (self->scheme == NULL) 1448 1568 { … … 1450 1570 return NULL; 1451 1571 } 1452 1572 self->username = PyString_FromString(""); 1453 1573 if (self->username == NULL) 1454 1574 { … … 1456 1576 return NULL; 1457 1577 } 1458 1578 self->data = PyString_FromString(""); 1459 1579 if (self->data == NULL) 1460 1580 { … … 1473 1593 static PyMemberDef pjsip_cred_info_members[] = 1474 1594 { 1475 1476 1477 1478 1479 }, 1480 1481 1482 1483 1484 }, 1485 1486 1487 1488 1489 }, 1490 1491 1492 1493 1494 }, 1495 { 1496 1497 1595 { 1596 "realm", T_OBJECT_EX, 1597 offsetof(pjsip_cred_info_Object, realm), 0, 1598 "Realm" 1599 }, 1600 { 1601 "scheme", T_OBJECT_EX, 1602 offsetof(pjsip_cred_info_Object, scheme), 0, 1603 "Scheme" 1604 }, 1605 { 1606 "username", T_OBJECT_EX, 1607 offsetof(pjsip_cred_info_Object, username), 0, 1608 "User name" 1609 }, 1610 { 1611 "data", T_OBJECT_EX, 1612 offsetof(pjsip_cred_info_Object, data), 0, 1613 "The data, which can be a plaintext password or a hashed digest. " 1614 }, 1615 { 1616 "data_type", T_INT, offsetof(pjsip_cred_info_Object, data_type), 0, 1617 "Type of data" 1498 1618 }, 1499 1619 … … 1548 1668 }; 1549 1669 1670 /* 1671 * py_pjsua_thread_register 1672 * !added @ 061206 1673 */ 1674 static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject 1675 *pArgs) 1676 { 1677 1678 pj_status_t status; 1679 const char *name; 1680 PyObject *py_desc; 1681 pj_thread_t *thread; 1682 void *thread_desc; 1683 int size; 1684 int i; 1685 int *td; 1686 1687 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) 1688 { 1689 return NULL; 1690 } 1691 #if 0 1692 size = PyList_Size(py_desc); 1693 td = (int *)malloc(size * sizeof(int)); 1694 for (i = 0; i < size; i++) { 1695 if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i])) { 1696 return NULL; 1697 } 1698 } 1699 thread_desc = td; 1700 #else 1701 thread_desc = malloc(sizeof(pj_thread_desc)); 1702 #endif 1703 status = pj_thread_register(name, thread_desc, &thread); 1704 return Py_BuildValue("i",status); 1705 } 1550 1706 1551 1707 /* 1552 1708 * py_pjsua_logging_config_default 1709 * !modified @ 051206 1553 1710 */ 1554 1711 static PyObject *py_pjsua_logging_config_default(PyObject *pSelf, 1555 1712 PyObject *pArgs) 1556 1713 { 1557 logging_config_Object *obj; 1714 logging_config_Object *obj; 1558 1715 pjsua_logging_config cfg; 1559 1716 1560 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 1561 { 1562 return NULL; 1563 } 1564 /*pj_bzero(cfg, sizeof(*cfg)); 1565 1566 cfg->msg_logging = obj->msg_logging; 1567 cfg->level = obj->level; 1568 cfg->console_level = obj->console_level; 1569 cfg->decor = obj->decor;*/ 1717 if (!PyArg_ParseTuple(pArgs, "")) 1718 { 1719 return NULL; 1720 } 1721 1570 1722 pjsua_logging_config_default(&cfg); 1723 obj = (logging_config_Object *) logging_config_new 1724 (&logging_config_Type,NULL,NULL); 1571 1725 obj->msg_logging = cfg.msg_logging; 1572 1726 obj->level = cfg.level; 1573 1727 obj->console_level = cfg.console_level; 1574 1728 obj->decor = cfg.decor; 1575 /*printf("msg logging : %d\n",obj->msg_logging); 1576 printf("level : %d\n",obj->level); 1577 printf("console level : %d\n",obj->console_level); 1578 printf("decor : %d\n",obj->decor); 1579 printf("str sebelum "); 1580 printf(PyString_AsString(obj->log_filename)); 1581 1582 Py_XDECREF(obj->log_filename); 1583 obj->log_filename = PyString_FromString("oke"); 1584 printf("\nstr sesudah "); 1585 printf(PyString_AsString(obj->log_filename));*/ 1586 Py_INCREF(Py_None); 1587 return Py_None; 1729 1730 return (PyObject *)obj; 1588 1731 } 1589 1732 … … 1591 1734 /* 1592 1735 * py_pjsua_config_default 1736 * !modified @ 051206 1593 1737 */ 1594 1738 static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs) … … 1597 1741 pjsua_config cfg; 1598 1742 1599 if (!PyArg_ParseTuple(pArgs, " O", &obj))1743 if (!PyArg_ParseTuple(pArgs, "")) 1600 1744 { 1601 1745 return NULL; 1602 1746 } 1603 1747 pjsua_config_default(&cfg); 1748 obj = (config_Object *) config_new(&config_Type, NULL, NULL); 1604 1749 obj->max_calls = cfg.max_calls; 1605 1750 obj->thread_cnt = cfg.thread_cnt; 1606 Py_INCREF(Py_None); 1607 return Py_None; 1751 return (PyObject *)obj; 1608 1752 } 1609 1753 … … 1611 1755 /* 1612 1756 * py_pjsua_media_config_default 1757 * !modified @ 051206 1613 1758 */ 1614 1759 static PyObject * py_pjsua_media_config_default(PyObject *pSelf, … … 1617 1762 media_config_Object *obj; 1618 1763 pjsua_media_config cfg; 1619 if (!PyArg_ParseTuple(pArgs, " O", &obj))1764 if (!PyArg_ParseTuple(pArgs, "")) 1620 1765 { 1621 1766 return NULL; 1622 1767 } 1623 1768 pjsua_media_config_default(&cfg); 1769 obj = (media_config_Object *)PyType_GenericNew(&media_config_Type, NULL, NULL); 1624 1770 obj->clock_rate = cfg.clock_rate; 1625 1771 obj->ec_options = cfg.ec_options; … … 1634 1780 obj->thread_cnt = cfg.thread_cnt; 1635 1781 obj->tx_drop_pct = cfg.tx_drop_pct; 1636 Py_INCREF(Py_None); 1637 return Py_None; 1782 return (PyObject *)obj; 1638 1783 } 1639 1784 … … 1641 1786 /* 1642 1787 * py_pjsua_msg_data_init 1788 * !modified @ 051206 1643 1789 */ 1644 1790 static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs) … … 1646 1792 msg_data_Object *obj; 1647 1793 pjsua_msg_data msg; 1648 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 1794 1795 if (!PyArg_ParseTuple(pArgs, "")) 1649 1796 { 1650 1797 return NULL; 1651 1798 } 1652 1799 pjsua_msg_data_init(&msg); 1800 obj = (msg_data_Object *)msg_data_new(&msg_data_Type, NULL, NULL); 1653 1801 Py_XDECREF(obj->content_type); 1654 1802 obj->content_type = PyString_FromStringAndSize( … … 1659 1807 msg.msg_body.ptr, msg.msg_body.slen 1660 1808 ); 1661 obj->hdr_list = msg.hdr_list; 1662 Py_INCREF(Py_None); 1663 return Py_None; 1664 } 1665 1666 1667 /* 1668 * py_pjsua_logging_config_dup 1669 */ 1670 static PyObject *py_pjsua_logging_config_dup(PyObject *pSelf, PyObject *pArgs) 1671 { 1672 pj_pool_Object *pool; 1673 logging_config_Object *src; 1674 logging_config_Object *dest; 1675 pj_str_t strdest; 1676 pj_str_t strsrc; 1677 int len; 1678 1679 if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) 1680 { 1681 return NULL; 1682 } 1683 pj_memcpy(dest, src, sizeof(*src)); 1684 len = strlen(PyString_AsString(src->log_filename)); 1685 strsrc.ptr = PyString_AsString(src->log_filename); 1686 strsrc.slen = len; 1687 pj_strdup_with_null(pool->pool, &strdest, &strsrc); 1688 Py_XDECREF(dest->log_filename); 1689 dest->log_filename = PyString_FromStringAndSize(strdest.ptr, strdest.slen); 1690 Py_INCREF(Py_None); 1691 return Py_None; 1692 } 1693 1694 1695 /* 1696 * py_pjsua_config_dup 1697 */ 1698 static PyObject *py_pjsua_config_dup(PyObject *pSelf, PyObject *pArgs) 1699 { 1700 pj_pool_Object *pool; 1701 config_Object *src; 1702 config_Object *dest; 1703 pj_str_t strdest; 1704 pj_str_t strsrc; 1705 int len; 1706 unsigned i; 1707 1708 if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) 1709 { 1710 return NULL; 1711 } 1712 pj_memcpy(dest, src, sizeof(*src)); 1713 1714 for (i=0; i<src->outbound_proxy_cnt; ++i) 1715 { 1716 pj_strdup_with_null( 1717 pool->pool, &dest->outbound_proxy[i], &src->outbound_proxy[i] 1718 ); 1719 } 1720 1721 for (i=0; i<src->cred_count; ++i) 1722 { 1723 pjsip_cred_dup(pool->pool, &dest->cred_info[i], &src->cred_info[i]); 1724 } 1725 len = strlen(PyString_AsString(src->user_agent)); 1726 strsrc.ptr = PyString_AsString(src->user_agent); 1727 strsrc.slen = len; 1728 pj_strdup_with_null(pool->pool, &strdest, &strsrc); 1729 Py_XDECREF(dest->user_agent); 1730 dest->user_agent = PyString_FromStringAndSize(strdest.ptr, strdest.slen); 1731 Py_INCREF(Py_None); 1732 return Py_None; 1733 } 1734 1735 1736 /* 1737 * py_pjsip_cred_dup 1738 */ 1739 static PyObject *py_pjsip_cred_dup(PyObject *pSelf, PyObject *pArgs) 1740 { 1741 pj_pool_Object *pool; 1742 pjsip_cred_info_Object *src; 1743 pjsip_cred_info_Object *dest; 1744 pjsip_cred_info s; 1745 pjsip_cred_info d; 1746 if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) 1747 { 1748 return NULL; 1749 } 1750 s.data.ptr = PyString_AsString(src->data); 1751 s.data.slen = strlen(PyString_AsString(src->data)); 1752 s.realm.ptr = PyString_AsString(src->realm); 1753 s.realm.slen = strlen(PyString_AsString(src->realm)); 1754 s.scheme.ptr = PyString_AsString(src->scheme); 1755 s.scheme.slen = strlen(PyString_AsString(src->scheme)); 1756 s.username.ptr = PyString_AsString(src->username); 1757 s.username.slen = strlen(PyString_AsString(src->username)); 1758 s.data_type = src->data_type; 1759 d.data.ptr = PyString_AsString(dest->data); 1760 d.data.slen = strlen(PyString_AsString(dest->data)); 1761 d.realm.ptr = PyString_AsString(dest->realm); 1762 d.realm.slen = strlen(PyString_AsString(dest->realm)); 1763 d.scheme.ptr = PyString_AsString(dest->scheme); 1764 d.scheme.slen = strlen(PyString_AsString(dest->scheme)); 1765 d.username.ptr = PyString_AsString(dest->username); 1766 d.username.slen = strlen(PyString_AsString(dest->username)); 1767 d.data_type = dest->data_type; 1768 pjsip_cred_dup(pool->pool, &d, &s); 1769 Py_XDECREF(src->data); 1770 src->data = PyString_FromStringAndSize(s.data.ptr, s.data.slen); 1771 Py_XDECREF(src->realm); 1772 src->realm = PyString_FromStringAndSize(s.realm.ptr, s.realm.slen); 1773 Py_XDECREF(src->scheme); 1774 src->scheme = PyString_FromStringAndSize(s.scheme.ptr, s.scheme.slen); 1775 Py_XDECREF(src->username); 1776 src->username = 1777 PyString_FromStringAndSize(s.username.ptr, s.username.slen); 1778 Py_INCREF(Py_None); 1779 src->data_type = s.data_type; 1780 Py_XDECREF(dest->data); 1781 dest->data = PyString_FromStringAndSize(d.data.ptr, d.data.slen); 1782 Py_XDECREF(dest->realm); 1783 dest->realm = PyString_FromStringAndSize(d.realm.ptr, d.realm.slen); 1784 Py_XDECREF(dest->scheme); 1785 dest->scheme = PyString_FromStringAndSize(d.scheme.ptr, d.scheme.slen); 1786 Py_XDECREF(dest->username); 1787 dest->username = 1788 PyString_FromStringAndSize(d.username.ptr, d.username.slen); 1789 Py_INCREF(Py_None); 1790 src->data_type = s.data_type; 1791 return Py_None; 1809 1810 translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list, obj->hdr_list); 1811 1812 return (PyObject *)obj; 1792 1813 } 1793 1814 … … 1922 1943 return NULL; 1923 1944 } 1945 1924 1946 pjsua_perror(sender, title, status); 1925 1947 Py_INCREF(Py_None); … … 1939 1961 } 1940 1962 status = pjsua_create(); 1941 printf("status %d\n",status);1963 //printf("status %d\n",status); 1942 1964 return Py_BuildValue("i",status); 1943 1965 } … … 2037 2059 } 2038 2060 status = pjsua_start(); 2039 printf("status %d\n",status);2061 //printf("status %d\n",status); 2040 2062 return Py_BuildValue("i",status); 2041 2063 } … … 2053 2075 } 2054 2076 status = pjsua_destroy(); 2055 printf("status %d\n",status);2077 //printf("status %d\n",status); 2056 2078 return Py_BuildValue("i",status); 2057 2079 } … … 2070 2092 } 2071 2093 ret = pjsua_handle_events(msec); 2072 printf("return %d\n",ret);2094 //printf("return %d\n",ret); 2073 2095 return Py_BuildValue("i",ret); 2074 2096 } … … 2087 2109 } 2088 2110 status = pjsua_verify_sip_url(url); 2089 printf("status %d\n",status);2111 //printf("status %d\n",status); 2090 2112 return Py_BuildValue("i",status); 2091 2113 } 2092 2114 2093 2115 2094 2095 2096 2097 2098 /* 2099 * error messages 2100 */ 2101 2116 /* 2117 * function doc 2118 */ 2119 2120 static char pjsua_thread_register_doc[] = 2121 "int py_pjsua.thread_register(string name, int[] desc)"; 2102 2122 static char pjsua_perror_doc[] = 2103 2123 "void py_pjsua.perror (string sender, string title, int status) " … … 2182 2202 2183 2203 static char pjsua_logging_config_default_doc[] = 2184 " void py_pjsua.logging_config_default (py_pjsua.Logging_Config cfg) "2204 "py_pjsua.Logging_Config py_pjsua.logging_config_default () " 2185 2205 "Use this function to initialize logging config."; 2186 2206 2187 2207 static char pjsua_config_default_doc[] = 2188 "void py_pjsua.config_default (py_pjsua.Config cfg). Use this function to " 2189 "initialize pjsua config. Parameters: " 2190 "cfg: pjsua config to be initialized."; 2208 "py_pjsua.Config py_pjsua.config_default (). Use this function to " 2209 "initialize pjsua config. "; 2191 2210 2192 2211 static char pjsua_media_config_default_doc[] = 2212 "py_pjsua.Media_Config py_pjsua.media_config_default (). " 2193 2213 "Use this function to initialize media config."; 2194 2214 2195 static char pjsua_logging_config_dup_doc[] =2196 "void py_pjsua.logging_config_dup (py_pjsua.PJ_Pool pool, "2197 "py_pjsua.Logging_Config dst, py_pjsua.Logging_Config src) "2198 "Use this function to duplicate logging config. Parameters: "2199 "pool: Pool to use; "2200 "dst: Destination config; "2201 "src: Source config.";2202 2203 static char pjsua_config_dup_doc[] =2204 "void py_pjsua.config_dup (py_pjsua.PJ_Pool pool, py_pjsua.Config dst, "2205 "py_pjsua.Config src) "2206 "Duplicate pjsua_config. ";2207 2208 static char pjsip_cred_dup_doc[] =2209 "void py_pjsua.pjsip_cred_dup (py_pjsua.PJ_Pool pool, "2210 "py_pjsua.PJSIP_Cred_Info dst, "2211 "py_pjsua.PJSIP_Cred_Info src) "2212 "Duplicate credential.";2213 2214 2215 static char pjsua_msg_data_init_doc[] = 2215 " void py_pjsua.msg_data_init (py_pjsua.Msg_Data msg_data) "2216 "Initialize message data Parameters: "2217 "msg_data: Message data to be initialized.";2216 "py_pjsua.Msg_Data void py_pjsua.msg_data_init () " 2217 "Initialize message data "; 2218 2218 2219 2219 2220 /* END OF LIB BASE */ … … 2229 2230 PyObject_HEAD 2230 2231 /* Type-specific fields go here. */ 2231 2232 PyObject * stun_srv1; 2232 2233 unsigned stun_port1; 2233 2234 PyObject * stun_srv2; … … 2283 2284 { 2284 2285 { 2285 2286 2287 }, 2288 { 2289 2290 2291 2286 "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0, 2287 "The first STUN server IP address or hostname." 2288 }, 2289 { 2290 "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0, 2291 "Port number of the second STUN server. " 2292 "If zero, default STUN port will be used." 2292 2293 }, 2293 2294 { 2294 2295 2296 2297 }, 2298 { 2299 2300 2301 2302 2303 2295 "stun_srv1", T_OBJECT_EX, 2296 offsetof(stun_config_Object, stun_srv1), 0, 2297 "The first STUN server IP address or hostname" 2298 }, 2299 { 2300 "stun_srv2", T_OBJECT_EX, 2301 offsetof(stun_config_Object, stun_srv2), 0, 2302 "Optional second STUN server IP address or hostname, for which the " 2303 "result of the mapping request will be compared to. If the value " 2304 "is empty, only one STUN server will be used" 2304 2305 }, 2305 2306 {NULL} /* Sentinel */ … … 2365 2366 PyObject_HEAD 2366 2367 /* Type-specific fields go here. */ 2367 2368 2369 2370 2371 2368 unsigned port; 2369 PyObject * public_addr; 2370 PyObject * bound_addr; 2371 int use_stun; 2372 stun_config_Object * stun_config; 2372 2373 } transport_config_Object; 2373 2374 … … 2379 2380 static void transport_config_dealloc(transport_config_Object* self) 2380 2381 { 2381 2382 2382 Py_XDECREF(self->public_addr); 2383 Py_XDECREF(self->bound_addr); 2383 2384 Py_XDECREF(self->stun_config); 2384 2385 self->ob_type->tp_free((PyObject*)self); … … 2411 2412 } 2412 2413 self->stun_config = 2413 2414 (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL); 2414 2415 if (self->stun_config == NULL) 2415 2416 { … … 2430 2431 { 2431 2432 { 2432 2433 2434 2435 2436 2437 }, 2438 { 2439 2440 2441 2442 2443 2444 2445 2433 "port", T_INT, offsetof(transport_config_Object, port), 0, 2434 "UDP port number to bind locally. This setting MUST be specified " 2435 "even when default port is desired. If the value is zero, the " 2436 "transport will be bound to any available port, and application " 2437 "can query the port by querying the transport info." 2438 }, 2439 { 2440 "public_addr", T_OBJECT_EX, 2441 offsetof(transport_config_Object, public_addr), 0, 2442 "Optional address to advertise as the address of this transport. " 2443 "Application can specify any address or hostname for this field, " 2444 "for example it can point to one of the interface address in the " 2445 "system, or it can point to the public address of a NAT router " 2446 "where port mappings have been configured for the application." 2446 2447 }, 2447 2448 2449 2450 2451 2452 2453 2454 2448 { 2449 "bound_addr", T_OBJECT_EX, 2450 offsetof(transport_config_Object, bound_addr), 0, 2451 "Optional address where the socket should be bound to. This option " 2452 "SHOULD only be used to selectively bind the socket to particular " 2453 "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the " 2454 "published address of a transport (the public_addr field should be " 2455 "used for that purpose)." 2455 2456 }, 2456 2457 { 2457 2458 2459 2460 }, 2461 { 2462 2463 2464 2458 "use_stun", T_INT, 2459 offsetof(transport_config_Object, use_stun), 0, 2460 "Flag to indicate whether STUN should be used." 2461 }, 2462 { 2463 "stun_config", T_OBJECT_EX, 2464 offsetof(transport_config_Object, stun_config), 0, 2465 "STUN configuration, must be specified when STUN is used." 2465 2466 }, 2466 2467 {NULL} /* Sentinel */ … … 2594 2595 #endif 2595 2596 { 2596 2597 2598 2597 "sa_data", T_OBJECT_EX, 2598 offsetof(sockaddr_Object, sa_data), 0, 2599 "Address data" 2599 2600 }, 2600 2601 {NULL} /* Sentinel */ … … 2708 2709 }, 2709 2710 { 2710 2711 2712 2711 "host", T_OBJECT_EX, 2712 offsetof(host_port_Object, host), 0, 2713 "Host part or IP address." 2713 2714 }, 2714 2715 {NULL} /* Sentinel */ … … 2762 2763 }; 2763 2764 2764 /* 2765 * transport_id_Object 2766 * C/Python wrapper for transport_id object 2765 2766 2767 2768 /* 2769 * transport_info_Object 2770 * Transport info 2767 2771 */ 2768 2772 typedef struct … … 2770 2774 PyObject_HEAD 2771 2775 /* Type-specific fields go here. */ 2772 int transport_id; 2773 } transport_id_Object; 2774 2775 2776 /* 2777 * transport_id_members 2778 * declares attributes accessible from 2779 * both C and Python for transport_id object 2780 */ 2781 static PyMemberDef transport_id_members[] = 2782 { 2783 { 2784 "transport_id", T_INT, offsetof(transport_id_Object, transport_id), 0, 2785 "SIP transport identification" 2786 }, 2787 {NULL} /* Sentinel */ 2788 }; 2789 2790 2791 /* 2792 * transport_id_Type 2793 */ 2794 static PyTypeObject transport_id_Type = 2795 { 2796 PyObject_HEAD_INIT(NULL) 2797 0, /*ob_size*/ 2798 "py_pjsua.Transport_ID", /*tp_name*/ 2799 sizeof(transport_id_Object), /*tp_basicsize*/ 2800 0, /*tp_itemsize*/ 2801 0, /*tp_dealloc*/ 2802 0, /*tp_print*/ 2803 0, /*tp_getattr*/ 2804 0, /*tp_setattr*/ 2805 0, /*tp_compare*/ 2806 0, /*tp_repr*/ 2807 0, /*tp_as_number*/ 2808 0, /*tp_as_sequence*/ 2809 0, /*tp_as_mapping*/ 2810 0, /*tp_hash */ 2811 0, /*tp_call*/ 2812 0, /*tp_str*/ 2813 0, /*tp_getattro*/ 2814 0, /*tp_setattro*/ 2815 0, /*tp_as_buffer*/ 2816 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2817 "Transport ID objects", /*tp_doc*/ 2818 0, /*tp_traverse*/ 2819 0, /*tp_clear*/ 2820 0, /*tp_richcompare*/ 2821 0, /* tp_weaklistoffset */ 2822 0, /* tp_iter */ 2823 0, /* tp_iternext */ 2824 0, /* tp_methods */ 2825 transport_id_members, /* tp_members */ 2826 2827 }; 2828 2829 /* 2830 * integer_Object 2831 * C/Python wrapper for integer object 2832 */ 2833 typedef struct 2834 { 2835 PyObject_HEAD 2836 /* Type-specific fields go here. */ 2837 int integer; 2838 } integer_Object; 2839 2840 2841 /* 2842 * integer_members 2843 * declares attributes accessible from both C and Python for integer object 2844 */ 2845 static PyMemberDef integer_members[] = 2846 { 2847 { 2848 "integer", T_INT, offsetof(integer_Object, integer), 0, 2849 "integer value" 2850 }, 2851 {NULL} /* Sentinel */ 2852 }; 2853 2854 2855 /* 2856 * integer_Type 2857 */ 2858 static PyTypeObject integer_Type = 2859 { 2860 PyObject_HEAD_INIT(NULL) 2861 0, /*ob_size*/ 2862 "py_pjsua.Integer", /*tp_name*/ 2863 sizeof(integer_Object), /*tp_basicsize*/ 2864 0, /*tp_itemsize*/ 2865 0, /*tp_dealloc*/ 2866 0, /*tp_print*/ 2867 0, /*tp_getattr*/ 2868 0, /*tp_setattr*/ 2869 0, /*tp_compare*/ 2870 0, /*tp_repr*/ 2871 0, /*tp_as_number*/ 2872 0, /*tp_as_sequence*/ 2873 0, /*tp_as_mapping*/ 2874 0, /*tp_hash */ 2875 0, /*tp_call*/ 2876 0, /*tp_str*/ 2877 0, /*tp_getattro*/ 2878 0, /*tp_setattro*/ 2879 0, /*tp_as_buffer*/ 2880 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2881 "Integer objects", /*tp_doc*/ 2882 0, /*tp_traverse*/ 2883 0, /*tp_clear*/ 2884 0, /*tp_richcompare*/ 2885 0, /* tp_weaklistoffset */ 2886 0, /* tp_iter */ 2887 0, /* tp_iternext */ 2888 0, /* tp_methods */ 2889 integer_members, /* tp_members */ 2890 2891 }; 2892 2893 2894 /* 2895 * transport_info_Object 2896 * Transport info 2897 */ 2898 typedef struct 2899 { 2900 PyObject_HEAD 2901 /* Type-specific fields go here. */ 2902 int id; 2903 int type; 2904 PyObject * type_name; 2905 PyObject * info; 2906 unsigned flag; 2907 unsigned addr_len; 2908 sockaddr_Object * local_addr; 2909 host_port_Object * local_name; 2910 unsigned usage_count; 2776 int id; 2777 int type; 2778 PyObject * type_name; 2779 PyObject * info; 2780 unsigned flag; 2781 unsigned addr_len; 2782 sockaddr_Object * local_addr; 2783 host_port_Object * local_name; 2784 unsigned usage_count; 2911 2785 } transport_info_Object; 2912 2786 … … 2919 2793 { 2920 2794 Py_XDECREF(self->type_name); 2921 2922 2923 2795 Py_XDECREF(self->info); 2796 Py_XDECREF(self->local_addr); 2797 Py_XDECREF(self->local_name); 2924 2798 self->ob_type->tp_free((PyObject*)self); 2925 2799 } … … 2938 2812 if (self != NULL) 2939 2813 { 2940 2814 self->type_name = PyString_FromString(""); 2941 2815 if (self->type_name == NULL) 2942 2816 { … … 2944 2818 return NULL; 2945 2819 } 2946 2820 self->info = PyString_FromString(""); 2947 2821 if (self->info == NULL) 2948 2822 { … … 2951 2825 } 2952 2826 self->local_addr = 2953 2827 (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL); 2954 2828 if (self->local_addr == NULL) 2955 2829 { … … 2958 2832 } 2959 2833 self->local_name = 2960 2834 (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL); 2961 2835 if (self->local_name == NULL) 2962 2836 { … … 2975 2849 static PyMemberDef transport_info_members[] = 2976 2850 { 2977 2978 2979 2980 }, 2981 2982 2983 2984 }, 2985 2986 2987 2988 2989 }, 2990 2991 2992 2993 2994 }, 2995 2996 2997 2998 }, 2999 3000 3001 3002 }, 3003 3004 3005 3006 3007 }, 3008 3009 3010 3011 3012 }, 3013 3014 3015 2851 { 2852 "id", T_INT, offsetof(transport_info_Object, id), 0, 2853 "PJSUA transport identification." 2854 }, 2855 { 2856 "type", T_INT, offsetof(transport_info_Object, id), 0, 2857 "Transport type." 2858 }, 2859 { 2860 "type_name", T_OBJECT_EX, 2861 offsetof(transport_info_Object, type_name), 0, 2862 "Transport type name." 2863 }, 2864 { 2865 "info", T_OBJECT_EX, 2866 offsetof(transport_info_Object, info), 0, 2867 "Transport string info/description." 2868 }, 2869 { 2870 "flag", T_INT, offsetof(transport_info_Object, flag), 0, 2871 "Transport flag (see ##pjsip_transport_flags_e)." 2872 }, 2873 { 2874 "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0, 2875 "Local address length." 2876 }, 2877 { 2878 "local_addr", T_OBJECT_EX, 2879 offsetof(transport_info_Object, local_addr), 0, 2880 "Local/bound address." 2881 }, 2882 { 2883 "local_name", T_OBJECT_EX, 2884 offsetof(transport_info_Object, local_name), 0, 2885 "Published address (or transport address name)." 2886 }, 2887 { 2888 "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0, 2889 "Current number of objects currently referencing this transport." 3016 2890 }, 3017 2891 {NULL} /* Sentinel */ … … 3112 2986 /* 3113 2987 * py_pjsua_stun_config_default 2988 * !modified @ 051206 3114 2989 */ 3115 2990 static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs) … … 3118 2993 pjsua_stun_config cfg; 3119 2994 2995 if (!PyArg_ParseTuple(pArgs, "")) 2996 { 2997 return NULL; 2998 } 2999 3000 pjsua_stun_config_default(&cfg); 3001 obj = (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); 3002 obj->stun_port1 = cfg.stun_port1; 3003 obj->stun_port2 = cfg.stun_port2; 3004 Py_XDECREF(obj->stun_srv1); 3005 obj->stun_srv1 = 3006 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen); 3007 Py_XDECREF(obj->stun_srv2); 3008 obj->stun_srv2 = 3009 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen); 3010 return (PyObject *)obj; 3011 } 3012 3013 /* 3014 * py_pjsua_transport_config_default 3015 * !modified @ 051206 3016 */ 3017 static PyObject *py_pjsua_transport_config_default 3018 (PyObject *pSelf, PyObject *pArgs) 3019 { 3020 transport_config_Object *obj; 3021 pjsua_transport_config cfg; 3022 3023 if (!PyArg_ParseTuple(pArgs, "")) 3024 { 3025 return NULL; 3026 } 3027 pjsua_transport_config_default(&cfg); 3028 obj = (transport_config_Object *)transport_config_new 3029 (&transport_config_Type,NULL,NULL); 3030 obj->public_addr = 3031 PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen); 3032 obj->bound_addr = 3033 PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen); 3034 obj->port = cfg.port; 3035 obj->use_stun = cfg.use_stun; 3036 Py_XDECREF(obj->stun_config); 3037 obj->stun_config = 3038 (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); 3039 obj->stun_config->stun_port1 = cfg.stun_config.stun_port1; 3040 obj->stun_config->stun_port2 = cfg.stun_config.stun_port2; 3041 Py_XDECREF(obj->stun_config->stun_srv1); 3042 obj->stun_config->stun_srv1 = 3043 PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr, 3044 cfg.stun_config.stun_srv1.slen); 3045 Py_XDECREF(obj->stun_config->stun_srv2); 3046 obj->stun_config->stun_srv2 = 3047 PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr, 3048 cfg.stun_config.stun_srv2.slen); 3049 return (PyObject *)obj; 3050 } 3051 3052 /* 3053 * py_pjsua_normalize_stun_config 3054 */ 3055 static PyObject *py_pjsua_normalize_stun_config 3056 (PyObject *pSelf, PyObject *pArgs) 3057 { 3058 stun_config_Object *obj; 3059 pjsua_stun_config *cfg; 3060 3120 3061 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 3121 3062 { 3122 3063 return NULL; 3123 3064 } 3124 pjsua_stun_config_default(&cfg); 3125 obj->stun_port1 = cfg.stun_port1; 3126 obj->stun_port2 = cfg.stun_port2; 3127 Py_XDECREF(obj->stun_srv1); 3065 cfg = (pjsua_stun_config *)malloc(sizeof(pjsua_stun_config)); 3066 cfg->stun_port1 = obj->stun_port1; 3067 cfg->stun_port2 = obj->stun_port2; 3068 cfg->stun_srv1.ptr = PyString_AsString(obj->stun_srv1); 3069 cfg->stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1)); 3070 cfg->stun_srv2.ptr = PyString_AsString(obj->stun_srv2); 3071 cfg->stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2)); 3072 pjsua_normalize_stun_config(cfg); 3073 obj->stun_port1 = cfg->stun_port1; 3074 obj->stun_port2 = cfg->stun_port2; 3075 Py_XDECREF(obj->stun_srv1); 3128 3076 obj->stun_srv1 = 3129 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen); 3130 Py_XDECREF(obj->stun_srv2); 3131 obj->stun_srv2 = 3132 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen); 3077 PyString_FromStringAndSize(cfg->stun_srv1.ptr, cfg->stun_srv1.slen); 3078 Py_XDECREF(obj->stun_srv2); 3079 obj->stun_srv2 = 3080 PyString_FromStringAndSize(cfg->stun_srv2.ptr, cfg->stun_srv2.slen); 3081 free(cfg); 3133 3082 Py_INCREF(Py_None); 3134 3083 return Py_None; … … 3136 3085 3137 3086 /* 3138 * py_pjsua_transport_config_default 3139 */ 3140 static PyObject *py_pjsua_transport_config_default 3141 (PyObject *pSelf, PyObject *pArgs) 3142 { 3087 * py_pjsua_transport_create 3088 * !modified @ 051206 3089 */ 3090 static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) 3091 { 3092 pj_status_t status; 3093 int type; 3094 3143 3095 transport_config_Object *obj; 3144 3096 pjsua_transport_config cfg; 3145 3097 pjsua_transport_id id; 3098 if (!PyArg_ParseTuple(pArgs, "iO", &type, &obj)) 3099 { 3100 return NULL; 3101 } 3102 cfg.public_addr.ptr = PyString_AsString(obj->public_addr); 3103 cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr)); 3104 cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr); 3105 cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr)); 3106 cfg.port = obj->port; 3107 cfg.use_stun = obj->use_stun; 3108 cfg.stun_config.stun_port1 = obj->stun_config->stun_port1; 3109 cfg.stun_config.stun_port2 = obj->stun_config->stun_port2; 3110 cfg.stun_config.stun_srv1.ptr = 3111 PyString_AsString(obj->stun_config->stun_srv1); 3112 cfg.stun_config.stun_srv1.slen = 3113 strlen(PyString_AsString(obj->stun_config->stun_srv1)); 3114 cfg.stun_config.stun_srv2.ptr = 3115 PyString_AsString(obj->stun_config->stun_srv2); 3116 cfg.stun_config.stun_srv2.slen = 3117 strlen(PyString_AsString(obj->stun_config->stun_srv2)); 3118 status = pjsua_transport_create(type, &cfg, &id); 3119 3120 3121 return Py_BuildValue("ii",status,id); 3122 } 3123 3124 /* 3125 * py_pjsua_transport_register 3126 * !modified @ 051206 3127 */ 3128 static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs) 3129 { 3130 pj_status_t status; 3131 pjsip_transport_Object *obj; 3132 pjsua_transport_id id; 3146 3133 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 3147 3134 { 3148 3135 return NULL; 3149 3136 } 3150 pjsua_transport_config_default(&cfg); 3151 obj->public_addr = 3152 PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen); 3153 obj->bound_addr = 3154 PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen); 3155 obj->port = cfg.port; 3156 obj->use_stun = cfg.use_stun; 3157 Py_XDECREF(obj->stun_config); 3158 obj->stun_config = 3159 (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); 3160 obj->stun_config->stun_port1 = cfg.stun_config.stun_port1; 3161 obj->stun_config->stun_port2 = cfg.stun_config.stun_port2; 3162 Py_XDECREF(obj->stun_config->stun_srv1); 3163 obj->stun_config->stun_srv1 = 3164 PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr, 3165 cfg.stun_config.stun_srv1.slen); 3166 Py_XDECREF(obj->stun_config->stun_srv2); 3167 obj->stun_config->stun_srv2 = 3168 PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr, 3169 cfg.stun_config.stun_srv2.slen); 3170 Py_INCREF(Py_None); 3171 return Py_None; 3172 } 3173 3174 /* 3175 * py_pjsua_normalize_stun_config 3176 */ 3177 static PyObject *py_pjsua_normalize_stun_config 3178 (PyObject *pSelf, PyObject *pArgs) 3179 { 3180 stun_config_Object *obj; 3181 pjsua_stun_config *cfg; 3182 3183 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 3184 { 3185 return NULL; 3186 } 3187 cfg = (pjsua_stun_config *)malloc(sizeof(pjsua_stun_config)); 3188 cfg->stun_port1 = obj->stun_port1; 3189 cfg->stun_port2 = obj->stun_port2; 3190 cfg->stun_srv1.ptr = PyString_AsString(obj->stun_srv1); 3191 cfg->stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1)); 3192 cfg->stun_srv2.ptr = PyString_AsString(obj->stun_srv2); 3193 cfg->stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2)); 3194 pjsua_normalize_stun_config(cfg); 3195 obj->stun_port1 = cfg->stun_port1; 3196 obj->stun_port2 = cfg->stun_port2; 3197 Py_XDECREF(obj->stun_srv1); 3198 obj->stun_srv1 = 3199 PyString_FromStringAndSize(cfg->stun_srv1.ptr, cfg->stun_srv1.slen); 3200 Py_XDECREF(obj->stun_srv2); 3201 obj->stun_srv2 = 3202 PyString_FromStringAndSize(cfg->stun_srv2.ptr, cfg->stun_srv2.slen); 3203 free(cfg); 3204 Py_INCREF(Py_None); 3205 return Py_None; 3206 } 3207 3208 /* 3209 * py_pjsua_transport_config_dup 3210 */ 3211 static PyObject *py_pjsua_transport_config_dup 3212 (PyObject *pSelf, PyObject *pArgs) 3213 { 3214 pj_pool_Object *pool; 3215 transport_config_Object *src; 3216 transport_config_Object *dest; 3217 pj_pool_t *p; 3218 pjsua_transport_config s; 3219 pjsua_transport_config d; 3220 3221 if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) 3222 { 3223 return NULL; 3224 } 3225 p = pool->pool; 3226 s.public_addr.ptr = PyString_AsString(src->public_addr); 3227 s.public_addr.slen = strlen(PyString_AsString(src->public_addr)); 3228 s.bound_addr.ptr = PyString_AsString(src->bound_addr); 3229 s.bound_addr.slen = strlen(PyString_AsString(src->bound_addr)); 3230 s.port = src->port; 3231 s.use_stun = src->use_stun; 3232 s.stun_config.stun_port1 = src->stun_config->stun_port1; 3233 s.stun_config.stun_port2 = src->stun_config->stun_port2; 3234 s.stun_config.stun_srv1.ptr = 3235 PyString_AsString(src->stun_config->stun_srv1); 3236 s.stun_config.stun_srv1.slen = 3237 strlen(PyString_AsString(src->stun_config->stun_srv1)); 3238 s.stun_config.stun_srv2.ptr = 3239 PyString_AsString(src->stun_config->stun_srv2); 3240 s.stun_config.stun_srv2.slen = 3241 strlen(PyString_AsString(src->stun_config->stun_srv2)); 3242 d.public_addr.ptr = PyString_AsString(dest->public_addr); 3243 d.public_addr.slen = strlen(PyString_AsString(dest->public_addr)); 3244 d.bound_addr.ptr = PyString_AsString(dest->bound_addr); 3245 d.bound_addr.slen = strlen(PyString_AsString(dest->bound_addr)); 3246 d.port = dest->port; 3247 d.use_stun = dest->use_stun; 3248 d.stun_config.stun_port1 = dest->stun_config->stun_port1; 3249 d.stun_config.stun_port2 = dest->stun_config->stun_port2; 3250 d.stun_config.stun_srv1.ptr = 3251 PyString_AsString(dest->stun_config->stun_srv1); 3252 d.stun_config.stun_srv1.slen = 3253 strlen(PyString_AsString(dest->stun_config->stun_srv1)); 3254 d.stun_config.stun_srv2.ptr = 3255 PyString_AsString(dest->stun_config->stun_srv2); 3256 d.stun_config.stun_srv2.slen = 3257 strlen(PyString_AsString(dest->stun_config->stun_srv2)); 3258 pjsua_transport_config_dup(p, &d, &s); 3259 src->public_addr = 3260 PyString_FromStringAndSize(s.public_addr.ptr, s.public_addr.slen); 3261 src->bound_addr = 3262 PyString_FromStringAndSize(s.bound_addr.ptr, s.bound_addr.slen); 3263 src->port = s.port; 3264 src->use_stun = s.use_stun; 3265 src->stun_config->stun_port1 = s.stun_config.stun_port1; 3266 src->stun_config->stun_port2 = s.stun_config.stun_port2; 3267 Py_XDECREF(src->stun_config->stun_srv1); 3268 src->stun_config->stun_srv1 = 3269 PyString_FromStringAndSize(s.stun_config.stun_srv1.ptr, 3270 s.stun_config.stun_srv1.slen); 3271 Py_XDECREF(src->stun_config->stun_srv2); 3272 src->stun_config->stun_srv2 = 3273 PyString_FromStringAndSize(s.stun_config.stun_srv2.ptr, 3274 s.stun_config.stun_srv2.slen); 3275 dest->public_addr = 3276 PyString_FromStringAndSize(d.public_addr.ptr, d.public_addr.slen); 3277 dest->bound_addr = 3278 PyString_FromStringAndSize(d.bound_addr.ptr, d.bound_addr.slen); 3279 dest->port = d.port; 3280 dest->use_stun = d.use_stun; 3281 dest->stun_config->stun_port1 = d.stun_config.stun_port1; 3282 dest->stun_config->stun_port2 = d.stun_config.stun_port2; 3283 Py_XDECREF(dest->stun_config->stun_srv1); 3284 dest->stun_config->stun_srv1 = 3285 PyString_FromStringAndSize(d.stun_config.stun_srv1.ptr, 3286 d.stun_config.stun_srv1.slen); 3287 Py_XDECREF(dest->stun_config->stun_srv2); 3288 dest->stun_config->stun_srv2 = 3289 PyString_FromStringAndSize(d.stun_config.stun_srv2.ptr, 3290 d.stun_config.stun_srv2.slen); 3291 Py_INCREF(Py_None); 3292 return Py_None; 3293 } 3294 3295 /* 3296 * py_pjsua_transport_create 3297 */ 3298 static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) 3137 3138 3139 status = pjsua_transport_register(obj->tp, &id); 3140 3141 return Py_BuildValue("ii",status, id); 3142 } 3143 3144 /* 3145 * py_pjsua_enum_transports 3146 */ 3147 static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) 3299 3148 { 3300 3149 pj_status_t status; 3301 int type; 3302 transport_id_Object *p_id; 3303 transport_config_Object *obj; 3304 pjsua_transport_config cfg; 3305 pjsua_transport_id id; 3306 if (!PyArg_ParseTuple(pArgs, "iOO", &type, &obj, &p_id)) 3307 { 3308 return NULL; 3309 } 3310 cfg.public_addr.ptr = PyString_AsString(obj->public_addr); 3311 cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr)); 3312 cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr); 3313 cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr)); 3314 cfg.port = obj->port; 3315 cfg.use_stun = obj->use_stun; 3316 cfg.stun_config.stun_port1 = obj->stun_config->stun_port1; 3317 cfg.stun_config.stun_port2 = obj->stun_config->stun_port2; 3318 cfg.stun_config.stun_srv1.ptr = 3319 PyString_AsString(obj->stun_config->stun_srv1); 3320 cfg.stun_config.stun_srv1.slen = 3321 strlen(PyString_AsString(obj->stun_config->stun_srv1)); 3322 cfg.stun_config.stun_srv2.ptr = 3323 PyString_AsString(obj->stun_config->stun_srv2); 3324 cfg.stun_config.stun_srv2.slen = 3325 strlen(PyString_AsString(obj->stun_config->stun_srv2)); 3326 status = pjsua_transport_create(type, &cfg, &id); 3327 p_id->transport_id = id; 3328 printf("status %d\n",status); 3329 return Py_BuildValue("i",status); 3330 } 3331 3332 /* 3333 * py_pjsua_transport_register 3334 */ 3335 static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs) 3336 { 3337 pj_status_t status; 3338 transport_id_Object *p_id; 3339 pjsip_transport_Object *obj; 3340 pjsua_transport_id id; 3341 if (!PyArg_ParseTuple(pArgs, "OO", &obj, &p_id)) 3342 { 3343 return NULL; 3344 } 3345 3346 id = p_id->transport_id; 3347 status = pjsua_transport_register(obj->tp, &id); 3348 p_id->transport_id = id; 3349 return Py_BuildValue("i",status); 3350 } 3351 3352 /* 3353 * py_pjsua_enum_transports 3354 */ 3355 static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) 3150 PyObject *list; 3151 3152 pjsua_transport_id *id; 3153 int c, i; 3154 if (!PyArg_ParseTuple(pArgs, "i", &c)) 3155 { 3156 return NULL; 3157 } 3158 3159 id = (pjsua_transport_id *)malloc(c * sizeof(pjsua_transport_id)); 3160 status = pjsua_enum_transports(id, &c); 3161 3162 list = PyList_New(c); 3163 for (i = 0; i < c; i++) 3164 { 3165 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 3166 if (ret == -1) 3167 { 3168 return NULL; 3169 } 3170 } 3171 3172 free(id); 3173 return Py_BuildValue("O",list); 3174 } 3175 3176 /* 3177 * py_pjsua_transport_get_info 3178 * !modified @ 051206 3179 */ 3180 static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs) 3356 3181 { 3357 3182 pj_status_t status; 3358 PyObject *list; 3359 integer_Object *count; 3360 pjsua_transport_id *id; 3361 int c, i; 3362 if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) 3183 int id; 3184 transport_info_Object *obj; 3185 pjsua_transport_info info; 3186 3187 3188 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3363 3189 { 3364 3190 return NULL; 3365 3191 } 3366 c = count->integer; 3367 id = (pjsua_transport_id *)malloc(c * sizeof(pjsua_transport_id)); 3368 status = pjsua_enum_transports(id, &c); 3369 Py_XDECREF(list); 3370 list = PyList_New(c); 3371 for (i = 0; i < c; i++) { 3372 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 3373 if (ret == -1) { 3374 return NULL; 3375 } 3376 } 3377 count->integer = c; 3378 free(id); 3379 return Py_BuildValue("i",status); 3380 } 3381 3382 /* 3383 * py_pjsua_transport_get_info 3384 */ 3385 static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs) 3386 { 3387 pj_status_t status; 3388 int id; 3389 transport_info_Object *obj; 3390 pjsua_transport_info info; 3391 char * str; 3392 int len; 3393 int i; 3394 3395 if (!PyArg_ParseTuple(pArgs, "iO", &id, &obj)) 3396 { 3397 return NULL; 3398 } 3399 info.addr_len = obj->addr_len; 3400 info.flag = obj->flag; 3401 info.id = obj->id; 3402 info.info.ptr = PyString_AsString(obj->info); 3403 info.info.slen = strlen(PyString_AsString(obj->info)); 3404 str = PyString_AsString(obj->local_addr->sa_data); 3405 len = strlen(str); 3406 if (len > 14) { 3407 len = 14; 3408 } 3409 for (i = 0; i < len; i++) { 3410 info.local_addr.sa_data[i] = str[i]; 3411 } 3192 3193 status = pjsua_transport_get_info(id, &info); 3194 if (status == PJ_SUCCESS) { 3195 obj = (transport_info_Object *) transport_info_new 3196 (&transport_info_Type,NULL,NULL); 3197 obj->addr_len = info.addr_len; 3198 obj->flag = info.flag; 3199 obj->id = info.id; 3200 obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen); 3201 obj->local_addr->sa_data = 3202 PyString_FromStringAndSize(info.local_addr.sa_data, 14); 3412 3203 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 3413 info.local_addr.sa_zero_len = obj->local_addr->sa_zero_len;3414 info.local_addr.sa_family = obj->local_addr->sa_family;3204 obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len; 3205 obj->local_addr->sa_family = info.local_addr.sa_family; 3415 3206 #else 3416 info.local_addr.sa_family = obj->local_addr->sa_family;3207 obj->local_addr->sa_family = info.local_addr.sa_family; 3417 3208 #endif 3418 status = pjsua_transport_get_info(id, &info); 3419 obj->addr_len = info.addr_len; 3420 obj->flag = info.flag; 3421 obj->id = info.id; 3422 obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen); 3423 obj->local_addr->sa_data = 3424 PyString_FromStringAndSize(info.local_addr.sa_data, 14); 3425 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 3426 obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len; 3427 obj->local_addr->sa_family = info.local_addr.sa_family; 3428 #else 3429 obj->local_addr->sa_family = info.local_addr.sa_family; 3430 #endif 3431 return Py_BuildValue("i",status); 3209 return Py_BuildValue("O", obj); 3210 } else { 3211 Py_INCREF(Py_None); 3212 return Py_None; 3213 } 3432 3214 } 3433 3215 … … 3439 3221 { 3440 3222 pj_status_t status; 3441 3442 3223 int id; 3224 int enabled; 3443 3225 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) 3444 3226 { … … 3456 3238 { 3457 3239 pj_status_t status; 3458 3459 3240 int id; 3241 int force; 3460 3242 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) 3461 3243 { … … 3468 3250 3469 3251 static char pjsua_stun_config_default_doc[] = 3470 " void py_pjsua.stun_config_default (py_pjsua.STUN_Config cfg) "3252 "py_pjsua.STUN_Config py_pjsua.stun_config_default () " 3471 3253 "Call this function to initialize STUN config with default values."; 3472 3254 static char pjsua_transport_config_default_doc[] = 3473 "void py_pjsua.transport_config_default (py_pjsua.Transport_Config cfg) "3474 3255 "py_pjsua.Transport_Config py_pjsua.transport_config_default () " 3256 "Call this function to initialize UDP config with default values."; 3475 3257 static char pjsua_normalize_stun_config_doc[] = 3476 "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) " 3477 "Normalize STUN config. "; 3478 static char pjsua_transport_config_dup_doc[] = 3479 "void py_pjsua.transport_config_dup (py_pjsua.Pool pool, " 3480 "py_pjsua.Transport_Config dest, py_pjsua.Transport_Config dest) " 3481 "Duplicate transport config. "; 3258 "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) " 3259 "Normalize STUN config. "; 3482 3260 static char pjsua_transport_create_doc[] = 3483 "voidpy_pjsua.transport_create (int type, "3484 "py_pjsua.Transport_Config cfg, py_pjsua.Transport_ID p_id) "3485 3261 "int, int py_pjsua.transport_create (int type, " 3262 "py_pjsua.Transport_Config cfg) " 3263 "Create SIP transport."; 3486 3264 static char pjsua_transport_register_doc[] = 3487 "voidpy_pjsua.transport_register "3488 "(py_pjsua.PJSIP_Transport tp, py_pjsua.Transport_ID p_id) "3489 3265 "int, int py_pjsua.transport_register " 3266 "(py_pjsua.PJSIP_Transport tp) " 3267 "Register transport that has been created by application."; 3490 3268 static char pjsua_enum_transports_doc[] = 3491 "void py_pjsua.enum_transports " 3492 "(py_pjsua.Transport_ID id[], py_pjsua.Integer count) " 3493 "Enumerate all transports currently created in the system."; 3269 "int[] py_pjsua.enum_transports (int count) " 3270 "Enumerate all transports currently created in the system."; 3494 3271 static char pjsua_transport_get_info_doc[] = 3495 3496 3497 3272 "void py_pjsua.transport_get_info " 3273 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) " 3274 "Get information about transports."; 3498 3275 static char pjsua_transport_set_enable_doc[] = 3499 3500 3501 3502 3503 3504 3505 3276 "void py_pjsua.transport_set_enable " 3277 "(py_pjsua.Transport_ID id, int enabled) " 3278 "Disable a transport or re-enable it. " 3279 "By default transport is always enabled after it is created. " 3280 "Disabling a transport does not necessarily close the socket, " 3281 "it will only discard incoming messages and prevent the transport " 3282 "from being used to send outgoing messages."; 3506 3283 static char pjsua_transport_close_doc[] = 3507 3508 3509 3510 3511 3512 3513 3284 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) " 3285 "Close the transport. If transport is forcefully closed, " 3286 "it will be immediately closed, and any pending transactions " 3287 "that are using the transport may not terminate properly. " 3288 "Otherwise, the system will wait until all transactions are closed " 3289 "while preventing new users from using the transport, and will close " 3290 "the transport when it is safe to do so."; 3514 3291 3515 3292 /* END OF LIB TRANSPORT */ … … 3525 3302 PyObject_HEAD 3526 3303 /* Type-specific fields go here. */ 3527 int priority; 3528 PyObject * id; 3529 PyObject * reg_uri; 3530 int publish_enabled; 3531 PyObject * force_contact; 3532 unsigned proxy_cnt; 3533 pj_str_t proxy[8]; 3534 unsigned reg_timeout; 3535 unsigned cred_count; 3536 pjsip_cred_info cred_info[8]; 3304 int priority; 3305 PyObject * id; 3306 PyObject * reg_uri; 3307 int publish_enabled; 3308 PyObject * force_contact; 3309 unsigned proxy_cnt; 3310 /*pj_str_t proxy[8];*/ 3311 PyListObject * proxy; 3312 unsigned reg_timeout; 3313 unsigned cred_count; 3314 /*pjsip_cred_info cred_info[8];*/ 3315 PyListObject * cred_info; 3537 3316 } acc_config_Object; 3538 3317 … … 3545 3324 { 3546 3325 Py_XDECREF(self->id); 3547 Py_XDECREF(self->reg_uri); 3548 Py_XDECREF(self->force_contact); 3326 Py_XDECREF(self->reg_uri); 3327 Py_XDECREF(self->force_contact); 3328 Py_XDECREF(self->proxy); 3329 Py_XDECREF(self->cred_info); 3549 3330 self->ob_type->tp_free((PyObject*)self); 3550 3331 } … … 3563 3344 if (self != NULL) 3564 3345 { 3565 3346 self->id = PyString_FromString(""); 3566 3347 if (self->id == NULL) 3567 3348 { … … 3569 3350 return NULL; 3570 3351 } 3571 3352 self->reg_uri = PyString_FromString(""); 3572 3353 if (self->reg_uri == NULL) 3573 3354 { … … 3581 3362 return NULL; 3582 3363 } 3364 self->proxy = (PyListObject *)PyList_New(8); 3365 if (self->proxy == NULL) 3366 { 3367 Py_DECREF(self); 3368 return NULL; 3369 } 3370 self->cred_info = (PyListObject *)PyList_New(8); 3371 if (self->cred_info == NULL) 3372 { 3373 Py_DECREF(self); 3374 return NULL; 3375 } 3583 3376 } 3584 3377 … … 3586 3379 } 3587 3380 3588 static PyObject * acc_config_get_proxy3589 (acc_config_Object *self, PyObject * args)3590 {3591 int idx;3592 pj_str_t elmt;3593 if (!PyArg_ParseTuple(args,"i",&idx))3594 {3595 return NULL;3596 }3597 if ((idx >= 0) && (idx < 8))3598 {3599 elmt = self->proxy[idx];3600 }3601 else3602 {3603 return NULL;3604 }3605 return PyString_FromStringAndSize(elmt.ptr, elmt.slen);3606 }3607 3608 static PyObject * acc_config_set_proxy3609 (acc_config_Object *self, PyObject * args)3610 {3611 int idx;3612 PyObject * str;3613 if (!PyArg_ParseTuple(args,"iO",&idx, &str))3614 {3615 return NULL;3616 }3617 if ((idx >= 0) && (idx < 8))3618 {3619 self->proxy[idx].ptr = PyString_AsString(str);3620 self->proxy[idx].slen = strlen(PyString_AsString(str));3621 }3622 else3623 {3624 return NULL;3625 }3626 Py_INCREF(Py_None);3627 return Py_None;3628 }3629 static PyObject * acc_config_get_cred_info3630 (acc_config_Object *self, PyObject * args)3631 {3632 int idx;3633 pjsip_cred_info elmt;3634 pjsip_cred_info_Object *obj;3635 if (!PyArg_ParseTuple(args,"i",&idx))3636 {3637 return NULL;3638 }3639 if ((idx >= 0) && (idx < 8))3640 {3641 elmt = self->cred_info[idx];3642 }3643 else3644 {3645 return NULL;3646 }3647 obj = (pjsip_cred_info_Object *)3648 PyType_GenericNew(&pjsip_cred_info_Type, NULL, NULL);3649 obj->data = PyString_FromStringAndSize(elmt.data.ptr, elmt.data.slen);3650 obj->realm = PyString_FromStringAndSize(elmt.realm.ptr, elmt.realm.slen);3651 obj->scheme =3652 PyString_FromStringAndSize(elmt.scheme.ptr, elmt.scheme.slen);3653 obj->username =3654 PyString_FromStringAndSize(elmt.username.ptr, elmt.username.slen);3655 obj->data_type = elmt.data_type;3656 return (PyObject *)obj;3657 }3658 3659 static PyObject * acc_config_set_cred_info3660 (acc_config_Object *self, PyObject * args)3661 {3662 int idx;3663 pjsip_cred_info_Object * obj;3664 if (!PyArg_ParseTuple(args,"iO",&idx, &obj))3665 {3666 return NULL;3667 }3668 if ((idx >= 0) && (idx < 8))3669 {3670 self->cred_info[idx].data.ptr = PyString_AsString(obj->data);3671 self->cred_info[idx].data.slen = strlen(PyString_AsString(obj->data));3672 self->cred_info[idx].realm.ptr = PyString_AsString(obj->realm);3673 self->cred_info[idx].realm.slen = strlen(PyString_AsString(obj->realm));3674 self->cred_info[idx].scheme.ptr = PyString_AsString(obj->scheme);3675 self->cred_info[idx].scheme.slen =3676 strlen(PyString_AsString(obj->scheme));3677 self->cred_info[idx].username.ptr = PyString_AsString(obj->username);3678 self->cred_info[idx].username.slen =3679 strlen(PyString_AsString(obj->username));3680 self->cred_info[idx].data_type = obj->data_type;3681 }3682 else3683 {3684 return NULL;3685 }3686 Py_INCREF(Py_None);3687 return Py_None;3688 }3689 3690 static PyMethodDef acc_config_methods[] = {3691 {3692 "get_proxy", (PyCFunction)acc_config_get_proxy, METH_VARARGS,3693 "Return proxy at specified index"3694 },3695 {3696 "set_proxy", (PyCFunction)acc_config_set_proxy, METH_VARARGS,3697 "Set proxy at specified index"3698 },3699 {3700 "get_cred_info", (PyCFunction)acc_config_get_cred_info, METH_VARARGS,3701 "Return cred_info at specified index"3702 },3703 {3704 "set_cred_info", (PyCFunction)acc_config_set_cred_info, METH_VARARGS,3705 "Set cred_info at specified index"3706 },3707 {NULL} /* Sentinel */3708 };3709 3710 3381 3711 3382 … … 3715 3386 static PyMemberDef acc_config_members[] = 3716 3387 { 3717 { 3718 "priority", T_INT, offsetof(acc_config_Object, priority), 0, 3719 "Account priority, which is used to control the order of matching " 3720 "incoming/outgoing requests. The higher the number means the higher " 3721 "the priority is, and the account will be matched first. " 3722 }, 3723 { 3724 "id", T_OBJECT_EX, 3725 offsetof(acc_config_Object, id), 0, 3726 "The full SIP URL for the account. " 3727 "The value can take name address or URL format, " 3728 "and will look something like 'sip:account@serviceprovider'. " 3729 "This field is mandatory." 3730 }, 3731 { 3732 "reg_uri", T_OBJECT_EX, 3733 offsetof(acc_config_Object, reg_uri), 0, 3734 "This is the URL to be put in the request URI for the registration, " 3735 "and will look something like 'sip:serviceprovider'. " 3736 "This field should be specified if registration is desired. " 3737 "If the value is empty, no account registration will be performed. " 3738 }, 3739 { 3740 "publish_enabled", T_INT, 3741 offsetof(acc_config_Object, publish_enabled), 0, 3742 "Publish presence? " 3743 }, 3744 { 3745 "force_contact", T_OBJECT_EX, 3746 offsetof(acc_config_Object, force_contact), 0, 3747 "Optional URI to be put as Contact for this account. " 3748 "It is recommended that this field is left empty, " 3749 "so that the value will be calculated automatically " 3750 "based on the transport address. " 3751 }, 3752 { 3753 "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0, 3754 "Number of proxies in the proxy array below. " 3755 }, 3756 { 3757 "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0, 3758 "Optional interval for registration, in seconds. " 3759 "If the value is zero, default interval will be used " 3760 "(PJSUA_REG_INTERVAL, 55 seconds). " 3761 }, 3762 { 3763 "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0, 3764 "Number of credentials in the credential array. " 3388 { 3389 "priority", T_INT, offsetof(acc_config_Object, priority), 0, 3390 "Account priority, which is used to control the order of matching " 3391 "incoming/outgoing requests. The higher the number means the higher " 3392 "the priority is, and the account will be matched first. " 3393 }, 3394 { 3395 "id", T_OBJECT_EX, 3396 offsetof(acc_config_Object, id), 0, 3397 "The full SIP URL for the account. " 3398 "The value can take name address or URL format, " 3399 "and will look something like 'sip:account@serviceprovider'. " 3400 "This field is mandatory." 3401 }, 3402 { 3403 "reg_uri", T_OBJECT_EX, 3404 offsetof(acc_config_Object, reg_uri), 0, 3405 "This is the URL to be put in the request URI for the registration, " 3406 "and will look something like 'sip:serviceprovider'. " 3407 "This field should be specified if registration is desired. " 3408 "If the value is empty, no account registration will be performed. " 3409 }, 3410 { 3411 "publish_enabled", T_INT, 3412 offsetof(acc_config_Object, publish_enabled), 0, 3413 "Publish presence? " 3414 }, 3415 { 3416 "force_contact", T_OBJECT_EX, 3417 offsetof(acc_config_Object, force_contact), 0, 3418 "Optional URI to be put as Contact for this account. " 3419 "It is recommended that this field is left empty, " 3420 "so that the value will be calculated automatically " 3421 "based on the transport address. " 3422 }, 3423 { 3424 "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0, 3425 "Number of proxies in the proxy array below. " 3426 }, 3427 { 3428 "proxy", T_OBJECT_EX, 3429 offsetof(acc_config_Object, proxy), 0, 3430 "Optional URI of the proxies to be visited for all outgoing requests " 3431 "that are using this account (REGISTER, INVITE, etc). Application need " 3432 "to specify these proxies if the service provider requires " 3433 "that requests destined towards its network should go through certain " 3434 "proxies first (for example, border controllers)." 3435 }, 3436 { 3437 "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0, 3438 "Optional interval for registration, in seconds. " 3439 "If the value is zero, default interval will be used " 3440 "(PJSUA_REG_INTERVAL, 55 seconds). " 3441 }, 3442 { 3443 "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0, 3444 "Number of credentials in the credential array. " 3445 }, 3446 { 3447 "cred_info", T_OBJECT_EX, 3448 offsetof(acc_config_Object, cred_info), 0, 3449 "Array of credentials. If registration is desired, normally there " 3450 "should be at least one credential specified, to successfully " 3451 "authenticate against the service provider. More credentials can " 3452 "be specified, for example when the requests are expected to be " 3453 "challenged by the proxies in the route set." 3765 3454 }, 3766 3455 {NULL} /* Sentinel */ … … 3803 3492 0, /* tp_iter */ 3804 3493 0, /* tp_iternext */ 3805 acc_config_methods, /* tp_methods */3494 0/*acc_config_methods*/, /* tp_methods */ 3806 3495 acc_config_members, /* tp_members */ 3807 3496 0, /* tp_getset */ … … 3825 3514 PyObject_HEAD 3826 3515 /* Type-specific fields go here. */ 3827 3828 3829 3830 3831 3832 3833 3834 3835 3516 int id; 3517 int is_default; 3518 PyObject * acc_uri; 3519 int has_registration; 3520 int expires; 3521 int status; 3522 PyObject * status_text; 3523 int online_status; 3524 char buf_[PJ_ERR_MSG_SIZE]; 3836 3525 } acc_info_Object; 3837 3526 … … 3844 3533 { 3845 3534 Py_XDECREF(self->acc_uri); 3846 3535 Py_XDECREF(self->status_text); 3847 3536 self->ob_type->tp_free((PyObject*)self); 3848 3537 } … … 3861 3550 if (self != NULL) 3862 3551 { 3863 3552 self->acc_uri = PyString_FromString(""); 3864 3553 if (self->acc_uri == NULL) 3865 3554 { … … 3882 3571 (acc_info_Object *self, PyObject * args) 3883 3572 { 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3573 int idx; 3574 char elmt; 3575 if (!PyArg_ParseTuple(args,"i",&idx)) 3576 { 3577 return NULL; 3578 } 3579 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) 3580 { 3581 elmt = self->buf_[idx]; 3582 } 3583 else 3584 { 3585 return NULL; 3586 } 3587 return PyString_FromStringAndSize(&elmt, 1); 3899 3588 } 3900 3589 … … 3902 3591 (acc_info_Object *self, PyObject * args) 3903 3592 { 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 }3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3593 int idx; 3594 PyObject * str; 3595 char * s; 3596 if (!PyArg_ParseTuple(args,"iO",&idx, &str)) 3597 { 3598 return NULL; 3599 } 3600 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) 3601 { 3602 s = PyString_AsString(str); 3603 if (s[0]) 3604 { 3605 self->buf_[idx] = s[0]; 3606 } 3607 else 3608 { 3609 return NULL; 3610 } 3611 } 3612 else 3613 { 3614 return NULL; 3615 } 3616 Py_INCREF(Py_None); 3617 return Py_None; 3929 3618 } 3930 3619 3931 3620 static PyMethodDef acc_info_methods[] = { 3932 3621 { 3933 3934 3935 }, 3936 3937 3938 3622 "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS, 3623 "Return buf char at specified index" 3624 }, 3625 { 3626 "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS, 3627 "Set buf at specified index" 3939 3628 }, 3940 3629 … … 3949 3638 static PyMemberDef acc_info_members[] = 3950 3639 { 3951 3952 3953 3954 }, 3955 3956 3957 3958 }, 3959 3960 3961 3962 3963 }, 3964 3965 3966 3967 3968 3969 }, 3970 3971 3972 3973 }, 3974 3975 3976 3977 3978 3979 }, 3980 3981 3982 3983 3984 }, 3985 3986 3987 3640 { 3641 "id", T_INT, offsetof(acc_info_Object, id), 0, 3642 "The account ID." 3643 }, 3644 { 3645 "is_default", T_INT, offsetof(acc_info_Object, is_default), 0, 3646 "Flag to indicate whether this is the default account. " 3647 }, 3648 { 3649 "acc_uri", T_OBJECT_EX, 3650 offsetof(acc_info_Object, acc_uri), 0, 3651 "Account URI" 3652 }, 3653 { 3654 "has_registration", T_INT, offsetof(acc_info_Object, has_registration), 3655 0, 3656 "Flag to tell whether this account has registration setting " 3657 "(reg_uri is not empty)." 3658 }, 3659 { 3660 "expires", T_INT, offsetof(acc_info_Object, expires), 0, 3661 "An up to date expiration interval for account registration session." 3662 }, 3663 { 3664 "status", T_INT, offsetof(acc_info_Object, status), 0, 3665 "Last registration status code. If status code is zero, " 3666 "the account is currently not registered. Any other value indicates " 3667 "the SIP status code of the registration. " 3668 }, 3669 { 3670 "status_text", T_OBJECT_EX, 3671 offsetof(acc_info_Object, status_text), 0, 3672 "String describing the registration status." 3673 }, 3674 { 3675 "online_status", T_INT, offsetof(acc_info_Object, online_status), 0, 3676 "Presence online status for this account. " 3988 3677 }, 3989 3678 {NULL} /* Sentinel */ … … 4040 3729 }; 4041 3730 4042 /* 4043 * acc_id_Object 4044 * C/Python wrapper for acc_id object 3731 3732 3733 /* 3734 * py_pjsua_acc_config_default 3735 * !modified @ 051206 3736 */ 3737 static PyObject *py_pjsua_acc_config_default 3738 (PyObject *pSelf, PyObject *pArgs) 3739 { 3740 acc_config_Object *obj; 3741 pjsua_acc_config cfg; 3742 int i; 3743 3744 if (!PyArg_ParseTuple(pArgs, "")) 3745 { 3746 return NULL; 3747 } 3748 pjsua_acc_config_default(&cfg); 3749 obj = (acc_config_Object *)acc_config_new(&acc_config_Type, NULL, NULL); 3750 obj->cred_count = cfg.cred_count; 3751 for (i = 0; i < 8; i++) 3752 { 3753 /*obj->cred_info[i] = cfg.cred_info[i];*/ 3754 int ret; 3755 pjsip_cred_info_Object * ci = 3756 (pjsip_cred_info_Object *)pjsip_cred_info_new 3757 (&pjsip_cred_info_Type,NULL,NULL); 3758 ci->data = PyString_FromStringAndSize(cfg.cred_info[i].data.ptr, 3759 cfg.cred_info[i].data.slen); 3760 ci->realm = PyString_FromStringAndSize(cfg.cred_info[i].realm.ptr, 3761 cfg.cred_info[i].realm.slen); 3762 ci->scheme = PyString_FromStringAndSize(cfg.cred_info[i].scheme.ptr, 3763 cfg.cred_info[i].scheme.slen); 3764 ci->username = PyString_FromStringAndSize(cfg.cred_info[i].username.ptr, 3765 cfg.cred_info[i].username.slen); 3766 ci->data_type = cfg.cred_info[i].data_type; 3767 ret = PyList_SetItem((PyObject *)obj->cred_info,i,(PyObject *)ci); 3768 if (ret == -1) { 3769 return NULL; 3770 } 3771 } 3772 3773 Py_XDECREF(obj->force_contact); 3774 obj->force_contact = 3775 PyString_FromStringAndSize(cfg.force_contact.ptr, 3776 cfg.force_contact.slen); 3777 obj->priority = cfg.priority; 3778 Py_XDECREF(obj->id); 3779 obj->id = 3780 PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen); 3781 Py_XDECREF(obj->reg_uri); 3782 obj->reg_uri = 3783 PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen); 3784 obj->proxy_cnt = cfg.proxy_cnt; 3785 for (i = 0; i < 8; i++) 3786 { 3787 PyObject * str; 3788 int ret; 3789 /*obj->proxy[i] = cfg.proxy[i];*/ 3790 str = PyString_FromStringAndSize(cfg.proxy[i].ptr, cfg.proxy[i].slen); 3791 ret = PyList_SetItem((PyObject *)obj->proxy,i,str); 3792 if (ret == -1) { 3793 return NULL; 3794 } 3795 } 3796 obj->publish_enabled = cfg.publish_enabled; 3797 obj->reg_timeout = cfg.reg_timeout; 3798 3799 return (PyObject *)obj; 3800 } 3801 3802 /* 3803 * py_pjsua_acc_get_count 3804 */ 3805 static PyObject *py_pjsua_acc_get_count 3806 (PyObject *pSelf, PyObject *pArgs) 3807 { 3808 int count; 3809 if (!PyArg_ParseTuple(pArgs, "")) 3810 { 3811 return NULL; 3812 } 3813 count = pjsua_acc_get_count(); 3814 return Py_BuildValue("i",count); 3815 } 3816 3817 /* 3818 * py_pjsua_acc_is_valid 3819 */ 3820 static PyObject *py_pjsua_acc_is_valid 3821 (PyObject *pSelf, PyObject *pArgs) 3822 { 3823 int id; 3824 int is_valid; 3825 3826 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3827 { 3828 return NULL; 3829 } 3830 is_valid = pjsua_acc_is_valid(id); 3831 3832 return Py_BuildValue("i", is_valid); 3833 } 3834 3835 /* 3836 * py_pjsua_acc_set_default 3837 */ 3838 static PyObject *py_pjsua_acc_set_default 3839 (PyObject *pSelf, PyObject *pArgs) 3840 { 3841 int id; 3842 int status; 3843 3844 if (!PyArg_ParseTuple(pArgs, "i", &id)) 3845 { 3846 return NULL; 3847 } 3848 status = pjsua_acc_set_default(id); 3849 3850 return Py_BuildValue("i", status); 3851 } 3852 3853 /* 3854 * py_pjsua_acc_get_default 3855 */ 3856 static PyObject *py_pjsua_acc_get_default 3857 (PyObject *pSelf, PyObject *pArgs) 3858 { 3859 int id; 3860 3861 if (!PyArg_ParseTuple(pArgs, "")) 3862 { 3863 return NULL; 3864 } 3865 id = pjsua_acc_get_default(); 3866 3867 return Py_BuildValue("i", id); 3868 } 3869 3870 /* 3871 * py_pjsua_acc_add 3872 * !modified @ 051206 3873 */ 3874 static PyObject *py_pjsua_acc_add 3875 (PyObject *pSelf, PyObject *pArgs) 3876 { 3877 int is_default; 3878 acc_config_Object * ac; 3879 pjsua_acc_config cfg; 3880 3881 int p_acc_id; 3882 int status; 3883 int i; 3884 3885 if (!PyArg_ParseTuple(pArgs, "Oi", &ac, &is_default)) 3886 { 3887 return NULL; 3888 } 3889 cfg.cred_count = ac->cred_count; 3890 for (i = 0; i < 8; i++) 3891 { 3892 /*cfg.cred_info[i] = ac->cred_info[i];*/ 3893 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)PyList_GetItem((PyObject *)ac->cred_info,i); 3894 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data); 3895 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data)); 3896 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm); 3897 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm)); 3898 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme); 3899 cfg.cred_info[i].scheme.slen = strlen(PyString_AsString(ci->scheme)); 3900 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username); 3901 cfg.cred_info[i].username.slen = strlen(PyString_AsString(ci->username)); 3902 cfg.cred_info[i].data_type = ci->data_type; 3903 } 3904 cfg.force_contact.ptr = PyString_AsString(ac->force_contact); 3905 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); 3906 cfg.id.ptr = PyString_AsString(ac->id); 3907 cfg.id.slen = strlen(PyString_AsString(ac->id)); 3908 cfg.priority = ac->priority; 3909 for (i = 0; i < 8; i++) { 3910 /*cfg.proxy[i] = ac->proxy[i];*/ 3911 cfg.proxy[i].ptr = PyString_AsString(PyList_GetItem((PyObject *)ac->proxy,i)); 3912 } 3913 cfg.proxy_cnt = ac->proxy_cnt; 3914 cfg.publish_enabled = ac->publish_enabled; 3915 cfg.reg_timeout = ac->reg_timeout; 3916 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); 3917 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); 3918 3919 status = pjsua_acc_add(&cfg, is_default, &p_acc_id); 3920 3921 return Py_BuildValue("ii", status, p_acc_id); 3922 } 3923 3924 /* 3925 * py_pjsua_acc_add_local 3926 * !modified @ 051206 3927 */ 3928 static PyObject *py_pjsua_acc_add_local 3929 (PyObject *pSelf, PyObject *pArgs) 3930 { 3931 int is_default; 3932 int tid; 3933 3934 int p_acc_id; 3935 int status; 3936 3937 3938 if (!PyArg_ParseTuple(pArgs, "iiO", &tid, &is_default)) 3939 { 3940 return NULL; 3941 } 3942 3943 3944 status = pjsua_acc_add_local(tid, is_default, &p_acc_id); 3945 3946 return Py_BuildValue("ii", status, p_acc_id); 3947 } 3948 3949 /* 3950 * py_pjsua_acc_del 3951 */ 3952 static PyObject *py_pjsua_acc_del 3953 (PyObject *pSelf, PyObject *pArgs) 3954 { 3955 int acc_id; 3956 int status; 3957 3958 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) 3959 { 3960 return NULL; 3961 } 3962 3963 3964 status = pjsua_acc_del(acc_id); 3965 return Py_BuildValue("i", status); 3966 } 3967 3968 /* 3969 * py_pjsua_acc_modify 3970 */ 3971 static PyObject *py_pjsua_acc_modify 3972 (PyObject *pSelf, PyObject *pArgs) 3973 { 3974 acc_config_Object * ac; 3975 pjsua_acc_config cfg; 3976 int acc_id; 3977 int status; 3978 int i; 3979 3980 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &ac)) 3981 { 3982 return NULL; 3983 } 3984 cfg.cred_count = ac->cred_count; 3985 for (i = 0; i < 8; i++) 3986 { 3987 /*cfg.cred_info[i] = ac->cred_info[i];*/ 3988 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)PyList_GetItem((PyObject *)ac->cred_info,i); 3989 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data); 3990 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data)); 3991 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm); 3992 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm)); 3993 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme); 3994 cfg.cred_info[i].scheme.slen = strlen(PyString_AsString(ci->scheme)); 3995 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username); 3996 cfg.cred_info[i].username.slen = strlen(PyString_AsString(ci->username)); 3997 } 3998 cfg.force_contact.ptr = PyString_AsString(ac->force_contact); 3999 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); 4000 cfg.id.ptr = PyString_AsString(ac->id); 4001 cfg.id.slen = strlen(PyString_AsString(ac->id)); 4002 cfg.priority = ac->priority; 4003 for (i = 0; i < 8; i++) { 4004 /*cfg.proxy[i] = ac->proxy[i];*/ 4005 cfg.proxy[i].ptr = PyString_AsString(PyList_GetItem((PyObject *)ac->proxy,i)); 4006 } 4007 cfg.proxy_cnt = ac->proxy_cnt; 4008 cfg.publish_enabled = ac->publish_enabled; 4009 cfg.reg_timeout = ac->reg_timeout; 4010 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); 4011 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); 4012 status = pjsua_acc_modify(acc_id, &cfg); 4013 return Py_BuildValue("i", status); 4014 } 4015 4016 /* 4017 * py_pjsua_acc_set_online_status 4018 */ 4019 static PyObject *py_pjsua_acc_set_online_status 4020 (PyObject *pSelf, PyObject *pArgs) 4021 { 4022 int is_online; 4023 int acc_id; 4024 int status; 4025 4026 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) 4027 { 4028 return NULL; 4029 } 4030 4031 status = pjsua_acc_set_online_status(acc_id, is_online); 4032 4033 return Py_BuildValue("i", status); 4034 } 4035 4036 /* 4037 * py_pjsua_acc_set_registration 4038 */ 4039 static PyObject *py_pjsua_acc_set_registration 4040 (PyObject *pSelf, PyObject *pArgs) 4041 { 4042 int renew; 4043 int acc_id; 4044 int status; 4045 4046 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) 4047 { 4048 return NULL; 4049 } 4050 4051 status = pjsua_acc_set_registration(acc_id, renew); 4052 4053 return Py_BuildValue("i", status); 4054 } 4055 4056 /* 4057 * py_pjsua_acc_get_info 4058 * !modified @ 051206 4059 */ 4060 static PyObject *py_pjsua_acc_get_info 4061 (PyObject *pSelf, PyObject *pArgs) 4062 { 4063 int acc_id; 4064 acc_info_Object * obj; 4065 pjsua_acc_info info; 4066 int status; 4067 int i; 4068 4069 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) 4070 { 4071 return NULL; 4072 } 4073 4074 4075 status = pjsua_acc_get_info(acc_id, &info); 4076 if (status == PJ_SUCCESS) { 4077 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL, NULL); 4078 obj->acc_uri = 4079 PyString_FromStringAndSize(info.acc_uri.ptr, 4080 info.acc_uri.slen); 4081 for (i = 0; i < PJ_ERR_MSG_SIZE; i++) { 4082 obj->buf_[i] = info.buf_[i]; 4083 } 4084 obj->expires = info.expires; 4085 obj->has_registration = info.has_registration; 4086 obj->id = info.id; 4087 obj->is_default = info.is_default; 4088 obj->online_status = info.online_status; 4089 obj->status = info.status; 4090 obj->status_text = 4091 PyString_FromStringAndSize(info.status_text.ptr, 4092 info.status_text.slen); 4093 return Py_BuildValue("O", obj); 4094 } else { 4095 Py_INCREF(Py_None); 4096 return Py_None; 4097 } 4098 } 4099 4100 /* 4101 * py_pjsua_enum_accs 4102 * !modified @ 051206 4103 */ 4104 static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) 4105 { 4106 pj_status_t status; 4107 PyObject *list; 4108 4109 pjsua_acc_id *id; 4110 int c, i; 4111 if (!PyArg_ParseTuple(pArgs, "i", &c)) 4112 { 4113 return NULL; 4114 } 4115 4116 id = (pjsua_acc_id *)malloc(c * sizeof(pjsua_acc_id)); 4117 status = pjsua_enum_accs(id, &c); 4118 4119 list = PyList_New(c); 4120 for (i = 0; i < c; i++) { 4121 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 4122 if (ret == -1) { 4123 return NULL; 4124 } 4125 } 4126 4127 free(id); 4128 return Py_BuildValue("O",list); 4129 } 4130 4131 /* 4132 * py_pjsua_acc_enum_info 4133 * !modified @ 051206 4134 */ 4135 static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) 4136 { 4137 pj_status_t status; 4138 PyObject *list; 4139 4140 pjsua_acc_info *info; 4141 int c, i; 4142 if (!PyArg_ParseTuple(pArgs, "i", &c)) 4143 { 4144 return NULL; 4145 } 4146 4147 info = (pjsua_acc_info *)malloc(c * sizeof(pjsua_acc_info)); 4148 status = pjsua_acc_enum_info(info, &c); 4149 4150 list = PyList_New(c); 4151 for (i = 0; i < c; i++) { 4152 int ret; 4153 int j; 4154 acc_info_Object *obj; 4155 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL,NULL); 4156 obj->acc_uri = PyString_FromStringAndSize 4157 (info[i].acc_uri.ptr, info[i].acc_uri.slen); 4158 for(j = 0; j < PJ_ERR_MSG_SIZE; j++) { 4159 obj->buf_[j] = info[i].buf_[j]; 4160 } 4161 obj->expires = info[i].expires; 4162 obj->has_registration = info[i].has_registration; 4163 obj->id = info[i].id; 4164 obj->is_default = info[i].is_default; 4165 obj->online_status = info[i].online_status; 4166 obj->status = info[i].status; 4167 obj->status_text = PyString_FromStringAndSize(info[i].status_text.ptr, 4168 info[i].status_text.slen); 4169 ret = PyList_SetItem(list, i, (PyObject *)obj); 4170 if (ret == -1) { 4171 return NULL; 4172 } 4173 } 4174 4175 free(info); 4176 return Py_BuildValue("O",list); 4177 } 4178 4179 /* 4180 * py_pjsua_acc_find_for_outgoing 4181 */ 4182 static PyObject *py_pjsua_acc_find_for_outgoing 4183 (PyObject *pSelf, PyObject *pArgs) 4184 { 4185 4186 int acc_id; 4187 PyObject * url; 4188 pj_str_t str; 4189 4190 if (!PyArg_ParseTuple(pArgs, "O", &url)) 4191 { 4192 return NULL; 4193 } 4194 str.ptr = PyString_AsString(url); 4195 str.slen = strlen(PyString_AsString(url)); 4196 4197 acc_id = pjsua_acc_find_for_outgoing(&str); 4198 4199 return Py_BuildValue("i", acc_id); 4200 } 4201 4202 /* 4203 * py_pjsua_acc_find_for_incoming 4204 */ 4205 static PyObject *py_pjsua_acc_find_for_incoming 4206 (PyObject *pSelf, PyObject *pArgs) 4207 { 4208 int acc_id; 4209 pjsip_rx_data_Object * obj; 4210 pjsip_rx_data * rdata; 4211 4212 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 4213 { 4214 return NULL; 4215 } 4216 4217 rdata = obj->rdata; 4218 acc_id = pjsua_acc_find_for_incoming(rdata); 4219 4220 return Py_BuildValue("i", acc_id); 4221 } 4222 4223 /* 4224 * py_pjsua_acc_create_uac_contact 4225 * !modified @ 061206 4226 */ 4227 static PyObject *py_pjsua_acc_create_uac_contact 4228 (PyObject *pSelf, PyObject *pArgs) 4229 { 4230 int status; 4231 int acc_id; 4232 pj_pool_Object * p; 4233 pj_pool_t * pool; 4234 PyObject * strc; 4235 pj_str_t contact; 4236 PyObject * stru; 4237 pj_str_t uri; 4238 4239 if (!PyArg_ParseTuple(pArgs, "OiO", &p, &acc_id, &stru)) 4240 { 4241 return NULL; 4242 } 4243 4244 pool = p->pool; 4245 uri.ptr = PyString_AsString(stru); 4246 uri.slen = strlen(PyString_AsString(stru)); 4247 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri); 4248 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 4249 4250 return Py_BuildValue("O", strc); 4251 } 4252 4253 /* 4254 * py_pjsua_acc_create_uas_contact 4255 * !modified @ 061206 4256 */ 4257 static PyObject *py_pjsua_acc_create_uas_contact 4258 (PyObject *pSelf, PyObject *pArgs) 4259 { 4260 int status; 4261 int acc_id; 4262 pj_pool_Object * p; 4263 pj_pool_t * pool; 4264 PyObject * strc; 4265 pj_str_t contact; 4266 pjsip_rx_data_Object * objr; 4267 pjsip_rx_data * rdata; 4268 4269 if (!PyArg_ParseTuple(pArgs, "OiO", &p, &acc_id, &objr)) 4270 { 4271 return NULL; 4272 } 4273 4274 pool = p->pool; 4275 4276 rdata = objr->rdata; 4277 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata); 4278 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 4279 4280 return Py_BuildValue("O", strc); 4281 } 4282 4283 static char pjsua_acc_config_default_doc[] = 4284 "py_pjsua.Acc_Config py_pjsua.acc_config_default () " 4285 "Call this function to initialize account config with default values."; 4286 static char pjsua_acc_get_count_doc[] = 4287 "int py_pjsua.acc_get_count () " 4288 "Get number of current accounts."; 4289 static char pjsua_acc_is_valid_doc[] = 4290 "int py_pjsua.acc_is_valid (int acc_id) " 4291 "Check if the specified account ID is valid."; 4292 static char pjsua_acc_set_default_doc[] = 4293 "int py_pjsua.acc_set_default (int acc_id) " 4294 "Set default account to be used when incoming " 4295 "and outgoing requests doesn't match any accounts."; 4296 static char pjsua_acc_get_default_doc[] = 4297 "int py_pjsua.acc_get_default () " 4298 "Get default account."; 4299 static char pjsua_acc_add_doc[] = 4300 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, " 4301 "int is_default) " 4302 "Add a new account to pjsua. PJSUA must have been initialized " 4303 "(with pjsua_init()) before calling this function."; 4304 static char pjsua_acc_add_local_doc[] = 4305 "int,int py_pjsua.acc_add_local (int tid, " 4306 "int is_default) " 4307 "Add a local account. A local account is used to identify " 4308 "local endpoint instead of a specific user, and for this reason, " 4309 "a transport ID is needed to obtain the local address information."; 4310 static char pjsua_acc_del_doc[] = 4311 "int py_pjsua.acc_del (int acc_id) " 4312 "Delete account."; 4313 static char pjsua_acc_modify_doc[] = 4314 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) " 4315 "Modify account information."; 4316 static char pjsua_acc_set_online_status_doc[] = 4317 "int py_pjsua.acc_set_online_status (int acc_id, int is_online) " 4318 "Modify account's presence status to be advertised " 4319 "to remote/presence subscribers."; 4320 static char pjsua_acc_set_registration_doc[] = 4321 "int py_pjsua.acc_set_registration (int acc_id, int renew) " 4322 "Update registration or perform unregistration."; 4323 static char pjsua_acc_get_info_doc[] = 4324 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) " 4325 "Get account information."; 4326 static char pjsua_enum_accs_doc[] = 4327 "int[] py_pjsua.enum_accs (int count) " 4328 "Enum accounts all account ids."; 4329 static char pjsua_acc_enum_info_doc[] = 4330 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info (int count) " 4331 "Enum accounts info."; 4332 static char pjsua_acc_find_for_outgoing_doc[] = 4333 "int py_pjsua.acc_find_for_outgoing (string url) " 4334 "This is an internal function to find the most appropriate account " 4335 "to used to reach to the specified URL."; 4336 static char pjsua_acc_find_for_incoming_doc[] = 4337 "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) " 4338 "This is an internal function to find the most appropriate account " 4339 "to be used to handle incoming calls."; 4340 static char pjsua_acc_create_uac_contact_doc[] = 4341 "string py_pjsua.acc_create_uac_contact (pj_pool_Object pool, " 4342 "int acc_id, string uri) " 4343 "Create a suitable URI to be put as Contact based on the specified " 4344 "target URI for the specified account."; 4345 static char pjsua_acc_create_uas_contact_doc[] = 4346 "string py_pjsua.acc_create_uas_contact (pj_pool_Object pool, " 4347 "int acc_id, pjsip_rx_data_Object rdata) " 4348 "Create a suitable URI to be put as Contact based on the information " 4349 "in the incoming request."; 4350 4351 /* END OF LIB ACCOUNT */ 4352 4353 /* LIB BUDDY */ 4354 4355 4356 4357 /* 4358 * buddy_config_Object 4359 * Buddy Config 4045 4360 */ 4046 4361 typedef struct … … 4048 4363 PyObject_HEAD 4049 4364 /* Type-specific fields go here. */ 4050 int acc_id; 4051 } acc_id_Object; 4052 4053 4054 /* 4055 * acc_id_members 4056 * declares attributes accessible from 4057 * both C and Python for acc_id object 4058 */ 4059 static PyMemberDef acc_id_members[] = 4060 { 4061 { 4062 "acc_id", T_INT, offsetof(acc_id_Object, acc_id), 0, 4063 "Account identification" 4064 }, 4365 4366 PyObject * uri; 4367 int subscribe; 4368 } buddy_config_Object; 4369 4370 4371 /* 4372 * buddy_config_dealloc 4373 * deletes a buddy_config from memory 4374 */ 4375 static void buddy_config_dealloc(buddy_config_Object* self) 4376 { 4377 Py_XDECREF(self->uri); 4378 self->ob_type->tp_free((PyObject*)self); 4379 } 4380 4381 4382 /* 4383 * buddy_config_new 4384 * constructor for buddy_config object 4385 */ 4386 static PyObject * buddy_config_new(PyTypeObject *type, PyObject *args, 4387 PyObject *kwds) 4388 { 4389 buddy_config_Object *self; 4390 4391 self = (buddy_config_Object *)type->tp_alloc(type, 0); 4392 if (self != NULL) 4393 { 4394 self->uri = PyString_FromString(""); 4395 if (self->uri == NULL) 4396 { 4397 Py_DECREF(self); 4398 return NULL; 4399 } 4400 } 4401 return (PyObject *)self; 4402 } 4403 4404 /* 4405 * buddy_config_members 4406 */ 4407 static PyMemberDef buddy_config_members[] = 4408 { 4409 4410 { 4411 "uri", T_OBJECT_EX, 4412 offsetof(buddy_config_Object, uri), 0, 4413 "TBuddy URL or name address." 4414 }, 4415 4416 { 4417 "subscribe", T_INT, 4418 offsetof(buddy_config_Object, subscribe), 0, 4419 "Specify whether presence subscription should start immediately. " 4420 }, 4421 4065 4422 {NULL} /* Sentinel */ 4066 4423 }; 4067 4424 4068 4425 4069 /* 4070 * acc_id_Type 4071 */ 4072 static PyTypeObject acc_id_Type = 4426 4427 4428 /* 4429 * buddy_config_Type 4430 */ 4431 static PyTypeObject buddy_config_Type = 4073 4432 { 4074 4433 PyObject_HEAD_INIT(NULL) 4075 4434 0, /*ob_size*/ 4076 "py_pjsua. Acc_ID",/*tp_name*/4077 sizeof( acc_id_Object),/*tp_basicsize*/4435 "py_pjsua.Buddy_Config", /*tp_name*/ 4436 sizeof(buddy_config_Object), /*tp_basicsize*/ 4078 4437 0, /*tp_itemsize*/ 4079 0,/*tp_dealloc*/4438 (destructor)buddy_config_dealloc,/*tp_dealloc*/ 4080 4439 0, /*tp_print*/ 4081 4440 0, /*tp_getattr*/ … … 4093 4452 0, /*tp_as_buffer*/ 4094 4453 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 4095 " Acc ID objects", /*tp_doc*/4096 0, /* tp_traverse*/4097 0, /* tp_clear*/4098 0, /* tp_richcompare*/4454 "Buddy Config objects", /* tp_doc */ 4455 0, /* tp_traverse */ 4456 0, /* tp_clear */ 4457 0, /* tp_richcompare */ 4099 4458 0, /* tp_weaklistoffset */ 4100 4459 0, /* tp_iter */ 4101 4460 0, /* tp_iternext */ 4102 4461 0, /* tp_methods */ 4103 acc_id_members, /* tp_members */ 4462 buddy_config_members, /* tp_members */ 4463 0, /* tp_getset */ 4464 0, /* tp_base */ 4465 0, /* tp_dict */ 4466 0, /* tp_descr_get */ 4467 0, /* tp_descr_set */ 4468 0, /* tp_dictoffset */ 4469 0, /* tp_init */ 4470 0, /* tp_alloc */ 4471 buddy_config_new, /* tp_new */ 4104 4472 4105 4473 }; 4106 4474 4107 4475 /* 4108 * py_pjsua_acc_config_default 4109 */ 4110 static PyObject *py_pjsua_acc_config_default 4476 * buddy_info_Object 4477 * Buddy Info 4478 * !modified @ 071206 4479 */ 4480 typedef struct 4481 { 4482 PyObject_HEAD 4483 /* Type-specific fields go here. */ 4484 int id; 4485 PyObject * uri; 4486 PyObject * contact; 4487 int status; 4488 PyObject * status_text; 4489 int monitor_pres; 4490 char buf_[256]; 4491 } buddy_info_Object; 4492 4493 4494 /* 4495 * buddy_info_dealloc 4496 * deletes a buddy_info from memory 4497 * !modified @ 071206 4498 */ 4499 static void buddy_info_dealloc(buddy_info_Object* self) 4500 { 4501 Py_XDECREF(self->uri); 4502 Py_XDECREF(self->contact); 4503 Py_XDECREF(self->status_text); 4504 4505 self->ob_type->tp_free((PyObject*)self); 4506 } 4507 4508 4509 /* 4510 * buddy_info_new 4511 * constructor for buddy_info object 4512 * !modified @ 071206 4513 */ 4514 static PyObject * buddy_info_new(PyTypeObject *type, PyObject *args, 4515 PyObject *kwds) 4516 { 4517 buddy_info_Object *self; 4518 4519 self = (buddy_info_Object *)type->tp_alloc(type, 0); 4520 if (self != NULL) 4521 { 4522 self->uri = PyString_FromString(""); 4523 if (self->uri == NULL) 4524 { 4525 Py_DECREF(self); 4526 return NULL; 4527 } 4528 self->contact = PyString_FromString(""); 4529 if (self->contact == NULL) 4530 { 4531 Py_DECREF(self); 4532 return NULL; 4533 } 4534 self->status_text = PyString_FromString(""); 4535 if (self->status_text == NULL) 4536 { 4537 Py_DECREF(self); 4538 return NULL; 4539 } 4540 4541 } 4542 return (PyObject *)self; 4543 } 4544 4545 /* 4546 * buddy_info_members 4547 * !modified @ 071206 4548 */ 4549 static PyMemberDef buddy_info_members[] = 4550 { 4551 { 4552 "id", T_INT, 4553 offsetof(buddy_info_Object, id), 0, 4554 "The buddy ID." 4555 }, 4556 { 4557 "uri", T_OBJECT_EX, 4558 offsetof(buddy_info_Object, uri), 0, 4559 "The full URI of the buddy, as specified in the configuration. " 4560 }, 4561 { 4562 "contact", T_OBJECT_EX, 4563 offsetof(buddy_info_Object, contact), 0, 4564 "Buddy's Contact, only available when presence subscription " 4565 "has been established to the buddy." 4566 }, 4567 { 4568 "status", T_INT, 4569 offsetof(buddy_info_Object, status), 0, 4570 "Buddy's online status. " 4571 }, 4572 { 4573 "status_text", T_OBJECT_EX, 4574 offsetof(buddy_info_Object, status_text), 0, 4575 "Text to describe buddy's online status." 4576 }, 4577 { 4578 "monitor_pres", T_INT, 4579 offsetof(buddy_info_Object, monitor_pres), 0, 4580 "Flag to indicate that we should monitor the presence information " 4581 "for this buddy (normally yes, unless explicitly disabled). " 4582 }, 4583 4584 4585 {NULL} /* Sentinel */ 4586 }; 4587 4588 4589 4590 4591 /* 4592 * buddy_info_Type 4593 */ 4594 static PyTypeObject buddy_info_Type = 4595 { 4596 PyObject_HEAD_INIT(NULL) 4597 0, /*ob_size*/ 4598 "py_pjsua.Buddy_Info", /*tp_name*/ 4599 sizeof(buddy_info_Object), /*tp_basicsize*/ 4600 0, /*tp_itemsize*/ 4601 (destructor)buddy_info_dealloc,/*tp_dealloc*/ 4602 0, /*tp_print*/ 4603 0, /*tp_getattr*/ 4604 0, /*tp_setattr*/ 4605 0, /*tp_compare*/ 4606 0, /*tp_repr*/ 4607 0, /*tp_as_number*/ 4608 0, /*tp_as_sequence*/ 4609 0, /*tp_as_mapping*/ 4610 0, /*tp_hash */ 4611 0, /*tp_call*/ 4612 0, /*tp_str*/ 4613 0, /*tp_getattro*/ 4614 0, /*tp_setattro*/ 4615 0, /*tp_as_buffer*/ 4616 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 4617 "Buddy Info objects", /* tp_doc */ 4618 0, /* tp_traverse */ 4619 0, /* tp_clear */ 4620 0, /* tp_richcompare */ 4621 0, /* tp_weaklistoffset */ 4622 0, /* tp_iter */ 4623 0, /* tp_iternext */ 4624 0, /* tp_methods */ 4625 buddy_info_members, /* tp_members */ 4626 0, /* tp_getset */ 4627 0, /* tp_base */ 4628 0, /* tp_dict */ 4629 0, /* tp_descr_get */ 4630 0, /* tp_descr_set */ 4631 0, /* tp_dictoffset */ 4632 0, /* tp_init */ 4633 0, /* tp_alloc */ 4634 buddy_info_new, /* tp_new */ 4635 4636 }; 4637 4638 /* 4639 * py_pjsua_get_buddy_count 4640 */ 4641 static PyObject *py_pjsua_get_buddy_count 4111 4642 (PyObject *pSelf, PyObject *pArgs) 4112 { 4113 acc_config_Object *obj; 4114 pjsua_acc_config cfg; 4115 int i; 4116 4117 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 4118 { 4119 return NULL; 4120 } 4121 pjsua_acc_config_default(&cfg); 4122 obj->cred_count = cfg.cred_count; 4123 for (i = 0; i < 8; i++) 4124 { 4125 obj->cred_info[i] = cfg.cred_info[i]; 4643 { 4644 int ret; 4645 4646 if (!PyArg_ParseTuple(pArgs, "")) 4647 { 4648 return NULL; 4649 } 4650 ret = pjsua_get_buddy_count(); 4651 4652 return Py_BuildValue("i", ret); 4653 } 4654 4655 /* 4656 * py_pjsua_buddy_is_valid 4657 */ 4658 static PyObject *py_pjsua_buddy_is_valid 4659 (PyObject *pSelf, PyObject *pArgs) 4660 { 4661 int id; 4662 int is_valid; 4663 4664 if (!PyArg_ParseTuple(pArgs, "i", &id)) 4665 { 4666 return NULL; 4667 } 4668 is_valid = pjsua_buddy_is_valid(id); 4669 4670 return Py_BuildValue("i", is_valid); 4671 } 4672 4673 /* 4674 * py_pjsua_enum_buddies 4675 * !modified @ 061206 4676 */ 4677 static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs) 4678 { 4679 pj_status_t status; 4680 PyObject *list; 4681 4682 pjsua_buddy_id *id; 4683 int c, i; 4684 if (!PyArg_ParseTuple(pArgs, "i", &c)) 4685 { 4686 return NULL; 4687 } 4688 4689 id = (pjsua_buddy_id *)malloc(c * sizeof(pjsua_buddy_id)); 4690 status = pjsua_enum_buddies(id, &c); 4691 4692 list = PyList_New(c); 4693 for (i = 0; i < c; i++) { 4694 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 4695 if (ret == -1) { 4696 return NULL; 4126 4697 } 4127 Py_XDECREF(obj->force_contact); 4128 obj->force_contact = 4129 PyString_FromStringAndSize(cfg.force_contact.ptr, 4130 cfg.force_contact.slen); 4131 obj->priority = cfg.priority; 4132 Py_XDECREF(obj->id); 4133 obj->id = 4134 PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen); 4135 Py_XDECREF(obj->reg_uri); 4136 obj->reg_uri = 4137 PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen); 4138 obj->proxy_cnt = cfg.proxy_cnt; 4139 for (i = 0; i < 8; i++) 4140 { 4141 obj->proxy[i] = cfg.proxy[i]; 4698 } 4699 4700 free(id); 4701 return Py_BuildValue("O",list); 4702 } 4703 4704 /* 4705 * py_pjsua_buddy_get_info 4706 * !modified @ 071206 4707 */ 4708 static PyObject *py_pjsua_buddy_get_info 4709 (PyObject *pSelf, PyObject *pArgs) 4710 { 4711 int buddy_id; 4712 buddy_info_Object * obj; 4713 pjsua_buddy_info info; 4714 int status; 4715 int i; 4716 4717 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) 4718 { 4719 return NULL; 4720 } 4721 4722 4723 status = pjsua_buddy_get_info(buddy_id, &info); 4724 if (status == PJ_SUCCESS) { 4725 obj = (buddy_info_Object *)buddy_info_new(&buddy_info_Type,NULL,NULL); 4726 obj->id = info.id; 4727 Py_XDECREF(obj->uri); 4728 obj->uri = 4729 PyString_FromStringAndSize(info.uri.ptr, 4730 info.uri.slen); 4731 Py_XDECREF(obj->contact); 4732 obj->contact = 4733 PyString_FromStringAndSize(info.contact.ptr, 4734 info.contact.slen); 4735 obj->status = info.status; 4736 Py_XDECREF(obj->status_text); 4737 obj->status_text = 4738 PyString_FromStringAndSize(info.status_text.ptr, 4739 info.status_text.slen); 4740 obj->monitor_pres = info.monitor_pres; 4741 for (i = 0; i < 256; i++) { 4742 4743 obj->buf_[i] = info.buf_[i]; 4142 4744 } 4143 obj->publish_enabled = cfg.publish_enabled;4144 obj->reg_timeout = cfg.reg_timeout;4145 4745 4746 return Py_BuildValue("O", obj); 4747 } else { 4748 Py_INCREF(Py_None); 4749 return Py_None; 4750 } 4751 } 4752 4753 /* 4754 * py_pjsua_buddy_add 4755 * !modified @ 061206 4756 */ 4757 static PyObject *py_pjsua_buddy_add 4758 (PyObject *pSelf, PyObject *pArgs) 4759 { 4760 buddy_config_Object * bc; 4761 pjsua_buddy_config cfg; 4762 4763 int p_buddy_id; 4764 int status; 4765 4766 if (!PyArg_ParseTuple(pArgs, "O", &bc)) 4767 { 4768 return NULL; 4769 } 4770 cfg.subscribe = bc->subscribe; 4771 cfg.uri.ptr = PyString_AsString(bc->uri); 4772 cfg.uri.slen = strlen(PyString_AsString(bc->uri)); 4773 4774 status = pjsua_buddy_add(&cfg, &p_buddy_id); 4775 4776 return Py_BuildValue("ii", status, p_buddy_id); 4777 } 4778 4779 /* 4780 * py_pjsua_buddy_del 4781 */ 4782 static PyObject *py_pjsua_buddy_del 4783 (PyObject *pSelf, PyObject *pArgs) 4784 { 4785 int buddy_id; 4786 int status; 4787 4788 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) 4789 { 4790 return NULL; 4791 } 4792 4793 4794 status = pjsua_buddy_del(buddy_id); 4795 return Py_BuildValue("i", status); 4796 } 4797 4798 /* 4799 * py_pjsua_buddy_subscribe_pres 4800 */ 4801 static PyObject *py_pjsua_buddy_subscribe_pres 4802 (PyObject *pSelf, PyObject *pArgs) 4803 { 4804 int buddy_id; 4805 int status; 4806 int subscribe; 4807 4808 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) 4809 { 4810 return NULL; 4811 } 4812 4813 4814 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe); 4815 return Py_BuildValue("i", status); 4816 } 4817 4818 /* 4819 * py_pjsua_pres_dump 4820 */ 4821 static PyObject *py_pjsua_pres_dump 4822 (PyObject *pSelf, PyObject *pArgs) 4823 { 4824 int verbose; 4825 4826 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) 4827 { 4828 return NULL; 4829 } 4830 4831 4832 pjsua_pres_dump(verbose); 4146 4833 Py_INCREF(Py_None); 4147 4834 return Py_None; … … 4149 4836 4150 4837 /* 4151 * py_pjsua_acc_get_count 4152 */ 4153 static PyObject *py_pjsua_acc_get_count 4154 (PyObject *pSelf, PyObject *pArgs) 4155 { 4156 int count; 4157 if (!PyArg_ParseTuple(pArgs, "")) 4158 { 4159 return NULL; 4160 } 4161 count = pjsua_acc_get_count(); 4162 return Py_BuildValue("i",count); 4163 } 4164 4165 /* 4166 * py_pjsua_acc_is_valid 4167 */ 4168 static PyObject *py_pjsua_acc_is_valid 4838 * py_pjsua_im_send 4839 * !modified @ 071206 4840 */ 4841 static PyObject *py_pjsua_im_send 4169 4842 (PyObject *pSelf, PyObject *pArgs) 4170 4843 { 4171 int id; 4172 int is_valid; 4173 4174 if (!PyArg_ParseTuple(pArgs, "i", &id)) 4175 { 4176 return NULL; 4177 } 4178 is_valid = pjsua_acc_is_valid(id); 4844 int status; 4845 int acc_id; 4846 pj_str_t to, mime_type, content; 4847 PyObject * st; 4848 PyObject * smt; 4849 PyObject * sc; 4850 pjsua_msg_data msg_data; 4851 msg_data_Object * omd; 4852 int user_data; 4853 pj_pool_t *pool; 4854 4855 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id, &st, &smt, &sc, &omd, &user_data)) 4856 { 4857 return NULL; 4858 } 4179 4859 4180 return Py_BuildValue("i", is_valid); 4181 } 4182 4183 /* 4184 * py_pjsua_acc_set_default 4185 */ 4186 static PyObject *py_pjsua_acc_set_default 4860 to.ptr = PyString_AsString(st); 4861 to.slen = strlen(PyString_AsString(st)); 4862 mime_type.ptr = PyString_AsString(smt); 4863 mime_type.slen = strlen(PyString_AsString(smt)); 4864 content.ptr = PyString_AsString(sc); 4865 content.slen = strlen(PyString_AsString(sc)); 4866 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4867 msg_data.content_type.slen = strlen(PyString_AsString(omd->content_type)); 4868 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 4869 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 4870 pool = pjsua_pool_create("pjsua", 4000, 4000); 4871 4872 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 4873 status = pjsua_im_send(acc_id, &to, &mime_type, &content, &msg_data, &user_data); 4874 pj_pool_release(pool); 4875 return Py_BuildValue("i",status); 4876 } 4877 4878 /* 4879 * py_pjsua_im_typing 4880 */ 4881 static PyObject *py_pjsua_im_typing 4187 4882 (PyObject *pSelf, PyObject *pArgs) 4188 4883 { 4189 int id; 4190 int status; 4191 4192 if (!PyArg_ParseTuple(pArgs, "i", &id)) 4193 { 4194 return NULL; 4195 } 4196 status = pjsua_acc_set_default(id); 4884 int status; 4885 int acc_id; 4886 pj_str_t to; 4887 PyObject * st; 4888 int is_typing; 4889 pjsua_msg_data msg_data; 4890 msg_data_Object * omd; 4891 pj_pool_t * pool; 4892 4893 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omd)) 4894 { 4895 return NULL; 4896 } 4197 4897 4198 return Py_BuildValue("i", status); 4199 } 4200 4201 /* 4202 * py_pjsua_acc_get_default 4203 */ 4204 static PyObject *py_pjsua_acc_get_default 4205 (PyObject *pSelf, PyObject *pArgs) 4206 { 4207 int id; 4208 4209 if (!PyArg_ParseTuple(pArgs, "")) 4210 { 4211 return NULL; 4212 } 4213 id = pjsua_acc_get_default(); 4214 4215 return Py_BuildValue("i", id); 4216 } 4217 4218 /* 4219 * py_pjsua_acc_add 4220 */ 4221 static PyObject *py_pjsua_acc_add 4222 (PyObject *pSelf, PyObject *pArgs) 4223 { 4224 int is_default; 4225 acc_config_Object * ac; 4226 pjsua_acc_config cfg; 4227 acc_id_Object * id; 4228 int p_acc_id; 4229 int status; 4230 int i; 4231 4232 if (!PyArg_ParseTuple(pArgs, "OiO", &ac, &is_default, &id)) 4233 { 4234 return NULL; 4235 } 4236 cfg.cred_count = ac->cred_count; 4237 for (i = 0; i < 8; i++) 4238 { 4239 cfg.cred_info[i] = ac->cred_info[i]; 4240 } 4241 cfg.force_contact.ptr = PyString_AsString(ac->force_contact); 4242 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); 4243 cfg.id.ptr = PyString_AsString(ac->id); 4244 cfg.id.slen = strlen(PyString_AsString(ac->id)); 4245 cfg.priority = ac->priority; 4246 for (i = 0; i < 8; i++) { 4247 cfg.proxy[i] = ac->proxy[i]; 4248 } 4249 cfg.proxy_cnt = ac->proxy_cnt; 4250 cfg.publish_enabled = ac->publish_enabled; 4251 cfg.reg_timeout = ac->reg_timeout; 4252 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); 4253 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); 4254 p_acc_id = id->acc_id; 4255 status = pjsua_acc_add(&cfg, is_default, &p_acc_id); 4256 id->acc_id = p_acc_id; 4257 return Py_BuildValue("i", status); 4258 } 4259 4260 /* 4261 * py_pjsua_acc_add_local 4262 */ 4263 static PyObject *py_pjsua_acc_add_local 4264 (PyObject *pSelf, PyObject *pArgs) 4265 { 4266 int is_default; 4267 int tid; 4268 acc_id_Object * id; 4269 int p_acc_id; 4270 int status; 4271 4272 4273 if (!PyArg_ParseTuple(pArgs, "iiO", &tid, &is_default, &id)) 4274 { 4275 return NULL; 4276 } 4277 4278 p_acc_id = id->acc_id; 4279 status = pjsua_acc_add_local(tid, is_default, &p_acc_id); 4280 id->acc_id = p_acc_id; 4281 return Py_BuildValue("i", status); 4282 } 4283 4284 /* 4285 * py_pjsua_acc_del 4286 */ 4287 static PyObject *py_pjsua_acc_del 4288 (PyObject *pSelf, PyObject *pArgs) 4289 { 4290 int acc_id; 4291 int status; 4292 4293 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) 4294 { 4295 return NULL; 4296 } 4297 4298 4299 status = pjsua_acc_del(acc_id); 4300 return Py_BuildValue("i", status); 4301 } 4302 4303 /* 4304 * py_pjsua_acc_modify 4305 */ 4306 static PyObject *py_pjsua_acc_modify 4307 (PyObject *pSelf, PyObject *pArgs) 4308 { 4309 acc_config_Object * ac; 4310 pjsua_acc_config cfg; 4311 int acc_id; 4312 int status; 4313 int i; 4314 4315 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &ac)) 4316 { 4317 return NULL; 4318 } 4319 cfg.cred_count = ac->cred_count; 4320 for (i = 0; i < 8; i++) 4321 { 4322 cfg.cred_info[i] = ac->cred_info[i]; 4323 } 4324 cfg.force_contact.ptr = PyString_AsString(ac->force_contact); 4325 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); 4326 cfg.id.ptr = PyString_AsString(ac->id); 4327 cfg.id.slen = strlen(PyString_AsString(ac->id)); 4328 cfg.priority = ac->priority; 4329 for (i = 0; i < 8; i++) { 4330 cfg.proxy[i] = ac->proxy[i]; 4331 } 4332 cfg.proxy_cnt = ac->proxy_cnt; 4333 cfg.publish_enabled = ac->publish_enabled; 4334 cfg.reg_timeout = ac->reg_timeout; 4335 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); 4336 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); 4337 status = pjsua_acc_modify(acc_id, &cfg); 4338 return Py_BuildValue("i", status); 4339 } 4340 4341 /* 4342 * py_pjsua_acc_set_online_status 4343 */ 4344 static PyObject *py_pjsua_acc_set_online_status 4345 (PyObject *pSelf, PyObject *pArgs) 4346 { 4347 int is_online; 4348 int acc_id; 4349 int status; 4350 4351 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) 4352 { 4353 return NULL; 4354 } 4355 4356 status = pjsua_acc_set_online_status(acc_id, is_online); 4357 4358 return Py_BuildValue("i", status); 4359 } 4360 4361 /* 4362 * py_pjsua_acc_set_registration 4363 */ 4364 static PyObject *py_pjsua_acc_set_registration 4365 (PyObject *pSelf, PyObject *pArgs) 4366 { 4367 int renew; 4368 int acc_id; 4369 int status; 4370 4371 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) 4372 { 4373 return NULL; 4374 } 4375 4376 status = pjsua_acc_set_registration(acc_id, renew); 4377 4378 return Py_BuildValue("i", status); 4379 } 4380 4381 /* 4382 * py_pjsua_acc_set_get_info 4383 */ 4384 static PyObject *py_pjsua_acc_get_info 4385 (PyObject *pSelf, PyObject *pArgs) 4386 { 4387 int acc_id; 4388 acc_info_Object * obj; 4389 pjsua_acc_info info; 4390 int status; 4391 int i; 4392 4393 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &obj)) 4394 { 4395 return NULL; 4396 } 4397 4398 info.acc_uri.ptr = PyString_AsString(obj->acc_uri); 4399 info.acc_uri.slen = strlen(PyString_AsString(obj->acc_uri)); 4400 for (i = 0; i < PJ_ERR_MSG_SIZE; i++) { 4401 info.buf_[i] = obj->buf_[i]; 4402 } 4403 info.expires = obj->expires; 4404 info.has_registration = obj->has_registration; 4405 info.id = obj->id; 4406 info.is_default = obj->is_default; 4407 info.online_status = obj->online_status; 4408 info.status = obj->status; 4409 info.status_text.ptr = PyString_AsString(obj->status_text); 4410 info.status_text.slen = strlen(PyString_AsString(obj->status_text)); 4411 status = pjsua_acc_get_info(acc_id, &info); 4412 obj->acc_uri = 4413 PyString_FromStringAndSize(info.acc_uri.ptr, 4414 info.acc_uri.slen); 4415 for (i = 0; i < PJ_ERR_MSG_SIZE; i++) { 4416 obj->buf_[i] = info.buf_[i]; 4417 } 4418 obj->expires = info.expires; 4419 obj->has_registration = info.has_registration; 4420 obj->id = info.id; 4421 obj->is_default = info.is_default; 4422 obj->online_status = info.online_status; 4423 obj->status = info.status; 4424 obj->status_text = 4425 PyString_FromStringAndSize(info.status_text.ptr, 4426 info.status_text.slen); 4427 return Py_BuildValue("i", status); 4428 } 4429 4430 /* 4431 * py_pjsua_enum_accs 4432 */ 4433 static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) 4434 { 4435 pj_status_t status; 4436 PyObject *list; 4437 integer_Object *count; 4438 pjsua_acc_id *id; 4439 int c, i; 4440 if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) 4441 { 4442 return NULL; 4443 } 4444 c = count->integer; 4445 id = (pjsua_acc_id *)malloc(c * sizeof(pjsua_acc_id)); 4446 status = pjsua_enum_accs(id, &c); 4447 Py_XDECREF(list); 4448 list = PyList_New(c); 4449 for (i = 0; i < c; i++) { 4450 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); 4451 if (ret == -1) { 4452 return NULL; 4453 } 4454 } 4455 count->integer = c; 4456 free(id); 4898 to.ptr = PyString_AsString(st); 4899 to.slen = strlen(PyString_AsString(st)); 4900 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 4901 msg_data.content_type.slen = strlen(PyString_AsString(omd->content_type)); 4902 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 4903 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); 4904 pool = pjsua_pool_create("pjsua", 4000, 4000); 4905 4906 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 4907 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data); 4908 pj_pool_release(pool); 4457 4909 return Py_BuildValue("i",status); 4458 4910 } 4459 4911 4460 /* 4461 * py_pjsua_acc_enum_info 4462 */ 4463 static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) 4464 { 4465 pj_status_t status; 4466 PyObject *list; 4467 integer_Object *count; 4468 pjsua_acc_info *info; 4469 int c, i; 4470 if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) 4471 { 4472 return NULL; 4473 } 4474 c = count->integer; 4475 info = (pjsua_acc_info *)malloc(c * sizeof(pjsua_acc_info)); 4476 status = pjsua_acc_enum_info(info, &c); 4477 Py_XDECREF(list); 4478 list = PyList_New(c); 4479 for (i = 0; i < c; i++) { 4480 int ret = PyList_SetItem(list, i, Py_BuildValue("i", info[i])); 4481 if (ret == -1) { 4482 return NULL; 4483 } 4484 } 4485 count->integer = c; 4486 free(info); 4487 return Py_BuildValue("i",status); 4488 } 4489 4490 /* 4491 * py_pjsua_acc_find_for_outgoing 4492 */ 4493 static PyObject *py_pjsua_acc_find_for_outgoing 4494 (PyObject *pSelf, PyObject *pArgs) 4495 { 4496 4497 int acc_id; 4498 PyObject * url; 4499 pj_str_t str; 4500 4501 if (!PyArg_ParseTuple(pArgs, "O", &url)) 4502 { 4503 return NULL; 4504 } 4505 str.ptr = PyString_AsString(url); 4506 str.slen = strlen(PyString_AsString(url)); 4507 4508 acc_id = pjsua_acc_find_for_outgoing(&str); 4509 4510 return Py_BuildValue("i", acc_id); 4511 } 4512 4513 /* 4514 * py_pjsua_acc_find_for_incoming 4515 */ 4516 static PyObject *py_pjsua_acc_find_for_incoming 4517 (PyObject *pSelf, PyObject *pArgs) 4518 { 4519 int acc_id; 4520 pjsip_rx_data_Object * obj; 4521 pjsip_rx_data * rdata; 4522 4523 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 4524 { 4525 return NULL; 4526 } 4527 4528 rdata = obj->rdata; 4529 acc_id = pjsua_acc_find_for_incoming(rdata); 4530 4531 return Py_BuildValue("i", acc_id); 4532 } 4533 4534 /* 4535 * py_pjsua_acc_create_uac_contact 4536 */ 4537 static PyObject *py_pjsua_acc_create_uac_contact 4538 (PyObject *pSelf, PyObject *pArgs) 4539 { 4540 int status; 4541 int acc_id; 4542 pj_pool_Object * p; 4543 pj_pool_t * pool; 4544 PyObject * strc; 4545 pj_str_t contact; 4546 PyObject * stru; 4547 pj_str_t uri; 4548 4549 if (!PyArg_ParseTuple(pArgs, "OOiO", &p, &strc, &acc_id, &stru)) 4550 { 4551 return NULL; 4552 } 4553 4554 pool = p->pool; 4555 contact.ptr = PyString_AsString(strc); 4556 contact.slen = strlen(PyString_AsString(strc)); 4557 uri.ptr = PyString_AsString(stru); 4558 uri.slen = strlen(PyString_AsString(stru)); 4559 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri); 4560 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 4561 4562 return Py_BuildValue("i", status); 4563 } 4564 4565 /* 4566 * py_pjsua_acc_create_uas_contact 4567 */ 4568 static PyObject *py_pjsua_acc_create_uas_contact 4569 (PyObject *pSelf, PyObject *pArgs) 4570 { 4571 int status; 4572 int acc_id; 4573 pj_pool_Object * p; 4574 pj_pool_t * pool; 4575 PyObject * strc; 4576 pj_str_t contact; 4577 pjsip_rx_data_Object * objr; 4578 pjsip_rx_data * rdata; 4579 4580 if (!PyArg_ParseTuple(pArgs, "OOiO", &p, &strc, &acc_id, &objr)) 4581 { 4582 return NULL; 4583 } 4584 4585 pool = p->pool; 4586 contact.ptr = PyString_AsString(strc); 4587 contact.slen = strlen(PyString_AsString(strc)); 4588 rdata = objr->rdata; 4589 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata); 4590 strc = PyString_FromStringAndSize(contact.ptr, contact.slen); 4591 4592 return Py_BuildValue("i", status); 4593 } 4594 4595 static char pjsua_acc_config_default_doc[] = 4596 "void py_pjsua.acc_config_default (py_pjsua.Acc_Config cfg) " 4597 "Call this function to initialize account config with default values."; 4598 static char pjsua_acc_get_count_doc[] = 4599 "int py_pjsua.acc_get_count () " 4600 "Get number of current accounts."; 4601 static char pjsua_acc_is_valid_doc[] = 4602 "int py_pjsua.acc_is_valid (int acc_id) " 4603 "Check if the specified account ID is valid."; 4604 static char pjsua_acc_set_default_doc[] = 4605 "int py_pjsua.acc_set_default (int acc_id) " 4606 "Set default account to be used when incoming " 4607 "and outgoing requests doesn't match any accounts."; 4608 static char pjsua_acc_get_default_doc[] = 4609 "int py_pjsua.acc_get_default () " 4610 "Get default account."; 4611 static char pjsua_acc_add_doc[] = 4612 "int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, " 4613 "int is_default, py_pjsua.Acc_ID p_acc_id) " 4614 "Add a new account to pjsua. PJSUA must have been initialized " 4615 "(with pjsua_init()) before calling this function."; 4616 static char pjsua_acc_add_local_doc[] = 4617 "int py_pjsua.acc_add_local (int tid, " 4618 "int is_default, py_pjsua.Acc_ID p_acc_id) " 4619 "Add a local account. A local account is used to identify " 4620 "local endpoint instead of a specific user, and for this reason, " 4621 "a transport ID is needed to obtain the local address information."; 4622 static char pjsua_acc_del_doc[] = 4623 "int py_pjsua.acc_del (int acc_id) " 4624 "Delete account."; 4625 static char pjsua_acc_modify_doc[] = 4626 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) " 4627 "Modify account information."; 4628 static char pjsua_acc_set_online_status_doc[] = 4629 "int py_pjsua.acc_set_online_status (int acc_id, int is_online) " 4630 "Modify account's presence status to be advertised " 4631 "to remote/presence subscribers."; 4632 static char pjsua_acc_set_registration_doc[] = 4633 "int py_pjsua.acc_set_registration (int acc_id, int renew) " 4634 "Update registration or perform unregistration."; 4635 static char pjsua_acc_get_info_doc[] = 4636 "int py_pjsua.acc_get_info (int acc_id, py_pjsua.Acc_Info info) " 4637 "Get account information."; 4638 static char pjsua_enum_accs_doc[] = 4639 "int py_pjsua.enum_accs (py_pjsua.Acc_ID ids[], py_pjsua.Integer count) " 4640 "Enum accounts all account ids."; 4641 static char pjsua_acc_enum_info_doc[] = 4642 "int py_pjsua.acc_enum_info (py_pjsua.Acc_Info info[], " 4643 "py_pjsua.Integer count) " 4644 "Enum accounts info."; 4645 static char pjsua_acc_find_for_outgoing_doc[] = 4646 "int py_pjsua.acc_find_for_outgoing (string url) " 4647 "This is an internal function to find the most appropriate account " 4648 "to used to reach to the specified URL."; 4649 static char pjsua_acc_find_for_incoming_doc[] = 4650 "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) " 4651 "This is an internal function to find the most appropriate account " 4652 "to be used to handle incoming calls."; 4653 static char pjsua_acc_create_uac_contact_doc[] = 4654 "int py_pjsua.acc_create_uac_contact (pj_pool_Object pool, " 4655 "string contact, int acc_id, string uri) " 4656 "Create a suitable URI to be put as Contact based on the specified " 4657 "target URI for the specified account."; 4658 static char pjsua_acc_create_uas_contact_doc[] = 4659 "int py_pjsua.acc_create_uas_contact (pj_pool_Object pool, " 4660 "string contact, int acc_id, pjsip_rx_data_Object rdata) " 4661 "Create a suitable URI to be put as Contact based on the information " 4662 "in the incoming request."; 4663 4664 /* END OF LIB ACCOUNT */ 4665 4666 /* XXX test */ 4667 static PyObject *py_my_parse_by_reference 4668 (PyObject *pSelf, PyObject *pArgs) 4669 { 4670 PyObject *obj; 4671 4672 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 4673 { 4674 return NULL; 4675 } 4676 4677 4678 Py_INCREF(Py_None); 4679 return Py_None; 4680 } 4681 4682 /* XXX end-test */ 4912 static char pjsua_get_buddy_count_doc[] = 4913 "int py_pjsua.get_buddy_count () " 4914 "Get total number of buddies."; 4915 static char pjsua_buddy_is_valid_doc[] = 4916 "int py_pjsua.buddy_is_valid (int buddy_id) " 4917 "Check if buddy ID is valid."; 4918 static char pjsua_enum_buddies_doc[] = 4919 "int[] py_pjsua.enum_buddies (int count) " 4920 "Enum buddy IDs."; 4921 static char pjsua_buddy_get_info_doc[] = 4922 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) " 4923 "Get detailed buddy info."; 4924 static char pjsua_buddy_add_doc[] = 4925 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) " 4926 "Add new buddy."; 4927 static char pjsua_buddy_del_doc[] = 4928 "int py_pjsua.buddy_del (int buddy_id) " 4929 "Delete buddy."; 4930 static char pjsua_buddy_subscribe_pres_doc[] = 4931 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) " 4932 "Enable/disable buddy's presence monitoring."; 4933 static char pjsua_pres_dump_doc[] = 4934 "void py_pjsua.pres_dump (int verbose) " 4935 "Dump presence subscriptions to log file."; 4936 static char pjsua_im_send_doc[] = 4937 "int py_pjsua.im_send (int acc_id, string to, string mime_type, " 4938 "string content, py_pjsua.Msg_Data msg_data, int user_data) " 4939 "Send instant messaging outside dialog, using the specified account " 4940 "for route set and authentication."; 4941 static char pjsua_im_typing_doc[] = 4942 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, " 4943 "py_pjsua.Msg_Data msg_data) " 4944 "Send typing indication outside dialog."; 4945 4946 /* END OF LIB BUDDY */ 4947 4683 4948 4684 4949 … … 4689 4954 { 4690 4955 { 4691 "my_parse_by_reference", py_my_parse_by_reference, METH_VARARGS, "" 4956 "thread_register", py_pjsua_thread_register, METH_VARARGS, 4957 pjsua_thread_register_doc 4692 4958 }, 4693 4959 { … … 4746 5012 pjsua_media_config_default_doc 4747 5013 }, 4748 { 4749 "logging_config_dup", py_pjsua_logging_config_dup, METH_VARARGS, 4750 pjsua_logging_config_dup_doc 4751 }, 4752 { 4753 "config_dup", py_pjsua_config_dup, METH_VARARGS, pjsua_config_dup_doc 4754 }, 4755 { 4756 "pjsip_cred_dup", py_pjsip_cred_dup, METH_VARARGS, pjsip_cred_dup_doc 4757 }, 5014 5015 4758 5016 { 4759 5017 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS, 4760 5018 pjsua_msg_data_init_doc 4761 5019 }, 4762 { 4763 "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS, 4764 pjsua_stun_config_default_doc 4765 }, 4766 { 4767 "transport_config_default", py_pjsua_transport_config_default, 4768 METH_VARARGS,pjsua_transport_config_default_doc 4769 }, 4770 { 4771 "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS, 4772 pjsua_normalize_stun_config_doc 4773 }, 4774 { 4775 "transport_config_dup", py_pjsua_transport_config_dup, METH_VARARGS, 4776 pjsua_transport_config_dup_doc 4777 }, 4778 { 4779 "transport_create", py_pjsua_transport_create, METH_VARARGS, 4780 pjsua_transport_create_doc 4781 }, 4782 { 4783 "transport_register", py_pjsua_transport_register, METH_VARARGS, 4784 pjsua_transport_register_doc 4785 }, 4786 { 4787 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS, 4788 pjsua_enum_transports_doc 4789 }, 4790 { 4791 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS, 4792 pjsua_transport_get_info_doc 4793 }, 4794 { 4795 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS, 4796 pjsua_transport_set_enable_doc 4797 }, 4798 { 4799 "transport_close", py_pjsua_transport_close, METH_VARARGS, 4800 pjsua_transport_close_doc 4801 }, 4802 { 4803 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS, 4804 pjsua_acc_config_default_doc 4805 }, 4806 { 4807 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS, 4808 pjsua_acc_get_count_doc 4809 }, 4810 { 4811 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS, 4812 pjsua_acc_is_valid_doc 4813 }, 4814 { 4815 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS, 4816 pjsua_acc_set_default_doc 4817 }, 4818 { 4819 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS, 4820 pjsua_acc_get_default_doc 4821 }, 4822 { 4823 "acc_add", py_pjsua_acc_add, METH_VARARGS, 4824 pjsua_acc_add_doc 4825 }, 4826 { 4827 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS, 4828 pjsua_acc_add_local_doc 4829 }, 4830 { 4831 "acc_del", py_pjsua_acc_del, METH_VARARGS, 4832 pjsua_acc_del_doc 4833 }, 4834 { 4835 "acc_modify", py_pjsua_acc_modify, METH_VARARGS, 4836 pjsua_acc_modify_doc 4837 }, 4838 { 4839 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS, 4840 pjsua_acc_set_online_status_doc 4841 }, 4842 { 4843 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS, 4844 pjsua_acc_set_registration_doc 4845 }, 4846 { 4847 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS, 4848 pjsua_acc_get_info_doc 4849 }, 4850 { 4851 "enum_accs", py_pjsua_enum_accs, METH_VARARGS, 4852 pjsua_enum_accs_doc 4853 }, 4854 { 4855 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, 4856 pjsua_acc_enum_info_doc 4857 }, 4858 { 4859 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS, 4860 pjsua_acc_find_for_outgoing_doc 4861 }, 4862 { 4863 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS, 4864 pjsua_acc_find_for_incoming_doc 4865 }, 4866 { 4867 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS, 4868 pjsua_acc_create_uac_contact_doc 4869 }, 4870 { 4871 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS, 4872 pjsua_acc_create_uas_contact_doc 4873 }, 5020 { 5021 "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS, 5022 pjsua_stun_config_default_doc 5023 }, 5024 { 5025 "transport_config_default", py_pjsua_transport_config_default, 5026 METH_VARARGS,pjsua_transport_config_default_doc 5027 }, 5028 { 5029 "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS, 5030 pjsua_normalize_stun_config_doc 5031 }, 5032 5033 { 5034 "transport_create", py_pjsua_transport_create, METH_VARARGS, 5035 pjsua_transport_create_doc 5036 }, 5037 { 5038 "transport_register", py_pjsua_transport_register, METH_VARARGS, 5039 pjsua_transport_register_doc 5040 }, 5041 { 5042 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS, 5043 pjsua_enum_transports_doc 5044 }, 5045 { 5046 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS, 5047 pjsua_transport_get_info_doc 5048 }, 5049 { 5050 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS, 5051 pjsua_transport_set_enable_doc 5052 }, 5053 { 5054 "transport_close", py_pjsua_transport_close, METH_VARARGS, 5055 pjsua_transport_close_doc 5056 }, 5057 { 5058 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS, 5059 pjsua_acc_config_default_doc 5060 }, 5061 { 5062 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS, 5063 pjsua_acc_get_count_doc 5064 }, 5065 { 5066 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS, 5067 pjsua_acc_is_valid_doc 5068 }, 5069 { 5070 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS, 5071 pjsua_acc_set_default_doc 5072 }, 5073 { 5074 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS, 5075 pjsua_acc_get_default_doc 5076 }, 5077 { 5078 "acc_add", py_pjsua_acc_add, METH_VARARGS, 5079 pjsua_acc_add_doc 5080 }, 5081 { 5082 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS, 5083 pjsua_acc_add_local_doc 5084 }, 5085 { 5086 "acc_del", py_pjsua_acc_del, METH_VARARGS, 5087 pjsua_acc_del_doc 5088 }, 5089 { 5090 "acc_modify", py_pjsua_acc_modify, METH_VARARGS, 5091 pjsua_acc_modify_doc 5092 }, 5093 { 5094 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS, 5095 pjsua_acc_set_online_status_doc 5096 }, 5097 { 5098 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS, 5099 pjsua_acc_set_registration_doc 5100 }, 5101 { 5102 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS, 5103 pjsua_acc_get_info_doc 5104 }, 5105 { 5106 "enum_accs", py_pjsua_enum_accs, METH_VARARGS, 5107 pjsua_enum_accs_doc 5108 }, 5109 { 5110 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, 5111 pjsua_acc_enum_info_doc 5112 }, 5113 { 5114 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS, 5115 pjsua_acc_find_for_outgoing_doc 5116 }, 5117 { 5118 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS, 5119 pjsua_acc_find_for_incoming_doc 5120 }, 5121 { 5122 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS, 5123 pjsua_acc_create_uac_contact_doc 5124 }, 5125 { 5126 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS, 5127 pjsua_acc_create_uas_contact_doc 5128 }, 5129 { 5130 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS, 5131 pjsua_get_buddy_count_doc 5132 }, 5133 { 5134 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS, 5135 pjsua_buddy_is_valid_doc 5136 }, 5137 { 5138 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS, 5139 pjsua_enum_buddies_doc 5140 }, 5141 { 5142 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS, 5143 pjsua_buddy_get_info_doc 5144 }, 5145 { 5146 "buddy_add", py_pjsua_buddy_add, METH_VARARGS, 5147 pjsua_buddy_add_doc 5148 }, 5149 { 5150 "buddy_del", py_pjsua_buddy_del, METH_VARARGS, 5151 pjsua_buddy_del_doc 5152 }, 5153 { 5154 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS, 5155 pjsua_buddy_subscribe_pres_doc 5156 }, 5157 { 5158 "pres_dump", py_pjsua_pres_dump, METH_VARARGS, 5159 pjsua_pres_dump_doc 5160 }, 5161 { 5162 "im_send", py_pjsua_im_send, METH_VARARGS, 5163 pjsua_im_send_doc 5164 }, 5165 { 5166 "im_typing", py_pjsua_im_typing, METH_VARARGS, 5167 pjsua_im_typing_doc 5168 }, 5169 5170 4874 5171 {NULL, NULL} /* end of function list */ 4875 5172 }; … … 4885 5182 PyObject* m = NULL; 4886 5183 5184 4887 5185 if (PyType_Ready(&callback_Type) < 0) 4888 5186 return; … … 4918 5216 return; 4919 5217 4920 4921 4922 5218 /* LIB TRANSPORT */ 5219 5220 if (PyType_Ready(&stun_config_Type) < 0) 4923 5221 return; 4924 5222 if (PyType_Ready(&transport_config_Type) < 0) 4925 5223 return; 4926 5224 if (PyType_Ready(&sockaddr_Type) < 0) 4927 5225 return; 4928 5226 if (PyType_Ready(&host_port_Type) < 0) 4929 5227 return; 4930 transport_id_Type.tp_new = PyType_GenericNew; 4931 if (PyType_Ready(&transport_id_Type) < 0)5228 5229 if (PyType_Ready(&transport_info_Type) < 0) 4932 5230 return; 4933 if (PyType_Ready(&transport_info_Type) < 0) 4934 return; 4935 integer_Type.tp_new = PyType_GenericNew; 4936 if (PyType_Ready(&integer_Type) < 0) 4937 return; 4938 pjsip_transport_Type.tp_new = PyType_GenericNew; 5231 5232 pjsip_transport_Type.tp_new = PyType_GenericNew; 4939 5233 if (PyType_Ready(&pjsip_transport_Type) < 0) 4940 5234 return; 4941 5235 4942 4943 4944 4945 4946 acc_id_Type.tp_new = PyType_GenericNew; 4947 if (PyType_Ready(&acc_id_Type) < 0)5236 /* END OF LIB TRANSPORT */ 5237 5238 /* LIB ACCOUNT */ 5239 5240 5241 if (PyType_Ready(&acc_config_Type) < 0) 4948 5242 return; 4949 if (PyType_Ready(&acc_config_Type) < 0)5243 if (PyType_Ready(&acc_info_Type) < 0) 4950 5244 return; 4951 if (PyType_Ready(&acc_info_Type) < 0) 5245 5246 /* END OF LIB ACCOUNT */ 5247 5248 /* LIB BUDDY */ 5249 5250 if (PyType_Ready(&buddy_config_Type) < 0) 4952 5251 return; 4953 4954 /* END OF LIB ACCOUNT */ 5252 if (PyType_Ready(&buddy_info_Type) < 0) 5253 return; 5254 5255 /* END OF LIB BUDDY */ 5256 5257 4955 5258 4956 5259 m = Py_InitModule3( … … 4998 5301 ); 4999 5302 5000 5001 5002 5303 /* LIB TRANSPORT */ 5304 5305 Py_INCREF(&stun_config_Type); 5003 5306 PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type); 5004 5307 Py_INCREF(&transport_config_Type); 5005 5308 PyModule_AddObject 5006 5007 5309 (m, "Transport_Config", (PyObject *)&transport_config_Type); 5310 Py_INCREF(&sockaddr_Type); 5008 5311 PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type); 5009 5312 Py_INCREF(&host_port_Type); 5010 5313 PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type); 5011 Py_INCREF(&transport_id_Type); 5012 PyModule_AddObject(m, "Transport_ID", (PyObject *)&transport_id_Type); 5013 Py_INCREF(&transport_info_Type); 5314 5315 Py_INCREF(&transport_info_Type); 5014 5316 PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type); 5015 Py_INCREF(&integer_Type); 5016 PyModule_AddObject(m, "Integer", (PyObject *)&integer_Type); 5017 Py_INCREF(&pjsip_transport_Type); 5317 5318 Py_INCREF(&pjsip_transport_Type); 5018 5319 PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type); 5019 5320 5020 /* END OF LIB TRANSPORT */ 5021 5022 /* LIB ACCOUNT */ 5023 5024 Py_INCREF(&acc_id_Type); 5025 PyModule_AddObject(m, "Acc_ID", (PyObject *)&acc_id_Type); 5026 Py_INCREF(&acc_config_Type); 5321 /* END OF LIB TRANSPORT */ 5322 5323 /* LIB ACCOUNT */ 5324 5325 5326 Py_INCREF(&acc_config_Type); 5027 5327 PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type); 5028 5328 Py_INCREF(&acc_info_Type); 5029 5329 PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type); 5030 5330 5031 /* END OF LIB ACCOUNT */ 5331 /* END OF LIB ACCOUNT */ 5332 5333 /* LIB BUDDY */ 5334 5335 Py_INCREF(&buddy_config_Type); 5336 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&buddy_config_Type); 5337 Py_INCREF(&buddy_info_Type); 5338 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&buddy_info_Type); 5339 5340 /* END OF LIB BUDDY */ 5341 5342 5032 5343 5033 5344 #ifdef PJSUA_INVALID_ID … … 5083 5394 #endif 5084 5395 5085 } 5396 #ifdef PJSUA_MAX_BUDDIES 5397 /* 5398 * Default account priority. 5399 */ 5400 PyModule_AddIntConstant( 5401 m, "PJSUA_MAX_BUDDIES", PJSUA_MAX_BUDDIES 5402 ); 5403 #endif 5404 5405 5406 5407 5408 }
Note: See TracChangeset
for help on using the changeset viewer.