From 232d52d33fe530971f81b57bbc8b024fb259c4fd Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 27 Sep 2004 12:37:54 +0000 Subject: [PATCH] Fixed up to work with mod_caml 1.3.0-2. --- scripts/.depend | 28 ++++++++---------- scripts/Makefile | 6 ++-- scripts/cgi_expires.ml | 69 ------------------------------------------- scripts/cocanwiki.ml | 15 ++-------- scripts/cocanwiki_cgi_args.ml | 45 ---------------------------- scripts/contact.ml | 5 ++-- scripts/file.ml | 4 +-- scripts/hoststyle.ml | 4 +-- scripts/image.ml | 4 +-- scripts/page.ml | 4 +-- scripts/pagestyle.ml | 4 +-- 11 files changed, 29 insertions(+), 159 deletions(-) delete mode 100644 scripts/cgi_expires.ml delete mode 100644 scripts/cocanwiki_cgi_args.ml diff --git a/scripts/.depend b/scripts/.depend index 2523154..e9c333a 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -1,7 +1,5 @@ 00-TEMPLATE.cmo: cocanwiki.cmo cocanwiki_template.cmi 00-TEMPLATE.cmx: cocanwiki.cmx cocanwiki_template.cmx -cgi_expires.cmo: cocanwiki_date.cmo -cgi_expires.cmx: cocanwiki_date.cmx change_password.cmo: cocanwiki.cmo cocanwiki_ok.cmo change_password.cmx: cocanwiki.cmx cocanwiki_ok.cmx change_password_form.cmo: cocanwiki.cmo cocanwiki_template.cmi @@ -96,8 +94,8 @@ edit_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo edit_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx edit_user_form.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi edit_user_form.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx -file.cmo: cgi_expires.cmo cocanwiki.cmo -file.cmx: cgi_expires.cmx cocanwiki.cmx +file.cmo: cocanwiki.cmo +file.cmx: cocanwiki.cmx files.cmo: cocanwiki.cmo cocanwiki_template.cmi files.cmx: cocanwiki.cmx cocanwiki_template.cmx forgot_password.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo @@ -108,10 +106,10 @@ history.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi history.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx host_menu.cmo: cocanwiki.cmo cocanwiki_template.cmi host_menu.cmx: cocanwiki.cmx cocanwiki_template.cmx -hoststyle.cmo: cgi_expires.cmo cocanwiki.cmo cocanwiki_template.cmi -hoststyle.cmx: cgi_expires.cmx cocanwiki.cmx cocanwiki_template.cmx -image.cmo: cgi_expires.cmo cocanwiki.cmo -image.cmx: cgi_expires.cmx cocanwiki.cmx +hoststyle.cmo: cocanwiki.cmo cocanwiki_template.cmi +hoststyle.cmx: cocanwiki.cmx cocanwiki_template.cmx +image.cmo: cocanwiki.cmo +image.cmx: cocanwiki.cmx images.cmo: cocanwiki.cmo cocanwiki_template.cmi images.cmx: cocanwiki.cmx cocanwiki_template.cmx largest_pages.cmo: cocanwiki.cmo cocanwiki_template.cmi @@ -136,12 +134,10 @@ mailing_list_view.cmo: cocanwiki.cmo cocanwiki_date.cmo \ cocanwiki_template.cmi mailing_list_view.cmx: cocanwiki.cmx cocanwiki_date.cmx \ cocanwiki_template.cmx -page.cmo: cocanwiki.cmo cocanwiki_cgi_args.cmo cocanwiki_date.cmo \ - cocanwiki_ok.cmo cocanwiki_server_settings.cmo cocanwiki_template.cmi \ - wikilib.cmi -page.cmx: cocanwiki.cmx cocanwiki_cgi_args.cmx cocanwiki_date.cmx \ - cocanwiki_ok.cmx cocanwiki_server_settings.cmx cocanwiki_template.cmx \ - wikilib.cmx +page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \ + cocanwiki_server_settings.cmo cocanwiki_template.cmi wikilib.cmi +page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \ + cocanwiki_server_settings.cmx cocanwiki_template.cmx wikilib.cmx page_email_confirm.cmo: cocanwiki.cmo cocanwiki_ok.cmo page_email_confirm.cmx: cocanwiki.cmx cocanwiki_ok.cmx page_email_form.cmo: cocanwiki.cmo cocanwiki_template.cmi @@ -152,8 +148,8 @@ page_email_send.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx \ cocanwiki_template.cmx page_email_unsubscribe.cmo: cocanwiki.cmo cocanwiki_ok.cmo page_email_unsubscribe.cmx: cocanwiki.cmx cocanwiki_ok.cmx -pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo -pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx +pagestyle.cmo: cocanwiki.cmo +pagestyle.cmx: cocanwiki.cmx preview.cmo: cocanwiki.cmo wikilib.cmi preview.cmx: cocanwiki.cmx wikilib.cmx recent.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi diff --git a/scripts/Makefile b/scripts/Makefile index a3179c6..3968181 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.27 2004/09/25 16:05:03 rich Exp $ +# $Id: Makefile,v 1.28 2004/09/27 12:37:54 rich Exp $ include ../Makefile.config @@ -8,7 +8,6 @@ OCAMLCFLAGS := -w s -I +apache -I +pcre -I +dbi -I +extlib CPP := cpp LIB_OBJS := \ - cocanwiki_cgi_args.cmo \ cocanwiki_date.cmo \ cocanwiki_version.cmo \ cocanwiki_files.cmo \ @@ -20,8 +19,7 @@ LIB_OBJS := \ cocanwiki.cmo \ cocanwiki_diff.cmo \ cocanwiki_emailnotify.cmo \ - wikilib.cmo \ - cgi_expires.cmo + wikilib.cmo OBJS := 00-TEMPLATE.cmo \ change_password.cmo \ diff --git a/scripts/cgi_expires.ml b/scripts/cgi_expires.ml deleted file mode 100644 index d4e2428..0000000 --- a/scripts/cgi_expires.ml +++ /dev/null @@ -1,69 +0,0 @@ -(* COCANWIKI - a wiki written in Objective CAML. - * Written by Richard W.M. Jones . - * Copyright (C) 2004 Merjis Ltd. - * $Id: cgi_expires.ml,v 1.3 2004/09/09 12:21:22 rich Exp $ - * - * This program 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. - * - * This program 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 this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - *) - -open Apache -open Registry -open Cgi - -open Printf - -open Cocanwiki_date - -(* This library should eventually be integrated with mod_caml. XXX *) - -(* Expires headers. - * - * All content on wiki sites is dynamic, but we try to make it look static - * for users and search engines. We have 4 types of 'Expires' headers that - * we can send: - * - * expires_past () - * Send an expiry header in the past (theoretically removing content from - * caches). - * expires_short () - * Send a short expiry header (now + 5 minutes). This should be used for - * all news pages. - * expires_medium () - * Send a medium-term expiry header (now + 24 hours). This should be used - * for all "static" content. - * expires_long () - * Send a very long expiry header (now + 2 years). This should be used for - * content which really never will change. - *) -let expires_past, expires_short, expires_medium, expires_long = - let make offset = - let t = Unix.time () in - let tm = Unix.gmtime (t +. float offset) in - sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT" - (short_weekday tm.Unix.tm_wday) - tm.Unix.tm_mday - (short_month (tm.Unix.tm_mon + 1)) - (tm.Unix.tm_year + 1900) - tm.Unix.tm_hour - tm.Unix.tm_min - tm.Unix.tm_sec - in - let mins m = m * 60 in - let days d = d * 86400 in - (fun () -> make (mins (-5))), - (fun () -> make (mins 5)), - (fun () -> make (days 1)), - (fun () -> make (days (365*2))) diff --git a/scripts/cocanwiki.ml b/scripts/cocanwiki.ml index e6fb225..037c654 100644 --- a/scripts/cocanwiki.ml +++ b/scripts/cocanwiki.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki.ml,v 1.12 2004/09/23 15:16:21 rich Exp $ + * $Id: cocanwiki.ml,v 1.13 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,14 +34,6 @@ module Pool = DbiPool (Dbi_postgres) *) let _get_dbh r = Pool.get r "cocanwiki" -(* The [CgiExit] exception should be folded back into the base - * mod_caml code at some point. It just causes the 'run' function to - * return at that point safely. (XXX) - *) -exception CgiExit - -let return () = raise CgiExit - (* Permissions and restrictions. * * Use the optional ~restrict parameter to register_script to restrict @@ -195,10 +187,7 @@ let register_script ?(restrict = []) ?(anonymous = true) run = if permitted then ( (* Call the actual CGI script. *) - try - run r q dbh hostid host user - with - CgiExit -> () + run r q dbh hostid host user ) else error ~back_button:true ~title:"Access denied" diff --git a/scripts/cocanwiki_cgi_args.ml b/scripts/cocanwiki_cgi_args.ml deleted file mode 100644 index c019c0d..0000000 --- a/scripts/cocanwiki_cgi_args.ml +++ /dev/null @@ -1,45 +0,0 @@ -(* COCANWIKI - a wiki written in Objective CAML. - * Written by Richard W.M. Jones . - * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_cgi_args.ml,v 1.1 2004/09/24 10:44:55 rich Exp $ - * - * This program 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. - * - * This program 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 this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * This badly needs to become a standard part of the Cgi library. - *) - -let split1_re = Pcre.regexp "\\?" -let split2_re = Pcre.regexp "&" -let split3_re = Pcre.regexp "=" - -let parse full_url = - let url, qs = match Pcre.split ~rex:split1_re ~max:2 full_url with - | [url] | [url;""] -> url, None - | [url;qs] -> url, Some qs - | _ -> assert false in - let args = match qs with - None -> [] - | Some qs -> - let args = Pcre.split ~rex:split2_re qs in - let f arg = - match Pcre.split ~rex:split3_re ~max:2 arg with - | [] -> ("", "") - | [key] -> (key, "") - | [key;value] -> (key, value) - | _ -> assert false - in - List.map f args in - url, qs, args diff --git a/scripts/contact.ml b/scripts/contact.ml index 436ee35..7cf8ac5 100644 --- a/scripts/contact.ml +++ b/scripts/contact.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: contact.ml,v 1.4 2004/09/25 12:53:55 rich Exp $ + * $Id: contact.ml,v 1.5 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,7 +43,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = let name = try q#param "id" with - Not_found -> fail "The 'name' field is missing in that form." in + Not_found -> + fail "The 'name' field is missing in that form." in (* Get the contacts / emails from the database. *) let sth = dbh#prepare_cached "select id, subject from contacts diff --git a/scripts/file.ml b/scripts/file.ml index a964aa3..0084d12 100644 --- a/scripts/file.ml +++ b/scripts/file.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: file.ml,v 1.5 2004/09/09 12:21:22 rich Exp $ + * $Id: file.ml,v 1.6 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = if version <> None then (* Set a medium-length expiry time on this resource. *) - Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium()); + Table.set (Request.headers_out r) "Expires" (Expires.medium ()); q#header ~content_type:mime_type (); print_string r data diff --git a/scripts/hoststyle.ml b/scripts/hoststyle.ml index e2de804..642ba71 100644 --- a/scripts/hoststyle.ml +++ b/scripts/hoststyle.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: hoststyle.ml,v 1.4 2004/09/09 12:21:22 rich Exp $ + * $Id: hoststyle.ml,v 1.5 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = * people will need to hit [Shift]+Reload, I'm going to set a * medium-length expiry time on this resource. *) - Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium ()); + Table.set (Request.headers_out r) "Expires" (Expires.medium ()); q#header ~content_type:"text/css" (); print_string r css diff --git a/scripts/image.ml b/scripts/image.ml index 4484546..2515dcd 100644 --- a/scripts/image.ml +++ b/scripts/image.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: image.ml,v 1.5 2004/09/09 12:21:22 rich Exp $ + * $Id: image.ml,v 1.6 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,7 +55,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = if version <> None then (* Set a medium-length expiry time on this resource. *) - Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium()); + Table.set (Request.headers_out r) "Expires" (Expires.medium ()); q#header ~content_type:mime_type (); print_string r data diff --git a/scripts/page.ml b/scripts/page.ml index d9b85ec..c756ae3 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.21 2004/09/24 16:30:07 rich Exp $ + * $Id: page.ml,v 1.22 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -86,7 +86,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = let search_terms_from_referer referer = let _, argnames = List.find (fun (rex, _) -> Pcre.pmatch ~rex referer) search_engines in - let _, _, args = Cocanwiki_cgi_args.parse referer in + let args = Cgi_args.parse referer in let argname = List.find (fun argname -> List.mem_assoc argname args) argnames in let search_string = List.assoc argname args in diff --git a/scripts/pagestyle.ml b/scripts/pagestyle.ml index 2ad181f..a0d5157 100644 --- a/scripts/pagestyle.ml +++ b/scripts/pagestyle.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: pagestyle.ml,v 1.4 2004/09/09 12:21:22 rich Exp $ + * $Id: pagestyle.ml,v 1.5 2004/09/27 12:37:54 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,7 +57,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = * people will need to hit [Shift]+Reload, I'm going to set a * medium-length expiry time on this resource. *) - Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium ()); + Table.set (Request.headers_out r) "Expires" (Expires.medium ()); q#header ~content_type:"text/css" (); print_string r css -- 1.8.3.1