summaryrefslogtreecommitdiff
path: root/pjsip-apps
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2009-10-29 08:16:46 +0000
committerBenny Prijono <bennylp@teluu.com>2009-10-29 08:16:46 +0000
commit64153021595b2d80fe4182d888f88cf932006067 (patch)
tree059fead24f992778a1bee0fdf370e494e53bdf29 /pjsip-apps
parenta24b3dc0939d1a80494e716e9664fdb86aa82545 (diff)
More ticket #982: added MWI support for Python
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2976 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps')
-rw-r--r--pjsip-apps/src/python/_pjsua.c28
-rw-r--r--pjsip-apps/src/python/_pjsua.h16
-rw-r--r--pjsip-apps/src/python/pjsua.py21
3 files changed, 65 insertions, 0 deletions
diff --git a/pjsip-apps/src/python/_pjsua.c b/pjsip-apps/src/python/_pjsua.c
index dd479fda..517184a5 100644
--- a/pjsip-apps/src/python/_pjsua.c
+++ b/pjsip-apps/src/python/_pjsua.c
@@ -630,6 +630,33 @@ static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
}
+/*
+ * on_mwi_info
+ */
+static void cb_on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
+{
+ if (PyCallable_Check(g_obj_callback->on_mwi_info)) {
+ PyObject *param_acc_id, *param_body;
+ pj_str_t body;
+
+ ENTER_PYTHON();
+
+ body.ptr = mwi_info->rdata->msg_info.msg->body->data;
+ body.slen = mwi_info->rdata->msg_info.msg->body->len;
+
+ PyObject_CallFunctionObjArgs(
+ g_obj_callback->on_mwi_info,
+ param_acc_id = Py_BuildValue("i",acc_id),
+ param_body = PyString_FromPJ(&body),
+ NULL
+ );
+
+ Py_DECREF(param_acc_id);
+ Py_DECREF(param_body);
+
+ LEAVE_PYTHON();
+ }
+}
/*
* translate_hdr
@@ -901,6 +928,7 @@ static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
cfg_ua.cb.on_pager2 = &cb_on_pager;
cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
cfg_ua.cb.on_typing2 = &cb_on_typing;
+ cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;
p_cfg_ua = &cfg_ua;
diff --git a/pjsip-apps/src/python/_pjsua.h b/pjsip-apps/src/python/_pjsua.h
index 7147e2ef..04290e66 100644
--- a/pjsip-apps/src/python/_pjsua.h
+++ b/pjsip-apps/src/python/_pjsua.h
@@ -235,6 +235,7 @@ typedef struct PyObj_pjsua_callback
PyObject * on_pager;
PyObject * on_pager_status;
PyObject * on_typing;
+ PyObject * on_mwi_info;
} PyObj_pjsua_callback;
@@ -258,6 +259,7 @@ static void PyObj_pjsua_callback_delete(PyObj_pjsua_callback* self)
Py_XDECREF(self->on_pager);
Py_XDECREF(self->on_pager_status);
Py_XDECREF(self->on_typing);
+ Py_XDECREF(self->on_mwi_info);
self->ob_type->tp_free((PyObject*)self);
}
@@ -291,6 +293,7 @@ static PyObject * PyObj_pjsua_callback_new(PyTypeObject *type,
self->on_pager = Py_BuildValue("");
self->on_pager_status = Py_BuildValue("");
self->on_typing = Py_BuildValue("");
+ self->on_mwi_info = Py_BuildValue("");
}
return (PyObject *)self;
@@ -394,6 +397,11 @@ static PyMemberDef PyObj_pjsua_callback_members[] =
offsetof(PyObj_pjsua_callback, on_typing), 0,
"Notify application about typing indication."
},
+ {
+ "on_mwi_info", T_OBJECT_EX,
+ offsetof(PyObj_pjsua_callback, on_mwi_info), 0,
+ "Notify application about MWI indication."
+ },
{NULL} /* Sentinel */
};
@@ -1645,6 +1653,7 @@ typedef struct
PyObject *id;
PyObject *reg_uri;
int publish_enabled;
+ int mwi_enabled;
PyObject *force_contact;
PyListObject *proxy;
unsigned reg_timeout;
@@ -1698,6 +1707,7 @@ static void PyObj_pjsua_acc_config_import(PyObj_pjsua_acc_config *obj,
Py_XDECREF(obj->reg_uri);
obj->reg_uri = PyString_FromPJ(&cfg->reg_uri);
obj->publish_enabled = cfg->publish_enabled;
+ obj->mwi_enabled = cfg->mwi_enabled;
Py_XDECREF(obj->force_contact);
obj->force_contact = PyString_FromPJ(&cfg->force_contact);
Py_XDECREF(obj->proxy);
@@ -1753,6 +1763,7 @@ static void PyObj_pjsua_acc_config_export(pjsua_acc_config *cfg,
cfg->id = PyString_ToPJ(obj->id);
cfg->reg_uri = PyString_ToPJ(obj->reg_uri);
cfg->publish_enabled = obj->publish_enabled;
+ cfg->mwi_enabled = obj->mwi_enabled;
cfg->force_contact = PyString_ToPJ(obj->force_contact);
cfg->proxy_cnt = PyList_Size((PyObject*)obj->proxy);
@@ -1858,6 +1869,11 @@ static PyMemberDef PyObj_pjsua_acc_config_members[] =
"Publish presence? "
},
{
+ "mwi_enabled", T_INT,
+ offsetof(PyObj_pjsua_acc_config, mwi_enabled), 0,
+ "Enable MWI subscription "
+ },
+ {
"force_contact", T_OBJECT_EX,
offsetof(PyObj_pjsua_acc_config, force_contact), 0,
"Optional URI to be put as Contact for this account. "
diff --git a/pjsip-apps/src/python/pjsua.py b/pjsip-apps/src/python/pjsua.py
index c9c2ff5e..89809e97 100644
--- a/pjsip-apps/src/python/pjsua.py
+++ b/pjsip-apps/src/python/pjsua.py
@@ -993,6 +993,19 @@ class AccountCallback:
"""
pass
+ def on_mwi_info(self, body):
+ """
+ Notification about change in Message Summary / Message Waiting
+ Indication (RFC 3842) status. MWI subscription must be enabled
+ in the account config to receive this notification.
+
+ Keyword arguments:
+ body -- String containing message body as received in the
+ NOTIFY request.
+
+ """
+ pass
+
class Account:
@@ -2113,6 +2126,7 @@ class Lib:
py_ua_cfg.cb.on_pager = _cb_on_pager
py_ua_cfg.cb.on_pager_status = _cb_on_pager_status
py_ua_cfg.cb.on_typing = _cb_on_typing
+ py_ua_cfg.cb.on_mwi_info = _cb_on_mwi_info;
err = _pjsua.init(py_ua_cfg, log_cfg._cvt_to_pjsua(),
media_cfg._cvt_to_pjsua())
@@ -2763,6 +2777,11 @@ class Lib:
else:
acc._cb.on_typing(from_uri, contact, is_typing)
+ def _cb_on_mwi_info(self, acc_id, body):
+ acc = self._lookup_account(acc_id)
+ if acc:
+ return acc._cb.on_mwi_info(body)
+
def _cb_on_buddy_state(self, buddy_id):
buddy = self._lookup_buddy(buddy_id)
if buddy:
@@ -2816,6 +2835,8 @@ def _cb_on_pager_status(call_id, to, body, user_data, status, reason, acc_id):
def _cb_on_typing(call_id, from_uri, to, contact, is_typing, acc_id):
_lib._cb_on_typing(call_id, from_uri, to, contact, is_typing, acc_id)
+def _cb_on_mwi_info(acc_id, body):
+ _lib._cb_on_mwi_info(acc_id, body)
# Worker thread
def _worker_thread_main(arg):