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