Fix error creation and warning
[claws.git] / src / common / session.h
blob4986303e10dc46c05d96655bc15da90306e6984a
1 /*
2 * Claws Mail -- 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"
33 #include "proxy.h"
35 #define SESSION_BUFFSIZE 4096
37 typedef struct _Session Session;
39 #define SESSION(obj) ((Session *)obj)
41 typedef enum {
42 SESSION_UNKNOWN,
43 SESSION_IMAP,
44 SESSION_NEWS,
45 SESSION_SMTP,
46 SESSION_POP3
47 } SessionType;
49 typedef enum {
50 SESSION_READY,
51 SESSION_SEND,
52 SESSION_RECV,
53 SESSION_EOF,
54 SESSION_TIMEOUT,
55 SESSION_ERROR,
56 SESSION_DISCONNECTED
57 } SessionState;
59 typedef gint (*RecvMsgNotify) (Session *session,
60 const gchar *msg,
61 gpointer user_data);
62 typedef gint (*RecvDataProgressiveNotify) (Session *session,
63 guint cur_len,
64 guint total_len,
65 gpointer user_data);
66 typedef gint (*RecvDataNotify) (Session *session,
67 guint len,
68 gpointer user_data);
69 typedef gint (*SendDataProgressiveNotify) (Session *session,
70 guint cur_len,
71 guint total_len,
72 gpointer user_data);
73 typedef gint (*SendDataNotify) (Session *session,
74 guint len,
75 gpointer user_data);
77 struct _Session
79 SessionType type;
81 SockInfo *sock;
83 gchar *server;
84 gushort port;
86 gboolean nonblocking;
88 SessionState state;
90 time_t last_access_time;
91 GDateTime *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 /* Pointer to ProxyInfo struct holding the info about proxy
152 * to be used. Set to NULL if no proxy is used.
153 * If non-NULL, the memory this pointer is pointing at does
154 * not belong to this Session, and shouldn't be modified
155 * or freed by Session. It is usually a pointer to the
156 * SockInfo in common prefs, or in account prefs. */
157 ProxyInfo *proxy_info;
159 #ifdef USE_GNUTLS
160 SSLType ssl_type;
161 gchar *gnutls_priority;
162 gboolean use_tls_sni;
163 #endif
166 void session_init (Session *session,
167 const void *prefs_account,
168 gboolean is_smtp);
169 gint session_connect (Session *session,
170 const gchar *server,
171 gushort port);
172 gint session_disconnect (Session *session);
173 void session_destroy (Session *session);
174 gboolean session_is_running (Session *session);
175 gboolean session_is_connected (Session *session);
177 void session_set_access_time (Session *session);
179 void session_set_timeout (Session *session,
180 guint interval);
182 void session_set_recv_message_notify (Session *session,
183 RecvMsgNotify notify_func,
184 gpointer data);
185 void session_set_recv_data_progressive_notify
186 (Session *session,
187 RecvDataProgressiveNotify notify_func,
188 gpointer data);
189 void session_set_recv_data_notify (Session *session,
190 RecvDataNotify notify_func,
191 gpointer data);
192 void session_set_send_data_progressive_notify
193 (Session *session,
194 SendDataProgressiveNotify notify_func,
195 gpointer data);
196 void session_set_send_data_notify (Session *session,
197 SendDataNotify notify_func,
198 gpointer data);
200 #ifdef USE_GNUTLS
201 gint session_start_tls (Session *session);
202 #endif
204 gint session_send_msg (Session *session,
205 const gchar *msg);
206 gint session_recv_msg (Session *session);
207 gint session_send_data (Session *session,
208 const guchar *data,
209 guint size);
210 gint session_recv_data (Session *session,
211 guint size,
212 const gchar *terminator);
213 void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data));
215 #endif /* __SESSION_H__ */