From: Timo Sirainen Date: Fri, 2 Oct 2015 09:23:22 +0000 (+0300) Subject: push-notification: Use setting_get_time() parsing for cache_lifetime OX driver setting. X-Git-Tag: 2.2.19~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=630c1df5b6aaec452b0ef040df56cffd978fe9c3;p=thirdparty%2Fdovecot%2Fcore.git push-notification: Use setting_get_time() parsing for cache_lifetime OX driver setting. --- diff --git a/src/plugins/push-notification/Makefile.am b/src/plugins/push-notification/Makefile.am index dfeb5770bb..f24a1c55a1 100644 --- a/src/plugins/push-notification/Makefile.am +++ b/src/plugins/push-notification/Makefile.am @@ -1,5 +1,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-http \ -I$(top_srcdir)/src/lib-index \ -I$(top_srcdir)/src/lib-mail \ diff --git a/src/plugins/push-notification/push-notification-driver-ox.c b/src/plugins/push-notification/push-notification-driver-ox.c index 453b323467..fb5be307c5 100644 --- a/src/plugins/push-notification/push-notification-driver-ox.c +++ b/src/plugins/push-notification/push-notification-driver-ox.c @@ -6,6 +6,7 @@ #include "http-url.h" #include "ioloop.h" #include "istream.h" +#include "settings-parser.h" #include "json-parser.h" #include "mailbox-attribute.h" #include "mail-storage-private.h" @@ -25,7 +26,7 @@ /* Default values. */ static const char *const default_events[] = { "MessageNew", NULL }; static const char *const default_mboxes[] = { "INBOX", NULL }; -#define DEFAULT_CACHE_LIFETIME 60 +#define DEFAULT_CACHE_LIFETIME_SECS 60 #define DEFAULT_TIMEOUT_MSECS 2000 #define DEFAULT_RETRY_COUNT 1 @@ -39,7 +40,7 @@ static struct push_notification_driver_ox_global *ox_global = NULL; /* This is data specific to an OX driver. */ struct push_notification_driver_ox_config { struct http_url *http_url; - unsigned int cached_ox_metadata_lifetime; + unsigned int cached_ox_metadata_lifetime_secs; bool use_unsafe_username; unsigned int http_max_retries; unsigned int http_timeout_msecs; @@ -100,9 +101,12 @@ push_notification_driver_ox_init(struct push_notification_driver_config *config, push_notification_driver_debug(OX_LOG_LABEL, user, "Using URL %s", tmp); tmp = hash_table_lookup(config->config, (const char *)"cache_lifetime"); - if ((tmp == NULL) || - (str_to_uint(tmp, &dconfig->cached_ox_metadata_lifetime) < 0)) { - dconfig->cached_ox_metadata_lifetime = DEFAULT_CACHE_LIFETIME; + if (tmp == NULL) + dconfig->cached_ox_metadata_lifetime_secs = DEFAULT_CACHE_LIFETIME_SECS; + else if (settings_get_time(tmp, &dconfig->cached_ox_metadata_lifetime_secs, &error) < 0) { + *error_r = t_strdup_printf(OX_LOG_LABEL "Failed to parse OX cache_lifetime %s: %s", + tmp, error); + return -1; } tmp = hash_table_lookup(config->config, (const char *)"max_retries"); @@ -118,7 +122,7 @@ push_notification_driver_ox_init(struct push_notification_driver_config *config, push_notification_driver_debug(OX_LOG_LABEL, user, "Using cache lifetime: %u", - dconfig->cached_ox_metadata_lifetime); + dconfig->cached_ox_metadata_lifetime_secs); if (ox_global == NULL) { ox_global = i_new(struct push_notification_driver_ox_global, 1); @@ -143,7 +147,8 @@ static const char *push_notification_driver_ox_get_metadata int ret; if ((dconfig->cached_ox_metadata != NULL) && - ((dconfig->cached_ox_metadata_timestamp + (time_t)dconfig->cached_ox_metadata_lifetime) > ioloop_time)) { + ((dconfig->cached_ox_metadata_timestamp + + (time_t)dconfig->cached_ox_metadata_lifetime_secs) > ioloop_time)) { return dconfig->cached_ox_metadata; }