blob: 0966d90ec59cf3f4d7f9036df78233c80ee50db0 [file] [log] [blame]
Benny Prijono9c461142008-07-10 22:41:20 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include "_pjsua.h"
20
21#define THIS_FILE "main.c"
Benny Prijono55040452008-07-21 18:20:57 +000022#define POOL_SIZE 512
Benny Prijono9c461142008-07-10 22:41:20 +000023#define SND_DEV_NUM 64
24#define SND_NAME_LEN 64
25
26/* LIB BASE */
27
Benny Prijono55040452008-07-21 18:20:57 +000028static PyObject* g_obj_log_cb;
29static long g_thread_id;
30static struct py_thread_desc
31{
32 struct py_thread_desc *next;
33 pj_thread_desc desc;
34} *py_thread_desc;
Benny Prijono9c461142008-07-10 22:41:20 +000035
Benny Prijono55040452008-07-21 18:20:57 +000036/*
37 * The global callback object.
38 */
39static PyObj_pjsua_callback * g_obj_callback;
40
41/* Set this to 1 if all threads are created by Python */
42#define NO_PJSIP_THREAD 1
43
44#if NO_PJSIP_THREAD
45# define ENTER_PYTHON()
46# define LEAVE_PYTHON()
47#else
48# define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure()
49# define LEAVE_PYTHON() PyGILState_Release(state)
50#endif
51
52
53static void clear_py_thread_desc(void)
54{
55 while (py_thread_desc) {
56 struct py_thread_desc *next = py_thread_desc->next;
57 free(py_thread_desc);
58 py_thread_desc = next;
59 }
60}
61
Benny Prijono9c461142008-07-10 22:41:20 +000062
63/*
64 * cb_log_cb
65 * declares method for reconfiguring logging process for callback struct
66 */
67static void cb_log_cb(int level, const char *data, int len)
68{
69
70 /* Ignore if this callback is called from alien thread context,
71 * or otherwise it will crash Python.
72 */
Benny Prijono55040452008-07-21 18:20:57 +000073 if (pj_thread_local_get(g_thread_id) == 0)
Benny Prijono9c461142008-07-10 22:41:20 +000074 return;
75
Benny Prijono55040452008-07-21 18:20:57 +000076 if (PyCallable_Check(g_obj_log_cb)) {
77 PyObject *param_data;
78
Benny Prijono9c461142008-07-10 22:41:20 +000079 ENTER_PYTHON();
80
Benny Prijono55040452008-07-21 18:20:57 +000081 param_data = PyString_FromStringAndSize(data, len);
82
83 PyObject_CallFunction(
84 g_obj_log_cb,
85 "iOi",
86 level,
87 param_data,
88 len,
89 NULL
Benny Prijono9c461142008-07-10 22:41:20 +000090 );
91
Benny Prijono55040452008-07-21 18:20:57 +000092 Py_DECREF(param_data);
93
Benny Prijono9c461142008-07-10 22:41:20 +000094 LEAVE_PYTHON();
95 }
96}
97
Benny Prijono9c461142008-07-10 22:41:20 +000098/*
99 * cb_on_call_state
100 * declares method on_call_state for callback struct
101 */
102static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
103{
Benny Prijono55040452008-07-21 18:20:57 +0000104 PJ_UNUSED_ARG(e);
105
106 if (PyCallable_Check(g_obj_callback->on_call_state)) {
107 PyObject * obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000108
109 ENTER_PYTHON();
110
Benny Prijono55040452008-07-21 18:20:57 +0000111 obj = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000112
Benny Prijono55040452008-07-21 18:20:57 +0000113 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000114 g_obj_callback->on_call_state,
Benny Prijono55040452008-07-21 18:20:57 +0000115 "iO",
116 call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000117 obj,
118 NULL
119 );
120
Benny Prijono55040452008-07-21 18:20:57 +0000121 Py_DECREF(obj);
122
Benny Prijono9c461142008-07-10 22:41:20 +0000123 LEAVE_PYTHON();
124 }
125}
126
127
128/*
129 * cb_on_incoming_call
130 * declares method on_incoming_call for callback struct
131 */
132static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
133 pjsip_rx_data *rdata)
134{
Benny Prijono55040452008-07-21 18:20:57 +0000135 PJ_UNUSED_ARG(rdata);
136
137 if (PyCallable_Check(g_obj_callback->on_incoming_call)) {
138 PyObject *obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000139
140 ENTER_PYTHON();
141
Benny Prijono55040452008-07-21 18:20:57 +0000142 obj = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000143
Benny Prijono55040452008-07-21 18:20:57 +0000144 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000145 g_obj_callback->on_incoming_call,
Benny Prijono55040452008-07-21 18:20:57 +0000146 "iiO",
147 acc_id,
148 call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000149 obj,
150 NULL
151 );
152
Benny Prijono55040452008-07-21 18:20:57 +0000153 Py_DECREF(obj);
154
Benny Prijono9c461142008-07-10 22:41:20 +0000155 LEAVE_PYTHON();
156 }
157}
158
159
160/*
161 * cb_on_call_media_state
162 * declares method on_call_media_state for callback struct
163 */
164static void cb_on_call_media_state(pjsua_call_id call_id)
165{
Benny Prijono55040452008-07-21 18:20:57 +0000166 if (PyCallable_Check(g_obj_callback->on_call_media_state)) {
167
Benny Prijono9c461142008-07-10 22:41:20 +0000168 ENTER_PYTHON();
169
170 PyObject_CallFunction(
171 g_obj_callback->on_call_media_state,
172 "i",
173 call_id,
174 NULL
175 );
176
177 LEAVE_PYTHON();
178 }
179}
180
181
182/*
183 * cb_on_dtmf_digit()
184 * Callback from PJSUA-LIB on receiving DTMF digit
185 */
186static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
187{
Benny Prijono55040452008-07-21 18:20:57 +0000188 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000189 char digit_str[10];
190
191 ENTER_PYTHON();
192
193 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
194
Benny Prijono55040452008-07-21 18:20:57 +0000195 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000196 g_obj_callback->on_dtmf_digit,
Benny Prijono55040452008-07-21 18:20:57 +0000197 "is",
198 call_id,
199 digit_str,
Benny Prijono9c461142008-07-10 22:41:20 +0000200 NULL
201 );
202
203 LEAVE_PYTHON();
204 }
205}
206
207
208/*
209 * Notify application on call being transfered.
210 * !modified @061206
211 */
212static void cb_on_call_transfer_request(pjsua_call_id call_id,
213 const pj_str_t *dst,
214 pjsip_status_code *code)
215{
Benny Prijono55040452008-07-21 18:20:57 +0000216 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) {
217 PyObject *ret, *param_dst;
Benny Prijono9c461142008-07-10 22:41:20 +0000218 int cd;
219
220 ENTER_PYTHON();
221
Benny Prijono55040452008-07-21 18:20:57 +0000222 param_dst = PyString_FromPJ(dst);
223
224 ret = PyObject_CallFunction(
225 g_obj_callback->on_call_transfer_request,
226 "iOi",
227 call_id,
228 param_dst,
229 *code,
230 NULL
231 );
232
233 Py_DECREF(param_dst);
234
Benny Prijono9c461142008-07-10 22:41:20 +0000235 if (ret != NULL) {
236 if (ret != Py_None) {
237 if (PyArg_Parse(ret,"i",&cd)) {
238 *code = cd;
239 }
240 }
Benny Prijono55040452008-07-21 18:20:57 +0000241 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000242 }
243
244 LEAVE_PYTHON();
245 }
246}
247
248
249/*
250 * Notify application of the status of previously sent call
251 * transfer request. Application can monitor the status of the
252 * call transfer request, for example to decide whether to
253 * terminate existing call.
254 * !modified @061206
255 */
256static void cb_on_call_transfer_status( pjsua_call_id call_id,
257 int status_code,
258 const pj_str_t *status_text,
259 pj_bool_t final,
260 pj_bool_t *p_cont)
261{
Benny Prijono55040452008-07-21 18:20:57 +0000262 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) {
263 PyObject *ret, *param_reason;
Benny Prijono9c461142008-07-10 22:41:20 +0000264
265 ENTER_PYTHON();
266
Benny Prijono55040452008-07-21 18:20:57 +0000267 param_reason = PyString_FromPJ(status_text);
268
269 ret = PyObject_CallFunction(
270 g_obj_callback->on_call_transfer_status,
271 "iiOii",
272 call_id,
273 status_code,
274 param_reason,
275 final,
276 *p_cont,
277 NULL
278 );
279
280 Py_DECREF(param_reason);
281
Benny Prijono9c461142008-07-10 22:41:20 +0000282 if (ret != NULL) {
283 if (ret != Py_None) {
Benny Prijono55040452008-07-21 18:20:57 +0000284 int cnt;
Benny Prijono9c461142008-07-10 22:41:20 +0000285 if (PyArg_Parse(ret,"i",&cnt)) {
286 *p_cont = cnt;
287 }
288 }
Benny Prijono55040452008-07-21 18:20:57 +0000289 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000290 }
291
292 LEAVE_PYTHON();
293 }
294}
295
296
297/*
298 * Notify application about incoming INVITE with Replaces header.
299 * Application may reject the request by setting non-2xx code.
300 * !modified @061206
301 */
302static void cb_on_call_replace_request( pjsua_call_id call_id,
303 pjsip_rx_data *rdata,
304 int *st_code,
305 pj_str_t *st_text)
306{
Benny Prijono55040452008-07-21 18:20:57 +0000307 PJ_UNUSED_ARG(rdata);
308
309 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) {
310 PyObject *ret, *param_reason, *param_rdata;
Benny Prijono9c461142008-07-10 22:41:20 +0000311 int cd;
Benny Prijono9c461142008-07-10 22:41:20 +0000312
313 ENTER_PYTHON();
314
Benny Prijono55040452008-07-21 18:20:57 +0000315 param_reason = PyString_FromPJ(st_text);
316 param_rdata = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000317
Benny Prijono55040452008-07-21 18:20:57 +0000318 ret = PyObject_CallFunction(
319 g_obj_callback->on_call_replace_request,
320 "iOiO",
321 call_id,
322 param_rdata,
323 *st_code,
324 param_reason,
325 NULL
326 );
327
328 Py_DECREF(param_rdata);
329 Py_DECREF(param_reason);
330
Benny Prijono9c461142008-07-10 22:41:20 +0000331 if (ret != NULL) {
332 if (ret != Py_None) {
Benny Prijono55040452008-07-21 18:20:57 +0000333 PyObject * txt;
Benny Prijono9c461142008-07-10 22:41:20 +0000334 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
335 *st_code = cd;
Benny Prijono55040452008-07-21 18:20:57 +0000336 *st_text = PyString_ToPJ(txt);
Benny Prijono9c461142008-07-10 22:41:20 +0000337 }
338 }
Benny Prijono55040452008-07-21 18:20:57 +0000339 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000340 }
341
342 LEAVE_PYTHON();
343 }
344}
345
346
347/*
348 * Notify application that an existing call has been replaced with
349 * a new call. This happens when PJSUA-API receives incoming INVITE
350 * request with Replaces header.
351 */
352static void cb_on_call_replaced(pjsua_call_id old_call_id,
353 pjsua_call_id new_call_id)
354{
Benny Prijono55040452008-07-21 18:20:57 +0000355 if (PyCallable_Check(g_obj_callback->on_call_replaced)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000356 ENTER_PYTHON();
357
Benny Prijono55040452008-07-21 18:20:57 +0000358 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000359 g_obj_callback->on_call_replaced,
Benny Prijono55040452008-07-21 18:20:57 +0000360 "ii",
361 old_call_id,
362 new_call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000363 NULL
364 );
365
366 LEAVE_PYTHON();
367 }
368}
369
370
371/*
372 * cb_on_reg_state
373 * declares method on_reg_state for callback struct
374 */
375static void cb_on_reg_state(pjsua_acc_id acc_id)
376{
Benny Prijono55040452008-07-21 18:20:57 +0000377 if (PyCallable_Check(g_obj_callback->on_reg_state)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000378 ENTER_PYTHON();
379
380 PyObject_CallFunction(
381 g_obj_callback->on_reg_state,
382 "i",
383 acc_id,
384 NULL
385 );
386
387 LEAVE_PYTHON();
388 }
389}
390
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000391/*
392 * cb_on_incoming_subscribe
393 */
394static void cb_on_incoming_subscribe( pjsua_acc_id acc_id,
395 pjsua_srv_pres *srv_pres,
396 pjsua_buddy_id buddy_id,
397 const pj_str_t *from,
398 pjsip_rx_data *rdata,
399 pjsip_status_code *code,
400 pj_str_t *reason,
401 pjsua_msg_data *msg_data)
402{
403 static char reason_buf[64];
404
405 PJ_UNUSED_ARG(rdata);
406 PJ_UNUSED_ARG(msg_data);
407
Benny Prijono55040452008-07-21 18:20:57 +0000408 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) {
409 PyObject *ret, *param_from, *param_contact, *param_srv_pres;
410 pjsip_contact_hdr *contact_hdr;
411 pj_pool_t *pool = NULL;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000412
413 ENTER_PYTHON();
414
Benny Prijono55040452008-07-21 18:20:57 +0000415 param_from = PyString_FromPJ(from);
416 param_srv_pres = PyLong_FromLong((long)srv_pres);
417
418 contact_hdr = (pjsip_contact_hdr*)
419 pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
420 NULL);
421 if (contact_hdr) {
422 char *contact;
423 int len;
424
425 pool = pjsua_pool_create("pytmp", 512, 512);
426 contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1);
427 len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri,
428 contact, PJSIP_MAX_URL_SIZE);
429 if (len < 1)
430 len = 0;
431 contact[len] = '\0';
432
433 param_contact = PyString_FromStringAndSize(contact, len);
434 } else {
435 param_contact = Py_BuildValue("");
436 }
437
438 ret = PyObject_CallFunction(
439 g_obj_callback->on_incoming_subscribe,
440 "iiOOO",
441 acc_id,
442 buddy_id,
443 param_from,
444 param_contact,
445 param_srv_pres,
446 NULL
447 );
448
449 if (pool)
450 pj_pool_release(pool);
451
452 Py_DECREF(param_from);
453 Py_DECREF(param_contact);
454 Py_DECREF(param_srv_pres);
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000455
456 if (ret && PyTuple_Check(ret)) {
457 if (PyTuple_Size(ret) >= 1)
458 *code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0));
459 if (PyTuple_Size(ret) >= 2) {
460 if (PyTuple_GetItem(ret, 1) != Py_None) {
461 pj_str_t tmp;
Benny Prijono55040452008-07-21 18:20:57 +0000462 tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1));
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000463 reason->ptr = reason_buf;
464 pj_strncpy(reason, &tmp, sizeof(reason_buf));
465 } else {
Benny Prijono55040452008-07-21 18:20:57 +0000466 reason->slen = 0;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000467 }
468 }
Benny Prijono55040452008-07-21 18:20:57 +0000469 Py_XDECREF(ret);
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000470 } else if (ret) {
471 Py_XDECREF(ret);
472 }
473
474 LEAVE_PYTHON();
475 }
476}
Benny Prijono9c461142008-07-10 22:41:20 +0000477
478/*
479 * cb_on_buddy_state
480 * declares method on_buddy state for callback struct
481 */
482static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
483{
Benny Prijono55040452008-07-21 18:20:57 +0000484 if (PyCallable_Check(g_obj_callback->on_buddy_state)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000485 ENTER_PYTHON();
486
487 PyObject_CallFunction(
488 g_obj_callback->on_buddy_state,
489 "i",
490 buddy_id,
491 NULL
492 );
493
494 LEAVE_PYTHON();
495 }
496}
497
498/*
499 * cb_on_pager
500 * declares method on_pager for callback struct
501 */
502static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
503 const pj_str_t *to, const pj_str_t *contact,
504 const pj_str_t *mime_type, const pj_str_t *body,
505 pjsip_rx_data *rdata, pjsua_acc_id acc_id)
506{
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000507 PJ_UNUSED_ARG(rdata);
508
Benny Prijono55040452008-07-21 18:20:57 +0000509 if (PyCallable_Check(g_obj_callback->on_pager)) {
510 PyObject *param_from, *param_to, *param_contact, *param_mime_type,
511 *param_body;
512
Benny Prijono9c461142008-07-10 22:41:20 +0000513 ENTER_PYTHON();
514
Benny Prijono55040452008-07-21 18:20:57 +0000515 param_from = PyString_FromPJ(from);
516 param_to = PyString_FromPJ(to);
517 param_contact = PyString_FromPJ(contact);
518 param_mime_type = PyString_FromPJ(mime_type);
519 param_body = PyString_FromPJ(body);
520
521 PyObject_CallFunction(
522 g_obj_callback->on_pager,
523 "iOOOOOi",
524 call_id,
525 param_from,
526 param_to,
527 param_contact,
528 param_mime_type,
529 param_body,
530 acc_id,
531 NULL
532 );
533
534 Py_DECREF(param_body);
535 Py_DECREF(param_mime_type);
536 Py_DECREF(param_contact);
537 Py_DECREF(param_to);
538 Py_DECREF(param_from);
Benny Prijono9c461142008-07-10 22:41:20 +0000539
540 LEAVE_PYTHON();
541 }
542}
543
544
545/*
546 * cb_on_pager_status
547 * declares method on_pager_status for callback struct
548 */
549static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
550 const pj_str_t *body, void *user_data,
551 pjsip_status_code status,
552 const pj_str_t *reason,
553 pjsip_tx_data *tdata,
554 pjsip_rx_data *rdata,
555 pjsua_acc_id acc_id)
556{
Benny Prijono55040452008-07-21 18:20:57 +0000557 if (PyCallable_Check(g_obj_callback->on_pager)) {
558 PyObject *param_call_id, *param_to, *param_body,
559 *param_user_data, *param_status, *param_reason,
560 *param_acc_id;
Benny Prijono9c461142008-07-10 22:41:20 +0000561
562 ENTER_PYTHON();
563
564 PJ_UNUSED_ARG(tdata);
565 PJ_UNUSED_ARG(rdata);
566
Benny Prijono9c461142008-07-10 22:41:20 +0000567 PyObject_CallFunctionObjArgs(
Benny Prijono55040452008-07-21 18:20:57 +0000568 g_obj_callback->on_pager_status,
569 param_call_id = Py_BuildValue("i",call_id),
570 param_to = PyString_FromPJ(to),
571 param_body = PyString_FromPJ(body),
572 param_user_data = Py_BuildValue("i", user_data),
573 param_status = Py_BuildValue("i",status),
574 param_reason = PyString_FromPJ(reason),
575 param_acc_id = Py_BuildValue("i",acc_id),
576 NULL
577 );
578
579 Py_DECREF(param_call_id);
580 Py_DECREF(param_to);
581 Py_DECREF(param_body);
582 Py_DECREF(param_user_data);
583 Py_DECREF(param_status);
584 Py_DECREF(param_reason);
585 Py_DECREF(param_acc_id);
Benny Prijono9c461142008-07-10 22:41:20 +0000586
587 LEAVE_PYTHON();
588 }
589}
590
591
592/*
593 * cb_on_typing
594 * declares method on_typing for callback struct
595 */
596static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
597 const pj_str_t *to, const pj_str_t *contact,
598 pj_bool_t is_typing, pjsip_rx_data *rdata,
599 pjsua_acc_id acc_id)
600{
Benny Prijono55040452008-07-21 18:20:57 +0000601 if (PyCallable_Check(g_obj_callback->on_typing)) {
602 PyObject *param_call_id, *param_from, *param_to, *param_contact,
603 *param_is_typing, *param_acc_id;
604
Benny Prijono9c461142008-07-10 22:41:20 +0000605 ENTER_PYTHON();
606
607 PJ_UNUSED_ARG(rdata);
608
609 PyObject_CallFunctionObjArgs(
Benny Prijono55040452008-07-21 18:20:57 +0000610 g_obj_callback->on_typing,
611 param_call_id = Py_BuildValue("i",call_id),
612 param_from = PyString_FromPJ(from),
613 param_to = PyString_FromPJ(to),
614 param_contact = PyString_FromPJ(contact),
615 param_is_typing = Py_BuildValue("i",is_typing),
616 param_acc_id = Py_BuildValue("i",acc_id),
617 NULL
618 );
619
620 Py_DECREF(param_call_id);
621 Py_DECREF(param_from);
622 Py_DECREF(param_to);
623 Py_DECREF(param_contact);
624 Py_DECREF(param_is_typing);
625 Py_DECREF(param_acc_id);
Benny Prijono9c461142008-07-10 22:41:20 +0000626
627 LEAVE_PYTHON();
628 }
629}
630
631
632
633/*
634 * translate_hdr
635 * internal function
636 * translate from hdr_list to pjsip_generic_string_hdr
637 */
638void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
639{
640 pj_list_init(hdr);
641
642 if (PyList_Check(py_hdr_list)) {
643 int i;
644
Benny Prijono55040452008-07-21 18:20:57 +0000645 for (i=0; i<PyList_Size(py_hdr_list); ++i) {
Benny Prijono9c461142008-07-10 22:41:20 +0000646 pj_str_t hname, hvalue;
647 pjsip_generic_string_hdr * new_hdr;
648 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
649
Benny Prijono55040452008-07-21 18:20:57 +0000650 if (PyTuple_Check(tuple)) {
651 if (PyTuple_Size(tuple) >= 1)
652 hname = PyString_ToPJ(PyTuple_GetItem(tuple,0));
653 else
654 hname.slen = 0;
655 if (PyTuple_Size(tuple) >= 2)
656 hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1));
657 else
658 hvalue.slen = 0;
Benny Prijono9c461142008-07-10 22:41:20 +0000659 } else {
660 hname.ptr = "";
661 hname.slen = 0;
662 hvalue.ptr = "";
663 hvalue.slen = 0;
664 }
665 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
666 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
667 }
668 }
669}
670
Benny Prijono9c461142008-07-10 22:41:20 +0000671/*
672 * py_pjsua_thread_register
Benny Prijono9c461142008-07-10 22:41:20 +0000673 */
674static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
675{
Benny Prijono9c461142008-07-10 22:41:20 +0000676 pj_status_t status;
677 const char *name;
678 PyObject *py_desc;
679 pj_thread_t *thread;
Benny Prijono55040452008-07-21 18:20:57 +0000680 struct py_thread_desc *thread_desc;
Benny Prijono9c461142008-07-10 22:41:20 +0000681
682 PJ_UNUSED_ARG(pSelf);
683
Benny Prijono55040452008-07-21 18:20:57 +0000684 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000685 return NULL;
686 }
Benny Prijono55040452008-07-21 18:20:57 +0000687 thread_desc = (struct py_thread_desc*)
688 malloc(sizeof(struct py_thread_desc));
689 thread_desc->next = py_thread_desc;
690 py_thread_desc = thread_desc;
691
692 status = pj_thread_register(name, thread_desc->desc, &thread);
Benny Prijono9c461142008-07-10 22:41:20 +0000693
694 if (status == PJ_SUCCESS)
Benny Prijono55040452008-07-21 18:20:57 +0000695 status = pj_thread_local_set(g_thread_id, (void*)1);
696
Benny Prijono9c461142008-07-10 22:41:20 +0000697 return Py_BuildValue("i",status);
698}
699
700/*
701 * py_pjsua_logging_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000702 */
703static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
Benny Prijono55040452008-07-21 18:20:57 +0000704 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +0000705{
706 PyObj_pjsua_logging_config *obj;
707 pjsua_logging_config cfg;
708
709 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000710 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000711
Benny Prijono9c461142008-07-10 22:41:20 +0000712 pjsua_logging_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +0000713 obj = (PyObj_pjsua_logging_config*)
714 PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config,
715 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000716 PyObj_pjsua_logging_config_import(obj, &cfg);
717
Benny Prijono55040452008-07-21 18:20:57 +0000718 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000719}
720
721
722/*
723 * py_pjsua_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000724 */
725static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
726{
727 PyObj_pjsua_config *obj;
728 pjsua_config cfg;
729
730 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000731 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000732
Benny Prijono9c461142008-07-10 22:41:20 +0000733 pjsua_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +0000734 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config,
735 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000736 PyObj_pjsua_config_import(obj, &cfg);
737
Benny Prijono55040452008-07-21 18:20:57 +0000738 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000739}
740
741
742/*
743 * py_pjsua_media_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000744 */
745static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
746 PyObject *pArgs)
747{
748 PyObj_pjsua_media_config *obj;
749 pjsua_media_config cfg;
750
751 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000752 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000753
Benny Prijono9c461142008-07-10 22:41:20 +0000754 pjsua_media_config_default(&cfg);
755 obj = (PyObj_pjsua_media_config *)
756 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
757 PyObj_pjsua_media_config_import(obj, &cfg);
Benny Prijono55040452008-07-21 18:20:57 +0000758
Benny Prijono9c461142008-07-10 22:41:20 +0000759 return (PyObject *)obj;
760}
761
762
763/*
764 * py_pjsua_msg_data_init
Benny Prijono9c461142008-07-10 22:41:20 +0000765 */
766static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
767{
Benny Prijono9c461142008-07-10 22:41:20 +0000768 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000769 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000770
Benny Prijono55040452008-07-21 18:20:57 +0000771 return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data,
772 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000773}
774
775
776/*
777 * py_pjsua_reconfigure_logging
778 */
Benny Prijono55040452008-07-21 18:20:57 +0000779static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf,
780 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +0000781{
Benny Prijono55040452008-07-21 18:20:57 +0000782 PyObject *logObj;
Benny Prijono9c461142008-07-10 22:41:20 +0000783 pj_status_t status;
784
785 PJ_UNUSED_ARG(pSelf);
786
Benny Prijono55040452008-07-21 18:20:57 +0000787 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000788 return NULL;
789 }
Benny Prijono55040452008-07-21 18:20:57 +0000790
791 if (logObj != Py_None) {
792 PyObj_pjsua_logging_config *log;
793 pjsua_logging_config cfg;
794
795 log = (PyObj_pjsua_logging_config*)logObj;
Benny Prijono9c461142008-07-10 22:41:20 +0000796 cfg.msg_logging = log->msg_logging;
797 cfg.level = log->level;
798 cfg.console_level = log->console_level;
799 cfg.decor = log->decor;
Benny Prijono55040452008-07-21 18:20:57 +0000800 cfg.log_filename = PyString_ToPJ(log->log_filename);
801 Py_XDECREF(g_obj_log_cb);
802 g_obj_log_cb = log->cb;
803 Py_INCREF(g_obj_log_cb);
Benny Prijono9c461142008-07-10 22:41:20 +0000804 cfg.cb = &cb_log_cb;
805 status = pjsua_reconfigure_logging(&cfg);
806 } else {
807 status = pjsua_reconfigure_logging(NULL);
808 }
Benny Prijono55040452008-07-21 18:20:57 +0000809
Benny Prijono9c461142008-07-10 22:41:20 +0000810 return Py_BuildValue("i",status);
811}
812
813
814/*
Benny Prijono9c461142008-07-10 22:41:20 +0000815 * py_pjsua_perror
816 */
817static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
818{
819 const char *sender;
820 const char *title;
821 pj_status_t status;
822
823 PJ_UNUSED_ARG(pSelf);
824
Benny Prijono55040452008-07-21 18:20:57 +0000825 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000826 return NULL;
827 }
828
829 pjsua_perror(sender, title, status);
Benny Prijono55040452008-07-21 18:20:57 +0000830
831 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000832}
833
834
835/*
836 * py_pjsua_create
837 */
838static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
839{
840 pj_status_t status;
841
842 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000843 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000844
Benny Prijono9c461142008-07-10 22:41:20 +0000845 status = pjsua_create();
846
Benny Prijono55040452008-07-21 18:20:57 +0000847 if (status == PJ_SUCCESS) {
848 status = pj_thread_local_alloc(&g_thread_id);
Benny Prijono9c461142008-07-10 22:41:20 +0000849 if (status == PJ_SUCCESS)
Benny Prijono55040452008-07-21 18:20:57 +0000850 status = pj_thread_local_set(g_thread_id, (void*)1);
851
852 pj_atexit(&clear_py_thread_desc);
Benny Prijono9c461142008-07-10 22:41:20 +0000853 }
854
855 return Py_BuildValue("i",status);
856}
857
858
859/*
860 * py_pjsua_init
861 */
862static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
863{
864 pj_status_t status;
865 PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
866 pjsua_config cfg_ua, *p_cfg_ua;
867 pjsua_logging_config cfg_log, *p_cfg_log;
868 pjsua_media_config cfg_media, *p_cfg_media;
869
870 PJ_UNUSED_ARG(pSelf);
871
Benny Prijono55040452008-07-21 18:20:57 +0000872 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000873 return NULL;
874 }
875
876 pjsua_config_default(&cfg_ua);
877 pjsua_logging_config_default(&cfg_log);
878 pjsua_media_config_default(&cfg_media);
879
Benny Prijono55040452008-07-21 18:20:57 +0000880 if (o_ua_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000881 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
882
883 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
884
Benny Prijono55040452008-07-21 18:20:57 +0000885 Py_XDECREF(g_obj_callback);
Benny Prijono9c461142008-07-10 22:41:20 +0000886 g_obj_callback = obj_ua_cfg->cb;
887 Py_INCREF(g_obj_callback);
888
889 cfg_ua.cb.on_call_state = &cb_on_call_state;
890 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
891 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
892 cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
893 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
894 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
895 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
896 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
897 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000898 cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe;
Benny Prijono9c461142008-07-10 22:41:20 +0000899 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
900 cfg_ua.cb.on_pager2 = &cb_on_pager;
901 cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
902 cfg_ua.cb.on_typing2 = &cb_on_typing;
903
904 p_cfg_ua = &cfg_ua;
905
906 } else {
907 p_cfg_ua = NULL;
908 }
909
Benny Prijono55040452008-07-21 18:20:57 +0000910 if (o_log_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000911 PyObj_pjsua_logging_config * obj_log;
912
913 obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
914
915 PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
916
Benny Prijono55040452008-07-21 18:20:57 +0000917 Py_XDECREF(g_obj_log_cb);
918 g_obj_log_cb = obj_log->cb;
919 Py_INCREF(g_obj_log_cb);
Benny Prijono9c461142008-07-10 22:41:20 +0000920
921 cfg_log.cb = &cb_log_cb;
922 p_cfg_log = &cfg_log;
923
924 } else {
925 p_cfg_log = NULL;
926 }
927
Benny Prijono55040452008-07-21 18:20:57 +0000928 if (o_media_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000929 PyObj_pjsua_media_config_export(&cfg_media,
930 (PyObj_pjsua_media_config*)o_media_cfg);
931 p_cfg_media = &cfg_media;
932
933 } else {
934 p_cfg_media = NULL;
935 }
936
937 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
Benny Prijono55040452008-07-21 18:20:57 +0000938
939 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +0000940}
941
942
943/*
944 * py_pjsua_start
945 */
946static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
947{
948 pj_status_t status;
949
950 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000951 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000952
Benny Prijono9c461142008-07-10 22:41:20 +0000953 status = pjsua_start();
954
Benny Prijono55040452008-07-21 18:20:57 +0000955 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +0000956}
957
958
959/*
960 * py_pjsua_destroy
961 */
962static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
963{
964 pj_status_t status;
965
966 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000967 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000968
Benny Prijono9c461142008-07-10 22:41:20 +0000969 status = pjsua_destroy();
970
Benny Prijono55040452008-07-21 18:20:57 +0000971 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +0000972}
973
974
975/*
976 * py_pjsua_handle_events
977 */
978static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
979{
980 int ret;
Benny Prijono55040452008-07-21 18:20:57 +0000981 int msec;
Benny Prijono9c461142008-07-10 22:41:20 +0000982
983 PJ_UNUSED_ARG(pSelf);
984
Benny Prijono55040452008-07-21 18:20:57 +0000985 if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000986 return NULL;
987 }
988
Benny Prijono55040452008-07-21 18:20:57 +0000989 if (msec < 0)
990 msec = 0;
991
992#if !NO_PJSIP_THREAD
Benny Prijono9c461142008-07-10 22:41:20 +0000993 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
994 * construct, or otherwise many Python blocking functions (such as
995 * time.sleep(), readline(), etc.) may hang/block indefinitely.
996 * See http://www.python.org/doc/current/api/threads.html for more info.
997 */
998 Py_BEGIN_ALLOW_THREADS
Benny Prijono55040452008-07-21 18:20:57 +0000999#endif
1000
Benny Prijono9c461142008-07-10 22:41:20 +00001001 ret = pjsua_handle_events(msec);
Benny Prijono55040452008-07-21 18:20:57 +00001002
1003#if !NO_PJSIP_THREAD
Benny Prijono9c461142008-07-10 22:41:20 +00001004 Py_END_ALLOW_THREADS
Benny Prijono55040452008-07-21 18:20:57 +00001005#endif
Benny Prijono9c461142008-07-10 22:41:20 +00001006
Benny Prijono55040452008-07-21 18:20:57 +00001007 return Py_BuildValue("i", ret);
Benny Prijono9c461142008-07-10 22:41:20 +00001008}
1009
1010
1011/*
1012 * py_pjsua_verify_sip_url
1013 */
1014static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
1015{
1016 pj_status_t status;
1017 const char *url;
1018
1019 PJ_UNUSED_ARG(pSelf);
1020
Benny Prijono55040452008-07-21 18:20:57 +00001021 if (!PyArg_ParseTuple(pArgs, "s", &url)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001022 return NULL;
1023 }
Benny Prijono55040452008-07-21 18:20:57 +00001024
Benny Prijono9c461142008-07-10 22:41:20 +00001025 status = pjsua_verify_sip_url(url);
1026
Benny Prijono55040452008-07-21 18:20:57 +00001027 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001028}
1029
1030
1031/*
1032 * function doc
1033 */
1034
1035static char pjsua_thread_register_doc[] =
1036 "int _pjsua.thread_register(string name, int[] desc)";
1037static char pjsua_perror_doc[] =
1038 "void _pjsua.perror (string sender, string title, int status) "
1039 "Display error message for the specified error code. Parameters: "
1040 "sender: The log sender field; "
1041 "title: Message title for the error; "
1042 "status: Status code.";
1043
1044static char pjsua_create_doc[] =
1045 "int _pjsua.create (void) "
1046 "Instantiate pjsua application. Application "
1047 "must call this function before calling any other functions, to make sure "
1048 "that the underlying libraries are properly initialized. Once this "
1049 "function has returned success, application must call pjsua_destroy() "
1050 "before quitting.";
1051
1052static char pjsua_init_doc[] =
1053 "int _pjsua.init (_pjsua.Config obj_ua_cfg, "
1054 "_pjsua.Logging_Config log_cfg, _pjsua.Media_Config media_cfg) "
1055 "Initialize pjsua with the specified settings. All the settings are "
1056 "optional, and the default values will be used when the config is not "
1057 "specified. Parameters: "
1058 "obj_ua_cfg : User agent configuration; "
1059 "log_cfg : Optional logging configuration; "
1060 "media_cfg : Optional media configuration.";
1061
1062static char pjsua_start_doc[] =
1063 "int _pjsua.start (void) "
1064 "Application is recommended to call this function after all "
1065 "initialization is done, so that the library can do additional checking "
1066 "set up additional";
1067
1068static char pjsua_destroy_doc[] =
1069 "int _pjsua.destroy (void) "
1070 "Destroy pjsua This function must be called once PJSUA is created. To "
1071 "make it easier for application, application may call this function "
1072 "several times with no danger.";
1073
1074static char pjsua_handle_events_doc[] =
1075 "int _pjsua.handle_events (int msec_timeout) "
1076 "Poll pjsua for events, and if necessary block the caller thread for the "
1077 "specified maximum interval (in miliseconds) Parameters: "
1078 "msec_timeout: Maximum time to wait, in miliseconds. "
1079 "Returns: The number of events that have been handled during the poll. "
1080 "Negative value indicates error, and application can retrieve the error "
1081 "as (err = -return_value).";
1082
1083static char pjsua_verify_sip_url_doc[] =
1084 "int _pjsua.verify_sip_url (string c_url) "
1085 "Verify that valid SIP url is given Parameters: "
1086 "c_url: The URL, as NULL terminated string.";
1087
Benny Prijono9c461142008-07-10 22:41:20 +00001088static char pjsua_reconfigure_logging_doc[] =
1089 "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) "
1090 "Application can call this function at any time (after pjsua_create(), of "
1091 "course) to change logging settings. Parameters: "
1092 "c: Logging configuration.";
1093
1094static char pjsua_logging_config_default_doc[] =
1095 "_pjsua.Logging_Config _pjsua.logging_config_default () "
1096 "Use this function to initialize logging config.";
1097
1098static char pjsua_config_default_doc[] =
1099 "_pjsua.Config _pjsua.config_default (). Use this function to "
1100 "initialize pjsua config. ";
1101
1102static char pjsua_media_config_default_doc[] =
1103 "_pjsua.Media_Config _pjsua.media_config_default (). "
1104 "Use this function to initialize media config.";
1105
1106static char pjsua_msg_data_init_doc[] =
1107 "_pjsua.Msg_Data void _pjsua.msg_data_init () "
1108 "Initialize message data ";
1109
1110
1111/* END OF LIB BASE */
1112
1113/* LIB TRANSPORT */
1114
1115/*
1116 * py_pjsua_transport_config_default
Benny Prijono9c461142008-07-10 22:41:20 +00001117 */
1118static PyObject *py_pjsua_transport_config_default(PyObject *pSelf,
1119 PyObject *pArgs)
1120{
1121 PyObj_pjsua_transport_config *obj;
1122 pjsua_transport_config cfg;
1123
1124 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001125 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001126
1127 pjsua_transport_config_default(&cfg);
1128 obj = (PyObj_pjsua_transport_config*)
1129 PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
1130 NULL, NULL);
1131 PyObj_pjsua_transport_config_import(obj, &cfg);
1132
1133 return (PyObject *)obj;
1134}
1135
1136/*
1137 * py_pjsua_transport_create
Benny Prijono9c461142008-07-10 22:41:20 +00001138 */
1139static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1140{
1141 pj_status_t status;
1142 int type;
Benny Prijono55040452008-07-21 18:20:57 +00001143 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001144 pjsua_transport_config cfg;
1145 pjsua_transport_id id;
1146
1147 PJ_UNUSED_ARG(pSelf);
1148
Benny Prijono55040452008-07-21 18:20:57 +00001149 if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001150 return NULL;
1151 }
1152
Benny Prijono55040452008-07-21 18:20:57 +00001153 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001154 PyObj_pjsua_transport_config *obj;
Benny Prijono55040452008-07-21 18:20:57 +00001155
1156 obj = (PyObj_pjsua_transport_config*)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001157 PyObj_pjsua_transport_config_export(&cfg, obj);
1158 status = pjsua_transport_create(type, &cfg, &id);
1159 } else {
1160 status = pjsua_transport_create(type, NULL, &id);
1161 }
1162
1163
1164 return Py_BuildValue("ii", status, id);
1165}
1166
1167/*
1168 * py_pjsua_enum_transports
Benny Prijono9c461142008-07-10 22:41:20 +00001169 */
1170static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1171{
1172 pj_status_t status;
1173 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001174 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
1175 unsigned c, i;
1176
1177 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001178 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001179
Benny Prijono9c461142008-07-10 22:41:20 +00001180 c = PJ_ARRAY_SIZE(id);
1181 status = pjsua_enum_transports(id, &c);
1182
1183 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00001184 for (i = 0; i < c; i++) {
1185 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00001186 }
1187
Benny Prijono55040452008-07-21 18:20:57 +00001188 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001189}
1190
1191/*
1192 * py_pjsua_transport_get_info
1193 * !modified @ 051206
1194 */
1195static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
1196{
1197 pj_status_t status;
1198 int id;
1199 pjsua_transport_info info;
1200
1201 PJ_UNUSED_ARG(pSelf);
1202
1203 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1204 return NULL;
1205 }
1206
1207 status = pjsua_transport_get_info(id, &info);
1208 if (status == PJ_SUCCESS) {
1209 PyObj_pjsua_transport_info *obj;
1210 obj = (PyObj_pjsua_transport_info *)
1211 PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info,
1212 NULL, NULL);
1213 PyObj_pjsua_transport_info_import(obj, &info);
Benny Prijono55040452008-07-21 18:20:57 +00001214 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001215 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001216 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001217 }
1218}
1219
1220/*
1221 * py_pjsua_transport_set_enable
1222 */
Benny Prijono55040452008-07-21 18:20:57 +00001223static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf,
1224 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00001225{
1226 pj_status_t status;
1227 int id;
1228 int enabled;
1229
1230 PJ_UNUSED_ARG(pSelf);
1231
Benny Prijono55040452008-07-21 18:20:57 +00001232 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001233 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00001234 }
1235 status = pjsua_transport_set_enable(id, enabled);
1236
1237 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001238}
1239
1240/*
1241 * py_pjsua_transport_close
1242 */
1243static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
1244{
1245 pj_status_t status;
1246 int id;
1247 int force;
1248
1249 PJ_UNUSED_ARG(pSelf);
1250
Benny Prijono55040452008-07-21 18:20:57 +00001251 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001252 return NULL;
1253 }
1254 status = pjsua_transport_close(id, force);
1255
Benny Prijono55040452008-07-21 18:20:57 +00001256 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001257}
1258
1259static char pjsua_transport_config_default_doc[] =
1260 "_pjsua.Transport_Config _pjsua.transport_config_default () "
1261 "Call this function to initialize UDP config with default values.";
1262static char pjsua_transport_create_doc[] =
1263 "int, int _pjsua.transport_create (int type, "
1264 "_pjsua.Transport_Config cfg) "
1265 "Create SIP transport.";
1266static char pjsua_enum_transports_doc[] =
1267 "int[] _pjsua.enum_transports () "
1268 "Enumerate all transports currently created in the system.";
1269static char pjsua_transport_get_info_doc[] =
1270 "void _pjsua.transport_get_info "
1271 "(_pjsua.Transport_ID id, _pjsua.Transport_Info info) "
1272 "Get information about transports.";
1273static char pjsua_transport_set_enable_doc[] =
1274 "void _pjsua.transport_set_enable "
1275 "(_pjsua.Transport_ID id, int enabled) "
1276 "Disable a transport or re-enable it. "
1277 "By default transport is always enabled after it is created. "
1278 "Disabling a transport does not necessarily close the socket, "
1279 "it will only discard incoming messages and prevent the transport "
1280 "from being used to send outgoing messages.";
1281static char pjsua_transport_close_doc[] =
1282 "void _pjsua.transport_close (_pjsua.Transport_ID id, int force) "
1283 "Close the transport. If transport is forcefully closed, "
1284 "it will be immediately closed, and any pending transactions "
1285 "that are using the transport may not terminate properly. "
1286 "Otherwise, the system will wait until all transactions are closed "
1287 "while preventing new users from using the transport, and will close "
1288 "the transport when it is safe to do so.";
1289
1290/* END OF LIB TRANSPORT */
1291
1292/* LIB ACCOUNT */
1293
1294
1295/*
1296 * py_pjsua_acc_config_default
Benny Prijono9c461142008-07-10 22:41:20 +00001297 */
1298static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
1299{
1300 PyObj_pjsua_acc_config *obj;
1301 pjsua_acc_config cfg;
1302
1303 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001304 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001305
1306 if (!PyArg_ParseTuple(pArgs, "")) {
1307 return NULL;
1308 }
1309
1310 pjsua_acc_config_default(&cfg);
1311 obj = (PyObj_pjsua_acc_config *)
1312 PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config,
1313 NULL, NULL);
1314 PyObj_pjsua_acc_config_import(obj, &cfg);
1315 return (PyObject *)obj;
1316}
1317
1318/*
1319 * py_pjsua_acc_get_count
1320 */
1321static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
1322{
1323 int count;
1324
1325 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001326 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001327
1328 count = pjsua_acc_get_count();
Benny Prijono55040452008-07-21 18:20:57 +00001329 return Py_BuildValue("i", count);
Benny Prijono9c461142008-07-10 22:41:20 +00001330}
1331
1332/*
1333 * py_pjsua_acc_is_valid
1334 */
1335static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
1336{
1337 int id;
1338 int is_valid;
1339
1340 PJ_UNUSED_ARG(pSelf);
1341
1342 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1343 return NULL;
1344 }
1345
1346 is_valid = pjsua_acc_is_valid(id);
1347 return Py_BuildValue("i", is_valid);
1348}
1349
1350/*
1351 * py_pjsua_acc_set_default
1352 */
1353static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
1354{
1355 int id;
1356 int status;
1357
1358 PJ_UNUSED_ARG(pSelf);
1359
1360 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1361 return NULL;
1362 }
1363 status = pjsua_acc_set_default(id);
1364
1365 return Py_BuildValue("i", status);
1366}
1367
1368/*
1369 * py_pjsua_acc_get_default
1370 */
1371static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
1372{
1373 int id;
1374
1375 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001376 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001377
1378 id = pjsua_acc_get_default();
1379
1380 return Py_BuildValue("i", id);
1381}
1382
1383/*
1384 * py_pjsua_acc_add
Benny Prijono9c461142008-07-10 22:41:20 +00001385 */
1386static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
1387{
1388 int is_default;
Benny Prijono55040452008-07-21 18:20:57 +00001389 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001390 int acc_id;
1391 int status;
1392
1393 PJ_UNUSED_ARG(pSelf);
1394
Benny Prijono55040452008-07-21 18:20:57 +00001395 if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001396 return NULL;
1397 }
1398
Benny Prijono55040452008-07-21 18:20:57 +00001399 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001400 pjsua_acc_config cfg;
Benny Prijono55040452008-07-21 18:20:57 +00001401 PyObj_pjsua_acc_config *ac;
Benny Prijono9c461142008-07-10 22:41:20 +00001402
1403 pjsua_acc_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +00001404 ac = (PyObj_pjsua_acc_config *)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001405 PyObj_pjsua_acc_config_export(&cfg, ac);
1406 status = pjsua_acc_add(&cfg, is_default, &acc_id);
1407 } else {
1408 status = PJ_EINVAL;
1409 acc_id = PJSUA_INVALID_ID;
1410 }
1411
1412 return Py_BuildValue("ii", status, acc_id);
1413}
1414
1415/*
1416 * py_pjsua_acc_add_local
Benny Prijono9c461142008-07-10 22:41:20 +00001417 */
1418static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
1419{
1420 int is_default;
1421 int tid;
Benny Prijono55040452008-07-21 18:20:57 +00001422 int acc_id;
Benny Prijono9c461142008-07-10 22:41:20 +00001423 int status;
1424
1425 PJ_UNUSED_ARG(pSelf);
1426
1427 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
1428 return NULL;
1429 }
1430
Benny Prijono55040452008-07-21 18:20:57 +00001431 status = pjsua_acc_add_local(tid, is_default, &acc_id);
Benny Prijono9c461142008-07-10 22:41:20 +00001432
Benny Prijono55040452008-07-21 18:20:57 +00001433 return Py_BuildValue("ii", status, acc_id);
1434}
1435
1436/*
1437 * py_pjsua_acc_set_user_data
1438 */
1439static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs)
1440{
1441 int acc_id;
1442 PyObject *pUserData, *old_user_data;
1443 int status;
1444
1445 PJ_UNUSED_ARG(pSelf);
1446
1447 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) {
1448 return NULL;
1449 }
1450
1451 old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1452
1453 status = pjsua_acc_set_user_data(acc_id, (void*)pUserData);
1454
1455 if (status == PJ_SUCCESS) {
1456 Py_XINCREF(pUserData);
1457 Py_XDECREF(old_user_data);
1458 }
1459
1460 return Py_BuildValue("i", status);
1461}
1462
1463/*
1464 * py_pjsua_acc_get_user_data
1465 */
1466static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs)
1467{
1468 int acc_id;
1469 PyObject *user_data;
1470
1471 PJ_UNUSED_ARG(pSelf);
1472
1473 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1474 return NULL;
1475 }
1476
1477 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1478
1479 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001480}
1481
1482/*
1483 * py_pjsua_acc_del
1484 */
1485static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
1486{
1487 int acc_id;
Benny Prijono55040452008-07-21 18:20:57 +00001488 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00001489 int status;
1490
1491 PJ_UNUSED_ARG(pSelf);
1492
Benny Prijono55040452008-07-21 18:20:57 +00001493 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001494 return NULL;
1495 }
Benny Prijono55040452008-07-21 18:20:57 +00001496
1497 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1498 Py_XDECREF(user_data);
1499
1500 status = pjsua_acc_del(acc_id);
1501
Benny Prijono9c461142008-07-10 22:41:20 +00001502 return Py_BuildValue("i", status);
1503}
1504
1505/*
1506 * py_pjsua_acc_modify
1507 */
1508static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
1509{
Benny Prijono55040452008-07-21 18:20:57 +00001510 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001511 PyObj_pjsua_acc_config * ac;
1512 int acc_id;
1513 int status;
1514
1515 PJ_UNUSED_ARG(pSelf);
1516
Benny Prijono55040452008-07-21 18:20:57 +00001517 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001518 return NULL;
1519 }
1520
Benny Prijono55040452008-07-21 18:20:57 +00001521 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001522 pjsua_acc_config cfg;
1523
1524 pjsua_acc_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +00001525 ac = (PyObj_pjsua_acc_config*)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001526 PyObj_pjsua_acc_config_export(&cfg, ac);
1527
1528 status = pjsua_acc_modify(acc_id, &cfg);
1529 } else {
1530 status = PJ_EINVAL;
1531 }
1532 return Py_BuildValue("i", status);
1533}
1534
1535/*
1536 * py_pjsua_acc_set_online_status
1537 */
1538static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf,
1539 PyObject *pArgs)
1540{
1541 int is_online;
1542 int acc_id;
1543 int status;
1544
1545 PJ_UNUSED_ARG(pSelf);
1546
1547 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
1548 return NULL;
1549 }
1550
1551 status = pjsua_acc_set_online_status(acc_id, is_online);
1552
1553 return Py_BuildValue("i", status);
1554}
1555
1556/*
1557 * py_pjsua_acc_set_online_status2
1558 */
1559static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf,
1560 PyObject *pArgs)
1561{
1562 int is_online;
1563 int acc_id;
1564 int activity_id;
Benny Prijono55040452008-07-21 18:20:57 +00001565 const char *activity_text = NULL;
1566 const char *rpid_id = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00001567 pjrpid_element rpid;
1568 pj_status_t status;
1569
1570 PJ_UNUSED_ARG(pSelf);
1571
1572 if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online,
Benny Prijono55040452008-07-21 18:20:57 +00001573 &activity_id, &activity_text, &rpid_id))
1574 {
Benny Prijono9c461142008-07-10 22:41:20 +00001575 return NULL;
1576 }
1577
1578 pj_bzero(&rpid, sizeof(rpid));
1579 rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
1580 rpid.activity = activity_id;
Benny Prijono55040452008-07-21 18:20:57 +00001581 if (activity_text)
1582 rpid.note = pj_str((char*)activity_text);
Benny Prijono9c461142008-07-10 22:41:20 +00001583
1584 if (rpid_id)
1585 rpid.id = pj_str((char*)rpid_id);
1586
1587 status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
1588
1589 return Py_BuildValue("i", status);
1590}
1591
1592/*
1593 * py_pjsua_acc_set_registration
1594 */
1595static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf,
1596 PyObject *pArgs)
1597{
1598 int renew;
1599 int acc_id;
1600 int status;
1601
1602 PJ_UNUSED_ARG(pSelf);
1603
1604 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
1605 return NULL;
1606 }
1607
1608 status = pjsua_acc_set_registration(acc_id, renew);
1609
1610 return Py_BuildValue("i", status);
1611}
1612
1613/*
1614 * py_pjsua_acc_get_info
Benny Prijono9c461142008-07-10 22:41:20 +00001615 */
1616static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
1617{
1618 int acc_id;
1619 PyObj_pjsua_acc_info * obj;
1620 pjsua_acc_info info;
1621 int status;
1622
1623 PJ_UNUSED_ARG(pSelf);
1624
1625 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1626 return NULL;
1627 }
1628
1629 status = pjsua_acc_get_info(acc_id, &info);
1630 if (status == PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00001631 obj = (PyObj_pjsua_acc_info*)
1632 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00001633 PyObj_pjsua_acc_info_import(obj, &info);
Benny Prijono55040452008-07-21 18:20:57 +00001634 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001635 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001636 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001637 }
1638}
1639
1640/*
1641 * py_pjsua_enum_accs
Benny Prijono9c461142008-07-10 22:41:20 +00001642 */
1643static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1644{
1645 pj_status_t status;
1646 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001647 pjsua_acc_id id[PJSUA_MAX_ACC];
1648 unsigned c, i;
1649
1650 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001651 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001652
Benny Prijono9c461142008-07-10 22:41:20 +00001653 c = PJ_ARRAY_SIZE(id);
Benny Prijono9c461142008-07-10 22:41:20 +00001654 status = pjsua_enum_accs(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001655 if (status != PJ_SUCCESS)
1656 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00001657
1658 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00001659 for (i = 0; i < c; i++) {
1660 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00001661 }
1662
Benny Prijono55040452008-07-21 18:20:57 +00001663 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001664}
1665
1666/*
1667 * py_pjsua_acc_enum_info
Benny Prijono9c461142008-07-10 22:41:20 +00001668 */
1669static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
1670{
1671 pj_status_t status;
1672 PyObject *list;
1673 pjsua_acc_info info[PJSUA_MAX_ACC];
1674 unsigned c, i;
1675
1676 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001677 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001678
1679 if (!PyArg_ParseTuple(pArgs, "")) {
1680 return NULL;
1681 }
1682
1683 c = PJ_ARRAY_SIZE(info);
1684 status = pjsua_acc_enum_info(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001685 if (status != PJ_SUCCESS)
1686 c = 0;
1687
Benny Prijono9c461142008-07-10 22:41:20 +00001688 list = PyList_New(c);
1689 for (i = 0; i < c; i++) {
1690 PyObj_pjsua_acc_info *obj;
1691 obj = (PyObj_pjsua_acc_info *)
1692 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1693
1694 PyObj_pjsua_acc_info_import(obj, &info[i]);
1695
Benny Prijono55040452008-07-21 18:20:57 +00001696 PyList_SetItem(list, i, (PyObject*)obj);
Benny Prijono9c461142008-07-10 22:41:20 +00001697 }
1698
Benny Prijono55040452008-07-21 18:20:57 +00001699 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001700}
1701
1702/*
1703 * py_pjsua_acc_set_transport
1704 */
Benny Prijono55040452008-07-21 18:20:57 +00001705static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00001706{
1707 int acc_id, transport_id;
1708 int status;
1709
1710 PJ_UNUSED_ARG(pSelf);
1711
Benny Prijono55040452008-07-21 18:20:57 +00001712 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001713 return NULL;
1714 }
1715
1716 status = pjsua_acc_set_transport(acc_id, transport_id);
1717
1718
1719 return Py_BuildValue("i", status);
1720}
1721
1722
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001723/*
1724 * py_pjsua_acc_pres_notify
1725 */
Benny Prijono55040452008-07-21 18:20:57 +00001726static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf,
1727 PyObject *pArgs)
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001728{
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001729 int acc_id, state;
Benny Prijono55040452008-07-21 18:20:57 +00001730 PyObject *arg_pres, *arg_msg_data, *arg_reason;
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001731 void *srv_pres;
1732 pjsua_msg_data msg_data;
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001733 pj_str_t reason;
1734 pj_bool_t with_body;
1735 pj_pool_t *pool = NULL;
1736 int status;
1737
1738 PJ_UNUSED_ARG(pSelf);
1739
Benny Prijono55040452008-07-21 18:20:57 +00001740 if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres,
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001741 &state, &arg_reason, &arg_msg_data))
1742 {
1743 return NULL;
1744 }
1745
1746 srv_pres = (void*) PyLong_AsLong(arg_pres);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001747 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED);
1748
Benny Prijono55040452008-07-21 18:20:57 +00001749 if (arg_reason && PyString_Check(arg_reason)) {
1750 reason = PyString_ToPJ(arg_reason);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001751 } else {
1752 reason = pj_str("");
1753 }
1754
Benny Prijono55040452008-07-21 18:20:57 +00001755 pjsua_msg_data_init(&msg_data);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001756 if (arg_msg_data && arg_msg_data != Py_None) {
1757 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00001758 msg_data.content_type = PyString_ToPJ(omd->content_type);
1759 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001760 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
1761 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001762 }
1763
1764 status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres,
1765 (pjsip_evsub_state)state, NULL,
1766 &reason, with_body, &msg_data);
1767
1768 if (pool) {
1769 pj_pool_release(pool);
1770 }
1771
1772 return Py_BuildValue("i", status);
1773}
1774
Benny Prijono9c461142008-07-10 22:41:20 +00001775static char pjsua_acc_config_default_doc[] =
1776 "_pjsua.Acc_Config _pjsua.acc_config_default () "
1777 "Call this function to initialize account config with default values.";
1778static char pjsua_acc_get_count_doc[] =
1779 "int _pjsua.acc_get_count () "
1780 "Get number of current accounts.";
1781static char pjsua_acc_is_valid_doc[] =
1782 "int _pjsua.acc_is_valid (int acc_id) "
1783 "Check if the specified account ID is valid.";
1784static char pjsua_acc_set_default_doc[] =
1785 "int _pjsua.acc_set_default (int acc_id) "
1786 "Set default account to be used when incoming "
1787 "and outgoing requests doesn't match any accounts.";
1788static char pjsua_acc_get_default_doc[] =
1789 "int _pjsua.acc_get_default () "
1790 "Get default account.";
1791static char pjsua_acc_add_doc[] =
1792 "int, int _pjsua.acc_add (_pjsua.Acc_Config cfg, "
1793 "int is_default) "
1794 "Add a new account to pjsua. PJSUA must have been initialized "
1795 "(with pjsua_init()) before calling this function.";
1796static char pjsua_acc_add_local_doc[] =
1797 "int,int _pjsua.acc_add_local (int tid, "
1798 "int is_default) "
1799 "Add a local account. A local account is used to identify "
1800 "local endpoint instead of a specific user, and for this reason, "
1801 "a transport ID is needed to obtain the local address information.";
1802static char pjsua_acc_del_doc[] =
1803 "int _pjsua.acc_del (int acc_id) "
1804 "Delete account.";
1805static char pjsua_acc_modify_doc[] =
1806 "int _pjsua.acc_modify (int acc_id, _pjsua.Acc_Config cfg) "
1807 "Modify account information.";
1808static char pjsua_acc_set_online_status_doc[] =
1809 "int _pjsua.acc_set_online_status2(int acc_id, int is_online) "
1810 "Modify account's presence status to be advertised "
1811 "to remote/presence subscribers.";
1812static char pjsua_acc_set_online_status2_doc[] =
1813 "int _pjsua.acc_set_online_status (int acc_id, int is_online, "
1814 "int activity_id, string activity_text) "
1815 "Modify account's presence status to be advertised "
1816 "to remote/presence subscribers.";
1817static char pjsua_acc_set_registration_doc[] =
1818 "int _pjsua.acc_set_registration (int acc_id, int renew) "
1819 "Update registration or perform unregistration.";
1820static char pjsua_acc_get_info_doc[] =
1821 "_pjsua.Acc_Info _pjsua.acc_get_info (int acc_id) "
1822 "Get account information.";
1823static char pjsua_enum_accs_doc[] =
1824 "int[] _pjsua.enum_accs () "
1825 "Enum accounts all account ids.";
1826static char pjsua_acc_enum_info_doc[] =
1827 "_pjsua.Acc_Info[] _pjsua.acc_enum_info () "
1828 "Enum accounts info.";
Benny Prijono9c461142008-07-10 22:41:20 +00001829
1830/* END OF LIB ACCOUNT */
1831
1832/* LIB BUDDY */
1833
1834
1835
1836/*
1837 * py_pjsua_buddy_config_default
1838 */
1839static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf,
1840 PyObject *pArgs)
1841{
1842 PyObj_pjsua_buddy_config *obj;
1843 pjsua_buddy_config cfg;
1844
1845 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001846 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001847
Benny Prijono9c461142008-07-10 22:41:20 +00001848 pjsua_buddy_config_default(&cfg);
1849 obj = (PyObj_pjsua_buddy_config *)
1850 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
1851 PyObj_pjsua_buddy_config_import(obj, &cfg);
1852
1853 return (PyObject *)obj;
1854}
1855
1856/*
1857 * py_pjsua_get_buddy_count
1858 */
1859static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
1860{
Benny Prijono9c461142008-07-10 22:41:20 +00001861 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001862 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001863
Benny Prijono55040452008-07-21 18:20:57 +00001864 return Py_BuildValue("i", pjsua_get_buddy_count());
Benny Prijono9c461142008-07-10 22:41:20 +00001865}
1866
1867/*
1868 * py_pjsua_buddy_is_valid
1869 */
1870static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
1871{
1872 int id;
1873 int is_valid;
1874
1875 PJ_UNUSED_ARG(pSelf);
1876
1877 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1878 return NULL;
1879 }
1880 is_valid = pjsua_buddy_is_valid(id);
1881
1882 return Py_BuildValue("i", is_valid);
1883}
1884
1885/*
1886 * py_pjsua_enum_buddies
Benny Prijono9c461142008-07-10 22:41:20 +00001887 */
1888static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1889{
1890 pj_status_t status;
1891 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001892 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
1893 unsigned c, i;
1894
1895 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001896 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001897
Benny Prijono9c461142008-07-10 22:41:20 +00001898 c = PJ_ARRAY_SIZE(id);
1899 status = pjsua_enum_buddies(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001900 if (status != PJ_SUCCESS)
1901 c = 0;
1902
Benny Prijono9c461142008-07-10 22:41:20 +00001903 list = PyList_New(c);
1904 for (i = 0; i < c; i++) {
1905 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1906 }
1907
Benny Prijono55040452008-07-21 18:20:57 +00001908 return (PyObject*)list;
1909}
1910
1911/*
1912 * py_pjsua_buddy_find
1913 */
1914static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs)
1915{
1916 PyObject *pURI;
1917 pj_str_t uri;
1918 pjsua_buddy_id buddy_id;
1919
1920 PJ_UNUSED_ARG(pSelf);
1921
1922 if (!PyArg_ParseTuple(pArgs, "O", &pURI)) {
1923 return NULL;
1924 }
1925
1926 if (!PyString_Check(pURI))
1927 return Py_BuildValue("i", PJSUA_INVALID_ID);
1928
1929 uri = PyString_ToPJ(pURI);
1930 buddy_id = pjsua_buddy_find(&uri);
1931
1932 return Py_BuildValue("i", buddy_id);
Benny Prijono9c461142008-07-10 22:41:20 +00001933}
1934
1935/*
1936 * py_pjsua_buddy_get_info
Benny Prijono9c461142008-07-10 22:41:20 +00001937 */
1938static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
1939{
1940 int buddy_id;
Benny Prijono9c461142008-07-10 22:41:20 +00001941 pjsua_buddy_info info;
1942 int status;
1943
1944 PJ_UNUSED_ARG(pSelf);
1945
1946 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
1947 return NULL;
1948 }
1949
1950 status = pjsua_buddy_get_info(buddy_id, &info);
1951 if (status == PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00001952 PyObj_pjsua_buddy_info *obj;
1953
Benny Prijono9c461142008-07-10 22:41:20 +00001954 obj = (PyObj_pjsua_buddy_info *)
Benny Prijono55040452008-07-21 18:20:57 +00001955 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,
1956 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00001957 PyObj_pjsua_buddy_info_import(obj, &info);
Benny Prijono55040452008-07-21 18:20:57 +00001958 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001959 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001960 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001961 }
1962}
1963
1964/*
1965 * py_pjsua_buddy_add
Benny Prijono9c461142008-07-10 22:41:20 +00001966 */
1967static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
1968{
Benny Prijono55040452008-07-21 18:20:57 +00001969 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001970 int buddy_id;
1971 int status;
1972
1973 PJ_UNUSED_ARG(pSelf);
1974
Benny Prijono55040452008-07-21 18:20:57 +00001975 if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001976 return NULL;
1977 }
1978
Benny Prijono55040452008-07-21 18:20:57 +00001979 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001980 pjsua_buddy_config cfg;
Benny Prijono55040452008-07-21 18:20:57 +00001981 PyObj_pjsua_buddy_config *bc;
Benny Prijono9c461142008-07-10 22:41:20 +00001982
Benny Prijono55040452008-07-21 18:20:57 +00001983 bc = (PyObj_pjsua_buddy_config *)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001984
1985 pjsua_buddy_config_default(&cfg);
1986 PyObj_pjsua_buddy_config_export(&cfg, bc);
1987
1988 status = pjsua_buddy_add(&cfg, &buddy_id);
Benny Prijono55040452008-07-21 18:20:57 +00001989
Benny Prijono9c461142008-07-10 22:41:20 +00001990 } else {
1991 status = PJ_EINVAL;
1992 buddy_id = PJSUA_INVALID_ID;
1993 }
1994 return Py_BuildValue("ii", status, buddy_id);
1995}
1996
1997/*
1998 * py_pjsua_buddy_del
1999 */
2000static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
2001{
2002 int buddy_id;
2003 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002004 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00002005
2006 PJ_UNUSED_ARG(pSelf);
2007
2008 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2009 return NULL;
2010 }
Benny Prijono55040452008-07-21 18:20:57 +00002011
2012 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2013 Py_XDECREF(user_data);
2014
2015 status = pjsua_buddy_del(buddy_id);
2016
Benny Prijono9c461142008-07-10 22:41:20 +00002017 return Py_BuildValue("i", status);
2018}
2019
2020/*
Benny Prijono55040452008-07-21 18:20:57 +00002021 * py_pjsua_buddy_set_user_data
2022 */
2023static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs)
2024{
2025 int buddy_id;
2026 int status;
2027 PyObject *user_data, *old_user_data;
2028
2029 PJ_UNUSED_ARG(pSelf);
2030
2031 if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) {
2032 return NULL;
2033 }
2034
2035 old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2036
2037 status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data);
2038
2039 if (status == PJ_SUCCESS) {
2040 Py_XINCREF(user_data);
2041 Py_XDECREF(old_user_data);
2042 }
2043
2044 return Py_BuildValue("i", status);
2045}
2046
2047/*
2048 * py_pjsua_buddy_get_user_data
2049 */
2050static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs)
2051{
2052 int buddy_id;
2053 PyObject *user_data;
2054
2055 PJ_UNUSED_ARG(pSelf);
2056
2057 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2058 return NULL;
2059 }
2060
2061 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2062
2063 return user_data? Py_BuildValue("O", user_data) : Py_BuildValue("");
2064}
2065
2066/*
Benny Prijono9c461142008-07-10 22:41:20 +00002067 * py_pjsua_buddy_subscribe_pres
2068 */
Benny Prijono55040452008-07-21 18:20:57 +00002069static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf,
2070 PyObject *pArgs)
2071{
Benny Prijono9c461142008-07-10 22:41:20 +00002072 int buddy_id;
2073 int status;
2074 int subscribe;
2075
2076 PJ_UNUSED_ARG(pSelf);
2077
2078 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
2079 return NULL;
2080 }
Benny Prijono55040452008-07-21 18:20:57 +00002081
2082 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2083
Benny Prijono9c461142008-07-10 22:41:20 +00002084 return Py_BuildValue("i", status);
2085}
2086
2087/*
2088 * py_pjsua_pres_dump
2089 */
2090static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
2091{
2092 int verbose;
2093
2094 PJ_UNUSED_ARG(pSelf);
2095
2096 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
2097 return NULL;
2098 }
Benny Prijono55040452008-07-21 18:20:57 +00002099
Benny Prijono9c461142008-07-10 22:41:20 +00002100 pjsua_pres_dump(verbose);
Benny Prijono55040452008-07-21 18:20:57 +00002101
2102 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00002103}
2104
2105/*
2106 * py_pjsua_im_send
Benny Prijono9c461142008-07-10 22:41:20 +00002107 */
2108static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
2109{
2110 int status;
2111 int acc_id;
Benny Prijono55040452008-07-21 18:20:57 +00002112 pj_str_t *mime_type, tmp_mime_type;
Benny Prijono9c461142008-07-10 22:41:20 +00002113 pj_str_t to, content;
Benny Prijono55040452008-07-21 18:20:57 +00002114 PyObject *pTo;
2115 PyObject *pMimeType;
2116 PyObject *pContent;
Benny Prijono9c461142008-07-10 22:41:20 +00002117 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00002118 PyObject *pMsgData;
Benny Prijono9c461142008-07-10 22:41:20 +00002119 int user_data;
Benny Prijono55040452008-07-21 18:20:57 +00002120 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002121
2122 PJ_UNUSED_ARG(pSelf);
2123
2124 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
Benny Prijono55040452008-07-21 18:20:57 +00002125 &pTo, &pMimeType, &pContent, &pMsgData, &user_data))
Benny Prijono9c461142008-07-10 22:41:20 +00002126 {
2127 return NULL;
2128 }
Benny Prijono55040452008-07-21 18:20:57 +00002129
2130 if (pMimeType != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00002131 mime_type = &tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00002132 tmp_mime_type = PyString_ToPJ(pMimeType);
Benny Prijono9c461142008-07-10 22:41:20 +00002133 } else {
2134 mime_type = NULL;
2135 }
Benny Prijono9c461142008-07-10 22:41:20 +00002136
Benny Prijono55040452008-07-21 18:20:57 +00002137 to = PyString_ToPJ(pTo);
2138 content = PyString_ToPJ(pContent);
Benny Prijono9c461142008-07-10 22:41:20 +00002139
Benny Prijono55040452008-07-21 18:20:57 +00002140 if (pMsgData != Py_None) {
2141 PyObj_pjsua_msg_data *omd;
2142
2143 omd = (PyObj_pjsua_msg_data *)pMsgData;
2144 msg_data.content_type = PyString_ToPJ(omd->content_type);
2145 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2146 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00002147 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00002148 }
Benny Prijono55040452008-07-21 18:20:57 +00002149
2150 status = pjsua_im_send(acc_id, &to, mime_type, &content,
2151 &msg_data, (void *)user_data);
2152 if (pool)
2153 pj_pool_release(pool);
Benny Prijono9c461142008-07-10 22:41:20 +00002154
2155 return Py_BuildValue("i",status);
2156}
2157
2158/*
2159 * py_pjsua_im_typing
2160 */
2161static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
2162{
2163 int status;
2164 int acc_id;
2165 pj_str_t to;
Benny Prijono55040452008-07-21 18:20:57 +00002166 PyObject *pTo;
Benny Prijono9c461142008-07-10 22:41:20 +00002167 int is_typing;
2168 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00002169 PyObject *pMsgData;
2170 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002171
2172 PJ_UNUSED_ARG(pSelf);
2173
Benny Prijono55040452008-07-21 18:20:57 +00002174 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing,
2175 &pMsgData))
2176 {
Benny Prijono9c461142008-07-10 22:41:20 +00002177 return NULL;
2178 }
2179
Benny Prijono55040452008-07-21 18:20:57 +00002180 to = PyString_ToPJ(pTo);
Benny Prijono9c461142008-07-10 22:41:20 +00002181
Benny Prijono55040452008-07-21 18:20:57 +00002182 if (pMsgData != Py_None) {
2183 PyObj_pjsua_msg_data *omd;
2184
2185 omd = (PyObj_pjsua_msg_data *)pMsgData;
2186 msg_data.content_type = PyString_ToPJ(omd->content_type);
2187 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2188 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00002189
2190 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00002191 }
Benny Prijono55040452008-07-21 18:20:57 +00002192
2193 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
2194
2195 if (pool)
2196 pj_pool_release(pool);
2197
2198 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00002199}
2200
2201static char pjsua_buddy_config_default_doc[] =
2202 "_pjsua.Buddy_Config _pjsua.buddy_config_default () "
2203 "Set default values to the buddy config.";
2204static char pjsua_get_buddy_count_doc[] =
2205 "int _pjsua.get_buddy_count () "
2206 "Get total number of buddies.";
2207static char pjsua_buddy_is_valid_doc[] =
2208 "int _pjsua.buddy_is_valid (int buddy_id) "
2209 "Check if buddy ID is valid.";
2210static char pjsua_enum_buddies_doc[] =
2211 "int[] _pjsua.enum_buddies () "
2212 "Enum buddy IDs.";
2213static char pjsua_buddy_get_info_doc[] =
2214 "_pjsua.Buddy_Info _pjsua.buddy_get_info (int buddy_id) "
2215 "Get detailed buddy info.";
2216static char pjsua_buddy_add_doc[] =
2217 "int,int _pjsua.buddy_add (_pjsua.Buddy_Config cfg) "
2218 "Add new buddy.";
2219static char pjsua_buddy_del_doc[] =
2220 "int _pjsua.buddy_del (int buddy_id) "
2221 "Delete buddy.";
2222static char pjsua_buddy_subscribe_pres_doc[] =
2223 "int _pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
2224 "Enable/disable buddy's presence monitoring.";
2225static char pjsua_pres_dump_doc[] =
2226 "void _pjsua.pres_dump (int verbose) "
2227 "Dump presence subscriptions to log file.";
2228static char pjsua_im_send_doc[] =
2229 "int _pjsua.im_send (int acc_id, string to, string mime_type, "
2230 "string content, _pjsua.Msg_Data msg_data, int user_data) "
2231 "Send instant messaging outside dialog, using the specified account "
2232 "for route set and authentication.";
2233static char pjsua_im_typing_doc[] =
2234 "int _pjsua.im_typing (int acc_id, string to, int is_typing, "
2235 "_pjsua.Msg_Data msg_data) "
2236 "Send typing indication outside dialog.";
2237
2238/* END OF LIB BUDDY */
2239
2240/* LIB MEDIA */
2241
2242
Benny Prijono9c461142008-07-10 22:41:20 +00002243/*
2244 * py_pjsua_conf_get_max_ports
2245 */
Benny Prijono55040452008-07-21 18:20:57 +00002246static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002247{
Benny Prijono9c461142008-07-10 22:41:20 +00002248 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002249 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002250
Benny Prijono55040452008-07-21 18:20:57 +00002251 return Py_BuildValue("i", pjsua_conf_get_max_ports());
Benny Prijono9c461142008-07-10 22:41:20 +00002252}
2253
2254/*
2255 * py_pjsua_conf_get_active_ports
2256 */
Benny Prijono55040452008-07-21 18:20:57 +00002257static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf,
2258 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002259{
Benny Prijono9c461142008-07-10 22:41:20 +00002260 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002261 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002262
Benny Prijono55040452008-07-21 18:20:57 +00002263 return Py_BuildValue("i", pjsua_conf_get_active_ports());
Benny Prijono9c461142008-07-10 22:41:20 +00002264}
2265
2266/*
2267 * py_pjsua_enum_conf_ports
Benny Prijono9c461142008-07-10 22:41:20 +00002268 */
2269static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
2270{
2271 pj_status_t status;
2272 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00002273 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
2274 unsigned c, i;
2275
2276 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002277 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002278
Benny Prijono9c461142008-07-10 22:41:20 +00002279 c = PJ_ARRAY_SIZE(id);
2280 status = pjsua_enum_conf_ports(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002281 if (status != PJ_SUCCESS)
2282 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002283
2284 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00002285 for (i = 0; i < c; i++) {
2286 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00002287 }
2288
Benny Prijono55040452008-07-21 18:20:57 +00002289 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00002290}
2291
2292/*
2293 * py_pjsua_conf_get_port_info
2294 */
Benny Prijono55040452008-07-21 18:20:57 +00002295static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002296{
2297 int id;
Benny Prijono55040452008-07-21 18:20:57 +00002298 PyObj_pjsua_conf_port_info *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002299 pjsua_conf_port_info info;
2300 int status;
2301 unsigned i;
2302
2303 PJ_UNUSED_ARG(pSelf);
2304
Benny Prijono55040452008-07-21 18:20:57 +00002305 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002306 return NULL;
2307 }
Benny Prijono9c461142008-07-10 22:41:20 +00002308
2309 status = pjsua_conf_get_port_info(id, &info);
Benny Prijono55040452008-07-21 18:20:57 +00002310 ret = (PyObj_pjsua_conf_port_info *)
2311 conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL);
2312 ret->bits_per_sample = info.bits_per_sample;
2313 ret->channel_count = info.bits_per_sample;
2314 ret->clock_rate = info.clock_rate;
2315 ret->name = PyString_FromPJ(&info.name);
2316 ret->samples_per_frame = info.samples_per_frame;
2317 ret->slot_id = info.slot_id;
2318 Py_XDECREF(ret->listeners);
2319 ret->listeners = PyList_New(info.listener_cnt);
Benny Prijono9c461142008-07-10 22:41:20 +00002320 for (i = 0; i < info.listener_cnt; i++) {
Benny Prijono55040452008-07-21 18:20:57 +00002321 PyObject *item = Py_BuildValue("i",info.listeners[i]);
2322 PyList_SetItem(ret->listeners, i, item);
Benny Prijono9c461142008-07-10 22:41:20 +00002323 }
Benny Prijono55040452008-07-21 18:20:57 +00002324 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002325}
2326
2327/*
2328 * py_pjsua_conf_remove_port
2329 */
Benny Prijono55040452008-07-21 18:20:57 +00002330static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002331{
2332 int id;
2333 int status;
2334
2335 PJ_UNUSED_ARG(pSelf);
2336
Benny Prijono55040452008-07-21 18:20:57 +00002337 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002338 return NULL;
2339 }
2340
2341 status = pjsua_conf_remove_port(id);
2342
Benny Prijono9c461142008-07-10 22:41:20 +00002343 return Py_BuildValue("i", status);
2344}
2345
2346/*
2347 * py_pjsua_conf_connect
2348 */
Benny Prijono55040452008-07-21 18:20:57 +00002349static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002350{
2351 int source, sink;
2352 int status;
2353
2354 PJ_UNUSED_ARG(pSelf);
2355
Benny Prijono55040452008-07-21 18:20:57 +00002356 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002357 return NULL;
2358 }
2359
2360 status = pjsua_conf_connect(source, sink);
2361
Benny Prijono9c461142008-07-10 22:41:20 +00002362 return Py_BuildValue("i", status);
2363}
2364
2365/*
2366 * py_pjsua_conf_disconnect
2367 */
Benny Prijono55040452008-07-21 18:20:57 +00002368static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002369{
2370 int source, sink;
2371 int status;
2372
2373 PJ_UNUSED_ARG(pSelf);
2374
Benny Prijono55040452008-07-21 18:20:57 +00002375 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002376 return NULL;
2377 }
2378
2379 status = pjsua_conf_disconnect(source, sink);
2380
Benny Prijono9c461142008-07-10 22:41:20 +00002381 return Py_BuildValue("i", status);
2382}
2383
2384/*
Benny Prijono288d4bd2008-07-19 15:40:21 +00002385 * py_pjsua_conf_set_tx_level
2386 */
Benny Prijono55040452008-07-21 18:20:57 +00002387static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002388{
2389 int slot;
2390 float level;
2391 int status;
2392
2393 PJ_UNUSED_ARG(pSelf);
2394
Benny Prijono55040452008-07-21 18:20:57 +00002395 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002396 return NULL;
2397 }
2398
2399 status = pjsua_conf_adjust_tx_level(slot, level);
2400
Benny Prijono288d4bd2008-07-19 15:40:21 +00002401 return Py_BuildValue("i", status);
2402}
2403
2404/*
2405 * py_pjsua_conf_set_rx_level
2406 */
Benny Prijono55040452008-07-21 18:20:57 +00002407static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002408{
2409 int slot;
2410 float level;
2411 int status;
2412
2413 PJ_UNUSED_ARG(pSelf);
2414
Benny Prijono55040452008-07-21 18:20:57 +00002415 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002416 return NULL;
2417 }
2418
2419 status = pjsua_conf_adjust_rx_level(slot, level);
2420
Benny Prijono288d4bd2008-07-19 15:40:21 +00002421 return Py_BuildValue("i", status);
2422}
2423
2424/*
2425 * py_pjsua_conf_get_signal_level
2426 */
Benny Prijono55040452008-07-21 18:20:57 +00002427static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf,
2428 PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002429{
2430 int slot;
2431 unsigned tx_level, rx_level;
2432 int status;
2433
2434 PJ_UNUSED_ARG(pSelf);
2435
Benny Prijono55040452008-07-21 18:20:57 +00002436 if (!PyArg_ParseTuple(pArgs, "i", &slot)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002437 return NULL;
2438 }
2439
2440 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level);
2441
Benny Prijono288d4bd2008-07-19 15:40:21 +00002442 return Py_BuildValue("iff", status, (float)(tx_level/255.0),
Benny Prijono55040452008-07-21 18:20:57 +00002443 (float)(rx_level/255.0));
Benny Prijono288d4bd2008-07-19 15:40:21 +00002444}
2445
2446/*
Benny Prijono9c461142008-07-10 22:41:20 +00002447 * py_pjsua_player_create
2448 */
Benny Prijono55040452008-07-21 18:20:57 +00002449static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002450{
2451 int id;
2452 int options;
Benny Prijono55040452008-07-21 18:20:57 +00002453 PyObject *pFilename;
2454 pj_str_t filename;
Benny Prijono9c461142008-07-10 22:41:20 +00002455 int status;
2456
2457 PJ_UNUSED_ARG(pSelf);
2458
Benny Prijono55040452008-07-21 18:20:57 +00002459 if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002460 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002461 }
2462
2463 filename = PyString_ToPJ(pFilename);
2464 status = pjsua_player_create(&filename, options, &id);
Benny Prijono9c461142008-07-10 22:41:20 +00002465
2466 return Py_BuildValue("ii", status, id);
2467}
2468
2469/*
Benny Prijono288d4bd2008-07-19 15:40:21 +00002470 * py_pjsua_playlist_create
2471 */
Benny Prijono55040452008-07-21 18:20:57 +00002472static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002473{
2474 int id;
2475 int options;
Benny Prijono55040452008-07-21 18:20:57 +00002476 PyObject *pLabel, *pFileList;
Benny Prijono288d4bd2008-07-19 15:40:21 +00002477 pj_str_t label;
2478 int count;
2479 pj_str_t files[64];
2480 int status;
2481
2482 PJ_UNUSED_ARG(pSelf);
2483
Benny Prijono55040452008-07-21 18:20:57 +00002484 if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002485 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002486 }
Benny Prijono288d4bd2008-07-19 15:40:21 +00002487
Benny Prijono55040452008-07-21 18:20:57 +00002488 label = PyString_ToPJ(pLabel);
2489 if (!PyList_Check(pFileList))
2490 return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID);
Benny Prijono288d4bd2008-07-19 15:40:21 +00002491
2492 count = 0;
Benny Prijono55040452008-07-21 18:20:57 +00002493 for (count=0; count<PyList_Size(pFileList) &&
Benny Prijono288d4bd2008-07-19 15:40:21 +00002494 count<PJ_ARRAY_SIZE(files); ++count)
2495 {
Benny Prijono55040452008-07-21 18:20:57 +00002496 files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count));
Benny Prijono288d4bd2008-07-19 15:40:21 +00002497 }
2498
2499 status = pjsua_playlist_create(files, count, &label, options, &id);
2500
2501 return Py_BuildValue("ii", status, id);
2502}
2503
2504/*
Benny Prijono9c461142008-07-10 22:41:20 +00002505 * py_pjsua_player_get_conf_port
2506 */
Benny Prijono55040452008-07-21 18:20:57 +00002507static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf,
2508 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002509{
2510
2511 int id, port_id;
2512
2513 PJ_UNUSED_ARG(pSelf);
2514
Benny Prijono55040452008-07-21 18:20:57 +00002515 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002516 return NULL;
2517 }
2518
2519 port_id = pjsua_player_get_conf_port(id);
2520
Benny Prijono9c461142008-07-10 22:41:20 +00002521 return Py_BuildValue("i", port_id);
2522}
2523
2524/*
2525 * py_pjsua_player_set_pos
2526 */
Benny Prijono55040452008-07-21 18:20:57 +00002527static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002528{
2529 int id;
Benny Prijono55040452008-07-21 18:20:57 +00002530 int samples;
Benny Prijono9c461142008-07-10 22:41:20 +00002531 int status;
2532
2533 PJ_UNUSED_ARG(pSelf);
2534
Benny Prijono55040452008-07-21 18:20:57 +00002535 if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002536 return NULL;
2537 }
2538
Benny Prijono55040452008-07-21 18:20:57 +00002539 if (samples < 0)
2540 samples = 0;
2541
Benny Prijono9c461142008-07-10 22:41:20 +00002542 status = pjsua_player_set_pos(id, samples);
2543
Benny Prijono9c461142008-07-10 22:41:20 +00002544 return Py_BuildValue("i", status);
2545}
2546
2547/*
2548 * py_pjsua_player_destroy
2549 */
Benny Prijono55040452008-07-21 18:20:57 +00002550static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002551{
2552 int id;
2553 int status;
2554
2555 PJ_UNUSED_ARG(pSelf);
2556
Benny Prijono55040452008-07-21 18:20:57 +00002557 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002558 return NULL;
2559 }
2560
2561 status = pjsua_player_destroy(id);
2562
Benny Prijono9c461142008-07-10 22:41:20 +00002563 return Py_BuildValue("i", status);
2564}
2565
2566/*
2567 * py_pjsua_recorder_create
Benny Prijono9c461142008-07-10 22:41:20 +00002568 */
Benny Prijono55040452008-07-21 18:20:57 +00002569static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002570{
Benny Prijono55040452008-07-21 18:20:57 +00002571 int id, options;
Benny Prijono9c461142008-07-10 22:41:20 +00002572 int max_size;
Benny Prijono55040452008-07-21 18:20:57 +00002573 PyObject *pFilename, *pEncParam;
2574 pj_str_t filename;
Benny Prijono9c461142008-07-10 22:41:20 +00002575 int enc_type;
2576
2577 int status;
2578
2579 PJ_UNUSED_ARG(pSelf);
2580
Benny Prijono55040452008-07-21 18:20:57 +00002581 if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam,
2582 &max_size, &options))
Benny Prijono9c461142008-07-10 22:41:20 +00002583 {
2584 return NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002585 }
Benny Prijono55040452008-07-21 18:20:57 +00002586
2587 filename = PyString_ToPJ(pFilename);
2588
2589 status = pjsua_recorder_create(&filename, enc_type, NULL, max_size,
2590 options, &id);
2591
2592 return Py_BuildValue("ii", status, id);
Benny Prijono9c461142008-07-10 22:41:20 +00002593}
2594
2595/*
2596 * py_pjsua_recorder_get_conf_port
2597 */
Benny Prijono55040452008-07-21 18:20:57 +00002598static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf,
2599 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002600{
2601
2602 int id, port_id;
2603
2604 PJ_UNUSED_ARG(pSelf);
2605
Benny Prijono55040452008-07-21 18:20:57 +00002606 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002607 return NULL;
2608 }
2609
2610 port_id = pjsua_recorder_get_conf_port(id);
2611
Benny Prijono9c461142008-07-10 22:41:20 +00002612 return Py_BuildValue("i", port_id);
2613}
2614
2615/*
2616 * py_pjsua_recorder_destroy
2617 */
Benny Prijono55040452008-07-21 18:20:57 +00002618static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002619{
2620 int id;
2621 int status;
2622
2623 PJ_UNUSED_ARG(pSelf);
2624
Benny Prijono55040452008-07-21 18:20:57 +00002625 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002626 return NULL;
2627 }
2628
2629 status = pjsua_recorder_destroy(id);
2630
Benny Prijono9c461142008-07-10 22:41:20 +00002631 return Py_BuildValue("i", status);
2632}
2633
2634/*
2635 * py_pjsua_enum_snd_devs
2636 */
2637static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
2638{
2639 pj_status_t status;
Benny Prijono55040452008-07-21 18:20:57 +00002640 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002641 pjmedia_snd_dev_info info[SND_DEV_NUM];
2642 unsigned c, i;
2643
2644 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002645 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002646
Benny Prijono9c461142008-07-10 22:41:20 +00002647 c = PJ_ARRAY_SIZE(info);
2648 status = pjsua_enum_snd_devs(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002649 if (status != PJ_SUCCESS)
2650 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002651
Benny Prijono55040452008-07-21 18:20:57 +00002652 ret = PyList_New(c);
2653 for (i = 0; i < c; i++) {
Benny Prijono9c461142008-07-10 22:41:20 +00002654 PyObj_pjmedia_snd_dev_info * obj;
Benny Prijono55040452008-07-21 18:20:57 +00002655
2656 obj = (PyObj_pjmedia_snd_dev_info *)
2657 pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info,
2658 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00002659 obj->default_samples_per_sec = info[i].default_samples_per_sec;
2660 obj->input_count = info[i].input_count;
2661 obj->output_count = info[i].output_count;
Benny Prijono55040452008-07-21 18:20:57 +00002662 obj->name = PyString_FromString(info[i].name);
2663
2664 PyList_SetItem(ret, i, (PyObject *)obj);
Benny Prijono9c461142008-07-10 22:41:20 +00002665 }
2666
Benny Prijono55040452008-07-21 18:20:57 +00002667 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002668}
2669
2670/*
2671 * py_pjsua_get_snd_dev
2672 */
Benny Prijono55040452008-07-21 18:20:57 +00002673static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002674{
2675 int capture_dev, playback_dev;
2676 int status;
2677
2678 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002679 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002680
Benny Prijono9c461142008-07-10 22:41:20 +00002681 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
2682
Benny Prijono9c461142008-07-10 22:41:20 +00002683 return Py_BuildValue("ii", capture_dev, playback_dev);
2684}
2685
2686/*
2687 * py_pjsua_set_snd_dev
2688 */
Benny Prijono55040452008-07-21 18:20:57 +00002689static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002690{
2691 int capture_dev, playback_dev;
2692 int status;
2693
2694 PJ_UNUSED_ARG(pSelf);
2695
Benny Prijono55040452008-07-21 18:20:57 +00002696 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002697 return NULL;
2698 }
2699
2700 status = pjsua_set_snd_dev(capture_dev, playback_dev);
2701
Benny Prijono9c461142008-07-10 22:41:20 +00002702 return Py_BuildValue("i", status);
2703}
2704
2705/*
2706 * py_pjsua_set_null_snd_dev
2707 */
Benny Prijono55040452008-07-21 18:20:57 +00002708static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002709{
Benny Prijono9c461142008-07-10 22:41:20 +00002710 int status;
Benny Prijono9c461142008-07-10 22:41:20 +00002711
Benny Prijono55040452008-07-21 18:20:57 +00002712 PJ_UNUSED_ARG(pSelf);
2713 PJ_UNUSED_ARG(pArgs);
2714
Benny Prijono9c461142008-07-10 22:41:20 +00002715 status = pjsua_set_null_snd_dev();
Benny Prijono55040452008-07-21 18:20:57 +00002716
Benny Prijono9c461142008-07-10 22:41:20 +00002717 return Py_BuildValue("i", status);
2718}
2719
2720/*
Benny Prijono9c461142008-07-10 22:41:20 +00002721 * py_pjsua_set_ec
2722 */
Benny Prijono55040452008-07-21 18:20:57 +00002723static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002724{
2725 int options;
2726 int tail_ms;
2727 int status;
2728
2729 PJ_UNUSED_ARG(pSelf);
2730
Benny Prijono55040452008-07-21 18:20:57 +00002731 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002732 return NULL;
2733 }
Benny Prijono55040452008-07-21 18:20:57 +00002734
Benny Prijono9c461142008-07-10 22:41:20 +00002735 status = pjsua_set_ec(tail_ms, options);
2736
Benny Prijono9c461142008-07-10 22:41:20 +00002737 return Py_BuildValue("i", status);
2738}
2739
2740/*
2741 * py_pjsua_get_ec_tail
2742 */
Benny Prijono55040452008-07-21 18:20:57 +00002743static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002744{
Benny Prijono9c461142008-07-10 22:41:20 +00002745 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002746 unsigned tail_ms;
Benny Prijono9c461142008-07-10 22:41:20 +00002747
2748 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002749 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002750
Benny Prijono55040452008-07-21 18:20:57 +00002751 status = pjsua_get_ec_tail(&tail_ms);
2752 if (status != PJ_SUCCESS)
2753 tail_ms = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002754
Benny Prijono55040452008-07-21 18:20:57 +00002755 return Py_BuildValue("i", tail_ms);
Benny Prijono9c461142008-07-10 22:41:20 +00002756}
2757
2758/*
2759 * py_pjsua_enum_codecs
Benny Prijono9c461142008-07-10 22:41:20 +00002760 */
2761static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
2762{
2763 pj_status_t status;
Benny Prijono55040452008-07-21 18:20:57 +00002764 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002765 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
2766 unsigned c, i;
2767
2768 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002769 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002770
Benny Prijono9c461142008-07-10 22:41:20 +00002771 c = PJ_ARRAY_SIZE(info);
2772 status = pjsua_enum_codecs(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002773 if (status != PJ_SUCCESS)
2774 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002775
Benny Prijono55040452008-07-21 18:20:57 +00002776 ret = PyList_New(c);
2777 for (i = 0; i < c; i++) {
Benny Prijono9c461142008-07-10 22:41:20 +00002778 PyObj_pjsua_codec_info * obj;
Benny Prijono55040452008-07-21 18:20:57 +00002779 obj = (PyObj_pjsua_codec_info *)
2780 codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL);
2781 obj->codec_id = PyString_FromPJ(&info[i].codec_id);
Benny Prijono9c461142008-07-10 22:41:20 +00002782 obj->priority = info[i].priority;
Benny Prijono9c461142008-07-10 22:41:20 +00002783
Benny Prijono55040452008-07-21 18:20:57 +00002784 PyList_SetItem(ret, i, (PyObject *)obj);
2785 }
2786
2787 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002788}
2789
2790/*
2791 * py_pjsua_codec_set_priority
2792 */
Benny Prijono55040452008-07-21 18:20:57 +00002793static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002794{
Benny Prijono9c461142008-07-10 22:41:20 +00002795 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002796 PyObject *pCodecId;
2797 pj_str_t codec_id;
2798 int priority;
Benny Prijono9c461142008-07-10 22:41:20 +00002799
2800 PJ_UNUSED_ARG(pSelf);
2801
Benny Prijono55040452008-07-21 18:20:57 +00002802 if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002803 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002804 }
2805
2806 codec_id = PyString_ToPJ(pCodecId);
2807 if (priority < 0)
2808 priority = 0;
2809 if (priority > 255)
2810 priority = 255;
2811
2812 status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority);
Benny Prijono9c461142008-07-10 22:41:20 +00002813
2814 return Py_BuildValue("i", status);
2815}
2816
2817/*
2818 * py_pjsua_codec_get_param
2819 */
Benny Prijono55040452008-07-21 18:20:57 +00002820static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002821{
Benny Prijono9c461142008-07-10 22:41:20 +00002822 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002823 PyObject *pCodecId;
2824 pj_str_t codec_id;
Benny Prijono9c461142008-07-10 22:41:20 +00002825 pjmedia_codec_param param;
Benny Prijono55040452008-07-21 18:20:57 +00002826 PyObj_pjmedia_codec_param *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002827
2828 PJ_UNUSED_ARG(pSelf);
2829
Benny Prijono55040452008-07-21 18:20:57 +00002830 if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002831 return NULL;
2832 }
Benny Prijono9c461142008-07-10 22:41:20 +00002833
Benny Prijono55040452008-07-21 18:20:57 +00002834 codec_id = PyString_ToPJ(pCodecId);
2835
2836 status = pjsua_codec_get_param(&codec_id, &param);
2837 if (status != PJ_SUCCESS)
2838 return Py_BuildValue("");
2839
2840 ret = (PyObj_pjmedia_codec_param *)
2841 pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL);
2842
2843 ret->info->avg_bps = param.info.avg_bps;
2844 ret->info->channel_cnt = param.info.channel_cnt;
2845 ret->info->clock_rate = param.info.clock_rate;
2846 ret->info->frm_ptime = param.info.frm_ptime;
2847 ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
2848 ret->info->pt = param.info.pt;
2849 ret->setting->cng = param.setting.cng;
2850 ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
2851 ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
2852 ret->setting->frm_per_pkt = param.setting.frm_per_pkt;
2853 ret->setting->penh = param.setting.penh;
2854 ret->setting->plc = param.setting.plc;
2855 ret->setting->vad = param.setting.vad;
2856
2857 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002858}
Benny Prijono55040452008-07-21 18:20:57 +00002859
2860
Benny Prijono9c461142008-07-10 22:41:20 +00002861/*
2862 * py_pjsua_codec_set_param
2863 */
Benny Prijono55040452008-07-21 18:20:57 +00002864static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002865{
Benny Prijono9c461142008-07-10 22:41:20 +00002866 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002867 PyObject *pCodecId, *pCodecParam;
2868 pj_str_t codec_id;
Benny Prijono9c461142008-07-10 22:41:20 +00002869 pjmedia_codec_param param;
Benny Prijono9c461142008-07-10 22:41:20 +00002870
2871 PJ_UNUSED_ARG(pSelf);
2872
Benny Prijono55040452008-07-21 18:20:57 +00002873 if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002874 return NULL;
2875 }
2876
Benny Prijono55040452008-07-21 18:20:57 +00002877 codec_id = PyString_ToPJ(pCodecId);
2878
2879 if (pCodecParam != Py_None) {
2880 PyObj_pjmedia_codec_param *obj;
2881
2882 obj = (PyObj_pjmedia_codec_param *)pCodecParam;
2883
Benny Prijono9c461142008-07-10 22:41:20 +00002884 param.info.avg_bps = obj->info->avg_bps;
2885 param.info.channel_cnt = obj->info->channel_cnt;
2886 param.info.clock_rate = obj->info->clock_rate;
2887 param.info.frm_ptime = obj->info->frm_ptime;
2888 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
2889 param.info.pt = obj->info->pt;
2890 param.setting.cng = obj->setting->cng;
2891 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
2892 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
2893 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
2894 param.setting.penh = obj->setting->penh;
2895 param.setting.plc = obj->setting->plc;
Benny Prijono9c461142008-07-10 22:41:20 +00002896 param.setting.vad = obj->setting->vad;
Benny Prijono55040452008-07-21 18:20:57 +00002897 status = pjsua_codec_set_param(&codec_id, &param);
2898
Benny Prijono9c461142008-07-10 22:41:20 +00002899 } else {
Benny Prijono55040452008-07-21 18:20:57 +00002900 status = pjsua_codec_set_param(&codec_id, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00002901 }
Benny Prijono55040452008-07-21 18:20:57 +00002902
Benny Prijono9c461142008-07-10 22:41:20 +00002903 return Py_BuildValue("i", status);
2904}
2905
2906static char pjsua_conf_get_max_ports_doc[] =
2907 "int _pjsua.conf_get_max_ports () "
2908 "Get maxinum number of conference ports.";
2909static char pjsua_conf_get_active_ports_doc[] =
2910 "int _pjsua.conf_get_active_ports () "
2911 "Get current number of active ports in the bridge.";
2912static char pjsua_enum_conf_ports_doc[] =
2913 "int[] _pjsua.enum_conf_ports () "
2914 "Enumerate all conference ports.";
2915static char pjsua_conf_get_port_info_doc[] =
2916 "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) "
2917 "Get information about the specified conference port";
Benny Prijono9c461142008-07-10 22:41:20 +00002918static char pjsua_conf_remove_port_doc[] =
2919 "int _pjsua.conf_remove_port (int id) "
2920 "Remove arbitrary slot from the conference bridge. "
2921 "Application should only call this function "
2922 "if it registered the port manually.";
2923static char pjsua_conf_connect_doc[] =
2924 "int _pjsua.conf_connect (int source, int sink) "
2925 "Establish unidirectional media flow from souce to sink. "
2926 "One source may transmit to multiple destinations/sink. "
2927 "And if multiple sources are transmitting to the same sink, "
2928 "the media will be mixed together. Source and sink may refer "
2929 "to the same ID, effectively looping the media. "
2930 "If bidirectional media flow is desired, application "
2931 "needs to call this function twice, with the second "
2932 "one having the arguments reversed.";
2933static char pjsua_conf_disconnect_doc[] =
2934 "int _pjsua.conf_disconnect (int source, int sink) "
2935 "Disconnect media flow from the source to destination port.";
2936static char pjsua_player_create_doc[] =
2937 "int, int _pjsua.player_create (string filename, int options) "
2938 "Create a file player, and automatically connect "
2939 "this player to the conference bridge.";
2940static char pjsua_player_get_conf_port_doc[] =
2941 "int _pjsua.player_get_conf_port (int) "
2942 "Get conference port ID associated with player.";
2943static char pjsua_player_set_pos_doc[] =
2944 "int _pjsua.player_set_pos (int id, int samples) "
2945 "Set playback position.";
2946static char pjsua_player_destroy_doc[] =
2947 "int _pjsua.player_destroy (int id) "
2948 "Close the file, remove the player from the bridge, "
2949 "and free resources associated with the file player.";
2950static char pjsua_recorder_create_doc[] =
2951 "int, int _pjsua.recorder_create (string filename, "
2952 "int enc_type, int enc_param, int max_size, int options) "
2953 "Create a file recorder, and automatically connect this recorder "
2954 "to the conference bridge. The recorder currently supports recording "
2955 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
2956 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
2957static char pjsua_recorder_get_conf_port_doc[] =
2958 "int _pjsua.recorder_get_conf_port (int id) "
2959 "Get conference port associated with recorder.";
2960static char pjsua_recorder_destroy_doc[] =
2961 "int _pjsua.recorder_destroy (int id) "
2962 "Destroy recorder (this will complete recording).";
2963static char pjsua_enum_snd_devs_doc[] =
2964 "_pjsua.PJMedia_Snd_Dev_Info[] _pjsua.enum_snd_devs (int count) "
2965 "Enum sound devices.";
2966static char pjsua_get_snd_dev_doc[] =
2967 "int, int _pjsua.get_snd_dev () "
2968 "Get currently active sound devices. "
2969 "If sound devices has not been created "
2970 "(for example when pjsua_start() is not called), "
2971 "it is possible that the function returns "
2972 "PJ_SUCCESS with -1 as device IDs.";
2973static char pjsua_set_snd_dev_doc[] =
2974 "int _pjsua.set_snd_dev (int capture_dev, int playback_dev) "
2975 "Select or change sound device. Application may call this function "
2976 "at any time to replace current sound device.";
2977static char pjsua_set_null_snd_dev_doc[] =
2978 "int _pjsua.set_null_snd_dev () "
2979 "Set pjsua to use null sound device. The null sound device only "
2980 "provides the timing needed by the conference bridge, and will not "
2981 "interract with any hardware.";
Benny Prijono9c461142008-07-10 22:41:20 +00002982static char pjsua_set_ec_doc[] =
2983 "int _pjsua.set_ec (int tail_ms, int options) "
2984 "Configure the echo canceller tail length of the sound port.";
2985static char pjsua_get_ec_tail_doc[] =
2986 "int _pjsua.get_ec_tail () "
2987 "Get current echo canceller tail length.";
2988static char pjsua_enum_codecs_doc[] =
2989 "_pjsua.Codec_Info[] _pjsua.enum_codecs () "
2990 "Enum all supported codecs in the system.";
2991static char pjsua_codec_set_priority_doc[] =
2992 "int _pjsua.codec_set_priority (string id, int priority) "
2993 "Change codec priority.";
2994static char pjsua_codec_get_param_doc[] =
2995 "_pjsua.PJMedia_Codec_Param _pjsua.codec_get_param (string id) "
2996 "Get codec parameters";
2997static char pjsua_codec_set_param_doc[] =
2998 "int _pjsua.codec_set_param (string id, "
2999 "_pjsua.PJMedia_Codec_Param param) "
3000 "Set codec parameters.";
3001
3002/* END OF LIB MEDIA */
3003
3004/* LIB CALL */
3005
3006/*
Benny Prijono9c461142008-07-10 22:41:20 +00003007 * py_pjsua_call_get_max_count
3008 */
Benny Prijono55040452008-07-21 18:20:57 +00003009static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003010{
3011 int count;
3012
3013 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003014 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003015
Benny Prijono9c461142008-07-10 22:41:20 +00003016 count = pjsua_call_get_max_count();
3017
Benny Prijono9c461142008-07-10 22:41:20 +00003018 return Py_BuildValue("i", count);
3019}
3020
3021/*
3022 * py_pjsua_call_get_count
3023 */
Benny Prijono55040452008-07-21 18:20:57 +00003024static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003025{
Benny Prijono9c461142008-07-10 22:41:20 +00003026 int count;
3027
3028 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003029 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003030
Benny Prijono9c461142008-07-10 22:41:20 +00003031 count = pjsua_call_get_count();
3032
Benny Prijono9c461142008-07-10 22:41:20 +00003033 return Py_BuildValue("i", count);
3034}
3035
3036/*
3037 * py_pjsua_enum_calls
3038 */
3039static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
3040{
3041 pj_status_t status;
Benny Prijono55040452008-07-21 18:20:57 +00003042 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003043 pjsua_transport_id id[PJSUA_MAX_CALLS];
3044 unsigned c, i;
3045
3046 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003047 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003048
Benny Prijono9c461142008-07-10 22:41:20 +00003049 c = PJ_ARRAY_SIZE(id);
3050 status = pjsua_enum_calls(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00003051 if (status != PJ_SUCCESS)
3052 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00003053
Benny Prijono55040452008-07-21 18:20:57 +00003054 ret = PyList_New(c);
3055 for (i = 0; i < c; i++) {
3056 PyList_SetItem(ret, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00003057 }
3058
Benny Prijono55040452008-07-21 18:20:57 +00003059 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003060}
3061
3062/*
3063 * py_pjsua_call_make_call
3064 */
Benny Prijono55040452008-07-21 18:20:57 +00003065static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003066{
3067 int status;
3068 int acc_id;
3069 pj_str_t dst_uri;
Benny Prijono55040452008-07-21 18:20:57 +00003070 PyObject *pDstUri, *pMsgData, *pUserData;
Benny Prijono9c461142008-07-10 22:41:20 +00003071 unsigned options;
3072 pjsua_msg_data msg_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003073 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003074 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003075
3076 PJ_UNUSED_ARG(pSelf);
3077
Benny Prijono55040452008-07-21 18:20:57 +00003078 if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &options,
3079 &pUserData, &pMsgData))
Benny Prijono9c461142008-07-10 22:41:20 +00003080 {
3081 return NULL;
3082 }
3083
Benny Prijono55040452008-07-21 18:20:57 +00003084 dst_uri = PyString_ToPJ(pDstUri);
3085 pjsua_msg_data_init(&msg_data);
3086
3087 if (pMsgData != Py_None) {
3088 PyObj_pjsua_msg_data * omd;
3089
3090 omd = (PyObj_pjsua_msg_data *)pMsgData;
3091
3092 msg_data.content_type = PyString_ToPJ(omd->content_type);
3093 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3094 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003095 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003096 }
Benny Prijono55040452008-07-21 18:20:57 +00003097
3098 Py_XINCREF(pUserData);
3099
3100 status = pjsua_call_make_call(acc_id, &dst_uri,
3101 options, (void*)pUserData,
3102 &msg_data, &call_id);
3103 if (pool != NULL)
3104 pj_pool_release(pool);
3105
Benny Prijono680c39e2008-07-21 21:15:46 +00003106 if (status != PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00003107 Py_XDECREF(pUserData);
Benny Prijono680c39e2008-07-21 21:15:46 +00003108 }
Benny Prijono55040452008-07-21 18:20:57 +00003109
3110 return Py_BuildValue("ii", status, call_id);
Benny Prijono9c461142008-07-10 22:41:20 +00003111}
3112
3113/*
3114 * py_pjsua_call_is_active
3115 */
Benny Prijono55040452008-07-21 18:20:57 +00003116static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003117{
3118 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003119 int is_active;
Benny Prijono9c461142008-07-10 22:41:20 +00003120
3121 PJ_UNUSED_ARG(pSelf);
3122
Benny Prijono55040452008-07-21 18:20:57 +00003123 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003124 return NULL;
3125 }
3126
Benny Prijono55040452008-07-21 18:20:57 +00003127 is_active = pjsua_call_is_active(call_id);
Benny Prijono9c461142008-07-10 22:41:20 +00003128
Benny Prijono55040452008-07-21 18:20:57 +00003129 return Py_BuildValue("i", is_active);
Benny Prijono9c461142008-07-10 22:41:20 +00003130}
3131
3132/*
3133 * py_pjsua_call_has_media
3134 */
Benny Prijono55040452008-07-21 18:20:57 +00003135static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003136{
3137 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003138 int has_media;
Benny Prijono9c461142008-07-10 22:41:20 +00003139
3140 PJ_UNUSED_ARG(pSelf);
3141
Benny Prijono55040452008-07-21 18:20:57 +00003142 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003143 return NULL;
3144 }
3145
Benny Prijono55040452008-07-21 18:20:57 +00003146 has_media = pjsua_call_has_media(call_id);
3147
3148 return Py_BuildValue("i", has_media);
Benny Prijono9c461142008-07-10 22:41:20 +00003149}
3150
3151/*
3152 * py_pjsua_call_get_conf_port
3153 */
Benny Prijono55040452008-07-21 18:20:57 +00003154static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003155{
3156 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003157 int port_id;
3158
Benny Prijono9c461142008-07-10 22:41:20 +00003159 PJ_UNUSED_ARG(pSelf);
3160
Benny Prijono55040452008-07-21 18:20:57 +00003161 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003162 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003163 }
3164
Benny Prijono9c461142008-07-10 22:41:20 +00003165 port_id = pjsua_call_get_conf_port(call_id);
Benny Prijono55040452008-07-21 18:20:57 +00003166
Benny Prijono9c461142008-07-10 22:41:20 +00003167 return Py_BuildValue("i", port_id);
3168}
3169
3170/*
3171 * py_pjsua_call_get_info
3172 */
Benny Prijono55040452008-07-21 18:20:57 +00003173static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003174{
3175 int call_id;
3176 int status;
Benny Prijono55040452008-07-21 18:20:57 +00003177 PyObj_pjsua_call_info *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003178 pjsua_call_info info;
3179
3180 PJ_UNUSED_ARG(pSelf);
3181
Benny Prijono55040452008-07-21 18:20:57 +00003182 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003183 return NULL;
3184 }
3185
Benny Prijono9c461142008-07-10 22:41:20 +00003186 status = pjsua_call_get_info(call_id, &info);
Benny Prijono55040452008-07-21 18:20:57 +00003187 if (status != PJ_SUCCESS)
3188 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003189
Benny Prijono55040452008-07-21 18:20:57 +00003190 ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info,
3191 NULL, NULL);
3192 ret->acc_id = info.acc_id;
3193 Py_XDECREF(ret->call_id);
3194 ret->call_id = PyString_FromPJ(&info.call_id);
3195 ret->conf_slot = info.conf_slot;
3196 ret->connect_duration = info.connect_duration.sec * 1000 +
3197 info.connect_duration.msec;
3198 ret->total_duration = info.total_duration.sec * 1000 +
3199 info.total_duration.msec;
3200 ret->id = info.id;
3201 ret->last_status = info.last_status;
3202 Py_XDECREF(ret->last_status_text);
3203 ret->last_status_text = PyString_FromPJ(&info.last_status_text);
3204 Py_XDECREF(ret->local_contact);
3205 ret->local_contact = PyString_FromPJ(&info.local_contact);
3206 Py_XDECREF(ret->local_info);
3207 ret->local_info = PyString_FromPJ(&info.local_info);
3208 Py_XDECREF(ret->remote_contact);
3209 ret->remote_contact = PyString_FromPJ(&info.remote_contact);
3210 Py_XDECREF(ret->remote_info);
3211 ret->remote_info = PyString_FromPJ(&info.remote_info);
3212 ret->media_dir = info.media_dir;
3213 ret->media_status = info.media_status;
3214 ret->role = info.role;
3215 ret->state = info.state;
3216 Py_XDECREF(ret->state_text);
3217 ret->state_text = PyString_FromPJ(&info.state_text);
Benny Prijono9c461142008-07-10 22:41:20 +00003218
Benny Prijono55040452008-07-21 18:20:57 +00003219 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003220}
3221
3222/*
3223 * py_pjsua_call_set_user_data
3224 */
Benny Prijono55040452008-07-21 18:20:57 +00003225static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003226{
3227 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003228 PyObject *pUserData, *old_user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003229 int status;
3230
3231 PJ_UNUSED_ARG(pSelf);
3232
Benny Prijono55040452008-07-21 18:20:57 +00003233 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003234 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003235 }
3236
3237 old_user_data = (PyObject*) pjsua_call_get_user_data(call_id);
3238
3239 if (old_user_data == pUserData) {
3240 return Py_BuildValue("i", PJ_SUCCESS);
3241 }
3242
3243 Py_XINCREF(pUserData);
3244 Py_XDECREF(old_user_data);
3245
3246 status = pjsua_call_set_user_data(call_id, (void*)pUserData);
Benny Prijono9c461142008-07-10 22:41:20 +00003247
Benny Prijono680c39e2008-07-21 21:15:46 +00003248 if (status != PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00003249 Py_XDECREF(pUserData);
Benny Prijono680c39e2008-07-21 21:15:46 +00003250 }
Benny Prijono55040452008-07-21 18:20:57 +00003251
Benny Prijono9c461142008-07-10 22:41:20 +00003252 return Py_BuildValue("i", status);
3253}
3254
3255/*
3256 * py_pjsua_call_get_user_data
3257 */
Benny Prijono55040452008-07-21 18:20:57 +00003258static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003259{
3260 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003261 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003262
3263 PJ_UNUSED_ARG(pSelf);
3264
Benny Prijono55040452008-07-21 18:20:57 +00003265 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003266 return NULL;
3267 }
3268
Benny Prijono55040452008-07-21 18:20:57 +00003269 user_data = (PyObject*)pjsua_call_get_user_data(call_id);
3270 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003271}
3272
3273/*
3274 * py_pjsua_call_answer
3275 */
Benny Prijono55040452008-07-21 18:20:57 +00003276static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003277{
3278 int status;
3279 int call_id;
3280 pj_str_t * reason, tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003281 PyObject *pReason;
Benny Prijono9c461142008-07-10 22:41:20 +00003282 unsigned code;
3283 pjsua_msg_data msg_data;
3284 PyObject * omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003285 pj_pool_t * pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003286
3287 PJ_UNUSED_ARG(pSelf);
3288
Benny Prijono55040452008-07-21 18:20:57 +00003289 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003290 return NULL;
3291 }
Benny Prijono55040452008-07-21 18:20:57 +00003292
3293 if (pReason == Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00003294 reason = NULL;
3295 } else {
3296 reason = &tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003297 tmp_reason = PyString_ToPJ(pReason);
Benny Prijono9c461142008-07-10 22:41:20 +00003298 }
Benny Prijono55040452008-07-21 18:20:57 +00003299
3300 pjsua_msg_data_init(&msg_data);
3301 if (omdObj != Py_None) {
3302 PyObj_pjsua_msg_data *omd;
3303
Benny Prijono9c461142008-07-10 22:41:20 +00003304 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003305 msg_data.content_type = PyString_ToPJ(omd->content_type);
3306 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3307 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003308 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003309 }
3310
Benny Prijono55040452008-07-21 18:20:57 +00003311 status = pjsua_call_answer(call_id, code, reason, &msg_data);
3312
3313 if (pool)
3314 pj_pool_release(pool);
3315
3316 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003317}
3318
3319/*
3320 * py_pjsua_call_hangup
3321 */
Benny Prijono55040452008-07-21 18:20:57 +00003322static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003323{
3324 int status;
3325 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003326 pj_str_t *reason, tmp_reason;
3327 PyObject *pReason;
Benny Prijono9c461142008-07-10 22:41:20 +00003328 unsigned code;
3329 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003330 PyObject *omdObj;
3331 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003332
3333 PJ_UNUSED_ARG(pSelf);
3334
Benny Prijono55040452008-07-21 18:20:57 +00003335 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason,
3336 &omdObj))
Benny Prijono9c461142008-07-10 22:41:20 +00003337 {
3338 return NULL;
3339 }
Benny Prijono55040452008-07-21 18:20:57 +00003340
3341 if (pReason == Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00003342 reason = NULL;
3343 } else {
3344 reason = &tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003345 tmp_reason = PyString_ToPJ(pReason);
Benny Prijono9c461142008-07-10 22:41:20 +00003346 }
Benny Prijono55040452008-07-21 18:20:57 +00003347
3348 pjsua_msg_data_init(&msg_data);
3349 if (omdObj != Py_None) {
3350 PyObj_pjsua_msg_data *omd;
3351
Benny Prijono9c461142008-07-10 22:41:20 +00003352 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003353 msg_data.content_type = PyString_ToPJ(omd->content_type);
3354 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3355 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003356 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003357 }
3358
Benny Prijono55040452008-07-21 18:20:57 +00003359 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
3360 if (pool)
3361 pj_pool_release(pool);
3362
3363 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003364}
3365
3366/*
3367 * py_pjsua_call_set_hold
3368 */
Benny Prijono55040452008-07-21 18:20:57 +00003369static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003370{
3371 int status;
3372 int call_id;
3373 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003374 PyObject *omdObj;
3375 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003376
3377 PJ_UNUSED_ARG(pSelf);
3378
Benny Prijono55040452008-07-21 18:20:57 +00003379 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003380 return NULL;
3381 }
3382
Benny Prijono55040452008-07-21 18:20:57 +00003383 pjsua_msg_data_init(&msg_data);
3384 if (omdObj != Py_None) {
3385 PyObj_pjsua_msg_data *omd;
3386
Benny Prijono9c461142008-07-10 22:41:20 +00003387 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003388 msg_data.content_type = PyString_ToPJ(omd->content_type);
3389 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3390 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003391 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003392 }
Benny Prijono55040452008-07-21 18:20:57 +00003393
3394 status = pjsua_call_set_hold(call_id, &msg_data);
3395
3396 if (pool)
3397 pj_pool_release(pool);
3398
Benny Prijono9c461142008-07-10 22:41:20 +00003399 return Py_BuildValue("i",status);
3400}
3401
3402/*
3403 * py_pjsua_call_reinvite
3404 */
Benny Prijono55040452008-07-21 18:20:57 +00003405static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003406{
3407 int status;
Benny Prijono55040452008-07-21 18:20:57 +00003408 int call_id;
Benny Prijono9c461142008-07-10 22:41:20 +00003409 int unhold;
3410 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003411 PyObject *omdObj;
3412 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003413
3414 PJ_UNUSED_ARG(pSelf);
3415
Benny Prijono55040452008-07-21 18:20:57 +00003416 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003417 return NULL;
3418 }
3419
Benny Prijono55040452008-07-21 18:20:57 +00003420 pjsua_msg_data_init(&msg_data);
3421 if (omdObj != Py_None) {
3422 PyObj_pjsua_msg_data *omd;
3423
Benny Prijono9c461142008-07-10 22:41:20 +00003424 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003425 msg_data.content_type = PyString_ToPJ(omd->content_type);
3426 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3427 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003428 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003429 }
Benny Prijono55040452008-07-21 18:20:57 +00003430
3431 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
3432
3433 if (pool)
3434 pj_pool_release(pool);
3435
3436 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003437}
3438
3439/*
3440 * py_pjsua_call_update
3441 */
Benny Prijono55040452008-07-21 18:20:57 +00003442static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003443{
3444 int status;
3445 int call_id;
3446 int option;
3447 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003448 PyObject *omdObj;
3449 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003450
3451 PJ_UNUSED_ARG(pSelf);
3452
Benny Prijono55040452008-07-21 18:20:57 +00003453 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003454 return NULL;
3455 }
3456
Benny Prijono55040452008-07-21 18:20:57 +00003457 pjsua_msg_data_init(&msg_data);
3458 if (omdObj != Py_None) {
3459 PyObj_pjsua_msg_data *omd;
3460
Benny Prijono9c461142008-07-10 22:41:20 +00003461 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003462 msg_data.content_type = PyString_ToPJ(omd->content_type);
3463 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3464 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003465 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003466 }
Benny Prijono55040452008-07-21 18:20:57 +00003467
3468 status = pjsua_call_update(call_id, option, &msg_data);
3469
3470 if (pool)
3471 pj_pool_release(pool);
3472
3473 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003474}
3475
3476/*
3477 * py_pjsua_call_send_request
3478 */
Benny Prijono55040452008-07-21 18:20:57 +00003479static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003480{
3481 int status;
3482 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003483 PyObject *pMethod;
Benny Prijono9c461142008-07-10 22:41:20 +00003484 pj_str_t method;
3485 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003486 PyObject *omdObj;
3487 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003488
3489 PJ_UNUSED_ARG(pSelf);
3490
Benny Prijono55040452008-07-21 18:20:57 +00003491 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003492 return NULL;
3493 }
3494
Benny Prijono55040452008-07-21 18:20:57 +00003495 if (!PyString_Check(pMethod)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003496 return NULL;
3497 }
3498
Benny Prijono55040452008-07-21 18:20:57 +00003499 method = PyString_ToPJ(pMethod);
3500 pjsua_msg_data_init(&msg_data);
Benny Prijono9c461142008-07-10 22:41:20 +00003501
Benny Prijono55040452008-07-21 18:20:57 +00003502 if (omdObj != Py_None) {
3503 PyObj_pjsua_msg_data *omd;
3504
Benny Prijono9c461142008-07-10 22:41:20 +00003505 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003506 msg_data.content_type = PyString_ToPJ(omd->content_type);
3507 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3508 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003509 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003510 }
Benny Prijono55040452008-07-21 18:20:57 +00003511
3512 status = pjsua_call_send_request(call_id, &method, &msg_data);
3513
3514 if (pool)
3515 pj_pool_release(pool);
3516
3517 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003518}
3519
3520/*
3521 * py_pjsua_call_xfer
3522 */
Benny Prijono55040452008-07-21 18:20:57 +00003523static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003524{
3525 int status;
3526 int call_id;
3527 pj_str_t dest;
Benny Prijono55040452008-07-21 18:20:57 +00003528 PyObject *pDstUri;
Benny Prijono9c461142008-07-10 22:41:20 +00003529 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003530 PyObject *omdObj;
3531 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003532
3533 PJ_UNUSED_ARG(pSelf);
3534
Benny Prijono55040452008-07-21 18:20:57 +00003535 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003536 return NULL;
3537 }
Benny Prijono55040452008-07-21 18:20:57 +00003538
3539 if (!PyString_Check(pDstUri))
3540 return NULL;
3541
3542 dest = PyString_ToPJ(pDstUri);
3543 pjsua_msg_data_init(&msg_data);
3544
3545 if (omdObj != Py_None) {
3546 PyObj_pjsua_msg_data *omd;
3547
Benny Prijono9c461142008-07-10 22:41:20 +00003548 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003549 msg_data.content_type = PyString_ToPJ(omd->content_type);
3550 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3551 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003552 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003553 }
Benny Prijono55040452008-07-21 18:20:57 +00003554
3555 status = pjsua_call_xfer(call_id, &dest, &msg_data);
3556
3557 if (pool)
3558 pj_pool_release(pool);
3559
3560 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003561}
3562
3563/*
3564 * py_pjsua_call_xfer_replaces
3565 */
Benny Prijono55040452008-07-21 18:20:57 +00003566static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003567{
3568 int status;
3569 int call_id;
3570 int dest_call_id;
3571 unsigned options;
3572 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003573 PyObject *omdObj;
3574 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003575
3576 PJ_UNUSED_ARG(pSelf);
3577
Benny Prijono55040452008-07-21 18:20:57 +00003578 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id,
3579 &options, &omdObj))
Benny Prijono9c461142008-07-10 22:41:20 +00003580 {
3581 return NULL;
3582 }
Benny Prijono55040452008-07-21 18:20:57 +00003583
3584 pjsua_msg_data_init(&msg_data);
3585
3586 if (omdObj != Py_None) {
3587 PyObj_pjsua_msg_data *omd;
3588
3589 omd = (PyObj_pjsua_msg_data *)omdObj;
3590 msg_data.content_type = PyString_ToPJ(omd->content_type);
3591 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3592 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003593 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003594 }
Benny Prijono55040452008-07-21 18:20:57 +00003595
3596 status = pjsua_call_xfer_replaces(call_id, dest_call_id, options,
3597 &msg_data);
3598
3599 if (pool)
3600 pj_pool_release(pool);
3601
3602 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003603}
3604
3605/*
3606 * py_pjsua_call_dial_dtmf
3607 */
Benny Prijono55040452008-07-21 18:20:57 +00003608static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003609{
3610 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003611 PyObject *pDigits;
Benny Prijono9c461142008-07-10 22:41:20 +00003612 pj_str_t digits;
3613 int status;
3614
3615 PJ_UNUSED_ARG(pSelf);
3616
Benny Prijono55040452008-07-21 18:20:57 +00003617 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003618 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003619 }
3620
3621 if (!PyString_Check(pDigits))
3622 return Py_BuildValue("i", PJ_EINVAL);
3623
3624 digits = PyString_ToPJ(pDigits);
Benny Prijono9c461142008-07-10 22:41:20 +00003625 status = pjsua_call_dial_dtmf(call_id, &digits);
3626
3627 return Py_BuildValue("i", status);
3628}
3629
3630/*
3631 * py_pjsua_call_send_im
3632 */
Benny Prijono55040452008-07-21 18:20:57 +00003633static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003634{
3635 int status;
3636 int call_id;
3637 pj_str_t content;
3638 pj_str_t * mime_type, tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00003639 PyObject *pMimeType, *pContent, *omdObj;
Benny Prijono9c461142008-07-10 22:41:20 +00003640 pjsua_msg_data msg_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003641 int user_data;
Benny Prijono55040452008-07-21 18:20:57 +00003642 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003643
3644 PJ_UNUSED_ARG(pSelf);
3645
Benny Prijono55040452008-07-21 18:20:57 +00003646 if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent,
3647 &omdObj, &user_data))
Benny Prijono9c461142008-07-10 22:41:20 +00003648 {
3649 return NULL;
3650 }
Benny Prijono55040452008-07-21 18:20:57 +00003651
3652 if (!PyString_Check(pContent))
3653 return Py_BuildValue("i", PJ_EINVAL);
3654
3655 content = PyString_ToPJ(pContent);
3656
3657 if (PyString_Check(pMimeType)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003658 mime_type = &tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00003659 tmp_mime_type = PyString_ToPJ(pMimeType);
Benny Prijono9c461142008-07-10 22:41:20 +00003660 } else {
Benny Prijono55040452008-07-21 18:20:57 +00003661 mime_type = NULL;
3662 }
3663
3664 pjsua_msg_data_init(&msg_data);
3665 if (omdObj != Py_None) {
3666 PyObj_pjsua_msg_data * omd;
3667
3668 omd = (PyObj_pjsua_msg_data *)omdObj;
3669 msg_data.content_type = PyString_ToPJ(omd->content_type);
3670 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3671 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3672 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003673 }
3674
Benny Prijono55040452008-07-21 18:20:57 +00003675 status = pjsua_call_send_im(call_id, mime_type, &content,
3676 &msg_data, (void *)user_data);
3677
3678 if (pool)
3679 pj_pool_release(pool);
3680
3681 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003682}
3683
3684/*
3685 * py_pjsua_call_send_typing_ind
3686 */
Benny Prijono55040452008-07-21 18:20:57 +00003687static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf,
3688 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003689{
3690 int status;
3691 int call_id;
3692 int is_typing;
3693 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003694 PyObject *omdObj;
3695 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003696
3697 PJ_UNUSED_ARG(pSelf);
3698
Benny Prijono55040452008-07-21 18:20:57 +00003699 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003700 return NULL;
3701 }
3702
Benny Prijono55040452008-07-21 18:20:57 +00003703 pjsua_msg_data_init(&msg_data);
3704 if (omdObj != Py_None) {
3705 PyObj_pjsua_msg_data *omd;
3706
Benny Prijono9c461142008-07-10 22:41:20 +00003707 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003708 msg_data.content_type = PyString_ToPJ(omd->content_type);
3709 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3710 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003711 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003712 }
Benny Prijono55040452008-07-21 18:20:57 +00003713
3714 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
3715
3716 if (pool)
3717 pj_pool_release(pool);
3718
3719 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003720}
3721
3722/*
3723 * py_pjsua_call_hangup_all
3724 */
Benny Prijono55040452008-07-21 18:20:57 +00003725static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003726{
Benny Prijono9c461142008-07-10 22:41:20 +00003727 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003728 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003729
Benny Prijono9c461142008-07-10 22:41:20 +00003730 pjsua_call_hangup_all();
3731
Benny Prijono55040452008-07-21 18:20:57 +00003732 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003733}
3734
3735/*
3736 * py_pjsua_call_dump
3737 */
Benny Prijono55040452008-07-21 18:20:57 +00003738static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003739{
3740 int call_id;
3741 int with_media;
Benny Prijono55040452008-07-21 18:20:57 +00003742 PyObject *ret;
3743 PyObject *pIndent;
3744 char *buffer;
3745 char *indent;
Benny Prijono9c461142008-07-10 22:41:20 +00003746 unsigned maxlen;
3747 int status;
3748
3749 PJ_UNUSED_ARG(pSelf);
3750
Benny Prijono55040452008-07-21 18:20:57 +00003751 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media,
3752 &maxlen, &pIndent))
Benny Prijono9c461142008-07-10 22:41:20 +00003753 {
3754 return NULL;
3755 }
Benny Prijono55040452008-07-21 18:20:57 +00003756
3757 buffer = (char*) malloc(maxlen * sizeof(char));
3758 indent = PyString_AsString(pIndent);
Benny Prijono9c461142008-07-10 22:41:20 +00003759
3760 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
Benny Prijono55040452008-07-21 18:20:57 +00003761 if (status != PJ_SUCCESS) {
3762 free(buffer);
3763 return PyString_FromString("");
3764 }
3765
3766 ret = PyString_FromString(buffer);
Benny Prijono9c461142008-07-10 22:41:20 +00003767 free(buffer);
Benny Prijono55040452008-07-21 18:20:57 +00003768 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003769}
3770
3771
3772/*
3773 * py_pjsua_dump
3774 * Dump application states.
3775 */
3776static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
3777{
Benny Prijono9c461142008-07-10 22:41:20 +00003778 int detail;
3779
3780 PJ_UNUSED_ARG(pSelf);
3781
Benny Prijono55040452008-07-21 18:20:57 +00003782 if (!PyArg_ParseTuple(pArgs, "i", &detail)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003783 return NULL;
3784 }
3785
Benny Prijono55040452008-07-21 18:20:57 +00003786 pjsua_dump(detail);
Benny Prijono9c461142008-07-10 22:41:20 +00003787
Benny Prijono55040452008-07-21 18:20:57 +00003788 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003789}
3790
3791
3792/*
3793 * py_pj_strerror
3794 */
3795static PyObject *py_pj_strerror(PyObject *pSelf, PyObject *pArgs)
3796{
3797 int err;
3798 char err_msg[PJ_ERR_MSG_SIZE];
Benny Prijono55040452008-07-21 18:20:57 +00003799 pj_str_t ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003800
3801 PJ_UNUSED_ARG(pSelf);
3802
Benny Prijono55040452008-07-21 18:20:57 +00003803 if (!PyArg_ParseTuple(pArgs, "i", &err)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003804 return NULL;
3805 }
3806
Benny Prijono55040452008-07-21 18:20:57 +00003807 ret = pj_strerror(err, err_msg, sizeof(err_msg));
Benny Prijono9c461142008-07-10 22:41:20 +00003808
Benny Prijono55040452008-07-21 18:20:57 +00003809 return PyString_FromStringAndSize(err_msg, ret.slen);
Benny Prijono9c461142008-07-10 22:41:20 +00003810}
3811
3812
3813/*
3814 * py_pj_parse_simple_sip
3815 */
3816static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs)
3817{
Benny Prijono55040452008-07-21 18:20:57 +00003818 const char *arg_uri;
Benny Prijono9c461142008-07-10 22:41:20 +00003819 pj_pool_t *pool;
3820 char tmp[PJSIP_MAX_URL_SIZE];
3821 pjsip_uri *uri;
3822 pjsip_sip_uri *sip_uri;
3823 PyObject *ret, *item;
3824
3825 PJ_UNUSED_ARG(pSelf);
3826
Benny Prijono55040452008-07-21 18:20:57 +00003827 if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003828 return NULL;
3829 }
3830
Benny Prijono55040452008-07-21 18:20:57 +00003831 strncpy(tmp, arg_uri, sizeof(tmp));
Benny Prijono9c461142008-07-10 22:41:20 +00003832 tmp[sizeof(tmp)-1] = '\0';
3833
3834 pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512);
3835 uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0);
3836
3837 if (uri == NULL || (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
3838 !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
3839 pj_pool_release(pool);
Benny Prijono55040452008-07-21 18:20:57 +00003840 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003841 }
3842
3843 ret = PyTuple_New(5);
3844 sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri);
3845
3846 /* Scheme */
Benny Prijono55040452008-07-21 18:20:57 +00003847 item = PyString_FromPJ(pjsip_uri_get_scheme(uri));
Benny Prijono9c461142008-07-10 22:41:20 +00003848 PyTuple_SetItem(ret, 0, item);
3849
3850 /* Username */
Benny Prijono55040452008-07-21 18:20:57 +00003851 item = PyString_FromPJ(&sip_uri->user);
Benny Prijono9c461142008-07-10 22:41:20 +00003852 PyTuple_SetItem(ret, 1, item);
3853
3854 /* Host */
Benny Prijono55040452008-07-21 18:20:57 +00003855 item = PyString_FromPJ(&sip_uri->host);
Benny Prijono9c461142008-07-10 22:41:20 +00003856 PyTuple_SetItem(ret, 2, item);
3857
3858 /* Port */
3859 if (sip_uri->port == 5060) {
3860 sip_uri->port = 0;
3861 }
3862 item = Py_BuildValue("i", sip_uri->port);
3863 PyTuple_SetItem(ret, 3, item);
3864
3865 /* Transport */
3866 if (pj_stricmp2(&sip_uri->transport_param, "udp")) {
3867 sip_uri->transport_param.ptr = "";
3868 sip_uri->transport_param.slen = 0;
3869 }
Benny Prijono55040452008-07-21 18:20:57 +00003870 item = PyString_FromPJ(&sip_uri->transport_param);
Benny Prijono9c461142008-07-10 22:41:20 +00003871 PyTuple_SetItem(ret, 4, item);
3872
3873 return ret;
3874}
3875
3876
3877static char pjsua_call_get_max_count_doc[] =
3878 "int _pjsua.call_get_max_count () "
3879 "Get maximum number of calls configured in pjsua.";
3880static char pjsua_call_get_count_doc[] =
3881 "int _pjsua.call_get_count () "
3882 "Get number of currently active calls.";
3883static char pjsua_enum_calls_doc[] =
3884 "int[] _pjsua.enum_calls () "
3885 "Get maximum number of calls configured in pjsua.";
3886static char pjsua_call_make_call_doc[] =
3887 "int,int _pjsua.call_make_call (int acc_id, string dst_uri, int options,"
3888 "int user_data, _pjsua.Msg_Data msg_data) "
3889 "Make outgoing call to the specified URI using the specified account.";
3890static char pjsua_call_is_active_doc[] =
3891 "int _pjsua.call_is_active (int call_id) "
3892 "Check if the specified call has active INVITE session and the INVITE "
3893 "session has not been disconnected.";
3894static char pjsua_call_has_media_doc[] =
3895 "int _pjsua.call_has_media (int call_id) "
3896 "Check if call has an active media session.";
3897static char pjsua_call_get_conf_port_doc[] =
3898 "int _pjsua.call_get_conf_port (int call_id) "
3899 "Get the conference port identification associated with the call.";
3900static char pjsua_call_get_info_doc[] =
3901 "_pjsua.Call_Info _pjsua.call_get_info (int call_id) "
3902 "Obtain detail information about the specified call.";
3903static char pjsua_call_set_user_data_doc[] =
3904 "int _pjsua.call_set_user_data (int call_id, int user_data) "
3905 "Attach application specific data to the call.";
3906static char pjsua_call_get_user_data_doc[] =
3907 "int _pjsua.call_get_user_data (int call_id) "
3908 "Get user data attached to the call.";
3909static char pjsua_call_answer_doc[] =
3910 "int _pjsua.call_answer (int call_id, int code, string reason, "
3911 "_pjsua.Msg_Data msg_data) "
3912 "Send response to incoming INVITE request.";
3913static char pjsua_call_hangup_doc[] =
3914 "int _pjsua.call_hangup (int call_id, int code, string reason, "
3915 "_pjsua.Msg_Data msg_data) "
3916 "Hangup call by using method that is appropriate according "
3917 "to the call state.";
3918static char pjsua_call_set_hold_doc[] =
3919 "int _pjsua.call_set_hold (int call_id, _pjsua.Msg_Data msg_data) "
3920 "Put the specified call on hold.";
3921static char pjsua_call_reinvite_doc[] =
3922 "int _pjsua.call_reinvite (int call_id, int unhold, "
3923 "_pjsua.Msg_Data msg_data) "
3924 "Send re-INVITE (to release hold).";
3925static char pjsua_call_xfer_doc[] =
3926 "int _pjsua.call_xfer (int call_id, string dest, "
3927 "_pjsua.Msg_Data msg_data) "
3928 "Initiate call transfer to the specified address. "
3929 "This function will send REFER request to instruct remote call party "
3930 "to initiate a new INVITE session to the specified destination/target.";
3931static char pjsua_call_xfer_replaces_doc[] =
3932 "int _pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
3933 "int options, _pjsua.Msg_Data msg_data) "
3934 "Initiate attended call transfer. This function will send REFER request "
3935 "to instruct remote call party to initiate new INVITE session to the URL "
3936 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
3937 "with us with the new call from the REFER recipient.";
3938static char pjsua_call_dial_dtmf_doc[] =
3939 "int _pjsua.call_dial_dtmf (int call_id, string digits) "
3940 "Send DTMF digits to remote using RFC 2833 payload formats.";
3941static char pjsua_call_send_im_doc[] =
3942 "int _pjsua.call_send_im (int call_id, string mime_type, string content,"
3943 "_pjsua.Msg_Data msg_data, int user_data) "
3944 "Send instant messaging inside INVITE session.";
3945static char pjsua_call_send_typing_ind_doc[] =
3946 "int _pjsua.call_send_typing_ind (int call_id, int is_typing, "
3947 "_pjsua.Msg_Data msg_data) "
3948 "Send IM typing indication inside INVITE session.";
3949static char pjsua_call_hangup_all_doc[] =
3950 "void _pjsua.call_hangup_all () "
3951 "Terminate all calls.";
3952static char pjsua_call_dump_doc[] =
3953 "int _pjsua.call_dump (int call_id, int with_media, int maxlen, "
3954 "string indent) "
3955 "Dump call and media statistics to string.";
3956
3957/* END OF LIB CALL */
3958
3959/*
3960 * Map of function names to functions
3961 */
3962static PyMethodDef py_pjsua_methods[] =
3963{
3964 {
3965 "thread_register", py_pjsua_thread_register, METH_VARARGS,
3966 pjsua_thread_register_doc
3967 },
3968 {
3969 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
3970 },
3971 {
3972 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
3973 },
3974 {
3975 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
3976 },
3977 {
3978 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
3979 },
3980 {
3981 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
3982 },
3983 {
3984 "handle_events", py_pjsua_handle_events, METH_VARARGS,
3985 pjsua_handle_events_doc
3986 },
3987 {
3988 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
3989 pjsua_verify_sip_url_doc
3990 },
3991 {
Benny Prijono9c461142008-07-10 22:41:20 +00003992 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
3993 pjsua_reconfigure_logging_doc
3994 },
3995 {
3996 "logging_config_default", py_pjsua_logging_config_default,
3997 METH_VARARGS, pjsua_logging_config_default_doc
3998 },
3999 {
4000 "config_default", py_pjsua_config_default, METH_VARARGS,
4001 pjsua_config_default_doc
4002 },
4003 {
4004 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
4005 pjsua_media_config_default_doc
4006 },
4007
4008
4009 {
4010 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
4011 pjsua_msg_data_init_doc
4012 },
4013 {
4014 "transport_config_default", py_pjsua_transport_config_default,
4015 METH_VARARGS,pjsua_transport_config_default_doc
4016 },
4017 {
4018 "transport_create", py_pjsua_transport_create, METH_VARARGS,
4019 pjsua_transport_create_doc
4020 },
4021 {
4022 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
4023 pjsua_enum_transports_doc
4024 },
4025 {
4026 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
4027 pjsua_transport_get_info_doc
4028 },
4029 {
4030 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
4031 pjsua_transport_set_enable_doc
4032 },
4033 {
4034 "transport_close", py_pjsua_transport_close, METH_VARARGS,
4035 pjsua_transport_close_doc
4036 },
4037 {
4038 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
4039 pjsua_acc_config_default_doc
4040 },
4041 {
4042 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
4043 pjsua_acc_get_count_doc
4044 },
4045 {
4046 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
4047 pjsua_acc_is_valid_doc
4048 },
4049 {
4050 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
4051 pjsua_acc_set_default_doc
4052 },
4053 {
4054 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
4055 pjsua_acc_get_default_doc
4056 },
4057 {
4058 "acc_add", py_pjsua_acc_add, METH_VARARGS,
4059 pjsua_acc_add_doc
4060 },
4061 {
4062 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
4063 pjsua_acc_add_local_doc
4064 },
4065 {
4066 "acc_del", py_pjsua_acc_del, METH_VARARGS,
4067 pjsua_acc_del_doc
4068 },
4069 {
Benny Prijono55040452008-07-21 18:20:57 +00004070 "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS,
4071 "Accociate user data with the account"
4072 },
4073 {
4074 "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS,
4075 "Get account's user data"
4076 },
4077 {
Benny Prijono9c461142008-07-10 22:41:20 +00004078 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
4079 pjsua_acc_modify_doc
4080 },
4081 {
4082 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
4083 pjsua_acc_set_online_status_doc
4084 },
4085 {
4086 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
4087 pjsua_acc_set_online_status2_doc
4088 },
4089 {
4090 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
4091 pjsua_acc_set_registration_doc
4092 },
4093 {
4094 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
4095 pjsua_acc_get_info_doc
4096 },
4097 {
Benny Prijonoe6787ec2008-07-18 23:00:56 +00004098 "acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS,
4099 "Accept or reject subscription request"
4100 },
4101 {
Benny Prijono9c461142008-07-10 22:41:20 +00004102 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
4103 pjsua_enum_accs_doc
4104 },
4105 {
4106 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
4107 pjsua_acc_enum_info_doc
4108 },
4109 {
Benny Prijono9c461142008-07-10 22:41:20 +00004110 "acc_set_transport", py_pjsua_acc_set_transport, METH_VARARGS,
4111 "Lock transport to use the specified transport"
4112 },
4113 {
4114 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
4115 pjsua_buddy_config_default_doc
4116 },
4117 {
4118 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
4119 pjsua_get_buddy_count_doc
4120 },
4121 {
4122 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
4123 pjsua_buddy_is_valid_doc
4124 },
4125 {
4126 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
4127 pjsua_enum_buddies_doc
4128 },
4129 {
Benny Prijono55040452008-07-21 18:20:57 +00004130 "buddy_find", py_pjsua_buddy_find, METH_VARARGS,
4131 "Find buddy with the specified URI"
4132 },
4133 {
Benny Prijono9c461142008-07-10 22:41:20 +00004134 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
4135 pjsua_buddy_get_info_doc
4136 },
4137 {
4138 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
4139 pjsua_buddy_add_doc
4140 },
4141 {
4142 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
4143 pjsua_buddy_del_doc
4144 },
4145 {
Benny Prijono55040452008-07-21 18:20:57 +00004146 "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS,
4147 "Associate user data to the buddy object"
4148 },
4149 {
4150 "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS,
4151 "Get buddy user data"
4152 },
4153 {
Benny Prijono9c461142008-07-10 22:41:20 +00004154 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
4155 pjsua_buddy_subscribe_pres_doc
4156 },
4157 {
4158 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
4159 pjsua_pres_dump_doc
4160 },
4161 {
4162 "im_send", py_pjsua_im_send, METH_VARARGS,
4163 pjsua_im_send_doc
4164 },
4165 {
4166 "im_typing", py_pjsua_im_typing, METH_VARARGS,
4167 pjsua_im_typing_doc
4168 },
4169 {
4170 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
4171 pjsua_conf_get_max_ports_doc
4172 },
4173 {
4174 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
4175 pjsua_conf_get_active_ports_doc
4176 },
4177 {
4178 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
4179 pjsua_enum_conf_ports_doc
4180 },
4181 {
4182 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
4183 pjsua_conf_get_port_info_doc
4184 },
4185 {
Benny Prijono9c461142008-07-10 22:41:20 +00004186 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
4187 pjsua_conf_remove_port_doc
4188 },
4189 {
4190 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
4191 pjsua_conf_connect_doc
4192 },
4193 {
4194 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
4195 pjsua_conf_disconnect_doc
4196 },
4197 {
Benny Prijono288d4bd2008-07-19 15:40:21 +00004198 "conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS,
4199 "Adjust the signal level to be transmitted from the bridge to the"
4200 " specified port by making it louder or quieter"
4201 },
4202 {
4203 "conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS,
4204 "Adjust the signal level to be received from the specified port (to"
4205 " the bridge) by making it louder or quieter"
4206 },
4207 {
4208 "conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS,
4209 "Get last signal level transmitted to or received from the specified port"
4210 },
4211 {
Benny Prijono9c461142008-07-10 22:41:20 +00004212 "player_create", py_pjsua_player_create, METH_VARARGS,
4213 pjsua_player_create_doc
4214 },
4215 {
Benny Prijono288d4bd2008-07-19 15:40:21 +00004216 "playlist_create", py_pjsua_playlist_create, METH_VARARGS,
4217 "Create WAV playlist"
4218 },
4219 {
Benny Prijono9c461142008-07-10 22:41:20 +00004220 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
4221 pjsua_player_get_conf_port_doc
4222 },
4223 {
4224 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
4225 pjsua_player_set_pos_doc
4226 },
4227 {
4228 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
4229 pjsua_player_destroy_doc
4230 },
4231 {
4232 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
4233 pjsua_recorder_create_doc
4234 },
4235 {
4236 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
4237 pjsua_recorder_get_conf_port_doc
4238 },
4239 {
4240 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
4241 pjsua_recorder_destroy_doc
4242 },
4243 {
4244 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
4245 pjsua_enum_snd_devs_doc
4246 },
4247 {
4248 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
4249 pjsua_get_snd_dev_doc
4250 },
4251 {
4252 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
4253 pjsua_set_snd_dev_doc
4254 },
4255 {
4256 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
4257 pjsua_set_null_snd_dev_doc
4258 },
4259 {
Benny Prijono9c461142008-07-10 22:41:20 +00004260 "set_ec", py_pjsua_set_ec, METH_VARARGS,
4261 pjsua_set_ec_doc
4262 },
4263 {
4264 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
4265 pjsua_get_ec_tail_doc
4266 },
4267 {
4268 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
4269 pjsua_enum_codecs_doc
4270 },
4271 {
4272 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
4273 pjsua_codec_set_priority_doc
4274 },
4275 {
4276 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
4277 pjsua_codec_get_param_doc
4278 },
4279 {
4280 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
4281 pjsua_codec_set_param_doc
4282 },
4283 {
4284 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
4285 pjsua_call_get_max_count_doc
4286 },
4287 {
4288 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
4289 pjsua_call_get_count_doc
4290 },
4291 {
4292 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
4293 pjsua_enum_calls_doc
4294 },
4295 {
4296 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
4297 pjsua_call_make_call_doc
4298 },
4299 {
4300 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
4301 pjsua_call_is_active_doc
4302 },
4303 {
4304 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
4305 pjsua_call_has_media_doc
4306 },
4307 {
4308 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
4309 pjsua_call_get_conf_port_doc
4310 },
4311 {
4312 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
4313 pjsua_call_get_info_doc
4314 },
4315 {
4316 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
4317 pjsua_call_set_user_data_doc
4318 },
4319 {
4320 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
4321 pjsua_call_get_user_data_doc
4322 },
4323 {
4324 "call_answer", py_pjsua_call_answer, METH_VARARGS,
4325 pjsua_call_answer_doc
4326 },
4327 {
4328 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
4329 pjsua_call_hangup_doc
4330 },
4331 {
4332 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
4333 pjsua_call_set_hold_doc
4334 },
4335 {
4336 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
4337 pjsua_call_reinvite_doc
4338 },
4339 {
4340 "call_update", py_pjsua_call_update, METH_VARARGS,
4341 "Send UPDATE"
4342 },
4343 {
4344 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
4345 pjsua_call_xfer_doc
4346 },
4347 {
4348 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
4349 pjsua_call_xfer_replaces_doc
4350 },
4351 {
4352 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
4353 pjsua_call_dial_dtmf_doc
4354 },
4355 {
4356 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
4357 pjsua_call_send_im_doc
4358 },
4359 {
4360 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
4361 pjsua_call_send_typing_ind_doc
4362 },
4363 {
4364 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
4365 pjsua_call_hangup_all_doc
4366 },
4367 {
4368 "call_dump", py_pjsua_call_dump, METH_VARARGS,
4369 pjsua_call_dump_doc
4370 },
4371 {
4372 "call_send_request", py_pjsua_call_send_request, METH_VARARGS,
4373 "Send arbitrary request"
4374 },
4375 {
4376 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
4377 },
4378 {
4379 "strerror", py_pj_strerror, METH_VARARGS, "Get error message"
4380 },
4381 {
4382 "parse_simple_uri", py_pj_parse_simple_sip, METH_VARARGS, "Parse URI"
4383 },
4384
4385
4386 {NULL, NULL} /* end of function list */
4387};
4388
4389
4390
4391/*
4392 * Mapping C structs from and to Python objects & initializing object
4393 */
4394DL_EXPORT(void)
4395init_pjsua(void)
4396{
4397 PyObject* m = NULL;
4398#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
4399
4400
4401 PyEval_InitThreads();
4402
4403 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
4404 return;
4405 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
4406 return;
4407 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
4408 return;
4409 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
4410 return;
4411 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
4412 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
4413 return;
Benny Prijono9c461142008-07-10 22:41:20 +00004414 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
4415 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
4416 return;
4417
4418 /* LIB TRANSPORT */
4419
4420 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
4421 return;
4422
4423 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
4424 return;
4425
4426 /* END OF LIB TRANSPORT */
4427
4428 /* LIB ACCOUNT */
4429
4430
4431 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
4432 return;
4433 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
4434 return;
4435
4436 /* END OF LIB ACCOUNT */
4437
4438 /* LIB BUDDY */
4439
4440 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
4441 return;
4442 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
4443 return;
4444
4445 /* END OF LIB BUDDY */
4446
4447 /* LIB MEDIA */
4448
4449 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
4450 return;
4451
4452 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
4453 return;
4454
Benny Prijono9c461142008-07-10 22:41:20 +00004455 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
4456 return;
4457
4458 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
4459 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
4460 return;
4461 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
4462 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
4463 return;
4464
4465 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
4466 return;
4467
4468 /* END OF LIB MEDIA */
4469
4470 /* LIB CALL */
4471
Benny Prijono9c461142008-07-10 22:41:20 +00004472 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
4473 return;
4474
4475 /* END OF LIB CALL */
4476
4477 m = Py_InitModule3(
Benny Prijono55040452008-07-21 18:20:57 +00004478 "_pjsua", py_pjsua_methods, "PJSUA-lib module for python"
Benny Prijono9c461142008-07-10 22:41:20 +00004479 );
4480
4481 Py_INCREF(&PyTyp_pjsua_callback);
4482 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
4483
4484 Py_INCREF(&PyTyp_pjsua_config);
4485 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
4486
4487 Py_INCREF(&PyTyp_pjsua_media_config);
4488 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
4489
4490 Py_INCREF(&PyTyp_pjsua_logging_config);
4491 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
4492
4493 Py_INCREF(&PyTyp_pjsua_msg_data);
4494 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
4495
Benny Prijono9c461142008-07-10 22:41:20 +00004496 Py_INCREF(&PyTyp_pjsip_cred_info);
4497 PyModule_AddObject(m, "Pjsip_Cred_Info",
4498 (PyObject *)&PyTyp_pjsip_cred_info
4499 );
4500
4501 /* LIB TRANSPORT */
4502
4503 Py_INCREF(&PyTyp_pjsua_transport_config);
4504 PyModule_AddObject
4505 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
4506
4507 Py_INCREF(&PyTyp_pjsua_transport_info);
4508 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
4509
4510
4511 /* END OF LIB TRANSPORT */
4512
4513 /* LIB ACCOUNT */
4514
4515
4516 Py_INCREF(&PyTyp_pjsua_acc_config);
4517 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
4518 Py_INCREF(&PyTyp_pjsua_acc_info);
4519 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
4520
4521 /* END OF LIB ACCOUNT */
4522
4523 /* LIB BUDDY */
4524
4525 Py_INCREF(&PyTyp_pjsua_buddy_config);
4526 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
4527 Py_INCREF(&PyTyp_pjsua_buddy_info);
4528 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
4529
4530 /* END OF LIB BUDDY */
4531
4532 /* LIB MEDIA */
4533
4534 Py_INCREF(&PyTyp_pjsua_codec_info);
4535 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
4536 Py_INCREF(&PyTyp_pjsua_conf_port_info);
4537 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
Benny Prijono9c461142008-07-10 22:41:20 +00004538 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
4539 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
4540 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
4541 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
4542 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
4543 (PyObject *)&PyTyp_pjmedia_codec_param_info);
4544 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
4545 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
4546 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
4547 Py_INCREF(&PyTyp_pjmedia_codec_param);
4548 PyModule_AddObject(m, "PJMedia_Codec_Param",
4549 (PyObject *)&PyTyp_pjmedia_codec_param);
4550
4551 /* END OF LIB MEDIA */
4552
4553 /* LIB CALL */
4554
Benny Prijono9c461142008-07-10 22:41:20 +00004555 Py_INCREF(&PyTyp_pjsua_call_info);
4556 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
4557
4558 /* END OF LIB CALL */
4559
4560
4561 /*
4562 * Add various constants.
4563 */
Benny Prijono55040452008-07-21 18:20:57 +00004564 /* Skip it.. */
Benny Prijono9c461142008-07-10 22:41:20 +00004565
4566#undef ADD_CONSTANT
4567}