From 4357c2aca4f9855649f7492f75a11c53726df8d1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 4 Mar 2009 20:41:38 +0000 Subject: [PATCH] Wed Mar 4 12:37:47 CST 2009 Pekka Pessi * nua: moved contents of test_s2.[hc] to check_nua.[hc] Ignore-this: f53929b29092e2d62e661fc40397492e git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12422 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/sofia-sip/.update | 2 +- .../sofia-sip/libsofia-sip-ua/nua/Makefile.am | 3 +- .../libsofia-sip-ua/nua/check_etsi.c | 4 +- .../sofia-sip/libsofia-sip-ua/nua/check_nua.c | 403 ++++++++++++++++- .../sofia-sip/libsofia-sip-ua/nua/check_nua.h | 99 +++++ .../libsofia-sip-ua/nua/check_register.c | 4 +- .../libsofia-sip-ua/nua/check_session.c | 10 +- .../libsofia-sip-ua/nua/check_simple.c | 4 +- libs/sofia-sip/libsofia-sip-ua/nua/test_s2.c | 416 ------------------ libs/sofia-sip/libsofia-sip-ua/nua/test_s2.h | 102 ----- 10 files changed, 511 insertions(+), 536 deletions(-) delete mode 100644 libs/sofia-sip/libsofia-sip-ua/nua/test_s2.c delete mode 100644 libs/sofia-sip/libsofia-sip-ua/nua/test_s2.h diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index 1f8d9e606d..9c37c1fc96 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Wed Mar 4 14:39:41 CST 2009 +Wed Mar 4 14:40:17 CST 2009 diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/Makefile.am b/libs/sofia-sip/libsofia-sip-ua/nua/Makefile.am index 18405129af..9709173caa 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/Makefile.am +++ b/libs/sofia-sip/libsofia-sip-ua/nua/Makefile.am @@ -49,8 +49,7 @@ COVERAGE_INPUT = $(libnua_la_SOURCES) $(include_sofia_HEADERS) check_nua_SOURCES = check_nua.c check_nua.h \ check_session.c check_register.c \ - check_etsi.c check_simple.c \ - test_s2.h test_s2.c + check_etsi.c check_simple.c check_nua_LDADD = $(nua_libs) ${top_builddir}/s2check/libs2.a \ @CHECK_LIBS@ diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_etsi.c b/libs/sofia-sip/libsofia-sip-ua/nua/check_etsi.c index 0646b30b0d..c2f73c94d5 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_etsi.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_etsi.c @@ -34,9 +34,9 @@ #include "config.h" -#include "check_nua.h" +#undef NDEBUG -#include "test_s2.h" +#include "check_nua.h" #include #include diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.c b/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.c index a0ab993b23..fcc79debc1 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.c @@ -22,7 +22,7 @@ * */ -/**@CFILE check2_sofia.c +/**@CFILE check_nua.c * * @brief Check-driven tester for Sofia SIP User Agent library * @@ -33,16 +33,26 @@ #include "config.h" -#include "test_s2.h" +#undef NDEBUG + #include "check_nua.h" +#include "s2dns.h" + +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include - -#if HAVE_FNMATCH_H -#include -#endif +#include +#include +#include static void usage(int exitcode) { @@ -111,3 +121,384 @@ int main(int argc, char *argv[]) exit(failed ? EXIT_FAILURE : EXIT_SUCCESS); } + +/* ---------------------------------------------------------------------- */ + +/* -- Globals -------------------------------------------------------------- */ + +struct s2nua *s2; + +int s2_nua_thread = 0; + +unsigned s2_default_registration_duration = 3600; + +char const s2_auth_digest_str[] = + "Digest realm=\"s2test\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "qop=\"auth\", " + "algorithm=\"MD5\""; + +char const s2_auth_credentials[] = "Digest:\"s2test\":abc:abc"; + +char const s2_auth2_digest_str[] = + "Digest realm=\"s2test2\", " + "nonce=\"fb0c093dcd98b7102dd2f0e8b11d0f600b\", " + "qop=\"auth\", " + "algorithm=\"MD5\""; + +char const s2_auth2_credentials[] = "Digest:\"s2test2\":abc:abc"; + +char const s2_auth3_digest_str[] = + "Digest realm=\"s2test3\", " + "nonce=\"e8b11d0f600bfb0c093dcd98b7102dd2f0\", " + "qop=\"auth-int\", " + "algorithm=\"MD5-sess\""; + +char const s2_auth3_credentials[] = "Digest:\"s2test3\":abc:abc"; + +/* -- NUA events -------------------------------------------------------- */ + +struct event *s2_remove_event(struct event *e) +{ + if ((*e->prev = e->next)) + e->next->prev = e->prev; + + e->prev = NULL, e->next = NULL; + + return e; +} + +void s2_free_event(struct event *e) +{ + if (e) { + if (e->prev) { + if ((*e->prev = e->next)) + e->next->prev = e->prev; + } + nua_destroy_event(e->event); + nua_handle_unref(e->nh); + free(e); + } +} + +void s2_flush_events(void) +{ + while (s2->events) { + s2_free_event(s2->events); + } +} + +struct event *s2_next_event(void) +{ + for (;;) { + if (s2->events) + return s2_remove_event(s2->events); + + su_root_step(s2base->root, 100); + } +} + +struct event *s2_wait_for_event(nua_event_t event, int status) +{ + struct event *e; + + for (;;) { + for (e = s2->events; e; e = e->next) { + if (event != nua_i_none && event != e->data->e_event) + continue; + if (status && e->data->e_status != status) + continue; + return s2_remove_event(e); + } + + su_root_step(s2base->root, 100); + } +} + +int s2_check_event(nua_event_t event, int status) +{ + struct event *e = s2_wait_for_event(event, status); + s2_free_event(e); + return e != NULL; +} + +int s2_check_callstate(enum nua_callstate state) +{ + int retval = 0; + tagi_t const *tagi; + struct event *e; + + e = s2_wait_for_event(nua_i_state, 0); + if (e) { + tagi = tl_find(e->data->e_tags, nutag_callstate); + if (tagi) { + retval = (tag_value_t)state == tagi->t_value; + } + } + s2_free_event(e); + return retval; +} + +int s2_check_substate(struct event *e, enum nua_substate state) +{ + int retval = 0; + tagi_t const *tagi; + + tagi = tl_find(e->data->e_tags, nutag_substate); + if (tagi) { + retval = (tag_value_t)state == tagi->t_value; + } + + return retval; +} + +static void +s2_nua_callback(nua_event_t event, + int status, char const *phrase, + nua_t *nua, nua_magic_t *_t, + nua_handle_t *nh, nua_hmagic_t *hmagic, + sip_t const *sip, + tagi_t tags[]) +{ + struct event *e, **prev; + + if (event == nua_i_active || event == nua_i_terminated) + return; + + e = calloc(1, sizeof *e); + nua_save_event(nua, e->event); + e->nh = nua_handle_ref(nh); + e->data = nua_event_data(e->event); + + for (prev = &s2->events; *prev; prev = &(*prev)->next) + ; + + *prev = e, e->prev = prev; +} + + +/* ====================================================================== */ + +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[]; + +void +s2_setup_logs(int level) +{ + 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); +} + +nua_t *s2_nua_setup(char const *label, + tag_type_t tag, tag_value_t value, ...) +{ + ta_list ta; + + s2_setup(label); + + s2 = su_home_new(sizeof *s2); + + s2_dns_setup(s2base->root); + + s2_setup_logs(0); + s2_sip_setup("example.org", NULL, TAG_END()); + assert(s2sip->contact); + + s2_dns_domain("example.org", 1, + "s2", 1, s2sip->udp.contact->m_url, + "s2", 1, s2sip->tcp.contact->m_url, + NULL); + + /* enable/disable multithreading */ + su_root_threading(s2base->root, s2_nua_thread); + + ta_start(ta, tag, value); + s2->nua = + nua_create(s2base->root, + s2_nua_callback, + s2, + SIPTAG_FROM_STR("Alice "), + /* NUTAG_PROXY((url_string_t *)s2sip->contact->m_url), */ + /* Use internal DNS server */ + NUTAG_PROXY("sip:example.org"), + /* Force sresolv to use localhost and s2dns as DNS server */ +#if HAVE_WIN32 + SRESTAG_RESOLV_CONF("NUL"), +#else + SRESTAG_RESOLV_CONF("/dev/null"), +#endif + ta_tags(ta)); + ta_end(ta); + + return s2->nua; +} + +void +s2_nua_fast_forward(unsigned long seconds, + su_root_t *steproot) +{ + s2_fast_forward(seconds, NULL); + + if (s2_nua_thread) + /* Wake up nua thread */ + nua_handle_by_call_id(s2->nua, NULL); + + if (steproot) + su_root_step(steproot, 0); +} + +void s2_nua_teardown(void) +{ + if (s2) { + struct s2nua *zap = s2; + nua_destroy(s2->nua), s2->nua = NULL; + s2 = NULL; + su_home_unref(zap->home); + } + + s2_dns_teardown(); + s2_sip_teardown(); + s2_teardown(); + +} + +/* ====================================================================== */ + +/** Register NUA user. + * + *
+ *  A                  B
+ *  |-----REGISTER---->|
+ *  |<-----200 OK------|
+ *  |                  |
+ * 
+ */ +void s2_register_setup(void) +{ + nua_handle_t *nh; + struct message *m; + + assert(s2 && s2->nua); + assert(!s2->registration->nh); + + nh = nua_handle(s2->nua, NULL, TAG_END()); + + nua_register(nh, TAG_END()); + + m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); + assert(m); + + s2_save_register(m); + + s2_sip_respond_to(m, NULL, + SIP_200_OK, + SIPTAG_CONTACT(s2->registration->contact), + TAG_END()); + s2_sip_free_message(m); + + assert(s2->registration->contact != NULL); + s2_check_event(nua_r_register, 200); + + s2->registration->nh = nh; +} + +/** Un-register NUA user. + * + *
+ *  A                  B
+ *  |-----REGISTER---->|
+ *  |<-----200 OK------|
+ *  |                  |
+ * 
+ */ +void s2_register_teardown(void) +{ + if (s2 && s2->registration->nh) { + nua_handle_t *nh = s2->registration->nh; + struct message *m; + + nua_unregister(nh, TAG_END()); + + m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); assert(m); + s2_save_register(m); + s2_sip_respond_to(m, NULL, + SIP_200_OK, + SIPTAG_CONTACT(s2->registration->contact), + TAG_END()); + assert(s2->registration->contact == NULL); + + s2_sip_free_message(m); + + s2_check_event(nua_r_unregister, 200); + + nua_handle_destroy(nh); + s2->registration->nh = NULL; + } +} + +int +s2_save_register(struct message *rm) +{ + sip_contact_t *contact, *m, **m_prev; + sip_expires_t const *ex; + sip_date_t const *date; + sip_time_t now = rm->when.tv_sec, expires; + + msg_header_free_all(s2->home, (msg_header_t *)s2->registration->aor); + msg_header_free_all(s2->home, (msg_header_t *)s2->registration->contact); + tport_unref(s2->registration->tport); + + s2->registration->aor = NULL; + s2->registration->contact = NULL; + s2->registration->tport = NULL; + + if (rm == NULL) + return 0; + + assert(rm && rm->sip && rm->sip->sip_request); + assert(rm->sip->sip_request->rq_method == sip_method_register); + + ex = rm->sip->sip_expires; + date = rm->sip->sip_date; + + contact = sip_contact_dup(s2->home, rm->sip->sip_contact); + + for (m_prev = &contact; *m_prev;) { + m = *m_prev; + + expires = sip_contact_expires(m, ex, date, + s2_default_registration_duration, + now); + if (expires) { + char *p = su_sprintf(s2->home, "expires=%lu", (unsigned long)expires); + msg_header_add_param(s2->home, m->m_common, p); + m_prev = &m->m_next; + } + else { + *m_prev = m->m_next; + m->m_next = NULL; + msg_header_free(s2->home, (msg_header_t *)m); + } + } + + if (contact == NULL) + return 0; + + s2->registration->aor = sip_to_dup(s2->home, rm->sip->sip_to); + s2->registration->contact = contact; + s2->registration->tport = tport_ref(rm->tport); + + s2sip->sut.aor = s2->registration->aor; + s2sip->sut.contact = s2->registration->contact; + s2sip->sut.tport = s2->registration->tport; + + return 0; +} diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.h b/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.h index e7a68187f9..aba4f1c6e3 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_nua.h @@ -1,5 +1,104 @@ +/* + * This file is part of the Sofia-SIP package + * + * Copyright (C) 2008 Nokia Corporation. + * + * Contact: Pekka Pessi + * + * 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 CHECK_NUA_H +#include +#include +#include +#include +#include + +#include "s2base.h" +#include "s2util.h" +#include "s2sip.h" + +struct s2nua +{ + su_home_t home[1]; + + nua_t *nua; + + int shutdown; + + 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]; +}; + +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[]; + +extern int s2_nua_thread; + +extern struct s2nua *s2; + +void s2_setup_logs(int level); + +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); +int s2_check_substate(struct event *e, enum nua_substate state); + +#define SIP_METHOD_UNKNOWN sip_method_unknown, NULL + +void s2_flush_all(void); + +nua_t *s2_nua_setup(char const *label, tag_type_t tag, tag_value_t value, ...); + +void s2_nua_teardown(void); + +void s2_nua_fast_forward(unsigned long seconds, + su_root_t *steproot); + +int s2_save_register(struct message *m); + +void s2_register_setup(void); +void s2_register_teardown(void); + #include void check_session_cases(Suite *suite, int threading); diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c b/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c index b2971c8460..95e05726e1 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c @@ -33,9 +33,9 @@ #include "config.h" -#include "check_nua.h" +#undef NDEBUG -#include "test_s2.h" +#include "check_nua.h" #include #include diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c b/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c index df9dd388fb..ef39617ef9 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c @@ -33,9 +33,9 @@ #include "config.h" -#include "check_nua.h" +#undef NDEBUG -#include "test_s2.h" +#include "check_nua.h" #include #include @@ -1131,7 +1131,11 @@ START_TEST(cancel_2_2_10) s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END()); s2_sip_free_message(cancel); - s2_register_teardown(); + /* emulate network gone bad below + zap registration handle here + so that s2_register_teardown() does not hang + */ + s2->registration->nh = NULL; nua_set_params(s2->nua, NUTAG_SHUTDOWN_EVENTS(1), TAG_END()); fail_unless(s2_check_event(nua_r_set_params, 200)); diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/check_simple.c b/libs/sofia-sip/libsofia-sip-ua/nua/check_simple.c index 6e69158edf..e4f236d177 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/check_simple.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/check_simple.c @@ -33,9 +33,9 @@ #include "config.h" -#include "check_nua.h" +#undef NDEBUG -#include "test_s2.h" +#include "check_nua.h" #include #include diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.c b/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.c deleted file mode 100644 index c4e560a15e..0000000000 --- a/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - * This file is part of the Sofia-SIP package - * - * Copyright (C) 2008 Nokia Corporation. - * - * Contact: Pekka Pessi - * - * 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 s2tester.c - * @brief 2nd test Suite for Sofia SIP User Agent Engine - * - * @author Pekka Pessi - * - * @date Created: Wed Apr 30 12:48:27 EEST 2008 ppessi - */ - -#include "config.h" - -#undef NDEBUG - -#define TP_MAGIC_T struct tp_magic_s - -#include "test_s2.h" -#include "s2dns.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -/* -- Globals -------------------------------------------------------------- */ - -struct s2nua *s2; - -int s2_nua_thread = 0; - -unsigned s2_default_registration_duration = 3600; - -char const s2_auth_digest_str[] = - "Digest realm=\"s2test\", " - "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " - "qop=\"auth\", " - "algorithm=\"MD5\""; - -char const s2_auth_credentials[] = "Digest:\"s2test\":abc:abc"; - -char const s2_auth2_digest_str[] = - "Digest realm=\"s2test2\", " - "nonce=\"fb0c093dcd98b7102dd2f0e8b11d0f600b\", " - "qop=\"auth\", " - "algorithm=\"MD5\""; - -char const s2_auth2_credentials[] = "Digest:\"s2test2\":abc:abc"; - -char const s2_auth3_digest_str[] = - "Digest realm=\"s2test3\", " - "nonce=\"e8b11d0f600bfb0c093dcd98b7102dd2f0\", " - "qop=\"auth-int\", " - "algorithm=\"MD5-sess\""; - -char const s2_auth3_credentials[] = "Digest:\"s2test3\":abc:abc"; - -/* -- NUA events -------------------------------------------------------- */ - -struct event *s2_remove_event(struct event *e) -{ - if ((*e->prev = e->next)) - e->next->prev = e->prev; - - e->prev = NULL, e->next = NULL; - - return e; -} - -void s2_free_event(struct event *e) -{ - if (e) { - if (e->prev) { - if ((*e->prev = e->next)) - e->next->prev = e->prev; - } - nua_destroy_event(e->event); - nua_handle_unref(e->nh); - free(e); - } -} - -void s2_flush_events(void) -{ - while (s2->events) { - s2_free_event(s2->events); - } -} - -struct event *s2_next_event(void) -{ - for (;;) { - if (s2->events) - return s2_remove_event(s2->events); - - su_root_step(s2base->root, 100); - } -} - -struct event *s2_wait_for_event(nua_event_t event, int status) -{ - struct event *e; - - for (;;) { - for (e = s2->events; e; e = e->next) { - if (event != nua_i_none && event != e->data->e_event) - continue; - if (status && e->data->e_status != status) - continue; - return s2_remove_event(e); - } - - su_root_step(s2base->root, 100); - } -} - -int s2_check_event(nua_event_t event, int status) -{ - struct event *e = s2_wait_for_event(event, status); - s2_free_event(e); - return e != NULL; -} - -int s2_check_callstate(enum nua_callstate state) -{ - int retval = 0; - tagi_t const *tagi; - struct event *e; - - e = s2_wait_for_event(nua_i_state, 0); - if (e) { - tagi = tl_find(e->data->e_tags, nutag_callstate); - if (tagi) { - retval = (tag_value_t)state == tagi->t_value; - } - } - s2_free_event(e); - return retval; -} - -int s2_check_substate(struct event *e, enum nua_substate state) -{ - int retval = 0; - tagi_t const *tagi; - - tagi = tl_find(e->data->e_tags, nutag_substate); - if (tagi) { - retval = (tag_value_t)state == tagi->t_value; - } - - return retval; -} - -static void -s2_nua_callback(nua_event_t event, - int status, char const *phrase, - nua_t *nua, nua_magic_t *_t, - nua_handle_t *nh, nua_hmagic_t *hmagic, - sip_t const *sip, - tagi_t tags[]) -{ - struct event *e, **prev; - - if (event == nua_i_active || event == nua_i_terminated) - return; - - e = calloc(1, sizeof *e); - nua_save_event(nua, e->event); - e->nh = nua_handle_ref(nh); - e->data = nua_event_data(e->event); - - for (prev = &s2->events; *prev; prev = &(*prev)->next) - ; - - *prev = e, e->prev = prev; -} - - -/* ====================================================================== */ - -nua_t *s2_nua_setup(char const *label, - tag_type_t tag, tag_value_t value, ...) -{ - ta_list ta; - - s2_setup(label); - - s2 = su_home_new(sizeof *s2); - - s2_dns_setup(s2base->root); - - s2_setup_logs(0); - s2_sip_setup("example.org", NULL, TAG_END()); - assert(s2sip->contact); - - s2_dns_domain("example.org", 1, - "s2", 1, s2sip->udp.contact->m_url, - "s2", 1, s2sip->tcp.contact->m_url, - NULL); - - /* enable/disable multithreading */ - su_root_threading(s2base->root, s2_nua_thread); - - ta_start(ta, tag, value); - s2->nua = - nua_create(s2base->root, - s2_nua_callback, - s2, - SIPTAG_FROM_STR("Alice "), - /* NUTAG_PROXY((url_string_t *)s2sip->contact->m_url), */ - /* Use internal DNS server */ - NUTAG_PROXY("sip:example.org"), - /* Force sresolv to use localhost and s2dns as DNS server */ -#if HAVE_WIN32 - SRESTAG_RESOLV_CONF("NUL"), -#else - SRESTAG_RESOLV_CONF("/dev/null"), -#endif - ta_tags(ta)); - ta_end(ta); - - return s2->nua; -} - -void -s2_nua_fast_forward(unsigned long seconds, - su_root_t *steproot) -{ - s2_fast_forward(seconds, NULL); - - if (s2_nua_thread) - /* Wake up nua thread */ - nua_handle_by_call_id(s2->nua, NULL); - - if (steproot) - su_root_step(steproot, 0); -} - -void s2_nua_teardown(void) -{ - if (s2) { - struct s2nua *zap = s2; - nua_destroy(s2->nua), s2->nua = NULL; - s2 = NULL; - su_home_unref(zap->home); - } - - s2_dns_teardown(); - s2_sip_teardown(); - s2_teardown(); - -} - -/* ====================================================================== */ - -/** Register NUA user. - * - *
- *  A                  B
- *  |-----REGISTER---->|
- *  |<-----200 OK------|
- *  |                  |
- * 
- */ -void s2_register_setup(void) -{ - nua_handle_t *nh; - struct message *m; - - assert(s2 && s2->nua); - assert(!s2->registration->nh); - - nh = nua_handle(s2->nua, NULL, TAG_END()); - - nua_register(nh, TAG_END()); - - m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); - assert(m); - - s2_save_register(m); - - s2_sip_respond_to(m, NULL, - SIP_200_OK, - SIPTAG_CONTACT(s2->registration->contact), - TAG_END()); - s2_sip_free_message(m); - - assert(s2->registration->contact != NULL); - s2_check_event(nua_r_register, 200); - - s2->registration->nh = nh; -} - -/** Un-register NUA user. - * - *
- *  A                  B
- *  |-----REGISTER---->|
- *  |<-----200 OK------|
- *  |                  |
- * 
- */ -void s2_register_teardown(void) -{ - if (s2 && s2->registration->nh) { - nua_handle_t *nh = s2->registration->nh; - struct message *m; - - nua_unregister(nh, TAG_END()); - - m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); assert(m); - s2_save_register(m); - s2_sip_respond_to(m, NULL, - SIP_200_OK, - SIPTAG_CONTACT(s2->registration->contact), - TAG_END()); - assert(s2->registration->contact == NULL); - - s2_sip_free_message(m); - - s2_check_event(nua_r_unregister, 200); - - nua_handle_destroy(nh); - s2->registration->nh = NULL; - } -} - -int -s2_save_register(struct message *rm) -{ - sip_contact_t *contact, *m, **m_prev; - sip_expires_t const *ex; - sip_date_t const *date; - sip_time_t now = rm->when.tv_sec, expires; - - msg_header_free_all(s2->home, (msg_header_t *)s2->registration->aor); - msg_header_free_all(s2->home, (msg_header_t *)s2->registration->contact); - tport_unref(s2->registration->tport); - - s2->registration->aor = NULL; - s2->registration->contact = NULL; - s2->registration->tport = NULL; - - if (rm == NULL) - return 0; - - assert(rm && rm->sip && rm->sip->sip_request); - assert(rm->sip->sip_request->rq_method == sip_method_register); - - ex = rm->sip->sip_expires; - date = rm->sip->sip_date; - - contact = sip_contact_dup(s2->home, rm->sip->sip_contact); - - for (m_prev = &contact; *m_prev;) { - m = *m_prev; - - expires = sip_contact_expires(m, ex, date, - s2_default_registration_duration, - now); - if (expires) { - char *p = su_sprintf(s2->home, "expires=%lu", (unsigned long)expires); - msg_header_add_param(s2->home, m->m_common, p); - m_prev = &m->m_next; - } - else { - *m_prev = m->m_next; - m->m_next = NULL; - msg_header_free(s2->home, (msg_header_t *)m); - } - } - - if (contact == NULL) - return 0; - - s2->registration->aor = sip_to_dup(s2->home, rm->sip->sip_to); - s2->registration->contact = contact; - s2->registration->tport = tport_ref(rm->tport); - - s2sip->sut.aor = s2->registration->aor; - s2sip->sut.contact = s2->registration->contact; - s2sip->sut.tport = s2->registration->tport; - - return 0; -} diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.h b/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.h deleted file mode 100644 index 6004e6d26c..0000000000 --- a/libs/sofia-sip/libsofia-sip-ua/nua/test_s2.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of the Sofia-SIP package - * - * Copyright (C) 2008 Nokia Corporation. - * - * Contact: Pekka Pessi - * - * 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 - -#include -#include -#include -#include -#include - -#include "s2base.h" -#include "s2util.h" -#include "s2sip.h" - -struct s2nua -{ - su_home_t home[1]; - - nua_t *nua; - - int shutdown; - - 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]; -}; - -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[]; - -extern int s2_nua_thread; - -extern struct s2nua *s2; - -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); -int s2_check_substate(struct event *e, enum nua_substate state); - -#define SIP_METHOD_UNKNOWN sip_method_unknown, NULL - -void s2_flush_all(void); - -nua_t *s2_nua_setup(char const *label, tag_type_t tag, tag_value_t value, ...); - -void s2_nua_teardown(void); - -void s2_nua_fast_forward(unsigned long seconds, - su_root_t *steproot); - -int s2_save_register(struct message *m); - -void s2_register_setup(void); -void s2_register_teardown(void); - -#endif -