- Timestamp:
- Dec 4, 2006 8:33:20 AM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/build/py_pjsua.dsp
r824 r845 81 81 LINK32=link.exe 82 82 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept 83 # ADD LINK32 python24 .lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib /nologo /dll /debug /machine:I386 /out:"..\lib\py_pjsua_d.pyd" /pdbtype:sept /libpath:"../../pjlib/lib" /libpath:"../../pjlib-util/lib" /libpath:"../../pjmedia/lib" /libpath:"../../pjsip/lib" /libpath:"F:\incoming\projects\divusi\Python-2.4\Python-2.4\PCbuild" /libpath:"F:\incoming\projects\divusi\Python-2.4\Python-2.4\PC\VC6"83 # ADD LINK32 python24_d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib /nologo /dll /debug /machine:I386 /out:"..\lib\py_pjsua_d.pyd" /pdbtype:sept /libpath:"../../pjlib/lib" /libpath:"../../pjlib-util/lib" /libpath:"../../pjmedia/lib" /libpath:"../../pjsip/lib" /libpath:"F:\incoming\projects\divusi\Python-2.4\Python-2.4\PCbuild" /libpath:"F:\incoming\projects\divusi\Python-2.4\Python-2.4\PC\VC6" 84 84 85 85 !ENDIF -
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua.py
r824 r845 75 75 # 76 76 77 # lib transport 78 stunc = py_pjsua.STUN_Config(); 79 py_pjsua.stun_config_default(stunc); 80 81 tc = py_pjsua.Transport_Config(); 82 py_pjsua.transport_config_default(tc); 83 84 py_pjsua.normalize_stun_config(stunc); 85 86 id = py_pjsua.Transport_ID(); 87 status = py_pjsua.transport_create(1, tc, id); 88 print "py transport create status " + `status` 89 90 t_id = id.transport_id; 91 ti = py_pjsua.Transport_Info(); 92 status = py_pjsua.transport_get_info(t_id,ti) 93 print "py transport get info status " + `status` 94 95 status = py_pjsua.transport_set_enable(t_id,1) 96 print "py transport set enable status " + `status` 97 if status != 0 : 98 py_pjsua.perror("py_pjsua","set enable",status) 99 100 101 status = py_pjsua.transport_close(t_id,1) 102 print "py transport close status " + `status` 103 if status != 0 : 104 py_pjsua.perror("py_pjsua","close",status) 105 106 # end of lib transport 107 108 # lib account 109 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) 114 print "py acc add status " + `status` 115 if status != 0 : 116 py_pjsua.perror("py_pjsua","add acc",status) 117 count = py_pjsua.acc_get_count() 118 print "acc count " + `count` 119 120 accid.acc_id = py_pjsua.acc_get_default() 121 122 print "acc id default " + `accid.acc_id` 123 124 # end of lib account 125 77 126 py_pjsua.perror("saya","hallo",70006) 78 127 -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r824 r845 22 22 23 23 #define THIS_FILE "main.c" 24 25 /* LIB BASE */ 24 26 25 27 static PyObject* obj_reconfigure_logging; … … 1402 1404 PyObject_HEAD 1403 1405 /* Type-specific fields go here. */ 1404 pjsip_cred_info * cred; 1406 PyObject * realm; 1407 PyObject * scheme; 1408 PyObject * username; 1409 int data_type; 1410 PyObject * data; 1411 1405 1412 } pjsip_cred_info_Object; 1406 1413 1414 /* 1415 * cred_info_dealloc 1416 * deletes a cred info from memory 1417 */ 1418 static void pjsip_cred_info_dealloc(pjsip_cred_info_Object* self) 1419 { 1420 Py_XDECREF(self->realm); 1421 Py_XDECREF(self->scheme); 1422 Py_XDECREF(self->username); 1423 Py_XDECREF(self->data); 1424 self->ob_type->tp_free((PyObject*)self); 1425 } 1426 1427 1428 /* 1429 * cred_info_new 1430 * constructor for cred_info object 1431 */ 1432 static PyObject * pjsip_cred_info_new(PyTypeObject *type, PyObject *args, 1433 PyObject *kwds) 1434 { 1435 pjsip_cred_info_Object *self; 1436 1437 self = (pjsip_cred_info_Object *)type->tp_alloc(type, 0); 1438 if (self != NULL) 1439 { 1440 self->realm = PyString_FromString(""); 1441 if (self->realm == NULL) 1442 { 1443 Py_DECREF(self); 1444 return NULL; 1445 } 1446 self->scheme = PyString_FromString(""); 1447 if (self->scheme == NULL) 1448 { 1449 Py_DECREF(self); 1450 return NULL; 1451 } 1452 self->username = PyString_FromString(""); 1453 if (self->username == NULL) 1454 { 1455 Py_DECREF(self); 1456 return NULL; 1457 } 1458 self->data = PyString_FromString(""); 1459 if (self->data == NULL) 1460 { 1461 Py_DECREF(self); 1462 return NULL; 1463 } 1464 } 1465 1466 return (PyObject *)self; 1467 } 1468 1469 1470 /* 1471 * pjsip_cred_info_members 1472 */ 1473 static PyMemberDef pjsip_cred_info_members[] = 1474 { 1475 { 1476 "realm", T_OBJECT_EX, 1477 offsetof(pjsip_cred_info_Object, realm), 0, 1478 "Realm" 1479 }, 1480 { 1481 "scheme", T_OBJECT_EX, 1482 offsetof(pjsip_cred_info_Object, scheme), 0, 1483 "Scheme" 1484 }, 1485 { 1486 "username", T_OBJECT_EX, 1487 offsetof(pjsip_cred_info_Object, username), 0, 1488 "User name" 1489 }, 1490 { 1491 "data", T_OBJECT_EX, 1492 offsetof(pjsip_cred_info_Object, data), 0, 1493 "The data, which can be a plaintext password or a hashed digest. " 1494 }, 1495 { 1496 "data_type", T_INT, offsetof(pjsip_cred_info_Object, data_type), 0, 1497 "Type of data" 1498 }, 1499 1500 {NULL} /* Sentinel */ 1501 }; 1407 1502 1408 1503 /* … … 1412 1507 { 1413 1508 PyObject_HEAD_INIT(NULL) 1414 0, /*ob_size*/ 1415 "py_pjsua.PJSIP_Cred_Info",/*tp_name*/ 1416 sizeof(pjsip_cred_info_Object), /*tp_basicsize*/ 1417 0, /*tp_itemsize*/ 1418 0, /*tp_dealloc*/ 1419 0, /*tp_print*/ 1420 0, /*tp_getattr*/ 1421 0, /*tp_setattr*/ 1422 0, /*tp_compare*/ 1423 0, /*tp_repr*/ 1424 0, /*tp_as_number*/ 1425 0, /*tp_as_sequence*/ 1426 0, /*tp_as_mapping*/ 1427 0, /*tp_hash */ 1428 0, /*tp_call*/ 1429 0, /*tp_str*/ 1430 0, /*tp_getattro*/ 1431 0, /*tp_setattro*/ 1432 0, /*tp_as_buffer*/ 1433 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 1434 "pjsip_cred_info objects", /* tp_doc */ 1509 0, /*ob_size*/ 1510 "py_pjsua.PJSIP_Cred_Info", /*tp_name*/ 1511 sizeof(pjsip_cred_info_Object), /*tp_basicsize*/ 1512 0, /*tp_itemsize*/ 1513 (destructor)pjsip_cred_info_dealloc,/*tp_dealloc*/ 1514 0, /*tp_print*/ 1515 0, /*tp_getattr*/ 1516 0, /*tp_setattr*/ 1517 0, /*tp_compare*/ 1518 0, /*tp_repr*/ 1519 0, /*tp_as_number*/ 1520 0, /*tp_as_sequence*/ 1521 0, /*tp_as_mapping*/ 1522 0, /*tp_hash */ 1523 0, /*tp_call*/ 1524 0, /*tp_str*/ 1525 0, /*tp_getattro*/ 1526 0, /*tp_setattro*/ 1527 0, /*tp_as_buffer*/ 1528 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 1529 "PJSIP Cred Info objects", /* tp_doc */ 1530 0, /* tp_traverse */ 1531 0, /* tp_clear */ 1532 0, /* tp_richcompare */ 1533 0, /* tp_weaklistoffset */ 1534 0, /* tp_iter */ 1535 0, /* tp_iternext */ 1536 0, /* tp_methods */ 1537 pjsip_cred_info_members, /* tp_members */ 1538 0, /* tp_getset */ 1539 0, /* tp_base */ 1540 0, /* tp_dict */ 1541 0, /* tp_descr_get */ 1542 0, /* tp_descr_set */ 1543 0, /* tp_dictoffset */ 1544 0, /* tp_init */ 1545 0, /* tp_alloc */ 1546 pjsip_cred_info_new, /* tp_new */ 1435 1547 1436 1548 }; … … 1630 1742 pjsip_cred_info_Object *src; 1631 1743 pjsip_cred_info_Object *dest; 1744 pjsip_cred_info s; 1745 pjsip_cred_info d; 1632 1746 if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) 1633 1747 { 1634 1748 return NULL; 1635 1749 } 1636 pjsip_cred_dup(pool->pool, dest->cred, src->cred); 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); 1637 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; 1638 1791 return Py_None; 1639 1792 } … … 2064 2217 "msg_data: Message data to be initialized."; 2065 2218 2219 /* END OF LIB BASE */ 2220 2221 /* LIB TRANSPORT */ 2222 2223 /* 2224 * stun_config_Object 2225 * STUN configuration 2226 */ 2227 typedef struct 2228 { 2229 PyObject_HEAD 2230 /* Type-specific fields go here. */ 2231 PyObject * stun_srv1; 2232 unsigned stun_port1; 2233 PyObject * stun_srv2; 2234 unsigned stun_port2; 2235 } stun_config_Object; 2236 2237 2238 /* 2239 * stun_config_dealloc 2240 * deletes a stun config from memory 2241 */ 2242 static void stun_config_dealloc(stun_config_Object* self) 2243 { 2244 Py_XDECREF(self->stun_srv1); 2245 Py_XDECREF(self->stun_srv2); 2246 self->ob_type->tp_free((PyObject*)self); 2247 } 2248 2249 2250 /* 2251 * stun_config_new 2252 * constructor for stun_config object 2253 */ 2254 static PyObject * stun_config_new(PyTypeObject *type, PyObject *args, 2255 PyObject *kwds) 2256 { 2257 stun_config_Object *self; 2258 self = (stun_config_Object *)type->tp_alloc(type, 0); 2259 if (self != NULL) 2260 { 2261 self->stun_srv1 = PyString_FromString(""); 2262 if (self->stun_srv1 == NULL) 2263 { 2264 Py_DECREF(self); 2265 return NULL; 2266 } 2267 self->stun_srv2 = PyString_FromString(""); 2268 if (self->stun_srv2 == NULL) 2269 { 2270 Py_DECREF(self); 2271 return NULL; 2272 } 2273 } 2274 2275 return (PyObject *)self; 2276 } 2277 2278 2279 /* 2280 * stun_config_members 2281 */ 2282 static PyMemberDef stun_config_members[] = 2283 { 2284 { 2285 "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0, 2286 "The first STUN server IP address or hostname." 2287 }, 2288 { 2289 "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0, 2290 "Port number of the second STUN server. " 2291 "If zero, default STUN port will be used." 2292 }, 2293 { 2294 "stun_srv1", T_OBJECT_EX, 2295 offsetof(stun_config_Object, stun_srv1), 0, 2296 "The first STUN server IP address or hostname" 2297 }, 2298 { 2299 "stun_srv2", T_OBJECT_EX, 2300 offsetof(stun_config_Object, stun_srv2), 0, 2301 "Optional second STUN server IP address or hostname, for which the " 2302 "result of the mapping request will be compared to. If the value " 2303 "is empty, only one STUN server will be used" 2304 }, 2305 {NULL} /* Sentinel */ 2306 }; 2307 2308 2309 2310 2311 /* 2312 * stun_config_Type 2313 */ 2314 static PyTypeObject stun_config_Type = 2315 { 2316 PyObject_HEAD_INIT(NULL) 2317 0, /*ob_size*/ 2318 "py_pjsua.STUN_Config", /*tp_name*/ 2319 sizeof(stun_config_Object), /*tp_basicsize*/ 2320 0, /*tp_itemsize*/ 2321 (destructor)stun_config_dealloc,/*tp_dealloc*/ 2322 0, /*tp_print*/ 2323 0, /*tp_getattr*/ 2324 0, /*tp_setattr*/ 2325 0, /*tp_compare*/ 2326 0, /*tp_repr*/ 2327 0, /*tp_as_number*/ 2328 0, /*tp_as_sequence*/ 2329 0, /*tp_as_mapping*/ 2330 0, /*tp_hash */ 2331 0, /*tp_call*/ 2332 0, /*tp_str*/ 2333 0, /*tp_getattro*/ 2334 0, /*tp_setattro*/ 2335 0, /*tp_as_buffer*/ 2336 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2337 "STUN Config objects", /* tp_doc */ 2338 0, /* tp_traverse */ 2339 0, /* tp_clear */ 2340 0, /* tp_richcompare */ 2341 0, /* tp_weaklistoffset */ 2342 0, /* tp_iter */ 2343 0, /* tp_iternext */ 2344 0, /* tp_methods */ 2345 stun_config_members, /* tp_members */ 2346 0, /* tp_getset */ 2347 0, /* tp_base */ 2348 0, /* tp_dict */ 2349 0, /* tp_descr_get */ 2350 0, /* tp_descr_set */ 2351 0, /* tp_dictoffset */ 2352 0, /* tp_init */ 2353 0, /* tp_alloc */ 2354 stun_config_new, /* tp_new */ 2355 2356 }; 2357 2358 /* 2359 * transport_config_Object 2360 * Transport configuration for creating UDP transports for both SIP 2361 * and media. 2362 */ 2363 typedef struct 2364 { 2365 PyObject_HEAD 2366 /* Type-specific fields go here. */ 2367 unsigned port; 2368 PyObject * public_addr; 2369 PyObject * bound_addr; 2370 int use_stun; 2371 stun_config_Object * stun_config; 2372 } transport_config_Object; 2373 2374 2375 /* 2376 * transport_config_dealloc 2377 * deletes a transport config from memory 2378 */ 2379 static void transport_config_dealloc(transport_config_Object* self) 2380 { 2381 Py_XDECREF(self->public_addr); 2382 Py_XDECREF(self->bound_addr); 2383 Py_XDECREF(self->stun_config); 2384 self->ob_type->tp_free((PyObject*)self); 2385 } 2386 2387 2388 /* 2389 * transport_config_new 2390 * constructor for transport_config object 2391 */ 2392 static PyObject * transport_config_new(PyTypeObject *type, PyObject *args, 2393 PyObject *kwds) 2394 { 2395 transport_config_Object *self; 2396 2397 self = (transport_config_Object *)type->tp_alloc(type, 0); 2398 if (self != NULL) 2399 { 2400 self->public_addr = PyString_FromString(""); 2401 if (self->public_addr == NULL) 2402 { 2403 Py_DECREF(self); 2404 return NULL; 2405 } 2406 self->bound_addr = PyString_FromString(""); 2407 if (self->bound_addr == NULL) 2408 { 2409 Py_DECREF(self); 2410 return NULL; 2411 } 2412 self->stun_config = 2413 (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL); 2414 if (self->stun_config == NULL) 2415 { 2416 Py_DECREF(self); 2417 return NULL; 2418 } 2419 2420 } 2421 2422 return (PyObject *)self; 2423 } 2424 2425 2426 /* 2427 * transport_config_members 2428 */ 2429 static PyMemberDef transport_config_members[] = 2430 { 2431 { 2432 "port", T_INT, offsetof(transport_config_Object, port), 0, 2433 "UDP port number to bind locally. This setting MUST be specified " 2434 "even when default port is desired. If the value is zero, the " 2435 "transport will be bound to any available port, and application " 2436 "can query the port by querying the transport info." 2437 }, 2438 { 2439 "public_addr", T_OBJECT_EX, 2440 offsetof(transport_config_Object, public_addr), 0, 2441 "Optional address to advertise as the address of this transport. " 2442 "Application can specify any address or hostname for this field, " 2443 "for example it can point to one of the interface address in the " 2444 "system, or it can point to the public address of a NAT router " 2445 "where port mappings have been configured for the application." 2446 }, 2447 { 2448 "bound_addr", T_OBJECT_EX, 2449 offsetof(transport_config_Object, bound_addr), 0, 2450 "Optional address where the socket should be bound to. This option " 2451 "SHOULD only be used to selectively bind the socket to particular " 2452 "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the " 2453 "published address of a transport (the public_addr field should be " 2454 "used for that purpose)." 2455 }, 2456 { 2457 "use_stun", T_INT, 2458 offsetof(transport_config_Object, use_stun), 0, 2459 "Flag to indicate whether STUN should be used." 2460 }, 2461 { 2462 "stun_config", T_OBJECT_EX, 2463 offsetof(transport_config_Object, stun_config), 0, 2464 "STUN configuration, must be specified when STUN is used." 2465 }, 2466 {NULL} /* Sentinel */ 2467 }; 2468 2469 2470 2471 2472 /* 2473 * transport_config_Type 2474 */ 2475 static PyTypeObject transport_config_Type = 2476 { 2477 PyObject_HEAD_INIT(NULL) 2478 0, /*ob_size*/ 2479 "py_pjsua.Transport_Config", /*tp_name*/ 2480 sizeof(transport_config_Object), /*tp_basicsize*/ 2481 0, /*tp_itemsize*/ 2482 (destructor)transport_config_dealloc,/*tp_dealloc*/ 2483 0, /*tp_print*/ 2484 0, /*tp_getattr*/ 2485 0, /*tp_setattr*/ 2486 0, /*tp_compare*/ 2487 0, /*tp_repr*/ 2488 0, /*tp_as_number*/ 2489 0, /*tp_as_sequence*/ 2490 0, /*tp_as_mapping*/ 2491 0, /*tp_hash */ 2492 0, /*tp_call*/ 2493 0, /*tp_str*/ 2494 0, /*tp_getattro*/ 2495 0, /*tp_setattro*/ 2496 0, /*tp_as_buffer*/ 2497 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2498 "Transport Config objects", /* tp_doc */ 2499 0, /* tp_traverse */ 2500 0, /* tp_clear */ 2501 0, /* tp_richcompare */ 2502 0, /* tp_weaklistoffset */ 2503 0, /* tp_iter */ 2504 0, /* tp_iternext */ 2505 0, /* tp_methods */ 2506 transport_config_members, /* tp_members */ 2507 0, /* tp_getset */ 2508 0, /* tp_base */ 2509 0, /* tp_dict */ 2510 0, /* tp_descr_get */ 2511 0, /* tp_descr_set */ 2512 0, /* tp_dictoffset */ 2513 0, /* tp_init */ 2514 0, /* tp_alloc */ 2515 transport_config_new, /* tp_new */ 2516 2517 }; 2518 2519 /* 2520 * sockaddr_Object 2521 * C/Python wrapper for sockaddr object 2522 */ 2523 typedef struct 2524 { 2525 PyObject_HEAD 2526 /* Type-specific fields go here. */ 2527 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 2528 pj_uint8_t sa_zero_len; 2529 pj_uint8_t sa_family; 2530 #else 2531 pj_uint16_t sa_family; /**< Common data: address family. */ 2532 #endif 2533 PyObject * sa_data; /**< Address data. */ 2534 } sockaddr_Object; 2535 2536 /* 2537 * sockaddr_dealloc 2538 * deletes a sockaddr from memory 2539 */ 2540 static void sockaddr_dealloc(sockaddr_Object* self) 2541 { 2542 Py_XDECREF(self->sa_data); 2543 self->ob_type->tp_free((PyObject*)self); 2544 } 2545 2546 2547 /* 2548 * sockaddr_new 2549 * constructor for sockaddr object 2550 */ 2551 static PyObject * sockaddr_new(PyTypeObject *type, PyObject *args, 2552 PyObject *kwds) 2553 { 2554 sockaddr_Object *self; 2555 2556 self = (sockaddr_Object *)type->tp_alloc(type, 0); 2557 if (self != NULL) 2558 { 2559 self->sa_data = PyString_FromString(""); 2560 if (self->sa_data == NULL) 2561 { 2562 Py_DECREF(self); 2563 return NULL; 2564 } 2565 2566 } 2567 2568 return (PyObject *)self; 2569 } 2570 2571 2572 /* 2573 * sockaddr_members 2574 * declares attributes accessible from both C and Python for sockaddr object 2575 */ 2576 static PyMemberDef sockaddr_members[] = 2577 { 2578 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 2579 { 2580 "sa_zero_len", T_INT, offsetof(sockaddr_Object, sa_zero_len), 0, 2581 "" 2582 }, 2583 { 2584 "sa_family", T_INT, 2585 offsetof(sockaddr_Object, sa_family), 0, 2586 "Common data: address family." 2587 }, 2588 #else 2589 { 2590 "sa_family", T_INT, 2591 offsetof(sockaddr_Object, sa_family), 0, 2592 "Common data: address family." 2593 }, 2594 #endif 2595 { 2596 "sa_data", T_OBJECT_EX, 2597 offsetof(sockaddr_Object, sa_data), 0, 2598 "Address data" 2599 }, 2600 {NULL} /* Sentinel */ 2601 }; 2602 2603 2604 /* 2605 * sockaddr_Type 2606 */ 2607 static PyTypeObject sockaddr_Type = 2608 { 2609 PyObject_HEAD_INIT(NULL) 2610 0, /*ob_size*/ 2611 "py_pjsua.Sockaddr", /*tp_name*/ 2612 sizeof(sockaddr_Object), /*tp_basicsize*/ 2613 0, /*tp_itemsize*/ 2614 (destructor)sockaddr_dealloc,/*tp_dealloc*/ 2615 0, /*tp_print*/ 2616 0, /*tp_getattr*/ 2617 0, /*tp_setattr*/ 2618 0, /*tp_compare*/ 2619 0, /*tp_repr*/ 2620 0, /*tp_as_number*/ 2621 0, /*tp_as_sequence*/ 2622 0, /*tp_as_mapping*/ 2623 0, /*tp_hash */ 2624 0, /*tp_call*/ 2625 0, /*tp_str*/ 2626 0, /*tp_getattro*/ 2627 0, /*tp_setattro*/ 2628 0, /*tp_as_buffer*/ 2629 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2630 "Sockaddr objects", /*tp_doc*/ 2631 0, /*tp_traverse*/ 2632 0, /*tp_clear*/ 2633 0, /*tp_richcompare*/ 2634 0, /* tp_weaklistoffset */ 2635 0, /* tp_iter */ 2636 0, /* tp_iternext */ 2637 0, /* tp_methods */ 2638 sockaddr_members, /* tp_members */ 2639 0, /* tp_getset */ 2640 0, /* tp_base */ 2641 0, /* tp_dict */ 2642 0, /* tp_descr_get */ 2643 0, /* tp_descr_set */ 2644 0, /* tp_dictoffset */ 2645 0, /* tp_init */ 2646 0, /* tp_alloc */ 2647 sockaddr_new, /* tp_new */ 2648 }; 2649 2650 /* 2651 * host_port_Object 2652 * C/Python wrapper for host_port object 2653 */ 2654 typedef struct 2655 { 2656 PyObject_HEAD 2657 /* Type-specific fields go here. */ 2658 PyObject * host; 2659 int port; 2660 } host_port_Object; 2661 2662 /* 2663 * host_port_dealloc 2664 * deletes a host_port from memory 2665 */ 2666 static void host_port_dealloc(host_port_Object* self) 2667 { 2668 Py_XDECREF(self->host); 2669 self->ob_type->tp_free((PyObject*)self); 2670 } 2671 2672 2673 /* 2674 * host_port_new 2675 * constructor for host_port object 2676 */ 2677 static PyObject * host_port_new(PyTypeObject *type, PyObject *args, 2678 PyObject *kwds) 2679 { 2680 host_port_Object *self; 2681 2682 self = (host_port_Object *)type->tp_alloc(type, 0); 2683 if (self != NULL) 2684 { 2685 self->host = PyString_FromString(""); 2686 if (self->host == NULL) 2687 { 2688 Py_DECREF(self); 2689 return NULL; 2690 } 2691 2692 } 2693 2694 return (PyObject *)self; 2695 } 2696 2697 2698 /* 2699 * host_port_members 2700 * declares attributes accessible from both C and Python for host_port object 2701 */ 2702 static PyMemberDef host_port_members[] = 2703 { 2704 { 2705 "port", T_INT, 2706 offsetof(host_port_Object, port), 0, 2707 "Port number." 2708 }, 2709 { 2710 "host", T_OBJECT_EX, 2711 offsetof(host_port_Object, host), 0, 2712 "Host part or IP address." 2713 }, 2714 {NULL} /* Sentinel */ 2715 }; 2716 2717 2718 /* 2719 * host_port_Type 2720 */ 2721 static PyTypeObject host_port_Type = 2722 { 2723 PyObject_HEAD_INIT(NULL) 2724 0, /*ob_size*/ 2725 "py_pjsua.Host_Port", /*tp_name*/ 2726 sizeof(host_port_Object), /*tp_basicsize*/ 2727 0, /*tp_itemsize*/ 2728 (destructor)host_port_dealloc,/*tp_dealloc*/ 2729 0, /*tp_print*/ 2730 0, /*tp_getattr*/ 2731 0, /*tp_setattr*/ 2732 0, /*tp_compare*/ 2733 0, /*tp_repr*/ 2734 0, /*tp_as_number*/ 2735 0, /*tp_as_sequence*/ 2736 0, /*tp_as_mapping*/ 2737 0, /*tp_hash */ 2738 0, /*tp_call*/ 2739 0, /*tp_str*/ 2740 0, /*tp_getattro*/ 2741 0, /*tp_setattro*/ 2742 0, /*tp_as_buffer*/ 2743 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 2744 "Host_port objects", /*tp_doc*/ 2745 0, /*tp_traverse*/ 2746 0, /*tp_clear*/ 2747 0, /*tp_richcompare*/ 2748 0, /* tp_weaklistoffset */ 2749 0, /* tp_iter */ 2750 0, /* tp_iternext */ 2751 0, /* tp_methods */ 2752 host_port_members, /* tp_members */ 2753 0, /* tp_getset */ 2754 0, /* tp_base */ 2755 0, /* tp_dict */ 2756 0, /* tp_descr_get */ 2757 0, /* tp_descr_set */ 2758 0, /* tp_dictoffset */ 2759 0, /* tp_init */ 2760 0, /* tp_alloc */ 2761 host_port_new, /* tp_new */ 2762 }; 2763 2764 /* 2765 * transport_id_Object 2766 * C/Python wrapper for transport_id object 2767 */ 2768 typedef struct 2769 { 2770 PyObject_HEAD 2771 /* 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; 2911 } transport_info_Object; 2912 2913 2914 /* 2915 * transport_info_dealloc 2916 * deletes a transport info from memory 2917 */ 2918 static void transport_info_dealloc(transport_info_Object* self) 2919 { 2920 Py_XDECREF(self->type_name); 2921 Py_XDECREF(self->info); 2922 Py_XDECREF(self->local_addr); 2923 Py_XDECREF(self->local_name); 2924 self->ob_type->tp_free((PyObject*)self); 2925 } 2926 2927 2928 /* 2929 * transport_info_new 2930 * constructor for transport_info object 2931 */ 2932 static PyObject * transport_info_new(PyTypeObject *type, PyObject *args, 2933 PyObject *kwds) 2934 { 2935 transport_info_Object *self; 2936 2937 self = (transport_info_Object *)type->tp_alloc(type, 0); 2938 if (self != NULL) 2939 { 2940 self->type_name = PyString_FromString(""); 2941 if (self->type_name == NULL) 2942 { 2943 Py_DECREF(self); 2944 return NULL; 2945 } 2946 self->info = PyString_FromString(""); 2947 if (self->info == NULL) 2948 { 2949 Py_DECREF(self); 2950 return NULL; 2951 } 2952 self->local_addr = 2953 (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL); 2954 if (self->local_addr == NULL) 2955 { 2956 Py_DECREF(self); 2957 return NULL; 2958 } 2959 self->local_name = 2960 (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL); 2961 if (self->local_name == NULL) 2962 { 2963 Py_DECREF(self); 2964 return NULL; 2965 } 2966 } 2967 2968 return (PyObject *)self; 2969 } 2970 2971 2972 /* 2973 * transport_info_members 2974 */ 2975 static PyMemberDef transport_info_members[] = 2976 { 2977 { 2978 "id", T_INT, offsetof(transport_info_Object, id), 0, 2979 "PJSUA transport identification." 2980 }, 2981 { 2982 "type", T_INT, offsetof(transport_info_Object, id), 0, 2983 "Transport type." 2984 }, 2985 { 2986 "type_name", T_OBJECT_EX, 2987 offsetof(transport_info_Object, type_name), 0, 2988 "Transport type name." 2989 }, 2990 { 2991 "info", T_OBJECT_EX, 2992 offsetof(transport_info_Object, info), 0, 2993 "Transport string info/description." 2994 }, 2995 { 2996 "flag", T_INT, offsetof(transport_info_Object, flag), 0, 2997 "Transport flag (see ##pjsip_transport_flags_e)." 2998 }, 2999 { 3000 "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0, 3001 "Local address length." 3002 }, 3003 { 3004 "local_addr", T_OBJECT_EX, 3005 offsetof(transport_info_Object, local_addr), 0, 3006 "Local/bound address." 3007 }, 3008 { 3009 "local_name", T_OBJECT_EX, 3010 offsetof(transport_info_Object, local_name), 0, 3011 "Published address (or transport address name)." 3012 }, 3013 { 3014 "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0, 3015 "Current number of objects currently referencing this transport." 3016 }, 3017 {NULL} /* Sentinel */ 3018 }; 3019 3020 3021 3022 3023 /* 3024 * transport_info_Type 3025 */ 3026 static PyTypeObject transport_info_Type = 3027 { 3028 PyObject_HEAD_INIT(NULL) 3029 0, /*ob_size*/ 3030 "py_pjsua.Transport_Info", /*tp_name*/ 3031 sizeof(transport_info_Object), /*tp_basicsize*/ 3032 0, /*tp_itemsize*/ 3033 (destructor)transport_info_dealloc,/*tp_dealloc*/ 3034 0, /*tp_print*/ 3035 0, /*tp_getattr*/ 3036 0, /*tp_setattr*/ 3037 0, /*tp_compare*/ 3038 0, /*tp_repr*/ 3039 0, /*tp_as_number*/ 3040 0, /*tp_as_sequence*/ 3041 0, /*tp_as_mapping*/ 3042 0, /*tp_hash */ 3043 0, /*tp_call*/ 3044 0, /*tp_str*/ 3045 0, /*tp_getattro*/ 3046 0, /*tp_setattro*/ 3047 0, /*tp_as_buffer*/ 3048 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3049 "Transport Info objects", /* tp_doc */ 3050 0, /* tp_traverse */ 3051 0, /* tp_clear */ 3052 0, /* tp_richcompare */ 3053 0, /* tp_weaklistoffset */ 3054 0, /* tp_iter */ 3055 0, /* tp_iternext */ 3056 0, /* tp_methods */ 3057 transport_info_members, /* tp_members */ 3058 0, /* tp_getset */ 3059 0, /* tp_base */ 3060 0, /* tp_dict */ 3061 0, /* tp_descr_get */ 3062 0, /* tp_descr_set */ 3063 0, /* tp_dictoffset */ 3064 0, /* tp_init */ 3065 0, /* tp_alloc */ 3066 transport_info_new, /* tp_new */ 3067 3068 }; 3069 3070 /* 3071 * pjsip_transport_Object 3072 * C/python typewrapper for pjsip_transport 3073 */ 3074 typedef struct 3075 { 3076 PyObject_HEAD 3077 /* Type-specific fields go here. */ 3078 pjsip_transport *tp; 3079 } pjsip_transport_Object; 3080 3081 3082 /* 3083 * pjsip_transport_Type 3084 */ 3085 static PyTypeObject pjsip_transport_Type = 3086 { 3087 PyObject_HEAD_INIT(NULL) 3088 0, /*ob_size*/ 3089 "py_pjsua.PJSIP_Transport", /*tp_name*/ 3090 sizeof(pjsip_transport_Object), /*tp_basicsize*/ 3091 0, /*tp_itemsize*/ 3092 0, /*tp_dealloc*/ 3093 0, /*tp_print*/ 3094 0, /*tp_getattr*/ 3095 0, /*tp_setattr*/ 3096 0, /*tp_compare*/ 3097 0, /*tp_repr*/ 3098 0, /*tp_as_number*/ 3099 0, /*tp_as_sequence*/ 3100 0, /*tp_as_mapping*/ 3101 0, /*tp_hash */ 3102 0, /*tp_call*/ 3103 0, /*tp_str*/ 3104 0, /*tp_getattro*/ 3105 0, /*tp_setattro*/ 3106 0, /*tp_as_buffer*/ 3107 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3108 "pjsip_transport objects", /*tp_doc*/ 3109 }; 3110 3111 3112 /* 3113 * py_pjsua_stun_config_default 3114 */ 3115 static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs) 3116 { 3117 stun_config_Object *obj; 3118 pjsua_stun_config cfg; 3119 3120 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 3121 { 3122 return NULL; 3123 } 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); 3128 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); 3133 Py_INCREF(Py_None); 3134 return Py_None; 3135 } 3136 3137 /* 3138 * py_pjsua_transport_config_default 3139 */ 3140 static PyObject *py_pjsua_transport_config_default 3141 (PyObject *pSelf, PyObject *pArgs) 3142 { 3143 transport_config_Object *obj; 3144 pjsua_transport_config cfg; 3145 3146 if (!PyArg_ParseTuple(pArgs, "O", &obj)) 3147 { 3148 return NULL; 3149 } 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) 3299 { 3300 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) 3356 { 3357 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)) 3363 { 3364 return NULL; 3365 } 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 } 3412 #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; 3415 #else 3416 info.local_addr.sa_family = obj->local_addr->sa_family; 3417 #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); 3432 } 3433 3434 /* 3435 * py_pjsua_transport_set_enable 3436 */ 3437 static PyObject *py_pjsua_transport_set_enable 3438 (PyObject *pSelf, PyObject *pArgs) 3439 { 3440 pj_status_t status; 3441 int id; 3442 int enabled; 3443 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) 3444 { 3445 return NULL; 3446 } 3447 status = pjsua_transport_set_enable(id, enabled); 3448 //printf("status %d\n",status); 3449 return Py_BuildValue("i",status); 3450 } 3451 3452 /* 3453 * py_pjsua_transport_close 3454 */ 3455 static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs) 3456 { 3457 pj_status_t status; 3458 int id; 3459 int force; 3460 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) 3461 { 3462 return NULL; 3463 } 3464 status = pjsua_transport_close(id, force); 3465 //printf("status %d\n",status); 3466 return Py_BuildValue("i",status); 3467 } 3468 3469 static char pjsua_stun_config_default_doc[] = 3470 "void py_pjsua.stun_config_default (py_pjsua.STUN_Config cfg) " 3471 "Call this function to initialize STUN config with default values."; 3472 static char pjsua_transport_config_default_doc[] = 3473 "void py_pjsua.transport_config_default (py_pjsua.Transport_Config cfg) " 3474 "Call this function to initialize UDP config with default values."; 3475 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. "; 3482 static char pjsua_transport_create_doc[] = 3483 "void py_pjsua.transport_create (int type, " 3484 "py_pjsua.Transport_Config cfg, py_pjsua.Transport_ID p_id) " 3485 "Create SIP transport."; 3486 static char pjsua_transport_register_doc[] = 3487 "void py_pjsua.transport_register " 3488 "(py_pjsua.PJSIP_Transport tp, py_pjsua.Transport_ID p_id) " 3489 "Register transport that has been created by application."; 3490 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."; 3494 static char pjsua_transport_get_info_doc[] = 3495 "void py_pjsua.transport_get_info " 3496 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) " 3497 "Get information about transports."; 3498 static char pjsua_transport_set_enable_doc[] = 3499 "void py_pjsua.transport_set_enable " 3500 "(py_pjsua.Transport_ID id, int enabled) " 3501 "Disable a transport or re-enable it. " 3502 "By default transport is always enabled after it is created. " 3503 "Disabling a transport does not necessarily close the socket, " 3504 "it will only discard incoming messages and prevent the transport " 3505 "from being used to send outgoing messages."; 3506 static char pjsua_transport_close_doc[] = 3507 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) " 3508 "Close the transport. If transport is forcefully closed, " 3509 "it will be immediately closed, and any pending transactions " 3510 "that are using the transport may not terminate properly. " 3511 "Otherwise, the system will wait until all transactions are closed " 3512 "while preventing new users from using the transport, and will close " 3513 "the transport when it is safe to do so."; 3514 3515 /* END OF LIB TRANSPORT */ 3516 3517 /* LIB ACCOUNT */ 3518 3519 /* 3520 * acc_config_Object 3521 * Acc Config 3522 */ 3523 typedef struct 3524 { 3525 PyObject_HEAD 3526 /* 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]; 3537 } acc_config_Object; 3538 3539 3540 /* 3541 * acc_config_dealloc 3542 * deletes a acc_config from memory 3543 */ 3544 static void acc_config_dealloc(acc_config_Object* self) 3545 { 3546 Py_XDECREF(self->id); 3547 Py_XDECREF(self->reg_uri); 3548 Py_XDECREF(self->force_contact); 3549 self->ob_type->tp_free((PyObject*)self); 3550 } 3551 3552 3553 /* 3554 * acc_config_new 3555 * constructor for acc_config object 3556 */ 3557 static PyObject * acc_config_new(PyTypeObject *type, PyObject *args, 3558 PyObject *kwds) 3559 { 3560 acc_config_Object *self; 3561 3562 self = (acc_config_Object *)type->tp_alloc(type, 0); 3563 if (self != NULL) 3564 { 3565 self->id = PyString_FromString(""); 3566 if (self->id == NULL) 3567 { 3568 Py_DECREF(self); 3569 return NULL; 3570 } 3571 self->reg_uri = PyString_FromString(""); 3572 if (self->reg_uri == NULL) 3573 { 3574 Py_DECREF(self); 3575 return NULL; 3576 } 3577 self->force_contact = PyString_FromString(""); 3578 if (self->force_contact == NULL) 3579 { 3580 Py_DECREF(self); 3581 return NULL; 3582 } 3583 } 3584 3585 return (PyObject *)self; 3586 } 3587 3588 static PyObject * acc_config_get_proxy 3589 (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 else 3602 { 3603 return NULL; 3604 } 3605 return PyString_FromStringAndSize(elmt.ptr, elmt.slen); 3606 } 3607 3608 static PyObject * acc_config_set_proxy 3609 (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 else 3623 { 3624 return NULL; 3625 } 3626 Py_INCREF(Py_None); 3627 return Py_None; 3628 } 3629 static PyObject * acc_config_get_cred_info 3630 (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 else 3644 { 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_info 3660 (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 else 3683 { 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 3711 3712 /* 3713 * acc_config_members 3714 */ 3715 static PyMemberDef acc_config_members[] = 3716 { 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. " 3765 }, 3766 {NULL} /* Sentinel */ 3767 }; 3768 3769 3770 3771 3772 /* 3773 * acc_config_Type 3774 */ 3775 static PyTypeObject acc_config_Type = 3776 { 3777 PyObject_HEAD_INIT(NULL) 3778 0, /*ob_size*/ 3779 "py_pjsua.Acc_Config", /*tp_name*/ 3780 sizeof(acc_config_Object), /*tp_basicsize*/ 3781 0, /*tp_itemsize*/ 3782 (destructor)acc_config_dealloc,/*tp_dealloc*/ 3783 0, /*tp_print*/ 3784 0, /*tp_getattr*/ 3785 0, /*tp_setattr*/ 3786 0, /*tp_compare*/ 3787 0, /*tp_repr*/ 3788 0, /*tp_as_number*/ 3789 0, /*tp_as_sequence*/ 3790 0, /*tp_as_mapping*/ 3791 0, /*tp_hash */ 3792 0, /*tp_call*/ 3793 0, /*tp_str*/ 3794 0, /*tp_getattro*/ 3795 0, /*tp_setattro*/ 3796 0, /*tp_as_buffer*/ 3797 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 3798 "Acc Config objects", /* tp_doc */ 3799 0, /* tp_traverse */ 3800 0, /* tp_clear */ 3801 0, /* tp_richcompare */ 3802 0, /* tp_weaklistoffset */ 3803 0, /* tp_iter */ 3804 0, /* tp_iternext */ 3805 acc_config_methods, /* tp_methods */ 3806 acc_config_members, /* tp_members */ 3807 0, /* tp_getset */ 3808 0, /* tp_base */ 3809 0, /* tp_dict */ 3810 0, /* tp_descr_get */ 3811 0, /* tp_descr_set */ 3812 0, /* tp_dictoffset */ 3813 0, /* tp_init */ 3814 0, /* tp_alloc */ 3815 acc_config_new, /* tp_new */ 3816 3817 }; 3818 3819 /* 3820 * acc_info_Object 3821 * Acc Info 3822 */ 3823 typedef struct 3824 { 3825 PyObject_HEAD 3826 /* Type-specific fields go here. */ 3827 int id; 3828 int is_default; 3829 PyObject * acc_uri; 3830 int has_registration; 3831 int expires; 3832 int status; 3833 PyObject * status_text; 3834 int online_status; 3835 char buf_[PJ_ERR_MSG_SIZE]; 3836 } acc_info_Object; 3837 3838 3839 /* 3840 * acc_info_dealloc 3841 * deletes a acc_info from memory 3842 */ 3843 static void acc_info_dealloc(acc_info_Object* self) 3844 { 3845 Py_XDECREF(self->acc_uri); 3846 Py_XDECREF(self->status_text); 3847 self->ob_type->tp_free((PyObject*)self); 3848 } 3849 3850 3851 /* 3852 * acc_info_new 3853 * constructor for acc_info object 3854 */ 3855 static PyObject * acc_info_new(PyTypeObject *type, PyObject *args, 3856 PyObject *kwds) 3857 { 3858 acc_info_Object *self; 3859 3860 self = (acc_info_Object *)type->tp_alloc(type, 0); 3861 if (self != NULL) 3862 { 3863 self->acc_uri = PyString_FromString(""); 3864 if (self->acc_uri == NULL) 3865 { 3866 Py_DECREF(self); 3867 return NULL; 3868 } 3869 self->status_text = PyString_FromString(""); 3870 if (self->status_text == NULL) 3871 { 3872 Py_DECREF(self); 3873 return NULL; 3874 } 3875 3876 } 3877 3878 return (PyObject *)self; 3879 } 3880 3881 static PyObject * acc_info_get_buf 3882 (acc_info_Object *self, PyObject * args) 3883 { 3884 int idx; 3885 char elmt; 3886 if (!PyArg_ParseTuple(args,"i",&idx)) 3887 { 3888 return NULL; 3889 } 3890 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) 3891 { 3892 elmt = self->buf_[idx]; 3893 } 3894 else 3895 { 3896 return NULL; 3897 } 3898 return PyString_FromStringAndSize(&elmt, 1); 3899 } 3900 3901 static PyObject * acc_info_set_buf 3902 (acc_info_Object *self, PyObject * args) 3903 { 3904 int idx; 3905 PyObject * str; 3906 char * s; 3907 if (!PyArg_ParseTuple(args,"iO",&idx, &str)) 3908 { 3909 return NULL; 3910 } 3911 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) 3912 { 3913 s = PyString_AsString(str); 3914 if (s[0]) 3915 { 3916 self->buf_[idx] = s[0]; 3917 } 3918 else 3919 { 3920 return NULL; 3921 } 3922 } 3923 else 3924 { 3925 return NULL; 3926 } 3927 Py_INCREF(Py_None); 3928 return Py_None; 3929 } 3930 3931 static PyMethodDef acc_info_methods[] = { 3932 { 3933 "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS, 3934 "Return buf char at specified index" 3935 }, 3936 { 3937 "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS, 3938 "Set buf at specified index" 3939 }, 3940 3941 {NULL} /* Sentinel */ 3942 }; 3943 3944 3945 3946 /* 3947 * acc_info_members 3948 */ 3949 static PyMemberDef acc_info_members[] = 3950 { 3951 { 3952 "id", T_INT, offsetof(acc_info_Object, id), 0, 3953 "The account ID." 3954 }, 3955 { 3956 "is_default", T_INT, offsetof(acc_info_Object, is_default), 0, 3957 "Flag to indicate whether this is the default account. " 3958 }, 3959 { 3960 "acc_uri", T_OBJECT_EX, 3961 offsetof(acc_info_Object, acc_uri), 0, 3962 "Account URI" 3963 }, 3964 { 3965 "has_registration", T_INT, offsetof(acc_info_Object, has_registration), 3966 0, 3967 "Flag to tell whether this account has registration setting " 3968 "(reg_uri is not empty)." 3969 }, 3970 { 3971 "expires", T_INT, offsetof(acc_info_Object, expires), 0, 3972 "An up to date expiration interval for account registration session." 3973 }, 3974 { 3975 "status", T_INT, offsetof(acc_info_Object, status), 0, 3976 "Last registration status code. If status code is zero, " 3977 "the account is currently not registered. Any other value indicates " 3978 "the SIP status code of the registration. " 3979 }, 3980 { 3981 "status_text", T_OBJECT_EX, 3982 offsetof(acc_info_Object, status_text), 0, 3983 "String describing the registration status." 3984 }, 3985 { 3986 "online_status", T_INT, offsetof(acc_info_Object, online_status), 0, 3987 "Presence online status for this account. " 3988 }, 3989 {NULL} /* Sentinel */ 3990 }; 3991 3992 3993 3994 3995 /* 3996 * acc_info_Type 3997 */ 3998 static PyTypeObject acc_info_Type = 3999 { 4000 PyObject_HEAD_INIT(NULL) 4001 0, /*ob_size*/ 4002 "py_pjsua.Acc_Info", /*tp_name*/ 4003 sizeof(acc_info_Object), /*tp_basicsize*/ 4004 0, /*tp_itemsize*/ 4005 (destructor)acc_info_dealloc,/*tp_dealloc*/ 4006 0, /*tp_print*/ 4007 0, /*tp_getattr*/ 4008 0, /*tp_setattr*/ 4009 0, /*tp_compare*/ 4010 0, /*tp_repr*/ 4011 0, /*tp_as_number*/ 4012 0, /*tp_as_sequence*/ 4013 0, /*tp_as_mapping*/ 4014 0, /*tp_hash */ 4015 0, /*tp_call*/ 4016 0, /*tp_str*/ 4017 0, /*tp_getattro*/ 4018 0, /*tp_setattro*/ 4019 0, /*tp_as_buffer*/ 4020 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 4021 "Acc Info objects", /* tp_doc */ 4022 0, /* tp_traverse */ 4023 0, /* tp_clear */ 4024 0, /* tp_richcompare */ 4025 0, /* tp_weaklistoffset */ 4026 0, /* tp_iter */ 4027 0, /* tp_iternext */ 4028 acc_info_methods, /* tp_methods */ 4029 acc_info_members, /* tp_members */ 4030 0, /* tp_getset */ 4031 0, /* tp_base */ 4032 0, /* tp_dict */ 4033 0, /* tp_descr_get */ 4034 0, /* tp_descr_set */ 4035 0, /* tp_dictoffset */ 4036 0, /* tp_init */ 4037 0, /* tp_alloc */ 4038 acc_info_new, /* tp_new */ 4039 4040 }; 4041 4042 /* 4043 * acc_id_Object 4044 * C/Python wrapper for acc_id object 4045 */ 4046 typedef struct 4047 { 4048 PyObject_HEAD 4049 /* 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 }, 4065 {NULL} /* Sentinel */ 4066 }; 4067 4068 4069 /* 4070 * acc_id_Type 4071 */ 4072 static PyTypeObject acc_id_Type = 4073 { 4074 PyObject_HEAD_INIT(NULL) 4075 0, /*ob_size*/ 4076 "py_pjsua.Acc_ID", /*tp_name*/ 4077 sizeof(acc_id_Object), /*tp_basicsize*/ 4078 0, /*tp_itemsize*/ 4079 0, /*tp_dealloc*/ 4080 0, /*tp_print*/ 4081 0, /*tp_getattr*/ 4082 0, /*tp_setattr*/ 4083 0, /*tp_compare*/ 4084 0, /*tp_repr*/ 4085 0, /*tp_as_number*/ 4086 0, /*tp_as_sequence*/ 4087 0, /*tp_as_mapping*/ 4088 0, /*tp_hash */ 4089 0, /*tp_call*/ 4090 0, /*tp_str*/ 4091 0, /*tp_getattro*/ 4092 0, /*tp_setattro*/ 4093 0, /*tp_as_buffer*/ 4094 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 4095 "Acc ID objects", /*tp_doc*/ 4096 0, /*tp_traverse*/ 4097 0, /*tp_clear*/ 4098 0, /*tp_richcompare*/ 4099 0, /* tp_weaklistoffset */ 4100 0, /* tp_iter */ 4101 0, /* tp_iternext */ 4102 0, /* tp_methods */ 4103 acc_id_members, /* tp_members */ 4104 4105 }; 4106 4107 /* 4108 * py_pjsua_acc_config_default 4109 */ 4110 static PyObject *py_pjsua_acc_config_default 4111 (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]; 4126 } 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]; 4142 } 4143 obj->publish_enabled = cfg.publish_enabled; 4144 obj->reg_timeout = cfg.reg_timeout; 4145 4146 Py_INCREF(Py_None); 4147 return Py_None; 4148 } 4149 4150 /* 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 4169 (PyObject *pSelf, PyObject *pArgs) 4170 { 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); 4179 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 4187 (PyObject *pSelf, PyObject *pArgs) 4188 { 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); 4197 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); 4457 return Py_BuildValue("i",status); 4458 } 4459 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 */ 4683 2066 4684 2067 4685 /* … … 2070 4688 static PyMethodDef py_pjsua_methods[] = 2071 4689 { 4690 { 4691 "my_parse_by_reference", py_my_parse_by_reference, METH_VARARGS, "" 4692 }, 2072 4693 { 2073 4694 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc … … 2138 4759 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS, 2139 4760 pjsua_msg_data_init_doc 4761 }, 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 2140 4873 }, 2141 4874 {NULL, NULL} /* end of function list */ … … 2185 4918 return; 2186 4919 4920 /* LIB TRANSPORT */ 4921 4922 if (PyType_Ready(&stun_config_Type) < 0) 4923 return; 4924 if (PyType_Ready(&transport_config_Type) < 0) 4925 return; 4926 if (PyType_Ready(&sockaddr_Type) < 0) 4927 return; 4928 if (PyType_Ready(&host_port_Type) < 0) 4929 return; 4930 transport_id_Type.tp_new = PyType_GenericNew; 4931 if (PyType_Ready(&transport_id_Type) < 0) 4932 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; 4939 if (PyType_Ready(&pjsip_transport_Type) < 0) 4940 return; 4941 4942 /* END OF LIB TRANSPORT */ 4943 4944 /* LIB ACCOUNT */ 4945 4946 acc_id_Type.tp_new = PyType_GenericNew; 4947 if (PyType_Ready(&acc_id_Type) < 0) 4948 return; 4949 if (PyType_Ready(&acc_config_Type) < 0) 4950 return; 4951 if (PyType_Ready(&acc_info_Type) < 0) 4952 return; 4953 4954 /* END OF LIB ACCOUNT */ 4955 2187 4956 m = Py_InitModule3( 2188 4957 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python" … … 2229 4998 ); 2230 4999 5000 /* LIB TRANSPORT */ 5001 5002 Py_INCREF(&stun_config_Type); 5003 PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type); 5004 Py_INCREF(&transport_config_Type); 5005 PyModule_AddObject 5006 (m, "Transport_Config", (PyObject *)&transport_config_Type); 5007 Py_INCREF(&sockaddr_Type); 5008 PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type); 5009 Py_INCREF(&host_port_Type); 5010 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); 5014 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); 5018 PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type); 5019 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); 5027 PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type); 5028 Py_INCREF(&acc_info_Type); 5029 PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type); 5030 5031 /* END OF LIB ACCOUNT */ 2231 5032 2232 5033 #ifdef PJSUA_INVALID_ID … … 2245 5046 ); 2246 5047 #endif 2247 } 5048 5049 #ifdef PJSUA_MAX_ACC 5050 /* 5051 * Maximum account. 5052 */ 5053 PyModule_AddIntConstant( 5054 m, "PJSUA_MAX_ACC", PJSUA_MAX_ACC 5055 ); 5056 #endif 5057 5058 #ifdef PJSUA_REG_INTERVAL 5059 /* 5060 * Default registration interval.. 5061 */ 5062 PyModule_AddIntConstant( 5063 m, "PJSUA_REG_INTERVAL", PJSUA_REG_INTERVAL 5064 ); 5065 #endif 5066 5067 #ifdef PJSUA_PUBLISH_EXPIRATION 5068 /* 5069 * Default PUBLISH expiration 5070 */ 5071 PyModule_AddIntConstant( 5072 m, "PJSUA_PUBLISH_EXPIRATION", PJSUA_PUBLISH_EXPIRATION 5073 ); 5074 #endif 5075 5076 #ifdef PJSUA_DEFAULT_ACC_PRIORITY 5077 /* 5078 * Default account priority. 5079 */ 5080 PyModule_AddIntConstant( 5081 m, "PJSUA_DEFAULT_ACC_PRIORITY", PJSUA_DEFAULT_ACC_PRIORITY 5082 ); 5083 #endif 5084 5085 }
Note: See TracChangeset
for help on using the changeset viewer.