Commit 3fc01be1 authored by Pekka Pessi's avatar Pekka Pessi

Fixed agent_init_contact() in nta/nta.c.

The logic for selecting transport parameter for primary contact was flawed.
Added some tests, too.

darcs-hash:20051020173738-65a35-8b7323dc5979373b8dc6927a8b5563404ed003c5.gz
parent 50885974
......@@ -1574,28 +1574,39 @@ int agent_init_via(nta_agent_t *self, int use_maddr)
}
/** Initialize contact header. */
/** Initialize main contact header. */
static
int agent_init_contact(nta_agent_t *self)
{
sip_via_t const *v = agent_tport_via(tport_primaries(self->sa_tports));
sip_via_t const *v1 = self->sa_vias, *v2;
char const *tp;
if (self->sa_contact)
return 0;
if (!v) return -1;
tp = strrchr(v->v_protocol, '/');
if (!v1) return -1;
tp = strrchr(v1->v_protocol, '/');
if (!tp++)
return -1;
if (strcasecmp(tp, "udp") == 0 && v->v_next &&
str0casecmp(v->v_next->v_protocol, sip_transport_tcp))
/* Do not include transport if we have both UDP and TCP */
tp = NULL;
v2 = v1->v_next;
if (v2 &&
strcasecmp(v1->v_host, v2->v_host) == 0 &&
strcasecmp(v1->v_port, v2->v_port) == 0) {
char const *p1 = v1->v_protocol, *p2 = v2->v_protocol;
if (strcasecmp(p1, sip_transport_udp))
p1 = v2->v_protocol, p2 = v1->v_protocol;
if (strcasecmp(p1, sip_transport_udp) == 0 &&
strcasecmp(p2, sip_transport_tcp) == 0)
/* Do not include transport if we have both UDP and TCP */
tp = NULL;
}
self->sa_contact =
sip_contact_create_from_via_with_transport(self->sa_home, v, NULL, tp);
sip_contact_create_from_via_with_transport(self->sa_home, v1, NULL, tp);
if (!self->sa_contact)
return -1;
......
......@@ -80,6 +80,8 @@ int tstflags = 0;
#define __func__ name
#endif
#define NONE ((void *)-1)
struct sigcomp_compartment;
char const name[] = "nta_test";
......@@ -766,8 +768,59 @@ int test_tports(agent_t *ag)
BEGIN();
nta_agent_t *agent;
sip_contact_t const *m;
*url = *ag->ag_contact->m_url;
url->url_port = "*";
url->url_params = "transport=tcp";
TEST_1(agent = nta_agent_create(ag->ag_root, NONE, NULL, NULL, TAG_END()));
TEST_1(!nta_agent_via(agent));
TEST_1(!nta_agent_contact(agent));
TEST_1(nta_agent_add_tport(agent, (url_string_t *)url, TAG_END()) == 0);
TEST_1(v = nta_agent_via(agent));
TEST(strcasecmp(v->v_protocol, sip_transport_tcp), 0);
TEST_1(m = nta_agent_contact(agent));
TEST_S(m->m_url->url_params, "transport=tcp");
url->url_params = "transport=udp";
TEST_1(nta_agent_add_tport(agent, (url_string_t *)url, TAG_END()) == 0);
TEST_1(v = nta_agent_via(agent)); TEST_1(v = v->v_next);
TEST(strcasecmp(v->v_protocol, sip_transport_udp), 0);
TEST_VOID(nta_agent_destroy(agent));
TEST_1(agent = nta_agent_create(ag->ag_root, NONE, NULL, NULL, TAG_END()));
TEST_1(nta_agent_add_tport(agent, (url_string_t *)url, TAG_END()) == 0);
TEST_1(v = nta_agent_via(agent)); TEST_1(!v->v_next);
TEST(strcasecmp(v->v_protocol, sip_transport_udp), 0);
TEST_1(m = nta_agent_contact(agent));
TEST_S(m->m_url->url_params, "transport=udp");
TEST_VOID(nta_agent_destroy(agent));
url->url_params = "transport=tcp,udp";
TEST_1(agent = nta_agent_create(ag->ag_root, NONE, NULL, NULL, TAG_END()));
TEST_1(nta_agent_add_tport(agent, (url_string_t *)url, TAG_END()) == 0);
TEST_1(v = nta_agent_via(agent));
TEST(strcasecmp(v->v_protocol, sip_transport_tcp), 0);
TEST_1(v = v->v_next);
TEST(strcasecmp(v->v_protocol, sip_transport_udp), 0);
TEST_1(m = nta_agent_contact(agent));
TEST_1(!m->m_url->url_params);
TEST_VOID(nta_agent_destroy(agent));
url->url_params = NULL;
TEST_1(agent = nta_agent_create(ag->ag_root, NONE, NULL, NULL, TAG_END()));
TEST_1(nta_agent_add_tport(agent, (url_string_t *)url, TAG_END()) == 0);
TEST_1(v = nta_agent_via(agent));
TEST(strcasecmp(v->v_protocol, sip_transport_udp), 0);
TEST_1(v = v->v_next);
TEST(strcasecmp(v->v_protocol, sip_transport_tcp), 0);
TEST_1(m = nta_agent_contact(agent));
TEST_1(!m->m_url->url_params);
TEST_VOID(nta_agent_destroy(agent));
url->url_params = "transport=udp";
TEST_1(nta_agent_add_tport(ag->ag_agent, (url_string_t *)url,
......@@ -2347,6 +2400,7 @@ int test_call(agent_t *ag)
SIPTAG_SUBJECT_STR("Call 1"),
SIPTAG_CONTACT(ag->ag_m_alice),
SIPTAG_CONTENT_TYPE(c),
SIPTAG_ACCEPT_CONTACT_STR("*;audio"),
SIPTAG_PAYLOAD(sdp),
NTATAG_USE_TIMESTAMP(1),
NTATAG_PASS_100(1),
......
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