[CalendarServer-changes] [1919] PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 27 12:14:57 PDT 2007


Revision: 1919
          http://trac.macosforge.org/projects/calendarserver/changeset/1919
Author:   cdaboo at apple.com
Date:     2007-09-27 12:14:56 -0700 (Thu, 27 Sep 2007)

Log Message:
-----------
Api changes to allow multiple records with the same short name to be returned. The return value is now an array
instead of a dict.

Modified Paths:
--------------
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/pysrc/opendirectory.py
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.cpp
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.h
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/PythonWrapper.cpp
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test.py
    PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test_auth.py

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/pysrc/opendirectory.py
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/pysrc/opendirectory.py	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/pysrc/opendirectory.py	2007-09-27 19:14:56 UTC (rev 1919)
@@ -36,8 +36,8 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
 
 def queryRecordsWithAttribute(obj, attr, value, matchType, casei, recordType, attributes):
@@ -51,8 +51,8 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
 
 def queryRecordsWithAttributes(obj, compound, casei, recordType, attributes):
@@ -64,8 +64,8 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
 
 def authenticateUserBasic(obj, guid, user, pswd):

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.cpp
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.cpp	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.cpp	2007-09-27 19:14:56 UTC (rev 1919)
@@ -85,11 +85,12 @@
 //
 // @param recordType: the record type to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
-// @return: CFMutableDictionaryRef composed of CFMutableDictionaryRef of CFStringRef key and value entries
-//			for each attribute/value requested in the record indexed by uid,
+// @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
+//          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
+//			and value entries for each attribute/value requested in the record indexed by uid,
 //		    or NULL if it fails.
 //
