index 9579d91e45cf02b8241302f3bb52dbfd56de996f..ee0111c4f5c141be9d087fcbca7154ba82810924 100644 (file)
*/
static sdb_time_t default_interval = 0;
+static char *plugin_dir = NULL;
/*
* private helper functions
* public parse results
*/
-char **listen_addresses = NULL;
+daemon_listener_t *listen_addresses = NULL;
size_t listen_addresses_num = 0;
/*
static int
daemon_add_listener(oconfig_item_t *ci)
{
- char **tmp;
+ daemon_listener_t *listener;
char *address;
+ int i, ret = 0;
if (oconfig_get_string(ci, &address)) {
sdb_log(SDB_LOG_ERR, "config: Listen requires a single "
return ERR_INVALID_ARG;
}
- tmp = realloc(listen_addresses,
+ listener = realloc(listen_addresses,
(listen_addresses_num + 1) * sizeof(*listen_addresses));
- if (! tmp) {
+ if (! listener) {
char buf[1024];
sdb_log(SDB_LOG_ERR, "config: Failed to allocate memory: %s",
sdb_strerror(errno, buf, sizeof(buf)));
return -1;
}
- listen_addresses = tmp;
- listen_addresses[listen_addresses_num] = strdup(address);
- if (! listen_addresses[listen_addresses_num]) {
+ listen_addresses = listener;
+ listener = listen_addresses + listen_addresses_num;
+ memset(listener, 0, sizeof(*listener));
+ listener->address = strdup(address);
+ if (! listener->address) {
char buf[1024];
sdb_log(SDB_LOG_ERR, "config: Failed to allocate memory: %s",
sdb_strerror(errno, buf, sizeof(buf)));
return -1;
}
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *child = ci->children + i;
+ char *tmp = NULL;
+
+ if (! strcasecmp(child->key, "SSLCertificate")) {
+ if (oconfig_get_string(child, &tmp)) {
+ ret = ERR_INVALID_ARG;
+ break;
+ }
+ listener->ssl_opts.cert_file = strdup(tmp);
+ }
+ else if (! strcasecmp(child->key, "SSLCertificateKey")) {
+ if (oconfig_get_string(child, &tmp)) {
+ ret = ERR_INVALID_ARG;
+ break;
+ }
+ listener->ssl_opts.key_file = strdup(tmp);
+ }
+ else if (! strcasecmp(child->key, "SSLCACertificates")) {
+ if (oconfig_get_string(child, &tmp)) {
+ ret = ERR_INVALID_ARG;
+ break;
+ }
+ listener->ssl_opts.ca_file = strdup(tmp);
+ }
+ else {
+ sdb_log(SDB_LOG_WARNING, "config: Unknown option '%s' "
+ "inside 'Listen' -- see the documentation for "
+ "details.", child->key);
+ continue;
+ }
+ }
+
+ if (ret) {
+ sdb_ssl_free_options(&listener->ssl_opts);
+ return ret;
+ }
+
++listen_addresses_num;
return 0;
} /* daemon_add_listener */
return config_get_interval(ci, &default_interval);
} /* daemon_set_interval */
+static int
+daemon_set_plugindir(oconfig_item_t *ci)
+{
+ if (oconfig_get_string(ci, &plugin_dir)) {
+ sdb_log(SDB_LOG_ERR, "config: PluginDir requires a single "
+ "string argument\n"
+ "\tUsage: PluginDir DIR");
+ return ERR_INVALID_ARG;
+ }
+ plugin_dir = strdup(plugin_dir);
+ return 0;
+} /* daemon_set_plugindir */
+
static int
daemon_load_plugin(oconfig_item_t *ci)
{
}
/* returns a negative value on error */
- return sdb_plugin_load(name, NULL);
+ return sdb_plugin_load(plugin_dir, name, NULL);
} /* daemon_load_plugin */
static int
{
sdb_plugin_ctx_t ctx = SDB_PLUGIN_CTX_INIT;
- char plugin_name[1024];
+ char plugin_name[1024];
char *name;
int i;
}
}
- return sdb_plugin_load(plugin_name, &ctx);
+ return sdb_plugin_load(plugin_dir, plugin_name, &ctx);
} /* daemon_load_backend */
static int
daemon_configure_plugin(oconfig_item_t *ci)
{
+ char plugin_name[1024];
char *name;
assert(ci);
if (oconfig_get_string(ci, &name)) {
sdb_log(SDB_LOG_ERR, "config: %s requires a single "
"string argument\n"
- "\tUsage: LoadBackend BACKEND",
- ci->key);
+ "\tUsage: <%s NAME>...</%s>",
+ ci->key, ci->key, ci->key);
return ERR_INVALID_ARG;
}
- return sdb_plugin_configure(name, ci);
+ if (!strcasecmp(ci->key, "Backend"))
+ snprintf(plugin_name, sizeof(plugin_name), "Backend::%s", name);
+ else
+ strncpy(plugin_name, name, sizeof(plugin_name));
+ return sdb_plugin_configure(plugin_name, ci);
} /* daemon_configure_backend */
static token_parser_t token_parser_list[] = {
{ "Listen", daemon_add_listener },
{ "Interval", daemon_set_interval },
+ { "PluginDir", daemon_set_plugindir },
{ "LoadPlugin", daemon_load_plugin },
{ "LoadBackend", daemon_load_backend },
{ "Backend", daemon_configure_plugin },
* public API
*/
+void
+daemon_free_listen_addresses(void)
+{
+ size_t i;
+
+ if (! listen_addresses)
+ return;
+
+ for (i = 0; i < listen_addresses_num; ++i) {
+ free(listen_addresses[i].address);
+ sdb_ssl_free_options(&listen_addresses[i].ssl_opts);
+ }
+ free(listen_addresses);
+
+ listen_addresses = NULL;
+ listen_addresses_num = 0;
+} /* daemon_free_listen_addresses */
+
int
daemon_parse_config(const char *filename)
{
retval = status;
}
}
+
+ oconfig_free(ci);
+ free(ci);
+
+ if (plugin_dir) {
+ free(plugin_dir);
+ plugin_dir = NULL;
+ }
return retval;
} /* daemon_parse_config */