Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4 | * |
| 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 Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 19 | #include <Python.h> |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 20 | #include "structmember.h" |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 21 | #include <pjsua-lib/pjsua.h> |
| 22 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 23 | #define THIS_FILE "main.c" |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 24 | #define POOL_SIZE 4000 |
| 25 | #define SND_DEV_NUM 64 |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 26 | #define SND_NAME_LEN 64 |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 27 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 28 | /* LIB BASE */ |
| 29 | |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 30 | static PyObject* obj_log_cb; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 31 | static long thread_id; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 32 | |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 33 | #define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure() |
| 34 | #define LEAVE_PYTHON() PyGILState_Release(state) |
| 35 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 36 | /* |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 37 | * cb_log_cb |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 38 | * declares method for reconfiguring logging process for callback struct |
| 39 | */ |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 40 | static void cb_log_cb(int level, const char *data, pj_size_t len) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 41 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 42 | |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 43 | /* Ignore if this callback is called from alien thread context, |
| 44 | * or otherwise it will crash Python. |
| 45 | */ |
| 46 | if (pj_thread_local_get(thread_id) == 0) |
| 47 | return; |
| 48 | |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 49 | if (PyCallable_Check(obj_log_cb)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 50 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 51 | ENTER_PYTHON(); |
| 52 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 53 | PyObject_CallFunctionObjArgs( |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 54 | obj_log_cb, Py_BuildValue("i",level), |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 55 | PyString_FromString(data), Py_BuildValue("i",len), NULL |
| 56 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 57 | |
| 58 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | /* |
| 64 | * pjsip_event_Object |
| 65 | * C/python typewrapper for event struct |
| 66 | */ |
| 67 | typedef struct |
| 68 | { |
| 69 | PyObject_HEAD |
| 70 | /* Type-specific fields go here. */ |
| 71 | pjsip_event * event; |
| 72 | } pjsip_event_Object; |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * pjsip_event_Type |
| 77 | * event struct signatures |
| 78 | */ |
| 79 | static PyTypeObject pjsip_event_Type = |
| 80 | { |
| 81 | PyObject_HEAD_INIT(NULL) |
| 82 | 0, /*ob_size*/ |
| 83 | "py_pjsua.PJSIP_Event", /*tp_name*/ |
| 84 | sizeof(pjsip_event_Object), /*tp_basicsize*/ |
| 85 | 0, /*tp_itemsize*/ |
| 86 | 0, /*tp_dealloc*/ |
| 87 | 0, /*tp_print*/ |
| 88 | 0, /*tp_getattr*/ |
| 89 | 0, /*tp_setattr*/ |
| 90 | 0, /*tp_compare*/ |
| 91 | 0, /*tp_repr*/ |
| 92 | 0, /*tp_as_number*/ |
| 93 | 0, /*tp_as_sequence*/ |
| 94 | 0, /*tp_as_mapping*/ |
| 95 | 0, /*tp_hash */ |
| 96 | 0, /*tp_call*/ |
| 97 | 0, /*tp_str*/ |
| 98 | 0, /*tp_getattro*/ |
| 99 | 0, /*tp_setattro*/ |
| 100 | 0, /*tp_as_buffer*/ |
| 101 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 102 | "pjsip_event objects", /*tp_doc */ |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 106 | /* |
| 107 | * pjsip_rx_data_Object |
| 108 | * C/python typewrapper for RX data struct |
| 109 | */ |
| 110 | typedef struct |
| 111 | { |
| 112 | PyObject_HEAD |
| 113 | /* Type-specific fields go here. */ |
| 114 | pjsip_rx_data * rdata; |
| 115 | } pjsip_rx_data_Object; |
| 116 | |
| 117 | |
| 118 | /* |
| 119 | * pjsip_rx_data_Type |
| 120 | */ |
| 121 | static PyTypeObject pjsip_rx_data_Type = |
| 122 | { |
| 123 | PyObject_HEAD_INIT(NULL) |
| 124 | 0, /*ob_size*/ |
| 125 | "py_pjsua.PJSIP_RX_Data", /*tp_name*/ |
| 126 | sizeof(pjsip_rx_data_Object), /*tp_basicsize*/ |
| 127 | 0, /*tp_itemsize*/ |
| 128 | 0, /*tp_dealloc*/ |
| 129 | 0, /*tp_print*/ |
| 130 | 0, /*tp_getattr*/ |
| 131 | 0, /*tp_setattr*/ |
| 132 | 0, /*tp_compare*/ |
| 133 | 0, /*tp_repr*/ |
| 134 | 0, /*tp_as_number*/ |
| 135 | 0, /*tp_as_sequence*/ |
| 136 | 0, /*tp_as_mapping*/ |
| 137 | 0, /*tp_hash */ |
| 138 | 0, /*tp_call*/ |
| 139 | 0, /*tp_str*/ |
| 140 | 0, /*tp_getattro*/ |
| 141 | 0, /*tp_setattro*/ |
| 142 | 0, /*tp_as_buffer*/ |
| 143 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 144 | "pjsip_rx_data objects", /*tp_doc*/ |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | * callback_Object |
| 150 | * C/python typewrapper for callback struct |
| 151 | */ |
| 152 | typedef struct |
| 153 | { |
| 154 | PyObject_HEAD |
| 155 | /* Type-specific fields go here. */ |
| 156 | PyObject * on_call_state; |
| 157 | PyObject * on_incoming_call; |
| 158 | PyObject * on_call_media_state; |
| 159 | PyObject * on_call_transfer_request; |
| 160 | PyObject * on_call_transfer_status; |
| 161 | PyObject * on_call_replace_request; |
| 162 | PyObject * on_call_replaced; |
| 163 | PyObject * on_reg_state; |
| 164 | PyObject * on_buddy_state; |
| 165 | PyObject * on_pager; |
| 166 | PyObject * on_pager_status; |
| 167 | PyObject * on_typing; |
| 168 | |
| 169 | } callback_Object; |
| 170 | |
| 171 | |
| 172 | /* |
| 173 | * The global callback object. |
| 174 | */ |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 175 | static callback_Object * g_obj_callback; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 176 | |
| 177 | |
| 178 | /* |
| 179 | * cb_on_call_state |
| 180 | * declares method on_call_state for callback struct |
| 181 | */ |
| 182 | static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e) |
| 183 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 184 | if (PyCallable_Check(g_obj_callback->on_call_state)) |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 185 | { |
| 186 | pjsip_event_Object * obj; |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 187 | |
| 188 | ENTER_PYTHON(); |
| 189 | |
| 190 | obj = (pjsip_event_Object *)PyType_GenericNew(&pjsip_event_Type, |
| 191 | NULL, NULL); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 192 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 193 | obj->event = e; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 194 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 195 | PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 196 | g_obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 197 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 198 | |
| 199 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /* |
| 205 | * cb_on_incoming_call |
| 206 | * declares method on_incoming_call for callback struct |
| 207 | */ |
| 208 | static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, |
| 209 | pjsip_rx_data *rdata) |
| 210 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 211 | if (PyCallable_Check(g_obj_callback->on_incoming_call)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 212 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 213 | pjsip_rx_data_Object * obj; |
| 214 | |
| 215 | ENTER_PYTHON(); |
| 216 | |
| 217 | obj = (pjsip_rx_data_Object *)PyType_GenericNew(&pjsip_rx_data_Type, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 218 | NULL, NULL); |
| 219 | obj->rdata = rdata; |
| 220 | |
| 221 | PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 222 | g_obj_callback->on_incoming_call, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 223 | Py_BuildValue("i",acc_id), |
| 224 | Py_BuildValue("i",call_id), |
| 225 | obj, |
| 226 | NULL |
| 227 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 228 | |
| 229 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /* |
| 235 | * cb_on_call_media_state |
| 236 | * declares method on_call_media_state for callback struct |
| 237 | */ |
| 238 | static void cb_on_call_media_state(pjsua_call_id call_id) |
| 239 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 240 | if (PyCallable_Check(g_obj_callback->on_call_media_state)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 241 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 242 | ENTER_PYTHON(); |
| 243 | |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 244 | PyObject_CallFunction(g_obj_callback->on_call_media_state,"i",call_id); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 245 | |
| 246 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | |
| 251 | /* |
| 252 | * Notify application on call being transfered. |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 253 | * !modified @061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 254 | */ |
| 255 | static void cb_on_call_transfer_request(pjsua_call_id call_id, |
| 256 | const pj_str_t *dst, |
| 257 | pjsip_status_code *code) |
| 258 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 259 | if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 260 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 261 | PyObject * ret; |
| 262 | int cd; |
| 263 | |
| 264 | ENTER_PYTHON(); |
| 265 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 266 | ret = PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 267 | g_obj_callback->on_call_transfer_request, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 268 | Py_BuildValue("i",call_id), |
| 269 | PyString_FromStringAndSize(dst->ptr, dst->slen), |
| 270 | Py_BuildValue("i",*code), |
| 271 | NULL |
| 272 | ); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 273 | if (ret != NULL) { |
| 274 | if (ret != Py_None) { |
| 275 | if (PyArg_Parse(ret,"i",&cd)) { |
| 276 | *code = cd; |
| 277 | } |
| 278 | } |
| 279 | } |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 280 | |
| 281 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | |
| 286 | /* |
| 287 | * Notify application of the status of previously sent call |
| 288 | * transfer request. Application can monitor the status of the |
| 289 | * call transfer request, for example to decide whether to |
| 290 | * terminate existing call. |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 291 | * !modified @061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 292 | */ |
| 293 | static void cb_on_call_transfer_status( pjsua_call_id call_id, |
| 294 | int status_code, |
| 295 | const pj_str_t *status_text, |
| 296 | pj_bool_t final, |
| 297 | pj_bool_t *p_cont) |
| 298 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 299 | if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 300 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 301 | PyObject * ret; |
| 302 | int cnt; |
| 303 | |
| 304 | ENTER_PYTHON(); |
| 305 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 306 | ret = PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 307 | g_obj_callback->on_call_transfer_status, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 308 | Py_BuildValue("i",call_id), |
| 309 | Py_BuildValue("i",status_code), |
| 310 | PyString_FromStringAndSize(status_text->ptr, status_text->slen), |
| 311 | Py_BuildValue("i",final), |
| 312 | Py_BuildValue("i",*p_cont), |
| 313 | NULL |
| 314 | ); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 315 | if (ret != NULL) { |
| 316 | if (ret != Py_None) { |
| 317 | if (PyArg_Parse(ret,"i",&cnt)) { |
| 318 | *p_cont = cnt; |
| 319 | } |
| 320 | } |
| 321 | } |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 322 | |
| 323 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | |
| 328 | /* |
| 329 | * Notify application about incoming INVITE with Replaces header. |
| 330 | * Application may reject the request by setting non-2xx code. |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 331 | * !modified @061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 332 | */ |
| 333 | static void cb_on_call_replace_request( pjsua_call_id call_id, |
| 334 | pjsip_rx_data *rdata, |
| 335 | int *st_code, |
| 336 | pj_str_t *st_text) |
| 337 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 338 | if (PyCallable_Check(g_obj_callback->on_call_replace_request)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 339 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 340 | PyObject * ret; |
| 341 | PyObject * txt; |
| 342 | int cd; |
| 343 | pjsip_rx_data_Object * obj; |
| 344 | |
| 345 | ENTER_PYTHON(); |
| 346 | |
| 347 | obj = (pjsip_rx_data_Object *)PyType_GenericNew(&pjsip_rx_data_Type, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 348 | NULL, NULL); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 349 | obj->rdata = rdata; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 350 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 351 | ret = PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 352 | g_obj_callback->on_call_replace_request, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 353 | Py_BuildValue("i",call_id), |
| 354 | obj, |
| 355 | Py_BuildValue("i",*st_code), |
| 356 | PyString_FromStringAndSize(st_text->ptr, st_text->slen), |
| 357 | NULL |
| 358 | ); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 359 | if (ret != NULL) { |
| 360 | if (ret != Py_None) { |
| 361 | if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) { |
| 362 | *st_code = cd; |
| 363 | st_text->ptr = PyString_AsString(txt); |
| 364 | st_text->slen = strlen(PyString_AsString(txt)); |
| 365 | } |
| 366 | } |
| 367 | } |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 368 | |
| 369 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | |
| 374 | /* |
| 375 | * Notify application that an existing call has been replaced with |
| 376 | * a new call. This happens when PJSUA-API receives incoming INVITE |
| 377 | * request with Replaces header. |
| 378 | */ |
| 379 | static void cb_on_call_replaced(pjsua_call_id old_call_id, |
| 380 | pjsua_call_id new_call_id) |
| 381 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 382 | if (PyCallable_Check(g_obj_callback->on_call_replaced)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 383 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 384 | ENTER_PYTHON(); |
| 385 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 386 | PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 387 | g_obj_callback->on_call_replaced, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 388 | Py_BuildValue("i",old_call_id), |
| 389 | Py_BuildValue("i",old_call_id), |
| 390 | NULL |
| 391 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 392 | |
| 393 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /* |
| 399 | * cb_on_reg_state |
| 400 | * declares method on_reg_state for callback struct |
| 401 | */ |
| 402 | static void cb_on_reg_state(pjsua_acc_id acc_id) |
| 403 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 404 | if (PyCallable_Check(g_obj_callback->on_reg_state)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 405 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 406 | ENTER_PYTHON(); |
| 407 | |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 408 | PyObject_CallFunction(g_obj_callback->on_reg_state,"i",acc_id); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 409 | |
| 410 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | |
| 415 | /* |
| 416 | * cb_on_buddy_state |
| 417 | * declares method on_buddy state for callback struct |
| 418 | */ |
| 419 | static void cb_on_buddy_state(pjsua_buddy_id buddy_id) |
| 420 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 421 | if (PyCallable_Check(g_obj_callback->on_buddy_state)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 422 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 423 | ENTER_PYTHON(); |
| 424 | |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 425 | PyObject_CallFunction(g_obj_callback->on_buddy_state,"i",buddy_id); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 426 | |
| 427 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * cb_on_pager |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 433 | * declares method on_pager for callback struct |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 434 | */ |
| 435 | static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from, |
| 436 | const pj_str_t *to, const pj_str_t *contact, |
| 437 | const pj_str_t *mime_type, const pj_str_t *body) |
| 438 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 439 | if (PyCallable_Check(g_obj_callback->on_pager)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 440 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 441 | ENTER_PYTHON(); |
| 442 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 443 | PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 444 | g_obj_callback->on_pager,Py_BuildValue("i",call_id), |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 445 | PyString_FromStringAndSize(from->ptr, from->slen), |
| 446 | PyString_FromStringAndSize(to->ptr, to->slen), |
| 447 | PyString_FromStringAndSize(contact->ptr, contact->slen), |
| 448 | PyString_FromStringAndSize(mime_type->ptr, mime_type->slen), |
| 449 | PyString_FromStringAndSize(body->ptr, body->slen), NULL |
| 450 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 451 | |
| 452 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | |
| 457 | /* |
| 458 | * cb_on_pager_status |
| 459 | * declares method on_pager_status for callback struct |
| 460 | */ |
| 461 | static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to, |
| 462 | const pj_str_t *body, void *user_data, |
| 463 | pjsip_status_code status, |
| 464 | const pj_str_t *reason) |
| 465 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 466 | if (PyCallable_Check(g_obj_callback->on_pager)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 467 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 468 | PyObject * obj_user_data; |
| 469 | |
| 470 | ENTER_PYTHON(); |
| 471 | |
| 472 | obj_user_data = Py_BuildValue("i", user_data); |
| 473 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 474 | PyObject_CallFunctionObjArgs( |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 475 | g_obj_callback->on_pager_status, |
| 476 | Py_BuildValue("i",call_id), |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 477 | PyString_FromStringAndSize(to->ptr, to->slen), |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 478 | PyString_FromStringAndSize(body->ptr, body->slen), |
| 479 | obj_user_data, |
| 480 | Py_BuildValue("i",status), |
| 481 | PyString_FromStringAndSize(reason->ptr,reason->slen), |
| 482 | NULL |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 483 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 484 | |
| 485 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | |
| 490 | /* |
| 491 | * cb_on_typing |
| 492 | * declares method on_typing for callback struct |
| 493 | */ |
| 494 | static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from, |
| 495 | const pj_str_t *to, const pj_str_t *contact, |
| 496 | pj_bool_t is_typing) |
| 497 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 498 | if (PyCallable_Check(g_obj_callback->on_typing)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 499 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 500 | ENTER_PYTHON(); |
| 501 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 502 | PyObject_CallFunctionObjArgs( |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 503 | g_obj_callback->on_typing,Py_BuildValue("i",call_id), |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 504 | PyString_FromStringAndSize(from->ptr, from->slen), |
| 505 | PyString_FromStringAndSize(to->ptr, to->slen), |
| 506 | PyString_FromStringAndSize(contact->ptr, contact->slen), |
| 507 | Py_BuildValue("i",is_typing),NULL |
| 508 | ); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 509 | |
| 510 | LEAVE_PYTHON(); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /* |
| 516 | * callback_dealloc |
| 517 | * destructor function for callback struct |
| 518 | */ |
| 519 | static void callback_dealloc(callback_Object* self) |
| 520 | { |
| 521 | Py_XDECREF(self->on_call_state); |
| 522 | Py_XDECREF(self->on_incoming_call); |
| 523 | Py_XDECREF(self->on_call_media_state); |
| 524 | Py_XDECREF(self->on_call_transfer_request); |
| 525 | Py_XDECREF(self->on_call_transfer_status); |
| 526 | Py_XDECREF(self->on_call_replace_request); |
| 527 | Py_XDECREF(self->on_call_replaced); |
| 528 | Py_XDECREF(self->on_reg_state); |
| 529 | Py_XDECREF(self->on_buddy_state); |
| 530 | Py_XDECREF(self->on_pager); |
| 531 | Py_XDECREF(self->on_pager_status); |
| 532 | Py_XDECREF(self->on_typing); |
| 533 | self->ob_type->tp_free((PyObject*)self); |
| 534 | } |
| 535 | |
| 536 | |
| 537 | /* |
| 538 | * callback_new |
| 539 | * * declares constructor for callback struct |
| 540 | */ |
| 541 | static PyObject * callback_new(PyTypeObject *type, PyObject *args, |
| 542 | PyObject *kwds) |
| 543 | { |
| 544 | callback_Object *self; |
| 545 | |
| 546 | self = (callback_Object *)type->tp_alloc(type, 0); |
| 547 | if (self != NULL) |
| 548 | { |
| 549 | Py_INCREF(Py_None); |
| 550 | self->on_call_state = Py_None; |
| 551 | if (self->on_call_state == NULL) |
| 552 | { |
| 553 | Py_DECREF(Py_None); |
| 554 | return NULL; |
| 555 | } |
| 556 | Py_INCREF(Py_None); |
| 557 | self->on_incoming_call = Py_None; |
| 558 | if (self->on_incoming_call == NULL) |
| 559 | { |
| 560 | Py_DECREF(Py_None); |
| 561 | return NULL; |
| 562 | } |
| 563 | Py_INCREF(Py_None); |
| 564 | self->on_call_media_state = Py_None; |
| 565 | if (self->on_call_media_state == NULL) |
| 566 | { |
| 567 | Py_DECREF(Py_None); |
| 568 | return NULL; |
| 569 | } |
| 570 | Py_INCREF(Py_None); |
| 571 | self->on_call_transfer_request = Py_None; |
| 572 | if (self->on_call_transfer_request == NULL) |
| 573 | { |
| 574 | Py_DECREF(Py_None); |
| 575 | return NULL; |
| 576 | } |
| 577 | Py_INCREF(Py_None); |
| 578 | self->on_call_transfer_status = Py_None; |
| 579 | if (self->on_call_transfer_status == NULL) |
| 580 | { |
| 581 | Py_DECREF(Py_None); |
| 582 | return NULL; |
| 583 | } |
| 584 | Py_INCREF(Py_None); |
| 585 | self->on_call_replace_request = Py_None; |
| 586 | if (self->on_call_replace_request == NULL) |
| 587 | { |
| 588 | Py_DECREF(Py_None); |
| 589 | return NULL; |
| 590 | } |
| 591 | Py_INCREF(Py_None); |
| 592 | self->on_call_replaced = Py_None; |
| 593 | if (self->on_call_replaced == NULL) |
| 594 | { |
| 595 | Py_DECREF(Py_None); |
| 596 | return NULL; |
| 597 | } |
| 598 | Py_INCREF(Py_None); |
| 599 | self->on_reg_state = Py_None; |
| 600 | if (self->on_reg_state == NULL) |
| 601 | { |
| 602 | Py_DECREF(Py_None); |
| 603 | return NULL; |
| 604 | } |
| 605 | Py_INCREF(Py_None); |
| 606 | self->on_buddy_state = Py_None; |
| 607 | if (self->on_buddy_state == NULL) |
| 608 | { |
| 609 | Py_DECREF(Py_None); |
| 610 | return NULL; |
| 611 | } |
| 612 | Py_INCREF(Py_None); |
| 613 | self->on_pager = Py_None; |
| 614 | if (self->on_pager == NULL) |
| 615 | { |
| 616 | Py_DECREF(Py_None); |
| 617 | return NULL; |
| 618 | } |
| 619 | Py_INCREF(Py_None); |
| 620 | self->on_pager_status = Py_None; |
| 621 | if (self->on_pager_status == NULL) |
| 622 | { |
| 623 | Py_DECREF(Py_None); |
| 624 | return NULL; |
| 625 | } |
| 626 | Py_INCREF(Py_None); |
| 627 | self->on_typing = Py_None; |
| 628 | if (self->on_typing == NULL) |
| 629 | { |
| 630 | Py_DECREF(Py_None); |
| 631 | return NULL; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | return (PyObject *)self; |
| 636 | } |
| 637 | |
| 638 | |
| 639 | /* |
| 640 | * callback_members |
| 641 | * declares available functions for callback object |
| 642 | */ |
| 643 | static PyMemberDef callback_members[] = |
| 644 | { |
| 645 | { |
| 646 | "on_call_state", T_OBJECT_EX, offsetof(callback_Object, on_call_state), |
| 647 | 0, "Notify application when invite state has changed. Application may " |
| 648 | "then query the call info to get the detail call states." |
| 649 | }, |
| 650 | { |
| 651 | "on_incoming_call", T_OBJECT_EX, |
| 652 | offsetof(callback_Object, on_incoming_call), 0, |
| 653 | "Notify application on incoming call." |
| 654 | }, |
| 655 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 656 | "on_call_media_state", T_OBJECT_EX, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 657 | offsetof(callback_Object, on_call_media_state), 0, |
| 658 | "Notify application when media state in the call has changed. Normal " |
| 659 | "application would need to implement this callback, e.g. to connect " |
| 660 | "the call's media to sound device." |
| 661 | }, |
| 662 | { |
| 663 | "on_call_transfer_request", T_OBJECT_EX, |
| 664 | offsetof(callback_Object, on_call_transfer_request), 0, |
| 665 | "Notify application on call being transfered. " |
| 666 | "Application can decide to accept/reject transfer request " |
| 667 | "by setting the code (default is 200). When this callback " |
| 668 | "is not defined, the default behavior is to accept the " |
| 669 | "transfer." |
| 670 | }, |
| 671 | { |
| 672 | "on_call_transfer_status", T_OBJECT_EX, |
| 673 | offsetof(callback_Object, on_call_transfer_status), 0, |
| 674 | "Notify application of the status of previously sent call " |
| 675 | "transfer request. Application can monitor the status of the " |
| 676 | "call transfer request, for example to decide whether to " |
| 677 | "terminate existing call." |
| 678 | }, |
| 679 | { |
| 680 | "on_call_replace_request", T_OBJECT_EX, |
| 681 | offsetof(callback_Object, on_call_replace_request), 0, |
| 682 | "Notify application about incoming INVITE with Replaces header. " |
| 683 | "Application may reject the request by setting non-2xx code." |
| 684 | }, |
| 685 | { |
| 686 | "on_call_replaced", T_OBJECT_EX, |
| 687 | offsetof(callback_Object, on_call_replaced), 0, |
| 688 | "Notify application that an existing call has been replaced with " |
| 689 | "a new call. This happens when PJSUA-API receives incoming INVITE " |
| 690 | "request with Replaces header." |
| 691 | " " |
| 692 | "After this callback is called, normally PJSUA-API will disconnect " |
| 693 | "old_call_id and establish new_call_id." |
| 694 | }, |
| 695 | { |
| 696 | "on_reg_state", T_OBJECT_EX, |
| 697 | offsetof(callback_Object, on_reg_state), 0, |
| 698 | "Notify application when registration status has changed. Application " |
| 699 | "may then query the account info to get the registration details." |
| 700 | }, |
| 701 | { |
| 702 | "on_buddy_state", T_OBJECT_EX, |
| 703 | offsetof(callback_Object, on_buddy_state), 0, |
| 704 | "Notify application when the buddy state has changed. Application may " |
| 705 | "then query the buddy into to get the details." |
| 706 | }, |
| 707 | { |
| 708 | "on_pager", T_OBJECT_EX, offsetof(callback_Object, on_pager), 0, |
| 709 | "Notify application on incoming pager (i.e. MESSAGE request). " |
| 710 | "Argument call_id will be -1 if MESSAGE request is not related to an " |
| 711 | "existing call." |
| 712 | }, |
| 713 | { |
| 714 | "on_pager_status", T_OBJECT_EX, |
| 715 | offsetof(callback_Object, on_pager_status), 0, |
| 716 | "Notify application about the delivery status of outgoing pager " |
| 717 | "request." |
| 718 | }, |
| 719 | { |
| 720 | "on_typing", T_OBJECT_EX, offsetof(callback_Object, on_typing), 0, |
| 721 | "Notify application about typing indication." |
| 722 | }, |
| 723 | {NULL} /* Sentinel */ |
| 724 | }; |
| 725 | |
| 726 | |
| 727 | /* |
| 728 | * callback_Type |
| 729 | * callback class definition |
| 730 | */ |
| 731 | static PyTypeObject callback_Type = |
| 732 | { |
| 733 | PyObject_HEAD_INIT(NULL) |
| 734 | 0, /*ob_size*/ |
| 735 | "py_pjsua.Callback", /*tp_name*/ |
| 736 | sizeof(callback_Object), /*tp_basicsize*/ |
| 737 | 0, /*tp_itemsize*/ |
| 738 | (destructor)callback_dealloc, /*tp_dealloc*/ |
| 739 | 0, /*tp_print*/ |
| 740 | 0, /*tp_getattr*/ |
| 741 | 0, /*tp_setattr*/ |
| 742 | 0, /*tp_compare*/ |
| 743 | 0, /*tp_repr*/ |
| 744 | 0, /*tp_as_number*/ |
| 745 | 0, /*tp_as_sequence*/ |
| 746 | 0, /*tp_as_mapping*/ |
| 747 | 0, /*tp_hash */ |
| 748 | 0, /*tp_call*/ |
| 749 | 0, /*tp_str*/ |
| 750 | 0, /*tp_getattro*/ |
| 751 | 0, /*tp_setattro*/ |
| 752 | 0, /*tp_as_buffer*/ |
| 753 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 754 | "Callback objects", /* tp_doc */ |
| 755 | 0, /* tp_traverse */ |
| 756 | 0, /* tp_clear */ |
| 757 | 0, /* tp_richcompare */ |
| 758 | 0, /* tp_weaklistoffset */ |
| 759 | 0, /* tp_iter */ |
| 760 | 0, /* tp_iternext */ |
| 761 | 0, /* tp_methods */ |
| 762 | callback_members, /* tp_members */ |
| 763 | 0, /* tp_getset */ |
| 764 | 0, /* tp_base */ |
| 765 | 0, /* tp_dict */ |
| 766 | 0, /* tp_descr_get */ |
| 767 | 0, /* tp_descr_set */ |
| 768 | 0, /* tp_dictoffset */ |
| 769 | 0, /* tp_init */ |
| 770 | 0, /* tp_alloc */ |
| 771 | callback_new, /* tp_new */ |
| 772 | |
| 773 | }; |
| 774 | |
| 775 | |
| 776 | /* |
| 777 | * media_config_Object |
| 778 | * C/Python wrapper for media_config object |
| 779 | */ |
| 780 | typedef struct |
| 781 | { |
| 782 | PyObject_HEAD |
| 783 | /* Type-specific fields go here. */ |
| 784 | unsigned clock_rate; |
| 785 | unsigned max_media_ports; |
| 786 | int has_ioqueue; |
| 787 | unsigned thread_cnt; |
| 788 | unsigned quality; |
| 789 | unsigned ptime; |
| 790 | int no_vad; |
| 791 | unsigned ilbc_mode; |
| 792 | unsigned tx_drop_pct; |
| 793 | unsigned rx_drop_pct; |
| 794 | unsigned ec_options; |
| 795 | unsigned ec_tail_len; |
| 796 | } media_config_Object; |
| 797 | |
| 798 | |
| 799 | /* |
| 800 | * media_config_members |
| 801 | * declares attributes accessible from both C and Python for media_config file |
| 802 | */ |
| 803 | static PyMemberDef media_config_members[] = |
| 804 | { |
| 805 | { |
| 806 | "clock_rate", T_INT, offsetof(media_config_Object, clock_rate), 0, |
| 807 | "Clock rate to be applied to the conference bridge. If value is zero, " |
| 808 | "default clock rate will be used (16KHz)." |
| 809 | }, |
| 810 | { |
| 811 | "max_media_ports", T_INT, |
| 812 | offsetof(media_config_Object, max_media_ports), 0, |
| 813 | "Specify maximum number of media ports to be created in the " |
| 814 | "conference bridge. Since all media terminate in the bridge (calls, " |
| 815 | "file player, file recorder, etc), the value must be large enough to " |
| 816 | "support all of them. However, the larger the value, the more " |
| 817 | "computations are performed." |
| 818 | }, |
| 819 | { |
| 820 | "has_ioqueue", T_INT, offsetof(media_config_Object, has_ioqueue), 0, |
| 821 | "Specify whether the media manager should manage its own ioqueue for " |
| 822 | "the RTP/RTCP sockets. If yes, ioqueue will be created and at least " |
| 823 | "one worker thread will be created too. If no, the RTP/RTCP sockets " |
| 824 | "will share the same ioqueue as SIP sockets, and no worker thread is " |
| 825 | "needed." |
| 826 | }, |
| 827 | { |
| 828 | "thread_cnt", T_INT, offsetof(media_config_Object, thread_cnt), 0, |
| 829 | "Specify the number of worker threads to handle incoming RTP packets. " |
| 830 | "A value of one is recommended for most applications." |
| 831 | }, |
| 832 | { |
| 833 | "quality", T_INT, offsetof(media_config_Object, quality), 0, |
| 834 | "The media quality also sets speex codec quality/complexity to the " |
| 835 | "number." |
| 836 | }, |
| 837 | { |
| 838 | "ptime", T_INT, offsetof(media_config_Object, ptime), 0, |
| 839 | "Specify default ptime." |
| 840 | }, |
| 841 | { |
| 842 | "no_vad", T_INT, offsetof(media_config_Object, no_vad), 0, |
| 843 | "Disable VAD?" |
| 844 | }, |
| 845 | { |
| 846 | "ilbc_mode", T_INT, offsetof(media_config_Object, ilbc_mode), 0, |
| 847 | "iLBC mode (20 or 30)." |
| 848 | }, |
| 849 | { |
| 850 | "tx_drop_pct", T_INT, offsetof(media_config_Object, tx_drop_pct), 0, |
| 851 | "Percentage of RTP packet to drop in TX direction (to simulate packet " |
| 852 | "lost)." |
| 853 | }, |
| 854 | { |
| 855 | "rx_drop_pct", T_INT, offsetof(media_config_Object, rx_drop_pct), 0, |
| 856 | "Percentage of RTP packet to drop in RX direction (to simulate packet " |
| 857 | "lost)."}, |
| 858 | { |
| 859 | "ec_options", T_INT, offsetof(media_config_Object, ec_options), 0, |
| 860 | "Echo canceller options (see #pjmedia_echo_create())" |
| 861 | }, |
| 862 | { |
| 863 | "ec_tail_len", T_INT, offsetof(media_config_Object, ec_tail_len), 0, |
| 864 | "Echo canceller tail length, in miliseconds." |
| 865 | }, |
| 866 | {NULL} /* Sentinel */ |
| 867 | }; |
| 868 | |
| 869 | |
| 870 | /* |
| 871 | * media_config_Type |
| 872 | */ |
| 873 | static PyTypeObject media_config_Type = |
| 874 | { |
| 875 | PyObject_HEAD_INIT(NULL) |
| 876 | 0, /*ob_size*/ |
| 877 | "py_pjsua.Media_Config", /*tp_name*/ |
| 878 | sizeof(media_config_Object), /*tp_basicsize*/ |
| 879 | 0, /*tp_itemsize*/ |
| 880 | 0, /*tp_dealloc*/ |
| 881 | 0, /*tp_print*/ |
| 882 | 0, /*tp_getattr*/ |
| 883 | 0, /*tp_setattr*/ |
| 884 | 0, /*tp_compare*/ |
| 885 | 0, /*tp_repr*/ |
| 886 | 0, /*tp_as_number*/ |
| 887 | 0, /*tp_as_sequence*/ |
| 888 | 0, /*tp_as_mapping*/ |
| 889 | 0, /*tp_hash */ |
| 890 | 0, /*tp_call*/ |
| 891 | 0, /*tp_str*/ |
| 892 | 0, /*tp_getattro*/ |
| 893 | 0, /*tp_setattro*/ |
| 894 | 0, /*tp_as_buffer*/ |
| 895 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 896 | "Media Config objects", /*tp_doc*/ |
| 897 | 0, /*tp_traverse*/ |
| 898 | 0, /*tp_clear*/ |
| 899 | 0, /*tp_richcompare*/ |
| 900 | 0, /* tp_weaklistoffset */ |
| 901 | 0, /* tp_iter */ |
| 902 | 0, /* tp_iternext */ |
| 903 | 0, /* tp_methods */ |
| 904 | media_config_members, /* tp_members */ |
| 905 | |
| 906 | }; |
| 907 | |
| 908 | |
| 909 | /* |
| 910 | * config_Object |
| 911 | * attribute list for config object |
| 912 | */ |
| 913 | typedef struct |
| 914 | { |
| 915 | PyObject_HEAD |
| 916 | /* Type-specific fields go here. */ |
| 917 | unsigned max_calls; |
| 918 | unsigned thread_cnt; |
| 919 | unsigned outbound_proxy_cnt; |
| 920 | pj_str_t outbound_proxy[4]; |
| 921 | unsigned cred_count; |
| 922 | pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES]; |
| 923 | callback_Object * cb; |
| 924 | PyObject * user_agent; |
| 925 | } config_Object; |
| 926 | |
| 927 | |
| 928 | /* |
| 929 | * config_dealloc |
| 930 | * deallocates a config object |
| 931 | */ |
| 932 | static void config_dealloc(config_Object* self) |
| 933 | { |
| 934 | Py_XDECREF(self->cb); |
| 935 | Py_XDECREF(self->user_agent); |
| 936 | self->ob_type->tp_free((PyObject*)self); |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * config_new |
| 941 | * config object constructor |
| 942 | */ |
| 943 | static PyObject *config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 944 | { |
| 945 | config_Object *self; |
| 946 | |
| 947 | self = (config_Object *)type->tp_alloc(type, 0); |
| 948 | if (self != NULL) |
| 949 | { |
| 950 | self->user_agent = PyString_FromString(""); |
| 951 | if (self->user_agent == NULL) |
| 952 | { |
| 953 | Py_DECREF(self); |
| 954 | return NULL; |
| 955 | } |
| 956 | self->cb = (callback_Object *)PyType_GenericNew( |
| 957 | &callback_Type, NULL, NULL |
| 958 | ); |
| 959 | if (self->cb == NULL) |
| 960 | { |
| 961 | Py_DECREF(Py_None); |
| 962 | return NULL; |
| 963 | } |
| 964 | } |
| 965 | return (PyObject *)self; |
| 966 | } |
| 967 | |
| 968 | |
| 969 | /* |
| 970 | * config_members |
| 971 | * attribute list accessible from Python/C |
| 972 | */ |
| 973 | static PyMemberDef config_members[] = |
| 974 | { |
| 975 | { |
| 976 | "max_calls", T_INT, offsetof(config_Object, max_calls), 0, |
| 977 | "Maximum calls to support (default: 4) " |
| 978 | }, |
| 979 | { |
| 980 | "thread_cnt", T_INT, offsetof(config_Object, thread_cnt), 0, |
| 981 | "Number of worker threads. Normally application will want to have at " |
| 982 | "least one worker thread, unless when it wants to poll the library " |
| 983 | "periodically, which in this case the worker thread can be set to " |
| 984 | "zero." |
| 985 | }, |
| 986 | { |
| 987 | "outbound_proxy_cnt", T_INT, |
| 988 | offsetof(config_Object, outbound_proxy_cnt), 0, |
| 989 | "Number of outbound proxies in the array." |
| 990 | }, |
| 991 | { |
| 992 | "cred_count", T_INT, offsetof(config_Object, cred_count), 0, |
| 993 | "Number of credentials in the credential array." |
| 994 | }, |
| 995 | { |
| 996 | "user_agent", T_OBJECT_EX, offsetof(config_Object, user_agent), 0, |
| 997 | "User agent string (default empty)" |
| 998 | }, |
| 999 | { |
| 1000 | "cb", T_OBJECT_EX, offsetof(config_Object, cb), 0, |
| 1001 | "Application callback." |
| 1002 | }, |
| 1003 | {NULL} /* Sentinel */ |
| 1004 | }; |
| 1005 | |
| 1006 | |
| 1007 | /* |
| 1008 | * config_Type |
| 1009 | * type wrapper for config class |
| 1010 | */ |
| 1011 | static PyTypeObject config_Type = |
| 1012 | { |
| 1013 | PyObject_HEAD_INIT(NULL) |
| 1014 | 0, /*ob_size*/ |
| 1015 | "py_pjsua.Config", /*tp_name*/ |
| 1016 | sizeof(config_Object), /*tp_basicsize*/ |
| 1017 | 0, /*tp_itemsize*/ |
| 1018 | (destructor)config_dealloc,/*tp_dealloc*/ |
| 1019 | 0, /*tp_print*/ |
| 1020 | 0, /*tp_getattr*/ |
| 1021 | 0, /*tp_setattr*/ |
| 1022 | 0, /*tp_compare*/ |
| 1023 | 0, /*tp_repr*/ |
| 1024 | 0, /*tp_as_number*/ |
| 1025 | 0, /*tp_as_sequence*/ |
| 1026 | 0, /*tp_as_mapping*/ |
| 1027 | 0, /*tp_hash */ |
| 1028 | 0, /*tp_call*/ |
| 1029 | 0, /*tp_str*/ |
| 1030 | 0, /*tp_getattro*/ |
| 1031 | 0, /*tp_setattro*/ |
| 1032 | 0, /*tp_as_buffer*/ |
| 1033 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1034 | "Config objects", /* tp_doc */ |
| 1035 | 0, /* tp_traverse */ |
| 1036 | 0, /* tp_clear */ |
| 1037 | 0, /* tp_richcompare */ |
| 1038 | 0, /* tp_weaklistoffset */ |
| 1039 | 0, /* tp_iter */ |
| 1040 | 0, /* tp_iternext */ |
| 1041 | 0, /* tp_methods */ |
| 1042 | config_members, /* tp_members */ |
| 1043 | 0, /* tp_getset */ |
| 1044 | 0, /* tp_base */ |
| 1045 | 0, /* tp_dict */ |
| 1046 | 0, /* tp_descr_get */ |
| 1047 | 0, /* tp_descr_set */ |
| 1048 | 0, /* tp_dictoffset */ |
| 1049 | 0, /* tp_init */ |
| 1050 | 0, /* tp_alloc */ |
| 1051 | config_new, /* tp_new */ |
| 1052 | |
| 1053 | }; |
| 1054 | |
| 1055 | |
| 1056 | /* |
| 1057 | * logging_config_Object |
| 1058 | * configuration class for logging_config object |
| 1059 | */ |
| 1060 | typedef struct |
| 1061 | { |
| 1062 | PyObject_HEAD |
| 1063 | /* Type-specific fields go here. */ |
| 1064 | int msg_logging; |
| 1065 | unsigned level; |
| 1066 | unsigned console_level; |
| 1067 | unsigned decor; |
| 1068 | PyObject * log_filename; |
| 1069 | PyObject * cb; |
| 1070 | } logging_config_Object; |
| 1071 | |
| 1072 | |
| 1073 | /* |
| 1074 | * logging_config_dealloc |
| 1075 | * deletes a logging config from memory |
| 1076 | */ |
| 1077 | static void logging_config_dealloc(logging_config_Object* self) |
| 1078 | { |
| 1079 | Py_XDECREF(self->log_filename); |
| 1080 | Py_XDECREF(self->cb); |
| 1081 | self->ob_type->tp_free((PyObject*)self); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | /* |
| 1086 | * logging_config_new |
| 1087 | * constructor for logging_config object |
| 1088 | */ |
| 1089 | static PyObject * logging_config_new(PyTypeObject *type, PyObject *args, |
| 1090 | PyObject *kwds) |
| 1091 | { |
| 1092 | logging_config_Object *self; |
| 1093 | |
| 1094 | self = (logging_config_Object *)type->tp_alloc(type, 0); |
| 1095 | if (self != NULL) |
| 1096 | { |
| 1097 | self->log_filename = PyString_FromString(""); |
| 1098 | if (self->log_filename == NULL) |
| 1099 | { |
| 1100 | Py_DECREF(self); |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | Py_INCREF(Py_None); |
| 1104 | self->cb = Py_None; |
| 1105 | if (self->cb == NULL) |
| 1106 | { |
| 1107 | Py_DECREF(Py_None); |
| 1108 | return NULL; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | return (PyObject *)self; |
| 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | /* |
| 1117 | * logging_config_members |
| 1118 | */ |
| 1119 | static PyMemberDef logging_config_members[] = |
| 1120 | { |
| 1121 | { |
| 1122 | "msg_logging", T_INT, offsetof(logging_config_Object, msg_logging), 0, |
| 1123 | "Log incoming and outgoing SIP message? Yes!" |
| 1124 | }, |
| 1125 | { |
| 1126 | "level", T_INT, offsetof(logging_config_Object, level), 0, |
| 1127 | "Input verbosity level. Value 5 is reasonable." |
| 1128 | }, |
| 1129 | { |
| 1130 | "console_level", T_INT, offsetof(logging_config_Object, console_level), |
| 1131 | 0, "Verbosity level for console. Value 4 is reasonable." |
| 1132 | }, |
| 1133 | { |
| 1134 | "decor", T_INT, offsetof(logging_config_Object, decor), 0, |
| 1135 | "Log decoration" |
| 1136 | }, |
| 1137 | { |
| 1138 | "log_filename", T_OBJECT_EX, |
| 1139 | offsetof(logging_config_Object, log_filename), 0, |
| 1140 | "Optional log filename" |
| 1141 | }, |
| 1142 | { |
| 1143 | "cb", T_OBJECT_EX, offsetof(logging_config_Object, cb), 0, |
| 1144 | "Optional callback function to be called to write log to application " |
| 1145 | "specific device. This function will be called forlog messages on " |
| 1146 | "input verbosity level." |
| 1147 | }, |
| 1148 | {NULL} /* Sentinel */ |
| 1149 | }; |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | /* |
| 1155 | * logging_config_Type |
| 1156 | */ |
| 1157 | static PyTypeObject logging_config_Type = |
| 1158 | { |
| 1159 | PyObject_HEAD_INIT(NULL) |
| 1160 | 0, /*ob_size*/ |
| 1161 | "py_pjsua.Logging_Config", /*tp_name*/ |
| 1162 | sizeof(logging_config_Object), /*tp_basicsize*/ |
| 1163 | 0, /*tp_itemsize*/ |
| 1164 | (destructor)logging_config_dealloc,/*tp_dealloc*/ |
| 1165 | 0, /*tp_print*/ |
| 1166 | 0, /*tp_getattr*/ |
| 1167 | 0, /*tp_setattr*/ |
| 1168 | 0, /*tp_compare*/ |
| 1169 | 0, /*tp_repr*/ |
| 1170 | 0, /*tp_as_number*/ |
| 1171 | 0, /*tp_as_sequence*/ |
| 1172 | 0, /*tp_as_mapping*/ |
| 1173 | 0, /*tp_hash */ |
| 1174 | 0, /*tp_call*/ |
| 1175 | 0, /*tp_str*/ |
| 1176 | 0, /*tp_getattro*/ |
| 1177 | 0, /*tp_setattro*/ |
| 1178 | 0, /*tp_as_buffer*/ |
| 1179 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1180 | "Logging Config objects", /* tp_doc */ |
| 1181 | 0, /* tp_traverse */ |
| 1182 | 0, /* tp_clear */ |
| 1183 | 0, /* tp_richcompare */ |
| 1184 | 0, /* tp_weaklistoffset */ |
| 1185 | 0, /* tp_iter */ |
| 1186 | 0, /* tp_iternext */ |
| 1187 | 0, /* tp_methods */ |
| 1188 | logging_config_members, /* tp_members */ |
| 1189 | 0, /* tp_getset */ |
| 1190 | 0, /* tp_base */ |
| 1191 | 0, /* tp_dict */ |
| 1192 | 0, /* tp_descr_get */ |
| 1193 | 0, /* tp_descr_set */ |
| 1194 | 0, /* tp_dictoffset */ |
| 1195 | 0, /* tp_init */ |
| 1196 | 0, /* tp_alloc */ |
| 1197 | logging_config_new, /* tp_new */ |
| 1198 | |
| 1199 | }; |
| 1200 | |
| 1201 | |
| 1202 | /* |
| 1203 | * msg_data_Object |
| 1204 | * typewrapper for MessageData class |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1205 | * !modified @ 061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1206 | */ |
| 1207 | typedef struct |
| 1208 | { |
| 1209 | PyObject_HEAD |
| 1210 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1211 | /*pjsip_hdr hdr_list;*/ |
| 1212 | PyObject * hdr_list; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1213 | PyObject * content_type; |
| 1214 | PyObject * msg_body; |
| 1215 | } msg_data_Object; |
| 1216 | |
| 1217 | |
| 1218 | /* |
| 1219 | * msg_data_dealloc |
| 1220 | * deletes a msg_data |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1221 | * !modified @ 061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1222 | */ |
| 1223 | static void msg_data_dealloc(msg_data_Object* self) |
| 1224 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1225 | Py_XDECREF(self->hdr_list); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1226 | Py_XDECREF(self->content_type); |
| 1227 | Py_XDECREF(self->msg_body); |
| 1228 | self->ob_type->tp_free((PyObject*)self); |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | /* |
| 1233 | * msg_data_new |
| 1234 | * constructor for msg_data object |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1235 | * !modified @ 061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1236 | */ |
| 1237 | static PyObject * msg_data_new(PyTypeObject *type, PyObject *args, |
| 1238 | PyObject *kwds) |
| 1239 | { |
| 1240 | msg_data_Object *self; |
| 1241 | |
| 1242 | self = (msg_data_Object *)type->tp_alloc(type, 0); |
| 1243 | if (self != NULL) |
| 1244 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1245 | Py_INCREF(Py_None); |
| 1246 | self->hdr_list = Py_None; |
| 1247 | if (self->hdr_list == NULL) |
| 1248 | { |
| 1249 | Py_DECREF(self); |
| 1250 | return NULL; |
| 1251 | } |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1252 | self->content_type = PyString_FromString(""); |
| 1253 | if (self->content_type == NULL) |
| 1254 | { |
| 1255 | Py_DECREF(self); |
| 1256 | return NULL; |
| 1257 | } |
| 1258 | self->msg_body = PyString_FromString(""); |
| 1259 | if (self->msg_body == NULL) |
| 1260 | { |
| 1261 | Py_DECREF(self); |
| 1262 | return NULL; |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | return (PyObject *)self; |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | /* |
| 1271 | * msg_data_members |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1272 | * !modified @ 061206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1273 | */ |
| 1274 | static PyMemberDef msg_data_members[] = |
| 1275 | { |
| 1276 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1277 | "hdr_list", T_OBJECT_EX, offsetof(msg_data_Object, hdr_list), |
| 1278 | 0, "Additional message headers as linked list." |
| 1279 | }, |
| 1280 | { |
| 1281 | "content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type), |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1282 | 0, "MIME type of optional message body." |
| 1283 | }, |
| 1284 | { |
| 1285 | "msg_body", T_OBJECT_EX, offsetof(msg_data_Object, msg_body), 0, |
| 1286 | "Optional message body." |
| 1287 | }, |
| 1288 | {NULL} /* Sentinel */ |
| 1289 | }; |
| 1290 | |
| 1291 | |
| 1292 | /* |
| 1293 | * msg_data_Type |
| 1294 | */ |
| 1295 | static PyTypeObject msg_data_Type = |
| 1296 | { |
| 1297 | PyObject_HEAD_INIT(NULL) |
| 1298 | 0, /*ob_size*/ |
| 1299 | "py_pjsua.Msg_Data", /*tp_name*/ |
| 1300 | sizeof(msg_data_Object), /*tp_basicsize*/ |
| 1301 | 0, /*tp_itemsize*/ |
| 1302 | (destructor)msg_data_dealloc,/*tp_dealloc*/ |
| 1303 | 0, /*tp_print*/ |
| 1304 | 0, /*tp_getattr*/ |
| 1305 | 0, /*tp_setattr*/ |
| 1306 | 0, /*tp_compare*/ |
| 1307 | 0, /*tp_repr*/ |
| 1308 | 0, /*tp_as_number*/ |
| 1309 | 0, /*tp_as_sequence*/ |
| 1310 | 0, /*tp_as_mapping*/ |
| 1311 | 0, /*tp_hash */ |
| 1312 | 0, /*tp_call*/ |
| 1313 | 0, /*tp_str*/ |
| 1314 | 0, /*tp_getattro*/ |
| 1315 | 0, /*tp_setattro*/ |
| 1316 | 0, /*tp_as_buffer*/ |
| 1317 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1318 | "msg_data objects", /* tp_doc */ |
| 1319 | 0, /* tp_traverse */ |
| 1320 | 0, /* tp_clear */ |
| 1321 | 0, /* tp_richcompare */ |
| 1322 | 0, /* tp_weaklistoffset */ |
| 1323 | 0, /* tp_iter */ |
| 1324 | 0, /* tp_iternext */ |
| 1325 | 0, /* tp_methods */ |
| 1326 | msg_data_members, /* tp_members */ |
| 1327 | 0, /* tp_getset */ |
| 1328 | 0, /* tp_base */ |
| 1329 | 0, /* tp_dict */ |
| 1330 | 0, /* tp_descr_get */ |
| 1331 | 0, /* tp_descr_set */ |
| 1332 | 0, /* tp_dictoffset */ |
| 1333 | 0, /* tp_init */ |
| 1334 | 0, /* tp_alloc */ |
| 1335 | msg_data_new, /* tp_new */ |
| 1336 | |
| 1337 | }; |
| 1338 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1339 | /* |
| 1340 | * translate_hdr |
| 1341 | * internal function |
| 1342 | * translate from hdr_list to pjsip_generic_string_hdr |
| 1343 | */ |
| 1344 | void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list) |
| 1345 | { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 1346 | pj_list_init(hdr); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1347 | |
| 1348 | if (PyList_Check(py_hdr_list)) { |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 1349 | int i; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1350 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1351 | for (i = 0; i < PyList_Size(py_hdr_list); i++) |
| 1352 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1353 | pj_str_t hname, hvalue; |
| 1354 | pjsip_generic_string_hdr * new_hdr; |
| 1355 | PyObject * tuple = PyList_GetItem(py_hdr_list, i); |
| 1356 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1357 | if (PyTuple_Check(tuple)) |
| 1358 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1359 | hname.ptr = PyString_AsString(PyTuple_GetItem(tuple,0)); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1360 | hname.slen = strlen(PyString_AsString |
| 1361 | (PyTuple_GetItem(tuple,0))); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1362 | hvalue.ptr = PyString_AsString(PyTuple_GetItem(tuple,1)); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1363 | hvalue.slen = strlen(PyString_AsString |
| 1364 | (PyTuple_GetItem(tuple,1))); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1365 | } else { |
| 1366 | hname.ptr = ""; |
| 1367 | hname.slen = 0; |
| 1368 | hvalue.ptr = ""; |
| 1369 | hvalue.slen = 0; |
| 1370 | } |
| 1371 | new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue); |
| 1372 | pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr); |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | /* |
| 1378 | * translate_hdr_rev |
| 1379 | * internal function |
| 1380 | * translate from pjsip_generic_string_hdr to hdr_list |
| 1381 | */ |
| 1382 | |
| 1383 | void translate_hdr_rev(pjsip_generic_string_hdr *hdr, PyObject *py_hdr_list) |
| 1384 | { |
| 1385 | int i; |
| 1386 | int len; |
| 1387 | pjsip_generic_string_hdr * p_hdr; |
| 1388 | |
| 1389 | len = pj_list_size(hdr); |
| 1390 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1391 | if (len > 0) |
| 1392 | { |
| 1393 | p_hdr = hdr; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1394 | Py_XDECREF(py_hdr_list); |
| 1395 | py_hdr_list = PyList_New(len); |
| 1396 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1397 | for (i = 0; i < len && p_hdr != NULL; i++) |
| 1398 | { |
| 1399 | PyObject * tuple; |
| 1400 | PyObject * str; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1401 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1402 | tuple = PyTuple_New(2); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1403 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1404 | str = PyString_FromStringAndSize(p_hdr->name.ptr, p_hdr->name.slen); |
| 1405 | PyTuple_SetItem(tuple, 0, str); |
| 1406 | str = PyString_FromStringAndSize |
| 1407 | (hdr->hvalue.ptr, p_hdr->hvalue.slen); |
| 1408 | PyTuple_SetItem(tuple, 1, str); |
| 1409 | PyList_SetItem(py_hdr_list, i, tuple); |
| 1410 | p_hdr = p_hdr->next; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | } |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * pj_pool_Object |
| 1419 | */ |
| 1420 | typedef struct |
| 1421 | { |
| 1422 | PyObject_HEAD |
| 1423 | /* Type-specific fields go here. */ |
| 1424 | pj_pool_t * pool; |
| 1425 | } pj_pool_Object; |
| 1426 | |
| 1427 | |
| 1428 | /* |
| 1429 | * pj_pool_Type |
| 1430 | */ |
| 1431 | static PyTypeObject pj_pool_Type = |
| 1432 | { |
| 1433 | PyObject_HEAD_INIT(NULL) |
| 1434 | 0, /*ob_size*/ |
| 1435 | "py_pjsua.PJ_Pool", /*tp_name*/ |
| 1436 | sizeof(pj_pool_Object), /*tp_basicsize*/ |
| 1437 | 0, /*tp_itemsize*/ |
| 1438 | 0, /*tp_dealloc*/ |
| 1439 | 0, /*tp_print*/ |
| 1440 | 0, /*tp_getattr*/ |
| 1441 | 0, /*tp_setattr*/ |
| 1442 | 0, /*tp_compare*/ |
| 1443 | 0, /*tp_repr*/ |
| 1444 | 0, /*tp_as_number*/ |
| 1445 | 0, /*tp_as_sequence*/ |
| 1446 | 0, /*tp_as_mapping*/ |
| 1447 | 0, /*tp_hash */ |
| 1448 | 0, /*tp_call*/ |
| 1449 | 0, /*tp_str*/ |
| 1450 | 0, /*tp_getattro*/ |
| 1451 | 0, /*tp_setattro*/ |
| 1452 | 0, /*tp_as_buffer*/ |
| 1453 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1454 | "pj_pool_t objects", /* tp_doc */ |
| 1455 | |
| 1456 | }; |
| 1457 | |
| 1458 | |
| 1459 | /* |
| 1460 | * pjsip_endpoint_Object |
| 1461 | */ |
| 1462 | typedef struct |
| 1463 | { |
| 1464 | PyObject_HEAD |
| 1465 | /* Type-specific fields go here. */ |
| 1466 | pjsip_endpoint * endpt; |
| 1467 | } pjsip_endpoint_Object; |
| 1468 | |
| 1469 | |
| 1470 | /* |
| 1471 | * pjsip_endpoint_Type |
| 1472 | */ |
| 1473 | static PyTypeObject pjsip_endpoint_Type = |
| 1474 | { |
| 1475 | PyObject_HEAD_INIT(NULL) |
| 1476 | 0, /*ob_size*/ |
| 1477 | "py_pjsua.PJSIP_Endpoint", /*tp_name*/ |
| 1478 | sizeof(pjsip_endpoint_Object),/*tp_basicsize*/ |
| 1479 | 0, /*tp_itemsize*/ |
| 1480 | 0, /*tp_dealloc*/ |
| 1481 | 0, /*tp_print*/ |
| 1482 | 0, /*tp_getattr*/ |
| 1483 | 0, /*tp_setattr*/ |
| 1484 | 0, /*tp_compare*/ |
| 1485 | 0, /*tp_repr*/ |
| 1486 | 0, /*tp_as_number*/ |
| 1487 | 0, /*tp_as_sequence*/ |
| 1488 | 0, /*tp_as_mapping*/ |
| 1489 | 0, /*tp_hash */ |
| 1490 | 0, /*tp_call*/ |
| 1491 | 0, /*tp_str*/ |
| 1492 | 0, /*tp_getattro*/ |
| 1493 | 0, /*tp_setattro*/ |
| 1494 | 0, /*tp_as_buffer*/ |
| 1495 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1496 | "pjsip_endpoint objects", /* tp_doc */ |
| 1497 | }; |
| 1498 | |
| 1499 | |
| 1500 | /* |
| 1501 | * pjmedia_endpt_Object |
| 1502 | */ |
| 1503 | typedef struct |
| 1504 | { |
| 1505 | PyObject_HEAD |
| 1506 | /* Type-specific fields go here. */ |
| 1507 | pjmedia_endpt * endpt; |
| 1508 | } pjmedia_endpt_Object; |
| 1509 | |
| 1510 | |
| 1511 | /* |
| 1512 | * pjmedia_endpt_Type |
| 1513 | */ |
| 1514 | static PyTypeObject pjmedia_endpt_Type = |
| 1515 | { |
| 1516 | PyObject_HEAD_INIT(NULL) |
| 1517 | 0, /*ob_size*/ |
| 1518 | "py_pjsua.PJMedia_Endpt", /*tp_name*/ |
| 1519 | sizeof(pjmedia_endpt_Object), /*tp_basicsize*/ |
| 1520 | 0, /*tp_itemsize*/ |
| 1521 | 0, /*tp_dealloc*/ |
| 1522 | 0, /*tp_print*/ |
| 1523 | 0, /*tp_getattr*/ |
| 1524 | 0, /*tp_setattr*/ |
| 1525 | 0, /*tp_compare*/ |
| 1526 | 0, /*tp_repr*/ |
| 1527 | 0, /*tp_as_number*/ |
| 1528 | 0, /*tp_as_sequence*/ |
| 1529 | 0, /*tp_as_mapping*/ |
| 1530 | 0, /*tp_hash */ |
| 1531 | 0, /*tp_call*/ |
| 1532 | 0, /*tp_str*/ |
| 1533 | 0, /*tp_getattro*/ |
| 1534 | 0, /*tp_setattro*/ |
| 1535 | 0, /*tp_as_buffer*/ |
| 1536 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1537 | "pjmedia_endpt objects", /* tp_doc */ |
| 1538 | |
| 1539 | }; |
| 1540 | |
| 1541 | |
| 1542 | /* |
| 1543 | * pj_pool_factory_Object |
| 1544 | */ |
| 1545 | typedef struct |
| 1546 | { |
| 1547 | PyObject_HEAD |
| 1548 | /* Type-specific fields go here. */ |
| 1549 | pj_pool_factory * pool_fact; |
| 1550 | } pj_pool_factory_Object; |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | /* |
| 1555 | * pj_pool_factory_Type |
| 1556 | */ |
| 1557 | static PyTypeObject pj_pool_factory_Type = |
| 1558 | { |
| 1559 | PyObject_HEAD_INIT(NULL) |
| 1560 | 0, /*ob_size*/ |
| 1561 | "py_pjsua.PJ_Pool_Factory",/*tp_name*/ |
| 1562 | sizeof(pj_pool_factory_Object), /*tp_basicsize*/ |
| 1563 | 0, /*tp_itemsize*/ |
| 1564 | 0, /*tp_dealloc*/ |
| 1565 | 0, /*tp_print*/ |
| 1566 | 0, /*tp_getattr*/ |
| 1567 | 0, /*tp_setattr*/ |
| 1568 | 0, /*tp_compare*/ |
| 1569 | 0, /*tp_repr*/ |
| 1570 | 0, /*tp_as_number*/ |
| 1571 | 0, /*tp_as_sequence*/ |
| 1572 | 0, /*tp_as_mapping*/ |
| 1573 | 0, /*tp_hash */ |
| 1574 | 0, /*tp_call*/ |
| 1575 | 0, /*tp_str*/ |
| 1576 | 0, /*tp_getattro*/ |
| 1577 | 0, /*tp_setattro*/ |
| 1578 | 0, /*tp_as_buffer*/ |
| 1579 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1580 | "pj_pool_factory objects", /* tp_doc */ |
| 1581 | |
| 1582 | }; |
| 1583 | |
| 1584 | |
| 1585 | /* |
| 1586 | * pjsip_cred_info_Object |
| 1587 | */ |
| 1588 | typedef struct |
| 1589 | { |
| 1590 | PyObject_HEAD |
| 1591 | /* Type-specific fields go here. */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1592 | PyObject * realm; |
| 1593 | PyObject * scheme; |
| 1594 | PyObject * username; |
| 1595 | int data_type; |
| 1596 | PyObject * data; |
| 1597 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1598 | } pjsip_cred_info_Object; |
| 1599 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1600 | /* |
| 1601 | * cred_info_dealloc |
| 1602 | * deletes a cred info from memory |
| 1603 | */ |
| 1604 | static void pjsip_cred_info_dealloc(pjsip_cred_info_Object* self) |
| 1605 | { |
| 1606 | Py_XDECREF(self->realm); |
| 1607 | Py_XDECREF(self->scheme); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1608 | Py_XDECREF(self->username); |
| 1609 | Py_XDECREF(self->data); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1610 | self->ob_type->tp_free((PyObject*)self); |
| 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | /* |
| 1615 | * cred_info_new |
| 1616 | * constructor for cred_info object |
| 1617 | */ |
| 1618 | static PyObject * pjsip_cred_info_new(PyTypeObject *type, PyObject *args, |
| 1619 | PyObject *kwds) |
| 1620 | { |
| 1621 | pjsip_cred_info_Object *self; |
| 1622 | |
| 1623 | self = (pjsip_cred_info_Object *)type->tp_alloc(type, 0); |
| 1624 | if (self != NULL) |
| 1625 | { |
| 1626 | self->realm = PyString_FromString(""); |
| 1627 | if (self->realm == NULL) |
| 1628 | { |
| 1629 | Py_DECREF(self); |
| 1630 | return NULL; |
| 1631 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1632 | self->scheme = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1633 | if (self->scheme == NULL) |
| 1634 | { |
| 1635 | Py_DECREF(self); |
| 1636 | return NULL; |
| 1637 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1638 | self->username = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1639 | if (self->username == NULL) |
| 1640 | { |
| 1641 | Py_DECREF(self); |
| 1642 | return NULL; |
| 1643 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1644 | self->data = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1645 | if (self->data == NULL) |
| 1646 | { |
| 1647 | Py_DECREF(self); |
| 1648 | return NULL; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | return (PyObject *)self; |
| 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | /* |
| 1657 | * pjsip_cred_info_members |
| 1658 | */ |
| 1659 | static PyMemberDef pjsip_cred_info_members[] = |
| 1660 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1661 | { |
| 1662 | "realm", T_OBJECT_EX, |
| 1663 | offsetof(pjsip_cred_info_Object, realm), 0, |
| 1664 | "Realm" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1665 | }, |
| 1666 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1667 | "scheme", T_OBJECT_EX, |
| 1668 | offsetof(pjsip_cred_info_Object, scheme), 0, |
| 1669 | "Scheme" |
| 1670 | }, |
| 1671 | { |
| 1672 | "username", T_OBJECT_EX, |
| 1673 | offsetof(pjsip_cred_info_Object, username), 0, |
| 1674 | "User name" |
| 1675 | }, |
| 1676 | { |
| 1677 | "data", T_OBJECT_EX, |
| 1678 | offsetof(pjsip_cred_info_Object, data), 0, |
| 1679 | "The data, which can be a plaintext password or a hashed digest. " |
| 1680 | }, |
| 1681 | { |
| 1682 | "data_type", T_INT, offsetof(pjsip_cred_info_Object, data_type), 0, |
| 1683 | "Type of data" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1684 | }, |
| 1685 | |
| 1686 | {NULL} /* Sentinel */ |
| 1687 | }; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1688 | |
| 1689 | /* |
| 1690 | * pjsip_cred_info_Type |
| 1691 | */ |
| 1692 | static PyTypeObject pjsip_cred_info_Type = |
| 1693 | { |
| 1694 | PyObject_HEAD_INIT(NULL) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1695 | 0, /*ob_size*/ |
| 1696 | "py_pjsua.PJSIP_Cred_Info", /*tp_name*/ |
| 1697 | sizeof(pjsip_cred_info_Object), /*tp_basicsize*/ |
| 1698 | 0, /*tp_itemsize*/ |
| 1699 | (destructor)pjsip_cred_info_dealloc,/*tp_dealloc*/ |
| 1700 | 0, /*tp_print*/ |
| 1701 | 0, /*tp_getattr*/ |
| 1702 | 0, /*tp_setattr*/ |
| 1703 | 0, /*tp_compare*/ |
| 1704 | 0, /*tp_repr*/ |
| 1705 | 0, /*tp_as_number*/ |
| 1706 | 0, /*tp_as_sequence*/ |
| 1707 | 0, /*tp_as_mapping*/ |
| 1708 | 0, /*tp_hash */ |
| 1709 | 0, /*tp_call*/ |
| 1710 | 0, /*tp_str*/ |
| 1711 | 0, /*tp_getattro*/ |
| 1712 | 0, /*tp_setattro*/ |
| 1713 | 0, /*tp_as_buffer*/ |
| 1714 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1715 | "PJSIP Cred Info objects", /* tp_doc */ |
| 1716 | 0, /* tp_traverse */ |
| 1717 | 0, /* tp_clear */ |
| 1718 | 0, /* tp_richcompare */ |
| 1719 | 0, /* tp_weaklistoffset */ |
| 1720 | 0, /* tp_iter */ |
| 1721 | 0, /* tp_iternext */ |
| 1722 | 0, /* tp_methods */ |
| 1723 | pjsip_cred_info_members, /* tp_members */ |
| 1724 | 0, /* tp_getset */ |
| 1725 | 0, /* tp_base */ |
| 1726 | 0, /* tp_dict */ |
| 1727 | 0, /* tp_descr_get */ |
| 1728 | 0, /* tp_descr_set */ |
| 1729 | 0, /* tp_dictoffset */ |
| 1730 | 0, /* tp_init */ |
| 1731 | 0, /* tp_alloc */ |
| 1732 | pjsip_cred_info_new, /* tp_new */ |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1733 | |
| 1734 | }; |
| 1735 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1736 | /* |
| 1737 | * py_pjsua_thread_register |
| 1738 | * !added @ 061206 |
| 1739 | */ |
| 1740 | static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject |
| 1741 | *pArgs) |
| 1742 | { |
| 1743 | |
| 1744 | pj_status_t status; |
| 1745 | const char *name; |
| 1746 | PyObject *py_desc; |
| 1747 | pj_thread_t *thread; |
| 1748 | void *thread_desc; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 1749 | #if 0 |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1750 | int size; |
| 1751 | int i; |
| 1752 | int *td; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 1753 | #endif |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1754 | |
| 1755 | if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) |
| 1756 | { |
| 1757 | return NULL; |
| 1758 | } |
| 1759 | #if 0 |
| 1760 | size = PyList_Size(py_desc); |
| 1761 | td = (int *)malloc(size * sizeof(int)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1762 | for (i = 0; i < size; i++) |
| 1763 | { |
| 1764 | if (!PyArg_Parse(PyList_GetItem(py_desc,i),"i", td[i])) |
| 1765 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1766 | return NULL; |
| 1767 | } |
| 1768 | } |
| 1769 | thread_desc = td; |
| 1770 | #else |
| 1771 | thread_desc = malloc(sizeof(pj_thread_desc)); |
| 1772 | #endif |
| 1773 | status = pj_thread_register(name, thread_desc, &thread); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 1774 | |
| 1775 | if (status == PJ_SUCCESS) |
| 1776 | status = pj_thread_local_set(thread_id, (void*)1); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1777 | return Py_BuildValue("i",status); |
| 1778 | } |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1779 | |
| 1780 | /* |
| 1781 | * py_pjsua_logging_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1782 | * !modified @ 051206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1783 | */ |
| 1784 | static PyObject *py_pjsua_logging_config_default(PyObject *pSelf, |
| 1785 | PyObject *pArgs) |
| 1786 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1787 | logging_config_Object *obj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1788 | pjsua_logging_config cfg; |
| 1789 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1790 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1791 | { |
| 1792 | return NULL; |
| 1793 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1794 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1795 | pjsua_logging_config_default(&cfg); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1796 | obj = (logging_config_Object *) logging_config_new |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1797 | (&logging_config_Type,NULL,NULL); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1798 | obj->msg_logging = cfg.msg_logging; |
| 1799 | obj->level = cfg.level; |
| 1800 | obj->console_level = cfg.console_level; |
| 1801 | obj->decor = cfg.decor; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1802 | |
| 1803 | return (PyObject *)obj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | |
| 1807 | /* |
| 1808 | * py_pjsua_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1809 | * !modified @ 051206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1810 | */ |
| 1811 | static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs) |
| 1812 | { |
| 1813 | config_Object *obj; |
| 1814 | pjsua_config cfg; |
| 1815 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1816 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1817 | { |
| 1818 | return NULL; |
| 1819 | } |
| 1820 | pjsua_config_default(&cfg); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1821 | obj = (config_Object *) config_new(&config_Type, NULL, NULL); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1822 | obj->max_calls = cfg.max_calls; |
| 1823 | obj->thread_cnt = cfg.thread_cnt; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1824 | return (PyObject *)obj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | |
| 1828 | /* |
| 1829 | * py_pjsua_media_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1830 | * !modified @ 051206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1831 | */ |
| 1832 | static PyObject * py_pjsua_media_config_default(PyObject *pSelf, |
| 1833 | PyObject *pArgs) |
| 1834 | { |
| 1835 | media_config_Object *obj; |
| 1836 | pjsua_media_config cfg; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1837 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1838 | { |
| 1839 | return NULL; |
| 1840 | } |
| 1841 | pjsua_media_config_default(&cfg); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1842 | obj = (media_config_Object *)PyType_GenericNew |
| 1843 | (&media_config_Type, NULL, NULL); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1844 | obj->clock_rate = cfg.clock_rate; |
| 1845 | obj->ec_options = cfg.ec_options; |
| 1846 | obj->ec_tail_len = cfg.ec_tail_len; |
| 1847 | obj->has_ioqueue = cfg.has_ioqueue; |
| 1848 | obj->ilbc_mode = cfg.ilbc_mode; |
| 1849 | obj->max_media_ports = cfg.max_media_ports; |
| 1850 | obj->no_vad = cfg.no_vad; |
| 1851 | obj->ptime = cfg.ptime; |
| 1852 | obj->quality = cfg.quality; |
| 1853 | obj->rx_drop_pct = cfg.rx_drop_pct; |
| 1854 | obj->thread_cnt = cfg.thread_cnt; |
| 1855 | obj->tx_drop_pct = cfg.tx_drop_pct; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1856 | return (PyObject *)obj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | /* |
| 1861 | * py_pjsua_msg_data_init |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1862 | * !modified @ 051206 |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1863 | */ |
| 1864 | static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs) |
| 1865 | { |
| 1866 | msg_data_Object *obj; |
| 1867 | pjsua_msg_data msg; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1868 | |
| 1869 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1870 | { |
| 1871 | return NULL; |
| 1872 | } |
| 1873 | pjsua_msg_data_init(&msg); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1874 | obj = (msg_data_Object *)msg_data_new(&msg_data_Type, NULL, NULL); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1875 | Py_XDECREF(obj->content_type); |
| 1876 | obj->content_type = PyString_FromStringAndSize( |
| 1877 | msg.content_type.ptr, msg.content_type.slen |
| 1878 | ); |
| 1879 | Py_XDECREF(obj->msg_body); |
| 1880 | obj->msg_body = PyString_FromStringAndSize( |
| 1881 | msg.msg_body.ptr, msg.msg_body.slen |
| 1882 | ); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1883 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1884 | translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 1885 | |
| 1886 | return (PyObject *)obj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | |
| 1890 | /* |
| 1891 | * py_pjsua_reconfigure_logging |
| 1892 | */ |
| 1893 | static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs) |
| 1894 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1895 | PyObject * logObj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1896 | logging_config_Object *log; |
| 1897 | pjsua_logging_config cfg; |
| 1898 | pj_status_t status; |
| 1899 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1900 | if (!PyArg_ParseTuple(pArgs, "O", &logObj)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1901 | { |
| 1902 | return NULL; |
| 1903 | } |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1904 | if (logObj != Py_None) |
| 1905 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1906 | log = (logging_config_Object *)logObj; |
| 1907 | cfg.msg_logging = log->msg_logging; |
| 1908 | cfg.level = log->level; |
| 1909 | cfg.console_level = log->console_level; |
| 1910 | cfg.decor = log->decor; |
| 1911 | cfg.log_filename.ptr = PyString_AsString(log->log_filename); |
| 1912 | cfg.log_filename.slen = strlen(cfg.log_filename.ptr); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 1913 | Py_XDECREF(obj_log_cb); |
| 1914 | obj_log_cb = log->cb; |
| 1915 | Py_INCREF(obj_log_cb); |
| 1916 | cfg.cb = &cb_log_cb; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 1917 | status = pjsua_reconfigure_logging(&cfg); |
| 1918 | } else { |
| 1919 | status = pjsua_reconfigure_logging(NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 1920 | } |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1921 | return Py_BuildValue("i",status); |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | /* |
| 1926 | * py_pjsua_pool_create |
| 1927 | */ |
| 1928 | static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs) |
| 1929 | { |
| 1930 | pj_size_t init_size; |
| 1931 | pj_size_t increment; |
| 1932 | const char * name; |
| 1933 | pj_pool_t *p; |
| 1934 | pj_pool_Object *pool; |
| 1935 | |
| 1936 | if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment)) |
| 1937 | { |
| 1938 | return NULL; |
| 1939 | } |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 1940 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1941 | p = pjsua_pool_create(name, init_size, increment); |
| 1942 | pool = (pj_pool_Object *)PyType_GenericNew(&pj_pool_Type, NULL, NULL); |
| 1943 | pool->pool = p; |
| 1944 | return (PyObject *)pool; |
| 1945 | |
| 1946 | } |
| 1947 | |
| 1948 | |
| 1949 | /* |
| 1950 | * py_pjsua_get_pjsip_endpt |
| 1951 | */ |
| 1952 | static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs) |
| 1953 | { |
| 1954 | pjsip_endpoint_Object *endpt; |
| 1955 | pjsip_endpoint *e; |
| 1956 | |
| 1957 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1958 | { |
| 1959 | return NULL; |
| 1960 | } |
| 1961 | e = pjsua_get_pjsip_endpt(); |
| 1962 | endpt = (pjsip_endpoint_Object *)PyType_GenericNew( |
| 1963 | &pjsip_endpoint_Type, NULL, NULL |
| 1964 | ); |
| 1965 | endpt->endpt = e; |
| 1966 | return (PyObject *)endpt; |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | /* |
| 1971 | * py_pjsua_get_pjmedia_endpt |
| 1972 | */ |
| 1973 | static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs) |
| 1974 | { |
| 1975 | pjmedia_endpt_Object *endpt; |
| 1976 | pjmedia_endpt *e; |
| 1977 | |
| 1978 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1979 | { |
| 1980 | return NULL; |
| 1981 | } |
| 1982 | e = pjsua_get_pjmedia_endpt(); |
| 1983 | endpt = (pjmedia_endpt_Object *)PyType_GenericNew( |
| 1984 | &pjmedia_endpt_Type, NULL, NULL |
| 1985 | ); |
| 1986 | endpt->endpt = e; |
| 1987 | return (PyObject *)endpt; |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | /* |
| 1992 | * py_pjsua_get_pool_factory |
| 1993 | */ |
| 1994 | static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs) |
| 1995 | { |
| 1996 | pj_pool_factory_Object *pool; |
| 1997 | pj_pool_factory *p; |
| 1998 | |
| 1999 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2000 | { |
| 2001 | return NULL; |
| 2002 | } |
| 2003 | p = pjsua_get_pool_factory(); |
| 2004 | pool = (pj_pool_factory_Object *)PyType_GenericNew( |
| 2005 | &pj_pool_factory_Type, NULL, NULL |
| 2006 | ); |
| 2007 | pool->pool_fact = p; |
| 2008 | return (PyObject *)pool; |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | /* |
| 2013 | * py_pjsua_perror |
| 2014 | */ |
| 2015 | static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs) |
| 2016 | { |
| 2017 | const char *sender; |
| 2018 | const char *title; |
| 2019 | pj_status_t status; |
| 2020 | if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) |
| 2021 | { |
| 2022 | return NULL; |
| 2023 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2024 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2025 | pjsua_perror(sender, title, status); |
| 2026 | Py_INCREF(Py_None); |
| 2027 | return Py_None; |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | /* |
| 2032 | * py_pjsua_create |
| 2033 | */ |
| 2034 | static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs) |
| 2035 | { |
| 2036 | pj_status_t status; |
| 2037 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2038 | { |
| 2039 | return NULL; |
| 2040 | } |
| 2041 | status = pjsua_create(); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2042 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2043 | if (status == PJ_SUCCESS) |
| 2044 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2045 | status = pj_thread_local_alloc(&thread_id); |
| 2046 | if (status == PJ_SUCCESS) |
| 2047 | status = pj_thread_local_set(thread_id, (void*)1); |
| 2048 | } |
| 2049 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2050 | return Py_BuildValue("i",status); |
| 2051 | } |
| 2052 | |
| 2053 | |
| 2054 | /* |
| 2055 | * py_pjsua_init |
| 2056 | */ |
| 2057 | static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs) |
| 2058 | { |
| 2059 | pj_status_t status; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2060 | PyObject * ua_cfgObj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2061 | config_Object * ua_cfg; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2062 | PyObject * log_cfgObj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2063 | logging_config_Object * log_cfg; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2064 | PyObject * media_cfgObj; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2065 | media_config_Object * media_cfg; |
| 2066 | pjsua_config cfg_ua; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2067 | pjsua_config * p_cfg_ua; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2068 | pjsua_logging_config cfg_log; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2069 | pjsua_logging_config * p_cfg_log; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2070 | pjsua_media_config cfg_media; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2071 | pjsua_media_config * p_cfg_media; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2072 | unsigned i; |
| 2073 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2074 | if (!PyArg_ParseTuple(pArgs, "OOO", &ua_cfgObj, &log_cfgObj,&media_cfgObj)) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2075 | { |
| 2076 | return NULL; |
| 2077 | } |
| 2078 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2079 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2080 | pjsua_config_default(&cfg_ua); |
| 2081 | pjsua_logging_config_default(&cfg_log); |
| 2082 | pjsua_media_config_default(&cfg_media); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2083 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2084 | if (ua_cfgObj != Py_None) |
| 2085 | { |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2086 | ua_cfg = (config_Object *)ua_cfgObj; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2087 | cfg_ua.cred_count = ua_cfg->cred_count; |
| 2088 | for (i = 0; i < 4; i++) |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2089 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2090 | cfg_ua.cred_info[i] = ua_cfg->cred_info[i]; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2091 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2092 | cfg_ua.max_calls = ua_cfg->max_calls; |
| 2093 | for (i = 0; i < PJSUA_ACC_MAX_PROXIES; i++) |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2094 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2095 | cfg_ua.outbound_proxy[i] = ua_cfg->outbound_proxy[i]; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | g_obj_callback = ua_cfg->cb; |
| 2099 | Py_INCREF(g_obj_callback); |
| 2100 | |
| 2101 | cfg_ua.cb.on_call_state = &cb_on_call_state; |
| 2102 | cfg_ua.cb.on_incoming_call = &cb_on_incoming_call; |
| 2103 | cfg_ua.cb.on_call_media_state = &cb_on_call_media_state; |
| 2104 | cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request; |
| 2105 | cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status; |
| 2106 | cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request; |
| 2107 | cfg_ua.cb.on_call_replaced = &cb_on_call_replaced; |
| 2108 | cfg_ua.cb.on_reg_state = &cb_on_reg_state; |
| 2109 | cfg_ua.cb.on_buddy_state = &cb_on_buddy_state; |
| 2110 | cfg_ua.cb.on_pager = &cb_on_pager; |
| 2111 | cfg_ua.cb.on_pager_status = &cb_on_pager_status; |
| 2112 | cfg_ua.cb.on_typing = &cb_on_typing; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2113 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2114 | cfg_ua.outbound_proxy_cnt = ua_cfg->outbound_proxy_cnt; |
| 2115 | cfg_ua.thread_cnt = ua_cfg->thread_cnt; |
| 2116 | cfg_ua.user_agent.ptr = PyString_AsString(ua_cfg->user_agent); |
| 2117 | cfg_ua.user_agent.slen = strlen(cfg_ua.user_agent.ptr); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2118 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2119 | p_cfg_ua = &cfg_ua; |
| 2120 | } else { |
| 2121 | p_cfg_ua = NULL; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2124 | if (log_cfgObj != Py_None) |
| 2125 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2126 | log_cfg = (logging_config_Object *)log_cfgObj; |
| 2127 | cfg_log.msg_logging = log_cfg->msg_logging; |
| 2128 | cfg_log.level = log_cfg->level; |
| 2129 | cfg_log.console_level = log_cfg->console_level; |
| 2130 | cfg_log.decor = log_cfg->decor; |
| 2131 | cfg_log.log_filename.ptr = PyString_AsString(log_cfg->log_filename); |
| 2132 | cfg_log.log_filename.slen = strlen(cfg_log.log_filename.ptr); |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 2133 | Py_XDECREF(obj_log_cb); |
| 2134 | obj_log_cb = log_cfg->cb; |
| 2135 | Py_INCREF(obj_log_cb); |
| 2136 | cfg_log.cb = &cb_log_cb; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2137 | p_cfg_log = &cfg_log; |
| 2138 | } else { |
| 2139 | p_cfg_log = NULL; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2142 | if (media_cfgObj != Py_None) |
| 2143 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2144 | media_cfg = (media_config_Object *)media_cfgObj; |
| 2145 | cfg_media.clock_rate = media_cfg->clock_rate; |
| 2146 | cfg_media.ec_options = media_cfg->ec_options; |
| 2147 | cfg_media.ec_tail_len = media_cfg->ec_tail_len; |
| 2148 | cfg_media.has_ioqueue = media_cfg->has_ioqueue; |
| 2149 | cfg_media.ilbc_mode = media_cfg->ilbc_mode; |
| 2150 | cfg_media.max_media_ports = media_cfg->max_media_ports; |
| 2151 | cfg_media.no_vad = media_cfg->no_vad; |
| 2152 | cfg_media.ptime = media_cfg->ptime; |
| 2153 | cfg_media.quality = media_cfg->quality; |
| 2154 | cfg_media.rx_drop_pct = media_cfg->rx_drop_pct; |
| 2155 | cfg_media.thread_cnt = media_cfg->thread_cnt; |
| 2156 | cfg_media.tx_drop_pct = media_cfg->tx_drop_pct; |
| 2157 | p_cfg_media = &cfg_media; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2158 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2159 | p_cfg_media = NULL; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 2162 | status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2163 | return Py_BuildValue("i",status); |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | /* |
| 2168 | * py_pjsua_start |
| 2169 | */ |
| 2170 | static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs) |
| 2171 | { |
| 2172 | pj_status_t status; |
| 2173 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2174 | { |
| 2175 | return NULL; |
| 2176 | } |
| 2177 | status = pjsua_start(); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 2178 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2179 | return Py_BuildValue("i",status); |
| 2180 | } |
| 2181 | |
| 2182 | |
| 2183 | /* |
| 2184 | * py_pjsua_destroy |
| 2185 | */ |
| 2186 | static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs) |
| 2187 | { |
| 2188 | pj_status_t status; |
| 2189 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2190 | { |
| 2191 | return NULL; |
| 2192 | } |
| 2193 | status = pjsua_destroy(); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 2194 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2195 | return Py_BuildValue("i",status); |
| 2196 | } |
| 2197 | |
| 2198 | |
| 2199 | /* |
| 2200 | * py_pjsua_handle_events |
| 2201 | */ |
| 2202 | static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs) |
| 2203 | { |
| 2204 | int ret; |
| 2205 | unsigned msec; |
| 2206 | if (!PyArg_ParseTuple(pArgs, "i", &msec)) |
| 2207 | { |
| 2208 | return NULL; |
| 2209 | } |
Benny Prijono | 4759f9c | 2007-02-14 02:15:19 +0000 | [diff] [blame] | 2210 | |
| 2211 | /* Since handle_events() will block, we must wrap it with ALLOW_THREADS |
| 2212 | * construct, or otherwise many Python blocking functions (such as |
| 2213 | * time.sleep(), readline(), etc.) may hang/block indefinitely. |
| 2214 | * See http://www.python.org/doc/current/api/threads.html for more info. |
| 2215 | */ |
| 2216 | Py_BEGIN_ALLOW_THREADS |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2217 | ret = pjsua_handle_events(msec); |
Benny Prijono | 4759f9c | 2007-02-14 02:15:19 +0000 | [diff] [blame] | 2218 | Py_END_ALLOW_THREADS |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 2219 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2220 | return Py_BuildValue("i",ret); |
| 2221 | } |
| 2222 | |
| 2223 | |
| 2224 | /* |
| 2225 | * py_pjsua_verify_sip_url |
| 2226 | */ |
| 2227 | static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs) |
| 2228 | { |
| 2229 | pj_status_t status; |
| 2230 | const char *url; |
| 2231 | if (!PyArg_ParseTuple(pArgs, "s", &url)) |
| 2232 | { |
| 2233 | return NULL; |
| 2234 | } |
| 2235 | status = pjsua_verify_sip_url(url); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 2236 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2237 | return Py_BuildValue("i",status); |
| 2238 | } |
| 2239 | |
| 2240 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2241 | /* |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2242 | * function doc |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2243 | */ |
| 2244 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2245 | static char pjsua_thread_register_doc[] = |
| 2246 | "int py_pjsua.thread_register(string name, int[] desc)"; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2247 | static char pjsua_perror_doc[] = |
| 2248 | "void py_pjsua.perror (string sender, string title, int status) " |
| 2249 | "Display error message for the specified error code. Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2250 | "sender: The log sender field; " |
| 2251 | "title: Message title for the error; " |
| 2252 | "status: Status code."; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2253 | |
| 2254 | static char pjsua_create_doc[] = |
| 2255 | "int py_pjsua.create (void) " |
| 2256 | "Instantiate pjsua application. Application " |
| 2257 | "must call this function before calling any other functions, to make sure " |
| 2258 | "that the underlying libraries are properly initialized. Once this " |
| 2259 | "function has returned success, application must call pjsua_destroy() " |
| 2260 | "before quitting."; |
| 2261 | |
| 2262 | static char pjsua_init_doc[] = |
| 2263 | "int py_pjsua.init (py_pjsua.Config ua_cfg, " |
| 2264 | "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) " |
| 2265 | "Initialize pjsua with the specified settings. All the settings are " |
| 2266 | "optional, and the default values will be used when the config is not " |
| 2267 | "specified. Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2268 | "ua_cfg : User agent configuration; " |
| 2269 | "log_cfg : Optional logging configuration; " |
| 2270 | "media_cfg : Optional media configuration."; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2271 | |
| 2272 | static char pjsua_start_doc[] = |
| 2273 | "int py_pjsua.start (void) " |
| 2274 | "Application is recommended to call this function after all " |
| 2275 | "initialization is done, so that the library can do additional checking " |
| 2276 | "set up additional"; |
| 2277 | |
| 2278 | static char pjsua_destroy_doc[] = |
| 2279 | "int py_pjsua.destroy (void) " |
| 2280 | "Destroy pjsua This function must be called once PJSUA is created. To " |
| 2281 | "make it easier for application, application may call this function " |
| 2282 | "several times with no danger."; |
| 2283 | |
| 2284 | static char pjsua_handle_events_doc[] = |
| 2285 | "int py_pjsua.handle_events (int msec_timeout) " |
| 2286 | "Poll pjsua for events, and if necessary block the caller thread for the " |
| 2287 | "specified maximum interval (in miliseconds) Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2288 | "msec_timeout: Maximum time to wait, in miliseconds. " |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2289 | "Returns: The number of events that have been handled during the poll. " |
| 2290 | "Negative value indicates error, and application can retrieve the error " |
| 2291 | "as (err = -return_value)."; |
| 2292 | |
| 2293 | static char pjsua_verify_sip_url_doc[] = |
| 2294 | "int py_pjsua.verify_sip_url (string c_url) " |
| 2295 | "Verify that valid SIP url is given Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2296 | "c_url: The URL, as NULL terminated string."; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2297 | |
| 2298 | static char pjsua_pool_create_doc[] = |
| 2299 | "py_pjsua.PJ_Pool py_pjsua.pool_create (string name, int init_size, " |
| 2300 | "int increment) " |
| 2301 | "Create memory pool Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2302 | "name: Optional pool name; " |
| 2303 | "init_size: Initial size of the pool; " |
| 2304 | "increment: Increment size."; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2305 | |
| 2306 | static char pjsua_get_pjsip_endpt_doc[] = |
| 2307 | "py_pjsua.PJSIP_Endpoint py_pjsua.get_pjsip_endpt (void) " |
| 2308 | "Internal function to get SIP endpoint instance of pjsua, which is needed " |
| 2309 | "for example to register module, create transports, etc. Probably is only " |
| 2310 | "valid after pjsua_init() is called."; |
| 2311 | |
| 2312 | static char pjsua_get_pjmedia_endpt_doc[] = |
| 2313 | "py_pjsua.PJMedia_Endpt py_pjsua.get_pjmedia_endpt (void) " |
| 2314 | "Internal function to get media endpoint instance. Only valid after " |
| 2315 | "pjsua_init() is called."; |
| 2316 | |
| 2317 | static char pjsua_get_pool_factory_doc[] = |
| 2318 | "py_pjsua.PJ_Pool_Factory py_pjsua.get_pool_factory (void) " |
| 2319 | "Internal function to get PJSUA pool factory. Only valid after " |
| 2320 | "pjsua_init() is called."; |
| 2321 | |
| 2322 | static char pjsua_reconfigure_logging_doc[] = |
| 2323 | "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) " |
| 2324 | "Application can call this function at any time (after pjsua_create(), of " |
| 2325 | "course) to change logging settings. Parameters: " |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2326 | "c: Logging configuration."; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2327 | |
| 2328 | static char pjsua_logging_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2329 | "py_pjsua.Logging_Config py_pjsua.logging_config_default () " |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2330 | "Use this function to initialize logging config."; |
| 2331 | |
| 2332 | static char pjsua_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2333 | "py_pjsua.Config py_pjsua.config_default (). Use this function to " |
| 2334 | "initialize pjsua config. "; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2335 | |
| 2336 | static char pjsua_media_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2337 | "py_pjsua.Media_Config py_pjsua.media_config_default (). " |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2338 | "Use this function to initialize media config."; |
| 2339 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2340 | static char pjsua_msg_data_init_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2341 | "py_pjsua.Msg_Data void py_pjsua.msg_data_init () " |
| 2342 | "Initialize message data "; |
| 2343 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 2344 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2345 | /* END OF LIB BASE */ |
| 2346 | |
| 2347 | /* LIB TRANSPORT */ |
| 2348 | |
| 2349 | /* |
| 2350 | * stun_config_Object |
| 2351 | * STUN configuration |
| 2352 | */ |
| 2353 | typedef struct |
| 2354 | { |
| 2355 | PyObject_HEAD |
| 2356 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2357 | PyObject * stun_srv1; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2358 | unsigned stun_port1; |
| 2359 | PyObject * stun_srv2; |
| 2360 | unsigned stun_port2; |
| 2361 | } stun_config_Object; |
| 2362 | |
| 2363 | |
| 2364 | /* |
| 2365 | * stun_config_dealloc |
| 2366 | * deletes a stun config from memory |
| 2367 | */ |
| 2368 | static void stun_config_dealloc(stun_config_Object* self) |
| 2369 | { |
| 2370 | Py_XDECREF(self->stun_srv1); |
| 2371 | Py_XDECREF(self->stun_srv2); |
| 2372 | self->ob_type->tp_free((PyObject*)self); |
| 2373 | } |
| 2374 | |
| 2375 | |
| 2376 | /* |
| 2377 | * stun_config_new |
| 2378 | * constructor for stun_config object |
| 2379 | */ |
| 2380 | static PyObject * stun_config_new(PyTypeObject *type, PyObject *args, |
| 2381 | PyObject *kwds) |
| 2382 | { |
| 2383 | stun_config_Object *self; |
| 2384 | self = (stun_config_Object *)type->tp_alloc(type, 0); |
| 2385 | if (self != NULL) |
| 2386 | { |
| 2387 | self->stun_srv1 = PyString_FromString(""); |
| 2388 | if (self->stun_srv1 == NULL) |
| 2389 | { |
| 2390 | Py_DECREF(self); |
| 2391 | return NULL; |
| 2392 | } |
| 2393 | self->stun_srv2 = PyString_FromString(""); |
| 2394 | if (self->stun_srv2 == NULL) |
| 2395 | { |
| 2396 | Py_DECREF(self); |
| 2397 | return NULL; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | return (PyObject *)self; |
| 2402 | } |
| 2403 | |
| 2404 | |
| 2405 | /* |
| 2406 | * stun_config_members |
| 2407 | */ |
| 2408 | static PyMemberDef stun_config_members[] = |
| 2409 | { |
| 2410 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2411 | "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0, |
| 2412 | "The first STUN server IP address or hostname." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2413 | }, |
| 2414 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2415 | "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0, |
| 2416 | "Port number of the second STUN server. " |
| 2417 | "If zero, default STUN port will be used." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2418 | }, |
| 2419 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2420 | "stun_srv1", T_OBJECT_EX, |
| 2421 | offsetof(stun_config_Object, stun_srv1), 0, |
| 2422 | "The first STUN server IP address or hostname" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2423 | }, |
| 2424 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2425 | "stun_srv2", T_OBJECT_EX, |
| 2426 | offsetof(stun_config_Object, stun_srv2), 0, |
| 2427 | "Optional second STUN server IP address or hostname, for which the " |
| 2428 | "result of the mapping request will be compared to. If the value " |
| 2429 | "is empty, only one STUN server will be used" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2430 | }, |
| 2431 | {NULL} /* Sentinel */ |
| 2432 | }; |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | |
| 2437 | /* |
| 2438 | * stun_config_Type |
| 2439 | */ |
| 2440 | static PyTypeObject stun_config_Type = |
| 2441 | { |
| 2442 | PyObject_HEAD_INIT(NULL) |
| 2443 | 0, /*ob_size*/ |
| 2444 | "py_pjsua.STUN_Config", /*tp_name*/ |
| 2445 | sizeof(stun_config_Object), /*tp_basicsize*/ |
| 2446 | 0, /*tp_itemsize*/ |
| 2447 | (destructor)stun_config_dealloc,/*tp_dealloc*/ |
| 2448 | 0, /*tp_print*/ |
| 2449 | 0, /*tp_getattr*/ |
| 2450 | 0, /*tp_setattr*/ |
| 2451 | 0, /*tp_compare*/ |
| 2452 | 0, /*tp_repr*/ |
| 2453 | 0, /*tp_as_number*/ |
| 2454 | 0, /*tp_as_sequence*/ |
| 2455 | 0, /*tp_as_mapping*/ |
| 2456 | 0, /*tp_hash */ |
| 2457 | 0, /*tp_call*/ |
| 2458 | 0, /*tp_str*/ |
| 2459 | 0, /*tp_getattro*/ |
| 2460 | 0, /*tp_setattro*/ |
| 2461 | 0, /*tp_as_buffer*/ |
| 2462 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2463 | "STUN Config objects", /* tp_doc */ |
| 2464 | 0, /* tp_traverse */ |
| 2465 | 0, /* tp_clear */ |
| 2466 | 0, /* tp_richcompare */ |
| 2467 | 0, /* tp_weaklistoffset */ |
| 2468 | 0, /* tp_iter */ |
| 2469 | 0, /* tp_iternext */ |
| 2470 | 0, /* tp_methods */ |
| 2471 | stun_config_members, /* tp_members */ |
| 2472 | 0, /* tp_getset */ |
| 2473 | 0, /* tp_base */ |
| 2474 | 0, /* tp_dict */ |
| 2475 | 0, /* tp_descr_get */ |
| 2476 | 0, /* tp_descr_set */ |
| 2477 | 0, /* tp_dictoffset */ |
| 2478 | 0, /* tp_init */ |
| 2479 | 0, /* tp_alloc */ |
| 2480 | stun_config_new, /* tp_new */ |
| 2481 | |
| 2482 | }; |
| 2483 | |
| 2484 | /* |
| 2485 | * transport_config_Object |
| 2486 | * Transport configuration for creating UDP transports for both SIP |
| 2487 | * and media. |
| 2488 | */ |
| 2489 | typedef struct |
| 2490 | { |
| 2491 | PyObject_HEAD |
| 2492 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2493 | unsigned port; |
| 2494 | PyObject * public_addr; |
| 2495 | PyObject * bound_addr; |
| 2496 | int use_stun; |
| 2497 | stun_config_Object * stun_config; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2498 | } transport_config_Object; |
| 2499 | |
| 2500 | |
| 2501 | /* |
| 2502 | * transport_config_dealloc |
| 2503 | * deletes a transport config from memory |
| 2504 | */ |
| 2505 | static void transport_config_dealloc(transport_config_Object* self) |
| 2506 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2507 | Py_XDECREF(self->public_addr); |
| 2508 | Py_XDECREF(self->bound_addr); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2509 | Py_XDECREF(self->stun_config); |
| 2510 | self->ob_type->tp_free((PyObject*)self); |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | /* |
| 2515 | * transport_config_new |
| 2516 | * constructor for transport_config object |
| 2517 | */ |
| 2518 | static PyObject * transport_config_new(PyTypeObject *type, PyObject *args, |
| 2519 | PyObject *kwds) |
| 2520 | { |
| 2521 | transport_config_Object *self; |
| 2522 | |
| 2523 | self = (transport_config_Object *)type->tp_alloc(type, 0); |
| 2524 | if (self != NULL) |
| 2525 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2526 | self->public_addr = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2527 | if (self->public_addr == NULL) |
| 2528 | { |
| 2529 | Py_DECREF(self); |
| 2530 | return NULL; |
| 2531 | } |
| 2532 | self->bound_addr = PyString_FromString(""); |
| 2533 | if (self->bound_addr == NULL) |
| 2534 | { |
| 2535 | Py_DECREF(self); |
| 2536 | return NULL; |
| 2537 | } |
| 2538 | self->stun_config = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2539 | (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2540 | if (self->stun_config == NULL) |
| 2541 | { |
| 2542 | Py_DECREF(self); |
| 2543 | return NULL; |
| 2544 | } |
| 2545 | |
| 2546 | } |
| 2547 | |
| 2548 | return (PyObject *)self; |
| 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | /* |
| 2553 | * transport_config_members |
| 2554 | */ |
| 2555 | static PyMemberDef transport_config_members[] = |
| 2556 | { |
| 2557 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2558 | "port", T_INT, offsetof(transport_config_Object, port), 0, |
| 2559 | "UDP port number to bind locally. This setting MUST be specified " |
| 2560 | "even when default port is desired. If the value is zero, the " |
| 2561 | "transport will be bound to any available port, and application " |
| 2562 | "can query the port by querying the transport info." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2563 | }, |
| 2564 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2565 | "public_addr", T_OBJECT_EX, |
| 2566 | offsetof(transport_config_Object, public_addr), 0, |
| 2567 | "Optional address to advertise as the address of this transport. " |
| 2568 | "Application can specify any address or hostname for this field, " |
| 2569 | "for example it can point to one of the interface address in the " |
| 2570 | "system, or it can point to the public address of a NAT router " |
| 2571 | "where port mappings have been configured for the application." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2572 | }, |
| 2573 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2574 | "bound_addr", T_OBJECT_EX, |
| 2575 | offsetof(transport_config_Object, bound_addr), 0, |
| 2576 | "Optional address where the socket should be bound to. This option " |
| 2577 | "SHOULD only be used to selectively bind the socket to particular " |
| 2578 | "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the " |
| 2579 | "published address of a transport (the public_addr field should be " |
| 2580 | "used for that purpose)." |
| 2581 | }, |
| 2582 | { |
| 2583 | "use_stun", T_INT, |
| 2584 | offsetof(transport_config_Object, use_stun), 0, |
| 2585 | "Flag to indicate whether STUN should be used." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2586 | }, |
| 2587 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2588 | "stun_config", T_OBJECT_EX, |
| 2589 | offsetof(transport_config_Object, stun_config), 0, |
| 2590 | "STUN configuration, must be specified when STUN is used." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2591 | }, |
| 2592 | {NULL} /* Sentinel */ |
| 2593 | }; |
| 2594 | |
| 2595 | |
| 2596 | |
| 2597 | |
| 2598 | /* |
| 2599 | * transport_config_Type |
| 2600 | */ |
| 2601 | static PyTypeObject transport_config_Type = |
| 2602 | { |
| 2603 | PyObject_HEAD_INIT(NULL) |
| 2604 | 0, /*ob_size*/ |
| 2605 | "py_pjsua.Transport_Config", /*tp_name*/ |
| 2606 | sizeof(transport_config_Object), /*tp_basicsize*/ |
| 2607 | 0, /*tp_itemsize*/ |
| 2608 | (destructor)transport_config_dealloc,/*tp_dealloc*/ |
| 2609 | 0, /*tp_print*/ |
| 2610 | 0, /*tp_getattr*/ |
| 2611 | 0, /*tp_setattr*/ |
| 2612 | 0, /*tp_compare*/ |
| 2613 | 0, /*tp_repr*/ |
| 2614 | 0, /*tp_as_number*/ |
| 2615 | 0, /*tp_as_sequence*/ |
| 2616 | 0, /*tp_as_mapping*/ |
| 2617 | 0, /*tp_hash */ |
| 2618 | 0, /*tp_call*/ |
| 2619 | 0, /*tp_str*/ |
| 2620 | 0, /*tp_getattro*/ |
| 2621 | 0, /*tp_setattro*/ |
| 2622 | 0, /*tp_as_buffer*/ |
| 2623 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2624 | "Transport Config objects", /* tp_doc */ |
| 2625 | 0, /* tp_traverse */ |
| 2626 | 0, /* tp_clear */ |
| 2627 | 0, /* tp_richcompare */ |
| 2628 | 0, /* tp_weaklistoffset */ |
| 2629 | 0, /* tp_iter */ |
| 2630 | 0, /* tp_iternext */ |
| 2631 | 0, /* tp_methods */ |
| 2632 | transport_config_members, /* tp_members */ |
| 2633 | 0, /* tp_getset */ |
| 2634 | 0, /* tp_base */ |
| 2635 | 0, /* tp_dict */ |
| 2636 | 0, /* tp_descr_get */ |
| 2637 | 0, /* tp_descr_set */ |
| 2638 | 0, /* tp_dictoffset */ |
| 2639 | 0, /* tp_init */ |
| 2640 | 0, /* tp_alloc */ |
| 2641 | transport_config_new, /* tp_new */ |
| 2642 | |
| 2643 | }; |
| 2644 | |
| 2645 | /* |
| 2646 | * sockaddr_Object |
| 2647 | * C/Python wrapper for sockaddr object |
| 2648 | */ |
| 2649 | typedef struct |
| 2650 | { |
| 2651 | PyObject_HEAD |
| 2652 | /* Type-specific fields go here. */ |
| 2653 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 2654 | pj_uint8_t sa_zero_len; |
| 2655 | pj_uint8_t sa_family; |
| 2656 | #else |
| 2657 | pj_uint16_t sa_family; /**< Common data: address family. */ |
| 2658 | #endif |
| 2659 | PyObject * sa_data; /**< Address data. */ |
| 2660 | } sockaddr_Object; |
| 2661 | |
| 2662 | /* |
| 2663 | * sockaddr_dealloc |
| 2664 | * deletes a sockaddr from memory |
| 2665 | */ |
| 2666 | static void sockaddr_dealloc(sockaddr_Object* self) |
| 2667 | { |
| 2668 | Py_XDECREF(self->sa_data); |
| 2669 | self->ob_type->tp_free((PyObject*)self); |
| 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | /* |
| 2674 | * sockaddr_new |
| 2675 | * constructor for sockaddr object |
| 2676 | */ |
| 2677 | static PyObject * sockaddr_new(PyTypeObject *type, PyObject *args, |
| 2678 | PyObject *kwds) |
| 2679 | { |
| 2680 | sockaddr_Object *self; |
| 2681 | |
| 2682 | self = (sockaddr_Object *)type->tp_alloc(type, 0); |
| 2683 | if (self != NULL) |
| 2684 | { |
| 2685 | self->sa_data = PyString_FromString(""); |
| 2686 | if (self->sa_data == NULL) |
| 2687 | { |
| 2688 | Py_DECREF(self); |
| 2689 | return NULL; |
| 2690 | } |
| 2691 | |
| 2692 | } |
| 2693 | |
| 2694 | return (PyObject *)self; |
| 2695 | } |
| 2696 | |
| 2697 | |
| 2698 | /* |
| 2699 | * sockaddr_members |
| 2700 | * declares attributes accessible from both C and Python for sockaddr object |
| 2701 | */ |
| 2702 | static PyMemberDef sockaddr_members[] = |
| 2703 | { |
| 2704 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 2705 | { |
| 2706 | "sa_zero_len", T_INT, offsetof(sockaddr_Object, sa_zero_len), 0, |
| 2707 | "" |
| 2708 | }, |
| 2709 | { |
| 2710 | "sa_family", T_INT, |
| 2711 | offsetof(sockaddr_Object, sa_family), 0, |
| 2712 | "Common data: address family." |
| 2713 | }, |
| 2714 | #else |
| 2715 | { |
| 2716 | "sa_family", T_INT, |
| 2717 | offsetof(sockaddr_Object, sa_family), 0, |
| 2718 | "Common data: address family." |
| 2719 | }, |
| 2720 | #endif |
| 2721 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2722 | "sa_data", T_OBJECT_EX, |
| 2723 | offsetof(sockaddr_Object, sa_data), 0, |
| 2724 | "Address data" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2725 | }, |
| 2726 | {NULL} /* Sentinel */ |
| 2727 | }; |
| 2728 | |
| 2729 | |
| 2730 | /* |
| 2731 | * sockaddr_Type |
| 2732 | */ |
| 2733 | static PyTypeObject sockaddr_Type = |
| 2734 | { |
| 2735 | PyObject_HEAD_INIT(NULL) |
| 2736 | 0, /*ob_size*/ |
| 2737 | "py_pjsua.Sockaddr", /*tp_name*/ |
| 2738 | sizeof(sockaddr_Object), /*tp_basicsize*/ |
| 2739 | 0, /*tp_itemsize*/ |
| 2740 | (destructor)sockaddr_dealloc,/*tp_dealloc*/ |
| 2741 | 0, /*tp_print*/ |
| 2742 | 0, /*tp_getattr*/ |
| 2743 | 0, /*tp_setattr*/ |
| 2744 | 0, /*tp_compare*/ |
| 2745 | 0, /*tp_repr*/ |
| 2746 | 0, /*tp_as_number*/ |
| 2747 | 0, /*tp_as_sequence*/ |
| 2748 | 0, /*tp_as_mapping*/ |
| 2749 | 0, /*tp_hash */ |
| 2750 | 0, /*tp_call*/ |
| 2751 | 0, /*tp_str*/ |
| 2752 | 0, /*tp_getattro*/ |
| 2753 | 0, /*tp_setattro*/ |
| 2754 | 0, /*tp_as_buffer*/ |
| 2755 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2756 | "Sockaddr objects", /*tp_doc*/ |
| 2757 | 0, /*tp_traverse*/ |
| 2758 | 0, /*tp_clear*/ |
| 2759 | 0, /*tp_richcompare*/ |
| 2760 | 0, /* tp_weaklistoffset */ |
| 2761 | 0, /* tp_iter */ |
| 2762 | 0, /* tp_iternext */ |
| 2763 | 0, /* tp_methods */ |
| 2764 | sockaddr_members, /* tp_members */ |
| 2765 | 0, /* tp_getset */ |
| 2766 | 0, /* tp_base */ |
| 2767 | 0, /* tp_dict */ |
| 2768 | 0, /* tp_descr_get */ |
| 2769 | 0, /* tp_descr_set */ |
| 2770 | 0, /* tp_dictoffset */ |
| 2771 | 0, /* tp_init */ |
| 2772 | 0, /* tp_alloc */ |
| 2773 | sockaddr_new, /* tp_new */ |
| 2774 | }; |
| 2775 | |
| 2776 | /* |
| 2777 | * host_port_Object |
| 2778 | * C/Python wrapper for host_port object |
| 2779 | */ |
| 2780 | typedef struct |
| 2781 | { |
| 2782 | PyObject_HEAD |
| 2783 | /* Type-specific fields go here. */ |
| 2784 | PyObject * host; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 2785 | int port; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2786 | } host_port_Object; |
| 2787 | |
| 2788 | /* |
| 2789 | * host_port_dealloc |
| 2790 | * deletes a host_port from memory |
| 2791 | */ |
| 2792 | static void host_port_dealloc(host_port_Object* self) |
| 2793 | { |
| 2794 | Py_XDECREF(self->host); |
| 2795 | self->ob_type->tp_free((PyObject*)self); |
| 2796 | } |
| 2797 | |
| 2798 | |
| 2799 | /* |
| 2800 | * host_port_new |
| 2801 | * constructor for host_port object |
| 2802 | */ |
| 2803 | static PyObject * host_port_new(PyTypeObject *type, PyObject *args, |
| 2804 | PyObject *kwds) |
| 2805 | { |
| 2806 | host_port_Object *self; |
| 2807 | |
| 2808 | self = (host_port_Object *)type->tp_alloc(type, 0); |
| 2809 | if (self != NULL) |
| 2810 | { |
| 2811 | self->host = PyString_FromString(""); |
| 2812 | if (self->host == NULL) |
| 2813 | { |
| 2814 | Py_DECREF(self); |
| 2815 | return NULL; |
| 2816 | } |
| 2817 | |
| 2818 | } |
| 2819 | |
| 2820 | return (PyObject *)self; |
| 2821 | } |
| 2822 | |
| 2823 | |
| 2824 | /* |
| 2825 | * host_port_members |
| 2826 | * declares attributes accessible from both C and Python for host_port object |
| 2827 | */ |
| 2828 | static PyMemberDef host_port_members[] = |
| 2829 | { |
| 2830 | { |
| 2831 | "port", T_INT, |
| 2832 | offsetof(host_port_Object, port), 0, |
| 2833 | "Port number." |
| 2834 | }, |
| 2835 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2836 | "host", T_OBJECT_EX, |
| 2837 | offsetof(host_port_Object, host), 0, |
| 2838 | "Host part or IP address." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2839 | }, |
| 2840 | {NULL} /* Sentinel */ |
| 2841 | }; |
| 2842 | |
| 2843 | |
| 2844 | /* |
| 2845 | * host_port_Type |
| 2846 | */ |
| 2847 | static PyTypeObject host_port_Type = |
| 2848 | { |
| 2849 | PyObject_HEAD_INIT(NULL) |
| 2850 | 0, /*ob_size*/ |
| 2851 | "py_pjsua.Host_Port", /*tp_name*/ |
| 2852 | sizeof(host_port_Object), /*tp_basicsize*/ |
| 2853 | 0, /*tp_itemsize*/ |
| 2854 | (destructor)host_port_dealloc,/*tp_dealloc*/ |
| 2855 | 0, /*tp_print*/ |
| 2856 | 0, /*tp_getattr*/ |
| 2857 | 0, /*tp_setattr*/ |
| 2858 | 0, /*tp_compare*/ |
| 2859 | 0, /*tp_repr*/ |
| 2860 | 0, /*tp_as_number*/ |
| 2861 | 0, /*tp_as_sequence*/ |
| 2862 | 0, /*tp_as_mapping*/ |
| 2863 | 0, /*tp_hash */ |
| 2864 | 0, /*tp_call*/ |
| 2865 | 0, /*tp_str*/ |
| 2866 | 0, /*tp_getattro*/ |
| 2867 | 0, /*tp_setattro*/ |
| 2868 | 0, /*tp_as_buffer*/ |
| 2869 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2870 | "Host_port objects", /*tp_doc*/ |
| 2871 | 0, /*tp_traverse*/ |
| 2872 | 0, /*tp_clear*/ |
| 2873 | 0, /*tp_richcompare*/ |
| 2874 | 0, /* tp_weaklistoffset */ |
| 2875 | 0, /* tp_iter */ |
| 2876 | 0, /* tp_iternext */ |
| 2877 | 0, /* tp_methods */ |
| 2878 | host_port_members, /* tp_members */ |
| 2879 | 0, /* tp_getset */ |
| 2880 | 0, /* tp_base */ |
| 2881 | 0, /* tp_dict */ |
| 2882 | 0, /* tp_descr_get */ |
| 2883 | 0, /* tp_descr_set */ |
| 2884 | 0, /* tp_dictoffset */ |
| 2885 | 0, /* tp_init */ |
| 2886 | 0, /* tp_alloc */ |
| 2887 | host_port_new, /* tp_new */ |
| 2888 | }; |
| 2889 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2890 | |
| 2891 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2892 | |
| 2893 | /* |
| 2894 | * transport_info_Object |
| 2895 | * Transport info |
| 2896 | */ |
| 2897 | typedef struct |
| 2898 | { |
| 2899 | PyObject_HEAD |
| 2900 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2901 | int id; |
| 2902 | int type; |
| 2903 | PyObject * type_name; |
| 2904 | PyObject * info; |
| 2905 | unsigned flag; |
| 2906 | unsigned addr_len; |
| 2907 | sockaddr_Object * local_addr; |
| 2908 | host_port_Object * local_name; |
| 2909 | unsigned usage_count; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2910 | } transport_info_Object; |
| 2911 | |
| 2912 | |
| 2913 | /* |
| 2914 | * transport_info_dealloc |
| 2915 | * deletes a transport info from memory |
| 2916 | */ |
| 2917 | static void transport_info_dealloc(transport_info_Object* self) |
| 2918 | { |
| 2919 | Py_XDECREF(self->type_name); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2920 | Py_XDECREF(self->info); |
| 2921 | Py_XDECREF(self->local_addr); |
| 2922 | Py_XDECREF(self->local_name); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2923 | self->ob_type->tp_free((PyObject*)self); |
| 2924 | } |
| 2925 | |
| 2926 | |
| 2927 | /* |
| 2928 | * transport_info_new |
| 2929 | * constructor for transport_info object |
| 2930 | */ |
| 2931 | static PyObject * transport_info_new(PyTypeObject *type, PyObject *args, |
| 2932 | PyObject *kwds) |
| 2933 | { |
| 2934 | transport_info_Object *self; |
| 2935 | |
| 2936 | self = (transport_info_Object *)type->tp_alloc(type, 0); |
| 2937 | if (self != NULL) |
| 2938 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2939 | self->type_name = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2940 | if (self->type_name == NULL) |
| 2941 | { |
| 2942 | Py_DECREF(self); |
| 2943 | return NULL; |
| 2944 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2945 | self->info = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2946 | if (self->info == NULL) |
| 2947 | { |
| 2948 | Py_DECREF(self); |
| 2949 | return NULL; |
| 2950 | } |
| 2951 | self->local_addr = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2952 | (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2953 | if (self->local_addr == NULL) |
| 2954 | { |
| 2955 | Py_DECREF(self); |
| 2956 | return NULL; |
| 2957 | } |
| 2958 | self->local_name = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2959 | (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2960 | if (self->local_name == NULL) |
| 2961 | { |
| 2962 | Py_DECREF(self); |
| 2963 | return NULL; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | return (PyObject *)self; |
| 2968 | } |
| 2969 | |
| 2970 | |
| 2971 | /* |
| 2972 | * transport_info_members |
| 2973 | */ |
| 2974 | static PyMemberDef transport_info_members[] = |
| 2975 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2976 | { |
| 2977 | "id", T_INT, offsetof(transport_info_Object, id), 0, |
| 2978 | "PJSUA transport identification." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2979 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2980 | { |
| 2981 | "type", T_INT, offsetof(transport_info_Object, id), 0, |
| 2982 | "Transport type." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2983 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2984 | { |
| 2985 | "type_name", T_OBJECT_EX, |
| 2986 | offsetof(transport_info_Object, type_name), 0, |
| 2987 | "Transport type name." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2988 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2989 | { |
| 2990 | "info", T_OBJECT_EX, |
| 2991 | offsetof(transport_info_Object, info), 0, |
| 2992 | "Transport string info/description." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2993 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2994 | { |
| 2995 | "flag", T_INT, offsetof(transport_info_Object, flag), 0, |
| 2996 | "Transport flag (see ##pjsip_transport_flags_e)." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2997 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 2998 | { |
| 2999 | "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0, |
| 3000 | "Local address length." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3001 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3002 | { |
| 3003 | "local_addr", T_OBJECT_EX, |
| 3004 | offsetof(transport_info_Object, local_addr), 0, |
| 3005 | "Local/bound address." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3006 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3007 | { |
| 3008 | "local_name", T_OBJECT_EX, |
| 3009 | offsetof(transport_info_Object, local_name), 0, |
| 3010 | "Published address (or transport address name)." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3011 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3012 | { |
| 3013 | "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0, |
| 3014 | "Current number of objects currently referencing this transport." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3015 | }, |
| 3016 | {NULL} /* Sentinel */ |
| 3017 | }; |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | /* |
| 3023 | * transport_info_Type |
| 3024 | */ |
| 3025 | static PyTypeObject transport_info_Type = |
| 3026 | { |
| 3027 | PyObject_HEAD_INIT(NULL) |
| 3028 | 0, /*ob_size*/ |
| 3029 | "py_pjsua.Transport_Info", /*tp_name*/ |
| 3030 | sizeof(transport_info_Object), /*tp_basicsize*/ |
| 3031 | 0, /*tp_itemsize*/ |
| 3032 | (destructor)transport_info_dealloc,/*tp_dealloc*/ |
| 3033 | 0, /*tp_print*/ |
| 3034 | 0, /*tp_getattr*/ |
| 3035 | 0, /*tp_setattr*/ |
| 3036 | 0, /*tp_compare*/ |
| 3037 | 0, /*tp_repr*/ |
| 3038 | 0, /*tp_as_number*/ |
| 3039 | 0, /*tp_as_sequence*/ |
| 3040 | 0, /*tp_as_mapping*/ |
| 3041 | 0, /*tp_hash */ |
| 3042 | 0, /*tp_call*/ |
| 3043 | 0, /*tp_str*/ |
| 3044 | 0, /*tp_getattro*/ |
| 3045 | 0, /*tp_setattro*/ |
| 3046 | 0, /*tp_as_buffer*/ |
| 3047 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3048 | "Transport Info objects", /* tp_doc */ |
| 3049 | 0, /* tp_traverse */ |
| 3050 | 0, /* tp_clear */ |
| 3051 | 0, /* tp_richcompare */ |
| 3052 | 0, /* tp_weaklistoffset */ |
| 3053 | 0, /* tp_iter */ |
| 3054 | 0, /* tp_iternext */ |
| 3055 | 0, /* tp_methods */ |
| 3056 | transport_info_members, /* tp_members */ |
| 3057 | 0, /* tp_getset */ |
| 3058 | 0, /* tp_base */ |
| 3059 | 0, /* tp_dict */ |
| 3060 | 0, /* tp_descr_get */ |
| 3061 | 0, /* tp_descr_set */ |
| 3062 | 0, /* tp_dictoffset */ |
| 3063 | 0, /* tp_init */ |
| 3064 | 0, /* tp_alloc */ |
| 3065 | transport_info_new, /* tp_new */ |
| 3066 | |
| 3067 | }; |
| 3068 | |
| 3069 | /* |
| 3070 | * pjsip_transport_Object |
| 3071 | * C/python typewrapper for pjsip_transport |
| 3072 | */ |
| 3073 | typedef struct |
| 3074 | { |
| 3075 | PyObject_HEAD |
| 3076 | /* Type-specific fields go here. */ |
| 3077 | pjsip_transport *tp; |
| 3078 | } pjsip_transport_Object; |
| 3079 | |
| 3080 | |
| 3081 | /* |
| 3082 | * pjsip_transport_Type |
| 3083 | */ |
| 3084 | static PyTypeObject pjsip_transport_Type = |
| 3085 | { |
| 3086 | PyObject_HEAD_INIT(NULL) |
| 3087 | 0, /*ob_size*/ |
| 3088 | "py_pjsua.PJSIP_Transport", /*tp_name*/ |
| 3089 | sizeof(pjsip_transport_Object), /*tp_basicsize*/ |
| 3090 | 0, /*tp_itemsize*/ |
| 3091 | 0, /*tp_dealloc*/ |
| 3092 | 0, /*tp_print*/ |
| 3093 | 0, /*tp_getattr*/ |
| 3094 | 0, /*tp_setattr*/ |
| 3095 | 0, /*tp_compare*/ |
| 3096 | 0, /*tp_repr*/ |
| 3097 | 0, /*tp_as_number*/ |
| 3098 | 0, /*tp_as_sequence*/ |
| 3099 | 0, /*tp_as_mapping*/ |
| 3100 | 0, /*tp_hash */ |
| 3101 | 0, /*tp_call*/ |
| 3102 | 0, /*tp_str*/ |
| 3103 | 0, /*tp_getattro*/ |
| 3104 | 0, /*tp_setattro*/ |
| 3105 | 0, /*tp_as_buffer*/ |
| 3106 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3107 | "pjsip_transport objects", /*tp_doc*/ |
| 3108 | }; |
| 3109 | |
| 3110 | |
| 3111 | /* |
| 3112 | * py_pjsua_stun_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3113 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3114 | */ |
| 3115 | static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs) |
| 3116 | { |
| 3117 | stun_config_Object *obj; |
| 3118 | pjsua_stun_config cfg; |
| 3119 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3120 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3121 | { |
| 3122 | return NULL; |
| 3123 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3124 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3125 | pjsua_stun_config_default(&cfg); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3126 | obj = (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3127 | obj->stun_port1 = cfg.stun_port1; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3128 | obj->stun_port2 = cfg.stun_port2; |
| 3129 | Py_XDECREF(obj->stun_srv1); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3130 | obj->stun_srv1 = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3131 | PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen); |
| 3132 | Py_XDECREF(obj->stun_srv2); |
| 3133 | obj->stun_srv2 = |
| 3134 | PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen); |
| 3135 | return (PyObject *)obj; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | /* |
| 3139 | * py_pjsua_transport_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3140 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3141 | */ |
| 3142 | static PyObject *py_pjsua_transport_config_default |
| 3143 | (PyObject *pSelf, PyObject *pArgs) |
| 3144 | { |
| 3145 | transport_config_Object *obj; |
| 3146 | pjsua_transport_config cfg; |
| 3147 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3148 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3149 | { |
| 3150 | return NULL; |
| 3151 | } |
| 3152 | pjsua_transport_config_default(&cfg); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3153 | obj = (transport_config_Object *)transport_config_new |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3154 | (&transport_config_Type,NULL,NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3155 | obj->public_addr = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3156 | PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen); |
| 3157 | obj->bound_addr = |
| 3158 | PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen); |
| 3159 | obj->port = cfg.port; |
| 3160 | obj->use_stun = cfg.use_stun; |
| 3161 | Py_XDECREF(obj->stun_config); |
| 3162 | obj->stun_config = |
| 3163 | (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3164 | obj->stun_config->stun_port1 = cfg.stun_config.stun_port1; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3165 | obj->stun_config->stun_port2 = cfg.stun_config.stun_port2; |
| 3166 | Py_XDECREF(obj->stun_config->stun_srv1); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3167 | obj->stun_config->stun_srv1 = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3168 | PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr, |
| 3169 | cfg.stun_config.stun_srv1.slen); |
| 3170 | Py_XDECREF(obj->stun_config->stun_srv2); |
| 3171 | obj->stun_config->stun_srv2 = |
| 3172 | PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr, |
| 3173 | cfg.stun_config.stun_srv2.slen); |
| 3174 | return (PyObject *)obj; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /* |
| 3178 | * py_pjsua_normalize_stun_config |
| 3179 | */ |
| 3180 | static PyObject *py_pjsua_normalize_stun_config |
| 3181 | (PyObject *pSelf, PyObject *pArgs) |
| 3182 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3183 | PyObject * tmpObj; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3184 | stun_config_Object *obj; |
Benny Prijono | 40d2cc7 | 2007-02-14 01:45:08 +0000 | [diff] [blame] | 3185 | pjsua_stun_config cfg; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3186 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3187 | if (!PyArg_ParseTuple(pArgs, "O", &tmpObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3188 | { |
| 3189 | return NULL; |
| 3190 | } |
Benny Prijono | 40d2cc7 | 2007-02-14 01:45:08 +0000 | [diff] [blame] | 3191 | |
| 3192 | if (tmpObj == Py_None) { |
| 3193 | Py_INCREF(Py_None); |
| 3194 | return Py_None; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3195 | } |
Benny Prijono | 40d2cc7 | 2007-02-14 01:45:08 +0000 | [diff] [blame] | 3196 | |
| 3197 | obj = (stun_config_Object *) tmpObj; |
| 3198 | cfg.stun_port1 = obj->stun_port1; |
| 3199 | cfg.stun_port2 = obj->stun_port2; |
| 3200 | cfg.stun_srv1.ptr = PyString_AsString(obj->stun_srv1); |
| 3201 | cfg.stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1)); |
| 3202 | cfg.stun_srv2.ptr = PyString_AsString(obj->stun_srv2); |
| 3203 | cfg.stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2)); |
| 3204 | |
| 3205 | pjsua_normalize_stun_config(&cfg); |
| 3206 | obj->stun_port1 = cfg.stun_port1; |
| 3207 | obj->stun_port2 = cfg.stun_port2; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3208 | Py_XDECREF(obj->stun_srv1); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3209 | obj->stun_srv1 = |
Benny Prijono | 40d2cc7 | 2007-02-14 01:45:08 +0000 | [diff] [blame] | 3210 | PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3211 | Py_XDECREF(obj->stun_srv2); |
| 3212 | obj->stun_srv2 = |
Benny Prijono | 40d2cc7 | 2007-02-14 01:45:08 +0000 | [diff] [blame] | 3213 | PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen); |
| 3214 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3215 | Py_INCREF(Py_None); |
| 3216 | return Py_None; |
| 3217 | } |
| 3218 | |
| 3219 | /* |
| 3220 | * py_pjsua_transport_create |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3221 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3222 | */ |
| 3223 | static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) |
| 3224 | { |
| 3225 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3226 | int type; |
| 3227 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3228 | PyObject * tmpObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3229 | transport_config_Object *obj; |
| 3230 | pjsua_transport_config cfg; |
| 3231 | pjsua_transport_id id; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3232 | if (!PyArg_ParseTuple(pArgs, "iO", &type, &tmpObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3233 | { |
| 3234 | return NULL; |
| 3235 | } |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3236 | if (tmpObj != Py_None) |
| 3237 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3238 | obj = (transport_config_Object *)tmpObj; |
| 3239 | cfg.public_addr.ptr = PyString_AsString(obj->public_addr); |
| 3240 | cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr)); |
| 3241 | cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr); |
| 3242 | cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr)); |
| 3243 | cfg.port = obj->port; |
| 3244 | cfg.use_stun = obj->use_stun; |
| 3245 | cfg.stun_config.stun_port1 = obj->stun_config->stun_port1; |
| 3246 | cfg.stun_config.stun_port2 = obj->stun_config->stun_port2; |
| 3247 | cfg.stun_config.stun_srv1.ptr = |
| 3248 | PyString_AsString(obj->stun_config->stun_srv1); |
| 3249 | cfg.stun_config.stun_srv1.slen = |
| 3250 | strlen(PyString_AsString(obj->stun_config->stun_srv1)); |
| 3251 | cfg.stun_config.stun_srv2.ptr = |
| 3252 | PyString_AsString(obj->stun_config->stun_srv2); |
| 3253 | cfg.stun_config.stun_srv2.slen = |
| 3254 | strlen(PyString_AsString(obj->stun_config->stun_srv2)); |
| 3255 | status = pjsua_transport_create(type, &cfg, &id); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3256 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3257 | status = pjsua_transport_create(type, NULL, &id); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3258 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3259 | |
| 3260 | |
| 3261 | return Py_BuildValue("ii",status,id); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | /* |
| 3265 | * py_pjsua_transport_register |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3266 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3267 | */ |
| 3268 | static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs) |
| 3269 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3270 | pj_status_t status; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3271 | PyObject * tmpObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3272 | pjsip_transport_Object *obj; |
| 3273 | pjsua_transport_id id; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3274 | if (!PyArg_ParseTuple(pArgs, "O", &tmpObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3275 | { |
| 3276 | return NULL; |
| 3277 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3278 | if (tmpObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3279 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3280 | obj = (pjsip_transport_Object *)tmpObj; |
| 3281 | status = pjsua_transport_register(obj->tp, &id); |
| 3282 | } else { |
| 3283 | status = pjsua_transport_register(NULL, &id); |
| 3284 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3285 | |
| 3286 | return Py_BuildValue("ii",status, id); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | /* |
| 3290 | * py_pjsua_enum_transports |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 3291 | * !modified @ 261206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3292 | */ |
| 3293 | static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) |
| 3294 | { |
| 3295 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3296 | PyObject *list; |
| 3297 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 3298 | pjsua_transport_id id[PJSIP_MAX_TRANSPORTS]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 3299 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 3300 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3301 | { |
| 3302 | return NULL; |
| 3303 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3304 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 3305 | c = PJ_ARRAY_SIZE(id); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3306 | status = pjsua_enum_transports(id, &c); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3307 | |
| 3308 | list = PyList_New(c); |
| 3309 | for (i = 0; i < c; i++) |
| 3310 | { |
| 3311 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
| 3312 | if (ret == -1) |
| 3313 | { |
| 3314 | return NULL; |
| 3315 | } |
| 3316 | } |
| 3317 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3318 | return Py_BuildValue("O",list); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | /* |
| 3322 | * py_pjsua_transport_get_info |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3323 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3324 | */ |
| 3325 | static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs) |
| 3326 | { |
| 3327 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3328 | int id; |
| 3329 | transport_info_Object *obj; |
| 3330 | pjsua_transport_info info; |
| 3331 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3332 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3333 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3334 | { |
| 3335 | return NULL; |
| 3336 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3337 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3338 | status = pjsua_transport_get_info(id, &info); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3339 | if (status == PJ_SUCCESS) { |
| 3340 | obj = (transport_info_Object *) transport_info_new |
| 3341 | (&transport_info_Type,NULL,NULL); |
| 3342 | obj->addr_len = info.addr_len; |
| 3343 | obj->flag = info.flag; |
| 3344 | obj->id = info.id; |
| 3345 | obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen); |
| 3346 | obj->local_addr->sa_data = |
| 3347 | PyString_FromStringAndSize(info.local_addr.sa_data, 14); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3348 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3349 | obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len; |
| 3350 | obj->local_addr->sa_family = info.local_addr.sa_family; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3351 | #else |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3352 | obj->local_addr->sa_family = info.local_addr.sa_family; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3353 | #endif |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3354 | return Py_BuildValue("O", obj); |
| 3355 | } else { |
| 3356 | Py_INCREF(Py_None); |
| 3357 | return Py_None; |
| 3358 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | /* |
| 3362 | * py_pjsua_transport_set_enable |
| 3363 | */ |
| 3364 | static PyObject *py_pjsua_transport_set_enable |
| 3365 | (PyObject *pSelf, PyObject *pArgs) |
| 3366 | { |
| 3367 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3368 | int id; |
| 3369 | int enabled; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3370 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) |
| 3371 | { |
| 3372 | return NULL; |
| 3373 | } |
| 3374 | status = pjsua_transport_set_enable(id, enabled); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 3375 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3376 | return Py_BuildValue("i",status); |
| 3377 | } |
| 3378 | |
| 3379 | /* |
| 3380 | * py_pjsua_transport_close |
| 3381 | */ |
| 3382 | static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs) |
| 3383 | { |
| 3384 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3385 | int id; |
| 3386 | int force; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3387 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) |
| 3388 | { |
| 3389 | return NULL; |
| 3390 | } |
| 3391 | status = pjsua_transport_close(id, force); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 3392 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3393 | return Py_BuildValue("i",status); |
| 3394 | } |
| 3395 | |
| 3396 | static char pjsua_stun_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3397 | "py_pjsua.STUN_Config py_pjsua.stun_config_default () " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3398 | "Call this function to initialize STUN config with default values."; |
| 3399 | static char pjsua_transport_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3400 | "py_pjsua.Transport_Config py_pjsua.transport_config_default () " |
| 3401 | "Call this function to initialize UDP config with default values."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3402 | static char pjsua_normalize_stun_config_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3403 | "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) " |
| 3404 | "Normalize STUN config. "; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3405 | static char pjsua_transport_create_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3406 | "int, int py_pjsua.transport_create (int type, " |
| 3407 | "py_pjsua.Transport_Config cfg) " |
| 3408 | "Create SIP transport."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3409 | static char pjsua_transport_register_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3410 | "int, int py_pjsua.transport_register " |
| 3411 | "(py_pjsua.PJSIP_Transport tp) " |
| 3412 | "Register transport that has been created by application."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3413 | static char pjsua_enum_transports_doc[] = |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 3414 | "int[] py_pjsua.enum_transports () " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3415 | "Enumerate all transports currently created in the system."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3416 | static char pjsua_transport_get_info_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3417 | "void py_pjsua.transport_get_info " |
| 3418 | "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) " |
| 3419 | "Get information about transports."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3420 | static char pjsua_transport_set_enable_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3421 | "void py_pjsua.transport_set_enable " |
| 3422 | "(py_pjsua.Transport_ID id, int enabled) " |
| 3423 | "Disable a transport or re-enable it. " |
| 3424 | "By default transport is always enabled after it is created. " |
| 3425 | "Disabling a transport does not necessarily close the socket, " |
| 3426 | "it will only discard incoming messages and prevent the transport " |
| 3427 | "from being used to send outgoing messages."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3428 | static char pjsua_transport_close_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3429 | "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) " |
| 3430 | "Close the transport. If transport is forcefully closed, " |
| 3431 | "it will be immediately closed, and any pending transactions " |
| 3432 | "that are using the transport may not terminate properly. " |
| 3433 | "Otherwise, the system will wait until all transactions are closed " |
| 3434 | "while preventing new users from using the transport, and will close " |
| 3435 | "the transport when it is safe to do so."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3436 | |
| 3437 | /* END OF LIB TRANSPORT */ |
| 3438 | |
| 3439 | /* LIB ACCOUNT */ |
| 3440 | |
| 3441 | /* |
| 3442 | * acc_config_Object |
| 3443 | * Acc Config |
| 3444 | */ |
| 3445 | typedef struct |
| 3446 | { |
| 3447 | PyObject_HEAD |
| 3448 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3449 | int priority; |
| 3450 | PyObject * id; |
| 3451 | PyObject * reg_uri; |
| 3452 | int publish_enabled; |
| 3453 | PyObject * force_contact; |
| 3454 | unsigned proxy_cnt; |
| 3455 | /*pj_str_t proxy[8];*/ |
| 3456 | PyListObject * proxy; |
| 3457 | unsigned reg_timeout; |
| 3458 | unsigned cred_count; |
| 3459 | /*pjsip_cred_info cred_info[8];*/ |
| 3460 | PyListObject * cred_info; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3461 | } acc_config_Object; |
| 3462 | |
| 3463 | |
| 3464 | /* |
| 3465 | * acc_config_dealloc |
| 3466 | * deletes a acc_config from memory |
| 3467 | */ |
| 3468 | static void acc_config_dealloc(acc_config_Object* self) |
| 3469 | { |
| 3470 | Py_XDECREF(self->id); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3471 | Py_XDECREF(self->reg_uri); |
| 3472 | Py_XDECREF(self->force_contact); |
| 3473 | Py_XDECREF(self->proxy); |
| 3474 | Py_XDECREF(self->cred_info); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3475 | self->ob_type->tp_free((PyObject*)self); |
| 3476 | } |
| 3477 | |
| 3478 | |
| 3479 | /* |
| 3480 | * acc_config_new |
| 3481 | * constructor for acc_config object |
| 3482 | */ |
| 3483 | static PyObject * acc_config_new(PyTypeObject *type, PyObject *args, |
| 3484 | PyObject *kwds) |
| 3485 | { |
| 3486 | acc_config_Object *self; |
| 3487 | |
| 3488 | self = (acc_config_Object *)type->tp_alloc(type, 0); |
| 3489 | if (self != NULL) |
| 3490 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3491 | self->id = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3492 | if (self->id == NULL) |
| 3493 | { |
| 3494 | Py_DECREF(self); |
| 3495 | return NULL; |
| 3496 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3497 | self->reg_uri = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3498 | if (self->reg_uri == NULL) |
| 3499 | { |
| 3500 | Py_DECREF(self); |
| 3501 | return NULL; |
| 3502 | } |
| 3503 | self->force_contact = PyString_FromString(""); |
| 3504 | if (self->force_contact == NULL) |
| 3505 | { |
| 3506 | Py_DECREF(self); |
| 3507 | return NULL; |
| 3508 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3509 | self->proxy = (PyListObject *)PyList_New(8); |
| 3510 | if (self->proxy == NULL) |
| 3511 | { |
| 3512 | Py_DECREF(self); |
| 3513 | return NULL; |
| 3514 | } |
| 3515 | self->cred_info = (PyListObject *)PyList_New(8); |
| 3516 | if (self->cred_info == NULL) |
| 3517 | { |
| 3518 | Py_DECREF(self); |
| 3519 | return NULL; |
| 3520 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | return (PyObject *)self; |
| 3524 | } |
| 3525 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3526 | |
| 3527 | |
| 3528 | /* |
| 3529 | * acc_config_members |
| 3530 | */ |
| 3531 | static PyMemberDef acc_config_members[] = |
| 3532 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3533 | { |
| 3534 | "priority", T_INT, offsetof(acc_config_Object, priority), 0, |
| 3535 | "Account priority, which is used to control the order of matching " |
| 3536 | "incoming/outgoing requests. The higher the number means the higher " |
| 3537 | "the priority is, and the account will be matched first. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3538 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3539 | { |
| 3540 | "id", T_OBJECT_EX, |
| 3541 | offsetof(acc_config_Object, id), 0, |
| 3542 | "The full SIP URL for the account. " |
| 3543 | "The value can take name address or URL format, " |
| 3544 | "and will look something like 'sip:account@serviceprovider'. " |
| 3545 | "This field is mandatory." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3546 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3547 | { |
| 3548 | "reg_uri", T_OBJECT_EX, |
| 3549 | offsetof(acc_config_Object, reg_uri), 0, |
| 3550 | "This is the URL to be put in the request URI for the registration, " |
| 3551 | "and will look something like 'sip:serviceprovider'. " |
| 3552 | "This field should be specified if registration is desired. " |
| 3553 | "If the value is empty, no account registration will be performed. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3554 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3555 | { |
| 3556 | "publish_enabled", T_INT, |
| 3557 | offsetof(acc_config_Object, publish_enabled), 0, |
| 3558 | "Publish presence? " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3559 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3560 | { |
| 3561 | "force_contact", T_OBJECT_EX, |
| 3562 | offsetof(acc_config_Object, force_contact), 0, |
| 3563 | "Optional URI to be put as Contact for this account. " |
| 3564 | "It is recommended that this field is left empty, " |
| 3565 | "so that the value will be calculated automatically " |
| 3566 | "based on the transport address. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3567 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3568 | { |
| 3569 | "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0, |
| 3570 | "Number of proxies in the proxy array below. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3571 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3572 | { |
| 3573 | "proxy", T_OBJECT_EX, |
| 3574 | offsetof(acc_config_Object, proxy), 0, |
| 3575 | "Optional URI of the proxies to be visited for all outgoing requests " |
| 3576 | "that are using this account (REGISTER, INVITE, etc). Application need " |
| 3577 | "to specify these proxies if the service provider requires " |
| 3578 | "that requests destined towards its network should go through certain " |
| 3579 | "proxies first (for example, border controllers)." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3580 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3581 | { |
| 3582 | "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0, |
| 3583 | "Optional interval for registration, in seconds. " |
| 3584 | "If the value is zero, default interval will be used " |
| 3585 | "(PJSUA_REG_INTERVAL, 55 seconds). " |
| 3586 | }, |
| 3587 | { |
| 3588 | "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0, |
| 3589 | "Number of credentials in the credential array. " |
| 3590 | }, |
| 3591 | { |
| 3592 | "cred_info", T_OBJECT_EX, |
| 3593 | offsetof(acc_config_Object, cred_info), 0, |
| 3594 | "Array of credentials. If registration is desired, normally there " |
| 3595 | "should be at least one credential specified, to successfully " |
| 3596 | "authenticate against the service provider. More credentials can " |
| 3597 | "be specified, for example when the requests are expected to be " |
| 3598 | "challenged by the proxies in the route set." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3599 | }, |
| 3600 | {NULL} /* Sentinel */ |
| 3601 | }; |
| 3602 | |
| 3603 | |
| 3604 | |
| 3605 | |
| 3606 | /* |
| 3607 | * acc_config_Type |
| 3608 | */ |
| 3609 | static PyTypeObject acc_config_Type = |
| 3610 | { |
| 3611 | PyObject_HEAD_INIT(NULL) |
| 3612 | 0, /*ob_size*/ |
| 3613 | "py_pjsua.Acc_Config", /*tp_name*/ |
| 3614 | sizeof(acc_config_Object), /*tp_basicsize*/ |
| 3615 | 0, /*tp_itemsize*/ |
| 3616 | (destructor)acc_config_dealloc,/*tp_dealloc*/ |
| 3617 | 0, /*tp_print*/ |
| 3618 | 0, /*tp_getattr*/ |
| 3619 | 0, /*tp_setattr*/ |
| 3620 | 0, /*tp_compare*/ |
| 3621 | 0, /*tp_repr*/ |
| 3622 | 0, /*tp_as_number*/ |
| 3623 | 0, /*tp_as_sequence*/ |
| 3624 | 0, /*tp_as_mapping*/ |
| 3625 | 0, /*tp_hash */ |
| 3626 | 0, /*tp_call*/ |
| 3627 | 0, /*tp_str*/ |
| 3628 | 0, /*tp_getattro*/ |
| 3629 | 0, /*tp_setattro*/ |
| 3630 | 0, /*tp_as_buffer*/ |
| 3631 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3632 | "Acc Config objects", /* tp_doc */ |
| 3633 | 0, /* tp_traverse */ |
| 3634 | 0, /* tp_clear */ |
| 3635 | 0, /* tp_richcompare */ |
| 3636 | 0, /* tp_weaklistoffset */ |
| 3637 | 0, /* tp_iter */ |
| 3638 | 0, /* tp_iternext */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3639 | 0/*acc_config_methods*/, /* tp_methods */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3640 | acc_config_members, /* tp_members */ |
| 3641 | 0, /* tp_getset */ |
| 3642 | 0, /* tp_base */ |
| 3643 | 0, /* tp_dict */ |
| 3644 | 0, /* tp_descr_get */ |
| 3645 | 0, /* tp_descr_set */ |
| 3646 | 0, /* tp_dictoffset */ |
| 3647 | 0, /* tp_init */ |
| 3648 | 0, /* tp_alloc */ |
| 3649 | acc_config_new, /* tp_new */ |
| 3650 | |
| 3651 | }; |
| 3652 | |
| 3653 | /* |
| 3654 | * acc_info_Object |
| 3655 | * Acc Info |
| 3656 | */ |
| 3657 | typedef struct |
| 3658 | { |
| 3659 | PyObject_HEAD |
| 3660 | /* Type-specific fields go here. */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3661 | int id; |
| 3662 | int is_default; |
| 3663 | PyObject * acc_uri; |
| 3664 | int has_registration; |
| 3665 | int expires; |
| 3666 | int status; |
| 3667 | PyObject * status_text; |
| 3668 | int online_status; |
| 3669 | char buf_[PJ_ERR_MSG_SIZE]; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3670 | } acc_info_Object; |
| 3671 | |
| 3672 | |
| 3673 | /* |
| 3674 | * acc_info_dealloc |
| 3675 | * deletes a acc_info from memory |
| 3676 | */ |
| 3677 | static void acc_info_dealloc(acc_info_Object* self) |
| 3678 | { |
| 3679 | Py_XDECREF(self->acc_uri); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3680 | Py_XDECREF(self->status_text); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3681 | self->ob_type->tp_free((PyObject*)self); |
| 3682 | } |
| 3683 | |
| 3684 | |
| 3685 | /* |
| 3686 | * acc_info_new |
| 3687 | * constructor for acc_info object |
| 3688 | */ |
| 3689 | static PyObject * acc_info_new(PyTypeObject *type, PyObject *args, |
| 3690 | PyObject *kwds) |
| 3691 | { |
| 3692 | acc_info_Object *self; |
| 3693 | |
| 3694 | self = (acc_info_Object *)type->tp_alloc(type, 0); |
| 3695 | if (self != NULL) |
| 3696 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3697 | self->acc_uri = PyString_FromString(""); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3698 | if (self->acc_uri == NULL) |
| 3699 | { |
| 3700 | Py_DECREF(self); |
| 3701 | return NULL; |
| 3702 | } |
| 3703 | self->status_text = PyString_FromString(""); |
| 3704 | if (self->status_text == NULL) |
| 3705 | { |
| 3706 | Py_DECREF(self); |
| 3707 | return NULL; |
| 3708 | } |
| 3709 | |
| 3710 | } |
| 3711 | |
| 3712 | return (PyObject *)self; |
| 3713 | } |
| 3714 | |
| 3715 | static PyObject * acc_info_get_buf |
| 3716 | (acc_info_Object *self, PyObject * args) |
| 3717 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3718 | int idx; |
| 3719 | char elmt; |
| 3720 | if (!PyArg_ParseTuple(args,"i",&idx)) |
| 3721 | { |
| 3722 | return NULL; |
| 3723 | } |
| 3724 | if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) |
| 3725 | { |
| 3726 | elmt = self->buf_[idx]; |
| 3727 | } |
| 3728 | else |
| 3729 | { |
| 3730 | return NULL; |
| 3731 | } |
| 3732 | return PyString_FromStringAndSize(&elmt, 1); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | static PyObject * acc_info_set_buf |
| 3736 | (acc_info_Object *self, PyObject * args) |
| 3737 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3738 | int idx; |
| 3739 | PyObject * str; |
| 3740 | char * s; |
| 3741 | if (!PyArg_ParseTuple(args,"iO",&idx, &str)) |
| 3742 | { |
| 3743 | return NULL; |
| 3744 | } |
| 3745 | if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) |
| 3746 | { |
| 3747 | s = PyString_AsString(str); |
| 3748 | if (s[0]) |
| 3749 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3750 | self->buf_[idx] = s[0]; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3751 | } |
| 3752 | else |
| 3753 | { |
| 3754 | return NULL; |
| 3755 | } |
| 3756 | } |
| 3757 | else |
| 3758 | { |
| 3759 | return NULL; |
| 3760 | } |
| 3761 | Py_INCREF(Py_None); |
| 3762 | return Py_None; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | static PyMethodDef acc_info_methods[] = { |
| 3766 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3767 | "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS, |
| 3768 | "Return buf char at specified index" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3769 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3770 | { |
| 3771 | "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS, |
| 3772 | "Set buf at specified index" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3773 | }, |
| 3774 | |
| 3775 | {NULL} /* Sentinel */ |
| 3776 | }; |
| 3777 | |
| 3778 | |
| 3779 | |
| 3780 | /* |
| 3781 | * acc_info_members |
| 3782 | */ |
| 3783 | static PyMemberDef acc_info_members[] = |
| 3784 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3785 | { |
| 3786 | "id", T_INT, offsetof(acc_info_Object, id), 0, |
| 3787 | "The account ID." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3788 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3789 | { |
| 3790 | "is_default", T_INT, offsetof(acc_info_Object, is_default), 0, |
| 3791 | "Flag to indicate whether this is the default account. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3792 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3793 | { |
| 3794 | "acc_uri", T_OBJECT_EX, |
| 3795 | offsetof(acc_info_Object, acc_uri), 0, |
| 3796 | "Account URI" |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3797 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3798 | { |
| 3799 | "has_registration", T_INT, offsetof(acc_info_Object, has_registration), |
| 3800 | 0, |
| 3801 | "Flag to tell whether this account has registration setting " |
| 3802 | "(reg_uri is not empty)." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3803 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3804 | { |
| 3805 | "expires", T_INT, offsetof(acc_info_Object, expires), 0, |
| 3806 | "An up to date expiration interval for account registration session." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3807 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3808 | { |
| 3809 | "status", T_INT, offsetof(acc_info_Object, status), 0, |
| 3810 | "Last registration status code. If status code is zero, " |
| 3811 | "the account is currently not registered. Any other value indicates " |
| 3812 | "the SIP status code of the registration. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3813 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3814 | { |
| 3815 | "status_text", T_OBJECT_EX, |
| 3816 | offsetof(acc_info_Object, status_text), 0, |
| 3817 | "String describing the registration status." |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3818 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3819 | { |
| 3820 | "online_status", T_INT, offsetof(acc_info_Object, online_status), 0, |
| 3821 | "Presence online status for this account. " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3822 | }, |
| 3823 | {NULL} /* Sentinel */ |
| 3824 | }; |
| 3825 | |
| 3826 | |
| 3827 | |
| 3828 | |
| 3829 | /* |
| 3830 | * acc_info_Type |
| 3831 | */ |
| 3832 | static PyTypeObject acc_info_Type = |
| 3833 | { |
| 3834 | PyObject_HEAD_INIT(NULL) |
| 3835 | 0, /*ob_size*/ |
| 3836 | "py_pjsua.Acc_Info", /*tp_name*/ |
| 3837 | sizeof(acc_info_Object), /*tp_basicsize*/ |
| 3838 | 0, /*tp_itemsize*/ |
| 3839 | (destructor)acc_info_dealloc,/*tp_dealloc*/ |
| 3840 | 0, /*tp_print*/ |
| 3841 | 0, /*tp_getattr*/ |
| 3842 | 0, /*tp_setattr*/ |
| 3843 | 0, /*tp_compare*/ |
| 3844 | 0, /*tp_repr*/ |
| 3845 | 0, /*tp_as_number*/ |
| 3846 | 0, /*tp_as_sequence*/ |
| 3847 | 0, /*tp_as_mapping*/ |
| 3848 | 0, /*tp_hash */ |
| 3849 | 0, /*tp_call*/ |
| 3850 | 0, /*tp_str*/ |
| 3851 | 0, /*tp_getattro*/ |
| 3852 | 0, /*tp_setattro*/ |
| 3853 | 0, /*tp_as_buffer*/ |
| 3854 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3855 | "Acc Info objects", /* tp_doc */ |
| 3856 | 0, /* tp_traverse */ |
| 3857 | 0, /* tp_clear */ |
| 3858 | 0, /* tp_richcompare */ |
| 3859 | 0, /* tp_weaklistoffset */ |
| 3860 | 0, /* tp_iter */ |
| 3861 | 0, /* tp_iternext */ |
| 3862 | acc_info_methods, /* tp_methods */ |
| 3863 | acc_info_members, /* tp_members */ |
| 3864 | 0, /* tp_getset */ |
| 3865 | 0, /* tp_base */ |
| 3866 | 0, /* tp_dict */ |
| 3867 | 0, /* tp_descr_get */ |
| 3868 | 0, /* tp_descr_set */ |
| 3869 | 0, /* tp_dictoffset */ |
| 3870 | 0, /* tp_init */ |
| 3871 | 0, /* tp_alloc */ |
| 3872 | acc_info_new, /* tp_new */ |
| 3873 | |
| 3874 | }; |
| 3875 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3876 | |
| 3877 | |
| 3878 | /* |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3879 | * py_pjsua_acc_config_default |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3880 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3881 | */ |
| 3882 | static PyObject *py_pjsua_acc_config_default |
| 3883 | (PyObject *pSelf, PyObject *pArgs) |
| 3884 | { |
| 3885 | acc_config_Object *obj; |
| 3886 | pjsua_acc_config cfg; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3887 | int i; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3888 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3889 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3890 | { |
| 3891 | return NULL; |
| 3892 | } |
| 3893 | pjsua_acc_config_default(&cfg); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3894 | obj = (acc_config_Object *)acc_config_new(&acc_config_Type, NULL, NULL); |
| 3895 | obj->cred_count = cfg.cred_count; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3896 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3897 | { |
| 3898 | /*obj->cred_info[i] = cfg.cred_info[i];*/ |
| 3899 | int ret; |
| 3900 | pjsip_cred_info_Object * ci = |
| 3901 | (pjsip_cred_info_Object *)pjsip_cred_info_new |
| 3902 | (&pjsip_cred_info_Type,NULL,NULL); |
| 3903 | ci->data = PyString_FromStringAndSize(cfg.cred_info[i].data.ptr, |
| 3904 | cfg.cred_info[i].data.slen); |
| 3905 | ci->realm = PyString_FromStringAndSize(cfg.cred_info[i].realm.ptr, |
| 3906 | cfg.cred_info[i].realm.slen); |
| 3907 | ci->scheme = PyString_FromStringAndSize(cfg.cred_info[i].scheme.ptr, |
| 3908 | cfg.cred_info[i].scheme.slen); |
| 3909 | ci->username = PyString_FromStringAndSize(cfg.cred_info[i].username.ptr, |
| 3910 | cfg.cred_info[i].username.slen); |
| 3911 | ci->data_type = cfg.cred_info[i].data_type; |
| 3912 | ret = PyList_SetItem((PyObject *)obj->cred_info,i,(PyObject *)ci); |
| 3913 | if (ret == -1) { |
| 3914 | return NULL; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3915 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | Py_XDECREF(obj->force_contact); |
| 3919 | obj->force_contact = |
| 3920 | PyString_FromStringAndSize(cfg.force_contact.ptr, |
| 3921 | cfg.force_contact.slen); |
| 3922 | obj->priority = cfg.priority; |
| 3923 | Py_XDECREF(obj->id); |
| 3924 | obj->id = |
| 3925 | PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen); |
| 3926 | Py_XDECREF(obj->reg_uri); |
| 3927 | obj->reg_uri = |
| 3928 | PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen); |
| 3929 | obj->proxy_cnt = cfg.proxy_cnt; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 3930 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3931 | { |
| 3932 | PyObject * str; |
| 3933 | int ret; |
| 3934 | /*obj->proxy[i] = cfg.proxy[i];*/ |
| 3935 | str = PyString_FromStringAndSize(cfg.proxy[i].ptr, cfg.proxy[i].slen); |
| 3936 | ret = PyList_SetItem((PyObject *)obj->proxy,i,str); |
| 3937 | if (ret == -1) { |
| 3938 | return NULL; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3939 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3940 | } |
| 3941 | obj->publish_enabled = cfg.publish_enabled; |
| 3942 | obj->reg_timeout = cfg.reg_timeout; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3943 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3944 | return (PyObject *)obj; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | /* |
| 3948 | * py_pjsua_acc_get_count |
| 3949 | */ |
| 3950 | static PyObject *py_pjsua_acc_get_count |
| 3951 | (PyObject *pSelf, PyObject *pArgs) |
| 3952 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3953 | int count; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3954 | if (!PyArg_ParseTuple(pArgs, "")) |
| 3955 | { |
| 3956 | return NULL; |
| 3957 | } |
| 3958 | count = pjsua_acc_get_count(); |
| 3959 | return Py_BuildValue("i",count); |
| 3960 | } |
| 3961 | |
| 3962 | /* |
| 3963 | * py_pjsua_acc_is_valid |
| 3964 | */ |
| 3965 | static PyObject *py_pjsua_acc_is_valid |
| 3966 | (PyObject *pSelf, PyObject *pArgs) |
| 3967 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3968 | int id; |
| 3969 | int is_valid; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3970 | |
| 3971 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 3972 | { |
| 3973 | return NULL; |
| 3974 | } |
| 3975 | is_valid = pjsua_acc_is_valid(id); |
| 3976 | |
| 3977 | return Py_BuildValue("i", is_valid); |
| 3978 | } |
| 3979 | |
| 3980 | /* |
| 3981 | * py_pjsua_acc_set_default |
| 3982 | */ |
| 3983 | static PyObject *py_pjsua_acc_set_default |
| 3984 | (PyObject *pSelf, PyObject *pArgs) |
| 3985 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 3986 | int id; |
| 3987 | int status; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 3988 | |
| 3989 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 3990 | { |
| 3991 | return NULL; |
| 3992 | } |
| 3993 | status = pjsua_acc_set_default(id); |
| 3994 | |
| 3995 | return Py_BuildValue("i", status); |
| 3996 | } |
| 3997 | |
| 3998 | /* |
| 3999 | * py_pjsua_acc_get_default |
| 4000 | */ |
| 4001 | static PyObject *py_pjsua_acc_get_default |
| 4002 | (PyObject *pSelf, PyObject *pArgs) |
| 4003 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4004 | int id; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4005 | |
| 4006 | if (!PyArg_ParseTuple(pArgs, "")) |
| 4007 | { |
| 4008 | return NULL; |
| 4009 | } |
| 4010 | id = pjsua_acc_get_default(); |
| 4011 | |
| 4012 | return Py_BuildValue("i", id); |
| 4013 | } |
| 4014 | |
| 4015 | /* |
| 4016 | * py_pjsua_acc_add |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4017 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4018 | */ |
| 4019 | static PyObject *py_pjsua_acc_add |
| 4020 | (PyObject *pSelf, PyObject *pArgs) |
| 4021 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4022 | int is_default; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4023 | PyObject * acObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4024 | acc_config_Object * ac; |
| 4025 | pjsua_acc_config cfg; |
| 4026 | |
| 4027 | int p_acc_id; |
| 4028 | int status; |
| 4029 | int i; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4030 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4031 | if (!PyArg_ParseTuple(pArgs, "Oi", &acObj, &is_default)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4032 | { |
| 4033 | return NULL; |
| 4034 | } |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 4035 | |
| 4036 | pjsua_acc_config_default(&cfg); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4037 | if (acObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4038 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4039 | ac = (acc_config_Object *)acObj; |
| 4040 | cfg.cred_count = ac->cred_count; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4041 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 4042 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4043 | /*cfg.cred_info[i] = ac->cred_info[i];*/ |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4044 | pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *) |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4045 | PyList_GetItem((PyObject *)ac->cred_info,i); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4046 | cfg.cred_info[i].data.ptr = PyString_AsString(ci->data); |
| 4047 | cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data)); |
| 4048 | cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm); |
| 4049 | cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm)); |
| 4050 | cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme); |
| 4051 | cfg.cred_info[i].scheme.slen = strlen |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4052 | (PyString_AsString(ci->scheme)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4053 | cfg.cred_info[i].username.ptr = PyString_AsString(ci->username); |
| 4054 | cfg.cred_info[i].username.slen = strlen |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4055 | (PyString_AsString(ci->username)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4056 | cfg.cred_info[i].data_type = ci->data_type; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 4057 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4058 | cfg.force_contact.ptr = PyString_AsString(ac->force_contact); |
| 4059 | cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); |
| 4060 | cfg.id.ptr = PyString_AsString(ac->id); |
| 4061 | cfg.id.slen = strlen(PyString_AsString(ac->id)); |
| 4062 | cfg.priority = ac->priority; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4063 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
| 4064 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4065 | /*cfg.proxy[i] = ac->proxy[i];*/ |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4066 | cfg.proxy[i].ptr = PyString_AsString |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4067 | (PyList_GetItem((PyObject *)ac->proxy,i)); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 4068 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4069 | cfg.proxy_cnt = ac->proxy_cnt; |
| 4070 | cfg.publish_enabled = ac->publish_enabled; |
| 4071 | cfg.reg_timeout = ac->reg_timeout; |
| 4072 | cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); |
| 4073 | cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4074 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4075 | status = pjsua_acc_add(&cfg, is_default, &p_acc_id); |
| 4076 | } else { |
| 4077 | status = pjsua_acc_add(NULL, is_default, &p_acc_id); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4078 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4079 | |
| 4080 | return Py_BuildValue("ii", status, p_acc_id); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | /* |
| 4084 | * py_pjsua_acc_add_local |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4085 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4086 | */ |
| 4087 | static PyObject *py_pjsua_acc_add_local |
| 4088 | (PyObject *pSelf, PyObject *pArgs) |
| 4089 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4090 | int is_default; |
| 4091 | int tid; |
| 4092 | |
| 4093 | int p_acc_id; |
| 4094 | int status; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4095 | |
| 4096 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4097 | if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4098 | { |
| 4099 | return NULL; |
| 4100 | } |
| 4101 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4102 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4103 | status = pjsua_acc_add_local(tid, is_default, &p_acc_id); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4104 | |
| 4105 | return Py_BuildValue("ii", status, p_acc_id); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | /* |
| 4109 | * py_pjsua_acc_del |
| 4110 | */ |
| 4111 | static PyObject *py_pjsua_acc_del |
| 4112 | (PyObject *pSelf, PyObject *pArgs) |
| 4113 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4114 | int acc_id; |
| 4115 | int status; |
| 4116 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4117 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) |
| 4118 | { |
| 4119 | return NULL; |
| 4120 | } |
| 4121 | |
| 4122 | |
| 4123 | status = pjsua_acc_del(acc_id); |
| 4124 | return Py_BuildValue("i", status); |
| 4125 | } |
| 4126 | |
| 4127 | /* |
| 4128 | * py_pjsua_acc_modify |
| 4129 | */ |
| 4130 | static PyObject *py_pjsua_acc_modify |
| 4131 | (PyObject *pSelf, PyObject *pArgs) |
| 4132 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4133 | PyObject * acObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4134 | acc_config_Object * ac; |
| 4135 | pjsua_acc_config cfg; |
| 4136 | int acc_id; |
| 4137 | int status; |
| 4138 | int i; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4139 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4140 | if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &acObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4141 | { |
| 4142 | return NULL; |
| 4143 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4144 | if (acObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4145 | { |
| 4146 | ac = (acc_config_Object *)acObj; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4147 | cfg.cred_count = ac->cred_count; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4148 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
| 4149 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4150 | /*cfg.cred_info[i] = ac->cred_info[i];*/ |
| 4151 | pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *) |
| 4152 | PyList_GetItem((PyObject *)ac->cred_info,i); |
| 4153 | cfg.cred_info[i].data.ptr = PyString_AsString(ci->data); |
| 4154 | cfg.cred_info[i].data.slen = strlen(PyString_AsString(ci->data)); |
| 4155 | cfg.cred_info[i].realm.ptr = PyString_AsString(ci->realm); |
| 4156 | cfg.cred_info[i].realm.slen = strlen(PyString_AsString(ci->realm)); |
| 4157 | cfg.cred_info[i].scheme.ptr = PyString_AsString(ci->scheme); |
| 4158 | cfg.cred_info[i].scheme.slen = strlen |
| 4159 | (PyString_AsString(ci->scheme)); |
| 4160 | cfg.cred_info[i].username.ptr = PyString_AsString(ci->username); |
| 4161 | cfg.cred_info[i].username.slen = strlen |
| 4162 | (PyString_AsString(ci->username)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4163 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4164 | cfg.force_contact.ptr = PyString_AsString(ac->force_contact); |
| 4165 | cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); |
| 4166 | cfg.id.ptr = PyString_AsString(ac->id); |
| 4167 | cfg.id.slen = strlen(PyString_AsString(ac->id)); |
| 4168 | cfg.priority = ac->priority; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4169 | for (i = 0; i < PJSUA_MAX_ACC; i++) |
| 4170 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4171 | /*cfg.proxy[i] = ac->proxy[i];*/ |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4172 | cfg.proxy[i].ptr = PyString_AsString |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4173 | (PyList_GetItem((PyObject *)ac->proxy,i)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4174 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4175 | cfg.proxy_cnt = ac->proxy_cnt; |
| 4176 | cfg.publish_enabled = ac->publish_enabled; |
| 4177 | cfg.reg_timeout = ac->reg_timeout; |
| 4178 | cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); |
| 4179 | cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); |
| 4180 | status = pjsua_acc_modify(acc_id, &cfg); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4181 | } else { |
| 4182 | status = pjsua_acc_modify(acc_id, NULL); |
| 4183 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4184 | return Py_BuildValue("i", status); |
| 4185 | } |
| 4186 | |
| 4187 | /* |
| 4188 | * py_pjsua_acc_set_online_status |
| 4189 | */ |
| 4190 | static PyObject *py_pjsua_acc_set_online_status |
| 4191 | (PyObject *pSelf, PyObject *pArgs) |
| 4192 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4193 | int is_online; |
| 4194 | int acc_id; |
| 4195 | int status; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4196 | |
| 4197 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) |
| 4198 | { |
| 4199 | return NULL; |
| 4200 | } |
| 4201 | |
| 4202 | status = pjsua_acc_set_online_status(acc_id, is_online); |
| 4203 | |
| 4204 | return Py_BuildValue("i", status); |
| 4205 | } |
| 4206 | |
| 4207 | /* |
| 4208 | * py_pjsua_acc_set_registration |
| 4209 | */ |
| 4210 | static PyObject *py_pjsua_acc_set_registration |
| 4211 | (PyObject *pSelf, PyObject *pArgs) |
| 4212 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4213 | int renew; |
| 4214 | int acc_id; |
| 4215 | int status; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4216 | |
| 4217 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) |
| 4218 | { |
| 4219 | return NULL; |
| 4220 | } |
| 4221 | |
| 4222 | status = pjsua_acc_set_registration(acc_id, renew); |
| 4223 | |
| 4224 | return Py_BuildValue("i", status); |
| 4225 | } |
| 4226 | |
| 4227 | /* |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4228 | * py_pjsua_acc_get_info |
| 4229 | * !modified @ 051206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4230 | */ |
| 4231 | static PyObject *py_pjsua_acc_get_info |
| 4232 | (PyObject *pSelf, PyObject *pArgs) |
| 4233 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4234 | int acc_id; |
| 4235 | acc_info_Object * obj; |
| 4236 | pjsua_acc_info info; |
| 4237 | int status; |
| 4238 | int i; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4239 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4240 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4241 | { |
| 4242 | return NULL; |
| 4243 | } |
| 4244 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4245 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4246 | status = pjsua_acc_get_info(acc_id, &info); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4247 | if (status == PJ_SUCCESS) |
| 4248 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4249 | obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL, NULL); |
| 4250 | obj->acc_uri = |
| 4251 | PyString_FromStringAndSize(info.acc_uri.ptr, |
| 4252 | info.acc_uri.slen); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4253 | for (i = 0; i < PJ_ERR_MSG_SIZE; i++) |
| 4254 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4255 | obj->buf_[i] = info.buf_[i]; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4256 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4257 | obj->expires = info.expires; |
| 4258 | obj->has_registration = info.has_registration; |
| 4259 | obj->id = info.id; |
| 4260 | obj->is_default = info.is_default; |
| 4261 | obj->online_status = info.online_status; |
| 4262 | obj->status = info.status; |
| 4263 | obj->status_text = |
| 4264 | PyString_FromStringAndSize(info.status_text.ptr, |
| 4265 | info.status_text.slen); |
| 4266 | return Py_BuildValue("O", obj); |
| 4267 | } else { |
| 4268 | Py_INCREF(Py_None); |
| 4269 | return Py_None; |
| 4270 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | /* |
| 4274 | * py_pjsua_enum_accs |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4275 | * !modified @ 241206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4276 | */ |
| 4277 | static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) |
| 4278 | { |
| 4279 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4280 | PyObject *list; |
| 4281 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4282 | pjsua_acc_id id[PJSUA_MAX_ACC]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4283 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4284 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4285 | { |
| 4286 | return NULL; |
| 4287 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4288 | c = PJ_ARRAY_SIZE(id); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4289 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4290 | status = pjsua_enum_accs(id, &c); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4291 | |
| 4292 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4293 | for (i = 0; i < c; i++) |
| 4294 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4295 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4296 | if (ret == -1) |
| 4297 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4298 | return NULL; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4299 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4302 | return Py_BuildValue("O",list); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | /* |
| 4306 | * py_pjsua_acc_enum_info |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4307 | * !modified @ 241206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4308 | */ |
| 4309 | static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) |
| 4310 | { |
| 4311 | pj_status_t status; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4312 | PyObject *list; |
| 4313 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4314 | pjsua_acc_info info[PJSUA_MAX_ACC]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4315 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4316 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4317 | { |
| 4318 | return NULL; |
| 4319 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4320 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4321 | c = PJ_ARRAY_SIZE(info); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4322 | status = pjsua_acc_enum_info(info, &c); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4323 | |
| 4324 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4325 | for (i = 0; i < c; i++) |
| 4326 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4327 | int ret; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4328 | int j; |
| 4329 | acc_info_Object *obj; |
| 4330 | obj = (acc_info_Object *)acc_info_new(&acc_info_Type,NULL,NULL); |
| 4331 | obj->acc_uri = PyString_FromStringAndSize |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4332 | (info[i].acc_uri.ptr, info[i].acc_uri.slen); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4333 | for(j = 0; j < PJ_ERR_MSG_SIZE; j++) |
| 4334 | { |
| 4335 | obj->buf_[j] = info[i].buf_[j]; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4336 | } |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4337 | obj->expires = info[i].expires; |
| 4338 | obj->has_registration = info[i].has_registration; |
| 4339 | obj->id = info[i].id; |
| 4340 | obj->is_default = info[i].is_default; |
| 4341 | obj->online_status = info[i].online_status; |
| 4342 | obj->status = info[i].status; |
| 4343 | obj->status_text = PyString_FromStringAndSize(info[i].status_text.ptr, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4344 | info[i].status_text.slen); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4345 | ret = PyList_SetItem(list, i, (PyObject *)obj); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4346 | if (ret == -1) { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4347 | return NULL; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4351 | return Py_BuildValue("O",list); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | /* |
| 4355 | * py_pjsua_acc_find_for_outgoing |
| 4356 | */ |
| 4357 | static PyObject *py_pjsua_acc_find_for_outgoing |
| 4358 | (PyObject *pSelf, PyObject *pArgs) |
| 4359 | { |
| 4360 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4361 | int acc_id; |
| 4362 | PyObject * url; |
| 4363 | pj_str_t str; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4364 | |
| 4365 | if (!PyArg_ParseTuple(pArgs, "O", &url)) |
| 4366 | { |
| 4367 | return NULL; |
| 4368 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4369 | str.ptr = PyString_AsString(url); |
| 4370 | str.slen = strlen(PyString_AsString(url)); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4371 | |
| 4372 | acc_id = pjsua_acc_find_for_outgoing(&str); |
| 4373 | |
| 4374 | return Py_BuildValue("i", acc_id); |
| 4375 | } |
| 4376 | |
| 4377 | /* |
| 4378 | * py_pjsua_acc_find_for_incoming |
| 4379 | */ |
| 4380 | static PyObject *py_pjsua_acc_find_for_incoming |
| 4381 | (PyObject *pSelf, PyObject *pArgs) |
| 4382 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4383 | int acc_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4384 | PyObject * tmpObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4385 | pjsip_rx_data_Object * obj; |
| 4386 | pjsip_rx_data * rdata; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4387 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4388 | if (!PyArg_ParseTuple(pArgs, "O", &tmpObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4389 | { |
| 4390 | return NULL; |
| 4391 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4392 | if (tmpObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4393 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4394 | obj = (pjsip_rx_data_Object *)tmpObj; |
| 4395 | rdata = obj->rdata; |
| 4396 | acc_id = pjsua_acc_find_for_incoming(rdata); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4397 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4398 | acc_id = pjsua_acc_find_for_incoming(NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4399 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4400 | return Py_BuildValue("i", acc_id); |
| 4401 | } |
| 4402 | |
| 4403 | /* |
| 4404 | * py_pjsua_acc_create_uac_contact |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4405 | * !modified @ 061206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4406 | */ |
| 4407 | static PyObject *py_pjsua_acc_create_uac_contact |
| 4408 | (PyObject *pSelf, PyObject *pArgs) |
| 4409 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4410 | int status; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4411 | int acc_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4412 | PyObject * pObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4413 | pj_pool_Object * p; |
| 4414 | pj_pool_t * pool; |
| 4415 | PyObject * strc; |
| 4416 | pj_str_t contact; |
| 4417 | PyObject * stru; |
| 4418 | pj_str_t uri; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4419 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4420 | if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &stru)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4421 | { |
| 4422 | return NULL; |
| 4423 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4424 | if (pObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4425 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4426 | p = (pj_pool_Object *)pObj; |
| 4427 | pool = p->pool; |
| 4428 | uri.ptr = PyString_AsString(stru); |
| 4429 | uri.slen = strlen(PyString_AsString(stru)); |
| 4430 | status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4431 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4432 | status = pjsua_acc_create_uac_contact(NULL, &contact, acc_id, &uri); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4433 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4434 | strc = PyString_FromStringAndSize(contact.ptr, contact.slen); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4435 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4436 | return Py_BuildValue("O", strc); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | /* |
| 4440 | * py_pjsua_acc_create_uas_contact |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4441 | * !modified @ 061206 |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4442 | */ |
| 4443 | static PyObject *py_pjsua_acc_create_uas_contact |
| 4444 | (PyObject *pSelf, PyObject *pArgs) |
| 4445 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4446 | int status; |
| 4447 | int acc_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4448 | PyObject * pObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4449 | pj_pool_Object * p; |
| 4450 | pj_pool_t * pool; |
| 4451 | PyObject * strc; |
| 4452 | pj_str_t contact; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4453 | PyObject * rObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4454 | pjsip_rx_data_Object * objr; |
| 4455 | pjsip_rx_data * rdata; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4456 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4457 | if (!PyArg_ParseTuple(pArgs, "OiO", &pObj, &acc_id, &rObj)) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4458 | { |
| 4459 | return NULL; |
| 4460 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4461 | if (pObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4462 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4463 | p = (pj_pool_Object *)pObj; |
| 4464 | pool = p->pool; |
| 4465 | } else { |
| 4466 | pool = NULL; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4467 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4468 | if (rObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4469 | { |
| 4470 | objr = (pjsip_rx_data_Object *)rObj; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4471 | rdata = objr->rdata; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4472 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4473 | rdata = NULL; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4474 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4475 | status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4476 | strc = PyString_FromStringAndSize(contact.ptr, contact.slen); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4477 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4478 | return Py_BuildValue("O", strc); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | static char pjsua_acc_config_default_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4482 | "py_pjsua.Acc_Config py_pjsua.acc_config_default () " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4483 | "Call this function to initialize account config with default values."; |
| 4484 | static char pjsua_acc_get_count_doc[] = |
| 4485 | "int py_pjsua.acc_get_count () " |
| 4486 | "Get number of current accounts."; |
| 4487 | static char pjsua_acc_is_valid_doc[] = |
| 4488 | "int py_pjsua.acc_is_valid (int acc_id) " |
| 4489 | "Check if the specified account ID is valid."; |
| 4490 | static char pjsua_acc_set_default_doc[] = |
| 4491 | "int py_pjsua.acc_set_default (int acc_id) " |
| 4492 | "Set default account to be used when incoming " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4493 | "and outgoing requests doesn't match any accounts."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4494 | static char pjsua_acc_get_default_doc[] = |
| 4495 | "int py_pjsua.acc_get_default () " |
| 4496 | "Get default account."; |
| 4497 | static char pjsua_acc_add_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4498 | "int, int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, " |
| 4499 | "int is_default) " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4500 | "Add a new account to pjsua. PJSUA must have been initialized " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4501 | "(with pjsua_init()) before calling this function."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4502 | static char pjsua_acc_add_local_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4503 | "int,int py_pjsua.acc_add_local (int tid, " |
| 4504 | "int is_default) " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4505 | "Add a local account. A local account is used to identify " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4506 | "local endpoint instead of a specific user, and for this reason, " |
| 4507 | "a transport ID is needed to obtain the local address information."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4508 | static char pjsua_acc_del_doc[] = |
| 4509 | "int py_pjsua.acc_del (int acc_id) " |
| 4510 | "Delete account."; |
| 4511 | static char pjsua_acc_modify_doc[] = |
| 4512 | "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) " |
| 4513 | "Modify account information."; |
| 4514 | static char pjsua_acc_set_online_status_doc[] = |
| 4515 | "int py_pjsua.acc_set_online_status (int acc_id, int is_online) " |
| 4516 | "Modify account's presence status to be advertised " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4517 | "to remote/presence subscribers."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4518 | static char pjsua_acc_set_registration_doc[] = |
| 4519 | "int py_pjsua.acc_set_registration (int acc_id, int renew) " |
| 4520 | "Update registration or perform unregistration."; |
| 4521 | static char pjsua_acc_get_info_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4522 | "py_pjsua.Acc_Info py_pjsua.acc_get_info (int acc_id) " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4523 | "Get account information."; |
| 4524 | static char pjsua_enum_accs_doc[] = |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4525 | "int[] py_pjsua.enum_accs () " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4526 | "Enum accounts all account ids."; |
| 4527 | static char pjsua_acc_enum_info_doc[] = |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4528 | "py_pjsua.Acc_Info[] py_pjsua.acc_enum_info () " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4529 | "Enum accounts info."; |
| 4530 | static char pjsua_acc_find_for_outgoing_doc[] = |
| 4531 | "int py_pjsua.acc_find_for_outgoing (string url) " |
| 4532 | "This is an internal function to find the most appropriate account " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4533 | "to used to reach to the specified URL."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4534 | static char pjsua_acc_find_for_incoming_doc[] = |
| 4535 | "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) " |
| 4536 | "This is an internal function to find the most appropriate account " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4537 | "to be used to handle incoming calls."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4538 | static char pjsua_acc_create_uac_contact_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4539 | "string py_pjsua.acc_create_uac_contact (pj_pool_Object pool, " |
| 4540 | "int acc_id, string uri) " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4541 | "Create a suitable URI to be put as Contact based on the specified " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4542 | "target URI for the specified account."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4543 | static char pjsua_acc_create_uas_contact_doc[] = |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4544 | "string py_pjsua.acc_create_uas_contact (pj_pool_Object pool, " |
| 4545 | "int acc_id, pjsip_rx_data_Object rdata) " |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4546 | "Create a suitable URI to be put as Contact based on the information " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4547 | "in the incoming request."; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4548 | |
| 4549 | /* END OF LIB ACCOUNT */ |
| 4550 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4551 | /* LIB BUDDY */ |
| 4552 | |
| 4553 | |
| 4554 | |
| 4555 | /* |
| 4556 | * buddy_config_Object |
| 4557 | * Buddy Config |
| 4558 | */ |
| 4559 | typedef struct |
| 4560 | { |
| 4561 | PyObject_HEAD |
| 4562 | /* Type-specific fields go here. */ |
| 4563 | |
| 4564 | PyObject * uri; |
| 4565 | int subscribe; |
| 4566 | } buddy_config_Object; |
| 4567 | |
| 4568 | |
| 4569 | /* |
| 4570 | * buddy_config_dealloc |
| 4571 | * deletes a buddy_config from memory |
| 4572 | */ |
| 4573 | static void buddy_config_dealloc(buddy_config_Object* self) |
| 4574 | { |
| 4575 | Py_XDECREF(self->uri); |
| 4576 | self->ob_type->tp_free((PyObject*)self); |
| 4577 | } |
| 4578 | |
| 4579 | |
| 4580 | /* |
| 4581 | * buddy_config_new |
| 4582 | * constructor for buddy_config object |
| 4583 | */ |
| 4584 | static PyObject * buddy_config_new(PyTypeObject *type, PyObject *args, |
| 4585 | PyObject *kwds) |
| 4586 | { |
| 4587 | buddy_config_Object *self; |
| 4588 | |
| 4589 | self = (buddy_config_Object *)type->tp_alloc(type, 0); |
| 4590 | if (self != NULL) |
| 4591 | { |
| 4592 | self->uri = PyString_FromString(""); |
| 4593 | if (self->uri == NULL) |
| 4594 | { |
| 4595 | Py_DECREF(self); |
| 4596 | return NULL; |
| 4597 | } |
| 4598 | } |
| 4599 | return (PyObject *)self; |
| 4600 | } |
| 4601 | |
| 4602 | /* |
| 4603 | * buddy_config_members |
| 4604 | */ |
| 4605 | static PyMemberDef buddy_config_members[] = |
| 4606 | { |
| 4607 | |
| 4608 | { |
| 4609 | "uri", T_OBJECT_EX, |
| 4610 | offsetof(buddy_config_Object, uri), 0, |
| 4611 | "TBuddy URL or name address." |
| 4612 | }, |
| 4613 | |
| 4614 | { |
| 4615 | "subscribe", T_INT, |
| 4616 | offsetof(buddy_config_Object, subscribe), 0, |
| 4617 | "Specify whether presence subscription should start immediately. " |
| 4618 | }, |
| 4619 | |
| 4620 | {NULL} /* Sentinel */ |
| 4621 | }; |
| 4622 | |
| 4623 | |
| 4624 | |
| 4625 | |
| 4626 | /* |
| 4627 | * buddy_config_Type |
| 4628 | */ |
| 4629 | static PyTypeObject buddy_config_Type = |
| 4630 | { |
| 4631 | PyObject_HEAD_INIT(NULL) |
| 4632 | 0, /*ob_size*/ |
| 4633 | "py_pjsua.Buddy_Config", /*tp_name*/ |
| 4634 | sizeof(buddy_config_Object), /*tp_basicsize*/ |
| 4635 | 0, /*tp_itemsize*/ |
| 4636 | (destructor)buddy_config_dealloc,/*tp_dealloc*/ |
| 4637 | 0, /*tp_print*/ |
| 4638 | 0, /*tp_getattr*/ |
| 4639 | 0, /*tp_setattr*/ |
| 4640 | 0, /*tp_compare*/ |
| 4641 | 0, /*tp_repr*/ |
| 4642 | 0, /*tp_as_number*/ |
| 4643 | 0, /*tp_as_sequence*/ |
| 4644 | 0, /*tp_as_mapping*/ |
| 4645 | 0, /*tp_hash */ |
| 4646 | 0, /*tp_call*/ |
| 4647 | 0, /*tp_str*/ |
| 4648 | 0, /*tp_getattro*/ |
| 4649 | 0, /*tp_setattro*/ |
| 4650 | 0, /*tp_as_buffer*/ |
| 4651 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 4652 | "Buddy Config objects", /* tp_doc */ |
| 4653 | 0, /* tp_traverse */ |
| 4654 | 0, /* tp_clear */ |
| 4655 | 0, /* tp_richcompare */ |
| 4656 | 0, /* tp_weaklistoffset */ |
| 4657 | 0, /* tp_iter */ |
| 4658 | 0, /* tp_iternext */ |
| 4659 | 0, /* tp_methods */ |
| 4660 | buddy_config_members, /* tp_members */ |
| 4661 | 0, /* tp_getset */ |
| 4662 | 0, /* tp_base */ |
| 4663 | 0, /* tp_dict */ |
| 4664 | 0, /* tp_descr_get */ |
| 4665 | 0, /* tp_descr_set */ |
| 4666 | 0, /* tp_dictoffset */ |
| 4667 | 0, /* tp_init */ |
| 4668 | 0, /* tp_alloc */ |
| 4669 | buddy_config_new, /* tp_new */ |
| 4670 | |
| 4671 | }; |
| 4672 | |
| 4673 | /* |
| 4674 | * buddy_info_Object |
| 4675 | * Buddy Info |
| 4676 | * !modified @ 071206 |
| 4677 | */ |
| 4678 | typedef struct |
| 4679 | { |
| 4680 | PyObject_HEAD |
| 4681 | /* Type-specific fields go here. */ |
| 4682 | int id; |
| 4683 | PyObject * uri; |
| 4684 | PyObject * contact; |
| 4685 | int status; |
| 4686 | PyObject * status_text; |
| 4687 | int monitor_pres; |
| 4688 | char buf_[256]; |
| 4689 | } buddy_info_Object; |
| 4690 | |
| 4691 | |
| 4692 | /* |
| 4693 | * buddy_info_dealloc |
| 4694 | * deletes a buddy_info from memory |
| 4695 | * !modified @ 071206 |
| 4696 | */ |
| 4697 | static void buddy_info_dealloc(buddy_info_Object* self) |
| 4698 | { |
| 4699 | Py_XDECREF(self->uri); |
| 4700 | Py_XDECREF(self->contact); |
| 4701 | Py_XDECREF(self->status_text); |
| 4702 | |
| 4703 | self->ob_type->tp_free((PyObject*)self); |
| 4704 | } |
| 4705 | |
| 4706 | |
| 4707 | /* |
| 4708 | * buddy_info_new |
| 4709 | * constructor for buddy_info object |
| 4710 | * !modified @ 071206 |
| 4711 | */ |
| 4712 | static PyObject * buddy_info_new(PyTypeObject *type, PyObject *args, |
| 4713 | PyObject *kwds) |
| 4714 | { |
| 4715 | buddy_info_Object *self; |
| 4716 | |
| 4717 | self = (buddy_info_Object *)type->tp_alloc(type, 0); |
| 4718 | if (self != NULL) |
| 4719 | { |
| 4720 | self->uri = PyString_FromString(""); |
| 4721 | if (self->uri == NULL) |
| 4722 | { |
| 4723 | Py_DECREF(self); |
| 4724 | return NULL; |
| 4725 | } |
| 4726 | self->contact = PyString_FromString(""); |
| 4727 | if (self->contact == NULL) |
| 4728 | { |
| 4729 | Py_DECREF(self); |
| 4730 | return NULL; |
| 4731 | } |
| 4732 | self->status_text = PyString_FromString(""); |
| 4733 | if (self->status_text == NULL) |
| 4734 | { |
| 4735 | Py_DECREF(self); |
| 4736 | return NULL; |
| 4737 | } |
| 4738 | |
| 4739 | } |
| 4740 | return (PyObject *)self; |
| 4741 | } |
| 4742 | |
| 4743 | /* |
| 4744 | * buddy_info_members |
| 4745 | * !modified @ 071206 |
| 4746 | */ |
| 4747 | static PyMemberDef buddy_info_members[] = |
| 4748 | { |
| 4749 | { |
| 4750 | "id", T_INT, |
| 4751 | offsetof(buddy_info_Object, id), 0, |
| 4752 | "The buddy ID." |
| 4753 | }, |
| 4754 | { |
| 4755 | "uri", T_OBJECT_EX, |
| 4756 | offsetof(buddy_info_Object, uri), 0, |
| 4757 | "The full URI of the buddy, as specified in the configuration. " |
| 4758 | }, |
| 4759 | { |
| 4760 | "contact", T_OBJECT_EX, |
| 4761 | offsetof(buddy_info_Object, contact), 0, |
| 4762 | "Buddy's Contact, only available when presence subscription " |
| 4763 | "has been established to the buddy." |
| 4764 | }, |
| 4765 | { |
| 4766 | "status", T_INT, |
| 4767 | offsetof(buddy_info_Object, status), 0, |
| 4768 | "Buddy's online status. " |
| 4769 | }, |
| 4770 | { |
| 4771 | "status_text", T_OBJECT_EX, |
| 4772 | offsetof(buddy_info_Object, status_text), 0, |
| 4773 | "Text to describe buddy's online status." |
| 4774 | }, |
| 4775 | { |
| 4776 | "monitor_pres", T_INT, |
| 4777 | offsetof(buddy_info_Object, monitor_pres), 0, |
| 4778 | "Flag to indicate that we should monitor the presence information " |
| 4779 | "for this buddy (normally yes, unless explicitly disabled). " |
| 4780 | }, |
| 4781 | |
| 4782 | |
| 4783 | {NULL} /* Sentinel */ |
| 4784 | }; |
| 4785 | |
| 4786 | |
| 4787 | |
| 4788 | |
| 4789 | /* |
| 4790 | * buddy_info_Type |
| 4791 | */ |
| 4792 | static PyTypeObject buddy_info_Type = |
| 4793 | { |
| 4794 | PyObject_HEAD_INIT(NULL) |
| 4795 | 0, /*ob_size*/ |
| 4796 | "py_pjsua.Buddy_Info", /*tp_name*/ |
| 4797 | sizeof(buddy_info_Object), /*tp_basicsize*/ |
| 4798 | 0, /*tp_itemsize*/ |
| 4799 | (destructor)buddy_info_dealloc,/*tp_dealloc*/ |
| 4800 | 0, /*tp_print*/ |
| 4801 | 0, /*tp_getattr*/ |
| 4802 | 0, /*tp_setattr*/ |
| 4803 | 0, /*tp_compare*/ |
| 4804 | 0, /*tp_repr*/ |
| 4805 | 0, /*tp_as_number*/ |
| 4806 | 0, /*tp_as_sequence*/ |
| 4807 | 0, /*tp_as_mapping*/ |
| 4808 | 0, /*tp_hash */ |
| 4809 | 0, /*tp_call*/ |
| 4810 | 0, /*tp_str*/ |
| 4811 | 0, /*tp_getattro*/ |
| 4812 | 0, /*tp_setattro*/ |
| 4813 | 0, /*tp_as_buffer*/ |
| 4814 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 4815 | "Buddy Info objects", /* tp_doc */ |
| 4816 | 0, /* tp_traverse */ |
| 4817 | 0, /* tp_clear */ |
| 4818 | 0, /* tp_richcompare */ |
| 4819 | 0, /* tp_weaklistoffset */ |
| 4820 | 0, /* tp_iter */ |
| 4821 | 0, /* tp_iternext */ |
| 4822 | 0, /* tp_methods */ |
| 4823 | buddy_info_members, /* tp_members */ |
| 4824 | 0, /* tp_getset */ |
| 4825 | 0, /* tp_base */ |
| 4826 | 0, /* tp_dict */ |
| 4827 | 0, /* tp_descr_get */ |
| 4828 | 0, /* tp_descr_set */ |
| 4829 | 0, /* tp_dictoffset */ |
| 4830 | 0, /* tp_init */ |
| 4831 | 0, /* tp_alloc */ |
| 4832 | buddy_info_new, /* tp_new */ |
| 4833 | |
| 4834 | }; |
| 4835 | |
| 4836 | /* |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4837 | * py_pjsua_buddy_config_default |
| 4838 | */ |
| 4839 | static PyObject *py_pjsua_buddy_config_default |
| 4840 | (PyObject *pSelf, PyObject *pArgs) |
| 4841 | { |
| 4842 | buddy_config_Object *obj; |
| 4843 | pjsua_buddy_config cfg; |
| 4844 | |
| 4845 | if (!PyArg_ParseTuple(pArgs, "")) |
| 4846 | { |
| 4847 | return NULL; |
| 4848 | } |
| 4849 | |
| 4850 | pjsua_buddy_config_default(&cfg); |
| 4851 | obj = (buddy_config_Object *) buddy_config_new |
| 4852 | (&buddy_config_Type,NULL,NULL); |
| 4853 | obj->uri = PyString_FromStringAndSize( |
| 4854 | cfg.uri.ptr, cfg.uri.slen |
| 4855 | ); |
| 4856 | obj->subscribe = cfg.subscribe; |
| 4857 | |
| 4858 | return (PyObject *)obj; |
| 4859 | } |
| 4860 | |
| 4861 | /* |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4862 | * py_pjsua_get_buddy_count |
| 4863 | */ |
| 4864 | static PyObject *py_pjsua_get_buddy_count |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4865 | (PyObject *pSelf, PyObject *pArgs) |
| 4866 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4867 | int ret; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4868 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4869 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4870 | { |
| 4871 | return NULL; |
| 4872 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4873 | ret = pjsua_get_buddy_count(); |
| 4874 | |
| 4875 | return Py_BuildValue("i", ret); |
| 4876 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4877 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4878 | /* |
| 4879 | * py_pjsua_buddy_is_valid |
| 4880 | */ |
| 4881 | static PyObject *py_pjsua_buddy_is_valid |
| 4882 | (PyObject *pSelf, PyObject *pArgs) |
| 4883 | { |
| 4884 | int id; |
| 4885 | int is_valid; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4886 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4887 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 4888 | { |
| 4889 | return NULL; |
| 4890 | } |
| 4891 | is_valid = pjsua_buddy_is_valid(id); |
| 4892 | |
| 4893 | return Py_BuildValue("i", is_valid); |
| 4894 | } |
| 4895 | |
| 4896 | /* |
| 4897 | * py_pjsua_enum_buddies |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4898 | * !modified @ 241206 |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4899 | */ |
| 4900 | static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs) |
| 4901 | { |
| 4902 | pj_status_t status; |
| 4903 | PyObject *list; |
| 4904 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4905 | pjsua_buddy_id id[PJSUA_MAX_BUDDIES]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4906 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4907 | if (!PyArg_ParseTuple(pArgs, "")) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4908 | { |
| 4909 | return NULL; |
| 4910 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 4911 | c = PJ_ARRAY_SIZE(id); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4912 | status = pjsua_enum_buddies(id, &c); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4913 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4914 | for (i = 0; i < c; i++) |
| 4915 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4916 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4917 | if (ret == -1) |
| 4918 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4919 | return NULL; |
| 4920 | } |
| 4921 | } |
| 4922 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4923 | return Py_BuildValue("O",list); |
| 4924 | } |
| 4925 | |
| 4926 | /* |
| 4927 | * py_pjsua_buddy_get_info |
| 4928 | * !modified @ 071206 |
| 4929 | */ |
| 4930 | static PyObject *py_pjsua_buddy_get_info |
| 4931 | (PyObject *pSelf, PyObject *pArgs) |
| 4932 | { |
| 4933 | int buddy_id; |
| 4934 | buddy_info_Object * obj; |
| 4935 | pjsua_buddy_info info; |
| 4936 | int status; |
| 4937 | int i; |
| 4938 | |
| 4939 | if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) |
| 4940 | { |
| 4941 | return NULL; |
| 4942 | } |
| 4943 | |
| 4944 | |
| 4945 | status = pjsua_buddy_get_info(buddy_id, &info); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4946 | if (status == PJ_SUCCESS) |
| 4947 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4948 | obj = (buddy_info_Object *)buddy_info_new(&buddy_info_Type,NULL,NULL); |
| 4949 | obj->id = info.id; |
| 4950 | Py_XDECREF(obj->uri); |
| 4951 | obj->uri = |
| 4952 | PyString_FromStringAndSize(info.uri.ptr, |
| 4953 | info.uri.slen); |
| 4954 | Py_XDECREF(obj->contact); |
| 4955 | obj->contact = |
| 4956 | PyString_FromStringAndSize(info.contact.ptr, |
| 4957 | info.contact.slen); |
| 4958 | obj->status = info.status; |
| 4959 | Py_XDECREF(obj->status_text); |
| 4960 | obj->status_text = |
| 4961 | PyString_FromStringAndSize(info.status_text.ptr, |
| 4962 | info.status_text.slen); |
| 4963 | obj->monitor_pres = info.monitor_pres; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4964 | for (i = 0; i < 256; i++) |
| 4965 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4966 | |
| 4967 | obj->buf_[i] = info.buf_[i]; |
| 4968 | } |
| 4969 | |
| 4970 | return Py_BuildValue("O", obj); |
| 4971 | } else { |
| 4972 | Py_INCREF(Py_None); |
| 4973 | return Py_None; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | /* |
| 4978 | * py_pjsua_buddy_add |
| 4979 | * !modified @ 061206 |
| 4980 | */ |
| 4981 | static PyObject *py_pjsua_buddy_add |
| 4982 | (PyObject *pSelf, PyObject *pArgs) |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4983 | { |
| 4984 | PyObject * bcObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4985 | buddy_config_Object * bc; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4986 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4987 | pjsua_buddy_config cfg; |
| 4988 | |
| 4989 | int p_buddy_id; |
| 4990 | int status; |
| 4991 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4992 | if (!PyArg_ParseTuple(pArgs, "O", &bcObj)) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 4993 | { |
| 4994 | return NULL; |
| 4995 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4996 | if (bcObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 4997 | { |
| 4998 | bc = (buddy_config_Object *)bcObj; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 4999 | |
| 5000 | cfg.subscribe = bc->subscribe; |
| 5001 | cfg.uri.ptr = PyString_AsString(bc->uri); |
| 5002 | cfg.uri.slen = strlen(PyString_AsString(bc->uri)); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5003 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5004 | status = pjsua_buddy_add(&cfg, &p_buddy_id); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5005 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5006 | status = pjsua_buddy_add(NULL, &p_buddy_id); |
| 5007 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5008 | return Py_BuildValue("ii", status, p_buddy_id); |
| 5009 | } |
| 5010 | |
| 5011 | /* |
| 5012 | * py_pjsua_buddy_del |
| 5013 | */ |
| 5014 | static PyObject *py_pjsua_buddy_del |
| 5015 | (PyObject *pSelf, PyObject *pArgs) |
| 5016 | { |
| 5017 | int buddy_id; |
| 5018 | int status; |
| 5019 | |
| 5020 | if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) |
| 5021 | { |
| 5022 | return NULL; |
| 5023 | } |
| 5024 | |
| 5025 | |
| 5026 | status = pjsua_buddy_del(buddy_id); |
| 5027 | return Py_BuildValue("i", status); |
| 5028 | } |
| 5029 | |
| 5030 | /* |
| 5031 | * py_pjsua_buddy_subscribe_pres |
| 5032 | */ |
| 5033 | static PyObject *py_pjsua_buddy_subscribe_pres |
| 5034 | (PyObject *pSelf, PyObject *pArgs) |
| 5035 | { |
| 5036 | int buddy_id; |
| 5037 | int status; |
| 5038 | int subscribe; |
| 5039 | |
| 5040 | if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) |
| 5041 | { |
| 5042 | return NULL; |
| 5043 | } |
| 5044 | |
| 5045 | |
| 5046 | status = pjsua_buddy_subscribe_pres(buddy_id, subscribe); |
| 5047 | return Py_BuildValue("i", status); |
| 5048 | } |
| 5049 | |
| 5050 | /* |
| 5051 | * py_pjsua_pres_dump |
| 5052 | */ |
| 5053 | static PyObject *py_pjsua_pres_dump |
| 5054 | (PyObject *pSelf, PyObject *pArgs) |
| 5055 | { |
| 5056 | int verbose; |
| 5057 | |
| 5058 | if (!PyArg_ParseTuple(pArgs, "i", &verbose)) |
| 5059 | { |
| 5060 | return NULL; |
| 5061 | } |
| 5062 | |
| 5063 | |
| 5064 | pjsua_pres_dump(verbose); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 5065 | Py_INCREF(Py_None); |
| 5066 | return Py_None; |
| 5067 | } |
| 5068 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5069 | /* |
| 5070 | * py_pjsua_im_send |
| 5071 | * !modified @ 071206 |
| 5072 | */ |
| 5073 | static PyObject *py_pjsua_im_send |
| 5074 | (PyObject *pSelf, PyObject *pArgs) |
| 5075 | { |
| 5076 | int status; |
| 5077 | int acc_id; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5078 | pj_str_t * mime_type, tmp_mime_type; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5079 | pj_str_t to, content; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5080 | PyObject * st; |
| 5081 | PyObject * smt; |
| 5082 | PyObject * sc; |
| 5083 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5084 | PyObject * omdObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5085 | msg_data_Object * omd; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5086 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5087 | int user_data; |
| 5088 | pj_pool_t *pool; |
| 5089 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5090 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5091 | if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id, |
| 5092 | &st, &smt, &sc, &omdObj, &user_data)) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5093 | { |
| 5094 | return NULL; |
| 5095 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5096 | if (smt != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5097 | { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5098 | mime_type = &tmp_mime_type; |
| 5099 | tmp_mime_type.ptr = PyString_AsString(smt); |
| 5100 | tmp_mime_type.slen = strlen(PyString_AsString(smt)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5101 | } else { |
| 5102 | mime_type = NULL; |
| 5103 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5104 | to.ptr = PyString_AsString(st); |
| 5105 | to.slen = strlen(PyString_AsString(st)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5106 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5107 | content.ptr = PyString_AsString(sc); |
| 5108 | content.slen = strlen(PyString_AsString(sc)); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5109 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5110 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5111 | |
| 5112 | omd = (msg_data_Object *)omdObj; |
| 5113 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 5114 | msg_data.content_type.slen = strlen |
| 5115 | (PyString_AsString(omd->content_type)); |
| 5116 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 5117 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5118 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5119 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5120 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5121 | status = pjsua_im_send(acc_id, &to, mime_type, |
| 5122 | &content, &msg_data, (void *)user_data); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5123 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5124 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5125 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5126 | status = pjsua_im_send(acc_id, &to, mime_type, |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5127 | &content, NULL, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5128 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5129 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5130 | return Py_BuildValue("i",status); |
| 5131 | } |
| 5132 | |
| 5133 | /* |
| 5134 | * py_pjsua_im_typing |
| 5135 | */ |
| 5136 | static PyObject *py_pjsua_im_typing |
| 5137 | (PyObject *pSelf, PyObject *pArgs) |
| 5138 | { |
| 5139 | int status; |
| 5140 | int acc_id; |
| 5141 | pj_str_t to; |
| 5142 | PyObject * st; |
| 5143 | int is_typing; |
| 5144 | pjsua_msg_data msg_data; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5145 | PyObject * omdObj; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5146 | msg_data_Object * omd; |
| 5147 | pj_pool_t * pool; |
| 5148 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5149 | if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &st, &is_typing, &omdObj)) |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5150 | { |
| 5151 | return NULL; |
| 5152 | } |
| 5153 | |
| 5154 | to.ptr = PyString_AsString(st); |
| 5155 | to.slen = strlen(PyString_AsString(st)); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5156 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5157 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5158 | omd = (msg_data_Object *)omdObj; |
| 5159 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 5160 | msg_data.content_type.slen = strlen |
| 5161 | (PyString_AsString(omd->content_type)); |
| 5162 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 5163 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5164 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5165 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5166 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 5167 | status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data); |
| 5168 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5169 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 5170 | status = pjsua_im_typing(acc_id, &to, is_typing, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5171 | } |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5172 | return Py_BuildValue("i",status); |
| 5173 | } |
| 5174 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5175 | static char pjsua_buddy_config_default_doc[] = |
| 5176 | "py_pjsua.Buddy_Config py_pjsua.buddy_config_default () " |
| 5177 | "Set default values to the buddy config."; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5178 | static char pjsua_get_buddy_count_doc[] = |
| 5179 | "int py_pjsua.get_buddy_count () " |
| 5180 | "Get total number of buddies."; |
| 5181 | static char pjsua_buddy_is_valid_doc[] = |
| 5182 | "int py_pjsua.buddy_is_valid (int buddy_id) " |
| 5183 | "Check if buddy ID is valid."; |
| 5184 | static char pjsua_enum_buddies_doc[] = |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5185 | "int[] py_pjsua.enum_buddies () " |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 5186 | "Enum buddy IDs."; |
| 5187 | static char pjsua_buddy_get_info_doc[] = |
| 5188 | "py_pjsua.Buddy_Info py_pjsua.buddy_get_info (int buddy_id) " |
| 5189 | "Get detailed buddy info."; |
| 5190 | static char pjsua_buddy_add_doc[] = |
| 5191 | "int,int py_pjsua.buddy_add (py_pjsua.Buddy_Config cfg) " |
| 5192 | "Add new buddy."; |
| 5193 | static char pjsua_buddy_del_doc[] = |
| 5194 | "int py_pjsua.buddy_del (int buddy_id) " |
| 5195 | "Delete buddy."; |
| 5196 | static char pjsua_buddy_subscribe_pres_doc[] = |
| 5197 | "int py_pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) " |
| 5198 | "Enable/disable buddy's presence monitoring."; |
| 5199 | static char pjsua_pres_dump_doc[] = |
| 5200 | "void py_pjsua.pres_dump (int verbose) " |
| 5201 | "Dump presence subscriptions to log file."; |
| 5202 | static char pjsua_im_send_doc[] = |
| 5203 | "int py_pjsua.im_send (int acc_id, string to, string mime_type, " |
| 5204 | "string content, py_pjsua.Msg_Data msg_data, int user_data) " |
| 5205 | "Send instant messaging outside dialog, using the specified account " |
| 5206 | "for route set and authentication."; |
| 5207 | static char pjsua_im_typing_doc[] = |
| 5208 | "int py_pjsua.im_typing (int acc_id, string to, int is_typing, " |
| 5209 | "py_pjsua.Msg_Data msg_data) " |
| 5210 | "Send typing indication outside dialog."; |
| 5211 | |
| 5212 | /* END OF LIB BUDDY */ |
| 5213 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5214 | /* LIB MEDIA */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 5215 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 5216 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5217 | |
| 5218 | /* |
| 5219 | * codec_info_Object |
| 5220 | * Codec Info |
| 5221 | * !modified @ 071206 |
| 5222 | */ |
| 5223 | typedef struct |
| 5224 | { |
| 5225 | PyObject_HEAD |
| 5226 | /* Type-specific fields go here. */ |
| 5227 | |
| 5228 | PyObject * codec_id; |
| 5229 | pj_uint8_t priority; |
| 5230 | char buf_[32]; |
| 5231 | } codec_info_Object; |
| 5232 | |
| 5233 | |
| 5234 | /* |
| 5235 | * codec_info_dealloc |
| 5236 | * deletes a codec_info from memory |
| 5237 | * !modified @ 071206 |
| 5238 | */ |
| 5239 | static void codec_info_dealloc(codec_info_Object* self) |
| 5240 | { |
| 5241 | Py_XDECREF(self->codec_id); |
| 5242 | |
| 5243 | self->ob_type->tp_free((PyObject*)self); |
| 5244 | } |
| 5245 | |
| 5246 | |
| 5247 | /* |
| 5248 | * codec_info_new |
| 5249 | * constructor for codec_info object |
| 5250 | * !modified @ 071206 |
| 5251 | */ |
| 5252 | static PyObject * codec_info_new(PyTypeObject *type, PyObject *args, |
| 5253 | PyObject *kwds) |
| 5254 | { |
| 5255 | codec_info_Object *self; |
| 5256 | |
| 5257 | self = (codec_info_Object *)type->tp_alloc(type, 0); |
| 5258 | if (self != NULL) |
| 5259 | { |
| 5260 | self->codec_id = PyString_FromString(""); |
| 5261 | if (self->codec_id == NULL) |
| 5262 | { |
| 5263 | Py_DECREF(self); |
| 5264 | return NULL; |
| 5265 | } |
| 5266 | |
| 5267 | |
| 5268 | } |
| 5269 | return (PyObject *)self; |
| 5270 | } |
| 5271 | |
| 5272 | /* |
| 5273 | * codec_info_members |
| 5274 | * !modified @ 071206 |
| 5275 | */ |
| 5276 | static PyMemberDef codec_info_members[] = |
| 5277 | { |
| 5278 | { |
| 5279 | "codec_id", T_OBJECT_EX, |
| 5280 | offsetof(codec_info_Object, codec_id), 0, |
| 5281 | "Codec unique identification." |
| 5282 | }, |
| 5283 | |
| 5284 | { |
| 5285 | "priority", T_INT, |
| 5286 | offsetof(codec_info_Object, priority), 0, |
| 5287 | "Codec priority (integer 0-255)." |
| 5288 | }, |
| 5289 | |
| 5290 | |
| 5291 | |
| 5292 | {NULL} /* Sentinel */ |
| 5293 | }; |
| 5294 | |
| 5295 | |
| 5296 | |
| 5297 | |
| 5298 | /* |
| 5299 | * codec_info_Type |
| 5300 | */ |
| 5301 | static PyTypeObject codec_info_Type = |
| 5302 | { |
| 5303 | PyObject_HEAD_INIT(NULL) |
| 5304 | 0, /*ob_size*/ |
| 5305 | "py_pjsua.Codec_Info", /*tp_name*/ |
| 5306 | sizeof(codec_info_Object), /*tp_basicsize*/ |
| 5307 | 0, /*tp_itemsize*/ |
| 5308 | (destructor)codec_info_dealloc,/*tp_dealloc*/ |
| 5309 | 0, /*tp_print*/ |
| 5310 | 0, /*tp_getattr*/ |
| 5311 | 0, /*tp_setattr*/ |
| 5312 | 0, /*tp_compare*/ |
| 5313 | 0, /*tp_repr*/ |
| 5314 | 0, /*tp_as_number*/ |
| 5315 | 0, /*tp_as_sequence*/ |
| 5316 | 0, /*tp_as_mapping*/ |
| 5317 | 0, /*tp_hash */ |
| 5318 | 0, /*tp_call*/ |
| 5319 | 0, /*tp_str*/ |
| 5320 | 0, /*tp_getattro*/ |
| 5321 | 0, /*tp_setattro*/ |
| 5322 | 0, /*tp_as_buffer*/ |
| 5323 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5324 | "Codec Info objects", /* tp_doc */ |
| 5325 | 0, /* tp_traverse */ |
| 5326 | 0, /* tp_clear */ |
| 5327 | 0, /* tp_richcompare */ |
| 5328 | 0, /* tp_weaklistoffset */ |
| 5329 | 0, /* tp_iter */ |
| 5330 | 0, /* tp_iternext */ |
| 5331 | 0, /* tp_methods */ |
| 5332 | codec_info_members, /* tp_members */ |
| 5333 | 0, /* tp_getset */ |
| 5334 | 0, /* tp_base */ |
| 5335 | 0, /* tp_dict */ |
| 5336 | 0, /* tp_descr_get */ |
| 5337 | 0, /* tp_descr_set */ |
| 5338 | 0, /* tp_dictoffset */ |
| 5339 | 0, /* tp_init */ |
| 5340 | 0, /* tp_alloc */ |
| 5341 | codec_info_new, /* tp_new */ |
| 5342 | |
| 5343 | }; |
| 5344 | |
| 5345 | /* |
| 5346 | * conf_port_info_Object |
| 5347 | * Conf Port Info |
| 5348 | */ |
| 5349 | typedef struct |
| 5350 | { |
| 5351 | PyObject_HEAD |
| 5352 | /* Type-specific fields go here. */ |
| 5353 | |
| 5354 | int slot_id; |
| 5355 | PyObject * name; |
| 5356 | unsigned clock_rate; |
| 5357 | unsigned channel_count; |
| 5358 | unsigned samples_per_frame; |
| 5359 | unsigned bits_per_sample; |
| 5360 | unsigned listener_cnt; |
| 5361 | PyListObject * listeners; |
| 5362 | |
| 5363 | } conf_port_info_Object; |
| 5364 | |
| 5365 | |
| 5366 | /* |
| 5367 | * conf_port_info_dealloc |
| 5368 | * deletes a conf_port_info from memory |
| 5369 | */ |
| 5370 | static void conf_port_info_dealloc(conf_port_info_Object* self) |
| 5371 | { |
| 5372 | Py_XDECREF(self->name); |
| 5373 | Py_XDECREF(self->listeners); |
| 5374 | self->ob_type->tp_free((PyObject*)self); |
| 5375 | } |
| 5376 | |
| 5377 | |
| 5378 | /* |
| 5379 | * conf_port_info_new |
| 5380 | * constructor for conf_port_info object |
| 5381 | */ |
| 5382 | static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args, |
| 5383 | PyObject *kwds) |
| 5384 | { |
| 5385 | conf_port_info_Object *self; |
| 5386 | |
| 5387 | self = (conf_port_info_Object *)type->tp_alloc(type, 0); |
| 5388 | if (self != NULL) |
| 5389 | { |
| 5390 | self->name = PyString_FromString(""); |
| 5391 | if (self->name == NULL) |
| 5392 | { |
| 5393 | Py_DECREF(self); |
| 5394 | return NULL; |
| 5395 | } |
| 5396 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 5397 | self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5398 | if (self->listeners == NULL) |
| 5399 | { |
| 5400 | Py_DECREF(self); |
| 5401 | return NULL; |
| 5402 | } |
| 5403 | } |
| 5404 | return (PyObject *)self; |
| 5405 | } |
| 5406 | |
| 5407 | /* |
| 5408 | * conf_port_info_members |
| 5409 | */ |
| 5410 | static PyMemberDef conf_port_info_members[] = |
| 5411 | { |
| 5412 | { |
| 5413 | "slot_id", T_INT, |
| 5414 | offsetof(conf_port_info_Object, slot_id), 0, |
| 5415 | "Conference port number." |
| 5416 | }, |
| 5417 | { |
| 5418 | "name", T_OBJECT_EX, |
| 5419 | offsetof(conf_port_info_Object, name), 0, |
| 5420 | "Port name" |
| 5421 | }, |
| 5422 | { |
| 5423 | "clock_rate", T_INT, |
| 5424 | offsetof(conf_port_info_Object, clock_rate), 0, |
| 5425 | "Clock rate" |
| 5426 | }, |
| 5427 | { |
| 5428 | "channel_count", T_INT, |
| 5429 | offsetof(conf_port_info_Object, channel_count), 0, |
| 5430 | "Number of channels." |
| 5431 | }, |
| 5432 | { |
| 5433 | "samples_per_frame", T_INT, |
| 5434 | offsetof(conf_port_info_Object, samples_per_frame), 0, |
| 5435 | "Samples per frame " |
| 5436 | }, |
| 5437 | { |
| 5438 | "bits_per_sample", T_INT, |
| 5439 | offsetof(conf_port_info_Object, bits_per_sample), 0, |
| 5440 | "Bits per sample" |
| 5441 | }, |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 5442 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5443 | "listener_cnt", T_INT, |
| 5444 | offsetof(conf_port_info_Object, listener_cnt), 0, |
| 5445 | "Number of listeners in the array." |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 5446 | }, |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5447 | { |
| 5448 | "listeners", T_OBJECT_EX, |
| 5449 | offsetof(conf_port_info_Object, listeners), 0, |
| 5450 | "Array of listeners (in other words, ports where this port " |
| 5451 | "is transmitting to" |
| 5452 | }, |
| 5453 | |
| 5454 | {NULL} /* Sentinel */ |
| 5455 | }; |
| 5456 | |
| 5457 | |
| 5458 | |
| 5459 | |
| 5460 | /* |
| 5461 | * conf_port_info_Type |
| 5462 | */ |
| 5463 | static PyTypeObject conf_port_info_Type = |
| 5464 | { |
| 5465 | PyObject_HEAD_INIT(NULL) |
| 5466 | 0, /*ob_size*/ |
| 5467 | "py_pjsua.Conf_Port_Info", /*tp_name*/ |
| 5468 | sizeof(conf_port_info_Object), /*tp_basicsize*/ |
| 5469 | 0, /*tp_itemsize*/ |
| 5470 | (destructor)conf_port_info_dealloc,/*tp_dealloc*/ |
| 5471 | 0, /*tp_print*/ |
| 5472 | 0, /*tp_getattr*/ |
| 5473 | 0, /*tp_setattr*/ |
| 5474 | 0, /*tp_compare*/ |
| 5475 | 0, /*tp_repr*/ |
| 5476 | 0, /*tp_as_number*/ |
| 5477 | 0, /*tp_as_sequence*/ |
| 5478 | 0, /*tp_as_mapping*/ |
| 5479 | 0, /*tp_hash */ |
| 5480 | 0, /*tp_call*/ |
| 5481 | 0, /*tp_str*/ |
| 5482 | 0, /*tp_getattro*/ |
| 5483 | 0, /*tp_setattro*/ |
| 5484 | 0, /*tp_as_buffer*/ |
| 5485 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5486 | "Conf Port Info objects", /* tp_doc */ |
| 5487 | 0, /* tp_traverse */ |
| 5488 | 0, /* tp_clear */ |
| 5489 | 0, /* tp_richcompare */ |
| 5490 | 0, /* tp_weaklistoffset */ |
| 5491 | 0, /* tp_iter */ |
| 5492 | 0, /* tp_iternext */ |
| 5493 | 0, /* tp_methods */ |
| 5494 | conf_port_info_members, /* tp_members */ |
| 5495 | 0, /* tp_getset */ |
| 5496 | 0, /* tp_base */ |
| 5497 | 0, /* tp_dict */ |
| 5498 | 0, /* tp_descr_get */ |
| 5499 | 0, /* tp_descr_set */ |
| 5500 | 0, /* tp_dictoffset */ |
| 5501 | 0, /* tp_init */ |
| 5502 | 0, /* tp_alloc */ |
| 5503 | conf_port_info_new, /* tp_new */ |
| 5504 | |
| 5505 | }; |
| 5506 | |
| 5507 | /* |
| 5508 | * pjmedia_port_Object |
| 5509 | */ |
| 5510 | typedef struct |
| 5511 | { |
| 5512 | PyObject_HEAD |
| 5513 | /* Type-specific fields go here. */ |
| 5514 | pjmedia_port * port; |
| 5515 | } pjmedia_port_Object; |
| 5516 | |
| 5517 | |
| 5518 | /* |
| 5519 | * pjmedia_port_Type |
| 5520 | */ |
| 5521 | static PyTypeObject pjmedia_port_Type = |
| 5522 | { |
| 5523 | PyObject_HEAD_INIT(NULL) |
| 5524 | 0, /*ob_size*/ |
| 5525 | "py_pjsua.PJMedia_Port", /*tp_name*/ |
| 5526 | sizeof(pjmedia_port_Object), /*tp_basicsize*/ |
| 5527 | 0, /*tp_itemsize*/ |
| 5528 | 0, /*tp_dealloc*/ |
| 5529 | 0, /*tp_print*/ |
| 5530 | 0, /*tp_getattr*/ |
| 5531 | 0, /*tp_setattr*/ |
| 5532 | 0, /*tp_compare*/ |
| 5533 | 0, /*tp_repr*/ |
| 5534 | 0, /*tp_as_number*/ |
| 5535 | 0, /*tp_as_sequence*/ |
| 5536 | 0, /*tp_as_mapping*/ |
| 5537 | 0, /*tp_hash */ |
| 5538 | 0, /*tp_call*/ |
| 5539 | 0, /*tp_str*/ |
| 5540 | 0, /*tp_getattro*/ |
| 5541 | 0, /*tp_setattro*/ |
| 5542 | 0, /*tp_as_buffer*/ |
| 5543 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5544 | "pjmedia_port objects", /* tp_doc */ |
| 5545 | |
| 5546 | }; |
| 5547 | |
| 5548 | /* |
| 5549 | * pjmedia_snd_dev_info_Object |
| 5550 | * PJMedia Snd Dev Info |
| 5551 | */ |
| 5552 | typedef struct |
| 5553 | { |
| 5554 | PyObject_HEAD |
| 5555 | /* Type-specific fields go here. */ |
| 5556 | |
| 5557 | |
| 5558 | unsigned input_count; |
| 5559 | unsigned output_count; |
| 5560 | unsigned default_samples_per_sec; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5561 | PyObject * name; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5562 | |
| 5563 | } pjmedia_snd_dev_info_Object; |
| 5564 | |
| 5565 | |
| 5566 | /* |
| 5567 | * pjmedia_snd_dev_info_dealloc |
| 5568 | * deletes a pjmedia_snd_dev_info from memory |
| 5569 | */ |
| 5570 | static void pjmedia_snd_dev_info_dealloc(pjmedia_snd_dev_info_Object* self) |
| 5571 | { |
| 5572 | Py_XDECREF(self->name); |
| 5573 | self->ob_type->tp_free((PyObject*)self); |
| 5574 | } |
| 5575 | |
| 5576 | |
| 5577 | /* |
| 5578 | * pjmedia_snd_dev_info_new |
| 5579 | * constructor for pjmedia_snd_dev_info object |
| 5580 | */ |
| 5581 | static PyObject * pjmedia_snd_dev_info_new(PyTypeObject *type, PyObject *args, |
| 5582 | PyObject *kwds) |
| 5583 | { |
| 5584 | pjmedia_snd_dev_info_Object *self; |
| 5585 | |
| 5586 | self = (pjmedia_snd_dev_info_Object *)type->tp_alloc(type, 0); |
| 5587 | if (self != NULL) |
| 5588 | { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 5589 | self->name = PyString_FromString(""); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 5590 | if (self->name == NULL) |
| 5591 | { |
| 5592 | Py_DECREF(self); |
| 5593 | return NULL; |
| 5594 | } |
| 5595 | |
| 5596 | } |
| 5597 | return (PyObject *)self; |
| 5598 | } |
| 5599 | |
| 5600 | /* |
| 5601 | * pjmedia_snd_dev_info_members |
| 5602 | */ |
| 5603 | static PyMemberDef pjmedia_snd_dev_info_members[] = |
| 5604 | { |
| 5605 | |
| 5606 | { |
| 5607 | "name", T_OBJECT_EX, |
| 5608 | offsetof(pjmedia_snd_dev_info_Object, name), 0, |
| 5609 | "Device name" |
| 5610 | }, |
| 5611 | { |
| 5612 | "input_count", T_INT, |
| 5613 | offsetof(pjmedia_snd_dev_info_Object, input_count), 0, |
| 5614 | "Max number of input channels" |
| 5615 | }, |
| 5616 | { |
| 5617 | "output_count", T_INT, |
| 5618 | offsetof(pjmedia_snd_dev_info_Object, output_count), 0, |
| 5619 | "Max number of output channels" |
| 5620 | }, |
| 5621 | { |
| 5622 | "default_samples_per_sec", T_INT, |
| 5623 | offsetof(pjmedia_snd_dev_info_Object, default_samples_per_sec), 0, |
| 5624 | "Default sampling rate." |
| 5625 | }, |
| 5626 | |
| 5627 | |
| 5628 | {NULL} /* Sentinel */ |
| 5629 | }; |
| 5630 | |
| 5631 | |
| 5632 | |
| 5633 | |
| 5634 | /* |
| 5635 | * pjmedia_snd_dev_info_Type |
| 5636 | */ |
| 5637 | static PyTypeObject pjmedia_snd_dev_info_Type = |
| 5638 | { |
| 5639 | PyObject_HEAD_INIT(NULL) |
| 5640 | 0, /*ob_size*/ |
| 5641 | "py_pjsua.PJMedia_Snd_Dev_Info", /*tp_name*/ |
| 5642 | sizeof(pjmedia_snd_dev_info_Object), /*tp_basicsize*/ |
| 5643 | 0, /*tp_itemsize*/ |
| 5644 | (destructor)pjmedia_snd_dev_info_dealloc,/*tp_dealloc*/ |
| 5645 | 0, /*tp_print*/ |
| 5646 | 0, /*tp_getattr*/ |
| 5647 | 0, /*tp_setattr*/ |
| 5648 | 0, /*tp_compare*/ |
| 5649 | 0, /*tp_repr*/ |
| 5650 | 0, /*tp_as_number*/ |
| 5651 | 0, /*tp_as_sequence*/ |
| 5652 | 0, /*tp_as_mapping*/ |
| 5653 | 0, /*tp_hash */ |
| 5654 | 0, /*tp_call*/ |
| 5655 | 0, /*tp_str*/ |
| 5656 | 0, /*tp_getattro*/ |
| 5657 | 0, /*tp_setattro*/ |
| 5658 | 0, /*tp_as_buffer*/ |
| 5659 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5660 | "PJMedia Snd Dev Info objects", /* tp_doc */ |
| 5661 | 0, /* tp_traverse */ |
| 5662 | 0, /* tp_clear */ |
| 5663 | 0, /* tp_richcompare */ |
| 5664 | 0, /* tp_weaklistoffset */ |
| 5665 | 0, /* tp_iter */ |
| 5666 | 0, /* tp_iternext */ |
| 5667 | 0, /* tp_methods */ |
| 5668 | pjmedia_snd_dev_info_members, /* tp_members */ |
| 5669 | 0, /* tp_getset */ |
| 5670 | 0, /* tp_base */ |
| 5671 | 0, /* tp_dict */ |
| 5672 | 0, /* tp_descr_get */ |
| 5673 | 0, /* tp_descr_set */ |
| 5674 | 0, /* tp_dictoffset */ |
| 5675 | 0, /* tp_init */ |
| 5676 | 0, /* tp_alloc */ |
| 5677 | pjmedia_snd_dev_info_new, /* tp_new */ |
| 5678 | |
| 5679 | }; |
| 5680 | |
| 5681 | /* |
| 5682 | * pjmedia_codec_param_info_Object |
| 5683 | * PJMedia Codec Param Info |
| 5684 | */ |
| 5685 | typedef struct |
| 5686 | { |
| 5687 | PyObject_HEAD |
| 5688 | /* Type-specific fields go here. */ |
| 5689 | |
| 5690 | unsigned clock_rate; |
| 5691 | unsigned channel_cnt; |
| 5692 | pj_uint32_t avg_bps; |
| 5693 | pj_uint16_t frm_ptime; |
| 5694 | pj_uint8_t pcm_bits_per_sample; |
| 5695 | pj_uint8_t pt; |
| 5696 | |
| 5697 | } pjmedia_codec_param_info_Object; |
| 5698 | |
| 5699 | |
| 5700 | |
| 5701 | /* |
| 5702 | * pjmedia_codec_param_info_members |
| 5703 | */ |
| 5704 | static PyMemberDef pjmedia_codec_param_info_members[] = |
| 5705 | { |
| 5706 | |
| 5707 | { |
| 5708 | "clock_rate", T_INT, |
| 5709 | offsetof(pjmedia_codec_param_info_Object, clock_rate), 0, |
| 5710 | "Sampling rate in Hz" |
| 5711 | }, |
| 5712 | { |
| 5713 | "channel_cnt", T_INT, |
| 5714 | offsetof(pjmedia_codec_param_info_Object, channel_cnt), 0, |
| 5715 | "Channel count" |
| 5716 | }, |
| 5717 | { |
| 5718 | "avg_bps", T_INT, |
| 5719 | offsetof(pjmedia_codec_param_info_Object, avg_bps), 0, |
| 5720 | "Average bandwidth in bits/sec" |
| 5721 | }, |
| 5722 | { |
| 5723 | "frm_ptime", T_INT, |
| 5724 | offsetof(pjmedia_codec_param_info_Object, frm_ptime), 0, |
| 5725 | "Base frame ptime in msec." |
| 5726 | }, |
| 5727 | { |
| 5728 | "pcm_bits_per_sample", T_INT, |
| 5729 | offsetof(pjmedia_codec_param_info_Object, pcm_bits_per_sample), 0, |
| 5730 | "Bits/sample in the PCM side" |
| 5731 | }, |
| 5732 | { |
| 5733 | "pt", T_INT, |
| 5734 | offsetof(pjmedia_codec_param_info_Object, pt), 0, |
| 5735 | "Payload type" |
| 5736 | }, |
| 5737 | |
| 5738 | {NULL} /* Sentinel */ |
| 5739 | }; |
| 5740 | |
| 5741 | |
| 5742 | |
| 5743 | |
| 5744 | /* |
| 5745 | * pjmedia_codec_param_info_Type |
| 5746 | */ |
| 5747 | static PyTypeObject pjmedia_codec_param_info_Type = |
| 5748 | { |
| 5749 | PyObject_HEAD_INIT(NULL) |
| 5750 | 0, /*ob_size*/ |
| 5751 | "py_pjsua.PJMedia_Codec_Param_Info", /*tp_name*/ |
| 5752 | sizeof(pjmedia_codec_param_info_Object), /*tp_basicsize*/ |
| 5753 | 0, /*tp_itemsize*/ |
| 5754 | 0,/*tp_dealloc*/ |
| 5755 | 0, /*tp_print*/ |
| 5756 | 0, /*tp_getattr*/ |
| 5757 | 0, /*tp_setattr*/ |
| 5758 | 0, /*tp_compare*/ |
| 5759 | 0, /*tp_repr*/ |
| 5760 | 0, /*tp_as_number*/ |
| 5761 | 0, /*tp_as_sequence*/ |
| 5762 | 0, /*tp_as_mapping*/ |
| 5763 | 0, /*tp_hash */ |
| 5764 | 0, /*tp_call*/ |
| 5765 | 0, /*tp_str*/ |
| 5766 | 0, /*tp_getattro*/ |
| 5767 | 0, /*tp_setattro*/ |
| 5768 | 0, /*tp_as_buffer*/ |
| 5769 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5770 | "PJMedia Codec Param Info objects", /* tp_doc */ |
| 5771 | 0, /* tp_traverse */ |
| 5772 | 0, /* tp_clear */ |
| 5773 | 0, /* tp_richcompare */ |
| 5774 | 0, /* tp_weaklistoffset */ |
| 5775 | 0, /* tp_iter */ |
| 5776 | 0, /* tp_iternext */ |
| 5777 | 0, /* tp_methods */ |
| 5778 | pjmedia_codec_param_info_members, /* tp_members */ |
| 5779 | |
| 5780 | |
| 5781 | }; |
| 5782 | |
| 5783 | /* |
| 5784 | * pjmedia_codec_param_setting_Object |
| 5785 | * PJMedia Codec Param Setting |
| 5786 | */ |
| 5787 | typedef struct |
| 5788 | { |
| 5789 | PyObject_HEAD |
| 5790 | /* Type-specific fields go here. */ |
| 5791 | pj_uint8_t frm_per_pkt; |
| 5792 | unsigned vad; |
| 5793 | unsigned cng; |
| 5794 | unsigned penh; |
| 5795 | unsigned plc; |
| 5796 | unsigned reserved; |
| 5797 | pj_uint8_t enc_fmtp_mode; |
| 5798 | pj_uint8_t dec_fmtp_mode; |
| 5799 | |
| 5800 | } pjmedia_codec_param_setting_Object; |
| 5801 | |
| 5802 | |
| 5803 | |
| 5804 | /* |
| 5805 | * pjmedia_codec_param_setting_members |
| 5806 | */ |
| 5807 | static PyMemberDef pjmedia_codec_param_setting_members[] = |
| 5808 | { |
| 5809 | |
| 5810 | { |
| 5811 | "frm_per_pkt", T_INT, |
| 5812 | offsetof(pjmedia_codec_param_setting_Object, frm_per_pkt), 0, |
| 5813 | "Number of frames per packet" |
| 5814 | }, |
| 5815 | { |
| 5816 | "vad", T_INT, |
| 5817 | offsetof(pjmedia_codec_param_setting_Object, vad), 0, |
| 5818 | "Voice Activity Detector" |
| 5819 | }, |
| 5820 | { |
| 5821 | "penh", T_INT, |
| 5822 | offsetof(pjmedia_codec_param_setting_Object, penh), 0, |
| 5823 | "Perceptual Enhancement" |
| 5824 | }, |
| 5825 | { |
| 5826 | "plc", T_INT, |
| 5827 | offsetof(pjmedia_codec_param_setting_Object, plc), 0, |
| 5828 | "Packet loss concealment" |
| 5829 | }, |
| 5830 | { |
| 5831 | "reserved", T_INT, |
| 5832 | offsetof(pjmedia_codec_param_setting_Object, reserved), 0, |
| 5833 | "Reserved, must be zero" |
| 5834 | }, |
| 5835 | { |
| 5836 | "cng", T_INT, |
| 5837 | offsetof(pjmedia_codec_param_setting_Object, cng), 0, |
| 5838 | "Comfort Noise Generator" |
| 5839 | }, |
| 5840 | { |
| 5841 | "enc_fmtp_mode", T_INT, |
| 5842 | offsetof(pjmedia_codec_param_setting_Object, enc_fmtp_mode), 0, |
| 5843 | "Mode param in fmtp (def:0)" |
| 5844 | }, |
| 5845 | { |
| 5846 | "dec_fmtp_mode", T_INT, |
| 5847 | offsetof(pjmedia_codec_param_setting_Object, dec_fmtp_mode), 0, |
| 5848 | "Mode param in fmtp (def:0)" |
| 5849 | }, |
| 5850 | |
| 5851 | {NULL} /* Sentinel */ |
| 5852 | }; |
| 5853 | |
| 5854 | |
| 5855 | |
| 5856 | |
| 5857 | /* |
| 5858 | * pjmedia_codec_param_setting_Type |
| 5859 | */ |
| 5860 | static PyTypeObject pjmedia_codec_param_setting_Type = |
| 5861 | { |
| 5862 | PyObject_HEAD_INIT(NULL) |
| 5863 | 0, /*ob_size*/ |
| 5864 | "py_pjsua.PJMedia_Codec_Param_Setting", /*tp_name*/ |
| 5865 | sizeof(pjmedia_codec_param_setting_Object), /*tp_basicsize*/ |
| 5866 | 0, /*tp_itemsize*/ |
| 5867 | 0,/*tp_dealloc*/ |
| 5868 | 0, /*tp_print*/ |
| 5869 | 0, /*tp_getattr*/ |
| 5870 | 0, /*tp_setattr*/ |
| 5871 | 0, /*tp_compare*/ |
| 5872 | 0, /*tp_repr*/ |
| 5873 | 0, /*tp_as_number*/ |
| 5874 | 0, /*tp_as_sequence*/ |
| 5875 | 0, /*tp_as_mapping*/ |
| 5876 | 0, /*tp_hash */ |
| 5877 | 0, /*tp_call*/ |
| 5878 | 0, /*tp_str*/ |
| 5879 | 0, /*tp_getattro*/ |
| 5880 | 0, /*tp_setattro*/ |
| 5881 | 0, /*tp_as_buffer*/ |
| 5882 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 5883 | "PJMedia Codec Param Setting objects", /* tp_doc */ |
| 5884 | 0, /* tp_traverse */ |
| 5885 | 0, /* tp_clear */ |
| 5886 | 0, /* tp_richcompare */ |
| 5887 | 0, /* tp_weaklistoffset */ |
| 5888 | 0, /* tp_iter */ |
| 5889 | 0, /* tp_iternext */ |
| 5890 | 0, /* tp_methods */ |
| 5891 | pjmedia_codec_param_setting_members, /* tp_members */ |
| 5892 | |
| 5893 | |
| 5894 | }; |
| 5895 | |
| 5896 | /* |
| 5897 | * pjmedia_codec_param_Object |
| 5898 | * PJMedia Codec Param |
| 5899 | */ |
| 5900 | typedef struct |
| 5901 | { |
| 5902 | PyObject_HEAD |
| 5903 | /* Type-specific fields go here. */ |
| 5904 | |
| 5905 | pjmedia_codec_param_info_Object * info; |
| 5906 | pjmedia_codec_param_setting_Object * setting; |
| 5907 | |
| 5908 | } pjmedia_codec_param_Object; |
| 5909 | |
| 5910 | |
| 5911 | /* |
| 5912 | * pjmedia_codec_param_dealloc |
| 5913 | * deletes a pjmedia_codec_param from memory |
| 5914 | */ |
| 5915 | static void pjmedia_codec_param_dealloc(pjmedia_codec_param_Object* self) |
| 5916 | { |
| 5917 | Py_XDECREF(self->info); |
| 5918 | Py_XDECREF(self->setting); |
| 5919 | self->ob_type->tp_free((PyObject*)self); |
| 5920 | } |
| 5921 | |
| 5922 | |
| 5923 | /* |
| 5924 | * pjmedia_codec_param_new |
| 5925 | * constructor for pjmedia_codec_param object |
| 5926 | */ |
| 5927 | static PyObject * pjmedia_codec_param_new(PyTypeObject *type, PyObject *args, |
| 5928 | PyObject *kwds) |
| 5929 | { |
| 5930 | pjmedia_codec_param_Object *self; |
| 5931 | |
| 5932 | self = (pjmedia_codec_param_Object *)type->tp_alloc(type, 0); |
| 5933 | if (self != NULL) |
| 5934 | { |
| 5935 | self->info = (pjmedia_codec_param_info_Object *) |
| 5936 | PyType_GenericNew(&pjmedia_codec_param_info_Type, NULL, NULL); |
| 5937 | if (self->info == NULL) |
| 5938 | { |
| 5939 | Py_DECREF(self); |
| 5940 | return NULL; |
| 5941 | } |
| 5942 | self->setting = (pjmedia_codec_param_setting_Object *) |
| 5943 | PyType_GenericNew(&pjmedia_codec_param_setting_Type, NULL, NULL); |
| 5944 | if (self->setting == NULL) |
| 5945 | { |
| 5946 | Py_DECREF(self); |
| 5947 | return NULL; |
| 5948 | } |
| 5949 | } |
| 5950 | return (PyObject *)self; |
| 5951 | } |
| 5952 | |
| 5953 | /* |
| 5954 | * pjmedia_codec_param_members |
| 5955 | */ |
| 5956 | static PyMemberDef pjmedia_codec_param_members[] = |
| 5957 | { |
| 5958 | |
| 5959 | { |
| 5960 | "info", T_OBJECT_EX, |
| 5961 | offsetof(pjmedia_codec_param_Object, info), 0, |
| 5962 | "The 'info' part of codec param describes the capability of the codec," |
| 5963 | " and the value should NOT be changed by application." |
| 5964 | }, |
| 5965 | { |
| 5966 | "setting", T_OBJECT_EX, |
| 5967 | offsetof(pjmedia_codec_param_Object, setting), 0, |
| 5968 | "The 'setting' part of codec param describes various settings to be " |
| 5969 | "applied to the codec. When the codec param is retrieved from the " |
| 5970 | "codec or codec factory, the values of these will be filled by " |
| 5971 | "the capability of the codec. Any features that are supported by " |
| 5972 | "the codec (e.g. vad or plc) will be turned on, so that application " |
| 5973 | "can query which capabilities are supported by the codec. " |
| 5974 | "Application may change the settings here before instantiating " |
| 5975 | "the codec/stream." |
| 5976 | }, |
| 5977 | |
| 5978 | {NULL} /* Sentinel */ |
| 5979 | }; |
| 5980 | |
| 5981 | |
| 5982 | |
| 5983 | |
| 5984 | /* |
| 5985 | * pjmedia_codec_param_Type |
| 5986 | */ |
| 5987 | static PyTypeObject pjmedia_codec_param_Type = |
| 5988 | { |
| 5989 | PyObject_HEAD_INIT(NULL) |
| 5990 | 0, /*ob_size*/ |
| 5991 | "py_pjsua.PJMedia_Codec_Param", /*tp_name*/ |
| 5992 | sizeof(pjmedia_codec_param_Object), /*tp_basicsize*/ |
| 5993 | 0, /*tp_itemsize*/ |
| 5994 | (destructor)pjmedia_codec_param_dealloc,/*tp_dealloc*/ |
| 5995 | 0, /*tp_print*/ |
| 5996 | 0, /*tp_getattr*/ |
| 5997 | 0, /*tp_setattr*/ |
| 5998 | 0, /*tp_compare*/ |
| 5999 | 0, /*tp_repr*/ |
| 6000 | 0, /*tp_as_number*/ |
| 6001 | 0, /*tp_as_sequence*/ |
| 6002 | 0, /*tp_as_mapping*/ |
| 6003 | 0, /*tp_hash */ |
| 6004 | 0, /*tp_call*/ |
| 6005 | 0, /*tp_str*/ |
| 6006 | 0, /*tp_getattro*/ |
| 6007 | 0, /*tp_setattro*/ |
| 6008 | 0, /*tp_as_buffer*/ |
| 6009 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 6010 | "PJMedia Codec Param objects", /* tp_doc */ |
| 6011 | 0, /* tp_traverse */ |
| 6012 | 0, /* tp_clear */ |
| 6013 | 0, /* tp_richcompare */ |
| 6014 | 0, /* tp_weaklistoffset */ |
| 6015 | 0, /* tp_iter */ |
| 6016 | 0, /* tp_iternext */ |
| 6017 | 0, /* tp_methods */ |
| 6018 | pjmedia_codec_param_members, /* tp_members */ |
| 6019 | 0, /* tp_getset */ |
| 6020 | 0, /* tp_base */ |
| 6021 | 0, /* tp_dict */ |
| 6022 | 0, /* tp_descr_get */ |
| 6023 | 0, /* tp_descr_set */ |
| 6024 | 0, /* tp_dictoffset */ |
| 6025 | 0, /* tp_init */ |
| 6026 | 0, /* tp_alloc */ |
| 6027 | pjmedia_codec_param_new, /* tp_new */ |
| 6028 | |
| 6029 | }; |
| 6030 | |
| 6031 | /* |
| 6032 | * py_pjsua_conf_get_max_ports |
| 6033 | */ |
| 6034 | static PyObject *py_pjsua_conf_get_max_ports |
| 6035 | (PyObject *pSelf, PyObject *pArgs) |
| 6036 | { |
| 6037 | int ret; |
| 6038 | |
| 6039 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6040 | { |
| 6041 | return NULL; |
| 6042 | } |
| 6043 | ret = pjsua_conf_get_max_ports(); |
| 6044 | |
| 6045 | return Py_BuildValue("i", ret); |
| 6046 | } |
| 6047 | |
| 6048 | /* |
| 6049 | * py_pjsua_conf_get_active_ports |
| 6050 | */ |
| 6051 | static PyObject *py_pjsua_conf_get_active_ports |
| 6052 | (PyObject *pSelf, PyObject *pArgs) |
| 6053 | { |
| 6054 | int ret; |
| 6055 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6056 | { |
| 6057 | return NULL; |
| 6058 | } |
| 6059 | ret = pjsua_conf_get_active_ports(); |
| 6060 | |
| 6061 | return Py_BuildValue("i", ret); |
| 6062 | } |
| 6063 | |
| 6064 | /* |
| 6065 | * py_pjsua_enum_conf_ports |
| 6066 | * !modified @ 241206 |
| 6067 | */ |
| 6068 | static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs) |
| 6069 | { |
| 6070 | pj_status_t status; |
| 6071 | PyObject *list; |
| 6072 | |
| 6073 | pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6074 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6075 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6076 | { |
| 6077 | return NULL; |
| 6078 | } |
| 6079 | |
| 6080 | c = PJ_ARRAY_SIZE(id); |
| 6081 | status = pjsua_enum_conf_ports(id, &c); |
| 6082 | |
| 6083 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6084 | for (i = 0; i < c; i++) |
| 6085 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6086 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6087 | if (ret == -1) |
| 6088 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6089 | return NULL; |
| 6090 | } |
| 6091 | } |
| 6092 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6093 | return Py_BuildValue("O",list); |
| 6094 | } |
| 6095 | |
| 6096 | /* |
| 6097 | * py_pjsua_conf_get_port_info |
| 6098 | */ |
| 6099 | static PyObject *py_pjsua_conf_get_port_info |
| 6100 | (PyObject *pSelf, PyObject *pArgs) |
| 6101 | { |
| 6102 | int id; |
| 6103 | conf_port_info_Object * obj; |
| 6104 | pjsua_conf_port_info info; |
| 6105 | int status; |
| 6106 | int i; |
| 6107 | |
| 6108 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6109 | { |
| 6110 | return NULL; |
| 6111 | } |
| 6112 | |
| 6113 | |
| 6114 | status = pjsua_conf_get_port_info(id, &info); |
| 6115 | obj = (conf_port_info_Object *)conf_port_info_new |
| 6116 | (&conf_port_info_Type,NULL,NULL); |
| 6117 | obj->bits_per_sample = info.bits_per_sample; |
| 6118 | obj->channel_count = info.bits_per_sample; |
| 6119 | obj->clock_rate = info.clock_rate; |
| 6120 | obj->listener_cnt = info.listener_cnt; |
| 6121 | obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen); |
| 6122 | obj->samples_per_frame = info.samples_per_frame; |
| 6123 | obj->slot_id = info.slot_id; |
| 6124 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6125 | for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6126 | PyObject * item = Py_BuildValue("i",info.listeners[i]); |
| 6127 | PyList_SetItem((PyObject *)obj->listeners, i, item); |
| 6128 | } |
| 6129 | return Py_BuildValue("O", obj); |
| 6130 | } |
| 6131 | |
| 6132 | /* |
| 6133 | * py_pjsua_conf_add_port |
| 6134 | */ |
| 6135 | static PyObject *py_pjsua_conf_add_port |
| 6136 | (PyObject *pSelf, PyObject *pArgs) |
| 6137 | { |
| 6138 | int p_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6139 | PyObject * oportObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6140 | pjmedia_port_Object * oport; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6141 | pjmedia_port * port; |
| 6142 | PyObject * opoolObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6143 | pj_pool_Object * opool; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6144 | pj_pool_t * pool; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6145 | |
| 6146 | int status; |
| 6147 | |
| 6148 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6149 | if (!PyArg_ParseTuple(pArgs, "OO", &opoolObj, &oportObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6150 | { |
| 6151 | return NULL; |
| 6152 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6153 | if (opoolObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6154 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6155 | opool = (pj_pool_Object *)opoolObj; |
| 6156 | pool = opool->pool; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6157 | } else { |
| 6158 | opool = NULL; |
| 6159 | pool = NULL; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6160 | } |
| 6161 | if (oportObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6162 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6163 | oport = (pjmedia_port_Object *)oportObj; |
| 6164 | port = oport->port; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6165 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6166 | oport = NULL; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6167 | port = NULL; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6168 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6169 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6170 | status = pjsua_conf_add_port(pool, port, &p_id); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6171 | |
| 6172 | |
| 6173 | return Py_BuildValue("ii", status, p_id); |
| 6174 | } |
| 6175 | |
| 6176 | /* |
| 6177 | * py_pjsua_conf_remove_port |
| 6178 | */ |
| 6179 | static PyObject *py_pjsua_conf_remove_port |
| 6180 | (PyObject *pSelf, PyObject *pArgs) |
| 6181 | { |
| 6182 | int id; |
| 6183 | int status; |
| 6184 | |
| 6185 | |
| 6186 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6187 | { |
| 6188 | return NULL; |
| 6189 | } |
| 6190 | |
| 6191 | status = pjsua_conf_remove_port(id); |
| 6192 | |
| 6193 | |
| 6194 | return Py_BuildValue("i", status); |
| 6195 | } |
| 6196 | |
| 6197 | /* |
| 6198 | * py_pjsua_conf_connect |
| 6199 | */ |
| 6200 | static PyObject *py_pjsua_conf_connect |
| 6201 | (PyObject *pSelf, PyObject *pArgs) |
| 6202 | { |
| 6203 | int source, sink; |
| 6204 | int status; |
| 6205 | |
| 6206 | |
| 6207 | if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) |
| 6208 | { |
| 6209 | return NULL; |
| 6210 | } |
| 6211 | |
| 6212 | status = pjsua_conf_connect(source, sink); |
| 6213 | |
| 6214 | |
| 6215 | return Py_BuildValue("i", status); |
| 6216 | } |
| 6217 | |
| 6218 | /* |
| 6219 | * py_pjsua_conf_disconnect |
| 6220 | */ |
| 6221 | static PyObject *py_pjsua_conf_disconnect |
| 6222 | (PyObject *pSelf, PyObject *pArgs) |
| 6223 | { |
| 6224 | int source, sink; |
| 6225 | int status; |
| 6226 | |
| 6227 | |
| 6228 | if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) |
| 6229 | { |
| 6230 | return NULL; |
| 6231 | } |
| 6232 | |
| 6233 | status = pjsua_conf_disconnect(source, sink); |
| 6234 | |
| 6235 | |
| 6236 | return Py_BuildValue("i", status); |
| 6237 | } |
| 6238 | |
| 6239 | /* |
| 6240 | * py_pjsua_player_create |
| 6241 | */ |
| 6242 | static PyObject *py_pjsua_player_create |
| 6243 | (PyObject *pSelf, PyObject *pArgs) |
| 6244 | { |
| 6245 | int id; |
| 6246 | int options; |
| 6247 | PyObject * filename; |
| 6248 | pj_str_t str; |
| 6249 | int status; |
| 6250 | |
| 6251 | |
| 6252 | if (!PyArg_ParseTuple(pArgs, "Oi", &filename, &options)) |
| 6253 | { |
| 6254 | return NULL; |
| 6255 | } |
| 6256 | str.ptr = PyString_AsString(filename); |
| 6257 | str.slen = strlen(PyString_AsString(filename)); |
| 6258 | status = pjsua_player_create(&str, options, &id); |
| 6259 | |
| 6260 | return Py_BuildValue("ii", status, id); |
| 6261 | } |
| 6262 | |
| 6263 | /* |
| 6264 | * py_pjsua_player_get_conf_port |
| 6265 | */ |
| 6266 | static PyObject *py_pjsua_player_get_conf_port |
| 6267 | (PyObject *pSelf, PyObject *pArgs) |
| 6268 | { |
| 6269 | |
| 6270 | int id, port_id; |
| 6271 | |
| 6272 | |
| 6273 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6274 | { |
| 6275 | return NULL; |
| 6276 | } |
| 6277 | |
| 6278 | port_id = pjsua_player_get_conf_port(id); |
| 6279 | |
| 6280 | |
| 6281 | return Py_BuildValue("i", port_id); |
| 6282 | } |
| 6283 | |
| 6284 | /* |
| 6285 | * py_pjsua_player_set_pos |
| 6286 | */ |
| 6287 | static PyObject *py_pjsua_player_set_pos |
| 6288 | (PyObject *pSelf, PyObject *pArgs) |
| 6289 | { |
| 6290 | int id; |
| 6291 | pj_uint32_t samples; |
| 6292 | int status; |
| 6293 | |
| 6294 | |
| 6295 | if (!PyArg_ParseTuple(pArgs, "iI", &id, &samples)) |
| 6296 | { |
| 6297 | return NULL; |
| 6298 | } |
| 6299 | |
| 6300 | status = pjsua_player_set_pos(id, samples); |
| 6301 | |
| 6302 | |
| 6303 | return Py_BuildValue("i", status); |
| 6304 | } |
| 6305 | |
| 6306 | /* |
| 6307 | * py_pjsua_player_destroy |
| 6308 | */ |
| 6309 | static PyObject *py_pjsua_player_destroy |
| 6310 | (PyObject *pSelf, PyObject *pArgs) |
| 6311 | { |
| 6312 | int id; |
| 6313 | int status; |
| 6314 | |
| 6315 | |
| 6316 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6317 | { |
| 6318 | return NULL; |
| 6319 | } |
| 6320 | |
| 6321 | status = pjsua_player_destroy(id); |
| 6322 | |
| 6323 | |
| 6324 | return Py_BuildValue("i", status); |
| 6325 | } |
| 6326 | |
| 6327 | /* |
| 6328 | * py_pjsua_recorder_create |
| 6329 | * !modified @ 261206 |
| 6330 | */ |
| 6331 | static PyObject *py_pjsua_recorder_create |
| 6332 | (PyObject *pSelf, PyObject *pArgs) |
| 6333 | { |
| 6334 | int p_id; |
| 6335 | int options; |
| 6336 | int max_size; |
| 6337 | PyObject * filename; |
| 6338 | pj_str_t str; |
| 6339 | PyObject * enc_param; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6340 | pj_str_t strparam; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6341 | int enc_type; |
| 6342 | |
| 6343 | int status; |
| 6344 | |
| 6345 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6346 | if (!PyArg_ParseTuple(pArgs, "OiOii", &filename, |
| 6347 | &enc_type, &enc_param, &max_size, &options)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6348 | { |
| 6349 | return NULL; |
| 6350 | } |
| 6351 | str.ptr = PyString_AsString(filename); |
| 6352 | str.slen = strlen(PyString_AsString(filename)); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 6353 | if (enc_param != Py_None) |
| 6354 | { |
| 6355 | strparam.ptr = PyString_AsString(enc_param); |
| 6356 | strparam.slen = strlen(PyString_AsString(enc_param)); |
| 6357 | status = pjsua_recorder_create |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6358 | (&str, enc_type, NULL, max_size, options, &p_id); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 6359 | } else { |
| 6360 | status = pjsua_recorder_create |
| 6361 | (&str, enc_type, NULL, max_size, options, &p_id); |
| 6362 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6363 | return Py_BuildValue("ii", status, p_id); |
| 6364 | } |
| 6365 | |
| 6366 | /* |
| 6367 | * py_pjsua_recorder_get_conf_port |
| 6368 | */ |
| 6369 | static PyObject *py_pjsua_recorder_get_conf_port |
| 6370 | (PyObject *pSelf, PyObject *pArgs) |
| 6371 | { |
| 6372 | |
| 6373 | int id, port_id; |
| 6374 | |
| 6375 | |
| 6376 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6377 | { |
| 6378 | return NULL; |
| 6379 | } |
| 6380 | |
| 6381 | port_id = pjsua_recorder_get_conf_port(id); |
| 6382 | |
| 6383 | |
| 6384 | return Py_BuildValue("i", port_id); |
| 6385 | } |
| 6386 | |
| 6387 | /* |
| 6388 | * py_pjsua_recorder_destroy |
| 6389 | */ |
| 6390 | static PyObject *py_pjsua_recorder_destroy |
| 6391 | (PyObject *pSelf, PyObject *pArgs) |
| 6392 | { |
| 6393 | int id; |
| 6394 | int status; |
| 6395 | |
| 6396 | |
| 6397 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 6398 | { |
| 6399 | return NULL; |
| 6400 | } |
| 6401 | |
| 6402 | status = pjsua_recorder_destroy(id); |
| 6403 | |
| 6404 | |
| 6405 | return Py_BuildValue("i", status); |
| 6406 | } |
| 6407 | |
| 6408 | /* |
| 6409 | * py_pjsua_enum_snd_devs |
| 6410 | */ |
| 6411 | static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs) |
| 6412 | { |
| 6413 | pj_status_t status; |
| 6414 | PyObject *list; |
| 6415 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6416 | pjmedia_snd_dev_info info[SND_DEV_NUM]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6417 | unsigned c, i; |
Fahris | b721aa3 | 2007-01-29 05:07:41 +0000 | [diff] [blame] | 6418 | if (!PyArg_ParseTuple(pArgs, "")) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6419 | { |
| 6420 | return NULL; |
| 6421 | } |
| 6422 | |
Fahris | b721aa3 | 2007-01-29 05:07:41 +0000 | [diff] [blame] | 6423 | c = PJ_ARRAY_SIZE(info); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6424 | status = pjsua_enum_snd_devs(info, &c); |
| 6425 | |
| 6426 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6427 | for (i = 0; i < c; i++) |
| 6428 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6429 | int ret; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6430 | int j; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 6431 | char * str; |
| 6432 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6433 | pjmedia_snd_dev_info_Object * obj; |
| 6434 | obj = (pjmedia_snd_dev_info_Object *)pjmedia_snd_dev_info_new |
| 6435 | (&pjmedia_snd_dev_info_Type, NULL, NULL); |
| 6436 | obj->default_samples_per_sec = info[i].default_samples_per_sec; |
| 6437 | obj->input_count = info[i].input_count; |
| 6438 | obj->output_count = info[i].output_count; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 6439 | str = (char *)malloc(SND_NAME_LEN * sizeof(char)); |
| 6440 | memset(str, 0, SND_NAME_LEN); |
| 6441 | for (j = 0; j < SND_NAME_LEN; j++) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6442 | { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 6443 | str[j] = info[i].name[j]; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6444 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 6445 | obj->name = PyString_FromStringAndSize(str, SND_NAME_LEN); |
| 6446 | free(str); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6447 | ret = PyList_SetItem(list, i, (PyObject *)obj); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6448 | if (ret == -1) |
| 6449 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6450 | return NULL; |
| 6451 | } |
| 6452 | } |
| 6453 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6454 | return Py_BuildValue("O",list); |
| 6455 | } |
| 6456 | |
| 6457 | /* |
| 6458 | * py_pjsua_get_snd_dev |
| 6459 | */ |
| 6460 | static PyObject *py_pjsua_get_snd_dev |
| 6461 | (PyObject *pSelf, PyObject *pArgs) |
| 6462 | { |
| 6463 | int capture_dev, playback_dev; |
| 6464 | int status; |
| 6465 | |
| 6466 | |
| 6467 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6468 | { |
| 6469 | return NULL; |
| 6470 | } |
| 6471 | |
| 6472 | status = pjsua_get_snd_dev(&capture_dev, &playback_dev); |
| 6473 | |
| 6474 | |
| 6475 | return Py_BuildValue("ii", capture_dev, playback_dev); |
| 6476 | } |
| 6477 | |
| 6478 | /* |
| 6479 | * py_pjsua_set_snd_dev |
| 6480 | */ |
| 6481 | static PyObject *py_pjsua_set_snd_dev |
| 6482 | (PyObject *pSelf, PyObject *pArgs) |
| 6483 | { |
| 6484 | int capture_dev, playback_dev; |
| 6485 | int status; |
| 6486 | |
| 6487 | |
| 6488 | if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) |
| 6489 | { |
| 6490 | return NULL; |
| 6491 | } |
| 6492 | |
| 6493 | status = pjsua_set_snd_dev(capture_dev, playback_dev); |
| 6494 | |
| 6495 | |
| 6496 | return Py_BuildValue("i", status); |
| 6497 | } |
| 6498 | |
| 6499 | /* |
| 6500 | * py_pjsua_set_null_snd_dev |
| 6501 | */ |
| 6502 | static PyObject *py_pjsua_set_null_snd_dev |
| 6503 | (PyObject *pSelf, PyObject *pArgs) |
| 6504 | { |
| 6505 | |
| 6506 | int status; |
| 6507 | |
| 6508 | |
| 6509 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6510 | { |
| 6511 | return NULL; |
| 6512 | } |
| 6513 | |
| 6514 | status = pjsua_set_null_snd_dev(); |
| 6515 | |
| 6516 | |
| 6517 | return Py_BuildValue("i", status); |
| 6518 | } |
| 6519 | |
| 6520 | /* |
| 6521 | * py_pjsua_set_no_snd_dev |
| 6522 | */ |
| 6523 | static PyObject *py_pjsua_set_no_snd_dev |
| 6524 | (PyObject *pSelf, PyObject *pArgs) |
| 6525 | { |
| 6526 | |
| 6527 | pjmedia_port_Object * obj; |
| 6528 | |
| 6529 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6530 | { |
| 6531 | return NULL; |
| 6532 | } |
| 6533 | |
| 6534 | obj = (pjmedia_port_Object *)PyType_GenericNew |
| 6535 | (&pjmedia_port_Type, NULL, NULL); |
| 6536 | obj->port = pjsua_set_no_snd_dev(); |
| 6537 | return Py_BuildValue("O", obj); |
| 6538 | } |
| 6539 | |
| 6540 | /* |
| 6541 | * py_pjsua_set_ec |
| 6542 | */ |
| 6543 | static PyObject *py_pjsua_set_ec |
| 6544 | (PyObject *pSelf, PyObject *pArgs) |
| 6545 | { |
| 6546 | int options; |
| 6547 | int tail_ms; |
| 6548 | int status; |
| 6549 | |
| 6550 | |
| 6551 | if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) |
| 6552 | { |
| 6553 | return NULL; |
| 6554 | } |
| 6555 | |
| 6556 | status = pjsua_set_ec(tail_ms, options); |
| 6557 | |
| 6558 | |
| 6559 | return Py_BuildValue("i", status); |
| 6560 | } |
| 6561 | |
| 6562 | /* |
| 6563 | * py_pjsua_get_ec_tail |
| 6564 | */ |
| 6565 | static PyObject *py_pjsua_get_ec_tail |
| 6566 | (PyObject *pSelf, PyObject *pArgs) |
| 6567 | { |
| 6568 | |
| 6569 | int status; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6570 | unsigned p_tail_ms; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6571 | |
| 6572 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6573 | { |
| 6574 | return NULL; |
| 6575 | } |
| 6576 | |
| 6577 | status = pjsua_get_ec_tail(&p_tail_ms); |
| 6578 | |
| 6579 | |
| 6580 | return Py_BuildValue("i", p_tail_ms); |
| 6581 | } |
| 6582 | |
| 6583 | /* |
| 6584 | * py_pjsua_enum_codecs |
| 6585 | * !modified @ 261206 |
| 6586 | */ |
| 6587 | static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs) |
| 6588 | { |
| 6589 | pj_status_t status; |
| 6590 | PyObject *list; |
| 6591 | |
| 6592 | pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6593 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6594 | if (!PyArg_ParseTuple(pArgs, "")) |
| 6595 | { |
| 6596 | return NULL; |
| 6597 | } |
| 6598 | |
| 6599 | c = PJ_ARRAY_SIZE(info); |
| 6600 | status = pjsua_enum_codecs(info, &c); |
| 6601 | |
| 6602 | list = PyList_New(c); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6603 | for (i = 0; i < c; i++) |
| 6604 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6605 | int ret; |
| 6606 | int j; |
| 6607 | codec_info_Object * obj; |
| 6608 | obj = (codec_info_Object *)codec_info_new |
| 6609 | (&codec_info_Type, NULL, NULL); |
| 6610 | obj->codec_id = PyString_FromStringAndSize |
| 6611 | (info[i].codec_id.ptr, info[i].codec_id.slen); |
| 6612 | obj->priority = info[i].priority; |
| 6613 | for (j = 0; j < 32; j++) |
| 6614 | { |
| 6615 | obj->buf_[j] = info[i].buf_[j]; |
| 6616 | } |
| 6617 | ret = PyList_SetItem(list, i, (PyObject *)obj); |
| 6618 | if (ret == -1) { |
| 6619 | return NULL; |
| 6620 | } |
| 6621 | } |
| 6622 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6623 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6624 | return Py_BuildValue("O",list); |
| 6625 | } |
| 6626 | |
| 6627 | /* |
| 6628 | * py_pjsua_codec_set_priority |
| 6629 | */ |
| 6630 | static PyObject *py_pjsua_codec_set_priority |
| 6631 | (PyObject *pSelf, PyObject *pArgs) |
| 6632 | { |
| 6633 | |
| 6634 | int status; |
| 6635 | PyObject * id; |
| 6636 | pj_str_t str; |
| 6637 | pj_uint8_t priority; |
| 6638 | |
| 6639 | if (!PyArg_ParseTuple(pArgs, "OB", &id, &priority)) |
| 6640 | { |
| 6641 | return NULL; |
| 6642 | } |
| 6643 | str.ptr = PyString_AsString(id); |
| 6644 | str.slen = strlen(PyString_AsString(id)); |
| 6645 | status = pjsua_codec_set_priority(&str, priority); |
| 6646 | |
| 6647 | |
| 6648 | return Py_BuildValue("i", status); |
| 6649 | } |
| 6650 | |
| 6651 | /* |
| 6652 | * py_pjsua_codec_get_param |
| 6653 | */ |
| 6654 | static PyObject *py_pjsua_codec_get_param |
| 6655 | (PyObject *pSelf, PyObject *pArgs) |
| 6656 | { |
| 6657 | |
| 6658 | int status; |
| 6659 | PyObject * id; |
| 6660 | pj_str_t str; |
| 6661 | pjmedia_codec_param param; |
| 6662 | pjmedia_codec_param_Object *obj; |
| 6663 | |
| 6664 | |
| 6665 | if (!PyArg_ParseTuple(pArgs, "O", &id)) |
| 6666 | { |
| 6667 | return NULL; |
| 6668 | } |
| 6669 | str.ptr = PyString_AsString(id); |
| 6670 | str.slen = strlen(PyString_AsString(id)); |
| 6671 | status = pjsua_codec_get_param(&str, ¶m); |
| 6672 | obj = (pjmedia_codec_param_Object *)pjmedia_codec_param_new |
| 6673 | (&pjmedia_codec_param_Type, NULL, NULL); |
| 6674 | obj->info->avg_bps = param.info.avg_bps; |
| 6675 | obj->info->channel_cnt = param.info.channel_cnt; |
| 6676 | obj->info->clock_rate = param.info.clock_rate; |
| 6677 | obj->info->frm_ptime = param.info.frm_ptime; |
| 6678 | obj->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample; |
| 6679 | obj->info->pt = param.info.pt; |
| 6680 | obj->setting->cng = param.setting.cng; |
| 6681 | obj->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode; |
| 6682 | obj->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode; |
| 6683 | obj->setting->frm_per_pkt = param.setting.frm_per_pkt; |
| 6684 | obj->setting->penh = param.setting.penh; |
| 6685 | obj->setting->plc = param.setting.plc; |
| 6686 | obj->setting->reserved = param.setting.reserved; |
| 6687 | obj->setting->vad = param.setting.vad; |
| 6688 | |
| 6689 | return Py_BuildValue("O", obj); |
| 6690 | } |
| 6691 | /* |
| 6692 | * py_pjsua_codec_set_param |
| 6693 | */ |
| 6694 | static PyObject *py_pjsua_codec_set_param |
| 6695 | (PyObject *pSelf, PyObject *pArgs) |
| 6696 | { |
| 6697 | |
| 6698 | int status; |
| 6699 | PyObject * id; |
| 6700 | pj_str_t str; |
| 6701 | pjmedia_codec_param param; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6702 | PyObject * tmpObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6703 | pjmedia_codec_param_Object *obj; |
| 6704 | |
| 6705 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6706 | if (!PyArg_ParseTuple(pArgs, "OO", &id, &tmpObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6707 | { |
| 6708 | return NULL; |
| 6709 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6710 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6711 | str.ptr = PyString_AsString(id); |
| 6712 | str.slen = strlen(PyString_AsString(id)); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6713 | if (tmpObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6714 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 6715 | obj = (pjmedia_codec_param_Object *)tmpObj; |
| 6716 | param.info.avg_bps = obj->info->avg_bps; |
| 6717 | param.info.channel_cnt = obj->info->channel_cnt; |
| 6718 | param.info.clock_rate = obj->info->clock_rate; |
| 6719 | param.info.frm_ptime = obj->info->frm_ptime; |
| 6720 | param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample; |
| 6721 | param.info.pt = obj->info->pt; |
| 6722 | param.setting.cng = obj->setting->cng; |
| 6723 | param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode; |
| 6724 | param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode; |
| 6725 | param.setting.frm_per_pkt = obj->setting->frm_per_pkt; |
| 6726 | param.setting.penh = obj->setting->penh; |
| 6727 | param.setting.plc = obj->setting->plc; |
| 6728 | param.setting.reserved = obj->setting->reserved; |
| 6729 | param.setting.vad = obj->setting->vad; |
| 6730 | status = pjsua_codec_set_param(&str, ¶m); |
| 6731 | } else { |
| 6732 | status = pjsua_codec_set_param(&str, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 6733 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 6734 | return Py_BuildValue("i", status); |
| 6735 | } |
| 6736 | |
| 6737 | static char pjsua_conf_get_max_ports_doc[] = |
| 6738 | "int py_pjsua.conf_get_max_ports () " |
| 6739 | "Get maxinum number of conference ports."; |
| 6740 | static char pjsua_conf_get_active_ports_doc[] = |
| 6741 | "int py_pjsua.conf_get_active_ports () " |
| 6742 | "Get current number of active ports in the bridge."; |
| 6743 | static char pjsua_enum_conf_ports_doc[] = |
| 6744 | "int[] py_pjsua.enum_conf_ports () " |
| 6745 | "Enumerate all conference ports."; |
| 6746 | static char pjsua_conf_get_port_info_doc[] = |
| 6747 | "py_pjsua.Conf_Port_Info py_pjsua.conf_get_port_info (int id) " |
| 6748 | "Get information about the specified conference port"; |
| 6749 | static char pjsua_conf_add_port_doc[] = |
| 6750 | "int, int py_pjsua.conf_add_port " |
| 6751 | "(py_pjsua.PJ_Pool pool, py_pjsua.PJMedia_Port port) " |
| 6752 | "Add arbitrary media port to PJSUA's conference bridge. " |
| 6753 | "Application can use this function to add the media port " |
| 6754 | "that it creates. For media ports that are created by PJSUA-LIB " |
| 6755 | "(such as calls, file player, or file recorder), PJSUA-LIB will " |
| 6756 | "automatically add the port to the bridge."; |
| 6757 | static char pjsua_conf_remove_port_doc[] = |
| 6758 | "int py_pjsua.conf_remove_port (int id) " |
| 6759 | "Remove arbitrary slot from the conference bridge. " |
| 6760 | "Application should only call this function " |
| 6761 | "if it registered the port manually."; |
| 6762 | static char pjsua_conf_connect_doc[] = |
| 6763 | "int py_pjsua.conf_connect (int source, int sink) " |
| 6764 | "Establish unidirectional media flow from souce to sink. " |
| 6765 | "One source may transmit to multiple destinations/sink. " |
| 6766 | "And if multiple sources are transmitting to the same sink, " |
| 6767 | "the media will be mixed together. Source and sink may refer " |
| 6768 | "to the same ID, effectively looping the media. " |
| 6769 | "If bidirectional media flow is desired, application " |
| 6770 | "needs to call this function twice, with the second " |
| 6771 | "one having the arguments reversed."; |
| 6772 | static char pjsua_conf_disconnect_doc[] = |
| 6773 | "int py_pjsua.conf_disconnect (int source, int sink) " |
| 6774 | "Disconnect media flow from the source to destination port."; |
| 6775 | static char pjsua_player_create_doc[] = |
| 6776 | "int, int py_pjsua.player_create (string filename, int options) " |
| 6777 | "Create a file player, and automatically connect " |
| 6778 | "this player to the conference bridge."; |
| 6779 | static char pjsua_player_get_conf_port_doc[] = |
| 6780 | "int py_pjsua.player_get_conf_port (int) " |
| 6781 | "Get conference port ID associated with player."; |
| 6782 | static char pjsua_player_set_pos_doc[] = |
| 6783 | "int py_pjsua.player_set_pos (int id, int samples) " |
| 6784 | "Set playback position."; |
| 6785 | static char pjsua_player_destroy_doc[] = |
| 6786 | "int py_pjsua.player_destroy (int id) " |
| 6787 | "Close the file, remove the player from the bridge, " |
| 6788 | "and free resources associated with the file player."; |
| 6789 | static char pjsua_recorder_create_doc[] = |
| 6790 | "int, int py_pjsua.recorder_create (string filename, " |
| 6791 | "int enc_type, int enc_param, int max_size, int options) " |
| 6792 | "Create a file recorder, and automatically connect this recorder " |
| 6793 | "to the conference bridge. The recorder currently supports recording " |
| 6794 | "WAV file, and on Windows, MP3 file. The type of the recorder to use " |
| 6795 | "is determined by the extension of the file (e.g. '.wav' or '.mp3')."; |
| 6796 | static char pjsua_recorder_get_conf_port_doc[] = |
| 6797 | "int py_pjsua.recorder_get_conf_port (int id) " |
| 6798 | "Get conference port associated with recorder."; |
| 6799 | static char pjsua_recorder_destroy_doc[] = |
| 6800 | "int py_pjsua.recorder_destroy (int id) " |
| 6801 | "Destroy recorder (this will complete recording)."; |
| 6802 | static char pjsua_enum_snd_devs_doc[] = |
| 6803 | "py_pjsua.PJMedia_Snd_Dev_Info[] py_pjsua.enum_snd_devs (int count) " |
| 6804 | "Enum sound devices."; |
| 6805 | static char pjsua_get_snd_dev_doc[] = |
| 6806 | "int, int py_pjsua.get_snd_dev () " |
| 6807 | "Get currently active sound devices. " |
| 6808 | "If sound devices has not been created " |
| 6809 | "(for example when pjsua_start() is not called), " |
| 6810 | "it is possible that the function returns " |
| 6811 | "PJ_SUCCESS with -1 as device IDs."; |
| 6812 | static char pjsua_set_snd_dev_doc[] = |
| 6813 | "int py_pjsua.set_snd_dev (int capture_dev, int playback_dev) " |
| 6814 | "Select or change sound device. Application may call this function " |
| 6815 | "at any time to replace current sound device."; |
| 6816 | static char pjsua_set_null_snd_dev_doc[] = |
| 6817 | "int py_pjsua.set_null_snd_dev () " |
| 6818 | "Set pjsua to use null sound device. The null sound device only " |
| 6819 | "provides the timing needed by the conference bridge, and will not " |
| 6820 | "interract with any hardware."; |
| 6821 | static char pjsua_set_no_snd_dev_doc[] = |
| 6822 | "py_pjsua.PJMedia_Port py_pjsua.set_no_snd_dev () " |
| 6823 | "Disconnect the main conference bridge from any sound devices, " |
| 6824 | "and let application connect the bridge to it's " |
| 6825 | "own sound device/master port."; |
| 6826 | static char pjsua_set_ec_doc[] = |
| 6827 | "int py_pjsua.set_ec (int tail_ms, int options) " |
| 6828 | "Configure the echo canceller tail length of the sound port."; |
| 6829 | static char pjsua_get_ec_tail_doc[] = |
| 6830 | "int py_pjsua.get_ec_tail () " |
| 6831 | "Get current echo canceller tail length."; |
| 6832 | static char pjsua_enum_codecs_doc[] = |
| 6833 | "py_pjsua.Codec_Info[] py_pjsua.enum_codecs () " |
| 6834 | "Enum all supported codecs in the system."; |
| 6835 | static char pjsua_codec_set_priority_doc[] = |
| 6836 | "int py_pjsua.codec_set_priority (string id, int priority) " |
| 6837 | "Change codec priority."; |
| 6838 | static char pjsua_codec_get_param_doc[] = |
| 6839 | "py_pjsua.PJMedia_Codec_Param py_pjsua.codec_get_param (string id) " |
| 6840 | "Get codec parameters"; |
| 6841 | static char pjsua_codec_set_param_doc[] = |
| 6842 | "int py_pjsua.codec_set_param (string id, " |
| 6843 | "py_pjsua.PJMedia_Codec_Param param) " |
| 6844 | "Set codec parameters."; |
| 6845 | |
| 6846 | /* END OF LIB MEDIA */ |
| 6847 | |
| 6848 | /* LIB CALL */ |
| 6849 | |
| 6850 | /* |
| 6851 | * pj_time_val_Object |
| 6852 | * PJ Time Val |
| 6853 | */ |
| 6854 | typedef struct |
| 6855 | { |
| 6856 | PyObject_HEAD |
| 6857 | /* Type-specific fields go here. */ |
| 6858 | long sec; |
| 6859 | long msec; |
| 6860 | |
| 6861 | } pj_time_val_Object; |
| 6862 | |
| 6863 | |
| 6864 | |
| 6865 | /* |
| 6866 | * pj_time_val_members |
| 6867 | */ |
| 6868 | static PyMemberDef pj_time_val_members[] = |
| 6869 | { |
| 6870 | |
| 6871 | { |
| 6872 | "sec", T_INT, |
| 6873 | offsetof(pj_time_val_Object, sec), 0, |
| 6874 | "The seconds part of the time" |
| 6875 | }, |
| 6876 | { |
| 6877 | "msec", T_INT, |
| 6878 | offsetof(pj_time_val_Object, sec), 0, |
| 6879 | "The milliseconds fraction of the time" |
| 6880 | }, |
| 6881 | |
| 6882 | |
| 6883 | {NULL} /* Sentinel */ |
| 6884 | }; |
| 6885 | |
| 6886 | |
| 6887 | |
| 6888 | |
| 6889 | /* |
| 6890 | * pj_time_val_Type |
| 6891 | */ |
| 6892 | static PyTypeObject pj_time_val_Type = |
| 6893 | { |
| 6894 | PyObject_HEAD_INIT(NULL) |
| 6895 | 0, /*ob_size*/ |
| 6896 | "py_pjsua.PJ_Time_Val", /*tp_name*/ |
| 6897 | sizeof(pj_time_val_Object), /*tp_basicsize*/ |
| 6898 | 0, /*tp_itemsize*/ |
| 6899 | 0,/*tp_dealloc*/ |
| 6900 | 0, /*tp_print*/ |
| 6901 | 0, /*tp_getattr*/ |
| 6902 | 0, /*tp_setattr*/ |
| 6903 | 0, /*tp_compare*/ |
| 6904 | 0, /*tp_repr*/ |
| 6905 | 0, /*tp_as_number*/ |
| 6906 | 0, /*tp_as_sequence*/ |
| 6907 | 0, /*tp_as_mapping*/ |
| 6908 | 0, /*tp_hash */ |
| 6909 | 0, /*tp_call*/ |
| 6910 | 0, /*tp_str*/ |
| 6911 | 0, /*tp_getattro*/ |
| 6912 | 0, /*tp_setattro*/ |
| 6913 | 0, /*tp_as_buffer*/ |
| 6914 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 6915 | "PJ Time Val objects", /* tp_doc */ |
| 6916 | 0, /* tp_traverse */ |
| 6917 | 0, /* tp_clear */ |
| 6918 | 0, /* tp_richcompare */ |
| 6919 | 0, /* tp_weaklistoffset */ |
| 6920 | 0, /* tp_iter */ |
| 6921 | 0, /* tp_iternext */ |
| 6922 | 0, /* tp_methods */ |
| 6923 | pj_time_val_members, /* tp_members */ |
| 6924 | |
| 6925 | |
| 6926 | }; |
| 6927 | |
| 6928 | /* |
| 6929 | * call_info_Object |
| 6930 | * Call Info |
| 6931 | */ |
| 6932 | typedef struct |
| 6933 | { |
| 6934 | PyObject_HEAD |
| 6935 | /* Type-specific fields go here. */ |
| 6936 | |
| 6937 | int id; |
| 6938 | int role; |
| 6939 | int acc_id; |
| 6940 | PyObject * local_info; |
| 6941 | PyObject * local_contact; |
| 6942 | PyObject * remote_info; |
| 6943 | PyObject * remote_contact; |
| 6944 | PyObject * call_id; |
| 6945 | int state; |
| 6946 | PyObject * state_text; |
| 6947 | int last_status; |
| 6948 | PyObject * last_status_text; |
| 6949 | int media_status; |
| 6950 | int media_dir; |
| 6951 | int conf_slot; |
| 6952 | pj_time_val_Object * connect_duration; |
| 6953 | pj_time_val_Object * total_duration; |
| 6954 | struct { |
| 6955 | char local_info[128]; |
| 6956 | char local_contact[128]; |
| 6957 | char remote_info[128]; |
| 6958 | char remote_contact[128]; |
| 6959 | char call_id[128]; |
| 6960 | char last_status_text[128]; |
| 6961 | } buf_; |
| 6962 | |
| 6963 | } call_info_Object; |
| 6964 | |
| 6965 | |
| 6966 | /* |
| 6967 | * call_info_dealloc |
| 6968 | * deletes a call_info from memory |
| 6969 | */ |
| 6970 | static void call_info_dealloc(call_info_Object* self) |
| 6971 | { |
| 6972 | Py_XDECREF(self->local_info); |
| 6973 | Py_XDECREF(self->local_contact); |
| 6974 | Py_XDECREF(self->remote_info); |
| 6975 | Py_XDECREF(self->remote_contact); |
| 6976 | Py_XDECREF(self->call_id); |
| 6977 | Py_XDECREF(self->state_text); |
| 6978 | Py_XDECREF(self->last_status_text); |
| 6979 | Py_XDECREF(self->connect_duration); |
| 6980 | Py_XDECREF(self->total_duration); |
| 6981 | self->ob_type->tp_free((PyObject*)self); |
| 6982 | } |
| 6983 | |
| 6984 | |
| 6985 | /* |
| 6986 | * call_info_new |
| 6987 | * constructor for call_info object |
| 6988 | */ |
| 6989 | static PyObject * call_info_new(PyTypeObject *type, PyObject *args, |
| 6990 | PyObject *kwds) |
| 6991 | { |
| 6992 | call_info_Object *self; |
| 6993 | |
| 6994 | self = (call_info_Object *)type->tp_alloc(type, 0); |
| 6995 | if (self != NULL) |
| 6996 | { |
| 6997 | self->local_info = PyString_FromString(""); |
| 6998 | if (self->local_info == NULL) |
| 6999 | { |
| 7000 | Py_DECREF(self); |
| 7001 | return NULL; |
| 7002 | } |
| 7003 | self->local_contact = PyString_FromString(""); |
| 7004 | if (self->local_contact == NULL) |
| 7005 | { |
| 7006 | Py_DECREF(self); |
| 7007 | return NULL; |
| 7008 | } |
| 7009 | self->remote_info = PyString_FromString(""); |
| 7010 | if (self->remote_info == NULL) |
| 7011 | { |
| 7012 | Py_DECREF(self); |
| 7013 | return NULL; |
| 7014 | } |
| 7015 | self->remote_contact = PyString_FromString(""); |
| 7016 | if (self->remote_contact == NULL) |
| 7017 | { |
| 7018 | Py_DECREF(self); |
| 7019 | return NULL; |
| 7020 | } |
| 7021 | self->call_id = PyString_FromString(""); |
| 7022 | if (self->call_id == NULL) |
| 7023 | { |
| 7024 | Py_DECREF(self); |
| 7025 | return NULL; |
| 7026 | } |
| 7027 | self->state_text = PyString_FromString(""); |
| 7028 | if (self->state_text == NULL) |
| 7029 | { |
| 7030 | Py_DECREF(self); |
| 7031 | return NULL; |
| 7032 | } |
| 7033 | self->last_status_text = PyString_FromString(""); |
| 7034 | if (self->last_status_text == NULL) |
| 7035 | { |
| 7036 | Py_DECREF(self); |
| 7037 | return NULL; |
| 7038 | } |
| 7039 | self->connect_duration = (pj_time_val_Object *)PyType_GenericNew |
| 7040 | (&pj_time_val_Type,NULL,NULL); |
| 7041 | if (self->connect_duration == NULL) |
| 7042 | { |
| 7043 | Py_DECREF(self); |
| 7044 | return NULL; |
| 7045 | } |
| 7046 | self->total_duration = (pj_time_val_Object *)PyType_GenericNew |
| 7047 | (&pj_time_val_Type,NULL,NULL); |
| 7048 | if (self->total_duration == NULL) |
| 7049 | { |
| 7050 | Py_DECREF(self); |
| 7051 | return NULL; |
| 7052 | } |
| 7053 | } |
| 7054 | return (PyObject *)self; |
| 7055 | } |
| 7056 | |
| 7057 | /* |
| 7058 | * call_info_members |
| 7059 | */ |
| 7060 | static PyMemberDef call_info_members[] = |
| 7061 | { |
| 7062 | { |
| 7063 | "id", T_INT, |
| 7064 | offsetof(call_info_Object, id), 0, |
| 7065 | "Call identification" |
| 7066 | }, |
| 7067 | { |
| 7068 | "role", T_INT, |
| 7069 | offsetof(call_info_Object, role), 0, |
| 7070 | "Initial call role (UAC == caller)" |
| 7071 | }, |
| 7072 | { |
| 7073 | "acc_id", T_INT, |
| 7074 | offsetof(call_info_Object, acc_id), 0, |
| 7075 | "The account ID where this call belongs." |
| 7076 | }, |
| 7077 | { |
| 7078 | "local_info", T_OBJECT_EX, |
| 7079 | offsetof(call_info_Object, local_info), 0, |
| 7080 | "Local URI" |
| 7081 | }, |
| 7082 | { |
| 7083 | "local_contact", T_OBJECT_EX, |
| 7084 | offsetof(call_info_Object, local_contact), 0, |
| 7085 | "Local Contact" |
| 7086 | }, |
| 7087 | { |
| 7088 | "remote_info", T_OBJECT_EX, |
| 7089 | offsetof(call_info_Object, remote_info), 0, |
| 7090 | "Remote URI" |
| 7091 | }, |
| 7092 | { |
| 7093 | "remote_contact", T_OBJECT_EX, |
| 7094 | offsetof(call_info_Object, remote_contact), 0, |
| 7095 | "Remote Contact" |
| 7096 | }, |
| 7097 | { |
| 7098 | "call_id", T_OBJECT_EX, |
| 7099 | offsetof(call_info_Object, call_id), 0, |
| 7100 | "Dialog Call-ID string" |
| 7101 | }, |
| 7102 | { |
| 7103 | "state", T_INT, |
| 7104 | offsetof(call_info_Object, state), 0, |
| 7105 | "Call state" |
| 7106 | }, |
| 7107 | { |
| 7108 | "state_text", T_OBJECT_EX, |
| 7109 | offsetof(call_info_Object, state_text), 0, |
| 7110 | "Text describing the state " |
| 7111 | }, |
| 7112 | { |
| 7113 | "last_status", T_INT, |
| 7114 | offsetof(call_info_Object, last_status), 0, |
| 7115 | "Last status code heard, which can be used as cause code" |
| 7116 | }, |
| 7117 | { |
| 7118 | "last_status_text", T_OBJECT_EX, |
| 7119 | offsetof(call_info_Object, last_status_text), 0, |
| 7120 | "The reason phrase describing the status." |
| 7121 | }, |
| 7122 | { |
| 7123 | "media_status", T_INT, |
| 7124 | offsetof(call_info_Object, media_status), 0, |
| 7125 | "Call media status." |
| 7126 | }, |
| 7127 | { |
| 7128 | "media_dir", T_INT, |
| 7129 | offsetof(call_info_Object, media_dir), 0, |
| 7130 | "Media direction" |
| 7131 | }, |
| 7132 | { |
| 7133 | "conf_slot", T_INT, |
| 7134 | offsetof(call_info_Object, conf_slot), 0, |
| 7135 | "The conference port number for the call" |
| 7136 | }, |
| 7137 | { |
| 7138 | "connect_duration", T_OBJECT_EX, |
| 7139 | offsetof(call_info_Object, connect_duration), 0, |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7140 | "Up-to-date call connected duration(zero when call is not established)" |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7141 | }, |
| 7142 | { |
| 7143 | "total_duration", T_OBJECT_EX, |
| 7144 | offsetof(call_info_Object, total_duration), 0, |
| 7145 | "Total call duration, including set-up time" |
| 7146 | }, |
| 7147 | |
| 7148 | {NULL} /* Sentinel */ |
| 7149 | }; |
| 7150 | |
| 7151 | |
| 7152 | |
| 7153 | |
| 7154 | /* |
| 7155 | * call_info_Type |
| 7156 | */ |
| 7157 | static PyTypeObject call_info_Type = |
| 7158 | { |
| 7159 | PyObject_HEAD_INIT(NULL) |
| 7160 | 0, /*ob_size*/ |
| 7161 | "py_pjsua.Call_Info", /*tp_name*/ |
| 7162 | sizeof(call_info_Object), /*tp_basicsize*/ |
| 7163 | 0, /*tp_itemsize*/ |
| 7164 | (destructor)call_info_dealloc,/*tp_dealloc*/ |
| 7165 | 0, /*tp_print*/ |
| 7166 | 0, /*tp_getattr*/ |
| 7167 | 0, /*tp_setattr*/ |
| 7168 | 0, /*tp_compare*/ |
| 7169 | 0, /*tp_repr*/ |
| 7170 | 0, /*tp_as_number*/ |
| 7171 | 0, /*tp_as_sequence*/ |
| 7172 | 0, /*tp_as_mapping*/ |
| 7173 | 0, /*tp_hash */ |
| 7174 | 0, /*tp_call*/ |
| 7175 | 0, /*tp_str*/ |
| 7176 | 0, /*tp_getattro*/ |
| 7177 | 0, /*tp_setattro*/ |
| 7178 | 0, /*tp_as_buffer*/ |
| 7179 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 7180 | "Call Info objects", /* tp_doc */ |
| 7181 | 0, /* tp_traverse */ |
| 7182 | 0, /* tp_clear */ |
| 7183 | 0, /* tp_richcompare */ |
| 7184 | 0, /* tp_weaklistoffset */ |
| 7185 | 0, /* tp_iter */ |
| 7186 | 0, /* tp_iternext */ |
| 7187 | 0, /* tp_methods */ |
| 7188 | call_info_members, /* tp_members */ |
| 7189 | 0, /* tp_getset */ |
| 7190 | 0, /* tp_base */ |
| 7191 | 0, /* tp_dict */ |
| 7192 | 0, /* tp_descr_get */ |
| 7193 | 0, /* tp_descr_set */ |
| 7194 | 0, /* tp_dictoffset */ |
| 7195 | 0, /* tp_init */ |
| 7196 | 0, /* tp_alloc */ |
| 7197 | call_info_new, /* tp_new */ |
| 7198 | |
| 7199 | }; |
| 7200 | |
| 7201 | /* |
| 7202 | * py_pjsua_call_get_max_count |
| 7203 | */ |
| 7204 | static PyObject *py_pjsua_call_get_max_count |
| 7205 | (PyObject *pSelf, PyObject *pArgs) |
| 7206 | { |
| 7207 | int count; |
| 7208 | |
| 7209 | if (!PyArg_ParseTuple(pArgs, "")) |
| 7210 | { |
| 7211 | return NULL; |
| 7212 | } |
| 7213 | |
| 7214 | count = pjsua_call_get_max_count(); |
| 7215 | |
| 7216 | |
| 7217 | return Py_BuildValue("i", count); |
| 7218 | } |
| 7219 | |
| 7220 | /* |
| 7221 | * py_pjsua_call_get_count |
| 7222 | */ |
| 7223 | static PyObject *py_pjsua_call_get_count |
| 7224 | (PyObject *pSelf, PyObject *pArgs) |
| 7225 | { |
| 7226 | |
| 7227 | int count; |
| 7228 | |
| 7229 | |
| 7230 | if (!PyArg_ParseTuple(pArgs, "")) |
| 7231 | { |
| 7232 | return NULL; |
| 7233 | } |
| 7234 | |
| 7235 | count = pjsua_call_get_count(); |
| 7236 | |
| 7237 | |
| 7238 | return Py_BuildValue("i", count); |
| 7239 | } |
| 7240 | |
| 7241 | /* |
| 7242 | * py_pjsua_enum_calls |
| 7243 | */ |
| 7244 | static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs) |
| 7245 | { |
| 7246 | pj_status_t status; |
| 7247 | PyObject *list; |
| 7248 | |
| 7249 | pjsua_transport_id id[PJSUA_MAX_CALLS]; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7250 | unsigned c, i; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7251 | if (!PyArg_ParseTuple(pArgs, "")) |
| 7252 | { |
| 7253 | return NULL; |
| 7254 | } |
| 7255 | |
| 7256 | c = PJ_ARRAY_SIZE(id); |
| 7257 | status = pjsua_enum_calls(id, &c); |
| 7258 | |
| 7259 | list = PyList_New(c); |
| 7260 | for (i = 0; i < c; i++) |
| 7261 | { |
| 7262 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
| 7263 | if (ret == -1) |
| 7264 | { |
| 7265 | return NULL; |
| 7266 | } |
| 7267 | } |
| 7268 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7269 | return Py_BuildValue("O",list); |
| 7270 | } |
| 7271 | |
| 7272 | /* |
| 7273 | * py_pjsua_call_make_call |
| 7274 | */ |
| 7275 | static PyObject *py_pjsua_call_make_call |
| 7276 | (PyObject *pSelf, PyObject *pArgs) |
| 7277 | { |
| 7278 | int status; |
| 7279 | int acc_id; |
| 7280 | pj_str_t dst_uri; |
| 7281 | PyObject * sd; |
| 7282 | unsigned options; |
| 7283 | pjsua_msg_data msg_data; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7284 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7285 | msg_data_Object * omd; |
| 7286 | int user_data; |
| 7287 | int call_id; |
| 7288 | pj_pool_t * pool; |
| 7289 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7290 | if (!PyArg_ParseTuple |
| 7291 | (pArgs, "iOIiO", &acc_id, &sd, &options, &user_data, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7292 | { |
| 7293 | return NULL; |
| 7294 | } |
| 7295 | |
| 7296 | dst_uri.ptr = PyString_AsString(sd); |
| 7297 | dst_uri.slen = strlen(PyString_AsString(sd)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7298 | if (omdObj != Py_None) |
| 7299 | { |
| 7300 | omd = (msg_data_Object *)omdObj; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7301 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7302 | msg_data.content_type.slen = strlen |
| 7303 | (PyString_AsString(omd->content_type)); |
| 7304 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7305 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7306 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7307 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7308 | status = pjsua_call_make_call(acc_id, &dst_uri, |
Benny Prijono | e6ead54 | 2007-01-31 20:53:31 +0000 | [diff] [blame] | 7309 | options, (void*)user_data, &msg_data, &call_id); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7310 | pj_pool_release(pool); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 7311 | } else { |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 7312 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7313 | status = pjsua_call_make_call(acc_id, &dst_uri, |
Benny Prijono | e6ead54 | 2007-01-31 20:53:31 +0000 | [diff] [blame] | 7314 | options, (void*)user_data, NULL, &call_id); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 7315 | } |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 7316 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7317 | return Py_BuildValue("ii",status, call_id); |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 7318 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | /* |
| 7322 | * py_pjsua_call_is_active |
| 7323 | */ |
| 7324 | static PyObject *py_pjsua_call_is_active |
| 7325 | (PyObject *pSelf, PyObject *pArgs) |
| 7326 | { |
| 7327 | int call_id; |
| 7328 | int isActive; |
| 7329 | |
| 7330 | |
| 7331 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) |
| 7332 | { |
| 7333 | return NULL; |
| 7334 | } |
| 7335 | |
| 7336 | isActive = pjsua_call_is_active(call_id); |
| 7337 | |
| 7338 | |
| 7339 | return Py_BuildValue("i", isActive); |
| 7340 | } |
| 7341 | |
| 7342 | /* |
| 7343 | * py_pjsua_call_has_media |
| 7344 | */ |
| 7345 | static PyObject *py_pjsua_call_has_media |
| 7346 | (PyObject *pSelf, PyObject *pArgs) |
| 7347 | { |
| 7348 | int call_id; |
| 7349 | int hasMedia; |
| 7350 | |
| 7351 | |
| 7352 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) |
| 7353 | { |
| 7354 | return NULL; |
| 7355 | } |
| 7356 | |
| 7357 | hasMedia = pjsua_call_has_media(call_id); |
| 7358 | |
| 7359 | |
| 7360 | return Py_BuildValue("i", hasMedia); |
| 7361 | } |
| 7362 | |
| 7363 | /* |
| 7364 | * py_pjsua_call_get_conf_port |
| 7365 | */ |
| 7366 | static PyObject *py_pjsua_call_get_conf_port |
| 7367 | (PyObject *pSelf, PyObject *pArgs) |
| 7368 | { |
| 7369 | int call_id; |
| 7370 | int port_id; |
| 7371 | |
| 7372 | |
| 7373 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) |
| 7374 | { |
| 7375 | return NULL; |
| 7376 | } |
| 7377 | |
| 7378 | port_id = pjsua_call_get_conf_port(call_id); |
| 7379 | |
| 7380 | |
| 7381 | return Py_BuildValue("i", port_id); |
| 7382 | } |
| 7383 | |
| 7384 | /* |
| 7385 | * py_pjsua_call_get_info |
| 7386 | */ |
| 7387 | static PyObject *py_pjsua_call_get_info |
| 7388 | (PyObject *pSelf, PyObject *pArgs) |
| 7389 | { |
| 7390 | int call_id; |
| 7391 | int status; |
| 7392 | call_info_Object * oi; |
| 7393 | pjsua_call_info info; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7394 | |
| 7395 | |
| 7396 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) |
| 7397 | { |
| 7398 | return NULL; |
| 7399 | } |
| 7400 | |
| 7401 | |
| 7402 | status = pjsua_call_get_info(call_id, &info); |
| 7403 | if (status == PJ_SUCCESS) |
| 7404 | { |
| 7405 | oi = (call_info_Object *)call_info_new(&call_info_Type, NULL, NULL); |
| 7406 | oi->acc_id = info.acc_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7407 | pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id), |
| 7408 | "%.*s", (int)info.call_id.slen, info.call_id.ptr); |
| 7409 | pj_ansi_snprintf(oi->buf_.last_status_text, |
| 7410 | sizeof(oi->buf_.last_status_text), |
| 7411 | "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr); |
| 7412 | pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact), |
| 7413 | "%.*s", (int)info.local_contact.slen, info.local_contact.ptr); |
| 7414 | pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info), |
| 7415 | "%.*s", (int)info.local_info.slen, info.local_info.ptr); |
| 7416 | pj_ansi_snprintf(oi->buf_.remote_contact, |
| 7417 | sizeof(oi->buf_.remote_contact), |
| 7418 | "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr); |
| 7419 | pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info), |
| 7420 | "%.*s", (int)info.remote_info.slen, info.remote_info.ptr); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 7421 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7422 | oi->call_id = PyString_FromStringAndSize(info.call_id.ptr, |
| 7423 | info.call_id.slen); |
| 7424 | oi->conf_slot = info.conf_slot; |
| 7425 | oi->connect_duration->sec = info.connect_duration.sec; |
| 7426 | oi->connect_duration->msec = info.connect_duration.msec; |
| 7427 | oi->total_duration->sec = info.total_duration.sec; |
| 7428 | oi->total_duration->msec = info.total_duration.msec; |
| 7429 | oi->id = info.id; |
| 7430 | oi->last_status = info.last_status; |
| 7431 | oi->last_status_text = PyString_FromStringAndSize( |
| 7432 | info.last_status_text.ptr, info.last_status_text.slen); |
| 7433 | oi->local_contact = PyString_FromStringAndSize( |
| 7434 | info.local_contact.ptr, info.local_contact.slen); |
| 7435 | oi->local_info = PyString_FromStringAndSize( |
| 7436 | info.local_info.ptr, info.local_info.slen); |
| 7437 | oi->remote_contact = PyString_FromStringAndSize( |
| 7438 | info.remote_contact.ptr, info.remote_contact.slen); |
| 7439 | oi->remote_info = PyString_FromStringAndSize( |
| 7440 | info.remote_info.ptr, info.remote_info.slen); |
| 7441 | oi->media_dir = info.media_dir; |
| 7442 | oi->media_status = info.media_status; |
| 7443 | oi->role = info.role; |
| 7444 | oi->state = info.state; |
| 7445 | oi->state_text = PyString_FromStringAndSize( |
| 7446 | info.state_text.ptr, info.state_text.slen); |
| 7447 | |
| 7448 | return Py_BuildValue("O", oi); |
| 7449 | } else { |
| 7450 | Py_INCREF(Py_None); |
| 7451 | return Py_None; |
| 7452 | } |
| 7453 | } |
| 7454 | |
| 7455 | /* |
| 7456 | * py_pjsua_call_set_user_data |
| 7457 | */ |
| 7458 | static PyObject *py_pjsua_call_set_user_data |
| 7459 | (PyObject *pSelf, PyObject *pArgs) |
| 7460 | { |
| 7461 | int call_id; |
| 7462 | int user_data; |
| 7463 | int status; |
| 7464 | |
| 7465 | if (!PyArg_ParseTuple(pArgs, "ii", &call_id, &user_data)) |
| 7466 | { |
| 7467 | return NULL; |
| 7468 | } |
| 7469 | |
Benny Prijono | e6ead54 | 2007-01-31 20:53:31 +0000 | [diff] [blame] | 7470 | status = pjsua_call_set_user_data(call_id, (void*)user_data); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7471 | |
| 7472 | |
| 7473 | return Py_BuildValue("i", status); |
| 7474 | } |
| 7475 | |
| 7476 | /* |
| 7477 | * py_pjsua_call_get_user_data |
| 7478 | */ |
| 7479 | static PyObject *py_pjsua_call_get_user_data |
| 7480 | (PyObject *pSelf, PyObject *pArgs) |
| 7481 | { |
| 7482 | int call_id; |
Benny Prijono | e6ead54 | 2007-01-31 20:53:31 +0000 | [diff] [blame] | 7483 | void * user_data; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7484 | |
| 7485 | |
| 7486 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) |
| 7487 | { |
| 7488 | return NULL; |
| 7489 | } |
| 7490 | |
| 7491 | user_data = pjsua_call_get_user_data(call_id); |
| 7492 | |
| 7493 | |
Benny Prijono | e6ead54 | 2007-01-31 20:53:31 +0000 | [diff] [blame] | 7494 | return Py_BuildValue("i", (int)user_data); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7495 | } |
| 7496 | |
| 7497 | /* |
| 7498 | * py_pjsua_call_answer |
| 7499 | */ |
| 7500 | static PyObject *py_pjsua_call_answer |
| 7501 | (PyObject *pSelf, PyObject *pArgs) |
| 7502 | { |
| 7503 | int status; |
| 7504 | int call_id; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7505 | pj_str_t * reason, tmp_reason; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7506 | PyObject * sr; |
| 7507 | unsigned code; |
| 7508 | pjsua_msg_data msg_data; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7509 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7510 | msg_data_Object * omd; |
| 7511 | pj_pool_t * pool; |
| 7512 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7513 | if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7514 | { |
| 7515 | return NULL; |
| 7516 | } |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7517 | if (sr == Py_None) |
| 7518 | { |
| 7519 | reason = NULL; |
| 7520 | } else { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7521 | reason = &tmp_reason; |
| 7522 | tmp_reason.ptr = PyString_AsString(sr); |
| 7523 | tmp_reason.slen = strlen(PyString_AsString(sr)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7524 | } |
| 7525 | if (omdObj != Py_None) |
| 7526 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7527 | omd = (msg_data_Object *)omdObj; |
| 7528 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7529 | msg_data.content_type.slen = strlen |
| 7530 | (PyString_AsString(omd->content_type)); |
| 7531 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7532 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7533 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7534 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7535 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7536 | status = pjsua_call_answer(call_id, code, reason, &msg_data); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7537 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7538 | pj_pool_release(pool); |
| 7539 | } else { |
| 7540 | |
Fahris | 89ea3d0 | 2007-02-07 08:18:35 +0000 | [diff] [blame] | 7541 | status = pjsua_call_answer(call_id, code, reason, NULL); |
| 7542 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7543 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7544 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7545 | return Py_BuildValue("i",status); |
| 7546 | } |
| 7547 | |
| 7548 | /* |
| 7549 | * py_pjsua_call_hangup |
| 7550 | */ |
| 7551 | static PyObject *py_pjsua_call_hangup |
| 7552 | (PyObject *pSelf, PyObject *pArgs) |
| 7553 | { |
| 7554 | int status; |
| 7555 | int call_id; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7556 | pj_str_t * reason, tmp_reason; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7557 | PyObject * sr; |
| 7558 | unsigned code; |
| 7559 | pjsua_msg_data msg_data; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7560 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7561 | msg_data_Object * omd; |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 7562 | pj_pool_t * pool = NULL; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7563 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7564 | if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7565 | { |
| 7566 | return NULL; |
| 7567 | } |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 7568 | if (sr == Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7569 | { |
| 7570 | reason = NULL; |
| 7571 | } else { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7572 | reason = &tmp_reason; |
| 7573 | tmp_reason.ptr = PyString_AsString(sr); |
| 7574 | tmp_reason.slen = strlen(PyString_AsString(sr)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7575 | } |
| 7576 | if (omdObj != Py_None) |
| 7577 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7578 | omd = (msg_data_Object *)omdObj; |
| 7579 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7580 | msg_data.content_type.slen = strlen |
| 7581 | (PyString_AsString(omd->content_type)); |
| 7582 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7583 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7584 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7585 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7586 | status = pjsua_call_hangup(call_id, code, reason, &msg_data); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7587 | pj_pool_release(pool); |
Benny Prijono | ed7a5a7 | 2007-01-29 18:36:38 +0000 | [diff] [blame] | 7588 | } else { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7589 | status = pjsua_call_hangup(call_id, code, reason, NULL); |
| 7590 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7591 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7592 | return Py_BuildValue("i",status); |
| 7593 | } |
| 7594 | |
| 7595 | /* |
| 7596 | * py_pjsua_call_set_hold |
| 7597 | */ |
| 7598 | static PyObject *py_pjsua_call_set_hold |
| 7599 | (PyObject *pSelf, PyObject *pArgs) |
| 7600 | { |
| 7601 | int status; |
| 7602 | int call_id; |
| 7603 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7604 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7605 | msg_data_Object * omd; |
| 7606 | pj_pool_t * pool; |
| 7607 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7608 | if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7609 | { |
| 7610 | return NULL; |
| 7611 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7612 | |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7613 | if (omdObj != Py_None) |
| 7614 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7615 | omd = (msg_data_Object *)omdObj; |
| 7616 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7617 | msg_data.content_type.slen = strlen |
| 7618 | (PyString_AsString(omd->content_type)); |
| 7619 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7620 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7621 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7622 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7623 | status = pjsua_call_set_hold(call_id, &msg_data); |
| 7624 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7625 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7626 | status = pjsua_call_set_hold(call_id, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7627 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7628 | return Py_BuildValue("i",status); |
| 7629 | } |
| 7630 | |
| 7631 | /* |
| 7632 | * py_pjsua_call_reinvite |
| 7633 | */ |
| 7634 | static PyObject *py_pjsua_call_reinvite |
| 7635 | (PyObject *pSelf, PyObject *pArgs) |
| 7636 | { |
| 7637 | int status; |
| 7638 | int call_id; |
| 7639 | int unhold; |
| 7640 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7641 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7642 | msg_data_Object * omd; |
| 7643 | pj_pool_t * pool; |
| 7644 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7645 | if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7646 | { |
| 7647 | return NULL; |
| 7648 | } |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7649 | |
| 7650 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7651 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7652 | omd = (msg_data_Object *)omdObj; |
| 7653 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7654 | msg_data.content_type.slen = strlen |
| 7655 | (PyString_AsString(omd->content_type)); |
| 7656 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7657 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7658 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7659 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7660 | status = pjsua_call_reinvite(call_id, unhold, &msg_data); |
| 7661 | pj_pool_release(pool); |
| 7662 | } else { |
| 7663 | status = pjsua_call_reinvite(call_id, unhold, NULL); |
| 7664 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7665 | return Py_BuildValue("i",status); |
| 7666 | } |
| 7667 | |
| 7668 | /* |
| 7669 | * py_pjsua_call_xfer |
| 7670 | */ |
| 7671 | static PyObject *py_pjsua_call_xfer |
| 7672 | (PyObject *pSelf, PyObject *pArgs) |
| 7673 | { |
| 7674 | int status; |
| 7675 | int call_id; |
| 7676 | pj_str_t dest; |
| 7677 | PyObject * sd; |
| 7678 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7679 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7680 | msg_data_Object * omd; |
| 7681 | pj_pool_t * pool; |
| 7682 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7683 | if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &sd, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7684 | { |
| 7685 | return NULL; |
| 7686 | } |
| 7687 | |
| 7688 | dest.ptr = PyString_AsString(sd); |
| 7689 | dest.slen = strlen(PyString_AsString(sd)); |
| 7690 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7691 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7692 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7693 | omd = (msg_data_Object *)omdObj; |
| 7694 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7695 | msg_data.content_type.slen = strlen |
| 7696 | (PyString_AsString(omd->content_type)); |
| 7697 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7698 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7699 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7700 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7701 | status = pjsua_call_xfer(call_id, &dest, &msg_data); |
| 7702 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7703 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7704 | status = pjsua_call_xfer(call_id, &dest, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7705 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7706 | return Py_BuildValue("i",status); |
| 7707 | } |
| 7708 | |
| 7709 | /* |
| 7710 | * py_pjsua_call_xfer_replaces |
| 7711 | */ |
| 7712 | static PyObject *py_pjsua_call_xfer_replaces |
| 7713 | (PyObject *pSelf, PyObject *pArgs) |
| 7714 | { |
| 7715 | int status; |
| 7716 | int call_id; |
| 7717 | int dest_call_id; |
| 7718 | unsigned options; |
| 7719 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7720 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7721 | msg_data_Object * omd; |
| 7722 | pj_pool_t * pool; |
| 7723 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7724 | if (!PyArg_ParseTuple |
| 7725 | (pArgs, "iiIO", &call_id, &dest_call_id, &options, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7726 | { |
| 7727 | return NULL; |
| 7728 | } |
| 7729 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7730 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7731 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7732 | omd = (msg_data_Object *)omdObj; |
| 7733 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7734 | msg_data.content_type.slen = strlen |
| 7735 | (PyString_AsString(omd->content_type)); |
| 7736 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7737 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7738 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7739 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7740 | status = pjsua_call_xfer_replaces |
| 7741 | (call_id, dest_call_id, options, &msg_data); |
| 7742 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7743 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7744 | status = pjsua_call_xfer_replaces(call_id, dest_call_id,options, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7745 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7746 | return Py_BuildValue("i",status); |
| 7747 | } |
| 7748 | |
| 7749 | /* |
| 7750 | * py_pjsua_call_dial_dtmf |
| 7751 | */ |
| 7752 | static PyObject *py_pjsua_call_dial_dtmf |
| 7753 | (PyObject *pSelf, PyObject *pArgs) |
| 7754 | { |
| 7755 | int call_id; |
| 7756 | PyObject * sd; |
| 7757 | pj_str_t digits; |
| 7758 | int status; |
| 7759 | |
| 7760 | if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &sd)) |
| 7761 | { |
| 7762 | return NULL; |
| 7763 | } |
| 7764 | digits.ptr = PyString_AsString(sd); |
| 7765 | digits.slen = strlen(PyString_AsString(sd)); |
| 7766 | status = pjsua_call_dial_dtmf(call_id, &digits); |
| 7767 | |
| 7768 | return Py_BuildValue("i", status); |
| 7769 | } |
| 7770 | |
| 7771 | /* |
| 7772 | * py_pjsua_call_send_im |
| 7773 | */ |
| 7774 | static PyObject *py_pjsua_call_send_im |
| 7775 | (PyObject *pSelf, PyObject *pArgs) |
| 7776 | { |
| 7777 | int status; |
| 7778 | int call_id; |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7779 | pj_str_t content; |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7780 | pj_str_t * mime_type, tmp_mime_type; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7781 | PyObject * sm; |
| 7782 | PyObject * sc; |
| 7783 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7784 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7785 | msg_data_Object * omd; |
| 7786 | int user_data; |
| 7787 | pj_pool_t * pool; |
| 7788 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7789 | if (!PyArg_ParseTuple |
| 7790 | (pArgs, "iOOOi", &call_id, &sm, &sc, &omdObj, &user_data)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7791 | { |
| 7792 | return NULL; |
| 7793 | } |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7794 | if (sm == Py_None) |
| 7795 | { |
| 7796 | mime_type = NULL; |
| 7797 | } else { |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7798 | mime_type = &tmp_mime_type; |
| 7799 | tmp_mime_type.ptr = PyString_AsString(sm); |
| 7800 | tmp_mime_type.slen = strlen(PyString_AsString(sm)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7801 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7802 | content.ptr = PyString_AsString(sc); |
| 7803 | content.slen = strlen(PyString_AsString(sc)); |
| 7804 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7805 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7806 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7807 | omd = (msg_data_Object *)omdObj; |
| 7808 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7809 | msg_data.content_type.slen = strlen |
| 7810 | (PyString_AsString(omd->content_type)); |
| 7811 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7812 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7813 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7814 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7815 | status = pjsua_call_send_im |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7816 | (call_id, mime_type, &content, &msg_data, (void *)user_data); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7817 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7818 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7819 | status = pjsua_call_send_im |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7820 | (call_id, mime_type, &content, NULL, (void *)user_data); |
| 7821 | } |
Fahris | e314b88 | 2007-02-02 10:52:04 +0000 | [diff] [blame] | 7822 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7823 | return Py_BuildValue("i",status); |
| 7824 | } |
| 7825 | |
| 7826 | /* |
| 7827 | * py_pjsua_call_send_typing_ind |
| 7828 | */ |
| 7829 | static PyObject *py_pjsua_call_send_typing_ind |
| 7830 | (PyObject *pSelf, PyObject *pArgs) |
| 7831 | { |
| 7832 | int status; |
| 7833 | int call_id; |
| 7834 | int is_typing; |
| 7835 | pjsua_msg_data msg_data; |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7836 | PyObject * omdObj; |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7837 | msg_data_Object * omd; |
| 7838 | pj_pool_t * pool; |
| 7839 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7840 | if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7841 | { |
| 7842 | return NULL; |
| 7843 | } |
| 7844 | |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7845 | if (omdObj != Py_None) |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7846 | { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7847 | omd = (msg_data_Object *)omdObj; |
| 7848 | msg_data.content_type.ptr = PyString_AsString(omd->content_type); |
| 7849 | msg_data.content_type.slen = strlen |
| 7850 | (PyString_AsString(omd->content_type)); |
| 7851 | msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); |
| 7852 | msg_data.msg_body.slen = strlen(PyString_AsString(omd->msg_body)); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7853 | pool = pjsua_pool_create("pjsua", POOL_SIZE, POOL_SIZE); |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7854 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
| 7855 | status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data); |
| 7856 | pj_pool_release(pool); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7857 | } else { |
Fahris | 17d9181 | 2007-01-29 12:09:33 +0000 | [diff] [blame] | 7858 | status = pjsua_call_send_typing_ind(call_id, is_typing, NULL); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7859 | } |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7860 | return Py_BuildValue("i",status); |
| 7861 | } |
| 7862 | |
| 7863 | /* |
| 7864 | * py_pjsua_call_hangup_all |
| 7865 | */ |
| 7866 | static PyObject *py_pjsua_call_hangup_all |
| 7867 | (PyObject *pSelf, PyObject *pArgs) |
| 7868 | { |
| 7869 | |
| 7870 | if (!PyArg_ParseTuple(pArgs, "")) |
| 7871 | { |
| 7872 | return NULL; |
| 7873 | } |
| 7874 | |
| 7875 | pjsua_call_hangup_all(); |
| 7876 | |
| 7877 | Py_INCREF(Py_None); |
| 7878 | return Py_None; |
| 7879 | } |
| 7880 | |
| 7881 | /* |
| 7882 | * py_pjsua_call_dump |
| 7883 | */ |
| 7884 | static PyObject *py_pjsua_call_dump |
| 7885 | (PyObject *pSelf, PyObject *pArgs) |
| 7886 | { |
| 7887 | int call_id; |
| 7888 | int with_media; |
| 7889 | PyObject * sb; |
| 7890 | PyObject * si; |
| 7891 | char * buffer; |
| 7892 | char * indent; |
| 7893 | unsigned maxlen; |
| 7894 | int status; |
| 7895 | |
| 7896 | if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, &maxlen, &si)) |
| 7897 | { |
| 7898 | return NULL; |
| 7899 | } |
| 7900 | buffer = (char *) malloc (maxlen * sizeof(char)); |
| 7901 | indent = PyString_AsString(si); |
| 7902 | |
| 7903 | status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent); |
| 7904 | sb = PyString_FromStringAndSize(buffer, maxlen); |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 7905 | free(buffer); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7906 | return Py_BuildValue("O", sb); |
| 7907 | } |
| 7908 | |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 7909 | |
| 7910 | /* |
| 7911 | * py_pjsua_dump |
| 7912 | * Dump application states. |
| 7913 | */ |
| 7914 | static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs) |
| 7915 | { |
| 7916 | unsigned old_decor; |
| 7917 | char buf[1024]; |
| 7918 | int detail; |
| 7919 | |
| 7920 | if (!PyArg_ParseTuple(pArgs, "i", &detail)) |
| 7921 | { |
| 7922 | return NULL; |
| 7923 | } |
| 7924 | |
| 7925 | PJ_LOG(3,(THIS_FILE, "Start dumping application states:")); |
| 7926 | |
| 7927 | old_decor = pj_log_get_decor(); |
| 7928 | pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR)); |
| 7929 | |
| 7930 | if (detail) |
| 7931 | pj_dump_config(); |
| 7932 | |
| 7933 | pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail); |
| 7934 | pjmedia_endpt_dump(pjsua_get_pjmedia_endpt()); |
| 7935 | pjsip_tsx_layer_dump(detail); |
| 7936 | pjsip_ua_dump(detail); |
| 7937 | |
| 7938 | |
| 7939 | /* Dump all invite sessions: */ |
| 7940 | PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:")); |
| 7941 | |
| 7942 | if (pjsua_call_get_count() == 0) { |
| 7943 | |
| 7944 | PJ_LOG(3,(THIS_FILE, " - no sessions -")); |
| 7945 | |
| 7946 | } else { |
| 7947 | unsigned i, max; |
| 7948 | |
| 7949 | max = pjsua_call_get_max_count(); |
| 7950 | for (i=0; i<max; ++i) { |
| 7951 | if (pjsua_call_is_active(i)) { |
| 7952 | pjsua_call_dump(i, detail, buf, sizeof(buf), " "); |
| 7953 | PJ_LOG(3,(THIS_FILE, "%s", buf)); |
| 7954 | } |
| 7955 | } |
| 7956 | } |
| 7957 | |
| 7958 | /* Dump presence status */ |
| 7959 | pjsua_pres_dump(detail); |
| 7960 | |
| 7961 | pj_log_set_decor(old_decor); |
| 7962 | PJ_LOG(3,(THIS_FILE, "Dump complete")); |
| 7963 | |
| 7964 | Py_INCREF(Py_None); |
| 7965 | return Py_None; |
| 7966 | } |
| 7967 | |
| 7968 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 7969 | static char pjsua_call_get_max_count_doc[] = |
| 7970 | "int py_pjsua.call_get_max_count () " |
| 7971 | "Get maximum number of calls configured in pjsua."; |
| 7972 | static char pjsua_call_get_count_doc[] = |
| 7973 | "int py_pjsua.call_get_count () " |
| 7974 | "Get number of currently active calls."; |
| 7975 | static char pjsua_enum_calls_doc[] = |
| 7976 | "int[] py_pjsua.enum_calls () " |
| 7977 | "Get maximum number of calls configured in pjsua."; |
| 7978 | static char pjsua_call_make_call_doc[] = |
| 7979 | "int,int py_pjsua.call_make_call (int acc_id, string dst_uri, int options," |
| 7980 | "int user_data, py_pjsua.Msg_Data msg_data) " |
| 7981 | "Make outgoing call to the specified URI using the specified account."; |
| 7982 | static char pjsua_call_is_active_doc[] = |
| 7983 | "int py_pjsua.call_is_active (int call_id) " |
| 7984 | "Check if the specified call has active INVITE session and the INVITE " |
| 7985 | "session has not been disconnected."; |
| 7986 | static char pjsua_call_has_media_doc[] = |
| 7987 | "int py_pjsua.call_has_media (int call_id) " |
| 7988 | "Check if call has an active media session."; |
| 7989 | static char pjsua_call_get_conf_port_doc[] = |
| 7990 | "int py_pjsua.call_get_conf_port (int call_id) " |
| 7991 | "Get the conference port identification associated with the call."; |
| 7992 | static char pjsua_call_get_info_doc[] = |
| 7993 | "py_pjsua.Call_Info py_pjsua.call_get_info (int call_id) " |
| 7994 | "Obtain detail information about the specified call."; |
| 7995 | static char pjsua_call_set_user_data_doc[] = |
| 7996 | "int py_pjsua.call_set_user_data (int call_id, int user_data) " |
| 7997 | "Attach application specific data to the call."; |
| 7998 | static char pjsua_call_get_user_data_doc[] = |
| 7999 | "int py_pjsua.call_get_user_data (int call_id) " |
| 8000 | "Get user data attached to the call."; |
| 8001 | static char pjsua_call_answer_doc[] = |
| 8002 | "int py_pjsua.call_answer (int call_id, int code, string reason, " |
| 8003 | "py_pjsua.Msg_Data msg_data) " |
| 8004 | "Send response to incoming INVITE request."; |
| 8005 | static char pjsua_call_hangup_doc[] = |
| 8006 | "int py_pjsua.call_hangup (int call_id, int code, string reason, " |
| 8007 | "py_pjsua.Msg_Data msg_data) " |
| 8008 | "Hangup call by using method that is appropriate according " |
| 8009 | "to the call state."; |
| 8010 | static char pjsua_call_set_hold_doc[] = |
| 8011 | "int py_pjsua.call_set_hold (int call_id, py_pjsua.Msg_Data msg_data) " |
| 8012 | "Put the specified call on hold."; |
| 8013 | static char pjsua_call_reinvite_doc[] = |
| 8014 | "int py_pjsua.call_reinvite (int call_id, int unhold, " |
| 8015 | "py_pjsua.Msg_Data msg_data) " |
| 8016 | "Send re-INVITE (to release hold)."; |
| 8017 | static char pjsua_call_xfer_doc[] = |
| 8018 | "int py_pjsua.call_xfer (int call_id, string dest, " |
| 8019 | "py_pjsua.Msg_Data msg_data) " |
| 8020 | "Initiate call transfer to the specified address. " |
| 8021 | "This function will send REFER request to instruct remote call party " |
| 8022 | "to initiate a new INVITE session to the specified destination/target."; |
| 8023 | static char pjsua_call_xfer_replaces_doc[] = |
| 8024 | "int py_pjsua.call_xfer_replaces (int call_id, int dest_call_id, " |
| 8025 | "int options, py_pjsua.Msg_Data msg_data) " |
| 8026 | "Initiate attended call transfer. This function will send REFER request " |
| 8027 | "to instruct remote call party to initiate new INVITE session to the URL " |
| 8028 | "of dest_call_id. The party at dest_call_id then should 'replace' the call" |
| 8029 | "with us with the new call from the REFER recipient."; |
| 8030 | static char pjsua_call_dial_dtmf_doc[] = |
| 8031 | "int py_pjsua.call_dial_dtmf (int call_id, string digits) " |
| 8032 | "Send DTMF digits to remote using RFC 2833 payload formats."; |
| 8033 | static char pjsua_call_send_im_doc[] = |
| 8034 | "int py_pjsua.call_send_im (int call_id, string mime_type, string content," |
| 8035 | "py_pjsua.Msg_Data msg_data, int user_data) " |
| 8036 | "Send instant messaging inside INVITE session."; |
| 8037 | static char pjsua_call_send_typing_ind_doc[] = |
| 8038 | "int py_pjsua.call_send_typing_ind (int call_id, int is_typing, " |
| 8039 | "py_pjsua.Msg_Data msg_data) " |
| 8040 | "Send IM typing indication inside INVITE session."; |
| 8041 | static char pjsua_call_hangup_all_doc[] = |
| 8042 | "void py_pjsua.call_hangup_all () " |
| 8043 | "Terminate all calls."; |
| 8044 | static char pjsua_call_dump_doc[] = |
| 8045 | "int py_pjsua.call_dump (int call_id, int with_media, int maxlen, " |
| 8046 | "string indent) " |
| 8047 | "Dump call and media statistics to string."; |
| 8048 | |
| 8049 | /* END OF LIB CALL */ |
| 8050 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8051 | /* |
| 8052 | * Map of function names to functions |
| 8053 | */ |
| 8054 | static PyMethodDef py_pjsua_methods[] = |
| 8055 | { |
| 8056 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8057 | "thread_register", py_pjsua_thread_register, METH_VARARGS, |
| 8058 | pjsua_thread_register_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8059 | }, |
| 8060 | { |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8061 | "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc |
| 8062 | }, |
| 8063 | { |
| 8064 | "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc |
| 8065 | }, |
| 8066 | { |
| 8067 | "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc |
| 8068 | }, |
| 8069 | { |
| 8070 | "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc |
| 8071 | }, |
| 8072 | { |
| 8073 | "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc |
| 8074 | }, |
| 8075 | { |
| 8076 | "handle_events", py_pjsua_handle_events, METH_VARARGS, |
| 8077 | pjsua_handle_events_doc |
| 8078 | }, |
| 8079 | { |
| 8080 | "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS, |
| 8081 | pjsua_verify_sip_url_doc |
| 8082 | }, |
| 8083 | { |
| 8084 | "pool_create", py_pjsua_pool_create, METH_VARARGS, |
| 8085 | pjsua_pool_create_doc |
| 8086 | }, |
| 8087 | { |
| 8088 | "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS, |
| 8089 | pjsua_get_pjsip_endpt_doc |
| 8090 | }, |
| 8091 | { |
| 8092 | "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS, |
| 8093 | pjsua_get_pjmedia_endpt_doc |
| 8094 | }, |
| 8095 | { |
| 8096 | "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS, |
| 8097 | pjsua_get_pool_factory_doc |
| 8098 | }, |
| 8099 | { |
| 8100 | "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS, |
| 8101 | pjsua_reconfigure_logging_doc |
| 8102 | }, |
| 8103 | { |
| 8104 | "logging_config_default", py_pjsua_logging_config_default, |
| 8105 | METH_VARARGS, pjsua_logging_config_default_doc |
| 8106 | }, |
| 8107 | { |
| 8108 | "config_default", py_pjsua_config_default, METH_VARARGS, |
| 8109 | pjsua_config_default_doc |
| 8110 | }, |
| 8111 | { |
| 8112 | "media_config_default", py_pjsua_media_config_default, METH_VARARGS, |
| 8113 | pjsua_media_config_default_doc |
| 8114 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8115 | |
| 8116 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8117 | { |
| 8118 | "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS, |
| 8119 | pjsua_msg_data_init_doc |
| 8120 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8121 | { |
| 8122 | "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS, |
| 8123 | pjsua_stun_config_default_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8124 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8125 | { |
| 8126 | "transport_config_default", py_pjsua_transport_config_default, |
| 8127 | METH_VARARGS,pjsua_transport_config_default_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8128 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8129 | { |
| 8130 | "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS, |
| 8131 | pjsua_normalize_stun_config_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8132 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8133 | |
| 8134 | { |
| 8135 | "transport_create", py_pjsua_transport_create, METH_VARARGS, |
| 8136 | pjsua_transport_create_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8137 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8138 | { |
| 8139 | "transport_register", py_pjsua_transport_register, METH_VARARGS, |
| 8140 | pjsua_transport_register_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8141 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8142 | { |
| 8143 | "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS, |
| 8144 | pjsua_enum_transports_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8145 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8146 | { |
| 8147 | "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS, |
| 8148 | pjsua_transport_get_info_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8149 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8150 | { |
| 8151 | "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS, |
| 8152 | pjsua_transport_set_enable_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8153 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8154 | { |
| 8155 | "transport_close", py_pjsua_transport_close, METH_VARARGS, |
| 8156 | pjsua_transport_close_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8157 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8158 | { |
| 8159 | "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS, |
| 8160 | pjsua_acc_config_default_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8161 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8162 | { |
| 8163 | "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS, |
| 8164 | pjsua_acc_get_count_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8165 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8166 | { |
| 8167 | "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS, |
| 8168 | pjsua_acc_is_valid_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8169 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8170 | { |
| 8171 | "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS, |
| 8172 | pjsua_acc_set_default_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8173 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8174 | { |
| 8175 | "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS, |
| 8176 | pjsua_acc_get_default_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8177 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8178 | { |
| 8179 | "acc_add", py_pjsua_acc_add, METH_VARARGS, |
| 8180 | pjsua_acc_add_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8181 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8182 | { |
| 8183 | "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS, |
| 8184 | pjsua_acc_add_local_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8185 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8186 | { |
| 8187 | "acc_del", py_pjsua_acc_del, METH_VARARGS, |
| 8188 | pjsua_acc_del_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8189 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8190 | { |
| 8191 | "acc_modify", py_pjsua_acc_modify, METH_VARARGS, |
| 8192 | pjsua_acc_modify_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8193 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8194 | { |
| 8195 | "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS, |
| 8196 | pjsua_acc_set_online_status_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8197 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8198 | { |
| 8199 | "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS, |
| 8200 | pjsua_acc_set_registration_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8201 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8202 | { |
| 8203 | "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS, |
| 8204 | pjsua_acc_get_info_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8205 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8206 | { |
| 8207 | "enum_accs", py_pjsua_enum_accs, METH_VARARGS, |
| 8208 | pjsua_enum_accs_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8209 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8210 | { |
| 8211 | "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, |
| 8212 | pjsua_acc_enum_info_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8213 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8214 | { |
| 8215 | "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS, |
| 8216 | pjsua_acc_find_for_outgoing_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8217 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8218 | { |
| 8219 | "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS, |
| 8220 | pjsua_acc_find_for_incoming_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8221 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8222 | { |
| 8223 | "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS, |
| 8224 | pjsua_acc_create_uac_contact_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8225 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8226 | { |
| 8227 | "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS, |
| 8228 | pjsua_acc_create_uas_contact_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8229 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8230 | { |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 8231 | "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS, |
| 8232 | pjsua_buddy_config_default_doc |
| 8233 | }, |
| 8234 | { |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8235 | "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS, |
| 8236 | pjsua_get_buddy_count_doc |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8237 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8238 | { |
| 8239 | "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS, |
| 8240 | pjsua_buddy_is_valid_doc |
| 8241 | }, |
| 8242 | { |
| 8243 | "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS, |
| 8244 | pjsua_enum_buddies_doc |
Fahris | 6f35cb8 | 2007-02-01 07:41:26 +0000 | [diff] [blame] | 8245 | }, |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8246 | { |
| 8247 | "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS, |
| 8248 | pjsua_buddy_get_info_doc |
| 8249 | }, |
| 8250 | { |
| 8251 | "buddy_add", py_pjsua_buddy_add, METH_VARARGS, |
| 8252 | pjsua_buddy_add_doc |
| 8253 | }, |
| 8254 | { |
| 8255 | "buddy_del", py_pjsua_buddy_del, METH_VARARGS, |
| 8256 | pjsua_buddy_del_doc |
| 8257 | }, |
| 8258 | { |
| 8259 | "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS, |
| 8260 | pjsua_buddy_subscribe_pres_doc |
| 8261 | }, |
| 8262 | { |
| 8263 | "pres_dump", py_pjsua_pres_dump, METH_VARARGS, |
| 8264 | pjsua_pres_dump_doc |
| 8265 | }, |
| 8266 | { |
| 8267 | "im_send", py_pjsua_im_send, METH_VARARGS, |
| 8268 | pjsua_im_send_doc |
| 8269 | }, |
| 8270 | { |
| 8271 | "im_typing", py_pjsua_im_typing, METH_VARARGS, |
| 8272 | pjsua_im_typing_doc |
| 8273 | }, |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8274 | { |
| 8275 | "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS, |
| 8276 | pjsua_conf_get_max_ports_doc |
| 8277 | }, |
| 8278 | { |
| 8279 | "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS, |
| 8280 | pjsua_conf_get_active_ports_doc |
| 8281 | }, |
| 8282 | { |
| 8283 | "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS, |
| 8284 | pjsua_enum_conf_ports_doc |
| 8285 | }, |
| 8286 | { |
| 8287 | "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS, |
| 8288 | pjsua_conf_get_port_info_doc |
| 8289 | }, |
| 8290 | { |
| 8291 | "conf_add_port", py_pjsua_conf_add_port, METH_VARARGS, |
| 8292 | pjsua_conf_add_port_doc |
| 8293 | }, |
| 8294 | { |
| 8295 | "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS, |
| 8296 | pjsua_conf_remove_port_doc |
| 8297 | }, |
| 8298 | { |
| 8299 | "conf_connect", py_pjsua_conf_connect, METH_VARARGS, |
| 8300 | pjsua_conf_connect_doc |
| 8301 | }, |
| 8302 | { |
| 8303 | "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS, |
| 8304 | pjsua_conf_disconnect_doc |
| 8305 | }, |
| 8306 | { |
| 8307 | "player_create", py_pjsua_player_create, METH_VARARGS, |
| 8308 | pjsua_player_create_doc |
| 8309 | }, |
| 8310 | { |
| 8311 | "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS, |
| 8312 | pjsua_player_get_conf_port_doc |
| 8313 | }, |
| 8314 | { |
| 8315 | "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS, |
| 8316 | pjsua_player_set_pos_doc |
| 8317 | }, |
| 8318 | { |
| 8319 | "player_destroy", py_pjsua_player_destroy, METH_VARARGS, |
| 8320 | pjsua_player_destroy_doc |
| 8321 | }, |
| 8322 | { |
| 8323 | "recorder_create", py_pjsua_recorder_create, METH_VARARGS, |
| 8324 | pjsua_recorder_create_doc |
| 8325 | }, |
| 8326 | { |
| 8327 | "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS, |
| 8328 | pjsua_recorder_get_conf_port_doc |
| 8329 | }, |
| 8330 | { |
| 8331 | "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS, |
| 8332 | pjsua_recorder_destroy_doc |
| 8333 | }, |
| 8334 | { |
| 8335 | "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS, |
| 8336 | pjsua_enum_snd_devs_doc |
| 8337 | }, |
Benny Prijono | ebdf877 | 2007-02-01 19:25:50 +0000 | [diff] [blame] | 8338 | { |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8339 | "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS, |
| 8340 | pjsua_get_snd_dev_doc |
Benny Prijono | ebdf877 | 2007-02-01 19:25:50 +0000 | [diff] [blame] | 8341 | }, |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8342 | { |
| 8343 | "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS, |
| 8344 | pjsua_set_snd_dev_doc |
| 8345 | }, |
| 8346 | { |
| 8347 | "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS, |
| 8348 | pjsua_set_null_snd_dev_doc |
| 8349 | }, |
| 8350 | { |
| 8351 | "set_no_snd_dev", py_pjsua_set_no_snd_dev, METH_VARARGS, |
| 8352 | pjsua_set_no_snd_dev_doc |
| 8353 | }, |
| 8354 | { |
| 8355 | "set_ec", py_pjsua_set_ec, METH_VARARGS, |
| 8356 | pjsua_set_ec_doc |
| 8357 | }, |
| 8358 | { |
| 8359 | "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS, |
| 8360 | pjsua_get_ec_tail_doc |
| 8361 | }, |
| 8362 | { |
| 8363 | "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS, |
| 8364 | pjsua_enum_codecs_doc |
| 8365 | }, |
| 8366 | { |
| 8367 | "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS, |
| 8368 | pjsua_codec_set_priority_doc |
| 8369 | }, |
| 8370 | { |
| 8371 | "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS, |
| 8372 | pjsua_codec_get_param_doc |
| 8373 | }, |
| 8374 | { |
| 8375 | "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS, |
| 8376 | pjsua_codec_set_param_doc |
| 8377 | }, |
| 8378 | { |
| 8379 | "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS, |
| 8380 | pjsua_call_get_max_count_doc |
| 8381 | }, |
| 8382 | { |
| 8383 | "call_get_count", py_pjsua_call_get_count, METH_VARARGS, |
| 8384 | pjsua_call_get_count_doc |
| 8385 | }, |
| 8386 | { |
| 8387 | "enum_calls", py_pjsua_enum_calls, METH_VARARGS, |
| 8388 | pjsua_enum_calls_doc |
| 8389 | }, |
| 8390 | { |
| 8391 | "call_make_call", py_pjsua_call_make_call, METH_VARARGS, |
| 8392 | pjsua_call_make_call_doc |
| 8393 | }, |
| 8394 | { |
| 8395 | "call_is_active", py_pjsua_call_is_active, METH_VARARGS, |
| 8396 | pjsua_call_is_active_doc |
| 8397 | }, |
| 8398 | { |
| 8399 | "call_has_media", py_pjsua_call_has_media, METH_VARARGS, |
| 8400 | pjsua_call_has_media_doc |
| 8401 | }, |
| 8402 | { |
| 8403 | "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS, |
| 8404 | pjsua_call_get_conf_port_doc |
| 8405 | }, |
| 8406 | { |
| 8407 | "call_get_info", py_pjsua_call_get_info, METH_VARARGS, |
| 8408 | pjsua_call_get_info_doc |
| 8409 | }, |
| 8410 | { |
| 8411 | "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS, |
| 8412 | pjsua_call_set_user_data_doc |
| 8413 | }, |
| 8414 | { |
| 8415 | "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS, |
| 8416 | pjsua_call_get_user_data_doc |
| 8417 | }, |
| 8418 | { |
| 8419 | "call_answer", py_pjsua_call_answer, METH_VARARGS, |
| 8420 | pjsua_call_answer_doc |
| 8421 | }, |
| 8422 | { |
| 8423 | "call_hangup", py_pjsua_call_hangup, METH_VARARGS, |
| 8424 | pjsua_call_hangup_doc |
| 8425 | }, |
| 8426 | { |
| 8427 | "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS, |
| 8428 | pjsua_call_set_hold_doc |
| 8429 | }, |
| 8430 | { |
| 8431 | "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS, |
| 8432 | pjsua_call_reinvite_doc |
| 8433 | }, |
| 8434 | { |
| 8435 | "call_xfer", py_pjsua_call_xfer, METH_VARARGS, |
| 8436 | pjsua_call_xfer_doc |
| 8437 | }, |
| 8438 | { |
| 8439 | "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS, |
| 8440 | pjsua_call_xfer_replaces_doc |
| 8441 | }, |
| 8442 | { |
| 8443 | "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS, |
| 8444 | pjsua_call_dial_dtmf_doc |
| 8445 | }, |
| 8446 | { |
| 8447 | "call_send_im", py_pjsua_call_send_im, METH_VARARGS, |
| 8448 | pjsua_call_send_im_doc |
| 8449 | }, |
| 8450 | { |
| 8451 | "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS, |
| 8452 | pjsua_call_send_typing_ind_doc |
| 8453 | }, |
| 8454 | { |
| 8455 | "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS, |
| 8456 | pjsua_call_hangup_all_doc |
| 8457 | }, |
| 8458 | { |
| 8459 | "call_dump", py_pjsua_call_dump, METH_VARARGS, |
| 8460 | pjsua_call_dump_doc |
| 8461 | }, |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 8462 | { |
| 8463 | "dump", py_pjsua_dump, METH_VARARGS, "Dump application state" |
| 8464 | }, |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8465 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8466 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8467 | {NULL, NULL} /* end of function list */ |
| 8468 | }; |
| 8469 | |
| 8470 | |
| 8471 | |
| 8472 | /* |
| 8473 | * Mapping C structs from and to Python objects & initializing object |
| 8474 | */ |
| 8475 | DL_EXPORT(void) |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 8476 | initpy_pjsua(void) |
| 8477 | { |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8478 | PyObject* m = NULL; |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8479 | #define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name) |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8480 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8481 | |
Benny Prijono | da275f6 | 2007-02-18 23:49:14 +0000 | [diff] [blame^] | 8482 | PyEval_InitThreads(); |
| 8483 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8484 | if (PyType_Ready(&callback_Type) < 0) |
| 8485 | return; |
| 8486 | if (PyType_Ready(&config_Type) < 0) |
| 8487 | return; |
| 8488 | if (PyType_Ready(&logging_config_Type) < 0) |
| 8489 | return; |
| 8490 | if (PyType_Ready(&msg_data_Type) < 0) |
| 8491 | return; |
| 8492 | media_config_Type.tp_new = PyType_GenericNew; |
| 8493 | if (PyType_Ready(&media_config_Type) < 0) |
| 8494 | return; |
| 8495 | pjsip_event_Type.tp_new = PyType_GenericNew; |
| 8496 | if (PyType_Ready(&pjsip_event_Type) < 0) |
| 8497 | return; |
| 8498 | pjsip_rx_data_Type.tp_new = PyType_GenericNew; |
| 8499 | if (PyType_Ready(&pjsip_rx_data_Type) < 0) |
| 8500 | return; |
| 8501 | pj_pool_Type.tp_new = PyType_GenericNew; |
| 8502 | if (PyType_Ready(&pj_pool_Type) < 0) |
| 8503 | return; |
| 8504 | pjsip_endpoint_Type.tp_new = PyType_GenericNew; |
| 8505 | if (PyType_Ready(&pjsip_endpoint_Type) < 0) |
| 8506 | return; |
| 8507 | pjmedia_endpt_Type.tp_new = PyType_GenericNew; |
| 8508 | if (PyType_Ready(&pjmedia_endpt_Type) < 0) |
| 8509 | return; |
| 8510 | pj_pool_factory_Type.tp_new = PyType_GenericNew; |
| 8511 | if (PyType_Ready(&pj_pool_factory_Type) < 0) |
| 8512 | return; |
| 8513 | pjsip_cred_info_Type.tp_new = PyType_GenericNew; |
| 8514 | if (PyType_Ready(&pjsip_cred_info_Type) < 0) |
| 8515 | return; |
| 8516 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8517 | /* LIB TRANSPORT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8518 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8519 | if (PyType_Ready(&stun_config_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8520 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8521 | if (PyType_Ready(&transport_config_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8522 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8523 | if (PyType_Ready(&sockaddr_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8524 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8525 | if (PyType_Ready(&host_port_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8526 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8527 | |
| 8528 | if (PyType_Ready(&transport_info_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8529 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8530 | |
| 8531 | pjsip_transport_Type.tp_new = PyType_GenericNew; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8532 | if (PyType_Ready(&pjsip_transport_Type) < 0) |
| 8533 | return; |
| 8534 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8535 | /* END OF LIB TRANSPORT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8536 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8537 | /* LIB ACCOUNT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8538 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8539 | |
| 8540 | if (PyType_Ready(&acc_config_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8541 | return; |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8542 | if (PyType_Ready(&acc_info_Type) < 0) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8543 | return; |
| 8544 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8545 | /* END OF LIB ACCOUNT */ |
| 8546 | |
| 8547 | /* LIB BUDDY */ |
| 8548 | |
| 8549 | if (PyType_Ready(&buddy_config_Type) < 0) |
| 8550 | return; |
| 8551 | if (PyType_Ready(&buddy_info_Type) < 0) |
| 8552 | return; |
| 8553 | |
| 8554 | /* END OF LIB BUDDY */ |
| 8555 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8556 | /* LIB MEDIA */ |
| 8557 | |
| 8558 | if (PyType_Ready(&codec_info_Type) < 0) |
| 8559 | return; |
| 8560 | |
| 8561 | if (PyType_Ready(&conf_port_info_Type) < 0) |
| 8562 | return; |
| 8563 | |
| 8564 | pjmedia_port_Type.tp_new = PyType_GenericNew; |
| 8565 | if (PyType_Ready(&pjmedia_port_Type) < 0) |
| 8566 | return; |
| 8567 | |
| 8568 | if (PyType_Ready(&pjmedia_snd_dev_info_Type) < 0) |
| 8569 | return; |
| 8570 | |
| 8571 | pjmedia_codec_param_info_Type.tp_new = PyType_GenericNew; |
| 8572 | if (PyType_Ready(&pjmedia_codec_param_info_Type) < 0) |
| 8573 | return; |
| 8574 | pjmedia_codec_param_setting_Type.tp_new = PyType_GenericNew; |
| 8575 | if (PyType_Ready(&pjmedia_codec_param_setting_Type) < 0) |
| 8576 | return; |
| 8577 | |
| 8578 | if (PyType_Ready(&pjmedia_codec_param_Type) < 0) |
| 8579 | return; |
| 8580 | |
| 8581 | /* END OF LIB MEDIA */ |
| 8582 | |
| 8583 | /* LIB CALL */ |
| 8584 | |
| 8585 | pj_time_val_Type.tp_new = PyType_GenericNew; |
| 8586 | if (PyType_Ready(&pj_time_val_Type) < 0) |
| 8587 | return; |
| 8588 | |
| 8589 | if (PyType_Ready(&call_info_Type) < 0) |
| 8590 | return; |
| 8591 | |
| 8592 | /* END OF LIB CALL */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8593 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8594 | m = Py_InitModule3( |
| 8595 | "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python" |
| 8596 | ); |
| 8597 | |
| 8598 | Py_INCREF(&callback_Type); |
| 8599 | PyModule_AddObject(m, "Callback", (PyObject *)&callback_Type); |
| 8600 | |
| 8601 | Py_INCREF(&config_Type); |
| 8602 | PyModule_AddObject(m, "Config", (PyObject *)&config_Type); |
| 8603 | |
| 8604 | Py_INCREF(&media_config_Type); |
| 8605 | PyModule_AddObject(m, "Media_Config", (PyObject *)&media_config_Type); |
| 8606 | |
| 8607 | Py_INCREF(&logging_config_Type); |
| 8608 | PyModule_AddObject(m, "Logging_Config", (PyObject *)&logging_config_Type); |
| 8609 | |
| 8610 | Py_INCREF(&msg_data_Type); |
| 8611 | PyModule_AddObject(m, "Msg_Data", (PyObject *)&msg_data_Type); |
| 8612 | |
| 8613 | Py_INCREF(&pjsip_event_Type); |
| 8614 | PyModule_AddObject(m, "PJSIP_Event", (PyObject *)&pjsip_event_Type); |
| 8615 | |
| 8616 | Py_INCREF(&pjsip_rx_data_Type); |
| 8617 | PyModule_AddObject(m, "PJSIP_RX_Data", (PyObject *)&pjsip_rx_data_Type); |
| 8618 | |
| 8619 | Py_INCREF(&pj_pool_Type); |
| 8620 | PyModule_AddObject(m, "PJ_Pool", (PyObject *)&pj_pool_Type); |
| 8621 | |
| 8622 | Py_INCREF(&pjsip_endpoint_Type); |
| 8623 | PyModule_AddObject(m, "PJSIP_Endpoint", (PyObject *)&pjsip_endpoint_Type); |
| 8624 | |
| 8625 | Py_INCREF(&pjmedia_endpt_Type); |
| 8626 | PyModule_AddObject(m, "PJMedia_Endpt", (PyObject *)&pjmedia_endpt_Type); |
| 8627 | |
| 8628 | Py_INCREF(&pj_pool_factory_Type); |
| 8629 | PyModule_AddObject( |
| 8630 | m, "PJ_Pool_Factory", (PyObject *)&pj_pool_factory_Type |
| 8631 | ); |
| 8632 | |
| 8633 | Py_INCREF(&pjsip_cred_info_Type); |
| 8634 | PyModule_AddObject(m, "PJSIP_Cred_Info", |
| 8635 | (PyObject *)&pjsip_cred_info_Type |
| 8636 | ); |
| 8637 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8638 | /* LIB TRANSPORT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8639 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8640 | Py_INCREF(&stun_config_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8641 | PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8642 | Py_INCREF(&transport_config_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8643 | PyModule_AddObject |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8644 | (m, "Transport_Config", (PyObject *)&transport_config_Type); |
| 8645 | Py_INCREF(&sockaddr_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8646 | PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8647 | Py_INCREF(&host_port_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8648 | PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8649 | |
| 8650 | Py_INCREF(&transport_info_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8651 | PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8652 | |
| 8653 | Py_INCREF(&pjsip_transport_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8654 | PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type); |
| 8655 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8656 | /* END OF LIB TRANSPORT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8657 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8658 | /* LIB ACCOUNT */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8659 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8660 | |
| 8661 | Py_INCREF(&acc_config_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8662 | PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type); |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8663 | Py_INCREF(&acc_info_Type); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 8664 | PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type); |
| 8665 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8666 | /* END OF LIB ACCOUNT */ |
| 8667 | |
| 8668 | /* LIB BUDDY */ |
| 8669 | |
| 8670 | Py_INCREF(&buddy_config_Type); |
| 8671 | PyModule_AddObject(m, "Buddy_Config", (PyObject *)&buddy_config_Type); |
| 8672 | Py_INCREF(&buddy_info_Type); |
| 8673 | PyModule_AddObject(m, "Buddy_Info", (PyObject *)&buddy_info_Type); |
| 8674 | |
| 8675 | /* END OF LIB BUDDY */ |
| 8676 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8677 | /* LIB MEDIA */ |
| 8678 | |
| 8679 | Py_INCREF(&codec_info_Type); |
| 8680 | PyModule_AddObject(m, "Codec_Info", (PyObject *)&codec_info_Type); |
| 8681 | Py_INCREF(&conf_port_info_Type); |
| 8682 | PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&conf_port_info_Type); |
| 8683 | Py_INCREF(&pjmedia_port_Type); |
| 8684 | PyModule_AddObject(m, "PJMedia_Port", (PyObject *)&pjmedia_port_Type); |
| 8685 | Py_INCREF(&pjmedia_snd_dev_info_Type); |
| 8686 | PyModule_AddObject(m, "PJMedia_Snd_Dev_Info", |
| 8687 | (PyObject *)&pjmedia_snd_dev_info_Type); |
| 8688 | Py_INCREF(&pjmedia_codec_param_info_Type); |
| 8689 | PyModule_AddObject(m, "PJMedia_Codec_Param_Info", |
| 8690 | (PyObject *)&pjmedia_codec_param_info_Type); |
| 8691 | Py_INCREF(&pjmedia_codec_param_setting_Type); |
| 8692 | PyModule_AddObject(m, "PJMedia_Codec_Param_Setting", |
| 8693 | (PyObject *)&pjmedia_codec_param_setting_Type); |
| 8694 | Py_INCREF(&pjmedia_codec_param_Type); |
| 8695 | PyModule_AddObject(m, "PJMedia_Codec_Param", |
| 8696 | (PyObject *)&pjmedia_codec_param_Type); |
| 8697 | |
| 8698 | /* END OF LIB MEDIA */ |
| 8699 | |
| 8700 | /* LIB CALL */ |
| 8701 | |
| 8702 | Py_INCREF(&pj_time_val_Type); |
| 8703 | PyModule_AddObject(m, "PJ_Time_Val", (PyObject *)&pj_time_val_Type); |
| 8704 | |
| 8705 | Py_INCREF(&call_info_Type); |
| 8706 | PyModule_AddObject(m, "Call_Info", (PyObject *)&call_info_Type); |
| 8707 | |
| 8708 | /* END OF LIB CALL */ |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 8709 | |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8710 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8711 | /* |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8712 | * Add various constants. |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8713 | */ |
Benny Prijono | dc30870 | 2006-12-09 00:39:42 +0000 | [diff] [blame] | 8714 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8715 | /* Call states */ |
| 8716 | ADD_CONSTANT(m, PJSIP_INV_STATE_NULL); |
| 8717 | ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING); |
| 8718 | ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING); |
| 8719 | ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY); |
| 8720 | ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING); |
| 8721 | ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED); |
| 8722 | ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8723 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8724 | /* Call media status (enum pjsua_call_media_status) */ |
| 8725 | ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE); |
| 8726 | ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE); |
| 8727 | ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD); |
| 8728 | ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8729 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8730 | /* Buddy status */ |
| 8731 | ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN); |
| 8732 | ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE); |
| 8733 | ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8734 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8735 | /* PJSIP transport types (enum pjsip_transport_type_e) */ |
| 8736 | ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED); |
| 8737 | ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP); |
| 8738 | ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP); |
| 8739 | ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS); |
| 8740 | ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP); |
| 8741 | ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP); |
| 8742 | ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8743 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8744 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8745 | /* Invalid IDs */ |
| 8746 | ADD_CONSTANT(m, PJSUA_INVALID_ID); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8747 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8748 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8749 | /* Various compile time constants */ |
| 8750 | ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES); |
| 8751 | ADD_CONSTANT(m, PJSUA_MAX_ACC); |
| 8752 | ADD_CONSTANT(m, PJSUA_REG_INTERVAL); |
| 8753 | ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION); |
| 8754 | ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY); |
| 8755 | ADD_CONSTANT(m, PJSUA_MAX_BUDDIES); |
| 8756 | ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS); |
| 8757 | ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE); |
| 8758 | ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY); |
| 8759 | ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE); |
| 8760 | ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN); |
| 8761 | ADD_CONSTANT(m, PJSUA_MAX_CALLS); |
| 8762 | ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES); |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8763 | |
Fahris | dcf8fa4 | 2006-12-28 03:13:48 +0000 | [diff] [blame] | 8764 | |
Benny Prijono | aa28604 | 2007-02-03 17:23:22 +0000 | [diff] [blame] | 8765 | #undef ADD_CONSTANT |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 8766 | } |