diff options
author | Chris Toshok <toshok@ximian.com> | 2002-11-13 07:05:06 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2002-11-13 07:05:06 +0800 |
commit | becc84e5c51f8150b8db1fb28337fa55f7c14caf (patch) | |
tree | 2151389a9cc1d7682fc922f50a11a8ef1e479c4c /e-util/e-passwords.c | |
parent | 6c988be90916e1928b48b8ac7a8feceaed9f5c57 (diff) | |
download | gsoc2013-evolution-becc84e5c51f8150b8db1fb28337fa55f7c14caf.tar.gz gsoc2013-evolution-becc84e5c51f8150b8db1fb28337fa55f7c14caf.tar.zst gsoc2013-evolution-becc84e5c51f8150b8db1fb28337fa55f7c14caf.zip |
add e-password.h (libeutil_la_SOURCES): add e-password.c
2002-11-12 Chris Toshok <toshok@ximian.com>
* Makefile.am
(eutilinclude_HEADERS): add e-password.h
(libeutil_la_SOURCES): add e-password.c
* e-passwords.[ch]: port this to gnome2's gnome-config-private.
svn path=/trunk/; revision=18727
Diffstat (limited to 'e-util/e-passwords.c')
-rw-r--r-- | e-util/e-passwords.c | 144 |
1 files changed, 56 insertions, 88 deletions
diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c index 7d5f25a545..48acd6297b 100644 --- a/e-util/e-passwords.c +++ b/e-util/e-passwords.c @@ -27,22 +27,15 @@ #endif #include "e-passwords.h" -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> #include <libgnome/gnome-config.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock.h> +#include <libgnome/gnome-i18n.h> #include <gtk/gtkentry.h> +#include <gtk/gtkbox.h> #include <gtk/gtkcheckbutton.h> -#include <bonobo-conf/bonobo-config-database.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-moniker-util.h> -#include <bonobo/bonobo-exception.h> +#include <gtk/gtkmessagedialog.h> static char *decode_base64 (char *base64); -Bonobo_ConfigDatabase db; static GHashTable *passwords = NULL; static char *component_name = NULL; @@ -58,24 +51,7 @@ static int base64_encode_step(unsigned char *in, int len, gboolean break_lines, void e_passwords_init (const char *component) { - CORBA_Environment ev; - - /* open up our bonobo config database */ - CORBA_exception_init (&ev); - db = bonobo_get_object ("wombat-private:", "Bonobo/ConfigDatabase", &ev); - - if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL) { - char *err; - g_error ("Very serious error, cannot activate private config database '%s'", - (err = bonobo_exception_get_text (&ev))); - g_free (err); - CORBA_exception_free (&ev); - return; - } - - CORBA_exception_free (&ev); - - /* and create the per-session hash table */ + /* create the per-session hash table */ passwords = g_hash_table_new (g_str_hash, g_str_equal); component_name = g_strdup (component); @@ -98,14 +74,8 @@ free_entry (gpointer key, gpointer value, gpointer user_data) void e_passwords_shutdown () { - CORBA_Environment ev; - - /* sync our db work */ - CORBA_exception_init (&ev); - Bonobo_ConfigDatabase_sync (db, &ev); - bonobo_object_release_unref (db, &ev); - CORBA_exception_free (&ev); - db = NULL; + /* shouldn't need this really - everything is synchronous */ + gnome_config_private_sync_file ("/Evolution"); /* and destroy our per session hash */ g_hash_table_foreach_remove (passwords, free_entry, NULL); @@ -125,13 +95,8 @@ e_passwords_shutdown () void e_passwords_forget_passwords () { - CORBA_Environment ev; - - /* remove all the persistent passwords */ - CORBA_exception_init (&ev); - Bonobo_ConfigDatabase_removeDir (db, "/Passwords", &ev); - Bonobo_ConfigDatabase_sync (db, &ev); - CORBA_exception_free (&ev); + gnome_config_private_clean_section ("/Evolution/Passwords"); + gnome_config_private_sync_file ("/Evolution"); /* free up the session passwords */ g_hash_table_foreach_remove (passwords, free_entry, NULL); @@ -145,15 +110,12 @@ e_passwords_forget_passwords () void e_passwords_clear_component_passwords () { - CORBA_Environment ev; char *path; - path = g_strdup_printf ("/Passwords/%s", component_name); + path = g_strdup_printf ("/Evolution/Passwords-%s", component_name); - CORBA_exception_init (&ev); - Bonobo_ConfigDatabase_removeDir (db, path, &ev); - Bonobo_ConfigDatabase_sync (db, &ev); - CORBA_exception_free (&ev); + gnome_config_private_clean_section (path); + gnome_config_private_sync_file ("/Evolution"); g_free (path); } @@ -161,15 +123,17 @@ e_passwords_clear_component_passwords () static char * password_path (const char *key) { - int len, state, save; - char *key64, *path; + char *keycopy, *path; + int i; + keycopy = g_strdup (key); - len = strlen (key); - key64 = g_malloc0 ((len + 2) * 4 / 3 + 1); - state = save = 0; - base64_encode_close ((char*)key, len, FALSE, key64, &state, &save); - path = g_strdup_printf ("/Passwords/%s/%s", component_name, key64); - g_free (key64); + for (i = 0; i < strlen (keycopy); i ++) + if (keycopy[i] == '/' || keycopy[i] =='=') + keycopy[i] = '_'; + + path = g_strdup_printf ("/Evolution/Passwords-%s/%s", component_name, keycopy); + + g_free (keycopy); return path; } @@ -198,7 +162,9 @@ e_passwords_remember_password (const char *key) state = save = 0; base64_encode_close (value, len, FALSE, pass64, &state, &save); - bonobo_config_set_string (db, path, pass64, NULL); + printf ("remembering password for (%s): %s\n", path, pass64); + + gnome_config_private_set_string (path, pass64); g_free (path); g_free (pass64); @@ -206,6 +172,8 @@ e_passwords_remember_password (const char *key) g_hash_table_remove (passwords, key); g_free (okey); g_free (value); + + gnome_config_private_sync_file ("/Evolution"); } /** @@ -218,7 +186,6 @@ void e_passwords_forget_password (const char *key) { gpointer okey, value; - CORBA_Environment ev; char *path; if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) { @@ -230,9 +197,8 @@ e_passwords_forget_password (const char *key) /* clear it in the on disk db */ path = password_path (key); - CORBA_exception_init (&ev); - Bonobo_ConfigDatabase_removeValue (db, path, &ev); - CORBA_exception_free (&ev); + gnome_config_private_clean_key (path); + gnome_config_private_sync_file ("/Evolution"); g_free (path); } @@ -247,24 +213,20 @@ char * e_passwords_get_password (const char *key) { char *path, *passwd = g_hash_table_lookup (passwords, key); - CORBA_Environment ev; - char *encoded; + char *encoded = NULL; if (passwd) return g_strdup (passwd); /* not part of the session hash, look it up in the on disk db */ path = password_path (key); + + encoded = gnome_config_private_get_string_with_default (path, NULL); - /* We need to pass an ev to bonobo-conf, or it will emit a - * g_warning if the data isn't found. - */ - CORBA_exception_init (&ev); - encoded = bonobo_config_get_string (db, path, &ev); - CORBA_exception_free (&ev); + printf ("getting password for (%s): %s\n", path, encoded); g_free (path); - + if (!encoded) return NULL; @@ -301,6 +263,12 @@ e_passwords_add_password (const char *key, const char *passwd) } +static void +entry_activate (GtkEntry *entry, GtkDialog *dialog) +{ + gtk_dialog_response (dialog, GTK_RESPONSE_OK); +} + /** * e_passwords_ask_password: * @title: title for the password dialog @@ -330,30 +298,30 @@ e_passwords_ask_password (const char *title, const char *key, GtkWidget *dialog; GtkWidget *check = NULL, *entry; char *password; - int button; + int response; + + dialog = gtk_message_dialog_new (parent, + 0, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, + prompt); - dialog = gnome_message_box_new (prompt, GNOME_MESSAGE_BOX_QUESTION, - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); gtk_window_set_title (GTK_WINDOW (dialog), title); - if (parent) - gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent); - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gnome_dialog_set_close (GNOME_DIALOG (dialog), FALSE); + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); /* Password entry */ entry = gtk_entry_new(); if (secret) gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), entry, FALSE, FALSE, 4); gtk_widget_show (entry); gtk_widget_grab_focus (entry); - /* If Return is pressed in the text entry, propagate to the buttons */ - gnome_dialog_editable_enters (GNOME_DIALOG(dialog), GTK_EDITABLE(entry)); + g_signal_connect (entry, "activate", + G_CALLBACK (entry_activate), dialog); /* Remember the password? */ if (remember_type != E_PASSWORDS_DO_NOT_REMEMBER) { @@ -367,15 +335,14 @@ e_passwords_ask_password (const char *title, const char *key, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), *remember); - gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (dialog)->vbox), + gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), check, TRUE, FALSE, 4); gtk_widget_show (check); } - gtk_widget_show (dialog); - button = gnome_dialog_run (GNOME_DIALOG (dialog)); + response = gtk_dialog_run (GTK_DIALOG (dialog)); - if (button == 0) { + if (response == GTK_RESPONSE_OK) { password = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); if (remember_type != E_PASSWORDS_DO_NOT_REMEMBER) { *remember = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)); @@ -388,7 +355,8 @@ e_passwords_ask_password (const char *title, const char *key, } else password = NULL; - gnome_dialog_close (GNOME_DIALOG (dialog)); + gtk_widget_destroy (dialog); + return password; } |