2008-10-02 [colin] 3.5.0cvs144
[claws.git] / src / common / session.c
index 35dd6bfe3d3e6f6c3f1fab9a82b01a5c79eb23c3..cae294a84666f93f2d69146f3bb8e25794dc9af6 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -60,13 +60,13 @@ static gboolean session_write_data_cb       (SockInfo       *source,
                                         gpointer        data);
 
 
-void session_init(Session *session)
+void session_init(Session *session, const void *prefs_account, gboolean is_smtp)
 {
        session->type = SESSION_UNKNOWN;
        session->sock = NULL;
        session->server = NULL;
        session->port = 0;
-#if USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
        session->ssl_type = SSL_NONE;
 #endif
        session->nonblocking = TRUE;
@@ -97,6 +97,8 @@ void session_init(Session *session)
        session->timeout_interval = 0;
 
        session->data = NULL;
+       session->account = prefs_account;
+       session->is_smtp = is_smtp;
 }
 
 /*!
@@ -139,6 +141,7 @@ gint session_connect(Session *session, const gchar *server, gushort port)
                session_close(session);
                return -1;
        }
+       sock->is_smtp = session->is_smtp;
 
        return session_connect_cb(sock, session);
 #endif
@@ -157,13 +160,14 @@ static gint session_connect_cb(SockInfo *sock, gpointer data)
        }
 
        session->sock = sock;
-
-#if USE_OPENSSL
+       sock->account = session->account;
+       sock->is_smtp = session->is_smtp;
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
        if (session->ssl_type == SSL_TUNNEL) {
                sock_set_nonblocking_mode(sock, FALSE);
                if (!ssl_init_socket(sock)) {
                        g_warning("can't initialize SSL.");
-                       log_error(_("SSL handshake failed\n"));
+                       log_error(LOG_PROTOCOL, _("SSL handshake failed\n"));
                        session->state = SESSION_ERROR;
                        return -1;
                }
@@ -236,10 +240,16 @@ void session_set_timeout(Session *session, guint interval)
                g_source_remove(session->timeout_tag);
 
        session->timeout_interval = interval;
-       if (interval > 0)
+       if (interval > 0) {
+#if GLIB_CHECK_VERSION(2,14,0)
+               if (interval % 1000 == 0)
+                       session->timeout_tag =
+                               g_timeout_add_seconds(interval/1000, session_timeout_cb, session);
+               else
+#endif
                session->timeout_tag =
                        g_timeout_add(interval, session_timeout_cb, session);
-       else
+       else
                session->timeout_tag = 0;
 }
 
@@ -335,7 +345,7 @@ static gint session_close(Session *session)
        return 0;
 }
 
-#if USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
 gint session_start_tls(Session *session)
 {
        gboolean nb_mode;
@@ -348,7 +358,7 @@ gint session_start_tls(Session *session)
        if (!ssl_init_socket_with_method(session->sock, SSL_METHOD_TLSv1)) {
                g_warning("couldn't start TLS session.\n");
                if (nb_mode)
-                       sock_set_nonblocking_mode(session->sock, TRUE);
+                       sock_set_nonblocking_mode(session->sock, session->nonblocking);
                return -1;
        }