cl-http-70-23 virtual machine

Mandriva Linux 2007.0

Image by dpicker via Flickr

Here is a version of cl-http (the Common Lisp Hypermedia Server) for downloading (link), that runs on Mandriva 2006 with cumcl-18b.linux.glibc2 installed. As you probably won’t want to install this version of Mandriva on your computer I’ve created a Virtual Appliance (link), that you can download and run in VMware Player.

Mandriva 2006, is an ideal platform for small lisp projects and integrates nicely into Windows via the Openssh interface which allows applications to log into a remote machine and execute commands. I always install andLinux on my dos box because then the Xming X server is set up automatically and can be accessed from the Mandriva Virtual Machine. I just set my DISPLAY variable to the address of the Xming X server which is usually 192.168.11.1:0.0. Then when a command is executed on the Mandriva Virtual Machine using ssh (plink on windows), the Xming server is chosen for graphics output by default.

Once you’ve booted Mandiva and started iceWM and the cl-http server, just start Firefox and you’ll be presented with a start page from which you can access the documentation. To start the iceWM you’ll need to login as “plateau” with password “toor” and type startx at the shell prompt. When iceWM has started then open a shell by clicking on the terminal button in the bottom menu bar, and type in cl-http. Firefox can be started by clicking on the browser button.

The root directory for cl-http is “/usr/local/cl-http-70-23”. The patches I downloaded with this version have already been applied. One patch was rejected so I fixed the lisp code by hand. To compile cl-http just do the following:

    > cd /usr/local/cl-http-70-23
    > lisp < cmucl/start.lisp

At the end of this post you’ll find some example code. With luck, I’ll post some more examples about creating dynamic web pages within the next few weeks.

If you want to launch applications using ssh (plink) then you will need to log into the Mandriva Virtual Machine as “root”, password “toor”, and run ifconfig to find out what the IP address of the Virtual Machine is. Then commands can be executed as follows:

plink 192.168.86.128 -l plateau -pw toor xterm -fn 12×24

Where 192.168.86.128 is the IP address I obtained by executing ifconfig, plateau is the name of the remote account and toor is the password. Don’t forget to set the DISPLAY variable for user “plateau” to point to the Xming server.

This version of cl-http has not given me any problems but then I only created an interface to the Wordnet Lexicon which works fine.

Just for reference here are the important links, user names and passwords mentioned in this post:

  • user: “root”, password “toor”
  • user: “plateau”, password “toor”
  • cl-http-79-23 source code: (link)
  • virtual machine: (link)

Example 1

;;; exporting computed URLs. A. Ritz, 17 April 2001.  Example 1
;;; This example shows how to write a computed url that displays text from a file.
;;; This is probably the simplist web page that you will ever write.
;;; Two functions are provided for displaying text from a file. The first
;;; function calls lisp functions to open and iteratively read and display the
;;; contents of the file. The second function uses the run-program feature and the unix
;;; command cat.

;;; example of the preformated text, <pre>, tag.
(defun Display-File1 (filename stream)
(setq a (open filename))
(loop
(setq str (read-line a nil))
(when (not str) (return))
(write-string "<pre>" stream)
(write-string str stream)
(write-string "<\pre>" stream)
)
)

;;; example of the preformatted text, <pre>, tag.
(defun Display-File2 (str stream)
(write-string "<pre>" stream)
(run-program "cat" (list str) :output stream)
(write-string "<\pre>" stream)
)

;;; example of the paragraph, <p>, tag.
(defun write-paragraph (str stream)
(write-string "<p>" stream)
(write-string str stream)
(write-string "</p>" stream)
)

;;; a horizontal rule
(defun hr (stream)
(write-string "<HR>")
)

;;; write the HTML for the document body.
(defun Document-Body (str stream)
(html:with-document-body (:stream stream)
(write-paragraph str stream)
(hr stream);
(Display-File1 "test.txt" stream)
(hr stream);
(Display-File2 "test.txt" stream)
(hr stream);
)
)

;;; write the HTML for the whole document.
(defun Document (str stream)
(html:with-html-document (:stream stream)
(html:with-document-preamble (:stream stream)
(html:declare-title str :stream stream)
)
(Document-Body "Testing export of computed url" stream)
)
)

;;; Function Document outputs the following HTML.
;;; <HTML>
;;; <HEAD>
;;; <TITLE></TITLE>
;;; </HEAD>
;;; <BODY>
;;; The HTML output by function Document-Body.
;;; </BODY>
;;; </HTML>

;;; Write the web page
(defmethod write-test-page ((url url:http-url) stream)
(http:with-successful-response
(stream
:html
:cache-control       (url:response-cache-control-directives url)
:content-language (url:languages url)
)
(Document "Test Page" stream)
)
)

;;; export the url
(http:export-url #u"/cl-http/test.html"
  :computed
  :response-function #'write-test-page
  :public t
  :language :en)

;;;                 Function index
;;;
;;;    http:with-successful-response
;;;    html:with-html-document
;;;    html:with-document-preamble
;;;    html:declare-title
;;;    html:with-document-body
;;;    http:export-url

CL-HTTP

CL-HTTP is a full-featured server for the Internet Hypertext Transfer Protocol (HTTP 1.1, HTML 2.0, HTML 3.2 & pre-HTML 4.0) that comes complete with source code. The server has been proven in major production systems and is a component of some interesting applications.

Web servers like CL-HTTP are ideal for building Semantic Web applications. One such application is, RacerPro, which is an OWL reasoner and inference server for the Semantic Web.

For an overview of the design ideas embodied in the CL-HTTP server see the paper by John C. Mallery.

SBCL, EMACS, Hunchentoot and Cygwin

