/[clhp]/clhp/mod_clhp.c
ViewVC logotype

Contents of /clhp/mod_clhp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Oct 29 21:34:44 2003 UTC (10 years, 5 months ago) by aventimiglia
Branch: MAIN
File MIME type: text/plain
Working on Apache Module
1 /* $Id: mod_clhp.c,v 1.1 2003/10/29 21:34:44 aventimiglia Exp $
2
3 CLHP the Common Lisp Hypertext Preprocessor
4 (C) 2003 Anthony J Ventimiglia
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 email: aventimiglia@common-lisp.net
21 HomePage: http://common-lisp.net/project/clhp/
22
23 Apache module for clhp
24 */
25
26 #include "httpd.h"
27 #include "http_config.h"
28 #include "http_protocol.h"
29 #include "util_script.h"
30 #include <string.h>
31
32 #define DEBUG_CLHP 1
33
34 #ifndef HUGE_STRING_LEN
35 #define HUGE_STRING_LEN 65000
36 #endif
37
38 typedef struct _child {
39 request_rec *req;
40 } child_stuff;
41
42 /* Child init, right now this just runs a quick Lisp command */
43 static int run_lisp ( void *void_child_stuff, child_info *pinfo )
44 {
45 child_stuff *child = (child_stuff *) void_child_stuff;
46 char **env = ap_create_environment ( child->req->pool,
47 child->req->subprocess_env );
48 int child_pid;
49
50 #ifdef DEBUG_CLHP
51 FILE *dbg = ap_pfopen ( child->req->pool, "/tmp/clhp.debug", "w" );
52 int i;
53 #endif
54
55 #ifdef DEBUG_CLHP
56 fprintf ( dbg, "run_lisp: env:\n" );
57 for ( i = 0; env[i]; ++i )
58 fprintf ( dbg, "\t'%s'\n", env[i] );
59 fprintf ( dbg, "\nargs:\t\"%s\"\n", child->req->args );
60 ap_pfclose ( child->req->pool, dbg );
61 #endif
62
63 child->req->args = "-noinit -quiet -core /usr/lib/cmucl/clhp.core";
64 ap_cleanup_for_exec ();
65 child_pid = ap_call_exec ( child->req, pinfo, "/usr/bin/lisp", env, 1 );
66
67 return (0);
68 }
69
70 static void send_to_lisp ( BUFF *out_buffer, const char *str )
71 {
72 ap_bwrite ( out_buffer, str, strlen ( str ));
73 ap_bflush ( out_buffer );
74 }
75
76 static void close_lisp ( BUFF *out_buff )
77 {
78 send_to_lisp ( out_buff, "(quit)" );
79 }
80
81 static int Handler ( request_rec *req )
82 {
83 BUFF *lisp_out, *lisp_in;
84 child_stuff child;
85
86 req->content_type = "text/plain";
87 ap_send_http_header ( req );
88
89 ap_add_common_vars ( req );
90 ap_add_cgi_vars ( req );
91 child.req = req;
92
93 if ( ! ap_bspawn_child ( req->pool, run_lisp, (void *) &child,
94 kill_always, &lisp_out, &lisp_in, NULL ))
95 return HTTP_INTERNAL_SERVER_ERROR;
96
97 ap_hard_timeout ( "Hard Timeout", req );
98
99 send_to_lisp ( lisp_out, "(mapcar #'print ext:*environment-list*)" );
100 close_lisp ( lisp_out );
101 ap_bclose ( lisp_out );
102
103 ap_send_fb ( lisp_in, req );
104 ap_bclose ( lisp_in );
105
106 ap_rputs ( "Done", req );
107 ap_child_terminate ( req );
108
109 return OK;
110 }
111
112
113 // Associate the handler with Handler String
114 static handler_rec Handlers[] =
115 {
116 { "clhp", Handler },
117 { NULL }
118 };
119
120 module clhp_module = {
121 STANDARD_MODULE_STUFF,
122 NULL, /* Initializer */
123 NULL, /* dir_config creator */
124 NULL, /* dir merger */
125 NULL, /* server config */
126 NULL, /* merge server configs */
127 NULL, /* command-table */
128 Handlers, /* handlers */
129 NULL, /* Filename translation */
130 NULL, /* check user ID */
131 NULL, /* Check auth */
132 NULL, /* Check Access */
133 NULL, /* type checker */
134 NULL, /* Fixups */
135 NULL, /* logger */
136 NULL, /* Header Parser */
137 NULL, /* child init */
138 NULL, /* child exit */
139 NULL, /* post read request */
140 };
141

  ViewVC Help
Powered by ViewVC 1.1.5