You should be automatically redirected . If not, visit
http://newlisper.wordpress.com
and update your bookmarks.

01/08/2009

Enter the Dragon(fly)

I'm now running this blog on Dragonfly, a cool new newLISP framework written by Marc, using some code by Jeff (and a few minor contributions from me). It's great to have someone else in charge of all that weird web stuff such as CGI headers and .htaccessing URLs for a change. I'm hopeful that I can soon start writing some newLISP again.

I've spent the last week puzzling over a bug in my newLISP XMLRPC server (which is based on Lutz' original XMLRPC code). This is designed to receive a post submitted by a desktop blogging application and enter it into the database. The obvious and visible problem I thought I had was that pre-formatted text (such as a code listing) was being displayed in a web browser on a single line - the linefeeds were being removed somewhere, by something. I examined many different ways of parsing XML, and spent much time replacing carriage returns and newlines, and printing intermediate results to temporary files, but couldn't find anything that could be removing linefeeds. Many days passed...

It turned out that I'd been looking in the wrong places, and had incorrectly diagnosed the problem anyway. Consider this code, which is where the server reads the incoming XML:

(if (not input)
        (print
            "Content-type: text/html\r\n\r\n"
            "

newLISP XML-RPC v." version ": not a valid XML-RPC request

"
) (begin (while (read-line) (write-buffer input (current-line))) ; <-- -- - (process-post input)))

It looks obvious now, but after I modified the code to this:

(if (not input)
    (print
        "Content-type: text/html\r\n\r\n"
        "

newLISP XML-RPC v." version ": not a valid XML-RPC request

"
) (begin (while (read-line) (write-buffer input (string (current-line) "\n"))) ; <-- -- (process-post input)))

it all started working correctly. In the entry for read-line, the newLISP manual correctly states:

The line always breaks on a line-feed, which is then swallowed.

In other words, the newlines had been swallowed and thrown away right at the beginning of the script, and I'd noticed it only in the obvious places, where the text is pre-formatted.

Finding the problem can be much harder than finding the solution!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home