Commit c68ed147 authored by Pekka Pessi's avatar Pekka Pessi
Browse files

Using nua_owner_t instead of nua_handle_t with <nua_dialog.h>.

Prepare to move nua_dialog.[hc] to nta or to its own module.

darcs-hash:20060308225203-65a35-723e9f88e32f22d5845d59d9e2623da45264e067.gz
parent 95bda1af
......@@ -42,23 +42,42 @@
#include <sofia-sip/string0.h>
#include <sofia-sip/sip_protos.h>
#define NUA_OWNER_T su_home_t
#include "nua_dialog.h"
#define SU_LOG (nua_log)
#include <sofia-sip/su_debug.h>
#ifndef NONE
#define NONE ((void *)-1)
#endif
/* ======================================================================== */
/* Dialog handling */
static void nua_dialog_usage_remove_at(nua_handle_t*, nua_dialog_state_t*,
static void nua_dialog_usage_remove_at(nua_owner_t*, nua_dialog_state_t*,
nua_dialog_usage_t**);
static void nua_dialog_log_usage(nua_handle_t *, nua_dialog_state_t *);
static void nua_dialog_log_usage(nua_owner_t *, nua_dialog_state_t *);
/** UAS tag and route */
void nua_dialog_uas_route(nua_handle_t *nh, sip_t const *sip, int rtag)
/** UAS tag and route.
*
* Update dialog tags and route on the UAS side.
*
* @param own dialog owner
* @param sip SIP message containing response used to update dialog
* @param rtag if true, set remote tag within the leg
*/
void nua_dialog_uas_route(nua_owner_t *own,
nua_dialog_state_t *ds,
sip_t const *sip,
int rtag)
{
struct nua_dialog_state *ds = nh->nh_ds;
int established = nua_dialog_is_established(ds);
if (!established && sip->sip_from->a_tag)
ds->ds_remote_tag = su_strdup(nh->nh_home, sip->sip_from->a_tag);
ds->ds_remote_tag = su_strdup(own, sip->sip_from->a_tag);
if (ds->ds_leg == NULL)
return;
......@@ -74,17 +93,19 @@ void nua_dialog_uas_route(nua_handle_t *nh, sip_t const *sip, int rtag)
*
* Update dialog tags and route on the UAC side.
*
* @param nh NUA handle
* @param own dialog owner
* @param sip SIP message containing response used to update dialog
* @param rtag if true, set remote tag within the leg
*/
void nua_dialog_uac_route(nua_handle_t *nh, sip_t const *sip, int rtag)
void nua_dialog_uac_route(nua_owner_t *own,
nua_dialog_state_t *ds,
sip_t const *sip,
int rtag)
{
struct nua_dialog_state *ds = nh->nh_ds;
int established = nua_dialog_is_established(ds);
if (!established && sip->sip_to->a_tag)
ds->ds_remote_tag = su_strdup(nh->nh_home, sip->sip_to->a_tag);
ds->ds_remote_tag = su_strdup(own, sip->sip_to->a_tag);
if (ds->ds_leg == NULL)
return;
......@@ -97,35 +118,42 @@ void nua_dialog_uac_route(nua_handle_t *nh, sip_t const *sip, int rtag)
}
/** Store information from remote endpoint. */
void nua_dialog_get_peer_info(nua_handle_t *nh, sip_t const *sip)
void nua_dialog_store_peer_info(nua_owner_t *own,
nua_dialog_state_t *ds,
sip_t const *sip)
{
nua_remote_t *nr = nh->nh_ds->ds_remote_ua, old[1];
nua_remote_t *nr = ds->ds_remote_ua;
nua_remote_t old[1];
*old = *nr;
if (sip->sip_allow) {
nr->nr_allow = sip_allow_dup(nh->nh_home, sip->sip_allow);
su_free(nh->nh_home, old->nr_allow);
nr->nr_allow = sip_allow_dup(own, sip->sip_allow);
su_free(own, old->nr_allow);
}
if (sip->sip_accept) {
nr->nr_accept = sip_accept_dup(nh->nh_home, sip->sip_accept);
su_free(nh->nh_home, old->nr_accept);
nr->nr_accept = sip_accept_dup(own, sip->sip_accept);
su_free(own, old->nr_accept);
}
if (sip->sip_require) {
nr->nr_require = sip_require_dup(nh->nh_home, sip->sip_require);
su_free(nh->nh_home, old->nr_require);
nr->nr_require = sip_require_dup(own, sip->sip_require);
su_free(own, old->nr_require);
}
if (sip->sip_supported) {
nr->nr_supported = sip_supported_dup(nh->nh_home, sip->sip_supported);
su_free(nh->nh_home, old->nr_supported);
nr->nr_supported = sip_supported_dup(own, sip->sip_supported);
su_free(own, old->nr_supported);
}
if (sip->sip_user_agent) {
nr->nr_user_agent = sip_user_agent_dup(nh->nh_home, sip->sip_user_agent);
su_free(nh->nh_home, old->nr_user_agent);
nr->nr_user_agent = sip_user_agent_dup(own, sip->sip_user_agent);
su_free(own, old->nr_user_agent);
}
else if (sip->sip_server) {
nr->nr_user_agent = sip_user_agent_dup(own, sip->sip_server);
su_free(own, old->nr_user_agent);
}
}
......@@ -186,7 +214,7 @@ char const *nua_dialog_usage_name(nua_dialog_usage_t const *du)
}
/** Add dialog usage */
nua_dialog_usage_t *nua_dialog_usage_add(nua_handle_t *nh,
nua_dialog_usage_t *nua_dialog_usage_add(nua_owner_t *own,
struct nua_dialog_state *ds,
nua_usage_class const *uclass,
sip_event_t const *event)
......@@ -199,7 +227,7 @@ nua_dialog_usage_t *nua_dialog_usage_add(nua_handle_t *nh,
du = *prev_du;
if (du) { /* Already exists */
SU_DEBUG_5(("nua(%p): adding already existing %s usage%s%s\n",
nh, nua_dialog_usage_name(du),
own, nua_dialog_usage_name(du),
event ? " with event " : "", event ? event->o_type : ""));
if (prev_du != &ds->ds_usage) {
......@@ -211,45 +239,45 @@ nua_dialog_usage_t *nua_dialog_usage_add(nua_handle_t *nh,
return du;
}
o = event ? sip_event_dup(nh->nh_home, event) : NULL;
o = event ? sip_event_dup(own, event) : NULL;
if (o != NULL || event == NULL)
du = su_zalloc(nh->nh_home, sizeof *du + uclass->usage_size);
du = su_zalloc(own, sizeof *du + uclass->usage_size);
if (du) {
du->du_class = uclass;
du->du_event = o;
if (uclass->usage_add(nh, ds, du) < 0) {
su_free(nh->nh_home, o);
su_free(nh->nh_home, du);
if (uclass->usage_add(own, ds, du) < 0) {
su_free(own, o);
su_free(own, du);
return NULL;
}
SU_DEBUG_5(("nua(%p): adding %s usage%s%s\n",
nh, nua_dialog_usage_name(du),
own, nua_dialog_usage_name(du),
o ? " with event " : "", o ? o->o_type :""));
nua_handle_ref(nh);
su_home_ref(own);
du->du_next = ds->ds_usage, ds->ds_usage = du;
return du;
}
su_free(nh->nh_home, o);
su_free(own, o);
}
return NULL;
}
/** Remove dialog usage. */
void nua_dialog_usage_remove(nua_handle_t *nh,
void nua_dialog_usage_remove(nua_owner_t *own,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du)
{
nua_dialog_usage_t **at;
assert(nh); assert(ds); assert(du);
assert(own); assert(ds); assert(du);
for (at = &ds->ds_usage; *at; at = &(*at)->du_next)
if (du == *at)
......@@ -257,7 +285,7 @@ void nua_dialog_usage_remove(nua_handle_t *nh,
assert(*at);
nua_dialog_usage_remove_at(nh, ds, at);
nua_dialog_usage_remove_at(own, ds, at);
}
/** Remove dialog usage.
......@@ -265,7 +293,7 @@ void nua_dialog_usage_remove(nua_handle_t *nh,
* Zap dialog state (leg, tag and route) if no usages remain.
*/
static
void nua_dialog_usage_remove_at(nua_handle_t *nh,
void nua_dialog_usage_remove_at(nua_owner_t *own,
nua_dialog_state_t *ds,
nua_dialog_usage_t **at)
{
......@@ -278,34 +306,34 @@ void nua_dialog_usage_remove_at(nua_handle_t *nh,
o = du->du_event;
SU_DEBUG_5(("nua(%p): removing %s usage%s%s\n",
nh, nua_dialog_usage_name(du),
own, nua_dialog_usage_name(du),
o ? " with event " : "", o ? o->o_type :""));
du->du_class->usage_remove(nh, ds, du);
du->du_class->usage_remove(own, ds, du);
msg_destroy(du->du_msg);
nua_handle_unref(nh);
su_free(nh->nh_home, du);
su_home_unref(own);
su_free(own, du);
}
/* Zap dialog if there is no more usages */
if (ds->ds_usage == NULL) {
nta_leg_destroy(ds->ds_leg), ds->ds_leg = NULL;
su_free(nh->nh_home, (void *)ds->ds_remote_tag), ds->ds_remote_tag = NULL;
su_free(own, (void *)ds->ds_remote_tag), ds->ds_remote_tag = NULL;
ds->ds_route = 0;
ds->ds_has_events = 0;
ds->ds_terminated = 0;
return;
}
else if (!ds->ds_terminated) {
nua_dialog_log_usage(nh, ds);
nua_dialog_log_usage(own, ds);
}
}
static
void nua_dialog_log_usage(nua_handle_t *nh, nua_dialog_state_t *ds)
void nua_dialog_log_usage(nua_owner_t *own, nua_dialog_state_t *ds)
{
nua_dialog_usage_t *du;
if (nua_log->log_level >= 3) {
if (SU_LOG->log_level >= 3) {
char buffer[160];
int l = 0, n, N = sizeof buffer;
......@@ -327,7 +355,7 @@ void nua_dialog_log_usage(nua_handle_t *nh, nua_dialog_state_t *ds)
}
}
SU_DEBUG_3(("nua(%p): handle with %s%s%s\n", nh,
SU_DEBUG_3(("nua(%p): handle with %s%s%s\n", own,
ds->ds_has_session ? "session and " : "",
ds->ds_has_events ? "events " : "",
buffer));
......@@ -335,7 +363,7 @@ void nua_dialog_log_usage(nua_handle_t *nh, nua_dialog_state_t *ds)
}
/** Dialog has been terminated. */
void nua_dialog_terminated(nua_handle_t *nh,
void nua_dialog_terminated(nua_owner_t *own,
struct nua_dialog_state *ds,
int status,
char const *phrase)
......@@ -352,7 +380,7 @@ void nua_dialog_terminated(nua_handle_t *nh,
else
/* XXX */;
#endif
nua_dialog_usage_remove_at(nh, ds, &ds->ds_usage);
nua_dialog_usage_remove_at(own, ds, &ds->ds_usage);
}
}
......@@ -383,70 +411,3 @@ void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta)
du->du_refresh = target;
}
#if 0
switch (kind) {
case nua_session_usage:
ds->ds_has_session = 0;
break;
case nua_notifier_usage:
su_free(nh->nh_home, (void *)du->du_event);
ds->ds_has_notifier = NULL != *nua_dialog_usage_at(ds, kind, NONE);
ds->ds_has_events = ds->ds_has_notifier || ds->ds_has_subscription;
break;
case nua_subscriber_usage:
su_free(nh->nh_home, (void *)du->du_event);
ds->ds_has_subscription = NULL != *nua_dialog_usage_at(ds, kind, NONE);
ds->ds_has_events = ds->ds_has_subscription || ds->ds_has_notifier;
msg_destroy(du->du_subscriber->de_msg);
break;
case nua_register_usage:
ds->ds_has_register = 0;
msg_destroy(du->du_register->ru_msg);
break;
case nua_publish_usage:
ds->ds_has_publish = 0;
su_free(nh->nh_home, du->du_publisher->pu_etag);
break;
case nua_transaction_usage:
default:
break;
}
switch (kind) {
case nua_session_usage:
ds->ds_has_session = 1;
break;
case nua_notifier_usage:
ds->ds_has_events = 1;
ds->ds_has_notifier = 1;
break;
case nua_subscriber_usage:
ds->ds_has_events = 1;
ds->ds_has_subscription = 1;
break;
case nua_register_usage:
ds->ds_has_register = 1;
break;
case nua_publish_usage:
ds->ds_has_publish = 1;
break;
case nua_transaction_usage:
default:
break;
}
typedef struct {
void (*nua_dialog_destructor)(nua_handle_t *nh,
nua_dialog_usage_t *du);
} nua_usage_class;
#endif
......@@ -36,10 +36,13 @@
typedef struct nua_dialog_state nua_dialog_state_t;
typedef struct nua_dialog_usage nua_dialog_usage_t;
typedef struct nua_remote_s nua_remote_t;
#ifndef NUA_H
#include <sofia-sip/nua.h>
#ifndef NUA_OWNER_T
#define NUA_OWNER_T struct nua_owner_s
#endif
typedef NUA_OWNER_T nua_owner_t;
#ifndef NTA_H
#include <sofia-sip/nta.h>
#endif
......@@ -79,29 +82,18 @@ struct nua_dialog_state
} ds_remote_ua[1];
};
typedef void nh_pending_f(nua_handle_t *nh,
typedef void nh_pending_f(nua_owner_t *,
nua_dialog_usage_t *du,
sip_time_t now);
enum nua_dialog_usage_e
{
nua_is_transaction_usage = 0,
nua_is_session_usage,
nua_is_notifier_usage,
nua_is_subscriber_usage,
nua_is_register_usage,
nua_is_publish_usage
};
typedef struct {
unsigned usage_size, usage_class_size;
int (*usage_add)(nua_handle_t *nh,
int (*usage_add)(nua_owner_t *,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
void (*usage_remove)(nua_owner_t *,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
void (*usage_remove)(nua_handle_t *nh,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
char const *(*usage_name)(nua_dialog_usage_t const *du);
} nua_usage_class;
......@@ -127,13 +119,16 @@ struct nua_dialog_usage {
msg_t *du_msg; /**< Template message */
};
void nua_dialog_uac_route(nua_handle_t *nh, sip_t const *sip, int rtag);
void nua_dialog_uas_route(nua_handle_t *nh, sip_t const *sip, int rtag);
void nua_dialog_get_peer_info(nua_handle_t *nh, sip_t const *sip);
void nua_dialog_uac_route(nua_owner_t *, nua_dialog_state_t *ds,
sip_t const *sip, int rtag);
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);
char const *nua_dialog_usage_name(nua_dialog_usage_t const *du);
nua_dialog_usage_t *nua_dialog_usage_add(nua_handle_t *nh,
nua_dialog_usage_t *nua_dialog_usage_add(nua_owner_t *,
struct nua_dialog_state *ds,
nua_usage_class const *uclass,
sip_event_t const *event);
......@@ -142,11 +137,11 @@ nua_dialog_usage_t *nua_dialog_usage_get(nua_dialog_state_t const *ds,
nua_usage_class const *uclass,
sip_event_t const *event);
void nua_dialog_usage_remove(nua_handle_t *nh,
void nua_dialog_usage_remove(nua_owner_t *,
nua_dialog_state_t *ds,
nua_dialog_usage_t *du);
void nua_dialog_terminated(nua_handle_t *nh,
void nua_dialog_terminated(nua_owner_t *,
struct nua_dialog_state *ds,
int status,
char const *phrase);
......@@ -170,8 +165,4 @@ void *nua_dialog_usage_private(nua_dialog_usage_t const *du)
#define nua_dialog_usage_private(du) ((void*)((du) + 1))
#endif
#ifndef NUA_STACK_H
#include <nua_stack.h>
#endif
#endif /* NUA_DIALOG_H */
......@@ -45,7 +45,7 @@
#define NTA_LEG_MAGIC_T struct nua_handle_s
#define NTA_OUTGOING_MAGIC_T struct nua_handle_s
#include "nua_dialog.h"
#include "nua_stack.h"
#if HAVE_SIGCOMP
#include <sigcomp.h>
......
......@@ -362,8 +362,8 @@ static int process_response_to_invite(nua_handle_t *nh,
/* XXX - check remote tag, handle forks */
/* Set route, contact, nh_ds->ds_remote_tag */
nua_dialog_uac_route(nh, sip, 1);
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uac_route(nh, nh->nh_ds, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
init_session_timer(nua, nh, sip);
......@@ -550,8 +550,8 @@ process_100rel(nua_handle_t *nh,
if (!nua_dialog_is_established(nh->nh_ds)) {
/* Tag the INVITE request */
nua_dialog_uac_route(nh, sip, 1);
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uac_route(nh, nh->nh_ds, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
cr_invite->cr_orq =
nta_outgoing_tagged(orq, process_response_to_invite, nh,
......@@ -927,7 +927,7 @@ int process_invite2(nua_t *nua,
/* Session Timer negotiation */
init_session_timer(nua, nh, sip);
nua_dialog_uas_route(nh, sip, 1); /* Set route and tags */
nua_dialog_uas_route(nh, nh->nh_ds, sip, 1); /* Set route and tags */
nta_incoming_bind(irq, process_ack_or_cancel, nh);
......@@ -1824,8 +1824,9 @@ static int process_response_to_update(nua_handle_t *nh,
}
else if (status >= 200) {
/* XXX - check remote tag, handle forks */
nua_dialog_uac_route(nh, sip, 1); /* Set (route), contact, (remote tag) */
nua_dialog_get_peer_info(nh, sip);
/* Set (route), contact, (remote tag) */
nua_dialog_uac_route(nh, nh->nh_ds, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
if (is_session_timer_set(ss)) {
init_session_timer(nua, nh, sip);
......
......@@ -1502,7 +1502,7 @@ nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
if (nh && create_dialog) {
struct nua_dialog_state *ds = nh->nh_ds;
nua_dialog_get_peer_info(nh, sip);
nua_dialog_store_peer_info(nh, ds, sip);
ds->ds_leg = nta_leg_tcreate(nua->nua_nta, nua_stack_process_request, nh,
SIPTAG_CALL_ID(sip->sip_call_id),
......@@ -1516,7 +1516,7 @@ nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
}
if (nh)
nua_dialog_uas_route(nh, sip, 1);
nua_dialog_uas_route(nh, nh->nh_ds, sip, 1);
return nh;
}
......
......@@ -64,16 +64,17 @@
#define SU_LOG (nua_log)
#include <sofia-sip/su_debug.h>
#ifndef NUA_DIALOG_H
#define NUA_OWNER_T struct nua_handle_s
#include <nua_dialog.h>
#endif
SOFIA_BEGIN_DECLS
#if HAVE_SIGCOMP
#include <sigcomp.h>
#endif
#ifndef NUA_DIALOG_H
#include <nua_dialog.h>
#endif
typedef struct event_s event_t;
#define NONE ((void *)-1)
......@@ -96,7 +97,6 @@ enum nh_oa_event {
};
typedef struct nua_chat_s nua_chat_t;
typedef struct nua_remote_s nua_remote_t;
typedef struct nua_client_request nua_client_request_t;
typedef struct nua_server_request nua_server_request_t;
......
......@@ -47,7 +47,7 @@
#define NTA_LEG_MAGIC_T struct nua_handle_s
#define NTA_OUTGOING_MAGIC_T struct nua_handle_s
#include "nua_dialog.h"
#include "nua_stack.h"
/* ---------------------------------------------------------------------- */
/* Subcribe event usage */
......@@ -282,8 +282,8 @@ static int process_response_to_subscribe(nua_handle_t *nh,
/* We have not received notify. */
if (!win_messenger_enable)
nua_dialog_uac_route(nh, sip, 1);
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uac_route(nh, nh->nh_ds, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
if (delta > 0) {
nua_dialog_usage_set_refresh(du, delta);
......@@ -463,8 +463,8 @@ int nua_stack_process_subsribe(nua_t *nua,
/* Refresh existing subscription */
eu = nua_dialog_usage_private(du); assert(nh && du && eu);
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uas_route(nh, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
nua_dialog_uas_route(nh, nh->nh_ds, sip, 1);
refer_expires = NH_PGET(nh, refer_expires);
expires = refer_expires;
......@@ -723,8 +723,8 @@ int nua_stack_process_notify(nua_t *nua,
}
}
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uas_route(nh, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
nua_dialog_uas_route(nh, nh->nh_ds, sip, 1);
if (strcasecmp(subs->ss_substate, what = "terminated") == 0) {
eu->eu_substate = nua_substate_terminated;
......@@ -888,8 +888,8 @@ static int process_response_to_refer(nua_handle_t *nh,
else if (status < 300) {
if (cr->cr_usage)
cr->cr_usage->du_ready = 1;
nua_dialog_uac_route(nh, sip, 1);
nua_dialog_get_peer_info(nh, sip);
nua_dialog_uac_route(nh, nh->nh_ds, sip, 1);
nua_dialog_store_peer_info(nh, nh->nh_ds, sip);
}
else /* if (status >= 300) */ {
if (cr->cr_usage)
......@@ -935,7 +935,7 @@ int nua_stack_process_refer(nua_t *nua,
du->du_ready = 1;
nua_dialog_uas_route(nh, sip, 1); /* Set route and tags */
nua_dialog_uas_route(nh, nh->nh_ds, sip, 1); /* Set route and tags */
if (!sip->sip_referred_by) {
sip_from_t *a = sip->sip_from;
......
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