blob: a7d063fbbbb5076ee5e454013834b9ed50ba217d [file] [log] [blame]
Benny Prijono1f63cc42007-09-10 16:54:22 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PY_PJSUA_H__
20#define __PY_PJSUA_H__
21
Benny Prijono6be3c732007-09-19 18:51:39 +000022#define _CRT_SECURE_NO_DEPRECATE
23
Benny Prijono1f63cc42007-09-10 16:54:22 +000024#include <Python.h>
25#include <structmember.h>
26#include <pjsua-lib/pjsua.h>
27
28
29PJ_INLINE(pj_str_t) PyString_to_pj_str(const PyObject *obj)
30{
31 pj_str_t str;
32
Benny Prijonod7ea6052007-09-17 15:44:47 +000033 if (obj) {
34 str.ptr = PyString_AS_STRING(obj);
35 str.slen = PyString_GET_SIZE(obj);
36 } else {
37 str.ptr = NULL;
38 str.slen = 0;
39 }
Benny Prijono1f63cc42007-09-10 16:54:22 +000040
41 return str;
42}
43
44
45//////////////////////////////////////////////////////////////////////////////
46/*
47 * PyObj_pj_pool
48 */
49typedef struct
50{
51 PyObject_HEAD
52 /* Type-specific fields go here. */
53 pj_pool_t * pool;
54} PyObj_pj_pool;
55
56
57/*
58 * PyTyp_pj_pool_t
59 */
60static PyTypeObject PyTyp_pj_pool_t =
61{
62 PyObject_HEAD_INIT(NULL)
63 0, /*ob_size*/
64 "py_pjsua.Pj_Pool", /*tp_name*/
65 sizeof(PyObj_pj_pool), /*tp_basicsize*/
66 0, /*tp_itemsize*/
67 0, /*tp_dealloc*/
68 0, /*tp_print*/
69 0, /*tp_getattr*/
70 0, /*tp_setattr*/
71 0, /*tp_compare*/
72 0, /*tp_repr*/
73 0, /*tp_as_number*/
74 0, /*tp_as_sequence*/
75 0, /*tp_as_mapping*/
76 0, /*tp_hash */
77 0, /*tp_call*/
78 0, /*tp_str*/
79 0, /*tp_getattro*/
80 0, /*tp_setattro*/
81 0, /*tp_as_buffer*/
82 Py_TPFLAGS_DEFAULT, /*tp_flags*/
83 "pj_pool_t objects", /* tp_doc */
84
85};
86
87
88//////////////////////////////////////////////////////////////////////////////
89/*
90 * PyObj_pjsip_endpoint
91 */
92typedef struct
93{
94 PyObject_HEAD
95 /* Type-specific fields go here. */
96 pjsip_endpoint * endpt;
97} PyObj_pjsip_endpoint;
98
99
100/*
101 * PyTyp_pjsip_endpoint
102 */
103static PyTypeObject PyTyp_pjsip_endpoint =
104{
105 PyObject_HEAD_INIT(NULL)
106 0, /*ob_size*/
107 "py_pjsua.Pjsip_Endpoint", /*tp_name*/
108 sizeof(PyObj_pjsip_endpoint),/*tp_basicsize*/
109 0, /*tp_itemsize*/
110 0, /*tp_dealloc*/
111 0, /*tp_print*/
112 0, /*tp_getattr*/
113 0, /*tp_setattr*/
114 0, /*tp_compare*/
115 0, /*tp_repr*/
116 0, /*tp_as_number*/
117 0, /*tp_as_sequence*/
118 0, /*tp_as_mapping*/
119 0, /*tp_hash */
120 0, /*tp_call*/
121 0, /*tp_str*/
122 0, /*tp_getattro*/
123 0, /*tp_setattro*/
124 0, /*tp_as_buffer*/
125 Py_TPFLAGS_DEFAULT, /*tp_flags*/
126 "pjsip_endpoint objects", /* tp_doc */
127};
128
129
130/*
131 * PyObj_pjmedia_endpt
132 */
133typedef struct
134{
135 PyObject_HEAD
136 /* Type-specific fields go here. */
137 pjmedia_endpt * endpt;
138} PyObj_pjmedia_endpt;
139
140
141//////////////////////////////////////////////////////////////////////////////
142/*
143 * PyTyp_pjmedia_endpt
144 */
145static PyTypeObject PyTyp_pjmedia_endpt =
146{
147 PyObject_HEAD_INIT(NULL)
148 0, /*ob_size*/
149 "py_pjsua.Pjmedia_Endpt", /*tp_name*/
150 sizeof(PyObj_pjmedia_endpt), /*tp_basicsize*/
151 0, /*tp_itemsize*/
152 0, /*tp_dealloc*/
153 0, /*tp_print*/
154 0, /*tp_getattr*/
155 0, /*tp_setattr*/
156 0, /*tp_compare*/
157 0, /*tp_repr*/
158 0, /*tp_as_number*/
159 0, /*tp_as_sequence*/
160 0, /*tp_as_mapping*/
161 0, /*tp_hash */
162 0, /*tp_call*/
163 0, /*tp_str*/
164 0, /*tp_getattro*/
165 0, /*tp_setattro*/
166 0, /*tp_as_buffer*/
167 Py_TPFLAGS_DEFAULT, /*tp_flags*/
168 "pjmedia_endpt objects", /* tp_doc */
169
170};
171
172
173//////////////////////////////////////////////////////////////////////////////
174/*
175 * PyObj_pj_pool_factory
176 */
177typedef struct
178{
179 PyObject_HEAD
180 /* Type-specific fields go here. */
181 pj_pool_factory * pool_fact;
182} PyObj_pj_pool_factory;
183
184
185
186/*
187 * PyTyp_pj_pool_factory
188 */
189static PyTypeObject PyTyp_pj_pool_factory =
190{
191 PyObject_HEAD_INIT(NULL)
192 0, /*ob_size*/
193 "py_pjsua.Pj_Pool_Factory",/*tp_name*/
194 sizeof(PyObj_pj_pool_factory), /*tp_basicsize*/
195 0, /*tp_itemsize*/
196 0, /*tp_dealloc*/
197 0, /*tp_print*/
198 0, /*tp_getattr*/
199 0, /*tp_setattr*/
200 0, /*tp_compare*/
201 0, /*tp_repr*/
202 0, /*tp_as_number*/
203 0, /*tp_as_sequence*/
204 0, /*tp_as_mapping*/
205 0, /*tp_hash */
206 0, /*tp_call*/
207 0, /*tp_str*/
208 0, /*tp_getattro*/
209 0, /*tp_setattro*/
210 0, /*tp_as_buffer*/
211 Py_TPFLAGS_DEFAULT, /*tp_flags*/
212 "pj_pool_factory objects", /* tp_doc */
213
214};
215
216
217//////////////////////////////////////////////////////////////////////////////
218/*
219 * PyObj_pjsip_cred_info
220 */
221typedef struct
222{
223 PyObject_HEAD
224
225 /* Type-specific fields go here. */
226 PyObject *realm;
227 PyObject *scheme;
228 PyObject *username;
229 int data_type;
230 PyObject *data;
231
232} PyObj_pjsip_cred_info;
233
234/*
235 * cred_info_dealloc
236 * deletes a cred info from memory
237 */
238static void PyObj_pjsip_cred_info_delete(PyObj_pjsip_cred_info* self)
239{
240 Py_XDECREF(self->realm);
241 Py_XDECREF(self->scheme);
242 Py_XDECREF(self->username);
243 Py_XDECREF(self->data);
244 self->ob_type->tp_free((PyObject*)self);
245}
246
247
248static void PyObj_pjsip_cred_info_import(PyObj_pjsip_cred_info *obj,
249 const pjsip_cred_info *cfg)
250{
251 Py_XDECREF(obj->realm);
252 obj->realm = PyString_FromStringAndSize(cfg->realm.ptr, cfg->realm.slen);
253 Py_XDECREF(obj->scheme);
254 obj->scheme = PyString_FromStringAndSize(cfg->scheme.ptr, cfg->scheme.slen);
255 Py_XDECREF(obj->username);
256 obj->username = PyString_FromStringAndSize(cfg->username.ptr, cfg->username.slen);
257 obj->data_type = cfg->data_type;
258 Py_XDECREF(obj->data);
259 obj->data = PyString_FromStringAndSize(cfg->data.ptr, cfg->data.slen);
260}
261
262static void PyObj_pjsip_cred_info_export(pjsip_cred_info *cfg,
263 PyObj_pjsip_cred_info *obj)
264{
265 cfg->realm = PyString_to_pj_str(obj->realm);
266 cfg->scheme = PyString_to_pj_str(obj->scheme);
267 cfg->username = PyString_to_pj_str(obj->username);
268 cfg->data_type = obj->data_type;
269 cfg->data = PyString_to_pj_str(obj->data);
270}
271
272
273/*
274 * cred_info_new
275 * constructor for cred_info object
276 */
277static PyObject * PyObj_pjsip_cred_info_new(PyTypeObject *type,
278 PyObject *args,
279 PyObject *kwds)
280{
281 PyObj_pjsip_cred_info *self;
282
283 PJ_UNUSED_ARG(args);
284 PJ_UNUSED_ARG(kwds);
285
286 self = (PyObj_pjsip_cred_info *)type->tp_alloc(type, 0);
287 if (self != NULL)
288 {
289 self->realm = PyString_FromString("");
290 if (self->realm == NULL)
291 {
292 Py_DECREF(self);
293 return NULL;
294 }
295 self->scheme = PyString_FromString("");
296 if (self->scheme == NULL)
297 {
298 Py_DECREF(self);
299 return NULL;
300 }
301 self->username = PyString_FromString("");
302 if (self->username == NULL)
303 {
304 Py_DECREF(self);
305 return NULL;
306 }
307 self->data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
308 self->data = PyString_FromString("");
309 if (self->data == NULL)
310 {
311 Py_DECREF(self);
312 return NULL;
313 }
314 }
315
316 return (PyObject *)self;
317}
318
319
320/*
321 * PyObj_pjsip_cred_info_members
322 */
323static PyMemberDef PyObj_pjsip_cred_info_members[] =
324{
325 {
326 "realm", T_OBJECT_EX,
327 offsetof(PyObj_pjsip_cred_info, realm), 0,
328 "Realm"
329 },
330 {
331 "scheme", T_OBJECT_EX,
332 offsetof(PyObj_pjsip_cred_info, scheme), 0,
333 "Scheme"
334 },
335 {
336 "username", T_OBJECT_EX,
337 offsetof(PyObj_pjsip_cred_info, username), 0,
338 "User name"
339 },
340 {
341 "data", T_OBJECT_EX,
342 offsetof(PyObj_pjsip_cred_info, data), 0,
343 "The data, which can be a plaintext password or a hashed digest, "
344 "depending on the value of data_type"
345 },
346 {
347 "data_type", T_INT,
348 offsetof(PyObj_pjsip_cred_info, data_type), 0,
349 "Type of data"
350 },
351
352 {NULL} /* Sentinel */
353};
354
355/*
356 * PyTyp_pjsip_cred_info
357 */
358static PyTypeObject PyTyp_pjsip_cred_info =
359{
360 PyObject_HEAD_INIT(NULL)
361 0, /*ob_size*/
362 "py_pjsua.Pjsip_Cred_Info", /*tp_name*/
363 sizeof(PyObj_pjsip_cred_info), /*tp_basicsize*/
364 0, /*tp_itemsize*/
365 (destructor)PyObj_pjsip_cred_info_delete,/*tp_dealloc*/
366 0, /*tp_print*/
367 0, /*tp_getattr*/
368 0, /*tp_setattr*/
369 0, /*tp_compare*/
370 0, /*tp_repr*/
371 0, /*tp_as_number*/
372 0, /*tp_as_sequence*/
373 0, /*tp_as_mapping*/
374 0, /*tp_hash */
375 0, /*tp_call*/
376 0, /*tp_str*/
377 0, /*tp_getattro*/
378 0, /*tp_setattro*/
379 0, /*tp_as_buffer*/
380 Py_TPFLAGS_DEFAULT, /*tp_flags*/
381 "PJSIP credential information", /* tp_doc */
382 0, /* tp_traverse */
383 0, /* tp_clear */
384 0, /* tp_richcompare */
385 0, /* tp_weaklistoffset */
386 0, /* tp_iter */
387 0, /* tp_iternext */
388 0, /* tp_methods */
389 PyObj_pjsip_cred_info_members, /* tp_members */
390 0, /* tp_getset */
391 0, /* tp_base */
392 0, /* tp_dict */
393 0, /* tp_descr_get */
394 0, /* tp_descr_set */
395 0, /* tp_dictoffset */
396 0, /* tp_init */
397 0, /* tp_alloc */
398 PyObj_pjsip_cred_info_new, /* tp_new */
399
400};
401
402
403//////////////////////////////////////////////////////////////////////////////
404/*
405 * PyObj_pjsip_event
406 * C/python typewrapper for event struct
407 */
408typedef struct
409{
410 PyObject_HEAD
411 /* Type-specific fields go here. */
412 pjsip_event * event;
413} PyObj_pjsip_event;
414
415
416
417/*
418 * PyTyp_pjsip_event
419 * event struct signatures
420 */
421static PyTypeObject PyTyp_pjsip_event =
422{
423 PyObject_HEAD_INIT(NULL)
424 0, /*ob_size*/
425 "py_pjsua.Pjsip_Event", /*tp_name*/
426 sizeof(PyObj_pjsip_event), /*tp_basicsize*/
427 0, /*tp_itemsize*/
428 0, /*tp_dealloc*/
429 0, /*tp_print*/
430 0, /*tp_getattr*/
431 0, /*tp_setattr*/
432 0, /*tp_compare*/
433 0, /*tp_repr*/
434 0, /*tp_as_number*/
435 0, /*tp_as_sequence*/
436 0, /*tp_as_mapping*/
437 0, /*tp_hash */
438 0, /*tp_call*/
439 0, /*tp_str*/
440 0, /*tp_getattro*/
441 0, /*tp_setattro*/
442 0, /*tp_as_buffer*/
443 Py_TPFLAGS_DEFAULT, /*tp_flags*/
444 "pjsip_event object", /*tp_doc */
445};
446
447
448//////////////////////////////////////////////////////////////////////////////
449/*
450 * PyObj_pjsip_rx_data
451 * C/python typewrapper for pjsip_rx_data struct
452 */
453typedef struct
454{
455 PyObject_HEAD
456 /* Type-specific fields go here. */
457 pjsip_rx_data * rdata;
458} PyObj_pjsip_rx_data;
459
460
461/*
462 * PyTyp_pjsip_rx_data
463 */
464static PyTypeObject PyTyp_pjsip_rx_data =
465{
466 PyObject_HEAD_INIT(NULL)
467 0, /*ob_size*/
468 "py_pjsua.Pjsip_Rx_Data", /*tp_name*/
469 sizeof(PyObj_pjsip_rx_data), /*tp_basicsize*/
470 0, /*tp_itemsize*/
471 0, /*tp_dealloc*/
472 0, /*tp_print*/
473 0, /*tp_getattr*/
474 0, /*tp_setattr*/
475 0, /*tp_compare*/
476 0, /*tp_repr*/
477 0, /*tp_as_number*/
478 0, /*tp_as_sequence*/
479 0, /*tp_as_mapping*/
480 0, /*tp_hash */
481 0, /*tp_call*/
482 0, /*tp_str*/
483 0, /*tp_getattro*/
484 0, /*tp_setattro*/
485 0, /*tp_as_buffer*/
486 Py_TPFLAGS_DEFAULT, /*tp_flags*/
487 "pjsip_rx_data object", /*tp_doc*/
488};
489
490
491
492//////////////////////////////////////////////////////////////////////////////
493/*
494 * PyObj_pjsua_callback
495 * C/python typewrapper for callback struct
496 */
497typedef struct PyObj_pjsua_callback
498{
499 PyObject_HEAD
500 /* Type-specific fields go here. */
501 PyObject * on_call_state;
502 PyObject * on_incoming_call;
503 PyObject * on_call_media_state;
504 PyObject * on_dtmf_digit;
505 PyObject * on_call_transfer_request;
506 PyObject * on_call_transfer_status;
507 PyObject * on_call_replace_request;
508 PyObject * on_call_replaced;
509 PyObject * on_reg_state;
510 PyObject * on_buddy_state;
511 PyObject * on_pager;
512 PyObject * on_pager_status;
513 PyObject * on_typing;
514} PyObj_pjsua_callback;
515
516
517/*
518 * PyObj_pjsua_callback_delete
519 * destructor function for callback struct
520 */
521static void PyObj_pjsua_callback_delete(PyObj_pjsua_callback* self)
522{
523 Py_XDECREF(self->on_call_state);
524 Py_XDECREF(self->on_incoming_call);
525 Py_XDECREF(self->on_call_media_state);
526 Py_XDECREF(self->on_dtmf_digit);
527 Py_XDECREF(self->on_call_transfer_request);
528 Py_XDECREF(self->on_call_transfer_status);
529 Py_XDECREF(self->on_call_replace_request);
530 Py_XDECREF(self->on_call_replaced);
531 Py_XDECREF(self->on_reg_state);
532 Py_XDECREF(self->on_buddy_state);
533 Py_XDECREF(self->on_pager);
534 Py_XDECREF(self->on_pager_status);
535 Py_XDECREF(self->on_typing);
536 self->ob_type->tp_free((PyObject*)self);
537}
538
539
540/*
541 * PyObj_pjsua_callback_new
542 * * declares constructor for callback struct
543 */
544static PyObject * PyObj_pjsua_callback_new(PyTypeObject *type,
545 PyObject *args,
546 PyObject *kwds)
547{
548 PyObj_pjsua_callback *self;
549
550 PJ_UNUSED_ARG(args);
551 PJ_UNUSED_ARG(kwds);
552
553 self = (PyObj_pjsua_callback *)type->tp_alloc(type, 0);
554 if (self != NULL)
555 {
556 Py_INCREF(Py_None);
557 self->on_call_state = Py_None;
558 if (self->on_call_state == NULL)
559 {
560 Py_DECREF(Py_None);
561 return NULL;
562 }
563 Py_INCREF(Py_None);
564 self->on_incoming_call = Py_None;
565 if (self->on_incoming_call == NULL)
566 {
567 Py_DECREF(Py_None);
568 return NULL;
569 }
570 Py_INCREF(Py_None);
571 self->on_call_media_state = Py_None;
572 if (self->on_call_media_state == NULL)
573 {
574 Py_DECREF(Py_None);
575 return NULL;
576 }
577 Py_INCREF(Py_None);
578 self->on_dtmf_digit = Py_None;
579 if (self->on_dtmf_digit == NULL)
580 {
581 Py_DECREF(Py_None);
582 return NULL;
583 }
584 Py_INCREF(Py_None);
585 self->on_call_transfer_request = Py_None;
586 if (self->on_call_transfer_request == NULL)
587 {
588 Py_DECREF(Py_None);
589 return NULL;
590 }
591 Py_INCREF(Py_None);
592 self->on_call_transfer_status = Py_None;
593 if (self->on_call_transfer_status == NULL)
594 {
595 Py_DECREF(Py_None);
596 return NULL;
597 }
598 Py_INCREF(Py_None);
599 self->on_call_replace_request = Py_None;
600 if (self->on_call_replace_request == NULL)
601 {
602 Py_DECREF(Py_None);
603 return NULL;
604 }
605 Py_INCREF(Py_None);
606 self->on_call_replaced = Py_None;
607 if (self->on_call_replaced == NULL)
608 {
609 Py_DECREF(Py_None);
610 return NULL;
611 }
612 Py_INCREF(Py_None);
613 self->on_reg_state = Py_None;
614 if (self->on_reg_state == NULL)
615 {
616 Py_DECREF(Py_None);
617 return NULL;
618 }
619 Py_INCREF(Py_None);
620 self->on_buddy_state = Py_None;
621 if (self->on_buddy_state == NULL)
622 {
623 Py_DECREF(Py_None);
624 return NULL;
625 }
626 Py_INCREF(Py_None);
627 self->on_pager = Py_None;
628 if (self->on_pager == NULL)
629 {
630 Py_DECREF(Py_None);
631 return NULL;
632 }
633 Py_INCREF(Py_None);
634 self->on_pager_status = Py_None;
635 if (self->on_pager_status == NULL)
636 {
637 Py_DECREF(Py_None);
638 return NULL;
639 }
640 Py_INCREF(Py_None);
641 self->on_typing = Py_None;
642 if (self->on_typing == NULL)
643 {
644 Py_DECREF(Py_None);
645 return NULL;
646 }
647 }
648
649 return (PyObject *)self;
650}
651
652
653/*
654 * PyObj_pjsua_callback_members
655 * declares available functions for callback object
656 */
657static PyMemberDef PyObj_pjsua_callback_members[] =
658{
659 {
660 "on_call_state", T_OBJECT_EX,
661 offsetof(PyObj_pjsua_callback, on_call_state), 0,
662 "Notify application when invite state has changed. Application may "
663 "then query the call info to get the detail call states."
664 },
665 {
666 "on_incoming_call", T_OBJECT_EX,
667 offsetof(PyObj_pjsua_callback, on_incoming_call), 0,
668 "Notify application on incoming call."
669 },
670 {
671 "on_call_media_state", T_OBJECT_EX,
672 offsetof(PyObj_pjsua_callback, on_call_media_state), 0,
673 "Notify application when media state in the call has changed. Normal "
674 "application would need to implement this callback, e.g. to connect "
675 "the call's media to sound device."
676 },
677 {
678 "on_dtmf_digit", T_OBJECT_EX,
679 offsetof(PyObj_pjsua_callback, on_dtmf_digit), 0,
680 "Notify application upon receiving incoming DTMF digit."
681 },
682 {
683 "on_call_transfer_request", T_OBJECT_EX,
684 offsetof(PyObj_pjsua_callback, on_call_transfer_request), 0,
685 "Notify application on call being transfered. "
686 "Application can decide to accept/reject transfer request "
687 "by setting the code (default is 200). When this callback "
688 "is not defined, the default behavior is to accept the "
689 "transfer."
690 },
691 {
692 "on_call_transfer_status", T_OBJECT_EX,
693 offsetof(PyObj_pjsua_callback, on_call_transfer_status), 0,
694 "Notify application of the status of previously sent call "
695 "transfer request. Application can monitor the status of the "
696 "call transfer request, for example to decide whether to "
697 "terminate existing call."
698 },
699 {
700 "on_call_replace_request", T_OBJECT_EX,
701 offsetof(PyObj_pjsua_callback, on_call_replace_request), 0,
702 "Notify application about incoming INVITE with Replaces header. "
703 "Application may reject the request by setting non-2xx code."
704 },
705 {
706 "on_call_replaced", T_OBJECT_EX,
707 offsetof(PyObj_pjsua_callback, on_call_replaced), 0,
708 "Notify application that an existing call has been replaced with "
709 "a new call. This happens when PJSUA-API receives incoming INVITE "
710 "request with Replaces header."
711 " "
712 "After this callback is called, normally PJSUA-API will disconnect "
713 "old_call_id and establish new_call_id."
714 },
715 {
716 "on_reg_state", T_OBJECT_EX,
717 offsetof(PyObj_pjsua_callback, on_reg_state), 0,
718 "Notify application when registration status has changed. Application "
719 "may then query the account info to get the registration details."
720 },
721 {
722 "on_buddy_state", T_OBJECT_EX,
723 offsetof(PyObj_pjsua_callback, on_buddy_state), 0,
724 "Notify application when the buddy state has changed. Application may "
725 "then query the buddy into to get the details."
726 },
727 {
728 "on_pager", T_OBJECT_EX,
729 offsetof(PyObj_pjsua_callback, on_pager), 0,
730 "Notify application on incoming pager (i.e. MESSAGE request). "
731 "Argument call_id will be -1 if MESSAGE request is not related to an "
732 "existing call."
733 },
734 {
735 "on_pager_status", T_OBJECT_EX,
736 offsetof(PyObj_pjsua_callback, on_pager_status), 0,
737 "Notify application about the delivery status of outgoing pager "
738 "request."
739 },
740 {
741 "on_typing", T_OBJECT_EX,
742 offsetof(PyObj_pjsua_callback, on_typing), 0,
743 "Notify application about typing indication."
744 },
745 {NULL} /* Sentinel */
746};
747
748
749/*
750 * PyTyp_pjsua_callback
751 * callback class definition
752 */
753static PyTypeObject PyTyp_pjsua_callback =
754{
755 PyObject_HEAD_INIT(NULL)
756 0, /*ob_size*/
757 "py_pjsua.Callback", /*tp_name*/
758 sizeof(PyObj_pjsua_callback), /*tp_basicsize*/
759 0, /*tp_itemsize*/
760 (destructor)PyObj_pjsua_callback_delete, /*tp_dealloc*/
761 0, /*tp_print*/
762 0, /*tp_getattr*/
763 0, /*tp_setattr*/
764 0, /*tp_compare*/
765 0, /*tp_repr*/
766 0, /*tp_as_number*/
767 0, /*tp_as_sequence*/
768 0, /*tp_as_mapping*/
769 0, /*tp_hash */
770 0, /*tp_call*/
771 0, /*tp_str*/
772 0, /*tp_getattro*/
773 0, /*tp_setattro*/
774 0, /*tp_as_buffer*/
775 Py_TPFLAGS_DEFAULT, /*tp_flags*/
776 "This structure describes application callback "
777 "to receive various event notifications from "
778 "PJSUA-API", /* tp_doc */
779 0, /* tp_traverse */
780 0, /* tp_clear */
781 0, /* tp_richcompare */
782 0, /* tp_weaklistoffset */
783 0, /* tp_iter */
784 0, /* tp_iternext */
785 0, /* tp_methods */
786 PyObj_pjsua_callback_members, /* tp_members */
787 0, /* tp_getset */
788 0, /* tp_base */
789 0, /* tp_dict */
790 0, /* tp_descr_get */
791 0, /* tp_descr_set */
792 0, /* tp_dictoffset */
793 0, /* tp_init */
794 0, /* tp_alloc */
795 PyObj_pjsua_callback_new, /* tp_new */
796
797};
798
799
800//////////////////////////////////////////////////////////////////////////////
801/*
802 * PyObj_pjsua_media_config
803 * C/Python wrapper for pjsua_media_config object
804 */
805typedef struct
806{
807 PyObject_HEAD
808 /* Type-specific fields go here. */
809 unsigned clock_rate;
810 unsigned max_media_ports;
811 int has_ioqueue;
812 unsigned thread_cnt;
813 unsigned quality;
814 unsigned ptime;
815 int no_vad;
816 unsigned ilbc_mode;
817 unsigned tx_drop_pct;
818 unsigned rx_drop_pct;
819 unsigned ec_options;
820 unsigned ec_tail_len;
821} PyObj_pjsua_media_config;
822
823
824/*
825 * PyObj_pjsua_media_config_members
826 * declares attributes accessible from both C and Python for media_config file
827 */
828static PyMemberDef PyObj_pjsua_media_config_members[] =
829{
830 {
831 "clock_rate", T_INT,
832 offsetof(PyObj_pjsua_media_config, clock_rate), 0,
833 "Clock rate to be applied to the conference bridge. If value is zero, "
834 "default clock rate will be used (16KHz)."
835 },
836 {
837 "max_media_ports", T_INT,
838 offsetof(PyObj_pjsua_media_config, max_media_ports), 0,
839 "Specify maximum number of media ports to be created in the "
840 "conference bridge. Since all media terminate in the bridge (calls, "
841 "file player, file recorder, etc), the value must be large enough to "
842 "support all of them. However, the larger the value, the more "
843 "computations are performed."
844 },
845 {
846 "has_ioqueue", T_INT,
847 offsetof(PyObj_pjsua_media_config, has_ioqueue), 0,
848 "Specify whether the media manager should manage its own ioqueue for "
849 "the RTP/RTCP sockets. If yes, ioqueue will be created and at least "
850 "one worker thread will be created too. If no, the RTP/RTCP sockets "
851 "will share the same ioqueue as SIP sockets, and no worker thread is "
852 "needed."
853 },
854 {
855 "thread_cnt", T_INT,
856 offsetof(PyObj_pjsua_media_config, thread_cnt), 0,
857 "Specify the number of worker threads to handle incoming RTP packets. "
858 "A value of one is recommended for most applications."
859 },
860 {
861 "quality", T_INT,
862 offsetof(PyObj_pjsua_media_config, quality), 0,
863 "The media quality also sets speex codec quality/complexity to the "
864 "number."
865 },
866 {
867 "ptime", T_INT,
868 offsetof(PyObj_pjsua_media_config, ptime), 0,
869 "Specify default ptime."
870 },
871 {
872 "no_vad", T_INT,
873 offsetof(PyObj_pjsua_media_config, no_vad), 0,
874 "Disable VAD?"
875 },
876 {
877 "ilbc_mode", T_INT,
878 offsetof(PyObj_pjsua_media_config, ilbc_mode), 0,
879 "iLBC mode (20 or 30)."
880 },
881 {
882 "tx_drop_pct", T_INT,
883 offsetof(PyObj_pjsua_media_config, tx_drop_pct), 0,
884 "Percentage of RTP packet to drop in TX direction (to simulate packet "
885 "lost)."
886 },
887 {
888 "rx_drop_pct", T_INT,
889 offsetof(PyObj_pjsua_media_config, rx_drop_pct), 0,
890 "Percentage of RTP packet to drop in RX direction (to simulate packet "
891 "lost)."},
892 {
893 "ec_options", T_INT,
894 offsetof(PyObj_pjsua_media_config, ec_options), 0,
895 "Echo canceller options (see pjmedia_echo_create())"
896 },
897 {
898 "ec_tail_len", T_INT,
899 offsetof(PyObj_pjsua_media_config, ec_tail_len), 0,
900 "Echo canceller tail length, in miliseconds."
901 },
902 {NULL} /* Sentinel */
903};
904
905
906/*
907 * PyTyp_pjsua_media_config
908 */
909static PyTypeObject PyTyp_pjsua_media_config =
910{
911 PyObject_HEAD_INIT(NULL)
912 0, /*ob_size*/
913 "py_pjsua.Media_Config", /*tp_name*/
914 sizeof(PyObj_pjsua_media_config),/*tp_basicsize*/
915 0, /*tp_itemsize*/
916 0, /*tp_dealloc*/
917 0, /*tp_print*/
918 0, /*tp_getattr*/
919 0, /*tp_setattr*/
920 0, /*tp_compare*/
921 0, /*tp_repr*/
922 0, /*tp_as_number*/
923 0, /*tp_as_sequence*/
924 0, /*tp_as_mapping*/
925 0, /*tp_hash */
926 0, /*tp_call*/
927 0, /*tp_str*/
928 0, /*tp_getattro*/
929 0, /*tp_setattro*/
930 0, /*tp_as_buffer*/
931 Py_TPFLAGS_DEFAULT, /*tp_flags*/
932 "Media Config objects", /*tp_doc*/
933 0, /*tp_traverse*/
934 0, /*tp_clear*/
935 0, /*tp_richcompare*/
936 0, /* tp_weaklistoffset */
937 0, /* tp_iter */
938 0, /* tp_iternext */
939 0, /* tp_methods */
940 PyObj_pjsua_media_config_members, /* tp_members */
941
942};
943
944
945static void PyObj_pjsua_media_config_import(PyObj_pjsua_media_config *obj,
946 const pjsua_media_config *cfg)
947{
948 obj->clock_rate = cfg->clock_rate;
949 obj->max_media_ports = cfg->max_media_ports;
950 obj->has_ioqueue = cfg->has_ioqueue;
951 obj->thread_cnt = cfg->thread_cnt;
952 obj->quality = cfg->quality;
953 obj->ptime = cfg->ptime;
954 obj->no_vad = cfg->no_vad;
955 obj->ilbc_mode = cfg->ilbc_mode;
956 obj->tx_drop_pct = cfg->tx_drop_pct;
957 obj->rx_drop_pct = cfg->rx_drop_pct;
958 obj->ec_options = cfg->ec_options;
959 obj->ec_tail_len = cfg->ec_tail_len;
960}
961
962static void PyObj_pjsua_media_config_export(pjsua_media_config *cfg,
963 const PyObj_pjsua_media_config *obj)
964{
965 cfg->clock_rate = obj->clock_rate;
966 cfg->max_media_ports = obj->max_media_ports;
967 cfg->has_ioqueue = obj->has_ioqueue;
968 cfg->thread_cnt = obj->thread_cnt;
969 cfg->quality = obj->quality;
970 cfg->ptime = obj->ptime;
971 cfg->no_vad = obj->no_vad;
972 cfg->ilbc_mode = obj->ilbc_mode;
973 cfg->tx_drop_pct = obj->tx_drop_pct;
974 cfg->rx_drop_pct = obj->rx_drop_pct;
975 cfg->ec_options = obj->ec_options;
976 cfg->ec_tail_len = obj->ec_tail_len;
977}
978
979//////////////////////////////////////////////////////////////////////////////
980/*
981 * PyObj_pjsua_config
982 * attribute list for config object
983 */
984typedef struct
985{
986 PyObject_HEAD
987 /* Type-specific fields go here. */
988 unsigned max_calls;
989 unsigned thread_cnt;
990 PyObject *outbound_proxy;
991 PyObject *stun_domain;
992 PyObject *stun_host;
993 PyObject *stun_relay_host;
994 PyObj_pjsua_callback *cb;
995 PyObject *user_agent;
996} PyObj_pjsua_config;
997
998
999static void PyObj_pjsua_config_delete(PyObj_pjsua_config* self)
1000{
1001 Py_XDECREF(self->outbound_proxy);
1002 Py_XDECREF(self->stun_domain);
1003 Py_XDECREF(self->stun_host);
1004 Py_XDECREF(self->stun_relay_host);
1005 Py_XDECREF(self->cb);
1006 Py_XDECREF(self->user_agent);
1007 self->ob_type->tp_free((PyObject*)self);
1008}
1009
1010
1011static void PyObj_pjsua_config_import(PyObj_pjsua_config *obj,
1012 const pjsua_config *cfg)
1013{
1014 obj->max_calls = cfg->max_calls;
1015 obj->thread_cnt = cfg->thread_cnt;
1016 Py_XDECREF(obj->outbound_proxy);
1017 obj->outbound_proxy = PyString_FromStringAndSize(cfg->outbound_proxy[0].ptr,
1018 cfg->outbound_proxy[0].slen);
1019 Py_XDECREF(obj->stun_domain);
1020 obj->stun_domain = PyString_FromStringAndSize(cfg->stun_domain.ptr,
1021 cfg->stun_domain.slen);
1022 Py_XDECREF(obj->stun_host);
1023 obj->stun_host = PyString_FromStringAndSize(cfg->stun_host.ptr,
1024 cfg->stun_host.slen);
1025 Py_XDECREF(obj->stun_relay_host);
Benny Prijono3eb16d72008-06-12 22:45:26 +00001026 obj->stun_relay_host= PyString_FromStringAndSize(cfg->stun_host.ptr,
1027 cfg->stun_host.slen);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001028 Py_XDECREF(obj->user_agent);
1029 obj->user_agent = PyString_FromStringAndSize(cfg->user_agent.ptr,
1030 cfg->user_agent.slen);
1031}
1032
1033
1034static void PyObj_pjsua_config_export(pjsua_config *cfg,
1035 PyObj_pjsua_config *obj)
1036{
1037 cfg->max_calls = obj->max_calls;
1038 cfg->thread_cnt = obj->thread_cnt;
1039 if (PyString_Size(obj->outbound_proxy) > 0) {
1040 cfg->outbound_proxy_cnt = 1;
1041 cfg->outbound_proxy[0] = PyString_to_pj_str(obj->outbound_proxy);
1042 } else {
1043 cfg->outbound_proxy_cnt = 0;
1044 }
1045 cfg->stun_domain = PyString_to_pj_str(obj->stun_domain);
1046 cfg->stun_host = PyString_to_pj_str(obj->stun_host);
Benny Prijono3eb16d72008-06-12 22:45:26 +00001047 //cfg->stun_relay_host= PyString_to_pj_str(obj->stun_host);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001048 cfg->user_agent = PyString_to_pj_str(obj->user_agent);
1049
1050}
1051
1052
1053static PyObject *PyObj_pjsua_config_new(PyTypeObject *type,
1054 PyObject *args,
1055 PyObject *kwds)
1056{
1057 PyObj_pjsua_config *self;
1058
1059 PJ_UNUSED_ARG(args);
1060 PJ_UNUSED_ARG(kwds);
1061
1062 self = (PyObj_pjsua_config *)type->tp_alloc(type, 0);
1063 if (self != NULL)
1064 {
1065 self->user_agent = PyString_FromString("");
1066 if (self->user_agent == NULL)
1067 {
1068 Py_DECREF(self);
1069 return NULL;
1070 }
1071 self->outbound_proxy = PyString_FromString("");
1072 if (self->outbound_proxy == NULL)
1073 {
1074 Py_DECREF(self);
1075 return NULL;
1076 }
1077 self->cb = (PyObj_pjsua_callback *)
1078 PyType_GenericNew(&PyTyp_pjsua_callback, NULL, NULL);
1079 if (self->cb == NULL)
1080 {
1081 Py_DECREF(Py_None);
1082 return NULL;
1083 }
1084 }
1085 return (PyObject *)self;
1086}
1087
1088
1089/*
1090 * PyObj_pjsua_config_members
1091 * attribute list accessible from Python/C
1092 */
1093static PyMemberDef PyObj_pjsua_config_members[] =
1094{
1095 {
1096 "max_calls", T_INT,
1097 offsetof(PyObj_pjsua_config, max_calls), 0,
1098 "Maximum calls to support (default: 4) "
1099 },
1100 {
1101 "thread_cnt", T_INT,
1102 offsetof(PyObj_pjsua_config, thread_cnt), 0,
1103 "Number of worker threads. Normally application will want to have at "
1104 "least one worker thread, unless when it wants to poll the library "
1105 "periodically, which in this case the worker thread can be set to "
1106 "zero."
1107 },
1108 {
1109 "outbound_proxy", T_OBJECT_EX,
1110 offsetof(PyObj_pjsua_config, outbound_proxy), 0,
1111 "SIP URL of the outbound proxy (optional)"
1112 },
1113 {
1114 "stun_domain", T_OBJECT_EX,
1115 offsetof(PyObj_pjsua_config, stun_domain), 0,
1116 "Domain of the STUN server (optional). STUN server will be resolved "
1117 "using DNS SRV resolution only when nameserver is configured. "
1118 "Alternatively, if DNS SRV resolution for STUN is not desired, "
1119 "application can specify the STUN server hostname or IP address "
1120 "in stun_host attribute."
1121 },
1122 {
1123 "stun_host", T_OBJECT_EX,
1124 offsetof(PyObj_pjsua_config, stun_host), 0,
1125 "Hostname or IP address of the STUN server (optional)."
1126 },
1127 {
1128 "stun_relay_host", T_OBJECT_EX,
1129 offsetof(PyObj_pjsua_config, stun_relay_host), 0,
1130 "Hostname or IP address of the TURN server (optional)."
1131 },
1132 {
1133 "cb", T_OBJECT_EX, offsetof(PyObj_pjsua_config, cb), 0,
1134 "Application callback."
1135 },
1136 {
1137 "user_agent", T_OBJECT_EX, offsetof(PyObj_pjsua_config, user_agent), 0,
1138 "User agent string (default empty)"
1139 },
1140 {NULL} /* Sentinel */
1141};
1142
1143
1144/*
1145 * PyTyp_pjsua_config
1146 * type wrapper for config class
1147 */
1148static PyTypeObject PyTyp_pjsua_config =
1149{
1150 PyObject_HEAD_INIT(NULL)
1151 0, /*ob_size*/
1152 "py_pjsua.Config", /*tp_name*/
1153 sizeof(PyObj_pjsua_config),/*tp_basicsize*/
1154 0, /*tp_itemsize*/
1155 (destructor)PyObj_pjsua_config_delete,/*tp_dealloc*/
1156 0, /*tp_print*/
1157 0, /*tp_getattr*/
1158 0, /*tp_setattr*/
1159 0, /*tp_compare*/
1160 0, /*tp_repr*/
1161 0, /*tp_as_number*/
1162 0, /*tp_as_sequence*/
1163 0, /*tp_as_mapping*/
1164 0, /*tp_hash */
1165 0, /*tp_call*/
1166 0, /*tp_str*/
1167 0, /*tp_getattro*/
1168 0, /*tp_setattro*/
1169 0, /*tp_as_buffer*/
1170 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1171 "Config object", /* tp_doc */
1172 0, /* tp_traverse */
1173 0, /* tp_clear */
1174 0, /* tp_richcompare */
1175 0, /* tp_weaklistoffset */
1176 0, /* tp_iter */
1177 0, /* tp_iternext */
1178 0, /* tp_methods */
1179 PyObj_pjsua_config_members,/* tp_members */
1180 0, /* tp_getset */
1181 0, /* tp_base */
1182 0, /* tp_dict */
1183 0, /* tp_descr_get */
1184 0, /* tp_descr_set */
1185 0, /* tp_dictoffset */
1186 0, /* tp_init */
1187 0, /* tp_alloc */
1188 PyObj_pjsua_config_new, /* tp_new */
1189
1190};
1191
1192//////////////////////////////////////////////////////////////////////////////
1193/*
1194 * PyObj_pjsua_logging_config
1195 * configuration class for logging_config object
1196 */
1197typedef struct
1198{
1199 PyObject_HEAD
1200 /* Type-specific fields go here. */
1201 int msg_logging;
1202 unsigned level;
1203 unsigned console_level;
1204 unsigned decor;
1205 PyObject *log_filename;
1206 PyObject *cb;
1207} PyObj_pjsua_logging_config;
1208
1209
1210/*
1211 * PyObj_pjsua_logging_config_delete
1212 * deletes a logging config from memory
1213 */
1214static void PyObj_pjsua_logging_config_delete(PyObj_pjsua_logging_config* self)
1215{
1216 Py_XDECREF(self->log_filename);
1217 Py_XDECREF(self->cb);
1218 self->ob_type->tp_free((PyObject*)self);
1219}
1220
1221
1222static void PyObj_pjsua_logging_config_import(PyObj_pjsua_logging_config *obj,
1223 const pjsua_logging_config *cfg)
1224{
1225 obj->msg_logging = cfg->msg_logging;
1226 obj->level = cfg->level;
1227 obj->console_level = cfg->console_level;
1228 obj->decor = cfg->decor;
1229}
1230
1231static void PyObj_pjsua_logging_config_export(pjsua_logging_config *cfg,
1232 PyObj_pjsua_logging_config *obj)
1233{
1234 cfg->msg_logging = obj->msg_logging;
1235 cfg->level = obj->level;
1236 cfg->console_level = obj->console_level;
1237 cfg->decor = obj->decor;
1238 cfg->log_filename = PyString_to_pj_str(obj->log_filename);
1239}
1240
1241
1242/*
1243 * PyObj_pjsua_logging_config_new
1244 * constructor for logging_config object
1245 */
1246static PyObject * PyObj_pjsua_logging_config_new(PyTypeObject *type,
1247 PyObject *args,
1248 PyObject *kwds)
1249{
1250 PyObj_pjsua_logging_config *self;
1251
1252 PJ_UNUSED_ARG(args);
1253 PJ_UNUSED_ARG(kwds);
1254
1255 self = (PyObj_pjsua_logging_config *)type->tp_alloc(type, 0);
1256 if (self != NULL)
1257 {
1258 self->log_filename = PyString_FromString("");
1259 if (self->log_filename == NULL)
1260 {
1261 Py_DECREF(self);
1262 return NULL;
1263 }
1264 Py_INCREF(Py_None);
1265 self->cb = Py_None;
1266 if (self->cb == NULL)
1267 {
1268 Py_DECREF(Py_None);
1269 return NULL;
1270 }
1271 }
1272
1273 return (PyObject *)self;
1274}
1275
1276
1277/*
1278 * PyObj_pjsua_logging_config_members
1279 */
1280static PyMemberDef PyObj_pjsua_logging_config_members[] =
1281{
1282 {
1283 "msg_logging", T_INT,
1284 offsetof(PyObj_pjsua_logging_config, msg_logging), 0,
1285 "Log incoming and outgoing SIP message? Yes!"
1286 },
1287 {
1288 "level", T_INT,
1289 offsetof(PyObj_pjsua_logging_config, level), 0,
1290 "Input verbosity level. Value 5 is reasonable."
1291 },
1292 {
1293 "console_level", T_INT,
1294 offsetof(PyObj_pjsua_logging_config, console_level),
1295 0, "Verbosity level for console. Value 4 is reasonable."
1296 },
1297 {
1298 "decor", T_INT,
1299 offsetof(PyObj_pjsua_logging_config, decor), 0,
1300 "Log decoration"
1301 },
1302 {
1303 "log_filename", T_OBJECT_EX,
1304 offsetof(PyObj_pjsua_logging_config, log_filename), 0,
1305 "Optional log filename"
1306 },
1307 {
1308 "cb", T_OBJECT_EX,
1309 offsetof(PyObj_pjsua_logging_config, cb), 0,
1310 "Optional callback function to be called to write log to application "
1311 "specific device. This function will be called forlog messages on "
1312 "input verbosity level."
1313 },
1314 {NULL} /* Sentinel */
1315};
1316
1317
1318
1319
1320/*
1321 * PyTyp_pjsua_logging_config
1322 */
1323static PyTypeObject PyTyp_pjsua_logging_config =
1324{
1325 PyObject_HEAD_INIT(NULL)
1326 0, /*ob_size*/
1327 "py_pjsua.Logging_Config", /*tp_name*/
1328 sizeof(PyObj_pjsua_logging_config), /*tp_basicsize*/
1329 0, /*tp_itemsize*/
1330 (destructor)PyObj_pjsua_logging_config_delete,/*tp_dealloc*/
1331 0, /*tp_print*/
1332 0, /*tp_getattr*/
1333 0, /*tp_setattr*/
1334 0, /*tp_compare*/
1335 0, /*tp_repr*/
1336 0, /*tp_as_number*/
1337 0, /*tp_as_sequence*/
1338 0, /*tp_as_mapping*/
1339 0, /*tp_hash */
1340 0, /*tp_call*/
1341 0, /*tp_str*/
1342 0, /*tp_getattro*/
1343 0, /*tp_setattro*/
1344 0, /*tp_as_buffer*/
1345 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1346 "Logging Config objects", /* tp_doc */
1347 0, /* tp_traverse */
1348 0, /* tp_clear */
1349 0, /* tp_richcompare */
1350 0, /* tp_weaklistoffset */
1351 0, /* tp_iter */
1352 0, /* tp_iternext */
1353 0, /* tp_methods */
1354 PyObj_pjsua_logging_config_members,/* tp_members */
1355 0, /* tp_getset */
1356 0, /* tp_base */
1357 0, /* tp_dict */
1358 0, /* tp_descr_get */
1359 0, /* tp_descr_set */
1360 0, /* tp_dictoffset */
1361 0, /* tp_init */
1362 0, /* tp_alloc */
1363 PyObj_pjsua_logging_config_new, /* tp_new */
1364
1365};
1366
1367
1368//////////////////////////////////////////////////////////////////////////////
1369/*
1370 * PyObj_pjsua_msg_data
1371 * typewrapper for MessageData class
1372 * !modified @ 061206
1373 */
1374typedef struct
1375{
1376 PyObject_HEAD
1377 /* Type-specific fields go here. */
1378 PyObject * hdr_list;
1379 PyObject * content_type;
1380 PyObject * msg_body;
1381} PyObj_pjsua_msg_data;
1382
1383
1384/*
1385 * PyObj_pjsua_msg_data_delete
1386 * deletes a msg_data
1387 * !modified @ 061206
1388 */
1389static void PyObj_pjsua_msg_data_delete(PyObj_pjsua_msg_data* self)
1390{
1391 Py_XDECREF(self->hdr_list);
1392 Py_XDECREF(self->content_type);
1393 Py_XDECREF(self->msg_body);
1394 self->ob_type->tp_free((PyObject*)self);
1395}
1396
1397
1398/*
1399 * PyObj_pjsua_msg_data_new
1400 * constructor for msg_data object
1401 * !modified @ 061206
1402 */
1403static PyObject * PyObj_pjsua_msg_data_new(PyTypeObject *type,
1404 PyObject *args,
1405 PyObject *kwds)
1406{
1407 PyObj_pjsua_msg_data *self;
1408
1409 PJ_UNUSED_ARG(args);
1410 PJ_UNUSED_ARG(kwds);
1411
1412 self = (PyObj_pjsua_msg_data *)type->tp_alloc(type, 0);
1413 if (self != NULL)
1414 {
1415 Py_INCREF(Py_None);
1416 self->hdr_list = Py_None;
1417 if (self->hdr_list == NULL) {
1418 Py_DECREF(self);
1419 return NULL;
1420 }
1421 self->content_type = PyString_FromString("");
1422 if (self->content_type == NULL) {
1423 Py_DECREF(self);
1424 return NULL;
1425 }
1426 self->msg_body = PyString_FromString("");
1427 if (self->msg_body == NULL) {
1428 Py_DECREF(self);
1429 return NULL;
1430 }
1431 }
1432
1433 return (PyObject *)self;
1434}
1435
1436
1437/*
1438 * PyObj_pjsua_msg_data_members
1439 * !modified @ 061206
1440 */
1441static PyMemberDef PyObj_pjsua_msg_data_members[] =
1442{
1443 {
1444 "hdr_list", T_OBJECT_EX,
1445 offsetof(PyObj_pjsua_msg_data, hdr_list), 0,
1446 "Additional message headers as linked list of strings."
1447 },
1448 {
1449 "content_type", T_OBJECT_EX,
1450 offsetof(PyObj_pjsua_msg_data, content_type), 0,
1451 "MIME type of optional message body."
1452 },
1453 {
1454 "msg_body", T_OBJECT_EX,
1455 offsetof(PyObj_pjsua_msg_data, msg_body), 0,
1456 "Optional message body."
1457 },
1458 {NULL} /* Sentinel */
1459};
1460
1461
1462/*
1463 * PyTyp_pjsua_msg_data
1464 */
1465static PyTypeObject PyTyp_pjsua_msg_data =
1466{
1467 PyObject_HEAD_INIT(NULL)
1468 0, /*ob_size*/
1469 "py_pjsua.Msg_Data", /*tp_name*/
1470 sizeof(PyObj_pjsua_msg_data), /*tp_basicsize*/
1471 0, /*tp_itemsize*/
1472 (destructor)PyObj_pjsua_msg_data_delete,/*tp_dealloc*/
1473 0, /*tp_print*/
1474 0, /*tp_getattr*/
1475 0, /*tp_setattr*/
1476 0, /*tp_compare*/
1477 0, /*tp_repr*/
1478 0, /*tp_as_number*/
1479 0, /*tp_as_sequence*/
1480 0, /*tp_as_mapping*/
1481 0, /*tp_hash */
1482 0, /*tp_call*/
1483 0, /*tp_str*/
1484 0, /*tp_getattro*/
1485 0, /*tp_setattro*/
1486 0, /*tp_as_buffer*/
1487 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1488 "msg_data objects", /* tp_doc */
1489 0, /* tp_traverse */
1490 0, /* tp_clear */
1491 0, /* tp_richcompare */
1492 0, /* tp_weaklistoffset */
1493 0, /* tp_iter */
1494 0, /* tp_iternext */
1495 0, /* tp_methods */
1496 PyObj_pjsua_msg_data_members, /* tp_members */
1497 0, /* tp_getset */
1498 0, /* tp_base */
1499 0, /* tp_dict */
1500 0, /* tp_descr_get */
1501 0, /* tp_descr_set */
1502 0, /* tp_dictoffset */
1503 0, /* tp_init */
1504 0, /* tp_alloc */
1505 PyObj_pjsua_msg_data_new, /* tp_new */
1506
1507};
1508
1509
1510//////////////////////////////////////////////////////////////////////////////
1511/*
1512 * PyObj_pjsua_transport_config
1513 * Transport configuration for creating UDP transports for both SIP
1514 * and media.
1515 */
1516typedef struct
1517{
1518 PyObject_HEAD
1519 /* Type-specific fields go here. */
1520 unsigned port;
1521 PyObject *public_addr;
1522 PyObject *bound_addr;
1523} PyObj_pjsua_transport_config;
1524
1525
1526/*
1527 * PyObj_pjsua_transport_config_delete
1528 * deletes a transport config from memory
1529 */
1530static void PyObj_pjsua_transport_config_delete(PyObj_pjsua_transport_config* self)
1531{
1532 Py_XDECREF(self->public_addr);
1533 Py_XDECREF(self->bound_addr);
1534 self->ob_type->tp_free((PyObject*)self);
1535}
1536
1537
1538static void PyObj_pjsua_transport_config_export(pjsua_transport_config *cfg,
1539 PyObj_pjsua_transport_config *obj)
1540{
1541 cfg->public_addr = PyString_to_pj_str(obj->public_addr);
1542 cfg->bound_addr = PyString_to_pj_str(obj->bound_addr);
1543 cfg->port = obj->port;
1544
1545}
1546
1547static void PyObj_pjsua_transport_config_import(PyObj_pjsua_transport_config *obj,
1548 const pjsua_transport_config *cfg)
1549{
1550 Py_XDECREF(obj->public_addr);
1551 obj->public_addr = PyString_FromStringAndSize(cfg->public_addr.ptr,
1552 cfg->public_addr.slen);
1553
1554 Py_XDECREF(obj->bound_addr);
1555 obj->bound_addr = PyString_FromStringAndSize(cfg->bound_addr.ptr,
1556 cfg->bound_addr.slen);
1557
1558 obj->port = cfg->port;
1559}
1560
1561
1562/*
1563 * PyObj_pjsua_transport_config_new
1564 * constructor for transport_config object
1565 */
1566static PyObject * PyObj_pjsua_transport_config_new(PyTypeObject *type,
1567 PyObject *args,
1568 PyObject *kwds)
1569{
1570 PyObj_pjsua_transport_config *self;
1571
1572 PJ_UNUSED_ARG(args);
1573 PJ_UNUSED_ARG(kwds);
1574
1575 self = (PyObj_pjsua_transport_config *)type->tp_alloc(type, 0);
1576 if (self != NULL) {
1577 self->public_addr = PyString_FromString("");
1578 if (self->public_addr == NULL) {
1579 Py_DECREF(self);
1580 return NULL;
1581 }
1582 self->bound_addr = PyString_FromString("");
1583 if (self->bound_addr == NULL) {
1584 Py_DECREF(self);
1585 return NULL;
1586 }
1587 }
1588
1589 return (PyObject *)self;
1590}
1591
1592
1593/*
1594 * PyObj_pjsua_transport_config_members
1595 */
1596static PyMemberDef PyObj_pjsua_transport_config_members[] =
1597{
1598 {
1599 "port", T_INT,
1600 offsetof(PyObj_pjsua_transport_config, port), 0,
1601 "UDP port number to bind locally. This setting MUST be specified "
1602 "even when default port is desired. If the value is zero, the "
1603 "transport will be bound to any available port, and application "
1604 "can query the port by querying the transport info."
1605 },
1606 {
1607 "public_addr", T_OBJECT_EX,
1608 offsetof(PyObj_pjsua_transport_config, public_addr), 0,
1609 "Optional address to advertise as the address of this transport. "
1610 "Application can specify any address or hostname for this field, "
1611 "for example it can point to one of the interface address in the "
1612 "system, or it can point to the public address of a NAT router "
1613 "where port mappings have been configured for the application."
1614 },
1615 {
1616 "bound_addr", T_OBJECT_EX,
1617 offsetof(PyObj_pjsua_transport_config, bound_addr), 0,
1618 "Optional address where the socket should be bound to. This option "
1619 "SHOULD only be used to selectively bind the socket to particular "
1620 "interface (instead of 0.0.0.0), and SHOULD NOT be used to set the "
1621 "published address of a transport (the public_addr field should be "
1622 "used for that purpose)."
1623 },
1624 {NULL} /* Sentinel */
1625};
1626
1627
1628
1629
1630/*
1631 * PyTyp_pjsua_transport_config
1632 */
1633static PyTypeObject PyTyp_pjsua_transport_config =
1634{
1635 PyObject_HEAD_INIT(NULL)
1636 0, /*ob_size*/
1637 "py_pjsua.Transport_Config", /*tp_name*/
1638 sizeof(PyObj_pjsua_transport_config), /*tp_basicsize*/
1639 0, /*tp_itemsize*/
1640 (destructor)PyObj_pjsua_transport_config_delete,/*tp_dealloc*/
1641 0, /*tp_print*/
1642 0, /*tp_getattr*/
1643 0, /*tp_setattr*/
1644 0, /*tp_compare*/
1645 0, /*tp_repr*/
1646 0, /*tp_as_number*/
1647 0, /*tp_as_sequence*/
1648 0, /*tp_as_mapping*/
1649 0, /*tp_hash */
1650 0, /*tp_call*/
1651 0, /*tp_str*/
1652 0, /*tp_getattro*/
1653 0, /*tp_setattro*/
1654 0, /*tp_as_buffer*/
1655 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1656 "Transport setting", /* tp_doc */
1657 0, /* tp_traverse */
1658 0, /* tp_clear */
1659 0, /* tp_richcompare */
1660 0, /* tp_weaklistoffset */
1661 0, /* tp_iter */
1662 0, /* tp_iternext */
1663 0, /* tp_methods */
1664 PyObj_pjsua_transport_config_members,/* tp_members */
1665 0, /* tp_getset */
1666 0, /* tp_base */
1667 0, /* tp_dict */
1668 0, /* tp_descr_get */
1669 0, /* tp_descr_set */
1670 0, /* tp_dictoffset */
1671 0, /* tp_init */
1672 0, /* tp_alloc */
1673 PyObj_pjsua_transport_config_new,/* tp_new */
1674};
1675
1676
1677//////////////////////////////////////////////////////////////////////////////
1678/*
1679 * PyObj_pjsua_transport_info
1680 * Transport info
1681 */
1682typedef struct
1683{
1684 PyObject_HEAD
1685 /* Type-specific fields go here. */
1686 int id;
1687 int type;
1688 PyObject *type_name;
1689 PyObject *info;
1690 unsigned flag;
1691 PyObject *addr;
1692 unsigned port;
1693 unsigned usage_count;
1694} PyObj_pjsua_transport_info;
1695
1696
1697/*
1698 * PyObj_pjsua_transport_info_delete
1699 * deletes a transport info from memory
1700 */
1701static void PyObj_pjsua_transport_info_delete(PyObj_pjsua_transport_info* self)
1702{
1703 Py_XDECREF(self->type_name);
1704 Py_XDECREF(self->info);
1705 Py_XDECREF(self->addr);
1706 self->ob_type->tp_free((PyObject*)self);
1707}
1708
1709
1710static void PyObj_pjsua_transport_info_import(PyObj_pjsua_transport_info *obj,
1711 const pjsua_transport_info *info)
1712{
1713 obj->id = info->id;
1714 obj->type = info->type;
1715 obj->type_name = PyString_FromStringAndSize(info->type_name.ptr,
1716 info->type_name.slen);
1717 obj->info = PyString_FromStringAndSize(info->info.ptr,
1718 info->info.slen);
1719 obj->flag = info->flag;
1720 obj->addr = PyString_FromStringAndSize(info->local_name.host.ptr,
1721 info->local_name.host.slen);
1722 obj->port = info->local_name.port;
1723 obj->usage_count= info->usage_count;
1724}
1725
1726/*
1727 * PyObj_pjsua_transport_info_new
1728 * constructor for transport_info object
1729 */
1730static PyObject * PyObj_pjsua_transport_info_new(PyTypeObject *type,
1731 PyObject *args,
1732 PyObject *kwds)
1733{
1734 PyObj_pjsua_transport_info *self;
1735
1736 PJ_UNUSED_ARG(args);
1737 PJ_UNUSED_ARG(kwds);
1738
1739 self = (PyObj_pjsua_transport_info *)type->tp_alloc(type, 0);
1740 if (self != NULL)
1741 {
1742 self->type_name = PyString_FromString("");
1743 if (self->type_name == NULL) {
1744 Py_DECREF(self);
1745 return NULL;
1746 }
1747 self->info = PyString_FromString("");
1748 if (self->info == NULL) {
1749 Py_DECREF(self);
1750 return NULL;
1751 }
1752 self->addr = PyString_FromString("");
1753 if (self->addr == NULL) {
1754 Py_DECREF(self);
1755 return NULL;
1756 }
1757 }
1758
1759 return (PyObject *)self;
1760}
1761
1762
1763/*
1764 * PyObj_pjsua_transport_info_members
1765 */
1766static PyMemberDef PyObj_pjsua_transport_info_members[] =
1767{
1768 {
1769 "id", T_INT,
1770 offsetof(PyObj_pjsua_transport_info, id), 0,
1771 "PJSUA transport identification."
1772 },
1773 {
1774 "type", T_INT,
1775 offsetof(PyObj_pjsua_transport_info, id), 0,
1776 "Transport type."
1777 },
1778 {
1779 "type_name", T_OBJECT_EX,
1780 offsetof(PyObj_pjsua_transport_info, type_name), 0,
1781 "Transport type name."
1782 },
1783 {
1784 "info", T_OBJECT_EX,
1785 offsetof(PyObj_pjsua_transport_info, info), 0,
1786 "Transport string info/description."
1787 },
1788 {
1789 "flag", T_INT,
1790 offsetof(PyObj_pjsua_transport_info, flag), 0,
1791 "Transport flag (see ##pjsip_transport_flags_e)."
1792 },
1793 {
1794 "addr", T_OBJECT_EX,
1795 offsetof(PyObj_pjsua_transport_info, addr), 0,
1796 "Published address (or transport address name)."
1797 },
1798 {
1799 "port", T_INT,
1800 offsetof(PyObj_pjsua_transport_info, port), 0,
1801 "Published port number."
1802 },
1803 {
1804 "usage_count", T_INT,
1805 offsetof(PyObj_pjsua_transport_info, usage_count), 0,
1806 "Current number of objects currently referencing this transport."
1807 },
1808 {NULL} /* Sentinel */
1809};
1810
1811
1812/*
1813 * PyTyp_pjsua_transport_info
1814 */
1815static PyTypeObject PyTyp_pjsua_transport_info =
1816{
1817 PyObject_HEAD_INIT(NULL)
1818 0, /*ob_size*/
1819 "py_pjsua.Transport_Info", /*tp_name*/
1820 sizeof(PyObj_pjsua_transport_info), /*tp_basicsize*/
1821 0, /*tp_itemsize*/
1822 (destructor)PyObj_pjsua_transport_info_delete,/*tp_dealloc*/
1823 0, /*tp_print*/
1824 0, /*tp_getattr*/
1825 0, /*tp_setattr*/
1826 0, /*tp_compare*/
1827 0, /*tp_repr*/
1828 0, /*tp_as_number*/
1829 0, /*tp_as_sequence*/
1830 0, /*tp_as_mapping*/
1831 0, /*tp_hash */
1832 0, /*tp_call*/
1833 0, /*tp_str*/
1834 0, /*tp_getattro*/
1835 0, /*tp_setattro*/
1836 0, /*tp_as_buffer*/
1837 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1838 "Transport Info objects", /* tp_doc */
1839 0, /* tp_traverse */
1840 0, /* tp_clear */
1841 0, /* tp_richcompare */
1842 0, /* tp_weaklistoffset */
1843 0, /* tp_iter */
1844 0, /* tp_iternext */
1845 0, /* tp_methods */
1846 PyObj_pjsua_transport_info_members, /* tp_members */
1847 0, /* tp_getset */
1848 0, /* tp_base */
1849 0, /* tp_dict */
1850 0, /* tp_descr_get */
1851 0, /* tp_descr_set */
1852 0, /* tp_dictoffset */
1853 0, /* tp_init */
1854 0, /* tp_alloc */
1855 PyObj_pjsua_transport_info_new, /* tp_new */
1856
1857};
1858
1859
1860//////////////////////////////////////////////////////////////////////////////
1861
1862/*
1863 * PyObj_pjsua_acc_config
1864 * Acc Config
1865 */
1866typedef struct
1867{
1868 PyObject_HEAD
1869 /* Type-specific fields go here. */
1870 int priority;
1871 PyObject *id;
1872 PyObject *reg_uri;
1873 int publish_enabled;
1874 PyObject *force_contact;
1875 /*pj_str_t proxy[8];*/
1876 PyListObject *proxy;
1877 unsigned reg_timeout;
1878 /*pjsip_cred_info cred_info[8];*/
1879 PyListObject *cred_info;
1880 int transport_id;
1881} PyObj_pjsua_acc_config;
1882
1883
1884/*
1885 * PyObj_pjsua_acc_config_delete
1886 * deletes a acc_config from memory
1887 */
1888static void PyObj_pjsua_acc_config_delete(PyObj_pjsua_acc_config* self)
1889{
1890 Py_XDECREF(self->id);
1891 Py_XDECREF(self->reg_uri);
1892 Py_XDECREF(self->force_contact);
1893 Py_XDECREF(self->proxy);
1894 Py_XDECREF(self->cred_info);
1895 self->ob_type->tp_free((PyObject*)self);
1896}
1897
1898
1899static void PyObj_pjsua_acc_config_import(PyObj_pjsua_acc_config *obj,
1900 const pjsua_acc_config *cfg)
1901{
1902 unsigned i;
1903
1904 obj->priority = cfg->priority;
1905 Py_XDECREF(obj->id);
1906 obj->id = PyString_FromStringAndSize(cfg->id.ptr, cfg->id.slen);
1907 Py_XDECREF(obj->reg_uri);
1908 obj->reg_uri = PyString_FromStringAndSize(cfg->reg_uri.ptr,
1909 cfg->reg_uri.slen);
1910 obj->publish_enabled = cfg->publish_enabled;
1911 Py_XDECREF(obj->force_contact);
1912 obj->force_contact = PyString_FromStringAndSize(cfg->force_contact.ptr,
1913 cfg->force_contact.slen);
1914 Py_XDECREF(obj->proxy);
Benny Prijonod7ea6052007-09-17 15:44:47 +00001915 obj->proxy = (PyListObject *)PyList_New(0);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001916 for (i=0; i<cfg->proxy_cnt; ++i) {
1917 PyObject * str;
1918 str = PyString_FromStringAndSize(cfg->proxy[i].ptr,
1919 cfg->proxy[i].slen);
Benny Prijonod7ea6052007-09-17 15:44:47 +00001920 PyList_Append((PyObject *)obj->proxy, str);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001921 }
1922
1923 obj->reg_timeout = cfg->reg_timeout;
1924
1925 Py_XDECREF(obj->cred_info);
Benny Prijonod7ea6052007-09-17 15:44:47 +00001926 obj->cred_info = (PyListObject *)PyList_New(0);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001927 for (i=0; i<cfg->cred_count; ++i) {
1928 PyObj_pjsip_cred_info * ci;
1929
1930 ci = (PyObj_pjsip_cred_info *)
1931 PyObj_pjsip_cred_info_new(&PyTyp_pjsip_cred_info,NULL,NULL);
1932 PyObj_pjsip_cred_info_import(ci, &cfg->cred_info[i]);
Benny Prijonod7ea6052007-09-17 15:44:47 +00001933 PyList_Append((PyObject *)obj->cred_info, (PyObject *)ci);
Benny Prijono1f63cc42007-09-10 16:54:22 +00001934 }
1935
1936 obj->transport_id = cfg->transport_id;
1937}
1938
1939static void PyObj_pjsua_acc_config_export(pjsua_acc_config *cfg,
1940 PyObj_pjsua_acc_config *obj)
1941{
1942 unsigned i;
1943
1944 cfg->priority = obj->priority;
1945 cfg->id = PyString_to_pj_str(obj->id);
1946 cfg->reg_uri = PyString_to_pj_str(obj->reg_uri);
1947 cfg->publish_enabled = obj->publish_enabled;
1948 cfg->force_contact = PyString_to_pj_str(obj->force_contact);
1949
1950 cfg->proxy_cnt = PyList_Size((PyObject*)obj->proxy);
1951 for (i = 0; i < cfg->proxy_cnt; i++) {
1952 /*cfg.proxy[i] = ac->proxy[i];*/
1953 cfg->proxy[i] = PyString_to_pj_str(PyList_GetItem((PyObject *)obj->proxy,i));
1954 }
1955
1956 cfg->reg_timeout = obj->reg_timeout;
1957
1958 cfg->cred_count = PyList_Size((PyObject*)obj->cred_info);
1959 for (i = 0; i < cfg->cred_count; i++) {
1960 /*cfg.cred_info[i] = ac->cred_info[i];*/
1961 PyObj_pjsip_cred_info *ci;
1962 ci = (PyObj_pjsip_cred_info*)
1963 PyList_GetItem((PyObject *)obj->cred_info,i);
1964 PyObj_pjsip_cred_info_export(&cfg->cred_info[i], ci);
1965 }
1966
1967 cfg->transport_id = obj->transport_id;
1968}
1969
1970
1971/*
1972 * PyObj_pjsua_acc_config_new
1973 * constructor for acc_config object
1974 */
1975static PyObject * PyObj_pjsua_acc_config_new(PyTypeObject *type,
1976 PyObject *args,
1977 PyObject *kwds)
1978{
1979 PyObj_pjsua_acc_config *self;
1980
1981 PJ_UNUSED_ARG(args);
1982 PJ_UNUSED_ARG(kwds);
1983
1984 self = (PyObj_pjsua_acc_config *)type->tp_alloc(type, 0);
1985 if (self != NULL) {
1986 self->id = PyString_FromString("");
1987 if (self->id == NULL) {
1988 Py_DECREF(self);
1989 return NULL;
1990 }
1991 self->reg_uri = PyString_FromString("");
1992 if (self->reg_uri == NULL) {
1993 Py_DECREF(self);
1994 return NULL;
1995 }
1996 self->force_contact = PyString_FromString("");
1997 if (self->force_contact == NULL) {
1998 Py_DECREF(self);
1999 return NULL;
2000 }
Benny Prijonod7ea6052007-09-17 15:44:47 +00002001 self->proxy = (PyListObject *)PyList_New(0);
Benny Prijono1f63cc42007-09-10 16:54:22 +00002002 if (self->proxy == NULL) {
2003 Py_DECREF(self);
2004 return NULL;
2005 }
Benny Prijonod7ea6052007-09-17 15:44:47 +00002006 self->cred_info = (PyListObject *)PyList_New(0);
Benny Prijono1f63cc42007-09-10 16:54:22 +00002007 if (self->cred_info == NULL) {
2008 Py_DECREF(self);
2009 return NULL;
2010 }
2011 }
2012
2013 return (PyObject *)self;
2014}
2015
2016
2017
2018/*
2019 * PyObj_pjsua_acc_config_members
2020 */
2021static PyMemberDef PyObj_pjsua_acc_config_members[] =
2022{
2023 {
2024 "priority", T_INT, offsetof(PyObj_pjsua_acc_config, priority), 0,
2025 "Account priority, which is used to control the order of matching "
2026 "incoming/outgoing requests. The higher the number means the higher "
2027 "the priority is, and the account will be matched first. "
2028 },
2029 {
2030 "id", T_OBJECT_EX,
2031 offsetof(PyObj_pjsua_acc_config, id), 0,
2032 "The full SIP URL for the account. "
2033 "The value can take name address or URL format, "
2034 "and will look something like 'sip:account@serviceprovider'. "
2035 "This field is mandatory."
2036 },
2037 {
2038 "reg_uri", T_OBJECT_EX,
2039 offsetof(PyObj_pjsua_acc_config, reg_uri), 0,
2040 "This is the URL to be put in the request URI for the registration, "
2041 "and will look something like 'sip:serviceprovider'. "
2042 "This field should be specified if registration is desired. "
2043 "If the value is empty, no account registration will be performed. "
2044 },
2045 {
2046 "publish_enabled", T_INT,
2047 offsetof(PyObj_pjsua_acc_config, publish_enabled), 0,
2048 "Publish presence? "
2049 },
2050 {
2051 "force_contact", T_OBJECT_EX,
2052 offsetof(PyObj_pjsua_acc_config, force_contact), 0,
2053 "Optional URI to be put as Contact for this account. "
2054 "It is recommended that this field is left empty, "
2055 "so that the value will be calculated automatically "
2056 "based on the transport address. "
2057 },
2058 {
2059 "proxy", T_OBJECT_EX,
2060 offsetof(PyObj_pjsua_acc_config, proxy), 0,
2061 "Optional URI of the proxies to be visited for all outgoing requests "
2062 "that are using this account (REGISTER, INVITE, etc). Application need "
2063 "to specify these proxies if the service provider requires "
2064 "that requests destined towards its network should go through certain "
2065 "proxies first (for example, border controllers)."
2066 },
2067 {
2068 "reg_timeout", T_INT, offsetof(PyObj_pjsua_acc_config, reg_timeout), 0,
2069 "Optional interval for registration, in seconds. "
2070 "If the value is zero, default interval will be used "
2071 "(PJSUA_REG_INTERVAL, 55 seconds). "
2072 },
2073 {
2074 "cred_info", T_OBJECT_EX,
2075 offsetof(PyObj_pjsua_acc_config, cred_info), 0,
2076 "Array of credentials. If registration is desired, normally there "
2077 "should be at least one credential specified, to successfully "
2078 "authenticate against the service provider. More credentials can "
2079 "be specified, for example when the requests are expected to be "
2080 "challenged by the proxies in the route set."
2081 },
2082 {
2083 "transport_id", T_INT,
2084 offsetof(PyObj_pjsua_acc_config, transport_id), 0,
2085 "Optionally bind this account to specific transport. This normally is"
2086 " not a good idea, as account should be able to send requests using"
2087 " any available transports according to the destination. But some"
2088 " application may want to have explicit control over the transport to"
2089 " use, so in that case it can set this field."
2090 },
2091 {NULL} /* Sentinel */
2092};
2093
2094
2095
2096
2097/*
2098 * PyTyp_pjsua_acc_config
2099 */
2100static PyTypeObject PyTyp_pjsua_acc_config =
2101{
2102 PyObject_HEAD_INIT(NULL)
2103 0, /*ob_size*/
2104 "py_pjsua.Acc_Config", /*tp_name*/
2105 sizeof(PyObj_pjsua_acc_config), /*tp_basicsize*/
2106 0, /*tp_itemsize*/
2107 (destructor)PyObj_pjsua_acc_config_delete,/*tp_dealloc*/
2108 0, /*tp_print*/
2109 0, /*tp_getattr*/
2110 0, /*tp_setattr*/
2111 0, /*tp_compare*/
2112 0, /*tp_repr*/
2113 0, /*tp_as_number*/
2114 0, /*tp_as_sequence*/
2115 0, /*tp_as_mapping*/
2116 0, /*tp_hash */
2117 0, /*tp_call*/
2118 0, /*tp_str*/
2119 0, /*tp_getattro*/
2120 0, /*tp_setattro*/
2121 0, /*tp_as_buffer*/
2122 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2123 "Acc Config objects", /* tp_doc */
2124 0, /* tp_traverse */
2125 0, /* tp_clear */
2126 0, /* tp_richcompare */
2127 0, /* tp_weaklistoffset */
2128 0, /* tp_iter */
2129 0, /* tp_iternext */
2130 0/*acc_config_methods*/, /* tp_methods */
2131 PyObj_pjsua_acc_config_members, /* tp_members */
2132 0, /* tp_getset */
2133 0, /* tp_base */
2134 0, /* tp_dict */
2135 0, /* tp_descr_get */
2136 0, /* tp_descr_set */
2137 0, /* tp_dictoffset */
2138 0, /* tp_init */
2139 0, /* tp_alloc */
2140 PyObj_pjsua_acc_config_new, /* tp_new */
2141
2142};
2143
2144
2145//////////////////////////////////////////////////////////////////////////////
2146/*
2147 * PyObj_pjsua_acc_info
2148 * Acc Info
2149 */
2150typedef struct
2151{
2152 PyObject_HEAD
2153 /* Type-specific fields go here. */
2154 int id;
2155 int is_default;
2156 PyObject *acc_uri;
2157 int has_registration;
2158 int expires;
2159 int status;
2160 PyObject *status_text;
2161 int online_status;
2162 PyObject *online_status_text;
2163} PyObj_pjsua_acc_info;
2164
2165
2166/*
2167 * PyObj_pjsua_acc_info_delete
2168 * deletes a acc_info from memory
2169 */
2170static void PyObj_pjsua_acc_info_delete(PyObj_pjsua_acc_info* self)
2171{
2172 Py_XDECREF(self->acc_uri);
2173 Py_XDECREF(self->status_text);
2174 Py_XDECREF(self->online_status_text);
2175 self->ob_type->tp_free((PyObject*)self);
2176}
2177
2178
2179static void PyObj_pjsua_acc_info_import(PyObj_pjsua_acc_info *obj,
2180 const pjsua_acc_info *info)
2181{
2182 obj->id = info->id;
2183 obj->is_default = info->is_default;
2184 obj->acc_uri = PyString_FromStringAndSize(info->acc_uri.ptr,
2185 info->acc_uri.slen);
2186 obj->has_registration = info->has_registration;
2187 obj->expires = info->expires;
2188 obj->status = info->status;
2189 obj->status_text= PyString_FromStringAndSize(info->status_text.ptr,
2190 info->status_text.slen);
2191 obj->online_status = info->online_status;
2192 obj->online_status_text = PyString_FromStringAndSize(info->online_status_text.ptr,
2193 info->online_status_text.slen);
2194}
2195
2196
2197/*
2198 * PyObj_pjsua_acc_info_new
2199 * constructor for acc_info object
2200 */
2201static PyObject * PyObj_pjsua_acc_info_new(PyTypeObject *type,
2202 PyObject *args,
2203 PyObject *kwds)
2204{
2205 PyObj_pjsua_acc_info *self;
2206
2207 PJ_UNUSED_ARG(args);
2208 PJ_UNUSED_ARG(kwds);
2209
2210 self = (PyObj_pjsua_acc_info *)type->tp_alloc(type, 0);
2211 if (self != NULL) {
2212 self->acc_uri = PyString_FromString("");
2213 if (self->acc_uri == NULL) {
2214 Py_DECREF(self);
2215 return NULL;
2216 }
2217 self->status_text = PyString_FromString("");
2218 if (self->status_text == NULL) {
2219 Py_DECREF(self);
2220 return NULL;
2221 }
2222 self->online_status_text = PyString_FromString("");
2223 if (self->online_status_text == NULL) {
2224 Py_DECREF(self);
2225 return NULL;
2226 }
2227 }
2228
2229 return (PyObject *)self;
2230}
2231
2232/*
2233 * acc_info_members
2234 */
2235static PyMemberDef acc_info_members[] =
2236{
2237 {
2238 "id", T_INT,
2239 offsetof(PyObj_pjsua_acc_info, id), 0,
2240 "The account ID."
2241 },
2242 {
2243 "is_default", T_INT,
2244 offsetof(PyObj_pjsua_acc_info, is_default), 0,
2245 "Flag to indicate whether this is the default account. "
2246 },
2247 {
2248 "acc_uri", T_OBJECT_EX,
2249 offsetof(PyObj_pjsua_acc_info, acc_uri), 0,
2250 "Account URI"
2251 },
2252 {
2253 "has_registration", T_INT,
2254 offsetof(PyObj_pjsua_acc_info, has_registration), 0,
2255 "Flag to tell whether this account has registration setting "
2256 "(reg_uri is not empty)."
2257 },
2258 {
2259 "expires", T_INT,
2260 offsetof(PyObj_pjsua_acc_info, expires), 0,
2261 "An up to date expiration interval for account registration session."
2262 },
2263 {
2264 "status", T_INT,
2265 offsetof(PyObj_pjsua_acc_info, status), 0,
2266 "Last registration status code. If status code is zero, "
2267 "the account is currently not registered. Any other value indicates "
2268 "the SIP status code of the registration. "
2269 },
2270 {
2271 "status_text", T_OBJECT_EX,
2272 offsetof(PyObj_pjsua_acc_info, status_text), 0,
2273 "String describing the registration status."
2274 },
2275 {
2276 "online_status", T_INT,
2277 offsetof(PyObj_pjsua_acc_info, online_status), 0,
2278 "Presence online status for this account. "
2279 },
2280 {
2281 "online_status_text", T_OBJECT_EX,
2282 offsetof(PyObj_pjsua_acc_info, online_status_text), 0,
2283 "Presence online status text."
2284 },
2285 {NULL} /* Sentinel */
2286};
2287
2288
2289
2290
2291/*
2292 * PyTyp_pjsua_acc_info
2293 */
2294static PyTypeObject PyTyp_pjsua_acc_info =
2295{
2296 PyObject_HEAD_INIT(NULL)
2297 0, /*ob_size*/
2298 "py_pjsua.Acc_Info", /*tp_name*/
2299 sizeof(PyObj_pjsua_acc_info), /*tp_basicsize*/
2300 0, /*tp_itemsize*/
2301 (destructor)PyObj_pjsua_acc_info_delete,/*tp_dealloc*/
2302 0, /*tp_print*/
2303 0, /*tp_getattr*/
2304 0, /*tp_setattr*/
2305 0, /*tp_compare*/
2306 0, /*tp_repr*/
2307 0, /*tp_as_number*/
2308 0, /*tp_as_sequence*/
2309 0, /*tp_as_mapping*/
2310 0, /*tp_hash */
2311 0, /*tp_call*/
2312 0, /*tp_str*/
2313 0, /*tp_getattro*/
2314 0, /*tp_setattro*/
2315 0, /*tp_as_buffer*/
2316 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2317 "Acc Info objects", /* tp_doc */
2318 0, /* tp_traverse */
2319 0, /* tp_clear */
2320 0, /* tp_richcompare */
2321 0, /* tp_weaklistoffset */
2322 0, /* tp_iter */
2323 0, /* tp_iternext */
2324 NULL, /* tp_methods */
2325 acc_info_members, /* tp_members */
2326 0, /* tp_getset */
2327 0, /* tp_base */
2328 0, /* tp_dict */
2329 0, /* tp_descr_get */
2330 0, /* tp_descr_set */
2331 0, /* tp_dictoffset */
2332 0, /* tp_init */
2333 0, /* tp_alloc */
2334 PyObj_pjsua_acc_info_new, /* tp_new */
2335
2336};
2337
2338
2339//////////////////////////////////////////////////////////////////////////////
2340
2341/*
2342 * PyObj_pjsua_buddy_config
2343 * Buddy Config
2344 */
2345typedef struct
2346{
2347 PyObject_HEAD
2348 /* Type-specific fields go here. */
2349 PyObject *uri;
2350 int subscribe;
2351} PyObj_pjsua_buddy_config;
2352
2353
2354/*
2355 * PyObj_pjsua_buddy_config_delete
2356 * deletes a buddy_config from memory
2357 */
2358static void PyObj_pjsua_buddy_config_delete(PyObj_pjsua_buddy_config* self)
2359{
2360 Py_XDECREF(self->uri);
2361 self->ob_type->tp_free((PyObject*)self);
2362}
2363
2364
2365static void PyObj_pjsua_buddy_config_import(PyObj_pjsua_buddy_config *obj,
2366 const pjsua_buddy_config *cfg)
2367{
2368 Py_XDECREF(obj->uri);
2369 obj->uri = PyString_FromStringAndSize(cfg->uri.ptr, cfg->uri.slen);
2370 obj->subscribe = cfg->subscribe;
2371}
2372
2373
2374static void PyObj_pjsua_buddy_config_export(pjsua_buddy_config *cfg,
2375 PyObj_pjsua_buddy_config *obj)
2376{
2377 cfg->uri = PyString_to_pj_str(obj->uri);
2378 cfg->subscribe = obj->subscribe;
2379}
2380
2381
2382
2383/*
2384 * PyObj_pjsua_buddy_config_new
2385 * constructor for buddy_config object
2386 */
2387static PyObject *PyObj_pjsua_buddy_config_new(PyTypeObject *type,
2388 PyObject *args,
2389 PyObject *kwds)
2390{
2391 PyObj_pjsua_buddy_config *self;
2392
2393 PJ_UNUSED_ARG(args);
2394 PJ_UNUSED_ARG(kwds);
2395
2396 self = (PyObj_pjsua_buddy_config *)type->tp_alloc(type, 0);
2397 if (self != NULL) {
2398 self->uri = PyString_FromString("");
2399 if (self->uri == NULL) {
2400 Py_DECREF(self);
2401 return NULL;
2402 }
2403 }
2404 return (PyObject *)self;
2405}
2406
2407/*
2408 * PyObj_pjsua_buddy_config_members
2409 */
2410static PyMemberDef PyObj_pjsua_buddy_config_members[] =
2411{
2412
2413 {
2414 "uri", T_OBJECT_EX,
2415 offsetof(PyObj_pjsua_buddy_config, uri), 0,
2416 "TBuddy URL or name address."
2417 },
2418
2419 {
2420 "subscribe", T_INT,
2421 offsetof(PyObj_pjsua_buddy_config, subscribe), 0,
2422 "Specify whether presence subscription should start immediately. "
2423 },
2424
2425 {NULL} /* Sentinel */
2426};
2427
2428
2429
2430
2431/*
2432 * PyTyp_pjsua_buddy_config
2433 */
2434static PyTypeObject PyTyp_pjsua_buddy_config =
2435{
2436 PyObject_HEAD_INIT(NULL)
2437 0, /*ob_size*/
2438 "py_pjsua.Buddy_Config", /*tp_name*/
2439 sizeof(PyObj_pjsua_buddy_config),/*tp_basicsize*/
2440 0, /*tp_itemsize*/
2441 (destructor)PyObj_pjsua_buddy_config_delete,/*tp_dealloc*/
2442 0, /*tp_print*/
2443 0, /*tp_getattr*/
2444 0, /*tp_setattr*/
2445 0, /*tp_compare*/
2446 0, /*tp_repr*/
2447 0, /*tp_as_number*/
2448 0, /*tp_as_sequence*/
2449 0, /*tp_as_mapping*/
2450 0, /*tp_hash */
2451 0, /*tp_call*/
2452 0, /*tp_str*/
2453 0, /*tp_getattro*/
2454 0, /*tp_setattro*/
2455 0, /*tp_as_buffer*/
2456 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2457 "Buddy Config objects", /* tp_doc */
2458 0, /* tp_traverse */
2459 0, /* tp_clear */
2460 0, /* tp_richcompare */
2461 0, /* tp_weaklistoffset */
2462 0, /* tp_iter */
2463 0, /* tp_iternext */
2464 0, /* tp_methods */
2465 PyObj_pjsua_buddy_config_members, /* tp_members */
2466 0, /* tp_getset */
2467 0, /* tp_base */
2468 0, /* tp_dict */
2469 0, /* tp_descr_get */
2470 0, /* tp_descr_set */
2471 0, /* tp_dictoffset */
2472 0, /* tp_init */
2473 0, /* tp_alloc */
2474 PyObj_pjsua_buddy_config_new, /* tp_new */
2475
2476};
2477
2478//////////////////////////////////////////////////////////////////////////////
2479/*
2480 * PyObj_pjsua_buddy_info
2481 * Buddy Info
2482 */
2483typedef struct
2484{
2485 PyObject_HEAD
2486 /* Type-specific fields go here. */
2487 int id;
2488 PyObject *uri;
2489 PyObject *contact;
2490 int status;
2491 PyObject *status_text;
2492 int monitor_pres;
2493} PyObj_pjsua_buddy_info;
2494
2495
2496/*
2497 * PyObj_pjsua_buddy_info_delete
2498 * deletes a buddy_info from memory
2499 * !modified @ 071206
2500 */
2501static void PyObj_pjsua_buddy_info_delete(PyObj_pjsua_buddy_info* self)
2502{
2503 Py_XDECREF(self->uri);
2504 Py_XDECREF(self->contact);
2505 Py_XDECREF(self->status_text);
2506
2507 self->ob_type->tp_free((PyObject*)self);
2508}
2509
2510
2511static void PyObj_pjsua_buddy_info_import(PyObj_pjsua_buddy_info *obj,
2512 const pjsua_buddy_info *info)
2513{
2514 obj->id = info->id;
2515 Py_XDECREF(obj->uri);
2516 obj->uri = PyString_FromStringAndSize(info->uri.ptr, info->uri.slen);
2517 Py_XDECREF(obj->contact);
2518 obj->contact = PyString_FromStringAndSize(info->contact.ptr, info->contact.slen);
2519 obj->status = info->status;
2520 Py_XDECREF(obj->status_text);
2521 obj->status_text = PyString_FromStringAndSize(info->status_text.ptr,
2522 info->status_text.slen);
2523 obj->monitor_pres = info->monitor_pres;
2524}
2525
2526
2527/*
2528 * PyObj_pjsua_buddy_info_new
2529 * constructor for buddy_info object
2530 * !modified @ 071206
2531 */
2532static PyObject * PyObj_pjsua_buddy_info_new(PyTypeObject *type,
2533 PyObject *args,
2534 PyObject *kwds)
2535{
2536 PyObj_pjsua_buddy_info *self;
2537
2538 PJ_UNUSED_ARG(args);
2539 PJ_UNUSED_ARG(kwds);
2540
2541 self = (PyObj_pjsua_buddy_info *)type->tp_alloc(type, 0);
2542 if (self != NULL) {
2543 self->uri = PyString_FromString("");
2544 if (self->uri == NULL) {
2545 Py_DECREF(self);
2546 return NULL;
2547 }
2548 self->contact = PyString_FromString("");
2549 if (self->contact == NULL) {
2550 Py_DECREF(self);
2551 return NULL;
2552 }
2553 self->status_text = PyString_FromString("");
2554 if (self->status_text == NULL) {
2555 Py_DECREF(self);
2556 return NULL;
2557 }
2558
2559 }
2560 return (PyObject *)self;
2561}
2562
2563/*
2564 * PyObj_pjsua_buddy_info_members
2565 * !modified @ 071206
2566 */
2567static PyMemberDef PyObj_pjsua_buddy_info_members[] =
2568{
2569 {
2570 "id", T_INT,
2571 offsetof(PyObj_pjsua_buddy_info, id), 0,
2572 "The buddy ID."
2573 },
2574 {
2575 "uri", T_OBJECT_EX,
2576 offsetof(PyObj_pjsua_buddy_info, uri), 0,
2577 "The full URI of the buddy, as specified in the configuration. "
2578 },
2579 {
2580 "contact", T_OBJECT_EX,
2581 offsetof(PyObj_pjsua_buddy_info, contact), 0,
2582 "Buddy's Contact, only available when presence subscription "
2583 "has been established to the buddy."
2584 },
2585 {
2586 "status", T_INT,
2587 offsetof(PyObj_pjsua_buddy_info, status), 0,
2588 "Buddy's online status. "
2589 },
2590 {
2591 "status_text", T_OBJECT_EX,
2592 offsetof(PyObj_pjsua_buddy_info, status_text), 0,
2593 "Text to describe buddy's online status."
2594 },
2595 {
2596 "monitor_pres", T_INT,
2597 offsetof(PyObj_pjsua_buddy_info, monitor_pres), 0,
2598 "Flag to indicate that we should monitor the presence information "
2599 "for this buddy (normally yes, unless explicitly disabled). "
2600 },
2601
2602
2603 {NULL} /* Sentinel */
2604};
2605
2606
2607
2608
2609/*
2610 * PyTyp_pjsua_buddy_info
2611 */
2612static PyTypeObject PyTyp_pjsua_buddy_info =
2613{
2614 PyObject_HEAD_INIT(NULL)
2615 0, /*ob_size*/
2616 "py_pjsua.Buddy_Info", /*tp_name*/
2617 sizeof(PyObj_pjsua_buddy_info), /*tp_basicsize*/
2618 0, /*tp_itemsize*/
2619 (destructor)PyObj_pjsua_buddy_info_delete,/*tp_dealloc*/
2620 0, /*tp_print*/
2621 0, /*tp_getattr*/
2622 0, /*tp_setattr*/
2623 0, /*tp_compare*/
2624 0, /*tp_repr*/
2625 0, /*tp_as_number*/
2626 0, /*tp_as_sequence*/
2627 0, /*tp_as_mapping*/
2628 0, /*tp_hash */
2629 0, /*tp_call*/
2630 0, /*tp_str*/
2631 0, /*tp_getattro*/
2632 0, /*tp_setattro*/
2633 0, /*tp_as_buffer*/
2634 Py_TPFLAGS_DEFAULT, /*tp_flags*/
2635 "Buddy Info objects", /* tp_doc */
2636 0, /* tp_traverse */
2637 0, /* tp_clear */
2638 0, /* tp_richcompare */
2639 0, /* tp_weaklistoffset */
2640 0, /* tp_iter */
2641 0, /* tp_iternext */
2642 0, /* tp_methods */
2643 PyObj_pjsua_buddy_info_members, /* tp_members */
2644 0, /* tp_getset */
2645 0, /* tp_base */
2646 0, /* tp_dict */
2647 0, /* tp_descr_get */
2648 0, /* tp_descr_set */
2649 0, /* tp_dictoffset */
2650 0, /* tp_init */
2651 0, /* tp_alloc */
2652 PyObj_pjsua_buddy_info_new, /* tp_new */
2653
2654};
2655
2656
2657
2658
2659
2660#endif /* __PY_PJSUA_H__ */
2661