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

Contents of /clhp/mod_clhp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Nov 12 01:31:25 2003 UTC (10 years, 5 months ago) by aventimiglia
Branch: MAIN
Changes since 1.1: +13 -17 lines
File MIME type: text/plain
Getting nowhere slowly
1 aventimiglia 1.2 /* $Id: mod_clhp.c,v 1.2 2003/11/12 01:31:25 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     typedef struct _child {
37     request_rec *req;
38     } child_stuff;
39    
40     /* Child init, right now this just runs a quick Lisp command */
41     static int run_lisp ( void *void_child_stuff, child_info *pinfo )
42     {
43     child_stuff *child = (child_stuff *) void_child_stuff;
44     char **env = ap_create_environment ( child->req->pool,
45     child->req->subprocess_env );
46     int child_pid;
47    
48 aventimiglia 1.2 child->req->args = ap_pstrdup ( child->req->pool,
49     "-noinit -quiet -core /usr/lib/cmucl/clhp.core" );
50 aventimiglia 1.1
51     ap_cleanup_for_exec ();
52     child_pid = ap_call_exec ( child->req, pinfo, "/usr/bin/lisp", env, 1 );
53 aventimiglia 1.2
54 aventimiglia 1.1 return (0);
55     }
56    
57     static void send_to_lisp ( BUFF *out_buffer, const char *str )
58     {
59     ap_bwrite ( out_buffer, str, strlen ( str ));
60     ap_bflush ( out_buffer );
61     }
62    
63     static void close_lisp ( BUFF *out_buff )
64     {
65     send_to_lisp ( out_buff, "(quit)" );
66     }
67    
68     static int Handler ( request_rec *req )
69     {
70     BUFF *lisp_out, *lisp_in;
71     child_stuff child;
72    
73     req->content_type = "text/plain";
74     ap_send_http_header ( req );
75    
76     ap_add_common_vars ( req );
77     ap_add_cgi_vars ( req );
78     child.req = req;
79    
80     if ( ! ap_bspawn_child ( req->pool, run_lisp, (void *) &child,
81     kill_always, &lisp_out, &lisp_in, NULL ))
82     return HTTP_INTERNAL_SERVER_ERROR;
83    
84     ap_hard_timeout ( "Hard Timeout", req );
85    
86 aventimiglia 1.2 // Debugging output
87     ap_rputs ( "-----------------\n", child.req );
88     ap_rprintf ( child.req, "ARGS: %s\n-------------\n", child.req->args );
89    
90    
91     send_to_lisp ( lisp_out, "(mapcar #'print ext:*command-line-strings*)");
92     send_to_lisp ( lisp_out, "(progn (loop for f from 1 to 50 do (format t \"-\")) (terpri))" );
93 aventimiglia 1.1 send_to_lisp ( lisp_out, "(mapcar #'print ext:*environment-list*)" );
94 aventimiglia 1.2
95    
96 aventimiglia 1.1 close_lisp ( lisp_out );
97     ap_bclose ( lisp_out );
98    
99     ap_send_fb ( lisp_in, req );
100     ap_bclose ( lisp_in );
101    
102     ap_rputs ( "Done", req );
103     ap_child_terminate ( req );
104    
105     return OK;
106     }
107    
108    
109     // Associate the handler with Handler String
110     static handler_rec Handlers[] =
111     {
112     { "clhp", Handler },
113     { NULL }
114     };
115    
116     module clhp_module = {
117     STANDARD_MODULE_STUFF,
118     NULL, /* Initializer */
119     NULL, /* dir_config creator */
120     NULL, /* dir merger */
121     NULL, /* server config */
122     NULL, /* merge server configs */
123     NULL, /* command-table */
124     Handlers, /* handlers */
125     NULL, /* Filename translation */
126     NULL, /* check user ID */
127     NULL, /* Check auth */
128     NULL, /* Check Access */
129     NULL, /* type checker */
130     NULL, /* Fixups */
131     NULL, /* logger */
132     NULL, /* Header Parser */
133     NULL, /* child init */
134     NULL, /* child exit */
135     NULL, /* post read request */
136     };
137    

  ViewVC Help
Powered by ViewVC 1.1.5