/* * ============================================================================================ * Read file into list. Main entry point * Return: TRUE if file read successfully. * ============================================================================================ */ gint jpilot_read_data( JPilotFile *pilotFile ) { name_order = FAMILY_LAST; convert_charcode = FALSE; if( conv_is_ja_locale() ) { name_order = FAMILY_FIRST; convert_charcode = TRUE; } g_return_val_if_fail( pilotFile != NULL, -1 ); pilotFile->retVal = MGU_SUCCESS; pilotFile->accessFlag = FALSE; if( jpilot_check_files( pilotFile ) ) { addrcache_clear( pilotFile->addressCache ); jpilot_read_metadata( pilotFile ); if( pilotFile->retVal == MGU_SUCCESS ) { jpilot_setup_labels( pilotFile ); jpilot_build_category_list( pilotFile ); pilotFile->retVal = jpilot_read_file( pilotFile ); if( pilotFile->retVal == MGU_SUCCESS ) { jpilot_remove_empty( pilotFile ); jpilot_mark_files( pilotFile ); pilotFile->addressCache->modified = FALSE; pilotFile->addressCache->dataRead = TRUE; } } } return pilotFile->retVal; }
/* * Free up cardfile object by releasing internal memory. */ void vcard_free( VCardFile *cardFile ) { g_return_if_fail( cardFile != NULL ); /* Close file */ if( cardFile->file ) fclose( cardFile->file ); /* Clear cache */ addrcache_clear( cardFile->addressCache ); addrcache_free( cardFile->addressCache ); /* Free internal stuff */ g_free( cardFile->path ); /* Clear pointers */ cardFile->file = NULL; cardFile->path = NULL; cardFile->bufptr = NULL; cardFile->type = ADBOOKTYPE_NONE; cardFile->addressCache = NULL; cardFile->retVal = MGU_SUCCESS; /* Now release file object */ g_free( cardFile ); }
/* * Read metadata from file. */ static gint jpilot_read_metadata( JPilotFile *pilotFile ) { gint retVal; unsigned int rec_size; unsigned char *buf; int num; g_return_val_if_fail( pilotFile != NULL, -1 ); pilotFile->readMetadata = FALSE; addrcache_clear( pilotFile->addressCache ); /* Read file info */ retVal = jpilot_get_file_info( pilotFile, &buf, &rec_size); if( retVal != MGU_SUCCESS ) { pilotFile->retVal = retVal; return pilotFile->retVal; } num = unpack_AddressAppInfo( &pilotFile->addrInfo, buf, rec_size ); if( buf ) { free(buf); } if( num <= 0 ) { pilotFile->retVal = MGU_ERROR_READ; return pilotFile->retVal; } pilotFile->readMetadata = TRUE; pilotFile->retVal = MGU_SUCCESS; return pilotFile->retVal; }
/** * Free up pilot file object by releasing internal memory. * \param pilotFile JPilot control data. */ void jpilot_free( JPilotFile *pilotFile ) { g_return_if_fail( pilotFile != NULL ); /* Release custom labels */ jpilot_clear_custom_labels( pilotFile ); /* Clear cache */ addrcache_clear( pilotFile->addressCache ); addrcache_free( pilotFile->addressCache ); /* Free internal stuff */ g_free( pilotFile->path ); pilotFile->file = NULL; pilotFile->path = NULL; pilotFile->readMetadata = FALSE; pilotFile->havePC3 = FALSE; pilotFile->pc3ModifyTime = 0; pilotFile->type = ADBOOKTYPE_NONE; pilotFile->addressCache = NULL; pilotFile->retVal = MGU_SUCCESS; /* Now release file object */ g_free( pilotFile ); }
/** * Read file into list. Main entry point * \param pilotFile JPilot control data. * \return Error/status code. <code>MGU_SUCCESS</code> if data read * successfully. */ gint jpilot_read_data( JPilotFile *pilotFile ) { const gchar *cur_locale; name_order = FAMILY_LAST; convert_charcode = FALSE; cur_locale = conv_get_current_locale(); if( g_strncasecmp( cur_locale, "ja", 2 ) == 0 ) { name_order = FAMILY_FIRST; } if( conv_get_current_charset() == C_EUC_JP ) { convert_charcode = TRUE; } g_return_val_if_fail( pilotFile != NULL, -1 ); pilotFile->retVal = MGU_SUCCESS; pilotFile->addressCache->accessFlag = FALSE; if( jpilot_check_files( pilotFile ) ) { addrcache_clear( pilotFile->addressCache ); jpilot_read_metadata( pilotFile ); if( pilotFile->retVal == MGU_SUCCESS ) { pilotFile->retVal = jpilot_read_file( pilotFile ); if( pilotFile->retVal == MGU_SUCCESS ) { pilotFile->addressCache->modified = FALSE; pilotFile->addressCache->dataRead = TRUE; } } } return pilotFile->retVal; }
/* * ============================================================================ * Read all files in specified directory into address book. * Enter: harvester Harvester object. * cache Address cache to load. * msgList List of message numbers, or NULL to process folder. * Return: Status. * ============================================================================ */ gint addrharvest_harvest( AddressHarvester *harvester, AddressCache *cache, GList *msgList ) { gint retVal; GList *node; GList *listHdr; retVal = MGU_BAD_ARGS; g_return_val_if_fail( harvester != NULL, retVal ); g_return_val_if_fail( cache != NULL, retVal ); g_return_val_if_fail( harvester->path != NULL, retVal ); /* Clear cache */ addrcache_clear( cache ); cache->dataRead = FALSE; /* Build list of headers of interest */ listHdr = NULL; node = harvester->headerTable; while( node ) { HeaderEntry *entry; entry = node->data; if( entry->selected ) { gchar *p; p = g_strdup( entry->header ); g_strdown( p ); listHdr = g_list_append( listHdr, p ); } node = g_list_next( node ); } /* Process directory/files */ if( msgList == NULL ) { addrharvest_harvest_dir( harvester, cache, listHdr, harvester->path ); } else { addrharvest_harvest_list( harvester, cache, listHdr, msgList ); } mgu_free_dlist( listHdr ); /* Mark cache */ cache->modified = FALSE; cache->dataRead = TRUE; return retVal; }
/** * Read file into list. Main entry point * \param ldifFile LDIF import control object. * \param cache Address cache to load. * \return Status code. */ gint ldif_import_data( LdifFile *ldifFile, AddressCache *cache ) { cm_return_val_if_fail( ldifFile != NULL, MGU_BAD_ARGS ); ldifFile->retVal = MGU_SUCCESS; addrcache_clear( cache ); cache->dataRead = FALSE; ldif_open_file( ldifFile ); if( ldifFile->retVal == MGU_SUCCESS ) { /* Read data into the cache */ ldif_read_file( ldifFile, cache ); ldif_close_file( ldifFile ); /* Mark cache */ cache->modified = FALSE; cache->dataRead = TRUE; } return ldifFile->retVal; }
/* * Free up LDAP server interface object by releasing internal memory. */ void syldap_free( SyldapServer *ldapServer ) { g_return_if_fail( ldapServer != NULL ); debug_print("Freeing LDAP server interface object\n"); ldapServer->callBack = NULL; /* Clear cache */ addrcache_clear( ldapServer->addressCache ); addrcache_free( ldapServer->addressCache ); /* Free internal stuff */ g_free( ldapServer->hostName ); g_free( ldapServer->baseDN ); g_free( ldapServer->bindDN ); g_free( ldapServer->bindPass ); g_free( ldapServer->searchCriteria ); g_free( ldapServer->searchValue ); g_free( ldapServer->thread ); /* Clear pointers */ ldapServer->hostName = NULL; ldapServer->port = 0; ldapServer->baseDN = NULL; ldapServer->bindDN = NULL; ldapServer->bindPass = NULL; ldapServer->searchCriteria = NULL; ldapServer->searchValue = NULL; ldapServer->entriesRead = 0; ldapServer->maxEntries = 0; ldapServer->timeOut = 0; ldapServer->newSearch = FALSE; ldapServer->thread = NULL; ldapServer->busyFlag = FALSE; ldapServer->callBack = NULL; ldapServer->idleId = 0; ldapServer->type = ADBOOKTYPE_NONE; ldapServer->addressCache = NULL; ldapServer->retVal = MGU_SUCCESS; /* Now release LDAP object */ g_free( ldapServer ); }
/* * ============================================================================================ * Read file into list. Main entry point * Enter: muttFile MUTT control data. * cache Address cache to load. * Return: Status code. * ============================================================================================ */ gint mutt_import_data( MuttFile *muttFile, AddressCache *cache ) { g_return_val_if_fail( muttFile != NULL, MGU_BAD_ARGS ); g_return_val_if_fail( cache != NULL, MGU_BAD_ARGS ); muttFile->retVal = MGU_SUCCESS; addrcache_clear( cache ); cache->dataRead = FALSE; mutt_open_file( muttFile ); if( muttFile->retVal == MGU_SUCCESS ) { /* Read data into the cache */ mutt_read_file( muttFile, cache ); mutt_close_file( muttFile ); /* Mark cache */ cache->modified = FALSE; cache->dataRead = TRUE; } return muttFile->retVal; }
/* ============================================================================================ */ gint vcard_read_data( VCardFile *cardFile ) { g_return_val_if_fail( cardFile != NULL, -1 ); cardFile->retVal = MGU_SUCCESS; cardFile->addressCache->accessFlag = FALSE; if( addrcache_check_file( cardFile->addressCache, cardFile->path ) ) { addrcache_clear( cardFile->addressCache ); vcard_open_file( cardFile ); if( cardFile->retVal == MGU_SUCCESS ) { /* Read data into the list */ vcard_read_file( cardFile ); vcard_close_file( cardFile ); /* Mark cache */ addrcache_mark_file( cardFile->addressCache, cardFile->path ); cardFile->addressCache->modified = FALSE; cardFile->addressCache->dataRead = TRUE; } } return cardFile->retVal; }
/* * Perform the LDAP search, reading LDAP entries into cache. * Note that one LDAP entry can have multiple values for many of its * attributes. If these attributes are E-Mail addresses; these are * broken out into separate address items. For any other attribute, * only the first occurrence is read. */ gint syldap_search( SyldapServer *ldapServer ) { LDAP *ld; LDAPMessage *result, *e; char *attribs[10]; char *attribute; gchar *criteria; BerElement *ber; gint rc; GSList *listName = NULL, *listAddress = NULL, *listID = NULL; GSList *listFirst = NULL, *listLast = NULL, *listDN = NULL; struct timeval timeout; gboolean entriesFound = FALSE; g_return_val_if_fail( ldapServer != NULL, -1 ); ldapServer->retVal = MGU_SUCCESS; if( ! syldap_check_search( ldapServer ) ) { return ldapServer->retVal; } /* Set timeout */ timeout.tv_sec = ldapServer->timeOut; timeout.tv_usec = 0L; ldapServer->entriesRead = 0; if( ( ld = ldap_init( ldapServer->hostName, ldapServer->port ) ) == NULL ) { ldapServer->retVal = MGU_LDAP_INIT; return ldapServer->retVal; } /* printf( "connected to LDAP host %s on port %d\n", ldapServer->hostName, ldapServer->port ); */ /* Bind to the server, if required */ if( ldapServer->bindDN ) { if( * ldapServer->bindDN != '\0' ) { /* printf( "binding...\n" ); */ rc = ldap_simple_bind_s( ld, ldapServer->bindDN, ldapServer->bindPass ); /* printf( "rc=%d\n", rc ); */ if( rc != LDAP_SUCCESS ) { /* printf( "LDAP Error: ldap_simple_bind_s: %s\n", ldap_err2string( rc ) ); */ ldap_unbind( ld ); ldapServer->retVal = MGU_LDAP_BIND; return ldapServer->retVal; } } } /* Define all attributes we are interested in. */ attribs[0] = SYLDAP_ATTR_DN; attribs[1] = SYLDAP_ATTR_COMMONNAME; attribs[2] = SYLDAP_ATTR_GIVENNAME; attribs[3] = SYLDAP_ATTR_SURNAME; attribs[4] = SYLDAP_ATTR_EMAIL; attribs[5] = SYLDAP_ATTR_UID; attribs[6] = NULL; /* Create LDAP search string and apply search criteria */ criteria = g_strdup_printf( ldapServer->searchCriteria, ldapServer->searchValue ); rc = ldap_search_ext_s( ld, ldapServer->baseDN, LDAP_SCOPE_SUBTREE, criteria, attribs, 0, NULL, NULL, &timeout, 0, &result ); g_free( criteria ); criteria = NULL; if( rc == LDAP_TIMEOUT ) { ldap_unbind( ld ); ldapServer->retVal = MGU_LDAP_TIMEOUT; return ldapServer->retVal; } if( rc != LDAP_SUCCESS ) { /* printf( "LDAP Error: ldap_search_st: %s\n", ldap_err2string( rc ) ); */ ldap_unbind( ld ); ldapServer->retVal = MGU_LDAP_SEARCH; return ldapServer->retVal; } /* printf( "Total results are: %d\n", ldap_count_entries( ld, result ) ); */ /* Clear the cache if we have new entries, otherwise leave untouched. */ if( ldap_count_entries( ld, result ) > 0 ) { addrcache_clear( ldapServer->addressCache ); } /* Process results */ ldapServer->entriesRead = 0; for( e = ldap_first_entry( ld, result ); e != NULL; e = ldap_next_entry( ld, e ) ) { entriesFound = TRUE; if( ldapServer->entriesRead >= ldapServer->maxEntries ) break; /* printf( "DN: %s\n", ldap_get_dn( ld, e ) ); */ /* Process all attributes */ for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL; attribute = ldap_next_attribute( ld, e, ber ) ) { if( strcasecmp( attribute, SYLDAP_ATTR_COMMONNAME ) == 0 ) { listName = syldap_add_list_values( ld, e, attribute ); } if( strcasecmp( attribute, SYLDAP_ATTR_EMAIL ) == 0 ) { listAddress = syldap_add_list_values( ld, e, attribute ); } if( strcasecmp( attribute, SYLDAP_ATTR_UID ) == 0 ) { listID = syldap_add_single_value( ld, e, attribute ); } if( strcasecmp( attribute, SYLDAP_ATTR_GIVENNAME ) == 0 ) { listFirst = syldap_add_list_values( ld, e, attribute ); } if( strcasecmp( attribute, SYLDAP_ATTR_SURNAME ) == 0 ) { listLast = syldap_add_single_value( ld, e, attribute ); } if( strcasecmp( attribute, SYLDAP_ATTR_DN ) == 0 ) { listDN = syldap_add_single_value( ld, e, attribute ); } /* Free memory used to store attribute */ ldap_memfree( attribute ); } /* Format and add items to cache */ syldap_build_items_fl( ldapServer, listAddress, listFirst, listLast ); /* Free up */ syldap_free_lists( listName, listAddress, listID, listDN, listFirst, listLast ); listName = listAddress = listID = listFirst = listLast = listDN = NULL; if( ber != NULL ) { ber_free( ber, 0 ); } } syldap_free_lists( listName, listAddress, listID, listDN, listFirst, listLast ); listName = listAddress = listID = listFirst = listLast = listDN = NULL; /* Free up and disconnect */ ldap_msgfree( result ); ldap_unbind( ld ); ldapServer->newSearch = FALSE; if( entriesFound ) { ldapServer->retVal = MGU_SUCCESS; } else { ldapServer->retVal = MGU_LDAP_NOENTRIES; } return ldapServer->retVal; }