blob: cb370f1e5a1d160485a78d1902ad595f0f08ef8b [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;
Benny Prijono40d2cc72007-02-14 01:45:08 +00003133 pjsua_stun_config cfg;
Benny Prijono98793592006-12-04 08:33:20 +00003134
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 }
Benny Prijono40d2cc72007-02-14 01:45:08 +00003139
3140 if (tmpObj == Py_None) {
3141 Py_INCREF(Py_None);
3142 return Py_None;
Fahris6f35cb82007-02-01 07:41:26 +00003143 }
Benny Prijono40d2cc72007-02-14 01:45:08 +00003144
3145 obj = (stun_config_Object *) tmpObj;
3146 cfg.stun_port1 = obj->stun_port1;
3147 cfg.stun_port2 = obj->stun_port2;
3148 cfg.stun_srv1.ptr = PyString_AsString(obj->stun_srv1);
3149 cfg.stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1));
3150 cfg.stun_srv2.ptr = PyString_AsString(obj->stun_srv2);
3151 cfg.stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2));
3152
3153 pjsua_normalize_stun_config(&cfg);
3154 obj->stun_port1 = cfg.stun_port1;
3155 obj->stun_port2 = cfg.stun_port2;
Benny Prijonodc308702006-12-09 00:39:42 +00003156 Py_XDECREF(obj->stun_srv1);
Benny Prijono98793592006-12-04 08:33:20 +00003157 obj->stun_srv1 =
Benny Prijono40d2cc72007-02-14 01:45:08 +00003158 PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen);
Benny Prijonodc308702006-12-09 00:39:42 +00003159 Py_XDECREF(obj->stun_srv2);
3160 obj->stun_srv2 =
Benny Prijono40d2cc72007-02-14 01:45:08 +00003161 PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen);
3162
Benny Prijono98793592006-12-04 08:33:20 +00003163 Py_INCREF(Py_None);
3164 return Py_None;
3165}
3166
3167/*
3168 * py_pjsua_transport_create
Benny Prijonodc308702006-12-09 00:39:42 +00003169 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003170 */
3171static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
3172{
3173 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003174 int type;
3175
Fahris6f35cb82007-02-01 07:41:26 +00003176 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003177 transport_config_Object *obj;
3178 pjsua_transport_config cfg;
3179 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003180 if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003181 {
3182 return NULL;
3183 }
Fahris6f35cb82007-02-01 07:41:26 +00003184 if (tmpObj != Py_None)
3185 {
Fahris17d91812007-01-29 12:09:33 +00003186 obj = (transport_config_Object *)tmpObj;
3187 cfg.public_addr.ptr = PyString_AsString(obj->public_addr);
3188 cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr));
3189 cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr);
3190 cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr));
3191 cfg.port = obj->port;
3192 cfg.use_stun = obj->use_stun;
3193 cfg.stun_config.stun_port1 = obj->stun_config->stun_port1;
3194 cfg.stun_config.stun_port2 = obj->stun_config->stun_port2;
3195 cfg.stun_config.stun_srv1.ptr =
3196 PyString_AsString(obj->stun_config->stun_srv1);
3197 cfg.stun_config.stun_srv1.slen =
3198 strlen(PyString_AsString(obj->stun_config->stun_srv1));
3199 cfg.stun_config.stun_srv2.ptr =
3200 PyString_AsString(obj->stun_config->stun_srv2);
3201 cfg.stun_config.stun_srv2.slen =
3202 strlen(PyString_AsString(obj->stun_config->stun_srv2));
3203 status = pjsua_transport_create(type, &cfg, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003204 } else {
Fahris17d91812007-01-29 12:09:33 +00003205 status = pjsua_transport_create(type, NULL, &id);
Fahris6f35cb82007-02-01 07:41:26 +00003206 }
Benny Prijonodc308702006-12-09 00:39:42 +00003207
3208
3209 return Py_BuildValue("ii",status,id);
Benny Prijono98793592006-12-04 08:33:20 +00003210}
3211
3212/*
3213 * py_pjsua_transport_register
Benny Prijonodc308702006-12-09 00:39:42 +00003214 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003215 */
3216static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs)
3217{
Benny Prijonodc308702006-12-09 00:39:42 +00003218 pj_status_t status;
Fahris6f35cb82007-02-01 07:41:26 +00003219 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003220 pjsip_transport_Object *obj;
3221 pjsua_transport_id id;
Fahris17d91812007-01-29 12:09:33 +00003222 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00003223 {
3224 return NULL;
3225 }
Fahris17d91812007-01-29 12:09:33 +00003226 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003227 {
Fahris17d91812007-01-29 12:09:33 +00003228 obj = (pjsip_transport_Object *)tmpObj;
3229 status = pjsua_transport_register(obj->tp, &id);
3230 } else {
3231 status = pjsua_transport_register(NULL, &id);
3232 }
Benny Prijonodc308702006-12-09 00:39:42 +00003233
3234 return Py_BuildValue("ii",status, id);
Benny Prijono98793592006-12-04 08:33:20 +00003235}
3236
3237/*
3238 * py_pjsua_enum_transports
Fahrisdcf8fa42006-12-28 03:13:48 +00003239 * !modified @ 261206
Benny Prijono98793592006-12-04 08:33:20 +00003240 */
3241static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
3242{
3243 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003244 PyObject *list;
3245
Fahrisdcf8fa42006-12-28 03:13:48 +00003246 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
Fahris17d91812007-01-29 12:09:33 +00003247 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00003248 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003249 {
3250 return NULL;
3251 }
Benny Prijonodc308702006-12-09 00:39:42 +00003252
Fahrisdcf8fa42006-12-28 03:13:48 +00003253 c = PJ_ARRAY_SIZE(id);
Benny Prijono98793592006-12-04 08:33:20 +00003254 status = pjsua_enum_transports(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00003255
3256 list = PyList_New(c);
3257 for (i = 0; i < c; i++)
3258 {
3259 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
3260 if (ret == -1)
3261 {
3262 return NULL;
3263 }
3264 }
3265
Benny Prijonodc308702006-12-09 00:39:42 +00003266 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00003267}
3268
3269/*
3270 * py_pjsua_transport_get_info
Benny Prijonodc308702006-12-09 00:39:42 +00003271 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003272 */
3273static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
3274{
3275 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003276 int id;
3277 transport_info_Object *obj;
3278 pjsua_transport_info info;
3279
Benny Prijono98793592006-12-04 08:33:20 +00003280
Benny Prijonodc308702006-12-09 00:39:42 +00003281 if (!PyArg_ParseTuple(pArgs, "i", &id))
Benny Prijono98793592006-12-04 08:33:20 +00003282 {
3283 return NULL;
3284 }
Benny Prijonodc308702006-12-09 00:39:42 +00003285
Benny Prijono98793592006-12-04 08:33:20 +00003286 status = pjsua_transport_get_info(id, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00003287 if (status == PJ_SUCCESS) {
3288 obj = (transport_info_Object *) transport_info_new
3289 (&transport_info_Type,NULL,NULL);
3290 obj->addr_len = info.addr_len;
3291 obj->flag = info.flag;
3292 obj->id = info.id;
3293 obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen);
3294 obj->local_addr->sa_data =
3295 PyString_FromStringAndSize(info.local_addr.sa_data, 14);
Benny Prijono98793592006-12-04 08:33:20 +00003296#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
Benny Prijonodc308702006-12-09 00:39:42 +00003297 obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len;
3298 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003299#else
Benny Prijonodc308702006-12-09 00:39:42 +00003300 obj->local_addr->sa_family = info.local_addr.sa_family;
Benny Prijono98793592006-12-04 08:33:20 +00003301#endif
Benny Prijonodc308702006-12-09 00:39:42 +00003302 return Py_BuildValue("O", obj);
3303 } else {
3304 Py_INCREF(Py_None);
3305 return Py_None;
3306 }
Benny Prijono98793592006-12-04 08:33:20 +00003307}
3308
3309/*
3310 * py_pjsua_transport_set_enable
3311 */
3312static PyObject *py_pjsua_transport_set_enable
3313(PyObject *pSelf, PyObject *pArgs)
3314{
3315 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003316 int id;
3317 int enabled;
Benny Prijono98793592006-12-04 08:33:20 +00003318 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled))
3319 {
3320 return NULL;
3321 }
3322 status = pjsua_transport_set_enable(id, enabled);
Fahris89ea3d02007-02-07 08:18:35 +00003323
Benny Prijono98793592006-12-04 08:33:20 +00003324 return Py_BuildValue("i",status);
3325}
3326
3327/*
3328 * py_pjsua_transport_close
3329 */
3330static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
3331{
3332 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00003333 int id;
3334 int force;
Benny Prijono98793592006-12-04 08:33:20 +00003335 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force))
3336 {
3337 return NULL;
3338 }
3339 status = pjsua_transport_close(id, force);
Fahris89ea3d02007-02-07 08:18:35 +00003340
Benny Prijono98793592006-12-04 08:33:20 +00003341 return Py_BuildValue("i",status);
3342}
3343
3344static char pjsua_stun_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003345 "py_pjsua.STUN_Config py_pjsua.stun_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00003346 "Call this function to initialize STUN config with default values.";
3347static char pjsua_transport_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003348 "py_pjsua.Transport_Config py_pjsua.transport_config_default () "
3349 "Call this function to initialize UDP config with default values.";
Benny Prijono98793592006-12-04 08:33:20 +00003350static char pjsua_normalize_stun_config_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003351 "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) "
3352 "Normalize STUN config. ";
Benny Prijono98793592006-12-04 08:33:20 +00003353static char pjsua_transport_create_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003354 "int, int py_pjsua.transport_create (int type, "
3355 "py_pjsua.Transport_Config cfg) "
3356 "Create SIP transport.";
Benny Prijono98793592006-12-04 08:33:20 +00003357static char pjsua_transport_register_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003358 "int, int py_pjsua.transport_register "
3359 "(py_pjsua.PJSIP_Transport tp) "
3360 "Register transport that has been created by application.";
Benny Prijono98793592006-12-04 08:33:20 +00003361static char pjsua_enum_transports_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00003362 "int[] py_pjsua.enum_transports () "
Benny Prijonodc308702006-12-09 00:39:42 +00003363 "Enumerate all transports currently created in the system.";
Benny Prijono98793592006-12-04 08:33:20 +00003364static char pjsua_transport_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003365 "void py_pjsua.transport_get_info "
3366 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) "
3367 "Get information about transports.";
Benny Prijono98793592006-12-04 08:33:20 +00003368static char pjsua_transport_set_enable_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003369 "void py_pjsua.transport_set_enable "
3370 "(py_pjsua.Transport_ID id, int enabled) "
3371 "Disable a transport or re-enable it. "
3372 "By default transport is always enabled after it is created. "
3373 "Disabling a transport does not necessarily close the socket, "
3374 "it will only discard incoming messages and prevent the transport "
3375 "from being used to send outgoing messages.";
Benny Prijono98793592006-12-04 08:33:20 +00003376static char pjsua_transport_close_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00003377 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) "
3378 "Close the transport. If transport is forcefully closed, "
3379 "it will be immediately closed, and any pending transactions "
3380 "that are using the transport may not terminate properly. "
3381 "Otherwise, the system will wait until all transactions are closed "
3382 "while preventing new users from using the transport, and will close "
3383 "the transport when it is safe to do so.";
Benny Prijono98793592006-12-04 08:33:20 +00003384
3385/* END OF LIB TRANSPORT */
3386
3387/* LIB ACCOUNT */
3388
3389/*
3390 * acc_config_Object
3391 * Acc Config
3392 */
3393typedef struct
3394{
3395 PyObject_HEAD
3396 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003397 int priority;
3398 PyObject * id;
3399 PyObject * reg_uri;
3400 int publish_enabled;
3401 PyObject * force_contact;
3402 unsigned proxy_cnt;
3403 /*pj_str_t proxy[8];*/
3404 PyListObject * proxy;
3405 unsigned reg_timeout;
3406 unsigned cred_count;
3407 /*pjsip_cred_info cred_info[8];*/
3408 PyListObject * cred_info;
Benny Prijono98793592006-12-04 08:33:20 +00003409} acc_config_Object;
3410
3411
3412/*
3413 * acc_config_dealloc
3414 * deletes a acc_config from memory
3415 */
3416static void acc_config_dealloc(acc_config_Object* self)
3417{
3418 Py_XDECREF(self->id);
Benny Prijonodc308702006-12-09 00:39:42 +00003419 Py_XDECREF(self->reg_uri);
3420 Py_XDECREF(self->force_contact);
3421 Py_XDECREF(self->proxy);
3422 Py_XDECREF(self->cred_info);
Benny Prijono98793592006-12-04 08:33:20 +00003423 self->ob_type->tp_free((PyObject*)self);
3424}
3425
3426
3427/*
3428 * acc_config_new
3429 * constructor for acc_config object
3430 */
3431static PyObject * acc_config_new(PyTypeObject *type, PyObject *args,
3432 PyObject *kwds)
3433{
3434 acc_config_Object *self;
3435
3436 self = (acc_config_Object *)type->tp_alloc(type, 0);
3437 if (self != NULL)
3438 {
Benny Prijonodc308702006-12-09 00:39:42 +00003439 self->id = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003440 if (self->id == NULL)
3441 {
3442 Py_DECREF(self);
3443 return NULL;
3444 }
Benny Prijonodc308702006-12-09 00:39:42 +00003445 self->reg_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003446 if (self->reg_uri == NULL)
3447 {
3448 Py_DECREF(self);
3449 return NULL;
3450 }
3451 self->force_contact = PyString_FromString("");
3452 if (self->force_contact == NULL)
3453 {
3454 Py_DECREF(self);
3455 return NULL;
3456 }
Benny Prijonodc308702006-12-09 00:39:42 +00003457 self->proxy = (PyListObject *)PyList_New(8);
3458 if (self->proxy == NULL)
3459 {
3460 Py_DECREF(self);
3461 return NULL;
3462 }
3463 self->cred_info = (PyListObject *)PyList_New(8);
3464 if (self->cred_info == NULL)
3465 {
3466 Py_DECREF(self);
3467 return NULL;
3468 }
Benny Prijono98793592006-12-04 08:33:20 +00003469 }
3470
3471 return (PyObject *)self;
3472}
3473
Benny Prijono98793592006-12-04 08:33:20 +00003474
3475
3476/*
3477 * acc_config_members
3478 */
3479static PyMemberDef acc_config_members[] =
3480{
Benny Prijonodc308702006-12-09 00:39:42 +00003481 {
3482 "priority", T_INT, offsetof(acc_config_Object, priority), 0,
3483 "Account priority, which is used to control the order of matching "
3484 "incoming/outgoing requests. The higher the number means the higher "
3485 "the priority is, and the account will be matched first. "
Benny Prijono98793592006-12-04 08:33:20 +00003486 },
Benny Prijonodc308702006-12-09 00:39:42 +00003487 {
3488 "id", T_OBJECT_EX,
3489 offsetof(acc_config_Object, id), 0,
3490 "The full SIP URL for the account. "
3491 "The value can take name address or URL format, "
3492 "and will look something like 'sip:account@serviceprovider'. "
3493 "This field is mandatory."
Benny Prijono98793592006-12-04 08:33:20 +00003494 },
Benny Prijonodc308702006-12-09 00:39:42 +00003495 {
3496 "reg_uri", T_OBJECT_EX,
3497 offsetof(acc_config_Object, reg_uri), 0,
3498 "This is the URL to be put in the request URI for the registration, "
3499 "and will look something like 'sip:serviceprovider'. "
3500 "This field should be specified if registration is desired. "
3501 "If the value is empty, no account registration will be performed. "
Benny Prijono98793592006-12-04 08:33:20 +00003502 },
Benny Prijonodc308702006-12-09 00:39:42 +00003503 {
3504 "publish_enabled", T_INT,
3505 offsetof(acc_config_Object, publish_enabled), 0,
3506 "Publish presence? "
Benny Prijono98793592006-12-04 08:33:20 +00003507 },
Benny Prijonodc308702006-12-09 00:39:42 +00003508 {
3509 "force_contact", T_OBJECT_EX,
3510 offsetof(acc_config_Object, force_contact), 0,
3511 "Optional URI to be put as Contact for this account. "
3512 "It is recommended that this field is left empty, "
3513 "so that the value will be calculated automatically "
3514 "based on the transport address. "
Benny Prijono98793592006-12-04 08:33:20 +00003515 },
Benny Prijonodc308702006-12-09 00:39:42 +00003516 {
3517 "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0,
3518 "Number of proxies in the proxy array below. "
Benny Prijono98793592006-12-04 08:33:20 +00003519 },
Benny Prijonodc308702006-12-09 00:39:42 +00003520 {
3521 "proxy", T_OBJECT_EX,
3522 offsetof(acc_config_Object, proxy), 0,
3523 "Optional URI of the proxies to be visited for all outgoing requests "
3524 "that are using this account (REGISTER, INVITE, etc). Application need "
3525 "to specify these proxies if the service provider requires "
3526 "that requests destined towards its network should go through certain "
3527 "proxies first (for example, border controllers)."
Benny Prijono98793592006-12-04 08:33:20 +00003528 },
Benny Prijonodc308702006-12-09 00:39:42 +00003529 {
3530 "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0,
3531 "Optional interval for registration, in seconds. "
3532 "If the value is zero, default interval will be used "
3533 "(PJSUA_REG_INTERVAL, 55 seconds). "
3534 },
3535 {
3536 "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0,
3537 "Number of credentials in the credential array. "
3538 },
3539 {
3540 "cred_info", T_OBJECT_EX,
3541 offsetof(acc_config_Object, cred_info), 0,
3542 "Array of credentials. If registration is desired, normally there "
3543 "should be at least one credential specified, to successfully "
3544 "authenticate against the service provider. More credentials can "
3545 "be specified, for example when the requests are expected to be "
3546 "challenged by the proxies in the route set."
Benny Prijono98793592006-12-04 08:33:20 +00003547 },
3548 {NULL} /* Sentinel */
3549};
3550
3551
3552
3553
3554/*
3555 * acc_config_Type
3556 */
3557static PyTypeObject acc_config_Type =
3558{
3559 PyObject_HEAD_INIT(NULL)
3560 0, /*ob_size*/
3561 "py_pjsua.Acc_Config", /*tp_name*/
3562 sizeof(acc_config_Object), /*tp_basicsize*/
3563 0, /*tp_itemsize*/
3564 (destructor)acc_config_dealloc,/*tp_dealloc*/
3565 0, /*tp_print*/
3566 0, /*tp_getattr*/
3567 0, /*tp_setattr*/
3568 0, /*tp_compare*/
3569 0, /*tp_repr*/
3570 0, /*tp_as_number*/
3571 0, /*tp_as_sequence*/
3572 0, /*tp_as_mapping*/
3573 0, /*tp_hash */
3574 0, /*tp_call*/
3575 0, /*tp_str*/
3576 0, /*tp_getattro*/
3577 0, /*tp_setattro*/
3578 0, /*tp_as_buffer*/
3579 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3580 "Acc Config objects", /* tp_doc */
3581 0, /* tp_traverse */
3582 0, /* tp_clear */
3583 0, /* tp_richcompare */
3584 0, /* tp_weaklistoffset */
3585 0, /* tp_iter */
3586 0, /* tp_iternext */
Benny Prijonodc308702006-12-09 00:39:42 +00003587 0/*acc_config_methods*/, /* tp_methods */
Benny Prijono98793592006-12-04 08:33:20 +00003588 acc_config_members, /* tp_members */
3589 0, /* tp_getset */
3590 0, /* tp_base */
3591 0, /* tp_dict */
3592 0, /* tp_descr_get */
3593 0, /* tp_descr_set */
3594 0, /* tp_dictoffset */
3595 0, /* tp_init */
3596 0, /* tp_alloc */
3597 acc_config_new, /* tp_new */
3598
3599};
3600
3601/*
3602 * acc_info_Object
3603 * Acc Info
3604 */
3605typedef struct
3606{
3607 PyObject_HEAD
3608 /* Type-specific fields go here. */
Benny Prijonodc308702006-12-09 00:39:42 +00003609 int id;
3610 int is_default;
3611 PyObject * acc_uri;
3612 int has_registration;
3613 int expires;
3614 int status;
3615 PyObject * status_text;
3616 int online_status;
3617 char buf_[PJ_ERR_MSG_SIZE];
Benny Prijono98793592006-12-04 08:33:20 +00003618} acc_info_Object;
3619
3620
3621/*
3622 * acc_info_dealloc
3623 * deletes a acc_info from memory
3624 */
3625static void acc_info_dealloc(acc_info_Object* self)
3626{
3627 Py_XDECREF(self->acc_uri);
Benny Prijonodc308702006-12-09 00:39:42 +00003628 Py_XDECREF(self->status_text);
Benny Prijono98793592006-12-04 08:33:20 +00003629 self->ob_type->tp_free((PyObject*)self);
3630}
3631
3632
3633/*
3634 * acc_info_new
3635 * constructor for acc_info object
3636 */
3637static PyObject * acc_info_new(PyTypeObject *type, PyObject *args,
3638 PyObject *kwds)
3639{
3640 acc_info_Object *self;
3641
3642 self = (acc_info_Object *)type->tp_alloc(type, 0);
3643 if (self != NULL)
3644 {
Benny Prijonodc308702006-12-09 00:39:42 +00003645 self->acc_uri = PyString_FromString("");
Benny Prijono98793592006-12-04 08:33:20 +00003646 if (self->acc_uri == NULL)
3647 {
3648 Py_DECREF(self);
3649 return NULL;
3650 }
3651 self->status_text = PyString_FromString("");
3652 if (self->status_text == NULL)
3653 {
3654 Py_DECREF(self);
3655 return NULL;
3656 }
3657
3658 }
3659
3660 return (PyObject *)self;
3661}
3662
3663static PyObject * acc_info_get_buf
3664(acc_info_Object *self, PyObject * args)
3665{
Benny Prijonodc308702006-12-09 00:39:42 +00003666 int idx;
3667 char elmt;
3668 if (!PyArg_ParseTuple(args,"i",&idx))
3669 {
3670 return NULL;
3671 }
3672 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3673 {
3674 elmt = self->buf_[idx];
3675 }
3676 else
3677 {
3678 return NULL;
3679 }
3680 return PyString_FromStringAndSize(&elmt, 1);
Benny Prijono98793592006-12-04 08:33:20 +00003681}
3682
3683static PyObject * acc_info_set_buf
3684(acc_info_Object *self, PyObject * args)
3685{
Benny Prijonodc308702006-12-09 00:39:42 +00003686 int idx;
3687 PyObject * str;
3688 char * s;
3689 if (!PyArg_ParseTuple(args,"iO",&idx, &str))
3690 {
3691 return NULL;
3692 }
3693 if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE))
3694 {
3695 s = PyString_AsString(str);
3696 if (s[0])
3697 {
Fahris6f35cb82007-02-01 07:41:26 +00003698 self->buf_[idx] = s[0];
Benny Prijonodc308702006-12-09 00:39:42 +00003699 }
3700 else
3701 {
3702 return NULL;
3703 }
3704 }
3705 else
3706 {
3707 return NULL;
3708 }
3709 Py_INCREF(Py_None);
3710 return Py_None;
Benny Prijono98793592006-12-04 08:33:20 +00003711}
3712
3713static PyMethodDef acc_info_methods[] = {
3714 {
Benny Prijonodc308702006-12-09 00:39:42 +00003715 "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS,
3716 "Return buf char at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003717 },
Benny Prijonodc308702006-12-09 00:39:42 +00003718 {
3719 "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS,
3720 "Set buf at specified index"
Benny Prijono98793592006-12-04 08:33:20 +00003721 },
3722
3723 {NULL} /* Sentinel */
3724};
3725
3726
3727
3728/*
3729 * acc_info_members
3730 */
3731static PyMemberDef acc_info_members[] =
3732{
Benny Prijonodc308702006-12-09 00:39:42 +00003733 {
3734 "id", T_INT, offsetof(acc_info_Object, id), 0,
3735 "The account ID."
Benny Prijono98793592006-12-04 08:33:20 +00003736 },
Benny Prijonodc308702006-12-09 00:39:42 +00003737 {
3738 "is_default", T_INT, offsetof(acc_info_Object, is_default), 0,
3739 "Flag to indicate whether this is the default account. "
Benny Prijono98793592006-12-04 08:33:20 +00003740 },
Benny Prijonodc308702006-12-09 00:39:42 +00003741 {
3742 "acc_uri", T_OBJECT_EX,
3743 offsetof(acc_info_Object, acc_uri), 0,
3744 "Account URI"
Benny Prijono98793592006-12-04 08:33:20 +00003745 },
Benny Prijonodc308702006-12-09 00:39:42 +00003746 {
3747 "has_registration", T_INT, offsetof(acc_info_Object, has_registration),
3748 0,
3749 "Flag to tell whether this account has registration setting "
3750 "(reg_uri is not empty)."
Benny Prijono98793592006-12-04 08:33:20 +00003751 },
Benny Prijonodc308702006-12-09 00:39:42 +00003752 {
3753 "expires", T_INT, offsetof(acc_info_Object, expires), 0,
3754 "An up to date expiration interval for account registration session."
Benny Prijono98793592006-12-04 08:33:20 +00003755 },
Benny Prijonodc308702006-12-09 00:39:42 +00003756 {
3757 "status", T_INT, offsetof(acc_info_Object, status), 0,
3758 "Last registration status code. If status code is zero, "
3759 "the account is currently not registered. Any other value indicates "
3760 "the SIP status code of the registration. "
Benny Prijono98793592006-12-04 08:33:20 +00003761 },
Benny Prijonodc308702006-12-09 00:39:42 +00003762 {
3763 "status_text", T_OBJECT_EX,
3764 offsetof(acc_info_Object, status_text), 0,
3765 "String describing the registration status."
Benny Prijono98793592006-12-04 08:33:20 +00003766 },
Benny Prijonodc308702006-12-09 00:39:42 +00003767 {
3768 "online_status", T_INT, offsetof(acc_info_Object, online_status), 0,
3769 "Presence online status for this account. "
Benny Prijono98793592006-12-04 08:33:20 +00003770 },
3771 {NULL} /* Sentinel */
3772};
3773
3774
3775
3776
3777/*
3778 * acc_info_Type
3779 */
3780static PyTypeObject acc_info_Type =
3781{
3782 PyObject_HEAD_INIT(NULL)
3783 0, /*ob_size*/
3784 "py_pjsua.Acc_Info", /*tp_name*/
3785 sizeof(acc_info_Object), /*tp_basicsize*/
3786 0, /*tp_itemsize*/
3787 (destructor)acc_info_dealloc,/*tp_dealloc*/
3788 0, /*tp_print*/
3789 0, /*tp_getattr*/
3790 0, /*tp_setattr*/
3791 0, /*tp_compare*/
3792 0, /*tp_repr*/
3793 0, /*tp_as_number*/
3794 0, /*tp_as_sequence*/
3795 0, /*tp_as_mapping*/
3796 0, /*tp_hash */
3797 0, /*tp_call*/
3798 0, /*tp_str*/
3799 0, /*tp_getattro*/
3800 0, /*tp_setattro*/
3801 0, /*tp_as_buffer*/
3802 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3803 "Acc Info objects", /* tp_doc */
3804 0, /* tp_traverse */
3805 0, /* tp_clear */
3806 0, /* tp_richcompare */
3807 0, /* tp_weaklistoffset */
3808 0, /* tp_iter */
3809 0, /* tp_iternext */
3810 acc_info_methods, /* tp_methods */
3811 acc_info_members, /* tp_members */
3812 0, /* tp_getset */
3813 0, /* tp_base */
3814 0, /* tp_dict */
3815 0, /* tp_descr_get */
3816 0, /* tp_descr_set */
3817 0, /* tp_dictoffset */
3818 0, /* tp_init */
3819 0, /* tp_alloc */
3820 acc_info_new, /* tp_new */
3821
3822};
3823
Benny Prijono98793592006-12-04 08:33:20 +00003824
3825
3826/*
Benny Prijono98793592006-12-04 08:33:20 +00003827 * py_pjsua_acc_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00003828 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003829 */
3830static PyObject *py_pjsua_acc_config_default
3831(PyObject *pSelf, PyObject *pArgs)
3832{
3833 acc_config_Object *obj;
3834 pjsua_acc_config cfg;
Benny Prijonodc308702006-12-09 00:39:42 +00003835 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003836
Benny Prijonodc308702006-12-09 00:39:42 +00003837 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00003838 {
3839 return NULL;
3840 }
3841 pjsua_acc_config_default(&cfg);
Benny Prijonodc308702006-12-09 00:39:42 +00003842 obj = (acc_config_Object *)acc_config_new(&acc_config_Type, NULL, NULL);
3843 obj->cred_count = cfg.cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003844 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003845 {
3846 /*obj->cred_info[i] = cfg.cred_info[i];*/
3847 int ret;
3848 pjsip_cred_info_Object * ci =
3849 (pjsip_cred_info_Object *)pjsip_cred_info_new
3850 (&pjsip_cred_info_Type,NULL,NULL);
3851 ci->data = PyString_FromStringAndSize(cfg.cred_info[i].data.ptr,
3852 cfg.cred_info[i].data.slen);
3853 ci->realm = PyString_FromStringAndSize(cfg.cred_info[i].realm.ptr,
3854 cfg.cred_info[i].realm.slen);
3855 ci->scheme = PyString_FromStringAndSize(cfg.cred_info[i].scheme.ptr,
3856 cfg.cred_info[i].scheme.slen);
3857 ci->username = PyString_FromStringAndSize(cfg.cred_info[i].username.ptr,
3858 cfg.cred_info[i].username.slen);
3859 ci->data_type = cfg.cred_info[i].data_type;
3860 ret = PyList_SetItem((PyObject *)obj->cred_info,i,(PyObject *)ci);
3861 if (ret == -1) {
3862 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003863 }
Benny Prijonodc308702006-12-09 00:39:42 +00003864 }
3865
3866 Py_XDECREF(obj->force_contact);
3867 obj->force_contact =
3868 PyString_FromStringAndSize(cfg.force_contact.ptr,
3869 cfg.force_contact.slen);
3870 obj->priority = cfg.priority;
3871 Py_XDECREF(obj->id);
3872 obj->id =
3873 PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen);
3874 Py_XDECREF(obj->reg_uri);
3875 obj->reg_uri =
3876 PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen);
3877 obj->proxy_cnt = cfg.proxy_cnt;
Fahris6f35cb82007-02-01 07:41:26 +00003878 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonodc308702006-12-09 00:39:42 +00003879 {
3880 PyObject * str;
3881 int ret;
3882 /*obj->proxy[i] = cfg.proxy[i];*/
3883 str = PyString_FromStringAndSize(cfg.proxy[i].ptr, cfg.proxy[i].slen);
3884 ret = PyList_SetItem((PyObject *)obj->proxy,i,str);
3885 if (ret == -1) {
3886 return NULL;
Benny Prijono98793592006-12-04 08:33:20 +00003887 }
Benny Prijonodc308702006-12-09 00:39:42 +00003888 }
3889 obj->publish_enabled = cfg.publish_enabled;
3890 obj->reg_timeout = cfg.reg_timeout;
Benny Prijono98793592006-12-04 08:33:20 +00003891
Benny Prijonodc308702006-12-09 00:39:42 +00003892 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00003893}
3894
3895/*
3896 * py_pjsua_acc_get_count
3897 */
3898static PyObject *py_pjsua_acc_get_count
3899(PyObject *pSelf, PyObject *pArgs)
3900{
Benny Prijonodc308702006-12-09 00:39:42 +00003901 int count;
Benny Prijono98793592006-12-04 08:33:20 +00003902 if (!PyArg_ParseTuple(pArgs, ""))
3903 {
3904 return NULL;
3905 }
3906 count = pjsua_acc_get_count();
3907 return Py_BuildValue("i",count);
3908}
3909
3910/*
3911 * py_pjsua_acc_is_valid
3912 */
3913static PyObject *py_pjsua_acc_is_valid
3914(PyObject *pSelf, PyObject *pArgs)
3915{
Benny Prijonodc308702006-12-09 00:39:42 +00003916 int id;
3917 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00003918
3919 if (!PyArg_ParseTuple(pArgs, "i", &id))
3920 {
3921 return NULL;
3922 }
3923 is_valid = pjsua_acc_is_valid(id);
3924
3925 return Py_BuildValue("i", is_valid);
3926}
3927
3928/*
3929 * py_pjsua_acc_set_default
3930 */
3931static PyObject *py_pjsua_acc_set_default
3932(PyObject *pSelf, PyObject *pArgs)
3933{
Benny Prijonodc308702006-12-09 00:39:42 +00003934 int id;
3935 int status;
Benny Prijono98793592006-12-04 08:33:20 +00003936
3937 if (!PyArg_ParseTuple(pArgs, "i", &id))
3938 {
3939 return NULL;
3940 }
3941 status = pjsua_acc_set_default(id);
3942
3943 return Py_BuildValue("i", status);
3944}
3945
3946/*
3947 * py_pjsua_acc_get_default
3948 */
3949static PyObject *py_pjsua_acc_get_default
3950(PyObject *pSelf, PyObject *pArgs)
3951{
Benny Prijonodc308702006-12-09 00:39:42 +00003952 int id;
Benny Prijono98793592006-12-04 08:33:20 +00003953
3954 if (!PyArg_ParseTuple(pArgs, ""))
3955 {
3956 return NULL;
3957 }
3958 id = pjsua_acc_get_default();
3959
3960 return Py_BuildValue("i", id);
3961}
3962
3963/*
3964 * py_pjsua_acc_add
Benny Prijonodc308702006-12-09 00:39:42 +00003965 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00003966 */
3967static PyObject *py_pjsua_acc_add
3968(PyObject *pSelf, PyObject *pArgs)
3969{
Benny Prijonodc308702006-12-09 00:39:42 +00003970 int is_default;
Fahris6f35cb82007-02-01 07:41:26 +00003971 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00003972 acc_config_Object * ac;
3973 pjsua_acc_config cfg;
3974
3975 int p_acc_id;
3976 int status;
3977 int i;
Benny Prijono98793592006-12-04 08:33:20 +00003978
Fahris17d91812007-01-29 12:09:33 +00003979 if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00003980 {
3981 return NULL;
3982 }
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003983
3984 pjsua_acc_config_default(&cfg);
Fahris17d91812007-01-29 12:09:33 +00003985 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003986 {
Fahris17d91812007-01-29 12:09:33 +00003987 ac = (acc_config_Object *)acObj;
3988 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00003989 for (i = 0; i < PJSUA_MAX_ACC; i++)
Benny Prijonoed7a5a72007-01-29 18:36:38 +00003990 {
Fahris17d91812007-01-29 12:09:33 +00003991 /*cfg.cred_info[i] = ac->cred_info[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00003992 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
Fahris17d91812007-01-29 12:09:33 +00003993 PyList_GetItem((PyObject *)ac->cred_info,i);
Fahris6f35cb82007-02-01 07:41:26 +00003994 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
3995 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
3996 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
3997 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
3998 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
3999 cfg.cred_info[i].scheme.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004000 (PyString_AsString(ci->scheme));
Fahris6f35cb82007-02-01 07:41:26 +00004001 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4002 cfg.cred_info[i].username.slen = strlen
Fahris17d91812007-01-29 12:09:33 +00004003 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004004 cfg.cred_info[i].data_type = ci->data_type;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004005 }
Fahris17d91812007-01-29 12:09:33 +00004006 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4007 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4008 cfg.id.ptr = PyString_AsString(ac->id);
4009 cfg.id.slen = strlen(PyString_AsString(ac->id));
4010 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004011 for (i = 0; i < PJSUA_MAX_ACC; i++)
4012 {
Fahris17d91812007-01-29 12:09:33 +00004013 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004014 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004015 (PyList_GetItem((PyObject *)ac->proxy,i));
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004016 }
Fahris17d91812007-01-29 12:09:33 +00004017 cfg.proxy_cnt = ac->proxy_cnt;
4018 cfg.publish_enabled = ac->publish_enabled;
4019 cfg.reg_timeout = ac->reg_timeout;
4020 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4021 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004022
Fahris17d91812007-01-29 12:09:33 +00004023 status = pjsua_acc_add(&cfg, is_default, &p_acc_id);
4024 } else {
4025 status = pjsua_acc_add(NULL, is_default, &p_acc_id);
Fahris6f35cb82007-02-01 07:41:26 +00004026 }
Benny Prijonodc308702006-12-09 00:39:42 +00004027
4028 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004029}
4030
4031/*
4032 * py_pjsua_acc_add_local
Benny Prijonodc308702006-12-09 00:39:42 +00004033 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004034 */
4035static PyObject *py_pjsua_acc_add_local
4036(PyObject *pSelf, PyObject *pArgs)
4037{
Benny Prijonodc308702006-12-09 00:39:42 +00004038 int is_default;
4039 int tid;
4040
4041 int p_acc_id;
4042 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004043
4044
Fahris17d91812007-01-29 12:09:33 +00004045 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default))
Benny Prijono98793592006-12-04 08:33:20 +00004046 {
4047 return NULL;
4048 }
4049
Benny Prijonodc308702006-12-09 00:39:42 +00004050
Benny Prijono98793592006-12-04 08:33:20 +00004051 status = pjsua_acc_add_local(tid, is_default, &p_acc_id);
Benny Prijonodc308702006-12-09 00:39:42 +00004052
4053 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00004054}
4055
4056/*
4057 * py_pjsua_acc_del
4058 */
4059static PyObject *py_pjsua_acc_del
4060(PyObject *pSelf, PyObject *pArgs)
4061{
Benny Prijonodc308702006-12-09 00:39:42 +00004062 int acc_id;
4063 int status;
4064
Benny Prijono98793592006-12-04 08:33:20 +00004065 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
4066 {
4067 return NULL;
4068 }
4069
4070
4071 status = pjsua_acc_del(acc_id);
4072 return Py_BuildValue("i", status);
4073}
4074
4075/*
4076 * py_pjsua_acc_modify
4077 */
4078static PyObject *py_pjsua_acc_modify
4079(PyObject *pSelf, PyObject *pArgs)
4080{
Fahris6f35cb82007-02-01 07:41:26 +00004081 PyObject * acObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004082 acc_config_Object * ac;
4083 pjsua_acc_config cfg;
4084 int acc_id;
4085 int status;
4086 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004087
Fahris17d91812007-01-29 12:09:33 +00004088 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj))
Benny Prijono98793592006-12-04 08:33:20 +00004089 {
4090 return NULL;
4091 }
Fahris17d91812007-01-29 12:09:33 +00004092 if (acObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004093 {
4094 ac = (acc_config_Object *)acObj;
Fahris17d91812007-01-29 12:09:33 +00004095 cfg.cred_count = ac->cred_count;
Fahris6f35cb82007-02-01 07:41:26 +00004096 for (i = 0; i < PJSUA_MAX_ACC; i++)
4097 {
Fahris17d91812007-01-29 12:09:33 +00004098 /*cfg.cred_info[i] = ac->cred_info[i];*/
4099 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *)
4100 PyList_GetItem((PyObject *)ac->cred_info,i);
4101 cfg.cred_info[i].data.ptr = PyString_AsString(ci->data);
4102 cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data));
4103 cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm);
4104 cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm));
4105 cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme);
4106 cfg.cred_info[i].scheme.slen = strlen
4107 (PyString_AsString(ci->scheme));
4108 cfg.cred_info[i].username.ptr = PyString_AsString(ci->username);
4109 cfg.cred_info[i].username.slen = strlen
4110 (PyString_AsString(ci->username));
Fahris6f35cb82007-02-01 07:41:26 +00004111 }
Fahris17d91812007-01-29 12:09:33 +00004112 cfg.force_contact.ptr = PyString_AsString(ac->force_contact);
4113 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact));
4114 cfg.id.ptr = PyString_AsString(ac->id);
4115 cfg.id.slen = strlen(PyString_AsString(ac->id));
4116 cfg.priority = ac->priority;
Fahris6f35cb82007-02-01 07:41:26 +00004117 for (i = 0; i < PJSUA_MAX_ACC; i++)
4118 {
Fahris17d91812007-01-29 12:09:33 +00004119 /*cfg.proxy[i] = ac->proxy[i];*/
Fahris6f35cb82007-02-01 07:41:26 +00004120 cfg.proxy[i].ptr = PyString_AsString
Fahris17d91812007-01-29 12:09:33 +00004121 (PyList_GetItem((PyObject *)ac->proxy,i));
Fahris6f35cb82007-02-01 07:41:26 +00004122 }
Fahris17d91812007-01-29 12:09:33 +00004123 cfg.proxy_cnt = ac->proxy_cnt;
4124 cfg.publish_enabled = ac->publish_enabled;
4125 cfg.reg_timeout = ac->reg_timeout;
4126 cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri);
4127 cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri));
4128 status = pjsua_acc_modify(acc_id, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00004129 } else {
4130 status = pjsua_acc_modify(acc_id, NULL);
4131 }
Benny Prijono98793592006-12-04 08:33:20 +00004132 return Py_BuildValue("i", status);
4133}
4134
4135/*
4136 * py_pjsua_acc_set_online_status
4137 */
4138static PyObject *py_pjsua_acc_set_online_status
4139(PyObject *pSelf, PyObject *pArgs)
4140{
Benny Prijonodc308702006-12-09 00:39:42 +00004141 int is_online;
4142 int acc_id;
4143 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004144
4145 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online))
4146 {
4147 return NULL;
4148 }
4149
4150 status = pjsua_acc_set_online_status(acc_id, is_online);
4151
4152 return Py_BuildValue("i", status);
4153}
4154
4155/*
4156 * py_pjsua_acc_set_registration
4157 */
4158static PyObject *py_pjsua_acc_set_registration
4159(PyObject *pSelf, PyObject *pArgs)
4160{
Benny Prijonodc308702006-12-09 00:39:42 +00004161 int renew;
4162 int acc_id;
4163 int status;
Benny Prijono98793592006-12-04 08:33:20 +00004164
4165 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew))
4166 {
4167 return NULL;
4168 }
4169
4170 status = pjsua_acc_set_registration(acc_id, renew);
4171
4172 return Py_BuildValue("i", status);
4173}
4174
4175/*
Benny Prijonodc308702006-12-09 00:39:42 +00004176 * py_pjsua_acc_get_info
4177 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00004178 */
4179static PyObject *py_pjsua_acc_get_info
4180(PyObject *pSelf, PyObject *pArgs)
4181{
Benny Prijonodc308702006-12-09 00:39:42 +00004182 int acc_id;
4183 acc_info_Object * obj;
4184 pjsua_acc_info info;
4185 int status;
4186 int i;
Benny Prijono98793592006-12-04 08:33:20 +00004187
Benny Prijonodc308702006-12-09 00:39:42 +00004188 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
Benny Prijono98793592006-12-04 08:33:20 +00004189 {
4190 return NULL;
4191 }
4192
Benny Prijonodc308702006-12-09 00:39:42 +00004193
Benny Prijono98793592006-12-04 08:33:20 +00004194 status = pjsua_acc_get_info(acc_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004195 if (status == PJ_SUCCESS)
4196 {
Benny Prijonodc308702006-12-09 00:39:42 +00004197 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL, NULL);
4198 obj->acc_uri =
4199 PyString_FromStringAndSize(info.acc_uri.ptr,
4200 info.acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004201 for (i = 0; i < PJ_ERR_MSG_SIZE; i++)
4202 {
Benny Prijonodc308702006-12-09 00:39:42 +00004203 obj->buf_[i] = info.buf_[i];
Benny Prijono98793592006-12-04 08:33:20 +00004204 }
Benny Prijonodc308702006-12-09 00:39:42 +00004205 obj->expires = info.expires;
4206 obj->has_registration = info.has_registration;
4207 obj->id = info.id;
4208 obj->is_default = info.is_default;
4209 obj->online_status = info.online_status;
4210 obj->status = info.status;
4211 obj->status_text =
4212 PyString_FromStringAndSize(info.status_text.ptr,
4213 info.status_text.slen);
4214 return Py_BuildValue("O", obj);
4215 } else {
4216 Py_INCREF(Py_None);
4217 return Py_None;
4218 }
Benny Prijono98793592006-12-04 08:33:20 +00004219}
4220
4221/*
4222 * py_pjsua_enum_accs
Fahrisdcf8fa42006-12-28 03:13:48 +00004223 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004224 */
4225static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
4226{
4227 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004228 PyObject *list;
4229
Fahrisdcf8fa42006-12-28 03:13:48 +00004230 pjsua_acc_id id[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004231 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004232 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004233 {
4234 return NULL;
4235 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004236 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004237
Benny Prijono98793592006-12-04 08:33:20 +00004238 status = pjsua_enum_accs(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004239
4240 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004241 for (i = 0; i < c; i++)
4242 {
Benny Prijonodc308702006-12-09 00:39:42 +00004243 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004244 if (ret == -1)
4245 {
Benny Prijonodc308702006-12-09 00:39:42 +00004246 return NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004247 }
Benny Prijonodc308702006-12-09 00:39:42 +00004248 }
4249
Benny Prijonodc308702006-12-09 00:39:42 +00004250 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004251}
4252
4253/*
4254 * py_pjsua_acc_enum_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004255 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00004256 */
4257static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
4258{
4259 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00004260 PyObject *list;
4261
Fahrisdcf8fa42006-12-28 03:13:48 +00004262 pjsua_acc_info info[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00004263 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004264 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004265 {
4266 return NULL;
4267 }
Benny Prijonodc308702006-12-09 00:39:42 +00004268
Fahrisdcf8fa42006-12-28 03:13:48 +00004269 c = PJ_ARRAY_SIZE(info);
Benny Prijono98793592006-12-04 08:33:20 +00004270 status = pjsua_acc_enum_info(info, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004271
4272 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004273 for (i = 0; i < c; i++)
4274 {
Benny Prijonodc308702006-12-09 00:39:42 +00004275 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00004276 int j;
4277 acc_info_Object *obj;
4278 obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL,NULL);
4279 obj->acc_uri = PyString_FromStringAndSize
Benny Prijonodc308702006-12-09 00:39:42 +00004280 (info[i].acc_uri.ptr, info[i].acc_uri.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004281 for(j = 0; j < PJ_ERR_MSG_SIZE; j++)
4282 {
4283 obj->buf_[j] = info[i].buf_[j];
Benny Prijono98793592006-12-04 08:33:20 +00004284 }
Fahris6f35cb82007-02-01 07:41:26 +00004285 obj->expires = info[i].expires;
4286 obj->has_registration = info[i].has_registration;
4287 obj->id = info[i].id;
4288 obj->is_default = info[i].is_default;
4289 obj->online_status = info[i].online_status;
4290 obj->status = info[i].status;
4291 obj->status_text = PyString_FromStringAndSize(info[i].status_text.ptr,
Benny Prijonodc308702006-12-09 00:39:42 +00004292 info[i].status_text.slen);
Fahris6f35cb82007-02-01 07:41:26 +00004293 ret = PyList_SetItem(list, i, (PyObject *)obj);
Benny Prijonodc308702006-12-09 00:39:42 +00004294 if (ret == -1) {
Fahris6f35cb82007-02-01 07:41:26 +00004295 return NULL;
Benny Prijonodc308702006-12-09 00:39:42 +00004296 }
4297 }
4298
Benny Prijonodc308702006-12-09 00:39:42 +00004299 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00004300}
4301
4302/*
4303 * py_pjsua_acc_find_for_outgoing
4304 */
4305static PyObject *py_pjsua_acc_find_for_outgoing
4306(PyObject *pSelf, PyObject *pArgs)
4307{
4308
Benny Prijonodc308702006-12-09 00:39:42 +00004309 int acc_id;
4310 PyObject * url;
4311 pj_str_t str;
Benny Prijono98793592006-12-04 08:33:20 +00004312
4313 if (!PyArg_ParseTuple(pArgs, "O", &url))
4314 {
4315 return NULL;
4316 }
Benny Prijonodc308702006-12-09 00:39:42 +00004317 str.ptr = PyString_AsString(url);
4318 str.slen = strlen(PyString_AsString(url));
Benny Prijono98793592006-12-04 08:33:20 +00004319
4320 acc_id = pjsua_acc_find_for_outgoing(&str);
4321
4322 return Py_BuildValue("i", acc_id);
4323}
4324
4325/*
4326 * py_pjsua_acc_find_for_incoming
4327 */
4328static PyObject *py_pjsua_acc_find_for_incoming
4329(PyObject *pSelf, PyObject *pArgs)
4330{
Benny Prijonodc308702006-12-09 00:39:42 +00004331 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004332 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004333 pjsip_rx_data_Object * obj;
4334 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004335
Fahris17d91812007-01-29 12:09:33 +00004336 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00004337 {
4338 return NULL;
4339 }
Fahris17d91812007-01-29 12:09:33 +00004340 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004341 {
Fahris17d91812007-01-29 12:09:33 +00004342 obj = (pjsip_rx_data_Object *)tmpObj;
4343 rdata = obj->rdata;
4344 acc_id = pjsua_acc_find_for_incoming(rdata);
Fahris6f35cb82007-02-01 07:41:26 +00004345 } else {
Fahris17d91812007-01-29 12:09:33 +00004346 acc_id = pjsua_acc_find_for_incoming(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004347 }
Benny Prijono98793592006-12-04 08:33:20 +00004348 return Py_BuildValue("i", acc_id);
4349}
4350
4351/*
4352 * py_pjsua_acc_create_uac_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004353 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004354 */
4355static PyObject *py_pjsua_acc_create_uac_contact
4356(PyObject *pSelf, PyObject *pArgs)
4357{
Benny Prijonodc308702006-12-09 00:39:42 +00004358 int status;
Fahris17d91812007-01-29 12:09:33 +00004359 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004360 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004361 pj_pool_Object * p;
4362 pj_pool_t * pool;
4363 PyObject * strc;
4364 pj_str_t contact;
4365 PyObject * stru;
4366 pj_str_t uri;
Benny Prijono98793592006-12-04 08:33:20 +00004367
Fahris17d91812007-01-29 12:09:33 +00004368 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru))
Benny Prijono98793592006-12-04 08:33:20 +00004369 {
4370 return NULL;
4371 }
Fahris17d91812007-01-29 12:09:33 +00004372 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004373 {
Fahris17d91812007-01-29 12:09:33 +00004374 p = (pj_pool_Object *)pObj;
4375 pool = p->pool;
4376 uri.ptr = PyString_AsString(stru);
4377 uri.slen = strlen(PyString_AsString(stru));
4378 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004379 } else {
Fahris17d91812007-01-29 12:09:33 +00004380 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00004381 }
Benny Prijonodc308702006-12-09 00:39:42 +00004382 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004383
Benny Prijonodc308702006-12-09 00:39:42 +00004384 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004385}
4386
4387/*
4388 * py_pjsua_acc_create_uas_contact
Benny Prijonodc308702006-12-09 00:39:42 +00004389 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00004390 */
4391static PyObject *py_pjsua_acc_create_uas_contact
4392(PyObject *pSelf, PyObject *pArgs)
4393{
Benny Prijonodc308702006-12-09 00:39:42 +00004394 int status;
4395 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004396 PyObject * pObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004397 pj_pool_Object * p;
4398 pj_pool_t * pool;
4399 PyObject * strc;
4400 pj_str_t contact;
Fahris6f35cb82007-02-01 07:41:26 +00004401 PyObject * rObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004402 pjsip_rx_data_Object * objr;
4403 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00004404
Fahris17d91812007-01-29 12:09:33 +00004405 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj))
Benny Prijono98793592006-12-04 08:33:20 +00004406 {
4407 return NULL;
4408 }
Fahris17d91812007-01-29 12:09:33 +00004409 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004410 {
Fahris17d91812007-01-29 12:09:33 +00004411 p = (pj_pool_Object *)pObj;
4412 pool = p->pool;
4413 } else {
4414 pool = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004415 }
Fahris17d91812007-01-29 12:09:33 +00004416 if (rObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004417 {
4418 objr = (pjsip_rx_data_Object *)rObj;
Fahris17d91812007-01-29 12:09:33 +00004419 rdata = objr->rdata;
Fahris6f35cb82007-02-01 07:41:26 +00004420 } else {
Fahris17d91812007-01-29 12:09:33 +00004421 rdata = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00004422 }
Benny Prijono98793592006-12-04 08:33:20 +00004423 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata);
Benny Prijonodc308702006-12-09 00:39:42 +00004424 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00004425
Benny Prijonodc308702006-12-09 00:39:42 +00004426 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00004427}
4428
4429static char pjsua_acc_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004430 "py_pjsua.Acc_Config py_pjsua.acc_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00004431 "Call this function to initialize account config with default values.";
4432static char pjsua_acc_get_count_doc[] =
4433 "int py_pjsua.acc_get_count () "
4434 "Get number of current accounts.";
4435static char pjsua_acc_is_valid_doc[] =
4436 "int py_pjsua.acc_is_valid (int acc_id) "
4437 "Check if the specified account ID is valid.";
4438static char pjsua_acc_set_default_doc[] =
4439 "int py_pjsua.acc_set_default (int acc_id) "
4440 "Set default account to be used when incoming "
Benny Prijonodc308702006-12-09 00:39:42 +00004441 "and outgoing requests doesn't match any accounts.";
Benny Prijono98793592006-12-04 08:33:20 +00004442static char pjsua_acc_get_default_doc[] =
4443 "int py_pjsua.acc_get_default () "
4444 "Get default account.";
4445static char pjsua_acc_add_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004446 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, "
4447 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004448 "Add a new account to pjsua. PJSUA must have been initialized "
Benny Prijonodc308702006-12-09 00:39:42 +00004449 "(with pjsua_init()) before calling this function.";
Benny Prijono98793592006-12-04 08:33:20 +00004450static char pjsua_acc_add_local_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004451 "int,int py_pjsua.acc_add_local (int tid, "
4452 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00004453 "Add a local account. A local account is used to identify "
Benny Prijonodc308702006-12-09 00:39:42 +00004454 "local endpoint instead of a specific user, and for this reason, "
4455 "a transport ID is needed to obtain the local address information.";
Benny Prijono98793592006-12-04 08:33:20 +00004456static char pjsua_acc_del_doc[] =
4457 "int py_pjsua.acc_del (int acc_id) "
4458 "Delete account.";
4459static char pjsua_acc_modify_doc[] =
4460 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) "
4461 "Modify account information.";
4462static char pjsua_acc_set_online_status_doc[] =
4463 "int py_pjsua.acc_set_online_status (int acc_id, int is_online) "
4464 "Modify account's presence status to be advertised "
Benny Prijonodc308702006-12-09 00:39:42 +00004465 "to remote/presence subscribers.";
Benny Prijono98793592006-12-04 08:33:20 +00004466static char pjsua_acc_set_registration_doc[] =
4467 "int py_pjsua.acc_set_registration (int acc_id, int renew) "
4468 "Update registration or perform unregistration.";
4469static char pjsua_acc_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004470 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) "
Benny Prijono98793592006-12-04 08:33:20 +00004471 "Get account information.";
4472static char pjsua_enum_accs_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004473 "int[] py_pjsua.enum_accs () "
Benny Prijono98793592006-12-04 08:33:20 +00004474 "Enum accounts all account ids.";
4475static char pjsua_acc_enum_info_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00004476 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () "
Benny Prijono98793592006-12-04 08:33:20 +00004477 "Enum accounts info.";
4478static char pjsua_acc_find_for_outgoing_doc[] =
4479 "int py_pjsua.acc_find_for_outgoing (string url) "
4480 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004481 "to used to reach to the specified URL.";
Benny Prijono98793592006-12-04 08:33:20 +00004482static char pjsua_acc_find_for_incoming_doc[] =
4483 "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) "
4484 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00004485 "to be used to handle incoming calls.";
Benny Prijono98793592006-12-04 08:33:20 +00004486static char pjsua_acc_create_uac_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004487 "string py_pjsua.acc_create_uac_contact (pj_pool_Object pool, "
4488 "int acc_id, string uri) "
Benny Prijono98793592006-12-04 08:33:20 +00004489 "Create a suitable URI to be put as Contact based on the specified "
Benny Prijonodc308702006-12-09 00:39:42 +00004490 "target URI for the specified account.";
Benny Prijono98793592006-12-04 08:33:20 +00004491static char pjsua_acc_create_uas_contact_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00004492 "string py_pjsua.acc_create_uas_contact (pj_pool_Object pool, "
4493 "int acc_id, pjsip_rx_data_Object rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00004494 "Create a suitable URI to be put as Contact based on the information "
Benny Prijonodc308702006-12-09 00:39:42 +00004495 "in the incoming request.";
Benny Prijono98793592006-12-04 08:33:20 +00004496
4497/* END OF LIB ACCOUNT */
4498
Benny Prijonodc308702006-12-09 00:39:42 +00004499/* LIB BUDDY */
4500
4501
4502
4503/*
4504 * buddy_config_Object
4505 * Buddy Config
4506 */
4507typedef struct
4508{
4509 PyObject_HEAD
4510 /* Type-specific fields go here. */
4511
4512 PyObject * uri;
4513 int subscribe;
4514} buddy_config_Object;
4515
4516
4517/*
4518 * buddy_config_dealloc
4519 * deletes a buddy_config from memory
4520 */
4521static void buddy_config_dealloc(buddy_config_Object* self)
4522{
4523 Py_XDECREF(self->uri);
4524 self->ob_type->tp_free((PyObject*)self);
4525}
4526
4527
4528/*
4529 * buddy_config_new
4530 * constructor for buddy_config object
4531 */
4532static PyObject * buddy_config_new(PyTypeObject *type, PyObject *args,
4533 PyObject *kwds)
4534{
4535 buddy_config_Object *self;
4536
4537 self = (buddy_config_Object *)type->tp_alloc(type, 0);
4538 if (self != NULL)
4539 {
4540 self->uri = PyString_FromString("");
4541 if (self->uri == NULL)
4542 {
4543 Py_DECREF(self);
4544 return NULL;
4545 }
4546 }
4547 return (PyObject *)self;
4548}
4549
4550/*
4551 * buddy_config_members
4552 */
4553static PyMemberDef buddy_config_members[] =
4554{
4555
4556 {
4557 "uri", T_OBJECT_EX,
4558 offsetof(buddy_config_Object, uri), 0,
4559 "TBuddy URL or name address."
4560 },
4561
4562 {
4563 "subscribe", T_INT,
4564 offsetof(buddy_config_Object, subscribe), 0,
4565 "Specify whether presence subscription should start immediately. "
4566 },
4567
4568 {NULL} /* Sentinel */
4569};
4570
4571
4572
4573
4574/*
4575 * buddy_config_Type
4576 */
4577static PyTypeObject buddy_config_Type =
4578{
4579 PyObject_HEAD_INIT(NULL)
4580 0, /*ob_size*/
4581 "py_pjsua.Buddy_Config", /*tp_name*/
4582 sizeof(buddy_config_Object), /*tp_basicsize*/
4583 0, /*tp_itemsize*/
4584 (destructor)buddy_config_dealloc,/*tp_dealloc*/
4585 0, /*tp_print*/
4586 0, /*tp_getattr*/
4587 0, /*tp_setattr*/
4588 0, /*tp_compare*/
4589 0, /*tp_repr*/
4590 0, /*tp_as_number*/
4591 0, /*tp_as_sequence*/
4592 0, /*tp_as_mapping*/
4593 0, /*tp_hash */
4594 0, /*tp_call*/
4595 0, /*tp_str*/
4596 0, /*tp_getattro*/
4597 0, /*tp_setattro*/
4598 0, /*tp_as_buffer*/
4599 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4600 "Buddy Config objects", /* tp_doc */
4601 0, /* tp_traverse */
4602 0, /* tp_clear */
4603 0, /* tp_richcompare */
4604 0, /* tp_weaklistoffset */
4605 0, /* tp_iter */
4606 0, /* tp_iternext */
4607 0, /* tp_methods */
4608 buddy_config_members, /* tp_members */
4609 0, /* tp_getset */
4610 0, /* tp_base */
4611 0, /* tp_dict */
4612 0, /* tp_descr_get */
4613 0, /* tp_descr_set */
4614 0, /* tp_dictoffset */
4615 0, /* tp_init */
4616 0, /* tp_alloc */
4617 buddy_config_new, /* tp_new */
4618
4619};
4620
4621/*
4622 * buddy_info_Object
4623 * Buddy Info
4624 * !modified @ 071206
4625 */
4626typedef struct
4627{
4628 PyObject_HEAD
4629 /* Type-specific fields go here. */
4630 int id;
4631 PyObject * uri;
4632 PyObject * contact;
4633 int status;
4634 PyObject * status_text;
4635 int monitor_pres;
4636 char buf_[256];
4637} buddy_info_Object;
4638
4639
4640/*
4641 * buddy_info_dealloc
4642 * deletes a buddy_info from memory
4643 * !modified @ 071206
4644 */
4645static void buddy_info_dealloc(buddy_info_Object* self)
4646{
4647 Py_XDECREF(self->uri);
4648 Py_XDECREF(self->contact);
4649 Py_XDECREF(self->status_text);
4650
4651 self->ob_type->tp_free((PyObject*)self);
4652}
4653
4654
4655/*
4656 * buddy_info_new
4657 * constructor for buddy_info object
4658 * !modified @ 071206
4659 */
4660static PyObject * buddy_info_new(PyTypeObject *type, PyObject *args,
4661 PyObject *kwds)
4662{
4663 buddy_info_Object *self;
4664
4665 self = (buddy_info_Object *)type->tp_alloc(type, 0);
4666 if (self != NULL)
4667 {
4668 self->uri = PyString_FromString("");
4669 if (self->uri == NULL)
4670 {
4671 Py_DECREF(self);
4672 return NULL;
4673 }
4674 self->contact = PyString_FromString("");
4675 if (self->contact == NULL)
4676 {
4677 Py_DECREF(self);
4678 return NULL;
4679 }
4680 self->status_text = PyString_FromString("");
4681 if (self->status_text == NULL)
4682 {
4683 Py_DECREF(self);
4684 return NULL;
4685 }
4686
4687 }
4688 return (PyObject *)self;
4689}
4690
4691/*
4692 * buddy_info_members
4693 * !modified @ 071206
4694 */
4695static PyMemberDef buddy_info_members[] =
4696{
4697 {
4698 "id", T_INT,
4699 offsetof(buddy_info_Object, id), 0,
4700 "The buddy ID."
4701 },
4702 {
4703 "uri", T_OBJECT_EX,
4704 offsetof(buddy_info_Object, uri), 0,
4705 "The full URI of the buddy, as specified in the configuration. "
4706 },
4707 {
4708 "contact", T_OBJECT_EX,
4709 offsetof(buddy_info_Object, contact), 0,
4710 "Buddy's Contact, only available when presence subscription "
4711 "has been established to the buddy."
4712 },
4713 {
4714 "status", T_INT,
4715 offsetof(buddy_info_Object, status), 0,
4716 "Buddy's online status. "
4717 },
4718 {
4719 "status_text", T_OBJECT_EX,
4720 offsetof(buddy_info_Object, status_text), 0,
4721 "Text to describe buddy's online status."
4722 },
4723 {
4724 "monitor_pres", T_INT,
4725 offsetof(buddy_info_Object, monitor_pres), 0,
4726 "Flag to indicate that we should monitor the presence information "
4727 "for this buddy (normally yes, unless explicitly disabled). "
4728 },
4729
4730
4731 {NULL} /* Sentinel */
4732};
4733
4734
4735
4736
4737/*
4738 * buddy_info_Type
4739 */
4740static PyTypeObject buddy_info_Type =
4741{
4742 PyObject_HEAD_INIT(NULL)
4743 0, /*ob_size*/
4744 "py_pjsua.Buddy_Info", /*tp_name*/
4745 sizeof(buddy_info_Object), /*tp_basicsize*/
4746 0, /*tp_itemsize*/
4747 (destructor)buddy_info_dealloc,/*tp_dealloc*/
4748 0, /*tp_print*/
4749 0, /*tp_getattr*/
4750 0, /*tp_setattr*/
4751 0, /*tp_compare*/
4752 0, /*tp_repr*/
4753 0, /*tp_as_number*/
4754 0, /*tp_as_sequence*/
4755 0, /*tp_as_mapping*/
4756 0, /*tp_hash */
4757 0, /*tp_call*/
4758 0, /*tp_str*/
4759 0, /*tp_getattro*/
4760 0, /*tp_setattro*/
4761 0, /*tp_as_buffer*/
4762 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4763 "Buddy Info objects", /* tp_doc */
4764 0, /* tp_traverse */
4765 0, /* tp_clear */
4766 0, /* tp_richcompare */
4767 0, /* tp_weaklistoffset */
4768 0, /* tp_iter */
4769 0, /* tp_iternext */
4770 0, /* tp_methods */
4771 buddy_info_members, /* tp_members */
4772 0, /* tp_getset */
4773 0, /* tp_base */
4774 0, /* tp_dict */
4775 0, /* tp_descr_get */
4776 0, /* tp_descr_set */
4777 0, /* tp_dictoffset */
4778 0, /* tp_init */
4779 0, /* tp_alloc */
4780 buddy_info_new, /* tp_new */
4781
4782};
4783
4784/*
Fahris6f35cb82007-02-01 07:41:26 +00004785 * py_pjsua_buddy_config_default
4786 */
4787static PyObject *py_pjsua_buddy_config_default
4788(PyObject *pSelf, PyObject *pArgs)
4789{
4790 buddy_config_Object *obj;
4791 pjsua_buddy_config cfg;
4792
4793 if (!PyArg_ParseTuple(pArgs, ""))
4794 {
4795 return NULL;
4796 }
4797
4798 pjsua_buddy_config_default(&cfg);
4799 obj = (buddy_config_Object *) buddy_config_new
4800 (&buddy_config_Type,NULL,NULL);
4801 obj->uri = PyString_FromStringAndSize(
4802 cfg.uri.ptr, cfg.uri.slen
4803 );
4804 obj->subscribe = cfg.subscribe;
4805
4806 return (PyObject *)obj;
4807}
4808
4809/*
Benny Prijonodc308702006-12-09 00:39:42 +00004810 * py_pjsua_get_buddy_count
4811 */
4812static PyObject *py_pjsua_get_buddy_count
Benny Prijono98793592006-12-04 08:33:20 +00004813(PyObject *pSelf, PyObject *pArgs)
4814{
Benny Prijonodc308702006-12-09 00:39:42 +00004815 int ret;
Benny Prijono98793592006-12-04 08:33:20 +00004816
Benny Prijonodc308702006-12-09 00:39:42 +00004817 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00004818 {
4819 return NULL;
4820 }
Benny Prijonodc308702006-12-09 00:39:42 +00004821 ret = pjsua_get_buddy_count();
4822
4823 return Py_BuildValue("i", ret);
4824}
Benny Prijono98793592006-12-04 08:33:20 +00004825
Benny Prijonodc308702006-12-09 00:39:42 +00004826/*
4827 * py_pjsua_buddy_is_valid
4828 */
4829static PyObject *py_pjsua_buddy_is_valid
4830(PyObject *pSelf, PyObject *pArgs)
4831{
4832 int id;
4833 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00004834
Benny Prijonodc308702006-12-09 00:39:42 +00004835 if (!PyArg_ParseTuple(pArgs, "i", &id))
4836 {
4837 return NULL;
4838 }
4839 is_valid = pjsua_buddy_is_valid(id);
4840
4841 return Py_BuildValue("i", is_valid);
4842}
4843
4844/*
4845 * py_pjsua_enum_buddies
Fahrisdcf8fa42006-12-28 03:13:48 +00004846 * !modified @ 241206
Benny Prijonodc308702006-12-09 00:39:42 +00004847 */
4848static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
4849{
4850 pj_status_t status;
4851 PyObject *list;
4852
Fahrisdcf8fa42006-12-28 03:13:48 +00004853 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
Fahris17d91812007-01-29 12:09:33 +00004854 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00004855 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijonodc308702006-12-09 00:39:42 +00004856 {
4857 return NULL;
4858 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004859 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00004860 status = pjsua_enum_buddies(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00004861 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00004862 for (i = 0; i < c; i++)
4863 {
Benny Prijonodc308702006-12-09 00:39:42 +00004864 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00004865 if (ret == -1)
4866 {
Benny Prijonodc308702006-12-09 00:39:42 +00004867 return NULL;
4868 }
4869 }
4870
Benny Prijonodc308702006-12-09 00:39:42 +00004871 return Py_BuildValue("O",list);
4872}
4873
4874/*
4875 * py_pjsua_buddy_get_info
4876 * !modified @ 071206
4877 */
4878static PyObject *py_pjsua_buddy_get_info
4879(PyObject *pSelf, PyObject *pArgs)
4880{
4881 int buddy_id;
4882 buddy_info_Object * obj;
4883 pjsua_buddy_info info;
4884 int status;
4885 int i;
4886
4887 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4888 {
4889 return NULL;
4890 }
4891
4892
4893 status = pjsua_buddy_get_info(buddy_id, &info);
Fahris6f35cb82007-02-01 07:41:26 +00004894 if (status == PJ_SUCCESS)
4895 {
Benny Prijonodc308702006-12-09 00:39:42 +00004896 obj = (buddy_info_Object *)buddy_info_new(&buddy_info_Type,NULL,NULL);
4897 obj->id = info.id;
4898 Py_XDECREF(obj->uri);
4899 obj->uri =
4900 PyString_FromStringAndSize(info.uri.ptr,
4901 info.uri.slen);
4902 Py_XDECREF(obj->contact);
4903 obj->contact =
4904 PyString_FromStringAndSize(info.contact.ptr,
4905 info.contact.slen);
4906 obj->status = info.status;
4907 Py_XDECREF(obj->status_text);
4908 obj->status_text =
4909 PyString_FromStringAndSize(info.status_text.ptr,
4910 info.status_text.slen);
4911 obj->monitor_pres = info.monitor_pres;
Fahris6f35cb82007-02-01 07:41:26 +00004912 for (i = 0; i < 256; i++)
4913 {
Benny Prijonodc308702006-12-09 00:39:42 +00004914
4915 obj->buf_[i] = info.buf_[i];
4916 }
4917
4918 return Py_BuildValue("O", obj);
4919 } else {
4920 Py_INCREF(Py_None);
4921 return Py_None;
4922 }
4923}
4924
4925/*
4926 * py_pjsua_buddy_add
4927 * !modified @ 061206
4928 */
4929static PyObject *py_pjsua_buddy_add
4930(PyObject *pSelf, PyObject *pArgs)
Fahris17d91812007-01-29 12:09:33 +00004931{
4932 PyObject * bcObj;
Benny Prijonodc308702006-12-09 00:39:42 +00004933 buddy_config_Object * bc;
Fahris17d91812007-01-29 12:09:33 +00004934
Benny Prijonodc308702006-12-09 00:39:42 +00004935 pjsua_buddy_config cfg;
4936
4937 int p_buddy_id;
4938 int status;
4939
Fahris17d91812007-01-29 12:09:33 +00004940 if (!PyArg_ParseTuple(pArgs, "O", &bcObj))
Benny Prijonodc308702006-12-09 00:39:42 +00004941 {
4942 return NULL;
4943 }
Fahris17d91812007-01-29 12:09:33 +00004944 if (bcObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004945 {
4946 bc = (buddy_config_Object *)bcObj;
Fahris17d91812007-01-29 12:09:33 +00004947
4948 cfg.subscribe = bc->subscribe;
4949 cfg.uri.ptr = PyString_AsString(bc->uri);
4950 cfg.uri.slen = strlen(PyString_AsString(bc->uri));
Benny Prijonodc308702006-12-09 00:39:42 +00004951
Fahris17d91812007-01-29 12:09:33 +00004952 status = pjsua_buddy_add(&cfg, &p_buddy_id);
Fahris6f35cb82007-02-01 07:41:26 +00004953 } else {
Fahris17d91812007-01-29 12:09:33 +00004954 status = pjsua_buddy_add(NULL, &p_buddy_id);
4955 }
Benny Prijonodc308702006-12-09 00:39:42 +00004956 return Py_BuildValue("ii", status, p_buddy_id);
4957}
4958
4959/*
4960 * py_pjsua_buddy_del
4961 */
4962static PyObject *py_pjsua_buddy_del
4963(PyObject *pSelf, PyObject *pArgs)
4964{
4965 int buddy_id;
4966 int status;
4967
4968 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id))
4969 {
4970 return NULL;
4971 }
4972
4973
4974 status = pjsua_buddy_del(buddy_id);
4975 return Py_BuildValue("i", status);
4976}
4977
4978/*
4979 * py_pjsua_buddy_subscribe_pres
4980 */
4981static PyObject *py_pjsua_buddy_subscribe_pres
4982(PyObject *pSelf, PyObject *pArgs)
4983{
4984 int buddy_id;
4985 int status;
4986 int subscribe;
4987
4988 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe))
4989 {
4990 return NULL;
4991 }
4992
4993
4994 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
4995 return Py_BuildValue("i", status);
4996}
4997
4998/*
4999 * py_pjsua_pres_dump
5000 */
5001static PyObject *py_pjsua_pres_dump
5002(PyObject *pSelf, PyObject *pArgs)
5003{
5004 int verbose;
5005
5006 if (!PyArg_ParseTuple(pArgs, "i", &verbose))
5007 {
5008 return NULL;
5009 }
5010
5011
5012 pjsua_pres_dump(verbose);
Benny Prijono98793592006-12-04 08:33:20 +00005013 Py_INCREF(Py_None);
5014 return Py_None;
5015}
5016
Benny Prijonodc308702006-12-09 00:39:42 +00005017/*
5018 * py_pjsua_im_send
5019 * !modified @ 071206
5020 */
5021static PyObject *py_pjsua_im_send
5022(PyObject *pSelf, PyObject *pArgs)
5023{
5024 int status;
5025 int acc_id;
Fahrise314b882007-02-02 10:52:04 +00005026 pj_str_t * mime_type, tmp_mime_type;
Fahris6f35cb82007-02-01 07:41:26 +00005027 pj_str_t to, content;
Benny Prijonodc308702006-12-09 00:39:42 +00005028 PyObject * st;
5029 PyObject * smt;
5030 PyObject * sc;
5031 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00005032 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005033 msg_data_Object * omd;
Fahris6f35cb82007-02-01 07:41:26 +00005034
Benny Prijonodc308702006-12-09 00:39:42 +00005035 int user_data;
5036 pj_pool_t *pool;
5037
Fahris6f35cb82007-02-01 07:41:26 +00005038
Fahris17d91812007-01-29 12:09:33 +00005039 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
5040 &st, &smt, &sc, &omdObj, &user_data))
Benny Prijonodc308702006-12-09 00:39:42 +00005041 {
5042 return NULL;
5043 }
Fahrise314b882007-02-02 10:52:04 +00005044 if (smt != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005045 {
Fahrise314b882007-02-02 10:52:04 +00005046 mime_type = &tmp_mime_type;
5047 tmp_mime_type.ptr = PyString_AsString(smt);
5048 tmp_mime_type.slen = strlen(PyString_AsString(smt));
Fahris6f35cb82007-02-01 07:41:26 +00005049 } else {
5050 mime_type = NULL;
5051 }
Benny Prijonodc308702006-12-09 00:39:42 +00005052 to.ptr = PyString_AsString(st);
5053 to.slen = strlen(PyString_AsString(st));
Fahris6f35cb82007-02-01 07:41:26 +00005054
Benny Prijonodc308702006-12-09 00:39:42 +00005055 content.ptr = PyString_AsString(sc);
5056 content.slen = strlen(PyString_AsString(sc));
Fahris17d91812007-01-29 12:09:33 +00005057 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005058 {
Fahris17d91812007-01-29 12:09:33 +00005059
5060 omd = (msg_data_Object *)omdObj;
5061 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5062 msg_data.content_type.slen = strlen
5063 (PyString_AsString(omd->content_type));
5064 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5065 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005066 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005067
Fahris17d91812007-01-29 12:09:33 +00005068 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00005069 status = pjsua_im_send(acc_id, &to, mime_type,
5070 &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00005071 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005072 } else {
Fahris17d91812007-01-29 12:09:33 +00005073
Fahris6f35cb82007-02-01 07:41:26 +00005074 status = pjsua_im_send(acc_id, &to, mime_type,
Fahris17d91812007-01-29 12:09:33 +00005075 &content, NULL, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005076 }
Fahrise314b882007-02-02 10:52:04 +00005077
Benny Prijonodc308702006-12-09 00:39:42 +00005078 return Py_BuildValue("i",status);
5079}
5080
5081/*
5082 * py_pjsua_im_typing
5083 */
5084static PyObject *py_pjsua_im_typing
5085(PyObject *pSelf, PyObject *pArgs)
5086{
5087 int status;
5088 int acc_id;
5089 pj_str_t to;
5090 PyObject * st;
5091 int is_typing;
5092 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00005093 PyObject * omdObj;
Benny Prijonodc308702006-12-09 00:39:42 +00005094 msg_data_Object * omd;
5095 pj_pool_t * pool;
5096
Fahris17d91812007-01-29 12:09:33 +00005097 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj))
Benny Prijonodc308702006-12-09 00:39:42 +00005098 {
5099 return NULL;
5100 }
5101
5102 to.ptr = PyString_AsString(st);
5103 to.slen = strlen(PyString_AsString(st));
Fahris17d91812007-01-29 12:09:33 +00005104 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00005105 {
Fahris17d91812007-01-29 12:09:33 +00005106 omd = (msg_data_Object *)omdObj;
5107 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
5108 msg_data.content_type.slen = strlen
5109 (PyString_AsString(omd->content_type));
5110 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
5111 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00005112 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00005113
Fahris17d91812007-01-29 12:09:33 +00005114 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
5115 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
5116 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00005117 } else {
Fahris17d91812007-01-29 12:09:33 +00005118 status = pjsua_im_typing(acc_id, &to, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00005119 }
Benny Prijonodc308702006-12-09 00:39:42 +00005120 return Py_BuildValue("i",status);
5121}
5122
Fahris6f35cb82007-02-01 07:41:26 +00005123static char pjsua_buddy_config_default_doc[] =
5124 "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () "
5125 "Set default values to the buddy config.";
Benny Prijonodc308702006-12-09 00:39:42 +00005126static char pjsua_get_buddy_count_doc[] =
5127 "int py_pjsua.get_buddy_count () "
5128 "Get total number of buddies.";
5129static char pjsua_buddy_is_valid_doc[] =
5130 "int py_pjsua.buddy_is_valid (int buddy_id) "
5131 "Check if buddy ID is valid.";
5132static char pjsua_enum_buddies_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00005133 "int[] py_pjsua.enum_buddies () "
Benny Prijonodc308702006-12-09 00:39:42 +00005134 "Enum buddy IDs.";
5135static char pjsua_buddy_get_info_doc[] =
5136 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) "
5137 "Get detailed buddy info.";
5138static char pjsua_buddy_add_doc[] =
5139 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) "
5140 "Add new buddy.";
5141static char pjsua_buddy_del_doc[] =
5142 "int py_pjsua.buddy_del (int buddy_id) "
5143 "Delete buddy.";
5144static char pjsua_buddy_subscribe_pres_doc[] =
5145 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
5146 "Enable/disable buddy's presence monitoring.";
5147static char pjsua_pres_dump_doc[] =
5148 "void py_pjsua.pres_dump (int verbose) "
5149 "Dump presence subscriptions to log file.";
5150static char pjsua_im_send_doc[] =
5151 "int py_pjsua.im_send (int acc_id, string to, string mime_type, "
5152 "string content, py_pjsua.Msg_Data msg_data, int user_data) "
5153 "Send instant messaging outside dialog, using the specified account "
5154 "for route set and authentication.";
5155static char pjsua_im_typing_doc[] =
5156 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, "
5157 "py_pjsua.Msg_Data msg_data) "
5158 "Send typing indication outside dialog.";
5159
5160/* END OF LIB BUDDY */
5161
Fahrisdcf8fa42006-12-28 03:13:48 +00005162/* LIB MEDIA */
Benny Prijono98793592006-12-04 08:33:20 +00005163
Benny Prijono572d4852006-11-23 21:50:02 +00005164
Fahrisdcf8fa42006-12-28 03:13:48 +00005165
5166/*
5167 * codec_info_Object
5168 * Codec Info
5169 * !modified @ 071206
5170 */
5171typedef struct
5172{
5173 PyObject_HEAD
5174 /* Type-specific fields go here. */
5175
5176 PyObject * codec_id;
5177 pj_uint8_t priority;
5178 char buf_[32];
5179} codec_info_Object;
5180
5181
5182/*
5183 * codec_info_dealloc
5184 * deletes a codec_info from memory
5185 * !modified @ 071206
5186 */
5187static void codec_info_dealloc(codec_info_Object* self)
5188{
5189 Py_XDECREF(self->codec_id);
5190
5191 self->ob_type->tp_free((PyObject*)self);
5192}
5193
5194
5195/*
5196 * codec_info_new
5197 * constructor for codec_info object
5198 * !modified @ 071206
5199 */
5200static PyObject * codec_info_new(PyTypeObject *type, PyObject *args,
5201 PyObject *kwds)
5202{
5203 codec_info_Object *self;
5204
5205 self = (codec_info_Object *)type->tp_alloc(type, 0);
5206 if (self != NULL)
5207 {
5208 self->codec_id = PyString_FromString("");
5209 if (self->codec_id == NULL)
5210 {
5211 Py_DECREF(self);
5212 return NULL;
5213 }
5214
5215
5216 }
5217 return (PyObject *)self;
5218}
5219
5220/*
5221 * codec_info_members
5222 * !modified @ 071206
5223 */
5224static PyMemberDef codec_info_members[] =
5225{
5226 {
5227 "codec_id", T_OBJECT_EX,
5228 offsetof(codec_info_Object, codec_id), 0,
5229 "Codec unique identification."
5230 },
5231
5232 {
5233 "priority", T_INT,
5234 offsetof(codec_info_Object, priority), 0,
5235 "Codec priority (integer 0-255)."
5236 },
5237
5238
5239
5240 {NULL} /* Sentinel */
5241};
5242
5243
5244
5245
5246/*
5247 * codec_info_Type
5248 */
5249static PyTypeObject codec_info_Type =
5250{
5251 PyObject_HEAD_INIT(NULL)
5252 0, /*ob_size*/
5253 "py_pjsua.Codec_Info", /*tp_name*/
5254 sizeof(codec_info_Object), /*tp_basicsize*/
5255 0, /*tp_itemsize*/
5256 (destructor)codec_info_dealloc,/*tp_dealloc*/
5257 0, /*tp_print*/
5258 0, /*tp_getattr*/
5259 0, /*tp_setattr*/
5260 0, /*tp_compare*/
5261 0, /*tp_repr*/
5262 0, /*tp_as_number*/
5263 0, /*tp_as_sequence*/
5264 0, /*tp_as_mapping*/
5265 0, /*tp_hash */
5266 0, /*tp_call*/
5267 0, /*tp_str*/
5268 0, /*tp_getattro*/
5269 0, /*tp_setattro*/
5270 0, /*tp_as_buffer*/
5271 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5272 "Codec Info objects", /* tp_doc */
5273 0, /* tp_traverse */
5274 0, /* tp_clear */
5275 0, /* tp_richcompare */
5276 0, /* tp_weaklistoffset */
5277 0, /* tp_iter */
5278 0, /* tp_iternext */
5279 0, /* tp_methods */
5280 codec_info_members, /* tp_members */
5281 0, /* tp_getset */
5282 0, /* tp_base */
5283 0, /* tp_dict */
5284 0, /* tp_descr_get */
5285 0, /* tp_descr_set */
5286 0, /* tp_dictoffset */
5287 0, /* tp_init */
5288 0, /* tp_alloc */
5289 codec_info_new, /* tp_new */
5290
5291};
5292
5293/*
5294 * conf_port_info_Object
5295 * Conf Port Info
5296 */
5297typedef struct
5298{
5299 PyObject_HEAD
5300 /* Type-specific fields go here. */
5301
5302 int slot_id;
5303 PyObject * name;
5304 unsigned clock_rate;
5305 unsigned channel_count;
5306 unsigned samples_per_frame;
5307 unsigned bits_per_sample;
5308 unsigned listener_cnt;
5309 PyListObject * listeners;
5310
5311} conf_port_info_Object;
5312
5313
5314/*
5315 * conf_port_info_dealloc
5316 * deletes a conf_port_info from memory
5317 */
5318static void conf_port_info_dealloc(conf_port_info_Object* self)
5319{
5320 Py_XDECREF(self->name);
5321 Py_XDECREF(self->listeners);
5322 self->ob_type->tp_free((PyObject*)self);
5323}
5324
5325
5326/*
5327 * conf_port_info_new
5328 * constructor for conf_port_info object
5329 */
5330static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
5331 PyObject *kwds)
5332{
5333 conf_port_info_Object *self;
5334
5335 self = (conf_port_info_Object *)type->tp_alloc(type, 0);
5336 if (self != NULL)
5337 {
5338 self->name = PyString_FromString("");
5339 if (self->name == NULL)
5340 {
5341 Py_DECREF(self);
5342 return NULL;
5343 }
5344
Fahris6f35cb82007-02-01 07:41:26 +00005345 self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS);
Fahrisdcf8fa42006-12-28 03:13:48 +00005346 if (self->listeners == NULL)
5347 {
5348 Py_DECREF(self);
5349 return NULL;
5350 }
5351 }
5352 return (PyObject *)self;
5353}
5354
5355/*
5356 * conf_port_info_members
5357 */
5358static PyMemberDef conf_port_info_members[] =
5359{
5360 {
5361 "slot_id", T_INT,
5362 offsetof(conf_port_info_Object, slot_id), 0,
5363 "Conference port number."
5364 },
5365 {
5366 "name", T_OBJECT_EX,
5367 offsetof(conf_port_info_Object, name), 0,
5368 "Port name"
5369 },
5370 {
5371 "clock_rate", T_INT,
5372 offsetof(conf_port_info_Object, clock_rate), 0,
5373 "Clock rate"
5374 },
5375 {
5376 "channel_count", T_INT,
5377 offsetof(conf_port_info_Object, channel_count), 0,
5378 "Number of channels."
5379 },
5380 {
5381 "samples_per_frame", T_INT,
5382 offsetof(conf_port_info_Object, samples_per_frame), 0,
5383 "Samples per frame "
5384 },
5385 {
5386 "bits_per_sample", T_INT,
5387 offsetof(conf_port_info_Object, bits_per_sample), 0,
5388 "Bits per sample"
5389 },
Fahris89ea3d02007-02-07 08:18:35 +00005390 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005391 "listener_cnt", T_INT,
5392 offsetof(conf_port_info_Object, listener_cnt), 0,
5393 "Number of listeners in the array."
Fahris89ea3d02007-02-07 08:18:35 +00005394 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005395 {
5396 "listeners", T_OBJECT_EX,
5397 offsetof(conf_port_info_Object, listeners), 0,
5398 "Array of listeners (in other words, ports where this port "
5399 "is transmitting to"
5400 },
5401
5402 {NULL} /* Sentinel */
5403};
5404
5405
5406
5407
5408/*
5409 * conf_port_info_Type
5410 */
5411static PyTypeObject conf_port_info_Type =
5412{
5413 PyObject_HEAD_INIT(NULL)
5414 0, /*ob_size*/
5415 "py_pjsua.Conf_Port_Info", /*tp_name*/
5416 sizeof(conf_port_info_Object), /*tp_basicsize*/
5417 0, /*tp_itemsize*/
5418 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
5419 0, /*tp_print*/
5420 0, /*tp_getattr*/
5421 0, /*tp_setattr*/
5422 0, /*tp_compare*/
5423 0, /*tp_repr*/
5424 0, /*tp_as_number*/
5425 0, /*tp_as_sequence*/
5426 0, /*tp_as_mapping*/
5427 0, /*tp_hash */
5428 0, /*tp_call*/
5429 0, /*tp_str*/
5430 0, /*tp_getattro*/
5431 0, /*tp_setattro*/
5432 0, /*tp_as_buffer*/
5433 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5434 "Conf Port Info objects", /* tp_doc */
5435 0, /* tp_traverse */
5436 0, /* tp_clear */
5437 0, /* tp_richcompare */
5438 0, /* tp_weaklistoffset */
5439 0, /* tp_iter */
5440 0, /* tp_iternext */
5441 0, /* tp_methods */
5442 conf_port_info_members, /* tp_members */
5443 0, /* tp_getset */
5444 0, /* tp_base */
5445 0, /* tp_dict */
5446 0, /* tp_descr_get */
5447 0, /* tp_descr_set */
5448 0, /* tp_dictoffset */
5449 0, /* tp_init */
5450 0, /* tp_alloc */
5451 conf_port_info_new, /* tp_new */
5452
5453};
5454
5455/*
5456 * pjmedia_port_Object
5457 */
5458typedef struct
5459{
5460 PyObject_HEAD
5461 /* Type-specific fields go here. */
5462 pjmedia_port * port;
5463} pjmedia_port_Object;
5464
5465
5466/*
5467 * pjmedia_port_Type
5468 */
5469static PyTypeObject pjmedia_port_Type =
5470{
5471 PyObject_HEAD_INIT(NULL)
5472 0, /*ob_size*/
5473 "py_pjsua.PJMedia_Port", /*tp_name*/
5474 sizeof(pjmedia_port_Object), /*tp_basicsize*/
5475 0, /*tp_itemsize*/
5476 0, /*tp_dealloc*/
5477 0, /*tp_print*/
5478 0, /*tp_getattr*/
5479 0, /*tp_setattr*/
5480 0, /*tp_compare*/
5481 0, /*tp_repr*/
5482 0, /*tp_as_number*/
5483 0, /*tp_as_sequence*/
5484 0, /*tp_as_mapping*/
5485 0, /*tp_hash */
5486 0, /*tp_call*/
5487 0, /*tp_str*/
5488 0, /*tp_getattro*/
5489 0, /*tp_setattro*/
5490 0, /*tp_as_buffer*/
5491 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5492 "pjmedia_port objects", /* tp_doc */
5493
5494};
5495
5496/*
5497 * pjmedia_snd_dev_info_Object
5498 * PJMedia Snd Dev Info
5499 */
5500typedef struct
5501{
5502 PyObject_HEAD
5503 /* Type-specific fields go here. */
5504
5505
5506 unsigned input_count;
5507 unsigned output_count;
5508 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00005509 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00005510
5511} pjmedia_snd_dev_info_Object;
5512
5513
5514/*
5515 * pjmedia_snd_dev_info_dealloc
5516 * deletes a pjmedia_snd_dev_info from memory
5517 */
5518static void pjmedia_snd_dev_info_dealloc(pjmedia_snd_dev_info_Object* self)
5519{
5520 Py_XDECREF(self->name);
5521 self->ob_type->tp_free((PyObject*)self);
5522}
5523
5524
5525/*
5526 * pjmedia_snd_dev_info_new
5527 * constructor for pjmedia_snd_dev_info object
5528 */
5529static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
5530 PyObject *kwds)
5531{
5532 pjmedia_snd_dev_info_Object *self;
5533
5534 self = (pjmedia_snd_dev_info_Object *)type->tp_alloc(type, 0);
5535 if (self != NULL)
5536 {
Fahrise314b882007-02-02 10:52:04 +00005537 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00005538 if (self->name == NULL)
5539 {
5540 Py_DECREF(self);
5541 return NULL;
5542 }
5543
5544 }
5545 return (PyObject *)self;
5546}
5547
5548/*
5549 * pjmedia_snd_dev_info_members
5550 */
5551static PyMemberDef pjmedia_snd_dev_info_members[] =
5552{
5553
5554 {
5555 "name", T_OBJECT_EX,
5556 offsetof(pjmedia_snd_dev_info_Object, name), 0,
5557 "Device name"
5558 },
5559 {
5560 "input_count", T_INT,
5561 offsetof(pjmedia_snd_dev_info_Object, input_count), 0,
5562 "Max number of input channels"
5563 },
5564 {
5565 "output_count", T_INT,
5566 offsetof(pjmedia_snd_dev_info_Object, output_count), 0,
5567 "Max number of output channels"
5568 },
5569 {
5570 "default_samples_per_sec", T_INT,
5571 offsetof(pjmedia_snd_dev_info_Object, default_samples_per_sec), 0,
5572 "Default sampling rate."
5573 },
5574
5575
5576 {NULL} /* Sentinel */
5577};
5578
5579
5580
5581
5582/*
5583 * pjmedia_snd_dev_info_Type
5584 */
5585static PyTypeObject pjmedia_snd_dev_info_Type =
5586{
5587 PyObject_HEAD_INIT(NULL)
5588 0, /*ob_size*/
5589 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
5590 sizeof(pjmedia_snd_dev_info_Object), /*tp_basicsize*/
5591 0, /*tp_itemsize*/
5592 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
5593 0, /*tp_print*/
5594 0, /*tp_getattr*/
5595 0, /*tp_setattr*/
5596 0, /*tp_compare*/
5597 0, /*tp_repr*/
5598 0, /*tp_as_number*/
5599 0, /*tp_as_sequence*/
5600 0, /*tp_as_mapping*/
5601 0, /*tp_hash */
5602 0, /*tp_call*/
5603 0, /*tp_str*/
5604 0, /*tp_getattro*/
5605 0, /*tp_setattro*/
5606 0, /*tp_as_buffer*/
5607 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5608 "PJMedia Snd Dev Info objects", /* tp_doc */
5609 0, /* tp_traverse */
5610 0, /* tp_clear */
5611 0, /* tp_richcompare */
5612 0, /* tp_weaklistoffset */
5613 0, /* tp_iter */
5614 0, /* tp_iternext */
5615 0, /* tp_methods */
5616 pjmedia_snd_dev_info_members, /* tp_members */
5617 0, /* tp_getset */
5618 0, /* tp_base */
5619 0, /* tp_dict */
5620 0, /* tp_descr_get */
5621 0, /* tp_descr_set */
5622 0, /* tp_dictoffset */
5623 0, /* tp_init */
5624 0, /* tp_alloc */
5625 pjmedia_snd_dev_info_new, /* tp_new */
5626
5627};
5628
5629/*
5630 * pjmedia_codec_param_info_Object
5631 * PJMedia Codec Param Info
5632 */
5633typedef struct
5634{
5635 PyObject_HEAD
5636 /* Type-specific fields go here. */
5637
5638 unsigned clock_rate;
5639 unsigned channel_cnt;
5640 pj_uint32_t avg_bps;
5641 pj_uint16_t frm_ptime;
5642 pj_uint8_t pcm_bits_per_sample;
5643 pj_uint8_t pt;
5644
5645} pjmedia_codec_param_info_Object;
5646
5647
5648
5649/*
5650 * pjmedia_codec_param_info_members
5651 */
5652static PyMemberDef pjmedia_codec_param_info_members[] =
5653{
5654
5655 {
5656 "clock_rate", T_INT,
5657 offsetof(pjmedia_codec_param_info_Object, clock_rate), 0,
5658 "Sampling rate in Hz"
5659 },
5660 {
5661 "channel_cnt", T_INT,
5662 offsetof(pjmedia_codec_param_info_Object, channel_cnt), 0,
5663 "Channel count"
5664 },
5665 {
5666 "avg_bps", T_INT,
5667 offsetof(pjmedia_codec_param_info_Object, avg_bps), 0,
5668 "Average bandwidth in bits/sec"
5669 },
5670 {
5671 "frm_ptime", T_INT,
5672 offsetof(pjmedia_codec_param_info_Object, frm_ptime), 0,
5673 "Base frame ptime in msec."
5674 },
5675 {
5676 "pcm_bits_per_sample", T_INT,
5677 offsetof(pjmedia_codec_param_info_Object, pcm_bits_per_sample), 0,
5678 "Bits/sample in the PCM side"
5679 },
5680 {
5681 "pt", T_INT,
5682 offsetof(pjmedia_codec_param_info_Object, pt), 0,
5683 "Payload type"
5684 },
5685
5686 {NULL} /* Sentinel */
5687};
5688
5689
5690
5691
5692/*
5693 * pjmedia_codec_param_info_Type
5694 */
5695static PyTypeObject pjmedia_codec_param_info_Type =
5696{
5697 PyObject_HEAD_INIT(NULL)
5698 0, /*ob_size*/
5699 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
5700 sizeof(pjmedia_codec_param_info_Object), /*tp_basicsize*/
5701 0, /*tp_itemsize*/
5702 0,/*tp_dealloc*/
5703 0, /*tp_print*/
5704 0, /*tp_getattr*/
5705 0, /*tp_setattr*/
5706 0, /*tp_compare*/
5707 0, /*tp_repr*/
5708 0, /*tp_as_number*/
5709 0, /*tp_as_sequence*/
5710 0, /*tp_as_mapping*/
5711 0, /*tp_hash */
5712 0, /*tp_call*/
5713 0, /*tp_str*/
5714 0, /*tp_getattro*/
5715 0, /*tp_setattro*/
5716 0, /*tp_as_buffer*/
5717 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5718 "PJMedia Codec Param Info objects", /* tp_doc */
5719 0, /* tp_traverse */
5720 0, /* tp_clear */
5721 0, /* tp_richcompare */
5722 0, /* tp_weaklistoffset */
5723 0, /* tp_iter */
5724 0, /* tp_iternext */
5725 0, /* tp_methods */
5726 pjmedia_codec_param_info_members, /* tp_members */
5727
5728
5729};
5730
5731/*
5732 * pjmedia_codec_param_setting_Object
5733 * PJMedia Codec Param Setting
5734 */
5735typedef struct
5736{
5737 PyObject_HEAD
5738 /* Type-specific fields go here. */
5739 pj_uint8_t frm_per_pkt;
5740 unsigned vad;
5741 unsigned cng;
5742 unsigned penh;
5743 unsigned plc;
5744 unsigned reserved;
5745 pj_uint8_t enc_fmtp_mode;
5746 pj_uint8_t dec_fmtp_mode;
5747
5748} pjmedia_codec_param_setting_Object;
5749
5750
5751
5752/*
5753 * pjmedia_codec_param_setting_members
5754 */
5755static PyMemberDef pjmedia_codec_param_setting_members[] =
5756{
5757
5758 {
5759 "frm_per_pkt", T_INT,
5760 offsetof(pjmedia_codec_param_setting_Object, frm_per_pkt), 0,
5761 "Number of frames per packet"
5762 },
5763 {
5764 "vad", T_INT,
5765 offsetof(pjmedia_codec_param_setting_Object, vad), 0,
5766 "Voice Activity Detector"
5767 },
5768 {
5769 "penh", T_INT,
5770 offsetof(pjmedia_codec_param_setting_Object, penh), 0,
5771 "Perceptual Enhancement"
5772 },
5773 {
5774 "plc", T_INT,
5775 offsetof(pjmedia_codec_param_setting_Object, plc), 0,
5776 "Packet loss concealment"
5777 },
5778 {
5779 "reserved", T_INT,
5780 offsetof(pjmedia_codec_param_setting_Object, reserved), 0,
5781 "Reserved, must be zero"
5782 },
5783 {
5784 "cng", T_INT,
5785 offsetof(pjmedia_codec_param_setting_Object, cng), 0,
5786 "Comfort Noise Generator"
5787 },
5788 {
5789 "enc_fmtp_mode", T_INT,
5790 offsetof(pjmedia_codec_param_setting_Object, enc_fmtp_mode), 0,
5791 "Mode param in fmtp (def:0)"
5792 },
5793 {
5794 "dec_fmtp_mode", T_INT,
5795 offsetof(pjmedia_codec_param_setting_Object, dec_fmtp_mode), 0,
5796 "Mode param in fmtp (def:0)"
5797 },
5798
5799 {NULL} /* Sentinel */
5800};
5801
5802
5803
5804
5805/*
5806 * pjmedia_codec_param_setting_Type
5807 */
5808static PyTypeObject pjmedia_codec_param_setting_Type =
5809{
5810 PyObject_HEAD_INIT(NULL)
5811 0, /*ob_size*/
5812 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
5813 sizeof(pjmedia_codec_param_setting_Object), /*tp_basicsize*/
5814 0, /*tp_itemsize*/
5815 0,/*tp_dealloc*/
5816 0, /*tp_print*/
5817 0, /*tp_getattr*/
5818 0, /*tp_setattr*/
5819 0, /*tp_compare*/
5820 0, /*tp_repr*/
5821 0, /*tp_as_number*/
5822 0, /*tp_as_sequence*/
5823 0, /*tp_as_mapping*/
5824 0, /*tp_hash */
5825 0, /*tp_call*/
5826 0, /*tp_str*/
5827 0, /*tp_getattro*/
5828 0, /*tp_setattro*/
5829 0, /*tp_as_buffer*/
5830 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5831 "PJMedia Codec Param Setting objects", /* tp_doc */
5832 0, /* tp_traverse */
5833 0, /* tp_clear */
5834 0, /* tp_richcompare */
5835 0, /* tp_weaklistoffset */
5836 0, /* tp_iter */
5837 0, /* tp_iternext */
5838 0, /* tp_methods */
5839 pjmedia_codec_param_setting_members, /* tp_members */
5840
5841
5842};
5843
5844/*
5845 * pjmedia_codec_param_Object
5846 * PJMedia Codec Param
5847 */
5848typedef struct
5849{
5850 PyObject_HEAD
5851 /* Type-specific fields go here. */
5852
5853 pjmedia_codec_param_info_Object * info;
5854 pjmedia_codec_param_setting_Object * setting;
5855
5856} pjmedia_codec_param_Object;
5857
5858
5859/*
5860 * pjmedia_codec_param_dealloc
5861 * deletes a pjmedia_codec_param from memory
5862 */
5863static void pjmedia_codec_param_dealloc(pjmedia_codec_param_Object* self)
5864{
5865 Py_XDECREF(self->info);
5866 Py_XDECREF(self->setting);
5867 self->ob_type->tp_free((PyObject*)self);
5868}
5869
5870
5871/*
5872 * pjmedia_codec_param_new
5873 * constructor for pjmedia_codec_param object
5874 */
5875static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
5876 PyObject *kwds)
5877{
5878 pjmedia_codec_param_Object *self;
5879
5880 self = (pjmedia_codec_param_Object *)type->tp_alloc(type, 0);
5881 if (self != NULL)
5882 {
5883 self->info = (pjmedia_codec_param_info_Object *)
5884 PyType_GenericNew(&pjmedia_codec_param_info_Type, NULL, NULL);
5885 if (self->info == NULL)
5886 {
5887 Py_DECREF(self);
5888 return NULL;
5889 }
5890 self->setting = (pjmedia_codec_param_setting_Object *)
5891 PyType_GenericNew(&pjmedia_codec_param_setting_Type, NULL, NULL);
5892 if (self->setting == NULL)
5893 {
5894 Py_DECREF(self);
5895 return NULL;
5896 }
5897 }
5898 return (PyObject *)self;
5899}
5900
5901/*
5902 * pjmedia_codec_param_members
5903 */
5904static PyMemberDef pjmedia_codec_param_members[] =
5905{
5906
5907 {
5908 "info", T_OBJECT_EX,
5909 offsetof(pjmedia_codec_param_Object, info), 0,
5910 "The 'info' part of codec param describes the capability of the codec,"
5911 " and the value should NOT be changed by application."
5912 },
5913 {
5914 "setting", T_OBJECT_EX,
5915 offsetof(pjmedia_codec_param_Object, setting), 0,
5916 "The 'setting' part of codec param describes various settings to be "
5917 "applied to the codec. When the codec param is retrieved from the "
5918 "codec or codec factory, the values of these will be filled by "
5919 "the capability of the codec. Any features that are supported by "
5920 "the codec (e.g. vad or plc) will be turned on, so that application "
5921 "can query which capabilities are supported by the codec. "
5922 "Application may change the settings here before instantiating "
5923 "the codec/stream."
5924 },
5925
5926 {NULL} /* Sentinel */
5927};
5928
5929
5930
5931
5932/*
5933 * pjmedia_codec_param_Type
5934 */
5935static PyTypeObject pjmedia_codec_param_Type =
5936{
5937 PyObject_HEAD_INIT(NULL)
5938 0, /*ob_size*/
5939 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
5940 sizeof(pjmedia_codec_param_Object), /*tp_basicsize*/
5941 0, /*tp_itemsize*/
5942 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
5943 0, /*tp_print*/
5944 0, /*tp_getattr*/
5945 0, /*tp_setattr*/
5946 0, /*tp_compare*/
5947 0, /*tp_repr*/
5948 0, /*tp_as_number*/
5949 0, /*tp_as_sequence*/
5950 0, /*tp_as_mapping*/
5951 0, /*tp_hash */
5952 0, /*tp_call*/
5953 0, /*tp_str*/
5954 0, /*tp_getattro*/
5955 0, /*tp_setattro*/
5956 0, /*tp_as_buffer*/
5957 Py_TPFLAGS_DEFAULT, /*tp_flags*/
5958 "PJMedia Codec Param objects", /* tp_doc */
5959 0, /* tp_traverse */
5960 0, /* tp_clear */
5961 0, /* tp_richcompare */
5962 0, /* tp_weaklistoffset */
5963 0, /* tp_iter */
5964 0, /* tp_iternext */
5965 0, /* tp_methods */
5966 pjmedia_codec_param_members, /* tp_members */
5967 0, /* tp_getset */
5968 0, /* tp_base */
5969 0, /* tp_dict */
5970 0, /* tp_descr_get */
5971 0, /* tp_descr_set */
5972 0, /* tp_dictoffset */
5973 0, /* tp_init */
5974 0, /* tp_alloc */
5975 pjmedia_codec_param_new, /* tp_new */
5976
5977};
5978
5979/*
5980 * py_pjsua_conf_get_max_ports
5981 */
5982static PyObject *py_pjsua_conf_get_max_ports
5983(PyObject *pSelf, PyObject *pArgs)
5984{
5985 int ret;
5986
5987 if (!PyArg_ParseTuple(pArgs, ""))
5988 {
5989 return NULL;
5990 }
5991 ret = pjsua_conf_get_max_ports();
5992
5993 return Py_BuildValue("i", ret);
5994}
5995
5996/*
5997 * py_pjsua_conf_get_active_ports
5998 */
5999static PyObject *py_pjsua_conf_get_active_ports
6000(PyObject *pSelf, PyObject *pArgs)
6001{
6002 int ret;
6003 if (!PyArg_ParseTuple(pArgs, ""))
6004 {
6005 return NULL;
6006 }
6007 ret = pjsua_conf_get_active_ports();
6008
6009 return Py_BuildValue("i", ret);
6010}
6011
6012/*
6013 * py_pjsua_enum_conf_ports
6014 * !modified @ 241206
6015 */
6016static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
6017{
6018 pj_status_t status;
6019 PyObject *list;
6020
6021 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00006022 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006023 if (!PyArg_ParseTuple(pArgs, ""))
6024 {
6025 return NULL;
6026 }
6027
6028 c = PJ_ARRAY_SIZE(id);
6029 status = pjsua_enum_conf_ports(id, &c);
6030
6031 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006032 for (i = 0; i < c; i++)
6033 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006034 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00006035 if (ret == -1)
6036 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006037 return NULL;
6038 }
6039 }
6040
Fahrisdcf8fa42006-12-28 03:13:48 +00006041 return Py_BuildValue("O",list);
6042}
6043
6044/*
6045 * py_pjsua_conf_get_port_info
6046 */
6047static PyObject *py_pjsua_conf_get_port_info
6048(PyObject *pSelf, PyObject *pArgs)
6049{
6050 int id;
6051 conf_port_info_Object * obj;
6052 pjsua_conf_port_info info;
6053 int status;
6054 int i;
6055
6056 if (!PyArg_ParseTuple(pArgs, "i", &id))
6057 {
6058 return NULL;
6059 }
6060
6061
6062 status = pjsua_conf_get_port_info(id, &info);
6063 obj = (conf_port_info_Object *)conf_port_info_new
6064 (&conf_port_info_Type,NULL,NULL);
6065 obj->bits_per_sample = info.bits_per_sample;
6066 obj->channel_count = info.bits_per_sample;
6067 obj->clock_rate = info.clock_rate;
6068 obj->listener_cnt = info.listener_cnt;
6069 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
6070 obj->samples_per_frame = info.samples_per_frame;
6071 obj->slot_id = info.slot_id;
6072
Fahris6f35cb82007-02-01 07:41:26 +00006073 for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00006074 PyObject * item = Py_BuildValue("i",info.listeners[i]);
6075 PyList_SetItem((PyObject *)obj->listeners, i, item);
6076 }
6077 return Py_BuildValue("O", obj);
6078}
6079
6080/*
6081 * py_pjsua_conf_add_port
6082 */
6083static PyObject *py_pjsua_conf_add_port
6084(PyObject *pSelf, PyObject *pArgs)
6085{
6086 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00006087 PyObject * oportObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006088 pjmedia_port_Object * oport;
Fahris6f35cb82007-02-01 07:41:26 +00006089 pjmedia_port * port;
6090 PyObject * opoolObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006091 pj_pool_Object * opool;
Fahris6f35cb82007-02-01 07:41:26 +00006092 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00006093
6094 int status;
6095
6096
Fahris17d91812007-01-29 12:09:33 +00006097 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006098 {
6099 return NULL;
6100 }
Fahris17d91812007-01-29 12:09:33 +00006101 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006102 {
Fahris17d91812007-01-29 12:09:33 +00006103 opool = (pj_pool_Object *)opoolObj;
6104 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00006105 } else {
6106 opool = NULL;
6107 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00006108 }
6109 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006110 {
Fahris17d91812007-01-29 12:09:33 +00006111 oport = (pjmedia_port_Object *)oportObj;
6112 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00006113 } else {
Fahris17d91812007-01-29 12:09:33 +00006114 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00006115 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00006116 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006117
Fahris17d91812007-01-29 12:09:33 +00006118 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00006119
6120
6121 return Py_BuildValue("ii", status, p_id);
6122}
6123
6124/*
6125 * py_pjsua_conf_remove_port
6126 */
6127static PyObject *py_pjsua_conf_remove_port
6128(PyObject *pSelf, PyObject *pArgs)
6129{
6130 int id;
6131 int status;
6132
6133
6134 if (!PyArg_ParseTuple(pArgs, "i", &id))
6135 {
6136 return NULL;
6137 }
6138
6139 status = pjsua_conf_remove_port(id);
6140
6141
6142 return Py_BuildValue("i", status);
6143}
6144
6145/*
6146 * py_pjsua_conf_connect
6147 */
6148static PyObject *py_pjsua_conf_connect
6149(PyObject *pSelf, PyObject *pArgs)
6150{
6151 int source, sink;
6152 int status;
6153
6154
6155 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6156 {
6157 return NULL;
6158 }
6159
6160 status = pjsua_conf_connect(source, sink);
6161
6162
6163 return Py_BuildValue("i", status);
6164}
6165
6166/*
6167 * py_pjsua_conf_disconnect
6168 */
6169static PyObject *py_pjsua_conf_disconnect
6170(PyObject *pSelf, PyObject *pArgs)
6171{
6172 int source, sink;
6173 int status;
6174
6175
6176 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
6177 {
6178 return NULL;
6179 }
6180
6181 status = pjsua_conf_disconnect(source, sink);
6182
6183
6184 return Py_BuildValue("i", status);
6185}
6186
6187/*
6188 * py_pjsua_player_create
6189 */
6190static PyObject *py_pjsua_player_create
6191(PyObject *pSelf, PyObject *pArgs)
6192{
6193 int id;
6194 int options;
6195 PyObject * filename;
6196 pj_str_t str;
6197 int status;
6198
6199
6200 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
6201 {
6202 return NULL;
6203 }
6204 str.ptr = PyString_AsString(filename);
6205 str.slen = strlen(PyString_AsString(filename));
6206 status = pjsua_player_create(&str, options, &id);
6207
6208 return Py_BuildValue("ii", status, id);
6209}
6210
6211/*
6212 * py_pjsua_player_get_conf_port
6213 */
6214static PyObject *py_pjsua_player_get_conf_port
6215(PyObject *pSelf, PyObject *pArgs)
6216{
6217
6218 int id, port_id;
6219
6220
6221 if (!PyArg_ParseTuple(pArgs, "i", &id))
6222 {
6223 return NULL;
6224 }
6225
6226 port_id = pjsua_player_get_conf_port(id);
6227
6228
6229 return Py_BuildValue("i", port_id);
6230}
6231
6232/*
6233 * py_pjsua_player_set_pos
6234 */
6235static PyObject *py_pjsua_player_set_pos
6236(PyObject *pSelf, PyObject *pArgs)
6237{
6238 int id;
6239 pj_uint32_t samples;
6240 int status;
6241
6242
6243 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
6244 {
6245 return NULL;
6246 }
6247
6248 status = pjsua_player_set_pos(id, samples);
6249
6250
6251 return Py_BuildValue("i", status);
6252}
6253
6254/*
6255 * py_pjsua_player_destroy
6256 */
6257static PyObject *py_pjsua_player_destroy
6258(PyObject *pSelf, PyObject *pArgs)
6259{
6260 int id;
6261 int status;
6262
6263
6264 if (!PyArg_ParseTuple(pArgs, "i", &id))
6265 {
6266 return NULL;
6267 }
6268
6269 status = pjsua_player_destroy(id);
6270
6271
6272 return Py_BuildValue("i", status);
6273}
6274
6275/*
6276 * py_pjsua_recorder_create
6277 * !modified @ 261206
6278 */
6279static PyObject *py_pjsua_recorder_create
6280(PyObject *pSelf, PyObject *pArgs)
6281{
6282 int p_id;
6283 int options;
6284 int max_size;
6285 PyObject * filename;
6286 pj_str_t str;
6287 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00006288 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00006289 int enc_type;
6290
6291 int status;
6292
6293
Fahris17d91812007-01-29 12:09:33 +00006294 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
6295 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00006296 {
6297 return NULL;
6298 }
6299 str.ptr = PyString_AsString(filename);
6300 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00006301 if (enc_param != Py_None)
6302 {
6303 strparam.ptr = PyString_AsString(enc_param);
6304 strparam.slen = strlen(PyString_AsString(enc_param));
6305 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00006306 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00006307 } else {
6308 status = pjsua_recorder_create
6309 (&str, enc_type, NULL, max_size, options, &p_id);
6310 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006311 return Py_BuildValue("ii", status, p_id);
6312}
6313
6314/*
6315 * py_pjsua_recorder_get_conf_port
6316 */
6317static PyObject *py_pjsua_recorder_get_conf_port
6318(PyObject *pSelf, PyObject *pArgs)
6319{
6320
6321 int id, port_id;
6322
6323
6324 if (!PyArg_ParseTuple(pArgs, "i", &id))
6325 {
6326 return NULL;
6327 }
6328
6329 port_id = pjsua_recorder_get_conf_port(id);
6330
6331
6332 return Py_BuildValue("i", port_id);
6333}
6334
6335/*
6336 * py_pjsua_recorder_destroy
6337 */
6338static PyObject *py_pjsua_recorder_destroy
6339(PyObject *pSelf, PyObject *pArgs)
6340{
6341 int id;
6342 int status;
6343
6344
6345 if (!PyArg_ParseTuple(pArgs, "i", &id))
6346 {
6347 return NULL;
6348 }
6349
6350 status = pjsua_recorder_destroy(id);
6351
6352
6353 return Py_BuildValue("i", status);
6354}
6355
6356/*
6357 * py_pjsua_enum_snd_devs
6358 */
6359static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
6360{
6361 pj_status_t status;
6362 PyObject *list;
6363
Fahris6f35cb82007-02-01 07:41:26 +00006364 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00006365 unsigned c, i;
Fahrisb721aa32007-01-29 05:07:41 +00006366 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00006367 {
6368 return NULL;
6369 }
6370
Fahrisb721aa32007-01-29 05:07:41 +00006371 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00006372 status = pjsua_enum_snd_devs(info, &c);
6373
6374 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006375 for (i = 0; i < c; i++)
6376 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006377 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00006378 int j;
Fahrise314b882007-02-02 10:52:04 +00006379 char * str;
6380
Fahrisdcf8fa42006-12-28 03:13:48 +00006381 pjmedia_snd_dev_info_Object * obj;
6382 obj = (pjmedia_snd_dev_info_Object *)pjmedia_snd_dev_info_new
6383 (&pjmedia_snd_dev_info_Type, NULL, NULL);
6384 obj->default_samples_per_sec = info[i].default_samples_per_sec;
6385 obj->input_count = info[i].input_count;
6386 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00006387 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
6388 memset(str, 0, SND_NAME_LEN);
6389 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00006390 {
Fahrise314b882007-02-02 10:52:04 +00006391 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00006392 }
Fahrise314b882007-02-02 10:52:04 +00006393 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
6394 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00006395 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00006396 if (ret == -1)
6397 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006398 return NULL;
6399 }
6400 }
6401
Fahrisdcf8fa42006-12-28 03:13:48 +00006402 return Py_BuildValue("O",list);
6403}
6404
6405/*
6406 * py_pjsua_get_snd_dev
6407 */
6408static PyObject *py_pjsua_get_snd_dev
6409(PyObject *pSelf, PyObject *pArgs)
6410{
6411 int capture_dev, playback_dev;
6412 int status;
6413
6414
6415 if (!PyArg_ParseTuple(pArgs, ""))
6416 {
6417 return NULL;
6418 }
6419
6420 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
6421
6422
6423 return Py_BuildValue("ii", capture_dev, playback_dev);
6424}
6425
6426/*
6427 * py_pjsua_set_snd_dev
6428 */
6429static PyObject *py_pjsua_set_snd_dev
6430(PyObject *pSelf, PyObject *pArgs)
6431{
6432 int capture_dev, playback_dev;
6433 int status;
6434
6435
6436 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
6437 {
6438 return NULL;
6439 }
6440
6441 status = pjsua_set_snd_dev(capture_dev, playback_dev);
6442
6443
6444 return Py_BuildValue("i", status);
6445}
6446
6447/*
6448 * py_pjsua_set_null_snd_dev
6449 */
6450static PyObject *py_pjsua_set_null_snd_dev
6451(PyObject *pSelf, PyObject *pArgs)
6452{
6453
6454 int status;
6455
6456
6457 if (!PyArg_ParseTuple(pArgs, ""))
6458 {
6459 return NULL;
6460 }
6461
6462 status = pjsua_set_null_snd_dev();
6463
6464
6465 return Py_BuildValue("i", status);
6466}
6467
6468/*
6469 * py_pjsua_set_no_snd_dev
6470 */
6471static PyObject *py_pjsua_set_no_snd_dev
6472(PyObject *pSelf, PyObject *pArgs)
6473{
6474
6475 pjmedia_port_Object * obj;
6476
6477 if (!PyArg_ParseTuple(pArgs, ""))
6478 {
6479 return NULL;
6480 }
6481
6482 obj = (pjmedia_port_Object *)PyType_GenericNew
6483 (&pjmedia_port_Type, NULL, NULL);
6484 obj->port = pjsua_set_no_snd_dev();
6485 return Py_BuildValue("O", obj);
6486}
6487
6488/*
6489 * py_pjsua_set_ec
6490 */
6491static PyObject *py_pjsua_set_ec
6492(PyObject *pSelf, PyObject *pArgs)
6493{
6494 int options;
6495 int tail_ms;
6496 int status;
6497
6498
6499 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
6500 {
6501 return NULL;
6502 }
6503
6504 status = pjsua_set_ec(tail_ms, options);
6505
6506
6507 return Py_BuildValue("i", status);
6508}
6509
6510/*
6511 * py_pjsua_get_ec_tail
6512 */
6513static PyObject *py_pjsua_get_ec_tail
6514(PyObject *pSelf, PyObject *pArgs)
6515{
6516
6517 int status;
Fahris17d91812007-01-29 12:09:33 +00006518 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00006519
6520 if (!PyArg_ParseTuple(pArgs, ""))
6521 {
6522 return NULL;
6523 }
6524
6525 status = pjsua_get_ec_tail(&p_tail_ms);
6526
6527
6528 return Py_BuildValue("i", p_tail_ms);
6529}
6530
6531/*
6532 * py_pjsua_enum_codecs
6533 * !modified @ 261206
6534 */
6535static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
6536{
6537 pj_status_t status;
6538 PyObject *list;
6539
6540 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00006541 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00006542 if (!PyArg_ParseTuple(pArgs, ""))
6543 {
6544 return NULL;
6545 }
6546
6547 c = PJ_ARRAY_SIZE(info);
6548 status = pjsua_enum_codecs(info, &c);
6549
6550 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00006551 for (i = 0; i < c; i++)
6552 {
Fahrisdcf8fa42006-12-28 03:13:48 +00006553 int ret;
6554 int j;
6555 codec_info_Object * obj;
6556 obj = (codec_info_Object *)codec_info_new
6557 (&codec_info_Type, NULL, NULL);
6558 obj->codec_id = PyString_FromStringAndSize
6559 (info[i].codec_id.ptr, info[i].codec_id.slen);
6560 obj->priority = info[i].priority;
6561 for (j = 0; j < 32; j++)
6562 {
6563 obj->buf_[j] = info[i].buf_[j];
6564 }
6565 ret = PyList_SetItem(list, i, (PyObject *)obj);
6566 if (ret == -1) {
6567 return NULL;
6568 }
6569 }
6570
Fahris17d91812007-01-29 12:09:33 +00006571
Fahrisdcf8fa42006-12-28 03:13:48 +00006572 return Py_BuildValue("O",list);
6573}
6574
6575/*
6576 * py_pjsua_codec_set_priority
6577 */
6578static PyObject *py_pjsua_codec_set_priority
6579(PyObject *pSelf, PyObject *pArgs)
6580{
6581
6582 int status;
6583 PyObject * id;
6584 pj_str_t str;
6585 pj_uint8_t priority;
6586
6587 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
6588 {
6589 return NULL;
6590 }
6591 str.ptr = PyString_AsString(id);
6592 str.slen = strlen(PyString_AsString(id));
6593 status = pjsua_codec_set_priority(&str, priority);
6594
6595
6596 return Py_BuildValue("i", status);
6597}
6598
6599/*
6600 * py_pjsua_codec_get_param
6601 */
6602static PyObject *py_pjsua_codec_get_param
6603(PyObject *pSelf, PyObject *pArgs)
6604{
6605
6606 int status;
6607 PyObject * id;
6608 pj_str_t str;
6609 pjmedia_codec_param param;
6610 pjmedia_codec_param_Object *obj;
6611
6612
6613 if (!PyArg_ParseTuple(pArgs, "O", &id))
6614 {
6615 return NULL;
6616 }
6617 str.ptr = PyString_AsString(id);
6618 str.slen = strlen(PyString_AsString(id));
6619 status = pjsua_codec_get_param(&str, &param);
6620 obj = (pjmedia_codec_param_Object *)pjmedia_codec_param_new
6621 (&pjmedia_codec_param_Type, NULL, NULL);
6622 obj->info->avg_bps = param.info.avg_bps;
6623 obj->info->channel_cnt = param.info.channel_cnt;
6624 obj->info->clock_rate = param.info.clock_rate;
6625 obj->info->frm_ptime = param.info.frm_ptime;
6626 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
6627 obj->info->pt = param.info.pt;
6628 obj->setting->cng = param.setting.cng;
6629 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
6630 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
6631 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
6632 obj->setting->penh = param.setting.penh;
6633 obj->setting->plc = param.setting.plc;
6634 obj->setting->reserved = param.setting.reserved;
6635 obj->setting->vad = param.setting.vad;
6636
6637 return Py_BuildValue("O", obj);
6638}
6639/*
6640 * py_pjsua_codec_set_param
6641 */
6642static PyObject *py_pjsua_codec_set_param
6643(PyObject *pSelf, PyObject *pArgs)
6644{
6645
6646 int status;
6647 PyObject * id;
6648 pj_str_t str;
6649 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00006650 PyObject * tmpObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00006651 pjmedia_codec_param_Object *obj;
6652
6653
Fahris17d91812007-01-29 12:09:33 +00006654 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00006655 {
6656 return NULL;
6657 }
Fahris17d91812007-01-29 12:09:33 +00006658
Fahrisdcf8fa42006-12-28 03:13:48 +00006659 str.ptr = PyString_AsString(id);
6660 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00006661 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00006662 {
Fahris17d91812007-01-29 12:09:33 +00006663 obj = (pjmedia_codec_param_Object *)tmpObj;
6664 param.info.avg_bps = obj->info->avg_bps;
6665 param.info.channel_cnt = obj->info->channel_cnt;
6666 param.info.clock_rate = obj->info->clock_rate;
6667 param.info.frm_ptime = obj->info->frm_ptime;
6668 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
6669 param.info.pt = obj->info->pt;
6670 param.setting.cng = obj->setting->cng;
6671 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
6672 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
6673 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
6674 param.setting.penh = obj->setting->penh;
6675 param.setting.plc = obj->setting->plc;
6676 param.setting.reserved = obj->setting->reserved;
6677 param.setting.vad = obj->setting->vad;
6678 status = pjsua_codec_set_param(&str, &param);
6679 } else {
6680 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00006681 }
Fahrisdcf8fa42006-12-28 03:13:48 +00006682 return Py_BuildValue("i", status);
6683}
6684
6685static char pjsua_conf_get_max_ports_doc[] =
6686 "int py_pjsua.conf_get_max_ports () "
6687 "Get maxinum number of conference ports.";
6688static char pjsua_conf_get_active_ports_doc[] =
6689 "int py_pjsua.conf_get_active_ports () "
6690 "Get current number of active ports in the bridge.";
6691static char pjsua_enum_conf_ports_doc[] =
6692 "int[] py_pjsua.enum_conf_ports () "
6693 "Enumerate all conference ports.";
6694static char pjsua_conf_get_port_info_doc[] =
6695 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
6696 "Get information about the specified conference port";
6697static char pjsua_conf_add_port_doc[] =
6698 "int, int py_pjsua.conf_add_port "
6699 "(py_pjsua.PJ_Pool pool, py_pjsua.PJMedia_Port port) "
6700 "Add arbitrary media port to PJSUA's conference bridge. "
6701 "Application can use this function to add the media port "
6702 "that it creates. For media ports that are created by PJSUA-LIB "
6703 "(such as calls, file player, or file recorder), PJSUA-LIB will "
6704 "automatically add the port to the bridge.";
6705static char pjsua_conf_remove_port_doc[] =
6706 "int py_pjsua.conf_remove_port (int id) "
6707 "Remove arbitrary slot from the conference bridge. "
6708 "Application should only call this function "
6709 "if it registered the port manually.";
6710static char pjsua_conf_connect_doc[] =
6711 "int py_pjsua.conf_connect (int source, int sink) "
6712 "Establish unidirectional media flow from souce to sink. "
6713 "One source may transmit to multiple destinations/sink. "
6714 "And if multiple sources are transmitting to the same sink, "
6715 "the media will be mixed together. Source and sink may refer "
6716 "to the same ID, effectively looping the media. "
6717 "If bidirectional media flow is desired, application "
6718 "needs to call this function twice, with the second "
6719 "one having the arguments reversed.";
6720static char pjsua_conf_disconnect_doc[] =
6721 "int py_pjsua.conf_disconnect (int source, int sink) "
6722 "Disconnect media flow from the source to destination port.";
6723static char pjsua_player_create_doc[] =
6724 "int, int py_pjsua.player_create (string filename, int options) "
6725 "Create a file player, and automatically connect "
6726 "this player to the conference bridge.";
6727static char pjsua_player_get_conf_port_doc[] =
6728 "int py_pjsua.player_get_conf_port (int) "
6729 "Get conference port ID associated with player.";
6730static char pjsua_player_set_pos_doc[] =
6731 "int py_pjsua.player_set_pos (int id, int samples) "
6732 "Set playback position.";
6733static char pjsua_player_destroy_doc[] =
6734 "int py_pjsua.player_destroy (int id) "
6735 "Close the file, remove the player from the bridge, "
6736 "and free resources associated with the file player.";
6737static char pjsua_recorder_create_doc[] =
6738 "int, int py_pjsua.recorder_create (string filename, "
6739 "int enc_type, int enc_param, int max_size, int options) "
6740 "Create a file recorder, and automatically connect this recorder "
6741 "to the conference bridge. The recorder currently supports recording "
6742 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
6743 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
6744static char pjsua_recorder_get_conf_port_doc[] =
6745 "int py_pjsua.recorder_get_conf_port (int id) "
6746 "Get conference port associated with recorder.";
6747static char pjsua_recorder_destroy_doc[] =
6748 "int py_pjsua.recorder_destroy (int id) "
6749 "Destroy recorder (this will complete recording).";
6750static char pjsua_enum_snd_devs_doc[] =
6751 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
6752 "Enum sound devices.";
6753static char pjsua_get_snd_dev_doc[] =
6754 "int, int py_pjsua.get_snd_dev () "
6755 "Get currently active sound devices. "
6756 "If sound devices has not been created "
6757 "(for example when pjsua_start() is not called), "
6758 "it is possible that the function returns "
6759 "PJ_SUCCESS with -1 as device IDs.";
6760static char pjsua_set_snd_dev_doc[] =
6761 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
6762 "Select or change sound device. Application may call this function "
6763 "at any time to replace current sound device.";
6764static char pjsua_set_null_snd_dev_doc[] =
6765 "int py_pjsua.set_null_snd_dev () "
6766 "Set pjsua to use null sound device. The null sound device only "
6767 "provides the timing needed by the conference bridge, and will not "
6768 "interract with any hardware.";
6769static char pjsua_set_no_snd_dev_doc[] =
6770 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
6771 "Disconnect the main conference bridge from any sound devices, "
6772 "and let application connect the bridge to it's "
6773 "own sound device/master port.";
6774static char pjsua_set_ec_doc[] =
6775 "int py_pjsua.set_ec (int tail_ms, int options) "
6776 "Configure the echo canceller tail length of the sound port.";
6777static char pjsua_get_ec_tail_doc[] =
6778 "int py_pjsua.get_ec_tail () "
6779 "Get current echo canceller tail length.";
6780static char pjsua_enum_codecs_doc[] =
6781 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
6782 "Enum all supported codecs in the system.";
6783static char pjsua_codec_set_priority_doc[] =
6784 "int py_pjsua.codec_set_priority (string id, int priority) "
6785 "Change codec priority.";
6786static char pjsua_codec_get_param_doc[] =
6787 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
6788 "Get codec parameters";
6789static char pjsua_codec_set_param_doc[] =
6790 "int py_pjsua.codec_set_param (string id, "
6791 "py_pjsua.PJMedia_Codec_Param param) "
6792 "Set codec parameters.";
6793
6794/* END OF LIB MEDIA */
6795
6796/* LIB CALL */
6797
6798/*
6799 * pj_time_val_Object
6800 * PJ Time Val
6801 */
6802typedef struct
6803{
6804 PyObject_HEAD
6805 /* Type-specific fields go here. */
6806 long sec;
6807 long msec;
6808
6809} pj_time_val_Object;
6810
6811
6812
6813/*
6814 * pj_time_val_members
6815 */
6816static PyMemberDef pj_time_val_members[] =
6817{
6818
6819 {
6820 "sec", T_INT,
6821 offsetof(pj_time_val_Object, sec), 0,
6822 "The seconds part of the time"
6823 },
6824 {
6825 "msec", T_INT,
6826 offsetof(pj_time_val_Object, sec), 0,
6827 "The milliseconds fraction of the time"
6828 },
6829
6830
6831 {NULL} /* Sentinel */
6832};
6833
6834
6835
6836
6837/*
6838 * pj_time_val_Type
6839 */
6840static PyTypeObject pj_time_val_Type =
6841{
6842 PyObject_HEAD_INIT(NULL)
6843 0, /*ob_size*/
6844 "py_pjsua.PJ_Time_Val", /*tp_name*/
6845 sizeof(pj_time_val_Object), /*tp_basicsize*/
6846 0, /*tp_itemsize*/
6847 0,/*tp_dealloc*/
6848 0, /*tp_print*/
6849 0, /*tp_getattr*/
6850 0, /*tp_setattr*/
6851 0, /*tp_compare*/
6852 0, /*tp_repr*/
6853 0, /*tp_as_number*/
6854 0, /*tp_as_sequence*/
6855 0, /*tp_as_mapping*/
6856 0, /*tp_hash */
6857 0, /*tp_call*/
6858 0, /*tp_str*/
6859 0, /*tp_getattro*/
6860 0, /*tp_setattro*/
6861 0, /*tp_as_buffer*/
6862 Py_TPFLAGS_DEFAULT, /*tp_flags*/
6863 "PJ Time Val objects", /* tp_doc */
6864 0, /* tp_traverse */
6865 0, /* tp_clear */
6866 0, /* tp_richcompare */
6867 0, /* tp_weaklistoffset */
6868 0, /* tp_iter */
6869 0, /* tp_iternext */
6870 0, /* tp_methods */
6871 pj_time_val_members, /* tp_members */
6872
6873
6874};
6875
6876/*
6877 * call_info_Object
6878 * Call Info
6879 */
6880typedef struct
6881{
6882 PyObject_HEAD
6883 /* Type-specific fields go here. */
6884
6885 int id;
6886 int role;
6887 int acc_id;
6888 PyObject * local_info;
6889 PyObject * local_contact;
6890 PyObject * remote_info;
6891 PyObject * remote_contact;
6892 PyObject * call_id;
6893 int state;
6894 PyObject * state_text;
6895 int last_status;
6896 PyObject * last_status_text;
6897 int media_status;
6898 int media_dir;
6899 int conf_slot;
6900 pj_time_val_Object * connect_duration;
6901 pj_time_val_Object * total_duration;
6902 struct {
6903 char local_info[128];
6904 char local_contact[128];
6905 char remote_info[128];
6906 char remote_contact[128];
6907 char call_id[128];
6908 char last_status_text[128];
6909 } buf_;
6910
6911} call_info_Object;
6912
6913
6914/*
6915 * call_info_dealloc
6916 * deletes a call_info from memory
6917 */
6918static void call_info_dealloc(call_info_Object* self)
6919{
6920 Py_XDECREF(self->local_info);
6921 Py_XDECREF(self->local_contact);
6922 Py_XDECREF(self->remote_info);
6923 Py_XDECREF(self->remote_contact);
6924 Py_XDECREF(self->call_id);
6925 Py_XDECREF(self->state_text);
6926 Py_XDECREF(self->last_status_text);
6927 Py_XDECREF(self->connect_duration);
6928 Py_XDECREF(self->total_duration);
6929 self->ob_type->tp_free((PyObject*)self);
6930}
6931
6932
6933/*
6934 * call_info_new
6935 * constructor for call_info object
6936 */
6937static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
6938 PyObject *kwds)
6939{
6940 call_info_Object *self;
6941
6942 self = (call_info_Object *)type->tp_alloc(type, 0);
6943 if (self != NULL)
6944 {
6945 self->local_info = PyString_FromString("");
6946 if (self->local_info == NULL)
6947 {
6948 Py_DECREF(self);
6949 return NULL;
6950 }
6951 self->local_contact = PyString_FromString("");
6952 if (self->local_contact == NULL)
6953 {
6954 Py_DECREF(self);
6955 return NULL;
6956 }
6957 self->remote_info = PyString_FromString("");
6958 if (self->remote_info == NULL)
6959 {
6960 Py_DECREF(self);
6961 return NULL;
6962 }
6963 self->remote_contact = PyString_FromString("");
6964 if (self->remote_contact == NULL)
6965 {
6966 Py_DECREF(self);
6967 return NULL;
6968 }
6969 self->call_id = PyString_FromString("");
6970 if (self->call_id == NULL)
6971 {
6972 Py_DECREF(self);
6973 return NULL;
6974 }
6975 self->state_text = PyString_FromString("");
6976 if (self->state_text == NULL)
6977 {
6978 Py_DECREF(self);
6979 return NULL;
6980 }
6981 self->last_status_text = PyString_FromString("");
6982 if (self->last_status_text == NULL)
6983 {
6984 Py_DECREF(self);
6985 return NULL;
6986 }
6987 self->connect_duration = (pj_time_val_Object *)PyType_GenericNew
6988 (&pj_time_val_Type,NULL,NULL);
6989 if (self->connect_duration == NULL)
6990 {
6991 Py_DECREF(self);
6992 return NULL;
6993 }
6994 self->total_duration = (pj_time_val_Object *)PyType_GenericNew
6995 (&pj_time_val_Type,NULL,NULL);
6996 if (self->total_duration == NULL)
6997 {
6998 Py_DECREF(self);
6999 return NULL;
7000 }
7001 }
7002 return (PyObject *)self;
7003}
7004
7005/*
7006 * call_info_members
7007 */
7008static PyMemberDef call_info_members[] =
7009{
7010 {
7011 "id", T_INT,
7012 offsetof(call_info_Object, id), 0,
7013 "Call identification"
7014 },
7015 {
7016 "role", T_INT,
7017 offsetof(call_info_Object, role), 0,
7018 "Initial call role (UAC == caller)"
7019 },
7020 {
7021 "acc_id", T_INT,
7022 offsetof(call_info_Object, acc_id), 0,
7023 "The account ID where this call belongs."
7024 },
7025 {
7026 "local_info", T_OBJECT_EX,
7027 offsetof(call_info_Object, local_info), 0,
7028 "Local URI"
7029 },
7030 {
7031 "local_contact", T_OBJECT_EX,
7032 offsetof(call_info_Object, local_contact), 0,
7033 "Local Contact"
7034 },
7035 {
7036 "remote_info", T_OBJECT_EX,
7037 offsetof(call_info_Object, remote_info), 0,
7038 "Remote URI"
7039 },
7040 {
7041 "remote_contact", T_OBJECT_EX,
7042 offsetof(call_info_Object, remote_contact), 0,
7043 "Remote Contact"
7044 },
7045 {
7046 "call_id", T_OBJECT_EX,
7047 offsetof(call_info_Object, call_id), 0,
7048 "Dialog Call-ID string"
7049 },
7050 {
7051 "state", T_INT,
7052 offsetof(call_info_Object, state), 0,
7053 "Call state"
7054 },
7055 {
7056 "state_text", T_OBJECT_EX,
7057 offsetof(call_info_Object, state_text), 0,
7058 "Text describing the state "
7059 },
7060 {
7061 "last_status", T_INT,
7062 offsetof(call_info_Object, last_status), 0,
7063 "Last status code heard, which can be used as cause code"
7064 },
7065 {
7066 "last_status_text", T_OBJECT_EX,
7067 offsetof(call_info_Object, last_status_text), 0,
7068 "The reason phrase describing the status."
7069 },
7070 {
7071 "media_status", T_INT,
7072 offsetof(call_info_Object, media_status), 0,
7073 "Call media status."
7074 },
7075 {
7076 "media_dir", T_INT,
7077 offsetof(call_info_Object, media_dir), 0,
7078 "Media direction"
7079 },
7080 {
7081 "conf_slot", T_INT,
7082 offsetof(call_info_Object, conf_slot), 0,
7083 "The conference port number for the call"
7084 },
7085 {
7086 "connect_duration", T_OBJECT_EX,
7087 offsetof(call_info_Object, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00007088 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00007089 },
7090 {
7091 "total_duration", T_OBJECT_EX,
7092 offsetof(call_info_Object, total_duration), 0,
7093 "Total call duration, including set-up time"
7094 },
7095
7096 {NULL} /* Sentinel */
7097};
7098
7099
7100
7101
7102/*
7103 * call_info_Type
7104 */
7105static PyTypeObject call_info_Type =
7106{
7107 PyObject_HEAD_INIT(NULL)
7108 0, /*ob_size*/
7109 "py_pjsua.Call_Info", /*tp_name*/
7110 sizeof(call_info_Object), /*tp_basicsize*/
7111 0, /*tp_itemsize*/
7112 (destructor)call_info_dealloc,/*tp_dealloc*/
7113 0, /*tp_print*/
7114 0, /*tp_getattr*/
7115 0, /*tp_setattr*/
7116 0, /*tp_compare*/
7117 0, /*tp_repr*/
7118 0, /*tp_as_number*/
7119 0, /*tp_as_sequence*/
7120 0, /*tp_as_mapping*/
7121 0, /*tp_hash */
7122 0, /*tp_call*/
7123 0, /*tp_str*/
7124 0, /*tp_getattro*/
7125 0, /*tp_setattro*/
7126 0, /*tp_as_buffer*/
7127 Py_TPFLAGS_DEFAULT, /*tp_flags*/
7128 "Call Info objects", /* tp_doc */
7129 0, /* tp_traverse */
7130 0, /* tp_clear */
7131 0, /* tp_richcompare */
7132 0, /* tp_weaklistoffset */
7133 0, /* tp_iter */
7134 0, /* tp_iternext */
7135 0, /* tp_methods */
7136 call_info_members, /* tp_members */
7137 0, /* tp_getset */
7138 0, /* tp_base */
7139 0, /* tp_dict */
7140 0, /* tp_descr_get */
7141 0, /* tp_descr_set */
7142 0, /* tp_dictoffset */
7143 0, /* tp_init */
7144 0, /* tp_alloc */
7145 call_info_new, /* tp_new */
7146
7147};
7148
7149/*
7150 * py_pjsua_call_get_max_count
7151 */
7152static PyObject *py_pjsua_call_get_max_count
7153(PyObject *pSelf, PyObject *pArgs)
7154{
7155 int count;
7156
7157 if (!PyArg_ParseTuple(pArgs, ""))
7158 {
7159 return NULL;
7160 }
7161
7162 count = pjsua_call_get_max_count();
7163
7164
7165 return Py_BuildValue("i", count);
7166}
7167
7168/*
7169 * py_pjsua_call_get_count
7170 */
7171static PyObject *py_pjsua_call_get_count
7172(PyObject *pSelf, PyObject *pArgs)
7173{
7174
7175 int count;
7176
7177
7178 if (!PyArg_ParseTuple(pArgs, ""))
7179 {
7180 return NULL;
7181 }
7182
7183 count = pjsua_call_get_count();
7184
7185
7186 return Py_BuildValue("i", count);
7187}
7188
7189/*
7190 * py_pjsua_enum_calls
7191 */
7192static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
7193{
7194 pj_status_t status;
7195 PyObject *list;
7196
7197 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00007198 unsigned c, i;
Fahrisdcf8fa42006-12-28 03:13:48 +00007199 if (!PyArg_ParseTuple(pArgs, ""))
7200 {
7201 return NULL;
7202 }
7203
7204 c = PJ_ARRAY_SIZE(id);
7205 status = pjsua_enum_calls(id, &c);
7206
7207 list = PyList_New(c);
7208 for (i = 0; i < c; i++)
7209 {
7210 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
7211 if (ret == -1)
7212 {
7213 return NULL;
7214 }
7215 }
7216
Fahrisdcf8fa42006-12-28 03:13:48 +00007217 return Py_BuildValue("O",list);
7218}
7219
7220/*
7221 * py_pjsua_call_make_call
7222 */
7223static PyObject *py_pjsua_call_make_call
7224(PyObject *pSelf, PyObject *pArgs)
7225{
7226 int status;
7227 int acc_id;
7228 pj_str_t dst_uri;
7229 PyObject * sd;
7230 unsigned options;
7231 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007232 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007233 msg_data_Object * omd;
7234 int user_data;
7235 int call_id;
7236 pj_pool_t * pool;
7237
Fahris17d91812007-01-29 12:09:33 +00007238 if (!PyArg_ParseTuple
7239 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007240 {
7241 return NULL;
7242 }
7243
7244 dst_uri.ptr = PyString_AsString(sd);
7245 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00007246 if (omdObj != Py_None)
7247 {
7248 omd = (msg_data_Object *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00007249 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7250 msg_data.content_type.slen = strlen
7251 (PyString_AsString(omd->content_type));
7252 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7253 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007254 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007255 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7256 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007257 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00007258 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007259 } else {
Fahris89ea3d02007-02-07 08:18:35 +00007260
Fahris17d91812007-01-29 12:09:33 +00007261 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00007262 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007263 }
Fahris89ea3d02007-02-07 08:18:35 +00007264
Fahrisdcf8fa42006-12-28 03:13:48 +00007265 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00007266
Fahrisdcf8fa42006-12-28 03:13:48 +00007267}
7268
7269/*
7270 * py_pjsua_call_is_active
7271 */
7272static PyObject *py_pjsua_call_is_active
7273(PyObject *pSelf, PyObject *pArgs)
7274{
7275 int call_id;
7276 int isActive;
7277
7278
7279 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7280 {
7281 return NULL;
7282 }
7283
7284 isActive = pjsua_call_is_active(call_id);
7285
7286
7287 return Py_BuildValue("i", isActive);
7288}
7289
7290/*
7291 * py_pjsua_call_has_media
7292 */
7293static PyObject *py_pjsua_call_has_media
7294(PyObject *pSelf, PyObject *pArgs)
7295{
7296 int call_id;
7297 int hasMedia;
7298
7299
7300 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7301 {
7302 return NULL;
7303 }
7304
7305 hasMedia = pjsua_call_has_media(call_id);
7306
7307
7308 return Py_BuildValue("i", hasMedia);
7309}
7310
7311/*
7312 * py_pjsua_call_get_conf_port
7313 */
7314static PyObject *py_pjsua_call_get_conf_port
7315(PyObject *pSelf, PyObject *pArgs)
7316{
7317 int call_id;
7318 int port_id;
7319
7320
7321 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7322 {
7323 return NULL;
7324 }
7325
7326 port_id = pjsua_call_get_conf_port(call_id);
7327
7328
7329 return Py_BuildValue("i", port_id);
7330}
7331
7332/*
7333 * py_pjsua_call_get_info
7334 */
7335static PyObject *py_pjsua_call_get_info
7336(PyObject *pSelf, PyObject *pArgs)
7337{
7338 int call_id;
7339 int status;
7340 call_info_Object * oi;
7341 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00007342
7343
7344 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7345 {
7346 return NULL;
7347 }
7348
7349
7350 status = pjsua_call_get_info(call_id, &info);
7351 if (status == PJ_SUCCESS)
7352 {
7353 oi = (call_info_Object *)call_info_new(&call_info_Type, NULL, NULL);
7354 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00007355 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
7356 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
7357 pj_ansi_snprintf(oi->buf_.last_status_text,
7358 sizeof(oi->buf_.last_status_text),
7359 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
7360 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
7361 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
7362 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
7363 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
7364 pj_ansi_snprintf(oi->buf_.remote_contact,
7365 sizeof(oi->buf_.remote_contact),
7366 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
7367 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
7368 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007369
Fahrisdcf8fa42006-12-28 03:13:48 +00007370 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
7371 info.call_id.slen);
7372 oi->conf_slot = info.conf_slot;
7373 oi->connect_duration->sec = info.connect_duration.sec;
7374 oi->connect_duration->msec = info.connect_duration.msec;
7375 oi->total_duration->sec = info.total_duration.sec;
7376 oi->total_duration->msec = info.total_duration.msec;
7377 oi->id = info.id;
7378 oi->last_status = info.last_status;
7379 oi->last_status_text = PyString_FromStringAndSize(
7380 info.last_status_text.ptr, info.last_status_text.slen);
7381 oi->local_contact = PyString_FromStringAndSize(
7382 info.local_contact.ptr, info.local_contact.slen);
7383 oi->local_info = PyString_FromStringAndSize(
7384 info.local_info.ptr, info.local_info.slen);
7385 oi->remote_contact = PyString_FromStringAndSize(
7386 info.remote_contact.ptr, info.remote_contact.slen);
7387 oi->remote_info = PyString_FromStringAndSize(
7388 info.remote_info.ptr, info.remote_info.slen);
7389 oi->media_dir = info.media_dir;
7390 oi->media_status = info.media_status;
7391 oi->role = info.role;
7392 oi->state = info.state;
7393 oi->state_text = PyString_FromStringAndSize(
7394 info.state_text.ptr, info.state_text.slen);
7395
7396 return Py_BuildValue("O", oi);
7397 } else {
7398 Py_INCREF(Py_None);
7399 return Py_None;
7400 }
7401}
7402
7403/*
7404 * py_pjsua_call_set_user_data
7405 */
7406static PyObject *py_pjsua_call_set_user_data
7407(PyObject *pSelf, PyObject *pArgs)
7408{
7409 int call_id;
7410 int user_data;
7411 int status;
7412
7413 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
7414 {
7415 return NULL;
7416 }
7417
Benny Prijonoe6ead542007-01-31 20:53:31 +00007418 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007419
7420
7421 return Py_BuildValue("i", status);
7422}
7423
7424/*
7425 * py_pjsua_call_get_user_data
7426 */
7427static PyObject *py_pjsua_call_get_user_data
7428(PyObject *pSelf, PyObject *pArgs)
7429{
7430 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00007431 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00007432
7433
7434 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
7435 {
7436 return NULL;
7437 }
7438
7439 user_data = pjsua_call_get_user_data(call_id);
7440
7441
Benny Prijonoe6ead542007-01-31 20:53:31 +00007442 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007443}
7444
7445/*
7446 * py_pjsua_call_answer
7447 */
7448static PyObject *py_pjsua_call_answer
7449(PyObject *pSelf, PyObject *pArgs)
7450{
7451 int status;
7452 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007453 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007454 PyObject * sr;
7455 unsigned code;
7456 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007457 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007458 msg_data_Object * omd;
7459 pj_pool_t * pool;
7460
Fahris17d91812007-01-29 12:09:33 +00007461 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007462 {
7463 return NULL;
7464 }
Fahris6f35cb82007-02-01 07:41:26 +00007465 if (sr == Py_None)
7466 {
7467 reason = NULL;
7468 } else {
Fahrise314b882007-02-02 10:52:04 +00007469 reason = &tmp_reason;
7470 tmp_reason.ptr = PyString_AsString(sr);
7471 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007472 }
7473 if (omdObj != Py_None)
7474 {
Fahris17d91812007-01-29 12:09:33 +00007475 omd = (msg_data_Object *)omdObj;
7476 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7477 msg_data.content_type.slen = strlen
7478 (PyString_AsString(omd->content_type));
7479 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7480 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007481 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007482 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7483
Fahris6f35cb82007-02-01 07:41:26 +00007484 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00007485
Fahris17d91812007-01-29 12:09:33 +00007486 pj_pool_release(pool);
7487 } else {
7488
Fahris89ea3d02007-02-07 08:18:35 +00007489 status = pjsua_call_answer(call_id, code, reason, NULL);
7490
Fahris6f35cb82007-02-01 07:41:26 +00007491 }
Fahrise314b882007-02-02 10:52:04 +00007492
Fahrisdcf8fa42006-12-28 03:13:48 +00007493 return Py_BuildValue("i",status);
7494}
7495
7496/*
7497 * py_pjsua_call_hangup
7498 */
7499static PyObject *py_pjsua_call_hangup
7500(PyObject *pSelf, PyObject *pArgs)
7501{
7502 int status;
7503 int call_id;
Fahrise314b882007-02-02 10:52:04 +00007504 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00007505 PyObject * sr;
7506 unsigned code;
7507 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00007508 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007509 msg_data_Object * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007510 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00007511
Fahris17d91812007-01-29 12:09:33 +00007512 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007513 {
7514 return NULL;
7515 }
Benny Prijonoaa286042007-02-03 17:23:22 +00007516 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007517 {
7518 reason = NULL;
7519 } else {
Fahrise314b882007-02-02 10:52:04 +00007520 reason = &tmp_reason;
7521 tmp_reason.ptr = PyString_AsString(sr);
7522 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00007523 }
7524 if (omdObj != Py_None)
7525 {
Fahris17d91812007-01-29 12:09:33 +00007526 omd = (msg_data_Object *)omdObj;
7527 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7528 msg_data.content_type.slen = strlen
7529 (PyString_AsString(omd->content_type));
7530 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7531 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007532 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007533 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00007534 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00007535 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00007536 } else {
Fahris6f35cb82007-02-01 07:41:26 +00007537 status = pjsua_call_hangup(call_id, code, reason, NULL);
7538 }
Fahrise314b882007-02-02 10:52:04 +00007539
Fahrisdcf8fa42006-12-28 03:13:48 +00007540 return Py_BuildValue("i",status);
7541}
7542
7543/*
7544 * py_pjsua_call_set_hold
7545 */
7546static PyObject *py_pjsua_call_set_hold
7547(PyObject *pSelf, PyObject *pArgs)
7548{
7549 int status;
7550 int call_id;
7551 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007552 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007553 msg_data_Object * omd;
7554 pj_pool_t * pool;
7555
Fahris17d91812007-01-29 12:09:33 +00007556 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007557 {
7558 return NULL;
7559 }
Fahris17d91812007-01-29 12:09:33 +00007560
Fahris6f35cb82007-02-01 07:41:26 +00007561 if (omdObj != Py_None)
7562 {
Fahris17d91812007-01-29 12:09:33 +00007563 omd = (msg_data_Object *)omdObj;
7564 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7565 msg_data.content_type.slen = strlen
7566 (PyString_AsString(omd->content_type));
7567 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7568 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007569 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007570 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7571 status = pjsua_call_set_hold(call_id, &msg_data);
7572 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007573 } else {
Fahris17d91812007-01-29 12:09:33 +00007574 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007575 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007576 return Py_BuildValue("i",status);
7577}
7578
7579/*
7580 * py_pjsua_call_reinvite
7581 */
7582static PyObject *py_pjsua_call_reinvite
7583(PyObject *pSelf, PyObject *pArgs)
7584{
7585 int status;
7586 int call_id;
7587 int unhold;
7588 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007589 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007590 msg_data_Object * omd;
7591 pj_pool_t * pool;
7592
Fahris17d91812007-01-29 12:09:33 +00007593 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007594 {
7595 return NULL;
7596 }
Fahris17d91812007-01-29 12:09:33 +00007597
7598 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007599 {
Fahris17d91812007-01-29 12:09:33 +00007600 omd = (msg_data_Object *)omdObj;
7601 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7602 msg_data.content_type.slen = strlen
7603 (PyString_AsString(omd->content_type));
7604 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7605 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007606 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007607 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7608 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
7609 pj_pool_release(pool);
7610 } else {
7611 status = pjsua_call_reinvite(call_id, unhold, NULL);
7612 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007613 return Py_BuildValue("i",status);
7614}
7615
7616/*
7617 * py_pjsua_call_xfer
7618 */
7619static PyObject *py_pjsua_call_xfer
7620(PyObject *pSelf, PyObject *pArgs)
7621{
7622 int status;
7623 int call_id;
7624 pj_str_t dest;
7625 PyObject * sd;
7626 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007627 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007628 msg_data_Object * omd;
7629 pj_pool_t * pool;
7630
Fahris17d91812007-01-29 12:09:33 +00007631 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007632 {
7633 return NULL;
7634 }
7635
7636 dest.ptr = PyString_AsString(sd);
7637 dest.slen = strlen(PyString_AsString(sd));
7638
Fahris17d91812007-01-29 12:09:33 +00007639 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007640 {
Fahris17d91812007-01-29 12:09:33 +00007641 omd = (msg_data_Object *)omdObj;
7642 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7643 msg_data.content_type.slen = strlen
7644 (PyString_AsString(omd->content_type));
7645 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7646 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007647 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007648 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7649 status = pjsua_call_xfer(call_id, &dest, &msg_data);
7650 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007651 } else {
Fahris17d91812007-01-29 12:09:33 +00007652 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007653 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007654 return Py_BuildValue("i",status);
7655}
7656
7657/*
7658 * py_pjsua_call_xfer_replaces
7659 */
7660static PyObject *py_pjsua_call_xfer_replaces
7661(PyObject *pSelf, PyObject *pArgs)
7662{
7663 int status;
7664 int call_id;
7665 int dest_call_id;
7666 unsigned options;
7667 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007668 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007669 msg_data_Object * omd;
7670 pj_pool_t * pool;
7671
Fahris17d91812007-01-29 12:09:33 +00007672 if (!PyArg_ParseTuple
7673 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007674 {
7675 return NULL;
7676 }
7677
Fahris17d91812007-01-29 12:09:33 +00007678 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007679 {
Fahris17d91812007-01-29 12:09:33 +00007680 omd = (msg_data_Object *)omdObj;
7681 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7682 msg_data.content_type.slen = strlen
7683 (PyString_AsString(omd->content_type));
7684 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7685 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007686 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007687 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7688 status = pjsua_call_xfer_replaces
7689 (call_id, dest_call_id, options, &msg_data);
7690 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007691 } else {
Fahris17d91812007-01-29 12:09:33 +00007692 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007693 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007694 return Py_BuildValue("i",status);
7695}
7696
7697/*
7698 * py_pjsua_call_dial_dtmf
7699 */
7700static PyObject *py_pjsua_call_dial_dtmf
7701(PyObject *pSelf, PyObject *pArgs)
7702{
7703 int call_id;
7704 PyObject * sd;
7705 pj_str_t digits;
7706 int status;
7707
7708 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
7709 {
7710 return NULL;
7711 }
7712 digits.ptr = PyString_AsString(sd);
7713 digits.slen = strlen(PyString_AsString(sd));
7714 status = pjsua_call_dial_dtmf(call_id, &digits);
7715
7716 return Py_BuildValue("i", status);
7717}
7718
7719/*
7720 * py_pjsua_call_send_im
7721 */
7722static PyObject *py_pjsua_call_send_im
7723(PyObject *pSelf, PyObject *pArgs)
7724{
7725 int status;
7726 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00007727 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00007728 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00007729 PyObject * sm;
7730 PyObject * sc;
7731 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007732 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007733 msg_data_Object * omd;
7734 int user_data;
7735 pj_pool_t * pool;
7736
Fahris17d91812007-01-29 12:09:33 +00007737 if (!PyArg_ParseTuple
7738 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00007739 {
7740 return NULL;
7741 }
Fahris6f35cb82007-02-01 07:41:26 +00007742 if (sm == Py_None)
7743 {
7744 mime_type = NULL;
7745 } else {
Fahrise314b882007-02-02 10:52:04 +00007746 mime_type = &tmp_mime_type;
7747 tmp_mime_type.ptr = PyString_AsString(sm);
7748 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00007749 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007750 content.ptr = PyString_AsString(sc);
7751 content.slen = strlen(PyString_AsString(sc));
7752
Fahris17d91812007-01-29 12:09:33 +00007753 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007754 {
Fahris17d91812007-01-29 12:09:33 +00007755 omd = (msg_data_Object *)omdObj;
7756 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7757 msg_data.content_type.slen = strlen
7758 (PyString_AsString(omd->content_type));
7759 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7760 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007761 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007762 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7763 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007764 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00007765 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007766 } else {
Fahris17d91812007-01-29 12:09:33 +00007767 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00007768 (call_id, mime_type, &content, NULL, (void *)user_data);
7769 }
Fahrise314b882007-02-02 10:52:04 +00007770
Fahrisdcf8fa42006-12-28 03:13:48 +00007771 return Py_BuildValue("i",status);
7772}
7773
7774/*
7775 * py_pjsua_call_send_typing_ind
7776 */
7777static PyObject *py_pjsua_call_send_typing_ind
7778(PyObject *pSelf, PyObject *pArgs)
7779{
7780 int status;
7781 int call_id;
7782 int is_typing;
7783 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00007784 PyObject * omdObj;
Fahrisdcf8fa42006-12-28 03:13:48 +00007785 msg_data_Object * omd;
7786 pj_pool_t * pool;
7787
Fahris17d91812007-01-29 12:09:33 +00007788 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00007789 {
7790 return NULL;
7791 }
7792
Fahris17d91812007-01-29 12:09:33 +00007793 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00007794 {
Fahris17d91812007-01-29 12:09:33 +00007795 omd = (msg_data_Object *)omdObj;
7796 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
7797 msg_data.content_type.slen = strlen
7798 (PyString_AsString(omd->content_type));
7799 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
7800 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00007801 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00007802 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
7803 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
7804 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00007805 } else {
Fahris17d91812007-01-29 12:09:33 +00007806 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00007807 }
Fahrisdcf8fa42006-12-28 03:13:48 +00007808 return Py_BuildValue("i",status);
7809}
7810
7811/*
7812 * py_pjsua_call_hangup_all
7813 */
7814static PyObject *py_pjsua_call_hangup_all
7815(PyObject *pSelf, PyObject *pArgs)
7816{
7817
7818 if (!PyArg_ParseTuple(pArgs, ""))
7819 {
7820 return NULL;
7821 }
7822
7823 pjsua_call_hangup_all();
7824
7825 Py_INCREF(Py_None);
7826 return Py_None;
7827}
7828
7829/*
7830 * py_pjsua_call_dump
7831 */
7832static PyObject *py_pjsua_call_dump
7833(PyObject *pSelf, PyObject *pArgs)
7834{
7835 int call_id;
7836 int with_media;
7837 PyObject * sb;
7838 PyObject * si;
7839 char * buffer;
7840 char * indent;
7841 unsigned maxlen;
7842 int status;
7843
7844 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
7845 {
7846 return NULL;
7847 }
7848 buffer = (char *) malloc (maxlen * sizeof(char));
7849 indent = PyString_AsString(si);
7850
7851 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
7852 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00007853 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00007854 return Py_BuildValue("O", sb);
7855}
7856
7857static char pjsua_call_get_max_count_doc[] =
7858 "int py_pjsua.call_get_max_count () "
7859 "Get maximum number of calls configured in pjsua.";
7860static char pjsua_call_get_count_doc[] =
7861 "int py_pjsua.call_get_count () "
7862 "Get number of currently active calls.";
7863static char pjsua_enum_calls_doc[] =
7864 "int[] py_pjsua.enum_calls () "
7865 "Get maximum number of calls configured in pjsua.";
7866static char pjsua_call_make_call_doc[] =
7867 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
7868 "int user_data, py_pjsua.Msg_Data msg_data) "
7869 "Make outgoing call to the specified URI using the specified account.";
7870static char pjsua_call_is_active_doc[] =
7871 "int py_pjsua.call_is_active (int call_id) "
7872 "Check if the specified call has active INVITE session and the INVITE "
7873 "session has not been disconnected.";
7874static char pjsua_call_has_media_doc[] =
7875 "int py_pjsua.call_has_media (int call_id) "
7876 "Check if call has an active media session.";
7877static char pjsua_call_get_conf_port_doc[] =
7878 "int py_pjsua.call_get_conf_port (int call_id) "
7879 "Get the conference port identification associated with the call.";
7880static char pjsua_call_get_info_doc[] =
7881 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
7882 "Obtain detail information about the specified call.";
7883static char pjsua_call_set_user_data_doc[] =
7884 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
7885 "Attach application specific data to the call.";
7886static char pjsua_call_get_user_data_doc[] =
7887 "int py_pjsua.call_get_user_data (int call_id) "
7888 "Get user data attached to the call.";
7889static char pjsua_call_answer_doc[] =
7890 "int py_pjsua.call_answer (int call_id, int code, string reason, "
7891 "py_pjsua.Msg_Data msg_data) "
7892 "Send response to incoming INVITE request.";
7893static char pjsua_call_hangup_doc[] =
7894 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
7895 "py_pjsua.Msg_Data msg_data) "
7896 "Hangup call by using method that is appropriate according "
7897 "to the call state.";
7898static char pjsua_call_set_hold_doc[] =
7899 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
7900 "Put the specified call on hold.";
7901static char pjsua_call_reinvite_doc[] =
7902 "int py_pjsua.call_reinvite (int call_id, int unhold, "
7903 "py_pjsua.Msg_Data msg_data) "
7904 "Send re-INVITE (to release hold).";
7905static char pjsua_call_xfer_doc[] =
7906 "int py_pjsua.call_xfer (int call_id, string dest, "
7907 "py_pjsua.Msg_Data msg_data) "
7908 "Initiate call transfer to the specified address. "
7909 "This function will send REFER request to instruct remote call party "
7910 "to initiate a new INVITE session to the specified destination/target.";
7911static char pjsua_call_xfer_replaces_doc[] =
7912 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
7913 "int options, py_pjsua.Msg_Data msg_data) "
7914 "Initiate attended call transfer. This function will send REFER request "
7915 "to instruct remote call party to initiate new INVITE session to the URL "
7916 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
7917 "with us with the new call from the REFER recipient.";
7918static char pjsua_call_dial_dtmf_doc[] =
7919 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
7920 "Send DTMF digits to remote using RFC 2833 payload formats.";
7921static char pjsua_call_send_im_doc[] =
7922 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
7923 "py_pjsua.Msg_Data msg_data, int user_data) "
7924 "Send instant messaging inside INVITE session.";
7925static char pjsua_call_send_typing_ind_doc[] =
7926 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
7927 "py_pjsua.Msg_Data msg_data) "
7928 "Send IM typing indication inside INVITE session.";
7929static char pjsua_call_hangup_all_doc[] =
7930 "void py_pjsua.call_hangup_all () "
7931 "Terminate all calls.";
7932static char pjsua_call_dump_doc[] =
7933 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
7934 "string indent) "
7935 "Dump call and media statistics to string.";
7936
7937/* END OF LIB CALL */
7938
Benny Prijono572d4852006-11-23 21:50:02 +00007939/*
7940 * Map of function names to functions
7941 */
7942static PyMethodDef py_pjsua_methods[] =
7943{
7944 {
Benny Prijonodc308702006-12-09 00:39:42 +00007945 "thread_register", py_pjsua_thread_register, METH_VARARGS,
7946 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00007947 },
7948 {
Benny Prijono572d4852006-11-23 21:50:02 +00007949 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
7950 },
7951 {
7952 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
7953 },
7954 {
7955 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
7956 },
7957 {
7958 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
7959 },
7960 {
7961 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
7962 },
7963 {
7964 "handle_events", py_pjsua_handle_events, METH_VARARGS,
7965 pjsua_handle_events_doc
7966 },
7967 {
7968 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
7969 pjsua_verify_sip_url_doc
7970 },
7971 {
7972 "pool_create", py_pjsua_pool_create, METH_VARARGS,
7973 pjsua_pool_create_doc
7974 },
7975 {
7976 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
7977 pjsua_get_pjsip_endpt_doc
7978 },
7979 {
7980 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
7981 pjsua_get_pjmedia_endpt_doc
7982 },
7983 {
7984 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
7985 pjsua_get_pool_factory_doc
7986 },
7987 {
7988 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
7989 pjsua_reconfigure_logging_doc
7990 },
7991 {
7992 "logging_config_default", py_pjsua_logging_config_default,
7993 METH_VARARGS, pjsua_logging_config_default_doc
7994 },
7995 {
7996 "config_default", py_pjsua_config_default, METH_VARARGS,
7997 pjsua_config_default_doc
7998 },
7999 {
8000 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
8001 pjsua_media_config_default_doc
8002 },
Benny Prijonodc308702006-12-09 00:39:42 +00008003
8004
Benny Prijono572d4852006-11-23 21:50:02 +00008005 {
8006 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
8007 pjsua_msg_data_init_doc
8008 },
Benny Prijonodc308702006-12-09 00:39:42 +00008009 {
8010 "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS,
8011 pjsua_stun_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008012 },
Benny Prijonodc308702006-12-09 00:39:42 +00008013 {
8014 "transport_config_default", py_pjsua_transport_config_default,
8015 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008016 },
Benny Prijonodc308702006-12-09 00:39:42 +00008017 {
8018 "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS,
8019 pjsua_normalize_stun_config_doc
Benny Prijono98793592006-12-04 08:33:20 +00008020 },
Benny Prijonodc308702006-12-09 00:39:42 +00008021
8022 {
8023 "transport_create", py_pjsua_transport_create, METH_VARARGS,
8024 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00008025 },
Benny Prijonodc308702006-12-09 00:39:42 +00008026 {
8027 "transport_register", py_pjsua_transport_register, METH_VARARGS,
8028 pjsua_transport_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00008029 },
Benny Prijonodc308702006-12-09 00:39:42 +00008030 {
8031 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
8032 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00008033 },
Benny Prijonodc308702006-12-09 00:39:42 +00008034 {
8035 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
8036 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008037 },
Benny Prijonodc308702006-12-09 00:39:42 +00008038 {
8039 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
8040 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00008041 },
Benny Prijonodc308702006-12-09 00:39:42 +00008042 {
8043 "transport_close", py_pjsua_transport_close, METH_VARARGS,
8044 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00008045 },
Benny Prijonodc308702006-12-09 00:39:42 +00008046 {
8047 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
8048 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008049 },
Benny Prijonodc308702006-12-09 00:39:42 +00008050 {
8051 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
8052 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008053 },
Benny Prijonodc308702006-12-09 00:39:42 +00008054 {
8055 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
8056 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00008057 },
Benny Prijonodc308702006-12-09 00:39:42 +00008058 {
8059 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
8060 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008061 },
Benny Prijonodc308702006-12-09 00:39:42 +00008062 {
8063 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
8064 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00008065 },
Benny Prijonodc308702006-12-09 00:39:42 +00008066 {
8067 "acc_add", py_pjsua_acc_add, METH_VARARGS,
8068 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00008069 },
Benny Prijonodc308702006-12-09 00:39:42 +00008070 {
8071 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
8072 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00008073 },
Benny Prijonodc308702006-12-09 00:39:42 +00008074 {
8075 "acc_del", py_pjsua_acc_del, METH_VARARGS,
8076 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00008077 },
Benny Prijonodc308702006-12-09 00:39:42 +00008078 {
8079 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
8080 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00008081 },
Benny Prijonodc308702006-12-09 00:39:42 +00008082 {
8083 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
8084 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00008085 },
Benny Prijonodc308702006-12-09 00:39:42 +00008086 {
8087 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
8088 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00008089 },
Benny Prijonodc308702006-12-09 00:39:42 +00008090 {
8091 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
8092 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008093 },
Benny Prijonodc308702006-12-09 00:39:42 +00008094 {
8095 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
8096 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00008097 },
Benny Prijonodc308702006-12-09 00:39:42 +00008098 {
8099 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
8100 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00008101 },
Benny Prijonodc308702006-12-09 00:39:42 +00008102 {
8103 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
8104 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00008105 },
Benny Prijonodc308702006-12-09 00:39:42 +00008106 {
8107 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
8108 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00008109 },
Benny Prijonodc308702006-12-09 00:39:42 +00008110 {
8111 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
8112 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008113 },
Benny Prijonodc308702006-12-09 00:39:42 +00008114 {
8115 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
8116 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00008117 },
Benny Prijonodc308702006-12-09 00:39:42 +00008118 {
Fahris6f35cb82007-02-01 07:41:26 +00008119 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
8120 pjsua_buddy_config_default_doc
8121 },
8122 {
Benny Prijonodc308702006-12-09 00:39:42 +00008123 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
8124 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00008125 },
Benny Prijonodc308702006-12-09 00:39:42 +00008126 {
8127 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
8128 pjsua_buddy_is_valid_doc
8129 },
8130 {
8131 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
8132 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00008133 },
Benny Prijonodc308702006-12-09 00:39:42 +00008134 {
8135 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
8136 pjsua_buddy_get_info_doc
8137 },
8138 {
8139 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
8140 pjsua_buddy_add_doc
8141 },
8142 {
8143 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
8144 pjsua_buddy_del_doc
8145 },
8146 {
8147 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
8148 pjsua_buddy_subscribe_pres_doc
8149 },
8150 {
8151 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
8152 pjsua_pres_dump_doc
8153 },
8154 {
8155 "im_send", py_pjsua_im_send, METH_VARARGS,
8156 pjsua_im_send_doc
8157 },
8158 {
8159 "im_typing", py_pjsua_im_typing, METH_VARARGS,
8160 pjsua_im_typing_doc
8161 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008162 {
8163 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
8164 pjsua_conf_get_max_ports_doc
8165 },
8166 {
8167 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
8168 pjsua_conf_get_active_ports_doc
8169 },
8170 {
8171 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
8172 pjsua_enum_conf_ports_doc
8173 },
8174 {
8175 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
8176 pjsua_conf_get_port_info_doc
8177 },
8178 {
8179 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
8180 pjsua_conf_add_port_doc
8181 },
8182 {
8183 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
8184 pjsua_conf_remove_port_doc
8185 },
8186 {
8187 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
8188 pjsua_conf_connect_doc
8189 },
8190 {
8191 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
8192 pjsua_conf_disconnect_doc
8193 },
8194 {
8195 "player_create", py_pjsua_player_create, METH_VARARGS,
8196 pjsua_player_create_doc
8197 },
8198 {
8199 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
8200 pjsua_player_get_conf_port_doc
8201 },
8202 {
8203 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
8204 pjsua_player_set_pos_doc
8205 },
8206 {
8207 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
8208 pjsua_player_destroy_doc
8209 },
8210 {
8211 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
8212 pjsua_recorder_create_doc
8213 },
8214 {
8215 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
8216 pjsua_recorder_get_conf_port_doc
8217 },
8218 {
8219 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
8220 pjsua_recorder_destroy_doc
8221 },
8222 {
8223 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
8224 pjsua_enum_snd_devs_doc
8225 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00008226 {
Fahrisdcf8fa42006-12-28 03:13:48 +00008227 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
8228 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00008229 },
Fahrisdcf8fa42006-12-28 03:13:48 +00008230 {
8231 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
8232 pjsua_set_snd_dev_doc
8233 },
8234 {
8235 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
8236 pjsua_set_null_snd_dev_doc
8237 },
8238 {
8239 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
8240 pjsua_set_no_snd_dev_doc
8241 },
8242 {
8243 "set_ec", py_pjsua_set_ec, METH_VARARGS,
8244 pjsua_set_ec_doc
8245 },
8246 {
8247 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
8248 pjsua_get_ec_tail_doc
8249 },
8250 {
8251 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
8252 pjsua_enum_codecs_doc
8253 },
8254 {
8255 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
8256 pjsua_codec_set_priority_doc
8257 },
8258 {
8259 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
8260 pjsua_codec_get_param_doc
8261 },
8262 {
8263 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
8264 pjsua_codec_set_param_doc
8265 },
8266 {
8267 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
8268 pjsua_call_get_max_count_doc
8269 },
8270 {
8271 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
8272 pjsua_call_get_count_doc
8273 },
8274 {
8275 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
8276 pjsua_enum_calls_doc
8277 },
8278 {
8279 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
8280 pjsua_call_make_call_doc
8281 },
8282 {
8283 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
8284 pjsua_call_is_active_doc
8285 },
8286 {
8287 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
8288 pjsua_call_has_media_doc
8289 },
8290 {
8291 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
8292 pjsua_call_get_conf_port_doc
8293 },
8294 {
8295 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
8296 pjsua_call_get_info_doc
8297 },
8298 {
8299 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
8300 pjsua_call_set_user_data_doc
8301 },
8302 {
8303 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
8304 pjsua_call_get_user_data_doc
8305 },
8306 {
8307 "call_answer", py_pjsua_call_answer, METH_VARARGS,
8308 pjsua_call_answer_doc
8309 },
8310 {
8311 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
8312 pjsua_call_hangup_doc
8313 },
8314 {
8315 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
8316 pjsua_call_set_hold_doc
8317 },
8318 {
8319 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
8320 pjsua_call_reinvite_doc
8321 },
8322 {
8323 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
8324 pjsua_call_xfer_doc
8325 },
8326 {
8327 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
8328 pjsua_call_xfer_replaces_doc
8329 },
8330 {
8331 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
8332 pjsua_call_dial_dtmf_doc
8333 },
8334 {
8335 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
8336 pjsua_call_send_im_doc
8337 },
8338 {
8339 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
8340 pjsua_call_send_typing_ind_doc
8341 },
8342 {
8343 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
8344 pjsua_call_hangup_all_doc
8345 },
8346 {
8347 "call_dump", py_pjsua_call_dump, METH_VARARGS,
8348 pjsua_call_dump_doc
8349 },
8350
8351
Benny Prijonodc308702006-12-09 00:39:42 +00008352
Benny Prijono572d4852006-11-23 21:50:02 +00008353 {NULL, NULL} /* end of function list */
8354};
8355
8356
8357
8358/*
8359 * Mapping C structs from and to Python objects & initializing object
8360 */
8361DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00008362initpy_pjsua(void)
8363{
Benny Prijono572d4852006-11-23 21:50:02 +00008364 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00008365#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00008366
Benny Prijonodc308702006-12-09 00:39:42 +00008367
Benny Prijono572d4852006-11-23 21:50:02 +00008368 if (PyType_Ready(&callback_Type) < 0)
8369 return;
8370 if (PyType_Ready(&config_Type) < 0)
8371 return;
8372 if (PyType_Ready(&logging_config_Type) < 0)
8373 return;
8374 if (PyType_Ready(&msg_data_Type) < 0)
8375 return;
8376 media_config_Type.tp_new = PyType_GenericNew;
8377 if (PyType_Ready(&media_config_Type) < 0)
8378 return;
8379 pjsip_event_Type.tp_new = PyType_GenericNew;
8380 if (PyType_Ready(&pjsip_event_Type) < 0)
8381 return;
8382 pjsip_rx_data_Type.tp_new = PyType_GenericNew;
8383 if (PyType_Ready(&pjsip_rx_data_Type) < 0)
8384 return;
8385 pj_pool_Type.tp_new = PyType_GenericNew;
8386 if (PyType_Ready(&pj_pool_Type) < 0)
8387 return;
8388 pjsip_endpoint_Type.tp_new = PyType_GenericNew;
8389 if (PyType_Ready(&pjsip_endpoint_Type) < 0)
8390 return;
8391 pjmedia_endpt_Type.tp_new = PyType_GenericNew;
8392 if (PyType_Ready(&pjmedia_endpt_Type) < 0)
8393 return;
8394 pj_pool_factory_Type.tp_new = PyType_GenericNew;
8395 if (PyType_Ready(&pj_pool_factory_Type) < 0)
8396 return;
8397 pjsip_cred_info_Type.tp_new = PyType_GenericNew;
8398 if (PyType_Ready(&pjsip_cred_info_Type) < 0)
8399 return;
8400
Benny Prijonodc308702006-12-09 00:39:42 +00008401 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008402
Benny Prijonodc308702006-12-09 00:39:42 +00008403 if (PyType_Ready(&stun_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008404 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008405 if (PyType_Ready(&transport_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008406 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008407 if (PyType_Ready(&sockaddr_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008408 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008409 if (PyType_Ready(&host_port_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008410 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008411
8412 if (PyType_Ready(&transport_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008413 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008414
8415 pjsip_transport_Type.tp_new = PyType_GenericNew;
Benny Prijono98793592006-12-04 08:33:20 +00008416 if (PyType_Ready(&pjsip_transport_Type) < 0)
8417 return;
8418
Benny Prijonodc308702006-12-09 00:39:42 +00008419 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008420
Benny Prijonodc308702006-12-09 00:39:42 +00008421 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008422
Benny Prijonodc308702006-12-09 00:39:42 +00008423
8424 if (PyType_Ready(&acc_config_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008425 return;
Benny Prijonodc308702006-12-09 00:39:42 +00008426 if (PyType_Ready(&acc_info_Type) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00008427 return;
8428
Benny Prijonodc308702006-12-09 00:39:42 +00008429 /* END OF LIB ACCOUNT */
8430
8431 /* LIB BUDDY */
8432
8433 if (PyType_Ready(&buddy_config_Type) < 0)
8434 return;
8435 if (PyType_Ready(&buddy_info_Type) < 0)
8436 return;
8437
8438 /* END OF LIB BUDDY */
8439
Fahrisdcf8fa42006-12-28 03:13:48 +00008440 /* LIB MEDIA */
8441
8442 if (PyType_Ready(&codec_info_Type) < 0)
8443 return;
8444
8445 if (PyType_Ready(&conf_port_info_Type) < 0)
8446 return;
8447
8448 pjmedia_port_Type.tp_new = PyType_GenericNew;
8449 if (PyType_Ready(&pjmedia_port_Type) < 0)
8450 return;
8451
8452 if (PyType_Ready(&pjmedia_snd_dev_info_Type) < 0)
8453 return;
8454
8455 pjmedia_codec_param_info_Type.tp_new = PyType_GenericNew;
8456 if (PyType_Ready(&pjmedia_codec_param_info_Type) < 0)
8457 return;
8458 pjmedia_codec_param_setting_Type.tp_new = PyType_GenericNew;
8459 if (PyType_Ready(&pjmedia_codec_param_setting_Type) < 0)
8460 return;
8461
8462 if (PyType_Ready(&pjmedia_codec_param_Type) < 0)
8463 return;
8464
8465 /* END OF LIB MEDIA */
8466
8467 /* LIB CALL */
8468
8469 pj_time_val_Type.tp_new = PyType_GenericNew;
8470 if (PyType_Ready(&pj_time_val_Type) < 0)
8471 return;
8472
8473 if (PyType_Ready(&call_info_Type) < 0)
8474 return;
8475
8476 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00008477
Benny Prijono572d4852006-11-23 21:50:02 +00008478 m = Py_InitModule3(
8479 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
8480 );
8481
8482 Py_INCREF(&callback_Type);
8483 PyModule_AddObject(m, "Callback", (PyObject *)&callback_Type);
8484
8485 Py_INCREF(&config_Type);
8486 PyModule_AddObject(m, "Config", (PyObject *)&config_Type);
8487
8488 Py_INCREF(&media_config_Type);
8489 PyModule_AddObject(m, "Media_Config", (PyObject *)&media_config_Type);
8490
8491 Py_INCREF(&logging_config_Type);
8492 PyModule_AddObject(m, "Logging_Config", (PyObject *)&logging_config_Type);
8493
8494 Py_INCREF(&msg_data_Type);
8495 PyModule_AddObject(m, "Msg_Data", (PyObject *)&msg_data_Type);
8496
8497 Py_INCREF(&pjsip_event_Type);
8498 PyModule_AddObject(m, "PJSIP_Event", (PyObject *)&pjsip_event_Type);
8499
8500 Py_INCREF(&pjsip_rx_data_Type);
8501 PyModule_AddObject(m, "PJSIP_RX_Data", (PyObject *)&pjsip_rx_data_Type);
8502
8503 Py_INCREF(&pj_pool_Type);
8504 PyModule_AddObject(m, "PJ_Pool", (PyObject *)&pj_pool_Type);
8505
8506 Py_INCREF(&pjsip_endpoint_Type);
8507 PyModule_AddObject(m, "PJSIP_Endpoint", (PyObject *)&pjsip_endpoint_Type);
8508
8509 Py_INCREF(&pjmedia_endpt_Type);
8510 PyModule_AddObject(m, "PJMedia_Endpt", (PyObject *)&pjmedia_endpt_Type);
8511
8512 Py_INCREF(&pj_pool_factory_Type);
8513 PyModule_AddObject(
8514 m, "PJ_Pool_Factory", (PyObject *)&pj_pool_factory_Type
8515 );
8516
8517 Py_INCREF(&pjsip_cred_info_Type);
8518 PyModule_AddObject(m, "PJSIP_Cred_Info",
8519 (PyObject *)&pjsip_cred_info_Type
8520 );
8521
Benny Prijonodc308702006-12-09 00:39:42 +00008522 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008523
Benny Prijonodc308702006-12-09 00:39:42 +00008524 Py_INCREF(&stun_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008525 PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008526 Py_INCREF(&transport_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008527 PyModule_AddObject
Benny Prijonodc308702006-12-09 00:39:42 +00008528 (m, "Transport_Config", (PyObject *)&transport_config_Type);
8529 Py_INCREF(&sockaddr_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008530 PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008531 Py_INCREF(&host_port_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008532 PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008533
8534 Py_INCREF(&transport_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008535 PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008536
8537 Py_INCREF(&pjsip_transport_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008538 PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type);
8539
Benny Prijonodc308702006-12-09 00:39:42 +00008540 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00008541
Benny Prijonodc308702006-12-09 00:39:42 +00008542 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00008543
Benny Prijonodc308702006-12-09 00:39:42 +00008544
8545 Py_INCREF(&acc_config_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008546 PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type);
Benny Prijonodc308702006-12-09 00:39:42 +00008547 Py_INCREF(&acc_info_Type);
Benny Prijono98793592006-12-04 08:33:20 +00008548 PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type);
8549
Benny Prijonodc308702006-12-09 00:39:42 +00008550 /* END OF LIB ACCOUNT */
8551
8552 /* LIB BUDDY */
8553
8554 Py_INCREF(&buddy_config_Type);
8555 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&buddy_config_Type);
8556 Py_INCREF(&buddy_info_Type);
8557 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&buddy_info_Type);
8558
8559 /* END OF LIB BUDDY */
8560
Fahrisdcf8fa42006-12-28 03:13:48 +00008561 /* LIB MEDIA */
8562
8563 Py_INCREF(&codec_info_Type);
8564 PyModule_AddObject(m, "Codec_Info", (PyObject *)&codec_info_Type);
8565 Py_INCREF(&conf_port_info_Type);
8566 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&conf_port_info_Type);
8567 Py_INCREF(&pjmedia_port_Type);
8568 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&pjmedia_port_Type);
8569 Py_INCREF(&pjmedia_snd_dev_info_Type);
8570 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
8571 (PyObject *)&pjmedia_snd_dev_info_Type);
8572 Py_INCREF(&pjmedia_codec_param_info_Type);
8573 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
8574 (PyObject *)&pjmedia_codec_param_info_Type);
8575 Py_INCREF(&pjmedia_codec_param_setting_Type);
8576 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
8577 (PyObject *)&pjmedia_codec_param_setting_Type);
8578 Py_INCREF(&pjmedia_codec_param_Type);
8579 PyModule_AddObject(m, "PJMedia_Codec_Param",
8580 (PyObject *)&pjmedia_codec_param_Type);
8581
8582 /* END OF LIB MEDIA */
8583
8584 /* LIB CALL */
8585
8586 Py_INCREF(&pj_time_val_Type);
8587 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&pj_time_val_Type);
8588
8589 Py_INCREF(&call_info_Type);
8590 PyModule_AddObject(m, "Call_Info", (PyObject *)&call_info_Type);
8591
8592 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00008593
Benny Prijonodc308702006-12-09 00:39:42 +00008594
Fahrisdcf8fa42006-12-28 03:13:48 +00008595 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00008596 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00008597 */
Benny Prijonodc308702006-12-09 00:39:42 +00008598
Benny Prijonoaa286042007-02-03 17:23:22 +00008599 /* Call states */
8600 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
8601 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
8602 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
8603 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
8604 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
8605 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
8606 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00008607
Benny Prijonoaa286042007-02-03 17:23:22 +00008608 /* Call media status (enum pjsua_call_media_status) */
8609 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
8610 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
8611 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
8612 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00008613
Benny Prijonoaa286042007-02-03 17:23:22 +00008614 /* Buddy status */
8615 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
8616 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
8617 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00008618
Benny Prijonoaa286042007-02-03 17:23:22 +00008619 /* PJSIP transport types (enum pjsip_transport_type_e) */
8620 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
8621 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
8622 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
8623 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
8624 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
8625 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
8626 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00008627
Fahrisdcf8fa42006-12-28 03:13:48 +00008628
Benny Prijonoaa286042007-02-03 17:23:22 +00008629 /* Invalid IDs */
8630 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00008631
Fahrisdcf8fa42006-12-28 03:13:48 +00008632
Benny Prijonoaa286042007-02-03 17:23:22 +00008633 /* Various compile time constants */
8634 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
8635 ADD_CONSTANT(m, PJSUA_MAX_ACC);
8636 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
8637 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
8638 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
8639 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
8640 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
8641 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
8642 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
8643 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
8644 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
8645 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
8646 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00008647
Fahrisdcf8fa42006-12-28 03:13:48 +00008648
Benny Prijonoaa286042007-02-03 17:23:22 +00008649#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00008650}