-CFMutableDictionaryRef CDirectoryService::ListAllRecordsWithAttributes(const char* recordType, CFArrayRef attributes)
+CFMutableArrayRef CDirectoryService::ListAllRecordsWithAttributes(const char* recordType, CFArrayRef attributes)
 {
 	try
 	{
@@ -118,11 +119,12 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param recordType: the record type to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
-// @return: CFMutableDictionaryRef composed of CFMutableDictionaryRef of CFStringRef key and value entries
-//			for each attribute/value requested in the record indexed by uid,
+// @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
+//          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
+//			and value entries for each attribute/value requested in the record indexed by uid,
 //		    or NULL if it fails.
 //
-CFMutableDictionaryRef CDirectoryService::QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, const char* recordType, CFArrayRef attributes)
+CFMutableArrayRef CDirectoryService::QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, const char* recordType, CFArrayRef attributes)
 {
 	try
 	{
@@ -149,11 +151,12 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param recordType: the record type to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
-// @return: CFMutableDictionaryRef composed of CFMutableDictionaryRef of CFStringRef key and value entries
-//			for each attribute/value requested in the record indexed by uid,
+// @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
+//          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
+//			and value entries for each attribute/value requested in the record indexed by uid,
 //		    or NULL if it fails.
 //
-CFMutableDictionaryRef CDirectoryService::QueryRecordsWithAttributes(const char* query, bool casei, const char* recordType, CFArrayRef attributes)
+CFMutableArrayRef CDirectoryService::QueryRecordsWithAttributes(const char* query, bool casei, const char* recordType, CFArrayRef attributes)
 {
 	try
 	{
@@ -237,14 +240,16 @@
 // @param type: the record type to check.
 // @param names: a list of record names to target if NULL all records are matched.
 // @param attrs: a list of attributes to return.
-// @return: CFMutableDictionaryRef composed of CFMutableDictionaryRef of CFStringRef key and value entries
-//			for each attribute/value requested in the record indexed by uid,
+// @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
+//          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
+//			and value entries for each attribute/value requested in the record indexed by uid,
 //		    or NULL if it fails.
 //
-CFMutableDictionaryRef CDirectoryService::_ListAllRecordsWithAttributes(const char* type, CFArrayRef names, CFArrayRef attrs)
+CFMutableArrayRef CDirectoryService::_ListAllRecordsWithAttributes(const char* type, CFArrayRef names, CFArrayRef attrs)
 {
-	CFMutableDictionaryRef result = NULL;
-	CFMutableDictionaryRef vresult = NULL;
+	CFMutableArrayRef result = NULL;
+	CFMutableArrayRef record_tuple = NULL;
+	CFMutableDictionaryRef record = NULL;
 	CFMutableArrayRef values = NULL;
 	tDataListPtr recNames = NULL;
 	tDataListPtr recTypes = NULL;
@@ -286,7 +291,7 @@
 		ThrowIfNULL(attrTypes);
 		BuildStringDataList(attrs, attrTypes);
 		
-		result = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+		result = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
 		
 		do
 		{
@@ -311,7 +316,7 @@
 				std::auto_ptr<char> recname(temp);
 				
 				// Create a dictionary for the values
-				vresult = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+				record = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 				
 				// Look at each requested attribute and get one value
 				for(unsigned long j = 1; j <= pRecEntry->fRecordAttributeCount; j++)
@@ -342,7 +347,7 @@
 								::dsDeallocAttributeValueEntry(mDir, attributeValue);
 								attributeValue = NULL;
 							}
-							::CFDictionarySetValue(vresult, cfattrname.get(), values);
+							::CFDictionarySetValue(record, cfattrname.get(), values);
 							::CFRelease(values);
 							values = NULL;
 						}
@@ -353,7 +358,7 @@
 							ThrowIfDSErr(::dsGetAttributeValue(mNode, mData, 1, attributeValueListRef, &attributeValue));
 							std::auto_ptr<char> data(CStringFromBuffer(&attributeValue->fAttributeValueData));
 							CFStringUtil strvalue(data.get());
-							::CFDictionarySetValue(vresult, cfattrname.get(), strvalue.get());
+							::CFDictionarySetValue(record, cfattrname.get(), strvalue.get());
 							::dsDeallocAttributeValueEntry(mDir, attributeValue);
 							attributeValue = NULL;
 						}
@@ -365,12 +370,20 @@
 					attributeInfoPtr = NULL;
 				}
 				
-				// Add dictionary of values to result array
+				// Create tuple of record name and record values
 				CFStringUtil str(recname.get());
-				::CFDictionarySetValue(result, str.get(), vresult);
-				::CFRelease(vresult);
-				vresult = NULL;
 				
+				record_tuple = ::CFArrayCreateMutable(kCFAllocatorDefault, 2, &kCFTypeArrayCallBacks);
+				::CFArrayAppendValue(record_tuple, str.get());
+				::CFArrayAppendValue(record_tuple, record);
+				::CFRelease(record);
+				record = NULL;
+
+				// Append tuple to results array
+				::CFArrayAppendValue(result, record_tuple);
+				::CFRelease(record_tuple);
+				record_tuple = NULL;
+				
 				// Clean-up
 				::dsCloseAttributeList(attrListRef);
 				attrListRef = 0L;
@@ -426,11 +439,16 @@
 			::CFRelease(values);
 			values = NULL;
 		}
-		if (vresult != NULL)
+		if (record != NULL)
 		{
-			::CFRelease(vresult);
-			vresult = NULL;
+			::CFRelease(record);
+			record = NULL;
 		}
+		if (record_tuple != NULL)
+		{
+			::CFRelease(record_tuple);
+			record_tuple = NULL;
+		}
 		if (result != NULL)
 		{
 			::CFRelease(result);
@@ -453,14 +471,16 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param type: the record type to check.
 // @param attrs: a list of attributes to return.
-// @return: CFMutableDictionaryRef composed of CFMutableDictionaryRef of CFStringRef key and value entries
-//			for each attribute/value requested in the record indexed by uid,
+// @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
+//          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
+//			and value entries for each attribute/value requested in the record indexed by uid,
 //		    or NULL if it fails.
 //
-CFMutableDictionaryRef CDirectoryService::_QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, const char* type, CFArrayRef attrs)
+CFMutableArrayRef CDirectoryService::_QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, const char* type, CFArrayRef attrs)
 {
-	CFMutableDictionaryRef result = NULL;
-	CFMutableDictionaryRef vresult = NULL;
+	CFMutableArrayRef result = NULL;
+	CFMutableArrayRef record_tuple = NULL;
+	CFMutableDictionaryRef record = NULL;
 	CFMutableArrayRef values = NULL;
 	tDataNodePtr queryAttr = NULL;
 	tDataNodePtr queryValue = NULL;
@@ -520,7 +540,7 @@
 		ThrowIfNULL(attrTypes);
 		BuildStringDataList(attrs, attrTypes);
 		
-		result = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+		result = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
 		
 		do
 		{
@@ -545,7 +565,7 @@
 				std::auto_ptr<char> recname(temp);
 				
 				// Create a dictionary for the values
-				vresult = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+				record = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 				
 				// Look at each requested attribute and get one value
 				for(unsigned long j = 1; j <= pRecEntry->fRecordAttributeCount; j++)
@@ -576,7 +596,7 @@
 								::dsDeallocAttributeValueEntry(mDir, attributeValue);
 								attributeValue = NULL;
 							}
-							::CFDictionarySetValue(vresult, cfattrname.get(), values);
+							::CFDictionarySetValue(record, cfattrname.get(), values);
 							::CFRelease(values);
 							values = NULL;
 						}
