diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-09-22 14:48:04 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-09-22 14:48:04 +0000 |
commit | 372eb6965b0c457f6ae3b58978bae8e9bc59da6c (patch) | |
tree | 1502177f0e2604c321a7cff762388354f5d7b67c /cdr | |
parent | 49a9ba3159c152c3e3131443f00fe65f3fbb19a6 (diff) |
Allow the encoding to be set, in case local charset does not agree with database.
(closes issue #16940)
Reported by: jamicque
Patches:
20100827__issue16940.diff.txt uploaded by tilghman (license 14)
20100921__issue16940__1.6.2.diff.txt uploaded by tilghman (license 14)
Tested by: jamicque
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@288265 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r-- | cdr/cdr_pgsql.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c index a2144a712..2e60d9c6a 100644 --- a/cdr/cdr_pgsql.c +++ b/cdr/cdr_pgsql.c @@ -61,7 +61,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static char *name = "pgsql"; static char *config = "cdr_pgsql.conf"; -static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL; +static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL, *encoding = NULL; static int connected = 0; AST_MUTEX_DEFINE_STATIC(pgsql_lock); @@ -85,6 +85,9 @@ static int pgsql_log(struct ast_cdr *cdr) conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword); if (PQstatus(conn) != CONNECTION_BAD) { connected = 1; + if (PQsetClientEncoding(conn, encoding)) { + ast_log(LOG_WARNING, "Failed to set encoding to '%s'. Encoding set to default '%s'\n", encoding, pg_encoding_to_char(PQclientEncoding(conn))); + } } else { pgerror = PQerrorMessage(conn); ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. Calls will not be logged!\n", pghostname); @@ -205,6 +208,9 @@ static int my_unload_module(void) free(pgdbport); if (table) free(table); + if (encoding) { + free(encoding); + } ast_cdr_unregister(name); return 0; } @@ -266,8 +272,16 @@ static int process_my_load_module(struct ast_config *cfg) if (!(table = ast_strdup(tmp))) return -1; + if (!(tmp = ast_variable_retrieve(cfg, "global", "encoding"))) { + tmp = "LATIN9"; + } + + if (!(encoding = ast_strdup(tmp))) { + return -1; + } + if (option_debug) { - if (ast_strlen_zero(pghostname)) + if (ast_strlen_zero(pghostname)) ast_log(LOG_DEBUG, "cdr_pgsql: using default unix socket\n"); else ast_log(LOG_DEBUG, "cdr_pgsql: got hostname of %s\n", pghostname); @@ -277,14 +291,17 @@ static int process_my_load_module(struct ast_config *cfg) ast_log(LOG_DEBUG, "cdr_pgsql: got password of %s\n", pgpassword); ast_log(LOG_DEBUG, "cdr_pgsql: got sql table name of %s\n", table); } - + conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword); if (PQstatus(conn) != CONNECTION_BAD) { if (option_debug) ast_log(LOG_DEBUG, "Successfully connected to PostgreSQL database.\n"); connected = 1; + if (PQsetClientEncoding(conn, encoding)) { + ast_log(LOG_WARNING, "Failed to set encoding to '%s'. Encoding set to default '%s'\n", encoding, pg_encoding_to_char(PQclientEncoding(conn))); + } } else { - pgerror = PQerrorMessage(conn); + pgerror = PQerrorMessage(conn); ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. CALLS WILL NOT BE LOGGED!!\n", pghostname); ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror); connected = 0; |