core/sslconn.h

changeset 14253
b63ebf84c42b
parent 14241
7b47f525742a
equal deleted inserted replaced
14252:d10dda2777a9 14253:b63ebf84c42b
1 /**
2 * @file sslconn.h SSL API
3 * @ingroup core
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 #ifndef _GAIM_SSLCONN_H_
26 #define _GAIM_SSLCONN_H_
27
28 #include "proxy.h"
29
30 #define GAIM_SSL_DEFAULT_PORT 443
31
32 typedef enum
33 {
34 GAIM_SSL_HANDSHAKE_FAILED = 1,
35 GAIM_SSL_CONNECT_FAILED = 2
36 } GaimSslErrorType;
37
38 typedef struct _GaimSslConnection GaimSslConnection;
39
40 typedef void (*GaimSslInputFunction)(gpointer, GaimSslConnection *,
41 GaimInputCondition);
42 typedef void (*GaimSslErrorFunction)(GaimSslConnection *, GaimSslErrorType,
43 gpointer);
44
45 struct _GaimSslConnection
46 {
47 char *host;
48 int port;
49 void *connect_cb_data;
50 GaimSslInputFunction connect_cb;
51 GaimSslErrorFunction error_cb;
52 void *recv_cb_data;
53 GaimSslInputFunction recv_cb;
54
55 int fd;
56 int inpa;
57 GaimProxyConnectInfo *connect_info;
58
59 void *private_data;
60 };
61
62 /**
63 * SSL implementation operations structure.
64 *
65 * Every SSL implementation must provide all of these and register it.
66 */
67 typedef struct
68 {
69 gboolean (*init)(void);
70 void (*uninit)(void);
71 void (*connectfunc)(GaimSslConnection *gsc);
72 void (*close)(GaimSslConnection *gsc);
73 size_t (*read)(GaimSslConnection *gsc, void *data, size_t len);
74 size_t (*write)(GaimSslConnection *gsc, const void *data, size_t len);
75
76 } GaimSslOps;
77
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81
82 /**************************************************************************/
83 /** @name SSL API */
84 /**************************************************************************/
85 /*@{*/
86
87 /**
88 * Returns whether or not SSL is currently supported.
89 *
90 * @return TRUE if SSL is supported, or FALSE otherwise.
91 */
92 gboolean gaim_ssl_is_supported(void);
93
94 /**
95 * Makes a SSL connection to the specified host and port.
96 *
97 * @param account The account making the connection.
98 * @param host The destination host.
99 * @param port The destination port.
100 * @param func The SSL input handler function.
101 * @param error_func The SSL error handler function.
102 * @param data User-defined data.
103 *
104 * @return The SSL connection handle.
105 */
106 GaimSslConnection *gaim_ssl_connect(GaimAccount *account, const char *host,
107 int port, GaimSslInputFunction func,
108 GaimSslErrorFunction error_func,
109 void *data);
110
111 /**
112 * Makes a SSL connection using an already open file descriptor.
113 *
114 * @param account The account making the connection.
115 * @param fd The file descriptor.
116 * @param func The SSL input handler function.
117 * @param error_func The SSL error handler function.
118 * @param data User-defined data.
119 *
120 * @return The SSL connection handle.
121 */
122 GaimSslConnection *gaim_ssl_connect_fd(GaimAccount *account, int fd,
123 GaimSslInputFunction func,
124 GaimSslErrorFunction error_func,
125 void *data);
126
127 /**
128 * Adds an input watcher for the specified SSL connection.
129 *
130 * @param gsc The SSL connection handle.
131 * @param func The callback function.
132 * @param data User-defined data.
133 */
134 void gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func,
135 void *data);
136
137 /**
138 * Closes a SSL connection.
139 *
140 * @param gsc The SSL connection to close.
141 */
142 void gaim_ssl_close(GaimSslConnection *gsc);
143
144 /**
145 * Reads data from an SSL connection.
146 *
147 * @param gsc The SSL connection handle.
148 * @param buffer The destination buffer.
149 * @param len The maximum number of bytes to read.
150 *
151 * @return The number of bytes read.
152 */
153 size_t gaim_ssl_read(GaimSslConnection *gsc, void *buffer, size_t len);
154
155 /**
156 * Writes data to an SSL connection.
157 *
158 * @param gsc The SSL connection handle.
159 * @param buffer The buffer to write.
160 * @param len The length of the data to write.
161 *
162 * @return The number of bytes written.
163 */
164 size_t gaim_ssl_write(GaimSslConnection *gsc, const void *buffer, size_t len);
165
166 /*@}*/
167
168 /**************************************************************************/
169 /** @name Subsystem API */
170 /**************************************************************************/
171 /*@{*/
172
173 /**
174 * Sets the current SSL operations structure.
175 *
176 * @param ops The SSL operations structure to assign.
177 */
178 void gaim_ssl_set_ops(GaimSslOps *ops);
179
180 /**
181 * Returns the current SSL operations structure.
182 *
183 * @return The SSL operations structure.
184 */
185 GaimSslOps *gaim_ssl_get_ops(void);
186
187 /**
188 * Initializes the SSL subsystem.
189 */
190 void gaim_ssl_init(void);
191
192 /**
193 * Uninitializes the SSL subsystem.
194 */
195 void gaim_ssl_uninit(void);
196
197 /*@}*/
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* _GAIM_SSLCONN_H_ */

mercurial