Commit 895516df authored by Pekka Pessi's avatar Pekka Pessi

nua: moved client and server request structures to nua_dialog.h

darcs-hash:20061025080255-65a35-9be7838a49a22ec5c5aed4257368613ff4ade1ec.gz
parent c2335697
......@@ -342,6 +342,20 @@ void nua_dialog_usage_remove_at(nua_owner_t *own,
if (*at) {
nua_dialog_usage_t *du = *at;
sip_event_t const *o = NULL;
nua_client_request_t *cr, *cr_next;
nua_server_request_t *sr, *sr_next;
for (cr = ds->ds_cr; cr; cr = cr_next) {
cr_next = cr->cr_next;
if (cr->cr_usage == du)
cr->cr_usage = NULL;
}
for (sr = ds->ds_sr; sr; sr = sr_next) {
sr_next = sr->sr_next;
if (sr->sr_usage == du)
nua_server_request_destroy(sr);
}
*at = du->du_next;
......@@ -508,13 +522,14 @@ void nua_dialog_usage_refresh_range(nua_dialog_usage_t *du,
}
/**@internal Do not refresh. */
void nua_dialog_usage_no_refresh(nua_dialog_usage_t *du)
void nua_dialog_usage_reset_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_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now)
{
......@@ -523,14 +538,14 @@ void nua_dialog_usage_refresh(nua_owner_t *owner,
if (now > 0) {
if (du->du_class->usage_refresh) {
du->du_class->usage_refresh(owner, du, now);
du->du_class->usage_refresh(owner, ds, du, now);
return;
}
}
else {
du->du_shutdown = 1;
if (du->du_class->usage_shutdown) {
du->du_class->usage_shutdown(owner, du);
du->du_class->usage_shutdown(owner, ds, du);
return;
}
}
......
......@@ -48,8 +48,86 @@ typedef NUA_OWNER_T nua_owner_t;
#include <sofia-sip/nta.h>
#endif
typedef struct nua_server_request nua_server_request_t;
typedef struct nua_client_request nua_client_request_t;
/** Respond to an incoming request. */
typedef int nua_server_respond_f(nua_server_request_t *, tagi_t const *);
/** Restart an outgoing request. */
typedef void nua_creq_restart_f(nua_owner_t *, tagi_t *tags);
/** Server side transaction */
struct nua_server_request {
struct nua_server_request *sr_next, **sr_prev;
nua_owner_t *sr_owner; /**< Backpointer to handle */
nua_dialog_usage_t *sr_usage; /**< Backpointer to usage */
/** When the application responds to an request with
* nua_respond(), the sr_respond() is called
*/
nua_server_respond_f *sr_respond;
nta_incoming_t *sr_irq; /**< Server transaction object */
msg_t *sr_msg; /**< Request message */
sip_method_t sr_method; /**< Request method */
int sr_status; /**< Status code */
char const *sr_phrase; /**< Status phrase */
unsigned sr_auto:1; /**< Autoresponse - no event has been sent */
unsigned sr_initial:1; /**< Handle was created by this request */
/* Flags used with offer-answer */
unsigned sr_offer_recv:1; /**< We have received an offer */
unsigned sr_answer_sent:2; /**< We have answered (reliably, if >1) */
unsigned sr_offer_sent:1; /**< We have offered SDP */
unsigned sr_answer_recv:1; /**< We have received SDP answer */
};
#define SR_INIT(sr) \
(memset((sr), 0, sizeof (sr)[0]), SR_STATUS1((sr), SIP_100_TRYING), sr)
#define SR_STATUS(sr, status, phrase) \
((sr)->sr_phrase = (phrase), (sr)->sr_status = (status))
#define SR_STATUS1(sr, statusphrase) \
sr_status(sr, statusphrase)
su_inline
int sr_status(nua_server_request_t *sr, int status, char const *phrase)
{
return (void)(sr->sr_phrase = phrase), (sr->sr_status = status);
}
struct nua_client_request
{
nua_client_request_t *cr_next; /**< Linked list of requests */
/*nua_event_t*/ int cr_event; /**< Request event */
nua_creq_restart_f *cr_restart;
nta_outgoing_t *cr_orq;
msg_t *cr_msg;
nua_dialog_usage_t *cr_usage;
unsigned short cr_retry_count; /**< Retry count for this request */
/* Flags used with offer-answer */
unsigned short cr_answer_recv; /**< Recv answer in response
* with this status.
*/
unsigned cr_offer_sent:1; /**< Sent offer in this request */
unsigned cr_offer_recv:1; /**< Recv offer in a response */
unsigned cr_answer_sent:1; /**< Sent answer in (PR)ACK */
};
struct nua_dialog_state
{
nua_client_request_t ds_cr[1];
nua_server_request_t *ds_sr;
/** Dialog usages. */
nua_dialog_usage_t *ds_usage;
......@@ -103,8 +181,10 @@ typedef struct {
void (*usage_peer_info)(nua_dialog_usage_t *du,
nua_dialog_state_t const *ds,
sip_t const *sip);
void (*usage_refresh)(nua_owner_t *, nua_dialog_usage_t *, sip_time_t now);
int (*usage_shutdown)(nua_owner_t *, nua_dialog_usage_t *);
void (*usage_refresh)(nua_owner_t *, nua_dialog_state_t *ds,
nua_dialog_usage_t *, sip_time_t now);
int (*usage_shutdown)(nua_owner_t *, nua_dialog_state_t *ds,
nua_dialog_usage_t *);
} nua_usage_class;
......@@ -171,12 +251,13 @@ 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_reset_refresh(nua_dialog_usage_t *du);
void nua_dialog_usage_refresh(nua_owner_t *owner,
nua_dialog_state_t *ds,
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)
{
......@@ -200,4 +281,20 @@ nua_dialog_usage_t *nua_dialog_usage_public(void const *p)
#define nua_dialog_usage_public(p) ((p) ? (nua_dialog_usage_t*)(p) - 1 : NULL)
#endif
/* ---------------------------------------------------------------------- */
void nua_server_request_destroy(nua_server_request_t *sr);
int nua_server_respond(nua_server_request_t *sr,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
msg_t *nua_server_response(nua_server_request_t *sr,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int nua_default_respond(nua_server_request_t *sr,
tagi_t const *tags);
#endif /* NUA_DIALOG_H */
......@@ -58,7 +58,7 @@ static int process_response_to_message(nua_handle_t *nh,
int
nua_stack_message(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
{
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
msg_t *msg;
sip_t *sip;
......@@ -92,16 +92,16 @@ nua_stack_message(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tag
void restart_message(nua_handle_t *nh, tagi_t *tags)
{
nua_creq_restart(nh, nh->nh_cr, process_response_to_message, tags);
nua_creq_restart(nh, nh->nh_ds->ds_cr, process_response_to_message, tags);
}
static int process_response_to_message(nua_handle_t *nh,
nta_outgoing_t *orq,
sip_t const *sip)
{
if (nua_creq_check_restart(nh, nh->nh_cr, orq, sip, restart_message))
if (nua_creq_check_restart(nh, nh->nh_ds->ds_cr, orq, sip, restart_message))
return 0;
return nua_stack_process_response(nh, nh->nh_cr, orq, sip, TAG_END());
return nua_stack_process_response(nh, nh->nh_ds->ds_cr, orq, sip, TAG_END());
}
int nua_stack_process_message(nua_t *nua,
......
......@@ -70,9 +70,11 @@ static void nua_notify_usage_remove(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
static void nua_notify_usage_refresh(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now);
static int nua_notify_usage_shutdown(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
static nua_usage_class const nua_notify_usage[1] = {
......@@ -206,7 +208,7 @@ int nua_stack_process_subscribe(nua_t *nua,
}
sr = nua_server_request(nua, nh, irq, sip, sr, sizeof *sr,
respond_to_subscribe, nua_i_subscribe, 1);
respond_to_subscribe, 1);
if (!du && substate == nua_substate_embryonic && sr->sr_status < 300) {
nh = sr->sr_owner; assert(nh && nh != nua->nua_dhandle);
......@@ -230,7 +232,8 @@ int nua_stack_process_subscribe(nua_t *nua,
sr->sr_usage = du;
return nua_stack_server_event(nua, sr, NUTAG_SUBSTATE(substate), TAG_END());
return nua_stack_server_event(nua, sr, nua_i_subscribe,
NUTAG_SUBSTATE(substate), TAG_END());
}
/** @internal Respond to an SUBSCRIBE request.
......@@ -240,6 +243,7 @@ static
int respond_to_subscribe(nua_server_request_t *sr, tagi_t const *tags)
{
nua_handle_t *nh = sr->sr_owner;
nua_dialog_state_t *ds = nh->nh_ds;
nua_t *nua = nh->nh_nua;
struct notifier_usage *nu;
sip_allow_events_t *allow_events = NUA_PGET(nua, nh, allow_events);
......@@ -271,7 +275,7 @@ int respond_to_subscribe(nua_server_request_t *sr, tagi_t const *tags)
if (nu && nu->nu_substate != nua_substate_embryonic)
/* Send NOTIFY (and terminate subscription, when needed) */
nua_dialog_usage_refresh(nh, sr->sr_usage, sip_now());
nua_dialog_usage_refresh(nh, ds, sr->sr_usage, sip_now());
}
else {
/* XXX - send nua_i_error */
......@@ -339,7 +343,7 @@ int nua_stack_notify2(nua_t *nua,
nua_dialog_usage_t *du,
tagi_t const *tags)
{
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
struct notifier_usage *nu;
msg_t *msg;
sip_t *sip;
......@@ -485,7 +489,7 @@ int nua_stack_notify2(nua_t *nua,
static
void restart_notify(nua_handle_t *nh, tagi_t *tags)
{
nua_creq_restart(nh, nh->nh_cr, process_response_to_notify, tags);
nua_creq_restart(nh, nh->nh_ds->ds_cr, process_response_to_notify, tags);
}
/** @var nua_event_e::nua_r_notify
......@@ -512,28 +516,29 @@ static int process_response_to_notify(nua_handle_t *nh,
{
enum nua_substate substate = nua_substate_terminated;
if (nua_creq_check_restart(nh, nh->nh_cr, orq, sip, restart_notify))
if (nua_creq_check_restart(nh, nh->nh_ds->ds_cr, orq, sip, restart_notify))
return 0;
if (nh->nh_cr->cr_usage) {
struct notifier_usage *nu = nua_dialog_usage_private(nh->nh_cr->cr_usage);
if (nh->nh_ds->ds_cr->cr_usage) {
struct notifier_usage *nu = nua_dialog_usage_private(nh->nh_ds->ds_cr->cr_usage);
substate = nu->nu_substate;
assert(substate != nua_substate_embryonic);
}
return nua_stack_process_response(nh, nh->nh_cr, orq, sip,
return nua_stack_process_response(nh, nh->nh_ds->ds_cr, orq, sip,
NUTAG_SUBSTATE(substate),
TAG_END());
}
static void nua_notify_usage_refresh(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now)
{
struct notifier_usage *nu = nua_dialog_usage_private(du);
if (nh->nh_cr->cr_usage == du) /* Already notifying. */
if (nh->nh_ds->ds_cr->cr_usage == du) /* Already notifying. */
return;
if (now >= nu->nu_expires) {
......@@ -564,15 +569,18 @@ static void nua_notify_usage_refresh(nua_handle_t *nh,
* @retval <0 try again later
*/
static int nua_notify_usage_shutdown(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du)
{
if (!nh->nh_cr->cr_usage) {
nua_client_request_t *cr = nh->nh_ds->ds_cr;
if (!cr->cr_usage) {
/* Unnotify */
nua_stack_notify2(nh->nh_nua, nh, nua_r_destroy, du, NULL);
return nh->nh_cr->cr_usage != du;
return cr->cr_usage != du;
}
if (!du->du_ready && !nh->nh_cr->cr_orq)
if (!du->du_ready && !cr->cr_orq)
return 1; /* Unauthenticated NOTIFY? */
return -1; /* Request in progress */
......
......@@ -58,7 +58,7 @@ static int process_response_to_options(nua_handle_t *nh,
int
nua_stack_options(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
{
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
msg_t *msg;
if (nh_is_special(nh)) {
......@@ -88,16 +88,16 @@ nua_stack_options(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tag
void restart_options(nua_handle_t *nh, tagi_t *tags)
{
nua_creq_restart(nh, nh->nh_cr, process_response_to_options, tags);
nua_creq_restart(nh, nh->nh_ds->ds_cr, process_response_to_options, tags);
}
static int process_response_to_options(nua_handle_t *nh,
nta_outgoing_t *orq,
sip_t const *sip)
{
if (nua_creq_check_restart(nh, nh->nh_cr, orq, sip, restart_options))
if (nua_creq_check_restart(nh, nh->nh_ds->ds_cr, orq, sip, restart_options))
return 0;
return nua_stack_process_response(nh, nh->nh_cr, orq, sip, TAG_END());
return nua_stack_process_response(nh, nh->nh_ds->ds_cr, orq, sip, TAG_END());
}
int nua_stack_process_options(nua_t *nua,
......
......@@ -65,9 +65,11 @@ static void nua_publish_usage_remove(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
static void nua_publish_usage_refresh(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now);
static int nua_publish_usage_shutdown(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
static nua_usage_class const nua_publish_usage[1] = {
......@@ -217,7 +219,7 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
{
nua_dialog_usage_t *du;
struct publish_usage *pu;
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
msg_t *msg = NULL;
sip_t *sip;
int remove_body = 0;
......@@ -246,7 +248,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);
nua_dialog_usage_reset_refresh(du);
pu = nua_dialog_usage_private(du); assert(pu);
if (refresh) {
......@@ -304,7 +306,7 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
static void
restart_publish(nua_handle_t *nh, tagi_t *tags)
{
nua_creq_restart(nh, nh->nh_cr, process_response_to_publish, tags);
nua_creq_restart(nh, nh->nh_ds->ds_cr, process_response_to_publish, tags);
}
......@@ -314,7 +316,7 @@ int process_response_to_publish(nua_handle_t *nh,
sip_t const *sip)
{
int status = sip->sip_status->st_status;
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
nua_dialog_usage_t *du = cr->cr_usage;
struct publish_usage *pu = nua_dialog_usage_private(du);
unsigned saved_retry_count = cr->cr_retry_count + 1;
......@@ -323,7 +325,7 @@ int process_response_to_publish(nua_handle_t *nh,
return 0;
if (status < 200 || pu == NULL)
return nua_stack_process_response(nh, nh->nh_cr, orq, sip, TAG_END());
return nua_stack_process_response(nh, cr, orq, sip, TAG_END());
if (pu->pu_etag)
su_free(nh->nh_home, pu->pu_etag), pu->pu_etag = NULL;
......@@ -367,15 +369,16 @@ int process_response_to_publish(nua_handle_t *nh,
}
}
return nua_stack_process_response(nh, nh->nh_cr, orq, sip, TAG_END());
return nua_stack_process_response(nh, cr, orq, sip, TAG_END());
}
static void nua_publish_usage_refresh(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now)
{
if (nh->nh_cr->cr_usage == du) /* Already publishing. */
if (ds->ds_cr->cr_usage == du) /* Already publishing. */
return;
nua_stack_publish2(nh->nh_nua, nh, nua_r_publish, 1, NULL);
}
......@@ -387,16 +390,19 @@ static void nua_publish_usage_refresh(nua_handle_t *nh,
* @retval <0 try again later
*/
static int nua_publish_usage_shutdown(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du)
{
if (!nh->nh_cr->cr_usage) {
nua_client_request_t *cr = ds->ds_cr;
if (!cr->cr_usage) {
/* Unpublish */
nua_stack_publish2(nh->nh_nua, nh, nua_r_destroy, 1, NULL);
return nh->nh_cr->cr_usage != du;
return cr->cr_usage != du;
}
if (!du->du_ready && !nh->nh_cr->cr_orq)
return 1; /* Unauthenticated initial request */
if (!du->du_ready && !cr->cr_orq)
return 1; /* had unauthenticated initial request */
return -1; /* Request in progress */
}
......@@ -451,9 +457,9 @@ int nua_stack_process_publish(nua_t *nua,
SR_STATUS1(sr, SIP_489_BAD_EVENT);
sr = nua_server_request(nua, nh, irq, sip, sr, sizeof *sr,
respond_to_publish, nua_i_publish, 0);
respond_to_publish, 0);
return nua_stack_server_event(nua, sr, TAG_END());
return nua_stack_server_event(nua, sr, nua_i_publish, TAG_END());
}
static
......
......@@ -107,9 +107,13 @@ static void nua_register_usage_remove(nua_handle_t *nh,
static void nua_register_usage_peer_info(nua_dialog_usage_t *du,
nua_dialog_state_t const *ds,
sip_t const *sip);
static void nua_register_usage_refresh(nua_handle_t *, nua_dialog_usage_t *,
static void nua_register_usage_refresh(nua_handle_t *,
nua_dialog_state_t *,
nua_dialog_usage_t *,
sip_time_t);
static int nua_register_usage_shutdown(nua_handle_t *, nua_dialog_usage_t *);
static int nua_register_usage_shutdown(nua_handle_t *,
nua_dialog_state_t *,
nua_dialog_usage_t *);
/** REGISTER usage, aka nua_registration_t */
struct register_usage {
......@@ -512,7 +516,7 @@ nua_stack_register(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_dialog_usage_t *du;
nua_registration_t *nr = NULL;
outbound_t *ob = NULL;
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
msg_t *msg = NULL;
sip_t *sip;
int terminating = e != nua_r_register;
......@@ -622,7 +626,7 @@ nua_stack_register(nua_t *nua, nua_handle_t *nh, nua_event_t e,
static void
restart_register(nua_handle_t *nh, tagi_t *tags)
{
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
msg_t *msg;
nua_dialog_usage_t *du = cr->cr_usage;
nua_registration_t *nr = nua_dialog_usage_private(du);
......@@ -662,11 +666,12 @@ restart_register(nua_handle_t *nh, tagi_t *tags)
/** Refresh registration */
static
void nua_register_usage_refresh(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du,
sip_time_t now)
{
nua_t *nua = nh->nh_nua;
nua_client_request_t *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
nua_registration_t *nr = nua_dialog_usage_private(du);
msg_t *msg;
sip_t *sip;
......@@ -719,10 +724,12 @@ void nua_register_usage_refresh(nua_handle_t *nh,
* Called when stack is shut down or handle is destroyed. Unregister.
*/
static
int nua_register_usage_shutdown(nua_handle_t *nh, nua_dialog_usage_t *du)
int nua_register_usage_shutdown(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du)
{
nua_t *nua = nh->nh_nua;
nua_client_request_t *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
nua_registration_t *nr = nua_dialog_usage_private(du);
msg_t *msg;
sip_t *sip;
......@@ -777,7 +784,7 @@ int process_response_to_register(nua_handle_t *nh,
nta_outgoing_t *orq,
sip_t const *sip)
{
struct nua_client_request *cr = nh->nh_cr;
nua_client_request_t *cr = nh->nh_ds->ds_cr;
nua_dialog_usage_t *du = cr->cr_usage;
nua_registration_t *nr = nua_dialog_usage_private(du);
int status, ready, reregister, terminating;
......@@ -1149,7 +1156,7 @@ nua_stack_init_registrations(nua_t *nua)
du = ds->ds_usage;
if (ds->ds_has_register == 1 && du->du_class->usage_refresh) {
nua_dialog_usage_refresh(*nh_list, du, 1);
nua_dialog_usage_refresh(*nh_list, ds, du, 1);
}
}
......@@ -1671,13 +1678,18 @@ void unregister_expires_contacts(msg_t *msg, sip_t *sip)
}
/** Outbound requests us to refres registration */
/** Outbound requests us to refresh registration */
static int nua_stack_outbound_refresh(nua_handle_t *nh,
outbound_t *ob)
{
nua_dialog_usage_t *du = nua_dialog_usage_get(nh->nh_ds, nua_register_usage, NULL);
nua_dialog_state_t *ds = nh->nh_ds;
nua_dialog_usage_t *du;
du = nua_dialog_usage_get(ds, nua_register_usage, NULL);
if (du)
nua_dialog_usage_refresh(nh, du, 1);
nua_dialog_usage_refresh(nh, ds, du, 1);
return 0;
}
......
......@@ -62,7 +62,7 @@ int nua_stack_process_register(nua_t *nua,
nua_server_request_t *sr, sr0[1];
sr = nua_server_request(nua, nh, irq, sip, SR_INIT(sr0), sizeof *sr,
nua_default_respond, nua_i_register, 0);
nua_default_respond, 0);
return nua_stack_server_event(nua, sr, TAG_END());
return nua_stack_server_event(nua, sr, nua_i_register, TAG_END());
}
This diff is collapsed.
......@@ -468,10 +468,11 @@ void nua_stack_timer(nua_t *nua, su_timer_t *t, su_timer_arg_t *a)
static
int nh_call_pending(nua_handle_t *nh, sip_time_t now)
{
nua_dialog_state_t *ds = nh->nh_ds;
nua_dialog_usage_t *du;
sip_time_t next = now + NUA_STACK_TIMER_INTERVAL / 1000;
for (du = nh->nh_ds->ds_usage; du; du = du->du_next) {
for (du = ds->ds_usage; du; du = du->du_next) {
if (now == 0)
break;
if (du->du_refresh && du->du_refresh < next)
......@@ -486,7 +487,7 @@ int nh_call_pending(nua_handle_t *nh, sip_time_t now)
while (du) {
nua_dialog_usage_t *du_next = du->du_next;
nua_dialog_usage_refresh(nh, du, now);
nua_dialog_usage_refresh(nh, ds, du, now);
if (du_next == NULL)
break;
......@@ -526,11 +527,12 @@ void nua_stack_shutdown(nua_t *nua)
nua->nua_shutdown = now;
for (nh = nua->nua_handles; nh; nh = nh_next) {
nua_dialog_state_t *ds = nh->nh_ds;
nua_server_request_t *sr, *sr_next;
nh_next = nh->nh_next;
for (sr = nh->nh_sr; sr; sr = sr_next) {
for (sr = ds->ds_sr; sr; sr = sr_next) {
sr_next = sr->sr_next;
if (sr->sr_respond) {
......@@ -550,7 +552,7 @@ void nua_stack_shutdown(nua_t *nua)
soa_destroy(nh->nh_soa), nh->nh_soa = NULL;
}
if (nua_client_request_pending(nh->nh_cr))
if (nua_client_request_pending(ds->ds_cr))
busy++;
if (nh_notifier_shutdown(nh, NULL, NEATAG_REASON("noresource"), TAG_END()))
......@@ -669,7 +671,7 @@ void nh_destroy(nua_t *nua, nua_handle_t *nh)
if (nh->nh_notifier)
nea_server_destroy(nh->nh_notifier), nh->nh_notifier = NULL;
nua_creq_deinit(nh->nh_cr, NULL);
nua_creq_deinit(nh->nh_ds->ds_cr, NULL);
nua_dialog_deinit(nh, nh->nh_ds);
......@@ -916,7 +918,7 @@ int nua_tagis_have_contact_tag(tagi_t const *t)
*/
msg_t *nua_creq_msg(nua_t *nua,
nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
int restart,
sip_method_t method, char const *name,
tag_type_t tag, tag_value_t value, ...)
......@@ -1228,7 +1230,7 @@ nua_client_request_by_orq(nua_client_request_t const *cr,
return NULL;
}
void nua_creq_deinit(struct nua_client_request *cr, nta_outgoing_t *orq)
void nua_creq_deinit(nua_client_request_t *cr, nta_outgoing_t *orq)
{
if (orq == NULL || orq == cr->cr_orq) {
cr->cr_retry_count = 0;
......@@ -1351,7 +1353,7 @@ nua_stack_method(nua_t *nua, nua_handle_t *nh, nua_event_t e,
* release the handle with nh_destroy().
*/
int nua_stack_process_response(nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
nta_outgoing_t *orq,
sip_t const *sip,
tag_type_t tag, tag_value_t value, ...)
......@@ -1370,10 +1372,10 @@ int nua_stack_process_response(nua_handle_t *nh,
else
final = status >= 200;
if (final) {
if (final && cr) {
nua_creq_deinit(cr, orq);
if (cr->cr_usage && nh->nh_cr == cr) {
if (cr->cr_usage && nh->nh_ds->ds_cr == cr) {
if ((status >= 300 && !cr->cr_usage->du_ready) ||
cr->cr_usage->du_terminating)
nua_dialog_usage_remove(nh, nh->nh_ds, cr->cr_usage);
......@@ -1412,7 +1414,7 @@ int can_redirect(sip_contact_t const *m, sip_method_t method)
}
int nua_creq_restart_with(nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
nta_outgoing_t *orq,
int status, char const *phrase,
nua_creq_restart_f *f,
......@@ -1438,7 +1440,7 @@ int nua_creq_restart_with(nua_handle_t *nh,
/** @internal Save operation until it can be restarted */
int nua_creq_save_restart(nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
nta_outgoing_t *orq,
int status, char const *phrase,
nua_creq_restart_f *restart_function)
......@@ -1464,7 +1466,7 @@ int nua_creq_save_restart(nua_handle_t *nh,
*
*/
int nua_creq_check_restart(nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
nta_outgoing_t *orq,
sip_t const *sip,
nua_creq_restart_f *restart_function)
......@@ -1567,7 +1569,7 @@ int nua_creq_check_restart(nua_handle_t *nh,
/** @internal Restart a request */
int nua_creq_restart(nua_handle_t *nh,
struct nua_client_request *cr,
nua_client_request_t *cr,
nta_response_f *cb,
tagi_t *tags)
{
......@@ -1605,7 +1607,7 @@ nua_stack_authenticate(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_client_request_t *cr;
nua_creq_restart_f *restart = NULL;
cr = nua_client_request_restarting(nh->nh_cr);
cr = nua_client_request_restarting(nh->nh_ds->ds_cr);
if (cr)
restart = cr->cr_restart, cr->cr_restart = NULL;
......@@ -1754,7 +1756,6 @@ nua_server_request_t *nua_server_request(nua_t *nua,