Mercurial > pidgin
annotate src/sslconn.h @ 7824:1663c076a744
[gaim-migrate @ 8476]
Changes from revo/shx. They're still all #if 0'ed out and what not.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Wed, 10 Dec 2003 06:34:11 +0000 |
| parents | 448e39ace278 |
| children | fa6395637e2c |
| rev | line source |
|---|---|
| 6703 | 1 /** |
| 2 * @file sslconn.h SSL API | |
| 3 * @ingroup core | |
| 4 * | |
| 5 * gaim | |
| 6 * | |
| 7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License as published by | |
| 11 * the Free Software Foundation; either version 2 of the License, or | |
| 12 * (at your option) any later version. | |
| 13 * | |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 */ | |
| 23 #ifndef _GAIM_SSL_H_ | |
| 24 #define _GAIM_SSL_H_ | |
| 25 | |
| 26 #include "proxy.h" | |
| 27 | |
|
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
28 #define GAIM_SSL_DEFAULT_PORT 443 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
29 |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
30 typedef enum |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
31 { |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
32 GAIM_SSL_HANDSHAKE_FAILED = 1 |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
33 |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
34 } GaimSslErrorType; |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
35 |
|
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
36 typedef struct _GaimSslConnection GaimSslConnection; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
37 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
38 typedef void (*GaimSslInputFunction)(gpointer, GaimSslConnection *, |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
39 GaimInputCondition); |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
40 typedef void (*GaimSslErrorFunction)(GaimSslConnection *, GaimSslErrorType, |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
41 gpointer); |
|
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
42 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
43 struct _GaimSslConnection |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
44 { |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
45 char *host; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
46 int port; |
| 6764 | 47 void *connect_cb_data; |
| 48 GaimSslInputFunction connect_cb; | |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
49 GaimSslErrorFunction error_cb; |
| 6764 | 50 void *recv_cb_data; |
| 51 GaimSslInputFunction recv_cb; | |
|
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
52 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
53 int fd; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
54 int inpa; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
55 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
56 void *private_data; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
57 }; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
58 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
59 /** |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
60 * SSL implementation operations structure. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
61 * |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
62 * Every SSL implementation must provide one of these and register it. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
63 */ |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
64 typedef struct |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
65 { |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
66 gboolean (*init)(void); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
67 void (*uninit)(void); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
68 GaimInputFunction connect_cb; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
69 void (*close)(GaimSslConnection *gsc); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
70 size_t (*read)(GaimSslConnection *gsc, void *data, size_t len); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
71 size_t (*write)(GaimSslConnection *gsc, const void *data, size_t len); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
72 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
73 } GaimSslOps; |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
74 |
| 6703 | 75 #ifdef __cplusplus |
| 76 extern "C" { | |
| 77 #endif | |
| 78 | |
| 79 /**************************************************************************/ | |
| 80 /** @name SSL API */ | |
| 81 /**************************************************************************/ | |
| 82 /*@{*/ | |
| 83 | |
| 84 /** | |
| 85 * Returns whether or not SSL is currently supported. | |
| 86 * | |
| 87 * @return TRUE if SSL is supported, or FALSE otherwise. | |
| 88 */ | |
| 89 gboolean gaim_ssl_is_supported(void); | |
| 90 | |
| 91 /** | |
| 92 * Makes a SSL connection to the specified host and port. | |
| 93 * | |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
94 * @param account The account making the connection. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
95 * @param host The destination host. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
96 * @param port The destination port. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
97 * @param func The SSL input handler function. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
98 * @param error_func The SSL error handler function. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
99 * @param data User-defined data. |
| 6703 | 100 * |
| 101 * @return The SSL connection handle. | |
| 102 */ | |
| 103 GaimSslConnection *gaim_ssl_connect(GaimAccount *account, const char *host, | |
| 104 int port, GaimSslInputFunction func, | |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
105 GaimSslErrorFunction error_func, |
| 6703 | 106 void *data); |
| 107 | |
| 108 /** | |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
109 * Makes a SSL connection using an already open file descriptor. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
110 * |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
111 * @param account The account making the connection. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
112 * @param fd The file descriptor. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
113 * @param func The SSL input handler function. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
114 * @param error_func The SSL error handler function. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
115 * @param data User-defined data. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
116 * |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
117 * @return The SSL connection handle. |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
118 */ |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
119 GaimSslConnection *gaim_ssl_connect_fd(GaimAccount *account, int fd, |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
120 GaimSslInputFunction func, |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
121 GaimSslErrorFunction error_func, |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
122 void *data); |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
123 |
|
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
124 /** |
| 6764 | 125 * Adds an input watcher for the specified SSL connection. |
| 126 * | |
| 127 * @param gsc The SSL connection handle. | |
| 128 * @param func The callback function. | |
| 129 * @param data User-defined data. | |
| 130 */ | |
| 131 void gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func, | |
|
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
132 void *data); |
|
6762
818ce550d2ce
[gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
133 |
|
818ce550d2ce
[gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
134 /** |
| 6703 | 135 * Closes a SSL connection. |
| 136 * | |
| 137 * @param gsc The SSL connection to close. | |
| 138 */ | |
| 139 void gaim_ssl_close(GaimSslConnection *gsc); | |
| 140 | |
| 141 /** | |
| 142 * Reads data from an SSL connection. | |
| 143 * | |
| 144 * @param gsc The SSL connection handle. | |
| 145 * @param buffer The destination buffer. | |
| 146 * @param len The maximum number of bytes to read. | |
| 147 * | |
| 148 * @return The number of bytes read. | |
| 149 */ | |
|
6720
41120df7ed94
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
150 size_t gaim_ssl_read(GaimSslConnection *gsc, void *buffer, size_t len); |
| 6703 | 151 |
| 152 /** | |
| 153 * Writes data to an SSL connection. | |
| 154 * | |
|
6720
41120df7ed94
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
155 * @param gsc The SSL connection handle. |
|
41120df7ed94
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
156 * @param buffer The buffer to write. |
|
41120df7ed94
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
157 * @param len The length of the data to write. |
| 6703 | 158 * |
| 159 * @return The number of bytes written. | |
| 160 */ | |
|
6720
41120df7ed94
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
161 size_t gaim_ssl_write(GaimSslConnection *gsc, const void *buffer, size_t len); |
| 6703 | 162 |
| 163 /*@}*/ | |
| 164 | |
| 165 /**************************************************************************/ | |
| 166 /** @name Subsystem API */ | |
| 167 /**************************************************************************/ | |
| 168 /*@{*/ | |
| 169 | |
| 170 /** | |
|
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
171 * Sets the current SSL operations structure. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
172 * |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
173 * @param ops The SSL operations structure to assign. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
174 */ |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
175 void gaim_ssl_set_ops(GaimSslOps *ops); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
176 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
177 /** |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
178 * Returns the current SSL operations structure. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
179 * |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
180 * @return The SSL operations structure. |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
181 */ |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
182 GaimSslOps *gaim_ssl_get_ops(void); |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
183 |
|
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
184 /** |
| 6703 | 185 * Initializes the SSL subsystem. |
| 186 */ | |
| 187 void gaim_ssl_init(void); | |
| 188 | |
| 189 /** | |
| 190 * Uninitializes the SSL subsystem. | |
| 191 */ | |
| 192 void gaim_ssl_uninit(void); | |
| 193 | |
| 194 /*@}*/ | |
| 195 | |
| 196 #ifdef __cplusplus | |
| 197 } | |
| 198 #endif | |
| 199 | |
| 200 #endif /* _GAIM_SSL_H_ */ |
