Tue, 21 Jun 2005 04:40:34 +0000
[gaim-migrate @ 12885]
Wherever possible, allow users to act on objects and data directly, rather
than through dialogs or explicit commands. For example, it is more intuitive
to drag a circle object around in a diagram rather than selecting a "Move"
command from a menu while the circle is selected. Simlarly, in an email
application, allow the user to attach files by dragging them from the file
manager and dropping them onto the message composition window if they wish.
-- GNOME HIG
This allows direct manipulation of buddy aliases and group names, by moving
the features from dialogs to GtkTreeView's inline editing.
I think this is a great change, but it seems like the type of thing that
might stir up controversy. If so, take it to the mailing list for discussion.
If not, I'll go ahead and perfect this sometime later.
-s.
| 7016 | 1 | /** |
| 2 | * @file ssl-gnutls.c GNUTLS SSL plugin. | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | #include "internal.h" | |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
23 | #include "debug.h" |
| 7016 | 24 | #include "plugin.h" |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
25 | #include "sslconn.h" |
| 9943 | 26 | #include "version.h" |
| 7016 | 27 | |
| 28 | #define SSL_GNUTLS_PLUGIN_ID "ssl-gnutls" | |
| 29 | ||
| 30 | #ifdef HAVE_GNUTLS | |
| 31 | ||
| 32 | #include <gnutls/gnutls.h> | |
| 33 | ||
| 34 | typedef struct | |
| 35 | { | |
| 36 | gnutls_session session; | |
| 37 | ||
| 38 | } GaimSslGnutlsData; | |
| 39 | ||
| 40 | #define GAIM_SSL_GNUTLS_DATA(gsc) ((GaimSslGnutlsData *)gsc->private_data) | |
| 41 | ||
| 42 | static gnutls_certificate_client_credentials xcred; | |
| 43 | ||
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
44 | static void |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
45 | ssl_gnutls_init_gnutls(void) |
| 7016 | 46 | { |
| 47 | gnutls_global_init(); | |
| 48 | ||
| 49 | gnutls_certificate_allocate_credentials(&xcred); | |
| 50 | gnutls_certificate_set_x509_trust_file(xcred, "ca.pem", | |
| 51 | GNUTLS_X509_FMT_PEM); | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
52 | } |
| 7016 | 53 | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
54 | static gboolean |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
55 | ssl_gnutls_init(void) |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
56 | { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
57 | return TRUE; |
| 7016 | 58 | } |
| 59 | ||
| 60 | static void | |
| 61 | ssl_gnutls_uninit(void) | |
| 62 | { | |
| 63 | gnutls_global_deinit(); | |
| 64 | ||
| 65 | gnutls_certificate_free_credentials(xcred); | |
| 66 | } | |
| 67 | ||
| 68 | static void | |
| 69 | ssl_gnutls_connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 70 | { | |
| 71 | GaimSslConnection *gsc = (GaimSslConnection *)data; | |
| 72 | GaimSslGnutlsData *gnutls_data; | |
| 73 | static const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 }; | |
| 74 | int ret; | |
| 75 | ||
| 8362 | 76 | if (source < 0) { |
| 77 | if(gsc->error_cb != NULL) | |
| 78 | gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | |
| 79 | ||
| 80 | gaim_ssl_close(gsc); | |
| 7016 | 81 | return; |
| 8362 | 82 | } |
| 7016 | 83 | |
| 84 | gsc->fd = source; | |
| 85 | ||
| 86 | gnutls_data = g_new0(GaimSslGnutlsData, 1); | |
| 87 | gsc->private_data = gnutls_data; | |
| 88 | ||
| 89 | gnutls_init(&gnutls_data->session, GNUTLS_CLIENT); | |
| 90 | gnutls_set_default_priority(gnutls_data->session); | |
| 91 | ||
| 92 | gnutls_certificate_type_set_priority(gnutls_data->session, | |
| 93 | cert_type_priority); | |
| 94 | ||
| 95 | gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE, | |
| 96 | xcred); | |
| 97 | ||
| 98 | gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(source)); | |
| 99 | ||
| 7834 | 100 | |
| 101 | do | |
| 102 | { | |
| 8375 | 103 | gaim_debug_info("gnutls", "Handshaking\n"); |
| 7834 | 104 | ret = gnutls_handshake(gnutls_data->session); |
| 105 | } | |
| 106 | while ((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)); | |
| 107 | ||
| 7016 | 108 | if (ret < 0) |
| 109 | { | |
|
7325
714ca91f70d0
[gaim-migrate @ 7911]
Christian Hammond <chipx86@chipx86.com>
parents:
7274
diff
changeset
|
110 | gaim_debug_error("gnutls", "Handshake failed. Error %d\n", ret); |
| 7016 | 111 | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7051
diff
changeset
|
112 | if (gsc->error_cb != NULL) |
| 7481 | 113 | gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, |
| 114 | gsc->connect_cb_data); | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7051
diff
changeset
|
115 | |
| 7016 | 116 | gaim_ssl_close(gsc); |
| 117 | } | |
| 118 | else | |
| 119 | { | |
| 8369 | 120 | gaim_debug_info("gnutls", "Handshake complete\n"); |
| 121 | ||
| 7016 | 122 | gsc->connect_cb(gsc->connect_cb_data, gsc, cond); |
| 123 | } | |
| 124 | } | |
| 125 | ||
| 126 | static void | |
| 127 | ssl_gnutls_close(GaimSslConnection *gsc) | |
| 128 | { | |
| 129 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 130 | ||
| 7467 | 131 | if(!gnutls_data) |
| 132 | return; | |
| 133 | ||
| 7016 | 134 | gnutls_bye(gnutls_data->session, GNUTLS_SHUT_RDWR); |
| 135 | ||
| 136 | gnutls_deinit(gnutls_data->session); | |
| 137 | ||
| 138 | g_free(gnutls_data); | |
| 139 | } | |
| 140 | ||
| 141 | static size_t | |
| 142 | ssl_gnutls_read(GaimSslConnection *gsc, void *data, size_t len) | |
| 143 | { | |
| 144 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 145 | int s; | |
| 146 | ||
| 7834 | 147 | do |
| 148 | { | |
| 149 | s = gnutls_record_recv(gnutls_data->session, data, len); | |
| 150 | } | |
| 151 | while ((s == GNUTLS_E_AGAIN) || (s == GNUTLS_E_INTERRUPTED)); | |
| 7016 | 152 | |
| 153 | if (s < 0) | |
| 7834 | 154 | { |
| 155 | gaim_debug_error("gnutls", "receive failed: %d\n", s); | |
| 7016 | 156 | s = 0; |
| 7834 | 157 | } |
| 7016 | 158 | |
| 159 | return s; | |
| 160 | } | |
| 161 | ||
| 162 | static size_t | |
| 163 | ssl_gnutls_write(GaimSslConnection *gsc, const void *data, size_t len) | |
| 164 | { | |
| 165 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 7467 | 166 | size_t s = 0; |
| 7016 | 167 | |
| 7467 | 168 | if(gnutls_data) |
| 169 | s = gnutls_record_send(gnutls_data->session, data, len); | |
| 7016 | 170 | |
| 171 | return s; | |
| 172 | } | |
| 173 | ||
| 174 | static GaimSslOps ssl_ops = | |
| 175 | { | |
| 176 | ssl_gnutls_init, | |
| 177 | ssl_gnutls_uninit, | |
| 178 | ssl_gnutls_connect_cb, | |
| 179 | ssl_gnutls_close, | |
| 180 | ssl_gnutls_read, | |
| 181 | ssl_gnutls_write | |
| 182 | }; | |
| 183 | ||
| 184 | #endif /* HAVE_GNUTLS */ | |
| 185 | ||
| 186 | static gboolean | |
| 187 | plugin_load(GaimPlugin *plugin) | |
| 188 | { | |
| 189 | #ifdef HAVE_GNUTLS | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
190 | if (!gaim_ssl_get_ops()) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
191 | gaim_ssl_set_ops(&ssl_ops); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
192 | } |
| 7016 | 193 | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
194 | /* Init GNUTLS now so others can use it even if sslconn never does */ |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
195 | ssl_gnutls_init_gnutls(); |
| 7016 | 196 | return TRUE; |
| 197 | #else | |
| 198 | return FALSE; | |
| 199 | #endif | |
| 200 | } | |
| 201 | ||
| 202 | static gboolean | |
| 203 | plugin_unload(GaimPlugin *plugin) | |
| 204 | { | |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
205 | #ifdef HAVE_GNUTLS |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
206 | if (gaim_ssl_get_ops() == &ssl_ops) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
207 | gaim_ssl_set_ops(NULL); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
208 | } |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
209 | #endif |
|
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
210 | |
| 7016 | 211 | return TRUE; |
| 212 | } | |
| 213 | ||
| 214 | static GaimPluginInfo info = | |
| 215 | { | |
| 9943 | 216 | GAIM_PLUGIN_MAGIC, |
| 217 | GAIM_MAJOR_VERSION, | |
| 218 | GAIM_MINOR_VERSION, | |
| 7016 | 219 | GAIM_PLUGIN_STANDARD, /**< type */ |
| 220 | NULL, /**< ui_requirement */ | |
| 221 | GAIM_PLUGIN_FLAG_INVISIBLE, /**< flags */ | |
| 222 | NULL, /**< dependencies */ | |
| 223 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 224 | ||
| 225 | SSL_GNUTLS_PLUGIN_ID, /**< id */ | |
| 226 | N_("GNUTLS"), /**< name */ | |
| 227 | VERSION, /**< version */ | |
| 228 | /** summary */ | |
| 229 | N_("Provides SSL support through GNUTLS."), | |
| 230 | /** description */ | |
| 231 | N_("Provides SSL support through GNUTLS."), | |
| 232 | "Christian Hammond <chipx86@gnupdate.org>", | |
| 233 | GAIM_WEBSITE, /**< homepage */ | |
| 234 | ||
| 235 | plugin_load, /**< load */ | |
| 236 | plugin_unload, /**< unload */ | |
| 237 | NULL, /**< destroy */ | |
| 238 | ||
| 239 | NULL, /**< ui_info */ | |
| 240 | NULL /**< extra_info */ | |
| 241 | }; | |
| 242 | ||
| 243 | static void | |
| 244 | init_plugin(GaimPlugin *plugin) | |
| 245 | { | |
| 246 | } | |
| 247 | ||
| 248 | GAIM_INIT_PLUGIN(ssl_gnutls, init_plugin, info) |