Index: cdr/cdr_pgsql.c =================================================================== --- cdr/cdr_pgsql.c (revision 283769) +++ cdr/cdr_pgsql.c (working copy) @@ -61,7 +61,7 @@ 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 @@ 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 @@ free(pgdbport); if (table) free(table); + if (encoding) { + free(encoding); + } ast_cdr_unregister(name); return 0; } @@ -266,8 +272,17 @@ if (!(table = ast_strdup(tmp))) return -1; + if (!(tmp = ast_variable_retrieve(cfg, "global", "encoding"))) { + ast_log(LOG_WARNING, "Encoding not specified. Assuming LATIN9\n"); + 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 +292,17 @@ 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; Index: configs/cdr_pgsql.conf.sample =================================================================== --- configs/cdr_pgsql.conf.sample (revision 283769) +++ configs/cdr_pgsql.conf.sample (working copy) @@ -7,3 +7,4 @@ ;password=password ;user=postgres ;table=cdr ;SQL table where CDRs will be inserted +;encoding=LATIN9 ; Encoding of logged characters in Asterisk (this is unlikely to be UTF8).