2012-11-28 [colin] 3.9.0cvs27
authorColin Leroy <colin@colino.net>
Wed, 28 Nov 2012 11:01:24 +0000 (11:01 +0000)
committerColin Leroy <colin@colino.net>
Wed, 28 Nov 2012 11:01:24 +0000 (11:01 +0000)
* src/imap.c
* src/news.c
* src/common/session.c
* src/common/session.h
Add keep-alive pings on IMAP and NNTP

ChangeLog
PATCHSETS
configure.ac
src/common/session.c
src/common/session.h
src/imap.c
src/news.c

index 9627ed9e10c544f3a72b1eed558365a765c7a845..45594cb51f74cb18916fa49bb9224f7b82826970 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-11-28 [colin]     3.9.0cvs27
+
+       * src/imap.c
+       * src/news.c
+       * src/common/session.c
+       * src/common/session.h
+               Add keep-alive pings on IMAP and NNTP
+
 2012-11-28 [colin]     3.9.0cvs26
 
        * src/imap.c
index 0272b0442895af083ea50efd1e6a003c910cb729..140d301e85fd4d26e0de0c68bb2b035e434a1978 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.9.2.58 -r 1.9.2.59 src/common/ssl.c;  ) > 3.9.0cvs24.patchset
 ( cvs diff -u -r 1.115.2.264 -r 1.115.2.265 src/main.c;  ) > 3.9.0cvs25.patchset
 ( cvs diff -u -r 1.179.2.268 -r 1.179.2.269 src/imap.c;  cvs diff -u -r 1.1.4.126 -r 1.1.4.127 src/etpan/imap-thread.c;  cvs diff -u -r 1.1.4.30 -r 1.1.4.31 src/etpan/imap-thread.h;  ) > 3.9.0cvs26.patchset
+( cvs diff -u -r 1.179.2.269 -r 1.179.2.270 src/imap.c;  cvs diff -u -r 1.101.2.73 -r 1.101.2.74 src/news.c;  cvs diff -u -r 1.23.2.28 -r 1.23.2.29 src/common/session.c;  cvs diff -u -r 1.8.2.21 -r 1.8.2.22 src/common/session.h;  ) > 3.9.0cvs27.patchset
index 389ca02d749cff31983fb98525e57decdb715d23..bf8822e7abcc8091cc5c7c9c2cd9fdf9bf9c81ee 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=9
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=26
+EXTRA_VERSION=27
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index d38a574448d72b7b0af86b02270f0a91cf990932..6e1e2b9d83bf981df84606fbb0265741c5d99825 100644 (file)
@@ -100,6 +100,8 @@ void session_init(Session *session, const void *prefs_account, gboolean is_smtp)
        session->data = NULL;
        session->account = prefs_account;
        session->is_smtp = is_smtp;
+
+       session->ping_tag = -1;
 }
 
 /*!
@@ -215,6 +217,8 @@ void session_destroy(Session *session)
        cm_return_if_fail(session != NULL);
        cm_return_if_fail(session->destroy != NULL);
 
+       session_register_ping(session, NULL);
+
        session_close(session);
        session->destroy(session);
        g_free(session->server);
@@ -867,3 +871,22 @@ static gboolean session_write_data_cb(SockInfo *source,
 
        return FALSE;
 }
+
+void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data))
+{
+       if (!session)
+               return;
+       if (session->ping_tag > -1)
+               g_source_remove(session->ping_tag);
+
+       session->ping_tag = -1;
+
+       if (ping_cb != NULL)
+#if GLIB_CHECK_VERSION(2,14,0)
+               session->ping_tag =
+                       g_timeout_add_seconds(60, ping_cb, session);
+#else
+               session->ping_tag =
+                       g_timeout_add(60*1000, ping_cb, session);
+#endif
+}
index 8244711615a43b6612a501262d3f774b2eb077f4..6ed2d24cdf2f875af3f1fb78743b40af2b5e8702 100644 (file)
@@ -154,6 +154,8 @@ struct _Session
        const void *account;
        gboolean is_smtp;
 
+       gint ping_tag;
+
 #ifdef USE_GNUTLS
        SSLType ssl_type;
 #endif
@@ -207,5 +209,6 @@ gint session_send_data      (Session        *session,
 gint session_recv_data (Session        *session,
                         guint           size,
                         const gchar    *terminator);
+void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data));
 
 #endif /* __SESSION_H__ */
index ba6de0abc13b648490392b6adc288a8f157bb9a0..a7fdb0a921a81859a70d403d5af363f15bcbf22f 100644 (file)
@@ -544,6 +544,24 @@ static void unlock_session(IMAPSession *session)
        }
 }
 
