--- src/syldap.c.ldap_utf8 Thu Jan 3 23:10:11 2002 +++ src/syldap.c Thu Jan 3 23:11:26 2002 @@ -42,6 +42,32 @@ #include "addrcache.h" #include "syldap.h" #include "utils.h" +#include "codeconv.h" + +static void +set_utf8_string_from_local(gchar **var, const gchar *local_str) +{ + gchar *result = conv_codeset_strdup(local_str, + conv_get_current_charset_str(), + CS_UTF_8); + if (!result) { + *var = mgu_replace_string(*var, local_str); + return; + } + g_strstrip(result); + g_free(*var); + *var = result; +} + +static gchar *strdup_local_from_utf8(const gchar *utf8_str) +{ + gchar *result = conv_codeset_strdup(utf8_str, CS_UTF_8, + conv_get_current_charset_str()); + if (result) + return result; + else + return g_strdup(utf8_str); +} /* * Create new LDAP server interface object. @@ -109,8 +135,7 @@ */ void syldap_set_base_dn( SyldapServer* ldapServer, const gchar *value ) { addrcache_refresh( ldapServer->addressCache ); - ldapServer->baseDN = mgu_replace_string( ldapServer->baseDN, value ); - g_strstrip( ldapServer->baseDN ); + set_utf8_string_from_local(&ldapServer->baseDN, value); } /* @@ -118,8 +143,7 @@ */ void syldap_set_bind_dn( SyldapServer* ldapServer, const gchar *value ) { addrcache_refresh( ldapServer->addressCache ); - ldapServer->bindDN = mgu_replace_string( ldapServer->bindDN, value ); - g_strstrip( ldapServer->bindDN ); + set_utf8_string_from_local(&ldapServer->bindDN, value); } /* @@ -127,8 +151,7 @@ */ void syldap_set_bind_password( SyldapServer* ldapServer, const gchar *value ) { addrcache_refresh( ldapServer->addressCache ); - ldapServer->bindPass = mgu_replace_string( ldapServer->bindPass, value ); - g_strstrip( ldapServer->bindPass ); + set_utf8_string_from_local(&ldapServer->bindPass, value); } /* @@ -136,8 +159,7 @@ */ void syldap_set_search_criteria( SyldapServer* ldapServer, const gchar *value ) { addrcache_refresh( ldapServer->addressCache ); - ldapServer->searchCriteria = mgu_replace_string( ldapServer->searchCriteria, value ); - g_strstrip( ldapServer->searchCriteria ); + set_utf8_string_from_local(&ldapServer->searchCriteria, value); ldapServer->newSearch = TRUE; } @@ -146,8 +168,7 @@ */ void syldap_set_search_value( SyldapServer* ldapServer, const gchar *value ) { addrcache_refresh( ldapServer->addressCache ); - ldapServer->searchValue = mgu_replace_string( ldapServer->searchValue, value ); - g_strstrip( ldapServer->searchValue ); + set_utf8_string_from_local(&ldapServer->searchValue, value); ldapServer->newSearch = TRUE; } @@ -419,7 +440,7 @@ if( ( vals = ldap_get_values( ld, entry, attr ) ) != NULL ) { for( i = 0; vals[i] != NULL; i++ ) { /* printf( "lv\t%s: %s\n", attr, vals[i] ); */ - list = g_slist_append( list, g_strdup( vals[i] ) ); + list = g_slist_append( list, strdup_local_from_utf8( vals[i] ) ); } } ldap_value_free( vals ); @@ -436,7 +457,7 @@ if( ( vals = ldap_get_values( ld, entry, attr ) ) != NULL ) { if( vals[0] != NULL ) { /* printf( "sv\t%s: %s\n", attr, vals[0] ); */ - list = g_slist_append( list, g_strdup( vals[0] ) ); + list = g_slist_append( list, strdup_local_from_utf8( vals[0] ) ); } } ldap_value_free( vals ); @@ -814,7 +835,7 @@ if( ( vals = ldap_get_values( ld, e, attribute ) ) != NULL ) { for( i = 0; vals[i] != NULL; i++ ) { /* printf( "\t%s: %s\n", attribute, vals[i] ); */ - baseDN = g_list_append( baseDN, g_strdup( vals[i] ) ); + baseDN = g_list_append( baseDN, strdup_local_from_utf8( vals[i] ) ); } } ldap_value_free( vals ); @@ -855,7 +876,7 @@ gchar *bn = g_strdup( ++ch ); g_strchomp( bn ); g_strchug( bn ); - baseDN = g_list_append( baseDN, g_strdup( bn ) ); + baseDN = g_list_append( baseDN, strdup_local_from_utf8( bn ) ); } } } @@ -943,7 +964,7 @@ if( ( vals = ldap_get_values( ld, e, attribute ) ) != NULL ) { for( i = 0; vals[i] != NULL; i++ ) { /* printf( "\t%s: %s\n", attribute, vals[i] ); */ - baseDN = g_list_append( baseDN, g_strdup( vals[i] ) ); + baseDN = g_list_append( baseDN, strdup_local_from_utf8( vals[i] ) ); } } ldap_value_free( vals ); @@ -986,7 +1007,7 @@ gchar *bn = g_strdup( ++ch ); g_strchomp( bn ); g_strchug( bn ); - baseDN = g_list_append( baseDN, g_strdup( bn ) ); + baseDN = g_list_append( baseDN, strdup_local_from_utf8( bn ) ); } } }