Beispiel #1
0
/*
* 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;
}
Beispiel #2
0
/**
 * 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);
}