1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: modlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Demonstration command processor
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Dec 2002
10 ;;;; $Id: demo.lisp,v 1.1 2003/07/05 00:59:49 kevin Exp $
11 ;;;; *************************************************************************
13 (in-package #:modlisp)
16 (defun demo-apache-command-processor (command)
17 "Sample function to process an apache command"
18 (let ((url (header-value command "url")))
20 ((equal url "/fixed.lsp")
21 (output-html-page (fixed-html-string)))
22 ((equal url "/precompute.lsp")
23 (with-ml-page (:precompute t)
24 (write-precomputed-page)))
26 (with-ml-page (:precompute nil)
27 (write-debug-table command))))))
29 (defun write-debug-table (command)
30 (write-string "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
33 <h1>mod_lisp debug page</h1>" *apache-socket*)
34 (write-request-counts *apache-socket*)
35 (write-string "<table>
36 <thead><tr><th>Key</th><th>Value</th></tr></thead>
37 <tbody>" *apache-socket*)
38 (loop for (key . value) in command do
39 (format *apache-socket* "<tr><td>~a</td><td>~a</td></tr>" key value))
40 (write-string "</tbody></table></body></html>" *apache-socket*))
43 (defun fixed-html-string ()
44 (with-output-to-string (s)
46 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
47 <html><head></head><body><h1>mod_lisp fixed page</h1>
48 <p>This is a fixed string sent by mod_lisp</p>" s)
49 (write-request-counts s)
50 (write-string "</body></html>" s)))
52 (defun write-precomputed-page ()
54 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
55 <html><head></head><body><h1>mod_lisp precomputed page</h1>
56 <p>This is a precomputed string sent by mod_lisp</p>" *apache-socket*)
57 (write-request-counts *apache-socket*)
58 (write-string "</body></html>" *apache-socket*))
60 (defun write-request-counts (s)
61 (format s "<p>Number of server requests: ~D</p>"
62 (get-number-server-requests))
63 (format s "<p>Number of worker requests for this socket: ~D</p>"
64 (get-number-worker-requests)))