2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2012 Match Grun and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Functions necessary to access LDIF files (LDAP Data Interchange Format
26 #include <glib/gi18n.h>
33 #include "addrcache.h"
37 #define LDIF_SEP_TAG ':'
38 #define LDIF_LANG_TAG ';'
42 * \return Initialized LDIF file object.
44 LdifFile *ldif_create() {
46 ldifFile = g_new0( LdifFile, 1 );
47 ldifFile->path = NULL;
48 ldifFile->file = NULL;
49 ldifFile->hashFields = g_hash_table_new( g_str_hash, g_str_equal );
50 ldifFile->tempList = NULL;
51 ldifFile->dirtyFlag = TRUE;
52 ldifFile->accessFlag = FALSE;
53 ldifFile->retVal = MGU_SUCCESS;
54 ldifFile->cbProgress = NULL;
55 ldifFile->importCount = 0;
60 * Specify full file specification of LDIF file.
61 * \param ldifFile LDIF import control object.
62 * \param value Value of access flag.
64 void ldif_set_file( LdifFile *ldifFile, const gchar *value ) {
65 cm_return_if_fail( ldifFile != NULL );
67 if( ldifFile->path ) {
68 if( strcmp( ldifFile->path, value ) != 0 )
69 ldifFile->dirtyFlag = TRUE;
72 ldifFile->dirtyFlag = TRUE;
74 ldifFile->path = mgu_replace_string( ldifFile->path, value );
75 g_strstrip( ldifFile->path );
76 ldifFile->importCount = 0;
80 * Set the file access indicator.
81 * \param ldifFile LDIF import control object.
82 * \param value File specification.
84 void ldif_set_accessed( LdifFile *ldifFile, const gboolean value ) {
85 cm_return_if_fail( ldifFile != NULL );
86 ldifFile->accessFlag = value;
90 * Create field record object.
91 * \return Initialized LDIF field object.
93 static Ldif_FieldRec *ldif_create_fieldrec( const gchar *field ) {
94 Ldif_FieldRec *rec = g_new0( Ldif_FieldRec, 1 );
95 rec->tagName = g_strdup( field );
97 rec->reserved = FALSE;
98 rec->selected = FALSE;
103 * Free field record object.
104 * \param rec LDIF field object.
106 static void ldif_free_fieldrec( Ldif_FieldRec *rec ) {
108 g_free( rec->tagName );
109 g_free( rec->userName );
111 rec->userName = NULL;
112 rec->reserved = FALSE;
113 rec->selected = FALSE;
119 * Set user name for field record.
120 * \param rec LDIF field object.
121 * \param value User name to set. Note that reserved fields cannot be
124 void ldif_field_set_name( Ldif_FieldRec *rec, const gchar *value ) {
125 cm_return_if_fail( rec != NULL );
127 if( ! rec->reserved ) {
128 rec->userName = mgu_replace_string( rec->userName, value );
129 g_strstrip( rec->userName );
134 * Specify selection for field record.
135 * \param rec LDIF field object.
136 * \param value Set to <i>TRUE</i> to select field. Note that reserved
137 * fields cannot be unselected.
139 void ldif_field_set_selected( Ldif_FieldRec *rec, const gboolean value ) {
140 cm_return_if_fail( rec != NULL );
142 if( ! rec->reserved ) {
143 rec->selected = value;
148 * Toggle selection for field record. Note that reserved fields cannot be
150 * \param rec LDIF field object.
152 void ldif_field_toggle( Ldif_FieldRec *rec ) {
153 cm_return_if_fail( rec != NULL );
155 if( ! rec->reserved ) {
156 rec->selected = !rec->selected;
161 * Free hash table entry visitor function.
163 * \param value Value (the LDIF field record).
164 * \param data User data.
165 * \return <code>-1</code>.
167 static gint ldif_hash_free_vis( gpointer key, gpointer value, gpointer data ) {
168 ldif_free_fieldrec( ( Ldif_FieldRec * ) value );
173 * Free up object by releasing internal memory.
174 * \param ldifFile LDIF import control object.
176 void ldif_free( LdifFile *ldifFile ) {
177 cm_return_if_fail( ldifFile != NULL );
180 if( ldifFile->file ) fclose( ldifFile->file );
182 /* Free internal stuff */
183 g_free( ldifFile->path );
185 /* Free field list */
186 g_hash_table_foreach_remove( ldifFile->hashFields, ldif_hash_free_vis, NULL );
187 g_hash_table_destroy( ldifFile->hashFields );
188 ldifFile->hashFields = NULL;
191 ldifFile->file = NULL;
192 ldifFile->path = NULL;
193 ldifFile->retVal = MGU_SUCCESS;
194 ldifFile->tempList = NULL;
195 ldifFile->dirtyFlag = FALSE;
196 ldifFile->accessFlag = FALSE;
197 ldifFile->cbProgress = NULL;
199 /* Now release file object */
204 * Open file for read.
205 * \param ldifFile LDIF import control object.
206 * \return <i>TRUE</i> if file opened successfully.
208 static gint ldif_open_file( LdifFile* ldifFile ) {
209 /* g_print( "Opening file\n" ); */
210 if( ldifFile->path ) {
211 ldifFile->file = g_fopen( ldifFile->path, "rb" );
212 if( ! ldifFile->file ) {
213 /* g_print( "can't open %s\n", ldifFile->path ); */
214 ldifFile->retVal = MGU_OPEN_FILE;
215 return ldifFile->retVal;
219 /* g_print( "file not specified\n" ); */
220 ldifFile->retVal = MGU_NO_FILE;
221 return ldifFile->retVal;
224 /* Setup a buffer area */
225 ldifFile->retVal = MGU_SUCCESS;
226 return ldifFile->retVal;
231 * \param ldifFile LDIF import control object.
233 static void ldif_close_file( LdifFile *ldifFile ) {
234 cm_return_if_fail( ldifFile != NULL );
235 if( ldifFile->file ) fclose( ldifFile->file );
236 ldifFile->file = NULL;
240 * Read line of text from file.
241 * \param ldifFile LDIF import control object.
242 * \return ptr to buffer where line starts.
244 static gchar *ldif_get_line( LdifFile *ldifFile ) {
245 gchar *buf = g_malloc(LDIFBUFSIZE);
248 int cur_alloc = LDIFBUFSIZE;
250 if( feof( ldifFile->file ) ) {
255 while( i < cur_alloc-1 ) {
256 ch = fgetc( ldifFile->file );
257 if (ferror( ldifFile->file ))
258 ldifFile->retVal = MGU_ERROR_READ;
259 if( ch == '\0' || ch == EOF ) {
260 if( i == 0 ) return NULL;
263 #if HAVE_DOSISH_SYSTEM
272 if (i == cur_alloc-1 && cur_alloc < LDIFBUFSIZE * 32) {
273 cur_alloc += LDIFBUFSIZE;
274 buf = g_realloc(buf, cur_alloc);
279 /* Return a copy of buffer */
280 return g_strdup( buf );
284 * Parse tag name from line buffer.
285 * \param line Buffer.
286 * \param flag64 Base-64 encoder flag.
287 * \return Buffer containing the tag name, or NULL if no delimiter char found.
288 * If a double delimiter (::) is found, flag64 is set.
290 static gchar *ldif_get_tagname( char* line, gboolean *flag64 ) {
297 /* Check for language tag */
298 if( *lptr == LDIF_LANG_TAG ) {
299 if( sptr == NULL ) sptr = lptr;
302 /* Check for delimiter */
303 if( *lptr == LDIF_SEP_TAG ) {
311 /* Base-64 encoding? */
312 if( * ++lptr == LDIF_SEP_TAG ) *flag64 = TRUE;
314 tag = g_strndup( line, len+1 );
323 * Parse tag value from line buffer.
324 * \param line Buffer.
325 * \return Buffer containing the tag value. Empty string is returned if
326 * no delimiter char found.
328 static gchar *ldif_get_tagvalue( gchar* line ) {
334 for( lptr = line; *lptr; lptr++ ) {
335 if( *lptr == LDIF_SEP_TAG ) {
341 if( *start == LDIF_SEP_TAG ) start++;
343 value = g_strndup( start, len+1 );
347 /* Ensure that we get an empty string */
348 value = g_strndup( "", 1 );
355 * Parsed address data record.
357 typedef struct _Ldif_ParsedRec_ Ldif_ParsedRec;
358 struct _Ldif_ParsedRec_ {
369 * User attribute data record.
371 typedef struct _Ldif_UserAttr_ Ldif_UserAttr;
372 struct _Ldif_UserAttr_ {
378 * Build an address list entry and append to list of address items in the
379 * address cache. Name is formatted as "<first-name> <last-name>".
380 * \param ldifFile LDIF import control object.
381 * \param rec LDIF field object.
382 * \param cache Address cache to be populated with data.
384 static void ldif_build_items(
385 LdifFile *ldifFile, Ldif_ParsedRec *rec, AddressCache *cache )
390 gchar *firstName = NULL, *lastName = NULL, *fullName = NULL;
391 gchar *nickName = NULL;
392 gint iLen = 0, iLenT = 0;
396 nodeAddress = rec->listAddress;
397 // if( nodeAddress == NULL ) return;
399 /* Find longest first name in list */
400 nodeFirst = rec->listFName;
402 if( firstName == NULL ) {
403 firstName = nodeFirst->data;
404 iLen = strlen( firstName );
407 if( ( iLenT = strlen( nodeFirst->data ) ) > iLen ) {
408 firstName = nodeFirst->data;
412 nodeFirst = g_slist_next( nodeFirst );
416 if( rec->listLName ) {
417 lastName = rec->listLName->data;
422 fullName = g_strdup_printf(
423 "%s %s", firstName, lastName );
426 fullName = g_strdup_printf( "%s", firstName );
431 fullName = g_strdup_printf( "%s", lastName );
435 if (!fullName || strlen(fullName) == 0) {
439 fullName = g_strdup(rec->listCName->data);
443 g_strchug( fullName ); g_strchomp( fullName );
446 if( rec->listNName ) {
447 nickName = rec->listNName->data;
450 person = addritem_create_item_person();
451 addritem_person_set_common_name( person, fullName );
452 addritem_person_set_first_name( person, firstName );
453 addritem_person_set_last_name( person, lastName );
454 addritem_person_set_nick_name( person, nickName );
455 addrcache_id_person( cache, person );
456 addrcache_add_person( cache, person );
457 ++ldifFile->importCount;
459 /* Add address item */
460 while( nodeAddress ) {
461 email = addritem_create_item_email();
462 addritem_email_set_address( email, nodeAddress->data );
463 addrcache_id_email( cache, email );
464 addrcache_person_add_email( cache, person, email );
465 nodeAddress = g_slist_next( nodeAddress );
468 fullName = firstName = lastName = NULL;
470 /* Add user attributes */
471 nodeAttr = rec->userAttr;
473 Ldif_UserAttr *attr = nodeAttr->data;
474 UserAttribute *attrib = addritem_create_attribute();
475 addritem_attrib_set_name( attrib, attr->name );
476 addritem_attrib_set_value( attrib, attr->value );
477 addritem_person_add_attribute( person, attrib );
478 nodeAttr = g_slist_next( nodeAttr );
484 * Add selected field as user attribute.
485 * \param rec LDIF field object.
486 * \param tagName LDIF tag name.
487 * \param tagValue Data value.
488 * \param hashField Hash table to populate.
490 static void ldif_add_user_attr(
491 Ldif_ParsedRec *rec, gchar *tagName, gchar *tagValue,
492 GHashTable *hashField )
494 Ldif_FieldRec *fld = NULL;
495 Ldif_UserAttr *attr = NULL;
498 fld = g_hash_table_lookup( hashField, tagName );
500 if( ! fld->selected ) return;
503 if( fld->userName ) {
504 name = fld->userName;
506 attr = g_new0( Ldif_UserAttr, 1 );
507 attr->name = g_strdup( name );
508 attr->value = g_strdup( tagValue );
509 rec->userAttr = g_slist_append( rec->userAttr, attr );
514 * Add value to parsed data.
515 * \param rec LDIF field object.
516 * \param tagName LDIF tag name.
517 * \param tagValue Data value.
518 * \param hashField Hash table to populate.
520 static void ldif_add_value(
521 Ldif_ParsedRec *rec, gchar *tagName, gchar *tagValue,
522 GHashTable *hashField )
526 nm = g_utf8_strdown( tagName, -1 );
528 val = g_strdup( tagValue );
531 val = g_strdup( "" );
535 if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) {
536 rec->listCName = g_slist_append( rec->listCName, val );
538 else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) {
539 rec->listFName = g_slist_append( rec->listFName, val );
541 else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) {
542 rec->listLName = g_slist_append( rec->listLName, val );
544 else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) {
545 rec->listNName = g_slist_append( rec->listNName, val );
547 else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) {
548 rec->listAddress = g_slist_append( rec->listAddress, val );
551 /* Add field as user attribute */
552 ldif_add_user_attr( rec, tagName, tagValue, hashField );
558 * Clear parsed data record.
559 * \param rec LDIF field object.
561 static void ldif_clear_rec( Ldif_ParsedRec *rec ) {
564 /* Free up user attributes */
565 list = rec->userAttr;
567 Ldif_UserAttr *attr = list->data;
568 g_free( attr->name );
569 g_free( attr->value );
571 list = g_slist_next( list );
573 g_slist_free( rec->userAttr );
575 g_slist_free( rec->listCName );
576 g_slist_free( rec->listFName );
577 g_slist_free( rec->listLName );
578 g_slist_free( rec->listNName );
579 g_slist_free( rec->listAddress );
580 g_slist_free( rec->listID );
582 rec->userAttr = NULL;
583 rec->listCName = NULL;
584 rec->listFName = NULL;
585 rec->listLName = NULL;
586 rec->listNName = NULL;
587 rec->listAddress = NULL;
592 * Read file data into address cache.
593 * Note that one LDIF record identifies one entity uniquely with the
594 * distinguished name (dn) tag. Each person can have multiple E-Mail
595 * addresses. Also, each person can have many common name (cn) tags.
597 * \param ldifFile LDIF import control object.
598 * \param cache Address cache to be populated with data.
600 static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
601 gchar *tagName = NULL, *tagValue = NULL;
602 gchar *lastTag = NULL, *fullValue = NULL;
603 GSList *listValue = NULL;
604 gboolean flagEOF = FALSE, flagEOR = FALSE;
605 gboolean flag64 = FALSE, last64 = FALSE;
609 GHashTable *hashField;
613 hashField = ldifFile->hashFields;
614 rec = g_new0( Ldif_ParsedRec, 1 );
615 ldif_clear_rec( rec );
617 /* Find EOF for progress indicator */
618 fseek( ldifFile->file, 0L, SEEK_END );
619 posEnd = ftell( ldifFile->file );
620 fseek( ldifFile->file, 0L, SEEK_SET );
623 gchar *line = ldif_get_line( ldifFile );
625 posCur = ftell( ldifFile->file );
626 if( ldifFile->cbProgress ) {
627 /* Call progress indicator */
628 ( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur );
633 flagEOF = flagEOR = TRUE;
635 else if( *line == '\0' ) {
640 /* EOR, Output address data */
643 fullValue = mgu_list_coalesce( listValue );
644 if (fullValue && last64) {
645 gchar *tmp = g_base64_decode_zero(fullValue, &len);
650 ldif_add_value( rec, lastTag, fullValue, hashField );
651 /* ldif_print_record( rec, stdout ); */
652 ldif_build_items( ldifFile, rec, cache );
653 ldif_clear_rec( rec );
655 mgu_free_list( listValue );
665 /* Continuation line */
666 listValue = g_slist_append(
667 listValue, g_strdup( line+1 ) );
669 else if( *line == '=' ) {
670 /* Base-64 encoded continuation field */
671 listValue = g_slist_append(
672 listValue, g_strdup( line ) );
676 tagName = ldif_get_tagname( line, &flag64 );
678 tagValue = ldif_get_tagvalue( line );
683 mgu_list_coalesce( listValue );
684 if (fullValue && last64) {
685 gchar *tmp = g_base64_decode_zero(fullValue, &len);
689 /* Base-64 encoded data */
692 ldif_dump_b64( fullValue );
697 rec, lastTag, fullValue,
700 mgu_free_list( listValue );
705 lastTag = g_strdup( tagName );
706 listValue = g_slist_append(
708 g_strdup( tagValue ) );
720 ldif_clear_rec( rec );
723 mgu_free_list( listValue );
727 * Add list of field names to hash table.
728 * \param table Hashtable.
729 * \param list List of fields.
731 static void ldif_hash_add_list( GHashTable *table, GSList *list ) {
734 /* mgu_print_list( list, stdout ); */
736 gchar *tag = node->data;
737 if( ! g_hash_table_lookup( table, tag ) ) {
738 Ldif_FieldRec *rec = NULL;
739 gchar *key = g_utf8_strdown( tag, -1 );
741 rec = ldif_create_fieldrec( tag );
742 if( g_utf8_collate( key, LDIF_TAG_DN ) == 0 ) {
743 rec->reserved = rec->selected = TRUE;
744 rec->userName = g_strdup( "dn" );
746 else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) {
747 rec->reserved = rec->selected = TRUE;
748 rec->userName = g_strdup( _( "Display Name" ) );
750 else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) {
751 rec->reserved = rec->selected = TRUE;
752 rec->userName = g_strdup( _( "First Name" ) );
754 else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) {
755 rec->reserved = rec->selected = TRUE;
756 rec->userName = g_strdup( _( "Last Name" ) );
758 else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) {
759 rec->reserved = rec->selected = TRUE;
760 rec->userName = g_strdup( _( "Nick Name" ) );
762 else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) {
763 rec->reserved = rec->selected = TRUE;
764 rec->userName = g_strdup( _( "Email Address" ) );
766 g_hash_table_insert( table, key, rec );
768 node = g_slist_next( node );
773 * Sorted list comparison function.
774 * \param ptr1 First field.
775 * \param ptr2 Second field.
776 * \return <code>-1, 0, +1</code> if first record less than, equal,
777 * greater than second.
779 static gint ldif_field_compare( gconstpointer ptr1, gconstpointer ptr2 ) {
780 const Ldif_FieldRec *rec1 = ptr1;
781 const Ldif_FieldRec *rec2 = ptr2;
783 if( rec1->reserved ) {
784 if( ! rec2->reserved ) {
789 if( rec2->reserved ) {
793 return g_utf8_collate( rec1->tagName, rec2->tagName );
797 * Append hash table entry to list - visitor function.
799 * \param value Data value.
800 * \param data User data (the LDIF import control object).
802 static void ldif_hash2list_vis( gpointer key, gpointer value, gpointer data ) {
803 LdifFile *ldf = data;
805 g_list_insert_sorted( ldf->tempList, value, ldif_field_compare );
809 * Read tag names for file data.
810 * \param ldifFile LDIF import control object.
812 static void ldif_read_tag_list( LdifFile *ldifFile ) {
813 gchar *tagName = NULL;
814 GSList *listTags = NULL;
815 gboolean flagEOF = FALSE, flagEOR = FALSE, flagMail = FALSE;
816 gboolean flag64 = FALSE;
820 /* Clear hash table */
821 g_hash_table_foreach_remove(
822 ldifFile->hashFields, ldif_hash_free_vis, NULL );
824 /* Find EOF for progress indicator */
825 fseek( ldifFile->file, 0L, SEEK_END );
826 posEnd = ftell( ldifFile->file );
827 fseek( ldifFile->file, 0L, SEEK_SET );
830 ldifFile->retVal = MGU_EOF;
836 gchar *line = ldif_get_line( ldifFile );
837 posCur = ftell( ldifFile->file );
838 if( ldifFile->cbProgress ) {
839 /* Call progress indicator */
840 ( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur );
845 flagEOF = flagEOR = TRUE;
847 else if( *line == '\0' ) {
852 /* EOR, Output address data */
853 /* Save field list to hash table */
856 ldifFile->hashFields, listTags );
858 mgu_free_list( listTags );
865 /* Continuation line */
867 else if( *line == '=' ) {
868 /* Base-64 encoded continuation field */
872 tagName = ldif_get_tagname( line, &flag64 );
874 /* Add tag to list */
875 listTags = g_slist_append( listTags, tagName );
878 tagName, LDIF_TAG_EMAIL ) == 0 )
885 debug_print("ldif: bad format: '%s'\n", line);
886 ldifFile->retVal = MGU_BAD_FORMAT;
895 mgu_free_list( listTags );
900 * Read file into list. Main entry point
901 * \param ldifFile LDIF import control object.
902 * \param cache Address cache to load.
903 * \return Status code.
905 gint ldif_import_data( LdifFile *ldifFile, AddressCache *cache ) {
906 cm_return_val_if_fail( ldifFile != NULL, MGU_BAD_ARGS );
907 ldifFile->retVal = MGU_SUCCESS;
908 addrcache_clear( cache );
909 cache->dataRead = FALSE;
910 ldif_open_file( ldifFile );
911 if( ldifFile->retVal == MGU_SUCCESS ) {
912 /* Read data into the cache */
913 ldif_read_file( ldifFile, cache );
914 ldif_close_file( ldifFile );
917 cache->modified = FALSE;
918 cache->dataRead = TRUE;
920 return ldifFile->retVal;
924 * Process entire file reading list of unique fields. List of fields may be
925 * accessed with the <code>ldif_get_fieldlist()</code> function.
926 * \param ldifFile LDIF import control object.
927 * \return Status code.
929 gint ldif_read_tags( LdifFile *ldifFile ) {
930 cm_return_val_if_fail( ldifFile != NULL, MGU_BAD_ARGS );
931 ldifFile->retVal = MGU_SUCCESS;
932 if( ldifFile->dirtyFlag ) {
933 ldif_open_file( ldifFile );
934 if( ldifFile->retVal == MGU_SUCCESS ) {
935 /* Read data into the cache */
936 ldif_read_tag_list( ldifFile );
937 ldif_close_file( ldifFile );
938 ldifFile->dirtyFlag = FALSE;
939 ldifFile->accessFlag = TRUE;
942 return ldifFile->retVal;
946 * Return list of fields for LDIF file.
947 * \param ldifFile LDIF import control object.
948 * \return Linked list of <code>Ldif_FieldRec</code> objects. This list may be
949 * <code>g_free()</code>. Note that the objects in the list should not
950 * be freed since they refer to objects inside the internal cache.
951 * These objects will be freed when LDIF file object is freed.
953 GList *ldif_get_fieldlist( LdifFile *ldifFile ) {
956 cm_return_val_if_fail( ldifFile != NULL, NULL );
957 if( ldifFile->hashFields ) {
958 ldifFile->tempList = NULL;
959 g_hash_table_foreach( ldifFile->hashFields, ldif_hash2list_vis, ldifFile );
960 list = ldifFile->tempList;
961 ldifFile->tempList = NULL;
967 * Output LDIF name-value pair to stream. Only non-empty names and values will
969 * \param stream File output stream.
971 * \param value Data value.
972 * \return <i>TRUE</i> if data output.
974 gboolean ldif_write_value( FILE *stream, const gchar *name, const gchar *value ) {
975 if( name == NULL ) return FALSE;
976 if( value == NULL ) return FALSE;
977 if( strlen( name ) < 1 ) return FALSE;
978 if( strlen( value ) < 1 ) return FALSE;
979 fprintf( stream, "%s: ", name );
980 fprintf( stream, "%s\n", value );
985 * Output LDIF End of Record to stream.
986 * \param stream File output stream.
987 * \return <i>TRUE</i> if data output.
989 void ldif_write_eor( FILE *stream ) {
990 /* Simple but caller should not need to know how to end record. */
991 fprintf( stream, "\n" );
995 * ============================================================================
997 * ============================================================================