#include <sys_defs.h>
#include <string.h>
#include <stringops.h>
#include <split_at.h>
#include <mac_expand.h>
#include <dict.h>
#include <msg.h>
#include <mymalloc.h>
#include <mail_conf.h>
#include <mail_params.h>
#include <dict_proxy.h>
#include <dict_ldap.h>
#include <dict_mysql.h>
#include <dict_pgsql.h>
#include <dict_sqlite.h>
#include <dict_memcache.h>
#include <postconf.h>
#define STR(x) vstring_str(x)
#ifdef LEGACY_DBMS_SUPPORT
static const char *pcf_ldap_suffixes[] = {
"bind", "bind_dn", "bind_pw", "cache", "cache_expiry", "cache_size",
"chase_referrals", "debuglevel", "dereference", "domain",
"expansion_limit", "leaf_result_attribute", "query_filter",
"recursion_limit", "result_attribute", "result_format", "scope",
"search_base", "server_host", "server_port", "size_limit",
"special_result_attribute", "terminal_result_attribute",
"timeout", "version", 0,
};
static const char *pcf_mysql_suffixes[] = {
"additional_conditions", "dbname", "domain", "expansion_limit",
"hosts", "password", "query", "result_format", "require_result_set",
"select_field", "table", "user", "where_field", 0,
};
static const char *pcf_pgsql_suffixes[] = {
"additional_conditions", "dbname", "domain", "expansion_limit",
"hosts", "password", "query", "result_format", "select_field",
"select_function", "table", "user", "where_field", 0,
};
static const char *pcf_sqlite_suffixes[] = {
"additional_conditions", "dbpath", "domain", "expansion_limit",
"query", "result_format", "select_field", "table", "where_field",
0,
};
static const char *pcf_memcache_suffixes[] = {
"backup", "data_size_limit", "domain", "flags", "key_format",
"line_size_limit", "max_try", "memcache", "retry_pause",
"timeout", "ttl", 0,
};
typedef struct {
const char *db_type;
const char **db_suffixes;
} PCF_DBMS_INFO;
static const PCF_DBMS_INFO pcf_dbms_info[] = {
DICT_TYPE_LDAP, pcf_ldap_suffixes,
DICT_TYPE_MYSQL, pcf_mysql_suffixes,
DICT_TYPE_PGSQL, pcf_pgsql_suffixes,
DICT_TYPE_SQLITE, pcf_sqlite_suffixes,
DICT_TYPE_MEMCACHE, pcf_memcache_suffixes,
0,
};
static void pcf_register_dbms_helper(char *str_value,
const char *(flag_parameter) (const char *, int, PCF_MASTER_ENT *),
PCF_MASTER_ENT *local_scope)
{
const PCF_DBMS_INFO *dp;
char *db_type;
char *prefix;
static VSTRING *candidate = 0;
const char **cpp;
char *err;
while ((db_type = mystrtokq(&str_value, CHARS_COMMA_SP, CHARS_BRACE)) != 0) {
while ((prefix = split_at(db_type, ':')) != 0
&& strcmp(db_type, DICT_TYPE_PROXY) == 0)
db_type = prefix;
if (prefix != 0 && *prefix != '/' && *prefix != '.') {
if (*prefix == CHARS_BRACE[0]) {
if ((err = extpar(&prefix, CHARS_BRACE, EXTPAR_FLAG_NONE)) != 0) {
if (local_scope)
msg_warn("%s:%s: %s",
MASTER_CONF_FILE, local_scope->name_space,
err);
else
msg_warn("%s: %s", MAIN_CONF_FILE, err);
myfree(err);
}
pcf_register_dbms_helper(prefix, flag_parameter,
local_scope);
} else {
for (dp = pcf_dbms_info; dp->db_type != 0; dp++) {
if (strcmp(db_type, dp->db_type) == 0) {
for (cpp = dp->db_suffixes; *cpp; cpp++) {
vstring_sprintf(candidate ? candidate :
(candidate = vstring_alloc(30)),
"%s_%s", prefix, *cpp);
flag_parameter(STR(candidate),
PCF_PARAM_FLAG_DBMS | PCF_PARAM_FLAG_USER,
local_scope);
}
break;
}
}
}
}
}
}
void pcf_register_dbms_parameters(const char *param_value,
const char *(flag_parameter) (const char *, int, PCF_MASTER_ENT *),
PCF_MASTER_ENT *local_scope)
{
char *bufp;
static VSTRING *buffer = 0;
if (buffer == 0)
buffer = vstring_alloc(100);
bufp = pcf_expand_parameter_value(buffer, PCF_SHOW_EVAL, param_value,
local_scope);
pcf_register_dbms_helper(bufp, flag_parameter, local_scope);
}
#endif