Commit d13d051d authored by Pekka Pessi's avatar Pekka Pessi

test_nua. added tests for initial route set

darcs-hash:20070917141600-65a35-867c1a061fc13d90df55e7f411115dc6a536f0f9.gz
parent 2eca488d
......@@ -1436,12 +1436,13 @@ int test_basic_call_6(struct context *ctx)
struct endpoint *a = &ctx->a, *b = &ctx->b;
struct call *a_call = a->call, *b_call = b->call;
struct event *e;
sip_route_t *r, rb[1];
sip_t *sip;
sip_contact_t ma[1], mb[1];
if (print_headings)
printf("TEST NUA-3.1: Basic call\n");
printf("TEST NUA-3.6: Basic call\n");
a_call->sdp = "m=audio 5008 RTP/AVP 8";
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
......@@ -1460,9 +1461,17 @@ int test_basic_call_6(struct context *ctx)
mb->m_url->url_user = "b++b";
contact_for_b = mb;
sip_route_init(rb)->r_url[0] = b->contact->m_url[0];
rb->r_url->url_user = "bob+0";
url_param_add(nua_handle_home(a_call->nh), rb->r_url, "lr");
INVITE(a, a_call, a_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
NUTAG_URL("sip:bob@example.org"), /* Expanded by proxy */
SIPTAG_ROUTE_STR("B2 <sip:bob+2@example.org>;bar=foo"), /* Last in list */
NUTAG_INITIAL_ROUTE(ctx->lr), /* Removed by proxy (if any) */
NUTAG_INITIAL_ROUTE(rb), /* Used to route request to b (not removed) */
NUTAG_INITIAL_ROUTE_STR("B1 <sip:bob+1@example.org;lr>;foo=bar"), /* Next in list */
SOATAG_USER_SDP_STR(a_call->sdp),
SIPTAG_CONTACT(ma),
TAG_END());
......@@ -1517,6 +1526,14 @@ int test_basic_call_6(struct context *ctx)
TEST_1(sip->sip_contact);
TEST_S(sip->sip_contact->m_display, "Alice B.");
TEST_S(sip->sip_contact->m_url->url_user, "a++a");
TEST_1(r = sip->sip_route);
TEST_S(r->r_url->url_user, "bob+0");
TEST_1(r = r->r_next);
TEST_S(r->r_url->url_user, "bob+1");
TEST_1(r = r->r_next);
TEST_S(r->r_url->url_user, "bob+2");
TEST_1(!r->r_next);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_received); /* RECEIVED */
TEST_1(is_offer_recv(e->data->e_tags));
......@@ -1598,7 +1615,7 @@ int test_basic_call_6(struct context *ctx)
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
if (print_headings)
printf("TEST NUA-3.1: PASSED\n");
printf("TEST NUA-3.6: PASSED\n");
END();
}
......
......@@ -72,6 +72,7 @@ int test_nua_init(struct context *ctx,
sip_supported_t const *supported = NULL;
char const *appl_method = NULL;
url_t const *p_uri, *a_uri, *b_uri; /* Proxy URI */
char const *initial_route = NULL; /* Initial route towards internal proxy */
char const *a_bind, *a_bind2;
int err = -1;
url_t b_proxy[1];
......@@ -164,6 +165,9 @@ int test_nua_init(struct context *ctx,
if (start_nat && p_uri == NULL)
p_uri = url_hdup(ctx->home, (void *)o_proxy);
if (ctx->p)
initial_route = test_proxy_route_uri(ctx->p, &ctx->lr);
if (start_nat && p_uri != NULL) {
int family = 0;
su_sockaddr_t su[1];
......@@ -259,6 +263,7 @@ int test_nua_init(struct context *ctx,
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
NUTAG_PROXY(a_uri ? a_uri : o_proxy),
NUTAG_INITIAL_ROUTE_STR(initial_route),
SIPTAG_FROM_STR("sip:alice@example.com"),
NUTAG_URL(a_bind),
TAG_IF(a_bind != a_bind2, NUTAG_SIPS_URL(a_bind2)),
......
......@@ -180,6 +180,7 @@ struct context
} a, b, c;
struct proxy *p;
sip_route_t const *lr;
struct nat *nat;
};
......
......@@ -43,6 +43,8 @@
#define __func__ "test_nua_params"
#endif
sip_route_t *GLOBAL_ROUTE;
int test_tag_filter(void)
{
BEGIN();
......@@ -104,7 +106,6 @@ int test_nua_params(struct context *ctx)
ctx->root = su_root_create(NULL);
TEST_1(ctx->root);
/* Disable threading by command line switch? */
su_root_threading(ctx->root, ctx->threading);
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
......@@ -153,7 +154,6 @@ int test_nua_params(struct context *ctx)
SIPTAG_ALLOW_EVENTS_STR("reg"),
SIPTAG_USER_AGENT_STR("test_nua/1.0"),
SIPTAG_ORGANIZATION_STR("Open Laboratory"),
NUTAG_M_DISPLAY("XXX"),
......@@ -163,6 +163,12 @@ int test_nua_params(struct context *ctx)
NUTAG_INSTANCE("urn:uuid:3eb007b1-6d7f-472e-8b64-29e482795da8"),
NUTAG_OUTBOUND("bar"),
NUTAG_INITIAL_ROUTE(NULL),
NUTAG_INITIAL_ROUTE(sip_route_make(tmphome, "<sip:tst@example.net;lr>")),
NUTAG_INITIAL_ROUTE_STR("<sip:str1@example.net;lr>"),
NUTAG_INITIAL_ROUTE_STR("sip:str2@example.net;lr=foo"),
NUTAG_INITIAL_ROUTE_STR(NULL),
TAG_END());
run_a_until(ctx, nua_r_set_params, until_final_response);
......@@ -221,6 +227,12 @@ int test_nua_params(struct context *ctx)
SIPTAG_ALLOW_EVENTS(sip_allow_events_make(tmphome, "presence")),
NUTAG_ALLOW_EVENTS("presence.winfo"),
NUTAG_INITIAL_ROUTE(NULL),
NUTAG_INITIAL_ROUTE(sip_route_make(nua_handle_home(nh), "<sip:1@example.com;lr>")),
NUTAG_INITIAL_ROUTE_STR("<sip:2@example.com;lr>"),
/* Check for sip_route_fix() */
NUTAG_INITIAL_ROUTE_STR("sip:3@example.com;lr=foo"),
NUTAG_INITIAL_ROUTE_STR(NULL),
SIPTAG_USER_AGENT(sip_user_agent_make(tmphome, "test_nua")),
......@@ -287,6 +299,9 @@ int test_nua_params(struct context *ctx)
sip_organization_t const *organization = NONE;
char const *organization_str = "NONE";
sip_route_t *initial_route = NONE;
char const *initial_route_str = NONE;
char const *outbound = "NONE";
char const *m_display = "NONE";
char const *m_username = "NONE";
......@@ -352,6 +367,9 @@ int test_nua_params(struct context *ctx)
SIPTAG_ORGANIZATION_REF(organization),
SIPTAG_ORGANIZATION_STR_REF(organization_str),
NUTAG_INITIAL_ROUTE_REF(initial_route),
NUTAG_INITIAL_ROUTE_STR_REF(initial_route_str),
NUTAG_REGISTRAR_REF(registrar),
NUTAG_KEEPALIVE_REF(keepalive),
NUTAG_KEEPALIVE_STREAM_REF(keepalive_stream),
......@@ -364,7 +382,7 @@ int test_nua_params(struct context *ctx)
NUTAG_INSTANCE_REF(instance),
TAG_END());
TEST(n, 48);
TEST(n, 50);
TEST_S(sip_header_as_string(tmphome, (void *)from), Alice);
TEST_S(from_str, Alice);
......@@ -414,6 +432,17 @@ int test_nua_params(struct context *ctx)
"Pussy Galore's Flying Circus");
TEST_S(organization_str, "Pussy Galore's Flying Circus");
TEST_1(initial_route); TEST_1(initial_route != (void *)-1);
TEST_S(initial_route->r_url->url_user, "1");
TEST_1(url_has_param(initial_route->r_url, "lr"));
TEST_1(initial_route->r_next);
TEST_S(initial_route->r_next->r_url->url_user, "2");
TEST_1(url_has_param(initial_route->r_next->r_url, "lr"));
TEST_1(initial_route->r_next->r_next);
TEST_S(initial_route->r_next->r_next->r_url->url_user, "3");
TEST_1(url_has_param(initial_route->r_next->r_next->r_url, "lr"));
TEST_1(!initial_route->r_next->r_next->r_next);
TEST_S(url_as_string(tmphome, registrar->us_url),
"sip:sip.wonderland.org");
TEST(keepalive, 66);
......@@ -473,6 +502,9 @@ int test_nua_params(struct context *ctx)
sip_organization_t const *organization = NONE;
char const *organization_str = "NONE";
sip_route_t *initial_route = NONE;
char const *initial_route_str = "NONE";
url_string_t const *registrar = NONE;
char const *outbound = "NONE";
......@@ -585,6 +617,9 @@ int test_nua_params(struct context *ctx)
TEST_P(organization, NONE);
TEST_S(organization_str, "NONE");
TEST_1(initial_route == (void *)-1);
TEST_S(initial_route_str, "NONE");
TEST_S(outbound, "NONE");
TEST_S(m_display, "NONE");
TEST_S(m_username, "NONE");
......
......@@ -100,6 +100,8 @@ struct proxy {
nta_agent_t *agent;
url_t const *uri;
sip_route_t *lr;
char const *lr_str;
url_t const *rr_uri;
nta_leg_t *defleg;
......@@ -326,7 +328,12 @@ test_proxy_init(su_root_t *root, struct proxy *proxy)
return -1;
proxy->uri = nta_agent_contact(proxy->agent)->m_url;
proxy->lr_str = su_sprintf(proxy->home, "<" URL_PRINT_FORMAT ";lr>", URL_PRINT_ARGS(proxy->uri));
proxy->lr = sip_route_make(proxy->home, proxy->lr_str);
if (!proxy->lr)
return -1;
return 0;
}
......@@ -391,6 +398,19 @@ url_t const *test_proxy_uri(struct proxy const *p)
return p ? p->uri : NULL;
}
/* Return the proxy route URI */
char const *test_proxy_route_uri(struct proxy const *p,
sip_route_t const **return_route)
{
if (p == NULL)
return NULL;
if (return_route)
*return_route = p->lr;
return p->lr_str;
}
void test_proxy_domain_set_expiration(struct domain *d,
sip_time_t min_expires,
sip_time_t expires,
......@@ -796,8 +816,9 @@ static int validate_transaction(struct proxy_tr *t)
/* Remove our routes */
while (t->sip->sip_route &&
url_has_param(t->sip->sip_route->r_url, "lr") &&
url_cmp(t->proxy->rr_uri, t->sip->sip_route->r_url) == 0) {
url_has_param(t->sip->sip_route->r_url, "lr") &&
(url_cmp(t->proxy->lr->r_url, t->sip->sip_route->r_url) == 0 ||
url_cmp(t->proxy->rr_uri, t->sip->sip_route->r_url) == 0)) {
sip_route_remove(t->msg, t->sip);
/* add record-route also to the forwarded request */
t->rr = 1;
......
......@@ -39,6 +39,9 @@ void test_proxy_destroy(struct proxy *);
url_t const *test_proxy_uri(struct proxy const *);
char const *test_proxy_route_uri(struct proxy const *p,
sip_route_t const **return_route);
struct domain *test_proxy_add_domain(struct proxy *,
url_t const *domain,
tag_type_t, tag_value_t, ...);
......
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