Sun, 17 Oct 2004 23:55:49 +0000
[gaim-migrate @ 11141]
Two things:
a. Added Enter as a gtk_binding to GtkIMHtml. This fixes everything.
Input methods now work. The "Enter sends" and "Ctrl-Enter sends" preferences
were removed and defaulted to yes and no respectively, BUT, in a very super-cool
turn of events, you can now add your own bindings to .gtkrc to make WHATEVER
YOU WANT send. Awesome. Someone should use g_signal_accumulator_true_handled
or something to make profiles and away messages able to insert newlines.
b. Removed "Use multi-colored screennames in chats," defaulted to yes, and
wrote a nifty algorithm to automatically adjust the colors to accomodate the
background (see http://gaim.sf.net/sean/porn-chat.png). People should play
around and tweak it a bit. The algorithm takes into consideration the
luminosity of the current background and the base hue to use for the screenname
in generating the new colors. Note that it does this while maintaining the hues.
Someone should optimize this so it skips over the floating point arithmatic when
the background color is white.
| 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) |