*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
*/
#include <glib.h>
+#include <glib/gi18n.h>
#include <string.h>
#include <sys/stat.h>
-#include "intl.h"
#include "mgutils.h"
#include "ldif.h"
#include "addritem.h"
#include "addrcache.h"
#include "base64.h"
+#include "utils.h"
#define LDIF_SEP_TAG ':'
#define LDIF_LANG_TAG ';'
static gint ldif_open_file( LdifFile* ldifFile ) {
/* printf( "Opening file\n" ); */
if( ldifFile->path ) {
- ldifFile->file = fopen( ldifFile->path, "rb" );
+ ldifFile->file = g_fopen( ldifFile->path, "rb" );
if( ! ldifFile->file ) {
/* printf( "can't open %s\n", ldifFile->path ); */
ldifFile->retVal = MGU_OPEN_FILE;
static gchar *ldif_get_line( LdifFile *ldifFile ) {
gchar buf[ LDIFBUFSIZE ];
gint ch;
- gchar *ptr;
+ int i = 0;
- if( feof( ldifFile->file ) ) return NULL;
+ if( feof( ldifFile->file ) )
+ return NULL;
- ptr = buf;
- while( TRUE ) {
- *ptr = '\0';
+ while( i < LDIFBUFSIZE-1 ) {
ch = fgetc( ldifFile->file );
if( ch == '\0' || ch == EOF ) {
- if( *buf == '\0' ) return NULL;
+ if( i == 0 ) return NULL;
break;
}
#if HAVE_DOSISH_SYSTEM
#else
- if( ch == '\r' ) continue;
+ if( ch == '\r' )
+ continue;
#endif
- if( ch == '\n' ) break;
- *ptr = ch;
- ptr++;
+ if( ch == '\n' )
+ break;
+ buf[i] = ch;
+ i++;
}
+ buf[i] = '\0';
/* Return a copy of buffer */
return g_strdup( buf );
fullName = g_strdup_printf( "%s", lastName );
}
}
+
+ if (!fullName || strlen(fullName) == 0) {
+ g_free(fullName);
+ fullName = NULL;
+ if (rec->listCName)
+ fullName = g_strdup(rec->listCName->data);
+ }
+
if( fullName ) {
g_strchug( fullName ); g_strchomp( fullName );
}
}
g_strstrip( val );
- if( g_strcasecmp( nm, LDIF_TAG_COMMONNAME ) == 0 ) {
+ if( g_utf8_collate( nm, LDIF_TAG_COMMONNAME ) == 0 ) {
rec->listCName = g_slist_append( rec->listCName, val );
}
- else if( g_strcasecmp( nm, LDIF_TAG_FIRSTNAME ) == 0 ) {
+ else if( g_utf8_collate( nm, LDIF_TAG_FIRSTNAME ) == 0 ) {
rec->listFName = g_slist_append( rec->listFName, val );
}
- else if( g_strcasecmp( nm, LDIF_TAG_LASTNAME ) == 0 ) {
+ else if( g_utf8_collate( nm, LDIF_TAG_LASTNAME ) == 0 ) {
rec->listLName = g_slist_append( rec->listLName, val );
}
- else if( g_strcasecmp( nm, LDIF_TAG_NICKNAME ) == 0 ) {
+ else if( g_utf8_collate( nm, LDIF_TAG_NICKNAME ) == 0 ) {
rec->listNName = g_slist_append( rec->listNName, val );
}
- else if( g_strcasecmp( nm, LDIF_TAG_EMAIL ) == 0 ) {
+ else if( g_utf8_collate( nm, LDIF_TAG_EMAIL ) == 0 ) {
rec->listAddress = g_slist_append( rec->listAddress, val );
}
else {
if( lastTag ) {
/* 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 ) {
/* Save data */
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 ) {
gchar *key = g_strdup( tag );
rec = ldif_create_fieldrec( tag );
- if( g_strcasecmp( tag, LDIF_TAG_DN ) == 0 ) {
+ if( g_utf8_collate( tag, LDIF_TAG_DN ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( "dn" );
}
- else if( g_strcasecmp( tag, LDIF_TAG_COMMONNAME ) == 0 ) {
+ else if( g_utf8_collate( tag, LDIF_TAG_COMMONNAME ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( _( "Display Name" ) );
}
- else if( g_strcasecmp( tag, LDIF_TAG_FIRSTNAME ) == 0 ) {
+ else if( g_utf8_collate( tag, LDIF_TAG_FIRSTNAME ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( _( "First Name" ) );
}
- else if( g_strcasecmp( tag, LDIF_TAG_LASTNAME ) == 0 ) {
+ else if( g_utf8_collate( tag, LDIF_TAG_LASTNAME ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( _( "Last Name" ) );
}
- else if( g_strcasecmp( tag, LDIF_TAG_NICKNAME ) == 0 ) {
+ else if( g_utf8_collate( tag, LDIF_TAG_NICKNAME ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( _( "Nick Name" ) );
}
- else if( g_strcasecmp( tag, LDIF_TAG_EMAIL ) == 0 ) {
+ else if( g_utf8_collate( tag, LDIF_TAG_EMAIL ) == 0 ) {
rec->reserved = rec->selected = TRUE;
rec->userName = g_strdup( _( "E-Mail Address" ) );
}
return -1;
}
}
- return g_strcasecmp( rec1->tagName, rec2->tagName );
+ return g_utf8_collate( rec1->tagName, rec2->tagName );
}
/*
/* Process file */
while( ! flagEOF ) {
gchar *line = ldif_get_line( ldifFile );
-
posCur = ftell( ldifFile->file );
if( ldifFile->cbProgress ) {
/* Call progress indicator */
if( tagName ) {
/* Add tag to list */
listTags = g_slist_append( listTags, tagName );
- if( g_strcasecmp(
+
+ if( g_utf8_collate(
tagName, LDIF_TAG_EMAIL ) == 0 )
{
flagMail = TRUE;