示例#1
0
/**
 * Free linked lists of character strings.
 * \param listName  List of common names.
 * \param listAddr  List of addresses.
 * \param listFirst List of first names.
 * \param listLast  List of last names.
 */
static void ldapqry_free_lists(
		GSList *listName, GSList *listAddr, GSList *listFirst,
		GSList *listLast, GSList *listDisplay, GSList *other_attrs )
{
	GSList *cur = other_attrs;
	mgu_free_list( listName );
	mgu_free_list( listAddr );
	mgu_free_list( listFirst );
	mgu_free_list( listLast );
	mgu_free_list( listDisplay );
	for(;cur; cur = cur->next)
		addritem_free_attribute((UserAttribute *)cur->data);
	g_slist_free(other_attrs);
}
示例#2
0
/*
 * Read file data into address cache.
 * Enter: muttFile MUTT control data.
 *        cache Address cache.
 */
static void mutt_read_file( MuttFile *muttFile, AddressCache *cache ) {
	GSList *listValue = NULL;
	gboolean flagEOF = FALSE, flagCont = FALSE, lastCont = FALSE;
	gchar *line =  NULL, *lineValue = NULL;
	long posEnd = 0L;
	long posCur = 0L;

	/* Find EOF for progress indicator */
	fseek( muttFile->file, 0L, SEEK_END );
	posEnd = ftell( muttFile->file );
	fseek( muttFile->file, 0L, SEEK_SET );

	while( ! flagEOF ) {
		flagCont = FALSE;
		line =  mutt_get_line( muttFile, &flagCont );

		posCur = ftell( muttFile->file );
		if( muttFile->cbProgress ) {
			/* Call progress indicator */
			( muttFile->cbProgress ) ( muttFile, & posEnd, & posCur );
		}

		if( line == NULL ) flagEOF = TRUE;
		if( ! lastCont ) {
			/* Save data */
			lineValue = mgu_list_coalesce( listValue );
			if( lineValue ) {
				mutt_build_items( muttFile, cache, lineValue );
			}
			g_free( lineValue );
			lineValue = NULL;
			mgu_free_list( listValue );
			listValue = NULL;
		}
		lastCont = flagCont;

		/* Add line to list */
		listValue = g_slist_append( listValue, g_strdup( line ) );

		g_free( line );
		line = NULL;
	}

	/* Release data */
	mgu_free_list( listValue );
	listValue = NULL;
}
示例#3
0
/*
 * Read specified file into address book.
 * Enter:  harvester Harvester object.
 *         fileName  File to read.
 *         cache     Address cache to load.
 * Return: Status.
 */
static gint addrharvest_readfile(
		AddressHarvester *harvester, const gchar *fileName,
		AddressCache *cache, GList *listHdr )
{
	gint retVal;
	FILE *msgFile;
	gchar *buf, *addr, *p;
	HeaderEntry *entry;
	GSList *list;
	gboolean done;

	msgFile = fopen( fileName, "rb" );
	if( ! msgFile ) {
		/* Cannot open file */
		retVal = MGU_OPEN_FILE;
		return retVal;
	}

	done = FALSE;
	while( TRUE ) {
		list = addrharvest_get_header( msgFile, listHdr, &done );
		if( done ) break;

		if( list == NULL ) {
			continue;
		}

		buf = mgu_list_coalesce( list );
		mgu_free_list( list );

		if(( p = strchr( buf, ':' ) ) != NULL ) {
			addr = p + 1;
			*p = '\0';

			entry = addrharvest_find( harvester, buf );
			if( entry && entry->selected ) {
				/* Sanitize control characters */
				p = addr;
				while( *p ) {
					if( *p == '\r' || *p == '\n' || *p == '\t' )
						*p = ' ';
					p++;
				}
				addrharvest_parse_address(
					harvester, entry, cache, addr );
			}
		}
		g_free( buf );
	}

	fclose( msgFile );
	return MGU_SUCCESS;
}
示例#4
0
/*
* Free linked lists of character strings.
*/
static void syldap_free_lists( GSList *listName, GSList *listAddr, GSList *listID, GSList *listDN, GSList *listFirst, GSList *listLast ) {
	mgu_free_list( listName );
	mgu_free_list( listAddr );
	mgu_free_list( listID );
	mgu_free_list( listDN );
	mgu_free_list( listFirst );
	mgu_free_list( listLast );
}
示例#5
0
/*
* Read quoted-printable text, which may span several lines into one long string.
* Param: cardFile - object.
* Param: tagvalue - will be placed into the linked list.
*/
static gchar *vcard_read_qp( VCardFile *cardFile, char *tagvalue ) {
	GSList *listQP = NULL;
	gint len = 0;
	gchar *line = tagvalue;
	while( line ) {
		listQP = g_slist_append( listQP, line );
		len = strlen( line ) - 1;
		if( line[ len ] != '=' ) break;
		line[ len ] = '\0';
		line = vcard_get_line( cardFile );
	}

	/* Coalesce linked list into one long buffer. */
	line = mgu_list_coalesce( listQP );

	/* Clean up */
	mgu_free_list( listQP );
	listQP = NULL;
	return line;
}
示例#6
0
/**
 * Process a single search entry.
 * \param  cache Address cache to load.
 * \param  qry   Query object to process.
 * \param  ld    LDAP handle.
 * \param  e     LDAP message.
 * \return List of EMail objects found.
 */
