static int module_init(void) { struct sa laddr_udp, laddr_http; struct pl addr; uint32_t port; int err; /* UDP bind address */ if (conf_get(restund_conf(), "status_udp_addr", &addr)) pl_set_str(&addr, "127.0.0.1"); if (conf_get_u32(restund_conf(), "status_udp_port", &port)) port = 33000; err = sa_set(&laddr_udp, &addr, port); if (err) { restund_error("status: bad udp bind address: %r:%u", &addr, port); goto out; } /* HTTP bind address */ if (conf_get(restund_conf(), "status_http_addr", &addr)) pl_set_str(&addr, "127.0.0.1"); if (conf_get_u32(restund_conf(), "status_http_port", &port)) port = 8080; err = sa_set(&laddr_http, &addr, port); if (err) { restund_error("status: bad http bind address: %r:%u", &addr, port); goto out; } err = udp_listen(&stg.us, &laddr_udp, udp_recv, NULL); if (err) { restund_warning("status: udp_listen: %m\n", err); goto out; } err = httpd_alloc(&stg.httpd, &laddr_http, httpd_handler); if (err) { restund_warning("status: httpd: %m\n", err); goto out; } stg.start = time(NULL); restund_debug("status: module loaded (udp=%J http=%J)\n", &laddr_udp, &laddr_http); out: if (err) { stg.us = mem_deref(stg.us); stg.httpd = mem_deref(stg.httpd); } return err; }
static int module_init(void) { int err = 0; #ifdef MODULE_CONF struct pl pl; if (!conf_get(conf_cur(), "opus_application", &pl)) { if (!pl_strcasecmp(&pl, "voip")) opus.app = OPUS_APPLICATION_VOIP; else if (!pl_strcasecmp(&pl, "audio")) opus.app = OPUS_APPLICATION_AUDIO; else { DEBUG_WARNING("unknown application: %r\n", &pl); } } if (!conf_get(conf_cur(), "opus_bandwidth", &pl)) { if (!pl_strcasecmp(&pl, "narrowband")) opus.bandwidth = OPUS_BANDWIDTH_NARROWBAND; else if (!pl_strcasecmp(&pl, "mediumband")) opus.bandwidth = OPUS_BANDWIDTH_MEDIUMBAND; else if (!pl_strcasecmp(&pl, "wideband")) opus.bandwidth = OPUS_BANDWIDTH_WIDEBAND; else if (!pl_strcasecmp(&pl, "superwideband")) opus.bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND; else if (!pl_strcasecmp(&pl, "fullband")) opus.bandwidth = OPUS_BANDWIDTH_FULLBAND; else { DEBUG_WARNING("unknown bandwidth: %r\n", &pl); } } conf_get_u32(conf_cur(), "opus_complexity", &opus.complex); conf_get_u32(conf_cur(), "opus_bitrate", &opus.bitrate); conf_get_bool(conf_cur(), "opus_vbr", &opus.vbr); #endif err |= aucodec_register(&codecv[0], NULL, "opus", 48000, 2, NULL, alloc, encode, decode, NULL); err |= aucodec_register(&codecv[1], NULL, "opus", 48000, 1, NULL, alloc, encode, decode, NULL); #if 0 err |= aucodec_register(&codecv[2], NULL, "opus", 32000, 1, NULL, alloc, encode, decode, NULL); #endif return err; }
static void config_parse(struct conf *conf) { uint32_t v; if (0 == conf_get_u32(conf, "speex_quality", &v)) sconf.quality = v; if (0 == conf_get_u32(conf, "speex_complexity", &v)) sconf.complexity = v; if (0 == conf_get_u32(conf, "speex_enhancement", &v)) sconf.enhancement = v; if (0 == conf_get_u32(conf, "speex_vbr", &v)) sconf.vbr = v; if (0 == conf_get_u32(conf, "speex_vad", &v)) sconf.vad = v; }
static int module_init(void) { auth.nonce_expiry = NONCE_EXPIRY; auth.secret = rand_u64(); conf_get_u32(restund_conf(), "auth_nonce_expiry", &auth.nonce_expiry); auth.sharedsecret_length = 0; auth.sharedsecret2_length = 0; conf_get_str(restund_conf(), "auth_shared", auth.sharedsecret, sizeof(auth.sharedsecret)); auth.sharedsecret_length = strlen(auth.sharedsecret); conf_get_str(restund_conf(), "auth_shared_rollover", auth.sharedsecret2, sizeof(auth.sharedsecret2)); auth.sharedsecret2_length = strlen(auth.sharedsecret2); if (auth.sharedsecret_length > 0 || auth.sharedsecret2_length > 0) { restund_debug("auth: module loaded shared secret lengths %d and %d\n", auth.sharedsecret_length, auth.sharedsecret2_length); } restund_stun_register_handler(&stun); restund_debug("auth: module loaded (nonce_expiry=%us)\n", auth.nonce_expiry); return 0; }
static void config_parse(struct conf *conf) { uint32_t v; if (0 == conf_get_u32(conf, "speex_agc_level", &v)) pp_conf.agc_level = v; }
static int module_init(void) { struct conf *conf = conf_cur(); uint32_t value; char *p = fmtp + str_len(fmtp); bool b; int n = 0; if (0 == conf_get_u32(conf, "opus_bitrate", &value)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";maxaveragebitrate=%d", value); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_cbr", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";cbr=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_inbandfec", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";useinbandfec=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_dtx", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";usedtx=%d", b); if (n <= 0) return ENOMEM; p += n; } (void)conf_get_bool(conf, "opus_mirror", &opus_mirror); debug("opus: fmtp=\"%s\"\n", fmtp); aucodec_register(&opus); return 0; }
static int module_init(void) { auth.nonce_expiry = NONCE_EXPIRY; auth.rand_time = rand_u32(); auth.rand_addr = rand_u32(); conf_get_u32(restund_conf(), "auth_nonce_expiry", &auth.nonce_expiry); restund_stun_register_handler(&stun); restund_debug("auth: module loaded (nonce_expiry=%us)\n", auth.nonce_expiry); return 0; }
static int module_init(void) { struct conf *conf = conf_cur(); uint32_t value; static char fmtp[128]; if (0 == conf_get_u32(conf, "opus_bitrate", &value)) { (void)re_snprintf(fmtp, sizeof(fmtp), "stereo=1;sprop-stereo=1;maxaveragebitrate=%d", value); opus.fmtp = fmtp; } aucodec_register(&opus); return 0; }
int restund_udp_init(void) { uint32_t sockbuf_size = 0; int err; list_init(&lstnrl); (void)conf_get_u32(restund_conf(), "udp_sockbuf_size", &sockbuf_size); err = conf_apply(restund_conf(), "udp_listen", listen_handler, &sockbuf_size); if (err) goto out; out: if (err) restund_udp_close(); return err; }
static int module_init(void) { static struct restund_db db = { .allh = accounts_getall, .cnth = accounts_count, .tlogh = NULL, }; conf_get_str(restund_conf(), "mysql_host", my.host, sizeof(my.host)); conf_get_str(restund_conf(), "mysql_user", my.user, sizeof(my.user)); conf_get_str(restund_conf(), "mysql_pass", my.pass, sizeof(my.pass)); conf_get_str(restund_conf(), "mysql_db", my.db, sizeof(my.db)); conf_get_u32(restund_conf(), "mysql_ser", &my.version); if (myconnect()) { restund_error("mysql: %s\n", mysql_error(&my.mysql)); } restund_db_set_handler(&db); return 0; }
int conf_get_range(const struct conf *conf, const char *name, struct range *rng) { struct pl r, min, max; uint32_t v; int err; err = conf_get(conf, name, &r); if (err) return err; err = re_regex(r.p, r.l, "[0-9]+-[0-9]+", &min, &max); if (err) { /* fallback to non-range numeric value */ err = conf_get_u32(conf, name, &v); if (err) { warning("conf: %s: could not parse range: (%r)\n", name, &r); return err; } rng->min = rng->max = v; return err; } rng->min = pl_u32(&min); rng->max = pl_u32(&max); if (rng->min > rng->max) { warning("conf: %s: invalid range (%u - %u)\n", name, rng->min, rng->max); return EINVAL; } return 0; }
static int module_init(void) { struct conf *conf = conf_cur(); uint32_t value; char *p = fmtp + str_len(fmtp); bool b, stereo = true, sprop_stereo = true; struct pl pl; int n = 0; conf_get_bool(conf, "opus_stereo", &stereo); conf_get_bool(conf, "opus_sprop_stereo", &sprop_stereo); /* always set stereo parameter first */ n = re_snprintf(p, sizeof(fmtp) - str_len(p), "stereo=%d;sprop-stereo=%d", stereo, sprop_stereo); if (n <= 0) return ENOMEM; p += n; if (0 == conf_get_u32(conf, "opus_bitrate", &value)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";maxaveragebitrate=%d", value); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_cbr", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";cbr=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_inbandfec", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";useinbandfec=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_dtx", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";usedtx=%d", b); if (n <= 0) return ENOMEM; p += n; } (void)conf_get_bool(conf, "opus_mirror", &opus_mirror); if (opus_mirror) { opus.fmtp = NULL; opus.fmtp_ench = opus_fmtp_enc; } (void)conf_get_u32(conf, "opus_complexity", &opus_complexity); if (opus_complexity > 10) opus_complexity = 10; if (!conf_get(conf, "opus_application", &pl)) { if (!pl_strcasecmp(&pl, "audio")) opus_application = OPUS_APPLICATION_AUDIO; else if (!pl_strcasecmp(&pl, "voip")) opus_application = OPUS_APPLICATION_VOIP; else { warning("opus: unknown encoder application: %r\n", &pl); return EINVAL; } } debug("opus: fmtp=\"%s\"\n", fmtp); aucodec_register(baresip_aucodecl(), &opus); return 0; }
static int module_init(void) { uint32_t x, bsize = ALLOC_DEFAULT_BSIZE; struct pl opt; int err = 0; restund_stun_register_handler(&stun); restund_cmd_subscribe(&cmd_turn); restund_cmd_subscribe(&cmd_turnstats); /* turn_external_addr */ if (!conf_get(restund_conf(), "turn_relay_addr", &opt)) err = sa_set(&turnd.rel_addr, &opt, 0); else sa_init(&turnd.rel_addr, AF_UNSPEC); if (err) { restund_error("turn: bad turn_relay_addr: '%r'\n", &opt); goto out; } /* turn_external_addr6 */ if (!conf_get(restund_conf(), "turn_relay_addr6", &opt)) err = sa_set(&turnd.rel_addr6, &opt, 0); else sa_init(&turnd.rel_addr6, AF_UNSPEC); if (err) { restund_error("turn: bad turn_relay_addr6: '%r'\n", &opt); goto out; } if (!sa_isset(&turnd.rel_addr, SA_ADDR) && !sa_isset(&turnd.rel_addr6, SA_ADDR)) { restund_error("turn: no relay address configured\n"); err = EINVAL; goto out; } /* turn_max_lifetime, turn_max_allocations, udp_sockbuf_size */ turnd.lifetime_max = TURN_DEFAULT_LIFETIME; conf_get_u32(restund_conf(), "turn_max_lifetime", &turnd.lifetime_max); conf_get_u32(restund_conf(), "turn_max_allocations", &bsize); conf_get_u32(restund_conf(), "udp_sockbuf_size", &turnd.udp_sockbuf_size); for (x=2; (uint32_t)1<<x<bsize; x++); bsize = 1<<x; err = hash_alloc(&turnd.ht_alloc, bsize); if (err) { restund_error("turnd hash alloc error: %m\n", err); goto out; } restund_debug("turn: lifetime=%u ext=%j ext6=%j bsz=%u\n", turnd.lifetime_max, &turnd.rel_addr, &turnd.rel_addr6, bsize); out: return err; }
int config_parse_conf(struct config *cfg, const struct conf *conf) { struct pl pollm, as, ap; enum poll_method method; struct vidsz size = {0, 0}; uint32_t v; int err = 0; if (!cfg || !conf) return EINVAL; /* Core */ if (0 == conf_get(conf, "poll_method", &pollm)) { if (0 == poll_method_type(&method, &pollm)) { err = poll_method_set(method); if (err) { warning("config: poll method (%r) set: %m\n", &pollm, err); } } else { warning("config: unknown poll method (%r)\n", &pollm); } } /* SIP */ (void)conf_get_u32(conf, "sip_trans_bsize", &cfg->sip.trans_bsize); (void)conf_get_str(conf, "sip_listen", cfg->sip.local, sizeof(cfg->sip.local)); (void)conf_get_str(conf, "sip_certificate", cfg->sip.cert, sizeof(cfg->sip.cert)); /* Call */ (void)conf_get_u32(conf, "call_local_timeout", &cfg->call.local_timeout); /* Audio */ (void)conf_get_str(conf, "audio_path", cfg->audio.audio_path, sizeof(cfg->audio.audio_path)); (void)conf_get_csv(conf, "audio_player", cfg->audio.play_mod, sizeof(cfg->audio.play_mod), cfg->audio.play_dev, sizeof(cfg->audio.play_dev)); (void)conf_get_csv(conf, "audio_source", cfg->audio.src_mod, sizeof(cfg->audio.src_mod), cfg->audio.src_dev, sizeof(cfg->audio.src_dev)); (void)conf_get_csv(conf, "audio_alert", cfg->audio.alert_mod, sizeof(cfg->audio.alert_mod), cfg->audio.alert_dev, sizeof(cfg->audio.alert_dev)); (void)conf_get_range(conf, "audio_srate", &cfg->audio.srate); (void)conf_get_range(conf, "audio_channels", &cfg->audio.channels); (void)conf_get_u32(conf, "ausrc_srate", &cfg->audio.srate_src); (void)conf_get_u32(conf, "auplay_srate", &cfg->audio.srate_play); (void)conf_get_u32(conf, "ausrc_channels", &cfg->audio.channels_src); (void)conf_get_u32(conf, "auplay_channels", &cfg->audio.channels_play); if (0 == conf_get(conf, "audio_source", &as) && 0 == conf_get(conf, "audio_player", &ap)) cfg->audio.src_first = as.p < ap.p; #ifdef USE_VIDEO /* Video */ (void)conf_get_csv(conf, "video_source", cfg->video.src_mod, sizeof(cfg->video.src_mod), cfg->video.src_dev, sizeof(cfg->video.src_dev)); (void)conf_get_csv(conf, "video_display", cfg->video.disp_mod, sizeof(cfg->video.disp_mod), cfg->video.disp_dev, sizeof(cfg->video.disp_dev)); if (0 == conf_get_vidsz(conf, "video_size", &size)) { cfg->video.width = size.w; cfg->video.height = size.h; } (void)conf_get_u32(conf, "video_bitrate", &cfg->video.bitrate); (void)conf_get_u32(conf, "video_fps", &cfg->video.fps); #else (void)size; #endif /* AVT - Audio/Video Transport */ if (0 == conf_get_u32(conf, "rtp_tos", &v)) cfg->avt.rtp_tos = v; (void)conf_get_range(conf, "rtp_ports", &cfg->avt.rtp_ports); if (0 == conf_get_range(conf, "rtp_bandwidth", &cfg->avt.rtp_bw)) { cfg->avt.rtp_bw.min *= 1000; cfg->avt.rtp_bw.max *= 1000; } (void)conf_get_bool(conf, "rtcp_enable", &cfg->avt.rtcp_enable); (void)conf_get_bool(conf, "rtcp_mux", &cfg->avt.rtcp_mux); (void)conf_get_range(conf, "jitter_buffer_delay", &cfg->avt.jbuf_del); (void)conf_get_bool(conf, "rtp_stats", &cfg->avt.rtp_stats); if (err) { warning("config: configure parse error (%m)\n", err); } /* Network */ (void)conf_apply(conf, "dns_server", dns_server_handler, &cfg->net); (void)conf_get_str(conf, "net_interface", cfg->net.ifname, sizeof(cfg->net.ifname)); #ifdef USE_VIDEO /* BFCP */ (void)conf_get_str(conf, "bfcp_proto", cfg->bfcp.proto, sizeof(cfg->bfcp.proto)); #endif return err; }
/** * Parse the core configuration file and update baresip core config * * @param cfg Baresip core config to update * @param conf Configuration file to parse * * @return 0 if success, otherwise errorcode */ int config_parse_conf(struct config *cfg, const struct conf *conf) { struct pl pollm, as, ap; enum poll_method method; struct vidsz size = {0, 0}; struct pl txmode; uint32_t v; int err = 0; if (!cfg || !conf) return EINVAL; /* Core */ if (0 == conf_get(conf, "poll_method", &pollm)) { if (0 == poll_method_type(&method, &pollm)) { err = poll_method_set(method); if (err) { warning("config: poll method (%r) set: %m\n", &pollm, err); } } else { warning("config: unknown poll method (%r)\n", &pollm); } } /* SIP */ (void)conf_get_str(conf, "sip_listen", cfg->sip.local, sizeof(cfg->sip.local)); (void)conf_get_str(conf, "sip_certificate", cfg->sip.cert, sizeof(cfg->sip.cert)); (void)conf_get_str(conf, "sip_cafile", cfg->sip.cafile, sizeof(cfg->sip.cafile)); /* Call */ (void)conf_get_u32(conf, "call_local_timeout", &cfg->call.local_timeout); (void)conf_get_u32(conf, "call_max_calls", &cfg->call.max_calls); /* Audio */ (void)conf_get_str(conf, "audio_path", cfg->audio.audio_path, sizeof(cfg->audio.audio_path)); (void)conf_get_csv(conf, "audio_player", cfg->audio.play_mod, sizeof(cfg->audio.play_mod), cfg->audio.play_dev, sizeof(cfg->audio.play_dev)); (void)conf_get_csv(conf, "audio_source", cfg->audio.src_mod, sizeof(cfg->audio.src_mod), cfg->audio.src_dev, sizeof(cfg->audio.src_dev)); (void)conf_get_csv(conf, "audio_alert", cfg->audio.alert_mod, sizeof(cfg->audio.alert_mod), cfg->audio.alert_dev, sizeof(cfg->audio.alert_dev)); (void)conf_get_u32(conf, "ausrc_srate", &cfg->audio.srate_src); (void)conf_get_u32(conf, "auplay_srate", &cfg->audio.srate_play); (void)conf_get_u32(conf, "ausrc_channels", &cfg->audio.channels_src); (void)conf_get_u32(conf, "auplay_channels", &cfg->audio.channels_play); if (0 == conf_get(conf, "audio_source", &as) && 0 == conf_get(conf, "audio_player", &ap)) cfg->audio.src_first = as.p < ap.p; if (0 == conf_get(conf, "audio_txmode", &txmode)) { if (0 == pl_strcasecmp(&txmode, "poll")) cfg->audio.txmode = AUDIO_MODE_POLL; else if (0 == pl_strcasecmp(&txmode, "thread")) cfg->audio.txmode = AUDIO_MODE_THREAD; else { warning("unsupported audio txmode (%r)\n", &txmode); } } (void)conf_get_bool(conf, "audio_level", &cfg->audio.level); conf_get_aufmt(conf, "ausrc_format", &cfg->audio.src_fmt); conf_get_aufmt(conf, "auplay_format", &cfg->audio.play_fmt); conf_get_aufmt(conf, "auenc_format", &cfg->audio.enc_fmt); conf_get_aufmt(conf, "audec_format", &cfg->audio.dec_fmt); /* Video */ (void)conf_get_csv(conf, "video_source", cfg->video.src_mod, sizeof(cfg->video.src_mod), cfg->video.src_dev, sizeof(cfg->video.src_dev)); (void)conf_get_csv(conf, "video_display", cfg->video.disp_mod, sizeof(cfg->video.disp_mod), cfg->video.disp_dev, sizeof(cfg->video.disp_dev)); if (0 == conf_get_vidsz(conf, "video_size", &size)) { cfg->video.width = size.w; cfg->video.height = size.h; } (void)conf_get_u32(conf, "video_bitrate", &cfg->video.bitrate); (void)conf_get_float(conf, "video_fps", &cfg->video.fps); (void)conf_get_bool(conf, "video_fullscreen", &cfg->video.fullscreen); conf_get_vidfmt(conf, "videnc_format", &cfg->video.enc_fmt); /* AVT - Audio/Video Transport */ if (0 == conf_get_u32(conf, "rtp_tos", &v)) cfg->avt.rtp_tos = v; (void)conf_get_range(conf, "rtp_ports", &cfg->avt.rtp_ports); if (0 == conf_get_range(conf, "rtp_bandwidth", &cfg->avt.rtp_bw)) { cfg->avt.rtp_bw.min *= 1000; cfg->avt.rtp_bw.max *= 1000; } (void)conf_get_bool(conf, "rtcp_mux", &cfg->avt.rtcp_mux); (void)conf_get_range(conf, "jitter_buffer_delay", &cfg->avt.jbuf_del); (void)conf_get_bool(conf, "rtp_stats", &cfg->avt.rtp_stats); (void)conf_get_u32(conf, "rtp_timeout", &cfg->avt.rtp_timeout); if (err) { warning("config: configure parse error (%m)\n", err); } /* Network */ #if HAVE_INET6 (void)conf_get_bool(conf, "prefer_ipv6", &cfg->net.prefer_ipv6); #endif (void)conf_apply(conf, "dns_server", dns_server_handler, &cfg->net); (void)conf_get_str(conf, "net_interface", cfg->net.ifname, sizeof(cfg->net.ifname)); /* BFCP */ (void)conf_get_str(conf, "bfcp_proto", cfg->bfcp.proto, sizeof(cfg->bfcp.proto)); /* SDP */ (void)conf_get_bool(conf, "sdp_ebuacip", &cfg->sdp.ebuacip); return err; }
static int module_init(void) { struct conf *conf = conf_cur(); uint32_t value; char *p = fmtp + str_len(fmtp); bool b, stereo = true, sprop_stereo = true; int n = 0; conf_get_bool(conf, "opus_stereo", &stereo); conf_get_bool(conf, "opus_sprop_stereo", &sprop_stereo); /* always set stereo parameter first */ n = re_snprintf(p, sizeof(fmtp) - str_len(p), "stereo=%d;sprop-stereo=%d", stereo, sprop_stereo); if (n <= 0) return ENOMEM; p += n; if (0 == conf_get_u32(conf, "opus_bitrate", &value)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";maxaveragebitrate=%d", value); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_cbr", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";cbr=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_inbandfec", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";useinbandfec=%d", b); if (n <= 0) return ENOMEM; p += n; } if (0 == conf_get_bool(conf, "opus_dtx", &b)) { n = re_snprintf(p, sizeof(fmtp) - str_len(p), ";usedtx=%d", b); if (n <= 0) return ENOMEM; p += n; } (void)conf_get_bool(conf, "opus_mirror", &opus_mirror); if (opus_mirror) { opus.fmtp = NULL; opus.fmtp_ench = opus_fmtp_enc; } debug("opus: fmtp=\"%s\"\n", fmtp); aucodec_register(baresip_aucodecl(), &opus); return 0; }