@@ -587,7 +607,7 @@
 							ThrowIfDSErr(::dsGetAttributeValue(mNode, mData, 1, attributeValueListRef, &attributeValue));
 							std::auto_ptr<char> data(CStringFromBuffer(&attributeValue->fAttributeValueData));
 							CFStringUtil strvalue(data.get());
-							::CFDictionarySetValue(vresult, cfattrname.get(), strvalue.get());
+							::CFDictionarySetValue(record, cfattrname.get(), strvalue.get());
 							::dsDeallocAttributeValueEntry(mDir, attributeValue);
 							attributeValue = NULL;
 						}
@@ -599,12 +619,20 @@
 					attributeInfoPtr = NULL;
 				}
 				
-				// Add dictionary of values to result array
+				// Create tuple of record name and record values
 				CFStringUtil str(recname.get());
-				::CFDictionarySetValue(result, str.get(), vresult);
-				::CFRelease(vresult);
-				vresult = NULL;
 				
+				record_tuple = ::CFArrayCreateMutable(kCFAllocatorDefault, 2, &kCFTypeArrayCallBacks);
+				::CFArrayAppendValue(record_tuple, str.get());
+				::CFArrayAppendValue(record_tuple, record);
+				::CFRelease(record);
+				record = NULL;
+
+				// Append tuple to results array
+				::CFArrayAppendValue(result, record_tuple);
+				::CFRelease(record_tuple);
+				record_tuple = NULL;
+
 				// Clean-up
 				::dsCloseAttributeList(attrListRef);
 				attrListRef = 0L;
@@ -664,11 +692,16 @@
 			::CFRelease(values);
 			values = NULL;
 		}
-		if (vresult != NULL)
+		if (record != NULL)
 		{
-			::CFRelease(vresult);
-			vresult = NULL;
+			::CFRelease(record);
+			record = NULL;
 		}
