/* Password for the above.
/* .IP dbname
/* Name of the database.
+/* .IP "encoding (default: UTF8)
+/* Client encoding, Postfix 3.8 and later. Previously this was
+/* hard-coded as LATIN1.
/* .IP query
/* Query template. If not defined a default query template is constructed
/* from the legacy \fIselect_function\fR or failing that the \fItable\fR,
char *username;
char *password;
char *dbname;
+ char *encoding;
char *table;
ARGV *hosts;
PLPGSQL *pldb;
/* internal function declarations */
static PLPGSQL *plpgsql_init(ARGV *);
static PGSQL_RES *plpgsql_query(DICT_PGSQL *, const char *, VSTRING *, char *,
- char *, char *);
+ char *, char *, char *);
static void plpgsql_dealloc(PLPGSQL *);
static void plpgsql_close_host(HOST *);
static void plpgsql_down_host(HOST *);
-static void plpgsql_connect_single(HOST *, char *, char *, char *);
+static void plpgsql_connect_single(HOST *, char *, char *, char *, char *);
static const char *dict_pgsql_lookup(DICT *, const char *);
DICT *dict_pgsql_open(const char *, int, int);
static void dict_pgsql_close(DICT *);
/*
* Don't frustrate future attempts to make Postfix UTF-8 transparent.
*/
-#ifdef SNAPSHOT
if ((dict->flags & DICT_FLAG_UTF8_ACTIVE) == 0
&& !valid_utf8_string(name, strlen(name))) {
if (msg_verbose)
myname, dict_pgsql->parser->name, name);
return (0);
}
-#endif
/*
* Optionally fold the key.
/* do the query - set dict->error & cleanup if there's an error */
if ((query_res = plpgsql_query(dict_pgsql, name, query,
dict_pgsql->dbname,
+ dict_pgsql->encoding,
dict_pgsql->username,
dict_pgsql->password)) == 0) {
dict->error = DICT_ERR_RETRY;
/* dict_pgsql_get_active - get an active connection */
-static HOST *dict_pgsql_get_active(PLPGSQL *PLDB, char *dbname,
+static HOST *dict_pgsql_get_active(PLPGSQL *PLDB, char *dbname, char *encoding,
char *username, char *password)
{
const char *myname = "dict_pgsql_get_active";
if (msg_verbose)
msg_info("%s: attempting to connect to host %s", myname,
host->hostname);
- plpgsql_connect_single(host, dbname, username, password);
+ plpgsql_connect_single(host, dbname, encoding, username, password);
if (host->stat == STATACTIVE)
return host;
}
const char *name,
VSTRING *query,
char *dbname,
+ char *encoding,
char *username,
char *password)
{
PGSQL_RES *res = 0;
ExecStatusType status;
- while ((host = dict_pgsql_get_active(PLDB, dbname, username, password)) != NULL) {
+ while ((host = dict_pgsql_get_active(PLDB, dbname, encoding, username, password)) != NULL) {
/*
* The active host is used to escape strings in the context of the
* used to reconnect to a single database when one is down or none is
* connected yet. Log all errors and set the stat field of host accordingly
*/
-static void plpgsql_connect_single(HOST *host, char *dbname, char *username, char *password)
+static void plpgsql_connect_single(HOST *host, char *dbname, char *encoding, char *username, char *password)
{
if (host->type == TYPECONNSTRING) {
host->db = PQconnectdb(host->name);
plpgsql_down_host(host);
return;
}
- if (msg_verbose)
- msg_info("dict_pgsql: successful connection to host %s",
- host->hostname);
-
- /*
- * The only legitimate encodings for Internet mail are ASCII and UTF-8.
- */
-#ifdef SNAPSHOT
- if (PQsetClientEncoding(host->db, "UTF8") != 0) {
- msg_warn("dict_pgsql: cannot set the encoding to UTF8, skipping %s",
- host->hostname);
+ if (PQsetClientEncoding(host->db, encoding) != 0) {
+ msg_warn("dict_pgsql: cannot set the encoding to %s, skipping %s",
+ encoding, host->hostname);
plpgsql_down_host(host);
return;
}
-#else
-
- /*
- * XXX Postfix does not send multi-byte characters. The following piece
- * of code is an explicit statement of this fact, and the database server
- * should not accept multi-byte information after this point.
- */
- if (PQsetClientEncoding(host->db, "LATIN1") != 0) {
- msg_warn("dict_pgsql: cannot set the encoding to LATIN1, skipping %s",
+ if (msg_verbose)
+ msg_info("dict_pgsql: successful connection to host %s",
host->hostname);
- plpgsql_down_host(host);
- return;
- }
-#endif
/* Success. */
host->stat = STATACTIVE;
}
dict_pgsql->username = cfg_get_str(p, "user", "", 0, 0);
dict_pgsql->password = cfg_get_str(p, "password", "", 0, 0);
dict_pgsql->dbname = cfg_get_str(p, "dbname", "", 1, 0);
+ dict_pgsql->encoding = cfg_get_str(p, "encoding", "UTF8", 1, 0);
dict_pgsql->result_format = cfg_get_str(p, "result_format", "%s", 1, 0);
/*
myfree(dict_pgsql->username);
myfree(dict_pgsql->password);
myfree(dict_pgsql->dbname);
+ myfree(dict_pgsql->encoding);
myfree(dict_pgsql->query);
myfree(dict_pgsql->result_format);
if (dict_pgsql->hosts)