ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/src prefs.c,1.31.2.2,1.31.2.3 prefs.h,1.6.2.


From: Andy Maloney <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src prefs.c,1.31.2.2,1.31.2.3 prefs.h,1.6.2.2,1.6.2.3
Date: Mon, 24 Mar 2003 04:00:20 -0500

Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv9713

Modified Files:
      Tag: new_prefs
        prefs.c prefs.h 
Log Message:
Move reload_service_accounts() to service.c from prefs.[ch]
Remove remaining glib/gtk stiff from prefs.c
Code cleanups


Index: prefs.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/prefs.c,v
retrieving revision 1.31.2.2
retrieving revision 1.31.2.3
diff -u -r1.31.2.2 -r1.31.2.3
--- prefs.c     23 Mar 2003 11:41:57 -0000      1.31.2.2
+++ prefs.c     24 Mar 2003 09:00:18 -0000      1.31.2.3
@@ -26,11 +26,11 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "service.h"
 #include "value_pair.h"
 #include "globals.h"
-#include "dialog.h"
 #include "defaults.h"
 #include "libproxy/libproxy.h"
 #include "prefs_window.h"
@@ -73,6 +73,34 @@
        s_global_prefs = l_list_append( s_global_prefs, PrefData );
 }
 
+static char    *strip_whitespace( char *inStr )
+{
+       char    *ptr = inStr;
+       int             len = strlen( inStr );
+       
+       
+       while ( isspace( *ptr ) )
+               ptr++;
+       
+       if ( ptr != inStr )
+               memmove( inStr, ptr, len - (ptr - inStr) );
+       
+       len = strlen( inStr ) - 1;
+       
+       ptr = inStr + len;
+       
+       while ( isspace( *ptr ) )
+               ptr--;
+       
+       if ( ptr != (inStr + len) )
+       {
+               ptr++;
+               *ptr = '\0';
+       }
+       
+       return( inStr );
+}
+
 
 void   ayttm_prefs_init( void )
 {
@@ -140,7 +168,7 @@
        cSetLocalPref( "SendFilename", SendDefault );
        cSetLocalPref( "ReceiveFilename", ReceiveDefault );
        cSetLocalPref( "FirstMsgFilename", ReceiveDefault );
-               
+
        fSetLocalPref( "SoundVolume", 0.0 );
 
        /* advanced */
@@ -158,15 +186,13 @@
 
 void   ayttm_prefs_read( void )
 {
-       const int       bufferLen = 1024;
-       char            buff[bufferLen];
-       int                     pref_type=0;
-       FILE            *fp = NULL;
-       char            *param = buff;
-       char            *val = buff;
+       const int               buffer_size = 1024;
+       char                    buff[buffer_size];
+       char * const    param = buff;           /* just another name for 
buff... */
+       FILE                    *fp = NULL;
        
-
-       snprintf( buff, bufferLen, "%sprefs",config_dir );
+       
+       snprintf( buff, buffer_size, "%sprefs",config_dir );
        
        fp = fopen( buff, "r" );
        
@@ -177,119 +203,138 @@
                return;
        }
        
+       fgets( param, buffer_size, fp );
+       
        while ( !feof( fp ) )
        {
-               fgets(buff, bufferLen, fp);
-               param=buff;
-               if(feof(fp))
-                       break;
-               g_strstrip(param);
-               pref_type=CORE_PREF;
-               if(!strcasecmp(buff, "plugins"))
-                       pref_type=PLUGIN_PREF;
-               else if(!strcasecmp(buff, "connections"))
-                       pref_type=SERVICE_PREF;
-               if(pref_type!=CORE_PREF)
+               int             pref_type = CORE_PREF;
+               char    *val = buff;
+               
+
+               strip_whitespace( param );
+               
+               if ( !strcasecmp( param, "plugins" ) )
+                       pref_type = PLUGIN_PREF;
+               else if( !strcasecmp( param, "connections" ) )
+                       pref_type = SERVICE_PREF;
+                       
+               if ( pref_type != CORE_PREF )
                {
-                       for(;;)
+                       for (;;)
                        {
-                               int id=-1;
-                               char *plugin_name=NULL;
-                               LList * session_prefs = NULL;
-                               LList *osession_prefs = NULL;
-                               fgets(buff, bufferLen, fp);
-                               param=buff;
-                               g_strstrip(param);
-                               if(!strcasecmp(param, "end"))
-                               {
-                                       break;
-                               }
-                               switch(pref_type) {
-                               case PLUGIN_PREF:
-                                       plugin_name=strdup(param);
-                                       break;
-                               case SERVICE_PREF:
-                                       id = get_service_id(param);
-                                       break;
-                               default:
+                               int             id = -1;
+                               char    *plugin_name = NULL;
+                               LList   *session_prefs = NULL;
+                               
+                               
+                               fgets( param, buffer_size, fp );
+                               
+                               strip_whitespace( param );
+                               
+                               if ( !strcasecmp( param, "end" ) )
                                        break;
+
+                               switch( pref_type )
+                               {
+                                       case PLUGIN_PREF:
+                                               plugin_name = strdup( param );
+                                               break;
+                                               
+                                       case SERVICE_PREF:
+                                               id = get_service_id( param );
+                                               break;
+                                               
+                                       default:
+                                               break;
                                }
 
-                               for(;;)
+                               for (;;)
                                {
-                                       fgets(buff, bufferLen, fp);
-                                       param=buff;
-                                       g_strstrip(param);
-                                       if(!strcasecmp(param, "end"))
+                                       LList   *old_session_prefs = NULL;
+                               
+                                       
+                                       fgets( param, buffer_size, fp );
+                                       
+                                       strip_whitespace( param );
+                                       
+                                       if ( !strcasecmp( param, "end" ) )
                                        {
-                                               switch(pref_type) {
-                                               case PLUGIN_PREF:
-                                                       osession_prefs = 
SetPref(plugin_name, session_prefs);
-                                                       if(osession_prefs)
-                                                       {
-                                                               
eb_debug(DBG_CORE, "Freeing osession_prefs\n");
-                                                               
value_pair_free(osession_prefs);
-                                                       }
-                                                       free(plugin_name);
-                                                       break;
-                                               case SERVICE_PREF:
-                                                       osession_prefs = 
SetPref(get_service_name(id), session_prefs);
-                                                       if(osession_prefs)
-                                                       {
-                                                               
eb_debug(DBG_CORE, "Freeing osession_prefs\n");
-                                                               
value_pair_free(osession_prefs);
-                                                       }
-                                                       break;
-                                               default:
-                                                       eb_debug(DBG_CORE, 
"Error!  We're not supposed to ever get here!\n");
-                                                       break;
+                                               switch( pref_type )
+                                               {
+                                                       case PLUGIN_PREF:
+                                                               
old_session_prefs = SetPref( plugin_name, session_prefs );
+                                                               
+                                                               free( 
plugin_name );
+                                                               break;
+                                                               
+                                                       case SERVICE_PREF:
+                                                               
old_session_prefs = SetPref( get_service_name(id), session_prefs );
+                                                               break;
+                                                               
+                                                       default:
+                                                               
eb_debug(DBG_CORE, "Error!  We're not supposed to ever get here!\n");
+                                                               break;
+                                               }
+                                               
+                                               if ( old_session_prefs != NULL )
+                                               {
+                                                       eb_debug(DBG_CORE, 
"Freeing old_session_prefs\n");
+                                                       value_pair_free( 
old_session_prefs );
                                                }
+                                               
                                                break;
                                        }
                                        else
                                        {
-                                               val=param;
+                                               val = param;
 
-                                               while(*val != 0 && *val !='=')
+                                               while ( *val != 0 && *val != 
'=' )
                                                        val++;
-                                               if(*val=='=')
+                                                       
+                                               if ( *val == '=' )
                                                {
-                                                       *val='\0';
+                                                       *val = '\0';
                                                        val++;
                                                }
 
-                                               /*
-                                               * if quoted strip off the quotes
-                                               */
-
-                                               if(*val == '"')
+                                               /* strip off quotes */
+                                               if ( *val == '"' )
                                                {
                                                        val++;
                                                        val[strlen(val)-1] = 
'\0';
                                                }
+                                               
                                                eb_debug(DBG_CORE,"Adding %s:%s 
to session_prefs\n", param, val);
-                                               session_prefs = 
value_pair_add(session_prefs, param, val);
+                                               session_prefs = value_pair_add( 
session_prefs, param, val );
                                        }
                                }
                        }
                        continue;
                } /* if(pref_type != CORE_PREF) */
-               val=param;
+               
+               val = param;
 
-               while(*val != 0 && *val !='=')
+               while ( *val != 0 && *val != '=' )
                        val++;
-               if(*val=='=')
+                       
+               if ( *val == '=' )
                {
-                       *val='\0';
+                       *val = '\0';
                        val++;
                }
-               cSetLocalPref(param, val);
+               
+               cSetLocalPref( param, val );
+               
+               fgets( param, buffer_size, fp );
        }
        
-       fclose(fp);
+       fclose( fp );
 
-       proxy_set_proxy(iGetLocalPref("proxy_type"), 
cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port"));
-       proxy_set_auth(iGetLocalPref("do_proxy_auth"), 
cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password"));
+       if ( iGetLocalPref("proxy_type") != 0 )
+       {
+               proxy_set_proxy( iGetLocalPref("proxy_type"), 
cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port") );
+               proxy_set_auth( iGetLocalPref("do_proxy_auth"), 
cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password") );
+       }
 }
 
 void   ayttm_prefs_write( void )
@@ -380,11 +425,10 @@
        fprintf( fp, "remote_encoding=%s\n", cGetLocalPref("remote_encoding") );
         
        fprintf( fp, "end\n" );
+       
        fclose( fp );
 
        rename( buff, file );
-
-       ayttm_prefs_read();
 }
 
 void   ayttm_prefs_show_window( void )
@@ -524,8 +568,8 @@
        
        if ( inPrefs.advanced.proxy_type != 0 )
        {
-               proxy_set_proxy(iGetLocalPref("proxy_type"), 
cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port"));
-               proxy_set_auth(iGetLocalPref("do_proxy_auth"), 
cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password"));
+               proxy_set_proxy( iGetLocalPref("proxy_type"), 
cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port") );
+               proxy_set_auth( iGetLocalPref("do_proxy_auth"), 
cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password") );
        }
 }
 
@@ -620,52 +664,16 @@
 
 /* Used when loading service modules later, so passwords and user names are 
still available
  * as service:username */
-void save_account_info(char *service, LList *pairs)
+void   save_account_info( const char *service, LList *pairs )
 {
        const int       buffer_size = 256;
        char            buff[buffer_size];
-       char            *val = value_pair_get_value(pairs, "SCREEN_NAME");
+       char            *val = value_pair_get_value( pairs, "SCREEN_NAME" );
        
-       snprintf(buff, buffer_size, "%s:%s", service, val);
-       free(val);
-       SetPref(buff, pairs);
-}
-
-void reload_service_accounts(int service_id)
-{
-       LList                           *node = accounts;
-       LList                           *account_pairs = NULL;
-       eb_local_account        *oela = NULL;
-       eb_local_account        *nela = NULL;
-       const int                       buffer_size = 256;
-       char                            buff[buffer_size];
-       char                            buff2[buffer_size];
-
-       while(node)
-       {
-               oela=node->data;
-               if(oela->service_id != service_id || oela->connected) {
-                       node = node->next;
-                       continue;
-               }
-               eb_debug(DBG_CORE, "Account: handle:%s service: %s\n", 
oela->handle, get_service_name(oela->service_id));
-               snprintf(buff, buffer_size, "%s:%s", 
get_service_name(oela->service_id), oela->handle);
-               account_pairs = GetPref(buff);
-               nela = 
eb_services[oela->service_id].sc->read_local_account_config(account_pairs);
-               if(!nela) {
-                       snprintf(buff2, buffer_size, _("Unable to create 
account for %s.\nCheck your config file."), buff);
-                       do_error_dialog(buff2, _("Invalid account"));
-                       oela->service_id=get_service_id("NO SERVICE");
-               }
-               else {
-                       nela->service_id = oela->service_id;
-                       node->data=nela;
-                       //FIXME: This should probably be left to the service to 
clean up, though at this point, it may not exist
-                       free(oela->handle);
-                       free(oela->protocol_local_account_data);
-                       free(oela);
-               }
-               node = node->next;
-       }
+       snprintf( buff, buffer_size, "%s:%s", service, val );
+       
+       free( val );
+       
+       SetPref( buff, pairs );
 }
 

Index: prefs.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/prefs.h,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -r1.6.2.2 -r1.6.2.3
--- prefs.h     23 Mar 2003 11:41:57 -0000      1.6.2.2
+++ prefs.h     24 Mar 2003 09:00:18 -0000      1.6.2.3
@@ -140,8 +140,7 @@
 void   cSetLocalPref(const char *key, char *data);
 char   *cGetLocalPref(const char *key);
 
-void   save_account_info(char *service, LList *pairs);
-void   reload_service_accounts(int service_id);
+void   save_account_info( const char *service, LList *pairs );
 
 #ifdef __cplusplus
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]