[CalendarServer-changes] [8919] CalendarServer/branches/users/gaya/ldapdirectorybacker
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 21 17:02:26 PDT 2012
Revision: 8919
http://trac.macosforge.org/projects/calendarserver/changeset/8919
Author: gaya at apple.com
Date: 2012-03-21 17:02:25 -0700 (Wed, 21 Mar 2012)
Log Message:
-----------
VCardRecord -> VCardResource
Modified Paths:
--------------
CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist
CalendarServer/branches/users/gaya/ldapdirectorybacker/support/CalendarServer.xcodeproj/project.pbxproj
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/test/test_opendirectorybacker.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/xmldirectorybacker.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_addressbook_query.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_multiget_common.py
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist 2012-03-22 00:02:25 UTC (rev 8919)
@@ -1136,157 +1136,152 @@
<dict>
<key>base</key>
<string>o=apple</string>
- <key>queryTypes</key>
- <array>
- <string>people</string>
- <string>distribution list</string>
- </array>
- <!-- user vCards -->
- <key>people</key>
- <dict>
- <key>rdn</key>
- <string>ou=people</string>
- <key>filter</key>
- <string></string>
- <!-- map from ab query to indexed ldap attribute. If unindexed, too slow. -->
- <key>vcardPropToLdapAttrMap</key>
- <dict>
- <key>FN</key>
- <string>cn</string>
- <key>EMAIL</key>
- <string>mail</string>
- <key>TEL</key>
- <string>telephoneNumber</string>
- <key>UID</key>
- <string>appleDSID</string>
+ <key>queries</key>
+ <array>
+ <!-- user vCards -->
+ <dict>
+ <key>rdn</key>
+ <string>ou=people</string>
+ <key>filter</key>
+ <string></string>
+ <!-- map from ab query to indexed ldap attribute. If unindexed, too slow. -->
+ <key>vcardPropToLdapAttrMap</key>
+ <dict>
+ <key>FN</key>
+ <string>cn</string>
+ <key>EMAIL</key>
+ <string>mail</string>
+ <key>TEL</key>
+ <string>telephoneNumber</string>
+ <key>UID</key>
+ <string>appleDSID</string>
+ </dict>
+ <!-- map ldap attributes to ds attribute types. -->
+ <key>ldapAttrToDSAttrMap</key>
+ <dict>
+ <key>givenName</key>
+ <string>FirstName</string>
+ <key>sn</key>
+ <string>LastName</string>
+ <key>cn</key>
+ <array>
+ <string>RealName</string>
+ <string>RecordName</string>
+ </array>
+ <key>applePhotoPreferred-jpeg</key>
+ <string>JPEGPhoto</string>
+ <key>buildingName</key>
+ <string>Building</string>
+ <key>destinationIndicator</key>
+ <string>Building</string>
+ <key>street</key>
+ <string>Street</string>
+ <key>l</key>
+ <string>City</string>
+ <key>st</key>
+ <string>State</string>
+ <key>postalCode</key>
+ <string>PostalCode</string>
+ <key>co</key>
+ <string>Country</string>
+ <key>telephoneNumber</key>
+ <string>PhoneNumber</string>
+ <key>appleSecondaryPhone</key>
+ <string>PhoneNumber</string>
+ <key>facsimileTelephoneNumber</key>
+ <string>FaxNumber</string>
+ <key>pager</key>
+ <string>PagerNumber</string>
+ <key>mobile</key>
+ <string>MobileNumber</string>
+ <key>mail</key>
+ <string>EMailAddress</string>
+ <key>applePreferredEmail</key>
+ <string>EMailAddress</string>
+ <key>appleNotificationEmail</key>
+ <string>EMailAddress</string>
+ <key>appleDSID</key>
+ <string>GeneratedUID</string>
+ <key>o</key>
+ <string>OrganizationName</string>
+ <key>ou</key>
+ <string>Department</string>
+ <key>appleAIMPreferred</key>
+ <string>IMHandle</string>
+ <key>appleAIMOfficial</key>
+ <string>IMHandle</string>
+ <key>appleManager</key>
+ <string>dsAttrTypeNative:appleManager</string>
+ </dict>
+ </dict>
+ <!-- mailing list vCards. Should mark as company-->
+ <dict>
+ <key>rdn</key>
+ <string>ou=groups</string>
+ <key>filter</key>
+ <string>(objectClass=appleGroup)</string>
+ <key>getAllAttributes</key>
+ <false/>
+ <key>vcardPropToLdapAttrMap</key>
+ <dict>
+ <key>EMAIL</key>
+ <string>appleGroupEmail</string>
+ <key>FN</key>
+ <string>description</string>
+ <key>UID</key>
+ <string>appleDSID</string>
+ </dict>
+ <key>ldapAttrToDSAttrMap</key>
+ <dict>
+ <key>cn</key>
+ <string>RecordName</string>
+ <key>description</key>
+ <array>
+ <string>RealName</string>
+ <string>OrganizationName</string>
+ </array>
+ <key>appleDSID</key>
+ <string>GeneratedUID</string>
+ <key>appleGroupContact</key>
+ <string>dsAttrTypeNative:appleManager</string>
+ <key>appleGroupEmail</key>
+ <string>EMailAddress</string>
+ </dict>
</dict>
- <!-- map ldap attributes to ds attribute types. -->
- <key>ldapAttrToDSAttrMap</key>
- <dict>
- <key>givenName</key>
- <string>FirstName</string>
- <key>sn</key>
- <string>LastName</string>
- <key>cn</key>
- <array>
- <string>RealName</string>
- <string>RecordName</string>
- </array>
- <key>applePhotoPreferred-jpeg</key>
- <string>JPEGPhoto</string>
- <key>buildingName</key>
- <string>Building</string>
- <key>destinationIndicator</key>
- <string>Building</string>
- <key>street</key>
- <string>Street</string>
- <key>l</key>
- <string>City</string>
- <key>st</key>
- <string>State</string>
- <key>postalCode</key>
- <string>PostalCode</string>
- <key>co</key>
- <string>Country</string>
- <key>telephoneNumber</key>
- <string>PhoneNumber</string>
- <key>appleSecondaryPhone</key>
- <string>PhoneNumber</string>
- <key>facsimileTelephoneNumber</key>
- <string>FaxNumber</string>
- <key>pager</key>
- <string>PagerNumber</string>
- <key>mobile</key>
- <string>MobileNumber</string>
- <key>mail</key>
- <string>EMailAddress</string>
- <key>applePreferredEmail</key>
- <string>EMailAddress</string>
- <key>appleNotificationEmail</key>
- <string>EMailAddress</string>
- <key>appleDSID</key>
- <string>GeneratedUID</string>
- <key>o</key>
- <string>OrganizationName</string>
- <key>ou</key>
- <string>Department</string>
- <key>appleAIMPreferred</key>
- <string>IMHandle</string>
- <key>appleAIMOfficial</key>
- <string>IMHandle</string>
- <key>appleManager</key>
- <string>dsAttrTypeNative:appleManager</string>
- </dict>
- </dict>
- <!-- mailing list vCards. Should mark as "company" or use vCard 4.0 types -->
- <key>distribution list</key>
- <dict>
- <key>rdn</key>
- <string>ou=groups</string>
- <key>filter</key>
- <string>(objectClass=appleGroup)</string>
- <key>getAllAttributes</key>
- <false/>
- <key>vcardPropToLdapAttrMap</key>
- <dict>
- <key>EMAIL</key>
- <string>appleGroupEmail</string>
- <key>FN</key>
- <string>description</string>
- <key>UID</key>
- <string>appleDSID</string>
- </dict>
- <key>ldapAttrToDSAttrMap</key>
- <dict>
- <key>cn</key>
- <string>RecordName</string>
- <key>description</key>
- <array>
- <string>RealName</string>
- <string>OrganizationName</string>
- </array>
- <key>appleDSID</key>
- <string>GeneratedUID</string>
- <key>appleGroupContact</key>
- <string>dsAttrTypeNative:appleManager</string>
- <key>appleGroupEmail</key>
- <string>EMailAddress</string>
- </dict>
- </dict>
- <!-- people vCards for another server. Unused
- <key>people - 2</key>
- <dict>
- <key>ldapAttrToDSAttrMap</key>
+ <!-- people vCards for another server. Unused
<dict>
- <key>givenName</key>
- <string>FirstName</string>
- <key>sn</key>
- <string>LastName</string>
- <key>cn</key>
- <array>
- <string>RealName</string>
- <string>RecordName</string>
- </array>
- <key>mail</key>
- <string>EMailAddress</string>
- <key>uid</key>
- <string>GeneratedUID</string>
+ <key>ldapAttrToDSAttrMap</key>
+ <dict>
+ <key>givenName</key>
+ <string>FirstName</string>
+ <key>sn</key>
+ <string>LastName</string>
+ <key>cn</key>
+ <array>
+ <string>RealName</string>
+ <string>RecordName</string>
+ </array>
+ <key>mail</key>
+ <string>EMailAddress</string>
+ <key>uid</key>
+ <string>GeneratedUID</string>
+ </dict>
+ <key>rdn</key>
+ <string>ou=People</string>
+ <key>filter</key>
+ <string></string>
+ <key>vcardPropToLdapAttrMap</key>
+ <dict>
+ <key>FN</key>
+ <string>cn</string>
+ <key>EMAIL</key>
+ <string>mail</string>
+ <key>UID</key>
+ <string>uid</string>
+ </dict>
</dict>
- <key>rdn</key>
- <string>ou=People</string>
- <key>filter</key>
- <string></string>
- <key>vcardPropToLdapAttrMap</key>
- <dict>
- <key>FN</key>
- <string>cn</string>
- <key>EMAIL</key>
- <string>mail</string>
- <key>UID</key>
- <string>uid</string>
- </dict>
- </dict>
- -->
+ -->
+ </array>
</dict>
</dict>
</dict>
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/support/CalendarServer.xcodeproj/project.pbxproj
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/support/CalendarServer.xcodeproj/project.pbxproj 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/support/CalendarServer.xcodeproj/project.pbxproj 2012-03-22 00:02:25 UTC (rev 8919)
@@ -22,6 +22,7 @@
667574D7151168C400BE9C7C /* shell.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = shell.sh; sourceTree = SOURCE_ROOT; };
667574D8151168C400BE9C7C /* submit */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = submit; sourceTree = SOURCE_ROOT; };
667574DC151168C400BE9C7C /* version.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = version.py; sourceTree = SOURCE_ROOT; };
+ 66D312CA151A71DB00743E4F /* xmldirectorybacker.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = xmldirectorybacker.py; sourceTree = "<group>"; };
66EAD03D150AF4EB00B8C5A7 /* benchmark */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = benchmark; path = ../benchmark; sourceTree = "<group>"; };
66EAD03E150AF4EB00B8C5A7 /* benchreport */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = benchreport; path = ../benchreport; sourceTree = "<group>"; };
66EAD040150AF4EB00B8C5A7 /* _calendarserver_preamble.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = _calendarserver_preamble.py; sourceTree = "<group>"; };
@@ -3049,6 +3050,7 @@
66EAD315150AF4EB00B8C5A7 /* util.py */,
66EAD316150AF4EB00B8C5A7 /* wiki.py */,
66EAD317150AF4EB00B8C5A7 /* xmlaccountsparser.py */,
+ 66D312CA151A71DB00743E4F /* xmldirectorybacker.py */,
66EAD318150AF4EB00B8C5A7 /* xmlaugmentsparser.py */,
66EAD319150AF4EB00B8C5A7 /* xmlfile.py */,
);
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -39,7 +39,7 @@
from twistedcaldav.directory.ldapdirectory import LdapDirectoryService
import ldap
-from twistedcaldav.directory.opendirectorybacker import VCardRecord, dsFilterFromAddressBookFilter, propertiesInAddressBookQuery
+from twistedcaldav.directory.opendirectorybacker import VCardResource, dsFilterFromAddressBookFilter, propertiesInAddressBookQuery
class LdapDirectoryBackingService(LdapDirectoryService):
@@ -61,18 +61,20 @@
"recordTypes": (), # for super
"rdnSchema": {
"base": "dc=example,dc=com",
- "queryTypes": ("people",),
- "people": {
- "rdn":"ou=people",
- "vcardPropToLdapAttrMap" : { # maps vCard properties to searchable ldap attributes
- "FN" : "cn",
- },
- "ldapAttrToDSAttrMap" : { # maps ldap attributes to ds record types
- "cn" : "dsAttrTypeStandard:RealName",
- },
- },
+ "queries": (
+ { #people
+ "rdn":"ou=people",
+ "vcardPropToLdapAttrMap" : { # maps vCard properties to searchable ldap attributes
+ "FN" : "cn",
+ },
+ "ldapAttrToDSAttrMap" : { # maps ldap attributes to ds attribute types
+ "cn" : "dsAttrTypeStandard:RealName",
+ },
+ },
+ ),
+
},
- "appleInternalServer":False, # does magic in VCardRecord
+ "appleInternalServer":False, # does magic in VCardResource
"maxQueryRecords":0, # max records returned
"fakeETag":True, # eTag is fake, otherwise it is md5(all attributes)
"generateSimpleUIDs":False, # if UID is faked, use simple method for generating
@@ -106,8 +108,8 @@
#standardize ds attributes type names
# or we could just require dsAttrTypeStandard: prefix in the plist
rdnSchema = params["rdnSchema"];
- for queryType in rdnSchema["queryTypes"]:
- ldapAttrToDSAttrMap = rdnSchema[queryType]["ldapAttrToDSAttrMap"]
+ for query in rdnSchema["queries"]:
+ ldapAttrToDSAttrMap = query["ldapAttrToDSAttrMap"]
for ldapAttrName, dsAttrNames in ldapAttrToDSAttrMap.iteritems():
if not isinstance(dsAttrNames, list):
dsAttrNames = [dsAttrNames,]
@@ -136,14 +138,14 @@
self.realmName = None # needed for super
- ### params for VCardRecord()
+ ### params for VCardResource()
self.fakeETag = fakeETag
self.generateSimpleUIDs = generateSimpleUIDs
self.appleInternalServer = appleInternalServer
super(LdapDirectoryBackingService, self).__init__(params)
- ### self.defaultNodeName used by VCardRecord.
+ ### self.defaultNodeName used by VCardResource.
# get this now once
hostname = getfqdn()
if hostname:
@@ -152,16 +154,6 @@
self.defaultNodeName = None
- def __cmp__(self, other):
- if not isinstance(other, DirectoryRecord):
- return super(DirectoryRecord, self).__eq__(other)
-
- for attr in ("directory", "node"):
- diff = cmp(getattr(self, attr), getattr(other, attr))
- if diff != 0:
- return diff
- return 0
-
def __hash__(self):
h = hash(self.__class__.__name__)
for attr in ("node",):
@@ -200,7 +192,7 @@
@inlineCallbacks
- def vCardRecordsForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
+ def vCardResourcesForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
"""
Get vCards for a given addressBookFilter and addressBookQuery
"""
@@ -213,14 +205,14 @@
if self.maxQueryRecords and maxRecords > self.maxQueryRecords:
maxRecords = self.maxQueryRecords
- for queryType in self.rdnSchema["queryTypes"]:
+ for queryMap in self.rdnSchema["queries"]:
- queryMap = self.rdnSchema[queryType]
+ rdn = queryMap["rdn"]
vcardPropToLdapAttrMap = queryMap["vcardPropToLdapAttrMap"]
ldapAttrToDSAttrMap = queryMap["ldapAttrToDSAttrMap"]
allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToLdapAttrMap );
- self.log_debug("vCardRecordsForAddressBookQuery: queryType=\"%s\" LDAP allRecords=%s, filterAttributes=%s, query=%s" % (queryType, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
+ self.log_debug("vCardResourcesForAddressBookQuery: rdn=%s LDAP allRecords=%s, filterAttributes=%s, query=%s" % (rdn, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
if allRecords:
@@ -232,13 +224,12 @@
if not clear:
queryAttributes = self._ldapAttributesForAddressBookQuery( addressBookQuery, ldapAttrToDSAttrMap )
attributes = filterAttributes + queryAttributes if queryAttributes else None
- self.log_debug("vCardRecordsForAddressBookQuery: attributes=%s, queryAttributes=%s" % (attributes, queryAttributes,))
+ self.log_debug("vCardResourcesForAddressBookQuery: attributes=%s, queryAttributes=%s" % (attributes, queryAttributes,))
#get all ldap attributes -- for debug
if queryMap.get("getAllAttributes"):
attributes = None
- rdn = queryMap["rdn"]
base = ldap.dn.str2dn(rdn) + self.base
filterstr = "(cn=*)" # all query
@@ -254,11 +245,11 @@
# can't resist also using a timeout, 1 sec per requested record for now
timeout = maxRecords
- self.log_debug("vCardRecordsForAddressBookQuery:LDAP query base=%s and filter=%s and attributes=%s timeout=%s resultLimit=%s" % (ldap.dn.dn2str(base), filterstr, attributes, timeout, maxRecords))
+ self.log_debug("vCardResourcesForAddressBookQuery:LDAP query base=%s and filter=%s and attributes=%s timeout=%s resultLimit=%s" % (ldap.dn.dn2str(base), filterstr, attributes, timeout, maxRecords))
ldapSearchResult = (yield self.timedSearch(ldap.dn.dn2str(base), ldap.SCOPE_SUBTREE, filterstr=filterstr, attrlist=attributes, timeoutSeconds=timeout, resultLimit=maxRecords))
- self.log_debug("vCardRecordsForAddressBookQuery: ldapSearchResult=%s" % (ldapSearchResult,))
+ self.log_debug("vCardResourcesForAddressBookQuery: ldapSearchResult=%s" % (ldapSearchResult,))
for dn, ldapAttributes in ldapSearchResult:
#dn = normalizeDNstr(dn)
@@ -283,7 +274,7 @@
for dsAttributeName in dsAttributeNames:
# base64 encode binary attributes
- if dsAttributeName in VCardRecord.binaryDSAttributeStrs:
+ if dsAttributeName in VCardResource.binaryDSAttributeStrs:
ldapAttributeValues = [attr.encode('base64') for attr in ldapAttributeValues]
# add to dsRecordAttributes
@@ -291,16 +282,16 @@
dsRecordAttributes[dsAttributeName] = list()
dsRecordAttributes[dsAttributeName] = list(set(dsRecordAttributes[dsAttributeName] + ldapAttributeValues))
- self.log_debug("vCardRecordsForAddressBookQuery: dsRecordAttributes[%s] = %s" % (dsAttributeName, dsRecordAttributes[dsAttributeName],))
+ self.log_debug("vCardResourcesForAddressBookQuery: dsRecordAttributes[%s] = %s" % (dsAttributeName, dsRecordAttributes[dsAttributeName],))
# get a record for dsRecordAttributes
- dsRecord = VCardRecord(self, dsRecordAttributes, defaultNodeName=None, generateSimpleUIDs=self.generateSimpleUIDs, appleInternalServer=self.appleInternalServer)
+ dsRecord = VCardResource(self.directoryBackedAddressBook, dsRecordAttributes, defaultNodeName=None, generateSimpleUIDs=self.generateSimpleUIDs, appleInternalServer=self.appleInternalServer)
vCardText = dsRecord.vCardText()
except:
traceback.print_exc()
self.log_info("Could not get vcard for ds record %s" % (dsRecord,))
else:
- self.log_debug("vCardRecordsForAddressBookQuery: VCard text =\n%s" % (vCardText, ))
+ self.log_debug("vCardResourcesForAddressBookQuery: VCard text =\n%s" % (vCardText, ))
queryRecords.append(dsRecord)
# only get requested number of record results
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -20,7 +20,7 @@
"""
__all__ = [
- "OpenDirectoryBackingService", "VCardRecord",
+ "OpenDirectoryBackingService", "VCardResource",
]
import traceback
@@ -58,6 +58,8 @@
from calendarserver.platform.darwin.od import dsattributes, dsquery
from twisted.python.reflect import namedModule
+from twext.python.log import LoggingMixIn
+
class OpenDirectoryBackingService(DirectoryService):
"""
Open Directory implementation of L{IDirectoryService}.
@@ -158,17 +160,17 @@
# filter allows attributes, but make sure there are a minimum of attributes for functionality
if allowedAttributes:
self.allowedDSQueryAttributes = sorted(list(set(
- [attr for attr in VCardRecord.allDSQueryAttributes
+ [attr for attr in VCardResource.allDSQueryAttributes
if (isinstance(attr, str) and attr in allowedAttributes) or
(isinstance(attr, tuple) and attr[0] in allowedAttributes)] +
- VCardRecord.dsqueryAttributesForProperty.get("X-INTERNAL-REQUIRED")
+ VCardResource.dsqueryAttributesForProperty.get("X-INTERNAL-REQUIRED")
)))
- if (self.allowedDSQueryAttributes != VCardRecord.allDSQueryAttributes):
+ if (self.allowedDSQueryAttributes != VCardResource.allDSQueryAttributes):
self.log_info("Allowed DS query attributes = %r" % (self.allowedDSQueryAttributes, ))
else:
- self.allowedDSQueryAttributes = VCardRecord.allDSQueryAttributes
+ self.allowedDSQueryAttributes = VCardResource.allDSQueryAttributes
- #self.returnedAttributes = VCardRecord.allDSQueryAttributes
+ #self.returnedAttributes = VCardResource.allDSQueryAttributes
self.returnedAttributes = self.allowedDSQueryAttributes
@@ -230,7 +232,7 @@
self._dsLocalRecords = []
for (recordShortName, value) in results: #@UnusedVariable
- record = VCardRecord(self, value, "/Local/Default")
+ record = VCardResource(self.directoryBackedAddressBook, value, "/Local/Default")
if self.ignoreSystemRecords:
# remove system users and people
@@ -267,8 +269,8 @@
@inlineCallbacks
def _getDirectoryRecords(self, query=None, attributes=None, maxRecords=0 ):
"""
- Get a list of filtered VCardRecord for the given query with the given attributes.
- query == None gets all records. attribute == None gets VCardRecord.allDSQueryAttributes
+ Get a list of filtered VCardResource for the given query with the given attributes.
+ query == None gets all records. attribute == None gets VCardResource.allDSQueryAttributes
"""
limited = False
queryResults = (yield self._queryDirectory(query, attributes, maxRecords ))
@@ -283,7 +285,7 @@
for (recordShortName, value) in queryResults: #@UnusedVariable
- record = VCardRecord(self, value, defaultNodeName=self.defaultNodeName,
+ record = VCardResource(self.directoryBackedAddressBook, value, defaultNodeName=self.defaultNodeName,
generateSimpleUIDs=self.generateSimpleUIDs,
addDSAttrXProperties=self.addDSAttrXProperties,
appleInternalServer=self.appleInternalServer,
@@ -413,21 +415,21 @@
propertyNames.append("X-INTERNAL-MINIMUM-VCARD-PROPERTIES") # these properties are required to make a vCard
queryAttributes = []
for prop in propertyNames:
- if prop in VCardRecord.dsqueryAttributesForProperty:
- #print("adding attributes %r" % VCardRecord.dsqueryAttributesForProperty.get(prop))
- queryAttributes += VCardRecord.dsqueryAttributesForProperty.get(prop)
+ if prop in VCardResource.dsqueryAttributesForProperty:
+ #print("adding attributes %r" % VCardResource.dsqueryAttributesForProperty.get(prop))
+ queryAttributes += VCardResource.dsqueryAttributesForProperty.get(prop)
return list(set(queryAttributes).intersection(set(self.returnedAttributes)))
@inlineCallbacks
- def vCardRecordsForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
+ def vCardResourcesForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
"""
Get vCards for a given addressBookFilter and addressBookQuery
"""
- allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToLdapAttrMap=VCardRecord.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
+ allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToLdapAttrMap=VCardResource.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
#print("allRecords = %s, query = %s" % (allRecords, "None" if dsFilter is None else dsFilter.generate(),))
# testing:
@@ -642,13 +644,13 @@
# special case UID's formed from node and record name
if propFilter.filter_name == "UID":
matchString = matchStrings[0]
- seperatorIndex = matchString.find(VCardRecord.peopleUIDSeparator)
+ seperatorIndex = matchString.find(VCardResource.peopleUIDSeparator)
if seperatorIndex > 1:
- recordNameStart = seperatorIndex + len(VCardRecord.peopleUIDSeparator)
+ recordNameStart = seperatorIndex + len(VCardResource.peopleUIDSeparator)
else:
- seperatorIndex = matchString.find(VCardRecord.userUIDSeparator)
+ seperatorIndex = matchString.find(VCardResource.userUIDSeparator)
if seperatorIndex > 1:
- recordNameStart = seperatorIndex + len(VCardRecord.userUIDSeparator)
+ recordNameStart = seperatorIndex + len(VCardResource.userUIDSeparator)
else:
recordNameStart = sys.maxint
@@ -700,7 +702,7 @@
# get attribute strings from dsqueryAttributesForProperty list
- #queryAttributes = list(set(VCardRecord.dsqueryAttributesForProperty.get(propFilter.filter_name, [])).intersection(set(self.allowedDSQueryAttributes)))
+ #queryAttributes = list(set(VCardResource.dsqueryAttributesForProperty.get(propFilter.filter_name, [])).intersection(set(self.allowedDSQueryAttributes)))
queryAttributes = vcardPropToLdapAttrMap.get(propFilter.filter_name, [])
if isinstance(queryAttributes, str):
queryAttributes = [queryAttributes,]
@@ -716,7 +718,7 @@
stringAttrStrs.append(attr)
allAttrStrings = stringAttrStrs + binaryAttrStrs
- constant = VCardRecord.constantProperties.get(propFilter.filter_name)
+ constant = VCardResource.constantProperties.get(propFilter.filter_name)
if not constant and not allAttrStrings:
return (False, [], [])
@@ -805,7 +807,7 @@
-class VCardRecord(DirectoryRecord, DAVPropertyMixIn):
+class VCardResource(DAVPropertyMixIn, LoggingMixIn):
"""
Open Directory implementation of L{IDirectoryRecord}.
"""
@@ -977,27 +979,27 @@
}
- def __init__(self, service, recordAttributes, defaultNodeName=None, generateSimpleUIDs=False, addDSAttrXProperties=False, appleInternalServer=False, ):
+ def __init__(self, directoryBackedAddressBook, recordAttributes, defaultNodeName=None, generateSimpleUIDs=False, addDSAttrXProperties=False, appleInternalServer=False, ):
- self.log_debug("service=%s, attributes=%s" % (service, recordAttributes))
+ self.log_debug("directoryBackedAddressBook=%s, attributes=%s" % (directoryBackedAddressBook, recordAttributes))
#save off for debugging
self.addDSAttrXProperties = addDSAttrXProperties;
if addDSAttrXProperties:
self.originalAttributes = recordAttributes.copy()
- self.generateSimpleUIDs = generateSimpleUIDs
self.appleInternalServer = appleInternalServer
- self.directoryBackedAddressBook = service.directoryBackedAddressBook
+ self._directoryBackedAddressBook = directoryBackedAddressBook
self._vCard = None
self._vCardText = None
self._uriName = None
self._hRef = None
+ #clean attributes
self.attributes = {}
for key, values in recordAttributes.items():
- if key in VCardRecord.stringDSAttributeStrs:
+ if key in VCardResource.stringDSAttributeStrs:
if isinstance(values, list):
self.attributes[key] = [removeControlChars(val).decode("utf8") for val in values]
else:
@@ -1005,32 +1007,10 @@
else:
self.attributes[key] = values
- # super needs recordname
- recordName = self.firstValueForAttribute(dsattributes.kDSNAttrRecordName)
- if not recordName:
- recordName = self.firstValueForAttribute(dsattributes.kDS1AttrDistinguishedName)
- if not recordName:
- recordName = self.firstValueForAttribute(dsattributes.kDS1AttrLastName)
- if not recordName:
- recordName = self.firstValueForAttribute(dsattributes.kDS1AttrFirstName)
- if not recordName:
- recordName = self.firstValueForAttribute(dsattributes.kDS1AttrGeneratedUID)
- recordAttributes[dsattributes.kDSNAttrRecordName] = recordName
- self.attributes[dsattributes.kDSNAttrRecordName] = recordName
-
- # fill in missing essential attributes used for filtering
- fullName = self.firstValueForAttribute(dsattributes.kDS1AttrDistinguishedName)
- if not fullName:
- fullName = self.firstValueForAttribute(dsattributes.kDSNAttrRecordName)
- self.attributes[dsattributes.kDS1AttrDistinguishedName] = fullName
-
- node = self.firstValueForAttribute(dsattributes.kDSNAttrMetaNodeLocation)
+ if self.firstValueForAttribute(dsattributes.kDS1AttrLastName) == "99":
+ del self.attributes[dsattributes.kDS1AttrLastName]
- # use a better node name -- makes better synthetic GUIDS
- if not node or node == "/LDAPv3/127.0.0.1":
- node = defaultNodeName if defaultNodeName else service.realmName
- self.attributes[dsattributes.kDSNAttrMetaNodeLocation] = node
-
+ # find a GUID
guid = self.firstValueForAttribute(dsattributes.kDS1AttrGeneratedUID)
if not guid:
if generateSimpleUIDs:
@@ -1039,47 +1019,25 @@
nodeUUIDStr = "%x" % abs(hash(node))
nameUUIDStr = "".join(self.firstValueForAttribute(dsattributes.kDSNAttrRecordName).encode("utf8").encode("base64").split("\n"))
if self.firstValueForAttribute(dsattributes.kDSNAttrRecordType) != dsattributes.kDSStdRecordTypePeople:
- guid = VCardRecord.userUIDSeparator.join([nodeUUIDStr, nameUUIDStr,])
+ guid = VCardResource.userUIDSeparator.join([nodeUUIDStr, nameUUIDStr,])
else:
- guid = VCardRecord.peopleUIDSeparator.join([nodeUUIDStr, nameUUIDStr,])
-
+ guid = VCardResource.peopleUIDSeparator.join([nodeUUIDStr, nameUUIDStr,])
- # since guid is used as file name, normalize so uid uniqueness == fine name uniqueness
- #guid = "/".join(guid.split(":")).upper()
- self.attributes[dsattributes.kDS1AttrGeneratedUID] = guid
+ self.attributes[dsattributes.kDS1AttrGeneratedUID] = guid
+ self.guid = guid
+
- if self.firstValueForAttribute(dsattributes.kDS1AttrLastName) == "99":
- del self.attributes[dsattributes.kDS1AttrLastName]
- if self.firstValueForAttribute(dsattributes.kDSNAttrRecordType) != dsattributes.kDSStdRecordTypePeople:
- recordType = DirectoryService.recordType_users
- else:
- recordType = DirectoryService.recordType_people
-
- super(VCardRecord, self).__init__(
- service = service,
- recordType = recordType,
- guid = guid,
- shortNames = tuple(self.valuesForAttribute(dsattributes.kDSNAttrRecordName)),
- fullName = fullName,
- firstName = self.firstValueForAttribute(dsattributes.kDS1AttrFirstName, None),
- lastName = self.firstValueForAttribute(dsattributes.kDS1AttrLastName, None),
- emailAddresses = (),
- calendarUserAddresses = (),
- autoSchedule = False,
- enabledForCalendaring = False,
- )
-
def __repr__(self):
- return "<%s[%s(%s)] %s(%s) %r>" % (
+ return "<%s[%s(%s)] %s" % (
self.__class__.__name__,
self.firstValueForAttribute(dsattributes.kDSNAttrRecordType),
self.firstValueForAttribute(dsattributes.kDSNAttrMetaNodeLocation),
self.guid,
- self.shortNames,
- self.fullName
+ #self.shortNames,
+ #self.fullName
)
def __hash__(self):
@@ -1221,13 +1179,13 @@
self.log_error("addPropertiesAndLabelsForPrefixedAttribute(): Trouble parsing attribute %s, with value \"%s\". Error = %s" % (attrType, attrValue, e,))
- #print("VCardRecord.vCard")
+ #print("VCardResource.vCard")
# create vCard
vcard = Component("VCARD")
groupCount = [0]
# add constant properties - properties that are the same regardless of the record attributes
- for key, value in VCardRecord.constantProperties.items():
+ for key, value in VCardResource.constantProperties.items():
vcard.addProperty(Property(key, value))
# 3.1 IDENTIFICATION TYPES http://tools.ietf.org/html/rfc2426#section-3.1
@@ -1717,10 +1675,10 @@
return result
elif namespace == twisted_dav_namespace:
- return super(VCardRecord, self).readProperty(property, request)
+ return super(VCardResource, self).readProperty(property, request)
#return DAVPropertyMixIn.readProperty(self, property, request)
- return self.directoryBackedAddressBook.readProperty(property, request)
+ return self._directoryBackedAddressBook.readProperty(property, request)
def listProperties(self, request):
#print("VCardResource.listProperties()")
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/test/test_opendirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/test/test_opendirectorybacker.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/test/test_opendirectorybacker.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2011 Apple Inc. All rights reserved.
+# Copyright (c) 2011-2012 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,24 +14,17 @@
# limitations under the License.
##
-from twistedcaldav.directory.opendirectorybacker import VCardRecord
+from twistedcaldav.directory.opendirectorybacker import VCardResource
from twistedcaldav.test.util import TestCase
-class VCardRecordTestCase(TestCase):
+class VCardResourceTestCase(TestCase):
def test_multiplePhoneNumbersAndEmailAddresses(self):
attributes={u'dsAttrTypeStandard:AppleMetaRecordName': ['uid=odtestamanda,cn=users,dc=dalek,dc=example,dc=com'], u'dsAttrTypeStandard:ModificationTimestamp': '20111017170937Z', u'dsAttrTypeStandard:PhoneNumber': ['408 555-1212', '415 555-1212'], u'dsAttrTypeStandard:RecordType': ['dsRecTypeStandard:Users'], u'dsAttrTypeStandard:AppleMetaNodeLocation': ['/LDAPv3/127.0.0.1'], u'dsAttrTypeStandard:RecordName': ['odtestamanda'], u'dsAttrTypeStandard:FirstName': 'Amanda', u'dsAttrTypeStandard:GeneratedUID': '9DC04A70-E6DD-11DF-9492-0800200C9A66', u'dsAttrTypeStandard:LastName': 'Test', u'dsAttrTypeStandard:CreationTimestamp': '20110927182945Z', u'dsAttrTypeStandard:EMailAddress': ['amanda at example.com', 'second at example.com'], u'dsAttrTypeStandard:RealName': 'Amanda Test'}
- vcardRecord = VCardRecord(StubService(), attributes)
- vcard = vcardRecord.vCard()
+ vcardresource = VCardResource(None, attributes)
+ vcard = vcardresource.vCard()
properties = set([prop.value() for prop in vcard.properties("TEL")])
self.assertEquals(properties, set(["408 555-1212", "415 555-1212"]))
properties = set([prop.value() for prop in vcard.properties("EMAIL")])
self.assertEquals(properties, set(["amanda at example.com", "second at example.com"]))
-
-
-class StubService(object):
- addDSAttrXProperties = False
- directoryBackedAddressBook = None
- appleInternalServer = False
- realmName = "testing"
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/xmldirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/xmldirectorybacker.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/xmldirectorybacker.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -38,7 +38,7 @@
from twistedcaldav.directory.directory import DirectoryRecord
from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.directory.opendirectorybacker import VCardRecord, dsFilterFromAddressBookFilter
+from twistedcaldav.directory.opendirectorybacker import VCardResource, dsFilterFromAddressBookFilter
from calendarserver.platform.darwin.od import dsattributes, dsquery
@@ -121,7 +121,7 @@
super(XMLDirectoryBackingService, self).__init__(params)
- ### self.defaultNodeName used by VCardRecord.
+ ### self.defaultNodeName used by VCardResource.
# get this now once
hostname = getfqdn()
if hostname:
@@ -151,7 +151,7 @@
@inlineCallbacks
- def vCardRecordsForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
+ def vCardResourcesForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
"""
Get vCards for a given addressBookFilter and addressBookQuery
"""
@@ -171,7 +171,7 @@
dirRecordAttrToDSAttrMap = queryMap["dirRecordAttrToDSAttrMap"]
allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToDirRecordAttrMap );
- self.log_debug("vCardRecordsForAddressBookQuery: queryType=\"%s\" LDAP allRecords=%s, filterAttributes=%s, query=%s" % (queryType, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
+ self.log_debug("vCardResourcesForAddressBookQuery: queryType=\"%s\" LDAP allRecords=%s, filterAttributes=%s, query=%s" % (queryType, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
if allRecords:
@@ -240,16 +240,16 @@
# walk the expression tree
xmlDirectoryRecords = (yield recordsForDSFilter(dsFilter, queryType))
- self.log_debug("vCardRecordsForAddressBookQuery: #xmlDirectoryRecords %s" % (len(xmlDirectoryRecords) if xmlDirectoryRecords is not None else xmlDirectoryRecords, ))
+ self.log_debug("vCardResourcesForAddressBookQuery: #xmlDirectoryRecords %s" % (len(xmlDirectoryRecords) if xmlDirectoryRecords is not None else xmlDirectoryRecords, ))
if xmlDirectoryRecords is None:
xmlDirectoryRecords = (yield self.listRecords(queryType))
- self.log_debug("vCardRecordsForAddressBookQuery: all #xmlDirectoryRecords %s" % (len(xmlDirectoryRecords), ))
+ self.log_debug("vCardResourcesForAddressBookQuery: all #xmlDirectoryRecords %s" % (len(xmlDirectoryRecords), ))
# apply limit
if len(xmlDirectoryRecords) > maxRecords:
xmlDirectoryRecords = set(list(xmlDirectoryRecords)[:maxRecords])
- self.log_debug("vCardRecordsForAddressBookQuery: #xmlDirectoryRecords after max %s" % (len(xmlDirectoryRecords), ))
+ self.log_debug("vCardResourcesForAddressBookQuery: #xmlDirectoryRecords after max %s" % (len(xmlDirectoryRecords), ))
for xmlDirectoryRecord in xmlDirectoryRecords:
@@ -267,14 +267,14 @@
dsRecord = None
dsRecordAttributes = dsRecordAttributesFromDirectoryRecord( xmlDirectoryRecord )
try:
- dsRecord = VCardRecord(self, dsRecordAttributes,)
+ dsRecord = VCardResource(self.directoryBackedAddressBook, dsRecordAttributes,)
vCardText = dsRecord.vCardText()
except:
traceback.print_exc()
self.log_info("Could not get vcard for ds record %s" % (dsRecord,))
else:
- self.log_debug("vCardRecordsForAddressBookQuery: VCard text =\n%s" % (vCardText, ))
+ self.log_debug("vCardResourcesForAddressBookQuery: VCard text =\n%s" % (vCardText, ))
queryRecords.append(dsRecord)
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_addressbook_query.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_addressbook_query.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_addressbook_query.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -159,114 +159,108 @@
def queryDirectoryBackedAddressBook(directoryBackedAddressBook, addressBookFilter):
"""
"""
- records, limited[0] = (yield directoryBackedAddressBook.directory.vCardRecordsForAddressBookQuery( addressBookFilter, query, max_number_of_results[0] ))
- for vCardRecord in records:
+ resources, limited[0] = (yield directoryBackedAddressBook.directory.vCardResourcesForAddressBookQuery( addressBookFilter, query, max_number_of_results[0] ))
+ for vCardResource in resources:
# match against original filter
- if filter.match((yield vCardRecord.vCard())):
+ if filter.match((yield vCardResource.vCard())):
# Check size of results is within limit
checkMaxResults()
try:
- yield report_common.responseForHref(request, responses, vCardRecord.hRef(), vCardRecord, propertiesForResource, query, vcard=(yield vCardRecord.vCard()))
+ yield report_common.responseForHref(request, responses, vCardResource.hRef(), vCardResource, propertiesForResource, query, vcard=(yield vCardResource.vCard()))
except ConcurrentModification:
# This can happen because of a race-condition between the
# time we determine which resources exist and the deletion
# of one of these resources in another request. In this
# case, we ignore the now missing resource rather
# than raise an error for the entire report.
- log.err("Missing resource during sync: %s" % (vCardRecord.hRef(),))
+ log.err("Missing resource during sync: %s" % (vCardResource.hRef(),))
- directoryAddressBookLock = None
- try:
- if not addrresource.isAddressBookCollection():
-
- #do UID lookup on last part of uri
- resource_name = urllib.unquote(uri[uri.rfind("/") + 1:])
- if resource_name.endswith(".vcf") and len(resource_name) > 4:
+ if not addrresource.isAddressBookCollection():
+
+ #do UID lookup on last part of uri
+ resource_name = urllib.unquote(uri[uri.rfind("/") + 1:])
+ if resource_name.endswith(".vcf") and len(resource_name) > 4:
+
+ # see if parent is directory backed address book
+ parent = (yield addrresource.locateParent( request, uri ) )
- # see if parent is directory backed address book
- parent = (yield addrresource.locateParent( request, uri ) )
-
-
- # Check whether supplied resource is an address book or an address book object resource
- if addrresource.isAddressBookCollection():
- if addrresource.isDirectoryBackedAddressBookCollection():
- yield maybeDeferred( queryDirectoryBackedAddressBook, addrresource, filter )
-
- else:
+ # Check whether supplied resource is an address book or an address book object resource
+ if addrresource.isAddressBookCollection():
- # Do some optimisation of access control calculation by determining any inherited ACLs outside of
- # the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = (yield addrresource.inheritedACEsforChildren(request))
+ if addrresource.isDirectoryBackedAddressBookCollection():
+ yield maybeDeferred( queryDirectoryBackedAddressBook, addrresource, filter )
+
+ else:
+
+ # Do some optimisation of access control calculation by determining any inherited ACLs outside of
+ # the child resource loop and supply those to the checkPrivileges on each child.
+ filteredaces = (yield addrresource.inheritedACEsforChildren(request))
+
+ # Check for disabled access
+ if filteredaces is not None:
+ # See whether the filter is valid for an index only query
+ index_query_ok = addrresource.index().searchValid(filter)
- # Check for disabled access
- if filteredaces is not None:
- # See whether the filter is valid for an index only query
- index_query_ok = addrresource.index().searchValid(filter)
-
- # Get list of children that match the search and have read access
- names = [name for name, ignore_uid in (yield addrresource.index().search(filter))] #@UnusedVariable
- if not names:
- return
-
- # Now determine which valid resources are readable and which are not
- ok_resources = []
- yield addrresource.findChildrenFaster(
- "1",
- request,
- lambda x, y: ok_resources.append((x, y)),
- None,
- names,
- (davxml.Read(),),
- inherited_aces=filteredaces
- )
- for child, child_uri in ok_resources:
- child_uri_name = child_uri[child_uri.rfind("/") + 1:]
-
- if generate_address_data or not index_query_ok:
- vcard = yield child.vCard()
- assert vcard is not None, "vCard %s is missing from address book collection %r" % (child_uri_name, self)
- else:
- vcard = None
-
- yield queryAddressBookObjectResource(child, uri, child_uri_name, vcard, query_ok = index_query_ok)
+ # Get list of children that match the search and have read access
+ names = [name for name, ignore_uid in (yield addrresource.index().search(filter))] #@UnusedVariable
+ if not names:
+ return
+
+ # Now determine which valid resources are readable and which are not
+ ok_resources = []
+ yield addrresource.findChildrenFaster(
+ "1",
+ request,
+ lambda x, y: ok_resources.append((x, y)),
+ None,
+ names,
+ (davxml.Read(),),
+ inherited_aces=filteredaces
+ )
+ for child, child_uri in ok_resources:
+ child_uri_name = child_uri[child_uri.rfind("/") + 1:]
- else:
+ if generate_address_data or not index_query_ok:
+ vcard = yield child.vCard()
+ assert vcard is not None, "vCard %s is missing from address book collection %r" % (child_uri_name, self)
+ else:
+ vcard = None
+
+ yield queryAddressBookObjectResource(child, uri, child_uri_name, vcard, query_ok = index_query_ok)
+
+ else:
+
+ handled = False;
+ resource_name = urllib.unquote(uri[uri.rfind("/") + 1:])
+ if resource_name.endswith(".vcf") and len(resource_name) > 4:
- handled = False;
- resource_name = urllib.unquote(uri[uri.rfind("/") + 1:])
- if resource_name.endswith(".vcf") and len(resource_name) > 4:
+ # see if parent is directory backed address book
+ parent = (yield addrresource.locateParent( request, uri ) )
+
+ if parent.isDirectoryBackedAddressBookCollection():
+
+ vCardFilter = carddavxml.Filter( *[carddavxml.PropertyFilter(
+ carddavxml.TextMatch.fromString(resource_name[:-4]),
+ name="UID", # attributes
+ ),] )
+ vCardFilter = addressbookqueryfilter.Filter(vCardFilter)
- # see if parent is directory backed address book
- parent = (yield addrresource.locateParent( request, uri ) )
+ yield maybeDeferred( queryDirectoryBackedAddressBook, parent, vCardFilter )
+ handled = True
+
+ if not handled:
+ vcard = yield addrresource.vCard()
+ yield queryAddressBookObjectResource(addrresource, uri, None, vcard)
- if parent.isDirectoryBackedAddressBookCollection():
-
- vCardFilter = carddavxml.Filter( *[carddavxml.PropertyFilter(
- carddavxml.TextMatch.fromString(resource_name[:-4]),
- name="UID", # attributes
- ),] )
- vCardFilter = addressbookqueryfilter.Filter(vCardFilter)
-
- yield maybeDeferred( queryDirectoryBackedAddressBook, parent, vCardFilter )
- handled = True
+ if limited[0]:
+ raise NumberOfMatchesWithinLimits(matchcount[0])
- if not handled:
- vcard = yield addrresource.vCard()
- yield queryAddressBookObjectResource(addrresource, uri, None, vcard)
-
- if limited[0]:
- raise NumberOfMatchesWithinLimits(matchcount[0])
-
- finally:
- if directoryAddressBookLock:
- yield directoryAddressBookLock.release()
-
# Run report taking depth into account
try:
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_multiget_common.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_multiget_common.py 2012-03-21 23:39:33 UTC (rev 8918)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/method/report_multiget_common.py 2012-03-22 00:02:25 UTC (rev 8919)
@@ -275,7 +275,7 @@
#get vCards and filter
limit = config.DirectoryAddressBook.MaxQueryResults
- vCardRecords, limited = (yield self.directory.vCardRecordsForAddressBookQuery( addressBookFilter, propertyreq, limit ))
+ vCardResources, limited = (yield self.directory.vCardResourcesForAddressBookQuery( addressBookFilter, propertyreq, limit ))
if limited:
log.err("Too many results in multiget report: %d" % len(resources))
raise HTTPError(ErrorResponse(
@@ -285,14 +285,14 @@
))
for href in valid_hrefs:
- matchingRecord = None
- for vCardRecord in vCardRecords:
- if href == vCardRecord.hRef(): # might need to compare urls instead - also case sens ok?
- matchingRecord = vCardRecord
+ matchingResource = None
+ for vCardResource in vCardResources:
+ if href == vCardResource.hRef(): # might need to compare urls instead - also case sens ok?
+ matchingResource = vCardResource
break;
- if matchingRecord:
- yield report_common.responseForHref(request, responses, href, matchingRecord, propertiesForResource, propertyreq, vcard=matchingRecord.vCard())
+ if matchingResource:
+ yield report_common.responseForHref(request, responses, href, matchingResource, propertiesForResource, propertyreq, vcard=matchingResource.vCard())
else:
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.NOT_FOUND)))
finally:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120321/3f7e06de/attachment-0001.html>
More information about the calendarserver-changes
mailing list