Commit 1d90d565 authored by Martti Mela's avatar Martti Mela

moved network detection from NTA to NUA

darcs-hash:20060815140956-1b897-7f181e7441ba0927b918e0ad0217d622c6900ef0.gz
parent d2841a9e
......@@ -51,14 +51,11 @@
#define SU_MSG_ARG_T union sm_arg_u
/** @internal SU timer argument pointer type */
#define SU_TIMER_ARG_T struct nta_agent_s
/** @internal SU network changed detector argument pointer type */
#define SU_NETWORK_CHANGED_MAGIC_T struct nta_agent_s
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su.h>
#include <sofia-sip/su_time.h>
#include <sofia-sip/su_wait.h>
#include <sofia-sip/su_os_nw.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/base64.h>
......@@ -132,7 +129,6 @@ static void agent_kill_terminator(nta_agent_t *agent);
static int agent_set_params(nta_agent_t *agent, tagi_t *tags);
static void agent_set_udp_params(nta_agent_t *self, unsigned udp_mtu);
static int agent_get_params(nta_agent_t *agent, tagi_t *tags);
static int agent_launch_network_change_detector(nta_agent_t *agent);
/* Transport interface */
static sip_via_t const *agent_tport_via(tport_t *tport);
......@@ -462,12 +458,6 @@ nta_agent_t *nta_agent_create(su_root_t *root,
SU_DEBUG_9(("nta_agent_create: initialized %s\n", "resolver"));
#endif
if (agent_launch_network_change_detector(agent) < 0)
SU_DEBUG_9(("nta_agent_create: failure %s\n", "network change detector"));
else
SU_DEBUG_9(("nta_agent_create: initialized %s\n", "network change detector"));
ta_end(ta);
return agent;
......@@ -745,57 +735,6 @@ int agent_launch_terminator(nta_agent_t *agent)
return -1;
}
static
void agent_network_changed_cb(nta_agent_t *agent, su_root_t *root)
{
switch (agent->sa_nw_updates) {
case NTA_NW_DETECT_ONLY_INFO:
(void)agent->sa_callback(agent->sa_magic, agent, NULL, NULL);
break;
case NTA_NW_DETECT_TRY_FULL:
/* XXX - loop through transactions and remove tport_primaries */
/* XXX - tport_shutdown() */
/* XXX - tport_tcreate() */
/* XXX - tport_tbind() */
(void)agent->sa_callback(agent->sa_magic, agent, NULL, NULL);
break;
default:
break;
}
return;
}
static
int agent_launch_network_change_detector(nta_agent_t *agent)
{
su_network_changed_t *snc = NULL;
if (agent->sa_nw_updates == NTA_NW_DETECT_NOTHING)
return 0;
/* else ... */
snc = su_root_add_network_changed(agent->sa_home,
agent->sa_root,
agent_network_changed_cb,
agent);
if (!snc)
return -1;
agent->sa_nw_changed = snc;
return 0;
}
/** Kill transaction terminator task */
static
void agent_kill_terminator(nta_agent_t *agent)
......@@ -885,7 +824,6 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
unsigned threadpool = agent->sa_tport_threadpool;
char const *sigcomp = agent->sa_sigcomp_options;
char const *algorithm = NONE;
unsigned nw_updates = 0;
msg_mclass_t *mclass = NONE;
sip_contact_t const *aliases = NONE;
url_string_t const *proxy = NONE;
......@@ -936,7 +874,6 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
#endif
NTATAG_SIGCOMP_OPTIONS_REF(sigcomp),
NTATAG_SIGCOMP_ALGORITHM_REF(algorithm),
NTATAG_DETECT_NETWORK_UPDATES_REF(nw_updates),
TAG_END());
if (mclass != NONE)
......@@ -1001,10 +938,6 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
}
}
/* Store network detector param value */
if (agent->sa_nw_updates == 0)
agent->sa_nw_updates = nw_updates;
if (maxsize == 0) maxsize = 2 * 1024 * 1024;
if (maxsize > NTA_TIME_MAX) maxsize = NTA_TIME_MAX;
agent->sa_maxsize = maxsize;
......
......@@ -95,7 +95,6 @@ struct nta_agent_s
su_home_t sa_home[1];
su_root_t *sa_root;
su_timer_t *sa_timer;
su_network_changed_t *sa_nw_changed;
nta_agent_magic_t *sa_magic;
nta_message_f *sa_callback;
......
......@@ -142,8 +142,6 @@ tag_typedef_t ntatag_s_recv_retry = UINTTAG_TYPEDEF(s_recv_retry);
tag_typedef_t ntatag_s_tout_request = UINTTAG_TYPEDEF(s_tout_request);
tag_typedef_t ntatag_s_tout_response = UINTTAG_TYPEDEF(s_tout_response);
tag_typedef_t ntatag_detect_network_updates = UINTTAG_TYPEDEF(detect_network_updates);
/* Internal */
tag_typedef_t ntatag_delay_sending = BOOLTAG_TYPEDEF(delay_sending);
tag_typedef_t ntatag_incomplete = BOOLTAG_TYPEDEF(incomplete);
......@@ -113,13 +113,6 @@ enum {
/**< Maximum value for timers. */
};
typedef enum {
NTA_NW_DETECT_NOTHING = 0,
NTA_NW_DETECT_ONLY_INFO,
NTA_NW_DETECT_TRY_FULL,
} nta_nw_detector_e;
/* ----------------------------------------------------------------------
* 3) Agent-level prototypes
*/
......
......@@ -449,24 +449,6 @@ NTA_DLL extern tag_typedef_t ntatag_rseq;
NTA_DLL extern tag_typedef_t ntatag_rseq_ref;
#define NTATAG_RSEQ_REF(x) ntatag_rseq_ref, tag_uint_vr(&(x))
/** Enable detection of local IP address updates
*
* @par Used with
* #nua_i_network_updated
*
* @par Parameter type
* int
*
* Corresponding tag taking reference parameter is NTATAG_DETECT_NETWORK_UPDATES_REF()
*/
#define NTATAG_DETECT_NETWORK_UPDATES(x) \
ntatag_detect_network_updates, tag_uint_v(x)
NTA_DLL extern tag_typedef_t ntatag_detect_network_updates;
#define NTATAG_DETECT_NETWORK_UPDATES_REF(x) \
ntatag_detect_network_updates_ref, tag_uint_vr(&(x))
NTA_DLL extern tag_typedef_t ntatag_detect_network_updates_ref;
/* ====================================================================== */
/* Tags for statistics. */
......
......@@ -220,6 +220,7 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
* NUTAG_MEDIA_FEATURES() \n
* NUTAG_MIN_SE() \n
* NUTAG_OUTBOUND() \n
* NUTAG_DETECT_NETWORK_UPDATES() \n
* NUTAG_PATH_ENABLE() \n
* NUTAG_REGISTRAR() \n
* NUTAG_SERVICE_ROUTE_ENABLE() \n
......@@ -486,6 +487,10 @@ int nua_stack_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
else if (t->t_tag == nutag_outbound) {
outbound = (void *)t->t_value;
}
/* NUTAG_DETECT_NETWORK_UPDATES_REF(detect_network_updates) */
else if (t->t_tag == nutag_detect_network_updates) {
NHP_SET(nhp, detect_network_updates, (unsigned)t->t_value);
}
}
/* Sanitize values */
......@@ -655,6 +660,9 @@ int nua_stack_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_stack_set_smime_params(nua, tags);
if (NHP_ISSET(nhp, detect_network_updates))
nua_stack_launch_network_change_detector(nua);
return e == nua_r_set_params ? UA_EVENT2(e, 200, "OK") : 0;
}
......@@ -869,6 +877,7 @@ int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
TIF_STR(SIPTAG_ORGANIZATION_STR, organization),
TIF(NUTAG_OUTBOUND, outbound),
TIF(NUTAG_DETECT_NETWORK_UPDATES, detect_network_updates),
TIF(NUTAG_INSTANCE, instance),
TIF(NUTAG_KEEPALIVE, keepalive),
TIF(NUTAG_KEEPALIVE_STREAM, keepalive_stream),
......
......@@ -100,6 +100,9 @@ typedef struct nua_handle_preferences
/**< Outbound OPTIONS */
char const *nhp_outbound;
/**< Network detection: NONE, INFORMAL, TRY_FULL */
uint32_t nhp_detect_network_updates;
/* A bit for each feature set by application */
union {
uint32_t set_any;
......@@ -135,6 +138,7 @@ typedef struct nua_handle_preferences
unsigned nhb_organization:1;
unsigned nhb_instance:1;
unsigned nhb_outbound:1;
unsigned nhb_detect_network_updates:1;
unsigned :0;
} set_bits;
} nhp_set;
......
......@@ -47,6 +47,9 @@
#define SU_ROOT_MAGIC_T struct nua_s
#define SU_MSG_ARG_T struct event_s
/** @internal SU network changed detector argument pointer type */
#define SU_NETWORK_CHANGED_MAGIC_T struct nua_s
#define NUA_SAVED_EVENT_T su_msg_t *
#define NTA_AGENT_MAGIC_T struct nua_s
......@@ -1663,3 +1666,66 @@ nua_stack_respond(nua_t *nua, nua_handle_t *nh,
500, "Responding to a Non-Existing Request", TAG_END());
}
}
#if 0
/* Store network detector param value */
if (agent->sa_nw_updates == 0)
agent->sa_nw_updates = nw_updates;
NTATAG_DETECT_NETWORK_UPDATES_REF(nw_updates),
unsigned nw_updates = 0;
unsigned nw_updates = 0;
su_network_changed_t *sa_nw_changed;
#endif
static
void nua_network_changed_cb(nua_t *nua, su_root_t *root)
{
uint32_t nw_updates = NUA_NW_DETECT_ONLY_INFO;
switch (nw_updates) {
case NUA_NW_DETECT_ONLY_INFO:
nua_stack_event(nua, NULL, NULL, nua_i_network_changed,
SIP_200_OK, TAG_END());
break;
case NUA_NW_DETECT_TRY_FULL:
/* XXX - loop through transactions and remove tport_primaries */
/* XXX - tport_shutdown() */
/* XXX - tport_tcreate() */
/* XXX - tport_tbind() */
//if (agent->sa_callback)
//(void)agent->sa_callback(agent->sa_magic, agent, NULL, NULL);
break;
default:
break;
}
return;
}
int nua_stack_launch_network_change_detector(nua_t *nua)
{
su_network_changed_t *snc = NULL;
snc = su_root_add_network_changed(nua->nua_home,
nua->nua_api_root,
nua_network_changed_cb,
nua);
if (!snc)
return -1;
nua->nua_nw_changed = snc;
return 0;
}
......@@ -285,6 +285,9 @@ struct nua_s {
su_root_t *nua_api_root;
su_clone_r nua_clone;
su_task_r nua_client;
su_network_changed_t *nua_nw_changed;
nua_callback_f nua_callback;
nua_magic_t *nua_magic;
......@@ -440,6 +443,8 @@ int nua_stack_process_response(nua_handle_t *nh,
sip_t const *sip,
tag_type_t tag, tag_value_t value, ...);
int nua_stack_launch_network_change_detector(nua_t *nua);
msg_t *nua_creq_msg(nua_t *nua, nua_handle_t *nh,
struct nua_client_request *cr,
int restart,
......
......@@ -25,6 +25,7 @@
/**@CFILE nua_tag.c Tags and tag lists for NUA
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Martti Mela <Martti.Mela@nokia.com>
*
* @date Created: Wed Feb 21 10:13:29 2001 ppessi
*/
......@@ -132,5 +133,8 @@ tag_typedef_t nutag_path_enable = BOOLTAG_TYPEDEF(path_enable);
tag_typedef_t nutag_service_route_enable =
BOOLTAG_TYPEDEF(service_route_enable);
tag_typedef_t nutag_detect_network_updates = UINTTAG_TYPEDEF(detect_network_updates);
tag_typedef_t _nutag_add_contact = BOOLTAG_TYPEDEF(add_contact);
tag_typedef_t _nutag_copy = BOOLTAG_TYPEDEF(copy);
......@@ -38,6 +38,10 @@
#include <sofia-sip/su_wait.h>
#endif
#ifndef SU_OS_NW_H
#include <sofia-sip/su_os_nw.h>
#endif
#ifndef URL_H
#include <sofia-sip/url.h>
#endif
......@@ -64,6 +68,13 @@ typedef NUA_MAGIC_T nua_magic_t;
/** Application context for NUA handle. */
typedef NUA_HMAGIC_T nua_hmagic_t;
typedef enum nua_nw_detector_e{
NUA_NW_DETECT_NOTHING = 0,
NUA_NW_DETECT_ONLY_INFO,
NUA_NW_DETECT_TRY_FULL,
} nua_nw_detector_t;
/** Events */
typedef enum nua_event_e {
/* Indications */
......@@ -77,6 +88,7 @@ typedef enum nua_event_e {
nua_i_terminated, /**< A call has been terminated */
nua_i_state, /**< Call state has changed */
nua_i_network_changed, /**< Our IP(v6) address has changed */
nua_i_outbound, /**< Status from outbound processing */
nua_i_bye, /**< Incoming call hangup */
......
......@@ -30,6 +30,7 @@
* @brief Tags for Sofia-SIP User Agent Library
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Martti Mela <Martti.Mela@nokia.com>
*
* @date Created: Mon Feb 19 18:54:26 EET 2001 ppessi
*/
......@@ -1534,6 +1535,24 @@ SOFIAPUBVAR tag_typedef_t nutag_answer_sent;
#define NUTAG_ANSWER_SENT_REF(x) nutag_answer_sent_ref, tag_bool_vr(&(x))
SOFIAPUBVAR tag_typedef_t nutag_answer_sent_ref;
/** Enable detection of local IP address updates
*
* @par Used with
* #nua_i_network_updated
*
* @par Parameter type
* int
*
* Corresponding tag taking reference parameter is NUTAG_DETECT_NETWORK_UPDATES_REF()
*/
#define NUTAG_DETECT_NETWORK_UPDATES(x) \
nutag_detect_network_updates, tag_uint_v(x)
SOFIAPUBVAR tag_typedef_t nutag_detect_network_updates;
#define NUTAG_DETECT_NETWORK_UPDATES_REF(x) \
nutag_detect_network_updates_ref, tag_uint_vr(&(x))
SOFIAPUBVAR tag_typedef_t nutag_detect_network_updates_ref;
#if SU_HAVE_INLINE
su_inline tag_value_t nutag_handle_v(nua_handle_t *v) { return (tag_value_t)v; }
su_inline tag_value_t nutag_handle_vr(nua_handle_t **vp) {return(tag_value_t)vp;}
......
......@@ -52,7 +52,7 @@ nobase_include_sofia_HEADERS = \
sofia-sip/su_log.h \
sofia-sip/su_config.h sofia-sip/su_md5.h \
sofia-sip/su_uniqueid.h sofia-sip/su_bm.h \
sofia-sip/tstdef.h
sofia-sip/tstdef.h sofia-sip/su_os_nw.h
nobase_nodist_include_sofia_HEADERS = sofia-sip/su_configure.h
......@@ -61,7 +61,7 @@ libsu_la_SOURCES = \
su_alloc.c su_alloc_lock.c su_strdup.c su_sprintf.c \
su_strlst.c su_vector.c \
su_time.c su_time0.c \
su_wait.c su_root.c su_timer.c su_port.c su_port.h \
su_wait.c su_os_nw.c su_root.c su_timer.c su_port.c su_port.h \
su_localinfo.c \
su_taglist.c su_tag.c su_tag_io.c \
su_log.c su_global_log.c su_default_log.c su_module_debug.h \
......
......@@ -44,6 +44,15 @@
#ifndef SU_TIME_H
#include "sofia-sip/su_time.h"
#endif
#ifndef SU_ALLOC_H
#include "sofia-sip/su_alloc.h"
#endif
#ifndef SU_WAIT_H
#include "sofia-sip/su_wait.h"
#endif
#if SU_HAVE_POLL
#include <sys/poll.h>
#endif
......
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