+		if (record_tuple != NULL)
+		{
+			::CFRelease(record_tuple);
+			record_tuple = NULL;
+		}
 		if (result != NULL)
 		{
 			::CFRelease(result);
@@ -698,22 +731,20 @@
 	::CFArrayAppendValue(attrs, cfattr.get());
 	
 	// First list the record for the current GUID and get its node.
-	CFMutableDictionaryRef found = _QueryRecordsWithAttributes(kDS1AttrGeneratedUID, guid, eDSExact, NULL, false, kDSStdRecordTypeUsers, attrs);
+	CFMutableArrayRef found = _QueryRecordsWithAttributes(kDS1AttrGeneratedUID, guid, eDSExact, NULL, false, kDSStdRecordTypeUsers, attrs);
 	::CFRelease(attrs);
 	if (found == NULL)
 		return result;
 
 	// Must have only one result
-	if (CFDictionaryGetCount(found) != 1)
+	if (CFArrayGetCount(found) != 1)
 	{
 		::CFRelease(found);
 		return result;
 	}
 
-	// Now extract the returned data.
-	const void* dictvalues[1] = {NULL};
-	::CFDictionaryGetKeysAndValues(found, NULL, &dictvalues[0]);
-	CFDictionaryRef dictvalue = (CFDictionaryRef)dictvalues[0];
+	// Now extract the returned record data.
+	CFDictionaryRef dictvalue = (CFDictionaryRef)::CFArrayGetValueAtIndex((CFArrayRef)::CFArrayGetValueAtIndex(found, 0), 1);
 	if ((dictvalue == NULL) || (::CFDictionaryGetCount(dictvalue) == 0))
 	{
 		::CFRelease(found);

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.h
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.h	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/CDirectoryService.h	2007-09-27 19:14:56 UTC (rev 1919)
@@ -32,9 +32,9 @@
 	CDirectoryService(const char* nodename);
 	~CDirectoryService();
 	
-	CFMutableDictionaryRef ListAllRecordsWithAttributes(const char* recordType, CFArrayRef attributes);
-	CFMutableDictionaryRef QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, const char* recordType, CFArrayRef attributes);
-	CFMutableDictionaryRef QueryRecordsWithAttributes(const char* query, bool casei, const char* recordType, CFArrayRef attributes);
+	CFMutableArrayRef ListAllRecordsWithAttributes(const char* recordType, CFArrayRef attributes);
+	CFMutableArrayRef QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, const char* recordType, CFArrayRef attributes);
+	CFMutableArrayRef QueryRecordsWithAttributes(const char* query, bool casei, const char* recordType, CFArrayRef attributes);
 
 	bool AuthenticateUserBasic(const char* guid, const char* user, const char* pswd, bool& result);
 	bool AuthenticateUserDigest(const char* guid, const char* user, const char* challenge, const char* response, const char* method, bool& result);
@@ -53,8 +53,8 @@
 	tDataBufferPtr		mData;
 	UInt32				mDataSize;
 	
-	CFMutableDictionaryRef _ListAllRecordsWithAttributes(const char* type, CFArrayRef names, CFArrayRef attrs);
-	CFMutableDictionaryRef _QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, const char* recordType, CFArrayRef attributes);
+	CFMutableArrayRef _ListAllRecordsWithAttributes(const char* type, CFArrayRef names, CFArrayRef attrs);
+	CFMutableArrayRef _QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, const char* recordType, CFArrayRef attributes);
 
 	CFStringRef CDirectoryService::AuthenticationGetNode(const char* guid);
 	bool NativeAuthenticationBasic(const char* guid, const char* user, const char* pswd);

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/PythonWrapper.cpp
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/PythonWrapper.cpp	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/src/PythonWrapper.cpp	2007-09-27 19:14:56 UTC (rev 1919)
@@ -144,6 +144,43 @@
 	return result;
 }
 
+// Utility function - not exposed to Python
+static PyObject* CFArrayStringDictionaryToPyList(CFArrayRef list)
+{
+	CFIndex lsize = (list != NULL) ? CFArrayGetCount(list) : 0;
+	if (lsize != 2)
+		return NULL;
+	
+	PyObject* result = PyList_New(lsize);
+
+	CFStringRef str = (CFStringRef)CFArrayGetValueAtIndex(list, 0);
+	PyObject* pystr = CFStringToPyStr(str);
+	PyList_SetItem(result, 0, pystr);
+	
+	CFDictionaryRef dict = (CFDictionaryRef)CFArrayGetValueAtIndex(list, 1);
+	PyObject* pydict = CFDictionaryToPyDict(dict);
+	PyList_SetItem(result, 1, pydict);
+	
+	return result;
+}
+
+// Utility function - not exposed to Python
+static PyObject* CFArrayArrayDictionaryToPyList(CFArrayRef list)
+{
+	CFIndex lsize = (list != NULL) ? CFArrayGetCount(list) : 0;
+	
+	PyObject* result = PyList_New(lsize);
+	for(CFIndex i = 0, j = 0; i < lsize; i++)
+	{
+		CFArrayRef nested = (CFArrayRef)CFArrayGetValueAtIndex(list, i);
+		PyObject* pylist = CFArrayStringDictionaryToPyList(nested);
+		if (pylist != NULL)
+			PyList_SetItem(result, j++, pylist);
+	}
+	
+	return result;
+}
+
 PyObject* ODException_class = NULL;
 
 /*
@@ -193,8 +230,8 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
  */
 extern "C" PyObject *listAllRecordsWithAttributes(PyObject *self, PyObject *args)
@@ -219,11 +256,11 @@
 	CDirectoryService* ds = static_cast<CDirectoryService*>(PyCObject_AsVoidPtr(pyds));
 	if (ds != NULL)
 	{
-		CFMutableDictionaryRef dict = ds->ListAllRecordsWithAttributes(recordType, cfattributes);
-		if (dict != NULL)
+		CFMutableArrayRef list = ds->ListAllRecordsWithAttributes(recordType, cfattributes);
+		if (list != NULL)
 		{
-			PyObject* result = CFDictionaryDictionaryToPyDict(dict);
-			CFRelease(dict);
+			PyObject* result = CFArrayArrayDictionaryToPyList(list);
+			CFRelease(list);
 			CFRelease(cfattributes);
 			
 			return result;
@@ -248,8 +285,8 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
  */
 extern "C" PyObject *queryRecordsWithAttribute(PyObject *self, PyObject *args)
@@ -282,11 +319,11 @@
 	CDirectoryService* ds = static_cast<CDirectoryService*>(PyCObject_AsVoidPtr(pyds));
 	if (ds != NULL)
 	{
-		CFMutableDictionaryRef dict = ds->QueryRecordsWithAttribute(attr, value, matchType, casei, recordType, cfattributes);
-		if (dict != NULL)
+		CFMutableArrayRef list = ds->QueryRecordsWithAttribute(attr, value, matchType, casei, recordType, cfattributes);
+		if (list != NULL)
 		{
-			PyObject* result = CFDictionaryDictionaryToPyDict(dict);
-			CFRelease(dict);
+			PyObject* result = CFArrayArrayDictionaryToPyList(list);
+			CFRelease(list);
 			CFRelease(cfattributes);
 			
 			return result;
@@ -309,8 +346,8 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str} containing the OD record type to lookup.
     @param attributes: C{list} containing the attributes to return for each record.
-    @return: C{dict} containing a C{dict} of attributes for each record found, 
-        or C{None} otherwise.
+    @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
+         for each record found, or C{None} otherwise.
     """
  */
 extern "C" PyObject *queryRecordsWithAttributes(PyObject *self, PyObject *args)
@@ -341,11 +378,11 @@
 	CDirectoryService* ds = static_cast<CDirectoryService*>(PyCObject_AsVoidPtr(pyds));
 	if (ds != NULL)
 	{
-		CFMutableDictionaryRef dict = ds->QueryRecordsWithAttributes(query, casei, recordType, cfattributes);
-		if (dict != NULL)
+		CFMutableArrayRef list = ds->QueryRecordsWithAttributes(query, casei, recordType, cfattributes);
+		if (list != NULL)
 		{
-			PyObject* result = CFDictionaryDictionaryToPyDict(dict);
-			CFRelease(dict);
+			PyObject* result = CFArrayArrayDictionaryToPyList(list);
+			CFRelease(list);
 			CFRelease(cfattributes);
 			
 			return result;

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test.py
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test.py	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test.py	2007-09-27 19:14:56 UTC (rev 1919)
@@ -34,12 +34,11 @@
 		if d is None:
 			print "Failed to list users"
 		else:
-			names = [v for v in d.iterkeys()]
-			names.sort()
-			print "\nlistUsers number of results = %d" % (len(names),)
-			for n in names:
-				print "Name: %s" % n
-				print "dict: %s" % str(d[n])
+			d.sort(cmp=lambda x, y: x[0] < y[0])
+			print "\nlistUsers number of results = %d" % (len(d),)
+			for name, record in d:
+				print "Name: %s" % name
+				print "dict: %s" % str(record)
 	
 	def listGroups():
 		d = opendirectory.listAllRecordsWithAttributes(ref, dsattributes.kDSStdRecordTypeGroups,
@@ -47,12 +46,11 @@
 		if d is None:
 			print "Failed to list groups"
 		else:
-			names = [v for v in d.iterkeys()]
-			names.sort()
-			print "\nlistGroups number of results = %d" % (len(names),)
-			for n in names:
-				print "Name: %s" % n
-				print "dict: %s" % str(d[n])
+			d.sort(cmp=lambda x, y: x[0] < y[0])
+			print "\nlistGroups number of results = %d" % (len(d),)
+			for name, record in d:
+				print "Name: %s" % name
+				print "dict: %s" % str(record)
 	
 	def listComputers():
 		d = opendirectory.listAllRecordsWithAttributes(ref, dsattributes.kDSStdRecordTypeComputers,
@@ -60,12 +58,11 @@
 		if d is None:
 			print "Failed to list computers"
 		else:
-			names = [v for v in d.iterkeys()]
-			names.sort()
-			print "\nlistComputers number of results = %d" % (len(names),)
-			for n in names:
-				print "Name: %s" % n
-				print "dict: %s" % str(d[n])
+			d.sort(cmp=lambda x, y: x[0] < y[0])
+			print "\nlistComputers number of results = %d" % (len(d),)
+			for name, record in d:
+				print "Name: %s" % name
+				print "dict: %s" % str(record)
 	
 	def querySimple(title, attr, value, matchType, casei, recordType, attrs):
 		d = opendirectory.queryRecordsWithAttribute(
@@ -80,12 +77,11 @@
 		if d is None:
 			print "Failed to query users"
 		else:
-			names = [v for v in d.iterkeys()]
-			names.sort()
-			print "\n%s number of results = %d" % (title, len(names),)
-			for n in names:
-				print "Name: %s" % n
-				print "dict: %s" % str(d[n])
+			d.sort(cmp=lambda x, y: x[0] < y[0])
+			print "\n%s number of results = %d" % (title, len(d),)
+			for name, record in d:
+				print "Name: %s" % name
+				print "dict: %s" % str(record)
 		
 	def queryCompound(title, compound, casei, recordType, attrs):
 		d = opendirectory.queryRecordsWithAttributes(
@@ -98,12 +94,11 @@
 		if d is None:
 			print "Failed to query users"
 		else:
-			names = [v for v in d.iterkeys()]
-			names.sort()
-			print "\n%s number of results = %d" % (title, len(names),)
-			for n in names:
-				print "Name: %s" % n
-				print "dict: %s" % str(d[n])
+			d.sort(cmp=lambda x, y: x[0] < y[0])
+			print "\n%s number of results = %d" % (title, len(d),)
+			for name, record in d:
+				print "Name: %s" % name
+				print "dict: %s" % str(record)
 		
 	def queryUsers():
 		querySimple(
@@ -155,9 +150,9 @@
 		else:
 			print "Failed to authenticate user"
 	
-	#listUsers()
-	#listGroups()
-	#listComputers()
+	listUsers()
+	listGroups()
+	listComputers()
 	queryUsers()
 	queryUsersCompoundOr()
 	queryUsersCompoundOrExact()

Modified: PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test_auth.py
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test_auth.py	2007-09-27 19:09:51 UTC (rev 1918)
+++ PyOpenDirectory/branches/users/cdaboo/multiple-computer-records-1917/test_auth.py	2007-09-27 19:14:56 UTC (rev 1919)
@@ -123,7 +123,7 @@
         False,
         dsattributes.kDSStdRecordTypeUsers,
         [dsattributes.kDS1AttrGeneratedUID])
-    guid = result[username][dsattributes.kDS1AttrGeneratedUID]
+    guid = result[0][1][dsattributes.kDS1AttrGeneratedUID]
     
     expected = calcResponse(
                 calcHA1(algorithm, username, realm, password, nonce, cnonce),
@@ -173,7 +173,7 @@
         False,
         dsattributes.kDSStdRecordTypeUsers,
         [dsattributes.kDS1AttrGeneratedUID])
-    guid = result[username][dsattributes.kDS1AttrGeneratedUID]
+    guid = result[0][1][dsattributes.kDS1AttrGeneratedUID]
     
     for x in xrange(attempts):
         success = opendirectory.authenticateUserBasic(
@@ -196,6 +196,4 @@
 
 doAuthBasic(user, pswd)
 doAuthDigest(user, pswd, None, "md5")
-#doAuth(user, pswd, "auth", "md5")
-#doAuth(user, pswd, "auth", "md5-sess")
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070927/81f68235/attachment.html


More information about the calendarserver-changes mailing list