diff --git a/wdialog/code/src/wdialog/Makefile.code b/wdialog/code/src/wdialog/Makefile.code index 4580a15af44c26e74ba69ea7282852ff0594a704..02d372b5ffa8b5022ec97dd5eebd54a5185c3094 100644 --- a/wdialog/code/src/wdialog/Makefile.code +++ b/wdialog/code/src/wdialog/Makefile.code @@ -1,15 +1,15 @@ -# $Id: Makefile.code,v 1.7 2003-03-09 17:10:04 stolpmann Exp $ +# $Id: Makefile.code,v 1.8 2004-12-04 03:50:50 gremlin43820 Exp $ TOP_DIR=../.. -OBJECTS = wd_ocamlversion.cmo \ - wd_dictionary.cmo wd_types.cmo wd_interactor.cmo \ - wd_encoding.cmo wd_stdlib.cmo wd_var_functions.cmo \ +OBJECTS = wd_ocamlversion.cmo \ + wd_dictionary.cmo wd_types.cmo wd_interactor.cmo \ + wd_encoding.cmo wd_stdlib.cmo wd_var_functions.cmo \ wd_upload.cmo wd_templrep.cmo wd_application_dtd.cmo \ - wd_dialog_decl.cmo wd_application.cmo wd_transform.cmo \ - wd_template.cmo wd_dialog.cmo \ - wd_universe.cmo wd_cycle.cmo wd_run_cgi.cmo \ - wd_run_jserv.cmo + wd_dialog_decl.cmo wd_application.cmo wd_transform.cmo \ + wd_template.cmo wd_dialog.cmo \ + wd_universe.cmo wd_cycle.cmo wd_run_fcgi.cmo \ + wd_run_cgi.cmo wd_run_jserv.cmo # interfaces to include in the ocamldoc output: INTERFACES = $(shell echo *.mli) diff --git a/wdialog/code/src/wdialog/wd_run_fcgi.ml b/wdialog/code/src/wdialog/wd_run_fcgi.ml new file mode 100644 index 0000000000000000000000000000000000000000..9407f91298842d1820ff0fad6bd907e639a96407 --- /dev/null +++ b/wdialog/code/src/wdialog/wd_run_fcgi.ml @@ -0,0 +1,135 @@ +(* + * + * Copyright 2002 Joachim Schrod Network and Publication Consultance GmbH, Gerd Stolpmann + * + * + * This file is part of WDialog. + * + * WDialog is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * WDialog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WDialog; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + *) + +(* $Id: wd_run_fcgi.ml,v 1.1 2004-12-04 03:51:08 gremlin43820 Exp $ + * ---------------------------------------------------------------------- + * + *) + +open Wd_types +open Netcgi +open Netchannels +open Netcgi_fcgi +open Netcgi_types + +let print_error (ch:out_obj_channel) exc = + let s = Printexc.to_string exc in + let out = ch # output_string in + out "

Software error

