示例#1
0
static void destructor(void *arg)
{
	struct sip_server *srv = arg;

	sip_close(srv->sip, false);
	mem_deref(srv->sip);

	mem_deref(srv->us);
}
示例#2
0
文件: sip_ua.c 项目: chk-jxcn/redemo
/* terminate */
static void terminate(void)
{
	/* terminate session */
	sess = mem_deref(sess);

	/* terminate registration */
	reg = mem_deref(reg);

	/* wait for pending transactions to finish */
	sip_close(sip, false);
}
示例#3
0
static int reg_test(enum sip_transp tp)
{
    struct test test;
    struct sip_server *srv = NULL;
    struct sipreg *reg = NULL;
    struct sip *sip = NULL;
    char reg_uri[256];
    int err;

    memset(&test, 0, sizeof(test));
    test.tp = tp;

    err = sip_server_alloc(&srv);
    if (err)
        goto out;

    err = sipstack_fixture(&sip);
    if (err)
        goto out;

    err = sip_server_uri(srv, reg_uri, sizeof(reg_uri), tp);
    if (err)
        goto out;

    err = sipreg_register(&reg, sip, reg_uri,
                          "sip:x@test",
                          "sip:x@test",
                          3600, "x", NULL, 0, 0, NULL, NULL, false,
                          sip_resp_handler, &test, NULL, NULL);
    if (err)
        goto out;

    err = re_main_timeout(800);
    if (err)
        goto out;

    TEST_ERR(test.err);

    TEST_ASSERT(srv->n_register_req > 0);
    TEST_ASSERT(test.n_resp > 0);

out:
    mem_deref(reg);

    sip_close(sip, true);
    mem_deref(sip);

    mem_deref(srv);

    return err;
}
示例#4
0
/**
 * 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);
}
示例#5
0
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;
}