Here are my notes on setting up EMACS and SBCL for windows to work with CYGWIN. Once you have done this you can then install Hunchentoot. Hunchentoot is a web server that works quite well with SBCL. After following these instructions you should have a working lisp web server to play with.

Install CYGWIN into c:\cygwin and EMACS and SBCL into c:\home. Before you start cygwin edit your cygwin.bat file. I use the ‘C’ shell so my cygwin.bat file looks like this:

@echo off

C:
chdir C:\cygwin\bin
tcsh -l

Start CYGWIN and change to the root (‘/’) directory. Delete the existing home directory and create a symbolic link pointing to c:\home. At the SHELL prompt type

rmdir home
ln –s c:\home /home

In your home directory, mine is called VID, edit your .cshrc file and create a .emacs file containing the following:

;
(setq inferior-lisp-program “/home/sbcl/sbcl.exe
–core /home/sbcl/sbcl.core”)
(add-to-list `load-path “/home/sbcl/slime/”)
(require ‘slime)
(slime-setup)

My .cshrc file looks like this:

alias emacs “/home/emacs/bin/runemacs.exe”
set path=($path /home/vid/bin)

In your HOME directory, create a bin directory. Change to this directory and create a file called sbcl containing:

#!/bin/csh
/cygdrive/c/home/sbcl/sbcl.exe –core c:\\home\\sbcl\\sbcl.core $*

Then at the shell prompt type

chmod +x sbcl; rehash

Now in your bin directory create a file called start-server containing

#!/bin/csh
sbcl –userinit /home/vid/bin/hunchentoot-test.lisp

The hunchentoot-test.lisp file that you need to create in your bin directory should contain the following:

(require :asdf)

(asdf:oos ‘asdf:load-op :hunchentoot)
(asdf:oos ‘asdf:load-op :hunchentoot-test)

(hunchentoot:start-server :port 4242)

You also need to edit the file c:\home\emacs\site-lisp\site-start.lisp. Mine contains just one line:

(setenv “HOME” “c:\\home\\vid\\”)

Download and install the following packages into c:\home\sbcl:

cffi
cffi-examples
cffi-tests
chunga
cl+ssl (see below)
cl-base64
cl-fad
cl-ppcre
cl-wh
flexi-streams
hunchentoot
hunchentoot-test
md5
rfc2388
slime
trivial-gray-streams
url-rewrite

You can download these packages from cliki. Put each of the downloaded packages into c:\home\sbcl and them just type

tar -xvzf <package-name.tar.gz>

You will need a different copy of cl+ssl. You can download cl+ssl from here. I made some minor changes to the original package so that the correct libraries are loaded by cffi. These libraries, libssl32.dll and libeay32.dll are included in the gzipped tar file clssl.tar.gz.

You will have to create the directories, cffi-examples, cffi-tests and hunchentoot-test, yourself. For simplicity I just copied cffi to cffi-test and to cffi-examples. Likewise I copied hunchentoot to hunchentoot–test. From a CYGWIN shell just type

cd /home/sbcl
cp –r cffi cffi-test
cp –r cffi cffi-examples
cp –r hunchentoot hunchentoot-test

Now you can do the following:

1) start cygwin and at the shell prompt type start-server. This will start hunchentoot. Point your browser at http://localhost:4242/

2) run emacs with sbcl as the inferior-lisp-program. When emacs has started type M-x slime. Sbcl should start.

Web Server Design

LISP is an ideal tool for developing Semantic Web Applications. On the server side there are two Web Servers that stand out. The first is CL-HTTP, described elsewhere on this blog. The second is Portable AllegroServe (AServe) from Franz Inc. AServe is an open source tool that runs on many platforms. AServe has these components:

  • HTTP/1.1 compliant web server capable of serving static and dynamic pages
  • HTML generation facility that seamlessly merges html tag printing with computation of dynamic content. The HTML generator matches perfectly with the HTML parser (which is in another project) to allow web pages to be read, modifed in Lisp and then regenerated.
  • HTTP client functions to access web sites and retrieve data.
  • Secure Socket Layer (SSL) for both the server and client.
  • Web Proxy facility with a local cache.
  • Comprehensive regression test suite that verifies the functionality of the client, server, proxy and SSL
  • high performance for static and dynamic web page delivery
  • Licensed under terms that ensure that it will always be open source and that encourages its use in commercial settings.
  • A new publish function that builds a page from static and dynamic data and handles caching of the result.
  • Access control mechanisms for publishing directories that gives the webmaster the ability to specify which files and directories in the tree should be visible.
  • The ability to run external CGI programs.
  • An improved virtual hosting system that supports different logging and error streams for each virtual host.

If you would like to experiment with AServe I suggest you download and install “LISP in a Box” (Lispbox). When you are developing server side applications you will probably want to install AllegroGraph from Franz Inc., as well.

Lispbox contains:

  • Emacs, the powerful, customizable text editor
  • A Common Lisp implementation of your choosing
  • SLIME, the Superior Lisp Integration Mode for Emacs
  • ASDF, Another System Definition Facility, used to load Common Lisp libraries.
  • The practical code from Practical Common Lisp ready to be loaded using ASDF.
  • Some glue code to make it all a bit easier to use.

AllegoGraph is “capable of processing billions of RDF triples, and is a modern, high-performance, persistent, disk-based RDF graph database with support for SPARQL, RDFS++, and Prolog reasoning from Java applications. The new features of version 3.0 form a unified “Activity Recognition” package for flexibly analyzing networks and events in large volumes of structured and unstructured data.”

For futher information about developing applications read the book “A Semantic Web Primer”. Web Programming with AServe can be read about here.

Follow

Get every new post delivered to your Inbox.