blob: cfa6adc4282570d5c3ace7cfcf3b793521817965 [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 }
2166 ret = pjsua_handle_events(msec);
Fahris89ea3d02007-02-07 08:18:35 +00002167
Benny Prijono572d4852006-11-23 21:50:02 +00002168 return Py_BuildValue("i",ret);
2169}
2170
2171
2172/*
2173 * py_pjsua_verify_sip_url
2174 */
2175static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
2176{
2177 pj_status_t status;
2178 const char *url;
2179 if (!PyArg_ParseTuple(pArgs, "s", &url))
2180 {
2181 return NULL;
2182 }
2183 status = pjsua_verify_sip_url(url);
Fahris89ea3d02007-02-07 08:18:35 +00002184
Benny Prijono572d4852006-11-23 21:50:02 +00002185 return Py_BuildValue("i",status);
2186}
2187
2188
Benny Prijono572d4852006-11-23 21:50:02 +00002189/*
Benny Prijonodc308702006-12-09 00:39:42 +00002190 * function doc
Benny Prijono572d4852006-11-23 21:50:02 +00002191 */
2192
Benny Prijonodc308702006-12-09 00:39:42 +00002193static char pjsua_thread_register_doc[] =
2194 "int py_pjsua.thread_register(string name, int[] desc)";
Benny Prijono572d4852006-11-23 21:50:02 +00002195static char pjsua_perror_doc[] =
2196 "void py_pjsua.perror (string sender, string title, int status) "
2197 "Display error message for the specified error code. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002198 "sender: The log sender field; "
2199 "title: Message title for the error; "
2200 "status: Status code.";
Benny Prijono572d4852006-11-23 21:50:02 +00002201
2202static char pjsua_create_doc[] =
2203 "int py_pjsua.create (void) "
2204 "Instantiate pjsua application. Application "
2205 "must call this function before calling any other functions, to make sure "
2206 "that the underlying libraries are properly initialized. Once this "
2207 "function has returned success, application must call pjsua_destroy() "
2208 "before quitting.";
2209
2210static char pjsua_init_doc[] =
2211 "int py_pjsua.init (py_pjsua.Config ua_cfg, "
2212 "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) "
2213 "Initialize pjsua with the specified settings. All the settings are "
2214 "optional, and the default values will be used when the config is not "
2215 "specified. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002216 "ua_cfg : User agent configuration; "
2217 "log_cfg : Optional logging configuration; "
2218 "media_cfg : Optional media configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00002219
2220static char pjsua_start_doc[] =
2221 "int py_pjsua.start (void) "
2222 "Application is recommended to call this function after all "
2223 "initialization is done, so that the library can do additional checking "
2224 "set up additional";
2225
2226static char pjsua_destroy_doc[] =
2227 "int py_pjsua.destroy (void) "
2228 "Destroy pjsua This function must be called once PJSUA is created. To "
2229 "make it easier for application, application may call this function "
2230 "several times with no danger.";
2231
2232static char pjsua_handle_events_doc[] =
2233 "int py_pjsua.handle_events (int msec_timeout) "
2234 "Poll pjsua for events, and if necessary block the caller thread for the "
2235 "specified maximum interval (in miliseconds) Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002236 "msec_timeout: Maximum time to wait, in miliseconds. "
Benny Prijono572d4852006-11-23 21:50:02 +00002237 "Returns: The number of events that have been handled during the poll. "
2238 "Negative value indicates error, and application can retrieve the error "
2239 "as (err = -return_value).";
2240
2241static char pjsua_verify_sip_url_doc[] =
2242 "int py_pjsua.verify_sip_url (string c_url) "
2243 "Verify that valid SIP url is given Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002244 "c_url: The URL, as NULL terminated string.";
Benny Prijono572d4852006-11-23 21:50:02 +00002245
2246static char pjsua_pool_create_doc[] =
2247 "py_pjsua.PJ_Pool py_pjsua.pool_create (string name, int init_size, "
2248 "int increment) "
2249 "Create memory pool Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002250 "name: Optional pool name; "
2251 "init_size: Initial size of the pool; "
2252 "increment: Increment size.";
Benny Prijono572d4852006-11-23 21:50:02 +00002253
2254static char pjsua_get_pjsip_endpt_doc[] =
2255 "py_pjsua.PJSIP_Endpoint py_pjsua.get_pjsip_endpt (void) "
2256 "Internal function to get SIP endpoint instance of pjsua, which is needed "
2257 "for example to register module, create transports, etc. Probably is only "
2258 "valid after pjsua_init() is called.";
2259
2260static char pjsua_get_pjmedia_endpt_doc[] =
2261 "py_pjsua.PJMedia_Endpt py_pjsua.get_pjmedia_endpt (void) "
2262 "Internal function to get media endpoint instance. Only valid after "
2263 "pjsua_init() is called.";
2264
2265static char pjsua_get_pool_factory_doc[] =
2266 "py_pjsua.PJ_Pool_Factory py_pjsua.get_pool_factory (void) "
2267 "Internal function to get PJSUA pool factory. Only valid after "
2268 "pjsua_init() is called.";
2269
2270static char pjsua_reconfigure_logging_doc[] =
2271 "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) "
2272 "Application can call this function at any time (after pjsua_create(), of "
2273 "course) to change logging settings. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00002274 "c: Logging configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00002275
2276static char pjsua_logging_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002277 "py_pjsua.Logging_Config py_pjsua.logging_config_default () "
Benny Prijono572d4852006-11-23 21:50:02 +00002278 "Use this function to initialize logging config.";
2279
2280static char pjsua_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002281 "py_pjsua.Config py_pjsua.config_default (). Use this function to "
2282 "initialize pjsua config. ";
Benny Prijono572d4852006-11-23 21:50:02 +00002283
2284static char pjsua_media_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002285 "py_pjsua.Media_Config py_pjsua.media_config_default (). "
Benny Prijono572d4852006-11-23 21:50:02 +00002286 "Use this function to initialize media config.";
2287
Benny Prijono572d4852006-11-23 21:50:02 +00002288static char pjsua_msg_data_init_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00002289 "py_pjsua.Msg_Data void py_pjsua.msg_data_init () "
2290 "Initialize message data ";
2291
Benny Prijono572d4852006-11-23 21:50:02 +00002292
Benny Prijono98793592006-12-04 08:33:20 +00002293/* END OF LIB BASE */
2294
2295/* LIB TRANSPORT */
2296
2297/*
2298 * stun_config_Object
2299 * STUN configuration
2300 */
2301typedef struct
2302{
2303 PyObject_HEAD
2304 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002305 PyObject * stun_srv1;
Benny Prijono98793592006-12-04 08:33:20 +00002306 unsigned stun_port1;
2307 PyObject * stun_srv2;
2308 unsigned stun_port2;
2309} stun_config_Object;
2310
2311
2312/*
2313 * stun_config_dealloc
2314 * deletes a stun config from memory
2315 */
2316static void stun_config_dealloc(stun_config_Object* self)
2317{
2318 Py_XDECREF(self->stun_srv1);
2319 Py_XDECREF(self->stun_srv2);
2320 self->ob_type->tp_free((PyObject*)self);
2321}
2322
2323
2324/*
2325 * stun_config_new
2326 * constructor for stun_config object
2327 */
2328static PyObject * stun_config_new(PyTypeObject *type, PyObject *args,
2329 PyObject *kwds)
2330{
2331 stun_config_Object *self;
2332 self = (stun_config_Object *)type->tp_alloc(type, 0);
2333 if (self != NULL)
2334 {
2335 self->stun_srv1 = PyString_FromString("");
2336 if (self->stun_srv1 == NULL)
2337 {
2338 Py_DECREF(self);
2339 return NULL;
2340 }
2341 self->stun_srv2 = PyString_FromString("");
2342 if (self->stun_srv2 == NULL)
2343 {
2344 Py_DECREF(self);
2345 return NULL;
2346 }
2347 }
2348
2349 return (PyObject *)self;
2350}
2351
2352
2353/*
2354 * stun_config_members
2355 */
2356static PyMemberDef stun_config_members[] =
2357{
2358 {
Benny Prijonodc308702006-12-09 00:39:42 +00002359 "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0,
2360 "The first STUN server IP address or hostname."
Benny Prijono98793592006-12-04 08:33:20 +00002361 },
2362 {
Benny Prijonodc308702006-12-09 00:39:42 +00002363 "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0,
2364 "Port number of the second STUN server. "
2365 "If zero, default STUN port will be used."
Benny Prijono98793592006-12-04 08:33:20 +00002366 },
2367 {
Benny Prijonodc308702006-12-09 00:39:42 +00002368 "stun_srv1", T_OBJECT_EX,
2369 offsetof(stun_config_Object, stun_srv1), 0,
2370 "The first STUN server IP address or hostname"
Benny Prijono98793592006-12-04 08:33:20 +00002371 },
2372 {
Benny Prijonodc308702006-12-09 00:39:42 +00002373 "stun_srv2", T_OBJECT_EX,
2374 offsetof(stun_config_Object, stun_srv2), 0,
2375 "Optional second STUN server IP address or hostname, for which the "
2376 "result of the mapping request will be compared to. If the value "
2377 "is empty, only one STUN server will be used"
Benny Prijono98793592006-12-04 08:33:20 +00002378 },
2379 {NULL} /* Sentinel */
2380};
2381
2382
2383
2384
2385/*
2386 * stun_config_Type
2387 */
2388static PyTypeObject stun_config_Type =
2389{
2390 PyObject_HEAD_INIT(NULL)
2391 0, /*ob_size*/
2392 "py_pjsua.STUN_Config", /*tp_name*/
2393 sizeof(stun_config_Object), /*tp_basicsize*/
2394 0, /*tp_itemsize*/
2395 (destructor)stun_config_dealloc,/*tp_dealloc*/
2396 0, /*tp_print*/
2397 0, /*tp_getattr*/
2398 0, /*tp_setattr*/
2399 0, /*tp_compare*/
2400 0, /*tp_repr*/
2401 0, /*tp_as_number*/
2402 0, /*tp_as_sequence*/
2403 0, /*tp_as_mapping*/
2404 0, /*tp_hash */
2405 0, /*tp_call*/
2406 0, /*tp_str*/
2407 0, /*tp_getattro*/
2408 0, /*tp_setattro*/
2409 0, /*tp_as_buffer*/
2410 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2411 "STUN Config objects", /* tp_doc */
2412 0, /* tp_traverse */
2413 0, /* tp_clear */
2414 0, /* tp_richcompare */
2415 0, /* tp_weaklistoffset */
2416 0, /* tp_iter */
2417 0, /* tp_iternext */
2418 0, /* tp_methods */
2419 stun_config_members, /* tp_members */
2420 0, /* tp_getset */
2421 0, /* tp_base */
2422 0, /* tp_dict */
2423 0, /* tp_descr_get */
2424 0, /* tp_descr_set */
2425 0, /* tp_dictoffset */
2426 0, /* tp_init */
2427 0, /* tp_alloc */
2428 stun_config_new, /* tp_new */
2429
2430};
2431
2432/*
2433 * transport_config_Object
2434 * Transport configuration for creating UDP transports for both SIP
2435 * and media.
2436 */
2437typedef struct
2438{
2439 PyObject_HEAD
2440 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002441 unsigned port;
2442 PyObject * public_addr;
2443 PyObject * bound_addr;
2444 int use_stun;
2445 stun_config_Object * stun_config;
Benny Prijono98793592006-12-04 08:33:20 +00002446} transport_config_Object;
2447
2448
2449/*
2450 * transport_config_dealloc
2451 * deletes a transport config from memory
2452 */
2453static void transport_config_dealloc(transport_config_Object* self)
2454{
Benny Prijonodc308702006-12-09 00:39:42 +00002455 Py_XDECREF(self->public_addr);
2456 Py_XDECREF(self->bound_addr);
Benny Prijono98793592006-12-04 08:33:20 +00002457 Py_XDECREF(self->stun_config);
2458 self->ob_type->tp_free((PyObject*)self);
2459}
2460
2461
2462/*
2463 * transport_config_new
2464 * constructor for transport_config object
2465 */
2466static PyObject * transport_config_new(PyTypeObject *type, PyObject *args,
2467 PyObject *kwds)
2468{
2469 transport_config_Object *self;
2470
2471 self = (transport_config_Object *)type->tp_alloc(type, 0);
2472 if (self != NULL)
2473 {
Fahris6f35cb82007-02-01 07:41:26 +00002474 self->public_addr = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002475 if (self->public_addr == NULL)
2476 {
2477 Py_DECREF(self);
2478 return NULL;
2479 }
2480 self->bound_addr = PyString_FromString("");
2481 if (self->bound_addr == NULL)
2482 {
2483 Py_DECREF(self);
2484 return NULL;
2485 }
2486 self->stun_config =
Benny Prijonodc308702006-12-09 00:39:42 +00002487 (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002488 if (self->stun_config == NULL)
2489 {
2490 Py_DECREF(self);
2491 return NULL;
2492 }
2493
2494 }
2495
2496 return (PyObject *)self;
2497}
2498
2499
2500/*
2501 * transport_config_members
2502 */
2503static PyMemberDef transport_config_members[] =
2504{
2505 {
Benny Prijonodc308702006-12-09 00:39:42 +00002506 "port", T_INT, offsetof(transport_config_Object, port), 0,
2507 "UDP port number to bind locally. This setting MUST be specified "
2508 "even when default port is desired. If the value is zero, the "
2509 "transport will be bound to any available port, and application "
2510 "can query the port by querying the transport info."
Benny Prijono98793592006-12-04 08:33:20 +00002511 },
2512 {
Benny Prijonodc308702006-12-09 00:39:42 +00002513 "public_addr", T_OBJECT_EX,
2514 offsetof(transport_config_Object, public_addr), 0,
2515 "Optional address to advertise as the address of this transport. "
2516 "Application can specify any address or hostname for this field, "
2517 "for example it can point to one of the interface address in the "
2518 "system, or it can point to the public address of a NAT router "
2519 "where port mappings have been configured for the application."
Benny Prijono98793592006-12-04 08:33:20 +00002520 },
2521 {
Benny Prijonodc308702006-12-09 00:39:42 +00002522 "bound_addr", T_OBJECT_EX,
2523 offsetof(transport_config_Object, bound_addr), 0,
2524 "Optional address where the socket should be bound to. This option "
2525 "SHOULD only be used to selectively bind the socket to particular "
2526 "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the "
2527 "published address of a transport (the public_addr field should be "
2528 "used for that purpose)."
2529 },
2530 {
2531 "use_stun", T_INT,
2532 offsetof(transport_config_Object, use_stun), 0,
2533 "Flag to indicate whether STUN should be used."
Benny Prijono98793592006-12-04 08:33:20 +00002534 },
2535 {
Benny Prijonodc308702006-12-09 00:39:42 +00002536 "stun_config", T_OBJECT_EX,
2537 offsetof(transport_config_Object, stun_config), 0,
2538 "STUN configuration, must be specified when STUN is used."
Benny Prijono98793592006-12-04 08:33:20 +00002539 },
2540 {NULL} /* Sentinel */
2541};
2542
2543
2544
2545
2546/*
2547 * transport_config_Type
2548 */
2549static PyTypeObject transport_config_Type =
2550{
2551 PyObject_HEAD_INIT(NULL)
2552 0, /*ob_size*/
2553 "py_pjsua.Transport_Config", /*tp_name*/
2554 sizeof(transport_config_Object), /*tp_basicsize*/
2555 0, /*tp_itemsize*/
2556 (destructor)transport_config_dealloc,/*tp_dealloc*/
2557 0, /*tp_print*/
2558 0, /*tp_getattr*/
2559 0, /*tp_setattr*/
2560 0, /*tp_compare*/
2561 0, /*tp_repr*/
2562 0, /*tp_as_number*/
2563 0, /*tp_as_sequence*/
2564 0, /*tp_as_mapping*/
2565 0, /*tp_hash */
2566 0, /*tp_call*/
2567 0, /*tp_str*/
2568 0, /*tp_getattro*/
2569 0, /*tp_setattro*/
2570 0, /*tp_as_buffer*/
2571 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2572 "Transport Config objects", /* tp_doc */
2573 0, /* tp_traverse */
2574 0, /* tp_clear */
2575 0, /* tp_richcompare */
2576 0, /* tp_weaklistoffset */
2577 0, /* tp_iter */
2578 0, /* tp_iternext */
2579 0, /* tp_methods */
2580 transport_config_members, /* tp_members */
2581 0, /* tp_getset */
2582 0, /* tp_base */
2583 0, /* tp_dict */
2584 0, /* tp_descr_get */
2585 0, /* tp_descr_set */
2586 0, /* tp_dictoffset */
2587 0, /* tp_init */
2588 0, /* tp_alloc */
2589 transport_config_new, /* tp_new */
2590
2591};
2592
2593/*
2594 * sockaddr_Object
2595 * C/Python wrapper for sockaddr object
2596 */
2597typedef struct
2598{
2599 PyObject_HEAD
2600 /* Type-specific fields go here. */
2601#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
2602 pj_uint8_t sa_zero_len;
2603 pj_uint8_t sa_family;
2604#else
2605 pj_uint16_t sa_family; /**< Common data: address family. */
2606#endif
2607 PyObject * sa_data; /**< Address data. */
2608} sockaddr_Object;
2609
2610/*
2611 * sockaddr_dealloc
2612 * deletes a sockaddr from memory
2613 */
2614static void sockaddr_dealloc(sockaddr_Object* self)
2615{
2616 Py_XDECREF(self->sa_data);
2617 self->ob_type->tp_free((PyObject*)self);
2618}
2619
2620
2621/*
2622 * sockaddr_new
2623 * constructor for sockaddr object
2624 */
2625static PyObject * sockaddr_new(PyTypeObject *type, PyObject *args,
2626 PyObject *kwds)
2627{
2628 sockaddr_Object *self;
2629
2630 self = (sockaddr_Object *)type->tp_alloc(type, 0);
2631 if (self != NULL)
2632 {
2633 self->sa_data = PyString_FromString("");
2634 if (self->sa_data == NULL)
2635 {
2636 Py_DECREF(self);
2637 return NULL;
2638 }
2639
2640 }
2641
2642 return (PyObject *)self;
2643}
2644
2645
2646/*
2647 * sockaddr_members
2648 * declares attributes accessible from both C and Python for sockaddr object
2649 */
2650static PyMemberDef sockaddr_members[] =
2651{
2652#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
2653 {
2654 "sa_zero_len", T_INT, offsetof(sockaddr_Object, sa_zero_len), 0,
2655 ""
2656 },
2657 {
2658 "sa_family", T_INT,
2659 offsetof(sockaddr_Object, sa_family), 0,
2660 "Common data: address family."
2661 },
2662#else
2663 {
2664 "sa_family", T_INT,
2665 offsetof(sockaddr_Object, sa_family), 0,
2666 "Common data: address family."
2667 },
2668#endif
2669 {
Benny Prijonodc308702006-12-09 00:39:42 +00002670 "sa_data", T_OBJECT_EX,
2671 offsetof(sockaddr_Object, sa_data), 0,
2672 "Address data"
Benny Prijono98793592006-12-04 08:33:20 +00002673 },
2674 {NULL} /* Sentinel */
2675};
2676
2677
2678/*
2679 * sockaddr_Type
2680 */
2681static PyTypeObject sockaddr_Type =
2682{
2683 PyObject_HEAD_INIT(NULL)
2684 0, /*ob_size*/
2685 "py_pjsua.Sockaddr", /*tp_name*/
2686 sizeof(sockaddr_Object), /*tp_basicsize*/
2687 0, /*tp_itemsize*/
2688 (destructor)sockaddr_dealloc,/*tp_dealloc*/
2689 0, /*tp_print*/
2690 0, /*tp_getattr*/
2691 0, /*tp_setattr*/
2692 0, /*tp_compare*/
2693 0, /*tp_repr*/
2694 0, /*tp_as_number*/
2695 0, /*tp_as_sequence*/
2696 0, /*tp_as_mapping*/
2697 0, /*tp_hash */
2698 0, /*tp_call*/
2699 0, /*tp_str*/
2700 0, /*tp_getattro*/
2701 0, /*tp_setattro*/
2702 0, /*tp_as_buffer*/
2703 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2704 "Sockaddr objects", /*tp_doc*/
2705 0, /*tp_traverse*/
2706 0, /*tp_clear*/
2707 0, /*tp_richcompare*/
2708 0, /* tp_weaklistoffset */
2709 0, /* tp_iter */
2710 0, /* tp_iternext */
2711 0, /* tp_methods */
2712 sockaddr_members, /* tp_members */
2713 0, /* tp_getset */
2714 0, /* tp_base */
2715 0, /* tp_dict */
2716 0, /* tp_descr_get */
2717 0, /* tp_descr_set */
2718 0, /* tp_dictoffset */
2719 0, /* tp_init */
2720 0, /* tp_alloc */
2721 sockaddr_new, /* tp_new */
2722};
2723
2724/*
2725 * host_port_Object
2726 * C/Python wrapper for host_port object
2727 */
2728typedef struct
2729{
2730 PyObject_HEAD
2731 /* Type-specific fields go here. */
2732 PyObject * host;
Fahris6f35cb82007-02-01 07:41:26 +00002733 int port;
Benny Prijono98793592006-12-04 08:33:20 +00002734} host_port_Object;
2735
2736/*
2737 * host_port_dealloc
2738 * deletes a host_port from memory
2739 */
2740static void host_port_dealloc(host_port_Object* self)
2741{
2742 Py_XDECREF(self->host);
2743 self->ob_type->tp_free((PyObject*)self);
2744}
2745
2746
2747/*
2748 * host_port_new
2749 * constructor for host_port object
2750 */
2751static PyObject * host_port_new(PyTypeObject *type, PyObject *args,
2752 PyObject *kwds)
2753{
2754 host_port_Object *self;
2755
2756 self = (host_port_Object *)type->tp_alloc(type, 0);
2757 if (self != NULL)
2758 {
2759 self->host = PyString_FromString("");
2760 if (self->host == NULL)
2761 {
2762 Py_DECREF(self);
2763 return NULL;
2764 }
2765
2766 }
2767
2768 return (PyObject *)self;
2769}
2770
2771
2772/*
2773 * host_port_members
2774 * declares attributes accessible from both C and Python for host_port object
2775 */
2776static PyMemberDef host_port_members[] =
2777{
2778 {
2779 "port", T_INT,
2780 offsetof(host_port_Object, port), 0,
2781 "Port number."
2782 },
2783 {
Benny Prijonodc308702006-12-09 00:39:42 +00002784 "host", T_OBJECT_EX,
2785 offsetof(host_port_Object, host), 0,
2786 "Host part or IP address."
Benny Prijono98793592006-12-04 08:33:20 +00002787 },
2788 {NULL} /* Sentinel */
2789};
2790
2791
2792/*
2793 * host_port_Type
2794 */
2795static PyTypeObject host_port_Type =
2796{
2797 PyObject_HEAD_INIT(NULL)
2798 0, /*ob_size*/
2799 "py_pjsua.Host_Port", /*tp_name*/
2800 sizeof(host_port_Object), /*tp_basicsize*/
2801 0, /*tp_itemsize*/
2802 (destructor)host_port_dealloc,/*tp_dealloc*/
2803 0, /*tp_print*/
2804 0, /*tp_getattr*/
2805 0, /*tp_setattr*/
2806 0, /*tp_compare*/
2807 0, /*tp_repr*/
2808 0, /*tp_as_number*/
2809 0, /*tp_as_sequence*/
2810 0, /*tp_as_mapping*/
2811 0, /*tp_hash */
2812 0, /*tp_call*/
2813 0, /*tp_str*/
2814 0, /*tp_getattro*/
2815 0, /*tp_setattro*/
2816 0, /*tp_as_buffer*/
2817 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2818 "Host_port objects", /*tp_doc*/
2819 0, /*tp_traverse*/
2820 0, /*tp_clear*/
2821 0, /*tp_richcompare*/
2822 0, /* tp_weaklistoffset */
2823 0, /* tp_iter */
2824 0, /* tp_iternext */
2825 0, /* tp_methods */
2826 host_port_members, /* tp_members */
2827 0, /* tp_getset */
2828 0, /* tp_base */
2829 0, /* tp_dict */
2830 0, /* tp_descr_get */
2831 0, /* tp_descr_set */
2832 0, /* tp_dictoffset */
2833 0, /* tp_init */
2834 0, /* tp_alloc */
2835 host_port_new, /* tp_new */
2836};
2837
Benny Prijono98793592006-12-04 08:33:20 +00002838
2839
Benny Prijono98793592006-12-04 08:33:20 +00002840
2841/*
2842 * transport_info_Object
2843 * Transport info
2844 */
2845typedef struct
2846{
2847 PyObject_HEAD
2848 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00002849 int id;
2850 int type;
2851 PyObject * type_name;
2852 PyObject * info;
2853 unsigned flag;
2854 unsigned addr_len;
2855 sockaddr_Object * local_addr;
2856 host_port_Object * local_name;
2857 unsigned usage_count;
Benny Prijono98793592006-12-04 08:33:20 +00002858} transport_info_Object;
2859
2860
2861/*
2862 * transport_info_dealloc
2863 * deletes a transport info from memory
2864 */
2865static void transport_info_dealloc(transport_info_Object* self)
2866{
2867 Py_XDECREF(self->type_name);
Benny Prijonodc308702006-12-09 00:39:42 +00002868 Py_XDECREF(self->info);
2869 Py_XDECREF(self->local_addr);
2870 Py_XDECREF(self->local_name);
Benny Prijono98793592006-12-04 08:33:20 +00002871 self->ob_type->tp_free((PyObject*)self);
2872}
2873
2874
2875/*
2876 * transport_info_new
2877 * constructor for transport_info object
2878 */
2879static PyObject * transport_info_new(PyTypeObject *type, PyObject *args,
2880 PyObject *kwds)
2881{
2882 transport_info_Object *self;
2883
2884 self = (transport_info_Object *)type->tp_alloc(type, 0);
2885 if (self != NULL)
2886 {
Benny Prijonodc308702006-12-09 00:39:42 +00002887 self->type_name = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002888 if (self->type_name == NULL)
2889 {
2890 Py_DECREF(self);
2891 return NULL;
2892 }
Benny Prijonodc308702006-12-09 00:39:42 +00002893 self->info = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00002894 if (self->info == NULL)
2895 {
2896 Py_DECREF(self);
2897 return NULL;
2898 }
2899 self->local_addr =
Benny Prijonodc308702006-12-09 00:39:42 +00002900 (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002901 if (self->local_addr == NULL)
2902 {
2903 Py_DECREF(self);
2904 return NULL;
2905 }
2906 self->local_name =
Benny Prijonodc308702006-12-09 00:39:42 +00002907 (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00002908 if (self->local_name == NULL)
2909 {
2910 Py_DECREF(self);
2911 return NULL;
2912 }
2913 }
2914
2915 return (PyObject *)self;
2916}
2917
2918
2919/*
2920 * transport_info_members
2921 */
2922static PyMemberDef transport_info_members[] =
2923{
Benny Prijonodc308702006-12-09 00:39:42 +00002924 {
2925 "id", T_INT, offsetof(transport_info_Object, id), 0,
2926 "PJSUA transport identification."
Benny Prijono98793592006-12-04 08:33:20 +00002927 },
Benny Prijonodc308702006-12-09 00:39:42 +00002928 {
2929 "type", T_INT, offsetof(transport_info_Object, id), 0,
2930 "Transport type."
Benny Prijono98793592006-12-04 08:33:20 +00002931 },
Benny Prijonodc308702006-12-09 00:39:42 +00002932 {
2933 "type_name", T_OBJECT_EX,
2934 offsetof(transport_info_Object, type_name), 0,
2935 "Transport type name."
Benny Prijono98793592006-12-04 08:33:20 +00002936 },
Benny Prijonodc308702006-12-09 00:39:42 +00002937 {
2938 "info", T_OBJECT_EX,
2939 offsetof(transport_info_Object, info), 0,
2940 "Transport string info/description."
Benny Prijono98793592006-12-04 08:33:20 +00002941 },
Benny Prijonodc308702006-12-09 00:39:42 +00002942 {
2943 "flag", T_INT, offsetof(transport_info_Object, flag), 0,
2944 "Transport flag (see ##pjsip_transport_flags_e)."
Benny Prijono98793592006-12-04 08:33:20 +00002945 },
Benny Prijonodc308702006-12-09 00:39:42 +00002946 {
2947 "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0,
2948 "Local address length."
Benny Prijono98793592006-12-04 08:33:20 +00002949 },
Benny Prijonodc308702006-12-09 00:39:42 +00002950 {
2951 "local_addr", T_OBJECT_EX,
2952 offsetof(transport_info_Object, local_addr), 0,
2953 "Local/bound address."
Benny Prijono98793592006-12-04 08:33:20 +00002954 },
Benny Prijonodc308702006-12-09 00:39:42 +00002955 {
2956 "local_name", T_OBJECT_EX,
2957 offsetof(transport_info_Object, local_name), 0,
2958 "Published address (or transport address name)."
Benny Prijono98793592006-12-04 08:33:20 +00002959 },
Benny Prijonodc308702006-12-09 00:39:42 +00002960 {
2961 "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0,
2962 "Current number of objects currently referencing this transport."
Benny Prijono98793592006-12-04 08:33:20 +00002963 },
2964 {NULL} /* Sentinel */
2965};
2966
2967
2968
2969
2970/*
2971 * transport_info_Type
2972 */
2973static PyTypeObject transport_info_Type =
2974{
2975 PyObject_HEAD_INIT(NULL)
2976 0, /*ob_size*/
2977 "py_pjsua.Transport_Info", /*tp_name*/
2978 sizeof(transport_info_Object), /*tp_basicsize*/
2979 0, /*tp_itemsize*/
2980 (destructor)transport_info_dealloc,/*tp_dealloc*/
2981 0, /*tp_print*/
2982 0, /*tp_getattr*/
2983 0, /*tp_setattr*/
2984 0, /*tp_compare*/
2985 0, /*tp_repr*/
2986 0, /*tp_as_number*/
2987 0, /*tp_as_sequence*/
2988 0, /*tp_as_mapping*/
2989 0, /*tp_hash */
2990 0, /*tp_call*/
2991 0, /*tp_str*/
2992 0, /*tp_getattro*/
2993 0, /*tp_setattro*/
2994 0, /*tp_as_buffer*/
2995 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2996 "Transport Info objects", /* tp_doc */
2997 0, /* tp_traverse */
2998 0, /* tp_clear */
2999 0, /* tp_richcompare */
3000 0, /* tp_weaklistoffset */
3001 0, /* tp_iter */
3002 0, /* tp_iternext */
3003 0, /* tp_methods */
3004 transport_info_members, /* tp_members */
3005 0, /* tp_getset */
3006 0, /* tp_base */
3007 0, /* tp_dict */
3008 0, /* tp_descr_get */
3009 0, /* tp_descr_set */
3010 0, /* tp_dictoffset */
3011 0, /* tp_init */
3012 0, /* tp_alloc */
3013 transport_info_new, /* tp_new */
3014
3015};
3016
3017/*
3018 * pjsip_transport_Object
3019 * C/python typewrapper for pjsip_transport
3020 */
3021typedef struct
3022{
3023 PyObject_HEAD
3024 /* Type-specific fields go here. */
3025 pjsip_transport *tp;
3026} pjsip_transport_Object;
3027
3028
3029/*
3030 * pjsip_transport_Type
3031 */
3032static PyTypeObject pjsip_transport_Type =
3033{
3034 PyObject_HEAD_INIT(NULL)
3035 0, /*ob_size*/
3036 "py_pjsua.PJSIP_Transport", /*tp_name*/
3037 sizeof(pjsip_transport_Object), /*tp_basicsize*/
3038 0, /*tp_itemsize*/
3039 0, /*tp_dealloc*/
3040 0, /*tp_print*/
3041 0, /*tp_getattr*/
3042 0, /*tp_setattr*/
3043 0, /*tp_compare*/
3044 0, /*tp_repr*/
3045 0, /*tp_as_number*/
3046 0, /*tp_as_sequence*/
3047 0, /*tp_as_mapping*/
3048 0, /*tp_hash */
3049 0, /*tp_call*/
3050 0, /*tp_str*/
3051 0, /*tp_getattro*/
3052 0, /*tp_setattro*/
3053 0, /*tp_as_buffer*/
3054 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3055 "pjsip_transport objects", /*tp_doc*/
3056};
3057
3058
3059/*
3060 * py_pjsua_stun_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003061 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003062 */
3063static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs)
3064{
3065 stun_config_Object *obj;
3066 pjsua_stun_config cfg;
3067
Benny Prijonodc308702006-12-09 00:39:42 +00003068 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003069 {
3070 return NULL;
3071 }
Benny Prijonodc308702006-12-09 00:39:42 +00003072
Benny Prijono98793592006-12-04 08:33:20 +00003073 pjsua_stun_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00003074 obj = (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003075 obj->stun_port1 = cfg.stun_port1;
Benny Prijonodc308702006-12-09 00:39:42 +00003076 obj->stun_port2 = cfg.stun_port2;
3077 Py_XDECREF(obj->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003078 obj->stun_srv1 =
Benny Prijonodc308702006-12-09 00:39:42 +00003079 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen);
3080 Py_XDECREF(obj->stun_srv2);
3081 obj->stun_srv2 =
3082 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen);
3083 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003084}
3085
3086/*
3087 * py_pjsua_transport_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003088 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003089 */
3090static PyObject *py_pjsua_transport_config_default
3091(PyObject *pSelf, PyObject *pArgs)
3092{
3093 transport_config_Object *obj;
3094 pjsua_transport_config cfg;
3095
Benny Prijonodc308702006-12-09 00:39:42 +00003096 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003097 {
3098 return NULL;
3099 }
3100 pjsua_transport_config_default(&cfg);
Fahris6f35cb82007-02-01 07:41:26 +00003101 obj = (transport_config_Object *)transport_config_new
Benny Prijonodc308702006-12-09 00:39:42 +00003102 (&transport_config_Type,NULL,NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003103 obj->public_addr =
Benny Prijonodc308702006-12-09 00:39:42 +00003104 PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen);
3105 obj->bound_addr =
3106 PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen);
3107 obj->port = cfg.port;
3108 obj->use_stun = cfg.use_stun;
3109 Py_XDECREF(obj->stun_config);
3110 obj->stun_config =
3111 (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL);
Benny Prijono98793592006-12-04 08:33:20 +00003112 obj->stun_config->stun_port1 = cfg.stun_config.stun_port1;
Benny Prijonodc308702006-12-09 00:39:42 +00003113 obj->stun_config->stun_port2 = cfg.stun_config.stun_port2;
3114 Py_XDECREF(obj->stun_config->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003115 obj->stun_config->stun_srv1 =
Benny Prijonodc308702006-12-09 00:39:42 +00003116 PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr,
3117 cfg.stun_config.stun_srv1.slen);
3118 Py_XDECREF(obj->stun_config->stun_srv2);
3119 obj->stun_config->stun_srv2 =
3120 PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr,
3121 cfg.stun_config.stun_srv2.slen);
3122 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003123}
3124
3125/*
3126 * py_pjsua_normalize_stun_config
3127 */
3128static PyObject *py_pjsua_normalize_stun_config
3129(PyObject *pSelf, PyObject *pArgs)
3130{
Fahris6f35cb82007-02-01 07:41:26 +00003131 PyObject * tmpObj;
Benny Prijono98793592006-12-04 08:33:20 +00003132 stun_config_Object *obj;
3133 pjsua_stun_config *cfg;
3134
Fahris17d91812007-01-29 12:09:33 +00003135 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003136 {
3137 return NULL;
3138 }
Fahris6f35cb82007-02-01 07:41:26 +00003139 if (tmpObj != Py_None)
3140 {
3141 obj = (stun_config_Object *) tmpObj;
Fahris17d91812007-01-29 12:09:33 +00003142 cfg = (pjsua_stun_config *)malloc(sizeof(pjsua_stun_config));
3143 cfg->stun_port1 = obj->stun_port1;
3144 cfg->stun_port2 = obj->stun_port2;
3145 cfg->stun_srv1.ptr = PyString_AsString(obj->stun_srv1);
3146 cfg->stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1));
3147 cfg->stun_srv2.ptr = PyString_AsString(obj->stun_srv2);
3148 cfg->stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2));
Fahris6f35cb82007-02-01 07:41:26 +00003149 } else {
3150 cfg = NULL;
3151 }
Benny Prijono98793592006-12-04 08:33:20 +00003152 pjsua_normalize_stun_config(cfg);
3153 obj->stun_port1 = cfg->stun_port1;
Benny Prijonodc308702006-12-09 00:39:42 +00003154 obj->stun_port2 = cfg->stun_port2;
3155 Py_XDECREF(obj->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003156 obj->stun_srv1 =
Benny Prijonodc308702006-12-09 00:39:42 +00003157 PyString_FromStringAndSize(cfg->stun_srv1.ptr, cfg->stun_srv1.slen);
3158 Py_XDECREF(obj->stun_srv2);
3159 obj->stun_srv2 =
3160 PyString_FromStringAndSize(cfg->stun_srv2.ptr, cfg->stun_srv2.slen);
Fahrise314b882007-02-02 10:52:04 +00003161 if (cfg != NULL)
3162 {
3163 free(cfg);
3164 }
Benny Prijono98793592006-12-04 08:33:20 +00003165 Py_INCREF(Py_None);
3166 return Py_None;
3167}
3168
3169/*
3170 * py_pjsua_transport_create
Benny Prijonodc308702006-12-09 00:39:42 +00003171 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003172 */
3173static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
3174{
3175 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003176 int type;
3177
Fahris6f35cb82007-02-01 07:41:26 +00003178 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003179 transport_config_Object *obj;
3180 pjsua_transport_config cfg;
3181 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003182 if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003183 {
3184 return NULL;
3185 }
Fahris6f35cb82007-02-01 07:41:26 +00003186 if (tmpObj != Py_None)
3187 {
Fahris17d91812007-01-29 12:09:33 +00003188 obj = (transport_config_Object *)tmpObj;
3189 cfg.public_addr.ptr = PyString_AsString(obj->public_addr);
3190 cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr));
3191 cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr);
3192 cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr));
3193 cfg.port = obj->port;
3194 cfg.use_stun = obj->use_stun;
3195 cfg.stun_config.stun_port1 = obj->stun_config->stun_port1;
3196 cfg.stun_config.stun_port2 = obj->stun_config->stun_port2;
3197 cfg.stun_config.stun_srv1.ptr =
3198 PyString_AsString(obj->stun_config->stun_srv1);
3199 cfg.stun_config.stun_srv1.slen =
3200 strlen(PyString_AsString(obj->stun_config->stun_srv1));
3201 cfg.stun_config.stun_srv2.ptr =
3202 PyString_AsString(obj->stun_config->stun_srv2);
3203 cfg.stun_config.stun_srv2.slen =
3204 strlen(PyString_AsString(obj->stun_config->stun_srv2));
3205 status = pjsua_transport_create(type, &cfg, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003206 } else {
Fahris17d91812007-01-29 12:09:33 +00003207 status = pjsua_transport_create(type, NULL, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003208 }
Benny Prijonodc308702006-12-09 00:39:42 +00003209
3210
3211 return Py_BuildValue("ii",status,id);
Benny Prijono98793592006-12-04 08:33:20 +00003212}
3213
3214/*
3215 * py_pjsua_transport_register
Benny Prijonodc308702006-12-09 00:39:42 +00003216 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003217 */
3218static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs)
3219{
Benny Prijonodc308702006-12-09 00:39:42 +00003220 pj_status_t status;
Fahris6f35cb82007-02-01 07:41:26 +00003221 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003222 pjsip_transport_Object *obj;
3223 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003224 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003225 {
3226 return NULL;
3227 }
Fahris17d91812007-01-29 12:09:33 +00003228 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003229 {
Fahris17d91812007-01-29 12:09:33 +00003230 obj = (pjsip_transport_Object *)tmpObj;
3231 status = pjsua_transport_register(obj->tp, &id);
3232 } else {
3233 status = pjsua_transport_register(NULL, &id);
3234 }
Benny Prijonodc308702006-12-09 00:39:42 +00003235
3236 return Py_BuildValue("ii",status, id);
Benny Prijono98793592006-12-04 08:33:20 +00003237}
3238
3239/*
3240 * py_pjsua_enum_transports
Fahrisdcf8fa42006-12-28 03:13:48 +00003241 * !modified @ 261206
Benny Prijono98793592006-12-04 08:33:20 +00003242 */
3243static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
3244{
3245 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003246 PyObject *list;
3247
Fahrisdcf8fa42006-12-28 03:13:48 +00003248 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
Fahris17d91812007-01-29 12:09:33 +00003249 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00003250 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003251 {
3252 return NULL;
3253 }
Benny Prijonodc308702006-12-09 00:39:42 +00003254
Fahrisdcf8fa42006-12-28 03:13:48 +00003255 c = PJ_ARRAY_SIZE(id);
Benny Prijono98793592006-12-04 08:33:20 +00003256 status = pjsua_enum_transports(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00003257
3258 list = PyList_New(c);
3259 for (i = 0; i < c; i++)
3260 {
3261 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
3262 if (ret == -1)
3263 {
3264 return NULL;
3265 }
3266 }
3267
Benny Prijonodc308702006-12-09 00:39:42 +00003268 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00003269}
3270
3271/*
3272 * py_pjsua_transport_get_info
Benny Prijonodc308702006-12-09 00:39:42 +00003273 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003274 */
3275static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
3276{
3277 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003278 int id;
3279 transport_info_Object *obj;
3280 pjsua_transport_info info;
3281
Benny Prijono98793592006-12-04 08:33:20 +00003282
Benny Prijonodc308702006-12-09 00:39:42 +00003283 if (!PyArg_ParseTuple(pArgs, "i", &id))
Benny Prijono98793592006-12-04 08:33:20 +00003284 {
3285 return NULL;
3286 }
Benny Prijonodc308702006-12-09 00:39:42 +00003287
Benny Prijono98793592006-12-04 08:33:20 +00003288 status = pjsua_transport_get_info(id, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00003289 if (status == PJ_SUCCESS) {
3290 obj = (transport_info_Object *) transport_info_new
3291 (&transport_info_Type,NULL,NULL);
3292 obj->addr_len = info.addr_len;
3293 obj->flag = info.flag;
3294 obj->id = info.id;
3295 obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen);
3296 obj->local_addr->sa_data =
3297 PyString_FromStringAndSize(info.local_addr.sa_data, 14);
Benny Prijono98793592006-12-04 08:33:20 +00003298#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
Benny Prijonodc308702006-12-09 00:39:42 +00003299 obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len;
3300 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003301#else
Benny Prijonodc308702006-12-09 00:39:42 +00003302 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003303#endif
Benny Prijonodc308702006-12-09 00:39:42 +00003304 return Py_BuildValue("O", obj);
3305 } else {
3306 Py_INCREF(Py_None);
3307 return Py_None;
3308 }
Benny Prijono98793592006-12-04 08:33:20 +00003309}
3310
3311/*
3312 * py_pjsua_transport_set_enable
3313 */
3314static PyObject *py_pjsua_transport_set_enable
3315(PyObject *pSelf, PyObject *pArgs)
3316{
3317 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003318 int id;
3319 int enabled;
Benny Prijono98793592006-12-04 08:33:20 +00003320 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled))
3321 {
3322 return NULL;
3323 }
3324 status = pjsua_transport_set_enable(id, enabled);
Fahris89ea3d02007-02-07 08:18:35 +00003325
Benny Prijono98793592006-12-04 08:33:20 +00003326 return Py_BuildValue("i",status);
3327}
3328
3329/*
3330 * py_pjsua_transport_close
3331 */
3332static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
3333{
3334 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003335 int id;
3336 int force;
Benny Prijono98793592006-12-04 08:33:20 +00003337 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force))
3338 {
3339 return NULL;
3340 }
3341 status = pjsua_transport_close(id, force);
Fahris89ea3d02007-02-07 08:18:35 +00003342
Benny Prijono98793592006-12-04 08:33:20 +00003343 return Py_BuildValue("i",status);
3344}
3345
3346static char pjsua_stun_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003347 "py_pjsua.STUN_Config py_pjsua.stun_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00003348 "Call this function to initialize STUN config with default values.";
3349static char pjsua_transport_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003350 "py_pjsua.Transport_Config py_pjsua.transport_config_default () "
3351 "Call this function to initialize UDP config with default values.";
Benny Prijono98793592006-12-04 08:33:20 +00003352static char pjsua_normalize_stun_config_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003353 "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) "
3354 "Normalize STUN config. ";
Benny Prijono98793592006-12-04 08:33:20 +00003355static char pjsua_transport_create_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003356 "int, int py_pjsua.transport_create (int type, "
3357 "py_pjsua.Transport_Config cfg) "
3358 "Create SIP transport.";
Benny Prijono98793592006-12-04 08:33:20 +00003359static char pjsua_transport_register_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003360 "int, int py_pjsua.transport_register "
3361 "(py_pjsua.PJSIP_Transport tp) "
3362 "Register transport that has been created by application.";
Benny Prijono98793592006-12-04 08:33:20 +00003363static char pjsua_enum_transports_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00003364 "int[] py_pjsua.enum_transports () "
Benny Prijonodc308702006-12-09 00:39:42 +00003365 "Enumerate all transports currently created in the system.";
Benny Prijono98793592006-12-04 08:33:20 +00003366static char pjsua_transport_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003367 "void py_pjsua.transport_get_info "
3368 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) "
3369 "Get information about transports.";
Benny Prijono98793592006-12-04 08:33:20 +00003370static char pjsua_transport_set_enable_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003371 "void py_pjsua.transport_set_enable "
3372 "(py_pjsua.Transport_ID id, int enabled) "
3373 "Disable a transport or re-enable it. "
3374 "By default transport is always enabled after it is created. "
3375 "Disabling a transport does not necessarily close the socket, "
3376 "it will only discard incoming messages and prevent the transport "
3377 "from being used to send outgoing messages.";
Benny Prijono98793592006-12-04 08:33:20 +00003378static char pjsua_transport_close_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003379 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) "
3380 "Close the transport. If transport is forcefully closed, "
3381 "it will be immediately closed, and any pending transactions "
3382 "that are using the transport may not terminate properly. "
3383 "Otherwise, the system will wait until all transactions are closed "
3384 "while preventing new users from using the transport, and will close "
3385 "the transport when it is safe to do so.";
Benny Prijono98793592006-12-04 08:33:20 +00003386
3387/* END OF LIB TRANSPORT */
3388
3389/* LIB ACCOUNT */
3390
3391/*
3392 * acc_config_Object
3393 * Acc Config
3394 */
3395typedef struct
3396{
3397 PyObject_HEAD
3398 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003399 int priority;
3400 PyObject * id;
3401 PyObject * reg_uri;
3402 int publish_enabled;
3403 PyObject * force_contact;
3404 unsigned proxy_cnt;
3405 /*pj_str_t proxy[8];*/
3406 PyListObject * proxy;
3407 unsigned reg_timeout;
3408 unsigned cred_count;
3409 /*pjsip_cred_info cred_info[8];*/
3410 PyListObject * cred_info;
Benny Prijono98793592006-12-04 08:33:20 +00003411} acc_config_Object;
3412
3413
3414/*
3415 * acc_config_dealloc
3416 * deletes a acc_config from memory
3417 */
3418static void acc_config_dealloc(acc_config_Object* self)
3419{
3420 Py_XDECREF(self->id);
Benny Prijonodc308702006-12-09 00:39:42 +00003421 Py_XDECREF(self->reg_uri);
3422 Py_XDECREF(self->force_contact);
3423 Py_XDECREF(self->proxy);
3424 Py_XDECREF(self->cred_info);
Benny Prijono98793592006-12-04 08:33:20 +00003425 self->ob_type->tp_free((PyObject*)self);
3426}
3427
3428
3429/*
3430 * acc_config_new
3431 * constructor for acc_config object
3432 */
3433static PyObject * acc_config_new(PyTypeObject *type, PyObject *args,
3434 PyObject *kwds)
3435{
3436 acc_config_Object *self;
3437
3438 self = (acc_config_Object *)type->tp_alloc(type, 0);
3439 if (self != NULL)
3440 {
Benny Prijonodc308702006-12-09 00:39:42 +00003441 self->id = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003442 if (self->id == NULL)
3443 {
3444 Py_DECREF(self);
3445 return NULL;
3446 }
Benny Prijonodc308702006-12-09 00:39:42 +00003447 self->reg_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003448 if (self->reg_uri == NULL)
3449 {
3450 Py_DECREF(self);
3451 return NULL;
3452 }
3453 self->force_contact = PyString_FromString("");
3454 if (self->force_contact == NULL)
3455 {
3456 Py_DECREF(self);
3457 return NULL;
3458 }
Benny Prijonodc308702006-12-09 00:39:42 +00003459 self->proxy = (PyListObject *)PyList_New(8);
3460 if (self->proxy == NULL)
3461 {
3462 Py_DECREF(self);
3463 return NULL;
3464 }
3465 self->cred_info = (PyListObject *)PyList_New(8);
3466 if (self->cred_info == NULL)
3467 {
3468 Py_DECREF(self);
3469 return NULL;
3470 }
Benny Prijono98793592006-12-04 08:33:20 +00003471 }
3472
3473 return (PyObject *)self;
3474}
3475
Benny Prijono98793592006-12-04 08:33:20 +00003476
3477
3478/*
3479 * acc_config_members
3480 */
3481static PyMemberDef acc_config_members[] =
3482{
Benny Prijonodc308702006-12-09 00:39:42 +00003483 {
3484 "priority", T_INT, offsetof(acc_config_Object, priority), 0,
3485 "Account priority, which is used to control the order of matching "
3486 "incoming/outgoing requests. The higher the number means the higher "
3487 "the priority is, and the account will be matched first. "
Benny Prijono98793592006-12-04 08:33:20 +00003488 },
Benny Prijonodc308702006-12-09 00:39:42 +00003489 {
3490 "id", T_OBJECT_EX,
3491 offsetof(acc_config_Object, id), 0,
3492 "The full SIP URL for the account. "
3493 "The value can take name address or URL format, "
3494 "and will look something like 'sip:account@serviceprovider'. "
3495 "This field is mandatory."
Benny Prijono98793592006-12-04 08:33:20 +00003496 },
Benny Prijonodc308702006-12-09 00:39:42 +00003497 {
3498 "reg_uri", T_OBJECT_EX,
3499 offsetof(acc_config_Object, reg_uri), 0,
3500 "This is the URL to be put in the request URI for the registration, "
3501 "and will look something like 'sip:serviceprovider'. "
3502 "This field should be specified if registration is desired. "
3503 "If the value is empty, no account registration will be performed. "
Benny Prijono98793592006-12-04 08:33:20 +00003504 },
Benny Prijonodc308702006-12-09 00:39:42 +00003505 {
3506 "publish_enabled", T_INT,
3507 offsetof(acc_config_Object, publish_enabled), 0,
3508 "Publish presence? "
Benny Prijono98793592006-12-04 08:33:20 +00003509 },
Benny Prijonodc308702006-12-09 00:39:42 +00003510 {
3511 "force_contact", T_OBJECT_EX,
3512 offsetof(acc_config_Object, force_contact), 0,
3513 "Optional URI to be put as Contact for this account. "
3514 "It is recommended that this field is left empty, "
3515 "so that the value will be calculated automatically "
3516 "based on the transport address. "
Benny Prijono98793592006-12-04 08:33:20 +00003517 },
Benny Prijonodc308702006-12-09 00:39:42 +00003518 {
3519 "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0,
3520 "Number of proxies in the proxy array below. "
Benny Prijono98793592006-12-04 08:33:20 +00003521 },
Benny Prijonodc308702006-12-09 00:39:42 +00003522 {
3523 "proxy", T_OBJECT_EX,
3524 offsetof(acc_config_Object, proxy), 0,
3525 "Optional URI of the proxies to be visited for all outgoing requests "
3526 "that are using this account (REGISTER, INVITE, etc). Application need "
3527 "to specify these proxies if the service provider requires "
3528 "that requests destined towards its network should go through certain "
3529 "proxies first (for example, border controllers)."
Benny Prijono98793592006-12-04 08:33:20 +00003530 },
Benny Prijonodc308702006-12-09 00:39:42 +00003531 {
3532 "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0,
3533 "Optional interval for registration, in seconds. "
3534 "If the value is zero, default interval will be used "
3535 "(PJSUA_REG_INTERVAL, 55 seconds). "
3536 },
3537 {
3538 "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0,
3539 "Number of credentials in the credential array. "
3540 },
3541 {
3542 "cred_info", T_OBJECT_EX,
3543 offsetof(acc_config_Object, cred_info), 0,
3544 "Array of credentials. If registration is desired, normally there "
3545 "should be at least one credential specified, to successfully "
3546 "authenticate against the service provider. More credentials can "
3547 "be specified, for example when the requests are expected to be "
3548 "challenged by the proxies in the route set."
Benny Prijono98793592006-12-04 08:33:20 +00003549 },
3550 {NULL} /* Sentinel */
3551};
3552
3553
3554
3555
3556/*
3557 * acc_config_Type
3558 */
3559static PyTypeObject acc_config_Type =
3560{
3561 PyObject_HEAD_INIT(NULL)
3562 0, /*ob_size*/
3563 "py_pjsua.Acc_Config", /*tp_name*/
3564 sizeof(acc_config_Object), /*tp_basicsize*/
3565 0, /*tp_itemsize*/
3566 (destructor)acc_config_dealloc,/*tp_dealloc*/
3567 0, /*tp_print*/
3568 0, /*tp_getattr*/
3569 0, /*tp_setattr*/
3570 0, /*tp_compare*/
3571 0, /*tp_repr*/
3572 0, /*tp_as_number*/
3573 0, /*tp_as_sequence*/
3574 0, /*tp_as_mapping*/
3575 0, /*tp_hash */
3576 0, /*tp_call*/
3577 0, /*tp_str*/
3578 0, /*tp_getattro*/
3579 0, /*tp_setattro*/
3580 0, /*tp_as_buffer*/
3581 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3582 "Acc Config objects", /* tp_doc */
3583 0, /* tp_traverse */
3584 0, /* tp_clear */
3585 0, /* tp_richcompare */
3586 0, /* tp_weaklistoffset */
3587 0, /* tp_iter */
3588 0, /* tp_iternext */
Benny Prijonodc308702006-12-09 00:39:42 +00003589 0/*acc_config_methods*/, /* tp_methods */
Benny Prijono98793592006-12-04 08:33:20 +00003590 acc_config_members, /* tp_members */
3591 0, /* tp_getset */
3592 0, /* tp_base */
3593 0, /* tp_dict */
3594 0, /* tp_descr_get */
3595 0, /* tp_descr_set */
3596 0, /* tp_dictoffset */
3597 0, /* tp_init */
3598 0, /* tp_alloc */
3599 acc_config_new, /* tp_new */
3600
3601};
3602
3603/*
3604 * acc_info_Object
3605 * Acc Info
3606 */
3607typedef struct
3608{
3609 PyObject_HEAD
3610 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003611 int id;
3612 int is_default;
3613 PyObject * acc_uri;
3614 int has_registration;
3615 int expires;
3616 int status;
3617 PyObject * status_text;
3618 int online_status;
3619 char buf_[PJ_ERR_MSG_SIZE];
Benny Prijono98793592006-12-04 08:33:20 +00003620} acc_info_Object;
3621
3622
3623/*
3624 * acc_info_dealloc
3625 * deletes a acc_info from memory
3626 */
3627static void acc_info_dealloc(acc_info_Object* self)
3628{
3629 Py_XDECREF(self->acc_uri);
Benny Prijonodc308702006-12-09 00:39:42 +00003630 Py_XDECREF(self->status_text);
Benny Prijono98793592006-12-04 08:33:20 +00003631 self->ob_type->tp_free((PyObject*)self);
3632}
3633
3634
3635/*
3636 * acc_info_new
3637 * constructor for acc_info object
3638 */
3639static PyObject * acc_info_new(PyTypeObject *type, PyObject *args,
3640 PyObject *kwds)
3641{
3642 acc_info_Object *self;
3643
3644 self = (acc_info_Object *)type->tp_alloc(type, 0);
3645 if (self != NULL)
3646 {
Benny Prijonodc308702006-12-09 00:39:42 +00003647 self->acc_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003648 if (self->acc_uri == NULL)
3649 {
3650 Py_DECREF(self);
3651 return NULL;
3652 }
3653 self->status_text = PyString_FromString("");
3654 if (self->status_text == NULL)
3655 {
3656 Py_DECREF(self);
3657 return NULL;
3658 }
3659
3660 }
3661
3662 return (PyObject *)self;
3663}
3664
3665static PyObject * acc_info_get_buf
3666(acc_info_Object *self, PyObject * args)
3667{
Benny Prijonodc308702006-12-09 00:39:42 +00003668 int idx;
3669 char elmt;
3670 if (!PyArg_ParseTuple(args,"i",&idx))
3671 {
3672 return NULL;
3673 }
3674 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3675 {
3676 elmt = self->buf_[idx];
3677 }
3678 else
3679 {
3680 return NULL;
3681 }
3682 return PyString_FromStringAndSize(&elmt, 1);
Benny Prijono98793592006-12-04 08:33:20 +00003683}
3684
3685static PyObject * acc_info_set_buf
3686(acc_info_Object *self, PyObject * args)
3687{
Benny Prijonodc308702006-12-09 00:39:42 +00003688 int idx;
3689 PyObject * str;
3690 char * s;
3691 if (!PyArg_ParseTuple(args,"iO",&idx, &str))
3692 {
3693 return NULL;
3694 }
3695 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3696 {
3697 s = PyString_AsString(str);
3698 if (s[0])
3699 {
Fahris6f35cb82007-02-01 07:41:26 +00003700 self->buf_[idx] = s[0];
Benny Prijonodc308702006-12-09 00:39:42 +00003701 }
3702 else
3703 {
3704 return NULL;
3705 }
3706 }
3707 else
3708 {
3709 return NULL;
3710 }
3711 Py_INCREF(Py_None);
3712 return Py_None;
Benny Prijono98793592006-12-04 08:33:20 +00003713}
3714
3715static PyMethodDef acc_info_methods[] = {
3716 {
Benny Prijonodc308702006-12-09 00:39:42 +00003717 "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS,
3718 "Return buf char at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003719 },
Benny Prijonodc308702006-12-09 00:39:42 +00003720 {
3721 "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS,
3722 "Set buf at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003723 },
3724
3725 {NULL} /* Sentinel */
3726};
3727
3728
3729
3730/*
3731 * acc_info_members
3732 */
3733static PyMemberDef acc_info_members[] =
3734{
Benny Prijonodc308702006-12-09 00:39:42 +00003735 {
3736 "id", T_INT, offsetof(acc_info_Object, id), 0,
3737 "The account ID."
Benny Prijono98793592006-12-04 08:33:20 +00003738 },
Benny Prijonodc308702006-12-09 00:39:42 +00003739 {
3740 "is_default", T_INT, offsetof(acc_info_Object, is_default), 0,
3741 "Flag to indicate whether this is the default account. "
Benny Prijono98793592006-12-04 08:33:20 +00003742 },
Benny Prijonodc308702006-12-09 00:39:42 +00003743 {
3744 "acc_uri", T_OBJECT_EX,
3745 offsetof(acc_info_Object, acc_uri), 0,
3746 "Account URI"
Benny Prijono98793592006-12-04 08:33:20 +00003747 },
Benny Prijonodc308702006-12-09 00:39:42 +00003748 {
3749 "has_registration", T_INT, offsetof(acc_info_Object, has_registration),
3750 0,
3751 "Flag to tell whether this account has registration setting "
3752 "(reg_uri is not empty)."
Benny Prijono98793592006-12-04 08:33:20 +00003753 },
Benny Prijonodc308702006-12-09 00:39:42 +00003754 {
3755 "expires", T_INT, offsetof(acc_info_Object, expires), 0,
3756 "An up to date expiration interval for account registration session."
Benny Prijono98793592006-12-04 08:33:20 +00003757 },
Benny Prijonodc308702006-12-09 00:39:42 +00003758 {
3759 "status", T_INT, offsetof(acc_info_Object, status), 0,
3760 "Last registration status code. If status code is zero, "
3761 "the account is currently not registered. Any other value indicates "
3762 "the SIP status code of the registration. "
Benny Prijono98793592006-12-04 08:33:20 +00003763 },
Benny Prijonodc308702006-12-09 00:39:42 +00003764 {
3765 "status_text", T_OBJECT_EX,
3766 offsetof(acc_info_Object, status_text), 0,
3767 "String describing the registration status."
Benny Prijono98793592006-12-04 08:33:20 +00003768 },
Benny Prijonodc308702006-12-09 00:39:42 +00003769 {
3770 "online_status", T_INT, offsetof(acc_info_Object, online_status), 0,
3771 "Presence online status for this account. "
Benny Prijono98793592006-12-04 08:33:20 +00003772 },
3773 {NULL} /* Sentinel */
3774};
3775
3776
3777
3778
3779/*
3780 * acc_info_Type
3781 */
3782static PyTypeObject acc_info_Type =
3783{
3784 PyObject_HEAD_INIT(NULL)
3785 0, /*ob_size*/
3786 "py_pjsua.Acc_Info", /*tp_name*/
3787 sizeof(acc_info_Object), /*tp_basicsize*/
3788 0, /*tp_itemsize*/
3789 (destructor)acc_info_dealloc,/*tp_dealloc*/
3790 0, /*tp_print*/
3791 0, /*tp_getattr*/
3792 0, /*tp_setattr*/
3793 0, /*tp_compare*/
3794 0, /*tp_repr*/
3795 0, /*tp_as_number*/
3796 0, /*tp_as_sequence*/
3797 0, /*tp_as_mapping*/
3798 0, /*tp_hash */
3799 0, /*tp_call*/
3800 0, /*tp_str*/
3801 0, /*tp_getattro*/
3802 0, /*tp_setattro*/
3803 0, /*tp_as_buffer*/
3804 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3805 "Acc Info objects", /* tp_doc */
3806 0, /* tp_traverse */
3807 0, /* tp_clear */
3808 0, /* tp_richcompare */
3809 0, /* tp_weaklistoffset */
3810 0, /* tp_iter */
3811 0, /* tp_iternext */
3812 acc_info_methods, /* tp_methods */
3813 acc_info_members, /* tp_members */
3814 0, /* tp_getset */
3815 0, /* tp_base */
3816 0, /* tp_dict */
3817 0, /* tp_descr_get */
3818 0, /* tp_descr_set */
3819 0, /* tp_dictoffset */
3820 0, /* tp_init */
3821 0, /* tp_alloc */
3822 acc_info_new, /* tp_new */
3823
3824};
3825
Benny Prijono98793592006-12-04 08:33:20 +00003826
3827
3828/*
Benny Prijono98793592006-12-04 08:33:20 +00003829 * py_pjsua_acc_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003830 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003831 */
3832static PyObject *py_pjsua_acc_config_default
3833(PyObject *pSelf, PyObject *pArgs)
3834{
3835 acc_config_Object *obj;
3836 pjsua_acc_config cfg;
Benny Prijonodc308702006-12-09 00:39:42 +00003837 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003838
Benny Prijonodc308702006-12-09 00:39:42 +00003839 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003840 {
3841 return NULL;
3842 }
3843 pjsua_acc_config_default(&cfg);
Benny Prijonodc308702006-12-09 00:39:42 +00003844 obj = (acc_config_Object *)acc_config_new(&acc_config_Type, NULL, NULL);
3845 obj->cred_count = cfg.cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003846 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003847 {
3848 /*obj->cred_info[i] = cfg.cred_info[i];*/
3849 int ret;
3850 pjsip_cred_info_Object * ci =
3851 (pjsip_cred_info_Object *)pjsip_cred_info_new
3852 (&pjsip_cred_info_Type,NULL,NULL);
3853 ci->data = PyString_FromStringAndSize(cfg.cred_info[i].data.ptr,
3854 cfg.cred_info[i].data.slen);
3855 ci->realm = PyString_FromStringAndSize(cfg.cred_info[i].realm.ptr,
3856 cfg.cred_info[i].realm.slen);
3857 ci->scheme = PyString_FromStringAndSize(cfg.cred_info[i].scheme.ptr,
3858 cfg.cred_info[i].scheme.slen);
3859 ci->username = PyString_FromStringAndSize(cfg.cred_info[i].username.ptr,
3860 cfg.cred_info[i].username.slen);
3861 ci->data_type = cfg.cred_info[i].data_type;
3862 ret = PyList_SetItem((PyObject *)obj->cred_info,i,(PyObject *)ci);
3863 if (ret == -1) {
3864 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003865 }
Benny Prijonodc308702006-12-09 00:39:42 +00003866 }
3867
3868 Py_XDECREF(obj->force_contact);
3869 obj->force_contact =
3870 PyString_FromStringAndSize(cfg.force_contact.ptr,
3871 cfg.force_contact.slen);
3872 obj->priority = cfg.priority;
3873 Py_XDECREF(obj->id);
3874 obj->id =
3875 PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen);
3876 Py_XDECREF(obj->reg_uri);
3877 obj->reg_uri =
3878 PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen);
3879 obj->proxy_cnt = cfg.proxy_cnt;
Fahris6f35cb82007-02-01 07:41:26 +00003880 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003881 {
3882 PyObject * str;
3883 int ret;
3884 /*obj->proxy[i] = cfg.proxy[i];*/
3885 str = PyString_FromStringAndSize(cfg.proxy[i].ptr, cfg.proxy[i].slen);
3886 ret = PyList_SetItem((PyObject *)obj->proxy,i,str);
3887 if (ret == -1) {
3888 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003889 }
Benny Prijonodc308702006-12-09 00:39:42 +00003890 }
3891 obj->publish_enabled = cfg.publish_enabled;
3892 obj->reg_timeout = cfg.reg_timeout;
Benny Prijono98793592006-12-04 08:33:20 +00003893
Benny Prijonodc308702006-12-09 00:39:42 +00003894 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003895}
3896
3897/*
3898 * py_pjsua_acc_get_count
3899 */
3900static PyObject *py_pjsua_acc_get_count
3901(PyObject *pSelf, PyObject *pArgs)
3902{
Benny Prijonodc308702006-12-09 00:39:42 +00003903 int count;
Benny Prijono98793592006-12-04 08:33:20 +00003904 if (!PyArg_ParseTuple(pArgs, ""))
3905 {
3906 return NULL;
3907 }
3908 count = pjsua_acc_get_count();
3909 return Py_BuildValue("i",count);
3910}
3911
3912/*
3913 * py_pjsua_acc_is_valid
3914 */
3915static PyObject *py_pjsua_acc_is_valid
3916(PyObject *pSelf, PyObject *pArgs)
3917{
Benny Prijonodc308702006-12-09 00:39:42 +00003918 int id;
3919 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00003920
3921 if (!PyArg_ParseTuple(pArgs, "i", &id))
3922 {
3923 return NULL;
3924 }
3925 is_valid = pjsua_acc_is_valid(id);
3926
3927 return Py_BuildValue("i", is_valid);
3928}
3929
3930/*
3931 * py_pjsua_acc_set_default
3932 */
3933static PyObject *py_pjsua_acc_set_default
3934(PyObject *pSelf, PyObject *pArgs)
3935{
Benny Prijonodc308702006-12-09 00:39:42 +00003936 int id;
3937 int status;
Benny Prijono98793592006-12-04 08:33:20 +00003938
3939 if (!PyArg_ParseTuple(pArgs, "i", &id))
3940 {
3941 return NULL;
3942 }
3943 status = pjsua_acc_set_default(id);
3944
3945 return Py_BuildValue("i", status);
3946}
3947
3948/*
3949 * py_pjsua_acc_get_default
3950 */
3951static PyObject *py_pjsua_acc_get_default
3952(PyObject *pSelf, PyObject *pArgs)
3953{
Benny Prijonodc308702006-12-09 00:39:42 +00003954 int id;
Benny Prijono98793592006-12-04 08:33:20 +00003955
3956 if (!PyArg_ParseTuple(pArgs, ""))
3957 {
3958 return NULL;
3959 }
3960 id = pjsua_acc_get_default();
3961
3962 return Py_BuildValue("i", id);
3963}
3964
3965/*
3966 * py_pjsua_acc_add
Benny Prijonodc308702006-12-09 00:39:42 +00003967 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003968 */
3969static PyObject *py_pjsua_acc_add
3970(PyObject *pSelf, PyObject *pArgs)
3971{
Benny Prijonodc308702006-12-09 00:39:42 +00003972 int is_default;
Fahris6f35cb82007-02-01 07:41:26 +00003973 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003974 acc_config_Object * ac;
3975 pjsua_acc_config cfg;
3976
3977 int p_acc_id;
3978 int status;
3979 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003980
Fahris17d91812007-01-29 12:09:33 +00003981 if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00003982 {
3983 return NULL;
3984 }
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003985
3986 pjsua_acc_config_default(&cfg);
Fahris17d91812007-01-29 12:09:33 +00003987 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003988 {
Fahris17d91812007-01-29 12:09:33 +00003989 ac = (acc_config_Object *)acObj;
3990 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003991 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003992 {
Fahris17d91812007-01-29 12:09:33 +00003993 /*cfg.cred_info[i] = ac->cred_info[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00003994 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
Fahris17d91812007-01-29 12:09:33 +00003995 PyList_GetItem((PyObject *)ac->cred_info,i);
Fahris6f35cb82007-02-01 07:41:26 +00003996 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
3997 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
3998 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
3999 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
4000 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
4001 cfg.cred_info[i].scheme.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004002 (PyString_AsString(ci->scheme));
Fahris6f35cb82007-02-01 07:41:26 +00004003 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4004 cfg.cred_info[i].username.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004005 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004006 cfg.cred_info[i].data_type = ci->data_type;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004007 }
Fahris17d91812007-01-29 12:09:33 +00004008 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4009 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4010 cfg.id.ptr = PyString_AsString(ac->id);
4011 cfg.id.slen = strlen(PyString_AsString(ac->id));
4012 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004013 for (i = 0; i < PJSUA_MAX_ACC; i++)
4014 {
Fahris17d91812007-01-29 12:09:33 +00004015 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004016 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004017 (PyList_GetItem((PyObject *)ac->proxy,i));
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004018 }
Fahris17d91812007-01-29 12:09:33 +00004019 cfg.proxy_cnt = ac->proxy_cnt;
4020 cfg.publish_enabled = ac->publish_enabled;
4021 cfg.reg_timeout = ac->reg_timeout;
4022 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4023 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004024
Fahris17d91812007-01-29 12:09:33 +00004025 status = pjsua_acc_add(&cfg, is_default, &p_acc_id);
4026 } else {
4027 status = pjsua_acc_add(NULL, is_default, &p_acc_id);
Fahris6f35cb82007-02-01 07:41:26 +00004028 }
Benny Prijonodc308702006-12-09 00:39:42 +00004029
4030 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004031}
4032
4033/*
4034 * py_pjsua_acc_add_local
Benny Prijonodc308702006-12-09 00:39:42 +00004035 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004036 */
4037static PyObject *py_pjsua_acc_add_local
4038(PyObject *pSelf, PyObject *pArgs)
4039{
Benny Prijonodc308702006-12-09 00:39:42 +00004040 int is_default;
4041 int tid;
4042
4043 int p_acc_id;
4044 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004045
4046
Fahris17d91812007-01-29 12:09:33 +00004047 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00004048 {
4049 return NULL;
4050 }
4051
Benny Prijonodc308702006-12-09 00:39:42 +00004052
Benny Prijono98793592006-12-04 08:33:20 +00004053 status = pjsua_acc_add_local(tid, is_default, &p_acc_id);
Benny Prijonodc308702006-12-09 00:39:42 +00004054
4055 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004056}
4057
4058/*
4059 * py_pjsua_acc_del
4060 */
4061static PyObject *py_pjsua_acc_del
4062(PyObject *pSelf, PyObject *pArgs)
4063{
Benny Prijonodc308702006-12-09 00:39:42 +00004064 int acc_id;
4065 int status;
4066
Benny Prijono98793592006-12-04 08:33:20 +00004067 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
4068 {
4069 return NULL;
4070 }
4071
4072
4073 status = pjsua_acc_del(acc_id);
4074 return Py_BuildValue("i", status);
4075}
4076
4077/*
4078 * py_pjsua_acc_modify
4079 */
4080static PyObject *py_pjsua_acc_modify
4081(PyObject *pSelf, PyObject *pArgs)
4082{
Fahris6f35cb82007-02-01 07:41:26 +00004083 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004084 acc_config_Object * ac;
4085 pjsua_acc_config cfg;
4086 int acc_id;
4087 int status;
4088 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004089
Fahris17d91812007-01-29 12:09:33 +00004090 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj))
Benny Prijono98793592006-12-04 08:33:20 +00004091 {
4092 return NULL;
4093 }
Fahris17d91812007-01-29 12:09:33 +00004094 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004095 {
4096 ac = (acc_config_Object *)acObj;
Fahris17d91812007-01-29 12:09:33 +00004097 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00004098 for (i = 0; i < PJSUA_MAX_ACC; i++)
4099 {
Fahris17d91812007-01-29 12:09:33 +00004100 /*cfg.cred_info[i] = ac->cred_info[i];*/
4101 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
4102 PyList_GetItem((PyObject *)ac->cred_info,i);
4103 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
4104 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
4105 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
4106 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
4107 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
4108 cfg.cred_info[i].scheme.slen = strlen
4109 (PyString_AsString(ci->scheme));
4110 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4111 cfg.cred_info[i].username.slen = strlen
4112 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004113 }
Fahris17d91812007-01-29 12:09:33 +00004114 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4115 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4116 cfg.id.ptr = PyString_AsString(ac->id);
4117 cfg.id.slen = strlen(PyString_AsString(ac->id));
4118 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004119 for (i = 0; i < PJSUA_MAX_ACC; i++)
4120 {
Fahris17d91812007-01-29 12:09:33 +00004121 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004122 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004123 (PyList_GetItem((PyObject *)ac->proxy,i));
Fahris6f35cb82007-02-01 07:41:26 +00004124 }
Fahris17d91812007-01-29 12:09:33 +00004125 cfg.proxy_cnt = ac->proxy_cnt;
4126 cfg.publish_enabled = ac->publish_enabled;
4127 cfg.reg_timeout = ac->reg_timeout;
4128 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4129 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
4130 status = pjsua_acc_modify(acc_id, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00004131 } else {
4132 status = pjsua_acc_modify(acc_id, NULL);
4133 }
Benny Prijono98793592006-12-04 08:33:20 +00004134 return Py_BuildValue("i", status);
4135}
4136
4137/*
4138 * py_pjsua_acc_set_online_status
4139 */
4140static PyObject *py_pjsua_acc_set_online_status
4141(PyObject *pSelf, PyObject *pArgs)
4142{
Benny Prijonodc308702006-12-09 00:39:42 +00004143 int is_online;
4144 int acc_id;
4145 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004146
4147 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online))
4148 {
4149 return NULL;
4150 }
4151
4152 status = pjsua_acc_set_online_status(acc_id, is_online);
4153
4154 return Py_BuildValue("i", status);
4155}
4156
4157/*
4158 * py_pjsua_acc_set_registration
4159 */
4160static PyObject *py_pjsua_acc_set_registration
4161(PyObject *pSelf, PyObject *pArgs)
4162{
Benny Prijonodc308702006-12-09 00:39:42 +00004163 int renew;
4164 int acc_id;
4165 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004166
4167 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew))
4168 {
4169 return NULL;
4170 }
4171
4172 status = pjsua_acc_set_registration(acc_id, renew);
4173
4174 return Py_BuildValue("i", status);
4175}
4176
4177/*
Benny Prijonodc308702006-12-09 00:39:42 +00004178 * py_pjsua_acc_get_info
4179 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004180 */
4181static PyObject *py_pjsua_acc_get_info
4182(PyObject *pSelf, PyObject *pArgs)
4183{
Benny Prijonodc308702006-12-09 00:39:42 +00004184 int acc_id;
4185 acc_info_Object * obj;
4186 pjsua_acc_info info;
4187 int status;
4188 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004189
Benny Prijonodc308702006-12-09 00:39:42 +00004190 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
Benny Prijono98793592006-12-04 08:33:20 +00004191 {
4192 return NULL;
4193 }
4194
Benny Prijonodc308702006-12-09 00:39:42 +00004195
Benny Prijono98793592006-12-04 08:33:20 +00004196 status = pjsua_acc_get_info(acc_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004197 if (status == PJ_SUCCESS)
4198 {
Benny Prijonodc308702006-12-09 00:39:42 +00004199 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL, NULL);
4200 obj->acc_uri =
4201 PyString_FromStringAndSize(info.acc_uri.ptr,
4202 info.acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004203 for (i = 0; i < PJ_ERR_MSG_SIZE; i++)
4204 {
Benny Prijonodc308702006-12-09 00:39:42 +00004205 obj->buf_[i] = info.buf_[i];
Benny Prijono98793592006-12-04 08:33:20 +00004206 }
Benny Prijonodc308702006-12-09 00:39:42 +00004207 obj->expires = info.expires;
4208 obj->has_registration = info.has_registration;
4209 obj->id = info.id;
4210 obj->is_default = info.is_default;
4211 obj->online_status = info.online_status;
4212 obj->status = info.status;
4213 obj->status_text =
4214 PyString_FromStringAndSize(info.status_text.ptr,
4215 info.status_text.slen);
4216 return Py_BuildValue("O", obj);
4217 } else {
4218 Py_INCREF(Py_None);
4219 return Py_None;
4220 }
Benny Prijono98793592006-12-04 08:33:20 +00004221}
4222
4223/*
4224 * py_pjsua_enum_accs
Fahrisdcf8fa42006-12-28 03:13:48 +00004225 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004226 */
4227static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
4228{
4229 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004230 PyObject *list;
4231
Fahrisdcf8fa42006-12-28 03:13:48 +00004232 pjsua_acc_id id[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004233 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004234 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004235 {
4236 return NULL;
4237 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004238 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004239
Benny Prijono98793592006-12-04 08:33:20 +00004240 status = pjsua_enum_accs(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004241
4242 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004243 for (i = 0; i < c; i++)
4244 {
Benny Prijonodc308702006-12-09 00:39:42 +00004245 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004246 if (ret == -1)
4247 {
Benny Prijonodc308702006-12-09 00:39:42 +00004248 return NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004249 }
Benny Prijonodc308702006-12-09 00:39:42 +00004250 }
4251
Benny Prijonodc308702006-12-09 00:39:42 +00004252 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004253}
4254
4255/*
4256 * py_pjsua_acc_enum_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004257 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004258 */
4259static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
4260{
4261 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004262 PyObject *list;
4263
Fahrisdcf8fa42006-12-28 03:13:48 +00004264 pjsua_acc_info info[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004265 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004266 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004267 {
4268 return NULL;
4269 }
Benny Prijonodc308702006-12-09 00:39:42 +00004270
Fahrisdcf8fa42006-12-28 03:13:48 +00004271 c = PJ_ARRAY_SIZE(info);
Benny Prijono98793592006-12-04 08:33:20 +00004272 status = pjsua_acc_enum_info(info, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004273
4274 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004275 for (i = 0; i < c; i++)
4276 {
Benny Prijonodc308702006-12-09 00:39:42 +00004277 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00004278 int j;
4279 acc_info_Object *obj;
4280 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL,NULL);
4281 obj->acc_uri = PyString_FromStringAndSize
Benny Prijonodc308702006-12-09 00:39:42 +00004282 (info[i].acc_uri.ptr, info[i].acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004283 for(j = 0; j < PJ_ERR_MSG_SIZE; j++)
4284 {
4285 obj->buf_[j] = info[i].buf_[j];
Benny Prijono98793592006-12-04 08:33:20 +00004286 }
Fahris6f35cb82007-02-01 07:41:26 +00004287 obj->expires = info[i].expires;
4288 obj->has_registration = info[i].has_registration;
4289 obj->id = info[i].id;
4290 obj->is_default = info[i].is_default;
4291 obj->online_status = info[i].online_status;
4292 obj->status = info[i].status;
4293 obj->status_text = PyString_FromStringAndSize(info[i].status_text.ptr,
Benny Prijonodc308702006-12-09 00:39:42 +00004294 info[i].status_text.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004295 ret = PyList_SetItem(list, i, (PyObject *)obj);
Benny Prijonodc308702006-12-09 00:39:42 +00004296 if (ret == -1) {
Fahris6f35cb82007-02-01 07:41:26 +00004297 return NULL;
Benny Prijonodc308702006-12-09 00:39:42 +00004298 }
4299 }
4300
Benny Prijonodc308702006-12-09 00:39:42 +00004301 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004302}
4303
4304/*
4305 * py_pjsua_acc_find_for_outgoing
4306 */
4307static PyObject *py_pjsua_acc_find_for_outgoing
4308(PyObject *pSelf, PyObject *pArgs)
4309{
4310
Benny Prijonodc308702006-12-09 00:39:42 +00004311 int acc_id;
4312 PyObject * url;
4313 pj_str_t str;
Benny Prijono98793592006-12-04 08:33:20 +00004314
4315 if (!PyArg_ParseTuple(pArgs, "O", &url))
4316 {
4317 return NULL;
4318 }
Benny Prijonodc308702006-12-09 00:39:42 +00004319 str.ptr = PyString_AsString(url);
4320 str.slen = strlen(PyString_AsString(url));
Benny Prijono98793592006-12-04 08:33:20 +00004321
4322 acc_id = pjsua_acc_find_for_outgoing(&str);
4323
4324 return Py_BuildValue("i", acc_id);
4325}
4326
4327/*
4328 * py_pjsua_acc_find_for_incoming
4329 */
4330static PyObject *py_pjsua_acc_find_for_incoming
4331(PyObject *pSelf, PyObject *pArgs)
4332{
Benny Prijonodc308702006-12-09 00:39:42 +00004333 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004334 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004335 pjsip_rx_data_Object * obj;
4336 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004337
Fahris17d91812007-01-29 12:09:33 +00004338 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00004339 {
4340 return NULL;
4341 }
Fahris17d91812007-01-29 12:09:33 +00004342 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004343 {
Fahris17d91812007-01-29 12:09:33 +00004344 obj = (pjsip_rx_data_Object *)tmpObj;
4345 rdata = obj->rdata;
4346 acc_id = pjsua_acc_find_for_incoming(rdata);
Fahris6f35cb82007-02-01 07:41:26 +00004347 } else {
Fahris17d91812007-01-29 12:09:33 +00004348 acc_id = pjsua_acc_find_for_incoming(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004349 }
Benny Prijono98793592006-12-04 08:33:20 +00004350 return Py_BuildValue("i", acc_id);
4351}
4352
4353/*
4354 * py_pjsua_acc_create_uac_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004355 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004356 */
4357static PyObject *py_pjsua_acc_create_uac_contact
4358(PyObject *pSelf, PyObject *pArgs)
4359{
Benny Prijonodc308702006-12-09 00:39:42 +00004360 int status;
Fahris17d91812007-01-29 12:09:33 +00004361 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004362 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004363 pj_pool_Object * p;
4364 pj_pool_t * pool;
4365 PyObject * strc;
4366 pj_str_t contact;
4367 PyObject * stru;
4368 pj_str_t uri;
Benny Prijono98793592006-12-04 08:33:20 +00004369
Fahris17d91812007-01-29 12:09:33 +00004370 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru))
Benny Prijono98793592006-12-04 08:33:20 +00004371 {
4372 return NULL;
4373 }
Fahris17d91812007-01-29 12:09:33 +00004374 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004375 {
Fahris17d91812007-01-29 12:09:33 +00004376 p = (pj_pool_Object *)pObj;
4377 pool = p->pool;
4378 uri.ptr = PyString_AsString(stru);
4379 uri.slen = strlen(PyString_AsString(stru));
4380 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004381 } else {
Fahris17d91812007-01-29 12:09:33 +00004382 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004383 }
Benny Prijonodc308702006-12-09 00:39:42 +00004384 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004385
Benny Prijonodc308702006-12-09 00:39:42 +00004386 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004387}
4388
4389/*
4390 * py_pjsua_acc_create_uas_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004391 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004392 */
4393static PyObject *py_pjsua_acc_create_uas_contact
4394(PyObject *pSelf, PyObject *pArgs)
4395{
Benny Prijonodc308702006-12-09 00:39:42 +00004396 int status;
4397 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004398 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004399 pj_pool_Object * p;
4400 pj_pool_t * pool;
4401 PyObject * strc;
4402 pj_str_t contact;
Fahris6f35cb82007-02-01 07:41:26 +00004403 PyObject * rObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004404 pjsip_rx_data_Object * objr;
4405 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004406
Fahris17d91812007-01-29 12:09:33 +00004407 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj))
Benny Prijono98793592006-12-04 08:33:20 +00004408 {
4409 return NULL;
4410 }
Fahris17d91812007-01-29 12:09:33 +00004411 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004412 {
Fahris17d91812007-01-29 12:09:33 +00004413 p = (pj_pool_Object *)pObj;
4414 pool = p->pool;
4415 } else {
4416 pool = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004417 }
Fahris17d91812007-01-29 12:09:33 +00004418 if (rObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004419 {
4420 objr = (pjsip_rx_data_Object *)rObj;
Fahris17d91812007-01-29 12:09:33 +00004421 rdata = objr->rdata;
Fahris6f35cb82007-02-01 07:41:26 +00004422 } else {
Fahris17d91812007-01-29 12:09:33 +00004423 rdata = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004424 }
Benny Prijono98793592006-12-04 08:33:20 +00004425 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata);
Benny Prijonodc308702006-12-09 00:39:42 +00004426 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004427
Benny Prijonodc308702006-12-09 00:39:42 +00004428 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004429}
4430
4431static char pjsua_acc_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004432 "py_pjsua.Acc_Config py_pjsua.acc_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00004433 "Call this function to initialize account config with default values.";
4434static char pjsua_acc_get_count_doc[] =
4435 "int py_pjsua.acc_get_count () "
4436 "Get number of current accounts.";
4437static char pjsua_acc_is_valid_doc[] =
4438 "int py_pjsua.acc_is_valid (int acc_id) "
4439 "Check if the specified account ID is valid.";
4440static char pjsua_acc_set_default_doc[] =
4441 "int py_pjsua.acc_set_default (int acc_id) "
4442 "Set default account to be used when incoming "
Benny Prijonodc308702006-12-09 00:39:42 +00004443 "and outgoing requests doesn't match any accounts.";
Benny Prijono98793592006-12-04 08:33:20 +00004444static char pjsua_acc_get_default_doc[] =
4445 "int py_pjsua.acc_get_default () "
4446 "Get default account.";
4447static char pjsua_acc_add_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004448 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, "
4449 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004450 "Add a new account to pjsua. PJSUA must have been initialized "
Benny Prijonodc308702006-12-09 00:39:42 +00004451 "(with pjsua_init()) before calling this function.";
Benny Prijono98793592006-12-04 08:33:20 +00004452static char pjsua_acc_add_local_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004453 "int,int py_pjsua.acc_add_local (int tid, "
4454 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004455 "Add a local account. A local account is used to identify "
Benny Prijonodc308702006-12-09 00:39:42 +00004456 "local endpoint instead of a specific user, and for this reason, "
4457 "a transport ID is needed to obtain the local address information.";
Benny Prijono98793592006-12-04 08:33:20 +00004458static char pjsua_acc_del_doc[] =
4459 "int py_pjsua.acc_del (int acc_id) "
4460 "Delete account.";
4461static char pjsua_acc_modify_doc[] =
4462 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) "
4463 "Modify account information.";
4464static char pjsua_acc_set_online_status_doc[] =
4465 "int py_pjsua.acc_set_online_status (int acc_id, int is_online) "
4466 "Modify account's presence status to be advertised "
Benny Prijonodc308702006-12-09 00:39:42 +00004467 "to remote/presence subscribers.";
Benny Prijono98793592006-12-04 08:33:20 +00004468static char pjsua_acc_set_registration_doc[] =
4469 "int py_pjsua.acc_set_registration (int acc_id, int renew) "
4470 "Update registration or perform unregistration.";
4471static char pjsua_acc_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004472 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) "
Benny Prijono98793592006-12-04 08:33:20 +00004473 "Get account information.";
4474static char pjsua_enum_accs_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004475 "int[] py_pjsua.enum_accs () "
Benny Prijono98793592006-12-04 08:33:20 +00004476 "Enum accounts all account ids.";
4477static char pjsua_acc_enum_info_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004478 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () "
Benny Prijono98793592006-12-04 08:33:20 +00004479 "Enum accounts info.";
4480static char pjsua_acc_find_for_outgoing_doc[] =
4481 "int py_pjsua.acc_find_for_outgoing (string url) "
4482 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004483 "to used to reach to the specified URL.";
Benny Prijono98793592006-12-04 08:33:20 +00004484static char pjsua_acc_find_for_incoming_doc[] =
4485 "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) "
4486 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004487 "to be used to handle incoming calls.";
Benny Prijono98793592006-12-04 08:33:20 +00004488static char pjsua_acc_create_uac_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004489 "string py_pjsua.acc_create_uac_contact (pj_pool_Object pool, "
4490 "int acc_id, string uri) "
Benny Prijono98793592006-12-04 08:33:20 +00004491 "Create a suitable URI to be put as Contact based on the specified "
Benny Prijonodc308702006-12-09 00:39:42 +00004492 "target URI for the specified account.";
Benny Prijono98793592006-12-04 08:33:20 +00004493static char pjsua_acc_create_uas_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004494 "string py_pjsua.acc_create_uas_contact (pj_pool_Object pool, "
4495 "int acc_id, pjsip_rx_data_Object rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00004496 "Create a suitable URI to be put as Contact based on the information "
Benny Prijonodc308702006-12-09 00:39:42 +00004497 "in the incoming request.";
Benny Prijono98793592006-12-04 08:33:20 +00004498
4499/* END OF LIB ACCOUNT */
4500
Benny Prijonodc308702006-12-09 00:39:42 +00004501/* LIB BUDDY */
4502
4503
4504
4505/*
4506 * buddy_config_Object
4507 * Buddy Config
4508 */
4509typedef struct
4510{
4511 PyObject_HEAD
4512 /* Type-specific fields go here. */
4513
4514 PyObject * uri;
4515 int subscribe;
4516} buddy_config_Object;
4517
4518
4519/*
4520 * buddy_config_dealloc
4521 * deletes a buddy_config from memory
4522 */
4523static void buddy_config_dealloc(buddy_config_Object* self)
4524{
4525 Py_XDECREF(self->uri);
4526 self->ob_type->tp_free((PyObject*)self);
4527}
4528
4529
4530/*
4531 * buddy_config_new
4532 * constructor for buddy_config object
4533 */
4534static PyObject * buddy_config_new(PyTypeObject *type, PyObject *args,
4535 PyObject *kwds)
4536{
4537 buddy_config_Object *self;
4538
4539 self = (buddy_config_Object *)type->tp_alloc(type, 0);
4540 if (self != NULL)
4541 {
4542 self->uri = PyString_FromString("");
4543 if (self->uri == NULL)
4544 {
4545 Py_DECREF(self);
4546 return NULL;
4547 }
4548 }
4549 return (PyObject *)self;
4550}
4551
4552/*
4553 * buddy_config_members
4554 */
4555static PyMemberDef buddy_config_members[] =
4556{
4557
4558 {
4559 "uri", T_OBJECT_EX,
4560 offsetof(buddy_config_Object, uri), 0,
4561 "TBuddy URL or name address."
4562 },
4563
4564 {
4565 "subscribe", T_INT,
4566 offsetof(buddy_config_Object, subscribe), 0,
4567 "Specify whether presence subscription should start immediately. "
4568 },
4569
4570 {NULL} /* Sentinel */
4571};
4572
4573
4574
4575
4576/*
4577 * buddy_config_Type
4578 */
4579static PyTypeObject buddy_config_Type =
4580{
4581 PyObject_HEAD_INIT(NULL)
4582 0, /*ob_size*/
4583 "py_pjsua.Buddy_Config", /*tp_name*/
4584 sizeof(buddy_config_Object), /*tp_basicsize*/
4585 0, /*tp_itemsize*/
4586 (destructor)buddy_config_dealloc,/*tp_dealloc*/
4587 0, /*tp_print*/
4588 0, /*tp_getattr*/
4589 0, /*tp_setattr*/
4590 0, /*tp_compare*/
4591 0, /*tp_repr*/
4592 0, /*tp_as_number*/
4593 0, /*tp_as_sequence*/
4594 0, /*tp_as_mapping*/
4595 0, /*tp_hash */
4596 0, /*tp_call*/
4597 0, /*tp_str*/
4598 0, /*tp_getattro*/
4599 0, /*tp_setattro*/
4600 0, /*tp_as_buffer*/
4601 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4602 "Buddy Config objects", /* tp_doc */
4603 0, /* tp_traverse */
4604 0, /* tp_clear */
4605 0, /* tp_richcompare */
4606 0, /* tp_weaklistoffset */
4607 0, /* tp_iter */
4608 0, /* tp_iternext */
4609 0, /* tp_methods */
4610 buddy_config_members, /* tp_members */
4611 0, /* tp_getset */
4612 0, /* tp_base */
4613 0, /* tp_dict */
4614 0, /* tp_descr_get */
4615 0, /* tp_descr_set */
4616 0, /* tp_dictoffset */
4617 0, /* tp_init */
4618 0, /* tp_alloc */
4619 buddy_config_new, /* tp_new */
4620
4621};
4622
4623/*
4624 * buddy_info_Object
4625 * Buddy Info
4626 * !modified @ 071206
4627 */
4628typedef struct
4629{
4630 PyObject_HEAD
4631 /* Type-specific fields go here. */
4632 int id;
4633 PyObject * uri;
4634 PyObject * contact;
4635 int status;
4636 PyObject * status_text;
4637 int monitor_pres;
4638 char buf_[256];
4639} buddy_info_Object;
4640
4641
4642/*
4643 * buddy_info_dealloc
4644 * deletes a buddy_info from memory
4645 * !modified @ 071206
4646 */
4647static void buddy_info_dealloc(buddy_info_Object* self)
4648{
4649 Py_XDECREF(self->uri);
4650 Py_XDECREF(self->contact);
4651 Py_XDECREF(self->status_text);
4652
4653 self->ob_type->tp_free((PyObject*)self);
4654}
4655
4656
4657/*
4658 * buddy_info_new
4659 * constructor for buddy_info object
4660 * !modified @ 071206
4661 */
4662static PyObject * buddy_info_new(PyTypeObject *type, PyObject *args,
4663 PyObject *kwds)
4664{
4665 buddy_info_Object *self;
4666
4667 self = (buddy_info_Object *)type->tp_alloc(type, 0);
4668 if (self != NULL)
4669 {
4670 self->uri = PyString_FromString("");
4671 if (self->uri == NULL)
4672 {
4673 Py_DECREF(self);
4674 return NULL;
4675 }
4676 self->contact = PyString_FromString("");
4677 if (self->contact == NULL)
4678 {
4679 Py_DECREF(self);
4680 return NULL;
4681 }
4682 self->status_text = PyString_FromString("");
4683 if (self->status_text == NULL)
4684 {
4685 Py_DECREF(self);
4686 return NULL;
4687 }
4688
4689 }
4690 return (PyObject *)self;
4691}
4692
4693/*
4694 * buddy_info_members
4695 * !modified @ 071206
4696 */
4697static PyMemberDef buddy_info_members[] =
4698{
4699 {
4700 "id", T_INT,
4701 offsetof(buddy_info_Object, id), 0,
4702 "The buddy ID."
4703 },
4704 {
4705 "uri", T_OBJECT_EX,
4706 offsetof(buddy_info_Object, uri), 0,
4707 "The full URI of the buddy, as specified in the configuration. "
4708 },
4709 {
4710 "contact", T_OBJECT_EX,
4711 offsetof(buddy_info_Object, contact), 0,
4712 "Buddy's Contact, only available when presence subscription "
4713 "has been established to the buddy."
4714 },
4715 {
4716 "status", T_INT,
4717 offsetof(buddy_info_Object, status), 0,
4718 "Buddy's online status. "
4719 },
4720 {
4721 "status_text", T_OBJECT_EX,
4722 offsetof(buddy_info_Object, status_text), 0,
4723 "Text to describe buddy's online status."
4724 },
4725 {
4726 "monitor_pres", T_INT,
4727 offsetof(buddy_info_Object, monitor_pres), 0,
4728 "Flag to indicate that we should monitor the presence information "
4729 "for this buddy (normally yes, unless explicitly disabled). "
4730 },
4731
4732
4733 {NULL} /* Sentinel */
4734};
4735
4736
4737
4738
4739/*
4740 * buddy_info_Type
4741 */
4742static PyTypeObject buddy_info_Type =
4743{
4744 PyObject_HEAD_INIT(NULL)
4745 0, /*ob_size*/
4746 "py_pjsua.Buddy_Info", /*tp_name*/
4747 sizeof(buddy_info_Object), /*tp_basicsize*/
4748 0, /*tp_itemsize*/
4749 (destructor)buddy_info_dealloc,/*tp_dealloc*/
4750 0, /*tp_print*/
4751 0, /*tp_getattr*/
4752 0, /*tp_setattr*/
4753 0, /*tp_compare*/
4754 0, /*tp_repr*/
4755 0, /*tp_as_number*/
4756 0, /*tp_as_sequence*/
4757 0, /*tp_as_mapping*/
4758 0, /*tp_hash */
4759 0, /*tp_call*/
4760 0, /*tp_str*/
4761 0, /*tp_getattro*/
4762 0, /*tp_setattro*/
4763 0, /*tp_as_buffer*/
4764 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4765 "Buddy Info objects", /* tp_doc */
4766 0, /* tp_traverse */
4767 0, /* tp_clear */
4768 0, /* tp_richcompare */
4769 0, /* tp_weaklistoffset */
4770 0, /* tp_iter */
4771 0, /* tp_iternext */
4772 0, /* tp_methods */
4773 buddy_info_members, /* tp_members */
4774 0, /* tp_getset */
4775 0, /* tp_base */
4776 0, /* tp_dict */
4777 0, /* tp_descr_get */
4778 0, /* tp_descr_set */
4779 0, /* tp_dictoffset */
4780 0, /* tp_init */
4781 0, /* tp_alloc */
4782 buddy_info_new, /* tp_new */
4783
4784};
4785
4786/*
Fahris6f35cb82007-02-01 07:41:26 +00004787 * py_pjsua_buddy_config_default
4788 */
4789static PyObject *py_pjsua_buddy_config_default
4790(PyObject *pSelf, PyObject *pArgs)
4791{
4792 buddy_config_Object *obj;
4793 pjsua_buddy_config cfg;
4794
4795 if (!PyArg_ParseTuple(pArgs, ""))
4796 {
4797 return NULL;
4798 }
4799
4800 pjsua_buddy_config_default(&cfg);
4801 obj = (buddy_config_Object *) buddy_config_new
4802 (&buddy_config_Type,NULL,NULL);
4803 obj->uri = PyString_FromStringAndSize(
4804 cfg.uri.ptr, cfg.uri.slen
4805 );
4806 obj->subscribe = cfg.subscribe;
4807
4808 return (PyObject *)obj;
4809}
4810
4811/*
Benny Prijonodc308702006-12-09 00:39:42 +00004812 * py_pjsua_get_buddy_count
4813 */
4814static PyObject *py_pjsua_get_buddy_count
Benny Prijono98793592006-12-04 08:33:20 +00004815(PyObject *pSelf, PyObject *pArgs)
4816{
Benny Prijonodc308702006-12-09 00:39:42 +00004817 int ret;
Benny Prijono98793592006-12-04 08:33:20 +00004818
Benny Prijonodc308702006-12-09 00:39:42 +00004819 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004820 {
4821 return NULL;
4822 }
Benny Prijonodc308702006-12-09 00:39:42 +00004823 ret = pjsua_get_buddy_count();
4824
4825 return Py_BuildValue("i", ret);
4826}
Benny Prijono98793592006-12-04 08:33:20 +00004827
Benny Prijonodc308702006-12-09 00:39:42 +00004828/*
4829 * py_pjsua_buddy_is_valid
4830 */
4831static PyObject *py_pjsua_buddy_is_valid
4832(PyObject *pSelf, PyObject *pArgs)
4833{
4834 int id;
4835 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00004836
Benny Prijonodc308702006-12-09 00:39:42 +00004837 if (!PyArg_ParseTuple(pArgs, "i", &id))
4838 {
4839 return NULL;
4840 }
4841 is_valid = pjsua_buddy_is_valid(id);
4842
4843 return Py_BuildValue("i", is_valid);
4844}
4845
4846/*
4847 * py_pjsua_enum_buddies
Fahrisdcf8fa42006-12-28 03:13:48 +00004848 * !modified @ 241206
Benny Prijonodc308702006-12-09 00:39:42 +00004849 */
4850static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
4851{
4852 pj_status_t status;
4853 PyObject *list;
4854
Fahrisdcf8fa42006-12-28 03:13:48 +00004855 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
Fahris17d91812007-01-29 12:09:33 +00004856 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004857 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijonodc308702006-12-09 00:39:42 +00004858 {
4859 return NULL;
4860 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004861 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004862 status = pjsua_enum_buddies(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004863 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004864 for (i = 0; i < c; i++)
4865 {
Benny Prijonodc308702006-12-09 00:39:42 +00004866 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004867 if (ret == -1)
4868 {
Benny Prijonodc308702006-12-09 00:39:42 +00004869 return NULL;
4870 }
4871 }
4872
Benny Prijonodc308702006-12-09 00:39:42 +00004873 return Py_BuildValue("O",list);
4874}
4875
4876/*
4877 * py_pjsua_buddy_get_info
4878 * !modified @ 071206
4879 */
4880static PyObject *py_pjsua_buddy_get_info
4881(PyObject *pSelf, PyObject *pArgs)
4882{
4883 int buddy_id;
4884 buddy_info_Object * obj;
4885 pjsua_buddy_info info;
4886 int status;
4887 int i;
4888
4889 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4890 {
4891 return NULL;
4892 }
4893
4894
4895 status = pjsua_buddy_get_info(buddy_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004896 if (status == PJ_SUCCESS)
4897 {
Benny Prijonodc308702006-12-09 00:39:42 +00004898 obj = (buddy_info_Object *)buddy_info_new(&buddy_info_Type,NULL,NULL);
4899 obj->id = info.id;
4900 Py_XDECREF(obj->uri);
4901 obj->uri =
4902 PyString_FromStringAndSize(info.uri.ptr,
4903 info.uri.slen);
4904 Py_XDECREF(obj->contact);
4905 obj->contact =
4906 PyString_FromStringAndSize(info.contact.ptr,
4907 info.contact.slen);
4908 obj->status = info.status;
4909 Py_XDECREF(obj->status_text);
4910 obj->status_text =
4911 PyString_FromStringAndSize(info.status_text.ptr,
4912 info.status_text.slen);
4913 obj->monitor_pres = info.monitor_pres;
Fahris6f35cb82007-02-01 07:41:26 +00004914 for (i = 0; i < 256; i++)
4915 {
Benny Prijonodc308702006-12-09 00:39:42 +00004916
4917 obj->buf_[i] = info.buf_[i];
4918 }
4919
4920 return Py_BuildValue("O", obj);
4921 } else {
4922 Py_INCREF(Py_None);
4923 return Py_None;
4924 }
4925}
4926
4927/*
4928 * py_pjsua_buddy_add
4929 * !modified @ 061206
4930 */
4931static PyObject *py_pjsua_buddy_add
4932(PyObject *pSelf, PyObject *pArgs)
Fahris17d91812007-01-29 12:09:33 +00004933{
4934 PyObject * bcObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004935 buddy_config_Object * bc;
Fahris17d91812007-01-29 12:09:33 +00004936
Benny Prijonodc308702006-12-09 00:39:42 +00004937 pjsua_buddy_config cfg;
4938
4939 int p_buddy_id;
4940 int status;
4941
Fahris17d91812007-01-29 12:09:33 +00004942 if (!PyArg_ParseTuple(pArgs, "O", &bcObj))
Benny Prijonodc308702006-12-09 00:39:42 +00004943 {
4944 return NULL;
4945 }
Fahris17d91812007-01-29 12:09:33 +00004946 if (bcObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004947 {
4948 bc = (buddy_config_Object *)bcObj;
Fahris17d91812007-01-29 12:09:33 +00004949
4950 cfg.subscribe = bc->subscribe;
4951 cfg.uri.ptr = PyString_AsString(bc->uri);
4952 cfg.uri.slen = strlen(PyString_AsString(bc->uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004953
Fahris17d91812007-01-29 12:09:33 +00004954 status = pjsua_buddy_add(&cfg, &p_buddy_id);
Fahris6f35cb82007-02-01 07:41:26 +00004955 } else {
Fahris17d91812007-01-29 12:09:33 +00004956 status = pjsua_buddy_add(NULL, &p_buddy_id);
4957 }
Benny Prijonodc308702006-12-09 00:39:42 +00004958 return Py_BuildValue("ii", status, p_buddy_id);
4959}
4960
4961/*
4962 * py_pjsua_buddy_del
4963 */
4964static PyObject *py_pjsua_buddy_del
4965(PyObject *pSelf, PyObject *pArgs)
4966{
4967 int buddy_id;
4968 int status;
4969
4970 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4971 {
4972 return NULL;
4973 }
4974
4975
4976 status = pjsua_buddy_del(buddy_id);
4977 return Py_BuildValue("i", status);
4978}
4979
4980/*
4981 * py_pjsua_buddy_subscribe_pres
4982 */
4983static PyObject *py_pjsua_buddy_subscribe_pres
4984(PyObject *pSelf, PyObject *pArgs)
4985{
4986 int buddy_id;
4987 int status;
4988 int subscribe;
4989
4990 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe))
4991 {
4992 return NULL;
4993 }
4994
4995
4996 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
4997 return Py_BuildValue("i", status);
4998}
4999
5000/*
5001 * py_pjsua_pres_dump
5002 */
5003static PyObject *py_pjsua_pres_dump
5004(PyObject *pSelf, PyObject *pArgs)
5005{
5006 int verbose;
5007
5008 if (!PyArg_ParseTuple(pArgs, "i", &verbose))
5009 {
5010 return NULL;
5011 }
5012
5013
5014 pjsua_pres_dump(verbose);
Benny Prijono98793592006-12-04 08:33:20 +00005015 Py_INCREF(Py_None);
5016 return Py_None;
5017}
5018
Benny Prijonodc308702006-12-09 00:39:42 +00005019/*
5020 * py_pjsua_im_send
5021 * !modified @ 071206
5022 */
5023static PyObject *py_pjsua_im_send
5024(PyObject *pSelf, PyObject *pArgs)
5025{
5026 int status;
5027 int acc_id;
Fahrise314b882007-02-02 10:52:04 +00005028 pj_str_t * mime_type, tmp_mime_type;
Fahris6f35cb82007-02-01 07:41:26 +00005029 pj_str_t to, content;
Benny Prijonodc308702006-12-09 00:39:42 +00005030 PyObject * st;
5031 PyObject * smt;
5032 PyObject * sc;
5033 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00005034 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005035 msg_data_Object * omd;
Fahris6f35cb82007-02-01 07:41:26 +00005036
Benny Prijonodc308702006-12-09 00:39:42 +00005037 int user_data;
5038 pj_pool_t *pool;
5039
Fahris6f35cb82007-02-01 07:41:26 +00005040
Fahris17d91812007-01-29 12:09:33 +00005041 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
5042 &st, &smt, &sc, &omdObj, &user_data))
Benny Prijonodc308702006-12-09 00:39:42 +00005043 {
5044 return NULL;
5045 }
Fahrise314b882007-02-02 10:52:04 +00005046 if (smt != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005047 {
Fahrise314b882007-02-02 10:52:04 +00005048 mime_type = &tmp_mime_type;
5049 tmp_mime_type.ptr = PyString_AsString(smt);
5050 tmp_mime_type.slen = strlen(PyString_AsString(smt));
Fahris6f35cb82007-02-01 07:41:26 +00005051 } else {
5052 mime_type = NULL;
5053 }
Benny Prijonodc308702006-12-09 00:39:42 +00005054 to.ptr = PyString_AsString(st);
5055 to.slen = strlen(PyString_AsString(st));
Fahris6f35cb82007-02-01 07:41:26 +00005056
Benny Prijonodc308702006-12-09 00:39:42 +00005057 content.ptr = PyString_AsString(sc);
5058 content.slen = strlen(PyString_AsString(sc));
Fahris17d91812007-01-29 12:09:33 +00005059 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005060 {
Fahris17d91812007-01-29 12:09:33 +00005061
5062 omd = (msg_data_Object *)omdObj;
5063 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5064 msg_data.content_type.slen = strlen
5065 (PyString_AsString(omd->content_type));
5066 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5067 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005068 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005069
Fahris17d91812007-01-29 12:09:33 +00005070 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00005071 status = pjsua_im_send(acc_id, &to, mime_type,
5072 &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00005073 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005074 } else {
Fahris17d91812007-01-29 12:09:33 +00005075
Fahris6f35cb82007-02-01 07:41:26 +00005076 status = pjsua_im_send(acc_id, &to, mime_type,
Fahris17d91812007-01-29 12:09:33 +00005077 &content, NULL, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005078 }
Fahrise314b882007-02-02 10:52:04 +00005079
Benny Prijonodc308702006-12-09 00:39:42 +00005080 return Py_BuildValue("i",status);
5081}
5082
5083/*
5084 * py_pjsua_im_typing
5085 */
5086static PyObject *py_pjsua_im_typing
5087(PyObject *pSelf, PyObject *pArgs)
5088{
5089 int status;
5090 int acc_id;
5091 pj_str_t to;
5092 PyObject * st;
5093 int is_typing;
5094 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00005095 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005096 msg_data_Object * omd;
5097 pj_pool_t * pool;
5098
Fahris17d91812007-01-29 12:09:33 +00005099 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj))
Benny Prijonodc308702006-12-09 00:39:42 +00005100 {
5101 return NULL;
5102 }
5103
5104 to.ptr = PyString_AsString(st);
5105 to.slen = strlen(PyString_AsString(st));
Fahris17d91812007-01-29 12:09:33 +00005106 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005107 {
Fahris17d91812007-01-29 12:09:33 +00005108 omd = (msg_data_Object *)omdObj;
5109 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5110 msg_data.content_type.slen = strlen
5111 (PyString_AsString(omd->content_type));
5112 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5113 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005114 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005115
Fahris17d91812007-01-29 12:09:33 +00005116 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
5117 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
5118 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005119 } else {
Fahris17d91812007-01-29 12:09:33 +00005120 status = pjsua_im_typing(acc_id, &to, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005121 }
Benny Prijonodc308702006-12-09 00:39:42 +00005122 return Py_BuildValue("i",status);
5123}
5124
Fahris6f35cb82007-02-01 07:41:26 +00005125static char pjsua_buddy_config_default_doc[] =
5126 "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () "
5127 "Set default values to the buddy config.";
Benny Prijonodc308702006-12-09 00:39:42 +00005128static char pjsua_get_buddy_count_doc[] =
5129 "int py_pjsua.get_buddy_count () "
5130 "Get total number of buddies.";
5131static char pjsua_buddy_is_valid_doc[] =
5132 "int py_pjsua.buddy_is_valid (int buddy_id) "
5133 "Check if buddy ID is valid.";
5134static char pjsua_enum_buddies_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00005135 "int[] py_pjsua.enum_buddies () "
Benny Prijonodc308702006-12-09 00:39:42 +00005136 "Enum buddy IDs.";
5137static char pjsua_buddy_get_info_doc[] =
5138 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) "
5139 "Get detailed buddy info.";
5140static char pjsua_buddy_add_doc[] =
5141 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) "
5142 "Add new buddy.";
5143static char pjsua_buddy_del_doc[] =
5144 "int py_pjsua.buddy_del (int buddy_id) "
5145 "Delete buddy.";
5146static char pjsua_buddy_subscribe_pres_doc[] =
5147 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
5148 "Enable/disable buddy's presence monitoring.";
5149static char pjsua_pres_dump_doc[] =
5150 "void py_pjsua.pres_dump (int verbose) "
5151 "Dump presence subscriptions to log file.";
5152static char pjsua_im_send_doc[] =
5153 "int py_pjsua.im_send (int acc_id, string to, string mime_type, "
5154 "string content, py_pjsua.Msg_Data msg_data, int user_data) "
5155 "Send instant messaging outside dialog, using the specified account "
5156 "for route set and authentication.";
5157static char pjsua_im_typing_doc[] =
5158 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, "
5159 "py_pjsua.Msg_Data msg_data) "
5160 "Send typing indication outside dialog.";
5161
5162/* END OF LIB BUDDY */
5163
Fahrisdcf8fa42006-12-28 03:13:48 +00005164/* LIB MEDIA */
Benny Prijono98793592006-12-04 08:33:20 +00005165
Benny Prijono572d4852006-11-23 21:50:02 +00005166
Fahrisdcf8fa42006-12-28 03:13:48 +00005167
5168/*
5169 * codec_info_Object
5170 * Codec Info
5171 * !modified @ 071206
5172 */
5173typedef struct
5174{
5175 PyObject_HEAD
5176 /* Type-specific fields go here. */
5177
5178 PyObject * codec_id;
5179 pj_uint8_t priority;
5180 char buf_[32];
5181} codec_info_Object;
5182
5183
5184/*
5185 * codec_info_dealloc
5186 * deletes a codec_info from memory
5187 * !modified @ 071206
5188 */
5189static void codec_info_dealloc(codec_info_Object* self)
5190{
5191 Py_XDECREF(self->codec_id);
5192
5193 self->ob_type->tp_free((PyObject*)self);
5194}
5195
5196
5197/*
5198 * codec_info_new
5199 * constructor for codec_info object
5200 * !modified @ 071206
5201 */
5202static PyObject * codec_info_new(PyTypeObject *type, PyObject *args,
5203 PyObject *kwds)
5204{
5205 codec_info_Object *self;
5206
5207 self = (codec_info_Object *)type->tp_alloc(type, 0);
5208 if (self != NULL)
5209 {
5210 self->codec_id = PyString_FromString("");
5211 if (self->codec_id == NULL)
5212 {
5213 Py_DECREF(self);
5214 return NULL;
5215 }
5216
5217
5218 }
5219 return (PyObject *)self;
5220}
5221
5222/*
5223 * codec_info_members
5224 * !modified @ 071206
5225 */
5226static PyMemberDef codec_info_members[] =
5227{
5228 {
5229 "codec_id", T_OBJECT_EX,
5230 offsetof(codec_info_Object, codec_id), 0,
5231 "Codec unique identification."
5232 },
5233
5234 {
5235 "priority", T_INT,
5236 offsetof(codec_info_Object, priority), 0,
5237 "Codec priority (integer 0-255)."
5238 },
5239
5240
5241
5242 {NULL} /* Sentinel */
5243};
5244
5245
5246
5247
5248/*
5249 * codec_info_Type
5250 */
5251static PyTypeObject codec_info_Type =
5252{
5253 PyObject_HEAD_INIT(NULL)
5254 0, /*ob_size*/
5255 "py_pjsua.Codec_Info", /*tp_name*/
5256 sizeof(codec_info_Object), /*tp_basicsize*/
5257 0, /*tp_itemsize*/
5258 (destructor)codec_info_dealloc,/*tp_dealloc*/
5259 0, /*tp_print*/
5260 0, /*tp_getattr*/
5261 0, /*tp_setattr*/
5262 0, /*tp_compare*/
5263 0, /*tp_repr*/
5264 0, /*tp_as_number*/
5265 0, /*tp_as_sequence*/
5266 0, /*tp_as_mapping*/
5267 0, /*tp_hash */
5268 0, /*tp_call*/
5269 0, /*tp_str*/
5270 0, /*tp_getattro*/
5271 0, /*tp_setattro*/
5272 0, /*tp_as_buffer*/
5273 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5274 "Codec Info objects", /* tp_doc */
5275 0, /* tp_traverse */
5276 0, /* tp_clear */
5277 0, /* tp_richcompare */
5278 0, /* tp_weaklistoffset */
5279 0, /* tp_iter */
5280 0, /* tp_iternext */
5281 0, /* tp_methods */
5282 codec_info_members, /* tp_members */
5283 0, /* tp_getset */
5284 0, /* tp_base */
5285 0, /* tp_dict */
5286 0, /* tp_descr_get */
5287 0, /* tp_descr_set */
5288 0, /* tp_dictoffset */
5289 0, /* tp_init */
5290 0, /* tp_alloc */
5291 codec_info_new, /* tp_new */
5292
5293};
5294
5295/*
5296 * conf_port_info_Object
5297 * Conf Port Info
5298 */
5299typedef struct
5300{
5301 PyObject_HEAD
5302 /* Type-specific fields go here. */
5303
5304 int slot_id;
5305 PyObject * name;
5306 unsigned clock_rate;
5307 unsigned channel_count;
5308 unsigned samples_per_frame;
5309 unsigned bits_per_sample;
5310 unsigned listener_cnt;
5311 PyListObject * listeners;
5312
5313} conf_port_info_Object;
5314
5315
5316/*
5317 * conf_port_info_dealloc
5318 * deletes a conf_port_info from memory
5319 */
5320static void conf_port_info_dealloc(conf_port_info_Object* self)
5321{
5322 Py_XDECREF(self->name);
5323 Py_XDECREF(self->listeners);
5324 self->ob_type->tp_free((PyObject*)self);
5325}
5326
5327
5328/*
5329 * conf_port_info_new
5330 * constructor for conf_port_info object
5331 */
5332static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
5333 PyObject *kwds)
5334{
5335 conf_port_info_Object *self;
5336
5337 self = (conf_port_info_Object *)type->tp_alloc(type, 0);
5338 if (self != NULL)
5339 {
5340 self->name = PyString_FromString("");
5341 if (self->name == NULL)
5342 {
5343 Py_DECREF(self);
5344 return NULL;
5345 }
5346
Fahris6f35cb82007-02-01 07:41:26 +00005347 self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS);
Fahrisdcf8fa42006-12-28 03:13:48 +00005348 if (self->listeners == NULL)
5349 {
5350 Py_DECREF(self);
5351 return NULL;
5352 }
5353 }
5354 return (PyObject *)self;
5355}
5356
5357/*
5358 * conf_port_info_members
5359 */
5360static PyMemberDef conf_port_info_members[] =
5361{
5362 {
5363 "slot_id", T_INT,
5364 offsetof(conf_port_info_Object, slot_id), 0,
5365 "Conference port number."
5366 },
5367 {
5368 "name", T_OBJECT_EX,
5369 offsetof(conf_port_info_Object, name), 0,
5370 "Port name"
5371 },
5372 {
5373 "clock_rate", T_INT,
5374 offsetof(conf_port_info_Object, clock_rate), 0,
5375 "Clock rate"
5376 },
5377 {
5378 "channel_count", T_INT,
5379 offsetof(conf_port_info_Object, channel_count), 0,
5380 "Number of channels."
5381 },
5382 {
5383 "samples_per_frame", T_INT,
5384 offsetof(conf_port_info_Object, samples_per_frame), 0,
5385 "Samples per frame "
5386 },
5387 {
5388 "bits_per_sample", T_INT,
5389 offsetof(conf_port_info_Object, bits_per_sample), 0,
5390 "Bits per sample"
5391 },
Fahris89ea3d02007-02-07 08:18:35 +00005392 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005393 "listener_cnt", T_INT,
5394 offsetof(conf_port_info_Object, listener_cnt), 0,
5395 "Number of listeners in the array."
Fahris89ea3d02007-02-07 08:18:35 +00005396 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005397 {
5398 "listeners", T_OBJECT_EX,
5399 offsetof(conf_port_info_Object, listeners), 0,
5400 "Array of listeners (in other words, ports where this port "
5401 "is transmitting to"
5402 },
5403
5404 {NULL} /* Sentinel */
5405};
5406
5407
5408
5409
5410/*
5411 * conf_port_info_Type
5412 */
5413static PyTypeObject conf_port_info_Type =
5414{
5415 PyObject_HEAD_INIT(NULL)
5416 0, /*ob_size*/
5417 "py_pjsua.Conf_Port_Info", /*tp_name*/
5418 sizeof(conf_port_info_Object), /*tp_basicsize*/
5419 0, /*tp_itemsize*/
5420 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
5421 0, /*tp_print*/
5422 0, /*tp_getattr*/
5423 0, /*tp_setattr*/
5424 0, /*tp_compare*/
5425 0, /*tp_repr*/
5426 0, /*tp_as_number*/
5427 0, /*tp_as_sequence*/
5428 0, /*tp_as_mapping*/
5429 0, /*tp_hash */
5430 0, /*tp_call*/
5431 0, /*tp_str*/
5432 0, /*tp_getattro*/
5433 0, /*tp_setattro*/
5434 0, /*tp_as_buffer*/
5435 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5436 "Conf Port Info objects", /* tp_doc */
5437 0, /* tp_traverse */
5438 0, /* tp_clear */
5439 0, /* tp_richcompare */
5440 0, /* tp_weaklistoffset */
5441 0, /* tp_iter */
5442 0, /* tp_iternext */
5443 0, /* tp_methods */
5444 conf_port_info_members, /* tp_members */
5445 0, /* tp_getset */
5446 0, /* tp_base */
5447 0, /* tp_dict */
5448 0, /* tp_descr_get */
5449 0, /* tp_descr_set */
5450 0, /* tp_dictoffset */
5451 0, /* tp_init */
5452 0, /* tp_alloc */
5453 conf_port_info_new, /* tp_new */
5454
5455};
5456
5457/*
5458 * pjmedia_port_Object
5459 */
5460typedef struct
5461{
5462 PyObject_HEAD
5463 /* Type-specific fields go here. */
5464 pjmedia_port * port;
5465} pjmedia_port_Object;
5466
5467
5468/*
5469 * pjmedia_port_Type
5470 */
5471static PyTypeObject pjmedia_port_Type =
5472{
5473 PyObject_HEAD_INIT(NULL)
5474 0, /*ob_size*/
5475 "py_pjsua.PJMedia_Port", /*tp_name*/
5476 sizeof(pjmedia_port_Object), /*tp_basicsize*/
5477 0, /*tp_itemsize*/
5478 0, /*tp_dealloc*/
5479 0, /*tp_print*/
5480 0, /*tp_getattr*/
5481 0, /*tp_setattr*/
5482 0, /*tp_compare*/
5483 0, /*tp_repr*/
5484 0, /*tp_as_number*/
5485 0, /*tp_as_sequence*/
5486 0, /*tp_as_mapping*/
5487 0, /*tp_hash */
5488 0, /*tp_call*/
5489 0, /*tp_str*/
5490 0, /*tp_getattro*/
5491 0, /*tp_setattro*/
5492 0, /*tp_as_buffer*/
5493 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5494 "pjmedia_port objects", /* tp_doc */
5495
5496};
5497
5498/*
5499 * pjmedia_snd_dev_info_Object
5500 * PJMedia Snd Dev Info
5501 */
5502typedef struct
5503{
5504 PyObject_HEAD
5505 /* Type-specific fields go here. */
5506
5507
5508 unsigned input_count;
5509 unsigned output_count;
5510 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00005511 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00005512
5513} pjmedia_snd_dev_info_Object;
5514
5515
5516/*
5517 * pjmedia_snd_dev_info_dealloc
5518 * deletes a pjmedia_snd_dev_info from memory
5519 */
5520static void pjmedia_snd_dev_info_dealloc(pjmedia_snd_dev_info_Object* self)
5521{
5522 Py_XDECREF(self->name);
5523 self->ob_type->tp_free((PyObject*)self);
5524}
5525
5526
5527/*
5528 * pjmedia_snd_dev_info_new
5529 * constructor for pjmedia_snd_dev_info object
5530 */
5531static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
5532 PyObject *kwds)
5533{
5534 pjmedia_snd_dev_info_Object *self;
5535
5536 self = (pjmedia_snd_dev_info_Object *)type->tp_alloc(type, 0);
5537 if (self != NULL)
5538 {
Fahrise314b882007-02-02 10:52:04 +00005539 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00005540 if (self->name == NULL)
5541 {
5542 Py_DECREF(self);
5543 return NULL;
5544 }
5545
5546 }
5547 return (PyObject *)self;
5548}
5549
5550/*
5551 * pjmedia_snd_dev_info_members
5552 */
5553static PyMemberDef pjmedia_snd_dev_info_members[] =
5554{
5555
5556 {
5557 "name", T_OBJECT_EX,
5558 offsetof(pjmedia_snd_dev_info_Object, name), 0,
5559 "Device name"
5560 },
5561 {
5562 "input_count", T_INT,
5563 offsetof(pjmedia_snd_dev_info_Object, input_count), 0,
5564 "Max number of input channels"
5565 },
5566 {
5567 "output_count", T_INT,
5568 offsetof(pjmedia_snd_dev_info_Object, output_count), 0,
5569 "Max number of output channels"
5570 },
5571 {
5572 "default_samples_per_sec", T_INT,
5573 offsetof(pjmedia_snd_dev_info_Object, default_samples_per_sec), 0,
5574 "Default sampling rate."
5575 },
5576
5577
5578 {NULL} /* Sentinel */
5579};
5580
5581
5582
5583
5584/*
5585 * pjmedia_snd_dev_info_Type
5586 */
5587static PyTypeObject pjmedia_snd_dev_info_Type =
5588{
5589 PyObject_HEAD_INIT(NULL)
5590 0, /*ob_size*/
5591 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
5592 sizeof(pjmedia_snd_dev_info_Object), /*tp_basicsize*/
5593 0, /*tp_itemsize*/
5594 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
5595 0, /*tp_print*/
5596 0, /*tp_getattr*/
5597 0, /*tp_setattr*/
5598 0, /*tp_compare*/
5599 0, /*tp_repr*/
5600 0, /*tp_as_number*/
5601 0, /*tp_as_sequence*/
5602 0, /*tp_as_mapping*/
5603 0, /*tp_hash */
5604 0, /*tp_call*/
5605 0, /*tp_str*/
5606 0, /*tp_getattro*/
5607 0, /*tp_setattro*/
5608 0, /*tp_as_buffer*/
5609 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5610 "PJMedia Snd Dev Info objects", /* tp_doc */
5611 0, /* tp_traverse */
5612 0, /* tp_clear */
5613 0, /* tp_richcompare */
5614 0, /* tp_weaklistoffset */
5615 0, /* tp_iter */
5616 0, /* tp_iternext */
5617 0, /* tp_methods */
5618 pjmedia_snd_dev_info_members, /* tp_members */
5619 0, /* tp_getset */
5620 0, /* tp_base */
5621 0, /* tp_dict */
5622 0, /* tp_descr_get */
5623 0, /* tp_descr_set */
5624 0, /* tp_dictoffset */
5625 0, /* tp_init */
5626 0, /* tp_alloc */
5627 pjmedia_snd_dev_info_new, /* tp_new */
5628
5629};
5630
5631/*
5632 * pjmedia_codec_param_info_Object
5633 * PJMedia Codec Param Info
5634 */
5635typedef struct
5636{
5637 PyObject_HEAD
5638 /* Type-specific fields go here. */
5639
5640 unsigned clock_rate;
5641 unsigned channel_cnt;
5642 pj_uint32_t avg_bps;
5643 pj_uint16_t frm_ptime;
5644 pj_uint8_t pcm_bits_per_sample;
5645 pj_uint8_t pt;
5646
5647} pjmedia_codec_param_info_Object;
5648
5649
5650
5651/*
5652 * pjmedia_codec_param_info_members
5653 */
5654static PyMemberDef pjmedia_codec_param_info_members[] =
5655{
5656
5657 {
5658 "clock_rate", T_INT,
5659 offsetof(pjmedia_codec_param_info_Object, clock_rate), 0,
5660 "Sampling rate in Hz"
5661 },
5662 {
5663 "channel_cnt", T_INT,
5664 offsetof(pjmedia_codec_param_info_Object, channel_cnt), 0,
5665 "Channel count"
5666 },
5667 {
5668 "avg_bps", T_INT,
5669 offsetof(pjmedia_codec_param_info_Object, avg_bps), 0,
5670 "Average bandwidth in bits/sec"
5671 },
5672 {
5673 "frm_ptime", T_INT,
5674 offsetof(pjmedia_codec_param_info_Object, frm_ptime), 0,
5675 "Base frame ptime in msec."
5676 },
5677 {
5678 "pcm_bits_per_sample", T_INT,
5679 offsetof(pjmedia_codec_param_info_Object, pcm_bits_per_sample), 0,
5680 "Bits/sample in the PCM side"
5681 },
5682 {
5683 "pt", T_INT,
5684 offsetof(pjmedia_codec_param_info_Object, pt), 0,
5685 "Payload type"
5686 },
5687
5688 {NULL} /* Sentinel */
5689};
5690
5691
5692
5693
5694/*
5695 * pjmedia_codec_param_info_Type
5696 */
5697static PyTypeObject pjmedia_codec_param_info_Type =
5698{
5699 PyObject_HEAD_INIT(NULL)
5700 0, /*ob_size*/
5701 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
5702 sizeof(pjmedia_codec_param_info_Object), /*tp_basicsize*/
5703 0, /*tp_itemsize*/
5704 0,/*tp_dealloc*/
5705 0, /*tp_print*/
5706 0, /*tp_getattr*/
5707 0, /*tp_setattr*/
5708 0, /*tp_compare*/
5709 0, /*tp_repr*/
5710 0, /*tp_as_number*/
5711 0, /*tp_as_sequence*/
5712 0, /*tp_as_mapping*/
5713 0, /*tp_hash */
5714 0, /*tp_call*/
5715 0, /*tp_str*/
5716 0, /*tp_getattro*/
5717 0, /*tp_setattro*/
5718 0, /*tp_as_buffer*/
5719 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5720 "PJMedia Codec Param Info objects", /* tp_doc */
5721 0, /* tp_traverse */
5722 0, /* tp_clear */
5723 0, /* tp_richcompare */
5724 0, /* tp_weaklistoffset */
5725 0, /* tp_iter */
5726 0, /* tp_iternext */
5727 0, /* tp_methods */
5728 pjmedia_codec_param_info_members, /* tp_members */
5729
5730
5731};
5732
5733/*
5734 * pjmedia_codec_param_setting_Object
5735 * PJMedia Codec Param Setting
5736 */
5737typedef struct
5738{
5739 PyObject_HEAD
5740 /* Type-specific fields go here. */
5741 pj_uint8_t frm_per_pkt;
5742 unsigned vad;
5743 unsigned cng;
5744 unsigned penh;
5745 unsigned plc;
5746 unsigned reserved;
5747 pj_uint8_t enc_fmtp_mode;
5748 pj_uint8_t dec_fmtp_mode;
5749
5750} pjmedia_codec_param_setting_Object;
5751
5752
5753
5754/*
5755 * pjmedia_codec_param_setting_members
5756 */
5757static PyMemberDef pjmedia_codec_param_setting_members[] =
5758{
5759
5760 {
5761 "frm_per_pkt", T_INT,
5762 offsetof(pjmedia_codec_param_setting_Object, frm_per_pkt), 0,
5763 "Number of frames per packet"
5764 },
5765 {
5766 "vad", T_INT,
5767 offsetof(pjmedia_codec_param_setting_Object, vad), 0,
5768 "Voice Activity Detector"
5769 },
5770 {
5771 "penh", T_INT,
5772 offsetof(pjmedia_codec_param_setting_Object, penh), 0,
5773 "Perceptual Enhancement"
5774 },
5775 {
5776 "plc", T_INT,
5777 offsetof(pjmedia_codec_param_setting_Object, plc), 0,
5778 "Packet loss concealment"
5779 },
5780 {
5781 "reserved", T_INT,
5782 offsetof(pjmedia_codec_param_setting_Object, reserved), 0,
5783 "Reserved, must be zero"
5784 },
5785 {
5786 "cng", T_INT,
5787 offsetof(pjmedia_codec_param_setting_Object, cng), 0,
5788 "Comfort Noise Generator"
5789 },
5790 {
5791 "enc_fmtp_mode", T_INT,
5792 offsetof(pjmedia_codec_param_setting_Object, enc_fmtp_mode), 0,
5793 "Mode param in fmtp (def:0)"
5794 },
5795 {
5796 "dec_fmtp_mode", T_INT,
5797 offsetof(pjmedia_codec_param_setting_Object, dec_fmtp_mode), 0,
5798 "Mode param in fmtp (def:0)"
5799 },
5800
5801 {NULL} /* Sentinel */
5802};
5803
5804
5805
5806
5807/*
5808 * pjmedia_codec_param_setting_Type
5809 */
5810static PyTypeObject pjmedia_codec_param_setting_Type =
5811{
5812 PyObject_HEAD_INIT(NULL)
5813 0, /*ob_size*/
5814 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
5815 sizeof(pjmedia_codec_param_setting_Object), /*tp_basicsize*/
5816 0, /*tp_itemsize*/
5817 0,/*tp_dealloc*/
5818 0, /*tp_print*/
5819 0, /*tp_getattr*/
5820 0, /*tp_setattr*/
5821 0, /*tp_compare*/
5822 0, /*tp_repr*/
5823 0, /*tp_as_number*/
5824 0, /*tp_as_sequence*/
5825 0, /*tp_as_mapping*/
5826 0, /*tp_hash */
5827 0, /*tp_call*/
5828 0, /*tp_str*/
5829 0, /*tp_getattro*/
5830 0, /*tp_setattro*/
5831 0, /*tp_as_buffer*/
5832 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5833 "PJMedia Codec Param Setting objects", /* tp_doc */
5834 0, /* tp_traverse */
5835 0, /* tp_clear */
5836 0, /* tp_richcompare */
5837 0, /* tp_weaklistoffset */
5838 0, /* tp_iter */
5839 0, /* tp_iternext */
5840 0, /* tp_methods */
5841 pjmedia_codec_param_setting_members, /* tp_members */
5842
5843
5844};
5845
5846/*
5847 * pjmedia_codec_param_Object
5848 * PJMedia Codec Param
5849 */
5850typedef struct
5851{
5852 PyObject_HEAD
5853 /* Type-specific fields go here. */
5854
5855 pjmedia_codec_param_info_Object * info;
5856 pjmedia_codec_param_setting_Object * setting;
5857
5858} pjmedia_codec_param_Object;
5859
5860
5861/*
5862 * pjmedia_codec_param_dealloc
5863 * deletes a pjmedia_codec_param from memory
5864 */
5865static void pjmedia_codec_param_dealloc(pjmedia_codec_param_Object* self)
5866{
5867 Py_XDECREF(self->info);
5868 Py_XDECREF(self->setting);
5869 self->ob_type->tp_free((PyObject*)self);
5870}
5871
5872
5873/*
5874 * pjmedia_codec_param_new
5875 * constructor for pjmedia_codec_param object
5876 */
5877static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
5878 PyObject *kwds)
5879{
5880 pjmedia_codec_param_Object *self;
5881
5882 self = (pjmedia_codec_param_Object *)type->tp_alloc(type, 0);
5883 if (self != NULL)
5884 {
5885 self->info = (pjmedia_codec_param_info_Object *)
5886 PyType_GenericNew(&pjmedia_codec_param_info_Type, NULL, NULL);
5887 if (self->info == NULL)
5888 {
5889 Py_DECREF(self);
5890 return NULL;
5891 }
5892 self->setting = (pjmedia_codec_param_setting_Object *)
5893 PyType_GenericNew(&pjmedia_codec_param_setting_Type, NULL, NULL);
5894 if (self->setting == NULL)
5895 {
5896 Py_DECREF(self);
5897 return NULL;
5898 }
5899 }
5900 return (PyObject *)self;
5901}
5902
5903/*
5904 * pjmedia_codec_param_members
5905 */
5906static PyMemberDef pjmedia_codec_param_members[] =
5907{
5908
5909 {
5910 "info", T_OBJECT_EX,
5911 offsetof(pjmedia_codec_param_Object, info), 0,
5912 "The 'info' part of codec param describes the capability of the codec,"
5913 " and the value should NOT be changed by application."
5914 },
5915 {
5916 "setting", T_OBJECT_EX,
5917 offsetof(pjmedia_codec_param_Object, setting), 0,
5918 "The 'setting' part of codec param describes various settings to be "
5919 "applied to the codec. When the codec param is retrieved from the "
5920 "codec or codec factory, the values of these will be filled by "
5921 "the capability of the codec. Any features that are supported by "
5922 "the codec (e.g. vad or plc) will be turned on, so that application "
5923 "can query which capabilities are supported by the codec. "
5924 "Application may change the settings here before instantiating "
5925 "the codec/stream."
5926 },
5927
5928 {NULL} /* Sentinel */
5929};
5930
5931
5932
5933
5934/*
5935 * pjmedia_codec_param_Type
5936 */
5937static PyTypeObject pjmedia_codec_param_Type =
5938{
5939 PyObject_HEAD_INIT(NULL)
5940 0, /*ob_size*/
5941 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
5942 sizeof(pjmedia_codec_param_Object), /*tp_basicsize*/
5943 0, /*tp_itemsize*/
5944 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
5945 0, /*tp_print*/
5946 0, /*tp_getattr*/
5947 0, /*tp_setattr*/
5948 0, /*tp_compare*/
5949 0, /*tp_repr*/
5950 0, /*tp_as_number*/
5951 0, /*tp_as_sequence*/
5952 0, /*tp_as_mapping*/
5953 0, /*tp_hash */
5954 0, /*tp_call*/
5955 0, /*tp_str*/
5956 0, /*tp_getattro*/
5957 0, /*tp_setattro*/
5958 0, /*tp_as_buffer*/
5959 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5960 "PJMedia Codec Param objects", /* tp_doc */
5961 0, /* tp_traverse */
5962 0, /* tp_clear */
5963 0, /* tp_richcompare */
5964 0, /* tp_weaklistoffset */
5965 0, /* tp_iter */
5966 0, /* tp_iternext */
5967 0, /* tp_methods */
5968 pjmedia_codec_param_members, /* tp_members */
5969 0, /* tp_getset */
5970 0, /* tp_base */
5971 0, /* tp_dict */
5972 0, /* tp_descr_get */
5973 0, /* tp_descr_set */
5974 0, /* tp_dictoffset */
5975 0, /* tp_init */
5976 0, /* tp_alloc */
5977 pjmedia_codec_param_new, /* tp_new */
5978
5979};
5980
5981/*
5982 * py_pjsua_conf_get_max_ports
5983 */
5984static PyObject *py_pjsua_conf_get_max_ports
5985(PyObject *pSelf, PyObject *pArgs)
5986{
5987 int ret;
5988
5989 if (!PyArg_ParseTuple(pArgs, ""))
5990 {
5991 return NULL;
5992 }
5993 ret = pjsua_conf_get_max_ports();
5994
5995 return Py_BuildValue("i", ret);
5996}
5997
5998/*
5999 * py_pjsua_conf_get_active_ports
6000 */
6001static PyObject *py_pjsua_conf_get_active_ports
6002(PyObject *pSelf, PyObject *pArgs)
6003{
6004 int ret;
6005 if (!PyArg_ParseTuple(pArgs, ""))
6006 {
6007 return NULL;
6008 }
6009 ret = pjsua_conf_get_active_ports();
6010
6011 return Py_BuildValue("i", ret);
6012}
6013
6014/*
6015 * py_pjsua_enum_conf_ports
6016 * !modified @ 241206
6017 */
6018static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
6019{
6020 pj_status_t status;
6021 PyObject *list;
6022
6023 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00006024 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006025 if (!PyArg_ParseTuple(pArgs, ""))
6026 {
6027 return NULL;
6028 }
6029
6030 c = PJ_ARRAY_SIZE(id);
6031 status = pjsua_enum_conf_ports(id, &c);
6032
6033 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006034 for (i = 0; i < c; i++)
6035 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006036 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00006037 if (ret == -1)
6038 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006039 return NULL;
6040 }
6041 }
6042
Fahrisdcf8fa42006-12-28 03:13:48 +00006043 return Py_BuildValue("O",list);
6044}
6045
6046/*
6047 * py_pjsua_conf_get_port_info
6048 */
6049static PyObject *py_pjsua_conf_get_port_info
6050(PyObject *pSelf, PyObject *pArgs)
6051{
6052 int id;
6053 conf_port_info_Object * obj;
6054 pjsua_conf_port_info info;
6055 int status;
6056 int i;
6057
6058 if (!PyArg_ParseTuple(pArgs, "i", &id))
6059 {
6060 return NULL;
6061 }
6062
6063
6064 status = pjsua_conf_get_port_info(id, &info);
6065 obj = (conf_port_info_Object *)conf_port_info_new
6066 (&conf_port_info_Type,NULL,NULL);
6067 obj->bits_per_sample = info.bits_per_sample;
6068 obj->channel_count = info.bits_per_sample;
6069 obj->clock_rate = info.clock_rate;
6070 obj->listener_cnt = info.listener_cnt;
6071 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
6072 obj->samples_per_frame = info.samples_per_frame;
6073 obj->slot_id = info.slot_id;
6074
Fahris6f35cb82007-02-01 07:41:26 +00006075 for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00006076 PyObject * item = Py_BuildValue("i",info.listeners[i]);
6077 PyList_SetItem((PyObject *)obj->listeners, i, item);
6078 }
6079 return Py_BuildValue("O", obj);
6080}
6081
6082/*
6083 * py_pjsua_conf_add_port
6084 */
6085static PyObject *py_pjsua_conf_add_port
6086(PyObject *pSelf, PyObject *pArgs)
6087{
6088 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00006089 PyObject * oportObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006090 pjmedia_port_Object * oport;
Fahris6f35cb82007-02-01 07:41:26 +00006091 pjmedia_port * port;
6092 PyObject * opoolObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006093 pj_pool_Object * opool;
Fahris6f35cb82007-02-01 07:41:26 +00006094 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00006095
6096 int status;
6097
6098
Fahris17d91812007-01-29 12:09:33 +00006099 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006100 {
6101 return NULL;
6102 }
Fahris17d91812007-01-29 12:09:33 +00006103 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006104 {
Fahris17d91812007-01-29 12:09:33 +00006105 opool = (pj_pool_Object *)opoolObj;
6106 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00006107 } else {
6108 opool = NULL;
6109 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00006110 }
6111 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006112 {
Fahris17d91812007-01-29 12:09:33 +00006113 oport = (pjmedia_port_Object *)oportObj;
6114 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00006115 } else {
Fahris17d91812007-01-29 12:09:33 +00006116 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00006117 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00006118 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006119
Fahris17d91812007-01-29 12:09:33 +00006120 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00006121
6122
6123 return Py_BuildValue("ii", status, p_id);
6124}
6125
6126/*
6127 * py_pjsua_conf_remove_port
6128 */
6129static PyObject *py_pjsua_conf_remove_port
6130(PyObject *pSelf, PyObject *pArgs)
6131{
6132 int id;
6133 int status;
6134
6135
6136 if (!PyArg_ParseTuple(pArgs, "i", &id))
6137 {
6138 return NULL;
6139 }
6140
6141 status = pjsua_conf_remove_port(id);
6142
6143
6144 return Py_BuildValue("i", status);
6145}
6146
6147/*
6148 * py_pjsua_conf_connect
6149 */
6150static PyObject *py_pjsua_conf_connect
6151(PyObject *pSelf, PyObject *pArgs)
6152{
6153 int source, sink;
6154 int status;
6155
6156
6157 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6158 {
6159 return NULL;
6160 }
6161
6162 status = pjsua_conf_connect(source, sink);
6163
6164
6165 return Py_BuildValue("i", status);
6166}
6167
6168/*
6169 * py_pjsua_conf_disconnect
6170 */
6171static PyObject *py_pjsua_conf_disconnect
6172(PyObject *pSelf, PyObject *pArgs)
6173{
6174 int source, sink;
6175 int status;
6176
6177
6178 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6179 {
6180 return NULL;
6181 }
6182
6183 status = pjsua_conf_disconnect(source, sink);
6184
6185
6186 return Py_BuildValue("i", status);
6187}
6188
6189/*
6190 * py_pjsua_player_create
6191 */
6192static PyObject *py_pjsua_player_create
6193(PyObject *pSelf, PyObject *pArgs)
6194{
6195 int id;
6196 int options;
6197 PyObject * filename;
6198 pj_str_t str;
6199 int status;
6200
6201
6202 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
6203 {
6204 return NULL;
6205 }
6206 str.ptr = PyString_AsString(filename);
6207 str.slen = strlen(PyString_AsString(filename));
6208 status = pjsua_player_create(&str, options, &id);
6209
6210 return Py_BuildValue("ii", status, id);
6211}
6212
6213/*
6214 * py_pjsua_player_get_conf_port
6215 */
6216static PyObject *py_pjsua_player_get_conf_port
6217(PyObject *pSelf, PyObject *pArgs)
6218{
6219
6220 int id, port_id;
6221
6222
6223 if (!PyArg_ParseTuple(pArgs, "i", &id))
6224 {
6225 return NULL;
6226 }
6227
6228 port_id = pjsua_player_get_conf_port(id);
6229
6230
6231 return Py_BuildValue("i", port_id);
6232}
6233
6234/*
6235 * py_pjsua_player_set_pos
6236 */
6237static PyObject *py_pjsua_player_set_pos
6238(PyObject *pSelf, PyObject *pArgs)
6239{
6240 int id;
6241 pj_uint32_t samples;
6242 int status;
6243
6244
6245 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
6246 {
6247 return NULL;
6248 }
6249
6250 status = pjsua_player_set_pos(id, samples);
6251
6252
6253 return Py_BuildValue("i", status);
6254}
6255
6256/*
6257 * py_pjsua_player_destroy
6258 */
6259static PyObject *py_pjsua_player_destroy
6260(PyObject *pSelf, PyObject *pArgs)
6261{
6262 int id;
6263 int status;
6264
6265
6266 if (!PyArg_ParseTuple(pArgs, "i", &id))
6267 {
6268 return NULL;
6269 }
6270
6271 status = pjsua_player_destroy(id);
6272
6273
6274 return Py_BuildValue("i", status);
6275}
6276
6277/*
6278 * py_pjsua_recorder_create
6279 * !modified @ 261206
6280 */
6281static PyObject *py_pjsua_recorder_create
6282(PyObject *pSelf, PyObject *pArgs)
6283{
6284 int p_id;
6285 int options;
6286 int max_size;
6287 PyObject * filename;
6288 pj_str_t str;
6289 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00006290 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00006291 int enc_type;
6292
6293 int status;
6294
6295
Fahris17d91812007-01-29 12:09:33 +00006296 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
6297 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00006298 {
6299 return NULL;
6300 }
6301 str.ptr = PyString_AsString(filename);
6302 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00006303 if (enc_param != Py_None)
6304 {
6305 strparam.ptr = PyString_AsString(enc_param);
6306 strparam.slen = strlen(PyString_AsString(enc_param));
6307 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00006308 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00006309 } else {
6310 status = pjsua_recorder_create
6311 (&str, enc_type, NULL, max_size, options, &p_id);
6312 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006313 return Py_BuildValue("ii", status, p_id);
6314}
6315
6316/*
6317 * py_pjsua_recorder_get_conf_port
6318 */
6319static PyObject *py_pjsua_recorder_get_conf_port
6320(PyObject *pSelf, PyObject *pArgs)
6321{
6322
6323 int id, port_id;
6324
6325
6326 if (!PyArg_ParseTuple(pArgs, "i", &id))
6327 {
6328 return NULL;
6329 }
6330
6331 port_id = pjsua_recorder_get_conf_port(id);
6332
6333
6334 return Py_BuildValue("i", port_id);
6335}
6336
6337/*
6338 * py_pjsua_recorder_destroy
6339 */
6340static PyObject *py_pjsua_recorder_destroy
6341(PyObject *pSelf, PyObject *pArgs)
6342{
6343 int id;
6344 int status;
6345
6346
6347 if (!PyArg_ParseTuple(pArgs, "i", &id))
6348 {
6349 return NULL;
6350 }
6351
6352 status = pjsua_recorder_destroy(id);
6353
6354
6355 return Py_BuildValue("i", status);
6356}
6357
6358/*
6359 * py_pjsua_enum_snd_devs
6360 */
6361static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
6362{
6363 pj_status_t status;
6364 PyObject *list;
6365
Fahris6f35cb82007-02-01 07:41:26 +00006366 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00006367 unsigned c, i;
Fahrisb721aa32007-01-29 05:07:41 +00006368 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00006369 {
6370 return NULL;
6371 }
6372
Fahrisb721aa32007-01-29 05:07:41 +00006373 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00006374 status = pjsua_enum_snd_devs(info, &c);
6375
6376 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006377 for (i = 0; i < c; i++)
6378 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006379 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00006380 int j;
Fahrise314b882007-02-02 10:52:04 +00006381 char * str;
6382
Fahrisdcf8fa42006-12-28 03:13:48 +00006383 pjmedia_snd_dev_info_Object * obj;
6384 obj = (pjmedia_snd_dev_info_Object *)pjmedia_snd_dev_info_new
6385 (&pjmedia_snd_dev_info_Type, NULL, NULL);
6386 obj->default_samples_per_sec = info[i].default_samples_per_sec;
6387 obj->input_count = info[i].input_count;
6388 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00006389 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
6390 memset(str, 0, SND_NAME_LEN);
6391 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00006392 {
Fahrise314b882007-02-02 10:52:04 +00006393 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00006394 }
Fahrise314b882007-02-02 10:52:04 +00006395 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
6396 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00006397 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00006398 if (ret == -1)
6399 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006400 return NULL;
6401 }
6402 }
6403
Fahrisdcf8fa42006-12-28 03:13:48 +00006404 return Py_BuildValue("O",list);
6405}
6406
6407/*
6408 * py_pjsua_get_snd_dev
6409 */
6410static PyObject *py_pjsua_get_snd_dev
6411(PyObject *pSelf, PyObject *pArgs)
6412{
6413 int capture_dev, playback_dev;
6414 int status;
6415
6416
6417 if (!PyArg_ParseTuple(pArgs, ""))
6418 {
6419 return NULL;
6420 }
6421
6422 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
6423
6424
6425 return Py_BuildValue("ii", capture_dev, playback_dev);
6426}
6427
6428/*
6429 * py_pjsua_set_snd_dev
6430 */
6431static PyObject *py_pjsua_set_snd_dev
6432(PyObject *pSelf, PyObject *pArgs)
6433{
6434 int capture_dev, playback_dev;
6435 int status;
6436
6437
6438 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
6439 {
6440 return NULL;
6441 }
6442
6443 status = pjsua_set_snd_dev(capture_dev, playback_dev);
6444
6445
6446 return Py_BuildValue("i", status);
6447}
6448
6449/*
6450 * py_pjsua_set_null_snd_dev
6451 */
6452static PyObject *py_pjsua_set_null_snd_dev
6453(PyObject *pSelf, PyObject *pArgs)
6454{
6455
6456 int status;
6457
6458
6459 if (!PyArg_ParseTuple(pArgs, ""))
6460 {
6461 return NULL;
6462 }
6463
6464 status = pjsua_set_null_snd_dev();
6465
6466
6467 return Py_BuildValue("i", status);
6468}
6469
6470/*
6471 * py_pjsua_set_no_snd_dev
6472 */
6473static PyObject *py_pjsua_set_no_snd_dev
6474(PyObject *pSelf, PyObject *pArgs)
6475{
6476
6477 pjmedia_port_Object * obj;
6478
6479 if (!PyArg_ParseTuple(pArgs, ""))
6480 {
6481 return NULL;
6482 }
6483
6484 obj = (pjmedia_port_Object *)PyType_GenericNew
6485 (&pjmedia_port_Type, NULL, NULL);
6486 obj->port = pjsua_set_no_snd_dev();
6487 return Py_BuildValue("O", obj);
6488}
6489
6490/*
6491 * py_pjsua_set_ec
6492 */
6493static PyObject *py_pjsua_set_ec
6494(PyObject *pSelf, PyObject *pArgs)
6495{
6496 int options;
6497 int tail_ms;
6498 int status;
6499
6500
6501 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
6502 {
6503 return NULL;
6504 }
6505
6506 status = pjsua_set_ec(tail_ms, options);
6507
6508
6509 return Py_BuildValue("i", status);
6510}
6511
6512/*
6513 * py_pjsua_get_ec_tail
6514 */
6515static PyObject *py_pjsua_get_ec_tail
6516(PyObject *pSelf, PyObject *pArgs)
6517{
6518
6519 int status;
Fahris17d91812007-01-29 12:09:33 +00006520 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00006521
6522 if (!PyArg_ParseTuple(pArgs, ""))
6523 {
6524 return NULL;
6525 }
6526
6527 status = pjsua_get_ec_tail(&p_tail_ms);
6528
6529
6530 return Py_BuildValue("i", p_tail_ms);
6531}
6532
6533/*
6534 * py_pjsua_enum_codecs
6535 * !modified @ 261206
6536 */
6537static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
6538{
6539 pj_status_t status;
6540 PyObject *list;
6541
6542 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00006543 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006544 if (!PyArg_ParseTuple(pArgs, ""))
6545 {
6546 return NULL;
6547 }
6548
6549 c = PJ_ARRAY_SIZE(info);
6550 status = pjsua_enum_codecs(info, &c);
6551
6552 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006553 for (i = 0; i < c; i++)
6554 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006555 int ret;
6556 int j;
6557 codec_info_Object * obj;
6558 obj = (codec_info_Object *)codec_info_new
6559 (&codec_info_Type, NULL, NULL);
6560 obj->codec_id = PyString_FromStringAndSize
6561 (info[i].codec_id.ptr, info[i].codec_id.slen);
6562 obj->priority = info[i].priority;
6563 for (j = 0; j < 32; j++)
6564 {
6565 obj->buf_[j] = info[i].buf_[j];
6566 }
6567 ret = PyList_SetItem(list, i, (PyObject *)obj);
6568 if (ret == -1) {
6569 return NULL;
6570 }
6571 }
6572
Fahris17d91812007-01-29 12:09:33 +00006573
Fahrisdcf8fa42006-12-28 03:13:48 +00006574 return Py_BuildValue("O",list);
6575}
6576
6577/*
6578 * py_pjsua_codec_set_priority
6579 */
6580static PyObject *py_pjsua_codec_set_priority
6581(PyObject *pSelf, PyObject *pArgs)
6582{
6583
6584 int status;
6585 PyObject * id;
6586 pj_str_t str;
6587 pj_uint8_t priority;
6588
6589 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
6590 {
6591 return NULL;
6592 }
6593 str.ptr = PyString_AsString(id);
6594 str.slen = strlen(PyString_AsString(id));
6595 status = pjsua_codec_set_priority(&str, priority);
6596
6597
6598 return Py_BuildValue("i", status);
6599}
6600
6601/*
6602 * py_pjsua_codec_get_param
6603 */
6604static PyObject *py_pjsua_codec_get_param
6605(PyObject *pSelf, PyObject *pArgs)
6606{
6607
6608 int status;
6609 PyObject * id;
6610 pj_str_t str;
6611 pjmedia_codec_param param;
6612 pjmedia_codec_param_Object *obj;
6613
6614
6615 if (!PyArg_ParseTuple(pArgs, "O", &id))
6616 {
6617 return NULL;
6618 }
6619 str.ptr = PyString_AsString(id);
6620 str.slen = strlen(PyString_AsString(id));
6621 status = pjsua_codec_get_param(&str, &param);
6622 obj = (pjmedia_codec_param_Object *)pjmedia_codec_param_new
6623 (&pjmedia_codec_param_Type, NULL, NULL);
6624 obj->info->avg_bps = param.info.avg_bps;
6625 obj->info->channel_cnt = param.info.channel_cnt;
6626 obj->info->clock_rate = param.info.clock_rate;
6627 obj->info->frm_ptime = param.info.frm_ptime;
6628 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
6629 obj->info->pt = param.info.pt;
6630 obj->setting->cng = param.setting.cng;
6631 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
6632 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
6633 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
6634 obj->setting->penh = param.setting.penh;
6635 obj->setting->plc = param.setting.plc;
6636 obj->setting->reserved = param.setting.reserved;
6637 obj->setting->vad = param.setting.vad;
6638
6639 return Py_BuildValue("O", obj);
6640}
6641/*
6642 * py_pjsua_codec_set_param
6643 */
6644static PyObject *py_pjsua_codec_set_param
6645(PyObject *pSelf, PyObject *pArgs)
6646{
6647
6648 int status;
6649 PyObject * id;
6650 pj_str_t str;
6651 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00006652 PyObject * tmpObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006653 pjmedia_codec_param_Object *obj;
6654
6655
Fahris17d91812007-01-29 12:09:33 +00006656 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006657 {
6658 return NULL;
6659 }
Fahris17d91812007-01-29 12:09:33 +00006660
Fahrisdcf8fa42006-12-28 03:13:48 +00006661 str.ptr = PyString_AsString(id);
6662 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00006663 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006664 {
Fahris17d91812007-01-29 12:09:33 +00006665 obj = (pjmedia_codec_param_Object *)tmpObj;
6666 param.info.avg_bps = obj->info->avg_bps;
6667 param.info.channel_cnt = obj->info->channel_cnt;
6668 param.info.clock_rate = obj->info->clock_rate;
6669 param.info.frm_ptime = obj->info->frm_ptime;
6670 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
6671 param.info.pt = obj->info->pt;
6672 param.setting.cng = obj->setting->cng;
6673 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
6674 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
6675 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
6676 param.setting.penh = obj->setting->penh;
6677 param.setting.plc = obj->setting->plc;
6678 param.setting.reserved = obj->setting->reserved;
6679 param.setting.vad = obj->setting->vad;
6680 status = pjsua_codec_set_param(&str, &param);
6681 } else {
6682 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00006683 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006684 return Py_BuildValue("i", status);
6685}
6686
6687static char pjsua_conf_get_max_ports_doc[] =
6688 "int py_pjsua.conf_get_max_ports () "
6689 "Get maxinum number of conference ports.";
6690static char pjsua_conf_get_active_ports_doc[] =
6691 "int py_pjsua.conf_get_active_ports () "
6692 "Get current number of active ports in the bridge.";
6693static char pjsua_enum_conf_ports_doc[] =
6694 "int[] py_pjsua.enum_conf_ports () "
6695 "Enumerate all conference ports.";
6696static char pjsua_conf_get_port_info_doc[] =
6697 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
6698 "Get information about the specified conference port";
6699static char pjsua_conf_add_port_doc[] =
6700 "int, int py_pjsua.conf_add_port "
6701 "(py_pjsua.PJ_Pool pool, py_pjsua.PJMedia_Port port) "
6702 "Add arbitrary media port to PJSUA's conference bridge. "
6703 "Application can use this function to add the media port "
6704 "that it creates. For media ports that are created by PJSUA-LIB "
6705 "(such as calls, file player, or file recorder), PJSUA-LIB will "
6706 "automatically add the port to the bridge.";
6707static char pjsua_conf_remove_port_doc[] =
6708 "int py_pjsua.conf_remove_port (int id) "
6709 "Remove arbitrary slot from the conference bridge. "
6710 "Application should only call this function "
6711 "if it registered the port manually.";
6712static char pjsua_conf_connect_doc[] =
6713 "int py_pjsua.conf_connect (int source, int sink) "
6714 "Establish unidirectional media flow from souce to sink. "
6715 "One source may transmit to multiple destinations/sink. "
6716 "And if multiple sources are transmitting to the same sink, "
6717 "the media will be mixed together. Source and sink may refer "
6718 "to the same ID, effectively looping the media. "
6719 "If bidirectional media flow is desired, application "
6720 "needs to call this function twice, with the second "
6721 "one having the arguments reversed.";
6722static char pjsua_conf_disconnect_doc[] =
6723 "int py_pjsua.conf_disconnect (int source, int sink) "
6724 "Disconnect media flow from the source to destination port.";
6725static char pjsua_player_create_doc[] =
6726 "int, int py_pjsua.player_create (string filename, int options) "
6727 "Create a file player, and automatically connect "
6728 "this player to the conference bridge.";
6729static char pjsua_player_get_conf_port_doc[] =
6730 "int py_pjsua.player_get_conf_port (int) "
6731 "Get conference port ID associated with player.";
6732static char pjsua_player_set_pos_doc[] =
6733 "int py_pjsua.player_set_pos (int id, int samples) "
6734 "Set playback position.";
6735static char pjsua_player_destroy_doc[] =
6736 "int py_pjsua.player_destroy (int id) "
6737 "Close the file, remove the player from the bridge, "
6738 "and free resources associated with the file player.";
6739static char pjsua_recorder_create_doc[] =
6740 "int, int py_pjsua.recorder_create (string filename, "
6741 "int enc_type, int enc_param, int max_size, int options) "
6742 "Create a file recorder, and automatically connect this recorder "
6743 "to the conference bridge. The recorder currently supports recording "
6744 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
6745 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
6746static char pjsua_recorder_get_conf_port_doc[] =
6747 "int py_pjsua.recorder_get_conf_port (int id) "
6748 "Get conference port associated with recorder.";
6749static char pjsua_recorder_destroy_doc[] =
6750 "int py_pjsua.recorder_destroy (int id) "
6751 "Destroy recorder (this will complete recording).";
6752static char pjsua_enum_snd_devs_doc[] =
6753 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
6754 "Enum sound devices.";
6755static char pjsua_get_snd_dev_doc[] =
6756 "int, int py_pjsua.get_snd_dev () "
6757 "Get currently active sound devices. "
6758 "If sound devices has not been created "
6759 "(for example when pjsua_start() is not called), "
6760 "it is possible that the function returns "
6761 "PJ_SUCCESS with -1 as device IDs.";
6762static char pjsua_set_snd_dev_doc[] =
6763 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
6764 "Select or change sound device. Application may call this function "
6765 "at any time to replace current sound device.";
6766static char pjsua_set_null_snd_dev_doc[] =
6767 "int py_pjsua.set_null_snd_dev () "
6768 "Set pjsua to use null sound device. The null sound device only "
6769 "provides the timing needed by the conference bridge, and will not "
6770 "interract with any hardware.";
6771static char pjsua_set_no_snd_dev_doc[] =
6772 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
6773 "Disconnect the main conference bridge from any sound devices, "
6774 "and let application connect the bridge to it's "
6775 "own sound device/master port.";
6776static char pjsua_set_ec_doc[] =
6777 "int py_pjsua.set_ec (int tail_ms, int options) "
6778 "Configure the echo canceller tail length of the sound port.";
6779static char pjsua_get_ec_tail_doc[] =
6780 "int py_pjsua.get_ec_tail () "
6781 "Get current echo canceller tail length.";
6782static char pjsua_enum_codecs_doc[] =
6783 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
6784 "Enum all supported codecs in the system.";
6785static char pjsua_codec_set_priority_doc[] =
6786 "int py_pjsua.codec_set_priority (string id, int priority) "
6787 "Change codec priority.";
6788static char pjsua_codec_get_param_doc[] =
6789 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
6790 "Get codec parameters";
6791static char pjsua_codec_set_param_doc[] =
6792 "int py_pjsua.codec_set_param (string id, "
6793 "py_pjsua.PJMedia_Codec_Param param) "
6794 "Set codec parameters.";
6795
6796/* END OF LIB MEDIA */
6797
6798/* LIB CALL */
6799
6800/*
6801 * pj_time_val_Object
6802 * PJ Time Val
6803 */
6804typedef struct
6805{
6806 PyObject_HEAD
6807 /* Type-specific fields go here. */
6808 long sec;
6809 long msec;
6810
6811} pj_time_val_Object;
6812
6813
6814
6815/*
6816 * pj_time_val_members
6817 */
6818static PyMemberDef pj_time_val_members[] =
6819{
6820
6821 {
6822 "sec", T_INT,
6823 offsetof(pj_time_val_Object, sec), 0,
6824 "The seconds part of the time"
6825 },
6826 {
6827 "msec", T_INT,
6828 offsetof(pj_time_val_Object, sec), 0,
6829 "The milliseconds fraction of the time"
6830 },
6831
6832
6833 {NULL} /* Sentinel */
6834};
6835
6836
6837
6838
6839/*
6840 * pj_time_val_Type
6841 */
6842static PyTypeObject pj_time_val_Type =
6843{
6844 PyObject_HEAD_INIT(NULL)
6845 0, /*ob_size*/
6846 "py_pjsua.PJ_Time_Val", /*tp_name*/
6847 sizeof(pj_time_val_Object), /*tp_basicsize*/
6848 0, /*tp_itemsize*/
6849 0,/*tp_dealloc*/
6850 0, /*tp_print*/
6851 0, /*tp_getattr*/
6852 0, /*tp_setattr*/
6853 0, /*tp_compare*/
6854 0, /*tp_repr*/
6855 0, /*tp_as_number*/
6856 0, /*tp_as_sequence*/
6857 0, /*tp_as_mapping*/
6858 0, /*tp_hash */
6859 0, /*tp_call*/
6860 0, /*tp_str*/
6861 0, /*tp_getattro*/
6862 0, /*tp_setattro*/
6863 0, /*tp_as_buffer*/
6864 Py_TPFLAGS_DEFAULT, /*tp_flags*/
6865 "PJ Time Val objects", /* tp_doc */
6866 0, /* tp_traverse */
6867 0, /* tp_clear */
6868 0, /* tp_richcompare */
6869 0, /* tp_weaklistoffset */
6870 0, /* tp_iter */
6871 0, /* tp_iternext */
6872 0, /* tp_methods */
6873 pj_time_val_members, /* tp_members */
6874
6875
6876};
6877
6878/*
6879 * call_info_Object
6880 * Call Info
6881 */
6882typedef struct
6883{
6884 PyObject_HEAD
6885 /* Type-specific fields go here. */
6886
6887 int id;
6888 int role;
6889 int acc_id;
6890 PyObject * local_info;
6891 PyObject * local_contact;
6892 PyObject * remote_info;
6893 PyObject * remote_contact;
6894 PyObject * call_id;
6895 int state;
6896 PyObject * state_text;
6897 int last_status;
6898 PyObject * last_status_text;
6899 int media_status;
6900 int media_dir;
6901 int conf_slot;
6902 pj_time_val_Object * connect_duration;
6903 pj_time_val_Object * total_duration;
6904 struct {
6905 char local_info[128];
6906 char local_contact[128];
6907 char remote_info[128];
6908 char remote_contact[128];
6909 char call_id[128];
6910 char last_status_text[128];
6911 } buf_;
6912
6913} call_info_Object;
6914
6915
6916/*
6917 * call_info_dealloc
6918 * deletes a call_info from memory
6919 */
6920static void call_info_dealloc(call_info_Object* self)
6921{
6922 Py_XDECREF(self->local_info);
6923 Py_XDECREF(self->local_contact);
6924 Py_XDECREF(self->remote_info);
6925 Py_XDECREF(self->remote_contact);
6926 Py_XDECREF(self->call_id);
6927 Py_XDECREF(self->state_text);
6928 Py_XDECREF(self->last_status_text);
6929 Py_XDECREF(self->connect_duration);
6930 Py_XDECREF(self->total_duration);
6931 self->ob_type->tp_free((PyObject*)self);
6932}
6933
6934
6935/*
6936 * call_info_new
6937 * constructor for call_info object
6938 */
6939static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
6940 PyObject *kwds)
6941{
6942 call_info_Object *self;
6943
6944 self = (call_info_Object *)type->tp_alloc(type, 0);
6945 if (self != NULL)
6946 {
6947 self->local_info = PyString_FromString("");
6948 if (self->local_info == NULL)
6949 {
6950 Py_DECREF(self);
6951 return NULL;
6952 }
6953 self->local_contact = PyString_FromString("");
6954 if (self->local_contact == NULL)
6955 {
6956 Py_DECREF(self);
6957 return NULL;
6958 }
6959 self->remote_info = PyString_FromString("");
6960 if (self->remote_info == NULL)
6961 {
6962 Py_DECREF(self);
6963 return NULL;
6964 }
6965 self->remote_contact = PyString_FromString("");
6966 if (self->remote_contact == NULL)
6967 {
6968 Py_DECREF(self);
6969 return NULL;
6970 }
6971 self->call_id = PyString_FromString("");
6972 if (self->call_id == NULL)
6973 {
6974 Py_DECREF(self);
6975 return NULL;
6976 }
6977 self->state_text = PyString_FromString("");
6978 if (self->state_text == NULL)
6979 {
6980 Py_DECREF(self);
6981 return NULL;
6982 }
6983 self->last_status_text = PyString_FromString("");
6984 if (self->last_status_text == NULL)
6985 {
6986 Py_DECREF(self);
6987 return NULL;
6988 }
6989 self->connect_duration = (pj_time_val_Object *)PyType_GenericNew
6990 (&pj_time_val_Type,NULL,NULL);
6991 if (self->connect_duration == NULL)
6992 {
6993 Py_DECREF(self);
6994 return NULL;
6995 }
6996 self->total_duration = (pj_time_val_Object *)PyType_GenericNew
6997 (&pj_time_val_Type,NULL,NULL);
6998 if (self->total_duration == NULL)
6999 {
7000 Py_DECREF(self);
7001 return NULL;
7002 }
7003 }
7004 return (PyObject *)self;
7005}
7006
7007/*
7008 * call_info_members
7009 */
7010static PyMemberDef call_info_members[] =
7011{
7012 {
7013 "id", T_INT,
7014 offsetof(call_info_Object, id), 0,
7015 "Call identification"
7016 },
7017 {
7018 "role", T_INT,
7019 offsetof(call_info_Object, role), 0,
7020 "Initial call role (UAC == caller)"
7021 },
7022 {
7023 "acc_id", T_INT,
7024 offsetof(call_info_Object, acc_id), 0,
7025 "The account ID where this call belongs."
7026 },
7027 {
7028 "local_info", T_OBJECT_EX,
7029 offsetof(call_info_Object, local_info), 0,
7030 "Local URI"
7031 },
7032 {
7033 "local_contact", T_OBJECT_EX,
7034 offsetof(call_info_Object, local_contact), 0,
7035 "Local Contact"
7036 },
7037 {
7038 "remote_info", T_OBJECT_EX,
7039 offsetof(call_info_Object, remote_info), 0,
7040 "Remote URI"
7041 },
7042 {
7043 "remote_contact", T_OBJECT_EX,
7044 offsetof(call_info_Object, remote_contact), 0,
7045 "Remote Contact"
7046 },
7047 {
7048 "call_id", T_OBJECT_EX,
7049 offsetof(call_info_Object, call_id), 0,
7050 "Dialog Call-ID string"
7051 },
7052 {
7053 "state", T_INT,
7054 offsetof(call_info_Object, state), 0,
7055 "Call state"
7056 },
7057 {
7058 "state_text", T_OBJECT_EX,
7059 offsetof(call_info_Object, state_text), 0,
7060 "Text describing the state "
7061 },
7062 {
7063 "last_status", T_INT,
7064 offsetof(call_info_Object, last_status), 0,
7065 "Last status code heard, which can be used as cause code"
7066 },
7067 {
7068 "last_status_text", T_OBJECT_EX,
7069 offsetof(call_info_Object, last_status_text), 0,
7070 "The reason phrase describing the status."
7071 },
7072 {
7073 "media_status", T_INT,
7074 offsetof(call_info_Object, media_status), 0,
7075 "Call media status."
7076 },
7077 {
7078 "media_dir", T_INT,
7079 offsetof(call_info_Object, media_dir), 0,
7080 "Media direction"
7081 },
7082 {
7083 "conf_slot", T_INT,
7084 offsetof(call_info_Object, conf_slot), 0,
7085 "The conference port number for the call"
7086 },
7087 {
7088 "connect_duration", T_OBJECT_EX,
7089 offsetof(call_info_Object, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00007090 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00007091 },
7092 {
7093 "total_duration", T_OBJECT_EX,
7094 offsetof(call_info_Object, total_duration), 0,
7095 "Total call duration, including set-up time"
7096 },
7097
7098 {NULL} /* Sentinel */
7099};
7100
7101
7102
7103
7104/*
7105 * call_info_Type
7106 */
7107static PyTypeObject call_info_Type =
7108{
7109 PyObject_HEAD_INIT(NULL)
7110 0, /*ob_size*/
7111 "py_pjsua.Call_Info", /*tp_name*/
7112 sizeof(call_info_Object), /*tp_basicsize*/
7113 0, /*tp_itemsize*/
7114 (destructor)call_info_dealloc,/*tp_dealloc*/
7115 0, /*tp_print*/
7116 0, /*tp_getattr*/
7117 0, /*tp_setattr*/
7118 0, /*tp_compare*/
7119 0, /*tp_repr*/
7120 0, /*tp_as_number*/
7121 0, /*tp_as_sequence*/
7122 0, /*tp_as_mapping*/
7123 0, /*tp_hash */
7124 0, /*tp_call*/
7125 0, /*tp_str*/
7126 0, /*tp_getattro*/
7127 0, /*tp_setattro*/
7128 0, /*tp_as_buffer*/
7129 Py_TPFLAGS_DEFAULT, /*tp_flags*/
7130 "Call Info objects", /* tp_doc */
7131 0, /* tp_traverse */
7132 0, /* tp_clear */
7133 0, /* tp_richcompare */
7134 0, /* tp_weaklistoffset */
7135 0, /* tp_iter */
7136 0, /* tp_iternext */
7137 0, /* tp_methods */
7138 call_info_members, /* tp_members */
7139 0, /* tp_getset */
7140 0, /* tp_base */
7141 0, /* tp_dict */
7142 0, /* tp_descr_get */
7143 0, /* tp_descr_set */
7144 0, /* tp_dictoffset */
7145 0, /* tp_init */
7146 0, /* tp_alloc */
7147 call_info_new, /* tp_new */
7148
7149};
7150
7151/*
7152 * py_pjsua_call_get_max_count
7153 */
7154static PyObject *py_pjsua_call_get_max_count
7155(PyObject *pSelf, PyObject *pArgs)
7156{
7157 int count;
7158
7159 if (!PyArg_ParseTuple(pArgs, ""))
7160 {
7161 return NULL;
7162 }
7163
7164 count = pjsua_call_get_max_count();
7165
7166
7167 return Py_BuildValue("i", count);
7168}
7169
7170/*
7171 * py_pjsua_call_get_count
7172 */
7173static PyObject *py_pjsua_call_get_count
7174(PyObject *pSelf, PyObject *pArgs)
7175{
7176
7177 int count;
7178
7179
7180 if (!PyArg_ParseTuple(pArgs, ""))
7181 {
7182 return NULL;
7183 }
7184
7185 count = pjsua_call_get_count();
7186
7187
7188 return Py_BuildValue("i", count);
7189}
7190
7191/*
7192 * py_pjsua_enum_calls
7193 */
7194static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
7195{
7196 pj_status_t status;
7197 PyObject *list;
7198
7199 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00007200 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00007201 if (!PyArg_ParseTuple(pArgs, ""))
7202 {
7203 return NULL;
7204 }
7205
7206 c = PJ_ARRAY_SIZE(id);
7207 status = pjsua_enum_calls(id, &c);
7208
7209 list = PyList_New(c);
7210 for (i = 0; i < c; i++)
7211 {
7212 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
7213 if (ret == -1)
7214 {
7215 return NULL;
7216 }
7217 }
7218
Fahrisdcf8fa42006-12-28 03:13:48 +00007219 return Py_BuildValue("O",list);
7220}
7221
7222/*
7223 * py_pjsua_call_make_call
7224 */
7225static PyObject *py_pjsua_call_make_call
7226(PyObject *pSelf, PyObject *pArgs)
7227{
7228 int status;
7229 int acc_id;
7230 pj_str_t dst_uri;
7231 PyObject * sd;
7232 unsigned options;
7233 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007234 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007235 msg_data_Object * omd;
7236 int user_data;
7237 int call_id;
7238 pj_pool_t * pool;
7239
Fahris17d91812007-01-29 12:09:33 +00007240 if (!PyArg_ParseTuple
7241 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007242 {
7243 return NULL;
7244 }
7245
7246 dst_uri.ptr = PyString_AsString(sd);
7247 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00007248 if (omdObj != Py_None)
7249 {
7250 omd = (msg_data_Object *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00007251 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7252 msg_data.content_type.slen = strlen
7253 (PyString_AsString(omd->content_type));
7254 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7255 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007256 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007257 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7258 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007259 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00007260 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007261 } else {
Fahris89ea3d02007-02-07 08:18:35 +00007262
Fahris17d91812007-01-29 12:09:33 +00007263 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007264 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007265 }
Fahris89ea3d02007-02-07 08:18:35 +00007266
Fahrisdcf8fa42006-12-28 03:13:48 +00007267 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00007268
Fahrisdcf8fa42006-12-28 03:13:48 +00007269}
7270
7271/*
7272 * py_pjsua_call_is_active
7273 */
7274static PyObject *py_pjsua_call_is_active
7275(PyObject *pSelf, PyObject *pArgs)
7276{
7277 int call_id;
7278 int isActive;
7279
7280
7281 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7282 {
7283 return NULL;
7284 }
7285
7286 isActive = pjsua_call_is_active(call_id);
7287
7288
7289 return Py_BuildValue("i", isActive);
7290}
7291
7292/*
7293 * py_pjsua_call_has_media
7294 */
7295static PyObject *py_pjsua_call_has_media
7296(PyObject *pSelf, PyObject *pArgs)
7297{
7298 int call_id;
7299 int hasMedia;
7300
7301
7302 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7303 {
7304 return NULL;
7305 }
7306
7307 hasMedia = pjsua_call_has_media(call_id);
7308
7309
7310 return Py_BuildValue("i", hasMedia);
7311}
7312
7313/*
7314 * py_pjsua_call_get_conf_port
7315 */
7316static PyObject *py_pjsua_call_get_conf_port
7317(PyObject *pSelf, PyObject *pArgs)
7318{
7319 int call_id;
7320 int port_id;
7321
7322
7323 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7324 {
7325 return NULL;
7326 }
7327
7328 port_id = pjsua_call_get_conf_port(call_id);
7329
7330
7331 return Py_BuildValue("i", port_id);
7332}
7333
7334/*
7335 * py_pjsua_call_get_info
7336 */
7337static PyObject *py_pjsua_call_get_info
7338(PyObject *pSelf, PyObject *pArgs)
7339{
7340 int call_id;
7341 int status;
7342 call_info_Object * oi;
7343 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00007344
7345
7346 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7347 {
7348 return NULL;
7349 }
7350
7351
7352 status = pjsua_call_get_info(call_id, &info);
7353 if (status == PJ_SUCCESS)
7354 {
7355 oi = (call_info_Object *)call_info_new(&call_info_Type, NULL, NULL);
7356 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00007357 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
7358 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
7359 pj_ansi_snprintf(oi->buf_.last_status_text,
7360 sizeof(oi->buf_.last_status_text),
7361 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
7362 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
7363 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
7364 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
7365 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
7366 pj_ansi_snprintf(oi->buf_.remote_contact,
7367 sizeof(oi->buf_.remote_contact),
7368 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
7369 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
7370 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007371
Fahrisdcf8fa42006-12-28 03:13:48 +00007372 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
7373 info.call_id.slen);
7374 oi->conf_slot = info.conf_slot;
7375 oi->connect_duration->sec = info.connect_duration.sec;
7376 oi->connect_duration->msec = info.connect_duration.msec;
7377 oi->total_duration->sec = info.total_duration.sec;
7378 oi->total_duration->msec = info.total_duration.msec;
7379 oi->id = info.id;
7380 oi->last_status = info.last_status;
7381 oi->last_status_text = PyString_FromStringAndSize(
7382 info.last_status_text.ptr, info.last_status_text.slen);
7383 oi->local_contact = PyString_FromStringAndSize(
7384 info.local_contact.ptr, info.local_contact.slen);
7385 oi->local_info = PyString_FromStringAndSize(
7386 info.local_info.ptr, info.local_info.slen);
7387 oi->remote_contact = PyString_FromStringAndSize(
7388 info.remote_contact.ptr, info.remote_contact.slen);
7389 oi->remote_info = PyString_FromStringAndSize(
7390 info.remote_info.ptr, info.remote_info.slen);
7391 oi->media_dir = info.media_dir;
7392 oi->media_status = info.media_status;
7393 oi->role = info.role;
7394 oi->state = info.state;
7395 oi->state_text = PyString_FromStringAndSize(
7396 info.state_text.ptr, info.state_text.slen);
7397
7398 return Py_BuildValue("O", oi);
7399 } else {
7400 Py_INCREF(Py_None);
7401 return Py_None;
7402 }
7403}
7404
7405/*
7406 * py_pjsua_call_set_user_data
7407 */
7408static PyObject *py_pjsua_call_set_user_data
7409(PyObject *pSelf, PyObject *pArgs)
7410{
7411 int call_id;
7412 int user_data;
7413 int status;
7414
7415 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
7416 {
7417 return NULL;
7418 }
7419
Benny Prijonoe6ead542007-01-31 20:53:31 +00007420 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007421
7422
7423 return Py_BuildValue("i", status);
7424}
7425
7426/*
7427 * py_pjsua_call_get_user_data
7428 */
7429static PyObject *py_pjsua_call_get_user_data
7430(PyObject *pSelf, PyObject *pArgs)
7431{
7432 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00007433 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00007434
7435
7436 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7437 {
7438 return NULL;
7439 }
7440
7441 user_data = pjsua_call_get_user_data(call_id);
7442
7443
Benny Prijonoe6ead542007-01-31 20:53:31 +00007444 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007445}
7446
7447/*
7448 * py_pjsua_call_answer
7449 */
7450static PyObject *py_pjsua_call_answer
7451(PyObject *pSelf, PyObject *pArgs)
7452{
7453 int status;
7454 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007455 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007456 PyObject * sr;
7457 unsigned code;
7458 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007459 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007460 msg_data_Object * omd;
7461 pj_pool_t * pool;
7462
Fahris17d91812007-01-29 12:09:33 +00007463 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007464 {
7465 return NULL;
7466 }
Fahris6f35cb82007-02-01 07:41:26 +00007467 if (sr == Py_None)
7468 {
7469 reason = NULL;
7470 } else {
Fahrise314b882007-02-02 10:52:04 +00007471 reason = &tmp_reason;
7472 tmp_reason.ptr = PyString_AsString(sr);
7473 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007474 }
7475 if (omdObj != Py_None)
7476 {
Fahris17d91812007-01-29 12:09:33 +00007477 omd = (msg_data_Object *)omdObj;
7478 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7479 msg_data.content_type.slen = strlen
7480 (PyString_AsString(omd->content_type));
7481 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7482 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007483 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007484 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7485
Fahris6f35cb82007-02-01 07:41:26 +00007486 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007487
Fahris17d91812007-01-29 12:09:33 +00007488 pj_pool_release(pool);
7489 } else {
7490
Fahris89ea3d02007-02-07 08:18:35 +00007491 status = pjsua_call_answer(call_id, code, reason, NULL);
7492
Fahris6f35cb82007-02-01 07:41:26 +00007493 }
Fahrise314b882007-02-02 10:52:04 +00007494
Fahrisdcf8fa42006-12-28 03:13:48 +00007495 return Py_BuildValue("i",status);
7496}
7497
7498/*
7499 * py_pjsua_call_hangup
7500 */
7501static PyObject *py_pjsua_call_hangup
7502(PyObject *pSelf, PyObject *pArgs)
7503{
7504 int status;
7505 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007506 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007507 PyObject * sr;
7508 unsigned code;
7509 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007510 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007511 msg_data_Object * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007512 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00007513
Fahris17d91812007-01-29 12:09:33 +00007514 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007515 {
7516 return NULL;
7517 }
Benny Prijonoaa286042007-02-03 17:23:22 +00007518 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007519 {
7520 reason = NULL;
7521 } else {
Fahrise314b882007-02-02 10:52:04 +00007522 reason = &tmp_reason;
7523 tmp_reason.ptr = PyString_AsString(sr);
7524 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007525 }
7526 if (omdObj != Py_None)
7527 {
Fahris17d91812007-01-29 12:09:33 +00007528 omd = (msg_data_Object *)omdObj;
7529 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7530 msg_data.content_type.slen = strlen
7531 (PyString_AsString(omd->content_type));
7532 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7533 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007534 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007535 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00007536 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00007537 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007538 } else {
Fahris6f35cb82007-02-01 07:41:26 +00007539 status = pjsua_call_hangup(call_id, code, reason, NULL);
7540 }
Fahrise314b882007-02-02 10:52:04 +00007541
Fahrisdcf8fa42006-12-28 03:13:48 +00007542 return Py_BuildValue("i",status);
7543}
7544
7545/*
7546 * py_pjsua_call_set_hold
7547 */
7548static PyObject *py_pjsua_call_set_hold
7549(PyObject *pSelf, PyObject *pArgs)
7550{
7551 int status;
7552 int call_id;
7553 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007554 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007555 msg_data_Object * omd;
7556 pj_pool_t * pool;
7557
Fahris17d91812007-01-29 12:09:33 +00007558 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007559 {
7560 return NULL;
7561 }
Fahris17d91812007-01-29 12:09:33 +00007562
Fahris6f35cb82007-02-01 07:41:26 +00007563 if (omdObj != Py_None)
7564 {
Fahris17d91812007-01-29 12:09:33 +00007565 omd = (msg_data_Object *)omdObj;
7566 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7567 msg_data.content_type.slen = strlen
7568 (PyString_AsString(omd->content_type));
7569 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7570 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007571 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007572 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7573 status = pjsua_call_set_hold(call_id, &msg_data);
7574 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007575 } else {
Fahris17d91812007-01-29 12:09:33 +00007576 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007577 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007578 return Py_BuildValue("i",status);
7579}
7580
7581/*
7582 * py_pjsua_call_reinvite
7583 */
7584static PyObject *py_pjsua_call_reinvite
7585(PyObject *pSelf, PyObject *pArgs)
7586{
7587 int status;
7588 int call_id;
7589 int unhold;
7590 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007591 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007592 msg_data_Object * omd;
7593 pj_pool_t * pool;
7594
Fahris17d91812007-01-29 12:09:33 +00007595 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007596 {
7597 return NULL;
7598 }
Fahris17d91812007-01-29 12:09:33 +00007599
7600 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007601 {
Fahris17d91812007-01-29 12:09:33 +00007602 omd = (msg_data_Object *)omdObj;
7603 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7604 msg_data.content_type.slen = strlen
7605 (PyString_AsString(omd->content_type));
7606 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7607 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007608 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007609 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7610 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
7611 pj_pool_release(pool);
7612 } else {
7613 status = pjsua_call_reinvite(call_id, unhold, NULL);
7614 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007615 return Py_BuildValue("i",status);
7616}
7617
7618/*
7619 * py_pjsua_call_xfer
7620 */
7621static PyObject *py_pjsua_call_xfer
7622(PyObject *pSelf, PyObject *pArgs)
7623{
7624 int status;
7625 int call_id;
7626 pj_str_t dest;
7627 PyObject * sd;
7628 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007629 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007630 msg_data_Object * omd;
7631 pj_pool_t * pool;
7632
Fahris17d91812007-01-29 12:09:33 +00007633 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007634 {
7635 return NULL;
7636 }
7637
7638 dest.ptr = PyString_AsString(sd);
7639 dest.slen = strlen(PyString_AsString(sd));
7640
Fahris17d91812007-01-29 12:09:33 +00007641 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007642 {
Fahris17d91812007-01-29 12:09:33 +00007643 omd = (msg_data_Object *)omdObj;
7644 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7645 msg_data.content_type.slen = strlen
7646 (PyString_AsString(omd->content_type));
7647 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7648 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007649 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007650 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7651 status = pjsua_call_xfer(call_id, &dest, &msg_data);
7652 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007653 } else {
Fahris17d91812007-01-29 12:09:33 +00007654 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007655 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007656 return Py_BuildValue("i",status);
7657}
7658
7659/*
7660 * py_pjsua_call_xfer_replaces
7661 */
7662static PyObject *py_pjsua_call_xfer_replaces
7663(PyObject *pSelf, PyObject *pArgs)
7664{
7665 int status;
7666 int call_id;
7667 int dest_call_id;
7668 unsigned options;
7669 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007670 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007671 msg_data_Object * omd;
7672 pj_pool_t * pool;
7673
Fahris17d91812007-01-29 12:09:33 +00007674 if (!PyArg_ParseTuple
7675 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007676 {
7677 return NULL;
7678 }
7679
Fahris17d91812007-01-29 12:09:33 +00007680 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007681 {
Fahris17d91812007-01-29 12:09:33 +00007682 omd = (msg_data_Object *)omdObj;
7683 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7684 msg_data.content_type.slen = strlen
7685 (PyString_AsString(omd->content_type));
7686 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7687 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007688 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007689 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7690 status = pjsua_call_xfer_replaces
7691 (call_id, dest_call_id, options, &msg_data);
7692 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007693 } else {
Fahris17d91812007-01-29 12:09:33 +00007694 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007695 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007696 return Py_BuildValue("i",status);
7697}
7698
7699/*
7700 * py_pjsua_call_dial_dtmf
7701 */
7702static PyObject *py_pjsua_call_dial_dtmf
7703(PyObject *pSelf, PyObject *pArgs)
7704{
7705 int call_id;
7706 PyObject * sd;
7707 pj_str_t digits;
7708 int status;
7709
7710 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
7711 {
7712 return NULL;
7713 }
7714 digits.ptr = PyString_AsString(sd);
7715 digits.slen = strlen(PyString_AsString(sd));
7716 status = pjsua_call_dial_dtmf(call_id, &digits);
7717
7718 return Py_BuildValue("i", status);
7719}
7720
7721/*
7722 * py_pjsua_call_send_im
7723 */
7724static PyObject *py_pjsua_call_send_im
7725(PyObject *pSelf, PyObject *pArgs)
7726{
7727 int status;
7728 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00007729 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00007730 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00007731 PyObject * sm;
7732 PyObject * sc;
7733 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007734 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007735 msg_data_Object * omd;
7736 int user_data;
7737 pj_pool_t * pool;
7738
Fahris17d91812007-01-29 12:09:33 +00007739 if (!PyArg_ParseTuple
7740 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00007741 {
7742 return NULL;
7743 }
Fahris6f35cb82007-02-01 07:41:26 +00007744 if (sm == Py_None)
7745 {
7746 mime_type = NULL;
7747 } else {
Fahrise314b882007-02-02 10:52:04 +00007748 mime_type = &tmp_mime_type;
7749 tmp_mime_type.ptr = PyString_AsString(sm);
7750 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00007751 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007752 content.ptr = PyString_AsString(sc);
7753 content.slen = strlen(PyString_AsString(sc));
7754
Fahris17d91812007-01-29 12:09:33 +00007755 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007756 {
Fahris17d91812007-01-29 12:09:33 +00007757 omd = (msg_data_Object *)omdObj;
7758 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7759 msg_data.content_type.slen = strlen
7760 (PyString_AsString(omd->content_type));
7761 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7762 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007763 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007764 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7765 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007766 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00007767 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007768 } else {
Fahris17d91812007-01-29 12:09:33 +00007769 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007770 (call_id, mime_type, &content, NULL, (void *)user_data);
7771 }
Fahrise314b882007-02-02 10:52:04 +00007772
Fahrisdcf8fa42006-12-28 03:13:48 +00007773 return Py_BuildValue("i",status);
7774}
7775
7776/*
7777 * py_pjsua_call_send_typing_ind
7778 */
7779static PyObject *py_pjsua_call_send_typing_ind
7780(PyObject *pSelf, PyObject *pArgs)
7781{
7782 int status;
7783 int call_id;
7784 int is_typing;
7785 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007786 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007787 msg_data_Object * omd;
7788 pj_pool_t * pool;
7789
Fahris17d91812007-01-29 12:09:33 +00007790 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007791 {
7792 return NULL;
7793 }
7794
Fahris17d91812007-01-29 12:09:33 +00007795 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007796 {
Fahris17d91812007-01-29 12:09:33 +00007797 omd = (msg_data_Object *)omdObj;
7798 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7799 msg_data.content_type.slen = strlen
7800 (PyString_AsString(omd->content_type));
7801 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7802 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007803 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007804 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7805 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
7806 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007807 } else {
Fahris17d91812007-01-29 12:09:33 +00007808 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007809 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007810 return Py_BuildValue("i",status);
7811}
7812
7813/*
7814 * py_pjsua_call_hangup_all
7815 */
7816static PyObject *py_pjsua_call_hangup_all
7817(PyObject *pSelf, PyObject *pArgs)
7818{
7819
7820 if (!PyArg_ParseTuple(pArgs, ""))
7821 {
7822 return NULL;
7823 }
7824
7825 pjsua_call_hangup_all();
7826
7827 Py_INCREF(Py_None);
7828 return Py_None;
7829}
7830
7831/*
7832 * py_pjsua_call_dump
7833 */
7834static PyObject *py_pjsua_call_dump
7835(PyObject *pSelf, PyObject *pArgs)
7836{
7837 int call_id;
7838 int with_media;
7839 PyObject * sb;
7840 PyObject * si;
7841 char * buffer;
7842 char * indent;
7843 unsigned maxlen;
7844 int status;
7845
7846 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
7847 {
7848 return NULL;
7849 }
7850 buffer = (char *) malloc (maxlen * sizeof(char));
7851 indent = PyString_AsString(si);
7852
7853 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
7854 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00007855 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00007856 return Py_BuildValue("O", sb);
7857}
7858
7859static char pjsua_call_get_max_count_doc[] =
7860 "int py_pjsua.call_get_max_count () "
7861 "Get maximum number of calls configured in pjsua.";
7862static char pjsua_call_get_count_doc[] =
7863 "int py_pjsua.call_get_count () "
7864 "Get number of currently active calls.";
7865static char pjsua_enum_calls_doc[] =
7866 "int[] py_pjsua.enum_calls () "
7867 "Get maximum number of calls configured in pjsua.";
7868static char pjsua_call_make_call_doc[] =
7869 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
7870 "int user_data, py_pjsua.Msg_Data msg_data) "
7871 "Make outgoing call to the specified URI using the specified account.";
7872static char pjsua_call_is_active_doc[] =
7873 "int py_pjsua.call_is_active (int call_id) "
7874 "Check if the specified call has active INVITE session and the INVITE "
7875 "session has not been disconnected.";
7876static char pjsua_call_has_media_doc[] =
7877 "int py_pjsua.call_has_media (int call_id) "
7878 "Check if call has an active media session.";
7879static char pjsua_call_get_conf_port_doc[] =
7880 "int py_pjsua.call_get_conf_port (int call_id) "
7881 "Get the conference port identification associated with the call.";
7882static char pjsua_call_get_info_doc[] =
7883 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
7884 "Obtain detail information about the specified call.";
7885static char pjsua_call_set_user_data_doc[] =
7886 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
7887 "Attach application specific data to the call.";
7888static char pjsua_call_get_user_data_doc[] =
7889 "int py_pjsua.call_get_user_data (int call_id) "
7890 "Get user data attached to the call.";
7891static char pjsua_call_answer_doc[] =
7892 "int py_pjsua.call_answer (int call_id, int code, string reason, "
7893 "py_pjsua.Msg_Data msg_data) "
7894 "Send response to incoming INVITE request.";
7895static char pjsua_call_hangup_doc[] =
7896 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
7897 "py_pjsua.Msg_Data msg_data) "
7898 "Hangup call by using method that is appropriate according "
7899 "to the call state.";
7900static char pjsua_call_set_hold_doc[] =
7901 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
7902 "Put the specified call on hold.";
7903static char pjsua_call_reinvite_doc[] =
7904 "int py_pjsua.call_reinvite (int call_id, int unhold, "
7905 "py_pjsua.Msg_Data msg_data) "
7906 "Send re-INVITE (to release hold).";
7907static char pjsua_call_xfer_doc[] =
7908 "int py_pjsua.call_xfer (int call_id, string dest, "
7909 "py_pjsua.Msg_Data msg_data) "
7910 "Initiate call transfer to the specified address. "
7911 "This function will send REFER request to instruct remote call party "
7912 "to initiate a new INVITE session to the specified destination/target.";
7913static char pjsua_call_xfer_replaces_doc[] =
7914 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
7915 "int options, py_pjsua.Msg_Data msg_data) "
7916 "Initiate attended call transfer. This function will send REFER request "
7917 "to instruct remote call party to initiate new INVITE session to the URL "
7918 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
7919 "with us with the new call from the REFER recipient.";
7920static char pjsua_call_dial_dtmf_doc[] =
7921 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
7922 "Send DTMF digits to remote using RFC 2833 payload formats.";
7923static char pjsua_call_send_im_doc[] =
7924 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
7925 "py_pjsua.Msg_Data msg_data, int user_data) "
7926 "Send instant messaging inside INVITE session.";
7927static char pjsua_call_send_typing_ind_doc[] =
7928 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
7929 "py_pjsua.Msg_Data msg_data) "
7930 "Send IM typing indication inside INVITE session.";
7931static char pjsua_call_hangup_all_doc[] =
7932 "void py_pjsua.call_hangup_all () "
7933 "Terminate all calls.";
7934static char pjsua_call_dump_doc[] =
7935 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
7936 "string indent) "
7937 "Dump call and media statistics to string.";
7938
7939/* END OF LIB CALL */
7940
Benny Prijono572d4852006-11-23 21:50:02 +00007941/*
7942 * Map of function names to functions
7943 */
7944static PyMethodDef py_pjsua_methods[] =
7945{
7946 {
Benny Prijonodc308702006-12-09 00:39:42 +00007947 "thread_register", py_pjsua_thread_register, METH_VARARGS,
7948 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00007949 },
7950 {
Benny Prijono572d4852006-11-23 21:50:02 +00007951 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
7952 },
7953 {
7954 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
7955 },
7956 {
7957 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
7958 },
7959 {
7960 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
7961 },
7962 {
7963 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
7964 },
7965 {
7966 "handle_events", py_pjsua_handle_events, METH_VARARGS,
7967 pjsua_handle_events_doc
7968 },
7969 {
7970 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
7971 pjsua_verify_sip_url_doc
7972 },
7973 {
7974 "pool_create", py_pjsua_pool_create, METH_VARARGS,
7975 pjsua_pool_create_doc
7976 },
7977 {
7978 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
7979 pjsua_get_pjsip_endpt_doc
7980 },
7981 {
7982 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
7983 pjsua_get_pjmedia_endpt_doc
7984 },
7985 {
7986 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
7987 pjsua_get_pool_factory_doc
7988 },
7989 {
7990 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
7991 pjsua_reconfigure_logging_doc
7992 },
7993 {
7994 "logging_config_default", py_pjsua_logging_config_default,
7995 METH_VARARGS, pjsua_logging_config_default_doc
7996 },
7997 {
7998 "config_default", py_pjsua_config_default, METH_VARARGS,
7999 pjsua_config_default_doc
8000 },
8001 {
8002 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
8003 pjsua_media_config_default_doc
8004 },
Benny Prijonodc308702006-12-09 00:39:42 +00008005
8006
Benny Prijono572d4852006-11-23 21:50:02 +00008007 {
8008 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
8009 pjsua_msg_data_init_doc
8010 },
Benny Prijonodc308702006-12-09 00:39:42 +00008011 {
8012 "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS,
8013 pjsua_stun_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008014 },
Benny Prijonodc308702006-12-09 00:39:42 +00008015 {
8016 "transport_config_default", py_pjsua_transport_config_default,
8017 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008018 },
Benny Prijonodc308702006-12-09 00:39:42 +00008019 {
8020 "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS,
8021 pjsua_normalize_stun_config_doc
Benny Prijono98793592006-12-04 08:33:20 +00008022 },
Benny Prijonodc308702006-12-09 00:39:42 +00008023
8024 {
8025 "transport_create", py_pjsua_transport_create, METH_VARARGS,
8026 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00008027 },
Benny Prijonodc308702006-12-09 00:39:42 +00008028 {
8029 "transport_register", py_pjsua_transport_register, METH_VARARGS,
8030 pjsua_transport_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00008031 },
Benny Prijonodc308702006-12-09 00:39:42 +00008032 {
8033 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
8034 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00008035 },
Benny Prijonodc308702006-12-09 00:39:42 +00008036 {
8037 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
8038 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008039 },
Benny Prijonodc308702006-12-09 00:39:42 +00008040 {
8041 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
8042 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00008043 },
Benny Prijonodc308702006-12-09 00:39:42 +00008044 {
8045 "transport_close", py_pjsua_transport_close, METH_VARARGS,
8046 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00008047 },
Benny Prijonodc308702006-12-09 00:39:42 +00008048 {
8049 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
8050 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008051 },
Benny Prijonodc308702006-12-09 00:39:42 +00008052 {
8053 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
8054 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008055 },
Benny Prijonodc308702006-12-09 00:39:42 +00008056 {
8057 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
8058 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00008059 },
Benny Prijonodc308702006-12-09 00:39:42 +00008060 {
8061 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
8062 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008063 },
Benny Prijonodc308702006-12-09 00:39:42 +00008064 {
8065 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
8066 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008067 },
Benny Prijonodc308702006-12-09 00:39:42 +00008068 {
8069 "acc_add", py_pjsua_acc_add, METH_VARARGS,
8070 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00008071 },
Benny Prijonodc308702006-12-09 00:39:42 +00008072 {
8073 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
8074 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00008075 },
Benny Prijonodc308702006-12-09 00:39:42 +00008076 {
8077 "acc_del", py_pjsua_acc_del, METH_VARARGS,
8078 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00008079 },
Benny Prijonodc308702006-12-09 00:39:42 +00008080 {
8081 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
8082 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00008083 },
Benny Prijonodc308702006-12-09 00:39:42 +00008084 {
8085 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
8086 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00008087 },
Benny Prijonodc308702006-12-09 00:39:42 +00008088 {
8089 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
8090 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00008091 },
Benny Prijonodc308702006-12-09 00:39:42 +00008092 {
8093 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
8094 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008095 },
Benny Prijonodc308702006-12-09 00:39:42 +00008096 {
8097 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
8098 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00008099 },
Benny Prijonodc308702006-12-09 00:39:42 +00008100 {
8101 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
8102 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008103 },
Benny Prijonodc308702006-12-09 00:39:42 +00008104 {
8105 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
8106 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00008107 },
Benny Prijonodc308702006-12-09 00:39:42 +00008108 {
8109 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
8110 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00008111 },
Benny Prijonodc308702006-12-09 00:39:42 +00008112 {
8113 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
8114 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008115 },
Benny Prijonodc308702006-12-09 00:39:42 +00008116 {
8117 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
8118 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008119 },
Benny Prijonodc308702006-12-09 00:39:42 +00008120 {
Fahris6f35cb82007-02-01 07:41:26 +00008121 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
8122 pjsua_buddy_config_default_doc
8123 },
8124 {
Benny Prijonodc308702006-12-09 00:39:42 +00008125 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
8126 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008127 },
Benny Prijonodc308702006-12-09 00:39:42 +00008128 {
8129 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
8130 pjsua_buddy_is_valid_doc
8131 },
8132 {
8133 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
8134 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00008135 },
Benny Prijonodc308702006-12-09 00:39:42 +00008136 {
8137 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
8138 pjsua_buddy_get_info_doc
8139 },
8140 {
8141 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
8142 pjsua_buddy_add_doc
8143 },
8144 {
8145 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
8146 pjsua_buddy_del_doc
8147 },
8148 {
8149 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
8150 pjsua_buddy_subscribe_pres_doc
8151 },
8152 {
8153 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
8154 pjsua_pres_dump_doc
8155 },
8156 {
8157 "im_send", py_pjsua_im_send, METH_VARARGS,
8158 pjsua_im_send_doc
8159 },
8160 {
8161 "im_typing", py_pjsua_im_typing, METH_VARARGS,
8162 pjsua_im_typing_doc
8163 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008164 {
8165 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
8166 pjsua_conf_get_max_ports_doc
8167 },
8168 {
8169 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
8170 pjsua_conf_get_active_ports_doc
8171 },
8172 {
8173 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
8174 pjsua_enum_conf_ports_doc
8175 },
8176 {
8177 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
8178 pjsua_conf_get_port_info_doc
8179 },
8180 {
8181 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
8182 pjsua_conf_add_port_doc
8183 },
8184 {
8185 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
8186 pjsua_conf_remove_port_doc
8187 },
8188 {
8189 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
8190 pjsua_conf_connect_doc
8191 },
8192 {
8193 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
8194 pjsua_conf_disconnect_doc
8195 },
8196 {
8197 "player_create", py_pjsua_player_create, METH_VARARGS,
8198 pjsua_player_create_doc
8199 },
8200 {
8201 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
8202 pjsua_player_get_conf_port_doc
8203 },
8204 {
8205 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
8206 pjsua_player_set_pos_doc
8207 },
8208 {
8209 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
8210 pjsua_player_destroy_doc
8211 },
8212 {
8213 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
8214 pjsua_recorder_create_doc
8215 },
8216 {
8217 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
8218 pjsua_recorder_get_conf_port_doc
8219 },
8220 {
8221 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
8222 pjsua_recorder_destroy_doc
8223 },
8224 {
8225 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
8226 pjsua_enum_snd_devs_doc
8227 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00008228 {
Fahrisdcf8fa42006-12-28 03:13:48 +00008229 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
8230 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00008231 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008232 {
8233 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
8234 pjsua_set_snd_dev_doc
8235 },
8236 {
8237 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
8238 pjsua_set_null_snd_dev_doc
8239 },
8240 {
8241 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
8242 pjsua_set_no_snd_dev_doc
8243 },
8244 {
8245 "set_ec", py_pjsua_set_ec, METH_VARARGS,
8246 pjsua_set_ec_doc
8247 },
8248 {
8249 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
8250 pjsua_get_ec_tail_doc
8251 },
8252 {
8253 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
8254 pjsua_enum_codecs_doc
8255 },
8256 {
8257 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
8258 pjsua_codec_set_priority_doc
8259 },
8260 {
8261 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
8262 pjsua_codec_get_param_doc
8263 },
8264 {
8265 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
8266 pjsua_codec_set_param_doc
8267 },
8268 {
8269 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
8270 pjsua_call_get_max_count_doc
8271 },
8272 {
8273 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
8274 pjsua_call_get_count_doc
8275 },
8276 {
8277 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
8278 pjsua_enum_calls_doc
8279 },
8280 {
8281 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
8282 pjsua_call_make_call_doc
8283 },
8284 {
8285 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
8286 pjsua_call_is_active_doc
8287 },
8288 {
8289 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
8290 pjsua_call_has_media_doc
8291 },
8292 {
8293 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
8294 pjsua_call_get_conf_port_doc
8295 },
8296 {
8297 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
8298 pjsua_call_get_info_doc
8299 },
8300 {
8301 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
8302 pjsua_call_set_user_data_doc
8303 },
8304 {
8305 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
8306 pjsua_call_get_user_data_doc
8307 },
8308 {
8309 "call_answer", py_pjsua_call_answer, METH_VARARGS,
8310 pjsua_call_answer_doc
8311 },
8312 {
8313 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
8314 pjsua_call_hangup_doc
8315 },
8316 {
8317 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
8318 pjsua_call_set_hold_doc
8319 },
8320 {
8321 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
8322 pjsua_call_reinvite_doc
8323 },
8324 {
8325 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
8326 pjsua_call_xfer_doc
8327 },
8328 {
8329 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
8330 pjsua_call_xfer_replaces_doc
8331 },
8332 {
8333 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
8334 pjsua_call_dial_dtmf_doc
8335 },
8336 {
8337 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
8338 pjsua_call_send_im_doc
8339 },
8340 {
8341 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
8342 pjsua_call_send_typing_ind_doc
8343 },
8344 {
8345 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
8346 pjsua_call_hangup_all_doc
8347 },
8348 {
8349 "call_dump", py_pjsua_call_dump, METH_VARARGS,
8350 pjsua_call_dump_doc
8351 },
8352
8353
Benny Prijonodc308702006-12-09 00:39:42 +00008354
Benny Prijono572d4852006-11-23 21:50:02 +00008355 {NULL, NULL} /* end of function list */
8356};
8357
8358
8359
8360/*
8361 * Mapping C structs from and to Python objects & initializing object
8362 */
8363DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00008364initpy_pjsua(void)
8365{
Benny Prijono572d4852006-11-23 21:50:02 +00008366 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00008367#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00008368
Benny Prijonodc308702006-12-09 00:39:42 +00008369
Benny Prijono572d4852006-11-23 21:50:02 +00008370 if (PyType_Ready(&callback_Type) < 0)
8371 return;
8372 if (PyType_Ready(&config_Type) < 0)
8373 return;
8374 if (PyType_Ready(&logging_config_Type) < 0)
8375 return;
8376 if (PyType_Ready(&msg_data_Type) < 0)
8377 return;
8378 media_config_Type.tp_new = PyType_GenericNew;
8379 if (PyType_Ready(&media_config_Type) < 0)
8380 return;
8381 pjsip_event_Type.tp_new = PyType_GenericNew;
8382 if (PyType_Ready(&pjsip_event_Type) < 0)
8383 return;
8384 pjsip_rx_data_Type.tp_new = PyType_GenericNew;
8385 if (PyType_Ready(&pjsip_rx_data_Type) < 0)
8386 return;
8387 pj_pool_Type.tp_new = PyType_GenericNew;
8388 if (PyType_Ready(&pj_pool_Type) < 0)
8389 return;
8390 pjsip_endpoint_Type.tp_new = PyType_GenericNew;
8391 if (PyType_Ready(&pjsip_endpoint_Type) < 0)
8392 return;
8393 pjmedia_endpt_Type.tp_new = PyType_GenericNew;
8394 if (PyType_Ready(&pjmedia_endpt_Type) < 0)
8395 return;
8396 pj_pool_factory_Type.tp_new = PyType_GenericNew;
8397 if (PyType_Ready(&pj_pool_factory_Type) < 0)
8398 return;
8399 pjsip_cred_info_Type.tp_new = PyType_GenericNew;
8400 if (PyType_Ready(&pjsip_cred_info_Type) < 0)
8401 return;
8402
Benny Prijonodc308702006-12-09 00:39:42 +00008403 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008404
Benny Prijonodc308702006-12-09 00:39:42 +00008405 if (PyType_Ready(&stun_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008406 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008407 if (PyType_Ready(&transport_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008408 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008409 if (PyType_Ready(&sockaddr_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008410 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008411 if (PyType_Ready(&host_port_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008412 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008413
8414 if (PyType_Ready(&transport_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008415 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008416
8417 pjsip_transport_Type.tp_new = PyType_GenericNew;
Benny Prijono98793592006-12-04 08:33:20 +00008418 if (PyType_Ready(&pjsip_transport_Type) < 0)
8419 return;
8420
Benny Prijonodc308702006-12-09 00:39:42 +00008421 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008422
Benny Prijonodc308702006-12-09 00:39:42 +00008423 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008424
Benny Prijonodc308702006-12-09 00:39:42 +00008425
8426 if (PyType_Ready(&acc_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008427 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008428 if (PyType_Ready(&acc_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008429 return;
8430
Benny Prijonodc308702006-12-09 00:39:42 +00008431 /* END OF LIB ACCOUNT */
8432
8433 /* LIB BUDDY */
8434
8435 if (PyType_Ready(&buddy_config_Type) < 0)
8436 return;
8437 if (PyType_Ready(&buddy_info_Type) < 0)
8438 return;
8439
8440 /* END OF LIB BUDDY */
8441
Fahrisdcf8fa42006-12-28 03:13:48 +00008442 /* LIB MEDIA */
8443
8444 if (PyType_Ready(&codec_info_Type) < 0)
8445 return;
8446
8447 if (PyType_Ready(&conf_port_info_Type) < 0)
8448 return;
8449
8450 pjmedia_port_Type.tp_new = PyType_GenericNew;
8451 if (PyType_Ready(&pjmedia_port_Type) < 0)
8452 return;
8453
8454 if (PyType_Ready(&pjmedia_snd_dev_info_Type) < 0)
8455 return;
8456
8457 pjmedia_codec_param_info_Type.tp_new = PyType_GenericNew;
8458 if (PyType_Ready(&pjmedia_codec_param_info_Type) < 0)
8459 return;
8460 pjmedia_codec_param_setting_Type.tp_new = PyType_GenericNew;
8461 if (PyType_Ready(&pjmedia_codec_param_setting_Type) < 0)
8462 return;
8463
8464 if (PyType_Ready(&pjmedia_codec_param_Type) < 0)
8465 return;
8466
8467 /* END OF LIB MEDIA */
8468
8469 /* LIB CALL */
8470
8471 pj_time_val_Type.tp_new = PyType_GenericNew;
8472 if (PyType_Ready(&pj_time_val_Type) < 0)
8473 return;
8474
8475 if (PyType_Ready(&call_info_Type) < 0)
8476 return;
8477
8478 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00008479
Benny Prijono572d4852006-11-23 21:50:02 +00008480 m = Py_InitModule3(
8481 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
8482 );
8483
8484 Py_INCREF(&callback_Type);
8485 PyModule_AddObject(m, "Callback", (PyObject *)&callback_Type);
8486
8487 Py_INCREF(&config_Type);
8488 PyModule_AddObject(m, "Config", (PyObject *)&config_Type);
8489
8490 Py_INCREF(&media_config_Type);
8491 PyModule_AddObject(m, "Media_Config", (PyObject *)&media_config_Type);
8492
8493 Py_INCREF(&logging_config_Type);
8494 PyModule_AddObject(m, "Logging_Config", (PyObject *)&logging_config_Type);
8495
8496 Py_INCREF(&msg_data_Type);
8497 PyModule_AddObject(m, "Msg_Data", (PyObject *)&msg_data_Type);
8498
8499 Py_INCREF(&pjsip_event_Type);
8500 PyModule_AddObject(m, "PJSIP_Event", (PyObject *)&pjsip_event_Type);
8501
8502 Py_INCREF(&pjsip_rx_data_Type);
8503 PyModule_AddObject(m, "PJSIP_RX_Data", (PyObject *)&pjsip_rx_data_Type);
8504
8505 Py_INCREF(&pj_pool_Type);
8506 PyModule_AddObject(m, "PJ_Pool", (PyObject *)&pj_pool_Type);
8507
8508 Py_INCREF(&pjsip_endpoint_Type);
8509 PyModule_AddObject(m, "PJSIP_Endpoint", (PyObject *)&pjsip_endpoint_Type);
8510
8511 Py_INCREF(&pjmedia_endpt_Type);
8512 PyModule_AddObject(m, "PJMedia_Endpt", (PyObject *)&pjmedia_endpt_Type);
8513
8514 Py_INCREF(&pj_pool_factory_Type);
8515 PyModule_AddObject(
8516 m, "PJ_Pool_Factory", (PyObject *)&pj_pool_factory_Type
8517 );
8518
8519 Py_INCREF(&pjsip_cred_info_Type);
8520 PyModule_AddObject(m, "PJSIP_Cred_Info",
8521 (PyObject *)&pjsip_cred_info_Type
8522 );
8523
Benny Prijonodc308702006-12-09 00:39:42 +00008524 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008525
Benny Prijonodc308702006-12-09 00:39:42 +00008526 Py_INCREF(&stun_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008527 PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008528 Py_INCREF(&transport_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008529 PyModule_AddObject
Benny Prijonodc308702006-12-09 00:39:42 +00008530 (m, "Transport_Config", (PyObject *)&transport_config_Type);
8531 Py_INCREF(&sockaddr_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008532 PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008533 Py_INCREF(&host_port_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008534 PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008535
8536 Py_INCREF(&transport_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008537 PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008538
8539 Py_INCREF(&pjsip_transport_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008540 PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type);
8541
Benny Prijonodc308702006-12-09 00:39:42 +00008542 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008543
Benny Prijonodc308702006-12-09 00:39:42 +00008544 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008545
Benny Prijonodc308702006-12-09 00:39:42 +00008546
8547 Py_INCREF(&acc_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008548 PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008549 Py_INCREF(&acc_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008550 PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type);
8551
Benny Prijonodc308702006-12-09 00:39:42 +00008552 /* END OF LIB ACCOUNT */
8553
8554 /* LIB BUDDY */
8555
8556 Py_INCREF(&buddy_config_Type);
8557 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&buddy_config_Type);
8558 Py_INCREF(&buddy_info_Type);
8559 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&buddy_info_Type);
8560
8561 /* END OF LIB BUDDY */
8562
Fahrisdcf8fa42006-12-28 03:13:48 +00008563 /* LIB MEDIA */
8564
8565 Py_INCREF(&codec_info_Type);
8566 PyModule_AddObject(m, "Codec_Info", (PyObject *)&codec_info_Type);
8567 Py_INCREF(&conf_port_info_Type);
8568 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&conf_port_info_Type);
8569 Py_INCREF(&pjmedia_port_Type);
8570 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&pjmedia_port_Type);
8571 Py_INCREF(&pjmedia_snd_dev_info_Type);
8572 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
8573 (PyObject *)&pjmedia_snd_dev_info_Type);
8574 Py_INCREF(&pjmedia_codec_param_info_Type);
8575 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
8576 (PyObject *)&pjmedia_codec_param_info_Type);
8577 Py_INCREF(&pjmedia_codec_param_setting_Type);
8578 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
8579 (PyObject *)&pjmedia_codec_param_setting_Type);
8580 Py_INCREF(&pjmedia_codec_param_Type);
8581 PyModule_AddObject(m, "PJMedia_Codec_Param",
8582 (PyObject *)&pjmedia_codec_param_Type);
8583
8584 /* END OF LIB MEDIA */
8585
8586 /* LIB CALL */
8587
8588 Py_INCREF(&pj_time_val_Type);
8589 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&pj_time_val_Type);
8590
8591 Py_INCREF(&call_info_Type);
8592 PyModule_AddObject(m, "Call_Info", (PyObject *)&call_info_Type);
8593
8594 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00008595
Benny Prijonodc308702006-12-09 00:39:42 +00008596
Fahrisdcf8fa42006-12-28 03:13:48 +00008597 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00008598 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00008599 */
Benny Prijonodc308702006-12-09 00:39:42 +00008600
Benny Prijonoaa286042007-02-03 17:23:22 +00008601 /* Call states */
8602 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
8603 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
8604 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
8605 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
8606 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
8607 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
8608 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00008609
Benny Prijonoaa286042007-02-03 17:23:22 +00008610 /* Call media status (enum pjsua_call_media_status) */
8611 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
8612 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
8613 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
8614 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00008615
Benny Prijonoaa286042007-02-03 17:23:22 +00008616 /* Buddy status */
8617 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
8618 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
8619 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00008620
Benny Prijonoaa286042007-02-03 17:23:22 +00008621 /* PJSIP transport types (enum pjsip_transport_type_e) */
8622 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
8623 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
8624 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
8625 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
8626 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
8627 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
8628 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00008629
Fahrisdcf8fa42006-12-28 03:13:48 +00008630
Benny Prijonoaa286042007-02-03 17:23:22 +00008631 /* Invalid IDs */
8632 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00008633
Fahrisdcf8fa42006-12-28 03:13:48 +00008634
Benny Prijonoaa286042007-02-03 17:23:22 +00008635 /* Various compile time constants */
8636 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
8637 ADD_CONSTANT(m, PJSUA_MAX_ACC);
8638 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
8639 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
8640 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
8641 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
8642 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
8643 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
8644 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
8645 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
8646 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
8647 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
8648 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00008649
Fahrisdcf8fa42006-12-28 03:13:48 +00008650
Benny Prijonoaa286042007-02-03 17:23:22 +00008651#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00008652}