Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
DirectoryTool - Blob - ViewGit - Blue Static
/*
 * Directory Tool
 * Copyright (c) 2002 - 2007, Blue Static <http://www.bluestatic.org>
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#import "BSDirectoryRecordType.h"
#import "BSDirectoryRecord.h"

@implementation BSDirectoryRecordType

@synthesize name;
@synthesize fullName;

/**
 * Initializer
 */
- (id)initWithFullName:(NSString *)aName
				inNode:(BSDirectoryNode *)aNode
{
	if (self = [super init])
	{
		node = aNode;
		dirRef = node.service.dirRef;
		nodeRef = node.nodeRef;

		fullName = aName;
		NSRange range = [fullName rangeOfString:@":" options:NSBackwardsSearch];
		range.location = range.location + 1;
		range.length = [fullName length] - range.location;
		name = [fullName substringWithRange:range];
	}
	return self;
}

/**
 * Gets all the children of a specified type
 */
- (NSArray *)children
{
	NSMutableArray *records = [NSMutableArray array];

	tDataList recordNames;
	CK_STATUS_R(dsBuildListFromStringsAlloc(dirRef, &recordNames, kDSRecordsAll, NULL), @"could not allocate record names list", nil);

	tDataList recordTypes;
	CK_STATUS_R(dsBuildListFromStringsAlloc(dirRef, &recordTypes, [name UTF8String], NULL), @"could not allocate record types list", nil);

	tDataList attributesTypes;
	CK_STATUS_R(dsBuildListFromStringsAlloc(dirRef, &attributesTypes, kDSAttributesAll, NULL), @"could not allocate attribute types list", nil);

	tDataBufferPtr buffer = dsDataBufferAllocate(dirRef, 3 * 1024);
	unsigned long count = 0;
	tContextData context = NULL;
	CK_STATUS(dsGetRecordList(nodeRef, buffer, &recordNames, eDSExact, &recordTypes, &attributesTypes, false, &count, &context), @"could not get record list");

	for (unsigned long i = 1; i <= count; i++)
	{
		tAttributeListRef attributeList;
		tRecordEntry *record;
		CK_STATUS_C(dsGetRecordEntry(nodeRef, buffer, i, &attributeList, &record), @"could not open record");

		[records addObject:[[BSDirectoryRecord alloc] initWithRecord:record withAttributes:attributeList inNode:node]];
	}

	dsDataBufferDeAllocate(dirRef, buffer);
	dsDataListDeallocate(dirRef, &recordNames);
	dsDataListDeallocate(dirRef, &recordTypes);
	dsDataListDeallocate(dirRef, &attributesTypes);

	return records;
}

@end