+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: modlisp -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name: demo.lisp
+;;;; Purpose: Demonstration command processor
+;;;; Programmer: Kevin M. Rosenberg
+;;;; Date Started: Dec 2002
+;;;;
+;;;; $Id: demo.lisp,v 1.1 2003/07/05 00:59:49 kevin Exp $
+;;;; *************************************************************************
+
+(in-package #:modlisp)
+
+
+(defun demo-apache-command-processor (command)
+ "Sample function to process an apache command"
+ (let ((url (header-value command "url")))
+ (cond
+ ((equal url "/fixed.lsp")
+ (output-html-page (fixed-html-string)))
+ ((equal url "/precompute.lsp")
+ (with-ml-page (:precompute t)
+ (write-precomputed-page)))
+ (t
+ (with-ml-page (:precompute nil)
+ (write-debug-table command))))))
+
+(defun write-debug-table (command)
+ (write-string "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
+<html><head></head>
+<body>
+<h1>mod_lisp debug page</h1>" *apache-socket*)
+ (write-request-counts *apache-socket*)
+ (write-string "<table>
+<thead><tr><th>Key</th><th>Value</th></tr></thead>
+<tbody>" *apache-socket*)
+ (loop for (key . value) in command do
+ (format *apache-socket* "<tr><td>~a</td><td>~a</td></tr>" key value))
+ (write-string "</tbody></table></body></html>" *apache-socket*))
+
+
+(defun fixed-html-string ()
+ (with-output-to-string (s)
+ (write-string
+ "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
+<html><head></head><body><h1>mod_lisp fixed page</h1>
+<p>This is a fixed string sent by mod_lisp</p>" s)
+ (write-request-counts s)
+ (write-string "</body></html>" s)))
+
+(defun write-precomputed-page ()
+ (write-string
+ "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
+<html><head></head><body><h1>mod_lisp precomputed page</h1>
+<p>This is a precomputed string sent by mod_lisp</p>" *apache-socket*)
+ (write-request-counts *apache-socket*)
+ (write-string "</body></html>" *apache-socket*))
+
+(defun write-request-counts (s)
+ (format s "<p>Number of server requests: ~D</p>"
+ (get-number-server-requests))
+ (format s "<p>Number of worker requests for this socket: ~D</p>"
+ (get-number-worker-requests)))
+
+
+