annotate src/sslconn.c @ 6856:a14200b24371

[gaim-migrate @ 7401] This fixes bug 803017: Use global proxy setting not saved http://sourceforge.net/tracker/?func=detail&aid=803017&group_id=235&atid=100235 The problem was basically a lack of variable initialization. Proxy settings are confusing. Like some girls I know. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 16 Sep 2003 02:39:52 +0000
parents 6d0d4e9149b9
children aa619031193b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file sslconn.c SSL API
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * (at your option) any later version.
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * GNU General Public License for more details.
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 */
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 #include "internal.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "debug.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "sslconn.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
28 /* Pre-installed SSL op functions. */
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 #ifdef HAVE_NSS
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
30 GaimSslOps *gaim_ssl_nss_get_ops();
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
33 #ifdef HAVE_GNUTLS
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
34 GaimSslOps *gaim_ssl_gnutls_get_ops();
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
37
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
38 static gboolean _ssl_initialized = FALSE;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
39 static GaimSslOps *_ssl_ops = NULL;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
40
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
41 static gboolean
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
42 ssl_init(void)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
43 {
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
44 GaimSslOps *ops = gaim_ssl_get_ops();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
45 gboolean success = FALSE;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
46
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
47 if (_ssl_initialized)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
48 return FALSE;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
49
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
50 if (ops != NULL && ops->init != NULL)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
51 success = ops->init();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
52
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
53 _ssl_initialized = success;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
54
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
55 return success;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 gboolean
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 gaim_ssl_is_supported(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
61 #ifdef HAVE_SSL
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
62 return (gaim_ssl_get_ops() != NULL);
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 #else
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 return FALSE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 GaimSslConnection *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 gaim_ssl_connect(GaimAccount *account, const char *host, int port,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 GaimSslInputFunction func, void *data)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
72 GaimSslConnection *gsc;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
73 GaimSslOps *ops;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 int i;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 g_return_val_if_fail(host != NULL, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77 g_return_val_if_fail(port != 0 && port != -1, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 g_return_val_if_fail(func != NULL, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 g_return_val_if_fail(gaim_ssl_is_supported(), NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
81 ops = gaim_ssl_get_ops();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
82
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
83 g_return_val_if_fail(ops != NULL, NULL);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
84 g_return_val_if_fail(ops->connect_cb != NULL, NULL);
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
86 if (!_ssl_initialized)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
87 {
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
88 if (!ssl_init())
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
89 return NULL;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
90 }
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
92 gsc = g_new0(GaimSslConnection, 1);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
93
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
94 gsc->host = g_strdup(host);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
95 gsc->port = port;
6764
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
96 gsc->connect_cb_data = data;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
97 gsc->connect_cb = func;
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
98
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
99 i = gaim_proxy_connect(account, host, port, ops->connect_cb, gsc);
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 if (i < 0)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
103 g_free(gsc->host);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
104 g_free(gsc);
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 return NULL;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
109 return (GaimSslConnection *)gsc;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111
6764
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
112 static void
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
113 recv_cb(gpointer data, gint source, GaimInputCondition cond)
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
114 {
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
115 GaimSslConnection *gsc = data;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
116
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
117 gsc->recv_cb(gsc->recv_cb_data, gsc, cond);
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
118 }
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
119
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
120 void
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
121 gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func, void *data)
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
122 {
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
123 GaimSslOps *ops;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
124
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
125 g_return_if_fail(func != NULL);
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
126 g_return_if_fail(gaim_ssl_is_supported());
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
127
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
128 ops = gaim_ssl_get_ops();
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
129
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
130 gsc->recv_cb_data = data;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
131 gsc->recv_cb = func;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
132 gsc->inpa = gaim_input_add(gsc->fd, GAIM_INPUT_READ, recv_cb, gsc);
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
133 }
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
134
6762
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
135 GaimSslConnection *
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
136 gaim_ssl_connect_fd(GaimAccount *account, int fd,
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
137 GaimSslInputFunction func, void *data)
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
138 {
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
139 GaimSslConnection *gsc;
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
140 GaimSslOps *ops;
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
141
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
142 g_return_val_if_fail(fd > 0, NULL);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
143 g_return_val_if_fail(func != NULL, NULL);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
144 g_return_val_if_fail(gaim_ssl_is_supported(), NULL);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
145
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
146 ops = gaim_ssl_get_ops();
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
147
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
148 g_return_val_if_fail(ops != NULL, NULL);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
149 g_return_val_if_fail(ops->connect_cb != NULL, NULL);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
150
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
151 if (!_ssl_initialized)
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
152 {
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
153 if (!ssl_init())
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
154 return NULL;
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
155 }
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
156
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
157 gsc = g_new0(GaimSslConnection, 1);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
158
6764
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
159 gsc->connect_cb_data = data;
6d0d4e9149b9 [gaim-migrate @ 7296]
Nathan Walp <nwalp@pidgin.im>
parents: 6762
diff changeset
160 gsc->connect_cb = func;
6762
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
161
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
162 ops->connect_cb(gsc, fd, GAIM_INPUT_READ);
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
163
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
164 return (GaimSslConnection *)gsc;
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
165 }
818ce550d2ce [gaim-migrate @ 7294]
Christian Hammond <chipx86@chipx86.com>
parents: 6745
diff changeset
166
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
167 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 gaim_ssl_close(GaimSslConnection *gsc)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
170 GaimSslOps *ops;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
171
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172 g_return_if_fail(gsc != NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
174 ops = gaim_ssl_get_ops();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
175
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
176 if (gsc->inpa)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
177 gaim_input_remove(gsc->inpa);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
178
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
179 if (ops != NULL && ops->close != NULL)
6745
57a24492434b [gaim-migrate @ 7277]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6738
diff changeset
180 (ops->close)(gsc);
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
181
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
182 if (gsc->fd)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
183 close(gsc->fd);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
184
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
185 if (gsc->host != NULL)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
186 g_free(gsc->host);
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
187
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
188 g_free(gsc);
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 size_t
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 gaim_ssl_read(GaimSslConnection *gsc, void *data, size_t len)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
194 GaimSslOps *ops;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
195
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
196 g_return_val_if_fail(gsc != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197 g_return_val_if_fail(data != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198 g_return_val_if_fail(len > 0, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
199
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
200 ops = gaim_ssl_get_ops();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
201
6745
57a24492434b [gaim-migrate @ 7277]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6738
diff changeset
202 if (ops != NULL && (ops->read) != NULL)
57a24492434b [gaim-migrate @ 7277]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6738
diff changeset
203 return (ops->read)(gsc, data, len);
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
204
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
205 return 0;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
206 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
207
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
208 size_t
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
209 gaim_ssl_write(GaimSslConnection *gsc, const void *data, size_t len)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
210 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
211 GaimSslOps *ops;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
212
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
213 g_return_val_if_fail(gsc != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
214 g_return_val_if_fail(data != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
215 g_return_val_if_fail(len > 0, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
216
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
217 ops = gaim_ssl_get_ops();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
218
6745
57a24492434b [gaim-migrate @ 7277]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6738
diff changeset
219 if (ops != NULL && (ops->write) != NULL)
57a24492434b [gaim-migrate @ 7277]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6738
diff changeset
220 return (ops->write)(gsc, data, len);
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
221
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 return 0;
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
223 }
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
224
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
225 void
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
226 gaim_ssl_set_ops(GaimSslOps *ops)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
227 {
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
228 _ssl_ops = ops;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
229 }
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
230
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
231 GaimSslOps *
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
232 gaim_ssl_get_ops(void)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
233 {
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
234 return _ssl_ops;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 gaim_ssl_init(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
240 #if defined(HAVE_NSS)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
241 gaim_ssl_set_ops(gaim_ssl_nss_get_ops());
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
242 #elif defined(HAVE_GNUTLS)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
243 gaim_ssl_set_ops(gaim_ssl_gnutls_get_ops());
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
244 #endif
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
247 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 gaim_ssl_uninit(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249 {
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
250 GaimSslOps *ops;
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
251
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
252 if (!_ssl_initialized)
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
255 ops = gaim_ssl_get_ops();
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256
6738
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
257 if (ops != NULL && ops->uninit != NULL)
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
258 ops->uninit();
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
259
6c95f01aaf49 [gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
260 _ssl_initialized = FALSE;
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261 }