changeset 228:f3b61c04f44e

[gaim-migrate @ 238] Buddy lists (and changes) are cached to ~/.gaimbdcache_<sn> where <sn> is your screen name (folder to uppercase). If for some reason, you log into the AOL server and the buddy list comes back empty, we check for a cache file, and, if we find one, read it in. This essentially implements recovery from a server crash at AOL (AOL does not back up machines that contain TOC-based buddy lists, unfortunately). committer: Tailor Script <tailor@pidgin.im>
author Syd Logan <slogan>
date Wed, 10 May 2000 07:41:25 +0000
parents fb8e65df5fe7
children e8ea7f37e28f
files src/aim.c src/buddy.c src/dialogs.c src/toc.c
diffstat 4 files changed, 113 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/aim.c	Wed May 10 07:37:56 2000 +0000
+++ b/src/aim.c	Wed May 10 07:41:25 2000 +0000
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include "gaim.h"
 #ifndef USE_APPLET
 #include "pixmaps/logo.xpm"
@@ -117,11 +118,14 @@
 	gtk_timeout_remove(snd_tmout);
 }
 
+char g_screenname[ 64 ];	/* gotta be enough */
+
 void dologin(GtkWidget *widget, GtkWidget *w)
 {
 	static gboolean running = FALSE;
 	char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry));
         char *password = gtk_entry_get_text(GTK_ENTRY(pass));
+	int i;
 
         if (query_state() != STATE_OFFLINE)
                 return;
@@ -135,6 +139,16 @@
 		return;
 	}
 
+	/* save screenname away for cache file use */
+
+	strcpy( g_screenname, username );
+
+	/* fold cache screen name file to upper case to avoid problems
+	   finding file later if user uses different case at login time */
+
+	for ( i = 0; i < strlen( g_screenname ); i++ )
+		g_screenname[i] = toupper( g_screenname[i] );
+
 #ifdef USE_APPLET
 	set_applet_draw_closed();
 	setUserState(signing_on);
--- a/src/buddy.c	Wed May 10 07:37:56 2000 +0000
+++ b/src/buddy.c	Wed May 10 07:41:25 2000 +0000
@@ -484,6 +484,10 @@
         g_free(delb);
 
         serv_save_config();
+
+	// flush buddy list to cache
+
+	do_export( (GtkWidget *) NULL, 0 );
         
 	update_num_groups();
 
@@ -516,6 +520,10 @@
 	g_free(delg);
 
         serv_save_config();
+
+        // flush buddy list to cache
+
+        do_export( (GtkWidget *) NULL, 0 );
 }
 
 
@@ -754,6 +762,10 @@
         }
 
         serv_save_config();
+
+        // flush buddy list to cache
+
+        do_export( (GtkWidget *) NULL, 0 );
 }
 
 
@@ -935,6 +947,11 @@
                 
                 build_edit_tree();
                 serv_save_config();
+
+        	// flush buddy list to cache
+
+        	do_export( (GtkWidget *) NULL, 0 );
+
         } else {
                 /* Nothing selected. */
         }
--- a/src/dialogs.c	Wed May 10 07:37:56 2000 +0000
+++ b/src/dialogs.c	Wed May 10 07:41:25 2000 +0000
@@ -676,6 +676,8 @@
 
         serv_add_buddy(who);
 
+	do_export( (GtkWidget *) NULL, 0 );
+
         update_num_groups();
 
         destroy_dialog(NULL, a->window);
@@ -1934,27 +1936,46 @@
 /*  The dialog for import/export                                          */
 /*------------------------------------------------------------------------*/
 
+#define PATHSIZE 1024
+
+/* if dummy is 0, save to ~/.gaimbdcache_screenname */
+
 void do_export(GtkWidget *w, void *dummy)
 {
         FILE *f;
+	gint show_dialog = (int) dummy;
         char *buf = g_malloc(BUF_LONG);
-        char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(exportdialog));
+        char *file;
+	char path[PATHSIZE];
+	extern char g_screenname[];
 
-        if ((f = fopen(file,"w"))) {
-                toc_build_config(buf, BUF_LONG - 1);
+	if ( show_dialog == 1 ) {
+		file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(exportdialog));
+		strncpy( path, file, PATHSIZE - 1 );
+	}
+	else {
+		file = getenv( "HOME" );
+		if ( file != (char *) NULL )
+                        sprintf( path, "%s/.gaimbdcache_%s", file, g_screenname );
+		else
+			return;
+	}
+        if ((f = fopen(path,"w"))) {
+                toc_build_config(buf, 1024 - 1);
                 fprintf(f, "%s\n", buf);
                 fclose(f);
                 chmod(buf, S_IRUSR | S_IWUSR);
-        } else {
+        } else if ( show_dialog == 1 ) {
                 g_snprintf(buf, BUF_LONG / 2, "Error writing file %s", file);
                 do_error_dialog(buf, "Error");
         }