\n"; + out ""; + out (Netencoding.Html.encode_from_latin1 s); + out "\n" +;; + + +let processing name hdr = + `Automatic +;; + + +let create_request_handler + ?(charset = `Enc_iso88591) + ?session_manager + ?(no_cache = true) + ?(error_page = print_error) + ?response_header + ?(reg = (fun _ -> ())) + ~uifile + () = + + (* Load the UI term: *) + + let app = + if Filename.check_suffix uifile ".ui.bin" then + Wd_transform.load_uiapplication ~charset uifile + else + if Filename.check_suffix uifile ".ui" then + Wd_transform.parse_uiapplication ~charset uifile + else + failwith "Wd_run_jserv: Bad file extension of ~uifile" + in + + let universe = new Wd_universe.universe app in + reg universe; + + let activate (cgi : cgi_activation) = + begin try + let cache = + match cgi # request_method with + `GET -> `No_cache + | `POST -> if no_cache then `No_cache else `Unspecified + | _ -> assert false + in + + let charset_s = + Netconversion.string_of_encoding (charset :> Netconversion.encoding) in + + let response_header = + match response_header with + None -> { rh_status = `Ok; + rh_content_type = "text/html; charset=" ^ charset_s; + (* Note: Some browsers (e.g. Mozilla-0.9.6) do not like + * quotes around charset + *) + rh_cache = cache; + rh_filename = None; + rh_language = None; + rh_script_type = None; + rh_style_type = None; + rh_set_cookie = []; + rh_fields = []; + } + | Some rh -> rh + in + + Wd_cycle.process_request ?session_manager ~response_header universe cgi; + + with + exc -> + cgi # output # rollback_work(); + cgi # set_header ~status:`Internal_server_error ~cache:`No_cache (); + error_page (cgi#output :> out_obj_channel) exc; + (* may raise another exception! *) + end; + cgi # output # commit_work(); + cgi # finalize(); + in + activate +;; + + + +(* ====================================================================== + * History: + * + * $Log: wd_run_fcgi.ml,v $ + * Revision 1.1 2004-12-04 03:51:08 gremlin43820 + * finially adding fastcgi support + * + * Revision 1.2 2003/01/04 21:55:25 stolpmann + * new record response_header + * + * Revision 1.1 2002/03/19 22:09:55 stolpmann + * Initial revision. + * + *) diff --git a/wdialog/code/src/wdialog/wd_run_fcgi.mli b/wdialog/code/src/wdialog/wd_run_fcgi.mli new file mode 100644 index 0000000000000000000000000000000000000000..c167f74873186312fc289ab47081ca13409f9ce8 --- /dev/null +++ b/wdialog/code/src/wdialog/wd_run_fcgi.mli @@ -0,0 +1,115 @@ +(* + * + * Copyright 2002 Joachim Schrod Network and Publication Consultance GmbH, Gerd Stolpmann + * + * + * This file is part of WDialog. + * + * WDialog is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * WDialog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WDialog; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + *) + +(* $Id: wd_run_fcgi.mli,v 1.1 2004-12-04 03:51:15 gremlin43820 Exp $ + * ---------------------------------------------------------------------- + * + *) + +(** This module contains a customizable main program for application servers + connected with the fastcgi protocol + *) + +open Wd_types +open Netchannels +open Netcgi_fcgi + +val create_request_handler : + ?charset:Pxp_types.rep_encoding -> (* default: `Enc_iso88591 *) + ?session_manager:session_manager_type -> (* defalt: instant_session_manager *) + ?no_cache:bool -> (* default: true *) + ?error_page:(out_obj_channel -> exn -> unit) -> (* default: a simple error page *) + ?response_header:response_header -> (* default: see below *) + ?reg:(universe_type -> unit) -> + uifile:string -> + unit -> (Netcgi_types.cgi_activation -> unit) + + (** This function creates a request handler for a fastcgi-based application + * server. Use this function like in this example: + * + * Netcgi_fcgi.serv + * (Wd_run_fcgi.create_request_handler + * ~session_manager: (new memory_session_manager) + * ~charset:`Enc_utf8 ~reg ~uifile:"adder.ui" ()) + * buffered_transactional_optype + * + * This main program creates a single threaded (single process) server + * which handles requests sequentially. Since fastcgi processes are managed + * by an application server, this is the only mode provided. The application + * server can then be configured to create process pools, cgi style + * servers, etc.. See the manual for your fastcgi application server for details. + * + * The application is accessible under the URL which you have configured + * for it in your web server. + * + * Call the function [create_request_handler] as follows: + * + * {[let req_hdl = create_request_handler ~reg ~uifile ()]} + * + * The argument [~reg] registers the dialog classes (like in Wd_run_cgi). + * The argument [~uifile] must be the absolute path of the UI definition. + * The suffix of this file must be ".ui" or ".ui.bin". + * + * @param charset determines the character set for the internal representation + * of strings and for the generated HTML pages. (Note that the parsed + * XML files can have character sets independent of this setting.) + * The default is [ISO-8859-1]. + * + * @param no_cache If [true]: The CGI response contains header directives + * preventing the browser (and all caches between server and browser) + * from storing the response. This ensures that never a cache copy + * is taken, and for many browsers, the history is no longer usable + * (when hitting the "Back" button, the user only gets a message + * that the data is expired, but not the old page). + * The default is [true]. + * + * @param error_page This function is called when an exception is caught. + * It can generate an error page by writing a nicely formatted + * message to the output channel. The default is a function that + * outputs a simple error page. + * + * @param response_header If set, this parameter is taken as the initial + * HTTP response header while processing the request. If omitted, + * the response header defaults to: The content type is text/html, + * the character set as determined by [charset], the caching header is + * set according to [no_cache]. + *) + + +(* ====================================================================== + * History: + * + * $Log: wd_run_fcgi.mli,v $ + * Revision 1.1 2004-12-04 03:51:15 gremlin43820 + * finially adding fastcgi support + * + * Revision 1.3 2003/03/21 14:23:44 stolpmann + * ocamldoc updated + * + * Revision 1.2 2003/01/04 21:55:25 stolpmann + * new record response_header + * + * Revision 1.1 2002/03/19 22:09:55 stolpmann + * Initial revision. + * + *)