Forgot to adjust default window size
[claws.git] / src / common / session.h
blob72b451261c5a08eec72b67c79b511cdf85760c1f
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef __SESSION_H__
21 #define __SESSION_H__
23 #ifdef HAVE_CONFIG_H
24 #include "claws-features.h"
25 #endif
27 #include <glib.h>
29 #include <time.h>
30 #include <unistd.h>
32 #include "socket.h"
34 #define SESSION_BUFFSIZE 4096
36 typedef struct _Session Session;
38 #define SESSION(obj) ((Session *)obj)
40 typedef enum {
41 SESSION_UNKNOWN,
42 SESSION_IMAP,
43 SESSION_NEWS,
44 SESSION_SMTP,
45 SESSION_POP3
46 } SessionType;
48 typedef enum {
49 SESSION_READY,
50 SESSION_SEND,
51 SESSION_RECV,
52 SESSION_EOF,
53 SESSION_TIMEOUT,
54 SESSION_ERROR,
55 SESSION_DISCONNECTED
56 } SessionState;
58 typedef gint (*RecvMsgNotify) (Session *session,
59 const gchar *msg,
60 gpointer user_data);
61 typedef gint (*RecvDataProgressiveNotify) (Session *session,
62 guint cur_len,
63 guint total_len,
64 gpointer user_data);
65 typedef gint (*RecvDataNotify) (Session *session,
66 guint len,
67 gpointer user_data);
68 typedef gint (*SendDataProgressiveNotify) (Session *session,
69 guint cur_len,
70 guint total_len,
71 gpointer user_data);
72 typedef gint (*SendDataNotify) (Session *session,
73 guint len,
74 gpointer user_data);
76 struct _Session
78 SessionType type;
80 SockInfo *sock;
82 gchar *server;
83 gushort port;
85 gboolean nonblocking;
87 SessionState state;
89 time_t last_access_time;
90 GTimeVal tv_prev;
92 gint conn_id;
94 gint io_tag;
96 gchar read_buf[SESSION_BUFFSIZE];
97 gchar *read_buf_p;
98 gint read_buf_len;
100 GString *read_msg_buf;
101 GByteArray *read_data_buf;
102 gchar *read_data_terminator;
104 /* buffer for short messages */
105 gchar *write_buf;
106 gchar *write_buf_p;
107 gint write_buf_len;
109 /* buffer for large data */
110 const guchar *write_data;
111 const guchar *write_data_p;
112 gint write_data_len;
114 guint timeout_tag;
115 guint timeout_interval;
117 gpointer data;
119 /* virtual methods to parse server responses */
120 gint (*recv_msg) (Session *session,
121 const gchar *msg);
123 void (*connect_finished) (Session *session,
124 gboolean success);
125 gint (*send_data_finished) (Session *session,
126 guint len);
127 gint (*recv_data_finished) (Session *session,
128 guchar *data,
129 guint len);
131 void (*destroy) (Session *session);
133 /* notification functions */
134 RecvMsgNotify recv_msg_notify;
135 RecvDataProgressiveNotify recv_data_progressive_notify;
136 RecvDataNotify recv_data_notify;
137 SendDataProgressiveNotify send_data_progressive_notify;
138 SendDataNotify send_data_notify;
140 gpointer recv_msg_notify_data;
141 gpointer recv_data_progressive_notify_data;
142 gpointer recv_data_notify_data;
143 gpointer send_data_progressive_notify_data;
144 gpointer send_data_notify_data;
146 const void *account;
147 gboolean is_smtp;
148 gboolean ssl_cert_auto_accept;
149 gint ping_tag;
151 #ifdef USE_GNUTLS
152 SSLType ssl_type;
153 gchar *gnutls_priority;
154 #endif
157 void session_init (Session *session,
158 const void *prefs_account,
159 gboolean is_smtp);
160 gint session_connect (Session *session,
161 const gchar *server,
162 gushort port);
163 gint session_disconnect (Session *session);
164 void session_destroy (Session *session);
165 gboolean session_is_running (Session *session);
166 gboolean session_is_connected (Session *session);
168 void session_set_access_time (Session *session);
170 void session_set_timeout (Session *session,
171 guint interval);
173 void session_set_recv_message_notify (Session *session,
174 RecvMsgNotify notify_func,
175 gpointer data);
176 void session_set_recv_data_progressive_notify
177 (Session *session,
178 RecvDataProgressiveNotify notify_func,
179 gpointer data);
180 void session_set_recv_data_notify (Session *session,
181 RecvDataNotify notify_func,
182 gpointer data);
183 void session_set_send_data_progressive_notify
184 (Session *session,
185 SendDataProgressiveNotify notify_func,
186 gpointer data);
187 void session_set_send_data_notify (Session *session,
188 SendDataNotify notify_func,
189 gpointer data);
191 #ifdef USE_GNUTLS
192 gint session_start_tls (Session *session);
193 #endif
195 gint session_send_msg (Session *session,
196 const gchar *msg);
197 gint session_recv_msg (Session *session);
198 gint session_send_data (Session *session,
199 const guchar *data,
200 guint size);
201 gint session_recv_data (Session *session,
202 guint size,
203 const gchar *terminator);
204 void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data));
206 #endif /* __SESSION_H__ */