-        destroy_dialog(NULL, exportdialog);
-        exportdialog = NULL;
+	if ( show_dialog == 1 ) {
+        	destroy_dialog(NULL, exportdialog);
+        	exportdialog = NULL;
+	}
         
         g_free(buf);
         
-        
 }
 
 	
@@ -1973,7 +1994,7 @@
                                    GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
                 
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->ok_button),
-                                   "clicked", GTK_SIGNAL_FUNC(do_export), NULL);
+                                   "clicked", GTK_SIGNAL_FUNC(do_export), 1);
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->cancel_button),
                                    "clicked", GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
                 
@@ -1987,20 +2008,39 @@
 
 }
 
+/* if dummy is 0, then import from ~/.gaimbdcache_screenname */
+
 void do_import(GtkWidget *w, void *dummy)
 {
+	gint show_dialog = (int) dummy;
         GList *grp, *grp2;
         char *buf = g_malloc(BUF_LONG);
         char *buf2;
         char *first = g_malloc(64);
-        char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
+	char *file;
+	char path[PATHSIZE];
         FILE *f;
-        
-        if (!(f = fopen(file,"r"))) {
-                g_snprintf(buf, BUF_LONG / 2, "Error reading file %s", file);
-                do_error_dialog(buf, "Error");
-                destroy_dialog(NULL, importdialog);
-                importdialog = NULL;
+	extern char g_screenname[];
+
+        if ( show_dialog == 1 ) {
+        	file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
+                strncpy( path, file, PATHSIZE - 1 );
+        }
+        else {
+                file = getenv( "HOME" );
+                if ( file != (char *) NULL )
+                        sprintf( path, "%s/.gaimbdcache_%s", file, g_screenname );
+                else
+			return;
+        }
+
+        if (!(f = fopen(path,"r"))) {
+		if ( show_dialog == 1 ) {
+                	g_snprintf(buf, BUF_LONG / 2, "Error reading file %s", file);
+                	do_error_dialog(buf, "Error");
+                	destroy_dialog(NULL, importdialog);
+                	importdialog = NULL;
+		}
                 g_free(buf);
 		g_free(first);
                 return;
@@ -2009,10 +2049,13 @@
         fgets(first, 64, f);
 
         if (!strcasecmp(first, "Config {\n")) {
-                destroy_dialog(NULL, importdialog);
-                importdialog = NULL;
+		if ( show_dialog == 1 ) {
+                	destroy_dialog(NULL, importdialog);
+                	importdialog = NULL;
+		}
 		g_free(buf);
 		g_free(first);
+		fclose( f );
                 return;
         } else if (buf[0] == 'm') {
                 buf2 = buf;
@@ -2041,12 +2084,18 @@
         build_edit_tree();
         build_permit_tree();
         
-        destroy_dialog(NULL, importdialog);
-        importdialog = NULL;
+	fclose( f );
+
+	if ( show_dialog == 1 ) {
+		/* save what we just did to cache */
+
+		do_export( (GtkWidget *) NULL, 0 );
+               	destroy_dialog(NULL, importdialog);
+               	importdialog = NULL;
+	} 
         
         g_free(buf);
         g_free(first);
-	
 }
 
 void show_import_dialog()
@@ -2064,7 +2113,7 @@
                                    GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
                 
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button),
-                                   "clicked", GTK_SIGNAL_FUNC(do_import), NULL);
+                                   "clicked", GTK_SIGNAL_FUNC(do_import), 1);
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button),
                                    "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
                 
--- a/src/toc.c	Wed May 10 07:37:56 2000 +0000
+++ b/src/toc.c	Wed May 10 07:41:25 2000 +0000
@@ -849,13 +849,14 @@
         char current[256];
 	char *name;
 	GList *bud;
+	int how_many = 0;
+
         /* Clean out the permit/deny list!*/
         g_list_free(permit);
         g_list_free(deny);
         permit = NULL;
 	deny = NULL;
 	bud = NULL;
-
         
         /* skip "CONFIG:" (if it exists)*/
 
@@ -868,8 +869,10 @@
 		if (*c == 'g') {
 			strncpy(current,c+2, sizeof(current));
 			add_group(current);
+			how_many++;
 		} else if (*c == 'b') {
 			add_buddy(current, c+2);
+			how_many++;
 			bud = g_list_append(bud, c+2);
         } else if (*c == 'p') {
             name = g_malloc(strlen(c+2) + 2);
@@ -888,7 +891,14 @@
 #if 0
 	fprintf(stdout, "Sending message '%s'\n",buf);
 #endif
-       
+      
 	serv_add_buddies(bud);
         serv_set_permit_deny();
+
+	/* perhaps the server dropped the buddy list, try importing from
+           cache */
+
+	if ( how_many == 0 ) {
+		do_import( (GtkWidget *) NULL, 0 );
+	}
  }