(archive 'newLISPer)

August 1, 2009

Enter the Dragon(fly)

Filed under: newLISP — newlisper @ 14:27
Tags:

Not functional in the archive version.

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!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: