Commit b5c7ea04 authored by Pekka Pessi's avatar Pekka Pessi

Fixed binding problems in nua and nta.c.

Returning more appropriate error code from tport_tbind(), too.
This patch fixes tracked bugs
#1485624 (nua not binding to 5060),
#1485625 (nua_create() fails if STUN init fails) and
#1485632 (ncorrect error message for nua bind error).
Nua now also binds both to NUTAG_URL and NUTAG_SIPS_URL() URIs, nua_create()
fails if binding either of them fails.

darcs-hash:20060512135552-65a35-be04d33c18f485b16d4407c0c8534b15e5424c73.gz
parent 2a7b3c9a
......@@ -1415,20 +1415,24 @@ int nta_agent_add_tport(nta_agent_t *self,
return -1;
}
tpn->tpn_canon = url->url_host;
tpn->tpn_host = url->url_host;
tpn->tpn_port = url_port(url);
if (url->url_type == url_sip) {
tpn->tpn_proto = "*";
tports = tports_sip;
if (!tpn->tpn_port || !tpn->tpn_port[0])
tpn->tpn_port = SIP_DEFAULT_SERV;
}
else {
assert(url->url_type == url_sips);
tpn->tpn_proto = "tls";
tpn->tpn_proto = "*";
tports = tports_sips;
if (!tpn->tpn_port || !tpn->tpn_port[0])
tpn->tpn_port = SIPS_DEFAULT_SERV;
}
tpn->tpn_canon = url->url_host;
tpn->tpn_host = url->url_host;
tpn->tpn_port = url_port(url);
if (url->url_params) {
if (url_param(url->url_params, "transport", tp, sizeof(tp)) > 0) {
if (strchr(tp, ',')) {
......
......@@ -840,6 +840,9 @@ nua_stack_init_transport(nua_t *nua, tagi_t const *tags)
NUTAG_CERTIFICATE_DIR_REF(certificate_dir),
TAG_END());
if (!contact1 && contact2)
contact1 = contact2, contact2 = NULL;
if (contact1 &&
(url_is_string(contact1)
? strncasecmp(contact1->us_str, "sips:", 5) == 0
......@@ -852,43 +855,43 @@ nua_stack_init_transport(nua_t *nua, tagi_t const *tags)
: contact2->us_url->url_type == url_sips))
name2 = "sips";
if (!contact1 && !contact2) {
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 &&
TPTAG_IDENT("sip"),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0 &&
nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("sip:*:*"),
TPTAG_IDENT("sip"),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)
TPTAG_IDENT("sip"),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)
return -1;
#if HAVE_SOFIA_STUN
if (stun_is_requested(TAG_NEXT(nua->nua_args)))
if (nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("sip:*:*"),
TPTAG_IDENT("stun"),
TPTAG_PUBLIC(tport_type_stun), /* use stun */
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0) {
SU_DEBUG_5(("nua: error initializing STUN transport\n"));
return -1;
}
if (stun_is_requested(TAG_NEXT(nua->nua_args)) &&
nta_agent_add_tport(nua->nua_nta, URL_STRING_MAKE("sip:0.0.0.0:*"),
TPTAG_IDENT("stun"),
TPTAG_PUBLIC(tport_type_stun), /* use stun */
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0) {
SU_DEBUG_0(("nua: error initializing STUN transport\n"));
}
#endif
}
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;
else {
if (nta_agent_add_tport(nua->nua_nta, contact1,
TPTAG_IDENT(name1),
TPTAG_CERTIFICATE(certificate_dir),
TAG_NEXT(nua->nua_args)) < 0)
return -1;
if (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;
......
......@@ -447,8 +447,10 @@ stun_handle_t *stun_handle_init(su_root_t *root,
__func__, server));
/* fail, if no server or a domain for a DNS-SRV lookup is specified */
if (!server && !domain)
if (!server && !domain) {
errno = ENOENT;
return NULL;
}
stun->sh_pri_info.ai_addrlen = 16;
stun->sh_pri_info.ai_addr = &stun->sh_pri_addr->su_sa;
......@@ -464,9 +466,10 @@ stun_handle_t *stun_handle_init(su_root_t *root,
if (server) {
err = stun_atoaddr(stun->sh_home, AF_INET, &stun->sh_pri_info, server);
if (err < 0)
if (err < 0) {
errno = ENOENT;
return NULL;
}
}
stun->sh_nattype = stun_nat_unknown;
......@@ -2660,7 +2663,8 @@ int stun_atoaddr(su_home_t *home,
dstaddr->su_port = htons(STUN_DEFAULT_PORT);
}
else {
STUN_ERROR(err, su_getaddrinfo);
SU_DEBUG_5(("stun_atoaddr: %s(%s): %s\n", "su_getaddrinfo", in,
su_gai_strerror(err)));
}
if (res)
......
......@@ -1457,7 +1457,7 @@ int tport_bind_server(tport_master_t *mr,
;
port = port0 = port1 = ntohs(((su_sockaddr_t *)res->ai_addr)->su_port);
error = ENOENT, not_supported = 1;
error = EPROTONOSUPPORT;
/*
* Loop until we can bind all the transports requested
......@@ -1535,9 +1535,6 @@ int tport_bind_server(tport_master_t *mr,
tport_freeaddrinfo(res);
if (res && not_supported)
error = EPROTONOSUPPORT;
if (!*tbf) {
su_seterrno(error);
return -1;
......@@ -1628,7 +1625,7 @@ int tport_server_addrinfo(tport_master_t *mr,
}
if (N == 0)
return su_seterrno(ENOENT);
return su_seterrno(EPROTONOSUPPORT);
if (transports[i] /* Too many protocols */)
return su_seterrno(ENOMEM);
......
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