blob: 021bd74223c1410b69d85e7bfd5dbf25ceb5b229 [file] [log] [blame]
Benny Prijono572d4852006-11-23 21:50:02 +00001/* $Id$ */
2/*
Benny Prijonoaa286042007-02-03 17:23:22 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono572d4852006-11-23 21:50:02 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
Benny 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 Prijonoda275f62007-02-18 23:49:14 +000038static void cb_log_cb(int level, const char *data, pj_size_t 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{
155 if (PyCallable_Check(g_obj_callback->on_call_media_state))
156 {
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(
164 g_obj_callback->on_call_media_state,
165 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;
2406 unsigned listener_cnt;
2407 PyListObject * listeners;
2408
Benny Prijono1f63cc42007-09-10 16:54:22 +00002409} PyObj_pjsua_conf_port_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002410
2411
2412/*
2413 * conf_port_info_dealloc
2414 * deletes a conf_port_info from memory
2415 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002416static void conf_port_info_dealloc(PyObj_pjsua_conf_port_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002417{
2418 Py_XDECREF(self->name);
2419 Py_XDECREF(self->listeners);
2420 self->ob_type->tp_free((PyObject*)self);
2421}
2422
2423
2424/*
2425 * conf_port_info_new
2426 * constructor for conf_port_info object
2427 */
2428static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
2429 PyObject *kwds)
2430{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002431 PyObj_pjsua_conf_port_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002432
Benny Prijono1f63cc42007-09-10 16:54:22 +00002433 PJ_UNUSED_ARG(args);
2434 PJ_UNUSED_ARG(kwds);
2435
2436 self = (PyObj_pjsua_conf_port_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002437 if (self != NULL)
2438 {
2439 self->name = PyString_FromString("");
2440 if (self->name == NULL)
2441 {
2442 Py_DECREF(self);
2443 return NULL;
2444 }
2445
Fahris6f35cb82007-02-01 07:41:26 +00002446 self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS);
Fahrisdcf8fa42006-12-28 03:13:48 +00002447 if (self->listeners == NULL)
2448 {
2449 Py_DECREF(self);
2450 return NULL;
2451 }
2452 }
2453 return (PyObject *)self;
2454}
2455
2456/*
2457 * conf_port_info_members
2458 */
2459static PyMemberDef conf_port_info_members[] =
2460{
2461 {
2462 "slot_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002463 offsetof(PyObj_pjsua_conf_port_info, slot_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002464 "Conference port number."
2465 },
2466 {
2467 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002468 offsetof(PyObj_pjsua_conf_port_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002469 "Port name"
2470 },
2471 {
2472 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002473 offsetof(PyObj_pjsua_conf_port_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002474 "Clock rate"
2475 },
2476 {
2477 "channel_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002478 offsetof(PyObj_pjsua_conf_port_info, channel_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002479 "Number of channels."
2480 },
2481 {
2482 "samples_per_frame", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002483 offsetof(PyObj_pjsua_conf_port_info, samples_per_frame), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002484 "Samples per frame "
2485 },
2486 {
2487 "bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002488 offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002489 "Bits per sample"
2490 },
Fahris89ea3d02007-02-07 08:18:35 +00002491 {
Fahrisdcf8fa42006-12-28 03:13:48 +00002492 "listener_cnt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002493 offsetof(PyObj_pjsua_conf_port_info, listener_cnt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002494 "Number of listeners in the array."
Fahris89ea3d02007-02-07 08:18:35 +00002495 },
Fahrisdcf8fa42006-12-28 03:13:48 +00002496 {
2497 "listeners", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002498 offsetof(PyObj_pjsua_conf_port_info, listeners), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002499 "Array of listeners (in other words, ports where this port "
2500 "is transmitting to"
2501 },
2502
2503 {NULL} /* Sentinel */
2504};
2505
2506
2507
2508
2509/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002510 * PyTyp_pjsua_conf_port_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002511 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002512static PyTypeObject PyTyp_pjsua_conf_port_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002513{
2514 PyObject_HEAD_INIT(NULL)
2515 0, /*ob_size*/
2516 "py_pjsua.Conf_Port_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002517 sizeof(PyObj_pjsua_conf_port_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002518 0, /*tp_itemsize*/
2519 (destructor)conf_port_info_dealloc,/*tp_dealloc*/
2520 0, /*tp_print*/
2521 0, /*tp_getattr*/
2522 0, /*tp_setattr*/
2523 0, /*tp_compare*/
2524 0, /*tp_repr*/
2525 0, /*tp_as_number*/
2526 0, /*tp_as_sequence*/
2527 0, /*tp_as_mapping*/
2528 0, /*tp_hash */
2529 0, /*tp_call*/
2530 0, /*tp_str*/
2531 0, /*tp_getattro*/
2532 0, /*tp_setattro*/
2533 0, /*tp_as_buffer*/
2534 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2535 "Conf Port Info objects", /* tp_doc */
2536 0, /* tp_traverse */
2537 0, /* tp_clear */
2538 0, /* tp_richcompare */
2539 0, /* tp_weaklistoffset */
2540 0, /* tp_iter */
2541 0, /* tp_iternext */
2542 0, /* tp_methods */
2543 conf_port_info_members, /* tp_members */
2544 0, /* tp_getset */
2545 0, /* tp_base */
2546 0, /* tp_dict */
2547 0, /* tp_descr_get */
2548 0, /* tp_descr_set */
2549 0, /* tp_dictoffset */
2550 0, /* tp_init */
2551 0, /* tp_alloc */
2552 conf_port_info_new, /* tp_new */
2553
2554};
2555
2556/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002557 * PyObj_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002558 */
2559typedef struct
2560{
2561 PyObject_HEAD
2562 /* Type-specific fields go here. */
2563 pjmedia_port * port;
Benny Prijono1f63cc42007-09-10 16:54:22 +00002564} PyObj_pjmedia_port;
Fahrisdcf8fa42006-12-28 03:13:48 +00002565
2566
2567/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002568 * PyTyp_pjmedia_port
Fahrisdcf8fa42006-12-28 03:13:48 +00002569 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002570static PyTypeObject PyTyp_pjmedia_port =
Fahrisdcf8fa42006-12-28 03:13:48 +00002571{
2572 PyObject_HEAD_INIT(NULL)
2573 0, /*ob_size*/
2574 "py_pjsua.PJMedia_Port", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002575 sizeof(PyObj_pjmedia_port), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002576 0, /*tp_itemsize*/
2577 0, /*tp_dealloc*/
2578 0, /*tp_print*/
2579 0, /*tp_getattr*/
2580 0, /*tp_setattr*/
2581 0, /*tp_compare*/
2582 0, /*tp_repr*/
2583 0, /*tp_as_number*/
2584 0, /*tp_as_sequence*/
2585 0, /*tp_as_mapping*/
2586 0, /*tp_hash */
2587 0, /*tp_call*/
2588 0, /*tp_str*/
2589 0, /*tp_getattro*/
2590 0, /*tp_setattro*/
2591 0, /*tp_as_buffer*/
2592 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2593 "pjmedia_port objects", /* tp_doc */
2594
2595};
2596
2597/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002598 * PyObj_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002599 * PJMedia Snd Dev Info
2600 */
2601typedef struct
2602{
2603 PyObject_HEAD
2604 /* Type-specific fields go here. */
2605
2606
2607 unsigned input_count;
2608 unsigned output_count;
2609 unsigned default_samples_per_sec;
Fahrise314b882007-02-02 10:52:04 +00002610 PyObject * name;
Fahrisdcf8fa42006-12-28 03:13:48 +00002611
Benny Prijono1f63cc42007-09-10 16:54:22 +00002612} PyObj_pjmedia_snd_dev_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002613
2614
2615/*
2616 * pjmedia_snd_dev_info_dealloc
2617 * deletes a pjmedia_snd_dev_info from memory
2618 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002619static void pjmedia_snd_dev_info_dealloc(PyObj_pjmedia_snd_dev_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002620{
2621 Py_XDECREF(self->name);
2622 self->ob_type->tp_free((PyObject*)self);
2623}
2624
2625
2626/*
2627 * pjmedia_snd_dev_info_new
2628 * constructor for pjmedia_snd_dev_info object
2629 */
2630static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args,
2631 PyObject *kwds)
2632{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002633 PyObj_pjmedia_snd_dev_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002634
Benny Prijono1f63cc42007-09-10 16:54:22 +00002635 PJ_UNUSED_ARG(args);
2636 PJ_UNUSED_ARG(kwds);
2637
2638 self = (PyObj_pjmedia_snd_dev_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002639 if (self != NULL)
2640 {
Fahrise314b882007-02-02 10:52:04 +00002641 self->name = PyString_FromString("");
Fahrisdcf8fa42006-12-28 03:13:48 +00002642 if (self->name == NULL)
2643 {
2644 Py_DECREF(self);
2645 return NULL;
2646 }
2647
2648 }
2649 return (PyObject *)self;
2650}
2651
2652/*
2653 * pjmedia_snd_dev_info_members
2654 */
2655static PyMemberDef pjmedia_snd_dev_info_members[] =
2656{
2657
2658 {
2659 "name", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002660 offsetof(PyObj_pjmedia_snd_dev_info, name), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002661 "Device name"
2662 },
2663 {
2664 "input_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002665 offsetof(PyObj_pjmedia_snd_dev_info, input_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002666 "Max number of input channels"
2667 },
2668 {
2669 "output_count", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002670 offsetof(PyObj_pjmedia_snd_dev_info, output_count), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002671 "Max number of output channels"
2672 },
2673 {
2674 "default_samples_per_sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002675 offsetof(PyObj_pjmedia_snd_dev_info, default_samples_per_sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002676 "Default sampling rate."
2677 },
2678
2679
2680 {NULL} /* Sentinel */
2681};
2682
2683
2684
2685
2686/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002687 * PyTyp_pjmedia_snd_dev_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002688 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002689static PyTypeObject PyTyp_pjmedia_snd_dev_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002690{
2691 PyObject_HEAD_INIT(NULL)
2692 0, /*ob_size*/
2693 "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002694 sizeof(PyObj_pjmedia_snd_dev_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002695 0, /*tp_itemsize*/
2696 (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/
2697 0, /*tp_print*/
2698 0, /*tp_getattr*/
2699 0, /*tp_setattr*/
2700 0, /*tp_compare*/
2701 0, /*tp_repr*/
2702 0, /*tp_as_number*/
2703 0, /*tp_as_sequence*/
2704 0, /*tp_as_mapping*/
2705 0, /*tp_hash */
2706 0, /*tp_call*/
2707 0, /*tp_str*/
2708 0, /*tp_getattro*/
2709 0, /*tp_setattro*/
2710 0, /*tp_as_buffer*/
2711 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2712 "PJMedia Snd Dev Info objects", /* tp_doc */
2713 0, /* tp_traverse */
2714 0, /* tp_clear */
2715 0, /* tp_richcompare */
2716 0, /* tp_weaklistoffset */
2717 0, /* tp_iter */
2718 0, /* tp_iternext */
2719 0, /* tp_methods */
2720 pjmedia_snd_dev_info_members, /* tp_members */
2721 0, /* tp_getset */
2722 0, /* tp_base */
2723 0, /* tp_dict */
2724 0, /* tp_descr_get */
2725 0, /* tp_descr_set */
2726 0, /* tp_dictoffset */
2727 0, /* tp_init */
2728 0, /* tp_alloc */
2729 pjmedia_snd_dev_info_new, /* tp_new */
2730
2731};
2732
2733/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002734 * PyObj_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002735 * PJMedia Codec Param Info
2736 */
2737typedef struct
2738{
2739 PyObject_HEAD
2740 /* Type-specific fields go here. */
2741
2742 unsigned clock_rate;
2743 unsigned channel_cnt;
2744 pj_uint32_t avg_bps;
2745 pj_uint16_t frm_ptime;
2746 pj_uint8_t pcm_bits_per_sample;
2747 pj_uint8_t pt;
2748
Benny Prijono1f63cc42007-09-10 16:54:22 +00002749} PyObj_pjmedia_codec_param_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00002750
2751
2752
2753/*
2754 * pjmedia_codec_param_info_members
2755 */
2756static PyMemberDef pjmedia_codec_param_info_members[] =
2757{
2758
2759 {
2760 "clock_rate", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002761 offsetof(PyObj_pjmedia_codec_param_info, clock_rate), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002762 "Sampling rate in Hz"
2763 },
2764 {
2765 "channel_cnt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002766 offsetof(PyObj_pjmedia_codec_param_info, channel_cnt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002767 "Channel count"
2768 },
2769 {
2770 "avg_bps", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002771 offsetof(PyObj_pjmedia_codec_param_info, avg_bps), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002772 "Average bandwidth in bits/sec"
2773 },
2774 {
2775 "frm_ptime", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002776 offsetof(PyObj_pjmedia_codec_param_info, frm_ptime), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002777 "Base frame ptime in msec."
2778 },
2779 {
2780 "pcm_bits_per_sample", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002781 offsetof(PyObj_pjmedia_codec_param_info, pcm_bits_per_sample), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002782 "Bits/sample in the PCM side"
2783 },
2784 {
2785 "pt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002786 offsetof(PyObj_pjmedia_codec_param_info, pt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002787 "Payload type"
2788 },
2789
2790 {NULL} /* Sentinel */
2791};
2792
2793
2794
2795
2796/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002797 * PyTyp_pjmedia_codec_param_info
Fahrisdcf8fa42006-12-28 03:13:48 +00002798 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002799static PyTypeObject PyTyp_pjmedia_codec_param_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00002800{
2801 PyObject_HEAD_INIT(NULL)
2802 0, /*ob_size*/
2803 "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002804 sizeof(PyObj_pjmedia_codec_param_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002805 0, /*tp_itemsize*/
2806 0,/*tp_dealloc*/
2807 0, /*tp_print*/
2808 0, /*tp_getattr*/
2809 0, /*tp_setattr*/
2810 0, /*tp_compare*/
2811 0, /*tp_repr*/
2812 0, /*tp_as_number*/
2813 0, /*tp_as_sequence*/
2814 0, /*tp_as_mapping*/
2815 0, /*tp_hash */
2816 0, /*tp_call*/
2817 0, /*tp_str*/
2818 0, /*tp_getattro*/
2819 0, /*tp_setattro*/
2820 0, /*tp_as_buffer*/
2821 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2822 "PJMedia Codec Param Info objects", /* tp_doc */
2823 0, /* tp_traverse */
2824 0, /* tp_clear */
2825 0, /* tp_richcompare */
2826 0, /* tp_weaklistoffset */
2827 0, /* tp_iter */
2828 0, /* tp_iternext */
2829 0, /* tp_methods */
2830 pjmedia_codec_param_info_members, /* tp_members */
2831
2832
2833};
2834
2835/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002836 * PyObj_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002837 * PJMedia Codec Param Setting
2838 */
2839typedef struct
2840{
2841 PyObject_HEAD
2842 /* Type-specific fields go here. */
2843 pj_uint8_t frm_per_pkt;
2844 unsigned vad;
2845 unsigned cng;
2846 unsigned penh;
2847 unsigned plc;
2848 unsigned reserved;
2849 pj_uint8_t enc_fmtp_mode;
2850 pj_uint8_t dec_fmtp_mode;
2851
Benny Prijono1f63cc42007-09-10 16:54:22 +00002852} PyObj_pjmedia_codec_param_setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002853
2854
2855
2856/*
2857 * pjmedia_codec_param_setting_members
2858 */
2859static PyMemberDef pjmedia_codec_param_setting_members[] =
2860{
2861
2862 {
2863 "frm_per_pkt", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002864 offsetof(PyObj_pjmedia_codec_param_setting, frm_per_pkt), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002865 "Number of frames per packet"
2866 },
2867 {
2868 "vad", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002869 offsetof(PyObj_pjmedia_codec_param_setting, vad), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002870 "Voice Activity Detector"
2871 },
2872 {
2873 "penh", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002874 offsetof(PyObj_pjmedia_codec_param_setting, penh), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002875 "Perceptual Enhancement"
2876 },
2877 {
2878 "plc", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002879 offsetof(PyObj_pjmedia_codec_param_setting, plc), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002880 "Packet loss concealment"
2881 },
2882 {
2883 "reserved", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002884 offsetof(PyObj_pjmedia_codec_param_setting, reserved), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002885 "Reserved, must be zero"
2886 },
2887 {
2888 "cng", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002889 offsetof(PyObj_pjmedia_codec_param_setting, cng), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002890 "Comfort Noise Generator"
2891 },
2892 {
2893 "enc_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002894 offsetof(PyObj_pjmedia_codec_param_setting, enc_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002895 "Mode param in fmtp (def:0)"
2896 },
2897 {
2898 "dec_fmtp_mode", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00002899 offsetof(PyObj_pjmedia_codec_param_setting, dec_fmtp_mode), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00002900 "Mode param in fmtp (def:0)"
2901 },
2902
2903 {NULL} /* Sentinel */
2904};
2905
2906
2907
2908
2909/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002910 * PyTyp_pjmedia_codec_param_setting
Fahrisdcf8fa42006-12-28 03:13:48 +00002911 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002912static PyTypeObject PyTyp_pjmedia_codec_param_setting =
Fahrisdcf8fa42006-12-28 03:13:48 +00002913{
2914 PyObject_HEAD_INIT(NULL)
2915 0, /*ob_size*/
2916 "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00002917 sizeof(PyObj_pjmedia_codec_param_setting), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00002918 0, /*tp_itemsize*/
2919 0,/*tp_dealloc*/
2920 0, /*tp_print*/
2921 0, /*tp_getattr*/
2922 0, /*tp_setattr*/
2923 0, /*tp_compare*/
2924 0, /*tp_repr*/
2925 0, /*tp_as_number*/
2926 0, /*tp_as_sequence*/
2927 0, /*tp_as_mapping*/
2928 0, /*tp_hash */
2929 0, /*tp_call*/
2930 0, /*tp_str*/
2931 0, /*tp_getattro*/
2932 0, /*tp_setattro*/
2933 0, /*tp_as_buffer*/
2934 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2935 "PJMedia Codec Param Setting objects", /* tp_doc */
2936 0, /* tp_traverse */
2937 0, /* tp_clear */
2938 0, /* tp_richcompare */
2939 0, /* tp_weaklistoffset */
2940 0, /* tp_iter */
2941 0, /* tp_iternext */
2942 0, /* tp_methods */
2943 pjmedia_codec_param_setting_members, /* tp_members */
2944
2945
2946};
2947
2948/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00002949 * PyObj_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00002950 * PJMedia Codec Param
2951 */
2952typedef struct
2953{
2954 PyObject_HEAD
2955 /* Type-specific fields go here. */
2956
Benny Prijono1f63cc42007-09-10 16:54:22 +00002957 PyObj_pjmedia_codec_param_info * info;
2958 PyObj_pjmedia_codec_param_setting * setting;
Fahrisdcf8fa42006-12-28 03:13:48 +00002959
Benny Prijono1f63cc42007-09-10 16:54:22 +00002960} PyObj_pjmedia_codec_param;
Fahrisdcf8fa42006-12-28 03:13:48 +00002961
2962
2963/*
2964 * pjmedia_codec_param_dealloc
2965 * deletes a pjmedia_codec_param from memory
2966 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00002967static void pjmedia_codec_param_dealloc(PyObj_pjmedia_codec_param* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00002968{
2969 Py_XDECREF(self->info);
2970 Py_XDECREF(self->setting);
2971 self->ob_type->tp_free((PyObject*)self);
2972}
2973
2974
2975/*
2976 * pjmedia_codec_param_new
2977 * constructor for pjmedia_codec_param object
2978 */
2979static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args,
2980 PyObject *kwds)
2981{
Benny Prijono1f63cc42007-09-10 16:54:22 +00002982 PyObj_pjmedia_codec_param *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00002983
Benny Prijono1f63cc42007-09-10 16:54:22 +00002984 PJ_UNUSED_ARG(args);
2985 PJ_UNUSED_ARG(kwds);
2986
2987 self = (PyObj_pjmedia_codec_param *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00002988 if (self != NULL)
2989 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00002990 self->info = (PyObj_pjmedia_codec_param_info *)
2991 PyType_GenericNew(&PyTyp_pjmedia_codec_param_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002992 if (self->info == NULL)
2993 {
2994 Py_DECREF(self);
2995 return NULL;
2996 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00002997 self->setting = (PyObj_pjmedia_codec_param_setting *)
2998 PyType_GenericNew(&PyTyp_pjmedia_codec_param_setting, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00002999 if (self->setting == NULL)
3000 {
3001 Py_DECREF(self);
3002 return NULL;
3003 }
3004 }
3005 return (PyObject *)self;
3006}
3007
3008/*
3009 * pjmedia_codec_param_members
3010 */
3011static PyMemberDef pjmedia_codec_param_members[] =
3012{
3013
3014 {
3015 "info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003016 offsetof(PyObj_pjmedia_codec_param, info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003017 "The 'info' part of codec param describes the capability of the codec,"
3018 " and the value should NOT be changed by application."
3019 },
3020 {
3021 "setting", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003022 offsetof(PyObj_pjmedia_codec_param, setting), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003023 "The 'setting' part of codec param describes various settings to be "
3024 "applied to the codec. When the codec param is retrieved from the "
3025 "codec or codec factory, the values of these will be filled by "
3026 "the capability of the codec. Any features that are supported by "
3027 "the codec (e.g. vad or plc) will be turned on, so that application "
3028 "can query which capabilities are supported by the codec. "
3029 "Application may change the settings here before instantiating "
3030 "the codec/stream."
3031 },
3032
3033 {NULL} /* Sentinel */
3034};
3035
3036
3037
3038
3039/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003040 * PyTyp_pjmedia_codec_param
Fahrisdcf8fa42006-12-28 03:13:48 +00003041 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003042static PyTypeObject PyTyp_pjmedia_codec_param =
Fahrisdcf8fa42006-12-28 03:13:48 +00003043{
3044 PyObject_HEAD_INIT(NULL)
3045 0, /*ob_size*/
3046 "py_pjsua.PJMedia_Codec_Param", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003047 sizeof(PyObj_pjmedia_codec_param), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003048 0, /*tp_itemsize*/
3049 (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/
3050 0, /*tp_print*/
3051 0, /*tp_getattr*/
3052 0, /*tp_setattr*/
3053 0, /*tp_compare*/
3054 0, /*tp_repr*/
3055 0, /*tp_as_number*/
3056 0, /*tp_as_sequence*/
3057 0, /*tp_as_mapping*/
3058 0, /*tp_hash */
3059 0, /*tp_call*/
3060 0, /*tp_str*/
3061 0, /*tp_getattro*/
3062 0, /*tp_setattro*/
3063 0, /*tp_as_buffer*/
3064 Py_TPFLAGS_DEFAULT, /*tp_flags*/
3065 "PJMedia Codec Param objects", /* tp_doc */
3066 0, /* tp_traverse */
3067 0, /* tp_clear */
3068 0, /* tp_richcompare */
3069 0, /* tp_weaklistoffset */
3070 0, /* tp_iter */
3071 0, /* tp_iternext */
3072 0, /* tp_methods */
3073 pjmedia_codec_param_members, /* tp_members */
3074 0, /* tp_getset */
3075 0, /* tp_base */
3076 0, /* tp_dict */
3077 0, /* tp_descr_get */
3078 0, /* tp_descr_set */
3079 0, /* tp_dictoffset */
3080 0, /* tp_init */
3081 0, /* tp_alloc */
3082 pjmedia_codec_param_new, /* tp_new */
3083
3084};
3085
3086/*
3087 * py_pjsua_conf_get_max_ports
3088 */
3089static PyObject *py_pjsua_conf_get_max_ports
3090(PyObject *pSelf, PyObject *pArgs)
3091{
3092 int ret;
3093
Benny Prijono1f63cc42007-09-10 16:54:22 +00003094 PJ_UNUSED_ARG(pSelf);
3095
Fahrisdcf8fa42006-12-28 03:13:48 +00003096 if (!PyArg_ParseTuple(pArgs, ""))
3097 {
3098 return NULL;
3099 }
3100 ret = pjsua_conf_get_max_ports();
3101
3102 return Py_BuildValue("i", ret);
3103}
3104
3105/*
3106 * py_pjsua_conf_get_active_ports
3107 */
3108static PyObject *py_pjsua_conf_get_active_ports
3109(PyObject *pSelf, PyObject *pArgs)
3110{
3111 int ret;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003112
3113 PJ_UNUSED_ARG(pSelf);
3114
Fahrisdcf8fa42006-12-28 03:13:48 +00003115 if (!PyArg_ParseTuple(pArgs, ""))
3116 {
3117 return NULL;
3118 }
3119 ret = pjsua_conf_get_active_ports();
3120
3121 return Py_BuildValue("i", ret);
3122}
3123
3124/*
3125 * py_pjsua_enum_conf_ports
3126 * !modified @ 241206
3127 */
3128static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs)
3129{
3130 pj_status_t status;
3131 PyObject *list;
3132
3133 pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
Fahris17d91812007-01-29 12:09:33 +00003134 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003135
3136 PJ_UNUSED_ARG(pSelf);
3137
Fahrisdcf8fa42006-12-28 03:13:48 +00003138 if (!PyArg_ParseTuple(pArgs, ""))
3139 {
3140 return NULL;
3141 }
3142
3143 c = PJ_ARRAY_SIZE(id);
3144 status = pjsua_enum_conf_ports(id, &c);
3145
3146 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003147 for (i = 0; i < c; i++)
3148 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003149 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
Fahris6f35cb82007-02-01 07:41:26 +00003150 if (ret == -1)
3151 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003152 return NULL;
3153 }
3154 }
3155
Fahrisdcf8fa42006-12-28 03:13:48 +00003156 return Py_BuildValue("O",list);
3157}
3158
3159/*
3160 * py_pjsua_conf_get_port_info
3161 */
3162static PyObject *py_pjsua_conf_get_port_info
3163(PyObject *pSelf, PyObject *pArgs)
3164{
3165 int id;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003166 PyObj_pjsua_conf_port_info * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003167 pjsua_conf_port_info info;
3168 int status;
3169 int i;
3170
Benny Prijono1f63cc42007-09-10 16:54:22 +00003171 PJ_UNUSED_ARG(pSelf);
3172
Fahrisdcf8fa42006-12-28 03:13:48 +00003173 if (!PyArg_ParseTuple(pArgs, "i", &id))
3174 {
3175 return NULL;
3176 }
3177
3178
3179 status = pjsua_conf_get_port_info(id, &info);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003180 obj = (PyObj_pjsua_conf_port_info *)conf_port_info_new
3181 (&PyTyp_pjsua_conf_port_info,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003182 obj->bits_per_sample = info.bits_per_sample;
3183 obj->channel_count = info.bits_per_sample;
3184 obj->clock_rate = info.clock_rate;
3185 obj->listener_cnt = info.listener_cnt;
3186 obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
3187 obj->samples_per_frame = info.samples_per_frame;
3188 obj->slot_id = info.slot_id;
3189
Fahris6f35cb82007-02-01 07:41:26 +00003190 for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) {
Fahrisdcf8fa42006-12-28 03:13:48 +00003191 PyObject * item = Py_BuildValue("i",info.listeners[i]);
3192 PyList_SetItem((PyObject *)obj->listeners, i, item);
3193 }
3194 return Py_BuildValue("O", obj);
3195}
3196
3197/*
3198 * py_pjsua_conf_add_port
3199 */
3200static PyObject *py_pjsua_conf_add_port
3201(PyObject *pSelf, PyObject *pArgs)
3202{
3203 int p_id;
Fahris6f35cb82007-02-01 07:41:26 +00003204 PyObject * oportObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003205 PyObj_pjmedia_port * oport;
Fahris6f35cb82007-02-01 07:41:26 +00003206 pjmedia_port * port;
3207 PyObject * opoolObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003208 PyObj_pj_pool * opool;
Fahris6f35cb82007-02-01 07:41:26 +00003209 pj_pool_t * pool;
Fahrisdcf8fa42006-12-28 03:13:48 +00003210
3211 int status;
3212
Benny Prijono1f63cc42007-09-10 16:54:22 +00003213 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003214
Fahris17d91812007-01-29 12:09:33 +00003215 if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003216 {
3217 return NULL;
3218 }
Fahris17d91812007-01-29 12:09:33 +00003219 if (opoolObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003220 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003221 opool = (PyObj_pj_pool *)opoolObj;
Fahris17d91812007-01-29 12:09:33 +00003222 pool = opool->pool;
Fahris6f35cb82007-02-01 07:41:26 +00003223 } else {
3224 opool = NULL;
3225 pool = NULL;
Fahris17d91812007-01-29 12:09:33 +00003226 }
3227 if (oportObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003228 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003229 oport = (PyObj_pjmedia_port *)oportObj;
Fahris17d91812007-01-29 12:09:33 +00003230 port = oport->port;
Fahris6f35cb82007-02-01 07:41:26 +00003231 } else {
Fahris17d91812007-01-29 12:09:33 +00003232 oport = NULL;
Fahris6f35cb82007-02-01 07:41:26 +00003233 port = NULL;
Fahris17d91812007-01-29 12:09:33 +00003234 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003235
Fahris17d91812007-01-29 12:09:33 +00003236 status = pjsua_conf_add_port(pool, port, &p_id);
Fahrisdcf8fa42006-12-28 03:13:48 +00003237
3238
3239 return Py_BuildValue("ii", status, p_id);
3240}
3241
3242/*
3243 * py_pjsua_conf_remove_port
3244 */
3245static PyObject *py_pjsua_conf_remove_port
3246(PyObject *pSelf, PyObject *pArgs)
3247{
3248 int id;
3249 int status;
3250
Benny Prijono1f63cc42007-09-10 16:54:22 +00003251 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003252
3253 if (!PyArg_ParseTuple(pArgs, "i", &id))
3254 {
3255 return NULL;
3256 }
3257
3258 status = pjsua_conf_remove_port(id);
3259
3260
3261 return Py_BuildValue("i", status);
3262}
3263
3264/*
3265 * py_pjsua_conf_connect
3266 */
3267static PyObject *py_pjsua_conf_connect
3268(PyObject *pSelf, PyObject *pArgs)
3269{
3270 int source, sink;
3271 int status;
3272
Benny Prijono1f63cc42007-09-10 16:54:22 +00003273 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003274
3275 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3276 {
3277 return NULL;
3278 }
3279
3280 status = pjsua_conf_connect(source, sink);
3281
3282
3283 return Py_BuildValue("i", status);
3284}
3285
3286/*
3287 * py_pjsua_conf_disconnect
3288 */
3289static PyObject *py_pjsua_conf_disconnect
3290(PyObject *pSelf, PyObject *pArgs)
3291{
3292 int source, sink;
3293 int status;
3294
Benny Prijono1f63cc42007-09-10 16:54:22 +00003295 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003296
3297 if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink))
3298 {
3299 return NULL;
3300 }
3301
3302 status = pjsua_conf_disconnect(source, sink);
3303
3304
3305 return Py_BuildValue("i", status);
3306}
3307
3308/*
3309 * py_pjsua_player_create
3310 */
3311static PyObject *py_pjsua_player_create
3312(PyObject *pSelf, PyObject *pArgs)
3313{
3314 int id;
3315 int options;
3316 PyObject * filename;
3317 pj_str_t str;
3318 int status;
3319
Benny Prijono1f63cc42007-09-10 16:54:22 +00003320 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003321
3322 if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options))
3323 {
3324 return NULL;
3325 }
3326 str.ptr = PyString_AsString(filename);
3327 str.slen = strlen(PyString_AsString(filename));
3328 status = pjsua_player_create(&str, options, &id);
3329
3330 return Py_BuildValue("ii", status, id);
3331}
3332
3333/*
3334 * py_pjsua_player_get_conf_port
3335 */
3336static PyObject *py_pjsua_player_get_conf_port
3337(PyObject *pSelf, PyObject *pArgs)
3338{
3339
3340 int id, port_id;
3341
Benny Prijono1f63cc42007-09-10 16:54:22 +00003342 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003343
3344 if (!PyArg_ParseTuple(pArgs, "i", &id))
3345 {
3346 return NULL;
3347 }
3348
3349 port_id = pjsua_player_get_conf_port(id);
3350
3351
3352 return Py_BuildValue("i", port_id);
3353}
3354
3355/*
3356 * py_pjsua_player_set_pos
3357 */
3358static PyObject *py_pjsua_player_set_pos
3359(PyObject *pSelf, PyObject *pArgs)
3360{
3361 int id;
3362 pj_uint32_t samples;
3363 int status;
3364
Benny Prijono1f63cc42007-09-10 16:54:22 +00003365 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003366
3367 if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples))
3368 {
3369 return NULL;
3370 }
3371
3372 status = pjsua_player_set_pos(id, samples);
3373
3374
3375 return Py_BuildValue("i", status);
3376}
3377
3378/*
3379 * py_pjsua_player_destroy
3380 */
3381static PyObject *py_pjsua_player_destroy
3382(PyObject *pSelf, PyObject *pArgs)
3383{
3384 int id;
3385 int status;
3386
Benny Prijono1f63cc42007-09-10 16:54:22 +00003387 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003388
3389 if (!PyArg_ParseTuple(pArgs, "i", &id))
3390 {
3391 return NULL;
3392 }
3393
3394 status = pjsua_player_destroy(id);
3395
3396
3397 return Py_BuildValue("i", status);
3398}
3399
3400/*
3401 * py_pjsua_recorder_create
3402 * !modified @ 261206
3403 */
3404static PyObject *py_pjsua_recorder_create
3405(PyObject *pSelf, PyObject *pArgs)
3406{
3407 int p_id;
3408 int options;
3409 int max_size;
3410 PyObject * filename;
3411 pj_str_t str;
3412 PyObject * enc_param;
Fahris6f35cb82007-02-01 07:41:26 +00003413 pj_str_t strparam;
Fahrisdcf8fa42006-12-28 03:13:48 +00003414 int enc_type;
3415
3416 int status;
3417
Benny Prijono1f63cc42007-09-10 16:54:22 +00003418 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003419
Fahris17d91812007-01-29 12:09:33 +00003420 if (!PyArg_ParseTuple(pArgs, "OiOii", &filename,
3421 &enc_type, &enc_param, &max_size, &options))
Fahrisdcf8fa42006-12-28 03:13:48 +00003422 {
3423 return NULL;
3424 }
3425 str.ptr = PyString_AsString(filename);
3426 str.slen = strlen(PyString_AsString(filename));
Fahris89ea3d02007-02-07 08:18:35 +00003427 if (enc_param != Py_None)
3428 {
3429 strparam.ptr = PyString_AsString(enc_param);
3430 strparam.slen = strlen(PyString_AsString(enc_param));
3431 status = pjsua_recorder_create
Fahris17d91812007-01-29 12:09:33 +00003432 (&str, enc_type, NULL, max_size, options, &p_id);
Fahris89ea3d02007-02-07 08:18:35 +00003433 } else {
3434 status = pjsua_recorder_create
3435 (&str, enc_type, NULL, max_size, options, &p_id);
3436 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003437 return Py_BuildValue("ii", status, p_id);
3438}
3439
3440/*
3441 * py_pjsua_recorder_get_conf_port
3442 */
3443static PyObject *py_pjsua_recorder_get_conf_port
3444(PyObject *pSelf, PyObject *pArgs)
3445{
3446
3447 int id, port_id;
3448
Benny Prijono1f63cc42007-09-10 16:54:22 +00003449 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003450
3451 if (!PyArg_ParseTuple(pArgs, "i", &id))
3452 {
3453 return NULL;
3454 }
3455
3456 port_id = pjsua_recorder_get_conf_port(id);
3457
3458
3459 return Py_BuildValue("i", port_id);
3460}
3461
3462/*
3463 * py_pjsua_recorder_destroy
3464 */
3465static PyObject *py_pjsua_recorder_destroy
3466(PyObject *pSelf, PyObject *pArgs)
3467{
3468 int id;
3469 int status;
3470
Benny Prijono1f63cc42007-09-10 16:54:22 +00003471 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003472
3473 if (!PyArg_ParseTuple(pArgs, "i", &id))
3474 {
3475 return NULL;
3476 }
3477
3478 status = pjsua_recorder_destroy(id);
3479
3480
3481 return Py_BuildValue("i", status);
3482}
3483
3484/*
3485 * py_pjsua_enum_snd_devs
3486 */
3487static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs)
3488{
3489 pj_status_t status;
3490 PyObject *list;
3491
Fahris6f35cb82007-02-01 07:41:26 +00003492 pjmedia_snd_dev_info info[SND_DEV_NUM];
Fahris17d91812007-01-29 12:09:33 +00003493 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003494
3495 PJ_UNUSED_ARG(pSelf);
3496
Fahrisb721aa32007-01-29 05:07:41 +00003497 if (!PyArg_ParseTuple(pArgs, ""))
Fahrisdcf8fa42006-12-28 03:13:48 +00003498 {
3499 return NULL;
3500 }
3501
Fahrisb721aa32007-01-29 05:07:41 +00003502 c = PJ_ARRAY_SIZE(info);
Fahrisdcf8fa42006-12-28 03:13:48 +00003503 status = pjsua_enum_snd_devs(info, &c);
3504
3505 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003506 for (i = 0; i < c; i++)
3507 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003508 int ret;
Fahris6f35cb82007-02-01 07:41:26 +00003509 int j;
Fahrise314b882007-02-02 10:52:04 +00003510 char * str;
3511
Benny Prijono1f63cc42007-09-10 16:54:22 +00003512 PyObj_pjmedia_snd_dev_info * obj;
3513 obj = (PyObj_pjmedia_snd_dev_info *)pjmedia_snd_dev_info_new
3514 (&PyTyp_pjmedia_snd_dev_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003515 obj->default_samples_per_sec = info[i].default_samples_per_sec;
3516 obj->input_count = info[i].input_count;
3517 obj->output_count = info[i].output_count;
Fahrise314b882007-02-02 10:52:04 +00003518 str = (char *)malloc(SND_NAME_LEN * sizeof(char));
3519 memset(str, 0, SND_NAME_LEN);
3520 for (j = 0; j < SND_NAME_LEN; j++)
Fahrisdcf8fa42006-12-28 03:13:48 +00003521 {
Fahrise314b882007-02-02 10:52:04 +00003522 str[j] = info[i].name[j];
Fahrisdcf8fa42006-12-28 03:13:48 +00003523 }
Fahrise314b882007-02-02 10:52:04 +00003524 obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN);
3525 free(str);
Fahrisdcf8fa42006-12-28 03:13:48 +00003526 ret = PyList_SetItem(list, i, (PyObject *)obj);
Fahris6f35cb82007-02-01 07:41:26 +00003527 if (ret == -1)
3528 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003529 return NULL;
3530 }
3531 }
3532
Fahrisdcf8fa42006-12-28 03:13:48 +00003533 return Py_BuildValue("O",list);
3534}
3535
3536/*
3537 * py_pjsua_get_snd_dev
3538 */
3539static PyObject *py_pjsua_get_snd_dev
3540(PyObject *pSelf, PyObject *pArgs)
3541{
3542 int capture_dev, playback_dev;
3543 int status;
3544
Benny Prijono1f63cc42007-09-10 16:54:22 +00003545 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003546
3547 if (!PyArg_ParseTuple(pArgs, ""))
3548 {
3549 return NULL;
3550 }
3551
3552 status = pjsua_get_snd_dev(&capture_dev, &playback_dev);
3553
3554
3555 return Py_BuildValue("ii", capture_dev, playback_dev);
3556}
3557
3558/*
3559 * py_pjsua_set_snd_dev
3560 */
3561static PyObject *py_pjsua_set_snd_dev
3562(PyObject *pSelf, PyObject *pArgs)
3563{
3564 int capture_dev, playback_dev;
3565 int status;
3566
Benny Prijono1f63cc42007-09-10 16:54:22 +00003567 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003568
3569 if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev))
3570 {
3571 return NULL;
3572 }
3573
3574 status = pjsua_set_snd_dev(capture_dev, playback_dev);
3575
3576
3577 return Py_BuildValue("i", status);
3578}
3579
3580/*
3581 * py_pjsua_set_null_snd_dev
3582 */
3583static PyObject *py_pjsua_set_null_snd_dev
3584(PyObject *pSelf, PyObject *pArgs)
3585{
3586
3587 int status;
3588
Benny Prijono1f63cc42007-09-10 16:54:22 +00003589 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003590
3591 if (!PyArg_ParseTuple(pArgs, ""))
3592 {
3593 return NULL;
3594 }
3595
3596 status = pjsua_set_null_snd_dev();
3597
3598
3599 return Py_BuildValue("i", status);
3600}
3601
3602/*
3603 * py_pjsua_set_no_snd_dev
3604 */
3605static PyObject *py_pjsua_set_no_snd_dev
3606(PyObject *pSelf, PyObject *pArgs)
3607{
3608
Benny Prijono1f63cc42007-09-10 16:54:22 +00003609 PyObj_pjmedia_port * obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003610
Benny Prijono1f63cc42007-09-10 16:54:22 +00003611 PJ_UNUSED_ARG(pSelf);
3612
Fahrisdcf8fa42006-12-28 03:13:48 +00003613 if (!PyArg_ParseTuple(pArgs, ""))
3614 {
3615 return NULL;
3616 }
3617
Benny Prijono1f63cc42007-09-10 16:54:22 +00003618 obj = (PyObj_pjmedia_port *)PyType_GenericNew
3619 (&PyTyp_pjmedia_port, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003620 obj->port = pjsua_set_no_snd_dev();
3621 return Py_BuildValue("O", obj);
3622}
3623
3624/*
3625 * py_pjsua_set_ec
3626 */
3627static PyObject *py_pjsua_set_ec
3628(PyObject *pSelf, PyObject *pArgs)
3629{
3630 int options;
3631 int tail_ms;
3632 int status;
3633
Benny Prijono1f63cc42007-09-10 16:54:22 +00003634 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00003635
3636 if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options))
3637 {
3638 return NULL;
3639 }
3640
3641 status = pjsua_set_ec(tail_ms, options);
3642
3643
3644 return Py_BuildValue("i", status);
3645}
3646
3647/*
3648 * py_pjsua_get_ec_tail
3649 */
3650static PyObject *py_pjsua_get_ec_tail
3651(PyObject *pSelf, PyObject *pArgs)
3652{
3653
3654 int status;
Fahris17d91812007-01-29 12:09:33 +00003655 unsigned p_tail_ms;
Fahrisdcf8fa42006-12-28 03:13:48 +00003656
Benny Prijono1f63cc42007-09-10 16:54:22 +00003657 PJ_UNUSED_ARG(pSelf);
3658
Fahrisdcf8fa42006-12-28 03:13:48 +00003659 if (!PyArg_ParseTuple(pArgs, ""))
3660 {
3661 return NULL;
3662 }
3663
3664 status = pjsua_get_ec_tail(&p_tail_ms);
3665
3666
3667 return Py_BuildValue("i", p_tail_ms);
3668}
3669
3670/*
3671 * py_pjsua_enum_codecs
3672 * !modified @ 261206
3673 */
3674static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs)
3675{
3676 pj_status_t status;
3677 PyObject *list;
3678
3679 pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
Fahris17d91812007-01-29 12:09:33 +00003680 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003681
3682 PJ_UNUSED_ARG(pSelf);
3683
Fahrisdcf8fa42006-12-28 03:13:48 +00003684 if (!PyArg_ParseTuple(pArgs, ""))
3685 {
3686 return NULL;
3687 }
3688
3689 c = PJ_ARRAY_SIZE(info);
3690 status = pjsua_enum_codecs(info, &c);
3691
3692 list = PyList_New(c);
Fahris6f35cb82007-02-01 07:41:26 +00003693 for (i = 0; i < c; i++)
3694 {
Fahrisdcf8fa42006-12-28 03:13:48 +00003695 int ret;
3696 int j;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003697 PyObj_pjsua_codec_info * obj;
3698 obj = (PyObj_pjsua_codec_info *)codec_info_new
3699 (&PyTyp_pjsua_codec_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003700 obj->codec_id = PyString_FromStringAndSize
3701 (info[i].codec_id.ptr, info[i].codec_id.slen);
3702 obj->priority = info[i].priority;
3703 for (j = 0; j < 32; j++)
3704 {
3705 obj->buf_[j] = info[i].buf_[j];
3706 }
3707 ret = PyList_SetItem(list, i, (PyObject *)obj);
3708 if (ret == -1) {
3709 return NULL;
3710 }
3711 }
3712
Fahris17d91812007-01-29 12:09:33 +00003713
Fahrisdcf8fa42006-12-28 03:13:48 +00003714 return Py_BuildValue("O",list);
3715}
3716
3717/*
3718 * py_pjsua_codec_set_priority
3719 */
3720static PyObject *py_pjsua_codec_set_priority
3721(PyObject *pSelf, PyObject *pArgs)
3722{
3723
3724 int status;
3725 PyObject * id;
3726 pj_str_t str;
3727 pj_uint8_t priority;
3728
Benny Prijono1f63cc42007-09-10 16:54:22 +00003729 PJ_UNUSED_ARG(pSelf);
3730
Fahrisdcf8fa42006-12-28 03:13:48 +00003731 if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority))
3732 {
3733 return NULL;
3734 }
3735 str.ptr = PyString_AsString(id);
3736 str.slen = strlen(PyString_AsString(id));
3737 status = pjsua_codec_set_priority(&str, priority);
3738
3739
3740 return Py_BuildValue("i", status);
3741}
3742
3743/*
3744 * py_pjsua_codec_get_param
3745 */
3746static PyObject *py_pjsua_codec_get_param
3747(PyObject *pSelf, PyObject *pArgs)
3748{
3749
3750 int status;
3751 PyObject * id;
3752 pj_str_t str;
3753 pjmedia_codec_param param;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003754 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003755
Benny Prijono1f63cc42007-09-10 16:54:22 +00003756 PJ_UNUSED_ARG(pSelf);
3757
Fahrisdcf8fa42006-12-28 03:13:48 +00003758 if (!PyArg_ParseTuple(pArgs, "O", &id))
3759 {
3760 return NULL;
3761 }
3762 str.ptr = PyString_AsString(id);
3763 str.slen = strlen(PyString_AsString(id));
3764 status = pjsua_codec_get_param(&str, &param);
Benny Prijono1f63cc42007-09-10 16:54:22 +00003765 obj = (PyObj_pjmedia_codec_param *)pjmedia_codec_param_new
3766 (&PyTyp_pjmedia_codec_param, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00003767 obj->info->avg_bps = param.info.avg_bps;
3768 obj->info->channel_cnt = param.info.channel_cnt;
3769 obj->info->clock_rate = param.info.clock_rate;
3770 obj->info->frm_ptime = param.info.frm_ptime;
3771 obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample;
3772 obj->info->pt = param.info.pt;
3773 obj->setting->cng = param.setting.cng;
3774 obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode;
3775 obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode;
3776 obj->setting->frm_per_pkt = param.setting.frm_per_pkt;
3777 obj->setting->penh = param.setting.penh;
3778 obj->setting->plc = param.setting.plc;
3779 obj->setting->reserved = param.setting.reserved;
3780 obj->setting->vad = param.setting.vad;
3781
3782 return Py_BuildValue("O", obj);
3783}
3784/*
3785 * py_pjsua_codec_set_param
3786 */
3787static PyObject *py_pjsua_codec_set_param
3788(PyObject *pSelf, PyObject *pArgs)
3789{
3790
3791 int status;
3792 PyObject * id;
3793 pj_str_t str;
3794 pjmedia_codec_param param;
Fahris6f35cb82007-02-01 07:41:26 +00003795 PyObject * tmpObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00003796 PyObj_pjmedia_codec_param *obj;
Fahrisdcf8fa42006-12-28 03:13:48 +00003797
Benny Prijono1f63cc42007-09-10 16:54:22 +00003798 PJ_UNUSED_ARG(pSelf);
3799
Fahris17d91812007-01-29 12:09:33 +00003800 if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00003801 {
3802 return NULL;
3803 }
Fahris17d91812007-01-29 12:09:33 +00003804
Fahrisdcf8fa42006-12-28 03:13:48 +00003805 str.ptr = PyString_AsString(id);
3806 str.slen = strlen(PyString_AsString(id));
Fahris17d91812007-01-29 12:09:33 +00003807 if (tmpObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00003808 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00003809 obj = (PyObj_pjmedia_codec_param *)tmpObj;
Fahris17d91812007-01-29 12:09:33 +00003810 param.info.avg_bps = obj->info->avg_bps;
3811 param.info.channel_cnt = obj->info->channel_cnt;
3812 param.info.clock_rate = obj->info->clock_rate;
3813 param.info.frm_ptime = obj->info->frm_ptime;
3814 param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample;
3815 param.info.pt = obj->info->pt;
3816 param.setting.cng = obj->setting->cng;
3817 param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode;
3818 param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode;
3819 param.setting.frm_per_pkt = obj->setting->frm_per_pkt;
3820 param.setting.penh = obj->setting->penh;
3821 param.setting.plc = obj->setting->plc;
3822 param.setting.reserved = obj->setting->reserved;
3823 param.setting.vad = obj->setting->vad;
3824 status = pjsua_codec_set_param(&str, &param);
3825 } else {
3826 status = pjsua_codec_set_param(&str, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00003827 }
Fahrisdcf8fa42006-12-28 03:13:48 +00003828 return Py_BuildValue("i", status);
3829}
3830
3831static char pjsua_conf_get_max_ports_doc[] =
3832 "int py_pjsua.conf_get_max_ports () "
3833 "Get maxinum number of conference ports.";
3834static char pjsua_conf_get_active_ports_doc[] =
3835 "int py_pjsua.conf_get_active_ports () "
3836 "Get current number of active ports in the bridge.";
3837static char pjsua_enum_conf_ports_doc[] =
3838 "int[] py_pjsua.enum_conf_ports () "
3839 "Enumerate all conference ports.";
3840static char pjsua_conf_get_port_info_doc[] =
3841 "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) "
3842 "Get information about the specified conference port";
3843static char pjsua_conf_add_port_doc[] =
3844 "int, int py_pjsua.conf_add_port "
Benny Prijono1f63cc42007-09-10 16:54:22 +00003845 "(py_pjsua.Pj_Pool pool, py_pjsua.PJMedia_Port port) "
Fahrisdcf8fa42006-12-28 03:13:48 +00003846 "Add arbitrary media port to PJSUA's conference bridge. "
3847 "Application can use this function to add the media port "
3848 "that it creates. For media ports that are created by PJSUA-LIB "
3849 "(such as calls, file player, or file recorder), PJSUA-LIB will "
3850 "automatically add the port to the bridge.";
3851static char pjsua_conf_remove_port_doc[] =
3852 "int py_pjsua.conf_remove_port (int id) "
3853 "Remove arbitrary slot from the conference bridge. "
3854 "Application should only call this function "
3855 "if it registered the port manually.";
3856static char pjsua_conf_connect_doc[] =
3857 "int py_pjsua.conf_connect (int source, int sink) "
3858 "Establish unidirectional media flow from souce to sink. "
3859 "One source may transmit to multiple destinations/sink. "
3860 "And if multiple sources are transmitting to the same sink, "
3861 "the media will be mixed together. Source and sink may refer "
3862 "to the same ID, effectively looping the media. "
3863 "If bidirectional media flow is desired, application "
3864 "needs to call this function twice, with the second "
3865 "one having the arguments reversed.";
3866static char pjsua_conf_disconnect_doc[] =
3867 "int py_pjsua.conf_disconnect (int source, int sink) "
3868 "Disconnect media flow from the source to destination port.";
3869static char pjsua_player_create_doc[] =
3870 "int, int py_pjsua.player_create (string filename, int options) "
3871 "Create a file player, and automatically connect "
3872 "this player to the conference bridge.";
3873static char pjsua_player_get_conf_port_doc[] =
3874 "int py_pjsua.player_get_conf_port (int) "
3875 "Get conference port ID associated with player.";
3876static char pjsua_player_set_pos_doc[] =
3877 "int py_pjsua.player_set_pos (int id, int samples) "
3878 "Set playback position.";
3879static char pjsua_player_destroy_doc[] =
3880 "int py_pjsua.player_destroy (int id) "
3881 "Close the file, remove the player from the bridge, "
3882 "and free resources associated with the file player.";
3883static char pjsua_recorder_create_doc[] =
3884 "int, int py_pjsua.recorder_create (string filename, "
3885 "int enc_type, int enc_param, int max_size, int options) "
3886 "Create a file recorder, and automatically connect this recorder "
3887 "to the conference bridge. The recorder currently supports recording "
3888 "WAV file, and on Windows, MP3 file. The type of the recorder to use "
3889 "is determined by the extension of the file (e.g. '.wav' or '.mp3').";
3890static char pjsua_recorder_get_conf_port_doc[] =
3891 "int py_pjsua.recorder_get_conf_port (int id) "
3892 "Get conference port associated with recorder.";
3893static char pjsua_recorder_destroy_doc[] =
3894 "int py_pjsua.recorder_destroy (int id) "
3895 "Destroy recorder (this will complete recording).";
3896static char pjsua_enum_snd_devs_doc[] =
3897 "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) "
3898 "Enum sound devices.";
3899static char pjsua_get_snd_dev_doc[] =
3900 "int, int py_pjsua.get_snd_dev () "
3901 "Get currently active sound devices. "
3902 "If sound devices has not been created "
3903 "(for example when pjsua_start() is not called), "
3904 "it is possible that the function returns "
3905 "PJ_SUCCESS with -1 as device IDs.";
3906static char pjsua_set_snd_dev_doc[] =
3907 "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) "
3908 "Select or change sound device. Application may call this function "
3909 "at any time to replace current sound device.";
3910static char pjsua_set_null_snd_dev_doc[] =
3911 "int py_pjsua.set_null_snd_dev () "
3912 "Set pjsua to use null sound device. The null sound device only "
3913 "provides the timing needed by the conference bridge, and will not "
3914 "interract with any hardware.";
3915static char pjsua_set_no_snd_dev_doc[] =
3916 "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () "
3917 "Disconnect the main conference bridge from any sound devices, "
3918 "and let application connect the bridge to it's "
3919 "own sound device/master port.";
3920static char pjsua_set_ec_doc[] =
3921 "int py_pjsua.set_ec (int tail_ms, int options) "
3922 "Configure the echo canceller tail length of the sound port.";
3923static char pjsua_get_ec_tail_doc[] =
3924 "int py_pjsua.get_ec_tail () "
3925 "Get current echo canceller tail length.";
3926static char pjsua_enum_codecs_doc[] =
3927 "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () "
3928 "Enum all supported codecs in the system.";
3929static char pjsua_codec_set_priority_doc[] =
3930 "int py_pjsua.codec_set_priority (string id, int priority) "
3931 "Change codec priority.";
3932static char pjsua_codec_get_param_doc[] =
3933 "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) "
3934 "Get codec parameters";
3935static char pjsua_codec_set_param_doc[] =
3936 "int py_pjsua.codec_set_param (string id, "
3937 "py_pjsua.PJMedia_Codec_Param param) "
3938 "Set codec parameters.";
3939
3940/* END OF LIB MEDIA */
3941
3942/* LIB CALL */
3943
3944/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003945 * PyObj_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003946 * PJ Time Val
3947 */
3948typedef struct
3949{
3950 PyObject_HEAD
3951 /* Type-specific fields go here. */
3952 long sec;
3953 long msec;
3954
Benny Prijono1f63cc42007-09-10 16:54:22 +00003955} PyObj_pj_time_val;
Fahrisdcf8fa42006-12-28 03:13:48 +00003956
3957
3958
3959/*
3960 * pj_time_val_members
3961 */
3962static PyMemberDef pj_time_val_members[] =
3963{
3964
3965 {
3966 "sec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003967 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003968 "The seconds part of the time"
3969 },
3970 {
3971 "msec", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00003972 offsetof(PyObj_pj_time_val, sec), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00003973 "The milliseconds fraction of the time"
3974 },
3975
3976
3977 {NULL} /* Sentinel */
3978};
3979
3980
3981
3982
3983/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00003984 * PyTyp_pj_time_val
Fahrisdcf8fa42006-12-28 03:13:48 +00003985 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00003986static PyTypeObject PyTyp_pj_time_val =
Fahrisdcf8fa42006-12-28 03:13:48 +00003987{
3988 PyObject_HEAD_INIT(NULL)
3989 0, /*ob_size*/
3990 "py_pjsua.PJ_Time_Val", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00003991 sizeof(PyObj_pj_time_val), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00003992 0, /*tp_itemsize*/
3993 0,/*tp_dealloc*/
3994 0, /*tp_print*/
3995 0, /*tp_getattr*/
3996 0, /*tp_setattr*/
3997 0, /*tp_compare*/
3998 0, /*tp_repr*/
3999 0, /*tp_as_number*/
4000 0, /*tp_as_sequence*/
4001 0, /*tp_as_mapping*/
4002 0, /*tp_hash */
4003 0, /*tp_call*/
4004 0, /*tp_str*/
4005 0, /*tp_getattro*/
4006 0, /*tp_setattro*/
4007 0, /*tp_as_buffer*/
4008 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4009 "PJ Time Val objects", /* tp_doc */
4010 0, /* tp_traverse */
4011 0, /* tp_clear */
4012 0, /* tp_richcompare */
4013 0, /* tp_weaklistoffset */
4014 0, /* tp_iter */
4015 0, /* tp_iternext */
4016 0, /* tp_methods */
4017 pj_time_val_members, /* tp_members */
4018
4019
4020};
4021
4022/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004023 * PyObj_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004024 * Call Info
4025 */
4026typedef struct
4027{
4028 PyObject_HEAD
4029 /* Type-specific fields go here. */
4030
4031 int id;
4032 int role;
4033 int acc_id;
4034 PyObject * local_info;
4035 PyObject * local_contact;
4036 PyObject * remote_info;
4037 PyObject * remote_contact;
4038 PyObject * call_id;
4039 int state;
4040 PyObject * state_text;
4041 int last_status;
4042 PyObject * last_status_text;
4043 int media_status;
4044 int media_dir;
4045 int conf_slot;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004046 PyObj_pj_time_val * connect_duration;
4047 PyObj_pj_time_val * total_duration;
Fahrisdcf8fa42006-12-28 03:13:48 +00004048 struct {
4049 char local_info[128];
4050 char local_contact[128];
4051 char remote_info[128];
4052 char remote_contact[128];
4053 char call_id[128];
4054 char last_status_text[128];
4055 } buf_;
4056
Benny Prijono1f63cc42007-09-10 16:54:22 +00004057} PyObj_pjsua_call_info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004058
4059
4060/*
4061 * call_info_dealloc
4062 * deletes a call_info from memory
4063 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004064static void call_info_dealloc(PyObj_pjsua_call_info* self)
Fahrisdcf8fa42006-12-28 03:13:48 +00004065{
4066 Py_XDECREF(self->local_info);
4067 Py_XDECREF(self->local_contact);
4068 Py_XDECREF(self->remote_info);
4069 Py_XDECREF(self->remote_contact);
4070 Py_XDECREF(self->call_id);
4071 Py_XDECREF(self->state_text);
4072 Py_XDECREF(self->last_status_text);
4073 Py_XDECREF(self->connect_duration);
4074 Py_XDECREF(self->total_duration);
4075 self->ob_type->tp_free((PyObject*)self);
4076}
4077
4078
4079/*
4080 * call_info_new
4081 * constructor for call_info object
4082 */
4083static PyObject * call_info_new(PyTypeObject *type, PyObject *args,
4084 PyObject *kwds)
4085{
Benny Prijono1f63cc42007-09-10 16:54:22 +00004086 PyObj_pjsua_call_info *self;
Fahrisdcf8fa42006-12-28 03:13:48 +00004087
Benny Prijono1f63cc42007-09-10 16:54:22 +00004088 PJ_UNUSED_ARG(args);
4089 PJ_UNUSED_ARG(kwds);
4090
4091 self = (PyObj_pjsua_call_info *)type->tp_alloc(type, 0);
Fahrisdcf8fa42006-12-28 03:13:48 +00004092 if (self != NULL)
4093 {
4094 self->local_info = PyString_FromString("");
4095 if (self->local_info == NULL)
4096 {
4097 Py_DECREF(self);
4098 return NULL;
4099 }
4100 self->local_contact = PyString_FromString("");
4101 if (self->local_contact == NULL)
4102 {
4103 Py_DECREF(self);
4104 return NULL;
4105 }
4106 self->remote_info = PyString_FromString("");
4107 if (self->remote_info == NULL)
4108 {
4109 Py_DECREF(self);
4110 return NULL;
4111 }
4112 self->remote_contact = PyString_FromString("");
4113 if (self->remote_contact == NULL)
4114 {
4115 Py_DECREF(self);
4116 return NULL;
4117 }
4118 self->call_id = PyString_FromString("");
4119 if (self->call_id == NULL)
4120 {
4121 Py_DECREF(self);
4122 return NULL;
4123 }
4124 self->state_text = PyString_FromString("");
4125 if (self->state_text == NULL)
4126 {
4127 Py_DECREF(self);
4128 return NULL;
4129 }
4130 self->last_status_text = PyString_FromString("");
4131 if (self->last_status_text == NULL)
4132 {
4133 Py_DECREF(self);
4134 return NULL;
4135 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004136 self->connect_duration = (PyObj_pj_time_val *)PyType_GenericNew
4137 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004138 if (self->connect_duration == NULL)
4139 {
4140 Py_DECREF(self);
4141 return NULL;
4142 }
Benny Prijono1f63cc42007-09-10 16:54:22 +00004143 self->total_duration = (PyObj_pj_time_val *)PyType_GenericNew
4144 (&PyTyp_pj_time_val,NULL,NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004145 if (self->total_duration == NULL)
4146 {
4147 Py_DECREF(self);
4148 return NULL;
4149 }
4150 }
4151 return (PyObject *)self;
4152}
4153
4154/*
4155 * call_info_members
4156 */
4157static PyMemberDef call_info_members[] =
4158{
4159 {
4160 "id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004161 offsetof(PyObj_pjsua_call_info, id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004162 "Call identification"
4163 },
4164 {
4165 "role", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004166 offsetof(PyObj_pjsua_call_info, role), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004167 "Initial call role (UAC == caller)"
4168 },
4169 {
4170 "acc_id", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004171 offsetof(PyObj_pjsua_call_info, acc_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004172 "The account ID where this call belongs."
4173 },
4174 {
4175 "local_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004176 offsetof(PyObj_pjsua_call_info, local_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004177 "Local URI"
4178 },
4179 {
4180 "local_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004181 offsetof(PyObj_pjsua_call_info, local_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004182 "Local Contact"
4183 },
4184 {
4185 "remote_info", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004186 offsetof(PyObj_pjsua_call_info, remote_info), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004187 "Remote URI"
4188 },
4189 {
4190 "remote_contact", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004191 offsetof(PyObj_pjsua_call_info, remote_contact), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004192 "Remote Contact"
4193 },
4194 {
4195 "call_id", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004196 offsetof(PyObj_pjsua_call_info, call_id), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004197 "Dialog Call-ID string"
4198 },
4199 {
4200 "state", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004201 offsetof(PyObj_pjsua_call_info, state), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004202 "Call state"
4203 },
4204 {
4205 "state_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004206 offsetof(PyObj_pjsua_call_info, state_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004207 "Text describing the state "
4208 },
4209 {
4210 "last_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004211 offsetof(PyObj_pjsua_call_info, last_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004212 "Last status code heard, which can be used as cause code"
4213 },
4214 {
4215 "last_status_text", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004216 offsetof(PyObj_pjsua_call_info, last_status_text), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004217 "The reason phrase describing the status."
4218 },
4219 {
4220 "media_status", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004221 offsetof(PyObj_pjsua_call_info, media_status), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004222 "Call media status."
4223 },
4224 {
4225 "media_dir", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004226 offsetof(PyObj_pjsua_call_info, media_dir), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004227 "Media direction"
4228 },
4229 {
4230 "conf_slot", T_INT,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004231 offsetof(PyObj_pjsua_call_info, conf_slot), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004232 "The conference port number for the call"
4233 },
4234 {
4235 "connect_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004236 offsetof(PyObj_pjsua_call_info, connect_duration), 0,
Fahris17d91812007-01-29 12:09:33 +00004237 "Up-to-date call connected duration(zero when call is not established)"
Fahrisdcf8fa42006-12-28 03:13:48 +00004238 },
4239 {
4240 "total_duration", T_OBJECT_EX,
Benny Prijono1f63cc42007-09-10 16:54:22 +00004241 offsetof(PyObj_pjsua_call_info, total_duration), 0,
Fahrisdcf8fa42006-12-28 03:13:48 +00004242 "Total call duration, including set-up time"
4243 },
4244
4245 {NULL} /* Sentinel */
4246};
4247
4248
4249
4250
4251/*
Benny Prijono1f63cc42007-09-10 16:54:22 +00004252 * PyTyp_pjsua_call_info
Fahrisdcf8fa42006-12-28 03:13:48 +00004253 */
Benny Prijono1f63cc42007-09-10 16:54:22 +00004254static PyTypeObject PyTyp_pjsua_call_info =
Fahrisdcf8fa42006-12-28 03:13:48 +00004255{
4256 PyObject_HEAD_INIT(NULL)
4257 0, /*ob_size*/
4258 "py_pjsua.Call_Info", /*tp_name*/
Benny Prijono1f63cc42007-09-10 16:54:22 +00004259 sizeof(PyObj_pjsua_call_info), /*tp_basicsize*/
Fahrisdcf8fa42006-12-28 03:13:48 +00004260 0, /*tp_itemsize*/
4261 (destructor)call_info_dealloc,/*tp_dealloc*/
4262 0, /*tp_print*/
4263 0, /*tp_getattr*/
4264 0, /*tp_setattr*/
4265 0, /*tp_compare*/
4266 0, /*tp_repr*/
4267 0, /*tp_as_number*/
4268 0, /*tp_as_sequence*/
4269 0, /*tp_as_mapping*/
4270 0, /*tp_hash */
4271 0, /*tp_call*/
4272 0, /*tp_str*/
4273 0, /*tp_getattro*/
4274 0, /*tp_setattro*/
4275 0, /*tp_as_buffer*/
4276 Py_TPFLAGS_DEFAULT, /*tp_flags*/
4277 "Call Info objects", /* tp_doc */
4278 0, /* tp_traverse */
4279 0, /* tp_clear */
4280 0, /* tp_richcompare */
4281 0, /* tp_weaklistoffset */
4282 0, /* tp_iter */
4283 0, /* tp_iternext */
4284 0, /* tp_methods */
4285 call_info_members, /* tp_members */
4286 0, /* tp_getset */
4287 0, /* tp_base */
4288 0, /* tp_dict */
4289 0, /* tp_descr_get */
4290 0, /* tp_descr_set */
4291 0, /* tp_dictoffset */
4292 0, /* tp_init */
4293 0, /* tp_alloc */
4294 call_info_new, /* tp_new */
4295
4296};
4297
4298/*
4299 * py_pjsua_call_get_max_count
4300 */
4301static PyObject *py_pjsua_call_get_max_count
4302(PyObject *pSelf, PyObject *pArgs)
4303{
4304 int count;
4305
Benny Prijono1f63cc42007-09-10 16:54:22 +00004306 PJ_UNUSED_ARG(pSelf);
4307
Fahrisdcf8fa42006-12-28 03:13:48 +00004308 if (!PyArg_ParseTuple(pArgs, ""))
4309 {
4310 return NULL;
4311 }
4312
4313 count = pjsua_call_get_max_count();
4314
4315
4316 return Py_BuildValue("i", count);
4317}
4318
4319/*
4320 * py_pjsua_call_get_count
4321 */
4322static PyObject *py_pjsua_call_get_count
4323(PyObject *pSelf, PyObject *pArgs)
4324{
4325
4326 int count;
4327
Benny Prijono1f63cc42007-09-10 16:54:22 +00004328 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004329
4330 if (!PyArg_ParseTuple(pArgs, ""))
4331 {
4332 return NULL;
4333 }
4334
4335 count = pjsua_call_get_count();
4336
4337
4338 return Py_BuildValue("i", count);
4339}
4340
4341/*
4342 * py_pjsua_enum_calls
4343 */
4344static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs)
4345{
4346 pj_status_t status;
4347 PyObject *list;
4348
4349 pjsua_transport_id id[PJSUA_MAX_CALLS];
Fahris17d91812007-01-29 12:09:33 +00004350 unsigned c, i;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004351
4352 PJ_UNUSED_ARG(pSelf);
4353
Fahrisdcf8fa42006-12-28 03:13:48 +00004354 if (!PyArg_ParseTuple(pArgs, ""))
4355 {
4356 return NULL;
4357 }
4358
4359 c = PJ_ARRAY_SIZE(id);
4360 status = pjsua_enum_calls(id, &c);
4361
4362 list = PyList_New(c);
4363 for (i = 0; i < c; i++)
4364 {
4365 int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i]));
4366 if (ret == -1)
4367 {
4368 return NULL;
4369 }
4370 }
4371
Fahrisdcf8fa42006-12-28 03:13:48 +00004372 return Py_BuildValue("O",list);
4373}
4374
4375/*
4376 * py_pjsua_call_make_call
4377 */
4378static PyObject *py_pjsua_call_make_call
4379(PyObject *pSelf, PyObject *pArgs)
4380{
4381 int status;
4382 int acc_id;
4383 pj_str_t dst_uri;
4384 PyObject * sd;
4385 unsigned options;
4386 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004387 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004388 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004389 int user_data;
4390 int call_id;
4391 pj_pool_t * pool;
4392
Benny Prijono1f63cc42007-09-10 16:54:22 +00004393 PJ_UNUSED_ARG(pSelf);
4394
Fahris17d91812007-01-29 12:09:33 +00004395 if (!PyArg_ParseTuple
4396 (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004397 {
4398 return NULL;
4399 }
4400
4401 dst_uri.ptr = PyString_AsString(sd);
4402 dst_uri.slen = strlen(PyString_AsString(sd));
Fahris6f35cb82007-02-01 07:41:26 +00004403 if (omdObj != Py_None)
4404 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004405 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004406 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4407 msg_data.content_type.slen = strlen
4408 (PyString_AsString(omd->content_type));
4409 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4410 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004411 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004412 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4413 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004414 options, (void*)user_data, &msg_data, &call_id);
Fahris17d91812007-01-29 12:09:33 +00004415 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004416 } else {
Fahris89ea3d02007-02-07 08:18:35 +00004417
Fahris17d91812007-01-29 12:09:33 +00004418 status = pjsua_call_make_call(acc_id, &dst_uri,
Benny Prijonoe6ead542007-01-31 20:53:31 +00004419 options, (void*)user_data, NULL, &call_id);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004420 }
Fahris89ea3d02007-02-07 08:18:35 +00004421
Fahrisdcf8fa42006-12-28 03:13:48 +00004422 return Py_BuildValue("ii",status, call_id);
Fahris89ea3d02007-02-07 08:18:35 +00004423
Fahrisdcf8fa42006-12-28 03:13:48 +00004424}
4425
4426/*
4427 * py_pjsua_call_is_active
4428 */
4429static PyObject *py_pjsua_call_is_active
4430(PyObject *pSelf, PyObject *pArgs)
4431{
4432 int call_id;
4433 int isActive;
4434
Benny Prijono1f63cc42007-09-10 16:54:22 +00004435 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004436
4437 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4438 {
4439 return NULL;
4440 }
4441
4442 isActive = pjsua_call_is_active(call_id);
4443
4444
4445 return Py_BuildValue("i", isActive);
4446}
4447
4448/*
4449 * py_pjsua_call_has_media
4450 */
4451static PyObject *py_pjsua_call_has_media
4452(PyObject *pSelf, PyObject *pArgs)
4453{
4454 int call_id;
4455 int hasMedia;
4456
Benny Prijono1f63cc42007-09-10 16:54:22 +00004457 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004458
4459 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4460 {
4461 return NULL;
4462 }
4463
4464 hasMedia = pjsua_call_has_media(call_id);
4465
4466
4467 return Py_BuildValue("i", hasMedia);
4468}
4469
4470/*
4471 * py_pjsua_call_get_conf_port
4472 */
4473static PyObject *py_pjsua_call_get_conf_port
4474(PyObject *pSelf, PyObject *pArgs)
4475{
4476 int call_id;
4477 int port_id;
4478
Benny Prijono1f63cc42007-09-10 16:54:22 +00004479 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004480
4481 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4482 {
4483 return NULL;
4484 }
4485
4486 port_id = pjsua_call_get_conf_port(call_id);
4487
4488
4489 return Py_BuildValue("i", port_id);
4490}
4491
4492/*
4493 * py_pjsua_call_get_info
4494 */
4495static PyObject *py_pjsua_call_get_info
4496(PyObject *pSelf, PyObject *pArgs)
4497{
4498 int call_id;
4499 int status;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004500 PyObj_pjsua_call_info * oi;
Fahrisdcf8fa42006-12-28 03:13:48 +00004501 pjsua_call_info info;
Fahrisdcf8fa42006-12-28 03:13:48 +00004502
Benny Prijono1f63cc42007-09-10 16:54:22 +00004503 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004504
4505 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4506 {
4507 return NULL;
4508 }
4509
4510
4511 status = pjsua_call_get_info(call_id, &info);
4512 if (status == PJ_SUCCESS)
4513 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004514 oi = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, NULL, NULL);
Fahrisdcf8fa42006-12-28 03:13:48 +00004515 oi->acc_id = info.acc_id;
Fahris6f35cb82007-02-01 07:41:26 +00004516 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id),
4517 "%.*s", (int)info.call_id.slen, info.call_id.ptr);
4518 pj_ansi_snprintf(oi->buf_.last_status_text,
4519 sizeof(oi->buf_.last_status_text),
4520 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr);
4521 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact),
4522 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr);
4523 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info),
4524 "%.*s", (int)info.local_info.slen, info.local_info.ptr);
4525 pj_ansi_snprintf(oi->buf_.remote_contact,
4526 sizeof(oi->buf_.remote_contact),
4527 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr);
4528 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info),
4529 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004530
Fahrisdcf8fa42006-12-28 03:13:48 +00004531 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr,
4532 info.call_id.slen);
4533 oi->conf_slot = info.conf_slot;
4534 oi->connect_duration->sec = info.connect_duration.sec;
4535 oi->connect_duration->msec = info.connect_duration.msec;
4536 oi->total_duration->sec = info.total_duration.sec;
4537 oi->total_duration->msec = info.total_duration.msec;
4538 oi->id = info.id;
4539 oi->last_status = info.last_status;
4540 oi->last_status_text = PyString_FromStringAndSize(
4541 info.last_status_text.ptr, info.last_status_text.slen);
4542 oi->local_contact = PyString_FromStringAndSize(
4543 info.local_contact.ptr, info.local_contact.slen);
4544 oi->local_info = PyString_FromStringAndSize(
4545 info.local_info.ptr, info.local_info.slen);
4546 oi->remote_contact = PyString_FromStringAndSize(
4547 info.remote_contact.ptr, info.remote_contact.slen);
4548 oi->remote_info = PyString_FromStringAndSize(
4549 info.remote_info.ptr, info.remote_info.slen);
4550 oi->media_dir = info.media_dir;
4551 oi->media_status = info.media_status;
4552 oi->role = info.role;
4553 oi->state = info.state;
4554 oi->state_text = PyString_FromStringAndSize(
4555 info.state_text.ptr, info.state_text.slen);
4556
4557 return Py_BuildValue("O", oi);
4558 } else {
4559 Py_INCREF(Py_None);
4560 return Py_None;
4561 }
4562}
4563
4564/*
4565 * py_pjsua_call_set_user_data
4566 */
4567static PyObject *py_pjsua_call_set_user_data
4568(PyObject *pSelf, PyObject *pArgs)
4569{
4570 int call_id;
4571 int user_data;
4572 int status;
4573
Benny Prijono1f63cc42007-09-10 16:54:22 +00004574 PJ_UNUSED_ARG(pSelf);
4575
Fahrisdcf8fa42006-12-28 03:13:48 +00004576 if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data))
4577 {
4578 return NULL;
4579 }
4580
Benny Prijonoe6ead542007-01-31 20:53:31 +00004581 status = pjsua_call_set_user_data(call_id, (void*)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004582
4583
4584 return Py_BuildValue("i", status);
4585}
4586
4587/*
4588 * py_pjsua_call_get_user_data
4589 */
4590static PyObject *py_pjsua_call_get_user_data
4591(PyObject *pSelf, PyObject *pArgs)
4592{
4593 int call_id;
Benny Prijonoe6ead542007-01-31 20:53:31 +00004594 void * user_data;
Fahrisdcf8fa42006-12-28 03:13:48 +00004595
Benny Prijono1f63cc42007-09-10 16:54:22 +00004596 PJ_UNUSED_ARG(pSelf);
Fahrisdcf8fa42006-12-28 03:13:48 +00004597
4598 if (!PyArg_ParseTuple(pArgs, "i", &call_id))
4599 {
4600 return NULL;
4601 }
4602
4603 user_data = pjsua_call_get_user_data(call_id);
4604
4605
Benny Prijonoe6ead542007-01-31 20:53:31 +00004606 return Py_BuildValue("i", (int)user_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004607}
4608
4609/*
4610 * py_pjsua_call_answer
4611 */
4612static PyObject *py_pjsua_call_answer
4613(PyObject *pSelf, PyObject *pArgs)
4614{
4615 int status;
4616 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004617 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004618 PyObject * sr;
4619 unsigned code;
4620 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004621 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004622 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004623 pj_pool_t * pool;
4624
Benny Prijono1f63cc42007-09-10 16:54:22 +00004625 PJ_UNUSED_ARG(pSelf);
4626
Fahris17d91812007-01-29 12:09:33 +00004627 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004628 {
4629 return NULL;
4630 }
Fahris6f35cb82007-02-01 07:41:26 +00004631 if (sr == Py_None)
4632 {
4633 reason = NULL;
4634 } else {
Fahrise314b882007-02-02 10:52:04 +00004635 reason = &tmp_reason;
4636 tmp_reason.ptr = PyString_AsString(sr);
4637 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004638 }
4639 if (omdObj != Py_None)
4640 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004641 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004642 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4643 msg_data.content_type.slen = strlen
4644 (PyString_AsString(omd->content_type));
4645 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4646 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004647 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004648 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4649
Fahris6f35cb82007-02-01 07:41:26 +00004650 status = pjsua_call_answer(call_id, code, reason, &msg_data);
Fahrisdcf8fa42006-12-28 03:13:48 +00004651
Fahris17d91812007-01-29 12:09:33 +00004652 pj_pool_release(pool);
4653 } else {
4654
Fahris89ea3d02007-02-07 08:18:35 +00004655 status = pjsua_call_answer(call_id, code, reason, NULL);
4656
Fahris6f35cb82007-02-01 07:41:26 +00004657 }
Fahrise314b882007-02-02 10:52:04 +00004658
Fahrisdcf8fa42006-12-28 03:13:48 +00004659 return Py_BuildValue("i",status);
4660}
4661
4662/*
4663 * py_pjsua_call_hangup
4664 */
4665static PyObject *py_pjsua_call_hangup
4666(PyObject *pSelf, PyObject *pArgs)
4667{
4668 int status;
4669 int call_id;
Fahrise314b882007-02-02 10:52:04 +00004670 pj_str_t * reason, tmp_reason;
Fahrisdcf8fa42006-12-28 03:13:48 +00004671 PyObject * sr;
4672 unsigned code;
4673 pjsua_msg_data msg_data;
Fahris6f35cb82007-02-01 07:41:26 +00004674 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004675 PyObj_pjsua_msg_data * omd;
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004676 pj_pool_t * pool = NULL;
Fahrisdcf8fa42006-12-28 03:13:48 +00004677
Benny Prijono1f63cc42007-09-10 16:54:22 +00004678 PJ_UNUSED_ARG(pSelf);
4679
Fahris17d91812007-01-29 12:09:33 +00004680 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004681 {
4682 return NULL;
4683 }
Benny Prijonoaa286042007-02-03 17:23:22 +00004684 if (sr == Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004685 {
4686 reason = NULL;
4687 } else {
Fahrise314b882007-02-02 10:52:04 +00004688 reason = &tmp_reason;
4689 tmp_reason.ptr = PyString_AsString(sr);
4690 tmp_reason.slen = strlen(PyString_AsString(sr));
Fahris6f35cb82007-02-01 07:41:26 +00004691 }
4692 if (omdObj != Py_None)
4693 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004694 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004695 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4696 msg_data.content_type.slen = strlen
4697 (PyString_AsString(omd->content_type));
4698 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4699 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004700 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004701 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
Fahris6f35cb82007-02-01 07:41:26 +00004702 status = pjsua_call_hangup(call_id, code, reason, &msg_data);
Fahris17d91812007-01-29 12:09:33 +00004703 pj_pool_release(pool);
Benny Prijonoed7a5a72007-01-29 18:36:38 +00004704 } else {
Fahris6f35cb82007-02-01 07:41:26 +00004705 status = pjsua_call_hangup(call_id, code, reason, NULL);
4706 }
Fahrise314b882007-02-02 10:52:04 +00004707
Fahrisdcf8fa42006-12-28 03:13:48 +00004708 return Py_BuildValue("i",status);
4709}
4710
4711/*
4712 * py_pjsua_call_set_hold
4713 */
4714static PyObject *py_pjsua_call_set_hold
4715(PyObject *pSelf, PyObject *pArgs)
4716{
4717 int status;
4718 int call_id;
4719 pjsua_msg_data msg_data;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004720 PyObject * omdObj;
4721 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004722 pj_pool_t * pool;
4723
Benny Prijono1f63cc42007-09-10 16:54:22 +00004724 PJ_UNUSED_ARG(pSelf);
4725
Fahris17d91812007-01-29 12:09:33 +00004726 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004727 {
4728 return NULL;
4729 }
Fahris17d91812007-01-29 12:09:33 +00004730
Fahris6f35cb82007-02-01 07:41:26 +00004731 if (omdObj != Py_None)
4732 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004733 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004734 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4735 msg_data.content_type.slen = strlen
4736 (PyString_AsString(omd->content_type));
4737 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4738 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004739 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004740 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4741 status = pjsua_call_set_hold(call_id, &msg_data);
4742 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004743 } else {
Fahris17d91812007-01-29 12:09:33 +00004744 status = pjsua_call_set_hold(call_id, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004745 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004746 return Py_BuildValue("i",status);
4747}
4748
4749/*
4750 * py_pjsua_call_reinvite
4751 */
4752static PyObject *py_pjsua_call_reinvite
4753(PyObject *pSelf, PyObject *pArgs)
4754{
4755 int status;
4756 int call_id;
4757 int unhold;
4758 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004759 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004760 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004761 pj_pool_t * pool;
4762
Benny Prijono1f63cc42007-09-10 16:54:22 +00004763 PJ_UNUSED_ARG(pSelf);
4764
Fahris17d91812007-01-29 12:09:33 +00004765 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004766 {
4767 return NULL;
4768 }
Fahris17d91812007-01-29 12:09:33 +00004769
4770 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004771 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004772 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004773 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4774 msg_data.content_type.slen = strlen
4775 (PyString_AsString(omd->content_type));
4776 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4777 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004778 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004779 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4780 status = pjsua_call_reinvite(call_id, unhold, &msg_data);
4781 pj_pool_release(pool);
4782 } else {
4783 status = pjsua_call_reinvite(call_id, unhold, NULL);
4784 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004785 return Py_BuildValue("i",status);
4786}
4787
4788/*
4789 * py_pjsua_call_xfer
4790 */
4791static PyObject *py_pjsua_call_xfer
4792(PyObject *pSelf, PyObject *pArgs)
4793{
4794 int status;
4795 int call_id;
4796 pj_str_t dest;
4797 PyObject * sd;
4798 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004799 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004800 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004801 pj_pool_t * pool;
4802
Benny Prijono1f63cc42007-09-10 16:54:22 +00004803 PJ_UNUSED_ARG(pSelf);
4804
Fahris17d91812007-01-29 12:09:33 +00004805 if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004806 {
4807 return NULL;
4808 }
4809
4810 dest.ptr = PyString_AsString(sd);
4811 dest.slen = strlen(PyString_AsString(sd));
4812
Fahris17d91812007-01-29 12:09:33 +00004813 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004814 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004815 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004816 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4817 msg_data.content_type.slen = strlen
4818 (PyString_AsString(omd->content_type));
4819 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4820 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004821 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004822 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4823 status = pjsua_call_xfer(call_id, &dest, &msg_data);
4824 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004825 } else {
Fahris17d91812007-01-29 12:09:33 +00004826 status = pjsua_call_xfer(call_id, &dest, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004827 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004828 return Py_BuildValue("i",status);
4829}
4830
4831/*
4832 * py_pjsua_call_xfer_replaces
4833 */
4834static PyObject *py_pjsua_call_xfer_replaces
4835(PyObject *pSelf, PyObject *pArgs)
4836{
4837 int status;
4838 int call_id;
4839 int dest_call_id;
4840 unsigned options;
4841 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004842 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004843 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004844 pj_pool_t * pool;
4845
Benny Prijono1f63cc42007-09-10 16:54:22 +00004846 PJ_UNUSED_ARG(pSelf);
4847
Fahris17d91812007-01-29 12:09:33 +00004848 if (!PyArg_ParseTuple
4849 (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004850 {
4851 return NULL;
4852 }
4853
Fahris17d91812007-01-29 12:09:33 +00004854 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004855 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004856 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004857 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4858 msg_data.content_type.slen = strlen
4859 (PyString_AsString(omd->content_type));
4860 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4861 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004862 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004863 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4864 status = pjsua_call_xfer_replaces
4865 (call_id, dest_call_id, options, &msg_data);
4866 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004867 } else {
Fahris17d91812007-01-29 12:09:33 +00004868 status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004869 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004870 return Py_BuildValue("i",status);
4871}
4872
4873/*
4874 * py_pjsua_call_dial_dtmf
4875 */
4876static PyObject *py_pjsua_call_dial_dtmf
4877(PyObject *pSelf, PyObject *pArgs)
4878{
4879 int call_id;
4880 PyObject * sd;
4881 pj_str_t digits;
4882 int status;
4883
Benny Prijono1f63cc42007-09-10 16:54:22 +00004884 PJ_UNUSED_ARG(pSelf);
4885
Fahrisdcf8fa42006-12-28 03:13:48 +00004886 if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd))
4887 {
4888 return NULL;
4889 }
4890 digits.ptr = PyString_AsString(sd);
4891 digits.slen = strlen(PyString_AsString(sd));
4892 status = pjsua_call_dial_dtmf(call_id, &digits);
4893
4894 return Py_BuildValue("i", status);
4895}
4896
4897/*
4898 * py_pjsua_call_send_im
4899 */
4900static PyObject *py_pjsua_call_send_im
4901(PyObject *pSelf, PyObject *pArgs)
4902{
4903 int status;
4904 int call_id;
Fahris6f35cb82007-02-01 07:41:26 +00004905 pj_str_t content;
Fahrise314b882007-02-02 10:52:04 +00004906 pj_str_t * mime_type, tmp_mime_type;
Fahrisdcf8fa42006-12-28 03:13:48 +00004907 PyObject * sm;
4908 PyObject * sc;
4909 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004910 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004911 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004912 int user_data;
4913 pj_pool_t * pool;
4914
Benny Prijono1f63cc42007-09-10 16:54:22 +00004915 PJ_UNUSED_ARG(pSelf);
4916
Fahris17d91812007-01-29 12:09:33 +00004917 if (!PyArg_ParseTuple
4918 (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data))
Fahrisdcf8fa42006-12-28 03:13:48 +00004919 {
4920 return NULL;
4921 }
Fahris6f35cb82007-02-01 07:41:26 +00004922 if (sm == Py_None)
4923 {
4924 mime_type = NULL;
4925 } else {
Fahrise314b882007-02-02 10:52:04 +00004926 mime_type = &tmp_mime_type;
4927 tmp_mime_type.ptr = PyString_AsString(sm);
4928 tmp_mime_type.slen = strlen(PyString_AsString(sm));
Fahris6f35cb82007-02-01 07:41:26 +00004929 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004930 content.ptr = PyString_AsString(sc);
4931 content.slen = strlen(PyString_AsString(sc));
4932
Fahris17d91812007-01-29 12:09:33 +00004933 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004934 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004935 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004936 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4937 msg_data.content_type.slen = strlen
4938 (PyString_AsString(omd->content_type));
4939 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4940 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004941 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004942 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4943 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004944 (call_id, mime_type, &content, &msg_data, (void *)user_data);
Fahris17d91812007-01-29 12:09:33 +00004945 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004946 } else {
Fahris17d91812007-01-29 12:09:33 +00004947 status = pjsua_call_send_im
Fahris6f35cb82007-02-01 07:41:26 +00004948 (call_id, mime_type, &content, NULL, (void *)user_data);
4949 }
Fahrise314b882007-02-02 10:52:04 +00004950
Fahrisdcf8fa42006-12-28 03:13:48 +00004951 return Py_BuildValue("i",status);
4952}
4953
4954/*
4955 * py_pjsua_call_send_typing_ind
4956 */
4957static PyObject *py_pjsua_call_send_typing_ind
4958(PyObject *pSelf, PyObject *pArgs)
4959{
4960 int status;
4961 int call_id;
4962 int is_typing;
4963 pjsua_msg_data msg_data;
Fahris17d91812007-01-29 12:09:33 +00004964 PyObject * omdObj;
Benny Prijono1f63cc42007-09-10 16:54:22 +00004965 PyObj_pjsua_msg_data * omd;
Fahrisdcf8fa42006-12-28 03:13:48 +00004966 pj_pool_t * pool;
4967
Benny Prijono1f63cc42007-09-10 16:54:22 +00004968 PJ_UNUSED_ARG(pSelf);
4969
Fahris17d91812007-01-29 12:09:33 +00004970 if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj))
Fahrisdcf8fa42006-12-28 03:13:48 +00004971 {
4972 return NULL;
4973 }
4974
Fahris17d91812007-01-29 12:09:33 +00004975 if (omdObj != Py_None)
Fahris6f35cb82007-02-01 07:41:26 +00004976 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00004977 omd = (PyObj_pjsua_msg_data *)omdObj;
Fahris17d91812007-01-29 12:09:33 +00004978 msg_data.content_type.ptr = PyString_AsString(omd->content_type);
4979 msg_data.content_type.slen = strlen
4980 (PyString_AsString(omd->content_type));
4981 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body);
4982 msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body));
Fahris6f35cb82007-02-01 07:41:26 +00004983 pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE);
Fahris17d91812007-01-29 12:09:33 +00004984 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list);
4985 status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data);
4986 pj_pool_release(pool);
Fahris6f35cb82007-02-01 07:41:26 +00004987 } else {
Fahris17d91812007-01-29 12:09:33 +00004988 status = pjsua_call_send_typing_ind(call_id, is_typing, NULL);
Fahris6f35cb82007-02-01 07:41:26 +00004989 }
Fahrisdcf8fa42006-12-28 03:13:48 +00004990 return Py_BuildValue("i",status);
4991}
4992
4993/*
4994 * py_pjsua_call_hangup_all
4995 */
4996static PyObject *py_pjsua_call_hangup_all
4997(PyObject *pSelf, PyObject *pArgs)
4998{
4999
Benny Prijono1f63cc42007-09-10 16:54:22 +00005000 PJ_UNUSED_ARG(pSelf);
5001
Fahrisdcf8fa42006-12-28 03:13:48 +00005002 if (!PyArg_ParseTuple(pArgs, ""))
5003 {
5004 return NULL;
5005 }
5006
5007 pjsua_call_hangup_all();
5008
5009 Py_INCREF(Py_None);
5010 return Py_None;
5011}
5012
5013/*
5014 * py_pjsua_call_dump
5015 */
5016static PyObject *py_pjsua_call_dump
5017(PyObject *pSelf, PyObject *pArgs)
5018{
5019 int call_id;
5020 int with_media;
5021 PyObject * sb;
5022 PyObject * si;
5023 char * buffer;
5024 char * indent;
5025 unsigned maxlen;
5026 int status;
5027
Benny Prijono1f63cc42007-09-10 16:54:22 +00005028 PJ_UNUSED_ARG(pSelf);
5029
Fahrisdcf8fa42006-12-28 03:13:48 +00005030 if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si))
5031 {
5032 return NULL;
5033 }
5034 buffer = (char *) malloc (maxlen * sizeof(char));
5035 indent = PyString_AsString(si);
5036
5037 status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent);
5038 sb = PyString_FromStringAndSize(buffer, maxlen);
Fahris6f35cb82007-02-01 07:41:26 +00005039 free(buffer);
Fahrisdcf8fa42006-12-28 03:13:48 +00005040 return Py_BuildValue("O", sb);
5041}
5042
Benny Prijonoda275f62007-02-18 23:49:14 +00005043
5044/*
5045 * py_pjsua_dump
5046 * Dump application states.
5047 */
5048static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs)
5049{
5050 unsigned old_decor;
5051 char buf[1024];
5052 int detail;
5053
Benny Prijono1f63cc42007-09-10 16:54:22 +00005054 PJ_UNUSED_ARG(pSelf);
5055
Benny Prijonoda275f62007-02-18 23:49:14 +00005056 if (!PyArg_ParseTuple(pArgs, "i", &detail))
5057 {
5058 return NULL;
5059 }
5060
5061 PJ_LOG(3,(THIS_FILE, "Start dumping application states:"));
5062
5063 old_decor = pj_log_get_decor();
5064 pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR));
5065
5066 if (detail)
5067 pj_dump_config();
5068
5069 pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail);
5070 pjmedia_endpt_dump(pjsua_get_pjmedia_endpt());
5071 pjsip_tsx_layer_dump(detail);
5072 pjsip_ua_dump(detail);
5073
5074
5075 /* Dump all invite sessions: */
5076 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:"));
5077
5078 if (pjsua_call_get_count() == 0) {
5079
5080 PJ_LOG(3,(THIS_FILE, " - no sessions -"));
5081
5082 } else {
5083 unsigned i, max;
5084
5085 max = pjsua_call_get_max_count();
5086 for (i=0; i<max; ++i) {
5087 if (pjsua_call_is_active(i)) {
5088 pjsua_call_dump(i, detail, buf, sizeof(buf), " ");
5089 PJ_LOG(3,(THIS_FILE, "%s", buf));
5090 }
5091 }
5092 }
5093
5094 /* Dump presence status */
5095 pjsua_pres_dump(detail);
5096
5097 pj_log_set_decor(old_decor);
5098 PJ_LOG(3,(THIS_FILE, "Dump complete"));
5099
5100 Py_INCREF(Py_None);
5101 return Py_None;
5102}
5103
5104
Fahrisdcf8fa42006-12-28 03:13:48 +00005105static char pjsua_call_get_max_count_doc[] =
5106 "int py_pjsua.call_get_max_count () "
5107 "Get maximum number of calls configured in pjsua.";
5108static char pjsua_call_get_count_doc[] =
5109 "int py_pjsua.call_get_count () "
5110 "Get number of currently active calls.";
5111static char pjsua_enum_calls_doc[] =
5112 "int[] py_pjsua.enum_calls () "
5113 "Get maximum number of calls configured in pjsua.";
5114static char pjsua_call_make_call_doc[] =
5115 "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options,"
5116 "int user_data, py_pjsua.Msg_Data msg_data) "
5117 "Make outgoing call to the specified URI using the specified account.";
5118static char pjsua_call_is_active_doc[] =
5119 "int py_pjsua.call_is_active (int call_id) "
5120 "Check if the specified call has active INVITE session and the INVITE "
5121 "session has not been disconnected.";
5122static char pjsua_call_has_media_doc[] =
5123 "int py_pjsua.call_has_media (int call_id) "
5124 "Check if call has an active media session.";
5125static char pjsua_call_get_conf_port_doc[] =
5126 "int py_pjsua.call_get_conf_port (int call_id) "
5127 "Get the conference port identification associated with the call.";
5128static char pjsua_call_get_info_doc[] =
5129 "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) "
5130 "Obtain detail information about the specified call.";
5131static char pjsua_call_set_user_data_doc[] =
5132 "int py_pjsua.call_set_user_data (int call_id, int user_data) "
5133 "Attach application specific data to the call.";
5134static char pjsua_call_get_user_data_doc[] =
5135 "int py_pjsua.call_get_user_data (int call_id) "
5136 "Get user data attached to the call.";
5137static char pjsua_call_answer_doc[] =
5138 "int py_pjsua.call_answer (int call_id, int code, string reason, "
5139 "py_pjsua.Msg_Data msg_data) "
5140 "Send response to incoming INVITE request.";
5141static char pjsua_call_hangup_doc[] =
5142 "int py_pjsua.call_hangup (int call_id, int code, string reason, "
5143 "py_pjsua.Msg_Data msg_data) "
5144 "Hangup call by using method that is appropriate according "
5145 "to the call state.";
5146static char pjsua_call_set_hold_doc[] =
5147 "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) "
5148 "Put the specified call on hold.";
5149static char pjsua_call_reinvite_doc[] =
5150 "int py_pjsua.call_reinvite (int call_id, int unhold, "
5151 "py_pjsua.Msg_Data msg_data) "
5152 "Send re-INVITE (to release hold).";
5153static char pjsua_call_xfer_doc[] =
5154 "int py_pjsua.call_xfer (int call_id, string dest, "
5155 "py_pjsua.Msg_Data msg_data) "
5156 "Initiate call transfer to the specified address. "
5157 "This function will send REFER request to instruct remote call party "
5158 "to initiate a new INVITE session to the specified destination/target.";
5159static char pjsua_call_xfer_replaces_doc[] =
5160 "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, "
5161 "int options, py_pjsua.Msg_Data msg_data) "
5162 "Initiate attended call transfer. This function will send REFER request "
5163 "to instruct remote call party to initiate new INVITE session to the URL "
5164 "of dest_call_id. The party at dest_call_id then should 'replace' the call"
5165 "with us with the new call from the REFER recipient.";
5166static char pjsua_call_dial_dtmf_doc[] =
5167 "int py_pjsua.call_dial_dtmf (int call_id, string digits) "
5168 "Send DTMF digits to remote using RFC 2833 payload formats.";
5169static char pjsua_call_send_im_doc[] =
5170 "int py_pjsua.call_send_im (int call_id, string mime_type, string content,"
5171 "py_pjsua.Msg_Data msg_data, int user_data) "
5172 "Send instant messaging inside INVITE session.";
5173static char pjsua_call_send_typing_ind_doc[] =
5174 "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, "
5175 "py_pjsua.Msg_Data msg_data) "
5176 "Send IM typing indication inside INVITE session.";
5177static char pjsua_call_hangup_all_doc[] =
5178 "void py_pjsua.call_hangup_all () "
5179 "Terminate all calls.";
5180static char pjsua_call_dump_doc[] =
5181 "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, "
5182 "string indent) "
5183 "Dump call and media statistics to string.";
5184
5185/* END OF LIB CALL */
5186
Benny Prijono572d4852006-11-23 21:50:02 +00005187/*
5188 * Map of function names to functions
5189 */
5190static PyMethodDef py_pjsua_methods[] =
5191{
5192 {
Benny Prijonodc308702006-12-09 00:39:42 +00005193 "thread_register", py_pjsua_thread_register, METH_VARARGS,
5194 pjsua_thread_register_doc
Benny Prijono98793592006-12-04 08:33:20 +00005195 },
5196 {
Benny Prijono572d4852006-11-23 21:50:02 +00005197 "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc
5198 },
5199 {
5200 "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc
5201 },
5202 {
5203 "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc
5204 },
5205 {
5206 "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc
5207 },
5208 {
5209 "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc
5210 },
5211 {
5212 "handle_events", py_pjsua_handle_events, METH_VARARGS,
5213 pjsua_handle_events_doc
5214 },
5215 {
5216 "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS,
5217 pjsua_verify_sip_url_doc
5218 },
5219 {
5220 "pool_create", py_pjsua_pool_create, METH_VARARGS,
5221 pjsua_pool_create_doc
5222 },
5223 {
5224 "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS,
5225 pjsua_get_pjsip_endpt_doc
5226 },
5227 {
5228 "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS,
5229 pjsua_get_pjmedia_endpt_doc
5230 },
5231 {
5232 "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS,
5233 pjsua_get_pool_factory_doc
5234 },
5235 {
5236 "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS,
5237 pjsua_reconfigure_logging_doc
5238 },
5239 {
5240 "logging_config_default", py_pjsua_logging_config_default,
5241 METH_VARARGS, pjsua_logging_config_default_doc
5242 },
5243 {
5244 "config_default", py_pjsua_config_default, METH_VARARGS,
5245 pjsua_config_default_doc
5246 },
5247 {
5248 "media_config_default", py_pjsua_media_config_default, METH_VARARGS,
5249 pjsua_media_config_default_doc
5250 },
Benny Prijonodc308702006-12-09 00:39:42 +00005251
5252
Benny Prijono572d4852006-11-23 21:50:02 +00005253 {
5254 "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS,
5255 pjsua_msg_data_init_doc
5256 },
Benny Prijonodc308702006-12-09 00:39:42 +00005257 {
Benny Prijonodc308702006-12-09 00:39:42 +00005258 "transport_config_default", py_pjsua_transport_config_default,
5259 METH_VARARGS,pjsua_transport_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005260 },
Benny Prijonodc308702006-12-09 00:39:42 +00005261 {
Benny Prijonodc308702006-12-09 00:39:42 +00005262 "transport_create", py_pjsua_transport_create, METH_VARARGS,
5263 pjsua_transport_create_doc
Benny Prijono98793592006-12-04 08:33:20 +00005264 },
Benny Prijonodc308702006-12-09 00:39:42 +00005265 {
Benny Prijonodc308702006-12-09 00:39:42 +00005266 "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS,
5267 pjsua_enum_transports_doc
Benny Prijono98793592006-12-04 08:33:20 +00005268 },
Benny Prijonodc308702006-12-09 00:39:42 +00005269 {
5270 "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS,
5271 pjsua_transport_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005272 },
Benny Prijonodc308702006-12-09 00:39:42 +00005273 {
5274 "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS,
5275 pjsua_transport_set_enable_doc
Benny Prijono98793592006-12-04 08:33:20 +00005276 },
Benny Prijonodc308702006-12-09 00:39:42 +00005277 {
5278 "transport_close", py_pjsua_transport_close, METH_VARARGS,
5279 pjsua_transport_close_doc
Benny Prijono98793592006-12-04 08:33:20 +00005280 },
Benny Prijonodc308702006-12-09 00:39:42 +00005281 {
5282 "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS,
5283 pjsua_acc_config_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005284 },
Benny Prijonodc308702006-12-09 00:39:42 +00005285 {
5286 "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS,
5287 pjsua_acc_get_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005288 },
Benny Prijonodc308702006-12-09 00:39:42 +00005289 {
5290 "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS,
5291 pjsua_acc_is_valid_doc
Benny Prijono98793592006-12-04 08:33:20 +00005292 },
Benny Prijonodc308702006-12-09 00:39:42 +00005293 {
5294 "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS,
5295 pjsua_acc_set_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005296 },
Benny Prijonodc308702006-12-09 00:39:42 +00005297 {
5298 "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS,
5299 pjsua_acc_get_default_doc
Benny Prijono98793592006-12-04 08:33:20 +00005300 },
Benny Prijonodc308702006-12-09 00:39:42 +00005301 {
5302 "acc_add", py_pjsua_acc_add, METH_VARARGS,
5303 pjsua_acc_add_doc
Benny Prijono98793592006-12-04 08:33:20 +00005304 },
Benny Prijonodc308702006-12-09 00:39:42 +00005305 {
5306 "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS,
5307 pjsua_acc_add_local_doc
Benny Prijono98793592006-12-04 08:33:20 +00005308 },
Benny Prijonodc308702006-12-09 00:39:42 +00005309 {
5310 "acc_del", py_pjsua_acc_del, METH_VARARGS,
5311 pjsua_acc_del_doc
Benny Prijono98793592006-12-04 08:33:20 +00005312 },
Benny Prijonodc308702006-12-09 00:39:42 +00005313 {
5314 "acc_modify", py_pjsua_acc_modify, METH_VARARGS,
5315 pjsua_acc_modify_doc
Benny Prijono98793592006-12-04 08:33:20 +00005316 },
Benny Prijonodc308702006-12-09 00:39:42 +00005317 {
5318 "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS,
5319 pjsua_acc_set_online_status_doc
Benny Prijono98793592006-12-04 08:33:20 +00005320 },
Benny Prijonodc308702006-12-09 00:39:42 +00005321 {
Benny Prijono1f63cc42007-09-10 16:54:22 +00005322 "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS,
5323 pjsua_acc_set_online_status2_doc
5324 },
5325 {
Benny Prijonodc308702006-12-09 00:39:42 +00005326 "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS,
5327 pjsua_acc_set_registration_doc
Benny Prijono98793592006-12-04 08:33:20 +00005328 },
Benny Prijonodc308702006-12-09 00:39:42 +00005329 {
5330 "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS,
5331 pjsua_acc_get_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005332 },
Benny Prijonodc308702006-12-09 00:39:42 +00005333 {
5334 "enum_accs", py_pjsua_enum_accs, METH_VARARGS,
5335 pjsua_enum_accs_doc
Benny Prijono98793592006-12-04 08:33:20 +00005336 },
Benny Prijonodc308702006-12-09 00:39:42 +00005337 {
5338 "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS,
5339 pjsua_acc_enum_info_doc
Benny Prijono98793592006-12-04 08:33:20 +00005340 },
Benny Prijonodc308702006-12-09 00:39:42 +00005341 {
5342 "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS,
5343 pjsua_acc_find_for_outgoing_doc
Benny Prijono98793592006-12-04 08:33:20 +00005344 },
Benny Prijonodc308702006-12-09 00:39:42 +00005345 {
5346 "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS,
5347 pjsua_acc_find_for_incoming_doc
Benny Prijono98793592006-12-04 08:33:20 +00005348 },
Benny Prijonodc308702006-12-09 00:39:42 +00005349 {
5350 "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS,
5351 pjsua_acc_create_uac_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005352 },
Benny Prijonodc308702006-12-09 00:39:42 +00005353 {
5354 "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS,
5355 pjsua_acc_create_uas_contact_doc
Benny Prijono98793592006-12-04 08:33:20 +00005356 },
Benny Prijonodc308702006-12-09 00:39:42 +00005357 {
Fahris6f35cb82007-02-01 07:41:26 +00005358 "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS,
5359 pjsua_buddy_config_default_doc
5360 },
5361 {
Benny Prijonodc308702006-12-09 00:39:42 +00005362 "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS,
5363 pjsua_get_buddy_count_doc
Benny Prijono98793592006-12-04 08:33:20 +00005364 },
Benny Prijonodc308702006-12-09 00:39:42 +00005365 {
5366 "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS,
5367 pjsua_buddy_is_valid_doc
5368 },
5369 {
5370 "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS,
5371 pjsua_enum_buddies_doc
Fahris6f35cb82007-02-01 07:41:26 +00005372 },
Benny Prijonodc308702006-12-09 00:39:42 +00005373 {
5374 "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS,
5375 pjsua_buddy_get_info_doc
5376 },
5377 {
5378 "buddy_add", py_pjsua_buddy_add, METH_VARARGS,
5379 pjsua_buddy_add_doc
5380 },
5381 {
5382 "buddy_del", py_pjsua_buddy_del, METH_VARARGS,
5383 pjsua_buddy_del_doc
5384 },
5385 {
5386 "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS,
5387 pjsua_buddy_subscribe_pres_doc
5388 },
5389 {
5390 "pres_dump", py_pjsua_pres_dump, METH_VARARGS,
5391 pjsua_pres_dump_doc
5392 },
5393 {
5394 "im_send", py_pjsua_im_send, METH_VARARGS,
5395 pjsua_im_send_doc
5396 },
5397 {
5398 "im_typing", py_pjsua_im_typing, METH_VARARGS,
5399 pjsua_im_typing_doc
5400 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005401 {
5402 "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS,
5403 pjsua_conf_get_max_ports_doc
5404 },
5405 {
5406 "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS,
5407 pjsua_conf_get_active_ports_doc
5408 },
5409 {
5410 "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS,
5411 pjsua_enum_conf_ports_doc
5412 },
5413 {
5414 "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS,
5415 pjsua_conf_get_port_info_doc
5416 },
5417 {
5418 "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS,
5419 pjsua_conf_add_port_doc
5420 },
5421 {
5422 "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS,
5423 pjsua_conf_remove_port_doc
5424 },
5425 {
5426 "conf_connect", py_pjsua_conf_connect, METH_VARARGS,
5427 pjsua_conf_connect_doc
5428 },
5429 {
5430 "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS,
5431 pjsua_conf_disconnect_doc
5432 },
5433 {
5434 "player_create", py_pjsua_player_create, METH_VARARGS,
5435 pjsua_player_create_doc
5436 },
5437 {
5438 "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS,
5439 pjsua_player_get_conf_port_doc
5440 },
5441 {
5442 "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS,
5443 pjsua_player_set_pos_doc
5444 },
5445 {
5446 "player_destroy", py_pjsua_player_destroy, METH_VARARGS,
5447 pjsua_player_destroy_doc
5448 },
5449 {
5450 "recorder_create", py_pjsua_recorder_create, METH_VARARGS,
5451 pjsua_recorder_create_doc
5452 },
5453 {
5454 "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS,
5455 pjsua_recorder_get_conf_port_doc
5456 },
5457 {
5458 "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS,
5459 pjsua_recorder_destroy_doc
5460 },
5461 {
5462 "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS,
5463 pjsua_enum_snd_devs_doc
5464 },
Benny Prijonoebdf8772007-02-01 19:25:50 +00005465 {
Fahrisdcf8fa42006-12-28 03:13:48 +00005466 "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS,
5467 pjsua_get_snd_dev_doc
Benny Prijonoebdf8772007-02-01 19:25:50 +00005468 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005469 {
5470 "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS,
5471 pjsua_set_snd_dev_doc
5472 },
5473 {
5474 "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS,
5475 pjsua_set_null_snd_dev_doc
5476 },
5477 {
5478 "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS,
5479 pjsua_set_no_snd_dev_doc
5480 },
5481 {
5482 "set_ec", py_pjsua_set_ec, METH_VARARGS,
5483 pjsua_set_ec_doc
5484 },
5485 {
5486 "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS,
5487 pjsua_get_ec_tail_doc
5488 },
5489 {
5490 "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS,
5491 pjsua_enum_codecs_doc
5492 },
5493 {
5494 "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS,
5495 pjsua_codec_set_priority_doc
5496 },
5497 {
5498 "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS,
5499 pjsua_codec_get_param_doc
5500 },
5501 {
5502 "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS,
5503 pjsua_codec_set_param_doc
5504 },
5505 {
5506 "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS,
5507 pjsua_call_get_max_count_doc
5508 },
5509 {
5510 "call_get_count", py_pjsua_call_get_count, METH_VARARGS,
5511 pjsua_call_get_count_doc
5512 },
5513 {
5514 "enum_calls", py_pjsua_enum_calls, METH_VARARGS,
5515 pjsua_enum_calls_doc
5516 },
5517 {
5518 "call_make_call", py_pjsua_call_make_call, METH_VARARGS,
5519 pjsua_call_make_call_doc
5520 },
5521 {
5522 "call_is_active", py_pjsua_call_is_active, METH_VARARGS,
5523 pjsua_call_is_active_doc
5524 },
5525 {
5526 "call_has_media", py_pjsua_call_has_media, METH_VARARGS,
5527 pjsua_call_has_media_doc
5528 },
5529 {
5530 "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS,
5531 pjsua_call_get_conf_port_doc
5532 },
5533 {
5534 "call_get_info", py_pjsua_call_get_info, METH_VARARGS,
5535 pjsua_call_get_info_doc
5536 },
5537 {
5538 "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS,
5539 pjsua_call_set_user_data_doc
5540 },
5541 {
5542 "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS,
5543 pjsua_call_get_user_data_doc
5544 },
5545 {
5546 "call_answer", py_pjsua_call_answer, METH_VARARGS,
5547 pjsua_call_answer_doc
5548 },
5549 {
5550 "call_hangup", py_pjsua_call_hangup, METH_VARARGS,
5551 pjsua_call_hangup_doc
5552 },
5553 {
5554 "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS,
5555 pjsua_call_set_hold_doc
5556 },
5557 {
5558 "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS,
5559 pjsua_call_reinvite_doc
5560 },
5561 {
5562 "call_xfer", py_pjsua_call_xfer, METH_VARARGS,
5563 pjsua_call_xfer_doc
5564 },
5565 {
5566 "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS,
5567 pjsua_call_xfer_replaces_doc
5568 },
5569 {
5570 "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS,
5571 pjsua_call_dial_dtmf_doc
5572 },
5573 {
5574 "call_send_im", py_pjsua_call_send_im, METH_VARARGS,
5575 pjsua_call_send_im_doc
5576 },
5577 {
5578 "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS,
5579 pjsua_call_send_typing_ind_doc
5580 },
5581 {
5582 "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS,
5583 pjsua_call_hangup_all_doc
5584 },
5585 {
5586 "call_dump", py_pjsua_call_dump, METH_VARARGS,
5587 pjsua_call_dump_doc
5588 },
Benny Prijonoda275f62007-02-18 23:49:14 +00005589 {
5590 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state"
5591 },
Fahrisdcf8fa42006-12-28 03:13:48 +00005592
Benny Prijonodc308702006-12-09 00:39:42 +00005593
Benny Prijono572d4852006-11-23 21:50:02 +00005594 {NULL, NULL} /* end of function list */
5595};
5596
5597
5598
5599/*
5600 * Mapping C structs from and to Python objects & initializing object
5601 */
5602DL_EXPORT(void)
Benny Prijono8b8b9972006-11-16 11:18:03 +00005603initpy_pjsua(void)
5604{
Benny Prijono572d4852006-11-23 21:50:02 +00005605 PyObject* m = NULL;
Benny Prijonoaa286042007-02-03 17:23:22 +00005606#define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name)
Benny Prijono572d4852006-11-23 21:50:02 +00005607
Benny Prijonodc308702006-12-09 00:39:42 +00005608
Benny Prijonoda275f62007-02-18 23:49:14 +00005609 PyEval_InitThreads();
5610
Benny Prijono1f63cc42007-09-10 16:54:22 +00005611 if (PyType_Ready(&PyTyp_pjsua_callback) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005612 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005613 if (PyType_Ready(&PyTyp_pjsua_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005614 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005615 if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005616 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005617 if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005618 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005619 PyTyp_pjsua_media_config.tp_new = PyType_GenericNew;
5620 if (PyType_Ready(&PyTyp_pjsua_media_config) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005621 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005622 PyTyp_pjsip_event.tp_new = PyType_GenericNew;
5623 if (PyType_Ready(&PyTyp_pjsip_event) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005624 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005625 PyTyp_pjsip_rx_data.tp_new = PyType_GenericNew;
5626 if (PyType_Ready(&PyTyp_pjsip_rx_data) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005627 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005628 PyTyp_pj_pool_t.tp_new = PyType_GenericNew;
5629 if (PyType_Ready(&PyTyp_pj_pool_t) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005630 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005631 PyTyp_pjsip_endpoint.tp_new = PyType_GenericNew;
5632 if (PyType_Ready(&PyTyp_pjsip_endpoint) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005633 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005634 PyTyp_pjmedia_endpt.tp_new = PyType_GenericNew;
5635 if (PyType_Ready(&PyTyp_pjmedia_endpt) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005636 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005637 PyTyp_pj_pool_factory.tp_new = PyType_GenericNew;
5638 if (PyType_Ready(&PyTyp_pj_pool_factory) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005639 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005640 PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew;
5641 if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0)
Benny Prijono572d4852006-11-23 21:50:02 +00005642 return;
5643
Benny Prijonodc308702006-12-09 00:39:42 +00005644 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005645
Benny Prijono1f63cc42007-09-10 16:54:22 +00005646 if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005647 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005648
Benny Prijono1f63cc42007-09-10 16:54:22 +00005649 if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005650 return;
Benny Prijonodc308702006-12-09 00:39:42 +00005651
Benny Prijonodc308702006-12-09 00:39:42 +00005652 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005653
Benny Prijonodc308702006-12-09 00:39:42 +00005654 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005655
Benny Prijonodc308702006-12-09 00:39:42 +00005656
Benny Prijono1f63cc42007-09-10 16:54:22 +00005657 if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005658 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005659 if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0)
Benny Prijono98793592006-12-04 08:33:20 +00005660 return;
5661
Benny Prijonodc308702006-12-09 00:39:42 +00005662 /* END OF LIB ACCOUNT */
5663
5664 /* LIB BUDDY */
5665
Benny Prijono1f63cc42007-09-10 16:54:22 +00005666 if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005667 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005668 if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0)
Benny Prijonodc308702006-12-09 00:39:42 +00005669 return;
5670
5671 /* END OF LIB BUDDY */
5672
Fahrisdcf8fa42006-12-28 03:13:48 +00005673 /* LIB MEDIA */
5674
Benny Prijono1f63cc42007-09-10 16:54:22 +00005675 if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005676 return;
5677
Benny Prijono1f63cc42007-09-10 16:54:22 +00005678 if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005679 return;
5680
Benny Prijono1f63cc42007-09-10 16:54:22 +00005681 PyTyp_pjmedia_port.tp_new = PyType_GenericNew;
5682 if (PyType_Ready(&PyTyp_pjmedia_port) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005683 return;
5684
Benny Prijono1f63cc42007-09-10 16:54:22 +00005685 if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005686 return;
5687
Benny Prijono1f63cc42007-09-10 16:54:22 +00005688 PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew;
5689 if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005690 return;
Benny Prijono1f63cc42007-09-10 16:54:22 +00005691 PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew;
5692 if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005693 return;
5694
Benny Prijono1f63cc42007-09-10 16:54:22 +00005695 if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005696 return;
5697
5698 /* END OF LIB MEDIA */
5699
5700 /* LIB CALL */
5701
Benny Prijono1f63cc42007-09-10 16:54:22 +00005702 PyTyp_pj_time_val.tp_new = PyType_GenericNew;
5703 if (PyType_Ready(&PyTyp_pj_time_val) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005704 return;
5705
Benny Prijono1f63cc42007-09-10 16:54:22 +00005706 if (PyType_Ready(&PyTyp_pjsua_call_info) < 0)
Fahrisdcf8fa42006-12-28 03:13:48 +00005707 return;
5708
5709 /* END OF LIB CALL */
Benny Prijono98793592006-12-04 08:33:20 +00005710
Benny Prijono572d4852006-11-23 21:50:02 +00005711 m = Py_InitModule3(
5712 "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python"
5713 );
5714
Benny Prijono1f63cc42007-09-10 16:54:22 +00005715 Py_INCREF(&PyTyp_pjsua_callback);
5716 PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback);
Benny Prijono572d4852006-11-23 21:50:02 +00005717
Benny Prijono1f63cc42007-09-10 16:54:22 +00005718 Py_INCREF(&PyTyp_pjsua_config);
5719 PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005720
Benny Prijono1f63cc42007-09-10 16:54:22 +00005721 Py_INCREF(&PyTyp_pjsua_media_config);
5722 PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005723
Benny Prijono1f63cc42007-09-10 16:54:22 +00005724 Py_INCREF(&PyTyp_pjsua_logging_config);
5725 PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config);
Benny Prijono572d4852006-11-23 21:50:02 +00005726
Benny Prijono1f63cc42007-09-10 16:54:22 +00005727 Py_INCREF(&PyTyp_pjsua_msg_data);
5728 PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005729
Benny Prijono1f63cc42007-09-10 16:54:22 +00005730 Py_INCREF(&PyTyp_pjsip_event);
5731 PyModule_AddObject(m, "Pjsip_Event", (PyObject *)&PyTyp_pjsip_event);
Benny Prijono572d4852006-11-23 21:50:02 +00005732
Benny Prijono1f63cc42007-09-10 16:54:22 +00005733 Py_INCREF(&PyTyp_pjsip_rx_data);
5734 PyModule_AddObject(m, "Pjsip_Rx_Data", (PyObject *)&PyTyp_pjsip_rx_data);
Benny Prijono572d4852006-11-23 21:50:02 +00005735
Benny Prijono1f63cc42007-09-10 16:54:22 +00005736 Py_INCREF(&PyTyp_pj_pool_t);
5737 PyModule_AddObject(m, "Pj_Pool", (PyObject *)&PyTyp_pj_pool_t);
Benny Prijono572d4852006-11-23 21:50:02 +00005738
Benny Prijono1f63cc42007-09-10 16:54:22 +00005739 Py_INCREF(&PyTyp_pjsip_endpoint);
5740 PyModule_AddObject(m, "Pjsip_Endpoint", (PyObject *)&PyTyp_pjsip_endpoint);
Benny Prijono572d4852006-11-23 21:50:02 +00005741
Benny Prijono1f63cc42007-09-10 16:54:22 +00005742 Py_INCREF(&PyTyp_pjmedia_endpt);
5743 PyModule_AddObject(m, "Pjmedia_Endpt", (PyObject *)&PyTyp_pjmedia_endpt);
Benny Prijono572d4852006-11-23 21:50:02 +00005744
Benny Prijono1f63cc42007-09-10 16:54:22 +00005745 Py_INCREF(&PyTyp_pj_pool_factory);
Benny Prijono572d4852006-11-23 21:50:02 +00005746 PyModule_AddObject(
Benny Prijono1f63cc42007-09-10 16:54:22 +00005747 m, "Pj_Pool_Factory", (PyObject *)&PyTyp_pj_pool_factory
Benny Prijono572d4852006-11-23 21:50:02 +00005748 );
5749
Benny Prijono1f63cc42007-09-10 16:54:22 +00005750 Py_INCREF(&PyTyp_pjsip_cred_info);
5751 PyModule_AddObject(m, "Pjsip_Cred_Info",
5752 (PyObject *)&PyTyp_pjsip_cred_info
Benny Prijono572d4852006-11-23 21:50:02 +00005753 );
5754
Benny Prijonodc308702006-12-09 00:39:42 +00005755 /* LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005756
Benny Prijono1f63cc42007-09-10 16:54:22 +00005757 Py_INCREF(&PyTyp_pjsua_transport_config);
Benny Prijono98793592006-12-04 08:33:20 +00005758 PyModule_AddObject
Benny Prijono1f63cc42007-09-10 16:54:22 +00005759 (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config);
Benny Prijonodc308702006-12-09 00:39:42 +00005760
Benny Prijono1f63cc42007-09-10 16:54:22 +00005761 Py_INCREF(&PyTyp_pjsua_transport_info);
5762 PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005763
Benny Prijono98793592006-12-04 08:33:20 +00005764
Benny Prijonodc308702006-12-09 00:39:42 +00005765 /* END OF LIB TRANSPORT */
Benny Prijono98793592006-12-04 08:33:20 +00005766
Benny Prijonodc308702006-12-09 00:39:42 +00005767 /* LIB ACCOUNT */
Benny Prijono98793592006-12-04 08:33:20 +00005768
Benny Prijonodc308702006-12-09 00:39:42 +00005769
Benny Prijono1f63cc42007-09-10 16:54:22 +00005770 Py_INCREF(&PyTyp_pjsua_acc_config);
5771 PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config);
5772 Py_INCREF(&PyTyp_pjsua_acc_info);
5773 PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info);
Benny Prijono98793592006-12-04 08:33:20 +00005774
Benny Prijonodc308702006-12-09 00:39:42 +00005775 /* END OF LIB ACCOUNT */
5776
5777 /* LIB BUDDY */
5778
Benny Prijono1f63cc42007-09-10 16:54:22 +00005779 Py_INCREF(&PyTyp_pjsua_buddy_config);
5780 PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config);
5781 Py_INCREF(&PyTyp_pjsua_buddy_info);
5782 PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info);
Benny Prijonodc308702006-12-09 00:39:42 +00005783
5784 /* END OF LIB BUDDY */
5785
Fahrisdcf8fa42006-12-28 03:13:48 +00005786 /* LIB MEDIA */
5787
Benny Prijono1f63cc42007-09-10 16:54:22 +00005788 Py_INCREF(&PyTyp_pjsua_codec_info);
5789 PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info);
5790 Py_INCREF(&PyTyp_pjsua_conf_port_info);
5791 PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info);
5792 Py_INCREF(&PyTyp_pjmedia_port);
5793 PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&PyTyp_pjmedia_port);
5794 Py_INCREF(&PyTyp_pjmedia_snd_dev_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005795 PyModule_AddObject(m, "PJMedia_Snd_Dev_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005796 (PyObject *)&PyTyp_pjmedia_snd_dev_info);
5797 Py_INCREF(&PyTyp_pjmedia_codec_param_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005798 PyModule_AddObject(m, "PJMedia_Codec_Param_Info",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005799 (PyObject *)&PyTyp_pjmedia_codec_param_info);
5800 Py_INCREF(&PyTyp_pjmedia_codec_param_setting);
Fahrisdcf8fa42006-12-28 03:13:48 +00005801 PyModule_AddObject(m, "PJMedia_Codec_Param_Setting",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005802 (PyObject *)&PyTyp_pjmedia_codec_param_setting);
5803 Py_INCREF(&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005804 PyModule_AddObject(m, "PJMedia_Codec_Param",
Benny Prijono1f63cc42007-09-10 16:54:22 +00005805 (PyObject *)&PyTyp_pjmedia_codec_param);
Fahrisdcf8fa42006-12-28 03:13:48 +00005806
5807 /* END OF LIB MEDIA */
5808
5809 /* LIB CALL */
5810
Benny Prijono1f63cc42007-09-10 16:54:22 +00005811 Py_INCREF(&PyTyp_pj_time_val);
5812 PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&PyTyp_pj_time_val);
Fahrisdcf8fa42006-12-28 03:13:48 +00005813
Benny Prijono1f63cc42007-09-10 16:54:22 +00005814 Py_INCREF(&PyTyp_pjsua_call_info);
5815 PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info);
Fahrisdcf8fa42006-12-28 03:13:48 +00005816
5817 /* END OF LIB CALL */
Benny Prijono572d4852006-11-23 21:50:02 +00005818
Benny Prijonodc308702006-12-09 00:39:42 +00005819
Fahrisdcf8fa42006-12-28 03:13:48 +00005820 /*
Benny Prijonoaa286042007-02-03 17:23:22 +00005821 * Add various constants.
Fahrisdcf8fa42006-12-28 03:13:48 +00005822 */
Benny Prijonodc308702006-12-09 00:39:42 +00005823
Benny Prijonoaa286042007-02-03 17:23:22 +00005824 /* Call states */
5825 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL);
5826 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING);
5827 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING);
5828 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY);
5829 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING);
5830 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED);
5831 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED);
Fahrisdcf8fa42006-12-28 03:13:48 +00005832
Benny Prijonoaa286042007-02-03 17:23:22 +00005833 /* Call media status (enum pjsua_call_media_status) */
5834 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE);
5835 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE);
5836 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD);
5837 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD);
Fahrisdcf8fa42006-12-28 03:13:48 +00005838
Benny Prijonoaa286042007-02-03 17:23:22 +00005839 /* Buddy status */
5840 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN);
5841 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE);
5842 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE);
Fahrisdcf8fa42006-12-28 03:13:48 +00005843
Benny Prijonoaa286042007-02-03 17:23:22 +00005844 /* PJSIP transport types (enum pjsip_transport_type_e) */
5845 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED);
5846 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP);
5847 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP);
5848 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS);
5849 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP);
5850 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP);
5851 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM);
Fahrisdcf8fa42006-12-28 03:13:48 +00005852
Fahrisdcf8fa42006-12-28 03:13:48 +00005853
Benny Prijonoaa286042007-02-03 17:23:22 +00005854 /* Invalid IDs */
5855 ADD_CONSTANT(m, PJSUA_INVALID_ID);
Fahrisdcf8fa42006-12-28 03:13:48 +00005856
Fahrisdcf8fa42006-12-28 03:13:48 +00005857
Benny Prijonoaa286042007-02-03 17:23:22 +00005858 /* Various compile time constants */
5859 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES);
5860 ADD_CONSTANT(m, PJSUA_MAX_ACC);
5861 ADD_CONSTANT(m, PJSUA_REG_INTERVAL);
5862 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION);
5863 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY);
5864 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES);
5865 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS);
5866 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE);
5867 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY);
5868 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE);
5869 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN);
5870 ADD_CONSTANT(m, PJSUA_MAX_CALLS);
5871 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES);
Fahrisdcf8fa42006-12-28 03:13:48 +00005872
Fahrisdcf8fa42006-12-28 03:13:48 +00005873
Benny Prijonoaa286042007-02-03 17:23:22 +00005874#undef ADD_CONSTANT
Benny Prijono8b8b9972006-11-16 11:18:03 +00005875}