From 70ac93378fd01f8229364705c69d75ebd8bd9c07 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Fri, 1 Sep 2017 16:29:46 +0300 Subject: [PATCH] odissey: configure and send timezone to a client --- odissey.conf | 8 ++++++-- scripts/debian/config | 8 ++++++-- sources/config.c | 10 ++++++++++ sources/frontend.c | 36 ++++++++++++++++++++++++------------ sources/scheme.c | 35 +++++++++++++++++------------------ sources/scheme.h | 2 ++ 6 files changed, 65 insertions(+), 34 deletions(-) diff --git a/odissey.conf b/odissey.conf index 74965c59..e2eab291 100644 --- a/odissey.conf +++ b/odissey.conf @@ -54,6 +54,9 @@ database "console" { authentication "none" pool "session" storage "local" + client_encoding "UTF8" + datestyle "ISO" + timezone "UTC" } } @@ -78,7 +81,8 @@ database default pool_rollback yes #client_max 100 - #client_encoding "UTF-8" - #datestyle "ISO" + client_encoding "UTF8" + datestyle "ISO" + timezone "UTC" } } diff --git a/scripts/debian/config b/scripts/debian/config index 98a65e80..dbefaf1f 100644 --- a/scripts/debian/config +++ b/scripts/debian/config @@ -54,6 +54,9 @@ database "console" { authentication "none" pool "session" storage "local" + client_encoding "UTF8" + datestyle "ISO" + timezone "UTC" } } @@ -78,7 +81,8 @@ database default pool_rollback yes #client_max 100 - #client_encoding "UTF-8" - #datestyle "ISO" + client_encoding "UTF8" + datestyle "ISO" + timezone "UTC" } } diff --git a/sources/config.c b/sources/config.c index af319241..3a107ee6 100644 --- a/sources/config.c +++ b/sources/config.c @@ -66,6 +66,7 @@ enum OD_LCLIENT_MAX, OD_LCLIENT_ENCODING, OD_LDATESTYLE, + OD_LTIMEZONE, OD_LTLS, OD_LTLS_CA_FILE, OD_LTLS_KEY_FILE, @@ -133,6 +134,7 @@ static od_keyword_t od_config_keywords[] = od_keyword("client_max", OD_LCLIENT_MAX), od_keyword("client_encoding", OD_LCLIENT_ENCODING), od_keyword("datestyle", OD_LDATESTYLE), + od_keyword("timezone", OD_LTIMEZONE), od_keyword("tls", OD_LTLS), od_keyword("tls_ca_file", OD_LTLS_CA_FILE), od_keyword("tls_key_file", OD_LTLS_KEY_FILE), @@ -625,11 +627,19 @@ od_config_parse_route(od_config_t *config, char *db_name, int db_name_len, case OD_LCLIENT_ENCODING: if (! od_config_next_string(config, &route->client_encoding)) return -1; + route->client_encoding_len = strlen(route->client_encoding); continue; /* datestyle */ case OD_LDATESTYLE: if (! od_config_next_string(config, &route->datestyle)) return -1; + route->datestyle_len = strlen(route->datestyle); + continue; + /* timezone */ + case OD_LTIMEZONE: + if (! od_config_next_string(config, &route->timezone)) + return -1; + route->timezone_len = strlen(route->timezone); continue; /* pool */ case OD_LPOOL: diff --git a/sources/frontend.c b/sources/frontend.c index a353230a..9eef0f84 100644 --- a/sources/frontend.c +++ b/sources/frontend.c @@ -203,18 +203,30 @@ od_frontend_setup(od_client_t *client) client->key.key); if (rc == -1) return -1; - /* set default client_encoding */ - rc = shapito_be_write_parameter_status(stream, "client_encoding", 16, - client->scheme->client_encoding, - client->scheme->client_encoding_len + 1); - if (rc == -1) - return -1; - /* set default datestyle */ - rc = shapito_be_write_parameter_status(stream, "datestyle", 10, - client->scheme->datestyle, - client->scheme->datestyle_len + 1); - if (rc == -1) - return -1; + /* client_encoding */ + if (client->scheme->client_encoding) { + rc = shapito_be_write_parameter_status(stream, "client_encoding", 16, + client->scheme->client_encoding, + client->scheme->client_encoding_len + 1); + if (rc == -1) + return -1; + } + /* datestyle */ + if (client->scheme->datestyle) { + rc = shapito_be_write_parameter_status(stream, "datestyle", 10, + client->scheme->datestyle, + client->scheme->datestyle_len + 1); + if (rc == -1) + return -1; + } + /* timezone */ + if (client->scheme->timezone) { + rc = shapito_be_write_parameter_status(stream, "timezone", 9, + client->scheme->timezone, + client->scheme->timezone_len + 1); + if (rc == -1) + return -1; + } rc = od_write(client->io, stream); if (rc == -1) { od_error_client(&instance->logger, &client->id, "setup", diff --git a/sources/scheme.c b/sources/scheme.c index 3f4fb48e..7c42e684 100644 --- a/sources/scheme.c +++ b/sources/scheme.c @@ -336,6 +336,8 @@ void od_schemeroute_free(od_schemeroute_t *route) free(route->client_encoding); if (route->datestyle) free(route->datestyle); + if (route->timezone) + free(route->timezone); if (route->storage) od_schemestorage_free(route->storage); if (route->storage_name) @@ -484,6 +486,15 @@ int od_schemeroute_compare(od_schemeroute_t *a, od_schemeroute_t *b) return 0; } + /* timezone */ + if (a->timezone && b->timezone) { + if (strcmp(a->timezone, b->timezone) != 0) + return 0; + } else + if (a->timezone || b->timezone) { + return 0; + } + /* storage */ if (strcmp(a->storage_name, b->storage_name) != 0) return 0; @@ -742,22 +753,6 @@ int od_scheme_validate(od_scheme_t *scheme, od_logger_t *logger) route->db_name, route->user_name); return -1; } - - /* client_encoding */ - if (route->client_encoding == NULL) { - route->client_encoding = strdup("UTF-8"); - if (route->client_encoding == NULL) - return -1; - route->client_encoding_len = strlen(route->client_encoding); - } - - /* datestyle */ - if (route->datestyle == NULL) { - route->datestyle = strdup("ISO"); - if (route->datestyle == NULL) - return -1; - route->datestyle_len = strlen(route->datestyle); - } } if (! route_default_default) { @@ -863,8 +858,12 @@ log_routes:; route->pool_discard ? "yes" : "no"); if (route->client_max_set) od_log(logger, " client_max %d", route->client_max); - od_log(logger, " client_encoding %s", route->client_encoding); - od_log(logger, " datestyle %s", route->datestyle); + if (route->client_encoding) + od_log(logger, " client_encoding %s", route->client_encoding); + if (route->datestyle) + od_log(logger, " datestyle %s", route->datestyle); + if (route->timezone) + od_log(logger, " timezone %s", route->timezone); od_log(logger, " storage %s", route->storage_name); od_log(logger, " type %s", route->storage->type); if (route->storage->host) diff --git a/sources/scheme.h b/sources/scheme.h index 9d2de50e..417bf8fc 100644 --- a/sources/scheme.h +++ b/sources/scheme.h @@ -95,6 +95,8 @@ struct od_schemeroute int client_encoding_len; char *datestyle; int datestyle_len; + char *timezone; + int timezone_len; /* pool */ od_pooling_t pool; char *pool_sz;