Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2003-2006 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 | */ |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 19 | #include <Python.h> |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 20 | #include "structmember.h" |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 21 | #include <pjsua-lib/pjsua.h> |
| 22 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 23 | #define THIS_FILE "main.c" |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 24 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 25 | /* LIB BASE */ |
| 26 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 27 | static PyObject* obj_reconfigure_logging; |
| 28 | static PyObject* obj_logging_init; |
| 29 | |
| 30 | /* |
| 31 | * cb_reconfigure_logging |
| 32 | * declares method for reconfiguring logging process for callback struct |
| 33 | */ |
| 34 | static void cb_reconfigure_logging(int level, const char *data, pj_size_t len) |
| 35 | { |
| 36 | if (PyCallable_Check(obj_reconfigure_logging)) |
| 37 | { |
| 38 | PyObject_CallFunctionObjArgs( |
| 39 | obj_reconfigure_logging, Py_BuildValue("i",level), |
| 40 | PyString_FromString(data), Py_BuildValue("i",len), NULL |
| 41 | ); |
| 42 | } |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 45 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 46 | /* |
| 47 | * cb_logging_init |
| 48 | * declares method logging_init for callback struct |
| 49 | */ |
| 50 | static void cb_logging_init(int level, const char *data, pj_size_t len) |
| 51 | { |
| 52 | if (PyCallable_Check(obj_logging_init)) |
| 53 | { |
| 54 | //PyObject_CallFunction(obj_logging_init,"iSi",level,data,len); |
| 55 | //printf("level : %d data : %s len : %d\n",level, data, len); |
| 56 | PyObject_CallFunctionObjArgs( |
| 57 | obj_logging_init, Py_BuildValue("i",level), |
| 58 | PyString_FromString(data), Py_BuildValue("i",len), NULL |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | * pjsip_event_Object |
| 66 | * C/python typewrapper for event struct |
| 67 | */ |
| 68 | typedef struct |
| 69 | { |
| 70 | PyObject_HEAD |
| 71 | /* Type-specific fields go here. */ |
| 72 | pjsip_event * event; |
| 73 | } pjsip_event_Object; |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * pjsip_event_Type |
| 78 | * event struct signatures |
| 79 | */ |
| 80 | static PyTypeObject pjsip_event_Type = |
| 81 | { |
| 82 | PyObject_HEAD_INIT(NULL) |
| 83 | 0, /*ob_size*/ |
| 84 | "py_pjsua.PJSIP_Event", /*tp_name*/ |
| 85 | sizeof(pjsip_event_Object), /*tp_basicsize*/ |
| 86 | 0, /*tp_itemsize*/ |
| 87 | 0, /*tp_dealloc*/ |
| 88 | 0, /*tp_print*/ |
| 89 | 0, /*tp_getattr*/ |
| 90 | 0, /*tp_setattr*/ |
| 91 | 0, /*tp_compare*/ |
| 92 | 0, /*tp_repr*/ |
| 93 | 0, /*tp_as_number*/ |
| 94 | 0, /*tp_as_sequence*/ |
| 95 | 0, /*tp_as_mapping*/ |
| 96 | 0, /*tp_hash */ |
| 97 | 0, /*tp_call*/ |
| 98 | 0, /*tp_str*/ |
| 99 | 0, /*tp_getattro*/ |
| 100 | 0, /*tp_setattro*/ |
| 101 | 0, /*tp_as_buffer*/ |
| 102 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 103 | "pjsip_event objects", /*tp_doc */ |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 107 | /* |
| 108 | * pjsip_rx_data_Object |
| 109 | * C/python typewrapper for RX data struct |
| 110 | */ |
| 111 | typedef struct |
| 112 | { |
| 113 | PyObject_HEAD |
| 114 | /* Type-specific fields go here. */ |
| 115 | pjsip_rx_data * rdata; |
| 116 | } pjsip_rx_data_Object; |
| 117 | |
| 118 | |
| 119 | /* |
| 120 | * pjsip_rx_data_Type |
| 121 | */ |
| 122 | static PyTypeObject pjsip_rx_data_Type = |
| 123 | { |
| 124 | PyObject_HEAD_INIT(NULL) |
| 125 | 0, /*ob_size*/ |
| 126 | "py_pjsua.PJSIP_RX_Data", /*tp_name*/ |
| 127 | sizeof(pjsip_rx_data_Object), /*tp_basicsize*/ |
| 128 | 0, /*tp_itemsize*/ |
| 129 | 0, /*tp_dealloc*/ |
| 130 | 0, /*tp_print*/ |
| 131 | 0, /*tp_getattr*/ |
| 132 | 0, /*tp_setattr*/ |
| 133 | 0, /*tp_compare*/ |
| 134 | 0, /*tp_repr*/ |
| 135 | 0, /*tp_as_number*/ |
| 136 | 0, /*tp_as_sequence*/ |
| 137 | 0, /*tp_as_mapping*/ |
| 138 | 0, /*tp_hash */ |
| 139 | 0, /*tp_call*/ |
| 140 | 0, /*tp_str*/ |
| 141 | 0, /*tp_getattro*/ |
| 142 | 0, /*tp_setattro*/ |
| 143 | 0, /*tp_as_buffer*/ |
| 144 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 145 | "pjsip_rx_data objects", /*tp_doc*/ |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | * callback_Object |
| 151 | * C/python typewrapper for callback struct |
| 152 | */ |
| 153 | typedef struct |
| 154 | { |
| 155 | PyObject_HEAD |
| 156 | /* Type-specific fields go here. */ |
| 157 | PyObject * on_call_state; |
| 158 | PyObject * on_incoming_call; |
| 159 | PyObject * on_call_media_state; |
| 160 | PyObject * on_call_transfer_request; |
| 161 | PyObject * on_call_transfer_status; |
| 162 | PyObject * on_call_replace_request; |
| 163 | PyObject * on_call_replaced; |
| 164 | PyObject * on_reg_state; |
| 165 | PyObject * on_buddy_state; |
| 166 | PyObject * on_pager; |
| 167 | PyObject * on_pager_status; |
| 168 | PyObject * on_typing; |
| 169 | |
| 170 | } callback_Object; |
| 171 | |
| 172 | |
| 173 | /* |
| 174 | * The global callback object. |
| 175 | */ |
| 176 | static callback_Object * obj_callback; |
| 177 | |
| 178 | |
| 179 | /* |
| 180 | * cb_on_call_state |
| 181 | * declares method on_call_state for callback struct |
| 182 | */ |
| 183 | static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e) |
| 184 | { |
| 185 | if (PyCallable_Check(obj_callback->on_call_state)) |
| 186 | { |
| 187 | pjsip_event_Object * obj = |
| 188 | (pjsip_event_Object *)PyType_GenericNew(&pjsip_event_Type, |
| 189 | NULL, NULL); |
| 190 | obj->event = e; |
| 191 | |
| 192 | PyObject_CallFunctionObjArgs( |
| 193 | obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL |
| 194 | ); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /* |
| 200 | * cb_on_incoming_call |
| 201 | * declares method on_incoming_call for callback struct |
| 202 | */ |
| 203 | static void cb_on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, |
| 204 | pjsip_rx_data *rdata) |
| 205 | { |
| 206 | if (PyCallable_Check(obj_callback->on_incoming_call)) |
| 207 | { |
| 208 | pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) |
| 209 | PyType_GenericNew(&pjsip_rx_data_Type, |
| 210 | NULL, NULL); |
| 211 | obj->rdata = rdata; |
| 212 | |
| 213 | PyObject_CallFunctionObjArgs( |
| 214 | obj_callback->on_incoming_call, |
| 215 | Py_BuildValue("i",acc_id), |
| 216 | Py_BuildValue("i",call_id), |
| 217 | obj, |
| 218 | NULL |
| 219 | ); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /* |
| 225 | * cb_on_call_media_state |
| 226 | * declares method on_call_media_state for callback struct |
| 227 | */ |
| 228 | static void cb_on_call_media_state(pjsua_call_id call_id) |
| 229 | { |
| 230 | if (PyCallable_Check(obj_callback->on_call_media_state)) |
| 231 | { |
| 232 | PyObject_CallFunction(obj_callback->on_call_media_state,"i",call_id); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | /* |
| 238 | * Notify application on call being transfered. |
| 239 | */ |
| 240 | static void cb_on_call_transfer_request(pjsua_call_id call_id, |
| 241 | const pj_str_t *dst, |
| 242 | pjsip_status_code *code) |
| 243 | { |
| 244 | if (PyCallable_Check(obj_callback->on_call_transfer_request)) |
| 245 | { |
| 246 | PyObject_CallFunctionObjArgs( |
| 247 | obj_callback->on_call_transfer_request, |
| 248 | Py_BuildValue("i",call_id), |
| 249 | PyString_FromStringAndSize(dst->ptr, dst->slen), |
| 250 | Py_BuildValue("i",*code), |
| 251 | NULL |
| 252 | ); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | |
| 257 | /* |
| 258 | * Notify application of the status of previously sent call |
| 259 | * transfer request. Application can monitor the status of the |
| 260 | * call transfer request, for example to decide whether to |
| 261 | * terminate existing call. |
| 262 | */ |
| 263 | static void cb_on_call_transfer_status( pjsua_call_id call_id, |
| 264 | int status_code, |
| 265 | const pj_str_t *status_text, |
| 266 | pj_bool_t final, |
| 267 | pj_bool_t *p_cont) |
| 268 | { |
| 269 | if (PyCallable_Check(obj_callback->on_call_transfer_status)) |
| 270 | { |
| 271 | PyObject_CallFunctionObjArgs( |
| 272 | obj_callback->on_call_transfer_status, |
| 273 | Py_BuildValue("i",call_id), |
| 274 | Py_BuildValue("i",status_code), |
| 275 | PyString_FromStringAndSize(status_text->ptr, status_text->slen), |
| 276 | Py_BuildValue("i",final), |
| 277 | Py_BuildValue("i",*p_cont), |
| 278 | NULL |
| 279 | ); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | /* |
| 285 | * Notify application about incoming INVITE with Replaces header. |
| 286 | * Application may reject the request by setting non-2xx code. |
| 287 | */ |
| 288 | static void cb_on_call_replace_request( pjsua_call_id call_id, |
| 289 | pjsip_rx_data *rdata, |
| 290 | int *st_code, |
| 291 | pj_str_t *st_text) |
| 292 | { |
| 293 | if (PyCallable_Check(obj_callback->on_call_replace_request)) |
| 294 | { |
| 295 | pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) |
| 296 | PyType_GenericNew(&pjsip_rx_data_Type, |
| 297 | NULL, NULL); |
| 298 | obj->rdata = rdata; |
| 299 | |
| 300 | PyObject_CallFunctionObjArgs( |
| 301 | obj_callback->on_call_replace_request, |
| 302 | Py_BuildValue("i",call_id), |
| 303 | obj, |
| 304 | Py_BuildValue("i",*st_code), |
| 305 | PyString_FromStringAndSize(st_text->ptr, st_text->slen), |
| 306 | NULL |
| 307 | ); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | |
| 312 | /* |
| 313 | * Notify application that an existing call has been replaced with |
| 314 | * a new call. This happens when PJSUA-API receives incoming INVITE |
| 315 | * request with Replaces header. |
| 316 | */ |
| 317 | static void cb_on_call_replaced(pjsua_call_id old_call_id, |
| 318 | pjsua_call_id new_call_id) |
| 319 | { |
| 320 | if (PyCallable_Check(obj_callback->on_call_replaced)) |
| 321 | { |
| 322 | PyObject_CallFunctionObjArgs( |
| 323 | obj_callback->on_call_replaced, |
| 324 | Py_BuildValue("i",old_call_id), |
| 325 | Py_BuildValue("i",old_call_id), |
| 326 | NULL |
| 327 | ); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | |
| 332 | /* |
| 333 | * cb_on_reg_state |
| 334 | * declares method on_reg_state for callback struct |
| 335 | */ |
| 336 | static void cb_on_reg_state(pjsua_acc_id acc_id) |
| 337 | { |
| 338 | if (PyCallable_Check(obj_callback->on_reg_state)) |
| 339 | { |
| 340 | PyObject_CallFunction(obj_callback->on_reg_state,"i",acc_id); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /* |
| 346 | * cb_on_buddy_state |
| 347 | * declares method on_buddy state for callback struct |
| 348 | */ |
| 349 | static void cb_on_buddy_state(pjsua_buddy_id buddy_id) |
| 350 | { |
| 351 | if (PyCallable_Check(obj_callback->on_buddy_state)) |
| 352 | { |
| 353 | PyObject_CallFunction(obj_callback->on_buddy_state,"i",buddy_id); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * cb_on_pager |
| 359 | * * declares method on_pager for callback struct |
| 360 | */ |
| 361 | static void cb_on_pager(pjsua_call_id call_id, const pj_str_t *from, |
| 362 | const pj_str_t *to, const pj_str_t *contact, |
| 363 | const pj_str_t *mime_type, const pj_str_t *body) |
| 364 | { |
| 365 | if (PyCallable_Check(obj_callback->on_pager)) |
| 366 | { |
| 367 | PyObject_CallFunctionObjArgs( |
| 368 | obj_callback->on_pager,Py_BuildValue("i",call_id), |
| 369 | PyString_FromStringAndSize(from->ptr, from->slen), |
| 370 | PyString_FromStringAndSize(to->ptr, to->slen), |
| 371 | PyString_FromStringAndSize(contact->ptr, contact->slen), |
| 372 | PyString_FromStringAndSize(mime_type->ptr, mime_type->slen), |
| 373 | PyString_FromStringAndSize(body->ptr, body->slen), NULL |
| 374 | ); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /* |
| 380 | * cb_on_pager_status |
| 381 | * declares method on_pager_status for callback struct |
| 382 | */ |
| 383 | static void cb_on_pager_status(pjsua_call_id call_id, const pj_str_t *to, |
| 384 | const pj_str_t *body, void *user_data, |
| 385 | pjsip_status_code status, |
| 386 | const pj_str_t *reason) |
| 387 | { |
| 388 | PyObject * obj = PyType_GenericNew(user_data, NULL, NULL); |
| 389 | if (PyCallable_Check(obj_callback->on_pager)) |
| 390 | { |
| 391 | PyObject_CallFunctionObjArgs( |
| 392 | obj_callback->on_pager,Py_BuildValue("i",call_id), |
| 393 | PyString_FromStringAndSize(to->ptr, to->slen), |
| 394 | PyString_FromStringAndSize(body->ptr, body->slen),obj, |
| 395 | Py_BuildValue("i",status),PyString_FromStringAndSize(reason->ptr, |
| 396 | reason->slen),NULL |
| 397 | ); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /* |
| 403 | * cb_on_typing |
| 404 | * declares method on_typing for callback struct |
| 405 | */ |
| 406 | static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from, |
| 407 | const pj_str_t *to, const pj_str_t *contact, |
| 408 | pj_bool_t is_typing) |
| 409 | { |
| 410 | if (PyCallable_Check(obj_callback->on_typing)) |
| 411 | { |
| 412 | PyObject_CallFunctionObjArgs( |
| 413 | obj_callback->on_typing,Py_BuildValue("i",call_id), |
| 414 | PyString_FromStringAndSize(from->ptr, from->slen), |
| 415 | PyString_FromStringAndSize(to->ptr, to->slen), |
| 416 | PyString_FromStringAndSize(contact->ptr, contact->slen), |
| 417 | Py_BuildValue("i",is_typing),NULL |
| 418 | ); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | |
| 423 | /* |
| 424 | * callback_dealloc |
| 425 | * destructor function for callback struct |
| 426 | */ |
| 427 | static void callback_dealloc(callback_Object* self) |
| 428 | { |
| 429 | Py_XDECREF(self->on_call_state); |
| 430 | Py_XDECREF(self->on_incoming_call); |
| 431 | Py_XDECREF(self->on_call_media_state); |
| 432 | Py_XDECREF(self->on_call_transfer_request); |
| 433 | Py_XDECREF(self->on_call_transfer_status); |
| 434 | Py_XDECREF(self->on_call_replace_request); |
| 435 | Py_XDECREF(self->on_call_replaced); |
| 436 | Py_XDECREF(self->on_reg_state); |
| 437 | Py_XDECREF(self->on_buddy_state); |
| 438 | Py_XDECREF(self->on_pager); |
| 439 | Py_XDECREF(self->on_pager_status); |
| 440 | Py_XDECREF(self->on_typing); |
| 441 | self->ob_type->tp_free((PyObject*)self); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /* |
| 446 | * callback_new |
| 447 | * * declares constructor for callback struct |
| 448 | */ |
| 449 | static PyObject * callback_new(PyTypeObject *type, PyObject *args, |
| 450 | PyObject *kwds) |
| 451 | { |
| 452 | callback_Object *self; |
| 453 | |
| 454 | self = (callback_Object *)type->tp_alloc(type, 0); |
| 455 | if (self != NULL) |
| 456 | { |
| 457 | Py_INCREF(Py_None); |
| 458 | self->on_call_state = Py_None; |
| 459 | if (self->on_call_state == NULL) |
| 460 | { |
| 461 | Py_DECREF(Py_None); |
| 462 | return NULL; |
| 463 | } |
| 464 | Py_INCREF(Py_None); |
| 465 | self->on_incoming_call = Py_None; |
| 466 | if (self->on_incoming_call == NULL) |
| 467 | { |
| 468 | Py_DECREF(Py_None); |
| 469 | return NULL; |
| 470 | } |
| 471 | Py_INCREF(Py_None); |
| 472 | self->on_call_media_state = Py_None; |
| 473 | if (self->on_call_media_state == NULL) |
| 474 | { |
| 475 | Py_DECREF(Py_None); |
| 476 | return NULL; |
| 477 | } |
| 478 | Py_INCREF(Py_None); |
| 479 | self->on_call_transfer_request = Py_None; |
| 480 | if (self->on_call_transfer_request == NULL) |
| 481 | { |
| 482 | Py_DECREF(Py_None); |
| 483 | return NULL; |
| 484 | } |
| 485 | Py_INCREF(Py_None); |
| 486 | self->on_call_transfer_status = Py_None; |
| 487 | if (self->on_call_transfer_status == NULL) |
| 488 | { |
| 489 | Py_DECREF(Py_None); |
| 490 | return NULL; |
| 491 | } |
| 492 | Py_INCREF(Py_None); |
| 493 | self->on_call_replace_request = Py_None; |
| 494 | if (self->on_call_replace_request == NULL) |
| 495 | { |
| 496 | Py_DECREF(Py_None); |
| 497 | return NULL; |
| 498 | } |
| 499 | Py_INCREF(Py_None); |
| 500 | self->on_call_replaced = Py_None; |
| 501 | if (self->on_call_replaced == NULL) |
| 502 | { |
| 503 | Py_DECREF(Py_None); |
| 504 | return NULL; |
| 505 | } |
| 506 | Py_INCREF(Py_None); |
| 507 | self->on_reg_state = Py_None; |
| 508 | if (self->on_reg_state == NULL) |
| 509 | { |
| 510 | Py_DECREF(Py_None); |
| 511 | return NULL; |
| 512 | } |
| 513 | Py_INCREF(Py_None); |
| 514 | self->on_buddy_state = Py_None; |
| 515 | if (self->on_buddy_state == NULL) |
| 516 | { |
| 517 | Py_DECREF(Py_None); |
| 518 | return NULL; |
| 519 | } |
| 520 | Py_INCREF(Py_None); |
| 521 | self->on_pager = Py_None; |
| 522 | if (self->on_pager == NULL) |
| 523 | { |
| 524 | Py_DECREF(Py_None); |
| 525 | return NULL; |
| 526 | } |
| 527 | Py_INCREF(Py_None); |
| 528 | self->on_pager_status = Py_None; |
| 529 | if (self->on_pager_status == NULL) |
| 530 | { |
| 531 | Py_DECREF(Py_None); |
| 532 | return NULL; |
| 533 | } |
| 534 | Py_INCREF(Py_None); |
| 535 | self->on_typing = Py_None; |
| 536 | if (self->on_typing == NULL) |
| 537 | { |
| 538 | Py_DECREF(Py_None); |
| 539 | return NULL; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | return (PyObject *)self; |
| 544 | } |
| 545 | |
| 546 | |
| 547 | /* |
| 548 | * callback_members |
| 549 | * declares available functions for callback object |
| 550 | */ |
| 551 | static PyMemberDef callback_members[] = |
| 552 | { |
| 553 | { |
| 554 | "on_call_state", T_OBJECT_EX, offsetof(callback_Object, on_call_state), |
| 555 | 0, "Notify application when invite state has changed. Application may " |
| 556 | "then query the call info to get the detail call states." |
| 557 | }, |
| 558 | { |
| 559 | "on_incoming_call", T_OBJECT_EX, |
| 560 | offsetof(callback_Object, on_incoming_call), 0, |
| 561 | "Notify application on incoming call." |
| 562 | }, |
| 563 | { |
| 564 | "on_call_media__state", T_OBJECT_EX, |
| 565 | offsetof(callback_Object, on_call_media_state), 0, |
| 566 | "Notify application when media state in the call has changed. Normal " |
| 567 | "application would need to implement this callback, e.g. to connect " |
| 568 | "the call's media to sound device." |
| 569 | }, |
| 570 | { |
| 571 | "on_call_transfer_request", T_OBJECT_EX, |
| 572 | offsetof(callback_Object, on_call_transfer_request), 0, |
| 573 | "Notify application on call being transfered. " |
| 574 | "Application can decide to accept/reject transfer request " |
| 575 | "by setting the code (default is 200). When this callback " |
| 576 | "is not defined, the default behavior is to accept the " |
| 577 | "transfer." |
| 578 | }, |
| 579 | { |
| 580 | "on_call_transfer_status", T_OBJECT_EX, |
| 581 | offsetof(callback_Object, on_call_transfer_status), 0, |
| 582 | "Notify application of the status of previously sent call " |
| 583 | "transfer request. Application can monitor the status of the " |
| 584 | "call transfer request, for example to decide whether to " |
| 585 | "terminate existing call." |
| 586 | }, |
| 587 | { |
| 588 | "on_call_replace_request", T_OBJECT_EX, |
| 589 | offsetof(callback_Object, on_call_replace_request), 0, |
| 590 | "Notify application about incoming INVITE with Replaces header. " |
| 591 | "Application may reject the request by setting non-2xx code." |
| 592 | }, |
| 593 | { |
| 594 | "on_call_replaced", T_OBJECT_EX, |
| 595 | offsetof(callback_Object, on_call_replaced), 0, |
| 596 | "Notify application that an existing call has been replaced with " |
| 597 | "a new call. This happens when PJSUA-API receives incoming INVITE " |
| 598 | "request with Replaces header." |
| 599 | " " |
| 600 | "After this callback is called, normally PJSUA-API will disconnect " |
| 601 | "old_call_id and establish new_call_id." |
| 602 | }, |
| 603 | { |
| 604 | "on_reg_state", T_OBJECT_EX, |
| 605 | offsetof(callback_Object, on_reg_state), 0, |
| 606 | "Notify application when registration status has changed. Application " |
| 607 | "may then query the account info to get the registration details." |
| 608 | }, |
| 609 | { |
| 610 | "on_buddy_state", T_OBJECT_EX, |
| 611 | offsetof(callback_Object, on_buddy_state), 0, |
| 612 | "Notify application when the buddy state has changed. Application may " |
| 613 | "then query the buddy into to get the details." |
| 614 | }, |
| 615 | { |
| 616 | "on_pager", T_OBJECT_EX, offsetof(callback_Object, on_pager), 0, |
| 617 | "Notify application on incoming pager (i.e. MESSAGE request). " |
| 618 | "Argument call_id will be -1 if MESSAGE request is not related to an " |
| 619 | "existing call." |
| 620 | }, |
| 621 | { |
| 622 | "on_pager_status", T_OBJECT_EX, |
| 623 | offsetof(callback_Object, on_pager_status), 0, |
| 624 | "Notify application about the delivery status of outgoing pager " |
| 625 | "request." |
| 626 | }, |
| 627 | { |
| 628 | "on_typing", T_OBJECT_EX, offsetof(callback_Object, on_typing), 0, |
| 629 | "Notify application about typing indication." |
| 630 | }, |
| 631 | {NULL} /* Sentinel */ |
| 632 | }; |
| 633 | |
| 634 | |
| 635 | /* |
| 636 | * callback_Type |
| 637 | * callback class definition |
| 638 | */ |
| 639 | static PyTypeObject callback_Type = |
| 640 | { |
| 641 | PyObject_HEAD_INIT(NULL) |
| 642 | 0, /*ob_size*/ |
| 643 | "py_pjsua.Callback", /*tp_name*/ |
| 644 | sizeof(callback_Object), /*tp_basicsize*/ |
| 645 | 0, /*tp_itemsize*/ |
| 646 | (destructor)callback_dealloc, /*tp_dealloc*/ |
| 647 | 0, /*tp_print*/ |
| 648 | 0, /*tp_getattr*/ |
| 649 | 0, /*tp_setattr*/ |
| 650 | 0, /*tp_compare*/ |
| 651 | 0, /*tp_repr*/ |
| 652 | 0, /*tp_as_number*/ |
| 653 | 0, /*tp_as_sequence*/ |
| 654 | 0, /*tp_as_mapping*/ |
| 655 | 0, /*tp_hash */ |
| 656 | 0, /*tp_call*/ |
| 657 | 0, /*tp_str*/ |
| 658 | 0, /*tp_getattro*/ |
| 659 | 0, /*tp_setattro*/ |
| 660 | 0, /*tp_as_buffer*/ |
| 661 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 662 | "Callback objects", /* tp_doc */ |
| 663 | 0, /* tp_traverse */ |
| 664 | 0, /* tp_clear */ |
| 665 | 0, /* tp_richcompare */ |
| 666 | 0, /* tp_weaklistoffset */ |
| 667 | 0, /* tp_iter */ |
| 668 | 0, /* tp_iternext */ |
| 669 | 0, /* tp_methods */ |
| 670 | callback_members, /* tp_members */ |
| 671 | 0, /* tp_getset */ |
| 672 | 0, /* tp_base */ |
| 673 | 0, /* tp_dict */ |
| 674 | 0, /* tp_descr_get */ |
| 675 | 0, /* tp_descr_set */ |
| 676 | 0, /* tp_dictoffset */ |
| 677 | 0, /* tp_init */ |
| 678 | 0, /* tp_alloc */ |
| 679 | callback_new, /* tp_new */ |
| 680 | |
| 681 | }; |
| 682 | |
| 683 | |
| 684 | /* |
| 685 | * media_config_Object |
| 686 | * C/Python wrapper for media_config object |
| 687 | */ |
| 688 | typedef struct |
| 689 | { |
| 690 | PyObject_HEAD |
| 691 | /* Type-specific fields go here. */ |
| 692 | unsigned clock_rate; |
| 693 | unsigned max_media_ports; |
| 694 | int has_ioqueue; |
| 695 | unsigned thread_cnt; |
| 696 | unsigned quality; |
| 697 | unsigned ptime; |
| 698 | int no_vad; |
| 699 | unsigned ilbc_mode; |
| 700 | unsigned tx_drop_pct; |
| 701 | unsigned rx_drop_pct; |
| 702 | unsigned ec_options; |
| 703 | unsigned ec_tail_len; |
| 704 | } media_config_Object; |
| 705 | |
| 706 | |
| 707 | /* |
| 708 | * media_config_members |
| 709 | * declares attributes accessible from both C and Python for media_config file |
| 710 | */ |
| 711 | static PyMemberDef media_config_members[] = |
| 712 | { |
| 713 | { |
| 714 | "clock_rate", T_INT, offsetof(media_config_Object, clock_rate), 0, |
| 715 | "Clock rate to be applied to the conference bridge. If value is zero, " |
| 716 | "default clock rate will be used (16KHz)." |
| 717 | }, |
| 718 | { |
| 719 | "max_media_ports", T_INT, |
| 720 | offsetof(media_config_Object, max_media_ports), 0, |
| 721 | "Specify maximum number of media ports to be created in the " |
| 722 | "conference bridge. Since all media terminate in the bridge (calls, " |
| 723 | "file player, file recorder, etc), the value must be large enough to " |
| 724 | "support all of them. However, the larger the value, the more " |
| 725 | "computations are performed." |
| 726 | }, |
| 727 | { |
| 728 | "has_ioqueue", T_INT, offsetof(media_config_Object, has_ioqueue), 0, |
| 729 | "Specify whether the media manager should manage its own ioqueue for " |
| 730 | "the RTP/RTCP sockets. If yes, ioqueue will be created and at least " |
| 731 | "one worker thread will be created too. If no, the RTP/RTCP sockets " |
| 732 | "will share the same ioqueue as SIP sockets, and no worker thread is " |
| 733 | "needed." |
| 734 | }, |
| 735 | { |
| 736 | "thread_cnt", T_INT, offsetof(media_config_Object, thread_cnt), 0, |
| 737 | "Specify the number of worker threads to handle incoming RTP packets. " |
| 738 | "A value of one is recommended for most applications." |
| 739 | }, |
| 740 | { |
| 741 | "quality", T_INT, offsetof(media_config_Object, quality), 0, |
| 742 | "The media quality also sets speex codec quality/complexity to the " |
| 743 | "number." |
| 744 | }, |
| 745 | { |
| 746 | "ptime", T_INT, offsetof(media_config_Object, ptime), 0, |
| 747 | "Specify default ptime." |
| 748 | }, |
| 749 | { |
| 750 | "no_vad", T_INT, offsetof(media_config_Object, no_vad), 0, |
| 751 | "Disable VAD?" |
| 752 | }, |
| 753 | { |
| 754 | "ilbc_mode", T_INT, offsetof(media_config_Object, ilbc_mode), 0, |
| 755 | "iLBC mode (20 or 30)." |
| 756 | }, |
| 757 | { |
| 758 | "tx_drop_pct", T_INT, offsetof(media_config_Object, tx_drop_pct), 0, |
| 759 | "Percentage of RTP packet to drop in TX direction (to simulate packet " |
| 760 | "lost)." |
| 761 | }, |
| 762 | { |
| 763 | "rx_drop_pct", T_INT, offsetof(media_config_Object, rx_drop_pct), 0, |
| 764 | "Percentage of RTP packet to drop in RX direction (to simulate packet " |
| 765 | "lost)."}, |
| 766 | { |
| 767 | "ec_options", T_INT, offsetof(media_config_Object, ec_options), 0, |
| 768 | "Echo canceller options (see #pjmedia_echo_create())" |
| 769 | }, |
| 770 | { |
| 771 | "ec_tail_len", T_INT, offsetof(media_config_Object, ec_tail_len), 0, |
| 772 | "Echo canceller tail length, in miliseconds." |
| 773 | }, |
| 774 | {NULL} /* Sentinel */ |
| 775 | }; |
| 776 | |
| 777 | |
| 778 | /* |
| 779 | * media_config_Type |
| 780 | */ |
| 781 | static PyTypeObject media_config_Type = |
| 782 | { |
| 783 | PyObject_HEAD_INIT(NULL) |
| 784 | 0, /*ob_size*/ |
| 785 | "py_pjsua.Media_Config", /*tp_name*/ |
| 786 | sizeof(media_config_Object), /*tp_basicsize*/ |
| 787 | 0, /*tp_itemsize*/ |
| 788 | 0, /*tp_dealloc*/ |
| 789 | 0, /*tp_print*/ |
| 790 | 0, /*tp_getattr*/ |
| 791 | 0, /*tp_setattr*/ |
| 792 | 0, /*tp_compare*/ |
| 793 | 0, /*tp_repr*/ |
| 794 | 0, /*tp_as_number*/ |
| 795 | 0, /*tp_as_sequence*/ |
| 796 | 0, /*tp_as_mapping*/ |
| 797 | 0, /*tp_hash */ |
| 798 | 0, /*tp_call*/ |
| 799 | 0, /*tp_str*/ |
| 800 | 0, /*tp_getattro*/ |
| 801 | 0, /*tp_setattro*/ |
| 802 | 0, /*tp_as_buffer*/ |
| 803 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 804 | "Media Config objects", /*tp_doc*/ |
| 805 | 0, /*tp_traverse*/ |
| 806 | 0, /*tp_clear*/ |
| 807 | 0, /*tp_richcompare*/ |
| 808 | 0, /* tp_weaklistoffset */ |
| 809 | 0, /* tp_iter */ |
| 810 | 0, /* tp_iternext */ |
| 811 | 0, /* tp_methods */ |
| 812 | media_config_members, /* tp_members */ |
| 813 | |
| 814 | }; |
| 815 | |
| 816 | |
| 817 | /* |
| 818 | * config_Object |
| 819 | * attribute list for config object |
| 820 | */ |
| 821 | typedef struct |
| 822 | { |
| 823 | PyObject_HEAD |
| 824 | /* Type-specific fields go here. */ |
| 825 | unsigned max_calls; |
| 826 | unsigned thread_cnt; |
| 827 | unsigned outbound_proxy_cnt; |
| 828 | pj_str_t outbound_proxy[4]; |
| 829 | unsigned cred_count; |
| 830 | pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES]; |
| 831 | callback_Object * cb; |
| 832 | PyObject * user_agent; |
| 833 | } config_Object; |
| 834 | |
| 835 | |
| 836 | /* |
| 837 | * config_dealloc |
| 838 | * deallocates a config object |
| 839 | */ |
| 840 | static void config_dealloc(config_Object* self) |
| 841 | { |
| 842 | Py_XDECREF(self->cb); |
| 843 | Py_XDECREF(self->user_agent); |
| 844 | self->ob_type->tp_free((PyObject*)self); |
| 845 | } |
| 846 | |
| 847 | /* |
| 848 | * config_new |
| 849 | * config object constructor |
| 850 | */ |
| 851 | static PyObject *config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 852 | { |
| 853 | config_Object *self; |
| 854 | |
| 855 | self = (config_Object *)type->tp_alloc(type, 0); |
| 856 | if (self != NULL) |
| 857 | { |
| 858 | self->user_agent = PyString_FromString(""); |
| 859 | if (self->user_agent == NULL) |
| 860 | { |
| 861 | Py_DECREF(self); |
| 862 | return NULL; |
| 863 | } |
| 864 | self->cb = (callback_Object *)PyType_GenericNew( |
| 865 | &callback_Type, NULL, NULL |
| 866 | ); |
| 867 | if (self->cb == NULL) |
| 868 | { |
| 869 | Py_DECREF(Py_None); |
| 870 | return NULL; |
| 871 | } |
| 872 | } |
| 873 | return (PyObject *)self; |
| 874 | } |
| 875 | |
| 876 | |
| 877 | /* |
| 878 | * config_members |
| 879 | * attribute list accessible from Python/C |
| 880 | */ |
| 881 | static PyMemberDef config_members[] = |
| 882 | { |
| 883 | { |
| 884 | "max_calls", T_INT, offsetof(config_Object, max_calls), 0, |
| 885 | "Maximum calls to support (default: 4) " |
| 886 | }, |
| 887 | { |
| 888 | "thread_cnt", T_INT, offsetof(config_Object, thread_cnt), 0, |
| 889 | "Number of worker threads. Normally application will want to have at " |
| 890 | "least one worker thread, unless when it wants to poll the library " |
| 891 | "periodically, which in this case the worker thread can be set to " |
| 892 | "zero." |
| 893 | }, |
| 894 | { |
| 895 | "outbound_proxy_cnt", T_INT, |
| 896 | offsetof(config_Object, outbound_proxy_cnt), 0, |
| 897 | "Number of outbound proxies in the array." |
| 898 | }, |
| 899 | { |
| 900 | "cred_count", T_INT, offsetof(config_Object, cred_count), 0, |
| 901 | "Number of credentials in the credential array." |
| 902 | }, |
| 903 | { |
| 904 | "user_agent", T_OBJECT_EX, offsetof(config_Object, user_agent), 0, |
| 905 | "User agent string (default empty)" |
| 906 | }, |
| 907 | { |
| 908 | "cb", T_OBJECT_EX, offsetof(config_Object, cb), 0, |
| 909 | "Application callback." |
| 910 | }, |
| 911 | {NULL} /* Sentinel */ |
| 912 | }; |
| 913 | |
| 914 | |
| 915 | /* |
| 916 | * config_Type |
| 917 | * type wrapper for config class |
| 918 | */ |
| 919 | static PyTypeObject config_Type = |
| 920 | { |
| 921 | PyObject_HEAD_INIT(NULL) |
| 922 | 0, /*ob_size*/ |
| 923 | "py_pjsua.Config", /*tp_name*/ |
| 924 | sizeof(config_Object), /*tp_basicsize*/ |
| 925 | 0, /*tp_itemsize*/ |
| 926 | (destructor)config_dealloc,/*tp_dealloc*/ |
| 927 | 0, /*tp_print*/ |
| 928 | 0, /*tp_getattr*/ |
| 929 | 0, /*tp_setattr*/ |
| 930 | 0, /*tp_compare*/ |
| 931 | 0, /*tp_repr*/ |
| 932 | 0, /*tp_as_number*/ |
| 933 | 0, /*tp_as_sequence*/ |
| 934 | 0, /*tp_as_mapping*/ |
| 935 | 0, /*tp_hash */ |
| 936 | 0, /*tp_call*/ |
| 937 | 0, /*tp_str*/ |
| 938 | 0, /*tp_getattro*/ |
| 939 | 0, /*tp_setattro*/ |
| 940 | 0, /*tp_as_buffer*/ |
| 941 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 942 | "Config objects", /* tp_doc */ |
| 943 | 0, /* tp_traverse */ |
| 944 | 0, /* tp_clear */ |
| 945 | 0, /* tp_richcompare */ |
| 946 | 0, /* tp_weaklistoffset */ |
| 947 | 0, /* tp_iter */ |
| 948 | 0, /* tp_iternext */ |
| 949 | 0, /* tp_methods */ |
| 950 | config_members, /* tp_members */ |
| 951 | 0, /* tp_getset */ |
| 952 | 0, /* tp_base */ |
| 953 | 0, /* tp_dict */ |
| 954 | 0, /* tp_descr_get */ |
| 955 | 0, /* tp_descr_set */ |
| 956 | 0, /* tp_dictoffset */ |
| 957 | 0, /* tp_init */ |
| 958 | 0, /* tp_alloc */ |
| 959 | config_new, /* tp_new */ |
| 960 | |
| 961 | }; |
| 962 | |
| 963 | |
| 964 | /* |
| 965 | * logging_config_Object |
| 966 | * configuration class for logging_config object |
| 967 | */ |
| 968 | typedef struct |
| 969 | { |
| 970 | PyObject_HEAD |
| 971 | /* Type-specific fields go here. */ |
| 972 | int msg_logging; |
| 973 | unsigned level; |
| 974 | unsigned console_level; |
| 975 | unsigned decor; |
| 976 | PyObject * log_filename; |
| 977 | PyObject * cb; |
| 978 | } logging_config_Object; |
| 979 | |
| 980 | |
| 981 | /* |
| 982 | * logging_config_dealloc |
| 983 | * deletes a logging config from memory |
| 984 | */ |
| 985 | static void logging_config_dealloc(logging_config_Object* self) |
| 986 | { |
| 987 | Py_XDECREF(self->log_filename); |
| 988 | Py_XDECREF(self->cb); |
| 989 | self->ob_type->tp_free((PyObject*)self); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | /* |
| 994 | * logging_config_new |
| 995 | * constructor for logging_config object |
| 996 | */ |
| 997 | static PyObject * logging_config_new(PyTypeObject *type, PyObject *args, |
| 998 | PyObject *kwds) |
| 999 | { |
| 1000 | logging_config_Object *self; |
| 1001 | |
| 1002 | self = (logging_config_Object *)type->tp_alloc(type, 0); |
| 1003 | if (self != NULL) |
| 1004 | { |
| 1005 | self->log_filename = PyString_FromString(""); |
| 1006 | if (self->log_filename == NULL) |
| 1007 | { |
| 1008 | Py_DECREF(self); |
| 1009 | return NULL; |
| 1010 | } |
| 1011 | Py_INCREF(Py_None); |
| 1012 | self->cb = Py_None; |
| 1013 | if (self->cb == NULL) |
| 1014 | { |
| 1015 | Py_DECREF(Py_None); |
| 1016 | return NULL; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | return (PyObject *)self; |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | /* |
| 1025 | * logging_config_members |
| 1026 | */ |
| 1027 | static PyMemberDef logging_config_members[] = |
| 1028 | { |
| 1029 | { |
| 1030 | "msg_logging", T_INT, offsetof(logging_config_Object, msg_logging), 0, |
| 1031 | "Log incoming and outgoing SIP message? Yes!" |
| 1032 | }, |
| 1033 | { |
| 1034 | "level", T_INT, offsetof(logging_config_Object, level), 0, |
| 1035 | "Input verbosity level. Value 5 is reasonable." |
| 1036 | }, |
| 1037 | { |
| 1038 | "console_level", T_INT, offsetof(logging_config_Object, console_level), |
| 1039 | 0, "Verbosity level for console. Value 4 is reasonable." |
| 1040 | }, |
| 1041 | { |
| 1042 | "decor", T_INT, offsetof(logging_config_Object, decor), 0, |
| 1043 | "Log decoration" |
| 1044 | }, |
| 1045 | { |
| 1046 | "log_filename", T_OBJECT_EX, |
| 1047 | offsetof(logging_config_Object, log_filename), 0, |
| 1048 | "Optional log filename" |
| 1049 | }, |
| 1050 | { |
| 1051 | "cb", T_OBJECT_EX, offsetof(logging_config_Object, cb), 0, |
| 1052 | "Optional callback function to be called to write log to application " |
| 1053 | "specific device. This function will be called forlog messages on " |
| 1054 | "input verbosity level." |
| 1055 | }, |
| 1056 | {NULL} /* Sentinel */ |
| 1057 | }; |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | /* |
| 1063 | * logging_config_Type |
| 1064 | */ |
| 1065 | static PyTypeObject logging_config_Type = |
| 1066 | { |
| 1067 | PyObject_HEAD_INIT(NULL) |
| 1068 | 0, /*ob_size*/ |
| 1069 | "py_pjsua.Logging_Config", /*tp_name*/ |
| 1070 | sizeof(logging_config_Object), /*tp_basicsize*/ |
| 1071 | 0, /*tp_itemsize*/ |
| 1072 | (destructor)logging_config_dealloc,/*tp_dealloc*/ |
| 1073 | 0, /*tp_print*/ |
| 1074 | 0, /*tp_getattr*/ |
| 1075 | 0, /*tp_setattr*/ |
| 1076 | 0, /*tp_compare*/ |
| 1077 | 0, /*tp_repr*/ |
| 1078 | 0, /*tp_as_number*/ |
| 1079 | 0, /*tp_as_sequence*/ |
| 1080 | 0, /*tp_as_mapping*/ |
| 1081 | 0, /*tp_hash */ |
| 1082 | 0, /*tp_call*/ |
| 1083 | 0, /*tp_str*/ |
| 1084 | 0, /*tp_getattro*/ |
| 1085 | 0, /*tp_setattro*/ |
| 1086 | 0, /*tp_as_buffer*/ |
| 1087 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1088 | "Logging Config objects", /* tp_doc */ |
| 1089 | 0, /* tp_traverse */ |
| 1090 | 0, /* tp_clear */ |
| 1091 | 0, /* tp_richcompare */ |
| 1092 | 0, /* tp_weaklistoffset */ |
| 1093 | 0, /* tp_iter */ |
| 1094 | 0, /* tp_iternext */ |
| 1095 | 0, /* tp_methods */ |
| 1096 | logging_config_members, /* tp_members */ |
| 1097 | 0, /* tp_getset */ |
| 1098 | 0, /* tp_base */ |
| 1099 | 0, /* tp_dict */ |
| 1100 | 0, /* tp_descr_get */ |
| 1101 | 0, /* tp_descr_set */ |
| 1102 | 0, /* tp_dictoffset */ |
| 1103 | 0, /* tp_init */ |
| 1104 | 0, /* tp_alloc */ |
| 1105 | logging_config_new, /* tp_new */ |
| 1106 | |
| 1107 | }; |
| 1108 | |
| 1109 | |
| 1110 | /* |
| 1111 | * msg_data_Object |
| 1112 | * typewrapper for MessageData class |
| 1113 | */ |
| 1114 | typedef struct |
| 1115 | { |
| 1116 | PyObject_HEAD |
| 1117 | /* Type-specific fields go here. */ |
| 1118 | pjsip_hdr hdr_list; |
| 1119 | PyObject * content_type; |
| 1120 | PyObject * msg_body; |
| 1121 | } msg_data_Object; |
| 1122 | |
| 1123 | |
| 1124 | /* |
| 1125 | * msg_data_dealloc |
| 1126 | * deletes a msg_data |
| 1127 | */ |
| 1128 | static void msg_data_dealloc(msg_data_Object* self) |
| 1129 | { |
| 1130 | Py_XDECREF(self->content_type); |
| 1131 | Py_XDECREF(self->msg_body); |
| 1132 | self->ob_type->tp_free((PyObject*)self); |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | /* |
| 1137 | * msg_data_new |
| 1138 | * constructor for msg_data object |
| 1139 | */ |
| 1140 | static PyObject * msg_data_new(PyTypeObject *type, PyObject *args, |
| 1141 | PyObject *kwds) |
| 1142 | { |
| 1143 | msg_data_Object *self; |
| 1144 | |
| 1145 | self = (msg_data_Object *)type->tp_alloc(type, 0); |
| 1146 | if (self != NULL) |
| 1147 | { |
| 1148 | self->content_type = PyString_FromString(""); |
| 1149 | if (self->content_type == NULL) |
| 1150 | { |
| 1151 | Py_DECREF(self); |
| 1152 | return NULL; |
| 1153 | } |
| 1154 | self->msg_body = PyString_FromString(""); |
| 1155 | if (self->msg_body == NULL) |
| 1156 | { |
| 1157 | Py_DECREF(self); |
| 1158 | return NULL; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | return (PyObject *)self; |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | /* |
| 1167 | * msg_data_members |
| 1168 | */ |
| 1169 | static PyMemberDef msg_data_members[] = |
| 1170 | { |
| 1171 | { |
| 1172 | "content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type), |
| 1173 | 0, "MIME type of optional message body." |
| 1174 | }, |
| 1175 | { |
| 1176 | "msg_body", T_OBJECT_EX, offsetof(msg_data_Object, msg_body), 0, |
| 1177 | "Optional message body." |
| 1178 | }, |
| 1179 | {NULL} /* Sentinel */ |
| 1180 | }; |
| 1181 | |
| 1182 | |
| 1183 | /* |
| 1184 | * msg_data_Type |
| 1185 | */ |
| 1186 | static PyTypeObject msg_data_Type = |
| 1187 | { |
| 1188 | PyObject_HEAD_INIT(NULL) |
| 1189 | 0, /*ob_size*/ |
| 1190 | "py_pjsua.Msg_Data", /*tp_name*/ |
| 1191 | sizeof(msg_data_Object), /*tp_basicsize*/ |
| 1192 | 0, /*tp_itemsize*/ |
| 1193 | (destructor)msg_data_dealloc,/*tp_dealloc*/ |
| 1194 | 0, /*tp_print*/ |
| 1195 | 0, /*tp_getattr*/ |
| 1196 | 0, /*tp_setattr*/ |
| 1197 | 0, /*tp_compare*/ |
| 1198 | 0, /*tp_repr*/ |
| 1199 | 0, /*tp_as_number*/ |
| 1200 | 0, /*tp_as_sequence*/ |
| 1201 | 0, /*tp_as_mapping*/ |
| 1202 | 0, /*tp_hash */ |
| 1203 | 0, /*tp_call*/ |
| 1204 | 0, /*tp_str*/ |
| 1205 | 0, /*tp_getattro*/ |
| 1206 | 0, /*tp_setattro*/ |
| 1207 | 0, /*tp_as_buffer*/ |
| 1208 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1209 | "msg_data objects", /* tp_doc */ |
| 1210 | 0, /* tp_traverse */ |
| 1211 | 0, /* tp_clear */ |
| 1212 | 0, /* tp_richcompare */ |
| 1213 | 0, /* tp_weaklistoffset */ |
| 1214 | 0, /* tp_iter */ |
| 1215 | 0, /* tp_iternext */ |
| 1216 | 0, /* tp_methods */ |
| 1217 | msg_data_members, /* tp_members */ |
| 1218 | 0, /* tp_getset */ |
| 1219 | 0, /* tp_base */ |
| 1220 | 0, /* tp_dict */ |
| 1221 | 0, /* tp_descr_get */ |
| 1222 | 0, /* tp_descr_set */ |
| 1223 | 0, /* tp_dictoffset */ |
| 1224 | 0, /* tp_init */ |
| 1225 | 0, /* tp_alloc */ |
| 1226 | msg_data_new, /* tp_new */ |
| 1227 | |
| 1228 | }; |
| 1229 | |
| 1230 | |
| 1231 | /* |
| 1232 | * pj_pool_Object |
| 1233 | */ |
| 1234 | typedef struct |
| 1235 | { |
| 1236 | PyObject_HEAD |
| 1237 | /* Type-specific fields go here. */ |
| 1238 | pj_pool_t * pool; |
| 1239 | } pj_pool_Object; |
| 1240 | |
| 1241 | |
| 1242 | /* |
| 1243 | * pj_pool_Type |
| 1244 | */ |
| 1245 | static PyTypeObject pj_pool_Type = |
| 1246 | { |
| 1247 | PyObject_HEAD_INIT(NULL) |
| 1248 | 0, /*ob_size*/ |
| 1249 | "py_pjsua.PJ_Pool", /*tp_name*/ |
| 1250 | sizeof(pj_pool_Object), /*tp_basicsize*/ |
| 1251 | 0, /*tp_itemsize*/ |
| 1252 | 0, /*tp_dealloc*/ |
| 1253 | 0, /*tp_print*/ |
| 1254 | 0, /*tp_getattr*/ |
| 1255 | 0, /*tp_setattr*/ |
| 1256 | 0, /*tp_compare*/ |
| 1257 | 0, /*tp_repr*/ |
| 1258 | 0, /*tp_as_number*/ |
| 1259 | 0, /*tp_as_sequence*/ |
| 1260 | 0, /*tp_as_mapping*/ |
| 1261 | 0, /*tp_hash */ |
| 1262 | 0, /*tp_call*/ |
| 1263 | 0, /*tp_str*/ |
| 1264 | 0, /*tp_getattro*/ |
| 1265 | 0, /*tp_setattro*/ |
| 1266 | 0, /*tp_as_buffer*/ |
| 1267 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1268 | "pj_pool_t objects", /* tp_doc */ |
| 1269 | |
| 1270 | }; |
| 1271 | |
| 1272 | |
| 1273 | /* |
| 1274 | * pjsip_endpoint_Object |
| 1275 | */ |
| 1276 | typedef struct |
| 1277 | { |
| 1278 | PyObject_HEAD |
| 1279 | /* Type-specific fields go here. */ |
| 1280 | pjsip_endpoint * endpt; |
| 1281 | } pjsip_endpoint_Object; |
| 1282 | |
| 1283 | |
| 1284 | /* |
| 1285 | * pjsip_endpoint_Type |
| 1286 | */ |
| 1287 | static PyTypeObject pjsip_endpoint_Type = |
| 1288 | { |
| 1289 | PyObject_HEAD_INIT(NULL) |
| 1290 | 0, /*ob_size*/ |
| 1291 | "py_pjsua.PJSIP_Endpoint", /*tp_name*/ |
| 1292 | sizeof(pjsip_endpoint_Object),/*tp_basicsize*/ |
| 1293 | 0, /*tp_itemsize*/ |
| 1294 | 0, /*tp_dealloc*/ |
| 1295 | 0, /*tp_print*/ |
| 1296 | 0, /*tp_getattr*/ |
| 1297 | 0, /*tp_setattr*/ |
| 1298 | 0, /*tp_compare*/ |
| 1299 | 0, /*tp_repr*/ |
| 1300 | 0, /*tp_as_number*/ |
| 1301 | 0, /*tp_as_sequence*/ |
| 1302 | 0, /*tp_as_mapping*/ |
| 1303 | 0, /*tp_hash */ |
| 1304 | 0, /*tp_call*/ |
| 1305 | 0, /*tp_str*/ |
| 1306 | 0, /*tp_getattro*/ |
| 1307 | 0, /*tp_setattro*/ |
| 1308 | 0, /*tp_as_buffer*/ |
| 1309 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1310 | "pjsip_endpoint objects", /* tp_doc */ |
| 1311 | }; |
| 1312 | |
| 1313 | |
| 1314 | /* |
| 1315 | * pjmedia_endpt_Object |
| 1316 | */ |
| 1317 | typedef struct |
| 1318 | { |
| 1319 | PyObject_HEAD |
| 1320 | /* Type-specific fields go here. */ |
| 1321 | pjmedia_endpt * endpt; |
| 1322 | } pjmedia_endpt_Object; |
| 1323 | |
| 1324 | |
| 1325 | /* |
| 1326 | * pjmedia_endpt_Type |
| 1327 | */ |
| 1328 | static PyTypeObject pjmedia_endpt_Type = |
| 1329 | { |
| 1330 | PyObject_HEAD_INIT(NULL) |
| 1331 | 0, /*ob_size*/ |
| 1332 | "py_pjsua.PJMedia_Endpt", /*tp_name*/ |
| 1333 | sizeof(pjmedia_endpt_Object), /*tp_basicsize*/ |
| 1334 | 0, /*tp_itemsize*/ |
| 1335 | 0, /*tp_dealloc*/ |
| 1336 | 0, /*tp_print*/ |
| 1337 | 0, /*tp_getattr*/ |
| 1338 | 0, /*tp_setattr*/ |
| 1339 | 0, /*tp_compare*/ |
| 1340 | 0, /*tp_repr*/ |
| 1341 | 0, /*tp_as_number*/ |
| 1342 | 0, /*tp_as_sequence*/ |
| 1343 | 0, /*tp_as_mapping*/ |
| 1344 | 0, /*tp_hash */ |
| 1345 | 0, /*tp_call*/ |
| 1346 | 0, /*tp_str*/ |
| 1347 | 0, /*tp_getattro*/ |
| 1348 | 0, /*tp_setattro*/ |
| 1349 | 0, /*tp_as_buffer*/ |
| 1350 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1351 | "pjmedia_endpt objects", /* tp_doc */ |
| 1352 | |
| 1353 | }; |
| 1354 | |
| 1355 | |
| 1356 | /* |
| 1357 | * pj_pool_factory_Object |
| 1358 | */ |
| 1359 | typedef struct |
| 1360 | { |
| 1361 | PyObject_HEAD |
| 1362 | /* Type-specific fields go here. */ |
| 1363 | pj_pool_factory * pool_fact; |
| 1364 | } pj_pool_factory_Object; |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | /* |
| 1369 | * pj_pool_factory_Type |
| 1370 | */ |
| 1371 | static PyTypeObject pj_pool_factory_Type = |
| 1372 | { |
| 1373 | PyObject_HEAD_INIT(NULL) |
| 1374 | 0, /*ob_size*/ |
| 1375 | "py_pjsua.PJ_Pool_Factory",/*tp_name*/ |
| 1376 | sizeof(pj_pool_factory_Object), /*tp_basicsize*/ |
| 1377 | 0, /*tp_itemsize*/ |
| 1378 | 0, /*tp_dealloc*/ |
| 1379 | 0, /*tp_print*/ |
| 1380 | 0, /*tp_getattr*/ |
| 1381 | 0, /*tp_setattr*/ |
| 1382 | 0, /*tp_compare*/ |
| 1383 | 0, /*tp_repr*/ |
| 1384 | 0, /*tp_as_number*/ |
| 1385 | 0, /*tp_as_sequence*/ |
| 1386 | 0, /*tp_as_mapping*/ |
| 1387 | 0, /*tp_hash */ |
| 1388 | 0, /*tp_call*/ |
| 1389 | 0, /*tp_str*/ |
| 1390 | 0, /*tp_getattro*/ |
| 1391 | 0, /*tp_setattro*/ |
| 1392 | 0, /*tp_as_buffer*/ |
| 1393 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1394 | "pj_pool_factory objects", /* tp_doc */ |
| 1395 | |
| 1396 | }; |
| 1397 | |
| 1398 | |
| 1399 | /* |
| 1400 | * pjsip_cred_info_Object |
| 1401 | */ |
| 1402 | typedef struct |
| 1403 | { |
| 1404 | PyObject_HEAD |
| 1405 | /* Type-specific fields go here. */ |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1406 | PyObject * realm; |
| 1407 | PyObject * scheme; |
| 1408 | PyObject * username; |
| 1409 | int data_type; |
| 1410 | PyObject * data; |
| 1411 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1412 | } pjsip_cred_info_Object; |
| 1413 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1414 | /* |
| 1415 | * cred_info_dealloc |
| 1416 | * deletes a cred info from memory |
| 1417 | */ |
| 1418 | static void pjsip_cred_info_dealloc(pjsip_cred_info_Object* self) |
| 1419 | { |
| 1420 | Py_XDECREF(self->realm); |
| 1421 | Py_XDECREF(self->scheme); |
| 1422 | Py_XDECREF(self->username); |
| 1423 | Py_XDECREF(self->data); |
| 1424 | self->ob_type->tp_free((PyObject*)self); |
| 1425 | } |
| 1426 | |
| 1427 | |
| 1428 | /* |
| 1429 | * cred_info_new |
| 1430 | * constructor for cred_info object |
| 1431 | */ |
| 1432 | static PyObject * pjsip_cred_info_new(PyTypeObject *type, PyObject *args, |
| 1433 | PyObject *kwds) |
| 1434 | { |
| 1435 | pjsip_cred_info_Object *self; |
| 1436 | |
| 1437 | self = (pjsip_cred_info_Object *)type->tp_alloc(type, 0); |
| 1438 | if (self != NULL) |
| 1439 | { |
| 1440 | self->realm = PyString_FromString(""); |
| 1441 | if (self->realm == NULL) |
| 1442 | { |
| 1443 | Py_DECREF(self); |
| 1444 | return NULL; |
| 1445 | } |
| 1446 | self->scheme = PyString_FromString(""); |
| 1447 | if (self->scheme == NULL) |
| 1448 | { |
| 1449 | Py_DECREF(self); |
| 1450 | return NULL; |
| 1451 | } |
| 1452 | self->username = PyString_FromString(""); |
| 1453 | if (self->username == NULL) |
| 1454 | { |
| 1455 | Py_DECREF(self); |
| 1456 | return NULL; |
| 1457 | } |
| 1458 | self->data = PyString_FromString(""); |
| 1459 | if (self->data == NULL) |
| 1460 | { |
| 1461 | Py_DECREF(self); |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | return (PyObject *)self; |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | /* |
| 1471 | * pjsip_cred_info_members |
| 1472 | */ |
| 1473 | static PyMemberDef pjsip_cred_info_members[] = |
| 1474 | { |
| 1475 | { |
| 1476 | "realm", T_OBJECT_EX, |
| 1477 | offsetof(pjsip_cred_info_Object, realm), 0, |
| 1478 | "Realm" |
| 1479 | }, |
| 1480 | { |
| 1481 | "scheme", T_OBJECT_EX, |
| 1482 | offsetof(pjsip_cred_info_Object, scheme), 0, |
| 1483 | "Scheme" |
| 1484 | }, |
| 1485 | { |
| 1486 | "username", T_OBJECT_EX, |
| 1487 | offsetof(pjsip_cred_info_Object, username), 0, |
| 1488 | "User name" |
| 1489 | }, |
| 1490 | { |
| 1491 | "data", T_OBJECT_EX, |
| 1492 | offsetof(pjsip_cred_info_Object, data), 0, |
| 1493 | "The data, which can be a plaintext password or a hashed digest. " |
| 1494 | }, |
| 1495 | { |
| 1496 | "data_type", T_INT, offsetof(pjsip_cred_info_Object, data_type), 0, |
| 1497 | "Type of data" |
| 1498 | }, |
| 1499 | |
| 1500 | {NULL} /* Sentinel */ |
| 1501 | }; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1502 | |
| 1503 | /* |
| 1504 | * pjsip_cred_info_Type |
| 1505 | */ |
| 1506 | static PyTypeObject pjsip_cred_info_Type = |
| 1507 | { |
| 1508 | PyObject_HEAD_INIT(NULL) |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1509 | 0, /*ob_size*/ |
| 1510 | "py_pjsua.PJSIP_Cred_Info", /*tp_name*/ |
| 1511 | sizeof(pjsip_cred_info_Object), /*tp_basicsize*/ |
| 1512 | 0, /*tp_itemsize*/ |
| 1513 | (destructor)pjsip_cred_info_dealloc,/*tp_dealloc*/ |
| 1514 | 0, /*tp_print*/ |
| 1515 | 0, /*tp_getattr*/ |
| 1516 | 0, /*tp_setattr*/ |
| 1517 | 0, /*tp_compare*/ |
| 1518 | 0, /*tp_repr*/ |
| 1519 | 0, /*tp_as_number*/ |
| 1520 | 0, /*tp_as_sequence*/ |
| 1521 | 0, /*tp_as_mapping*/ |
| 1522 | 0, /*tp_hash */ |
| 1523 | 0, /*tp_call*/ |
| 1524 | 0, /*tp_str*/ |
| 1525 | 0, /*tp_getattro*/ |
| 1526 | 0, /*tp_setattro*/ |
| 1527 | 0, /*tp_as_buffer*/ |
| 1528 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1529 | "PJSIP Cred Info objects", /* tp_doc */ |
| 1530 | 0, /* tp_traverse */ |
| 1531 | 0, /* tp_clear */ |
| 1532 | 0, /* tp_richcompare */ |
| 1533 | 0, /* tp_weaklistoffset */ |
| 1534 | 0, /* tp_iter */ |
| 1535 | 0, /* tp_iternext */ |
| 1536 | 0, /* tp_methods */ |
| 1537 | pjsip_cred_info_members, /* tp_members */ |
| 1538 | 0, /* tp_getset */ |
| 1539 | 0, /* tp_base */ |
| 1540 | 0, /* tp_dict */ |
| 1541 | 0, /* tp_descr_get */ |
| 1542 | 0, /* tp_descr_set */ |
| 1543 | 0, /* tp_dictoffset */ |
| 1544 | 0, /* tp_init */ |
| 1545 | 0, /* tp_alloc */ |
| 1546 | pjsip_cred_info_new, /* tp_new */ |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1547 | |
| 1548 | }; |
| 1549 | |
| 1550 | |
| 1551 | /* |
| 1552 | * py_pjsua_logging_config_default |
| 1553 | */ |
| 1554 | static PyObject *py_pjsua_logging_config_default(PyObject *pSelf, |
| 1555 | PyObject *pArgs) |
| 1556 | { |
| 1557 | logging_config_Object *obj; |
| 1558 | pjsua_logging_config cfg; |
| 1559 | |
| 1560 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 1561 | { |
| 1562 | return NULL; |
| 1563 | } |
| 1564 | /*pj_bzero(cfg, sizeof(*cfg)); |
| 1565 | |
| 1566 | cfg->msg_logging = obj->msg_logging; |
| 1567 | cfg->level = obj->level; |
| 1568 | cfg->console_level = obj->console_level; |
| 1569 | cfg->decor = obj->decor;*/ |
| 1570 | pjsua_logging_config_default(&cfg); |
| 1571 | obj->msg_logging = cfg.msg_logging; |
| 1572 | obj->level = cfg.level; |
| 1573 | obj->console_level = cfg.console_level; |
| 1574 | obj->decor = cfg.decor; |
| 1575 | /*printf("msg logging : %d\n",obj->msg_logging); |
| 1576 | printf("level : %d\n",obj->level); |
| 1577 | printf("console level : %d\n",obj->console_level); |
| 1578 | printf("decor : %d\n",obj->decor); |
| 1579 | printf("str sebelum "); |
| 1580 | printf(PyString_AsString(obj->log_filename)); |
| 1581 | |
| 1582 | Py_XDECREF(obj->log_filename); |
| 1583 | obj->log_filename = PyString_FromString("oke"); |
| 1584 | printf("\nstr sesudah "); |
| 1585 | printf(PyString_AsString(obj->log_filename));*/ |
| 1586 | Py_INCREF(Py_None); |
| 1587 | return Py_None; |
| 1588 | } |
| 1589 | |
| 1590 | |
| 1591 | /* |
| 1592 | * py_pjsua_config_default |
| 1593 | */ |
| 1594 | static PyObject *py_pjsua_config_default(PyObject *pSelf, PyObject *pArgs) |
| 1595 | { |
| 1596 | config_Object *obj; |
| 1597 | pjsua_config cfg; |
| 1598 | |
| 1599 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 1600 | { |
| 1601 | return NULL; |
| 1602 | } |
| 1603 | pjsua_config_default(&cfg); |
| 1604 | obj->max_calls = cfg.max_calls; |
| 1605 | obj->thread_cnt = cfg.thread_cnt; |
| 1606 | Py_INCREF(Py_None); |
| 1607 | return Py_None; |
| 1608 | } |
| 1609 | |
| 1610 | |
| 1611 | /* |
| 1612 | * py_pjsua_media_config_default |
| 1613 | */ |
| 1614 | static PyObject * py_pjsua_media_config_default(PyObject *pSelf, |
| 1615 | PyObject *pArgs) |
| 1616 | { |
| 1617 | media_config_Object *obj; |
| 1618 | pjsua_media_config cfg; |
| 1619 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 1620 | { |
| 1621 | return NULL; |
| 1622 | } |
| 1623 | pjsua_media_config_default(&cfg); |
| 1624 | obj->clock_rate = cfg.clock_rate; |
| 1625 | obj->ec_options = cfg.ec_options; |
| 1626 | obj->ec_tail_len = cfg.ec_tail_len; |
| 1627 | obj->has_ioqueue = cfg.has_ioqueue; |
| 1628 | obj->ilbc_mode = cfg.ilbc_mode; |
| 1629 | obj->max_media_ports = cfg.max_media_ports; |
| 1630 | obj->no_vad = cfg.no_vad; |
| 1631 | obj->ptime = cfg.ptime; |
| 1632 | obj->quality = cfg.quality; |
| 1633 | obj->rx_drop_pct = cfg.rx_drop_pct; |
| 1634 | obj->thread_cnt = cfg.thread_cnt; |
| 1635 | obj->tx_drop_pct = cfg.tx_drop_pct; |
| 1636 | Py_INCREF(Py_None); |
| 1637 | return Py_None; |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | /* |
| 1642 | * py_pjsua_msg_data_init |
| 1643 | */ |
| 1644 | static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs) |
| 1645 | { |
| 1646 | msg_data_Object *obj; |
| 1647 | pjsua_msg_data msg; |
| 1648 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 1649 | { |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | pjsua_msg_data_init(&msg); |
| 1653 | Py_XDECREF(obj->content_type); |
| 1654 | obj->content_type = PyString_FromStringAndSize( |
| 1655 | msg.content_type.ptr, msg.content_type.slen |
| 1656 | ); |
| 1657 | Py_XDECREF(obj->msg_body); |
| 1658 | obj->msg_body = PyString_FromStringAndSize( |
| 1659 | msg.msg_body.ptr, msg.msg_body.slen |
| 1660 | ); |
| 1661 | obj->hdr_list = msg.hdr_list; |
| 1662 | Py_INCREF(Py_None); |
| 1663 | return Py_None; |
| 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | /* |
| 1668 | * py_pjsua_logging_config_dup |
| 1669 | */ |
| 1670 | static PyObject *py_pjsua_logging_config_dup(PyObject *pSelf, PyObject *pArgs) |
| 1671 | { |
| 1672 | pj_pool_Object *pool; |
| 1673 | logging_config_Object *src; |
| 1674 | logging_config_Object *dest; |
| 1675 | pj_str_t strdest; |
| 1676 | pj_str_t strsrc; |
| 1677 | int len; |
| 1678 | |
| 1679 | if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) |
| 1680 | { |
| 1681 | return NULL; |
| 1682 | } |
| 1683 | pj_memcpy(dest, src, sizeof(*src)); |
| 1684 | len = strlen(PyString_AsString(src->log_filename)); |
| 1685 | strsrc.ptr = PyString_AsString(src->log_filename); |
| 1686 | strsrc.slen = len; |
| 1687 | pj_strdup_with_null(pool->pool, &strdest, &strsrc); |
| 1688 | Py_XDECREF(dest->log_filename); |
| 1689 | dest->log_filename = PyString_FromStringAndSize(strdest.ptr, strdest.slen); |
| 1690 | Py_INCREF(Py_None); |
| 1691 | return Py_None; |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | /* |
| 1696 | * py_pjsua_config_dup |
| 1697 | */ |
| 1698 | static PyObject *py_pjsua_config_dup(PyObject *pSelf, PyObject *pArgs) |
| 1699 | { |
| 1700 | pj_pool_Object *pool; |
| 1701 | config_Object *src; |
| 1702 | config_Object *dest; |
| 1703 | pj_str_t strdest; |
| 1704 | pj_str_t strsrc; |
| 1705 | int len; |
| 1706 | unsigned i; |
| 1707 | |
| 1708 | if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) |
| 1709 | { |
| 1710 | return NULL; |
| 1711 | } |
| 1712 | pj_memcpy(dest, src, sizeof(*src)); |
| 1713 | |
| 1714 | for (i=0; i<src->outbound_proxy_cnt; ++i) |
| 1715 | { |
| 1716 | pj_strdup_with_null( |
| 1717 | pool->pool, &dest->outbound_proxy[i], &src->outbound_proxy[i] |
| 1718 | ); |
| 1719 | } |
| 1720 | |
| 1721 | for (i=0; i<src->cred_count; ++i) |
| 1722 | { |
| 1723 | pjsip_cred_dup(pool->pool, &dest->cred_info[i], &src->cred_info[i]); |
| 1724 | } |
| 1725 | len = strlen(PyString_AsString(src->user_agent)); |
| 1726 | strsrc.ptr = PyString_AsString(src->user_agent); |
| 1727 | strsrc.slen = len; |
| 1728 | pj_strdup_with_null(pool->pool, &strdest, &strsrc); |
| 1729 | Py_XDECREF(dest->user_agent); |
| 1730 | dest->user_agent = PyString_FromStringAndSize(strdest.ptr, strdest.slen); |
| 1731 | Py_INCREF(Py_None); |
| 1732 | return Py_None; |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | /* |
| 1737 | * py_pjsip_cred_dup |
| 1738 | */ |
| 1739 | static PyObject *py_pjsip_cred_dup(PyObject *pSelf, PyObject *pArgs) |
| 1740 | { |
| 1741 | pj_pool_Object *pool; |
| 1742 | pjsip_cred_info_Object *src; |
| 1743 | pjsip_cred_info_Object *dest; |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1744 | pjsip_cred_info s; |
| 1745 | pjsip_cred_info d; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1746 | if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) |
| 1747 | { |
| 1748 | return NULL; |
| 1749 | } |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1750 | s.data.ptr = PyString_AsString(src->data); |
| 1751 | s.data.slen = strlen(PyString_AsString(src->data)); |
| 1752 | s.realm.ptr = PyString_AsString(src->realm); |
| 1753 | s.realm.slen = strlen(PyString_AsString(src->realm)); |
| 1754 | s.scheme.ptr = PyString_AsString(src->scheme); |
| 1755 | s.scheme.slen = strlen(PyString_AsString(src->scheme)); |
| 1756 | s.username.ptr = PyString_AsString(src->username); |
| 1757 | s.username.slen = strlen(PyString_AsString(src->username)); |
| 1758 | s.data_type = src->data_type; |
| 1759 | d.data.ptr = PyString_AsString(dest->data); |
| 1760 | d.data.slen = strlen(PyString_AsString(dest->data)); |
| 1761 | d.realm.ptr = PyString_AsString(dest->realm); |
| 1762 | d.realm.slen = strlen(PyString_AsString(dest->realm)); |
| 1763 | d.scheme.ptr = PyString_AsString(dest->scheme); |
| 1764 | d.scheme.slen = strlen(PyString_AsString(dest->scheme)); |
| 1765 | d.username.ptr = PyString_AsString(dest->username); |
| 1766 | d.username.slen = strlen(PyString_AsString(dest->username)); |
| 1767 | d.data_type = dest->data_type; |
| 1768 | pjsip_cred_dup(pool->pool, &d, &s); |
| 1769 | Py_XDECREF(src->data); |
| 1770 | src->data = PyString_FromStringAndSize(s.data.ptr, s.data.slen); |
| 1771 | Py_XDECREF(src->realm); |
| 1772 | src->realm = PyString_FromStringAndSize(s.realm.ptr, s.realm.slen); |
| 1773 | Py_XDECREF(src->scheme); |
| 1774 | src->scheme = PyString_FromStringAndSize(s.scheme.ptr, s.scheme.slen); |
| 1775 | Py_XDECREF(src->username); |
| 1776 | src->username = |
| 1777 | PyString_FromStringAndSize(s.username.ptr, s.username.slen); |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1778 | Py_INCREF(Py_None); |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 1779 | src->data_type = s.data_type; |
| 1780 | Py_XDECREF(dest->data); |
| 1781 | dest->data = PyString_FromStringAndSize(d.data.ptr, d.data.slen); |
| 1782 | Py_XDECREF(dest->realm); |
| 1783 | dest->realm = PyString_FromStringAndSize(d.realm.ptr, d.realm.slen); |
| 1784 | Py_XDECREF(dest->scheme); |
| 1785 | dest->scheme = PyString_FromStringAndSize(d.scheme.ptr, d.scheme.slen); |
| 1786 | Py_XDECREF(dest->username); |
| 1787 | dest->username = |
| 1788 | PyString_FromStringAndSize(d.username.ptr, d.username.slen); |
| 1789 | Py_INCREF(Py_None); |
| 1790 | src->data_type = s.data_type; |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 1791 | return Py_None; |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | /* |
| 1796 | * py_pjsua_reconfigure_logging |
| 1797 | */ |
| 1798 | static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs) |
| 1799 | { |
| 1800 | logging_config_Object *log; |
| 1801 | pjsua_logging_config cfg; |
| 1802 | pj_status_t status; |
| 1803 | |
| 1804 | if (!PyArg_ParseTuple(pArgs, "O", &log)) |
| 1805 | { |
| 1806 | return NULL; |
| 1807 | } |
| 1808 | cfg.msg_logging = log->msg_logging; |
| 1809 | cfg.level = log->level; |
| 1810 | cfg.console_level = log->console_level; |
| 1811 | cfg.decor = log->decor; |
| 1812 | cfg.log_filename.ptr = PyString_AsString(log->log_filename); |
| 1813 | cfg.log_filename.slen = strlen(cfg.log_filename.ptr); |
| 1814 | Py_XDECREF(obj_reconfigure_logging); |
| 1815 | obj_reconfigure_logging = log->cb; |
| 1816 | Py_INCREF(obj_reconfigure_logging); |
| 1817 | cfg.cb = &cb_reconfigure_logging; |
| 1818 | status = pjsua_reconfigure_logging(&cfg); |
| 1819 | return Py_BuildValue("i",status); |
| 1820 | } |
| 1821 | |
| 1822 | |
| 1823 | /* |
| 1824 | * py_pjsua_pool_create |
| 1825 | */ |
| 1826 | static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs) |
| 1827 | { |
| 1828 | pj_size_t init_size; |
| 1829 | pj_size_t increment; |
| 1830 | const char * name; |
| 1831 | pj_pool_t *p; |
| 1832 | pj_pool_Object *pool; |
| 1833 | |
| 1834 | if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment)) |
| 1835 | { |
| 1836 | return NULL; |
| 1837 | } |
| 1838 | /*printf("name : %s\n",name); |
| 1839 | printf("init : %d\n", init_size); |
| 1840 | printf("increment : %d\n", increment);*/ |
| 1841 | p = pjsua_pool_create(name, init_size, increment); |
| 1842 | pool = (pj_pool_Object *)PyType_GenericNew(&pj_pool_Type, NULL, NULL); |
| 1843 | pool->pool = p; |
| 1844 | return (PyObject *)pool; |
| 1845 | |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | /* |
| 1850 | * py_pjsua_get_pjsip_endpt |
| 1851 | */ |
| 1852 | static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs) |
| 1853 | { |
| 1854 | pjsip_endpoint_Object *endpt; |
| 1855 | pjsip_endpoint *e; |
| 1856 | |
| 1857 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1858 | { |
| 1859 | return NULL; |
| 1860 | } |
| 1861 | e = pjsua_get_pjsip_endpt(); |
| 1862 | endpt = (pjsip_endpoint_Object *)PyType_GenericNew( |
| 1863 | &pjsip_endpoint_Type, NULL, NULL |
| 1864 | ); |
| 1865 | endpt->endpt = e; |
| 1866 | return (PyObject *)endpt; |
| 1867 | } |
| 1868 | |
| 1869 | |
| 1870 | /* |
| 1871 | * py_pjsua_get_pjmedia_endpt |
| 1872 | */ |
| 1873 | static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs) |
| 1874 | { |
| 1875 | pjmedia_endpt_Object *endpt; |
| 1876 | pjmedia_endpt *e; |
| 1877 | |
| 1878 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1879 | { |
| 1880 | return NULL; |
| 1881 | } |
| 1882 | e = pjsua_get_pjmedia_endpt(); |
| 1883 | endpt = (pjmedia_endpt_Object *)PyType_GenericNew( |
| 1884 | &pjmedia_endpt_Type, NULL, NULL |
| 1885 | ); |
| 1886 | endpt->endpt = e; |
| 1887 | return (PyObject *)endpt; |
| 1888 | } |
| 1889 | |
| 1890 | |
| 1891 | /* |
| 1892 | * py_pjsua_get_pool_factory |
| 1893 | */ |
| 1894 | static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs) |
| 1895 | { |
| 1896 | pj_pool_factory_Object *pool; |
| 1897 | pj_pool_factory *p; |
| 1898 | |
| 1899 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1900 | { |
| 1901 | return NULL; |
| 1902 | } |
| 1903 | p = pjsua_get_pool_factory(); |
| 1904 | pool = (pj_pool_factory_Object *)PyType_GenericNew( |
| 1905 | &pj_pool_factory_Type, NULL, NULL |
| 1906 | ); |
| 1907 | pool->pool_fact = p; |
| 1908 | return (PyObject *)pool; |
| 1909 | } |
| 1910 | |
| 1911 | |
| 1912 | /* |
| 1913 | * py_pjsua_perror |
| 1914 | */ |
| 1915 | static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs) |
| 1916 | { |
| 1917 | const char *sender; |
| 1918 | const char *title; |
| 1919 | pj_status_t status; |
| 1920 | if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) |
| 1921 | { |
| 1922 | return NULL; |
| 1923 | } |
| 1924 | pjsua_perror(sender, title, status); |
| 1925 | Py_INCREF(Py_None); |
| 1926 | return Py_None; |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | /* |
| 1931 | * py_pjsua_create |
| 1932 | */ |
| 1933 | static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs) |
| 1934 | { |
| 1935 | pj_status_t status; |
| 1936 | if (!PyArg_ParseTuple(pArgs, "")) |
| 1937 | { |
| 1938 | return NULL; |
| 1939 | } |
| 1940 | status = pjsua_create(); |
| 1941 | printf("status %d\n",status); |
| 1942 | return Py_BuildValue("i",status); |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | /* |
| 1947 | * py_pjsua_init |
| 1948 | */ |
| 1949 | static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs) |
| 1950 | { |
| 1951 | pj_status_t status; |
| 1952 | config_Object * ua_cfg; |
| 1953 | logging_config_Object * log_cfg; |
| 1954 | media_config_Object * media_cfg; |
| 1955 | pjsua_config cfg_ua; |
| 1956 | pjsua_logging_config cfg_log; |
| 1957 | pjsua_media_config cfg_media; |
| 1958 | unsigned i; |
| 1959 | |
| 1960 | if (!PyArg_ParseTuple(pArgs, "OOO", &ua_cfg, &log_cfg, &media_cfg)) |
| 1961 | { |
| 1962 | return NULL; |
| 1963 | } |
| 1964 | |
| 1965 | pjsua_config_default(&cfg_ua); |
| 1966 | pjsua_logging_config_default(&cfg_log); |
| 1967 | pjsua_media_config_default(&cfg_media); |
| 1968 | cfg_ua.cred_count = ua_cfg->cred_count; |
| 1969 | for (i = 0; i < 4; i++) |
| 1970 | { |
| 1971 | cfg_ua.cred_info[i] = ua_cfg->cred_info[i]; |
| 1972 | } |
| 1973 | cfg_ua.max_calls = ua_cfg->max_calls; |
| 1974 | for (i = 0; i < PJSUA_ACC_MAX_PROXIES; i++) |
| 1975 | { |
| 1976 | cfg_ua.outbound_proxy[i] = ua_cfg->outbound_proxy[i]; |
| 1977 | } |
| 1978 | |
| 1979 | cfg_ua.outbound_proxy_cnt = ua_cfg->outbound_proxy_cnt; |
| 1980 | cfg_ua.thread_cnt = ua_cfg->thread_cnt; |
| 1981 | cfg_ua.user_agent.ptr = PyString_AsString(ua_cfg->user_agent); |
| 1982 | cfg_ua.user_agent.slen = strlen(cfg_ua.user_agent.ptr); |
| 1983 | |
| 1984 | obj_callback = ua_cfg->cb; |
| 1985 | cfg_ua.cb.on_call_state = &cb_on_call_state; |
| 1986 | cfg_ua.cb.on_incoming_call = &cb_on_incoming_call; |
| 1987 | cfg_ua.cb.on_call_media_state = &cb_on_call_media_state; |
| 1988 | cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request; |
| 1989 | cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status; |
| 1990 | cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request; |
| 1991 | cfg_ua.cb.on_call_replaced = &cb_on_call_replaced; |
| 1992 | cfg_ua.cb.on_reg_state = &cb_on_reg_state; |
| 1993 | cfg_ua.cb.on_buddy_state = &cb_on_buddy_state; |
| 1994 | cfg_ua.cb.on_pager = &cb_on_pager; |
| 1995 | cfg_ua.cb.on_pager_status = &cb_on_pager_status; |
| 1996 | cfg_ua.cb.on_typing = &cb_on_typing; |
| 1997 | |
| 1998 | cfg_log.msg_logging = log_cfg->msg_logging; |
| 1999 | cfg_log.level = log_cfg->level; |
| 2000 | cfg_log.console_level = log_cfg->console_level; |
| 2001 | cfg_log.decor = log_cfg->decor; |
| 2002 | cfg_log.log_filename.ptr = PyString_AsString(log_cfg->log_filename); |
| 2003 | cfg_log.log_filename.slen = strlen(cfg_log.log_filename.ptr); |
| 2004 | Py_XDECREF(obj_logging_init); |
| 2005 | obj_logging_init = log_cfg->cb; |
| 2006 | Py_INCREF(obj_logging_init); |
| 2007 | cfg_log.cb = &cb_logging_init; |
| 2008 | |
| 2009 | |
| 2010 | cfg_media.clock_rate = media_cfg->clock_rate; |
| 2011 | cfg_media.ec_options = media_cfg->ec_options; |
| 2012 | cfg_media.ec_tail_len = media_cfg->ec_tail_len; |
| 2013 | cfg_media.has_ioqueue = media_cfg->has_ioqueue; |
| 2014 | cfg_media.ilbc_mode = media_cfg->ilbc_mode; |
| 2015 | cfg_media.max_media_ports = media_cfg->max_media_ports; |
| 2016 | cfg_media.no_vad = media_cfg->no_vad; |
| 2017 | cfg_media.ptime = media_cfg->ptime; |
| 2018 | cfg_media.quality = media_cfg->quality; |
| 2019 | cfg_media.rx_drop_pct = media_cfg->rx_drop_pct; |
| 2020 | cfg_media.thread_cnt = media_cfg->thread_cnt; |
| 2021 | cfg_media.tx_drop_pct = media_cfg->tx_drop_pct; |
| 2022 | |
| 2023 | status = pjsua_init(&cfg_ua, &cfg_log, &cfg_media); |
| 2024 | return Py_BuildValue("i",status); |
| 2025 | } |
| 2026 | |
| 2027 | |
| 2028 | /* |
| 2029 | * py_pjsua_start |
| 2030 | */ |
| 2031 | static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs) |
| 2032 | { |
| 2033 | pj_status_t status; |
| 2034 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2035 | { |
| 2036 | return NULL; |
| 2037 | } |
| 2038 | status = pjsua_start(); |
| 2039 | printf("status %d\n",status); |
| 2040 | return Py_BuildValue("i",status); |
| 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | /* |
| 2045 | * py_pjsua_destroy |
| 2046 | */ |
| 2047 | static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs) |
| 2048 | { |
| 2049 | pj_status_t status; |
| 2050 | if (!PyArg_ParseTuple(pArgs, "")) |
| 2051 | { |
| 2052 | return NULL; |
| 2053 | } |
| 2054 | status = pjsua_destroy(); |
| 2055 | printf("status %d\n",status); |
| 2056 | return Py_BuildValue("i",status); |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | /* |
| 2061 | * py_pjsua_handle_events |
| 2062 | */ |
| 2063 | static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs) |
| 2064 | { |
| 2065 | int ret; |
| 2066 | unsigned msec; |
| 2067 | if (!PyArg_ParseTuple(pArgs, "i", &msec)) |
| 2068 | { |
| 2069 | return NULL; |
| 2070 | } |
| 2071 | ret = pjsua_handle_events(msec); |
| 2072 | printf("return %d\n",ret); |
| 2073 | return Py_BuildValue("i",ret); |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | /* |
| 2078 | * py_pjsua_verify_sip_url |
| 2079 | */ |
| 2080 | static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs) |
| 2081 | { |
| 2082 | pj_status_t status; |
| 2083 | const char *url; |
| 2084 | if (!PyArg_ParseTuple(pArgs, "s", &url)) |
| 2085 | { |
| 2086 | return NULL; |
| 2087 | } |
| 2088 | status = pjsua_verify_sip_url(url); |
| 2089 | printf("status %d\n",status); |
| 2090 | return Py_BuildValue("i",status); |
| 2091 | } |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | /* |
| 2099 | * error messages |
| 2100 | */ |
| 2101 | |
| 2102 | static char pjsua_perror_doc[] = |
| 2103 | "void py_pjsua.perror (string sender, string title, int status) " |
| 2104 | "Display error message for the specified error code. Parameters: " |
| 2105 | "sender: The log sender field; " |
| 2106 | "title: Message title for the error; " |
| 2107 | "status: Status code."; |
| 2108 | |
| 2109 | static char pjsua_create_doc[] = |
| 2110 | "int py_pjsua.create (void) " |
| 2111 | "Instantiate pjsua application. Application " |
| 2112 | "must call this function before calling any other functions, to make sure " |
| 2113 | "that the underlying libraries are properly initialized. Once this " |
| 2114 | "function has returned success, application must call pjsua_destroy() " |
| 2115 | "before quitting."; |
| 2116 | |
| 2117 | static char pjsua_init_doc[] = |
| 2118 | "int py_pjsua.init (py_pjsua.Config ua_cfg, " |
| 2119 | "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) " |
| 2120 | "Initialize pjsua with the specified settings. All the settings are " |
| 2121 | "optional, and the default values will be used when the config is not " |
| 2122 | "specified. Parameters: " |
| 2123 | "ua_cfg : User agent configuration; " |
| 2124 | "log_cfg : Optional logging configuration; " |
| 2125 | "media_cfg : Optional media configuration."; |
| 2126 | |
| 2127 | static char pjsua_start_doc[] = |
| 2128 | "int py_pjsua.start (void) " |
| 2129 | "Application is recommended to call this function after all " |
| 2130 | "initialization is done, so that the library can do additional checking " |
| 2131 | "set up additional"; |
| 2132 | |
| 2133 | static char pjsua_destroy_doc[] = |
| 2134 | "int py_pjsua.destroy (void) " |
| 2135 | "Destroy pjsua This function must be called once PJSUA is created. To " |
| 2136 | "make it easier for application, application may call this function " |
| 2137 | "several times with no danger."; |
| 2138 | |
| 2139 | static char pjsua_handle_events_doc[] = |
| 2140 | "int py_pjsua.handle_events (int msec_timeout) " |
| 2141 | "Poll pjsua for events, and if necessary block the caller thread for the " |
| 2142 | "specified maximum interval (in miliseconds) Parameters: " |
| 2143 | "msec_timeout: Maximum time to wait, in miliseconds. " |
| 2144 | "Returns: The number of events that have been handled during the poll. " |
| 2145 | "Negative value indicates error, and application can retrieve the error " |
| 2146 | "as (err = -return_value)."; |
| 2147 | |
| 2148 | static char pjsua_verify_sip_url_doc[] = |
| 2149 | "int py_pjsua.verify_sip_url (string c_url) " |
| 2150 | "Verify that valid SIP url is given Parameters: " |
| 2151 | "c_url: The URL, as NULL terminated string."; |
| 2152 | |
| 2153 | static char pjsua_pool_create_doc[] = |
| 2154 | "py_pjsua.PJ_Pool py_pjsua.pool_create (string name, int init_size, " |
| 2155 | "int increment) " |
| 2156 | "Create memory pool Parameters: " |
| 2157 | "name: Optional pool name; " |
| 2158 | "init_size: Initial size of the pool; " |
| 2159 | "increment: Increment size."; |
| 2160 | |
| 2161 | static char pjsua_get_pjsip_endpt_doc[] = |
| 2162 | "py_pjsua.PJSIP_Endpoint py_pjsua.get_pjsip_endpt (void) " |
| 2163 | "Internal function to get SIP endpoint instance of pjsua, which is needed " |
| 2164 | "for example to register module, create transports, etc. Probably is only " |
| 2165 | "valid after pjsua_init() is called."; |
| 2166 | |
| 2167 | static char pjsua_get_pjmedia_endpt_doc[] = |
| 2168 | "py_pjsua.PJMedia_Endpt py_pjsua.get_pjmedia_endpt (void) " |
| 2169 | "Internal function to get media endpoint instance. Only valid after " |
| 2170 | "pjsua_init() is called."; |
| 2171 | |
| 2172 | static char pjsua_get_pool_factory_doc[] = |
| 2173 | "py_pjsua.PJ_Pool_Factory py_pjsua.get_pool_factory (void) " |
| 2174 | "Internal function to get PJSUA pool factory. Only valid after " |
| 2175 | "pjsua_init() is called."; |
| 2176 | |
| 2177 | static char pjsua_reconfigure_logging_doc[] = |
| 2178 | "int py_pjsua.reconfigure_logging (py_pjsua.Logging_Config c) " |
| 2179 | "Application can call this function at any time (after pjsua_create(), of " |
| 2180 | "course) to change logging settings. Parameters: " |
| 2181 | "c: Logging configuration."; |
| 2182 | |
| 2183 | static char pjsua_logging_config_default_doc[] = |
| 2184 | "void py_pjsua.logging_config_default (py_pjsua.Logging_Config cfg) " |
| 2185 | "Use this function to initialize logging config."; |
| 2186 | |
| 2187 | static char pjsua_config_default_doc[] = |
| 2188 | "void py_pjsua.config_default (py_pjsua.Config cfg). Use this function to " |
| 2189 | "initialize pjsua config. Parameters: " |
| 2190 | "cfg: pjsua config to be initialized."; |
| 2191 | |
| 2192 | static char pjsua_media_config_default_doc[] = |
| 2193 | "Use this function to initialize media config."; |
| 2194 | |
| 2195 | static char pjsua_logging_config_dup_doc[] = |
| 2196 | "void py_pjsua.logging_config_dup (py_pjsua.PJ_Pool pool, " |
| 2197 | "py_pjsua.Logging_Config dst, py_pjsua.Logging_Config src) " |
| 2198 | "Use this function to duplicate logging config. Parameters: " |
| 2199 | "pool: Pool to use; " |
| 2200 | "dst: Destination config; " |
| 2201 | "src: Source config."; |
| 2202 | |
| 2203 | static char pjsua_config_dup_doc[] = |
| 2204 | "void py_pjsua.config_dup (py_pjsua.PJ_Pool pool, py_pjsua.Config dst, " |
| 2205 | "py_pjsua.Config src) " |
| 2206 | "Duplicate pjsua_config. "; |
| 2207 | |
| 2208 | static char pjsip_cred_dup_doc[] = |
| 2209 | "void py_pjsua.pjsip_cred_dup (py_pjsua.PJ_Pool pool, " |
| 2210 | "py_pjsua.PJSIP_Cred_Info dst, " |
| 2211 | "py_pjsua.PJSIP_Cred_Info src) " |
| 2212 | "Duplicate credential."; |
| 2213 | |
| 2214 | static char pjsua_msg_data_init_doc[] = |
| 2215 | "void py_pjsua.msg_data_init (py_pjsua.Msg_Data msg_data) " |
| 2216 | "Initialize message data Parameters: " |
| 2217 | "msg_data: Message data to be initialized."; |
| 2218 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 2219 | /* END OF LIB BASE */ |
| 2220 | |
| 2221 | /* LIB TRANSPORT */ |
| 2222 | |
| 2223 | /* |
| 2224 | * stun_config_Object |
| 2225 | * STUN configuration |
| 2226 | */ |
| 2227 | typedef struct |
| 2228 | { |
| 2229 | PyObject_HEAD |
| 2230 | /* Type-specific fields go here. */ |
| 2231 | PyObject * stun_srv1; |
| 2232 | unsigned stun_port1; |
| 2233 | PyObject * stun_srv2; |
| 2234 | unsigned stun_port2; |
| 2235 | } stun_config_Object; |
| 2236 | |
| 2237 | |
| 2238 | /* |
| 2239 | * stun_config_dealloc |
| 2240 | * deletes a stun config from memory |
| 2241 | */ |
| 2242 | static void stun_config_dealloc(stun_config_Object* self) |
| 2243 | { |
| 2244 | Py_XDECREF(self->stun_srv1); |
| 2245 | Py_XDECREF(self->stun_srv2); |
| 2246 | self->ob_type->tp_free((PyObject*)self); |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | /* |
| 2251 | * stun_config_new |
| 2252 | * constructor for stun_config object |
| 2253 | */ |
| 2254 | static PyObject * stun_config_new(PyTypeObject *type, PyObject *args, |
| 2255 | PyObject *kwds) |
| 2256 | { |
| 2257 | stun_config_Object *self; |
| 2258 | self = (stun_config_Object *)type->tp_alloc(type, 0); |
| 2259 | if (self != NULL) |
| 2260 | { |
| 2261 | self->stun_srv1 = PyString_FromString(""); |
| 2262 | if (self->stun_srv1 == NULL) |
| 2263 | { |
| 2264 | Py_DECREF(self); |
| 2265 | return NULL; |
| 2266 | } |
| 2267 | self->stun_srv2 = PyString_FromString(""); |
| 2268 | if (self->stun_srv2 == NULL) |
| 2269 | { |
| 2270 | Py_DECREF(self); |
| 2271 | return NULL; |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | return (PyObject *)self; |
| 2276 | } |
| 2277 | |
| 2278 | |
| 2279 | /* |
| 2280 | * stun_config_members |
| 2281 | */ |
| 2282 | static PyMemberDef stun_config_members[] = |
| 2283 | { |
| 2284 | { |
| 2285 | "stun_port1", T_INT, offsetof(stun_config_Object, stun_port1), 0, |
| 2286 | "The first STUN server IP address or hostname." |
| 2287 | }, |
| 2288 | { |
| 2289 | "stun_port2", T_INT, offsetof(stun_config_Object, stun_port2), 0, |
| 2290 | "Port number of the second STUN server. " |
| 2291 | "If zero, default STUN port will be used." |
| 2292 | }, |
| 2293 | { |
| 2294 | "stun_srv1", T_OBJECT_EX, |
| 2295 | offsetof(stun_config_Object, stun_srv1), 0, |
| 2296 | "The first STUN server IP address or hostname" |
| 2297 | }, |
| 2298 | { |
| 2299 | "stun_srv2", T_OBJECT_EX, |
| 2300 | offsetof(stun_config_Object, stun_srv2), 0, |
| 2301 | "Optional second STUN server IP address or hostname, for which the " |
| 2302 | "result of the mapping request will be compared to. If the value " |
| 2303 | "is empty, only one STUN server will be used" |
| 2304 | }, |
| 2305 | {NULL} /* Sentinel */ |
| 2306 | }; |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | /* |
| 2312 | * stun_config_Type |
| 2313 | */ |
| 2314 | static PyTypeObject stun_config_Type = |
| 2315 | { |
| 2316 | PyObject_HEAD_INIT(NULL) |
| 2317 | 0, /*ob_size*/ |
| 2318 | "py_pjsua.STUN_Config", /*tp_name*/ |
| 2319 | sizeof(stun_config_Object), /*tp_basicsize*/ |
| 2320 | 0, /*tp_itemsize*/ |
| 2321 | (destructor)stun_config_dealloc,/*tp_dealloc*/ |
| 2322 | 0, /*tp_print*/ |
| 2323 | 0, /*tp_getattr*/ |
| 2324 | 0, /*tp_setattr*/ |
| 2325 | 0, /*tp_compare*/ |
| 2326 | 0, /*tp_repr*/ |
| 2327 | 0, /*tp_as_number*/ |
| 2328 | 0, /*tp_as_sequence*/ |
| 2329 | 0, /*tp_as_mapping*/ |
| 2330 | 0, /*tp_hash */ |
| 2331 | 0, /*tp_call*/ |
| 2332 | 0, /*tp_str*/ |
| 2333 | 0, /*tp_getattro*/ |
| 2334 | 0, /*tp_setattro*/ |
| 2335 | 0, /*tp_as_buffer*/ |
| 2336 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2337 | "STUN Config objects", /* tp_doc */ |
| 2338 | 0, /* tp_traverse */ |
| 2339 | 0, /* tp_clear */ |
| 2340 | 0, /* tp_richcompare */ |
| 2341 | 0, /* tp_weaklistoffset */ |
| 2342 | 0, /* tp_iter */ |
| 2343 | 0, /* tp_iternext */ |
| 2344 | 0, /* tp_methods */ |
| 2345 | stun_config_members, /* tp_members */ |
| 2346 | 0, /* tp_getset */ |
| 2347 | 0, /* tp_base */ |
| 2348 | 0, /* tp_dict */ |
| 2349 | 0, /* tp_descr_get */ |
| 2350 | 0, /* tp_descr_set */ |
| 2351 | 0, /* tp_dictoffset */ |
| 2352 | 0, /* tp_init */ |
| 2353 | 0, /* tp_alloc */ |
| 2354 | stun_config_new, /* tp_new */ |
| 2355 | |
| 2356 | }; |
| 2357 | |
| 2358 | /* |
| 2359 | * transport_config_Object |
| 2360 | * Transport configuration for creating UDP transports for both SIP |
| 2361 | * and media. |
| 2362 | */ |
| 2363 | typedef struct |
| 2364 | { |
| 2365 | PyObject_HEAD |
| 2366 | /* Type-specific fields go here. */ |
| 2367 | unsigned port; |
| 2368 | PyObject * public_addr; |
| 2369 | PyObject * bound_addr; |
| 2370 | int use_stun; |
| 2371 | stun_config_Object * stun_config; |
| 2372 | } transport_config_Object; |
| 2373 | |
| 2374 | |
| 2375 | /* |
| 2376 | * transport_config_dealloc |
| 2377 | * deletes a transport config from memory |
| 2378 | */ |
| 2379 | static void transport_config_dealloc(transport_config_Object* self) |
| 2380 | { |
| 2381 | Py_XDECREF(self->public_addr); |
| 2382 | Py_XDECREF(self->bound_addr); |
| 2383 | Py_XDECREF(self->stun_config); |
| 2384 | self->ob_type->tp_free((PyObject*)self); |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | /* |
| 2389 | * transport_config_new |
| 2390 | * constructor for transport_config object |
| 2391 | */ |
| 2392 | static PyObject * transport_config_new(PyTypeObject *type, PyObject *args, |
| 2393 | PyObject *kwds) |
| 2394 | { |
| 2395 | transport_config_Object *self; |
| 2396 | |
| 2397 | self = (transport_config_Object *)type->tp_alloc(type, 0); |
| 2398 | if (self != NULL) |
| 2399 | { |
| 2400 | self->public_addr = PyString_FromString(""); |
| 2401 | if (self->public_addr == NULL) |
| 2402 | { |
| 2403 | Py_DECREF(self); |
| 2404 | return NULL; |
| 2405 | } |
| 2406 | self->bound_addr = PyString_FromString(""); |
| 2407 | if (self->bound_addr == NULL) |
| 2408 | { |
| 2409 | Py_DECREF(self); |
| 2410 | return NULL; |
| 2411 | } |
| 2412 | self->stun_config = |
| 2413 | (stun_config_Object *)stun_config_new(&stun_config_Type,NULL,NULL); |
| 2414 | if (self->stun_config == NULL) |
| 2415 | { |
| 2416 | Py_DECREF(self); |
| 2417 | return NULL; |
| 2418 | } |
| 2419 | |
| 2420 | } |
| 2421 | |
| 2422 | return (PyObject *)self; |
| 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | /* |
| 2427 | * transport_config_members |
| 2428 | */ |
| 2429 | static PyMemberDef transport_config_members[] = |
| 2430 | { |
| 2431 | { |
| 2432 | "port", T_INT, offsetof(transport_config_Object, port), 0, |
| 2433 | "UDP port number to bind locally. This setting MUST be specified " |
| 2434 | "even when default port is desired. If the value is zero, the " |
| 2435 | "transport will be bound to any available port, and application " |
| 2436 | "can query the port by querying the transport info." |
| 2437 | }, |
| 2438 | { |
| 2439 | "public_addr", T_OBJECT_EX, |
| 2440 | offsetof(transport_config_Object, public_addr), 0, |
| 2441 | "Optional address to advertise as the address of this transport. " |
| 2442 | "Application can specify any address or hostname for this field, " |
| 2443 | "for example it can point to one of the interface address in the " |
| 2444 | "system, or it can point to the public address of a NAT router " |
| 2445 | "where port mappings have been configured for the application." |
| 2446 | }, |
| 2447 | { |
| 2448 | "bound_addr", T_OBJECT_EX, |
| 2449 | offsetof(transport_config_Object, bound_addr), 0, |
| 2450 | "Optional address where the socket should be bound to. This option " |
| 2451 | "SHOULD only be used to selectively bind the socket to particular " |
| 2452 | "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the " |
| 2453 | "published address of a transport (the public_addr field should be " |
| 2454 | "used for that purpose)." |
| 2455 | }, |
| 2456 | { |
| 2457 | "use_stun", T_INT, |
| 2458 | offsetof(transport_config_Object, use_stun), 0, |
| 2459 | "Flag to indicate whether STUN should be used." |
| 2460 | }, |
| 2461 | { |
| 2462 | "stun_config", T_OBJECT_EX, |
| 2463 | offsetof(transport_config_Object, stun_config), 0, |
| 2464 | "STUN configuration, must be specified when STUN is used." |
| 2465 | }, |
| 2466 | {NULL} /* Sentinel */ |
| 2467 | }; |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | /* |
| 2473 | * transport_config_Type |
| 2474 | */ |
| 2475 | static PyTypeObject transport_config_Type = |
| 2476 | { |
| 2477 | PyObject_HEAD_INIT(NULL) |
| 2478 | 0, /*ob_size*/ |
| 2479 | "py_pjsua.Transport_Config", /*tp_name*/ |
| 2480 | sizeof(transport_config_Object), /*tp_basicsize*/ |
| 2481 | 0, /*tp_itemsize*/ |
| 2482 | (destructor)transport_config_dealloc,/*tp_dealloc*/ |
| 2483 | 0, /*tp_print*/ |
| 2484 | 0, /*tp_getattr*/ |
| 2485 | 0, /*tp_setattr*/ |
| 2486 | 0, /*tp_compare*/ |
| 2487 | 0, /*tp_repr*/ |
| 2488 | 0, /*tp_as_number*/ |
| 2489 | 0, /*tp_as_sequence*/ |
| 2490 | 0, /*tp_as_mapping*/ |
| 2491 | 0, /*tp_hash */ |
| 2492 | 0, /*tp_call*/ |
| 2493 | 0, /*tp_str*/ |
| 2494 | 0, /*tp_getattro*/ |
| 2495 | 0, /*tp_setattro*/ |
| 2496 | 0, /*tp_as_buffer*/ |
| 2497 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2498 | "Transport Config objects", /* tp_doc */ |
| 2499 | 0, /* tp_traverse */ |
| 2500 | 0, /* tp_clear */ |
| 2501 | 0, /* tp_richcompare */ |
| 2502 | 0, /* tp_weaklistoffset */ |
| 2503 | 0, /* tp_iter */ |
| 2504 | 0, /* tp_iternext */ |
| 2505 | 0, /* tp_methods */ |
| 2506 | transport_config_members, /* tp_members */ |
| 2507 | 0, /* tp_getset */ |
| 2508 | 0, /* tp_base */ |
| 2509 | 0, /* tp_dict */ |
| 2510 | 0, /* tp_descr_get */ |
| 2511 | 0, /* tp_descr_set */ |
| 2512 | 0, /* tp_dictoffset */ |
| 2513 | 0, /* tp_init */ |
| 2514 | 0, /* tp_alloc */ |
| 2515 | transport_config_new, /* tp_new */ |
| 2516 | |
| 2517 | }; |
| 2518 | |
| 2519 | /* |
| 2520 | * sockaddr_Object |
| 2521 | * C/Python wrapper for sockaddr object |
| 2522 | */ |
| 2523 | typedef struct |
| 2524 | { |
| 2525 | PyObject_HEAD |
| 2526 | /* Type-specific fields go here. */ |
| 2527 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 2528 | pj_uint8_t sa_zero_len; |
| 2529 | pj_uint8_t sa_family; |
| 2530 | #else |
| 2531 | pj_uint16_t sa_family; /**< Common data: address family. */ |
| 2532 | #endif |
| 2533 | PyObject * sa_data; /**< Address data. */ |
| 2534 | } sockaddr_Object; |
| 2535 | |
| 2536 | /* |
| 2537 | * sockaddr_dealloc |
| 2538 | * deletes a sockaddr from memory |
| 2539 | */ |
| 2540 | static void sockaddr_dealloc(sockaddr_Object* self) |
| 2541 | { |
| 2542 | Py_XDECREF(self->sa_data); |
| 2543 | self->ob_type->tp_free((PyObject*)self); |
| 2544 | } |
| 2545 | |
| 2546 | |
| 2547 | /* |
| 2548 | * sockaddr_new |
| 2549 | * constructor for sockaddr object |
| 2550 | */ |
| 2551 | static PyObject * sockaddr_new(PyTypeObject *type, PyObject *args, |
| 2552 | PyObject *kwds) |
| 2553 | { |
| 2554 | sockaddr_Object *self; |
| 2555 | |
| 2556 | self = (sockaddr_Object *)type->tp_alloc(type, 0); |
| 2557 | if (self != NULL) |
| 2558 | { |
| 2559 | self->sa_data = PyString_FromString(""); |
| 2560 | if (self->sa_data == NULL) |
| 2561 | { |
| 2562 | Py_DECREF(self); |
| 2563 | return NULL; |
| 2564 | } |
| 2565 | |
| 2566 | } |
| 2567 | |
| 2568 | return (PyObject *)self; |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | /* |
| 2573 | * sockaddr_members |
| 2574 | * declares attributes accessible from both C and Python for sockaddr object |
| 2575 | */ |
| 2576 | static PyMemberDef sockaddr_members[] = |
| 2577 | { |
| 2578 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 2579 | { |
| 2580 | "sa_zero_len", T_INT, offsetof(sockaddr_Object, sa_zero_len), 0, |
| 2581 | "" |
| 2582 | }, |
| 2583 | { |
| 2584 | "sa_family", T_INT, |
| 2585 | offsetof(sockaddr_Object, sa_family), 0, |
| 2586 | "Common data: address family." |
| 2587 | }, |
| 2588 | #else |
| 2589 | { |
| 2590 | "sa_family", T_INT, |
| 2591 | offsetof(sockaddr_Object, sa_family), 0, |
| 2592 | "Common data: address family." |
| 2593 | }, |
| 2594 | #endif |
| 2595 | { |
| 2596 | "sa_data", T_OBJECT_EX, |
| 2597 | offsetof(sockaddr_Object, sa_data), 0, |
| 2598 | "Address data" |
| 2599 | }, |
| 2600 | {NULL} /* Sentinel */ |
| 2601 | }; |
| 2602 | |
| 2603 | |
| 2604 | /* |
| 2605 | * sockaddr_Type |
| 2606 | */ |
| 2607 | static PyTypeObject sockaddr_Type = |
| 2608 | { |
| 2609 | PyObject_HEAD_INIT(NULL) |
| 2610 | 0, /*ob_size*/ |
| 2611 | "py_pjsua.Sockaddr", /*tp_name*/ |
| 2612 | sizeof(sockaddr_Object), /*tp_basicsize*/ |
| 2613 | 0, /*tp_itemsize*/ |
| 2614 | (destructor)sockaddr_dealloc,/*tp_dealloc*/ |
| 2615 | 0, /*tp_print*/ |
| 2616 | 0, /*tp_getattr*/ |
| 2617 | 0, /*tp_setattr*/ |
| 2618 | 0, /*tp_compare*/ |
| 2619 | 0, /*tp_repr*/ |
| 2620 | 0, /*tp_as_number*/ |
| 2621 | 0, /*tp_as_sequence*/ |
| 2622 | 0, /*tp_as_mapping*/ |
| 2623 | 0, /*tp_hash */ |
| 2624 | 0, /*tp_call*/ |
| 2625 | 0, /*tp_str*/ |
| 2626 | 0, /*tp_getattro*/ |
| 2627 | 0, /*tp_setattro*/ |
| 2628 | 0, /*tp_as_buffer*/ |
| 2629 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2630 | "Sockaddr objects", /*tp_doc*/ |
| 2631 | 0, /*tp_traverse*/ |
| 2632 | 0, /*tp_clear*/ |
| 2633 | 0, /*tp_richcompare*/ |
| 2634 | 0, /* tp_weaklistoffset */ |
| 2635 | 0, /* tp_iter */ |
| 2636 | 0, /* tp_iternext */ |
| 2637 | 0, /* tp_methods */ |
| 2638 | sockaddr_members, /* tp_members */ |
| 2639 | 0, /* tp_getset */ |
| 2640 | 0, /* tp_base */ |
| 2641 | 0, /* tp_dict */ |
| 2642 | 0, /* tp_descr_get */ |
| 2643 | 0, /* tp_descr_set */ |
| 2644 | 0, /* tp_dictoffset */ |
| 2645 | 0, /* tp_init */ |
| 2646 | 0, /* tp_alloc */ |
| 2647 | sockaddr_new, /* tp_new */ |
| 2648 | }; |
| 2649 | |
| 2650 | /* |
| 2651 | * host_port_Object |
| 2652 | * C/Python wrapper for host_port object |
| 2653 | */ |
| 2654 | typedef struct |
| 2655 | { |
| 2656 | PyObject_HEAD |
| 2657 | /* Type-specific fields go here. */ |
| 2658 | PyObject * host; |
| 2659 | int port; |
| 2660 | } host_port_Object; |
| 2661 | |
| 2662 | /* |
| 2663 | * host_port_dealloc |
| 2664 | * deletes a host_port from memory |
| 2665 | */ |
| 2666 | static void host_port_dealloc(host_port_Object* self) |
| 2667 | { |
| 2668 | Py_XDECREF(self->host); |
| 2669 | self->ob_type->tp_free((PyObject*)self); |
| 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | /* |
| 2674 | * host_port_new |
| 2675 | * constructor for host_port object |
| 2676 | */ |
| 2677 | static PyObject * host_port_new(PyTypeObject *type, PyObject *args, |
| 2678 | PyObject *kwds) |
| 2679 | { |
| 2680 | host_port_Object *self; |
| 2681 | |
| 2682 | self = (host_port_Object *)type->tp_alloc(type, 0); |
| 2683 | if (self != NULL) |
| 2684 | { |
| 2685 | self->host = PyString_FromString(""); |
| 2686 | if (self->host == NULL) |
| 2687 | { |
| 2688 | Py_DECREF(self); |
| 2689 | return NULL; |
| 2690 | } |
| 2691 | |
| 2692 | } |
| 2693 | |
| 2694 | return (PyObject *)self; |
| 2695 | } |
| 2696 | |
| 2697 | |
| 2698 | /* |
| 2699 | * host_port_members |
| 2700 | * declares attributes accessible from both C and Python for host_port object |
| 2701 | */ |
| 2702 | static PyMemberDef host_port_members[] = |
| 2703 | { |
| 2704 | { |
| 2705 | "port", T_INT, |
| 2706 | offsetof(host_port_Object, port), 0, |
| 2707 | "Port number." |
| 2708 | }, |
| 2709 | { |
| 2710 | "host", T_OBJECT_EX, |
| 2711 | offsetof(host_port_Object, host), 0, |
| 2712 | "Host part or IP address." |
| 2713 | }, |
| 2714 | {NULL} /* Sentinel */ |
| 2715 | }; |
| 2716 | |
| 2717 | |
| 2718 | /* |
| 2719 | * host_port_Type |
| 2720 | */ |
| 2721 | static PyTypeObject host_port_Type = |
| 2722 | { |
| 2723 | PyObject_HEAD_INIT(NULL) |
| 2724 | 0, /*ob_size*/ |
| 2725 | "py_pjsua.Host_Port", /*tp_name*/ |
| 2726 | sizeof(host_port_Object), /*tp_basicsize*/ |
| 2727 | 0, /*tp_itemsize*/ |
| 2728 | (destructor)host_port_dealloc,/*tp_dealloc*/ |
| 2729 | 0, /*tp_print*/ |
| 2730 | 0, /*tp_getattr*/ |
| 2731 | 0, /*tp_setattr*/ |
| 2732 | 0, /*tp_compare*/ |
| 2733 | 0, /*tp_repr*/ |
| 2734 | 0, /*tp_as_number*/ |
| 2735 | 0, /*tp_as_sequence*/ |
| 2736 | 0, /*tp_as_mapping*/ |
| 2737 | 0, /*tp_hash */ |
| 2738 | 0, /*tp_call*/ |
| 2739 | 0, /*tp_str*/ |
| 2740 | 0, /*tp_getattro*/ |
| 2741 | 0, /*tp_setattro*/ |
| 2742 | 0, /*tp_as_buffer*/ |
| 2743 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2744 | "Host_port objects", /*tp_doc*/ |
| 2745 | 0, /*tp_traverse*/ |
| 2746 | 0, /*tp_clear*/ |
| 2747 | 0, /*tp_richcompare*/ |
| 2748 | 0, /* tp_weaklistoffset */ |
| 2749 | 0, /* tp_iter */ |
| 2750 | 0, /* tp_iternext */ |
| 2751 | 0, /* tp_methods */ |
| 2752 | host_port_members, /* tp_members */ |
| 2753 | 0, /* tp_getset */ |
| 2754 | 0, /* tp_base */ |
| 2755 | 0, /* tp_dict */ |
| 2756 | 0, /* tp_descr_get */ |
| 2757 | 0, /* tp_descr_set */ |
| 2758 | 0, /* tp_dictoffset */ |
| 2759 | 0, /* tp_init */ |
| 2760 | 0, /* tp_alloc */ |
| 2761 | host_port_new, /* tp_new */ |
| 2762 | }; |
| 2763 | |
| 2764 | /* |
| 2765 | * transport_id_Object |
| 2766 | * C/Python wrapper for transport_id object |
| 2767 | */ |
| 2768 | typedef struct |
| 2769 | { |
| 2770 | PyObject_HEAD |
| 2771 | /* Type-specific fields go here. */ |
| 2772 | int transport_id; |
| 2773 | } transport_id_Object; |
| 2774 | |
| 2775 | |
| 2776 | /* |
| 2777 | * transport_id_members |
| 2778 | * declares attributes accessible from |
| 2779 | * both C and Python for transport_id object |
| 2780 | */ |
| 2781 | static PyMemberDef transport_id_members[] = |
| 2782 | { |
| 2783 | { |
| 2784 | "transport_id", T_INT, offsetof(transport_id_Object, transport_id), 0, |
| 2785 | "SIP transport identification" |
| 2786 | }, |
| 2787 | {NULL} /* Sentinel */ |
| 2788 | }; |
| 2789 | |
| 2790 | |
| 2791 | /* |
| 2792 | * transport_id_Type |
| 2793 | */ |
| 2794 | static PyTypeObject transport_id_Type = |
| 2795 | { |
| 2796 | PyObject_HEAD_INIT(NULL) |
| 2797 | 0, /*ob_size*/ |
| 2798 | "py_pjsua.Transport_ID", /*tp_name*/ |
| 2799 | sizeof(transport_id_Object), /*tp_basicsize*/ |
| 2800 | 0, /*tp_itemsize*/ |
| 2801 | 0, /*tp_dealloc*/ |
| 2802 | 0, /*tp_print*/ |
| 2803 | 0, /*tp_getattr*/ |
| 2804 | 0, /*tp_setattr*/ |
| 2805 | 0, /*tp_compare*/ |
| 2806 | 0, /*tp_repr*/ |
| 2807 | 0, /*tp_as_number*/ |
| 2808 | 0, /*tp_as_sequence*/ |
| 2809 | 0, /*tp_as_mapping*/ |
| 2810 | 0, /*tp_hash */ |
| 2811 | 0, /*tp_call*/ |
| 2812 | 0, /*tp_str*/ |
| 2813 | 0, /*tp_getattro*/ |
| 2814 | 0, /*tp_setattro*/ |
| 2815 | 0, /*tp_as_buffer*/ |
| 2816 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2817 | "Transport ID objects", /*tp_doc*/ |
| 2818 | 0, /*tp_traverse*/ |
| 2819 | 0, /*tp_clear*/ |
| 2820 | 0, /*tp_richcompare*/ |
| 2821 | 0, /* tp_weaklistoffset */ |
| 2822 | 0, /* tp_iter */ |
| 2823 | 0, /* tp_iternext */ |
| 2824 | 0, /* tp_methods */ |
| 2825 | transport_id_members, /* tp_members */ |
| 2826 | |
| 2827 | }; |
| 2828 | |
| 2829 | /* |
| 2830 | * integer_Object |
| 2831 | * C/Python wrapper for integer object |
| 2832 | */ |
| 2833 | typedef struct |
| 2834 | { |
| 2835 | PyObject_HEAD |
| 2836 | /* Type-specific fields go here. */ |
| 2837 | int integer; |
| 2838 | } integer_Object; |
| 2839 | |
| 2840 | |
| 2841 | /* |
| 2842 | * integer_members |
| 2843 | * declares attributes accessible from both C and Python for integer object |
| 2844 | */ |
| 2845 | static PyMemberDef integer_members[] = |
| 2846 | { |
| 2847 | { |
| 2848 | "integer", T_INT, offsetof(integer_Object, integer), 0, |
| 2849 | "integer value" |
| 2850 | }, |
| 2851 | {NULL} /* Sentinel */ |
| 2852 | }; |
| 2853 | |
| 2854 | |
| 2855 | /* |
| 2856 | * integer_Type |
| 2857 | */ |
| 2858 | static PyTypeObject integer_Type = |
| 2859 | { |
| 2860 | PyObject_HEAD_INIT(NULL) |
| 2861 | 0, /*ob_size*/ |
| 2862 | "py_pjsua.Integer", /*tp_name*/ |
| 2863 | sizeof(integer_Object), /*tp_basicsize*/ |
| 2864 | 0, /*tp_itemsize*/ |
| 2865 | 0, /*tp_dealloc*/ |
| 2866 | 0, /*tp_print*/ |
| 2867 | 0, /*tp_getattr*/ |
| 2868 | 0, /*tp_setattr*/ |
| 2869 | 0, /*tp_compare*/ |
| 2870 | 0, /*tp_repr*/ |
| 2871 | 0, /*tp_as_number*/ |
| 2872 | 0, /*tp_as_sequence*/ |
| 2873 | 0, /*tp_as_mapping*/ |
| 2874 | 0, /*tp_hash */ |
| 2875 | 0, /*tp_call*/ |
| 2876 | 0, /*tp_str*/ |
| 2877 | 0, /*tp_getattro*/ |
| 2878 | 0, /*tp_setattro*/ |
| 2879 | 0, /*tp_as_buffer*/ |
| 2880 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2881 | "Integer objects", /*tp_doc*/ |
| 2882 | 0, /*tp_traverse*/ |
| 2883 | 0, /*tp_clear*/ |
| 2884 | 0, /*tp_richcompare*/ |
| 2885 | 0, /* tp_weaklistoffset */ |
| 2886 | 0, /* tp_iter */ |
| 2887 | 0, /* tp_iternext */ |
| 2888 | 0, /* tp_methods */ |
| 2889 | integer_members, /* tp_members */ |
| 2890 | |
| 2891 | }; |
| 2892 | |
| 2893 | |
| 2894 | /* |
| 2895 | * transport_info_Object |
| 2896 | * Transport info |
| 2897 | */ |
| 2898 | typedef struct |
| 2899 | { |
| 2900 | PyObject_HEAD |
| 2901 | /* Type-specific fields go here. */ |
| 2902 | int id; |
| 2903 | int type; |
| 2904 | PyObject * type_name; |
| 2905 | PyObject * info; |
| 2906 | unsigned flag; |
| 2907 | unsigned addr_len; |
| 2908 | sockaddr_Object * local_addr; |
| 2909 | host_port_Object * local_name; |
| 2910 | unsigned usage_count; |
| 2911 | } transport_info_Object; |
| 2912 | |
| 2913 | |
| 2914 | /* |
| 2915 | * transport_info_dealloc |
| 2916 | * deletes a transport info from memory |
| 2917 | */ |
| 2918 | static void transport_info_dealloc(transport_info_Object* self) |
| 2919 | { |
| 2920 | Py_XDECREF(self->type_name); |
| 2921 | Py_XDECREF(self->info); |
| 2922 | Py_XDECREF(self->local_addr); |
| 2923 | Py_XDECREF(self->local_name); |
| 2924 | self->ob_type->tp_free((PyObject*)self); |
| 2925 | } |
| 2926 | |
| 2927 | |
| 2928 | /* |
| 2929 | * transport_info_new |
| 2930 | * constructor for transport_info object |
| 2931 | */ |
| 2932 | static PyObject * transport_info_new(PyTypeObject *type, PyObject *args, |
| 2933 | PyObject *kwds) |
| 2934 | { |
| 2935 | transport_info_Object *self; |
| 2936 | |
| 2937 | self = (transport_info_Object *)type->tp_alloc(type, 0); |
| 2938 | if (self != NULL) |
| 2939 | { |
| 2940 | self->type_name = PyString_FromString(""); |
| 2941 | if (self->type_name == NULL) |
| 2942 | { |
| 2943 | Py_DECREF(self); |
| 2944 | return NULL; |
| 2945 | } |
| 2946 | self->info = PyString_FromString(""); |
| 2947 | if (self->info == NULL) |
| 2948 | { |
| 2949 | Py_DECREF(self); |
| 2950 | return NULL; |
| 2951 | } |
| 2952 | self->local_addr = |
| 2953 | (sockaddr_Object *)sockaddr_new(&sockaddr_Type,NULL,NULL); |
| 2954 | if (self->local_addr == NULL) |
| 2955 | { |
| 2956 | Py_DECREF(self); |
| 2957 | return NULL; |
| 2958 | } |
| 2959 | self->local_name = |
| 2960 | (host_port_Object *)host_port_new(&host_port_Type,NULL,NULL); |
| 2961 | if (self->local_name == NULL) |
| 2962 | { |
| 2963 | Py_DECREF(self); |
| 2964 | return NULL; |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | return (PyObject *)self; |
| 2969 | } |
| 2970 | |
| 2971 | |
| 2972 | /* |
| 2973 | * transport_info_members |
| 2974 | */ |
| 2975 | static PyMemberDef transport_info_members[] = |
| 2976 | { |
| 2977 | { |
| 2978 | "id", T_INT, offsetof(transport_info_Object, id), 0, |
| 2979 | "PJSUA transport identification." |
| 2980 | }, |
| 2981 | { |
| 2982 | "type", T_INT, offsetof(transport_info_Object, id), 0, |
| 2983 | "Transport type." |
| 2984 | }, |
| 2985 | { |
| 2986 | "type_name", T_OBJECT_EX, |
| 2987 | offsetof(transport_info_Object, type_name), 0, |
| 2988 | "Transport type name." |
| 2989 | }, |
| 2990 | { |
| 2991 | "info", T_OBJECT_EX, |
| 2992 | offsetof(transport_info_Object, info), 0, |
| 2993 | "Transport string info/description." |
| 2994 | }, |
| 2995 | { |
| 2996 | "flag", T_INT, offsetof(transport_info_Object, flag), 0, |
| 2997 | "Transport flag (see ##pjsip_transport_flags_e)." |
| 2998 | }, |
| 2999 | { |
| 3000 | "addr_len", T_INT, offsetof(transport_info_Object, addr_len), 0, |
| 3001 | "Local address length." |
| 3002 | }, |
| 3003 | { |
| 3004 | "local_addr", T_OBJECT_EX, |
| 3005 | offsetof(transport_info_Object, local_addr), 0, |
| 3006 | "Local/bound address." |
| 3007 | }, |
| 3008 | { |
| 3009 | "local_name", T_OBJECT_EX, |
| 3010 | offsetof(transport_info_Object, local_name), 0, |
| 3011 | "Published address (or transport address name)." |
| 3012 | }, |
| 3013 | { |
| 3014 | "usage_count", T_INT, offsetof(transport_info_Object, usage_count), 0, |
| 3015 | "Current number of objects currently referencing this transport." |
| 3016 | }, |
| 3017 | {NULL} /* Sentinel */ |
| 3018 | }; |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | |
| 3023 | /* |
| 3024 | * transport_info_Type |
| 3025 | */ |
| 3026 | static PyTypeObject transport_info_Type = |
| 3027 | { |
| 3028 | PyObject_HEAD_INIT(NULL) |
| 3029 | 0, /*ob_size*/ |
| 3030 | "py_pjsua.Transport_Info", /*tp_name*/ |
| 3031 | sizeof(transport_info_Object), /*tp_basicsize*/ |
| 3032 | 0, /*tp_itemsize*/ |
| 3033 | (destructor)transport_info_dealloc,/*tp_dealloc*/ |
| 3034 | 0, /*tp_print*/ |
| 3035 | 0, /*tp_getattr*/ |
| 3036 | 0, /*tp_setattr*/ |
| 3037 | 0, /*tp_compare*/ |
| 3038 | 0, /*tp_repr*/ |
| 3039 | 0, /*tp_as_number*/ |
| 3040 | 0, /*tp_as_sequence*/ |
| 3041 | 0, /*tp_as_mapping*/ |
| 3042 | 0, /*tp_hash */ |
| 3043 | 0, /*tp_call*/ |
| 3044 | 0, /*tp_str*/ |
| 3045 | 0, /*tp_getattro*/ |
| 3046 | 0, /*tp_setattro*/ |
| 3047 | 0, /*tp_as_buffer*/ |
| 3048 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3049 | "Transport Info objects", /* tp_doc */ |
| 3050 | 0, /* tp_traverse */ |
| 3051 | 0, /* tp_clear */ |
| 3052 | 0, /* tp_richcompare */ |
| 3053 | 0, /* tp_weaklistoffset */ |
| 3054 | 0, /* tp_iter */ |
| 3055 | 0, /* tp_iternext */ |
| 3056 | 0, /* tp_methods */ |
| 3057 | transport_info_members, /* tp_members */ |
| 3058 | 0, /* tp_getset */ |
| 3059 | 0, /* tp_base */ |
| 3060 | 0, /* tp_dict */ |
| 3061 | 0, /* tp_descr_get */ |
| 3062 | 0, /* tp_descr_set */ |
| 3063 | 0, /* tp_dictoffset */ |
| 3064 | 0, /* tp_init */ |
| 3065 | 0, /* tp_alloc */ |
| 3066 | transport_info_new, /* tp_new */ |
| 3067 | |
| 3068 | }; |
| 3069 | |
| 3070 | /* |
| 3071 | * pjsip_transport_Object |
| 3072 | * C/python typewrapper for pjsip_transport |
| 3073 | */ |
| 3074 | typedef struct |
| 3075 | { |
| 3076 | PyObject_HEAD |
| 3077 | /* Type-specific fields go here. */ |
| 3078 | pjsip_transport *tp; |
| 3079 | } pjsip_transport_Object; |
| 3080 | |
| 3081 | |
| 3082 | /* |
| 3083 | * pjsip_transport_Type |
| 3084 | */ |
| 3085 | static PyTypeObject pjsip_transport_Type = |
| 3086 | { |
| 3087 | PyObject_HEAD_INIT(NULL) |
| 3088 | 0, /*ob_size*/ |
| 3089 | "py_pjsua.PJSIP_Transport", /*tp_name*/ |
| 3090 | sizeof(pjsip_transport_Object), /*tp_basicsize*/ |
| 3091 | 0, /*tp_itemsize*/ |
| 3092 | 0, /*tp_dealloc*/ |
| 3093 | 0, /*tp_print*/ |
| 3094 | 0, /*tp_getattr*/ |
| 3095 | 0, /*tp_setattr*/ |
| 3096 | 0, /*tp_compare*/ |
| 3097 | 0, /*tp_repr*/ |
| 3098 | 0, /*tp_as_number*/ |
| 3099 | 0, /*tp_as_sequence*/ |
| 3100 | 0, /*tp_as_mapping*/ |
| 3101 | 0, /*tp_hash */ |
| 3102 | 0, /*tp_call*/ |
| 3103 | 0, /*tp_str*/ |
| 3104 | 0, /*tp_getattro*/ |
| 3105 | 0, /*tp_setattro*/ |
| 3106 | 0, /*tp_as_buffer*/ |
| 3107 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3108 | "pjsip_transport objects", /*tp_doc*/ |
| 3109 | }; |
| 3110 | |
| 3111 | |
| 3112 | /* |
| 3113 | * py_pjsua_stun_config_default |
| 3114 | */ |
| 3115 | static PyObject *py_pjsua_stun_config_default(PyObject *pSelf, PyObject *pArgs) |
| 3116 | { |
| 3117 | stun_config_Object *obj; |
| 3118 | pjsua_stun_config cfg; |
| 3119 | |
| 3120 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 3121 | { |
| 3122 | return NULL; |
| 3123 | } |
| 3124 | pjsua_stun_config_default(&cfg); |
| 3125 | obj->stun_port1 = cfg.stun_port1; |
| 3126 | obj->stun_port2 = cfg.stun_port2; |
| 3127 | Py_XDECREF(obj->stun_srv1); |
| 3128 | obj->stun_srv1 = |
| 3129 | PyString_FromStringAndSize(cfg.stun_srv1.ptr, cfg.stun_srv1.slen); |
| 3130 | Py_XDECREF(obj->stun_srv2); |
| 3131 | obj->stun_srv2 = |
| 3132 | PyString_FromStringAndSize(cfg.stun_srv2.ptr, cfg.stun_srv2.slen); |
| 3133 | Py_INCREF(Py_None); |
| 3134 | return Py_None; |
| 3135 | } |
| 3136 | |
| 3137 | /* |
| 3138 | * py_pjsua_transport_config_default |
| 3139 | */ |
| 3140 | static PyObject *py_pjsua_transport_config_default |
| 3141 | (PyObject *pSelf, PyObject *pArgs) |
| 3142 | { |
| 3143 | transport_config_Object *obj; |
| 3144 | pjsua_transport_config cfg; |
| 3145 | |
| 3146 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 3147 | { |
| 3148 | return NULL; |
| 3149 | } |
| 3150 | pjsua_transport_config_default(&cfg); |
| 3151 | obj->public_addr = |
| 3152 | PyString_FromStringAndSize(cfg.public_addr.ptr, cfg.public_addr.slen); |
| 3153 | obj->bound_addr = |
| 3154 | PyString_FromStringAndSize(cfg.bound_addr.ptr, cfg.bound_addr.slen); |
| 3155 | obj->port = cfg.port; |
| 3156 | obj->use_stun = cfg.use_stun; |
| 3157 | Py_XDECREF(obj->stun_config); |
| 3158 | obj->stun_config = |
| 3159 | (stun_config_Object *)stun_config_new(&stun_config_Type, NULL, NULL); |
| 3160 | obj->stun_config->stun_port1 = cfg.stun_config.stun_port1; |
| 3161 | obj->stun_config->stun_port2 = cfg.stun_config.stun_port2; |
| 3162 | Py_XDECREF(obj->stun_config->stun_srv1); |
| 3163 | obj->stun_config->stun_srv1 = |
| 3164 | PyString_FromStringAndSize(cfg.stun_config.stun_srv1.ptr, |
| 3165 | cfg.stun_config.stun_srv1.slen); |
| 3166 | Py_XDECREF(obj->stun_config->stun_srv2); |
| 3167 | obj->stun_config->stun_srv2 = |
| 3168 | PyString_FromStringAndSize(cfg.stun_config.stun_srv2.ptr, |
| 3169 | cfg.stun_config.stun_srv2.slen); |
| 3170 | Py_INCREF(Py_None); |
| 3171 | return Py_None; |
| 3172 | } |
| 3173 | |
| 3174 | /* |
| 3175 | * py_pjsua_normalize_stun_config |
| 3176 | */ |
| 3177 | static PyObject *py_pjsua_normalize_stun_config |
| 3178 | (PyObject *pSelf, PyObject *pArgs) |
| 3179 | { |
| 3180 | stun_config_Object *obj; |
| 3181 | pjsua_stun_config *cfg; |
| 3182 | |
| 3183 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 3184 | { |
| 3185 | return NULL; |
| 3186 | } |
| 3187 | cfg = (pjsua_stun_config *)malloc(sizeof(pjsua_stun_config)); |
| 3188 | cfg->stun_port1 = obj->stun_port1; |
| 3189 | cfg->stun_port2 = obj->stun_port2; |
| 3190 | cfg->stun_srv1.ptr = PyString_AsString(obj->stun_srv1); |
| 3191 | cfg->stun_srv1.slen = strlen(PyString_AsString(obj->stun_srv1)); |
| 3192 | cfg->stun_srv2.ptr = PyString_AsString(obj->stun_srv2); |
| 3193 | cfg->stun_srv2.slen = strlen(PyString_AsString(obj->stun_srv2)); |
| 3194 | pjsua_normalize_stun_config(cfg); |
| 3195 | obj->stun_port1 = cfg->stun_port1; |
| 3196 | obj->stun_port2 = cfg->stun_port2; |
| 3197 | Py_XDECREF(obj->stun_srv1); |
| 3198 | obj->stun_srv1 = |
| 3199 | PyString_FromStringAndSize(cfg->stun_srv1.ptr, cfg->stun_srv1.slen); |
| 3200 | Py_XDECREF(obj->stun_srv2); |
| 3201 | obj->stun_srv2 = |
| 3202 | PyString_FromStringAndSize(cfg->stun_srv2.ptr, cfg->stun_srv2.slen); |
| 3203 | free(cfg); |
| 3204 | Py_INCREF(Py_None); |
| 3205 | return Py_None; |
| 3206 | } |
| 3207 | |
| 3208 | /* |
| 3209 | * py_pjsua_transport_config_dup |
| 3210 | */ |
| 3211 | static PyObject *py_pjsua_transport_config_dup |
| 3212 | (PyObject *pSelf, PyObject *pArgs) |
| 3213 | { |
| 3214 | pj_pool_Object *pool; |
| 3215 | transport_config_Object *src; |
| 3216 | transport_config_Object *dest; |
| 3217 | pj_pool_t *p; |
| 3218 | pjsua_transport_config s; |
| 3219 | pjsua_transport_config d; |
| 3220 | |
| 3221 | if (!PyArg_ParseTuple(pArgs, "OOO", &pool, &dest, &src)) |
| 3222 | { |
| 3223 | return NULL; |
| 3224 | } |
| 3225 | p = pool->pool; |
| 3226 | s.public_addr.ptr = PyString_AsString(src->public_addr); |
| 3227 | s.public_addr.slen = strlen(PyString_AsString(src->public_addr)); |
| 3228 | s.bound_addr.ptr = PyString_AsString(src->bound_addr); |
| 3229 | s.bound_addr.slen = strlen(PyString_AsString(src->bound_addr)); |
| 3230 | s.port = src->port; |
| 3231 | s.use_stun = src->use_stun; |
| 3232 | s.stun_config.stun_port1 = src->stun_config->stun_port1; |
| 3233 | s.stun_config.stun_port2 = src->stun_config->stun_port2; |
| 3234 | s.stun_config.stun_srv1.ptr = |
| 3235 | PyString_AsString(src->stun_config->stun_srv1); |
| 3236 | s.stun_config.stun_srv1.slen = |
| 3237 | strlen(PyString_AsString(src->stun_config->stun_srv1)); |
| 3238 | s.stun_config.stun_srv2.ptr = |
| 3239 | PyString_AsString(src->stun_config->stun_srv2); |
| 3240 | s.stun_config.stun_srv2.slen = |
| 3241 | strlen(PyString_AsString(src->stun_config->stun_srv2)); |
| 3242 | d.public_addr.ptr = PyString_AsString(dest->public_addr); |
| 3243 | d.public_addr.slen = strlen(PyString_AsString(dest->public_addr)); |
| 3244 | d.bound_addr.ptr = PyString_AsString(dest->bound_addr); |
| 3245 | d.bound_addr.slen = strlen(PyString_AsString(dest->bound_addr)); |
| 3246 | d.port = dest->port; |
| 3247 | d.use_stun = dest->use_stun; |
| 3248 | d.stun_config.stun_port1 = dest->stun_config->stun_port1; |
| 3249 | d.stun_config.stun_port2 = dest->stun_config->stun_port2; |
| 3250 | d.stun_config.stun_srv1.ptr = |
| 3251 | PyString_AsString(dest->stun_config->stun_srv1); |
| 3252 | d.stun_config.stun_srv1.slen = |
| 3253 | strlen(PyString_AsString(dest->stun_config->stun_srv1)); |
| 3254 | d.stun_config.stun_srv2.ptr = |
| 3255 | PyString_AsString(dest->stun_config->stun_srv2); |
| 3256 | d.stun_config.stun_srv2.slen = |
| 3257 | strlen(PyString_AsString(dest->stun_config->stun_srv2)); |
| 3258 | pjsua_transport_config_dup(p, &d, &s); |
| 3259 | src->public_addr = |
| 3260 | PyString_FromStringAndSize(s.public_addr.ptr, s.public_addr.slen); |
| 3261 | src->bound_addr = |
| 3262 | PyString_FromStringAndSize(s.bound_addr.ptr, s.bound_addr.slen); |
| 3263 | src->port = s.port; |
| 3264 | src->use_stun = s.use_stun; |
| 3265 | src->stun_config->stun_port1 = s.stun_config.stun_port1; |
| 3266 | src->stun_config->stun_port2 = s.stun_config.stun_port2; |
| 3267 | Py_XDECREF(src->stun_config->stun_srv1); |
| 3268 | src->stun_config->stun_srv1 = |
| 3269 | PyString_FromStringAndSize(s.stun_config.stun_srv1.ptr, |
| 3270 | s.stun_config.stun_srv1.slen); |
| 3271 | Py_XDECREF(src->stun_config->stun_srv2); |
| 3272 | src->stun_config->stun_srv2 = |
| 3273 | PyString_FromStringAndSize(s.stun_config.stun_srv2.ptr, |
| 3274 | s.stun_config.stun_srv2.slen); |
| 3275 | dest->public_addr = |
| 3276 | PyString_FromStringAndSize(d.public_addr.ptr, d.public_addr.slen); |
| 3277 | dest->bound_addr = |
| 3278 | PyString_FromStringAndSize(d.bound_addr.ptr, d.bound_addr.slen); |
| 3279 | dest->port = d.port; |
| 3280 | dest->use_stun = d.use_stun; |
| 3281 | dest->stun_config->stun_port1 = d.stun_config.stun_port1; |
| 3282 | dest->stun_config->stun_port2 = d.stun_config.stun_port2; |
| 3283 | Py_XDECREF(dest->stun_config->stun_srv1); |
| 3284 | dest->stun_config->stun_srv1 = |
| 3285 | PyString_FromStringAndSize(d.stun_config.stun_srv1.ptr, |
| 3286 | d.stun_config.stun_srv1.slen); |
| 3287 | Py_XDECREF(dest->stun_config->stun_srv2); |
| 3288 | dest->stun_config->stun_srv2 = |
| 3289 | PyString_FromStringAndSize(d.stun_config.stun_srv2.ptr, |
| 3290 | d.stun_config.stun_srv2.slen); |
| 3291 | Py_INCREF(Py_None); |
| 3292 | return Py_None; |
| 3293 | } |
| 3294 | |
| 3295 | /* |
| 3296 | * py_pjsua_transport_create |
| 3297 | */ |
| 3298 | static PyObject *py_pjsua_transport_create(PyObject *pSelf, PyObject *pArgs) |
| 3299 | { |
| 3300 | pj_status_t status; |
| 3301 | int type; |
| 3302 | transport_id_Object *p_id; |
| 3303 | transport_config_Object *obj; |
| 3304 | pjsua_transport_config cfg; |
| 3305 | pjsua_transport_id id; |
| 3306 | if (!PyArg_ParseTuple(pArgs, "iOO", &type, &obj, &p_id)) |
| 3307 | { |
| 3308 | return NULL; |
| 3309 | } |
| 3310 | cfg.public_addr.ptr = PyString_AsString(obj->public_addr); |
| 3311 | cfg.public_addr.slen = strlen(PyString_AsString(obj->public_addr)); |
| 3312 | cfg.bound_addr.ptr = PyString_AsString(obj->bound_addr); |
| 3313 | cfg.bound_addr.slen = strlen(PyString_AsString(obj->bound_addr)); |
| 3314 | cfg.port = obj->port; |
| 3315 | cfg.use_stun = obj->use_stun; |
| 3316 | cfg.stun_config.stun_port1 = obj->stun_config->stun_port1; |
| 3317 | cfg.stun_config.stun_port2 = obj->stun_config->stun_port2; |
| 3318 | cfg.stun_config.stun_srv1.ptr = |
| 3319 | PyString_AsString(obj->stun_config->stun_srv1); |
| 3320 | cfg.stun_config.stun_srv1.slen = |
| 3321 | strlen(PyString_AsString(obj->stun_config->stun_srv1)); |
| 3322 | cfg.stun_config.stun_srv2.ptr = |
| 3323 | PyString_AsString(obj->stun_config->stun_srv2); |
| 3324 | cfg.stun_config.stun_srv2.slen = |
| 3325 | strlen(PyString_AsString(obj->stun_config->stun_srv2)); |
| 3326 | status = pjsua_transport_create(type, &cfg, &id); |
| 3327 | p_id->transport_id = id; |
| 3328 | printf("status %d\n",status); |
| 3329 | return Py_BuildValue("i",status); |
| 3330 | } |
| 3331 | |
| 3332 | /* |
| 3333 | * py_pjsua_transport_register |
| 3334 | */ |
| 3335 | static PyObject *py_pjsua_transport_register(PyObject *pSelf, PyObject *pArgs) |
| 3336 | { |
| 3337 | pj_status_t status; |
| 3338 | transport_id_Object *p_id; |
| 3339 | pjsip_transport_Object *obj; |
| 3340 | pjsua_transport_id id; |
| 3341 | if (!PyArg_ParseTuple(pArgs, "OO", &obj, &p_id)) |
| 3342 | { |
| 3343 | return NULL; |
| 3344 | } |
| 3345 | |
| 3346 | id = p_id->transport_id; |
| 3347 | status = pjsua_transport_register(obj->tp, &id); |
| 3348 | p_id->transport_id = id; |
| 3349 | return Py_BuildValue("i",status); |
| 3350 | } |
| 3351 | |
| 3352 | /* |
| 3353 | * py_pjsua_enum_transports |
| 3354 | */ |
| 3355 | static PyObject *py_pjsua_enum_transports(PyObject *pSelf, PyObject *pArgs) |
| 3356 | { |
| 3357 | pj_status_t status; |
| 3358 | PyObject *list; |
| 3359 | integer_Object *count; |
| 3360 | pjsua_transport_id *id; |
| 3361 | int c, i; |
| 3362 | if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) |
| 3363 | { |
| 3364 | return NULL; |
| 3365 | } |
| 3366 | c = count->integer; |
| 3367 | id = (pjsua_transport_id *)malloc(c * sizeof(pjsua_transport_id)); |
| 3368 | status = pjsua_enum_transports(id, &c); |
| 3369 | Py_XDECREF(list); |
| 3370 | list = PyList_New(c); |
| 3371 | for (i = 0; i < c; i++) { |
| 3372 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
| 3373 | if (ret == -1) { |
| 3374 | return NULL; |
| 3375 | } |
| 3376 | } |
| 3377 | count->integer = c; |
| 3378 | free(id); |
| 3379 | return Py_BuildValue("i",status); |
| 3380 | } |
| 3381 | |
| 3382 | /* |
| 3383 | * py_pjsua_transport_get_info |
| 3384 | */ |
| 3385 | static PyObject *py_pjsua_transport_get_info(PyObject *pSelf, PyObject *pArgs) |
| 3386 | { |
| 3387 | pj_status_t status; |
| 3388 | int id; |
| 3389 | transport_info_Object *obj; |
| 3390 | pjsua_transport_info info; |
| 3391 | char * str; |
| 3392 | int len; |
| 3393 | int i; |
| 3394 | |
| 3395 | if (!PyArg_ParseTuple(pArgs, "iO", &id, &obj)) |
| 3396 | { |
| 3397 | return NULL; |
| 3398 | } |
| 3399 | info.addr_len = obj->addr_len; |
| 3400 | info.flag = obj->flag; |
| 3401 | info.id = obj->id; |
| 3402 | info.info.ptr = PyString_AsString(obj->info); |
| 3403 | info.info.slen = strlen(PyString_AsString(obj->info)); |
| 3404 | str = PyString_AsString(obj->local_addr->sa_data); |
| 3405 | len = strlen(str); |
| 3406 | if (len > 14) { |
| 3407 | len = 14; |
| 3408 | } |
| 3409 | for (i = 0; i < len; i++) { |
| 3410 | info.local_addr.sa_data[i] = str[i]; |
| 3411 | } |
| 3412 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 3413 | info.local_addr.sa_zero_len = obj->local_addr->sa_zero_len; |
| 3414 | info.local_addr.sa_family = obj->local_addr->sa_family; |
| 3415 | #else |
| 3416 | info.local_addr.sa_family = obj->local_addr->sa_family; |
| 3417 | #endif |
| 3418 | status = pjsua_transport_get_info(id, &info); |
| 3419 | obj->addr_len = info.addr_len; |
| 3420 | obj->flag = info.flag; |
| 3421 | obj->id = info.id; |
| 3422 | obj->info = PyString_FromStringAndSize(info.info.ptr, info.info.slen); |
| 3423 | obj->local_addr->sa_data = |
| 3424 | PyString_FromStringAndSize(info.local_addr.sa_data, 14); |
| 3425 | #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 |
| 3426 | obj->local_addr->sa_zero_len = info.local_addr.sa_zero_len; |
| 3427 | obj->local_addr->sa_family = info.local_addr.sa_family; |
| 3428 | #else |
| 3429 | obj->local_addr->sa_family = info.local_addr.sa_family; |
| 3430 | #endif |
| 3431 | return Py_BuildValue("i",status); |
| 3432 | } |
| 3433 | |
| 3434 | /* |
| 3435 | * py_pjsua_transport_set_enable |
| 3436 | */ |
| 3437 | static PyObject *py_pjsua_transport_set_enable |
| 3438 | (PyObject *pSelf, PyObject *pArgs) |
| 3439 | { |
| 3440 | pj_status_t status; |
| 3441 | int id; |
| 3442 | int enabled; |
| 3443 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &enabled)) |
| 3444 | { |
| 3445 | return NULL; |
| 3446 | } |
| 3447 | status = pjsua_transport_set_enable(id, enabled); |
| 3448 | //printf("status %d\n",status); |
| 3449 | return Py_BuildValue("i",status); |
| 3450 | } |
| 3451 | |
| 3452 | /* |
| 3453 | * py_pjsua_transport_close |
| 3454 | */ |
| 3455 | static PyObject *py_pjsua_transport_close(PyObject *pSelf, PyObject *pArgs) |
| 3456 | { |
| 3457 | pj_status_t status; |
| 3458 | int id; |
| 3459 | int force; |
| 3460 | if (!PyArg_ParseTuple(pArgs, "ii", &id, &force)) |
| 3461 | { |
| 3462 | return NULL; |
| 3463 | } |
| 3464 | status = pjsua_transport_close(id, force); |
| 3465 | //printf("status %d\n",status); |
| 3466 | return Py_BuildValue("i",status); |
| 3467 | } |
| 3468 | |
| 3469 | static char pjsua_stun_config_default_doc[] = |
| 3470 | "void py_pjsua.stun_config_default (py_pjsua.STUN_Config cfg) " |
| 3471 | "Call this function to initialize STUN config with default values."; |
| 3472 | static char pjsua_transport_config_default_doc[] = |
| 3473 | "void py_pjsua.transport_config_default (py_pjsua.Transport_Config cfg) " |
| 3474 | "Call this function to initialize UDP config with default values."; |
| 3475 | static char pjsua_normalize_stun_config_doc[] = |
| 3476 | "void py_pjsua.normalize_stun_config (py_pjsua.STUN_Config cfg) " |
| 3477 | "Normalize STUN config. "; |
| 3478 | static char pjsua_transport_config_dup_doc[] = |
| 3479 | "void py_pjsua.transport_config_dup (py_pjsua.Pool pool, " |
| 3480 | "py_pjsua.Transport_Config dest, py_pjsua.Transport_Config dest) " |
| 3481 | "Duplicate transport config. "; |
| 3482 | static char pjsua_transport_create_doc[] = |
| 3483 | "void py_pjsua.transport_create (int type, " |
| 3484 | "py_pjsua.Transport_Config cfg, py_pjsua.Transport_ID p_id) " |
| 3485 | "Create SIP transport."; |
| 3486 | static char pjsua_transport_register_doc[] = |
| 3487 | "void py_pjsua.transport_register " |
| 3488 | "(py_pjsua.PJSIP_Transport tp, py_pjsua.Transport_ID p_id) " |
| 3489 | "Register transport that has been created by application."; |
| 3490 | static char pjsua_enum_transports_doc[] = |
| 3491 | "void py_pjsua.enum_transports " |
| 3492 | "(py_pjsua.Transport_ID id[], py_pjsua.Integer count) " |
| 3493 | "Enumerate all transports currently created in the system."; |
| 3494 | static char pjsua_transport_get_info_doc[] = |
| 3495 | "void py_pjsua.transport_get_info " |
| 3496 | "(py_pjsua.Transport_ID id, py_pjsua.Transport_Info info) " |
| 3497 | "Get information about transports."; |
| 3498 | static char pjsua_transport_set_enable_doc[] = |
| 3499 | "void py_pjsua.transport_set_enable " |
| 3500 | "(py_pjsua.Transport_ID id, int enabled) " |
| 3501 | "Disable a transport or re-enable it. " |
| 3502 | "By default transport is always enabled after it is created. " |
| 3503 | "Disabling a transport does not necessarily close the socket, " |
| 3504 | "it will only discard incoming messages and prevent the transport " |
| 3505 | "from being used to send outgoing messages."; |
| 3506 | static char pjsua_transport_close_doc[] = |
| 3507 | "void py_pjsua.transport_close (py_pjsua.Transport_ID id, int force) " |
| 3508 | "Close the transport. If transport is forcefully closed, " |
| 3509 | "it will be immediately closed, and any pending transactions " |
| 3510 | "that are using the transport may not terminate properly. " |
| 3511 | "Otherwise, the system will wait until all transactions are closed " |
| 3512 | "while preventing new users from using the transport, and will close " |
| 3513 | "the transport when it is safe to do so."; |
| 3514 | |
| 3515 | /* END OF LIB TRANSPORT */ |
| 3516 | |
| 3517 | /* LIB ACCOUNT */ |
| 3518 | |
| 3519 | /* |
| 3520 | * acc_config_Object |
| 3521 | * Acc Config |
| 3522 | */ |
| 3523 | typedef struct |
| 3524 | { |
| 3525 | PyObject_HEAD |
| 3526 | /* Type-specific fields go here. */ |
| 3527 | int priority; |
| 3528 | PyObject * id; |
| 3529 | PyObject * reg_uri; |
| 3530 | int publish_enabled; |
| 3531 | PyObject * force_contact; |
| 3532 | unsigned proxy_cnt; |
| 3533 | pj_str_t proxy[8]; |
| 3534 | unsigned reg_timeout; |
| 3535 | unsigned cred_count; |
| 3536 | pjsip_cred_info cred_info[8]; |
| 3537 | } acc_config_Object; |
| 3538 | |
| 3539 | |
| 3540 | /* |
| 3541 | * acc_config_dealloc |
| 3542 | * deletes a acc_config from memory |
| 3543 | */ |
| 3544 | static void acc_config_dealloc(acc_config_Object* self) |
| 3545 | { |
| 3546 | Py_XDECREF(self->id); |
| 3547 | Py_XDECREF(self->reg_uri); |
| 3548 | Py_XDECREF(self->force_contact); |
| 3549 | self->ob_type->tp_free((PyObject*)self); |
| 3550 | } |
| 3551 | |
| 3552 | |
| 3553 | /* |
| 3554 | * acc_config_new |
| 3555 | * constructor for acc_config object |
| 3556 | */ |
| 3557 | static PyObject * acc_config_new(PyTypeObject *type, PyObject *args, |
| 3558 | PyObject *kwds) |
| 3559 | { |
| 3560 | acc_config_Object *self; |
| 3561 | |
| 3562 | self = (acc_config_Object *)type->tp_alloc(type, 0); |
| 3563 | if (self != NULL) |
| 3564 | { |
| 3565 | self->id = PyString_FromString(""); |
| 3566 | if (self->id == NULL) |
| 3567 | { |
| 3568 | Py_DECREF(self); |
| 3569 | return NULL; |
| 3570 | } |
| 3571 | self->reg_uri = PyString_FromString(""); |
| 3572 | if (self->reg_uri == NULL) |
| 3573 | { |
| 3574 | Py_DECREF(self); |
| 3575 | return NULL; |
| 3576 | } |
| 3577 | self->force_contact = PyString_FromString(""); |
| 3578 | if (self->force_contact == NULL) |
| 3579 | { |
| 3580 | Py_DECREF(self); |
| 3581 | return NULL; |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | return (PyObject *)self; |
| 3586 | } |
| 3587 | |
| 3588 | static PyObject * acc_config_get_proxy |
| 3589 | (acc_config_Object *self, PyObject * args) |
| 3590 | { |
| 3591 | int idx; |
| 3592 | pj_str_t elmt; |
| 3593 | if (!PyArg_ParseTuple(args,"i",&idx)) |
| 3594 | { |
| 3595 | return NULL; |
| 3596 | } |
| 3597 | if ((idx >= 0) && (idx < 8)) |
| 3598 | { |
| 3599 | elmt = self->proxy[idx]; |
| 3600 | } |
| 3601 | else |
| 3602 | { |
| 3603 | return NULL; |
| 3604 | } |
| 3605 | return PyString_FromStringAndSize(elmt.ptr, elmt.slen); |
| 3606 | } |
| 3607 | |
| 3608 | static PyObject * acc_config_set_proxy |
| 3609 | (acc_config_Object *self, PyObject * args) |
| 3610 | { |
| 3611 | int idx; |
| 3612 | PyObject * str; |
| 3613 | if (!PyArg_ParseTuple(args,"iO",&idx, &str)) |
| 3614 | { |
| 3615 | return NULL; |
| 3616 | } |
| 3617 | if ((idx >= 0) && (idx < 8)) |
| 3618 | { |
| 3619 | self->proxy[idx].ptr = PyString_AsString(str); |
| 3620 | self->proxy[idx].slen = strlen(PyString_AsString(str)); |
| 3621 | } |
| 3622 | else |
| 3623 | { |
| 3624 | return NULL; |
| 3625 | } |
| 3626 | Py_INCREF(Py_None); |
| 3627 | return Py_None; |
| 3628 | } |
| 3629 | static PyObject * acc_config_get_cred_info |
| 3630 | (acc_config_Object *self, PyObject * args) |
| 3631 | { |
| 3632 | int idx; |
| 3633 | pjsip_cred_info elmt; |
| 3634 | pjsip_cred_info_Object *obj; |
| 3635 | if (!PyArg_ParseTuple(args,"i",&idx)) |
| 3636 | { |
| 3637 | return NULL; |
| 3638 | } |
| 3639 | if ((idx >= 0) && (idx < 8)) |
| 3640 | { |
| 3641 | elmt = self->cred_info[idx]; |
| 3642 | } |
| 3643 | else |
| 3644 | { |
| 3645 | return NULL; |
| 3646 | } |
| 3647 | obj = (pjsip_cred_info_Object *) |
| 3648 | PyType_GenericNew(&pjsip_cred_info_Type, NULL, NULL); |
| 3649 | obj->data = PyString_FromStringAndSize(elmt.data.ptr, elmt.data.slen); |
| 3650 | obj->realm = PyString_FromStringAndSize(elmt.realm.ptr, elmt.realm.slen); |
| 3651 | obj->scheme = |
| 3652 | PyString_FromStringAndSize(elmt.scheme.ptr, elmt.scheme.slen); |
| 3653 | obj->username = |
| 3654 | PyString_FromStringAndSize(elmt.username.ptr, elmt.username.slen); |
| 3655 | obj->data_type = elmt.data_type; |
| 3656 | return (PyObject *)obj; |
| 3657 | } |
| 3658 | |
| 3659 | static PyObject * acc_config_set_cred_info |
| 3660 | (acc_config_Object *self, PyObject * args) |
| 3661 | { |
| 3662 | int idx; |
| 3663 | pjsip_cred_info_Object * obj; |
| 3664 | if (!PyArg_ParseTuple(args,"iO",&idx, &obj)) |
| 3665 | { |
| 3666 | return NULL; |
| 3667 | } |
| 3668 | if ((idx >= 0) && (idx < 8)) |
| 3669 | { |
| 3670 | self->cred_info[idx].data.ptr = PyString_AsString(obj->data); |
| 3671 | self->cred_info[idx].data.slen = strlen(PyString_AsString(obj->data)); |
| 3672 | self->cred_info[idx].realm.ptr = PyString_AsString(obj->realm); |
| 3673 | self->cred_info[idx].realm.slen = strlen(PyString_AsString(obj->realm)); |
| 3674 | self->cred_info[idx].scheme.ptr = PyString_AsString(obj->scheme); |
| 3675 | self->cred_info[idx].scheme.slen = |
| 3676 | strlen(PyString_AsString(obj->scheme)); |
| 3677 | self->cred_info[idx].username.ptr = PyString_AsString(obj->username); |
| 3678 | self->cred_info[idx].username.slen = |
| 3679 | strlen(PyString_AsString(obj->username)); |
| 3680 | self->cred_info[idx].data_type = obj->data_type; |
| 3681 | } |
| 3682 | else |
| 3683 | { |
| 3684 | return NULL; |
| 3685 | } |
| 3686 | Py_INCREF(Py_None); |
| 3687 | return Py_None; |
| 3688 | } |
| 3689 | |
| 3690 | static PyMethodDef acc_config_methods[] = { |
| 3691 | { |
| 3692 | "get_proxy", (PyCFunction)acc_config_get_proxy, METH_VARARGS, |
| 3693 | "Return proxy at specified index" |
| 3694 | }, |
| 3695 | { |
| 3696 | "set_proxy", (PyCFunction)acc_config_set_proxy, METH_VARARGS, |
| 3697 | "Set proxy at specified index" |
| 3698 | }, |
| 3699 | { |
| 3700 | "get_cred_info", (PyCFunction)acc_config_get_cred_info, METH_VARARGS, |
| 3701 | "Return cred_info at specified index" |
| 3702 | }, |
| 3703 | { |
| 3704 | "set_cred_info", (PyCFunction)acc_config_set_cred_info, METH_VARARGS, |
| 3705 | "Set cred_info at specified index" |
| 3706 | }, |
| 3707 | {NULL} /* Sentinel */ |
| 3708 | }; |
| 3709 | |
| 3710 | |
| 3711 | |
| 3712 | /* |
| 3713 | * acc_config_members |
| 3714 | */ |
| 3715 | static PyMemberDef acc_config_members[] = |
| 3716 | { |
| 3717 | { |
| 3718 | "priority", T_INT, offsetof(acc_config_Object, priority), 0, |
| 3719 | "Account priority, which is used to control the order of matching " |
| 3720 | "incoming/outgoing requests. The higher the number means the higher " |
| 3721 | "the priority is, and the account will be matched first. " |
| 3722 | }, |
| 3723 | { |
| 3724 | "id", T_OBJECT_EX, |
| 3725 | offsetof(acc_config_Object, id), 0, |
| 3726 | "The full SIP URL for the account. " |
| 3727 | "The value can take name address or URL format, " |
| 3728 | "and will look something like 'sip:account@serviceprovider'. " |
| 3729 | "This field is mandatory." |
| 3730 | }, |
| 3731 | { |
| 3732 | "reg_uri", T_OBJECT_EX, |
| 3733 | offsetof(acc_config_Object, reg_uri), 0, |
| 3734 | "This is the URL to be put in the request URI for the registration, " |
| 3735 | "and will look something like 'sip:serviceprovider'. " |
| 3736 | "This field should be specified if registration is desired. " |
| 3737 | "If the value is empty, no account registration will be performed. " |
| 3738 | }, |
| 3739 | { |
| 3740 | "publish_enabled", T_INT, |
| 3741 | offsetof(acc_config_Object, publish_enabled), 0, |
| 3742 | "Publish presence? " |
| 3743 | }, |
| 3744 | { |
| 3745 | "force_contact", T_OBJECT_EX, |
| 3746 | offsetof(acc_config_Object, force_contact), 0, |
| 3747 | "Optional URI to be put as Contact for this account. " |
| 3748 | "It is recommended that this field is left empty, " |
| 3749 | "so that the value will be calculated automatically " |
| 3750 | "based on the transport address. " |
| 3751 | }, |
| 3752 | { |
| 3753 | "proxy_cnt", T_INT, offsetof(acc_config_Object, proxy_cnt), 0, |
| 3754 | "Number of proxies in the proxy array below. " |
| 3755 | }, |
| 3756 | { |
| 3757 | "reg_timeout", T_INT, offsetof(acc_config_Object, reg_timeout), 0, |
| 3758 | "Optional interval for registration, in seconds. " |
| 3759 | "If the value is zero, default interval will be used " |
| 3760 | "(PJSUA_REG_INTERVAL, 55 seconds). " |
| 3761 | }, |
| 3762 | { |
| 3763 | "cred_count", T_INT, offsetof(acc_config_Object, cred_count), 0, |
| 3764 | "Number of credentials in the credential array. " |
| 3765 | }, |
| 3766 | {NULL} /* Sentinel */ |
| 3767 | }; |
| 3768 | |
| 3769 | |
| 3770 | |
| 3771 | |
| 3772 | /* |
| 3773 | * acc_config_Type |
| 3774 | */ |
| 3775 | static PyTypeObject acc_config_Type = |
| 3776 | { |
| 3777 | PyObject_HEAD_INIT(NULL) |
| 3778 | 0, /*ob_size*/ |
| 3779 | "py_pjsua.Acc_Config", /*tp_name*/ |
| 3780 | sizeof(acc_config_Object), /*tp_basicsize*/ |
| 3781 | 0, /*tp_itemsize*/ |
| 3782 | (destructor)acc_config_dealloc,/*tp_dealloc*/ |
| 3783 | 0, /*tp_print*/ |
| 3784 | 0, /*tp_getattr*/ |
| 3785 | 0, /*tp_setattr*/ |
| 3786 | 0, /*tp_compare*/ |
| 3787 | 0, /*tp_repr*/ |
| 3788 | 0, /*tp_as_number*/ |
| 3789 | 0, /*tp_as_sequence*/ |
| 3790 | 0, /*tp_as_mapping*/ |
| 3791 | 0, /*tp_hash */ |
| 3792 | 0, /*tp_call*/ |
| 3793 | 0, /*tp_str*/ |
| 3794 | 0, /*tp_getattro*/ |
| 3795 | 0, /*tp_setattro*/ |
| 3796 | 0, /*tp_as_buffer*/ |
| 3797 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 3798 | "Acc Config objects", /* tp_doc */ |
| 3799 | 0, /* tp_traverse */ |
| 3800 | 0, /* tp_clear */ |
| 3801 | 0, /* tp_richcompare */ |
| 3802 | 0, /* tp_weaklistoffset */ |
| 3803 | 0, /* tp_iter */ |
| 3804 | 0, /* tp_iternext */ |
| 3805 | acc_config_methods, /* tp_methods */ |
| 3806 | acc_config_members, /* tp_members */ |
| 3807 | 0, /* tp_getset */ |
| 3808 | 0, /* tp_base */ |
| 3809 | 0, /* tp_dict */ |
| 3810 | 0, /* tp_descr_get */ |
| 3811 | 0, /* tp_descr_set */ |
| 3812 | 0, /* tp_dictoffset */ |
| 3813 | 0, /* tp_init */ |
| 3814 | 0, /* tp_alloc */ |
| 3815 | acc_config_new, /* tp_new */ |
| 3816 | |
| 3817 | }; |
| 3818 | |
| 3819 | /* |
| 3820 | * acc_info_Object |
| 3821 | * Acc Info |
| 3822 | */ |
| 3823 | typedef struct |
| 3824 | { |
| 3825 | PyObject_HEAD |
| 3826 | /* Type-specific fields go here. */ |
| 3827 | int id; |
| 3828 | int is_default; |
| 3829 | PyObject * acc_uri; |
| 3830 | int has_registration; |
| 3831 | int expires; |
| 3832 | int status; |
| 3833 | PyObject * status_text; |
| 3834 | int online_status; |
| 3835 | char buf_[PJ_ERR_MSG_SIZE]; |
| 3836 | } acc_info_Object; |
| 3837 | |
| 3838 | |
| 3839 | /* |
| 3840 | * acc_info_dealloc |
| 3841 | * deletes a acc_info from memory |
| 3842 | */ |
| 3843 | static void acc_info_dealloc(acc_info_Object* self) |
| 3844 | { |
| 3845 | Py_XDECREF(self->acc_uri); |
| 3846 | Py_XDECREF(self->status_text); |
| 3847 | self->ob_type->tp_free((PyObject*)self); |
| 3848 | } |
| 3849 | |
| 3850 | |
| 3851 | /* |
| 3852 | * acc_info_new |
| 3853 | * constructor for acc_info object |
| 3854 | */ |
| 3855 | static PyObject * acc_info_new(PyTypeObject *type, PyObject *args, |
| 3856 | PyObject *kwds) |
| 3857 | { |
| 3858 | acc_info_Object *self; |
| 3859 | |
| 3860 | self = (acc_info_Object *)type->tp_alloc(type, 0); |
| 3861 | if (self != NULL) |
| 3862 | { |
| 3863 | self->acc_uri = PyString_FromString(""); |
| 3864 | if (self->acc_uri == NULL) |
| 3865 | { |
| 3866 | Py_DECREF(self); |
| 3867 | return NULL; |
| 3868 | } |
| 3869 | self->status_text = PyString_FromString(""); |
| 3870 | if (self->status_text == NULL) |
| 3871 | { |
| 3872 | Py_DECREF(self); |
| 3873 | return NULL; |
| 3874 | } |
| 3875 | |
| 3876 | } |
| 3877 | |
| 3878 | return (PyObject *)self; |
| 3879 | } |
| 3880 | |
| 3881 | static PyObject * acc_info_get_buf |
| 3882 | (acc_info_Object *self, PyObject * args) |
| 3883 | { |
| 3884 | int idx; |
| 3885 | char elmt; |
| 3886 | if (!PyArg_ParseTuple(args,"i",&idx)) |
| 3887 | { |
| 3888 | return NULL; |
| 3889 | } |
| 3890 | if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) |
| 3891 | { |
| 3892 | elmt = self->buf_[idx]; |
| 3893 | } |
| 3894 | else |
| 3895 | { |
| 3896 | return NULL; |
| 3897 | } |
| 3898 | return PyString_FromStringAndSize(&elmt, 1); |
| 3899 | } |
| 3900 | |
| 3901 | static PyObject * acc_info_set_buf |
| 3902 | (acc_info_Object *self, PyObject * args) |
| 3903 | { |
| 3904 | int idx; |
| 3905 | PyObject * str; |
| 3906 | char * s; |
| 3907 | if (!PyArg_ParseTuple(args,"iO",&idx, &str)) |
| 3908 | { |
| 3909 | return NULL; |
| 3910 | } |
| 3911 | if ((idx >= 0) && (idx < PJ_ERR_MSG_SIZE)) |
| 3912 | { |
| 3913 | s = PyString_AsString(str); |
| 3914 | if (s[0]) |
| 3915 | { |
| 3916 | self->buf_[idx] = s[0]; |
| 3917 | } |
| 3918 | else |
| 3919 | { |
| 3920 | return NULL; |
| 3921 | } |
| 3922 | } |
| 3923 | else |
| 3924 | { |
| 3925 | return NULL; |
| 3926 | } |
| 3927 | Py_INCREF(Py_None); |
| 3928 | return Py_None; |
| 3929 | } |
| 3930 | |
| 3931 | static PyMethodDef acc_info_methods[] = { |
| 3932 | { |
| 3933 | "get_buf", (PyCFunction)acc_info_get_buf, METH_VARARGS, |
| 3934 | "Return buf char at specified index" |
| 3935 | }, |
| 3936 | { |
| 3937 | "set_buf", (PyCFunction)acc_info_set_buf, METH_VARARGS, |
| 3938 | "Set buf at specified index" |
| 3939 | }, |
| 3940 | |
| 3941 | {NULL} /* Sentinel */ |
| 3942 | }; |
| 3943 | |
| 3944 | |
| 3945 | |
| 3946 | /* |
| 3947 | * acc_info_members |
| 3948 | */ |
| 3949 | static PyMemberDef acc_info_members[] = |
| 3950 | { |
| 3951 | { |
| 3952 | "id", T_INT, offsetof(acc_info_Object, id), 0, |
| 3953 | "The account ID." |
| 3954 | }, |
| 3955 | { |
| 3956 | "is_default", T_INT, offsetof(acc_info_Object, is_default), 0, |
| 3957 | "Flag to indicate whether this is the default account. " |
| 3958 | }, |
| 3959 | { |
| 3960 | "acc_uri", T_OBJECT_EX, |
| 3961 | offsetof(acc_info_Object, acc_uri), 0, |
| 3962 | "Account URI" |
| 3963 | }, |
| 3964 | { |
| 3965 | "has_registration", T_INT, offsetof(acc_info_Object, has_registration), |
| 3966 | 0, |
| 3967 | "Flag to tell whether this account has registration setting " |
| 3968 | "(reg_uri is not empty)." |
| 3969 | }, |
| 3970 | { |
| 3971 | "expires", T_INT, offsetof(acc_info_Object, expires), 0, |
| 3972 | "An up to date expiration interval for account registration session." |
| 3973 | }, |
| 3974 | { |
| 3975 | "status", T_INT, offsetof(acc_info_Object, status), 0, |
| 3976 | "Last registration status code. If status code is zero, " |
| 3977 | "the account is currently not registered. Any other value indicates " |
| 3978 | "the SIP status code of the registration. " |
| 3979 | }, |
| 3980 | { |
| 3981 | "status_text", T_OBJECT_EX, |
| 3982 | offsetof(acc_info_Object, status_text), 0, |
| 3983 | "String describing the registration status." |
| 3984 | }, |
| 3985 | { |
| 3986 | "online_status", T_INT, offsetof(acc_info_Object, online_status), 0, |
| 3987 | "Presence online status for this account. " |
| 3988 | }, |
| 3989 | {NULL} /* Sentinel */ |
| 3990 | }; |
| 3991 | |
| 3992 | |
| 3993 | |
| 3994 | |
| 3995 | /* |
| 3996 | * acc_info_Type |
| 3997 | */ |
| 3998 | static PyTypeObject acc_info_Type = |
| 3999 | { |
| 4000 | PyObject_HEAD_INIT(NULL) |
| 4001 | 0, /*ob_size*/ |
| 4002 | "py_pjsua.Acc_Info", /*tp_name*/ |
| 4003 | sizeof(acc_info_Object), /*tp_basicsize*/ |
| 4004 | 0, /*tp_itemsize*/ |
| 4005 | (destructor)acc_info_dealloc,/*tp_dealloc*/ |
| 4006 | 0, /*tp_print*/ |
| 4007 | 0, /*tp_getattr*/ |
| 4008 | 0, /*tp_setattr*/ |
| 4009 | 0, /*tp_compare*/ |
| 4010 | 0, /*tp_repr*/ |
| 4011 | 0, /*tp_as_number*/ |
| 4012 | 0, /*tp_as_sequence*/ |
| 4013 | 0, /*tp_as_mapping*/ |
| 4014 | 0, /*tp_hash */ |
| 4015 | 0, /*tp_call*/ |
| 4016 | 0, /*tp_str*/ |
| 4017 | 0, /*tp_getattro*/ |
| 4018 | 0, /*tp_setattro*/ |
| 4019 | 0, /*tp_as_buffer*/ |
| 4020 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 4021 | "Acc Info objects", /* tp_doc */ |
| 4022 | 0, /* tp_traverse */ |
| 4023 | 0, /* tp_clear */ |
| 4024 | 0, /* tp_richcompare */ |
| 4025 | 0, /* tp_weaklistoffset */ |
| 4026 | 0, /* tp_iter */ |
| 4027 | 0, /* tp_iternext */ |
| 4028 | acc_info_methods, /* tp_methods */ |
| 4029 | acc_info_members, /* tp_members */ |
| 4030 | 0, /* tp_getset */ |
| 4031 | 0, /* tp_base */ |
| 4032 | 0, /* tp_dict */ |
| 4033 | 0, /* tp_descr_get */ |
| 4034 | 0, /* tp_descr_set */ |
| 4035 | 0, /* tp_dictoffset */ |
| 4036 | 0, /* tp_init */ |
| 4037 | 0, /* tp_alloc */ |
| 4038 | acc_info_new, /* tp_new */ |
| 4039 | |
| 4040 | }; |
| 4041 | |
| 4042 | /* |
| 4043 | * acc_id_Object |
| 4044 | * C/Python wrapper for acc_id object |
| 4045 | */ |
| 4046 | typedef struct |
| 4047 | { |
| 4048 | PyObject_HEAD |
| 4049 | /* Type-specific fields go here. */ |
| 4050 | int acc_id; |
| 4051 | } acc_id_Object; |
| 4052 | |
| 4053 | |
| 4054 | /* |
| 4055 | * acc_id_members |
| 4056 | * declares attributes accessible from |
| 4057 | * both C and Python for acc_id object |
| 4058 | */ |
| 4059 | static PyMemberDef acc_id_members[] = |
| 4060 | { |
| 4061 | { |
| 4062 | "acc_id", T_INT, offsetof(acc_id_Object, acc_id), 0, |
| 4063 | "Account identification" |
| 4064 | }, |
| 4065 | {NULL} /* Sentinel */ |
| 4066 | }; |
| 4067 | |
| 4068 | |
| 4069 | /* |
| 4070 | * acc_id_Type |
| 4071 | */ |
| 4072 | static PyTypeObject acc_id_Type = |
| 4073 | { |
| 4074 | PyObject_HEAD_INIT(NULL) |
| 4075 | 0, /*ob_size*/ |
| 4076 | "py_pjsua.Acc_ID", /*tp_name*/ |
| 4077 | sizeof(acc_id_Object), /*tp_basicsize*/ |
| 4078 | 0, /*tp_itemsize*/ |
| 4079 | 0, /*tp_dealloc*/ |
| 4080 | 0, /*tp_print*/ |
| 4081 | 0, /*tp_getattr*/ |
| 4082 | 0, /*tp_setattr*/ |
| 4083 | 0, /*tp_compare*/ |
| 4084 | 0, /*tp_repr*/ |
| 4085 | 0, /*tp_as_number*/ |
| 4086 | 0, /*tp_as_sequence*/ |
| 4087 | 0, /*tp_as_mapping*/ |
| 4088 | 0, /*tp_hash */ |
| 4089 | 0, /*tp_call*/ |
| 4090 | 0, /*tp_str*/ |
| 4091 | 0, /*tp_getattro*/ |
| 4092 | 0, /*tp_setattro*/ |
| 4093 | 0, /*tp_as_buffer*/ |
| 4094 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 4095 | "Acc ID objects", /*tp_doc*/ |
| 4096 | 0, /*tp_traverse*/ |
| 4097 | 0, /*tp_clear*/ |
| 4098 | 0, /*tp_richcompare*/ |
| 4099 | 0, /* tp_weaklistoffset */ |
| 4100 | 0, /* tp_iter */ |
| 4101 | 0, /* tp_iternext */ |
| 4102 | 0, /* tp_methods */ |
| 4103 | acc_id_members, /* tp_members */ |
| 4104 | |
| 4105 | }; |
| 4106 | |
| 4107 | /* |
| 4108 | * py_pjsua_acc_config_default |
| 4109 | */ |
| 4110 | static PyObject *py_pjsua_acc_config_default |
| 4111 | (PyObject *pSelf, PyObject *pArgs) |
| 4112 | { |
| 4113 | acc_config_Object *obj; |
| 4114 | pjsua_acc_config cfg; |
| 4115 | int i; |
| 4116 | |
| 4117 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 4118 | { |
| 4119 | return NULL; |
| 4120 | } |
| 4121 | pjsua_acc_config_default(&cfg); |
| 4122 | obj->cred_count = cfg.cred_count; |
| 4123 | for (i = 0; i < 8; i++) |
| 4124 | { |
| 4125 | obj->cred_info[i] = cfg.cred_info[i]; |
| 4126 | } |
| 4127 | Py_XDECREF(obj->force_contact); |
| 4128 | obj->force_contact = |
| 4129 | PyString_FromStringAndSize(cfg.force_contact.ptr, |
| 4130 | cfg.force_contact.slen); |
| 4131 | obj->priority = cfg.priority; |
| 4132 | Py_XDECREF(obj->id); |
| 4133 | obj->id = |
| 4134 | PyString_FromStringAndSize(cfg.id.ptr, cfg.id.slen); |
| 4135 | Py_XDECREF(obj->reg_uri); |
| 4136 | obj->reg_uri = |
| 4137 | PyString_FromStringAndSize(cfg.reg_uri.ptr, cfg.reg_uri.slen); |
| 4138 | obj->proxy_cnt = cfg.proxy_cnt; |
| 4139 | for (i = 0; i < 8; i++) |
| 4140 | { |
| 4141 | obj->proxy[i] = cfg.proxy[i]; |
| 4142 | } |
| 4143 | obj->publish_enabled = cfg.publish_enabled; |
| 4144 | obj->reg_timeout = cfg.reg_timeout; |
| 4145 | |
| 4146 | Py_INCREF(Py_None); |
| 4147 | return Py_None; |
| 4148 | } |
| 4149 | |
| 4150 | /* |
| 4151 | * py_pjsua_acc_get_count |
| 4152 | */ |
| 4153 | static PyObject *py_pjsua_acc_get_count |
| 4154 | (PyObject *pSelf, PyObject *pArgs) |
| 4155 | { |
| 4156 | int count; |
| 4157 | if (!PyArg_ParseTuple(pArgs, "")) |
| 4158 | { |
| 4159 | return NULL; |
| 4160 | } |
| 4161 | count = pjsua_acc_get_count(); |
| 4162 | return Py_BuildValue("i",count); |
| 4163 | } |
| 4164 | |
| 4165 | /* |
| 4166 | * py_pjsua_acc_is_valid |
| 4167 | */ |
| 4168 | static PyObject *py_pjsua_acc_is_valid |
| 4169 | (PyObject *pSelf, PyObject *pArgs) |
| 4170 | { |
| 4171 | int id; |
| 4172 | int is_valid; |
| 4173 | |
| 4174 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 4175 | { |
| 4176 | return NULL; |
| 4177 | } |
| 4178 | is_valid = pjsua_acc_is_valid(id); |
| 4179 | |
| 4180 | return Py_BuildValue("i", is_valid); |
| 4181 | } |
| 4182 | |
| 4183 | /* |
| 4184 | * py_pjsua_acc_set_default |
| 4185 | */ |
| 4186 | static PyObject *py_pjsua_acc_set_default |
| 4187 | (PyObject *pSelf, PyObject *pArgs) |
| 4188 | { |
| 4189 | int id; |
| 4190 | int status; |
| 4191 | |
| 4192 | if (!PyArg_ParseTuple(pArgs, "i", &id)) |
| 4193 | { |
| 4194 | return NULL; |
| 4195 | } |
| 4196 | status = pjsua_acc_set_default(id); |
| 4197 | |
| 4198 | return Py_BuildValue("i", status); |
| 4199 | } |
| 4200 | |
| 4201 | /* |
| 4202 | * py_pjsua_acc_get_default |
| 4203 | */ |
| 4204 | static PyObject *py_pjsua_acc_get_default |
| 4205 | (PyObject *pSelf, PyObject *pArgs) |
| 4206 | { |
| 4207 | int id; |
| 4208 | |
| 4209 | if (!PyArg_ParseTuple(pArgs, "")) |
| 4210 | { |
| 4211 | return NULL; |
| 4212 | } |
| 4213 | id = pjsua_acc_get_default(); |
| 4214 | |
| 4215 | return Py_BuildValue("i", id); |
| 4216 | } |
| 4217 | |
| 4218 | /* |
| 4219 | * py_pjsua_acc_add |
| 4220 | */ |
| 4221 | static PyObject *py_pjsua_acc_add |
| 4222 | (PyObject *pSelf, PyObject *pArgs) |
| 4223 | { |
| 4224 | int is_default; |
| 4225 | acc_config_Object * ac; |
| 4226 | pjsua_acc_config cfg; |
| 4227 | acc_id_Object * id; |
| 4228 | int p_acc_id; |
| 4229 | int status; |
| 4230 | int i; |
| 4231 | |
| 4232 | if (!PyArg_ParseTuple(pArgs, "OiO", &ac, &is_default, &id)) |
| 4233 | { |
| 4234 | return NULL; |
| 4235 | } |
| 4236 | cfg.cred_count = ac->cred_count; |
| 4237 | for (i = 0; i < 8; i++) |
| 4238 | { |
| 4239 | cfg.cred_info[i] = ac->cred_info[i]; |
| 4240 | } |
| 4241 | cfg.force_contact.ptr = PyString_AsString(ac->force_contact); |
| 4242 | cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); |
| 4243 | cfg.id.ptr = PyString_AsString(ac->id); |
| 4244 | cfg.id.slen = strlen(PyString_AsString(ac->id)); |
| 4245 | cfg.priority = ac->priority; |
| 4246 | for (i = 0; i < 8; i++) { |
| 4247 | cfg.proxy[i] = ac->proxy[i]; |
| 4248 | } |
| 4249 | cfg.proxy_cnt = ac->proxy_cnt; |
| 4250 | cfg.publish_enabled = ac->publish_enabled; |
| 4251 | cfg.reg_timeout = ac->reg_timeout; |
| 4252 | cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); |
| 4253 | cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); |
| 4254 | p_acc_id = id->acc_id; |
| 4255 | status = pjsua_acc_add(&cfg, is_default, &p_acc_id); |
| 4256 | id->acc_id = p_acc_id; |
| 4257 | return Py_BuildValue("i", status); |
| 4258 | } |
| 4259 | |
| 4260 | /* |
| 4261 | * py_pjsua_acc_add_local |
| 4262 | */ |
| 4263 | static PyObject *py_pjsua_acc_add_local |
| 4264 | (PyObject *pSelf, PyObject *pArgs) |
| 4265 | { |
| 4266 | int is_default; |
| 4267 | int tid; |
| 4268 | acc_id_Object * id; |
| 4269 | int p_acc_id; |
| 4270 | int status; |
| 4271 | |
| 4272 | |
| 4273 | if (!PyArg_ParseTuple(pArgs, "iiO", &tid, &is_default, &id)) |
| 4274 | { |
| 4275 | return NULL; |
| 4276 | } |
| 4277 | |
| 4278 | p_acc_id = id->acc_id; |
| 4279 | status = pjsua_acc_add_local(tid, is_default, &p_acc_id); |
| 4280 | id->acc_id = p_acc_id; |
| 4281 | return Py_BuildValue("i", status); |
| 4282 | } |
| 4283 | |
| 4284 | /* |
| 4285 | * py_pjsua_acc_del |
| 4286 | */ |
| 4287 | static PyObject *py_pjsua_acc_del |
| 4288 | (PyObject *pSelf, PyObject *pArgs) |
| 4289 | { |
| 4290 | int acc_id; |
| 4291 | int status; |
| 4292 | |
| 4293 | if (!PyArg_ParseTuple(pArgs, "i", &acc_id)) |
| 4294 | { |
| 4295 | return NULL; |
| 4296 | } |
| 4297 | |
| 4298 | |
| 4299 | status = pjsua_acc_del(acc_id); |
| 4300 | return Py_BuildValue("i", status); |
| 4301 | } |
| 4302 | |
| 4303 | /* |
| 4304 | * py_pjsua_acc_modify |
| 4305 | */ |
| 4306 | static PyObject *py_pjsua_acc_modify |
| 4307 | (PyObject *pSelf, PyObject *pArgs) |
| 4308 | { |
| 4309 | acc_config_Object * ac; |
| 4310 | pjsua_acc_config cfg; |
| 4311 | int acc_id; |
| 4312 | int status; |
| 4313 | int i; |
| 4314 | |
| 4315 | if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &ac)) |
| 4316 | { |
| 4317 | return NULL; |
| 4318 | } |
| 4319 | cfg.cred_count = ac->cred_count; |
| 4320 | for (i = 0; i < 8; i++) |
| 4321 | { |
| 4322 | cfg.cred_info[i] = ac->cred_info[i]; |
| 4323 | } |
| 4324 | cfg.force_contact.ptr = PyString_AsString(ac->force_contact); |
| 4325 | cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); |
| 4326 | cfg.id.ptr = PyString_AsString(ac->id); |
| 4327 | cfg.id.slen = strlen(PyString_AsString(ac->id)); |
| 4328 | cfg.priority = ac->priority; |
| 4329 | for (i = 0; i < 8; i++) { |
| 4330 | cfg.proxy[i] = ac->proxy[i]; |
| 4331 | } |
| 4332 | cfg.proxy_cnt = ac->proxy_cnt; |
| 4333 | cfg.publish_enabled = ac->publish_enabled; |
| 4334 | cfg.reg_timeout = ac->reg_timeout; |
| 4335 | cfg.reg_uri.ptr = PyString_AsString(ac->reg_uri); |
| 4336 | cfg.reg_uri.slen = strlen(PyString_AsString(ac->reg_uri)); |
| 4337 | status = pjsua_acc_modify(acc_id, &cfg); |
| 4338 | return Py_BuildValue("i", status); |
| 4339 | } |
| 4340 | |
| 4341 | /* |
| 4342 | * py_pjsua_acc_set_online_status |
| 4343 | */ |
| 4344 | static PyObject *py_pjsua_acc_set_online_status |
| 4345 | (PyObject *pSelf, PyObject *pArgs) |
| 4346 | { |
| 4347 | int is_online; |
| 4348 | int acc_id; |
| 4349 | int status; |
| 4350 | |
| 4351 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &is_online)) |
| 4352 | { |
| 4353 | return NULL; |
| 4354 | } |
| 4355 | |
| 4356 | status = pjsua_acc_set_online_status(acc_id, is_online); |
| 4357 | |
| 4358 | return Py_BuildValue("i", status); |
| 4359 | } |
| 4360 | |
| 4361 | /* |
| 4362 | * py_pjsua_acc_set_registration |
| 4363 | */ |
| 4364 | static PyObject *py_pjsua_acc_set_registration |
| 4365 | (PyObject *pSelf, PyObject *pArgs) |
| 4366 | { |
| 4367 | int renew; |
| 4368 | int acc_id; |
| 4369 | int status; |
| 4370 | |
| 4371 | if (!PyArg_ParseTuple(pArgs, "ii", &acc_id, &renew)) |
| 4372 | { |
| 4373 | return NULL; |
| 4374 | } |
| 4375 | |
| 4376 | status = pjsua_acc_set_registration(acc_id, renew); |
| 4377 | |
| 4378 | return Py_BuildValue("i", status); |
| 4379 | } |
| 4380 | |
| 4381 | /* |
| 4382 | * py_pjsua_acc_set_get_info |
| 4383 | */ |
| 4384 | static PyObject *py_pjsua_acc_get_info |
| 4385 | (PyObject *pSelf, PyObject *pArgs) |
| 4386 | { |
| 4387 | int acc_id; |
| 4388 | acc_info_Object * obj; |
| 4389 | pjsua_acc_info info; |
| 4390 | int status; |
| 4391 | int i; |
| 4392 | |
| 4393 | if (!PyArg_ParseTuple(pArgs, "iO", &acc_id, &obj)) |
| 4394 | { |
| 4395 | return NULL; |
| 4396 | } |
| 4397 | |
| 4398 | info.acc_uri.ptr = PyString_AsString(obj->acc_uri); |
| 4399 | info.acc_uri.slen = strlen(PyString_AsString(obj->acc_uri)); |
| 4400 | for (i = 0; i < PJ_ERR_MSG_SIZE; i++) { |
| 4401 | info.buf_[i] = obj->buf_[i]; |
| 4402 | } |
| 4403 | info.expires = obj->expires; |
| 4404 | info.has_registration = obj->has_registration; |
| 4405 | info.id = obj->id; |
| 4406 | info.is_default = obj->is_default; |
| 4407 | info.online_status = obj->online_status; |
| 4408 | info.status = obj->status; |
| 4409 | info.status_text.ptr = PyString_AsString(obj->status_text); |
| 4410 | info.status_text.slen = strlen(PyString_AsString(obj->status_text)); |
| 4411 | status = pjsua_acc_get_info(acc_id, &info); |
| 4412 | obj->acc_uri = |
| 4413 | PyString_FromStringAndSize(info.acc_uri.ptr, |
| 4414 | info.acc_uri.slen); |
| 4415 | for (i = 0; i < PJ_ERR_MSG_SIZE; i++) { |
| 4416 | obj->buf_[i] = info.buf_[i]; |
| 4417 | } |
| 4418 | obj->expires = info.expires; |
| 4419 | obj->has_registration = info.has_registration; |
| 4420 | obj->id = info.id; |
| 4421 | obj->is_default = info.is_default; |
| 4422 | obj->online_status = info.online_status; |
| 4423 | obj->status = info.status; |
| 4424 | obj->status_text = |
| 4425 | PyString_FromStringAndSize(info.status_text.ptr, |
| 4426 | info.status_text.slen); |
| 4427 | return Py_BuildValue("i", status); |
| 4428 | } |
| 4429 | |
| 4430 | /* |
| 4431 | * py_pjsua_enum_accs |
| 4432 | */ |
| 4433 | static PyObject *py_pjsua_enum_accs(PyObject *pSelf, PyObject *pArgs) |
| 4434 | { |
| 4435 | pj_status_t status; |
| 4436 | PyObject *list; |
| 4437 | integer_Object *count; |
| 4438 | pjsua_acc_id *id; |
| 4439 | int c, i; |
| 4440 | if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) |
| 4441 | { |
| 4442 | return NULL; |
| 4443 | } |
| 4444 | c = count->integer; |
| 4445 | id = (pjsua_acc_id *)malloc(c * sizeof(pjsua_acc_id)); |
| 4446 | status = pjsua_enum_accs(id, &c); |
| 4447 | Py_XDECREF(list); |
| 4448 | list = PyList_New(c); |
| 4449 | for (i = 0; i < c; i++) { |
| 4450 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", id[i])); |
| 4451 | if (ret == -1) { |
| 4452 | return NULL; |
| 4453 | } |
| 4454 | } |
| 4455 | count->integer = c; |
| 4456 | free(id); |
| 4457 | return Py_BuildValue("i",status); |
| 4458 | } |
| 4459 | |
| 4460 | /* |
| 4461 | * py_pjsua_acc_enum_info |
| 4462 | */ |
| 4463 | static PyObject *py_pjsua_acc_enum_info(PyObject *pSelf, PyObject *pArgs) |
| 4464 | { |
| 4465 | pj_status_t status; |
| 4466 | PyObject *list; |
| 4467 | integer_Object *count; |
| 4468 | pjsua_acc_info *info; |
| 4469 | int c, i; |
| 4470 | if (!PyArg_ParseTuple(pArgs, "OO", &list, &count)) |
| 4471 | { |
| 4472 | return NULL; |
| 4473 | } |
| 4474 | c = count->integer; |
| 4475 | info = (pjsua_acc_info *)malloc(c * sizeof(pjsua_acc_info)); |
| 4476 | status = pjsua_acc_enum_info(info, &c); |
| 4477 | Py_XDECREF(list); |
| 4478 | list = PyList_New(c); |
| 4479 | for (i = 0; i < c; i++) { |
| 4480 | int ret = PyList_SetItem(list, i, Py_BuildValue("i", info[i])); |
| 4481 | if (ret == -1) { |
| 4482 | return NULL; |
| 4483 | } |
| 4484 | } |
| 4485 | count->integer = c; |
| 4486 | free(info); |
| 4487 | return Py_BuildValue("i",status); |
| 4488 | } |
| 4489 | |
| 4490 | /* |
| 4491 | * py_pjsua_acc_find_for_outgoing |
| 4492 | */ |
| 4493 | static PyObject *py_pjsua_acc_find_for_outgoing |
| 4494 | (PyObject *pSelf, PyObject *pArgs) |
| 4495 | { |
| 4496 | |
| 4497 | int acc_id; |
| 4498 | PyObject * url; |
| 4499 | pj_str_t str; |
| 4500 | |
| 4501 | if (!PyArg_ParseTuple(pArgs, "O", &url)) |
| 4502 | { |
| 4503 | return NULL; |
| 4504 | } |
| 4505 | str.ptr = PyString_AsString(url); |
| 4506 | str.slen = strlen(PyString_AsString(url)); |
| 4507 | |
| 4508 | acc_id = pjsua_acc_find_for_outgoing(&str); |
| 4509 | |
| 4510 | return Py_BuildValue("i", acc_id); |
| 4511 | } |
| 4512 | |
| 4513 | /* |
| 4514 | * py_pjsua_acc_find_for_incoming |
| 4515 | */ |
| 4516 | static PyObject *py_pjsua_acc_find_for_incoming |
| 4517 | (PyObject *pSelf, PyObject *pArgs) |
| 4518 | { |
| 4519 | int acc_id; |
| 4520 | pjsip_rx_data_Object * obj; |
| 4521 | pjsip_rx_data * rdata; |
| 4522 | |
| 4523 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 4524 | { |
| 4525 | return NULL; |
| 4526 | } |
| 4527 | |
| 4528 | rdata = obj->rdata; |
| 4529 | acc_id = pjsua_acc_find_for_incoming(rdata); |
| 4530 | |
| 4531 | return Py_BuildValue("i", acc_id); |
| 4532 | } |
| 4533 | |
| 4534 | /* |
| 4535 | * py_pjsua_acc_create_uac_contact |
| 4536 | */ |
| 4537 | static PyObject *py_pjsua_acc_create_uac_contact |
| 4538 | (PyObject *pSelf, PyObject *pArgs) |
| 4539 | { |
| 4540 | int status; |
| 4541 | int acc_id; |
| 4542 | pj_pool_Object * p; |
| 4543 | pj_pool_t * pool; |
| 4544 | PyObject * strc; |
| 4545 | pj_str_t contact; |
| 4546 | PyObject * stru; |
| 4547 | pj_str_t uri; |
| 4548 | |
| 4549 | if (!PyArg_ParseTuple(pArgs, "OOiO", &p, &strc, &acc_id, &stru)) |
| 4550 | { |
| 4551 | return NULL; |
| 4552 | } |
| 4553 | |
| 4554 | pool = p->pool; |
| 4555 | contact.ptr = PyString_AsString(strc); |
| 4556 | contact.slen = strlen(PyString_AsString(strc)); |
| 4557 | uri.ptr = PyString_AsString(stru); |
| 4558 | uri.slen = strlen(PyString_AsString(stru)); |
| 4559 | status = pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri); |
| 4560 | strc = PyString_FromStringAndSize(contact.ptr, contact.slen); |
| 4561 | |
| 4562 | return Py_BuildValue("i", status); |
| 4563 | } |
| 4564 | |
| 4565 | /* |
| 4566 | * py_pjsua_acc_create_uas_contact |
| 4567 | */ |
| 4568 | static PyObject *py_pjsua_acc_create_uas_contact |
| 4569 | (PyObject *pSelf, PyObject *pArgs) |
| 4570 | { |
| 4571 | int status; |
| 4572 | int acc_id; |
| 4573 | pj_pool_Object * p; |
| 4574 | pj_pool_t * pool; |
| 4575 | PyObject * strc; |
| 4576 | pj_str_t contact; |
| 4577 | pjsip_rx_data_Object * objr; |
| 4578 | pjsip_rx_data * rdata; |
| 4579 | |
| 4580 | if (!PyArg_ParseTuple(pArgs, "OOiO", &p, &strc, &acc_id, &objr)) |
| 4581 | { |
| 4582 | return NULL; |
| 4583 | } |
| 4584 | |
| 4585 | pool = p->pool; |
| 4586 | contact.ptr = PyString_AsString(strc); |
| 4587 | contact.slen = strlen(PyString_AsString(strc)); |
| 4588 | rdata = objr->rdata; |
| 4589 | status = pjsua_acc_create_uas_contact(pool, &contact, acc_id, rdata); |
| 4590 | strc = PyString_FromStringAndSize(contact.ptr, contact.slen); |
| 4591 | |
| 4592 | return Py_BuildValue("i", status); |
| 4593 | } |
| 4594 | |
| 4595 | static char pjsua_acc_config_default_doc[] = |
| 4596 | "void py_pjsua.acc_config_default (py_pjsua.Acc_Config cfg) " |
| 4597 | "Call this function to initialize account config with default values."; |
| 4598 | static char pjsua_acc_get_count_doc[] = |
| 4599 | "int py_pjsua.acc_get_count () " |
| 4600 | "Get number of current accounts."; |
| 4601 | static char pjsua_acc_is_valid_doc[] = |
| 4602 | "int py_pjsua.acc_is_valid (int acc_id) " |
| 4603 | "Check if the specified account ID is valid."; |
| 4604 | static char pjsua_acc_set_default_doc[] = |
| 4605 | "int py_pjsua.acc_set_default (int acc_id) " |
| 4606 | "Set default account to be used when incoming " |
| 4607 | "and outgoing requests doesn't match any accounts."; |
| 4608 | static char pjsua_acc_get_default_doc[] = |
| 4609 | "int py_pjsua.acc_get_default () " |
| 4610 | "Get default account."; |
| 4611 | static char pjsua_acc_add_doc[] = |
| 4612 | "int py_pjsua.acc_add (py_pjsua.Acc_Config cfg, " |
| 4613 | "int is_default, py_pjsua.Acc_ID p_acc_id) " |
| 4614 | "Add a new account to pjsua. PJSUA must have been initialized " |
| 4615 | "(with pjsua_init()) before calling this function."; |
| 4616 | static char pjsua_acc_add_local_doc[] = |
| 4617 | "int py_pjsua.acc_add_local (int tid, " |
| 4618 | "int is_default, py_pjsua.Acc_ID p_acc_id) " |
| 4619 | "Add a local account. A local account is used to identify " |
| 4620 | "local endpoint instead of a specific user, and for this reason, " |
| 4621 | "a transport ID is needed to obtain the local address information."; |
| 4622 | static char pjsua_acc_del_doc[] = |
| 4623 | "int py_pjsua.acc_del (int acc_id) " |
| 4624 | "Delete account."; |
| 4625 | static char pjsua_acc_modify_doc[] = |
| 4626 | "int py_pjsua.acc_modify (int acc_id, py_pjsua.Acc_Config cfg) " |
| 4627 | "Modify account information."; |
| 4628 | static char pjsua_acc_set_online_status_doc[] = |
| 4629 | "int py_pjsua.acc_set_online_status (int acc_id, int is_online) " |
| 4630 | "Modify account's presence status to be advertised " |
| 4631 | "to remote/presence subscribers."; |
| 4632 | static char pjsua_acc_set_registration_doc[] = |
| 4633 | "int py_pjsua.acc_set_registration (int acc_id, int renew) " |
| 4634 | "Update registration or perform unregistration."; |
| 4635 | static char pjsua_acc_get_info_doc[] = |
| 4636 | "int py_pjsua.acc_get_info (int acc_id, py_pjsua.Acc_Info info) " |
| 4637 | "Get account information."; |
| 4638 | static char pjsua_enum_accs_doc[] = |
| 4639 | "int py_pjsua.enum_accs (py_pjsua.Acc_ID ids[], py_pjsua.Integer count) " |
| 4640 | "Enum accounts all account ids."; |
| 4641 | static char pjsua_acc_enum_info_doc[] = |
| 4642 | "int py_pjsua.acc_enum_info (py_pjsua.Acc_Info info[], " |
| 4643 | "py_pjsua.Integer count) " |
| 4644 | "Enum accounts info."; |
| 4645 | static char pjsua_acc_find_for_outgoing_doc[] = |
| 4646 | "int py_pjsua.acc_find_for_outgoing (string url) " |
| 4647 | "This is an internal function to find the most appropriate account " |
| 4648 | "to used to reach to the specified URL."; |
| 4649 | static char pjsua_acc_find_for_incoming_doc[] = |
| 4650 | "int py_pjsua.acc_find_for_incoming (pjsip_rx_data_Object rdata) " |
| 4651 | "This is an internal function to find the most appropriate account " |
| 4652 | "to be used to handle incoming calls."; |
| 4653 | static char pjsua_acc_create_uac_contact_doc[] = |
| 4654 | "int py_pjsua.acc_create_uac_contact (pj_pool_Object pool, " |
| 4655 | "string contact, int acc_id, string uri) " |
| 4656 | "Create a suitable URI to be put as Contact based on the specified " |
| 4657 | "target URI for the specified account."; |
| 4658 | static char pjsua_acc_create_uas_contact_doc[] = |
| 4659 | "int py_pjsua.acc_create_uas_contact (pj_pool_Object pool, " |
| 4660 | "string contact, int acc_id, pjsip_rx_data_Object rdata) " |
| 4661 | "Create a suitable URI to be put as Contact based on the information " |
| 4662 | "in the incoming request."; |
| 4663 | |
| 4664 | /* END OF LIB ACCOUNT */ |
| 4665 | |
| 4666 | /* XXX test */ |
| 4667 | static PyObject *py_my_parse_by_reference |
| 4668 | (PyObject *pSelf, PyObject *pArgs) |
| 4669 | { |
| 4670 | PyObject *obj; |
| 4671 | |
| 4672 | if (!PyArg_ParseTuple(pArgs, "O", &obj)) |
| 4673 | { |
| 4674 | return NULL; |
| 4675 | } |
| 4676 | |
| 4677 | |
| 4678 | Py_INCREF(Py_None); |
| 4679 | return Py_None; |
| 4680 | } |
| 4681 | |
| 4682 | /* XXX end-test */ |
| 4683 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4684 | |
| 4685 | /* |
| 4686 | * Map of function names to functions |
| 4687 | */ |
| 4688 | static PyMethodDef py_pjsua_methods[] = |
| 4689 | { |
| 4690 | { |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4691 | "my_parse_by_reference", py_my_parse_by_reference, METH_VARARGS, "" |
| 4692 | }, |
| 4693 | { |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4694 | "perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc |
| 4695 | }, |
| 4696 | { |
| 4697 | "create", py_pjsua_create, METH_VARARGS, pjsua_create_doc |
| 4698 | }, |
| 4699 | { |
| 4700 | "init", py_pjsua_init, METH_VARARGS, pjsua_init_doc |
| 4701 | }, |
| 4702 | { |
| 4703 | "start", py_pjsua_start, METH_VARARGS, pjsua_start_doc |
| 4704 | }, |
| 4705 | { |
| 4706 | "destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc |
| 4707 | }, |
| 4708 | { |
| 4709 | "handle_events", py_pjsua_handle_events, METH_VARARGS, |
| 4710 | pjsua_handle_events_doc |
| 4711 | }, |
| 4712 | { |
| 4713 | "verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS, |
| 4714 | pjsua_verify_sip_url_doc |
| 4715 | }, |
| 4716 | { |
| 4717 | "pool_create", py_pjsua_pool_create, METH_VARARGS, |
| 4718 | pjsua_pool_create_doc |
| 4719 | }, |
| 4720 | { |
| 4721 | "get_pjsip_endpt", py_pjsua_get_pjsip_endpt, METH_VARARGS, |
| 4722 | pjsua_get_pjsip_endpt_doc |
| 4723 | }, |
| 4724 | { |
| 4725 | "get_pjmedia_endpt", py_pjsua_get_pjmedia_endpt, METH_VARARGS, |
| 4726 | pjsua_get_pjmedia_endpt_doc |
| 4727 | }, |
| 4728 | { |
| 4729 | "get_pool_factory", py_pjsua_get_pool_factory, METH_VARARGS, |
| 4730 | pjsua_get_pool_factory_doc |
| 4731 | }, |
| 4732 | { |
| 4733 | "reconfigure_logging", py_pjsua_reconfigure_logging, METH_VARARGS, |
| 4734 | pjsua_reconfigure_logging_doc |
| 4735 | }, |
| 4736 | { |
| 4737 | "logging_config_default", py_pjsua_logging_config_default, |
| 4738 | METH_VARARGS, pjsua_logging_config_default_doc |
| 4739 | }, |
| 4740 | { |
| 4741 | "config_default", py_pjsua_config_default, METH_VARARGS, |
| 4742 | pjsua_config_default_doc |
| 4743 | }, |
| 4744 | { |
| 4745 | "media_config_default", py_pjsua_media_config_default, METH_VARARGS, |
| 4746 | pjsua_media_config_default_doc |
| 4747 | }, |
| 4748 | { |
| 4749 | "logging_config_dup", py_pjsua_logging_config_dup, METH_VARARGS, |
| 4750 | pjsua_logging_config_dup_doc |
| 4751 | }, |
| 4752 | { |
| 4753 | "config_dup", py_pjsua_config_dup, METH_VARARGS, pjsua_config_dup_doc |
| 4754 | }, |
| 4755 | { |
| 4756 | "pjsip_cred_dup", py_pjsip_cred_dup, METH_VARARGS, pjsip_cred_dup_doc |
| 4757 | }, |
| 4758 | { |
| 4759 | "msg_data_init", py_pjsua_msg_data_init, METH_VARARGS, |
| 4760 | pjsua_msg_data_init_doc |
| 4761 | }, |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4762 | { |
| 4763 | "stun_config_default", py_pjsua_stun_config_default, METH_VARARGS, |
| 4764 | pjsua_stun_config_default_doc |
| 4765 | }, |
| 4766 | { |
| 4767 | "transport_config_default", py_pjsua_transport_config_default, |
| 4768 | METH_VARARGS,pjsua_transport_config_default_doc |
| 4769 | }, |
| 4770 | { |
| 4771 | "normalize_stun_config", py_pjsua_normalize_stun_config, METH_VARARGS, |
| 4772 | pjsua_normalize_stun_config_doc |
| 4773 | }, |
| 4774 | { |
| 4775 | "transport_config_dup", py_pjsua_transport_config_dup, METH_VARARGS, |
| 4776 | pjsua_transport_config_dup_doc |
| 4777 | }, |
| 4778 | { |
| 4779 | "transport_create", py_pjsua_transport_create, METH_VARARGS, |
| 4780 | pjsua_transport_create_doc |
| 4781 | }, |
| 4782 | { |
| 4783 | "transport_register", py_pjsua_transport_register, METH_VARARGS, |
| 4784 | pjsua_transport_register_doc |
| 4785 | }, |
| 4786 | { |
| 4787 | "transport_enum_transports", py_pjsua_enum_transports, METH_VARARGS, |
| 4788 | pjsua_enum_transports_doc |
| 4789 | }, |
| 4790 | { |
| 4791 | "transport_get_info", py_pjsua_transport_get_info, METH_VARARGS, |
| 4792 | pjsua_transport_get_info_doc |
| 4793 | }, |
| 4794 | { |
| 4795 | "transport_set_enable", py_pjsua_transport_set_enable, METH_VARARGS, |
| 4796 | pjsua_transport_set_enable_doc |
| 4797 | }, |
| 4798 | { |
| 4799 | "transport_close", py_pjsua_transport_close, METH_VARARGS, |
| 4800 | pjsua_transport_close_doc |
| 4801 | }, |
| 4802 | { |
| 4803 | "acc_config_default", py_pjsua_acc_config_default, METH_VARARGS, |
| 4804 | pjsua_acc_config_default_doc |
| 4805 | }, |
| 4806 | { |
| 4807 | "acc_get_count", py_pjsua_acc_get_count, METH_VARARGS, |
| 4808 | pjsua_acc_get_count_doc |
| 4809 | }, |
| 4810 | { |
| 4811 | "acc_is_valid", py_pjsua_acc_is_valid, METH_VARARGS, |
| 4812 | pjsua_acc_is_valid_doc |
| 4813 | }, |
| 4814 | { |
| 4815 | "acc_set_default", py_pjsua_acc_set_default, METH_VARARGS, |
| 4816 | pjsua_acc_set_default_doc |
| 4817 | }, |
| 4818 | { |
| 4819 | "acc_get_default", py_pjsua_acc_get_default, METH_VARARGS, |
| 4820 | pjsua_acc_get_default_doc |
| 4821 | }, |
| 4822 | { |
| 4823 | "acc_add", py_pjsua_acc_add, METH_VARARGS, |
| 4824 | pjsua_acc_add_doc |
| 4825 | }, |
| 4826 | { |
| 4827 | "acc_add_local", py_pjsua_acc_add_local, METH_VARARGS, |
| 4828 | pjsua_acc_add_local_doc |
| 4829 | }, |
| 4830 | { |
| 4831 | "acc_del", py_pjsua_acc_del, METH_VARARGS, |
| 4832 | pjsua_acc_del_doc |
| 4833 | }, |
| 4834 | { |
| 4835 | "acc_modify", py_pjsua_acc_modify, METH_VARARGS, |
| 4836 | pjsua_acc_modify_doc |
| 4837 | }, |
| 4838 | { |
| 4839 | "acc_set_online_status", py_pjsua_acc_set_online_status, METH_VARARGS, |
| 4840 | pjsua_acc_set_online_status_doc |
| 4841 | }, |
| 4842 | { |
| 4843 | "acc_set_registration", py_pjsua_acc_set_registration, METH_VARARGS, |
| 4844 | pjsua_acc_set_registration_doc |
| 4845 | }, |
| 4846 | { |
| 4847 | "acc_get_info", py_pjsua_acc_get_info, METH_VARARGS, |
| 4848 | pjsua_acc_get_info_doc |
| 4849 | }, |
| 4850 | { |
| 4851 | "enum_accs", py_pjsua_enum_accs, METH_VARARGS, |
| 4852 | pjsua_enum_accs_doc |
| 4853 | }, |
| 4854 | { |
| 4855 | "acc_enum_info", py_pjsua_acc_enum_info, METH_VARARGS, |
| 4856 | pjsua_acc_enum_info_doc |
| 4857 | }, |
| 4858 | { |
| 4859 | "acc_find_for_outgoing", py_pjsua_acc_find_for_outgoing, METH_VARARGS, |
| 4860 | pjsua_acc_find_for_outgoing_doc |
| 4861 | }, |
| 4862 | { |
| 4863 | "acc_find_for_incoming", py_pjsua_acc_find_for_incoming, METH_VARARGS, |
| 4864 | pjsua_acc_find_for_incoming_doc |
| 4865 | }, |
| 4866 | { |
| 4867 | "acc_create_uac_contact", py_pjsua_acc_create_uac_contact, METH_VARARGS, |
| 4868 | pjsua_acc_create_uac_contact_doc |
| 4869 | }, |
| 4870 | { |
| 4871 | "acc_create_uas_contact", py_pjsua_acc_create_uas_contact, METH_VARARGS, |
| 4872 | pjsua_acc_create_uas_contact_doc |
| 4873 | }, |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4874 | {NULL, NULL} /* end of function list */ |
| 4875 | }; |
| 4876 | |
| 4877 | |
| 4878 | |
| 4879 | /* |
| 4880 | * Mapping C structs from and to Python objects & initializing object |
| 4881 | */ |
| 4882 | DL_EXPORT(void) |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 4883 | initpy_pjsua(void) |
| 4884 | { |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4885 | PyObject* m = NULL; |
| 4886 | |
| 4887 | if (PyType_Ready(&callback_Type) < 0) |
| 4888 | return; |
| 4889 | if (PyType_Ready(&config_Type) < 0) |
| 4890 | return; |
| 4891 | if (PyType_Ready(&logging_config_Type) < 0) |
| 4892 | return; |
| 4893 | if (PyType_Ready(&msg_data_Type) < 0) |
| 4894 | return; |
| 4895 | media_config_Type.tp_new = PyType_GenericNew; |
| 4896 | if (PyType_Ready(&media_config_Type) < 0) |
| 4897 | return; |
| 4898 | pjsip_event_Type.tp_new = PyType_GenericNew; |
| 4899 | if (PyType_Ready(&pjsip_event_Type) < 0) |
| 4900 | return; |
| 4901 | pjsip_rx_data_Type.tp_new = PyType_GenericNew; |
| 4902 | if (PyType_Ready(&pjsip_rx_data_Type) < 0) |
| 4903 | return; |
| 4904 | pj_pool_Type.tp_new = PyType_GenericNew; |
| 4905 | if (PyType_Ready(&pj_pool_Type) < 0) |
| 4906 | return; |
| 4907 | pjsip_endpoint_Type.tp_new = PyType_GenericNew; |
| 4908 | if (PyType_Ready(&pjsip_endpoint_Type) < 0) |
| 4909 | return; |
| 4910 | pjmedia_endpt_Type.tp_new = PyType_GenericNew; |
| 4911 | if (PyType_Ready(&pjmedia_endpt_Type) < 0) |
| 4912 | return; |
| 4913 | pj_pool_factory_Type.tp_new = PyType_GenericNew; |
| 4914 | if (PyType_Ready(&pj_pool_factory_Type) < 0) |
| 4915 | return; |
| 4916 | pjsip_cred_info_Type.tp_new = PyType_GenericNew; |
| 4917 | if (PyType_Ready(&pjsip_cred_info_Type) < 0) |
| 4918 | return; |
| 4919 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 4920 | /* LIB TRANSPORT */ |
| 4921 | |
| 4922 | if (PyType_Ready(&stun_config_Type) < 0) |
| 4923 | return; |
| 4924 | if (PyType_Ready(&transport_config_Type) < 0) |
| 4925 | return; |
| 4926 | if (PyType_Ready(&sockaddr_Type) < 0) |
| 4927 | return; |
| 4928 | if (PyType_Ready(&host_port_Type) < 0) |
| 4929 | return; |
| 4930 | transport_id_Type.tp_new = PyType_GenericNew; |
| 4931 | if (PyType_Ready(&transport_id_Type) < 0) |
| 4932 | return; |
| 4933 | if (PyType_Ready(&transport_info_Type) < 0) |
| 4934 | return; |
| 4935 | integer_Type.tp_new = PyType_GenericNew; |
| 4936 | if (PyType_Ready(&integer_Type) < 0) |
| 4937 | return; |
| 4938 | pjsip_transport_Type.tp_new = PyType_GenericNew; |
| 4939 | if (PyType_Ready(&pjsip_transport_Type) < 0) |
| 4940 | return; |
| 4941 | |
| 4942 | /* END OF LIB TRANSPORT */ |
| 4943 | |
| 4944 | /* LIB ACCOUNT */ |
| 4945 | |
| 4946 | acc_id_Type.tp_new = PyType_GenericNew; |
| 4947 | if (PyType_Ready(&acc_id_Type) < 0) |
| 4948 | return; |
| 4949 | if (PyType_Ready(&acc_config_Type) < 0) |
| 4950 | return; |
| 4951 | if (PyType_Ready(&acc_info_Type) < 0) |
| 4952 | return; |
| 4953 | |
| 4954 | /* END OF LIB ACCOUNT */ |
| 4955 | |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 4956 | m = Py_InitModule3( |
| 4957 | "py_pjsua", py_pjsua_methods,"PJSUA-lib module for python" |
| 4958 | ); |
| 4959 | |
| 4960 | Py_INCREF(&callback_Type); |
| 4961 | PyModule_AddObject(m, "Callback", (PyObject *)&callback_Type); |
| 4962 | |
| 4963 | Py_INCREF(&config_Type); |
| 4964 | PyModule_AddObject(m, "Config", (PyObject *)&config_Type); |
| 4965 | |
| 4966 | Py_INCREF(&media_config_Type); |
| 4967 | PyModule_AddObject(m, "Media_Config", (PyObject *)&media_config_Type); |
| 4968 | |
| 4969 | Py_INCREF(&logging_config_Type); |
| 4970 | PyModule_AddObject(m, "Logging_Config", (PyObject *)&logging_config_Type); |
| 4971 | |
| 4972 | Py_INCREF(&msg_data_Type); |
| 4973 | PyModule_AddObject(m, "Msg_Data", (PyObject *)&msg_data_Type); |
| 4974 | |
| 4975 | Py_INCREF(&pjsip_event_Type); |
| 4976 | PyModule_AddObject(m, "PJSIP_Event", (PyObject *)&pjsip_event_Type); |
| 4977 | |
| 4978 | Py_INCREF(&pjsip_rx_data_Type); |
| 4979 | PyModule_AddObject(m, "PJSIP_RX_Data", (PyObject *)&pjsip_rx_data_Type); |
| 4980 | |
| 4981 | Py_INCREF(&pj_pool_Type); |
| 4982 | PyModule_AddObject(m, "PJ_Pool", (PyObject *)&pj_pool_Type); |
| 4983 | |
| 4984 | Py_INCREF(&pjsip_endpoint_Type); |
| 4985 | PyModule_AddObject(m, "PJSIP_Endpoint", (PyObject *)&pjsip_endpoint_Type); |
| 4986 | |
| 4987 | Py_INCREF(&pjmedia_endpt_Type); |
| 4988 | PyModule_AddObject(m, "PJMedia_Endpt", (PyObject *)&pjmedia_endpt_Type); |
| 4989 | |
| 4990 | Py_INCREF(&pj_pool_factory_Type); |
| 4991 | PyModule_AddObject( |
| 4992 | m, "PJ_Pool_Factory", (PyObject *)&pj_pool_factory_Type |
| 4993 | ); |
| 4994 | |
| 4995 | Py_INCREF(&pjsip_cred_info_Type); |
| 4996 | PyModule_AddObject(m, "PJSIP_Cred_Info", |
| 4997 | (PyObject *)&pjsip_cred_info_Type |
| 4998 | ); |
| 4999 | |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 5000 | /* LIB TRANSPORT */ |
| 5001 | |
| 5002 | Py_INCREF(&stun_config_Type); |
| 5003 | PyModule_AddObject(m, "STUN_Config", (PyObject *)&stun_config_Type); |
| 5004 | Py_INCREF(&transport_config_Type); |
| 5005 | PyModule_AddObject |
| 5006 | (m, "Transport_Config", (PyObject *)&transport_config_Type); |
| 5007 | Py_INCREF(&sockaddr_Type); |
| 5008 | PyModule_AddObject(m, "Sockaddr", (PyObject *)&sockaddr_Type); |
| 5009 | Py_INCREF(&host_port_Type); |
| 5010 | PyModule_AddObject(m, "Host_Port", (PyObject *)&host_port_Type); |
| 5011 | Py_INCREF(&transport_id_Type); |
| 5012 | PyModule_AddObject(m, "Transport_ID", (PyObject *)&transport_id_Type); |
| 5013 | Py_INCREF(&transport_info_Type); |
| 5014 | PyModule_AddObject(m, "Transport_Info", (PyObject *)&transport_info_Type); |
| 5015 | Py_INCREF(&integer_Type); |
| 5016 | PyModule_AddObject(m, "Integer", (PyObject *)&integer_Type); |
| 5017 | Py_INCREF(&pjsip_transport_Type); |
| 5018 | PyModule_AddObject(m, "PJSIP_Transport", (PyObject *)&pjsip_transport_Type); |
| 5019 | |
| 5020 | /* END OF LIB TRANSPORT */ |
| 5021 | |
| 5022 | /* LIB ACCOUNT */ |
| 5023 | |
| 5024 | Py_INCREF(&acc_id_Type); |
| 5025 | PyModule_AddObject(m, "Acc_ID", (PyObject *)&acc_id_Type); |
| 5026 | Py_INCREF(&acc_config_Type); |
| 5027 | PyModule_AddObject(m, "Acc_Config", (PyObject *)&acc_config_Type); |
| 5028 | Py_INCREF(&acc_info_Type); |
| 5029 | PyModule_AddObject(m, "Acc_Info", (PyObject *)&acc_info_Type); |
| 5030 | |
| 5031 | /* END OF LIB ACCOUNT */ |
Benny Prijono | 572d485 | 2006-11-23 21:50:02 +0000 | [diff] [blame] | 5032 | |
| 5033 | #ifdef PJSUA_INVALID_ID |
| 5034 | /* |
| 5035 | * Constant to identify invalid ID for all sorts of IDs. |
| 5036 | */ |
| 5037 | PyModule_AddIntConstant(m, "PJSUA_INVALID_ID", PJSUA_INVALID_ID); |
| 5038 | #endif |
| 5039 | |
| 5040 | #ifdef PJSUA_ACC_MAX_PROXIES |
| 5041 | /* |
| 5042 | * Maximum proxies in account. |
| 5043 | */ |
| 5044 | PyModule_AddIntConstant( |
| 5045 | m, "PJSUA_ACC_MAX_PROXIES ", PJSUA_ACC_MAX_PROXIES |
| 5046 | ); |
| 5047 | #endif |
Benny Prijono | 9879359 | 2006-12-04 08:33:20 +0000 | [diff] [blame] | 5048 | |
| 5049 | #ifdef PJSUA_MAX_ACC |
| 5050 | /* |
| 5051 | * Maximum account. |
| 5052 | */ |
| 5053 | PyModule_AddIntConstant( |
| 5054 | m, "PJSUA_MAX_ACC", PJSUA_MAX_ACC |
| 5055 | ); |
| 5056 | #endif |
| 5057 | |
| 5058 | #ifdef PJSUA_REG_INTERVAL |
| 5059 | /* |
| 5060 | * Default registration interval.. |
| 5061 | */ |
| 5062 | PyModule_AddIntConstant( |
| 5063 | m, "PJSUA_REG_INTERVAL", PJSUA_REG_INTERVAL |
| 5064 | ); |
| 5065 | #endif |
| 5066 | |
| 5067 | #ifdef PJSUA_PUBLISH_EXPIRATION |
| 5068 | /* |
| 5069 | * Default PUBLISH expiration |
| 5070 | */ |
| 5071 | PyModule_AddIntConstant( |
| 5072 | m, "PJSUA_PUBLISH_EXPIRATION", PJSUA_PUBLISH_EXPIRATION |
| 5073 | ); |
| 5074 | #endif |
| 5075 | |
| 5076 | #ifdef PJSUA_DEFAULT_ACC_PRIORITY |
| 5077 | /* |
| 5078 | * Default account priority. |
| 5079 | */ |
| 5080 | PyModule_AddIntConstant( |
| 5081 | m, "PJSUA_DEFAULT_ACC_PRIORITY", PJSUA_DEFAULT_ACC_PRIORITY |
| 5082 | ); |
| 5083 | #endif |
| 5084 | |
Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame] | 5085 | } |