[CalendarServer-changes] [1081] CalendarServer/trunk/twistedcaldav/directory/principal.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 22 17:06:03 PST 2007


Revision: 1081
          http://trac.macosforge.org/projects/calendarserver/changeset/1081
Author:   wsanchez at apple.com
Date:     2007-01-22 17:06:03 -0800 (Mon, 22 Jan 2007)

Log Message:
-----------
Fix _principalForURI to handle full URLs, but doesn't yet verify the hostname/port.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/principal.py

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-01-22 23:53:09 UTC (rev 1080)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-01-23 01:06:03 UTC (rev 1081)
@@ -27,6 +27,7 @@
 ]
 
 from urllib import unquote
+from urlparse import urlparse
 
 from twisted.python import log
 from twisted.python.failure import Failure
@@ -103,25 +104,35 @@
         return self.principalForShortName(record.recordType, record.shortName)
 
     def _principalForURI(self, uri):
-        if uri.startswith(self._url):
-            path = uri[len(self._url) - 1:]
+        scheme, host, path, params, query, fragment = urlparse(uri)
+
+        if scheme == "":
+            pass
+        elif scheme in ("http", "https"):
+            # FIXME: Check that the hostname matches this server
+            # This means we need to know our hostname/port combos
+            log.msg("**** %s" % (host,))
+            pass
+        elif scheme == "urn":
+            if path.startswith("uuid:"):
+                return self.principalForGUID(path[5:])
+            else:
+                return None
         else:
-            #TODO: figure out absolute URIs
-            #absuri = request.unparseURL(path=self._url)
-            #if uri.startswith(absuri):
-            #    path = uri[len(absuri) - 1:]
-            #else:
-            #    path = None
-            path = None
-        
-        if path:
-            segments = [unquote(s) for s in path.rstrip("/").split("/")]
-            if segments[0] == "" and len(segments) == 3:
-                typeResource = self.getChild(segments[1])
-                if typeResource is not None:
-                    principalResource = typeResource.getChild(segments[2])
-                    if principalResource:
-                        return principalResource
+            return None
+
+        if not path.startswith(self._url):
+            return None
+
+        path = path[len(self._url) - 1:]
+
+        segments = [unquote(s) for s in path.rstrip("/").split("/")]
+        if segments[0] == "" and len(segments) == 3:
+            typeResource = self.getChild(segments[1])
+            if typeResource is not None:
+                principalResource = typeResource.getChild(segments[2])
+                if principalResource:
+                    return principalResource
             
         return None
 
@@ -131,16 +142,6 @@
         if principal:
             return principal
 
-        # Special case server absolute URIs
-        if address.startswith("http:") or address.startswith("https:"):
-            if address.endswith("/"):
-                altaddress = address[:-1]
-            else:
-                altaddress = address + "/"
-            addresses = (address, altaddress,)
-        else:
-            addresses = (address,)
-                
         # Next try looking it up in the directory
         for addr in addresses:
             record = self.directory.recordWithCalendarUserAddress(addr)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070122/860057d5/attachment.html


More information about the calendarserver-changes mailing list