Add callback for session connection result
[claws.git] / src / common / session.h
index d747a14576c276a6948d390a87c355033311c2ca..cd4b774dbd6b5f705acca0bc364f1344541d3306 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
  *
  * 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,
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifndef __SESSION_H__
 #define __SESSION_H__
 
 #ifdef HAVE_CONFIG_H
-#  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include <glib.h>
 
 #include <time.h>
-#include <sys/time.h>
 #include <unistd.h>
 
 #include "socket.h"
@@ -51,6 +50,7 @@ typedef enum {
        SESSION_SEND,
        SESSION_RECV,
        SESSION_EOF,
+       SESSION_TIMEOUT,
        SESSION_ERROR,
        SESSION_DISCONNECTED
 } SessionState;
@@ -92,16 +92,12 @@ struct _Session
        gchar *server;
        gushort port;
 
-#if USE_OPENSSL
-       SSLType ssl_type;
-#endif
-
        gboolean nonblocking;
 
        SessionState state;
 
        time_t last_access_time;
-       struct timeval tv_prev;
+       GTimeVal tv_prev;
 
        gint conn_id;
 
@@ -115,16 +111,27 @@ struct _Session
        GByteArray *read_data_buf;
        gchar *read_data_terminator;
 
+       /* buffer for short messages */
        gchar *write_buf;
        gchar *write_buf_p;
        gint write_buf_len;
 
+       /* buffer for large data */
+       const guchar *write_data;
+       const guchar *write_data_p;
+       gint write_data_len;
+
+       guint timeout_tag;
+       guint timeout_interval;
+
        gpointer data;
 
        /* virtual methods to parse server responses */
        gint (*recv_msg)                (Session        *session,
                                         const gchar    *msg);
 
+       void (*connect_finished)        (Session        *session,
+                                        gboolean       success);
        gint (*send_data_finished)      (Session        *session,
                                         guint           len);
        gint (*recv_data_finished)      (Session        *session,
@@ -145,16 +152,34 @@ struct _Session
        gpointer recv_data_notify_data;
        gpointer send_data_progressive_notify_data;
        gpointer send_data_notify_data;
+
+       const void *account;
+       gboolean is_smtp;
+       gboolean ssl_cert_auto_accept;
+       gint ping_tag;
+
+#ifdef USE_GNUTLS
+       SSLType ssl_type;
+       gchar *gnutls_priority;
+#endif
 };
 
-void session_init              (Session        *session);
+void session_init              (Session        *session, 
+                                const void     *prefs_account,
+                                gboolean        is_smtp);
 gint session_connect           (Session        *session,
                                 const gchar    *server,
                                 gushort         port);
 gint session_disconnect                (Session        *session);
 void session_destroy           (Session        *session);
+gboolean session_is_running    (Session        *session);
 gboolean session_is_connected  (Session        *session);
 
+void session_set_access_time   (Session        *session);
+
+void session_set_timeout       (Session        *session,
+                                guint           interval);
+
 void session_set_recv_message_notify   (Session        *session,
                                         RecvMsgNotify   notify_func,
                                         gpointer        data);
@@ -173,7 +198,7 @@ void session_set_send_data_notify   (Session        *session,
                                         SendDataNotify  notify_func,
                                         gpointer        data);
 
-#if USE_OPENSSL
+#ifdef USE_GNUTLS
 gint session_start_tls (Session        *session);
 #endif
 
@@ -187,5 +212,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__ */