/** * Callback function to use with INI-H. * @arg user Opaque user value. We use the statsite_config pointer * @arg section The INI seciton * @arg name The config name * @arg value The config value * @return 1 on success. */ static int config_callback(void* user, const char* section, const char* name, const char* value) { // Specially handle histogram sections if (strncasecmp("histogram", section, 9) == 0) { return histogram_callback(user, section, name, value); } // Ignore any non-statsite sections if (strcasecmp("statsite", section) != 0) { return 0; } // Cast the user handle statsite_config *config = (statsite_config*)user; // Switch on the config #define NAME_MATCH(param) (strcasecmp(param, name) == 0) // Handle the int cases if (NAME_MATCH("port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("tcp_port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("udp_port")) { return value_to_int(value, &config->udp_port); } else if (NAME_MATCH("flush_interval")) { return value_to_int(value, &config->flush_interval); } else if (NAME_MATCH("daemonize")) { return value_to_bool(value, &config->daemonize); } else if (NAME_MATCH("binary_stream")) { return value_to_bool(value, &config->binary_stream); // Handle the double cases } else if (NAME_MATCH("timer_eps")) { return value_to_double(value, &config->timer_eps); } else if (NAME_MATCH("set_eps")) { return value_to_double(value, &config->set_eps); // Copy the string values } else if (NAME_MATCH("log_level")) { config->log_level = strdup(value); } else if (NAME_MATCH("stream_cmd")) { config->stream_cmd = strdup(value); } else if (NAME_MATCH("pid_file")) { config->pid_file = strdup(value); } else if (NAME_MATCH("input_counter")) { config->input_counter = strdup(value); } else if (NAME_MATCH("bind_address")) { config->bind_address = strdup(value); // Unknown parameter? } else { // Log it, but ignore syslog(LOG_NOTICE, "Unrecognized config parameter: %s", value); } // Success return 1; }
/** * Callback function to use with INI-H. * @arg user Opaque user value. We use the statsite_config pointer * @arg section The INI seciton * @arg name The config name * @arg value The config value * @return 1 on success. */ static int config_callback(void* user, const char* section, const char* name, const char* value) { // Specially handle histogram sections if (strncasecmp("histogram", section, 9) == 0) { return histogram_callback(user, section, name, value); } if (strncasecmp("sink", section, 4) == 0) { return sink_callback(user, section, name, value); } // Ignore any non-statsite sections if (strcasecmp("statsite", section) != 0) { syslog(LOG_NOTICE, "Unknown values in section ignored: %s", section); return 0; } // Cast the user handle statsite_config *config = (statsite_config*)user; // Handle the int cases if (NAME_MATCH("port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("tcp_port")) { return value_to_int(value, &config->tcp_port); } else if (NAME_MATCH("udp_port")) { return value_to_int(value, &config->udp_port); } else if (NAME_MATCH("flush_interval")) { return value_to_int(value, &config->flush_interval); } else if (NAME_MATCH("parse_stdin")) { return value_to_bool(value, &config->parse_stdin); } else if (NAME_MATCH("daemonize")) { return value_to_bool(value, &config->daemonize); } else if (NAME_MATCH("use_type_prefix")) { return value_to_bool(value, &config->use_type_prefix); } else if (NAME_MATCH("extended_counters")) { return value_to_bool(value, &config->extended_counters); } else if (NAME_MATCH("prefix_binary_stream")) { return value_to_bool(value, &config->prefix_binary_stream); // Handle the double cases } else if (NAME_MATCH("timer_eps")) { return value_to_double(value, &config->timer_eps); } else if (NAME_MATCH("set_eps")) { return value_to_double(value, &config->set_eps); // Handle quantiles as a comma-separated list of doubles } else if (NAME_MATCH("quantiles")) { return value_to_list_of_doubles(value, &config->quantiles, &config->num_quantiles); // Copy the string values } else if (NAME_MATCH("log_level")) { config->log_level = strdup(value); } else if (NAME_MATCH("log_facility")) { config->log_facility = strdup(value); } else if (NAME_MATCH("pid_file")) { config->pid_file = strdup(value); } else if (NAME_MATCH("input_counter")) { config->input_counter = strdup(value); } else if (NAME_MATCH("bind_address")) { config->bind_address = strdup(value); } else if (NAME_MATCH("global_prefix")) { config->global_prefix = strdup(value); } else if (NAME_MATCH("counts_prefix")) { config->prefixes[COUNTER] = strdup(value); } else if (NAME_MATCH("gauges_prefix")) { config->prefixes[GAUGE] = strdup(value); } else if (NAME_MATCH("timers_prefix")) { config->prefixes[TIMER] = strdup(value); } else if (NAME_MATCH("sets_prefix")) { config->prefixes[SET] = strdup(value); } else if (NAME_MATCH("kv_prefix")) { config->prefixes[KEY_VAL] = strdup(value); // Copy the multi-case variables } else if (NAME_MATCH("log_facility")) { return name_to_facility(value, &config->syslog_log_facility); // Unknown parameter? } else { // Log it, but ignore syslog(LOG_NOTICE, "Unrecognized config parameter: %s", name); } // Success return 1; }