]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: add callback to notify consumers about state changes
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 15 Feb 2017 14:12:35 +0000 (09:12 -0500)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 09:32:32 +0000 (11:32 +0200)
Add a callback to notify imapc users about failures.  Currently, the only
failure defined is "authentication failed".

src/lib-imap-client/imapc-client-private.h
src/lib-imap-client/imapc-client.c
src/lib-imap-client/imapc-client.h
src/lib-imap-client/imapc-connection.c

index 12780e07886d619cdac0cb47393d3f5fbcd81740..3d8f347e4e7185500b33369a3e3425660dac4851 100644 (file)
@@ -20,6 +20,9 @@ struct imapc_client {
        imapc_untagged_callback_t *untagged_callback;
        void *untagged_context;
 
+       imapc_state_change_callback_t *state_change_callback;
+       void *state_change_context;
+
        ARRAY(struct imapc_client_connection *) conns;
 
        struct ioloop *ioloop;
index 365341f59641d0611d3e8109c64f5d85d31b2b46..b4d7de73eab8383ae3ab676630bc4c0451657783 100644 (file)
@@ -468,3 +468,14 @@ int imapc_client_create_temp_fd(struct imapc_client *client,
        *path_r = str_c(path);
        return fd;
 }
+
+void imapc_client_register_state_change_callback(struct imapc_client *client,
+                                                imapc_state_change_callback_t *cb,
+                                                void *context)
+{
+       i_assert(client->state_change_callback == NULL);
+       i_assert(client->state_change_context == NULL);
+
+       client->state_change_callback = cb;
+       client->state_change_context = context;
+}
index 69583302ef94782fb44c7bca9d900f147ccf458a..0a0ecda94b593a76e70d13a598e68e7bb6043eed 100644 (file)
@@ -146,12 +146,19 @@ struct imapc_untagged_reply {
        void *untagged_box_context;
 };
 
+enum imapc_state_change_event {
+       IMAPC_STATE_CHANGE_AUTH_FAILED,
+};
+
 /* Called when tagged reply is received for command. */
 typedef void imapc_command_callback_t(const struct imapc_command_reply *reply,
                                      void *context);
 /* Called each time untagged input is received. */
 typedef void imapc_untagged_callback_t(const struct imapc_untagged_reply *reply,
                                       void *context);
+typedef void imapc_state_change_callback_t(void *context,
+                                          enum imapc_state_change_event event,
+                                          const char *error);
 
 struct imapc_client *
 imapc_client_init(const struct imapc_client_settings *set);
@@ -208,4 +215,8 @@ imapc_client_get_capabilities(struct imapc_client *client);
 int imapc_client_create_temp_fd(struct imapc_client *client,
                                const char **path_r);
 
+void imapc_client_register_state_change_callback(struct imapc_client *client,
+                                                imapc_state_change_callback_t *cb,
+                                                void *context);
+
 #endif
index 67486566fb23801e8dd2bdcd5222a4a4d190a723..8287f2aeee4ae10c9a2478188efb886f801e83bf 100644 (file)
@@ -146,6 +146,13 @@ imapc_auth_failed(struct imapc_connection *conn,
                  const char *error)
 {
        i_error("imapc(%s): Authentication failed: %s", conn->name, error);
+
+       if (conn->client->state_change_callback == NULL)
+               return;
+
+       conn->client->state_change_callback(conn->client->state_change_context,
+                                           IMAPC_STATE_CHANGE_AUTH_FAILED,
+                                           error);
 }
 
 struct imapc_connection *