diff options
-rw-r--r-- | pjsip-apps/src/pjsua/pjsua_app.c | 31 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 48 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_acc.c | 2 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_call.c | 25 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 3 |
5 files changed, 83 insertions, 26 deletions
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index 9da513d7..ad03f3d6 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -201,7 +201,7 @@ static void usage(void) #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) puts (" --use-srtp=N Use SRTP? 0:disabled, 1:optional, 2:mandatory,"); puts (" 3:optional by duplicating media offer (def:0)"); - puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 1:sips (def:1)"); + puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 2:sips (def:1)"); #endif puts (" --registrar=url Set the URL of registrar server"); puts (" --id=url Set the URL of local ID (used in From header)"); @@ -222,7 +222,8 @@ static void usage(void) puts (" --publish Send presence PUBLISH for this account"); puts (" --mwi Subscribe to message summary/waiting indication"); puts (" --use-100rel Require reliable provisional response (100rel)"); - puts (" --use-timer Require SIP session timers"); + puts (" --use-timer=N Use SIP session timers? (default=1)"); + puts (" 0:inactive, 1:optional, 2:mandatory, 3:always"); printf(" --timer-se=N Session timers expiration period, in secs (def:%d)\n", PJSIP_SESS_TIMER_DEF_SE); puts (" --timer-min-se=N Session timers minimum expiration period, in secs (def:90)"); @@ -262,7 +263,7 @@ static void usage(void) puts (" --tls-verify-server Verify server's certificate (default=no)"); puts (" --tls-verify-client Verify client's certificate (default=no)"); puts (" --tls-neg-timeout Specify TLS negotiation timeout (default=no)"); - puts (" --tls-srv-name Specify TLS server name for multi-hosting server (optional)"); + puts (" --tls-srv-name Specify TLS server name for multihosting server"); puts (""); puts ("Media Options:"); @@ -653,7 +654,7 @@ static pj_status_t parse_args(int argc, char *argv[], { "ipv6", 0, 0, OPT_IPV6}, #endif { "set-qos", 0, 0, OPT_QOS}, - { "use-timer", 0, 0, OPT_TIMER}, + { "use-timer", 1, 0, OPT_TIMER}, { "timer-se", 1, 0, OPT_TIMER_SE}, { "timer-min-se", 1, 0, OPT_TIMER_MIN_SE}, { NULL, 0, 0, 0} @@ -881,8 +882,14 @@ static pj_status_t parse_args(int argc, char *argv[], break; case OPT_TIMER: /** session timer */ - cur_acc->require_timer = PJ_TRUE; - cfg->cfg.require_timer = PJ_TRUE; + lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); + if (lval < 0 || lval > 3) { + PJ_LOG(1,(THIS_FILE, + "Error: expecting integer value 0-3 for --use-timer")); + return PJ_EINVAL; + } + cur_acc->use_timer = lval; + cfg->cfg.use_timer = lval; break; case OPT_TIMER_SE: /** session timer session expiration */ @@ -1624,8 +1631,10 @@ static void write_account_settings(int acc_index, pj_str_t *result) } /* Session Timer extension */ - if (acc_cfg->require_timer) { - pj_strcat2(result, "--use-timer\n"); + if (acc_cfg->use_timer) { + pj_ansi_sprintf(line, "--use-timer %d\n", + acc_cfg->use_timer); + pj_strcat2(result, line); } if (acc_cfg->timer_setting.min_se != 90) { pj_ansi_sprintf(line, "--timer-min-se %d\n", @@ -2103,8 +2112,10 @@ static int write_settings(const struct app_config *config, pj_strcat2(&cfg, "--use-100rel\n"); } /* Session Timer extension */ - if (config->cfg.require_timer) { - pj_strcat2(&cfg, "--use-timer\n"); + if (config->cfg.use_timer) { + pj_ansi_sprintf(line, "--use-timer %d\n", + config->cfg.use_timer); + pj_strcat2(&cfg, line); } if (config->cfg.timer_setting.min_se != 90) { pj_ansi_sprintf(line, "--timer-min-se %d\n", diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index b74a209e..0ab24942 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -886,6 +886,36 @@ typedef struct pjsua_callback } pjsua_callback; +/** + * This enumeration specifies the usage of SIP Session Timers extension. + */ +typedef enum pjsua_sip_timer_use +{ + /** + * When this flag is specified, Session Timers will not be used in any + * session, except it is explicitly required in the remote request. + */ + PJSUA_SIP_TIMER_INACTIVE, + + /** + * When this flag is specified, Session Timers will be used in all + * sessions whenever remote supports and uses it. + */ + PJSUA_SIP_TIMER_OPTIONAL, + + /** + * When this flag is specified, Session Timers support will be + * a requirement for the remote to be able to establish a session. + */ + PJSUA_SIP_TIMER_REQUIRED, + + /** + * When this flag is specified, Session Timers will always be used + * in all sessions, regardless whether remote supports/uses it or not. + */ + PJSUA_SIP_TIMER_ALWAYS + +} pjsua_sip_timer_use; /** @@ -1033,13 +1063,13 @@ typedef struct pjsua_config pj_bool_t require_100rel; /** - * Specify whether support for Session Timers should be required by - * default. Note that this setting can be further customized in account - * configuration (#pjsua_acc_config). + * Specify the usage of Session Timers for all sessions. See the + * #pjsua_sip_timer_use for possible values. Note that this setting can be + * further customized in account configuration (#pjsua_acc_config). * - * Default: PJ_FALSE + * Default: PJSUA_SIP_TIMER_OPTIONAL */ - pj_bool_t require_timer; + pjsua_sip_timer_use use_timer; /** * Handle unsolicited NOTIFY requests containing message waiting @@ -2098,12 +2128,12 @@ typedef struct pjsua_acc_config pj_bool_t require_100rel; /** - * Specify whether support for Session Timers should be required for all - * sessions of this account. + * Specify the usage of Session Timers for all sessions. See the + * #pjsua_sip_timer_use for possible values. * - * Default: PJ_FALSE + * Default: PJSUA_SIP_TIMER_OPTIONAL */ - pj_bool_t require_timer; + pjsua_sip_timer_use use_timer; /** * Specify Session Timer settings, see #pjsip_timer_setting. diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index 5597dad1..fbda32c2 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -737,7 +737,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, acc->cfg.require_100rel = cfg->require_100rel; /* Session timer */ - acc->cfg.require_timer = cfg->require_timer; + acc->cfg.use_timer = cfg->use_timer; acc->cfg.timer_setting = cfg->timer_setting; /* Transport and keep-alive */ diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index ed5eb100..2caaee1e 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -493,11 +493,15 @@ PJ_DEF(pj_status_t) pjsua_call_make_call( pjsua_acc_id acc_id, /* Create the INVITE session: */ options |= PJSIP_INV_SUPPORT_100REL; - options |= PJSIP_INV_SUPPORT_TIMER; if (acc->cfg.require_100rel) options |= PJSIP_INV_REQUIRE_100REL; - if (acc->cfg.require_timer) - options |= PJSIP_INV_REQUIRE_TIMER; + if (acc->cfg.use_timer != PJSUA_SIP_TIMER_INACTIVE) { + options |= PJSIP_INV_SUPPORT_TIMER; + if (acc->cfg.use_timer == PJSUA_SIP_TIMER_REQUIRED) + options |= PJSIP_INV_REQUIRE_TIMER; + else if (acc->cfg.use_timer == PJSUA_SIP_TIMER_ALWAYS) + options |= PJSIP_INV_ALWAYS_USE_TIMER; + } status = pjsip_inv_create_uac( dlg, offer, options, &inv); if (status != PJ_SUCCESS) { @@ -839,10 +843,12 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) options |= PJSIP_INV_SUPPORT_TIMER; if (pjsua_var.acc[acc_id].cfg.require_100rel) options |= PJSIP_INV_REQUIRE_100REL; - if (pjsua_var.acc[acc_id].cfg.require_timer) - options |= PJSIP_INV_REQUIRE_TIMER; if (pjsua_var.media_cfg.enable_ice) options |= PJSIP_INV_SUPPORT_ICE; + if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_REQUIRED) + options |= PJSIP_INV_REQUIRE_TIMER; + else if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_ALWAYS) + options |= PJSIP_INV_ALWAYS_USE_TIMER; status = pjsip_inv_verify_request2(rdata, &options, offer, answer, NULL, pjsua_var.endpt, &response); @@ -909,6 +915,15 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) pjsip_auth_clt_set_prefs(&dlg->auth_sess, &pjsua_var.acc[acc_id].cfg.auth_pref); + /* Disable Session Timers if not prefered and the incoming INVITE request + * did not require it. + */ + if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_INACTIVE && + (options & PJSIP_INV_REQUIRE_TIMER) == 0) + { + options &= ~(PJSIP_INV_SUPPORT_TIMER); + } + /* Create invite session: */ status = pjsip_inv_create_uas( dlg, rdata, answer, options, &inv); if (status != PJ_SUCCESS) { diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 368996d1..a0e43b21 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -109,6 +109,7 @@ PJ_DEF(void) pjsua_config_default(pjsua_config *cfg) #endif cfg->hangup_forked_call = PJ_TRUE; + cfg->use_timer = PJSUA_SIP_TIMER_OPTIONAL; pjsip_timer_setting_default(&cfg->timer_setting); } @@ -171,7 +172,7 @@ PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg) cfg->transport_id = PJSUA_INVALID_ID; cfg->allow_contact_rewrite = PJ_TRUE; cfg->require_100rel = pjsua_var.ua_cfg.require_100rel; - cfg->require_timer = pjsua_var.ua_cfg.require_timer; + cfg->use_timer = pjsua_var.ua_cfg.use_timer; cfg->timer_setting = pjsua_var.ua_cfg.timer_setting; cfg->ka_interval = 15; cfg->ka_data = pj_str("\r\n"); |