void ldisc_configure(Ldisc *ldisc, Conf *conf) { ldisc->telnet_keyboard = conf_get_bool(conf, CONF_telnet_keyboard); ldisc->telnet_newline = conf_get_bool(conf, CONF_telnet_newline); ldisc->protocol = conf_get_int(conf, CONF_protocol); ldisc->localecho = conf_get_int(conf, CONF_localecho); ldisc->localedit = conf_get_int(conf, CONF_localedit); }
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 bool_t check_extension(const char * conf_key, ...) { va_list args; bool_t retval = FALSE; if (conf_key != NULL) { retval = conf_get_bool(conf_key, TRUE); /* conf set this feature to FALSE */ if (!retval) return FALSE; } va_start(args, conf_key); const char * f = va_arg(args, const char *); while(f != NULL) { assert(strlen(f) < 64); TRACE(OPENGL, "check for feature %s\n", f); dict_data_t d = strdict_get(GL_extensions_dict, f); if (!(DICT_DATA_NULL(d))) { DEBUG(OPENGL, "find %s\n", f); va_end(args); return TRUE; } f = va_arg(args, const char *); } va_end(args); return FALSE; }
void LMDBEngineFactory::ParseConfig(const Properties& props, LMDBConfig& cfg) { cfg.path = "."; conf_get_string(props, "data-dir", cfg.path); conf_get_int64(props, "lmdb.database_max_size", cfg.max_db_size); conf_get_int64(props, "lmdb.batch_commit_watermark", cfg.batch_commit_watermark); conf_get_bool(props, "lmdb.readahead", cfg.readahead); }
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; }
int main(void) { int width = 0; int height = 0; int fullscreen = 0; int image_count = 0; int i = 0; int ret = 0; char expr[64] = {0}; const char *image; ret = conf_init("config.lua"); printf("ret: %d\n", ret); ret = conf_get_int("settings.resolution.width", &width); printf("ret: %d, width: %d\n", ret, width); ret = conf_get_int("settings.resolution.height", &height); printf("ret: %d, height: %d\n", ret, height); ret = conf_get_bool("settings.resolution.fullscreen", &fullscreen); printf("ret: %d, fullscreen: %d\n", ret, fullscreen); ret = conf_get_int("#settings.images", &image_count); printf("ret: %d, image_count: %d\n", ret, image_count); for (i = 0; i < image_count; ++i) { memset(expr, 0, sizeof(expr)); snprintf(expr, sizeof(expr), "settings.images[%d]", i + 1); ret = conf_get_string(expr, &image); printf("ret: %d, settings.images[%d] = %s\n", ret, i + 1, image); } conf_free(); return 0; }
int main(int argc, char **argv) { bool sending; SOCKET *sklist; size_t skcount, sksize; int exitcode; bool errors; bool use_subsystem = false; bool just_test_share_exists = false; enum TriState sanitise_stdout = AUTO, sanitise_stderr = AUTO; unsigned long now, next, then; const struct BackendVtable *vt; dll_hijacking_protection(); sklist = NULL; skcount = sksize = 0; /* * Initialise port and protocol to sensible defaults. (These * will be overridden by more or less anything.) */ default_protocol = PROT_SSH; default_port = 22; flags = 0; cmdline_tooltype |= (TOOLTYPE_HOST_ARG | TOOLTYPE_HOST_ARG_CAN_BE_SESSION | TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD); /* * Process the command line. */ conf = conf_new(); do_defaults(NULL, conf); loaded_session = false; default_protocol = conf_get_int(conf, CONF_protocol); default_port = conf_get_int(conf, CONF_port); errors = false; { /* * Override the default protocol if PLINK_PROTOCOL is set. */ char *p = getenv("PLINK_PROTOCOL"); if (p) { const struct BackendVtable *vt = backend_vt_from_name(p); if (vt) { default_protocol = vt->protocol; default_port = vt->default_port; conf_set_int(conf, CONF_protocol, default_protocol); conf_set_int(conf, CONF_port, default_port); } } } while (--argc) { char *p = *++argv; int ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL), 1, conf); if (ret == -2) { fprintf(stderr, "plink: option \"%s\" requires an argument\n", p); errors = true; } else if (ret == 2) { --argc, ++argv; } else if (ret == 1) { continue; } else if (!strcmp(p, "-batch")) { console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ use_subsystem = true; } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) { version(); } else if (!strcmp(p, "--help")) { usage(); } else if (!strcmp(p, "-pgpfp")) { pgp_fingerprints(); exit(1); } else if (!strcmp(p, "-shareexists")) { just_test_share_exists = true; } else if (!strcmp(p, "-sanitise-stdout") || !strcmp(p, "-sanitize-stdout")) { sanitise_stdout = FORCE_ON; } else if (!strcmp(p, "-no-sanitise-stdout") || !strcmp(p, "-no-sanitize-stdout")) { sanitise_stdout = FORCE_OFF; } else if (!strcmp(p, "-sanitise-stderr") || !strcmp(p, "-sanitize-stderr")) { sanitise_stderr = FORCE_ON; } else if (!strcmp(p, "-no-sanitise-stderr") || !strcmp(p, "-no-sanitize-stderr")) { sanitise_stderr = FORCE_OFF; } else if (!strcmp(p, "-no-antispoof")) { console_antispoof_prompt = false; } else if (*p != '-') { strbuf *cmdbuf = strbuf_new(); while (argc > 0) { if (cmdbuf->len > 0) put_byte(cmdbuf, ' '); /* add space separator */ put_datapl(cmdbuf, ptrlen_from_asciz(p)); if (--argc > 0) p = *++argv; } conf_set_str(conf, CONF_remote_cmd, cmdbuf->s); conf_set_str(conf, CONF_remote_cmd2, ""); conf_set_bool(conf, CONF_nopty, true); /* command => no tty */ strbuf_free(cmdbuf); break; /* done with cmdline */ } else { fprintf(stderr, "plink: unknown option \"%s\"\n", p); errors = true; } } if (errors) return 1; if (!cmdline_host_ok(conf)) { usage(); } prepare_session(conf); /* * Perform command-line overrides on session configuration. */ cmdline_run_saved(conf); /* * Apply subsystem status. */ if (use_subsystem) conf_set_bool(conf, CONF_ssh_subsys, true); if (!*conf_get_str(conf, CONF_remote_cmd) && !*conf_get_str(conf, CONF_remote_cmd2) && !*conf_get_str(conf, CONF_ssh_nc_host)) flags |= FLAG_INTERACTIVE; /* * Select protocol. This is farmed out into a table in a * separate file to enable an ssh-free variant. */ vt = backend_vt_from_proto(conf_get_int(conf, CONF_protocol)); if (vt == NULL) { fprintf(stderr, "Internal fault: Unsupported protocol found\n"); return 1; } sk_init(); if (p_WSAEventSelect == NULL) { fprintf(stderr, "Plink requires WinSock 2\n"); return 1; } /* * Plink doesn't provide any way to add forwardings after the * connection is set up, so if there are none now, we can safely set * the "simple" flag. */ if (conf_get_int(conf, CONF_protocol) == PROT_SSH && !conf_get_bool(conf, CONF_x11_forward) && !conf_get_bool(conf, CONF_agentfwd) && !conf_get_str_nthstrkey(conf, CONF_portfwd, 0)) conf_set_bool(conf, CONF_ssh_simple, true); logctx = log_init(default_logpolicy, conf); if (just_test_share_exists) { if (!vt->test_for_upstream) { fprintf(stderr, "Connection sharing not supported for connection " "type '%s'\n", vt->name); return 1; } if (vt->test_for_upstream(conf_get_str(conf, CONF_host), conf_get_int(conf, CONF_port), conf)) return 0; else return 1; } if (restricted_acl) { lp_eventlog(default_logpolicy, "Running with restricted process ACL"); } /* * Start up the connection. */ netevent = CreateEvent(NULL, false, false, NULL); { const char *error; char *realhost; /* nodelay is only useful if stdin is a character device (console) */ bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); error = backend_init(vt, plink_seat, &backend, logctx, conf, conf_get_str(conf, CONF_host), conf_get_int(conf, CONF_port), &realhost, nodelay, conf_get_bool(conf, CONF_tcp_keepalives)); if (error) { fprintf(stderr, "Unable to open connection:\n%s", error); return 1; } sfree(realhost); } inhandle = GetStdHandle(STD_INPUT_HANDLE); outhandle = GetStdHandle(STD_OUTPUT_HANDLE); errhandle = GetStdHandle(STD_ERROR_HANDLE); /* * Turn off ECHO and LINE input modes. We don't care if this * call fails, because we know we aren't necessarily running in * a console. */ GetConsoleMode(inhandle, &orig_console_mode); SetConsoleMode(inhandle, ENABLE_PROCESSED_INPUT); /* * Pass the output handles to the handle-handling subsystem. * (The input one we leave until we're through the * authentication process.) */ stdout_handle = handle_output_new(outhandle, stdouterr_sent, NULL, 0); stderr_handle = handle_output_new(errhandle, stdouterr_sent, NULL, 0); handle_sink_init(&stdout_hs, stdout_handle); handle_sink_init(&stderr_hs, stderr_handle); stdout_bs = BinarySink_UPCAST(&stdout_hs); stderr_bs = BinarySink_UPCAST(&stderr_hs); /* * Decide whether to sanitise control sequences out of standard * output and standard error. * * If we weren't given a command-line override, we do this if (a) * the fd in question is pointing at a console, and (b) we aren't * trying to allocate a terminal as part of the session. * * (Rationale: the risk of control sequences is that they cause * confusion when sent to a local console, so if there isn't one, * no problem. Also, if we allocate a remote terminal, then we * sent a terminal type, i.e. we told it what kind of escape * sequences we _like_, i.e. we were expecting to receive some.) */ if (sanitise_stdout == FORCE_ON || (sanitise_stdout == AUTO && is_console_handle(outhandle) && conf_get_bool(conf, CONF_nopty))) { stdout_scc = stripctrl_new(stdout_bs, true, L'\0'); stdout_bs = BinarySink_UPCAST(stdout_scc); } if (sanitise_stderr == FORCE_ON || (sanitise_stderr == AUTO && is_console_handle(errhandle) && conf_get_bool(conf, CONF_nopty))) { stderr_scc = stripctrl_new(stderr_bs, true, L'\0'); stderr_bs = BinarySink_UPCAST(stderr_scc); } main_thread_id = GetCurrentThreadId(); sending = false; now = GETTICKCOUNT(); while (1) { int nhandles; HANDLE *handles; int n; DWORD ticks; if (!sending && backend_sendok(backend)) { stdin_handle = handle_input_new(inhandle, stdin_gotdata, NULL, 0); sending = true; } if (toplevel_callback_pending()) { ticks = 0; next = now; } else if (run_timers(now, &next)) { then = now; now = GETTICKCOUNT(); if (now - then > next - then) ticks = 0; else ticks = next - now; } else { ticks = INFINITE; /* no need to initialise next here because we can never * get WAIT_TIMEOUT */ } handles = handle_get_events(&nhandles); handles = sresize(handles, nhandles+1, HANDLE); handles[nhandles] = netevent; n = MsgWaitForMultipleObjects(nhandles+1, handles, false, ticks, QS_POSTMESSAGE); if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) { handle_got_event(handles[n - WAIT_OBJECT_0]); } else if (n == WAIT_OBJECT_0 + nhandles) { WSANETWORKEVENTS things; SOCKET socket; int i, socketstate; /* * We must not call select_result() for any socket * until we have finished enumerating within the tree. * This is because select_result() may close the socket * and modify the tree. */ /* Count the active sockets. */ i = 0; for (socket = first_socket(&socketstate); socket != INVALID_SOCKET; socket = next_socket(&socketstate)) i++; /* Expand the buffer if necessary. */ sgrowarray(sklist, sksize, i); /* Retrieve the sockets into sklist. */ skcount = 0; for (socket = first_socket(&socketstate); socket != INVALID_SOCKET; socket = next_socket(&socketstate)) { sklist[skcount++] = socket; } /* Now we're done enumerating; go through the list. */ for (i = 0; i < skcount; i++) { WPARAM wp; socket = sklist[i]; wp = (WPARAM) socket; if (!p_WSAEnumNetworkEvents(socket, NULL, &things)) { static const struct { int bit, mask; } eventtypes[] = { {FD_CONNECT_BIT, FD_CONNECT}, {FD_READ_BIT, FD_READ}, {FD_CLOSE_BIT, FD_CLOSE}, {FD_OOB_BIT, FD_OOB}, {FD_WRITE_BIT, FD_WRITE}, {FD_ACCEPT_BIT, FD_ACCEPT}, }; int e; noise_ultralight(NOISE_SOURCE_IOID, socket); for (e = 0; e < lenof(eventtypes); e++) if (things.lNetworkEvents & eventtypes[e].mask) { LPARAM lp; int err = things.iErrorCode[eventtypes[e].bit]; lp = WSAMAKESELECTREPLY(eventtypes[e].mask, err); select_result(wp, lp); } } } } else if (n == WAIT_OBJECT_0 + nhandles + 1) { MSG msg; while (PeekMessage(&msg, INVALID_HANDLE_VALUE, WM_AGENT_CALLBACK, WM_AGENT_CALLBACK, PM_REMOVE)) { struct agent_callback *c = (struct agent_callback *)msg.lParam; c->callback(c->callback_ctx, c->data, c->len); sfree(c); } } run_toplevel_callbacks(); if (n == WAIT_TIMEOUT) { now = next; } else { now = GETTICKCOUNT(); } sfree(handles); if (sending) handle_unthrottle(stdin_handle, backend_sendbuffer(backend)); if (!backend_connected(backend) && handle_backlog(stdout_handle) + handle_backlog(stderr_handle) == 0) break; /* we closed the connection */ } exitcode = backend_exitcode(backend); if (exitcode < 0) { fprintf(stderr, "Remote process exit code unavailable\n"); exitcode = 1; /* this is an error condition */ } cleanup_exit(exitcode); return 0; /* placate compiler warning */ }
bool ArdbConfig::Parse(const Properties& props) { conf_props = props; conf_get_string(props, "home", home); if (home.empty()) { home = "../ardb"; } make_dir(home); int err = real_path(home, home); if (0 != err) { ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } err = access(home.c_str(), R_OK | W_OK); if (0 != err) { err = errno; ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } setenv("ARDB_HOME", home.c_str(), 1); replace_env_var(const_cast<Properties&>(props)); conf_get_string(props, "pidfile", pidfile); conf_get_int64(props, "tcp-keepalive", tcp_keepalive); conf_get_int64(props, "timeout", timeout); conf_get_int64(props, "unixsocketperm", unixsocketperm); conf_get_int64(props, "slowlog-log-slower-than", slowlog_log_slower_than); conf_get_int64(props, "slowlog-max-len", slowlog_max_len); conf_get_int64(props, "maxclients", max_clients); Properties::const_iterator listen_it = props.find("listen"); if (listen_it != props.end()) { const ConfItemsArray& cs = listen_it->second; for (uint32 i = 0; i < cs.size(); i++) { if (cs[i].size() != 1) { WARN_LOG("Invalid config 'listen'"); } else { const std::string& str = cs[i][0]; listen_addresses.push_back(str); } } } if (listen_addresses.empty()) { listen_addresses.push_back("0.0.0.0:16379"); } Properties::const_iterator tp_it = props.find("thread-pool-size"); if (tp_it != props.end()) { const ConfItemsArray& cs = tp_it->second; for (uint32 i = 0; i < cs.size(); i++) { uint32 size = 0; if (cs[i].size() != 1 || !string_touint32(cs[i][0], size)) { WARN_LOG("Invalid config 'thread-pool-size'"); } else { thread_pool_sizes.push_back((int64) size); } } } Properties::const_iterator qp_it = props.find("qps-limit"); if (qp_it != props.end()) { const ConfItemsArray& cs = qp_it->second; for (uint32 i = 0; i < cs.size(); i++) { uint32 limit = 0; if (cs[i].size() != 1 || !string_touint32(cs[i][0], limit)) { WARN_LOG("Invalid config 'qps-limit'"); } else { qps_limits.push_back((int64) limit); } } } thread_pool_sizes.resize(listen_addresses.size()); qps_limits.resize(listen_addresses.size()); conf_get_string(props, "data-dir", data_base_path); conf_get_string(props, "backup-dir", backup_dir); conf_get_string(props, "repl-dir", repl_data_dir); make_dir(repl_data_dir); make_dir(backup_dir); err = real_path(repl_data_dir, repl_data_dir); if (0 != err) { ERROR_LOG("Invalid 'repl-dir' config:%s for reason:%s", repl_data_dir.c_str(), strerror(err)); return false; } std::string backup_file_format; conf_get_string(props, "backup-file-format", backup_file_format); if (!strcasecmp(backup_file_format.c_str(), "redis")) { backup_redis_format = true; } conf_get_string(props, "zookeeper-servers", zookeeper_servers); conf_get_string(props, "loglevel", loglevel); conf_get_string(props, "logfile", logfile); conf_get_bool(props, "daemonize", daemonize); conf_get_int64(props, "repl-backlog-size", repl_backlog_size); conf_get_int64(props, "repl-ping-slave-period", repl_ping_slave_period); conf_get_int64(props, "repl-timeout", repl_timeout); conf_get_int64(props, "repl-state-persist-period", repl_state_persist_period); conf_get_int64(props, "repl-backlog-ttl", repl_backlog_time_limit); conf_get_bool(props, "repl-disable-tcp-nodelay", repl_disable_tcp_nodelay); conf_get_int64(props, "lua-time-limit", lua_time_limit); conf_get_int64(props, "hash-max-ziplist-entries", hash_max_ziplist_entries); conf_get_int64(props, "hash_max-ziplist-value", hash_max_ziplist_value); conf_get_int64(props, "set-max-ziplist-entries", set_max_ziplist_entries); conf_get_int64(props, "set-max-ziplist-value", set_max_ziplist_value); conf_get_int64(props, "list-max-ziplist-entries", list_max_ziplist_entries); conf_get_int64(props, "list-max-ziplist-value", list_max_ziplist_value); conf_get_int64(props, "zset-max-ziplist-entries", zset_max_ziplist_entries); conf_get_int64(props, "zset_max_ziplist_value", zset_max_ziplist_value); conf_get_int64(props, "L1-zset-max-cache-size", L1_zset_max_cache_size); conf_get_int64(props, "L1-set-max-cache-size", L1_set_max_cache_size); conf_get_int64(props, "L1-hash-max-cache-size", L1_hash_max_cache_size); conf_get_int64(props, "L1-list-max-cache-size", L1_list_max_cache_size); conf_get_int64(props, "L1-string-max-cache-size", L1_string_max_cache_size); conf_get_bool(props, "L1-zset-read-fill-cache", L1_zset_read_fill_cache); conf_get_bool(props, "L1-zset-seek-load-cache", L1_zset_seek_load_cache); conf_get_bool(props, "L1-set-read-fill-cache", L1_set_read_fill_cache); conf_get_bool(props, "L1-set-seek-load-cache", L1_set_seek_load_cache); conf_get_bool(props, "L1-hash-read-fill-cache", L1_hash_read_fill_cache); conf_get_bool(props, "L1-hash-seek-load-cache", L1_hash_seek_load_cache); conf_get_bool(props, "L1-list-read-fill-cache", L1_list_read_fill_cache); conf_get_bool(props, "L1-list-seek-load-cache", L1_list_seek_load_cache); conf_get_bool(props, "L1-string-read-fill-cache", L1_string_read_fill_cache); conf_get_int64(props, "hll-sparse-max-bytes", hll_sparse_max_bytes); conf_get_bool(props, "slave-read-only", slave_readonly); conf_get_bool(props, "slave-serve-stale-data", slave_serve_stale_data); conf_get_int64(props, "slave-priority", slave_priority); conf_get_bool(props, "slave-ignore-expire", slave_ignore_expire); conf_get_bool(props, "slave-ignore-del", slave_ignore_del); std::string slaveof; if (conf_get_string(props, "slaveof", slaveof)) { std::vector<std::string> ss = split_string(slaveof, ":"); if (ss.size() == 2) { master_host = ss[0]; if (!string_touint32(ss[1], master_port)) { master_host = ""; WARN_LOG("Invalid 'slaveof' config."); } } else { WARN_LOG("Invalid 'slaveof' config."); } } std::string include_dbs, exclude_dbs; repl_includes.clear(); repl_excludes.clear(); conf_get_string(props, "replicate-include-db", include_dbs); conf_get_string(props, "replicate-exclude-db", exclude_dbs); if (0 != split_uint32_array(include_dbs, "|", repl_includes)) { ERROR_LOG("Invalid 'replicate-include-db' config."); repl_includes.clear(); } if (0 != split_uint32_array(exclude_dbs, "|", repl_excludes)) { ERROR_LOG("Invalid 'replicate-exclude-db' config."); repl_excludes.clear(); } if (data_base_path.empty()) { data_base_path = "."; } make_dir(data_base_path); err = real_path(data_base_path, data_base_path); if (0 != err) { ERROR_LOG("Invalid 'data-dir' config:%s for reason:%s", data_base_path.c_str(), strerror(err)); return false; } conf_get_string(props, "additional-misc-info", additional_misc_info); conf_get_string(props, "requirepass", requirepass); Properties::const_iterator fit = props.find("rename-command"); if (fit != props.end()) { rename_commands.clear(); StringSet newcmdset; const ConfItemsArray& cs = fit->second; ConfItemsArray::const_iterator cit = cs.begin(); while (cit != cs.end()) { if (cit->size() != 2 || newcmdset.count(cit->at(1)) > 0) { ERROR_LOG("Invalid 'rename-command' config."); } else { rename_commands[cit->at(0)] = cit->at(1); newcmdset.insert(cit->at(1)); } cit++; } } conf_get_int64(props, "compact-min-interval", compact_min_interval); conf_get_int64(props, "compact-max-interval", compact_max_interval); conf_get_int64(props, "compact-after-write", compact_trigger_write_count); conf_get_bool(props, "compact-enable", compact_enable); conf_get_int64(props, "reply-pool-size", reply_pool_size); conf_get_bool(props, "replace-all-for-multi-sadd", replace_for_multi_sadd); conf_get_bool(props, "replace-all-for-hmset", replace_for_hmset); conf_get_int64(props, "slave-client-output-buffer-limit", slave_client_output_buffer_limit); conf_get_int64(props, "pubsub-client-output-buffer-limit", pubsub_client_output_buffer_limit); conf_get_bool(props, "scan-redis-compatible", scan_redis_compatible); conf_get_int64(props, "scan-cursor-expire-after", scan_cursor_expire_after); conf_get_int64(props, "max-string-bitset-value", max_string_bitset_value); conf_get_int64(props, "databases", maxdb); conf_get_bool(props, "lua-exec-atomic", lua_exec_atomic); trusted_ip.clear(); Properties::const_iterator ip_it = props.find("trusted-ip"); if (ip_it != props.end()) { const ConfItemsArray& cs = ip_it->second; for (uint32 i = 0; i < cs.size(); i++) { trusted_ip.insert(cs[i][0]); } } if (!verify_config(*this)) { return false; } ArdbLogger::SetLogLevel(loglevel); return true; }
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) { zrtp_status_t s; char config_path[256] = ""; char zrtp_zid_path[256] = ""; FILE *f; int ret, err; (void)conf_get_bool(conf_cur(), "zrtp_hash", &use_sig_hash); zrtp_log_set_log_engine(zrtp_log); zrtp_config_defaults(&zrtp_config); str_ncpy(zrtp_config.client_id, "baresip/zrtp", sizeof(zrtp_config.client_id)); zrtp_config.lic_mode = ZRTP_LICENSE_MODE_UNLIMITED; zrtp_config.cb.misc_cb.on_send_packet = on_send_packet; zrtp_config.cb.event_cb.on_zrtp_secure = on_zrtp_secure; zrtp_config.cb.event_cb.on_zrtp_security_event = on_zrtp_security_event; err = conf_path_get(config_path, sizeof(config_path)); if (err) { warning("zrtp: could not get config path: %m\n", err); return err; } ret = re_snprintf(zrtp_config.def_cache_path.buffer, zrtp_config.def_cache_path.max_length, "%s/zrtp_cache.dat", config_path); if (ret < 0) { warning("zrtp: could not write cache path\n"); return ENOMEM; } zrtp_config.def_cache_path.length = ret; if (re_snprintf(zrtp_zid_path, sizeof(zrtp_zid_path), "%s/zrtp_zid", config_path) < 0) return ENOMEM; if ((f = fopen(zrtp_zid_path, "rb")) != NULL) { if (fread(zid, sizeof(zid), 1, f) != 1) { if (feof(f) || ferror(f)) { warning("zrtp: invalid zrtp_zid file\n"); } } } else if ((f = fopen(zrtp_zid_path, "wb")) != NULL) { rand_bytes(zid, sizeof(zid)); if (fwrite(zid, sizeof(zid), 1, f) != 1) { warning("zrtp: zrtp_zid file write failed\n"); } info("zrtp: generated new persistent ZID (%s)\n", zrtp_zid_path); } else { err = errno; warning("zrtp: fopen() %s (%m)\n", zrtp_zid_path, err); } if (f) (void) fclose(f); s = zrtp_init(&zrtp_config, &zrtp_global); if (zrtp_status_ok != s) { warning("zrtp: zrtp_init() failed (status = %d)\n", s); return ENOSYS; } menc_register(baresip_mencl(), &menc_zrtp); debug("zrtp: cache_file: %s\n", zrtp_config.def_cache_path.buffer); debug(" zid_file: %s\n", zrtp_zid_path); debug(" zid: %w\n", zid, sizeof(zid)); return cmd_register(baresip_commands(), cmdv, ARRAY_SIZE(cmdv)); }
void menu_request_settings(void) { gint result; GtkDialog * dialog; GtkToggleButton * autostart_studio_button; GtkToggleButton * send_notifications_button; GtkEntry * shell_entry; GtkEntry * terminal_entry; GtkSpinButton * js_delay_spin; GtkEntry * jack_conf_tool_entry; bool autostart; bool notify; const char * shell; const char * terminal; unsigned int js_delay; const char * jack_conf_tool; autostart_studio_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_studio_autostart_checkbutton")); send_notifications_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_send_notifications_checkbutton")); shell_entry = GTK_ENTRY(get_gtk_builder_widget("settings_shell_entry")); terminal_entry = GTK_ENTRY(get_gtk_builder_widget("settings_terminal_entry")); js_delay_spin = GTK_SPIN_BUTTON(get_gtk_builder_widget("settings_js_delay_spin")); jack_conf_tool_entry = GTK_ENTRY(get_gtk_builder_widget("settings_jack_conf_tool_entry")); dialog = GTK_DIALOG(get_gtk_builder_widget("settings_dialog")); if (!conf_get_bool(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, &autostart)) { autostart = LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART_DEFAULT; } if (!conf_get_bool(LADISH_CONF_KEY_DAEMON_NOTIFY, ¬ify)) { notify = LADISH_CONF_KEY_DAEMON_NOTIFY_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_DAEMON_SHELL, &shell)) { shell = LADISH_CONF_KEY_DAEMON_SHELL_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_DAEMON_TERMINAL, &terminal)) { terminal = LADISH_CONF_KEY_DAEMON_TERMINAL_DEFAULT; } if (!conf_get_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, &js_delay)) { js_delay = LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_JACK_CONF_TOOL, &jack_conf_tool)) { jack_conf_tool = LADISH_CONF_KEY_JACK_CONF_TOOL_DEFAULT; } gtk_toggle_button_set_active(autostart_studio_button, autostart); gtk_toggle_button_set_active(send_notifications_button, notify); gtk_entry_set_text(shell_entry, shell); gtk_entry_set_text(terminal_entry, terminal); gtk_entry_set_text(jack_conf_tool_entry, jack_conf_tool); gtk_spin_button_set_range(js_delay_spin, 0, 1000); gtk_spin_button_set_increments(js_delay_spin, 1, 2); gtk_spin_button_set_value(js_delay_spin, js_delay); gtk_widget_show(GTK_WIDGET(dialog)); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(GTK_WIDGET(dialog)); if (result != GTK_RESPONSE_OK) { return; } autostart = gtk_toggle_button_get_active(autostart_studio_button); notify = gtk_toggle_button_get_active(send_notifications_button); shell = gtk_entry_get_text(shell_entry); terminal = gtk_entry_get_text(terminal_entry); js_delay = gtk_spin_button_get_value(js_delay_spin); jack_conf_tool = gtk_entry_get_text(jack_conf_tool_entry); if (!conf_set_bool(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, autostart) || !conf_set_bool(LADISH_CONF_KEY_DAEMON_NOTIFY, notify) || !conf_set(LADISH_CONF_KEY_DAEMON_SHELL, shell) || !conf_set(LADISH_CONF_KEY_DAEMON_TERMINAL, terminal) || !conf_set_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, js_delay) || !conf_set(LADISH_CONF_KEY_JACK_CONF_TOOL, jack_conf_tool)) { error_message_box(_("Storing settings")); } }
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; }
END_TEST START_TEST (test_conf_default) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); conf_free (conf); }
END_TEST START_TEST (test_conf_file) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "c group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "b group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "e group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "d group", head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == 0, "ret = %d", ret); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 55, "Got %u expected %u", u, 55); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 75, "Got %u expected %u", u, 75); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not") == 0, "Got '%s' expected 'Not'", s); i = conf_get_int (conf, "b group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "b group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 85, "Got %u expected %u", u, 85); c = conf_get_char (conf, "b group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "b group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "b group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "b group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 25.5f) < 0.0001f, "Got %f expected %f", f, -25.5f); s = conf_get_string (conf, "b group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "c group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -16, "Got %d expected %d", i, -16); u = conf_get_uint (conf, "c group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 16, "Got %u expected %u", u, 16); c = conf_get_char (conf, "c group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\0', "Got %c expected %c", c, '\0'); bf = conf_get_bool (conf, "c group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "c group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "c group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "c group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, " Not Default") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "d group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 100, "Got %d expected %d", i, 100); u = conf_get_uint (conf, "d group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 100, "Got %u expected %u", u, 100); c = conf_get_char (conf, "d group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\07', "Got %c expected %c", c, '\07'); bf = conf_get_bool (conf, "d group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "d group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "d group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 100.0f) < 0.0001f, "Got %f expected %f", f, +100.0f); s = conf_get_string (conf, "d group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "\b\v\t\n\r\f\a\\\?\'\"\x10\010") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "e group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -100, "Got %d expected %d", i, -100); u = conf_get_uint (conf, "e group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 0, "Got %u expected %u", u, 0); c = conf_get_char (conf, "e group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\t', "Got %c expected %c", c, '\t'); bf = conf_get_bool (conf, "e group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "e group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "e group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 100) < 0.0001f, "Got %f expected %f", f, -100.0f); s = conf_get_string (conf, "e group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strlen (s) == 0, "Got '%s' expected ''", s); conf_free (conf); }
void *thr_socket_end_engine(void *p) { struct l7_worker_arg *arg = p; cJSON *conf = arg->conf; int pipe_fd = work_pipe[arg->index]; int n, i, j, ret, val; struct epoll_event evarr[EVENT_BATCH_SIZE], ev; struct sockaddr_in client_addr; socklen_t client_addr_len; int epollwait_timeout; int client_sd; struct socket_end_st *se, *head; pthread_cleanup_push(socket_end_cleanup, NULL); /* SOCKET_END_MAX is restricted in range [CONCURRENT_UNDERLIMIT, CONCURRENT_UPPERLIMIT]. * CONCURRENT_UNDERLIMIT and CONCURRENT_UPPERLIMIT is defined in socket_end.h */ SOCKET_END_MAX = conf_get_int("ConcurrentMax", conf); if (SOCKET_END_MAX<CONCURRENT_UNDERLIMIT) { SOCKET_END_MAX = CONCURRENT_UNDERLIMIT; } else if (SOCKET_END_MAX > CONCURRENT_UPPERLIMIT) { SOCKET_END_MAX = CONCURRENT_UPPERLIMIT; } socket_end_arr_max = SOCKET_END_MAX/nr_threads+1; socket_end_arr = calloc(1, sizeof(*socket_end_arr)*socket_end_arr_max); if (socket_end_arr==NULL) { mylog(L_ERR, "Insufficent memory for socket_end_arr[]."); goto quit; } timeout_index = olist_new(CONCURRENT_UPPERLIMIT, se_timeout_cmp); if (unlikely(timeout_index == NULL)) { mylog(L_ERR, "Init timeout index failed"); goto quit; } http_xff = conf_get_bool("HttpXff", conf) ? 0 : 1; epollfd = epoll_create(EVENT_BATCH_SIZE); // For old kernel compatible. 1 is OKZ too. if (unlikely(epollfd == -1)) { mylog(L_ERR, "Init epollfd failed"); goto quit; } ev.events = EPOLLIN; ev.data.u32 = U32_SOCKET_CONNECT; ret = epoll_ctl(epollfd, EPOLL_CTL_ADD, pipe_fd, &ev); if (unlikely(ret < 0)) { mylog(L_ERR, "Watch listen socket failed"); goto quit; } client_addr_len = sizeof(client_addr); while (1) { now=systimestamp_ms(); head = olist_peek_head(timeout_index); if (head) { epollwait_timeout = head->min_timeout_abs_ms - now; if (epollwait_timeout < 0) { epollwait_timeout = 0; } } else { epollwait_timeout = 500; } n=epoll_wait(epollfd, evarr, EVENT_BATCH_SIZE, epollwait_timeout); for (i=0; i<n; ++i) { if (evarr[i].data.u32 == U32_SOCKET_CONNECT) { /* accept is ready */ evarr[i].data.ptr = NULL; mylog(L_DEBUG, "Socket end arr nr is %d", socket_end_arr_nr); while (1) { ret = read(pipe_fd, &client_sd, sizeof(int)); if (ret < 0) { if (errno==EAGAIN) { break; } else { mylog(L_ERR, "get client sd from pipe error: %m"); goto quit; } } if (ret == 0) { continue; } mylog(L_DEBUG, "Worker got a new fd: %d", client_sd); atomic_decrease(socket_in_pipe); if (likely((socket_end_arr_nr >= (socket_end_arr_max - 1)) && (socket_end_total_nr < SOCKET_END_MAX))) { mylog(L_ERR, "Thread process too many socket_ends, close"); close(client_sd); break; } if (unlikely(socket_end_total_nr >= SOCKET_END_MAX)) { mylog(L_ERR, "TOO many socket_ends! Ignored!"); close(client_sd); } else { val = 1; if (setsockopt(client_sd, IPPROTO_TCP, TCP_CORK, &val, sizeof(val))< 0) { mylog(L_ERR, "Set client sd cork failed"); } se = socket_end_new(client_sd); if (unlikely(se == NULL)) { mylog(L_ERR, "Create socket end failed"); goto quit; } while (socket_end_arr[socket_end_arr_tail]!=NULL) { socket_end_arr_tail++; if (unlikely(socket_end_arr_tail>=socket_end_arr_max)) { socket_end_arr_tail=0; mylog(L_DEBUG, "Socket_end arr tail return to 0"); } } socket_end_arr[socket_end_arr_tail] = se; socket_end_arr[socket_end_arr_tail]->id = socket_end_arr_tail; mylog(L_DEBUG, "Create socket end, se[%d]", se->id); socket_end_arr_nr++; mylog(L_DEBUG, "Socket end arr nr is %d", socket_end_arr_nr); atomic_increase(&socket_end_total_nr); mylog(L_DEBUG, "Socket end total nr is %d", socket_end_total_nr); } } break; /* break after while */ } } for (i=0; i<n; ++i) { if (evarr[i].data.ptr == NULL) { continue; } /* evarr[] 排重 */ for (j=i+1;j<n;++j) { if (evarr[i].data.ptr == evarr[j].data.ptr) { evarr[j].data.ptr = NULL; } } se = evarr[i].data.ptr; if (unlikely(socket_end_driver(se)==-EINVAL)) { mylog(L_DEBUG, "Remove entry engine %p, se[%d]", se, se->id); if (unlikely(olist_remove_entry_by_datap(timeout_index, se)!=0)) { /* should not be here */ mylog(L_ERR, "Critical exception: socket end missed in epollfd, se[%d]", se->id); goto quit; //abort(); } socket_end_arr[se->id]=NULL; socket_end_destroy(se); socket_end_arr_nr--; atomic_decrease(&socket_end_total_nr); } } now = systimestamp_ms(); while (1) { se = olist_fetch_head(timeout_index); if (se == NULL) { //mylog(L_DEBUG, "timeout_index is empty."); break; } if (se->min_timeout_abs_ms != 0 && se->min_timeout_abs_ms < now) { mylog(L_INFO, "Socket end is timed out, se[%d]", se->id); socket_end_process_timeout(se, now); } else { if (se->min_timeout_abs_ms != 0) { if (olist_add_entry(timeout_index, se)) { mylog(L_DEBUG, "Add entry engine %p failed, se[%d]", se, se->id); } else { mylog(L_DEBUG, "Add entry engine %p success, se[%d]", se, se->id); } break; } } } } quit: mylog(L_DEBUG, "Quit thr engine"); pthread_cleanup_pop(1); if (timeout_index) { olist_destroy(timeout_index); timeout_index = NULL; } if (socket_end_arr) { free(socket_end_arr); } if (likely(epollfd > 0)) { close(epollfd); epollfd = -1; } pthread_exit(NULL); }
/** * 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; }
void hamlib_init(void) { rig_model_t model; struct timespec sleep; freq_t freq; rmode_t mode; pbwidth_t width; gboolean enable; gchar *port, *conf, *spd; gint ret, speed; if (rig != NULL) return; enable = conf_get_bool("hamlib/enable"); model = conf_get_int("hamlib/rig"); port = conf_get_filename("hamlib/port"); speed = conf_get_int("hamlib/speed"); conf = conf_get_string("hamlib/conf"); if (!enable || !model || port[0] == 0) return; rig_set_debug(RIG_DEBUG_ERR); rig = rig_init(model); if (rig == NULL) { errmsg(_("Hamlib init: rig_init failed (model=%d)"), model); return; } g_strstrip(conf); if (conf[0]) { gchar **v, **p, *q; v = g_strsplit(conf, ",", 0); for (p = v; *p; p++) { if ((q = strchr(*p, '=')) == NULL) { errmsg(_("Hamlib init: Bad param=value pair: '%s'"), *p); break; } *q++ = 0; g_strstrip(*p); g_strstrip(q); if (hamlib_set_param(*p, q) == FALSE) break; } g_strfreev(v); } g_free(conf); hamlib_set_param("rig_pathname", port); g_free(port); spd = g_strdup_printf("%d", speed); hamlib_set_param("serial_speed", spd); g_free(spd); ret = rig_open(rig); if (ret != RIG_OK) { errmsg(_("Hamlib init: rig_open failed: %s"), rigerror(ret)); rig_cleanup(rig); rig = NULL; return; } /* Polling the rig sometimes fails right after opening it */ sleep.tv_sec = 0; sleep.tv_nsec = 100000000L; /* 100ms */ nanosleep(&sleep, NULL); if (need_freq == TRUE && \ (ret = rig_get_freq(rig, RIG_VFO_CURR, &freq)) != RIG_OK) { errmsg(_("Hamlib init: rig_get_freq failed: %s"), rigerror(ret)); hamlib_waterfall = FALSE; hamlib_qsodata = FALSE; need_freq = FALSE; need_mode = FALSE; } if (need_mode == TRUE && (ret = rig_get_mode(rig, RIG_VFO_CURR, &mode, &width)) != RIG_OK) { errmsg(_("Hamlib init: rig_get_mode failed: %s.\nAssuming USB mode."), rigerror(ret)); need_mode = FALSE; } if (hamlib_ptt == TRUE && (ret = rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_OFF)) != RIG_OK) { errmsg(_("Hamlib init: rig_set_ptt failed: %s.\nHamlib PTT disabled"), rigerror(ret)); hamlib_ptt = FALSE; } /* Don't create the thread if frequency data is not needed */ if (need_freq == FALSE) { // g_warning("Freq data not needed, thread not started."); /* If PTT isn't needed either then close everything */ if (hamlib_ptt == FALSE) { // g_warning("PTT not needed, closing rig."); rig_close(rig); rig_cleanup(rig); rig = NULL; } return; } if (pthread_create(&hamlib_thread, NULL, hamlib_loop, NULL) < 0) { errmsg(_("Hamlib init: pthread_create: %m")); rig_close(rig); rig_cleanup(rig); rig = NULL; } }
END_TEST START_TEST (test_conf_errors) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; /* * Test Add group errors. */ conf = conf_create (); fail_unless (conf != 0); /* Add group to non conf. */ ret = conf_add_group (NULL, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add two groups with no group name under root. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add group with bad parameter type. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, bad_1_group); fail_unless (ret < 0); conf_free (conf); /* * Test load errors. */ conf = conf_create (); fail_unless (conf != 0); /* Load with no groups. */ ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == -1); /* Test filename. */ ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); ret = conf_load (conf, NULL); fail_unless (ret == -1); ret = conf_load (conf, "/dev/null/something"); fail_unless (ret == -1); /* Test group names. */ ret = conf_load (conf, CONFDIR "test_bad1.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad2.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad3.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad4.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad5.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad6.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad7.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad8.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad9.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad10.conf"); fail_unless (ret != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test_bad11.conf"); fail_unless (ret == -15, "%d", ret); ret = conf_load (conf, CONFDIR "test_bad12.conf"); fail_unless (ret == -13); ret = conf_load (conf, CONFDIR "test_bad13.conf"); fail_unless (ret != -14); ret = conf_load (conf, CONFDIR "test_bad14.conf"); fail_unless (ret == -17, "%d", ret); conf_free (conf); /* Test getting values */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 0); i = conf_get_int (conf, "a group", "X_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, "a group", "X_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, "a group", "X_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, "a group", "X_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, "a group", "X_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, "a group", "X_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, "a group", "X_string", &valid); fail_unless (valid == 0); conf_free (conf); }
int PerconaFTEngine::Init(const std::string& dir, const std::string& options) { Properties props; parse_conf_content(options, props); //parse config conf_get_int64(props, "cache_size", g_perconaft_config.cache_size); conf_get_uint32(props, "checkpoint_pool_threads", g_perconaft_config.checkpoint_pool_threads); conf_get_uint32(props, "checkpoint_period", g_perconaft_config.checkpoint_period); conf_get_uint32(props, "cleaner_period", g_perconaft_config.cleaner_period); conf_get_uint32(props, "cleaner_iterations", g_perconaft_config.cleaner_iterations); conf_get_bool(props, "evictor_enable_partial_eviction", g_perconaft_config.evictor_enable_partial_eviction); std::string compression; conf_get_string(props, "compression", compression); if (compression == "none") { g_perconaft_config.compression = TOKU_NO_COMPRESSION; } else if (compression == "snappy" || compression.empty()) { g_perconaft_config.compression = TOKU_SNAPPY_METHOD; } else if (compression == "zlib") { g_perconaft_config.compression = TOKU_ZLIB_METHOD; } else { ERROR_LOG("Invalid compression config:%s for PercanoFT.", compression.c_str()); return -1; } uint32 env_open_flags = DB_CREATE | DB_PRIVATE | DB_THREAD | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_RECOVER; int env_open_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; db_env_create(&m_env, 0); m_env->set_default_bt_compare(m_env, ardb_perconaft_compare); m_env->set_errcall(m_env, _err_callback); /* * set env config */ uint32 cache_gsize = g_perconaft_config.cache_size >> 30; uint32 cache_bytes = g_perconaft_config.cache_size % (1024 * 1024 * 1024); m_env->set_cachesize(m_env, cache_gsize, cache_bytes, 1); m_env->set_cachetable_pool_threads(m_env, g_perconaft_config.checkpoint_pool_threads); m_env->checkpointing_set_period(m_env, g_perconaft_config.checkpoint_period); m_env->cleaner_set_period(m_env, g_perconaft_config.cleaner_period); m_env->cleaner_set_iterations(m_env, g_perconaft_config.cleaner_iterations); m_env->evictor_set_enable_partial_eviction(m_env, g_perconaft_config.evictor_enable_partial_eviction); int r = m_env->open(m_env, dir.c_str(), env_open_flags, env_open_mode); CHECK_EXPR(r); DataArray nss; if (0 == r) { g_toku_env = m_env; DB* db = m_env->get_db_for_directory(m_env); if (NULL != db) { PerconaFTLocalContext& local_ctx = g_local_ctx.GetValue(); DB_TXN* txn = local_ctx.transc.Get(); DBC *c = NULL; CHECK_EXPR(r = db->cursor(db, txn, &c, 0)); if (0 == r) { r = c->c_getf_first(c, 0, nil_callback, NULL); } while (0 == r) { DBT raw_key; DBT raw_val; memset(&raw_key, 0, sizeof(raw_key)); memset(&raw_val, 0, sizeof(raw_key)); if (0 == c->c_get(c, &raw_key, &raw_val, DB_CURRENT)) { //std::string ns_str Data ns; ns.SetString((const char*) raw_key.data, false); INFO_LOG("TokuFT directory db %s:%s", (const char* ) raw_key.data, (const char* ) raw_val.data); nss.push_back(ns); } r = c->c_getf_next(c, 0, nil_callback, NULL); } if (NULL != c) { c->c_close(c); } local_ctx.transc.Release(true); r = 0; } } for (size_t i = 0; i < nss.size(); i++) { Context tmp; GetFTDB(tmp, nss[i], true); } return ENGINE_ERR(r); }
bool ArdbConfig::Parse(const Properties& props) { conf_props = props; conf_get_string(props, "home", home); if (home.empty()) { home = "../ardb"; } make_dir(home); int err = real_path(home, home); if (0 != err) { ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } err = access(home.c_str(), R_OK | W_OK); if (0 != err) { err = errno; ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } setenv("ARDB_HOME", home.c_str(), 1); replace_env_var(const_cast<Properties&>(props)); conf_get_string(props, "pidfile", pidfile); conf_get_int64(props, "thread-pool-size", thread_pool_size); if (thread_pool_size <= 0) { thread_pool_size = available_processors(); } conf_get_int64(props, "hz", hz); if (hz < CONFIG_MIN_HZ) hz = CONFIG_MIN_HZ; if (hz > CONFIG_MAX_HZ) hz = CONFIG_MAX_HZ; conf_get_int64(props, "tcp-keepalive", tcp_keepalive); conf_get_int64(props, "timeout", timeout); //conf_get_int64(props, "unixsocketperm", unixsocketperm); conf_get_int64(props, "slowlog-log-slower-than", slowlog_log_slower_than); conf_get_int64(props, "slowlog-max-len", slowlog_max_len); conf_get_int64(props, "maxclients", max_clients); if(max_clients <= 0) { max_clients = 10000; } for (int i = 0;; i++) { char config_key[256]; sprintf(config_key, "server[%d].listen", i); ListenPoint lp; std::string address; if (!conf_get_string(props, config_key, address)) { break; } if (address.find(":") == std::string::npos) { lp.host = address; } else { std::vector<std::string> ss = split_string(address, ":"); uint32 port; if (ss.size() < 2 || !string_touint32(ss[ss.size() - 1], port) || port > 65535) { ERROR_LOG("Invalid listen address %s", address.c_str()); return false; } lp.host = address.substr(0, address.size() - ss[ss.size() - 1].size() - 1); lp.port = port; } sprintf(config_key, "server[%d].qps-limit", i); conf_get_int64(props, config_key, lp.qps_limit); sprintf(config_key, "server[%d].unixsocketperm", i); conf_get_int64(props, config_key, lp.qps_limit); servers.push_back(lp); } if (servers.empty()) { ListenPoint lp; lp.host = "0.0.0.0"; lp.port = 16379; servers.push_back(lp); } if (strcasecmp(engine.c_str(), "rocksdb") == 0) { conf_get_string(props, "rocksdb.compaction", rocksdb_compaction); conf_get_bool(props, "rocksdb.disableWAL", rocksdb_disablewal); conf_get_bool(props, "rocksdb.scan-total-order", rocksdb_scan_total_order); } conf_get_string(props, "engine", engine); conf_get_string(props, "data-dir", data_base_path); conf_get_string(props, "backup-dir", backup_dir); conf_get_string(props, "repl-dir", repl_data_dir); make_dir(repl_data_dir); make_dir(backup_dir); err = real_path(repl_data_dir, repl_data_dir); if (0 != err) { ERROR_LOG("Invalid 'repl-dir' config:%s for reason:%s", repl_data_dir.c_str(), strerror(err)); return false; } std::string backup_file_format; conf_get_string(props, "backup-file-format", backup_file_format); if (!strcasecmp(backup_file_format.c_str(), "redis")) { backup_redis_format = true; } conf_get_string(props, "zookeeper-servers", zookeeper_servers); conf_get_string(props, "zk-clientid-file", zk_clientid_file); conf_get_string(props, "loglevel", loglevel); conf_get_string(props, "logfile", logfile); conf_get_bool(props, "daemonize", daemonize); conf_get_int64(props, "repl-backlog-size", repl_backlog_size); conf_get_int64(props, "repl-backlog-cache-size", repl_backlog_cache_size); conf_get_int64(props, "repl-ping-slave-period", repl_ping_slave_period); conf_get_int64(props, "repl-timeout", repl_timeout); conf_get_int64(props, "repl-backlog-sync-period", repl_backlog_sync_period); conf_get_int64(props, "repl-backlog-ttl", repl_backlog_time_limit); conf_get_int64(props, "min-slaves-to-write", repl_min_slaves_to_write); conf_get_int64(props, "min-slaves-max-lag", repl_min_slaves_max_lag); conf_get_bool(props, "slave-serve-stale-data", repl_serve_stale_data); conf_get_int64(props, "max-slave-worker-queue", max_slave_worker_queue); if(max_slave_worker_queue <= 0) { max_slave_worker_queue = 1024; } conf_get_bool(props, "repl-disable-tcp-nodelay", repl_disable_tcp_nodelay); conf_get_int64(props, "lua-time-limit", lua_time_limit); conf_get_int64(props, "snapshot-max-lag-offset", snapshot_max_lag_offset); conf_get_int64(props, "maxsnapshots", maxsnapshots); if(maxsnapshots == 0) { maxsnapshots = 1; } if (snapshot_max_lag_offset > repl_backlog_size / 2) { snapshot_max_lag_offset = repl_backlog_size / 2; } conf_get_int64(props, "hll-sparse-max-bytes", hll_sparse_max_bytes); conf_get_bool(props, "slave-read-only", slave_readonly); conf_get_bool(props, "slave-serve-stale-data", slave_serve_stale_data); conf_get_int64(props, "slave-priority", slave_priority); conf_get_bool(props, "slave-ignore-expire", slave_ignore_expire); conf_get_bool(props, "slave-ignore-del", slave_ignore_del); conf_get_bool(props, "slave-cleardb-before-fullresync", slave_cleardb_before_fullresync); conf_get_int64(props, "statistics-log-period", statistics_log_period); if (statistics_log_period <= 0) { statistics_log_period = DEFAULT_STAT_LOG_PERIOD_SECS; } std::string slaveof; if (conf_get_string(props, "slaveof", slaveof)) { std::vector<std::string> ss = split_string(slaveof, ":"); if (ss.size() == 2) { master_host = ss[0]; if (!string_touint32(ss[1], master_port)) { master_host = ""; WARN_LOG("Invalid 'slaveof' config."); } } else { WARN_LOG("Invalid 'slaveof' config."); } } conf_get_string(props, "masterauth", masterauth); if (data_base_path.empty()) { data_base_path = "."; } make_dir(data_base_path); err = real_path(data_base_path, data_base_path); if (0 != err) { ERROR_LOG("Invalid 'data-dir' config:%s for reason:%s", data_base_path.c_str(), strerror(err)); return false; } conf_get_string(props, "requirepass", requirepass); Properties::const_iterator fit = props.find("rename-command"); if (fit != props.end()) { rename_commands.clear(); const ConfItemsArray& cs = fit->second; ConfItemsArray::const_iterator cit = cs.begin(); while (cit != cs.end()) { if (cit->size() != 2) { ERROR_LOG("Invalid 'rename-command' config with %u args.", cit->size()); } else { rename_commands[cit->at(0)] = cit->at(1); } cit++; } } conf_get_int64(props, "reply-pool-size", reply_pool_size); conf_get_int64(props, "slave-client-output-buffer-limit", slave_client_output_buffer_limit); conf_get_int64(props, "pubsub-client-output-buffer-limit", pubsub_client_output_buffer_limit); conf_get_string(props, "redis-compatible-version", redis_compatible_version); conf_get_bool(props, "redis-compatible-mode", redis_compatible); conf_get_bool(props, "compact-after-snapshot-load", compact_after_snapshot_load); conf_get_int64(props, "qps-limit-per-host", qps_limit_per_host); conf_get_int64(props, "qps-limit-per-connection", qps_limit_per_connection); conf_get_int64(props, "range-delete-min-size", range_delete_min_size); conf_get_int64(props, "stream-lru-cache-size", stream_lru_cache_size); //trusted_ip.clear(); Properties::const_iterator ip_it = props.find("trusted-ip"); if (ip_it != props.end()) { const ConfItemsArray& cs = ip_it->second; for (uint32 i = 0; i < cs.size(); i++) { //trusted_ip.insert(cs[i][0]); } } if (!verify_config(*this)) { return false; } ArdbLogger::SetLogLevel(loglevel); return true; }
int main(int argc, char **argv) { bool sending; int *fdlist; int fd; int i, fdstate; size_t fdsize; int exitcode; bool errors; enum TriState sanitise_stdout = AUTO, sanitise_stderr = AUTO; bool use_subsystem = false; bool just_test_share_exists = false; unsigned long now; struct winsize size; const struct BackendVtable *backvt; fdlist = NULL; fdsize = 0; /* * Initialise port and protocol to sensible defaults. (These * will be overridden by more or less anything.) */ default_protocol = PROT_SSH; default_port = 22; bufchain_init(&stdout_data); bufchain_init(&stderr_data); bufchain_sink_init(&stdout_bcs, &stdout_data); bufchain_sink_init(&stderr_bcs, &stderr_data); stdout_bs = BinarySink_UPCAST(&stdout_bcs); stderr_bs = BinarySink_UPCAST(&stderr_bcs); outgoingeof = EOF_NO; flags = FLAG_STDERR_TTY; cmdline_tooltype |= (TOOLTYPE_HOST_ARG | TOOLTYPE_HOST_ARG_CAN_BE_SESSION | TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD); stderr_tty_init(); /* * Process the command line. */ conf = conf_new(); do_defaults(NULL, conf); loaded_session = false; default_protocol = conf_get_int(conf, CONF_protocol); default_port = conf_get_int(conf, CONF_port); errors = false; { /* * Override the default protocol if PLINK_PROTOCOL is set. */ char *p = getenv("PLINK_PROTOCOL"); if (p) { const struct BackendVtable *vt = backend_vt_from_name(p); if (vt) { default_protocol = vt->protocol; default_port = vt->default_port; conf_set_int(conf, CONF_protocol, default_protocol); conf_set_int(conf, CONF_port, default_port); } } } while (--argc) { char *p = *++argv; int ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL), 1, conf); if (ret == -2) { fprintf(stderr, "plink: option \"%s\" requires an argument\n", p); errors = true; } else if (ret == 2) { --argc, ++argv; } else if (ret == 1) { continue; } else if (!strcmp(p, "-batch")) { console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ use_subsystem = true; } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) { version(); } else if (!strcmp(p, "--help")) { usage(); exit(0); } else if (!strcmp(p, "-pgpfp")) { pgp_fingerprints(); exit(1); } else if (!strcmp(p, "-o")) { if (argc <= 1) { fprintf(stderr, "plink: option \"-o\" requires an argument\n"); errors = true; } else { --argc; /* Explicitly pass "plink" in place of appname for * error reporting purposes. appname will have been * set by be_foo.c to something more generic, probably * "PuTTY". */ provide_xrm_string(*++argv, "plink"); } } else if (!strcmp(p, "-shareexists")) { just_test_share_exists = true; } else if (!strcmp(p, "-fuzznet")) { conf_set_int(conf, CONF_proxy_type, PROXY_FUZZ); conf_set_str(conf, CONF_proxy_telnet_command, "%host"); } else if (!strcmp(p, "-sanitise-stdout") || !strcmp(p, "-sanitize-stdout")) { sanitise_stdout = FORCE_ON; } else if (!strcmp(p, "-no-sanitise-stdout") || !strcmp(p, "-no-sanitize-stdout")) { sanitise_stdout = FORCE_OFF; } else if (!strcmp(p, "-sanitise-stderr") || !strcmp(p, "-sanitize-stderr")) { sanitise_stderr = FORCE_ON; } else if (!strcmp(p, "-no-sanitise-stderr") || !strcmp(p, "-no-sanitize-stderr")) { sanitise_stderr = FORCE_OFF; } else if (!strcmp(p, "-no-antispoof")) { console_antispoof_prompt = false; } else if (*p != '-') { strbuf *cmdbuf = strbuf_new(); while (argc > 0) { if (cmdbuf->len > 0) put_byte(cmdbuf, ' '); /* add space separator */ put_datapl(cmdbuf, ptrlen_from_asciz(p)); if (--argc > 0) p = *++argv; } conf_set_str(conf, CONF_remote_cmd, cmdbuf->s); conf_set_str(conf, CONF_remote_cmd2, ""); conf_set_bool(conf, CONF_nopty, true); /* command => no tty */ strbuf_free(cmdbuf); break; /* done with cmdline */ } else { fprintf(stderr, "plink: unknown option \"%s\"\n", p); errors = true; } } if (errors) return 1; if (!cmdline_host_ok(conf)) { usage(); } prepare_session(conf); /* * Perform command-line overrides on session configuration. */ cmdline_run_saved(conf); /* * If we have no better ideas for the remote username, use the local * one, as 'ssh' does. */ if (conf_get_str(conf, CONF_username)[0] == '\0') { char *user = get_username(); if (user) { conf_set_str(conf, CONF_username, user); sfree(user); } } /* * Apply subsystem status. */ if (use_subsystem) conf_set_bool(conf, CONF_ssh_subsys, true); if (!*conf_get_str(conf, CONF_remote_cmd) && !*conf_get_str(conf, CONF_remote_cmd2) && !*conf_get_str(conf, CONF_ssh_nc_host)) flags |= FLAG_INTERACTIVE; /* * Select protocol. This is farmed out into a table in a * separate file to enable an ssh-free variant. */ backvt = backend_vt_from_proto(conf_get_int(conf, CONF_protocol)); if (!backvt) { fprintf(stderr, "Internal fault: Unsupported protocol found\n"); return 1; } /* * Block SIGPIPE, so that we'll get EPIPE individually on * particular network connections that go wrong. */ putty_signal(SIGPIPE, SIG_IGN); /* * Set up the pipe we'll use to tell us about SIGWINCH. */ if (pipe(signalpipe) < 0) { perror("pipe"); exit(1); } /* We don't want the signal handler to block if the pipe's full. */ nonblock(signalpipe[0]); nonblock(signalpipe[1]); cloexec(signalpipe[0]); cloexec(signalpipe[1]); putty_signal(SIGWINCH, sigwinch); /* * Now that we've got the SIGWINCH handler installed, try to find * out the initial terminal size. */ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &size) >= 0) { conf_set_int(conf, CONF_width, size.ws_col); conf_set_int(conf, CONF_height, size.ws_row); } /* * Decide whether to sanitise control sequences out of standard * output and standard error. * * If we weren't given a command-line override, we do this if (a) * the fd in question is pointing at a terminal, and (b) we aren't * trying to allocate a terminal as part of the session. * * (Rationale: the risk of control sequences is that they cause * confusion when sent to a local terminal, so if there isn't one, * no problem. Also, if we allocate a remote terminal, then we * sent a terminal type, i.e. we told it what kind of escape * sequences we _like_, i.e. we were expecting to receive some.) */ if (sanitise_stdout == FORCE_ON || (sanitise_stdout == AUTO && isatty(STDOUT_FILENO) && conf_get_bool(conf, CONF_nopty))) { stdout_scc = stripctrl_new(stdout_bs, true, L'\0'); stdout_bs = BinarySink_UPCAST(stdout_scc); } if (sanitise_stderr == FORCE_ON || (sanitise_stderr == AUTO && isatty(STDERR_FILENO) && conf_get_bool(conf, CONF_nopty))) { stderr_scc = stripctrl_new(stderr_bs, true, L'\0'); stderr_bs = BinarySink_UPCAST(stderr_scc); } sk_init(); uxsel_init(); /* * Plink doesn't provide any way to add forwardings after the * connection is set up, so if there are none now, we can safely set * the "simple" flag. */ if (conf_get_int(conf, CONF_protocol) == PROT_SSH && !conf_get_bool(conf, CONF_x11_forward) && !conf_get_bool(conf, CONF_agentfwd) && !conf_get_str_nthstrkey(conf, CONF_portfwd, 0)) conf_set_bool(conf, CONF_ssh_simple, true); if (just_test_share_exists) { if (!backvt->test_for_upstream) { fprintf(stderr, "Connection sharing not supported for connection " "type '%s'\n", backvt->name); return 1; } if (backvt->test_for_upstream(conf_get_str(conf, CONF_host), conf_get_int(conf, CONF_port), conf)) return 0; else return 1; } /* * Start up the connection. */ logctx = log_init(default_logpolicy, conf); { const char *error; char *realhost; /* nodelay is only useful if stdin is a terminal device */ bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0); /* This is a good place for a fuzzer to fork us. */ #ifdef __AFL_HAVE_MANUAL_CONTROL __AFL_INIT(); #endif error = backend_init(backvt, plink_seat, &backend, logctx, conf, conf_get_str(conf, CONF_host), conf_get_int(conf, CONF_port), &realhost, nodelay, conf_get_bool(conf, CONF_tcp_keepalives)); if (error) { fprintf(stderr, "Unable to open connection:\n%s\n", error); return 1; } ldisc_create(conf, NULL, backend, plink_seat); sfree(realhost); } /* * Set up the initial console mode. We don't care if this call * fails, because we know we aren't necessarily running in a * console. */ local_tty = (tcgetattr(STDIN_FILENO, &orig_termios) == 0); atexit(cleanup_termios); seat_echoedit_update(plink_seat, 1, 1); sending = false; now = GETTICKCOUNT(); pollwrapper *pw = pollwrap_new(); while (1) { int rwx; int ret; unsigned long next; pollwrap_clear(pw); pollwrap_add_fd_rwx(pw, signalpipe[0], SELECT_R); if (!sending && backend_connected(backend) && backend_sendok(backend) && backend_sendbuffer(backend) < MAX_STDIN_BACKLOG) { /* If we're OK to send, then try to read from stdin. */ pollwrap_add_fd_rwx(pw, STDIN_FILENO, SELECT_R); } if (bufchain_size(&stdout_data) > 0) { /* If we have data for stdout, try to write to stdout. */ pollwrap_add_fd_rwx(pw, STDOUT_FILENO, SELECT_W); } if (bufchain_size(&stderr_data) > 0) { /* If we have data for stderr, try to write to stderr. */ pollwrap_add_fd_rwx(pw, STDERR_FILENO, SELECT_W); } /* Count the currently active fds. */ i = 0; for (fd = first_fd(&fdstate, &rwx); fd >= 0; fd = next_fd(&fdstate, &rwx)) i++; /* Expand the fdlist buffer if necessary. */ sgrowarray(fdlist, fdsize, i); /* * Add all currently open fds to pw, and store them in fdlist * as well. */ int fdcount = 0; for (fd = first_fd(&fdstate, &rwx); fd >= 0; fd = next_fd(&fdstate, &rwx)) { fdlist[fdcount++] = fd; pollwrap_add_fd_rwx(pw, fd, rwx); } if (toplevel_callback_pending()) { ret = pollwrap_poll_instant(pw); } else if (run_timers(now, &next)) { do { unsigned long then; long ticks; then = now; now = GETTICKCOUNT(); if (now - then > next - then) ticks = 0; else ticks = next - now; bool overflow = false; if (ticks > INT_MAX) { ticks = INT_MAX; overflow = true; } ret = pollwrap_poll_timeout(pw, ticks); if (ret == 0 && !overflow) now = next; else now = GETTICKCOUNT(); } while (ret < 0 && errno == EINTR); } else { ret = pollwrap_poll_endless(pw); } if (ret < 0 && errno == EINTR) continue; if (ret < 0) { perror("poll"); exit(1); } for (i = 0; i < fdcount; i++) { fd = fdlist[i]; int rwx = pollwrap_get_fd_rwx(pw, fd); /* * We must process exceptional notifications before * ordinary readability ones, or we may go straight * past the urgent marker. */ if (rwx & SELECT_X) select_result(fd, SELECT_X); if (rwx & SELECT_R) select_result(fd, SELECT_R); if (rwx & SELECT_W) select_result(fd, SELECT_W); } if (pollwrap_check_fd_rwx(pw, signalpipe[0], SELECT_R)) { char c[1]; struct winsize size; if (read(signalpipe[0], c, 1) <= 0) /* ignore error */; /* ignore its value; it'll be `x' */ if (ioctl(STDIN_FILENO, TIOCGWINSZ, (void *)&size) >= 0) backend_size(backend, size.ws_col, size.ws_row); } if (pollwrap_check_fd_rwx(pw, STDIN_FILENO, SELECT_R)) { char buf[4096]; int ret; if (backend_connected(backend)) { ret = read(STDIN_FILENO, buf, sizeof(buf)); noise_ultralight(NOISE_SOURCE_IOLEN, ret); if (ret < 0) { perror("stdin: read"); exit(1); } else if (ret == 0) { backend_special(backend, SS_EOF, 0); sending = false; /* send nothing further after this */ } else { if (local_tty) from_tty(buf, ret); else backend_send(backend, buf, ret); } } } if (pollwrap_check_fd_rwx(pw, STDOUT_FILENO, SELECT_W)) { backend_unthrottle(backend, try_output(false)); } if (pollwrap_check_fd_rwx(pw, STDERR_FILENO, SELECT_W)) { backend_unthrottle(backend, try_output(true)); } run_toplevel_callbacks(); if (!backend_connected(backend) && bufchain_size(&stdout_data) == 0 && bufchain_size(&stderr_data) == 0) break; /* we closed the connection */ } exitcode = backend_exitcode(backend); if (exitcode < 0) { fprintf(stderr, "Remote process exit code unavailable\n"); exitcode = 1; /* this is an error condition */ } cleanup_exit(exitcode); return exitcode; /* shouldn't happen, but placates gcc */ }
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; }
/* * This function can accept a NULL pointer as `addr', in which case * it will only check the host name. */ bool proxy_for_destination (SockAddr *addr, const char *hostname, int port, Conf *conf) { int s = 0, e = 0; char hostip[64]; int hostip_len, hostname_len; const char *exclude_list; /* * Special local connections such as Unix-domain sockets * unconditionally cannot be proxied, even in proxy-localhost * mode. There just isn't any way to ask any known proxy type for * them. */ if (addr && sk_address_is_special_local(addr)) return false; /* do not proxy */ /* * Check the host name and IP against the hard-coded * representations of `localhost'. */ if (!conf_get_bool(conf, CONF_even_proxy_localhost) && (sk_hostname_is_local(hostname) || (addr && sk_address_is_local(addr)))) return false; /* do not proxy */ /* we want a string representation of the IP address for comparisons */ if (addr) { sk_getaddr(addr, hostip, 64); hostip_len = strlen(hostip); } else hostip_len = 0; /* placate gcc; shouldn't be required */ hostname_len = strlen(hostname); exclude_list = conf_get_str(conf, CONF_proxy_exclude_list); /* now parse the exclude list, and see if either our IP * or hostname matches anything in it. */ while (exclude_list[s]) { while (exclude_list[s] && (isspace((unsigned char)exclude_list[s]) || exclude_list[s] == ',')) s++; if (!exclude_list[s]) break; e = s; while (exclude_list[e] && (isalnum((unsigned char)exclude_list[e]) || exclude_list[e] == '-' || exclude_list[e] == '.' || exclude_list[e] == '*')) e++; if (exclude_list[s] == '*') { /* wildcard at beginning of entry */ if ((addr && strnicmp(hostip + hostip_len - (e - s - 1), exclude_list + s + 1, e - s - 1) == 0) || strnicmp(hostname + hostname_len - (e - s - 1), exclude_list + s + 1, e - s - 1) == 0) { /* IP/hostname range excluded. do not use proxy. */ return false; } } else if (exclude_list[e-1] == '*') { /* wildcard at end of entry */ if ((addr && strnicmp(hostip, exclude_list + s, e - s - 1) == 0) || strnicmp(hostname, exclude_list + s, e - s - 1) == 0) { /* IP/hostname range excluded. do not use proxy. */ return false; } } else { /* no wildcard at either end, so let's try an absolute * match (ie. a specific IP) */ if (addr && strnicmp(hostip, exclude_list + s, e - s) == 0) return false; /* IP/hostname excluded. do not use proxy. */ if (strnicmp(hostname, exclude_list + s, e - s) == 0) return false; /* IP/hostname excluded. do not use proxy. */ } s = e; /* Make sure we really have reached the next comma or end-of-string */ while (exclude_list[s] && !isspace((unsigned char)exclude_list[s]) && exclude_list[s] != ',') s++; } /* no matches in the exclude list, so use the proxy */ return true; }