Commit 77e9c23f authored by Pekka Pessi's avatar Pekka Pessi

Updated stack initialization.

Transports are initialized by nua_stack_init_transport() in nua_register.c.
UICC (you don't want to know) is initialized by nua_stack_set_from() in
nua_params.c.

darcs-hash:20060331152712-88462-fbfabe348e7abecb908344a77899667296641a0d.gz
parent 40d249e8
...@@ -120,20 +120,28 @@ int nua_stack_set_defaults(nua_handle_t *nh, ...@@ -120,20 +120,28 @@ int nua_stack_set_defaults(nua_handle_t *nh,
} }
/** @internal Set the default from field */ /** @internal Set the default from field */
void nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags) int nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags)
{ {
sip_from_t const *from = NONE; sip_from_t const *from = NONE;
char const *str = NONE; char const *str = NONE;
sip_from_t *f = NULL, f0[1]; sip_from_t *f = NULL, f0[1];
char const *uicc_name = "default";
tl_gets(tags, tl_gets(tags,
/* By nua_stack_set_from() */ /* By nua_stack_set_from() */
SIPTAG_FROM_REF(from), SIPTAG_FROM_REF(from),
SIPTAG_FROM_STR_REF(str), SIPTAG_FROM_STR_REF(str),
NUTAG_UICC_REF(uicc_name),
TAG_END()); TAG_END());
#if HAVE_UICC_H
if (initial && uicc_name)
nua->nua_uicc = uicc_create(root, uicc_name);
#endif
if (!initial && from == NONE && str == NONE) if (!initial && from == NONE && str == NONE)
return; return 0;
sip_from_init(f0); sip_from_init(f0);
...@@ -157,8 +165,11 @@ void nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags) ...@@ -157,8 +165,11 @@ void nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags)
} }
} }
if (f) if (!f)
*nua->nua_from = *f; return -1;
*nua->nua_from = *f;
return 0;
} }
/** @internal Initialize instance ID. */ /** @internal Initialize instance ID. */
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "nua_stack.h" #include "nua_stack.h"
#include <sofia-sip/nta_tport.h> #include <sofia-sip/nta_tport.h>
#include <sofia-sip/tport_tag.h>
#if HAVE_SIGCOMP #if HAVE_SIGCOMP
#include <sigcomp.h> #include <sigcomp.h>
...@@ -786,7 +787,69 @@ refresh_register(nua_handle_t *nh, nua_dialog_usage_t *du, sip_time_t now) ...@@ -786,7 +787,69 @@ refresh_register(nua_handle_t *nh, nua_dialog_usage_t *du, sip_time_t now)
static void nua_stack_tport_update(nua_t *nua, nta_agent_t *nta); static void nua_stack_tport_update(nua_t *nua, nta_agent_t *nta);
int int
nua_stack_registrations_init(nua_t *nua) nua_stack_init_transport(nua_t *nua, tagi_t const *tags)
{
url_string_t const *contact1 = NULL, *contact2 = NULL;
char const *name1 = "sip", *name2 = "sip";
char const *certificate_dir = NULL;
tl_gets(tags,
NUTAG_URL_REF(contact1),
NUTAG_SIPS_URL_REF(contact2),
NUTAG_CERTIFICATE_DIR_REF(certificate_dir),
TAG_END());
if (contact1 &&
(url_is_string(contact1)
? strncasecmp(contact1->us_str, "sips:", 5) == 0
: contact1->us_url->url_type == url_sips))
name1 = "sips";
if (contact2 &&
(url_is_string(contact2)
? strncasecmp(contact2->us_str, "sips:", 5) == 0
: contact2->us_url->url_type == url_sips))
name2 = "sips";
if (!contact1 && !contact2) {
if (nta_agent_add_tport(nua->nua_nta, NULL,
TPTAG_IDENT("sip"),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0 &&
nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("*"),
TPTAG_IDENT("sip"),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)
return -1;
if (nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("*"),
TPTAG_IDENT("stun"),
TPTAG_PUBLIC(tport_type_stun), /* use stun */
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)
return -1;
}
else if ((!contact1 ||
nta_agent_add_tport(nua->nua_nta, contact1,
TPTAG_IDENT(name1),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0) &&
(!contact2 ||
nta_agent_add_tport(nua->nua_nta, contact2,
TPTAG_IDENT(name2),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)) {
return -1;
}
if (nua_stack_init_registrations(nua) < 0)
return -1;
return 0;
}
int
nua_stack_init_registrations(nua_t *nua)
{ {
/* Create initial identities: peer-to-peer, public, sips */ /* Create initial identities: peer-to-peer, public, sips */
sip_via_t const *v; sip_via_t const *v;
...@@ -1794,11 +1857,17 @@ int outbound_connect_init(outbound_connect *oc, ...@@ -1794,11 +1857,17 @@ int outbound_connect_init(outbound_connect *oc,
return outbound_connect_set_options(oc, options); return outbound_connect_set_options(oc, options);
} }
int outbound_connect_set_options(outbound_connect *oc, char const *options) int outbound_connect_set_options(outbound_connect *oc, char const *options)
{ {
struct outbound_prefs prefs[1] = {{ 0 }}; struct outbound_prefs prefs[1] = {{ 0 }};
char *s; char *s;
prefs->gruuize = 1;
prefs->outbound = 1;
prefs->natify = 1;
prefs->validate = 1;
#define MATCH(v) (len == sizeof(#v) - 1 && strncasecmp(#v, s, len) == 0) #define MATCH(v) (len == sizeof(#v) - 1 && strncasecmp(#v, s, len) == 0)
for (s = (char *)options; s && s[0]; ) { for (s = (char *)options; s && s[0]; ) {
......
...@@ -112,12 +112,6 @@ char const nua_application_sdp[] = "application/sdp"; ...@@ -112,12 +112,6 @@ char const nua_application_sdp[] = "application/sdp";
int nua_stack_init(su_root_t *root, nua_t *nua) int nua_stack_init(su_root_t *root, nua_t *nua)
{ {
su_home_t *home; su_home_t *home;
void *sip_parser = NULL;
url_string_t const *contact = NULL;
url_string_t const *sips_contact = NULL;
char const *certificate_dir = NULL;
char const *uicc_name = "default";
nua_handle_t *dnh; nua_handle_t *dnh;
int media_enable = 1; int media_enable = 1;
...@@ -169,59 +163,37 @@ int nua_stack_init(su_root_t *root, nua_t *nua) ...@@ -169,59 +163,37 @@ int nua_stack_init(su_root_t *root, nua_t *nua)
nua->nua_invite_accept = sip_accept_make(home, SDP_MIME_TYPE); nua->nua_invite_accept = sip_accept_make(home, SDP_MIME_TYPE);
/* Set initial nta/soa parameters */
if (tl_gets(nua->nua_args,
NUTAG_URL_REF(contact),
NUTAG_SIPS_URL_REF(sips_contact),
NUTAG_CERTIFICATE_DIR_REF(certificate_dir),
NUTAG_SIP_PARSER_REF(sip_parser),
NUTAG_UICC_REF(uicc_name),
NUTAG_MEDIA_ENABLE_REF(media_enable),
NUTAG_SOA_NAME_REF(soa_name),
TAG_NULL()) < 0)
return -1;
#if HAVE_UICC_H
if (uicc_name)
nua->nua_uicc = uicc_create(root, uicc_name);
#endif
nua->nua_nta = nta_agent_create(root, NONE, NULL, NULL, nua->nua_nta = nta_agent_create(root, NONE, NULL, NULL,
TPTAG_CERTIFICATE(certificate_dir),
NTATAG_MERGE_482(1), NTATAG_MERGE_482(1),
NTATAG_CLIENT_RPORT(1), NTATAG_CLIENT_RPORT(1),
NTATAG_UA(1), NTATAG_UA(1),
#if HAVE_SOFIA_SMIME #if HAVE_SOFIA_SMIME
NTATAG_SMIME(nua->sm), NTATAG_SMIME(nua->sm),
#endif #endif
TPTAG_STUN_SERVER(1),
TAG_NEXT(nua->nua_args)); TAG_NEXT(nua->nua_args));
if (!nua->nua_nta)
return -1;
nta_agent_set_params(nua->nua_nta, NTATAG_UA(1), TAG_END()); dnh->nh_ds->ds_leg = nta_leg_tcreate(nua->nua_nta,
nua_stack_process_request, dnh,
if (!contact && !sips_contact) { NTATAG_NO_DIALOG(1),
if (nta_agent_add_tport(nua->nua_nta, NULL, TAG_END());
TAG_NEXT(nua->nua_args)) < 0 &&
nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("sip:*:*"), if (nua->nua_nta == NULL ||
TAG_NEXT(nua->nua_args)) < 0 && dnh->nh_ds->ds_leg == NULL ||
nta_agent_add_tport(nua->nua_nta, NULL, nta_agent_set_params(nua->nua_nta, NTATAG_UA(1), TAG_END()) < 0 ||
TPTAG_PUBLIC(tport_type_stun), /* use stun */ nua_stack_init_transport(nua, nua->nua_args) < 0) {
TAG_NEXT(nua->nua_args)) < 0) SU_DEBUG_1(("nua: initializing SIP stack failed\n"));
return -1;
} }
else if ((!contact ||
nta_agent_add_tport(nua->nua_nta, contact, if (nua_stack_set_from(nua, 1, nua->nua_args) < 0)
TAG_NEXT(nua->nua_args)) < 0) &&
(!sips_contact ||
nta_agent_add_tport(nua->nua_nta, sips_contact,
TAG_NEXT(nua->nua_args)) < 0)) {
return -1; return -1;
}
if (nua_stack_registrations_init(nua) < 0) /* Set initial nta/soa parameters */
if (tl_gets(nua->nua_args,
NUTAG_MEDIA_ENABLE_REF(media_enable),
NUTAG_SOA_NAME_REF(soa_name),
TAG_NULL()) < 0)
return -1; return -1;
nua_stack_set_from(nua, 1, nua->nua_args);
nua->nua_media_enable = media_enable; nua->nua_media_enable = media_enable;
...@@ -232,18 +204,10 @@ int nua_stack_init(su_root_t *root, nua_t *nua) ...@@ -232,18 +204,10 @@ int nua_stack_init(su_root_t *root, nua_t *nua)
soa_set_params(soa, TAG_NEXT(nua->nua_args)); soa_set_params(soa, TAG_NEXT(nua->nua_args));
} }
dnh->nh_ds->ds_leg = nta_leg_tcreate(nua->nua_nta,
nua_stack_process_request, dnh,
NTATAG_NO_DIALOG(1),
TAG_END());
nua->nua_timer = su_timer_create(su_root_task(root), nua->nua_timer = su_timer_create(su_root_task(root),
NUA_STACK_TIMER_INTERVAL); NUA_STACK_TIMER_INTERVAL);
if (!(dnh->nh_ds->ds_leg && if (!nua->nua_timer)
nua->nua_registrations &&
nua->nua_from &&
nua->nua_timer))
return -1; return -1;
nua_stack_timer(nua, nua->nua_timer, NULL); nua_stack_timer(nua, nua->nua_timer, NULL);
......
...@@ -362,7 +362,9 @@ int nua_stack_init(su_root_t *root, nua_t *nua); ...@@ -362,7 +362,9 @@ int nua_stack_init(su_root_t *root, nua_t *nua);
void nua_stack_deinit(su_root_t *root, nua_t *nua); void nua_stack_deinit(su_root_t *root, nua_t *nua);
void nua_stack_signal(nua_t *nua, su_msg_r msg, event_t *e); void nua_stack_signal(nua_t *nua, su_msg_r msg, event_t *e);
int nua_stack_registrations_init(nua_t *nua); int nua_stack_init_transport(nua_t *nua, tagi_t const *tags);
int nua_stack_init_registrations(nua_t *nua);
int outbound_connect_check_accept(sip_accept_t const *accept); int outbound_connect_check_accept(sip_accept_t const *accept);
...@@ -415,7 +417,7 @@ nua_handle_t *nh_validate(nua_t *nua, nua_handle_t *maybe); ...@@ -415,7 +417,7 @@ nua_handle_t *nh_validate(nua_t *nua, nua_handle_t *maybe);
int nua_stack_set_defaults(nua_handle_t *nh, nua_handle_preferences_t *nhp); int nua_stack_set_defaults(nua_handle_t *nh, nua_handle_preferences_t *nhp);
void nua_stack_set_from(nua_t *, int initial, tagi_t const *tags); int nua_stack_set_from(nua_t *, int initial, tagi_t const *tags);
int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags); int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags);
......
...@@ -109,8 +109,6 @@ tag_typedef_t nutag_outbound_set4 = STRTAG_TYPEDEF(outbound_set4); ...@@ -109,8 +109,6 @@ tag_typedef_t nutag_outbound_set4 = STRTAG_TYPEDEF(outbound_set4);
tag_typedef_t nutag_keepalive = UINTTAG_TYPEDEF(keepalive); tag_typedef_t nutag_keepalive = UINTTAG_TYPEDEF(keepalive);
tag_typedef_t nutag_keepalive_stream = UINTTAG_TYPEDEF(keepalive_stream); tag_typedef_t nutag_keepalive_stream = UINTTAG_TYPEDEF(keepalive_stream);
tag_typedef_t nutag_sip_parser = PTRTAG_TYPEDEF(sip_parser);
tag_typedef_t nutag_use_dialog = BOOLTAG_TYPEDEF(use_dialog); tag_typedef_t nutag_use_dialog = BOOLTAG_TYPEDEF(use_dialog);
tag_typedef_t nutag_auth = STRTAG_TYPEDEF(auth); tag_typedef_t nutag_auth = STRTAG_TYPEDEF(auth);
......
...@@ -889,15 +889,14 @@ extern tag_typedef_t nutag_outbound_set4_ref; ...@@ -889,15 +889,14 @@ extern tag_typedef_t nutag_outbound_set4_ref;
* msg_mclass_t * * msg_mclass_t *
* *
* @par Values * @par Values
* Pointer to an extended SIP parser.
* *
* Corresponding tag taking reference parameter is NUTAG_SIP_PARSER_REF() * @sa msg_mclass_clone(), msg_mclass_insert_header()
*
* Corresponding tag taking reference parameter is NUTAG_SIP_PARSER_REF().
*/ */
#define NUTAG_SIP_PARSER(x) nutag_sip_parser, tag_ptr_v(x) #define NUTAG_SIP_PARSER(x) NTATAG_MCLASS(x)
extern tag_typedef_t nutag_sip_parser; #define NUTAG_SIP_PARSER_REF(x) NTATAG_MCLASS_REF(x)
#define NUTAG_SIP_PARSER_REF(x) \
nutag_sip_parser_ref, tag_ptr_vr(&(x), (x))
extern tag_typedef_t nutag_sip_parser_ref;
/** Authentication data ("scheme" "realm" "user" "password") /** Authentication data ("scheme" "realm" "user" "password")
* *
......
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