/* * Remove folder from cache. Children are deleted. * param: folder Folder to remove. * return: Folder, or NULL if not found. Note that object should still be freed. */ ItemFolder *addrcache_remove_folder_delete( AddressCache *cache, ItemFolder *folder ) { AddrItemObject *obj = NULL; cm_return_val_if_fail( cache != NULL, NULL ); if( folder ) { gchar *uid = ADDRITEM_ID(folder); if( uid == NULL || *uid == '\0' ) return NULL; obj = ( AddrItemObject * ) g_hash_table_lookup( cache->itemHash, uid ); if( obj ) { ItemFolder *parent = ( ItemFolder * ) ADDRITEM_PARENT(folder); if( ! parent ) parent = cache->rootFolder; /* Remove groups */ while( folder->listGroup ) { ItemGroup *item = ( ItemGroup * ) folder->listGroup->data; item = addrcache_remove_group( cache, item ); if( item ) { addritem_free_item_group( item ); item = NULL; } } while( folder->listPerson ) { ItemPerson *item = ( ItemPerson * ) folder->listPerson->data; item = addrcache_remove_person( cache, item ); if( item ) { addritem_free_item_person( item ); item = NULL; } } /* Recursive deletion of folder */ while( folder->listFolder ) { ItemFolder *item = ( ItemFolder * ) folder->listFolder->data; item = addrcache_remove_folder_delete( cache, item ); if( item ) { addritem_free_item_folder( item ); item = NULL; } } /* Remove folder from parent's list and hash table */ parent->listFolder = g_list_remove( parent->listFolder, folder ); ADDRITEM_PARENT(folder) = NULL; g_hash_table_remove( cache->itemHash, uid ); cache->dirtyFlag = TRUE; return folder; } } return NULL; }
/** * Free up list of person objects contained in specified folder. * \param folder Folder to process. */ void addritem_folder_free_person( ItemFolder *folder ) { GList *node; g_return_if_fail( folder != NULL ); /* Free up folder of persons. */ node = folder->listPerson; while( node ) { ItemPerson *person = node->data; addritem_free_item_person( person ); person = NULL; node = g_list_next( node ); } }
/* * Build an address list entry and append to list of address items. */ static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listAddr, GSList *listRem, GSList *listID ) { GSList *nodeName = listName; GSList *nodeID = listID; gchar *str; while( nodeName ) { GSList *nodeAddress = listAddr; GSList *nodeRemarks = listRem; ItemPerson *person = addritem_create_item_person(); addritem_person_set_common_name( person, nodeName->data ); while( nodeAddress ) { str = nodeAddress->data; if( *str != '\0' ) { ItemEMail *email = addritem_create_item_email(); addritem_email_set_address( email, str ); str = nodeRemarks->data; if( nodeRemarks ) { if( str ) { if( g_strcasecmp( str, "internet" ) != 0 ) { if( *str != '\0' ) addritem_email_set_remarks( email, str ); } } } addrcache_id_email( cardFile->addressCache, email ); addrcache_person_add_email( cardFile->addressCache, person, email ); } nodeAddress = g_slist_next( nodeAddress ); nodeRemarks = g_slist_next( nodeRemarks ); } if( person->listEMail ) { addrcache_id_person( cardFile->addressCache, person ); addrcache_add_person( cardFile->addressCache, person ); if( nodeID ) { str = nodeID->data; addritem_person_set_external_id( person, str ); } } else { addritem_free_item_person( person ); } nodeName = g_slist_next( nodeName ); nodeID = g_slist_next( nodeID ); } }
/* * Free hash table visitor function. */ static gint addrcache_free_item_vis( gpointer key, gpointer value, gpointer data ) { AddrItemObject *obj = ( AddrItemObject * ) value; if( ADDRITEM_TYPE(obj) == ITEMTYPE_PERSON ) { addritem_free_item_person( ( ItemPerson * ) obj ); } else if( ADDRITEM_TYPE(obj) == ITEMTYPE_EMAIL ) { addritem_free_item_email( ( ItemEMail * ) obj ); } else if( ADDRITEM_TYPE(obj) == ITEMTYPE_GROUP ) { addritem_free_item_group( ( ItemGroup * ) obj ); } else if( ADDRITEM_TYPE(obj) == ITEMTYPE_FOLDER ) { addritem_free_item_folder( ( ItemFolder * ) obj ); } key = NULL; value = NULL; return TRUE; }
/** * Clean up, close LDAP connection, and refresh cache * * \param ld Resource to LDAP * \param server AddressBook resource * \param contact GHashTable with current changed object */ void clean_up(LDAP *ld, LdapServer *server, GHashTable *contact) { ItemPerson *person = ldapsvr_get_contact(server, g_hash_table_lookup(contact , "uid")); if (person) { gchar *displayName; person->status = NONE; displayName = g_hash_table_lookup(contact, "displayName"); if (displayName) person->nickName = g_strdup(displayName); } if (server->retVal != LDAPRC_SUCCESS) { if (person) { ItemPerson *res = addrcache_remove_person(server->addressCache, person); if (!res) g_critical("ldapsvr_update_book: Could not clean cache\n"); else addritem_free_item_person(res); } } if (ld) ldapsvr_disconnect(ld); }
/* * Unpack address, building new data inside cache. */ static void jpilot_load_address( JPilotFile *pilotFile, buf_rec *buf, ItemFolder *folderInd[] ) { struct Address addr; gchar **addrEnt; gint num, k; gint cat_id = 0; guint unique_id; guchar attrib; gchar fullName[ FULLNAME_BUFSIZE ]; gchar bufEMail[ EMAIL_BUFSIZE ]; ItemPerson *person; ItemEMail *email; gint *indPhoneLbl; gchar *labelEntry; GList *node; gchar* extID; struct AddressAppInfo *ai; gchar **firstName = NULL; gchar **lastName = NULL; #if (PILOT_LINK_MAJOR > 11) pi_buffer_t *RecordBuffer; #endif /* PILOT_LINK_0_12 */ /* Retrieve address */ #if (PILOT_LINK_MAJOR < 12) num = unpack_Address( & addr, buf->buf, buf->size ); if( num > 0 ) { #else /* PILOT_LINK_0_12 */ RecordBuffer = pi_buffer_new(buf->size); memcpy(RecordBuffer->data, buf->buf, buf->size); RecordBuffer->used = buf->size; num = unpack_Address( & addr, RecordBuffer, address_v1 ); pi_buffer_free(RecordBuffer); if (num != -1) { #endif gchar *nameConv; addrEnt = addr.entry; attrib = buf->attrib; unique_id = buf->unique_id; cat_id = attrib & 0x0F; *fullName = *bufEMail = '\0'; if( addrEnt[ IND_LABEL_FIRSTNAME ] ) { firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 ); } if( addrEnt[ IND_LABEL_LASTNAME ] ) { lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 ); } if( name_order == FAMILY_LAST ) { g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", firstName ? firstName[0] : "", lastName ? lastName[0] : "" ); } else { g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", lastName ? lastName[0] : "", firstName ? firstName[0] : "" ); } if( firstName ) { g_strfreev( firstName ); } if( lastName ) { g_strfreev( lastName ); } g_strstrip( fullName ); nameConv = jpilot_convert_encoding( fullName ); strncpy2( fullName, nameConv, FULLNAME_BUFSIZE ); g_free( nameConv ); person = addritem_create_item_person(); addritem_person_set_common_name( person, fullName ); addritem_person_set_first_name( person, addrEnt[ IND_LABEL_FIRSTNAME ] ); addritem_person_set_last_name( person, addrEnt[ IND_LABEL_LASTNAME ] ); addrcache_id_person( pilotFile->addressCache, person ); extID = g_strdup_printf( "%d", unique_id ); addritem_person_set_external_id( person, extID ); g_free( extID ); extID = NULL; /* Pointer to address metadata. */ ai = & pilotFile->addrInfo; /* Add entry for each email address listed under phone labels. */ indPhoneLbl = addr.phoneLabel; for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) { gint ind; ind = indPhoneLbl[k]; /* * fprintf( stdout, "%d : %d : %20s : %s\n", k, ind, * ai->phoneLabels[ind], addrEnt[3+k] ); */ if( indPhoneLbl[k] == IND_PHONE_EMAIL ) { labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ]; if( labelEntry ) { strcpy( bufEMail, labelEntry ); g_strchug( bufEMail ); g_strchomp( bufEMail ); email = addritem_create_item_email(); addritem_email_set_address( email, bufEMail ); addrcache_id_email( pilotFile->addressCache, email ); addrcache_person_add_email ( pilotFile->addressCache, person, email ); } } } /* Add entry for each custom label */ node = pilotFile->labelInd; while( node ) { gint ind; ind = GPOINTER_TO_INT( node->data ); if( ind > -1 ) { /* * fprintf( stdout, "%d : %20s : %s\n", ind, ai->labels[ind], * addrEnt[ind] ); */ labelEntry = addrEnt[ind]; if( labelEntry ) { gchar *convertBuff; strcpy( bufEMail, labelEntry ); g_strchug( bufEMail ); g_strchomp( bufEMail ); email = addritem_create_item_email(); addritem_email_set_address( email, bufEMail ); convertBuff = jpilot_convert_encoding( ai->labels[ind] ); addritem_email_set_remarks( email, convertBuff ); g_free( convertBuff ); addrcache_id_email( pilotFile->addressCache, email ); addrcache_person_add_email ( pilotFile->addressCache, person, email ); } } node = g_list_next( node ); } if( person->listEMail ) { if( cat_id > -1 && cat_id < JPILOT_NUM_CATEG ) { /* Add to specified category */ addrcache_folder_add_person ( pilotFile->addressCache, folderInd[cat_id], person ); } else { /* Add to root folder */ addrcache_add_person( pilotFile->addressCache, person ); } } else { addritem_free_item_person( person ); person = NULL; } } } /* * Free up address list. */ static void jpilot_free_addrlist( GList *records ) { GList *node; buf_rec *br; node = records; while( node ) { br = node->data; free( br ); node->data = NULL; node = g_list_next( node ); } /* Free up list */ g_list_free( records ); }
/** * Unpack address, building new data inside cache. * \param pilotFile JPilot control data. * \param buf Record buffer. * \param folderInd Array of (category) folders to load. */ static void jpilot_load_address( JPilotFile *pilotFile, buf_rec *buf, ItemFolder *folderInd[] ) { struct Address addr; gchar **addrEnt; gint num, k; gint cat_id = 0; guint unique_id; guchar attrib; gchar fullName[ FULLNAME_BUFSIZE ]; ItemPerson *person; gint *indPhoneLbl; gchar *labelEntry; GList *node; gchar* extID; struct AddressAppInfo *ai; gchar **firstName = NULL; gchar **lastName = NULL; /* Retrieve address */ num = unpack_Address( & addr, buf->buf, buf->size ); if( num > 0 ) { addrEnt = addr.entry; attrib = buf->attrib; unique_id = buf->unique_id; cat_id = attrib & 0x0F; *fullName = '\0'; if( addrEnt[ IND_LABEL_FIRSTNAME ] ) { firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 ); } if( addrEnt[ IND_LABEL_LASTNAME ] ) { lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 ); } if( name_order == FAMILY_LAST ) { g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", firstName ? firstName[0] : "", lastName ? lastName[0] : "" ); } else { g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", lastName ? lastName[0] : "", firstName ? firstName[0] : "" ); } if( firstName ) { g_strfreev( firstName ); } if( lastName ) { g_strfreev( lastName ); } g_strstrip( fullName ); if( convert_charcode ) { gchar *nameConv; nameConv = g_strdup( fullName ); conv_sjistoeuc( fullName, FULLNAME_BUFSIZE, nameConv ); g_free( nameConv ); } person = addritem_create_item_person(); addritem_person_set_common_name( person, fullName ); addritem_person_set_first_name( person, addrEnt[ IND_LABEL_FIRSTNAME ] ); addritem_person_set_last_name( person, addrEnt[ IND_LABEL_LASTNAME ] ); addrcache_id_person( pilotFile->addressCache, person ); extID = g_strdup_printf( "%d", unique_id ); addritem_person_set_external_id( person, extID ); g_free( extID ); extID = NULL; /* Pointer to address metadata. */ ai = & pilotFile->addrInfo; /* Add entry for each email address listed under phone labels. */ indPhoneLbl = addr.phoneLabel; for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) { gint ind; ind = indPhoneLbl[k]; /* * fprintf( stdout, "%d : %d : %20s : %s\n", k, ind, * ai->phoneLabels[ind], addrEnt[3+k] ); */ if( indPhoneLbl[k] == IND_PHONE_EMAIL ) { labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ]; jpilot_parse_label( pilotFile, labelEntry, person ); } } /* Add entry for each custom label */ node = pilotFile->labelInd; while( node ) { gchar convertBuff[JPILOT_LEN_LABEL]; gint ind; ind = GPOINTER_TO_INT( node->data ); if( ind > -1 ) { /* * fprintf( stdout, "%d : %20s : %s\n", ind, ai->labels[ind], * addrEnt[ind] ); */ labelEntry = addrEnt[ind]; jpilot_parse_label( pilotFile, labelEntry, person ); } node = g_list_next( node ); } if( person->listEMail ) { if( cat_id > -1 && cat_id < JPILOT_NUM_CATEG ) { /* Add to specified category */ addrcache_folder_add_person( pilotFile->addressCache, folderInd[cat_id], person ); } else { /* Add to root folder */ addrcache_add_person( pilotFile->addressCache, person ); } } else { addritem_free_item_person( person ); person = NULL; } } /* Free up pointer allocated inside address */ free_Address( & addr ); }