dovecot-2.2: push-notification: Added timeout_msecs and max_retr...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 2 09:12:32 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5a64d5ea81e2
changeset: 19274:5a64d5ea81e2
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 02 12:09:30 2015 +0300
description:
push-notification: Added timeout_msecs and max_retries parameters to OX driver.
For configuring HTTP lookups.

diffstat:

 src/plugins/push-notification/push-notification-driver-ox.c |  30 ++++++++++--
 1 files changed, 25 insertions(+), 5 deletions(-)

diffs (76 lines):

diff -r 5e667cce0842 -r 5a64d5ea81e2 src/plugins/push-notification/push-notification-driver-ox.c
--- a/src/plugins/push-notification/push-notification-driver-ox.c	Fri Oct 02 11:46:30 2015 +0300
+++ b/src/plugins/push-notification/push-notification-driver-ox.c	Fri Oct 02 12:09:30 2015 +0300
@@ -26,7 +26,8 @@
 static const char *const default_events[] = { "MessageNew", NULL };
 static const char *const default_mboxes[] = { "INBOX", NULL };
 #define DEFAULT_CACHE_LIFETIME 60
-
+#define DEFAULT_TIMEOUT_MSECS 2000
+#define DEFAULT_RETRY_COUNT 1
 
 /* This is data that is shared by all plugin users. */
 struct push_notification_driver_ox_global {
@@ -38,10 +39,13 @@
 /* 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;
+    bool use_unsafe_username;
+    unsigned int http_max_retries;
+    unsigned int http_timeout_msecs;
+
     char *cached_ox_metadata;
-    unsigned int cached_ox_metadata_lifetime;
     time_t cached_ox_metadata_timestamp;
-    bool use_unsafe_username;
 };
 
 /* This is data specific to an OX driver transaction. */
@@ -50,13 +54,18 @@
 };
 
 static void
-push_notification_driver_ox_init_global(struct mail_user *user)
+push_notification_driver_ox_init_global(struct mail_user *user,
+	struct push_notification_driver_ox_config *config)
 {
     struct http_client_settings http_set;
 
     if (ox_global->http_client == NULL) {
+        /* this is going to use the first user's settings, but these are
+           unlikely to change between users so it shouldn't matter much. */
         memset(&http_set, 0, sizeof(http_set));
         http_set.debug = user->mail_debug;
+        http_set.max_attempts = config->http_max_retries+1;
+        http_set.request_timeout_msecs = config->http_timeout_msecs;
 
         ox_global->http_client = http_client_init(&http_set);
     }
@@ -96,6 +105,17 @@
         dconfig->cached_ox_metadata_lifetime = DEFAULT_CACHE_LIFETIME;
     }
 
+    tmp = hash_table_lookup(config->config, (const char *)"max_retries");
+    if ((tmp == NULL) ||
+        (str_to_uint(tmp, &dconfig->http_max_retries) < 0)) {
+        dconfig->http_max_retries = DEFAULT_RETRY_COUNT;
+    }
+    tmp = hash_table_lookup(config->config, (const char *)"timeout_msecs");
+    if ((tmp == NULL) ||
+        (str_to_uint(tmp, &dconfig->http_timeout_msecs) < 0)) {
+        dconfig->http_timeout_msecs = DEFAULT_TIMEOUT_MSECS;
+    }
+
     push_notification_driver_debug(OX_LOG_LABEL, user,
                                    "Using cache lifetime: %u",
                                    dconfig->cached_ox_metadata_lifetime);
@@ -309,7 +329,7 @@
         return;
     }
 
-    push_notification_driver_ox_init_global(user);
+    push_notification_driver_ox_init_global(user, dconfig);
 
     http_req = http_client_request_url(ox_global->http_client, "PUT",
                                        dconfig->http_url,


More information about the dovecot-cvs mailing list