Commit 64fec982 authored by Pekka Pessi's avatar Pekka Pessi

Improved 100rel handling in nua.

Added test_100rel in test_nua.c.

darcs-hash:20060214114147-65a35-b07847d9d86429eda7084405c39aa86875fa58ee.gz
parent f238fba0
......@@ -112,6 +112,7 @@ typedef enum nua_event_e {
nua_r_publish, /**< Answer to outgoing PUBLISH */
nua_r_unpublish, /**< Answer to outgoing un-PUBLISH */
nua_r_info, /**< Answer to outgoing INFO */
nua_r_prack, /**< Answer to outgoing PRACK */
nua_r_update, /**< Answer to outgoing UPDATE */
nua_r_message, /**< Answer to outgoing MESSAGE */
nua_r_chat, /**< Answer to outgoing chat message */
......
......@@ -247,6 +247,7 @@ char const *nua_event_name(nua_event_t event)
case nua_r_publish: return "nua_r_publish";
case nua_r_unpublish: return "nua_r_unpublish";
case nua_r_info: return "nua_r_info";
case nua_r_prack: return "nua_r_prack";
case nua_r_update: return "nua_r_update";
case nua_r_message: return "nua_r_message";
case nua_r_chat: return "nua_r_chat";
......
......@@ -3964,6 +3964,7 @@ process_100rel(nua_handle_t *nh,
TAG_END());
if (prack) {
cr_prack->cr_event = nua_r_prack;
cr_prack->cr_orq = prack;
if (answer_sent_in_prack)
cr_invite->cr_answer_sent = 1;
......@@ -4001,7 +4002,7 @@ process_response_to_prack(nua_handle_t *nh,
else
status = 408, phrase = sip_408_Request_timeout;
SU_DEBUG_1(("nua: process_response_to_prack:\n"));
SU_DEBUG_5(("nua: process_response_to_prack: %u %s\n", status, phrase));
#if 0
if (crequest_check_restart(nh, cr, orq, sip, restart_prack))
......@@ -4011,12 +4012,14 @@ process_response_to_prack(nua_handle_t *nh,
if (status < 200)
return 0;
crequest_deinit(cr, orq);
if (status < 300 && session_process_response(nh, cr, orq, sip, &recv) < 0) {
status = 500, phrase = "Malformed Session in Response";
reason = "SIP;status=400;phrase=\"Malformed Session in Response\"";
if (status < 300) {
if (session_process_response(nh, cr, orq, sip, &recv) < 0) {
status = 500, phrase = "Malformed Session in Response";
reason = "SIP;status=400;phrase=\"Malformed Session in Response\"";
}
}
else
process_response(nh, cr, orq, sip, TAG_END());
signal_call_state_change(nh, status, phrase,
nua_callstate_proceeding, recv, NULL);
......@@ -4389,8 +4392,14 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
sip_has_feature(ds->ds_remote_ua->nr_supported, "100rel"))
|| (status > 100 &&
ds->ds_remote_ua->nr_require &&
(sip_has_feature(ds->ds_remote_ua->nr_require, "100rel") ||
sip_has_feature(ds->ds_remote_ua->nr_require, "precondition")));
sip_has_feature(ds->ds_remote_ua->nr_require, "100rel"))
|| (status == 183 &&
ds->ds_remote_ua->nr_require &&
sip_has_feature(ds->ds_remote_ua->nr_require, "precondition"))
|| (status > 100 &&
ds->ds_remote_ua->nr_require &&
sip_has_feature(ds->ds_remote_ua->nr_require, "precondition") &&
sr->sr_offer_recv && !sr->sr_answer_sent);
msg = nh_make_response(nua, nh, ss->ss_srequest->sr_irq,
status, phrase,
......@@ -4465,12 +4474,16 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
if (reliable && status < 200)
/* we are done */;
else if (status != original_status) { /* Error responding */
assert(status >= 200);
ss->ss_srequest->sr_respond = NULL;
nta_incoming_treply(ss->ss_srequest->sr_irq,
status, phrase,
TAG_END());
msg_destroy(msg), msg = NULL;
}
else {
if (status >= 200)
ss->ss_srequest->sr_respond = NULL;
nta_incoming_mreply(ss->ss_srequest->sr_irq, msg);
}
......@@ -4495,6 +4508,7 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
/* Update session state */
assert(ss->ss_state != nua_callstate_calling);
assert(ss->ss_state != nua_callstate_proceeding);
signal_call_state_change(nh, status, phrase,
status >= 300
? nua_callstate_init
......@@ -4511,7 +4525,6 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
if (status >= 200) {
ss->ss_usage->du_ready = 1;
ss->ss_srequest->sr_respond = NULL;
}
if (status >= 300) {
......@@ -4519,6 +4532,7 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
soa_init_offer_answer(nh->nh_soa);
nta_incoming_destroy(ss->ss_srequest->sr_irq);
ss->ss_srequest->sr_irq = NULL;
ss->ss_srequest->sr_respond = NULL;
}
su_home_deinit(home);
......@@ -4569,7 +4583,13 @@ int process_prack(nua_handle_t *nh,
if (!sr->sr_irq) /* XXX */
return 481;
if (sip == NULL) { /* Timeout */
if (sip)
/* received PRACK */;
else if (sr->sr_respond == NULL) { /* Final response interrupted 100rel */
/* Ignore */
return 200;
}
else if (sip == NULL) {
SET_STATUS(504, "Reliable Response Timeout");
respond_to_invite(nh->nh_nua, nh, status, phrase, NULL);
......
......@@ -4159,6 +4159,284 @@ int test_refer(struct context *ctx)
/* ======================================================================== */
/* NUA-10 tests: early session, PRACK, UPDATE */
/*
X accept_100rel ep
|-------INVITE------>|
|<----100 Trying-----|
| |
|<-------183---------|
|-------PRACK------->|
|<-------200---------|
| |
|<-------180---------|
| |
|<------200 OK-------|
|--------ACK-------->|
| |
*/
int accept_100rel(CONDITION_PARAMS)
{
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
return 0;
save_event_in_list(ctx, event, ep, call);
switch (event) {
case nua_i_update:
if (200 <= status && status < 300) {
respond(ep, call, nh, SIP_180_RINGING, TAG_END());
respond(ep, call, nh, SIP_200_OK, TAG_END());
}
return 0;
default:
break;
}
switch (callstate(tags)) {
case nua_callstate_received:
respond(ep, call, nh, SIP_183_SESSION_PROGRESS,
SIPTAG_REQUIRE_STR("100rel"),
TAG_IF(call->sdp, SOATAG_USER_SDP_STR(call->sdp)),
TAG_END());
return 0;
case nua_callstate_early:
return 0;
case nua_callstate_ready:
return 1;
case nua_callstate_terminated:
if (call)
nua_handle_destroy(call->nh), call->nh = NULL;
return 1;
default:
return 0;
}
}
int test_100rel(struct context *ctx)
{
BEGIN();
struct endpoint *a = &ctx->a, *b = &ctx->b;
struct call *a_call = a->call, *b_call = b->call;
struct event *e;
if (print_headings)
printf("TEST NUA-10.1: Call with 100rel and preconditions\n");
/* Session timer test:
A B
|-------INVITE------>|
|<----100 Trying-----|
| |
|<-------183---------|
|-------PRACK------->|
|<-------200---------|
| |
|<-------180---------|
| |
|<------200 OK-------|
|--------ACK-------->|
| |
|<-------BYE---------|
|-------200 OK-------|
| |
*/
a_call->sdp = "m=audio 5008 RTP/AVP 8";
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
nua_set_params(ctx->a.nua,
NUTAG_EARLY_MEDIA(1),
SIPTAG_SUPPORTED_STR("100rel, precondition"),
TAG_END());
run_a_until(ctx, nua_r_set_params, until_final_response);
nua_set_params(ctx->b.nua,
NUTAG_EARLY_MEDIA(1),
SIPTAG_SUPPORTED_STR("100rel, precondition"),
TAG_END());
run_b_until(ctx, nua_r_set_params, until_final_response);
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
invite(a, a_call, a_call->nh,
TAG_IF(!ctx->p, NUTAG_URL(b->contact->m_url)),
SOATAG_USER_SDP_STR(a_call->sdp),
SIPTAG_SUPPORTED_STR("100rel"),
SIPTAG_REQUIRE_STR("precondition"),
TAG_END());
run_ab_until(ctx, -1, until_ready, -1, accept_100rel);
/* Client transitions:
INIT -(C1)-> CALLING: nua_invite(), nua_i_state
CALLING -(C2)-> PROCEEDING: nua_r_invite, nua_i_state
PROCEEDING -(C3+C4)-> READY: nua_r_invite, nua_i_state
*/
TEST_1(e = a_call->events.head); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_calling); /* CALLING */
TEST_1(is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
TEST(e->data->e_status, 183);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding);
TEST_1(is_answer_recv(e->data->e_tags));
TEST_1(is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_prack);
TEST(e->data->e_status, 200);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding);
TEST_1(is_answer_recv(e->data->e_tags));
TEST_1(!is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding);
TEST_1(!is_answer_recv(e->data->e_tags));
TEST_1(is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_update);
TEST(e->data->e_status, 200);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding);
TEST_1(is_answer_recv(e->data->e_tags));
TEST_1(!is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
TEST(e->data->e_status, 180);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding); /* PROCEEDING */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
TEST(e->data->e_status, 200);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(!is_answer_recv(e->data->e_tags));
TEST_1(!e->next);
free_events_in_list(ctx, a_call);
/*
Server transitions:
INIT -(S1)-> RECEIVED: nua_i_invite, nua_i_state
RECEIVED -(S2a)-> EARLY: nua_respond(), nua_i_state
EARLY -(S3b)-> COMPLETED: nua_respond(), nua_i_state
COMPLETED -(S4)-> READY: nua_i_ack, nua_i_state
*/
TEST_1(e = b_call->events.head); TEST_E(e->data->e_event, nua_i_invite);
TEST(e->data->e_status, 100);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_received); /* RECEIVED */
/* Responded with 183 Session Progress */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_early); /* EARLY */
TEST_1(is_answer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_prack);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_early); /* EARLY */
TEST_1(is_offer_recv(e->data->e_tags));
TEST_1(is_answer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_update);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_early); /* EARLY */
TEST_1(is_offer_recv(e->data->e_tags));
TEST_1(is_answer_sent(e->data->e_tags));
/* Responded with 180 Ringing */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_early); /* EARLY */
TEST_1(!is_answer_sent(e->data->e_tags));
/* Responded with 200 OK */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_completed); /* COMPLETED */
TEST_1(!is_answer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_ack);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(!e->next);
free_events_in_list(ctx, b_call);
if (print_headings)
printf("TEST NUA-10.1: PASSED\n");
#if 0
if (print_headings)
printf("TEST NUA-10.2: use UPDATE\n");
update(b, b_call, b_call->nh, TAG_END());
run_ab_until(ctx, -1, until_ready, -1, until_ready);
/* Events from B (who sent UPDATE) */
TEST_1(e = b_call->events.head); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(is_offer_sent(e->data->e_tags));
if (!e->next)
run_b_until(ctx, -1, until_ready);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_update);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_session_expires);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(is_answer_recv(e->data->e_tags));
TEST_1(!e->next);
free_events_in_list(ctx, b_call);
/* Events from A (who received UPDATE) */
TEST_1(e = a_call->events.head); TEST_E(e->data->e_event, nua_i_update);
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_session_expires);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(is_offer_recv(e->data->e_tags));
TEST_1(is_answer_sent(e->data->e_tags));
TEST_1(!e->next);
free_events_in_list(ctx, a_call);
#endif
bye(b, b_call, b_call->nh, TAG_END());
run_ab_until(ctx, -1, until_terminated, -1, until_terminated);
/* B transitions:
READY --(T2)--> TERMINATING: nua_bye()
TERMINATING --(T3)--> TERMINATED: nua_r_bye, nua_i_state
*/
TEST_1(e = b_call->events.head); TEST_E(e->data->e_event, nua_r_bye);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* TERMINATED */
TEST_1(!e->next);
free_events_in_list(ctx, b_call);
/* A: READY -(T1)-> TERMINATED: nua_i_bye, nua_i_state */
TEST_1(e = a_call->events.head); TEST_E(e->data->e_event, nua_i_bye);
TEST(e->data->e_status, 200);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* TERMINATED */
TEST_1(!e->next);
free_events_in_list(ctx, a_call);
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
if (print_headings)
printf("TEST NUA-10.2: PASSED\n");
END();
}
/* ======================================================================== */
/* Test simple methods: OPTIONS, MESSAGE, PUBLISH */
......@@ -5093,7 +5371,7 @@ int main(int argc, char *argv[])
retval |= test_call_hold(ctx); SINGLE_FAILURE_CHECK();
retval |= test_session_timer(ctx); SINGLE_FAILURE_CHECK();
retval |= test_refer(ctx); SINGLE_FAILURE_CHECK();
/* retval |= test_100rel(ctx); SINGLE_FAILURE_CHECK(); */
retval |= test_100rel(ctx); SINGLE_FAILURE_CHECK();
retval |= test_methods(ctx); SINGLE_FAILURE_CHECK();
retval |= test_events(ctx); SINGLE_FAILURE_CHECK();
}
......
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