blob: d25be6c82fdbdb1fb67b3d4e4ecb7110086e743f [file] [log] [blame]
Benny Prijono9c461142008-07-10 22:41:20 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono9c461142008-07-10 22:41:20 +00004 * 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"
Benny Prijono55040452008-07-21 18:20:57 +000023#define POOL_SIZE 512
Benny Prijono9c461142008-07-10 22:41:20 +000024#define SND_DEV_NUM 64
25#define SND_NAME_LEN 64
26
27/* LIB BASE */
28
Benny Prijono55040452008-07-21 18:20:57 +000029static 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;
Benny Prijono9c461142008-07-10 22:41:20 +000036
Benny Prijono55040452008-07-21 18:20:57 +000037/*
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
Benny Prijono9c461142008-07-10 22:41:20 +000063
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 */
Benny Prijono55040452008-07-21 18:20:57 +000074 if (pj_thread_local_get(g_thread_id) == 0)
Benny Prijono9c461142008-07-10 22:41:20 +000075 return;
76
Benny Prijono55040452008-07-21 18:20:57 +000077 if (PyCallable_Check(g_obj_log_cb)) {
78 PyObject *param_data;
79
Benny Prijono9c461142008-07-10 22:41:20 +000080 ENTER_PYTHON();
81
Benny Prijono55040452008-07-21 18:20:57 +000082 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
Benny Prijono9c461142008-07-10 22:41:20 +000091 );
92
Benny Prijono55040452008-07-21 18:20:57 +000093 Py_DECREF(param_data);
94
Benny Prijono9c461142008-07-10 22:41:20 +000095 LEAVE_PYTHON();
96 }
97}
98
Benny Prijono9c461142008-07-10 22:41:20 +000099/*
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{
Benny Prijono55040452008-07-21 18:20:57 +0000105 PJ_UNUSED_ARG(e);
106
107 if (PyCallable_Check(g_obj_callback->on_call_state)) {
108 PyObject * obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000109
110 ENTER_PYTHON();
111
Benny Prijono55040452008-07-21 18:20:57 +0000112 obj = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000113
Benny Prijono55040452008-07-21 18:20:57 +0000114 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000115 g_obj_callback->on_call_state,
Benny Prijono55040452008-07-21 18:20:57 +0000116 "iO",
117 call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000118 obj,
119 NULL
120 );
121
Benny Prijono55040452008-07-21 18:20:57 +0000122 Py_DECREF(obj);
123
Benny Prijono9c461142008-07-10 22:41:20 +0000124 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{
Benny Prijono55040452008-07-21 18:20:57 +0000136 PJ_UNUSED_ARG(rdata);
137
138 if (PyCallable_Check(g_obj_callback->on_incoming_call)) {
139 PyObject *obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000140
141 ENTER_PYTHON();
142
Benny Prijono55040452008-07-21 18:20:57 +0000143 obj = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000144
Benny Prijono55040452008-07-21 18:20:57 +0000145 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000146 g_obj_callback->on_incoming_call,
Benny Prijono55040452008-07-21 18:20:57 +0000147 "iiO",
148 acc_id,
149 call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000150 obj,
151 NULL
152 );
153
Benny Prijono55040452008-07-21 18:20:57 +0000154 Py_DECREF(obj);
155
Benny Prijono9c461142008-07-10 22:41:20 +0000156 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{
Benny Prijono55040452008-07-21 18:20:57 +0000167 if (PyCallable_Check(g_obj_callback->on_call_media_state)) {
168
Benny Prijono9c461142008-07-10 22:41:20 +0000169 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{
Benny Prijono55040452008-07-21 18:20:57 +0000189 if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000190 char digit_str[10];
191
Benny Prijono876a2ae2008-08-18 11:07:58 +0000192 PyGILState_STATE state = PyGILState_Ensure();
Benny Prijono9c461142008-07-10 22:41:20 +0000193
194 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
195
Benny Prijono55040452008-07-21 18:20:57 +0000196 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000197 g_obj_callback->on_dtmf_digit,
Benny Prijono55040452008-07-21 18:20:57 +0000198 "is",
199 call_id,
200 digit_str,
Benny Prijono9c461142008-07-10 22:41:20 +0000201 NULL
202 );
203
Benny Prijono876a2ae2008-08-18 11:07:58 +0000204 PyGILState_Release(state);
Benny Prijono9c461142008-07-10 22:41:20 +0000205 }
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{
Benny Prijono55040452008-07-21 18:20:57 +0000217 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) {
218 PyObject *ret, *param_dst;
Benny Prijono9c461142008-07-10 22:41:20 +0000219 int cd;
220
221 ENTER_PYTHON();
222
Benny Prijono55040452008-07-21 18:20:57 +0000223 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
Benny Prijono9c461142008-07-10 22:41:20 +0000236 if (ret != NULL) {
237 if (ret != Py_None) {
238 if (PyArg_Parse(ret,"i",&cd)) {
239 *code = cd;
240 }
241 }
Benny Prijono55040452008-07-21 18:20:57 +0000242 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000243 }
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{
Benny Prijono55040452008-07-21 18:20:57 +0000263 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) {
264 PyObject *ret, *param_reason;
Benny Prijono9c461142008-07-10 22:41:20 +0000265
266 ENTER_PYTHON();
267
Benny Prijono55040452008-07-21 18:20:57 +0000268 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
Benny Prijono9c461142008-07-10 22:41:20 +0000283 if (ret != NULL) {
284 if (ret != Py_None) {
Benny Prijono55040452008-07-21 18:20:57 +0000285 int cnt;
Benny Prijono9c461142008-07-10 22:41:20 +0000286 if (PyArg_Parse(ret,"i",&cnt)) {
287 *p_cont = cnt;
288 }
289 }
Benny Prijono55040452008-07-21 18:20:57 +0000290 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000291 }
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{
Benny Prijono55040452008-07-21 18:20:57 +0000308 PJ_UNUSED_ARG(rdata);
309
310 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) {
311 PyObject *ret, *param_reason, *param_rdata;
Benny Prijono9c461142008-07-10 22:41:20 +0000312 int cd;
Benny Prijono9c461142008-07-10 22:41:20 +0000313
314 ENTER_PYTHON();
315
Benny Prijono55040452008-07-21 18:20:57 +0000316 param_reason = PyString_FromPJ(st_text);
317 param_rdata = Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000318
Benny Prijono55040452008-07-21 18:20:57 +0000319 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
Benny Prijono9c461142008-07-10 22:41:20 +0000332 if (ret != NULL) {
333 if (ret != Py_None) {
Benny Prijono55040452008-07-21 18:20:57 +0000334 PyObject * txt;
Benny Prijono9c461142008-07-10 22:41:20 +0000335 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
336 *st_code = cd;
Benny Prijono55040452008-07-21 18:20:57 +0000337 *st_text = PyString_ToPJ(txt);
Benny Prijono9c461142008-07-10 22:41:20 +0000338 }
339 }
Benny Prijono55040452008-07-21 18:20:57 +0000340 Py_DECREF(ret);
Benny Prijono9c461142008-07-10 22:41:20 +0000341 }
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{
Benny Prijono55040452008-07-21 18:20:57 +0000356 if (PyCallable_Check(g_obj_callback->on_call_replaced)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000357 ENTER_PYTHON();
358
Benny Prijono55040452008-07-21 18:20:57 +0000359 PyObject_CallFunction(
Benny Prijono9c461142008-07-10 22:41:20 +0000360 g_obj_callback->on_call_replaced,
Benny Prijono55040452008-07-21 18:20:57 +0000361 "ii",
362 old_call_id,
363 new_call_id,
Benny Prijono9c461142008-07-10 22:41:20 +0000364 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{
Benny Prijono55040452008-07-21 18:20:57 +0000378 if (PyCallable_Check(g_obj_callback->on_reg_state)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000379 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
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000392/*
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
Benny Prijono55040452008-07-21 18:20:57 +0000409 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;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000413
414 ENTER_PYTHON();
415
Benny Prijono55040452008-07-21 18:20:57 +0000416 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);
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000456
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;
Benny Prijono55040452008-07-21 18:20:57 +0000463 tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1));
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000464 reason->ptr = reason_buf;
465 pj_strncpy(reason, &tmp, sizeof(reason_buf));
466 } else {
Benny Prijono55040452008-07-21 18:20:57 +0000467 reason->slen = 0;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000468 }
469 }
Benny Prijono55040452008-07-21 18:20:57 +0000470 Py_XDECREF(ret);
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000471 } else if (ret) {
472 Py_XDECREF(ret);
473 }
474
475 LEAVE_PYTHON();
476 }
477}
Benny Prijono9c461142008-07-10 22:41:20 +0000478
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{
Benny Prijono55040452008-07-21 18:20:57 +0000485 if (PyCallable_Check(g_obj_callback->on_buddy_state)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000486 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{
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000508 PJ_UNUSED_ARG(rdata);
509
Benny Prijono55040452008-07-21 18:20:57 +0000510 if (PyCallable_Check(g_obj_callback->on_pager)) {
511 PyObject *param_from, *param_to, *param_contact, *param_mime_type,
512 *param_body;
513
Benny Prijono9c461142008-07-10 22:41:20 +0000514 ENTER_PYTHON();
515
Benny Prijono55040452008-07-21 18:20:57 +0000516 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);
Benny Prijono9c461142008-07-10 22:41:20 +0000540
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{
Benny Prijono55040452008-07-21 18:20:57 +0000558 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;
Benny Prijono9c461142008-07-10 22:41:20 +0000562
563 ENTER_PYTHON();
564
565 PJ_UNUSED_ARG(tdata);
566 PJ_UNUSED_ARG(rdata);
567
Benny Prijono9c461142008-07-10 22:41:20 +0000568 PyObject_CallFunctionObjArgs(
Benny Prijono55040452008-07-21 18:20:57 +0000569 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);
Benny Prijono9c461142008-07-10 22:41:20 +0000587
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{
Benny Prijono55040452008-07-21 18:20:57 +0000602 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
Benny Prijono9c461142008-07-10 22:41:20 +0000606 ENTER_PYTHON();
607
608 PJ_UNUSED_ARG(rdata);
609
610 PyObject_CallFunctionObjArgs(
Benny Prijono55040452008-07-21 18:20:57 +0000611 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);
Benny Prijono9c461142008-07-10 22:41:20 +0000627
628 LEAVE_PYTHON();
629 }
630}
631
632
Benny Prijono6a464882009-10-29 08:16:46 +0000633/*
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}
Benny Prijono9c461142008-07-10 22:41:20 +0000660
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
Benny Prijono55040452008-07-21 18:20:57 +0000673 for (i=0; i<PyList_Size(py_hdr_list); ++i) {
Benny Prijono9c461142008-07-10 22:41:20 +0000674 pj_str_t hname, hvalue;
675 pjsip_generic_string_hdr * new_hdr;
676 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
677
Benny Prijono55040452008-07-21 18:20:57 +0000678 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;
Benny Prijono9c461142008-07-10 22:41:20 +0000687 } 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
Benny Prijono9c461142008-07-10 22:41:20 +0000699/*
700 * py_pjsua_thread_register
Benny Prijono9c461142008-07-10 22:41:20 +0000701 */
702static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
703{
Benny Prijono9c461142008-07-10 22:41:20 +0000704 pj_status_t status;
705 const char *name;
706 PyObject *py_desc;
707 pj_thread_t *thread;
Benny Prijono55040452008-07-21 18:20:57 +0000708 struct py_thread_desc *thread_desc;
Benny Prijono9c461142008-07-10 22:41:20 +0000709
710 PJ_UNUSED_ARG(pSelf);
711
Benny Prijono55040452008-07-21 18:20:57 +0000712 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000713 return NULL;
714 }
Benny Prijono55040452008-07-21 18:20:57 +0000715 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);
Benny Prijono9c461142008-07-10 22:41:20 +0000721
722 if (status == PJ_SUCCESS)
Benny Prijono55040452008-07-21 18:20:57 +0000723 status = pj_thread_local_set(g_thread_id, (void*)1);
724
Benny Prijono9c461142008-07-10 22:41:20 +0000725 return Py_BuildValue("i",status);
726}
727
728/*
729 * py_pjsua_logging_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000730 */
731static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
Benny Prijono55040452008-07-21 18:20:57 +0000732 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +0000733{
734 PyObj_pjsua_logging_config *obj;
735 pjsua_logging_config cfg;
736
737 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000738 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000739
Benny Prijono9c461142008-07-10 22:41:20 +0000740 pjsua_logging_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +0000741 obj = (PyObj_pjsua_logging_config*)
742 PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config,
743 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000744 PyObj_pjsua_logging_config_import(obj, &cfg);
745
Benny Prijono55040452008-07-21 18:20:57 +0000746 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000747}
748
749
750/*
751 * py_pjsua_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000752 */
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);
Benny Prijono55040452008-07-21 18:20:57 +0000759 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000760
Benny Prijono9c461142008-07-10 22:41:20 +0000761 pjsua_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +0000762 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config,
763 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000764 PyObj_pjsua_config_import(obj, &cfg);
765
Benny Prijono55040452008-07-21 18:20:57 +0000766 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +0000767}
768
769
770/*
771 * py_pjsua_media_config_default
Benny Prijono9c461142008-07-10 22:41:20 +0000772 */
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);
Benny Prijono55040452008-07-21 18:20:57 +0000780 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000781
Benny Prijono9c461142008-07-10 22:41:20 +0000782 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);
Benny Prijono55040452008-07-21 18:20:57 +0000786
Benny Prijono9c461142008-07-10 22:41:20 +0000787 return (PyObject *)obj;
788}
789
790
791/*
792 * py_pjsua_msg_data_init
Benny Prijono9c461142008-07-10 22:41:20 +0000793 */
794static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
795{
Benny Prijono9c461142008-07-10 22:41:20 +0000796 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +0000797 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000798
Benny Prijono55040452008-07-21 18:20:57 +0000799 return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data,
800 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +0000801}
802
803
804/*
805 * py_pjsua_reconfigure_logging
806 */
Benny Prijono55040452008-07-21 18:20:57 +0000807static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf,
808 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +0000809{
Benny Prijono55040452008-07-21 18:20:57 +0000810 PyObject *logObj;
Benny Prijono9c461142008-07-10 22:41:20 +0000811 pj_status_t status;
812
813 PJ_UNUSED_ARG(pSelf);
814
Benny Prijono55040452008-07-21 18:20:57 +0000815 if (!PyArg_ParseTuple(pArgs, "O", &logObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000816 return NULL;
817 }
Benny Prijono55040452008-07-21 18:20:57 +0000818
819 if (logObj != Py_None) {
820 PyObj_pjsua_logging_config *log;
821 pjsua_logging_config cfg;
822
823 log = (PyObj_pjsua_logging_config*)logObj;
Benny Prijono9c461142008-07-10 22:41:20 +0000824 cfg.msg_logging = log->msg_logging;
825 cfg.level = log->level;
826 cfg.console_level = log->console_level;
827 cfg.decor = log->decor;
Benny Prijono55040452008-07-21 18:20:57 +0000828 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);
Benny Prijono9c461142008-07-10 22:41:20 +0000832 cfg.cb = &cb_log_cb;
833 status = pjsua_reconfigure_logging(&cfg);
834 } else {
835 status = pjsua_reconfigure_logging(NULL);
836 }
Benny Prijono55040452008-07-21 18:20:57 +0000837
Benny Prijono9c461142008-07-10 22:41:20 +0000838 return Py_BuildValue("i",status);
839}
840
841
842/*
Benny Prijono9c461142008-07-10 22:41:20 +0000843 * 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
Benny Prijono55040452008-07-21 18:20:57 +0000853 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000854 return NULL;
855 }
856
857 pjsua_perror(sender, title, status);
Benny Prijono55040452008-07-21 18:20:57 +0000858
859 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +0000860}
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);
Benny Prijono55040452008-07-21 18:20:57 +0000871 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000872
Benny Prijono9c461142008-07-10 22:41:20 +0000873 status = pjsua_create();
874
Benny Prijono55040452008-07-21 18:20:57 +0000875 if (status == PJ_SUCCESS) {
876 status = pj_thread_local_alloc(&g_thread_id);
Benny Prijono9c461142008-07-10 22:41:20 +0000877 if (status == PJ_SUCCESS)
Benny Prijono55040452008-07-21 18:20:57 +0000878 status = pj_thread_local_set(g_thread_id, (void*)1);
879
880 pj_atexit(&clear_py_thread_desc);
Benny Prijono9c461142008-07-10 22:41:20 +0000881 }
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
Benny Prijono55040452008-07-21 18:20:57 +0000900 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +0000901 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
Benny Prijono55040452008-07-21 18:20:57 +0000908 if (o_ua_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000909 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
910
911 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
912
Benny Prijono55040452008-07-21 18:20:57 +0000913 Py_XDECREF(g_obj_callback);
Benny Prijono9c461142008-07-10 22:41:20 +0000914 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;
Benny Prijonoe6787ec2008-07-18 23:00:56 +0000926 cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe;
Benny Prijono9c461142008-07-10 22:41:20 +0000927 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;
Benny Prijono6a464882009-10-29 08:16:46 +0000931 cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;
Benny Prijono9c461142008-07-10 22:41:20 +0000932
933 p_cfg_ua = &cfg_ua;
934
935 } else {
936 p_cfg_ua = NULL;
937 }
938
Benny Prijono55040452008-07-21 18:20:57 +0000939 if (o_log_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000940 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
Benny Prijono55040452008-07-21 18:20:57 +0000946 Py_XDECREF(g_obj_log_cb);
947 g_obj_log_cb = obj_log->cb;
948 Py_INCREF(g_obj_log_cb);
Benny Prijono9c461142008-07-10 22:41:20 +0000949
950 cfg_log.cb = &cb_log_cb;
951 p_cfg_log = &cfg_log;
952
953 } else {
954 p_cfg_log = NULL;
955 }
956
Benny Prijono55040452008-07-21 18:20:57 +0000957 if (o_media_cfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +0000958 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);
Benny Prijono55040452008-07-21 18:20:57 +0000967
968 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +0000969}
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);
Benny Prijono55040452008-07-21 18:20:57 +0000980 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000981
Benny Prijono9c461142008-07-10 22:41:20 +0000982 status = pjsua_start();
983
Benny Prijono55040452008-07-21 18:20:57 +0000984 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +0000985}
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);
Benny Prijono55040452008-07-21 18:20:57 +0000996 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +0000997
Benny Prijono9c461142008-07-10 22:41:20 +0000998 status = pjsua_destroy();
999
Benny Prijono55040452008-07-21 18:20:57 +00001000 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001001}
1002
1003
1004/*
1005 * py_pjsua_handle_events
1006 */
1007static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
1008{
1009 int ret;
Benny Prijono55040452008-07-21 18:20:57 +00001010 int msec;
Benny Prijono9c461142008-07-10 22:41:20 +00001011
1012 PJ_UNUSED_ARG(pSelf);
1013
Benny Prijono55040452008-07-21 18:20:57 +00001014 if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001015 return NULL;
1016 }
1017
Benny Prijono55040452008-07-21 18:20:57 +00001018 if (msec < 0)
1019 msec = 0;
1020
1021#if !NO_PJSIP_THREAD
Benny Prijono9c461142008-07-10 22:41:20 +00001022 /* 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
Benny Prijono55040452008-07-21 18:20:57 +00001028#endif
1029
Benny Prijono9c461142008-07-10 22:41:20 +00001030 ret = pjsua_handle_events(msec);
Benny Prijono55040452008-07-21 18:20:57 +00001031
1032#if !NO_PJSIP_THREAD
Benny Prijono9c461142008-07-10 22:41:20 +00001033 Py_END_ALLOW_THREADS
Benny Prijono55040452008-07-21 18:20:57 +00001034#endif
Benny Prijono9c461142008-07-10 22:41:20 +00001035
Benny Prijono55040452008-07-21 18:20:57 +00001036 return Py_BuildValue("i", ret);
Benny Prijono9c461142008-07-10 22:41:20 +00001037}
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
Benny Prijono55040452008-07-21 18:20:57 +00001050 if (!PyArg_ParseTuple(pArgs, "s", &url)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001051 return NULL;
1052 }
Benny Prijono55040452008-07-21 18:20:57 +00001053
Benny Prijono9c461142008-07-10 22:41:20 +00001054 status = pjsua_verify_sip_url(url);
1055
Benny Prijono55040452008-07-21 18:20:57 +00001056 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001057}
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
Benny Prijono9c461142008-07-10 22:41:20 +00001117static 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
Benny Prijono9c461142008-07-10 22:41:20 +00001146 */
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);
Benny Prijono55040452008-07-21 18:20:57 +00001154 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001155
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
Benny Prijono9c461142008-07-10 22:41:20 +00001167 */
1168static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1169{
1170 pj_status_t status;
1171 int type;
Benny Prijono55040452008-07-21 18:20:57 +00001172 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001173 pjsua_transport_config cfg;
1174 pjsua_transport_id id;
1175
1176 PJ_UNUSED_ARG(pSelf);
1177
Benny Prijono55040452008-07-21 18:20:57 +00001178 if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001179 return NULL;
1180 }
1181
Benny Prijono55040452008-07-21 18:20:57 +00001182 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001183 PyObj_pjsua_transport_config *obj;
Benny Prijono55040452008-07-21 18:20:57 +00001184
1185 obj = (PyObj_pjsua_transport_config*)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001186 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
Benny Prijono9c461142008-07-10 22:41:20 +00001198 */
1199static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1200{
1201 pj_status_t status;
1202 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001203 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
1204 unsigned c, i;
1205
1206 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001207 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001208
Benny Prijono9c461142008-07-10 22:41:20 +00001209 c = PJ_ARRAY_SIZE(id);
1210 status = pjsua_enum_transports(id, &c);
1211
1212 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00001213 for (i = 0; i < c; i++) {
1214 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00001215 }
1216
Benny Prijono55040452008-07-21 18:20:57 +00001217 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001218}
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);
Benny Prijono55040452008-07-21 18:20:57 +00001243 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001244 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001245 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001246 }
1247}
1248
1249/*
1250 * py_pjsua_transport_set_enable
1251 */
Benny Prijono55040452008-07-21 18:20:57 +00001252static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf,
1253 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00001254{
1255 pj_status_t status;
1256 int id;
1257 int enabled;
1258
1259 PJ_UNUSED_ARG(pSelf);
1260
Benny Prijono55040452008-07-21 18:20:57 +00001261 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001262 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00001263 }
1264 status = pjsua_transport_set_enable(id, enabled);
1265
1266 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001267}
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
Benny Prijono55040452008-07-21 18:20:57 +00001280 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001281 return NULL;
1282 }
1283 status = pjsua_transport_close(id, force);
1284
Benny Prijono55040452008-07-21 18:20:57 +00001285 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00001286}
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
Benny Prijono9c461142008-07-10 22:41:20 +00001326 */
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);
Benny Prijono55040452008-07-21 18:20:57 +00001333 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001334
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);
Benny Prijono55040452008-07-21 18:20:57 +00001355 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001356
1357 count = pjsua_acc_get_count();
Benny Prijono55040452008-07-21 18:20:57 +00001358 return Py_BuildValue("i", count);
Benny Prijono9c461142008-07-10 22:41:20 +00001359}
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);
Benny Prijono55040452008-07-21 18:20:57 +00001405 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001406
1407 id = pjsua_acc_get_default();
1408
1409 return Py_BuildValue("i", id);
1410}
1411
1412/*
1413 * py_pjsua_acc_add
Benny Prijono9c461142008-07-10 22:41:20 +00001414 */
1415static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
1416{
1417 int is_default;
Benny Prijono55040452008-07-21 18:20:57 +00001418 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001419 int acc_id;
1420 int status;
1421
1422 PJ_UNUSED_ARG(pSelf);
1423
Benny Prijono55040452008-07-21 18:20:57 +00001424 if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001425 return NULL;
1426 }
1427
Benny Prijono55040452008-07-21 18:20:57 +00001428 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001429 pjsua_acc_config cfg;
Benny Prijono55040452008-07-21 18:20:57 +00001430 PyObj_pjsua_acc_config *ac;
Benny Prijono9c461142008-07-10 22:41:20 +00001431
1432 pjsua_acc_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +00001433 ac = (PyObj_pjsua_acc_config *)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001434 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
Benny Prijono9c461142008-07-10 22:41:20 +00001446 */
1447static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
1448{
1449 int is_default;
1450 int tid;
Benny Prijono55040452008-07-21 18:20:57 +00001451 int acc_id;
Benny Prijono9c461142008-07-10 22:41:20 +00001452 int status;
1453
1454 PJ_UNUSED_ARG(pSelf);
1455
1456 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
1457 return NULL;
1458 }
1459
Benny Prijono55040452008-07-21 18:20:57 +00001460 status = pjsua_acc_add_local(tid, is_default, &acc_id);
Benny Prijono9c461142008-07-10 22:41:20 +00001461
Benny Prijono55040452008-07-21 18:20:57 +00001462 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("");
Benny Prijono9c461142008-07-10 22:41:20 +00001509}
1510
1511/*
1512 * py_pjsua_acc_del
1513 */
1514static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
1515{
1516 int acc_id;
Benny Prijono55040452008-07-21 18:20:57 +00001517 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00001518 int status;
1519
1520 PJ_UNUSED_ARG(pSelf);
1521
Benny Prijono55040452008-07-21 18:20:57 +00001522 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001523 return NULL;
1524 }
Benny Prijono55040452008-07-21 18:20:57 +00001525
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
Benny Prijono9c461142008-07-10 22:41:20 +00001531 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{
Benny Prijono55040452008-07-21 18:20:57 +00001539 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001540 PyObj_pjsua_acc_config * ac;
1541 int acc_id;
1542 int status;
1543
1544 PJ_UNUSED_ARG(pSelf);
1545
Benny Prijono55040452008-07-21 18:20:57 +00001546 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001547 return NULL;
1548 }
1549
Benny Prijono55040452008-07-21 18:20:57 +00001550 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00001551 pjsua_acc_config cfg;
1552
1553 pjsua_acc_config_default(&cfg);
Benny Prijono55040452008-07-21 18:20:57 +00001554 ac = (PyObj_pjsua_acc_config*)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001555 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;
Benny Prijono55040452008-07-21 18:20:57 +00001594 const char *activity_text = NULL;
1595 const char *rpid_id = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00001596 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,
Benny Prijono55040452008-07-21 18:20:57 +00001602 &activity_id, &activity_text, &rpid_id))
1603 {
Benny Prijono9c461142008-07-10 22:41:20 +00001604 return NULL;
1605 }
1606
1607 pj_bzero(&rpid, sizeof(rpid));
1608 rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
1609 rpid.activity = activity_id;
Benny Prijono55040452008-07-21 18:20:57 +00001610 if (activity_text)
1611 rpid.note = pj_str((char*)activity_text);
Benny Prijono9c461142008-07-10 22:41:20 +00001612
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
Benny Prijono9c461142008-07-10 22:41:20 +00001644 */
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) {
Benny Prijono55040452008-07-21 18:20:57 +00001660 obj = (PyObj_pjsua_acc_info*)
1661 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00001662 PyObj_pjsua_acc_info_import(obj, &info);
Benny Prijono55040452008-07-21 18:20:57 +00001663 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001664 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001665 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001666 }
1667}
1668
1669/*
1670 * py_pjsua_enum_accs
Benny Prijono9c461142008-07-10 22:41:20 +00001671 */
1672static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1673{
1674 pj_status_t status;
1675 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001676 pjsua_acc_id id[PJSUA_MAX_ACC];
1677 unsigned c, i;
1678
1679 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001680 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001681
Benny Prijono9c461142008-07-10 22:41:20 +00001682 c = PJ_ARRAY_SIZE(id);
Benny Prijono9c461142008-07-10 22:41:20 +00001683 status = pjsua_enum_accs(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001684 if (status != PJ_SUCCESS)
1685 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00001686
1687 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00001688 for (i = 0; i < c; i++) {
1689 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00001690 }
1691
Benny Prijono55040452008-07-21 18:20:57 +00001692 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001693}
1694
1695/*
1696 * py_pjsua_acc_enum_info
Benny Prijono9c461142008-07-10 22:41:20 +00001697 */
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);
Benny Prijono55040452008-07-21 18:20:57 +00001706 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001707
1708 if (!PyArg_ParseTuple(pArgs, "")) {
1709 return NULL;
1710 }
1711
1712 c = PJ_ARRAY_SIZE(info);
1713 status = pjsua_acc_enum_info(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001714 if (status != PJ_SUCCESS)
1715 c = 0;
1716
Benny Prijono9c461142008-07-10 22:41:20 +00001717 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
Benny Prijono55040452008-07-21 18:20:57 +00001725 PyList_SetItem(list, i, (PyObject*)obj);
Benny Prijono9c461142008-07-10 22:41:20 +00001726 }
1727
Benny Prijono55040452008-07-21 18:20:57 +00001728 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00001729}
1730
1731/*
1732 * py_pjsua_acc_set_transport
1733 */
Benny Prijono55040452008-07-21 18:20:57 +00001734static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00001735{
1736 int acc_id, transport_id;
1737 int status;
1738
1739 PJ_UNUSED_ARG(pSelf);
1740
Benny Prijono55040452008-07-21 18:20:57 +00001741 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00001742 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
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001752/*
1753 * py_pjsua_acc_pres_notify
1754 */
Benny Prijono55040452008-07-21 18:20:57 +00001755static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf,
1756 PyObject *pArgs)
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001757{
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001758 int acc_id, state;
Benny Prijono55040452008-07-21 18:20:57 +00001759 PyObject *arg_pres, *arg_msg_data, *arg_reason;
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001760 void *srv_pres;
1761 pjsua_msg_data msg_data;
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001762 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
Benny Prijono55040452008-07-21 18:20:57 +00001769 if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres,
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001770 &state, &arg_reason, &arg_msg_data))
1771 {
1772 return NULL;
1773 }
1774
1775 srv_pres = (void*) PyLong_AsLong(arg_pres);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001776 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED);
1777
Benny Prijono55040452008-07-21 18:20:57 +00001778 if (arg_reason && PyString_Check(arg_reason)) {
1779 reason = PyString_ToPJ(arg_reason);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001780 } else {
1781 reason = pj_str("");
1782 }
1783
Benny Prijono55040452008-07-21 18:20:57 +00001784 pjsua_msg_data_init(&msg_data);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001785 if (arg_msg_data && arg_msg_data != Py_None) {
1786 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00001787 msg_data.content_type = PyString_ToPJ(omd->content_type);
1788 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001789 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
1790 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijonoe6787ec2008-07-18 23:00:56 +00001791 }
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
Benny Prijono9c461142008-07-10 22:41:20 +00001804static 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.";
Benny Prijono9c461142008-07-10 22:41:20 +00001858
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);
Benny Prijono55040452008-07-21 18:20:57 +00001875 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001876
Benny Prijono9c461142008-07-10 22:41:20 +00001877 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{
Benny Prijono9c461142008-07-10 22:41:20 +00001890 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001891 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001892
Benny Prijono55040452008-07-21 18:20:57 +00001893 return Py_BuildValue("i", pjsua_get_buddy_count());
Benny Prijono9c461142008-07-10 22:41:20 +00001894}
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
Benny Prijono9c461142008-07-10 22:41:20 +00001916 */
1917static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1918{
1919 pj_status_t status;
1920 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00001921 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
1922 unsigned c, i;
1923
1924 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00001925 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00001926
Benny Prijono9c461142008-07-10 22:41:20 +00001927 c = PJ_ARRAY_SIZE(id);
1928 status = pjsua_enum_buddies(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00001929 if (status != PJ_SUCCESS)
1930 c = 0;
1931
Benny Prijono9c461142008-07-10 22:41:20 +00001932 list = PyList_New(c);
1933 for (i = 0; i < c; i++) {
1934 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1935 }
1936
Benny Prijono55040452008-07-21 18:20:57 +00001937 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);
Benny Prijono9c461142008-07-10 22:41:20 +00001962}
1963
1964/*
1965 * py_pjsua_buddy_get_info
Benny Prijono9c461142008-07-10 22:41:20 +00001966 */
1967static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
1968{
1969 int buddy_id;
Benny Prijono9c461142008-07-10 22:41:20 +00001970 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) {
Benny Prijono55040452008-07-21 18:20:57 +00001981 PyObj_pjsua_buddy_info *obj;
1982
Benny Prijono9c461142008-07-10 22:41:20 +00001983 obj = (PyObj_pjsua_buddy_info *)
Benny Prijono55040452008-07-21 18:20:57 +00001984 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,
1985 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00001986 PyObj_pjsua_buddy_info_import(obj, &info);
Benny Prijono55040452008-07-21 18:20:57 +00001987 return (PyObject*)obj;
Benny Prijono9c461142008-07-10 22:41:20 +00001988 } else {
Benny Prijono55040452008-07-21 18:20:57 +00001989 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00001990 }
1991}
1992
1993/*
1994 * py_pjsua_buddy_add
Benny Prijono9c461142008-07-10 22:41:20 +00001995 */
1996static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
1997{
Benny Prijono55040452008-07-21 18:20:57 +00001998 PyObject *pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00001999 int buddy_id;
2000 int status;
2001
2002 PJ_UNUSED_ARG(pSelf);
2003
Benny Prijono55040452008-07-21 18:20:57 +00002004 if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002005 return NULL;
2006 }
2007
Benny Prijono55040452008-07-21 18:20:57 +00002008 if (pCfg != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00002009 pjsua_buddy_config cfg;
Benny Prijono55040452008-07-21 18:20:57 +00002010 PyObj_pjsua_buddy_config *bc;
Benny Prijono9c461142008-07-10 22:41:20 +00002011
Benny Prijono55040452008-07-21 18:20:57 +00002012 bc = (PyObj_pjsua_buddy_config *)pCfg;
Benny Prijono9c461142008-07-10 22:41:20 +00002013
2014 pjsua_buddy_config_default(&cfg);
2015 PyObj_pjsua_buddy_config_export(&cfg, bc);
2016
2017 status = pjsua_buddy_add(&cfg, &buddy_id);
Benny Prijono55040452008-07-21 18:20:57 +00002018
Benny Prijono9c461142008-07-10 22:41:20 +00002019 } 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;
Benny Prijono55040452008-07-21 18:20:57 +00002033 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00002034
2035 PJ_UNUSED_ARG(pSelf);
2036
2037 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
2038 return NULL;
2039 }
Benny Prijono55040452008-07-21 18:20:57 +00002040
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
Benny Prijono9c461142008-07-10 22:41:20 +00002046 return Py_BuildValue("i", status);
2047}
2048
2049/*
Benny Prijono55040452008-07-21 18:20:57 +00002050 * 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
Benny Prijono8595f8a2009-11-10 10:57:29 +00002064 if (!pjsua_buddy_is_valid(buddy_id)) {
2065 return Py_BuildValue("i", 0);
2066 }
2067
Benny Prijono55040452008-07-21 18:20:57 +00002068 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/*
Benny Prijono9c461142008-07-10 22:41:20 +00002100 * py_pjsua_buddy_subscribe_pres
2101 */
Benny Prijono55040452008-07-21 18:20:57 +00002102static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf,
2103 PyObject *pArgs)
2104{
Benny Prijono9c461142008-07-10 22:41:20 +00002105 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 }
Benny Prijono55040452008-07-21 18:20:57 +00002114
2115 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2116
Benny Prijono9c461142008-07-10 22:41:20 +00002117 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 }
Benny Prijono55040452008-07-21 18:20:57 +00002132
Benny Prijono9c461142008-07-10 22:41:20 +00002133 pjsua_pres_dump(verbose);
Benny Prijono55040452008-07-21 18:20:57 +00002134
2135 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00002136}
2137
2138/*
2139 * py_pjsua_im_send
Benny Prijono9c461142008-07-10 22:41:20 +00002140 */
2141static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
2142{
2143 int status;
2144 int acc_id;
Benny Prijono55040452008-07-21 18:20:57 +00002145 pj_str_t *mime_type, tmp_mime_type;
Benny Prijono9c461142008-07-10 22:41:20 +00002146 pj_str_t to, content;
Benny Prijono55040452008-07-21 18:20:57 +00002147 PyObject *pTo;
2148 PyObject *pMimeType;
2149 PyObject *pContent;
Benny Prijono9c461142008-07-10 22:41:20 +00002150 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00002151 PyObject *pMsgData;
Benny Prijono9c461142008-07-10 22:41:20 +00002152 int user_data;
Benny Prijono55040452008-07-21 18:20:57 +00002153 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002154
2155 PJ_UNUSED_ARG(pSelf);
2156
2157 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
Benny Prijono55040452008-07-21 18:20:57 +00002158 &pTo, &pMimeType, &pContent, &pMsgData, &user_data))
Benny Prijono9c461142008-07-10 22:41:20 +00002159 {
2160 return NULL;
2161 }
Benny Prijono55040452008-07-21 18:20:57 +00002162
2163 if (pMimeType != Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00002164 mime_type = &tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00002165 tmp_mime_type = PyString_ToPJ(pMimeType);
Benny Prijono9c461142008-07-10 22:41:20 +00002166 } else {
2167 mime_type = NULL;
2168 }
Benny Prijono9c461142008-07-10 22:41:20 +00002169
Benny Prijono55040452008-07-21 18:20:57 +00002170 to = PyString_ToPJ(pTo);
2171 content = PyString_ToPJ(pContent);
Benny Prijono9c461142008-07-10 22:41:20 +00002172
Benny Prijono21f871f2008-12-11 11:03:21 +00002173 pjsua_msg_data_init(&msg_data);
2174
Benny Prijono55040452008-07-21 18:20:57 +00002175 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);
Benny Prijono9c461142008-07-10 22:41:20 +00002182 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00002183 }
Benny Prijono55040452008-07-21 18:20:57 +00002184
2185 status = pjsua_im_send(acc_id, &to, mime_type, &content,
Benny Prijonocae95fc2010-10-21 02:22:41 +00002186 &msg_data, (void*)(long)user_data);
Benny Prijono55040452008-07-21 18:20:57 +00002187 if (pool)
2188 pj_pool_release(pool);
Benny Prijono9c461142008-07-10 22:41:20 +00002189
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;
Benny Prijono55040452008-07-21 18:20:57 +00002201 PyObject *pTo;
Benny Prijono9c461142008-07-10 22:41:20 +00002202 int is_typing;
2203 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00002204 PyObject *pMsgData;
2205 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002206
2207 PJ_UNUSED_ARG(pSelf);
2208
Benny Prijono55040452008-07-21 18:20:57 +00002209 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing,
2210 &pMsgData))
2211 {
Benny Prijono9c461142008-07-10 22:41:20 +00002212 return NULL;
2213 }
2214
Benny Prijono55040452008-07-21 18:20:57 +00002215 to = PyString_ToPJ(pTo);
Benny Prijono9c461142008-07-10 22:41:20 +00002216
Benny Prijono21f871f2008-12-11 11:03:21 +00002217 pjsua_msg_data_init(&msg_data);
2218
Benny Prijono55040452008-07-21 18:20:57 +00002219 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);
Benny Prijono9c461142008-07-10 22:41:20 +00002226
2227 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00002228 }
Benny Prijono55040452008-07-21 18:20:57 +00002229
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);
Benny Prijono9c461142008-07-10 22:41:20 +00002236}
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
Benny Prijono9c461142008-07-10 22:41:20 +00002280/*
2281 * py_pjsua_conf_get_max_ports
2282 */
Benny Prijono55040452008-07-21 18:20:57 +00002283static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002284{
Benny Prijono9c461142008-07-10 22:41:20 +00002285 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002286 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002287
Benny Prijono55040452008-07-21 18:20:57 +00002288 return Py_BuildValue("i", pjsua_conf_get_max_ports());
Benny Prijono9c461142008-07-10 22:41:20 +00002289}
2290
2291/*
2292 * py_pjsua_conf_get_active_ports
2293 */
Benny Prijono55040452008-07-21 18:20:57 +00002294static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf,
2295 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002296{
Benny Prijono9c461142008-07-10 22:41:20 +00002297 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002298 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002299
Benny Prijono55040452008-07-21 18:20:57 +00002300 return Py_BuildValue("i", pjsua_conf_get_active_ports());
Benny Prijono9c461142008-07-10 22:41:20 +00002301}
2302
2303/*
2304 * py_pjsua_enum_conf_ports
Benny Prijono9c461142008-07-10 22:41:20 +00002305 */
2306static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
2307{
2308 pj_status_t status;
2309 PyObject *list;
Benny Prijono9c461142008-07-10 22:41:20 +00002310 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
2311 unsigned c, i;
2312
2313 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002314 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002315
Benny Prijono9c461142008-07-10 22:41:20 +00002316 c = PJ_ARRAY_SIZE(id);
2317 status = pjsua_enum_conf_ports(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002318 if (status != PJ_SUCCESS)
2319 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002320
2321 list = PyList_New(c);
Benny Prijono55040452008-07-21 18:20:57 +00002322 for (i = 0; i < c; i++) {
2323 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00002324 }
2325
Benny Prijono55040452008-07-21 18:20:57 +00002326 return (PyObject*)list;
Benny Prijono9c461142008-07-10 22:41:20 +00002327}
2328
2329/*
2330 * py_pjsua_conf_get_port_info
2331 */
Benny Prijono55040452008-07-21 18:20:57 +00002332static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002333{
2334 int id;
Benny Prijono55040452008-07-21 18:20:57 +00002335 PyObj_pjsua_conf_port_info *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002336 pjsua_conf_port_info info;
2337 int status;
2338 unsigned i;
2339
2340 PJ_UNUSED_ARG(pSelf);
2341
Benny Prijono55040452008-07-21 18:20:57 +00002342 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002343 return NULL;
2344 }
Benny Prijono9c461142008-07-10 22:41:20 +00002345
2346 status = pjsua_conf_get_port_info(id, &info);
Benny Prijono55040452008-07-21 18:20:57 +00002347 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.bits_per_sample;
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);
Benny Prijono9c461142008-07-10 22:41:20 +00002357 for (i = 0; i < info.listener_cnt; i++) {
Benny Prijono55040452008-07-21 18:20:57 +00002358 PyObject *item = Py_BuildValue("i",info.listeners[i]);
2359 PyList_SetItem(ret->listeners, i, item);
Benny Prijono9c461142008-07-10 22:41:20 +00002360 }
Benny Prijono55040452008-07-21 18:20:57 +00002361 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002362}
2363
2364/*
2365 * py_pjsua_conf_remove_port
2366 */
Benny Prijono55040452008-07-21 18:20:57 +00002367static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002368{
2369 int id;
2370 int status;
2371
2372 PJ_UNUSED_ARG(pSelf);
2373
Benny Prijono55040452008-07-21 18:20:57 +00002374 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002375 return NULL;
2376 }
2377
2378 status = pjsua_conf_remove_port(id);
2379
Benny Prijono9c461142008-07-10 22:41:20 +00002380 return Py_BuildValue("i", status);
2381}
2382
2383/*
2384 * py_pjsua_conf_connect
2385 */
Benny Prijono55040452008-07-21 18:20:57 +00002386static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002387{
2388 int source, sink;
2389 int status;
2390
2391 PJ_UNUSED_ARG(pSelf);
2392
Benny Prijono55040452008-07-21 18:20:57 +00002393 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002394 return NULL;
2395 }
2396
2397 status = pjsua_conf_connect(source, sink);
2398
Benny Prijono9c461142008-07-10 22:41:20 +00002399 return Py_BuildValue("i", status);
2400}
2401
2402/*
2403 * py_pjsua_conf_disconnect
2404 */
Benny Prijono55040452008-07-21 18:20:57 +00002405static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002406{
2407 int source, sink;
2408 int status;
2409
2410 PJ_UNUSED_ARG(pSelf);
2411
Benny Prijono55040452008-07-21 18:20:57 +00002412 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002413 return NULL;
2414 }
2415
2416 status = pjsua_conf_disconnect(source, sink);
2417
Benny Prijono9c461142008-07-10 22:41:20 +00002418 return Py_BuildValue("i", status);
2419}
2420
2421/*
Benny Prijono288d4bd2008-07-19 15:40:21 +00002422 * py_pjsua_conf_set_tx_level
2423 */
Benny Prijono55040452008-07-21 18:20:57 +00002424static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002425{
2426 int slot;
2427 float level;
2428 int status;
2429
2430 PJ_UNUSED_ARG(pSelf);
2431
Benny Prijono55040452008-07-21 18:20:57 +00002432 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002433 return NULL;
2434 }
2435
2436 status = pjsua_conf_adjust_tx_level(slot, level);
2437
Benny Prijono288d4bd2008-07-19 15:40:21 +00002438 return Py_BuildValue("i", status);
2439}
2440
2441/*
2442 * py_pjsua_conf_set_rx_level
2443 */
Benny Prijono55040452008-07-21 18:20:57 +00002444static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002445{
2446 int slot;
2447 float level;
2448 int status;
2449
2450 PJ_UNUSED_ARG(pSelf);
2451
Benny Prijono55040452008-07-21 18:20:57 +00002452 if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002453 return NULL;
2454 }
2455
2456 status = pjsua_conf_adjust_rx_level(slot, level);
2457
Benny Prijono288d4bd2008-07-19 15:40:21 +00002458 return Py_BuildValue("i", status);
2459}
2460
2461/*
2462 * py_pjsua_conf_get_signal_level
2463 */
Benny Prijono55040452008-07-21 18:20:57 +00002464static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf,
2465 PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002466{
2467 int slot;
2468 unsigned tx_level, rx_level;
2469 int status;
2470
2471 PJ_UNUSED_ARG(pSelf);
2472
Benny Prijono55040452008-07-21 18:20:57 +00002473 if (!PyArg_ParseTuple(pArgs, "i", &slot)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002474 return NULL;
2475 }
2476
2477 status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level);
2478
Benny Prijono288d4bd2008-07-19 15:40:21 +00002479 return Py_BuildValue("iff", status, (float)(tx_level/255.0),
Benny Prijono55040452008-07-21 18:20:57 +00002480 (float)(rx_level/255.0));
Benny Prijono288d4bd2008-07-19 15:40:21 +00002481}
2482
2483/*
Benny Prijono9c461142008-07-10 22:41:20 +00002484 * py_pjsua_player_create
2485 */
Benny Prijono55040452008-07-21 18:20:57 +00002486static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002487{
2488 int id;
2489 int options;
Benny Prijono55040452008-07-21 18:20:57 +00002490 PyObject *pFilename;
2491 pj_str_t filename;
Benny Prijono9c461142008-07-10 22:41:20 +00002492 int status;
2493
2494 PJ_UNUSED_ARG(pSelf);
2495
Benny Prijono55040452008-07-21 18:20:57 +00002496 if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002497 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002498 }
2499
2500 filename = PyString_ToPJ(pFilename);
2501 status = pjsua_player_create(&filename, options, &id);
Benny Prijono9c461142008-07-10 22:41:20 +00002502
2503 return Py_BuildValue("ii", status, id);
2504}
2505
2506/*
Benny Prijono288d4bd2008-07-19 15:40:21 +00002507 * py_pjsua_playlist_create
2508 */
Benny Prijono55040452008-07-21 18:20:57 +00002509static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono288d4bd2008-07-19 15:40:21 +00002510{
2511 int id;
2512 int options;
Benny Prijono55040452008-07-21 18:20:57 +00002513 PyObject *pLabel, *pFileList;
Benny Prijono288d4bd2008-07-19 15:40:21 +00002514 pj_str_t label;
2515 int count;
2516 pj_str_t files[64];
2517 int status;
2518
2519 PJ_UNUSED_ARG(pSelf);
2520
Benny Prijono55040452008-07-21 18:20:57 +00002521 if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) {
Benny Prijono288d4bd2008-07-19 15:40:21 +00002522 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002523 }
Benny Prijono288d4bd2008-07-19 15:40:21 +00002524
Benny Prijono55040452008-07-21 18:20:57 +00002525 label = PyString_ToPJ(pLabel);
2526 if (!PyList_Check(pFileList))
2527 return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID);
Benny Prijono288d4bd2008-07-19 15:40:21 +00002528
2529 count = 0;
Benny Prijono55040452008-07-21 18:20:57 +00002530 for (count=0; count<PyList_Size(pFileList) &&
Benny Prijono288d4bd2008-07-19 15:40:21 +00002531 count<PJ_ARRAY_SIZE(files); ++count)
2532 {
Benny Prijono55040452008-07-21 18:20:57 +00002533 files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count));
Benny Prijono288d4bd2008-07-19 15:40:21 +00002534 }
2535
2536 status = pjsua_playlist_create(files, count, &label, options, &id);
2537
2538 return Py_BuildValue("ii", status, id);
2539}
2540
2541/*
Benny Prijono9c461142008-07-10 22:41:20 +00002542 * py_pjsua_player_get_conf_port
2543 */
Benny Prijono55040452008-07-21 18:20:57 +00002544static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf,
2545 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002546{
2547
2548 int id, port_id;
2549
2550 PJ_UNUSED_ARG(pSelf);
2551
Benny Prijono55040452008-07-21 18:20:57 +00002552 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002553 return NULL;
2554 }
2555
2556 port_id = pjsua_player_get_conf_port(id);
2557
Benny Prijono9c461142008-07-10 22:41:20 +00002558 return Py_BuildValue("i", port_id);
2559}
2560
2561/*
2562 * py_pjsua_player_set_pos
2563 */
Benny Prijono55040452008-07-21 18:20:57 +00002564static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002565{
2566 int id;
Benny Prijono55040452008-07-21 18:20:57 +00002567 int samples;
Benny Prijono9c461142008-07-10 22:41:20 +00002568 int status;
2569
2570 PJ_UNUSED_ARG(pSelf);
2571
Benny Prijono55040452008-07-21 18:20:57 +00002572 if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002573 return NULL;
2574 }
2575
Benny Prijono55040452008-07-21 18:20:57 +00002576 if (samples < 0)
2577 samples = 0;
2578
Benny Prijono9c461142008-07-10 22:41:20 +00002579 status = pjsua_player_set_pos(id, samples);
2580
Benny Prijono9c461142008-07-10 22:41:20 +00002581 return Py_BuildValue("i", status);
2582}
2583
2584/*
2585 * py_pjsua_player_destroy
2586 */
Benny Prijono55040452008-07-21 18:20:57 +00002587static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002588{
2589 int id;
2590 int status;
2591
2592 PJ_UNUSED_ARG(pSelf);
2593
Benny Prijono55040452008-07-21 18:20:57 +00002594 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002595 return NULL;
2596 }
2597
2598 status = pjsua_player_destroy(id);
2599
Benny Prijono9c461142008-07-10 22:41:20 +00002600 return Py_BuildValue("i", status);
2601}
2602
2603/*
2604 * py_pjsua_recorder_create
Benny Prijono9c461142008-07-10 22:41:20 +00002605 */
Benny Prijono55040452008-07-21 18:20:57 +00002606static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002607{
Benny Prijono55040452008-07-21 18:20:57 +00002608 int id, options;
Benny Prijono9c461142008-07-10 22:41:20 +00002609 int max_size;
Benny Prijono55040452008-07-21 18:20:57 +00002610 PyObject *pFilename, *pEncParam;
2611 pj_str_t filename;
Benny Prijono9c461142008-07-10 22:41:20 +00002612 int enc_type;
2613
2614 int status;
2615
2616 PJ_UNUSED_ARG(pSelf);
2617
Benny Prijono55040452008-07-21 18:20:57 +00002618 if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam,
2619 &max_size, &options))
Benny Prijono9c461142008-07-10 22:41:20 +00002620 {
2621 return NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00002622 }
Benny Prijono55040452008-07-21 18:20:57 +00002623
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);
Benny Prijono9c461142008-07-10 22:41:20 +00002630}
2631
2632/*
2633 * py_pjsua_recorder_get_conf_port
2634 */
Benny Prijono55040452008-07-21 18:20:57 +00002635static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf,
2636 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002637{
2638
2639 int id, port_id;
2640
2641 PJ_UNUSED_ARG(pSelf);
2642
Benny Prijono55040452008-07-21 18:20:57 +00002643 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002644 return NULL;
2645 }
2646
2647 port_id = pjsua_recorder_get_conf_port(id);
2648
Benny Prijono9c461142008-07-10 22:41:20 +00002649 return Py_BuildValue("i", port_id);
2650}
2651
2652/*
2653 * py_pjsua_recorder_destroy
2654 */
Benny Prijono55040452008-07-21 18:20:57 +00002655static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002656{
2657 int id;
2658 int status;
2659
2660 PJ_UNUSED_ARG(pSelf);
2661
Benny Prijono55040452008-07-21 18:20:57 +00002662 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002663 return NULL;
2664 }
2665
2666 status = pjsua_recorder_destroy(id);
2667
Benny Prijono9c461142008-07-10 22:41:20 +00002668 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;
Benny Prijono55040452008-07-21 18:20:57 +00002677 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002678 pjmedia_snd_dev_info info[SND_DEV_NUM];
2679 unsigned c, i;
2680
2681 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002682 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002683
Benny Prijono9c461142008-07-10 22:41:20 +00002684 c = PJ_ARRAY_SIZE(info);
2685 status = pjsua_enum_snd_devs(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002686 if (status != PJ_SUCCESS)
2687 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002688
Benny Prijono55040452008-07-21 18:20:57 +00002689 ret = PyList_New(c);
2690 for (i = 0; i < c; i++) {
Benny Prijono9c461142008-07-10 22:41:20 +00002691 PyObj_pjmedia_snd_dev_info * obj;
Benny Prijono55040452008-07-21 18:20:57 +00002692
2693 obj = (PyObj_pjmedia_snd_dev_info *)
2694 pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info,
2695 NULL, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00002696 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;
Benny Prijono55040452008-07-21 18:20:57 +00002699 obj->name = PyString_FromString(info[i].name);
2700
2701 PyList_SetItem(ret, i, (PyObject *)obj);
Benny Prijono9c461142008-07-10 22:41:20 +00002702 }
2703
Benny Prijono55040452008-07-21 18:20:57 +00002704 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002705}
2706
2707/*
2708 * py_pjsua_get_snd_dev
2709 */
Benny Prijono55040452008-07-21 18:20:57 +00002710static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002711{
2712 int capture_dev, playback_dev;
2713 int status;
2714
2715 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002716 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002717
Benny Prijono9c461142008-07-10 22:41:20 +00002718 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
2719
Benny Prijono9c461142008-07-10 22:41:20 +00002720 return Py_BuildValue("ii", capture_dev, playback_dev);
2721}
2722
2723/*
2724 * py_pjsua_set_snd_dev
2725 */
Benny Prijono55040452008-07-21 18:20:57 +00002726static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002727{
2728 int capture_dev, playback_dev;
2729 int status;
2730
2731 PJ_UNUSED_ARG(pSelf);
2732
Benny Prijono55040452008-07-21 18:20:57 +00002733 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002734 return NULL;
2735 }
2736
2737 status = pjsua_set_snd_dev(capture_dev, playback_dev);
2738
Benny Prijono9c461142008-07-10 22:41:20 +00002739 return Py_BuildValue("i", status);
2740}
2741
2742/*
2743 * py_pjsua_set_null_snd_dev
2744 */
Benny Prijono55040452008-07-21 18:20:57 +00002745static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002746{
Benny Prijono9c461142008-07-10 22:41:20 +00002747 int status;
Benny Prijono9c461142008-07-10 22:41:20 +00002748
Benny Prijono55040452008-07-21 18:20:57 +00002749 PJ_UNUSED_ARG(pSelf);
2750 PJ_UNUSED_ARG(pArgs);
2751
Benny Prijono9c461142008-07-10 22:41:20 +00002752 status = pjsua_set_null_snd_dev();
Benny Prijono55040452008-07-21 18:20:57 +00002753
Benny Prijono9c461142008-07-10 22:41:20 +00002754 return Py_BuildValue("i", status);
2755}
2756
2757/*
Benny Prijono9c461142008-07-10 22:41:20 +00002758 * py_pjsua_set_ec
2759 */
Benny Prijono55040452008-07-21 18:20:57 +00002760static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002761{
2762 int options;
2763 int tail_ms;
2764 int status;
2765
2766 PJ_UNUSED_ARG(pSelf);
2767
Benny Prijono55040452008-07-21 18:20:57 +00002768 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002769 return NULL;
2770 }
Benny Prijono55040452008-07-21 18:20:57 +00002771
Benny Prijono9c461142008-07-10 22:41:20 +00002772 status = pjsua_set_ec(tail_ms, options);
2773
Benny Prijono9c461142008-07-10 22:41:20 +00002774 return Py_BuildValue("i", status);
2775}
2776
2777/*
2778 * py_pjsua_get_ec_tail
2779 */
Benny Prijono55040452008-07-21 18:20:57 +00002780static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002781{
Benny Prijono9c461142008-07-10 22:41:20 +00002782 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002783 unsigned tail_ms;
Benny Prijono9c461142008-07-10 22:41:20 +00002784
2785 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002786 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002787
Benny Prijono55040452008-07-21 18:20:57 +00002788 status = pjsua_get_ec_tail(&tail_ms);
2789 if (status != PJ_SUCCESS)
2790 tail_ms = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002791
Benny Prijono55040452008-07-21 18:20:57 +00002792 return Py_BuildValue("i", tail_ms);
Benny Prijono9c461142008-07-10 22:41:20 +00002793}
2794
2795/*
2796 * py_pjsua_enum_codecs
Benny Prijono9c461142008-07-10 22:41:20 +00002797 */
2798static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
2799{
2800 pj_status_t status;
Benny Prijono55040452008-07-21 18:20:57 +00002801 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002802 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
2803 unsigned c, i;
2804
2805 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00002806 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00002807
Benny Prijono9c461142008-07-10 22:41:20 +00002808 c = PJ_ARRAY_SIZE(info);
2809 status = pjsua_enum_codecs(info, &c);
Benny Prijono55040452008-07-21 18:20:57 +00002810 if (status != PJ_SUCCESS)
2811 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00002812
Benny Prijono55040452008-07-21 18:20:57 +00002813 ret = PyList_New(c);
2814 for (i = 0; i < c; i++) {
Benny Prijono9c461142008-07-10 22:41:20 +00002815 PyObj_pjsua_codec_info * obj;
Benny Prijono55040452008-07-21 18:20:57 +00002816 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);
Benny Prijono9c461142008-07-10 22:41:20 +00002819 obj->priority = info[i].priority;
Benny Prijono9c461142008-07-10 22:41:20 +00002820
Benny Prijono55040452008-07-21 18:20:57 +00002821 PyList_SetItem(ret, i, (PyObject *)obj);
2822 }
2823
2824 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002825}
2826
2827/*
2828 * py_pjsua_codec_set_priority
2829 */
Benny Prijono55040452008-07-21 18:20:57 +00002830static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002831{
Benny Prijono9c461142008-07-10 22:41:20 +00002832 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002833 PyObject *pCodecId;
2834 pj_str_t codec_id;
2835 int priority;
Benny Prijono9c461142008-07-10 22:41:20 +00002836
2837 PJ_UNUSED_ARG(pSelf);
2838
Benny Prijono55040452008-07-21 18:20:57 +00002839 if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002840 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00002841 }
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);
Benny Prijono9c461142008-07-10 22:41:20 +00002850
2851 return Py_BuildValue("i", status);
2852}
2853
2854/*
2855 * py_pjsua_codec_get_param
2856 */
Benny Prijono55040452008-07-21 18:20:57 +00002857static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002858{
Benny Prijono9c461142008-07-10 22:41:20 +00002859 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002860 PyObject *pCodecId;
2861 pj_str_t codec_id;
Benny Prijono9c461142008-07-10 22:41:20 +00002862 pjmedia_codec_param param;
Benny Prijono55040452008-07-21 18:20:57 +00002863 PyObj_pjmedia_codec_param *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00002864
2865 PJ_UNUSED_ARG(pSelf);
2866
Benny Prijono55040452008-07-21 18:20:57 +00002867 if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002868 return NULL;
2869 }
Benny Prijono9c461142008-07-10 22:41:20 +00002870
Benny Prijono55040452008-07-21 18:20:57 +00002871 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;
Benny Prijonoc8215b32008-09-04 07:37:30 +00002887 //ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
2888 //ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
Benny Prijono55040452008-07-21 18:20:57 +00002889 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;
Benny Prijono9c461142008-07-10 22:41:20 +00002895}
Benny Prijono55040452008-07-21 18:20:57 +00002896
2897
Benny Prijono9c461142008-07-10 22:41:20 +00002898/*
2899 * py_pjsua_codec_set_param
2900 */
Benny Prijono55040452008-07-21 18:20:57 +00002901static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00002902{
Benny Prijono9c461142008-07-10 22:41:20 +00002903 int status;
Benny Prijono55040452008-07-21 18:20:57 +00002904 PyObject *pCodecId, *pCodecParam;
2905 pj_str_t codec_id;
Benny Prijono9c461142008-07-10 22:41:20 +00002906 pjmedia_codec_param param;
Benny Prijono9c461142008-07-10 22:41:20 +00002907
2908 PJ_UNUSED_ARG(pSelf);
2909
Benny Prijono55040452008-07-21 18:20:57 +00002910 if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) {
Benny Prijono9c461142008-07-10 22:41:20 +00002911 return NULL;
2912 }
2913
Benny Prijono55040452008-07-21 18:20:57 +00002914 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
Benny Prijono9c461142008-07-10 22:41:20 +00002921 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;
Benny Prijonoc8215b32008-09-04 07:37:30 +00002928 //param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
2929 //param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
Benny Prijono9c461142008-07-10 22:41:20 +00002930 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
2931 param.setting.penh = obj->setting->penh;
2932 param.setting.plc = obj->setting->plc;
Benny Prijono9c461142008-07-10 22:41:20 +00002933 param.setting.vad = obj->setting->vad;
Benny Prijono55040452008-07-21 18:20:57 +00002934 status = pjsua_codec_set_param(&codec_id, &param);
2935
Benny Prijono9c461142008-07-10 22:41:20 +00002936 } else {
Benny Prijono55040452008-07-21 18:20:57 +00002937 status = pjsua_codec_set_param(&codec_id, NULL);
Benny Prijono9c461142008-07-10 22:41:20 +00002938 }
Benny Prijono55040452008-07-21 18:20:57 +00002939
Benny Prijono9c461142008-07-10 22:41:20 +00002940 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";
Benny Prijono9c461142008-07-10 22:41:20 +00002955static 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.";
Benny Prijono9c461142008-07-10 22:41:20 +00003019static 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/*
Benny Prijono9c461142008-07-10 22:41:20 +00003044 * py_pjsua_call_get_max_count
3045 */
Benny Prijono55040452008-07-21 18:20:57 +00003046static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003047{
3048 int count;
3049
3050 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003051 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003052
Benny Prijono9c461142008-07-10 22:41:20 +00003053 count = pjsua_call_get_max_count();
3054
Benny Prijono9c461142008-07-10 22:41:20 +00003055 return Py_BuildValue("i", count);
3056}
3057
3058/*
3059 * py_pjsua_call_get_count
3060 */
Benny Prijono55040452008-07-21 18:20:57 +00003061static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003062{
Benny Prijono9c461142008-07-10 22:41:20 +00003063 int count;
3064
3065 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003066 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003067
Benny Prijono9c461142008-07-10 22:41:20 +00003068 count = pjsua_call_get_count();
3069
Benny Prijono9c461142008-07-10 22:41:20 +00003070 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;
Benny Prijono55040452008-07-21 18:20:57 +00003079 PyObject *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003080 pjsua_transport_id id[PJSUA_MAX_CALLS];
3081 unsigned c, i;
3082
3083 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003084 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003085
Benny Prijono9c461142008-07-10 22:41:20 +00003086 c = PJ_ARRAY_SIZE(id);
3087 status = pjsua_enum_calls(id, &c);
Benny Prijono55040452008-07-21 18:20:57 +00003088 if (status != PJ_SUCCESS)
3089 c = 0;
Benny Prijono9c461142008-07-10 22:41:20 +00003090
Benny Prijono55040452008-07-21 18:20:57 +00003091 ret = PyList_New(c);
3092 for (i = 0; i < c; i++) {
3093 PyList_SetItem(ret, i, Py_BuildValue("i", id[i]));
Benny Prijono9c461142008-07-10 22:41:20 +00003094 }
3095
Benny Prijono55040452008-07-21 18:20:57 +00003096 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003097}
3098
3099/*
3100 * py_pjsua_call_make_call
3101 */
Benny Prijono55040452008-07-21 18:20:57 +00003102static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003103{
3104 int status;
3105 int acc_id;
3106 pj_str_t dst_uri;
Benny Prijono55040452008-07-21 18:20:57 +00003107 PyObject *pDstUri, *pMsgData, *pUserData;
Benny Prijono9c461142008-07-10 22:41:20 +00003108 unsigned options;
3109 pjsua_msg_data msg_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003110 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003111 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003112
3113 PJ_UNUSED_ARG(pSelf);
3114
Benny Prijono55040452008-07-21 18:20:57 +00003115 if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &options,
3116 &pUserData, &pMsgData))
Benny Prijono9c461142008-07-10 22:41:20 +00003117 {
3118 return NULL;
3119 }
3120
Benny Prijono55040452008-07-21 18:20:57 +00003121 dst_uri = PyString_ToPJ(pDstUri);
3122 pjsua_msg_data_init(&msg_data);
3123
3124 if (pMsgData != Py_None) {
3125 PyObj_pjsua_msg_data * omd;
3126
3127 omd = (PyObj_pjsua_msg_data *)pMsgData;
3128
3129 msg_data.content_type = PyString_ToPJ(omd->content_type);
3130 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3131 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003132 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003133 }
Benny Prijono55040452008-07-21 18:20:57 +00003134
3135 Py_XINCREF(pUserData);
3136
3137 status = pjsua_call_make_call(acc_id, &dst_uri,
3138 options, (void*)pUserData,
3139 &msg_data, &call_id);
3140 if (pool != NULL)
3141 pj_pool_release(pool);
3142
Benny Prijono680c39e2008-07-21 21:15:46 +00003143 if (status != PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00003144 Py_XDECREF(pUserData);
Benny Prijono680c39e2008-07-21 21:15:46 +00003145 }
Benny Prijono55040452008-07-21 18:20:57 +00003146
3147 return Py_BuildValue("ii", status, call_id);
Benny Prijono9c461142008-07-10 22:41:20 +00003148}
3149
3150/*
3151 * py_pjsua_call_is_active
3152 */
Benny Prijono55040452008-07-21 18:20:57 +00003153static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003154{
3155 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003156 int is_active;
Benny Prijono9c461142008-07-10 22:41:20 +00003157
3158 PJ_UNUSED_ARG(pSelf);
3159
Benny Prijono55040452008-07-21 18:20:57 +00003160 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003161 return NULL;
3162 }
3163
Benny Prijono55040452008-07-21 18:20:57 +00003164 is_active = pjsua_call_is_active(call_id);
Benny Prijono9c461142008-07-10 22:41:20 +00003165
Benny Prijono55040452008-07-21 18:20:57 +00003166 return Py_BuildValue("i", is_active);
Benny Prijono9c461142008-07-10 22:41:20 +00003167}
3168
3169/*
3170 * py_pjsua_call_has_media
3171 */
Benny Prijono55040452008-07-21 18:20:57 +00003172static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003173{
3174 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003175 int has_media;
Benny Prijono9c461142008-07-10 22:41:20 +00003176
3177 PJ_UNUSED_ARG(pSelf);
3178
Benny Prijono55040452008-07-21 18:20:57 +00003179 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003180 return NULL;
3181 }
3182
Benny Prijono55040452008-07-21 18:20:57 +00003183 has_media = pjsua_call_has_media(call_id);
3184
3185 return Py_BuildValue("i", has_media);
Benny Prijono9c461142008-07-10 22:41:20 +00003186}
3187
3188/*
3189 * py_pjsua_call_get_conf_port
3190 */
Benny Prijono55040452008-07-21 18:20:57 +00003191static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003192{
3193 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003194 int port_id;
3195
Benny Prijono9c461142008-07-10 22:41:20 +00003196 PJ_UNUSED_ARG(pSelf);
3197
Benny Prijono55040452008-07-21 18:20:57 +00003198 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003199 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003200 }
3201
Benny Prijono9c461142008-07-10 22:41:20 +00003202 port_id = pjsua_call_get_conf_port(call_id);
Benny Prijono55040452008-07-21 18:20:57 +00003203
Benny Prijono9c461142008-07-10 22:41:20 +00003204 return Py_BuildValue("i", port_id);
3205}
3206
3207/*
3208 * py_pjsua_call_get_info
3209 */
Benny Prijono55040452008-07-21 18:20:57 +00003210static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003211{
3212 int call_id;
3213 int status;
Benny Prijono55040452008-07-21 18:20:57 +00003214 PyObj_pjsua_call_info *ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003215 pjsua_call_info info;
3216
3217 PJ_UNUSED_ARG(pSelf);
3218
Benny Prijono55040452008-07-21 18:20:57 +00003219 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003220 return NULL;
3221 }
3222
Benny Prijono9c461142008-07-10 22:41:20 +00003223 status = pjsua_call_get_info(call_id, &info);
Benny Prijono55040452008-07-21 18:20:57 +00003224 if (status != PJ_SUCCESS)
3225 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003226
Benny Prijono55040452008-07-21 18:20:57 +00003227 ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info,
3228 NULL, NULL);
3229 ret->acc_id = info.acc_id;
3230 Py_XDECREF(ret->call_id);
3231 ret->call_id = PyString_FromPJ(&info.call_id);
3232 ret->conf_slot = info.conf_slot;
3233 ret->connect_duration = info.connect_duration.sec * 1000 +
3234 info.connect_duration.msec;
3235 ret->total_duration = info.total_duration.sec * 1000 +
3236 info.total_duration.msec;
3237 ret->id = info.id;
3238 ret->last_status = info.last_status;
3239 Py_XDECREF(ret->last_status_text);
3240 ret->last_status_text = PyString_FromPJ(&info.last_status_text);
3241 Py_XDECREF(ret->local_contact);
3242 ret->local_contact = PyString_FromPJ(&info.local_contact);
3243 Py_XDECREF(ret->local_info);
3244 ret->local_info = PyString_FromPJ(&info.local_info);
3245 Py_XDECREF(ret->remote_contact);
3246 ret->remote_contact = PyString_FromPJ(&info.remote_contact);
3247 Py_XDECREF(ret->remote_info);
3248 ret->remote_info = PyString_FromPJ(&info.remote_info);
3249 ret->media_dir = info.media_dir;
3250 ret->media_status = info.media_status;
3251 ret->role = info.role;
3252 ret->state = info.state;
3253 Py_XDECREF(ret->state_text);
3254 ret->state_text = PyString_FromPJ(&info.state_text);
Benny Prijono9c461142008-07-10 22:41:20 +00003255
Benny Prijono55040452008-07-21 18:20:57 +00003256 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003257}
3258
3259/*
3260 * py_pjsua_call_set_user_data
3261 */
Benny Prijono55040452008-07-21 18:20:57 +00003262static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003263{
3264 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003265 PyObject *pUserData, *old_user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003266 int status;
3267
3268 PJ_UNUSED_ARG(pSelf);
3269
Benny Prijono55040452008-07-21 18:20:57 +00003270 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003271 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003272 }
3273
3274 old_user_data = (PyObject*) pjsua_call_get_user_data(call_id);
3275
3276 if (old_user_data == pUserData) {
3277 return Py_BuildValue("i", PJ_SUCCESS);
3278 }
3279
3280 Py_XINCREF(pUserData);
3281 Py_XDECREF(old_user_data);
3282
3283 status = pjsua_call_set_user_data(call_id, (void*)pUserData);
Benny Prijono9c461142008-07-10 22:41:20 +00003284
Benny Prijono680c39e2008-07-21 21:15:46 +00003285 if (status != PJ_SUCCESS) {
Benny Prijono55040452008-07-21 18:20:57 +00003286 Py_XDECREF(pUserData);
Benny Prijono680c39e2008-07-21 21:15:46 +00003287 }
Benny Prijono55040452008-07-21 18:20:57 +00003288
Benny Prijono9c461142008-07-10 22:41:20 +00003289 return Py_BuildValue("i", status);
3290}
3291
3292/*
3293 * py_pjsua_call_get_user_data
3294 */
Benny Prijono55040452008-07-21 18:20:57 +00003295static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003296{
3297 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003298 PyObject *user_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003299
3300 PJ_UNUSED_ARG(pSelf);
3301
Benny Prijono55040452008-07-21 18:20:57 +00003302 if (!PyArg_ParseTuple(pArgs, "i", &call_id)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003303 return NULL;
3304 }
3305
Benny Prijono55040452008-07-21 18:20:57 +00003306 user_data = (PyObject*)pjsua_call_get_user_data(call_id);
3307 return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003308}
3309
3310/*
3311 * py_pjsua_call_answer
3312 */
Benny Prijono55040452008-07-21 18:20:57 +00003313static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003314{
3315 int status;
3316 int call_id;
3317 pj_str_t * reason, tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003318 PyObject *pReason;
Benny Prijono9c461142008-07-10 22:41:20 +00003319 unsigned code;
3320 pjsua_msg_data msg_data;
3321 PyObject * omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003322 pj_pool_t * pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003323
3324 PJ_UNUSED_ARG(pSelf);
3325
Benny Prijono55040452008-07-21 18:20:57 +00003326 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003327 return NULL;
3328 }
Benny Prijono55040452008-07-21 18:20:57 +00003329
3330 if (pReason == Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00003331 reason = NULL;
3332 } else {
3333 reason = &tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003334 tmp_reason = PyString_ToPJ(pReason);
Benny Prijono9c461142008-07-10 22:41:20 +00003335 }
Benny Prijono55040452008-07-21 18:20:57 +00003336
3337 pjsua_msg_data_init(&msg_data);
3338 if (omdObj != Py_None) {
3339 PyObj_pjsua_msg_data *omd;
3340
Benny Prijono9c461142008-07-10 22:41:20 +00003341 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003342 msg_data.content_type = PyString_ToPJ(omd->content_type);
3343 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3344 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003345 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003346 }
3347
Benny Prijono55040452008-07-21 18:20:57 +00003348 status = pjsua_call_answer(call_id, code, reason, &msg_data);
3349
3350 if (pool)
3351 pj_pool_release(pool);
3352
3353 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003354}
3355
3356/*
3357 * py_pjsua_call_hangup
3358 */
Benny Prijono55040452008-07-21 18:20:57 +00003359static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003360{
3361 int status;
3362 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003363 pj_str_t *reason, tmp_reason;
3364 PyObject *pReason;
Benny Prijono9c461142008-07-10 22:41:20 +00003365 unsigned code;
3366 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003367 PyObject *omdObj;
3368 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003369
3370 PJ_UNUSED_ARG(pSelf);
3371
Benny Prijono55040452008-07-21 18:20:57 +00003372 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason,
3373 &omdObj))
Benny Prijono9c461142008-07-10 22:41:20 +00003374 {
3375 return NULL;
3376 }
Benny Prijono55040452008-07-21 18:20:57 +00003377
3378 if (pReason == Py_None) {
Benny Prijono9c461142008-07-10 22:41:20 +00003379 reason = NULL;
3380 } else {
3381 reason = &tmp_reason;
Benny Prijono55040452008-07-21 18:20:57 +00003382 tmp_reason = PyString_ToPJ(pReason);
Benny Prijono9c461142008-07-10 22:41:20 +00003383 }
Benny Prijono55040452008-07-21 18:20:57 +00003384
3385 pjsua_msg_data_init(&msg_data);
3386 if (omdObj != Py_None) {
3387 PyObj_pjsua_msg_data *omd;
3388
Benny Prijono9c461142008-07-10 22:41:20 +00003389 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003390 msg_data.content_type = PyString_ToPJ(omd->content_type);
3391 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3392 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003393 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003394 }
3395
Benny Prijono55040452008-07-21 18:20:57 +00003396 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
3397 if (pool)
3398 pj_pool_release(pool);
3399
3400 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003401}
3402
3403/*
3404 * py_pjsua_call_set_hold
3405 */
Benny Prijono55040452008-07-21 18:20:57 +00003406static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003407{
3408 int status;
3409 int call_id;
3410 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003411 PyObject *omdObj;
3412 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003413
3414 PJ_UNUSED_ARG(pSelf);
3415
Benny Prijono55040452008-07-21 18:20:57 +00003416 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003417 return NULL;
3418 }
3419
Benny Prijono55040452008-07-21 18:20:57 +00003420 pjsua_msg_data_init(&msg_data);
3421 if (omdObj != Py_None) {
3422 PyObj_pjsua_msg_data *omd;
3423
Benny Prijono9c461142008-07-10 22:41:20 +00003424 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003425 msg_data.content_type = PyString_ToPJ(omd->content_type);
3426 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3427 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003428 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003429 }
Benny Prijono55040452008-07-21 18:20:57 +00003430
3431 status = pjsua_call_set_hold(call_id, &msg_data);
3432
3433 if (pool)
3434 pj_pool_release(pool);
3435
Benny Prijono9c461142008-07-10 22:41:20 +00003436 return Py_BuildValue("i",status);
3437}
3438
3439/*
3440 * py_pjsua_call_reinvite
3441 */
Benny Prijono55040452008-07-21 18:20:57 +00003442static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003443{
3444 int status;
Benny Prijono55040452008-07-21 18:20:57 +00003445 int call_id;
Benny Prijono9c461142008-07-10 22:41:20 +00003446 int unhold;
3447 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003448 PyObject *omdObj;
3449 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003450
3451 PJ_UNUSED_ARG(pSelf);
3452
Benny Prijono55040452008-07-21 18:20:57 +00003453 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003454 return NULL;
3455 }
3456
Benny Prijono55040452008-07-21 18:20:57 +00003457 pjsua_msg_data_init(&msg_data);
3458 if (omdObj != Py_None) {
3459 PyObj_pjsua_msg_data *omd;
3460
Benny Prijono9c461142008-07-10 22:41:20 +00003461 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003462 msg_data.content_type = PyString_ToPJ(omd->content_type);
3463 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3464 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003465 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003466 }
Benny Prijono55040452008-07-21 18:20:57 +00003467
3468 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
3469
3470 if (pool)
3471 pj_pool_release(pool);
3472
3473 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003474}
3475
3476/*
3477 * py_pjsua_call_update
3478 */
Benny Prijono55040452008-07-21 18:20:57 +00003479static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003480{
3481 int status;
3482 int call_id;
3483 int option;
3484 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003485 PyObject *omdObj;
3486 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003487
3488 PJ_UNUSED_ARG(pSelf);
3489
Benny Prijono55040452008-07-21 18:20:57 +00003490 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003491 return NULL;
3492 }
3493
Benny Prijono55040452008-07-21 18:20:57 +00003494 pjsua_msg_data_init(&msg_data);
3495 if (omdObj != Py_None) {
3496 PyObj_pjsua_msg_data *omd;
3497
Benny Prijono9c461142008-07-10 22:41:20 +00003498 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003499 msg_data.content_type = PyString_ToPJ(omd->content_type);
3500 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3501 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003502 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003503 }
Benny Prijono55040452008-07-21 18:20:57 +00003504
3505 status = pjsua_call_update(call_id, option, &msg_data);
3506
3507 if (pool)
3508 pj_pool_release(pool);
3509
3510 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003511}
3512
3513/*
3514 * py_pjsua_call_send_request
3515 */
Benny Prijono55040452008-07-21 18:20:57 +00003516static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003517{
3518 int status;
3519 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003520 PyObject *pMethod;
Benny Prijono9c461142008-07-10 22:41:20 +00003521 pj_str_t method;
3522 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003523 PyObject *omdObj;
3524 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003525
3526 PJ_UNUSED_ARG(pSelf);
3527
Benny Prijono55040452008-07-21 18:20:57 +00003528 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003529 return NULL;
3530 }
3531
Benny Prijono55040452008-07-21 18:20:57 +00003532 if (!PyString_Check(pMethod)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003533 return NULL;
3534 }
3535
Benny Prijono55040452008-07-21 18:20:57 +00003536 method = PyString_ToPJ(pMethod);
3537 pjsua_msg_data_init(&msg_data);
Benny Prijono9c461142008-07-10 22:41:20 +00003538
Benny Prijono55040452008-07-21 18:20:57 +00003539 if (omdObj != Py_None) {
3540 PyObj_pjsua_msg_data *omd;
3541
Benny Prijono9c461142008-07-10 22:41:20 +00003542 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003543 msg_data.content_type = PyString_ToPJ(omd->content_type);
3544 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3545 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003546 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003547 }
Benny Prijono55040452008-07-21 18:20:57 +00003548
3549 status = pjsua_call_send_request(call_id, &method, &msg_data);
3550
3551 if (pool)
3552 pj_pool_release(pool);
3553
3554 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003555}
3556
3557/*
3558 * py_pjsua_call_xfer
3559 */
Benny Prijono55040452008-07-21 18:20:57 +00003560static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003561{
3562 int status;
3563 int call_id;
3564 pj_str_t dest;
Benny Prijono55040452008-07-21 18:20:57 +00003565 PyObject *pDstUri;
Benny Prijono9c461142008-07-10 22:41:20 +00003566 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003567 PyObject *omdObj;
3568 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003569
3570 PJ_UNUSED_ARG(pSelf);
3571
Benny Prijono55040452008-07-21 18:20:57 +00003572 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003573 return NULL;
3574 }
Benny Prijono55040452008-07-21 18:20:57 +00003575
3576 if (!PyString_Check(pDstUri))
3577 return NULL;
3578
3579 dest = PyString_ToPJ(pDstUri);
3580 pjsua_msg_data_init(&msg_data);
3581
3582 if (omdObj != Py_None) {
3583 PyObj_pjsua_msg_data *omd;
3584
Benny Prijono9c461142008-07-10 22:41:20 +00003585 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003586 msg_data.content_type = PyString_ToPJ(omd->content_type);
3587 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3588 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003589 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003590 }
Benny Prijono55040452008-07-21 18:20:57 +00003591
3592 status = pjsua_call_xfer(call_id, &dest, &msg_data);
3593
3594 if (pool)
3595 pj_pool_release(pool);
3596
3597 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003598}
3599
3600/*
3601 * py_pjsua_call_xfer_replaces
3602 */
Benny Prijono55040452008-07-21 18:20:57 +00003603static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003604{
3605 int status;
3606 int call_id;
3607 int dest_call_id;
3608 unsigned options;
3609 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003610 PyObject *omdObj;
3611 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003612
3613 PJ_UNUSED_ARG(pSelf);
3614
Benny Prijono55040452008-07-21 18:20:57 +00003615 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id,
3616 &options, &omdObj))
Benny Prijono9c461142008-07-10 22:41:20 +00003617 {
3618 return NULL;
3619 }
Benny Prijono55040452008-07-21 18:20:57 +00003620
3621 pjsua_msg_data_init(&msg_data);
3622
3623 if (omdObj != Py_None) {
3624 PyObj_pjsua_msg_data *omd;
3625
3626 omd = (PyObj_pjsua_msg_data *)omdObj;
3627 msg_data.content_type = PyString_ToPJ(omd->content_type);
3628 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3629 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003630 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003631 }
Benny Prijono55040452008-07-21 18:20:57 +00003632
3633 status = pjsua_call_xfer_replaces(call_id, dest_call_id, options,
3634 &msg_data);
3635
3636 if (pool)
3637 pj_pool_release(pool);
3638
3639 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003640}
3641
3642/*
3643 * py_pjsua_call_dial_dtmf
3644 */
Benny Prijono55040452008-07-21 18:20:57 +00003645static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003646{
3647 int call_id;
Benny Prijono55040452008-07-21 18:20:57 +00003648 PyObject *pDigits;
Benny Prijono9c461142008-07-10 22:41:20 +00003649 pj_str_t digits;
3650 int status;
3651
3652 PJ_UNUSED_ARG(pSelf);
3653
Benny Prijono55040452008-07-21 18:20:57 +00003654 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003655 return NULL;
Benny Prijono55040452008-07-21 18:20:57 +00003656 }
3657
3658 if (!PyString_Check(pDigits))
3659 return Py_BuildValue("i", PJ_EINVAL);
3660
3661 digits = PyString_ToPJ(pDigits);
Benny Prijono9c461142008-07-10 22:41:20 +00003662 status = pjsua_call_dial_dtmf(call_id, &digits);
3663
3664 return Py_BuildValue("i", status);
3665}
3666
3667/*
3668 * py_pjsua_call_send_im
3669 */
Benny Prijono55040452008-07-21 18:20:57 +00003670static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003671{
3672 int status;
3673 int call_id;
3674 pj_str_t content;
3675 pj_str_t * mime_type, tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00003676 PyObject *pMimeType, *pContent, *omdObj;
Benny Prijono9c461142008-07-10 22:41:20 +00003677 pjsua_msg_data msg_data;
Benny Prijono9c461142008-07-10 22:41:20 +00003678 int user_data;
Benny Prijono55040452008-07-21 18:20:57 +00003679 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003680
3681 PJ_UNUSED_ARG(pSelf);
3682
Benny Prijono55040452008-07-21 18:20:57 +00003683 if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent,
3684 &omdObj, &user_data))
Benny Prijono9c461142008-07-10 22:41:20 +00003685 {
3686 return NULL;
3687 }
Benny Prijono55040452008-07-21 18:20:57 +00003688
3689 if (!PyString_Check(pContent))
3690 return Py_BuildValue("i", PJ_EINVAL);
3691
3692 content = PyString_ToPJ(pContent);
3693
3694 if (PyString_Check(pMimeType)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003695 mime_type = &tmp_mime_type;
Benny Prijono55040452008-07-21 18:20:57 +00003696 tmp_mime_type = PyString_ToPJ(pMimeType);
Benny Prijono9c461142008-07-10 22:41:20 +00003697 } else {
Benny Prijono55040452008-07-21 18:20:57 +00003698 mime_type = NULL;
3699 }
3700
3701 pjsua_msg_data_init(&msg_data);
3702 if (omdObj != Py_None) {
3703 PyObj_pjsua_msg_data * omd;
3704
3705 omd = (PyObj_pjsua_msg_data *)omdObj;
3706 msg_data.content_type = PyString_ToPJ(omd->content_type);
3707 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3708 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
3709 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003710 }
3711
Benny Prijono55040452008-07-21 18:20:57 +00003712 status = pjsua_call_send_im(call_id, mime_type, &content,
Benny Prijonocae95fc2010-10-21 02:22:41 +00003713 &msg_data, (void*)(long)user_data);
Benny Prijono55040452008-07-21 18:20:57 +00003714
3715 if (pool)
3716 pj_pool_release(pool);
3717
3718 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003719}
3720
3721/*
3722 * py_pjsua_call_send_typing_ind
3723 */
Benny Prijono55040452008-07-21 18:20:57 +00003724static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf,
3725 PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003726{
3727 int status;
3728 int call_id;
3729 int is_typing;
3730 pjsua_msg_data msg_data;
Benny Prijono55040452008-07-21 18:20:57 +00003731 PyObject *omdObj;
3732 pj_pool_t *pool = NULL;
Benny Prijono9c461142008-07-10 22:41:20 +00003733
3734 PJ_UNUSED_ARG(pSelf);
3735
Benny Prijono55040452008-07-21 18:20:57 +00003736 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003737 return NULL;
3738 }
3739
Benny Prijono55040452008-07-21 18:20:57 +00003740 pjsua_msg_data_init(&msg_data);
3741 if (omdObj != Py_None) {
3742 PyObj_pjsua_msg_data *omd;
3743
Benny Prijono9c461142008-07-10 22:41:20 +00003744 omd = (PyObj_pjsua_msg_data *)omdObj;
Benny Prijono55040452008-07-21 18:20:57 +00003745 msg_data.content_type = PyString_ToPJ(omd->content_type);
3746 msg_data.msg_body = PyString_ToPJ(omd->msg_body);
3747 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE);
Benny Prijono9c461142008-07-10 22:41:20 +00003748 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Benny Prijono9c461142008-07-10 22:41:20 +00003749 }
Benny Prijono55040452008-07-21 18:20:57 +00003750
3751 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
3752
3753 if (pool)
3754 pj_pool_release(pool);
3755
3756 return Py_BuildValue("i", status);
Benny Prijono9c461142008-07-10 22:41:20 +00003757}
3758
3759/*
3760 * py_pjsua_call_hangup_all
3761 */
Benny Prijono55040452008-07-21 18:20:57 +00003762static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003763{
Benny Prijono9c461142008-07-10 22:41:20 +00003764 PJ_UNUSED_ARG(pSelf);
Benny Prijono55040452008-07-21 18:20:57 +00003765 PJ_UNUSED_ARG(pArgs);
Benny Prijono9c461142008-07-10 22:41:20 +00003766
Benny Prijono9c461142008-07-10 22:41:20 +00003767 pjsua_call_hangup_all();
3768
Benny Prijono55040452008-07-21 18:20:57 +00003769 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003770}
3771
3772/*
3773 * py_pjsua_call_dump
3774 */
Benny Prijono55040452008-07-21 18:20:57 +00003775static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs)
Benny Prijono9c461142008-07-10 22:41:20 +00003776{
3777 int call_id;
3778 int with_media;
Benny Prijono55040452008-07-21 18:20:57 +00003779 PyObject *ret;
3780 PyObject *pIndent;
3781 char *buffer;
3782 char *indent;
Benny Prijono9c461142008-07-10 22:41:20 +00003783 unsigned maxlen;
3784 int status;
3785
3786 PJ_UNUSED_ARG(pSelf);
3787
Benny Prijono55040452008-07-21 18:20:57 +00003788 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media,
3789 &maxlen, &pIndent))
Benny Prijono9c461142008-07-10 22:41:20 +00003790 {
3791 return NULL;
3792 }
Benny Prijono55040452008-07-21 18:20:57 +00003793
3794 buffer = (char*) malloc(maxlen * sizeof(char));
3795 indent = PyString_AsString(pIndent);
Benny Prijono9c461142008-07-10 22:41:20 +00003796
3797 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
Benny Prijono55040452008-07-21 18:20:57 +00003798 if (status != PJ_SUCCESS) {
3799 free(buffer);
3800 return PyString_FromString("");
3801 }
3802
3803 ret = PyString_FromString(buffer);
Benny Prijono9c461142008-07-10 22:41:20 +00003804 free(buffer);
Benny Prijono55040452008-07-21 18:20:57 +00003805 return (PyObject*)ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003806}
3807
3808
3809/*
3810 * py_pjsua_dump
3811 * Dump application states.
3812 */
3813static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
3814{
Benny Prijono9c461142008-07-10 22:41:20 +00003815 int detail;
3816
3817 PJ_UNUSED_ARG(pSelf);
3818
Benny Prijono55040452008-07-21 18:20:57 +00003819 if (!PyArg_ParseTuple(pArgs, "i", &detail)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003820 return NULL;
3821 }
3822
Benny Prijono55040452008-07-21 18:20:57 +00003823 pjsua_dump(detail);
Benny Prijono9c461142008-07-10 22:41:20 +00003824
Benny Prijono55040452008-07-21 18:20:57 +00003825 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003826}
3827
3828
3829/*
3830 * py_pj_strerror
3831 */
3832static PyObject *py_pj_strerror(PyObject *pSelf, PyObject *pArgs)
3833{
3834 int err;
3835 char err_msg[PJ_ERR_MSG_SIZE];
Benny Prijono55040452008-07-21 18:20:57 +00003836 pj_str_t ret;
Benny Prijono9c461142008-07-10 22:41:20 +00003837
3838 PJ_UNUSED_ARG(pSelf);
3839
Benny Prijono55040452008-07-21 18:20:57 +00003840 if (!PyArg_ParseTuple(pArgs, "i", &err)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003841 return NULL;
3842 }
3843
Benny Prijono55040452008-07-21 18:20:57 +00003844 ret = pj_strerror(err, err_msg, sizeof(err_msg));
Benny Prijono9c461142008-07-10 22:41:20 +00003845
Benny Prijono55040452008-07-21 18:20:57 +00003846 return PyString_FromStringAndSize(err_msg, ret.slen);
Benny Prijono9c461142008-07-10 22:41:20 +00003847}
3848
3849
3850/*
3851 * py_pj_parse_simple_sip
3852 */
3853static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs)
3854{
Benny Prijono55040452008-07-21 18:20:57 +00003855 const char *arg_uri;
Benny Prijono9c461142008-07-10 22:41:20 +00003856 pj_pool_t *pool;
3857 char tmp[PJSIP_MAX_URL_SIZE];
3858 pjsip_uri *uri;
3859 pjsip_sip_uri *sip_uri;
3860 PyObject *ret, *item;
3861
3862 PJ_UNUSED_ARG(pSelf);
3863
Benny Prijono55040452008-07-21 18:20:57 +00003864 if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) {
Benny Prijono9c461142008-07-10 22:41:20 +00003865 return NULL;
3866 }
3867
Benny Prijono55040452008-07-21 18:20:57 +00003868 strncpy(tmp, arg_uri, sizeof(tmp));
Benny Prijono9c461142008-07-10 22:41:20 +00003869 tmp[sizeof(tmp)-1] = '\0';
3870
3871 pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512);
3872 uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0);
3873
3874 if (uri == NULL || (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
3875 !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
3876 pj_pool_release(pool);
Benny Prijono55040452008-07-21 18:20:57 +00003877 return Py_BuildValue("");
Benny Prijono9c461142008-07-10 22:41:20 +00003878 }
3879
3880 ret = PyTuple_New(5);
3881 sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri);
3882
3883 /* Scheme */
Benny Prijono55040452008-07-21 18:20:57 +00003884 item = PyString_FromPJ(pjsip_uri_get_scheme(uri));
Benny Prijono9c461142008-07-10 22:41:20 +00003885 PyTuple_SetItem(ret, 0, item);
3886
3887 /* Username */
Benny Prijono55040452008-07-21 18:20:57 +00003888 item = PyString_FromPJ(&sip_uri->user);
Benny Prijono9c461142008-07-10 22:41:20 +00003889 PyTuple_SetItem(ret, 1, item);
3890
3891 /* Host */
Benny Prijono55040452008-07-21 18:20:57 +00003892 item = PyString_FromPJ(&sip_uri->host);
Benny Prijono9c461142008-07-10 22:41:20 +00003893 PyTuple_SetItem(ret, 2, item);
3894
3895 /* Port */
3896 if (sip_uri->port == 5060) {
3897 sip_uri->port = 0;
3898 }
3899 item = Py_BuildValue("i", sip_uri->port);
3900 PyTuple_SetItem(ret, 3, item);
3901
3902 /* Transport */
3903 if (pj_stricmp2(&sip_uri->transport_param, "udp")) {
3904 sip_uri->transport_param.ptr = "";
3905 sip_uri->transport_param.slen = 0;
3906 }
Benny Prijono55040452008-07-21 18:20:57 +00003907 item = PyString_FromPJ(&sip_uri->transport_param);
Benny Prijono9c461142008-07-10 22:41:20 +00003908 PyTuple_SetItem(ret, 4, item);
3909
Benny Prijono16639d92009-11-10 10:06:58 +00003910 pj_pool_release(pool);
Benny Prijono9c461142008-07-10 22:41:20 +00003911 return ret;
3912}
3913
3914
3915static char pjsua_call_get_max_count_doc[] =
3916 "int _pjsua.call_get_max_count () "
3917 "Get maximum number of calls configured in pjsua.";
3918static char pjsua_call_get_count_doc[] =
3919 "int _pjsua.call_get_count () "
3920 "Get number of currently active calls.";
3921static char pjsua_enum_calls_doc[] =
3922 "int[] _pjsua.enum_calls () "
3923 "Get maximum number of calls configured in pjsua.";
3924static char pjsua_call_make_call_doc[] =
3925 "int,int _pjsua.call_make_call (int acc_id, string dst_uri, int options,"
3926 "int user_data, _pjsua.Msg_Data msg_data) "
3927 "Make outgoing call to the specified URI using the specified account.";
3928static char pjsua_call_is_active_doc[] =
3929 "int _pjsua.call_is_active (int call_id) "
3930 "Check if the specified call has active INVITE session and the INVITE "
3931 "session has not been disconnected.";
3932static char pjsua_call_has_media_doc[] =
3933 "int _pjsua.call_has_media (int call_id) "
3934 "Check if call has an active media session.";
3935static char pjsua_call_get_conf_port_doc[] =
3936 "int _pjsua.call_get_conf_port (int call_id) "
3937 "Get the conference port identification associated with the call.";
3938static char pjsua_call_get_info_doc[] =
3939 "_pjsua.Call_Info _pjsua.call_get_info (int call_id) "
3940 "Obtain detail information about the specified call.";
3941static char pjsua_call_set_user_data_doc[] =
3942 "int _pjsua.call_set_user_data (int call_id, int user_data) "
3943 "Attach application specific data to the call.";
3944static char pjsua_call_get_user_data_doc[] =
3945 "int _pjsua.call_get_user_data (int call_id) "
3946 "Get user data attached to the call.";
3947static char pjsua_call_answer_doc[] =
3948 "int _pjsua.call_answer (int call_id, int code, string reason, "
3949 "_pjsua.Msg_Data msg_data) "
3950 "Send response to incoming INVITE request.";
3951static char pjsua_call_hangup_doc[] =
3952 "int _pjsua.call_hangup (int call_id, int code, string reason, "
3953 "_pjsua.Msg_Data msg_data) "
3954 "Hangup call by using method that is appropriate according "
3955 "to the call state.";
3956static char pjsua_call_set_hold_doc[] =
3957 "int _pjsua.call_set_hold (int call_id, _pjsua.Msg_Data msg_data) "
3958 "Put the specified call on hold.";
3959static char pjsua_call_reinvite_doc[] =
3960 "int _pjsua.call_reinvite (int call_id, int unhold, "
3961 "_pjsua.Msg_Data msg_data) "
3962 "Send re-INVITE (to release hold).";
3963static char pjsua_call_xfer_doc[] =
3964 "int _pjsua.call_xfer (int call_id, string dest, "
3965 "_pjsua.Msg_Data msg_data) "
3966 "Initiate call transfer to the specified address. "
3967 "This function will send REFER request to instruct remote call party "
3968 "to initiate a new INVITE session to the specified destination/target.";
3969static char pjsua_call_xfer_replaces_doc[] =
3970 "int _pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
3971 "int options, _pjsua.Msg_Data msg_data) "
3972 "Initiate attended call transfer. This function will send REFER request "
3973 "to instruct remote call party to initiate new INVITE session to the URL "
3974 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
3975 "with us with the new call from the REFER recipient.";
3976static char pjsua_call_dial_dtmf_doc[] =
3977 "int _pjsua.call_dial_dtmf (int call_id, string digits) "
3978 "Send DTMF digits to remote using RFC 2833 payload formats.";
3979static char pjsua_call_send_im_doc[] =
3980 "int _pjsua.call_send_im (int call_id, string mime_type, string content,"
3981 "_pjsua.Msg_Data msg_data, int user_data) "
3982 "Send instant messaging inside INVITE session.";
3983static char pjsua_call_send_typing_ind_doc[] =
3984 "int _pjsua.call_send_typing_ind (int call_id, int is_typing, "
3985 "_pjsua.Msg_Data msg_data) "
3986 "Send IM typing indication inside INVITE session.";
3987static char pjsua_call_hangup_all_doc[] =
3988 "void _pjsua.call_hangup_all () "
3989 "Terminate all calls.";
3990static char pjsua_call_dump_doc[] =
3991 "int _pjsua.call_dump (int call_id, int with_media, int maxlen, "
3992 "string indent) "
3993 "Dump call and media statistics to string.";
3994
3995/* END OF LIB CALL */
3996
3997/*
3998 * Map of function names to functions
3999 */
4000static PyMethodDef py_pjsua_methods[] =
4001{
4002 {
4003 "thread_register", py_pjsua_thread_register, METH_VARARGS,
4004 pjsua_thread_register_doc
4005 },
4006 {
4007 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
4008 },
4009 {
4010 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
4011 },
4012 {
4013 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
4014 },
4015 {
4016 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
4017 },
4018 {
4019 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
4020 },
4021 {
4022 "handle_events", py_pjsua_handle_events, METH_VARARGS,
4023 pjsua_handle_events_doc
4024 },
4025 {
4026 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
4027 pjsua_verify_sip_url_doc
4028 },
4029 {
Benny Prijono9c461142008-07-10 22:41:20 +00004030 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
4031 pjsua_reconfigure_logging_doc
4032 },
4033 {
4034 "logging_config_default", py_pjsua_logging_config_default,
4035 METH_VARARGS, pjsua_logging_config_default_doc
4036 },
4037 {
4038 "config_default", py_pjsua_config_default, METH_VARARGS,
4039 pjsua_config_default_doc
4040 },
4041 {
4042 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
4043 pjsua_media_config_default_doc
4044 },
4045
4046
4047 {
4048 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
4049 pjsua_msg_data_init_doc
4050 },
4051 {
4052 "transport_config_default", py_pjsua_transport_config_default,
4053 METH_VARARGS,pjsua_transport_config_default_doc
4054 },
4055 {
4056 "transport_create", py_pjsua_transport_create, METH_VARARGS,
4057 pjsua_transport_create_doc
4058 },
4059 {
4060 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
4061 pjsua_enum_transports_doc
4062 },
4063 {
4064 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
4065 pjsua_transport_get_info_doc
4066 },
4067 {
4068 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
4069 pjsua_transport_set_enable_doc
4070 },
4071 {
4072 "transport_close", py_pjsua_transport_close, METH_VARARGS,
4073 pjsua_transport_close_doc
4074 },
4075 {
4076 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
4077 pjsua_acc_config_default_doc
4078 },
4079 {
4080 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
4081 pjsua_acc_get_count_doc
4082 },
4083 {
4084 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
4085 pjsua_acc_is_valid_doc
4086 },
4087 {
4088 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
4089 pjsua_acc_set_default_doc
4090 },
4091 {
4092 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
4093 pjsua_acc_get_default_doc
4094 },
4095 {
4096 "acc_add", py_pjsua_acc_add, METH_VARARGS,
4097 pjsua_acc_add_doc
4098 },
4099 {
4100 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
4101 pjsua_acc_add_local_doc
4102 },
4103 {
4104 "acc_del", py_pjsua_acc_del, METH_VARARGS,
4105 pjsua_acc_del_doc
4106 },
4107 {
Benny Prijono55040452008-07-21 18:20:57 +00004108 "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS,
4109 "Accociate user data with the account"
4110 },
4111 {
4112 "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS,
4113 "Get account's user data"
4114 },
4115 {
Benny Prijono9c461142008-07-10 22:41:20 +00004116 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
4117 pjsua_acc_modify_doc
4118 },
4119 {
4120 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
4121 pjsua_acc_set_online_status_doc
4122 },
4123 {
4124 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
4125 pjsua_acc_set_online_status2_doc
4126 },
4127 {
4128 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
4129 pjsua_acc_set_registration_doc
4130 },
4131 {
4132 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
4133 pjsua_acc_get_info_doc
4134 },
4135 {
Benny Prijonoe6787ec2008-07-18 23:00:56 +00004136 "acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS,
4137 "Accept or reject subscription request"
4138 },
4139 {
Benny Prijono9c461142008-07-10 22:41:20 +00004140 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
4141 pjsua_enum_accs_doc
4142 },
4143 {
4144 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
4145 pjsua_acc_enum_info_doc
4146 },
4147 {
Benny Prijono9c461142008-07-10 22:41:20 +00004148 "acc_set_transport", py_pjsua_acc_set_transport, METH_VARARGS,
4149 "Lock transport to use the specified transport"
4150 },
4151 {
4152 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
4153 pjsua_buddy_config_default_doc
4154 },
4155 {
4156 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
4157 pjsua_get_buddy_count_doc
4158 },
4159 {
4160 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
4161 pjsua_buddy_is_valid_doc
4162 },
4163 {
4164 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
4165 pjsua_enum_buddies_doc
4166 },
4167 {
Benny Prijono55040452008-07-21 18:20:57 +00004168 "buddy_find", py_pjsua_buddy_find, METH_VARARGS,
4169 "Find buddy with the specified URI"
4170 },
4171 {
Benny Prijono9c461142008-07-10 22:41:20 +00004172 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
4173 pjsua_buddy_get_info_doc
4174 },
4175 {
4176 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
4177 pjsua_buddy_add_doc
4178 },
4179 {
4180 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
4181 pjsua_buddy_del_doc
4182 },
4183 {
Benny Prijono55040452008-07-21 18:20:57 +00004184 "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS,
4185 "Associate user data to the buddy object"
4186 },
4187 {
4188 "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS,
4189 "Get buddy user data"
4190 },
4191 {
Benny Prijono9c461142008-07-10 22:41:20 +00004192 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
4193 pjsua_buddy_subscribe_pres_doc
4194 },
4195 {
4196 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
4197 pjsua_pres_dump_doc
4198 },
4199 {
4200 "im_send", py_pjsua_im_send, METH_VARARGS,
4201 pjsua_im_send_doc
4202 },
4203 {
4204 "im_typing", py_pjsua_im_typing, METH_VARARGS,
4205 pjsua_im_typing_doc
4206 },
4207 {
4208 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
4209 pjsua_conf_get_max_ports_doc
4210 },
4211 {
4212 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
4213 pjsua_conf_get_active_ports_doc
4214 },
4215 {
4216 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
4217 pjsua_enum_conf_ports_doc
4218 },
4219 {
4220 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
4221 pjsua_conf_get_port_info_doc
4222 },
4223 {
Benny Prijono9c461142008-07-10 22:41:20 +00004224 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
4225 pjsua_conf_remove_port_doc
4226 },
4227 {
4228 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
4229 pjsua_conf_connect_doc
4230 },
4231 {
4232 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
4233 pjsua_conf_disconnect_doc
4234 },
4235 {
Benny Prijono288d4bd2008-07-19 15:40:21 +00004236 "conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS,
4237 "Adjust the signal level to be transmitted from the bridge to the"
4238 " specified port by making it louder or quieter"
4239 },
4240 {
4241 "conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS,
4242 "Adjust the signal level to be received from the specified port (to"
4243 " the bridge) by making it louder or quieter"
4244 },
4245 {
4246 "conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS,
4247 "Get last signal level transmitted to or received from the specified port"
4248 },
4249 {
Benny Prijono9c461142008-07-10 22:41:20 +00004250 "player_create", py_pjsua_player_create, METH_VARARGS,
4251 pjsua_player_create_doc
4252 },
4253 {
Benny Prijono288d4bd2008-07-19 15:40:21 +00004254 "playlist_create", py_pjsua_playlist_create, METH_VARARGS,
4255 "Create WAV playlist"
4256 },
4257 {
Benny Prijono9c461142008-07-10 22:41:20 +00004258 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
4259 pjsua_player_get_conf_port_doc
4260 },
4261 {
4262 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
4263 pjsua_player_set_pos_doc
4264 },
4265 {
4266 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
4267 pjsua_player_destroy_doc
4268 },
4269 {
4270 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
4271 pjsua_recorder_create_doc
4272 },
4273 {
4274 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
4275 pjsua_recorder_get_conf_port_doc
4276 },
4277 {
4278 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
4279 pjsua_recorder_destroy_doc
4280 },
4281 {
4282 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
4283 pjsua_enum_snd_devs_doc
4284 },
4285 {
4286 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
4287 pjsua_get_snd_dev_doc
4288 },
4289 {
4290 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
4291 pjsua_set_snd_dev_doc
4292 },
4293 {
4294 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
4295 pjsua_set_null_snd_dev_doc
4296 },
4297 {
Benny Prijono9c461142008-07-10 22:41:20 +00004298 "set_ec", py_pjsua_set_ec, METH_VARARGS,
4299 pjsua_set_ec_doc
4300 },
4301 {
4302 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
4303 pjsua_get_ec_tail_doc
4304 },
4305 {
4306 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
4307 pjsua_enum_codecs_doc
4308 },
4309 {
4310 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
4311 pjsua_codec_set_priority_doc
4312 },
4313 {
4314 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
4315 pjsua_codec_get_param_doc
4316 },
4317 {
4318 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
4319 pjsua_codec_set_param_doc
4320 },
4321 {
4322 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
4323 pjsua_call_get_max_count_doc
4324 },
4325 {
4326 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
4327 pjsua_call_get_count_doc
4328 },
4329 {
4330 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
4331 pjsua_enum_calls_doc
4332 },
4333 {
4334 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
4335 pjsua_call_make_call_doc
4336 },
4337 {
4338 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
4339 pjsua_call_is_active_doc
4340 },
4341 {
4342 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
4343 pjsua_call_has_media_doc
4344 },
4345 {
4346 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
4347 pjsua_call_get_conf_port_doc
4348 },
4349 {
4350 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
4351 pjsua_call_get_info_doc
4352 },
4353 {
4354 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
4355 pjsua_call_set_user_data_doc
4356 },
4357 {
4358 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
4359 pjsua_call_get_user_data_doc
4360 },
4361 {
4362 "call_answer", py_pjsua_call_answer, METH_VARARGS,
4363 pjsua_call_answer_doc
4364 },
4365 {
4366 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
4367 pjsua_call_hangup_doc
4368 },
4369 {
4370 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
4371 pjsua_call_set_hold_doc
4372 },
4373 {
4374 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
4375 pjsua_call_reinvite_doc
4376 },
4377 {
4378 "call_update", py_pjsua_call_update, METH_VARARGS,
4379 "Send UPDATE"
4380 },
4381 {
4382 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
4383 pjsua_call_xfer_doc
4384 },
4385 {
4386 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
4387 pjsua_call_xfer_replaces_doc
4388 },
4389 {
4390 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
4391 pjsua_call_dial_dtmf_doc
4392 },
4393 {
4394 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
4395 pjsua_call_send_im_doc
4396 },
4397 {
4398 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
4399 pjsua_call_send_typing_ind_doc
4400 },
4401 {
4402 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
4403 pjsua_call_hangup_all_doc
4404 },
4405 {
4406 "call_dump", py_pjsua_call_dump, METH_VARARGS,
4407 pjsua_call_dump_doc
4408 },
4409 {
4410 "call_send_request", py_pjsua_call_send_request, METH_VARARGS,
4411 "Send arbitrary request"
4412 },
4413 {
4414 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
4415 },
4416 {
4417 "strerror", py_pj_strerror, METH_VARARGS, "Get error message"
4418 },
4419 {
4420 "parse_simple_uri", py_pj_parse_simple_sip, METH_VARARGS, "Parse URI"
4421 },
4422
4423
4424 {NULL, NULL} /* end of function list */
4425};
4426
4427
4428
4429/*
4430 * Mapping C structs from and to Python objects & initializing object
4431 */
4432DL_EXPORT(void)
4433init_pjsua(void)
4434{
4435 PyObject* m = NULL;
4436#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
4437
4438
4439 PyEval_InitThreads();
4440
4441 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
4442 return;
4443 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
4444 return;
4445 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
4446 return;
4447 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
4448 return;
4449 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
4450 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
4451 return;
Benny Prijono9c461142008-07-10 22:41:20 +00004452 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
4453 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
4454 return;
4455
4456 /* LIB TRANSPORT */
4457
4458 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
4459 return;
4460
4461 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
4462 return;
4463
4464 /* END OF LIB TRANSPORT */
4465
4466 /* LIB ACCOUNT */
4467
4468
4469 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
4470 return;
4471 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
4472 return;
4473
4474 /* END OF LIB ACCOUNT */
4475
4476 /* LIB BUDDY */
4477
4478 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
4479 return;
4480 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
4481 return;
4482
4483 /* END OF LIB BUDDY */
4484
4485 /* LIB MEDIA */
4486
4487 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
4488 return;
4489
4490 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
4491 return;
4492
Benny Prijono9c461142008-07-10 22:41:20 +00004493 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
4494 return;
4495
4496 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
4497 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
4498 return;
4499 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
4500 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
4501 return;
4502
4503 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
4504 return;
4505
4506 /* END OF LIB MEDIA */
4507
4508 /* LIB CALL */
4509
Benny Prijono9c461142008-07-10 22:41:20 +00004510 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
4511 return;
4512
4513 /* END OF LIB CALL */
4514
4515 m = Py_InitModule3(
Benny Prijono55040452008-07-21 18:20:57 +00004516 "_pjsua", py_pjsua_methods, "PJSUA-lib module for python"
Benny Prijono9c461142008-07-10 22:41:20 +00004517 );
4518
4519 Py_INCREF(&PyTyp_pjsua_callback);
4520 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
4521
4522 Py_INCREF(&PyTyp_pjsua_config);
4523 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
4524
4525 Py_INCREF(&PyTyp_pjsua_media_config);
4526 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
4527
4528 Py_INCREF(&PyTyp_pjsua_logging_config);
4529 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
4530
4531 Py_INCREF(&PyTyp_pjsua_msg_data);
4532 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
4533
Benny Prijono9c461142008-07-10 22:41:20 +00004534 Py_INCREF(&PyTyp_pjsip_cred_info);
4535 PyModule_AddObject(m, "Pjsip_Cred_Info",
4536 (PyObject *)&PyTyp_pjsip_cred_info
4537 );
4538
4539 /* LIB TRANSPORT */
4540
4541 Py_INCREF(&PyTyp_pjsua_transport_config);
4542 PyModule_AddObject
4543 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
4544
4545 Py_INCREF(&PyTyp_pjsua_transport_info);
4546 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
4547
4548
4549 /* END OF LIB TRANSPORT */
4550
4551 /* LIB ACCOUNT */
4552
4553
4554 Py_INCREF(&PyTyp_pjsua_acc_config);
4555 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
4556 Py_INCREF(&PyTyp_pjsua_acc_info);
4557 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
4558
4559 /* END OF LIB ACCOUNT */
4560
4561 /* LIB BUDDY */
4562
4563 Py_INCREF(&PyTyp_pjsua_buddy_config);
4564 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
4565 Py_INCREF(&PyTyp_pjsua_buddy_info);
4566 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
4567
4568 /* END OF LIB BUDDY */
4569
4570 /* LIB MEDIA */
4571
4572 Py_INCREF(&PyTyp_pjsua_codec_info);
4573 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
4574 Py_INCREF(&PyTyp_pjsua_conf_port_info);
4575 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
Benny Prijono9c461142008-07-10 22:41:20 +00004576 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
4577 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
4578 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
4579 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
4580 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
4581 (PyObject *)&PyTyp_pjmedia_codec_param_info);
4582 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
4583 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
4584 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
4585 Py_INCREF(&PyTyp_pjmedia_codec_param);
4586 PyModule_AddObject(m, "PJMedia_Codec_Param",
4587 (PyObject *)&PyTyp_pjmedia_codec_param);
4588
4589 /* END OF LIB MEDIA */
4590
4591 /* LIB CALL */
4592
Benny Prijono9c461142008-07-10 22:41:20 +00004593 Py_INCREF(&PyTyp_pjsua_call_info);
4594 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
4595
4596 /* END OF LIB CALL */
4597
4598
4599 /*
4600 * Add various constants.
4601 */
Benny Prijono55040452008-07-21 18:20:57 +00004602 /* Skip it.. */
Benny Prijono9c461142008-07-10 22:41:20 +00004603
4604#undef ADD_CONSTANT
4605}