+static gboolean imap_ping(gpointer data)
+{
+       Session *session = (Session *)data;
+       IMAPSession *imap_session = IMAP_SESSION(session);
+       int r;
+
+       if (session->state != SESSION_READY)
+               return FALSE;
+       if (imap_session->busy || !imap_session->authenticated)
+               return TRUE;
+       
+       lock_session(imap_session);
+       r = imap_cmd_noop(imap_session);
+       unlock_session(imap_session);
+
+       return r == MAILIMAP_NO_ERROR;
+}
+
 static void imap_disc_session_destroy(IMAPSession *session)
 {
        RemoteFolder *rfolder = NULL;
@@ -752,7 +770,7 @@ static void imap_folder_init(Folder *folder, const gchar *name,
        folder_remote_folder_init((Folder *)folder, name, path);
        IMAP_FOLDER(folder)->max_set_size = IMAP_SET_MAX_COUNT;
        IMAP_FOLDER(folder)->search_charset_supported = TRUE;
-       IMAP_FOLDER(folder)->search_charset = "UTF-8";
+       IMAP_FOLDER(folder)->search_charset = conv_get_locale_charset_str_no_utf8();
 }
 
 static FolderItem *imap_folder_item_new(Folder *folder)
@@ -1183,6 +1201,8 @@ static IMAPSession *imap_session_new(Folder * folder,
        log_message(LOG_PROTOCOL, "IMAP connection is %s-authenticated\n",
                    (session->authenticated) ? "pre" : "un");
        
+       session_register_ping(SESSION(session), imap_ping);
+
        return session;
 }
 
@@ -2177,9 +2197,9 @@ static void imap_change_search_charset(IMAPFolder *folder)
         */
 
        if (folder->search_charset_supported) {
-               if (folder->search_charset && !strcmp(folder->search_charset, "UTF-8"))
-                       folder->search_charset = conv_get_locale_charset_str_no_utf8();
-               else if (folder->search_charset && !strcmp(folder->search_charset, conv_get_locale_charset_str_no_utf8()))
+               if (folder->search_charset && !strcmp(folder->search_charset, conv_get_locale_charset_str_no_utf8()))
+                       folder->search_charset = "UTF-8";
+               else if (folder->search_charset && !strcmp(folder->search_charset, "UTF-8"))
                        folder->search_charset = "UTF-7";
                else {
                        folder->search_charset = NULL;
@@ -3992,8 +4012,6 @@ static gint imap_cmd_noop(IMAPSession *session)
                return r;
        }
 
-       session->folder_content_changed = FALSE;
-
        if ((exists && exists != session->exists)
         || (recent && recent != session->recent)
         || (expunge && expunge != session->expunge)
index 541803d1fb94316c0e464eebd782dd2028c2beca..1f0ddc2ed9f9739286a25fff68bf078b72709dc1 100644 (file)
@@ -83,7 +83,7 @@ struct _NewsFolder
 struct _NewsSession
 {
        Session session;
-
+       Folder *folder;
        gchar *group;
 };
 
@@ -282,6 +282,34 @@ static void news_session_destroy(Session *session)
                g_free(news_session->group);
 }
 
+static gboolean nntp_ping(gpointer data)
+{
+       Session *session = (Session *)data;
+       NewsSession *news_session = NEWS_SESSION(session);
+       int r;
+       struct tm lt;
+
+       if (session->state != SESSION_READY || news_folder_locked(news_session->folder))
+               return FALSE;
+       
+       if ((r = nntp_threaded_date(news_session->folder, &lt)) != NEWSNNTP_NO_ERROR) {
+               if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED &&
+                   r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) {
+                       log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been"
+                             " disconnected.\n"),
+                           news_session->folder->account->nntp_server,
+                           news_session->folder->account->set_nntpport ?
+                           news_session->folder->account->nntpport : NNTP_PORT);
+                       REMOTE_FOLDER(news_session->folder)->session = NULL;
+                       session_destroy(session);
+                       return FALSE;
+               }
+       }
+       session_set_access_time(session);
+       return TRUE;
+}
+
+
 #ifdef USE_GNUTLS
 static Session *news_session_new(Folder *folder, const gchar *server, gushort port,
                                 const gchar *userid, const gchar *passwd,
@@ -320,7 +348,10 @@ static Session *news_session_new(Folder *folder, const gchar *server, gushort po
                session_destroy(SESSION(session));
                return NULL;
        }
-       
+
+       session->folder = folder;
+
+       session_register_ping(SESSION(session), nntp_ping);
        return SESSION(session);
 }
 
@@ -437,8 +468,6 @@ static Session *news_session_new_for_folder(Folder *folder)
 static NewsSession *news_session_get(Folder *folder)
 {
        RemoteFolder *rfolder = REMOTE_FOLDER(folder);
-       struct tm lt;
-       int r;
        
        cm_return_val_if_fail(folder != NULL, NULL);
        cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
@@ -469,18 +498,8 @@ static NewsSession *news_session_get(Folder *folder)
                return NEWS_SESSION(rfolder->session);
        }
 
-       if ((r = nntp_threaded_date(folder, &lt)) != NEWSNNTP_NO_ERROR) {
-               if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED &&
-                   r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) {
-                       log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been"
-                             " disconnected. Reconnecting...\n"),
-                           folder->account->nntp_server,
-                           folder->account->set_nntpport ?
-                           folder->account->nntpport : NNTP_PORT);
-                       session_destroy(rfolder->session);
-                       rfolder->session = news_session_new_for_folder(folder);
-               }
-       }
+       if (!nntp_ping(rfolder->session))
+               rfolder->session = news_session_new_for_folder(folder);
 
 newsession:
        if (rfolder->session)