blob: e5cb6cafe1bc6c40b78bdcb05cf7882a90e7f397 [file] [log] [blame]
Benny Prijono572d4852006-11-23 21:50:02 +00001/* $Id$ */
2/*
Benny Prijonoaa286042007-02-03 17:23:22 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono572d4852006-11-23 21:50:02 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
Benny Prijono8b8b9972006-11-16 11:18:03 +000019#include <Python.h>
Benny Prijono572d4852006-11-23 21:50:02 +000020#include "structmember.h"
Benny Prijono8b8b9972006-11-16 11:18:03 +000021#include <pjsua-lib/pjsua.h>
22
Benny Prijono572d4852006-11-23 21:50:02 +000023#define THIS_FILE "main.c"
Fahris6f35cb82007-02-01 07:41:26 +000024#define POOL_SIZE 4000
25#define SND_DEV_NUM 64
Fahrise314b882007-02-02 10:52:04 +000026#define SND_NAME_LEN 64
Benny Prijono8b8b9972006-11-16 11:18:03 +000027
Benny Prijono98793592006-12-04 08:33:20 +000028/* LIB BASE */
29
Benny Prijono572d4852006-11-23 21:50:02 +000030static PyObject* obj_reconfigure_logging;
31static PyObject* obj_logging_init;
Benny Prijonoed7a5a72007-01-29 18:36:38 +000032static long thread_id;
Benny Prijono572d4852006-11-23 21:50:02 +000033
34/*
35 * cb_reconfigure_logging
36 * declares method for reconfiguring logging process for callback struct
37 */
38static void cb_reconfigure_logging(int level, const char *data, pj_size_t len)
39{
Fahris17d91812007-01-29 12:09:33 +000040
Benny Prijono572d4852006-11-23 21:50:02 +000041 if (PyCallable_Check(obj_reconfigure_logging))
42 {
43 PyObject_CallFunctionObjArgs(
44 obj_reconfigure_logging, Py_BuildValue("i",level),
45 PyString_FromString(data), Py_BuildValue("i",len), NULL
46 );
47 }
Benny Prijono8b8b9972006-11-16 11:18:03 +000048}
49
Benny Prijono8b8b9972006-11-16 11:18:03 +000050
Benny Prijono572d4852006-11-23 21:50:02 +000051/*
52 * cb_logging_init
53 * declares method logging_init for callback struct
54 */
55static void cb_logging_init(int level, const char *data, pj_size_t len)
56{
Benny Prijonoed7a5a72007-01-29 18:36:38 +000057 /* Ignore if this callback is called from alien thread context,
58 * or otherwise it will crash Python.
59 */
60 if (pj_thread_local_get(thread_id) == 0)
61 return;
62
Benny Prijono572d4852006-11-23 21:50:02 +000063 if (PyCallable_Check(obj_logging_init))
64 {
Fahris89ea3d02007-02-07 08:18:35 +000065
Benny Prijono572d4852006-11-23 21:50:02 +000066 PyObject_CallFunctionObjArgs(
67 obj_logging_init, Py_BuildValue("i",level),
68 PyString_FromString(data), Py_BuildValue("i",len), NULL
69 );
70 }
71}
72
73
74/*
75 * pjsip_event_Object
76 * C/python typewrapper for event struct
77 */
78typedef struct
79{
80 PyObject_HEAD
81 /* Type-specific fields go here. */
82 pjsip_event * event;
83} pjsip_event_Object;
84
85
86/*
87 * pjsip_event_Type
88 * event struct signatures
89 */
90static PyTypeObject pjsip_event_Type =
91{
92 PyObject_HEAD_INIT(NULL)
93 0, /*ob_size*/
94 "py_pjsua.PJSIP_Event", /*tp_name*/
95 sizeof(pjsip_event_Object), /*tp_basicsize*/
96 0, /*tp_itemsize*/
97 0, /*tp_dealloc*/
98 0, /*tp_print*/
99 0, /*tp_getattr*/
100 0, /*tp_setattr*/
101 0, /*tp_compare*/
102 0, /*tp_repr*/
103 0, /*tp_as_number*/
104 0, /*tp_as_sequence*/
105 0, /*tp_as_mapping*/
106 0, /*tp_hash */
107 0, /*tp_call*/
108 0, /*tp_str*/
109 0, /*tp_getattro*/
110 0, /*tp_setattro*/
111 0, /*tp_as_buffer*/
112 Py_TPFLAGS_DEFAULT, /*tp_flags*/
113 "pjsip_event objects", /*tp_doc */
Benny Prijono8b8b9972006-11-16 11:18:03 +0000114};
115
116
Benny Prijono572d4852006-11-23 21:50:02 +0000117/*
118 * pjsip_rx_data_Object
119 * C/python typewrapper for RX data struct
120 */
121typedef struct
122{
123 PyObject_HEAD
124 /* Type-specific fields go here. */
125 pjsip_rx_data * rdata;
126} pjsip_rx_data_Object;
127
128
129/*
130 * pjsip_rx_data_Type
131 */
132static PyTypeObject pjsip_rx_data_Type =
133{
134 PyObject_HEAD_INIT(NULL)
135 0, /*ob_size*/
136 "py_pjsua.PJSIP_RX_Data", /*tp_name*/
137 sizeof(pjsip_rx_data_Object), /*tp_basicsize*/
138 0, /*tp_itemsize*/
139 0, /*tp_dealloc*/
140 0, /*tp_print*/
141 0, /*tp_getattr*/
142 0, /*tp_setattr*/
143 0, /*tp_compare*/
144 0, /*tp_repr*/
145 0, /*tp_as_number*/
146 0, /*tp_as_sequence*/
147 0, /*tp_as_mapping*/
148 0, /*tp_hash */
149 0, /*tp_call*/
150 0, /*tp_str*/
151 0, /*tp_getattro*/
152 0, /*tp_setattro*/
153 0, /*tp_as_buffer*/
154 Py_TPFLAGS_DEFAULT, /*tp_flags*/
155 "pjsip_rx_data objects", /*tp_doc*/
156};
157
158
159/*
160 * callback_Object
161 * C/python typewrapper for callback struct
162 */
163typedef struct
164{
165 PyObject_HEAD
166 /* Type-specific fields go here. */
167 PyObject * on_call_state;
168 PyObject * on_incoming_call;
169 PyObject * on_call_media_state;
170 PyObject * on_call_transfer_request;
171 PyObject * on_call_transfer_status;
172 PyObject * on_call_replace_request;
173 PyObject * on_call_replaced;
174 PyObject * on_reg_state;
175 PyObject * on_buddy_state;
176 PyObject * on_pager;
177 PyObject * on_pager_status;
178 PyObject * on_typing;
179
180} callback_Object;
181
182
183/*
184 * The global callback object.
185 */
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000186static callback_Object * g_obj_callback;
Benny Prijono572d4852006-11-23 21:50:02 +0000187
188
189/*
190 * cb_on_call_state
191 * declares method on_call_state for callback struct
192 */
193static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
194{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000195 if (PyCallable_Check(g_obj_callback->on_call_state))
Fahris17d91812007-01-29 12:09:33 +0000196 {
197 pjsip_event_Object * obj;
198
Fahris6f35cb82007-02-01 07:41:26 +0000199 obj =
Fahris17d91812007-01-29 12:09:33 +0000200 (pjsip_event_Object *)PyType_GenericNew(&pjsip_event_Type,
201 NULL, NULL);
202
Fahris6f35cb82007-02-01 07:41:26 +0000203 obj->event = e;
Fahris17d91812007-01-29 12:09:33 +0000204
Benny Prijono572d4852006-11-23 21:50:02 +0000205 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000206 g_obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000207 );
Fahris17d91812007-01-29 12:09:33 +0000208
Benny Prijono572d4852006-11-23 21:50:02 +0000209 }
210}
211
212
213/*
214 * cb_on_incoming_call
215 * declares method on_incoming_call for callback struct
216 */
217static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
218 pjsip_rx_data *rdata)
219{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000220 if (PyCallable_Check(g_obj_callback->on_incoming_call))
Benny Prijono572d4852006-11-23 21:50:02 +0000221 {
222 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *)
223 PyType_GenericNew(&pjsip_rx_data_Type,
224 NULL, NULL);
225 obj->rdata = rdata;
226
227 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000228 g_obj_callback->on_incoming_call,
Benny Prijono572d4852006-11-23 21:50:02 +0000229 Py_BuildValue("i",acc_id),
230 Py_BuildValue("i",call_id),
231 obj,
232 NULL
233 );
234 }
235}
236
237
238/*
239 * cb_on_call_media_state
240 * declares method on_call_media_state for callback struct
241 */
242static void cb_on_call_media_state(pjsua_call_id call_id)
243{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000244 if (PyCallable_Check(g_obj_callback->on_call_media_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000245 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000246 PyObject_CallFunction(g_obj_callback->on_call_media_state,"i",call_id);
Benny Prijono572d4852006-11-23 21:50:02 +0000247 }
248}
249
250
251/*
252 * Notify application on call being transfered.
Benny Prijonodc308702006-12-09 00:39:42 +0000253 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000254 */
255static void cb_on_call_transfer_request(pjsua_call_id call_id,
256 const pj_str_t *dst,
257 pjsip_status_code *code)
258{
Benny Prijonodc308702006-12-09 00:39:42 +0000259 PyObject * ret;
260 int cd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000261 if (PyCallable_Check(g_obj_callback->on_call_transfer_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000262 {
Benny Prijonodc308702006-12-09 00:39:42 +0000263 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000264 g_obj_callback->on_call_transfer_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000265 Py_BuildValue("i",call_id),
266 PyString_FromStringAndSize(dst->ptr, dst->slen),
267 Py_BuildValue("i",*code),
268 NULL
269 );
Benny Prijonodc308702006-12-09 00:39:42 +0000270 if (ret != NULL) {
271 if (ret != Py_None) {
272 if (PyArg_Parse(ret,"i",&cd)) {
273 *code = cd;
274 }
275 }
276 }
Benny Prijono572d4852006-11-23 21:50:02 +0000277 }
278}
279
280
281/*
282 * Notify application of the status of previously sent call
283 * transfer request. Application can monitor the status of the
284 * call transfer request, for example to decide whether to
285 * terminate existing call.
Benny Prijonodc308702006-12-09 00:39:42 +0000286 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000287 */
288static void cb_on_call_transfer_status( pjsua_call_id call_id,
289 int status_code,
290 const pj_str_t *status_text,
291 pj_bool_t final,
292 pj_bool_t *p_cont)
293{
Benny Prijonodc308702006-12-09 00:39:42 +0000294 PyObject * ret;
295 int cnt;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000296 if (PyCallable_Check(g_obj_callback->on_call_transfer_status))
Benny Prijono572d4852006-11-23 21:50:02 +0000297 {
Benny Prijonodc308702006-12-09 00:39:42 +0000298 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000299 g_obj_callback->on_call_transfer_status,
Benny Prijono572d4852006-11-23 21:50:02 +0000300 Py_BuildValue("i",call_id),
301 Py_BuildValue("i",status_code),
302 PyString_FromStringAndSize(status_text->ptr, status_text->slen),
303 Py_BuildValue("i",final),
304 Py_BuildValue("i",*p_cont),
305 NULL
306 );
Benny Prijonodc308702006-12-09 00:39:42 +0000307 if (ret != NULL) {
308 if (ret != Py_None) {
309 if (PyArg_Parse(ret,"i",&cnt)) {
310 *p_cont = cnt;
311 }
312 }
313 }
Benny Prijono572d4852006-11-23 21:50:02 +0000314 }
315}
316
317
318/*
319 * Notify application about incoming INVITE with Replaces header.
320 * Application may reject the request by setting non-2xx code.
Benny Prijonodc308702006-12-09 00:39:42 +0000321 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000322 */
323static void cb_on_call_replace_request( pjsua_call_id call_id,
324 pjsip_rx_data *rdata,
325 int *st_code,
326 pj_str_t *st_text)
327{
Benny Prijonodc308702006-12-09 00:39:42 +0000328 PyObject * ret;
329 PyObject * txt;
330 int cd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000331 if (PyCallable_Check(g_obj_callback->on_call_replace_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000332 {
Benny Prijonodc308702006-12-09 00:39:42 +0000333 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *)
Benny Prijono572d4852006-11-23 21:50:02 +0000334 PyType_GenericNew(&pjsip_rx_data_Type,
335 NULL, NULL);
Benny Prijonodc308702006-12-09 00:39:42 +0000336 obj->rdata = rdata;
Benny Prijono572d4852006-11-23 21:50:02 +0000337
Benny Prijonodc308702006-12-09 00:39:42 +0000338 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000339 g_obj_callback->on_call_replace_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000340 Py_BuildValue("i",call_id),
341 obj,
342 Py_BuildValue("i",*st_code),
343 PyString_FromStringAndSize(st_text->ptr, st_text->slen),
344 NULL
345 );
Benny Prijonodc308702006-12-09 00:39:42 +0000346 if (ret != NULL) {
347 if (ret != Py_None) {
348 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
349 *st_code = cd;
350 st_text->ptr = PyString_AsString(txt);
351 st_text->slen = strlen(PyString_AsString(txt));
352 }
353 }
354 }
Benny Prijono572d4852006-11-23 21:50:02 +0000355 }
356}
357
358
359/*
360 * Notify application that an existing call has been replaced with
361 * a new call. This happens when PJSUA-API receives incoming INVITE
362 * request with Replaces header.
363 */
364static void cb_on_call_replaced(pjsua_call_id old_call_id,
365 pjsua_call_id new_call_id)
366{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000367 if (PyCallable_Check(g_obj_callback->on_call_replaced))
Benny Prijono572d4852006-11-23 21:50:02 +0000368 {
369 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000370 g_obj_callback->on_call_replaced,
Benny Prijono572d4852006-11-23 21:50:02 +0000371 Py_BuildValue("i",old_call_id),
372 Py_BuildValue("i",old_call_id),
373 NULL
374 );
375 }
376}
377
378
379/*
380 * cb_on_reg_state
381 * declares method on_reg_state for callback struct
382 */
383static void cb_on_reg_state(pjsua_acc_id acc_id)
384{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000385 if (PyCallable_Check(g_obj_callback->on_reg_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000386 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000387 PyObject_CallFunction(g_obj_callback->on_reg_state,"i",acc_id);
Benny Prijono572d4852006-11-23 21:50:02 +0000388 }
389}
390
391
392/*
393 * cb_on_buddy_state
394 * declares method on_buddy state for callback struct
395 */
396static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
397{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000398 if (PyCallable_Check(g_obj_callback->on_buddy_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000399 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000400 PyObject_CallFunction(g_obj_callback->on_buddy_state,"i",buddy_id);
Benny Prijono572d4852006-11-23 21:50:02 +0000401 }
402}
403
404/*
405 * cb_on_pager
Fahrise314b882007-02-02 10:52:04 +0000406 * declares method on_pager for callback struct
Benny Prijono572d4852006-11-23 21:50:02 +0000407 */
408static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
409 const pj_str_t *to, const pj_str_t *contact,
410 const pj_str_t *mime_type, const pj_str_t *body)
411{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000412 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000413 {
414 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000415 g_obj_callback->on_pager,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000416 PyString_FromStringAndSize(from->ptr, from->slen),
417 PyString_FromStringAndSize(to->ptr, to->slen),
418 PyString_FromStringAndSize(contact->ptr, contact->slen),
419 PyString_FromStringAndSize(mime_type->ptr, mime_type->slen),
420 PyString_FromStringAndSize(body->ptr, body->slen), NULL
421 );
422 }
423}
424
425
426/*
427 * cb_on_pager_status
428 * declares method on_pager_status for callback struct
429 */
430static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
431 const pj_str_t *body, void *user_data,
432 pjsip_status_code status,
433 const pj_str_t *reason)
434{
Fahris17d91812007-01-29 12:09:33 +0000435
Benny Prijono572d4852006-11-23 21:50:02 +0000436 PyObject * obj = PyType_GenericNew(user_data, NULL, NULL);
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000437 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000438 {
439 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000440 g_obj_callback->on_pager,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000441 PyString_FromStringAndSize(to->ptr, to->slen),
442 PyString_FromStringAndSize(body->ptr, body->slen),obj,
443 Py_BuildValue("i",status),PyString_FromStringAndSize(reason->ptr,
444 reason->slen),NULL
445 );
446 }
447}
448
449
450/*
451 * cb_on_typing
452 * declares method on_typing for callback struct
453 */
454static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
455 const pj_str_t *to, const pj_str_t *contact,
456 pj_bool_t is_typing)
457{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000458 if (PyCallable_Check(g_obj_callback->on_typing))
Benny Prijono572d4852006-11-23 21:50:02 +0000459 {
460 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000461 g_obj_callback->on_typing,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000462 PyString_FromStringAndSize(from->ptr, from->slen),
463 PyString_FromStringAndSize(to->ptr, to->slen),
464 PyString_FromStringAndSize(contact->ptr, contact->slen),
465 Py_BuildValue("i",is_typing),NULL
466 );
467 }
468}
469
470
471/*
472 * callback_dealloc
473 * destructor function for callback struct
474 */
475static void callback_dealloc(callback_Object* self)
476{
477 Py_XDECREF(self->on_call_state);
478 Py_XDECREF(self->on_incoming_call);
479 Py_XDECREF(self->on_call_media_state);
480 Py_XDECREF(self->on_call_transfer_request);
481 Py_XDECREF(self->on_call_transfer_status);
482 Py_XDECREF(self->on_call_replace_request);
483 Py_XDECREF(self->on_call_replaced);
484 Py_XDECREF(self->on_reg_state);
485 Py_XDECREF(self->on_buddy_state);
486 Py_XDECREF(self->on_pager);
487 Py_XDECREF(self->on_pager_status);
488 Py_XDECREF(self->on_typing);
489 self->ob_type->tp_free((PyObject*)self);
490}
491
492
493/*
494 * callback_new
495 * * declares constructor for callback struct
496 */
497static PyObject * callback_new(PyTypeObject *type, PyObject *args,
498 PyObject *kwds)
499{
500 callback_Object *self;
501
502 self = (callback_Object *)type->tp_alloc(type, 0);
503 if (self != NULL)
504 {
505 Py_INCREF(Py_None);
506 self->on_call_state = Py_None;
507 if (self->on_call_state == NULL)
508 {
509 Py_DECREF(Py_None);
510 return NULL;
511 }
512 Py_INCREF(Py_None);
513 self->on_incoming_call = Py_None;
514 if (self->on_incoming_call == NULL)
515 {
516 Py_DECREF(Py_None);
517 return NULL;
518 }
519 Py_INCREF(Py_None);
520 self->on_call_media_state = Py_None;
521 if (self->on_call_media_state == NULL)
522 {
523 Py_DECREF(Py_None);
524 return NULL;
525 }
526 Py_INCREF(Py_None);
527 self->on_call_transfer_request = Py_None;
528 if (self->on_call_transfer_request == NULL)
529 {
530 Py_DECREF(Py_None);
531 return NULL;
532 }
533 Py_INCREF(Py_None);
534 self->on_call_transfer_status = Py_None;
535 if (self->on_call_transfer_status == NULL)
536 {
537 Py_DECREF(Py_None);
538 return NULL;
539 }
540 Py_INCREF(Py_None);
541 self->on_call_replace_request = Py_None;
542 if (self->on_call_replace_request == NULL)
543 {
544 Py_DECREF(Py_None);
545 return NULL;
546 }
547 Py_INCREF(Py_None);
548 self->on_call_replaced = Py_None;
549 if (self->on_call_replaced == NULL)
550 {
551 Py_DECREF(Py_None);
552 return NULL;
553 }
554 Py_INCREF(Py_None);
555 self->on_reg_state = Py_None;
556 if (self->on_reg_state == NULL)
557 {
558 Py_DECREF(Py_None);
559 return NULL;
560 }
561 Py_INCREF(Py_None);
562 self->on_buddy_state = Py_None;
563 if (self->on_buddy_state == NULL)
564 {
565 Py_DECREF(Py_None);
566 return NULL;
567 }
568 Py_INCREF(Py_None);
569 self->on_pager = Py_None;
570 if (self->on_pager == NULL)
571 {
572 Py_DECREF(Py_None);
573 return NULL;
574 }
575 Py_INCREF(Py_None);
576 self->on_pager_status = Py_None;
577 if (self->on_pager_status == NULL)
578 {
579 Py_DECREF(Py_None);
580 return NULL;
581 }
582 Py_INCREF(Py_None);
583 self->on_typing = Py_None;
584 if (self->on_typing == NULL)
585 {
586 Py_DECREF(Py_None);
587 return NULL;
588 }
589 }
590
591 return (PyObject *)self;
592}
593
594
595/*
596 * callback_members
597 * declares available functions for callback object
598 */
599static PyMemberDef callback_members[] =
600{
601 {
602 "on_call_state", T_OBJECT_EX, offsetof(callback_Object, on_call_state),
603 0, "Notify application when invite state has changed. Application may "
604 "then query the call info to get the detail call states."
605 },
606 {
607 "on_incoming_call", T_OBJECT_EX,
608 offsetof(callback_Object, on_incoming_call), 0,
609 "Notify application on incoming call."
610 },
611 {
Fahris17d91812007-01-29 12:09:33 +0000612 "on_call_media_state", T_OBJECT_EX,
Benny Prijono572d4852006-11-23 21:50:02 +0000613 offsetof(callback_Object, on_call_media_state), 0,
614 "Notify application when media state in the call has changed. Normal "
615 "application would need to implement this callback, e.g. to connect "
616 "the call's media to sound device."
617 },
618 {
619 "on_call_transfer_request", T_OBJECT_EX,
620 offsetof(callback_Object, on_call_transfer_request), 0,
621 "Notify application on call being transfered. "
622 "Application can decide to accept/reject transfer request "
623 "by setting the code (default is 200). When this callback "
624 "is not defined, the default behavior is to accept the "
625 "transfer."
626 },
627 {
628 "on_call_transfer_status", T_OBJECT_EX,
629 offsetof(callback_Object, on_call_transfer_status), 0,
630 "Notify application of the status of previously sent call "
631 "transfer request. Application can monitor the status of the "
632 "call transfer request, for example to decide whether to "
633 "terminate existing call."
634 },
635 {
636 "on_call_replace_request", T_OBJECT_EX,
637 offsetof(callback_Object, on_call_replace_request), 0,
638 "Notify application about incoming INVITE with Replaces header. "
639 "Application may reject the request by setting non-2xx code."
640 },
641 {
642 "on_call_replaced", T_OBJECT_EX,
643 offsetof(callback_Object, on_call_replaced), 0,
644 "Notify application that an existing call has been replaced with "
645 "a new call. This happens when PJSUA-API receives incoming INVITE "
646 "request with Replaces header."
647 " "
648 "After this callback is called, normally PJSUA-API will disconnect "
649 "old_call_id and establish new_call_id."
650 },
651 {
652 "on_reg_state", T_OBJECT_EX,
653 offsetof(callback_Object, on_reg_state), 0,
654 "Notify application when registration status has changed. Application "
655 "may then query the account info to get the registration details."
656 },
657 {
658 "on_buddy_state", T_OBJECT_EX,
659 offsetof(callback_Object, on_buddy_state), 0,
660 "Notify application when the buddy state has changed. Application may "
661 "then query the buddy into to get the details."
662 },
663 {
664 "on_pager", T_OBJECT_EX, offsetof(callback_Object, on_pager), 0,
665 "Notify application on incoming pager (i.e. MESSAGE request). "
666 "Argument call_id will be -1 if MESSAGE request is not related to an "
667 "existing call."
668 },
669 {
670 "on_pager_status", T_OBJECT_EX,
671 offsetof(callback_Object, on_pager_status), 0,
672 "Notify application about the delivery status of outgoing pager "
673 "request."
674 },
675 {
676 "on_typing", T_OBJECT_EX, offsetof(callback_Object, on_typing), 0,
677 "Notify application about typing indication."
678 },
679 {NULL} /* Sentinel */
680};
681
682
683/*
684 * callback_Type
685 * callback class definition
686 */
687static PyTypeObject callback_Type =
688{
689 PyObject_HEAD_INIT(NULL)
690 0, /*ob_size*/
691 "py_pjsua.Callback", /*tp_name*/
692 sizeof(callback_Object), /*tp_basicsize*/
693 0, /*tp_itemsize*/
694 (destructor)callback_dealloc, /*tp_dealloc*/
695 0, /*tp_print*/
696 0, /*tp_getattr*/
697 0, /*tp_setattr*/
698 0, /*tp_compare*/
699 0, /*tp_repr*/
700 0, /*tp_as_number*/
701 0, /*tp_as_sequence*/
702 0, /*tp_as_mapping*/
703 0, /*tp_hash */
704 0, /*tp_call*/
705 0, /*tp_str*/
706 0, /*tp_getattro*/
707 0, /*tp_setattro*/
708 0, /*tp_as_buffer*/
709 Py_TPFLAGS_DEFAULT, /*tp_flags*/
710 "Callback objects", /* tp_doc */
711 0, /* tp_traverse */
712 0, /* tp_clear */
713 0, /* tp_richcompare */
714 0, /* tp_weaklistoffset */
715 0, /* tp_iter */
716 0, /* tp_iternext */
717 0, /* tp_methods */
718 callback_members, /* tp_members */
719 0, /* tp_getset */
720 0, /* tp_base */
721 0, /* tp_dict */
722 0, /* tp_descr_get */
723 0, /* tp_descr_set */
724 0, /* tp_dictoffset */
725 0, /* tp_init */
726 0, /* tp_alloc */
727 callback_new, /* tp_new */
728
729};
730
731
732/*
733 * media_config_Object
734 * C/Python wrapper for media_config object
735 */
736typedef struct
737{
738 PyObject_HEAD
739 /* Type-specific fields go here. */
740 unsigned clock_rate;
741 unsigned max_media_ports;
742 int has_ioqueue;
743 unsigned thread_cnt;
744 unsigned quality;
745 unsigned ptime;
746 int no_vad;
747 unsigned ilbc_mode;
748 unsigned tx_drop_pct;
749 unsigned rx_drop_pct;
750 unsigned ec_options;
751 unsigned ec_tail_len;
752} media_config_Object;
753
754
755/*
756 * media_config_members
757 * declares attributes accessible from both C and Python for media_config file
758 */
759static PyMemberDef media_config_members[] =
760{
761 {
762 "clock_rate", T_INT, offsetof(media_config_Object, clock_rate), 0,
763 "Clock rate to be applied to the conference bridge. If value is zero, "
764 "default clock rate will be used (16KHz)."
765 },
766 {
767 "max_media_ports", T_INT,
768 offsetof(media_config_Object, max_media_ports), 0,
769 "Specify maximum number of media ports to be created in the "
770 "conference bridge. Since all media terminate in the bridge (calls, "
771 "file player, file recorder, etc), the value must be large enough to "
772 "support all of them. However, the larger the value, the more "
773 "computations are performed."
774 },
775 {
776 "has_ioqueue", T_INT, offsetof(media_config_Object, has_ioqueue), 0,
777 "Specify whether the media manager should manage its own ioqueue for "
778 "the RTP/RTCP sockets. If yes, ioqueue will be created and at least "
779 "one worker thread will be created too. If no, the RTP/RTCP sockets "
780 "will share the same ioqueue as SIP sockets, and no worker thread is "
781 "needed."
782 },
783 {
784 "thread_cnt", T_INT, offsetof(media_config_Object, thread_cnt), 0,
785 "Specify the number of worker threads to handle incoming RTP packets. "
786 "A value of one is recommended for most applications."
787 },
788 {
789 "quality", T_INT, offsetof(media_config_Object, quality), 0,
790 "The media quality also sets speex codec quality/complexity to the "
791 "number."
792 },
793 {
794 "ptime", T_INT, offsetof(media_config_Object, ptime), 0,
795 "Specify default ptime."
796 },
797 {
798 "no_vad", T_INT, offsetof(media_config_Object, no_vad), 0,
799 "Disable VAD?"
800 },
801 {
802 "ilbc_mode", T_INT, offsetof(media_config_Object, ilbc_mode), 0,
803 "iLBC mode (20 or 30)."
804 },
805 {
806 "tx_drop_pct", T_INT, offsetof(media_config_Object, tx_drop_pct), 0,
807 "Percentage of RTP packet to drop in TX direction (to simulate packet "
808 "lost)."
809 },
810 {
811 "rx_drop_pct", T_INT, offsetof(media_config_Object, rx_drop_pct), 0,
812 "Percentage of RTP packet to drop in RX direction (to simulate packet "
813 "lost)."},
814 {
815 "ec_options", T_INT, offsetof(media_config_Object, ec_options), 0,
816 "Echo canceller options (see #pjmedia_echo_create())"
817 },
818 {
819 "ec_tail_len", T_INT, offsetof(media_config_Object, ec_tail_len), 0,
820 "Echo canceller tail length, in miliseconds."
821 },
822 {NULL} /* Sentinel */
823};
824
825
826/*
827 * media_config_Type
828 */
829static PyTypeObject media_config_Type =
830{
831 PyObject_HEAD_INIT(NULL)
832 0, /*ob_size*/
833 "py_pjsua.Media_Config", /*tp_name*/
834 sizeof(media_config_Object), /*tp_basicsize*/
835 0, /*tp_itemsize*/
836 0, /*tp_dealloc*/
837 0, /*tp_print*/
838 0, /*tp_getattr*/
839 0, /*tp_setattr*/
840 0, /*tp_compare*/
841 0, /*tp_repr*/
842 0, /*tp_as_number*/
843 0, /*tp_as_sequence*/
844 0, /*tp_as_mapping*/
845 0, /*tp_hash */
846 0, /*tp_call*/
847 0, /*tp_str*/
848 0, /*tp_getattro*/
849 0, /*tp_setattro*/
850 0, /*tp_as_buffer*/
851 Py_TPFLAGS_DEFAULT, /*tp_flags*/
852 "Media Config objects", /*tp_doc*/
853 0, /*tp_traverse*/
854 0, /*tp_clear*/
855 0, /*tp_richcompare*/
856 0, /* tp_weaklistoffset */
857 0, /* tp_iter */
858 0, /* tp_iternext */
859 0, /* tp_methods */
860 media_config_members, /* tp_members */
861
862};
863
864
865/*
866 * config_Object
867 * attribute list for config object
868 */
869typedef struct
870{
871 PyObject_HEAD
872 /* Type-specific fields go here. */
873 unsigned max_calls;
874 unsigned thread_cnt;
875 unsigned outbound_proxy_cnt;
876 pj_str_t outbound_proxy[4];
877 unsigned cred_count;
878 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
879 callback_Object * cb;
880 PyObject * user_agent;
881} config_Object;
882
883
884/*
885 * config_dealloc
886 * deallocates a config object
887 */
888static void config_dealloc(config_Object* self)
889{
890 Py_XDECREF(self->cb);
891 Py_XDECREF(self->user_agent);
892 self->ob_type->tp_free((PyObject*)self);
893}
894
895/*
896 * config_new
897 * config object constructor
898 */
899static PyObject *config_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
900{
901 config_Object *self;
902
903 self = (config_Object *)type->tp_alloc(type, 0);
904 if (self != NULL)
905 {
906 self->user_agent = PyString_FromString("");
907 if (self->user_agent == NULL)
908 {
909 Py_DECREF(self);
910 return NULL;
911 }
912 self->cb = (callback_Object *)PyType_GenericNew(
913 &callback_Type, NULL, NULL
914 );
915 if (self->cb == NULL)
916 {
917 Py_DECREF(Py_None);
918 return NULL;
919 }
920 }
921 return (PyObject *)self;
922}
923
924
925/*
926 * config_members
927 * attribute list accessible from Python/C
928 */
929static PyMemberDef config_members[] =
930{
931 {
932 "max_calls", T_INT, offsetof(config_Object, max_calls), 0,
933 "Maximum calls to support (default: 4) "
934 },
935 {
936 "thread_cnt", T_INT, offsetof(config_Object, thread_cnt), 0,
937 "Number of worker threads. Normally application will want to have at "
938 "least one worker thread, unless when it wants to poll the library "
939 "periodically, which in this case the worker thread can be set to "
940 "zero."
941 },
942 {
943 "outbound_proxy_cnt", T_INT,
944 offsetof(config_Object, outbound_proxy_cnt), 0,
945 "Number of outbound proxies in the array."
946 },
947 {
948 "cred_count", T_INT, offsetof(config_Object, cred_count), 0,
949 "Number of credentials in the credential array."
950 },
951 {
952 "user_agent", T_OBJECT_EX, offsetof(config_Object, user_agent), 0,
953 "User agent string (default empty)"
954 },
955 {
956 "cb", T_OBJECT_EX, offsetof(config_Object, cb), 0,
957 "Application callback."
958 },
959 {NULL} /* Sentinel */
960};
961
962
963/*
964 * config_Type
965 * type wrapper for config class
966 */
967static PyTypeObject config_Type =
968{
969 PyObject_HEAD_INIT(NULL)
970 0, /*ob_size*/
971 "py_pjsua.Config", /*tp_name*/
972 sizeof(config_Object), /*tp_basicsize*/
973 0, /*tp_itemsize*/
974 (destructor)config_dealloc,/*tp_dealloc*/
975 0, /*tp_print*/
976 0, /*tp_getattr*/
977 0, /*tp_setattr*/
978 0, /*tp_compare*/
979 0, /*tp_repr*/
980 0, /*tp_as_number*/
981 0, /*tp_as_sequence*/
982 0, /*tp_as_mapping*/
983 0, /*tp_hash */
984 0, /*tp_call*/
985 0, /*tp_str*/
986 0, /*tp_getattro*/
987 0, /*tp_setattro*/
988 0, /*tp_as_buffer*/
989 Py_TPFLAGS_DEFAULT, /*tp_flags*/
990 "Config objects", /* tp_doc */
991 0, /* tp_traverse */
992 0, /* tp_clear */
993 0, /* tp_richcompare */
994 0, /* tp_weaklistoffset */
995 0, /* tp_iter */
996 0, /* tp_iternext */
997 0, /* tp_methods */
998 config_members, /* tp_members */
999 0, /* tp_getset */
1000 0, /* tp_base */
1001 0, /* tp_dict */
1002 0, /* tp_descr_get */
1003 0, /* tp_descr_set */
1004 0, /* tp_dictoffset */
1005 0, /* tp_init */
1006 0, /* tp_alloc */
1007 config_new, /* tp_new */
1008
1009};
1010
1011
1012/*
1013 * logging_config_Object
1014 * configuration class for logging_config object
1015 */
1016typedef struct
1017{
1018 PyObject_HEAD
1019 /* Type-specific fields go here. */
1020 int msg_logging;
1021 unsigned level;
1022 unsigned console_level;
1023 unsigned decor;
1024 PyObject * log_filename;
1025 PyObject * cb;
1026} logging_config_Object;
1027
1028
1029/*
1030 * logging_config_dealloc
1031 * deletes a logging config from memory
1032 */
1033static void logging_config_dealloc(logging_config_Object* self)
1034{
1035 Py_XDECREF(self->log_filename);
1036 Py_XDECREF(self->cb);
1037 self->ob_type->tp_free((PyObject*)self);
1038}
1039
1040
1041/*
1042 * logging_config_new
1043 * constructor for logging_config object
1044 */
1045static PyObject * logging_config_new(PyTypeObject *type, PyObject *args,
1046 PyObject *kwds)
1047{
1048 logging_config_Object *self;
1049
1050 self = (logging_config_Object *)type->tp_alloc(type, 0);
1051 if (self != NULL)
1052 {
1053 self->log_filename = PyString_FromString("");
1054 if (self->log_filename == NULL)
1055 {
1056 Py_DECREF(self);
1057 return NULL;
1058 }
1059 Py_INCREF(Py_None);
1060 self->cb = Py_None;
1061 if (self->cb == NULL)
1062 {
1063 Py_DECREF(Py_None);
1064 return NULL;
1065 }
1066 }
1067
1068 return (PyObject *)self;
1069}
1070
1071
1072/*
1073 * logging_config_members
1074 */
1075static PyMemberDef logging_config_members[] =
1076{
1077 {
1078 "msg_logging", T_INT, offsetof(logging_config_Object, msg_logging), 0,
1079 "Log incoming and outgoing SIP message? Yes!"
1080 },
1081 {
1082 "level", T_INT, offsetof(logging_config_Object, level), 0,
1083 "Input verbosity level. Value 5 is reasonable."
1084 },
1085 {
1086 "console_level", T_INT, offsetof(logging_config_Object, console_level),
1087 0, "Verbosity level for console. Value 4 is reasonable."
1088 },
1089 {
1090 "decor", T_INT, offsetof(logging_config_Object, decor), 0,
1091 "Log decoration"
1092 },
1093 {
1094 "log_filename", T_OBJECT_EX,
1095 offsetof(logging_config_Object, log_filename), 0,
1096 "Optional log filename"
1097 },
1098 {
1099 "cb", T_OBJECT_EX, offsetof(logging_config_Object, cb), 0,
1100 "Optional callback function to be called to write log to application "
1101 "specific device. This function will be called forlog messages on "
1102 "input verbosity level."
1103 },
1104 {NULL} /* Sentinel */
1105};
1106
1107
1108
1109
1110/*
1111 * logging_config_Type
1112 */
1113static PyTypeObject logging_config_Type =
1114{
1115 PyObject_HEAD_INIT(NULL)
1116 0, /*ob_size*/
1117 "py_pjsua.Logging_Config", /*tp_name*/
1118 sizeof(logging_config_Object), /*tp_basicsize*/
1119 0, /*tp_itemsize*/
1120 (destructor)logging_config_dealloc,/*tp_dealloc*/
1121 0, /*tp_print*/
1122 0, /*tp_getattr*/
1123 0, /*tp_setattr*/
1124 0, /*tp_compare*/
1125 0, /*tp_repr*/
1126 0, /*tp_as_number*/
1127 0, /*tp_as_sequence*/
1128 0, /*tp_as_mapping*/
1129 0, /*tp_hash */
1130 0, /*tp_call*/
1131 0, /*tp_str*/
1132 0, /*tp_getattro*/
1133 0, /*tp_setattro*/
1134 0, /*tp_as_buffer*/
1135 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1136 "Logging Config objects", /* tp_doc */
1137 0, /* tp_traverse */
1138 0, /* tp_clear */
1139 0, /* tp_richcompare */
1140 0, /* tp_weaklistoffset */
1141 0, /* tp_iter */
1142 0, /* tp_iternext */
1143 0, /* tp_methods */
1144 logging_config_members, /* tp_members */
1145 0, /* tp_getset */
1146 0, /* tp_base */
1147 0, /* tp_dict */
1148 0, /* tp_descr_get */
1149 0, /* tp_descr_set */
1150 0, /* tp_dictoffset */
1151 0, /* tp_init */
1152 0, /* tp_alloc */
1153 logging_config_new, /* tp_new */
1154
1155};
1156
1157
1158/*
1159 * msg_data_Object
1160 * typewrapper for MessageData class
Benny Prijonodc308702006-12-09 00:39:42 +00001161 * !modified @ 061206
Benny Prijono572d4852006-11-23 21:50:02 +00001162 */
1163typedef struct
1164{
1165 PyObject_HEAD
1166 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00001167 /*pjsip_hdr hdr_list;*/
1168 PyObject * hdr_list;
Benny Prijono572d4852006-11-23 21:50:02 +00001169 PyObject * content_type;
1170 PyObject * msg_body;
1171} msg_data_Object;
1172
1173
1174/*
1175 * msg_data_dealloc
1176 * deletes a msg_data
Benny Prijonodc308702006-12-09 00:39:42 +00001177 * !modified @ 061206
Benny Prijono572d4852006-11-23 21:50:02 +00001178 */
1179static void msg_data_dealloc(msg_data_Object* self)
1180{
Benny Prijonodc308702006-12-09 00:39:42 +00001181 Py_XDECREF(self->hdr_list);
Benny Prijono572d4852006-11-23 21:50:02 +00001182 Py_XDECREF(self->content_type);
1183 Py_XDECREF(self->msg_body);
1184 self->ob_type->tp_free((PyObject*)self);
1185}
1186
1187
1188/*
1189 * msg_data_new
1190 * constructor for msg_data object
Benny Prijonodc308702006-12-09 00:39:42 +00001191 * !modified @ 061206
Benny Prijono572d4852006-11-23 21:50:02 +00001192 */
1193static PyObject * msg_data_new(PyTypeObject *type, PyObject *args,
1194 PyObject *kwds)
1195{
1196 msg_data_Object *self;
1197
1198 self = (msg_data_Object *)type->tp_alloc(type, 0);
1199 if (self != NULL)
1200 {
Benny Prijonodc308702006-12-09 00:39:42 +00001201 Py_INCREF(Py_None);
1202 self->hdr_list = Py_None;
1203 if (self->hdr_list == NULL)
1204 {
1205 Py_DECREF(self);
1206 return NULL;
1207 }
Benny Prijono572d4852006-11-23 21:50:02 +00001208 self->content_type = PyString_FromString("");
1209 if (self->content_type == NULL)
1210 {
1211 Py_DECREF(self);
1212 return NULL;
1213 }
1214 self->msg_body = PyString_FromString("");
1215 if (self->msg_body == NULL)
1216 {
1217 Py_DECREF(self);
1218 return NULL;
1219 }
1220 }
1221
1222 return (PyObject *)self;
1223}
1224
1225
1226/*
1227 * msg_data_members
Benny Prijonodc308702006-12-09 00:39:42 +00001228 * !modified @ 061206
Benny Prijono572d4852006-11-23 21:50:02 +00001229 */
1230static PyMemberDef msg_data_members[] =
1231{
1232 {
Benny Prijonodc308702006-12-09 00:39:42 +00001233 "hdr_list", T_OBJECT_EX, offsetof(msg_data_Object, hdr_list),
1234 0, "Additional message headers as linked list."
1235 },
1236 {
1237 "content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type),
Benny Prijono572d4852006-11-23 21:50:02 +00001238 0, "MIME type of optional message body."
1239 },
1240 {
1241 "msg_body", T_OBJECT_EX, offsetof(msg_data_Object, msg_body), 0,
1242 "Optional message body."
1243 },
1244 {NULL} /* Sentinel */
1245};
1246
1247
1248/*
1249 * msg_data_Type
1250 */
1251static PyTypeObject msg_data_Type =
1252{
1253 PyObject_HEAD_INIT(NULL)
1254 0, /*ob_size*/
1255 "py_pjsua.Msg_Data", /*tp_name*/
1256 sizeof(msg_data_Object), /*tp_basicsize*/
1257 0, /*tp_itemsize*/
1258 (destructor)msg_data_dealloc,/*tp_dealloc*/
1259 0, /*tp_print*/
1260 0, /*tp_getattr*/
1261 0, /*tp_setattr*/
1262 0, /*tp_compare*/
1263 0, /*tp_repr*/
1264 0, /*tp_as_number*/
1265 0, /*tp_as_sequence*/
1266 0, /*tp_as_mapping*/
1267 0, /*tp_hash */
1268 0, /*tp_call*/
1269 0, /*tp_str*/
1270 0, /*tp_getattro*/
1271 0, /*tp_setattro*/
1272 0, /*tp_as_buffer*/
1273 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1274 "msg_data objects", /* tp_doc */
1275 0, /* tp_traverse */
1276 0, /* tp_clear */
1277 0, /* tp_richcompare */
1278 0, /* tp_weaklistoffset */
1279 0, /* tp_iter */
1280 0, /* tp_iternext */
1281 0, /* tp_methods */
1282 msg_data_members, /* tp_members */
1283 0, /* tp_getset */
1284 0, /* tp_base */
1285 0, /* tp_dict */
1286 0, /* tp_descr_get */
1287 0, /* tp_descr_set */
1288 0, /* tp_dictoffset */
1289 0, /* tp_init */
1290 0, /* tp_alloc */
1291 msg_data_new, /* tp_new */
1292
1293};
1294
Benny Prijonodc308702006-12-09 00:39:42 +00001295/*
1296 * translate_hdr
1297 * internal function
1298 * translate from hdr_list to pjsip_generic_string_hdr
1299 */
1300void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
1301{
1302 int i;
1303
1304 if (PyList_Check(py_hdr_list)) {
1305 pj_list_init(hdr);
1306
Fahris6f35cb82007-02-01 07:41:26 +00001307 for (i = 0; i < PyList_Size(py_hdr_list); i++)
1308 {
Benny Prijonodc308702006-12-09 00:39:42 +00001309 pj_str_t hname, hvalue;
1310 pjsip_generic_string_hdr * new_hdr;
1311 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
1312
Fahris6f35cb82007-02-01 07:41:26 +00001313 if (PyTuple_Check(tuple))
1314 {
Benny Prijonodc308702006-12-09 00:39:42 +00001315 hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0));
Fahris17d91812007-01-29 12:09:33 +00001316 hname.slen = strlen(PyString_AsString
1317 (PyTuple_GetItem(tuple,0)));
Benny Prijonodc308702006-12-09 00:39:42 +00001318 hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1));
Fahris17d91812007-01-29 12:09:33 +00001319 hvalue.slen = strlen(PyString_AsString
1320 (PyTuple_GetItem(tuple,1)));
Benny Prijonodc308702006-12-09 00:39:42 +00001321 } else {
1322 hname.ptr = "";
1323 hname.slen = 0;
1324 hvalue.ptr = "";
1325 hvalue.slen = 0;
1326 }
1327 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
1328 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
1329 }
1330 }
1331}
1332
1333/*
1334 * translate_hdr_rev
1335 * internal function
1336 * translate from pjsip_generic_string_hdr to hdr_list
1337 */
1338
1339void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list)
1340{
1341 int i;
1342 int len;
1343 pjsip_generic_string_hdr * p_hdr;
1344
1345 len = pj_list_size(hdr);
1346
Fahris6f35cb82007-02-01 07:41:26 +00001347 if (len > 0)
1348 {
1349 p_hdr = hdr;
Benny Prijonodc308702006-12-09 00:39:42 +00001350 Py_XDECREF(py_hdr_list);
1351 py_hdr_list = PyList_New(len);
1352
Fahris6f35cb82007-02-01 07:41:26 +00001353 for (i = 0; i < len && p_hdr != NULL; i++)
1354 {
1355 PyObject * tuple;
1356 PyObject * str;
Benny Prijonodc308702006-12-09 00:39:42 +00001357
Fahris6f35cb82007-02-01 07:41:26 +00001358 tuple = PyTuple_New(2);
Benny Prijonodc308702006-12-09 00:39:42 +00001359
Fahris6f35cb82007-02-01 07:41:26 +00001360 str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen);
1361 PyTuple_SetItem(tuple, 0, str);
1362 str = PyString_FromStringAndSize
1363 (hdr->hvalue.ptr, p_hdr->hvalue.slen);
1364 PyTuple_SetItem(tuple, 1, str);
1365 PyList_SetItem(py_hdr_list, i, tuple);
1366 p_hdr = p_hdr->next;
Benny Prijonodc308702006-12-09 00:39:42 +00001367 }
1368 }
1369
1370
1371}
Benny Prijono572d4852006-11-23 21:50:02 +00001372
1373/*
1374 * pj_pool_Object
1375 */
1376typedef struct
1377{
1378 PyObject_HEAD
1379 /* Type-specific fields go here. */
1380 pj_pool_t * pool;
1381} pj_pool_Object;
1382
1383
1384/*
1385 * pj_pool_Type
1386 */
1387static PyTypeObject pj_pool_Type =
1388{
1389 PyObject_HEAD_INIT(NULL)
1390 0, /*ob_size*/
1391 "py_pjsua.PJ_Pool", /*tp_name*/
1392 sizeof(pj_pool_Object), /*tp_basicsize*/
1393 0, /*tp_itemsize*/
1394 0, /*tp_dealloc*/
1395 0, /*tp_print*/
1396 0, /*tp_getattr*/
1397 0, /*tp_setattr*/
1398 0, /*tp_compare*/
1399 0, /*tp_repr*/
1400 0, /*tp_as_number*/
1401 0, /*tp_as_sequence*/
1402 0, /*tp_as_mapping*/
1403 0, /*tp_hash */
1404 0, /*tp_call*/
1405 0, /*tp_str*/
1406 0, /*tp_getattro*/
1407 0, /*tp_setattro*/
1408 0, /*tp_as_buffer*/
1409 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1410 "pj_pool_t objects", /* tp_doc */
1411
1412};
1413
1414
1415/*
1416 * pjsip_endpoint_Object
1417 */
1418typedef struct
1419{
1420 PyObject_HEAD
1421 /* Type-specific fields go here. */
1422 pjsip_endpoint * endpt;
1423} pjsip_endpoint_Object;
1424
1425
1426/*
1427 * pjsip_endpoint_Type
1428 */
1429static PyTypeObject pjsip_endpoint_Type =
1430{
1431 PyObject_HEAD_INIT(NULL)
1432 0, /*ob_size*/
1433 "py_pjsua.PJSIP_Endpoint", /*tp_name*/
1434 sizeof(pjsip_endpoint_Object),/*tp_basicsize*/
1435 0, /*tp_itemsize*/
1436 0, /*tp_dealloc*/
1437 0, /*tp_print*/
1438 0, /*tp_getattr*/
1439 0, /*tp_setattr*/
1440 0, /*tp_compare*/
1441 0, /*tp_repr*/
1442 0, /*tp_as_number*/
1443 0, /*tp_as_sequence*/
1444 0, /*tp_as_mapping*/
1445 0, /*tp_hash */
1446 0, /*tp_call*/
1447 0, /*tp_str*/
1448 0, /*tp_getattro*/
1449 0, /*tp_setattro*/
1450 0, /*tp_as_buffer*/
1451 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1452 "pjsip_endpoint objects", /* tp_doc */
1453};
1454
1455
1456/*
1457 * pjmedia_endpt_Object
1458 */
1459typedef struct
1460{
1461 PyObject_HEAD
1462 /* Type-specific fields go here. */
1463 pjmedia_endpt * endpt;
1464} pjmedia_endpt_Object;
1465
1466
1467/*
1468 * pjmedia_endpt_Type
1469 */
1470static PyTypeObject pjmedia_endpt_Type =
1471{
1472 PyObject_HEAD_INIT(NULL)
1473 0, /*ob_size*/
1474 "py_pjsua.PJMedia_Endpt", /*tp_name*/
1475 sizeof(pjmedia_endpt_Object), /*tp_basicsize*/
1476 0, /*tp_itemsize*/
1477 0, /*tp_dealloc*/
1478 0, /*tp_print*/
1479 0, /*tp_getattr*/
1480 0, /*tp_setattr*/
1481 0, /*tp_compare*/
1482 0, /*tp_repr*/
1483 0, /*tp_as_number*/
1484 0, /*tp_as_sequence*/
1485 0, /*tp_as_mapping*/
1486 0, /*tp_hash */
1487 0, /*tp_call*/
1488 0, /*tp_str*/
1489 0, /*tp_getattro*/
1490 0, /*tp_setattro*/
1491 0, /*tp_as_buffer*/
1492 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1493 "pjmedia_endpt objects", /* tp_doc */
1494
1495};
1496
1497
1498/*
1499 * pj_pool_factory_Object
1500 */
1501typedef struct
1502{
1503 PyObject_HEAD
1504 /* Type-specific fields go here. */
1505 pj_pool_factory * pool_fact;
1506} pj_pool_factory_Object;
1507
1508
1509
1510/*
1511 * pj_pool_factory_Type
1512 */
1513static PyTypeObject pj_pool_factory_Type =
1514{
1515 PyObject_HEAD_INIT(NULL)
1516 0, /*ob_size*/
1517 "py_pjsua.PJ_Pool_Factory",/*tp_name*/
1518 sizeof(pj_pool_factory_Object), /*tp_basicsize*/
1519 0, /*tp_itemsize*/
1520 0, /*tp_dealloc*/
1521 0, /*tp_print*/
1522 0, /*tp_getattr*/
1523 0, /*tp_setattr*/
1524 0, /*tp_compare*/
1525 0, /*tp_repr*/
1526 0, /*tp_as_number*/
1527 0, /*tp_as_sequence*/
1528 0, /*tp_as_mapping*/
1529 0, /*tp_hash */
1530 0, /*tp_call*/
1531 0, /*tp_str*/
1532 0, /*tp_getattro*/
1533 0, /*tp_setattro*/
1534 0, /*tp_as_buffer*/
1535 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1536 "pj_pool_factory objects", /* tp_doc */
1537
1538};
1539
1540
1541/*
1542 * pjsip_cred_info_Object
1543 */
1544typedef struct
1545{
1546 PyObject_HEAD
1547 /* Type-specific fields go here. */
Benny Prijono98793592006-12-04 08:33:20 +00001548 PyObject * realm;
1549 PyObject * scheme;
1550 PyObject * username;
1551 int data_type;
1552 PyObject * data;
1553
Benny Prijono572d4852006-11-23 21:50:02 +00001554} pjsip_cred_info_Object;
1555
Benny Prijono98793592006-12-04 08:33:20 +00001556/*
1557 * cred_info_dealloc
1558 * deletes a cred info from memory
1559 */
1560static void pjsip_cred_info_dealloc(pjsip_cred_info_Object* self)
1561{
1562 Py_XDECREF(self->realm);
1563 Py_XDECREF(self->scheme);
Fahris6f35cb82007-02-01 07:41:26 +00001564 Py_XDECREF(self->username);
1565 Py_XDECREF(self->data);
Benny Prijono98793592006-12-04 08:33:20 +00001566 self->ob_type->tp_free((PyObject*)self);
1567}
1568
1569
1570/*
1571 * cred_info_new
1572 * constructor for cred_info object
1573 */
1574static PyObject * pjsip_cred_info_new(PyTypeObject *type, PyObject *args,
1575 PyObject *kwds)
1576{
1577 pjsip_cred_info_Object *self;
1578
1579 self = (pjsip_cred_info_Object *)type->tp_alloc(type, 0);
1580 if (self != NULL)
1581 {
1582 self->realm = PyString_FromString("");
1583 if (self->realm == NULL)
1584 {
1585 Py_DECREF(self);
1586 return NULL;
1587 }
Benny Prijonodc308702006-12-09 00:39:42 +00001588 self->scheme = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00001589 if (self->scheme == NULL)
1590 {
1591 Py_DECREF(self);
1592 return NULL;
1593 }
Benny Prijonodc308702006-12-09 00:39:42 +00001594 self->username = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00001595 if (self->username == NULL)
1596 {
1597 Py_DECREF(self);
1598 return NULL;
1599 }
Benny Prijonodc308702006-12-09 00:39:42 +00001600 self->data = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00001601 if (self->data == NULL)
1602 {
1603 Py_DECREF(self);
1604 return NULL;
1605 }
1606 }
1607
1608 return (PyObject *)self;
1609}
1610
1611
1612/*
1613 * pjsip_cred_info_members
1614 */
1615static PyMemberDef pjsip_cred_info_members[] =
1616{
Benny Prijonodc308702006-12-09 00:39:42 +00001617 {
1618 "realm", T_OBJECT_EX,
1619 offsetof(pjsip_cred_info_Object, realm), 0,
1620 "Realm"
Benny Prijono98793592006-12-04 08:33:20 +00001621 },
1622 {
Benny Prijonodc308702006-12-09 00:39:42 +00001623 "scheme", T_OBJECT_EX,
1624 offsetof(pjsip_cred_info_Object, scheme), 0,
1625 "Scheme"
1626 },
1627 {
1628 "username", T_OBJECT_EX,
1629 offsetof(pjsip_cred_info_Object, username), 0,
1630 "User name"
1631 },
1632 {
1633 "data", T_OBJECT_EX,
1634 offsetof(pjsip_cred_info_Object, data), 0,
1635 "The data, which can be a plaintext password or a hashed digest. "
1636 },
1637 {
1638 "data_type", T_INT, offsetof(pjsip_cred_info_Object, data_type), 0,
1639 "Type of data"
Benny Prijono98793592006-12-04 08:33:20 +00001640 },
1641
1642 {NULL} /* Sentinel */
1643};
Benny Prijono572d4852006-11-23 21:50:02 +00001644
1645/*
1646 * pjsip_cred_info_Type
1647 */
1648static PyTypeObject pjsip_cred_info_Type =
1649{
1650 PyObject_HEAD_INIT(NULL)
Benny Prijono98793592006-12-04 08:33:20 +00001651 0, /*ob_size*/
1652 "py_pjsua.PJSIP_Cred_Info", /*tp_name*/
1653 sizeof(pjsip_cred_info_Object), /*tp_basicsize*/
1654 0, /*tp_itemsize*/
1655 (destructor)pjsip_cred_info_dealloc,/*tp_dealloc*/
1656 0, /*tp_print*/
1657 0, /*tp_getattr*/
1658 0, /*tp_setattr*/
1659 0, /*tp_compare*/
1660 0, /*tp_repr*/
1661 0, /*tp_as_number*/
1662 0, /*tp_as_sequence*/
1663 0, /*tp_as_mapping*/
1664 0, /*tp_hash */
1665 0, /*tp_call*/
1666 0, /*tp_str*/
1667 0, /*tp_getattro*/
1668 0, /*tp_setattro*/
1669 0, /*tp_as_buffer*/
1670 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1671 "PJSIP Cred Info objects", /* tp_doc */
1672 0, /* tp_traverse */
1673 0, /* tp_clear */
1674 0, /* tp_richcompare */
1675 0, /* tp_weaklistoffset */
1676 0, /* tp_iter */
1677 0, /* tp_iternext */
1678 0, /* tp_methods */
1679 pjsip_cred_info_members, /* tp_members */
1680 0, /* tp_getset */
1681 0, /* tp_base */
1682 0, /* tp_dict */
1683 0, /* tp_descr_get */
1684 0, /* tp_descr_set */
1685 0, /* tp_dictoffset */
1686 0, /* tp_init */
1687 0, /* tp_alloc */
1688 pjsip_cred_info_new, /* tp_new */
Benny Prijono572d4852006-11-23 21:50:02 +00001689
1690};
1691
Benny Prijonodc308702006-12-09 00:39:42 +00001692/*
1693 * py_pjsua_thread_register
1694 * !added @ 061206
1695 */
1696static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject
1697*pArgs)
1698{
1699
1700 pj_status_t status;
1701 const char *name;
1702 PyObject *py_desc;
1703 pj_thread_t *thread;
1704 void *thread_desc;
Fahrisdcf8fa42006-12-28 03:13:48 +00001705#if 0
Benny Prijonodc308702006-12-09 00:39:42 +00001706 int size;
1707 int i;
1708 int *td;
Fahrisdcf8fa42006-12-28 03:13:48 +00001709#endif
Benny Prijonodc308702006-12-09 00:39:42 +00001710
1711 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc))
1712 {
1713 return NULL;
1714 }
1715#if 0
1716 size = PyList_Size(py_desc);
1717 td = (int *)malloc(size * sizeof(int));
Fahris6f35cb82007-02-01 07:41:26 +00001718 for (i = 0; i < size; i++)
1719 {
1720 if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i]))
1721 {
Benny Prijonodc308702006-12-09 00:39:42 +00001722 return NULL;
1723 }
1724 }
1725 thread_desc = td;
1726#else
1727 thread_desc = malloc(sizeof(pj_thread_desc));
1728#endif
1729 status = pj_thread_register(name, thread_desc, &thread);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00001730
1731 if (status == PJ_SUCCESS)
1732 status = pj_thread_local_set(thread_id, (void*)1);
Benny Prijonodc308702006-12-09 00:39:42 +00001733 return Py_BuildValue("i",status);
1734}
Benny Prijono572d4852006-11-23 21:50:02 +00001735
1736/*
1737 * py_pjsua_logging_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001738 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +00001739 */
1740static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
1741 PyObject *pArgs)
1742{
Benny Prijonodc308702006-12-09 00:39:42 +00001743 logging_config_Object *obj;
Benny Prijono572d4852006-11-23 21:50:02 +00001744 pjsua_logging_config cfg;
1745
Benny Prijonodc308702006-12-09 00:39:42 +00001746 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +00001747 {
1748 return NULL;
1749 }
Benny Prijonodc308702006-12-09 00:39:42 +00001750
Benny Prijono572d4852006-11-23 21:50:02 +00001751 pjsua_logging_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001752 obj = (logging_config_Object *) logging_config_new
Benny Prijonodc308702006-12-09 00:39:42 +00001753 (&logging_config_Type,NULL,NULL);
Benny Prijono572d4852006-11-23 21:50:02 +00001754 obj->msg_logging = cfg.msg_logging;
1755 obj->level = cfg.level;
1756 obj->console_level = cfg.console_level;
1757 obj->decor = cfg.decor;
Benny Prijonodc308702006-12-09 00:39:42 +00001758
1759 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +00001760}
1761
1762
1763/*
1764 * py_pjsua_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001765 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +00001766 */
1767static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
1768{
1769 config_Object *obj;
1770 pjsua_config cfg;
1771
Benny Prijonodc308702006-12-09 00:39:42 +00001772 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +00001773 {
1774 return NULL;
1775 }
1776 pjsua_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001777 obj = (config_Object *) config_new(&config_Type, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +00001778 obj->max_calls = cfg.max_calls;
1779 obj->thread_cnt = cfg.thread_cnt;
Benny Prijonodc308702006-12-09 00:39:42 +00001780 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +00001781}
1782
1783
1784/*
1785 * py_pjsua_media_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001786 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +00001787 */
1788static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
1789 PyObject *pArgs)
1790{
1791 media_config_Object *obj;
1792 pjsua_media_config cfg;
Benny Prijonodc308702006-12-09 00:39:42 +00001793 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +00001794 {
1795 return NULL;
1796 }
1797 pjsua_media_config_default(&cfg);
Fahris17d91812007-01-29 12:09:33 +00001798 obj = (media_config_Object *)PyType_GenericNew
1799 (&media_config_Type, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +00001800 obj->clock_rate = cfg.clock_rate;
1801 obj->ec_options = cfg.ec_options;
1802 obj->ec_tail_len = cfg.ec_tail_len;
1803 obj->has_ioqueue = cfg.has_ioqueue;
1804 obj->ilbc_mode = cfg.ilbc_mode;
1805 obj->max_media_ports = cfg.max_media_ports;
1806 obj->no_vad = cfg.no_vad;
1807 obj->ptime = cfg.ptime;
1808 obj->quality = cfg.quality;
1809 obj->rx_drop_pct = cfg.rx_drop_pct;
1810 obj->thread_cnt = cfg.thread_cnt;
1811 obj->tx_drop_pct = cfg.tx_drop_pct;
Benny Prijonodc308702006-12-09 00:39:42 +00001812 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +00001813}
1814
1815
1816/*
1817 * py_pjsua_msg_data_init
Benny Prijonodc308702006-12-09 00:39:42 +00001818 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +00001819 */
1820static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
1821{
1822 msg_data_Object *obj;
1823 pjsua_msg_data msg;
Benny Prijonodc308702006-12-09 00:39:42 +00001824
1825 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +00001826 {
1827 return NULL;
1828 }
1829 pjsua_msg_data_init(&msg);
Benny Prijonodc308702006-12-09 00:39:42 +00001830 obj = (msg_data_Object *)msg_data_new(&msg_data_Type, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +00001831 Py_XDECREF(obj->content_type);
1832 obj->content_type = PyString_FromStringAndSize(
1833 msg.content_type.ptr, msg.content_type.slen
1834 );
1835 Py_XDECREF(obj->msg_body);
1836 obj->msg_body = PyString_FromStringAndSize(
1837 msg.msg_body.ptr, msg.msg_body.slen
1838 );
Benny Prijono572d4852006-11-23 21:50:02 +00001839
Fahris17d91812007-01-29 12:09:33 +00001840 translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list);
Benny Prijonodc308702006-12-09 00:39:42 +00001841
1842 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +00001843}
1844
1845
1846/*
1847 * py_pjsua_reconfigure_logging
1848 */
1849static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs)
1850{
Fahris6f35cb82007-02-01 07:41:26 +00001851 PyObject * logObj;
Benny Prijono572d4852006-11-23 21:50:02 +00001852 logging_config_Object *log;
1853 pjsua_logging_config cfg;
1854 pj_status_t status;
1855
Fahris17d91812007-01-29 12:09:33 +00001856 if (!PyArg_ParseTuple(pArgs, "O", &logObj))
Benny Prijono572d4852006-11-23 21:50:02 +00001857 {
1858 return NULL;
1859 }
Fahris6f35cb82007-02-01 07:41:26 +00001860 if (logObj != Py_None)
1861 {
Fahris17d91812007-01-29 12:09:33 +00001862 log = (logging_config_Object *)logObj;
1863 cfg.msg_logging = log->msg_logging;
1864 cfg.level = log->level;
1865 cfg.console_level = log->console_level;
1866 cfg.decor = log->decor;
1867 cfg.log_filename.ptr = PyString_AsString(log->log_filename);
1868 cfg.log_filename.slen = strlen(cfg.log_filename.ptr);
1869 Py_XDECREF(obj_reconfigure_logging);
1870 obj_reconfigure_logging = log->cb;
1871 Py_INCREF(obj_reconfigure_logging);
1872 cfg.cb = &cb_reconfigure_logging;
1873 status = pjsua_reconfigure_logging(&cfg);
1874 } else {
1875 status = pjsua_reconfigure_logging(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00001876 }
Benny Prijono572d4852006-11-23 21:50:02 +00001877 return Py_BuildValue("i",status);
1878}
1879
1880
1881/*
1882 * py_pjsua_pool_create
1883 */
1884static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs)
1885{
1886 pj_size_t init_size;
1887 pj_size_t increment;
1888 const char * name;
1889 pj_pool_t *p;
1890 pj_pool_Object *pool;
1891
1892 if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment))
1893 {
1894 return NULL;
1895 }
Fahris89ea3d02007-02-07 08:18:35 +00001896
Benny Prijono572d4852006-11-23 21:50:02 +00001897 p = pjsua_pool_create(name, init_size, increment);
1898 pool = (pj_pool_Object *)PyType_GenericNew(&pj_pool_Type, NULL, NULL);
1899 pool->pool = p;
1900 return (PyObject *)pool;
1901
1902}
1903
1904
1905/*
1906 * py_pjsua_get_pjsip_endpt
1907 */
1908static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs)
1909{
1910 pjsip_endpoint_Object *endpt;
1911 pjsip_endpoint *e;
1912
1913 if (!PyArg_ParseTuple(pArgs, ""))
1914 {
1915 return NULL;
1916 }
1917 e = pjsua_get_pjsip_endpt();
1918 endpt = (pjsip_endpoint_Object *)PyType_GenericNew(
1919 &pjsip_endpoint_Type, NULL, NULL
1920 );
1921 endpt->endpt = e;
1922 return (PyObject *)endpt;
1923}
1924
1925
1926/*
1927 * py_pjsua_get_pjmedia_endpt
1928 */
1929static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs)
1930{
1931 pjmedia_endpt_Object *endpt;
1932 pjmedia_endpt *e;
1933
1934 if (!PyArg_ParseTuple(pArgs, ""))
1935 {
1936 return NULL;
1937 }
1938 e = pjsua_get_pjmedia_endpt();
1939 endpt = (pjmedia_endpt_Object *)PyType_GenericNew(
1940 &pjmedia_endpt_Type, NULL, NULL
1941 );
1942 endpt->endpt = e;
1943 return (PyObject *)endpt;
1944}
1945
1946
1947/*
1948 * py_pjsua_get_pool_factory
1949 */
1950static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs)
1951{
1952 pj_pool_factory_Object *pool;
1953 pj_pool_factory *p;
1954
1955 if (!PyArg_ParseTuple(pArgs, ""))
1956 {
1957 return NULL;
1958 }
1959 p = pjsua_get_pool_factory();
1960 pool = (pj_pool_factory_Object *)PyType_GenericNew(
1961 &pj_pool_factory_Type, NULL, NULL
1962 );
1963 pool->pool_fact = p;
1964 return (PyObject *)pool;
1965}
1966
1967
1968/*
1969 * py_pjsua_perror
1970 */
1971static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
1972{
1973 const char *sender;
1974 const char *title;
1975 pj_status_t status;
1976 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status))
1977 {
1978 return NULL;
1979 }
Benny Prijonodc308702006-12-09 00:39:42 +00001980
Benny Prijono572d4852006-11-23 21:50:02 +00001981 pjsua_perror(sender, title, status);
1982 Py_INCREF(Py_None);
1983 return Py_None;
1984}
1985
1986
1987/*
1988 * py_pjsua_create
1989 */
1990static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
1991{
1992 pj_status_t status;
1993 if (!PyArg_ParseTuple(pArgs, ""))
1994 {
1995 return NULL;
1996 }
1997 status = pjsua_create();
Benny Prijonoed7a5a72007-01-29 18:36:38 +00001998
Fahris6f35cb82007-02-01 07:41:26 +00001999 if (status == PJ_SUCCESS)
2000 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002001 status = pj_thread_local_alloc(&thread_id);
2002 if (status == PJ_SUCCESS)
2003 status = pj_thread_local_set(thread_id, (void*)1);
2004 }
2005
Benny Prijono572d4852006-11-23 21:50:02 +00002006 return Py_BuildValue("i",status);
2007}
2008
2009
2010/*
2011 * py_pjsua_init
2012 */
2013static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
2014{
2015 pj_status_t status;
Fahris17d91812007-01-29 12:09:33 +00002016 PyObject * ua_cfgObj;
Benny Prijono572d4852006-11-23 21:50:02 +00002017 config_Object * ua_cfg;
Fahris17d91812007-01-29 12:09:33 +00002018 PyObject * log_cfgObj;
Benny Prijono572d4852006-11-23 21:50:02 +00002019 logging_config_Object * log_cfg;
Fahris17d91812007-01-29 12:09:33 +00002020 PyObject * media_cfgObj;
Benny Prijono572d4852006-11-23 21:50:02 +00002021 media_config_Object * media_cfg;
2022 pjsua_config cfg_ua;
Fahris17d91812007-01-29 12:09:33 +00002023 pjsua_config * p_cfg_ua;
Benny Prijono572d4852006-11-23 21:50:02 +00002024 pjsua_logging_config cfg_log;
Fahris17d91812007-01-29 12:09:33 +00002025 pjsua_logging_config * p_cfg_log;
Benny Prijono572d4852006-11-23 21:50:02 +00002026 pjsua_media_config cfg_media;
Fahris17d91812007-01-29 12:09:33 +00002027 pjsua_media_config * p_cfg_media;
Benny Prijono572d4852006-11-23 21:50:02 +00002028 unsigned i;
2029
Fahris17d91812007-01-29 12:09:33 +00002030 if (!PyArg_ParseTuple(pArgs, "OOO", &ua_cfgObj, &log_cfgObj,&media_cfgObj))
Benny Prijono572d4852006-11-23 21:50:02 +00002031 {
2032 return NULL;
2033 }
2034
Fahris17d91812007-01-29 12:09:33 +00002035
Benny Prijono572d4852006-11-23 21:50:02 +00002036 pjsua_config_default(&cfg_ua);
2037 pjsua_logging_config_default(&cfg_log);
2038 pjsua_media_config_default(&cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +00002039
Fahris6f35cb82007-02-01 07:41:26 +00002040 if (ua_cfgObj != Py_None)
2041 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002042 ua_cfg = (config_Object *)ua_cfgObj;
Fahris17d91812007-01-29 12:09:33 +00002043 cfg_ua.cred_count = ua_cfg->cred_count;
2044 for (i = 0; i < 4; i++)
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002045 {
Fahris17d91812007-01-29 12:09:33 +00002046 cfg_ua.cred_info[i] = ua_cfg->cred_info[i];
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002047 }
Fahris17d91812007-01-29 12:09:33 +00002048 cfg_ua.max_calls = ua_cfg->max_calls;
2049 for (i = 0; i < PJSUA_ACC_MAX_PROXIES; i++)
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002050 {
Fahris17d91812007-01-29 12:09:33 +00002051 cfg_ua.outbound_proxy[i] = ua_cfg->outbound_proxy[i];
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002052 }
2053
2054 g_obj_callback = ua_cfg->cb;
2055 Py_INCREF(g_obj_callback);
2056
2057 cfg_ua.cb.on_call_state = &cb_on_call_state;
2058 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
2059 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
2060 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
2061 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
2062 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
2063 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
2064 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
2065 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
2066 cfg_ua.cb.on_pager = &cb_on_pager;
2067 cfg_ua.cb.on_pager_status = &cb_on_pager_status;
2068 cfg_ua.cb.on_typing = &cb_on_typing;
Benny Prijono572d4852006-11-23 21:50:02 +00002069
Fahris17d91812007-01-29 12:09:33 +00002070 cfg_ua.outbound_proxy_cnt = ua_cfg->outbound_proxy_cnt;
2071 cfg_ua.thread_cnt = ua_cfg->thread_cnt;
2072 cfg_ua.user_agent.ptr = PyString_AsString(ua_cfg->user_agent);
2073 cfg_ua.user_agent.slen = strlen(cfg_ua.user_agent.ptr);
Benny Prijono572d4852006-11-23 21:50:02 +00002074
Fahris17d91812007-01-29 12:09:33 +00002075 p_cfg_ua = &cfg_ua;
2076 } else {
2077 p_cfg_ua = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002078 }
2079
Fahris6f35cb82007-02-01 07:41:26 +00002080 if (log_cfgObj != Py_None)
2081 {
Fahris17d91812007-01-29 12:09:33 +00002082 log_cfg = (logging_config_Object *)log_cfgObj;
2083 cfg_log.msg_logging = log_cfg->msg_logging;
2084 cfg_log.level = log_cfg->level;
2085 cfg_log.console_level = log_cfg->console_level;
2086 cfg_log.decor = log_cfg->decor;
2087 cfg_log.log_filename.ptr = PyString_AsString(log_cfg->log_filename);
2088 cfg_log.log_filename.slen = strlen(cfg_log.log_filename.ptr);
2089 Py_XDECREF(obj_logging_init);
2090 obj_logging_init = log_cfg->cb;
2091 Py_INCREF(obj_logging_init);
2092 cfg_log.cb = &cb_logging_init;
2093 p_cfg_log = &cfg_log;
2094 } else {
2095 p_cfg_log = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002096 }
2097
Fahris6f35cb82007-02-01 07:41:26 +00002098 if (media_cfgObj != Py_None)
2099 {
Fahris17d91812007-01-29 12:09:33 +00002100 media_cfg = (media_config_Object *)media_cfgObj;
2101 cfg_media.clock_rate = media_cfg->clock_rate;
2102 cfg_media.ec_options = media_cfg->ec_options;
2103 cfg_media.ec_tail_len = media_cfg->ec_tail_len;
2104 cfg_media.has_ioqueue = media_cfg->has_ioqueue;
2105 cfg_media.ilbc_mode = media_cfg->ilbc_mode;
2106 cfg_media.max_media_ports = media_cfg->max_media_ports;
2107 cfg_media.no_vad = media_cfg->no_vad;
2108 cfg_media.ptime = media_cfg->ptime;
2109 cfg_media.quality = media_cfg->quality;
2110 cfg_media.rx_drop_pct = media_cfg->rx_drop_pct;
2111 cfg_media.thread_cnt = media_cfg->thread_cnt;
2112 cfg_media.tx_drop_pct = media_cfg->tx_drop_pct;
2113 p_cfg_media = &cfg_media;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002114 } else {
Fahris17d91812007-01-29 12:09:33 +00002115 p_cfg_media = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00002116 }
2117
Fahris17d91812007-01-29 12:09:33 +00002118 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +00002119 return Py_BuildValue("i",status);
2120}
2121
2122
2123/*
2124 * py_pjsua_start
2125 */
2126static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
2127{
2128 pj_status_t status;
2129 if (!PyArg_ParseTuple(pArgs, ""))
2130 {
2131 return NULL;
2132 }
2133 status = pjsua_start();
Fahris89ea3d02007-02-07 08:18:35 +00002134
Benny Prijono572d4852006-11-23 21:50:02 +00002135 return Py_BuildValue("i",status);
2136}
2137
2138
2139/*
2140 * py_pjsua_destroy
2141 */
2142static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
2143{
2144 pj_status_t status;
2145 if (!PyArg_ParseTuple(pArgs, ""))
2146 {
2147 return NULL;
2148 }
2149 status = pjsua_destroy();
Fahris89ea3d02007-02-07 08:18:35 +00002150
Benny Prijono572d4852006-11-23 21:50:02 +00002151 return Py_BuildValue("i",status);
2152}
2153
2154
2155/*
2156 * py_pjsua_handle_events
2157 */
2158static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
2159{
2160 int ret;
2161 unsigned msec;
2162 if (!PyArg_ParseTuple(pArgs, "i", &msec))
2163 {
2164 return NULL;
2165 }
Benny Prijono4759f9c2007-02-14 02:15:19 +00002166
2167 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
2168 * construct, or otherwise many Python blocking functions (such as
2169 * time.sleep(), readline(), etc.) may hang/block indefinitely.
2170 * See http://www.python.org/doc/current/api/threads.html for more info.
2171 */
2172 Py_BEGIN_ALLOW_THREADS
Benny Prijono572d4852006-11-23 21:50:02 +00002173 ret = pjsua_handle_events(msec);
Benny Prijono4759f9c2007-02-14 02:15:19 +00002174 Py_END_ALLOW_THREADS
Fahris89ea3d02007-02-07 08:18:35 +00002175
Benny Prijono572d4852006-11-23 21:50:02 +00002176 return Py_BuildValue("i",ret);
2177}
2178
2179
2180/*
2181 * py_pjsua_verify_sip_url
2182 */
2183static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
2184{
2185 pj_status_t status;
2186 const char *url;
2187 if (!PyArg_ParseTuple(pArgs, "s", &url))
2188 {
2189 return NULL;
2190 }
2191 status = pjsua_verify_sip_url(url);
Fahris89ea3d02007-02-07 08:18:35 +00002192
Benny Prijono572d4852006-11-23 21:50:02 +00002193 return Py_BuildValue("i",status);
2194}
2195
2196
Benny Prijono572d4852006-11-23 21:50:02 +00002197/*
Benny Prijonodc308702006-12-09 00:39:42 +00002198 * function doc
Benny Prijono572d4852006-11-23 21:50:02 +00002199 */
2200
Benny Prijonodc308702006-12-09 00:39:42 +00002201static char pjsua_thread_register_doc[] =
2202 "int py_pjsua.thread_register(string name, int[] desc)";
Benny Prijono572d4852006-11-23 21:50:02 +00002203static char pjsua_perror_doc[] =
2204 "void py_pjsua.perror (string sender, string title, int status) "
2205 "Display error message for the specified error code. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002206 "sender: The log sender field; "
2207 "title: Message title for the error; "
2208 "status: Status code.";
Benny Prijono572d4852006-11-23 21:50:02 +00002209
2210static char pjsua_create_doc[] =
2211 "int py_pjsua.create (void) "
2212 "Instantiate pjsua application. Application "
2213 "must call this function before calling any other functions, to make sure "
2214 "that the underlying libraries are properly initialized. Once this "
2215 "function has returned success, application must call pjsua_destroy() "
2216 "before quitting.";
2217
2218static char pjsua_init_doc[] =
2219 "int py_pjsua.init (py_pjsua.Config ua_cfg, "
2220 "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) "
2221 "Initialize pjsua with the specified settings. All the settings are "
2222 "optional, and the default values will be used when the config is not "
2223 "specified. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002224 "ua_cfg : User agent configuration; "
2225 "log_cfg : Optional logging configuration; "
2226 "media_cfg : Optional media configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00002227
2228static char pjsua_start_doc[] =
2229 "int py_pjsua.start (void) "
2230 "Application is recommended to call this function after all "
2231 "initialization is done, so that the library can do additional checking "
2232 "set up additional";
2233
2234static char pjsua_destroy_doc[] =
2235 "int py_pjsua.destroy (void) "
2236 "Destroy pjsua This function must be called once PJSUA is created. To "
2237 "make it easier for application, application may call this function "
2238 "several times with no danger.";
2239
2240static char pjsua_handle_events_doc[] =
2241 "int py_pjsua.handle_events (int msec_timeout) "
2242 "Poll pjsua for events, and if necessary block the caller thread for the "
2243 "specified maximum interval (in miliseconds) Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002244 "msec_timeout: Maximum time to wait, in miliseconds. "
Benny Prijono572d4852006-11-23 21:50:02 +00002245 "Returns: The number of events that have been handled during the poll. "
2246 "Negative value indicates error, and application can retrieve the error "
2247 "as (err = -return_value).";
2248
2249static char pjsua_verify_sip_url_doc[] =
2250 "int py_pjsua.verify_sip_url (string c_url) "
2251 "Verify that valid SIP url is given Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002252 "c_url: The URL, as NULL terminated string.";
Benny Prijono572d4852006-11-23 21:50:02 +00002253
2254static char pjsua_pool_create_doc[] =
2255 "py_pjsua.PJ_Pool py_pjsua.pool_create (string name, int init_size, "
2256 "int increment) "
2257 "Create memory pool Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002258 "name: Optional pool name; "
2259 "init_size: Initial size of the pool; "
2260 "increment: Increment size.";
Benny Prijono572d4852006-11-23 21:50:02 +00002261
2262static char pjsua_get_pjsip_endpt_doc[] =
2263 "py_pjsua.PJSIP_Endpoint py_pjsua.get_pjsip_endpt (void) "
2264 "Internal function to get SIP endpoint instance of pjsua, which is needed "
2265 "for example to register module, create transports, etc. Probably is only "
2266 "valid after pjsua_init() is called.";
2267
2268static char pjsua_get_pjmedia_endpt_doc[] =
2269 "py_pjsua.PJMedia_Endpt py_pjsua.get_pjmedia_endpt (void) "
2270 "Internal function to get media endpoint instance. Only valid after "
2271 "pjsua_init() is called.";
2272
2273static char pjsua_get_pool_factory_doc[] =
2274 "py_pjsua.PJ_Pool_Factory py_pjsua.get_pool_factory (void) "
2275 "Internal function to get PJSUA pool factory. Only valid after "
2276 "pjsua_init() is called.";
2277
2278static char pjsua_reconfigure_logging_doc[] =
2279 "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) "
2280 "Application can call this function at any time (after pjsua_create(), of "
2281 "course) to change logging settings. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002282 "c: Logging configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00002283
2284static char pjsua_logging_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002285 "py_pjsua.Logging_Config py_pjsua.logging_config_default () "
Benny Prijono572d4852006-11-23 21:50:02 +00002286 "Use this function to initialize logging config.";
2287
2288static char pjsua_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002289 "py_pjsua.Config py_pjsua.config_default (). Use this function to "
2290 "initialize pjsua config. ";
Benny Prijono572d4852006-11-23 21:50:02 +00002291
2292static char pjsua_media_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002293 "py_pjsua.Media_Config py_pjsua.media_config_default (). "
Benny Prijono572d4852006-11-23 21:50:02 +00002294 "Use this function to initialize media config.";
2295
Benny Prijono572d4852006-11-23 21:50:02 +00002296static char pjsua_msg_data_init_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002297 "py_pjsua.Msg_Data void py_pjsua.msg_data_init () "
2298 "Initialize message data ";
2299
Benny Prijono572d4852006-11-23 21:50:02 +00002300
Benny Prijono98793592006-12-04 08:33:20 +00002301/* END OF LIB BASE */
2302
2303/* LIB TRANSPORT */
2304
2305/*
2306 * stun_config_Object
2307 * STUN configuration
2308 */
2309typedef struct
2310{
2311 PyObject_HEAD
2312 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002313 PyObject * stun_srv1;
Benny Prijono98793592006-12-04 08:33:20 +00002314 unsigned stun_port1;
2315 PyObject * stun_srv2;
2316 unsigned stun_port2;
2317} stun_config_Object;
2318
2319
2320/*
2321 * stun_config_dealloc
2322 * deletes a stun config from memory
2323 */
2324static void stun_config_dealloc(stun_config_Object* self)
2325{
2326 Py_XDECREF(self->stun_srv1);
2327 Py_XDECREF(self->stun_srv2);
2328 self->ob_type->tp_free((PyObject*)self);
2329}
2330
2331
2332/*
2333 * stun_config_new
2334 * constructor for stun_config object
2335 */
2336static PyObject * stun_config_new(PyTypeObject *type, PyObject *args,
2337 PyObject *kwds)
2338{
2339 stun_config_Object *self;
2340 self = (stun_config_Object *)type->tp_alloc(type, 0);
2341 if (self != NULL)
2342 {
2343 self->stun_srv1 = PyString_FromString("");
2344 if (self->stun_srv1 == NULL)
2345 {
2346 Py_DECREF(self);
2347 return NULL;
2348 }
2349 self->stun_srv2 = PyString_FromString("");
2350 if (self->stun_srv2 == NULL)
2351 {
2352 Py_DECREF(self);
2353 return NULL;
2354 }
2355 }
2356
2357 return (PyObject *)self;
2358}
2359
2360
2361/*
2362 * stun_config_members
2363 */
2364static PyMemberDef stun_config_members[] =
2365{
2366 {
Benny Prijonodc308702006-12-09 00:39:42 +00002367 "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0,
2368 "The first STUN server IP address or hostname."
Benny Prijono98793592006-12-04 08:33:20 +00002369 },
2370 {
Benny Prijonodc308702006-12-09 00:39:42 +00002371 "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0,
2372 "Port number of the second STUN server. "
2373 "If zero, default STUN port will be used."
Benny Prijono98793592006-12-04 08:33:20 +00002374 },
2375 {
Benny Prijonodc308702006-12-09 00:39:42 +00002376 "stun_srv1", T_OBJECT_EX,
2377 offsetof(stun_config_Object, stun_srv1), 0,
2378 "The first STUN server IP address or hostname"
Benny Prijono98793592006-12-04 08:33:20 +00002379 },
2380 {
Benny Prijonodc308702006-12-09 00:39:42 +00002381 "stun_srv2", T_OBJECT_EX,
2382 offsetof(stun_config_Object, stun_srv2), 0,
2383 "Optional second STUN server IP address or hostname, for which the "
2384 "result of the mapping request will be compared to. If the value "
2385 "is empty, only one STUN server will be used"
Benny Prijono98793592006-12-04 08:33:20 +00002386 },
2387 {NULL} /* Sentinel */
2388};
2389
2390
2391
2392
2393/*
2394 * stun_config_Type
2395 */
2396static PyTypeObject stun_config_Type =
2397{
2398 PyObject_HEAD_INIT(NULL)
2399 0, /*ob_size*/
2400 "py_pjsua.STUN_Config", /*tp_name*/
2401 sizeof(stun_config_Object), /*tp_basicsize*/
2402 0, /*tp_itemsize*/
2403 (destructor)stun_config_dealloc,/*tp_dealloc*/
2404 0, /*tp_print*/
2405 0, /*tp_getattr*/
2406 0, /*tp_setattr*/
2407 0, /*tp_compare*/
2408 0, /*tp_repr*/
2409 0, /*tp_as_number*/
2410 0, /*tp_as_sequence*/
2411 0, /*tp_as_mapping*/
2412 0, /*tp_hash */
2413 0, /*tp_call*/
2414 0, /*tp_str*/
2415 0, /*tp_getattro*/
2416 0, /*tp_setattro*/
2417 0, /*tp_as_buffer*/
2418 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2419 "STUN Config objects", /* tp_doc */
2420 0, /* tp_traverse */
2421 0, /* tp_clear */
2422 0, /* tp_richcompare */
2423 0, /* tp_weaklistoffset */
2424 0, /* tp_iter */
2425 0, /* tp_iternext */
2426 0, /* tp_methods */
2427 stun_config_members, /* tp_members */
2428 0, /* tp_getset */
2429 0, /* tp_base */
2430 0, /* tp_dict */
2431 0, /* tp_descr_get */
2432 0, /* tp_descr_set */
2433 0, /* tp_dictoffset */
2434 0, /* tp_init */
2435 0, /* tp_alloc */
2436 stun_config_new, /* tp_new */
2437
2438};
2439
2440/*
2441 * transport_config_Object
2442 * Transport configuration for creating UDP transports for both SIP
2443 * and media.
2444 */
2445typedef struct
2446{
2447 PyObject_HEAD
2448 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002449 unsigned port;
2450 PyObject * public_addr;
2451 PyObject * bound_addr;
2452 int use_stun;
2453 stun_config_Object * stun_config;
Benny Prijono98793592006-12-04 08:33:20 +00002454} transport_config_Object;
2455
2456
2457/*
2458 * transport_config_dealloc
2459 * deletes a transport config from memory
2460 */
2461static void transport_config_dealloc(transport_config_Object* self)
2462{
Benny Prijonodc308702006-12-09 00:39:42 +00002463 Py_XDECREF(self->public_addr);
2464 Py_XDECREF(self->bound_addr);
Benny Prijono98793592006-12-04 08:33:20 +00002465 Py_XDECREF(self->stun_config);
2466 self->ob_type->tp_free((PyObject*)self);
2467}
2468
2469
2470/*
2471 * transport_config_new
2472 * constructor for transport_config object
2473 */
2474static PyObject * transport_config_new(PyTypeObject *type, PyObject *args,
2475 PyObject *kwds)
2476{
2477 transport_config_Object *self;
2478
2479 self = (transport_config_Object *)type->tp_alloc(type, 0);
2480 if (self != NULL)
2481 {
Fahris6f35cb82007-02-01 07:41:26 +00002482 self->public_addr = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002483 if (self->public_addr == NULL)
2484 {
2485 Py_DECREF(self);
2486 return NULL;
2487 }
2488 self->bound_addr = PyString_FromString("");
2489 if (self->bound_addr == NULL)
2490 {
2491 Py_DECREF(self);
2492 return NULL;
2493 }
2494 self->stun_config =
Benny Prijonodc308702006-12-09 00:39:42 +00002495 (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002496 if (self->stun_config == NULL)
2497 {
2498 Py_DECREF(self);
2499 return NULL;
2500 }
2501
2502 }
2503
2504 return (PyObject *)self;
2505}
2506
2507
2508/*
2509 * transport_config_members
2510 */
2511static PyMemberDef transport_config_members[] =
2512{
2513 {
Benny Prijonodc308702006-12-09 00:39:42 +00002514 "port", T_INT, offsetof(transport_config_Object, port), 0,
2515 "UDP port number to bind locally. This setting MUST be specified "
2516 "even when default port is desired. If the value is zero, the "
2517 "transport will be bound to any available port, and application "
2518 "can query the port by querying the transport info."
Benny Prijono98793592006-12-04 08:33:20 +00002519 },
2520 {
Benny Prijonodc308702006-12-09 00:39:42 +00002521 "public_addr", T_OBJECT_EX,
2522 offsetof(transport_config_Object, public_addr), 0,
2523 "Optional address to advertise as the address of this transport. "
2524 "Application can specify any address or hostname for this field, "
2525 "for example it can point to one of the interface address in the "
2526 "system, or it can point to the public address of a NAT router "
2527 "where port mappings have been configured for the application."
Benny Prijono98793592006-12-04 08:33:20 +00002528 },
2529 {
Benny Prijonodc308702006-12-09 00:39:42 +00002530 "bound_addr", T_OBJECT_EX,
2531 offsetof(transport_config_Object, bound_addr), 0,
2532 "Optional address where the socket should be bound to. This option "
2533 "SHOULD only be used to selectively bind the socket to particular "
2534 "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the "
2535 "published address of a transport (the public_addr field should be "
2536 "used for that purpose)."
2537 },
2538 {
2539 "use_stun", T_INT,
2540 offsetof(transport_config_Object, use_stun), 0,
2541 "Flag to indicate whether STUN should be used."
Benny Prijono98793592006-12-04 08:33:20 +00002542 },
2543 {
Benny Prijonodc308702006-12-09 00:39:42 +00002544 "stun_config", T_OBJECT_EX,
2545 offsetof(transport_config_Object, stun_config), 0,
2546 "STUN configuration, must be specified when STUN is used."
Benny Prijono98793592006-12-04 08:33:20 +00002547 },
2548 {NULL} /* Sentinel */
2549};
2550
2551
2552
2553
2554/*
2555 * transport_config_Type
2556 */
2557static PyTypeObject transport_config_Type =
2558{
2559 PyObject_HEAD_INIT(NULL)
2560 0, /*ob_size*/
2561 "py_pjsua.Transport_Config", /*tp_name*/
2562 sizeof(transport_config_Object), /*tp_basicsize*/
2563 0, /*tp_itemsize*/
2564 (destructor)transport_config_dealloc,/*tp_dealloc*/
2565 0, /*tp_print*/
2566 0, /*tp_getattr*/
2567 0, /*tp_setattr*/
2568 0, /*tp_compare*/
2569 0, /*tp_repr*/
2570 0, /*tp_as_number*/
2571 0, /*tp_as_sequence*/
2572 0, /*tp_as_mapping*/
2573 0, /*tp_hash */
2574 0, /*tp_call*/
2575 0, /*tp_str*/
2576 0, /*tp_getattro*/
2577 0, /*tp_setattro*/
2578 0, /*tp_as_buffer*/
2579 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2580 "Transport Config objects", /* tp_doc */
2581 0, /* tp_traverse */
2582 0, /* tp_clear */
2583 0, /* tp_richcompare */
2584 0, /* tp_weaklistoffset */
2585 0, /* tp_iter */
2586 0, /* tp_iternext */
2587 0, /* tp_methods */
2588 transport_config_members, /* tp_members */
2589 0, /* tp_getset */
2590 0, /* tp_base */
2591 0, /* tp_dict */
2592 0, /* tp_descr_get */
2593 0, /* tp_descr_set */
2594 0, /* tp_dictoffset */
2595 0, /* tp_init */
2596 0, /* tp_alloc */
2597 transport_config_new, /* tp_new */
2598
2599};
2600
2601/*
2602 * sockaddr_Object
2603 * C/Python wrapper for sockaddr object
2604 */
2605typedef struct
2606{
2607 PyObject_HEAD
2608 /* Type-specific fields go here. */
2609#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
2610 pj_uint8_t sa_zero_len;
2611 pj_uint8_t sa_family;
2612#else
2613 pj_uint16_t sa_family; /**< Common data: address family. */
2614#endif
2615 PyObject * sa_data; /**< Address data. */
2616} sockaddr_Object;
2617
2618/*
2619 * sockaddr_dealloc
2620 * deletes a sockaddr from memory
2621 */
2622static void sockaddr_dealloc(sockaddr_Object* self)
2623{
2624 Py_XDECREF(self->sa_data);
2625 self->ob_type->tp_free((PyObject*)self);
2626}
2627
2628
2629/*
2630 * sockaddr_new
2631 * constructor for sockaddr object
2632 */
2633static PyObject * sockaddr_new(PyTypeObject *type, PyObject *args,
2634 PyObject *kwds)
2635{
2636 sockaddr_Object *self;
2637
2638 self = (sockaddr_Object *)type->tp_alloc(type, 0);
2639 if (self != NULL)
2640 {
2641 self->sa_data = PyString_FromString("");
2642 if (self->sa_data == NULL)
2643 {
2644 Py_DECREF(self);
2645 return NULL;
2646 }
2647
2648 }
2649
2650 return (PyObject *)self;
2651}
2652
2653
2654/*
2655 * sockaddr_members
2656 * declares attributes accessible from both C and Python for sockaddr object
2657 */
2658static PyMemberDef sockaddr_members[] =
2659{
2660#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
2661 {
2662 "sa_zero_len", T_INT, offsetof(sockaddr_Object, sa_zero_len), 0,
2663 ""
2664 },
2665 {
2666 "sa_family", T_INT,
2667 offsetof(sockaddr_Object, sa_family), 0,
2668 "Common data: address family."
2669 },
2670#else
2671 {
2672 "sa_family", T_INT,
2673 offsetof(sockaddr_Object, sa_family), 0,
2674 "Common data: address family."
2675 },
2676#endif
2677 {
Benny Prijonodc308702006-12-09 00:39:42 +00002678 "sa_data", T_OBJECT_EX,
2679 offsetof(sockaddr_Object, sa_data), 0,
2680 "Address data"
Benny Prijono98793592006-12-04 08:33:20 +00002681 },
2682 {NULL} /* Sentinel */
2683};
2684
2685
2686/*
2687 * sockaddr_Type
2688 */
2689static PyTypeObject sockaddr_Type =
2690{
2691 PyObject_HEAD_INIT(NULL)
2692 0, /*ob_size*/
2693 "py_pjsua.Sockaddr", /*tp_name*/
2694 sizeof(sockaddr_Object), /*tp_basicsize*/
2695 0, /*tp_itemsize*/
2696 (destructor)sockaddr_dealloc,/*tp_dealloc*/
2697 0, /*tp_print*/
2698 0, /*tp_getattr*/
2699 0, /*tp_setattr*/
2700 0, /*tp_compare*/
2701 0, /*tp_repr*/
2702 0, /*tp_as_number*/
2703 0, /*tp_as_sequence*/
2704 0, /*tp_as_mapping*/
2705 0, /*tp_hash */
2706 0, /*tp_call*/
2707 0, /*tp_str*/
2708 0, /*tp_getattro*/
2709 0, /*tp_setattro*/
2710 0, /*tp_as_buffer*/
2711 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2712 "Sockaddr objects", /*tp_doc*/
2713 0, /*tp_traverse*/
2714 0, /*tp_clear*/
2715 0, /*tp_richcompare*/
2716 0, /* tp_weaklistoffset */
2717 0, /* tp_iter */
2718 0, /* tp_iternext */
2719 0, /* tp_methods */
2720 sockaddr_members, /* tp_members */
2721 0, /* tp_getset */
2722 0, /* tp_base */
2723 0, /* tp_dict */
2724 0, /* tp_descr_get */
2725 0, /* tp_descr_set */
2726 0, /* tp_dictoffset */
2727 0, /* tp_init */
2728 0, /* tp_alloc */
2729 sockaddr_new, /* tp_new */
2730};
2731
2732/*
2733 * host_port_Object
2734 * C/Python wrapper for host_port object
2735 */
2736typedef struct
2737{
2738 PyObject_HEAD
2739 /* Type-specific fields go here. */
2740 PyObject * host;
Fahris6f35cb82007-02-01 07:41:26 +00002741 int port;
Benny Prijono98793592006-12-04 08:33:20 +00002742} host_port_Object;
2743
2744/*
2745 * host_port_dealloc
2746 * deletes a host_port from memory
2747 */
2748static void host_port_dealloc(host_port_Object* self)
2749{
2750 Py_XDECREF(self->host);
2751 self->ob_type->tp_free((PyObject*)self);
2752}
2753
2754
2755/*
2756 * host_port_new
2757 * constructor for host_port object
2758 */
2759static PyObject * host_port_new(PyTypeObject *type, PyObject *args,
2760 PyObject *kwds)
2761{
2762 host_port_Object *self;
2763
2764 self = (host_port_Object *)type->tp_alloc(type, 0);
2765 if (self != NULL)
2766 {
2767 self->host = PyString_FromString("");
2768 if (self->host == NULL)
2769 {
2770 Py_DECREF(self);
2771 return NULL;
2772 }
2773
2774 }
2775
2776 return (PyObject *)self;
2777}
2778
2779
2780/*
2781 * host_port_members
2782 * declares attributes accessible from both C and Python for host_port object
2783 */
2784static PyMemberDef host_port_members[] =
2785{
2786 {
2787 "port", T_INT,
2788 offsetof(host_port_Object, port), 0,
2789 "Port number."
2790 },
2791 {
Benny Prijonodc308702006-12-09 00:39:42 +00002792 "host", T_OBJECT_EX,
2793 offsetof(host_port_Object, host), 0,
2794 "Host part or IP address."
Benny Prijono98793592006-12-04 08:33:20 +00002795 },
2796 {NULL} /* Sentinel */
2797};
2798
2799
2800/*
2801 * host_port_Type
2802 */
2803static PyTypeObject host_port_Type =
2804{
2805 PyObject_HEAD_INIT(NULL)
2806 0, /*ob_size*/
2807 "py_pjsua.Host_Port", /*tp_name*/
2808 sizeof(host_port_Object), /*tp_basicsize*/
2809 0, /*tp_itemsize*/
2810 (destructor)host_port_dealloc,/*tp_dealloc*/
2811 0, /*tp_print*/
2812 0, /*tp_getattr*/
2813 0, /*tp_setattr*/
2814 0, /*tp_compare*/
2815 0, /*tp_repr*/
2816 0, /*tp_as_number*/
2817 0, /*tp_as_sequence*/
2818 0, /*tp_as_mapping*/
2819 0, /*tp_hash */
2820 0, /*tp_call*/
2821 0, /*tp_str*/
2822 0, /*tp_getattro*/
2823 0, /*tp_setattro*/
2824 0, /*tp_as_buffer*/
2825 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2826 "Host_port objects", /*tp_doc*/
2827 0, /*tp_traverse*/
2828 0, /*tp_clear*/
2829 0, /*tp_richcompare*/
2830 0, /* tp_weaklistoffset */
2831 0, /* tp_iter */
2832 0, /* tp_iternext */
2833 0, /* tp_methods */
2834 host_port_members, /* tp_members */
2835 0, /* tp_getset */
2836 0, /* tp_base */
2837 0, /* tp_dict */
2838 0, /* tp_descr_get */
2839 0, /* tp_descr_set */
2840 0, /* tp_dictoffset */
2841 0, /* tp_init */
2842 0, /* tp_alloc */
2843 host_port_new, /* tp_new */
2844};
2845
Benny Prijono98793592006-12-04 08:33:20 +00002846
2847
Benny Prijono98793592006-12-04 08:33:20 +00002848
2849/*
2850 * transport_info_Object
2851 * Transport info
2852 */
2853typedef struct
2854{
2855 PyObject_HEAD
2856 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002857 int id;
2858 int type;
2859 PyObject * type_name;
2860 PyObject * info;
2861 unsigned flag;
2862 unsigned addr_len;
2863 sockaddr_Object * local_addr;
2864 host_port_Object * local_name;
2865 unsigned usage_count;
Benny Prijono98793592006-12-04 08:33:20 +00002866} transport_info_Object;
2867
2868
2869/*
2870 * transport_info_dealloc
2871 * deletes a transport info from memory
2872 */
2873static void transport_info_dealloc(transport_info_Object* self)
2874{
2875 Py_XDECREF(self->type_name);
Benny Prijonodc308702006-12-09 00:39:42 +00002876 Py_XDECREF(self->info);
2877 Py_XDECREF(self->local_addr);
2878 Py_XDECREF(self->local_name);
Benny Prijono98793592006-12-04 08:33:20 +00002879 self->ob_type->tp_free((PyObject*)self);
2880}
2881
2882
2883/*
2884 * transport_info_new
2885 * constructor for transport_info object
2886 */
2887static PyObject * transport_info_new(PyTypeObject *type, PyObject *args,
2888 PyObject *kwds)
2889{
2890 transport_info_Object *self;
2891
2892 self = (transport_info_Object *)type->tp_alloc(type, 0);
2893 if (self != NULL)
2894 {
Benny Prijonodc308702006-12-09 00:39:42 +00002895 self->type_name = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002896 if (self->type_name == NULL)
2897 {
2898 Py_DECREF(self);
2899 return NULL;
2900 }
Benny Prijonodc308702006-12-09 00:39:42 +00002901 self->info = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002902 if (self->info == NULL)
2903 {
2904 Py_DECREF(self);
2905 return NULL;
2906 }
2907 self->local_addr =
Benny Prijonodc308702006-12-09 00:39:42 +00002908 (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002909 if (self->local_addr == NULL)
2910 {
2911 Py_DECREF(self);
2912 return NULL;
2913 }
2914 self->local_name =
Benny Prijonodc308702006-12-09 00:39:42 +00002915 (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002916 if (self->local_name == NULL)
2917 {
2918 Py_DECREF(self);
2919 return NULL;
2920 }
2921 }
2922
2923 return (PyObject *)self;
2924}
2925
2926
2927/*
2928 * transport_info_members
2929 */
2930static PyMemberDef transport_info_members[] =
2931{
Benny Prijonodc308702006-12-09 00:39:42 +00002932 {
2933 "id", T_INT, offsetof(transport_info_Object, id), 0,
2934 "PJSUA transport identification."
Benny Prijono98793592006-12-04 08:33:20 +00002935 },
Benny Prijonodc308702006-12-09 00:39:42 +00002936 {
2937 "type", T_INT, offsetof(transport_info_Object, id), 0,
2938 "Transport type."
Benny Prijono98793592006-12-04 08:33:20 +00002939 },
Benny Prijonodc308702006-12-09 00:39:42 +00002940 {
2941 "type_name", T_OBJECT_EX,
2942 offsetof(transport_info_Object, type_name), 0,
2943 "Transport type name."
Benny Prijono98793592006-12-04 08:33:20 +00002944 },
Benny Prijonodc308702006-12-09 00:39:42 +00002945 {
2946 "info", T_OBJECT_EX,
2947 offsetof(transport_info_Object, info), 0,
2948 "Transport string info/description."
Benny Prijono98793592006-12-04 08:33:20 +00002949 },
Benny Prijonodc308702006-12-09 00:39:42 +00002950 {
2951 "flag", T_INT, offsetof(transport_info_Object, flag), 0,
2952 "Transport flag (see ##pjsip_transport_flags_e)."
Benny Prijono98793592006-12-04 08:33:20 +00002953 },
Benny Prijonodc308702006-12-09 00:39:42 +00002954 {
2955 "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0,
2956 "Local address length."
Benny Prijono98793592006-12-04 08:33:20 +00002957 },
Benny Prijonodc308702006-12-09 00:39:42 +00002958 {
2959 "local_addr", T_OBJECT_EX,
2960 offsetof(transport_info_Object, local_addr), 0,
2961 "Local/bound address."
Benny Prijono98793592006-12-04 08:33:20 +00002962 },
Benny Prijonodc308702006-12-09 00:39:42 +00002963 {
2964 "local_name", T_OBJECT_EX,
2965 offsetof(transport_info_Object, local_name), 0,
2966 "Published address (or transport address name)."
Benny Prijono98793592006-12-04 08:33:20 +00002967 },
Benny Prijonodc308702006-12-09 00:39:42 +00002968 {
2969 "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0,
2970 "Current number of objects currently referencing this transport."
Benny Prijono98793592006-12-04 08:33:20 +00002971 },
2972 {NULL} /* Sentinel */
2973};
2974
2975
2976
2977
2978/*
2979 * transport_info_Type
2980 */
2981static PyTypeObject transport_info_Type =
2982{
2983 PyObject_HEAD_INIT(NULL)
2984 0, /*ob_size*/
2985 "py_pjsua.Transport_Info", /*tp_name*/
2986 sizeof(transport_info_Object), /*tp_basicsize*/
2987 0, /*tp_itemsize*/
2988 (destructor)transport_info_dealloc,/*tp_dealloc*/
2989 0, /*tp_print*/
2990 0, /*tp_getattr*/
2991 0, /*tp_setattr*/
2992 0, /*tp_compare*/
2993 0, /*tp_repr*/
2994 0, /*tp_as_number*/
2995 0, /*tp_as_sequence*/
2996 0, /*tp_as_mapping*/
2997 0, /*tp_hash */
2998 0, /*tp_call*/
2999 0, /*tp_str*/
3000 0, /*tp_getattro*/
3001 0, /*tp_setattro*/
3002 0, /*tp_as_buffer*/
3003 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3004 "Transport Info objects", /* tp_doc */
3005 0, /* tp_traverse */
3006 0, /* tp_clear */
3007 0, /* tp_richcompare */
3008 0, /* tp_weaklistoffset */
3009 0, /* tp_iter */
3010 0, /* tp_iternext */
3011 0, /* tp_methods */
3012 transport_info_members, /* tp_members */
3013 0, /* tp_getset */
3014 0, /* tp_base */
3015 0, /* tp_dict */
3016 0, /* tp_descr_get */
3017 0, /* tp_descr_set */
3018 0, /* tp_dictoffset */
3019 0, /* tp_init */
3020 0, /* tp_alloc */
3021 transport_info_new, /* tp_new */
3022
3023};
3024
3025/*
3026 * pjsip_transport_Object
3027 * C/python typewrapper for pjsip_transport
3028 */
3029typedef struct
3030{
3031 PyObject_HEAD
3032 /* Type-specific fields go here. */
3033 pjsip_transport *tp;
3034} pjsip_transport_Object;
3035
3036
3037/*
3038 * pjsip_transport_Type
3039 */
3040static PyTypeObject pjsip_transport_Type =
3041{
3042 PyObject_HEAD_INIT(NULL)
3043 0, /*ob_size*/
3044 "py_pjsua.PJSIP_Transport", /*tp_name*/
3045 sizeof(pjsip_transport_Object), /*tp_basicsize*/
3046 0, /*tp_itemsize*/
3047 0, /*tp_dealloc*/
3048 0, /*tp_print*/
3049 0, /*tp_getattr*/
3050 0, /*tp_setattr*/
3051 0, /*tp_compare*/
3052 0, /*tp_repr*/
3053 0, /*tp_as_number*/
3054 0, /*tp_as_sequence*/
3055 0, /*tp_as_mapping*/
3056 0, /*tp_hash */
3057 0, /*tp_call*/
3058 0, /*tp_str*/
3059 0, /*tp_getattro*/
3060 0, /*tp_setattro*/
3061 0, /*tp_as_buffer*/
3062 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3063 "pjsip_transport objects", /*tp_doc*/
3064};
3065
3066
3067/*
3068 * py_pjsua_stun_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003069 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003070 */
3071static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs)
3072{
3073 stun_config_Object *obj;
3074 pjsua_stun_config cfg;
3075
Benny Prijonodc308702006-12-09 00:39:42 +00003076 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003077 {
3078 return NULL;
3079 }
Benny Prijonodc308702006-12-09 00:39:42 +00003080
Benny Prijono98793592006-12-04 08:33:20 +00003081 pjsua_stun_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00003082 obj = (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003083 obj->stun_port1 = cfg.stun_port1;
Benny Prijonodc308702006-12-09 00:39:42 +00003084 obj->stun_port2 = cfg.stun_port2;
3085 Py_XDECREF(obj->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003086 obj->stun_srv1 =
Benny Prijonodc308702006-12-09 00:39:42 +00003087 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen);
3088 Py_XDECREF(obj->stun_srv2);
3089 obj->stun_srv2 =
3090 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen);
3091 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003092}
3093
3094/*
3095 * py_pjsua_transport_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003096 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003097 */
3098static PyObject *py_pjsua_transport_config_default
3099(PyObject *pSelf, PyObject *pArgs)
3100{
3101 transport_config_Object *obj;
3102 pjsua_transport_config cfg;
3103
Benny Prijonodc308702006-12-09 00:39:42 +00003104 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003105 {
3106 return NULL;
3107 }
3108 pjsua_transport_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00003109 obj = (transport_config_Object *)transport_config_new
Benny Prijonodc308702006-12-09 00:39:42 +00003110 (&transport_config_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003111 obj->public_addr =
Benny Prijonodc308702006-12-09 00:39:42 +00003112 PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen);
3113 obj->bound_addr =
3114 PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen);
3115 obj->port = cfg.port;
3116 obj->use_stun = cfg.use_stun;
3117 Py_XDECREF(obj->stun_config);
3118 obj->stun_config =
3119 (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003120 obj->stun_config->stun_port1 = cfg.stun_config.stun_port1;
Benny Prijonodc308702006-12-09 00:39:42 +00003121 obj->stun_config->stun_port2 = cfg.stun_config.stun_port2;
3122 Py_XDECREF(obj->stun_config->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003123 obj->stun_config->stun_srv1 =
Benny Prijonodc308702006-12-09 00:39:42 +00003124 PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr,
3125 cfg.stun_config.stun_srv1.slen);
3126 Py_XDECREF(obj->stun_config->stun_srv2);
3127 obj->stun_config->stun_srv2 =
3128 PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr,
3129 cfg.stun_config.stun_srv2.slen);
3130 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003131}
3132
3133/*
3134 * py_pjsua_normalize_stun_config
3135 */
3136static PyObject *py_pjsua_normalize_stun_config
3137(PyObject *pSelf, PyObject *pArgs)
3138{
Fahris6f35cb82007-02-01 07:41:26 +00003139 PyObject * tmpObj;
Benny Prijono98793592006-12-04 08:33:20 +00003140 stun_config_Object *obj;
Benny Prijono40d2cc72007-02-14 01:45:08 +00003141 pjsua_stun_config cfg;
Benny Prijono98793592006-12-04 08:33:20 +00003142
Fahris17d91812007-01-29 12:09:33 +00003143 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003144 {
3145 return NULL;
3146 }
Benny Prijono40d2cc72007-02-14 01:45:08 +00003147
3148 if (tmpObj == Py_None) {
3149 Py_INCREF(Py_None);
3150 return Py_None;
Fahris6f35cb82007-02-01 07:41:26 +00003151 }
Benny Prijono40d2cc72007-02-14 01:45:08 +00003152
3153 obj = (stun_config_Object *) tmpObj;
3154 cfg.stun_port1 = obj->stun_port1;
3155 cfg.stun_port2 = obj->stun_port2;
3156 cfg.stun_srv1.ptr = PyString_AsString(obj->stun_srv1);
3157 cfg.stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1));
3158 cfg.stun_srv2.ptr = PyString_AsString(obj->stun_srv2);
3159 cfg.stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2));
3160
3161 pjsua_normalize_stun_config(&cfg);
3162 obj->stun_port1 = cfg.stun_port1;
3163 obj->stun_port2 = cfg.stun_port2;
Benny Prijonodc308702006-12-09 00:39:42 +00003164 Py_XDECREF(obj->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003165 obj->stun_srv1 =
Benny Prijono40d2cc72007-02-14 01:45:08 +00003166 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen);
Benny Prijonodc308702006-12-09 00:39:42 +00003167 Py_XDECREF(obj->stun_srv2);
3168 obj->stun_srv2 =
Benny Prijono40d2cc72007-02-14 01:45:08 +00003169 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen);
3170
Benny Prijono98793592006-12-04 08:33:20 +00003171 Py_INCREF(Py_None);
3172 return Py_None;
3173}
3174
3175/*
3176 * py_pjsua_transport_create
Benny Prijonodc308702006-12-09 00:39:42 +00003177 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003178 */
3179static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
3180{
3181 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003182 int type;
3183
Fahris6f35cb82007-02-01 07:41:26 +00003184 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003185 transport_config_Object *obj;
3186 pjsua_transport_config cfg;
3187 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003188 if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003189 {
3190 return NULL;
3191 }
Fahris6f35cb82007-02-01 07:41:26 +00003192 if (tmpObj != Py_None)
3193 {
Fahris17d91812007-01-29 12:09:33 +00003194 obj = (transport_config_Object *)tmpObj;
3195 cfg.public_addr.ptr = PyString_AsString(obj->public_addr);
3196 cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr));
3197 cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr);
3198 cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr));
3199 cfg.port = obj->port;
3200 cfg.use_stun = obj->use_stun;
3201 cfg.stun_config.stun_port1 = obj->stun_config->stun_port1;
3202 cfg.stun_config.stun_port2 = obj->stun_config->stun_port2;
3203 cfg.stun_config.stun_srv1.ptr =
3204 PyString_AsString(obj->stun_config->stun_srv1);
3205 cfg.stun_config.stun_srv1.slen =
3206 strlen(PyString_AsString(obj->stun_config->stun_srv1));
3207 cfg.stun_config.stun_srv2.ptr =
3208 PyString_AsString(obj->stun_config->stun_srv2);
3209 cfg.stun_config.stun_srv2.slen =
3210 strlen(PyString_AsString(obj->stun_config->stun_srv2));
3211 status = pjsua_transport_create(type, &cfg, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003212 } else {
Fahris17d91812007-01-29 12:09:33 +00003213 status = pjsua_transport_create(type, NULL, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003214 }
Benny Prijonodc308702006-12-09 00:39:42 +00003215
3216
3217 return Py_BuildValue("ii",status,id);
Benny Prijono98793592006-12-04 08:33:20 +00003218}
3219
3220/*
3221 * py_pjsua_transport_register
Benny Prijonodc308702006-12-09 00:39:42 +00003222 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003223 */
3224static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs)
3225{
Benny Prijonodc308702006-12-09 00:39:42 +00003226 pj_status_t status;
Fahris6f35cb82007-02-01 07:41:26 +00003227 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003228 pjsip_transport_Object *obj;
3229 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003230 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003231 {
3232 return NULL;
3233 }
Fahris17d91812007-01-29 12:09:33 +00003234 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003235 {
Fahris17d91812007-01-29 12:09:33 +00003236 obj = (pjsip_transport_Object *)tmpObj;
3237 status = pjsua_transport_register(obj->tp, &id);
3238 } else {
3239 status = pjsua_transport_register(NULL, &id);
3240 }
Benny Prijonodc308702006-12-09 00:39:42 +00003241
3242 return Py_BuildValue("ii",status, id);
Benny Prijono98793592006-12-04 08:33:20 +00003243}
3244
3245/*
3246 * py_pjsua_enum_transports
Fahrisdcf8fa42006-12-28 03:13:48 +00003247 * !modified @ 261206
Benny Prijono98793592006-12-04 08:33:20 +00003248 */
3249static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
3250{
3251 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003252 PyObject *list;
3253
Fahrisdcf8fa42006-12-28 03:13:48 +00003254 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
Fahris17d91812007-01-29 12:09:33 +00003255 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00003256 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003257 {
3258 return NULL;
3259 }
Benny Prijonodc308702006-12-09 00:39:42 +00003260
Fahrisdcf8fa42006-12-28 03:13:48 +00003261 c = PJ_ARRAY_SIZE(id);
Benny Prijono98793592006-12-04 08:33:20 +00003262 status = pjsua_enum_transports(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00003263
3264 list = PyList_New(c);
3265 for (i = 0; i < c; i++)
3266 {
3267 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
3268 if (ret == -1)
3269 {
3270 return NULL;
3271 }
3272 }
3273
Benny Prijonodc308702006-12-09 00:39:42 +00003274 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00003275}
3276
3277/*
3278 * py_pjsua_transport_get_info
Benny Prijonodc308702006-12-09 00:39:42 +00003279 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003280 */
3281static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
3282{
3283 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003284 int id;
3285 transport_info_Object *obj;
3286 pjsua_transport_info info;
3287
Benny Prijono98793592006-12-04 08:33:20 +00003288
Benny Prijonodc308702006-12-09 00:39:42 +00003289 if (!PyArg_ParseTuple(pArgs, "i", &id))
Benny Prijono98793592006-12-04 08:33:20 +00003290 {
3291 return NULL;
3292 }
Benny Prijonodc308702006-12-09 00:39:42 +00003293
Benny Prijono98793592006-12-04 08:33:20 +00003294 status = pjsua_transport_get_info(id, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00003295 if (status == PJ_SUCCESS) {
3296 obj = (transport_info_Object *) transport_info_new
3297 (&transport_info_Type,NULL,NULL);
3298 obj->addr_len = info.addr_len;
3299 obj->flag = info.flag;
3300 obj->id = info.id;
3301 obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen);
3302 obj->local_addr->sa_data =
3303 PyString_FromStringAndSize(info.local_addr.sa_data, 14);
Benny Prijono98793592006-12-04 08:33:20 +00003304#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
Benny Prijonodc308702006-12-09 00:39:42 +00003305 obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len;
3306 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003307#else
Benny Prijonodc308702006-12-09 00:39:42 +00003308 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003309#endif
Benny Prijonodc308702006-12-09 00:39:42 +00003310 return Py_BuildValue("O", obj);
3311 } else {
3312 Py_INCREF(Py_None);
3313 return Py_None;
3314 }
Benny Prijono98793592006-12-04 08:33:20 +00003315}
3316
3317/*
3318 * py_pjsua_transport_set_enable
3319 */
3320static PyObject *py_pjsua_transport_set_enable
3321(PyObject *pSelf, PyObject *pArgs)
3322{
3323 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003324 int id;
3325 int enabled;
Benny Prijono98793592006-12-04 08:33:20 +00003326 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled))
3327 {
3328 return NULL;
3329 }
3330 status = pjsua_transport_set_enable(id, enabled);
Fahris89ea3d02007-02-07 08:18:35 +00003331
Benny Prijono98793592006-12-04 08:33:20 +00003332 return Py_BuildValue("i",status);
3333}
3334
3335/*
3336 * py_pjsua_transport_close
3337 */
3338static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
3339{
3340 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003341 int id;
3342 int force;
Benny Prijono98793592006-12-04 08:33:20 +00003343 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force))
3344 {
3345 return NULL;
3346 }
3347 status = pjsua_transport_close(id, force);
Fahris89ea3d02007-02-07 08:18:35 +00003348
Benny Prijono98793592006-12-04 08:33:20 +00003349 return Py_BuildValue("i",status);
3350}
3351
3352static char pjsua_stun_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003353 "py_pjsua.STUN_Config py_pjsua.stun_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00003354 "Call this function to initialize STUN config with default values.";
3355static char pjsua_transport_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003356 "py_pjsua.Transport_Config py_pjsua.transport_config_default () "
3357 "Call this function to initialize UDP config with default values.";
Benny Prijono98793592006-12-04 08:33:20 +00003358static char pjsua_normalize_stun_config_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003359 "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) "
3360 "Normalize STUN config. ";
Benny Prijono98793592006-12-04 08:33:20 +00003361static char pjsua_transport_create_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003362 "int, int py_pjsua.transport_create (int type, "
3363 "py_pjsua.Transport_Config cfg) "
3364 "Create SIP transport.";
Benny Prijono98793592006-12-04 08:33:20 +00003365static char pjsua_transport_register_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003366 "int, int py_pjsua.transport_register "
3367 "(py_pjsua.PJSIP_Transport tp) "
3368 "Register transport that has been created by application.";
Benny Prijono98793592006-12-04 08:33:20 +00003369static char pjsua_enum_transports_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00003370 "int[] py_pjsua.enum_transports () "
Benny Prijonodc308702006-12-09 00:39:42 +00003371 "Enumerate all transports currently created in the system.";
Benny Prijono98793592006-12-04 08:33:20 +00003372static char pjsua_transport_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003373 "void py_pjsua.transport_get_info "
3374 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) "
3375 "Get information about transports.";
Benny Prijono98793592006-12-04 08:33:20 +00003376static char pjsua_transport_set_enable_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003377 "void py_pjsua.transport_set_enable "
3378 "(py_pjsua.Transport_ID id, int enabled) "
3379 "Disable a transport or re-enable it. "
3380 "By default transport is always enabled after it is created. "
3381 "Disabling a transport does not necessarily close the socket, "
3382 "it will only discard incoming messages and prevent the transport "
3383 "from being used to send outgoing messages.";
Benny Prijono98793592006-12-04 08:33:20 +00003384static char pjsua_transport_close_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003385 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) "
3386 "Close the transport. If transport is forcefully closed, "
3387 "it will be immediately closed, and any pending transactions "
3388 "that are using the transport may not terminate properly. "
3389 "Otherwise, the system will wait until all transactions are closed "
3390 "while preventing new users from using the transport, and will close "
3391 "the transport when it is safe to do so.";
Benny Prijono98793592006-12-04 08:33:20 +00003392
3393/* END OF LIB TRANSPORT */
3394
3395/* LIB ACCOUNT */
3396
3397/*
3398 * acc_config_Object
3399 * Acc Config
3400 */
3401typedef struct
3402{
3403 PyObject_HEAD
3404 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003405 int priority;
3406 PyObject * id;
3407 PyObject * reg_uri;
3408 int publish_enabled;
3409 PyObject * force_contact;
3410 unsigned proxy_cnt;
3411 /*pj_str_t proxy[8];*/
3412 PyListObject * proxy;
3413 unsigned reg_timeout;
3414 unsigned cred_count;
3415 /*pjsip_cred_info cred_info[8];*/
3416 PyListObject * cred_info;
Benny Prijono98793592006-12-04 08:33:20 +00003417} acc_config_Object;
3418
3419
3420/*
3421 * acc_config_dealloc
3422 * deletes a acc_config from memory
3423 */
3424static void acc_config_dealloc(acc_config_Object* self)
3425{
3426 Py_XDECREF(self->id);
Benny Prijonodc308702006-12-09 00:39:42 +00003427 Py_XDECREF(self->reg_uri);
3428 Py_XDECREF(self->force_contact);
3429 Py_XDECREF(self->proxy);
3430 Py_XDECREF(self->cred_info);
Benny Prijono98793592006-12-04 08:33:20 +00003431 self->ob_type->tp_free((PyObject*)self);
3432}
3433
3434
3435/*
3436 * acc_config_new
3437 * constructor for acc_config object
3438 */
3439static PyObject * acc_config_new(PyTypeObject *type, PyObject *args,
3440 PyObject *kwds)
3441{
3442 acc_config_Object *self;
3443
3444 self = (acc_config_Object *)type->tp_alloc(type, 0);
3445 if (self != NULL)
3446 {
Benny Prijonodc308702006-12-09 00:39:42 +00003447 self->id = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003448 if (self->id == NULL)
3449 {
3450 Py_DECREF(self);
3451 return NULL;
3452 }
Benny Prijonodc308702006-12-09 00:39:42 +00003453 self->reg_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003454 if (self->reg_uri == NULL)
3455 {
3456 Py_DECREF(self);
3457 return NULL;
3458 }
3459 self->force_contact = PyString_FromString("");
3460 if (self->force_contact == NULL)
3461 {
3462 Py_DECREF(self);
3463 return NULL;
3464 }
Benny Prijonodc308702006-12-09 00:39:42 +00003465 self->proxy = (PyListObject *)PyList_New(8);
3466 if (self->proxy == NULL)
3467 {
3468 Py_DECREF(self);
3469 return NULL;
3470 }
3471 self->cred_info = (PyListObject *)PyList_New(8);
3472 if (self->cred_info == NULL)
3473 {
3474 Py_DECREF(self);
3475 return NULL;
3476 }
Benny Prijono98793592006-12-04 08:33:20 +00003477 }
3478
3479 return (PyObject *)self;
3480}
3481
Benny Prijono98793592006-12-04 08:33:20 +00003482
3483
3484/*
3485 * acc_config_members
3486 */
3487static PyMemberDef acc_config_members[] =
3488{
Benny Prijonodc308702006-12-09 00:39:42 +00003489 {
3490 "priority", T_INT, offsetof(acc_config_Object, priority), 0,
3491 "Account priority, which is used to control the order of matching "
3492 "incoming/outgoing requests. The higher the number means the higher "
3493 "the priority is, and the account will be matched first. "
Benny Prijono98793592006-12-04 08:33:20 +00003494 },
Benny Prijonodc308702006-12-09 00:39:42 +00003495 {
3496 "id", T_OBJECT_EX,
3497 offsetof(acc_config_Object, id), 0,
3498 "The full SIP URL for the account. "
3499 "The value can take name address or URL format, "
3500 "and will look something like 'sip:account@serviceprovider'. "
3501 "This field is mandatory."
Benny Prijono98793592006-12-04 08:33:20 +00003502 },
Benny Prijonodc308702006-12-09 00:39:42 +00003503 {
3504 "reg_uri", T_OBJECT_EX,
3505 offsetof(acc_config_Object, reg_uri), 0,
3506 "This is the URL to be put in the request URI for the registration, "
3507 "and will look something like 'sip:serviceprovider'. "
3508 "This field should be specified if registration is desired. "
3509 "If the value is empty, no account registration will be performed. "
Benny Prijono98793592006-12-04 08:33:20 +00003510 },
Benny Prijonodc308702006-12-09 00:39:42 +00003511 {
3512 "publish_enabled", T_INT,
3513 offsetof(acc_config_Object, publish_enabled), 0,
3514 "Publish presence? "
Benny Prijono98793592006-12-04 08:33:20 +00003515 },
Benny Prijonodc308702006-12-09 00:39:42 +00003516 {
3517 "force_contact", T_OBJECT_EX,
3518 offsetof(acc_config_Object, force_contact), 0,
3519 "Optional URI to be put as Contact for this account. "
3520 "It is recommended that this field is left empty, "
3521 "so that the value will be calculated automatically "
3522 "based on the transport address. "
Benny Prijono98793592006-12-04 08:33:20 +00003523 },
Benny Prijonodc308702006-12-09 00:39:42 +00003524 {
3525 "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0,
3526 "Number of proxies in the proxy array below. "
Benny Prijono98793592006-12-04 08:33:20 +00003527 },
Benny Prijonodc308702006-12-09 00:39:42 +00003528 {
3529 "proxy", T_OBJECT_EX,
3530 offsetof(acc_config_Object, proxy), 0,
3531 "Optional URI of the proxies to be visited for all outgoing requests "
3532 "that are using this account (REGISTER, INVITE, etc). Application need "
3533 "to specify these proxies if the service provider requires "
3534 "that requests destined towards its network should go through certain "
3535 "proxies first (for example, border controllers)."
Benny Prijono98793592006-12-04 08:33:20 +00003536 },
Benny Prijonodc308702006-12-09 00:39:42 +00003537 {
3538 "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0,
3539 "Optional interval for registration, in seconds. "
3540 "If the value is zero, default interval will be used "
3541 "(PJSUA_REG_INTERVAL, 55 seconds). "
3542 },
3543 {
3544 "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0,
3545 "Number of credentials in the credential array. "
3546 },
3547 {
3548 "cred_info", T_OBJECT_EX,
3549 offsetof(acc_config_Object, cred_info), 0,
3550 "Array of credentials. If registration is desired, normally there "
3551 "should be at least one credential specified, to successfully "
3552 "authenticate against the service provider. More credentials can "
3553 "be specified, for example when the requests are expected to be "
3554 "challenged by the proxies in the route set."
Benny Prijono98793592006-12-04 08:33:20 +00003555 },
3556 {NULL} /* Sentinel */
3557};
3558
3559
3560
3561
3562/*
3563 * acc_config_Type
3564 */
3565static PyTypeObject acc_config_Type =
3566{
3567 PyObject_HEAD_INIT(NULL)
3568 0, /*ob_size*/
3569 "py_pjsua.Acc_Config", /*tp_name*/
3570 sizeof(acc_config_Object), /*tp_basicsize*/
3571 0, /*tp_itemsize*/
3572 (destructor)acc_config_dealloc,/*tp_dealloc*/
3573 0, /*tp_print*/
3574 0, /*tp_getattr*/
3575 0, /*tp_setattr*/
3576 0, /*tp_compare*/
3577 0, /*tp_repr*/
3578 0, /*tp_as_number*/
3579 0, /*tp_as_sequence*/
3580 0, /*tp_as_mapping*/
3581 0, /*tp_hash */
3582 0, /*tp_call*/
3583 0, /*tp_str*/
3584 0, /*tp_getattro*/
3585 0, /*tp_setattro*/
3586 0, /*tp_as_buffer*/
3587 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3588 "Acc Config objects", /* tp_doc */
3589 0, /* tp_traverse */
3590 0, /* tp_clear */
3591 0, /* tp_richcompare */
3592 0, /* tp_weaklistoffset */
3593 0, /* tp_iter */
3594 0, /* tp_iternext */
Benny Prijonodc308702006-12-09 00:39:42 +00003595 0/*acc_config_methods*/, /* tp_methods */
Benny Prijono98793592006-12-04 08:33:20 +00003596 acc_config_members, /* tp_members */
3597 0, /* tp_getset */
3598 0, /* tp_base */
3599 0, /* tp_dict */
3600 0, /* tp_descr_get */
3601 0, /* tp_descr_set */
3602 0, /* tp_dictoffset */
3603 0, /* tp_init */
3604 0, /* tp_alloc */
3605 acc_config_new, /* tp_new */
3606
3607};
3608
3609/*
3610 * acc_info_Object
3611 * Acc Info
3612 */
3613typedef struct
3614{
3615 PyObject_HEAD
3616 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003617 int id;
3618 int is_default;
3619 PyObject * acc_uri;
3620 int has_registration;
3621 int expires;
3622 int status;
3623 PyObject * status_text;
3624 int online_status;
3625 char buf_[PJ_ERR_MSG_SIZE];
Benny Prijono98793592006-12-04 08:33:20 +00003626} acc_info_Object;
3627
3628
3629/*
3630 * acc_info_dealloc
3631 * deletes a acc_info from memory
3632 */
3633static void acc_info_dealloc(acc_info_Object* self)
3634{
3635 Py_XDECREF(self->acc_uri);
Benny Prijonodc308702006-12-09 00:39:42 +00003636 Py_XDECREF(self->status_text);
Benny Prijono98793592006-12-04 08:33:20 +00003637 self->ob_type->tp_free((PyObject*)self);
3638}
3639
3640
3641/*
3642 * acc_info_new
3643 * constructor for acc_info object
3644 */
3645static PyObject * acc_info_new(PyTypeObject *type, PyObject *args,
3646 PyObject *kwds)
3647{
3648 acc_info_Object *self;
3649
3650 self = (acc_info_Object *)type->tp_alloc(type, 0);
3651 if (self != NULL)
3652 {
Benny Prijonodc308702006-12-09 00:39:42 +00003653 self->acc_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003654 if (self->acc_uri == NULL)
3655 {
3656 Py_DECREF(self);
3657 return NULL;
3658 }
3659 self->status_text = PyString_FromString("");
3660 if (self->status_text == NULL)
3661 {
3662 Py_DECREF(self);
3663 return NULL;
3664 }
3665
3666 }
3667
3668 return (PyObject *)self;
3669}
3670
3671static PyObject * acc_info_get_buf
3672(acc_info_Object *self, PyObject * args)
3673{
Benny Prijonodc308702006-12-09 00:39:42 +00003674 int idx;
3675 char elmt;
3676 if (!PyArg_ParseTuple(args,"i",&idx))
3677 {
3678 return NULL;
3679 }
3680 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3681 {
3682 elmt = self->buf_[idx];
3683 }
3684 else
3685 {
3686 return NULL;
3687 }
3688 return PyString_FromStringAndSize(&elmt, 1);
Benny Prijono98793592006-12-04 08:33:20 +00003689}
3690
3691static PyObject * acc_info_set_buf
3692(acc_info_Object *self, PyObject * args)
3693{
Benny Prijonodc308702006-12-09 00:39:42 +00003694 int idx;
3695 PyObject * str;
3696 char * s;
3697 if (!PyArg_ParseTuple(args,"iO",&idx, &str))
3698 {
3699 return NULL;
3700 }
3701 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3702 {
3703 s = PyString_AsString(str);
3704 if (s[0])
3705 {
Fahris6f35cb82007-02-01 07:41:26 +00003706 self->buf_[idx] = s[0];
Benny Prijonodc308702006-12-09 00:39:42 +00003707 }
3708 else
3709 {
3710 return NULL;
3711 }
3712 }
3713 else
3714 {
3715 return NULL;
3716 }
3717 Py_INCREF(Py_None);
3718 return Py_None;
Benny Prijono98793592006-12-04 08:33:20 +00003719}
3720
3721static PyMethodDef acc_info_methods[] = {
3722 {
Benny Prijonodc308702006-12-09 00:39:42 +00003723 "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS,
3724 "Return buf char at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003725 },
Benny Prijonodc308702006-12-09 00:39:42 +00003726 {
3727 "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS,
3728 "Set buf at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003729 },
3730
3731 {NULL} /* Sentinel */
3732};
3733
3734
3735
3736/*
3737 * acc_info_members
3738 */
3739static PyMemberDef acc_info_members[] =
3740{
Benny Prijonodc308702006-12-09 00:39:42 +00003741 {
3742 "id", T_INT, offsetof(acc_info_Object, id), 0,
3743 "The account ID."
Benny Prijono98793592006-12-04 08:33:20 +00003744 },
Benny Prijonodc308702006-12-09 00:39:42 +00003745 {
3746 "is_default", T_INT, offsetof(acc_info_Object, is_default), 0,
3747 "Flag to indicate whether this is the default account. "
Benny Prijono98793592006-12-04 08:33:20 +00003748 },
Benny Prijonodc308702006-12-09 00:39:42 +00003749 {
3750 "acc_uri", T_OBJECT_EX,
3751 offsetof(acc_info_Object, acc_uri), 0,
3752 "Account URI"
Benny Prijono98793592006-12-04 08:33:20 +00003753 },
Benny Prijonodc308702006-12-09 00:39:42 +00003754 {
3755 "has_registration", T_INT, offsetof(acc_info_Object, has_registration),
3756 0,
3757 "Flag to tell whether this account has registration setting "
3758 "(reg_uri is not empty)."
Benny Prijono98793592006-12-04 08:33:20 +00003759 },
Benny Prijonodc308702006-12-09 00:39:42 +00003760 {
3761 "expires", T_INT, offsetof(acc_info_Object, expires), 0,
3762 "An up to date expiration interval for account registration session."
Benny Prijono98793592006-12-04 08:33:20 +00003763 },
Benny Prijonodc308702006-12-09 00:39:42 +00003764 {
3765 "status", T_INT, offsetof(acc_info_Object, status), 0,
3766 "Last registration status code. If status code is zero, "
3767 "the account is currently not registered. Any other value indicates "
3768 "the SIP status code of the registration. "
Benny Prijono98793592006-12-04 08:33:20 +00003769 },
Benny Prijonodc308702006-12-09 00:39:42 +00003770 {
3771 "status_text", T_OBJECT_EX,
3772 offsetof(acc_info_Object, status_text), 0,
3773 "String describing the registration status."
Benny Prijono98793592006-12-04 08:33:20 +00003774 },
Benny Prijonodc308702006-12-09 00:39:42 +00003775 {
3776 "online_status", T_INT, offsetof(acc_info_Object, online_status), 0,
3777 "Presence online status for this account. "
Benny Prijono98793592006-12-04 08:33:20 +00003778 },
3779 {NULL} /* Sentinel */
3780};
3781
3782
3783
3784
3785/*
3786 * acc_info_Type
3787 */
3788static PyTypeObject acc_info_Type =
3789{
3790 PyObject_HEAD_INIT(NULL)
3791 0, /*ob_size*/
3792 "py_pjsua.Acc_Info", /*tp_name*/
3793 sizeof(acc_info_Object), /*tp_basicsize*/
3794 0, /*tp_itemsize*/
3795 (destructor)acc_info_dealloc,/*tp_dealloc*/
3796 0, /*tp_print*/
3797 0, /*tp_getattr*/
3798 0, /*tp_setattr*/
3799 0, /*tp_compare*/
3800 0, /*tp_repr*/
3801 0, /*tp_as_number*/
3802 0, /*tp_as_sequence*/
3803 0, /*tp_as_mapping*/
3804 0, /*tp_hash */
3805 0, /*tp_call*/
3806 0, /*tp_str*/
3807 0, /*tp_getattro*/
3808 0, /*tp_setattro*/
3809 0, /*tp_as_buffer*/
3810 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3811 "Acc Info objects", /* tp_doc */
3812 0, /* tp_traverse */
3813 0, /* tp_clear */
3814 0, /* tp_richcompare */
3815 0, /* tp_weaklistoffset */
3816 0, /* tp_iter */
3817 0, /* tp_iternext */
3818 acc_info_methods, /* tp_methods */
3819 acc_info_members, /* tp_members */
3820 0, /* tp_getset */
3821 0, /* tp_base */
3822 0, /* tp_dict */
3823 0, /* tp_descr_get */
3824 0, /* tp_descr_set */
3825 0, /* tp_dictoffset */
3826 0, /* tp_init */
3827 0, /* tp_alloc */
3828 acc_info_new, /* tp_new */
3829
3830};
3831
Benny Prijono98793592006-12-04 08:33:20 +00003832
3833
3834/*
Benny Prijono98793592006-12-04 08:33:20 +00003835 * py_pjsua_acc_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003836 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003837 */
3838static PyObject *py_pjsua_acc_config_default
3839(PyObject *pSelf, PyObject *pArgs)
3840{
3841 acc_config_Object *obj;
3842 pjsua_acc_config cfg;
Benny Prijonodc308702006-12-09 00:39:42 +00003843 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003844
Benny Prijonodc308702006-12-09 00:39:42 +00003845 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003846 {
3847 return NULL;
3848 }
3849 pjsua_acc_config_default(&cfg);
Benny Prijonodc308702006-12-09 00:39:42 +00003850 obj = (acc_config_Object *)acc_config_new(&acc_config_Type, NULL, NULL);
3851 obj->cred_count = cfg.cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003852 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003853 {
3854 /*obj->cred_info[i] = cfg.cred_info[i];*/
3855 int ret;
3856 pjsip_cred_info_Object * ci =
3857 (pjsip_cred_info_Object *)pjsip_cred_info_new
3858 (&pjsip_cred_info_Type,NULL,NULL);
3859 ci->data = PyString_FromStringAndSize(cfg.cred_info[i].data.ptr,
3860 cfg.cred_info[i].data.slen);
3861 ci->realm = PyString_FromStringAndSize(cfg.cred_info[i].realm.ptr,
3862 cfg.cred_info[i].realm.slen);
3863 ci->scheme = PyString_FromStringAndSize(cfg.cred_info[i].scheme.ptr,
3864 cfg.cred_info[i].scheme.slen);
3865 ci->username = PyString_FromStringAndSize(cfg.cred_info[i].username.ptr,
3866 cfg.cred_info[i].username.slen);
3867 ci->data_type = cfg.cred_info[i].data_type;
3868 ret = PyList_SetItem((PyObject *)obj->cred_info,i,(PyObject *)ci);
3869 if (ret == -1) {
3870 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003871 }
Benny Prijonodc308702006-12-09 00:39:42 +00003872 }
3873
3874 Py_XDECREF(obj->force_contact);
3875 obj->force_contact =
3876 PyString_FromStringAndSize(cfg.force_contact.ptr,
3877 cfg.force_contact.slen);
3878 obj->priority = cfg.priority;
3879 Py_XDECREF(obj->id);
3880 obj->id =
3881 PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen);
3882 Py_XDECREF(obj->reg_uri);
3883 obj->reg_uri =
3884 PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen);
3885 obj->proxy_cnt = cfg.proxy_cnt;
Fahris6f35cb82007-02-01 07:41:26 +00003886 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003887 {
3888 PyObject * str;
3889 int ret;
3890 /*obj->proxy[i] = cfg.proxy[i];*/
3891 str = PyString_FromStringAndSize(cfg.proxy[i].ptr, cfg.proxy[i].slen);
3892 ret = PyList_SetItem((PyObject *)obj->proxy,i,str);
3893 if (ret == -1) {
3894 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003895 }
Benny Prijonodc308702006-12-09 00:39:42 +00003896 }
3897 obj->publish_enabled = cfg.publish_enabled;
3898 obj->reg_timeout = cfg.reg_timeout;
Benny Prijono98793592006-12-04 08:33:20 +00003899
Benny Prijonodc308702006-12-09 00:39:42 +00003900 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003901}
3902
3903/*
3904 * py_pjsua_acc_get_count
3905 */
3906static PyObject *py_pjsua_acc_get_count
3907(PyObject *pSelf, PyObject *pArgs)
3908{
Benny Prijonodc308702006-12-09 00:39:42 +00003909 int count;
Benny Prijono98793592006-12-04 08:33:20 +00003910 if (!PyArg_ParseTuple(pArgs, ""))
3911 {
3912 return NULL;
3913 }
3914 count = pjsua_acc_get_count();
3915 return Py_BuildValue("i",count);
3916}
3917
3918/*
3919 * py_pjsua_acc_is_valid
3920 */
3921static PyObject *py_pjsua_acc_is_valid
3922(PyObject *pSelf, PyObject *pArgs)
3923{
Benny Prijonodc308702006-12-09 00:39:42 +00003924 int id;
3925 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00003926
3927 if (!PyArg_ParseTuple(pArgs, "i", &id))
3928 {
3929 return NULL;
3930 }
3931 is_valid = pjsua_acc_is_valid(id);
3932
3933 return Py_BuildValue("i", is_valid);
3934}
3935
3936/*
3937 * py_pjsua_acc_set_default
3938 */
3939static PyObject *py_pjsua_acc_set_default
3940(PyObject *pSelf, PyObject *pArgs)
3941{
Benny Prijonodc308702006-12-09 00:39:42 +00003942 int id;
3943 int status;
Benny Prijono98793592006-12-04 08:33:20 +00003944
3945 if (!PyArg_ParseTuple(pArgs, "i", &id))
3946 {
3947 return NULL;
3948 }
3949 status = pjsua_acc_set_default(id);
3950
3951 return Py_BuildValue("i", status);
3952}
3953
3954/*
3955 * py_pjsua_acc_get_default
3956 */
3957static PyObject *py_pjsua_acc_get_default
3958(PyObject *pSelf, PyObject *pArgs)
3959{
Benny Prijonodc308702006-12-09 00:39:42 +00003960 int id;
Benny Prijono98793592006-12-04 08:33:20 +00003961
3962 if (!PyArg_ParseTuple(pArgs, ""))
3963 {
3964 return NULL;
3965 }
3966 id = pjsua_acc_get_default();
3967
3968 return Py_BuildValue("i", id);
3969}
3970
3971/*
3972 * py_pjsua_acc_add
Benny Prijonodc308702006-12-09 00:39:42 +00003973 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003974 */
3975static PyObject *py_pjsua_acc_add
3976(PyObject *pSelf, PyObject *pArgs)
3977{
Benny Prijonodc308702006-12-09 00:39:42 +00003978 int is_default;
Fahris6f35cb82007-02-01 07:41:26 +00003979 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003980 acc_config_Object * ac;
3981 pjsua_acc_config cfg;
3982
3983 int p_acc_id;
3984 int status;
3985 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003986
Fahris17d91812007-01-29 12:09:33 +00003987 if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00003988 {
3989 return NULL;
3990 }
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003991
3992 pjsua_acc_config_default(&cfg);
Fahris17d91812007-01-29 12:09:33 +00003993 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003994 {
Fahris17d91812007-01-29 12:09:33 +00003995 ac = (acc_config_Object *)acObj;
3996 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003997 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003998 {
Fahris17d91812007-01-29 12:09:33 +00003999 /*cfg.cred_info[i] = ac->cred_info[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004000 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
Fahris17d91812007-01-29 12:09:33 +00004001 PyList_GetItem((PyObject *)ac->cred_info,i);
Fahris6f35cb82007-02-01 07:41:26 +00004002 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
4003 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
4004 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
4005 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
4006 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
4007 cfg.cred_info[i].scheme.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004008 (PyString_AsString(ci->scheme));
Fahris6f35cb82007-02-01 07:41:26 +00004009 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4010 cfg.cred_info[i].username.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004011 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004012 cfg.cred_info[i].data_type = ci->data_type;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004013 }
Fahris17d91812007-01-29 12:09:33 +00004014 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4015 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4016 cfg.id.ptr = PyString_AsString(ac->id);
4017 cfg.id.slen = strlen(PyString_AsString(ac->id));
4018 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004019 for (i = 0; i < PJSUA_MAX_ACC; i++)
4020 {
Fahris17d91812007-01-29 12:09:33 +00004021 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004022 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004023 (PyList_GetItem((PyObject *)ac->proxy,i));
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004024 }
Fahris17d91812007-01-29 12:09:33 +00004025 cfg.proxy_cnt = ac->proxy_cnt;
4026 cfg.publish_enabled = ac->publish_enabled;
4027 cfg.reg_timeout = ac->reg_timeout;
4028 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4029 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004030
Fahris17d91812007-01-29 12:09:33 +00004031 status = pjsua_acc_add(&cfg, is_default, &p_acc_id);
4032 } else {
4033 status = pjsua_acc_add(NULL, is_default, &p_acc_id);
Fahris6f35cb82007-02-01 07:41:26 +00004034 }
Benny Prijonodc308702006-12-09 00:39:42 +00004035
4036 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004037}
4038
4039/*
4040 * py_pjsua_acc_add_local
Benny Prijonodc308702006-12-09 00:39:42 +00004041 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004042 */
4043static PyObject *py_pjsua_acc_add_local
4044(PyObject *pSelf, PyObject *pArgs)
4045{
Benny Prijonodc308702006-12-09 00:39:42 +00004046 int is_default;
4047 int tid;
4048
4049 int p_acc_id;
4050 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004051
4052
Fahris17d91812007-01-29 12:09:33 +00004053 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00004054 {
4055 return NULL;
4056 }
4057
Benny Prijonodc308702006-12-09 00:39:42 +00004058
Benny Prijono98793592006-12-04 08:33:20 +00004059 status = pjsua_acc_add_local(tid, is_default, &p_acc_id);
Benny Prijonodc308702006-12-09 00:39:42 +00004060
4061 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004062}
4063
4064/*
4065 * py_pjsua_acc_del
4066 */
4067static PyObject *py_pjsua_acc_del
4068(PyObject *pSelf, PyObject *pArgs)
4069{
Benny Prijonodc308702006-12-09 00:39:42 +00004070 int acc_id;
4071 int status;
4072
Benny Prijono98793592006-12-04 08:33:20 +00004073 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
4074 {
4075 return NULL;
4076 }
4077
4078
4079 status = pjsua_acc_del(acc_id);
4080 return Py_BuildValue("i", status);
4081}
4082
4083/*
4084 * py_pjsua_acc_modify
4085 */
4086static PyObject *py_pjsua_acc_modify
4087(PyObject *pSelf, PyObject *pArgs)
4088{
Fahris6f35cb82007-02-01 07:41:26 +00004089 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004090 acc_config_Object * ac;
4091 pjsua_acc_config cfg;
4092 int acc_id;
4093 int status;
4094 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004095
Fahris17d91812007-01-29 12:09:33 +00004096 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj))
Benny Prijono98793592006-12-04 08:33:20 +00004097 {
4098 return NULL;
4099 }
Fahris17d91812007-01-29 12:09:33 +00004100 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004101 {
4102 ac = (acc_config_Object *)acObj;
Fahris17d91812007-01-29 12:09:33 +00004103 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00004104 for (i = 0; i < PJSUA_MAX_ACC; i++)
4105 {
Fahris17d91812007-01-29 12:09:33 +00004106 /*cfg.cred_info[i] = ac->cred_info[i];*/
4107 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
4108 PyList_GetItem((PyObject *)ac->cred_info,i);
4109 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
4110 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
4111 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
4112 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
4113 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
4114 cfg.cred_info[i].scheme.slen = strlen
4115 (PyString_AsString(ci->scheme));
4116 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4117 cfg.cred_info[i].username.slen = strlen
4118 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004119 }
Fahris17d91812007-01-29 12:09:33 +00004120 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4121 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4122 cfg.id.ptr = PyString_AsString(ac->id);
4123 cfg.id.slen = strlen(PyString_AsString(ac->id));
4124 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004125 for (i = 0; i < PJSUA_MAX_ACC; i++)
4126 {
Fahris17d91812007-01-29 12:09:33 +00004127 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004128 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004129 (PyList_GetItem((PyObject *)ac->proxy,i));
Fahris6f35cb82007-02-01 07:41:26 +00004130 }
Fahris17d91812007-01-29 12:09:33 +00004131 cfg.proxy_cnt = ac->proxy_cnt;
4132 cfg.publish_enabled = ac->publish_enabled;
4133 cfg.reg_timeout = ac->reg_timeout;
4134 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4135 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
4136 status = pjsua_acc_modify(acc_id, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00004137 } else {
4138 status = pjsua_acc_modify(acc_id, NULL);
4139 }
Benny Prijono98793592006-12-04 08:33:20 +00004140 return Py_BuildValue("i", status);
4141}
4142
4143/*
4144 * py_pjsua_acc_set_online_status
4145 */
4146static PyObject *py_pjsua_acc_set_online_status
4147(PyObject *pSelf, PyObject *pArgs)
4148{
Benny Prijonodc308702006-12-09 00:39:42 +00004149 int is_online;
4150 int acc_id;
4151 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004152
4153 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online))
4154 {
4155 return NULL;
4156 }
4157
4158 status = pjsua_acc_set_online_status(acc_id, is_online);
4159
4160 return Py_BuildValue("i", status);
4161}
4162
4163/*
4164 * py_pjsua_acc_set_registration
4165 */
4166static PyObject *py_pjsua_acc_set_registration
4167(PyObject *pSelf, PyObject *pArgs)
4168{
Benny Prijonodc308702006-12-09 00:39:42 +00004169 int renew;
4170 int acc_id;
4171 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004172
4173 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew))
4174 {
4175 return NULL;
4176 }
4177
4178 status = pjsua_acc_set_registration(acc_id, renew);
4179
4180 return Py_BuildValue("i", status);
4181}
4182
4183/*
Benny Prijonodc308702006-12-09 00:39:42 +00004184 * py_pjsua_acc_get_info
4185 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004186 */
4187static PyObject *py_pjsua_acc_get_info
4188(PyObject *pSelf, PyObject *pArgs)
4189{
Benny Prijonodc308702006-12-09 00:39:42 +00004190 int acc_id;
4191 acc_info_Object * obj;
4192 pjsua_acc_info info;
4193 int status;
4194 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004195
Benny Prijonodc308702006-12-09 00:39:42 +00004196 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
Benny Prijono98793592006-12-04 08:33:20 +00004197 {
4198 return NULL;
4199 }
4200
Benny Prijonodc308702006-12-09 00:39:42 +00004201
Benny Prijono98793592006-12-04 08:33:20 +00004202 status = pjsua_acc_get_info(acc_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004203 if (status == PJ_SUCCESS)
4204 {
Benny Prijonodc308702006-12-09 00:39:42 +00004205 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL, NULL);
4206 obj->acc_uri =
4207 PyString_FromStringAndSize(info.acc_uri.ptr,
4208 info.acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004209 for (i = 0; i < PJ_ERR_MSG_SIZE; i++)
4210 {
Benny Prijonodc308702006-12-09 00:39:42 +00004211 obj->buf_[i] = info.buf_[i];
Benny Prijono98793592006-12-04 08:33:20 +00004212 }
Benny Prijonodc308702006-12-09 00:39:42 +00004213 obj->expires = info.expires;
4214 obj->has_registration = info.has_registration;
4215 obj->id = info.id;
4216 obj->is_default = info.is_default;
4217 obj->online_status = info.online_status;
4218 obj->status = info.status;
4219 obj->status_text =
4220 PyString_FromStringAndSize(info.status_text.ptr,
4221 info.status_text.slen);
4222 return Py_BuildValue("O", obj);
4223 } else {
4224 Py_INCREF(Py_None);
4225 return Py_None;
4226 }
Benny Prijono98793592006-12-04 08:33:20 +00004227}
4228
4229/*
4230 * py_pjsua_enum_accs
Fahrisdcf8fa42006-12-28 03:13:48 +00004231 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004232 */
4233static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
4234{
4235 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004236 PyObject *list;
4237
Fahrisdcf8fa42006-12-28 03:13:48 +00004238 pjsua_acc_id id[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004239 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004240 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004241 {
4242 return NULL;
4243 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004244 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004245
Benny Prijono98793592006-12-04 08:33:20 +00004246 status = pjsua_enum_accs(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004247
4248 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004249 for (i = 0; i < c; i++)
4250 {
Benny Prijonodc308702006-12-09 00:39:42 +00004251 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004252 if (ret == -1)
4253 {
Benny Prijonodc308702006-12-09 00:39:42 +00004254 return NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004255 }
Benny Prijonodc308702006-12-09 00:39:42 +00004256 }
4257
Benny Prijonodc308702006-12-09 00:39:42 +00004258 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004259}
4260
4261/*
4262 * py_pjsua_acc_enum_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004263 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004264 */
4265static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
4266{
4267 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004268 PyObject *list;
4269
Fahrisdcf8fa42006-12-28 03:13:48 +00004270 pjsua_acc_info info[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004271 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004272 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004273 {
4274 return NULL;
4275 }
Benny Prijonodc308702006-12-09 00:39:42 +00004276
Fahrisdcf8fa42006-12-28 03:13:48 +00004277 c = PJ_ARRAY_SIZE(info);
Benny Prijono98793592006-12-04 08:33:20 +00004278 status = pjsua_acc_enum_info(info, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004279
4280 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004281 for (i = 0; i < c; i++)
4282 {
Benny Prijonodc308702006-12-09 00:39:42 +00004283 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00004284 int j;
4285 acc_info_Object *obj;
4286 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL,NULL);
4287 obj->acc_uri = PyString_FromStringAndSize
Benny Prijonodc308702006-12-09 00:39:42 +00004288 (info[i].acc_uri.ptr, info[i].acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004289 for(j = 0; j < PJ_ERR_MSG_SIZE; j++)
4290 {
4291 obj->buf_[j] = info[i].buf_[j];
Benny Prijono98793592006-12-04 08:33:20 +00004292 }
Fahris6f35cb82007-02-01 07:41:26 +00004293 obj->expires = info[i].expires;
4294 obj->has_registration = info[i].has_registration;
4295 obj->id = info[i].id;
4296 obj->is_default = info[i].is_default;
4297 obj->online_status = info[i].online_status;
4298 obj->status = info[i].status;
4299 obj->status_text = PyString_FromStringAndSize(info[i].status_text.ptr,
Benny Prijonodc308702006-12-09 00:39:42 +00004300 info[i].status_text.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004301 ret = PyList_SetItem(list, i, (PyObject *)obj);
Benny Prijonodc308702006-12-09 00:39:42 +00004302 if (ret == -1) {
Fahris6f35cb82007-02-01 07:41:26 +00004303 return NULL;
Benny Prijonodc308702006-12-09 00:39:42 +00004304 }
4305 }
4306
Benny Prijonodc308702006-12-09 00:39:42 +00004307 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004308}
4309
4310/*
4311 * py_pjsua_acc_find_for_outgoing
4312 */
4313static PyObject *py_pjsua_acc_find_for_outgoing
4314(PyObject *pSelf, PyObject *pArgs)
4315{
4316
Benny Prijonodc308702006-12-09 00:39:42 +00004317 int acc_id;
4318 PyObject * url;
4319 pj_str_t str;
Benny Prijono98793592006-12-04 08:33:20 +00004320
4321 if (!PyArg_ParseTuple(pArgs, "O", &url))
4322 {
4323 return NULL;
4324 }
Benny Prijonodc308702006-12-09 00:39:42 +00004325 str.ptr = PyString_AsString(url);
4326 str.slen = strlen(PyString_AsString(url));
Benny Prijono98793592006-12-04 08:33:20 +00004327
4328 acc_id = pjsua_acc_find_for_outgoing(&str);
4329
4330 return Py_BuildValue("i", acc_id);
4331}
4332
4333/*
4334 * py_pjsua_acc_find_for_incoming
4335 */
4336static PyObject *py_pjsua_acc_find_for_incoming
4337(PyObject *pSelf, PyObject *pArgs)
4338{
Benny Prijonodc308702006-12-09 00:39:42 +00004339 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004340 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004341 pjsip_rx_data_Object * obj;
4342 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004343
Fahris17d91812007-01-29 12:09:33 +00004344 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00004345 {
4346 return NULL;
4347 }
Fahris17d91812007-01-29 12:09:33 +00004348 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004349 {
Fahris17d91812007-01-29 12:09:33 +00004350 obj = (pjsip_rx_data_Object *)tmpObj;
4351 rdata = obj->rdata;
4352 acc_id = pjsua_acc_find_for_incoming(rdata);
Fahris6f35cb82007-02-01 07:41:26 +00004353 } else {
Fahris17d91812007-01-29 12:09:33 +00004354 acc_id = pjsua_acc_find_for_incoming(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004355 }
Benny Prijono98793592006-12-04 08:33:20 +00004356 return Py_BuildValue("i", acc_id);
4357}
4358
4359/*
4360 * py_pjsua_acc_create_uac_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004361 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004362 */
4363static PyObject *py_pjsua_acc_create_uac_contact
4364(PyObject *pSelf, PyObject *pArgs)
4365{
Benny Prijonodc308702006-12-09 00:39:42 +00004366 int status;
Fahris17d91812007-01-29 12:09:33 +00004367 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004368 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004369 pj_pool_Object * p;
4370 pj_pool_t * pool;
4371 PyObject * strc;
4372 pj_str_t contact;
4373 PyObject * stru;
4374 pj_str_t uri;
Benny Prijono98793592006-12-04 08:33:20 +00004375
Fahris17d91812007-01-29 12:09:33 +00004376 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru))
Benny Prijono98793592006-12-04 08:33:20 +00004377 {
4378 return NULL;
4379 }
Fahris17d91812007-01-29 12:09:33 +00004380 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004381 {
Fahris17d91812007-01-29 12:09:33 +00004382 p = (pj_pool_Object *)pObj;
4383 pool = p->pool;
4384 uri.ptr = PyString_AsString(stru);
4385 uri.slen = strlen(PyString_AsString(stru));
4386 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004387 } else {
Fahris17d91812007-01-29 12:09:33 +00004388 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004389 }
Benny Prijonodc308702006-12-09 00:39:42 +00004390 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004391
Benny Prijonodc308702006-12-09 00:39:42 +00004392 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004393}
4394
4395/*
4396 * py_pjsua_acc_create_uas_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004397 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004398 */
4399static PyObject *py_pjsua_acc_create_uas_contact
4400(PyObject *pSelf, PyObject *pArgs)
4401{
Benny Prijonodc308702006-12-09 00:39:42 +00004402 int status;
4403 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004404 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004405 pj_pool_Object * p;
4406 pj_pool_t * pool;
4407 PyObject * strc;
4408 pj_str_t contact;
Fahris6f35cb82007-02-01 07:41:26 +00004409 PyObject * rObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004410 pjsip_rx_data_Object * objr;
4411 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004412
Fahris17d91812007-01-29 12:09:33 +00004413 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj))
Benny Prijono98793592006-12-04 08:33:20 +00004414 {
4415 return NULL;
4416 }
Fahris17d91812007-01-29 12:09:33 +00004417 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004418 {
Fahris17d91812007-01-29 12:09:33 +00004419 p = (pj_pool_Object *)pObj;
4420 pool = p->pool;
4421 } else {
4422 pool = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004423 }
Fahris17d91812007-01-29 12:09:33 +00004424 if (rObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004425 {
4426 objr = (pjsip_rx_data_Object *)rObj;
Fahris17d91812007-01-29 12:09:33 +00004427 rdata = objr->rdata;
Fahris6f35cb82007-02-01 07:41:26 +00004428 } else {
Fahris17d91812007-01-29 12:09:33 +00004429 rdata = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004430 }
Benny Prijono98793592006-12-04 08:33:20 +00004431 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata);
Benny Prijonodc308702006-12-09 00:39:42 +00004432 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004433
Benny Prijonodc308702006-12-09 00:39:42 +00004434 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004435}
4436
4437static char pjsua_acc_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004438 "py_pjsua.Acc_Config py_pjsua.acc_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00004439 "Call this function to initialize account config with default values.";
4440static char pjsua_acc_get_count_doc[] =
4441 "int py_pjsua.acc_get_count () "
4442 "Get number of current accounts.";
4443static char pjsua_acc_is_valid_doc[] =
4444 "int py_pjsua.acc_is_valid (int acc_id) "
4445 "Check if the specified account ID is valid.";
4446static char pjsua_acc_set_default_doc[] =
4447 "int py_pjsua.acc_set_default (int acc_id) "
4448 "Set default account to be used when incoming "
Benny Prijonodc308702006-12-09 00:39:42 +00004449 "and outgoing requests doesn't match any accounts.";
Benny Prijono98793592006-12-04 08:33:20 +00004450static char pjsua_acc_get_default_doc[] =
4451 "int py_pjsua.acc_get_default () "
4452 "Get default account.";
4453static char pjsua_acc_add_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004454 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, "
4455 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004456 "Add a new account to pjsua. PJSUA must have been initialized "
Benny Prijonodc308702006-12-09 00:39:42 +00004457 "(with pjsua_init()) before calling this function.";
Benny Prijono98793592006-12-04 08:33:20 +00004458static char pjsua_acc_add_local_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004459 "int,int py_pjsua.acc_add_local (int tid, "
4460 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004461 "Add a local account. A local account is used to identify "
Benny Prijonodc308702006-12-09 00:39:42 +00004462 "local endpoint instead of a specific user, and for this reason, "
4463 "a transport ID is needed to obtain the local address information.";
Benny Prijono98793592006-12-04 08:33:20 +00004464static char pjsua_acc_del_doc[] =
4465 "int py_pjsua.acc_del (int acc_id) "
4466 "Delete account.";
4467static char pjsua_acc_modify_doc[] =
4468 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) "
4469 "Modify account information.";
4470static char pjsua_acc_set_online_status_doc[] =
4471 "int py_pjsua.acc_set_online_status (int acc_id, int is_online) "
4472 "Modify account's presence status to be advertised "
Benny Prijonodc308702006-12-09 00:39:42 +00004473 "to remote/presence subscribers.";
Benny Prijono98793592006-12-04 08:33:20 +00004474static char pjsua_acc_set_registration_doc[] =
4475 "int py_pjsua.acc_set_registration (int acc_id, int renew) "
4476 "Update registration or perform unregistration.";
4477static char pjsua_acc_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004478 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) "
Benny Prijono98793592006-12-04 08:33:20 +00004479 "Get account information.";
4480static char pjsua_enum_accs_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004481 "int[] py_pjsua.enum_accs () "
Benny Prijono98793592006-12-04 08:33:20 +00004482 "Enum accounts all account ids.";
4483static char pjsua_acc_enum_info_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004484 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () "
Benny Prijono98793592006-12-04 08:33:20 +00004485 "Enum accounts info.";
4486static char pjsua_acc_find_for_outgoing_doc[] =
4487 "int py_pjsua.acc_find_for_outgoing (string url) "
4488 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004489 "to used to reach to the specified URL.";
Benny Prijono98793592006-12-04 08:33:20 +00004490static char pjsua_acc_find_for_incoming_doc[] =
4491 "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) "
4492 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004493 "to be used to handle incoming calls.";
Benny Prijono98793592006-12-04 08:33:20 +00004494static char pjsua_acc_create_uac_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004495 "string py_pjsua.acc_create_uac_contact (pj_pool_Object pool, "
4496 "int acc_id, string uri) "
Benny Prijono98793592006-12-04 08:33:20 +00004497 "Create a suitable URI to be put as Contact based on the specified "
Benny Prijonodc308702006-12-09 00:39:42 +00004498 "target URI for the specified account.";
Benny Prijono98793592006-12-04 08:33:20 +00004499static char pjsua_acc_create_uas_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004500 "string py_pjsua.acc_create_uas_contact (pj_pool_Object pool, "
4501 "int acc_id, pjsip_rx_data_Object rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00004502 "Create a suitable URI to be put as Contact based on the information "
Benny Prijonodc308702006-12-09 00:39:42 +00004503 "in the incoming request.";
Benny Prijono98793592006-12-04 08:33:20 +00004504
4505/* END OF LIB ACCOUNT */
4506
Benny Prijonodc308702006-12-09 00:39:42 +00004507/* LIB BUDDY */
4508
4509
4510
4511/*
4512 * buddy_config_Object
4513 * Buddy Config
4514 */
4515typedef struct
4516{
4517 PyObject_HEAD
4518 /* Type-specific fields go here. */
4519
4520 PyObject * uri;
4521 int subscribe;
4522} buddy_config_Object;
4523
4524
4525/*
4526 * buddy_config_dealloc
4527 * deletes a buddy_config from memory
4528 */
4529static void buddy_config_dealloc(buddy_config_Object* self)
4530{
4531 Py_XDECREF(self->uri);
4532 self->ob_type->tp_free((PyObject*)self);
4533}
4534
4535
4536/*
4537 * buddy_config_new
4538 * constructor for buddy_config object
4539 */
4540static PyObject * buddy_config_new(PyTypeObject *type, PyObject *args,
4541 PyObject *kwds)
4542{
4543 buddy_config_Object *self;
4544
4545 self = (buddy_config_Object *)type->tp_alloc(type, 0);
4546 if (self != NULL)
4547 {
4548 self->uri = PyString_FromString("");
4549 if (self->uri == NULL)
4550 {
4551 Py_DECREF(self);
4552 return NULL;
4553 }
4554 }
4555 return (PyObject *)self;
4556}
4557
4558/*
4559 * buddy_config_members
4560 */
4561static PyMemberDef buddy_config_members[] =
4562{
4563
4564 {
4565 "uri", T_OBJECT_EX,
4566 offsetof(buddy_config_Object, uri), 0,
4567 "TBuddy URL or name address."
4568 },
4569
4570 {
4571 "subscribe", T_INT,
4572 offsetof(buddy_config_Object, subscribe), 0,
4573 "Specify whether presence subscription should start immediately. "
4574 },
4575
4576 {NULL} /* Sentinel */
4577};
4578
4579
4580
4581
4582/*
4583 * buddy_config_Type
4584 */
4585static PyTypeObject buddy_config_Type =
4586{
4587 PyObject_HEAD_INIT(NULL)
4588 0, /*ob_size*/
4589 "py_pjsua.Buddy_Config", /*tp_name*/
4590 sizeof(buddy_config_Object), /*tp_basicsize*/
4591 0, /*tp_itemsize*/
4592 (destructor)buddy_config_dealloc,/*tp_dealloc*/
4593 0, /*tp_print*/
4594 0, /*tp_getattr*/
4595 0, /*tp_setattr*/
4596 0, /*tp_compare*/
4597 0, /*tp_repr*/
4598 0, /*tp_as_number*/
4599 0, /*tp_as_sequence*/
4600 0, /*tp_as_mapping*/
4601 0, /*tp_hash */
4602 0, /*tp_call*/
4603 0, /*tp_str*/
4604 0, /*tp_getattro*/
4605 0, /*tp_setattro*/
4606 0, /*tp_as_buffer*/
4607 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4608 "Buddy Config objects", /* tp_doc */
4609 0, /* tp_traverse */
4610 0, /* tp_clear */
4611 0, /* tp_richcompare */
4612 0, /* tp_weaklistoffset */
4613 0, /* tp_iter */
4614 0, /* tp_iternext */
4615 0, /* tp_methods */
4616 buddy_config_members, /* tp_members */
4617 0, /* tp_getset */
4618 0, /* tp_base */
4619 0, /* tp_dict */
4620 0, /* tp_descr_get */
4621 0, /* tp_descr_set */
4622 0, /* tp_dictoffset */
4623 0, /* tp_init */
4624 0, /* tp_alloc */
4625 buddy_config_new, /* tp_new */
4626
4627};
4628
4629/*
4630 * buddy_info_Object
4631 * Buddy Info
4632 * !modified @ 071206
4633 */
4634typedef struct
4635{
4636 PyObject_HEAD
4637 /* Type-specific fields go here. */
4638 int id;
4639 PyObject * uri;
4640 PyObject * contact;
4641 int status;
4642 PyObject * status_text;
4643 int monitor_pres;
4644 char buf_[256];
4645} buddy_info_Object;
4646
4647
4648/*
4649 * buddy_info_dealloc
4650 * deletes a buddy_info from memory
4651 * !modified @ 071206
4652 */
4653static void buddy_info_dealloc(buddy_info_Object* self)
4654{
4655 Py_XDECREF(self->uri);
4656 Py_XDECREF(self->contact);
4657 Py_XDECREF(self->status_text);
4658
4659 self->ob_type->tp_free((PyObject*)self);
4660}
4661
4662
4663/*
4664 * buddy_info_new
4665 * constructor for buddy_info object
4666 * !modified @ 071206
4667 */
4668static PyObject * buddy_info_new(PyTypeObject *type, PyObject *args,
4669 PyObject *kwds)
4670{
4671 buddy_info_Object *self;
4672
4673 self = (buddy_info_Object *)type->tp_alloc(type, 0);
4674 if (self != NULL)
4675 {
4676 self->uri = PyString_FromString("");
4677 if (self->uri == NULL)
4678 {
4679 Py_DECREF(self);
4680 return NULL;
4681 }
4682 self->contact = PyString_FromString("");
4683 if (self->contact == NULL)
4684 {
4685 Py_DECREF(self);
4686 return NULL;
4687 }
4688 self->status_text = PyString_FromString("");
4689 if (self->status_text == NULL)
4690 {
4691 Py_DECREF(self);
4692 return NULL;
4693 }
4694
4695 }
4696 return (PyObject *)self;
4697}
4698
4699/*
4700 * buddy_info_members
4701 * !modified @ 071206
4702 */
4703static PyMemberDef buddy_info_members[] =
4704{
4705 {
4706 "id", T_INT,
4707 offsetof(buddy_info_Object, id), 0,
4708 "The buddy ID."
4709 },
4710 {
4711 "uri", T_OBJECT_EX,
4712 offsetof(buddy_info_Object, uri), 0,
4713 "The full URI of the buddy, as specified in the configuration. "
4714 },
4715 {
4716 "contact", T_OBJECT_EX,
4717 offsetof(buddy_info_Object, contact), 0,
4718 "Buddy's Contact, only available when presence subscription "
4719 "has been established to the buddy."
4720 },
4721 {
4722 "status", T_INT,
4723 offsetof(buddy_info_Object, status), 0,
4724 "Buddy's online status. "
4725 },
4726 {
4727 "status_text", T_OBJECT_EX,
4728 offsetof(buddy_info_Object, status_text), 0,
4729 "Text to describe buddy's online status."
4730 },
4731 {
4732 "monitor_pres", T_INT,
4733 offsetof(buddy_info_Object, monitor_pres), 0,
4734 "Flag to indicate that we should monitor the presence information "
4735 "for this buddy (normally yes, unless explicitly disabled). "
4736 },
4737
4738
4739 {NULL} /* Sentinel */
4740};
4741
4742
4743
4744
4745/*
4746 * buddy_info_Type
4747 */
4748static PyTypeObject buddy_info_Type =
4749{
4750 PyObject_HEAD_INIT(NULL)
4751 0, /*ob_size*/
4752 "py_pjsua.Buddy_Info", /*tp_name*/
4753 sizeof(buddy_info_Object), /*tp_basicsize*/
4754 0, /*tp_itemsize*/
4755 (destructor)buddy_info_dealloc,/*tp_dealloc*/
4756 0, /*tp_print*/
4757 0, /*tp_getattr*/
4758 0, /*tp_setattr*/
4759 0, /*tp_compare*/
4760 0, /*tp_repr*/
4761 0, /*tp_as_number*/
4762 0, /*tp_as_sequence*/
4763 0, /*tp_as_mapping*/
4764 0, /*tp_hash */
4765 0, /*tp_call*/
4766 0, /*tp_str*/
4767 0, /*tp_getattro*/
4768 0, /*tp_setattro*/
4769 0, /*tp_as_buffer*/
4770 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4771 "Buddy Info objects", /* tp_doc */
4772 0, /* tp_traverse */
4773 0, /* tp_clear */
4774 0, /* tp_richcompare */
4775 0, /* tp_weaklistoffset */
4776 0, /* tp_iter */
4777 0, /* tp_iternext */
4778 0, /* tp_methods */
4779 buddy_info_members, /* tp_members */
4780 0, /* tp_getset */
4781 0, /* tp_base */
4782 0, /* tp_dict */
4783 0, /* tp_descr_get */
4784 0, /* tp_descr_set */
4785 0, /* tp_dictoffset */
4786 0, /* tp_init */
4787 0, /* tp_alloc */
4788 buddy_info_new, /* tp_new */
4789
4790};
4791
4792/*
Fahris6f35cb82007-02-01 07:41:26 +00004793 * py_pjsua_buddy_config_default
4794 */
4795static PyObject *py_pjsua_buddy_config_default
4796(PyObject *pSelf, PyObject *pArgs)
4797{
4798 buddy_config_Object *obj;
4799 pjsua_buddy_config cfg;
4800
4801 if (!PyArg_ParseTuple(pArgs, ""))
4802 {
4803 return NULL;
4804 }
4805
4806 pjsua_buddy_config_default(&cfg);
4807 obj = (buddy_config_Object *) buddy_config_new
4808 (&buddy_config_Type,NULL,NULL);
4809 obj->uri = PyString_FromStringAndSize(
4810 cfg.uri.ptr, cfg.uri.slen
4811 );
4812 obj->subscribe = cfg.subscribe;
4813
4814 return (PyObject *)obj;
4815}
4816
4817/*
Benny Prijonodc308702006-12-09 00:39:42 +00004818 * py_pjsua_get_buddy_count
4819 */
4820static PyObject *py_pjsua_get_buddy_count
Benny Prijono98793592006-12-04 08:33:20 +00004821(PyObject *pSelf, PyObject *pArgs)
4822{
Benny Prijonodc308702006-12-09 00:39:42 +00004823 int ret;
Benny Prijono98793592006-12-04 08:33:20 +00004824
Benny Prijonodc308702006-12-09 00:39:42 +00004825 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004826 {
4827 return NULL;
4828 }
Benny Prijonodc308702006-12-09 00:39:42 +00004829 ret = pjsua_get_buddy_count();
4830
4831 return Py_BuildValue("i", ret);
4832}
Benny Prijono98793592006-12-04 08:33:20 +00004833
Benny Prijonodc308702006-12-09 00:39:42 +00004834/*
4835 * py_pjsua_buddy_is_valid
4836 */
4837static PyObject *py_pjsua_buddy_is_valid
4838(PyObject *pSelf, PyObject *pArgs)
4839{
4840 int id;
4841 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00004842
Benny Prijonodc308702006-12-09 00:39:42 +00004843 if (!PyArg_ParseTuple(pArgs, "i", &id))
4844 {
4845 return NULL;
4846 }
4847 is_valid = pjsua_buddy_is_valid(id);
4848
4849 return Py_BuildValue("i", is_valid);
4850}
4851
4852/*
4853 * py_pjsua_enum_buddies
Fahrisdcf8fa42006-12-28 03:13:48 +00004854 * !modified @ 241206
Benny Prijonodc308702006-12-09 00:39:42 +00004855 */
4856static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
4857{
4858 pj_status_t status;
4859 PyObject *list;
4860
Fahrisdcf8fa42006-12-28 03:13:48 +00004861 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
Fahris17d91812007-01-29 12:09:33 +00004862 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004863 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijonodc308702006-12-09 00:39:42 +00004864 {
4865 return NULL;
4866 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004867 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004868 status = pjsua_enum_buddies(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004869 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004870 for (i = 0; i < c; i++)
4871 {
Benny Prijonodc308702006-12-09 00:39:42 +00004872 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004873 if (ret == -1)
4874 {
Benny Prijonodc308702006-12-09 00:39:42 +00004875 return NULL;
4876 }
4877 }
4878
Benny Prijonodc308702006-12-09 00:39:42 +00004879 return Py_BuildValue("O",list);
4880}
4881
4882/*
4883 * py_pjsua_buddy_get_info
4884 * !modified @ 071206
4885 */
4886static PyObject *py_pjsua_buddy_get_info
4887(PyObject *pSelf, PyObject *pArgs)
4888{
4889 int buddy_id;
4890 buddy_info_Object * obj;
4891 pjsua_buddy_info info;
4892 int status;
4893 int i;
4894
4895 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4896 {
4897 return NULL;
4898 }
4899
4900
4901 status = pjsua_buddy_get_info(buddy_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004902 if (status == PJ_SUCCESS)
4903 {
Benny Prijonodc308702006-12-09 00:39:42 +00004904 obj = (buddy_info_Object *)buddy_info_new(&buddy_info_Type,NULL,NULL);
4905 obj->id = info.id;
4906 Py_XDECREF(obj->uri);
4907 obj->uri =
4908 PyString_FromStringAndSize(info.uri.ptr,
4909 info.uri.slen);
4910 Py_XDECREF(obj->contact);
4911 obj->contact =
4912 PyString_FromStringAndSize(info.contact.ptr,
4913 info.contact.slen);
4914 obj->status = info.status;
4915 Py_XDECREF(obj->status_text);
4916 obj->status_text =
4917 PyString_FromStringAndSize(info.status_text.ptr,
4918 info.status_text.slen);
4919 obj->monitor_pres = info.monitor_pres;
Fahris6f35cb82007-02-01 07:41:26 +00004920 for (i = 0; i < 256; i++)
4921 {
Benny Prijonodc308702006-12-09 00:39:42 +00004922
4923 obj->buf_[i] = info.buf_[i];
4924 }
4925
4926 return Py_BuildValue("O", obj);
4927 } else {
4928 Py_INCREF(Py_None);
4929 return Py_None;
4930 }
4931}
4932
4933/*
4934 * py_pjsua_buddy_add
4935 * !modified @ 061206
4936 */
4937static PyObject *py_pjsua_buddy_add
4938(PyObject *pSelf, PyObject *pArgs)
Fahris17d91812007-01-29 12:09:33 +00004939{
4940 PyObject * bcObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004941 buddy_config_Object * bc;
Fahris17d91812007-01-29 12:09:33 +00004942
Benny Prijonodc308702006-12-09 00:39:42 +00004943 pjsua_buddy_config cfg;
4944
4945 int p_buddy_id;
4946 int status;
4947
Fahris17d91812007-01-29 12:09:33 +00004948 if (!PyArg_ParseTuple(pArgs, "O", &bcObj))
Benny Prijonodc308702006-12-09 00:39:42 +00004949 {
4950 return NULL;
4951 }
Fahris17d91812007-01-29 12:09:33 +00004952 if (bcObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004953 {
4954 bc = (buddy_config_Object *)bcObj;
Fahris17d91812007-01-29 12:09:33 +00004955
4956 cfg.subscribe = bc->subscribe;
4957 cfg.uri.ptr = PyString_AsString(bc->uri);
4958 cfg.uri.slen = strlen(PyString_AsString(bc->uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004959
Fahris17d91812007-01-29 12:09:33 +00004960 status = pjsua_buddy_add(&cfg, &p_buddy_id);
Fahris6f35cb82007-02-01 07:41:26 +00004961 } else {
Fahris17d91812007-01-29 12:09:33 +00004962 status = pjsua_buddy_add(NULL, &p_buddy_id);
4963 }
Benny Prijonodc308702006-12-09 00:39:42 +00004964 return Py_BuildValue("ii", status, p_buddy_id);
4965}
4966
4967/*
4968 * py_pjsua_buddy_del
4969 */
4970static PyObject *py_pjsua_buddy_del
4971(PyObject *pSelf, PyObject *pArgs)
4972{
4973 int buddy_id;
4974 int status;
4975
4976 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4977 {
4978 return NULL;
4979 }
4980
4981
4982 status = pjsua_buddy_del(buddy_id);
4983 return Py_BuildValue("i", status);
4984}
4985
4986/*
4987 * py_pjsua_buddy_subscribe_pres
4988 */
4989static PyObject *py_pjsua_buddy_subscribe_pres
4990(PyObject *pSelf, PyObject *pArgs)
4991{
4992 int buddy_id;
4993 int status;
4994 int subscribe;
4995
4996 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe))
4997 {
4998 return NULL;
4999 }
5000
5001
5002 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
5003 return Py_BuildValue("i", status);
5004}
5005
5006/*
5007 * py_pjsua_pres_dump
5008 */
5009static PyObject *py_pjsua_pres_dump
5010(PyObject *pSelf, PyObject *pArgs)
5011{
5012 int verbose;
5013
5014 if (!PyArg_ParseTuple(pArgs, "i", &verbose))
5015 {
5016 return NULL;
5017 }
5018
5019
5020 pjsua_pres_dump(verbose);
Benny Prijono98793592006-12-04 08:33:20 +00005021 Py_INCREF(Py_None);
5022 return Py_None;
5023}
5024
Benny Prijonodc308702006-12-09 00:39:42 +00005025/*
5026 * py_pjsua_im_send
5027 * !modified @ 071206
5028 */
5029static PyObject *py_pjsua_im_send
5030(PyObject *pSelf, PyObject *pArgs)
5031{
5032 int status;
5033 int acc_id;
Fahrise314b882007-02-02 10:52:04 +00005034 pj_str_t * mime_type, tmp_mime_type;
Fahris6f35cb82007-02-01 07:41:26 +00005035 pj_str_t to, content;
Benny Prijonodc308702006-12-09 00:39:42 +00005036 PyObject * st;
5037 PyObject * smt;
5038 PyObject * sc;
5039 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00005040 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005041 msg_data_Object * omd;
Fahris6f35cb82007-02-01 07:41:26 +00005042
Benny Prijonodc308702006-12-09 00:39:42 +00005043 int user_data;
5044 pj_pool_t *pool;
5045
Fahris6f35cb82007-02-01 07:41:26 +00005046
Fahris17d91812007-01-29 12:09:33 +00005047 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
5048 &st, &smt, &sc, &omdObj, &user_data))
Benny Prijonodc308702006-12-09 00:39:42 +00005049 {
5050 return NULL;
5051 }
Fahrise314b882007-02-02 10:52:04 +00005052 if (smt != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005053 {
Fahrise314b882007-02-02 10:52:04 +00005054 mime_type = &tmp_mime_type;
5055 tmp_mime_type.ptr = PyString_AsString(smt);
5056 tmp_mime_type.slen = strlen(PyString_AsString(smt));
Fahris6f35cb82007-02-01 07:41:26 +00005057 } else {
5058 mime_type = NULL;
5059 }
Benny Prijonodc308702006-12-09 00:39:42 +00005060 to.ptr = PyString_AsString(st);
5061 to.slen = strlen(PyString_AsString(st));
Fahris6f35cb82007-02-01 07:41:26 +00005062
Benny Prijonodc308702006-12-09 00:39:42 +00005063 content.ptr = PyString_AsString(sc);
5064 content.slen = strlen(PyString_AsString(sc));
Fahris17d91812007-01-29 12:09:33 +00005065 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005066 {
Fahris17d91812007-01-29 12:09:33 +00005067
5068 omd = (msg_data_Object *)omdObj;
5069 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5070 msg_data.content_type.slen = strlen
5071 (PyString_AsString(omd->content_type));
5072 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5073 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005074 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005075
Fahris17d91812007-01-29 12:09:33 +00005076 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00005077 status = pjsua_im_send(acc_id, &to, mime_type,
5078 &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00005079 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005080 } else {
Fahris17d91812007-01-29 12:09:33 +00005081
Fahris6f35cb82007-02-01 07:41:26 +00005082 status = pjsua_im_send(acc_id, &to, mime_type,
Fahris17d91812007-01-29 12:09:33 +00005083 &content, NULL, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005084 }
Fahrise314b882007-02-02 10:52:04 +00005085
Benny Prijonodc308702006-12-09 00:39:42 +00005086 return Py_BuildValue("i",status);
5087}
5088
5089/*
5090 * py_pjsua_im_typing
5091 */
5092static PyObject *py_pjsua_im_typing
5093(PyObject *pSelf, PyObject *pArgs)
5094{
5095 int status;
5096 int acc_id;
5097 pj_str_t to;
5098 PyObject * st;
5099 int is_typing;
5100 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00005101 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005102 msg_data_Object * omd;
5103 pj_pool_t * pool;
5104
Fahris17d91812007-01-29 12:09:33 +00005105 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj))
Benny Prijonodc308702006-12-09 00:39:42 +00005106 {
5107 return NULL;
5108 }
5109
5110 to.ptr = PyString_AsString(st);
5111 to.slen = strlen(PyString_AsString(st));
Fahris17d91812007-01-29 12:09:33 +00005112 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005113 {
Fahris17d91812007-01-29 12:09:33 +00005114 omd = (msg_data_Object *)omdObj;
5115 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5116 msg_data.content_type.slen = strlen
5117 (PyString_AsString(omd->content_type));
5118 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5119 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005120 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005121
Fahris17d91812007-01-29 12:09:33 +00005122 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
5123 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
5124 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005125 } else {
Fahris17d91812007-01-29 12:09:33 +00005126 status = pjsua_im_typing(acc_id, &to, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005127 }
Benny Prijonodc308702006-12-09 00:39:42 +00005128 return Py_BuildValue("i",status);
5129}
5130
Fahris6f35cb82007-02-01 07:41:26 +00005131static char pjsua_buddy_config_default_doc[] =
5132 "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () "
5133 "Set default values to the buddy config.";
Benny Prijonodc308702006-12-09 00:39:42 +00005134static char pjsua_get_buddy_count_doc[] =
5135 "int py_pjsua.get_buddy_count () "
5136 "Get total number of buddies.";
5137static char pjsua_buddy_is_valid_doc[] =
5138 "int py_pjsua.buddy_is_valid (int buddy_id) "
5139 "Check if buddy ID is valid.";
5140static char pjsua_enum_buddies_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00005141 "int[] py_pjsua.enum_buddies () "
Benny Prijonodc308702006-12-09 00:39:42 +00005142 "Enum buddy IDs.";
5143static char pjsua_buddy_get_info_doc[] =
5144 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) "
5145 "Get detailed buddy info.";
5146static char pjsua_buddy_add_doc[] =
5147 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) "
5148 "Add new buddy.";
5149static char pjsua_buddy_del_doc[] =
5150 "int py_pjsua.buddy_del (int buddy_id) "
5151 "Delete buddy.";
5152static char pjsua_buddy_subscribe_pres_doc[] =
5153 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
5154 "Enable/disable buddy's presence monitoring.";
5155static char pjsua_pres_dump_doc[] =
5156 "void py_pjsua.pres_dump (int verbose) "
5157 "Dump presence subscriptions to log file.";
5158static char pjsua_im_send_doc[] =
5159 "int py_pjsua.im_send (int acc_id, string to, string mime_type, "
5160 "string content, py_pjsua.Msg_Data msg_data, int user_data) "
5161 "Send instant messaging outside dialog, using the specified account "
5162 "for route set and authentication.";
5163static char pjsua_im_typing_doc[] =
5164 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, "
5165 "py_pjsua.Msg_Data msg_data) "
5166 "Send typing indication outside dialog.";
5167
5168/* END OF LIB BUDDY */
5169
Fahrisdcf8fa42006-12-28 03:13:48 +00005170/* LIB MEDIA */
Benny Prijono98793592006-12-04 08:33:20 +00005171
Benny Prijono572d4852006-11-23 21:50:02 +00005172
Fahrisdcf8fa42006-12-28 03:13:48 +00005173
5174/*
5175 * codec_info_Object
5176 * Codec Info
5177 * !modified @ 071206
5178 */
5179typedef struct
5180{
5181 PyObject_HEAD
5182 /* Type-specific fields go here. */
5183
5184 PyObject * codec_id;
5185 pj_uint8_t priority;
5186 char buf_[32];
5187} codec_info_Object;
5188
5189
5190/*
5191 * codec_info_dealloc
5192 * deletes a codec_info from memory
5193 * !modified @ 071206
5194 */
5195static void codec_info_dealloc(codec_info_Object* self)
5196{
5197 Py_XDECREF(self->codec_id);
5198
5199 self->ob_type->tp_free((PyObject*)self);
5200}
5201
5202
5203/*
5204 * codec_info_new
5205 * constructor for codec_info object
5206 * !modified @ 071206
5207 */
5208static PyObject * codec_info_new(PyTypeObject *type, PyObject *args,
5209 PyObject *kwds)
5210{
5211 codec_info_Object *self;
5212
5213 self = (codec_info_Object *)type->tp_alloc(type, 0);
5214 if (self != NULL)
5215 {
5216 self->codec_id = PyString_FromString("");
5217 if (self->codec_id == NULL)
5218 {
5219 Py_DECREF(self);
5220 return NULL;
5221 }
5222
5223
5224 }
5225 return (PyObject *)self;
5226}
5227
5228/*
5229 * codec_info_members
5230 * !modified @ 071206
5231 */
5232static PyMemberDef codec_info_members[] =
5233{
5234 {
5235 "codec_id", T_OBJECT_EX,
5236 offsetof(codec_info_Object, codec_id), 0,
5237 "Codec unique identification."
5238 },
5239
5240 {
5241 "priority", T_INT,
5242 offsetof(codec_info_Object, priority), 0,
5243 "Codec priority (integer 0-255)."
5244 },
5245
5246
5247
5248 {NULL} /* Sentinel */
5249};
5250
5251
5252
5253
5254/*
5255 * codec_info_Type
5256 */
5257static PyTypeObject codec_info_Type =
5258{
5259 PyObject_HEAD_INIT(NULL)
5260 0, /*ob_size*/
5261 "py_pjsua.Codec_Info", /*tp_name*/
5262 sizeof(codec_info_Object), /*tp_basicsize*/
5263 0, /*tp_itemsize*/
5264 (destructor)codec_info_dealloc,/*tp_dealloc*/
5265 0, /*tp_print*/
5266 0, /*tp_getattr*/
5267 0, /*tp_setattr*/
5268 0, /*tp_compare*/
5269 0, /*tp_repr*/
5270 0, /*tp_as_number*/
5271 0, /*tp_as_sequence*/
5272 0, /*tp_as_mapping*/
5273 0, /*tp_hash */
5274 0, /*tp_call*/
5275 0, /*tp_str*/
5276 0, /*tp_getattro*/
5277 0, /*tp_setattro*/
5278 0, /*tp_as_buffer*/
5279 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5280 "Codec Info objects", /* tp_doc */
5281 0, /* tp_traverse */
5282 0, /* tp_clear */
5283 0, /* tp_richcompare */
5284 0, /* tp_weaklistoffset */
5285 0, /* tp_iter */
5286 0, /* tp_iternext */
5287 0, /* tp_methods */
5288 codec_info_members, /* tp_members */
5289 0, /* tp_getset */
5290 0, /* tp_base */
5291 0, /* tp_dict */
5292 0, /* tp_descr_get */
5293 0, /* tp_descr_set */
5294 0, /* tp_dictoffset */
5295 0, /* tp_init */
5296 0, /* tp_alloc */
5297 codec_info_new, /* tp_new */
5298
5299};
5300
5301/*
5302 * conf_port_info_Object
5303 * Conf Port Info
5304 */
5305typedef struct
5306{
5307 PyObject_HEAD
5308 /* Type-specific fields go here. */
5309
5310 int slot_id;
5311 PyObject * name;
5312 unsigned clock_rate;
5313 unsigned channel_count;
5314 unsigned samples_per_frame;
5315 unsigned bits_per_sample;
5316 unsigned listener_cnt;
5317 PyListObject * listeners;
5318
5319} conf_port_info_Object;
5320
5321
5322/*
5323 * conf_port_info_dealloc
5324 * deletes a conf_port_info from memory
5325 */
5326static void conf_port_info_dealloc(conf_port_info_Object* self)
5327{
5328 Py_XDECREF(self->name);
5329 Py_XDECREF(self->listeners);
5330 self->ob_type->tp_free((PyObject*)self);
5331}
5332
5333
5334/*
5335 * conf_port_info_new
5336 * constructor for conf_port_info object
5337 */
5338static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
5339 PyObject *kwds)
5340{
5341 conf_port_info_Object *self;
5342
5343 self = (conf_port_info_Object *)type->tp_alloc(type, 0);
5344 if (self != NULL)
5345 {
5346 self->name = PyString_FromString("");
5347 if (self->name == NULL)
5348 {
5349 Py_DECREF(self);
5350 return NULL;
5351 }
5352
Fahris6f35cb82007-02-01 07:41:26 +00005353 self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS);
Fahrisdcf8fa42006-12-28 03:13:48 +00005354 if (self->listeners == NULL)
5355 {
5356 Py_DECREF(self);
5357 return NULL;
5358 }
5359 }
5360 return (PyObject *)self;
5361}
5362
5363/*
5364 * conf_port_info_members
5365 */
5366static PyMemberDef conf_port_info_members[] =
5367{
5368 {
5369 "slot_id", T_INT,
5370 offsetof(conf_port_info_Object, slot_id), 0,
5371 "Conference port number."
5372 },
5373 {
5374 "name", T_OBJECT_EX,
5375 offsetof(conf_port_info_Object, name), 0,
5376 "Port name"
5377 },
5378 {
5379 "clock_rate", T_INT,
5380 offsetof(conf_port_info_Object, clock_rate), 0,
5381 "Clock rate"
5382 },
5383 {
5384 "channel_count", T_INT,
5385 offsetof(conf_port_info_Object, channel_count), 0,
5386 "Number of channels."
5387 },
5388 {
5389 "samples_per_frame", T_INT,
5390 offsetof(conf_port_info_Object, samples_per_frame), 0,
5391 "Samples per frame "
5392 },
5393 {
5394 "bits_per_sample", T_INT,
5395 offsetof(conf_port_info_Object, bits_per_sample), 0,
5396 "Bits per sample"
5397 },
Fahris89ea3d02007-02-07 08:18:35 +00005398 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005399 "listener_cnt", T_INT,
5400 offsetof(conf_port_info_Object, listener_cnt), 0,
5401 "Number of listeners in the array."
Fahris89ea3d02007-02-07 08:18:35 +00005402 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005403 {
5404 "listeners", T_OBJECT_EX,
5405 offsetof(conf_port_info_Object, listeners), 0,
5406 "Array of listeners (in other words, ports where this port "
5407 "is transmitting to"
5408 },
5409
5410 {NULL} /* Sentinel */
5411};
5412
5413
5414
5415
5416/*
5417 * conf_port_info_Type
5418 */
5419static PyTypeObject conf_port_info_Type =
5420{
5421 PyObject_HEAD_INIT(NULL)
5422 0, /*ob_size*/
5423 "py_pjsua.Conf_Port_Info", /*tp_name*/
5424 sizeof(conf_port_info_Object), /*tp_basicsize*/
5425 0, /*tp_itemsize*/
5426 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
5427 0, /*tp_print*/
5428 0, /*tp_getattr*/
5429 0, /*tp_setattr*/
5430 0, /*tp_compare*/
5431 0, /*tp_repr*/
5432 0, /*tp_as_number*/
5433 0, /*tp_as_sequence*/
5434 0, /*tp_as_mapping*/
5435 0, /*tp_hash */
5436 0, /*tp_call*/
5437 0, /*tp_str*/
5438 0, /*tp_getattro*/
5439 0, /*tp_setattro*/
5440 0, /*tp_as_buffer*/
5441 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5442 "Conf Port Info objects", /* tp_doc */
5443 0, /* tp_traverse */
5444 0, /* tp_clear */
5445 0, /* tp_richcompare */
5446 0, /* tp_weaklistoffset */
5447 0, /* tp_iter */
5448 0, /* tp_iternext */
5449 0, /* tp_methods */
5450 conf_port_info_members, /* tp_members */
5451 0, /* tp_getset */
5452 0, /* tp_base */
5453 0, /* tp_dict */
5454 0, /* tp_descr_get */
5455 0, /* tp_descr_set */
5456 0, /* tp_dictoffset */
5457 0, /* tp_init */
5458 0, /* tp_alloc */
5459 conf_port_info_new, /* tp_new */
5460
5461};
5462
5463/*
5464 * pjmedia_port_Object
5465 */
5466typedef struct
5467{
5468 PyObject_HEAD
5469 /* Type-specific fields go here. */
5470 pjmedia_port * port;
5471} pjmedia_port_Object;
5472
5473
5474/*
5475 * pjmedia_port_Type
5476 */
5477static PyTypeObject pjmedia_port_Type =
5478{
5479 PyObject_HEAD_INIT(NULL)
5480 0, /*ob_size*/
5481 "py_pjsua.PJMedia_Port", /*tp_name*/
5482 sizeof(pjmedia_port_Object), /*tp_basicsize*/
5483 0, /*tp_itemsize*/
5484 0, /*tp_dealloc*/
5485 0, /*tp_print*/
5486 0, /*tp_getattr*/
5487 0, /*tp_setattr*/
5488 0, /*tp_compare*/
5489 0, /*tp_repr*/
5490 0, /*tp_as_number*/
5491 0, /*tp_as_sequence*/
5492 0, /*tp_as_mapping*/
5493 0, /*tp_hash */
5494 0, /*tp_call*/
5495 0, /*tp_str*/
5496 0, /*tp_getattro*/
5497 0, /*tp_setattro*/
5498 0, /*tp_as_buffer*/
5499 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5500 "pjmedia_port objects", /* tp_doc */
5501
5502};
5503
5504/*
5505 * pjmedia_snd_dev_info_Object
5506 * PJMedia Snd Dev Info
5507 */
5508typedef struct
5509{
5510 PyObject_HEAD
5511 /* Type-specific fields go here. */
5512
5513
5514 unsigned input_count;
5515 unsigned output_count;
5516 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00005517 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00005518
5519} pjmedia_snd_dev_info_Object;
5520
5521
5522/*
5523 * pjmedia_snd_dev_info_dealloc
5524 * deletes a pjmedia_snd_dev_info from memory
5525 */
5526static void pjmedia_snd_dev_info_dealloc(pjmedia_snd_dev_info_Object* self)
5527{
5528 Py_XDECREF(self->name);
5529 self->ob_type->tp_free((PyObject*)self);
5530}
5531
5532
5533/*
5534 * pjmedia_snd_dev_info_new
5535 * constructor for pjmedia_snd_dev_info object
5536 */
5537static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
5538 PyObject *kwds)
5539{
5540 pjmedia_snd_dev_info_Object *self;
5541
5542 self = (pjmedia_snd_dev_info_Object *)type->tp_alloc(type, 0);
5543 if (self != NULL)
5544 {
Fahrise314b882007-02-02 10:52:04 +00005545 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00005546 if (self->name == NULL)
5547 {
5548 Py_DECREF(self);
5549 return NULL;
5550 }
5551
5552 }
5553 return (PyObject *)self;
5554}
5555
5556/*
5557 * pjmedia_snd_dev_info_members
5558 */
5559static PyMemberDef pjmedia_snd_dev_info_members[] =
5560{
5561
5562 {
5563 "name", T_OBJECT_EX,
5564 offsetof(pjmedia_snd_dev_info_Object, name), 0,
5565 "Device name"
5566 },
5567 {
5568 "input_count", T_INT,
5569 offsetof(pjmedia_snd_dev_info_Object, input_count), 0,
5570 "Max number of input channels"
5571 },
5572 {
5573 "output_count", T_INT,
5574 offsetof(pjmedia_snd_dev_info_Object, output_count), 0,
5575 "Max number of output channels"
5576 },
5577 {
5578 "default_samples_per_sec", T_INT,
5579 offsetof(pjmedia_snd_dev_info_Object, default_samples_per_sec), 0,
5580 "Default sampling rate."
5581 },
5582
5583
5584 {NULL} /* Sentinel */
5585};
5586
5587
5588
5589
5590/*
5591 * pjmedia_snd_dev_info_Type
5592 */
5593static PyTypeObject pjmedia_snd_dev_info_Type =
5594{
5595 PyObject_HEAD_INIT(NULL)
5596 0, /*ob_size*/
5597 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
5598 sizeof(pjmedia_snd_dev_info_Object), /*tp_basicsize*/
5599 0, /*tp_itemsize*/
5600 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
5601 0, /*tp_print*/
5602 0, /*tp_getattr*/
5603 0, /*tp_setattr*/
5604 0, /*tp_compare*/
5605 0, /*tp_repr*/
5606 0, /*tp_as_number*/
5607 0, /*tp_as_sequence*/
5608 0, /*tp_as_mapping*/
5609 0, /*tp_hash */
5610 0, /*tp_call*/
5611 0, /*tp_str*/
5612 0, /*tp_getattro*/
5613 0, /*tp_setattro*/
5614 0, /*tp_as_buffer*/
5615 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5616 "PJMedia Snd Dev Info objects", /* tp_doc */
5617 0, /* tp_traverse */
5618 0, /* tp_clear */
5619 0, /* tp_richcompare */
5620 0, /* tp_weaklistoffset */
5621 0, /* tp_iter */
5622 0, /* tp_iternext */
5623 0, /* tp_methods */
5624 pjmedia_snd_dev_info_members, /* tp_members */
5625 0, /* tp_getset */
5626 0, /* tp_base */
5627 0, /* tp_dict */
5628 0, /* tp_descr_get */
5629 0, /* tp_descr_set */
5630 0, /* tp_dictoffset */
5631 0, /* tp_init */
5632 0, /* tp_alloc */
5633 pjmedia_snd_dev_info_new, /* tp_new */
5634
5635};
5636
5637/*
5638 * pjmedia_codec_param_info_Object
5639 * PJMedia Codec Param Info
5640 */
5641typedef struct
5642{
5643 PyObject_HEAD
5644 /* Type-specific fields go here. */
5645
5646 unsigned clock_rate;
5647 unsigned channel_cnt;
5648 pj_uint32_t avg_bps;
5649 pj_uint16_t frm_ptime;
5650 pj_uint8_t pcm_bits_per_sample;
5651 pj_uint8_t pt;
5652
5653} pjmedia_codec_param_info_Object;
5654
5655
5656
5657/*
5658 * pjmedia_codec_param_info_members
5659 */
5660static PyMemberDef pjmedia_codec_param_info_members[] =
5661{
5662
5663 {
5664 "clock_rate", T_INT,
5665 offsetof(pjmedia_codec_param_info_Object, clock_rate), 0,
5666 "Sampling rate in Hz"
5667 },
5668 {
5669 "channel_cnt", T_INT,
5670 offsetof(pjmedia_codec_param_info_Object, channel_cnt), 0,
5671 "Channel count"
5672 },
5673 {
5674 "avg_bps", T_INT,
5675 offsetof(pjmedia_codec_param_info_Object, avg_bps), 0,
5676 "Average bandwidth in bits/sec"
5677 },
5678 {
5679 "frm_ptime", T_INT,
5680 offsetof(pjmedia_codec_param_info_Object, frm_ptime), 0,
5681 "Base frame ptime in msec."
5682 },
5683 {
5684 "pcm_bits_per_sample", T_INT,
5685 offsetof(pjmedia_codec_param_info_Object, pcm_bits_per_sample), 0,
5686 "Bits/sample in the PCM side"
5687 },
5688 {
5689 "pt", T_INT,
5690 offsetof(pjmedia_codec_param_info_Object, pt), 0,
5691 "Payload type"
5692 },
5693
5694 {NULL} /* Sentinel */
5695};
5696
5697
5698
5699
5700/*
5701 * pjmedia_codec_param_info_Type
5702 */
5703static PyTypeObject pjmedia_codec_param_info_Type =
5704{
5705 PyObject_HEAD_INIT(NULL)
5706 0, /*ob_size*/
5707 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
5708 sizeof(pjmedia_codec_param_info_Object), /*tp_basicsize*/
5709 0, /*tp_itemsize*/
5710 0,/*tp_dealloc*/
5711 0, /*tp_print*/
5712 0, /*tp_getattr*/
5713 0, /*tp_setattr*/
5714 0, /*tp_compare*/
5715 0, /*tp_repr*/
5716 0, /*tp_as_number*/
5717 0, /*tp_as_sequence*/
5718 0, /*tp_as_mapping*/
5719 0, /*tp_hash */
5720 0, /*tp_call*/
5721 0, /*tp_str*/
5722 0, /*tp_getattro*/
5723 0, /*tp_setattro*/
5724 0, /*tp_as_buffer*/
5725 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5726 "PJMedia Codec Param Info objects", /* tp_doc */
5727 0, /* tp_traverse */
5728 0, /* tp_clear */
5729 0, /* tp_richcompare */
5730 0, /* tp_weaklistoffset */
5731 0, /* tp_iter */
5732 0, /* tp_iternext */
5733 0, /* tp_methods */
5734 pjmedia_codec_param_info_members, /* tp_members */
5735
5736
5737};
5738
5739/*
5740 * pjmedia_codec_param_setting_Object
5741 * PJMedia Codec Param Setting
5742 */
5743typedef struct
5744{
5745 PyObject_HEAD
5746 /* Type-specific fields go here. */
5747 pj_uint8_t frm_per_pkt;
5748 unsigned vad;
5749 unsigned cng;
5750 unsigned penh;
5751 unsigned plc;
5752 unsigned reserved;
5753 pj_uint8_t enc_fmtp_mode;
5754 pj_uint8_t dec_fmtp_mode;
5755
5756} pjmedia_codec_param_setting_Object;
5757
5758
5759
5760/*
5761 * pjmedia_codec_param_setting_members
5762 */
5763static PyMemberDef pjmedia_codec_param_setting_members[] =
5764{
5765
5766 {
5767 "frm_per_pkt", T_INT,
5768 offsetof(pjmedia_codec_param_setting_Object, frm_per_pkt), 0,
5769 "Number of frames per packet"
5770 },
5771 {
5772 "vad", T_INT,
5773 offsetof(pjmedia_codec_param_setting_Object, vad), 0,
5774 "Voice Activity Detector"
5775 },
5776 {
5777 "penh", T_INT,
5778 offsetof(pjmedia_codec_param_setting_Object, penh), 0,
5779 "Perceptual Enhancement"
5780 },
5781 {
5782 "plc", T_INT,
5783 offsetof(pjmedia_codec_param_setting_Object, plc), 0,
5784 "Packet loss concealment"
5785 },
5786 {
5787 "reserved", T_INT,
5788 offsetof(pjmedia_codec_param_setting_Object, reserved), 0,
5789 "Reserved, must be zero"
5790 },
5791 {
5792 "cng", T_INT,
5793 offsetof(pjmedia_codec_param_setting_Object, cng), 0,
5794 "Comfort Noise Generator"
5795 },
5796 {
5797 "enc_fmtp_mode", T_INT,
5798 offsetof(pjmedia_codec_param_setting_Object, enc_fmtp_mode), 0,
5799 "Mode param in fmtp (def:0)"
5800 },
5801 {
5802 "dec_fmtp_mode", T_INT,
5803 offsetof(pjmedia_codec_param_setting_Object, dec_fmtp_mode), 0,
5804 "Mode param in fmtp (def:0)"
5805 },
5806
5807 {NULL} /* Sentinel */
5808};
5809
5810
5811
5812
5813/*
5814 * pjmedia_codec_param_setting_Type
5815 */
5816static PyTypeObject pjmedia_codec_param_setting_Type =
5817{
5818 PyObject_HEAD_INIT(NULL)
5819 0, /*ob_size*/
5820 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
5821 sizeof(pjmedia_codec_param_setting_Object), /*tp_basicsize*/
5822 0, /*tp_itemsize*/
5823 0,/*tp_dealloc*/
5824 0, /*tp_print*/
5825 0, /*tp_getattr*/
5826 0, /*tp_setattr*/
5827 0, /*tp_compare*/
5828 0, /*tp_repr*/
5829 0, /*tp_as_number*/
5830 0, /*tp_as_sequence*/
5831 0, /*tp_as_mapping*/
5832 0, /*tp_hash */
5833 0, /*tp_call*/
5834 0, /*tp_str*/
5835 0, /*tp_getattro*/
5836 0, /*tp_setattro*/
5837 0, /*tp_as_buffer*/
5838 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5839 "PJMedia Codec Param Setting objects", /* tp_doc */
5840 0, /* tp_traverse */
5841 0, /* tp_clear */
5842 0, /* tp_richcompare */
5843 0, /* tp_weaklistoffset */
5844 0, /* tp_iter */
5845 0, /* tp_iternext */
5846 0, /* tp_methods */
5847 pjmedia_codec_param_setting_members, /* tp_members */
5848
5849
5850};
5851
5852/*
5853 * pjmedia_codec_param_Object
5854 * PJMedia Codec Param
5855 */
5856typedef struct
5857{
5858 PyObject_HEAD
5859 /* Type-specific fields go here. */
5860
5861 pjmedia_codec_param_info_Object * info;
5862 pjmedia_codec_param_setting_Object * setting;
5863
5864} pjmedia_codec_param_Object;
5865
5866
5867/*
5868 * pjmedia_codec_param_dealloc
5869 * deletes a pjmedia_codec_param from memory
5870 */
5871static void pjmedia_codec_param_dealloc(pjmedia_codec_param_Object* self)
5872{
5873 Py_XDECREF(self->info);
5874 Py_XDECREF(self->setting);
5875 self->ob_type->tp_free((PyObject*)self);
5876}
5877
5878
5879/*
5880 * pjmedia_codec_param_new
5881 * constructor for pjmedia_codec_param object
5882 */
5883static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
5884 PyObject *kwds)
5885{
5886 pjmedia_codec_param_Object *self;
5887
5888 self = (pjmedia_codec_param_Object *)type->tp_alloc(type, 0);
5889 if (self != NULL)
5890 {
5891 self->info = (pjmedia_codec_param_info_Object *)
5892 PyType_GenericNew(&pjmedia_codec_param_info_Type, NULL, NULL);
5893 if (self->info == NULL)
5894 {
5895 Py_DECREF(self);
5896 return NULL;
5897 }
5898 self->setting = (pjmedia_codec_param_setting_Object *)
5899 PyType_GenericNew(&pjmedia_codec_param_setting_Type, NULL, NULL);
5900 if (self->setting == NULL)
5901 {
5902 Py_DECREF(self);
5903 return NULL;
5904 }
5905 }
5906 return (PyObject *)self;
5907}
5908
5909/*
5910 * pjmedia_codec_param_members
5911 */
5912static PyMemberDef pjmedia_codec_param_members[] =
5913{
5914
5915 {
5916 "info", T_OBJECT_EX,
5917 offsetof(pjmedia_codec_param_Object, info), 0,
5918 "The 'info' part of codec param describes the capability of the codec,"
5919 " and the value should NOT be changed by application."
5920 },
5921 {
5922 "setting", T_OBJECT_EX,
5923 offsetof(pjmedia_codec_param_Object, setting), 0,
5924 "The 'setting' part of codec param describes various settings to be "
5925 "applied to the codec. When the codec param is retrieved from the "
5926 "codec or codec factory, the values of these will be filled by "
5927 "the capability of the codec. Any features that are supported by "
5928 "the codec (e.g. vad or plc) will be turned on, so that application "
5929 "can query which capabilities are supported by the codec. "
5930 "Application may change the settings here before instantiating "
5931 "the codec/stream."
5932 },
5933
5934 {NULL} /* Sentinel */
5935};
5936
5937
5938
5939
5940/*
5941 * pjmedia_codec_param_Type
5942 */
5943static PyTypeObject pjmedia_codec_param_Type =
5944{
5945 PyObject_HEAD_INIT(NULL)
5946 0, /*ob_size*/
5947 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
5948 sizeof(pjmedia_codec_param_Object), /*tp_basicsize*/
5949 0, /*tp_itemsize*/
5950 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
5951 0, /*tp_print*/
5952 0, /*tp_getattr*/
5953 0, /*tp_setattr*/
5954 0, /*tp_compare*/
5955 0, /*tp_repr*/
5956 0, /*tp_as_number*/
5957 0, /*tp_as_sequence*/
5958 0, /*tp_as_mapping*/
5959 0, /*tp_hash */
5960 0, /*tp_call*/
5961 0, /*tp_str*/
5962 0, /*tp_getattro*/
5963 0, /*tp_setattro*/
5964 0, /*tp_as_buffer*/
5965 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5966 "PJMedia Codec Param objects", /* tp_doc */
5967 0, /* tp_traverse */
5968 0, /* tp_clear */
5969 0, /* tp_richcompare */
5970 0, /* tp_weaklistoffset */
5971 0, /* tp_iter */
5972 0, /* tp_iternext */
5973 0, /* tp_methods */
5974 pjmedia_codec_param_members, /* tp_members */
5975 0, /* tp_getset */
5976 0, /* tp_base */
5977 0, /* tp_dict */
5978 0, /* tp_descr_get */
5979 0, /* tp_descr_set */
5980 0, /* tp_dictoffset */
5981 0, /* tp_init */
5982 0, /* tp_alloc */
5983 pjmedia_codec_param_new, /* tp_new */
5984
5985};
5986
5987/*
5988 * py_pjsua_conf_get_max_ports
5989 */
5990static PyObject *py_pjsua_conf_get_max_ports
5991(PyObject *pSelf, PyObject *pArgs)
5992{
5993 int ret;
5994
5995 if (!PyArg_ParseTuple(pArgs, ""))
5996 {
5997 return NULL;
5998 }
5999 ret = pjsua_conf_get_max_ports();
6000
6001 return Py_BuildValue("i", ret);
6002}
6003
6004/*
6005 * py_pjsua_conf_get_active_ports
6006 */
6007static PyObject *py_pjsua_conf_get_active_ports
6008(PyObject *pSelf, PyObject *pArgs)
6009{
6010 int ret;
6011 if (!PyArg_ParseTuple(pArgs, ""))
6012 {
6013 return NULL;
6014 }
6015 ret = pjsua_conf_get_active_ports();
6016
6017 return Py_BuildValue("i", ret);
6018}
6019
6020/*
6021 * py_pjsua_enum_conf_ports
6022 * !modified @ 241206
6023 */
6024static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
6025{
6026 pj_status_t status;
6027 PyObject *list;
6028
6029 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00006030 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006031 if (!PyArg_ParseTuple(pArgs, ""))
6032 {
6033 return NULL;
6034 }
6035
6036 c = PJ_ARRAY_SIZE(id);
6037 status = pjsua_enum_conf_ports(id, &c);
6038
6039 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006040 for (i = 0; i < c; i++)
6041 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006042 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00006043 if (ret == -1)
6044 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006045 return NULL;
6046 }
6047 }
6048
Fahrisdcf8fa42006-12-28 03:13:48 +00006049 return Py_BuildValue("O",list);
6050}
6051
6052/*
6053 * py_pjsua_conf_get_port_info
6054 */
6055static PyObject *py_pjsua_conf_get_port_info
6056(PyObject *pSelf, PyObject *pArgs)
6057{
6058 int id;
6059 conf_port_info_Object * obj;
6060 pjsua_conf_port_info info;
6061 int status;
6062 int i;
6063
6064 if (!PyArg_ParseTuple(pArgs, "i", &id))
6065 {
6066 return NULL;
6067 }
6068
6069
6070 status = pjsua_conf_get_port_info(id, &info);
6071 obj = (conf_port_info_Object *)conf_port_info_new
6072 (&conf_port_info_Type,NULL,NULL);
6073 obj->bits_per_sample = info.bits_per_sample;
6074 obj->channel_count = info.bits_per_sample;
6075 obj->clock_rate = info.clock_rate;
6076 obj->listener_cnt = info.listener_cnt;
6077 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
6078 obj->samples_per_frame = info.samples_per_frame;
6079 obj->slot_id = info.slot_id;
6080
Fahris6f35cb82007-02-01 07:41:26 +00006081 for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00006082 PyObject * item = Py_BuildValue("i",info.listeners[i]);
6083 PyList_SetItem((PyObject *)obj->listeners, i, item);
6084 }
6085 return Py_BuildValue("O", obj);
6086}
6087
6088/*
6089 * py_pjsua_conf_add_port
6090 */
6091static PyObject *py_pjsua_conf_add_port
6092(PyObject *pSelf, PyObject *pArgs)
6093{
6094 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00006095 PyObject * oportObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006096 pjmedia_port_Object * oport;
Fahris6f35cb82007-02-01 07:41:26 +00006097 pjmedia_port * port;
6098 PyObject * opoolObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006099 pj_pool_Object * opool;
Fahris6f35cb82007-02-01 07:41:26 +00006100 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00006101
6102 int status;
6103
6104
Fahris17d91812007-01-29 12:09:33 +00006105 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006106 {
6107 return NULL;
6108 }
Fahris17d91812007-01-29 12:09:33 +00006109 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006110 {
Fahris17d91812007-01-29 12:09:33 +00006111 opool = (pj_pool_Object *)opoolObj;
6112 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00006113 } else {
6114 opool = NULL;
6115 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00006116 }
6117 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006118 {
Fahris17d91812007-01-29 12:09:33 +00006119 oport = (pjmedia_port_Object *)oportObj;
6120 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00006121 } else {
Fahris17d91812007-01-29 12:09:33 +00006122 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00006123 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00006124 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006125
Fahris17d91812007-01-29 12:09:33 +00006126 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00006127
6128
6129 return Py_BuildValue("ii", status, p_id);
6130}
6131
6132/*
6133 * py_pjsua_conf_remove_port
6134 */
6135static PyObject *py_pjsua_conf_remove_port
6136(PyObject *pSelf, PyObject *pArgs)
6137{
6138 int id;
6139 int status;
6140
6141
6142 if (!PyArg_ParseTuple(pArgs, "i", &id))
6143 {
6144 return NULL;
6145 }
6146
6147 status = pjsua_conf_remove_port(id);
6148
6149
6150 return Py_BuildValue("i", status);
6151}
6152
6153/*
6154 * py_pjsua_conf_connect
6155 */
6156static PyObject *py_pjsua_conf_connect
6157(PyObject *pSelf, PyObject *pArgs)
6158{
6159 int source, sink;
6160 int status;
6161
6162
6163 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6164 {
6165 return NULL;
6166 }
6167
6168 status = pjsua_conf_connect(source, sink);
6169
6170
6171 return Py_BuildValue("i", status);
6172}
6173
6174/*
6175 * py_pjsua_conf_disconnect
6176 */
6177static PyObject *py_pjsua_conf_disconnect
6178(PyObject *pSelf, PyObject *pArgs)
6179{
6180 int source, sink;
6181 int status;
6182
6183
6184 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6185 {
6186 return NULL;
6187 }
6188
6189 status = pjsua_conf_disconnect(source, sink);
6190
6191
6192 return Py_BuildValue("i", status);
6193}
6194
6195/*
6196 * py_pjsua_player_create
6197 */
6198static PyObject *py_pjsua_player_create
6199(PyObject *pSelf, PyObject *pArgs)
6200{
6201 int id;
6202 int options;
6203 PyObject * filename;
6204 pj_str_t str;
6205 int status;
6206
6207
6208 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
6209 {
6210 return NULL;
6211 }
6212 str.ptr = PyString_AsString(filename);
6213 str.slen = strlen(PyString_AsString(filename));
6214 status = pjsua_player_create(&str, options, &id);
6215
6216 return Py_BuildValue("ii", status, id);
6217}
6218
6219/*
6220 * py_pjsua_player_get_conf_port
6221 */
6222static PyObject *py_pjsua_player_get_conf_port
6223(PyObject *pSelf, PyObject *pArgs)
6224{
6225
6226 int id, port_id;
6227
6228
6229 if (!PyArg_ParseTuple(pArgs, "i", &id))
6230 {
6231 return NULL;
6232 }
6233
6234 port_id = pjsua_player_get_conf_port(id);
6235
6236
6237 return Py_BuildValue("i", port_id);
6238}
6239
6240/*
6241 * py_pjsua_player_set_pos
6242 */
6243static PyObject *py_pjsua_player_set_pos
6244(PyObject *pSelf, PyObject *pArgs)
6245{
6246 int id;
6247 pj_uint32_t samples;
6248 int status;
6249
6250
6251 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
6252 {
6253 return NULL;
6254 }
6255
6256 status = pjsua_player_set_pos(id, samples);
6257
6258
6259 return Py_BuildValue("i", status);
6260}
6261
6262/*
6263 * py_pjsua_player_destroy
6264 */
6265static PyObject *py_pjsua_player_destroy
6266(PyObject *pSelf, PyObject *pArgs)
6267{
6268 int id;
6269 int status;
6270
6271
6272 if (!PyArg_ParseTuple(pArgs, "i", &id))
6273 {
6274 return NULL;
6275 }
6276
6277 status = pjsua_player_destroy(id);
6278
6279
6280 return Py_BuildValue("i", status);
6281}
6282
6283/*
6284 * py_pjsua_recorder_create
6285 * !modified @ 261206
6286 */
6287static PyObject *py_pjsua_recorder_create
6288(PyObject *pSelf, PyObject *pArgs)
6289{
6290 int p_id;
6291 int options;
6292 int max_size;
6293 PyObject * filename;
6294 pj_str_t str;
6295 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00006296 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00006297 int enc_type;
6298
6299 int status;
6300
6301
Fahris17d91812007-01-29 12:09:33 +00006302 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
6303 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00006304 {
6305 return NULL;
6306 }
6307 str.ptr = PyString_AsString(filename);
6308 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00006309 if (enc_param != Py_None)
6310 {
6311 strparam.ptr = PyString_AsString(enc_param);
6312 strparam.slen = strlen(PyString_AsString(enc_param));
6313 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00006314 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00006315 } else {
6316 status = pjsua_recorder_create
6317 (&str, enc_type, NULL, max_size, options, &p_id);
6318 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006319 return Py_BuildValue("ii", status, p_id);
6320}
6321
6322/*
6323 * py_pjsua_recorder_get_conf_port
6324 */
6325static PyObject *py_pjsua_recorder_get_conf_port
6326(PyObject *pSelf, PyObject *pArgs)
6327{
6328
6329 int id, port_id;
6330
6331
6332 if (!PyArg_ParseTuple(pArgs, "i", &id))
6333 {
6334 return NULL;
6335 }
6336
6337 port_id = pjsua_recorder_get_conf_port(id);
6338
6339
6340 return Py_BuildValue("i", port_id);
6341}
6342
6343/*
6344 * py_pjsua_recorder_destroy
6345 */
6346static PyObject *py_pjsua_recorder_destroy
6347(PyObject *pSelf, PyObject *pArgs)
6348{
6349 int id;
6350 int status;
6351
6352
6353 if (!PyArg_ParseTuple(pArgs, "i", &id))
6354 {
6355 return NULL;
6356 }
6357
6358 status = pjsua_recorder_destroy(id);
6359
6360
6361 return Py_BuildValue("i", status);
6362}
6363
6364/*
6365 * py_pjsua_enum_snd_devs
6366 */
6367static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
6368{
6369 pj_status_t status;
6370 PyObject *list;
6371
Fahris6f35cb82007-02-01 07:41:26 +00006372 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00006373 unsigned c, i;
Fahrisb721aa32007-01-29 05:07:41 +00006374 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00006375 {
6376 return NULL;
6377 }
6378
Fahrisb721aa32007-01-29 05:07:41 +00006379 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00006380 status = pjsua_enum_snd_devs(info, &c);
6381
6382 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006383 for (i = 0; i < c; i++)
6384 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006385 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00006386 int j;
Fahrise314b882007-02-02 10:52:04 +00006387 char * str;
6388
Fahrisdcf8fa42006-12-28 03:13:48 +00006389 pjmedia_snd_dev_info_Object * obj;
6390 obj = (pjmedia_snd_dev_info_Object *)pjmedia_snd_dev_info_new
6391 (&pjmedia_snd_dev_info_Type, NULL, NULL);
6392 obj->default_samples_per_sec = info[i].default_samples_per_sec;
6393 obj->input_count = info[i].input_count;
6394 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00006395 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
6396 memset(str, 0, SND_NAME_LEN);
6397 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00006398 {
Fahrise314b882007-02-02 10:52:04 +00006399 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00006400 }
Fahrise314b882007-02-02 10:52:04 +00006401 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
6402 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00006403 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00006404 if (ret == -1)
6405 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006406 return NULL;
6407 }
6408 }
6409
Fahrisdcf8fa42006-12-28 03:13:48 +00006410 return Py_BuildValue("O",list);
6411}
6412
6413/*
6414 * py_pjsua_get_snd_dev
6415 */
6416static PyObject *py_pjsua_get_snd_dev
6417(PyObject *pSelf, PyObject *pArgs)
6418{
6419 int capture_dev, playback_dev;
6420 int status;
6421
6422
6423 if (!PyArg_ParseTuple(pArgs, ""))
6424 {
6425 return NULL;
6426 }
6427
6428 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
6429
6430
6431 return Py_BuildValue("ii", capture_dev, playback_dev);
6432}
6433
6434/*
6435 * py_pjsua_set_snd_dev
6436 */
6437static PyObject *py_pjsua_set_snd_dev
6438(PyObject *pSelf, PyObject *pArgs)
6439{
6440 int capture_dev, playback_dev;
6441 int status;
6442
6443
6444 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
6445 {
6446 return NULL;
6447 }
6448
6449 status = pjsua_set_snd_dev(capture_dev, playback_dev);
6450
6451
6452 return Py_BuildValue("i", status);
6453}
6454
6455/*
6456 * py_pjsua_set_null_snd_dev
6457 */
6458static PyObject *py_pjsua_set_null_snd_dev
6459(PyObject *pSelf, PyObject *pArgs)
6460{
6461
6462 int status;
6463
6464
6465 if (!PyArg_ParseTuple(pArgs, ""))
6466 {
6467 return NULL;
6468 }
6469
6470 status = pjsua_set_null_snd_dev();
6471
6472
6473 return Py_BuildValue("i", status);
6474}
6475
6476/*
6477 * py_pjsua_set_no_snd_dev
6478 */
6479static PyObject *py_pjsua_set_no_snd_dev
6480(PyObject *pSelf, PyObject *pArgs)
6481{
6482
6483 pjmedia_port_Object * obj;
6484
6485 if (!PyArg_ParseTuple(pArgs, ""))
6486 {
6487 return NULL;
6488 }
6489
6490 obj = (pjmedia_port_Object *)PyType_GenericNew
6491 (&pjmedia_port_Type, NULL, NULL);
6492 obj->port = pjsua_set_no_snd_dev();
6493 return Py_BuildValue("O", obj);
6494}
6495
6496/*
6497 * py_pjsua_set_ec
6498 */
6499static PyObject *py_pjsua_set_ec
6500(PyObject *pSelf, PyObject *pArgs)
6501{
6502 int options;
6503 int tail_ms;
6504 int status;
6505
6506
6507 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
6508 {
6509 return NULL;
6510 }
6511
6512 status = pjsua_set_ec(tail_ms, options);
6513
6514
6515 return Py_BuildValue("i", status);
6516}
6517
6518/*
6519 * py_pjsua_get_ec_tail
6520 */
6521static PyObject *py_pjsua_get_ec_tail
6522(PyObject *pSelf, PyObject *pArgs)
6523{
6524
6525 int status;
Fahris17d91812007-01-29 12:09:33 +00006526 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00006527
6528 if (!PyArg_ParseTuple(pArgs, ""))
6529 {
6530 return NULL;
6531 }
6532
6533 status = pjsua_get_ec_tail(&p_tail_ms);
6534
6535
6536 return Py_BuildValue("i", p_tail_ms);
6537}
6538
6539/*
6540 * py_pjsua_enum_codecs
6541 * !modified @ 261206
6542 */
6543static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
6544{
6545 pj_status_t status;
6546 PyObject *list;
6547
6548 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00006549 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006550 if (!PyArg_ParseTuple(pArgs, ""))
6551 {
6552 return NULL;
6553 }
6554
6555 c = PJ_ARRAY_SIZE(info);
6556 status = pjsua_enum_codecs(info, &c);
6557
6558 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006559 for (i = 0; i < c; i++)
6560 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006561 int ret;
6562 int j;
6563 codec_info_Object * obj;
6564 obj = (codec_info_Object *)codec_info_new
6565 (&codec_info_Type, NULL, NULL);
6566 obj->codec_id = PyString_FromStringAndSize
6567 (info[i].codec_id.ptr, info[i].codec_id.slen);
6568 obj->priority = info[i].priority;
6569 for (j = 0; j < 32; j++)
6570 {
6571 obj->buf_[j] = info[i].buf_[j];
6572 }
6573 ret = PyList_SetItem(list, i, (PyObject *)obj);
6574 if (ret == -1) {
6575 return NULL;
6576 }
6577 }
6578
Fahris17d91812007-01-29 12:09:33 +00006579
Fahrisdcf8fa42006-12-28 03:13:48 +00006580 return Py_BuildValue("O",list);
6581}
6582
6583/*
6584 * py_pjsua_codec_set_priority
6585 */
6586static PyObject *py_pjsua_codec_set_priority
6587(PyObject *pSelf, PyObject *pArgs)
6588{
6589
6590 int status;
6591 PyObject * id;
6592 pj_str_t str;
6593 pj_uint8_t priority;
6594
6595 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
6596 {
6597 return NULL;
6598 }
6599 str.ptr = PyString_AsString(id);
6600 str.slen = strlen(PyString_AsString(id));
6601 status = pjsua_codec_set_priority(&str, priority);
6602
6603
6604 return Py_BuildValue("i", status);
6605}
6606
6607/*
6608 * py_pjsua_codec_get_param
6609 */
6610static PyObject *py_pjsua_codec_get_param
6611(PyObject *pSelf, PyObject *pArgs)
6612{
6613
6614 int status;
6615 PyObject * id;
6616 pj_str_t str;
6617 pjmedia_codec_param param;
6618 pjmedia_codec_param_Object *obj;
6619
6620
6621 if (!PyArg_ParseTuple(pArgs, "O", &id))
6622 {
6623 return NULL;
6624 }
6625 str.ptr = PyString_AsString(id);
6626 str.slen = strlen(PyString_AsString(id));
6627 status = pjsua_codec_get_param(&str, &param);
6628 obj = (pjmedia_codec_param_Object *)pjmedia_codec_param_new
6629 (&pjmedia_codec_param_Type, NULL, NULL);
6630 obj->info->avg_bps = param.info.avg_bps;
6631 obj->info->channel_cnt = param.info.channel_cnt;
6632 obj->info->clock_rate = param.info.clock_rate;
6633 obj->info->frm_ptime = param.info.frm_ptime;
6634 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
6635 obj->info->pt = param.info.pt;
6636 obj->setting->cng = param.setting.cng;
6637 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
6638 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
6639 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
6640 obj->setting->penh = param.setting.penh;
6641 obj->setting->plc = param.setting.plc;
6642 obj->setting->reserved = param.setting.reserved;
6643 obj->setting->vad = param.setting.vad;
6644
6645 return Py_BuildValue("O", obj);
6646}
6647/*
6648 * py_pjsua_codec_set_param
6649 */
6650static PyObject *py_pjsua_codec_set_param
6651(PyObject *pSelf, PyObject *pArgs)
6652{
6653
6654 int status;
6655 PyObject * id;
6656 pj_str_t str;
6657 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00006658 PyObject * tmpObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006659 pjmedia_codec_param_Object *obj;
6660
6661
Fahris17d91812007-01-29 12:09:33 +00006662 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006663 {
6664 return NULL;
6665 }
Fahris17d91812007-01-29 12:09:33 +00006666
Fahrisdcf8fa42006-12-28 03:13:48 +00006667 str.ptr = PyString_AsString(id);
6668 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00006669 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006670 {
Fahris17d91812007-01-29 12:09:33 +00006671 obj = (pjmedia_codec_param_Object *)tmpObj;
6672 param.info.avg_bps = obj->info->avg_bps;
6673 param.info.channel_cnt = obj->info->channel_cnt;
6674 param.info.clock_rate = obj->info->clock_rate;
6675 param.info.frm_ptime = obj->info->frm_ptime;
6676 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
6677 param.info.pt = obj->info->pt;
6678 param.setting.cng = obj->setting->cng;
6679 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
6680 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
6681 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
6682 param.setting.penh = obj->setting->penh;
6683 param.setting.plc = obj->setting->plc;
6684 param.setting.reserved = obj->setting->reserved;
6685 param.setting.vad = obj->setting->vad;
6686 status = pjsua_codec_set_param(&str, &param);
6687 } else {
6688 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00006689 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006690 return Py_BuildValue("i", status);
6691}
6692
6693static char pjsua_conf_get_max_ports_doc[] =
6694 "int py_pjsua.conf_get_max_ports () "
6695 "Get maxinum number of conference ports.";
6696static char pjsua_conf_get_active_ports_doc[] =
6697 "int py_pjsua.conf_get_active_ports () "
6698 "Get current number of active ports in the bridge.";
6699static char pjsua_enum_conf_ports_doc[] =
6700 "int[] py_pjsua.enum_conf_ports () "
6701 "Enumerate all conference ports.";
6702static char pjsua_conf_get_port_info_doc[] =
6703 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
6704 "Get information about the specified conference port";
6705static char pjsua_conf_add_port_doc[] =
6706 "int, int py_pjsua.conf_add_port "
6707 "(py_pjsua.PJ_Pool pool, py_pjsua.PJMedia_Port port) "
6708 "Add arbitrary media port to PJSUA's conference bridge. "
6709 "Application can use this function to add the media port "
6710 "that it creates. For media ports that are created by PJSUA-LIB "
6711 "(such as calls, file player, or file recorder), PJSUA-LIB will "
6712 "automatically add the port to the bridge.";
6713static char pjsua_conf_remove_port_doc[] =
6714 "int py_pjsua.conf_remove_port (int id) "
6715 "Remove arbitrary slot from the conference bridge. "
6716 "Application should only call this function "
6717 "if it registered the port manually.";
6718static char pjsua_conf_connect_doc[] =
6719 "int py_pjsua.conf_connect (int source, int sink) "
6720 "Establish unidirectional media flow from souce to sink. "
6721 "One source may transmit to multiple destinations/sink. "
6722 "And if multiple sources are transmitting to the same sink, "
6723 "the media will be mixed together. Source and sink may refer "
6724 "to the same ID, effectively looping the media. "
6725 "If bidirectional media flow is desired, application "
6726 "needs to call this function twice, with the second "
6727 "one having the arguments reversed.";
6728static char pjsua_conf_disconnect_doc[] =
6729 "int py_pjsua.conf_disconnect (int source, int sink) "
6730 "Disconnect media flow from the source to destination port.";
6731static char pjsua_player_create_doc[] =
6732 "int, int py_pjsua.player_create (string filename, int options) "
6733 "Create a file player, and automatically connect "
6734 "this player to the conference bridge.";
6735static char pjsua_player_get_conf_port_doc[] =
6736 "int py_pjsua.player_get_conf_port (int) "
6737 "Get conference port ID associated with player.";
6738static char pjsua_player_set_pos_doc[] =
6739 "int py_pjsua.player_set_pos (int id, int samples) "
6740 "Set playback position.";
6741static char pjsua_player_destroy_doc[] =
6742 "int py_pjsua.player_destroy (int id) "
6743 "Close the file, remove the player from the bridge, "
6744 "and free resources associated with the file player.";
6745static char pjsua_recorder_create_doc[] =
6746 "int, int py_pjsua.recorder_create (string filename, "
6747 "int enc_type, int enc_param, int max_size, int options) "
6748 "Create a file recorder, and automatically connect this recorder "
6749 "to the conference bridge. The recorder currently supports recording "
6750 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
6751 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
6752static char pjsua_recorder_get_conf_port_doc[] =
6753 "int py_pjsua.recorder_get_conf_port (int id) "
6754 "Get conference port associated with recorder.";
6755static char pjsua_recorder_destroy_doc[] =
6756 "int py_pjsua.recorder_destroy (int id) "
6757 "Destroy recorder (this will complete recording).";
6758static char pjsua_enum_snd_devs_doc[] =
6759 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
6760 "Enum sound devices.";
6761static char pjsua_get_snd_dev_doc[] =
6762 "int, int py_pjsua.get_snd_dev () "
6763 "Get currently active sound devices. "
6764 "If sound devices has not been created "
6765 "(for example when pjsua_start() is not called), "
6766 "it is possible that the function returns "
6767 "PJ_SUCCESS with -1 as device IDs.";
6768static char pjsua_set_snd_dev_doc[] =
6769 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
6770 "Select or change sound device. Application may call this function "
6771 "at any time to replace current sound device.";
6772static char pjsua_set_null_snd_dev_doc[] =
6773 "int py_pjsua.set_null_snd_dev () "
6774 "Set pjsua to use null sound device. The null sound device only "
6775 "provides the timing needed by the conference bridge, and will not "
6776 "interract with any hardware.";
6777static char pjsua_set_no_snd_dev_doc[] =
6778 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
6779 "Disconnect the main conference bridge from any sound devices, "
6780 "and let application connect the bridge to it's "
6781 "own sound device/master port.";
6782static char pjsua_set_ec_doc[] =
6783 "int py_pjsua.set_ec (int tail_ms, int options) "
6784 "Configure the echo canceller tail length of the sound port.";
6785static char pjsua_get_ec_tail_doc[] =
6786 "int py_pjsua.get_ec_tail () "
6787 "Get current echo canceller tail length.";
6788static char pjsua_enum_codecs_doc[] =
6789 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
6790 "Enum all supported codecs in the system.";
6791static char pjsua_codec_set_priority_doc[] =
6792 "int py_pjsua.codec_set_priority (string id, int priority) "
6793 "Change codec priority.";
6794static char pjsua_codec_get_param_doc[] =
6795 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
6796 "Get codec parameters";
6797static char pjsua_codec_set_param_doc[] =
6798 "int py_pjsua.codec_set_param (string id, "
6799 "py_pjsua.PJMedia_Codec_Param param) "
6800 "Set codec parameters.";
6801
6802/* END OF LIB MEDIA */
6803
6804/* LIB CALL */
6805
6806/*
6807 * pj_time_val_Object
6808 * PJ Time Val
6809 */
6810typedef struct
6811{
6812 PyObject_HEAD
6813 /* Type-specific fields go here. */
6814 long sec;
6815 long msec;
6816
6817} pj_time_val_Object;
6818
6819
6820
6821/*
6822 * pj_time_val_members
6823 */
6824static PyMemberDef pj_time_val_members[] =
6825{
6826
6827 {
6828 "sec", T_INT,
6829 offsetof(pj_time_val_Object, sec), 0,
6830 "The seconds part of the time"
6831 },
6832 {
6833 "msec", T_INT,
6834 offsetof(pj_time_val_Object, sec), 0,
6835 "The milliseconds fraction of the time"
6836 },
6837
6838
6839 {NULL} /* Sentinel */
6840};
6841
6842
6843
6844
6845/*
6846 * pj_time_val_Type
6847 */
6848static PyTypeObject pj_time_val_Type =
6849{
6850 PyObject_HEAD_INIT(NULL)
6851 0, /*ob_size*/
6852 "py_pjsua.PJ_Time_Val", /*tp_name*/
6853 sizeof(pj_time_val_Object), /*tp_basicsize*/
6854 0, /*tp_itemsize*/
6855 0,/*tp_dealloc*/
6856 0, /*tp_print*/
6857 0, /*tp_getattr*/
6858 0, /*tp_setattr*/
6859 0, /*tp_compare*/
6860 0, /*tp_repr*/
6861 0, /*tp_as_number*/
6862 0, /*tp_as_sequence*/
6863 0, /*tp_as_mapping*/
6864 0, /*tp_hash */
6865 0, /*tp_call*/
6866 0, /*tp_str*/
6867 0, /*tp_getattro*/
6868 0, /*tp_setattro*/
6869 0, /*tp_as_buffer*/
6870 Py_TPFLAGS_DEFAULT, /*tp_flags*/
6871 "PJ Time Val objects", /* tp_doc */
6872 0, /* tp_traverse */
6873 0, /* tp_clear */
6874 0, /* tp_richcompare */
6875 0, /* tp_weaklistoffset */
6876 0, /* tp_iter */
6877 0, /* tp_iternext */
6878 0, /* tp_methods */
6879 pj_time_val_members, /* tp_members */
6880
6881
6882};
6883
6884/*
6885 * call_info_Object
6886 * Call Info
6887 */
6888typedef struct
6889{
6890 PyObject_HEAD
6891 /* Type-specific fields go here. */
6892
6893 int id;
6894 int role;
6895 int acc_id;
6896 PyObject * local_info;
6897 PyObject * local_contact;
6898 PyObject * remote_info;
6899 PyObject * remote_contact;
6900 PyObject * call_id;
6901 int state;
6902 PyObject * state_text;
6903 int last_status;
6904 PyObject * last_status_text;
6905 int media_status;
6906 int media_dir;
6907 int conf_slot;
6908 pj_time_val_Object * connect_duration;
6909 pj_time_val_Object * total_duration;
6910 struct {
6911 char local_info[128];
6912 char local_contact[128];
6913 char remote_info[128];
6914 char remote_contact[128];
6915 char call_id[128];
6916 char last_status_text[128];
6917 } buf_;
6918
6919} call_info_Object;
6920
6921
6922/*
6923 * call_info_dealloc
6924 * deletes a call_info from memory
6925 */
6926static void call_info_dealloc(call_info_Object* self)
6927{
6928 Py_XDECREF(self->local_info);
6929 Py_XDECREF(self->local_contact);
6930 Py_XDECREF(self->remote_info);
6931 Py_XDECREF(self->remote_contact);
6932 Py_XDECREF(self->call_id);
6933 Py_XDECREF(self->state_text);
6934 Py_XDECREF(self->last_status_text);
6935 Py_XDECREF(self->connect_duration);
6936 Py_XDECREF(self->total_duration);
6937 self->ob_type->tp_free((PyObject*)self);
6938}
6939
6940
6941/*
6942 * call_info_new
6943 * constructor for call_info object
6944 */
6945static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
6946 PyObject *kwds)
6947{
6948 call_info_Object *self;
6949
6950 self = (call_info_Object *)type->tp_alloc(type, 0);
6951 if (self != NULL)
6952 {
6953 self->local_info = PyString_FromString("");
6954 if (self->local_info == NULL)
6955 {
6956 Py_DECREF(self);
6957 return NULL;
6958 }
6959 self->local_contact = PyString_FromString("");
6960 if (self->local_contact == NULL)
6961 {
6962 Py_DECREF(self);
6963 return NULL;
6964 }
6965 self->remote_info = PyString_FromString("");
6966 if (self->remote_info == NULL)
6967 {
6968 Py_DECREF(self);
6969 return NULL;
6970 }
6971 self->remote_contact = PyString_FromString("");
6972 if (self->remote_contact == NULL)
6973 {
6974 Py_DECREF(self);
6975 return NULL;
6976 }
6977 self->call_id = PyString_FromString("");
6978 if (self->call_id == NULL)
6979 {
6980 Py_DECREF(self);
6981 return NULL;
6982 }
6983 self->state_text = PyString_FromString("");
6984 if (self->state_text == NULL)
6985 {
6986 Py_DECREF(self);
6987 return NULL;
6988 }
6989 self->last_status_text = PyString_FromString("");
6990 if (self->last_status_text == NULL)
6991 {
6992 Py_DECREF(self);
6993 return NULL;
6994 }
6995 self->connect_duration = (pj_time_val_Object *)PyType_GenericNew
6996 (&pj_time_val_Type,NULL,NULL);
6997 if (self->connect_duration == NULL)
6998 {
6999 Py_DECREF(self);
7000 return NULL;
7001 }
7002 self->total_duration = (pj_time_val_Object *)PyType_GenericNew
7003 (&pj_time_val_Type,NULL,NULL);
7004 if (self->total_duration == NULL)
7005 {
7006 Py_DECREF(self);
7007 return NULL;
7008 }
7009 }
7010 return (PyObject *)self;
7011}
7012
7013/*
7014 * call_info_members
7015 */
7016static PyMemberDef call_info_members[] =
7017{
7018 {
7019 "id", T_INT,
7020 offsetof(call_info_Object, id), 0,
7021 "Call identification"
7022 },
7023 {
7024 "role", T_INT,
7025 offsetof(call_info_Object, role), 0,
7026 "Initial call role (UAC == caller)"
7027 },
7028 {
7029 "acc_id", T_INT,
7030 offsetof(call_info_Object, acc_id), 0,
7031 "The account ID where this call belongs."
7032 },
7033 {
7034 "local_info", T_OBJECT_EX,
7035 offsetof(call_info_Object, local_info), 0,
7036 "Local URI"
7037 },
7038 {
7039 "local_contact", T_OBJECT_EX,
7040 offsetof(call_info_Object, local_contact), 0,
7041 "Local Contact"
7042 },
7043 {
7044 "remote_info", T_OBJECT_EX,
7045 offsetof(call_info_Object, remote_info), 0,
7046 "Remote URI"
7047 },
7048 {
7049 "remote_contact", T_OBJECT_EX,
7050 offsetof(call_info_Object, remote_contact), 0,
7051 "Remote Contact"
7052 },
7053 {
7054 "call_id", T_OBJECT_EX,
7055 offsetof(call_info_Object, call_id), 0,
7056 "Dialog Call-ID string"
7057 },
7058 {
7059 "state", T_INT,
7060 offsetof(call_info_Object, state), 0,
7061 "Call state"
7062 },
7063 {
7064 "state_text", T_OBJECT_EX,
7065 offsetof(call_info_Object, state_text), 0,
7066 "Text describing the state "
7067 },
7068 {
7069 "last_status", T_INT,
7070 offsetof(call_info_Object, last_status), 0,
7071 "Last status code heard, which can be used as cause code"
7072 },
7073 {
7074 "last_status_text", T_OBJECT_EX,
7075 offsetof(call_info_Object, last_status_text), 0,
7076 "The reason phrase describing the status."
7077 },
7078 {
7079 "media_status", T_INT,
7080 offsetof(call_info_Object, media_status), 0,
7081 "Call media status."
7082 },
7083 {
7084 "media_dir", T_INT,
7085 offsetof(call_info_Object, media_dir), 0,
7086 "Media direction"
7087 },
7088 {
7089 "conf_slot", T_INT,
7090 offsetof(call_info_Object, conf_slot), 0,
7091 "The conference port number for the call"
7092 },
7093 {
7094 "connect_duration", T_OBJECT_EX,
7095 offsetof(call_info_Object, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00007096 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00007097 },
7098 {
7099 "total_duration", T_OBJECT_EX,
7100 offsetof(call_info_Object, total_duration), 0,
7101 "Total call duration, including set-up time"
7102 },
7103
7104 {NULL} /* Sentinel */
7105};
7106
7107
7108
7109
7110/*
7111 * call_info_Type
7112 */
7113static PyTypeObject call_info_Type =
7114{
7115 PyObject_HEAD_INIT(NULL)
7116 0, /*ob_size*/
7117 "py_pjsua.Call_Info", /*tp_name*/
7118 sizeof(call_info_Object), /*tp_basicsize*/
7119 0, /*tp_itemsize*/
7120 (destructor)call_info_dealloc,/*tp_dealloc*/
7121 0, /*tp_print*/
7122 0, /*tp_getattr*/
7123 0, /*tp_setattr*/
7124 0, /*tp_compare*/
7125 0, /*tp_repr*/
7126 0, /*tp_as_number*/
7127 0, /*tp_as_sequence*/
7128 0, /*tp_as_mapping*/
7129 0, /*tp_hash */
7130 0, /*tp_call*/
7131 0, /*tp_str*/
7132 0, /*tp_getattro*/
7133 0, /*tp_setattro*/
7134 0, /*tp_as_buffer*/
7135 Py_TPFLAGS_DEFAULT, /*tp_flags*/
7136 "Call Info objects", /* tp_doc */
7137 0, /* tp_traverse */
7138 0, /* tp_clear */
7139 0, /* tp_richcompare */
7140 0, /* tp_weaklistoffset */
7141 0, /* tp_iter */
7142 0, /* tp_iternext */
7143 0, /* tp_methods */
7144 call_info_members, /* tp_members */
7145 0, /* tp_getset */
7146 0, /* tp_base */
7147 0, /* tp_dict */
7148 0, /* tp_descr_get */
7149 0, /* tp_descr_set */
7150 0, /* tp_dictoffset */
7151 0, /* tp_init */
7152 0, /* tp_alloc */
7153 call_info_new, /* tp_new */
7154
7155};
7156
7157/*
7158 * py_pjsua_call_get_max_count
7159 */
7160static PyObject *py_pjsua_call_get_max_count
7161(PyObject *pSelf, PyObject *pArgs)
7162{
7163 int count;
7164
7165 if (!PyArg_ParseTuple(pArgs, ""))
7166 {
7167 return NULL;
7168 }
7169
7170 count = pjsua_call_get_max_count();
7171
7172
7173 return Py_BuildValue("i", count);
7174}
7175
7176/*
7177 * py_pjsua_call_get_count
7178 */
7179static PyObject *py_pjsua_call_get_count
7180(PyObject *pSelf, PyObject *pArgs)
7181{
7182
7183 int count;
7184
7185
7186 if (!PyArg_ParseTuple(pArgs, ""))
7187 {
7188 return NULL;
7189 }
7190
7191 count = pjsua_call_get_count();
7192
7193
7194 return Py_BuildValue("i", count);
7195}
7196
7197/*
7198 * py_pjsua_enum_calls
7199 */
7200static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
7201{
7202 pj_status_t status;
7203 PyObject *list;
7204
7205 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00007206 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00007207 if (!PyArg_ParseTuple(pArgs, ""))
7208 {
7209 return NULL;
7210 }
7211
7212 c = PJ_ARRAY_SIZE(id);
7213 status = pjsua_enum_calls(id, &c);
7214
7215 list = PyList_New(c);
7216 for (i = 0; i < c; i++)
7217 {
7218 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
7219 if (ret == -1)
7220 {
7221 return NULL;
7222 }
7223 }
7224
Fahrisdcf8fa42006-12-28 03:13:48 +00007225 return Py_BuildValue("O",list);
7226}
7227
7228/*
7229 * py_pjsua_call_make_call
7230 */
7231static PyObject *py_pjsua_call_make_call
7232(PyObject *pSelf, PyObject *pArgs)
7233{
7234 int status;
7235 int acc_id;
7236 pj_str_t dst_uri;
7237 PyObject * sd;
7238 unsigned options;
7239 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007240 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007241 msg_data_Object * omd;
7242 int user_data;
7243 int call_id;
7244 pj_pool_t * pool;
7245
Fahris17d91812007-01-29 12:09:33 +00007246 if (!PyArg_ParseTuple
7247 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007248 {
7249 return NULL;
7250 }
7251
7252 dst_uri.ptr = PyString_AsString(sd);
7253 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00007254 if (omdObj != Py_None)
7255 {
7256 omd = (msg_data_Object *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00007257 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7258 msg_data.content_type.slen = strlen
7259 (PyString_AsString(omd->content_type));
7260 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7261 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007262 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007263 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7264 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007265 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00007266 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007267 } else {
Fahris89ea3d02007-02-07 08:18:35 +00007268
Fahris17d91812007-01-29 12:09:33 +00007269 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007270 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007271 }
Fahris89ea3d02007-02-07 08:18:35 +00007272
Fahrisdcf8fa42006-12-28 03:13:48 +00007273 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00007274
Fahrisdcf8fa42006-12-28 03:13:48 +00007275}
7276
7277/*
7278 * py_pjsua_call_is_active
7279 */
7280static PyObject *py_pjsua_call_is_active
7281(PyObject *pSelf, PyObject *pArgs)
7282{
7283 int call_id;
7284 int isActive;
7285
7286
7287 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7288 {
7289 return NULL;
7290 }
7291
7292 isActive = pjsua_call_is_active(call_id);
7293
7294
7295 return Py_BuildValue("i", isActive);
7296}
7297
7298/*
7299 * py_pjsua_call_has_media
7300 */
7301static PyObject *py_pjsua_call_has_media
7302(PyObject *pSelf, PyObject *pArgs)
7303{
7304 int call_id;
7305 int hasMedia;
7306
7307
7308 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7309 {
7310 return NULL;
7311 }
7312
7313 hasMedia = pjsua_call_has_media(call_id);
7314
7315
7316 return Py_BuildValue("i", hasMedia);
7317}
7318
7319/*
7320 * py_pjsua_call_get_conf_port
7321 */
7322static PyObject *py_pjsua_call_get_conf_port
7323(PyObject *pSelf, PyObject *pArgs)
7324{
7325 int call_id;
7326 int port_id;
7327
7328
7329 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7330 {
7331 return NULL;
7332 }
7333
7334 port_id = pjsua_call_get_conf_port(call_id);
7335
7336
7337 return Py_BuildValue("i", port_id);
7338}
7339
7340/*
7341 * py_pjsua_call_get_info
7342 */
7343static PyObject *py_pjsua_call_get_info
7344(PyObject *pSelf, PyObject *pArgs)
7345{
7346 int call_id;
7347 int status;
7348 call_info_Object * oi;
7349 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00007350
7351
7352 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7353 {
7354 return NULL;
7355 }
7356
7357
7358 status = pjsua_call_get_info(call_id, &info);
7359 if (status == PJ_SUCCESS)
7360 {
7361 oi = (call_info_Object *)call_info_new(&call_info_Type, NULL, NULL);
7362 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00007363 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
7364 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
7365 pj_ansi_snprintf(oi->buf_.last_status_text,
7366 sizeof(oi->buf_.last_status_text),
7367 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
7368 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
7369 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
7370 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
7371 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
7372 pj_ansi_snprintf(oi->buf_.remote_contact,
7373 sizeof(oi->buf_.remote_contact),
7374 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
7375 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
7376 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007377
Fahrisdcf8fa42006-12-28 03:13:48 +00007378 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
7379 info.call_id.slen);
7380 oi->conf_slot = info.conf_slot;
7381 oi->connect_duration->sec = info.connect_duration.sec;
7382 oi->connect_duration->msec = info.connect_duration.msec;
7383 oi->total_duration->sec = info.total_duration.sec;
7384 oi->total_duration->msec = info.total_duration.msec;
7385 oi->id = info.id;
7386 oi->last_status = info.last_status;
7387 oi->last_status_text = PyString_FromStringAndSize(
7388 info.last_status_text.ptr, info.last_status_text.slen);
7389 oi->local_contact = PyString_FromStringAndSize(
7390 info.local_contact.ptr, info.local_contact.slen);
7391 oi->local_info = PyString_FromStringAndSize(
7392 info.local_info.ptr, info.local_info.slen);
7393 oi->remote_contact = PyString_FromStringAndSize(
7394 info.remote_contact.ptr, info.remote_contact.slen);
7395 oi->remote_info = PyString_FromStringAndSize(
7396 info.remote_info.ptr, info.remote_info.slen);
7397 oi->media_dir = info.media_dir;
7398 oi->media_status = info.media_status;
7399 oi->role = info.role;
7400 oi->state = info.state;
7401 oi->state_text = PyString_FromStringAndSize(
7402 info.state_text.ptr, info.state_text.slen);
7403
7404 return Py_BuildValue("O", oi);
7405 } else {
7406 Py_INCREF(Py_None);
7407 return Py_None;
7408 }
7409}
7410
7411/*
7412 * py_pjsua_call_set_user_data
7413 */
7414static PyObject *py_pjsua_call_set_user_data
7415(PyObject *pSelf, PyObject *pArgs)
7416{
7417 int call_id;
7418 int user_data;
7419 int status;
7420
7421 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
7422 {
7423 return NULL;
7424 }
7425
Benny Prijonoe6ead542007-01-31 20:53:31 +00007426 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007427
7428
7429 return Py_BuildValue("i", status);
7430}
7431
7432/*
7433 * py_pjsua_call_get_user_data
7434 */
7435static PyObject *py_pjsua_call_get_user_data
7436(PyObject *pSelf, PyObject *pArgs)
7437{
7438 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00007439 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00007440
7441
7442 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7443 {
7444 return NULL;
7445 }
7446
7447 user_data = pjsua_call_get_user_data(call_id);
7448
7449
Benny Prijonoe6ead542007-01-31 20:53:31 +00007450 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007451}
7452
7453/*
7454 * py_pjsua_call_answer
7455 */
7456static PyObject *py_pjsua_call_answer
7457(PyObject *pSelf, PyObject *pArgs)
7458{
7459 int status;
7460 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007461 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007462 PyObject * sr;
7463 unsigned code;
7464 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007465 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007466 msg_data_Object * omd;
7467 pj_pool_t * pool;
7468
Fahris17d91812007-01-29 12:09:33 +00007469 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007470 {
7471 return NULL;
7472 }
Fahris6f35cb82007-02-01 07:41:26 +00007473 if (sr == Py_None)
7474 {
7475 reason = NULL;
7476 } else {
Fahrise314b882007-02-02 10:52:04 +00007477 reason = &tmp_reason;
7478 tmp_reason.ptr = PyString_AsString(sr);
7479 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007480 }
7481 if (omdObj != Py_None)
7482 {
Fahris17d91812007-01-29 12:09:33 +00007483 omd = (msg_data_Object *)omdObj;
7484 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7485 msg_data.content_type.slen = strlen
7486 (PyString_AsString(omd->content_type));
7487 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7488 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007489 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007490 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7491
Fahris6f35cb82007-02-01 07:41:26 +00007492 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007493
Fahris17d91812007-01-29 12:09:33 +00007494 pj_pool_release(pool);
7495 } else {
7496
Fahris89ea3d02007-02-07 08:18:35 +00007497 status = pjsua_call_answer(call_id, code, reason, NULL);
7498
Fahris6f35cb82007-02-01 07:41:26 +00007499 }
Fahrise314b882007-02-02 10:52:04 +00007500
Fahrisdcf8fa42006-12-28 03:13:48 +00007501 return Py_BuildValue("i",status);
7502}
7503
7504/*
7505 * py_pjsua_call_hangup
7506 */
7507static PyObject *py_pjsua_call_hangup
7508(PyObject *pSelf, PyObject *pArgs)
7509{
7510 int status;
7511 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007512 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007513 PyObject * sr;
7514 unsigned code;
7515 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007516 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007517 msg_data_Object * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007518 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00007519
Fahris17d91812007-01-29 12:09:33 +00007520 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007521 {
7522 return NULL;
7523 }
Benny Prijonoaa286042007-02-03 17:23:22 +00007524 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007525 {
7526 reason = NULL;
7527 } else {
Fahrise314b882007-02-02 10:52:04 +00007528 reason = &tmp_reason;
7529 tmp_reason.ptr = PyString_AsString(sr);
7530 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007531 }
7532 if (omdObj != Py_None)
7533 {
Fahris17d91812007-01-29 12:09:33 +00007534 omd = (msg_data_Object *)omdObj;
7535 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7536 msg_data.content_type.slen = strlen
7537 (PyString_AsString(omd->content_type));
7538 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7539 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007540 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007541 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00007542 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00007543 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007544 } else {
Fahris6f35cb82007-02-01 07:41:26 +00007545 status = pjsua_call_hangup(call_id, code, reason, NULL);
7546 }
Fahrise314b882007-02-02 10:52:04 +00007547
Fahrisdcf8fa42006-12-28 03:13:48 +00007548 return Py_BuildValue("i",status);
7549}
7550
7551/*
7552 * py_pjsua_call_set_hold
7553 */
7554static PyObject *py_pjsua_call_set_hold
7555(PyObject *pSelf, PyObject *pArgs)
7556{
7557 int status;
7558 int call_id;
7559 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007560 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007561 msg_data_Object * omd;
7562 pj_pool_t * pool;
7563
Fahris17d91812007-01-29 12:09:33 +00007564 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007565 {
7566 return NULL;
7567 }
Fahris17d91812007-01-29 12:09:33 +00007568
Fahris6f35cb82007-02-01 07:41:26 +00007569 if (omdObj != Py_None)
7570 {
Fahris17d91812007-01-29 12:09:33 +00007571 omd = (msg_data_Object *)omdObj;
7572 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7573 msg_data.content_type.slen = strlen
7574 (PyString_AsString(omd->content_type));
7575 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7576 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007577 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007578 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7579 status = pjsua_call_set_hold(call_id, &msg_data);
7580 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007581 } else {
Fahris17d91812007-01-29 12:09:33 +00007582 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007583 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007584 return Py_BuildValue("i",status);
7585}
7586
7587/*
7588 * py_pjsua_call_reinvite
7589 */
7590static PyObject *py_pjsua_call_reinvite
7591(PyObject *pSelf, PyObject *pArgs)
7592{
7593 int status;
7594 int call_id;
7595 int unhold;
7596 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007597 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007598 msg_data_Object * omd;
7599 pj_pool_t * pool;
7600
Fahris17d91812007-01-29 12:09:33 +00007601 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007602 {
7603 return NULL;
7604 }
Fahris17d91812007-01-29 12:09:33 +00007605
7606 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007607 {
Fahris17d91812007-01-29 12:09:33 +00007608 omd = (msg_data_Object *)omdObj;
7609 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7610 msg_data.content_type.slen = strlen
7611 (PyString_AsString(omd->content_type));
7612 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7613 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007614 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007615 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7616 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
7617 pj_pool_release(pool);
7618 } else {
7619 status = pjsua_call_reinvite(call_id, unhold, NULL);
7620 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007621 return Py_BuildValue("i",status);
7622}
7623
7624/*
7625 * py_pjsua_call_xfer
7626 */
7627static PyObject *py_pjsua_call_xfer
7628(PyObject *pSelf, PyObject *pArgs)
7629{
7630 int status;
7631 int call_id;
7632 pj_str_t dest;
7633 PyObject * sd;
7634 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007635 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007636 msg_data_Object * omd;
7637 pj_pool_t * pool;
7638
Fahris17d91812007-01-29 12:09:33 +00007639 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007640 {
7641 return NULL;
7642 }
7643
7644 dest.ptr = PyString_AsString(sd);
7645 dest.slen = strlen(PyString_AsString(sd));
7646
Fahris17d91812007-01-29 12:09:33 +00007647 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007648 {
Fahris17d91812007-01-29 12:09:33 +00007649 omd = (msg_data_Object *)omdObj;
7650 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7651 msg_data.content_type.slen = strlen
7652 (PyString_AsString(omd->content_type));
7653 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7654 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007655 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007656 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7657 status = pjsua_call_xfer(call_id, &dest, &msg_data);
7658 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007659 } else {
Fahris17d91812007-01-29 12:09:33 +00007660 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007661 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007662 return Py_BuildValue("i",status);
7663}
7664
7665/*
7666 * py_pjsua_call_xfer_replaces
7667 */
7668static PyObject *py_pjsua_call_xfer_replaces
7669(PyObject *pSelf, PyObject *pArgs)
7670{
7671 int status;
7672 int call_id;
7673 int dest_call_id;
7674 unsigned options;
7675 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007676 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007677 msg_data_Object * omd;
7678 pj_pool_t * pool;
7679
Fahris17d91812007-01-29 12:09:33 +00007680 if (!PyArg_ParseTuple
7681 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007682 {
7683 return NULL;
7684 }
7685
Fahris17d91812007-01-29 12:09:33 +00007686 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007687 {
Fahris17d91812007-01-29 12:09:33 +00007688 omd = (msg_data_Object *)omdObj;
7689 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7690 msg_data.content_type.slen = strlen
7691 (PyString_AsString(omd->content_type));
7692 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7693 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007694 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007695 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7696 status = pjsua_call_xfer_replaces
7697 (call_id, dest_call_id, options, &msg_data);
7698 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007699 } else {
Fahris17d91812007-01-29 12:09:33 +00007700 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007701 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007702 return Py_BuildValue("i",status);
7703}
7704
7705/*
7706 * py_pjsua_call_dial_dtmf
7707 */
7708static PyObject *py_pjsua_call_dial_dtmf
7709(PyObject *pSelf, PyObject *pArgs)
7710{
7711 int call_id;
7712 PyObject * sd;
7713 pj_str_t digits;
7714 int status;
7715
7716 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
7717 {
7718 return NULL;
7719 }
7720 digits.ptr = PyString_AsString(sd);
7721 digits.slen = strlen(PyString_AsString(sd));
7722 status = pjsua_call_dial_dtmf(call_id, &digits);
7723
7724 return Py_BuildValue("i", status);
7725}
7726
7727/*
7728 * py_pjsua_call_send_im
7729 */
7730static PyObject *py_pjsua_call_send_im
7731(PyObject *pSelf, PyObject *pArgs)
7732{
7733 int status;
7734 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00007735 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00007736 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00007737 PyObject * sm;
7738 PyObject * sc;
7739 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007740 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007741 msg_data_Object * omd;
7742 int user_data;
7743 pj_pool_t * pool;
7744
Fahris17d91812007-01-29 12:09:33 +00007745 if (!PyArg_ParseTuple
7746 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00007747 {
7748 return NULL;
7749 }
Fahris6f35cb82007-02-01 07:41:26 +00007750 if (sm == Py_None)
7751 {
7752 mime_type = NULL;
7753 } else {
Fahrise314b882007-02-02 10:52:04 +00007754 mime_type = &tmp_mime_type;
7755 tmp_mime_type.ptr = PyString_AsString(sm);
7756 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00007757 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007758 content.ptr = PyString_AsString(sc);
7759 content.slen = strlen(PyString_AsString(sc));
7760
Fahris17d91812007-01-29 12:09:33 +00007761 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007762 {
Fahris17d91812007-01-29 12:09:33 +00007763 omd = (msg_data_Object *)omdObj;
7764 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7765 msg_data.content_type.slen = strlen
7766 (PyString_AsString(omd->content_type));
7767 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7768 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007769 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007770 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7771 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007772 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00007773 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007774 } else {
Fahris17d91812007-01-29 12:09:33 +00007775 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007776 (call_id, mime_type, &content, NULL, (void *)user_data);
7777 }
Fahrise314b882007-02-02 10:52:04 +00007778
Fahrisdcf8fa42006-12-28 03:13:48 +00007779 return Py_BuildValue("i",status);
7780}
7781
7782/*
7783 * py_pjsua_call_send_typing_ind
7784 */
7785static PyObject *py_pjsua_call_send_typing_ind
7786(PyObject *pSelf, PyObject *pArgs)
7787{
7788 int status;
7789 int call_id;
7790 int is_typing;
7791 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007792 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007793 msg_data_Object * omd;
7794 pj_pool_t * pool;
7795
Fahris17d91812007-01-29 12:09:33 +00007796 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007797 {
7798 return NULL;
7799 }
7800
Fahris17d91812007-01-29 12:09:33 +00007801 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007802 {
Fahris17d91812007-01-29 12:09:33 +00007803 omd = (msg_data_Object *)omdObj;
7804 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7805 msg_data.content_type.slen = strlen
7806 (PyString_AsString(omd->content_type));
7807 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7808 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007809 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007810 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7811 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
7812 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007813 } else {
Fahris17d91812007-01-29 12:09:33 +00007814 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007815 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007816 return Py_BuildValue("i",status);
7817}
7818
7819/*
7820 * py_pjsua_call_hangup_all
7821 */
7822static PyObject *py_pjsua_call_hangup_all
7823(PyObject *pSelf, PyObject *pArgs)
7824{
7825
7826 if (!PyArg_ParseTuple(pArgs, ""))
7827 {
7828 return NULL;
7829 }
7830
7831 pjsua_call_hangup_all();
7832
7833 Py_INCREF(Py_None);
7834 return Py_None;
7835}
7836
7837/*
7838 * py_pjsua_call_dump
7839 */
7840static PyObject *py_pjsua_call_dump
7841(PyObject *pSelf, PyObject *pArgs)
7842{
7843 int call_id;
7844 int with_media;
7845 PyObject * sb;
7846 PyObject * si;
7847 char * buffer;
7848 char * indent;
7849 unsigned maxlen;
7850 int status;
7851
7852 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
7853 {
7854 return NULL;
7855 }
7856 buffer = (char *) malloc (maxlen * sizeof(char));
7857 indent = PyString_AsString(si);
7858
7859 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
7860 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00007861 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00007862 return Py_BuildValue("O", sb);
7863}
7864
7865static char pjsua_call_get_max_count_doc[] =
7866 "int py_pjsua.call_get_max_count () "
7867 "Get maximum number of calls configured in pjsua.";
7868static char pjsua_call_get_count_doc[] =
7869 "int py_pjsua.call_get_count () "
7870 "Get number of currently active calls.";
7871static char pjsua_enum_calls_doc[] =
7872 "int[] py_pjsua.enum_calls () "
7873 "Get maximum number of calls configured in pjsua.";
7874static char pjsua_call_make_call_doc[] =
7875 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
7876 "int user_data, py_pjsua.Msg_Data msg_data) "
7877 "Make outgoing call to the specified URI using the specified account.";
7878static char pjsua_call_is_active_doc[] =
7879 "int py_pjsua.call_is_active (int call_id) "
7880 "Check if the specified call has active INVITE session and the INVITE "
7881 "session has not been disconnected.";
7882static char pjsua_call_has_media_doc[] =
7883 "int py_pjsua.call_has_media (int call_id) "
7884 "Check if call has an active media session.";
7885static char pjsua_call_get_conf_port_doc[] =
7886 "int py_pjsua.call_get_conf_port (int call_id) "
7887 "Get the conference port identification associated with the call.";
7888static char pjsua_call_get_info_doc[] =
7889 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
7890 "Obtain detail information about the specified call.";
7891static char pjsua_call_set_user_data_doc[] =
7892 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
7893 "Attach application specific data to the call.";
7894static char pjsua_call_get_user_data_doc[] =
7895 "int py_pjsua.call_get_user_data (int call_id) "
7896 "Get user data attached to the call.";
7897static char pjsua_call_answer_doc[] =
7898 "int py_pjsua.call_answer (int call_id, int code, string reason, "
7899 "py_pjsua.Msg_Data msg_data) "
7900 "Send response to incoming INVITE request.";
7901static char pjsua_call_hangup_doc[] =
7902 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
7903 "py_pjsua.Msg_Data msg_data) "
7904 "Hangup call by using method that is appropriate according "
7905 "to the call state.";
7906static char pjsua_call_set_hold_doc[] =
7907 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
7908 "Put the specified call on hold.";
7909static char pjsua_call_reinvite_doc[] =
7910 "int py_pjsua.call_reinvite (int call_id, int unhold, "
7911 "py_pjsua.Msg_Data msg_data) "
7912 "Send re-INVITE (to release hold).";
7913static char pjsua_call_xfer_doc[] =
7914 "int py_pjsua.call_xfer (int call_id, string dest, "
7915 "py_pjsua.Msg_Data msg_data) "
7916 "Initiate call transfer to the specified address. "
7917 "This function will send REFER request to instruct remote call party "
7918 "to initiate a new INVITE session to the specified destination/target.";
7919static char pjsua_call_xfer_replaces_doc[] =
7920 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
7921 "int options, py_pjsua.Msg_Data msg_data) "
7922 "Initiate attended call transfer. This function will send REFER request "
7923 "to instruct remote call party to initiate new INVITE session to the URL "
7924 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
7925 "with us with the new call from the REFER recipient.";
7926static char pjsua_call_dial_dtmf_doc[] =
7927 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
7928 "Send DTMF digits to remote using RFC 2833 payload formats.";
7929static char pjsua_call_send_im_doc[] =
7930 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
7931 "py_pjsua.Msg_Data msg_data, int user_data) "
7932 "Send instant messaging inside INVITE session.";
7933static char pjsua_call_send_typing_ind_doc[] =
7934 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
7935 "py_pjsua.Msg_Data msg_data) "
7936 "Send IM typing indication inside INVITE session.";
7937static char pjsua_call_hangup_all_doc[] =
7938 "void py_pjsua.call_hangup_all () "
7939 "Terminate all calls.";
7940static char pjsua_call_dump_doc[] =
7941 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
7942 "string indent) "
7943 "Dump call and media statistics to string.";
7944
7945/* END OF LIB CALL */
7946
Benny Prijono572d4852006-11-23 21:50:02 +00007947/*
7948 * Map of function names to functions
7949 */
7950static PyMethodDef py_pjsua_methods[] =
7951{
7952 {
Benny Prijonodc308702006-12-09 00:39:42 +00007953 "thread_register", py_pjsua_thread_register, METH_VARARGS,
7954 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00007955 },
7956 {
Benny Prijono572d4852006-11-23 21:50:02 +00007957 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
7958 },
7959 {
7960 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
7961 },
7962 {
7963 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
7964 },
7965 {
7966 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
7967 },
7968 {
7969 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
7970 },
7971 {
7972 "handle_events", py_pjsua_handle_events, METH_VARARGS,
7973 pjsua_handle_events_doc
7974 },
7975 {
7976 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
7977 pjsua_verify_sip_url_doc
7978 },
7979 {
7980 "pool_create", py_pjsua_pool_create, METH_VARARGS,
7981 pjsua_pool_create_doc
7982 },
7983 {
7984 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
7985 pjsua_get_pjsip_endpt_doc
7986 },
7987 {
7988 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
7989 pjsua_get_pjmedia_endpt_doc
7990 },
7991 {
7992 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
7993 pjsua_get_pool_factory_doc
7994 },
7995 {
7996 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
7997 pjsua_reconfigure_logging_doc
7998 },
7999 {
8000 "logging_config_default", py_pjsua_logging_config_default,
8001 METH_VARARGS, pjsua_logging_config_default_doc
8002 },
8003 {
8004 "config_default", py_pjsua_config_default, METH_VARARGS,
8005 pjsua_config_default_doc
8006 },
8007 {
8008 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
8009 pjsua_media_config_default_doc
8010 },
Benny Prijonodc308702006-12-09 00:39:42 +00008011
8012
Benny Prijono572d4852006-11-23 21:50:02 +00008013 {
8014 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
8015 pjsua_msg_data_init_doc
8016 },
Benny Prijonodc308702006-12-09 00:39:42 +00008017 {
8018 "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS,
8019 pjsua_stun_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008020 },
Benny Prijonodc308702006-12-09 00:39:42 +00008021 {
8022 "transport_config_default", py_pjsua_transport_config_default,
8023 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008024 },
Benny Prijonodc308702006-12-09 00:39:42 +00008025 {
8026 "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS,
8027 pjsua_normalize_stun_config_doc
Benny Prijono98793592006-12-04 08:33:20 +00008028 },
Benny Prijonodc308702006-12-09 00:39:42 +00008029
8030 {
8031 "transport_create", py_pjsua_transport_create, METH_VARARGS,
8032 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00008033 },
Benny Prijonodc308702006-12-09 00:39:42 +00008034 {
8035 "transport_register", py_pjsua_transport_register, METH_VARARGS,
8036 pjsua_transport_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00008037 },
Benny Prijonodc308702006-12-09 00:39:42 +00008038 {
8039 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
8040 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00008041 },
Benny Prijonodc308702006-12-09 00:39:42 +00008042 {
8043 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
8044 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008045 },
Benny Prijonodc308702006-12-09 00:39:42 +00008046 {
8047 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
8048 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00008049 },
Benny Prijonodc308702006-12-09 00:39:42 +00008050 {
8051 "transport_close", py_pjsua_transport_close, METH_VARARGS,
8052 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00008053 },
Benny Prijonodc308702006-12-09 00:39:42 +00008054 {
8055 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
8056 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008057 },
Benny Prijonodc308702006-12-09 00:39:42 +00008058 {
8059 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
8060 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008061 },
Benny Prijonodc308702006-12-09 00:39:42 +00008062 {
8063 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
8064 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00008065 },
Benny Prijonodc308702006-12-09 00:39:42 +00008066 {
8067 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
8068 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008069 },
Benny Prijonodc308702006-12-09 00:39:42 +00008070 {
8071 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
8072 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008073 },
Benny Prijonodc308702006-12-09 00:39:42 +00008074 {
8075 "acc_add", py_pjsua_acc_add, METH_VARARGS,
8076 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00008077 },
Benny Prijonodc308702006-12-09 00:39:42 +00008078 {
8079 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
8080 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00008081 },
Benny Prijonodc308702006-12-09 00:39:42 +00008082 {
8083 "acc_del", py_pjsua_acc_del, METH_VARARGS,
8084 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00008085 },
Benny Prijonodc308702006-12-09 00:39:42 +00008086 {
8087 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
8088 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00008089 },
Benny Prijonodc308702006-12-09 00:39:42 +00008090 {
8091 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
8092 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00008093 },
Benny Prijonodc308702006-12-09 00:39:42 +00008094 {
8095 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
8096 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00008097 },
Benny Prijonodc308702006-12-09 00:39:42 +00008098 {
8099 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
8100 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008101 },
Benny Prijonodc308702006-12-09 00:39:42 +00008102 {
8103 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
8104 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00008105 },
Benny Prijonodc308702006-12-09 00:39:42 +00008106 {
8107 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
8108 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008109 },
Benny Prijonodc308702006-12-09 00:39:42 +00008110 {
8111 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
8112 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00008113 },
Benny Prijonodc308702006-12-09 00:39:42 +00008114 {
8115 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
8116 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00008117 },
Benny Prijonodc308702006-12-09 00:39:42 +00008118 {
8119 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
8120 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008121 },
Benny Prijonodc308702006-12-09 00:39:42 +00008122 {
8123 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
8124 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008125 },
Benny Prijonodc308702006-12-09 00:39:42 +00008126 {
Fahris6f35cb82007-02-01 07:41:26 +00008127 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
8128 pjsua_buddy_config_default_doc
8129 },
8130 {
Benny Prijonodc308702006-12-09 00:39:42 +00008131 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
8132 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008133 },
Benny Prijonodc308702006-12-09 00:39:42 +00008134 {
8135 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
8136 pjsua_buddy_is_valid_doc
8137 },
8138 {
8139 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
8140 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00008141 },
Benny Prijonodc308702006-12-09 00:39:42 +00008142 {
8143 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
8144 pjsua_buddy_get_info_doc
8145 },
8146 {
8147 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
8148 pjsua_buddy_add_doc
8149 },
8150 {
8151 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
8152 pjsua_buddy_del_doc
8153 },
8154 {
8155 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
8156 pjsua_buddy_subscribe_pres_doc
8157 },
8158 {
8159 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
8160 pjsua_pres_dump_doc
8161 },
8162 {
8163 "im_send", py_pjsua_im_send, METH_VARARGS,
8164 pjsua_im_send_doc
8165 },
8166 {
8167 "im_typing", py_pjsua_im_typing, METH_VARARGS,
8168 pjsua_im_typing_doc
8169 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008170 {
8171 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
8172 pjsua_conf_get_max_ports_doc
8173 },
8174 {
8175 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
8176 pjsua_conf_get_active_ports_doc
8177 },
8178 {
8179 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
8180 pjsua_enum_conf_ports_doc
8181 },
8182 {
8183 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
8184 pjsua_conf_get_port_info_doc
8185 },
8186 {
8187 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
8188 pjsua_conf_add_port_doc
8189 },
8190 {
8191 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
8192 pjsua_conf_remove_port_doc
8193 },
8194 {
8195 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
8196 pjsua_conf_connect_doc
8197 },
8198 {
8199 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
8200 pjsua_conf_disconnect_doc
8201 },
8202 {
8203 "player_create", py_pjsua_player_create, METH_VARARGS,
8204 pjsua_player_create_doc
8205 },
8206 {
8207 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
8208 pjsua_player_get_conf_port_doc
8209 },
8210 {
8211 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
8212 pjsua_player_set_pos_doc
8213 },
8214 {
8215 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
8216 pjsua_player_destroy_doc
8217 },
8218 {
8219 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
8220 pjsua_recorder_create_doc
8221 },
8222 {
8223 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
8224 pjsua_recorder_get_conf_port_doc
8225 },
8226 {
8227 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
8228 pjsua_recorder_destroy_doc
8229 },
8230 {
8231 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
8232 pjsua_enum_snd_devs_doc
8233 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00008234 {
Fahrisdcf8fa42006-12-28 03:13:48 +00008235 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
8236 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00008237 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008238 {
8239 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
8240 pjsua_set_snd_dev_doc
8241 },
8242 {
8243 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
8244 pjsua_set_null_snd_dev_doc
8245 },
8246 {
8247 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
8248 pjsua_set_no_snd_dev_doc
8249 },
8250 {
8251 "set_ec", py_pjsua_set_ec, METH_VARARGS,
8252 pjsua_set_ec_doc
8253 },
8254 {
8255 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
8256 pjsua_get_ec_tail_doc
8257 },
8258 {
8259 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
8260 pjsua_enum_codecs_doc
8261 },
8262 {
8263 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
8264 pjsua_codec_set_priority_doc
8265 },
8266 {
8267 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
8268 pjsua_codec_get_param_doc
8269 },
8270 {
8271 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
8272 pjsua_codec_set_param_doc
8273 },
8274 {
8275 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
8276 pjsua_call_get_max_count_doc
8277 },
8278 {
8279 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
8280 pjsua_call_get_count_doc
8281 },
8282 {
8283 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
8284 pjsua_enum_calls_doc
8285 },
8286 {
8287 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
8288 pjsua_call_make_call_doc
8289 },
8290 {
8291 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
8292 pjsua_call_is_active_doc
8293 },
8294 {
8295 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
8296 pjsua_call_has_media_doc
8297 },
8298 {
8299 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
8300 pjsua_call_get_conf_port_doc
8301 },
8302 {
8303 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
8304 pjsua_call_get_info_doc
8305 },
8306 {
8307 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
8308 pjsua_call_set_user_data_doc
8309 },
8310 {
8311 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
8312 pjsua_call_get_user_data_doc
8313 },
8314 {
8315 "call_answer", py_pjsua_call_answer, METH_VARARGS,
8316 pjsua_call_answer_doc
8317 },
8318 {
8319 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
8320 pjsua_call_hangup_doc
8321 },
8322 {
8323 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
8324 pjsua_call_set_hold_doc
8325 },
8326 {
8327 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
8328 pjsua_call_reinvite_doc
8329 },
8330 {
8331 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
8332 pjsua_call_xfer_doc
8333 },
8334 {
8335 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
8336 pjsua_call_xfer_replaces_doc
8337 },
8338 {
8339 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
8340 pjsua_call_dial_dtmf_doc
8341 },
8342 {
8343 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
8344 pjsua_call_send_im_doc
8345 },
8346 {
8347 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
8348 pjsua_call_send_typing_ind_doc
8349 },
8350 {
8351 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
8352 pjsua_call_hangup_all_doc
8353 },
8354 {
8355 "call_dump", py_pjsua_call_dump, METH_VARARGS,
8356 pjsua_call_dump_doc
8357 },
8358
8359
Benny Prijonodc308702006-12-09 00:39:42 +00008360
Benny Prijono572d4852006-11-23 21:50:02 +00008361 {NULL, NULL} /* end of function list */
8362};
8363
8364
8365
8366/*
8367 * Mapping C structs from and to Python objects & initializing object
8368 */
8369DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00008370initpy_pjsua(void)
8371{
Benny Prijono572d4852006-11-23 21:50:02 +00008372 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00008373#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00008374
Benny Prijonodc308702006-12-09 00:39:42 +00008375
Benny Prijono572d4852006-11-23 21:50:02 +00008376 if (PyType_Ready(&callback_Type) < 0)
8377 return;
8378 if (PyType_Ready(&config_Type) < 0)
8379 return;
8380 if (PyType_Ready(&logging_config_Type) < 0)
8381 return;
8382 if (PyType_Ready(&msg_data_Type) < 0)
8383 return;
8384 media_config_Type.tp_new = PyType_GenericNew;
8385 if (PyType_Ready(&media_config_Type) < 0)
8386 return;
8387 pjsip_event_Type.tp_new = PyType_GenericNew;
8388 if (PyType_Ready(&pjsip_event_Type) < 0)
8389 return;
8390 pjsip_rx_data_Type.tp_new = PyType_GenericNew;
8391 if (PyType_Ready(&pjsip_rx_data_Type) < 0)
8392 return;
8393 pj_pool_Type.tp_new = PyType_GenericNew;
8394 if (PyType_Ready(&pj_pool_Type) < 0)
8395 return;
8396 pjsip_endpoint_Type.tp_new = PyType_GenericNew;
8397 if (PyType_Ready(&pjsip_endpoint_Type) < 0)
8398 return;
8399 pjmedia_endpt_Type.tp_new = PyType_GenericNew;
8400 if (PyType_Ready(&pjmedia_endpt_Type) < 0)
8401 return;
8402 pj_pool_factory_Type.tp_new = PyType_GenericNew;
8403 if (PyType_Ready(&pj_pool_factory_Type) < 0)
8404 return;
8405 pjsip_cred_info_Type.tp_new = PyType_GenericNew;
8406 if (PyType_Ready(&pjsip_cred_info_Type) < 0)
8407 return;
8408
Benny Prijonodc308702006-12-09 00:39:42 +00008409 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008410
Benny Prijonodc308702006-12-09 00:39:42 +00008411 if (PyType_Ready(&stun_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008412 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008413 if (PyType_Ready(&transport_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008414 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008415 if (PyType_Ready(&sockaddr_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008416 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008417 if (PyType_Ready(&host_port_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008418 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008419
8420 if (PyType_Ready(&transport_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008421 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008422
8423 pjsip_transport_Type.tp_new = PyType_GenericNew;
Benny Prijono98793592006-12-04 08:33:20 +00008424 if (PyType_Ready(&pjsip_transport_Type) < 0)
8425 return;
8426
Benny Prijonodc308702006-12-09 00:39:42 +00008427 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008428
Benny Prijonodc308702006-12-09 00:39:42 +00008429 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008430
Benny Prijonodc308702006-12-09 00:39:42 +00008431
8432 if (PyType_Ready(&acc_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008433 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008434 if (PyType_Ready(&acc_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008435 return;
8436
Benny Prijonodc308702006-12-09 00:39:42 +00008437 /* END OF LIB ACCOUNT */
8438
8439 /* LIB BUDDY */
8440
8441 if (PyType_Ready(&buddy_config_Type) < 0)
8442 return;
8443 if (PyType_Ready(&buddy_info_Type) < 0)
8444 return;
8445
8446 /* END OF LIB BUDDY */
8447
Fahrisdcf8fa42006-12-28 03:13:48 +00008448 /* LIB MEDIA */
8449
8450 if (PyType_Ready(&codec_info_Type) < 0)
8451 return;
8452
8453 if (PyType_Ready(&conf_port_info_Type) < 0)
8454 return;
8455
8456 pjmedia_port_Type.tp_new = PyType_GenericNew;
8457 if (PyType_Ready(&pjmedia_port_Type) < 0)
8458 return;
8459
8460 if (PyType_Ready(&pjmedia_snd_dev_info_Type) < 0)
8461 return;
8462
8463 pjmedia_codec_param_info_Type.tp_new = PyType_GenericNew;
8464 if (PyType_Ready(&pjmedia_codec_param_info_Type) < 0)
8465 return;
8466 pjmedia_codec_param_setting_Type.tp_new = PyType_GenericNew;
8467 if (PyType_Ready(&pjmedia_codec_param_setting_Type) < 0)
8468 return;
8469
8470 if (PyType_Ready(&pjmedia_codec_param_Type) < 0)
8471 return;
8472
8473 /* END OF LIB MEDIA */
8474
8475 /* LIB CALL */
8476
8477 pj_time_val_Type.tp_new = PyType_GenericNew;
8478 if (PyType_Ready(&pj_time_val_Type) < 0)
8479 return;
8480
8481 if (PyType_Ready(&call_info_Type) < 0)
8482 return;
8483
8484 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00008485
Benny Prijono572d4852006-11-23 21:50:02 +00008486 m = Py_InitModule3(
8487 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
8488 );
8489
8490 Py_INCREF(&callback_Type);
8491 PyModule_AddObject(m, "Callback", (PyObject *)&callback_Type);
8492
8493 Py_INCREF(&config_Type);
8494 PyModule_AddObject(m, "Config", (PyObject *)&config_Type);
8495
8496 Py_INCREF(&media_config_Type);
8497 PyModule_AddObject(m, "Media_Config", (PyObject *)&media_config_Type);
8498
8499 Py_INCREF(&logging_config_Type);
8500 PyModule_AddObject(m, "Logging_Config", (PyObject *)&logging_config_Type);
8501
8502 Py_INCREF(&msg_data_Type);
8503 PyModule_AddObject(m, "Msg_Data", (PyObject *)&msg_data_Type);
8504
8505 Py_INCREF(&pjsip_event_Type);
8506 PyModule_AddObject(m, "PJSIP_Event", (PyObject *)&pjsip_event_Type);
8507
8508 Py_INCREF(&pjsip_rx_data_Type);
8509 PyModule_AddObject(m, "PJSIP_RX_Data", (PyObject *)&pjsip_rx_data_Type);
8510
8511 Py_INCREF(&pj_pool_Type);
8512 PyModule_AddObject(m, "PJ_Pool", (PyObject *)&pj_pool_Type);
8513
8514 Py_INCREF(&pjsip_endpoint_Type);
8515 PyModule_AddObject(m, "PJSIP_Endpoint", (PyObject *)&pjsip_endpoint_Type);
8516
8517 Py_INCREF(&pjmedia_endpt_Type);
8518 PyModule_AddObject(m, "PJMedia_Endpt", (PyObject *)&pjmedia_endpt_Type);
8519
8520 Py_INCREF(&pj_pool_factory_Type);
8521 PyModule_AddObject(
8522 m, "PJ_Pool_Factory", (PyObject *)&pj_pool_factory_Type
8523 );
8524
8525 Py_INCREF(&pjsip_cred_info_Type);
8526 PyModule_AddObject(m, "PJSIP_Cred_Info",
8527 (PyObject *)&pjsip_cred_info_Type
8528 );
8529
Benny Prijonodc308702006-12-09 00:39:42 +00008530 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008531
Benny Prijonodc308702006-12-09 00:39:42 +00008532 Py_INCREF(&stun_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008533 PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008534 Py_INCREF(&transport_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008535 PyModule_AddObject
Benny Prijonodc308702006-12-09 00:39:42 +00008536 (m, "Transport_Config", (PyObject *)&transport_config_Type);
8537 Py_INCREF(&sockaddr_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008538 PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008539 Py_INCREF(&host_port_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008540 PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008541
8542 Py_INCREF(&transport_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008543 PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008544
8545 Py_INCREF(&pjsip_transport_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008546 PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type);
8547
Benny Prijonodc308702006-12-09 00:39:42 +00008548 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008549
Benny Prijonodc308702006-12-09 00:39:42 +00008550 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008551
Benny Prijonodc308702006-12-09 00:39:42 +00008552
8553 Py_INCREF(&acc_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008554 PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008555 Py_INCREF(&acc_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008556 PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type);
8557
Benny Prijonodc308702006-12-09 00:39:42 +00008558 /* END OF LIB ACCOUNT */
8559
8560 /* LIB BUDDY */
8561
8562 Py_INCREF(&buddy_config_Type);
8563 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&buddy_config_Type);
8564 Py_INCREF(&buddy_info_Type);
8565 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&buddy_info_Type);
8566
8567 /* END OF LIB BUDDY */
8568
Fahrisdcf8fa42006-12-28 03:13:48 +00008569 /* LIB MEDIA */
8570
8571 Py_INCREF(&codec_info_Type);
8572 PyModule_AddObject(m, "Codec_Info", (PyObject *)&codec_info_Type);
8573 Py_INCREF(&conf_port_info_Type);
8574 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&conf_port_info_Type);
8575 Py_INCREF(&pjmedia_port_Type);
8576 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&pjmedia_port_Type);
8577 Py_INCREF(&pjmedia_snd_dev_info_Type);
8578 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
8579 (PyObject *)&pjmedia_snd_dev_info_Type);
8580 Py_INCREF(&pjmedia_codec_param_info_Type);
8581 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
8582 (PyObject *)&pjmedia_codec_param_info_Type);
8583 Py_INCREF(&pjmedia_codec_param_setting_Type);
8584 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
8585 (PyObject *)&pjmedia_codec_param_setting_Type);
8586 Py_INCREF(&pjmedia_codec_param_Type);
8587 PyModule_AddObject(m, "PJMedia_Codec_Param",
8588 (PyObject *)&pjmedia_codec_param_Type);
8589
8590 /* END OF LIB MEDIA */
8591
8592 /* LIB CALL */
8593
8594 Py_INCREF(&pj_time_val_Type);
8595 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&pj_time_val_Type);
8596
8597 Py_INCREF(&call_info_Type);
8598 PyModule_AddObject(m, "Call_Info", (PyObject *)&call_info_Type);
8599
8600 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00008601
Benny Prijonodc308702006-12-09 00:39:42 +00008602
Fahrisdcf8fa42006-12-28 03:13:48 +00008603 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00008604 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00008605 */
Benny Prijonodc308702006-12-09 00:39:42 +00008606
Benny Prijonoaa286042007-02-03 17:23:22 +00008607 /* Call states */
8608 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
8609 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
8610 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
8611 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
8612 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
8613 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
8614 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00008615
Benny Prijonoaa286042007-02-03 17:23:22 +00008616 /* Call media status (enum pjsua_call_media_status) */
8617 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
8618 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
8619 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
8620 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00008621
Benny Prijonoaa286042007-02-03 17:23:22 +00008622 /* Buddy status */
8623 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
8624 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
8625 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00008626
Benny Prijonoaa286042007-02-03 17:23:22 +00008627 /* PJSIP transport types (enum pjsip_transport_type_e) */
8628 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
8629 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
8630 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
8631 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
8632 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
8633 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
8634 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00008635
Fahrisdcf8fa42006-12-28 03:13:48 +00008636
Benny Prijonoaa286042007-02-03 17:23:22 +00008637 /* Invalid IDs */
8638 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00008639
Fahrisdcf8fa42006-12-28 03:13:48 +00008640
Benny Prijonoaa286042007-02-03 17:23:22 +00008641 /* Various compile time constants */
8642 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
8643 ADD_CONSTANT(m, PJSUA_MAX_ACC);
8644 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
8645 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
8646 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
8647 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
8648 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
8649 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
8650 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
8651 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
8652 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
8653 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
8654 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00008655
Fahrisdcf8fa42006-12-28 03:13:48 +00008656
Benny Prijonoaa286042007-02-03 17:23:22 +00008657#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00008658}