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