static GList *ldapqry_process_single_entry(
		AddressCache *cache, LdapQuery *qry, LDAP *ld, LDAPMessage *e )
{
	char *dnEntry;
	char *attribute;
	LdapControl *ctl;
	BerElement *ber;
	GSList *listName = NULL, *listAddress = NULL;
	GSList *listFirst = NULL, *listLast = NULL;
	GSList *listDisplay = NULL;
	GSList *other_attrs = NULL;
	GList *listReturn;

	listReturn = NULL;
	ctl = qry->control;
	dnEntry = ldap_get_dn( ld, e );
	debug_print( "DN: %s\n", dnEntry?dnEntry:"null" );

	/* Process all attributes */
	for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL;
		attribute = ldap_next_attribute( ld, e, ber ) ) {
		if( strcasecmp( attribute, ctl->attribEMail ) == 0 ) {
			listAddress = ldapqry_add_list_values( ld, e, attribute );
		}
		else if( strcasecmp( attribute, ctl->attribCName ) == 0 ) {
			listName = ldapqry_add_list_values( ld, e, attribute );
		}
		else if( strcasecmp( attribute, ctl->attribFName ) == 0 ) {
			listFirst = ldapqry_add_list_values( ld, e, attribute );
		}
		else if( strcasecmp( attribute, ctl->attribLName ) == 0 ) {
			listLast = ldapqry_add_single_value( ld, e, attribute );
		} else if( strcasecmp( attribute, ctl->attribDName ) == 0 ) {
			listDisplay = ldapqry_add_single_value( ld, e, attribute );
		} else {
			GSList *attlist = ldapqry_add_single_value( ld, e, attribute );
			UserAttribute *attrib = addritem_create_attribute();
			const gchar *attvalue = attlist?((gchar *)attlist->data):NULL;
			if (attvalue) {
				addritem_attrib_set_name( attrib, attribute );
				addritem_attrib_set_value( attrib, attvalue );
				other_attrs = g_slist_prepend(other_attrs, attrib);
			}
			mgu_free_list(attlist);
		}
		/* Free memory used to store attribute */
		ldap_memfree( attribute );
	}

	/* Format and add items to cache */
	listReturn = ldapqry_build_items_fl(
		cache, qry, dnEntry, listName, listAddress, listFirst, listLast, listDisplay, other_attrs );

	/* Free up */
	ldapqry_free_lists( listName, listAddress, listFirst, listLast, listDisplay, other_attrs );
	listName = listAddress = listFirst = listLast = listDisplay = other_attrs = NULL;

	if( ber != NULL ) {
		ber_free( ber, 0 );
	}
	ldap_memfree( dnEntry );

	return listReturn;
}
示例#7
0
/*
* Free linked lists of character strings.
*/
static void vcard_free_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList* listID ) {
	mgu_free_list( listName );
	mgu_free_list( listAddr );
	mgu_free_list( listRem );
	mgu_free_list( listID );
}
示例#8
0
/**
 * Read tag names for file data.
 * \param  ldifFile LDIF import control object.
 */
