Commit 9184ed47 authored by Pekka Pessi's avatar Pekka Pessi

nta.c: returning 500 Internal Server Error response if unreplied incoming request is destroyed

darcs-hash:20061220093530-65a35-a6b386c2a3783805571569e11593073ff92474d0.gz
parent a942bae2
......@@ -3766,9 +3766,13 @@ void leg_recv(nta_leg_t *leg, msg_t *msg, sip_t *sip, tport_t *tport)
status = incoming_callback(leg, irq, sip);
irq->irq_in_callback = 0;
if (irq->irq_destroyed && irq->irq_terminated) {
incoming_free(irq);
return;
if (irq->irq_destroyed) {
if (irq->irq_terminated) {
incoming_free(irq);
return;
}
if (status < 200)
status = 500;
}
if (status == 0)
......@@ -4453,9 +4457,12 @@ void nta_incoming_destroy(nta_incoming_t *irq)
irq->irq_callback = NULL;
irq->irq_magic = NULL;
irq->irq_destroyed = 1;
if (!irq->irq_in_callback)
if (!irq->irq_in_callback) {
if (irq->irq_terminated || irq->irq_default)
incoming_free(irq);
else if (irq->irq_status < 200)
nta_incoming_treply(irq, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
}
}
}
......
......@@ -1328,6 +1328,105 @@ int test_tports(agent_t *ag)
END();
}
int leg_callback_destroy(agent_t *ag,
nta_leg_t *leg,
nta_incoming_t *irq,
sip_t const *sip)
{
if (tstflags & tst_verbatim) {
printf("%s: %s: %s " URL_PRINT_FORMAT " %s\n",
name, __func__, sip->sip_request->rq_method_name,
URL_PRINT_ARGS(sip->sip_request->rq_url),
sip->sip_request->rq_version);
}
ag->ag_latest_leg = leg;
nta_incoming_destroy(irq);
return 0;
}
int leg_callback_save(agent_t *ag,
nta_leg_t *leg,
nta_incoming_t *irq,
sip_t const *sip)
{
if (tstflags & tst_verbatim) {
printf("%s: %s: %s " URL_PRINT_FORMAT " %s\n",
name, __func__, sip->sip_request->rq_method_name,
URL_PRINT_ARGS(sip->sip_request->rq_url),
sip->sip_request->rq_version);
}
ag->ag_latest_leg = leg;
ag->ag_irq = irq;
ag->ag_status = 1000;
return 0;
}
int test_destroy_incoming(agent_t *ag)
{
BEGIN();
url_t url[1];
*url = *ag->ag_contact->m_url;
/* Test 3.1
* Check that when a incoming request is destroyed in callback,
* a 500 response is sent
*/
ag->ag_expect_leg = ag->ag_default_leg;
nta_leg_bind(ag->ag_default_leg, leg_callback_destroy, ag);
TEST_1(ag->ag_orq =
nta_outgoing_tcreate(ag->ag_default_leg,
outgoing_callback, ag,
ag->ag_obp,
SIP_METHOD_MESSAGE,
(url_string_t *)url,
SIPTAG_SUBJECT_STR("Test 3.1"),
SIPTAG_FROM(ag->ag_alice),
SIPTAG_TO(ag->ag_bob),
TAG_END()));
nta_test_run(ag);
TEST(ag->ag_status, 500);
TEST_P(ag->ag_orq, NULL);
TEST_P(ag->ag_latest_leg, ag->ag_default_leg);
/* Test 3.1
* Check that when a incoming request is destroyed, a 500 response is sent
*/
nta_leg_bind(ag->ag_default_leg, leg_callback_save, ag);
TEST_1(ag->ag_orq =
nta_outgoing_tcreate(ag->ag_default_leg,
outgoing_callback, ag,
ag->ag_obp,
SIP_METHOD_MESSAGE,
(url_string_t *)url,
SIPTAG_SUBJECT_STR("Test 3.1"),
SIPTAG_FROM(ag->ag_alice),
SIPTAG_TO(ag->ag_bob),
TAG_END()));
nta_test_run(ag);
TEST(ag->ag_status, 1000);
TEST_1(ag->ag_irq);
TEST_1(ag->ag_orq);
TEST_P(ag->ag_latest_leg, ag->ag_default_leg);
nta_incoming_destroy(ag->ag_irq), ag->ag_irq = NULL;
nta_test_run(ag);
TEST(ag->ag_status, 500);
TEST_P(ag->ag_orq, NULL);
END();
}
int test_resolv(agent_t *ag, char const *resolv_conf)
{
int udp = 0, tcp = 0, sctp = 0, tls = 0;
......@@ -1340,6 +1439,8 @@ int test_resolv(agent_t *ag, char const *resolv_conf)
BEGIN();
nta_leg_bind(ag->ag_default_leg, leg_callback_200, ag);
nta_agent_set_params(ag->ag_agent,
NTATAG_SIP_T1(8 * 25),
NTATAG_SIP_T1X64(64 * 25),
......@@ -2064,6 +2165,8 @@ int test_routing(agent_t *ag)
*url = *ag->ag_aliases->m_url;
url->url_user = "bob";
nta_leg_bind(ag->ag_default_leg, leg_callback_200, ag);
nta_agent_set_params(ag->ag_agent,
NTATAG_MAXSIZE(2 * 1024 * 1024),
TAG_END());
......@@ -3364,6 +3467,7 @@ int main(int argc, char *argv[])
retval |= test_bad_messages(ag); SINGLE_FAILURE_CHECK();
retval |= test_reinit(ag); SINGLE_FAILURE_CHECK();
retval |= test_tports(ag); SINGLE_FAILURE_CHECK();
retval |= test_destroy_incoming(ag); SINGLE_FAILURE_CHECK();
retval |= test_resolv(ag, argv[i]); SINGLE_FAILURE_CHECK();
retval |= test_routing(ag); SINGLE_FAILURE_CHECK();
retval |= test_dialog(ag); 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