Exemple #1
0
int main(int argc, char *argv[]) {
    int err;
    struct shouter app;
    libre_init();

    err = tcsound_alloc(&app.sound, asend, &app);
    if(err != 0)
        goto fail;

    err = rtp_io_alloc(&app.rtp, FMT_SPEEX);
    if(err != 0)
        goto close_sound;

    tcsound_start(app.sound);

    re_main(signal_handler);

close_sound:
    mem_deref(app.sound);
fail:
    tmr_debug();
    mem_debug();

    ENGINE_cleanup();


fail_sound:
    libre_close();
}
Exemple #2
0
static void exit_handler(void)
{
	libre_close();

	/* Check for memory leaks */
	tmr_debug();
	mem_debug();
}
Exemple #3
0
int main(int argc, char *argv[])
{
	const char *filename_wav, *filename_png;
	kiss_fftr_cfg fft;
	int err = 0;

	for (;;) {

		const int c = getopt(argc, argv, "h");
		if (0 > c)
			break;

		switch (c) {

		case '?':
			err = EINVAL;
			/*@fallthrough@*/
		case 'h':
			usage();
			return err;
		}
	}

	if (argc < 3 || argc != (optind + 2)) {
		usage();
		return -EINVAL;
	}

	filename_wav = argv[optind++];
	filename_png = argv[optind++];

	fft = kiss_fftr_alloc(NUM_FFT, 0, 0, 0);
	if (!fft) {
		err = ENOMEM;
		goto out;
	}

	err = read_wav(fft, filename_wav);
	if (err)
		goto out;
 
	err = plot_spectrum(filename_png);
	if (err)
		goto out;

 out:
	if (fft)
		kiss_fftr_free(fft);

	tmr_debug();
	mem_debug();

	return err;
}
Exemple #4
0
int main(void)
{
	struct sa laddr;
	int err; /* errno return values */

	/* enable coredumps to aid debugging */
	(void)sys_coredump_set(true);

	/* initialize libre state */
	err = libre_init();
	if (err) {
		re_fprintf(stderr, "re init failed: %s\n", strerror(err));
		goto out;
	}

	(void)sa_set_str(&laddr, "0.0.0.0", 3456);

	/* Create listening TCP socket, IP address 0.0.0.0, TCP port 3456 */
	err = tcp_listen(&ts, &laddr, connect_handler, NULL);
	if (err) {
		re_fprintf(stderr, "tcp listen error: %s\n", strerror(err));
		goto out;
	}

	re_printf("listening on TCP socket: %J\n", &laddr);

	/* main loop */
	err = re_main(signal_handler);

 out:
	/* destroy active TCP connections */
	list_flush(&connl);

	/* free TCP socket */
	ts = mem_deref(ts);

	/* free library state */
	libre_close();

	/* check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #5
0
int main(int argc, char *argv[])
{
	bool prefer_ipv6 = false, run_daemon = false, test = false;
	const char *ua_eprm = NULL;
	const char *exec = NULL;
	const char *modv[16];
	size_t modc = 0;
	int err;

	(void)re_fprintf(stderr, "baresip v%s"
			 " Copyright (C) 2010 - 2015"
			 " Alfred E. Heggestad et al.\n",
			 BARESIP_VERSION);

	(void)sys_coredump_set(true);

	err = libre_init();
	if (err)
		goto out;

#ifdef HAVE_GETOPT
	for (;;) {
		const int c = getopt(argc, argv, "6de:f:p:hu:vtm:");
		if (0 > c)
			break;

		switch (c) {

		case '?':
		case 'h':
			usage();
			return -2;

#if HAVE_INET6
		case '6':
			prefer_ipv6 = true;
			break;
#endif

		case 'd':
			run_daemon = true;
			break;

		case 'e':
			exec = optarg;
			break;

		case 'f':
			conf_path_set(optarg);
			break;

		case 'm':
			if (modc >= ARRAY_SIZE(modv)) {
				warning("max %zu modules\n",
					ARRAY_SIZE(modv));
				err = EINVAL;
				goto out;
			}
			modv[modc++] = optarg;
			break;

		case 'p':
			play_set_path(optarg);
			break;

		case 't':
			test = true;
			break;

		case 'u':
			ua_eprm = optarg;
			break;

		case 'v':
			log_enable_debug(true);
			break;

		default:
			break;
		}
	}
#else
	(void)argc;
	(void)argv;
#endif

	err = conf_configure();
	if (err) {
		warning("main: configure failed: %m\n", err);
		goto out;
	}

	/* NOTE: must be done after all arguments are processed */
	if (modc) {
		size_t i;

		info("pre-loading modules: %zu\n", modc);

		for (i=0; i<modc; i++) {

			err = module_preload(modv[i]);
			if (err) {
				re_fprintf(stderr,
					   "could not pre-load module"
					   " '%s' (%m)\n", modv[i], err);
			}
		}
	}

	/* Initialise User Agents */
	err = ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")",
		      true, true, true, prefer_ipv6);
	if (err)
		goto out;

	if (ua_eprm) {
		err = uag_set_extra_params(ua_eprm);
		if (err)
			goto out;
	}

	if (test)
		goto out;

	/* Load modules */
	err = conf_modules();
	if (err)
		goto out;

	if (run_daemon) {
		err = sys_daemon();
		if (err)
			goto out;

		log_enable_stderr(false);
	}

	info("baresip is ready.\n");

	if (exec)
		ui_input_str(exec);

	/* Main loop */
	err = re_main(signal_handler);

 out:
	if (err)
		ua_stop_all(true);

	ua_close();
	conf_close();

	libre_close();

	/* Check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #6
0
int main(int argc, char *argv[])
{
	bool prefer_ipv6 = false, run_daemon = false, test = false;
	const char *exec = NULL;
	int err;

	(void)re_fprintf(stderr, "baresip v%s"
			 " Copyright (C) 2010 - 2015"
			 " Alfred E. Heggestad et al.\n",
			 BARESIP_VERSION);

	(void)sys_coredump_set(true);

	err = libre_init();
	if (err)
		goto out;

#ifdef HAVE_GETOPT
	for (;;) {
		const int c = getopt(argc, argv, "6de:f:p:hvtm:");
		if (0 > c)
			break;

		switch (c) {

		case '?':
		case 'h':
			usage();
			return -2;

#if HAVE_INET6
		case '6':
			prefer_ipv6 = true;
			break;
#endif

		case 'd':
			run_daemon = true;
			break;

		case 'e':
			exec = optarg;
			break;

		case 'f':
			conf_path_set(optarg);
			break;

		case 'm':
			err = module_preload(optarg);
			if (err) {
				re_fprintf(stderr,
					   "could not pre-load module"
					   " '%s' (%m)\n", optarg, err);
			}
			break;

		case 'p':
			play_set_path(optarg);
			break;

		case 't':
			test = true;
			break;

		case 'v':
			log_enable_debug(true);
			break;

		default:
			break;
		}
	}
#else
	(void)argc;
	(void)argv;
#endif

	err = conf_configure();
	if (err) {
		warning("main: configure failed: %m\n", err);
		goto out;
	}

	/* Initialise User Agents */
	err = ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")",
		      true, true, true, prefer_ipv6);
	if (err)
		goto out;

	if (test)
		goto out;

	/* Load modules */
	err = conf_modules();
	if (err)
		goto out;

	if (run_daemon) {
		err = sys_daemon();
		if (err)
			goto out;

		log_enable_stderr(false);
	}

	info("baresip is ready.\n");

	if (exec)
		ui_input_str(exec);

	/* Main loop */
	err = re_main(signal_handler);

 out:
	if (err)
		ua_stop_all(true);

	ua_close();
	mod_close();

	libre_close();

	/* Check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #7
0
int main(int argc, char *argv[])
{
	const char *cert = NULL;
	int err = 0;

	tlsperf.num = 1;
	tlsperf.proto = IPPROTO_TCP;

	for (;;) {

		const int c = getopt(argc, argv, "a:dc:e:p:n:s:hv");
		if (0 > c)
			break;

		switch (c) {

		case 'c':
			cert = optarg;
			break;

		case 'd':
			tlsperf.proto = IPPROTO_UDP;
			break;

		case 'n':
			tlsperf.num = atoi(optarg);
			break;

		case 'v':
			tlsperf.verbose = true;
			break;

		case '?':
			err = EINVAL;
			/*@fallthrough@*/
		case 'h':
			usage();
			return err;
		}
	}

	err = libre_init();
	if (err)
		goto out;

	re_printf("tlsperf -- TLS performance testing program\n");
	re_printf("build:         %H\n", sys_build_get, 0);
	re_printf("compiler:      %s\n", __VERSION__);
	re_printf("libre:         %s\n", sys_libre_version_get());
	re_printf("os:            %s\n", sys_os_get());
	re_printf("arch:          %s\n", sys_arch_get());

