Commit 5e41a92d authored by Pekka Pessi's avatar Pekka Pessi

nua_subnotref.c: fixed REFER re-try case

REFER trashed its dialog when it got retried if there was no other dialog
usages.

darcs-hash:20080121190911-65a35-4edb2a972eba0f900e37ed458bdfd8c16519c592.gz
parent 4d1eaf06
......@@ -831,22 +831,31 @@ static int nua_refer_client_request(nua_client_request_t *cr,
tagi_t const *tags)
{
nua_handle_t *nh = cr->cr_owner;
nua_dialog_usage_t *du = cr->cr_usage;
nua_dialog_usage_t *du, *du0 = cr->cr_usage;
struct event_usage *eu;
sip_event_t *event;
int error;
cr->cr_usage = NULL;
if (du)
nua_dialog_usage_remove(nh, nh->nh_ds, du);
event = sip_event_format(nh->nh_home, "refer;id=%u", sip->sip_cseq->cs_seq);
if (!event)
return -1;
du = nua_dialog_usage_add(nh, nh->nh_ds, nua_subscribe_usage, event);
if (!du)
return -1;
if (du0 == NULL ||
du0->du_event == NULL ||
du0->du_event->o_id == NULL ||
strcmp(du0->du_event->o_id, event->o_id)) {
du = nua_dialog_usage_add(nh, nh->nh_ds, nua_subscribe_usage, event);
if (!du)
return -1;
}
else {
du = du0, du0 = NULL;
}
if (du0)
nua_dialog_usage_remove(nh, nh->nh_ds, du0);
eu = nua_dialog_usage_private(cr->cr_usage = du);
eu ->eu_refer = 1;
......
......@@ -48,13 +48,14 @@
int test_refer0(struct context *ctx, char const *tests,
int refer_with_id, int notify_by_appl);
int notify_until_terminated(CONDITION_PARAMS);
int test_challenge_refer(struct context *ctx);
int test_refer(struct context *ctx)
{
/* test twice, once without id and once with id */
return
test_challenge_refer(ctx) ||
test_refer0(ctx, "NUA-9.1", 0, 0) ||
test_refer0(ctx, "NUA-9.2", 1, 0) ||
test_refer0(ctx, "NUA-9.3", 0, 1) ||
......@@ -713,3 +714,129 @@ int notify_until_terminated(CONDITION_PARAMS)
return 0;
}
}
int authenticate_refer(CONDITION_PARAMS);
int reject_refer(CONDITION_PARAMS);
int test_challenge_refer(struct context *ctx)
{
BEGIN();
struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c;
struct call *a_call = a->call, *c_call = c->call;
struct event *e, *e_notify = NULL;
sip_t const *sip;
sip_refer_to_t r0[1];
if (print_headings)
printf("TEST NUA-9.0.1: challenge REFER\n");
nua_set_params(ctx->a.nua, NUTAG_APPL_METHOD("REFER"), TAG_END());
run_a_until(ctx, nua_r_set_params, until_final_response);
*sip_refer_to_init(r0)->r_url = *b->contact->m_url;
r0->r_url->url_headers = "subject=referred";
r0->r_display = "B";
TEST_1(c_call->nh = nua_handle(c->nua, c_call, SIPTAG_TO(a->to), TAG_END()));
REFER(c, c_call, c_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(a->contact->m_url)),
SIPTAG_FROM(c->to),
SIPTAG_REFER_TO(r0),
TAG_END());
run_abc_until(ctx, -1, reject_refer, -1, NULL, -1, authenticate_refer);
/*
Events in A:
nua_i_refer
*/
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_refer);
TEST(e->data->e_status, 100);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_refer_to);
/*
Events in C after nua_refer():
nua_r_refer
*/
TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_refer);
TEST(e->data->e_status, 100);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_refer);
TEST(e->data->e_status, 407);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_refer);
TEST(e->data->e_status, 100);
if (e->next && e->next->data->e_event == nua_i_notify) {
e_notify = e;
TEST_1(e = e->next);
}
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_refer);
TEST(e->data->e_status, 480);
if (e->next && e->next->data->e_event == nua_i_notify) {
e_notify = e;
TEST_1(e = e->next);
}
TEST_1(!e->next);
TEST_1(e_notify);
free_events_in_list(ctx, a->events);
free_events_in_list(ctx, c->events);
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
nua_handle_destroy(c_call->nh), c_call->nh = NULL;
nua_set_params(ctx->a.nua,
NUTAG_APPL_METHOD(NULL),
NUTAG_APPL_METHOD("INVITE, REGISTER, PUBLISH, SUBSCRIBE"),
TAG_END());
run_a_until(ctx, nua_r_set_params, until_final_response);
if (print_headings)
printf("TEST NUA-9.0.1: PASSED\n");
END();
}
int reject_refer(CONDITION_PARAMS)
{
msg_t *with = nua_current_request(nua);
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
return 0;
save_event_in_list(ctx, event, ep, call);
if (event == nua_i_refer) {
RESPOND(ep, call, nh, SIP_480_TEMPORARILY_UNAVAILABLE,
NUTAG_WITH(with),
TAG_END());
}
if (event == nua_r_notify) {
return 1;
}
return 0;
}
int authenticate_refer(CONDITION_PARAMS)
{
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
return 0;
save_event_in_list(ctx, event, ep, call);
if (status == 401 || status == 407) {
AUTHENTICATE(ep, call, nh,
NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"),
TAG_END());
}
return status == 480;
}
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