Commit bd35fc87 authored by Pekka Pessi's avatar Pekka Pessi

nua: added NUTAG_SUB_EXPIRES()

darcs-hash:20080225191415-65a35-6ae00e2a66a7a88919d1fbabd4bafdc3a4193121.gz
parent 9f61a8af
......@@ -237,7 +237,8 @@ int nua_subscribe_server_preprocess(nua_server_request_t *sr)
sip_event_t *o = sip->sip_event;
char const *event = o ? o->o_type : NULL;
/* Maximum expiration time */
unsigned long expires = 3600;
unsigned long expires = sip->sip_expires ? sip->sip_expires->ex_delta : 3600;
sip_time_t now = sip_now();
assert(nh && nh->nh_nua->nua_dhandle != nh);
......@@ -259,9 +260,10 @@ int nua_subscribe_server_preprocess(nua_server_request_t *sr)
nu = nua_dialog_usage_private(du);
if (sip->sip_expires && sip->sip_expires->ex_delta < expires)
expires = sip->sip_expires->ex_delta;
nu->nu_requested = sip_now() + expires;
if (now + expires >= now)
nu->nu_requested = now + expires;
else
nu->nu_requested = SIP_TIME_MAX - 1;
#if SU_HAVE_EXPERIMENTAL
nu->nu_etags =
......@@ -295,9 +297,23 @@ int nua_subscribe_server_respond(nua_server_request_t *sr, tagi_t const *tags)
sip_time_t now = sip_now();
if (nu->nu_requested) {
if (nu->nu_requested > nu->nu_expires)
if (sip->sip_expires) {
/* Expires in response can only shorten the expiration time */
if (nu->nu_requested > now + sip->sip_expires->ex_delta)
nu->nu_requested = now + sip->sip_expires->ex_delta;
}
else {
unsigned sub_expires = NH_PGET(sr->sr_owner, sub_expires);
if (nu->nu_requested > now + sub_expires)
nu->nu_requested = now + sub_expires;
}
if (nu->nu_requested >= now)
nu->nu_expires = nu->nu_requested;
else if (nu->nu_expires <= now || nu->nu_requested <= now)
else
nu->nu_expires = now;
if (nu->nu_expires <= now)
nu->nu_substate = nua_substate_terminated;
}
......@@ -305,7 +321,7 @@ int nua_subscribe_server_respond(nua_server_request_t *sr, tagi_t const *tags)
ex->ex_delta = nu->nu_expires - now;
}
else {
/* Add header Expires: 0 */
/* Always add header Expires: 0 */
}
if (!sip->sip_expires || sip->sip_expires->ex_delta > ex->ex_delta)
......
......@@ -325,6 +325,7 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
* NUTAG_SMIME_SIGNATURE() \n
* NUTAG_SOA_NAME() \n
* NUTAG_SUBSTATE() \n
* NUTAG_SUB_EXPIRES() \n
* NUTAG_SUPPORTED(), SIPTAG_SUPPORTED(), and SIPTAG_SUPPORTED_STR() \n
* NUTAG_UPDATE_REFRESH() \n
* NUTAG_USER_AGENT(), SIPTAG_USER_AGENT() and SIPTAG_USER_AGENT_STR() \n
......@@ -437,6 +438,7 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
* NUTAG_SESSION_TIMER() \n
* NUTAG_SOA_NAME() \n
* NUTAG_SUBSTATE() \n
* NUTAG_SUB_EXPIRES() \n
* NUTAG_SUPPORTED(), SIPTAG_SUPPORTED(), and SIPTAG_SUPPORTED_STR() \n
* NUTAG_UPDATE_REFRESH() \n
* NUTAG_USER_AGENT(), SIPTAG_USER_AGENT() and SIPTAG_USER_AGENT_STR() \n
......@@ -804,6 +806,10 @@ static int nhp_set_tags(su_home_t *home,
else if (tag == nutag_substate) {
NHP_SET(nhp, substate, (int)value);
}
/* NUTAG_SUB_EXPIRES(sub_expires) */
else if (tag == nutag_sub_expires) {
NHP_SET(nhp, sub_expires, value);
}
/* NUTAG_KEEPALIVE(keepalive) */
else if (tag == nutag_keepalive) {
NHP_SET(nhp, keepalive, (unsigned)value);
......@@ -1475,6 +1481,7 @@ int nua_stack_set_smime_params(nua_t *nua, tagi_t const *tags)
* NUTAG_SMIME_SIGNATURE() \n
* NUTAG_SOA_NAME() \n
* NUTAG_SUBSTATE() \n
* NUTAG_SUB_EXPIRES() \n
* NUTAG_UPDATE_REFRESH() \n
* NUTAG_USER_AGENT() \n
* SIPTAG_ALLOW() \n
......@@ -1629,6 +1636,7 @@ int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
TIF(NUTAG_REFER_WITH_ID, refer_with_id),
TIF(NUTAG_SUBSTATE, substate),
TIF(NUTAG_SUB_EXPIRES, sub_expires),
TIF(SIPTAG_SUPPORTED, supported),
TIF_STR(SIPTAG_SUPPORTED_STR, supported),
......
......@@ -107,6 +107,7 @@ typedef struct nua_handle_preferences
/* Subscriber state, i.e. nua_substate_pending */
unsigned nhp_substate;
unsigned nhp_sub_expires;
/* REGISTER keepalive intervals */
unsigned nhp_keepalive, nhp_keepalive_stream;
......@@ -169,13 +170,14 @@ typedef struct nua_handle_preferences
unsigned nhb_refer_with_id:1;
unsigned nhb_refer_expires:1;
unsigned nhb_substate:1;
unsigned nhb_sub_expires:1;
unsigned nhb_keepalive:1;
unsigned nhb_keepalive_stream:1;
unsigned nhb_registrar:1;
unsigned nhb_allow:1;
unsigned nhb_supported:1;
unsigned :0; /* at most 32 bits before this point */
unsigned nhb_supported:1;
unsigned nhb_allow_events:1;
unsigned nhb_user_agent:1;
......
......@@ -227,21 +227,22 @@
* - NUTAG_ALLOW_EVENTS(), SIPTAG_ALLOW_EVENTS(), and
* SIPTAG_ALLOW_EVENTS_STR()
* - NUTAG_MAX_SUBSCRIPTIONS()
* - NUTAG_SUBSTATE()
* - NUTAG_SUBSTATE(), NUTAG_SUB_EXPIRES()
* @par Specifications
* - @RFC3265
*
* @par SIP Event Subscriber
* - nua_subscribe(), #nua_r_subscribe, #nua_i_notify, NUTAG_SUBSTATE(),
* SIPTAG_EVENT(), SIPTAG_EXPIRES(),
* SIPTAG_EVENT(), SIPTAG_EXPIRES()
* - nua_unsubscribe(), #nua_r_unsubscribe()
* @par Specifications
* - @RFC3265
*
* @par SIP Event Notifier
* - #nua_i_subscribe(), nua_notify(), #nua_r_notify,
* NUTAG_SUBSTATE(), SIPTAG_EVENT()
* NUTAG_SUBSTATE(), NUTAG_SUB_EXPIRES(), SIPTAG_EVENT()
* Settings:
* - NUTAG_SUB_EXPIRES()
* - NUTAG_ALLOW_EVENTS(), SIPTAG_ALLOW_EVENTS(), and
* SIPTAG_ALLOW_EVENTS_STR()
* - NUTAG_ALLOW("SUBSCRIBE"), NUTAG_APPL_METHOD("SUBSCRIBE")
......@@ -769,14 +770,14 @@ tag_typedef_t nutag_answer_sent = BOOLTAG_TYPEDEF(answer_sent);
*
* @par Used with
* - with nua_create(), nua_set_params(), nua_get_params(),
* nua_handle(), nua_set_hparams(), nua_get_hparams(), and
* nua_notifier() to change the default subscription state returned by
* the intenal event server
* nua_handle(), nua_set_hparams(), nua_get_hparams(), and
* nua_notifier() to change the default subscription state returned by
* the internal event server
* - with nua_notify() and nua_respond() to SUBSCRIBE to determine the
* subscription state (if application include @SubscriptionState
* header in the tag list, the NUTAG_SUBSTATE() value is ignored)
* subscription state (if application include @SubscriptionState
* header in the tag list, the NUTAG_SUBSTATE() value is ignored)
* - with #nua_r_subscribe, #nua_i_notify, #nua_i_subscribe, and #nua_r_notify
* to indicate the current subscription state
* to indicate the current subscription state
*
* @par Parameter type
* int
......@@ -808,6 +809,39 @@ tag_typedef_t nutag_substate = INTTAG_TYPEDEF(substate);
*/
/**@def NUTAG_SUB_EXPIRES()
*
* Default expiration time of subscriptions.
*
* @par Used with
* - with nua_create(), nua_set_params(), nua_get_params(), nua_handle(),
* nua_set_hparams(), nua_get_hparams(), nua_respond(), nua_notify(), and
* nua_notifier() to change the default expiration time of subscriptions
*
* @par Parameter type
* unsigned int
*
* @par Values
* - default expiration time in seconds
*
* Note that the expires parameter in @SubscriptionState or @Expires header
* in the nua_response() to the SUBSCRIBE overrides the default subscription
* expiration specified by NUTAG_SUB_EXPIRES().
*
* @sa @RFC3265, NUTAG_REFER_EXPIRES(), @Expires, SIPTAG_EXPIRES(),
* SIPTAG_EXPIRES_STR(), @SubscriptionState, nua_respond(), nua_notifier(),
* #nua_r_subscribe, #nua_i_subscribe, #nua_r_refer, #nua_r_notify,
* #nua_i_notify.
*
* Corresponding tag taking reference parameter is NUTAG_SUB_EXPIRES_REF().
*/
tag_typedef_t nutag_sub_expires = UINTTAG_TYPEDEF(substate);
/**@def NUTAG_SUB_EXPIRES_REF(x)
* Reference tag for NUTAG_SUB_EXPIRES().
*/
/**@def NUTAG_NEWSUB()
*
* Send unsolicited NOTIFY request.
......@@ -1077,17 +1111,17 @@ tag_typedef_t nutag_update_refresh = BOOLTAG_TYPEDEF(update_refresh);
* REFER.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_set_hparams() \n
* nua_get_hparams() \n
* nua_handle(), nua_respond() \n
* nua_set_params() or nua_set_hparams() \n
* nua_get_params() or nua_get_hparams()
*
* @par Parameter type
* unsigned int
*
* @par Values
* @c 0 disable \n
* @c >0 interval in seconds
* - default interval in seconds
*
* @sa NUTAG_SUB_EXPIRES()
*
* Corresponding tag taking reference parameter is NUTAG_REFER_EXPIRES_REF().
*/
......
......@@ -497,6 +497,11 @@ SOFIAPUBFUN char const *nua_substate_name(enum nua_substate substate);
/** Convert string to enum nua_substate. @NEW_1_12_5. */
SOFIAPUBFUN enum nua_substate nua_substate_make(char const *sip_substate);
#define NUTAG_SUB_EXPIRES(x) nutag_sub_expires, tag_uint_v(x)
SOFIAPUBVAR tag_typedef_t nutag_sub_expires;
#define NUTAG_SUB_EXPIRES_REF(x) nutag_sub_expires_ref, tag_uint_vr(&(x))
SOFIAPUBVAR tag_typedef_t nutag_sub_expires_ref;
#define NUTAG_NEWSUB(x) nutag_newsub, tag_bool_v(x)
SOFIAPUBVAR tag_typedef_t nutag_newsub;
#define NUTAG_NEWSUB_REF(x) nutag_newsub_ref, tag_bool_vr(&(x))
......
......@@ -203,6 +203,7 @@ int test_nua_params(struct context *ctx)
NUTAG_REFER_EXPIRES(333),
NUTAG_REFER_WITH_ID(0),
NUTAG_SUBSTATE(nua_substate_pending),
NUTAG_SUB_EXPIRES(3700),
NUTAG_KEEPALIVE(66),
NUTAG_KEEPALIVE_STREAM(33),
......@@ -284,6 +285,7 @@ int test_nua_params(struct context *ctx)
int auth_cache = -1;
unsigned refer_expires = (unsigned)-1;
int refer_with_id = -1;
unsigned sub_expires = (unsigned)-1;
int substate = -1;
sip_allow_t const *allow = NONE;
......@@ -352,6 +354,7 @@ int test_nua_params(struct context *ctx)
NUTAG_REFER_EXPIRES_REF(refer_expires),
NUTAG_REFER_WITH_ID_REF(refer_with_id),
NUTAG_SUBSTATE_REF(substate),
NUTAG_SUB_EXPIRES_REF(sub_expires),
SIPTAG_SUPPORTED_REF(supported),
SIPTAG_SUPPORTED_STR_REF(supported_str),
......@@ -382,7 +385,7 @@ int test_nua_params(struct context *ctx)
NUTAG_INSTANCE_REF(instance),
TAG_END());
TEST(n, 50);
TEST(n, 51);
TEST_S(sip_header_as_string(tmphome, (void *)from), Alice);
TEST_S(from_str, Alice);
......@@ -416,6 +419,7 @@ int test_nua_params(struct context *ctx)
TEST(refer_expires, 333);
TEST(refer_with_id, 0);
TEST(substate, nua_substate_pending);
TEST(sub_expires, 3700);
TEST_S(sip_header_as_string(tmphome, (void *)allow), "OPTIONS, INFO, ACK");
TEST_S(allow_str, "OPTIONS, INFO, ACK");
......@@ -492,6 +496,7 @@ int test_nua_params(struct context *ctx)
unsigned refer_expires = (unsigned)-1;
int refer_with_id = -1;
int substate = -1;
unsigned sub_expires = (unsigned)-1;
sip_allow_t const *allow = NONE;
char const *allow_str = "NONE";
......@@ -552,6 +557,7 @@ int test_nua_params(struct context *ctx)
NUTAG_PATH_ENABLE_REF(path_enable),
NUTAG_AUTH_CACHE_REF(auth_cache),
NUTAG_SUBSTATE_REF(substate),
NUTAG_SUB_EXPIRES_REF(sub_expires),
SIPTAG_SUPPORTED_REF(supported),
SIPTAG_SUPPORTED_STR_REF(supported_str),
......@@ -607,6 +613,7 @@ int test_nua_params(struct context *ctx)
TEST(refer_expires, (unsigned)-1);
TEST(refer_with_id, -1);
TEST(substate, -1);
TEST(sub_expires, -1);
TEST_P(allow, NONE);
TEST_S(allow_str, "NONE");
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment