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

Contents of /clhp/mod_clhp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Thu Nov 13 19:37:41 2003 UTC (10 years, 5 months ago) by aventimiglia
Branch: MAIN
CVS Tags: rel-0-2-1alpha, HEAD
Changes since 1.4: +8 -1 lines
File MIME type: text/plain
Removed HEADER and INCLUDE functions, because they were not working
properly. mod_clhp generates a simple header. In the future, CLHP will
have to get control of this again, for doing things like setting
cookies and redirections.
1 aventimiglia 1.5 /* $Id: mod_clhp.c,v 1.5 2003/11/13 19:37:41 aventimiglia Exp $
2 aventimiglia 1.1
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     #ifndef HUGE_STRING_LEN
33     #define HUGE_STRING_LEN 65000
34     #endif
35    
36 aventimiglia 1.3 // AP_CALL_EXEC does not properly pass it's arguments
37     #define BROKEN_AP_CALL_EXEC 1
38    
39     #define LISP_COMMAND "/usr/bin/lisp"
40     #define LISP_OPTIONS "-noinit -nositeinit -quiet -batch"
41     #define LISP_CORE "-core /usr/lib/cmucl/clhp.core"
42     #define LISP_EVAL "-eval '(clhp:parse (cdr (assoc :script_filename ext:*environment-list*)))(quit)'"
43    
44 aventimiglia 1.1 typedef struct _child {
45     request_rec *req;
46     } child_stuff;
47    
48     /* Child init, right now this just runs a quick Lisp command */
49     static int run_lisp ( void *void_child_stuff, child_info *pinfo )
50     {
51     child_stuff *child = (child_stuff *) void_child_stuff;
52     char **env = ap_create_environment ( child->req->pool,
53     child->req->subprocess_env );
54     int child_pid;
55    
56 aventimiglia 1.3 #ifndef BROKEN_AP_CALL_EXEC
57     child->req->args = ap_psprintf ( child->req->pool, "%s %s %s", LISP_OPTIONS,
58     LISP_CORE, LISP_EVAL );
59     ap_cleanup_for_exec ();
60     child_pid = ap_call_exec ( child->req, pinfo, LISP_COMMAND, env, 1 );
61     #else
62     char *command = ap_psprintf (child->req->pool, "%s %s %s %s", LISP_COMMAND,
63     LISP_OPTIONS, LISP_CORE, LISP_EVAL );
64 aventimiglia 1.1 ap_cleanup_for_exec ();
65 aventimiglia 1.3 child_pid = ap_call_exec ( child->req, pinfo, command, env, 1 );
66     #endif
67    
68     #ifdef WIN32
69     return ( child_pid );
70     #else
71     exit ( 0 );
72     // Should not get here
73     return 0;
74     #endif
75 aventimiglia 1.1 }
76    
77     static int Handler ( request_rec *req )
78     {
79     BUFF *lisp_out, *lisp_in;
80     child_stuff child;
81    
82     ap_add_common_vars ( req );
83     ap_add_cgi_vars ( req );
84     child.req = req;
85 aventimiglia 1.5
86     // First we should check if the document exists
87     // But for now...
88     req->content_type = "text/html";
89     ap_table_set ( req->headers_out, "X-Powered-By",
90     "CLHP Common Lisp Hypertext Preprocessor" );
91     ap_send_http_header ( req );
92 aventimiglia 1.1
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 aventimiglia 1.3 // ap_hard_timeout ( "Hard Timeout", req );
98 aventimiglia 1.1 ap_bclose ( lisp_out );
99     ap_send_fb ( lisp_in, req );
100     ap_bclose ( lisp_in );
101     ap_child_terminate ( req );
102    
103     return OK;
104     }
105    
106    
107     // Associate the handler with Handler String
108     static handler_rec Handlers[] =
109     {
110 aventimiglia 1.4 { "clhp-handler", Handler },
111 aventimiglia 1.1 { NULL }
112     };
113    
114     module clhp_module = {
115     STANDARD_MODULE_STUFF,
116     NULL, /* Initializer */
117     NULL, /* dir_config creator */
118     NULL, /* dir merger */
119     NULL, /* server config */
120     NULL, /* merge server configs */
121     NULL, /* command-table */
122     Handlers, /* handlers */
123     NULL, /* Filename translation */
124     NULL, /* check user ID */
125     NULL, /* Check auth */
126     NULL, /* Check Access */
127     NULL, /* type checker */
128     NULL, /* Fixups */
129     NULL, /* logger */
130     NULL, /* Header Parser */
131     NULL, /* child init */
132     NULL, /* child exit */
133     NULL, /* post read request */
134     };
135    

  ViewVC Help
Powered by ViewVC 1.1.5