summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/py_pjsua
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-09-17 15:44:47 +0000
committerBenny Prijono <bennylp@teluu.com>2007-09-17 15:44:47 +0000
commit0b5b5d6d0b9e0c0362c15126bd74176aa1ce5161 (patch)
treef825c13c0f498430911d4312b5df6a90970f5ebf /pjsip-apps/src/py_pjsua
parent256d36fb49a1aebcea8d63dbb65f3597ddc2cb3c (diff)
Updated pjsua_app.py Python sample application to the new changes in Python module (thanks Gideon Klompje)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1438 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/py_pjsua')
-rw-r--r--pjsip-apps/src/py_pjsua/pjsua_app.py24
-rw-r--r--pjsip-apps/src/py_pjsua/py_pjsua.c14
-rw-r--r--pjsip-apps/src/py_pjsua/py_pjsua.h21
3 files changed, 31 insertions, 28 deletions
diff --git a/pjsip-apps/src/py_pjsua/pjsua_app.py b/pjsip-apps/src/py_pjsua/pjsua_app.py
index 1ba04930..093b96ea 100644
--- a/pjsip-apps/src/py_pjsua/pjsua_app.py
+++ b/pjsip-apps/src/py_pjsua/pjsua_app.py
@@ -19,8 +19,8 @@ C_LOG_LEVEL = 4
# STUN config.
# Set C_STUN_HOST to the address:port of the STUN server to enable STUN
#
-#C_STUN_HOST = ""
-C_STUN_HOST = "192.168.0.2"
+C_STUN_HOST = ""
+#C_STUN_HOST = "192.168.0.2"
#C_STUN_HOST = "stun.iptel.org:3478"
# SIP port
@@ -267,12 +267,16 @@ def add_account():
acc_cfg = py_pjsua.acc_config_default()
acc_cfg.id = "sip:" + acc_username + "@" + acc_domain
acc_cfg.reg_uri = "sip:" + acc_domain
- acc_cfg.cred_count = 1
- acc_cfg.cred_info[0].realm = acc_domain
- acc_cfg.cred_info[0].scheme = "digest"
- acc_cfg.cred_info[0].username = acc_username
- acc_cfg.cred_info[0].data_type = 0
- acc_cfg.cred_info[0].data = acc_passwd
+
+ cred_info = py_pjsua.Pjsip_Cred_Info()
+ cred_info.realm = "*"
+ cred_info.scheme = "digest"
+ cred_info.username = acc_username
+ cred_info.data_type = 0
+ cred_info.data = acc_passwd
+
+ acc_cfg.cred_info.append(1)
+ acc_cfg.cred_info[0] = cred_info
# Add new SIP account
status, acc_id = py_pjsua.acc_add(acc_cfg, 1)
@@ -338,8 +342,8 @@ def conf_list():
info = None
info = py_pjsua.conf_get_port_info(port)
txlist = ""
- for i in range(info.listener_cnt):
- txlist = txlist + "#" + `info.listeners[i]` + " "
+ for listener in info.listeners:
+ txlist = txlist + "#" + `listener` + " "
print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist
diff --git a/pjsip-apps/src/py_pjsua/py_pjsua.c b/pjsip-apps/src/py_pjsua/py_pjsua.c
index 021bd742..b1abbdad 100644
--- a/pjsip-apps/src/py_pjsua/py_pjsua.c
+++ b/pjsip-apps/src/py_pjsua/py_pjsua.c
@@ -2403,7 +2403,6 @@ typedef struct
unsigned channel_count;
unsigned samples_per_frame;
unsigned bits_per_sample;
- unsigned listener_cnt;
PyListObject * listeners;
} PyObj_pjsua_conf_port_info;
@@ -2443,7 +2442,7 @@ static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
return NULL;
}
- self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS);
+ self->listeners = (PyListObject *)PyList_New(0);
if (self->listeners == NULL)
{
Py_DECREF(self);
@@ -2489,11 +2488,6 @@ static PyMemberDef conf_port_info_members[] =
"Bits per sample"
},
{
- "listener_cnt", T_INT,
- offsetof(PyObj_pjsua_conf_port_info, listener_cnt), 0,
- "Number of listeners in the array."
- },
- {
"listeners", T_OBJECT_EX,
offsetof(PyObj_pjsua_conf_port_info, listeners), 0,
"Array of listeners (in other words, ports where this port "
@@ -3166,7 +3160,7 @@ static PyObject *py_pjsua_conf_get_port_info
PyObj_pjsua_conf_port_info * obj;
pjsua_conf_port_info info;
int status;
- int i;
+ unsigned i;
PJ_UNUSED_ARG(pSelf);
@@ -3182,12 +3176,12 @@ static PyObject *py_pjsua_conf_get_port_info
obj->bits_per_sample = info.bits_per_sample;
obj->channel_count = info.bits_per_sample;
obj->clock_rate = info.clock_rate;
- obj->listener_cnt = info.listener_cnt;
obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
obj->samples_per_frame = info.samples_per_frame;
obj->slot_id = info.slot_id;
- for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) {
+ obj->listeners = (PyListObject *)PyList_New(info.listener_cnt);
+ for (i = 0; i < info.listener_cnt; i++) {
PyObject * item = Py_BuildValue("i",info.listeners[i]);
PyList_SetItem((PyObject *)obj->listeners, i, item);
}
diff --git a/pjsip-apps/src/py_pjsua/py_pjsua.h b/pjsip-apps/src/py_pjsua/py_pjsua.h
index 00511a9b..b025a519 100644
--- a/pjsip-apps/src/py_pjsua/py_pjsua.h
+++ b/pjsip-apps/src/py_pjsua/py_pjsua.h
@@ -28,8 +28,13 @@ PJ_INLINE(pj_str_t) PyString_to_pj_str(const PyObject *obj)
{
pj_str_t str;
- str.ptr = PyString_AS_STRING(obj);
- str.slen = PyString_GET_SIZE(obj);
+ if (obj) {
+ str.ptr = PyString_AS_STRING(obj);
+ str.slen = PyString_GET_SIZE(obj);
+ } else {
+ str.ptr = NULL;
+ str.slen = 0;
+ }
return str;
}
@@ -1905,25 +1910,25 @@ static void PyObj_pjsua_acc_config_import(PyObj_pjsua_acc_config *obj,
obj->force_contact = PyString_FromStringAndSize(cfg->force_contact.ptr,
cfg->force_contact.slen);
Py_XDECREF(obj->proxy);
- obj->proxy = (PyListObject *)PyList_New(8);
+ obj->proxy = (PyListObject *)PyList_New(0);
for (i=0; i<cfg->proxy_cnt; ++i) {
PyObject * str;
str = PyString_FromStringAndSize(cfg->proxy[i].ptr,
cfg->proxy[i].slen);
- PyList_SetItem((PyObject *)obj->proxy, i, str);
+ PyList_Append((PyObject *)obj->proxy, str);
}
obj->reg_timeout = cfg->reg_timeout;
Py_XDECREF(obj->cred_info);
- obj->cred_info = (PyListObject *)PyList_New(8);
+ obj->cred_info = (PyListObject *)PyList_New(0);
for (i=0; i<cfg->cred_count; ++i) {
PyObj_pjsip_cred_info * ci;
ci = (PyObj_pjsip_cred_info *)
PyObj_pjsip_cred_info_new(&PyTyp_pjsip_cred_info,NULL,NULL);
PyObj_pjsip_cred_info_import(ci, &cfg->cred_info[i]);
- PyList_SetItem((PyObject *)obj->cred_info, i, (PyObject *)ci);
+ PyList_Append((PyObject *)obj->cred_info, (PyObject *)ci);
}
obj->transport_id = cfg->transport_id;
@@ -1991,12 +1996,12 @@ static PyObject * PyObj_pjsua_acc_config_new(PyTypeObject *type,
Py_DECREF(self);
return NULL;
}
- self->proxy = (PyListObject *)PyList_New(8);
+ self->proxy = (PyListObject *)PyList_New(0);
if (self->proxy == NULL) {
Py_DECREF(self);
return NULL;
}
- self->cred_info = (PyListObject *)PyList_New(8);
+ self->cred_info = (PyListObject *)PyList_New(0);
if (self->cred_info == NULL) {
Py_DECREF(self);
return NULL;