mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-16 14:28:34 +00:00
complete r8400 commit
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8406 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
deba14a301
commit
dd9f6af78d
29 files changed
+4203
No files matched your search
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2007 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE check2_sofia.c
|
||||
*
|
||||
* @brief Check-driven tester for Sofia SIP User Agent library
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @copyright (C) 2007 Nokia Corporation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "check_nua.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if HAVE_FNMATCH_H
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
static char const * const default_patterns[] = { "*", NULL };
|
||||
static char const * const *test_patterns = default_patterns;
|
||||
|
||||
void check_nua_tcase_add_test(TCase *tc, TFun tf, char const *name)
|
||||
{
|
||||
char const * const *patterns;
|
||||
|
||||
#if HAVE_FNMATCH_H
|
||||
for (patterns = test_patterns; *patterns; patterns++) {
|
||||
if (!fnmatch(*patterns, name, 0)) {
|
||||
if (strcmp(*patterns, "*")) {
|
||||
printf("%s: match with %s\n", name, *patterns);
|
||||
}
|
||||
_tcase_add_test(tc, tf, name, 0, 0, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (patterns = test_patterns; *patterns; patterns++) {
|
||||
if (!strcmp(*patterns, name) || !strcmp(*patterns, "*")) {
|
||||
if (strcmp(*patterns, "*")) {
|
||||
printf("%s: match with %s\n", name, *patterns);
|
||||
}
|
||||
_tcase_add_test(tc, tf, name, 0, 0, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
printf("%s: no match\n", name);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int failed = 0;
|
||||
|
||||
Suite *suite = suite_create("Unit tests for Sofia-SIP UA Engine");
|
||||
SRunner *runner;
|
||||
|
||||
if (getenv("CHECK_NUA_CASES")) {
|
||||
size_t i;
|
||||
char *s, **patterns;
|
||||
char *cases = strdup(getenv("CHECK_NUA_CASES"));
|
||||
|
||||
/* Count commas */
|
||||
for (i = 2, s = cases; (s = strchr(s, ',')); s++, i++);
|
||||
|
||||
patterns = calloc(i, sizeof *patterns);
|
||||
|
||||
for (i = 0, s = cases;; i++) {
|
||||
patterns[i] = s;
|
||||
if (s == NULL)
|
||||
break;
|
||||
s = strchr(s, ',');
|
||||
if (s)
|
||||
*s++ = '\0';
|
||||
}
|
||||
|
||||
test_patterns = (char const * const *)patterns;
|
||||
}
|
||||
|
||||
check_register_cases(suite);
|
||||
check_session_cases(suite);
|
||||
|
||||
runner = srunner_create(suite);
|
||||
|
||||
if (argv[1]) {
|
||||
srunner_set_xml(runner, argv[1]);
|
||||
}
|
||||
srunner_run_all(runner, CK_ENV);
|
||||
|
||||
failed = srunner_ntests_failed(runner);
|
||||
srunner_free(runner);
|
||||
|
||||
exit(failed ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef CHECK_NUA_H
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#undef tcase_add_test
|
||||
#define tcase_add_test(tc, tf) \
|
||||
check_nua_tcase_add_test(tc, tf, "" #tf "")
|
||||
|
||||
void check_nua_tcase_add_test(TCase *, TFun, char const *name);
|
||||
|
||||
void check_session_cases(Suite *suite);
|
||||
void check_register_cases(Suite *suite);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,741 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2008 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE check_register.c
|
||||
*
|
||||
* @brief Check-driven tester for Sofia SIP User Agent library
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @copyright (C) 2008 Nokia Corporation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "check_nua.h"
|
||||
|
||||
#include "test_s2.h"
|
||||
|
||||
#include <sofia-sip/sip_status.h>
|
||||
#include <sofia-sip/sip_header.h>
|
||||
#include <sofia-sip/soa.h>
|
||||
#include <sofia-sip/su_tagarg.h>
|
||||
#include <sofia-sip/su_tag_io.h>
|
||||
#include <sofia-sip/su_log.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
SOFIAPUBVAR su_log_t tport_log[];
|
||||
|
||||
static nua_t *nua;
|
||||
|
||||
static void register_setup(void)
|
||||
{
|
||||
nua = s2_nua_setup(TAG_END());
|
||||
}
|
||||
|
||||
static void register_pingpong_setup(void)
|
||||
{
|
||||
nua = s2_nua_setup(TPTAG_PINGPONG(20000),
|
||||
TPTAG_KEEPALIVE(10000),
|
||||
TAG_END());
|
||||
tport_set_params(s2->tcp.tport, TPTAG_PONG2PING(1), TAG_END());
|
||||
}
|
||||
|
||||
|
||||
static void register_teardown(void)
|
||||
{
|
||||
nua_shutdown(nua);
|
||||
fail_unless(s2_check_event(nua_r_shutdown, 200));
|
||||
s2_nua_teardown();
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
START_TEST(register_1_0_1)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.0.1", "Failed Register", "REGISTER returned 403 response");
|
||||
|
||||
nua_register(nh, TAG_END());
|
||||
|
||||
fail_unless((m = s2_wait_for_request(SIP_METHOD_REGISTER)) != NULL, NULL);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_403_FORBIDDEN,
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
nua_handle_destroy(nh);
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_1_1)
|
||||
{
|
||||
s2_case("1.1.1", "Basic Register", "REGISTER returning 200 OK");
|
||||
|
||||
s2_register_setup();
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_1_2)
|
||||
{
|
||||
nua_handle_t *nh;
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.1.2", "Register with dual authentication",
|
||||
"Register, authenticate");
|
||||
|
||||
nh = nua_handle(nua, NULL, TAG_END());
|
||||
|
||||
nua_register(nh, TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_407_PROXY_AUTH_REQUIRED,
|
||||
SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
s2_check_event(nua_r_register, 407);
|
||||
|
||||
nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_401_UNAUTHORIZED,
|
||||
SIPTAG_WWW_AUTHENTICATE_STR(s2_auth2_digest_str),
|
||||
SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
s2_check_event(nua_r_register, 401);
|
||||
|
||||
nua_authenticate(nh, NUTAG_AUTH(s2_auth2_credentials), TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_authorization);
|
||||
fail_if(!m->sip->sip_proxy_authorization);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
assert(s2->registration->contact != NULL);
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
s2->registration->nh = nh;
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
static char const *receive_natted = "received=4.255.255.9";
|
||||
|
||||
/* Return Via that looks very natted */
|
||||
static sip_via_t *natted_via(struct message *m)
|
||||
{
|
||||
su_home_t *h;
|
||||
sip_via_t *via;
|
||||
|
||||
h = msg_home(m->msg);
|
||||
via = sip_via_dup(h, m->sip->sip_via);
|
||||
msg_header_replace_param(h, via->v_common, receive_natted);
|
||||
|
||||
if (via->v_protocol == sip_transport_udp)
|
||||
msg_header_replace_param(h, via->v_common, "rport=9");
|
||||
|
||||
if (via->v_protocol == sip_transport_tcp && via->v_rport) {
|
||||
tp_name_t const *tpn = tport_name(m->tport);
|
||||
char *rport = su_sprintf(h, "rport=%s", tpn->tpn_port);
|
||||
msg_header_replace_param(h, via->v_common, rport);
|
||||
}
|
||||
|
||||
return via;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
START_TEST(register_1_2_1) {
|
||||
nua_handle_t *nh;
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.2.1", "Register behind NAT",
|
||||
"Register through NAT, detect NAT, re-REGISTER");
|
||||
|
||||
nh = nua_handle(nua, NULL, TAG_END());
|
||||
|
||||
nua_register(nh, TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
assert(s2->registration->contact != NULL);
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
s2->registration->nh = nh;
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
static nua_handle_t *make_auth_natted_register(
|
||||
nua_handle_t *nh,
|
||||
tag_type_t tag, tag_value_t value, ...)
|
||||
{
|
||||
struct message *m;
|
||||
|
||||
ta_list ta;
|
||||
ta_start(ta, tag, value);
|
||||
nua_register(nh, ta_tags(ta));
|
||||
ta_end(ta);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_401_UNAUTHORIZED,
|
||||
SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 401);
|
||||
|
||||
nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_authorization);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
assert(s2->registration->contact != NULL);
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
return nh;
|
||||
}
|
||||
|
||||
START_TEST(register_1_2_2_1)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
|
||||
s2_case("1.2.2.1", "Register behind NAT",
|
||||
"Authenticate, outbound activated");
|
||||
|
||||
mark_point();
|
||||
make_auth_natted_register(nh, TAG_END());
|
||||
s2->registration->nh = nh;
|
||||
s2_register_teardown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(register_1_2_2_2)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.2.2.2", "Register behind NAT",
|
||||
"Authenticate, outbound activated, "
|
||||
"authenticate OPTIONS probe, "
|
||||
"NAT binding change");
|
||||
|
||||
mark_point();
|
||||
make_auth_natted_register(nh, TAG_END());
|
||||
s2->registration->nh = nh;
|
||||
|
||||
mark_point();
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_OPTIONS);
|
||||
fail_if(!m);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_407_PROXY_AUTH_REQUIRED,
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
mark_point();
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_OPTIONS);
|
||||
fail_if(!m); fail_if(!m->sip->sip_proxy_authorization);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
su_root_step(s2->root, 20); su_root_step(s2->root, 20);
|
||||
s2_fast_forward(120); /* Default keepalive interval */
|
||||
mark_point();
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_OPTIONS);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
su_root_step(s2->root, 20); su_root_step(s2->root, 20);
|
||||
s2_fast_forward(120); /* Default keepalive interval */
|
||||
mark_point();
|
||||
|
||||
receive_natted = "received=4.255.255.10";
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_OPTIONS);
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_i_outbound, 0);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_2_2_3)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.2.2.3", "Register behind NAT",
|
||||
"Authenticate, outbound activated, "
|
||||
"detect NAT binding change when re-REGISTERing");
|
||||
|
||||
mark_point();
|
||||
|
||||
make_auth_natted_register(nh,
|
||||
NUTAG_OUTBOUND("no-options-keepalive"),
|
||||
TAG_END());
|
||||
s2->registration->nh = nh;
|
||||
|
||||
receive_natted = "received=4.255.255.10";
|
||||
|
||||
s2_fast_forward(3600);
|
||||
mark_point();
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_2_3) {
|
||||
nua_handle_t *nh;
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.2.3", "Register behind NAT",
|
||||
"Outbound activated by error response");
|
||||
|
||||
nh = nua_handle(nua, NULL, TAG_END());
|
||||
nua_register(nh, TAG_END());
|
||||
|
||||
mark_point();
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
400, "Bad Contact",
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
s2->registration->nh = nh;
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
START_TEST(register_1_3_1)
|
||||
{
|
||||
nua_handle_t *nh;
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.3.1", "Register over TCP via NAT",
|
||||
"REGISTER via TCP, detect NTA, re-REGISTER");
|
||||
|
||||
nh = nua_handle(nua, NULL, TAG_END());
|
||||
|
||||
nua_register(nh, NUTAG_PROXY(s2->tcp.contact->m_url), TAG_END());
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next);
|
||||
fail_if(!tport_is_tcp(m->tport));
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
assert(s2->registration->contact != NULL);
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
fail_unless(
|
||||
url_has_param(s2->registration->contact->m_url, "transport=tcp"));
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
s2->registration->nh = nh;
|
||||
|
||||
s2_register_teardown();
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_3_2_1)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
|
||||
s2_case("1.3.2.1", "Register behind NAT",
|
||||
"Authenticate, outbound activated");
|
||||
|
||||
mark_point();
|
||||
s2->registration->nh = nh;
|
||||
make_auth_natted_register(nh, NUTAG_PROXY(s2->tcp.contact->m_url), TAG_END());
|
||||
fail_if(!tport_is_tcp(s2->registration->tport));
|
||||
s2_register_teardown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST(register_1_3_2_2)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
struct message *m;
|
||||
|
||||
s2_case("1.3.2.2", "Register behind NAT with TCP",
|
||||
"Detect NAT over TCP using rport. "
|
||||
"Authenticate, detect NAT, "
|
||||
"close TCP at server, wait for re-REGISTERs.");
|
||||
|
||||
nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
|
||||
s2_check_event(nua_r_set_params, 200);
|
||||
|
||||
mark_point();
|
||||
s2->registration->nh = nh;
|
||||
make_auth_natted_register(
|
||||
nh, NUTAG_PROXY(s2->tcp.contact->m_url),
|
||||
NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
|
||||
TAG_END());
|
||||
fail_if(!tport_is_tcp(s2->registration->tport));
|
||||
tport_shutdown(s2->registration->tport, 2);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
/* The "NAT binding" changed when new TCP connection is established */
|
||||
/* => NUA re-REGISTERs with newly detected contact */
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
|
||||
s2_register_teardown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(register_1_3_3_1)
|
||||
{
|
||||
nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
|
||||
struct message *m;
|
||||
tport_t *tcp;
|
||||
|
||||
s2_case("1.3.3.1", "Register behind NAT with UDP and TCP",
|
||||
"Register with UDP, UDP time-outing, then w/ TCP using rport. ");
|
||||
|
||||
nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
|
||||
s2_check_event(nua_r_set_params, 200);
|
||||
|
||||
mark_point();
|
||||
s2->registration->nh = nh;
|
||||
|
||||
nua_register(nh,
|
||||
NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
|
||||
TAG_END());
|
||||
|
||||
/* NTA tries with UDP, we drop them */
|
||||
for (;;) {
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);
|
||||
if (!tport_is_udp(m->tport)) /* Drop UDP */
|
||||
break;
|
||||
s2_free_message(m);
|
||||
s2_fast_forward(4);
|
||||
}
|
||||
|
||||
tcp = tport_ref(m->tport);
|
||||
|
||||
/* Respond to request over TCP */
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_401_UNAUTHORIZED,
|
||||
SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
s2_check_event(nua_r_register, 401);
|
||||
nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());
|
||||
|
||||
/* Turn off pong */
|
||||
tport_set_params(tcp, TPTAG_PONG2PING(0), TAG_END());
|
||||
|
||||
/* Now request over UDP ... registering TCP contact! */
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
s2_save_register(m);
|
||||
fail_unless(
|
||||
url_has_param(s2->registration->contact->m_url, "transport=tcp"));
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
/* NUA detects oops... re-registers UDP */
|
||||
s2_check_event(nua_r_register, 100);
|
||||
|
||||
m = s2_wait_for_request(SIP_METHOD_REGISTER);
|
||||
fail_if(!m); fail_if(!m->sip->sip_authorization);
|
||||
fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
|
||||
s2_save_register(m);
|
||||
|
||||
s2_respond_to(m, NULL,
|
||||
SIP_200_OK,
|
||||
SIPTAG_CONTACT(s2->registration->contact),
|
||||
SIPTAG_VIA(natted_via(m)),
|
||||
TAG_END());
|
||||
s2_free_message(m);
|
||||
|
||||
s2_check_event(nua_r_register, 200);
|
||||
|
||||
fail_unless(s2->registration->contact != NULL);
|
||||
fail_if(s2->registration->contact->m_next != NULL);
|
||||
|
||||
/* Wait until ping-pong failure closes the TCP connection */
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
su_root_step(s2->root, 5);
|
||||
su_root_step(s2->root, 5);
|
||||
su_root_step(s2->root, 5);
|
||||
s2_fast_forward(5);
|
||||
}
|
||||
}
|
||||
|
||||
s2_register_teardown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
TCase *register_tcase(void)
|
||||
{
|
||||
TCase *tc = tcase_create("1 - REGISTER");
|
||||
/* Each testcase is run in different process */
|
||||
tcase_add_checked_fixture(tc, register_setup, register_teardown);
|
||||
{
|
||||
tcase_add_test(tc, register_1_0_1);
|
||||
tcase_add_test(tc, register_1_1_1);
|
||||
tcase_add_test(tc, register_1_1_2);
|
||||
tcase_add_test(tc, register_1_2_1);
|
||||
tcase_add_test(tc, register_1_2_2_1);
|
||||
tcase_add_test(tc, register_1_2_2_2);
|
||||
tcase_add_test(tc, register_1_2_2_3);
|
||||
tcase_add_test(tc, register_1_2_3);
|
||||
tcase_add_test(tc, register_1_3_1);
|
||||
tcase_add_test(tc, register_1_3_2_1);
|
||||
tcase_add_test(tc, register_1_3_2_2);
|
||||
}
|
||||
tcase_set_timeout(tc, 5);
|
||||
return tc;
|
||||
}
|
||||
|
||||
TCase *pingpong_tcase(void)
|
||||
{
|
||||
TCase *tc = tcase_create("1 - REGISTER with PingPong");
|
||||
/* Each testcase is run in different process */
|
||||
tcase_add_checked_fixture(tc, register_pingpong_setup, register_teardown);
|
||||
{
|
||||
tcase_add_test(tc, register_1_3_3_1);
|
||||
}
|
||||
tcase_set_timeout(tc, 5);
|
||||
return tc;
|
||||
}
|
||||
|
||||
void check_register_cases(Suite *suite)
|
||||
{
|
||||
suite_add_tcase(suite, register_tcase());
|
||||
suite_add_tcase(suite, pingpong_tcase());
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_extension.c
|
||||
* @brief NUA-12: Test extension methods.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @date Created: Mon Nov 13 15:37:05 EET 2006
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_extension"
|
||||
#endif
|
||||
|
||||
|
||||
int respond_to_extension(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);
|
||||
|
||||
switch (event) {
|
||||
case nua_i_method:
|
||||
RESPOND(ep, call, nh, SIP_200_OK,
|
||||
NUTAG_WITH(with),
|
||||
SIPTAG_SUBJECT_STR("extended"),
|
||||
TAG_END());
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int test_extension(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;
|
||||
sip_t const *sip;
|
||||
|
||||
|
||||
/* Test for EXTENSION
|
||||
|
||||
A B
|
||||
|------EXTENSION---->|
|
||||
|<--------501--------| (method not recognized)
|
||||
| |
|
||||
|------EXTENSION---->|
|
||||
|<-------200---------| (method allowed, responded)
|
||||
| |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-13.1: EXTENSION\n");
|
||||
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
|
||||
|
||||
/* Test first without NUTAG_METHOD() */
|
||||
METHOD(a, a_call, a_call->nh,
|
||||
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_final_response, -1, NULL);
|
||||
|
||||
/* Client events:
|
||||
nua_method(), nua_r_method
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
|
||||
TEST(e->data->e_status, 900); /* Internal error */
|
||||
TEST_1(!e->data->e_msg);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
|
||||
|
||||
METHOD(a, a_call, a_call->nh,
|
||||
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
NUTAG_METHOD("EXTENSION"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_final_response, -1, NULL);
|
||||
|
||||
/* Client events:
|
||||
nua_method(), nua_r_method
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
|
||||
TEST(e->data->e_status, 501);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
nua_set_params(b->nua, NUTAG_ALLOW("EXTENSION"), 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()));
|
||||
|
||||
METHOD(a, a_call, a_call->nh,
|
||||
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
NUTAG_METHOD("EXTENSION"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_final_response, -1, respond_to_extension);
|
||||
|
||||
/* Client events:
|
||||
nua_method(), nua_r_method
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(!e->next);
|
||||
|
||||
/*
|
||||
Server events:
|
||||
nua_i_method
|
||||
*/
|
||||
TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_method);
|
||||
TEST(e->data->e_status, 100);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
nua_set_params(b->nua,
|
||||
SIPTAG_ALLOW(b->allow),
|
||||
NUTAG_APPL_METHOD(NULL),
|
||||
NUTAG_APPL_METHOD(b->appl_method),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-13.1: PASSED\n");
|
||||
END();
|
||||
}
|
||||
@@ -1,448 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_init.c
|
||||
* @brief Init nua test context
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
|
||||
#include <sofia-sip/tport_tag.h>
|
||||
#include <sofia-sip/auth_module.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ name
|
||||
#endif
|
||||
|
||||
static char passwd_name[] = "tmp_sippasswd.XXXXXX";
|
||||
|
||||
static void remove_tmp(void)
|
||||
{
|
||||
if (passwd_name[0])
|
||||
unlink(passwd_name);
|
||||
}
|
||||
|
||||
static char const passwd[] =
|
||||
"alice:secret:\n"
|
||||
"bob:secret:\n"
|
||||
"charlie:secret:\n";
|
||||
|
||||
int test_nua_init(struct context *ctx,
|
||||
int start_proxy,
|
||||
url_t const *o_proxy,
|
||||
int start_nat,
|
||||
tag_type_t tag, tag_value_t value, ...)
|
||||
{
|
||||
BEGIN();
|
||||
struct event *e;
|
||||
sip_contact_t const *m = NULL;
|
||||
sip_from_t const *sipaddress = NULL;
|
||||
sip_allow_t const *allow = NULL;
|
||||
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;
|
||||
url_t *e_proxy = NULL;
|
||||
int err = -1;
|
||||
url_t b_proxy[1];
|
||||
|
||||
a_bind = a_bind2 = "sip:0.0.0.0:*";
|
||||
|
||||
#if SU_HAVE_OSX_CF_API
|
||||
if (ctx->osx_runloop)
|
||||
ctx->root = su_root_osx_runloop_create(NULL);
|
||||
else
|
||||
#endif
|
||||
ctx->root = su_root_create(NULL);
|
||||
TEST_1(ctx->root);
|
||||
|
||||
/* Disable threading by command line switch -s */
|
||||
su_root_threading(ctx->root, ctx->threading);
|
||||
|
||||
if (start_proxy && !o_proxy) {
|
||||
int temp;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.1.1: init proxy P\n");
|
||||
|
||||
#ifndef _WIN32
|
||||
temp = mkstemp(passwd_name);
|
||||
#else
|
||||
temp = open(passwd_name, O_WRONLY|O_CREAT|O_TRUNC, 666);
|
||||
#endif
|
||||
TEST_1(temp != -1);
|
||||
atexit(remove_tmp); /* Make sure temp file is unlinked */
|
||||
|
||||
TEST_SIZE(write(temp, passwd, strlen(passwd)), strlen(passwd));
|
||||
|
||||
TEST_1(close(temp) == 0);
|
||||
|
||||
ctx->p = test_proxy_create(ctx->root,
|
||||
TAG_IF(ctx->proxy_logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
|
||||
if (ctx->p) {
|
||||
ctx->a.domain =
|
||||
test_proxy_add_domain(ctx->p,
|
||||
URL_STRING_MAKE("sip:example.com")->us_url,
|
||||
AUTHTAG_METHOD("Digest"),
|
||||
AUTHTAG_REALM("test-proxy"),
|
||||
AUTHTAG_OPAQUE("kuik"),
|
||||
AUTHTAG_DB(passwd_name),
|
||||
AUTHTAG_QOP("auth-int"),
|
||||
AUTHTAG_ALGORITHM("md5"),
|
||||
AUTHTAG_NEXT_EXPIRES(60),
|
||||
TAG_END());
|
||||
|
||||
ctx->b.domain =
|
||||
test_proxy_add_domain(ctx->p,
|
||||
URL_STRING_MAKE("sip:example.org")->us_url,
|
||||
AUTHTAG_METHOD("Digest"),
|
||||
AUTHTAG_REALM("test-proxy"),
|
||||
AUTHTAG_OPAQUE("kuik"),
|
||||
AUTHTAG_DB(passwd_name),
|
||||
AUTHTAG_QOP("auth-int"),
|
||||
AUTHTAG_ALGORITHM("md5"),
|
||||
AUTHTAG_NEXT_EXPIRES(60),
|
||||
TAG_END());
|
||||
|
||||
test_proxy_domain_set_outbound(ctx->b.domain, 1);
|
||||
|
||||
ctx->c.domain =
|
||||
test_proxy_add_domain(ctx->p,
|
||||
URL_STRING_MAKE("sip:example.net")->us_url,
|
||||
AUTHTAG_METHOD("Digest"),
|
||||
AUTHTAG_REALM("test-proxy"),
|
||||
AUTHTAG_OPAQUE("kuik"),
|
||||
AUTHTAG_DB(passwd_name),
|
||||
AUTHTAG_QOP("auth-int"),
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.1.1: PASSED\n");
|
||||
}
|
||||
|
||||
p_uri = a_uri = b_uri = test_proxy_uri(ctx->p);
|
||||
|
||||
if (o_proxy) {
|
||||
TEST_1(e_proxy = url_hdup(ctx->home, (void *)o_proxy));
|
||||
ctx->external_proxy = e_proxy;
|
||||
}
|
||||
|
||||
if (start_nat && p_uri == NULL)
|
||||
p_uri = e_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];
|
||||
socklen_t sulen = sizeof su;
|
||||
char b[64];
|
||||
size_t len;
|
||||
ta_list ta;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.1.2: creating test NAT\n");
|
||||
|
||||
/* Try to use different family than proxy. */
|
||||
if (p_uri->url_host[0] == '[')
|
||||
family = AF_INET;
|
||||
#if defined(SU_HAVE_IN6)
|
||||
else
|
||||
family = AF_INET6;
|
||||
#endif
|
||||
|
||||
ta_start(ta, tag, value);
|
||||
ctx->nat = test_nat_create(ctx->root, family, ta_tags(ta));
|
||||
ta_end(ta);
|
||||
|
||||
/*
|
||||
* NAT thingy works so that we set the outgoing proxy URI to point
|
||||
* towards its "private" address and give the real address of the proxy
|
||||
* as its "public" address. If we use different IP families here, we may
|
||||
* even manage to test real connectivity problems as proxy and endpoint
|
||||
* can not talk to each other.
|
||||
*/
|
||||
|
||||
if (test_nat_private(ctx->nat, su, &sulen) < 0) {
|
||||
printf("%s:%u: NUA-2.1.2: failed to get private NAT address\n",
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
#if defined(SU_HAVE_IN6)
|
||||
else if (su->su_family == AF_INET6) {
|
||||
a_uri = (void *)
|
||||
su_sprintf(ctx->home, "sip:[%s]:%u",
|
||||
inet_ntop(su->su_family, SU_ADDR(su), b, sizeof b),
|
||||
ntohs(su->su_port));
|
||||
a_bind = "sip:[::]:*";
|
||||
}
|
||||
#endif
|
||||
else if (su->su_family == AF_INET) {
|
||||
a_uri = (void *)
|
||||
su_sprintf(ctx->home, "sip:%s:%u",
|
||||
inet_ntop(su->su_family, SU_ADDR(su), b, sizeof b),
|
||||
ntohs(su->su_port));
|
||||
}
|
||||
|
||||
#if defined(SU_HAVE_IN6)
|
||||
if (p_uri->url_host[0] == '[') {
|
||||
su->su_len = sulen = (sizeof su->su_sin6), su->su_family = AF_INET6;
|
||||
len = strcspn(p_uri->url_host + 1, "]"); assert(len < sizeof b);
|
||||
memcpy(b, p_uri->url_host + 1, len); b[len] = '\0';
|
||||
inet_pton(su->su_family, b, SU_ADDR(su));
|
||||
}
|
||||
else {
|
||||
su->su_len = sulen = (sizeof su->su_sin), su->su_family = AF_INET;
|
||||
inet_pton(su->su_family, p_uri->url_host, SU_ADDR(su));
|
||||
}
|
||||
#else
|
||||
su->su_len = sulen = (sizeof su->su_sin), su->su_family = AF_INET;
|
||||
inet_pton(su->su_family, p_uri->url_host, SU_ADDR(su));
|
||||
#endif
|
||||
|
||||
su->su_port = htons(strtoul(url_port(p_uri), NULL, 10));
|
||||
|
||||
if (test_nat_public(ctx->nat, su, sulen) < 0) {
|
||||
printf("%s:%u: NUA-2.1.2: failed to set public address\n",
|
||||
__FILE__, __LINE__);
|
||||
a_uri = NULL;
|
||||
}
|
||||
|
||||
if (print_headings) {
|
||||
if (ctx->nat && a_uri) {
|
||||
printf("TEST NUA-2.1.2: PASSED\n");
|
||||
} else {
|
||||
printf("TEST NUA-2.1.2: FAILED\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.1: init endpoint A\n");
|
||||
|
||||
if (a_uri == NULL)
|
||||
a_uri = p_uri;
|
||||
|
||||
ctx->a.instance = nua_generate_instance_identifier(ctx->home);
|
||||
|
||||
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
|
||||
NUTAG_PROXY(a_uri ? a_uri : e_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)),
|
||||
SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
|
||||
NTATAG_SIP_T1X64(2000),
|
||||
NUTAG_INSTANCE(ctx->a.instance),
|
||||
TAG_IF(ctx->a.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(ctx->a.nua);
|
||||
|
||||
nua_get_params(ctx->a.nua, TAG_ANY(), TAG_END());
|
||||
run_a_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
TEST_1(e = ctx->a.specials->head);
|
||||
err = tl_gets(e->data->e_tags,
|
||||
NTATAG_CONTACT_REF(m),
|
||||
SIPTAG_FROM_REF(sipaddress),
|
||||
SIPTAG_ALLOW_REF(allow),
|
||||
NUTAG_APPL_METHOD_REF(appl_method),
|
||||
SIPTAG_SUPPORTED_REF(supported),
|
||||
TAG_END());
|
||||
TEST(err, 5);
|
||||
TEST_1(m);
|
||||
TEST_1(ctx->a.contact = sip_contact_dup(ctx->home, m));
|
||||
TEST_1(ctx->a.to = sip_to_dup(ctx->home, sipaddress));
|
||||
TEST_1(ctx->a.allow = sip_allow_dup(ctx->home, allow));
|
||||
TEST_1(ctx->a.appl_method = su_strdup(ctx->home, appl_method));
|
||||
TEST_1(ctx->a.supported = sip_supported_dup(ctx->home, supported));
|
||||
|
||||
free_events_in_list(ctx, ctx->a.specials);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.1: PASSED\n");
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.2: init endpoint B\n");
|
||||
|
||||
ctx->b.instance = nua_generate_instance_identifier(ctx->home);
|
||||
|
||||
if (ctx->p) {
|
||||
/* B uses TCP when talking with proxy */
|
||||
*b_proxy = *b_uri;
|
||||
b_uri = b_proxy;
|
||||
b_proxy->url_params = "transport=tcp";
|
||||
}
|
||||
|
||||
ctx->b.nua = nua_create(ctx->root, b_callback, ctx,
|
||||
NUTAG_PROXY(b_uri ? b_uri : e_proxy),
|
||||
SIPTAG_FROM_STR("sip:bob@example.org"),
|
||||
NUTAG_URL("sip:0.0.0.0:*"),
|
||||
SOATAG_USER_SDP_STR("m=audio 5006 RTP/AVP 8 0"),
|
||||
NUTAG_INSTANCE(ctx->b.instance),
|
||||
/* Quicker timeout */
|
||||
NTATAG_SIP_T1X64(2000),
|
||||
TPTAG_KEEPALIVE(100),
|
||||
TAG_IF(ctx->b.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(ctx->b.nua);
|
||||
|
||||
nua_get_params(ctx->b.nua, TAG_ANY(), TAG_END());
|
||||
run_b_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
TEST_1(e = ctx->b.specials->head);
|
||||
err = tl_gets(e->data->e_tags,
|
||||
NTATAG_CONTACT_REF(m),
|
||||
SIPTAG_FROM_REF(sipaddress),
|
||||
SIPTAG_ALLOW_REF(allow),
|
||||
NUTAG_APPL_METHOD_REF(appl_method),
|
||||
SIPTAG_SUPPORTED_REF(supported),
|
||||
TAG_END());
|
||||
TEST(err, 5); TEST_1(m);
|
||||
|
||||
TEST_1(ctx->b.contact = sip_contact_dup(ctx->home, m));
|
||||
TEST_1(ctx->b.to = sip_to_dup(ctx->home, sipaddress));
|
||||
TEST_1(ctx->b.allow = sip_allow_dup(ctx->home, allow));
|
||||
TEST_1(ctx->b.appl_method = su_strdup(ctx->home, appl_method));
|
||||
TEST_1(ctx->b.supported = sip_supported_dup(ctx->home, supported));
|
||||
|
||||
free_events_in_list(ctx, ctx->b.specials);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.2: PASSED\n");
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.3: init endpoint C\n");
|
||||
|
||||
/* ctx->c.instance = nua_generate_instance_identifier(ctx->home); */
|
||||
|
||||
ctx->c.to = sip_from_make(ctx->home, "Charlie <sip:charlie@example.net>");
|
||||
|
||||
ctx->c.nua = nua_create(ctx->root, c_callback, ctx,
|
||||
NUTAG_PROXY(p_uri ? p_uri : e_proxy),
|
||||
NUTAG_URL("sip:0.0.0.0:*"),
|
||||
SOATAG_USER_SDP_STR("m=audio 5400 RTP/AVP 8 0"),
|
||||
NUTAG_INSTANCE(ctx->c.instance),
|
||||
TAG_IF(ctx->c.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(ctx->c.nua);
|
||||
|
||||
nua_get_params(ctx->c.nua, TAG_ANY(), TAG_END());
|
||||
run_c_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
TEST_1(e = ctx->c.specials->head);
|
||||
err = tl_gets(e->data->e_tags,
|
||||
NTATAG_CONTACT_REF(m),
|
||||
SIPTAG_ALLOW_REF(allow),
|
||||
NUTAG_APPL_METHOD_REF(appl_method),
|
||||
SIPTAG_SUPPORTED_REF(supported),
|
||||
TAG_END());
|
||||
|
||||
TEST(err, 4); TEST_1(m);
|
||||
TEST_1(ctx->c.contact = sip_contact_dup(ctx->home, m));
|
||||
TEST_1(ctx->c.allow = sip_allow_dup(ctx->home, allow));
|
||||
TEST_1(ctx->c.appl_method = su_strdup(ctx->home, appl_method));
|
||||
TEST_1(ctx->c.supported = sip_supported_dup(ctx->home, supported));
|
||||
free_events_in_list(ctx, ctx->c.specials);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-2.2.3: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
int test_deinit(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct call *call;
|
||||
|
||||
if (!ctx->threading)
|
||||
su_root_step(ctx->root, 100);
|
||||
|
||||
if (ctx->a.nua) {
|
||||
for (call = ctx->a.call; call; call = call->next)
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
|
||||
nua_shutdown(ctx->a.nua);
|
||||
run_a_until(ctx, nua_r_shutdown, until_final_response);
|
||||
free_events_in_list(ctx, ctx->a.events);
|
||||
free_events_in_list(ctx, ctx->a.specials);
|
||||
nua_destroy(ctx->a.nua), ctx->a.nua = NULL;
|
||||
}
|
||||
|
||||
if (ctx->b.nua) {
|
||||
for (call = ctx->b.call; call; call = call->next)
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
|
||||
nua_shutdown(ctx->b.nua);
|
||||
run_b_until(ctx, nua_r_shutdown, until_final_response);
|
||||
free_events_in_list(ctx, ctx->b.events);
|
||||
free_events_in_list(ctx, ctx->b.specials);
|
||||
nua_destroy(ctx->b.nua), ctx->b.nua = NULL;
|
||||
}
|
||||
|
||||
if (ctx->c.nua) {
|
||||
for (call = ctx->c.call; call; call = call->next)
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
|
||||
nua_shutdown(ctx->c.nua);
|
||||
run_c_until(ctx, nua_r_shutdown, until_final_response);
|
||||
free_events_in_list(ctx, ctx->c.events);
|
||||
free_events_in_list(ctx, ctx->c.specials);
|
||||
nua_destroy(ctx->c.nua), ctx->c.nua = NULL;
|
||||
}
|
||||
|
||||
test_proxy_destroy(ctx->p), ctx->p = NULL;
|
||||
|
||||
test_nat_destroy(ctx->nat), ctx->nat = NULL;
|
||||
|
||||
su_root_destroy(ctx->root), ctx->root = NULL;
|
||||
|
||||
END();
|
||||
}
|
||||
@@ -1,999 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nat.c
|
||||
* @brief Simulated NAT for testing
|
||||
*
|
||||
* NAT thing works so that we set the outgoing proxy URI to point
|
||||
* towards its "private" address and give the real address of the proxy
|
||||
* as its "public" address. If we use different IP families here, we may
|
||||
* even manage to test real connectivity problems as proxy and endpoint
|
||||
* can not talk to each other.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Mar 8 19:54:28 EET 2006
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
struct nat;
|
||||
struct binding;
|
||||
|
||||
#define SU_ROOT_MAGIC_T struct nat
|
||||
#define SU_WAKEUP_ARG_T struct binding
|
||||
|
||||
#include <sofia-sip/su.h>
|
||||
#include <sofia-sip/su_errno.h>
|
||||
#include <sofia-sip/su_wait.h>
|
||||
#include <sofia-sip/su_tagarg.h>
|
||||
#include <sofia-sip/su_localinfo.h>
|
||||
#include <sofia-sip/su_log.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LIST_PROTOS(STORAGE, PREFIX, T) \
|
||||
STORAGE void PREFIX ##_insert(T **list, T *node), \
|
||||
PREFIX ##_remove(T *node)
|
||||
|
||||
#define LIST_BODIES(STORAGE, PREFIX, T, NEXT, PREV) \
|
||||
STORAGE void PREFIX ##_insert(T **list, T *node) \
|
||||
{ \
|
||||
if ((node->NEXT = *list)) { \
|
||||
node->PREV = node->NEXT->PREV; \
|
||||
node->NEXT->PREV = &node->NEXT; \
|
||||
} \
|
||||
else \
|
||||
node->PREV = list; \
|
||||
*list = node; \
|
||||
} \
|
||||
STORAGE void PREFIX ##_remove(T *node) \
|
||||
{ \
|
||||
if (node->PREV) \
|
||||
if ((*node->PREV = node->NEXT)) \
|
||||
node->NEXT->PREV = node->PREV; \
|
||||
node->PREV = NULL; \
|
||||
} \
|
||||
extern int LIST_DUMMY_VARIABLE
|
||||
|
||||
#include "test_nat.h"
|
||||
|
||||
struct nat {
|
||||
su_home_t home[1];
|
||||
su_root_t *parent;
|
||||
su_clone_r clone;
|
||||
tagi_t *tags;
|
||||
|
||||
su_root_t *root;
|
||||
|
||||
struct binding *bindings;
|
||||
|
||||
struct nat_filter *in_filters, *out_filters;
|
||||
|
||||
/* True if we act in symmetric way */
|
||||
int symmetric;
|
||||
/* True if we do logging */
|
||||
int logging;
|
||||
|
||||
/* Everything sent to in_address will be forwarded to out_address */
|
||||
su_sockaddr_t in_address[1], out_address[1];
|
||||
socklen_t in_addrlen, out_addrlen;
|
||||
|
||||
int family; /* Preferred private family */
|
||||
|
||||
/* ...but source address will be "fake" */
|
||||
su_localinfo_t *localinfo, *private, *fake;
|
||||
|
||||
su_socket_t udp_socket, tcp_socket;
|
||||
int udp_register, tcp_register;
|
||||
|
||||
char buffer[65536];
|
||||
};
|
||||
|
||||
LIST_PROTOS(static, nat_binding, struct binding);
|
||||
|
||||
struct binding
|
||||
{
|
||||
struct binding *next, **prev;
|
||||
struct nat *nat; /* backpointer */
|
||||
int socktype, protocol;
|
||||
su_socket_t in_socket, out_socket;
|
||||
int in_register, out_register;
|
||||
int in_closed, out_closed;
|
||||
char in_name[64], out_name[64];
|
||||
};
|
||||
|
||||
static struct binding *nat_binding_new(struct nat *nat,
|
||||
char const *protoname,
|
||||
int socktype, int protocol,
|
||||
int connected,
|
||||
su_socket_t in_socket,
|
||||
su_sockaddr_t *from,
|
||||
socklen_t fromlen);
|
||||
static void nat_binding_destroy(struct binding *);
|
||||
|
||||
static int binding_init(struct binding *b,
|
||||
char const *protoname,
|
||||
int connected,
|
||||
su_localinfo_t *li,
|
||||
su_sockaddr_t *from,
|
||||
socklen_t fromlen);
|
||||
|
||||
static void flush_bindings(struct nat *nat);
|
||||
static int invalidate_bindings(void *nat);
|
||||
|
||||
static int new_udp(struct nat *, su_wait_t *wait, struct binding *dummy);
|
||||
static int udp_in_to_out(struct nat *, su_wait_t *wait, struct binding *);
|
||||
static int udp_out_to_in(struct nat *, su_wait_t *wait, struct binding *);
|
||||
|
||||
static int new_tcp(struct nat *, su_wait_t *wait, struct binding *dummy);
|
||||
static int tcp_in_to_out(struct nat *, su_wait_t *wait, struct binding *);
|
||||
static int tcp_out_to_in(struct nat *, su_wait_t *wait, struct binding *);
|
||||
|
||||
static int invalidate_binding(struct binding *b);
|
||||
|
||||
LIST_PROTOS(static, nat_filter, struct nat_filter);
|
||||
|
||||
struct nat_filter
|
||||
{
|
||||
struct nat_filter *next, **prev;
|
||||
size_t (*condition)(void *arg, void *message, size_t len);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
/* nat entry point */
|
||||
static int
|
||||
test_nat_init(su_root_t *root, struct nat *nat)
|
||||
{
|
||||
su_localinfo_t *li, hints[1] = {{ 0 }};
|
||||
int error;
|
||||
unsigned port = 0, port0 = 0;
|
||||
su_sockaddr_t su[1];
|
||||
socklen_t sulen;
|
||||
su_wait_t wait[1];
|
||||
|
||||
nat->root = root;
|
||||
nat->udp_socket = INVALID_SOCKET, nat->tcp_socket = INVALID_SOCKET;
|
||||
|
||||
tl_gets(nat->tags,
|
||||
TESTNATTAG_SYMMETRIC_REF(nat->symmetric),
|
||||
TESTNATTAG_LOGGING_REF(nat->logging),
|
||||
TAG_END());
|
||||
|
||||
hints->li_scope = LI_SCOPE_HOST | LI_SCOPE_SITE | LI_SCOPE_GLOBAL;
|
||||
|
||||
error = su_getlocalinfo(hints, &nat->localinfo);
|
||||
if (error) {
|
||||
fprintf(stderr, "test_nat: su_getlocalinfo: %s\n", su_gli_strerror(error));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* We must have two different IP addresses. */
|
||||
if (!nat->localinfo || !nat->localinfo->li_next) {
|
||||
fprintf(stderr, "test_nat: only one IP address available\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (li = nat->localinfo; li; li = li->li_next) {
|
||||
if (nat->family == 0 || nat->family == li->li_family)
|
||||
break;
|
||||
}
|
||||
if (li == NULL)
|
||||
li = nat->localinfo;
|
||||
|
||||
memcpy(su, li->li_addr, sulen = li->li_addrlen);
|
||||
memset(SU_ADDR(su), 0, SU_ADDRLEN(su));
|
||||
|
||||
nat->private = li;
|
||||
|
||||
/* Bind TCP and UDP to same port */
|
||||
for (;;) {
|
||||
nat->udp_socket = su_socket(li->li_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (nat->udp_socket == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
if (bind(nat->udp_socket, (void *)su, sulen) < 0) {
|
||||
if (port0 == 0) {
|
||||
su_perror("nat: bind(udp_socket)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "test_nat: port %u: %s\n",
|
||||
port, su_strerror(su_errno()));
|
||||
su_close(nat->udp_socket);
|
||||
|
||||
nat->udp_socket = INVALID_SOCKET;
|
||||
|
||||
if (++port > 65535)
|
||||
port = 1024;
|
||||
if (port == port0) {
|
||||
fprintf(stderr, "test_nat: could not find free port pairt\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (getsockname(nat->udp_socket, (void *)su, &sulen) < 0) {
|
||||
su_perror("nat: getsockname(udp_socket)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (port0 == 0) {
|
||||
port = port0 = ntohs(su->su_port);
|
||||
if (port0 == 0) {
|
||||
fprintf(stderr, "test_nat: bind did not return port\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
nat->tcp_socket = su_socket(li->li_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (nat->tcp_socket == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
if (bind(nat->tcp_socket, (void *)su, sulen) < 0) {
|
||||
su_close(nat->tcp_socket);
|
||||
nat->tcp_socket = INVALID_SOCKET;
|
||||
|
||||
fprintf(stderr, "test_nat: port %u: %s\n",
|
||||
port, su_strerror(su_errno()));
|
||||
|
||||
if (++port > 65535)
|
||||
port = 1024;
|
||||
if (port == port0) {
|
||||
fprintf(stderr, "test_nat: could not find free port pair\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(nat->in_address, li->li_addr, nat->in_addrlen = li->li_addrlen);
|
||||
nat->in_address->su_port = su->su_port;
|
||||
|
||||
if (su_setreuseaddr(nat->udp_socket, 1) < 0) {
|
||||
su_perror("nat: su_setreuseaddr(udp_socket)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(nat->tcp_socket, 5) < 0) {
|
||||
su_perror("nat: listen(tcp_socket)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (su_wait_create(wait, nat->udp_socket, SU_WAIT_IN) < 0) {
|
||||
su_perror("nat: su_wait_create");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nat->udp_register = su_root_register(root, wait, new_udp, NULL, 0);
|
||||
if (nat->udp_register < 0) {
|
||||
su_perror("nat: su_root_register");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (su_wait_create(wait, nat->tcp_socket, SU_WAIT_IN) < 0) {
|
||||
su_perror("nat: su_wait_create");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nat->tcp_register = su_root_register(root, wait, new_tcp, NULL, 0);
|
||||
if (nat->tcp_register < 0) {
|
||||
su_perror("nat: su_root_register");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_nat_deinit(su_root_t *root, struct nat *nat)
|
||||
{
|
||||
flush_bindings(nat);
|
||||
|
||||
if (nat->tcp_register)
|
||||
su_root_deregister(root, nat->tcp_register);
|
||||
if (nat->udp_register)
|
||||
su_root_deregister(root, nat->udp_register);
|
||||
|
||||
if (nat->udp_socket != INVALID_SOCKET)
|
||||
su_close(nat->udp_socket);
|
||||
if (nat->tcp_socket != INVALID_SOCKET)
|
||||
su_close(nat->tcp_socket);
|
||||
|
||||
su_freelocalinfo(nat->localinfo);
|
||||
|
||||
free(nat->tags);
|
||||
}
|
||||
|
||||
struct nat *test_nat_create(su_root_t *root,
|
||||
int family,
|
||||
tag_type_t tag, tag_value_t value, ...)
|
||||
{
|
||||
struct nat *nat = su_home_new(sizeof *nat);
|
||||
|
||||
if (nat) {
|
||||
ta_list ta;
|
||||
|
||||
nat->parent = root;
|
||||
nat->family = family;
|
||||
|
||||
ta_start(ta, tag, value);
|
||||
nat->tags = tl_llist(ta_tags(ta));
|
||||
ta_end(ta);
|
||||
|
||||
if (su_clone_start(root,
|
||||
nat->clone,
|
||||
nat,
|
||||
test_nat_init,
|
||||
test_nat_deinit) == -1)
|
||||
su_home_unref(nat->home), nat = NULL;
|
||||
}
|
||||
|
||||
return nat;
|
||||
}
|
||||
|
||||
void test_nat_destroy(struct nat *nat)
|
||||
{
|
||||
if (nat) {
|
||||
su_clone_wait(nat->parent, nat->clone);
|
||||
su_home_unref(nat->home);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get "private" address. */
|
||||
int test_nat_private(struct nat *nat, void *address, socklen_t *return_addrlen)
|
||||
{
|
||||
if (nat == NULL || address == NULL || return_addrlen == NULL)
|
||||
return su_seterrno(EFAULT);
|
||||
|
||||
if (*return_addrlen < nat->in_addrlen)
|
||||
return su_seterrno(EINVAL);
|
||||
|
||||
memcpy(address, nat->in_address, *return_addrlen = nat->in_addrlen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Set "public" address. */
|
||||
int test_nat_public(struct nat *nat, void const *address, int addrlen)
|
||||
{
|
||||
su_sockaddr_t const *su = address;
|
||||
su_localinfo_t *li;
|
||||
|
||||
if (nat == NULL)
|
||||
return su_seterrno(EFAULT);
|
||||
|
||||
if (address == NULL) {
|
||||
nat->fake = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((size_t)addrlen > sizeof nat->out_address)
|
||||
return su_seterrno(EINVAL);
|
||||
|
||||
for (li = nat->localinfo; li; li = li->li_next) {
|
||||
if (li != nat->private &&
|
||||
li->li_scope == LI_SCOPE_HOST &&
|
||||
li->li_family == su->su_family)
|
||||
break;
|
||||
}
|
||||
|
||||
if (li == NULL)
|
||||
for (li = nat->localinfo; li; li = li->li_next) {
|
||||
if (li != nat->private && li->li_family == su->su_family)
|
||||
break;
|
||||
}
|
||||
|
||||
if (li == NULL)
|
||||
return su_seterrno(EADDRNOTAVAIL);
|
||||
|
||||
su_clone_pause(nat->clone);
|
||||
memcpy(nat->out_address, address, nat->out_addrlen = addrlen);
|
||||
nat->fake = li;
|
||||
su_clone_resume(nat->clone);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_nat_flush(struct nat *nat)
|
||||
{
|
||||
if (nat == NULL)
|
||||
return su_seterrno(EFAULT);
|
||||
|
||||
return su_task_execute(su_clone_task(nat->clone),
|
||||
invalidate_bindings, nat, NULL);
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
struct binding *nat_binding_new(struct nat *nat,
|
||||
char const *protoname,
|
||||
int socktype,
|
||||
int protocol,
|
||||
int connected,
|
||||
su_socket_t in_socket,
|
||||
su_sockaddr_t *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
struct binding *b;
|
||||
|
||||
if (nat->fake == NULL) { /* Xyzzy */
|
||||
fprintf(stderr, "test_nat: fake address missing\n");
|
||||
su_close(in_socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b = su_zalloc(nat->home, sizeof *b);
|
||||
if (b == NULL) {
|
||||
su_perror("nat_binding_new: su_zalloc");
|
||||
su_close(in_socket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
b->nat = nat;
|
||||
b->socktype = socktype;
|
||||
b->protocol = protocol;
|
||||
b->in_socket = in_socket, b->out_socket = INVALID_SOCKET;
|
||||
b->in_register = -1, b->out_register = -1;
|
||||
|
||||
if (binding_init(b, protoname, connected, nat->fake, from, fromlen) < 0)
|
||||
nat_binding_destroy(b), b = NULL;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static int binding_init(struct binding *b,
|
||||
char const *protoname,
|
||||
int connected,
|
||||
su_localinfo_t *li,
|
||||
su_sockaddr_t *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
struct nat *nat = b->nat;
|
||||
su_socket_t out_socket;
|
||||
su_sockaddr_t addr[1];
|
||||
socklen_t addrlen = (sizeof addr);
|
||||
char ipname[64];
|
||||
su_wait_t wait[1];
|
||||
su_wakeup_f in_to_out, out_to_in;
|
||||
|
||||
if (b->socktype == SOCK_STREAM)
|
||||
in_to_out = tcp_in_to_out, out_to_in = tcp_out_to_in;
|
||||
else
|
||||
in_to_out = udp_in_to_out, out_to_in = udp_out_to_in;
|
||||
|
||||
if (b->in_socket == INVALID_SOCKET) {
|
||||
int in_socket;
|
||||
|
||||
in_socket = su_socket(from->su_family, b->socktype, b->protocol);
|
||||
if (in_socket == INVALID_SOCKET) {
|
||||
su_perror("nat_binding_new: socket");
|
||||
return -1;
|
||||
}
|
||||
b->in_socket = in_socket;
|
||||
if (su_setreuseaddr(in_socket, 1) < 0) {
|
||||
su_perror("nat_binding_new: su_setreuseaddr(in_socket)");
|
||||
return -1;
|
||||
}
|
||||
if (bind(in_socket, (void *)nat->in_address, nat->in_addrlen) < 0) {
|
||||
su_perror("nat_binding_new: bind(in_socket)");
|
||||
return -1;
|
||||
}
|
||||
if (connect(in_socket, (void *)from, fromlen) < 0) {
|
||||
su_perror("nat_binding_new: connect(in_socket)");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
out_socket = su_socket(li->li_family, b->socktype, b->protocol);
|
||||
if (out_socket == INVALID_SOCKET) {
|
||||
su_perror("nat_binding_new: socket");
|
||||
return -1;
|
||||
}
|
||||
b->out_socket = out_socket;
|
||||
|
||||
if (bind(out_socket, (void *)li->li_addr, li->li_addrlen) < 0) {
|
||||
su_perror("nat_binding_new: bind(to)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connected)
|
||||
if (connect(out_socket, (void *)nat->out_address, nat->out_addrlen) < 0) {
|
||||
su_perror("nat_binding_new: connect(to)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
getpeername(b->in_socket, (void *)addr, &addrlen);
|
||||
inet_ntop(addr->su_family, SU_ADDR(addr), ipname, sizeof ipname);
|
||||
snprintf(b->in_name, sizeof b->in_name,
|
||||
addr->su_family == AF_INET6 ? "[%s]:%u" : "%s:%u",
|
||||
ipname, ntohs(addr->su_port));
|
||||
|
||||
getsockname(out_socket, (void *)addr, &addrlen);
|
||||
inet_ntop(addr->su_family, SU_ADDR(addr), ipname, sizeof ipname);
|
||||
snprintf(b->out_name, sizeof b->out_name,
|
||||
addr->su_family == AF_INET6 ? "[%s]:%u" : "%s:%u",
|
||||
ipname, ntohs(addr->su_port));
|
||||
|
||||
if (su_wait_create(wait, b->in_socket, SU_WAIT_IN) < 0) {
|
||||
su_perror("nat_binding_new: su_wait_create");
|
||||
return -1;
|
||||
}
|
||||
b->in_register = su_root_register(nat->root, wait, in_to_out, b, 0);
|
||||
if (b->in_register < 0) {
|
||||
su_perror("nat_binding_new: su_root_register");
|
||||
su_wait_destroy(wait);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (su_wait_create(wait, out_socket, SU_WAIT_IN) < 0) {
|
||||
su_perror("nat_binding_new: su_wait_create");
|
||||
return -1;
|
||||
}
|
||||
b->out_register = su_root_register(nat->root, wait, out_to_in, b, 0);
|
||||
if (b->out_register < 0) {
|
||||
su_perror("nat_binding_new: su_root_register");
|
||||
su_wait_destroy(wait);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nat_binding_insert(&nat->bindings, b);
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: new %s binding %s <=> %s\n",
|
||||
protoname, b->in_name, b->out_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void nat_binding_destroy(struct binding *b)
|
||||
{
|
||||
nat_binding_remove(b);
|
||||
if (b->in_register != -1)
|
||||
su_root_deregister(b->nat->root, b->in_register);
|
||||
if (b->out_register != -1)
|
||||
su_root_deregister(b->nat->root, b->out_register);
|
||||
su_close(b->in_socket), su_close(b->out_socket);
|
||||
}
|
||||
|
||||
static void flush_bindings(struct nat *nat)
|
||||
{
|
||||
struct binding *b;
|
||||
|
||||
for (b = nat->bindings; b; b = b->next) {
|
||||
if (b->in_register)
|
||||
su_root_deregister(nat->root, b->in_register);
|
||||
su_close(b->in_socket);
|
||||
if (b->out_register)
|
||||
su_root_deregister(nat->root, b->out_register);
|
||||
su_close(b->out_socket);
|
||||
}
|
||||
}
|
||||
|
||||
static int invalidate_bindings(void *arg)
|
||||
{
|
||||
struct nat *nat = arg;
|
||||
struct binding *b;
|
||||
|
||||
for (b = nat->bindings; b; b = b->next) {
|
||||
invalidate_binding(b);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static struct binding *nat_binding_find(struct nat *nat,
|
||||
su_sockaddr_t *from,
|
||||
int fromlen)
|
||||
{
|
||||
char name[64], ipname[64];
|
||||
size_t namelen;
|
||||
struct binding *b;
|
||||
|
||||
inet_ntop(from->su_family, SU_ADDR(from), ipname, sizeof ipname);
|
||||
snprintf(name, sizeof name,
|
||||
from->su_family == AF_INET6 ? "[%s]:%u" : "%s:%u",
|
||||
ipname, ntohs(from->su_port));
|
||||
namelen = strlen(name) + 1;
|
||||
|
||||
for (b = nat->bindings; b; b = b->next) {
|
||||
if (memcmp(name, b->in_name, namelen) == 0)
|
||||
return b;
|
||||
}
|
||||
|
||||
if (b == NULL)
|
||||
b = nat_binding_new(nat, "UDP", SOCK_DGRAM, IPPROTO_UDP, nat->symmetric,
|
||||
INVALID_SOCKET, from, fromlen);
|
||||
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
LIST_BODIES(static, nat_binding, struct binding, next, prev);
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
static int new_udp(struct nat *nat, su_wait_t *wait, struct binding *dummy)
|
||||
{
|
||||
int events;
|
||||
su_sockaddr_t from[1];
|
||||
socklen_t fromlen = (sizeof from);
|
||||
struct binding *b;
|
||||
ssize_t n, m;
|
||||
|
||||
events = su_wait_events(wait, nat->udp_socket);
|
||||
|
||||
n = su_recvfrom(nat->udp_socket, nat->buffer, sizeof nat->buffer, 0,
|
||||
from, &fromlen);
|
||||
if (n < 0) {
|
||||
su_perror("new_udp: recvfrom");
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = nat_binding_new(nat, "UDP", SOCK_DGRAM, IPPROTO_UDP, nat->symmetric,
|
||||
INVALID_SOCKET, from, fromlen);
|
||||
if (b == NULL)
|
||||
return 0;
|
||||
|
||||
if (nat->symmetric)
|
||||
m = su_send(b->out_socket, nat->buffer, n, 0);
|
||||
else
|
||||
m = su_sendto(b->out_socket, nat->buffer, n, 0,
|
||||
nat->out_address, nat->out_addrlen);
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: udp out %d/%d %s => %s\n",
|
||||
(int)m, (int)n, b->in_name, b->out_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
|
||||
{
|
||||
int events;
|
||||
ssize_t n, m;
|
||||
size_t len, filtered;
|
||||
struct nat_filter *f;
|
||||
|
||||
events = su_wait_events(wait, b->in_socket);
|
||||
|
||||
n = su_recv(b->in_socket, nat->buffer, sizeof nat->buffer, 0);
|
||||
if (n == -1) {
|
||||
su_perror("udp_in_to_out: recv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = (size_t)n;
|
||||
|
||||
for (f = nat->out_filters; f; f = f->next) {
|
||||
filtered = f->condition(f->arg, nat->buffer, len);
|
||||
if (filtered != len) {
|
||||
if (nat->logging)
|
||||
printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
|
||||
len, b->in_name, filtered, b->out_name);
|
||||
if (filtered == 0)
|
||||
return 0;
|
||||
len = filtered;
|
||||
}
|
||||
}
|
||||
|
||||
if (nat->symmetric)
|
||||
m = su_send(b->out_socket, nat->buffer, len, 0);
|
||||
else
|
||||
m = su_sendto(b->out_socket, nat->buffer, len, 0,
|
||||
nat->out_address, nat->out_addrlen);
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: udp out %d/%d %s => %s\n",
|
||||
(int)m, (int)n, b->in_name, b->out_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
|
||||
{
|
||||
int events;
|
||||
ssize_t n, m;
|
||||
size_t len, filtered;
|
||||
struct nat_filter *f;
|
||||
|
||||
events = su_wait_events(wait, b->out_socket);
|
||||
|
||||
n = su_recv(b->out_socket, nat->buffer, sizeof nat->buffer, 0);
|
||||
if (n < 0) {
|
||||
su_perror("udp_out_to_out: recv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = (size_t)n;
|
||||
|
||||
for (f = nat->in_filters; f; f = f->next) {
|
||||
filtered = f->condition(f->arg, nat->buffer, len);
|
||||
if (filtered != len) {
|
||||
if (nat->logging)
|
||||
printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
|
||||
len, b->out_name, filtered, b->in_name);
|
||||
if (filtered == 0)
|
||||
return 0;
|
||||
len = filtered;
|
||||
}
|
||||
}
|
||||
|
||||
m = su_send(b->in_socket, nat->buffer, n, 0);
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: udp in %d/%d %s => %s\n",
|
||||
(int)m, (int)n, b->out_name, b->in_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
static int new_tcp(struct nat *nat, su_wait_t *wait, struct binding *dummy)
|
||||
{
|
||||
int events;
|
||||
su_socket_t in_socket;
|
||||
su_sockaddr_t from[1];
|
||||
socklen_t fromlen = (sizeof from);
|
||||
struct binding *b;
|
||||
|
||||
events = su_wait_events(wait, nat->tcp_socket);
|
||||
|
||||
in_socket = accept(nat->tcp_socket, (void *)from, &fromlen);
|
||||
if (in_socket == INVALID_SOCKET) {
|
||||
su_perror("new_tcp: accept");
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = nat_binding_new(nat, "TCP", SOCK_STREAM, IPPROTO_TCP, 1,
|
||||
in_socket, from, fromlen);
|
||||
if (b == NULL)
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tcp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
|
||||
{
|
||||
int events;
|
||||
ssize_t n, m, o;
|
||||
|
||||
events = su_wait_events(wait, b->in_socket);
|
||||
|
||||
n = su_recv(b->in_socket, nat->buffer, sizeof nat->buffer, 0);
|
||||
if (n < 0) {
|
||||
su_perror("tcp_in_to_out: recv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
if (nat->logging)
|
||||
printf("nat: tcp out FIN %s => %s\n", b->in_name, b->out_name);
|
||||
shutdown(b->out_socket, 1);
|
||||
su_root_eventmask(nat->root, b->in_register, b->in_socket, 0);
|
||||
b->in_closed = 1;
|
||||
if (b->out_closed && b->in_closed)
|
||||
nat_binding_destroy(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (m = 0; m < n; m += o) {
|
||||
o = su_send(b->out_socket, nat->buffer + m, n - m, 0);
|
||||
if (o < 0) {
|
||||
su_perror("tcp_in_to_out: send");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: tcp out %d/%d %s => %s\n",
|
||||
(int)m, (int)n, b->in_name, b->out_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tcp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
|
||||
{
|
||||
int events;
|
||||
ssize_t n, m, o;
|
||||
|
||||
events = su_wait_events(wait, b->out_socket);
|
||||
|
||||
n = su_recv(b->out_socket, nat->buffer, sizeof nat->buffer, 0);
|
||||
if (n < 0) {
|
||||
su_perror("tcp_out_to_in: recv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
if (nat->logging)
|
||||
printf("nat: tcp out FIN %s => %s\n", b->out_name, b->in_name);
|
||||
shutdown(b->in_socket, 1);
|
||||
su_root_eventmask(nat->root, b->in_register, b->out_socket, 0);
|
||||
b->out_closed = 1;
|
||||
if (b->out_closed && b->in_closed)
|
||||
nat_binding_destroy(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (m = 0; m < n; m += o) {
|
||||
o = su_send(b->in_socket, nat->buffer + m, n - m, 0);
|
||||
if (o < 0) {
|
||||
if (su_errno() != EPIPE)
|
||||
su_perror("tcp_in_to_out: send");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: tcp in %d/%d %s => %s\n",
|
||||
(int)m, (int)n, b->out_name, b->in_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int invalidate_binding(struct binding *b)
|
||||
{
|
||||
struct nat *nat = b->nat;
|
||||
su_sockaddr_t addr[1];
|
||||
socklen_t addrlen = (sizeof addr);
|
||||
su_socket_t out;
|
||||
int out_register;
|
||||
su_wait_t wout[1];
|
||||
char name[64];
|
||||
|
||||
out = su_socket(nat->fake->li_family, b->socktype, 0);
|
||||
if (out == INVALID_SOCKET) {
|
||||
su_perror("new_udp: socket");
|
||||
return -1;
|
||||
}
|
||||
if (bind(out, (void *)nat->fake->li_addr, nat->fake->li_addrlen) < 0) {
|
||||
su_perror("new_udp: bind(to)");
|
||||
su_close(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nat->symmetric)
|
||||
if (connect(out, (void *)nat->out_address, nat->out_addrlen) < 0) {
|
||||
su_perror("new_udp: connect(to)");
|
||||
su_close(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (su_wait_create(wout, out, SU_WAIT_IN) < 0) {
|
||||
su_perror("new_udp: su_wait_create");
|
||||
su_close(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (b->socktype == SOCK_DGRAM)
|
||||
out_register = su_root_register(nat->root, wout, udp_out_to_in, b, 0);
|
||||
else
|
||||
out_register = su_root_register(nat->root, wout, tcp_out_to_in, b, 0);
|
||||
|
||||
if (out_register < 0) {
|
||||
su_perror("new_udp: su_root_register");
|
||||
su_wait_destroy(wout);
|
||||
su_close(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
su_root_deregister(nat->root, b->out_register);
|
||||
su_close(b->out_socket);
|
||||
|
||||
b->out_socket = out;
|
||||
b->out_register = out_register;
|
||||
|
||||
getsockname(out, (void *)addr, &addrlen);
|
||||
inet_ntop(addr->su_family, SU_ADDR(addr), name, sizeof name);
|
||||
snprintf(b->out_name, sizeof b->out_name,
|
||||
addr->su_family == AF_INET6 ? "[%s]:%u" : "%s:%u",
|
||||
name, ntohs(addr->su_port));
|
||||
|
||||
if (nat->logging)
|
||||
printf("nat: flushed binding %s <=> %s\n", b->in_name, b->out_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LIST_BODIES(static, nat_filter, struct nat_filter, next, prev);
|
||||
|
||||
struct args {
|
||||
struct nat *nat;
|
||||
struct nat_filter *f;
|
||||
int outbound;
|
||||
};
|
||||
|
||||
int execute_nat_filter_insert(void *_args)
|
||||
{
|
||||
struct args *a = (struct args *)_args;
|
||||
if (a->outbound)
|
||||
nat_filter_insert(&a->nat->out_filters, a->f);
|
||||
else
|
||||
nat_filter_insert(&a->nat->in_filters, a->f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int execute_nat_filter_remove(void *_args)
|
||||
{
|
||||
struct args *a = (struct args *)_args;
|
||||
nat_filter_remove(a->f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct nat_filter *test_nat_add_filter(struct nat *nat,
|
||||
size_t (*condition)(void *arg,
|
||||
void *message,
|
||||
size_t len),
|
||||
void *arg,
|
||||
int outbound)
|
||||
{
|
||||
struct args a[1];
|
||||
|
||||
if (nat == NULL)
|
||||
return su_seterrno(EFAULT), NULL;
|
||||
|
||||
a->nat = nat;
|
||||
a->f = su_zalloc(nat->home, sizeof *a->f);
|
||||
a->outbound = outbound;
|
||||
|
||||
if (a->f) {
|
||||
a->f->condition = condition;
|
||||
a->f->arg = arg;
|
||||
if (su_task_execute(su_clone_task(nat->clone),
|
||||
execute_nat_filter_insert, a, NULL) < 0)
|
||||
su_free(nat->home, a->f), a->f = NULL;
|
||||
}
|
||||
|
||||
return a->f;
|
||||
}
|
||||
|
||||
|
||||
int test_nat_remove_filter(struct nat *nat,
|
||||
struct nat_filter *filter)
|
||||
{
|
||||
struct args a[1];
|
||||
|
||||
if (nat == NULL)
|
||||
return su_seterrno(EFAULT);
|
||||
|
||||
a->nat = nat;
|
||||
a->f = filter;
|
||||
|
||||
if (su_task_execute(su_clone_task(nat->clone),
|
||||
execute_nat_filter_remove, a, NULL) < 0)
|
||||
return -1;
|
||||
|
||||
su_free(nat->home, filter);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TEST_NAT_H
|
||||
#define TEST_NAT_H
|
||||
|
||||
#include <sofia-sip/su_wait.h>
|
||||
#include <sofia-sip/nta.h>
|
||||
|
||||
SOFIA_BEGIN_DECLS
|
||||
|
||||
struct nat;
|
||||
struct nat_filter;
|
||||
|
||||
struct nat *test_nat_create(su_root_t *, int family,
|
||||
tag_type_t, tag_value_t, ...);
|
||||
|
||||
void test_nat_destroy(struct nat *);
|
||||
|
||||
int test_nat_private(struct nat *nat, void *address, socklen_t *return_addrlen);
|
||||
int test_nat_public(struct nat *nat, void const *address, int addrlen);
|
||||
|
||||
int test_nat_flush(struct nat *nat);
|
||||
|
||||
struct nat_filter *test_nat_add_filter(struct nat *nat,
|
||||
size_t (*condition)(void *arg,
|
||||
void *message,
|
||||
size_t len),
|
||||
void *arg,
|
||||
int outbound);
|
||||
|
||||
enum { nat_inbound, nat_outbound };
|
||||
|
||||
int test_nat_remove_filter(struct nat *nat,
|
||||
struct nat_filter *filter);
|
||||
|
||||
/* Tags */
|
||||
|
||||
/** If true, act as symmetric nat. */
|
||||
#define TESTNATTAG_SYMMETRIC(x) testnattag_symmetric, tag_bool_v((x))
|
||||
#define TESTNATTAG_SYMMETRIC_REF(x) testnattag_symmetric_ref, tag_bool_vr(&(x))
|
||||
extern tag_typedef_t testnattag_symmetric;
|
||||
extern tag_typedef_t testnattag_symmetric_ref;
|
||||
|
||||
/** If true, print information about connections. */
|
||||
#define TESTNATTAG_LOGGING(x) testnattag_logging, tag_bool_v((x))
|
||||
#define TESTNATTAG_LOGGING_REF(x) testnattag_logging_ref, tag_bool_vr(&(x))
|
||||
extern tag_typedef_t testnattag_logging;
|
||||
extern tag_typedef_t testnattag_logging_ref;
|
||||
|
||||
SOFIA_END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nat_tags.c
|
||||
* @brief Tags for simulated NAT
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Mar 8 19:54:28 EET 2006
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nat.h"
|
||||
|
||||
tag_typedef_t testnattag_symmetric = BOOLTAG_TYPEDEF(symmetric);
|
||||
tag_typedef_t testnattag_symmetric_ref = REFTAG_TYPEDEF(testnattag_symmetric);
|
||||
tag_typedef_t testnattag_logging = BOOLTAG_TYPEDEF(symmetric);
|
||||
tag_typedef_t testnattag_logging_ref = REFTAG_TYPEDEF(testnattag_logging);
|
||||
@@ -1,397 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nua.c
|
||||
* @brief High-level tester for Sofia SIP User Agent Engine
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
|
||||
#if HAVE_ALARM
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
SOFIAPUBVAR su_log_t nua_log[];
|
||||
SOFIAPUBVAR su_log_t soa_log[];
|
||||
SOFIAPUBVAR su_log_t nea_log[];
|
||||
SOFIAPUBVAR su_log_t nta_log[];
|
||||
SOFIAPUBVAR su_log_t tport_log[];
|
||||
SOFIAPUBVAR su_log_t su_log_default[];
|
||||
|
||||
char const name[] = "test_nua";
|
||||
int print_headings = 1;
|
||||
int tstflags = 0;
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ name
|
||||
#endif
|
||||
|
||||
#if HAVE_ALARM
|
||||
static RETSIGTYPE sig_alarm(int s)
|
||||
{
|
||||
fprintf(stderr, "%s: FAIL! test timeout!\n", name);
|
||||
if (tstflags & tst_abort)
|
||||
abort();
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static char const options_usage[] =
|
||||
" -v | --verbose be verbose\n"
|
||||
" -q | --quiet be quiet\n"
|
||||
" -a | --abort abort on error\n"
|
||||
" -s use only single thread\n"
|
||||
" -l level set logging level (0 by default)\n"
|
||||
" -e | --events print nua events\n"
|
||||
" -A print nua events for A\n"
|
||||
" -B print nua events for B\n"
|
||||
" -C print nua events for C\n"
|
||||
" --log=a log messages for A\n"
|
||||
" --log=b log messages for B\n"
|
||||
" --log=c log messages for C\n"
|
||||
" --log=proxy log messages for proxy\n"
|
||||
" --attach print pid, wait for a debugger to be attached\n"
|
||||
" --no-proxy do not use internal proxy\n"
|
||||
" --no-nat do not use internal \"nat\"\n"
|
||||
" --symmetric run internal \"nat\" in symmetric mode\n"
|
||||
" -N print events from internal \"nat\"\n"
|
||||
" --loop loop main tests for ever\n"
|
||||
" --no-alarm don't ask for guard ALARM\n"
|
||||
" -p uri specify uri of outbound proxy (implies --no-proxy)\n"
|
||||
" --proxy-tests run tests involving proxy, too\n"
|
||||
#if SU_HAVE_OSX_CF_API /* If compiled with CoreFoundation events */
|
||||
" --osx-runloop use OSX CoreFoundation runloop instead of poll() loop\n"
|
||||
#endif
|
||||
" -k do not exit after first error\n"
|
||||
;
|
||||
|
||||
void usage(int exitcode)
|
||||
{
|
||||
fprintf(stderr, "usage: %s OPTIONS\n where OPTIONS are\n%s",
|
||||
name, options_usage);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int retval = 0;
|
||||
int i, o_quiet = 0, o_attach = 0, o_alarm = 1, o_loop = 0;
|
||||
int o_events_init = 0, o_events_a = 0, o_events_b = 0, o_events_c = 0;
|
||||
int o_iproxy = 1, o_inat = 1;
|
||||
int o_inat_symmetric = 0, o_inat_logging = 0, o_expensive = 0;
|
||||
url_t const *o_proxy = NULL;
|
||||
int level = 0;
|
||||
|
||||
struct context ctx[1] = {{{ SU_HOME_INIT(ctx) }}};
|
||||
|
||||
#if HAVE_OPEN_C
|
||||
dup2(1, 2);
|
||||
#endif
|
||||
|
||||
if (getenv("EXPENSIVE_CHECKS"))
|
||||
o_expensive = 1;
|
||||
|
||||
ctx->threading = 1;
|
||||
ctx->quit_on_single_failure = 1;
|
||||
|
||||
endpoint_init(ctx, &ctx->a, 'a');
|
||||
endpoint_init(ctx, &ctx->b, 'b');
|
||||
endpoint_init(ctx, &ctx->c, 'c');
|
||||
|
||||
for (i = 1; argv[i]; i++) {
|
||||
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0)
|
||||
tstflags |= tst_verbatim;
|
||||
else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--abort") == 0)
|
||||
tstflags |= tst_abort;
|
||||
else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0)
|
||||
tstflags &= ~tst_verbatim, o_quiet = 1;
|
||||
else if (strcmp(argv[i], "-k") == 0)
|
||||
ctx->quit_on_single_failure = 0;
|
||||
else if (strncmp(argv[i], "-l", 2) == 0) {
|
||||
char *rest = NULL;
|
||||
|
||||
if (argv[i][2])
|
||||
level = strtol(argv[i] + 2, &rest, 10);
|
||||
else if (argv[i + 1])
|
||||
level = strtol(argv[i + 1], &rest, 10), i++;
|
||||
else
|
||||
level = 3, rest = "";
|
||||
|
||||
if (rest == NULL || *rest)
|
||||
usage(1);
|
||||
|
||||
su_log_set_level(nua_log, level);
|
||||
su_log_soft_set_level(soa_log, level);
|
||||
su_log_soft_set_level(nea_log, level);
|
||||
su_log_soft_set_level(nta_log, level);
|
||||
su_log_soft_set_level(tport_log, level);
|
||||
}
|
||||
else if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--events") == 0) {
|
||||
o_events_init = o_events_a = o_events_b = o_events_c = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-I") == 0) {
|
||||
o_events_init = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-A") == 0) {
|
||||
o_events_a = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-B") == 0) {
|
||||
o_events_b = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-C") == 0) {
|
||||
o_events_c = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-s") == 0) {
|
||||
ctx->threading = 0;
|
||||
}
|
||||
else if (strcmp(argv[i], "--attach") == 0) {
|
||||
o_attach = 1;
|
||||
}
|
||||
else if (strncmp(argv[i], "-p", 2) == 0) {
|
||||
if (argv[i][2])
|
||||
o_proxy = URL_STRING_MAKE(argv[i] + 2)->us_url;
|
||||
else if (!argv[++i] || argv[i][0] == '-')
|
||||
usage(1);
|
||||
else
|
||||
o_proxy = URL_STRING_MAKE(argv[i])->us_url;
|
||||
}
|
||||
else if (strcmp(argv[i], "--proxy-tests") == 0) {
|
||||
ctx->proxy_tests = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--no-proxy") == 0) {
|
||||
o_iproxy = 0;
|
||||
}
|
||||
else if (strcmp(argv[i], "--no-nat") == 0) {
|
||||
o_inat = 0;
|
||||
}
|
||||
else if (strcmp(argv[i], "--nat") == 0) {
|
||||
o_inat = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--symmetric") == 0) {
|
||||
o_inat_symmetric = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-N") == 0) {
|
||||
o_inat_logging = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--expensive") == 0) {
|
||||
o_expensive = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--no-alarm") == 0) {
|
||||
o_alarm = 0;
|
||||
}
|
||||
else if (strcmp(argv[i], "--loop") == 0) {
|
||||
o_alarm = 0, o_loop = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--print-tags") == 0) {
|
||||
ctx->print_tags = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--tags=a") == 0) {
|
||||
ctx->a.print_tags = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--tags=b") == 0) {
|
||||
ctx->b.print_tags = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--tags=c") == 0) {
|
||||
ctx->c.print_tags = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--log=a") == 0) {
|
||||
ctx->a.logging = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--log=b") == 0) {
|
||||
ctx->b.logging = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--log=c") == 0) {
|
||||
ctx->c.logging = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "--log=proxy") == 0) {
|
||||
ctx->proxy_logging = 1;
|
||||
}
|
||||
#if SU_HAVE_OSX_CF_API /* If compiled with CoreFoundation events */
|
||||
else if (strcmp(argv[i], "--osx-runloop") == 0) {
|
||||
ctx->osx_runloop = 1;
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(argv[i], "-") == 0) {
|
||||
i++; break;
|
||||
}
|
||||
else if (argv[i][0] != '-') {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "test_nua: unknown argument \"%s\"\n\n", argv[i]);
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (o_attach) {
|
||||
char line[10], *l;
|
||||
printf("%s: pid %lu\n", name, (unsigned long)getpid());
|
||||
printf("<Press RETURN to continue>\n");
|
||||
l = fgets(line, sizeof line, stdin);
|
||||
}
|
||||
#if HAVE_ALARM
|
||||
else if (o_alarm) {
|
||||
signal(SIGALRM, sig_alarm);
|
||||
if (o_expensive) {
|
||||
printf("%s: extending timeout to %u because expensive tests\n",
|
||||
name, 240);
|
||||
alarm(240);
|
||||
}
|
||||
else {
|
||||
alarm(120);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_OPEN_C
|
||||
tstflags |= tst_verbatim;
|
||||
level = 9;
|
||||
o_inat = 1; /* No NATs */
|
||||
ctx->threading = 1;
|
||||
ctx->quit_on_single_failure = 1;
|
||||
su_log_soft_set_level(nua_log, level);
|
||||
su_log_soft_set_level(soa_log, level);
|
||||
su_log_soft_set_level(su_log_default, level);
|
||||
su_log_soft_set_level(nea_log, level);
|
||||
su_log_soft_set_level(nta_log, level);
|
||||
su_log_soft_set_level(tport_log, level);
|
||||
setenv("SU_DEBUG", "9", 1);
|
||||
setenv("NUA_DEBUG", "9", 1);
|
||||
setenv("NTA_DEBUG", "9", 1);
|
||||
setenv("TPORT_DEBUG", "9", 1);
|
||||
o_events_a = o_events_b = 1;
|
||||
#endif
|
||||
|
||||
su_init();
|
||||
|
||||
if (!(TSTFLAGS & tst_verbatim)) {
|
||||
if (level == 0 && !o_quiet)
|
||||
level = 1;
|
||||
su_log_soft_set_level(nua_log, level);
|
||||
su_log_soft_set_level(soa_log, level);
|
||||
su_log_soft_set_level(su_log_default, level);
|
||||
su_log_soft_set_level(nea_log, level);
|
||||
su_log_soft_set_level(nta_log, level);
|
||||
su_log_soft_set_level(tport_log, level);
|
||||
}
|
||||
|
||||
if (!o_quiet || (TSTFLAGS & tst_verbatim)
|
||||
|| o_events_a || o_events_b || o_events_c)
|
||||
print_headings = 1;
|
||||
|
||||
#if !HAVE_OPEN_C
|
||||
#define SINGLE_FAILURE_CHECK() \
|
||||
do { fflush(stdout); \
|
||||
if (retval && ctx->quit_on_single_failure) { \
|
||||
su_deinit(); return retval; } \
|
||||
} while(0)
|
||||
#else
|
||||
#define SINGLE_FAILURE_CHECK() \
|
||||
do { fflush(stdout); \
|
||||
if (retval && ctx->quit_on_single_failure) { \
|
||||
su_deinit(); sleep(10); return retval; } \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
ctx->a.printer = o_events_init ? print_event : NULL;
|
||||
|
||||
retval |= test_nua_api_errors(ctx); SINGLE_FAILURE_CHECK();
|
||||
|
||||
retval |= test_tag_filter(); SINGLE_FAILURE_CHECK();
|
||||
|
||||
retval |= test_nua_params(ctx); SINGLE_FAILURE_CHECK();
|
||||
|
||||
retval |= test_nua_destroy(ctx); SINGLE_FAILURE_CHECK();
|
||||
|
||||
retval |= test_stack_errors(ctx); SINGLE_FAILURE_CHECK();
|
||||
|
||||
retval |= test_nua_init(ctx, o_iproxy, o_proxy, o_inat,
|
||||
TESTNATTAG_SYMMETRIC(o_inat_symmetric),
|
||||
TESTNATTAG_LOGGING(o_inat_logging),
|
||||
TAG_END());
|
||||
|
||||
ctx->expensive = o_expensive;
|
||||
|
||||
if (retval == 0) {
|
||||
ctx->a.printer = o_events_a ? print_event : NULL;
|
||||
if (o_events_b)
|
||||
ctx->b.printer = print_event;
|
||||
if (o_events_c)
|
||||
ctx->c.printer = print_event;
|
||||
|
||||
retval |= test_register(ctx);
|
||||
|
||||
if (retval == 0)
|
||||
retval |= test_connectivity(ctx);
|
||||
|
||||
if (retval == 0 && o_inat)
|
||||
retval |= test_nat_timeout(ctx);
|
||||
|
||||
while (retval == 0) {
|
||||
retval |= test_basic_call(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_rejects(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_call_cancel(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_call_destroy(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_early_bye(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_offer_answer(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_reinvites(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_simple(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_events(ctx); SINGLE_FAILURE_CHECK();
|
||||
retval |= test_extension(ctx); SINGLE_FAILURE_CHECK();
|
||||
if (!o_loop)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctx->proxy_tests && (retval == 0 || !ctx->p))
|
||||
retval |= test_unregister(ctx); SINGLE_FAILURE_CHECK();
|
||||
}
|
||||
retval |= test_deinit(ctx);
|
||||
|
||||
su_home_deinit(ctx->home);
|
||||
|
||||
su_deinit();
|
||||
|
||||
#if HAVE_OPEN_C
|
||||
sleep(7);
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@@internal
|
||||
* @file test_nua.h
|
||||
* @brief High-level tester framework for Sofia SIP User Agent Engine
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#ifndef TEST_NUA_H
|
||||
#define TEST_NUA_H
|
||||
|
||||
struct context;
|
||||
#define NUA_MAGIC_T struct context
|
||||
|
||||
struct call;
|
||||
#define NUA_HMAGIC_T struct call
|
||||
|
||||
#include "sofia-sip/nua.h"
|
||||
#include "sofia-sip/sip_status.h"
|
||||
|
||||
#include <sofia-sip/sdp.h>
|
||||
#include <sofia-sip/sip_header.h>
|
||||
|
||||
#include <sofia-sip/su_log.h>
|
||||
#include <sofia-sip/su_tagarg.h>
|
||||
#include <sofia-sip/su_tag_io.h>
|
||||
#include <sofia-sip/nua_tag.h>
|
||||
|
||||
#if __APPLE_CC__
|
||||
#include <sofia-sip/su_osx_runloop.h>
|
||||
#endif
|
||||
|
||||
#include "test_proxy.h"
|
||||
#include "test_nat.h"
|
||||
#include <sofia-sip/auth_module.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char const name[];
|
||||
|
||||
extern int print_headings;
|
||||
extern int tstflags;
|
||||
#define TSTFLAGS tstflags
|
||||
|
||||
#include <sofia-sip/tstdef.h>
|
||||
|
||||
#define TEST_E(a, b) TEST_S(nua_event_name(a), nua_event_name(b))
|
||||
|
||||
#define NONE ((void*)-1)
|
||||
|
||||
struct endpoint;
|
||||
|
||||
typedef
|
||||
int condition_function(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
struct endpoint *ep,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
|
||||
typedef
|
||||
void printer_function(nua_event_t event,
|
||||
char const *operation,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
struct endpoint *ep,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
|
||||
struct proxy_transaction;
|
||||
struct registration_entry;
|
||||
|
||||
enum { event_is_extra, event_is_normal, event_is_special };
|
||||
|
||||
struct eventlist
|
||||
{
|
||||
nua_event_t kind;
|
||||
struct event *head, **tail;
|
||||
};
|
||||
|
||||
struct event
|
||||
{
|
||||
struct event *next, **prev;
|
||||
struct call *call;
|
||||
nua_saved_event_t saved_event[1];
|
||||
nua_event_data_t const *data;
|
||||
};
|
||||
|
||||
|
||||
struct context
|
||||
{
|
||||
su_home_t home[1];
|
||||
su_root_t *root;
|
||||
|
||||
int threading, proxy_tests, expensive, quit_on_single_failure, osx_runloop;
|
||||
int print_tags;
|
||||
|
||||
url_t *external_proxy;
|
||||
|
||||
int proxy_logging;
|
||||
|
||||
struct endpoint {
|
||||
char name[4];
|
||||
struct context *ctx; /* Backpointer */
|
||||
|
||||
int logging;
|
||||
int print_tags;
|
||||
|
||||
int running;
|
||||
|
||||
struct domain *domain;
|
||||
condition_function *next_condition;
|
||||
nua_event_t next_event, last_event;
|
||||
nua_t *nua;
|
||||
sip_contact_t *contact;
|
||||
sip_from_t *to;
|
||||
|
||||
sip_allow_t *allow;
|
||||
char const *appl_method;
|
||||
sip_supported_t *supported;
|
||||
|
||||
printer_function *printer;
|
||||
|
||||
char const *instance;
|
||||
|
||||
/* Per-call stuff */
|
||||
struct call {
|
||||
struct call *next;
|
||||
nua_handle_t *nh;
|
||||
char const *sdp;
|
||||
struct eventlist *events;
|
||||
} call[1], reg[1];
|
||||
|
||||
int (*is_special)(nua_event_t e);
|
||||
|
||||
/* Normal events are saved here */
|
||||
struct eventlist events[1];
|
||||
/* Special events are saved here */
|
||||
struct eventlist specials[1];
|
||||
|
||||
/* State flags for complex scenarios */
|
||||
struct {
|
||||
unsigned n;
|
||||
unsigned bit0:1, bit1:1, bit2:1, bit3:1;
|
||||
unsigned bit4:1, bit5:1, bit6:1, bit7:1;
|
||||
unsigned :0;
|
||||
} flags;
|
||||
/* Accross-run state information */
|
||||
struct {
|
||||
unsigned n;
|
||||
} state;
|
||||
} a, b, c;
|
||||
|
||||
struct proxy *p;
|
||||
sip_route_t const *lr;
|
||||
struct nat *nat;
|
||||
};
|
||||
|
||||
#define RETURN_ON_SINGLE_FAILURE(retval) \
|
||||
do { \
|
||||
fflush(stdout); \
|
||||
if (retval && ctx->quit_on_single_failure) { return retval; } \
|
||||
} while(0)
|
||||
|
||||
|
||||
int save_event_in_list(struct context *,
|
||||
nua_event_t nevent,
|
||||
struct endpoint *,
|
||||
struct call *);
|
||||
void free_events_in_list(struct context *,
|
||||
struct eventlist *);
|
||||
void free_event_in_list(struct context *ctx,
|
||||
struct eventlist *list,
|
||||
struct event *e);
|
||||
|
||||
struct event *event_by_type(struct event *e, nua_event_t);
|
||||
size_t count_events(struct event const *e);
|
||||
|
||||
#define CONDITION_PARAMS \
|
||||
nua_event_t event, \
|
||||
int status, char const *phrase, \
|
||||
nua_t *nua, struct context *ctx, \
|
||||
struct endpoint *ep, \
|
||||
nua_handle_t *nh, struct call *call, \
|
||||
sip_t const *sip, \
|
||||
tagi_t tags[]
|
||||
|
||||
int save_events(CONDITION_PARAMS);
|
||||
int until_final_response(CONDITION_PARAMS);
|
||||
int save_until_final_response(CONDITION_PARAMS);
|
||||
int save_until_received(CONDITION_PARAMS);
|
||||
int save_until_special(CONDITION_PARAMS);
|
||||
|
||||
int until_terminated(CONDITION_PARAMS);
|
||||
int until_ready(CONDITION_PARAMS);
|
||||
int accept_call(CONDITION_PARAMS);
|
||||
int cancel_when_ringing(CONDITION_PARAMS);
|
||||
|
||||
int accept_notify(CONDITION_PARAMS);
|
||||
|
||||
void a_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
void b_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
void c_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
|
||||
void run_abc_until(struct context *ctx,
|
||||
nua_event_t a_event, condition_function *a_condition,
|
||||
nua_event_t b_event, condition_function *b_condition,
|
||||
nua_event_t c_event, condition_function *c_condition);
|
||||
|
||||
void run_ab_until(struct context *ctx,
|
||||
nua_event_t a_event, condition_function *a_condition,
|
||||
nua_event_t b_event, condition_function *b_condition);
|
||||
|
||||
void run_bc_until(struct context *ctx,
|
||||
nua_event_t b_event, condition_function *b_condition,
|
||||
nua_event_t c_event, condition_function *c_condition);
|
||||
|
||||
int run_a_until(struct context *, nua_event_t, condition_function *);
|
||||
int run_b_until(struct context *, nua_event_t, condition_function *);
|
||||
int run_c_until(struct context *, nua_event_t, condition_function *);
|
||||
|
||||
typedef int operation_f(struct endpoint *ep, struct call *call,
|
||||
nua_handle_t *nh, tag_type_t tag, tag_value_t value,
|
||||
...);
|
||||
|
||||
operation_f INVITE, ACK, BYE, CANCEL, AUTHENTICATE, UPDATE, INFO, PRACK,
|
||||
REFER, MESSAGE, METHOD, OPTIONS, PUBLISH, UNPUBLISH, REGISTER, UNREGISTER,
|
||||
SUBSCRIBE, UNSUBSCRIBE, NOTIFY, NOTIFIER, TERMINATE, AUTHORIZE;
|
||||
|
||||
int RESPOND(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh,
|
||||
int status, char const *phrase,
|
||||
tag_type_t tag, tag_value_t value,
|
||||
...);
|
||||
|
||||
int DESTROY(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh);
|
||||
|
||||
struct call *check_handle(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh,
|
||||
int status, char const *phrase);
|
||||
|
||||
int is_special(nua_event_t e);
|
||||
int callstate(tagi_t const *tags);
|
||||
int is_offer_sent(tagi_t const *tags);
|
||||
int is_answer_sent(tagi_t const *tags);
|
||||
int is_offer_recv(tagi_t const *tags);
|
||||
int is_answer_recv(tagi_t const *tags);
|
||||
int is_offer_answer_done(tagi_t const *tags);
|
||||
int audio_activity(tagi_t const *tags);
|
||||
int video_activity(tagi_t const *tags);
|
||||
|
||||
void print_event(nua_event_t event,
|
||||
char const *operation,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
struct endpoint *ep,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[]);
|
||||
|
||||
su_inline
|
||||
void eventlist_init(struct eventlist *list)
|
||||
{
|
||||
list->tail = &list->head;
|
||||
}
|
||||
|
||||
su_inline
|
||||
void call_init(struct call *call)
|
||||
{
|
||||
}
|
||||
|
||||
void endpoint_init(struct context *ctx, struct endpoint *e, char id);
|
||||
|
||||
int test_nua_init(struct context *ctx,
|
||||
int start_proxy,
|
||||
url_t const *o_proxy,
|
||||
int start_nat,
|
||||
tag_type_t tag, tag_value_t value, ...);
|
||||
|
||||
int test_deinit(struct context *ctx);
|
||||
|
||||
int test_nua_api_errors(struct context *ctx);
|
||||
int test_nua_destroy(struct context *ctx);
|
||||
int test_stack_errors(struct context *ctx);
|
||||
int test_tag_filter(void);
|
||||
int test_nua_params(struct context *ctx);
|
||||
|
||||
int test_register(struct context *ctx);
|
||||
int test_connectivity(struct context *ctx);
|
||||
int test_nat_timeout(struct context *ctx);
|
||||
int test_unregister(struct context *ctx);
|
||||
|
||||
int test_basic_call(struct context *ctx);
|
||||
int test_offer_answer(struct context *ctx);
|
||||
int test_rejects(struct context *ctx);
|
||||
int test_mime_negotiation(struct context *ctx);
|
||||
int test_call_timeouts(struct context *ctx);
|
||||
int test_reject_401_aka(struct context *ctx);
|
||||
int test_call_cancel(struct context *ctx);
|
||||
int test_call_destroy(struct context *ctx);
|
||||
int test_early_bye(struct context *ctx);
|
||||
int test_call_hold(struct context *ctx);
|
||||
int test_reinvites(struct context *ctx);
|
||||
int test_session_timer(struct context *ctx);
|
||||
int test_refer(struct context *ctx);
|
||||
int test_100rel(struct context *ctx);
|
||||
int test_simple(struct context *ctx);
|
||||
int test_events(struct context *ctx);
|
||||
|
||||
int test_extension(struct context *ctx);
|
||||
|
||||
#endif
|
||||
@@ -1,460 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nua_api.c
|
||||
* @brief NUA API tester.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include "sofia-sip/tport_tag.h"
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_nua_api_errors"
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* API tests */
|
||||
|
||||
SOFIAPUBVAR su_log_t nua_log[];
|
||||
|
||||
int check_set_status(int status, char const *phrase)
|
||||
{
|
||||
return status == 200 && strcmp(phrase, sip_200_OK) == 0;
|
||||
}
|
||||
|
||||
int test_nua_api_errors(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
/* Invoke every API function with invalid arguments */
|
||||
|
||||
int level;
|
||||
|
||||
int status; char const *phrase;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.0: test API\n");
|
||||
|
||||
/* This is a nasty macro. Test it. */
|
||||
#define SET_STATUS1(x) ((status = x), status), (phrase = ((void)x))
|
||||
TEST_1(check_set_status(SET_STATUS1(SIP_200_OK)));
|
||||
TEST(status, 200); TEST_S(phrase, sip_200_OK);
|
||||
|
||||
su_log_init(nua_log);
|
||||
level = nua_log->log_level;
|
||||
if (!(tstflags & tst_verbatim))
|
||||
su_log_set_level(nua_log, 0); /* Log at level 0 by default */
|
||||
|
||||
TEST_1(!nua_create(NULL, NULL, NULL, TAG_END()));
|
||||
TEST_VOID(nua_shutdown(NULL));
|
||||
TEST_VOID(nua_destroy(NULL));
|
||||
TEST_VOID(nua_set_params(NULL, TAG_END()));
|
||||
TEST_VOID(nua_get_params(NULL, TAG_END()));
|
||||
TEST_1(!nua_default(NULL));
|
||||
TEST_1(!nua_handle(NULL, NULL, TAG_END()));
|
||||
TEST_VOID(nua_handle_destroy(NULL));
|
||||
TEST_VOID(nua_handle_bind(NULL, NULL));
|
||||
TEST_1(!nua_handle_has_invite(NULL));
|
||||
TEST_1(!nua_handle_has_subscribe(NULL));
|
||||
TEST_1(!nua_handle_has_register(NULL));
|
||||
TEST_1(!nua_handle_has_active_call(NULL));
|
||||
TEST_1(!nua_handle_has_call_on_hold(NULL));
|
||||
TEST_1(!nua_handle_has_events(NULL));
|
||||
TEST_1(!nua_handle_has_registrations(NULL));
|
||||
TEST_1(!nua_handle_remote(NULL));
|
||||
TEST_1(!nua_handle_local(NULL));
|
||||
TEST_S(nua_event_name(-1), "NUA_UNKNOWN");
|
||||
TEST_VOID(nua_register(NULL, TAG_END()));
|
||||
TEST_VOID(nua_unregister(NULL, TAG_END()));
|
||||
TEST_VOID(nua_invite(NULL, TAG_END()));
|
||||
TEST_VOID(nua_ack(NULL, TAG_END()));
|
||||
TEST_VOID(nua_prack(NULL, TAG_END()));
|
||||
TEST_VOID(nua_options(NULL, TAG_END()));
|
||||
TEST_VOID(nua_publish(NULL, TAG_END()));
|
||||
TEST_VOID(nua_message(NULL, TAG_END()));
|
||||
TEST_VOID(nua_chat(NULL, TAG_END()));
|
||||
TEST_VOID(nua_info(NULL, TAG_END()));
|
||||
TEST_VOID(nua_subscribe(NULL, TAG_END()));
|
||||
TEST_VOID(nua_unsubscribe(NULL, TAG_END()));
|
||||
TEST_VOID(nua_notify(NULL, TAG_END()));
|
||||
TEST_VOID(nua_notifier(NULL, TAG_END()));
|
||||
TEST_VOID(nua_terminate(NULL, TAG_END()));
|
||||
TEST_VOID(nua_refer(NULL, TAG_END()));
|
||||
TEST_VOID(nua_update(NULL, TAG_END()));
|
||||
TEST_VOID(nua_bye(NULL, TAG_END()));
|
||||
TEST_VOID(nua_cancel(NULL, TAG_END()));
|
||||
TEST_VOID(nua_authenticate(NULL, TAG_END()));
|
||||
TEST_VOID(nua_redirect(NULL, TAG_END()));
|
||||
TEST_VOID(nua_respond(NULL, 0, "", TAG_END()));
|
||||
|
||||
TEST_1(!nua_handle_home(NULL));
|
||||
TEST_1(!nua_save_event(NULL, NULL));
|
||||
TEST_1(!nua_event_data(NULL));
|
||||
TEST_VOID(nua_destroy_event(NULL));
|
||||
|
||||
{
|
||||
nua_saved_event_t event[1];
|
||||
|
||||
memset(event, 0, sizeof event);
|
||||
|
||||
TEST_1(!nua_save_event(NULL, event));
|
||||
TEST_1(!nua_event_data(event));
|
||||
TEST_VOID(nua_destroy_event(event));
|
||||
}
|
||||
|
||||
su_log_set_level(nua_log, level);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.0: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
void destroy_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
if (status >= 200) {
|
||||
nua_destroy(ctx->a.nua), ctx->a.nua = NULL;
|
||||
su_root_break(ctx->root);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test different nua_destroy() corner cases */
|
||||
int test_nua_destroy(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a;
|
||||
|
||||
TEST_1(ctx->root = su_root_create(NULL));
|
||||
|
||||
#if 0
|
||||
a->nua = nua_create(ctx->root, destroy_callback, ctx,
|
||||
NUTAG_URL("sip:0.0.0.0:*"),
|
||||
TAG_IF(ctx->a.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(a->nua);
|
||||
|
||||
nua_get_params(a->nua, TAG_ANY(), TAG_END());
|
||||
|
||||
su_root_run(ctx->root);
|
||||
|
||||
TEST_1(a->nua == NULL);
|
||||
#endif
|
||||
|
||||
a->nua = nua_create(ctx->root, destroy_callback, ctx,
|
||||
NUTAG_URL("sip:0.0.0.0:*"),
|
||||
TAG_IF(ctx->a.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(a->nua);
|
||||
|
||||
nua_shutdown(a->nua);
|
||||
|
||||
su_root_run(ctx->root);
|
||||
|
||||
TEST_1(a->nua == NULL);
|
||||
|
||||
su_root_destroy(ctx->root), ctx->root = NULL;
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
int test_byecancel_without_invite(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a, *b = &ctx->b;
|
||||
struct call *a_call = a->call;
|
||||
struct event *e;
|
||||
|
||||
int internal_error = 900;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.1: CANCEL without INVITE\n");
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
|
||||
|
||||
CANCEL(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_cancel);
|
||||
TEST(e->data->e_status, 481);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.1: PASSED\n");
|
||||
|
||||
/* -BYE without INVITE--------------------------------------------------- */
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.2: BYE without INVITE\n");
|
||||
|
||||
a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END());
|
||||
TEST_1(a_call->nh);
|
||||
|
||||
BYE(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_bye);
|
||||
TEST(e->data->e_status, internal_error);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.2: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
|
||||
int test_unregister_without_register(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a, *b = &ctx->b;
|
||||
struct call *a_call = a->call;
|
||||
struct event *e;
|
||||
|
||||
/* -Un-register without REGISTER--------------------------------------- */
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.3: unregister without register\n");
|
||||
|
||||
a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(a->to), TAG_END());
|
||||
TEST_1(a_call->nh);
|
||||
|
||||
UNREGISTER(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_unregister);
|
||||
if (e->data->e_status == 401)
|
||||
TEST(e->data->e_status, 401);
|
||||
else
|
||||
TEST(e->data->e_status, 406);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.3: PASSED\n");
|
||||
|
||||
/* -Un-publish without publish--------------------------------------- */
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.4: unpublish without publish\n");
|
||||
|
||||
a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END());
|
||||
TEST_1(a_call->nh);
|
||||
|
||||
UNPUBLISH(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_unpublish);
|
||||
TEST(e->data->e_status, 404);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.4: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
/* -terminate without notifier--------------------------------------- */
|
||||
|
||||
int test_terminate_without_notifier(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a, *b = &ctx->b;
|
||||
struct call *a_call = a->call;
|
||||
struct event *e;
|
||||
|
||||
int internal_error = 900;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.5: terminate without notifier\n");
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
|
||||
|
||||
TERMINATE(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_terminate);
|
||||
TEST(e->data->e_status, internal_error);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
AUTHORIZE(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_a_until(ctx, -1, save_until_final_response);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_authorize);
|
||||
TEST(e->data->e_status, internal_error);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.5: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
int destroy_on_503(CONDITION_PARAMS)
|
||||
{
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
|
||||
if (status == 503) {
|
||||
assert(nh == call->nh);
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
}
|
||||
|
||||
return
|
||||
nua_r_set_params <= event && event < nua_i_network_changed
|
||||
&& status >= 200;
|
||||
}
|
||||
|
||||
|
||||
int test_register_503(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a;
|
||||
struct call *a_reg = a->reg;
|
||||
struct event *e;
|
||||
|
||||
/* REGISTER test
|
||||
|
||||
A
|
||||
|------REGISTER--\
|
||||
|<-------503-----/
|
||||
|
|
||||
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.6: REGISTER with bad domain\n");
|
||||
|
||||
TEST_1(a_reg->nh = nua_handle(a->nua, a_reg, TAG_END()));
|
||||
|
||||
REGISTER(a, a_reg, a_reg->nh,
|
||||
NUTAG_REGISTRAR(URL_STRING_MAKE("sip:bad.domain")),
|
||||
SIPTAG_TO_STR("sip:lissu@bad.domain"),
|
||||
TAG_END());
|
||||
run_a_until(ctx, -1, destroy_on_503);
|
||||
|
||||
TEST_1(e = a->events->head);
|
||||
TEST_E(e->data->e_event, nua_r_register);
|
||||
TEST(e->data->e_status, 503);
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
TEST_1(a_reg->nh = nua_handle(a->nua, a_reg, TAG_END()));
|
||||
|
||||
REGISTER(a, a_reg, a_reg->nh,
|
||||
NUTAG_REGISTRAR(URL_STRING_MAKE("sip:bad.domain")),
|
||||
SIPTAG_TO_STR("sip:lissu@bad.domain"),
|
||||
TAG_END());
|
||||
nua_handle_destroy(a_reg->nh), a_reg->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2.6: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
int test_stack_errors(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2: Stack error handling\n");
|
||||
|
||||
TEST_1(ctx->root == NULL);
|
||||
TEST_1(ctx->root = su_root_create(NULL));
|
||||
|
||||
a->nua = nua_create(ctx->root, a_callback, ctx,
|
||||
NUTAG_URL("sip:0.0.0.0:*"),
|
||||
TAG_IF(ctx->a.logging, TPTAG_LOG(1)),
|
||||
TAG_END());
|
||||
TEST_1(a->nua);
|
||||
|
||||
TEST(test_byecancel_without_invite(ctx), 0);
|
||||
if (ctx->proxy_tests)
|
||||
TEST(test_unregister_without_register(ctx), 0);
|
||||
TEST(test_terminate_without_notifier(ctx), 0);
|
||||
TEST(test_register_503(ctx), 0);
|
||||
TEST(test_register_503(ctx), 0);
|
||||
|
||||
nua_shutdown(a->nua);
|
||||
|
||||
run_a_until(ctx, -1, until_final_response);
|
||||
|
||||
TEST_VOID(nua_destroy(a->nua));
|
||||
|
||||
su_root_destroy(ctx->root), ctx->root = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.2: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
@@ -1,656 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nua_params.c
|
||||
* @brief Test NUA parameter handling.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_nua_params"
|
||||
#endif
|
||||
|
||||
sip_route_t *GLOBAL_ROUTE;
|
||||
|
||||
int test_tag_filter(void)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
#undef TAG_NAMESPACE
|
||||
#define TAG_NAMESPACE "test"
|
||||
tag_typedef_t tag_a = STRTAG_TYPEDEF(a);
|
||||
#define TAG_A(s) tag_a, tag_str_v((s))
|
||||
tag_typedef_t tag_b = STRTAG_TYPEDEF(b);
|
||||
#define TAG_B(s) tag_b, tag_str_v((s))
|
||||
|
||||
tagi_t filter[2] = {{ NUTAG_ANY() }, { TAG_END() }};
|
||||
|
||||
tagi_t *lst, *result;
|
||||
|
||||
lst = tl_list(TAG_A("X"),
|
||||
TAG_SKIP(2),
|
||||
NUTAG_URL((void *)"urn:foo"),
|
||||
TAG_B("Y"),
|
||||
NUTAG_URL((void *)"urn:bar"),
|
||||
TAG_NULL());
|
||||
|
||||
TEST_1(lst);
|
||||
|
||||
result = tl_afilter(NULL, filter, lst);
|
||||
|
||||
TEST_1(result);
|
||||
TEST_P(result[0].t_tag, nutag_url);
|
||||
TEST_P(result[1].t_tag, nutag_url);
|
||||
|
||||
tl_vfree(lst);
|
||||
free(result);
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
int test_nua_params(struct context *ctx)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
char const Alice[] = "Alice <sip:a@wonderland.org>";
|
||||
sip_from_t const *from;
|
||||
su_home_t tmphome[SU_HOME_AUTO_SIZE(16384)];
|
||||
nua_handle_t *nh;
|
||||
struct event *e;
|
||||
tagi_t const *t;
|
||||
int n;
|
||||
|
||||
su_home_auto(tmphome, sizeof(tmphome));
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.1: PARAMETERS\n");
|
||||
|
||||
#if SU_HAVE_OSX_CF_API
|
||||
if (ctx->osx_runloop)
|
||||
ctx->root = su_root_osx_runloop_create(NULL);
|
||||
else
|
||||
#endif
|
||||
ctx->root = su_root_create(NULL);
|
||||
TEST_1(ctx->root);
|
||||
|
||||
su_root_threading(ctx->root, ctx->threading);
|
||||
|
||||
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
|
||||
SIPTAG_FROM_STR("sip:alice@example.com"),
|
||||
NUTAG_URL("sip:0.0.0.0:*;transport=udp"),
|
||||
TAG_END());
|
||||
|
||||
TEST_1(ctx->a.nua);
|
||||
|
||||
nua_get_params(ctx->a.nua, TAG_ANY(), TAG_END());
|
||||
run_a_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
|
||||
TEST_1(e = ctx->a.specials->head);
|
||||
TEST_E(e->data->e_event, nua_r_get_params);
|
||||
for (n = 0, t = e->data->e_tags; t; n++, t = tl_next(t))
|
||||
;
|
||||
TEST_1(n > 32);
|
||||
free_events_in_list(ctx, ctx->a.specials);
|
||||
|
||||
nh = nua_handle(ctx->a.nua, NULL, TAG_END()); TEST_1(nh);
|
||||
nua_handle_unref(nh);
|
||||
|
||||
nh = nua_handle(ctx->a.nua, NULL, TAG_END()); TEST_1(nh);
|
||||
nua_handle_destroy(nh);
|
||||
|
||||
from = sip_from_make(tmphome, Alice);
|
||||
|
||||
nh = nua_handle(ctx->a.nua, NULL, TAG_END());
|
||||
|
||||
nua_set_hparams(nh, NUTAG_INVITE_TIMER(90), TAG_END());
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
/* Modify all pointer values */
|
||||
nua_set_params(ctx->a.nua,
|
||||
SIPTAG_FROM_STR(Alice),
|
||||
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
NUTAG_SOA_NAME("test"),
|
||||
|
||||
NUTAG_REGISTRAR("sip:openlaboratory.net"),
|
||||
|
||||
SIPTAG_SUPPORTED_STR("test"),
|
||||
SIPTAG_ALLOW_STR("DWIM, OPTIONS, INFO"),
|
||||
NUTAG_APPL_METHOD(NULL),
|
||||
NUTAG_APPL_METHOD("INVITE, REGISTER, PUBLISH, SUBSCRIBE"),
|
||||
SIPTAG_ALLOW_EVENTS_STR("reg"),
|
||||
SIPTAG_USER_AGENT_STR("test_nua/1.0"),
|
||||
|
||||
SIPTAG_ORGANIZATION_STR("Open Laboratory"),
|
||||
|
||||
NUTAG_M_DISPLAY("XXX"),
|
||||
NUTAG_M_USERNAME("xxx"),
|
||||
NUTAG_M_PARAMS("user=ip"),
|
||||
NUTAG_M_FEATURES("language=\"fi\""),
|
||||
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);
|
||||
|
||||
/* Modify everything from their default value */
|
||||
nua_set_params(ctx->a.nua,
|
||||
SIPTAG_FROM(from),
|
||||
NUTAG_RETRY_COUNT(9),
|
||||
NUTAG_MAX_SUBSCRIPTIONS(6),
|
||||
|
||||
NUTAG_ENABLEINVITE(0),
|
||||
NUTAG_AUTOALERT(1),
|
||||
NUTAG_EARLY_MEDIA(1),
|
||||
NUTAG_AUTOANSWER(1),
|
||||
NUTAG_AUTOACK(0),
|
||||
NUTAG_INVITE_TIMER(60),
|
||||
|
||||
NUTAG_SESSION_TIMER(600),
|
||||
NUTAG_MIN_SE(35),
|
||||
NUTAG_SESSION_REFRESHER(nua_remote_refresher),
|
||||
NUTAG_UPDATE_REFRESH(1),
|
||||
|
||||
NUTAG_ENABLEMESSAGE(0),
|
||||
NUTAG_ENABLEMESSENGER(1),
|
||||
/* NUTAG_MESSAGE_AUTOANSWER(0), */
|
||||
|
||||
NUTAG_CALLEE_CAPS(1),
|
||||
NUTAG_MEDIA_FEATURES(1),
|
||||
NUTAG_SERVICE_ROUTE_ENABLE(0),
|
||||
NUTAG_PATH_ENABLE(0),
|
||||
NUTAG_AUTH_CACHE(nua_auth_cache_challenged),
|
||||
NUTAG_REFER_EXPIRES(333),
|
||||
NUTAG_REFER_WITH_ID(0),
|
||||
NUTAG_SUBSTATE(nua_substate_pending),
|
||||
NUTAG_SUB_EXPIRES(3700),
|
||||
|
||||
NUTAG_KEEPALIVE(66),
|
||||
NUTAG_KEEPALIVE_STREAM(33),
|
||||
|
||||
NUTAG_INSTANCE("urn:uuid:97701ad9-39df-1229-1083-dbc0a85f029c"),
|
||||
NUTAG_M_DISPLAY("Joe"),
|
||||
NUTAG_M_USERNAME("joe"),
|
||||
NUTAG_M_PARAMS("user=phone"),
|
||||
NUTAG_M_FEATURES("language=\"en\""),
|
||||
NUTAG_OUTBOUND("foo"),
|
||||
SIPTAG_SUPPORTED(sip_supported_make(tmphome, "foo")),
|
||||
NUTAG_SUPPORTED("foo, bar"),
|
||||
SIPTAG_SUPPORTED_STR(",baz,"),
|
||||
|
||||
SIPTAG_ALLOW_STR("OPTIONS"),
|
||||
SIPTAG_ALLOW(sip_allow_make(tmphome, "INFO")),
|
||||
NUTAG_ALLOW("ACK, INFO"),
|
||||
|
||||
NUTAG_APPL_METHOD("NOTIFY"),
|
||||
|
||||
SIPTAG_ALLOW_EVENTS_STR("reg"),
|
||||
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")),
|
||||
|
||||
SIPTAG_ORGANIZATION(sip_organization_make(tmphome, "Pussy Galore's Flying Circus")),
|
||||
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
NUTAG_REGISTRAR(url_hdup(tmphome, (url_t *)"sip:sip.wonderland.org")),
|
||||
|
||||
TAG_END());
|
||||
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
/* Modify something... */
|
||||
nua_set_params(ctx->a.nua,
|
||||
NUTAG_RETRY_COUNT(5),
|
||||
TAG_END());
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
{
|
||||
sip_from_t const *from = NONE;
|
||||
char const *from_str = "NONE";
|
||||
|
||||
unsigned retry_count = (unsigned)-1;
|
||||
unsigned max_subscriptions = (unsigned)-1;
|
||||
|
||||
char const *soa_name = "NONE";
|
||||
int media_enable = -1;
|
||||
int invite_enable = -1;
|
||||
int auto_alert = -1;
|
||||
int early_media = -1;
|
||||
int only183_100rel = -1;
|
||||
int auto_answer = -1;
|
||||
int auto_ack = -1;
|
||||
unsigned invite_timeout = (unsigned)-1;
|
||||
|
||||
unsigned session_timer = (unsigned)-1;
|
||||
unsigned min_se = (unsigned)-1;
|
||||
int refresher = -1;
|
||||
int update_refresh = -1;
|
||||
|
||||
int message_enable = -1;
|
||||
int win_messenger_enable = -1;
|
||||
int message_auto_respond = -1;
|
||||
|
||||
int callee_caps = -1;
|
||||
int media_features = -1;
|
||||
int service_route_enable = -1;
|
||||
int path_enable = -1;
|
||||
int auth_cache = -1;
|
||||
unsigned refer_expires = (unsigned)-1;
|
||||
int refer_with_id = -1;
|
||||
unsigned sub_expires = (unsigned)-1;
|
||||
int substate = -1;
|
||||
|
||||
sip_allow_t const *allow = NONE;
|
||||
char const *allow_str = "NONE";
|
||||
char const *appl_method = "NONE";
|
||||
sip_allow_events_t const *allow_events = NONE;
|
||||
char const *allow_events_str = "NONE";
|
||||
sip_supported_t const *supported = NONE;
|
||||
char const *supported_str = "NONE";
|
||||
sip_user_agent_t const *user_agent = NONE;
|
||||
char const *user_agent_str = "NONE";
|
||||
char const *ua_name = "NONE";
|
||||
sip_organization_t const *organization = NONE;
|
||||
char const *organization_str = "NONE";
|
||||
|
||||
sip_route_t const *initial_route = NONE;
|
||||
char const *initial_route_str = NONE;
|
||||
|
||||
char const *outbound = "NONE";
|
||||
char const *m_display = "NONE";
|
||||
char const *m_username = "NONE";
|
||||
char const *m_params = "NONE";
|
||||
char const *m_features = "NONE";
|
||||
char const *instance = "NONE";
|
||||
|
||||
url_string_t const *registrar = NONE;
|
||||
unsigned keepalive = (unsigned)-1, keepalive_stream = (unsigned)-1;
|
||||
|
||||
nua_get_params(ctx->a.nua, TAG_ANY(), TAG_END());
|
||||
run_a_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
|
||||
TEST_1(e = ctx->a.specials->head);
|
||||
TEST_E(e->data->e_event, nua_r_get_params);
|
||||
|
||||
n = tl_gets(e->data->e_tags,
|
||||
SIPTAG_FROM_REF(from),
|
||||
SIPTAG_FROM_STR_REF(from_str),
|
||||
|
||||
NUTAG_RETRY_COUNT_REF(retry_count),
|
||||
NUTAG_MAX_SUBSCRIPTIONS_REF(max_subscriptions),
|
||||
|
||||
NUTAG_SOA_NAME_REF(soa_name),
|
||||
NUTAG_MEDIA_ENABLE_REF(media_enable),
|
||||
NUTAG_ENABLEINVITE_REF(invite_enable),
|
||||
NUTAG_AUTOALERT_REF(auto_alert),
|
||||
NUTAG_EARLY_MEDIA_REF(early_media),
|
||||
NUTAG_ONLY183_100REL_REF(only183_100rel),
|
||||
NUTAG_AUTOANSWER_REF(auto_answer),
|
||||
NUTAG_AUTOACK_REF(auto_ack),
|
||||
NUTAG_INVITE_TIMER_REF(invite_timeout),
|
||||
|
||||
NUTAG_SESSION_TIMER_REF(session_timer),
|
||||
NUTAG_MIN_SE_REF(min_se),
|
||||
NUTAG_SESSION_REFRESHER_REF(refresher),
|
||||
NUTAG_UPDATE_REFRESH_REF(update_refresh),
|
||||
|
||||
NUTAG_ENABLEMESSAGE_REF(message_enable),
|
||||
NUTAG_ENABLEMESSENGER_REF(win_messenger_enable),
|
||||
/* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond), */
|
||||
|
||||
NUTAG_CALLEE_CAPS_REF(callee_caps),
|
||||
NUTAG_MEDIA_FEATURES_REF(media_features),
|
||||
NUTAG_SERVICE_ROUTE_ENABLE_REF(service_route_enable),
|
||||
NUTAG_PATH_ENABLE_REF(path_enable),
|
||||
NUTAG_AUTH_CACHE_REF(auth_cache),
|
||||
NUTAG_REFER_EXPIRES_REF(refer_expires),
|
||||
NUTAG_REFER_WITH_ID_REF(refer_with_id),
|
||||
NUTAG_SUBSTATE_REF(substate),
|
||||
NUTAG_SUB_EXPIRES_REF(sub_expires),
|
||||
|
||||
SIPTAG_SUPPORTED_REF(supported),
|
||||
SIPTAG_SUPPORTED_STR_REF(supported_str),
|
||||
SIPTAG_ALLOW_REF(allow),
|
||||
SIPTAG_ALLOW_STR_REF(allow_str),
|
||||
NUTAG_APPL_METHOD_REF(appl_method),
|
||||
SIPTAG_ALLOW_EVENTS_REF(allow_events),
|
||||
SIPTAG_ALLOW_EVENTS_STR_REF(allow_events_str),
|
||||
SIPTAG_USER_AGENT_REF(user_agent),
|
||||
SIPTAG_USER_AGENT_STR_REF(user_agent_str),
|
||||
NUTAG_USER_AGENT_REF(ua_name),
|
||||
|
||||
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),
|
||||
|
||||
NUTAG_OUTBOUND_REF(outbound),
|
||||
NUTAG_M_DISPLAY_REF(m_display),
|
||||
NUTAG_M_USERNAME_REF(m_username),
|
||||
NUTAG_M_PARAMS_REF(m_params),
|
||||
NUTAG_M_FEATURES_REF(m_features),
|
||||
NUTAG_INSTANCE_REF(instance),
|
||||
|
||||
TAG_END());
|
||||
TEST(n, 51);
|
||||
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)from), Alice);
|
||||
TEST_S(from_str, Alice);
|
||||
|
||||
TEST(retry_count, 5);
|
||||
TEST(max_subscriptions, 6);
|
||||
|
||||
TEST_S(soa_name, "test");
|
||||
TEST(media_enable, 0);
|
||||
TEST(invite_enable, 0);
|
||||
TEST(auto_alert, 1);
|
||||
TEST(early_media, 1);
|
||||
TEST(auto_answer, 1);
|
||||
TEST(auto_ack, 0);
|
||||
TEST(invite_timeout, 60);
|
||||
|
||||
TEST(session_timer, 600);
|
||||
TEST(min_se, 35);
|
||||
TEST(refresher, nua_remote_refresher);
|
||||
TEST(update_refresh, 1);
|
||||
|
||||
TEST(message_enable, 0);
|
||||
TEST(win_messenger_enable, 1);
|
||||
TEST(message_auto_respond, -1); /* XXX */
|
||||
|
||||
TEST(callee_caps, 1);
|
||||
TEST(media_features, 1);
|
||||
TEST(service_route_enable, 0);
|
||||
TEST(path_enable, 0);
|
||||
TEST(auth_cache, nua_auth_cache_challenged);
|
||||
TEST(refer_expires, 333);
|
||||
TEST(refer_with_id, 0);
|
||||
TEST(substate, nua_substate_pending);
|
||||
TEST(sub_expires, 3700);
|
||||
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)allow), "OPTIONS, INFO, ACK");
|
||||
TEST_S(allow_str, "OPTIONS, INFO, ACK");
|
||||
TEST_S(appl_method, "INVITE, REGISTER, PUBLISH, SUBSCRIBE, NOTIFY");
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)allow_events),
|
||||
"reg, presence, presence.winfo");
|
||||
TEST_S(allow_events_str, "reg, presence, presence.winfo");
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)supported),
|
||||
"foo, bar, baz");
|
||||
TEST_S(supported_str, "foo, bar, baz");
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)user_agent), "test_nua");
|
||||
TEST_S(user_agent_str, "test_nua");
|
||||
TEST_S(sip_header_as_string(tmphome, (void *)organization),
|
||||
"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);
|
||||
TEST(keepalive_stream, 33);
|
||||
|
||||
TEST_S(instance, "urn:uuid:97701ad9-39df-1229-1083-dbc0a85f029c");
|
||||
TEST_S(m_display, "Joe");
|
||||
TEST_S(m_username, "joe");
|
||||
TEST_S(m_params, "user=phone");
|
||||
{ char const *expect_m_features = "language=\"en\"";
|
||||
TEST_S(m_features, expect_m_features); }
|
||||
TEST_S(outbound, "foo");
|
||||
|
||||
free_events_in_list(ctx, ctx->a.specials);
|
||||
}
|
||||
|
||||
/* Test that only those tags that have been set per handle are returned by nua_get_hparams() */
|
||||
|
||||
{
|
||||
sip_from_t const *from = NONE;
|
||||
char const *from_str = "NONE";
|
||||
|
||||
unsigned retry_count = (unsigned)-1;
|
||||
unsigned max_subscriptions = (unsigned)-1;
|
||||
|
||||
int invite_enable = -1;
|
||||
int auto_alert = -1;
|
||||
int early_media = -1;
|
||||
int auto_answer = -1;
|
||||
int auto_ack = -1;
|
||||
unsigned invite_timeout = (unsigned)-1;
|
||||
|
||||
unsigned session_timer = (unsigned)-1;
|
||||
unsigned min_se = (unsigned)-1;
|
||||
int refresher = -1;
|
||||
int update_refresh = -1;
|
||||
|
||||
int message_enable = -1;
|
||||
int win_messenger_enable = -1;
|
||||
int message_auto_respond = -1;
|
||||
|
||||
int callee_caps = -1;
|
||||
int media_features = -1;
|
||||
int service_route_enable = -1;
|
||||
int path_enable = -1;
|
||||
int auth_cache = -1;
|
||||
unsigned refer_expires = (unsigned)-1;
|
||||
int refer_with_id = -1;
|
||||
int substate = -1;
|
||||
unsigned sub_expires = (unsigned)-1;
|
||||
|
||||
sip_allow_t const *allow = NONE;
|
||||
char const *allow_str = "NONE";
|
||||
sip_supported_t const *supported = NONE;
|
||||
char const *supported_str = "NONE";
|
||||
sip_user_agent_t const *user_agent = NONE;
|
||||
char const *user_agent_str = "NONE";
|
||||
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";
|
||||
char const *m_display = "NONE";
|
||||
char const *m_username = "NONE";
|
||||
char const *m_params = "NONE";
|
||||
char const *m_features = "NONE";
|
||||
char const *instance = "NONE";
|
||||
|
||||
int n;
|
||||
struct event *e;
|
||||
|
||||
nua_get_hparams(nh, TAG_ANY(), TAG_END());
|
||||
run_a_until(ctx, nua_r_get_params, save_until_final_response);
|
||||
|
||||
TEST_1(e = ctx->a.events->head);
|
||||
TEST_E(e->data->e_event, nua_r_get_params);
|
||||
|
||||
n = tl_gets(e->data->e_tags,
|
||||
SIPTAG_FROM_REF(from),
|
||||
SIPTAG_FROM_STR_REF(from_str),
|
||||
|
||||
NUTAG_RETRY_COUNT_REF(retry_count),
|
||||
NUTAG_MAX_SUBSCRIPTIONS_REF(max_subscriptions),
|
||||
|
||||
NUTAG_ENABLEINVITE_REF(invite_enable),
|
||||
NUTAG_AUTOALERT_REF(auto_alert),
|
||||
NUTAG_EARLY_MEDIA_REF(early_media),
|
||||
NUTAG_AUTOANSWER_REF(auto_answer),
|
||||
NUTAG_AUTOACK_REF(auto_ack),
|
||||
NUTAG_INVITE_TIMER_REF(invite_timeout),
|
||||
|
||||
NUTAG_SESSION_TIMER_REF(session_timer),
|
||||
NUTAG_MIN_SE_REF(min_se),
|
||||
NUTAG_SESSION_REFRESHER_REF(refresher),
|
||||
NUTAG_UPDATE_REFRESH_REF(update_refresh),
|
||||
|
||||
NUTAG_ENABLEMESSAGE_REF(message_enable),
|
||||
NUTAG_ENABLEMESSENGER_REF(win_messenger_enable),
|
||||
/* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond), */
|
||||
|
||||
NUTAG_CALLEE_CAPS_REF(callee_caps),
|
||||
NUTAG_MEDIA_FEATURES_REF(media_features),
|
||||
NUTAG_SERVICE_ROUTE_ENABLE_REF(service_route_enable),
|
||||
NUTAG_PATH_ENABLE_REF(path_enable),
|
||||
NUTAG_AUTH_CACHE_REF(auth_cache),
|
||||
NUTAG_SUBSTATE_REF(substate),
|
||||
NUTAG_SUB_EXPIRES_REF(sub_expires),
|
||||
|
||||
SIPTAG_SUPPORTED_REF(supported),
|
||||
SIPTAG_SUPPORTED_STR_REF(supported_str),
|
||||
SIPTAG_ALLOW_REF(allow),
|
||||
SIPTAG_ALLOW_STR_REF(allow_str),
|
||||
SIPTAG_USER_AGENT_REF(user_agent),
|
||||
SIPTAG_USER_AGENT_STR_REF(user_agent_str),
|
||||
|
||||
SIPTAG_ORGANIZATION_REF(organization),
|
||||
SIPTAG_ORGANIZATION_STR_REF(organization_str),
|
||||
|
||||
NUTAG_OUTBOUND_REF(outbound),
|
||||
NUTAG_M_DISPLAY_REF(m_display),
|
||||
NUTAG_M_USERNAME_REF(m_username),
|
||||
NUTAG_M_PARAMS_REF(m_params),
|
||||
NUTAG_M_FEATURES_REF(m_features),
|
||||
NUTAG_INSTANCE_REF(instance),
|
||||
|
||||
NUTAG_REGISTRAR_REF(registrar),
|
||||
|
||||
TAG_END());
|
||||
TEST(n, 3);
|
||||
|
||||
TEST(invite_timeout, 90);
|
||||
|
||||
TEST_1(from != NULL && from != NONE);
|
||||
TEST_1(strcmp(from_str, "NONE"));
|
||||
|
||||
/* Nothing else should be set */
|
||||
TEST(retry_count, (unsigned)-1);
|
||||
TEST(max_subscriptions, (unsigned)-1);
|
||||
|
||||
TEST(invite_enable, -1);
|
||||
TEST(auto_alert, -1);
|
||||
TEST(early_media, -1);
|
||||
TEST(auto_answer, -1);
|
||||
TEST(auto_ack, -1);
|
||||
|
||||
TEST(session_timer, (unsigned)-1);
|
||||
TEST(min_se, (unsigned)-1);
|
||||
TEST(refresher, -1);
|
||||
TEST(update_refresh, -1);
|
||||
|
||||
TEST(message_enable, -1);
|
||||
TEST(win_messenger_enable, -1);
|
||||
TEST(message_auto_respond, -1); /* XXX */
|
||||
|
||||
TEST(callee_caps, -1);
|
||||
TEST(media_features, -1);
|
||||
TEST(service_route_enable, -1);
|
||||
TEST(path_enable, -1);
|
||||
TEST(auth_cache, -1);
|
||||
TEST(refer_expires, (unsigned)-1);
|
||||
TEST(refer_with_id, -1);
|
||||
TEST(substate, -1);
|
||||
TEST(sub_expires, -1);
|
||||
|
||||
TEST_P(allow, NONE);
|
||||
TEST_S(allow_str, "NONE");
|
||||
TEST_P(supported, NONE);
|
||||
TEST_S(supported_str, "NONE");
|
||||
TEST_P(user_agent, NONE);
|
||||
TEST_S(user_agent_str, "NONE");
|
||||
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");
|
||||
TEST_S(m_params, "NONE");
|
||||
TEST_S(m_features, "NONE");
|
||||
TEST_S(instance, "NONE");
|
||||
|
||||
TEST_P(registrar->us_url, NONE);
|
||||
|
||||
free_events_in_list(ctx, ctx->a.events);
|
||||
}
|
||||
|
||||
nua_handle_destroy(nh);
|
||||
|
||||
nua_shutdown(ctx->a.nua);
|
||||
run_a_until(ctx, nua_r_shutdown, until_final_response);
|
||||
nua_destroy(ctx->a.nua), ctx->a.nua = NULL;
|
||||
|
||||
su_root_destroy(ctx->root), ctx->root = NULL;
|
||||
|
||||
su_home_deinit(tmphome);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-1.1: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
@@ -1,479 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_offer_answer.c
|
||||
* @brief Test offer/answer failures.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_offer_answer"
|
||||
#endif
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
/* Send offer in INVITE, no answer:
|
||||
|
||||
A B
|
||||
--nua_invite()-->| |
|
||||
|-------INVITE------>|
|
||||
<--nua_i_state---| |
|
||||
|<----100 Trying-----|
|
||||
| |
|
||||
|<--------180--------|
|
||||
<--nua_r_invite--| |
|
||||
<--nua_i_state---| |
|
||||
|<------200 OK-------|
|
||||
<--nua_r_invite--| |
|
||||
|--------ACK-------->|
|
||||
|--------BYE-------->|
|
||||
<--nua_i_state---| |
|
||||
|<-------200 OK------|
|
||||
<--nua_r_bye-----| |
|
||||
<--nua_i_state---| |
|
||||
|
||||
Client transitions:
|
||||
INIT -(C1)-> CALLING -(C2a)-> PROCEEDING -(C3+C4)->
|
||||
TERMINATING -> TERMINATED
|
||||
Server transitions:
|
||||
INIT -(S1)-> RECEIVED -(S2a)-> EARLY -(S3b)-> COMPLETED -(S4)-> READY
|
||||
-> TERMINATED
|
||||
|
||||
*/
|
||||
|
||||
int no_media_terminated(CONDITION_PARAMS);
|
||||
|
||||
int test_no_answer_1(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;
|
||||
sip_t *sip;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-6.5: No SDP answer from callee\n");
|
||||
|
||||
a_call->sdp = "m=audio 5008 RTP/AVP 8";
|
||||
b_call->sdp = NULL;
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
INVITE(a, a_call, a_call->nh,
|
||||
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
SOATAG_USER_SDP_STR(a_call->sdp),
|
||||
NUTAG_M_USERNAME("a+a"),
|
||||
NUTAG_M_DISPLAY("Alice"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_terminated, -1, no_media_terminated);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(b_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(b_call->nh));
|
||||
|
||||
/* Client transitions:
|
||||
INIT -(C1)-> CALLING: nua_invite(), nua_i_state
|
||||
CALLING -(C3)-> PROCEEDING: nua_r_invite, nua_i_state
|
||||
PROCEEDING -(C3a+C5)-> TERMINATING: nua_r_invite, nua_i_state
|
||||
TERMINATING -(C12)-> TERMINATED: nua_r_bye, nua_i_state
|
||||
*/
|
||||
TEST_1(e = a->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, 180);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(!sip->sip_payload);
|
||||
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(!is_answer_recv(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(!sip->sip_payload);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_media_error);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
|
||||
TEST(callstate(e->data->e_tags), nua_callstate_terminating); /* TERMINATING */
|
||||
TEST_1(e = e->next); 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, a->events);
|
||||
|
||||
/*
|
||||
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
|
||||
READY -(T1)-> 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);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_contact);
|
||||
TEST_S(sip->sip_contact->m_display, "Alice");
|
||||
TEST_S(sip->sip_contact->m_url->url_user, "a+a");
|
||||
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));
|
||||
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_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(sip = sip_object(e->data->e_msg));
|
||||
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(!is_offer_recv(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_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, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_active_call(b_call->nh));
|
||||
|
||||
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-6.5: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
int no_media_terminated(CONDITION_PARAMS)
|
||||
{
|
||||
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
|
||||
return 0;
|
||||
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
|
||||
switch (callstate(tags)) {
|
||||
case nua_callstate_received:
|
||||
RESPOND(ep, call, nh, SIP_180_RINGING,
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
TAG_END());
|
||||
return 0;
|
||||
case nua_callstate_early:
|
||||
RESPOND(ep, call, nh, SIP_200_OK,
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
TAG_END());
|
||||
return 0;
|
||||
case nua_callstate_terminated:
|
||||
if (call)
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int accept_call_until_terminated(CONDITION_PARAMS);
|
||||
|
||||
/* No offer in INVITE, offer in 200 OK, no answer in ACK */
|
||||
int test_no_answer_2(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;
|
||||
sip_t const *sip;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-6.6: No SDP offer from caller\n");
|
||||
|
||||
a_call->sdp = "v=0\r\n"
|
||||
"o=- 1 1 IN IP4 127.0.0.1\r\n"
|
||||
"s=-\r\n"
|
||||
"c=IN IP4 127.0.0.1\r\n"
|
||||
"t=0 0\r\n"
|
||||
"m=audio 5008 RTP/AVP 8\r\n";
|
||||
|
||||
b_call->sdp =
|
||||
"v=0\r\n"
|
||||
"o=- 2 1 IN IP4 127.0.0.1\r\n"
|
||||
"s=-\r\n"
|
||||
"c=IN IP4 127.0.0.1\r\n"
|
||||
"t=0 0\r\n"
|
||||
"m=audio 5010 RTP/AVP 0 8\r\n";
|
||||
|
||||
TEST_1(a_call->nh = nua_handle(a->nua, a_call,
|
||||
SIPTAG_TO_STR("<sip:b@x.org>"),
|
||||
TAG_END()));
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
INVITE(a, a_call, a_call->nh,
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
NUTAG_URL(b->contact->m_url),
|
||||
NUTAG_AUTOACK(1),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_terminated,
|
||||
-1, accept_call_until_terminated);
|
||||
|
||||
/* 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->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, 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(!is_answer_recv(e->data->e_tags));
|
||||
TEST_1(!is_offer_recv(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/sdp");
|
||||
TEST_1(sip->sip_payload); /* there is sdp in 200 OK */
|
||||
TEST_1(sip->sip_contact);
|
||||
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_sent(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_bye);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
|
||||
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* READY */
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
/*
|
||||
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->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 */
|
||||
TEST_1(!is_offer_recv(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_early); /* EARLY */
|
||||
TEST_1(!is_answer_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_completed); /* COMPLETED */
|
||||
TEST_1(is_offer_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_media_error);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
|
||||
TEST(callstate(e->data->e_tags), nua_callstate_terminating); /* TERMINATING */
|
||||
TEST_1(e = e->next); 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->events);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(b_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(b_call->nh));
|
||||
|
||||
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-6.6: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
int accept_call_until_terminated(CONDITION_PARAMS)
|
||||
{
|
||||
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
|
||||
return 0;
|
||||
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
|
||||
switch (callstate(tags)) {
|
||||
case nua_callstate_received:
|
||||
RESPOND(ep, call, nh, SIP_180_RINGING,
|
||||
TAG_END());
|
||||
return 0;
|
||||
case nua_callstate_early:
|
||||
RESPOND(ep, call, nh, SIP_200_OK,
|
||||
NUTAG_MEDIA_ENABLE(1),
|
||||
TAG_IF(call->sdp, SOATAG_USER_SDP_STR(call->sdp)),
|
||||
TAG_END());
|
||||
return 0;
|
||||
case nua_callstate_terminated:
|
||||
if (call)
|
||||
nua_handle_destroy(call->nh), call->nh = NULL;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* No offer in INVITE, no user SDP in 200 OK */
|
||||
int test_missing_user_sdp(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-6.6.2: No SDP offer from caller\n");
|
||||
|
||||
a_call->sdp = "v=0\r\n"
|
||||
"o=- 1 1 IN IP4 127.0.0.1\r\n"
|
||||
"s=-\r\n"
|
||||
"c=IN IP4 127.0.0.1\r\n"
|
||||
"t=0 0\r\n"
|
||||
"m=audio 5008 RTP/AVP 8\r\n";
|
||||
|
||||
b_call->sdp = NULL;
|
||||
|
||||
nua_set_params(b->nua, NUTAG_MEDIA_ENABLE(0), 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_STR("<sip:b@x.org>"),
|
||||
TAG_END()));
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
INVITE(a, a_call, a_call->nh,
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
NUTAG_URL(b->contact->m_url),
|
||||
NUTAG_AUTOACK(1),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_terminated,
|
||||
-1, accept_call_until_terminated);
|
||||
|
||||
/* 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->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, 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(!is_answer_recv(e->data->e_tags));
|
||||
TEST_1(!is_offer_recv(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
|
||||
TEST(e->data->e_status, 500);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
|
||||
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* READY */
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(a_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
|
||||
|
||||
/*
|
||||
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->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 */
|
||||
TEST_1(!is_offer_recv(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_early); /* EARLY */
|
||||
TEST_1(!is_answer_sent(e->data->e_tags));
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_error);
|
||||
TEST(e->data->e_status, 500);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
|
||||
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* COMPLETED */
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
TEST_1(!nua_handle_has_active_call(b_call->nh));
|
||||
TEST_1(!nua_handle_has_call_on_hold(b_call->nh));
|
||||
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
nua_set_params(b->nua,
|
||||
NUTAG_MEDIA_ENABLE(1),
|
||||
SOATAG_USER_SDP_STR("m=audio 5006 RTP/AVP 8 0"),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-6.6.2: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int test_offer_answer(struct context *ctx)
|
||||
{
|
||||
return
|
||||
test_no_answer_1(ctx) ||
|
||||
test_no_answer_2(ctx) ||
|
||||
test_missing_user_sdp(ctx) ||
|
||||
0;
|
||||
}
|
||||
@@ -1,566 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_ops.c
|
||||
* @brief High-level test framework for Sofia SIP User Agent Engine
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ name
|
||||
#endif
|
||||
|
||||
int save_events(CONDITION_PARAMS)
|
||||
{
|
||||
return save_event_in_list(ctx, event, ep, call) == event_is_normal;
|
||||
}
|
||||
|
||||
int until_final_response(CONDITION_PARAMS)
|
||||
{
|
||||
return status >= 200;
|
||||
}
|
||||
|
||||
int save_until_final_response(CONDITION_PARAMS)
|
||||
{
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
return
|
||||
nua_r_set_params <= event && event < nua_i_network_changed
|
||||
&& status >= 200;
|
||||
}
|
||||
|
||||
/** Save events.
|
||||
*
|
||||
* Terminate when a event is saved.
|
||||
*/
|
||||
int save_until_received(CONDITION_PARAMS)
|
||||
{
|
||||
return save_event_in_list(ctx, event, ep, call) == event_is_normal;
|
||||
}
|
||||
|
||||
/** Save events until nua_i_outbound is received. */
|
||||
int save_until_special(CONDITION_PARAMS)
|
||||
{
|
||||
return save_event_in_list(ctx, event, ep, call) == event_is_special;
|
||||
}
|
||||
|
||||
/* Return call state from event tag list */
|
||||
int callstate(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, nutag_callstate);
|
||||
return ti ? ti->t_value : -1;
|
||||
}
|
||||
|
||||
/* Return true if offer is sent */
|
||||
int is_offer_sent(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, nutag_offer_sent);
|
||||
return ti ? ti->t_value : 0;
|
||||
}
|
||||
|
||||
/* Return true if answer is sent */
|
||||
int is_answer_sent(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, nutag_answer_sent);
|
||||
return ti ? ti->t_value : 0;
|
||||
}
|
||||
|
||||
/* Return true if offer is recv */
|
||||
int is_offer_recv(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, nutag_offer_recv);
|
||||
return ti ? ti->t_value : 0;
|
||||
}
|
||||
|
||||
/* Return true if answer is recv */
|
||||
int is_answer_recv(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, nutag_answer_recv);
|
||||
return ti ? ti->t_value : 0;
|
||||
}
|
||||
|
||||
/* Return true if offer/answer is sent/recv */
|
||||
int is_offer_answer_done(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti;
|
||||
|
||||
return
|
||||
((ti = tl_find(tags, nutag_answer_recv)) && ti->t_value) ||
|
||||
((ti = tl_find(tags, nutag_offer_sent)) && ti->t_value) ||
|
||||
((ti = tl_find(tags, nutag_offer_recv)) && ti->t_value) ||
|
||||
((ti = tl_find(tags, nutag_answer_sent)) && ti->t_value);
|
||||
}
|
||||
|
||||
/* Return audio state from event tag list */
|
||||
int audio_activity(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, soatag_active_audio);
|
||||
return ti ? ti->t_value : -1;
|
||||
}
|
||||
|
||||
/* Return video state from event tag list */
|
||||
int video_activity(tagi_t const *tags)
|
||||
{
|
||||
tagi_t const *ti = tl_find(tags, soatag_active_video);
|
||||
return ti ? ti->t_value : -1;
|
||||
}
|
||||
|
||||
void print_event(nua_event_t event,
|
||||
char const *operation,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
struct endpoint *ep,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
tagi_t const *t;
|
||||
static su_nanotime_t started = 0;
|
||||
su_nanotime_t now;
|
||||
char timestamp[32];
|
||||
|
||||
su_nanotime(&now);
|
||||
|
||||
if (started == 0) started = now;
|
||||
|
||||
now -= started; now /= 1000000;
|
||||
|
||||
snprintf(timestamp, sizeof timestamp, "%03u.%03u",
|
||||
(unsigned)(now / 1000), (unsigned)(now % 1000));
|
||||
|
||||
if (event == nua_i_state) {
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s %s\n", timestamp,
|
||||
ep->name, (void *)nh, nua_event_name(event),
|
||||
nua_callstate_name(callstate(tags)));
|
||||
}
|
||||
else if ((int)event >= nua_r_set_params) {
|
||||
t = tl_find(tags, nutag_substate);
|
||||
if (t) {
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s status %u %s (%s)\n", timestamp,
|
||||
ep->name, (void*)nh, nua_event_name(event), status, phrase,
|
||||
nua_substate_name(t->t_value));
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s status %u %s\n", timestamp,
|
||||
ep->name, (void *)nh, nua_event_name(event), status, phrase);
|
||||
}
|
||||
}
|
||||
else if (event == nua_i_notify) {
|
||||
t = tl_find(tags, nutag_substate);
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s %s (%s)\n", timestamp,
|
||||
ep->name, (void *)nh, nua_event_name(event), phrase,
|
||||
nua_substate_name(t ? t->t_value : 0));
|
||||
}
|
||||
else if ((int)event >= nua_i_bye ||
|
||||
event == nua_i_invite || event == nua_i_cancel ||
|
||||
event == nua_i_ack) {
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s %03d %s\n", timestamp,
|
||||
ep->name, (void *)nh, nua_event_name(event), status, phrase);
|
||||
}
|
||||
else if ((int)event >= 0) {
|
||||
fprintf(stderr, "%s %s.nua(%p): event %s %s\n", timestamp,
|
||||
ep->name, (void *)nh, nua_event_name(event), phrase);
|
||||
}
|
||||
else if (status > 0) {
|
||||
fprintf(stderr, "%s %s.nua(%p): call %s() with status %u %s\n", timestamp,
|
||||
ep->name, (void *)nh, operation, status, phrase);
|
||||
}
|
||||
else {
|
||||
t = tl_find(tags, siptag_subject_str);
|
||||
if (t && t->t_value) {
|
||||
char const *subject = (char const *)t->t_value;
|
||||
fprintf(stderr, "%s %s.nua(%p): call %s() \"%s\"\n", timestamp,
|
||||
ep->name, (void *)nh, operation, subject);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "%s %s.nua(%p): call %s()\n", timestamp,
|
||||
ep->name, (void *)nh, operation);
|
||||
}
|
||||
|
||||
if (tags &&
|
||||
((tstflags & tst_verbatim) || ctx->print_tags || ep->print_tags))
|
||||
tl_print(stderr, "", tags);
|
||||
}
|
||||
|
||||
void ep_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
struct endpoint *ep,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
if (ep->printer)
|
||||
ep->printer(event, "", status, phrase, nua, ctx, ep, nh, call, sip, tags);
|
||||
|
||||
if (call == NULL && nh) {
|
||||
for (call = ep->call; call; call = call->next) {
|
||||
if (!call->nh)
|
||||
break;
|
||||
if (nh == call->nh)
|
||||
break;
|
||||
}
|
||||
|
||||
if (call && call->nh == NULL) {
|
||||
call->nh = nh;
|
||||
nua_handle_bind(nh, call);
|
||||
}
|
||||
}
|
||||
|
||||
if ((ep->next_condition == NULL ||
|
||||
ep->next_condition(event, status, phrase,
|
||||
nua, ctx, ep, nh, call, sip, tags))
|
||||
&&
|
||||
(ep->next_event == -1 || ep->next_event == event))
|
||||
ep->running = 0;
|
||||
|
||||
ep->last_event = event;
|
||||
|
||||
if (call == NULL && nh)
|
||||
nua_handle_destroy(nh);
|
||||
}
|
||||
|
||||
void a_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
ep_callback(event, status, phrase, nua, ctx, &ctx->a, nh, call, sip, tags);
|
||||
}
|
||||
|
||||
void b_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
ep_callback(event, status, phrase, nua, ctx, &ctx->b, nh, call, sip, tags);
|
||||
}
|
||||
|
||||
void c_callback(nua_event_t event,
|
||||
int status, char const *phrase,
|
||||
nua_t *nua, struct context *ctx,
|
||||
nua_handle_t *nh, struct call *call,
|
||||
sip_t const *sip,
|
||||
tagi_t tags[])
|
||||
{
|
||||
ep_callback(event, status, phrase, nua, ctx, &ctx->c, nh, call, sip, tags);
|
||||
}
|
||||
|
||||
void run_abc_until(struct context *ctx,
|
||||
nua_event_t a_event, condition_function *a_condition,
|
||||
nua_event_t b_event, condition_function *b_condition,
|
||||
nua_event_t c_event, condition_function *c_condition)
|
||||
{
|
||||
struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c;
|
||||
|
||||
a->next_event = a_event;
|
||||
a->next_condition = a_condition;
|
||||
a->last_event = -1;
|
||||
a->running = a_condition != NULL && a_condition != save_events;
|
||||
a->running |= a_event != -1;
|
||||
memset(&a->flags, 0, sizeof a->flags);
|
||||
|
||||
b->next_event = b_event;
|
||||
b->next_condition = b_condition;
|
||||
b->last_event = -1;
|
||||
b->running = b_condition != NULL && b_condition != save_events;
|
||||
b->running |= b_event != -1;
|
||||
memset(&b->flags, 0, sizeof b->flags);
|
||||
|
||||
c->next_event = c_event;
|
||||
c->next_condition = c_condition;
|
||||
c->last_event = -1;
|
||||
c->running = c_condition != NULL && c_condition != save_events;
|
||||
c->running |= c_event != -1;
|
||||
memset(&c->flags, 0, sizeof c->flags);
|
||||
|
||||
for (; a->running || b->running || c->running;) {
|
||||
su_root_step(ctx->root, 100);
|
||||
}
|
||||
}
|
||||
|
||||
void run_ab_until(struct context *ctx,
|
||||
nua_event_t a_event, condition_function *a_condition,
|
||||
nua_event_t b_event, condition_function *b_condition)
|
||||
{
|
||||
run_abc_until(ctx, a_event, a_condition, b_event, b_condition, -1, NULL);
|
||||
}
|
||||
|
||||
void run_bc_until(struct context *ctx,
|
||||
nua_event_t b_event, condition_function *b_condition,
|
||||
nua_event_t c_event, condition_function *c_condition)
|
||||
{
|
||||
run_abc_until(ctx, -1, NULL, b_event, b_condition, c_event, c_condition);
|
||||
}
|
||||
|
||||
int run_a_until(struct context *ctx,
|
||||
nua_event_t a_event,
|
||||
condition_function *a_condition)
|
||||
{
|
||||
run_abc_until(ctx, a_event, a_condition, -1, NULL, -1, NULL);
|
||||
return ctx->a.last_event;
|
||||
}
|
||||
|
||||
int run_b_until(struct context *ctx,
|
||||
nua_event_t b_event,
|
||||
condition_function *b_condition)
|
||||
{
|
||||
run_abc_until(ctx, -1, NULL, b_event, b_condition, -1, NULL);
|
||||
return ctx->b.last_event;
|
||||
}
|
||||
|
||||
int run_c_until(struct context *ctx,
|
||||
nua_event_t event,
|
||||
condition_function *condition)
|
||||
{
|
||||
run_abc_until(ctx, -1, NULL, -1, NULL, event, condition);
|
||||
return ctx->c.last_event;
|
||||
}
|
||||
|
||||
#define OPERATION(X, x) \
|
||||
int X(struct endpoint *ep, \
|
||||
struct call *call, nua_handle_t *nh, \
|
||||
tag_type_t tag, tag_value_t value, \
|
||||
...) \
|
||||
{ \
|
||||
ta_list ta; \
|
||||
ta_start(ta, tag, value); \
|
||||
\
|
||||
if (ep->printer) \
|
||||
ep->printer(-1, "nua_" #x, 0, "", ep->nua, ep->ctx, ep, \
|
||||
nh, call, NULL, ta_args(ta)); \
|
||||
\
|
||||
nua_##x(nh, ta_tags(ta)); \
|
||||
\
|
||||
ta_end(ta); \
|
||||
return 0; \
|
||||
} extern int dummy
|
||||
|
||||
OPERATION(INVITE, invite);
|
||||
OPERATION(ACK, ack);
|
||||
OPERATION(BYE, bye);
|
||||
OPERATION(CANCEL, cancel);
|
||||
OPERATION(AUTHENTICATE, authenticate);
|
||||
OPERATION(UPDATE, update);
|
||||
OPERATION(INFO, info);
|
||||
OPERATION(PRACK, prack);
|
||||
OPERATION(REFER, refer);
|
||||
OPERATION(MESSAGE, message);
|
||||
OPERATION(METHOD, method);
|
||||
OPERATION(OPTIONS, options);
|
||||
OPERATION(PUBLISH, publish);
|
||||
OPERATION(UNPUBLISH, unpublish);
|
||||
OPERATION(REGISTER, register);
|
||||
OPERATION(UNREGISTER, unregister);
|
||||
OPERATION(SUBSCRIBE, subscribe);
|
||||
OPERATION(UNSUBSCRIBE, unsubscribe);
|
||||
OPERATION(NOTIFY, notify);
|
||||
OPERATION(NOTIFIER, notifier);
|
||||
OPERATION(TERMINATE, terminate);
|
||||
OPERATION(AUTHORIZE, authorize);
|
||||
|
||||
/* Respond via endpoint and handle */
|
||||
int RESPOND(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh,
|
||||
int status, char const *phrase,
|
||||
tag_type_t tag, tag_value_t value,
|
||||
...)
|
||||
{
|
||||
ta_list ta;
|
||||
|
||||
ta_start(ta, tag, value);
|
||||
|
||||
if (ep->printer)
|
||||
ep->printer(-1, "nua_respond", status, phrase, ep->nua, ep->ctx, ep,
|
||||
nh, call, NULL, ta_args(ta));
|
||||
|
||||
nua_respond(nh, status, phrase, ta_tags(ta));
|
||||
ta_end(ta);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Destroy a handle */
|
||||
int DESTROY(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh)
|
||||
{
|
||||
if (ep->printer)
|
||||
ep->printer(-1, "nua_handle_destroy", 0, "", ep->nua, ep->ctx, ep,
|
||||
nh, call, NULL, NULL);
|
||||
|
||||
nua_handle_destroy(nh);
|
||||
|
||||
if (call->nh == nh)
|
||||
call->nh = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Reject all but currently used handles */
|
||||
struct call *check_handle(struct endpoint *ep,
|
||||
struct call *call,
|
||||
nua_handle_t *nh,
|
||||
int status, char const *phrase)
|
||||
{
|
||||
if (call)
|
||||
return call;
|
||||
|
||||
if (status)
|
||||
RESPOND(ep, call, nh, status, phrase, TAG_END());
|
||||
|
||||
nua_handle_destroy(nh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Save nua event in call-specific list */
|
||||
int save_event_in_list(struct context *ctx,
|
||||
nua_event_t nevent,
|
||||
struct endpoint *ep,
|
||||
struct call *call)
|
||||
|
||||
{
|
||||
struct eventlist *list;
|
||||
struct event *e;
|
||||
int action = ep->is_special(nevent);
|
||||
|
||||
if (action == event_is_extra)
|
||||
return 0;
|
||||
else if (action == event_is_special || call == NULL)
|
||||
list = ep->specials;
|
||||
else if (call->events)
|
||||
list = call->events;
|
||||
else
|
||||
list = ep->events;
|
||||
|
||||
e = su_zalloc(ctx->home, sizeof *e);
|
||||
|
||||
if (!e) { perror("su_zalloc"), abort(); }
|
||||
|
||||
if (!nua_save_event(ep->nua, e->saved_event)) {
|
||||
su_free(ctx->home, e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(e->prev = list->tail) = e; list->tail = &e->next;
|
||||
|
||||
e->call = call;
|
||||
e->data = nua_event_data(e->saved_event);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
/* Free nua events from endpoint list */
|
||||
void free_events_in_list(struct context *ctx,
|
||||
struct eventlist *list)
|
||||
{
|
||||
struct event *e;
|
||||
|
||||
while ((e = list->head)) {
|
||||
if ((*e->prev = e->next))
|
||||
e->next->prev = e->prev;
|
||||
nua_destroy_event(e->saved_event);
|
||||
su_free(ctx->home, e);
|
||||
}
|
||||
|
||||
list->tail = &list->head;
|
||||
}
|
||||
|
||||
void free_event_in_list(struct context *ctx,
|
||||
struct eventlist *list,
|
||||
struct event *e)
|
||||
{
|
||||
if (e) {
|
||||
if ((*e->prev = e->next))
|
||||
e->next->prev = e->prev;
|
||||
nua_destroy_event(e->saved_event);
|
||||
su_free(ctx->home, e);
|
||||
|
||||
if (list->head == NULL)
|
||||
list->tail = &list->head;
|
||||
}
|
||||
}
|
||||
|
||||
struct event *event_by_type(struct event *e, nua_event_t etype)
|
||||
{
|
||||
for (; e; e = e->next) {
|
||||
if (e->data->e_event == etype)
|
||||
break;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
size_t count_events(struct event const *e)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
for (n = 0; e; e = e->next)
|
||||
n++;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int is_special(nua_event_t e)
|
||||
{
|
||||
if (e == nua_i_active || e == nua_i_terminated)
|
||||
return event_is_extra;
|
||||
if (e == nua_i_outbound)
|
||||
return event_is_special;
|
||||
|
||||
return event_is_normal;
|
||||
}
|
||||
|
||||
void
|
||||
endpoint_init(struct context *ctx, struct endpoint *e, char id)
|
||||
{
|
||||
e->name[0] = id;
|
||||
e->ctx = ctx;
|
||||
|
||||
e->is_special = is_special;
|
||||
|
||||
call_init(e->call);
|
||||
call_init(e->reg);
|
||||
eventlist_init(e->events);
|
||||
eventlist_init(e->specials);
|
||||
}
|
||||
|
||||
void nolog(void *stream, char const *fmt, va_list ap) {}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TEST_PROXY_H
|
||||
#define TEST_PROXY_H
|
||||
|
||||
#include <sofia-sip/su_wait.h>
|
||||
#include <sofia-sip/nta.h>
|
||||
|
||||
SOFIA_BEGIN_DECLS
|
||||
|
||||
struct proxy;
|
||||
struct domain;
|
||||
|
||||
struct proxy *test_proxy_create(su_root_t *, tag_type_t, tag_value_t, ...);
|
||||
|
||||
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, ...);
|
||||
|
||||
void test_proxy_set_logging(struct proxy *, int logging);
|
||||
|
||||
void test_proxy_domain_set_expiration(struct domain *,
|
||||
sip_time_t min_expires,
|
||||
sip_time_t expires,
|
||||
sip_time_t max_expires);
|
||||
|
||||
void test_proxy_domain_get_expiration(struct domain *,
|
||||
sip_time_t *return_min_expires,
|
||||
sip_time_t *return_expires,
|
||||
sip_time_t *return_max_expires);
|
||||
|
||||
void test_proxy_set_session_timer(struct proxy *p,
|
||||
sip_time_t session_expires,
|
||||
sip_time_t min_se);
|
||||
|
||||
void test_proxy_get_session_timer(struct proxy *p,
|
||||
sip_time_t *return_session_expires,
|
||||
sip_time_t *return_min_se);
|
||||
|
||||
int test_proxy_domain_set_authorize(struct domain *, char const *realm);
|
||||
int test_proxy_domain_get_authorize(struct domain *,
|
||||
char const **return_realm);
|
||||
|
||||
void test_proxy_domain_set_outbound(struct domain *d,
|
||||
int use_outbound);
|
||||
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
|
||||
|
||||
#endif
|
||||
@@ -1,852 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_nua_re_invite.c
|
||||
* @brief Test re_inviteing, outbound, nat traversal.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_call_hold"
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
/* NUA-9 tests: REFER */
|
||||
|
||||
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) ||
|
||||
test_refer0(ctx, "NUA-9.4", 1, 1);
|
||||
}
|
||||
|
||||
/* Referred call:
|
||||
|
||||
A B
|
||||
| |
|
||||
|-------INVITE------>|
|
||||
|<----100 Trying-----|
|
||||
| |
|
||||
|<----180 Ringing----|
|
||||
| |
|
||||
|<------200 OK-------|
|
||||
|--------ACK-------->|
|
||||
| |
|
||||
|<------REFER--------|
|
||||
|-------200 OK------>| C
|
||||
[|-------NOTIFY------>|] |
|
||||
[|<------200 OK-------|] |
|
||||
| | |
|
||||
| | |
|
||||
|<-----SUBSCRIBE-----| |
|
||||
|-------200 OK------>| |
|
||||
| | |
|
||||
| | |
|
||||
|-----------------INVITE-------------------->|
|
||||
| | |
|
||||
|<------------------180----------------------|
|
||||
|-------NOTIFY------>| |
|
||||
|<------200 OK-------| |
|
||||
| | |
|
||||
|<------------------200----------------------|
|
||||
|-------NOTIFY------>| |
|
||||
|<------200 OK-------| |
|
||||
|-------------------ACK--------------------->|
|
||||
| | |
|
||||
|--------BYE-------->| |
|
||||
|<------200 OK-------| |
|
||||
| X |
|
||||
| |
|
||||
|-------------------BYE--------------------->|
|
||||
|<------------------200----------------------|
|
||||
| |
|
||||
|
||||
*/
|
||||
|
||||
int test_refer0(struct context *ctx, char const *tests,
|
||||
int refer_with_id, int notify_by_appl)
|
||||
{
|
||||
BEGIN();
|
||||
|
||||
struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c;
|
||||
struct call *a_call = a->call, *b_call = b->call, *c_call = c->call;
|
||||
struct call *a_refer, *a_c2, *b_refer;
|
||||
struct eventlist *a_revents, *b_revents;
|
||||
struct event *e, *notify_e;
|
||||
sip_t const *sip;
|
||||
sip_event_t const *a_event, *b_event;
|
||||
sip_refer_to_t const *refer_to;
|
||||
sip_referred_by_t const *referred_by;
|
||||
|
||||
sip_refer_to_t r0[1];
|
||||
sip_to_t to[1];
|
||||
|
||||
su_home_t tmphome[SU_HOME_AUTO_SIZE(16384)];
|
||||
|
||||
su_home_auto(tmphome, sizeof(tmphome));
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s: REFER: refer A to C%s%s%s\n", tests,
|
||||
refer_with_id ? " with Event id" : "",
|
||||
refer_with_id && !notify_by_appl ? " and" : "",
|
||||
!notify_by_appl ? " nua generating the NOTIFYs" : "");
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.1: REFER: make a call between A and B\n", tests);
|
||||
|
||||
/* Do (not) include id with first implicit Event: refer */
|
||||
nua_set_params(ctx->a.nua, NUTAG_REFER_WITH_ID(refer_with_id), TAG_END());
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
if (refer_with_id) {
|
||||
TEST_1(a_refer = calloc(1, (sizeof *a_refer) + (sizeof *a_refer->events)));
|
||||
call_init(a_refer);
|
||||
a_refer->events = (void *)(a_refer + 1);
|
||||
eventlist_init(a_refer->events);
|
||||
|
||||
a_call->next = a_refer;
|
||||
a_revents = a_refer->events;
|
||||
|
||||
TEST_1(b_refer = calloc(1, (sizeof *b_refer) + (sizeof *b_refer->events)));
|
||||
call_init(b_refer);
|
||||
b_refer->events = (void *)(b_refer + 1);
|
||||
eventlist_init(b_refer->events);
|
||||
|
||||
b_call->next = b_refer;
|
||||
b_revents = b_refer->events;
|
||||
}
|
||||
else {
|
||||
a_refer = a_call, b_refer = b_call;
|
||||
a_revents = a->events, b_revents = b->events;
|
||||
}
|
||||
|
||||
TEST_1(a_c2 = calloc(1, (sizeof *a_c2) + (sizeof *a_c2->events)));
|
||||
call_init(a_c2);
|
||||
a_c2->events = (void *)(a_c2 + 1);
|
||||
eventlist_init(a_c2->events);
|
||||
|
||||
a_call->sdp = "m=audio 5008 RTP/AVP 8";
|
||||
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
|
||||
a_c2->sdp = "m=audio 5012 RTP/AVP 8";
|
||||
c_call->sdp = "m=audio 5014 RTP/AVP 0 8";
|
||||
|
||||
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->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
SOATAG_USER_SDP_STR(a_call->sdp),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_ready, -1, accept_call);
|
||||
|
||||
/* 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->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, 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_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->events);
|
||||
|
||||
/*
|
||||
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->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 */
|
||||
TEST_1(is_offer_recv(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_early); /* EARLY */
|
||||
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->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.1: PASSED\n", tests);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* REFER (initial NOTIFY is no more sent unless REFER creates a new dialog)
|
||||
A B
|
||||
|<------REFER--------|
|
||||
|-------200 OK------>|
|
||||
[|-------NOTIFY------>|] |
|
||||
[|<------200 OK-------|] |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.2: B refers A to C\n", tests);
|
||||
|
||||
if (b_refer != b_call)
|
||||
TEST_1(b_refer->nh =
|
||||
nua_handle(b->nua, b_refer, SIPTAG_TO(a->to), TAG_END()));
|
||||
|
||||
*sip_refer_to_init(r0)->r_url = *c->contact->m_url;
|
||||
r0->r_url->url_headers = "subject=referred";
|
||||
r0->r_display = "C";
|
||||
|
||||
REFER(b, b_refer, b_refer->nh, SIPTAG_REFER_TO(r0),
|
||||
TAG_IF(!ctx->proxy_tests && b_refer != b_call,
|
||||
NUTAG_URL(a->contact->m_url)),
|
||||
TAG_END());
|
||||
run_ab_until(ctx, -1, save_until_received,
|
||||
-1, save_until_final_response);
|
||||
|
||||
/*
|
||||
Events in A:
|
||||
nua_i_refer
|
||||
*/
|
||||
TEST_1(e = a_revents->head); TEST_E(e->data->e_event, nua_i_refer);
|
||||
TEST(e->data->e_status, 202);
|
||||
a_event = NULL;
|
||||
TEST(tl_gets(e->data->e_tags,
|
||||
NUTAG_REFER_EVENT_REF(a_event),
|
||||
TAG_END()), 1);
|
||||
TEST_1(a_event); TEST_1(a_event = sip_event_dup(tmphome, a_event));
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_refer_to);
|
||||
TEST_1(refer_to = sip_refer_to_dup(tmphome, sip->sip_refer_to));
|
||||
TEST_1(sip->sip_referred_by);
|
||||
TEST_1(referred_by = sip_referred_by_dup(tmphome, sip->sip_referred_by));
|
||||
|
||||
/*
|
||||
Events in B after nua_refer():
|
||||
nua_r_refer
|
||||
*/
|
||||
TEST_1(e = b_revents->head); TEST_E(e->data->e_event, nua_r_refer);
|
||||
TEST(e->data->e_status, 100);
|
||||
TEST(tl_gets(e->data->e_tags,
|
||||
NUTAG_REFER_EVENT_REF(b_event),
|
||||
TAG_END()), 1);
|
||||
TEST_1(b_event); TEST_1(b_event->o_id);
|
||||
TEST_1(b_event = sip_event_dup(tmphome, b_event));
|
||||
|
||||
notify_e = NULL;
|
||||
|
||||
TEST_1(e = e->next);
|
||||
if (e->data->e_event == nua_i_notify) {
|
||||
notify_e = e;
|
||||
TEST_1(e = e->next);
|
||||
}
|
||||
TEST_E(e->data->e_event, nua_r_refer);
|
||||
TEST(e->data->e_status, 202);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_SIZE(strtoul(b_event->o_id, NULL, 10), sip->sip_cseq->cs_seq);
|
||||
|
||||
if (a_refer != a_call) {
|
||||
while (!notify_e) {
|
||||
for (e = b_revents->head; e; e = e->next) {
|
||||
if (e->data->e_event == nua_i_notify) {
|
||||
notify_e = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!notify_e)
|
||||
run_ab_until(ctx, -1, save_until_received, nua_i_notify, save_events);
|
||||
}
|
||||
|
||||
if (a_revents->head->next == NULL)
|
||||
run_a_until(ctx, -1, save_until_received);
|
||||
|
||||
TEST_1(e = a_revents->head->next); TEST_E(e->data->e_event, nua_r_notify);
|
||||
TEST_1(!e->next);
|
||||
|
||||
TEST_1(e = notify_e);
|
||||
TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event);
|
||||
if (refer_with_id)
|
||||
TEST_S(sip->sip_event->o_id, b_event->o_id);
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "pending");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
TEST_M(sip->sip_payload->pl_data, "SIP/2.0 100 Trying\r\n",
|
||||
sip->sip_payload->pl_len);
|
||||
}
|
||||
|
||||
free_events_in_list(ctx, a_revents);
|
||||
free_events_in_list(ctx, b_revents);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.2: PASSED\n", tests);
|
||||
|
||||
#if 0
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
A B
|
||||
|<-----SUBSCRIBE-----|
|
||||
|-------200 OK------>|
|
||||
|-------NOTIFY------>| |
|
||||
|<------200 OK-------| |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.3: extend expiration time for implied subscription\n", tests);
|
||||
|
||||
SUBSCRIBE(b, b_call, b_call->nh,
|
||||
SIPTAG_EVENT(b_event),
|
||||
SIPTAG_EXPIRES_STR("3600"),
|
||||
TAG_END());
|
||||
run_ab_until(ctx, -1, save_until_final_response,
|
||||
-1, save_until_final_response);
|
||||
|
||||
/*
|
||||
Events in A:
|
||||
nua_i_subscribe, nua_r_notify
|
||||
*/
|
||||
TEST_1(e = a->events->head);
|
||||
if (e->data->e_event == nua_r_notify)
|
||||
TEST_1(e = e->next);
|
||||
TEST_E(e->data->e_event, nua_i_subscribe);
|
||||
TEST(e->data->e_status, 202);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_notify);
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/*
|
||||
Events in B after nua_subscribe():
|
||||
nua_r_subscribe, nua_i_notify
|
||||
*/
|
||||
TEST_1(e = b->events->head);
|
||||
if (e->data->e_event == nua_i_notify) {
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event);
|
||||
if (refer_with_id)
|
||||
TEST_S(sip->sip_event->o_id, b_event->o_id);
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "pending");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
TEST_M(sip->sip_payload->pl_data, "SIP/2.0 100 Trying\r\n",
|
||||
sip->sip_payload->pl_len);
|
||||
TEST_1(e = e->next);
|
||||
}
|
||||
TEST_E(e->data->e_event, nua_r_subscribe);
|
||||
TEST(e->data->e_status, 202);
|
||||
if (!e->next)
|
||||
run_b_until(ctx, -1, save_until_received);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event);
|
||||
if (refer_with_id)
|
||||
TEST_S(sip->sip_event->o_id, b_event->o_id);
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "pending");
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.3: PASSED\n", tests);
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
A B C
|
||||
| | |
|
||||
|-----------------INVITE-------------------->|
|
||||
| | |
|
||||
XXX | |
|
||||
| | |
|
||||
|<------------------180----------------------|
|
||||
|-------NOTIFY------>| |
|
||||
|<------200 OK-------| |
|
||||
| | |
|
||||
XXX | |
|
||||
| | |
|
||||
|<------------------200----------------------|
|
||||
|-------NOTIFY------>| |
|
||||
|<------200 OK-------| |
|
||||
|-------------------ACK--------------------->|
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.4: A invites C\n", tests);
|
||||
|
||||
*sip_to_init(to)->a_url = *refer_to->r_url;
|
||||
to->a_display = refer_to->r_display;
|
||||
|
||||
a_refer->next = a_c2;
|
||||
|
||||
TEST_1(a_c2->nh = nua_handle(a->nua, a_c2, SIPTAG_TO(to), TAG_END()));
|
||||
|
||||
INVITE(a, a_c2, a_c2->nh, /* NUTAG_URL(refer_to->r_url), */
|
||||
TAG_IF(!notify_by_appl, NUTAG_REFER_EVENT(a_event)),
|
||||
TAG_IF(!notify_by_appl, NUTAG_NOTIFY_REFER(a_refer->nh)),
|
||||
SOATAG_USER_SDP_STR(a_c2->sdp),
|
||||
SIPTAG_REFERRED_BY(referred_by),
|
||||
TAG_END());
|
||||
|
||||
run_abc_until(ctx,
|
||||
-1, notify_by_appl ? notify_until_terminated : until_ready,
|
||||
-1, save_until_received,
|
||||
-1, accept_call);
|
||||
|
||||
/* Wait until both NOTIFY has been responded */
|
||||
while (a_revents->head == NULL || a_revents->head->next == NULL)
|
||||
run_ab_until(ctx, -1, save_until_received, -1, save_events);
|
||||
while (b_revents->head == NULL || b_revents->head->next == NULL)
|
||||
run_ab_until(ctx, -1, save_events, -1, save_until_received);
|
||||
|
||||
/* Client A transitions:
|
||||
INIT -(C1)-> CALLING: nua_invite(), nua_i_state
|
||||
CALLING -(C2+C4)-> PROCEEDING: nua_r_invite, nua_i_state
|
||||
nua_r_notify
|
||||
PROCEEDING -(C3+C4)-> READY: nua_r_invite, nua_i_state
|
||||
nua_r_notify
|
||||
*/
|
||||
TEST_1(e = a_c2->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, 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_c2->events);
|
||||
|
||||
TEST_1(e = a_revents->head); TEST_E(e->data->e_event, nua_r_notify);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_notify);
|
||||
if (a_refer == a_call && notify_by_appl) {
|
||||
free_event_in_list(ctx, a_revents, a_revents->head);
|
||||
free_event_in_list(ctx, a_revents, a_revents->head);
|
||||
}
|
||||
else {
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a_revents);
|
||||
}
|
||||
|
||||
/*
|
||||
Events in B after nua_refer():
|
||||
nua_i_notify
|
||||
*/
|
||||
TEST_1(e = b_revents->head); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "active");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
TEST_M(sip->sip_payload->pl_data, "SIP/2.0 180 Ringing\r\n", sip->sip_payload->pl_len);
|
||||
TEST_1(sip->sip_event);
|
||||
if (refer_with_id)
|
||||
TEST_S(sip->sip_event->o_id, b_event->o_id);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
TEST_M(sip->sip_payload->pl_data, "SIP/2.0 200 OK\r\n", sip->sip_payload->pl_len);
|
||||
TEST_1(sip->sip_event);
|
||||
if (refer_with_id)
|
||||
TEST_S(sip->sip_event->o_id, b_event->o_id);
|
||||
if (b_refer == b_call && notify_by_appl) {
|
||||
free_event_in_list(ctx, b_revents, b_revents->head);
|
||||
free_event_in_list(ctx, b_revents, b_revents->head);
|
||||
}
|
||||
else {
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, b_revents);
|
||||
}
|
||||
|
||||
/*
|
||||
C 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 = c->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 */
|
||||
TEST_1(is_offer_recv(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_early); /* EARLY */
|
||||
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, c->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.4: PASSED\n", tests);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
A B
|
||||
|---------BYE------->|
|
||||
|<--------200--------|
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.5.1: terminate call between A and B\n", tests);
|
||||
|
||||
if (notify_by_appl) {
|
||||
if (!a->events->head || !a->events->head->next)
|
||||
run_ab_until(ctx, -1, until_terminated, -1, save_events);
|
||||
if (!b->events->head || !b->events->head->next)
|
||||
run_ab_until(ctx, -1, save_events, -1, until_terminated);
|
||||
}
|
||||
else {
|
||||
BYE(a, a_call, a_call->nh, TAG_END());
|
||||
run_ab_until(ctx, -1, until_terminated, -1, until_terminated);
|
||||
}
|
||||
|
||||
/*
|
||||
Transitions of A:
|
||||
READY --(T2)--> TERMINATING: nua_bye()
|
||||
TERMINATING --(T3)--> TERMINATED: nua_r_bye, nua_i_state
|
||||
*/
|
||||
TEST_1(e = a->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, a->events);
|
||||
|
||||
/* Transitions of B:
|
||||
READY -(T1)-> TERMINATED: nua_i_bye, nua_i_state
|
||||
*/
|
||||
TEST_1(e = b->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, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.5.1: PASSED\n", tests);
|
||||
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
A C
|
||||
|-------------------BYE--------------------->|
|
||||
|<------------------200----------------------|
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.5.2: terminate call between A and C\n", tests);
|
||||
|
||||
BYE(a, a_c2, a_c2->nh, TAG_END());
|
||||
run_abc_until(ctx, -1, until_terminated, -1, NULL, -1, until_terminated);
|
||||
|
||||
/*
|
||||
Transitions of A:
|
||||
READY --(T2)--> TERMINATING: nua_bye()
|
||||
TERMINATING --(T3)--> TERMINATED: nua_r_bye, nua_i_state
|
||||
*/
|
||||
TEST_1(e = a_c2->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, a_c2->events);
|
||||
|
||||
/* Transitions of B:
|
||||
READY -(T1)-> TERMINATED: nua_i_bye, nua_i_state
|
||||
*/
|
||||
TEST_1(e = c->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, c->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s.5.2: PASSED\n", tests);
|
||||
|
||||
nua_handle_destroy(c_call->nh), c_call->nh = NULL;
|
||||
|
||||
nua_handle_destroy(a_c2->nh), a_c2->nh = NULL;
|
||||
a_refer->next = NULL; free(a_c2);
|
||||
|
||||
if (a_refer != a_call) {
|
||||
nua_handle_destroy(a_refer->nh), a_refer->nh = NULL;
|
||||
a_call->next = NULL; free(a_refer);
|
||||
}
|
||||
|
||||
if (b_refer != b_call) {
|
||||
nua_handle_destroy(b_refer->nh), b_refer->nh = NULL;
|
||||
b_call->next = NULL; free(b_refer);
|
||||
}
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST %s: PASSED\n", tests);
|
||||
|
||||
su_home_deinit(tmphome);
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
X INVITE
|
||||
| |
|
||||
|-----------------INVITE-------------------->|
|
||||
| | |
|
||||
| | |
|
||||
|<------------------200----------------------|
|
||||
|-------NOTIFY------>| |
|
||||
|--------BYE-------->| |
|
||||
|-------------------ACK--------------------->|
|
||||
|
||||
*/
|
||||
int notify_until_terminated(CONDITION_PARAMS)
|
||||
{
|
||||
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
|
||||
return 0;
|
||||
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
|
||||
if (event == nua_r_invite) {
|
||||
sip_status_t *st = sip->sip_status;
|
||||
sip_payload_t *pl;
|
||||
struct call *r_call;
|
||||
|
||||
if (!nua_handle_has_events(ep->call->nh))
|
||||
r_call = ep->call->next;
|
||||
else
|
||||
r_call = ep->call;
|
||||
|
||||
assert(nua_handle_has_events(r_call->nh));
|
||||
|
||||
pl = sip_payload_format(NULL, "SIP/2.0 %u %s\r\n",
|
||||
st->st_status, st->st_phrase);
|
||||
|
||||
NOTIFY(ep, r_call, r_call->nh,
|
||||
SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
|
||||
SIPTAG_PAYLOAD(pl),
|
||||
NUTAG_SUBSTATE(st->st_status >= 200
|
||||
? nua_substate_terminated
|
||||
: nua_substate_active),
|
||||
TAG_END());
|
||||
|
||||
su_free(NULL, pl);
|
||||
|
||||
if (st->st_status >= 200)
|
||||
BYE(ep, ep->call, ep->call->nh, TAG_END());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (call != ep->call)
|
||||
return 0;
|
||||
|
||||
switch (callstate(tags)) {
|
||||
case nua_callstate_terminated:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int authenticate_refer(CONDITION_PARAMS);
|
||||
int reject_refer_after_notified(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;
|
||||
sip_t const *sip;
|
||||
|
||||
sip_refer_to_t r0[1];
|
||||
|
||||
if (!ctx->proxy_tests)
|
||||
return 0;
|
||||
|
||||
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,
|
||||
SIPTAG_FROM(c->to),
|
||||
SIPTAG_REFER_TO(r0),
|
||||
TAG_END());
|
||||
|
||||
run_abc_until(ctx, -1, reject_refer_after_notified, -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);
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
TEST_1(!e->next);
|
||||
/*
|
||||
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);
|
||||
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST(e->data->e_status, 200);
|
||||
|
||||
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_refer);
|
||||
TEST(e->data->e_status, 480);
|
||||
|
||||
TEST_1(!e->next);
|
||||
|
||||
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_after_notified(CONDITION_PARAMS)
|
||||
{
|
||||
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) {
|
||||
}
|
||||
|
||||
if (event == nua_r_notify) {
|
||||
/* Respond to refer only after initial notify has been responded */
|
||||
struct eventlist *list;
|
||||
struct event *e;
|
||||
|
||||
if (call->events)
|
||||
list = call->events;
|
||||
else
|
||||
list = ep->events;
|
||||
|
||||
for (e = list->head; e; e = e->next)
|
||||
if (e->data->e_event == nua_i_refer)
|
||||
break;
|
||||
|
||||
if (e) {
|
||||
RESPOND(ep, call, nh, SIP_480_TEMPORARILY_UNAVAILABLE,
|
||||
NUTAG_WITH(e->data->e_msg),
|
||||
TAG_END());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2008 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef S2TESTER_H
|
||||
#define S2TESTER_H
|
||||
|
||||
#define TP_STACK_T struct tester
|
||||
#define SU_ROOT_MAGIC_T struct tester
|
||||
|
||||
#include <sofia-sip/su_wait.h>
|
||||
#include <sofia-sip/sip.h>
|
||||
#include <sofia-sip/tport.h>
|
||||
#include <sofia-sip/nua.h>
|
||||
|
||||
struct tester
|
||||
{
|
||||
su_home_t home[1];
|
||||
|
||||
su_root_t *root;
|
||||
msg_mclass_t const *mclass;
|
||||
int flags;
|
||||
|
||||
char const *hostname;
|
||||
tport_t *master;
|
||||
|
||||
sip_to_t *local;
|
||||
sip_contact_t *contact;
|
||||
struct {
|
||||
sip_contact_t *contact;
|
||||
tport_t *tport;
|
||||
} udp, tcp, tls;
|
||||
|
||||
struct message {
|
||||
struct message *next, **prev;
|
||||
msg_t *msg;
|
||||
sip_t *sip;
|
||||
tport_t *tport;
|
||||
su_time_t when;
|
||||
} *received;
|
||||
|
||||
struct {
|
||||
su_socket_t socket;
|
||||
su_wait_t wait[1];
|
||||
int reg;
|
||||
} dns;
|
||||
|
||||
nua_t *nua;
|
||||
|
||||
struct event {
|
||||
struct event *next, **prev;
|
||||
nua_saved_event_t event[1];
|
||||
nua_handle_t *nh;
|
||||
nua_event_data_t const *data;
|
||||
su_time_t when;
|
||||
} *events;
|
||||
|
||||
struct {
|
||||
nua_handle_t *nh;
|
||||
sip_to_t *aor;
|
||||
sip_contact_t *contact;
|
||||
tport_t *tport;
|
||||
} registration[1];
|
||||
|
||||
unsigned long tid;
|
||||
|
||||
/* Settings */
|
||||
int server_uses_rport;
|
||||
};
|
||||
|
||||
struct dialog
|
||||
{
|
||||
su_home_t home[1];
|
||||
sip_from_t *local;
|
||||
sip_to_t *remote;
|
||||
sip_call_id_t *call_id;
|
||||
uint32_t lseq, rseq;
|
||||
sip_contact_t *target;
|
||||
sip_route_t *route;
|
||||
sip_contact_t *contact;
|
||||
|
||||
tport_t *tport;
|
||||
msg_t *invite; /* latest invite sent */
|
||||
};
|
||||
|
||||
extern struct tester *s2;
|
||||
extern tp_stack_class_t const s2_stack[1];
|
||||
|
||||
extern unsigned s2_default_registration_duration;
|
||||
extern char const s2_auth_digest_str[];
|
||||
extern char const s2_auth_credentials[];
|
||||
|
||||
extern char const s2_auth2_digest_str[];
|
||||
extern char const s2_auth2_credentials[];
|
||||
|
||||
extern char const s2_auth3_digest_str[];
|
||||
extern char const s2_auth3_credentials[];
|
||||
|
||||
void s2_fast_forward(unsigned long seconds);
|
||||
|
||||
void s2_case(char const *tag,
|
||||
char const *title,
|
||||
char const *description);
|
||||
|
||||
struct event *s2_remove_event(struct event *);
|
||||
void s2_free_event(struct event *);
|
||||
void s2_flush_events(void);
|
||||
|
||||
struct event *s2_next_event(void);
|
||||
struct event *s2_wait_for_event(nua_event_t event, int status);
|
||||
int s2_check_event(nua_event_t event, int status);
|
||||
int s2_check_callstate(enum nua_callstate state);
|
||||
|
||||
struct message *s2_remove_message(struct message *m);
|
||||
void s2_free_message(struct message *m);
|
||||
void s2_flush_messages(void);
|
||||
|
||||
struct message *s2_next_response(void);
|
||||
struct message *s2_wait_for_response(int status, sip_method_t , char const *);
|
||||
int s2_check_response(int status, sip_method_t method, char const *name);
|
||||
|
||||
struct message *s2_next_request(void);
|
||||
struct message *s2_wait_for_request(sip_method_t method, char const *name);
|
||||
int s2_check_request(sip_method_t method, char const *name);
|
||||
|
||||
#define SIP_METHOD_UNKNOWN sip_method_unknown, NULL
|
||||
|
||||
struct message *s2_respond_to(struct message *m, struct dialog *d,
|
||||
int status, char const *phrase,
|
||||
tag_type_t tag, tag_value_t value, ...);
|
||||
|
||||
int s2_request_to(struct dialog *d,
|
||||
sip_method_t method, char const *name,
|
||||
tport_t *tport,
|
||||
tag_type_t tag, tag_value_t value, ...);
|
||||
|
||||
int s2_update_dialog(struct dialog *d, struct message *response);
|
||||
|
||||
int s2_save_register(struct message *m);
|
||||
|
||||
void s2_flush_all(void);
|
||||
|
||||
void s2_setup_base(char const *hostname);
|
||||
void s2_setup_logs(int level);
|
||||
void s2_setup_tport(char const * const *protocols,
|
||||
tag_type_t tag, tag_value_t value, ...);
|
||||
void s2_teardown(void);
|
||||
|
||||
nua_t *s2_nua_setup(tag_type_t tag, tag_value_t value, ...);
|
||||
void s2_nua_teardown(void);
|
||||
|
||||
void s2_register_setup(void);
|
||||
void s2_register_teardown(void);
|
||||
|
||||
#endif
|
||||
@@ -1,434 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_session_timer.c
|
||||
* @brief NUA-8 tests: Session timer, UPDATE
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_session_timer"
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
static size_t remove_update(void *a, void *message, size_t len);
|
||||
|
||||
int test_session_timer(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;
|
||||
sip_t const *sip;
|
||||
|
||||
/* Session timer test:
|
||||
|
||||
A P B
|
||||
|-------INVITE------>|
|
||||
|<----100 Trying-----|
|
||||
| |
|
||||
|<----180 Ringing----|
|
||||
| |
|
||||
|<------200 OK-------|
|
||||
|------------------->|
|
||||
| |
|
||||
| |
|
||||
|--INVITE->| |
|
||||
|<--422----| |
|
||||
|---ACK--->| |
|
||||
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.1: Session timers\n");
|
||||
|
||||
a_call->sdp = "m=audio 5008 RTP/AVP 8";
|
||||
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
|
||||
|
||||
/* We negotiate session timer of 6 second */
|
||||
/* Disable session timer from proxy */
|
||||
test_proxy_set_session_timer(ctx->p, 0, 0);
|
||||
|
||||
nua_set_params(ctx->b.nua,
|
||||
NUTAG_SESSION_REFRESHER(nua_any_refresher),
|
||||
NUTAG_MIN_SE(1),
|
||||
NUTAG_SESSION_TIMER(6),
|
||||
NTATAG_SIP_T1X64(8000),
|
||||
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->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
SOATAG_USER_SDP_STR(a_call->sdp),
|
||||
SIPTAG_SUPPORTED_STR("100rel"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_ready, -1, accept_call);
|
||||
|
||||
/* Client transitions:
|
||||
INIT -(C1)-> CALLING: 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->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, 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(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_session_expires);
|
||||
TEST_S(sip->sip_session_expires->x_refresher, "uas");
|
||||
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->events);
|
||||
|
||||
/*
|
||||
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->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 */
|
||||
TEST_1(is_offer_recv(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_early); /* EARLY */
|
||||
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->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.1: PASSED\n");
|
||||
|
||||
if (ctx->expensive) {
|
||||
nua_set_hparams(a_call->nh,
|
||||
NUTAG_SUPPORTED("timer"),
|
||||
NUTAG_MIN_SE(1),
|
||||
NUTAG_SESSION_TIMER(5),
|
||||
TAG_END());
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.2: Wait for refresh using INVITE\n");
|
||||
|
||||
run_ab_until(ctx, -1, until_ready, -1, until_ready);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.2: PASSED\n");
|
||||
|
||||
nua_set_hparams(b_call->nh,
|
||||
NUTAG_UPDATE_REFRESH(1),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.3: Wait for refresh using UPDATE\n");
|
||||
|
||||
run_ab_until(ctx, -1, until_ready, -1, until_ready);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_update);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.3: PASSED\n");
|
||||
|
||||
if (ctx->nat) {
|
||||
struct nat_filter *f;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.4: filter UPDATE, wait until session expires\n");
|
||||
|
||||
f = test_nat_add_filter(ctx->nat, remove_update, NULL, nat_inbound);
|
||||
TEST_1(f);
|
||||
|
||||
run_ab_until(ctx, -1, until_terminated, -1, until_terminated);
|
||||
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_bye);
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
test_nat_remove_filter(ctx->nat, f);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.4: PASSED\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (b_call->nh) {
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.1.9: Terminate first session timer call\n");
|
||||
|
||||
BYE(b, b_call, b_call->nh, TAG_END());
|
||||
run_ab_until(ctx, -1, until_terminated, -1, until_terminated);
|
||||
free_events_in_list(ctx, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
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-8.1.9: PASSED\n");
|
||||
}
|
||||
|
||||
/*
|
||||
| |
|
||||
|-------INVITE------>|
|
||||
|<-------422---------|
|
||||
|--------ACK-------->|
|
||||
| |
|
||||
|-------INVITE------>|
|
||||
|<----100 Trying-----|
|
||||
| |
|
||||
|<----180 Ringing----|
|
||||
| |
|
||||
|<------200 OK-------|
|
||||
|--------ACK-------->|
|
||||
| |
|
||||
|<-------BYE---------|
|
||||
|-------200 OK-------|
|
||||
| |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.2: Session timers negotiation\n");
|
||||
|
||||
test_proxy_set_session_timer(ctx->p, 180, 90);
|
||||
|
||||
nua_set_params(a->nua,
|
||||
NUTAG_SUPPORTED("timer"),
|
||||
TAG_END());
|
||||
|
||||
run_a_until(ctx, nua_r_set_params, until_final_response);
|
||||
|
||||
nua_set_params(b->nua,
|
||||
NUTAG_AUTOANSWER(0),
|
||||
NUTAG_MIN_SE(120),
|
||||
NTATAG_SIP_T1X64(2000),
|
||||
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->proxy_tests, NUTAG_URL(b->contact->m_url)),
|
||||
SOATAG_USER_SDP_STR(a_call->sdp),
|
||||
SIPTAG_SUPPORTED_STR("100rel, timer"),
|
||||
NUTAG_SESSION_TIMER(4),
|
||||
NUTAG_MIN_SE(3),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, until_ready, -1, accept_call);
|
||||
|
||||
/* Client transitions:
|
||||
INIT -(C1)-> CALLING: nua_invite(), nua_i_state
|
||||
CALLING -(C6a)-> (TERMINATED/INIT): nua_r_invite
|
||||
when testing with proxy, second 422 when call reaches UAS:
|
||||
(INIT) -(C1)-> CALLING: nua_i_state
|
||||
CALLING -(C6a)-> (TERMINATED/INIT): nua_r_invite
|
||||
(INIT) -(C1)-> CALLING: 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->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, 100);
|
||||
TEST(sip_object(e->data->e_msg)->sip_status->st_status, 422);
|
||||
|
||||
if (ctx->proxy_tests) {
|
||||
TEST_1(e = e->next); 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, 100);
|
||||
TEST(sip_object(e->data->e_msg)->sip_status->st_status, 422);
|
||||
}
|
||||
|
||||
TEST_1(e = e->next); 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, 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(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_session_expires);
|
||||
TEST(sip->sip_session_expires->x_delta, 120);
|
||||
TEST_S(sip->sip_session_expires->x_refresher, "uac");
|
||||
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->events);
|
||||
|
||||
/*
|
||||
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->events->head); TEST_E(e->data->e_event, nua_i_invite);
|
||||
TEST(e->data->e_status, 100);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_session_expires);
|
||||
TEST_1(!sip->sip_session_expires->x_refresher);
|
||||
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));
|
||||
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(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->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.2: PASSED\n");
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-8.3: UPDATE with session timer headers\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->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));
|
||||
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(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_answer_recv(e->data->e_tags));
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
/* Events from A (who received UPDATE) */
|
||||
TEST_1(e = a->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->events);
|
||||
|
||||
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->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->events);
|
||||
|
||||
/* A: READY -(T1)-> TERMINATED: nua_i_bye, nua_i_state */
|
||||
TEST_1(e = a->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->events);
|
||||
|
||||
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-8.3: PASSED\n");
|
||||
|
||||
END();
|
||||
}
|
||||
|
||||
static
|
||||
size_t remove_update(void *a, void *message, size_t len)
|
||||
{
|
||||
(void)a;
|
||||
|
||||
if (strncmp("UPDATE ", message, 7) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,601 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Sofia-SIP package
|
||||
*
|
||||
* Copyright (C) 2005 Nokia Corporation.
|
||||
*
|
||||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/**@CFILE test_sip_events.c
|
||||
* @brief NUA-12 tests: SUBSCRIBE/NOTIFY.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
* @author Martti Mela <Martti Mela@nokia.com>
|
||||
*
|
||||
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_nua.h"
|
||||
#include <sofia-sip/su_tag_class.h>
|
||||
#include <sofia-sip/nea.h>
|
||||
|
||||
#if !HAVE_MEMMEM
|
||||
void *memmem(const void *haystack, size_t haystacklen,
|
||||
const void *needle, size_t needlelen);
|
||||
#endif
|
||||
|
||||
#if HAVE_FUNC
|
||||
#elif HAVE_FUNCTION
|
||||
#define __func__ __FUNCTION__
|
||||
#else
|
||||
#define __func__ "test_sip_events"
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
/* Test events methods: SUBSCRIBE/NOTIFY */
|
||||
|
||||
/**Terminate until received notify.
|
||||
* Save events (except nua_i_active or terminated).
|
||||
*/
|
||||
int save_until_notified(CONDITION_PARAMS)
|
||||
{
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
return event == nua_i_notify;
|
||||
}
|
||||
|
||||
int save_until_notified_and_responded(CONDITION_PARAMS)
|
||||
{
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
|
||||
if (event == nua_i_notify) ep->flags.bit0 = 1;
|
||||
if (event == nua_r_subscribe || event == nua_r_unsubscribe) {
|
||||
if (status == 407) {
|
||||
AUTHENTICATE(ep, call, nh,
|
||||
NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"),
|
||||
TAG_END());
|
||||
}
|
||||
else if (status >= 300)
|
||||
return 1;
|
||||
else if (status >= 200)
|
||||
ep->flags.bit1 = 1;
|
||||
}
|
||||
|
||||
return ep->flags.bit0 && ep->flags.bit1;
|
||||
}
|
||||
|
||||
|
||||
int save_until_subscription(CONDITION_PARAMS)
|
||||
{
|
||||
save_event_in_list(ctx, event, ep, call);
|
||||
return event == nua_i_subscription;
|
||||
}
|
||||
|
||||
|
||||
int test_events(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, *en, *es;
|
||||
sip_t const *sip;
|
||||
tagi_t const *t, *n_tags, *r_tags;
|
||||
url_t b_url[1];
|
||||
enum nua_substate substate;
|
||||
nea_sub_t *sub = NULL;
|
||||
|
||||
char const open[] =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n"
|
||||
" entity='pres:bob@example.org'>\n"
|
||||
" <tuple id='ksac9udshce'>\n"
|
||||
" <status><basic>open</basic></status>\n"
|
||||
" <contact priority='1.0'>sip:bob@example.org</contact>\n"
|
||||
" </tuple>\n"
|
||||
"</presence>\n";
|
||||
|
||||
char const closed[] =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n"
|
||||
" entity='pres:bob@example.org'>\n"
|
||||
" <tuple id='ksac9udshce'>\n"
|
||||
" <status><basic>closed</basic></status>\n"
|
||||
" </tuple>\n"
|
||||
"</presence>\n";
|
||||
|
||||
|
||||
/* SUBSCRIBE test
|
||||
|
||||
A B
|
||||
|------SUBSCRIBE---->|
|
||||
|<--------405--------|
|
||||
| |
|
||||
|
||||
*/
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.1: SUBSCRIBE without notifier\n");
|
||||
|
||||
nua_set_params(b->nua, SIPTAG_ALLOW_EVENTS(NULL), 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()));
|
||||
|
||||
SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_final_response,
|
||||
-1, NULL /* XXX save_until_received */);
|
||||
|
||||
/* Client events:
|
||||
nua_subscribe(), nua_r_subscribe
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_subscribe);
|
||||
TEST(e->data->e_status, 489);
|
||||
TEST_1(!e->next);
|
||||
|
||||
#if 0 /* XXX */
|
||||
/*
|
||||
Server events:
|
||||
nua_i_subscribe
|
||||
*/
|
||||
TEST_1(e = b->events->head);
|
||||
TEST_E(e->data->e_event, nua_i_subscribe);
|
||||
TEST(e->data->e_status, 405);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event);
|
||||
TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_1(!e->next);
|
||||
#endif
|
||||
|
||||
free_events_in_list(ctx, a->events);
|
||||
free_events_in_list(ctx, b->events);
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.1: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/* SUBSCRIBE test using notifier and establishing subscription
|
||||
|
||||
A B
|
||||
| |
|
||||
|------SUBSCRIBE---->|
|
||||
|<--------202--------|
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.2: using notifier and establishing subscription\n");
|
||||
|
||||
TEST_1(b_call->nh = nua_handle(b->nua, b_call, TAG_END()));
|
||||
|
||||
*b_url = *b->contact->m_url;
|
||||
|
||||
NOTIFIER(b, b_call, b_call->nh,
|
||||
NUTAG_URL(b_url),
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"),
|
||||
SIPTAG_PAYLOAD_STR(closed),
|
||||
NEATAG_THROTTLE(1),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_notifier, until_final_response);
|
||||
|
||||
SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_ACCEPT_STR("application/xpidf, application/pidf+xml"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified_and_responded,
|
||||
-1, save_until_received);
|
||||
|
||||
/* Client events:
|
||||
nua_subscribe(), nua_i_notify/nua_r_subscribe
|
||||
*/
|
||||
TEST_1(en = event_by_type(a->events->head, nua_i_notify));
|
||||
TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));
|
||||
|
||||
TEST_1(e = es); TEST_E(e->data->e_event, nua_r_subscribe);
|
||||
r_tags = e->data->e_tags;
|
||||
TEST_1(tl_find(r_tags, nutag_substate));
|
||||
if (es->next == en) {
|
||||
TEST_1(200 <= e->data->e_status && e->data->e_status < 300);
|
||||
TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_embryonic);
|
||||
}
|
||||
else {
|
||||
TEST_1(200 <= e->data->e_status && e->data->e_status < 300);
|
||||
TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_active);
|
||||
}
|
||||
|
||||
TEST_1(e = en); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
n_tags = e->data->e_tags;
|
||||
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "active");
|
||||
TEST_1(sip->sip_subscription_state->ss_expires);
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active);
|
||||
TEST_1(!en->next || !es->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/* XXX --- Do not check server side events */
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.2: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/* NOTIFY with updated content
|
||||
|
||||
A B
|
||||
| |
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.3: update notifier\n");
|
||||
|
||||
/* Update presence data */
|
||||
|
||||
NOTIFIER(b, b_call, b_call->nh,
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"),
|
||||
SIPTAG_PAYLOAD_STR(open),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified, -1, save_until_received);
|
||||
|
||||
/* subscriber events:
|
||||
nua_i_notify
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "active");
|
||||
TEST_1(sip->sip_subscription_state->ss_expires);
|
||||
n_tags = e->data->e_tags;
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value,
|
||||
nua_substate_active);
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/* XXX --- Do not check server side events */
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.3: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/* un-SUBSCRIBE
|
||||
|
||||
A B
|
||||
| |
|
||||
|------SUBSCRIBE---->|
|
||||
|<--------202--------|
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.5: un-SUBSCRIBE\n");
|
||||
|
||||
UNSUBSCRIBE(a, a_call, a_call->nh, TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_final_response,
|
||||
-1, save_until_subscription);
|
||||
|
||||
/* Client events:
|
||||
nua_unsubscribe(), nua_i_notify/nua_r_unsubscribe
|
||||
*/
|
||||
TEST_1(e = a->events->head);
|
||||
if (e->data->e_event == nua_i_notify) {
|
||||
TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
n_tags = e->data->e_tags;
|
||||
TEST_1(sip->sip_event);
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
|
||||
TEST_1(!sip->sip_subscription_state->ss_expires);
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated);
|
||||
TEST_1(e = e->next);
|
||||
}
|
||||
TEST_E(e->data->e_event, nua_r_unsubscribe);
|
||||
TEST_1(tl_find(e->data->e_tags, nutag_substate));
|
||||
TEST(tl_find(e->data->e_tags, nutag_substate)->t_value,
|
||||
nua_substate_terminated);
|
||||
/* Currently, NOTIFY is dropped after successful response to unsubscribe */
|
||||
/* But we don't really care.. */
|
||||
/* TEST_1(!e->next); */
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/* Server events: nua_i_subscription with terminated status */
|
||||
TEST_1(e = b->events->head);
|
||||
TEST_E(e->data->e_event, nua_i_subscription);
|
||||
TEST(tl_gets(e->data->e_tags,
|
||||
NEATAG_SUB_REF(sub),
|
||||
NUTAG_SUBSTATE_REF(substate),
|
||||
TAG_END()), 2);
|
||||
TEST_1(sub);
|
||||
TEST(substate, nua_substate_terminated);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.5: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Fetch event, SUBSCRIBE with expires: 0
|
||||
|
||||
A B
|
||||
| |
|
||||
|------SUBSCRIBE---->|
|
||||
|<--------202--------|
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.5.1: event fetch\n");
|
||||
|
||||
SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_ACCEPT_STR("application/pidf+xml"),
|
||||
SIPTAG_EXPIRES_STR("0"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified_and_responded,
|
||||
-1, save_until_subscription);
|
||||
|
||||
/* Client events:
|
||||
nua_subscribe(), nua_i_notify/nua_r_subscribe
|
||||
*/
|
||||
TEST_1(en = event_by_type(a->events->head, nua_i_notify));
|
||||
TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));
|
||||
|
||||
e = es; TEST_E(e->data->e_event, nua_r_subscribe);
|
||||
TEST_1(t = tl_find(e->data->e_tags, nutag_substate));
|
||||
TEST_1(t->t_value == nua_substate_pending ||
|
||||
t->t_value == nua_substate_terminated ||
|
||||
t->t_value == nua_substate_embryonic);
|
||||
|
||||
e = en; TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
n_tags = e->data->e_tags;
|
||||
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value,
|
||||
nua_substate_terminated);
|
||||
TEST_1(!en->next || !es->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/*
|
||||
Server events:
|
||||
nua_i_subscription
|
||||
*/
|
||||
TEST_1(e = b->events->head);
|
||||
TEST_E(e->data->e_event, nua_i_subscription);
|
||||
TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1);
|
||||
TEST_1(sub);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.4.1: PASSED\n");
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* 2nd SUBSCRIBE with event id
|
||||
|
||||
A B
|
||||
| |
|
||||
|------SUBSCRIBE---->|
|
||||
|<--------202--------|
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
/* XXX - we should do this before unsubscribing first one */
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.4.2: establishing 2nd subscription\n");
|
||||
|
||||
NOTIFIER(b, b_call, b_call->nh,
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"),
|
||||
SIPTAG_PAYLOAD_STR(open),
|
||||
NEATAG_THROTTLE(1),
|
||||
NUTAG_SUBSTATE(nua_substate_pending),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_notifier, until_final_response);
|
||||
|
||||
NOTIFIER(b, b_call, b_call->nh,
|
||||
SIPTAG_EVENT_STR("presence"),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"),
|
||||
SIPTAG_PAYLOAD_STR(closed),
|
||||
NEATAG_THROTTLE(1),
|
||||
NEATAG_FAKE(1),
|
||||
NUTAG_SUBSTATE(nua_substate_pending),
|
||||
TAG_END());
|
||||
run_b_until(ctx, nua_r_notifier, until_final_response);
|
||||
|
||||
SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
|
||||
SIPTAG_EVENT_STR("presence;id=1"),
|
||||
SIPTAG_ACCEPT_STR("application/xpidf+xml"),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified_and_responded,
|
||||
-1, save_until_subscription);
|
||||
|
||||
/* Client events:
|
||||
nua_subscribe(), nua_i_notify/nua_r_subscribe
|
||||
*/
|
||||
TEST_1(en = event_by_type(a->events->head, nua_i_notify));
|
||||
TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));
|
||||
|
||||
e = es; TEST_E(e->data->e_event, nua_r_subscribe);
|
||||
TEST_1(t = tl_find(e->data->e_tags, nutag_substate));
|
||||
TEST_1(t->t_value == nua_substate_pending ||
|
||||
t->t_value == nua_substate_embryonic);
|
||||
|
||||
e = en; TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
n_tags = e->data->e_tags;
|
||||
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_S(sip->sip_event->o_id, "1");
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
/* Check that we really got "fake" content */
|
||||
TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len,
|
||||
"<basic>closed</basic>", strlen("<basic>closed</basic>")));
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "pending");
|
||||
TEST_1(sip->sip_subscription_state->ss_expires);
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value,
|
||||
nua_substate_pending);
|
||||
TEST_1(!en->next || !es->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/*
|
||||
Server events:
|
||||
nua_i_subscription
|
||||
*/
|
||||
TEST_1(e = b->events->head);
|
||||
TEST_E(e->data->e_event, nua_i_subscription);
|
||||
TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1);
|
||||
TEST_1(sub);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
/* Authorize user A */
|
||||
AUTHORIZE(b, b_call, b_call->nh,
|
||||
NUTAG_SUBSTATE(nua_substate_active),
|
||||
NEATAG_SUB(sub),
|
||||
NEATAG_FAKE(0),
|
||||
TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified,
|
||||
-1, save_until_final_response);
|
||||
|
||||
/* subscriber events:
|
||||
nua_i_notify with NUTAG_SUBSTATE(nua_substate_active)
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_1(sip->sip_content_type);
|
||||
TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml");
|
||||
TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
|
||||
/* Check that we really got real content */
|
||||
TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len,
|
||||
"<basic>open</basic>", strlen("<basic>open</basic>")));
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "active");
|
||||
TEST_1(sip->sip_subscription_state->ss_expires);
|
||||
n_tags = e->data->e_tags;
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active);
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
/*
|
||||
Server events:
|
||||
nua_r_authorize
|
||||
*/
|
||||
TEST_1(e = b->events->head);
|
||||
TEST_E(e->data->e_event, nua_r_authorize);
|
||||
TEST_1(!e->next);
|
||||
|
||||
free_events_in_list(ctx, b->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.4: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/* NOTIFY terminating subscription
|
||||
|
||||
A B
|
||||
| |
|
||||
|<------NOTIFY-------|
|
||||
|-------200 OK------>|
|
||||
| |
|
||||
*/
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.6: terminate notifier\n");
|
||||
|
||||
TERMINATE(b, b_call, b_call->nh, TAG_END());
|
||||
|
||||
run_ab_until(ctx, -1, save_until_notified, -1, until_final_response);
|
||||
|
||||
/* Client events:
|
||||
nua_i_notify
|
||||
*/
|
||||
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
|
||||
TEST_1(sip = sip_object(e->data->e_msg));
|
||||
TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
|
||||
TEST_S(sip->sip_event->o_id, "1");
|
||||
TEST_1(sip->sip_subscription_state);
|
||||
TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
|
||||
TEST_1(!sip->sip_subscription_state->ss_expires);
|
||||
n_tags = e->data->e_tags;
|
||||
TEST_1(tl_find(n_tags, nutag_substate));
|
||||
TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated);
|
||||
TEST_1(!e->next);
|
||||
free_events_in_list(ctx, a->events);
|
||||
|
||||
if (print_headings)
|
||||
printf("TEST NUA-12.6: PASSED\n");
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
|
||||
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
|
||||
|
||||
END(); /* test_events */
|
||||
}
|
||||
Reference in new issue
Block a user