[Chandler-dev] Network operations for a "subscribe"

Morgen Sagen morgen at osafoundation.org
Tue Dec 5 12:07:34 PST 2006


We're getting closer to using a new streamlined protocol with Cosmo,  
and it's now a good time to re-examine what network operations  
Chandler performs when given a URL to subscribe to.  Below is a first  
pass at the pseudo code for an initial subscribe.  One problem with  
this code is that Cosmo currently responds to a GET on a CalDAV  
calendar with an icalendar file of all the contained events, and thus  
if Chandler follows this algorithm it won't be able to subscribe to a  
Cosmo collection in CalDAV mode (Chandler would simply treat the  
collection as a monolithic ical file).  Chandler, upon receiving a  
monolithic ical file in response to the GET, will need to do  
something extra to see if there's really a CalDAV calendar hiding  
behind the ical file.

I've left out the logic for determining whether the user has write- 
permission, but I believe I read that we can do some sort of ticket  
discovery to ask Cosmo what the permissions are for a given ticket.   
Is that true?  I suppose in the case where there is no ticket  
provided we can assume we have write-permission; if a write does fail  
during the first sync then consider the share read-only.  On the  
other hand, at that point it's too late because the user may have  
made some modifications to the items.  So really, if there is no  
ticket involved, I will have to perform the same trick I am currently  
doing which is to MKCOL a temporary subcollection to verify write- 
permission at the time of initial subscribe.  Does that work for non- 
Cosmo CalDAV servers?


subscribe
-------------

if url has a ticket in it:
	ticket = url's ticket
    	username = password = None
else:
	ticket = None
	if there is a sharing account that corresponds to the url:
		username = account.username
		password = account.password

done = False

while True:
	try:
		response = GET(url, ticket, username, password)
	except NetworkError, e:
		# This could include problems such as not being able to connect to  
the server, or not being able to look up
		# a server's IP address
		return appropriate error

	if response.status == NotAuthorized:
		return NotAuthorized # the UI code will prompt the user for  
username and password and try again

	elif response.status == OK:
		if response.contenttype == "text/html":
			if real sharing URL is embedded in response.body:
				url = embedded sharing url
				continue # back up to the top of the while loop
			else: # this is some random HTML file
				return ThisIsJustAnHTMLFile # What should the UI do?

		elif response.contenttype == "application/icalendar":  # is that  
the right contenttype value?
			# response.body has the icalendar text
			Set up Share objects for simple monolithic ical subscription
			share.sync(body=response.body) # no need to fetch the body again,  
pass it directly to sync
			return Success
			# Note: the problem with this is that Cosmo returns a big  
icalendar file when the client does a
			# GET of a CalDAV calendar collection, and therefore Chandler  
won't be able to subscribe to
			# such a collection in CalDAV mode unless we do something  
different here.

		elif response.contenttype == "application/eim+xml":
			# response.body has EIM records
			Set up Share objects for morsecode subscription
			share.sync(body=response.body) # no need to fetch the body again,  
pass it directly to sync
			return

		else:
			return UnknownContentType

	elif response.status == MethodNotAllowed:
		# perhaps this is a CalDAV collection that doesn't allow GET?
		set up Share objects for CalDAV subscription
		share.sync( )
		return

	else: # deal with other response.status values, such as NotFound
		return appropriate error



More information about the chandler-dev mailing list