/** * Stop all User-Agents * * @param forced True to force, otherwise false */ void ua_stop_all(bool forced) { module_app_unload(); if (!list_isempty(&uag.ual)) { const uint32_t n = list_count(&uag.ual); info("Stopping %u useragent%s.. %s\n", n, n==1 ? "" : "s", forced ? "(Forced)" : ""); } if (forced) sipsess_close_all(uag.sock); else list_flush(&uag.ual); sip_close(uag.sip, forced); }
int test_sipsess(void) { struct test test; struct sa laddr; char to_uri[256]; int err; uint16_t port; memset(&test, 0, sizeof(test)); #ifndef WIN32 /* slurp warnings from SIP (todo: temp) */ (void)freopen("/dev/null", "w", stderr); #endif err = sip_alloc(&test.sip, NULL, 32, 32, 32, "retest", exit_handler, NULL); if (err) goto out; (void)sa_set_str(&laddr, "127.0.0.1", 0); err = sip_transp_add(test.sip, SIP_TRANSP_UDP, &laddr); if (err) goto out; err = sip_transp_laddr(test.sip, &laddr, SIP_TRANSP_UDP, NULL); if (err) goto out; port = sa_port(&laddr); err = sipsess_listen(&test.sock, test.sip, 32, conn_handler, &test); if (err) goto out; /* Connect to "b" */ (void)re_snprintf(to_uri, sizeof(to_uri), "sip:[email protected]:%u", port); err = sipsess_connect(&test.a, test.sock, to_uri, NULL, "sip:[email protected]", "a", NULL, 0, "application/sdp", NULL, NULL, NULL, false, offer_handler, answer_handler, NULL, estab_handler_a, NULL, NULL, close_handler, &test, NULL); if (err) goto out; err = re_main_timeout(200); if (err) goto out; if (test.err) { err = test.err; goto out; } /* okay here -- verify */ TEST_ASSERT(test.estab_a); TEST_ASSERT(test.estab_b); out: test.a = mem_deref(test.a); test.b = mem_deref(test.b); sipsess_close_all(test.sock); test.sock = mem_deref(test.sock); sip_close(test.sip, false); test.sip = mem_deref(test.sip); #ifndef WIN32 /* Restore stderr */ freopen("/dev/tty", "w", stderr); #endif return err; }