Commit e1964eb9 authored by Pekka Pessi's avatar Pekka Pessi

nua_prefs.h, nua_prefs.c, nua_common.c, nua_stack.c: updated preference handling.

The preferences are now handled in a more consistent way. nua_create() calls
internally nua_set_params(). NUTAG_MEDIA_ENABLE() can be set handle-wise,
even in nua_invite() or in nua_respond().

darcs-hash:20060925213223-65a35-5287236c60c3846eb8c6368186d92653d5e5261c.gz
parent f622a97e
......@@ -89,7 +89,7 @@ static void nh_destructor(void *arg);
* @retval NULL Creation failed
*
* @par Related tags:
* Creates a copy of provided tags and they will
* Creates a copy of the provided tags which will
* be used with every operation.
*
* @par Events:
......@@ -98,7 +98,8 @@ static void nh_destructor(void *arg);
* @note
* This function is called by both stack and application sides.
*/
nua_handle_t *nh_create_handle(nua_t *nua, nua_hmagic_t *hmagic,
nua_handle_t *nh_create_handle(nua_t *nua,
nua_hmagic_t *hmagic,
tagi_t *tags)
{
nua_handle_t *nh;
......@@ -109,62 +110,17 @@ nua_handle_t *nh_create_handle(nua_t *nua, nua_hmagic_t *hmagic,
assert(nua->nua_home);
if ((nh = su_home_clone(nua->nua_home, sizeof(*nh)))) {
url_string_t const *url = NULL;
sip_to_t to[1];
sip_to_t const *p_to = NULL;
sip_from_t from[1];
sip_from_t const *p_from = NULL;
tl_gets(tags, /* These does not change while nh lives */
SIPTAG_FROM_REF(p_from),
SIPTAG_TO_REF(p_to),
NUTAG_URL_REF(url),
TAG_END());
if (!p_from && nua->nua_from) {
*from = *nua->nua_from;
from->a_params = NULL;
}
else {
p_from = (void *)-1;
}
nh->nh_prefs = nua->nua_dhandle->nh_prefs;
if (!p_to && url) {
void *tbf = NULL;
if (url_is_string(url))
url = tbf = url_hdup(nh->nh_home, url->us_url);
*sip_to_init(to)->a_url = *url->us_url;
to->a_url->url_params = NULL;
to->a_url->url_headers = NULL;
nh->nh_ds->ds_remote = sip_to_dup(nh->nh_home, to);
if (tbf)
su_free(nh->nh_home, tbf);
}
else {
p_to = (void *)-1;
}
nh->nh_valid = nua_handle;
nh->nh_nua = nua;
nh->nh_magic = hmagic;
nh->nh_tags = tl_tlist(nh->nh_home,
TAG_IF(!p_from, SIPTAG_FROM(from)),
TAG_IF(!p_to, SIPTAG_TO(to)),
TAG_NEXT(tags));
tl_gets(nh->nh_tags, /* These does not change while nh lives */
SIPTAG_FROM_REF(nh->nh_ds->ds_local),
SIPTAG_TO_REF(nh->nh_ds->ds_remote),
TAG_END());
nh->nh_prefs = nua->nua_dhandle->nh_prefs;
if (su_home_is_threadsafe(nua->nua_home)) {
if (nua_handle_save_tags(nh, tags) < 0) {
SU_DEBUG_5(("nua(%p): creating handle %p failed\n", nua, nh));
su_home_unref(nh->nh_home), nh = NULL;
}
if (nh && su_home_is_threadsafe(nua->nua_home)) {
if (su_home_threadsafe(nh->nh_home) < 0) {
su_home_unref(nh->nh_home);
nh = NULL;
......@@ -172,8 +128,9 @@ nua_handle_t *nh_create_handle(nua_t *nua, nua_hmagic_t *hmagic,
}
if (nh && _handle_lifetime) {
/* This far, we have nothing real to destruct */
/* This far, we have nothing real to destruct but
* when _NUA_HANDLE_DEBUG is set, we add destructor
* and get more entertaining debugging output */
if (_handle_lifetime == 1 && !getenv("_NUA_HANDLE_DEBUG")) {
_handle_lifetime = 0;
}
......
This diff is collapsed.
......@@ -35,12 +35,29 @@
* @date Created: Wed Mar 8 11:38:18 EET 2006 ppessi
*/
/** NUA preferences.
*
* This structure contains values for various preferences and a separate
* bitmap (nhp_set) for each preference. Preferences are set using
* nua_set_params() or nua_set_hparams() or a handle-specific operation
* setting the preferences, including nua_invite(), nua_respond(),
* nua_ack(), nua_prack(), nua_update(), nua_info(), nua_bye(),
* nua_options(), nua_message(), nua_register(), nua_publish(), nua_refer(),
* nua_subscribe(), nua_notify(), nua_refer(), and nua_notifier().
*
* The stack uses preference value if corresponding bit in bitmap is set,
* otherwise it uses preference value from default handle.
*
* @see NHP_GET(), NH_PGET(), NHP_ISSET(), NH_PISSET()
*/
typedef struct nua_handle_preferences
{
unsigned nhp_retry_count; /**< times to retry a request */
unsigned nhp_max_subscriptions;
/* Session-related preferences */
char const *nhp_soa_name;
unsigned nhp_media_enable:1;
unsigned nhp_invite_enable:1;
unsigned nhp_auto_alert:1;
unsigned nhp_early_media:1;/**< Establish early media session */
......@@ -55,10 +72,6 @@ typedef struct nua_handle_preferences
* INVITE client transaction times out
*/
unsigned nhp_invite_timeout;
/* REGISTER Keepalive intervals */
unsigned nhp_keepalive, nhp_keepalive_stream;
/** Default session timer (in seconds, 0 disables) */
unsigned nhp_session_timer;
/** Default Min-SE Delta value */
......@@ -92,11 +105,14 @@ typedef struct nua_handle_preferences
/* Subscriber state, i.e. nua_substate_pending */
unsigned nhp_substate;
/* REGISTER Keepalive intervals */
unsigned nhp_keepalive, nhp_keepalive_stream;
char const *nhp_registrar;
sip_allow_t *nhp_allow;
sip_supported_t *nhp_supported;
sip_user_agent_t *nhp_user_agent;
char const *nhp_ua_name;
sip_organization_t *nhp_organization;
char const *nhp_user_agent;
char const *nhp_organization;
char const *nhp_m_display;
char const *nhp_m_username;
......@@ -106,14 +122,17 @@ typedef struct nua_handle_preferences
/**< Outbound OPTIONS */
char const *nhp_outbound;
/**< Network detection: NONE, INFORMAL, TRY_FULL */
uint32_t nhp_detect_network_updates;
int nhp_detect_network_updates;
/* A bit for each feature set by application */
struct {
unsigned nhb_retry_count:1;
unsigned nhb_max_subscriptions:1;
unsigned nhb_soa_name:1;
unsigned nhb_media_enable:1;
unsigned nhb_invite_enable:1;
unsigned nhb_auto_alert:1;
unsigned nhb_early_media:1;
......@@ -121,8 +140,7 @@ typedef struct nua_handle_preferences
unsigned nhb_auto_answer:1;
unsigned nhb_auto_ack:1;
unsigned nhb_invite_timeout:1;
unsigned nhb_keepalive:1;
unsigned nhb_keepalive_stream:1;
unsigned nhb_session_timer:1;
unsigned nhb_min_se:1;
unsigned nhb_refresher:1;
......@@ -137,14 +155,18 @@ typedef struct nua_handle_preferences
unsigned nhb_refer_with_id:1;
unsigned nhb_refer_expires:1;
unsigned nhb_substate:1;
unsigned nhb_keepalive:1;
unsigned nhb_keepalive_stream:1;
unsigned nhb_registrar:1;
unsigned nhb_allow:1;
unsigned nhb_supported:1;
unsigned nhb_user_agent:1;
unsigned nhb_ua_name:1;
unsigned nhb_organization:1;
unsigned :0; /* at most 32 bits ... */
unsigned nhb_m_display:1;
unsigned nhb_m_username:1;
unsigned :0;
unsigned nhb_m_params:1;
unsigned nhb_m_features:1;
unsigned nhb_instance:1;
......
......@@ -702,7 +702,7 @@ int nua_stack_ack(nua_t *nua, nua_handle_t *nh, nua_event_t e,
received = NULL;
if (tags) {
nua_stack_set_params(nua, nh, nua_r_ack, tags);
nua_stack_set_params(nua, nh, nua_i_error, tags);
}
msg = nua_creq_msg(nua, nh, cr, 0,
......@@ -1172,7 +1172,7 @@ nua_stack_cancel(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_client_request_t *crc = nh->nh_cr;
if (tags)
nua_stack_set_params(nua, nh, nua_r_cancel, tags);
nua_stack_set_params(nua, nh, nua_i_error, tags);
if (nh && cri->cr_orq && cri->cr_usage) {
nta_outgoing_t *orq;
......@@ -1258,7 +1258,7 @@ int process_invite1(nua_t *nua,
int have_sdp;
char const *sdp;
size_t len;
sip_user_agent_t const *user_agent = NH_PGET(nh0, user_agent);
char const *user_agent = NH_PGET(nh0, user_agent);
#if HAVE_SOFIA_SMIME
int sm_status;
......@@ -1281,7 +1281,7 @@ int process_invite1(nua_t *nua,
/* Make sure caller uses application/sdp without compression */
if (nta_check_session_content(irq, sip,
nua->nua_invite_accept,
SIPTAG_USER_AGENT(user_agent),
SIPTAG_USER_AGENT_STR(user_agent),
SIPTAG_ACCEPT_ENCODING_STR(""),
TAG_END()))
return 415;
......@@ -1290,7 +1290,7 @@ int process_invite1(nua_t *nua,
if (nta_check_accept(irq, sip,
nua->nua_invite_accept,
NULL,
SIPTAG_USER_AGENT(user_agent),
SIPTAG_USER_AGENT_STR(user_agent),
SIPTAG_ACCEPT_ENCODING_STR(""),
TAG_END()))
return 406;
......@@ -1300,7 +1300,7 @@ int process_invite1(nua_t *nua,
unsigned min_se = nh ? nh->nh_ss->ss_min_se : DNH_PGET(dnh, min_se);
if (nta_check_session_expires(irq, sip,
min_se,
SIPTAG_USER_AGENT(user_agent),
SIPTAG_USER_AGENT_STR(user_agent),
TAG_END()))
return 500; /* respond with 500 Internal Server Error */
}
......@@ -1475,7 +1475,7 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
assert(ss->ss_usage);
if (tags) {
nua_stack_set_params(nua, nh, nua_i_invite, tags);
nua_stack_set_params(nua, nh, nua_i_error, tags);
if (status < 200) {
early_answer = -1;
......
This diff is collapsed.
......@@ -84,6 +84,10 @@ typedef struct event_s event_t;
#define NONE ((void *)-1)
enum {
nua_i_none = -1 /** Event never sent to application */
};
enum nh_kind {
nh_has_nothing,
nh_has_invite,
......@@ -208,21 +212,11 @@ struct nua_handle_s
void *nh_valid;
nua_hmagic_t *nh_magic; /**< Application context */
tagi_t *nh_tags; /**< Default tags */
tagi_t *nh_tags; /**< Initial tags */
tagi_t *nh_ptags; /**< Initial parameters */
nua_handle_t *nh_identity; /**< Identity */
#if HAVE_PTHREAD_H
#if __CYGWIN__
pthread_mutex_t sup_reflock[1];
int sup_ref;
#else
pthread_rwlock_t nh_refcount[1];
#endif
#else
unsigned nh_refcount;
#endif
nua_handle_preferences_t *nh_prefs; /**< Preferences */
/* Handle state */
......@@ -230,7 +224,8 @@ struct nua_handle_s
unsigned nh_ref_by_stack:1; /**< Has stack used the handle? */
unsigned nh_ref_by_user:1; /**< Has user used the handle? */
unsigned nh_init:1;
unsigned nh_init:1; /**< Handle has been initialized */
unsigned nh_used_ptags:1; /**< Ptags has been used */
unsigned nh_has_invite:1; /**< Has call */
unsigned nh_has_subscribe:1; /**< Has watcher */
......@@ -317,17 +312,11 @@ struct nua_s {
/* Constants */
sip_accept_t *nua_invite_accept; /* What we accept for invite */
url_t *nua_registrar;
su_root_t *nua_root;
su_task_r nua_server;
nta_agent_t *nua_nta;
su_timer_t *nua_timer;
#if HAVE_UICC_H
uicc_t *nua_uicc;
#endif
void *nua_sip_parser;
sip_time_t nua_shutdown;
......@@ -422,6 +411,8 @@ nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
enum nh_kind kind,
int create_dialog);
int nua_handle_save_tags(nua_handle_t *h, tagi_t *tags);
void nh_destroy(nua_t *nua, nua_handle_t *nh);
nua_handle_t *nh_validate(nua_t *nua, nua_handle_t *maybe);
......
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