blob: 953a60b4f9494f77540d8dfedc90c29bad3ab3a7 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id: _pjsua.c 4422 2013-03-06 06:00:18Z ming $ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include "_pjsua.h"
21
22#define THIS_FILE "main.c"
23#define POOL_SIZE 512
24#define SND_DEV_NUM 64
25#define SND_NAME_LEN 64
26
27/* LIB BASE */
28
29static PyObject* g_obj_log_cb;
30static long g_thread_id;
31static struct py_thread_desc
32{
33 struct py_thread_desc *next;
34 pj_thread_desc desc;
35} *py_thread_desc;
36
37/*
38 * The global callback object.
39 */
40static PyObj_pjsua_callback * g_obj_callback;
41
42/* Set this to 1 if all threads are created by Python */
43#define NO_PJSIP_THREAD 1
44
45#if NO_PJSIP_THREAD
46# define ENTER_PYTHON()
47# define LEAVE_PYTHON()
48#else
49# define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure()
50# define LEAVE_PYTHON() PyGILState_Release(state)
51#endif
52
53
54static void clear_py_thread_desc(void)
55{
56 while (py_thread_desc) {
57 struct py_thread_desc *next = py_thread_desc->next;
58 free(py_thread_desc);
59 py_thread_desc = next;
60 }
61}
62
63
64/*
65 * cb_log_cb
66 * declares method for reconfiguring logging process for callback struct
67 */
68static void cb_log_cb(int level, const char *data, int len)
69{
70
71 /* Ignore if this callback is called from alien thread context,
72 * or otherwise it will crash Python.
73 */
74 if (pj_thread_local_get(g_thread_id) == 0)
75 return;
76
77 if (PyCallable_Check(g_obj_log_cb)) {
78 PyObject *param_data;
79
80 ENTER_PYTHON();
81
82 param_data = PyString_FromStringAndSize(data, len);
83
84 PyObject_CallFunction(
85 g_obj_log_cb,
86 "iOi",
87 level,
88 param_data,
89 len,
90 NULL
91 );
92
93 Py_DECREF(param_data);
94
95 LEAVE_PYTHON();
96 }
97}
98
99/*
100 * cb_on_call_state
101 * declares method on_call_state for callback struct
102 */
103static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
104{
105 PJ_UNUSED_ARG(e);
106
107 if (PyCallable_Check(g_obj_callback->on_call_state)) {
108 PyObject * obj;
109
110 ENTER_PYTHON();
111
112 obj = Py_BuildValue("");
113
114 PyObject_CallFunction(
115 g_obj_callback->on_call_state,
116 "iO",
117 call_id,
118 obj,
119 NULL
120 );
121
122 Py_DECREF(obj);
123
124 LEAVE_PYTHON();
125 }
126}
127
128
129/*
130 * cb_on_incoming_call
131 * declares method on_incoming_call for callback struct
132 */
133static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
134 pjsip_rx_data *rdata)
135{
136 PJ_UNUSED_ARG(rdata);
137
138 if (PyCallable_Check(g_obj_callback->on_incoming_call)) {
139 PyObject *obj;
140
141 ENTER_PYTHON();
142
143 obj = Py_BuildValue("");
144
145 PyObject_CallFunction(
146 g_obj_callback->on_incoming_call,
147 "iiO",
148 acc_id,
149 call_id,
150 obj,
151 NULL
152 );
153
154 Py_DECREF(obj);
155
156 LEAVE_PYTHON();
157 }
158}
159
160
161/*
162 * cb_on_call_media_state
163 * declares method on_call_media_state for callback struct
164 */
165static void cb_on_call_media_state(pjsua_call_id call_id)
166{
167 if (PyCallable_Check(g_obj_callback->on_call_media_state)) {
168
169 ENTER_PYTHON();
170
171 PyObject_CallFunction(
172 g_obj_callback->on_call_media_state,
173 "i",
174 call_id,
175 NULL
176 );
177
178 LEAVE_PYTHON();
179 }
180}
181
182
183/*
184 * cb_on_dtmf_digit()
185 * Callback from PJSUA-LIB on receiving DTMF digit
186 */
187static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
188{
189 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) {
190 char digit_str[10];
191
192 PyGILState_STATE state = PyGILState_Ensure();
193
194 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
195
196 PyObject_CallFunction(
197 g_obj_callback->on_dtmf_digit,
198 "is",
199 call_id,
200 digit_str,
201 NULL
202 );
203
204 PyGILState_Release(state);
205 }
206}
207
208
209/*
210 * Notify application on call being transfered.
211 * !modified @061206
212 */
213static void cb_on_call_transfer_request(pjsua_call_id call_id,
214 const pj_str_t *dst,
215 pjsip_status_code *code)
216{
217 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) {
218 PyObject *ret, *param_dst;
219 int cd;
220
221 ENTER_PYTHON();
222
223 param_dst = PyString_FromPJ(dst);
224
225 ret = PyObject_CallFunction(
226 g_obj_callback->on_call_transfer_request,
227 "iOi",
228 call_id,
229 param_dst,
230 *code,
231 NULL
232 );
233
234 Py_DECREF(param_dst);
235
236 if (ret != NULL) {
237 if (ret != Py_None) {
238 if (PyArg_Parse(ret,"i",&cd)) {
239 *code = cd;
240 }
241 }
242 Py_DECREF(ret);
243 }
244
245 LEAVE_PYTHON();
246 }
247}
248
249
250/*
251 * Notify application of the status of previously sent call
252 * transfer request. Application can monitor the status of the
253 * call transfer request, for example to decide whether to
254 * terminate existing call.
255 * !modified @061206
256 */
257static void cb_on_call_transfer_status( pjsua_call_id call_id,
258 int status_code,
259 const pj_str_t *status_text,
260 pj_bool_t final,
261 pj_bool_t *p_cont)
262{
263 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) {
264 PyObject *ret, *param_reason;
265
266 ENTER_PYTHON();
267
268 param_reason = PyString_FromPJ(status_text);
269
270 ret = PyObject_CallFunction(
271 g_obj_callback->on_call_transfer_status,
272 "iiOii",
273 call_id,
274 status_code,
275 param_reason,
276 final,
277 *p_cont,
278 NULL
279 );
280
281 Py_DECREF(param_reason);
282
283 if (ret != NULL) {
284 if (ret != Py_None) {
285 int cnt;
286 if (PyArg_Parse(ret,"i",&cnt)) {
287 *p_cont = cnt;
288 }
289 }
290 Py_DECREF(ret);
291 }
292
293 LEAVE_PYTHON();
294 }
295}
296
297
298/*
299 * Notify application about incoming INVITE with Replaces header.
300 * Application may reject the request by setting non-2xx code.
301 * !modified @061206
302 */
303static void cb_on_call_replace_request( pjsua_call_id call_id,
304 pjsip_rx_data *rdata,
305 int *st_code,
306 pj_str_t *st_text)
307{
308 PJ_UNUSED_ARG(rdata);
309
310 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) {
311 PyObject *ret, *param_reason, *param_rdata;
312 int cd;
313
314 ENTER_PYTHON();
315
316 param_reason = PyString_FromPJ(st_text);
317 param_rdata = Py_BuildValue("");
318
319 ret = PyObject_CallFunction(
320 g_obj_callback->on_call_replace_request,
321 "iOiO",
322 call_id,
323 param_rdata,
324 *st_code,
325 param_reason,
326 NULL
327 );
328
329 Py_DECREF(param_rdata);
330 Py_DECREF(param_reason);
331
332 if (ret != NULL) {
333 if (ret != Py_None) {
334 PyObject * txt;
335 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
336 *st_code = cd;
337 *st_text = PyString_ToPJ(txt);
338 }
339 }
340 Py_DECREF(ret);
341 }
342
343 LEAVE_PYTHON();
344 }
345}
346
347
348/*
349 * Notify application that an existing call has been replaced with
350 * a new call. This happens when PJSUA-API receives incoming INVITE
351 * request with Replaces header.
352 */
353static void cb_on_call_replaced(pjsua_call_id old_call_id,
354 pjsua_call_id new_call_id)
355{
356 if (PyCallable_Check(g_obj_callback->on_call_replaced)) {
357 ENTER_PYTHON();
358
359 PyObject_CallFunction(
360 g_obj_callback->on_call_replaced,
361 "ii",
362 old_call_id,
363 new_call_id,
364 NULL
365 );
366
367 LEAVE_PYTHON();
368 }
369}
370
371
372/*
373 * cb_on_reg_state
374 * declares method on_reg_state for callback struct
375 */
376static void cb_on_reg_state(pjsua_acc_id acc_id)
377{
378 if (PyCallable_Check(g_obj_callback->on_reg_state)) {
379 ENTER_PYTHON();
380
381 PyObject_CallFunction(
382 g_obj_callback->on_reg_state,
383 "i",
384 acc_id,
385 NULL
386 );
387
388 LEAVE_PYTHON();
389 }
390}
391
392/*
393 * cb_on_incoming_subscribe
394 */
395static void cb_on_incoming_subscribe( pjsua_acc_id acc_id,
396 pjsua_srv_pres *srv_pres,
397 pjsua_buddy_id buddy_id,
398 const pj_str_t *from,
399 pjsip_rx_data *rdata,
400 pjsip_status_code *code,
401 pj_str_t *reason,
402 pjsua_msg_data *msg_data)
403{
404 static char reason_buf[64];
405
406 PJ_UNUSED_ARG(rdata);
407 PJ_UNUSED_ARG(msg_data);
408
409 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) {
410 PyObject *ret, *param_from, *param_contact, *param_srv_pres;
411 pjsip_contact_hdr *contact_hdr;
412 pj_pool_t *pool = NULL;
413
414 ENTER_PYTHON();
415
416 param_from = PyString_FromPJ(from);
417 param_srv_pres = PyLong_FromLong((long)srv_pres);
418
419 contact_hdr = (pjsip_contact_hdr*)
420 pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
421 NULL);
422 if (contact_hdr) {
423 char *contact;
424 int len;
425
426 pool = pjsua_pool_create("pytmp", 512, 512);
427 contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1);
428 len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri,
429 contact, PJSIP_MAX_URL_SIZE);
430 if (len < 1)
431 len = 0;
432 contact[len] = '\0';
433
434 param_contact = PyString_FromStringAndSize(contact, len);
435 } else {
436 param_contact = Py_BuildValue("");
437 }
438
439 ret = PyObject_CallFunction(
440 g_obj_callback->on_incoming_subscribe,
441 "iiOOO",
442 acc_id,
443 buddy_id,
444 param_from,
445 param_contact,
446 param_srv_pres,
447 NULL
448 );
449
450 if (pool)
451 pj_pool_release(pool);
452
453 Py_DECREF(param_from);
454 Py_DECREF(param_contact);
455 Py_DECREF(param_srv_pres);
456
457 if (ret && PyTuple_Check(ret)) {
458 if (PyTuple_Size(ret) >= 1)
459 *code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0));
460 if (PyTuple_Size(ret) >= 2) {
461 if (PyTuple_GetItem(ret, 1) != Py_None) {
462 pj_str_t tmp;
463 tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1));
464 reason->ptr = reason_buf;
465 pj_strncpy(reason, &tmp, sizeof(reason_buf));
466 } else {
467 reason->slen = 0;
468 }
469 }
470 Py_XDECREF(ret);
471 } else if (ret) {
472 Py_XDECREF(ret);
473 }
474
475 LEAVE_PYTHON();
476 }
477}
478
479/*
480 * cb_on_buddy_state
481 * declares method on_buddy state for callback struct
482 */
483static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
484{
485 if (PyCallable_Check(g_obj_callback->on_buddy_state)) {
486 ENTER_PYTHON();
487
488 PyObject_CallFunction(
489 g_obj_callback->on_buddy_state,
490 "i",
491 buddy_id,
492 NULL
493 );
494
495 LEAVE_PYTHON();
496 }
497}
498
499/*
500 * cb_on_pager
501 * declares method on_pager for callback struct
502 */
503static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
504 const pj_str_t *to, const pj_str_t *contact,
505 const pj_str_t *mime_type, const pj_str_t *body,
506 pjsip_rx_data *rdata, pjsua_acc_id acc_id)
507{
508 PJ_UNUSED_ARG(rdata);
509
510 if (PyCallable_Check(g_obj_callback->on_pager)) {
511 PyObject *param_from, *param_to, *param_contact, *param_mime_type,
512 *param_body;
513
514 ENTER_PYTHON();
515
516 param_from = PyString_FromPJ(from);
517 param_to = PyString_FromPJ(to);
518 param_contact = PyString_FromPJ(contact);
519 param_mime_type = PyString_FromPJ(mime_type);
520 param_body = PyString_FromPJ(body);
521
522 PyObject_CallFunction(
523 g_obj_callback->on_pager,
524 "iOOOOOi",
525 call_id,
526 param_from,
527 param_to,
528 param_contact,
529 param_mime_type,
530 param_body,
531 acc_id,
532 NULL
533 );
534
535 Py_DECREF(param_body);
536 Py_DECREF(param_mime_type);
537 Py_DECREF(param_contact);
538 Py_DECREF(param_to);
539 Py_DECREF(param_from);
540
541 LEAVE_PYTHON();
542 }
543}
544
545
546/*
547 * cb_on_pager_status
548 * declares method on_pager_status for callback struct
549 */
550static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
551 const pj_str_t *body, void *user_data,
552 pjsip_status_code status,
553 const pj_str_t *reason,
554 pjsip_tx_data *tdata,
555 pjsip_rx_data *rdata,
556 pjsua_acc_id acc_id)
557{
558 if (PyCallable_Check(g_obj_callback->on_pager)) {
559 PyObject *param_call_id, *param_to, *param_body,
560 *param_user_data, *param_status, *param_reason,
561 *param_acc_id;
562
563 ENTER_PYTHON();
564
565 PJ_UNUSED_ARG(tdata);
566 PJ_UNUSED_ARG(rdata);
567
568 PyObject_CallFunctionObjArgs(
569 g_obj_callback->on_pager_status,
570 param_call_id = Py_BuildValue("i",call_id),
571 param_to = PyString_FromPJ(to),
572 param_body = PyString_FromPJ(body),
573 param_user_data = Py_BuildValue("i", user_data),
574 param_status = Py_BuildValue("i",status),
575 param_reason = PyString_FromPJ(reason),
576 param_acc_id = Py_BuildValue("i",acc_id),
577 NULL
578 );
579
580 Py_DECREF(param_call_id);
581 Py_DECREF(param_to);
582 Py_DECREF(param_body);
583 Py_DECREF(param_user_data);
584 Py_DECREF(param_status);
585 Py_DECREF(param_reason);
586 Py_DECREF(param_acc_id);
587
588 LEAVE_PYTHON();
589 }
590}
591
592
593/*
594 * cb_on_typing
595 * declares method on_typing for callback struct
596 */
597static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
598 const pj_str_t *to, const pj_str_t *contact,
599 pj_bool_t is_typing, pjsip_rx_data *rdata,
600 pjsua_acc_id acc_id)
601{
602 if (PyCallable_Check(g_obj_callback->on_typing)) {
603 PyObject *param_call_id, *param_from, *param_to, *param_contact,
604 *param_is_typing, *param_acc_id;
605
606 ENTER_PYTHON();
607
608 PJ_UNUSED_ARG(rdata);
609
610 PyObject_CallFunctionObjArgs(
611 g_obj_callback->on_typing,
612 param_call_id = Py_BuildValue("i",call_id),
613 param_from = PyString_FromPJ(from),
614 param_to = PyString_FromPJ(to),
615 param_contact = PyString_FromPJ(contact),
616 param_is_typing = Py_BuildValue("i",is_typing),
617 param_acc_id = Py_BuildValue("i",acc_id),
618 NULL
619 );
620
621 Py_DECREF(param_call_id);
622 Py_DECREF(param_from);
623 Py_DECREF(param_to);
624 Py_DECREF(param_contact);
625 Py_DECREF(param_is_typing);
626 Py_DECREF(param_acc_id);
627
628 LEAVE_PYTHON();
629 }
630}
631
632
633/*
634 * on_mwi_info
635 */
636static void cb_on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
637{
638 if (PyCallable_Check(g_obj_callback->on_mwi_info)) {
639 PyObject *param_acc_id, *param_body;
640 pj_str_t body;
641
642 ENTER_PYTHON();
643
644 body.ptr = mwi_info->rdata->msg_info.msg->body->data;
645 body.slen = mwi_info->rdata->msg_info.msg->body->len;
646
647 PyObject_CallFunctionObjArgs(
648 g_obj_callback->on_mwi_info,
649 param_acc_id = Py_BuildValue("i",acc_id),
650 param_body = PyString_FromPJ(&body),
651 NULL
652 );
653
654 Py_DECREF(param_acc_id);
655 Py_DECREF(param_body);
656
657 LEAVE_PYTHON();
658 }
659}
660
661/*
662 * translate_hdr
663 * internal function
664 * translate from hdr_list to pjsip_generic_string_hdr
665 */
666void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
667{
668 pj_list_init(hdr);
669
670 if (PyList_Check(py_hdr_list)) {
671 int i;
672
673 for (i=0; i<PyList_Size(py_hdr_list); ++i) {
674 pj_str_t hname, hvalue;
675 pjsip_generic_string_hdr * new_hdr;
676 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
677
678 if (PyTuple_Check(tuple)) {
679 if (PyTuple_Size(tuple) >= 1)
680 hname = PyString_ToPJ(PyTuple_GetItem(tuple,0));
681 else
682 hname.slen = 0;
683 if (PyTuple_Size(tuple) >= 2)
684 hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1));
685 else
686 hvalue.slen = 0;
687 } else {
688 hname.ptr = "";
689 hname.slen = 0;
690 hvalue.ptr = "";
691 hvalue.slen = 0;
692 }
693 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
694 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
695 }
696 }
697}
698
699/*
700 * py_pjsua_thread_register
701 */
702static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
703{
704 pj_status_t status;
705 const char *name;
706 PyObject *py_desc;
707 pj_thread_t *thread;
708 struct py_thread_desc *thread_desc;
709
710 PJ_UNUSED_ARG(pSelf);
711
712 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) {
713 return NULL;
714 }
715 thread_desc = (struct py_thread_desc*)
716 malloc(sizeof(struct py_thread_desc));
717 thread_desc->next = py_thread_desc;
718 py_thread_desc = thread_desc;
719
720 status = pj_thread_register(name, thread_desc->desc, &thread);
721
722 if (status == PJ_SUCCESS)
723 status = pj_thread_local_set(g_thread_id, (void*)1);
724
725 return Py_BuildValue("i",status);
726}
727
728/*
729 * py_pjsua_logging_config_default
730 */
731static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
732 PyObject *pArgs)
733{
734 PyObj_pjsua_logging_config *obj;
735 pjsua_logging_config cfg;
736
737 PJ_UNUSED_ARG(pSelf);
738 PJ_UNUSED_ARG(pArgs);
739
740 pjsua_logging_config_default(&cfg);
741 obj = (PyObj_pjsua_logging_config*)
742 PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config,
743 NULL, NULL);
744 PyObj_pjsua_logging_config_import(obj, &cfg);
745
746 return (PyObject*)obj;
747}
748
749
750/*
751 * py_pjsua_config_default
752 */
753static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
754{
755 PyObj_pjsua_config *obj;
756 pjsua_config cfg;
757
758 PJ_UNUSED_ARG(pSelf);
759 PJ_UNUSED_ARG(pArgs);
760
761 pjsua_config_default(&cfg);
762 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config,
763 NULL, NULL);
764 PyObj_pjsua_config_import(obj, &cfg);
765
766 return (PyObject*)obj;
767}
768
769
770/*
771 * py_pjsua_media_config_default
772 */
773static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
774 PyObject *pArgs)
775{
776 PyObj_pjsua_media_config *obj;
777 pjsua_media_config cfg;
778
779 PJ_UNUSED_ARG(pSelf);
780 PJ_UNUSED_ARG(pArgs);
781
782 pjsua_media_config_default(&cfg);
783 obj = (PyObj_pjsua_media_config *)
784 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
785 PyObj_pjsua_media_config_import(obj, &cfg);
786
787 return (PyObject *)obj;
788}
789
790
791/*
792 * py_pjsua_msg_data_init
793 */
794static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
795{
796 PJ_UNUSED_ARG(pSelf);
797 PJ_UNUSED_ARG(pArgs);
798
799 return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data,
800 NULL, NULL);
801}
802
803
804/*
805 * py_pjsua_reconfigure_logging
806 */
807static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf,
808 PyObject *pArgs)
809{
810 PyObject *logObj;
811 pj_status_t status;
812
813 PJ_UNUSED_ARG(pSelf);
814
815 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) {
816 return NULL;
817 }
818
819 if (logObj != Py_None) {
820 PyObj_pjsua_logging_config *log;
821 pjsua_logging_config cfg;
822
823 log = (PyObj_pjsua_logging_config*)logObj;
824 cfg.msg_logging = log->msg_logging;
825 cfg.level = log->level;
826 cfg.console_level = log->console_level;
827 cfg.decor = log->decor;
828 cfg.log_filename = PyString_ToPJ(log->log_filename);
829 Py_XDECREF(g_obj_log_cb);
830 g_obj_log_cb = log->cb;
831 Py_INCREF(g_obj_log_cb);
832 cfg.cb = &cb_log_cb;
833 status = pjsua_reconfigure_logging(&cfg);
834 } else {
835 status = pjsua_reconfigure_logging(NULL);
836 }
837
838 return Py_BuildValue("i",status);
839}
840
841
842/*
843 * py_pjsua_perror
844 */
845static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
846{
847 const char *sender;
848 const char *title;
849 pj_status_t status;
850
851 PJ_UNUSED_ARG(pSelf);
852
853 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
854 return NULL;
855 }
856
857 pjsua_perror(sender, title, status);
858
859 return Py_BuildValue("");
860}
861
862
863/*
864 * py_pjsua_create
865 */
866static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
867{
868 pj_status_t status;
869
870 PJ_UNUSED_ARG(pSelf);
871 PJ_UNUSED_ARG(pArgs);
872
873 status = pjsua_create();
874
875 if (status == PJ_SUCCESS) {
876 status = pj_thread_local_alloc(&g_thread_id);
877 if (status == PJ_SUCCESS)
878 status = pj_thread_local_set(g_thread_id, (void*)1);
879
880 pj_atexit(&clear_py_thread_desc);
881 }
882
883 return Py_BuildValue("i",status);
884}
885
886
887/*
888 * py_pjsua_init
889 */
890static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
891{
892 pj_status_t status;
893 PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
894 pjsua_config cfg_ua, *p_cfg_ua;
895 pjsua_logging_config cfg_log, *p_cfg_log;
896 pjsua_media_config cfg_media, *p_cfg_media;
897
898 PJ_UNUSED_ARG(pSelf);
899
900 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) {
901 return NULL;
902 }
903
904 pjsua_config_default(&cfg_ua);
905 pjsua_logging_config_default(&cfg_log);
906 pjsua_media_config_default(&cfg_media);
907
908 if (o_ua_cfg != Py_None) {
909 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
910
911 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
912
913 Py_XDECREF(g_obj_callback);
914 g_obj_callback = obj_ua_cfg->cb;
915 Py_INCREF(g_obj_callback);
916
917 cfg_ua.cb.on_call_state = &cb_on_call_state;
918 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
919 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
920 cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
921 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
922 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
923 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
924 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
925 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
926 cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe;
927 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
928 cfg_ua.cb.on_pager2 = &cb_on_pager;
929 cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
930 cfg_ua.cb.on_typing2 = &cb_on_typing;
931 cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;
932
933 p_cfg_ua = &cfg_ua;
934
935 } else {
936 p_cfg_ua = NULL;
937 }
938
939 if (o_log_cfg != Py_None) {
940 PyObj_pjsua_logging_config * obj_log;
941
942 obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
943
944 PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
945
946 Py_XDECREF(g_obj_log_cb);
947 g_obj_log_cb = obj_log->cb;
948 Py_INCREF(g_obj_log_cb);
949
950 cfg_log.cb = &cb_log_cb;
951 p_cfg_log = &cfg_log;
952
953 } else {
954 p_cfg_log = NULL;
955 }
956
957 if (o_media_cfg != Py_None) {
958 PyObj_pjsua_media_config_export(&cfg_media,
959 (PyObj_pjsua_media_config*)o_media_cfg);
960 p_cfg_media = &cfg_media;
961
962 } else {
963 p_cfg_media = NULL;
964 }
965
966 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
967
968 return Py_BuildValue("i", status);
969}
970
971
972/*
973 * py_pjsua_start
974 */
975static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
976{
977 pj_status_t status;
978
979 PJ_UNUSED_ARG(pSelf);
980 PJ_UNUSED_ARG(pArgs);
981
982 status = pjsua_start();
983
984 return Py_BuildValue("i", status);
985}
986
987
988/*
989 * py_pjsua_destroy
990 */
991static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
992{
993 pj_status_t status;
994
995 PJ_UNUSED_ARG(pSelf);
996 PJ_UNUSED_ARG(pArgs);
997
998 status = pjsua_destroy();
999
1000 return Py_BuildValue("i", status);
1001}
1002
1003
1004/*
1005 * py_pjsua_handle_events
1006 */
1007static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
1008{
1009 int ret;
1010 int msec;
1011
1012 PJ_UNUSED_ARG(pSelf);
1013
1014 if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
1015 return NULL;
1016 }
1017
1018 if (msec < 0)
1019 msec = 0;
1020
1021#if !NO_PJSIP_THREAD
1022 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
1023 * construct, or otherwise many Python blocking functions (such as
1024 * time.sleep(), readline(), etc.) may hang/block indefinitely.
1025 * See http://www.python.org/doc/current/api/threads.html for more info.
1026 */
1027 Py_BEGIN_ALLOW_THREADS
1028#endif
1029
1030 ret = pjsua_handle_events(msec);
1031
1032#if !NO_PJSIP_THREAD
1033 Py_END_ALLOW_THREADS
1034#endif
1035
1036 return Py_BuildValue("i", ret);
1037}
1038
1039
1040/*
1041 * py_pjsua_verify_sip_url
1042 */
1043static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
1044{
1045 pj_status_t status;
1046 const char *url;
1047
1048 PJ_UNUSED_ARG(pSelf);
1049
1050 if (!PyArg_ParseTuple(pArgs, "s", &url)) {
1051 return NULL;
1052 }
1053
1054 status = pjsua_verify_sip_url(url);
1055
1056 return Py_BuildValue("i", status);
1057}
1058
1059
1060/*
1061 * function doc
1062 */
1063
1064static char pjsua_thread_register_doc[] =
1065 "int _pjsua.thread_register(string name, int[] desc)";
1066static char pjsua_perror_doc[] =
1067 "void _pjsua.perror (string sender, string title, int status) "
1068 "Display error message for the specified error code. Parameters: "
1069 "sender: The log sender field; "
1070 "title: Message title for the error; "
1071 "status: Status code.";
1072
1073static char pjsua_create_doc[] =
1074 "int _pjsua.create (void) "
1075 "Instantiate pjsua application. Application "
1076 "must call this function before calling any other functions, to make sure "
1077 "that the underlying libraries are properly initialized. Once this "
1078 "function has returned success, application must call pjsua_destroy() "
1079 "before quitting.";
1080
1081static char pjsua_init_doc[] =
1082 "int _pjsua.init (_pjsua.Config obj_ua_cfg, "
1083 "_pjsua.Logging_Config log_cfg, _pjsua.Media_Config media_cfg) "
1084 "Initialize pjsua with the specified settings. All the settings are "
1085 "optional, and the default values will be used when the config is not "
1086 "specified. Parameters: "
1087 "obj_ua_cfg : User agent configuration; "
1088 "log_cfg : Optional logging configuration; "
1089 "media_cfg : Optional media configuration.";
1090
1091static char pjsua_start_doc[] =
1092 "int _pjsua.start (void) "
1093 "Application is recommended to call this function after all "
1094 "initialization is done, so that the library can do additional checking "
1095 "set up additional";
1096
1097static char pjsua_destroy_doc[] =
1098 "int _pjsua.destroy (void) "
1099 "Destroy pjsua This function must be called once PJSUA is created. To "
1100 "make it easier for application, application may call this function "
1101 "several times with no danger.";
1102
1103static char pjsua_handle_events_doc[] =
1104 "int _pjsua.handle_events (int msec_timeout) "
1105 "Poll pjsua for events, and if necessary block the caller thread for the "
1106 "specified maximum interval (in miliseconds) Parameters: "
1107 "msec_timeout: Maximum time to wait, in miliseconds. "
1108 "Returns: The number of events that have been handled during the poll. "
1109 "Negative value indicates error, and application can retrieve the error "
1110 "as (err = -return_value).";
1111
1112static char pjsua_verify_sip_url_doc[] =
1113 "int _pjsua.verify_sip_url (string c_url) "
1114 "Verify that valid SIP url is given Parameters: "
1115 "c_url: The URL, as NULL terminated string.";
1116
1117static char pjsua_reconfigure_logging_doc[] =
1118 "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) "
1119 "Application can call this function at any time (after pjsua_create(), of "
1120 "course) to change logging settings. Parameters: "
1121 "c: Logging configuration.";
1122
1123static char pjsua_logging_config_default_doc[] =
1124 "_pjsua.Logging_Config _pjsua.logging_config_default () "
1125 "Use this function to initialize logging config.";
1126
1127static char pjsua_config_default_doc[] =
1128 "_pjsua.Config _pjsua.config_default (). Use this function to "
1129 "initialize pjsua config. ";
1130
1131static char pjsua_media_config_default_doc[] =
1132 "_pjsua.Media_Config _pjsua.media_config_default (). "
1133 "Use this function to initialize media config.";
1134
1135static char pjsua_msg_data_init_doc[] =
1136 "_pjsua.Msg_Data void _pjsua.msg_data_init () "
1137 "Initialize message data ";
1138
1139
1140/* END OF LIB BASE */
1141
1142/* LIB TRANSPORT */
1143
1144/*
1145 * py_pjsua_transport_config_default
1146 */
1147static PyObject *py_pjsua_transport_config_default(PyObject *pSelf,
1148 PyObject *pArgs)
1149{
1150 PyObj_pjsua_transport_config *obj;
1151 pjsua_transport_config cfg;
1152
1153 PJ_UNUSED_ARG(pSelf);
1154 PJ_UNUSED_ARG(pArgs);
1155
1156 pjsua_transport_config_default(&cfg);
1157 obj = (PyObj_pjsua_transport_config*)
1158 PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
1159 NULL, NULL);
1160 PyObj_pjsua_transport_config_import(obj, &cfg);
1161
1162 return (PyObject *)obj;
1163}
1164
1165/*
1166 * py_pjsua_transport_create
1167 */
1168static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1169{
1170 pj_status_t status;
1171 int type;
1172 PyObject *pCfg;
1173 pjsua_transport_config cfg;
1174 pjsua_transport_id id;
1175
1176 PJ_UNUSED_ARG(pSelf);
1177
1178 if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) {
1179 return NULL;
1180 }
1181
1182 if (pCfg != Py_None) {
1183 PyObj_pjsua_transport_config *obj;
1184
1185 obj = (PyObj_pjsua_transport_config*)pCfg;
1186 PyObj_pjsua_transport_config_export(&cfg, obj);
1187 status = pjsua_transport_create(type, &cfg, &id);
1188 } else {
1189 status = pjsua_transport_create(type, NULL, &id);
1190 }
1191
1192
1193 return Py_BuildValue("ii", status, id);
1194}
1195
1196/*
1197 * py_pjsua_enum_transports
1198 */
1199static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1200{
1201 pj_status_t status;
1202 PyObject *list;
1203 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
1204 unsigned c, i;
1205
1206 PJ_UNUSED_ARG(pSelf);
1207 PJ_UNUSED_ARG(pArgs);
1208
1209 c = PJ_ARRAY_SIZE(id);
1210 status = pjsua_enum_transports(id, &c);
1211
1212 list = PyList_New(c);
1213 for (i = 0; i < c; i++) {
1214 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1215 }
1216
1217 return (PyObject*)list;
1218}
1219
1220/*
1221 * py_pjsua_transport_get_info
1222 * !modified @ 051206
1223 */
1224static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
1225{
1226 pj_status_t status;
1227 int id;
1228 pjsua_transport_info info;
1229
1230 PJ_UNUSED_ARG(pSelf);
1231
1232 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1233 return NULL;
1234 }
1235
1236 status = pjsua_transport_get_info(id, &info);
1237 if (status == PJ_SUCCESS) {
1238 PyObj_pjsua_transport_info *obj;
1239 obj = (PyObj_pjsua_transport_info *)
1240 PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info,
1241 NULL, NULL);
1242 PyObj_pjsua_transport_info_import(obj, &info);
1243 return (PyObject*)obj;
1244 } else {
1245 return Py_BuildValue("");
1246 }
1247}
1248
1249/*
1250 * py_pjsua_transport_set_enable
1251 */
1252static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf,
1253 PyObject *pArgs)
1254{
1255 pj_status_t status;
1256 int id;
1257 int enabled;
1258
1259 PJ_UNUSED_ARG(pSelf);
1260
1261 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) {
1262 return NULL;
1263 }
1264 status = pjsua_transport_set_enable(id, enabled);
1265
1266 return Py_BuildValue("i", status);
1267}
1268
1269/*
1270 * py_pjsua_transport_close
1271 */
1272static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
1273{
1274 pj_status_t status;
1275 int id;
1276 int force;
1277
1278 PJ_UNUSED_ARG(pSelf);
1279
1280 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) {
1281 return NULL;
1282 }
1283 status = pjsua_transport_close(id, force);
1284
1285 return Py_BuildValue("i", status);
1286}
1287
1288static char pjsua_transport_config_default_doc[] =
1289 "_pjsua.Transport_Config _pjsua.transport_config_default () "
1290 "Call this function to initialize UDP config with default values.";
1291static char pjsua_transport_create_doc[] =
1292 "int, int _pjsua.transport_create (int type, "
1293 "_pjsua.Transport_Config cfg) "
1294 "Create SIP transport.";
1295static char pjsua_enum_transports_doc[] =
1296 "int[] _pjsua.enum_transports () "
1297 "Enumerate all transports currently created in the system.";
1298static char pjsua_transport_get_info_doc[] =
1299 "void _pjsua.transport_get_info "
1300 "(_pjsua.Transport_ID id, _pjsua.Transport_Info info) "
1301 "Get information about transports.";
1302static char pjsua_transport_set_enable_doc[] =
1303 "void _pjsua.transport_set_enable "
1304 "(_pjsua.Transport_ID id, int enabled) "
1305 "Disable a transport or re-enable it. "
1306 "By default transport is always enabled after it is created. "
1307 "Disabling a transport does not necessarily close the socket, "
1308 "it will only discard incoming messages and prevent the transport "
1309 "from being used to send outgoing messages.";
1310static char pjsua_transport_close_doc[] =
1311 "void _pjsua.transport_close (_pjsua.Transport_ID id, int force) "
1312 "Close the transport. If transport is forcefully closed, "
1313 "it will be immediately closed, and any pending transactions "
1314 "that are using the transport may not terminate properly. "
1315 "Otherwise, the system will wait until all transactions are closed "
1316 "while preventing new users from using the transport, and will close "
1317 "the transport when it is safe to do so.";
1318
1319/* END OF LIB TRANSPORT */
1320
1321/* LIB ACCOUNT */
1322
1323
1324/*
1325 * py_pjsua_acc_config_default
1326 */
1327static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
1328{
1329 PyObj_pjsua_acc_config *obj;
1330 pjsua_acc_config cfg;
1331
1332 PJ_UNUSED_ARG(pSelf);
1333 PJ_UNUSED_ARG(pArgs);
1334
1335 if (!PyArg_ParseTuple(pArgs, "")) {
1336 return NULL;
1337 }
1338
1339 pjsua_acc_config_default(&cfg);
1340 obj = (PyObj_pjsua_acc_config *)
1341 PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config,
1342 NULL, NULL);
1343 PyObj_pjsua_acc_config_import(obj, &cfg);
1344 return (PyObject *)obj;
1345}
1346
1347/*
1348 * py_pjsua_acc_get_count
1349 */
1350static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
1351{
1352 int count;
1353
1354 PJ_UNUSED_ARG(pSelf);
1355 PJ_UNUSED_ARG(pArgs);
1356
1357 count = pjsua_acc_get_count();
1358 return Py_BuildValue("i", count);
1359}
1360
1361/*
1362 * py_pjsua_acc_is_valid
1363 */
1364static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
1365{
1366 int id;
1367 int is_valid;
1368
1369 PJ_UNUSED_ARG(pSelf);
1370
1371 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1372 return NULL;
1373 }
1374
1375 is_valid = pjsua_acc_is_valid(id);
1376 return Py_BuildValue("i", is_valid);
1377}
1378
1379/*
1380 * py_pjsua_acc_set_default
1381 */
1382static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
1383{
1384 int id;
1385 int status;
1386
1387 PJ_UNUSED_ARG(pSelf);
1388
1389 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1390 return NULL;
1391 }
1392 status = pjsua_acc_set_default(id);
1393
1394 return Py_BuildValue("i", status);
1395}
1396
1397/*
1398 * py_pjsua_acc_get_default
1399 */
1400static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
1401{
1402 int id;
1403
1404 PJ_UNUSED_ARG(pSelf);
1405 PJ_UNUSED_ARG(pArgs);
1406
1407 id = pjsua_acc_get_default();
1408
1409 return Py_BuildValue("i", id);
1410}
1411
1412/*
1413 * py_pjsua_acc_add
1414 */
1415static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
1416{
1417 int is_default;
1418 PyObject *pCfg;
1419 int acc_id;
1420 int status;
1421
1422 PJ_UNUSED_ARG(pSelf);
1423
1424 if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) {
1425 return NULL;
1426 }
1427
1428 if (pCfg != Py_None) {
1429 pjsua_acc_config cfg;
1430 PyObj_pjsua_acc_config *ac;
1431
1432 pjsua_acc_config_default(&cfg);
1433 ac = (PyObj_pjsua_acc_config *)pCfg;
1434 PyObj_pjsua_acc_config_export(&cfg, ac);
1435 status = pjsua_acc_add(&cfg, is_default, &acc_id);
1436 } else {
1437 status = PJ_EINVAL;
1438 acc_id = PJSUA_INVALID_ID;
1439 }
1440
1441 return Py_BuildValue("ii", status, acc_id);
1442}
1443
1444/*
1445 * py_pjsua_acc_add_local
1446 */
1447static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
1448{
1449 int is_default;
1450 int tid;
1451 int acc_id;
1452 int status;
1453
1454 PJ_UNUSED_ARG(pSelf);
1455
1456 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
1457 return NULL;
1458 }
1459
1460 status = pjsua_acc_add_local(tid, is_default, &acc_id);
1461
1462 return Py_BuildValue("ii", status, acc_id);
1463}
1464
1465/*
1466 * py_pjsua_acc_set_user_data
1467 */
1468static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs)
1469{
1470 int acc_id;
1471 PyObject *pUserData, *old_user_data;
1472 int status;
1473
1474 PJ_UNUSED_ARG(pSelf);
1475
1476 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) {
1477 return NULL;
1478 }
1479
1480 old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1481
1482 status = pjsua_acc_set_user_data(acc_id, (void*)pUserData);
1483
1484 if (status == PJ_SUCCESS) {
1485 Py_XINCREF(pUserData);
1486 Py_XDECREF(old_user_data);
1487 }
1488
1489 return Py_BuildValue("i", status);
1490}
1491
1492/*
1493 * py_pjsua_acc_get_user_data
1494 */
1495static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs)
1496{
1497 int acc_id;
1498 PyObject *user_data;
1499
1500 PJ_UNUSED_ARG(pSelf);
1501
1502 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1503 return NULL;
1504 }
1505
1506 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1507
1508 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
1509}
1510
1511/*
1512 * py_pjsua_acc_del
1513 */
1514static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
1515{
1516 int acc_id;
1517 PyObject *user_data;
1518 int status;
1519
1520 PJ_UNUSED_ARG(pSelf);
1521
1522 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1523 return NULL;
1524 }
1525
1526 user_data = (PyObject*) pjsua_acc_get_user_data(acc_id);
1527 Py_XDECREF(user_data);
1528
1529 status = pjsua_acc_del(acc_id);
1530
1531 return Py_BuildValue("i", status);
1532}
1533
1534/*
1535 * py_pjsua_acc_modify
1536 */
1537static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
1538{
1539 PyObject *pCfg;
1540 PyObj_pjsua_acc_config * ac;
1541 int acc_id;
1542 int status;
1543
1544 PJ_UNUSED_ARG(pSelf);
1545
1546 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) {
1547 return NULL;
1548 }
1549
1550 if (pCfg != Py_None) {
1551 pjsua_acc_config cfg;
1552
1553 pjsua_acc_config_default(&cfg);
1554 ac = (PyObj_pjsua_acc_config*)pCfg;
1555 PyObj_pjsua_acc_config_export(&cfg, ac);
1556
1557 status = pjsua_acc_modify(acc_id, &cfg);
1558 } else {
1559 status = PJ_EINVAL;
1560 }
1561 return Py_BuildValue("i", status);
1562}
1563
1564/*
1565 * py_pjsua_acc_set_online_status
1566 */
1567static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf,
1568 PyObject *pArgs)
1569{
1570 int is_online;
1571 int acc_id;
1572 int status;
1573
1574 PJ_UNUSED_ARG(pSelf);
1575
1576 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
1577 return NULL;
1578 }
1579
1580 status = pjsua_acc_set_online_status(acc_id, is_online);
1581
1582 return Py_BuildValue("i", status);
1583}
1584
1585/*
1586 * py_pjsua_acc_set_online_status2
1587 */
1588static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf,
1589 PyObject *pArgs)
1590{
1591 int is_online;
1592 int acc_id;
1593 int activity_id;
1594 const char *activity_text = NULL;
1595 const char *rpid_id = NULL;
1596 pjrpid_element rpid;
1597 pj_status_t status;
1598
1599 PJ_UNUSED_ARG(pSelf);
1600
1601 if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online,
1602 &activity_id, &activity_text, &rpid_id))
1603 {
1604 return NULL;
1605 }
1606
1607 pj_bzero(&rpid, sizeof(rpid));
1608 rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
1609 rpid.activity = activity_id;
1610 if (activity_text)
1611 rpid.note = pj_str((char*)activity_text);
1612
1613 if (rpid_id)
1614 rpid.id = pj_str((char*)rpid_id);
1615
1616 status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
1617
1618 return Py_BuildValue("i", status);
1619}
1620
1621/*
1622 * py_pjsua_acc_set_registration
1623 */
1624static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf,
1625 PyObject *pArgs)
1626{
1627 int renew;
1628 int acc_id;
1629 int status;
1630
1631 PJ_UNUSED_ARG(pSelf);
1632
1633 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
1634 return NULL;
1635 }
1636
1637 status = pjsua_acc_set_registration(acc_id, renew);
1638
1639 return Py_BuildValue("i", status);
1640}
1641
1642/*
1643 * py_pjsua_acc_get_info
1644 */
1645static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
1646{
1647 int acc_id;
1648 PyObj_pjsua_acc_info * obj;
1649 pjsua_acc_info info;
1650 int status;
1651
1652 PJ_UNUSED_ARG(pSelf);
1653
1654 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
1655 return NULL;
1656 }
1657
1658 status = pjsua_acc_get_info(acc_id, &info);
1659 if (status == PJ_SUCCESS) {
1660 obj = (PyObj_pjsua_acc_info*)
1661 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1662 PyObj_pjsua_acc_info_import(obj, &info);
1663 return (PyObject*)obj;
1664 } else {
1665 return Py_BuildValue("");
1666 }
1667}
1668
1669/*
1670 * py_pjsua_enum_accs
1671 */
1672static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1673{
1674 pj_status_t status;
1675 PyObject *list;
1676 pjsua_acc_id id[PJSUA_MAX_ACC];
1677 unsigned c, i;
1678
1679 PJ_UNUSED_ARG(pSelf);
1680 PJ_UNUSED_ARG(pArgs);
1681
1682 c = PJ_ARRAY_SIZE(id);
1683 status = pjsua_enum_accs(id, &c);
1684 if (status != PJ_SUCCESS)
1685 c = 0;
1686
1687 list = PyList_New(c);
1688 for (i = 0; i < c; i++) {
1689 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1690 }
1691
1692 return (PyObject*)list;
1693}
1694
1695/*
1696 * py_pjsua_acc_enum_info
1697 */
1698static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
1699{
1700 pj_status_t status;
1701 PyObject *list;
1702 pjsua_acc_info info[PJSUA_MAX_ACC];
1703 unsigned c, i;
1704
1705 PJ_UNUSED_ARG(pSelf);
1706 PJ_UNUSED_ARG(pArgs);
1707
1708 if (!PyArg_ParseTuple(pArgs, "")) {
1709 return NULL;
1710 }
1711
1712 c = PJ_ARRAY_SIZE(info);
1713 status = pjsua_acc_enum_info(info, &c);
1714 if (status != PJ_SUCCESS)
1715 c = 0;
1716
1717 list = PyList_New(c);
1718 for (i = 0; i < c; i++) {
1719 PyObj_pjsua_acc_info *obj;
1720 obj = (PyObj_pjsua_acc_info *)
1721 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1722
1723 PyObj_pjsua_acc_info_import(obj, &info[i]);
1724
1725 PyList_SetItem(list, i, (PyObject*)obj);
1726 }
1727
1728 return (PyObject*)list;
1729}
1730
1731/*
1732 * py_pjsua_acc_set_transport
1733 */
1734static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs)
1735{
1736 int acc_id, transport_id;
1737 int status;
1738
1739 PJ_UNUSED_ARG(pSelf);
1740
1741 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) {
1742 return NULL;
1743 }
1744
1745 status = pjsua_acc_set_transport(acc_id, transport_id);
1746
1747
1748 return Py_BuildValue("i", status);
1749}
1750
1751
1752/*
1753 * py_pjsua_acc_pres_notify
1754 */
1755static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf,
1756 PyObject *pArgs)
1757{
1758 int acc_id, state;
1759 PyObject *arg_pres, *arg_msg_data, *arg_reason;
1760 void *srv_pres;
1761 pjsua_msg_data msg_data;
1762 pj_str_t reason;
1763 pj_bool_t with_body;
1764 pj_pool_t *pool = NULL;
1765 int status;
1766
1767 PJ_UNUSED_ARG(pSelf);
1768
1769 if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres,
1770 &state, &arg_reason, &arg_msg_data))
1771 {
1772 return NULL;
1773 }
1774
1775 srv_pres = (void*) PyLong_AsLong(arg_pres);
1776 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED);
1777
1778 if (arg_reason && PyString_Check(arg_reason)) {
1779 reason = PyString_ToPJ(arg_reason);
1780 } else {
1781 reason = pj_str("");
1782 }
1783
1784 pjsua_msg_data_init(&msg_data);
1785 if (arg_msg_data && arg_msg_data != Py_None) {
1786 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data;
1787 msg_data.content_type = PyString_ToPJ(omd->content_type);
1788 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
1789 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
1790 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
1791 }
1792
1793 status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres,
1794 (pjsip_evsub_state)state, NULL,
1795 &reason, with_body, &msg_data);
1796
1797 if (pool) {
1798 pj_pool_release(pool);
1799 }
1800
1801 return Py_BuildValue("i", status);
1802}
1803
1804static char pjsua_acc_config_default_doc[] =
1805 "_pjsua.Acc_Config _pjsua.acc_config_default () "
1806 "Call this function to initialize account config with default values.";
1807static char pjsua_acc_get_count_doc[] =
1808 "int _pjsua.acc_get_count () "
1809 "Get number of current accounts.";
1810static char pjsua_acc_is_valid_doc[] =
1811 "int _pjsua.acc_is_valid (int acc_id) "
1812 "Check if the specified account ID is valid.";
1813static char pjsua_acc_set_default_doc[] =
1814 "int _pjsua.acc_set_default (int acc_id) "
1815 "Set default account to be used when incoming "
1816 "and outgoing requests doesn't match any accounts.";
1817static char pjsua_acc_get_default_doc[] =
1818 "int _pjsua.acc_get_default () "
1819 "Get default account.";
1820static char pjsua_acc_add_doc[] =
1821 "int, int _pjsua.acc_add (_pjsua.Acc_Config cfg, "
1822 "int is_default) "
1823 "Add a new account to pjsua. PJSUA must have been initialized "
1824 "(with pjsua_init()) before calling this function.";
1825static char pjsua_acc_add_local_doc[] =
1826 "int,int _pjsua.acc_add_local (int tid, "
1827 "int is_default) "
1828 "Add a local account. A local account is used to identify "
1829 "local endpoint instead of a specific user, and for this reason, "
1830 "a transport ID is needed to obtain the local address information.";
1831static char pjsua_acc_del_doc[] =
1832 "int _pjsua.acc_del (int acc_id) "
1833 "Delete account.";
1834static char pjsua_acc_modify_doc[] =
1835 "int _pjsua.acc_modify (int acc_id, _pjsua.Acc_Config cfg) "
1836 "Modify account information.";
1837static char pjsua_acc_set_online_status_doc[] =
1838 "int _pjsua.acc_set_online_status2(int acc_id, int is_online) "
1839 "Modify account's presence status to be advertised "
1840 "to remote/presence subscribers.";
1841static char pjsua_acc_set_online_status2_doc[] =
1842 "int _pjsua.acc_set_online_status (int acc_id, int is_online, "
1843 "int activity_id, string activity_text) "
1844 "Modify account's presence status to be advertised "
1845 "to remote/presence subscribers.";
1846static char pjsua_acc_set_registration_doc[] =
1847 "int _pjsua.acc_set_registration (int acc_id, int renew) "
1848 "Update registration or perform unregistration.";
1849static char pjsua_acc_get_info_doc[] =
1850 "_pjsua.Acc_Info _pjsua.acc_get_info (int acc_id) "
1851 "Get account information.";
1852static char pjsua_enum_accs_doc[] =
1853 "int[] _pjsua.enum_accs () "
1854 "Enum accounts all account ids.";
1855static char pjsua_acc_enum_info_doc[] =
1856 "_pjsua.Acc_Info[] _pjsua.acc_enum_info () "
1857 "Enum accounts info.";
1858
1859/* END OF LIB ACCOUNT */
1860
1861/* LIB BUDDY */
1862
1863
1864
1865/*
1866 * py_pjsua_buddy_config_default
1867 */
1868static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf,
1869 PyObject *pArgs)
1870{
1871 PyObj_pjsua_buddy_config *obj;
1872 pjsua_buddy_config cfg;
1873
1874 PJ_UNUSED_ARG(pSelf);
1875 PJ_UNUSED_ARG(pArgs);
1876
1877 pjsua_buddy_config_default(&cfg);
1878 obj = (PyObj_pjsua_buddy_config *)
1879 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
1880 PyObj_pjsua_buddy_config_import(obj, &cfg);
1881
1882 return (PyObject *)obj;
1883}
1884
1885/*
1886 * py_pjsua_get_buddy_count
1887 */
1888static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
1889{
1890 PJ_UNUSED_ARG(pSelf);
1891 PJ_UNUSED_ARG(pArgs);
1892
1893 return Py_BuildValue("i", pjsua_get_buddy_count());
1894}
1895
1896/*
1897 * py_pjsua_buddy_is_valid
1898 */
1899static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
1900{
1901 int id;
1902 int is_valid;
1903
1904 PJ_UNUSED_ARG(pSelf);
1905
1906 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
1907 return NULL;
1908 }
1909 is_valid = pjsua_buddy_is_valid(id);
1910
1911 return Py_BuildValue("i", is_valid);
1912}
1913
1914/*
1915 * py_pjsua_enum_buddies
1916 */
1917static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1918{
1919 pj_status_t status;
1920 PyObject *list;
1921 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
1922 unsigned c, i;
1923
1924 PJ_UNUSED_ARG(pSelf);
1925 PJ_UNUSED_ARG(pArgs);
1926
1927 c = PJ_ARRAY_SIZE(id);
1928 status = pjsua_enum_buddies(id, &c);
1929 if (status != PJ_SUCCESS)
1930 c = 0;
1931
1932 list = PyList_New(c);
1933 for (i = 0; i < c; i++) {
1934 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1935 }
1936
1937 return (PyObject*)list;
1938}
1939
1940/*
1941 * py_pjsua_buddy_find
1942 */
1943static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs)
1944{
1945 PyObject *pURI;
1946 pj_str_t uri;
1947 pjsua_buddy_id buddy_id;
1948
1949 PJ_UNUSED_ARG(pSelf);
1950
1951 if (!PyArg_ParseTuple(pArgs, "O", &pURI)) {
1952 return NULL;
1953 }
1954
1955 if (!PyString_Check(pURI))
1956 return Py_BuildValue("i", PJSUA_INVALID_ID);
1957
1958 uri = PyString_ToPJ(pURI);
1959 buddy_id = pjsua_buddy_find(&uri);
1960
1961 return Py_BuildValue("i", buddy_id);
1962}
1963
1964/*
1965 * py_pjsua_buddy_get_info
1966 */
1967static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
1968{
1969 int buddy_id;
1970 pjsua_buddy_info info;
1971 int status;
1972
1973 PJ_UNUSED_ARG(pSelf);
1974
1975 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
1976 return NULL;
1977 }
1978
1979 status = pjsua_buddy_get_info(buddy_id, &info);
1980 if (status == PJ_SUCCESS) {
1981 PyObj_pjsua_buddy_info *obj;
1982
1983 obj = (PyObj_pjsua_buddy_info *)
1984 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,
1985 NULL, NULL);
1986 PyObj_pjsua_buddy_info_import(obj, &info);
1987 return (PyObject*)obj;
1988 } else {
1989 return Py_BuildValue("");
1990 }
1991}
1992
1993/*
1994 * py_pjsua_buddy_add
1995 */
1996static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
1997{
1998 PyObject *pCfg;
1999 int buddy_id;
2000 int status;
2001
2002 PJ_UNUSED_ARG(pSelf);
2003
2004 if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) {
2005 return NULL;
2006 }
2007
2008 if (pCfg != Py_None) {
2009 pjsua_buddy_config cfg;
2010 PyObj_pjsua_buddy_config *bc;
2011
2012 bc = (PyObj_pjsua_buddy_config *)pCfg;
2013
2014 pjsua_buddy_config_default(&cfg);
2015 PyObj_pjsua_buddy_config_export(&cfg, bc);
2016
2017 status = pjsua_buddy_add(&cfg, &buddy_id);
2018
2019 } else {
2020 status = PJ_EINVAL;
2021 buddy_id = PJSUA_INVALID_ID;
2022 }
2023 return Py_BuildValue("ii", status, buddy_id);
2024}
2025
2026/*
2027 * py_pjsua_buddy_del
2028 */
2029static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
2030{
2031 int buddy_id;
2032 int status;
2033 PyObject *user_data;
2034
2035 PJ_UNUSED_ARG(pSelf);
2036
2037 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2038 return NULL;
2039 }
2040
2041 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2042 Py_XDECREF(user_data);
2043
2044 status = pjsua_buddy_del(buddy_id);
2045
2046 return Py_BuildValue("i", status);
2047}
2048
2049/*
2050 * py_pjsua_buddy_set_user_data
2051 */
2052static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs)
2053{
2054 int buddy_id;
2055 int status;
2056 PyObject *user_data, *old_user_data;
2057
2058 PJ_UNUSED_ARG(pSelf);
2059
2060 if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) {
2061 return NULL;
2062 }
2063
2064 if (!pjsua_buddy_is_valid(buddy_id)) {
2065 return Py_BuildValue("i", 0);
2066 }
2067
2068 old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2069
2070 status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data);
2071
2072 if (status == PJ_SUCCESS) {
2073 Py_XINCREF(user_data);
2074 Py_XDECREF(old_user_data);
2075 }
2076
2077 return Py_BuildValue("i", status);
2078}
2079
2080/*
2081 * py_pjsua_buddy_get_user_data
2082 */
2083static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs)
2084{
2085 int buddy_id;
2086 PyObject *user_data;
2087
2088 PJ_UNUSED_ARG(pSelf);
2089
2090 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2091 return NULL;
2092 }
2093
2094 user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id);
2095
2096 return user_data? Py_BuildValue("O", user_data) : Py_BuildValue("");
2097}
2098
2099/*
2100 * py_pjsua_buddy_subscribe_pres
2101 */
2102static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf,
2103 PyObject *pArgs)
2104{
2105 int buddy_id;
2106 int status;
2107 int subscribe;
2108
2109 PJ_UNUSED_ARG(pSelf);
2110
2111 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
2112 return NULL;
2113 }
2114
2115 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2116
2117 return Py_BuildValue("i", status);
2118}
2119
2120/*
2121 * py_pjsua_pres_dump
2122 */
2123static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
2124{
2125 int verbose;
2126
2127 PJ_UNUSED_ARG(pSelf);
2128
2129 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
2130 return NULL;
2131 }
2132
2133 pjsua_pres_dump(verbose);
2134
2135 return Py_BuildValue("");
2136}
2137
2138/*
2139 * py_pjsua_im_send
2140 */
2141static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
2142{
2143 int status;
2144 int acc_id;
2145 pj_str_t *mime_type, tmp_mime_type;
2146 pj_str_t to, content;
2147 PyObject *pTo;
2148 PyObject *pMimeType;
2149 PyObject *pContent;
2150 pjsua_msg_data msg_data;
2151 PyObject *pMsgData;
2152 int user_data;
2153 pj_pool_t *pool = NULL;
2154
2155 PJ_UNUSED_ARG(pSelf);
2156
2157 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
2158 &pTo, &pMimeType, &pContent, &pMsgData, &user_data))
2159 {
2160 return NULL;
2161 }
2162
2163 if (pMimeType != Py_None) {
2164 mime_type = &tmp_mime_type;
2165 tmp_mime_type = PyString_ToPJ(pMimeType);
2166 } else {
2167 mime_type = NULL;
2168 }
2169
2170 to = PyString_ToPJ(pTo);
2171 content = PyString_ToPJ(pContent);
2172
2173 pjsua_msg_data_init(&msg_data);
2174
2175 if (pMsgData != Py_None) {
2176 PyObj_pjsua_msg_data *omd;
2177
2178 omd = (PyObj_pjsua_msg_data *)pMsgData;
2179 msg_data.content_type = PyString_ToPJ(omd->content_type);
2180 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2181 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
2182 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2183 }
2184
2185 status = pjsua_im_send(acc_id, &to, mime_type, &content,
2186 &msg_data, (void*)(long)user_data);
2187 if (pool)
2188 pj_pool_release(pool);
2189
2190 return Py_BuildValue("i",status);
2191}
2192
2193/*
2194 * py_pjsua_im_typing
2195 */
2196static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
2197{
2198 int status;
2199 int acc_id;
2200 pj_str_t to;
2201 PyObject *pTo;
2202 int is_typing;
2203 pjsua_msg_data msg_data;
2204 PyObject *pMsgData;
2205 pj_pool_t *pool = NULL;
2206
2207 PJ_UNUSED_ARG(pSelf);
2208
2209 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing,
2210 &pMsgData))
2211 {
2212 return NULL;
2213 }
2214
2215 to = PyString_ToPJ(pTo);
2216
2217 pjsua_msg_data_init(&msg_data);
2218
2219 if (pMsgData != Py_None) {
2220 PyObj_pjsua_msg_data *omd;
2221
2222 omd = (PyObj_pjsua_msg_data *)pMsgData;
2223 msg_data.content_type = PyString_ToPJ(omd->content_type);
2224 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
2225 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
2226
2227 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2228 }
2229
2230 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
2231
2232 if (pool)
2233 pj_pool_release(pool);
2234
2235 return Py_BuildValue("i", status);
2236}
2237
2238static char pjsua_buddy_config_default_doc[] =
2239 "_pjsua.Buddy_Config _pjsua.buddy_config_default () "
2240 "Set default values to the buddy config.";
2241static char pjsua_get_buddy_count_doc[] =
2242 "int _pjsua.get_buddy_count () "
2243 "Get total number of buddies.";
2244static char pjsua_buddy_is_valid_doc[] =
2245 "int _pjsua.buddy_is_valid (int buddy_id) "
2246 "Check if buddy ID is valid.";
2247static char pjsua_enum_buddies_doc[] =
2248 "int[] _pjsua.enum_buddies () "
2249 "Enum buddy IDs.";
2250static char pjsua_buddy_get_info_doc[] =
2251 "_pjsua.Buddy_Info _pjsua.buddy_get_info (int buddy_id) "
2252 "Get detailed buddy info.";
2253static char pjsua_buddy_add_doc[] =
2254 "int,int _pjsua.buddy_add (_pjsua.Buddy_Config cfg) "
2255 "Add new buddy.";
2256static char pjsua_buddy_del_doc[] =
2257 "int _pjsua.buddy_del (int buddy_id) "
2258 "Delete buddy.";
2259static char pjsua_buddy_subscribe_pres_doc[] =
2260 "int _pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
2261 "Enable/disable buddy's presence monitoring.";
2262static char pjsua_pres_dump_doc[] =
2263 "void _pjsua.pres_dump (int verbose) "
2264 "Dump presence subscriptions to log file.";
2265static char pjsua_im_send_doc[] =
2266 "int _pjsua.im_send (int acc_id, string to, string mime_type, "
2267 "string content, _pjsua.Msg_Data msg_data, int user_data) "
2268 "Send instant messaging outside dialog, using the specified account "
2269 "for route set and authentication.";
2270static char pjsua_im_typing_doc[] =
2271 "int _pjsua.im_typing (int acc_id, string to, int is_typing, "
2272 "_pjsua.Msg_Data msg_data) "
2273 "Send typing indication outside dialog.";
2274
2275/* END OF LIB BUDDY */
2276
2277/* LIB MEDIA */
2278
2279
2280/*
2281 * py_pjsua_conf_get_max_ports
2282 */
2283static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs)
2284{
2285 PJ_UNUSED_ARG(pSelf);
2286 PJ_UNUSED_ARG(pArgs);
2287
2288 return Py_BuildValue("i", pjsua_conf_get_max_ports());
2289}
2290
2291/*
2292 * py_pjsua_conf_get_active_ports
2293 */
2294static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf,
2295 PyObject *pArgs)
2296{
2297 PJ_UNUSED_ARG(pSelf);
2298 PJ_UNUSED_ARG(pArgs);
2299
2300 return Py_BuildValue("i", pjsua_conf_get_active_ports());
2301}
2302
2303/*
2304 * py_pjsua_enum_conf_ports
2305 */
2306static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
2307{
2308 pj_status_t status;
2309 PyObject *list;
2310 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
2311 unsigned c, i;
2312
2313 PJ_UNUSED_ARG(pSelf);
2314 PJ_UNUSED_ARG(pArgs);
2315
2316 c = PJ_ARRAY_SIZE(id);
2317 status = pjsua_enum_conf_ports(id, &c);
2318 if (status != PJ_SUCCESS)
2319 c = 0;
2320
2321 list = PyList_New(c);
2322 for (i = 0; i < c; i++) {
2323 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
2324 }
2325
2326 return (PyObject*)list;
2327}
2328
2329/*
2330 * py_pjsua_conf_get_port_info
2331 */
2332static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs)
2333{
2334 int id;
2335 PyObj_pjsua_conf_port_info *ret;
2336 pjsua_conf_port_info info;
2337 int status;
2338 unsigned i;
2339
2340 PJ_UNUSED_ARG(pSelf);
2341
2342 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2343 return NULL;
2344 }
2345
2346 status = pjsua_conf_get_port_info(id, &info);
2347 ret = (PyObj_pjsua_conf_port_info *)
2348 conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL);
2349 ret->bits_per_sample = info.bits_per_sample;
2350 ret->channel_count = info.channel_count;
2351 ret->clock_rate = info.clock_rate;
2352 ret->name = PyString_FromPJ(&info.name);
2353 ret->samples_per_frame = info.samples_per_frame;
2354 ret->slot_id = info.slot_id;
2355 Py_XDECREF(ret->listeners);
2356 ret->listeners = PyList_New(info.listener_cnt);
2357 for (i = 0; i < info.listener_cnt; i++) {
2358 PyObject *item = Py_BuildValue("i",info.listeners[i]);
2359 PyList_SetItem(ret->listeners, i, item);
2360 }
2361 return (PyObject*)ret;
2362}
2363
2364/*
2365 * py_pjsua_conf_remove_port
2366 */
2367static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs)
2368{
2369 int id;
2370 int status;
2371
2372 PJ_UNUSED_ARG(pSelf);
2373
2374 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2375 return NULL;
2376 }
2377
2378 status = pjsua_conf_remove_port(id);
2379
2380 return Py_BuildValue("i", status);
2381}
2382
2383/*
2384 * py_pjsua_conf_connect
2385 */
2386static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs)
2387{
2388 int source, sink;
2389 int status;
2390
2391 PJ_UNUSED_ARG(pSelf);
2392
2393 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
2394 return NULL;
2395 }
2396
2397 status = pjsua_conf_connect(source, sink);
2398
2399 return Py_BuildValue("i", status);
2400}
2401
2402/*
2403 * py_pjsua_conf_disconnect
2404 */
2405static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs)
2406{
2407 int source, sink;
2408 int status;
2409
2410 PJ_UNUSED_ARG(pSelf);
2411
2412 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
2413 return NULL;
2414 }
2415
2416 status = pjsua_conf_disconnect(source, sink);
2417
2418 return Py_BuildValue("i", status);
2419}
2420
2421/*
2422 * py_pjsua_conf_set_tx_level
2423 */
2424static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs)
2425{
2426 int slot;
2427 float level;
2428 int status;
2429
2430 PJ_UNUSED_ARG(pSelf);
2431
2432 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
2433 return NULL;
2434 }
2435
2436 status = pjsua_conf_adjust_tx_level(slot, level);
2437
2438 return Py_BuildValue("i", status);
2439}
2440
2441/*
2442 * py_pjsua_conf_set_rx_level
2443 */
2444static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs)
2445{
2446 int slot;
2447 float level;
2448 int status;
2449
2450 PJ_UNUSED_ARG(pSelf);
2451
2452 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
2453 return NULL;
2454 }
2455
2456 status = pjsua_conf_adjust_rx_level(slot, level);
2457
2458 return Py_BuildValue("i", status);
2459}
2460
2461/*
2462 * py_pjsua_conf_get_signal_level
2463 */
2464static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf,
2465 PyObject *pArgs)
2466{
2467 int slot;
2468 unsigned tx_level, rx_level;
2469 int status;
2470
2471 PJ_UNUSED_ARG(pSelf);
2472
2473 if (!PyArg_ParseTuple(pArgs, "i", &slot)) {
2474 return NULL;
2475 }
2476
2477 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level);
2478
2479 return Py_BuildValue("iff", status, (float)(tx_level/255.0),
2480 (float)(rx_level/255.0));
2481}
2482
2483/*
2484 * py_pjsua_player_create
2485 */
2486static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs)
2487{
2488 int id;
2489 int options;
2490 PyObject *pFilename;
2491 pj_str_t filename;
2492 int status;
2493
2494 PJ_UNUSED_ARG(pSelf);
2495
2496 if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) {
2497 return NULL;
2498 }
2499
2500 filename = PyString_ToPJ(pFilename);
2501 status = pjsua_player_create(&filename, options, &id);
2502
2503 return Py_BuildValue("ii", status, id);
2504}
2505
2506/*
2507 * py_pjsua_playlist_create
2508 */
2509static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs)
2510{
2511 int id;
2512 int options;
2513 PyObject *pLabel, *pFileList;
2514 pj_str_t label;
2515 int count;
2516 pj_str_t files[64];
2517 int status;
2518
2519 PJ_UNUSED_ARG(pSelf);
2520
2521 if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) {
2522 return NULL;
2523 }
2524
2525 label = PyString_ToPJ(pLabel);
2526 if (!PyList_Check(pFileList))
2527 return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID);
2528
2529 count = 0;
2530 for (count=0; count<PyList_Size(pFileList) &&
2531 count<PJ_ARRAY_SIZE(files); ++count)
2532 {
2533 files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count));
2534 }
2535
2536 status = pjsua_playlist_create(files, count, &label, options, &id);
2537
2538 return Py_BuildValue("ii", status, id);
2539}
2540
2541/*
2542 * py_pjsua_player_get_conf_port
2543 */
2544static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf,
2545 PyObject *pArgs)
2546{
2547
2548 int id, port_id;
2549
2550 PJ_UNUSED_ARG(pSelf);
2551
2552 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2553 return NULL;
2554 }
2555
2556 port_id = pjsua_player_get_conf_port(id);
2557
2558 return Py_BuildValue("i", port_id);
2559}
2560
2561/*
2562 * py_pjsua_player_set_pos
2563 */
2564static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs)
2565{
2566 int id;
2567 int samples;
2568 int status;
2569
2570 PJ_UNUSED_ARG(pSelf);
2571
2572 if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) {
2573 return NULL;
2574 }
2575
2576 if (samples < 0)
2577 samples = 0;
2578
2579 status = pjsua_player_set_pos(id, samples);
2580
2581 return Py_BuildValue("i", status);
2582}
2583
2584/*
2585 * py_pjsua_player_destroy
2586 */
2587static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs)
2588{
2589 int id;
2590 int status;
2591
2592 PJ_UNUSED_ARG(pSelf);
2593
2594 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2595 return NULL;
2596 }
2597
2598 status = pjsua_player_destroy(id);
2599
2600 return Py_BuildValue("i", status);
2601}
2602
2603/*
2604 * py_pjsua_recorder_create
2605 */
2606static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs)
2607{
2608 int id, options;
2609 int max_size;
2610 PyObject *pFilename, *pEncParam;
2611 pj_str_t filename;
2612 int enc_type;
2613
2614 int status;
2615
2616 PJ_UNUSED_ARG(pSelf);
2617
2618 if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam,
2619 &max_size, &options))
2620 {
2621 return NULL;
2622 }
2623
2624 filename = PyString_ToPJ(pFilename);
2625
2626 status = pjsua_recorder_create(&filename, enc_type, NULL, max_size,
2627 options, &id);
2628
2629 return Py_BuildValue("ii", status, id);
2630}
2631
2632/*
2633 * py_pjsua_recorder_get_conf_port
2634 */
2635static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf,
2636 PyObject *pArgs)
2637{
2638
2639 int id, port_id;
2640
2641 PJ_UNUSED_ARG(pSelf);
2642
2643 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2644 return NULL;
2645 }
2646
2647 port_id = pjsua_recorder_get_conf_port(id);
2648
2649 return Py_BuildValue("i", port_id);
2650}
2651
2652/*
2653 * py_pjsua_recorder_destroy
2654 */
2655static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs)
2656{
2657 int id;
2658 int status;
2659
2660 PJ_UNUSED_ARG(pSelf);
2661
2662 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
2663 return NULL;
2664 }
2665
2666 status = pjsua_recorder_destroy(id);
2667
2668 return Py_BuildValue("i", status);
2669}
2670
2671/*
2672 * py_pjsua_enum_snd_devs
2673 */
2674static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
2675{
2676 pj_status_t status;
2677 PyObject *ret;
2678 pjmedia_snd_dev_info info[SND_DEV_NUM];
2679 unsigned c, i;
2680
2681 PJ_UNUSED_ARG(pSelf);
2682 PJ_UNUSED_ARG(pArgs);
2683
2684 c = PJ_ARRAY_SIZE(info);
2685 status = pjsua_enum_snd_devs(info, &c);
2686 if (status != PJ_SUCCESS)
2687 c = 0;
2688
2689 ret = PyList_New(c);
2690 for (i = 0; i < c; i++) {
2691 PyObj_pjmedia_snd_dev_info * obj;
2692
2693 obj = (PyObj_pjmedia_snd_dev_info *)
2694 pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info,
2695 NULL, NULL);
2696 obj->default_samples_per_sec = info[i].default_samples_per_sec;
2697 obj->input_count = info[i].input_count;
2698 obj->output_count = info[i].output_count;
2699 obj->name = PyString_FromString(info[i].name);
2700
2701 PyList_SetItem(ret, i, (PyObject *)obj);
2702 }
2703
2704 return (PyObject*)ret;
2705}
2706
2707/*
2708 * py_pjsua_get_snd_dev
2709 */
2710static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs)
2711{
2712 int capture_dev, playback_dev;
2713 int status;
2714
2715 PJ_UNUSED_ARG(pSelf);
2716 PJ_UNUSED_ARG(pArgs);
2717
2718 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
2719
2720 return Py_BuildValue("ii", capture_dev, playback_dev);
2721}
2722
2723/*
2724 * py_pjsua_set_snd_dev
2725 */
2726static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs)
2727{
2728 int capture_dev, playback_dev;
2729 int status;
2730
2731 PJ_UNUSED_ARG(pSelf);
2732
2733 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) {
2734 return NULL;
2735 }
2736
2737 status = pjsua_set_snd_dev(capture_dev, playback_dev);
2738
2739 return Py_BuildValue("i", status);
2740}
2741
2742/*
2743 * py_pjsua_set_null_snd_dev
2744 */
2745static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs)
2746{
2747 int status;
2748
2749 PJ_UNUSED_ARG(pSelf);
2750 PJ_UNUSED_ARG(pArgs);
2751
2752 status = pjsua_set_null_snd_dev();
2753
2754 return Py_BuildValue("i", status);
2755}
2756
2757/*
2758 * py_pjsua_set_ec
2759 */
2760static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs)
2761{
2762 int options;
2763 int tail_ms;
2764 int status;
2765
2766 PJ_UNUSED_ARG(pSelf);
2767
2768 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) {
2769 return NULL;
2770 }
2771
2772 status = pjsua_set_ec(tail_ms, options);
2773
2774 return Py_BuildValue("i", status);
2775}
2776
2777/*
2778 * py_pjsua_get_ec_tail
2779 */
2780static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs)
2781{
2782 int status;
2783 unsigned tail_ms;
2784
2785 PJ_UNUSED_ARG(pSelf);
2786 PJ_UNUSED_ARG(pArgs);
2787
2788 status = pjsua_get_ec_tail(&tail_ms);
2789 if (status != PJ_SUCCESS)
2790 tail_ms = 0;
2791
2792 return Py_BuildValue("i", tail_ms);
2793}
2794
2795/*
2796 * py_pjsua_enum_codecs
2797 */
2798static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
2799{
2800 pj_status_t status;
2801 PyObject *ret;
2802 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
2803 unsigned c, i;
2804
2805 PJ_UNUSED_ARG(pSelf);
2806 PJ_UNUSED_ARG(pArgs);
2807
2808 c = PJ_ARRAY_SIZE(info);
2809 status = pjsua_enum_codecs(info, &c);
2810 if (status != PJ_SUCCESS)
2811 c = 0;
2812
2813 ret = PyList_New(c);
2814 for (i = 0; i < c; i++) {
2815 PyObj_pjsua_codec_info * obj;
2816 obj = (PyObj_pjsua_codec_info *)
2817 codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL);
2818 obj->codec_id = PyString_FromPJ(&info[i].codec_id);
2819 obj->priority = info[i].priority;
2820
2821 PyList_SetItem(ret, i, (PyObject *)obj);
2822 }
2823
2824 return (PyObject*)ret;
2825}
2826
2827/*
2828 * py_pjsua_codec_set_priority
2829 */
2830static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs)
2831{
2832 int status;
2833 PyObject *pCodecId;
2834 pj_str_t codec_id;
2835 int priority;
2836
2837 PJ_UNUSED_ARG(pSelf);
2838
2839 if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) {
2840 return NULL;
2841 }
2842
2843 codec_id = PyString_ToPJ(pCodecId);
2844 if (priority < 0)
2845 priority = 0;
2846 if (priority > 255)
2847 priority = 255;
2848
2849 status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority);
2850
2851 return Py_BuildValue("i", status);
2852}
2853
2854/*
2855 * py_pjsua_codec_get_param
2856 */
2857static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs)
2858{
2859 int status;
2860 PyObject *pCodecId;
2861 pj_str_t codec_id;
2862 pjmedia_codec_param param;
2863 PyObj_pjmedia_codec_param *ret;
2864
2865 PJ_UNUSED_ARG(pSelf);
2866
2867 if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) {
2868 return NULL;
2869 }
2870
2871 codec_id = PyString_ToPJ(pCodecId);
2872
2873 status = pjsua_codec_get_param(&codec_id, &param);
2874 if (status != PJ_SUCCESS)
2875 return Py_BuildValue("");
2876
2877 ret = (PyObj_pjmedia_codec_param *)
2878 pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL);
2879
2880 ret->info->avg_bps = param.info.avg_bps;
2881 ret->info->channel_cnt = param.info.channel_cnt;
2882 ret->info->clock_rate = param.info.clock_rate;
2883 ret->info->frm_ptime = param.info.frm_ptime;
2884 ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
2885 ret->info->pt = param.info.pt;
2886 ret->setting->cng = param.setting.cng;
2887 //ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
2888 //ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
2889 ret->setting->frm_per_pkt = param.setting.frm_per_pkt;
2890 ret->setting->penh = param.setting.penh;
2891 ret->setting->plc = param.setting.plc;
2892 ret->setting->vad = param.setting.vad;
2893
2894 return (PyObject*)ret;
2895}
2896
2897
2898/*
2899 * py_pjsua_codec_set_param
2900 */
2901static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs)
2902{
2903 int status;
2904 PyObject *pCodecId, *pCodecParam;
2905 pj_str_t codec_id;
2906 pjmedia_codec_param param;
2907
2908 PJ_UNUSED_ARG(pSelf);
2909
2910 if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) {
2911 return NULL;
2912 }
2913
2914 codec_id = PyString_ToPJ(pCodecId);
2915
2916 if (pCodecParam != Py_None) {
2917 PyObj_pjmedia_codec_param *obj;
2918
2919 obj = (PyObj_pjmedia_codec_param *)pCodecParam;
2920
2921 param.info.avg_bps = obj->info->avg_bps;
2922 param.info.channel_cnt = obj->info->channel_cnt;
2923 param.info.clock_rate = obj->info->clock_rate;
2924 param.info.frm_ptime = obj->info->frm_ptime;
2925 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
2926 param.info.pt = obj->info->pt;
2927 param.setting.cng = obj->setting->cng;
2928 //param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
2929 //param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
2930 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
2931 param.setting.penh = obj->setting->penh;
2932 param.setting.plc = obj->setting->plc;
2933 param.setting.vad = obj->setting->vad;
2934 status = pjsua_codec_set_param(&codec_id, &param);
2935
2936 } else {
2937 status = pjsua_codec_set_param(&codec_id, NULL);
2938 }
2939
2940 return Py_BuildValue("i", status);
2941}
2942
2943static char pjsua_conf_get_max_ports_doc[] =
2944 "int _pjsua.conf_get_max_ports () "
2945 "Get maxinum number of conference ports.";
2946static char pjsua_conf_get_active_ports_doc[] =
2947 "int _pjsua.conf_get_active_ports () "
2948 "Get current number of active ports in the bridge.";
2949static char pjsua_enum_conf_ports_doc[] =
2950 "int[] _pjsua.enum_conf_ports () "
2951 "Enumerate all conference ports.";
2952static char pjsua_conf_get_port_info_doc[] =
2953 "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) "
2954 "Get information about the specified conference port";
2955static char pjsua_conf_remove_port_doc[] =
2956 "int _pjsua.conf_remove_port (int id) "
2957 "Remove arbitrary slot from the conference bridge. "
2958 "Application should only call this function "
2959 "if it registered the port manually.";
2960static char pjsua_conf_connect_doc[] =
2961 "int _pjsua.conf_connect (int source, int sink) "
2962 "Establish unidirectional media flow from souce to sink. "
2963 "One source may transmit to multiple destinations/sink. "
2964 "And if multiple sources are transmitting to the same sink, "
2965 "the media will be mixed together. Source and sink may refer "
2966 "to the same ID, effectively looping the media. "
2967 "If bidirectional media flow is desired, application "
2968 "needs to call this function twice, with the second "
2969 "one having the arguments reversed.";
2970static char pjsua_conf_disconnect_doc[] =
2971 "int _pjsua.conf_disconnect (int source, int sink) "
2972 "Disconnect media flow from the source to destination port.";
2973static char pjsua_player_create_doc[] =
2974 "int, int _pjsua.player_create (string filename, int options) "
2975 "Create a file player, and automatically connect "
2976 "this player to the conference bridge.";
2977static char pjsua_player_get_conf_port_doc[] =
2978 "int _pjsua.player_get_conf_port (int) "
2979 "Get conference port ID associated with player.";
2980static char pjsua_player_set_pos_doc[] =
2981 "int _pjsua.player_set_pos (int id, int samples) "
2982 "Set playback position.";
2983static char pjsua_player_destroy_doc[] =
2984 "int _pjsua.player_destroy (int id) "
2985 "Close the file, remove the player from the bridge, "
2986 "and free resources associated with the file player.";
2987static char pjsua_recorder_create_doc[] =
2988 "int, int _pjsua.recorder_create (string filename, "
2989 "int enc_type, int enc_param, int max_size, int options) "
2990 "Create a file recorder, and automatically connect this recorder "
2991 "to the conference bridge. The recorder currently supports recording "
2992 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
2993 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
2994static char pjsua_recorder_get_conf_port_doc[] =
2995 "int _pjsua.recorder_get_conf_port (int id) "
2996 "Get conference port associated with recorder.";
2997static char pjsua_recorder_destroy_doc[] =
2998 "int _pjsua.recorder_destroy (int id) "
2999 "Destroy recorder (this will complete recording).";
3000static char pjsua_enum_snd_devs_doc[] =
3001 "_pjsua.PJMedia_Snd_Dev_Info[] _pjsua.enum_snd_devs (int count) "
3002 "Enum sound devices.";
3003static char pjsua_get_snd_dev_doc[] =
3004 "int, int _pjsua.get_snd_dev () "
3005 "Get currently active sound devices. "
3006 "If sound devices has not been created "
3007 "(for example when pjsua_start() is not called), "
3008 "it is possible that the function returns "
3009 "PJ_SUCCESS with -1 as device IDs.";
3010static char pjsua_set_snd_dev_doc[] =
3011 "int _pjsua.set_snd_dev (int capture_dev, int playback_dev) "
3012 "Select or change sound device. Application may call this function "
3013 "at any time to replace current sound device.";
3014static char pjsua_set_null_snd_dev_doc[] =
3015 "int _pjsua.set_null_snd_dev () "
3016 "Set pjsua to use null sound device. The null sound device only "
3017 "provides the timing needed by the conference bridge, and will not "
3018 "interract with any hardware.";
3019static char pjsua_set_ec_doc[] =
3020 "int _pjsua.set_ec (int tail_ms, int options) "
3021 "Configure the echo canceller tail length of the sound port.";
3022static char pjsua_get_ec_tail_doc[] =
3023 "int _pjsua.get_ec_tail () "
3024 "Get current echo canceller tail length.";
3025static char pjsua_enum_codecs_doc[] =
3026 "_pjsua.Codec_Info[] _pjsua.enum_codecs () "
3027 "Enum all supported codecs in the system.";
3028static char pjsua_codec_set_priority_doc[] =
3029 "int _pjsua.codec_set_priority (string id, int priority) "
3030 "Change codec priority.";
3031static char pjsua_codec_get_param_doc[] =
3032 "_pjsua.PJMedia_Codec_Param _pjsua.codec_get_param (string id) "
3033 "Get codec parameters";
3034static char pjsua_codec_set_param_doc[] =
3035 "int _pjsua.codec_set_param (string id, "
3036 "_pjsua.PJMedia_Codec_Param param) "
3037 "Set codec parameters.";
3038
3039/* END OF LIB MEDIA */
3040
3041/* LIB CALL */
3042
3043/*
3044 * py_pjsua_call_get_max_count
3045 */
3046static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs)
3047{
3048 int count;
3049
3050 PJ_UNUSED_ARG(pSelf);
3051 PJ_UNUSED_ARG(pArgs);
3052
3053 count = pjsua_call_get_max_count();
3054
3055 return Py_BuildValue("i", count);
3056}
3057
3058/*
3059 * py_pjsua_call_get_count
3060 */
3061static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs)
3062{
3063 int count;
3064
3065 PJ_UNUSED_ARG(pSelf);
3066 PJ_UNUSED_ARG(pArgs);
3067
3068 count = pjsua_call_get_count();
3069
3070 return Py_BuildValue("i", count);
3071}
3072
3073/*
3074 * py_pjsua_enum_calls
3075 */
3076static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
3077{
3078 pj_status_t status;
3079 PyObject *ret;
3080 pjsua_transport_id id[PJSUA_MAX_CALLS];
3081 unsigned c, i;
3082
3083 PJ_UNUSED_ARG(pSelf);
3084 PJ_UNUSED_ARG(pArgs);
3085
3086 c = PJ_ARRAY_SIZE(id);
3087 status = pjsua_enum_calls(id, &c);
3088 if (status != PJ_SUCCESS)
3089 c = 0;
3090
3091 ret = PyList_New(c);
3092 for (i = 0; i < c; i++) {
3093 PyList_SetItem(ret, i, Py_BuildValue("i", id[i]));
3094 }
3095
3096 return (PyObject*)ret;
3097}
3098
3099/*
3100 * py_pjsua_call_make_call
3101 */
3102static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs)
3103{
3104 int status;
3105 int acc_id;
3106 pj_str_t dst_uri;
3107 PyObject *pDstUri, *pMsgData, *pUserData;
3108 pjsua_call_setting option;
3109 pjsua_msg_data msg_data;
3110 int call_id;
3111 pj_pool_t *pool = NULL;
3112
3113 PJ_UNUSED_ARG(pSelf);
3114
3115 pjsua_call_setting_default(&option);
3116 if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &option.flag,
3117 &pUserData, &pMsgData))
3118 {
3119 return NULL;
3120 }
3121
3122 dst_uri = PyString_ToPJ(pDstUri);
3123 pjsua_msg_data_init(&msg_data);
3124
3125 if (pMsgData != Py_None) {
3126 PyObj_pjsua_msg_data * omd;
3127
3128 omd = (PyObj_pjsua_msg_data *)pMsgData;
3129
3130 msg_data.content_type = PyString_ToPJ(omd->content_type);
3131 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3132 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3133 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3134 }
3135
3136 Py_XINCREF(pUserData);
3137
3138 status = pjsua_call_make_call(acc_id, &dst_uri,
3139 &option, (void*)pUserData,
3140 &msg_data, &call_id);
3141 if (pool != NULL)
3142 pj_pool_release(pool);
3143
3144 if (status != PJ_SUCCESS) {
3145 Py_XDECREF(pUserData);
3146 }
3147
3148 return Py_BuildValue("ii", status, call_id);
3149}
3150
3151/*
3152 * py_pjsua_call_is_active
3153 */
3154static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs)
3155{
3156 int call_id;
3157 int is_active;
3158
3159 PJ_UNUSED_ARG(pSelf);
3160
3161 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3162 return NULL;
3163 }
3164
3165 is_active = pjsua_call_is_active(call_id);
3166
3167 return Py_BuildValue("i", is_active);
3168}
3169
3170/*
3171 * py_pjsua_call_has_media
3172 */
3173static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs)
3174{
3175 int call_id;
3176 int has_media;
3177
3178 PJ_UNUSED_ARG(pSelf);
3179
3180 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3181 return NULL;
3182 }
3183
3184 has_media = pjsua_call_has_media(call_id);
3185
3186 return Py_BuildValue("i", has_media);
3187}
3188
3189/*
3190 * py_pjsua_call_get_conf_port
3191 */
3192static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs)
3193{
3194 int call_id;
3195 int port_id;
3196
3197 PJ_UNUSED_ARG(pSelf);
3198
3199 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3200 return NULL;
3201 }
3202
3203 port_id = pjsua_call_get_conf_port(call_id);
3204
3205 return Py_BuildValue("i", port_id);
3206}
3207
3208/*
3209 * py_pjsua_call_get_info
3210 */
3211static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs)
3212{
3213 int call_id;
3214 int status;
3215 PyObj_pjsua_call_info *ret;
3216 pjsua_call_info info;
3217
3218 PJ_UNUSED_ARG(pSelf);
3219
3220 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3221 return NULL;
3222 }
3223
3224 status = pjsua_call_get_info(call_id, &info);
3225 if (status != PJ_SUCCESS)
3226 return Py_BuildValue("");
3227
3228 ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info,
3229 NULL, NULL);
3230 ret->acc_id = info.acc_id;
3231 Py_XDECREF(ret->call_id);
3232 ret->call_id = PyString_FromPJ(&info.call_id);
3233 ret->conf_slot = info.conf_slot;
3234 ret->connect_duration = info.connect_duration.sec * 1000 +
3235 info.connect_duration.msec;
3236 ret->total_duration = info.total_duration.sec * 1000 +
3237 info.total_duration.msec;
3238 ret->id = info.id;
3239 ret->last_status = info.last_status;
3240 Py_XDECREF(ret->last_status_text);
3241 ret->last_status_text = PyString_FromPJ(&info.last_status_text);
3242 Py_XDECREF(ret->local_contact);
3243 ret->local_contact = PyString_FromPJ(&info.local_contact);
3244 Py_XDECREF(ret->local_info);
3245 ret->local_info = PyString_FromPJ(&info.local_info);
3246 Py_XDECREF(ret->remote_contact);
3247 ret->remote_contact = PyString_FromPJ(&info.remote_contact);
3248 Py_XDECREF(ret->remote_info);
3249 ret->remote_info = PyString_FromPJ(&info.remote_info);
3250 ret->media_dir = info.media_dir;
3251 ret->media_status = info.media_status;
3252 ret->role = info.role;
3253 ret->state = info.state;
3254 Py_XDECREF(ret->state_text);
3255 ret->state_text = PyString_FromPJ(&info.state_text);
3256
3257 return (PyObject*)ret;
3258}
3259
3260/*
3261 * py_pjsua_call_set_user_data
3262 */
3263static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs)
3264{
3265 int call_id;
3266 PyObject *pUserData, *old_user_data;
3267 int status;
3268
3269 PJ_UNUSED_ARG(pSelf);
3270
3271 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) {
3272 return NULL;
3273 }
3274
3275 old_user_data = (PyObject*) pjsua_call_get_user_data(call_id);
3276
3277 if (old_user_data == pUserData) {
3278 return Py_BuildValue("i", PJ_SUCCESS);
3279 }
3280
3281 Py_XINCREF(pUserData);
3282 Py_XDECREF(old_user_data);
3283
3284 status = pjsua_call_set_user_data(call_id, (void*)pUserData);
3285
3286 if (status != PJ_SUCCESS) {
3287 Py_XDECREF(pUserData);
3288 }
3289
3290 return Py_BuildValue("i", status);
3291}
3292
3293/*
3294 * py_pjsua_call_get_user_data
3295 */
3296static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs)
3297{
3298 int call_id;
3299 PyObject *user_data;
3300
3301 PJ_UNUSED_ARG(pSelf);
3302
3303 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
3304 return NULL;
3305 }
3306
3307 user_data = (PyObject*)pjsua_call_get_user_data(call_id);
3308 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
3309}
3310
3311/*
3312 * py_pjsua_call_answer
3313 */
3314static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs)
3315{
3316 int status;
3317 int call_id;
3318 pj_str_t * reason, tmp_reason;
3319 PyObject *pReason;
3320 unsigned code;
3321 pjsua_msg_data msg_data;
3322 PyObject * omdObj;
3323 pj_pool_t * pool = NULL;
3324
3325 PJ_UNUSED_ARG(pSelf);
3326
3327 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) {
3328 return NULL;
3329 }
3330
3331 if (pReason == Py_None) {
3332 reason = NULL;
3333 } else {
3334 reason = &tmp_reason;
3335 tmp_reason = PyString_ToPJ(pReason);
3336 }
3337
3338 pjsua_msg_data_init(&msg_data);
3339 if (omdObj != Py_None) {
3340 PyObj_pjsua_msg_data *omd;
3341
3342 omd = (PyObj_pjsua_msg_data *)omdObj;
3343 msg_data.content_type = PyString_ToPJ(omd->content_type);
3344 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3345 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3346 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3347 }
3348
3349 status = pjsua_call_answer(call_id, code, reason, &msg_data);
3350
3351 if (pool)
3352 pj_pool_release(pool);
3353
3354 return Py_BuildValue("i", status);
3355}
3356
3357/*
3358 * py_pjsua_call_hangup
3359 */
3360static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs)
3361{
3362 int status;
3363 int call_id;
3364 pj_str_t *reason, tmp_reason;
3365 PyObject *pReason;
3366 unsigned code;
3367 pjsua_msg_data msg_data;
3368 PyObject *omdObj;
3369 pj_pool_t *pool = NULL;
3370
3371 PJ_UNUSED_ARG(pSelf);
3372
3373 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason,
3374 &omdObj))
3375 {
3376 return NULL;
3377 }
3378
3379 if (pReason == Py_None) {
3380 reason = NULL;
3381 } else {
3382 reason = &tmp_reason;
3383 tmp_reason = PyString_ToPJ(pReason);
3384 }
3385
3386 pjsua_msg_data_init(&msg_data);
3387 if (omdObj != Py_None) {
3388 PyObj_pjsua_msg_data *omd;
3389
3390 omd = (PyObj_pjsua_msg_data *)omdObj;
3391 msg_data.content_type = PyString_ToPJ(omd->content_type);
3392 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3393 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3394 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3395 }
3396
3397 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
3398 if (pool)
3399 pj_pool_release(pool);
3400
3401 return Py_BuildValue("i", status);
3402}
3403
3404/*
3405 * py_pjsua_call_set_hold
3406 */
3407static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs)
3408{
3409 int status;
3410 int call_id;
3411 pjsua_msg_data msg_data;
3412 PyObject *omdObj;
3413 pj_pool_t *pool = NULL;
3414
3415 PJ_UNUSED_ARG(pSelf);
3416
3417 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) {
3418 return NULL;
3419 }
3420
3421 pjsua_msg_data_init(&msg_data);
3422 if (omdObj != Py_None) {
3423 PyObj_pjsua_msg_data *omd;
3424
3425 omd = (PyObj_pjsua_msg_data *)omdObj;
3426 msg_data.content_type = PyString_ToPJ(omd->content_type);
3427 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3428 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3429 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3430 }
3431
3432 status = pjsua_call_set_hold(call_id, &msg_data);
3433
3434 if (pool)
3435 pj_pool_release(pool);
3436
3437 return Py_BuildValue("i",status);
3438}
3439
3440/*
3441 * py_pjsua_call_reinvite
3442 */
3443static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs)
3444{
3445 int status;
3446 int call_id;
3447 int unhold;
3448 pjsua_msg_data msg_data;
3449 PyObject *omdObj;
3450 pj_pool_t *pool = NULL;
3451
3452 PJ_UNUSED_ARG(pSelf);
3453
3454 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) {
3455 return NULL;
3456 }
3457
3458 pjsua_msg_data_init(&msg_data);
3459 if (omdObj != Py_None) {
3460 PyObj_pjsua_msg_data *omd;
3461
3462 omd = (PyObj_pjsua_msg_data *)omdObj;
3463 msg_data.content_type = PyString_ToPJ(omd->content_type);
3464 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3465 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3466 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3467 }
3468
3469 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
3470
3471 if (pool)
3472 pj_pool_release(pool);
3473
3474 return Py_BuildValue("i", status);
3475}
3476
3477/*
3478 * py_pjsua_call_update
3479 */
3480static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs)
3481{
3482 int status;
3483 int call_id;
3484 int option;
3485 pjsua_msg_data msg_data;
3486 PyObject *omdObj;
3487 pj_pool_t *pool = NULL;
3488
3489 PJ_UNUSED_ARG(pSelf);
3490
3491 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) {
3492 return NULL;
3493 }
3494
3495 pjsua_msg_data_init(&msg_data);
3496 if (omdObj != Py_None) {
3497 PyObj_pjsua_msg_data *omd;
3498
3499 omd = (PyObj_pjsua_msg_data *)omdObj;
3500 msg_data.content_type = PyString_ToPJ(omd->content_type);
3501 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3502 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3503 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3504 }
3505
3506 status = pjsua_call_update(call_id, option, &msg_data);
3507
3508 if (pool)
3509 pj_pool_release(pool);
3510
3511 return Py_BuildValue("i", status);
3512}
3513
3514/*
3515 * py_pjsua_call_send_request
3516 */
3517static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs)
3518{
3519 int status;
3520 int call_id;
3521 PyObject *pMethod;
3522 pj_str_t method;
3523 pjsua_msg_data msg_data;
3524 PyObject *omdObj;
3525 pj_pool_t *pool = NULL;
3526
3527 PJ_UNUSED_ARG(pSelf);
3528
3529 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) {
3530 return NULL;
3531 }
3532
3533 if (!PyString_Check(pMethod)) {
3534 return NULL;
3535 }
3536
3537 method = PyString_ToPJ(pMethod);
3538 pjsua_msg_data_init(&msg_data);
3539
3540 if (omdObj != Py_None) {
3541 PyObj_pjsua_msg_data *omd;
3542
3543 omd = (PyObj_pjsua_msg_data *)omdObj;
3544 msg_data.content_type = PyString_ToPJ(omd->content_type);
3545 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3546 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3547 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3548 }
3549
3550 status = pjsua_call_send_request(call_id, &method, &msg_data);
3551
3552 if (pool)
3553 pj_pool_release(pool);
3554
3555 return Py_BuildValue("i", status);
3556}
3557
3558/*
3559 * py_pjsua_call_xfer
3560 */
3561static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs)
3562{
3563 int status;
3564 int call_id;
3565 pj_str_t dest;
3566 PyObject *pDstUri;
3567 pjsua_msg_data msg_data;
3568 PyObject *omdObj;
3569 pj_pool_t *pool = NULL;
3570
3571 PJ_UNUSED_ARG(pSelf);
3572
3573 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) {
3574 return NULL;
3575 }
3576
3577 if (!PyString_Check(pDstUri))
3578 return NULL;
3579
3580 dest = PyString_ToPJ(pDstUri);
3581 pjsua_msg_data_init(&msg_data);
3582
3583 if (omdObj != Py_None) {
3584 PyObj_pjsua_msg_data *omd;
3585
3586 omd = (PyObj_pjsua_msg_data *)omdObj;
3587 msg_data.content_type = PyString_ToPJ(omd->content_type);
3588 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3589 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3590 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3591 }
3592
3593 status = pjsua_call_xfer(call_id, &dest, &msg_data);
3594
3595 if (pool)
3596 pj_pool_release(pool);
3597
3598 return Py_BuildValue("i", status);
3599}
3600
3601/*
3602 * py_pjsua_call_xfer_replaces
3603 */
3604static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs)
3605{
3606 int status;
3607 int call_id;
3608 int dest_call_id;
3609 unsigned options;
3610 pjsua_msg_data msg_data;
3611 PyObject *omdObj;
3612 pj_pool_t *pool = NULL;
3613
3614 PJ_UNUSED_ARG(pSelf);
3615
3616 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id,
3617 &options, &omdObj))
3618 {
3619 return NULL;
3620 }
3621
3622 pjsua_msg_data_init(&msg_data);
3623
3624 if (omdObj != Py_None) {
3625 PyObj_pjsua_msg_data *omd;
3626
3627 omd = (PyObj_pjsua_msg_data *)omdObj;
3628 msg_data.content_type = PyString_ToPJ(omd->content_type);
3629 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3630 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3631 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3632 }
3633
3634 status = pjsua_call_xfer_replaces(call_id, dest_call_id, options,
3635 &msg_data);
3636
3637 if (pool)
3638 pj_pool_release(pool);
3639
3640 return Py_BuildValue("i", status);
3641}
3642
3643/*
3644 * py_pjsua_call_dial_dtmf
3645 */
3646static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs)
3647{
3648 int call_id;
3649 PyObject *pDigits;
3650 pj_str_t digits;
3651 int status;
3652
3653 PJ_UNUSED_ARG(pSelf);
3654
3655 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) {
3656 return NULL;
3657 }
3658
3659 if (!PyString_Check(pDigits))
3660 return Py_BuildValue("i", PJ_EINVAL);
3661
3662 digits = PyString_ToPJ(pDigits);
3663 status = pjsua_call_dial_dtmf(call_id, &digits);
3664
3665 return Py_BuildValue("i", status);
3666}
3667
3668/*
3669 * py_pjsua_call_send_im
3670 */
3671static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs)
3672{
3673 int status;
3674 int call_id;
3675 pj_str_t content;
3676 pj_str_t * mime_type, tmp_mime_type;
3677 PyObject *pMimeType, *pContent, *omdObj;
3678 pjsua_msg_data msg_data;
3679 int user_data;
3680 pj_pool_t *pool = NULL;
3681
3682 PJ_UNUSED_ARG(pSelf);
3683
3684 if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent,
3685 &omdObj, &user_data))
3686 {
3687 return NULL;
3688 }
3689
3690 if (!PyString_Check(pContent))
3691 return Py_BuildValue("i", PJ_EINVAL);
3692
3693 content = PyString_ToPJ(pContent);
3694
3695 if (PyString_Check(pMimeType)) {
3696 mime_type = &tmp_mime_type;
3697 tmp_mime_type = PyString_ToPJ(pMimeType);
3698 } else {
3699 mime_type = NULL;
3700 }
3701
3702 pjsua_msg_data_init(&msg_data);
3703 if (omdObj != Py_None) {
3704 PyObj_pjsua_msg_data * omd;
3705
3706 omd = (PyObj_pjsua_msg_data *)omdObj;
3707 msg_data.content_type = PyString_ToPJ(omd->content_type);
3708 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3709 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3710 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3711 }
3712
3713 status = pjsua_call_send_im(call_id, mime_type, &content,
3714 &msg_data, (void*)(long)user_data);
3715
3716 if (pool)
3717 pj_pool_release(pool);
3718
3719 return Py_BuildValue("i", status);
3720}
3721
3722/*
3723 * py_pjsua_call_send_typing_ind
3724 */
3725static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf,
3726 PyObject *pArgs)
3727{
3728 int status;
3729 int call_id;
3730 int is_typing;
3731 pjsua_msg_data msg_data;
3732 PyObject *omdObj;
3733 pj_pool_t *pool = NULL;
3734
3735 PJ_UNUSED_ARG(pSelf);
3736
3737 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) {
3738 return NULL;
3739 }
3740
3741 pjsua_msg_data_init(&msg_data);
3742 if (omdObj != Py_None) {
3743 PyObj_pjsua_msg_data *omd;
3744
3745 omd = (PyObj_pjsua_msg_data *)omdObj;
3746 msg_data.content_type = PyString_ToPJ(omd->content_type);
3747 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3748 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3749 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
3750 }
3751
3752 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
3753
3754 if (pool)
3755 pj_pool_release(pool);
3756
3757 return Py_BuildValue("i", status);
3758}
3759
3760/*
3761 * py_pjsua_call_hangup_all
3762 */
3763static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs)
3764{
3765 PJ_UNUSED_ARG(pSelf);
3766 PJ_UNUSED_ARG(pArgs);
3767
3768 pjsua_call_hangup_all();
3769
3770 return Py_BuildValue("");
3771}
3772
3773/*
3774 * py_pjsua_call_dump
3775 */
3776static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs)
3777{
3778 int call_id;
3779 int with_media;
3780 PyObject *ret;
3781 PyObject *pIndent;
3782 char *buffer;
3783 char *indent;
3784 unsigned maxlen;
3785 int status;
3786
3787 PJ_UNUSED_ARG(pSelf);
3788
3789 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media,
3790 &maxlen, &pIndent))
3791 {
3792 return NULL;
3793 }
3794
3795 buffer = (char*) malloc(maxlen * sizeof(char));
3796 indent = PyString_AsString(pIndent);
3797
3798 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
3799 if (status != PJ_SUCCESS) {
3800 free(buffer);
3801 return PyString_FromString("");
3802 }
3803
3804 ret = PyString_FromString(buffer);
3805 free(buffer);
3806 return (PyObject*)ret;
3807}
3808
3809
3810/*
3811 * py_pjsua_dump
3812 * Dump application states.
3813 */
3814static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
3815{
3816 int detail;
3817
3818 PJ_UNUSED_ARG(pSelf);
3819
3820 if (!PyArg_ParseTuple(pArgs, "i", &detail)) {
3821 return NULL;
3822 }
3823
3824 pjsua_dump(detail);
3825
3826 return Py_BuildValue("");
3827}
3828
3829
3830/*
3831 * py_pj_strerror
3832 */
3833static PyObject *py_pj_strerror(PyObject *pSelf, PyObject *pArgs)
3834{
3835 int err;
3836 char err_msg[PJ_ERR_MSG_SIZE];
3837 pj_str_t ret;
3838
3839 PJ_UNUSED_ARG(pSelf);
3840
3841 if (!PyArg_ParseTuple(pArgs, "i", &err)) {
3842 return NULL;
3843 }
3844
3845 ret = pj_strerror(err, err_msg, sizeof(err_msg));
3846
3847 return PyString_FromStringAndSize(err_msg, ret.slen);
3848}
3849
3850
3851/*
3852 * py_pj_parse_simple_sip
3853 */
3854static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs)
3855{
3856 const char *arg_uri;
3857 pj_pool_t *pool;
3858 char tmp[PJSIP_MAX_URL_SIZE];
3859 pjsip_uri *uri;
3860 pjsip_sip_uri *sip_uri;
3861 PyObject *ret, *item;
3862
3863 PJ_UNUSED_ARG(pSelf);
3864
3865 if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) {
3866 return NULL;
3867 }
3868
3869 strncpy(tmp, arg_uri, sizeof(tmp));
3870 tmp[sizeof(tmp)-1] = '\0';
3871
3872 pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512);
3873 uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0);
3874
3875 if (uri == NULL || (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
3876 !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
3877 pj_pool_release(pool);
3878 return Py_BuildValue("");
3879 }
3880
3881 ret = PyTuple_New(5);
3882 sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri);
3883
3884 /* Scheme */
3885 item = PyString_FromPJ(pjsip_uri_get_scheme(uri));
3886 PyTuple_SetItem(ret, 0, item);
3887
3888 /* Username */
3889 item = PyString_FromPJ(&sip_uri->user);
3890 PyTuple_SetItem(ret, 1, item);
3891
3892 /* Host */
3893 item = PyString_FromPJ(&sip_uri->host);
3894 PyTuple_SetItem(ret, 2, item);
3895
3896 /* Port */
3897 if (sip_uri->port == 5060) {
3898 sip_uri->port = 0;
3899 }
3900 item = Py_BuildValue("i", sip_uri->port);
3901 PyTuple_SetItem(ret, 3, item);
3902
3903 /* Transport */
3904 if (pj_stricmp2(&sip_uri->transport_param, "udp")) {
3905 sip_uri->transport_param.ptr = "";
3906 sip_uri->transport_param.slen = 0;
3907 }
3908 item = PyString_FromPJ(&sip_uri->transport_param);
3909 PyTuple_SetItem(ret, 4, item);
3910
3911 pj_pool_release(pool);
3912 return ret;
3913}
3914
3915
3916static char pjsua_call_get_max_count_doc[] =
3917 "int _pjsua.call_get_max_count () "
3918 "Get maximum number of calls configured in pjsua.";
3919static char pjsua_call_get_count_doc[] =
3920 "int _pjsua.call_get_count () "
3921 "Get number of currently active calls.";
3922static char pjsua_enum_calls_doc[] =
3923 "int[] _pjsua.enum_calls () "
3924 "Get maximum number of calls configured in pjsua.";
3925static char pjsua_call_make_call_doc[] =
3926 "int,int _pjsua.call_make_call (int acc_id, string dst_uri, int options,"
3927 "int user_data, _pjsua.Msg_Data msg_data) "
3928 "Make outgoing call to the specified URI using the specified account.";
3929static char pjsua_call_is_active_doc[] =
3930 "int _pjsua.call_is_active (int call_id) "
3931 "Check if the specified call has active INVITE session and the INVITE "
3932 "session has not been disconnected.";
3933static char pjsua_call_has_media_doc[] =
3934 "int _pjsua.call_has_media (int call_id) "
3935 "Check if call has an active media session.";
3936static char pjsua_call_get_conf_port_doc[] =
3937 "int _pjsua.call_get_conf_port (int call_id) "
3938 "Get the conference port identification associated with the call.";
3939static char pjsua_call_get_info_doc[] =
3940 "_pjsua.Call_Info _pjsua.call_get_info (int call_id) "
3941 "Obtain detail information about the specified call.";
3942static char pjsua_call_set_user_data_doc[] =
3943 "int _pjsua.call_set_user_data (int call_id, int user_data) "
3944 "Attach application specific data to the call.";
3945static char pjsua_call_get_user_data_doc[] =
3946 "int _pjsua.call_get_user_data (int call_id) "
3947 "Get user data attached to the call.";
3948static char pjsua_call_answer_doc[] =
3949 "int _pjsua.call_answer (int call_id, int code, string reason, "
3950 "_pjsua.Msg_Data msg_data) "
3951 "Send response to incoming INVITE request.";
3952static char pjsua_call_hangup_doc[] =
3953 "int _pjsua.call_hangup (int call_id, int code, string reason, "
3954 "_pjsua.Msg_Data msg_data) "
3955 "Hangup call by using method that is appropriate according "
3956 "to the call state.";
3957static char pjsua_call_set_hold_doc[] =
3958 "int _pjsua.call_set_hold (int call_id, _pjsua.Msg_Data msg_data) "
3959 "Put the specified call on hold.";
3960static char pjsua_call_reinvite_doc[] =
3961 "int _pjsua.call_reinvite (int call_id, int unhold, "
3962 "_pjsua.Msg_Data msg_data) "
3963 "Send re-INVITE (to release hold).";
3964static char pjsua_call_xfer_doc[] =
3965 "int _pjsua.call_xfer (int call_id, string dest, "
3966 "_pjsua.Msg_Data msg_data) "
3967 "Initiate call transfer to the specified address. "
3968 "This function will send REFER request to instruct remote call party "
3969 "to initiate a new INVITE session to the specified destination/target.";
3970static char pjsua_call_xfer_replaces_doc[] =
3971 "int _pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
3972 "int options, _pjsua.Msg_Data msg_data) "
3973 "Initiate attended call transfer. This function will send REFER request "
3974 "to instruct remote call party to initiate new INVITE session to the URL "
3975 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
3976 "with us with the new call from the REFER recipient.";
3977static char pjsua_call_dial_dtmf_doc[] =
3978 "int _pjsua.call_dial_dtmf (int call_id, string digits) "
3979 "Send DTMF digits to remote using RFC 2833 payload formats.";
3980static char pjsua_call_send_im_doc[] =
3981 "int _pjsua.call_send_im (int call_id, string mime_type, string content,"
3982 "_pjsua.Msg_Data msg_data, int user_data) "
3983 "Send instant messaging inside INVITE session.";
3984static char pjsua_call_send_typing_ind_doc[] =
3985 "int _pjsua.call_send_typing_ind (int call_id, int is_typing, "
3986 "_pjsua.Msg_Data msg_data) "
3987 "Send IM typing indication inside INVITE session.";
3988static char pjsua_call_hangup_all_doc[] =
3989 "void _pjsua.call_hangup_all () "
3990 "Terminate all calls.";
3991static char pjsua_call_dump_doc[] =
3992 "int _pjsua.call_dump (int call_id, int with_media, int maxlen, "
3993 "string indent) "
3994 "Dump call and media statistics to string.";
3995
3996/* END OF LIB CALL */
3997
3998/*
3999 * Map of function names to functions
4000 */
4001static PyMethodDef py_pjsua_methods[] =
4002{
4003 {
4004 "thread_register", py_pjsua_thread_register, METH_VARARGS,
4005 pjsua_thread_register_doc
4006 },
4007 {
4008 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
4009 },
4010 {
4011 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
4012 },
4013 {
4014 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
4015 },
4016 {
4017 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
4018 },
4019 {
4020 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
4021 },
4022 {
4023 "handle_events", py_pjsua_handle_events, METH_VARARGS,
4024 pjsua_handle_events_doc
4025 },
4026 {
4027 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
4028 pjsua_verify_sip_url_doc
4029 },
4030 {
4031 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
4032 pjsua_reconfigure_logging_doc
4033 },
4034 {
4035 "logging_config_default", py_pjsua_logging_config_default,
4036 METH_VARARGS, pjsua_logging_config_default_doc
4037 },
4038 {
4039 "config_default", py_pjsua_config_default, METH_VARARGS,
4040 pjsua_config_default_doc
4041 },
4042 {
4043 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
4044 pjsua_media_config_default_doc
4045 },
4046
4047
4048 {
4049 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
4050 pjsua_msg_data_init_doc
4051 },
4052 {
4053 "transport_config_default", py_pjsua_transport_config_default,
4054 METH_VARARGS,pjsua_transport_config_default_doc
4055 },
4056 {
4057 "transport_create", py_pjsua_transport_create, METH_VARARGS,
4058 pjsua_transport_create_doc
4059 },
4060 {
4061 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
4062 pjsua_enum_transports_doc
4063 },
4064 {
4065 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
4066 pjsua_transport_get_info_doc
4067 },
4068 {
4069 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
4070 pjsua_transport_set_enable_doc
4071 },
4072 {
4073 "transport_close", py_pjsua_transport_close, METH_VARARGS,
4074 pjsua_transport_close_doc
4075 },
4076 {
4077 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
4078 pjsua_acc_config_default_doc
4079 },
4080 {
4081 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
4082 pjsua_acc_get_count_doc
4083 },
4084 {
4085 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
4086 pjsua_acc_is_valid_doc
4087 },
4088 {
4089 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
4090 pjsua_acc_set_default_doc
4091 },
4092 {
4093 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
4094 pjsua_acc_get_default_doc
4095 },
4096 {
4097 "acc_add", py_pjsua_acc_add, METH_VARARGS,
4098 pjsua_acc_add_doc
4099 },
4100 {
4101 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
4102 pjsua_acc_add_local_doc
4103 },
4104 {
4105 "acc_del", py_pjsua_acc_del, METH_VARARGS,
4106 pjsua_acc_del_doc
4107 },
4108 {
4109 "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS,
4110 "Accociate user data with the account"
4111 },
4112 {
4113 "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS,
4114 "Get account's user data"
4115 },
4116 {
4117 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
4118 pjsua_acc_modify_doc
4119 },
4120 {
4121 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
4122 pjsua_acc_set_online_status_doc
4123 },
4124 {
4125 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
4126 pjsua_acc_set_online_status2_doc
4127 },
4128 {
4129 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
4130 pjsua_acc_set_registration_doc
4131 },
4132 {
4133 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
4134 pjsua_acc_get_info_doc
4135 },
4136 {
4137 "acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS,
4138 "Accept or reject subscription request"
4139 },
4140 {
4141 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
4142 pjsua_enum_accs_doc
4143 },
4144 {
4145 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
4146 pjsua_acc_enum_info_doc
4147 },
4148 {
4149 "acc_set_transport", py_pjsua_acc_set_transport, METH_VARARGS,
4150 "Lock transport to use the specified transport"
4151 },
4152 {
4153 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
4154 pjsua_buddy_config_default_doc
4155 },
4156 {
4157 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
4158 pjsua_get_buddy_count_doc
4159 },
4160 {
4161 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
4162 pjsua_buddy_is_valid_doc
4163 },
4164 {
4165 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
4166 pjsua_enum_buddies_doc
4167 },
4168 {
4169 "buddy_find", py_pjsua_buddy_find, METH_VARARGS,
4170 "Find buddy with the specified URI"
4171 },
4172 {
4173 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
4174 pjsua_buddy_get_info_doc
4175 },
4176 {
4177 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
4178 pjsua_buddy_add_doc
4179 },
4180 {
4181 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
4182 pjsua_buddy_del_doc
4183 },
4184 {
4185 "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS,
4186 "Associate user data to the buddy object"
4187 },
4188 {
4189 "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS,
4190 "Get buddy user data"
4191 },
4192 {
4193 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
4194 pjsua_buddy_subscribe_pres_doc
4195 },
4196 {
4197 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
4198 pjsua_pres_dump_doc
4199 },
4200 {
4201 "im_send", py_pjsua_im_send, METH_VARARGS,
4202 pjsua_im_send_doc
4203 },
4204 {
4205 "im_typing", py_pjsua_im_typing, METH_VARARGS,
4206 pjsua_im_typing_doc
4207 },
4208 {
4209 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
4210 pjsua_conf_get_max_ports_doc
4211 },
4212 {
4213 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
4214 pjsua_conf_get_active_ports_doc
4215 },
4216 {
4217 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
4218 pjsua_enum_conf_ports_doc
4219 },
4220 {
4221 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
4222 pjsua_conf_get_port_info_doc
4223 },
4224 {
4225 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
4226 pjsua_conf_remove_port_doc
4227 },
4228 {
4229 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
4230 pjsua_conf_connect_doc
4231 },
4232 {
4233 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
4234 pjsua_conf_disconnect_doc
4235 },
4236 {
4237 "conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS,
4238 "Adjust the signal level to be transmitted from the bridge to the"
4239 " specified port by making it louder or quieter"
4240 },
4241 {
4242 "conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS,
4243 "Adjust the signal level to be received from the specified port (to"
4244 " the bridge) by making it louder or quieter"
4245 },
4246 {
4247 "conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS,
4248 "Get last signal level transmitted to or received from the specified port"
4249 },
4250 {
4251 "player_create", py_pjsua_player_create, METH_VARARGS,
4252 pjsua_player_create_doc
4253 },
4254 {
4255 "playlist_create", py_pjsua_playlist_create, METH_VARARGS,
4256 "Create WAV playlist"
4257 },
4258 {
4259 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
4260 pjsua_player_get_conf_port_doc
4261 },
4262 {
4263 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
4264 pjsua_player_set_pos_doc
4265 },
4266 {
4267 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
4268 pjsua_player_destroy_doc
4269 },
4270 {
4271 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
4272 pjsua_recorder_create_doc
4273 },
4274 {
4275 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
4276 pjsua_recorder_get_conf_port_doc
4277 },
4278 {
4279 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
4280 pjsua_recorder_destroy_doc
4281 },
4282 {
4283 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
4284 pjsua_enum_snd_devs_doc
4285 },
4286 {
4287 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
4288 pjsua_get_snd_dev_doc
4289 },
4290 {
4291 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
4292 pjsua_set_snd_dev_doc
4293 },
4294 {
4295 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
4296 pjsua_set_null_snd_dev_doc
4297 },
4298 {
4299 "set_ec", py_pjsua_set_ec, METH_VARARGS,
4300 pjsua_set_ec_doc
4301 },
4302 {
4303 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
4304 pjsua_get_ec_tail_doc
4305 },
4306 {
4307 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
4308 pjsua_enum_codecs_doc
4309 },
4310 {
4311 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
4312 pjsua_codec_set_priority_doc
4313 },
4314 {
4315 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
4316 pjsua_codec_get_param_doc
4317 },
4318 {
4319 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
4320 pjsua_codec_set_param_doc
4321 },
4322 {
4323 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
4324 pjsua_call_get_max_count_doc
4325 },
4326 {
4327 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
4328 pjsua_call_get_count_doc
4329 },
4330 {
4331 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
4332 pjsua_enum_calls_doc
4333 },
4334 {
4335 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
4336 pjsua_call_make_call_doc
4337 },
4338 {
4339 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
4340 pjsua_call_is_active_doc
4341 },
4342 {
4343 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
4344 pjsua_call_has_media_doc
4345 },
4346 {
4347 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
4348 pjsua_call_get_conf_port_doc
4349 },
4350 {
4351 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
4352 pjsua_call_get_info_doc
4353 },
4354 {
4355 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
4356 pjsua_call_set_user_data_doc
4357 },
4358 {
4359 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
4360 pjsua_call_get_user_data_doc
4361 },
4362 {
4363 "call_answer", py_pjsua_call_answer, METH_VARARGS,
4364 pjsua_call_answer_doc
4365 },
4366 {
4367 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
4368 pjsua_call_hangup_doc
4369 },
4370 {
4371 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
4372 pjsua_call_set_hold_doc
4373 },
4374 {
4375 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
4376 pjsua_call_reinvite_doc
4377 },
4378 {
4379 "call_update", py_pjsua_call_update, METH_VARARGS,
4380 "Send UPDATE"
4381 },
4382 {
4383 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
4384 pjsua_call_xfer_doc
4385 },
4386 {
4387 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
4388 pjsua_call_xfer_replaces_doc
4389 },
4390 {
4391 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
4392 pjsua_call_dial_dtmf_doc
4393 },
4394 {
4395 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
4396 pjsua_call_send_im_doc
4397 },
4398 {
4399 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
4400 pjsua_call_send_typing_ind_doc
4401 },
4402 {
4403 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
4404 pjsua_call_hangup_all_doc
4405 },
4406 {
4407 "call_dump", py_pjsua_call_dump, METH_VARARGS,
4408 pjsua_call_dump_doc
4409 },
4410 {
4411 "call_send_request", py_pjsua_call_send_request, METH_VARARGS,
4412 "Send arbitrary request"
4413 },
4414 {
4415 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
4416 },
4417 {
4418 "strerror", py_pj_strerror, METH_VARARGS, "Get error message"
4419 },
4420 {
4421 "parse_simple_uri", py_pj_parse_simple_sip, METH_VARARGS, "Parse URI"
4422 },
4423
4424
4425 {NULL, NULL} /* end of function list */
4426};
4427
4428
4429
4430/*
4431 * Mapping C structs from and to Python objects & initializing object
4432 */
4433DL_EXPORT(void)
4434init_pjsua(void)
4435{
4436 PyObject* m = NULL;
4437#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
4438
4439
4440 PyEval_InitThreads();
4441
4442 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
4443 return;
4444 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
4445 return;
4446 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
4447 return;
4448 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
4449 return;
4450 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
4451 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
4452 return;
4453 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
4454 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
4455 return;
4456
4457 /* LIB TRANSPORT */
4458
4459 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
4460 return;
4461
4462 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
4463 return;
4464
4465 /* END OF LIB TRANSPORT */
4466
4467 /* LIB ACCOUNT */
4468
4469
4470 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
4471 return;
4472 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
4473 return;
4474
4475 /* END OF LIB ACCOUNT */
4476
4477 /* LIB BUDDY */
4478
4479 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
4480 return;
4481 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
4482 return;
4483
4484 /* END OF LIB BUDDY */
4485
4486 /* LIB MEDIA */
4487
4488 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
4489 return;
4490
4491 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
4492 return;
4493
4494 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
4495 return;
4496
4497 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
4498 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
4499 return;
4500 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
4501 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
4502 return;
4503
4504 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
4505 return;
4506
4507 /* END OF LIB MEDIA */
4508
4509 /* LIB CALL */
4510
4511 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
4512 return;
4513
4514 /* END OF LIB CALL */
4515
4516 m = Py_InitModule3(
4517 "_pjsua", py_pjsua_methods, "PJSUA-lib module for python"
4518 );
4519
4520 Py_INCREF(&PyTyp_pjsua_callback);
4521 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
4522
4523 Py_INCREF(&PyTyp_pjsua_config);
4524 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
4525
4526 Py_INCREF(&PyTyp_pjsua_media_config);
4527 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
4528
4529 Py_INCREF(&PyTyp_pjsua_logging_config);
4530 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
4531
4532 Py_INCREF(&PyTyp_pjsua_msg_data);
4533 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
4534
4535 Py_INCREF(&PyTyp_pjsip_cred_info);
4536 PyModule_AddObject(m, "Pjsip_Cred_Info",
4537 (PyObject *)&PyTyp_pjsip_cred_info
4538 );
4539
4540 /* LIB TRANSPORT */
4541
4542 Py_INCREF(&PyTyp_pjsua_transport_config);
4543 PyModule_AddObject
4544 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
4545
4546 Py_INCREF(&PyTyp_pjsua_transport_info);
4547 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
4548
4549
4550 /* END OF LIB TRANSPORT */
4551
4552 /* LIB ACCOUNT */
4553
4554
4555 Py_INCREF(&PyTyp_pjsua_acc_config);
4556 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
4557 Py_INCREF(&PyTyp_pjsua_acc_info);
4558 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
4559
4560 /* END OF LIB ACCOUNT */
4561
4562 /* LIB BUDDY */
4563
4564 Py_INCREF(&PyTyp_pjsua_buddy_config);
4565 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
4566 Py_INCREF(&PyTyp_pjsua_buddy_info);
4567 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
4568
4569 /* END OF LIB BUDDY */
4570
4571 /* LIB MEDIA */
4572
4573 Py_INCREF(&PyTyp_pjsua_codec_info);
4574 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
4575 Py_INCREF(&PyTyp_pjsua_conf_port_info);
4576 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
4577 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
4578 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
4579 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
4580 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
4581 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
4582 (PyObject *)&PyTyp_pjmedia_codec_param_info);
4583 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
4584 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
4585 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
4586 Py_INCREF(&PyTyp_pjmedia_codec_param);
4587 PyModule_AddObject(m, "PJMedia_Codec_Param",
4588 (PyObject *)&PyTyp_pjmedia_codec_param);
4589
4590 /* END OF LIB MEDIA */
4591
4592 /* LIB CALL */
4593
4594 Py_INCREF(&PyTyp_pjsua_call_info);
4595 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
4596
4597 /* END OF LIB CALL */
4598
4599
4600 /*
4601 * Add various constants.
4602 */
4603 /* Skip it.. */
4604
4605#undef ADD_CONSTANT
4606}