Remove unused variables
[claws.git] / src / ldif.c
index aa7c73cebea2884b1226398889cf69f04767cda6..3907802528ffb1dbe9e8b97829c7fc271beb81ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2009 Match Grun and the Claws Mail team
+ * Copyright (C) 2001-2012 Match Grun and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,6 @@
 #include "addritem.h"
 #include "addrcache.h"
 
-#include "base64.h"
 #include "utils.h"
 
 #define        LDIF_SEP_TAG    ':'
@@ -167,8 +166,6 @@ void ldif_field_toggle( Ldif_FieldRec *rec ) {
 */
 static gint ldif_hash_free_vis( gpointer key, gpointer value, gpointer data ) {
        ldif_free_fieldrec( ( Ldif_FieldRec * ) value );
-       value = NULL;
-       key = NULL;
        return -1;
 }
 
@@ -295,7 +292,7 @@ static gchar *ldif_get_tagname( char* line, gboolean *flag64 ) {
        gchar *tag = NULL;
        gchar *lptr = line;
        gchar *sptr = NULL;
-       gchar *down = NULL;
+       
        while( *lptr++ ) {
                /* Check for language tag */
                if( *lptr == LDIF_LANG_TAG ) {
@@ -316,9 +313,7 @@ static gchar *ldif_get_tagname( char* line, gboolean *flag64 ) {
 
                        tag = g_strndup( line, len+1 );
                        tag[ len ] = '\0';
-                       down = g_utf8_strdown( tag, -1 );
-                       g_free(tag);
-                       return down;
+                        return tag;
                }
        }
        return tag;
@@ -528,8 +523,7 @@ static void ldif_add_value(
 {
        gchar *nm, *val;
 
-       nm = g_strdup( tagName );
-       g_utf8_strdown( nm, -1 );
+       nm = g_utf8_strdown( tagName, -1 );
        if( tagValue ) {
                val = g_strdup( tagValue );
        }
@@ -538,19 +532,19 @@ static void ldif_add_value(
        }
        g_strstrip( val );
 
-       if( g_utf8_collate( nm, LDIF_TAG_COMMONNAME ) == 0 ) {
+       if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) {
                rec->listCName = g_slist_append( rec->listCName, val );
        }
-       else if( g_utf8_collate( nm, LDIF_TAG_FIRSTNAME ) == 0 ) {
+       else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) {
                rec->listFName = g_slist_append( rec->listFName, val );
        }
-       else if( g_utf8_collate( nm, LDIF_TAG_LASTNAME ) == 0 ) {
+       else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) {
                rec->listLName = g_slist_append( rec->listLName, val );
        }
-       else if( g_utf8_collate( nm, LDIF_TAG_NICKNAME ) == 0 ) {
+       else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) {
                rec->listNName = g_slist_append( rec->listNName, val );
        }
-       else if( g_utf8_collate( nm, LDIF_TAG_EMAIL ) == 0 ) {
+       else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) {
                rec->listAddress = g_slist_append( rec->listAddress, val );
        }
        else {
@@ -613,6 +607,7 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
        long posEnd = 0L;
        long posCur = 0L;
        GHashTable *hashField;
+       gsize len;
 
        hashField = ldifFile->hashFields;
        rec = g_new0( Ldif_ParsedRec, 1 );
@@ -646,22 +641,10 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                                /* Save record */
                                fullValue = mgu_list_coalesce( listValue );
                                if (fullValue && last64) {
-                                       gchar *out = g_malloc(strlen(fullValue));
-                                       int len = 0;
-                                       if ((len = base64_decode(out, fullValue,
-                                                       strlen(fullValue))) >= 0) {
-                                               g_free(fullValue);
-                                               fullValue = out;
-                                               fullValue[len] = '\0';
-                                       } else
-                                               g_free(out);
-                               }
-                               /* Base-64 encoded data */
-                               /*
-                               if( last64 ) {
-                                       ldif_dump_b64( fullValue );
+                                       gchar *tmp = g_base64_decode_zero(fullValue, &len);
+                                       g_free(fullValue);
+                                       fullValue = tmp;
                                }
-                               */
 
                                ldif_add_value( rec, lastTag, fullValue, hashField );
                                /* ldif_print_record( rec, stdout ); */
@@ -669,6 +652,7 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                                ldif_clear_rec( rec );
                                g_free( lastTag );
                                mgu_free_list( listValue );
+                               g_free(fullValue);
                                lastTag = NULL;
                                listValue = NULL;
                                last64 = FALSE;
@@ -697,15 +681,9 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                                                        fullValue =
                                                                mgu_list_coalesce( listValue );
                                                        if (fullValue && last64) {
-                                                               gchar *out = g_malloc(strlen(fullValue));
-                                                               int len = 0;
-                                                               if ((len = base64_decode(out, fullValue,
-                                                                               strlen(fullValue))) >= 0) {
-                                                                       g_free(fullValue);
-                                                                       fullValue = out;
-                                                                       fullValue[len] = '\0';
-                                                               } else
-                                                                       g_free(out);
+                                                               gchar *tmp = g_base64_decode_zero(fullValue, &len);
+                                                               g_free(fullValue);
+                                                               fullValue = tmp;
                                                        }
                                                        /* Base-64 encoded data */
                                                        /*
@@ -721,7 +699,6 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                                                        mgu_free_list( listValue );
                                                        lastTag = NULL;
                                                        listValue = NULL;
-                                                       last64 = FALSE;
                                                }
 
                                                lastTag = g_strdup( tagName );
@@ -758,30 +735,30 @@ static void ldif_hash_add_list( GHashTable *table, GSList *list ) {
                gchar *tag = node->data;
                if( ! g_hash_table_lookup( table, tag ) ) {
                        Ldif_FieldRec *rec = NULL;
-                       gchar *key = g_strdup( tag );
+                       gchar *key = g_utf8_strdown( tag, -1 );
 
                        rec = ldif_create_fieldrec( tag );
-                       if( g_utf8_collate( tag, LDIF_TAG_DN ) == 0 ) {
+                       if( g_utf8_collate( key, LDIF_TAG_DN ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( "dn" );
                        }
-                       else if( g_utf8_collate( tag, LDIF_TAG_COMMONNAME ) == 0 ) {
+                       else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( _( "Display Name" ) );
                        }
-                       else if( g_utf8_collate( tag, LDIF_TAG_FIRSTNAME ) == 0 ) {
+                       else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( _( "First Name" ) );
                        }
-                       else if( g_utf8_collate( tag, LDIF_TAG_LASTNAME ) == 0 ) {
+                       else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( _( "Last Name" ) );
                        }
-                       else if( g_utf8_collate( tag, LDIF_TAG_NICKNAME ) == 0 ) {
+                       else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( _( "Nick Name" ) );
                        }
-                       else if( g_utf8_collate( tag, LDIF_TAG_EMAIL ) == 0 ) {
+                       else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) {
                                rec->reserved = rec->selected = TRUE;
                                rec->userName = g_strdup( _( "Email Address" ) );
                        }