Commit 0e35974d authored by Pekka Pessi's avatar Pekka Pessi

nua: updated dialog and session state handling.

No more using expicitly set du_pending function pointer but a function
pointer table used by dialog_usage.

Changes in nua_dialog.c, nua_dialog.h, nua_publish.c, nua_register.c,
nua_session.c, nua_subnotref.c, nua_stack.h, nua_stack.c.

Added nua_notifier.c and moved notifier side of SIP event protocol to it.
Added nua_notifier.c to Makefile.am, too.

darcs-hash:20060821162147-65a35-871aef45582afdc6ed7e62711c0dfb12408ab4a9.gz
parent cd9b3d9c
......@@ -49,6 +49,7 @@ libnua_la_SOURCES = nua.c nua_stack.h nua_common.c nua_stack.c \
nua_params.c nua_params.h \
nua_register.c nua_session.c nua_options.c \
nua_message.c nua_publish.c nua_subnotref.c \
nua_notifier.c \
nua_event_server.c \
nua_tag.c nua_tag_ref.c
......
......@@ -424,6 +424,22 @@ void nua_dialog_terminated(nua_owner_t *own,
}
}
/**@internal
* Set expiration time.
*/
void nua_dialog_usage_set_expires(nua_dialog_usage_t *du,
unsigned delta)
{
if (delta) {
sip_time_t now = sip_now(), expires = now + delta;
if (expires < now)
expires = SIP_TIME_MAX;
du->du_expires = expires;
nua_dialog_usage_set_refresh(du, delta);
}
else
du->du_expires = 0, du->du_refresh = 0;
}
/**@internal
* Set refresh value suitably.
......@@ -438,13 +454,18 @@ void nua_dialog_terminated(nua_owner_t *own,
void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta)
{
if (delta == 0)
du->du_refresh = SIP_TIME_MAX;
du->du_refresh = 0;
else if (delta > 90 && delta < 5 * 60)
/* refresh 30..60 seconds before deadline */
nua_dialog_usage_refresh_range(du, delta - 60, delta - 30);
else
/* refresh around half time before deadline */
nua_dialog_usage_refresh_range(du, delta / 4, delta / 2 + delta / 4);
else {
/* By default, refresh around half time before deadline */
unsigned min = (delta + 2) / 4;
unsigned max = (delta + 2) / 4 + (delta + 1) / 2;
if (min == 0)
min = 1;
nua_dialog_usage_refresh_range(du, min, max);
}
}
/**@internal Set refresh in range min..max seconds in the future. */
......@@ -485,8 +506,6 @@ void nua_dialog_usage_refresh(nua_owner_t *owner,
sip_time_t now)
{
if (du) {
nh_pending_f *pending = du->du_pending;
du->du_refresh = 0;
if (now > 0) {
......@@ -502,11 +521,6 @@ void nua_dialog_usage_refresh(nua_owner_t *owner,
return;
}
}
du->du_pending = NULL;
if (pending)
pending(owner, du, now);
}
}
......@@ -115,15 +115,13 @@ struct nua_dialog_usage {
unsigned du_shutdown:1; /**< Shutdown in progress */
unsigned:0;
/** Pending operation.
*
* The du_pending() is called
* a) when current time sip_now() will soon exceed du_refresh (now > 1)
* b) when operation is restarted (now is 1)
* c) when usage is destroyed (now is 0)
/** When usage expires.
* Non-zero if the usage is established, SIP_TIME_MAX if there no
* expiration time.
*/
nh_pending_f *du_pending;
sip_time_t du_refresh; /**< When execute du_pending */
sip_time_t du_expires;
sip_time_t du_refresh; /**< When to refresh */
sip_event_t const *du_event; /**< Event of usage */
......@@ -160,6 +158,8 @@ void nua_dialog_terminated(nua_owner_t *,
int status,
char const *phrase);
void nua_dialog_usage_set_expires(nua_dialog_usage_t *du, unsigned delta);
void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta);
void nua_dialog_usage_refresh_range(nua_dialog_usage_t *du,
......
This diff is collapsed.
......@@ -166,8 +166,7 @@ static int process_response_to_publish(nua_handle_t *nh,
*/
/**@fn \
* void nua_unpublish(nua_handle_t *nh, \
* tag_type_t tag, tag_value_t value, ...);
void nua_unpublish(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...);
*
* Send un-PUBLISH request to publication server.
*
......@@ -245,6 +244,7 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
if (!du)
return UA_EVENT1(e, NUA_INTERNAL_ERROR);
nua_dialog_usage_no_refresh(du);
pu = nua_dialog_usage_private(du); assert(pu);
if (refresh) {
......@@ -294,7 +294,7 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
error:
msg_destroy(msg);
if (!du->du_ready)
if (!du->du_ready == 0)
nua_dialog_usage_remove(nh, nh->nh_ds, du);
return UA_EVENT1(e, NUA_INTERNAL_ERROR);
}
......@@ -342,7 +342,7 @@ int process_response_to_publish(nua_handle_t *nh,
if (status < 300 && !invalid_expiration && !retry) {
pu->pu_etag = sip_etag_dup(nh->nh_home, sip->sip_etag);
du->du_ready = 1;
nua_dialog_usage_set_refresh(du, sip->sip_expires->ex_delta);
nua_dialog_usage_set_expires(du, sip->sip_expires->ex_delta);
}
else if (retry && saved_retry_count < NH_PGET(nh, retry_count)) {
msg_t *response = nta_outgoing_getresponse(orq);
......@@ -364,7 +364,6 @@ int process_response_to_publish(nua_handle_t *nh,
cr->cr_usage = NULL;
return 0;
}
}
return nua_stack_process_response(nh, nh->nh_cr, orq, sip, TAG_END());
......@@ -375,7 +374,7 @@ static void nua_publish_usage_refresh(nua_handle_t *nh,
nua_dialog_usage_t *du,
sip_time_t now)
{
if (nh->nh_cr->cr_usage == du)
if (nh->nh_cr->cr_usage == du) /* Already publishing. */
return;
nua_stack_publish2(nh->nh_nua, nh, nua_r_publish, 1, NULL);
}
......
......@@ -604,8 +604,8 @@ void nua_register_usage_refresh(nua_handle_t *nh,
return;
if (cr->cr_msg) {
/* Busy, delay of 5 .. 15 seconds */
nua_dialog_usage_set_refresh(du, 5 + (unsigned)random() % 11U);
/* Dialog is busy, delay of 5 .. 15 seconds */
nua_dialog_usage_refresh_range(du, 5, 15);
return;
}
......@@ -763,9 +763,8 @@ int process_response_to_register(nua_handle_t *nh,
du->du_ready = ready;
if (status < 300) {
sip_time_t mindelta = 0;
if (!du->du_terminating) {
sip_time_t mindelta = 0;
sip_time_t now = sip_now(), delta, reqdelta;
sip_contact_t const *m, *sent;
......@@ -798,9 +797,10 @@ int process_response_to_register(nua_handle_t *nh,
if (mindelta == SIP_TIME_MAX)
mindelta = 3600;
nua_dialog_usage_set_expires(du, mindelta);
}
nua_dialog_usage_set_refresh(du, mindelta);
else
nua_dialog_usage_set_expires(du, 0);
}
#if HAVE_SIGCOMP
......@@ -1076,7 +1076,6 @@ nua_stack_init_registrations(nua_t *nua)
du = ds->ds_usage;
if (ds->ds_has_register == 1 && du->du_class->usage_refresh) {
du->du_refresh = sip_now();
nua_dialog_usage_refresh(*nh_list, du, 1);
}
}
......
This diff is collapsed.
......@@ -1335,10 +1335,8 @@ int nua_creq_save_restart(nua_handle_t *nh,
TAG_END());
nta_outgoing_destroy(orq);
if (du) {
du->du_pending = NULL;
if (du)
du->du_refresh = 0;
}
cr->cr_restart = restart_function;
return 1;
......@@ -1455,7 +1453,6 @@ int nua_creq_check_restart(nua_handle_t *nh,
cr->cr_orq = orq;
if (du) {
du->du_pending = NULL;
du->du_refresh = 0;
}
......
......@@ -132,7 +132,8 @@ typedef struct nua_session_state
unsigned ss_precondition:1; /**< Precondition required */
unsigned ss_hold_remote:1; /**< We are holding remote */
unsigned ss_timer_set:1; /**< We have active session timer. */
unsigned : 0;
unsigned ss_session_timer; /**< Value of Session-Expires (delta) */
......
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