comparison pidgin/gtkcertmgr.c @ 19062:da88aa8f83ad

- Import button now (more or less) functional
author William Ehlhardt <williamehlhardt@gmail.com>
date Mon, 30 Jul 2007 07:24:00 +0000
parents 3d6576b8c88a
children f407244c4e57
comparison
equal deleted inserted replaced
19061:3d6576b8c88a 19062:da88aa8f83ad
31 #include "pidgin.h" 31 #include "pidgin.h"
32 32
33 #include "certificate.h" 33 #include "certificate.h"
34 #include "debug.h" 34 #include "debug.h"
35 #include "notify.h" 35 #include "notify.h"
36 #include "request.h"
36 37
37 #include "gtkblist.h" 38 #include "gtkblist.h"
38 #include "gtkutils.h" 39 #include "gtkutils.h"
39 40
40 #include "gtkcertmgr.h" 41 #include "gtkcertmgr.h"
69 { 70 {
70 purple_debug_info("certmgr", 71 purple_debug_info("certmgr",
71 "tls peers self-destructs\n"); 72 "tls peers self-destructs\n");
72 73
73 purple_signals_disconnect_by_handle(tpm_dat); 74 purple_signals_disconnect_by_handle(tpm_dat);
75 purple_request_close_with_handle(tpm_dat);
74 g_free(tpm_dat); tpm_dat = NULL; 76 g_free(tpm_dat); tpm_dat = NULL;
75 } 77 }
76 78
77 static void 79 static void
78 tls_peers_mgmt_repopulate_list(void) 80 tls_peers_mgmt_repopulate_list(void)
135 137
136 } 138 }
137 } 139 }
138 140
139 static void 141 static void
142 tls_peers_mgmt_import_ok2_cb(gpointer data, const char *result)
143 {
144 PurpleCertificate *crt = (PurpleCertificate *) data;
145 const char *id = result;
146
147 /* TODO: Perhaps prompt if you're overwriting a cert? */
148
149 /* Drop the certificate into the pool */
150 purple_certificate_pool_store(tpm_dat->tls_peers, id, crt);
151
152 /* And this certificate is not needed any more */
153 purple_certificate_destroy(crt);
154 }
155
156 static void
157 tls_peers_mgmt_import_cancel2_cb(gpointer data, const char *result)
158 {
159 PurpleCertificate *crt = (PurpleCertificate *) data;
160 purple_certificate_destroy(crt);
161 }
162
163 static void
164 tls_peers_mgmt_import_ok_cb(gpointer data, const char *filename)
165 {
166 PurpleCertificateScheme *x509;
167 PurpleCertificate *crt;
168
169 /* Load the scheme of our tls_peers pool (ought to be x509) */
170 x509 = purple_certificate_pool_get_scheme(tpm_dat->tls_peers);
171
172 /* Now load the certificate from disk */
173 crt = purple_certificate_import(x509, filename);
174
175 /* Did it work? */
176 if (crt != NULL) {
177 gchar *default_hostname;
178 /* Get name to add to pool as */
179 /* Make a guess about what the hostname should be */
180 default_hostname = purple_certificate_get_subject_name(crt);
181 /* TODO: Find a way to make sure that crt gets destroyed
182 if the window gets closed unusually, such as by handle
183 deletion */
184 /* TODO: Display some more information on the certificate? */
185 purple_request_input(tpm_dat,
186 _("Certificate Import"),
187 _("Specify a hostname"),
188 _("Type the host name this certificate is for."),
189 default_hostname,
190 FALSE, /* Not multiline */
191 FALSE, /* Not masked? */
192 NULL, /* No hints? */
193 _("OK"),
194 G_CALLBACK(tls_peers_mgmt_import_ok2_cb),
195 _("Cancel"),
196 G_CALLBACK(tls_peers_mgmt_import_cancel2_cb),
197 NULL, NULL, NULL, /* No account/who/conv*/
198 crt /* Pass cert instance to callback*/
199 );
200
201 g_free(default_hostname);
202 } else {
203 /* Errors! Oh no! */
204 /* TODO: Perhaps find a way to be specific about what just
205 went wrong? */
206 gchar * secondary;
207
208 secondary = g_strdup_printf(_("File %s could not be imported.\nMake sure that the file is readable and in PEM format.\n"), filename);
209 purple_notify_error(NULL,
210 _("Certificate Import Error"),
211 _("X.509 certificate import failed"),
212 secondary);
213 g_free(secondary);
214 }
215 }
216
217 static void
218 tls_peers_mgmt_import_cb(GtkWidget *button, gpointer data)
219 {
220 /* TODO: need to tell the user that we want a .PEM file! */
221 purple_request_file(tpm_dat,
222 _("Select a PEM certificate"),
223 "certificate.pem",
224 FALSE, /* Not a save dialog */
225 G_CALLBACK(tls_peers_mgmt_import_ok_cb),
226 NULL, /* Do nothing if cancelled */
227 NULL, NULL, NULL, NULL );/* No account,conv,etc. */
228 }
229
230 static void
140 tls_peers_mgmt_delete_cb(GtkWidget *button, gpointer data) 231 tls_peers_mgmt_delete_cb(GtkWidget *button, gpointer data)
141 { 232 {
142 GtkTreeSelection *select = tpm_dat->listselect; 233 GtkTreeSelection *select = tpm_dat->listselect;
143 GtkTreeIter iter; 234 GtkTreeIter iter;
144 GtkTreeModel *model; 235 GtkTreeModel *model;
244 /* TODO: This is the wrong stock button */ 335 /* TODO: This is the wrong stock button */
245 tpm_dat->importbutton = importbutton = 336 tpm_dat->importbutton = importbutton =
246 gtk_button_new_from_stock(GTK_STOCK_ADD); 337 gtk_button_new_from_stock(GTK_STOCK_ADD);
247 gtk_box_pack_start(GTK_BOX(bbox), importbutton, FALSE, FALSE, 0); 338 gtk_box_pack_start(GTK_BOX(bbox), importbutton, FALSE, FALSE, 0);
248 gtk_widget_show(importbutton); 339 gtk_widget_show(importbutton);
340 g_signal_connect(G_OBJECT(importbutton), "clicked",
341 G_CALLBACK(tls_peers_mgmt_import_cb), NULL);
342
249 343
250 /* Export button */ 344 /* Export button */
251 /* TODO: This is the wrong stock button */ 345 /* TODO: This is the wrong stock button */
252 tpm_dat->exportbutton = exportbutton = 346 tpm_dat->exportbutton = exportbutton =
253 gtk_button_new_from_stock(GTK_STOCK_SAVE); 347 gtk_button_new_from_stock(GTK_STOCK_SAVE);