sync with 0.8.11cvs6
[claws.git] / src / common / session.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __SESSION_H__
21 #define __SESSION_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28
29 #include <time.h>
30 #include <unistd.h>
31
32 #include "socket.h"
33
34 typedef struct _Session Session;
35
36 #define SESSION(obj)    ((Session *)obj)
37
38 typedef enum {
39         SESSION_IMAP,
40         SESSION_NEWS,
41         SESSION_SMTP,
42         SESSION_POP3
43 } SessionType;
44
45 typedef enum {
46         SESSION_READY,
47         SESSION_SEND,
48         SESSION_RECV,
49         SESSION_ERROR,
50         SESSION_DISCONNECTED
51 } SessionState;
52
53 typedef enum
54 {
55         SESSION_MSG_NORMAL,
56         SESSION_MSG_SEND_DATA,
57         SESSION_MSG_RECV_DATA,
58         SESSION_MSG_CONTROL,
59         SESSION_MSG_ERROR,
60         SESSION_MSG_UNKNOWN
61 } SessionMsgType;
62
63 typedef gint (*RecvMsgNotify)                   (Session        *session,
64                                                  const gchar    *msg,
65                                                  gpointer        user_data);
66 typedef gint (*RecvDataProgressiveNotify)       (Session        *session,
67                                                  guint           cur_len,
68                                                  guint           total_len,
69                                                  gpointer        user_data);
70 typedef gint (*RecvDataNotify)                  (Session        *session,
71                                                  guint           len,
72                                                  gpointer        user_data);
73 typedef gint (*SendDataProgressiveNotify)       (Session        *session,
74                                                  guint           cur_len,
75                                                  guint           total_len,
76                                                  gpointer        user_data);
77 typedef gint (*SendDataNotify)                  (Session        *session,
78                                                  guint           len,
79                                                  gpointer        user_data);
80
81 struct _Session
82 {
83         SessionType type;
84
85         SockInfo *sock;
86
87         gchar *server;
88         gushort port;
89
90 #if USE_OPENSSL
91         SSLType ssl_type;
92 #endif
93
94         SessionState state;
95
96         time_t last_access_time;
97
98         pid_t child_pid;
99
100         /* pipe I/O */
101         GIOChannel *read_ch;
102         GIOChannel *write_ch;
103
104         gint read_tag;
105
106         gpointer data;
107
108         /* virtual methods to parse server responses */
109         gint (*recv_msg)                (Session        *session,
110                                          const gchar    *msg);
111
112         gint (*recv_data_finished)      (Session        *session,
113                                          guchar         *data,
114                                          guint           len);
115         gint (*send_data_finished)      (Session        *session,
116                                          guint           len);
117
118         void (*destroy)                 (Session        *session);
119
120         /* notification functions */
121         RecvMsgNotify                   recv_msg_notify;
122         RecvDataProgressiveNotify       recv_data_progressive_notify;
123         RecvDataNotify                  recv_data_notify;
124         SendDataProgressiveNotify       send_data_progressive_notify;
125         SendDataNotify                  send_data_notify;
126
127         gpointer recv_msg_notify_data;
128         gpointer recv_data_progressive_notify_data;
129         gpointer recv_data_notify_data;
130         gpointer send_data_progressive_notify_data;
131         gpointer send_data_notify_data;
132 };
133
134 gint session_connect    (Session        *session,
135                          const gchar    *server,
136                          gushort         port);
137 gint session_disconnect (Session        *session);
138 void session_destroy    (Session        *session);
139
140 void session_set_recv_message_notify    (Session        *session,
141                                          RecvMsgNotify   notify_func,
142                                          gpointer        data);
143 void session_set_recv_data_progressive_notify
144                                         (Session        *session,
145                                          RecvDataProgressiveNotify notify_func,
146                                          gpointer        data);
147 void session_set_recv_data_notify       (Session        *session,
148                                          RecvDataNotify  notify_func,
149                                          gpointer        data);
150 void session_set_send_data_progressive_notify
151                                         (Session        *session,
152                                          SendDataProgressiveNotify notify_func,
153                                          gpointer        data);
154 void session_set_send_data_notify       (Session        *session,
155                                          SendDataNotify  notify_func,
156                                          gpointer        data);
157
158 gint session_send_msg   (Session        *session,
159                          SessionMsgType  type,
160                          const gchar    *msg);
161 gint session_send_data  (Session        *session,
162                          const guchar   *data,
163                          guint           size);
164
165 #if USE_OPENSSL
166 gint session_start_tls  (Session        *session);
167 #endif
168
169 #endif /* __SESSION_H__ */