diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2012-06-19 14:35:18 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2012-06-19 14:35:18 +0000 |
commit | 253bf3c598087e7d4b11d0c0cb3940551becfcdc (patch) | |
tree | 34f5715a8756dee38c175264d58bd618c38bc4c1 /pjsip | |
parent | 4e48275b5dc67bce49f48c1f683dd3a8f3def8d5 (diff) |
Close #1540:
- added pjsua_acc_config.mwi_expires, also compile-time macro PJSIP_MWI_DEFAULT_EXPIRES
- updated pjsua_acc_modify() to update MWI subscription when mwi_expires & mwi_enabled of pjsua_acc_config is modified
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4172 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsip/sip_config.h | 17 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 8 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua_internal.h | 2 | ||||
-rw-r--r-- | pjsip/src/pjsip-simple/mwi.c | 3 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_acc.c | 24 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 1 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_pres.c | 57 |
7 files changed, 78 insertions, 34 deletions
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index 6b8b328a..ea19102e 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -994,6 +994,23 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) #endif +/** + * Specify the default expiration time for Message Waiting Indication + * (RFC 3842) event subscription, for both client and server subscription. + * For client subscription, application can override this by specifying + * positive non-zero value in "expires" parameter when calling + * #pjsip_mwi_initiate(). For server subscription, we would take the + * expiration value from the Expires header sent by client in the SUBSCRIBE + * request if the header exists and its value is less than this setting, + * otherwise this setting will be used. + * + * Default: 3600 seconds + */ +#ifndef PJSIP_MWI_DEFAULT_EXPIRES +# define PJSIP_MWI_DEFAULT_EXPIRES 3600 +#endif + + PJ_END_DECL /** diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 8723c2bc..8bf935aa 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2615,6 +2615,14 @@ typedef struct pjsua_acc_config pj_bool_t mwi_enabled; /** + * Specify the default expiration time for Message Waiting Indication + * (RFC 3842) event subscription. This must not be zero. + * + * Default: PJSIP_MWI_DEFAULT_EXPIRES + */ + unsigned mwi_expires; + + /** * If this flag is set, the presence information of this account will * be PUBLISH-ed to the server where the account belongs. * diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index 4b2dc947..911cad10 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -670,7 +670,7 @@ pj_status_t pjsua_im_init(void); /** * Start MWI subscription */ -void pjsua_start_mwi(pjsua_acc *acc); +pj_status_t pjsua_start_mwi(pjsua_acc_id acc_id, pj_bool_t force_renew); /** * Init call subsystem. diff --git a/pjsip/src/pjsip-simple/mwi.c b/pjsip/src/pjsip-simple/mwi.c index 5d445110..537ca9ec 100644 --- a/pjsip/src/pjsip-simple/mwi.c +++ b/pjsip/src/pjsip-simple/mwi.c @@ -32,7 +32,6 @@ #define THIS_FILE "mwi.c" -#define MWI_DEFAULT_EXPIRES 3600 /* * MWI module (mod-mdi) @@ -138,7 +137,7 @@ PJ_DEF(pj_status_t) pjsip_mwi_init_module( pjsip_endpoint *endpt, /* Register event package to event module. */ status = pjsip_evsub_register_pkg( &mod_mwi, &STR_MWI, - MWI_DEFAULT_EXPIRES, + PJSIP_MWI_DEFAULT_EXPIRES, PJ_ARRAY_SIZE(accept), accept); if (status != PJ_SUCCESS) { pjsip_endpt_unregister_module(endpt, &mod_mwi); diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index d475f826..65e52640 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -469,7 +469,7 @@ PJ_DEF(pj_status_t) pjsua_acc_add( const pjsua_acc_config *cfg, } else { /* Otherwise subscribe to MWI, if it's enabled */ if (pjsua_var.acc[id].cfg.mwi_enabled) - pjsua_start_mwi(&pjsua_var.acc[id]); + pjsua_start_mwi(id, PJ_TRUE); } pj_log_pop_indent(); @@ -679,6 +679,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, pj_str_t acc_proxy[PJSUA_ACC_MAX_PROXIES]; pj_bool_t update_reg = PJ_FALSE; pj_bool_t unreg_first = PJ_FALSE; + pj_bool_t update_mwi = PJ_FALSE; pj_status_t status = PJ_SUCCESS; PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc), @@ -838,7 +839,14 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, } /* MWI */ - acc->cfg.mwi_enabled = cfg->mwi_enabled; + if (acc->cfg.mwi_enabled != cfg->mwi_enabled) { + acc->cfg.mwi_enabled = cfg->mwi_enabled; + update_mwi = PJ_TRUE; + } + if (acc->cfg.mwi_expires != cfg->mwi_expires && cfg->mwi_expires > 0) { + acc->cfg.mwi_expires = cfg->mwi_expires; + update_mwi = PJ_TRUE; + } /* PIDF tuple ID */ if (pj_strcmp(&acc->cfg.pidf_tuple_id, &cfg->pidf_tuple_id)) @@ -1132,11 +1140,11 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, /* If accounts has registration enabled, start registration */ if (acc->cfg.reg_uri.slen) pjsua_acc_set_registration(acc->index, PJ_TRUE); - else { - /* Otherwise subscribe to MWI, if it's enabled */ - if (acc->cfg.mwi_enabled) - pjsua_start_mwi(acc); - } + } + + /* Update MWI subscription */ + if (update_mwi) { + pjsua_start_mwi(acc_id, PJ_TRUE); } /* Video settings */ @@ -1875,7 +1883,7 @@ static void regc_cb(struct pjsip_regc_cbparam *param) /* Subscribe to MWI, if it's enabled */ if (acc->cfg.mwi_enabled) - pjsua_start_mwi(acc); + pjsua_start_mwi(acc->index, PJ_FALSE); } } else { diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 5c0ecc3b..4fbfcb19 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -237,6 +237,7 @@ PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg) pj_list_init(&cfg->sub_hdr_list); cfg->call_hold_type = PJSUA_CALL_HOLD_TYPE_DEFAULT; cfg->register_on_acc_add = PJ_TRUE; + cfg->mwi_expires = PJSIP_MWI_DEFAULT_EXPIRES; } PJ_DEF(void) pjsua_buddy_config_default(pjsua_buddy_config *cfg) diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c index c78e8b5c..ff30879f 100644 --- a/pjsip/src/pjsua-lib/pjsua_pres.c +++ b/pjsip/src/pjsua-lib/pjsua_pres.c @@ -2011,17 +2011,22 @@ static pjsip_evsub_user mwi_cb = */ }; -void pjsua_start_mwi(pjsua_acc *acc) +pj_status_t pjsua_start_mwi(pjsua_acc_id acc_id, pj_bool_t force_renew) { + pjsua_acc *acc; pj_pool_t *tmp_pool = NULL; pj_str_t contact; pjsip_tx_data *tdata; - pj_status_t status; + pj_status_t status = PJ_SUCCESS; + + PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc) + && pjsua_var.acc[acc_id].valid, PJ_EINVAL); + + acc = &pjsua_var.acc[acc_id]; if (!acc->cfg.mwi_enabled) { if (acc->mwi_sub) { /* Terminate MWI subscription */ - pjsip_tx_data *tdata; pjsip_evsub *sub = acc->mwi_sub; /* Detach sub from this account */ @@ -2035,13 +2040,26 @@ void pjsua_start_mwi(pjsua_acc *acc) status = pjsip_mwi_send_request(acc->mwi_sub, tdata); } } - return; + return status; } + /* Subscription is already active */ if (acc->mwi_sub) { - /* Subscription is already active */ - return; + if (!force_renew) + return PJ_SUCCESS; + + /* Update MWI subscription */ + pj_assert(acc->mwi_dlg); + pjsip_dlg_inc_lock(acc->mwi_dlg); + + status = pjsip_mwi_initiate(acc->mwi_sub, acc->cfg.mwi_expires, &tdata); + if (status == PJ_SUCCESS) { + pjsua_process_msg_data(tdata, NULL); + status = pjsip_pres_send_request(acc->mwi_sub, tdata); + } + pjsip_dlg_dec_lock(acc->mwi_dlg); + return status; } PJ_LOG(4,(THIS_FILE, "Starting MWI subscription..")); @@ -2059,9 +2077,7 @@ void pjsua_start_mwi(pjsua_acc *acc) if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to generate Contact header", status); - pj_pool_release(tmp_pool); - pj_log_pop_indent(); - return; + goto on_return; } } @@ -2073,9 +2089,7 @@ void pjsua_start_mwi(pjsua_acc *acc) NULL, &acc->mwi_dlg); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to create dialog", status); - if (tmp_pool) pj_pool_release(tmp_pool); - pj_log_pop_indent(); - return; + goto on_return; } /* Increment the dialog's lock otherwise when presence session creation @@ -2088,10 +2102,8 @@ void pjsua_start_mwi(pjsua_acc *acc) PJSIP_EVSUB_NO_EVENT_ID, &acc->mwi_sub); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Error creating MWI subscription", status); - if (tmp_pool) pj_pool_release(tmp_pool); if (acc->mwi_dlg) pjsip_dlg_dec_lock(acc->mwi_dlg); - pj_log_pop_indent(); - return; + goto on_return; } /* If account is locked to specific transport, then lock dialog @@ -2120,7 +2132,7 @@ void pjsua_start_mwi(pjsua_acc *acc) pjsip_evsub_set_mod_data(acc->mwi_sub, pjsua_var.mod.id, acc); - status = pjsip_mwi_initiate(acc->mwi_sub, -1, &tdata); + status = pjsip_mwi_initiate(acc->mwi_sub, acc->cfg.mwi_expires, &tdata); if (status != PJ_SUCCESS) { if (acc->mwi_dlg) pjsip_dlg_dec_lock(acc->mwi_dlg); if (acc->mwi_sub) { @@ -2130,9 +2142,7 @@ void pjsua_start_mwi(pjsua_acc *acc) acc->mwi_dlg = NULL; pjsua_perror(THIS_FILE, "Unable to create initial MWI SUBSCRIBE", status); - if (tmp_pool) pj_pool_release(tmp_pool); - pj_log_pop_indent(); - return; + goto on_return; } pjsua_process_msg_data(tdata, NULL); @@ -2147,15 +2157,16 @@ void pjsua_start_mwi(pjsua_acc *acc) acc->mwi_dlg = NULL; pjsua_perror(THIS_FILE, "Unable to send initial MWI SUBSCRIBE", status); - if (tmp_pool) pj_pool_release(tmp_pool); - pj_log_pop_indent(); - return; + goto on_return; } pjsip_dlg_dec_lock(acc->mwi_dlg); + +on_return: if (tmp_pool) pj_pool_release(tmp_pool); pj_log_pop_indent(); + return status; } @@ -2269,7 +2280,7 @@ static void pres_timer_cb(pj_timer_heap_t *th, /* Re-subscribe MWI subscription if it's terminated prematurely */ if (acc->cfg.mwi_enabled && !acc->mwi_sub) - pjsua_start_mwi(acc); + pjsua_start_mwi(acc->index, PJ_FALSE); } /* #937: No need to do bulk client refresh, as buddies have their |