#ifdef USE_OPENSSL
	re_printf("openssl info:  %s\n%s\n",
		  SSLeay_version(SSLEAY_VERSION),
		  SSLeay_version(SSLEAY_CFLAGS));
#endif

	re_printf("protocol:      %s\n",
		  tlsperf.proto == IPPROTO_TCP ? "TLS" : "DTLS");

	err = tls_alloc(&tlsperf.tls, TLS_METHOD_SSLV23, cert, 0);
	if (err)
		goto out;

	if (cert) {
		re_printf("certificate:   %s\n", cert);
	}
	else {
		re_printf("certificate:   selfsigned RSA-1024\n");
		err = tls_set_selfsigned(tlsperf.tls, "a@b");
		if (err)
			goto out;
	}

	re_printf("starting tests now. (num=%u)\n", tlsperf.num);

	/*
	 * Start timing now
	 */

	tlsperf.ts_start = tmr_jiffies();

	err = start_test();
	if (err)
		goto out;

	re_main(0);

 out:
	mem_deref(tlsperf.ep_srv);
	mem_deref(tlsperf.ep_cli);

	mem_deref(tlsperf.tls);

	libre_close();

	/* check for memory leaks */
	mem_debug();
	tmr_debug();

	return err ? err : tlsperf.err;
}
Exemple #8
0
int main(int argc, char *argv[])
{
	bool prefer_ipv6 = false, run_daemon = false;
	const char *exec = NULL;
	int err;

	(void)re_fprintf(stderr, "baresip v%s"
			 " Copyright (C) 2010 - 2014"
			 " Alfred E. Heggestad et al.\n",
			 BARESIP_VERSION);

	(void)sys_coredump_set(true);

#ifdef HAVE_GETOPT
	for (;;) {
		const int c = getopt(argc, argv, "6de:f:hv");
		if (0 > c)
			break;

		switch (c) {

		case '?':
		case 'h':
			(void)re_fprintf(stderr,
					 "Usage: baresip [options]\n"
					 "options:\n"
#if HAVE_INET6
					 "\t-6               Prefer IPv6\n"
#endif
					 "\t-d               Daemon\n"
					 "\t-e <commands>    Exec commands\n"
					 "\t-f <path>        Config path\n"
					 "\t-h -?            Help\n"
					 "\t-v               Verbose debug\n"
					 );
			return -2;

#if HAVE_INET6
		case '6':
			prefer_ipv6 = true;
			break;
#endif

		case 'd':
			run_daemon = true;
			break;

		case 'e':
			exec = optarg;
			break;

		case 'f':
			conf_path_set(optarg);
			break;

		case 'v':
			log_enable_debug(true);
			break;

		default:
			break;
		}
	}
#else
	(void)argc;
	(void)argv;
#endif

	err = libre_init();
	if (err)
		goto out;

	err = conf_configure();
	if (err) {
		warning("main: configure failed: %m\n", err);
		goto out;
	}

	/* Initialise User Agents */
	err = ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")",
		      true, true, true, prefer_ipv6);
	if (err)
		goto out;

	/* Load modules */
	err = conf_modules();
	if (err)
		goto out;

	if (run_daemon) {
		err = sys_daemon();
		if (err)
			goto out;

		log_enable_stderr(false);
	}

	info("baresip is ready.\n");

	if (exec)
		ui_input_str(exec);

	/* Main loop */
	err = re_main(signal_handler);

 out:
	if (err)
		ua_stop_all(true);

	ua_close();
	mod_close();

	libre_close();

	/* Check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #9
0
int main(int argc, char *argv[])
{
	struct sa nsv[16];
	struct dnsc *dnsc = NULL;
	struct sa laddr;
	uint32_t nsc;
	int err; /* errno return values */

	/* enable coredumps to aid debugging */
	(void)sys_coredump_set(true);

	/* initialize libre state */
	err = libre_init();
	if (err) {
		re_fprintf(stderr, "re init failed: %s\n", strerror(err));
		goto out;
	}

	nsc = ARRAY_SIZE(nsv);

	/* fetch list of DNS server IP addresses */
	err = dns_srv_get(NULL, 0, nsv, &nsc);
	if (err) {
		re_fprintf(stderr, "unable to get dns servers: %s\n",
			   strerror(err));
		goto out;
	}

	/* create DNS client */
	err = dnsc_alloc(&dnsc, NULL, nsv, nsc);
	if (err) {
		re_fprintf(stderr, "unable to create dns client: %s\n",
			   strerror(err));
		goto out;
	}

	/* create SIP stack instance */
	err = sip_alloc(&sip, dnsc, 32, 32, 32,
			"ua demo v" VERSION " (" ARCH "/" OS ")",
			exit_handler, NULL);
	if (err) {
		re_fprintf(stderr, "sip error: %s\n", strerror(err));
		goto out;
	}

	/* fetch local IP address */
	err = net_default_source_addr_get(AF_INET, &laddr);
	if (err) {
		re_fprintf(stderr, "local address error: %s\n", strerror(err));
		goto out;
	}

	/* listen on random port */
	sa_set_port(&laddr, 0);

	/* add supported SIP transports */
	err |= sip_transp_add(sip, SIP_TRANSP_UDP, &laddr);
	err |= sip_transp_add(sip, SIP_TRANSP_TCP, &laddr);
	if (err) {
		re_fprintf(stderr, "transport error: %s\n", strerror(err));
		goto out;
	}

	/* create SIP session socket */
	err = sipsess_listen(&sess_sock, sip, 32, connect_handler, NULL);
	if (err) {
		re_fprintf(stderr, "session listen error: %s\n",
			   strerror(err));
		goto out;
	}

	/* create the RTP/RTCP socket */
	err = rtp_listen(&rtp, IPPROTO_UDP, &laddr, 10000, 30000, true,
			 rtp_handler, rtcp_handler, NULL);
	if (err) {
		re_fprintf(stderr, "rtp listen error: %m\n", err);
		goto out;
	}

	re_printf("local RTP port is %u\n", sa_port(rtp_local(rtp)));

	/* create SDP session */
	err = sdp_session_alloc(&sdp, &laddr);
	if (err) {
		re_fprintf(stderr, "sdp session error: %s\n", strerror(err));
		goto out;
	}

	/* add audio sdp media, using port from RTP socket */
	err = sdp_media_add(&sdp_media, sdp, "audio",
			    sa_port(rtp_local(rtp)), "RTP/AVP");
	if (err) {
		re_fprintf(stderr, "sdp media error: %s\n", strerror(err));
		goto out;
	}

	/* add G.711 sdp media format */
	err = sdp_format_add(NULL, sdp_media, false, "0", "PCMU", 8000, 1,
			     NULL, NULL, NULL, false, NULL);
	if (err) {
		re_fprintf(stderr, "sdp format error: %s\n", strerror(err));
		goto out;
	}

	/* invite provided URI */
	if (argc > 1) {

		struct mbuf *mb;

		/* create SDP offer */
		err = sdp_encode(&mb, sdp, true);
		if (err) {
			re_fprintf(stderr, "sdp encode error: %s\n",
				   strerror(err));
			goto out;
		}

		err = sipsess_connect(&sess, sess_sock, argv[1], name,
				      uri, name,
				      NULL, 0, "application/sdp", mb,
				      auth_handler, NULL, false,
				      offer_handler, answer_handler,
				      progress_handler, establish_handler,
				      NULL, NULL, close_handler, NULL, NULL);
		mem_deref(mb); /* free SDP buffer */
		if (err) {
			re_fprintf(stderr, "session connect error: %s\n",
				   strerror(err));
			goto out;
		}

		re_printf("inviting <%s>...\n", argv[1]);
	}
	else {

		err = sipreg_register(&reg, sip, registrar, uri, uri, 60, name,
				      NULL, 0, 0, auth_handler, NULL, false,
				      register_handler, NULL, NULL, NULL);
		if (err) {
			re_fprintf(stderr, "register error: %s\n",
				   strerror(err));
			goto out;
		}

		re_printf("registering <%s>...\n", uri);
	}

	/* main loop */
	err = re_main(signal_handler);

 out:
	/* clean up/free all state */
	mem_deref(sdp); /* will also free sdp_media */
	mem_deref(rtp);
	mem_deref(sess_sock);
	mem_deref(sip);
	mem_deref(dnsc);

	/* free librar state */
	libre_close();

	/* check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #10
0
int main(int argc, char *argv[])
{
	bool daemon = true;
	int err = 0;
	struct pl opt;

	(void)sys_coredump_set(true);

#ifdef HAVE_GETOPT
	for (;;) {

		const int c = getopt(argc, argv, "dhnf:");
		if (0 > c)
			break;

		switch (c) {

		case 'd':
			force_debug = true;
			restund_log_enable_debug(true);
			break;

		case 'f':
			configfile = optarg;
			break;

		case 'n':
			daemon = false;
			break;

		case '?':
			err = EINVAL;
			/*@fallthrough@*/
		case 'h':
			usage();
			return err;
		}
	}
