summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2009-11-20 23:33:07 +0000
committerBenny Prijono <bennylp@teluu.com>2009-11-20 23:33:07 +0000
commitf62192152803bfbe622baf2fa247bd346fdd7905 (patch)
tree1fbdacea676953e9c94c7c59bcb5182792f9dffb /pjsip
parentb8350d459e3d56e65ee9a1ea7fe3338ad51af476 (diff)
More ticket #982 (MWI): support for Asterisk unsolicited MWI requests:
- undo r3019 which put unsolicited MWI support in pjsua app only - put the unsolicited MWI support in PJSUA-LIB instead - unsolicited MWI is by default enabled - on_mwi_info() callback will be called just as the solicited MWI version git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3021 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h20
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c1
-rw-r--r--pjsip/src/pjsua-lib/pjsua_pres.c87
3 files changed, 106 insertions, 2 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index a8bb2f39..44ce9f0f 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -1002,6 +1002,21 @@ typedef struct pjsua_config
pj_bool_t require_timer;
/**
+ * Handle unsolicited NOTIFY requests containing message waiting
+ * indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests
+ * which are not requested by client with SUBSCRIBE request.
+ *
+ * If this is enabled, the library will respond 200/OK to the NOTIFY
+ * request and forward the request to \a on_mwi_info() callback.
+ *
+ * See also \a mwi_enabled field #on pjsua_acc_config.
+ *
+ * Default: PJ_TRUE
+ *
+ */
+ pj_bool_t enable_unsolicited_mwi;
+
+ /**
* Specify Session Timer settings, see #pjsip_timer_setting.
* Note that this setting can be further customized in account
* configuration (#pjsua_acc_config).
@@ -1882,8 +1897,9 @@ typedef struct pjsua_acc_config
pj_str_t reg_uri;
/**
- * Enable message summary and message waiting indication subscription
- * (RFC 3842) for this account.
+ * Subscribe to message waiting indication events (RFC 3842).
+ *
+ * See also \a enable_unsolicited_mwi field on #pjsua_config.
*
* Default: no
*/
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 6e41cbe0..52d436e3 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -101,6 +101,7 @@ PJ_DEF(void) pjsua_config_default(pjsua_config *cfg)
cfg->nat_type_in_sdp = 1;
cfg->stun_ignore_failure = PJ_TRUE;
cfg->force_lr = PJ_TRUE;
+ cfg->enable_unsolicited_mwi = PJ_TRUE;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
cfg->use_srtp = PJSUA_DEFAULT_USE_SRTP;
cfg->srtp_secure_signaling = PJSUA_DEFAULT_SRTP_SECURE_SIGNALING;
diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c
index fbf13352..effa4010 100644
--- a/pjsip/src/pjsua-lib/pjsua_pres.c
+++ b/pjsip/src/pjsua-lib/pjsua_pres.c
@@ -2075,6 +2075,87 @@ void pjsua_start_mwi(pjsua_acc *acc)
}
+/***************************************************************************
+ * Unsolicited MWI
+ */
+static pj_bool_t unsolicited_mwi_on_rx_request(pjsip_rx_data *rdata)
+{
+ pjsip_msg *msg = rdata->msg_info.msg;
+ pj_str_t EVENT_HDR = { "Event", 5 };
+ pj_str_t MWI = { "message-summary", 15 };
+ pjsip_event_hdr *eh;
+
+ if (pjsip_method_cmp(&msg->line.req.method, &pjsip_notify_method)!=0) {
+ /* Only interested with NOTIFY request */
+ return PJ_FALSE;
+ }
+
+ eh = (pjsip_event_hdr*) pjsip_msg_find_hdr_by_name(msg, &EVENT_HDR, NULL);
+ if (!eh) {
+ /* Something wrong with the request, it has no Event hdr */
+ return PJ_FALSE;
+ }
+
+ if (pj_stricmp(&eh->event_type, &MWI) != 0) {
+ /* Not MWI event */
+ return PJ_FALSE;
+ }
+
+ /* Got unsolicited MWI request, respond with 200/OK first */
+ pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL,
+ NULL, NULL, NULL);
+
+
+ /* Call callback */
+ if (pjsua_var.ua_cfg.cb.on_mwi_info) {
+ pjsua_acc_id acc_id;
+ pjsua_mwi_info mwi_info;
+
+ acc_id = pjsua_acc_find_for_incoming(rdata);
+
+ pj_bzero(&mwi_info, sizeof(mwi_info));
+ mwi_info.rdata = rdata;
+
+ (*pjsua_var.ua_cfg.cb.on_mwi_info)(acc_id, &mwi_info);
+ }
+
+
+ return PJ_TRUE;
+}
+
+/* The module instance. */
+static pjsip_module pjsua_unsolicited_mwi_mod =
+{
+ NULL, NULL, /* prev, next. */
+ { "mod-unsolicited-mwi", 19 }, /* Name. */
+ -1, /* Id */
+ PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
+ NULL, /* load() */
+ NULL, /* start() */
+ NULL, /* stop() */
+ NULL, /* unload() */
+ &unsolicited_mwi_on_rx_request, /* on_rx_request() */
+ NULL, /* on_rx_response() */
+ NULL, /* on_tx_request. */
+ NULL, /* on_tx_response() */
+ NULL, /* on_tsx_state() */
+};
+
+static pj_status_t enable_unsolicited_mwi(void)
+{
+ pj_status_t status;
+
+ status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(),
+ &pjsua_unsolicited_mwi_mod);
+ if (status != PJ_SUCCESS)
+ pjsua_perror(THIS_FILE, "Error registering unsolicited MWI module",
+ status);
+
+ return status;
+}
+
+
+
/***************************************************************************/
/* Timer callback to re-create client subscription */
@@ -2150,6 +2231,12 @@ pj_status_t pjsua_pres_start(void)
pjsua_var.pres_timer.id = PJ_TRUE;
}
+ if (pjsua_var.ua_cfg.enable_unsolicited_mwi) {
+ pj_status_t status = enable_unsolicited_mwi();
+ if (status != PJ_SUCCESS)
+ return status;
+ }
+
return PJ_SUCCESS;
}