Dispatching

While I was implementing the Comment API, I decided that I wanted a way to dispatch a POSTed item by content. Essentially, I look at the Content-Type, and call a method that knows how to dispatch that type. For text/xml, I parse the XML into an SXML document and then dispatch based on the root node. There are 2 cases I want to catch: the Comment API and an XML-RPC Pingback. The code looks like this:
(define (dispatch-text/xml sxml entry)
  (let ((dt `((item . ,comment-api)
              (methodCall . ,xml-rpc))))
    ((find-dispatch dt) sxml entry)))
find-dispatch is a simple lookup routine, returning a method that takes the children of the root node and an entry that is being commented on:
(define (find-dispatch dispatch-table)
  (lambda (rpc-envelope entry)
    ((cdr (assq (car rpc-envelope) dispatch-table)) (cdr rpc-envelope) entry)))
I had originally considered simply evaling the S-Expression, but this is problematic for 2 reasons: first, the S-Expression resulting from parsing a Comment API envelope isn't very functional:
 (item
  (title "RE: Test Post")
  (link "http://www.eighty-twenty.net/blog")
  (pubDate "Sun, 22 Feb 2004 21:16:10 GMT")
  (description "Test of Comment  API")
  (author "gweakliem@example.com (Gordon Weakliem)")
  (dc:creator "gweakliem@example.com (Gordon Weakliem)"))
and second, because a malicious caller could put anything into the envelope, and the amount of checking that I'd have to do to be safe would be prohibitive. So far, I like this way of dispatching calls, it seems to be easily extensible and fairly compact. I'll probably rework my higher level HTTP dispatch to use this technique.

— Gordon Weakliem at permanent link

Comment API (almost) working

I've implemented the Comment API on this weblog. I've observed one odd thing testing from RSS Bandit; the server returns a 500 but the comment is posted.

— Gordon Weakliem at permanent link