#else
	(void)argc;
	(void)argv;
#endif

	restund_cmd_subscribe(&cmd_reload);

	err = fd_setsize(4096);
	if (err) {
		restund_warning("fd_setsize error: %m\n", err);
		goto out;
	}

	err = libre_init();
	if (err) {
		restund_error("re init failed: %m\n", err);
		goto out;
	}

	/* configuration file */
	err = conf_alloc(&conf, configfile);
	if (err) {
		restund_error("error loading configuration: %s: %m\n",
			      configfile, err);
		goto out;
	}

	/* debug config */
	if (!conf_get(conf, "debug", &opt) && !pl_strcasecmp(&opt, "yes"))
		restund_log_enable_debug(true);

	/* udp */
	err = restund_udp_init();
	if (err)
		goto out;

	/* tcp */
	err = restund_tcp_init();
	if (err)
		goto out;

	/* daemon config */
	if (!conf_get(conf, "daemon", &opt) && !pl_strcasecmp(&opt, "no"))
		daemon = false;

	/* module config */
	if (conf_get(conf, "module_path", &opt))
		pl_set_str(&opt, ".");

	err = conf_apply(conf, "module", module_handler, &opt);
	if (err)
		goto out;

	/* daemon */
	if (daemon) {
		err = sys_daemon();
		if (err) {
			restund_error("daemon error: %m\n", err);
			goto out;
 		}

		restund_log_enable_stderr(false);
	}

	/* database */
	err = restund_db_init();
	if (err) {
		restund_warning("database error: %m\n", err);
		goto out;
	}

	restund_info("stun server ready\n");

	/* main loop */
	err = re_main(signal_handler);

 out:
	restund_db_close();
	mod_close();
	restund_udp_close();
	restund_tcp_close();
	conf = mem_deref(conf);

	libre_close();

	restund_cmd_unsubscribe(&cmd_reload);

	/* check for memory leaks */
	tmr_debug();
	mem_debug();

	return err;
}
Exemple #11
0
int main(int argc, char *argv[])
{
	struct config *config;
	int err;

	err = libre_init();
	if (err)
		return err;

	log_enable_info(false);

	for (;;) {
		const int c = getopt(argc, argv, "v");
		if (0 > c)
			break;

		switch (c) {

		case '?':
		case 'h':
			usage();
			return -2;

		case 'v':
			log_enable_info(true);
			break;

		default:
			break;
		}
	}

	re_printf("running baresip selftest version %s with %zu tests\n",
		  BARESIP_VERSION, ARRAY_SIZE(tests));

	/* note: run SIP-traffic on localhost */
	config = conf_config();
	if (!config) {
		err = ENOENT;
		goto out;
	}
	str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local));

	/* XXX: needed for ua tests */
	err = ua_init("test", true, true, true, false);
	if (err)
		goto out;

	err = run_tests();
	if (err)
		goto out;

#if 1
	ua_stop_all(true);
#endif

	re_printf("\x1b[32mOK. %zu tests passed successfully\x1b[;m\n",
		  ARRAY_SIZE(tests));

 out:
	if (err) {
		warning("test failed (%m)\n", err);
		re_printf("%H\n", re_debug, 0);
	}
	ua_stop_all(true);
	ua_close();

	libre_close();

	tmr_debug();
	mem_debug();

	return err;
}