Commit fa668c75 authored by Pekka Pessi's avatar Pekka Pessi

nua_dialog.h, nua_dialog.c: added nua_dialog_remove(),...

nua_dialog.h, nua_dialog.c: added nua_dialog_remove(), nua_dialog_usage_refresh_range() and nua_dialog_usage_no_refresh().

darcs-hash:20060817183556-65a35-0150b68e9fc686007e18fbd0126ade7e3835e5d5.gz
parent 279c2a00
......@@ -40,6 +40,7 @@
#include <assert.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/sip_protos.h>
......@@ -181,6 +182,21 @@ void nua_dialog_store_peer_info(nua_owner_t *own,
}
}
/** Remove dialog (if there is no other usages). */
int nua_dialog_remove(nua_owner_t *own,
nua_dialog_state_t *ds,
nua_dialog_usage_t *usage)
{
if (ds->ds_usage == usage && (usage == NULL || usage->du_next == NULL)) {
nua_dialog_store_peer_info(own, ds, NULL); /* zap peer info */
nta_leg_destroy(ds->ds_leg), ds->ds_leg = NULL;
su_free(own, (void *)ds->ds_remote_tag), ds->ds_remote_tag = NULL;
ds->ds_route = 0;
}
return 0;
}
/** @internal Get dialog usage slot. */
nua_dialog_usage_t **
nua_dialog_usage_at(nua_dialog_state_t const *ds,
......@@ -421,24 +437,49 @@ void nua_dialog_terminated(nua_owner_t *own,
*/
void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta)
{
sip_time_t target = sip_now();
if (delta > 90 && delta < 5 * 60)
if (delta == 0)
du->du_refresh = SIP_TIME_MAX;
else if (delta > 90 && delta < 5 * 60)
/* refresh 30..60 seconds before deadline */
delta -= su_randint(30, 60);
else if (delta > 1)
nua_dialog_usage_refresh_range(du, delta - 60, delta - 30);
else
/* refresh around half time before deadline */
delta = (delta + 3) / 4 + su_randint(0, delta / 2);
nua_dialog_usage_refresh_range(du, delta / 4, delta / 2 + delta / 4);
}
/**@internal Set refresh in range min..max seconds in the future. */
void nua_dialog_usage_refresh_range(nua_dialog_usage_t *du,
unsigned min, unsigned max)
{
sip_time_t now = sip_now(), target;
unsigned delta;
if (max < min)
max = min;
if (min != max)
delta = su_randint(min, max);
else
delta = min;
if (delta != 0 && target + delta >= target)
target = target + delta;
if (now + delta >= now)
target = now + delta;
else
target = SIP_TIME_MAX;
SU_DEBUG_7(("nua(): refresh %s after %lu seconds (in [%u..%u])\n",
nua_dialog_usage_name(du), target - now, min, max));
du->du_refresh = target;
}
/** @internal Call the owner operation function. */
/**@internal Do not refresh. */
void nua_dialog_usage_no_refresh(nua_dialog_usage_t *du)
{
du->du_refresh = 0;
}
/** @internal Refresh usage or shutdown usage if @a now is 0. */
void nua_dialog_usage_refresh(nua_owner_t *owner,
nua_dialog_usage_t *du,
sip_time_t now)
......
......@@ -22,7 +22,8 @@
*
*/
#ifndef NUA_DIALOG_H /** Defined when <nua_dialog.h> has been included. */
#ifndef NUA_DIALOG_H
/** Defined when <nua_dialog.h> has been included. */
#define NUA_DIALOG_H
/**@IFILE nua_dialog.h
......@@ -86,6 +87,7 @@ typedef void nh_pending_f(nua_owner_t *,
nua_dialog_usage_t *du,
sip_time_t now);
/** Virtual function pointer table for dialog usage. */
typedef struct {
unsigned usage_size, usage_class_size;
int (*usage_add)(nua_owner_t *,
......@@ -102,6 +104,8 @@ typedef struct {
int (*usage_shutdown)(nua_owner_t *, nua_dialog_usage_t *);
} nua_usage_class;
/** Base structure for dialog usage. */
struct nua_dialog_usage {
nua_dialog_usage_t *du_next;
nua_usage_class const *du_class;
......@@ -122,6 +126,7 @@ struct nua_dialog_usage {
sip_time_t du_refresh; /**< When execute du_pending */
sip_event_t const *du_event; /**< Event of usage */
msg_t *du_msg; /**< Template message */
};
......@@ -131,6 +136,9 @@ void nua_dialog_uas_route(nua_owner_t *, nua_dialog_state_t *ds,
sip_t const *sip, int rtag);
void nua_dialog_store_peer_info(nua_owner_t *, nua_dialog_state_t *ds,
sip_t const *sip);
int nua_dialog_remove(nua_owner_t *own,
nua_dialog_state_t *ds,
nua_dialog_usage_t *usage);
char const *nua_dialog_usage_name(nua_dialog_usage_t const *du);
......@@ -154,10 +162,14 @@ void nua_dialog_terminated(nua_owner_t *,
void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta);
void nua_dialog_usage_refresh_range(nua_dialog_usage_t *du,
unsigned min, unsigned max);
void nua_dialog_usage_refresh(nua_owner_t *owner,
nua_dialog_usage_t *du,
sip_time_t now);
void nua_dialog_usage_no_refresh(nua_dialog_usage_t *du);
static inline
int nua_dialog_is_established(nua_dialog_state_t const *ds)
......
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