Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 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 | */ |
| 19 | #include "_pjsua.h" |
| 20 | |
| 21 | #define THIS_FILE "main.c" |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 22 | #define POOL_SIZE 512 |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 23 | #define SND_DEV_NUM 64 |
| 24 | #define SND_NAME_LEN 64 |
| 25 | |
| 26 | /* LIB BASE */ |
| 27 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 28 | static PyObject* g_obj_log_cb; |
| 29 | static long g_thread_id; |
| 30 | static struct py_thread_desc |
| 31 | { |
| 32 | struct py_thread_desc *next; |
| 33 | pj_thread_desc desc; |
| 34 | } *py_thread_desc; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 35 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 36 | /* |
| 37 | * The global callback object. |
| 38 | */ |
| 39 | static PyObj_pjsua_callback * g_obj_callback; |
| 40 | |
| 41 | /* Set this to 1 if all threads are created by Python */ |
| 42 | #define NO_PJSIP_THREAD 1 |
| 43 | |
| 44 | #if NO_PJSIP_THREAD |
| 45 | # define ENTER_PYTHON() |
| 46 | # define LEAVE_PYTHON() |
| 47 | #else |
| 48 | # define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure() |
| 49 | # define LEAVE_PYTHON() PyGILState_Release(state) |
| 50 | #endif |
| 51 | |
| 52 | |
| 53 | static void clear_py_thread_desc(void) |
| 54 | { |
| 55 | while (py_thread_desc) { |
| 56 | struct py_thread_desc *next = py_thread_desc->next; |
| 57 | free(py_thread_desc); |
| 58 | py_thread_desc = next; |
| 59 | } |
| 60 | } |
| 61 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * cb_log_cb |
| 65 | * declares method for reconfiguring logging process for callback struct |
| 66 | */ |
| 67 | static void cb_log_cb(int level, const char *data, int len) |
| 68 | { |
| 69 | |
| 70 | /* Ignore if this callback is called from alien thread context, |
| 71 | * or otherwise it will crash Python. |
| 72 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 73 | if (pj_thread_local_get(g_thread_id) == 0) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 74 | return; |
| 75 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 76 | if (PyCallable_Check(g_obj_log_cb)) { |
| 77 | PyObject *param_data; |
| 78 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 79 | ENTER_PYTHON(); |
| 80 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 81 | param_data = PyString_FromStringAndSize(data, len); |
| 82 | |
| 83 | PyObject_CallFunction( |
| 84 | g_obj_log_cb, |
| 85 | "iOi", |
| 86 | level, |
| 87 | param_data, |
| 88 | len, |
| 89 | NULL |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 90 | ); |
| 91 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 92 | Py_DECREF(param_data); |
| 93 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 94 | LEAVE_PYTHON(); |
| 95 | } |
| 96 | } |
| 97 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 98 | /* |
| 99 | * cb_on_call_state |
| 100 | * declares method on_call_state for callback struct |
| 101 | */ |
| 102 | static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e) |
| 103 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 104 | PJ_UNUSED_ARG(e); |
| 105 | |
| 106 | if (PyCallable_Check(g_obj_callback->on_call_state)) { |
| 107 | PyObject * obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 108 | |
| 109 | ENTER_PYTHON(); |
| 110 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 111 | obj = Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 112 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 113 | PyObject_CallFunction( |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 114 | g_obj_callback->on_call_state, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 115 | "iO", |
| 116 | call_id, |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 117 | obj, |
| 118 | NULL |
| 119 | ); |
| 120 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 121 | Py_DECREF(obj); |
| 122 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 123 | LEAVE_PYTHON(); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /* |
| 129 | * cb_on_incoming_call |
| 130 | * declares method on_incoming_call for callback struct |
| 131 | */ |
| 132 | static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, |
| 133 | pjsip_rx_data *rdata) |
| 134 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 135 | PJ_UNUSED_ARG(rdata); |
| 136 | |
| 137 | if (PyCallable_Check(g_obj_callback->on_incoming_call)) { |
| 138 | PyObject *obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 139 | |
| 140 | ENTER_PYTHON(); |
| 141 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 142 | obj = Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 143 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 144 | PyObject_CallFunction( |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 145 | g_obj_callback->on_incoming_call, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 146 | "iiO", |
| 147 | acc_id, |
| 148 | call_id, |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 149 | obj, |
| 150 | NULL |
| 151 | ); |
| 152 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 153 | Py_DECREF(obj); |
| 154 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 155 | LEAVE_PYTHON(); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /* |
| 161 | * cb_on_call_media_state |
| 162 | * declares method on_call_media_state for callback struct |
| 163 | */ |
| 164 | static void cb_on_call_media_state(pjsua_call_id call_id) |
| 165 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 166 | if (PyCallable_Check(g_obj_callback->on_call_media_state)) { |
| 167 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 168 | ENTER_PYTHON(); |
| 169 | |
| 170 | PyObject_CallFunction( |
| 171 | g_obj_callback->on_call_media_state, |
| 172 | "i", |
| 173 | call_id, |
| 174 | NULL |
| 175 | ); |
| 176 | |
| 177 | LEAVE_PYTHON(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /* |
| 183 | * cb_on_dtmf_digit() |
| 184 | * Callback from PJSUA-LIB on receiving DTMF digit |
| 185 | */ |
| 186 | static void cb_on_dtmf_digit(pjsua_call_id call_id, int digit) |
| 187 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 188 | if (PyCallable_Check(g_obj_callback->on_dtmf_digit)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 189 | char digit_str[10]; |
| 190 | |
Benny Prijono | 876a2ae | 2008-08-18 11:07:58 +0000 | [diff] [blame] | 191 | PyGILState_STATE state = PyGILState_Ensure(); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 192 | |
| 193 | pj_ansi_snprintf(digit_str, sizeof(digit_str), "%c", digit); |
| 194 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 195 | PyObject_CallFunction( |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 196 | g_obj_callback->on_dtmf_digit, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 197 | "is", |
| 198 | call_id, |
| 199 | digit_str, |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 200 | NULL |
| 201 | ); |
| 202 | |
Benny Prijono | 876a2ae | 2008-08-18 11:07:58 +0000 | [diff] [blame] | 203 | PyGILState_Release(state); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /* |
| 209 | * Notify application on call being transfered. |
| 210 | * !modified @061206 |
| 211 | */ |
| 212 | static void cb_on_call_transfer_request(pjsua_call_id call_id, |
| 213 | const pj_str_t *dst, |
| 214 | pjsip_status_code *code) |
| 215 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 216 | if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) { |
| 217 | PyObject *ret, *param_dst; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 218 | int cd; |
| 219 | |
| 220 | ENTER_PYTHON(); |
| 221 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 222 | param_dst = PyString_FromPJ(dst); |
| 223 | |
| 224 | ret = PyObject_CallFunction( |
| 225 | g_obj_callback->on_call_transfer_request, |
| 226 | "iOi", |
| 227 | call_id, |
| 228 | param_dst, |
| 229 | *code, |
| 230 | NULL |
| 231 | ); |
| 232 | |
| 233 | Py_DECREF(param_dst); |
| 234 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 235 | if (ret != NULL) { |
| 236 | if (ret != Py_None) { |
| 237 | if (PyArg_Parse(ret,"i",&cd)) { |
| 238 | *code = cd; |
| 239 | } |
| 240 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 241 | Py_DECREF(ret); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | LEAVE_PYTHON(); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /* |
| 250 | * Notify application of the status of previously sent call |
| 251 | * transfer request. Application can monitor the status of the |
| 252 | * call transfer request, for example to decide whether to |
| 253 | * terminate existing call. |
| 254 | * !modified @061206 |
| 255 | */ |
| 256 | static void cb_on_call_transfer_status( pjsua_call_id call_id, |
| 257 | int status_code, |
| 258 | const pj_str_t *status_text, |
| 259 | pj_bool_t final, |
| 260 | pj_bool_t *p_cont) |
| 261 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 262 | if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) { |
| 263 | PyObject *ret, *param_reason; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 264 | |
| 265 | ENTER_PYTHON(); |
| 266 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 267 | param_reason = PyString_FromPJ(status_text); |
| 268 | |
| 269 | ret = PyObject_CallFunction( |
| 270 | g_obj_callback->on_call_transfer_status, |
| 271 | "iiOii", |
| 272 | call_id, |
| 273 | status_code, |
| 274 | param_reason, |
| 275 | final, |
| 276 | *p_cont, |
| 277 | NULL |
| 278 | ); |
| 279 | |
| 280 | Py_DECREF(param_reason); |
| 281 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 282 | if (ret != NULL) { |
| 283 | if (ret != Py_None) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 284 | int cnt; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 285 | if (PyArg_Parse(ret,"i",&cnt)) { |
| 286 | *p_cont = cnt; |
| 287 | } |
| 288 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 289 | Py_DECREF(ret); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | LEAVE_PYTHON(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /* |
| 298 | * Notify application about incoming INVITE with Replaces header. |
| 299 | * Application may reject the request by setting non-2xx code. |
| 300 | * !modified @061206 |
| 301 | */ |
| 302 | static void cb_on_call_replace_request( pjsua_call_id call_id, |
| 303 | pjsip_rx_data *rdata, |
| 304 | int *st_code, |
| 305 | pj_str_t *st_text) |
| 306 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 307 | PJ_UNUSED_ARG(rdata); |
| 308 | |
| 309 | if (PyCallable_Check(g_obj_callback->on_call_replace_request)) { |
| 310 | PyObject *ret, *param_reason, *param_rdata; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 311 | int cd; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 312 | |
| 313 | ENTER_PYTHON(); |
| 314 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 315 | param_reason = PyString_FromPJ(st_text); |
| 316 | param_rdata = Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 317 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 318 | ret = PyObject_CallFunction( |
| 319 | g_obj_callback->on_call_replace_request, |
| 320 | "iOiO", |
| 321 | call_id, |
| 322 | param_rdata, |
| 323 | *st_code, |
| 324 | param_reason, |
| 325 | NULL |
| 326 | ); |
| 327 | |
| 328 | Py_DECREF(param_rdata); |
| 329 | Py_DECREF(param_reason); |
| 330 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 331 | if (ret != NULL) { |
| 332 | if (ret != Py_None) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 333 | PyObject * txt; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 334 | if (PyArg_ParseTuple(ret,"iO",&cd, &txt)) { |
| 335 | *st_code = cd; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 336 | *st_text = PyString_ToPJ(txt); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 339 | Py_DECREF(ret); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | LEAVE_PYTHON(); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /* |
| 348 | * Notify application that an existing call has been replaced with |
| 349 | * a new call. This happens when PJSUA-API receives incoming INVITE |
| 350 | * request with Replaces header. |
| 351 | */ |
| 352 | static void cb_on_call_replaced(pjsua_call_id old_call_id, |
| 353 | pjsua_call_id new_call_id) |
| 354 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 355 | if (PyCallable_Check(g_obj_callback->on_call_replaced)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 356 | ENTER_PYTHON(); |
| 357 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 358 | PyObject_CallFunction( |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 359 | g_obj_callback->on_call_replaced, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 360 | "ii", |
| 361 | old_call_id, |
| 362 | new_call_id, |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 363 | NULL |
| 364 | ); |
| 365 | |
| 366 | LEAVE_PYTHON(); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /* |
| 372 | * cb_on_reg_state |
| 373 | * declares method on_reg_state for callback struct |
| 374 | */ |
| 375 | static void cb_on_reg_state(pjsua_acc_id acc_id) |
| 376 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 377 | if (PyCallable_Check(g_obj_callback->on_reg_state)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 378 | ENTER_PYTHON(); |
| 379 | |
| 380 | PyObject_CallFunction( |
| 381 | g_obj_callback->on_reg_state, |
| 382 | "i", |
| 383 | acc_id, |
| 384 | NULL |
| 385 | ); |
| 386 | |
| 387 | LEAVE_PYTHON(); |
| 388 | } |
| 389 | } |
| 390 | |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 391 | /* |
| 392 | * cb_on_incoming_subscribe |
| 393 | */ |
| 394 | static void cb_on_incoming_subscribe( pjsua_acc_id acc_id, |
| 395 | pjsua_srv_pres *srv_pres, |
| 396 | pjsua_buddy_id buddy_id, |
| 397 | const pj_str_t *from, |
| 398 | pjsip_rx_data *rdata, |
| 399 | pjsip_status_code *code, |
| 400 | pj_str_t *reason, |
| 401 | pjsua_msg_data *msg_data) |
| 402 | { |
| 403 | static char reason_buf[64]; |
| 404 | |
| 405 | PJ_UNUSED_ARG(rdata); |
| 406 | PJ_UNUSED_ARG(msg_data); |
| 407 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 408 | if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) { |
| 409 | PyObject *ret, *param_from, *param_contact, *param_srv_pres; |
| 410 | pjsip_contact_hdr *contact_hdr; |
| 411 | pj_pool_t *pool = NULL; |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 412 | |
| 413 | ENTER_PYTHON(); |
| 414 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 415 | param_from = PyString_FromPJ(from); |
| 416 | param_srv_pres = PyLong_FromLong((long)srv_pres); |
| 417 | |
| 418 | contact_hdr = (pjsip_contact_hdr*) |
| 419 | pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, |
| 420 | NULL); |
| 421 | if (contact_hdr) { |
| 422 | char *contact; |
| 423 | int len; |
| 424 | |
| 425 | pool = pjsua_pool_create("pytmp", 512, 512); |
| 426 | contact = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE+1); |
| 427 | len = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, |
| 428 | contact, PJSIP_MAX_URL_SIZE); |
| 429 | if (len < 1) |
| 430 | len = 0; |
| 431 | contact[len] = '\0'; |
| 432 | |
| 433 | param_contact = PyString_FromStringAndSize(contact, len); |
| 434 | } else { |
| 435 | param_contact = Py_BuildValue(""); |
| 436 | } |
| 437 | |
| 438 | ret = PyObject_CallFunction( |
| 439 | g_obj_callback->on_incoming_subscribe, |
| 440 | "iiOOO", |
| 441 | acc_id, |
| 442 | buddy_id, |
| 443 | param_from, |
| 444 | param_contact, |
| 445 | param_srv_pres, |
| 446 | NULL |
| 447 | ); |
| 448 | |
| 449 | if (pool) |
| 450 | pj_pool_release(pool); |
| 451 | |
| 452 | Py_DECREF(param_from); |
| 453 | Py_DECREF(param_contact); |
| 454 | Py_DECREF(param_srv_pres); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 455 | |
| 456 | if (ret && PyTuple_Check(ret)) { |
| 457 | if (PyTuple_Size(ret) >= 1) |
| 458 | *code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0)); |
| 459 | if (PyTuple_Size(ret) >= 2) { |
| 460 | if (PyTuple_GetItem(ret, 1) != Py_None) { |
| 461 | pj_str_t tmp; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 462 | tmp = PyString_ToPJ(PyTuple_GetItem(ret, 1)); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 463 | reason->ptr = reason_buf; |
| 464 | pj_strncpy(reason, &tmp, sizeof(reason_buf)); |
| 465 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 466 | reason->slen = 0; |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 469 | Py_XDECREF(ret); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 470 | } else if (ret) { |
| 471 | Py_XDECREF(ret); |
| 472 | } |
| 473 | |
| 474 | LEAVE_PYTHON(); |
| 475 | } |
| 476 | } |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 477 | |
| 478 | /* |
| 479 | * cb_on_buddy_state |
| 480 | * declares method on_buddy state for callback struct |
| 481 | */ |
| 482 | static void cb_on_buddy_state(pjsua_buddy_id buddy_id) |
| 483 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 484 | if (PyCallable_Check(g_obj_callback->on_buddy_state)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 485 | ENTER_PYTHON(); |
| 486 | |
| 487 | PyObject_CallFunction( |
| 488 | g_obj_callback->on_buddy_state, |
| 489 | "i", |
| 490 | buddy_id, |
| 491 | NULL |
| 492 | ); |
| 493 | |
| 494 | LEAVE_PYTHON(); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * cb_on_pager |
| 500 | * declares method on_pager for callback struct |
| 501 | */ |
| 502 | static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from, |
| 503 | const pj_str_t *to, const pj_str_t *contact, |
| 504 | const pj_str_t *mime_type, const pj_str_t *body, |
| 505 | pjsip_rx_data *rdata, pjsua_acc_id acc_id) |
| 506 | { |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 507 | PJ_UNUSED_ARG(rdata); |
| 508 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 509 | if (PyCallable_Check(g_obj_callback->on_pager)) { |
| 510 | PyObject *param_from, *param_to, *param_contact, *param_mime_type, |
| 511 | *param_body; |
| 512 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 513 | ENTER_PYTHON(); |
| 514 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 515 | param_from = PyString_FromPJ(from); |
| 516 | param_to = PyString_FromPJ(to); |
| 517 | param_contact = PyString_FromPJ(contact); |
| 518 | param_mime_type = PyString_FromPJ(mime_type); |
| 519 | param_body = PyString_FromPJ(body); |
| 520 | |
| 521 | PyObject_CallFunction( |
| 522 | g_obj_callback->on_pager, |
| 523 | "iOOOOOi", |
| 524 | call_id, |
| 525 | param_from, |
| 526 | param_to, |
| 527 | param_contact, |
| 528 | param_mime_type, |
| 529 | param_body, |
| 530 | acc_id, |
| 531 | NULL |
| 532 | ); |
| 533 | |
| 534 | Py_DECREF(param_body); |
| 535 | Py_DECREF(param_mime_type); |
| 536 | Py_DECREF(param_contact); |
| 537 | Py_DECREF(param_to); |
| 538 | Py_DECREF(param_from); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 539 | |
| 540 | LEAVE_PYTHON(); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | |
| 545 | /* |
| 546 | * cb_on_pager_status |
| 547 | * declares method on_pager_status for callback struct |
| 548 | */ |
| 549 | static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to, |
| 550 | const pj_str_t *body, void *user_data, |
| 551 | pjsip_status_code status, |
| 552 | const pj_str_t *reason, |
| 553 | pjsip_tx_data *tdata, |
| 554 | pjsip_rx_data *rdata, |
| 555 | pjsua_acc_id acc_id) |
| 556 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 557 | if (PyCallable_Check(g_obj_callback->on_pager)) { |
| 558 | PyObject *param_call_id, *param_to, *param_body, |
| 559 | *param_user_data, *param_status, *param_reason, |
| 560 | *param_acc_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 561 | |
| 562 | ENTER_PYTHON(); |
| 563 | |
| 564 | PJ_UNUSED_ARG(tdata); |
| 565 | PJ_UNUSED_ARG(rdata); |
| 566 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 567 | PyObject_CallFunctionObjArgs( |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 568 | g_obj_callback->on_pager_status, |
| 569 | param_call_id = Py_BuildValue("i",call_id), |
| 570 | param_to = PyString_FromPJ(to), |
| 571 | param_body = PyString_FromPJ(body), |
| 572 | param_user_data = Py_BuildValue("i", user_data), |
| 573 | param_status = Py_BuildValue("i",status), |
| 574 | param_reason = PyString_FromPJ(reason), |
| 575 | param_acc_id = Py_BuildValue("i",acc_id), |
| 576 | NULL |
| 577 | ); |
| 578 | |
| 579 | Py_DECREF(param_call_id); |
| 580 | Py_DECREF(param_to); |
| 581 | Py_DECREF(param_body); |
| 582 | Py_DECREF(param_user_data); |
| 583 | Py_DECREF(param_status); |
| 584 | Py_DECREF(param_reason); |
| 585 | Py_DECREF(param_acc_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 586 | |
| 587 | LEAVE_PYTHON(); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | |
| 592 | /* |
| 593 | * cb_on_typing |
| 594 | * declares method on_typing for callback struct |
| 595 | */ |
| 596 | static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from, |
| 597 | const pj_str_t *to, const pj_str_t *contact, |
| 598 | pj_bool_t is_typing, pjsip_rx_data *rdata, |
| 599 | pjsua_acc_id acc_id) |
| 600 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 601 | if (PyCallable_Check(g_obj_callback->on_typing)) { |
| 602 | PyObject *param_call_id, *param_from, *param_to, *param_contact, |
| 603 | *param_is_typing, *param_acc_id; |
| 604 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 605 | ENTER_PYTHON(); |
| 606 | |
| 607 | PJ_UNUSED_ARG(rdata); |
| 608 | |
| 609 | PyObject_CallFunctionObjArgs( |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 610 | g_obj_callback->on_typing, |
| 611 | param_call_id = Py_BuildValue("i",call_id), |
| 612 | param_from = PyString_FromPJ(from), |
| 613 | param_to = PyString_FromPJ(to), |
| 614 | param_contact = PyString_FromPJ(contact), |
| 615 | param_is_typing = Py_BuildValue("i",is_typing), |
| 616 | param_acc_id = Py_BuildValue("i",acc_id), |
| 617 | NULL |
| 618 | ); |
| 619 | |
| 620 | Py_DECREF(param_call_id); |
| 621 | Py_DECREF(param_from); |
| 622 | Py_DECREF(param_to); |
| 623 | Py_DECREF(param_contact); |
| 624 | Py_DECREF(param_is_typing); |
| 625 | Py_DECREF(param_acc_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 626 | |
| 627 | LEAVE_PYTHON(); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
| 632 | |
| 633 | /* |
| 634 | * translate_hdr |
| 635 | * internal function |
| 636 | * translate from hdr_list to pjsip_generic_string_hdr |
| 637 | */ |
| 638 | void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list) |
| 639 | { |
| 640 | pj_list_init(hdr); |
| 641 | |
| 642 | if (PyList_Check(py_hdr_list)) { |
| 643 | int i; |
| 644 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 645 | for (i=0; i<PyList_Size(py_hdr_list); ++i) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 646 | pj_str_t hname, hvalue; |
| 647 | pjsip_generic_string_hdr * new_hdr; |
| 648 | PyObject * tuple = PyList_GetItem(py_hdr_list, i); |
| 649 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 650 | if (PyTuple_Check(tuple)) { |
| 651 | if (PyTuple_Size(tuple) >= 1) |
| 652 | hname = PyString_ToPJ(PyTuple_GetItem(tuple,0)); |
| 653 | else |
| 654 | hname.slen = 0; |
| 655 | if (PyTuple_Size(tuple) >= 2) |
| 656 | hvalue = PyString_ToPJ(PyTuple_GetItem(tuple,1)); |
| 657 | else |
| 658 | hvalue.slen = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 659 | } else { |
| 660 | hname.ptr = ""; |
| 661 | hname.slen = 0; |
| 662 | hvalue.ptr = ""; |
| 663 | hvalue.slen = 0; |
| 664 | } |
| 665 | new_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue); |
| 666 | pj_list_push_back((pj_list_type *)hdr, (pj_list_type *)new_hdr); |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 671 | /* |
| 672 | * py_pjsua_thread_register |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 673 | */ |
| 674 | static PyObject *py_pjsua_thread_register(PyObject *pSelf, PyObject *pArgs) |
| 675 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 676 | pj_status_t status; |
| 677 | const char *name; |
| 678 | PyObject *py_desc; |
| 679 | pj_thread_t *thread; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 680 | struct py_thread_desc *thread_desc; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 681 | |
| 682 | PJ_UNUSED_ARG(pSelf); |
| 683 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 684 | if (!PyArg_ParseTuple(pArgs, "sO", &name, &py_desc)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 685 | return NULL; |
| 686 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 687 | thread_desc = (struct py_thread_desc*) |
| 688 | malloc(sizeof(struct py_thread_desc)); |
| 689 | thread_desc->next = py_thread_desc; |
| 690 | py_thread_desc = thread_desc; |
| 691 | |
| 692 | status = pj_thread_register(name, thread_desc->desc, &thread); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 693 | |
| 694 | if (status == PJ_SUCCESS) |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 695 | status = pj_thread_local_set(g_thread_id, (void*)1); |
| 696 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 697 | return Py_BuildValue("i",status); |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * py_pjsua_logging_config_default |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 702 | */ |
| 703 | static PyObject *py_pjsua_logging_config_default(PyObject *pSelf, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 704 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 705 | { |
| 706 | PyObj_pjsua_logging_config *obj; |
| 707 | pjsua_logging_config cfg; |
| 708 | |
| 709 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 710 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 711 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 712 | pjsua_logging_config_default(&cfg); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 713 | obj = (PyObj_pjsua_logging_config*) |
| 714 | PyObj_pjsua_logging_config_new(&PyTyp_pjsua_logging_config, |
| 715 | NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 716 | PyObj_pjsua_logging_config_import(obj, &cfg); |
| 717 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 718 | return (PyObject*)obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | |
| 722 | /* |
| 723 | * py_pjsua_config_default |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 724 | */ |
| 725 | static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs) |
| 726 | { |
| 727 | PyObj_pjsua_config *obj; |
| 728 | pjsua_config cfg; |
| 729 | |
| 730 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 731 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 732 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 733 | pjsua_config_default(&cfg); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 734 | obj = (PyObj_pjsua_config *) PyObj_pjsua_config_new(&PyTyp_pjsua_config, |
| 735 | NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 736 | PyObj_pjsua_config_import(obj, &cfg); |
| 737 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 738 | return (PyObject*)obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | |
| 742 | /* |
| 743 | * py_pjsua_media_config_default |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 744 | */ |
| 745 | static PyObject * py_pjsua_media_config_default(PyObject *pSelf, |
| 746 | PyObject *pArgs) |
| 747 | { |
| 748 | PyObj_pjsua_media_config *obj; |
| 749 | pjsua_media_config cfg; |
| 750 | |
| 751 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 752 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 753 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 754 | pjsua_media_config_default(&cfg); |
| 755 | obj = (PyObj_pjsua_media_config *) |
| 756 | PyType_GenericNew(&PyTyp_pjsua_media_config, NULL, NULL); |
| 757 | PyObj_pjsua_media_config_import(obj, &cfg); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 758 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 759 | return (PyObject *)obj; |
| 760 | } |
| 761 | |
| 762 | |
| 763 | /* |
| 764 | * py_pjsua_msg_data_init |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 765 | */ |
| 766 | static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs) |
| 767 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 768 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 769 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 770 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 771 | return (PyObject *)PyObj_pjsua_msg_data_new(&PyTyp_pjsua_msg_data, |
| 772 | NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
| 776 | /* |
| 777 | * py_pjsua_reconfigure_logging |
| 778 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 779 | static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, |
| 780 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 781 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 782 | PyObject *logObj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 783 | pj_status_t status; |
| 784 | |
| 785 | PJ_UNUSED_ARG(pSelf); |
| 786 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 787 | if (!PyArg_ParseTuple(pArgs, "O", &logObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 788 | return NULL; |
| 789 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 790 | |
| 791 | if (logObj != Py_None) { |
| 792 | PyObj_pjsua_logging_config *log; |
| 793 | pjsua_logging_config cfg; |
| 794 | |
| 795 | log = (PyObj_pjsua_logging_config*)logObj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 796 | cfg.msg_logging = log->msg_logging; |
| 797 | cfg.level = log->level; |
| 798 | cfg.console_level = log->console_level; |
| 799 | cfg.decor = log->decor; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 800 | cfg.log_filename = PyString_ToPJ(log->log_filename); |
| 801 | Py_XDECREF(g_obj_log_cb); |
| 802 | g_obj_log_cb = log->cb; |
| 803 | Py_INCREF(g_obj_log_cb); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 804 | cfg.cb = &cb_log_cb; |
| 805 | status = pjsua_reconfigure_logging(&cfg); |
| 806 | } else { |
| 807 | status = pjsua_reconfigure_logging(NULL); |
| 808 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 809 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 810 | return Py_BuildValue("i",status); |
| 811 | } |
| 812 | |
| 813 | |
| 814 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 815 | * py_pjsua_perror |
| 816 | */ |
| 817 | static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs) |
| 818 | { |
| 819 | const char *sender; |
| 820 | const char *title; |
| 821 | pj_status_t status; |
| 822 | |
| 823 | PJ_UNUSED_ARG(pSelf); |
| 824 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 825 | if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 826 | return NULL; |
| 827 | } |
| 828 | |
| 829 | pjsua_perror(sender, title, status); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 830 | |
| 831 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
| 835 | /* |
| 836 | * py_pjsua_create |
| 837 | */ |
| 838 | static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs) |
| 839 | { |
| 840 | pj_status_t status; |
| 841 | |
| 842 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 843 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 844 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 845 | status = pjsua_create(); |
| 846 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 847 | if (status == PJ_SUCCESS) { |
| 848 | status = pj_thread_local_alloc(&g_thread_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 849 | if (status == PJ_SUCCESS) |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 850 | status = pj_thread_local_set(g_thread_id, (void*)1); |
| 851 | |
| 852 | pj_atexit(&clear_py_thread_desc); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | return Py_BuildValue("i",status); |
| 856 | } |
| 857 | |
| 858 | |
| 859 | /* |
| 860 | * py_pjsua_init |
| 861 | */ |
| 862 | static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs) |
| 863 | { |
| 864 | pj_status_t status; |
| 865 | PyObject *o_ua_cfg, *o_log_cfg, *o_media_cfg; |
| 866 | pjsua_config cfg_ua, *p_cfg_ua; |
| 867 | pjsua_logging_config cfg_log, *p_cfg_log; |
| 868 | pjsua_media_config cfg_media, *p_cfg_media; |
| 869 | |
| 870 | PJ_UNUSED_ARG(pSelf); |
| 871 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 872 | if (!PyArg_ParseTuple(pArgs, "OOO", &o_ua_cfg, &o_log_cfg, &o_media_cfg)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 873 | return NULL; |
| 874 | } |
| 875 | |
| 876 | pjsua_config_default(&cfg_ua); |
| 877 | pjsua_logging_config_default(&cfg_log); |
| 878 | pjsua_media_config_default(&cfg_media); |
| 879 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 880 | if (o_ua_cfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 881 | PyObj_pjsua_config *obj_ua_cfg = (PyObj_pjsua_config*)o_ua_cfg; |
| 882 | |
| 883 | PyObj_pjsua_config_export(&cfg_ua, obj_ua_cfg); |
| 884 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 885 | Py_XDECREF(g_obj_callback); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 886 | g_obj_callback = obj_ua_cfg->cb; |
| 887 | Py_INCREF(g_obj_callback); |
| 888 | |
| 889 | cfg_ua.cb.on_call_state = &cb_on_call_state; |
| 890 | cfg_ua.cb.on_incoming_call = &cb_on_incoming_call; |
| 891 | cfg_ua.cb.on_call_media_state = &cb_on_call_media_state; |
| 892 | cfg_ua.cb.on_dtmf_digit = &cb_on_dtmf_digit; |
| 893 | cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request; |
| 894 | cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status; |
| 895 | cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request; |
| 896 | cfg_ua.cb.on_call_replaced = &cb_on_call_replaced; |
| 897 | cfg_ua.cb.on_reg_state = &cb_on_reg_state; |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 898 | cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 899 | cfg_ua.cb.on_buddy_state = &cb_on_buddy_state; |
| 900 | cfg_ua.cb.on_pager2 = &cb_on_pager; |
| 901 | cfg_ua.cb.on_pager_status2 = &cb_on_pager_status; |
| 902 | cfg_ua.cb.on_typing2 = &cb_on_typing; |
| 903 | |
| 904 | p_cfg_ua = &cfg_ua; |
| 905 | |
| 906 | } else { |
| 907 | p_cfg_ua = NULL; |
| 908 | } |
| 909 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 910 | if (o_log_cfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 911 | PyObj_pjsua_logging_config * obj_log; |
| 912 | |
| 913 | obj_log = (PyObj_pjsua_logging_config *)o_log_cfg; |
| 914 | |
| 915 | PyObj_pjsua_logging_config_export(&cfg_log, obj_log); |
| 916 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 917 | Py_XDECREF(g_obj_log_cb); |
| 918 | g_obj_log_cb = obj_log->cb; |
| 919 | Py_INCREF(g_obj_log_cb); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 920 | |
| 921 | cfg_log.cb = &cb_log_cb; |
| 922 | p_cfg_log = &cfg_log; |
| 923 | |
| 924 | } else { |
| 925 | p_cfg_log = NULL; |
| 926 | } |
| 927 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 928 | if (o_media_cfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 929 | PyObj_pjsua_media_config_export(&cfg_media, |
| 930 | (PyObj_pjsua_media_config*)o_media_cfg); |
| 931 | p_cfg_media = &cfg_media; |
| 932 | |
| 933 | } else { |
| 934 | p_cfg_media = NULL; |
| 935 | } |
| 936 | |
| 937 | status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 938 | |
| 939 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | |
| 943 | /* |
| 944 | * py_pjsua_start |
| 945 | */ |
| 946 | static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs) |
| 947 | { |
| 948 | pj_status_t status; |
| 949 | |
| 950 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 951 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 952 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 953 | status = pjsua_start(); |
| 954 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 955 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | |
| 959 | /* |
| 960 | * py_pjsua_destroy |
| 961 | */ |
| 962 | static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs) |
| 963 | { |
| 964 | pj_status_t status; |
| 965 | |
| 966 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 967 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 968 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 969 | status = pjsua_destroy(); |
| 970 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 971 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | |
| 975 | /* |
| 976 | * py_pjsua_handle_events |
| 977 | */ |
| 978 | static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs) |
| 979 | { |
| 980 | int ret; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 981 | int msec; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 982 | |
| 983 | PJ_UNUSED_ARG(pSelf); |
| 984 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 985 | if (!PyArg_ParseTuple(pArgs, "i", &msec)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 986 | return NULL; |
| 987 | } |
| 988 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 989 | if (msec < 0) |
| 990 | msec = 0; |
| 991 | |
| 992 | #if !NO_PJSIP_THREAD |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 993 | /* Since handle_events() will block, we must wrap it with ALLOW_THREADS |
| 994 | * construct, or otherwise many Python blocking functions (such as |
| 995 | * time.sleep(), readline(), etc.) may hang/block indefinitely. |
| 996 | * See http://www.python.org/doc/current/api/threads.html for more info. |
| 997 | */ |
| 998 | Py_BEGIN_ALLOW_THREADS |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 999 | #endif |
| 1000 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1001 | ret = pjsua_handle_events(msec); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1002 | |
| 1003 | #if !NO_PJSIP_THREAD |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1004 | Py_END_ALLOW_THREADS |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1005 | #endif |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1006 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1007 | return Py_BuildValue("i", ret); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | /* |
| 1012 | * py_pjsua_verify_sip_url |
| 1013 | */ |
| 1014 | static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs) |
| 1015 | { |
| 1016 | pj_status_t status; |
| 1017 | const char *url; |
| 1018 | |
| 1019 | PJ_UNUSED_ARG(pSelf); |
| 1020 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1021 | if (!PyArg_ParseTuple(pArgs, "s", &url)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1022 | return NULL; |
| 1023 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1024 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1025 | status = pjsua_verify_sip_url(url); |
| 1026 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1027 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | /* |
| 1032 | * function doc |
| 1033 | */ |
| 1034 | |
| 1035 | static char pjsua_thread_register_doc[] = |
| 1036 | "int _pjsua.thread_register(string name, int[] desc)"; |
| 1037 | static char pjsua_perror_doc[] = |
| 1038 | "void _pjsua.perror (string sender, string title, int status) " |
| 1039 | "Display error message for the specified error code. Parameters: " |
| 1040 | "sender: The log sender field; " |
| 1041 | "title: Message title for the error; " |
| 1042 | "status: Status code."; |
| 1043 | |
| 1044 | static char pjsua_create_doc[] = |
| 1045 | "int _pjsua.create (void) " |
| 1046 | "Instantiate pjsua application. Application " |
| 1047 | "must call this function before calling any other functions, to make sure " |
| 1048 | "that the underlying libraries are properly initialized. Once this " |
| 1049 | "function has returned success, application must call pjsua_destroy() " |
| 1050 | "before quitting."; |
| 1051 | |
| 1052 | static char pjsua_init_doc[] = |
| 1053 | "int _pjsua.init (_pjsua.Config obj_ua_cfg, " |
| 1054 | "_pjsua.Logging_Config log_cfg, _pjsua.Media_Config media_cfg) " |
| 1055 | "Initialize pjsua with the specified settings. All the settings are " |
| 1056 | "optional, and the default values will be used when the config is not " |
| 1057 | "specified. Parameters: " |
| 1058 | "obj_ua_cfg : User agent configuration; " |
| 1059 | "log_cfg : Optional logging configuration; " |
| 1060 | "media_cfg : Optional media configuration."; |
| 1061 | |
| 1062 | static char pjsua_start_doc[] = |
| 1063 | "int _pjsua.start (void) " |
| 1064 | "Application is recommended to call this function after all " |
| 1065 | "initialization is done, so that the library can do additional checking " |
| 1066 | "set up additional"; |
| 1067 | |
| 1068 | static char pjsua_destroy_doc[] = |
| 1069 | "int _pjsua.destroy (void) " |
| 1070 | "Destroy pjsua This function must be called once PJSUA is created. To " |
| 1071 | "make it easier for application, application may call this function " |
| 1072 | "several times with no danger."; |
| 1073 | |
| 1074 | static char pjsua_handle_events_doc[] = |
| 1075 | "int _pjsua.handle_events (int msec_timeout) " |
| 1076 | "Poll pjsua for events, and if necessary block the caller thread for the " |
| 1077 | "specified maximum interval (in miliseconds) Parameters: " |
| 1078 | "msec_timeout: Maximum time to wait, in miliseconds. " |
| 1079 | "Returns: The number of events that have been handled during the poll. " |
| 1080 | "Negative value indicates error, and application can retrieve the error " |
| 1081 | "as (err = -return_value)."; |
| 1082 | |
| 1083 | static char pjsua_verify_sip_url_doc[] = |
| 1084 | "int _pjsua.verify_sip_url (string c_url) " |
| 1085 | "Verify that valid SIP url is given Parameters: " |
| 1086 | "c_url: The URL, as NULL terminated string."; |
| 1087 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1088 | static char pjsua_reconfigure_logging_doc[] = |
| 1089 | "int _pjsua.reconfigure_logging (_pjsua.Logging_Config c) " |
| 1090 | "Application can call this function at any time (after pjsua_create(), of " |
| 1091 | "course) to change logging settings. Parameters: " |
| 1092 | "c: Logging configuration."; |
| 1093 | |
| 1094 | static char pjsua_logging_config_default_doc[] = |
| 1095 | "_pjsua.Logging_Config _pjsua.logging_config_default () " |
| 1096 | "Use this function to initialize logging config."; |
| 1097 | |
| 1098 | static char pjsua_config_default_doc[] = |
| 1099 | "_pjsua.Config _pjsua.config_default (). Use this function to " |
| 1100 | "initialize pjsua config. "; |
| 1101 | |
| 1102 | static char pjsua_media_config_default_doc[] = |
| 1103 | "_pjsua.Media_Config _pjsua.media_config_default (). " |
| 1104 | "Use this function to initialize media config."; |
| 1105 | |
| 1106 | static char pjsua_msg_data_init_doc[] = |
| 1107 | "_pjsua.Msg_Data void _pjsua.msg_data_init () " |
| 1108 | "Initialize message data "; |
| 1109 | |
| 1110 | |
| 1111 | /* END OF LIB BASE */ |
| 1112 | |
| 1113 | /* LIB TRANSPORT */ |
| 1114 | |
| 1115 | /* |
| 1116 | * py_pjsua_transport_config_default |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1117 | */ |
| 1118 | static PyObject *py_pjsua_transport_config_default(PyObject *pSelf, |
| 1119 | PyObject *pArgs) |
| 1120 | { |
| 1121 | PyObj_pjsua_transport_config *obj; |
| 1122 | pjsua_transport_config cfg; |
| 1123 | |
| 1124 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1125 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1126 | |
| 1127 | pjsua_transport_config_default(&cfg); |
| 1128 | obj = (PyObj_pjsua_transport_config*) |
| 1129 | PyObj_pjsua_transport_config_new(&PyTyp_pjsua_transport_config, |
| 1130 | NULL, NULL); |
| 1131 | PyObj_pjsua_transport_config_import(obj, &cfg); |
| 1132 | |
| 1133 | return (PyObject *)obj; |
| 1134 | } |
| 1135 | |
| 1136 | /* |
| 1137 | * py_pjsua_transport_create |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1138 | */ |
| 1139 | static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) |
| 1140 | { |
| 1141 | pj_status_t status; |
| 1142 | int type; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1143 | PyObject *pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1144 | pjsua_transport_config cfg; |
| 1145 | pjsua_transport_id id; |
| 1146 | |
| 1147 | PJ_UNUSED_ARG(pSelf); |
| 1148 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1149 | if (!PyArg_ParseTuple(pArgs, "iO", &type, &pCfg)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1150 | return NULL; |
| 1151 | } |
| 1152 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1153 | if (pCfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1154 | PyObj_pjsua_transport_config *obj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1155 | |
| 1156 | obj = (PyObj_pjsua_transport_config*)pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1157 | PyObj_pjsua_transport_config_export(&cfg, obj); |
| 1158 | status = pjsua_transport_create(type, &cfg, &id); |
| 1159 | } else { |
| 1160 | status = pjsua_transport_create(type, NULL, &id); |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | return Py_BuildValue("ii", status, id); |
| 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | * py_pjsua_enum_transports |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1169 | */ |
| 1170 | static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) |
| 1171 | { |
| 1172 | pj_status_t status; |
| 1173 | PyObject *list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1174 | pjsua_transport_id id[PJSIP_MAX_TRANSPORTS]; |
| 1175 | unsigned c, i; |
| 1176 | |
| 1177 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1178 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1179 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1180 | c = PJ_ARRAY_SIZE(id); |
| 1181 | status = pjsua_enum_transports(id, &c); |
| 1182 | |
| 1183 | list = PyList_New(c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1184 | for (i = 0; i < c; i++) { |
| 1185 | PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1188 | return (PyObject*)list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | * py_pjsua_transport_get_info |
| 1193 | * !modified @ 051206 |
| 1194 | */ |
| 1195 | static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs) |
| 1196 | { |
| 1197 | pj_status_t status; |
| 1198 | int id; |
| 1199 | pjsua_transport_info info; |
| 1200 | |
| 1201 | PJ_UNUSED_ARG(pSelf); |
| 1202 | |
| 1203 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
| 1207 | status = pjsua_transport_get_info(id, &info); |
| 1208 | if (status == PJ_SUCCESS) { |
| 1209 | PyObj_pjsua_transport_info *obj; |
| 1210 | obj = (PyObj_pjsua_transport_info *) |
| 1211 | PyObj_pjsua_transport_info_new(&PyTyp_pjsua_transport_info, |
| 1212 | NULL, NULL); |
| 1213 | PyObj_pjsua_transport_info_import(obj, &info); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1214 | return (PyObject*)obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1215 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1216 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | /* |
| 1221 | * py_pjsua_transport_set_enable |
| 1222 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1223 | static PyObject *py_pjsua_transport_set_enable(PyObject *pSelf, |
| 1224 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1225 | { |
| 1226 | pj_status_t status; |
| 1227 | int id; |
| 1228 | int enabled; |
| 1229 | |
| 1230 | PJ_UNUSED_ARG(pSelf); |
| 1231 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1232 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1233 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1234 | } |
| 1235 | status = pjsua_transport_set_enable(id, enabled); |
| 1236 | |
| 1237 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | /* |
| 1241 | * py_pjsua_transport_close |
| 1242 | */ |
| 1243 | static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs) |
| 1244 | { |
| 1245 | pj_status_t status; |
| 1246 | int id; |
| 1247 | int force; |
| 1248 | |
| 1249 | PJ_UNUSED_ARG(pSelf); |
| 1250 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1251 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1252 | return NULL; |
| 1253 | } |
| 1254 | status = pjsua_transport_close(id, force); |
| 1255 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1256 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static char pjsua_transport_config_default_doc[] = |
| 1260 | "_pjsua.Transport_Config _pjsua.transport_config_default () " |
| 1261 | "Call this function to initialize UDP config with default values."; |
| 1262 | static char pjsua_transport_create_doc[] = |
| 1263 | "int, int _pjsua.transport_create (int type, " |
| 1264 | "_pjsua.Transport_Config cfg) " |
| 1265 | "Create SIP transport."; |
| 1266 | static char pjsua_enum_transports_doc[] = |
| 1267 | "int[] _pjsua.enum_transports () " |
| 1268 | "Enumerate all transports currently created in the system."; |
| 1269 | static char pjsua_transport_get_info_doc[] = |
| 1270 | "void _pjsua.transport_get_info " |
| 1271 | "(_pjsua.Transport_ID id, _pjsua.Transport_Info info) " |
| 1272 | "Get information about transports."; |
| 1273 | static char pjsua_transport_set_enable_doc[] = |
| 1274 | "void _pjsua.transport_set_enable " |
| 1275 | "(_pjsua.Transport_ID id, int enabled) " |
| 1276 | "Disable a transport or re-enable it. " |
| 1277 | "By default transport is always enabled after it is created. " |
| 1278 | "Disabling a transport does not necessarily close the socket, " |
| 1279 | "it will only discard incoming messages and prevent the transport " |
| 1280 | "from being used to send outgoing messages."; |
| 1281 | static char pjsua_transport_close_doc[] = |
| 1282 | "void _pjsua.transport_close (_pjsua.Transport_ID id, int force) " |
| 1283 | "Close the transport. If transport is forcefully closed, " |
| 1284 | "it will be immediately closed, and any pending transactions " |
| 1285 | "that are using the transport may not terminate properly. " |
| 1286 | "Otherwise, the system will wait until all transactions are closed " |
| 1287 | "while preventing new users from using the transport, and will close " |
| 1288 | "the transport when it is safe to do so."; |
| 1289 | |
| 1290 | /* END OF LIB TRANSPORT */ |
| 1291 | |
| 1292 | /* LIB ACCOUNT */ |
| 1293 | |
| 1294 | |
| 1295 | /* |
| 1296 | * py_pjsua_acc_config_default |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1297 | */ |
| 1298 | static PyObject *py_pjsua_acc_config_default(PyObject *pSelf, PyObject *pArgs) |
| 1299 | { |
| 1300 | PyObj_pjsua_acc_config *obj; |
| 1301 | pjsua_acc_config cfg; |
| 1302 | |
| 1303 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1304 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1305 | |
| 1306 | if (!PyArg_ParseTuple(pArgs, "")) { |
| 1307 | return NULL; |
| 1308 | } |
| 1309 | |
| 1310 | pjsua_acc_config_default(&cfg); |
| 1311 | obj = (PyObj_pjsua_acc_config *) |
| 1312 | PyObj_pjsua_acc_config_new(&PyTyp_pjsua_acc_config, |
| 1313 | NULL, NULL); |
| 1314 | PyObj_pjsua_acc_config_import(obj, &cfg); |
| 1315 | return (PyObject *)obj; |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * py_pjsua_acc_get_count |
| 1320 | */ |
| 1321 | static PyObject *py_pjsua_acc_get_count(PyObject *pSelf, PyObject *pArgs) |
| 1322 | { |
| 1323 | int count; |
| 1324 | |
| 1325 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1326 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1327 | |
| 1328 | count = pjsua_acc_get_count(); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1329 | return Py_BuildValue("i", count); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | /* |
| 1333 | * py_pjsua_acc_is_valid |
| 1334 | */ |
| 1335 | static PyObject *py_pjsua_acc_is_valid(PyObject *pSelf, PyObject *pArgs) |
| 1336 | { |
| 1337 | int id; |
| 1338 | int is_valid; |
| 1339 | |
| 1340 | PJ_UNUSED_ARG(pSelf); |
| 1341 | |
| 1342 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
| 1343 | return NULL; |
| 1344 | } |
| 1345 | |
| 1346 | is_valid = pjsua_acc_is_valid(id); |
| 1347 | return Py_BuildValue("i", is_valid); |
| 1348 | } |
| 1349 | |
| 1350 | /* |
| 1351 | * py_pjsua_acc_set_default |
| 1352 | */ |
| 1353 | static PyObject *py_pjsua_acc_set_default(PyObject *pSelf, PyObject *pArgs) |
| 1354 | { |
| 1355 | int id; |
| 1356 | int status; |
| 1357 | |
| 1358 | PJ_UNUSED_ARG(pSelf); |
| 1359 | |
| 1360 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | status = pjsua_acc_set_default(id); |
| 1364 | |
| 1365 | return Py_BuildValue("i", status); |
| 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | * py_pjsua_acc_get_default |
| 1370 | */ |
| 1371 | static PyObject *py_pjsua_acc_get_default(PyObject *pSelf, PyObject *pArgs) |
| 1372 | { |
| 1373 | int id; |
| 1374 | |
| 1375 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1376 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1377 | |
| 1378 | id = pjsua_acc_get_default(); |
| 1379 | |
| 1380 | return Py_BuildValue("i", id); |
| 1381 | } |
| 1382 | |
| 1383 | /* |
| 1384 | * py_pjsua_acc_add |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1385 | */ |
| 1386 | static PyObject *py_pjsua_acc_add(PyObject *pSelf, PyObject *pArgs) |
| 1387 | { |
| 1388 | int is_default; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1389 | PyObject *pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1390 | int acc_id; |
| 1391 | int status; |
| 1392 | |
| 1393 | PJ_UNUSED_ARG(pSelf); |
| 1394 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1395 | if (!PyArg_ParseTuple(pArgs, "Oi", &pCfg, &is_default)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1396 | return NULL; |
| 1397 | } |
| 1398 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1399 | if (pCfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1400 | pjsua_acc_config cfg; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1401 | PyObj_pjsua_acc_config *ac; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1402 | |
| 1403 | pjsua_acc_config_default(&cfg); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1404 | ac = (PyObj_pjsua_acc_config *)pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1405 | PyObj_pjsua_acc_config_export(&cfg, ac); |
| 1406 | status = pjsua_acc_add(&cfg, is_default, &acc_id); |
| 1407 | } else { |
| 1408 | status = PJ_EINVAL; |
| 1409 | acc_id = PJSUA_INVALID_ID; |
| 1410 | } |
| 1411 | |
| 1412 | return Py_BuildValue("ii", status, acc_id); |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * py_pjsua_acc_add_local |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1417 | */ |
| 1418 | static PyObject *py_pjsua_acc_add_local(PyObject *pSelf, PyObject *pArgs) |
| 1419 | { |
| 1420 | int is_default; |
| 1421 | int tid; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1422 | int acc_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1423 | int status; |
| 1424 | |
| 1425 | PJ_UNUSED_ARG(pSelf); |
| 1426 | |
| 1427 | if (!PyArg_ParseTuple(pArgs, "ii", &tid, &is_default)) { |
| 1428 | return NULL; |
| 1429 | } |
| 1430 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1431 | status = pjsua_acc_add_local(tid, is_default, &acc_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1432 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1433 | return Py_BuildValue("ii", status, acc_id); |
| 1434 | } |
| 1435 | |
| 1436 | /* |
| 1437 | * py_pjsua_acc_set_user_data |
| 1438 | */ |
| 1439 | static PyObject *py_pjsua_acc_set_user_data(PyObject *pSelf, PyObject *pArgs) |
| 1440 | { |
| 1441 | int acc_id; |
| 1442 | PyObject *pUserData, *old_user_data; |
| 1443 | int status; |
| 1444 | |
| 1445 | PJ_UNUSED_ARG(pSelf); |
| 1446 | |
| 1447 | if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pUserData)) { |
| 1448 | return NULL; |
| 1449 | } |
| 1450 | |
| 1451 | old_user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); |
| 1452 | |
| 1453 | status = pjsua_acc_set_user_data(acc_id, (void*)pUserData); |
| 1454 | |
| 1455 | if (status == PJ_SUCCESS) { |
| 1456 | Py_XINCREF(pUserData); |
| 1457 | Py_XDECREF(old_user_data); |
| 1458 | } |
| 1459 | |
| 1460 | return Py_BuildValue("i", status); |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | * py_pjsua_acc_get_user_data |
| 1465 | */ |
| 1466 | static PyObject *py_pjsua_acc_get_user_data(PyObject *pSelf, PyObject *pArgs) |
| 1467 | { |
| 1468 | int acc_id; |
| 1469 | PyObject *user_data; |
| 1470 | |
| 1471 | PJ_UNUSED_ARG(pSelf); |
| 1472 | |
| 1473 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) { |
| 1474 | return NULL; |
| 1475 | } |
| 1476 | |
| 1477 | user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); |
| 1478 | |
| 1479 | return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /* |
| 1483 | * py_pjsua_acc_del |
| 1484 | */ |
| 1485 | static PyObject *py_pjsua_acc_del(PyObject *pSelf, PyObject *pArgs) |
| 1486 | { |
| 1487 | int acc_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1488 | PyObject *user_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1489 | int status; |
| 1490 | |
| 1491 | PJ_UNUSED_ARG(pSelf); |
| 1492 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1493 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1494 | return NULL; |
| 1495 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1496 | |
| 1497 | user_data = (PyObject*) pjsua_acc_get_user_data(acc_id); |
| 1498 | Py_XDECREF(user_data); |
| 1499 | |
| 1500 | status = pjsua_acc_del(acc_id); |
| 1501 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1502 | return Py_BuildValue("i", status); |
| 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * py_pjsua_acc_modify |
| 1507 | */ |
| 1508 | static PyObject *py_pjsua_acc_modify(PyObject *pSelf, PyObject *pArgs) |
| 1509 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1510 | PyObject *pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1511 | PyObj_pjsua_acc_config * ac; |
| 1512 | int acc_id; |
| 1513 | int status; |
| 1514 | |
| 1515 | PJ_UNUSED_ARG(pSelf); |
| 1516 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1517 | if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &pCfg)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1518 | return NULL; |
| 1519 | } |
| 1520 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1521 | if (pCfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1522 | pjsua_acc_config cfg; |
| 1523 | |
| 1524 | pjsua_acc_config_default(&cfg); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1525 | ac = (PyObj_pjsua_acc_config*)pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1526 | PyObj_pjsua_acc_config_export(&cfg, ac); |
| 1527 | |
| 1528 | status = pjsua_acc_modify(acc_id, &cfg); |
| 1529 | } else { |
| 1530 | status = PJ_EINVAL; |
| 1531 | } |
| 1532 | return Py_BuildValue("i", status); |
| 1533 | } |
| 1534 | |
| 1535 | /* |
| 1536 | * py_pjsua_acc_set_online_status |
| 1537 | */ |
| 1538 | static PyObject *py_pjsua_acc_set_online_status(PyObject *pSelf, |
| 1539 | PyObject *pArgs) |
| 1540 | { |
| 1541 | int is_online; |
| 1542 | int acc_id; |
| 1543 | int status; |
| 1544 | |
| 1545 | PJ_UNUSED_ARG(pSelf); |
| 1546 | |
| 1547 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) { |
| 1548 | return NULL; |
| 1549 | } |
| 1550 | |
| 1551 | status = pjsua_acc_set_online_status(acc_id, is_online); |
| 1552 | |
| 1553 | return Py_BuildValue("i", status); |
| 1554 | } |
| 1555 | |
| 1556 | /* |
| 1557 | * py_pjsua_acc_set_online_status2 |
| 1558 | */ |
| 1559 | static PyObject *py_pjsua_acc_set_online_status2(PyObject *pSelf, |
| 1560 | PyObject *pArgs) |
| 1561 | { |
| 1562 | int is_online; |
| 1563 | int acc_id; |
| 1564 | int activity_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1565 | const char *activity_text = NULL; |
| 1566 | const char *rpid_id = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1567 | pjrpid_element rpid; |
| 1568 | pj_status_t status; |
| 1569 | |
| 1570 | PJ_UNUSED_ARG(pSelf); |
| 1571 | |
| 1572 | if (!PyArg_ParseTuple(pArgs, "iiiss", &acc_id, &is_online, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1573 | &activity_id, &activity_text, &rpid_id)) |
| 1574 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1575 | return NULL; |
| 1576 | } |
| 1577 | |
| 1578 | pj_bzero(&rpid, sizeof(rpid)); |
| 1579 | rpid.type = PJRPID_ELEMENT_TYPE_PERSON; |
| 1580 | rpid.activity = activity_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1581 | if (activity_text) |
| 1582 | rpid.note = pj_str((char*)activity_text); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1583 | |
| 1584 | if (rpid_id) |
| 1585 | rpid.id = pj_str((char*)rpid_id); |
| 1586 | |
| 1587 | status = pjsua_acc_set_online_status2(acc_id, is_online, &rpid); |
| 1588 | |
| 1589 | return Py_BuildValue("i", status); |
| 1590 | } |
| 1591 | |
| 1592 | /* |
| 1593 | * py_pjsua_acc_set_registration |
| 1594 | */ |
| 1595 | static PyObject *py_pjsua_acc_set_registration(PyObject *pSelf, |
| 1596 | PyObject *pArgs) |
| 1597 | { |
| 1598 | int renew; |
| 1599 | int acc_id; |
| 1600 | int status; |
| 1601 | |
| 1602 | PJ_UNUSED_ARG(pSelf); |
| 1603 | |
| 1604 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) { |
| 1605 | return NULL; |
| 1606 | } |
| 1607 | |
| 1608 | status = pjsua_acc_set_registration(acc_id, renew); |
| 1609 | |
| 1610 | return Py_BuildValue("i", status); |
| 1611 | } |
| 1612 | |
| 1613 | /* |
| 1614 | * py_pjsua_acc_get_info |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1615 | */ |
| 1616 | static PyObject *py_pjsua_acc_get_info(PyObject *pSelf, PyObject *pArgs) |
| 1617 | { |
| 1618 | int acc_id; |
| 1619 | PyObj_pjsua_acc_info * obj; |
| 1620 | pjsua_acc_info info; |
| 1621 | int status; |
| 1622 | |
| 1623 | PJ_UNUSED_ARG(pSelf); |
| 1624 | |
| 1625 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) { |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | |
| 1629 | status = pjsua_acc_get_info(acc_id, &info); |
| 1630 | if (status == PJ_SUCCESS) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1631 | obj = (PyObj_pjsua_acc_info*) |
| 1632 | PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1633 | PyObj_pjsua_acc_info_import(obj, &info); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1634 | return (PyObject*)obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1635 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1636 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | /* |
| 1641 | * py_pjsua_enum_accs |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1642 | */ |
| 1643 | static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) |
| 1644 | { |
| 1645 | pj_status_t status; |
| 1646 | PyObject *list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1647 | pjsua_acc_id id[PJSUA_MAX_ACC]; |
| 1648 | unsigned c, i; |
| 1649 | |
| 1650 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1651 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1652 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1653 | c = PJ_ARRAY_SIZE(id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1654 | status = pjsua_enum_accs(id, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1655 | if (status != PJ_SUCCESS) |
| 1656 | c = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1657 | |
| 1658 | list = PyList_New(c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1659 | for (i = 0; i < c; i++) { |
| 1660 | PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1663 | return (PyObject*)list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /* |
| 1667 | * py_pjsua_acc_enum_info |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1668 | */ |
| 1669 | static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) |
| 1670 | { |
| 1671 | pj_status_t status; |
| 1672 | PyObject *list; |
| 1673 | pjsua_acc_info info[PJSUA_MAX_ACC]; |
| 1674 | unsigned c, i; |
| 1675 | |
| 1676 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1677 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1678 | |
| 1679 | if (!PyArg_ParseTuple(pArgs, "")) { |
| 1680 | return NULL; |
| 1681 | } |
| 1682 | |
| 1683 | c = PJ_ARRAY_SIZE(info); |
| 1684 | status = pjsua_acc_enum_info(info, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1685 | if (status != PJ_SUCCESS) |
| 1686 | c = 0; |
| 1687 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1688 | list = PyList_New(c); |
| 1689 | for (i = 0; i < c; i++) { |
| 1690 | PyObj_pjsua_acc_info *obj; |
| 1691 | obj = (PyObj_pjsua_acc_info *) |
| 1692 | PyObj_pjsua_acc_info_new(&PyTyp_pjsua_acc_info, NULL, NULL); |
| 1693 | |
| 1694 | PyObj_pjsua_acc_info_import(obj, &info[i]); |
| 1695 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1696 | PyList_SetItem(list, i, (PyObject*)obj); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1699 | return (PyObject*)list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /* |
| 1703 | * py_pjsua_acc_set_transport |
| 1704 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1705 | static PyObject *py_pjsua_acc_set_transport(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1706 | { |
| 1707 | int acc_id, transport_id; |
| 1708 | int status; |
| 1709 | |
| 1710 | PJ_UNUSED_ARG(pSelf); |
| 1711 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1712 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &transport_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1713 | return NULL; |
| 1714 | } |
| 1715 | |
| 1716 | status = pjsua_acc_set_transport(acc_id, transport_id); |
| 1717 | |
| 1718 | |
| 1719 | return Py_BuildValue("i", status); |
| 1720 | } |
| 1721 | |
| 1722 | |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1723 | /* |
| 1724 | * py_pjsua_acc_pres_notify |
| 1725 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1726 | static PyObject *py_pjsua_acc_pres_notify(PyObject *pSelf, |
| 1727 | PyObject *pArgs) |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1728 | { |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1729 | int acc_id, state; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1730 | PyObject *arg_pres, *arg_msg_data, *arg_reason; |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1731 | void *srv_pres; |
| 1732 | pjsua_msg_data msg_data; |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1733 | pj_str_t reason; |
| 1734 | pj_bool_t with_body; |
| 1735 | pj_pool_t *pool = NULL; |
| 1736 | int status; |
| 1737 | |
| 1738 | PJ_UNUSED_ARG(pSelf); |
| 1739 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1740 | if (!PyArg_ParseTuple(pArgs, "iOiOO", &acc_id, &arg_pres, |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1741 | &state, &arg_reason, &arg_msg_data)) |
| 1742 | { |
| 1743 | return NULL; |
| 1744 | } |
| 1745 | |
| 1746 | srv_pres = (void*) PyLong_AsLong(arg_pres); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1747 | with_body = (state != PJSIP_EVSUB_STATE_TERMINATED); |
| 1748 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1749 | if (arg_reason && PyString_Check(arg_reason)) { |
| 1750 | reason = PyString_ToPJ(arg_reason); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1751 | } else { |
| 1752 | reason = pj_str(""); |
| 1753 | } |
| 1754 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1755 | pjsua_msg_data_init(&msg_data); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1756 | if (arg_msg_data && arg_msg_data != Py_None) { |
| 1757 | PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1758 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 1759 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1760 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
| 1761 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres, |
| 1765 | (pjsip_evsub_state)state, NULL, |
| 1766 | &reason, with_body, &msg_data); |
| 1767 | |
| 1768 | if (pool) { |
| 1769 | pj_pool_release(pool); |
| 1770 | } |
| 1771 | |
| 1772 | return Py_BuildValue("i", status); |
| 1773 | } |
| 1774 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1775 | static char pjsua_acc_config_default_doc[] = |
| 1776 | "_pjsua.Acc_Config _pjsua.acc_config_default () " |
| 1777 | "Call this function to initialize account config with default values."; |
| 1778 | static char pjsua_acc_get_count_doc[] = |
| 1779 | "int _pjsua.acc_get_count () " |
| 1780 | "Get number of current accounts."; |
| 1781 | static char pjsua_acc_is_valid_doc[] = |
| 1782 | "int _pjsua.acc_is_valid (int acc_id) " |
| 1783 | "Check if the specified account ID is valid."; |
| 1784 | static char pjsua_acc_set_default_doc[] = |
| 1785 | "int _pjsua.acc_set_default (int acc_id) " |
| 1786 | "Set default account to be used when incoming " |
| 1787 | "and outgoing requests doesn't match any accounts."; |
| 1788 | static char pjsua_acc_get_default_doc[] = |
| 1789 | "int _pjsua.acc_get_default () " |
| 1790 | "Get default account."; |
| 1791 | static char pjsua_acc_add_doc[] = |
| 1792 | "int, int _pjsua.acc_add (_pjsua.Acc_Config cfg, " |
| 1793 | "int is_default) " |
| 1794 | "Add a new account to pjsua. PJSUA must have been initialized " |
| 1795 | "(with pjsua_init()) before calling this function."; |
| 1796 | static char pjsua_acc_add_local_doc[] = |
| 1797 | "int,int _pjsua.acc_add_local (int tid, " |
| 1798 | "int is_default) " |
| 1799 | "Add a local account. A local account is used to identify " |
| 1800 | "local endpoint instead of a specific user, and for this reason, " |
| 1801 | "a transport ID is needed to obtain the local address information."; |
| 1802 | static char pjsua_acc_del_doc[] = |
| 1803 | "int _pjsua.acc_del (int acc_id) " |
| 1804 | "Delete account."; |
| 1805 | static char pjsua_acc_modify_doc[] = |
| 1806 | "int _pjsua.acc_modify (int acc_id, _pjsua.Acc_Config cfg) " |
| 1807 | "Modify account information."; |
| 1808 | static char pjsua_acc_set_online_status_doc[] = |
| 1809 | "int _pjsua.acc_set_online_status2(int acc_id, int is_online) " |
| 1810 | "Modify account's presence status to be advertised " |
| 1811 | "to remote/presence subscribers."; |
| 1812 | static char pjsua_acc_set_online_status2_doc[] = |
| 1813 | "int _pjsua.acc_set_online_status (int acc_id, int is_online, " |
| 1814 | "int activity_id, string activity_text) " |
| 1815 | "Modify account's presence status to be advertised " |
| 1816 | "to remote/presence subscribers."; |
| 1817 | static char pjsua_acc_set_registration_doc[] = |
| 1818 | "int _pjsua.acc_set_registration (int acc_id, int renew) " |
| 1819 | "Update registration or perform unregistration."; |
| 1820 | static char pjsua_acc_get_info_doc[] = |
| 1821 | "_pjsua.Acc_Info _pjsua.acc_get_info (int acc_id) " |
| 1822 | "Get account information."; |
| 1823 | static char pjsua_enum_accs_doc[] = |
| 1824 | "int[] _pjsua.enum_accs () " |
| 1825 | "Enum accounts all account ids."; |
| 1826 | static char pjsua_acc_enum_info_doc[] = |
| 1827 | "_pjsua.Acc_Info[] _pjsua.acc_enum_info () " |
| 1828 | "Enum accounts info."; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1829 | |
| 1830 | /* END OF LIB ACCOUNT */ |
| 1831 | |
| 1832 | /* LIB BUDDY */ |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | /* |
| 1837 | * py_pjsua_buddy_config_default |
| 1838 | */ |
| 1839 | static PyObject *py_pjsua_buddy_config_default(PyObject *pSelf, |
| 1840 | PyObject *pArgs) |
| 1841 | { |
| 1842 | PyObj_pjsua_buddy_config *obj; |
| 1843 | pjsua_buddy_config cfg; |
| 1844 | |
| 1845 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1846 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1847 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1848 | pjsua_buddy_config_default(&cfg); |
| 1849 | obj = (PyObj_pjsua_buddy_config *) |
| 1850 | PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_config, NULL, NULL); |
| 1851 | PyObj_pjsua_buddy_config_import(obj, &cfg); |
| 1852 | |
| 1853 | return (PyObject *)obj; |
| 1854 | } |
| 1855 | |
| 1856 | /* |
| 1857 | * py_pjsua_get_buddy_count |
| 1858 | */ |
| 1859 | static PyObject *py_pjsua_get_buddy_count(PyObject *pSelf, PyObject *pArgs) |
| 1860 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1861 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1862 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1863 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1864 | return Py_BuildValue("i", pjsua_get_buddy_count()); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | /* |
| 1868 | * py_pjsua_buddy_is_valid |
| 1869 | */ |
| 1870 | static PyObject *py_pjsua_buddy_is_valid(PyObject *pSelf, PyObject *pArgs) |
| 1871 | { |
| 1872 | int id; |
| 1873 | int is_valid; |
| 1874 | |
| 1875 | PJ_UNUSED_ARG(pSelf); |
| 1876 | |
| 1877 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
| 1878 | return NULL; |
| 1879 | } |
| 1880 | is_valid = pjsua_buddy_is_valid(id); |
| 1881 | |
| 1882 | return Py_BuildValue("i", is_valid); |
| 1883 | } |
| 1884 | |
| 1885 | /* |
| 1886 | * py_pjsua_enum_buddies |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1887 | */ |
| 1888 | static PyObject *py_pjsua_enum_buddies(PyObject *pSelf, PyObject *pArgs) |
| 1889 | { |
| 1890 | pj_status_t status; |
| 1891 | PyObject *list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1892 | pjsua_buddy_id id[PJSUA_MAX_BUDDIES]; |
| 1893 | unsigned c, i; |
| 1894 | |
| 1895 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1896 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1897 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1898 | c = PJ_ARRAY_SIZE(id); |
| 1899 | status = pjsua_enum_buddies(id, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1900 | if (status != PJ_SUCCESS) |
| 1901 | c = 0; |
| 1902 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1903 | list = PyList_New(c); |
| 1904 | for (i = 0; i < c; i++) { |
| 1905 | PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
| 1906 | } |
| 1907 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1908 | return (PyObject*)list; |
| 1909 | } |
| 1910 | |
| 1911 | /* |
| 1912 | * py_pjsua_buddy_find |
| 1913 | */ |
| 1914 | static PyObject *py_pjsua_buddy_find(PyObject *pSelf, PyObject *pArgs) |
| 1915 | { |
| 1916 | PyObject *pURI; |
| 1917 | pj_str_t uri; |
| 1918 | pjsua_buddy_id buddy_id; |
| 1919 | |
| 1920 | PJ_UNUSED_ARG(pSelf); |
| 1921 | |
| 1922 | if (!PyArg_ParseTuple(pArgs, "O", &pURI)) { |
| 1923 | return NULL; |
| 1924 | } |
| 1925 | |
| 1926 | if (!PyString_Check(pURI)) |
| 1927 | return Py_BuildValue("i", PJSUA_INVALID_ID); |
| 1928 | |
| 1929 | uri = PyString_ToPJ(pURI); |
| 1930 | buddy_id = pjsua_buddy_find(&uri); |
| 1931 | |
| 1932 | return Py_BuildValue("i", buddy_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /* |
| 1936 | * py_pjsua_buddy_get_info |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1937 | */ |
| 1938 | static PyObject *py_pjsua_buddy_get_info(PyObject *pSelf, PyObject *pArgs) |
| 1939 | { |
| 1940 | int buddy_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1941 | pjsua_buddy_info info; |
| 1942 | int status; |
| 1943 | |
| 1944 | PJ_UNUSED_ARG(pSelf); |
| 1945 | |
| 1946 | if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) { |
| 1947 | return NULL; |
| 1948 | } |
| 1949 | |
| 1950 | status = pjsua_buddy_get_info(buddy_id, &info); |
| 1951 | if (status == PJ_SUCCESS) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1952 | PyObj_pjsua_buddy_info *obj; |
| 1953 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1954 | obj = (PyObj_pjsua_buddy_info *) |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1955 | PyObj_pjsua_buddy_config_new(&PyTyp_pjsua_buddy_info, |
| 1956 | NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1957 | PyObj_pjsua_buddy_info_import(obj, &info); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1958 | return (PyObject*)obj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1959 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1960 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | /* |
| 1965 | * py_pjsua_buddy_add |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1966 | */ |
| 1967 | static PyObject *py_pjsua_buddy_add(PyObject *pSelf, PyObject *pArgs) |
| 1968 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1969 | PyObject *pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1970 | int buddy_id; |
| 1971 | int status; |
| 1972 | |
| 1973 | PJ_UNUSED_ARG(pSelf); |
| 1974 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1975 | if (!PyArg_ParseTuple(pArgs, "O", &pCfg)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1976 | return NULL; |
| 1977 | } |
| 1978 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1979 | if (pCfg != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1980 | pjsua_buddy_config cfg; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1981 | PyObj_pjsua_buddy_config *bc; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1982 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1983 | bc = (PyObj_pjsua_buddy_config *)pCfg; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1984 | |
| 1985 | pjsua_buddy_config_default(&cfg); |
| 1986 | PyObj_pjsua_buddy_config_export(&cfg, bc); |
| 1987 | |
| 1988 | status = pjsua_buddy_add(&cfg, &buddy_id); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 1989 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 1990 | } else { |
| 1991 | status = PJ_EINVAL; |
| 1992 | buddy_id = PJSUA_INVALID_ID; |
| 1993 | } |
| 1994 | return Py_BuildValue("ii", status, buddy_id); |
| 1995 | } |
| 1996 | |
| 1997 | /* |
| 1998 | * py_pjsua_buddy_del |
| 1999 | */ |
| 2000 | static PyObject *py_pjsua_buddy_del(PyObject *pSelf, PyObject *pArgs) |
| 2001 | { |
| 2002 | int buddy_id; |
| 2003 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2004 | PyObject *user_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2005 | |
| 2006 | PJ_UNUSED_ARG(pSelf); |
| 2007 | |
| 2008 | if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) { |
| 2009 | return NULL; |
| 2010 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2011 | |
| 2012 | user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); |
| 2013 | Py_XDECREF(user_data); |
| 2014 | |
| 2015 | status = pjsua_buddy_del(buddy_id); |
| 2016 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2017 | return Py_BuildValue("i", status); |
| 2018 | } |
| 2019 | |
| 2020 | /* |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2021 | * py_pjsua_buddy_set_user_data |
| 2022 | */ |
| 2023 | static PyObject *py_pjsua_buddy_set_user_data(PyObject *pSelf, PyObject *pArgs) |
| 2024 | { |
| 2025 | int buddy_id; |
| 2026 | int status; |
| 2027 | PyObject *user_data, *old_user_data; |
| 2028 | |
| 2029 | PJ_UNUSED_ARG(pSelf); |
| 2030 | |
| 2031 | if (!PyArg_ParseTuple(pArgs, "iO", &buddy_id, &user_data)) { |
| 2032 | return NULL; |
| 2033 | } |
| 2034 | |
| 2035 | old_user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); |
| 2036 | |
| 2037 | status = pjsua_buddy_set_user_data(buddy_id, (void*)user_data); |
| 2038 | |
| 2039 | if (status == PJ_SUCCESS) { |
| 2040 | Py_XINCREF(user_data); |
| 2041 | Py_XDECREF(old_user_data); |
| 2042 | } |
| 2043 | |
| 2044 | return Py_BuildValue("i", status); |
| 2045 | } |
| 2046 | |
| 2047 | /* |
| 2048 | * py_pjsua_buddy_get_user_data |
| 2049 | */ |
| 2050 | static PyObject *py_pjsua_buddy_get_user_data(PyObject *pSelf, PyObject *pArgs) |
| 2051 | { |
| 2052 | int buddy_id; |
| 2053 | PyObject *user_data; |
| 2054 | |
| 2055 | PJ_UNUSED_ARG(pSelf); |
| 2056 | |
| 2057 | if (!PyArg_ParseTuple(pArgs, "i", &buddy_id)) { |
| 2058 | return NULL; |
| 2059 | } |
| 2060 | |
| 2061 | user_data = (PyObject*) pjsua_buddy_get_user_data(buddy_id); |
| 2062 | |
| 2063 | return user_data? Py_BuildValue("O", user_data) : Py_BuildValue(""); |
| 2064 | } |
| 2065 | |
| 2066 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2067 | * py_pjsua_buddy_subscribe_pres |
| 2068 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2069 | static PyObject *py_pjsua_buddy_subscribe_pres(PyObject *pSelf, |
| 2070 | PyObject *pArgs) |
| 2071 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2072 | int buddy_id; |
| 2073 | int status; |
| 2074 | int subscribe; |
| 2075 | |
| 2076 | PJ_UNUSED_ARG(pSelf); |
| 2077 | |
| 2078 | if (!PyArg_ParseTuple(pArgs, "ii", &buddy_id, &subscribe)) { |
| 2079 | return NULL; |
| 2080 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2081 | |
| 2082 | status = pjsua_buddy_subscribe_pres(buddy_id, subscribe); |
| 2083 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2084 | return Py_BuildValue("i", status); |
| 2085 | } |
| 2086 | |
| 2087 | /* |
| 2088 | * py_pjsua_pres_dump |
| 2089 | */ |
| 2090 | static PyObject *py_pjsua_pres_dump(PyObject *pSelf, PyObject *pArgs) |
| 2091 | { |
| 2092 | int verbose; |
| 2093 | |
| 2094 | PJ_UNUSED_ARG(pSelf); |
| 2095 | |
| 2096 | if (!PyArg_ParseTuple(pArgs, "i", &verbose)) { |
| 2097 | return NULL; |
| 2098 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2099 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2100 | pjsua_pres_dump(verbose); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2101 | |
| 2102 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | /* |
| 2106 | * py_pjsua_im_send |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2107 | */ |
| 2108 | static PyObject *py_pjsua_im_send(PyObject *pSelf, PyObject *pArgs) |
| 2109 | { |
| 2110 | int status; |
| 2111 | int acc_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2112 | pj_str_t *mime_type, tmp_mime_type; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2113 | pj_str_t to, content; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2114 | PyObject *pTo; |
| 2115 | PyObject *pMimeType; |
| 2116 | PyObject *pContent; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2117 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2118 | PyObject *pMsgData; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2119 | int user_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2120 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2121 | |
| 2122 | PJ_UNUSED_ARG(pSelf); |
| 2123 | |
| 2124 | if (!PyArg_ParseTuple(pArgs, "iOOOOi", &acc_id, |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2125 | &pTo, &pMimeType, &pContent, &pMsgData, &user_data)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2126 | { |
| 2127 | return NULL; |
| 2128 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2129 | |
| 2130 | if (pMimeType != Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2131 | mime_type = &tmp_mime_type; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2132 | tmp_mime_type = PyString_ToPJ(pMimeType); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2133 | } else { |
| 2134 | mime_type = NULL; |
| 2135 | } |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2136 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2137 | to = PyString_ToPJ(pTo); |
| 2138 | content = PyString_ToPJ(pContent); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2139 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2140 | if (pMsgData != Py_None) { |
| 2141 | PyObj_pjsua_msg_data *omd; |
| 2142 | |
| 2143 | omd = (PyObj_pjsua_msg_data *)pMsgData; |
| 2144 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 2145 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 2146 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2147 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2148 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2149 | |
| 2150 | status = pjsua_im_send(acc_id, &to, mime_type, &content, |
| 2151 | &msg_data, (void *)user_data); |
| 2152 | if (pool) |
| 2153 | pj_pool_release(pool); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2154 | |
| 2155 | return Py_BuildValue("i",status); |
| 2156 | } |
| 2157 | |
| 2158 | /* |
| 2159 | * py_pjsua_im_typing |
| 2160 | */ |
| 2161 | static PyObject *py_pjsua_im_typing(PyObject *pSelf, PyObject *pArgs) |
| 2162 | { |
| 2163 | int status; |
| 2164 | int acc_id; |
| 2165 | pj_str_t to; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2166 | PyObject *pTo; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2167 | int is_typing; |
| 2168 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2169 | PyObject *pMsgData; |
| 2170 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2171 | |
| 2172 | PJ_UNUSED_ARG(pSelf); |
| 2173 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2174 | if (!PyArg_ParseTuple(pArgs, "iOiO", &acc_id, &pTo, &is_typing, |
| 2175 | &pMsgData)) |
| 2176 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2177 | return NULL; |
| 2178 | } |
| 2179 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2180 | to = PyString_ToPJ(pTo); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2181 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2182 | if (pMsgData != Py_None) { |
| 2183 | PyObj_pjsua_msg_data *omd; |
| 2184 | |
| 2185 | omd = (PyObj_pjsua_msg_data *)pMsgData; |
| 2186 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 2187 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 2188 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2189 | |
| 2190 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2191 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2192 | |
| 2193 | status = pjsua_im_typing(acc_id, &to, is_typing, &msg_data); |
| 2194 | |
| 2195 | if (pool) |
| 2196 | pj_pool_release(pool); |
| 2197 | |
| 2198 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | static char pjsua_buddy_config_default_doc[] = |
| 2202 | "_pjsua.Buddy_Config _pjsua.buddy_config_default () " |
| 2203 | "Set default values to the buddy config."; |
| 2204 | static char pjsua_get_buddy_count_doc[] = |
| 2205 | "int _pjsua.get_buddy_count () " |
| 2206 | "Get total number of buddies."; |
| 2207 | static char pjsua_buddy_is_valid_doc[] = |
| 2208 | "int _pjsua.buddy_is_valid (int buddy_id) " |
| 2209 | "Check if buddy ID is valid."; |
| 2210 | static char pjsua_enum_buddies_doc[] = |
| 2211 | "int[] _pjsua.enum_buddies () " |
| 2212 | "Enum buddy IDs."; |
| 2213 | static char pjsua_buddy_get_info_doc[] = |
| 2214 | "_pjsua.Buddy_Info _pjsua.buddy_get_info (int buddy_id) " |
| 2215 | "Get detailed buddy info."; |
| 2216 | static char pjsua_buddy_add_doc[] = |
| 2217 | "int,int _pjsua.buddy_add (_pjsua.Buddy_Config cfg) " |
| 2218 | "Add new buddy."; |
| 2219 | static char pjsua_buddy_del_doc[] = |
| 2220 | "int _pjsua.buddy_del (int buddy_id) " |
| 2221 | "Delete buddy."; |
| 2222 | static char pjsua_buddy_subscribe_pres_doc[] = |
| 2223 | "int _pjsua.buddy_subscribe_pres (int buddy_id, int subscribe) " |
| 2224 | "Enable/disable buddy's presence monitoring."; |
| 2225 | static char pjsua_pres_dump_doc[] = |
| 2226 | "void _pjsua.pres_dump (int verbose) " |
| 2227 | "Dump presence subscriptions to log file."; |
| 2228 | static char pjsua_im_send_doc[] = |
| 2229 | "int _pjsua.im_send (int acc_id, string to, string mime_type, " |
| 2230 | "string content, _pjsua.Msg_Data msg_data, int user_data) " |
| 2231 | "Send instant messaging outside dialog, using the specified account " |
| 2232 | "for route set and authentication."; |
| 2233 | static char pjsua_im_typing_doc[] = |
| 2234 | "int _pjsua.im_typing (int acc_id, string to, int is_typing, " |
| 2235 | "_pjsua.Msg_Data msg_data) " |
| 2236 | "Send typing indication outside dialog."; |
| 2237 | |
| 2238 | /* END OF LIB BUDDY */ |
| 2239 | |
| 2240 | /* LIB MEDIA */ |
| 2241 | |
| 2242 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2243 | /* |
| 2244 | * py_pjsua_conf_get_max_ports |
| 2245 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2246 | static PyObject *py_pjsua_conf_get_max_ports(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2247 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2248 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2249 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2250 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2251 | return Py_BuildValue("i", pjsua_conf_get_max_ports()); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /* |
| 2255 | * py_pjsua_conf_get_active_ports |
| 2256 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2257 | static PyObject *py_pjsua_conf_get_active_ports(PyObject *pSelf, |
| 2258 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2259 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2260 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2261 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2262 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2263 | return Py_BuildValue("i", pjsua_conf_get_active_ports()); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /* |
| 2267 | * py_pjsua_enum_conf_ports |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2268 | */ |
| 2269 | static PyObject *py_pjsua_enum_conf_ports(PyObject *pSelf, PyObject *pArgs) |
| 2270 | { |
| 2271 | pj_status_t status; |
| 2272 | PyObject *list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2273 | pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS]; |
| 2274 | unsigned c, i; |
| 2275 | |
| 2276 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2277 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2278 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2279 | c = PJ_ARRAY_SIZE(id); |
| 2280 | status = pjsua_enum_conf_ports(id, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2281 | if (status != PJ_SUCCESS) |
| 2282 | c = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2283 | |
| 2284 | list = PyList_New(c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2285 | for (i = 0; i < c; i++) { |
| 2286 | PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2289 | return (PyObject*)list; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /* |
| 2293 | * py_pjsua_conf_get_port_info |
| 2294 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2295 | static PyObject *py_pjsua_conf_get_port_info(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2296 | { |
| 2297 | int id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2298 | PyObj_pjsua_conf_port_info *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2299 | pjsua_conf_port_info info; |
| 2300 | int status; |
| 2301 | unsigned i; |
| 2302 | |
| 2303 | PJ_UNUSED_ARG(pSelf); |
| 2304 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2305 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2306 | return NULL; |
| 2307 | } |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2308 | |
| 2309 | status = pjsua_conf_get_port_info(id, &info); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2310 | ret = (PyObj_pjsua_conf_port_info *) |
| 2311 | conf_port_info_new(&PyTyp_pjsua_conf_port_info, NULL, NULL); |
| 2312 | ret->bits_per_sample = info.bits_per_sample; |
| 2313 | ret->channel_count = info.bits_per_sample; |
| 2314 | ret->clock_rate = info.clock_rate; |
| 2315 | ret->name = PyString_FromPJ(&info.name); |
| 2316 | ret->samples_per_frame = info.samples_per_frame; |
| 2317 | ret->slot_id = info.slot_id; |
| 2318 | Py_XDECREF(ret->listeners); |
| 2319 | ret->listeners = PyList_New(info.listener_cnt); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2320 | for (i = 0; i < info.listener_cnt; i++) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2321 | PyObject *item = Py_BuildValue("i",info.listeners[i]); |
| 2322 | PyList_SetItem(ret->listeners, i, item); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2323 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2324 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | /* |
| 2328 | * py_pjsua_conf_remove_port |
| 2329 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2330 | static PyObject *py_pjsua_conf_remove_port(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2331 | { |
| 2332 | int id; |
| 2333 | int status; |
| 2334 | |
| 2335 | PJ_UNUSED_ARG(pSelf); |
| 2336 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2337 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2338 | return NULL; |
| 2339 | } |
| 2340 | |
| 2341 | status = pjsua_conf_remove_port(id); |
| 2342 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2343 | return Py_BuildValue("i", status); |
| 2344 | } |
| 2345 | |
| 2346 | /* |
| 2347 | * py_pjsua_conf_connect |
| 2348 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2349 | static PyObject *py_pjsua_conf_connect(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2350 | { |
| 2351 | int source, sink; |
| 2352 | int status; |
| 2353 | |
| 2354 | PJ_UNUSED_ARG(pSelf); |
| 2355 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2356 | if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2357 | return NULL; |
| 2358 | } |
| 2359 | |
| 2360 | status = pjsua_conf_connect(source, sink); |
| 2361 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2362 | return Py_BuildValue("i", status); |
| 2363 | } |
| 2364 | |
| 2365 | /* |
| 2366 | * py_pjsua_conf_disconnect |
| 2367 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2368 | static PyObject *py_pjsua_conf_disconnect(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2369 | { |
| 2370 | int source, sink; |
| 2371 | int status; |
| 2372 | |
| 2373 | PJ_UNUSED_ARG(pSelf); |
| 2374 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2375 | if (!PyArg_ParseTuple(pArgs, "ii", &source, &sink)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2376 | return NULL; |
| 2377 | } |
| 2378 | |
| 2379 | status = pjsua_conf_disconnect(source, sink); |
| 2380 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2381 | return Py_BuildValue("i", status); |
| 2382 | } |
| 2383 | |
| 2384 | /* |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2385 | * py_pjsua_conf_set_tx_level |
| 2386 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2387 | static PyObject *py_pjsua_conf_set_tx_level(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2388 | { |
| 2389 | int slot; |
| 2390 | float level; |
| 2391 | int status; |
| 2392 | |
| 2393 | PJ_UNUSED_ARG(pSelf); |
| 2394 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2395 | if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2396 | return NULL; |
| 2397 | } |
| 2398 | |
| 2399 | status = pjsua_conf_adjust_tx_level(slot, level); |
| 2400 | |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2401 | return Py_BuildValue("i", status); |
| 2402 | } |
| 2403 | |
| 2404 | /* |
| 2405 | * py_pjsua_conf_set_rx_level |
| 2406 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2407 | static PyObject *py_pjsua_conf_set_rx_level(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2408 | { |
| 2409 | int slot; |
| 2410 | float level; |
| 2411 | int status; |
| 2412 | |
| 2413 | PJ_UNUSED_ARG(pSelf); |
| 2414 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2415 | if (!PyArg_ParseTuple(pArgs, "if", &slot, &level)) { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2416 | return NULL; |
| 2417 | } |
| 2418 | |
| 2419 | status = pjsua_conf_adjust_rx_level(slot, level); |
| 2420 | |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2421 | return Py_BuildValue("i", status); |
| 2422 | } |
| 2423 | |
| 2424 | /* |
| 2425 | * py_pjsua_conf_get_signal_level |
| 2426 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2427 | static PyObject *py_pjsua_conf_get_signal_level(PyObject *pSelf, |
| 2428 | PyObject *pArgs) |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2429 | { |
| 2430 | int slot; |
| 2431 | unsigned tx_level, rx_level; |
| 2432 | int status; |
| 2433 | |
| 2434 | PJ_UNUSED_ARG(pSelf); |
| 2435 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2436 | if (!PyArg_ParseTuple(pArgs, "i", &slot)) { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2437 | return NULL; |
| 2438 | } |
| 2439 | |
| 2440 | status = pjsua_conf_get_signal_level(slot, &tx_level, &rx_level); |
| 2441 | |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2442 | return Py_BuildValue("iff", status, (float)(tx_level/255.0), |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2443 | (float)(rx_level/255.0)); |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2447 | * py_pjsua_player_create |
| 2448 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2449 | static PyObject *py_pjsua_player_create(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2450 | { |
| 2451 | int id; |
| 2452 | int options; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2453 | PyObject *pFilename; |
| 2454 | pj_str_t filename; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2455 | int status; |
| 2456 | |
| 2457 | PJ_UNUSED_ARG(pSelf); |
| 2458 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2459 | if (!PyArg_ParseTuple(pArgs, "Oi", &pFilename, &options)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2460 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | filename = PyString_ToPJ(pFilename); |
| 2464 | status = pjsua_player_create(&filename, options, &id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2465 | |
| 2466 | return Py_BuildValue("ii", status, id); |
| 2467 | } |
| 2468 | |
| 2469 | /* |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2470 | * py_pjsua_playlist_create |
| 2471 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2472 | static PyObject *py_pjsua_playlist_create(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2473 | { |
| 2474 | int id; |
| 2475 | int options; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2476 | PyObject *pLabel, *pFileList; |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2477 | pj_str_t label; |
| 2478 | int count; |
| 2479 | pj_str_t files[64]; |
| 2480 | int status; |
| 2481 | |
| 2482 | PJ_UNUSED_ARG(pSelf); |
| 2483 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2484 | if (!PyArg_ParseTuple(pArgs, "OOi", &pLabel, &pFileList, &options)) { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2485 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2486 | } |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2487 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2488 | label = PyString_ToPJ(pLabel); |
| 2489 | if (!PyList_Check(pFileList)) |
| 2490 | return Py_BuildValue("ii", PJ_EINVAL, PJSUA_INVALID_ID); |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2491 | |
| 2492 | count = 0; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2493 | for (count=0; count<PyList_Size(pFileList) && |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2494 | count<PJ_ARRAY_SIZE(files); ++count) |
| 2495 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2496 | files[count] = PyString_ToPJ(PyList_GetItem(pFileList, count)); |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | status = pjsua_playlist_create(files, count, &label, options, &id); |
| 2500 | |
| 2501 | return Py_BuildValue("ii", status, id); |
| 2502 | } |
| 2503 | |
| 2504 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2505 | * py_pjsua_player_get_conf_port |
| 2506 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2507 | static PyObject *py_pjsua_player_get_conf_port(PyObject *pSelf, |
| 2508 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2509 | { |
| 2510 | |
| 2511 | int id, port_id; |
| 2512 | |
| 2513 | PJ_UNUSED_ARG(pSelf); |
| 2514 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2515 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2516 | return NULL; |
| 2517 | } |
| 2518 | |
| 2519 | port_id = pjsua_player_get_conf_port(id); |
| 2520 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2521 | return Py_BuildValue("i", port_id); |
| 2522 | } |
| 2523 | |
| 2524 | /* |
| 2525 | * py_pjsua_player_set_pos |
| 2526 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2527 | static PyObject *py_pjsua_player_set_pos(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2528 | { |
| 2529 | int id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2530 | int samples; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2531 | int status; |
| 2532 | |
| 2533 | PJ_UNUSED_ARG(pSelf); |
| 2534 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2535 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &samples)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2536 | return NULL; |
| 2537 | } |
| 2538 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2539 | if (samples < 0) |
| 2540 | samples = 0; |
| 2541 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2542 | status = pjsua_player_set_pos(id, samples); |
| 2543 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2544 | return Py_BuildValue("i", status); |
| 2545 | } |
| 2546 | |
| 2547 | /* |
| 2548 | * py_pjsua_player_destroy |
| 2549 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2550 | static PyObject *py_pjsua_player_destroy(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2551 | { |
| 2552 | int id; |
| 2553 | int status; |
| 2554 | |
| 2555 | PJ_UNUSED_ARG(pSelf); |
| 2556 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2557 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2558 | return NULL; |
| 2559 | } |
| 2560 | |
| 2561 | status = pjsua_player_destroy(id); |
| 2562 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2563 | return Py_BuildValue("i", status); |
| 2564 | } |
| 2565 | |
| 2566 | /* |
| 2567 | * py_pjsua_recorder_create |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2568 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2569 | static PyObject *py_pjsua_recorder_create(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2570 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2571 | int id, options; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2572 | int max_size; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2573 | PyObject *pFilename, *pEncParam; |
| 2574 | pj_str_t filename; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2575 | int enc_type; |
| 2576 | |
| 2577 | int status; |
| 2578 | |
| 2579 | PJ_UNUSED_ARG(pSelf); |
| 2580 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2581 | if (!PyArg_ParseTuple(pArgs, "OiOii", &pFilename, &enc_type, &pEncParam, |
| 2582 | &max_size, &options)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2583 | { |
| 2584 | return NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2585 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2586 | |
| 2587 | filename = PyString_ToPJ(pFilename); |
| 2588 | |
| 2589 | status = pjsua_recorder_create(&filename, enc_type, NULL, max_size, |
| 2590 | options, &id); |
| 2591 | |
| 2592 | return Py_BuildValue("ii", status, id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | /* |
| 2596 | * py_pjsua_recorder_get_conf_port |
| 2597 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2598 | static PyObject *py_pjsua_recorder_get_conf_port(PyObject *pSelf, |
| 2599 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2600 | { |
| 2601 | |
| 2602 | int id, port_id; |
| 2603 | |
| 2604 | PJ_UNUSED_ARG(pSelf); |
| 2605 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2606 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2607 | return NULL; |
| 2608 | } |
| 2609 | |
| 2610 | port_id = pjsua_recorder_get_conf_port(id); |
| 2611 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2612 | return Py_BuildValue("i", port_id); |
| 2613 | } |
| 2614 | |
| 2615 | /* |
| 2616 | * py_pjsua_recorder_destroy |
| 2617 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2618 | static PyObject *py_pjsua_recorder_destroy(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2619 | { |
| 2620 | int id; |
| 2621 | int status; |
| 2622 | |
| 2623 | PJ_UNUSED_ARG(pSelf); |
| 2624 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2625 | if (!PyArg_ParseTuple(pArgs, "i", &id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2626 | return NULL; |
| 2627 | } |
| 2628 | |
| 2629 | status = pjsua_recorder_destroy(id); |
| 2630 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2631 | return Py_BuildValue("i", status); |
| 2632 | } |
| 2633 | |
| 2634 | /* |
| 2635 | * py_pjsua_enum_snd_devs |
| 2636 | */ |
| 2637 | static PyObject *py_pjsua_enum_snd_devs(PyObject *pSelf, PyObject *pArgs) |
| 2638 | { |
| 2639 | pj_status_t status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2640 | PyObject *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2641 | pjmedia_snd_dev_info info[SND_DEV_NUM]; |
| 2642 | unsigned c, i; |
| 2643 | |
| 2644 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2645 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2646 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2647 | c = PJ_ARRAY_SIZE(info); |
| 2648 | status = pjsua_enum_snd_devs(info, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2649 | if (status != PJ_SUCCESS) |
| 2650 | c = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2651 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2652 | ret = PyList_New(c); |
| 2653 | for (i = 0; i < c; i++) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2654 | PyObj_pjmedia_snd_dev_info * obj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2655 | |
| 2656 | obj = (PyObj_pjmedia_snd_dev_info *) |
| 2657 | pjmedia_snd_dev_info_new(&PyTyp_pjmedia_snd_dev_info, |
| 2658 | NULL, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2659 | obj->default_samples_per_sec = info[i].default_samples_per_sec; |
| 2660 | obj->input_count = info[i].input_count; |
| 2661 | obj->output_count = info[i].output_count; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2662 | obj->name = PyString_FromString(info[i].name); |
| 2663 | |
| 2664 | PyList_SetItem(ret, i, (PyObject *)obj); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2667 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | /* |
| 2671 | * py_pjsua_get_snd_dev |
| 2672 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2673 | static PyObject *py_pjsua_get_snd_dev(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2674 | { |
| 2675 | int capture_dev, playback_dev; |
| 2676 | int status; |
| 2677 | |
| 2678 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2679 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2680 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2681 | status = pjsua_get_snd_dev(&capture_dev, &playback_dev); |
| 2682 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2683 | return Py_BuildValue("ii", capture_dev, playback_dev); |
| 2684 | } |
| 2685 | |
| 2686 | /* |
| 2687 | * py_pjsua_set_snd_dev |
| 2688 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2689 | static PyObject *py_pjsua_set_snd_dev(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2690 | { |
| 2691 | int capture_dev, playback_dev; |
| 2692 | int status; |
| 2693 | |
| 2694 | PJ_UNUSED_ARG(pSelf); |
| 2695 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2696 | if (!PyArg_ParseTuple(pArgs, "ii", &capture_dev, &playback_dev)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2697 | return NULL; |
| 2698 | } |
| 2699 | |
| 2700 | status = pjsua_set_snd_dev(capture_dev, playback_dev); |
| 2701 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2702 | return Py_BuildValue("i", status); |
| 2703 | } |
| 2704 | |
| 2705 | /* |
| 2706 | * py_pjsua_set_null_snd_dev |
| 2707 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2708 | static PyObject *py_pjsua_set_null_snd_dev(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2709 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2710 | int status; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2711 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2712 | PJ_UNUSED_ARG(pSelf); |
| 2713 | PJ_UNUSED_ARG(pArgs); |
| 2714 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2715 | status = pjsua_set_null_snd_dev(); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2716 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2717 | return Py_BuildValue("i", status); |
| 2718 | } |
| 2719 | |
| 2720 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2721 | * py_pjsua_set_ec |
| 2722 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2723 | static PyObject *py_pjsua_set_ec(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2724 | { |
| 2725 | int options; |
| 2726 | int tail_ms; |
| 2727 | int status; |
| 2728 | |
| 2729 | PJ_UNUSED_ARG(pSelf); |
| 2730 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2731 | if (!PyArg_ParseTuple(pArgs, "ii", &tail_ms, &options)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2732 | return NULL; |
| 2733 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2734 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2735 | status = pjsua_set_ec(tail_ms, options); |
| 2736 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2737 | return Py_BuildValue("i", status); |
| 2738 | } |
| 2739 | |
| 2740 | /* |
| 2741 | * py_pjsua_get_ec_tail |
| 2742 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2743 | static PyObject *py_pjsua_get_ec_tail(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2744 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2745 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2746 | unsigned tail_ms; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2747 | |
| 2748 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2749 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2750 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2751 | status = pjsua_get_ec_tail(&tail_ms); |
| 2752 | if (status != PJ_SUCCESS) |
| 2753 | tail_ms = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2754 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2755 | return Py_BuildValue("i", tail_ms); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /* |
| 2759 | * py_pjsua_enum_codecs |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2760 | */ |
| 2761 | static PyObject *py_pjsua_enum_codecs(PyObject *pSelf, PyObject *pArgs) |
| 2762 | { |
| 2763 | pj_status_t status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2764 | PyObject *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2765 | pjsua_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS]; |
| 2766 | unsigned c, i; |
| 2767 | |
| 2768 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2769 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2770 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2771 | c = PJ_ARRAY_SIZE(info); |
| 2772 | status = pjsua_enum_codecs(info, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2773 | if (status != PJ_SUCCESS) |
| 2774 | c = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2775 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2776 | ret = PyList_New(c); |
| 2777 | for (i = 0; i < c; i++) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2778 | PyObj_pjsua_codec_info * obj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2779 | obj = (PyObj_pjsua_codec_info *) |
| 2780 | codec_info_new(&PyTyp_pjsua_codec_info, NULL, NULL); |
| 2781 | obj->codec_id = PyString_FromPJ(&info[i].codec_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2782 | obj->priority = info[i].priority; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2783 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2784 | PyList_SetItem(ret, i, (PyObject *)obj); |
| 2785 | } |
| 2786 | |
| 2787 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | /* |
| 2791 | * py_pjsua_codec_set_priority |
| 2792 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2793 | static PyObject *py_pjsua_codec_set_priority(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2794 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2795 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2796 | PyObject *pCodecId; |
| 2797 | pj_str_t codec_id; |
| 2798 | int priority; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2799 | |
| 2800 | PJ_UNUSED_ARG(pSelf); |
| 2801 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2802 | if (!PyArg_ParseTuple(pArgs, "Oi", &pCodecId, &priority)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2803 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | codec_id = PyString_ToPJ(pCodecId); |
| 2807 | if (priority < 0) |
| 2808 | priority = 0; |
| 2809 | if (priority > 255) |
| 2810 | priority = 255; |
| 2811 | |
| 2812 | status = pjsua_codec_set_priority(&codec_id, (pj_uint8_t)priority); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2813 | |
| 2814 | return Py_BuildValue("i", status); |
| 2815 | } |
| 2816 | |
| 2817 | /* |
| 2818 | * py_pjsua_codec_get_param |
| 2819 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2820 | static PyObject *py_pjsua_codec_get_param(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2821 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2822 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2823 | PyObject *pCodecId; |
| 2824 | pj_str_t codec_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2825 | pjmedia_codec_param param; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2826 | PyObj_pjmedia_codec_param *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2827 | |
| 2828 | PJ_UNUSED_ARG(pSelf); |
| 2829 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2830 | if (!PyArg_ParseTuple(pArgs, "O", &pCodecId)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2831 | return NULL; |
| 2832 | } |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2833 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2834 | codec_id = PyString_ToPJ(pCodecId); |
| 2835 | |
| 2836 | status = pjsua_codec_get_param(&codec_id, ¶m); |
| 2837 | if (status != PJ_SUCCESS) |
| 2838 | return Py_BuildValue(""); |
| 2839 | |
| 2840 | ret = (PyObj_pjmedia_codec_param *) |
| 2841 | pjmedia_codec_param_new(&PyTyp_pjmedia_codec_param, NULL, NULL); |
| 2842 | |
| 2843 | ret->info->avg_bps = param.info.avg_bps; |
| 2844 | ret->info->channel_cnt = param.info.channel_cnt; |
| 2845 | ret->info->clock_rate = param.info.clock_rate; |
| 2846 | ret->info->frm_ptime = param.info.frm_ptime; |
| 2847 | ret->info->pcm_bits_per_sample = param.info.pcm_bits_per_sample; |
| 2848 | ret->info->pt = param.info.pt; |
| 2849 | ret->setting->cng = param.setting.cng; |
| 2850 | ret->setting->dec_fmtp_mode = param.setting.dec_fmtp_mode; |
| 2851 | ret->setting->enc_fmtp_mode = param.setting.enc_fmtp_mode; |
| 2852 | ret->setting->frm_per_pkt = param.setting.frm_per_pkt; |
| 2853 | ret->setting->penh = param.setting.penh; |
| 2854 | ret->setting->plc = param.setting.plc; |
| 2855 | ret->setting->vad = param.setting.vad; |
| 2856 | |
| 2857 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2858 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2859 | |
| 2860 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2861 | /* |
| 2862 | * py_pjsua_codec_set_param |
| 2863 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2864 | static PyObject *py_pjsua_codec_set_param(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2865 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2866 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2867 | PyObject *pCodecId, *pCodecParam; |
| 2868 | pj_str_t codec_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2869 | pjmedia_codec_param param; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2870 | |
| 2871 | PJ_UNUSED_ARG(pSelf); |
| 2872 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2873 | if (!PyArg_ParseTuple(pArgs, "OO", &pCodecId, &pCodecParam)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2874 | return NULL; |
| 2875 | } |
| 2876 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2877 | codec_id = PyString_ToPJ(pCodecId); |
| 2878 | |
| 2879 | if (pCodecParam != Py_None) { |
| 2880 | PyObj_pjmedia_codec_param *obj; |
| 2881 | |
| 2882 | obj = (PyObj_pjmedia_codec_param *)pCodecParam; |
| 2883 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2884 | param.info.avg_bps = obj->info->avg_bps; |
| 2885 | param.info.channel_cnt = obj->info->channel_cnt; |
| 2886 | param.info.clock_rate = obj->info->clock_rate; |
| 2887 | param.info.frm_ptime = obj->info->frm_ptime; |
| 2888 | param.info.pcm_bits_per_sample = obj->info->pcm_bits_per_sample; |
| 2889 | param.info.pt = obj->info->pt; |
| 2890 | param.setting.cng = obj->setting->cng; |
| 2891 | param.setting.dec_fmtp_mode = obj->setting->dec_fmtp_mode; |
| 2892 | param.setting.enc_fmtp_mode = obj->setting->enc_fmtp_mode; |
| 2893 | param.setting.frm_per_pkt = obj->setting->frm_per_pkt; |
| 2894 | param.setting.penh = obj->setting->penh; |
| 2895 | param.setting.plc = obj->setting->plc; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2896 | param.setting.vad = obj->setting->vad; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2897 | status = pjsua_codec_set_param(&codec_id, ¶m); |
| 2898 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2899 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2900 | status = pjsua_codec_set_param(&codec_id, NULL); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2901 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 2902 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2903 | return Py_BuildValue("i", status); |
| 2904 | } |
| 2905 | |
| 2906 | static char pjsua_conf_get_max_ports_doc[] = |
| 2907 | "int _pjsua.conf_get_max_ports () " |
| 2908 | "Get maxinum number of conference ports."; |
| 2909 | static char pjsua_conf_get_active_ports_doc[] = |
| 2910 | "int _pjsua.conf_get_active_ports () " |
| 2911 | "Get current number of active ports in the bridge."; |
| 2912 | static char pjsua_enum_conf_ports_doc[] = |
| 2913 | "int[] _pjsua.enum_conf_ports () " |
| 2914 | "Enumerate all conference ports."; |
| 2915 | static char pjsua_conf_get_port_info_doc[] = |
| 2916 | "_pjsua.Conf_Port_Info _pjsua.conf_get_port_info (int id) " |
| 2917 | "Get information about the specified conference port"; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2918 | static char pjsua_conf_remove_port_doc[] = |
| 2919 | "int _pjsua.conf_remove_port (int id) " |
| 2920 | "Remove arbitrary slot from the conference bridge. " |
| 2921 | "Application should only call this function " |
| 2922 | "if it registered the port manually."; |
| 2923 | static char pjsua_conf_connect_doc[] = |
| 2924 | "int _pjsua.conf_connect (int source, int sink) " |
| 2925 | "Establish unidirectional media flow from souce to sink. " |
| 2926 | "One source may transmit to multiple destinations/sink. " |
| 2927 | "And if multiple sources are transmitting to the same sink, " |
| 2928 | "the media will be mixed together. Source and sink may refer " |
| 2929 | "to the same ID, effectively looping the media. " |
| 2930 | "If bidirectional media flow is desired, application " |
| 2931 | "needs to call this function twice, with the second " |
| 2932 | "one having the arguments reversed."; |
| 2933 | static char pjsua_conf_disconnect_doc[] = |
| 2934 | "int _pjsua.conf_disconnect (int source, int sink) " |
| 2935 | "Disconnect media flow from the source to destination port."; |
| 2936 | static char pjsua_player_create_doc[] = |
| 2937 | "int, int _pjsua.player_create (string filename, int options) " |
| 2938 | "Create a file player, and automatically connect " |
| 2939 | "this player to the conference bridge."; |
| 2940 | static char pjsua_player_get_conf_port_doc[] = |
| 2941 | "int _pjsua.player_get_conf_port (int) " |
| 2942 | "Get conference port ID associated with player."; |
| 2943 | static char pjsua_player_set_pos_doc[] = |
| 2944 | "int _pjsua.player_set_pos (int id, int samples) " |
| 2945 | "Set playback position."; |
| 2946 | static char pjsua_player_destroy_doc[] = |
| 2947 | "int _pjsua.player_destroy (int id) " |
| 2948 | "Close the file, remove the player from the bridge, " |
| 2949 | "and free resources associated with the file player."; |
| 2950 | static char pjsua_recorder_create_doc[] = |
| 2951 | "int, int _pjsua.recorder_create (string filename, " |
| 2952 | "int enc_type, int enc_param, int max_size, int options) " |
| 2953 | "Create a file recorder, and automatically connect this recorder " |
| 2954 | "to the conference bridge. The recorder currently supports recording " |
| 2955 | "WAV file, and on Windows, MP3 file. The type of the recorder to use " |
| 2956 | "is determined by the extension of the file (e.g. '.wav' or '.mp3')."; |
| 2957 | static char pjsua_recorder_get_conf_port_doc[] = |
| 2958 | "int _pjsua.recorder_get_conf_port (int id) " |
| 2959 | "Get conference port associated with recorder."; |
| 2960 | static char pjsua_recorder_destroy_doc[] = |
| 2961 | "int _pjsua.recorder_destroy (int id) " |
| 2962 | "Destroy recorder (this will complete recording)."; |
| 2963 | static char pjsua_enum_snd_devs_doc[] = |
| 2964 | "_pjsua.PJMedia_Snd_Dev_Info[] _pjsua.enum_snd_devs (int count) " |
| 2965 | "Enum sound devices."; |
| 2966 | static char pjsua_get_snd_dev_doc[] = |
| 2967 | "int, int _pjsua.get_snd_dev () " |
| 2968 | "Get currently active sound devices. " |
| 2969 | "If sound devices has not been created " |
| 2970 | "(for example when pjsua_start() is not called), " |
| 2971 | "it is possible that the function returns " |
| 2972 | "PJ_SUCCESS with -1 as device IDs."; |
| 2973 | static char pjsua_set_snd_dev_doc[] = |
| 2974 | "int _pjsua.set_snd_dev (int capture_dev, int playback_dev) " |
| 2975 | "Select or change sound device. Application may call this function " |
| 2976 | "at any time to replace current sound device."; |
| 2977 | static char pjsua_set_null_snd_dev_doc[] = |
| 2978 | "int _pjsua.set_null_snd_dev () " |
| 2979 | "Set pjsua to use null sound device. The null sound device only " |
| 2980 | "provides the timing needed by the conference bridge, and will not " |
| 2981 | "interract with any hardware."; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 2982 | static char pjsua_set_ec_doc[] = |
| 2983 | "int _pjsua.set_ec (int tail_ms, int options) " |
| 2984 | "Configure the echo canceller tail length of the sound port."; |
| 2985 | static char pjsua_get_ec_tail_doc[] = |
| 2986 | "int _pjsua.get_ec_tail () " |
| 2987 | "Get current echo canceller tail length."; |
| 2988 | static char pjsua_enum_codecs_doc[] = |
| 2989 | "_pjsua.Codec_Info[] _pjsua.enum_codecs () " |
| 2990 | "Enum all supported codecs in the system."; |
| 2991 | static char pjsua_codec_set_priority_doc[] = |
| 2992 | "int _pjsua.codec_set_priority (string id, int priority) " |
| 2993 | "Change codec priority."; |
| 2994 | static char pjsua_codec_get_param_doc[] = |
| 2995 | "_pjsua.PJMedia_Codec_Param _pjsua.codec_get_param (string id) " |
| 2996 | "Get codec parameters"; |
| 2997 | static char pjsua_codec_set_param_doc[] = |
| 2998 | "int _pjsua.codec_set_param (string id, " |
| 2999 | "_pjsua.PJMedia_Codec_Param param) " |
| 3000 | "Set codec parameters."; |
| 3001 | |
| 3002 | /* END OF LIB MEDIA */ |
| 3003 | |
| 3004 | /* LIB CALL */ |
| 3005 | |
| 3006 | /* |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3007 | * py_pjsua_call_get_max_count |
| 3008 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3009 | static PyObject *py_pjsua_call_get_max_count(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3010 | { |
| 3011 | int count; |
| 3012 | |
| 3013 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3014 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3015 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3016 | count = pjsua_call_get_max_count(); |
| 3017 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3018 | return Py_BuildValue("i", count); |
| 3019 | } |
| 3020 | |
| 3021 | /* |
| 3022 | * py_pjsua_call_get_count |
| 3023 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3024 | static PyObject *py_pjsua_call_get_count(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3025 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3026 | int count; |
| 3027 | |
| 3028 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3029 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3030 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3031 | count = pjsua_call_get_count(); |
| 3032 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3033 | return Py_BuildValue("i", count); |
| 3034 | } |
| 3035 | |
| 3036 | /* |
| 3037 | * py_pjsua_enum_calls |
| 3038 | */ |
| 3039 | static PyObject *py_pjsua_enum_calls(PyObject *pSelf, PyObject *pArgs) |
| 3040 | { |
| 3041 | pj_status_t status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3042 | PyObject *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3043 | pjsua_transport_id id[PJSUA_MAX_CALLS]; |
| 3044 | unsigned c, i; |
| 3045 | |
| 3046 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3047 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3048 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3049 | c = PJ_ARRAY_SIZE(id); |
| 3050 | status = pjsua_enum_calls(id, &c); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3051 | if (status != PJ_SUCCESS) |
| 3052 | c = 0; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3053 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3054 | ret = PyList_New(c); |
| 3055 | for (i = 0; i < c; i++) { |
| 3056 | PyList_SetItem(ret, i, Py_BuildValue("i", id[i])); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3059 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | /* |
| 3063 | * py_pjsua_call_make_call |
| 3064 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3065 | static PyObject *py_pjsua_call_make_call(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3066 | { |
| 3067 | int status; |
| 3068 | int acc_id; |
| 3069 | pj_str_t dst_uri; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3070 | PyObject *pDstUri, *pMsgData, *pUserData; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3071 | unsigned options; |
| 3072 | pjsua_msg_data msg_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3073 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3074 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3075 | |
| 3076 | PJ_UNUSED_ARG(pSelf); |
| 3077 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3078 | if (!PyArg_ParseTuple(pArgs, "iOIOO", &acc_id, &pDstUri, &options, |
| 3079 | &pUserData, &pMsgData)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3080 | { |
| 3081 | return NULL; |
| 3082 | } |
| 3083 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3084 | dst_uri = PyString_ToPJ(pDstUri); |
| 3085 | pjsua_msg_data_init(&msg_data); |
| 3086 | |
| 3087 | if (pMsgData != Py_None) { |
| 3088 | PyObj_pjsua_msg_data * omd; |
| 3089 | |
| 3090 | omd = (PyObj_pjsua_msg_data *)pMsgData; |
| 3091 | |
| 3092 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3093 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3094 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3095 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3096 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3097 | |
| 3098 | Py_XINCREF(pUserData); |
| 3099 | |
| 3100 | status = pjsua_call_make_call(acc_id, &dst_uri, |
| 3101 | options, (void*)pUserData, |
| 3102 | &msg_data, &call_id); |
| 3103 | if (pool != NULL) |
| 3104 | pj_pool_release(pool); |
| 3105 | |
Benny Prijono | 680c39e | 2008-07-21 21:15:46 +0000 | [diff] [blame] | 3106 | if (status != PJ_SUCCESS) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3107 | Py_XDECREF(pUserData); |
Benny Prijono | 680c39e | 2008-07-21 21:15:46 +0000 | [diff] [blame] | 3108 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3109 | |
| 3110 | return Py_BuildValue("ii", status, call_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | /* |
| 3114 | * py_pjsua_call_is_active |
| 3115 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3116 | static PyObject *py_pjsua_call_is_active(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3117 | { |
| 3118 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3119 | int is_active; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3120 | |
| 3121 | PJ_UNUSED_ARG(pSelf); |
| 3122 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3123 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3124 | return NULL; |
| 3125 | } |
| 3126 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3127 | is_active = pjsua_call_is_active(call_id); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3128 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3129 | return Py_BuildValue("i", is_active); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | /* |
| 3133 | * py_pjsua_call_has_media |
| 3134 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3135 | static PyObject *py_pjsua_call_has_media(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3136 | { |
| 3137 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3138 | int has_media; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3139 | |
| 3140 | PJ_UNUSED_ARG(pSelf); |
| 3141 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3142 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3143 | return NULL; |
| 3144 | } |
| 3145 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3146 | has_media = pjsua_call_has_media(call_id); |
| 3147 | |
| 3148 | return Py_BuildValue("i", has_media); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | /* |
| 3152 | * py_pjsua_call_get_conf_port |
| 3153 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3154 | static PyObject* py_pjsua_call_get_conf_port(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3155 | { |
| 3156 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3157 | int port_id; |
| 3158 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3159 | PJ_UNUSED_ARG(pSelf); |
| 3160 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3161 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3162 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3165 | port_id = pjsua_call_get_conf_port(call_id); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3166 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3167 | return Py_BuildValue("i", port_id); |
| 3168 | } |
| 3169 | |
| 3170 | /* |
| 3171 | * py_pjsua_call_get_info |
| 3172 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3173 | static PyObject* py_pjsua_call_get_info(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3174 | { |
| 3175 | int call_id; |
| 3176 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3177 | PyObj_pjsua_call_info *ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3178 | pjsua_call_info info; |
| 3179 | |
| 3180 | PJ_UNUSED_ARG(pSelf); |
| 3181 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3182 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3183 | return NULL; |
| 3184 | } |
| 3185 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3186 | status = pjsua_call_get_info(call_id, &info); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3187 | if (status != PJ_SUCCESS) |
| 3188 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3189 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3190 | ret = (PyObj_pjsua_call_info *)call_info_new(&PyTyp_pjsua_call_info, |
| 3191 | NULL, NULL); |
| 3192 | ret->acc_id = info.acc_id; |
| 3193 | Py_XDECREF(ret->call_id); |
| 3194 | ret->call_id = PyString_FromPJ(&info.call_id); |
| 3195 | ret->conf_slot = info.conf_slot; |
| 3196 | ret->connect_duration = info.connect_duration.sec * 1000 + |
| 3197 | info.connect_duration.msec; |
| 3198 | ret->total_duration = info.total_duration.sec * 1000 + |
| 3199 | info.total_duration.msec; |
| 3200 | ret->id = info.id; |
| 3201 | ret->last_status = info.last_status; |
| 3202 | Py_XDECREF(ret->last_status_text); |
| 3203 | ret->last_status_text = PyString_FromPJ(&info.last_status_text); |
| 3204 | Py_XDECREF(ret->local_contact); |
| 3205 | ret->local_contact = PyString_FromPJ(&info.local_contact); |
| 3206 | Py_XDECREF(ret->local_info); |
| 3207 | ret->local_info = PyString_FromPJ(&info.local_info); |
| 3208 | Py_XDECREF(ret->remote_contact); |
| 3209 | ret->remote_contact = PyString_FromPJ(&info.remote_contact); |
| 3210 | Py_XDECREF(ret->remote_info); |
| 3211 | ret->remote_info = PyString_FromPJ(&info.remote_info); |
| 3212 | ret->media_dir = info.media_dir; |
| 3213 | ret->media_status = info.media_status; |
| 3214 | ret->role = info.role; |
| 3215 | ret->state = info.state; |
| 3216 | Py_XDECREF(ret->state_text); |
| 3217 | ret->state_text = PyString_FromPJ(&info.state_text); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3218 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3219 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | /* |
| 3223 | * py_pjsua_call_set_user_data |
| 3224 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3225 | static PyObject *py_pjsua_call_set_user_data(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3226 | { |
| 3227 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3228 | PyObject *pUserData, *old_user_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3229 | int status; |
| 3230 | |
| 3231 | PJ_UNUSED_ARG(pSelf); |
| 3232 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3233 | if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pUserData)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3234 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | old_user_data = (PyObject*) pjsua_call_get_user_data(call_id); |
| 3238 | |
| 3239 | if (old_user_data == pUserData) { |
| 3240 | return Py_BuildValue("i", PJ_SUCCESS); |
| 3241 | } |
| 3242 | |
| 3243 | Py_XINCREF(pUserData); |
| 3244 | Py_XDECREF(old_user_data); |
| 3245 | |
| 3246 | status = pjsua_call_set_user_data(call_id, (void*)pUserData); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3247 | |
Benny Prijono | 680c39e | 2008-07-21 21:15:46 +0000 | [diff] [blame] | 3248 | if (status != PJ_SUCCESS) { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3249 | Py_XDECREF(pUserData); |
Benny Prijono | 680c39e | 2008-07-21 21:15:46 +0000 | [diff] [blame] | 3250 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3251 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3252 | return Py_BuildValue("i", status); |
| 3253 | } |
| 3254 | |
| 3255 | /* |
| 3256 | * py_pjsua_call_get_user_data |
| 3257 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3258 | static PyObject *py_pjsua_call_get_user_data(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3259 | { |
| 3260 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3261 | PyObject *user_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3262 | |
| 3263 | PJ_UNUSED_ARG(pSelf); |
| 3264 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3265 | if (!PyArg_ParseTuple(pArgs, "i", &call_id)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3266 | return NULL; |
| 3267 | } |
| 3268 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3269 | user_data = (PyObject*)pjsua_call_get_user_data(call_id); |
| 3270 | return user_data ? Py_BuildValue("O", user_data) : Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | /* |
| 3274 | * py_pjsua_call_answer |
| 3275 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3276 | static PyObject *py_pjsua_call_answer(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3277 | { |
| 3278 | int status; |
| 3279 | int call_id; |
| 3280 | pj_str_t * reason, tmp_reason; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3281 | PyObject *pReason; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3282 | unsigned code; |
| 3283 | pjsua_msg_data msg_data; |
| 3284 | PyObject * omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3285 | pj_pool_t * pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3286 | |
| 3287 | PJ_UNUSED_ARG(pSelf); |
| 3288 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3289 | if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3290 | return NULL; |
| 3291 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3292 | |
| 3293 | if (pReason == Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3294 | reason = NULL; |
| 3295 | } else { |
| 3296 | reason = &tmp_reason; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3297 | tmp_reason = PyString_ToPJ(pReason); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3298 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3299 | |
| 3300 | pjsua_msg_data_init(&msg_data); |
| 3301 | if (omdObj != Py_None) { |
| 3302 | PyObj_pjsua_msg_data *omd; |
| 3303 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3304 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3305 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3306 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3307 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3308 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3311 | status = pjsua_call_answer(call_id, code, reason, &msg_data); |
| 3312 | |
| 3313 | if (pool) |
| 3314 | pj_pool_release(pool); |
| 3315 | |
| 3316 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /* |
| 3320 | * py_pjsua_call_hangup |
| 3321 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3322 | static PyObject *py_pjsua_call_hangup(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3323 | { |
| 3324 | int status; |
| 3325 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3326 | pj_str_t *reason, tmp_reason; |
| 3327 | PyObject *pReason; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3328 | unsigned code; |
| 3329 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3330 | PyObject *omdObj; |
| 3331 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3332 | |
| 3333 | PJ_UNUSED_ARG(pSelf); |
| 3334 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3335 | if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &pReason, |
| 3336 | &omdObj)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3337 | { |
| 3338 | return NULL; |
| 3339 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3340 | |
| 3341 | if (pReason == Py_None) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3342 | reason = NULL; |
| 3343 | } else { |
| 3344 | reason = &tmp_reason; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3345 | tmp_reason = PyString_ToPJ(pReason); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3346 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3347 | |
| 3348 | pjsua_msg_data_init(&msg_data); |
| 3349 | if (omdObj != Py_None) { |
| 3350 | PyObj_pjsua_msg_data *omd; |
| 3351 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3352 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3353 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3354 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3355 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3356 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3359 | status = pjsua_call_hangup(call_id, code, reason, &msg_data); |
| 3360 | if (pool) |
| 3361 | pj_pool_release(pool); |
| 3362 | |
| 3363 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | /* |
| 3367 | * py_pjsua_call_set_hold |
| 3368 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3369 | static PyObject *py_pjsua_call_set_hold(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3370 | { |
| 3371 | int status; |
| 3372 | int call_id; |
| 3373 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3374 | PyObject *omdObj; |
| 3375 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3376 | |
| 3377 | PJ_UNUSED_ARG(pSelf); |
| 3378 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3379 | if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3380 | return NULL; |
| 3381 | } |
| 3382 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3383 | pjsua_msg_data_init(&msg_data); |
| 3384 | if (omdObj != Py_None) { |
| 3385 | PyObj_pjsua_msg_data *omd; |
| 3386 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3387 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3388 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3389 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3390 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3391 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3392 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3393 | |
| 3394 | status = pjsua_call_set_hold(call_id, &msg_data); |
| 3395 | |
| 3396 | if (pool) |
| 3397 | pj_pool_release(pool); |
| 3398 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3399 | return Py_BuildValue("i",status); |
| 3400 | } |
| 3401 | |
| 3402 | /* |
| 3403 | * py_pjsua_call_reinvite |
| 3404 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3405 | static PyObject *py_pjsua_call_reinvite(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3406 | { |
| 3407 | int status; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3408 | int call_id; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3409 | int unhold; |
| 3410 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3411 | PyObject *omdObj; |
| 3412 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3413 | |
| 3414 | PJ_UNUSED_ARG(pSelf); |
| 3415 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3416 | if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &unhold, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3417 | return NULL; |
| 3418 | } |
| 3419 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3420 | pjsua_msg_data_init(&msg_data); |
| 3421 | if (omdObj != Py_None) { |
| 3422 | PyObj_pjsua_msg_data *omd; |
| 3423 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3424 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3425 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3426 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3427 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3428 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3429 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3430 | |
| 3431 | status = pjsua_call_reinvite(call_id, unhold, &msg_data); |
| 3432 | |
| 3433 | if (pool) |
| 3434 | pj_pool_release(pool); |
| 3435 | |
| 3436 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | /* |
| 3440 | * py_pjsua_call_update |
| 3441 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3442 | static PyObject *py_pjsua_call_update(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3443 | { |
| 3444 | int status; |
| 3445 | int call_id; |
| 3446 | int option; |
| 3447 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3448 | PyObject *omdObj; |
| 3449 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3450 | |
| 3451 | PJ_UNUSED_ARG(pSelf); |
| 3452 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3453 | if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &option, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3454 | return NULL; |
| 3455 | } |
| 3456 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3457 | pjsua_msg_data_init(&msg_data); |
| 3458 | if (omdObj != Py_None) { |
| 3459 | PyObj_pjsua_msg_data *omd; |
| 3460 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3461 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3462 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3463 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3464 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3465 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3466 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3467 | |
| 3468 | status = pjsua_call_update(call_id, option, &msg_data); |
| 3469 | |
| 3470 | if (pool) |
| 3471 | pj_pool_release(pool); |
| 3472 | |
| 3473 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | /* |
| 3477 | * py_pjsua_call_send_request |
| 3478 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3479 | static PyObject *py_pjsua_call_send_request(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3480 | { |
| 3481 | int status; |
| 3482 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3483 | PyObject *pMethod; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3484 | pj_str_t method; |
| 3485 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3486 | PyObject *omdObj; |
| 3487 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3488 | |
| 3489 | PJ_UNUSED_ARG(pSelf); |
| 3490 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3491 | if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pMethod, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3492 | return NULL; |
| 3493 | } |
| 3494 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3495 | if (!PyString_Check(pMethod)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3496 | return NULL; |
| 3497 | } |
| 3498 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3499 | method = PyString_ToPJ(pMethod); |
| 3500 | pjsua_msg_data_init(&msg_data); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3501 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3502 | if (omdObj != Py_None) { |
| 3503 | PyObj_pjsua_msg_data *omd; |
| 3504 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3505 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3506 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3507 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3508 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3509 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3510 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3511 | |
| 3512 | status = pjsua_call_send_request(call_id, &method, &msg_data); |
| 3513 | |
| 3514 | if (pool) |
| 3515 | pj_pool_release(pool); |
| 3516 | |
| 3517 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | /* |
| 3521 | * py_pjsua_call_xfer |
| 3522 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3523 | static PyObject *py_pjsua_call_xfer(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3524 | { |
| 3525 | int status; |
| 3526 | int call_id; |
| 3527 | pj_str_t dest; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3528 | PyObject *pDstUri; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3529 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3530 | PyObject *omdObj; |
| 3531 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3532 | |
| 3533 | PJ_UNUSED_ARG(pSelf); |
| 3534 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3535 | if (!PyArg_ParseTuple(pArgs, "iOO", &call_id, &pDstUri, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3536 | return NULL; |
| 3537 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3538 | |
| 3539 | if (!PyString_Check(pDstUri)) |
| 3540 | return NULL; |
| 3541 | |
| 3542 | dest = PyString_ToPJ(pDstUri); |
| 3543 | pjsua_msg_data_init(&msg_data); |
| 3544 | |
| 3545 | if (omdObj != Py_None) { |
| 3546 | PyObj_pjsua_msg_data *omd; |
| 3547 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3548 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3549 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3550 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3551 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3552 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3553 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3554 | |
| 3555 | status = pjsua_call_xfer(call_id, &dest, &msg_data); |
| 3556 | |
| 3557 | if (pool) |
| 3558 | pj_pool_release(pool); |
| 3559 | |
| 3560 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | /* |
| 3564 | * py_pjsua_call_xfer_replaces |
| 3565 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3566 | static PyObject *py_pjsua_call_xfer_replaces(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3567 | { |
| 3568 | int status; |
| 3569 | int call_id; |
| 3570 | int dest_call_id; |
| 3571 | unsigned options; |
| 3572 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3573 | PyObject *omdObj; |
| 3574 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3575 | |
| 3576 | PJ_UNUSED_ARG(pSelf); |
| 3577 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3578 | if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &dest_call_id, |
| 3579 | &options, &omdObj)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3580 | { |
| 3581 | return NULL; |
| 3582 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3583 | |
| 3584 | pjsua_msg_data_init(&msg_data); |
| 3585 | |
| 3586 | if (omdObj != Py_None) { |
| 3587 | PyObj_pjsua_msg_data *omd; |
| 3588 | |
| 3589 | omd = (PyObj_pjsua_msg_data *)omdObj; |
| 3590 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3591 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3592 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3593 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3594 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3595 | |
| 3596 | status = pjsua_call_xfer_replaces(call_id, dest_call_id, options, |
| 3597 | &msg_data); |
| 3598 | |
| 3599 | if (pool) |
| 3600 | pj_pool_release(pool); |
| 3601 | |
| 3602 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | /* |
| 3606 | * py_pjsua_call_dial_dtmf |
| 3607 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3608 | static PyObject *py_pjsua_call_dial_dtmf(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3609 | { |
| 3610 | int call_id; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3611 | PyObject *pDigits; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3612 | pj_str_t digits; |
| 3613 | int status; |
| 3614 | |
| 3615 | PJ_UNUSED_ARG(pSelf); |
| 3616 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3617 | if (!PyArg_ParseTuple(pArgs, "iO", &call_id, &pDigits)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3618 | return NULL; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | if (!PyString_Check(pDigits)) |
| 3622 | return Py_BuildValue("i", PJ_EINVAL); |
| 3623 | |
| 3624 | digits = PyString_ToPJ(pDigits); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3625 | status = pjsua_call_dial_dtmf(call_id, &digits); |
| 3626 | |
| 3627 | return Py_BuildValue("i", status); |
| 3628 | } |
| 3629 | |
| 3630 | /* |
| 3631 | * py_pjsua_call_send_im |
| 3632 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3633 | static PyObject *py_pjsua_call_send_im(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3634 | { |
| 3635 | int status; |
| 3636 | int call_id; |
| 3637 | pj_str_t content; |
| 3638 | pj_str_t * mime_type, tmp_mime_type; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3639 | PyObject *pMimeType, *pContent, *omdObj; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3640 | pjsua_msg_data msg_data; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3641 | int user_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3642 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3643 | |
| 3644 | PJ_UNUSED_ARG(pSelf); |
| 3645 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3646 | if (!PyArg_ParseTuple(pArgs, "iOOOi", &call_id, &pMimeType, &pContent, |
| 3647 | &omdObj, &user_data)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3648 | { |
| 3649 | return NULL; |
| 3650 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3651 | |
| 3652 | if (!PyString_Check(pContent)) |
| 3653 | return Py_BuildValue("i", PJ_EINVAL); |
| 3654 | |
| 3655 | content = PyString_ToPJ(pContent); |
| 3656 | |
| 3657 | if (PyString_Check(pMimeType)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3658 | mime_type = &tmp_mime_type; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3659 | tmp_mime_type = PyString_ToPJ(pMimeType); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3660 | } else { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3661 | mime_type = NULL; |
| 3662 | } |
| 3663 | |
| 3664 | pjsua_msg_data_init(&msg_data); |
| 3665 | if (omdObj != Py_None) { |
| 3666 | PyObj_pjsua_msg_data * omd; |
| 3667 | |
| 3668 | omd = (PyObj_pjsua_msg_data *)omdObj; |
| 3669 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3670 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3671 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
| 3672 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3675 | status = pjsua_call_send_im(call_id, mime_type, &content, |
| 3676 | &msg_data, (void *)user_data); |
| 3677 | |
| 3678 | if (pool) |
| 3679 | pj_pool_release(pool); |
| 3680 | |
| 3681 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | /* |
| 3685 | * py_pjsua_call_send_typing_ind |
| 3686 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3687 | static PyObject *py_pjsua_call_send_typing_ind(PyObject *pSelf, |
| 3688 | PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3689 | { |
| 3690 | int status; |
| 3691 | int call_id; |
| 3692 | int is_typing; |
| 3693 | pjsua_msg_data msg_data; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3694 | PyObject *omdObj; |
| 3695 | pj_pool_t *pool = NULL; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3696 | |
| 3697 | PJ_UNUSED_ARG(pSelf); |
| 3698 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3699 | if (!PyArg_ParseTuple(pArgs, "iiO", &call_id, &is_typing, &omdObj)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3700 | return NULL; |
| 3701 | } |
| 3702 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3703 | pjsua_msg_data_init(&msg_data); |
| 3704 | if (omdObj != Py_None) { |
| 3705 | PyObj_pjsua_msg_data *omd; |
| 3706 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3707 | omd = (PyObj_pjsua_msg_data *)omdObj; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3708 | msg_data.content_type = PyString_ToPJ(omd->content_type); |
| 3709 | msg_data.msg_body = PyString_ToPJ(omd->msg_body); |
| 3710 | pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3711 | translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3712 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3713 | |
| 3714 | status = pjsua_call_send_typing_ind(call_id, is_typing, &msg_data); |
| 3715 | |
| 3716 | if (pool) |
| 3717 | pj_pool_release(pool); |
| 3718 | |
| 3719 | return Py_BuildValue("i", status); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | /* |
| 3723 | * py_pjsua_call_hangup_all |
| 3724 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3725 | static PyObject *py_pjsua_call_hangup_all(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3726 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3727 | PJ_UNUSED_ARG(pSelf); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3728 | PJ_UNUSED_ARG(pArgs); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3729 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3730 | pjsua_call_hangup_all(); |
| 3731 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3732 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /* |
| 3736 | * py_pjsua_call_dump |
| 3737 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3738 | static PyObject *py_pjsua_call_dump(PyObject *pSelf, PyObject *pArgs) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3739 | { |
| 3740 | int call_id; |
| 3741 | int with_media; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3742 | PyObject *ret; |
| 3743 | PyObject *pIndent; |
| 3744 | char *buffer; |
| 3745 | char *indent; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3746 | unsigned maxlen; |
| 3747 | int status; |
| 3748 | |
| 3749 | PJ_UNUSED_ARG(pSelf); |
| 3750 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3751 | if (!PyArg_ParseTuple(pArgs, "iiIO", &call_id, &with_media, |
| 3752 | &maxlen, &pIndent)) |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3753 | { |
| 3754 | return NULL; |
| 3755 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3756 | |
| 3757 | buffer = (char*) malloc(maxlen * sizeof(char)); |
| 3758 | indent = PyString_AsString(pIndent); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3759 | |
| 3760 | status = pjsua_call_dump(call_id, with_media, buffer, maxlen, indent); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3761 | if (status != PJ_SUCCESS) { |
| 3762 | free(buffer); |
| 3763 | return PyString_FromString(""); |
| 3764 | } |
| 3765 | |
| 3766 | ret = PyString_FromString(buffer); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3767 | free(buffer); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3768 | return (PyObject*)ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | |
| 3772 | /* |
| 3773 | * py_pjsua_dump |
| 3774 | * Dump application states. |
| 3775 | */ |
| 3776 | static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs) |
| 3777 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3778 | int detail; |
| 3779 | |
| 3780 | PJ_UNUSED_ARG(pSelf); |
| 3781 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3782 | if (!PyArg_ParseTuple(pArgs, "i", &detail)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3783 | return NULL; |
| 3784 | } |
| 3785 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3786 | pjsua_dump(detail); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3787 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3788 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | |
| 3792 | /* |
| 3793 | * py_pj_strerror |
| 3794 | */ |
| 3795 | static PyObject *py_pj_strerror(PyObject *pSelf, PyObject *pArgs) |
| 3796 | { |
| 3797 | int err; |
| 3798 | char err_msg[PJ_ERR_MSG_SIZE]; |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3799 | pj_str_t ret; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3800 | |
| 3801 | PJ_UNUSED_ARG(pSelf); |
| 3802 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3803 | if (!PyArg_ParseTuple(pArgs, "i", &err)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3804 | return NULL; |
| 3805 | } |
| 3806 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3807 | ret = pj_strerror(err, err_msg, sizeof(err_msg)); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3808 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3809 | return PyString_FromStringAndSize(err_msg, ret.slen); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | |
| 3813 | /* |
| 3814 | * py_pj_parse_simple_sip |
| 3815 | */ |
| 3816 | static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs) |
| 3817 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3818 | const char *arg_uri; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3819 | pj_pool_t *pool; |
| 3820 | char tmp[PJSIP_MAX_URL_SIZE]; |
| 3821 | pjsip_uri *uri; |
| 3822 | pjsip_sip_uri *sip_uri; |
| 3823 | PyObject *ret, *item; |
| 3824 | |
| 3825 | PJ_UNUSED_ARG(pSelf); |
| 3826 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3827 | if (!PyArg_ParseTuple(pArgs, "s", &arg_uri)) { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3828 | return NULL; |
| 3829 | } |
| 3830 | |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3831 | strncpy(tmp, arg_uri, sizeof(tmp)); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3832 | tmp[sizeof(tmp)-1] = '\0'; |
| 3833 | |
| 3834 | pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512); |
| 3835 | uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0); |
| 3836 | |
| 3837 | if (uri == NULL || (!PJSIP_URI_SCHEME_IS_SIP(uri) && |
| 3838 | !PJSIP_URI_SCHEME_IS_SIPS(uri))) { |
| 3839 | pj_pool_release(pool); |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3840 | return Py_BuildValue(""); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | ret = PyTuple_New(5); |
| 3844 | sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri); |
| 3845 | |
| 3846 | /* Scheme */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3847 | item = PyString_FromPJ(pjsip_uri_get_scheme(uri)); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3848 | PyTuple_SetItem(ret, 0, item); |
| 3849 | |
| 3850 | /* Username */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3851 | item = PyString_FromPJ(&sip_uri->user); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3852 | PyTuple_SetItem(ret, 1, item); |
| 3853 | |
| 3854 | /* Host */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3855 | item = PyString_FromPJ(&sip_uri->host); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3856 | PyTuple_SetItem(ret, 2, item); |
| 3857 | |
| 3858 | /* Port */ |
| 3859 | if (sip_uri->port == 5060) { |
| 3860 | sip_uri->port = 0; |
| 3861 | } |
| 3862 | item = Py_BuildValue("i", sip_uri->port); |
| 3863 | PyTuple_SetItem(ret, 3, item); |
| 3864 | |
| 3865 | /* Transport */ |
| 3866 | if (pj_stricmp2(&sip_uri->transport_param, "udp")) { |
| 3867 | sip_uri->transport_param.ptr = ""; |
| 3868 | sip_uri->transport_param.slen = 0; |
| 3869 | } |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 3870 | item = PyString_FromPJ(&sip_uri->transport_param); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3871 | PyTuple_SetItem(ret, 4, item); |
| 3872 | |
| 3873 | return ret; |
| 3874 | } |
| 3875 | |
| 3876 | |
| 3877 | static char pjsua_call_get_max_count_doc[] = |
| 3878 | "int _pjsua.call_get_max_count () " |
| 3879 | "Get maximum number of calls configured in pjsua."; |
| 3880 | static char pjsua_call_get_count_doc[] = |
| 3881 | "int _pjsua.call_get_count () " |
| 3882 | "Get number of currently active calls."; |
| 3883 | static char pjsua_enum_calls_doc[] = |
| 3884 | "int[] _pjsua.enum_calls () " |
| 3885 | "Get maximum number of calls configured in pjsua."; |
| 3886 | static char pjsua_call_make_call_doc[] = |
| 3887 | "int,int _pjsua.call_make_call (int acc_id, string dst_uri, int options," |
| 3888 | "int user_data, _pjsua.Msg_Data msg_data) " |
| 3889 | "Make outgoing call to the specified URI using the specified account."; |
| 3890 | static char pjsua_call_is_active_doc[] = |
| 3891 | "int _pjsua.call_is_active (int call_id) " |
| 3892 | "Check if the specified call has active INVITE session and the INVITE " |
| 3893 | "session has not been disconnected."; |
| 3894 | static char pjsua_call_has_media_doc[] = |
| 3895 | "int _pjsua.call_has_media (int call_id) " |
| 3896 | "Check if call has an active media session."; |
| 3897 | static char pjsua_call_get_conf_port_doc[] = |
| 3898 | "int _pjsua.call_get_conf_port (int call_id) " |
| 3899 | "Get the conference port identification associated with the call."; |
| 3900 | static char pjsua_call_get_info_doc[] = |
| 3901 | "_pjsua.Call_Info _pjsua.call_get_info (int call_id) " |
| 3902 | "Obtain detail information about the specified call."; |
| 3903 | static char pjsua_call_set_user_data_doc[] = |
| 3904 | "int _pjsua.call_set_user_data (int call_id, int user_data) " |
| 3905 | "Attach application specific data to the call."; |
| 3906 | static char pjsua_call_get_user_data_doc[] = |
| 3907 | "int _pjsua.call_get_user_data (int call_id) " |
| 3908 | "Get user data attached to the call."; |
| 3909 | static char pjsua_call_answer_doc[] = |
| 3910 | "int _pjsua.call_answer (int call_id, int code, string reason, " |
| 3911 | "_pjsua.Msg_Data msg_data) " |
| 3912 | "Send response to incoming INVITE request."; |
| 3913 | static char pjsua_call_hangup_doc[] = |
| 3914 | "int _pjsua.call_hangup (int call_id, int code, string reason, " |
| 3915 | "_pjsua.Msg_Data msg_data) " |
| 3916 | "Hangup call by using method that is appropriate according " |
| 3917 | "to the call state."; |
| 3918 | static char pjsua_call_set_hold_doc[] = |
| 3919 | "int _pjsua.call_set_hold (int call_id, _pjsua.Msg_Data msg_data) " |
| 3920 | "Put the specified call on hold."; |
| 3921 | static char pjsua_call_reinvite_doc[] = |
| 3922 | "int _pjsua.call_reinvite (int call_id, int unhold, " |
| 3923 | "_pjsua.Msg_Data msg_data) " |
| 3924 | "Send re-INVITE (to release hold)."; |
| 3925 | static char pjsua_call_xfer_doc[] = |
| 3926 | "int _pjsua.call_xfer (int call_id, string dest, " |
| 3927 | "_pjsua.Msg_Data msg_data) " |
| 3928 | "Initiate call transfer to the specified address. " |
| 3929 | "This function will send REFER request to instruct remote call party " |
| 3930 | "to initiate a new INVITE session to the specified destination/target."; |
| 3931 | static char pjsua_call_xfer_replaces_doc[] = |
| 3932 | "int _pjsua.call_xfer_replaces (int call_id, int dest_call_id, " |
| 3933 | "int options, _pjsua.Msg_Data msg_data) " |
| 3934 | "Initiate attended call transfer. This function will send REFER request " |
| 3935 | "to instruct remote call party to initiate new INVITE session to the URL " |
| 3936 | "of dest_call_id. The party at dest_call_id then should 'replace' the call" |
| 3937 | "with us with the new call from the REFER recipient."; |
| 3938 | static char pjsua_call_dial_dtmf_doc[] = |
| 3939 | "int _pjsua.call_dial_dtmf (int call_id, string digits) " |
| 3940 | "Send DTMF digits to remote using RFC 2833 payload formats."; |
| 3941 | static char pjsua_call_send_im_doc[] = |
| 3942 | "int _pjsua.call_send_im (int call_id, string mime_type, string content," |
| 3943 | "_pjsua.Msg_Data msg_data, int user_data) " |
| 3944 | "Send instant messaging inside INVITE session."; |
| 3945 | static char pjsua_call_send_typing_ind_doc[] = |
| 3946 | "int _pjsua.call_send_typing_ind (int call_id, int is_typing, " |
| 3947 | "_pjsua.Msg_Data msg_data) " |
| 3948 | "Send IM typing indication inside INVITE session."; |
| 3949 | static char pjsua_call_hangup_all_doc[] = |
| 3950 | "void _pjsua.call_hangup_all () " |
| 3951 | "Terminate all calls."; |
| 3952 | static char pjsua_call_dump_doc[] = |
| 3953 | "int _pjsua.call_dump (int call_id, int with_media, int maxlen, " |
| 3954 | "string indent) " |
| 3955 | "Dump call and media statistics to string."; |
| 3956 | |
| 3957 | /* END OF LIB CALL */ |
| 3958 | |
| 3959 | /* |
| 3960 | * Map of function names to functions |
| 3961 | */ |
| 3962 | static PyMethodDef py_pjsua_methods[] = |
| 3963 | { |
| 3964 | { |
| 3965 | "thread_register", py_pjsua_thread_register, METH_VARARGS, |
| 3966 | pjsua_thread_register_doc |
| 3967 | }, |
| 3968 | { |
| 3969 | "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc |
| 3970 | }, |
| 3971 | { |
| 3972 | "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc |
| 3973 | }, |
| 3974 | { |
| 3975 | "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc |
| 3976 | }, |
| 3977 | { |
| 3978 | "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc |
| 3979 | }, |
| 3980 | { |
| 3981 | "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc |
| 3982 | }, |
| 3983 | { |
| 3984 | "handle_events", py_pjsua_handle_events, METH_VARARGS, |
| 3985 | pjsua_handle_events_doc |
| 3986 | }, |
| 3987 | { |
| 3988 | "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS, |
| 3989 | pjsua_verify_sip_url_doc |
| 3990 | }, |
| 3991 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 3992 | "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS, |
| 3993 | pjsua_reconfigure_logging_doc |
| 3994 | }, |
| 3995 | { |
| 3996 | "logging_config_default", py_pjsua_logging_config_default, |
| 3997 | METH_VARARGS, pjsua_logging_config_default_doc |
| 3998 | }, |
| 3999 | { |
| 4000 | "config_default", py_pjsua_config_default, METH_VARARGS, |
| 4001 | pjsua_config_default_doc |
| 4002 | }, |
| 4003 | { |
| 4004 | "media_config_default", py_pjsua_media_config_default, METH_VARARGS, |
| 4005 | pjsua_media_config_default_doc |
| 4006 | }, |
| 4007 | |
| 4008 | |
| 4009 | { |
| 4010 | "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS, |
| 4011 | pjsua_msg_data_init_doc |
| 4012 | }, |
| 4013 | { |
| 4014 | "transport_config_default", py_pjsua_transport_config_default, |
| 4015 | METH_VARARGS,pjsua_transport_config_default_doc |
| 4016 | }, |
| 4017 | { |
| 4018 | "transport_create", py_pjsua_transport_create, METH_VARARGS, |
| 4019 | pjsua_transport_create_doc |
| 4020 | }, |
| 4021 | { |
| 4022 | "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS, |
| 4023 | pjsua_enum_transports_doc |
| 4024 | }, |
| 4025 | { |
| 4026 | "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS, |
| 4027 | pjsua_transport_get_info_doc |
| 4028 | }, |
| 4029 | { |
| 4030 | "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS, |
| 4031 | pjsua_transport_set_enable_doc |
| 4032 | }, |
| 4033 | { |
| 4034 | "transport_close", py_pjsua_transport_close, METH_VARARGS, |
| 4035 | pjsua_transport_close_doc |
| 4036 | }, |
| 4037 | { |
| 4038 | "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS, |
| 4039 | pjsua_acc_config_default_doc |
| 4040 | }, |
| 4041 | { |
| 4042 | "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS, |
| 4043 | pjsua_acc_get_count_doc |
| 4044 | }, |
| 4045 | { |
| 4046 | "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS, |
| 4047 | pjsua_acc_is_valid_doc |
| 4048 | }, |
| 4049 | { |
| 4050 | "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS, |
| 4051 | pjsua_acc_set_default_doc |
| 4052 | }, |
| 4053 | { |
| 4054 | "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS, |
| 4055 | pjsua_acc_get_default_doc |
| 4056 | }, |
| 4057 | { |
| 4058 | "acc_add", py_pjsua_acc_add, METH_VARARGS, |
| 4059 | pjsua_acc_add_doc |
| 4060 | }, |
| 4061 | { |
| 4062 | "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS, |
| 4063 | pjsua_acc_add_local_doc |
| 4064 | }, |
| 4065 | { |
| 4066 | "acc_del", py_pjsua_acc_del, METH_VARARGS, |
| 4067 | pjsua_acc_del_doc |
| 4068 | }, |
| 4069 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 4070 | "acc_set_user_data", py_pjsua_acc_set_user_data, METH_VARARGS, |
| 4071 | "Accociate user data with the account" |
| 4072 | }, |
| 4073 | { |
| 4074 | "acc_get_user_data", py_pjsua_acc_get_user_data, METH_VARARGS, |
| 4075 | "Get account's user data" |
| 4076 | }, |
| 4077 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4078 | "acc_modify", py_pjsua_acc_modify, METH_VARARGS, |
| 4079 | pjsua_acc_modify_doc |
| 4080 | }, |
| 4081 | { |
| 4082 | "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS, |
| 4083 | pjsua_acc_set_online_status_doc |
| 4084 | }, |
| 4085 | { |
| 4086 | "acc_set_online_status2", py_pjsua_acc_set_online_status2, METH_VARARGS, |
| 4087 | pjsua_acc_set_online_status2_doc |
| 4088 | }, |
| 4089 | { |
| 4090 | "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS, |
| 4091 | pjsua_acc_set_registration_doc |
| 4092 | }, |
| 4093 | { |
| 4094 | "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS, |
| 4095 | pjsua_acc_get_info_doc |
| 4096 | }, |
| 4097 | { |
Benny Prijono | e6787ec | 2008-07-18 23:00:56 +0000 | [diff] [blame] | 4098 | "acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS, |
| 4099 | "Accept or reject subscription request" |
| 4100 | }, |
| 4101 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4102 | "enum_accs", py_pjsua_enum_accs, METH_VARARGS, |
| 4103 | pjsua_enum_accs_doc |
| 4104 | }, |
| 4105 | { |
| 4106 | "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, |
| 4107 | pjsua_acc_enum_info_doc |
| 4108 | }, |
| 4109 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4110 | "acc_set_transport", py_pjsua_acc_set_transport, METH_VARARGS, |
| 4111 | "Lock transport to use the specified transport" |
| 4112 | }, |
| 4113 | { |
| 4114 | "buddy_config_default", py_pjsua_buddy_config_default, METH_VARARGS, |
| 4115 | pjsua_buddy_config_default_doc |
| 4116 | }, |
| 4117 | { |
| 4118 | "get_buddy_count", py_pjsua_get_buddy_count, METH_VARARGS, |
| 4119 | pjsua_get_buddy_count_doc |
| 4120 | }, |
| 4121 | { |
| 4122 | "buddy_is_valid", py_pjsua_buddy_is_valid, METH_VARARGS, |
| 4123 | pjsua_buddy_is_valid_doc |
| 4124 | }, |
| 4125 | { |
| 4126 | "enum_buddies", py_pjsua_enum_buddies, METH_VARARGS, |
| 4127 | pjsua_enum_buddies_doc |
| 4128 | }, |
| 4129 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 4130 | "buddy_find", py_pjsua_buddy_find, METH_VARARGS, |
| 4131 | "Find buddy with the specified URI" |
| 4132 | }, |
| 4133 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4134 | "buddy_get_info", py_pjsua_buddy_get_info, METH_VARARGS, |
| 4135 | pjsua_buddy_get_info_doc |
| 4136 | }, |
| 4137 | { |
| 4138 | "buddy_add", py_pjsua_buddy_add, METH_VARARGS, |
| 4139 | pjsua_buddy_add_doc |
| 4140 | }, |
| 4141 | { |
| 4142 | "buddy_del", py_pjsua_buddy_del, METH_VARARGS, |
| 4143 | pjsua_buddy_del_doc |
| 4144 | }, |
| 4145 | { |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 4146 | "buddy_set_user_data", py_pjsua_buddy_set_user_data, METH_VARARGS, |
| 4147 | "Associate user data to the buddy object" |
| 4148 | }, |
| 4149 | { |
| 4150 | "buddy_get_user_data", py_pjsua_buddy_get_user_data, METH_VARARGS, |
| 4151 | "Get buddy user data" |
| 4152 | }, |
| 4153 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4154 | "buddy_subscribe_pres", py_pjsua_buddy_subscribe_pres, METH_VARARGS, |
| 4155 | pjsua_buddy_subscribe_pres_doc |
| 4156 | }, |
| 4157 | { |
| 4158 | "pres_dump", py_pjsua_pres_dump, METH_VARARGS, |
| 4159 | pjsua_pres_dump_doc |
| 4160 | }, |
| 4161 | { |
| 4162 | "im_send", py_pjsua_im_send, METH_VARARGS, |
| 4163 | pjsua_im_send_doc |
| 4164 | }, |
| 4165 | { |
| 4166 | "im_typing", py_pjsua_im_typing, METH_VARARGS, |
| 4167 | pjsua_im_typing_doc |
| 4168 | }, |
| 4169 | { |
| 4170 | "conf_get_max_ports", py_pjsua_conf_get_max_ports, METH_VARARGS, |
| 4171 | pjsua_conf_get_max_ports_doc |
| 4172 | }, |
| 4173 | { |
| 4174 | "conf_get_active_ports", py_pjsua_conf_get_active_ports, METH_VARARGS, |
| 4175 | pjsua_conf_get_active_ports_doc |
| 4176 | }, |
| 4177 | { |
| 4178 | "enum_conf_ports", py_pjsua_enum_conf_ports, METH_VARARGS, |
| 4179 | pjsua_enum_conf_ports_doc |
| 4180 | }, |
| 4181 | { |
| 4182 | "conf_get_port_info", py_pjsua_conf_get_port_info, METH_VARARGS, |
| 4183 | pjsua_conf_get_port_info_doc |
| 4184 | }, |
| 4185 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4186 | "conf_remove_port", py_pjsua_conf_remove_port, METH_VARARGS, |
| 4187 | pjsua_conf_remove_port_doc |
| 4188 | }, |
| 4189 | { |
| 4190 | "conf_connect", py_pjsua_conf_connect, METH_VARARGS, |
| 4191 | pjsua_conf_connect_doc |
| 4192 | }, |
| 4193 | { |
| 4194 | "conf_disconnect", py_pjsua_conf_disconnect, METH_VARARGS, |
| 4195 | pjsua_conf_disconnect_doc |
| 4196 | }, |
| 4197 | { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 4198 | "conf_set_tx_level", py_pjsua_conf_set_tx_level, METH_VARARGS, |
| 4199 | "Adjust the signal level to be transmitted from the bridge to the" |
| 4200 | " specified port by making it louder or quieter" |
| 4201 | }, |
| 4202 | { |
| 4203 | "conf_set_rx_level", py_pjsua_conf_set_rx_level, METH_VARARGS, |
| 4204 | "Adjust the signal level to be received from the specified port (to" |
| 4205 | " the bridge) by making it louder or quieter" |
| 4206 | }, |
| 4207 | { |
| 4208 | "conf_get_signal_level", py_pjsua_conf_get_signal_level, METH_VARARGS, |
| 4209 | "Get last signal level transmitted to or received from the specified port" |
| 4210 | }, |
| 4211 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4212 | "player_create", py_pjsua_player_create, METH_VARARGS, |
| 4213 | pjsua_player_create_doc |
| 4214 | }, |
| 4215 | { |
Benny Prijono | 288d4bd | 2008-07-19 15:40:21 +0000 | [diff] [blame] | 4216 | "playlist_create", py_pjsua_playlist_create, METH_VARARGS, |
| 4217 | "Create WAV playlist" |
| 4218 | }, |
| 4219 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4220 | "player_get_conf_port", py_pjsua_player_get_conf_port, METH_VARARGS, |
| 4221 | pjsua_player_get_conf_port_doc |
| 4222 | }, |
| 4223 | { |
| 4224 | "player_set_pos", py_pjsua_player_set_pos, METH_VARARGS, |
| 4225 | pjsua_player_set_pos_doc |
| 4226 | }, |
| 4227 | { |
| 4228 | "player_destroy", py_pjsua_player_destroy, METH_VARARGS, |
| 4229 | pjsua_player_destroy_doc |
| 4230 | }, |
| 4231 | { |
| 4232 | "recorder_create", py_pjsua_recorder_create, METH_VARARGS, |
| 4233 | pjsua_recorder_create_doc |
| 4234 | }, |
| 4235 | { |
| 4236 | "recorder_get_conf_port", py_pjsua_recorder_get_conf_port, METH_VARARGS, |
| 4237 | pjsua_recorder_get_conf_port_doc |
| 4238 | }, |
| 4239 | { |
| 4240 | "recorder_destroy", py_pjsua_recorder_destroy, METH_VARARGS, |
| 4241 | pjsua_recorder_destroy_doc |
| 4242 | }, |
| 4243 | { |
| 4244 | "enum_snd_devs", py_pjsua_enum_snd_devs, METH_VARARGS, |
| 4245 | pjsua_enum_snd_devs_doc |
| 4246 | }, |
| 4247 | { |
| 4248 | "get_snd_dev", py_pjsua_get_snd_dev, METH_VARARGS, |
| 4249 | pjsua_get_snd_dev_doc |
| 4250 | }, |
| 4251 | { |
| 4252 | "set_snd_dev", py_pjsua_set_snd_dev, METH_VARARGS, |
| 4253 | pjsua_set_snd_dev_doc |
| 4254 | }, |
| 4255 | { |
| 4256 | "set_null_snd_dev", py_pjsua_set_null_snd_dev, METH_VARARGS, |
| 4257 | pjsua_set_null_snd_dev_doc |
| 4258 | }, |
| 4259 | { |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4260 | "set_ec", py_pjsua_set_ec, METH_VARARGS, |
| 4261 | pjsua_set_ec_doc |
| 4262 | }, |
| 4263 | { |
| 4264 | "get_ec_tail", py_pjsua_get_ec_tail, METH_VARARGS, |
| 4265 | pjsua_get_ec_tail_doc |
| 4266 | }, |
| 4267 | { |
| 4268 | "enum_codecs", py_pjsua_enum_codecs, METH_VARARGS, |
| 4269 | pjsua_enum_codecs_doc |
| 4270 | }, |
| 4271 | { |
| 4272 | "codec_set_priority", py_pjsua_codec_set_priority, METH_VARARGS, |
| 4273 | pjsua_codec_set_priority_doc |
| 4274 | }, |
| 4275 | { |
| 4276 | "codec_get_param", py_pjsua_codec_get_param, METH_VARARGS, |
| 4277 | pjsua_codec_get_param_doc |
| 4278 | }, |
| 4279 | { |
| 4280 | "codec_set_param", py_pjsua_codec_set_param, METH_VARARGS, |
| 4281 | pjsua_codec_set_param_doc |
| 4282 | }, |
| 4283 | { |
| 4284 | "call_get_max_count", py_pjsua_call_get_max_count, METH_VARARGS, |
| 4285 | pjsua_call_get_max_count_doc |
| 4286 | }, |
| 4287 | { |
| 4288 | "call_get_count", py_pjsua_call_get_count, METH_VARARGS, |
| 4289 | pjsua_call_get_count_doc |
| 4290 | }, |
| 4291 | { |
| 4292 | "enum_calls", py_pjsua_enum_calls, METH_VARARGS, |
| 4293 | pjsua_enum_calls_doc |
| 4294 | }, |
| 4295 | { |
| 4296 | "call_make_call", py_pjsua_call_make_call, METH_VARARGS, |
| 4297 | pjsua_call_make_call_doc |
| 4298 | }, |
| 4299 | { |
| 4300 | "call_is_active", py_pjsua_call_is_active, METH_VARARGS, |
| 4301 | pjsua_call_is_active_doc |
| 4302 | }, |
| 4303 | { |
| 4304 | "call_has_media", py_pjsua_call_has_media, METH_VARARGS, |
| 4305 | pjsua_call_has_media_doc |
| 4306 | }, |
| 4307 | { |
| 4308 | "call_get_conf_port", py_pjsua_call_get_conf_port, METH_VARARGS, |
| 4309 | pjsua_call_get_conf_port_doc |
| 4310 | }, |
| 4311 | { |
| 4312 | "call_get_info", py_pjsua_call_get_info, METH_VARARGS, |
| 4313 | pjsua_call_get_info_doc |
| 4314 | }, |
| 4315 | { |
| 4316 | "call_set_user_data", py_pjsua_call_set_user_data, METH_VARARGS, |
| 4317 | pjsua_call_set_user_data_doc |
| 4318 | }, |
| 4319 | { |
| 4320 | "call_get_user_data", py_pjsua_call_get_user_data, METH_VARARGS, |
| 4321 | pjsua_call_get_user_data_doc |
| 4322 | }, |
| 4323 | { |
| 4324 | "call_answer", py_pjsua_call_answer, METH_VARARGS, |
| 4325 | pjsua_call_answer_doc |
| 4326 | }, |
| 4327 | { |
| 4328 | "call_hangup", py_pjsua_call_hangup, METH_VARARGS, |
| 4329 | pjsua_call_hangup_doc |
| 4330 | }, |
| 4331 | { |
| 4332 | "call_set_hold", py_pjsua_call_set_hold, METH_VARARGS, |
| 4333 | pjsua_call_set_hold_doc |
| 4334 | }, |
| 4335 | { |
| 4336 | "call_reinvite", py_pjsua_call_reinvite, METH_VARARGS, |
| 4337 | pjsua_call_reinvite_doc |
| 4338 | }, |
| 4339 | { |
| 4340 | "call_update", py_pjsua_call_update, METH_VARARGS, |
| 4341 | "Send UPDATE" |
| 4342 | }, |
| 4343 | { |
| 4344 | "call_xfer", py_pjsua_call_xfer, METH_VARARGS, |
| 4345 | pjsua_call_xfer_doc |
| 4346 | }, |
| 4347 | { |
| 4348 | "call_xfer_replaces", py_pjsua_call_xfer_replaces, METH_VARARGS, |
| 4349 | pjsua_call_xfer_replaces_doc |
| 4350 | }, |
| 4351 | { |
| 4352 | "call_dial_dtmf", py_pjsua_call_dial_dtmf, METH_VARARGS, |
| 4353 | pjsua_call_dial_dtmf_doc |
| 4354 | }, |
| 4355 | { |
| 4356 | "call_send_im", py_pjsua_call_send_im, METH_VARARGS, |
| 4357 | pjsua_call_send_im_doc |
| 4358 | }, |
| 4359 | { |
| 4360 | "call_send_typing_ind", py_pjsua_call_send_typing_ind, METH_VARARGS, |
| 4361 | pjsua_call_send_typing_ind_doc |
| 4362 | }, |
| 4363 | { |
| 4364 | "call_hangup_all", py_pjsua_call_hangup_all, METH_VARARGS, |
| 4365 | pjsua_call_hangup_all_doc |
| 4366 | }, |
| 4367 | { |
| 4368 | "call_dump", py_pjsua_call_dump, METH_VARARGS, |
| 4369 | pjsua_call_dump_doc |
| 4370 | }, |
| 4371 | { |
| 4372 | "call_send_request", py_pjsua_call_send_request, METH_VARARGS, |
| 4373 | "Send arbitrary request" |
| 4374 | }, |
| 4375 | { |
| 4376 | "dump", py_pjsua_dump, METH_VARARGS, "Dump application state" |
| 4377 | }, |
| 4378 | { |
| 4379 | "strerror", py_pj_strerror, METH_VARARGS, "Get error message" |
| 4380 | }, |
| 4381 | { |
| 4382 | "parse_simple_uri", py_pj_parse_simple_sip, METH_VARARGS, "Parse URI" |
| 4383 | }, |
| 4384 | |
| 4385 | |
| 4386 | {NULL, NULL} /* end of function list */ |
| 4387 | }; |
| 4388 | |
| 4389 | |
| 4390 | |
| 4391 | /* |
| 4392 | * Mapping C structs from and to Python objects & initializing object |
| 4393 | */ |
| 4394 | DL_EXPORT(void) |
| 4395 | init_pjsua(void) |
| 4396 | { |
| 4397 | PyObject* m = NULL; |
| 4398 | #define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name) |
| 4399 | |
| 4400 | |
| 4401 | PyEval_InitThreads(); |
| 4402 | |
| 4403 | if (PyType_Ready(&PyTyp_pjsua_callback) < 0) |
| 4404 | return; |
| 4405 | if (PyType_Ready(&PyTyp_pjsua_config) < 0) |
| 4406 | return; |
| 4407 | if (PyType_Ready(&PyTyp_pjsua_logging_config) < 0) |
| 4408 | return; |
| 4409 | if (PyType_Ready(&PyTyp_pjsua_msg_data) < 0) |
| 4410 | return; |
| 4411 | PyTyp_pjsua_media_config.tp_new = PyType_GenericNew; |
| 4412 | if (PyType_Ready(&PyTyp_pjsua_media_config) < 0) |
| 4413 | return; |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4414 | PyTyp_pjsip_cred_info.tp_new = PyType_GenericNew; |
| 4415 | if (PyType_Ready(&PyTyp_pjsip_cred_info) < 0) |
| 4416 | return; |
| 4417 | |
| 4418 | /* LIB TRANSPORT */ |
| 4419 | |
| 4420 | if (PyType_Ready(&PyTyp_pjsua_transport_config) < 0) |
| 4421 | return; |
| 4422 | |
| 4423 | if (PyType_Ready(&PyTyp_pjsua_transport_info) < 0) |
| 4424 | return; |
| 4425 | |
| 4426 | /* END OF LIB TRANSPORT */ |
| 4427 | |
| 4428 | /* LIB ACCOUNT */ |
| 4429 | |
| 4430 | |
| 4431 | if (PyType_Ready(&PyTyp_pjsua_acc_config) < 0) |
| 4432 | return; |
| 4433 | if (PyType_Ready(&PyTyp_pjsua_acc_info) < 0) |
| 4434 | return; |
| 4435 | |
| 4436 | /* END OF LIB ACCOUNT */ |
| 4437 | |
| 4438 | /* LIB BUDDY */ |
| 4439 | |
| 4440 | if (PyType_Ready(&PyTyp_pjsua_buddy_config) < 0) |
| 4441 | return; |
| 4442 | if (PyType_Ready(&PyTyp_pjsua_buddy_info) < 0) |
| 4443 | return; |
| 4444 | |
| 4445 | /* END OF LIB BUDDY */ |
| 4446 | |
| 4447 | /* LIB MEDIA */ |
| 4448 | |
| 4449 | if (PyType_Ready(&PyTyp_pjsua_codec_info) < 0) |
| 4450 | return; |
| 4451 | |
| 4452 | if (PyType_Ready(&PyTyp_pjsua_conf_port_info) < 0) |
| 4453 | return; |
| 4454 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4455 | if (PyType_Ready(&PyTyp_pjmedia_snd_dev_info) < 0) |
| 4456 | return; |
| 4457 | |
| 4458 | PyTyp_pjmedia_codec_param_info.tp_new = PyType_GenericNew; |
| 4459 | if (PyType_Ready(&PyTyp_pjmedia_codec_param_info) < 0) |
| 4460 | return; |
| 4461 | PyTyp_pjmedia_codec_param_setting.tp_new = PyType_GenericNew; |
| 4462 | if (PyType_Ready(&PyTyp_pjmedia_codec_param_setting) < 0) |
| 4463 | return; |
| 4464 | |
| 4465 | if (PyType_Ready(&PyTyp_pjmedia_codec_param) < 0) |
| 4466 | return; |
| 4467 | |
| 4468 | /* END OF LIB MEDIA */ |
| 4469 | |
| 4470 | /* LIB CALL */ |
| 4471 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4472 | if (PyType_Ready(&PyTyp_pjsua_call_info) < 0) |
| 4473 | return; |
| 4474 | |
| 4475 | /* END OF LIB CALL */ |
| 4476 | |
| 4477 | m = Py_InitModule3( |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 4478 | "_pjsua", py_pjsua_methods, "PJSUA-lib module for python" |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4479 | ); |
| 4480 | |
| 4481 | Py_INCREF(&PyTyp_pjsua_callback); |
| 4482 | PyModule_AddObject(m, "Callback", (PyObject *)&PyTyp_pjsua_callback); |
| 4483 | |
| 4484 | Py_INCREF(&PyTyp_pjsua_config); |
| 4485 | PyModule_AddObject(m, "Config", (PyObject *)&PyTyp_pjsua_config); |
| 4486 | |
| 4487 | Py_INCREF(&PyTyp_pjsua_media_config); |
| 4488 | PyModule_AddObject(m, "Media_Config", (PyObject *)&PyTyp_pjsua_media_config); |
| 4489 | |
| 4490 | Py_INCREF(&PyTyp_pjsua_logging_config); |
| 4491 | PyModule_AddObject(m, "Logging_Config", (PyObject *)&PyTyp_pjsua_logging_config); |
| 4492 | |
| 4493 | Py_INCREF(&PyTyp_pjsua_msg_data); |
| 4494 | PyModule_AddObject(m, "Msg_Data", (PyObject *)&PyTyp_pjsua_msg_data); |
| 4495 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4496 | Py_INCREF(&PyTyp_pjsip_cred_info); |
| 4497 | PyModule_AddObject(m, "Pjsip_Cred_Info", |
| 4498 | (PyObject *)&PyTyp_pjsip_cred_info |
| 4499 | ); |
| 4500 | |
| 4501 | /* LIB TRANSPORT */ |
| 4502 | |
| 4503 | Py_INCREF(&PyTyp_pjsua_transport_config); |
| 4504 | PyModule_AddObject |
| 4505 | (m, "Transport_Config", (PyObject *)&PyTyp_pjsua_transport_config); |
| 4506 | |
| 4507 | Py_INCREF(&PyTyp_pjsua_transport_info); |
| 4508 | PyModule_AddObject(m, "Transport_Info", (PyObject *)&PyTyp_pjsua_transport_info); |
| 4509 | |
| 4510 | |
| 4511 | /* END OF LIB TRANSPORT */ |
| 4512 | |
| 4513 | /* LIB ACCOUNT */ |
| 4514 | |
| 4515 | |
| 4516 | Py_INCREF(&PyTyp_pjsua_acc_config); |
| 4517 | PyModule_AddObject(m, "Acc_Config", (PyObject *)&PyTyp_pjsua_acc_config); |
| 4518 | Py_INCREF(&PyTyp_pjsua_acc_info); |
| 4519 | PyModule_AddObject(m, "Acc_Info", (PyObject *)&PyTyp_pjsua_acc_info); |
| 4520 | |
| 4521 | /* END OF LIB ACCOUNT */ |
| 4522 | |
| 4523 | /* LIB BUDDY */ |
| 4524 | |
| 4525 | Py_INCREF(&PyTyp_pjsua_buddy_config); |
| 4526 | PyModule_AddObject(m, "Buddy_Config", (PyObject *)&PyTyp_pjsua_buddy_config); |
| 4527 | Py_INCREF(&PyTyp_pjsua_buddy_info); |
| 4528 | PyModule_AddObject(m, "Buddy_Info", (PyObject *)&PyTyp_pjsua_buddy_info); |
| 4529 | |
| 4530 | /* END OF LIB BUDDY */ |
| 4531 | |
| 4532 | /* LIB MEDIA */ |
| 4533 | |
| 4534 | Py_INCREF(&PyTyp_pjsua_codec_info); |
| 4535 | PyModule_AddObject(m, "Codec_Info", (PyObject *)&PyTyp_pjsua_codec_info); |
| 4536 | Py_INCREF(&PyTyp_pjsua_conf_port_info); |
| 4537 | PyModule_AddObject(m, "Conf_Port_Info", (PyObject *)&PyTyp_pjsua_conf_port_info); |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4538 | Py_INCREF(&PyTyp_pjmedia_snd_dev_info); |
| 4539 | PyModule_AddObject(m, "PJMedia_Snd_Dev_Info", |
| 4540 | (PyObject *)&PyTyp_pjmedia_snd_dev_info); |
| 4541 | Py_INCREF(&PyTyp_pjmedia_codec_param_info); |
| 4542 | PyModule_AddObject(m, "PJMedia_Codec_Param_Info", |
| 4543 | (PyObject *)&PyTyp_pjmedia_codec_param_info); |
| 4544 | Py_INCREF(&PyTyp_pjmedia_codec_param_setting); |
| 4545 | PyModule_AddObject(m, "PJMedia_Codec_Param_Setting", |
| 4546 | (PyObject *)&PyTyp_pjmedia_codec_param_setting); |
| 4547 | Py_INCREF(&PyTyp_pjmedia_codec_param); |
| 4548 | PyModule_AddObject(m, "PJMedia_Codec_Param", |
| 4549 | (PyObject *)&PyTyp_pjmedia_codec_param); |
| 4550 | |
| 4551 | /* END OF LIB MEDIA */ |
| 4552 | |
| 4553 | /* LIB CALL */ |
| 4554 | |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4555 | Py_INCREF(&PyTyp_pjsua_call_info); |
| 4556 | PyModule_AddObject(m, "Call_Info", (PyObject *)&PyTyp_pjsua_call_info); |
| 4557 | |
| 4558 | /* END OF LIB CALL */ |
| 4559 | |
| 4560 | |
| 4561 | /* |
| 4562 | * Add various constants. |
| 4563 | */ |
Benny Prijono | 5504045 | 2008-07-21 18:20:57 +0000 | [diff] [blame] | 4564 | /* Skip it.. */ |
Benny Prijono | 9c46114 | 2008-07-10 22:41:20 +0000 | [diff] [blame] | 4565 | |
| 4566 | #undef ADD_CONSTANT |
| 4567 | } |