Sat, 19 May 2007 21:38:47 +0000
merge of '1442df274a24edc9a31194327bd00dfbcf478720'
and 'ce02548a6b6a545d97fb3f371506bcf1b5cc5131'
| 6703 | 1 | /** |
| 2 | * @file sslconn.h SSL API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 15884 | 5 | * purple |
| 6703 | 6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 6703 | 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 | */ | |
| 15884 | 25 | #ifndef _PURPLE_SSLCONN_H_ |
| 26 | #define _PURPLE_SSLCONN_H_ | |
| 6703 | 27 | |
| 28 | #include "proxy.h" | |
| 29 | ||
| 15884 | 30 | #define PURPLE_SSL_DEFAULT_PORT 443 |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
31 | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
32 | typedef enum |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
33 | { |
| 15884 | 34 | PURPLE_SSL_HANDSHAKE_FAILED = 1, |
| 35 | PURPLE_SSL_CONNECT_FAILED = 2 | |
| 36 | } PurpleSslErrorType; | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
37 | |
| 15884 | 38 | typedef struct _PurpleSslConnection PurpleSslConnection; |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
39 | |
| 15884 | 40 | typedef void (*PurpleSslInputFunction)(gpointer, PurpleSslConnection *, |
| 41 | PurpleInputCondition); | |
| 42 | typedef void (*PurpleSslErrorFunction)(PurpleSslConnection *, PurpleSslErrorType, | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
43 | gpointer); |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
44 | |
| 15884 | 45 | struct _PurpleSslConnection |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
46 | { |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
47 | char *host; |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
48 | int port; |
| 6764 | 49 | void *connect_cb_data; |
| 15884 | 50 | PurpleSslInputFunction connect_cb; |
| 51 | PurpleSslErrorFunction error_cb; | |
| 6764 | 52 | void *recv_cb_data; |
| 15884 | 53 | PurpleSslInputFunction recv_cb; |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
54 | |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
55 | int fd; |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
56 | int inpa; |
| 15884 | 57 | PurpleProxyConnectData *connect_data; |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
58 | |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
59 | void *private_data; |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
60 | }; |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
61 | |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
62 | /** |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
63 | * SSL implementation operations structure. |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
64 | * |
|
14222
71d8761db708
[gaim-migrate @ 16808]
Mark Doliner <markdoliner@pidgin.im>
parents:
9713
diff
changeset
|
65 | * Every SSL implementation must provide all of these and register it. |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
66 | */ |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
67 | typedef struct |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
68 | { |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
69 | gboolean (*init)(void); |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
70 | void (*uninit)(void); |
| 15884 | 71 | void (*connectfunc)(PurpleSslConnection *gsc); |
| 72 | void (*close)(PurpleSslConnection *gsc); | |
| 73 | size_t (*read)(PurpleSslConnection *gsc, void *data, size_t len); | |
| 74 | size_t (*write)(PurpleSslConnection *gsc, const void *data, size_t len); | |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
75 | |
|
16743
1ce5ffe12e2a
Initial addition of padding for ui_ops and other class-like structs
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
76 | void (*_purple_reserved1)(void); |
|
1ce5ffe12e2a
Initial addition of padding for ui_ops and other class-like structs
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
77 | void (*_purple_reserved2)(void); |
|
1ce5ffe12e2a
Initial addition of padding for ui_ops and other class-like structs
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
78 | void (*_purple_reserved3)(void); |
|
1ce5ffe12e2a
Initial addition of padding for ui_ops and other class-like structs
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
79 | void (*_purple_reserved4)(void); |
| 15884 | 80 | } PurpleSslOps; |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
81 | |
| 6703 | 82 | #ifdef __cplusplus |
| 83 | extern "C" { | |
| 84 | #endif | |
| 85 | ||
| 86 | /**************************************************************************/ | |
| 87 | /** @name SSL API */ | |
| 88 | /**************************************************************************/ | |
| 89 | /*@{*/ | |
| 90 | ||
| 91 | /** | |
| 92 | * Returns whether or not SSL is currently supported. | |
| 93 | * | |
| 94 | * @return TRUE if SSL is supported, or FALSE otherwise. | |
| 95 | */ | |
| 15884 | 96 | gboolean purple_ssl_is_supported(void); |
| 6703 | 97 | |
| 98 | /** | |
|
14312
6ce4512aa9a8
[gaim-migrate @ 16932]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
99 | * Makes a SSL connection to the specified host and port. The caller |
|
6ce4512aa9a8
[gaim-migrate @ 16932]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
100 | * should keep track of the returned value and use it to cancel the |
|
6ce4512aa9a8
[gaim-migrate @ 16932]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
101 | * connection, if needed. |
| 6703 | 102 | * |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
103 | * @param account The account making the connection. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
104 | * @param host The destination host. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
105 | * @param port The destination port. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
106 | * @param func The SSL input handler function. |
|
14312
6ce4512aa9a8
[gaim-migrate @ 16932]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
107 | * @param error_func The SSL error handler function. This function |
| 15884 | 108 | * should NOT call purple_ssl_close(). In the event |
| 109 | * of an error the PurpleSslConnection will be | |
|
14312
6ce4512aa9a8
[gaim-migrate @ 16932]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
110 | * destroyed for you. |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
111 | * @param data User-defined data. |
| 6703 | 112 | * |
| 113 | * @return The SSL connection handle. | |
| 114 | */ | |
| 15884 | 115 | PurpleSslConnection *purple_ssl_connect(PurpleAccount *account, const char *host, |
| 116 | int port, PurpleSslInputFunction func, | |
| 117 | PurpleSslErrorFunction error_func, | |
| 6703 | 118 | void *data); |
| 119 | ||
| 120 | /** | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
121 | * Makes a SSL connection using an already open file descriptor. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
122 | * |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
123 | * @param account The account making the connection. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
124 | * @param fd The file descriptor. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
125 | * @param func The SSL input handler function. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
126 | * @param error_func The SSL error handler function. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
127 | * @param data User-defined data. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
128 | * |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
129 | * @return The SSL connection handle. |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
130 | */ |
| 15884 | 131 | PurpleSslConnection *purple_ssl_connect_fd(PurpleAccount *account, int fd, |
| 132 | PurpleSslInputFunction func, | |
| 133 | PurpleSslErrorFunction error_func, | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
134 | void *data); |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
135 | |
|
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
136 | /** |
| 6764 | 137 | * Adds an input watcher for the specified SSL connection. |
| 138 | * | |
| 139 | * @param gsc The SSL connection handle. | |
| 140 | * @param func The callback function. | |
| 141 | * @param data User-defined data. | |
| 142 | */ | |
| 15884 | 143 | void purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func, |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
6783
diff
changeset
|
144 | void *data); |
|
6762
2349053f14aa
[gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
145 | |
|
2349053f14aa
[gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
146 | /** |
| 6703 | 147 | * Closes a SSL connection. |
| 148 | * | |
| 149 | * @param gsc The SSL connection to close. | |
| 150 | */ | |
| 15884 | 151 | void purple_ssl_close(PurpleSslConnection *gsc); |
| 6703 | 152 | |
| 153 | /** | |
| 154 | * Reads data from an SSL connection. | |
| 155 | * | |
| 156 | * @param gsc The SSL connection handle. | |
| 157 | * @param buffer The destination buffer. | |
| 158 | * @param len The maximum number of bytes to read. | |
| 159 | * | |
| 160 | * @return The number of bytes read. | |
| 161 | */ | |
| 15884 | 162 | size_t purple_ssl_read(PurpleSslConnection *gsc, void *buffer, size_t len); |
| 6703 | 163 | |
| 164 | /** | |
| 165 | * Writes data to an SSL connection. | |
| 166 | * | |
|
6720
cdc5348dd848
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
167 | * @param gsc The SSL connection handle. |
|
cdc5348dd848
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
168 | * @param buffer The buffer to write. |
|
cdc5348dd848
[gaim-migrate @ 7247]
Christian Hammond <chipx86@chipx86.com>
parents:
6703
diff
changeset
|
169 | * @param len The length of the data to write. |
| 6703 | 170 | * |
| 171 | * @return The number of bytes written. | |
| 172 | */ | |
| 15884 | 173 | size_t purple_ssl_write(PurpleSslConnection *gsc, const void *buffer, size_t len); |
| 6703 | 174 | |
| 175 | /*@}*/ | |
| 176 | ||
| 177 | /**************************************************************************/ | |
| 178 | /** @name Subsystem API */ | |
| 179 | /**************************************************************************/ | |
| 180 | /*@{*/ | |
| 181 | ||
| 182 | /** | |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
183 | * Sets the current SSL operations structure. |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
184 | * |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
185 | * @param ops The SSL operations structure to assign. |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
186 | */ |
| 15884 | 187 | void purple_ssl_set_ops(PurpleSslOps *ops); |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
188 | |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
189 | /** |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
190 | * Returns the current SSL operations structure. |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
191 | * |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
192 | * @return The SSL operations structure. |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
193 | */ |
| 15884 | 194 | PurpleSslOps *purple_ssl_get_ops(void); |
|
6738
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
195 | |
|
aa797bcc69dd
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6720
diff
changeset
|
196 | /** |
| 6703 | 197 | * Initializes the SSL subsystem. |
| 198 | */ | |
| 15884 | 199 | void purple_ssl_init(void); |
| 6703 | 200 | |
| 201 | /** | |
| 202 | * Uninitializes the SSL subsystem. | |
| 203 | */ | |
| 15884 | 204 | void purple_ssl_uninit(void); |
| 6703 | 205 | |
| 206 | /*@}*/ | |
| 207 | ||
| 208 | #ifdef __cplusplus | |
| 209 | } | |
| 210 | #endif | |
| 211 | ||
| 15884 | 212 | #endif /* _PURPLE_SSLCONN_H_ */ |