#include <sys_defs.h>
#include <string.h>
#include <stringops.h>
#include <split_at.h>
#include <mac_expand.h>
#include <dict.h>
#include <mail_conf.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 *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 *mysql_suffixes[] = {
"additional_conditions", "dbname", "domain", "expansion_limit",
"hosts", "password", "query", "result_format", "select_field",
"table", "user", "where_field", 0,
};
static const char *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 *sqlite_suffixes[] = {
"additional_conditions", "dbpath", "domain", "expansion_limit",
"query", "result_format", "select_field", "table", "where_field",
0,
};
static const char *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;
} PC_DBMS_INFO;
static const PC_DBMS_INFO dbms_info[] = {
DICT_TYPE_LDAP, ldap_suffixes,
DICT_TYPE_MYSQL, mysql_suffixes,
DICT_TYPE_PGSQL, pgsql_suffixes,
DICT_TYPE_SQLITE, sqlite_suffixes,
DICT_TYPE_MEMCACHE, memcache_suffixes,
0,
};
static const char *register_dbms_parameters_cb(const char *mac_name,
int unused_mode,
char *context)
{
PC_MASTER_ENT *local_scope = (PC_MASTER_ENT *) context;
const char *mac_val;
if (local_scope == 0
|| (mac_val = dict_get(local_scope->all_params, mac_name)) == 0)
mac_val = mail_conf_lookup(mac_name);
return (mac_val);
}
void register_dbms_parameters(const char *param_value,
const char *(flag_parameter) (const char *, int, char *),
PC_MASTER_ENT *local_scope)
{
const PC_DBMS_INFO *dp;
char *bufp;
char *db_type;
char *prefix;
static VSTRING *buffer = 0;
static VSTRING *candidate = 0;
const char **cpp;
#define NO_SCAN_FILTER ((char *) 0)
(void) mac_expand(buffer ? buffer : (buffer = vstring_alloc(100)),
param_value, MAC_EXP_FLAG_RECURSE, NO_SCAN_FILTER,
register_dbms_parameters_cb, (char *) local_scope);
bufp = STR(buffer);
while ((db_type = mystrtok(&bufp, " ,\t\r\n")) != 0) {
while ((prefix = split_at(db_type, ':')) != 0
&& strcmp(db_type, DICT_TYPE_PROXY) == 0)
db_type = prefix;
if (prefix != 0 && *prefix != '/' && *prefix != '.') {
for (dp = 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), 0, (char *) local_scope);
}
break;
}
}
}
}
}
#endif