r5235: *** empty log message ***
[cl-modlisp.git] / demo.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: modlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          demo.lisp
6 ;;;; Purpose:       Demonstration command processor
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Dec 2002
9 ;;;;
10 ;;;; $Id: demo.lisp,v 1.1 2003/07/05 00:59:49 kevin Exp $
11 ;;;; *************************************************************************
12
13 (in-package #:modlisp)
14
15
16 (defun demo-apache-command-processor (command)
17   "Sample function to process an apache command"
18   (let ((url (header-value command "url")))
19     (cond
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)))
25       (t
26        (with-ml-page (:precompute nil)
27          (write-debug-table command))))))
28
29 (defun write-debug-table (command)
30   (write-string "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
31 <html><head></head>
32 <body>
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*))
41
42
43 (defun fixed-html-string ()
44   (with-output-to-string (s)
45     (write-string
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)))
51
52 (defun write-precomputed-page ()
53   (write-string
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*))
59
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)))
65
66
67