Adding a method to get all the attributes for a node
Adding a method to get all the attributes for a node
* Source/AppController.m: added test implementation
* Source/BSDirectoryNode.m:
* Source/BSDirectoryNode.h:
([BSDirectoryNode attributes]): New method
diff --git a/Source/AppController.m b/Source/AppController.m
index bc4aa03..b7eb952 100644
--- a/Source/AppController.m
+++ b/Source/AppController.m
@@ -31,6 +31,7 @@
{
NSLog(@"node = %@", [node name]);
[node open];
+ [node attributes];
for (BSDirectoryRecord *record in [node records])
{
[record attributes];
diff --git a/Source/BSDirectoryNode.h b/Source/BSDirectoryNode.h
index 04a15d5..a6866e5 100644
--- a/Source/BSDirectoryNode.h
+++ b/Source/BSDirectoryNode.h
@@ -30,5 +30,6 @@
- (void)open;
- (NSArray *)records;
+- (NSDictionary *)attributes;
@end
diff --git a/Source/BSDirectoryNode.m b/Source/BSDirectoryNode.m
index f568523..67af079 100644
--- a/Source/BSDirectoryNode.m
+++ b/Source/BSDirectoryNode.m
@@ -153,4 +153,54 @@
return records;
}
+/**
+ * Gets an NSDictionary of all the attributes a node has
+ */
+- (NSDictionary *)attributes
+{
+ tDataList infoTypes;
+ dsBuildListFromStringsAlloc(dirRef, &infoTypes, kDSAttributesAll, NULL);
+
+ tDataBuffer *buffer = dsDataBufferAllocate(dirRef, 1024 * 1024);
+ unsigned long count;
+ tAttributeListRef attrList;
+ tContextData context;
+ tDirStatus status = dsGetDirNodeInfo(nodeRef, &infoTypes, buffer, false, &count, &attrList, &context);
+ if (status != eDSNoErr)
+ {
+ NSLog(@"could not get node info: %i", status);
+ return nil;
+ }
+
+ unsigned long i = 1;
+ for ( ; i <= count; i++)
+ {
+ tAttributeValueListRef valueListRef = 0;
+ tAttributeEntryPtr infoRef = 0;
+ dsGetAttributeEntry(nodeRef, buffer, attrList, i, &valueListRef, &infoRef);
+
+ unsigned long j = 1;
+ for ( ; j <= infoRef->fAttributeValueCount; j++)
+ {
+ tAttributeValueEntryPtr valueRef;
+ dsGetAttributeValue(nodeRef, buffer, j, valueListRef, &valueRef);
+
+ NSLog(@"%s : %i", valueRef->fAttributeValueData.fBufferData, valueRef->fAttributeValueID);
+
+ dsDeallocAttributeValueEntry(dirRef, valueRef);
+ }
+
+ dsCloseAttributeValueList(valueListRef);
+ dsDeallocAttributeEntry(dirRef, infoRef);
+ }
+
+ NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
+
+ dsDataListDeallocate(dirRef, &infoTypes);
+ dsDataBufferDeAllocate(dirRef, buffer);
+ dsCloseAttributeList(attrList);
+
+ return attributes;
+}
+
@end