Mercurial > pidgin
comparison libpurple/sslconn.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 3bccbafea8c1 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file sslconn.c SSL API | 2 * @file sslconn.c SSL API |
3 * @ingroup core | 3 * @ingroup core |
4 * | 4 * |
5 * gaim | 5 * purple |
6 * | 6 * |
7 * Gaim is the legal property of its developers, whose names are too numerous | 7 * Purple 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 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | 9 * source distribution. |
10 * | 10 * |
11 * This program is free software; you can redistribute it and/or modify | 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 | 12 * it under the terms of the GNU General Public License as published by |
26 | 26 |
27 #include "debug.h" | 27 #include "debug.h" |
28 #include "sslconn.h" | 28 #include "sslconn.h" |
29 | 29 |
30 static gboolean _ssl_initialized = FALSE; | 30 static gboolean _ssl_initialized = FALSE; |
31 static GaimSslOps *_ssl_ops = NULL; | 31 static PurpleSslOps *_ssl_ops = NULL; |
32 | 32 |
33 static gboolean | 33 static gboolean |
34 ssl_init(void) | 34 ssl_init(void) |
35 { | 35 { |
36 GaimPlugin *plugin; | 36 PurplePlugin *plugin; |
37 GaimSslOps *ops; | 37 PurpleSslOps *ops; |
38 | 38 |
39 if (_ssl_initialized) | 39 if (_ssl_initialized) |
40 return FALSE; | 40 return FALSE; |
41 | 41 |
42 plugin = gaim_plugins_find_with_id("core-ssl"); | 42 plugin = purple_plugins_find_with_id("core-ssl"); |
43 | 43 |
44 if (plugin != NULL && !gaim_plugin_is_loaded(plugin)) | 44 if (plugin != NULL && !purple_plugin_is_loaded(plugin)) |
45 gaim_plugin_load(plugin); | 45 purple_plugin_load(plugin); |
46 | 46 |
47 ops = gaim_ssl_get_ops(); | 47 ops = purple_ssl_get_ops(); |
48 if ((ops == NULL) || (ops->init == NULL) || (ops->uninit == NULL) || | 48 if ((ops == NULL) || (ops->init == NULL) || (ops->uninit == NULL) || |
49 (ops->connectfunc == NULL) || (ops->close == NULL) || | 49 (ops->connectfunc == NULL) || (ops->close == NULL) || |
50 (ops->read == NULL) || (ops->write == NULL)) | 50 (ops->read == NULL) || (ops->write == NULL)) |
51 { | 51 { |
52 return FALSE; | 52 return FALSE; |
54 | 54 |
55 return ops->init(); | 55 return ops->init(); |
56 } | 56 } |
57 | 57 |
58 gboolean | 58 gboolean |
59 gaim_ssl_is_supported(void) | 59 purple_ssl_is_supported(void) |
60 { | 60 { |
61 #ifdef HAVE_SSL | 61 #ifdef HAVE_SSL |
62 ssl_init(); | 62 ssl_init(); |
63 return (gaim_ssl_get_ops() != NULL); | 63 return (purple_ssl_get_ops() != NULL); |
64 #else | 64 #else |
65 return FALSE; | 65 return FALSE; |
66 #endif | 66 #endif |
67 } | 67 } |
68 | 68 |
69 static void | 69 static void |
70 gaim_ssl_connect_cb(gpointer data, gint source, const gchar *error_message) | 70 purple_ssl_connect_cb(gpointer data, gint source, const gchar *error_message) |
71 { | 71 { |
72 GaimSslConnection *gsc; | 72 PurpleSslConnection *gsc; |
73 GaimSslOps *ops; | 73 PurpleSslOps *ops; |
74 | 74 |
75 gsc = data; | 75 gsc = data; |
76 gsc->connect_data = NULL; | 76 gsc->connect_data = NULL; |
77 | 77 |
78 if (source < 0) | 78 if (source < 0) |
79 { | 79 { |
80 if (gsc->error_cb != NULL) | 80 if (gsc->error_cb != NULL) |
81 gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | 81 gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data); |
82 | 82 |
83 gaim_ssl_close(gsc); | 83 purple_ssl_close(gsc); |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
87 gsc->fd = source; | 87 gsc->fd = source; |
88 | 88 |
89 ops = gaim_ssl_get_ops(); | 89 ops = purple_ssl_get_ops(); |
90 ops->connectfunc(gsc); | 90 ops->connectfunc(gsc); |
91 } | 91 } |
92 | 92 |
93 GaimSslConnection * | 93 PurpleSslConnection * |
94 gaim_ssl_connect(GaimAccount *account, const char *host, int port, | 94 purple_ssl_connect(PurpleAccount *account, const char *host, int port, |
95 GaimSslInputFunction func, GaimSslErrorFunction error_func, | 95 PurpleSslInputFunction func, PurpleSslErrorFunction error_func, |
96 void *data) | 96 void *data) |
97 { | 97 { |
98 GaimSslConnection *gsc; | 98 PurpleSslConnection *gsc; |
99 | 99 |
100 g_return_val_if_fail(host != NULL, NULL); | 100 g_return_val_if_fail(host != NULL, NULL); |
101 g_return_val_if_fail(port != 0 && port != -1, NULL); | 101 g_return_val_if_fail(port != 0 && port != -1, NULL); |
102 g_return_val_if_fail(func != NULL, NULL); | 102 g_return_val_if_fail(func != NULL, NULL); |
103 g_return_val_if_fail(gaim_ssl_is_supported(), NULL); | 103 g_return_val_if_fail(purple_ssl_is_supported(), NULL); |
104 | 104 |
105 if (!_ssl_initialized) | 105 if (!_ssl_initialized) |
106 { | 106 { |
107 if (!ssl_init()) | 107 if (!ssl_init()) |
108 return NULL; | 108 return NULL; |
109 } | 109 } |
110 | 110 |
111 gsc = g_new0(GaimSslConnection, 1); | 111 gsc = g_new0(PurpleSslConnection, 1); |
112 | 112 |
113 gsc->fd = -1; | 113 gsc->fd = -1; |
114 gsc->host = g_strdup(host); | 114 gsc->host = g_strdup(host); |
115 gsc->port = port; | 115 gsc->port = port; |
116 gsc->connect_cb_data = data; | 116 gsc->connect_cb_data = data; |
117 gsc->connect_cb = func; | 117 gsc->connect_cb = func; |
118 gsc->error_cb = error_func; | 118 gsc->error_cb = error_func; |
119 | 119 |
120 gsc->connect_data = gaim_proxy_connect(NULL, account, host, port, gaim_ssl_connect_cb, gsc); | 120 gsc->connect_data = purple_proxy_connect(NULL, account, host, port, purple_ssl_connect_cb, gsc); |
121 | 121 |
122 if (gsc->connect_data == NULL) | 122 if (gsc->connect_data == NULL) |
123 { | 123 { |
124 g_free(gsc->host); | 124 g_free(gsc->host); |
125 g_free(gsc); | 125 g_free(gsc); |
126 | 126 |
127 return NULL; | 127 return NULL; |
128 } | 128 } |
129 | 129 |
130 return (GaimSslConnection *)gsc; | 130 return (PurpleSslConnection *)gsc; |
131 } | 131 } |
132 | 132 |
133 static void | 133 static void |
134 recv_cb(gpointer data, gint source, GaimInputCondition cond) | 134 recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
135 { | 135 { |
136 GaimSslConnection *gsc = data; | 136 PurpleSslConnection *gsc = data; |
137 | 137 |
138 gsc->recv_cb(gsc->recv_cb_data, gsc, cond); | 138 gsc->recv_cb(gsc->recv_cb_data, gsc, cond); |
139 } | 139 } |
140 | 140 |
141 void | 141 void |
142 gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func, | 142 purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func, |
143 void *data) | 143 void *data) |
144 { | 144 { |
145 g_return_if_fail(func != NULL); | 145 g_return_if_fail(func != NULL); |
146 g_return_if_fail(gaim_ssl_is_supported()); | 146 g_return_if_fail(purple_ssl_is_supported()); |
147 | 147 |
148 gsc->recv_cb_data = data; | 148 gsc->recv_cb_data = data; |
149 gsc->recv_cb = func; | 149 gsc->recv_cb = func; |
150 | 150 |
151 gsc->inpa = gaim_input_add(gsc->fd, GAIM_INPUT_READ, recv_cb, gsc); | 151 gsc->inpa = purple_input_add(gsc->fd, PURPLE_INPUT_READ, recv_cb, gsc); |
152 } | 152 } |
153 | 153 |
154 GaimSslConnection * | 154 PurpleSslConnection * |
155 gaim_ssl_connect_fd(GaimAccount *account, int fd, | 155 purple_ssl_connect_fd(PurpleAccount *account, int fd, |
156 GaimSslInputFunction func, | 156 PurpleSslInputFunction func, |
157 GaimSslErrorFunction error_func, void *data) | 157 PurpleSslErrorFunction error_func, void *data) |
158 { | 158 { |
159 GaimSslConnection *gsc; | 159 PurpleSslConnection *gsc; |
160 GaimSslOps *ops; | 160 PurpleSslOps *ops; |
161 | 161 |
162 g_return_val_if_fail(fd != -1, NULL); | 162 g_return_val_if_fail(fd != -1, NULL); |
163 g_return_val_if_fail(func != NULL, NULL); | 163 g_return_val_if_fail(func != NULL, NULL); |
164 g_return_val_if_fail(gaim_ssl_is_supported(), NULL); | 164 g_return_val_if_fail(purple_ssl_is_supported(), NULL); |
165 | 165 |
166 if (!_ssl_initialized) | 166 if (!_ssl_initialized) |
167 { | 167 { |
168 if (!ssl_init()) | 168 if (!ssl_init()) |
169 return NULL; | 169 return NULL; |
170 } | 170 } |
171 | 171 |
172 gsc = g_new0(GaimSslConnection, 1); | 172 gsc = g_new0(PurpleSslConnection, 1); |
173 | 173 |
174 gsc->connect_cb_data = data; | 174 gsc->connect_cb_data = data; |
175 gsc->connect_cb = func; | 175 gsc->connect_cb = func; |
176 gsc->error_cb = error_func; | 176 gsc->error_cb = error_func; |
177 gsc->fd = fd; | 177 gsc->fd = fd; |
178 | 178 |
179 ops = gaim_ssl_get_ops(); | 179 ops = purple_ssl_get_ops(); |
180 ops->connectfunc(gsc); | 180 ops->connectfunc(gsc); |
181 | 181 |
182 return (GaimSslConnection *)gsc; | 182 return (PurpleSslConnection *)gsc; |
183 } | 183 } |
184 | 184 |
185 void | 185 void |
186 gaim_ssl_close(GaimSslConnection *gsc) | 186 purple_ssl_close(PurpleSslConnection *gsc) |
187 { | 187 { |
188 GaimSslOps *ops; | 188 PurpleSslOps *ops; |
189 | 189 |
190 g_return_if_fail(gsc != NULL); | 190 g_return_if_fail(gsc != NULL); |
191 | 191 |
192 ops = gaim_ssl_get_ops(); | 192 ops = purple_ssl_get_ops(); |
193 (ops->close)(gsc); | 193 (ops->close)(gsc); |
194 | 194 |
195 if (gsc->connect_data != NULL) | 195 if (gsc->connect_data != NULL) |
196 gaim_proxy_connect_cancel(gsc->connect_data); | 196 purple_proxy_connect_cancel(gsc->connect_data); |
197 | 197 |
198 if (gsc->inpa > 0) | 198 if (gsc->inpa > 0) |
199 gaim_input_remove(gsc->inpa); | 199 purple_input_remove(gsc->inpa); |
200 | 200 |
201 if (gsc->fd >= 0) | 201 if (gsc->fd >= 0) |
202 close(gsc->fd); | 202 close(gsc->fd); |
203 | 203 |
204 g_free(gsc->host); | 204 g_free(gsc->host); |
205 g_free(gsc); | 205 g_free(gsc); |
206 } | 206 } |
207 | 207 |
208 size_t | 208 size_t |
209 gaim_ssl_read(GaimSslConnection *gsc, void *data, size_t len) | 209 purple_ssl_read(PurpleSslConnection *gsc, void *data, size_t len) |
210 { | 210 { |
211 GaimSslOps *ops; | 211 PurpleSslOps *ops; |
212 | 212 |
213 g_return_val_if_fail(gsc != NULL, 0); | 213 g_return_val_if_fail(gsc != NULL, 0); |
214 g_return_val_if_fail(data != NULL, 0); | 214 g_return_val_if_fail(data != NULL, 0); |
215 g_return_val_if_fail(len > 0, 0); | 215 g_return_val_if_fail(len > 0, 0); |
216 | 216 |
217 ops = gaim_ssl_get_ops(); | 217 ops = purple_ssl_get_ops(); |
218 return (ops->read)(gsc, data, len); | 218 return (ops->read)(gsc, data, len); |
219 } | 219 } |
220 | 220 |
221 size_t | 221 size_t |
222 gaim_ssl_write(GaimSslConnection *gsc, const void *data, size_t len) | 222 purple_ssl_write(PurpleSslConnection *gsc, const void *data, size_t len) |
223 { | 223 { |
224 GaimSslOps *ops; | 224 PurpleSslOps *ops; |
225 | 225 |
226 g_return_val_if_fail(gsc != NULL, 0); | 226 g_return_val_if_fail(gsc != NULL, 0); |
227 g_return_val_if_fail(data != NULL, 0); | 227 g_return_val_if_fail(data != NULL, 0); |
228 g_return_val_if_fail(len > 0, 0); | 228 g_return_val_if_fail(len > 0, 0); |
229 | 229 |
230 ops = gaim_ssl_get_ops(); | 230 ops = purple_ssl_get_ops(); |
231 return (ops->write)(gsc, data, len); | 231 return (ops->write)(gsc, data, len); |
232 } | 232 } |
233 | 233 |
234 void | 234 void |
235 gaim_ssl_set_ops(GaimSslOps *ops) | 235 purple_ssl_set_ops(PurpleSslOps *ops) |
236 { | 236 { |
237 _ssl_ops = ops; | 237 _ssl_ops = ops; |
238 } | 238 } |
239 | 239 |
240 GaimSslOps * | 240 PurpleSslOps * |
241 gaim_ssl_get_ops(void) | 241 purple_ssl_get_ops(void) |
242 { | 242 { |
243 return _ssl_ops; | 243 return _ssl_ops; |
244 } | 244 } |
245 | 245 |
246 void | 246 void |
247 gaim_ssl_init(void) | 247 purple_ssl_init(void) |
248 { | 248 { |
249 } | 249 } |
250 | 250 |
251 void | 251 void |
252 gaim_ssl_uninit(void) | 252 purple_ssl_uninit(void) |
253 { | 253 { |
254 GaimSslOps *ops; | 254 PurpleSslOps *ops; |
255 | 255 |
256 if (!_ssl_initialized) | 256 if (!_ssl_initialized) |
257 return; | 257 return; |
258 | 258 |
259 ops = gaim_ssl_get_ops(); | 259 ops = purple_ssl_get_ops(); |
260 ops->uninit(); | 260 ops->uninit(); |
261 | 261 |
262 _ssl_initialized = FALSE; | 262 _ssl_initialized = FALSE; |
263 } | 263 } |