static void ldif_read_tag_list( LdifFile *ldifFile ) {
	gchar *tagName = NULL;
	GSList *listTags = NULL;
	gboolean flagEOF = FALSE, flagEOR = FALSE, flagMail = FALSE;
	gboolean flag64 = FALSE;
	long posEnd = 0L;
	long posCur = 0L;

	/* Clear hash table */
	g_hash_table_foreach_remove(
		ldifFile->hashFields, ldif_hash_free_vis, NULL );

	/* Find EOF for progress indicator */
	fseek( ldifFile->file, 0L, SEEK_END );
	posEnd = ftell( ldifFile->file );
	fseek( ldifFile->file, 0L, SEEK_SET );

	if (posEnd == 0) {
		ldifFile->retVal = MGU_EOF;
		return;
	}
		
	/* Process file */
	while( ! flagEOF ) {
		gchar *line = ldif_get_line( ldifFile );
		posCur = ftell( ldifFile->file );
		if( ldifFile->cbProgress ) {
			/* Call progress indicator */
			( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur );
		}

		flag64 = FALSE;
		if( line == NULL ) {
			flagEOF = flagEOR = TRUE;
		}
		else if( *line == '\0' ) {
			flagEOR = TRUE;
		}

		if( flagEOR ) {
			/* EOR, Output address data */
			/* Save field list to hash table */
			if( flagMail ) {
				ldif_hash_add_list(
					ldifFile->hashFields, listTags );
			}
			mgu_free_list( listTags );
			listTags = NULL;
			flagMail = FALSE;
		}
		if( line ) {
			flagEOR = FALSE;
			if( *line == ' ' ) {
				/* Continuation line */
			}
			else if( *line == '=' ) {
				/* Base-64 encoded continuation field */
			}
			else {
				/* Parse line */
				tagName = ldif_get_tagname( line, &flag64 );
				if( tagName ) {
					/* Add tag to list */
					listTags = g_slist_append( listTags, tagName );

					if( g_utf8_collate(
						tagName, LDIF_TAG_EMAIL ) == 0 )
					{
						flagMail = TRUE;
					}
				} else {
					g_strstrip(line);
					if (*line != '\0') {
						debug_print("ldif: bad format: '%s'\n", line);
						ldifFile->retVal = MGU_BAD_FORMAT;
					}
				}
			}
		}
		g_free( line );
	}

	/* Release data */
	mgu_free_list( listTags );
	listTags = NULL;
}
示例#9
0
/**
 * Read file data into address cache.
 * Note that one LDIF record identifies one entity uniquely with the
 * distinguished name (dn) tag. Each person can have multiple E-Mail
 * addresses. Also, each person can have many common name (cn) tags.
 *
 * \param  ldifFile LDIF import control object.
 * \param  cache    Address cache to be populated with data.
 */
static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
	gchar *tagName = NULL, *tagValue = NULL;
	gchar *lastTag = NULL, *fullValue = NULL;
	GSList *listValue = NULL;
	gboolean flagEOF = FALSE, flagEOR = FALSE;
	gboolean flag64 = FALSE, last64 = FALSE;
	Ldif_ParsedRec *rec;
	long posEnd = 0L;
	long posCur = 0L;
	GHashTable *hashField;
	gsize len;

	hashField = ldifFile->hashFields;
	rec = g_new0( Ldif_ParsedRec, 1 );
	ldif_clear_rec( rec );

	/* Find EOF for progress indicator */
	fseek( ldifFile->file, 0L, SEEK_END );
	posEnd = ftell( ldifFile->file );
	fseek( ldifFile->file, 0L, SEEK_SET );

	while( ! flagEOF ) {
		gchar *line =  ldif_get_line( ldifFile );

		posCur = ftell( ldifFile->file );
		if( ldifFile->cbProgress ) {
			/* Call progress indicator */
			( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur );
		}

		flag64 = FALSE;
		if( line == NULL ) {
			flagEOF = flagEOR = TRUE;
		}
		else if( *line == '\0' ) {
			flagEOR = TRUE;
		}

		if( flagEOR ) {
			/* EOR, Output address data */
			if( lastTag ) {
				/* Save record */
				fullValue = mgu_list_coalesce( listValue );
				if (fullValue && last64) {
					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 ); */
				ldif_build_items( ldifFile, rec, cache );
				ldif_clear_rec( rec );
				g_free( lastTag );
				mgu_free_list( listValue );
				g_free(fullValue);
				lastTag = NULL;
				listValue = NULL;
				last64 = FALSE;
			}
		}
		if( line ) {
			flagEOR = FALSE;
			if( *line == ' ' ) {
				/* Continuation line */
				listValue = g_slist_append(
					listValue, g_strdup( line+1 ) );
			}
			else if( *line == '=' ) {
				/* Base-64 encoded continuation field */
				listValue = g_slist_append(
					listValue, g_strdup( line ) );
			}
			else {
				/* Parse line */
				tagName = ldif_get_tagname( line, &flag64 );
				if( tagName ) {
					tagValue = ldif_get_tagvalue( line );
					if( tagValue ) {
						if( lastTag ) {
							/* Save data */
							fullValue =
								mgu_list_coalesce( listValue );
							if (fullValue && last64) {
								gchar *tmp = g_base64_decode_zero(fullValue, &len);
								g_free(fullValue);
								fullValue = tmp;
							}
							/* Base-64 encoded data */
							/*
							if( last64 ) {
								ldif_dump_b64( fullValue );
							}
							*/

							ldif_add_value(
								rec, lastTag, fullValue,
								hashField );
							g_free( lastTag );
							mgu_free_list( listValue );
							lastTag = NULL;
							listValue = NULL;
						}

						lastTag = g_strdup( tagName );
						listValue = g_slist_append(
							listValue,
							g_strdup( tagValue ) );
						g_free( tagValue );
						last64 = flag64;
					}
					g_free( tagName );
				}
			}
		}
		g_free( line );
	}

	/* Release data */
	ldif_clear_rec( rec );
	g_free( rec );
	g_free( lastTag );
	mgu_free_list( listValue );
}