blob: d02b9945f7fd7e488e4606addc599a77ae5c12ed [file] [log] [blame]
Benny Prijono572d4852006-11-23 21:50:02 +00001/* $Id$ */
2/*
Benny Prijono32177c02008-06-20 22:44:47 +00003 * Copyright (C) 2003-2008 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 Prijono1f63cc42007-09-10 16:54:22 +000019#include "py_pjsua.h"
Benny Prijono8b8b9972006-11-16 11:18:03 +000020
Benny Prijono572d4852006-11-23 21:50:02 +000021#define THIS_FILE "main.c"
Fahris6f35cb82007-02-01 07:41:26 +000022#define POOL_SIZE 4000
23#define SND_DEV_NUM 64
Fahrise314b882007-02-02 10:52:04 +000024#define SND_NAME_LEN 64
Benny Prijono8b8b9972006-11-16 11:18:03 +000025
Benny Prijono98793592006-12-04 08:33:20 +000026/* LIB BASE */
27
Benny Prijonoda275f62007-02-18 23:49:14 +000028static PyObject* obj_log_cb;
Benny Prijonoed7a5a72007-01-29 18:36:38 +000029static long thread_id;
Benny Prijono572d4852006-11-23 21:50:02 +000030
Benny Prijonoda275f62007-02-18 23:49:14 +000031#define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure()
32#define LEAVE_PYTHON() PyGILState_Release(state)
33
Benny Prijono572d4852006-11-23 21:50:02 +000034/*
Benny Prijonoda275f62007-02-18 23:49:14 +000035 * cb_log_cb
Benny Prijono572d4852006-11-23 21:50:02 +000036 * declares method for reconfiguring logging process for callback struct
37 */
Benny Prijono429fa1f2008-01-18 17:18:55 +000038static void cb_log_cb(int level, const char *data, int len)
Benny Prijono572d4852006-11-23 21:50:02 +000039{
Fahris17d91812007-01-29 12:09:33 +000040
Benny Prijonoed7a5a72007-01-29 18:36:38 +000041 /* Ignore if this callback is called from alien thread context,
42 * or otherwise it will crash Python.
43 */
44 if (pj_thread_local_get(thread_id) == 0)
45 return;
46
Benny Prijonoda275f62007-02-18 23:49:14 +000047 if (PyCallable_Check(obj_log_cb))
Benny Prijono572d4852006-11-23 21:50:02 +000048 {
Benny Prijonoda275f62007-02-18 23:49:14 +000049 ENTER_PYTHON();
50
Benny Prijono572d4852006-11-23 21:50:02 +000051 PyObject_CallFunctionObjArgs(
Benny Prijonoda275f62007-02-18 23:49:14 +000052 obj_log_cb, Py_BuildValue("i",level),
Benny Prijono572d4852006-11-23 21:50:02 +000053 PyString_FromString(data), Py_BuildValue("i",len), NULL
54 );
Benny Prijonoda275f62007-02-18 23:49:14 +000055
56 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +000057 }
58}
59
60
Benny Prijono572d4852006-11-23 21:50:02 +000061
62/*
63 * The global callback object.
64 */
Benny Prijono1f63cc42007-09-10 16:54:22 +000065static PyObj_pjsua_callback * g_obj_callback;
Benny Prijono572d4852006-11-23 21:50:02 +000066
67
68/*
69 * cb_on_call_state
70 * declares method on_call_state for callback struct
71 */
72static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e)
73{
Benny Prijonoed7a5a72007-01-29 18:36:38 +000074 if (PyCallable_Check(g_obj_callback->on_call_state))
Fahris17d91812007-01-29 12:09:33 +000075 {
Benny Prijono1f63cc42007-09-10 16:54:22 +000076 PyObj_pjsip_event * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +000077
78 ENTER_PYTHON();
79
Benny Prijono1f63cc42007-09-10 16:54:22 +000080 obj = (PyObj_pjsip_event *)PyType_GenericNew(&PyTyp_pjsip_event,
Benny Prijonoda275f62007-02-18 23:49:14 +000081 NULL, NULL);
Fahris17d91812007-01-29 12:09:33 +000082
Fahris6f35cb82007-02-01 07:41:26 +000083 obj->event = e;
Fahris17d91812007-01-29 12:09:33 +000084
Benny Prijono572d4852006-11-23 21:50:02 +000085 PyObject_CallFunctionObjArgs(
Benny Prijono1f63cc42007-09-10 16:54:22 +000086 g_obj_callback->on_call_state,
87 Py_BuildValue("i",call_id),
88 obj,
89 NULL
Benny Prijono572d4852006-11-23 21:50:02 +000090 );
Benny Prijonoda275f62007-02-18 23:49:14 +000091
92 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +000093 }
94}
95
96
97/*
98 * cb_on_incoming_call
99 * declares method on_incoming_call for callback struct
100 */
101static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
102 pjsip_rx_data *rdata)
103{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000104 if (PyCallable_Check(g_obj_callback->on_incoming_call))
Benny Prijono572d4852006-11-23 21:50:02 +0000105 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000106 PyObj_pjsip_rx_data * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +0000107
108 ENTER_PYTHON();
109
Benny Prijono1f63cc42007-09-10 16:54:22 +0000110 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data,
Benny Prijono572d4852006-11-23 21:50:02 +0000111 NULL, NULL);
112 obj->rdata = rdata;
113
114 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000115 g_obj_callback->on_incoming_call,
Benny Prijono572d4852006-11-23 21:50:02 +0000116 Py_BuildValue("i",acc_id),
117 Py_BuildValue("i",call_id),
118 obj,
119 NULL
120 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000121
122 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000123 }
124}
125
126
127/*
128 * cb_on_call_media_state
129 * declares method on_call_media_state for callback struct
130 */
131static void cb_on_call_media_state(pjsua_call_id call_id)
132{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000133 if (PyCallable_Check(g_obj_callback->on_call_media_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000134 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000135 ENTER_PYTHON();
136
Benny Prijono1f63cc42007-09-10 16:54:22 +0000137 PyObject_CallFunction(
138 g_obj_callback->on_call_media_state,
139 "i",
140 call_id,
141 NULL
142 );
143
144 LEAVE_PYTHON();
145 }
146}
147
148
149/*
150 * cb_on_dtmf_digit()
151 * Callback from PJSUA-LIB on receiving DTMF digit
152 */
153static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit)
154{
Benny Prijono0c97d532008-02-14 15:50:46 +0000155 if (PyCallable_Check(g_obj_callback->on_dtmf_digit))
Benny Prijono1f63cc42007-09-10 16:54:22 +0000156 {
157 char digit_str[10];
158
159 ENTER_PYTHON();
160
161 pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit);
162
163 PyObject_CallFunctionObjArgs(
Benny Prijono0c97d532008-02-14 15:50:46 +0000164 g_obj_callback->on_dtmf_digit,
Benny Prijono1f63cc42007-09-10 16:54:22 +0000165 Py_BuildValue("i",call_id),
166 PyString_FromString(digit_str),
167 NULL
168 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000169
170 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000171 }
172}
173
174
175/*
176 * Notify application on call being transfered.
Benny Prijonodc308702006-12-09 00:39:42 +0000177 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000178 */
179static void cb_on_call_transfer_request(pjsua_call_id call_id,
180 const pj_str_t *dst,
181 pjsip_status_code *code)
182{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000183 if (PyCallable_Check(g_obj_callback->on_call_transfer_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000184 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000185 PyObject * ret;
186 int cd;
187
188 ENTER_PYTHON();
189
Benny Prijonodc308702006-12-09 00:39:42 +0000190 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000191 g_obj_callback->on_call_transfer_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000192 Py_BuildValue("i",call_id),
193 PyString_FromStringAndSize(dst->ptr, dst->slen),
194 Py_BuildValue("i",*code),
195 NULL
196 );
Benny Prijonodc308702006-12-09 00:39:42 +0000197 if (ret != NULL) {
198 if (ret != Py_None) {
199 if (PyArg_Parse(ret,"i",&cd)) {
200 *code = cd;
201 }
202 }
203 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000204
205 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000206 }
207}
208
209
210/*
211 * Notify application of the status of previously sent call
212 * transfer request. Application can monitor the status of the
213 * call transfer request, for example to decide whether to
214 * terminate existing call.
Benny Prijonodc308702006-12-09 00:39:42 +0000215 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000216 */
217static void cb_on_call_transfer_status( pjsua_call_id call_id,
218 int status_code,
219 const pj_str_t *status_text,
220 pj_bool_t final,
221 pj_bool_t *p_cont)
222{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000223 if (PyCallable_Check(g_obj_callback->on_call_transfer_status))
Benny Prijono572d4852006-11-23 21:50:02 +0000224 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000225 PyObject * ret;
226 int cnt;
227
228 ENTER_PYTHON();
229
Benny Prijonodc308702006-12-09 00:39:42 +0000230 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000231 g_obj_callback->on_call_transfer_status,
Benny Prijono572d4852006-11-23 21:50:02 +0000232 Py_BuildValue("i",call_id),
233 Py_BuildValue("i",status_code),
234 PyString_FromStringAndSize(status_text->ptr, status_text->slen),
235 Py_BuildValue("i",final),
236 Py_BuildValue("i",*p_cont),
237 NULL
238 );
Benny Prijonodc308702006-12-09 00:39:42 +0000239 if (ret != NULL) {
240 if (ret != Py_None) {
241 if (PyArg_Parse(ret,"i",&cnt)) {
242 *p_cont = cnt;
243 }
244 }
245 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000246
247 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000248 }
249}
250
251
252/*
253 * Notify application about incoming INVITE with Replaces header.
254 * Application may reject the request by setting non-2xx code.
Benny Prijonodc308702006-12-09 00:39:42 +0000255 * !modified @061206
Benny Prijono572d4852006-11-23 21:50:02 +0000256 */
257static void cb_on_call_replace_request( pjsua_call_id call_id,
258 pjsip_rx_data *rdata,
259 int *st_code,
260 pj_str_t *st_text)
261{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000262 if (PyCallable_Check(g_obj_callback->on_call_replace_request))
Benny Prijono572d4852006-11-23 21:50:02 +0000263 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000264 PyObject * ret;
265 PyObject * txt;
266 int cd;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000267 PyObj_pjsip_rx_data * obj;
Benny Prijonoda275f62007-02-18 23:49:14 +0000268
269 ENTER_PYTHON();
270
Benny Prijono1f63cc42007-09-10 16:54:22 +0000271 obj = (PyObj_pjsip_rx_data *)PyType_GenericNew(&PyTyp_pjsip_rx_data,
Benny Prijono572d4852006-11-23 21:50:02 +0000272 NULL, NULL);
Benny Prijonodc308702006-12-09 00:39:42 +0000273 obj->rdata = rdata;
Benny Prijono572d4852006-11-23 21:50:02 +0000274
Benny Prijonodc308702006-12-09 00:39:42 +0000275 ret = PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000276 g_obj_callback->on_call_replace_request,
Benny Prijono572d4852006-11-23 21:50:02 +0000277 Py_BuildValue("i",call_id),
278 obj,
279 Py_BuildValue("i",*st_code),
280 PyString_FromStringAndSize(st_text->ptr, st_text->slen),
281 NULL
282 );
Benny Prijonodc308702006-12-09 00:39:42 +0000283 if (ret != NULL) {
284 if (ret != Py_None) {
285 if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) {
286 *st_code = cd;
287 st_text->ptr = PyString_AsString(txt);
288 st_text->slen = strlen(PyString_AsString(txt));
289 }
290 }
291 }
Benny Prijonoda275f62007-02-18 23:49:14 +0000292
293 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000294 }
295}
296
297
298/*
299 * Notify application that an existing call has been replaced with
300 * a new call. This happens when PJSUA-API receives incoming INVITE
301 * request with Replaces header.
302 */
303static void cb_on_call_replaced(pjsua_call_id old_call_id,
304 pjsua_call_id new_call_id)
305{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000306 if (PyCallable_Check(g_obj_callback->on_call_replaced))
Benny Prijono572d4852006-11-23 21:50:02 +0000307 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000308 ENTER_PYTHON();
309
Benny Prijono572d4852006-11-23 21:50:02 +0000310 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000311 g_obj_callback->on_call_replaced,
Benny Prijono572d4852006-11-23 21:50:02 +0000312 Py_BuildValue("i",old_call_id),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000313 Py_BuildValue("i",new_call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000314 NULL
315 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000316
317 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000318 }
319}
320
321
322/*
323 * cb_on_reg_state
324 * declares method on_reg_state for callback struct
325 */
326static void cb_on_reg_state(pjsua_acc_id acc_id)
327{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000328 if (PyCallable_Check(g_obj_callback->on_reg_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000329 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000330 ENTER_PYTHON();
331
Benny Prijono1f63cc42007-09-10 16:54:22 +0000332 PyObject_CallFunction(
333 g_obj_callback->on_reg_state,
334 "i",
335 acc_id,
336 NULL
337 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000338
339 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000340 }
341}
342
343
344/*
345 * cb_on_buddy_state
346 * declares method on_buddy state for callback struct
347 */
348static void cb_on_buddy_state(pjsua_buddy_id buddy_id)
349{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000350 if (PyCallable_Check(g_obj_callback->on_buddy_state))
Benny Prijono572d4852006-11-23 21:50:02 +0000351 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000352 ENTER_PYTHON();
353
Benny Prijono1f63cc42007-09-10 16:54:22 +0000354 PyObject_CallFunction(
355 g_obj_callback->on_buddy_state,
356 "i",
357 buddy_id,
358 NULL
359 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000360
361 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000362 }
363}
364
365/*
366 * cb_on_pager
Fahrise314b882007-02-02 10:52:04 +0000367 * declares method on_pager for callback struct
Benny Prijono572d4852006-11-23 21:50:02 +0000368 */
369static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from,
370 const pj_str_t *to, const pj_str_t *contact,
371 const pj_str_t *mime_type, const pj_str_t *body)
372{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000373 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000374 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000375 ENTER_PYTHON();
376
Benny Prijono572d4852006-11-23 21:50:02 +0000377 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000378 g_obj_callback->on_pager,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000379 PyString_FromStringAndSize(from->ptr, from->slen),
380 PyString_FromStringAndSize(to->ptr, to->slen),
381 PyString_FromStringAndSize(contact->ptr, contact->slen),
382 PyString_FromStringAndSize(mime_type->ptr, mime_type->slen),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000383 PyString_FromStringAndSize(body->ptr, body->slen),
384 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000385 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000386
387 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000388 }
389}
390
391
392/*
393 * cb_on_pager_status
394 * declares method on_pager_status for callback struct
395 */
396static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to,
397 const pj_str_t *body, void *user_data,
398 pjsip_status_code status,
399 const pj_str_t *reason)
400{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000401 if (PyCallable_Check(g_obj_callback->on_pager))
Benny Prijono572d4852006-11-23 21:50:02 +0000402 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000403 PyObject * obj_user_data;
404
405 ENTER_PYTHON();
406
407 obj_user_data = Py_BuildValue("i", user_data);
408
Benny Prijono572d4852006-11-23 21:50:02 +0000409 PyObject_CallFunctionObjArgs(
Benny Prijonoda275f62007-02-18 23:49:14 +0000410 g_obj_callback->on_pager_status,
411 Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000412 PyString_FromStringAndSize(to->ptr, to->slen),
Benny Prijonoda275f62007-02-18 23:49:14 +0000413 PyString_FromStringAndSize(body->ptr, body->slen),
414 obj_user_data,
415 Py_BuildValue("i",status),
416 PyString_FromStringAndSize(reason->ptr,reason->slen),
417 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000418 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000419
420 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000421 }
422}
423
424
425/*
426 * cb_on_typing
427 * declares method on_typing for callback struct
428 */
429static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
430 const pj_str_t *to, const pj_str_t *contact,
431 pj_bool_t is_typing)
432{
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000433 if (PyCallable_Check(g_obj_callback->on_typing))
Benny Prijono572d4852006-11-23 21:50:02 +0000434 {
Benny Prijonoda275f62007-02-18 23:49:14 +0000435 ENTER_PYTHON();
436
Benny Prijono572d4852006-11-23 21:50:02 +0000437 PyObject_CallFunctionObjArgs(
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000438 g_obj_callback->on_typing,Py_BuildValue("i",call_id),
Benny Prijono572d4852006-11-23 21:50:02 +0000439 PyString_FromStringAndSize(from->ptr, from->slen),
440 PyString_FromStringAndSize(to->ptr, to->slen),
441 PyString_FromStringAndSize(contact->ptr, contact->slen),
Benny Prijono1f63cc42007-09-10 16:54:22 +0000442 Py_BuildValue("i",is_typing),
443 NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000444 );
Benny Prijonoda275f62007-02-18 23:49:14 +0000445
446 LEAVE_PYTHON();
Benny Prijono572d4852006-11-23 21:50:02 +0000447 }
448}
449
450
Benny Prijono572d4852006-11-23 21:50:02 +0000451
Benny Prijonodc308702006-12-09 00:39:42 +0000452/*
453 * translate_hdr
454 * internal function
455 * translate from hdr_list to pjsip_generic_string_hdr
456 */
457void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
458{
Benny Prijonoda275f62007-02-18 23:49:14 +0000459 pj_list_init(hdr);
Benny Prijonodc308702006-12-09 00:39:42 +0000460
461 if (PyList_Check(py_hdr_list)) {
Benny Prijonoda275f62007-02-18 23:49:14 +0000462 int i;
Benny Prijonodc308702006-12-09 00:39:42 +0000463
Fahris6f35cb82007-02-01 07:41:26 +0000464 for (i = 0; i < PyList_Size(py_hdr_list); i++)
465 {
Benny Prijonodc308702006-12-09 00:39:42 +0000466 pj_str_t hname, hvalue;
467 pjsip_generic_string_hdr * new_hdr;
468 PyObject * tuple = PyList_GetItem(py_hdr_list, i);
469
Fahris6f35cb82007-02-01 07:41:26 +0000470 if (PyTuple_Check(tuple))
471 {
Benny Prijonodc308702006-12-09 00:39:42 +0000472 hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0));
Fahris17d91812007-01-29 12:09:33 +0000473 hname.slen = strlen(PyString_AsString
474 (PyTuple_GetItem(tuple,0)));
Benny Prijonodc308702006-12-09 00:39:42 +0000475 hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1));
Fahris17d91812007-01-29 12:09:33 +0000476 hvalue.slen = strlen(PyString_AsString
477 (PyTuple_GetItem(tuple,1)));
Benny Prijonodc308702006-12-09 00:39:42 +0000478 } else {
479 hname.ptr = "";
480 hname.slen = 0;
481 hvalue.ptr = "";
482 hvalue.slen = 0;
483 }
484 new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
485 pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr);
486 }
487 }
488}
489
490/*
491 * translate_hdr_rev
492 * internal function
493 * translate from pjsip_generic_string_hdr to hdr_list
494 */
495
496void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list)
497{
498 int i;
499 int len;
500 pjsip_generic_string_hdr * p_hdr;
501
502 len = pj_list_size(hdr);
503
Fahris6f35cb82007-02-01 07:41:26 +0000504 if (len > 0)
505 {
506 p_hdr = hdr;
Benny Prijonodc308702006-12-09 00:39:42 +0000507 Py_XDECREF(py_hdr_list);
508 py_hdr_list = PyList_New(len);
509
Fahris6f35cb82007-02-01 07:41:26 +0000510 for (i = 0; i < len && p_hdr != NULL; i++)
511 {
512 PyObject * tuple;
513 PyObject * str;
Benny Prijonodc308702006-12-09 00:39:42 +0000514
Fahris6f35cb82007-02-01 07:41:26 +0000515 tuple = PyTuple_New(2);
Benny Prijonodc308702006-12-09 00:39:42 +0000516
Fahris6f35cb82007-02-01 07:41:26 +0000517 str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen);
518 PyTuple_SetItem(tuple, 0, str);
519 str = PyString_FromStringAndSize
520 (hdr->hvalue.ptr, p_hdr->hvalue.slen);
521 PyTuple_SetItem(tuple, 1, str);
522 PyList_SetItem(py_hdr_list, i, tuple);
523 p_hdr = p_hdr->next;
Benny Prijonodc308702006-12-09 00:39:42 +0000524 }
525 }
526
527
528}
Benny Prijono572d4852006-11-23 21:50:02 +0000529
530/*
Benny Prijonodc308702006-12-09 00:39:42 +0000531 * py_pjsua_thread_register
532 * !added @ 061206
533 */
Benny Prijono1f63cc42007-09-10 16:54:22 +0000534static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +0000535{
536
537 pj_status_t status;
538 const char *name;
539 PyObject *py_desc;
540 pj_thread_t *thread;
541 void *thread_desc;
Fahrisdcf8fa42006-12-28 03:13:48 +0000542#if 0
Benny Prijonodc308702006-12-09 00:39:42 +0000543 int size;
544 int i;
545 int *td;
Fahrisdcf8fa42006-12-28 03:13:48 +0000546#endif
Benny Prijonodc308702006-12-09 00:39:42 +0000547
Benny Prijono1f63cc42007-09-10 16:54:22 +0000548 PJ_UNUSED_ARG(pSelf);
549
Benny Prijonodc308702006-12-09 00:39:42 +0000550 if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc))
551 {
552 return NULL;
553 }
554#if 0
555 size = PyList_Size(py_desc);
556 td = (int *)malloc(size * sizeof(int));
Fahris6f35cb82007-02-01 07:41:26 +0000557 for (i = 0; i < size; i++)
558 {
559 if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i]))
560 {
Benny Prijonodc308702006-12-09 00:39:42 +0000561 return NULL;
562 }
563 }
564 thread_desc = td;
565#else
566 thread_desc = malloc(sizeof(pj_thread_desc));
567#endif
568 status = pj_thread_register(name, thread_desc, &thread);
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000569
570 if (status == PJ_SUCCESS)
571 status = pj_thread_local_set(thread_id, (void*)1);
Benny Prijonodc308702006-12-09 00:39:42 +0000572 return Py_BuildValue("i",status);
573}
Benny Prijono572d4852006-11-23 21:50:02 +0000574
575/*
576 * py_pjsua_logging_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000577 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000578 */
579static PyObject *py_pjsua_logging_config_default(PyObject *pSelf,
580 PyObject *pArgs)
581{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000582 PyObj_pjsua_logging_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000583 pjsua_logging_config cfg;
584
Benny Prijono1f63cc42007-09-10 16:54:22 +0000585 PJ_UNUSED_ARG(pSelf);
586
Benny Prijonodc308702006-12-09 00:39:42 +0000587 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000588 {
589 return NULL;
590 }
Benny Prijonodc308702006-12-09 00:39:42 +0000591
Benny Prijono572d4852006-11-23 21:50:02 +0000592 pjsua_logging_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000593 obj = (PyObj_pjsua_logging_config *) PyObj_pjsua_logging_config_new
594 (&PyTyp_pjsua_logging_config,NULL,NULL);
595 PyObj_pjsua_logging_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +0000596
597 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000598}
599
600
601/*
602 * py_pjsua_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000603 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000604 */
605static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs)
606{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000607 PyObj_pjsua_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000608 pjsua_config cfg;
609
Benny Prijono1f63cc42007-09-10 16:54:22 +0000610 PJ_UNUSED_ARG(pSelf);
611
Benny Prijonodc308702006-12-09 00:39:42 +0000612 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000613 {
614 return NULL;
615 }
616 pjsua_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000617 obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, NULL, NULL);
618 PyObj_pjsua_config_import(obj, &cfg);
619
Benny Prijonodc308702006-12-09 00:39:42 +0000620 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000621}
622
623
624/*
625 * py_pjsua_media_config_default
Benny Prijonodc308702006-12-09 00:39:42 +0000626 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000627 */
628static PyObject * py_pjsua_media_config_default(PyObject *pSelf,
629 PyObject *pArgs)
630{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000631 PyObj_pjsua_media_config *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000632 pjsua_media_config cfg;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000633
634 PJ_UNUSED_ARG(pSelf);
635
Benny Prijonodc308702006-12-09 00:39:42 +0000636 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000637 {
638 return NULL;
639 }
640 pjsua_media_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000641 obj = (PyObj_pjsua_media_config *)
642 PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL);
643 PyObj_pjsua_media_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +0000644 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000645}
646
647
648/*
649 * py_pjsua_msg_data_init
Benny Prijonodc308702006-12-09 00:39:42 +0000650 * !modified @ 051206
Benny Prijono572d4852006-11-23 21:50:02 +0000651 */
652static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs)
653{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000654 PyObj_pjsua_msg_data *obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000655 pjsua_msg_data msg;
Benny Prijonodc308702006-12-09 00:39:42 +0000656
Benny Prijono1f63cc42007-09-10 16:54:22 +0000657 PJ_UNUSED_ARG(pSelf);
658
Benny Prijonodc308702006-12-09 00:39:42 +0000659 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono572d4852006-11-23 21:50:02 +0000660 {
661 return NULL;
662 }
663 pjsua_msg_data_init(&msg);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000664 obj = (PyObj_pjsua_msg_data *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +0000665 Py_XDECREF(obj->content_type);
666 obj->content_type = PyString_FromStringAndSize(
667 msg.content_type.ptr, msg.content_type.slen
668 );
669 Py_XDECREF(obj->msg_body);
670 obj->msg_body = PyString_FromStringAndSize(
671 msg.msg_body.ptr, msg.msg_body.slen
672 );
Benny Prijono572d4852006-11-23 21:50:02 +0000673
Fahris17d91812007-01-29 12:09:33 +0000674 translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list);
Benny Prijonodc308702006-12-09 00:39:42 +0000675
676 return (PyObject *)obj;
Benny Prijono572d4852006-11-23 21:50:02 +0000677}
678
679
680/*
681 * py_pjsua_reconfigure_logging
682 */
683static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs)
684{
Fahris6f35cb82007-02-01 07:41:26 +0000685 PyObject * logObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000686 PyObj_pjsua_logging_config *log;
Benny Prijono572d4852006-11-23 21:50:02 +0000687 pjsua_logging_config cfg;
688 pj_status_t status;
689
Benny Prijono1f63cc42007-09-10 16:54:22 +0000690 PJ_UNUSED_ARG(pSelf);
691
Fahris17d91812007-01-29 12:09:33 +0000692 if (!PyArg_ParseTuple(pArgs, "O", &logObj))
Benny Prijono572d4852006-11-23 21:50:02 +0000693 {
694 return NULL;
695 }
Fahris6f35cb82007-02-01 07:41:26 +0000696 if (logObj != Py_None)
697 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000698 log = (PyObj_pjsua_logging_config *)logObj;
Fahris17d91812007-01-29 12:09:33 +0000699 cfg.msg_logging = log->msg_logging;
700 cfg.level = log->level;
701 cfg.console_level = log->console_level;
702 cfg.decor = log->decor;
703 cfg.log_filename.ptr = PyString_AsString(log->log_filename);
704 cfg.log_filename.slen = strlen(cfg.log_filename.ptr);
Benny Prijonoda275f62007-02-18 23:49:14 +0000705 Py_XDECREF(obj_log_cb);
706 obj_log_cb = log->cb;
707 Py_INCREF(obj_log_cb);
708 cfg.cb = &cb_log_cb;
Fahris17d91812007-01-29 12:09:33 +0000709 status = pjsua_reconfigure_logging(&cfg);
710 } else {
711 status = pjsua_reconfigure_logging(NULL);
Fahris6f35cb82007-02-01 07:41:26 +0000712 }
Benny Prijono572d4852006-11-23 21:50:02 +0000713 return Py_BuildValue("i",status);
714}
715
716
717/*
718 * py_pjsua_pool_create
719 */
720static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs)
721{
722 pj_size_t init_size;
723 pj_size_t increment;
724 const char * name;
725 pj_pool_t *p;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000726 PyObj_pj_pool *pool;
727
728 PJ_UNUSED_ARG(pSelf);
Benny Prijono572d4852006-11-23 21:50:02 +0000729
730 if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment))
731 {
732 return NULL;
733 }
Fahris89ea3d02007-02-07 08:18:35 +0000734
Benny Prijono572d4852006-11-23 21:50:02 +0000735 p = pjsua_pool_create(name, init_size, increment);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000736 pool = (PyObj_pj_pool *)PyType_GenericNew(&PyTyp_pj_pool_t, NULL, NULL);
Benny Prijono572d4852006-11-23 21:50:02 +0000737 pool->pool = p;
738 return (PyObject *)pool;
739
740}
741
742
743/*
744 * py_pjsua_get_pjsip_endpt
745 */
746static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs)
747{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000748 PyObj_pjsip_endpoint *endpt;
Benny Prijono572d4852006-11-23 21:50:02 +0000749 pjsip_endpoint *e;
750
Benny Prijono1f63cc42007-09-10 16:54:22 +0000751 PJ_UNUSED_ARG(pSelf);
752
Benny Prijono572d4852006-11-23 21:50:02 +0000753 if (!PyArg_ParseTuple(pArgs, ""))
754 {
755 return NULL;
756 }
757 e = pjsua_get_pjsip_endpt();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000758 endpt = (PyObj_pjsip_endpoint *)PyType_GenericNew(
759 &PyTyp_pjsip_endpoint, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000760 );
761 endpt->endpt = e;
762 return (PyObject *)endpt;
763}
764
765
766/*
767 * py_pjsua_get_pjmedia_endpt
768 */
769static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs)
770{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000771 PyObj_pjmedia_endpt *endpt;
Benny Prijono572d4852006-11-23 21:50:02 +0000772 pjmedia_endpt *e;
773
Benny Prijono1f63cc42007-09-10 16:54:22 +0000774 PJ_UNUSED_ARG(pSelf);
775
Benny Prijono572d4852006-11-23 21:50:02 +0000776 if (!PyArg_ParseTuple(pArgs, ""))
777 {
778 return NULL;
779 }
780 e = pjsua_get_pjmedia_endpt();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000781 endpt = (PyObj_pjmedia_endpt *)PyType_GenericNew(
782 &PyTyp_pjmedia_endpt, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000783 );
784 endpt->endpt = e;
785 return (PyObject *)endpt;
786}
787
788
789/*
790 * py_pjsua_get_pool_factory
791 */
792static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs)
793{
Benny Prijono1f63cc42007-09-10 16:54:22 +0000794 PyObj_pj_pool_factory *pool;
Benny Prijono572d4852006-11-23 21:50:02 +0000795 pj_pool_factory *p;
796
Benny Prijono1f63cc42007-09-10 16:54:22 +0000797 PJ_UNUSED_ARG(pSelf);
798
Benny Prijono572d4852006-11-23 21:50:02 +0000799 if (!PyArg_ParseTuple(pArgs, ""))
800 {
801 return NULL;
802 }
803 p = pjsua_get_pool_factory();
Benny Prijono1f63cc42007-09-10 16:54:22 +0000804 pool = (PyObj_pj_pool_factory *)PyType_GenericNew(
805 &PyTyp_pj_pool_factory, NULL, NULL
Benny Prijono572d4852006-11-23 21:50:02 +0000806 );
807 pool->pool_fact = p;
808 return (PyObject *)pool;
809}
810
811
812/*
813 * py_pjsua_perror
814 */
815static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs)
816{
817 const char *sender;
818 const char *title;
819 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000820
821 PJ_UNUSED_ARG(pSelf);
822
Benny Prijono572d4852006-11-23 21:50:02 +0000823 if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status))
824 {
825 return NULL;
826 }
Benny Prijonodc308702006-12-09 00:39:42 +0000827
Benny Prijono572d4852006-11-23 21:50:02 +0000828 pjsua_perror(sender, title, status);
829 Py_INCREF(Py_None);
830 return Py_None;
831}
832
833
834/*
835 * py_pjsua_create
836 */
837static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs)
838{
839 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000840
841 PJ_UNUSED_ARG(pSelf);
842
Benny Prijono572d4852006-11-23 21:50:02 +0000843 if (!PyArg_ParseTuple(pArgs, ""))
844 {
845 return NULL;
846 }
847 status = pjsua_create();
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000848
Fahris6f35cb82007-02-01 07:41:26 +0000849 if (status == PJ_SUCCESS)
850 {
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000851 status = pj_thread_local_alloc(&thread_id);
852 if (status == PJ_SUCCESS)
853 status = pj_thread_local_set(thread_id, (void*)1);
854 }
855
Benny Prijono572d4852006-11-23 21:50:02 +0000856 return Py_BuildValue("i",status);
857}
858
859
860/*
861 * py_pjsua_init
862 */
863static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
864{
865 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000866 PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg;
867 pjsua_config cfg_ua, *p_cfg_ua;
868 pjsua_logging_config cfg_log, *p_cfg_log;
869 pjsua_media_config cfg_media, *p_cfg_media;
Benny Prijono572d4852006-11-23 21:50:02 +0000870
Benny Prijono1f63cc42007-09-10 16:54:22 +0000871 PJ_UNUSED_ARG(pSelf);
872
873 if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg))
Benny Prijono572d4852006-11-23 21:50:02 +0000874 {
875 return NULL;
876 }
Fahris17d91812007-01-29 12:09:33 +0000877
Benny Prijono572d4852006-11-23 21:50:02 +0000878 pjsua_config_default(&cfg_ua);
879 pjsua_logging_config_default(&cfg_log);
880 pjsua_media_config_default(&cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +0000881
Benny Prijono1f63cc42007-09-10 16:54:22 +0000882 if (o_ua_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000883 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000884 PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000885
Benny Prijono1f63cc42007-09-10 16:54:22 +0000886 PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg);
887
888 g_obj_callback = obj_ua_cfg->cb;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000889 Py_INCREF(g_obj_callback);
890
891 cfg_ua.cb.on_call_state = &cb_on_call_state;
892 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;
893 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000894 cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000895 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;
896 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;
897 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;
898 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;
899 cfg_ua.cb.on_reg_state = &cb_on_reg_state;
900 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;
901 cfg_ua.cb.on_pager = &cb_on_pager;
902 cfg_ua.cb.on_pager_status = &cb_on_pager_status;
903 cfg_ua.cb.on_typing = &cb_on_typing;
Benny Prijono572d4852006-11-23 21:50:02 +0000904
Fahris17d91812007-01-29 12:09:33 +0000905 p_cfg_ua = &cfg_ua;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000906
Fahris17d91812007-01-29 12:09:33 +0000907 } else {
908 p_cfg_ua = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000909 }
910
Benny Prijono1f63cc42007-09-10 16:54:22 +0000911 if (o_log_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000912 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000913 PyObj_pjsua_logging_config * obj_log;
914
915 obj_log = (PyObj_pjsua_logging_config *)o_log_cfg;
916
917 PyObj_pjsua_logging_config_export(&cfg_log, obj_log);
918
Benny Prijonoda275f62007-02-18 23:49:14 +0000919 Py_XDECREF(obj_log_cb);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000920 obj_log_cb = obj_log->cb;
Benny Prijonoda275f62007-02-18 23:49:14 +0000921 Py_INCREF(obj_log_cb);
Benny Prijono1f63cc42007-09-10 16:54:22 +0000922
Benny Prijonoda275f62007-02-18 23:49:14 +0000923 cfg_log.cb = &cb_log_cb;
Fahris17d91812007-01-29 12:09:33 +0000924 p_cfg_log = &cfg_log;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000925
Fahris17d91812007-01-29 12:09:33 +0000926 } else {
927 p_cfg_log = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000928 }
929
Benny Prijono1f63cc42007-09-10 16:54:22 +0000930 if (o_media_cfg != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +0000931 {
Benny Prijono1f63cc42007-09-10 16:54:22 +0000932 PyObj_pjsua_media_config_export(&cfg_media,
933 (PyObj_pjsua_media_config*)o_media_cfg);
934 p_cfg_media = &cfg_media;
935
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000936 } else {
Fahris17d91812007-01-29 12:09:33 +0000937 p_cfg_media = NULL;
Benny Prijonoed7a5a72007-01-29 18:36:38 +0000938 }
939
Fahris17d91812007-01-29 12:09:33 +0000940 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);
Benny Prijono572d4852006-11-23 21:50:02 +0000941 return Py_BuildValue("i",status);
942}
943
944
945/*
946 * py_pjsua_start
947 */
948static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs)
949{
950 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000951
952 PJ_UNUSED_ARG(pSelf);
953
Benny Prijono572d4852006-11-23 21:50:02 +0000954 if (!PyArg_ParseTuple(pArgs, ""))
955 {
956 return NULL;
957 }
958 status = pjsua_start();
Fahris89ea3d02007-02-07 08:18:35 +0000959
Benny Prijono572d4852006-11-23 21:50:02 +0000960 return Py_BuildValue("i",status);
961}
962
963
964/*
965 * py_pjsua_destroy
966 */
967static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs)
968{
969 pj_status_t status;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000970
971 PJ_UNUSED_ARG(pSelf);
972
Benny Prijono572d4852006-11-23 21:50:02 +0000973 if (!PyArg_ParseTuple(pArgs, ""))
974 {
975 return NULL;
976 }
977 status = pjsua_destroy();
Fahris89ea3d02007-02-07 08:18:35 +0000978
Benny Prijono572d4852006-11-23 21:50:02 +0000979 return Py_BuildValue("i",status);
980}
981
982
983/*
984 * py_pjsua_handle_events
985 */
986static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs)
987{
988 int ret;
989 unsigned msec;
Benny Prijono1f63cc42007-09-10 16:54:22 +0000990
991 PJ_UNUSED_ARG(pSelf);
992
Benny Prijono572d4852006-11-23 21:50:02 +0000993 if (!PyArg_ParseTuple(pArgs, "i", &msec))
994 {
995 return NULL;
996 }
Benny Prijono4759f9c2007-02-14 02:15:19 +0000997
998 /* Since handle_events() will block, we must wrap it with ALLOW_THREADS
999 * construct, or otherwise many Python blocking functions (such as
1000 * time.sleep(), readline(), etc.) may hang/block indefinitely.
1001 * See http://www.python.org/doc/current/api/threads.html for more info.
1002 */
1003 Py_BEGIN_ALLOW_THREADS
Benny Prijono572d4852006-11-23 21:50:02 +00001004 ret = pjsua_handle_events(msec);
Benny Prijono4759f9c2007-02-14 02:15:19 +00001005 Py_END_ALLOW_THREADS
Fahris89ea3d02007-02-07 08:18:35 +00001006
Benny Prijono572d4852006-11-23 21:50:02 +00001007 return Py_BuildValue("i",ret);
1008}
1009
1010
1011/*
1012 * py_pjsua_verify_sip_url
1013 */
1014static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs)
1015{
1016 pj_status_t status;
1017 const char *url;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001018
1019 PJ_UNUSED_ARG(pSelf);
1020
Benny Prijono572d4852006-11-23 21:50:02 +00001021 if (!PyArg_ParseTuple(pArgs, "s", &url))
1022 {
1023 return NULL;
1024 }
1025 status = pjsua_verify_sip_url(url);
Fahris89ea3d02007-02-07 08:18:35 +00001026
Benny Prijono572d4852006-11-23 21:50:02 +00001027 return Py_BuildValue("i",status);
1028}
1029
1030
Benny Prijono572d4852006-11-23 21:50:02 +00001031/*
Benny Prijonodc308702006-12-09 00:39:42 +00001032 * function doc
Benny Prijono572d4852006-11-23 21:50:02 +00001033 */
1034
Benny Prijonodc308702006-12-09 00:39:42 +00001035static char pjsua_thread_register_doc[] =
1036 "int py_pjsua.thread_register(string name, int[] desc)";
Benny Prijono572d4852006-11-23 21:50:02 +00001037static char pjsua_perror_doc[] =
1038 "void py_pjsua.perror (string sender, string title, int status) "
1039 "Display error message for the specified error code. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001040 "sender: The log sender field; "
1041 "title: Message title for the error; "
1042 "status: Status code.";
Benny Prijono572d4852006-11-23 21:50:02 +00001043
1044static char pjsua_create_doc[] =
1045 "int py_pjsua.create (void) "
1046 "Instantiate pjsua application. Application "
1047 "must call this function before calling any other functions, to make sure "
1048 "that the underlying libraries are properly initialized. Once this "
1049 "function has returned success, application must call pjsua_destroy() "
1050 "before quitting.";
1051
1052static char pjsua_init_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001053 "int py_pjsua.init (py_pjsua.Config obj_ua_cfg, "
Benny Prijono572d4852006-11-23 21:50:02 +00001054 "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) "
1055 "Initialize pjsua with the specified settings. All the settings are "
1056 "optional, and the default values will be used when the config is not "
1057 "specified. Parameters: "
Benny Prijono1f63cc42007-09-10 16:54:22 +00001058 "obj_ua_cfg : User agent configuration; "
Fahris6f35cb82007-02-01 07:41:26 +00001059 "log_cfg : Optional logging configuration; "
1060 "media_cfg : Optional media configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00001061
1062static char pjsua_start_doc[] =
1063 "int py_pjsua.start (void) "
1064 "Application is recommended to call this function after all "
1065 "initialization is done, so that the library can do additional checking "
1066 "set up additional";
1067
1068static char pjsua_destroy_doc[] =
1069 "int py_pjsua.destroy (void) "
1070 "Destroy pjsua This function must be called once PJSUA is created. To "
1071 "make it easier for application, application may call this function "
1072 "several times with no danger.";
1073
1074static char pjsua_handle_events_doc[] =
1075 "int py_pjsua.handle_events (int msec_timeout) "
1076 "Poll pjsua for events, and if necessary block the caller thread for the "
1077 "specified maximum interval (in miliseconds) Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001078 "msec_timeout: Maximum time to wait, in miliseconds. "
Benny Prijono572d4852006-11-23 21:50:02 +00001079 "Returns: The number of events that have been handled during the poll. "
1080 "Negative value indicates error, and application can retrieve the error "
1081 "as (err = -return_value).";
1082
1083static char pjsua_verify_sip_url_doc[] =
1084 "int py_pjsua.verify_sip_url (string c_url) "
1085 "Verify that valid SIP url is given Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001086 "c_url: The URL, as NULL terminated string.";
Benny Prijono572d4852006-11-23 21:50:02 +00001087
1088static char pjsua_pool_create_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001089 "py_pjsua.Pj_Pool py_pjsua.pool_create (string name, int init_size, "
Benny Prijono572d4852006-11-23 21:50:02 +00001090 "int increment) "
1091 "Create memory pool Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001092 "name: Optional pool name; "
1093 "init_size: Initial size of the pool; "
1094 "increment: Increment size.";
Benny Prijono572d4852006-11-23 21:50:02 +00001095
1096static char pjsua_get_pjsip_endpt_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001097 "py_pjsua.Pjsip_Endpoint py_pjsua.get_pjsip_endpt (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001098 "Internal function to get SIP endpoint instance of pjsua, which is needed "
1099 "for example to register module, create transports, etc. Probably is only "
1100 "valid after pjsua_init() is called.";
1101
1102static char pjsua_get_pjmedia_endpt_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001103 "py_pjsua.Pjmedia_Endpt py_pjsua.get_pjmedia_endpt (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001104 "Internal function to get media endpoint instance. Only valid after "
1105 "pjsua_init() is called.";
1106
1107static char pjsua_get_pool_factory_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001108 "py_pjsua.Pj_Pool_Factory py_pjsua.get_pool_factory (void) "
Benny Prijono572d4852006-11-23 21:50:02 +00001109 "Internal function to get PJSUA pool factory. Only valid after "
1110 "pjsua_init() is called.";
1111
1112static char pjsua_reconfigure_logging_doc[] =
1113 "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) "
1114 "Application can call this function at any time (after pjsua_create(), of "
1115 "course) to change logging settings. Parameters: "
Fahris6f35cb82007-02-01 07:41:26 +00001116 "c: Logging configuration.";
Benny Prijono572d4852006-11-23 21:50:02 +00001117
1118static char pjsua_logging_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001119 "py_pjsua.Logging_Config py_pjsua.logging_config_default () "
Benny Prijono572d4852006-11-23 21:50:02 +00001120 "Use this function to initialize logging config.";
1121
1122static char pjsua_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001123 "py_pjsua.Config py_pjsua.config_default (). Use this function to "
1124 "initialize pjsua config. ";
Benny Prijono572d4852006-11-23 21:50:02 +00001125
1126static char pjsua_media_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001127 "py_pjsua.Media_Config py_pjsua.media_config_default (). "
Benny Prijono572d4852006-11-23 21:50:02 +00001128 "Use this function to initialize media config.";
1129
Benny Prijono572d4852006-11-23 21:50:02 +00001130static char pjsua_msg_data_init_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001131 "py_pjsua.Msg_Data void py_pjsua.msg_data_init () "
1132 "Initialize message data ";
1133
Benny Prijono572d4852006-11-23 21:50:02 +00001134
Benny Prijono98793592006-12-04 08:33:20 +00001135/* END OF LIB BASE */
1136
1137/* LIB TRANSPORT */
1138
1139/*
Benny Prijono98793592006-12-04 08:33:20 +00001140 * py_pjsua_transport_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001141 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001142 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001143static PyObject *py_pjsua_transport_config_default(PyObject *pSelf,
1144 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001145{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001146 PyObj_pjsua_transport_config *obj;
Benny Prijono98793592006-12-04 08:33:20 +00001147 pjsua_transport_config cfg;
1148
Benny Prijono1f63cc42007-09-10 16:54:22 +00001149 PJ_UNUSED_ARG(pSelf);
1150
1151 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001152 return NULL;
1153 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001154
Benny Prijono98793592006-12-04 08:33:20 +00001155 pjsua_transport_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001156 obj = (PyObj_pjsua_transport_config*)
1157 PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config,
1158 NULL, NULL);
1159 PyObj_pjsua_transport_config_import(obj, &cfg);
1160
Benny Prijonodc308702006-12-09 00:39:42 +00001161 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00001162}
1163
1164/*
Benny Prijono98793592006-12-04 08:33:20 +00001165 * py_pjsua_transport_create
Benny Prijonodc308702006-12-09 00:39:42 +00001166 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001167 */
1168static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs)
1169{
1170 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001171 int type;
Fahris6f35cb82007-02-01 07:41:26 +00001172 PyObject * tmpObj;
Benny Prijonodc308702006-12-09 00:39:42 +00001173 pjsua_transport_config cfg;
1174 pjsua_transport_id id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001175
1176 PJ_UNUSED_ARG(pSelf);
1177
1178 if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj)) {
Benny Prijono98793592006-12-04 08:33:20 +00001179 return NULL;
1180 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001181
1182 if (tmpObj != Py_None) {
1183 PyObj_pjsua_transport_config *obj;
1184 obj = (PyObj_pjsua_transport_config*)tmpObj;
1185 PyObj_pjsua_transport_config_export(&cfg, obj);
Fahris17d91812007-01-29 12:09:33 +00001186 status = pjsua_transport_create(type, &cfg, &id);
Fahris6f35cb82007-02-01 07:41:26 +00001187 } else {
Fahris17d91812007-01-29 12:09:33 +00001188 status = pjsua_transport_create(type, NULL, &id);
Fahris6f35cb82007-02-01 07:41:26 +00001189 }
Benny Prijonodc308702006-12-09 00:39:42 +00001190
1191
Benny Prijono1f63cc42007-09-10 16:54:22 +00001192 return Py_BuildValue("ii", status, id);
Benny Prijono98793592006-12-04 08:33:20 +00001193}
1194
1195/*
1196 * py_pjsua_enum_transports
Fahrisdcf8fa42006-12-28 03:13:48 +00001197 * !modified @ 261206
Benny Prijono98793592006-12-04 08:33:20 +00001198 */
1199static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs)
1200{
1201 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001202 PyObject *list;
1203
Fahrisdcf8fa42006-12-28 03:13:48 +00001204 pjsua_transport_id id[PJSIP_MAX_TRANSPORTS];
Fahris17d91812007-01-29 12:09:33 +00001205 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001206
1207 PJ_UNUSED_ARG(pSelf);
1208
Fahrisdcf8fa42006-12-28 03:13:48 +00001209 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00001210 {
1211 return NULL;
1212 }
Benny Prijonodc308702006-12-09 00:39:42 +00001213
Fahrisdcf8fa42006-12-28 03:13:48 +00001214 c = PJ_ARRAY_SIZE(id);
Benny Prijono98793592006-12-04 08:33:20 +00001215 status = pjsua_enum_transports(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001216
1217 list = PyList_New(c);
1218 for (i = 0; i < c; i++)
1219 {
1220 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
1221 if (ret == -1)
1222 {
1223 return NULL;
1224 }
1225 }
1226
Benny Prijonodc308702006-12-09 00:39:42 +00001227 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001228}
1229
1230/*
1231 * py_pjsua_transport_get_info
Benny Prijonodc308702006-12-09 00:39:42 +00001232 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001233 */
1234static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs)
1235{
1236 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001237 int id;
Benny Prijonodc308702006-12-09 00:39:42 +00001238 pjsua_transport_info info;
1239
Benny Prijono1f63cc42007-09-10 16:54:22 +00001240 PJ_UNUSED_ARG(pSelf);
Benny Prijono98793592006-12-04 08:33:20 +00001241
Benny Prijono1f63cc42007-09-10 16:54:22 +00001242 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001243 return NULL;
1244 }
Benny Prijonodc308702006-12-09 00:39:42 +00001245
Benny Prijono98793592006-12-04 08:33:20 +00001246 status = pjsua_transport_get_info(id, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001247 if (status == PJ_SUCCESS) {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001248 PyObj_pjsua_transport_info *obj;
1249 obj = (PyObj_pjsua_transport_info *)
1250 PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info,
1251 NULL, NULL);
1252 PyObj_pjsua_transport_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001253 return Py_BuildValue("O", obj);
1254 } else {
1255 Py_INCREF(Py_None);
1256 return Py_None;
1257 }
Benny Prijono98793592006-12-04 08:33:20 +00001258}
1259
1260/*
1261 * py_pjsua_transport_set_enable
1262 */
1263static PyObject *py_pjsua_transport_set_enable
1264(PyObject *pSelf, PyObject *pArgs)
1265{
1266 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001267 int id;
1268 int enabled;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001269
1270 PJ_UNUSED_ARG(pSelf);
1271
Benny Prijono98793592006-12-04 08:33:20 +00001272 if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled))
1273 {
1274 return NULL;
1275 }
1276 status = pjsua_transport_set_enable(id, enabled);
Fahris89ea3d02007-02-07 08:18:35 +00001277
Benny Prijono98793592006-12-04 08:33:20 +00001278 return Py_BuildValue("i",status);
1279}
1280
1281/*
1282 * py_pjsua_transport_close
1283 */
1284static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs)
1285{
1286 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001287 int id;
1288 int force;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001289
1290 PJ_UNUSED_ARG(pSelf);
1291
Benny Prijono98793592006-12-04 08:33:20 +00001292 if (!PyArg_ParseTuple(pArgs, "ii", &id, &force))
1293 {
1294 return NULL;
1295 }
1296 status = pjsua_transport_close(id, force);
Fahris89ea3d02007-02-07 08:18:35 +00001297
Benny Prijono98793592006-12-04 08:33:20 +00001298 return Py_BuildValue("i",status);
1299}
1300
Benny Prijono98793592006-12-04 08:33:20 +00001301static char pjsua_transport_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001302 "py_pjsua.Transport_Config py_pjsua.transport_config_default () "
1303 "Call this function to initialize UDP config with default values.";
Benny Prijono98793592006-12-04 08:33:20 +00001304static char pjsua_transport_create_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001305 "int, int py_pjsua.transport_create (int type, "
1306 "py_pjsua.Transport_Config cfg) "
1307 "Create SIP transport.";
Benny Prijono98793592006-12-04 08:33:20 +00001308static char pjsua_enum_transports_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001309 "int[] py_pjsua.enum_transports () "
Benny Prijonodc308702006-12-09 00:39:42 +00001310 "Enumerate all transports currently created in the system.";
Benny Prijono98793592006-12-04 08:33:20 +00001311static char pjsua_transport_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001312 "void py_pjsua.transport_get_info "
1313 "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) "
1314 "Get information about transports.";
Benny Prijono98793592006-12-04 08:33:20 +00001315static char pjsua_transport_set_enable_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001316 "void py_pjsua.transport_set_enable "
1317 "(py_pjsua.Transport_ID id, int enabled) "
1318 "Disable a transport or re-enable it. "
1319 "By default transport is always enabled after it is created. "
1320 "Disabling a transport does not necessarily close the socket, "
1321 "it will only discard incoming messages and prevent the transport "
1322 "from being used to send outgoing messages.";
Benny Prijono98793592006-12-04 08:33:20 +00001323static char pjsua_transport_close_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001324 "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) "
1325 "Close the transport. If transport is forcefully closed, "
1326 "it will be immediately closed, and any pending transactions "
1327 "that are using the transport may not terminate properly. "
1328 "Otherwise, the system will wait until all transactions are closed "
1329 "while preventing new users from using the transport, and will close "
1330 "the transport when it is safe to do so.";
Benny Prijono98793592006-12-04 08:33:20 +00001331
1332/* END OF LIB TRANSPORT */
1333
1334/* LIB ACCOUNT */
1335
Benny Prijono98793592006-12-04 08:33:20 +00001336
1337/*
Benny Prijono98793592006-12-04 08:33:20 +00001338 * py_pjsua_acc_config_default
Benny Prijonodc308702006-12-09 00:39:42 +00001339 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001340 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001341static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001342{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001343 PyObj_pjsua_acc_config *obj;
Benny Prijono98793592006-12-04 08:33:20 +00001344 pjsua_acc_config cfg;
Benny Prijono98793592006-12-04 08:33:20 +00001345
Benny Prijono1f63cc42007-09-10 16:54:22 +00001346 PJ_UNUSED_ARG(pSelf);
1347
1348 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001349 return NULL;
1350 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001351
Benny Prijono98793592006-12-04 08:33:20 +00001352 pjsua_acc_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001353 obj = (PyObj_pjsua_acc_config *)
1354 PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config,
1355 NULL, NULL);
1356 PyObj_pjsua_acc_config_import(obj, &cfg);
Benny Prijonodc308702006-12-09 00:39:42 +00001357 return (PyObject *)obj;
Benny Prijono98793592006-12-04 08:33:20 +00001358}
1359
1360/*
1361 * py_pjsua_acc_get_count
1362 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001363static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001364{
Benny Prijonodc308702006-12-09 00:39:42 +00001365 int count;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001366
1367 PJ_UNUSED_ARG(pSelf);
1368
1369 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001370 return NULL;
1371 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001372
Benny Prijono98793592006-12-04 08:33:20 +00001373 count = pjsua_acc_get_count();
1374 return Py_BuildValue("i",count);
1375}
1376
1377/*
1378 * py_pjsua_acc_is_valid
1379 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001380static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001381{
Benny Prijonodc308702006-12-09 00:39:42 +00001382 int id;
1383 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00001384
Benny Prijono1f63cc42007-09-10 16:54:22 +00001385 PJ_UNUSED_ARG(pSelf);
1386
1387 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001388 return NULL;
1389 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001390
1391 is_valid = pjsua_acc_is_valid(id);
Benny Prijono98793592006-12-04 08:33:20 +00001392 return Py_BuildValue("i", is_valid);
1393}
1394
1395/*
1396 * py_pjsua_acc_set_default
1397 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001398static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001399{
Benny Prijonodc308702006-12-09 00:39:42 +00001400 int id;
1401 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001402
Benny Prijono1f63cc42007-09-10 16:54:22 +00001403 PJ_UNUSED_ARG(pSelf);
1404
1405 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001406 return NULL;
1407 }
1408 status = pjsua_acc_set_default(id);
1409
1410 return Py_BuildValue("i", status);
1411}
1412
1413/*
1414 * py_pjsua_acc_get_default
1415 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001416static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001417{
Benny Prijonodc308702006-12-09 00:39:42 +00001418 int id;
Benny Prijono98793592006-12-04 08:33:20 +00001419
Benny Prijono1f63cc42007-09-10 16:54:22 +00001420 PJ_UNUSED_ARG(pSelf);
1421
1422 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001423 return NULL;
1424 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001425
Benny Prijono98793592006-12-04 08:33:20 +00001426 id = pjsua_acc_get_default();
1427
1428 return Py_BuildValue("i", id);
1429}
1430
1431/*
1432 * py_pjsua_acc_add
Benny Prijonodc308702006-12-09 00:39:42 +00001433 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001434 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001435static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001436{
Benny Prijonodc308702006-12-09 00:39:42 +00001437 int is_default;
Fahris6f35cb82007-02-01 07:41:26 +00001438 PyObject * acObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001439 PyObj_pjsua_acc_config * ac;
1440 int acc_id;
Benny Prijonodc308702006-12-09 00:39:42 +00001441 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001442
Benny Prijono1f63cc42007-09-10 16:54:22 +00001443 PJ_UNUSED_ARG(pSelf);
1444
1445 if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default)) {
Benny Prijono98793592006-12-04 08:33:20 +00001446 return NULL;
1447 }
Benny Prijonodc308702006-12-09 00:39:42 +00001448
Benny Prijono1f63cc42007-09-10 16:54:22 +00001449 if (acObj != Py_None) {
1450 pjsua_acc_config cfg;
1451
1452 pjsua_acc_config_default(&cfg);
1453 ac = (PyObj_pjsua_acc_config *)acObj;
1454 PyObj_pjsua_acc_config_export(&cfg, ac);
1455 status = pjsua_acc_add(&cfg, is_default, &acc_id);
Fahris17d91812007-01-29 12:09:33 +00001456 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001457 status = PJ_EINVAL;
1458 acc_id = PJSUA_INVALID_ID;
Fahris6f35cb82007-02-01 07:41:26 +00001459 }
Benny Prijonodc308702006-12-09 00:39:42 +00001460
Benny Prijono1f63cc42007-09-10 16:54:22 +00001461 return Py_BuildValue("ii", status, acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00001462}
1463
1464/*
1465 * py_pjsua_acc_add_local
Benny Prijonodc308702006-12-09 00:39:42 +00001466 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001467 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001468static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001469{
Benny Prijonodc308702006-12-09 00:39:42 +00001470 int is_default;
1471 int tid;
Benny Prijonodc308702006-12-09 00:39:42 +00001472 int p_acc_id;
1473 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001474
Benny Prijono1f63cc42007-09-10 16:54:22 +00001475 PJ_UNUSED_ARG(pSelf);
Benny Prijono98793592006-12-04 08:33:20 +00001476
Benny Prijono1f63cc42007-09-10 16:54:22 +00001477 if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) {
Benny Prijono98793592006-12-04 08:33:20 +00001478 return NULL;
1479 }
1480
Benny Prijonodc308702006-12-09 00:39:42 +00001481
Benny Prijono98793592006-12-04 08:33:20 +00001482 status = pjsua_acc_add_local(tid, is_default, &p_acc_id);
Benny Prijonodc308702006-12-09 00:39:42 +00001483
1484 return Py_BuildValue("ii", status, p_acc_id);
Benny Prijono98793592006-12-04 08:33:20 +00001485}
1486
1487/*
1488 * py_pjsua_acc_del
1489 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001490static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001491{
Benny Prijonodc308702006-12-09 00:39:42 +00001492 int acc_id;
1493 int status;
1494
Benny Prijono1f63cc42007-09-10 16:54:22 +00001495 PJ_UNUSED_ARG(pSelf);
1496
Benny Prijono98793592006-12-04 08:33:20 +00001497 if (!PyArg_ParseTuple(pArgs, "i", &acc_id))
1498 {
1499 return NULL;
1500 }
1501
1502
1503 status = pjsua_acc_del(acc_id);
1504 return Py_BuildValue("i", status);
1505}
1506
1507/*
1508 * py_pjsua_acc_modify
1509 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001510static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001511{
Fahris6f35cb82007-02-01 07:41:26 +00001512 PyObject * acObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001513 PyObj_pjsua_acc_config * ac;
Benny Prijonodc308702006-12-09 00:39:42 +00001514 int acc_id;
1515 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001516
Benny Prijono1f63cc42007-09-10 16:54:22 +00001517 PJ_UNUSED_ARG(pSelf);
1518
1519 if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj)) {
Benny Prijono98793592006-12-04 08:33:20 +00001520 return NULL;
1521 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00001522
1523 if (acObj != Py_None) {
1524 pjsua_acc_config cfg;
1525
1526 pjsua_acc_config_default(&cfg);
1527 ac = (PyObj_pjsua_acc_config *)acObj;
1528 PyObj_pjsua_acc_config_export(&cfg, ac);
1529
Fahris17d91812007-01-29 12:09:33 +00001530 status = pjsua_acc_modify(acc_id, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001531 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001532 status = PJ_EINVAL;
Fahris6f35cb82007-02-01 07:41:26 +00001533 }
Benny Prijono98793592006-12-04 08:33:20 +00001534 return Py_BuildValue("i", status);
1535}
1536
1537/*
1538 * py_pjsua_acc_set_online_status
1539 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001540static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf,
1541 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001542{
Benny Prijonodc308702006-12-09 00:39:42 +00001543 int is_online;
1544 int acc_id;
1545 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001546
Benny Prijono1f63cc42007-09-10 16:54:22 +00001547 PJ_UNUSED_ARG(pSelf);
1548
1549 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) {
Benny Prijono98793592006-12-04 08:33:20 +00001550 return NULL;
1551 }
1552
1553 status = pjsua_acc_set_online_status(acc_id, is_online);
1554
1555 return Py_BuildValue("i", status);
1556}
1557
1558/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00001559 * py_pjsua_acc_set_online_status2
1560 */
1561static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf,
1562 PyObject *pArgs)
1563{
1564 int is_online;
1565 int acc_id;
1566 int activity_id;
1567 const char *activity_text;
1568 pjrpid_element rpid;
1569 pj_status_t status;
1570
1571 PJ_UNUSED_ARG(pSelf);
1572
1573 if (!PyArg_ParseTuple(pArgs, "iiis", &acc_id, &is_online,
1574 &activity_id, &activity_text)) {
1575 return NULL;
1576 }
1577
1578 pj_bzero(&rpid, sizeof(rpid));
1579 rpid.activity = activity_id;
1580 rpid.note = pj_str((char*)activity_text);
1581
1582 status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid);
1583
1584 return Py_BuildValue("i", status);
1585}
1586
1587/*
Benny Prijono98793592006-12-04 08:33:20 +00001588 * py_pjsua_acc_set_registration
1589 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001590static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf,
1591 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001592{
Benny Prijonodc308702006-12-09 00:39:42 +00001593 int renew;
1594 int acc_id;
1595 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001596
Benny Prijono1f63cc42007-09-10 16:54:22 +00001597 PJ_UNUSED_ARG(pSelf);
1598
1599 if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) {
Benny Prijono98793592006-12-04 08:33:20 +00001600 return NULL;
1601 }
1602
1603 status = pjsua_acc_set_registration(acc_id, renew);
1604
1605 return Py_BuildValue("i", status);
1606}
1607
1608/*
Benny Prijonodc308702006-12-09 00:39:42 +00001609 * py_pjsua_acc_get_info
1610 * !modified @ 051206
Benny Prijono98793592006-12-04 08:33:20 +00001611 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001612static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001613{
Benny Prijonodc308702006-12-09 00:39:42 +00001614 int acc_id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001615 PyObj_pjsua_acc_info * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00001616 pjsua_acc_info info;
1617 int status;
Benny Prijono98793592006-12-04 08:33:20 +00001618
Benny Prijono1f63cc42007-09-10 16:54:22 +00001619 PJ_UNUSED_ARG(pSelf);
1620
1621 if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) {
Benny Prijono98793592006-12-04 08:33:20 +00001622 return NULL;
1623 }
Benny Prijonodc308702006-12-09 00:39:42 +00001624
Benny Prijono98793592006-12-04 08:33:20 +00001625 status = pjsua_acc_get_info(acc_id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001626 if (status == PJ_SUCCESS) {
1627 obj = (PyObj_pjsua_acc_info *)
1628 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info,NULL, NULL);
1629 PyObj_pjsua_acc_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00001630 return Py_BuildValue("O", obj);
1631 } else {
1632 Py_INCREF(Py_None);
1633 return Py_None;
1634 }
Benny Prijono98793592006-12-04 08:33:20 +00001635}
1636
1637/*
1638 * py_pjsua_enum_accs
Fahrisdcf8fa42006-12-28 03:13:48 +00001639 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00001640 */
1641static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs)
1642{
1643 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001644 PyObject *list;
1645
Fahrisdcf8fa42006-12-28 03:13:48 +00001646 pjsua_acc_id id[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00001647 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001648
1649 PJ_UNUSED_ARG(pSelf);
1650
Fahrisdcf8fa42006-12-28 03:13:48 +00001651 if (!PyArg_ParseTuple(pArgs, ""))
Benny Prijono98793592006-12-04 08:33:20 +00001652 {
1653 return NULL;
1654 }
Fahrisdcf8fa42006-12-28 03:13:48 +00001655 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00001656
Benny Prijono98793592006-12-04 08:33:20 +00001657 status = pjsua_enum_accs(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001658
1659 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00001660 for (i = 0; i < c; i++)
1661 {
Benny Prijonodc308702006-12-09 00:39:42 +00001662 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00001663 if (ret == -1)
1664 {
Benny Prijonodc308702006-12-09 00:39:42 +00001665 return NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00001666 }
Benny Prijonodc308702006-12-09 00:39:42 +00001667 }
1668
Benny Prijonodc308702006-12-09 00:39:42 +00001669 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001670}
1671
1672/*
1673 * py_pjsua_acc_enum_info
Fahrisdcf8fa42006-12-28 03:13:48 +00001674 * !modified @ 241206
Benny Prijono98793592006-12-04 08:33:20 +00001675 */
1676static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs)
1677{
1678 pj_status_t status;
Benny Prijonodc308702006-12-09 00:39:42 +00001679 PyObject *list;
Fahrisdcf8fa42006-12-28 03:13:48 +00001680 pjsua_acc_info info[PJSUA_MAX_ACC];
Fahris17d91812007-01-29 12:09:33 +00001681 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001682
1683 PJ_UNUSED_ARG(pSelf);
1684
1685 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001686 return NULL;
1687 }
Benny Prijonodc308702006-12-09 00:39:42 +00001688
Fahrisdcf8fa42006-12-28 03:13:48 +00001689 c = PJ_ARRAY_SIZE(info);
Benny Prijono98793592006-12-04 08:33:20 +00001690 status = pjsua_acc_enum_info(info, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001691
1692 list = PyList_New(c);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001693 for (i = 0; i < c; i++) {
1694 PyObj_pjsua_acc_info *obj;
1695 obj = (PyObj_pjsua_acc_info *)
1696 PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL);
1697
1698 PyObj_pjsua_acc_info_import(obj, &info[i]);
1699
1700 PyList_SetItem(list, i, (PyObject *)obj);
Benny Prijonodc308702006-12-09 00:39:42 +00001701 }
1702
Benny Prijonodc308702006-12-09 00:39:42 +00001703 return Py_BuildValue("O",list);
Benny Prijono98793592006-12-04 08:33:20 +00001704}
1705
1706/*
1707 * py_pjsua_acc_find_for_outgoing
1708 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001709static PyObject *py_pjsua_acc_find_for_outgoing(PyObject *pSelf,
1710 PyObject *pArgs)
1711{
Benny Prijonodc308702006-12-09 00:39:42 +00001712 int acc_id;
1713 PyObject * url;
1714 pj_str_t str;
Benny Prijono98793592006-12-04 08:33:20 +00001715
Benny Prijono1f63cc42007-09-10 16:54:22 +00001716 PJ_UNUSED_ARG(pSelf);
1717
Benny Prijono98793592006-12-04 08:33:20 +00001718 if (!PyArg_ParseTuple(pArgs, "O", &url))
1719 {
1720 return NULL;
1721 }
Benny Prijonodc308702006-12-09 00:39:42 +00001722 str.ptr = PyString_AsString(url);
1723 str.slen = strlen(PyString_AsString(url));
Benny Prijono98793592006-12-04 08:33:20 +00001724
1725 acc_id = pjsua_acc_find_for_outgoing(&str);
1726
1727 return Py_BuildValue("i", acc_id);
1728}
1729
1730/*
1731 * py_pjsua_acc_find_for_incoming
1732 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001733static PyObject *py_pjsua_acc_find_for_incoming(PyObject *pSelf,
1734 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001735{
Benny Prijonodc308702006-12-09 00:39:42 +00001736 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001737 PyObject * tmpObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001738 PyObj_pjsip_rx_data * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00001739 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00001740
Benny Prijono1f63cc42007-09-10 16:54:22 +00001741 PJ_UNUSED_ARG(pSelf);
1742
Fahris17d91812007-01-29 12:09:33 +00001743 if (!PyArg_ParseTuple(pArgs, "O", &tmpObj))
Benny Prijono98793592006-12-04 08:33:20 +00001744 {
1745 return NULL;
1746 }
Fahris17d91812007-01-29 12:09:33 +00001747 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001748 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001749 obj = (PyObj_pjsip_rx_data *)tmpObj;
Fahris17d91812007-01-29 12:09:33 +00001750 rdata = obj->rdata;
1751 acc_id = pjsua_acc_find_for_incoming(rdata);
Fahris6f35cb82007-02-01 07:41:26 +00001752 } else {
Fahris17d91812007-01-29 12:09:33 +00001753 acc_id = pjsua_acc_find_for_incoming(NULL);
Fahris6f35cb82007-02-01 07:41:26 +00001754 }
Benny Prijono98793592006-12-04 08:33:20 +00001755 return Py_BuildValue("i", acc_id);
1756}
1757
1758/*
1759 * py_pjsua_acc_create_uac_contact
Benny Prijonodc308702006-12-09 00:39:42 +00001760 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00001761 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001762static PyObject *py_pjsua_acc_create_uac_contact(PyObject *pSelf,
1763 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001764{
Benny Prijonodc308702006-12-09 00:39:42 +00001765 int status;
Fahris17d91812007-01-29 12:09:33 +00001766 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001767 PyObject * pObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001768 PyObj_pj_pool * p;
Benny Prijonodc308702006-12-09 00:39:42 +00001769 pj_pool_t * pool;
1770 PyObject * strc;
1771 pj_str_t contact;
1772 PyObject * stru;
1773 pj_str_t uri;
Benny Prijono98793592006-12-04 08:33:20 +00001774
Benny Prijono1f63cc42007-09-10 16:54:22 +00001775 PJ_UNUSED_ARG(pSelf);
1776
Fahris17d91812007-01-29 12:09:33 +00001777 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru))
Benny Prijono98793592006-12-04 08:33:20 +00001778 {
1779 return NULL;
1780 }
Fahris17d91812007-01-29 12:09:33 +00001781 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001782 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001783 p = (PyObj_pj_pool *)pObj;
Fahris17d91812007-01-29 12:09:33 +00001784 pool = p->pool;
1785 uri.ptr = PyString_AsString(stru);
1786 uri.slen = strlen(PyString_AsString(stru));
1787 status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00001788 } else {
Fahris17d91812007-01-29 12:09:33 +00001789 status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri);
Fahris6f35cb82007-02-01 07:41:26 +00001790 }
Benny Prijonodc308702006-12-09 00:39:42 +00001791 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00001792
Benny Prijonodc308702006-12-09 00:39:42 +00001793 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00001794}
1795
1796/*
1797 * py_pjsua_acc_create_uas_contact
Benny Prijonodc308702006-12-09 00:39:42 +00001798 * !modified @ 061206
Benny Prijono98793592006-12-04 08:33:20 +00001799 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001800static PyObject *py_pjsua_acc_create_uas_contact(PyObject *pSelf,
1801 PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001802{
Benny Prijonodc308702006-12-09 00:39:42 +00001803 int status;
1804 int acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00001805 PyObject * pObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001806 PyObj_pj_pool * p;
Benny Prijonodc308702006-12-09 00:39:42 +00001807 pj_pool_t * pool;
1808 PyObject * strc;
1809 pj_str_t contact;
Fahris6f35cb82007-02-01 07:41:26 +00001810 PyObject * rObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001811 PyObj_pjsip_rx_data * objr;
Benny Prijonodc308702006-12-09 00:39:42 +00001812 pjsip_rx_data * rdata;
Benny Prijono98793592006-12-04 08:33:20 +00001813
Benny Prijono1f63cc42007-09-10 16:54:22 +00001814 PJ_UNUSED_ARG(pSelf);
1815
Fahris17d91812007-01-29 12:09:33 +00001816 if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj))
Benny Prijono98793592006-12-04 08:33:20 +00001817 {
1818 return NULL;
1819 }
Fahris17d91812007-01-29 12:09:33 +00001820 if (pObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001821 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001822 p = (PyObj_pj_pool *)pObj;
Fahris17d91812007-01-29 12:09:33 +00001823 pool = p->pool;
1824 } else {
1825 pool = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00001826 }
Fahris17d91812007-01-29 12:09:33 +00001827 if (rObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00001828 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00001829 objr = (PyObj_pjsip_rx_data *)rObj;
Fahris17d91812007-01-29 12:09:33 +00001830 rdata = objr->rdata;
Fahris6f35cb82007-02-01 07:41:26 +00001831 } else {
Fahris17d91812007-01-29 12:09:33 +00001832 rdata = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00001833 }
Benny Prijono98793592006-12-04 08:33:20 +00001834 status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata);
Benny Prijonodc308702006-12-09 00:39:42 +00001835 strc = PyString_FromStringAndSize(contact.ptr, contact.slen);
Benny Prijono98793592006-12-04 08:33:20 +00001836
Benny Prijonodc308702006-12-09 00:39:42 +00001837 return Py_BuildValue("O", strc);
Benny Prijono98793592006-12-04 08:33:20 +00001838}
1839
1840static char pjsua_acc_config_default_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001841 "py_pjsua.Acc_Config py_pjsua.acc_config_default () "
Benny Prijono98793592006-12-04 08:33:20 +00001842 "Call this function to initialize account config with default values.";
1843static char pjsua_acc_get_count_doc[] =
1844 "int py_pjsua.acc_get_count () "
1845 "Get number of current accounts.";
1846static char pjsua_acc_is_valid_doc[] =
1847 "int py_pjsua.acc_is_valid (int acc_id) "
1848 "Check if the specified account ID is valid.";
1849static char pjsua_acc_set_default_doc[] =
1850 "int py_pjsua.acc_set_default (int acc_id) "
1851 "Set default account to be used when incoming "
Benny Prijonodc308702006-12-09 00:39:42 +00001852 "and outgoing requests doesn't match any accounts.";
Benny Prijono98793592006-12-04 08:33:20 +00001853static char pjsua_acc_get_default_doc[] =
1854 "int py_pjsua.acc_get_default () "
1855 "Get default account.";
1856static char pjsua_acc_add_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001857 "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, "
1858 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00001859 "Add a new account to pjsua. PJSUA must have been initialized "
Benny Prijonodc308702006-12-09 00:39:42 +00001860 "(with pjsua_init()) before calling this function.";
Benny Prijono98793592006-12-04 08:33:20 +00001861static char pjsua_acc_add_local_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001862 "int,int py_pjsua.acc_add_local (int tid, "
1863 "int is_default) "
Benny Prijono98793592006-12-04 08:33:20 +00001864 "Add a local account. A local account is used to identify "
Benny Prijonodc308702006-12-09 00:39:42 +00001865 "local endpoint instead of a specific user, and for this reason, "
1866 "a transport ID is needed to obtain the local address information.";
Benny Prijono98793592006-12-04 08:33:20 +00001867static char pjsua_acc_del_doc[] =
1868 "int py_pjsua.acc_del (int acc_id) "
1869 "Delete account.";
1870static char pjsua_acc_modify_doc[] =
1871 "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) "
1872 "Modify account information.";
1873static char pjsua_acc_set_online_status_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001874 "int py_pjsua.acc_set_online_status2(int acc_id, int is_online) "
1875 "Modify account's presence status to be advertised "
1876 "to remote/presence subscribers.";
1877static char pjsua_acc_set_online_status2_doc[] =
1878 "int py_pjsua.acc_set_online_status (int acc_id, int is_online, "
1879 "int activity_id, string activity_text) "
Benny Prijono98793592006-12-04 08:33:20 +00001880 "Modify account's presence status to be advertised "
Benny Prijonodc308702006-12-09 00:39:42 +00001881 "to remote/presence subscribers.";
Benny Prijono98793592006-12-04 08:33:20 +00001882static char pjsua_acc_set_registration_doc[] =
1883 "int py_pjsua.acc_set_registration (int acc_id, int renew) "
1884 "Update registration or perform unregistration.";
1885static char pjsua_acc_get_info_doc[] =
Benny Prijonodc308702006-12-09 00:39:42 +00001886 "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) "
Benny Prijono98793592006-12-04 08:33:20 +00001887 "Get account information.";
1888static char pjsua_enum_accs_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001889 "int[] py_pjsua.enum_accs () "
Benny Prijono98793592006-12-04 08:33:20 +00001890 "Enum accounts all account ids.";
1891static char pjsua_acc_enum_info_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00001892 "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () "
Benny Prijono98793592006-12-04 08:33:20 +00001893 "Enum accounts info.";
1894static char pjsua_acc_find_for_outgoing_doc[] =
1895 "int py_pjsua.acc_find_for_outgoing (string url) "
1896 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00001897 "to used to reach to the specified URL.";
Benny Prijono98793592006-12-04 08:33:20 +00001898static char pjsua_acc_find_for_incoming_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001899 "int py_pjsua.acc_find_for_incoming (PyObj_pjsip_rx_data rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00001900 "This is an internal function to find the most appropriate account "
Benny Prijonodc308702006-12-09 00:39:42 +00001901 "to be used to handle incoming calls.";
Benny Prijono98793592006-12-04 08:33:20 +00001902static char pjsua_acc_create_uac_contact_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001903 "string py_pjsua.acc_create_uac_contact (PyObj_pj_pool pool, "
Benny Prijonodc308702006-12-09 00:39:42 +00001904 "int acc_id, string uri) "
Benny Prijono98793592006-12-04 08:33:20 +00001905 "Create a suitable URI to be put as Contact based on the specified "
Benny Prijonodc308702006-12-09 00:39:42 +00001906 "target URI for the specified account.";
Benny Prijono98793592006-12-04 08:33:20 +00001907static char pjsua_acc_create_uas_contact_doc[] =
Benny Prijono1f63cc42007-09-10 16:54:22 +00001908 "string py_pjsua.acc_create_uas_contact (PyObj_pj_pool pool, "
1909 "int acc_id, PyObj_pjsip_rx_data rdata) "
Benny Prijono98793592006-12-04 08:33:20 +00001910 "Create a suitable URI to be put as Contact based on the information "
Benny Prijonodc308702006-12-09 00:39:42 +00001911 "in the incoming request.";
Benny Prijono98793592006-12-04 08:33:20 +00001912
1913/* END OF LIB ACCOUNT */
1914
Benny Prijonodc308702006-12-09 00:39:42 +00001915/* LIB BUDDY */
1916
1917
1918
1919/*
Fahris6f35cb82007-02-01 07:41:26 +00001920 * py_pjsua_buddy_config_default
1921 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001922static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf,
1923 PyObject *pArgs)
Fahris6f35cb82007-02-01 07:41:26 +00001924{
Benny Prijono1f63cc42007-09-10 16:54:22 +00001925 PyObj_pjsua_buddy_config *obj;
Fahris6f35cb82007-02-01 07:41:26 +00001926 pjsua_buddy_config cfg;
1927
Benny Prijono1f63cc42007-09-10 16:54:22 +00001928 PJ_UNUSED_ARG(pSelf);
1929
1930 if (!PyArg_ParseTuple(pArgs, "")) {
Fahris6f35cb82007-02-01 07:41:26 +00001931 return NULL;
1932 }
1933
1934 pjsua_buddy_config_default(&cfg);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001935 obj = (PyObj_pjsua_buddy_config *)
1936 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL);
1937 PyObj_pjsua_buddy_config_import(obj, &cfg);
Fahris6f35cb82007-02-01 07:41:26 +00001938
1939 return (PyObject *)obj;
1940}
1941
1942/*
Benny Prijonodc308702006-12-09 00:39:42 +00001943 * py_pjsua_get_buddy_count
1944 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001945static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs)
Benny Prijono98793592006-12-04 08:33:20 +00001946{
Benny Prijonodc308702006-12-09 00:39:42 +00001947 int ret;
Benny Prijono98793592006-12-04 08:33:20 +00001948
Benny Prijono1f63cc42007-09-10 16:54:22 +00001949 PJ_UNUSED_ARG(pSelf);
1950
1951 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijono98793592006-12-04 08:33:20 +00001952 return NULL;
1953 }
Benny Prijonodc308702006-12-09 00:39:42 +00001954 ret = pjsua_get_buddy_count();
1955
1956 return Py_BuildValue("i", ret);
1957}
Benny Prijono98793592006-12-04 08:33:20 +00001958
Benny Prijonodc308702006-12-09 00:39:42 +00001959/*
1960 * py_pjsua_buddy_is_valid
1961 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00001962static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00001963{
1964 int id;
1965 int is_valid;
Benny Prijono98793592006-12-04 08:33:20 +00001966
Benny Prijono1f63cc42007-09-10 16:54:22 +00001967 PJ_UNUSED_ARG(pSelf);
1968
1969 if (!PyArg_ParseTuple(pArgs, "i", &id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00001970 return NULL;
1971 }
1972 is_valid = pjsua_buddy_is_valid(id);
1973
1974 return Py_BuildValue("i", is_valid);
1975}
1976
1977/*
1978 * py_pjsua_enum_buddies
Fahrisdcf8fa42006-12-28 03:13:48 +00001979 * !modified @ 241206
Benny Prijonodc308702006-12-09 00:39:42 +00001980 */
1981static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs)
1982{
1983 pj_status_t status;
1984 PyObject *list;
1985
Fahrisdcf8fa42006-12-28 03:13:48 +00001986 pjsua_buddy_id id[PJSUA_MAX_BUDDIES];
Fahris17d91812007-01-29 12:09:33 +00001987 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00001988
1989 PJ_UNUSED_ARG(pSelf);
1990
1991 if (!PyArg_ParseTuple(pArgs, "")) {
Benny Prijonodc308702006-12-09 00:39:42 +00001992 return NULL;
1993 }
Fahrisdcf8fa42006-12-28 03:13:48 +00001994 c = PJ_ARRAY_SIZE(id);
Benny Prijonodc308702006-12-09 00:39:42 +00001995 status = pjsua_enum_buddies(id, &c);
Benny Prijonodc308702006-12-09 00:39:42 +00001996 list = PyList_New(c);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001997 for (i = 0; i < c; i++) {
1998 PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Benny Prijonodc308702006-12-09 00:39:42 +00001999 }
2000
Benny Prijonodc308702006-12-09 00:39:42 +00002001 return Py_BuildValue("O",list);
2002}
2003
2004/*
2005 * py_pjsua_buddy_get_info
2006 * !modified @ 071206
2007 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002008static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002009{
2010 int buddy_id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002011 PyObj_pjsua_buddy_info * obj;
Benny Prijonodc308702006-12-09 00:39:42 +00002012 pjsua_buddy_info info;
2013 int status;
Benny Prijonodc308702006-12-09 00:39:42 +00002014
Benny Prijono1f63cc42007-09-10 16:54:22 +00002015 PJ_UNUSED_ARG(pSelf);
2016
2017 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002018 return NULL;
2019 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002020
Benny Prijonodc308702006-12-09 00:39:42 +00002021 status = pjsua_buddy_get_info(buddy_id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00002022 if (status == PJ_SUCCESS) {
2023 obj = (PyObj_pjsua_buddy_info *)
2024 PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info,NULL,NULL);
2025 PyObj_pjsua_buddy_info_import(obj, &info);
Benny Prijonodc308702006-12-09 00:39:42 +00002026 return Py_BuildValue("O", obj);
2027 } else {
2028 Py_INCREF(Py_None);
2029 return Py_None;
2030 }
2031}
2032
2033/*
2034 * py_pjsua_buddy_add
2035 * !modified @ 061206
2036 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002037static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs)
Fahris17d91812007-01-29 12:09:33 +00002038{
2039 PyObject * bcObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002040 int buddy_id;
Benny Prijonodc308702006-12-09 00:39:42 +00002041 int status;
2042
Benny Prijono1f63cc42007-09-10 16:54:22 +00002043 PJ_UNUSED_ARG(pSelf);
2044
2045 if (!PyArg_ParseTuple(pArgs, "O", &bcObj)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002046 return NULL;
2047 }
Fahris17d91812007-01-29 12:09:33 +00002048
Benny Prijono1f63cc42007-09-10 16:54:22 +00002049 if (bcObj != Py_None) {
2050 pjsua_buddy_config cfg;
2051 PyObj_pjsua_buddy_config * bc;
2052
2053 bc = (PyObj_pjsua_buddy_config *)bcObj;
2054
2055 pjsua_buddy_config_default(&cfg);
2056 PyObj_pjsua_buddy_config_export(&cfg, bc);
Benny Prijonodc308702006-12-09 00:39:42 +00002057
Benny Prijono1f63cc42007-09-10 16:54:22 +00002058 status = pjsua_buddy_add(&cfg, &buddy_id);
Fahris6f35cb82007-02-01 07:41:26 +00002059 } else {
Benny Prijono1f63cc42007-09-10 16:54:22 +00002060 status = PJ_EINVAL;
2061 buddy_id = PJSUA_INVALID_ID;
Fahris17d91812007-01-29 12:09:33 +00002062 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002063 return Py_BuildValue("ii", status, buddy_id);
Benny Prijonodc308702006-12-09 00:39:42 +00002064}
2065
2066/*
2067 * py_pjsua_buddy_del
2068 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002069static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002070{
2071 int buddy_id;
2072 int status;
2073
Benny Prijono1f63cc42007-09-10 16:54:22 +00002074 PJ_UNUSED_ARG(pSelf);
2075
2076 if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002077 return NULL;
2078 }
2079
2080
2081 status = pjsua_buddy_del(buddy_id);
2082 return Py_BuildValue("i", status);
2083}
2084
2085/*
2086 * py_pjsua_buddy_subscribe_pres
2087 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002088static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002089{
2090 int buddy_id;
2091 int status;
2092 int subscribe;
2093
Benny Prijono1f63cc42007-09-10 16:54:22 +00002094 PJ_UNUSED_ARG(pSelf);
2095
2096 if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002097 return NULL;
2098 }
2099
2100
2101 status = pjsua_buddy_subscribe_pres(buddy_id, subscribe);
2102 return Py_BuildValue("i", status);
2103}
2104
2105/*
2106 * py_pjsua_pres_dump
2107 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002108static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002109{
2110 int verbose;
2111
Benny Prijono1f63cc42007-09-10 16:54:22 +00002112 PJ_UNUSED_ARG(pSelf);
2113
2114 if (!PyArg_ParseTuple(pArgs, "i", &verbose)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002115 return NULL;
2116 }
2117
2118
2119 pjsua_pres_dump(verbose);
Benny Prijono98793592006-12-04 08:33:20 +00002120 Py_INCREF(Py_None);
2121 return Py_None;
2122}
2123
Benny Prijonodc308702006-12-09 00:39:42 +00002124/*
2125 * py_pjsua_im_send
2126 * !modified @ 071206
2127 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002128static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002129{
2130 int status;
2131 int acc_id;
Fahrise314b882007-02-02 10:52:04 +00002132 pj_str_t * mime_type, tmp_mime_type;
Fahris6f35cb82007-02-01 07:41:26 +00002133 pj_str_t to, content;
Benny Prijonodc308702006-12-09 00:39:42 +00002134 PyObject * st;
2135 PyObject * smt;
2136 PyObject * sc;
2137 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00002138 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002139 PyObj_pjsua_msg_data * omd;
Fahris6f35cb82007-02-01 07:41:26 +00002140
Benny Prijonodc308702006-12-09 00:39:42 +00002141 int user_data;
2142 pj_pool_t *pool;
2143
Benny Prijono1f63cc42007-09-10 16:54:22 +00002144 PJ_UNUSED_ARG(pSelf);
2145
Fahris17d91812007-01-29 12:09:33 +00002146 if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id,
2147 &st, &smt, &sc, &omdObj, &user_data))
Benny Prijonodc308702006-12-09 00:39:42 +00002148 {
2149 return NULL;
2150 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002151 if (smt != Py_None) {
Fahrise314b882007-02-02 10:52:04 +00002152 mime_type = &tmp_mime_type;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002153 tmp_mime_type = PyString_to_pj_str(smt);
Fahris6f35cb82007-02-01 07:41:26 +00002154 } else {
2155 mime_type = NULL;
2156 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002157 to = PyString_to_pj_str(st);
2158 content = PyString_to_pj_str(sc);
2159
2160 if (omdObj != Py_None) {
Fahris17d91812007-01-29 12:09:33 +00002161
Benny Prijono1f63cc42007-09-10 16:54:22 +00002162 omd = (PyObj_pjsua_msg_data *)omdObj;
2163 msg_data.content_type = PyString_to_pj_str(omd->content_type);
2164 msg_data.msg_body = PyString_to_pj_str(omd->msg_body);
Fahris6f35cb82007-02-01 07:41:26 +00002165 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00002166
Fahris17d91812007-01-29 12:09:33 +00002167 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00002168 status = pjsua_im_send(acc_id, &to, mime_type,
2169 &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00002170 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00002171 } else {
Fahris17d91812007-01-29 12:09:33 +00002172
Fahris6f35cb82007-02-01 07:41:26 +00002173 status = pjsua_im_send(acc_id, &to, mime_type,
Fahris17d91812007-01-29 12:09:33 +00002174 &content, NULL, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00002175 }
Fahrise314b882007-02-02 10:52:04 +00002176
Benny Prijonodc308702006-12-09 00:39:42 +00002177 return Py_BuildValue("i",status);
2178}
2179
2180/*
2181 * py_pjsua_im_typing
2182 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002183static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs)
Benny Prijonodc308702006-12-09 00:39:42 +00002184{
2185 int status;
2186 int acc_id;
2187 pj_str_t to;
2188 PyObject * st;
2189 int is_typing;
2190 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00002191 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002192 PyObj_pjsua_msg_data * omd;
Benny Prijonodc308702006-12-09 00:39:42 +00002193 pj_pool_t * pool;
2194
Benny Prijono1f63cc42007-09-10 16:54:22 +00002195 PJ_UNUSED_ARG(pSelf);
2196
2197 if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj)) {
Benny Prijonodc308702006-12-09 00:39:42 +00002198 return NULL;
2199 }
2200
Benny Prijono1f63cc42007-09-10 16:54:22 +00002201 to = PyString_to_pj_str(st);
2202
2203 if (omdObj != Py_None) {
2204 omd = (PyObj_pjsua_msg_data *)omdObj;
2205 msg_data.content_type = PyString_to_pj_str(omd->content_type);
2206 msg_data.msg_body = PyString_to_pj_str(omd->msg_body);
Fahris6f35cb82007-02-01 07:41:26 +00002207 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Benny Prijonodc308702006-12-09 00:39:42 +00002208
Fahris17d91812007-01-29 12:09:33 +00002209 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
2210 status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data);
2211 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00002212 } else {
Fahris17d91812007-01-29 12:09:33 +00002213 status = pjsua_im_typing(acc_id, &to, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00002214 }
Benny Prijonodc308702006-12-09 00:39:42 +00002215 return Py_BuildValue("i",status);
2216}
2217
Fahris6f35cb82007-02-01 07:41:26 +00002218static char pjsua_buddy_config_default_doc[] =
2219 "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () "
2220 "Set default values to the buddy config.";
Benny Prijonodc308702006-12-09 00:39:42 +00002221static char pjsua_get_buddy_count_doc[] =
2222 "int py_pjsua.get_buddy_count () "
2223 "Get total number of buddies.";
2224static char pjsua_buddy_is_valid_doc[] =
2225 "int py_pjsua.buddy_is_valid (int buddy_id) "
2226 "Check if buddy ID is valid.";
2227static char pjsua_enum_buddies_doc[] =
Fahrisdcf8fa42006-12-28 03:13:48 +00002228 "int[] py_pjsua.enum_buddies () "
Benny Prijonodc308702006-12-09 00:39:42 +00002229 "Enum buddy IDs.";
2230static char pjsua_buddy_get_info_doc[] =
2231 "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) "
2232 "Get detailed buddy info.";
2233static char pjsua_buddy_add_doc[] =
2234 "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) "
2235 "Add new buddy.";
2236static char pjsua_buddy_del_doc[] =
2237 "int py_pjsua.buddy_del (int buddy_id) "
2238 "Delete buddy.";
2239static char pjsua_buddy_subscribe_pres_doc[] =
2240 "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) "
2241 "Enable/disable buddy's presence monitoring.";
2242static char pjsua_pres_dump_doc[] =
2243 "void py_pjsua.pres_dump (int verbose) "
2244 "Dump presence subscriptions to log file.";
2245static char pjsua_im_send_doc[] =
2246 "int py_pjsua.im_send (int acc_id, string to, string mime_type, "
2247 "string content, py_pjsua.Msg_Data msg_data, int user_data) "
2248 "Send instant messaging outside dialog, using the specified account "
2249 "for route set and authentication.";
2250static char pjsua_im_typing_doc[] =
2251 "int py_pjsua.im_typing (int acc_id, string to, int is_typing, "
2252 "py_pjsua.Msg_Data msg_data) "
2253 "Send typing indication outside dialog.";
2254
2255/* END OF LIB BUDDY */
2256
Fahrisdcf8fa42006-12-28 03:13:48 +00002257/* LIB MEDIA */
Benny Prijono98793592006-12-04 08:33:20 +00002258
Benny Prijono572d4852006-11-23 21:50:02 +00002259
Fahrisdcf8fa42006-12-28 03:13:48 +00002260
2261/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002262 * PyObj_pjsua_codec_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002263 * Codec Info
2264 * !modified @ 071206
2265 */
2266typedef struct
2267{
2268 PyObject_HEAD
2269 /* Type-specific fields go here. */
2270
2271 PyObject * codec_id;
2272 pj_uint8_t priority;
2273 char buf_[32];
Benny Prijono1f63cc42007-09-10 16:54:22 +00002274} PyObj_pjsua_codec_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002275
2276
2277/*
2278 * codec_info_dealloc
2279 * deletes a codec_info from memory
2280 * !modified @ 071206
2281 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002282static void codec_info_dealloc(PyObj_pjsua_codec_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002283{
2284 Py_XDECREF(self->codec_id);
2285
2286 self->ob_type->tp_free((PyObject*)self);
2287}
2288
2289
2290/*
2291 * codec_info_new
2292 * constructor for codec_info object
2293 * !modified @ 071206
2294 */
2295static PyObject * codec_info_new(PyTypeObject *type, PyObject *args,
2296 PyObject *kwds)
2297{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002298 PyObj_pjsua_codec_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002299
Benny Prijono1f63cc42007-09-10 16:54:22 +00002300 PJ_UNUSED_ARG(args);
2301 PJ_UNUSED_ARG(kwds);
2302
2303 self = (PyObj_pjsua_codec_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002304 if (self != NULL)
2305 {
2306 self->codec_id = PyString_FromString("");
2307 if (self->codec_id == NULL)
2308 {
2309 Py_DECREF(self);
2310 return NULL;
2311 }
2312
2313
2314 }
2315 return (PyObject *)self;
2316}
2317
2318/*
2319 * codec_info_members
2320 * !modified @ 071206
2321 */
2322static PyMemberDef codec_info_members[] =
2323{
2324 {
2325 "codec_id", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002326 offsetof(PyObj_pjsua_codec_info, codec_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002327 "Codec unique identification."
2328 },
2329
2330 {
2331 "priority", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002332 offsetof(PyObj_pjsua_codec_info, priority), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002333 "Codec priority (integer 0-255)."
2334 },
2335
2336
2337
2338 {NULL} /* Sentinel */
2339};
2340
2341
2342
2343
2344/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002345 * PyTyp_pjsua_codec_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002346 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002347static PyTypeObject PyTyp_pjsua_codec_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002348{
2349 PyObject_HEAD_INIT(NULL)
2350 0, /*ob_size*/
2351 "py_pjsua.Codec_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002352 sizeof(PyObj_pjsua_codec_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002353 0, /*tp_itemsize*/
2354 (destructor)codec_info_dealloc,/*tp_dealloc*/
2355 0, /*tp_print*/
2356 0, /*tp_getattr*/
2357 0, /*tp_setattr*/
2358 0, /*tp_compare*/
2359 0, /*tp_repr*/
2360 0, /*tp_as_number*/
2361 0, /*tp_as_sequence*/
2362 0, /*tp_as_mapping*/
2363 0, /*tp_hash */
2364 0, /*tp_call*/
2365 0, /*tp_str*/
2366 0, /*tp_getattro*/
2367 0, /*tp_setattro*/
2368 0, /*tp_as_buffer*/
2369 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2370 "Codec Info objects", /* tp_doc */
2371 0, /* tp_traverse */
2372 0, /* tp_clear */
2373 0, /* tp_richcompare */
2374 0, /* tp_weaklistoffset */
2375 0, /* tp_iter */
2376 0, /* tp_iternext */
2377 0, /* tp_methods */
2378 codec_info_members, /* tp_members */
2379 0, /* tp_getset */
2380 0, /* tp_base */
2381 0, /* tp_dict */
2382 0, /* tp_descr_get */
2383 0, /* tp_descr_set */
2384 0, /* tp_dictoffset */
2385 0, /* tp_init */
2386 0, /* tp_alloc */
2387 codec_info_new, /* tp_new */
2388
2389};
2390
2391/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002392 * PyObj_pjsua_conf_port_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002393 * Conf Port Info
2394 */
2395typedef struct
2396{
2397 PyObject_HEAD
2398 /* Type-specific fields go here. */
2399
2400 int slot_id;
2401 PyObject * name;
2402 unsigned clock_rate;
2403 unsigned channel_count;
2404 unsigned samples_per_frame;
2405 unsigned bits_per_sample;
Fahrisdcf8fa42006-12-28 03:13:48 +00002406 PyListObject * listeners;
2407
Benny Prijono1f63cc42007-09-10 16:54:22 +00002408} PyObj_pjsua_conf_port_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002409
2410
2411/*
2412 * conf_port_info_dealloc
2413 * deletes a conf_port_info from memory
2414 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002415static void conf_port_info_dealloc(PyObj_pjsua_conf_port_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002416{
2417 Py_XDECREF(self->name);
2418 Py_XDECREF(self->listeners);
2419 self->ob_type->tp_free((PyObject*)self);
2420}
2421
2422
2423/*
2424 * conf_port_info_new
2425 * constructor for conf_port_info object
2426 */
2427static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
2428 PyObject *kwds)
2429{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002430 PyObj_pjsua_conf_port_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002431
Benny Prijono1f63cc42007-09-10 16:54:22 +00002432 PJ_UNUSED_ARG(args);
2433 PJ_UNUSED_ARG(kwds);
2434
2435 self = (PyObj_pjsua_conf_port_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002436 if (self != NULL)
2437 {
2438 self->name = PyString_FromString("");
2439 if (self->name == NULL)
2440 {
2441 Py_DECREF(self);
2442 return NULL;
2443 }
2444
Benny Prijonod7ea6052007-09-17 15:44:47 +00002445 self->listeners = (PyListObject *)PyList_New(0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002446 if (self->listeners == NULL)
2447 {
2448 Py_DECREF(self);
2449 return NULL;
2450 }
2451 }
2452 return (PyObject *)self;
2453}
2454
2455/*
2456 * conf_port_info_members
2457 */
2458static PyMemberDef conf_port_info_members[] =
2459{
2460 {
2461 "slot_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002462 offsetof(PyObj_pjsua_conf_port_info, slot_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002463 "Conference port number."
2464 },
2465 {
2466 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002467 offsetof(PyObj_pjsua_conf_port_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002468 "Port name"
2469 },
2470 {
2471 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002472 offsetof(PyObj_pjsua_conf_port_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002473 "Clock rate"
2474 },
2475 {
2476 "channel_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002477 offsetof(PyObj_pjsua_conf_port_info, channel_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002478 "Number of channels."
2479 },
2480 {
2481 "samples_per_frame", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002482 offsetof(PyObj_pjsua_conf_port_info, samples_per_frame), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002483 "Samples per frame "
2484 },
2485 {
2486 "bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002487 offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002488 "Bits per sample"
2489 },
Fahris89ea3d02007-02-07 08:18:35 +00002490 {
Fahrisdcf8fa42006-12-28 03:13:48 +00002491 "listeners", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002492 offsetof(PyObj_pjsua_conf_port_info, listeners), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002493 "Array of listeners (in other words, ports where this port "
2494 "is transmitting to"
2495 },
2496
2497 {NULL} /* Sentinel */
2498};
2499
2500
2501
2502
2503/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002504 * PyTyp_pjsua_conf_port_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002505 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002506static PyTypeObject PyTyp_pjsua_conf_port_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002507{
2508 PyObject_HEAD_INIT(NULL)
2509 0, /*ob_size*/
2510 "py_pjsua.Conf_Port_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002511 sizeof(PyObj_pjsua_conf_port_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002512 0, /*tp_itemsize*/
2513 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
2514 0, /*tp_print*/
2515 0, /*tp_getattr*/
2516 0, /*tp_setattr*/
2517 0, /*tp_compare*/
2518 0, /*tp_repr*/
2519 0, /*tp_as_number*/
2520 0, /*tp_as_sequence*/
2521 0, /*tp_as_mapping*/
2522 0, /*tp_hash */
2523 0, /*tp_call*/
2524 0, /*tp_str*/
2525 0, /*tp_getattro*/
2526 0, /*tp_setattro*/
2527 0, /*tp_as_buffer*/
2528 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2529 "Conf Port Info objects", /* tp_doc */
2530 0, /* tp_traverse */
2531 0, /* tp_clear */
2532 0, /* tp_richcompare */
2533 0, /* tp_weaklistoffset */
2534 0, /* tp_iter */
2535 0, /* tp_iternext */
2536 0, /* tp_methods */
2537 conf_port_info_members, /* tp_members */
2538 0, /* tp_getset */
2539 0, /* tp_base */
2540 0, /* tp_dict */
2541 0, /* tp_descr_get */
2542 0, /* tp_descr_set */
2543 0, /* tp_dictoffset */
2544 0, /* tp_init */
2545 0, /* tp_alloc */
2546 conf_port_info_new, /* tp_new */
2547
2548};
2549
2550/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002551 * PyObj_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002552 */
2553typedef struct
2554{
2555 PyObject_HEAD
2556 /* Type-specific fields go here. */
2557 pjmedia_port * port;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002558} PyObj_pjmedia_port;
Fahrisdcf8fa42006-12-28 03:13:48 +00002559
2560
2561/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002562 * PyTyp_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002563 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002564static PyTypeObject PyTyp_pjmedia_port =
Fahrisdcf8fa42006-12-28 03:13:48 +00002565{
2566 PyObject_HEAD_INIT(NULL)
2567 0, /*ob_size*/
2568 "py_pjsua.PJMedia_Port", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002569 sizeof(PyObj_pjmedia_port), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002570 0, /*tp_itemsize*/
2571 0, /*tp_dealloc*/
2572 0, /*tp_print*/
2573 0, /*tp_getattr*/
2574 0, /*tp_setattr*/
2575 0, /*tp_compare*/
2576 0, /*tp_repr*/
2577 0, /*tp_as_number*/
2578 0, /*tp_as_sequence*/
2579 0, /*tp_as_mapping*/
2580 0, /*tp_hash */
2581 0, /*tp_call*/
2582 0, /*tp_str*/
2583 0, /*tp_getattro*/
2584 0, /*tp_setattro*/
2585 0, /*tp_as_buffer*/
2586 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2587 "pjmedia_port objects", /* tp_doc */
2588
2589};
2590
2591/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002592 * PyObj_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002593 * PJMedia Snd Dev Info
2594 */
2595typedef struct
2596{
2597 PyObject_HEAD
2598 /* Type-specific fields go here. */
2599
2600
2601 unsigned input_count;
2602 unsigned output_count;
2603 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00002604 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00002605
Benny Prijono1f63cc42007-09-10 16:54:22 +00002606} PyObj_pjmedia_snd_dev_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002607
2608
2609/*
2610 * pjmedia_snd_dev_info_dealloc
2611 * deletes a pjmedia_snd_dev_info from memory
2612 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002613static void pjmedia_snd_dev_info_dealloc(PyObj_pjmedia_snd_dev_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002614{
2615 Py_XDECREF(self->name);
2616 self->ob_type->tp_free((PyObject*)self);
2617}
2618
2619
2620/*
2621 * pjmedia_snd_dev_info_new
2622 * constructor for pjmedia_snd_dev_info object
2623 */
2624static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
2625 PyObject *kwds)
2626{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002627 PyObj_pjmedia_snd_dev_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002628
Benny Prijono1f63cc42007-09-10 16:54:22 +00002629 PJ_UNUSED_ARG(args);
2630 PJ_UNUSED_ARG(kwds);
2631
2632 self = (PyObj_pjmedia_snd_dev_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002633 if (self != NULL)
2634 {
Fahrise314b882007-02-02 10:52:04 +00002635 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00002636 if (self->name == NULL)
2637 {
2638 Py_DECREF(self);
2639 return NULL;
2640 }
2641
2642 }
2643 return (PyObject *)self;
2644}
2645
2646/*
2647 * pjmedia_snd_dev_info_members
2648 */
2649static PyMemberDef pjmedia_snd_dev_info_members[] =
2650{
2651
2652 {
2653 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002654 offsetof(PyObj_pjmedia_snd_dev_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002655 "Device name"
2656 },
2657 {
2658 "input_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002659 offsetof(PyObj_pjmedia_snd_dev_info, input_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002660 "Max number of input channels"
2661 },
2662 {
2663 "output_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002664 offsetof(PyObj_pjmedia_snd_dev_info, output_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002665 "Max number of output channels"
2666 },
2667 {
2668 "default_samples_per_sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002669 offsetof(PyObj_pjmedia_snd_dev_info, default_samples_per_sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002670 "Default sampling rate."
2671 },
2672
2673
2674 {NULL} /* Sentinel */
2675};
2676
2677
2678
2679
2680/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002681 * PyTyp_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002682 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002683static PyTypeObject PyTyp_pjmedia_snd_dev_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002684{
2685 PyObject_HEAD_INIT(NULL)
2686 0, /*ob_size*/
2687 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002688 sizeof(PyObj_pjmedia_snd_dev_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002689 0, /*tp_itemsize*/
2690 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
2691 0, /*tp_print*/
2692 0, /*tp_getattr*/
2693 0, /*tp_setattr*/
2694 0, /*tp_compare*/
2695 0, /*tp_repr*/
2696 0, /*tp_as_number*/
2697 0, /*tp_as_sequence*/
2698 0, /*tp_as_mapping*/
2699 0, /*tp_hash */
2700 0, /*tp_call*/
2701 0, /*tp_str*/
2702 0, /*tp_getattro*/
2703 0, /*tp_setattro*/
2704 0, /*tp_as_buffer*/
2705 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2706 "PJMedia Snd Dev Info objects", /* tp_doc */
2707 0, /* tp_traverse */
2708 0, /* tp_clear */
2709 0, /* tp_richcompare */
2710 0, /* tp_weaklistoffset */
2711 0, /* tp_iter */
2712 0, /* tp_iternext */
2713 0, /* tp_methods */
2714 pjmedia_snd_dev_info_members, /* tp_members */
2715 0, /* tp_getset */
2716 0, /* tp_base */
2717 0, /* tp_dict */
2718 0, /* tp_descr_get */
2719 0, /* tp_descr_set */
2720 0, /* tp_dictoffset */
2721 0, /* tp_init */
2722 0, /* tp_alloc */
2723 pjmedia_snd_dev_info_new, /* tp_new */
2724
2725};
2726
2727/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002728 * PyObj_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002729 * PJMedia Codec Param Info
2730 */
2731typedef struct
2732{
2733 PyObject_HEAD
2734 /* Type-specific fields go here. */
2735
2736 unsigned clock_rate;
2737 unsigned channel_cnt;
2738 pj_uint32_t avg_bps;
2739 pj_uint16_t frm_ptime;
2740 pj_uint8_t pcm_bits_per_sample;
2741 pj_uint8_t pt;
2742
Benny Prijono1f63cc42007-09-10 16:54:22 +00002743} PyObj_pjmedia_codec_param_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002744
2745
2746
2747/*
2748 * pjmedia_codec_param_info_members
2749 */
2750static PyMemberDef pjmedia_codec_param_info_members[] =
2751{
2752
2753 {
2754 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002755 offsetof(PyObj_pjmedia_codec_param_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002756 "Sampling rate in Hz"
2757 },
2758 {
2759 "channel_cnt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002760 offsetof(PyObj_pjmedia_codec_param_info, channel_cnt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002761 "Channel count"
2762 },
2763 {
2764 "avg_bps", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002765 offsetof(PyObj_pjmedia_codec_param_info, avg_bps), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002766 "Average bandwidth in bits/sec"
2767 },
2768 {
2769 "frm_ptime", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002770 offsetof(PyObj_pjmedia_codec_param_info, frm_ptime), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002771 "Base frame ptime in msec."
2772 },
2773 {
2774 "pcm_bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002775 offsetof(PyObj_pjmedia_codec_param_info, pcm_bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002776 "Bits/sample in the PCM side"
2777 },
2778 {
2779 "pt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002780 offsetof(PyObj_pjmedia_codec_param_info, pt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002781 "Payload type"
2782 },
2783
2784 {NULL} /* Sentinel */
2785};
2786
2787
2788
2789
2790/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002791 * PyTyp_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002792 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002793static PyTypeObject PyTyp_pjmedia_codec_param_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002794{
2795 PyObject_HEAD_INIT(NULL)
2796 0, /*ob_size*/
2797 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002798 sizeof(PyObj_pjmedia_codec_param_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002799 0, /*tp_itemsize*/
2800 0,/*tp_dealloc*/
2801 0, /*tp_print*/
2802 0, /*tp_getattr*/
2803 0, /*tp_setattr*/
2804 0, /*tp_compare*/
2805 0, /*tp_repr*/
2806 0, /*tp_as_number*/
2807 0, /*tp_as_sequence*/
2808 0, /*tp_as_mapping*/
2809 0, /*tp_hash */
2810 0, /*tp_call*/
2811 0, /*tp_str*/
2812 0, /*tp_getattro*/
2813 0, /*tp_setattro*/
2814 0, /*tp_as_buffer*/
2815 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2816 "PJMedia Codec Param Info objects", /* tp_doc */
2817 0, /* tp_traverse */
2818 0, /* tp_clear */
2819 0, /* tp_richcompare */
2820 0, /* tp_weaklistoffset */
2821 0, /* tp_iter */
2822 0, /* tp_iternext */
2823 0, /* tp_methods */
2824 pjmedia_codec_param_info_members, /* tp_members */
2825
2826
2827};
2828
2829/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002830 * PyObj_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002831 * PJMedia Codec Param Setting
2832 */
2833typedef struct
2834{
2835 PyObject_HEAD
2836 /* Type-specific fields go here. */
2837 pj_uint8_t frm_per_pkt;
2838 unsigned vad;
2839 unsigned cng;
2840 unsigned penh;
2841 unsigned plc;
2842 unsigned reserved;
2843 pj_uint8_t enc_fmtp_mode;
2844 pj_uint8_t dec_fmtp_mode;
2845
Benny Prijono1f63cc42007-09-10 16:54:22 +00002846} PyObj_pjmedia_codec_param_setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002847
2848
2849
2850/*
2851 * pjmedia_codec_param_setting_members
2852 */
2853static PyMemberDef pjmedia_codec_param_setting_members[] =
2854{
2855
2856 {
2857 "frm_per_pkt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002858 offsetof(PyObj_pjmedia_codec_param_setting, frm_per_pkt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002859 "Number of frames per packet"
2860 },
2861 {
2862 "vad", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002863 offsetof(PyObj_pjmedia_codec_param_setting, vad), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002864 "Voice Activity Detector"
2865 },
2866 {
2867 "penh", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002868 offsetof(PyObj_pjmedia_codec_param_setting, penh), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002869 "Perceptual Enhancement"
2870 },
2871 {
2872 "plc", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002873 offsetof(PyObj_pjmedia_codec_param_setting, plc), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002874 "Packet loss concealment"
2875 },
2876 {
2877 "reserved", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002878 offsetof(PyObj_pjmedia_codec_param_setting, reserved), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002879 "Reserved, must be zero"
2880 },
2881 {
2882 "cng", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002883 offsetof(PyObj_pjmedia_codec_param_setting, cng), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002884 "Comfort Noise Generator"
2885 },
2886 {
2887 "enc_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002888 offsetof(PyObj_pjmedia_codec_param_setting, enc_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002889 "Mode param in fmtp (def:0)"
2890 },
2891 {
2892 "dec_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002893 offsetof(PyObj_pjmedia_codec_param_setting, dec_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002894 "Mode param in fmtp (def:0)"
2895 },
2896
2897 {NULL} /* Sentinel */
2898};
2899
2900
2901
2902
2903/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002904 * PyTyp_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002905 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002906static PyTypeObject PyTyp_pjmedia_codec_param_setting =
Fahrisdcf8fa42006-12-28 03:13:48 +00002907{
2908 PyObject_HEAD_INIT(NULL)
2909 0, /*ob_size*/
2910 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002911 sizeof(PyObj_pjmedia_codec_param_setting), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002912 0, /*tp_itemsize*/
2913 0,/*tp_dealloc*/
2914 0, /*tp_print*/
2915 0, /*tp_getattr*/
2916 0, /*tp_setattr*/
2917 0, /*tp_compare*/
2918 0, /*tp_repr*/
2919 0, /*tp_as_number*/
2920 0, /*tp_as_sequence*/
2921 0, /*tp_as_mapping*/
2922 0, /*tp_hash */
2923 0, /*tp_call*/
2924 0, /*tp_str*/
2925 0, /*tp_getattro*/
2926 0, /*tp_setattro*/
2927 0, /*tp_as_buffer*/
2928 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2929 "PJMedia Codec Param Setting objects", /* tp_doc */
2930 0, /* tp_traverse */
2931 0, /* tp_clear */
2932 0, /* tp_richcompare */
2933 0, /* tp_weaklistoffset */
2934 0, /* tp_iter */
2935 0, /* tp_iternext */
2936 0, /* tp_methods */
2937 pjmedia_codec_param_setting_members, /* tp_members */
2938
2939
2940};
2941
2942/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002943 * PyObj_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00002944 * PJMedia Codec Param
2945 */
2946typedef struct
2947{
2948 PyObject_HEAD
2949 /* Type-specific fields go here. */
2950
Benny Prijono1f63cc42007-09-10 16:54:22 +00002951 PyObj_pjmedia_codec_param_info * info;
2952 PyObj_pjmedia_codec_param_setting * setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002953
Benny Prijono1f63cc42007-09-10 16:54:22 +00002954} PyObj_pjmedia_codec_param;
Fahrisdcf8fa42006-12-28 03:13:48 +00002955
2956
2957/*
2958 * pjmedia_codec_param_dealloc
2959 * deletes a pjmedia_codec_param from memory
2960 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002961static void pjmedia_codec_param_dealloc(PyObj_pjmedia_codec_param* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002962{
2963 Py_XDECREF(self->info);
2964 Py_XDECREF(self->setting);
2965 self->ob_type->tp_free((PyObject*)self);
2966}
2967
2968
2969/*
2970 * pjmedia_codec_param_new
2971 * constructor for pjmedia_codec_param object
2972 */
2973static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
2974 PyObject *kwds)
2975{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002976 PyObj_pjmedia_codec_param *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002977
Benny Prijono1f63cc42007-09-10 16:54:22 +00002978 PJ_UNUSED_ARG(args);
2979 PJ_UNUSED_ARG(kwds);
2980
2981 self = (PyObj_pjmedia_codec_param *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002982 if (self != NULL)
2983 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00002984 self->info = (PyObj_pjmedia_codec_param_info *)
2985 PyType_GenericNew(&PyTyp_pjmedia_codec_param_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002986 if (self->info == NULL)
2987 {
2988 Py_DECREF(self);
2989 return NULL;
2990 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002991 self->setting = (PyObj_pjmedia_codec_param_setting *)
2992 PyType_GenericNew(&PyTyp_pjmedia_codec_param_setting, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002993 if (self->setting == NULL)
2994 {
2995 Py_DECREF(self);
2996 return NULL;
2997 }
2998 }
2999 return (PyObject *)self;
3000}
3001
3002/*
3003 * pjmedia_codec_param_members
3004 */
3005static PyMemberDef pjmedia_codec_param_members[] =
3006{
3007
3008 {
3009 "info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003010 offsetof(PyObj_pjmedia_codec_param, info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003011 "The 'info' part of codec param describes the capability of the codec,"
3012 " and the value should NOT be changed by application."
3013 },
3014 {
3015 "setting", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003016 offsetof(PyObj_pjmedia_codec_param, setting), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003017 "The 'setting' part of codec param describes various settings to be "
3018 "applied to the codec. When the codec param is retrieved from the "
3019 "codec or codec factory, the values of these will be filled by "
3020 "the capability of the codec. Any features that are supported by "
3021 "the codec (e.g. vad or plc) will be turned on, so that application "
3022 "can query which capabilities are supported by the codec. "
3023 "Application may change the settings here before instantiating "
3024 "the codec/stream."
3025 },
3026
3027 {NULL} /* Sentinel */
3028};
3029
3030
3031
3032
3033/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003034 * PyTyp_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00003035 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003036static PyTypeObject PyTyp_pjmedia_codec_param =
Fahrisdcf8fa42006-12-28 03:13:48 +00003037{
3038 PyObject_HEAD_INIT(NULL)
3039 0, /*ob_size*/
3040 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003041 sizeof(PyObj_pjmedia_codec_param), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003042 0, /*tp_itemsize*/
3043 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
3044 0, /*tp_print*/
3045 0, /*tp_getattr*/
3046 0, /*tp_setattr*/
3047 0, /*tp_compare*/
3048 0, /*tp_repr*/
3049 0, /*tp_as_number*/
3050 0, /*tp_as_sequence*/
3051 0, /*tp_as_mapping*/
3052 0, /*tp_hash */
3053 0, /*tp_call*/
3054 0, /*tp_str*/
3055 0, /*tp_getattro*/
3056 0, /*tp_setattro*/
3057 0, /*tp_as_buffer*/
3058 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3059 "PJMedia Codec Param objects", /* tp_doc */
3060 0, /* tp_traverse */
3061 0, /* tp_clear */
3062 0, /* tp_richcompare */
3063 0, /* tp_weaklistoffset */
3064 0, /* tp_iter */
3065 0, /* tp_iternext */
3066 0, /* tp_methods */
3067 pjmedia_codec_param_members, /* tp_members */
3068 0, /* tp_getset */
3069 0, /* tp_base */
3070 0, /* tp_dict */
3071 0, /* tp_descr_get */
3072 0, /* tp_descr_set */
3073 0, /* tp_dictoffset */
3074 0, /* tp_init */
3075 0, /* tp_alloc */
3076 pjmedia_codec_param_new, /* tp_new */
3077
3078};
3079
3080/*
3081 * py_pjsua_conf_get_max_ports
3082 */
3083static PyObject *py_pjsua_conf_get_max_ports
3084(PyObject *pSelf, PyObject *pArgs)
3085{
3086 int ret;
3087
Benny Prijono1f63cc42007-09-10 16:54:22 +00003088 PJ_UNUSED_ARG(pSelf);
3089
Fahrisdcf8fa42006-12-28 03:13:48 +00003090 if (!PyArg_ParseTuple(pArgs, ""))
3091 {
3092 return NULL;
3093 }
3094 ret = pjsua_conf_get_max_ports();
3095
3096 return Py_BuildValue("i", ret);
3097}
3098
3099/*
3100 * py_pjsua_conf_get_active_ports
3101 */
3102static PyObject *py_pjsua_conf_get_active_ports
3103(PyObject *pSelf, PyObject *pArgs)
3104{
3105 int ret;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003106
3107 PJ_UNUSED_ARG(pSelf);
3108
Fahrisdcf8fa42006-12-28 03:13:48 +00003109 if (!PyArg_ParseTuple(pArgs, ""))
3110 {
3111 return NULL;
3112 }
3113 ret = pjsua_conf_get_active_ports();
3114
3115 return Py_BuildValue("i", ret);
3116}
3117
3118/*
3119 * py_pjsua_enum_conf_ports
3120 * !modified @ 241206
3121 */
3122static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
3123{
3124 pj_status_t status;
3125 PyObject *list;
3126
3127 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00003128 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003129
3130 PJ_UNUSED_ARG(pSelf);
3131
Fahrisdcf8fa42006-12-28 03:13:48 +00003132 if (!PyArg_ParseTuple(pArgs, ""))
3133 {
3134 return NULL;
3135 }
3136
3137 c = PJ_ARRAY_SIZE(id);
3138 status = pjsua_enum_conf_ports(id, &c);
3139
3140 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003141 for (i = 0; i < c; i++)
3142 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003143 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00003144 if (ret == -1)
3145 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003146 return NULL;
3147 }
3148 }
3149
Fahrisdcf8fa42006-12-28 03:13:48 +00003150 return Py_BuildValue("O",list);
3151}
3152
3153/*
3154 * py_pjsua_conf_get_port_info
3155 */
3156static PyObject *py_pjsua_conf_get_port_info
3157(PyObject *pSelf, PyObject *pArgs)
3158{
3159 int id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003160 PyObj_pjsua_conf_port_info * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003161 pjsua_conf_port_info info;
3162 int status;
Benny Prijonod7ea6052007-09-17 15:44:47 +00003163 unsigned i;
Fahrisdcf8fa42006-12-28 03:13:48 +00003164
Benny Prijono1f63cc42007-09-10 16:54:22 +00003165 PJ_UNUSED_ARG(pSelf);
3166
Fahrisdcf8fa42006-12-28 03:13:48 +00003167 if (!PyArg_ParseTuple(pArgs, "i", &id))
3168 {
3169 return NULL;
3170 }
3171
3172
3173 status = pjsua_conf_get_port_info(id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003174 obj = (PyObj_pjsua_conf_port_info *)conf_port_info_new
3175 (&PyTyp_pjsua_conf_port_info,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003176 obj->bits_per_sample = info.bits_per_sample;
3177 obj->channel_count = info.bits_per_sample;
3178 obj->clock_rate = info.clock_rate;
Fahrisdcf8fa42006-12-28 03:13:48 +00003179 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
3180 obj->samples_per_frame = info.samples_per_frame;
3181 obj->slot_id = info.slot_id;
3182
Benny Prijonod7ea6052007-09-17 15:44:47 +00003183 obj->listeners = (PyListObject *)PyList_New(info.listener_cnt);
3184 for (i = 0; i < info.listener_cnt; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00003185 PyObject * item = Py_BuildValue("i",info.listeners[i]);
3186 PyList_SetItem((PyObject *)obj->listeners, i, item);
3187 }
3188 return Py_BuildValue("O", obj);
3189}
3190
3191/*
3192 * py_pjsua_conf_add_port
3193 */
3194static PyObject *py_pjsua_conf_add_port
3195(PyObject *pSelf, PyObject *pArgs)
3196{
3197 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00003198 PyObject * oportObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003199 PyObj_pjmedia_port * oport;
Fahris6f35cb82007-02-01 07:41:26 +00003200 pjmedia_port * port;
3201 PyObject * opoolObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003202 PyObj_pj_pool * opool;
Fahris6f35cb82007-02-01 07:41:26 +00003203 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00003204
3205 int status;
3206
Benny Prijono1f63cc42007-09-10 16:54:22 +00003207 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003208
Fahris17d91812007-01-29 12:09:33 +00003209 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003210 {
3211 return NULL;
3212 }
Fahris17d91812007-01-29 12:09:33 +00003213 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003214 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003215 opool = (PyObj_pj_pool *)opoolObj;
Fahris17d91812007-01-29 12:09:33 +00003216 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00003217 } else {
3218 opool = NULL;
3219 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00003220 }
3221 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003222 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003223 oport = (PyObj_pjmedia_port *)oportObj;
Fahris17d91812007-01-29 12:09:33 +00003224 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00003225 } else {
Fahris17d91812007-01-29 12:09:33 +00003226 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00003227 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00003228 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003229
Fahris17d91812007-01-29 12:09:33 +00003230 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00003231
3232
3233 return Py_BuildValue("ii", status, p_id);
3234}
3235
3236/*
3237 * py_pjsua_conf_remove_port
3238 */
3239static PyObject *py_pjsua_conf_remove_port
3240(PyObject *pSelf, PyObject *pArgs)
3241{
3242 int id;
3243 int status;
3244
Benny Prijono1f63cc42007-09-10 16:54:22 +00003245 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003246
3247 if (!PyArg_ParseTuple(pArgs, "i", &id))
3248 {
3249 return NULL;
3250 }
3251
3252 status = pjsua_conf_remove_port(id);
3253
3254
3255 return Py_BuildValue("i", status);
3256}
3257
3258/*
3259 * py_pjsua_conf_connect
3260 */
3261static PyObject *py_pjsua_conf_connect
3262(PyObject *pSelf, PyObject *pArgs)
3263{
3264 int source, sink;
3265 int status;
3266
Benny Prijono1f63cc42007-09-10 16:54:22 +00003267 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003268
3269 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3270 {
3271 return NULL;
3272 }
3273
3274 status = pjsua_conf_connect(source, sink);
3275
3276
3277 return Py_BuildValue("i", status);
3278}
3279
3280/*
3281 * py_pjsua_conf_disconnect
3282 */
3283static PyObject *py_pjsua_conf_disconnect
3284(PyObject *pSelf, PyObject *pArgs)
3285{
3286 int source, sink;
3287 int status;
3288
Benny Prijono1f63cc42007-09-10 16:54:22 +00003289 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003290
3291 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3292 {
3293 return NULL;
3294 }
3295
3296 status = pjsua_conf_disconnect(source, sink);
3297
3298
3299 return Py_BuildValue("i", status);
3300}
3301
3302/*
3303 * py_pjsua_player_create
3304 */
3305static PyObject *py_pjsua_player_create
3306(PyObject *pSelf, PyObject *pArgs)
3307{
3308 int id;
3309 int options;
3310 PyObject * filename;
3311 pj_str_t str;
3312 int status;
3313
Benny Prijono1f63cc42007-09-10 16:54:22 +00003314 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003315
3316 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
3317 {
3318 return NULL;
3319 }
3320 str.ptr = PyString_AsString(filename);
3321 str.slen = strlen(PyString_AsString(filename));
3322 status = pjsua_player_create(&str, options, &id);
3323
3324 return Py_BuildValue("ii", status, id);
3325}
3326
3327/*
3328 * py_pjsua_player_get_conf_port
3329 */
3330static PyObject *py_pjsua_player_get_conf_port
3331(PyObject *pSelf, PyObject *pArgs)
3332{
3333
3334 int id, port_id;
3335
Benny Prijono1f63cc42007-09-10 16:54:22 +00003336 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003337
3338 if (!PyArg_ParseTuple(pArgs, "i", &id))
3339 {
3340 return NULL;
3341 }
3342
3343 port_id = pjsua_player_get_conf_port(id);
3344
3345
3346 return Py_BuildValue("i", port_id);
3347}
3348
3349/*
3350 * py_pjsua_player_set_pos
3351 */
3352static PyObject *py_pjsua_player_set_pos
3353(PyObject *pSelf, PyObject *pArgs)
3354{
3355 int id;
3356 pj_uint32_t samples;
3357 int status;
3358
Benny Prijono1f63cc42007-09-10 16:54:22 +00003359 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003360
3361 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
3362 {
3363 return NULL;
3364 }
3365
3366 status = pjsua_player_set_pos(id, samples);
3367
3368
3369 return Py_BuildValue("i", status);
3370}
3371
3372/*
3373 * py_pjsua_player_destroy
3374 */
3375static PyObject *py_pjsua_player_destroy
3376(PyObject *pSelf, PyObject *pArgs)
3377{
3378 int id;
3379 int status;
3380
Benny Prijono1f63cc42007-09-10 16:54:22 +00003381 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003382
3383 if (!PyArg_ParseTuple(pArgs, "i", &id))
3384 {
3385 return NULL;
3386 }
3387
3388 status = pjsua_player_destroy(id);
3389
3390
3391 return Py_BuildValue("i", status);
3392}
3393
3394/*
3395 * py_pjsua_recorder_create
3396 * !modified @ 261206
3397 */
3398static PyObject *py_pjsua_recorder_create
3399(PyObject *pSelf, PyObject *pArgs)
3400{
3401 int p_id;
3402 int options;
3403 int max_size;
3404 PyObject * filename;
3405 pj_str_t str;
3406 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00003407 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00003408 int enc_type;
3409
3410 int status;
3411
Benny Prijono1f63cc42007-09-10 16:54:22 +00003412 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003413
Fahris17d91812007-01-29 12:09:33 +00003414 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
3415 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00003416 {
3417 return NULL;
3418 }
3419 str.ptr = PyString_AsString(filename);
3420 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00003421 if (enc_param != Py_None)
3422 {
3423 strparam.ptr = PyString_AsString(enc_param);
3424 strparam.slen = strlen(PyString_AsString(enc_param));
3425 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00003426 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00003427 } else {
3428 status = pjsua_recorder_create
3429 (&str, enc_type, NULL, max_size, options, &p_id);
3430 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003431 return Py_BuildValue("ii", status, p_id);
3432}
3433
3434/*
3435 * py_pjsua_recorder_get_conf_port
3436 */
3437static PyObject *py_pjsua_recorder_get_conf_port
3438(PyObject *pSelf, PyObject *pArgs)
3439{
3440
3441 int id, port_id;
3442
Benny Prijono1f63cc42007-09-10 16:54:22 +00003443 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003444
3445 if (!PyArg_ParseTuple(pArgs, "i", &id))
3446 {
3447 return NULL;
3448 }
3449
3450 port_id = pjsua_recorder_get_conf_port(id);
3451
3452
3453 return Py_BuildValue("i", port_id);
3454}
3455
3456/*
3457 * py_pjsua_recorder_destroy
3458 */
3459static PyObject *py_pjsua_recorder_destroy
3460(PyObject *pSelf, PyObject *pArgs)
3461{
3462 int id;
3463 int status;
3464
Benny Prijono1f63cc42007-09-10 16:54:22 +00003465 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003466
3467 if (!PyArg_ParseTuple(pArgs, "i", &id))
3468 {
3469 return NULL;
3470 }
3471
3472 status = pjsua_recorder_destroy(id);
3473
3474
3475 return Py_BuildValue("i", status);
3476}
3477
3478/*
3479 * py_pjsua_enum_snd_devs
3480 */
3481static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
3482{
3483 pj_status_t status;
3484 PyObject *list;
3485
Fahris6f35cb82007-02-01 07:41:26 +00003486 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00003487 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003488
3489 PJ_UNUSED_ARG(pSelf);
3490
Fahrisb721aa32007-01-29 05:07:41 +00003491 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00003492 {
3493 return NULL;
3494 }
3495
Fahrisb721aa32007-01-29 05:07:41 +00003496 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00003497 status = pjsua_enum_snd_devs(info, &c);
3498
3499 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003500 for (i = 0; i < c; i++)
3501 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003502 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00003503 int j;
Fahrise314b882007-02-02 10:52:04 +00003504 char * str;
3505
Benny Prijono1f63cc42007-09-10 16:54:22 +00003506 PyObj_pjmedia_snd_dev_info * obj;
3507 obj = (PyObj_pjmedia_snd_dev_info *)pjmedia_snd_dev_info_new
3508 (&PyTyp_pjmedia_snd_dev_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003509 obj->default_samples_per_sec = info[i].default_samples_per_sec;
3510 obj->input_count = info[i].input_count;
3511 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00003512 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
3513 memset(str, 0, SND_NAME_LEN);
3514 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00003515 {
Fahrise314b882007-02-02 10:52:04 +00003516 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00003517 }
Fahrise314b882007-02-02 10:52:04 +00003518 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
3519 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00003520 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00003521 if (ret == -1)
3522 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003523 return NULL;
3524 }
3525 }
3526
Fahrisdcf8fa42006-12-28 03:13:48 +00003527 return Py_BuildValue("O",list);
3528}
3529
3530/*
3531 * py_pjsua_get_snd_dev
3532 */
3533static PyObject *py_pjsua_get_snd_dev
3534(PyObject *pSelf, PyObject *pArgs)
3535{
3536 int capture_dev, playback_dev;
3537 int status;
3538
Benny Prijono1f63cc42007-09-10 16:54:22 +00003539 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003540
3541 if (!PyArg_ParseTuple(pArgs, ""))
3542 {
3543 return NULL;
3544 }
3545
3546 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
3547
3548
3549 return Py_BuildValue("ii", capture_dev, playback_dev);
3550}
3551
3552/*
3553 * py_pjsua_set_snd_dev
3554 */
3555static PyObject *py_pjsua_set_snd_dev
3556(PyObject *pSelf, PyObject *pArgs)
3557{
3558 int capture_dev, playback_dev;
3559 int status;
3560
Benny Prijono1f63cc42007-09-10 16:54:22 +00003561 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003562
3563 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
3564 {
3565 return NULL;
3566 }
3567
3568 status = pjsua_set_snd_dev(capture_dev, playback_dev);
3569
3570
3571 return Py_BuildValue("i", status);
3572}
3573
3574/*
3575 * py_pjsua_set_null_snd_dev
3576 */
3577static PyObject *py_pjsua_set_null_snd_dev
3578(PyObject *pSelf, PyObject *pArgs)
3579{
3580
3581 int status;
3582
Benny Prijono1f63cc42007-09-10 16:54:22 +00003583 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003584
3585 if (!PyArg_ParseTuple(pArgs, ""))
3586 {
3587 return NULL;
3588 }
3589
3590 status = pjsua_set_null_snd_dev();
3591
3592
3593 return Py_BuildValue("i", status);
3594}
3595
3596/*
3597 * py_pjsua_set_no_snd_dev
3598 */
3599static PyObject *py_pjsua_set_no_snd_dev
3600(PyObject *pSelf, PyObject *pArgs)
3601{
3602
Benny Prijono1f63cc42007-09-10 16:54:22 +00003603 PyObj_pjmedia_port * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003604
Benny Prijono1f63cc42007-09-10 16:54:22 +00003605 PJ_UNUSED_ARG(pSelf);
3606
Fahrisdcf8fa42006-12-28 03:13:48 +00003607 if (!PyArg_ParseTuple(pArgs, ""))
3608 {
3609 return NULL;
3610 }
3611
Benny Prijono1f63cc42007-09-10 16:54:22 +00003612 obj = (PyObj_pjmedia_port *)PyType_GenericNew
3613 (&PyTyp_pjmedia_port, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003614 obj->port = pjsua_set_no_snd_dev();
3615 return Py_BuildValue("O", obj);
3616}
3617
3618/*
3619 * py_pjsua_set_ec
3620 */
3621static PyObject *py_pjsua_set_ec
3622(PyObject *pSelf, PyObject *pArgs)
3623{
3624 int options;
3625 int tail_ms;
3626 int status;
3627
Benny Prijono1f63cc42007-09-10 16:54:22 +00003628 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003629
3630 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
3631 {
3632 return NULL;
3633 }
3634
3635 status = pjsua_set_ec(tail_ms, options);
3636
3637
3638 return Py_BuildValue("i", status);
3639}
3640
3641/*
3642 * py_pjsua_get_ec_tail
3643 */
3644static PyObject *py_pjsua_get_ec_tail
3645(PyObject *pSelf, PyObject *pArgs)
3646{
3647
3648 int status;
Fahris17d91812007-01-29 12:09:33 +00003649 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00003650
Benny Prijono1f63cc42007-09-10 16:54:22 +00003651 PJ_UNUSED_ARG(pSelf);
3652
Fahrisdcf8fa42006-12-28 03:13:48 +00003653 if (!PyArg_ParseTuple(pArgs, ""))
3654 {
3655 return NULL;
3656 }
3657
3658 status = pjsua_get_ec_tail(&p_tail_ms);
3659
3660
3661 return Py_BuildValue("i", p_tail_ms);
3662}
3663
3664/*
3665 * py_pjsua_enum_codecs
3666 * !modified @ 261206
3667 */
3668static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
3669{
3670 pj_status_t status;
3671 PyObject *list;
3672
3673 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00003674 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003675
3676 PJ_UNUSED_ARG(pSelf);
3677
Fahrisdcf8fa42006-12-28 03:13:48 +00003678 if (!PyArg_ParseTuple(pArgs, ""))
3679 {
3680 return NULL;
3681 }
3682
3683 c = PJ_ARRAY_SIZE(info);
3684 status = pjsua_enum_codecs(info, &c);
3685
3686 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003687 for (i = 0; i < c; i++)
3688 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003689 int ret;
3690 int j;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003691 PyObj_pjsua_codec_info * obj;
3692 obj = (PyObj_pjsua_codec_info *)codec_info_new
3693 (&PyTyp_pjsua_codec_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003694 obj->codec_id = PyString_FromStringAndSize
3695 (info[i].codec_id.ptr, info[i].codec_id.slen);
3696 obj->priority = info[i].priority;
3697 for (j = 0; j < 32; j++)
3698 {
3699 obj->buf_[j] = info[i].buf_[j];
3700 }
3701 ret = PyList_SetItem(list, i, (PyObject *)obj);
3702 if (ret == -1) {
3703 return NULL;
3704 }
3705 }
3706
Fahris17d91812007-01-29 12:09:33 +00003707
Fahrisdcf8fa42006-12-28 03:13:48 +00003708 return Py_BuildValue("O",list);
3709}
3710
3711/*
3712 * py_pjsua_codec_set_priority
3713 */
3714static PyObject *py_pjsua_codec_set_priority
3715(PyObject *pSelf, PyObject *pArgs)
3716{
3717
3718 int status;
3719 PyObject * id;
3720 pj_str_t str;
3721 pj_uint8_t priority;
3722
Benny Prijono1f63cc42007-09-10 16:54:22 +00003723 PJ_UNUSED_ARG(pSelf);
3724
Fahrisdcf8fa42006-12-28 03:13:48 +00003725 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
3726 {
3727 return NULL;
3728 }
3729 str.ptr = PyString_AsString(id);
3730 str.slen = strlen(PyString_AsString(id));
3731 status = pjsua_codec_set_priority(&str, priority);
3732
3733
3734 return Py_BuildValue("i", status);
3735}
3736
3737/*
3738 * py_pjsua_codec_get_param
3739 */
3740static PyObject *py_pjsua_codec_get_param
3741(PyObject *pSelf, PyObject *pArgs)
3742{
3743
3744 int status;
3745 PyObject * id;
3746 pj_str_t str;
3747 pjmedia_codec_param param;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003748 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003749
Benny Prijono1f63cc42007-09-10 16:54:22 +00003750 PJ_UNUSED_ARG(pSelf);
3751
Fahrisdcf8fa42006-12-28 03:13:48 +00003752 if (!PyArg_ParseTuple(pArgs, "O", &id))
3753 {
3754 return NULL;
3755 }
3756 str.ptr = PyString_AsString(id);
3757 str.slen = strlen(PyString_AsString(id));
3758 status = pjsua_codec_get_param(&str, &param);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003759 obj = (PyObj_pjmedia_codec_param *)pjmedia_codec_param_new
3760 (&PyTyp_pjmedia_codec_param, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003761 obj->info->avg_bps = param.info.avg_bps;
3762 obj->info->channel_cnt = param.info.channel_cnt;
3763 obj->info->clock_rate = param.info.clock_rate;
3764 obj->info->frm_ptime = param.info.frm_ptime;
3765 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
3766 obj->info->pt = param.info.pt;
3767 obj->setting->cng = param.setting.cng;
3768 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
3769 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
3770 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
3771 obj->setting->penh = param.setting.penh;
3772 obj->setting->plc = param.setting.plc;
3773 obj->setting->reserved = param.setting.reserved;
3774 obj->setting->vad = param.setting.vad;
3775
3776 return Py_BuildValue("O", obj);
3777}
3778/*
3779 * py_pjsua_codec_set_param
3780 */
3781static PyObject *py_pjsua_codec_set_param
3782(PyObject *pSelf, PyObject *pArgs)
3783{
3784
3785 int status;
3786 PyObject * id;
3787 pj_str_t str;
3788 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00003789 PyObject * tmpObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003790 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003791
Benny Prijono1f63cc42007-09-10 16:54:22 +00003792 PJ_UNUSED_ARG(pSelf);
3793
Fahris17d91812007-01-29 12:09:33 +00003794 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003795 {
3796 return NULL;
3797 }
Fahris17d91812007-01-29 12:09:33 +00003798
Fahrisdcf8fa42006-12-28 03:13:48 +00003799 str.ptr = PyString_AsString(id);
3800 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00003801 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003802 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003803 obj = (PyObj_pjmedia_codec_param *)tmpObj;
Fahris17d91812007-01-29 12:09:33 +00003804 param.info.avg_bps = obj->info->avg_bps;
3805 param.info.channel_cnt = obj->info->channel_cnt;
3806 param.info.clock_rate = obj->info->clock_rate;
3807 param.info.frm_ptime = obj->info->frm_ptime;
3808 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
3809 param.info.pt = obj->info->pt;
3810 param.setting.cng = obj->setting->cng;
3811 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
3812 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
3813 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
3814 param.setting.penh = obj->setting->penh;
3815 param.setting.plc = obj->setting->plc;
3816 param.setting.reserved = obj->setting->reserved;
3817 param.setting.vad = obj->setting->vad;
3818 status = pjsua_codec_set_param(&str, &param);
3819 } else {
3820 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00003821 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003822 return Py_BuildValue("i", status);
3823}
3824
3825static char pjsua_conf_get_max_ports_doc[] =
3826 "int py_pjsua.conf_get_max_ports () "
3827 "Get maxinum number of conference ports.";
3828static char pjsua_conf_get_active_ports_doc[] =
3829 "int py_pjsua.conf_get_active_ports () "
3830 "Get current number of active ports in the bridge.";
3831static char pjsua_enum_conf_ports_doc[] =
3832 "int[] py_pjsua.enum_conf_ports () "
3833 "Enumerate all conference ports.";
3834static char pjsua_conf_get_port_info_doc[] =
3835 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
3836 "Get information about the specified conference port";
3837static char pjsua_conf_add_port_doc[] =
3838 "int, int py_pjsua.conf_add_port "
Benny Prijono1f63cc42007-09-10 16:54:22 +00003839 "(py_pjsua.Pj_Pool pool, py_pjsua.PJMedia_Port port) "
Fahrisdcf8fa42006-12-28 03:13:48 +00003840 "Add arbitrary media port to PJSUA's conference bridge. "
3841 "Application can use this function to add the media port "
3842 "that it creates. For media ports that are created by PJSUA-LIB "
3843 "(such as calls, file player, or file recorder), PJSUA-LIB will "
3844 "automatically add the port to the bridge.";
3845static char pjsua_conf_remove_port_doc[] =
3846 "int py_pjsua.conf_remove_port (int id) "
3847 "Remove arbitrary slot from the conference bridge. "
3848 "Application should only call this function "
3849 "if it registered the port manually.";
3850static char pjsua_conf_connect_doc[] =
3851 "int py_pjsua.conf_connect (int source, int sink) "
3852 "Establish unidirectional media flow from souce to sink. "
3853 "One source may transmit to multiple destinations/sink. "
3854 "And if multiple sources are transmitting to the same sink, "
3855 "the media will be mixed together. Source and sink may refer "
3856 "to the same ID, effectively looping the media. "
3857 "If bidirectional media flow is desired, application "
3858 "needs to call this function twice, with the second "
3859 "one having the arguments reversed.";
3860static char pjsua_conf_disconnect_doc[] =
3861 "int py_pjsua.conf_disconnect (int source, int sink) "
3862 "Disconnect media flow from the source to destination port.";
3863static char pjsua_player_create_doc[] =
3864 "int, int py_pjsua.player_create (string filename, int options) "
3865 "Create a file player, and automatically connect "
3866 "this player to the conference bridge.";
3867static char pjsua_player_get_conf_port_doc[] =
3868 "int py_pjsua.player_get_conf_port (int) "
3869 "Get conference port ID associated with player.";
3870static char pjsua_player_set_pos_doc[] =
3871 "int py_pjsua.player_set_pos (int id, int samples) "
3872 "Set playback position.";
3873static char pjsua_player_destroy_doc[] =
3874 "int py_pjsua.player_destroy (int id) "
3875 "Close the file, remove the player from the bridge, "
3876 "and free resources associated with the file player.";
3877static char pjsua_recorder_create_doc[] =
3878 "int, int py_pjsua.recorder_create (string filename, "
3879 "int enc_type, int enc_param, int max_size, int options) "
3880 "Create a file recorder, and automatically connect this recorder "
3881 "to the conference bridge. The recorder currently supports recording "
3882 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
3883 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
3884static char pjsua_recorder_get_conf_port_doc[] =
3885 "int py_pjsua.recorder_get_conf_port (int id) "
3886 "Get conference port associated with recorder.";
3887static char pjsua_recorder_destroy_doc[] =
3888 "int py_pjsua.recorder_destroy (int id) "
3889 "Destroy recorder (this will complete recording).";
3890static char pjsua_enum_snd_devs_doc[] =
3891 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
3892 "Enum sound devices.";
3893static char pjsua_get_snd_dev_doc[] =
3894 "int, int py_pjsua.get_snd_dev () "
3895 "Get currently active sound devices. "
3896 "If sound devices has not been created "
3897 "(for example when pjsua_start() is not called), "
3898 "it is possible that the function returns "
3899 "PJ_SUCCESS with -1 as device IDs.";
3900static char pjsua_set_snd_dev_doc[] =
3901 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
3902 "Select or change sound device. Application may call this function "
3903 "at any time to replace current sound device.";
3904static char pjsua_set_null_snd_dev_doc[] =
3905 "int py_pjsua.set_null_snd_dev () "
3906 "Set pjsua to use null sound device. The null sound device only "
3907 "provides the timing needed by the conference bridge, and will not "
3908 "interract with any hardware.";
3909static char pjsua_set_no_snd_dev_doc[] =
3910 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
3911 "Disconnect the main conference bridge from any sound devices, "
3912 "and let application connect the bridge to it's "
3913 "own sound device/master port.";
3914static char pjsua_set_ec_doc[] =
3915 "int py_pjsua.set_ec (int tail_ms, int options) "
3916 "Configure the echo canceller tail length of the sound port.";
3917static char pjsua_get_ec_tail_doc[] =
3918 "int py_pjsua.get_ec_tail () "
3919 "Get current echo canceller tail length.";
3920static char pjsua_enum_codecs_doc[] =
3921 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
3922 "Enum all supported codecs in the system.";
3923static char pjsua_codec_set_priority_doc[] =
3924 "int py_pjsua.codec_set_priority (string id, int priority) "
3925 "Change codec priority.";
3926static char pjsua_codec_get_param_doc[] =
3927 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
3928 "Get codec parameters";
3929static char pjsua_codec_set_param_doc[] =
3930 "int py_pjsua.codec_set_param (string id, "
3931 "py_pjsua.PJMedia_Codec_Param param) "
3932 "Set codec parameters.";
3933
3934/* END OF LIB MEDIA */
3935
3936/* LIB CALL */
3937
3938/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003939 * PyObj_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003940 * PJ Time Val
3941 */
3942typedef struct
3943{
3944 PyObject_HEAD
3945 /* Type-specific fields go here. */
3946 long sec;
3947 long msec;
3948
Benny Prijono1f63cc42007-09-10 16:54:22 +00003949} PyObj_pj_time_val;
Fahrisdcf8fa42006-12-28 03:13:48 +00003950
3951
3952
3953/*
3954 * pj_time_val_members
3955 */
3956static PyMemberDef pj_time_val_members[] =
3957{
3958
3959 {
3960 "sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003961 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003962 "The seconds part of the time"
3963 },
3964 {
3965 "msec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003966 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003967 "The milliseconds fraction of the time"
3968 },
3969
3970
3971 {NULL} /* Sentinel */
3972};
3973
3974
3975
3976
3977/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003978 * PyTyp_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003979 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003980static PyTypeObject PyTyp_pj_time_val =
Fahrisdcf8fa42006-12-28 03:13:48 +00003981{
3982 PyObject_HEAD_INIT(NULL)
3983 0, /*ob_size*/
3984 "py_pjsua.PJ_Time_Val", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003985 sizeof(PyObj_pj_time_val), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003986 0, /*tp_itemsize*/
3987 0,/*tp_dealloc*/
3988 0, /*tp_print*/
3989 0, /*tp_getattr*/
3990 0, /*tp_setattr*/
3991 0, /*tp_compare*/
3992 0, /*tp_repr*/
3993 0, /*tp_as_number*/
3994 0, /*tp_as_sequence*/
3995 0, /*tp_as_mapping*/
3996 0, /*tp_hash */
3997 0, /*tp_call*/
3998 0, /*tp_str*/
3999 0, /*tp_getattro*/
4000 0, /*tp_setattro*/
4001 0, /*tp_as_buffer*/
4002 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4003 "PJ Time Val objects", /* tp_doc */
4004 0, /* tp_traverse */
4005 0, /* tp_clear */
4006 0, /* tp_richcompare */
4007 0, /* tp_weaklistoffset */
4008 0, /* tp_iter */
4009 0, /* tp_iternext */
4010 0, /* tp_methods */
4011 pj_time_val_members, /* tp_members */
4012
4013
4014};
4015
4016/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004017 * PyObj_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004018 * Call Info
4019 */
4020typedef struct
4021{
4022 PyObject_HEAD
4023 /* Type-specific fields go here. */
4024
4025 int id;
4026 int role;
4027 int acc_id;
4028 PyObject * local_info;
4029 PyObject * local_contact;
4030 PyObject * remote_info;
4031 PyObject * remote_contact;
4032 PyObject * call_id;
4033 int state;
4034 PyObject * state_text;
4035 int last_status;
4036 PyObject * last_status_text;
4037 int media_status;
4038 int media_dir;
4039 int conf_slot;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004040 PyObj_pj_time_val * connect_duration;
4041 PyObj_pj_time_val * total_duration;
Fahrisdcf8fa42006-12-28 03:13:48 +00004042 struct {
4043 char local_info[128];
4044 char local_contact[128];
4045 char remote_info[128];
4046 char remote_contact[128];
4047 char call_id[128];
4048 char last_status_text[128];
4049 } buf_;
4050
Benny Prijono1f63cc42007-09-10 16:54:22 +00004051} PyObj_pjsua_call_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004052
4053
4054/*
4055 * call_info_dealloc
4056 * deletes a call_info from memory
4057 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004058static void call_info_dealloc(PyObj_pjsua_call_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00004059{
4060 Py_XDECREF(self->local_info);
4061 Py_XDECREF(self->local_contact);
4062 Py_XDECREF(self->remote_info);
4063 Py_XDECREF(self->remote_contact);
4064 Py_XDECREF(self->call_id);
4065 Py_XDECREF(self->state_text);
4066 Py_XDECREF(self->last_status_text);
4067 Py_XDECREF(self->connect_duration);
4068 Py_XDECREF(self->total_duration);
4069 self->ob_type->tp_free((PyObject*)self);
4070}
4071
4072
4073/*
4074 * call_info_new
4075 * constructor for call_info object
4076 */
4077static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
4078 PyObject *kwds)
4079{
Benny Prijono1f63cc42007-09-10 16:54:22 +00004080 PyObj_pjsua_call_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00004081
Benny Prijono1f63cc42007-09-10 16:54:22 +00004082 PJ_UNUSED_ARG(args);
4083 PJ_UNUSED_ARG(kwds);
4084
4085 self = (PyObj_pjsua_call_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00004086 if (self != NULL)
4087 {
4088 self->local_info = PyString_FromString("");
4089 if (self->local_info == NULL)
4090 {
4091 Py_DECREF(self);
4092 return NULL;
4093 }
4094 self->local_contact = PyString_FromString("");
4095 if (self->local_contact == NULL)
4096 {
4097 Py_DECREF(self);
4098 return NULL;
4099 }
4100 self->remote_info = PyString_FromString("");
4101 if (self->remote_info == NULL)
4102 {
4103 Py_DECREF(self);
4104 return NULL;
4105 }
4106 self->remote_contact = PyString_FromString("");
4107 if (self->remote_contact == NULL)
4108 {
4109 Py_DECREF(self);
4110 return NULL;
4111 }
4112 self->call_id = PyString_FromString("");
4113 if (self->call_id == NULL)
4114 {
4115 Py_DECREF(self);
4116 return NULL;
4117 }
4118 self->state_text = PyString_FromString("");
4119 if (self->state_text == NULL)
4120 {
4121 Py_DECREF(self);
4122 return NULL;
4123 }
4124 self->last_status_text = PyString_FromString("");
4125 if (self->last_status_text == NULL)
4126 {
4127 Py_DECREF(self);
4128 return NULL;
4129 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004130 self->connect_duration = (PyObj_pj_time_val *)PyType_GenericNew
4131 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004132 if (self->connect_duration == NULL)
4133 {
4134 Py_DECREF(self);
4135 return NULL;
4136 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004137 self->total_duration = (PyObj_pj_time_val *)PyType_GenericNew
4138 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004139 if (self->total_duration == NULL)
4140 {
4141 Py_DECREF(self);
4142 return NULL;
4143 }
4144 }
4145 return (PyObject *)self;
4146}
4147
4148/*
4149 * call_info_members
4150 */
4151static PyMemberDef call_info_members[] =
4152{
4153 {
4154 "id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004155 offsetof(PyObj_pjsua_call_info, id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004156 "Call identification"
4157 },
4158 {
4159 "role", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004160 offsetof(PyObj_pjsua_call_info, role), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004161 "Initial call role (UAC == caller)"
4162 },
4163 {
4164 "acc_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004165 offsetof(PyObj_pjsua_call_info, acc_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004166 "The account ID where this call belongs."
4167 },
4168 {
4169 "local_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004170 offsetof(PyObj_pjsua_call_info, local_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004171 "Local URI"
4172 },
4173 {
4174 "local_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004175 offsetof(PyObj_pjsua_call_info, local_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004176 "Local Contact"
4177 },
4178 {
4179 "remote_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004180 offsetof(PyObj_pjsua_call_info, remote_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004181 "Remote URI"
4182 },
4183 {
4184 "remote_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004185 offsetof(PyObj_pjsua_call_info, remote_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004186 "Remote Contact"
4187 },
4188 {
4189 "call_id", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004190 offsetof(PyObj_pjsua_call_info, call_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004191 "Dialog Call-ID string"
4192 },
4193 {
4194 "state", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004195 offsetof(PyObj_pjsua_call_info, state), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004196 "Call state"
4197 },
4198 {
4199 "state_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004200 offsetof(PyObj_pjsua_call_info, state_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004201 "Text describing the state "
4202 },
4203 {
4204 "last_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004205 offsetof(PyObj_pjsua_call_info, last_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004206 "Last status code heard, which can be used as cause code"
4207 },
4208 {
4209 "last_status_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004210 offsetof(PyObj_pjsua_call_info, last_status_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004211 "The reason phrase describing the status."
4212 },
4213 {
4214 "media_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004215 offsetof(PyObj_pjsua_call_info, media_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004216 "Call media status."
4217 },
4218 {
4219 "media_dir", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004220 offsetof(PyObj_pjsua_call_info, media_dir), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004221 "Media direction"
4222 },
4223 {
4224 "conf_slot", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004225 offsetof(PyObj_pjsua_call_info, conf_slot), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004226 "The conference port number for the call"
4227 },
4228 {
4229 "connect_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004230 offsetof(PyObj_pjsua_call_info, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00004231 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00004232 },
4233 {
4234 "total_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004235 offsetof(PyObj_pjsua_call_info, total_duration), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004236 "Total call duration, including set-up time"
4237 },
4238
4239 {NULL} /* Sentinel */
4240};
4241
4242
4243
4244
4245/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004246 * PyTyp_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004247 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004248static PyTypeObject PyTyp_pjsua_call_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00004249{
4250 PyObject_HEAD_INIT(NULL)
4251 0, /*ob_size*/
4252 "py_pjsua.Call_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00004253 sizeof(PyObj_pjsua_call_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00004254 0, /*tp_itemsize*/
4255 (destructor)call_info_dealloc,/*tp_dealloc*/
4256 0, /*tp_print*/
4257 0, /*tp_getattr*/
4258 0, /*tp_setattr*/
4259 0, /*tp_compare*/
4260 0, /*tp_repr*/
4261 0, /*tp_as_number*/
4262 0, /*tp_as_sequence*/
4263 0, /*tp_as_mapping*/
4264 0, /*tp_hash */
4265 0, /*tp_call*/
4266 0, /*tp_str*/
4267 0, /*tp_getattro*/
4268 0, /*tp_setattro*/
4269 0, /*tp_as_buffer*/
4270 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4271 "Call Info objects", /* tp_doc */
4272 0, /* tp_traverse */
4273 0, /* tp_clear */
4274 0, /* tp_richcompare */
4275 0, /* tp_weaklistoffset */
4276 0, /* tp_iter */
4277 0, /* tp_iternext */
4278 0, /* tp_methods */
4279 call_info_members, /* tp_members */
4280 0, /* tp_getset */
4281 0, /* tp_base */
4282 0, /* tp_dict */
4283 0, /* tp_descr_get */
4284 0, /* tp_descr_set */
4285 0, /* tp_dictoffset */
4286 0, /* tp_init */
4287 0, /* tp_alloc */
4288 call_info_new, /* tp_new */
4289
4290};
4291
4292/*
4293 * py_pjsua_call_get_max_count
4294 */
4295static PyObject *py_pjsua_call_get_max_count
4296(PyObject *pSelf, PyObject *pArgs)
4297{
4298 int count;
4299
Benny Prijono1f63cc42007-09-10 16:54:22 +00004300 PJ_UNUSED_ARG(pSelf);
4301
Fahrisdcf8fa42006-12-28 03:13:48 +00004302 if (!PyArg_ParseTuple(pArgs, ""))
4303 {
4304 return NULL;
4305 }
4306
4307 count = pjsua_call_get_max_count();
4308
4309
4310 return Py_BuildValue("i", count);
4311}
4312
4313/*
4314 * py_pjsua_call_get_count
4315 */
4316static PyObject *py_pjsua_call_get_count
4317(PyObject *pSelf, PyObject *pArgs)
4318{
4319
4320 int count;
4321
Benny Prijono1f63cc42007-09-10 16:54:22 +00004322 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004323
4324 if (!PyArg_ParseTuple(pArgs, ""))
4325 {
4326 return NULL;
4327 }
4328
4329 count = pjsua_call_get_count();
4330
4331
4332 return Py_BuildValue("i", count);
4333}
4334
4335/*
4336 * py_pjsua_enum_calls
4337 */
4338static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
4339{
4340 pj_status_t status;
4341 PyObject *list;
4342
4343 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00004344 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004345
4346 PJ_UNUSED_ARG(pSelf);
4347
Fahrisdcf8fa42006-12-28 03:13:48 +00004348 if (!PyArg_ParseTuple(pArgs, ""))
4349 {
4350 return NULL;
4351 }
4352
4353 c = PJ_ARRAY_SIZE(id);
4354 status = pjsua_enum_calls(id, &c);
4355
4356 list = PyList_New(c);
4357 for (i = 0; i < c; i++)
4358 {
4359 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
4360 if (ret == -1)
4361 {
4362 return NULL;
4363 }
4364 }
4365
Fahrisdcf8fa42006-12-28 03:13:48 +00004366 return Py_BuildValue("O",list);
4367}
4368
4369/*
4370 * py_pjsua_call_make_call
4371 */
4372static PyObject *py_pjsua_call_make_call
4373(PyObject *pSelf, PyObject *pArgs)
4374{
4375 int status;
4376 int acc_id;
4377 pj_str_t dst_uri;
4378 PyObject * sd;
4379 unsigned options;
4380 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004381 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004382 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004383 int user_data;
4384 int call_id;
4385 pj_pool_t * pool;
4386
Benny Prijono1f63cc42007-09-10 16:54:22 +00004387 PJ_UNUSED_ARG(pSelf);
4388
Fahris17d91812007-01-29 12:09:33 +00004389 if (!PyArg_ParseTuple
4390 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004391 {
4392 return NULL;
4393 }
4394
4395 dst_uri.ptr = PyString_AsString(sd);
4396 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00004397 if (omdObj != Py_None)
4398 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004399 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004400 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4401 msg_data.content_type.slen = strlen
4402 (PyString_AsString(omd->content_type));
4403 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4404 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004405 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004406 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4407 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004408 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00004409 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004410 } else {
Fahris89ea3d02007-02-07 08:18:35 +00004411
Fahris17d91812007-01-29 12:09:33 +00004412 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004413 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004414 }
Fahris89ea3d02007-02-07 08:18:35 +00004415
Fahrisdcf8fa42006-12-28 03:13:48 +00004416 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00004417
Fahrisdcf8fa42006-12-28 03:13:48 +00004418}
4419
4420/*
4421 * py_pjsua_call_is_active
4422 */
4423static PyObject *py_pjsua_call_is_active
4424(PyObject *pSelf, PyObject *pArgs)
4425{
4426 int call_id;
4427 int isActive;
4428
Benny Prijono1f63cc42007-09-10 16:54:22 +00004429 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004430
4431 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4432 {
4433 return NULL;
4434 }
4435
4436 isActive = pjsua_call_is_active(call_id);
4437
4438
4439 return Py_BuildValue("i", isActive);
4440}
4441
4442/*
4443 * py_pjsua_call_has_media
4444 */
4445static PyObject *py_pjsua_call_has_media
4446(PyObject *pSelf, PyObject *pArgs)
4447{
4448 int call_id;
4449 int hasMedia;
4450
Benny Prijono1f63cc42007-09-10 16:54:22 +00004451 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004452
4453 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4454 {
4455 return NULL;
4456 }
4457
4458 hasMedia = pjsua_call_has_media(call_id);
4459
4460
4461 return Py_BuildValue("i", hasMedia);
4462}
4463
4464/*
4465 * py_pjsua_call_get_conf_port
4466 */
4467static PyObject *py_pjsua_call_get_conf_port
4468(PyObject *pSelf, PyObject *pArgs)
4469{
4470 int call_id;
4471 int port_id;
4472
Benny Prijono1f63cc42007-09-10 16:54:22 +00004473 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004474
4475 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4476 {
4477 return NULL;
4478 }
4479
4480 port_id = pjsua_call_get_conf_port(call_id);
4481
4482
4483 return Py_BuildValue("i", port_id);
4484}
4485
4486/*
4487 * py_pjsua_call_get_info
4488 */
4489static PyObject *py_pjsua_call_get_info
4490(PyObject *pSelf, PyObject *pArgs)
4491{
4492 int call_id;
4493 int status;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004494 PyObj_pjsua_call_info * oi;
Fahrisdcf8fa42006-12-28 03:13:48 +00004495 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004496
Benny Prijono1f63cc42007-09-10 16:54:22 +00004497 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004498
4499 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4500 {
4501 return NULL;
4502 }
4503
4504
4505 status = pjsua_call_get_info(call_id, &info);
4506 if (status == PJ_SUCCESS)
4507 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004508 oi = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004509 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004510 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
4511 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
4512 pj_ansi_snprintf(oi->buf_.last_status_text,
4513 sizeof(oi->buf_.last_status_text),
4514 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
4515 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
4516 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
4517 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
4518 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
4519 pj_ansi_snprintf(oi->buf_.remote_contact,
4520 sizeof(oi->buf_.remote_contact),
4521 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
4522 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
4523 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004524
Fahrisdcf8fa42006-12-28 03:13:48 +00004525 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
4526 info.call_id.slen);
4527 oi->conf_slot = info.conf_slot;
4528 oi->connect_duration->sec = info.connect_duration.sec;
4529 oi->connect_duration->msec = info.connect_duration.msec;
4530 oi->total_duration->sec = info.total_duration.sec;
4531 oi->total_duration->msec = info.total_duration.msec;
4532 oi->id = info.id;
4533 oi->last_status = info.last_status;
4534 oi->last_status_text = PyString_FromStringAndSize(
4535 info.last_status_text.ptr, info.last_status_text.slen);
4536 oi->local_contact = PyString_FromStringAndSize(
4537 info.local_contact.ptr, info.local_contact.slen);
4538 oi->local_info = PyString_FromStringAndSize(
4539 info.local_info.ptr, info.local_info.slen);
4540 oi->remote_contact = PyString_FromStringAndSize(
4541 info.remote_contact.ptr, info.remote_contact.slen);
4542 oi->remote_info = PyString_FromStringAndSize(
4543 info.remote_info.ptr, info.remote_info.slen);
4544 oi->media_dir = info.media_dir;
4545 oi->media_status = info.media_status;
4546 oi->role = info.role;
4547 oi->state = info.state;
4548 oi->state_text = PyString_FromStringAndSize(
4549 info.state_text.ptr, info.state_text.slen);
4550
4551 return Py_BuildValue("O", oi);
4552 } else {
4553 Py_INCREF(Py_None);
4554 return Py_None;
4555 }
4556}
4557
4558/*
4559 * py_pjsua_call_set_user_data
4560 */
4561static PyObject *py_pjsua_call_set_user_data
4562(PyObject *pSelf, PyObject *pArgs)
4563{
4564 int call_id;
4565 int user_data;
4566 int status;
4567
Benny Prijono1f63cc42007-09-10 16:54:22 +00004568 PJ_UNUSED_ARG(pSelf);
4569
Fahrisdcf8fa42006-12-28 03:13:48 +00004570 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
4571 {
4572 return NULL;
4573 }
4574
Benny Prijonoe6ead542007-01-31 20:53:31 +00004575 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004576
4577
4578 return Py_BuildValue("i", status);
4579}
4580
4581/*
4582 * py_pjsua_call_get_user_data
4583 */
4584static PyObject *py_pjsua_call_get_user_data
4585(PyObject *pSelf, PyObject *pArgs)
4586{
4587 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00004588 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00004589
Benny Prijono1f63cc42007-09-10 16:54:22 +00004590 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004591
4592 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4593 {
4594 return NULL;
4595 }
4596
4597 user_data = pjsua_call_get_user_data(call_id);
4598
4599
Benny Prijonoe6ead542007-01-31 20:53:31 +00004600 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004601}
4602
4603/*
4604 * py_pjsua_call_answer
4605 */
4606static PyObject *py_pjsua_call_answer
4607(PyObject *pSelf, PyObject *pArgs)
4608{
4609 int status;
4610 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004611 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004612 PyObject * sr;
4613 unsigned code;
4614 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004615 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004616 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004617 pj_pool_t * pool;
4618
Benny Prijono1f63cc42007-09-10 16:54:22 +00004619 PJ_UNUSED_ARG(pSelf);
4620
Fahris17d91812007-01-29 12:09:33 +00004621 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004622 {
4623 return NULL;
4624 }
Fahris6f35cb82007-02-01 07:41:26 +00004625 if (sr == Py_None)
4626 {
4627 reason = NULL;
4628 } else {
Fahrise314b882007-02-02 10:52:04 +00004629 reason = &tmp_reason;
4630 tmp_reason.ptr = PyString_AsString(sr);
4631 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004632 }
4633 if (omdObj != Py_None)
4634 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004635 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004636 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4637 msg_data.content_type.slen = strlen
4638 (PyString_AsString(omd->content_type));
4639 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4640 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004641 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004642 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4643
Fahris6f35cb82007-02-01 07:41:26 +00004644 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004645
Fahris17d91812007-01-29 12:09:33 +00004646 pj_pool_release(pool);
4647 } else {
4648
Fahris89ea3d02007-02-07 08:18:35 +00004649 status = pjsua_call_answer(call_id, code, reason, NULL);
4650
Fahris6f35cb82007-02-01 07:41:26 +00004651 }
Fahrise314b882007-02-02 10:52:04 +00004652
Fahrisdcf8fa42006-12-28 03:13:48 +00004653 return Py_BuildValue("i",status);
4654}
4655
4656/*
4657 * py_pjsua_call_hangup
4658 */
4659static PyObject *py_pjsua_call_hangup
4660(PyObject *pSelf, PyObject *pArgs)
4661{
4662 int status;
4663 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004664 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004665 PyObject * sr;
4666 unsigned code;
4667 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004668 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004669 PyObj_pjsua_msg_data * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004670 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004671
Benny Prijono1f63cc42007-09-10 16:54:22 +00004672 PJ_UNUSED_ARG(pSelf);
4673
Fahris17d91812007-01-29 12:09:33 +00004674 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004675 {
4676 return NULL;
4677 }
Benny Prijonoaa286042007-02-03 17:23:22 +00004678 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004679 {
4680 reason = NULL;
4681 } else {
Fahrise314b882007-02-02 10:52:04 +00004682 reason = &tmp_reason;
4683 tmp_reason.ptr = PyString_AsString(sr);
4684 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004685 }
4686 if (omdObj != Py_None)
4687 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004688 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004689 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4690 msg_data.content_type.slen = strlen
4691 (PyString_AsString(omd->content_type));
4692 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4693 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004694 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004695 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00004696 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00004697 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004698 } else {
Fahris6f35cb82007-02-01 07:41:26 +00004699 status = pjsua_call_hangup(call_id, code, reason, NULL);
4700 }
Fahrise314b882007-02-02 10:52:04 +00004701
Fahrisdcf8fa42006-12-28 03:13:48 +00004702 return Py_BuildValue("i",status);
4703}
4704
4705/*
4706 * py_pjsua_call_set_hold
4707 */
4708static PyObject *py_pjsua_call_set_hold
4709(PyObject *pSelf, PyObject *pArgs)
4710{
4711 int status;
4712 int call_id;
4713 pjsua_msg_data msg_data;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004714 PyObject * omdObj;
4715 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004716 pj_pool_t * pool;
4717
Benny Prijono1f63cc42007-09-10 16:54:22 +00004718 PJ_UNUSED_ARG(pSelf);
4719
Fahris17d91812007-01-29 12:09:33 +00004720 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004721 {
4722 return NULL;
4723 }
Fahris17d91812007-01-29 12:09:33 +00004724
Fahris6f35cb82007-02-01 07:41:26 +00004725 if (omdObj != Py_None)
4726 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004727 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004728 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4729 msg_data.content_type.slen = strlen
4730 (PyString_AsString(omd->content_type));
4731 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4732 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004733 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004734 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4735 status = pjsua_call_set_hold(call_id, &msg_data);
4736 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004737 } else {
Fahris17d91812007-01-29 12:09:33 +00004738 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004739 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004740 return Py_BuildValue("i",status);
4741}
4742
4743/*
4744 * py_pjsua_call_reinvite
4745 */
4746static PyObject *py_pjsua_call_reinvite
4747(PyObject *pSelf, PyObject *pArgs)
4748{
4749 int status;
4750 int call_id;
4751 int unhold;
4752 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004753 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004754 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004755 pj_pool_t * pool;
4756
Benny Prijono1f63cc42007-09-10 16:54:22 +00004757 PJ_UNUSED_ARG(pSelf);
4758
Fahris17d91812007-01-29 12:09:33 +00004759 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004760 {
4761 return NULL;
4762 }
Fahris17d91812007-01-29 12:09:33 +00004763
4764 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004765 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004766 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004767 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4768 msg_data.content_type.slen = strlen
4769 (PyString_AsString(omd->content_type));
4770 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4771 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004772 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004773 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4774 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
4775 pj_pool_release(pool);
4776 } else {
4777 status = pjsua_call_reinvite(call_id, unhold, NULL);
4778 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004779 return Py_BuildValue("i",status);
4780}
4781
4782/*
4783 * py_pjsua_call_xfer
4784 */
4785static PyObject *py_pjsua_call_xfer
4786(PyObject *pSelf, PyObject *pArgs)
4787{
4788 int status;
4789 int call_id;
4790 pj_str_t dest;
4791 PyObject * sd;
4792 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004793 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004794 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004795 pj_pool_t * pool;
4796
Benny Prijono1f63cc42007-09-10 16:54:22 +00004797 PJ_UNUSED_ARG(pSelf);
4798
Fahris17d91812007-01-29 12:09:33 +00004799 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004800 {
4801 return NULL;
4802 }
4803
4804 dest.ptr = PyString_AsString(sd);
4805 dest.slen = strlen(PyString_AsString(sd));
4806
Fahris17d91812007-01-29 12:09:33 +00004807 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004808 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004809 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004810 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4811 msg_data.content_type.slen = strlen
4812 (PyString_AsString(omd->content_type));
4813 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4814 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004815 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004816 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4817 status = pjsua_call_xfer(call_id, &dest, &msg_data);
4818 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004819 } else {
Fahris17d91812007-01-29 12:09:33 +00004820 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004821 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004822 return Py_BuildValue("i",status);
4823}
4824
4825/*
4826 * py_pjsua_call_xfer_replaces
4827 */
4828static PyObject *py_pjsua_call_xfer_replaces
4829(PyObject *pSelf, PyObject *pArgs)
4830{
4831 int status;
4832 int call_id;
4833 int dest_call_id;
4834 unsigned options;
4835 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004836 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004837 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004838 pj_pool_t * pool;
4839
Benny Prijono1f63cc42007-09-10 16:54:22 +00004840 PJ_UNUSED_ARG(pSelf);
4841
Fahris17d91812007-01-29 12:09:33 +00004842 if (!PyArg_ParseTuple
4843 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004844 {
4845 return NULL;
4846 }
4847
Fahris17d91812007-01-29 12:09:33 +00004848 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004849 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004850 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004851 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4852 msg_data.content_type.slen = strlen
4853 (PyString_AsString(omd->content_type));
4854 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4855 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004856 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004857 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4858 status = pjsua_call_xfer_replaces
4859 (call_id, dest_call_id, options, &msg_data);
4860 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004861 } else {
Fahris17d91812007-01-29 12:09:33 +00004862 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004863 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004864 return Py_BuildValue("i",status);
4865}
4866
4867/*
4868 * py_pjsua_call_dial_dtmf
4869 */
4870static PyObject *py_pjsua_call_dial_dtmf
4871(PyObject *pSelf, PyObject *pArgs)
4872{
4873 int call_id;
4874 PyObject * sd;
4875 pj_str_t digits;
4876 int status;
4877
Benny Prijono1f63cc42007-09-10 16:54:22 +00004878 PJ_UNUSED_ARG(pSelf);
4879
Fahrisdcf8fa42006-12-28 03:13:48 +00004880 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
4881 {
4882 return NULL;
4883 }
4884 digits.ptr = PyString_AsString(sd);
4885 digits.slen = strlen(PyString_AsString(sd));
4886 status = pjsua_call_dial_dtmf(call_id, &digits);
4887
4888 return Py_BuildValue("i", status);
4889}
4890
4891/*
4892 * py_pjsua_call_send_im
4893 */
4894static PyObject *py_pjsua_call_send_im
4895(PyObject *pSelf, PyObject *pArgs)
4896{
4897 int status;
4898 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00004899 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00004900 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00004901 PyObject * sm;
4902 PyObject * sc;
4903 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004904 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004905 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004906 int user_data;
4907 pj_pool_t * pool;
4908
Benny Prijono1f63cc42007-09-10 16:54:22 +00004909 PJ_UNUSED_ARG(pSelf);
4910
Fahris17d91812007-01-29 12:09:33 +00004911 if (!PyArg_ParseTuple
4912 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00004913 {
4914 return NULL;
4915 }
Fahris6f35cb82007-02-01 07:41:26 +00004916 if (sm == Py_None)
4917 {
4918 mime_type = NULL;
4919 } else {
Fahrise314b882007-02-02 10:52:04 +00004920 mime_type = &tmp_mime_type;
4921 tmp_mime_type.ptr = PyString_AsString(sm);
4922 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00004923 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004924 content.ptr = PyString_AsString(sc);
4925 content.slen = strlen(PyString_AsString(sc));
4926
Fahris17d91812007-01-29 12:09:33 +00004927 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004928 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004929 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004930 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4931 msg_data.content_type.slen = strlen
4932 (PyString_AsString(omd->content_type));
4933 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4934 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004935 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004936 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4937 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004938 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00004939 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004940 } else {
Fahris17d91812007-01-29 12:09:33 +00004941 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004942 (call_id, mime_type, &content, NULL, (void *)user_data);
4943 }
Fahrise314b882007-02-02 10:52:04 +00004944
Fahrisdcf8fa42006-12-28 03:13:48 +00004945 return Py_BuildValue("i",status);
4946}
4947
4948/*
4949 * py_pjsua_call_send_typing_ind
4950 */
4951static PyObject *py_pjsua_call_send_typing_ind
4952(PyObject *pSelf, PyObject *pArgs)
4953{
4954 int status;
4955 int call_id;
4956 int is_typing;
4957 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004958 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004959 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004960 pj_pool_t * pool;
4961
Benny Prijono1f63cc42007-09-10 16:54:22 +00004962 PJ_UNUSED_ARG(pSelf);
4963
Fahris17d91812007-01-29 12:09:33 +00004964 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004965 {
4966 return NULL;
4967 }
4968
Fahris17d91812007-01-29 12:09:33 +00004969 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004970 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004971 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004972 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4973 msg_data.content_type.slen = strlen
4974 (PyString_AsString(omd->content_type));
4975 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4976 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004977 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004978 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4979 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
4980 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004981 } else {
Fahris17d91812007-01-29 12:09:33 +00004982 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004983 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004984 return Py_BuildValue("i",status);
4985}
4986
4987/*
4988 * py_pjsua_call_hangup_all
4989 */
4990static PyObject *py_pjsua_call_hangup_all
4991(PyObject *pSelf, PyObject *pArgs)
4992{
4993
Benny Prijono1f63cc42007-09-10 16:54:22 +00004994 PJ_UNUSED_ARG(pSelf);
4995
Fahrisdcf8fa42006-12-28 03:13:48 +00004996 if (!PyArg_ParseTuple(pArgs, ""))
4997 {
4998 return NULL;
4999 }
5000
5001 pjsua_call_hangup_all();
5002
5003 Py_INCREF(Py_None);
5004 return Py_None;
5005}
5006
5007/*
5008 * py_pjsua_call_dump
5009 */
5010static PyObject *py_pjsua_call_dump
5011(PyObject *pSelf, PyObject *pArgs)
5012{
5013 int call_id;
5014 int with_media;
5015 PyObject * sb;
5016 PyObject * si;
5017 char * buffer;
5018 char * indent;
5019 unsigned maxlen;
5020 int status;
5021
Benny Prijono1f63cc42007-09-10 16:54:22 +00005022 PJ_UNUSED_ARG(pSelf);
5023
Fahrisdcf8fa42006-12-28 03:13:48 +00005024 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
5025 {
5026 return NULL;
5027 }
5028 buffer = (char *) malloc (maxlen * sizeof(char));
5029 indent = PyString_AsString(si);
5030
5031 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
5032 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00005033 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00005034 return Py_BuildValue("O", sb);
5035}
5036
Benny Prijonoda275f62007-02-18 23:49:14 +00005037
5038/*
5039 * py_pjsua_dump
5040 * Dump application states.
5041 */
5042static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
5043{
5044 unsigned old_decor;
5045 char buf[1024];
5046 int detail;
5047
Benny Prijono1f63cc42007-09-10 16:54:22 +00005048 PJ_UNUSED_ARG(pSelf);
5049
Benny Prijonoda275f62007-02-18 23:49:14 +00005050 if (!PyArg_ParseTuple(pArgs, "i", &detail))
5051 {
5052 return NULL;
5053 }
5054
5055 PJ_LOG(3,(THIS_FILE, "Start dumping application states:"));
5056
5057 old_decor = pj_log_get_decor();
5058 pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR));
5059
5060 if (detail)
5061 pj_dump_config();
5062
5063 pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail);
5064 pjmedia_endpt_dump(pjsua_get_pjmedia_endpt());
5065 pjsip_tsx_layer_dump(detail);
5066 pjsip_ua_dump(detail);
5067
5068
5069 /* Dump all invite sessions: */
5070 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:"));
5071
5072 if (pjsua_call_get_count() == 0) {
5073
5074 PJ_LOG(3,(THIS_FILE, " - no sessions -"));
5075
5076 } else {
5077 unsigned i, max;
5078
5079 max = pjsua_call_get_max_count();
5080 for (i=0; i<max; ++i) {
5081 if (pjsua_call_is_active(i)) {
5082 pjsua_call_dump(i, detail, buf, sizeof(buf), " ");
5083 PJ_LOG(3,(THIS_FILE, "%s", buf));
5084 }
5085 }
5086 }
5087
5088 /* Dump presence status */
5089 pjsua_pres_dump(detail);
5090
5091 pj_log_set_decor(old_decor);
5092 PJ_LOG(3,(THIS_FILE, "Dump complete"));
5093
5094 Py_INCREF(Py_None);
5095 return Py_None;
5096}
5097
5098
Fahrisdcf8fa42006-12-28 03:13:48 +00005099static char pjsua_call_get_max_count_doc[] =
5100 "int py_pjsua.call_get_max_count () "
5101 "Get maximum number of calls configured in pjsua.";
5102static char pjsua_call_get_count_doc[] =
5103 "int py_pjsua.call_get_count () "
5104 "Get number of currently active calls.";
5105static char pjsua_enum_calls_doc[] =
5106 "int[] py_pjsua.enum_calls () "
5107 "Get maximum number of calls configured in pjsua.";
5108static char pjsua_call_make_call_doc[] =
5109 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
5110 "int user_data, py_pjsua.Msg_Data msg_data) "
5111 "Make outgoing call to the specified URI using the specified account.";
5112static char pjsua_call_is_active_doc[] =
5113 "int py_pjsua.call_is_active (int call_id) "
5114 "Check if the specified call has active INVITE session and the INVITE "
5115 "session has not been disconnected.";
5116static char pjsua_call_has_media_doc[] =
5117 "int py_pjsua.call_has_media (int call_id) "
5118 "Check if call has an active media session.";
5119static char pjsua_call_get_conf_port_doc[] =
5120 "int py_pjsua.call_get_conf_port (int call_id) "
5121 "Get the conference port identification associated with the call.";
5122static char pjsua_call_get_info_doc[] =
5123 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
5124 "Obtain detail information about the specified call.";
5125static char pjsua_call_set_user_data_doc[] =
5126 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
5127 "Attach application specific data to the call.";
5128static char pjsua_call_get_user_data_doc[] =
5129 "int py_pjsua.call_get_user_data (int call_id) "
5130 "Get user data attached to the call.";
5131static char pjsua_call_answer_doc[] =
5132 "int py_pjsua.call_answer (int call_id, int code, string reason, "
5133 "py_pjsua.Msg_Data msg_data) "
5134 "Send response to incoming INVITE request.";
5135static char pjsua_call_hangup_doc[] =
5136 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
5137 "py_pjsua.Msg_Data msg_data) "
5138 "Hangup call by using method that is appropriate according "
5139 "to the call state.";
5140static char pjsua_call_set_hold_doc[] =
5141 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
5142 "Put the specified call on hold.";
5143static char pjsua_call_reinvite_doc[] =
5144 "int py_pjsua.call_reinvite (int call_id, int unhold, "
5145 "py_pjsua.Msg_Data msg_data) "
5146 "Send re-INVITE (to release hold).";
5147static char pjsua_call_xfer_doc[] =
5148 "int py_pjsua.call_xfer (int call_id, string dest, "
5149 "py_pjsua.Msg_Data msg_data) "
5150 "Initiate call transfer to the specified address. "
5151 "This function will send REFER request to instruct remote call party "
5152 "to initiate a new INVITE session to the specified destination/target.";
5153static char pjsua_call_xfer_replaces_doc[] =
5154 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
5155 "int options, py_pjsua.Msg_Data msg_data) "
5156 "Initiate attended call transfer. This function will send REFER request "
5157 "to instruct remote call party to initiate new INVITE session to the URL "
5158 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
5159 "with us with the new call from the REFER recipient.";
5160static char pjsua_call_dial_dtmf_doc[] =
5161 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
5162 "Send DTMF digits to remote using RFC 2833 payload formats.";
5163static char pjsua_call_send_im_doc[] =
5164 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
5165 "py_pjsua.Msg_Data msg_data, int user_data) "
5166 "Send instant messaging inside INVITE session.";
5167static char pjsua_call_send_typing_ind_doc[] =
5168 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
5169 "py_pjsua.Msg_Data msg_data) "
5170 "Send IM typing indication inside INVITE session.";
5171static char pjsua_call_hangup_all_doc[] =
5172 "void py_pjsua.call_hangup_all () "
5173 "Terminate all calls.";
5174static char pjsua_call_dump_doc[] =
5175 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
5176 "string indent) "
5177 "Dump call and media statistics to string.";
5178
5179/* END OF LIB CALL */
5180
Benny Prijono572d4852006-11-23 21:50:02 +00005181/*
5182 * Map of function names to functions
5183 */
5184static PyMethodDef py_pjsua_methods[] =
5185{
5186 {
Benny Prijonodc308702006-12-09 00:39:42 +00005187 "thread_register", py_pjsua_thread_register, METH_VARARGS,
5188 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00005189 },
5190 {
Benny Prijono572d4852006-11-23 21:50:02 +00005191 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
5192 },
5193 {
5194 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
5195 },
5196 {
5197 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
5198 },
5199 {
5200 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
5201 },
5202 {
5203 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
5204 },
5205 {
5206 "handle_events", py_pjsua_handle_events, METH_VARARGS,
5207 pjsua_handle_events_doc
5208 },
5209 {
5210 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
5211 pjsua_verify_sip_url_doc
5212 },
5213 {
5214 "pool_create", py_pjsua_pool_create, METH_VARARGS,
5215 pjsua_pool_create_doc
5216 },
5217 {
5218 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
5219 pjsua_get_pjsip_endpt_doc
5220 },
5221 {
5222 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
5223 pjsua_get_pjmedia_endpt_doc
5224 },
5225 {
5226 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
5227 pjsua_get_pool_factory_doc
5228 },
5229 {
5230 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
5231 pjsua_reconfigure_logging_doc
5232 },
5233 {
5234 "logging_config_default", py_pjsua_logging_config_default,
5235 METH_VARARGS, pjsua_logging_config_default_doc
5236 },
5237 {
5238 "config_default", py_pjsua_config_default, METH_VARARGS,
5239 pjsua_config_default_doc
5240 },
5241 {
5242 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
5243 pjsua_media_config_default_doc
5244 },
Benny Prijonodc308702006-12-09 00:39:42 +00005245
5246
Benny Prijono572d4852006-11-23 21:50:02 +00005247 {
5248 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
5249 pjsua_msg_data_init_doc
5250 },
Benny Prijonodc308702006-12-09 00:39:42 +00005251 {
Benny Prijonodc308702006-12-09 00:39:42 +00005252 "transport_config_default", py_pjsua_transport_config_default,
5253 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005254 },
Benny Prijonodc308702006-12-09 00:39:42 +00005255 {
Benny Prijonodc308702006-12-09 00:39:42 +00005256 "transport_create", py_pjsua_transport_create, METH_VARARGS,
5257 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00005258 },
Benny Prijonodc308702006-12-09 00:39:42 +00005259 {
Benny Prijonodc308702006-12-09 00:39:42 +00005260 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
5261 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00005262 },
Benny Prijonodc308702006-12-09 00:39:42 +00005263 {
5264 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
5265 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005266 },
Benny Prijonodc308702006-12-09 00:39:42 +00005267 {
5268 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
5269 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00005270 },
Benny Prijonodc308702006-12-09 00:39:42 +00005271 {
5272 "transport_close", py_pjsua_transport_close, METH_VARARGS,
5273 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00005274 },
Benny Prijonodc308702006-12-09 00:39:42 +00005275 {
5276 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
5277 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005278 },
Benny Prijonodc308702006-12-09 00:39:42 +00005279 {
5280 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
5281 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005282 },
Benny Prijonodc308702006-12-09 00:39:42 +00005283 {
5284 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
5285 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00005286 },
Benny Prijonodc308702006-12-09 00:39:42 +00005287 {
5288 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
5289 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005290 },
Benny Prijonodc308702006-12-09 00:39:42 +00005291 {
5292 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
5293 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005294 },
Benny Prijonodc308702006-12-09 00:39:42 +00005295 {
5296 "acc_add", py_pjsua_acc_add, METH_VARARGS,
5297 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00005298 },
Benny Prijonodc308702006-12-09 00:39:42 +00005299 {
5300 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
5301 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00005302 },
Benny Prijonodc308702006-12-09 00:39:42 +00005303 {
5304 "acc_del", py_pjsua_acc_del, METH_VARARGS,
5305 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00005306 },
Benny Prijonodc308702006-12-09 00:39:42 +00005307 {
5308 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
5309 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00005310 },
Benny Prijonodc308702006-12-09 00:39:42 +00005311 {
5312 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
5313 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00005314 },
Benny Prijonodc308702006-12-09 00:39:42 +00005315 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00005316 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
5317 pjsua_acc_set_online_status2_doc
5318 },
5319 {
Benny Prijonodc308702006-12-09 00:39:42 +00005320 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
5321 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00005322 },
Benny Prijonodc308702006-12-09 00:39:42 +00005323 {
5324 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
5325 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005326 },
Benny Prijonodc308702006-12-09 00:39:42 +00005327 {
5328 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
5329 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00005330 },
Benny Prijonodc308702006-12-09 00:39:42 +00005331 {
5332 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
5333 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005334 },
Benny Prijonodc308702006-12-09 00:39:42 +00005335 {
5336 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
5337 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00005338 },
Benny Prijonodc308702006-12-09 00:39:42 +00005339 {
5340 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
5341 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00005342 },
Benny Prijonodc308702006-12-09 00:39:42 +00005343 {
5344 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
5345 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005346 },
Benny Prijonodc308702006-12-09 00:39:42 +00005347 {
5348 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
5349 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005350 },
Benny Prijonodc308702006-12-09 00:39:42 +00005351 {
Fahris6f35cb82007-02-01 07:41:26 +00005352 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
5353 pjsua_buddy_config_default_doc
5354 },
5355 {
Benny Prijonodc308702006-12-09 00:39:42 +00005356 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
5357 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005358 },
Benny Prijonodc308702006-12-09 00:39:42 +00005359 {
5360 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
5361 pjsua_buddy_is_valid_doc
5362 },
5363 {
5364 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
5365 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00005366 },
Benny Prijonodc308702006-12-09 00:39:42 +00005367 {
5368 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
5369 pjsua_buddy_get_info_doc
5370 },
5371 {
5372 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
5373 pjsua_buddy_add_doc
5374 },
5375 {
5376 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
5377 pjsua_buddy_del_doc
5378 },
5379 {
5380 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
5381 pjsua_buddy_subscribe_pres_doc
5382 },
5383 {
5384 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
5385 pjsua_pres_dump_doc
5386 },
5387 {
5388 "im_send", py_pjsua_im_send, METH_VARARGS,
5389 pjsua_im_send_doc
5390 },
5391 {
5392 "im_typing", py_pjsua_im_typing, METH_VARARGS,
5393 pjsua_im_typing_doc
5394 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005395 {
5396 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
5397 pjsua_conf_get_max_ports_doc
5398 },
5399 {
5400 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
5401 pjsua_conf_get_active_ports_doc
5402 },
5403 {
5404 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
5405 pjsua_enum_conf_ports_doc
5406 },
5407 {
5408 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
5409 pjsua_conf_get_port_info_doc
5410 },
5411 {
5412 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
5413 pjsua_conf_add_port_doc
5414 },
5415 {
5416 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
5417 pjsua_conf_remove_port_doc
5418 },
5419 {
5420 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
5421 pjsua_conf_connect_doc
5422 },
5423 {
5424 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
5425 pjsua_conf_disconnect_doc
5426 },
5427 {
5428 "player_create", py_pjsua_player_create, METH_VARARGS,
5429 pjsua_player_create_doc
5430 },
5431 {
5432 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
5433 pjsua_player_get_conf_port_doc
5434 },
5435 {
5436 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
5437 pjsua_player_set_pos_doc
5438 },
5439 {
5440 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
5441 pjsua_player_destroy_doc
5442 },
5443 {
5444 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
5445 pjsua_recorder_create_doc
5446 },
5447 {
5448 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
5449 pjsua_recorder_get_conf_port_doc
5450 },
5451 {
5452 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
5453 pjsua_recorder_destroy_doc
5454 },
5455 {
5456 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
5457 pjsua_enum_snd_devs_doc
5458 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00005459 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005460 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
5461 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00005462 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005463 {
5464 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
5465 pjsua_set_snd_dev_doc
5466 },
5467 {
5468 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
5469 pjsua_set_null_snd_dev_doc
5470 },
5471 {
5472 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
5473 pjsua_set_no_snd_dev_doc
5474 },
5475 {
5476 "set_ec", py_pjsua_set_ec, METH_VARARGS,
5477 pjsua_set_ec_doc
5478 },
5479 {
5480 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
5481 pjsua_get_ec_tail_doc
5482 },
5483 {
5484 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
5485 pjsua_enum_codecs_doc
5486 },
5487 {
5488 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
5489 pjsua_codec_set_priority_doc
5490 },
5491 {
5492 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
5493 pjsua_codec_get_param_doc
5494 },
5495 {
5496 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
5497 pjsua_codec_set_param_doc
5498 },
5499 {
5500 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
5501 pjsua_call_get_max_count_doc
5502 },
5503 {
5504 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
5505 pjsua_call_get_count_doc
5506 },
5507 {
5508 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
5509 pjsua_enum_calls_doc
5510 },
5511 {
5512 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
5513 pjsua_call_make_call_doc
5514 },
5515 {
5516 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
5517 pjsua_call_is_active_doc
5518 },
5519 {
5520 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
5521 pjsua_call_has_media_doc
5522 },
5523 {
5524 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
5525 pjsua_call_get_conf_port_doc
5526 },
5527 {
5528 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
5529 pjsua_call_get_info_doc
5530 },
5531 {
5532 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
5533 pjsua_call_set_user_data_doc
5534 },
5535 {
5536 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
5537 pjsua_call_get_user_data_doc
5538 },
5539 {
5540 "call_answer", py_pjsua_call_answer, METH_VARARGS,
5541 pjsua_call_answer_doc
5542 },
5543 {
5544 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
5545 pjsua_call_hangup_doc
5546 },
5547 {
5548 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
5549 pjsua_call_set_hold_doc
5550 },
5551 {
5552 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
5553 pjsua_call_reinvite_doc
5554 },
5555 {
5556 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
5557 pjsua_call_xfer_doc
5558 },
5559 {
5560 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
5561 pjsua_call_xfer_replaces_doc
5562 },
5563 {
5564 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
5565 pjsua_call_dial_dtmf_doc
5566 },
5567 {
5568 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
5569 pjsua_call_send_im_doc
5570 },
5571 {
5572 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
5573 pjsua_call_send_typing_ind_doc
5574 },
5575 {
5576 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
5577 pjsua_call_hangup_all_doc
5578 },
5579 {
5580 "call_dump", py_pjsua_call_dump, METH_VARARGS,
5581 pjsua_call_dump_doc
5582 },
Benny Prijonoda275f62007-02-18 23:49:14 +00005583 {
5584 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
5585 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005586
Benny Prijonodc308702006-12-09 00:39:42 +00005587
Benny Prijono572d4852006-11-23 21:50:02 +00005588 {NULL, NULL} /* end of function list */
5589};
5590
5591
5592
5593/*
5594 * Mapping C structs from and to Python objects & initializing object
5595 */
5596DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00005597initpy_pjsua(void)
5598{
Benny Prijono572d4852006-11-23 21:50:02 +00005599 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00005600#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00005601
Benny Prijonodc308702006-12-09 00:39:42 +00005602
Benny Prijonoda275f62007-02-18 23:49:14 +00005603 PyEval_InitThreads();
5604
Benny Prijono1f63cc42007-09-10 16:54:22 +00005605 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005606 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005607 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005608 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005609 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005610 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005611 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005612 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005613 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
5614 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005615 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005616 PyTyp_pjsip_event.tp_new = PyType_GenericNew;
5617 if (PyType_Ready(&PyTyp_pjsip_event) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005618 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005619 PyTyp_pjsip_rx_data.tp_new = PyType_GenericNew;
5620 if (PyType_Ready(&PyTyp_pjsip_rx_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005621 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005622 PyTyp_pj_pool_t.tp_new = PyType_GenericNew;
5623 if (PyType_Ready(&PyTyp_pj_pool_t) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005624 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005625 PyTyp_pjsip_endpoint.tp_new = PyType_GenericNew;
5626 if (PyType_Ready(&PyTyp_pjsip_endpoint) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005627 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005628 PyTyp_pjmedia_endpt.tp_new = PyType_GenericNew;
5629 if (PyType_Ready(&PyTyp_pjmedia_endpt) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005630 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005631 PyTyp_pj_pool_factory.tp_new = PyType_GenericNew;
5632 if (PyType_Ready(&PyTyp_pj_pool_factory) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005633 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005634 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
5635 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005636 return;
5637
Benny Prijonodc308702006-12-09 00:39:42 +00005638 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005639
Benny Prijono1f63cc42007-09-10 16:54:22 +00005640 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005641 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005642
Benny Prijono1f63cc42007-09-10 16:54:22 +00005643 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005644 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005645
Benny Prijonodc308702006-12-09 00:39:42 +00005646 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005647
Benny Prijonodc308702006-12-09 00:39:42 +00005648 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005649
Benny Prijonodc308702006-12-09 00:39:42 +00005650
Benny Prijono1f63cc42007-09-10 16:54:22 +00005651 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005652 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005653 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005654 return;
5655
Benny Prijonodc308702006-12-09 00:39:42 +00005656 /* END OF LIB ACCOUNT */
5657
5658 /* LIB BUDDY */
5659
Benny Prijono1f63cc42007-09-10 16:54:22 +00005660 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005661 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005662 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005663 return;
5664
5665 /* END OF LIB BUDDY */
5666
Fahrisdcf8fa42006-12-28 03:13:48 +00005667 /* LIB MEDIA */
5668
Benny Prijono1f63cc42007-09-10 16:54:22 +00005669 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005670 return;
5671
Benny Prijono1f63cc42007-09-10 16:54:22 +00005672 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005673 return;
5674
Benny Prijono1f63cc42007-09-10 16:54:22 +00005675 PyTyp_pjmedia_port.tp_new = PyType_GenericNew;
5676 if (PyType_Ready(&PyTyp_pjmedia_port) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005677 return;
5678
Benny Prijono1f63cc42007-09-10 16:54:22 +00005679 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005680 return;
5681
Benny Prijono1f63cc42007-09-10 16:54:22 +00005682 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
5683 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005684 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005685 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
5686 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005687 return;
5688
Benny Prijono1f63cc42007-09-10 16:54:22 +00005689 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005690 return;
5691
5692 /* END OF LIB MEDIA */
5693
5694 /* LIB CALL */
5695
Benny Prijono1f63cc42007-09-10 16:54:22 +00005696 PyTyp_pj_time_val.tp_new = PyType_GenericNew;
5697 if (PyType_Ready(&PyTyp_pj_time_val) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005698 return;
5699
Benny Prijono1f63cc42007-09-10 16:54:22 +00005700 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005701 return;
5702
5703 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00005704
Benny Prijono572d4852006-11-23 21:50:02 +00005705 m = Py_InitModule3(
5706 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
5707 );
5708
Benny Prijono1f63cc42007-09-10 16:54:22 +00005709 Py_INCREF(&PyTyp_pjsua_callback);
5710 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
Benny Prijono572d4852006-11-23 21:50:02 +00005711
Benny Prijono1f63cc42007-09-10 16:54:22 +00005712 Py_INCREF(&PyTyp_pjsua_config);
5713 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005714
Benny Prijono1f63cc42007-09-10 16:54:22 +00005715 Py_INCREF(&PyTyp_pjsua_media_config);
5716 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005717
Benny Prijono1f63cc42007-09-10 16:54:22 +00005718 Py_INCREF(&PyTyp_pjsua_logging_config);
5719 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005720
Benny Prijono1f63cc42007-09-10 16:54:22 +00005721 Py_INCREF(&PyTyp_pjsua_msg_data);
5722 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005723
Benny Prijono1f63cc42007-09-10 16:54:22 +00005724 Py_INCREF(&PyTyp_pjsip_event);
5725 PyModule_AddObject(m, "Pjsip_Event", (PyObject *)&PyTyp_pjsip_event);
Benny Prijono572d4852006-11-23 21:50:02 +00005726
Benny Prijono1f63cc42007-09-10 16:54:22 +00005727 Py_INCREF(&PyTyp_pjsip_rx_data);
5728 PyModule_AddObject(m, "Pjsip_Rx_Data", (PyObject *)&PyTyp_pjsip_rx_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005729
Benny Prijono1f63cc42007-09-10 16:54:22 +00005730 Py_INCREF(&PyTyp_pj_pool_t);
5731 PyModule_AddObject(m, "Pj_Pool", (PyObject *)&PyTyp_pj_pool_t);
Benny Prijono572d4852006-11-23 21:50:02 +00005732
Benny Prijono1f63cc42007-09-10 16:54:22 +00005733 Py_INCREF(&PyTyp_pjsip_endpoint);
5734 PyModule_AddObject(m, "Pjsip_Endpoint", (PyObject *)&PyTyp_pjsip_endpoint);
Benny Prijono572d4852006-11-23 21:50:02 +00005735
Benny Prijono1f63cc42007-09-10 16:54:22 +00005736 Py_INCREF(&PyTyp_pjmedia_endpt);
5737 PyModule_AddObject(m, "Pjmedia_Endpt", (PyObject *)&PyTyp_pjmedia_endpt);
Benny Prijono572d4852006-11-23 21:50:02 +00005738
Benny Prijono1f63cc42007-09-10 16:54:22 +00005739 Py_INCREF(&PyTyp_pj_pool_factory);
Benny Prijono572d4852006-11-23 21:50:02 +00005740 PyModule_AddObject(
Benny Prijono1f63cc42007-09-10 16:54:22 +00005741 m, "Pj_Pool_Factory", (PyObject *)&PyTyp_pj_pool_factory
Benny Prijono572d4852006-11-23 21:50:02 +00005742 );
5743
Benny Prijono1f63cc42007-09-10 16:54:22 +00005744 Py_INCREF(&PyTyp_pjsip_cred_info);
5745 PyModule_AddObject(m, "Pjsip_Cred_Info",
5746 (PyObject *)&PyTyp_pjsip_cred_info
Benny Prijono572d4852006-11-23 21:50:02 +00005747 );
5748
Benny Prijonodc308702006-12-09 00:39:42 +00005749 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005750
Benny Prijono1f63cc42007-09-10 16:54:22 +00005751 Py_INCREF(&PyTyp_pjsua_transport_config);
Benny Prijono98793592006-12-04 08:33:20 +00005752 PyModule_AddObject
Benny Prijono1f63cc42007-09-10 16:54:22 +00005753 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
Benny Prijonodc308702006-12-09 00:39:42 +00005754
Benny Prijono1f63cc42007-09-10 16:54:22 +00005755 Py_INCREF(&PyTyp_pjsua_transport_info);
5756 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005757
Benny Prijono98793592006-12-04 08:33:20 +00005758
Benny Prijonodc308702006-12-09 00:39:42 +00005759 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005760
Benny Prijonodc308702006-12-09 00:39:42 +00005761 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005762
Benny Prijonodc308702006-12-09 00:39:42 +00005763
Benny Prijono1f63cc42007-09-10 16:54:22 +00005764 Py_INCREF(&PyTyp_pjsua_acc_config);
5765 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
5766 Py_INCREF(&PyTyp_pjsua_acc_info);
5767 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
Benny Prijono98793592006-12-04 08:33:20 +00005768
Benny Prijonodc308702006-12-09 00:39:42 +00005769 /* END OF LIB ACCOUNT */
5770
5771 /* LIB BUDDY */
5772
Benny Prijono1f63cc42007-09-10 16:54:22 +00005773 Py_INCREF(&PyTyp_pjsua_buddy_config);
5774 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
5775 Py_INCREF(&PyTyp_pjsua_buddy_info);
5776 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005777
5778 /* END OF LIB BUDDY */
5779
Fahrisdcf8fa42006-12-28 03:13:48 +00005780 /* LIB MEDIA */
5781
Benny Prijono1f63cc42007-09-10 16:54:22 +00005782 Py_INCREF(&PyTyp_pjsua_codec_info);
5783 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
5784 Py_INCREF(&PyTyp_pjsua_conf_port_info);
5785 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
5786 Py_INCREF(&PyTyp_pjmedia_port);
5787 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&PyTyp_pjmedia_port);
5788 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005789 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005790 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
5791 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005792 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005793 (PyObject *)&PyTyp_pjmedia_codec_param_info);
5794 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
Fahrisdcf8fa42006-12-28 03:13:48 +00005795 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005796 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
5797 Py_INCREF(&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005798 PyModule_AddObject(m, "PJMedia_Codec_Param",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005799 (PyObject *)&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005800
5801 /* END OF LIB MEDIA */
5802
5803 /* LIB CALL */
5804
Benny Prijono1f63cc42007-09-10 16:54:22 +00005805 Py_INCREF(&PyTyp_pj_time_val);
5806 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&PyTyp_pj_time_val);
Fahrisdcf8fa42006-12-28 03:13:48 +00005807
Benny Prijono1f63cc42007-09-10 16:54:22 +00005808 Py_INCREF(&PyTyp_pjsua_call_info);
5809 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005810
5811 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00005812
Benny Prijonodc308702006-12-09 00:39:42 +00005813
Fahrisdcf8fa42006-12-28 03:13:48 +00005814 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00005815 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00005816 */
Benny Prijonodc308702006-12-09 00:39:42 +00005817
Benny Prijonoaa286042007-02-03 17:23:22 +00005818 /* Call states */
5819 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
5820 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
5821 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
5822 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
5823 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
5824 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
5825 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00005826
Benny Prijonoaa286042007-02-03 17:23:22 +00005827 /* Call media status (enum pjsua_call_media_status) */
5828 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
5829 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
5830 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
5831 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00005832
Benny Prijonoaa286042007-02-03 17:23:22 +00005833 /* Buddy status */
5834 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
5835 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
5836 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00005837
Benny Prijonoaa286042007-02-03 17:23:22 +00005838 /* PJSIP transport types (enum pjsip_transport_type_e) */
5839 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
5840 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
5841 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
5842 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
5843 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
5844 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
5845 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00005846
Fahrisdcf8fa42006-12-28 03:13:48 +00005847
Benny Prijonoaa286042007-02-03 17:23:22 +00005848 /* Invalid IDs */
5849 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00005850
Fahrisdcf8fa42006-12-28 03:13:48 +00005851
Benny Prijonoaa286042007-02-03 17:23:22 +00005852 /* Various compile time constants */
5853 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
5854 ADD_CONSTANT(m, PJSUA_MAX_ACC);
5855 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
5856 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
5857 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
5858 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
5859 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
5860 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
5861 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
5862 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
5863 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
5864 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
5865 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00005866
Fahrisdcf8fa42006-12-28 03:13:48 +00005867
Benny Prijonoaa286042007-02-03 17:23:22 +00005868#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00005869}