(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: file.ml,v 1.8 2004/10/15 16:03:01 rich Exp $
+ * $Id: file.ml,v 1.12 2004/11/01 16:24:32 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
open Cocanwiki
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ =
let name = q#param "name" in
let version =
try Some (int_of_string (q#param "version")) with Not_found -> None in
sth#execute args;
let data, mime_type, deleted =
- match sth#fetch1 () with
- [ `Binary data; `String mime_type; `Bool deleted ] ->
- data, mime_type, deleted
- | _ -> assert false in
+ try
+ (match sth#fetch1 () with
+ [ `Binary data; `String mime_type; `Bool deleted ] ->
+ data, mime_type, deleted
+ | _ -> assert false)
+ with
+ Not_found -> raise (HttpError cHTTP_NOT_FOUND) in
- (* If deleted, refuse to serve this file except if called from the
- * deleted files page.
- *)
+ (* If deleted, refuse to serve this file except if called from the site. *)
if deleted then (
let referer =
try Table.get (Request.headers_in r) "Referer" with Not_found -> "" in
let ok =
- try String.find referer "/_files?deleted"; true
+ try String.find referer hostname; true
with String.Invalid_string -> false in
- if not ok then
- failwith "file.ml: bandwidth theft avoided"
+ if not ok then (
+ prerr_endline "file.ml: bandwidth theft avoided";
+ raise (HttpError cHTTP_NOT_FOUND)
+ )
);
if version <> None then
(string_of_int (String.length data));
q#header ~content_type:mime_type ();
- print_string r data
+ ignore (print_string r data)
let () =
register_script ~restrict:[CanView] run