Commit 92e1aa0a authored by Pekka Pessi's avatar Pekka Pessi

nua: initial fix for sf.net bug #1827511

BYE can now be challenged.

darcs-hash:20080226160937-65a35-fd58668dcea23da7f557a50f742942182e5edf35.gz
parent bd35fc87
......@@ -373,8 +373,12 @@ void nua_dialog_usage_remove_at(nua_owner_t *own,
/* Destroy saved client request */
if (nua_client_is_bound(du->du_cr)) {
nua_client_bind(cr = du->du_cr, NULL);
if (!nua_client_is_queued(cr) &&
!nua_client_is_reporting(cr))
if (nua_client_is_queued(cr))
nua_client_request_complete(cr);
else if (nua_client_is_reporting(cr))
;
else
nua_client_request_destroy(cr);
}
......
......@@ -177,6 +177,7 @@ int nua_stack_set_defaults(nua_handle_t *nh,
NHP_SET(nhp, refer_with_id, 1);
NHP_SET(nhp, substate, nua_substate_active);
NHP_SET(nhp, sub_expires, 3600);
NHP_SET(nhp, allow, sip_allow_make(home, nua_allow_str));
NHP_SET(nhp, supported, sip_supported_make(home, "timer, 100rel"));
......
......@@ -238,7 +238,8 @@ void nua_session_usage_remove(nua_handle_t *nh,
cr = du->du_cr;
if (cr && cr->cr_orq && cr->cr_status >= 200) {
if (cr && cr->cr_orq && cr->cr_status >= 200 &&
cr->cr_method == sip_method_invite) {
ss->ss_reporting = 1;
nua_invite_client_ack(cr, NULL);
ss->ss_reporting = 0;
......@@ -250,14 +251,17 @@ void nua_session_usage_remove(nua_handle_t *nh,
if (cr->cr_method != sip_method_invite)
continue;
if (cr == du->du_cr)
continue;
nua_stack_event(nh->nh_nua, nh,
NULL,
cr->cr_event,
SIP_481_NO_TRANSACTION,
NULL);
if (cr->cr_status < 200) {
nua_stack_event(nh->nh_nua, nh,
NULL,
cr->cr_event,
SIP_481_NO_TRANSACTION,
NULL);
}
nua_client_request_destroy(cr);
......@@ -604,10 +608,15 @@ static int nua_invite_client_init(nua_client_request_t *cr,
if (!du)
return -1;
ss = nua_dialog_usage_private(du);
if (ss->ss_state >= nua_callstate_terminating)
return nua_client_return(cr, 900, "Session is terminating", msg);
if (nua_client_bind(cr, du) < 0)
return nua_client_return(cr, 900, "INVITE already in progress", msg);
ss = nua_dialog_usage_private(du);
cr->cr_neutral = 0;
session_timer_preferences(ss->ss_timer,
sip,
......@@ -617,8 +626,6 @@ static int nua_invite_client_init(nua_client_request_t *cr,
NH_PGET(nh, refresher),
NH_PGET(nh, min_se));
cr->cr_neutral = 0;
return 0;
}
......@@ -635,6 +642,9 @@ static int nua_invite_client_request(nua_client_request_t *cr,
if (du == NULL) /* Call terminated */
return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
if (ss->ss_state >= nua_callstate_terminating)
return nua_client_return(cr, 900, "Session is terminating", msg);
assert(ss);
invite_timeout = NH_PGET(nh, invite_timeout);
......@@ -1047,7 +1057,7 @@ int nua_stack_ack(nua_t *nua, nua_handle_t *nh, nua_event_t e,
if (error < 0) {
if (ss->ss_reason == NULL)
ss->ss_reason = "SIP;cause=500;text=\"Internal Error\"";
ss->ss_reporting = 1; /* We report state here if BYE fails */
ss->ss_reporting = 1; /* We report terminated state here if BYE fails */
error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
ss->ss_reporting = 0;
signal_call_state_change(nh, ss, 500, "Internal Error",
......@@ -1090,6 +1100,7 @@ int nua_invite_client_ack(nua_client_request_t *cr, tagi_t const *tags)
char const *invite_branch;
assert(cr->cr_orq);
assert(cr->cr_method == sip_method_invite);
if (!ds->ds_leg) {
/* XXX - fix nua_dialog_usage_remove_at() instead! */
......@@ -1545,6 +1556,8 @@ static int nua_prack_client_request(nua_client_request_t *cr,
if (du == NULL) /* Call terminated */
return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
assert(ss);
if (ss->ss_state >= nua_callstate_terminating)
return nua_client_return(cr, 900, "Session is terminating", msg);
cri = du->du_cr;
......@@ -2322,7 +2335,7 @@ int process_ack(nua_server_request_t *sr,
nua_stack_event(nh->nh_nua, nh, NULL,
nua_i_media_error, status, phrase, NULL);
ss->ss_reporting = 1; /* We report state here if BYE fails */
ss->ss_reporting = 1; /* We report terminated state here if BYE fails */
error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
ss->ss_reporting = 0;
......@@ -2419,7 +2432,7 @@ int process_timeout(nua_server_request_t *sr,
/* send BYE, too, if 200 OK (or 183 to re-INVITE) timeouts */
ss->ss_reason = reason;
ss->ss_reporting = 1; /* We report state here if BYE fails */
ss->ss_reporting = 1; /* We report terminated state here if BYE fails */
error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
ss->ss_reporting = 0;
......@@ -2989,6 +3002,8 @@ static int nua_update_client_request(nua_client_request_t *cr,
if (du == NULL) /* Call terminated */
return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
assert(ss);
if (ss->ss_state >= nua_callstate_terminating)
return nua_client_return(cr, 900, "Session is terminating", msg);
cri = du->du_cr;
......@@ -3451,7 +3466,9 @@ static int nua_bye_client_init(nua_client_request_t *cr,
if (nh->nh_soa)
soa_terminate(nh->nh_soa, 0);
cr->cr_usage = du;
du->du_cr = NULL;
nua_client_bind(cr, du);
return 0;
}
......@@ -3523,17 +3540,23 @@ static int nua_bye_client_report(nua_client_request_t *cr,
else {
nua_session_usage_t *ss = nua_dialog_usage_private(du);
if (ss->ss_reporting) {
return 1; /* Somebody else's problem */
}
else if (cr->cr_waiting) {
return 1; /* Application problem */
}
signal_call_state_change(nh, ss, status, "to BYE",
nua_callstate_terminated);
if (ss && !ss->ss_reporting) {
if (du->du_cr == NULL ||
!nua_client_is_queued(du->du_cr) ||
du->du_cr->cr_status >= 200) {
/* INVITE is completed, we can zap the session... */;
cr->cr_usage = NULL;
nua_session_usage_destroy(nh, ss);
}
if (du &&
(du->du_cr == NULL ||
!nua_client_is_queued(du->du_cr) ||
du->du_cr->cr_status >= 200)) {
/* INVITE is completed, we can zap the session... */;
cr->cr_usage = NULL;
nua_session_usage_destroy(nh, ss);
}
}
......
......@@ -2078,6 +2078,7 @@ nua_client_request_t *nua_client_request_remove(nua_client_request_t *cr)
void nua_client_request_complete(nua_client_request_t *cr)
{
nua_client_request_remove(cr);
if (cr && cr->cr_methods->crm_complete)
cr->cr_methods->crm_complete(cr);
}
......@@ -2095,7 +2096,6 @@ void nua_client_request_destroy(nua_client_request_t *cr)
nua_destroy_signal(cr->cr_signal);
nua_client_request_remove(cr);
nua_client_bind(cr, NULL);
if (cr->cr_msg)
......@@ -2104,7 +2104,6 @@ void nua_client_request_destroy(nua_client_request_t *cr)
if (cr->cr_orq)
nta_outgoing_destroy(cr->cr_orq);
cr->cr_orq = NULL;
if (cr->cr_timer)
......
......@@ -726,9 +726,8 @@ int test_183rel(struct context *ctx)
if (e->data->e_event == nua_r_bye) {
TEST_E(e->data->e_event, nua_r_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);
bye = 0;
break;
}
else if (e->data->e_event == nua_r_invite) {
TEST_E(e->data->e_event, nua_r_invite);
......@@ -741,7 +740,10 @@ int test_183rel(struct context *ctx)
cancel = 0;
}
}
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_terminated);
}
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
......
......@@ -1133,7 +1133,7 @@ int test_bye_before_ack(struct context *ctx)
Server transitions:
INIT -(S1)-> RECEIVED: nua_i_invite, nua_i_state
RECEIVED -(S2a)-> EARLY: nua_respond(180), nua_i_state
EARLY -(S6b)--> TERMINATED: nua_i_cancel, nua_i_state
EARLY -(S6b)--> TERMINATED: nua_i_bye, nua_i_state
*/
TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_invite);
TEST(e->data->e_status, 100);
......@@ -1423,6 +1423,79 @@ int reject_reinvite_401(CONDITION_PARAMS)
return 0;
}
int test_bye_with_407(struct context *ctx)
{
BEGIN();
struct endpoint *a = &ctx->a, *c = &ctx->c;
struct call *a_call = a->call, *c_call = c->call;
struct event *e;
a_call->sdp = "m=audio 5008 RTP/AVP 8";
c_call->sdp = "m=audio 5010 RTP/AVP 0 8";
/* BYE after receiving 401
A C
|-------INVITE------>|
|<----100 Trying-----|
| |
|<----180 Ringing----|
|<-------200---------|
|--------ACK-------->|
| |
| |<----BYE----|
| |-----407--->|
|<-------BYE---------|
|--------200-------->|
| |
*/
if (print_headings)
printf("TEST NUA-6.4.5: BYE with 407\n");
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(c->to), TAG_END()));
INVITE(a, a_call, a_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(c->contact->m_url)),
SIPTAG_SUBJECT_STR("NUA-6.4.2"),
SOATAG_USER_SDP_STR(a_call->sdp),
NUTAG_AUTOANSWER(0),
NUTAG_APPL_METHOD("UPDATE"),
TAG_END());
run_abc_until(ctx, -1, until_ready, -1, NULL, -1, accept_call);
free_events_in_list(ctx, a->events);
TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_i_invite);
free_events_in_list(ctx, c->events);
BYE(c, c_call, c_call->nh,
TAG_END());
run_c_until(ctx, -1, save_until_final_response);
TEST_1(nua_handle_has_active_call(a_call->nh));
TEST_1(nua_handle_has_active_call(c_call->nh));
free_events_in_list(ctx, a->events);
free_events_in_list(ctx, c->events);
AUTHENTICATE(c, c_call, c_call->nh,
NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"), TAG_END());
run_abc_until(ctx, -1, until_terminated, -1, NULL, -1, until_terminated);
free_events_in_list(ctx, a->events);
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
free_events_in_list(ctx, c->events);
nua_handle_destroy(c_call->nh), c_call->nh = NULL;
if (print_headings)
printf("TEST NUA-6.4.5: PASSED\n");
END();
}
int test_bye_to_invalid_contact(struct context *ctx)
{
BEGIN();
......@@ -1576,6 +1649,7 @@ int test_bye_to_invalid_contact(struct context *ctx)
int test_early_bye(struct context *ctx)
{
return
test_bye_with_407(ctx) ||
test_bye_before_200(ctx) ||
test_bye_before_ack(ctx) ||
test_bye_after_receiving_401(ctx) ||
......
......@@ -151,8 +151,11 @@ int test_nua_init(struct context *ctx,
AUTHTAG_ALGORITHM("md5"),
AUTHTAG_NEXT_EXPIRES(60),
AUTHTAG_MAX_NCOUNT(1),
AUTHTAG_ALLOW("ACK, CANCEL"),
TAG_END());
test_proxy_domain_set_record_route(ctx->c.domain, 1);
ctx->proxy_tests = 1;
}
......
......@@ -135,6 +135,7 @@ struct domain {
sip_time_t min_expires, expires, max_expires;
int outbound_tcp; /**< Use inbound TCP connection as outbound */
char const *authorize; /**< Authorization realm to use */
int record_route;
} prefs;
tagi_t *tags;
......@@ -478,6 +479,23 @@ void test_proxy_domain_get_outbound(struct domain *d,
}
}
void test_proxy_domain_set_record_route(struct domain *d,
int use_record_route)
{
if (d) {
d->prefs.record_route = use_record_route;
}
}
void test_proxy_domain_get_record_route(struct domain *d,
int *return_use_record_route)
{
if (d) {
if (return_use_record_route)
*return_use_record_route = d->prefs.record_route;
}
}
int test_proxy_domain_set_authorize(struct domain *d,
char const *realm)
{
......@@ -743,6 +761,9 @@ static int proxy_tr_with(struct proxy *proxy,
if (t->method != sip_method_ack && t->method != sip_method_cancel)
nta_incoming_bind(irq, proxy_ack_cancel, t);
if (domain && domain->prefs.record_route)
t->rr = 1;
if (process(t) < 200)
return 0;
......@@ -818,6 +839,9 @@ static int originating_transaction(struct proxy_tr *t)
t->use_auth = 407;
}
if (o && o->prefs.record_route)
t->rr = 1;
return 0;
}
......@@ -841,7 +865,6 @@ static int validate_transaction(struct proxy_tr *t)
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;
}
if (t->use_auth)
......@@ -947,12 +970,17 @@ static int target_transaction(struct proxy_tr *t,
msg_header_insert(c->msg, (msg_pub_t *)c->sip, (msg_header_t *)c->rq);
if (t->rr && 0) {
if (t->rr) {
sip_record_route_t rr[1];
*sip_record_route_init(rr)->r_url = *t->proxy->rr_uri;
msg_header_add_dup(c->msg, (msg_pub_t *)c->sip, (msg_header_t *)rr);
if (t->proxy->rr_uri) {
*sip_record_route_init(rr)->r_url = *t->proxy->rr_uri;
msg_header_add_dup(c->msg, (msg_pub_t *)c->sip, (msg_header_t *)rr);
}
else if (t->proxy->lr) {
*sip_record_route_init(rr)->r_url = *t->proxy->lr->r_url;
msg_header_add_dup(c->msg, (msg_pub_t *)c->sip, (msg_header_t *)rr);
}
}
if (c->rq)
......
......@@ -73,6 +73,11 @@ void test_proxy_domain_set_outbound(struct domain *d,
void test_proxy_domain_get_outbound(struct domain *d,
int *return_use_outbound);
void test_proxy_domain_set_record_route(struct domain *d,
int use_record_route);
void test_proxy_domain_get_record_route(struct domain *d,
int *return_use_record_route);
int test_proxy_close_tports(struct proxy *p);
SOFIA_END_DECLS
......
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