From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D30FCBB84 for ; Mon, 10 Jul 2006 17:02:07 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6AF26KF009113 for ; Mon, 10 Jul 2006 17:02:07 +0200 Received: by nf-out-0910.google.com with SMTP id a25so681389nfc for ; Mon, 10 Jul 2006 08:02:04 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=N7oeMTYfDQ7HbZ5uast9qfI7Vtl409zqJk7HqtoLVcae4Wytrg006BfSUQlm3m/mJ/Za5MTZtBvyvniTM7vsoko7jbLkmsaZpx1nLJOtzgAfoBeYgLdzwJTJpOdK5vFaSJely3boEy37azZjuZKWJLdcIw0qEIxFGrcllwVMCSM= Received: by 10.78.157.15 with SMTP id f15mr1726548hue; Mon, 10 Jul 2006 08:02:03 -0700 (PDT) Received: by 10.78.116.20 with HTTP; Mon, 10 Jul 2006 08:02:02 -0700 (PDT) Message-ID: Date: Mon, 10 Jul 2006 11:02:02 -0400 From: "Jonathan Hayward http://JonathansCorner.com" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] "Hello web" please In-Reply-To: <20060708.224756.70330795.Christophe.Troestler@umh.ac.be> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_10263_26416646.1152543722971" References: <20060708.224756.70330795.Christophe.Troestler@umh.ac.be> X-j-chkmail-Score: MSGID : 44B26BEE.001 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44B26BEE.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocamlnet:01 usr:01 ocaml:01 netcgi:01 netencoding:01 encodes:01 foo:01 foo:01 buffer:01 buffered:01 netcgi:01 buffered:01 netchannels:01 syntax:01 syntax:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.3 required=5.0 tests=DNS_FROM_RFC_ABUSE,HTML_30_40, HTML_MESSAGE,RCVD_BY_IP,RCVD_IN_BL_SPAMCOP_NET autolearn=disabled version=3.0.3 ------=_Part_10263_26416646.1152543722971 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I need help getting Ocamlnet to work at a basic level. I tried running the script from the command-like to more easily access diagnostic output. What should the shebang line say? Right now I have the following (mostly) paste of the demo script, plus shebang line; when I run it from within apache I get an internal server error. (A copy of the comman= d line output follows the script). -- #!/usr/local/bin/ocaml open Netcgi let text =3D Netencoding.Html.encode_from_latin1 (* This function encodes "<", ">", "&", double quotes, and Latin 1 characters as character entities. E.g. text "<" =3D "<", and text "=E4" =3D "ä" *) (* Normally you would use a template system instead of this *) let html_page (cgi:cgi) title html =3D let out =3D cgi#out_channel#output_string in out "\n"; out ("\n" ^ text title ^" \n"); out html; out "\n" let main (cgi:cgi) =3D cgi#set_header ~cache:`No_cache ~content_type:"text/html; charset=3D\"iso-8859-1\"" (); let foo =3D cgi#argument_value "foo" let html =3D match foo with | "1" -> "Yes" | "0" -> "No" | _ -> "Undefined" in html_page cgi foo html (* You can buffer or not the output. If buffered you can rollback (useful in case of error). You can replace Netcgi_cgi.run by another connector entry point (FCGI, SCGI, AJP, Apache mod). *) let () =3D let buffered _ ch =3D new Netchannels.buffered_trans_channel ch in Netcgi_cgi.run ~output_type:(`Transactional buffered) main -- Couldnt get a file descriptor referring to the console Could not get a file descriptor referring to the console ./demo.ml: line 4: let: =3D: syntax error: operand expected (error token is "=3D") ./demo.ml: line 5: demo.ml: command not found ./demo.ml: line 6: characters: command not found ./demo.ml: line 7: text: command not found ./demo.ml: line 9: demo.ml: command not found ./demo.ml: line 10: syntax error near unexpected token `(' ./demo.ml: line 10: `let html_page (cgi:cgi) title html =3D' -- On 7/8/06, Christophe TROESTLER wrote: > > On Sat, 8 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" < > christos.jonathan.hayward@gmail.com> wrote: > > > > I'm trying to figure out how to use CamlGI with OCaml, [...] > > CamlGI code has been integrated into the Netcgi component > > of OcamlNet-2 , please use > that instead. > > > [...] script that [...] prints a webpage saying only "Yes", "No", > > "Other" or "Undefined" depending on whether the CGI variable "foo" > > has value 1, 0, some other defined value, or is undefined (never > > mind about multiple values)? > > You can find examples in the examples/ directory (add.ml is a very > simple one). As for the specific example you desire, it is attached. > It is maybe a bit more complex that you expected because it > demonstrates additional features (text escaping, setting the header, > buffered output). > > Hope it helps, > ChriS > > > open Netcgi > > let text =3D Netencoding.Html.encode_from_latin1 > (* This function encodes "<", ">", "&", double quotes, and Latin 1 > characters as character entities. E.g. text "<" =3D "<", and > text "=E4" =3D "ä" *) > > (* Normally you would use a template system instead of this *) > let html_page (cgi:cgi) title html =3D > let out =3D cgi#out_channel#output_string in > out " \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"; > out ("\n" ^ text title ^" > \n"); > out html; > out "\n" > > let main (cgi:cgi) =3D > cgi#set_header > ~cache:`No_cache > ~content_type:"text/html; charset=3D\"iso-8859-1\"" > (); > let foo =3D cgi#argument_value "foo" > let html =3D match foo with > | "1" -> "Yes" > | "0" -> "No" > | _ -> "Undefined" in > html_page cgi foo html > > (* You can buffer or not the output. If buffered you can rollback > (useful in case of error). You can replace Netcgi_cgi.run by > another connector entry point (FCGI, SCGI, AJP, Apache mod). *) > let () =3D > let buffered _ ch =3D new Netchannels.buffered_trans_channel ch in > Netcgi_cgi.run ~output_type:(`Transactional buffered) main > > > --=20 ++ Jonathan Hayward, jonathan.hayward@pobox.com ** To see an award-winning website with stories, essays, artwork, ** games, and a four-dimensional maze, why not visit my home page? ** All of this is waiting for you at http://JonathansCorner.com ** If you'd like a Google Mail (gmail.com) account, please tell me! ------=_Part_10263_26416646.1152543722971 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I need help getting Ocamlnet to work at a basic level.

I tried running the script from the command-like to more easily access diagnostic output. What should the shebang line say? Right now I have the following (mostly) paste of the demo script, plus shebang line; when I run it from within apache I get an internal server error. (A copy of the command line output follows the script).

--

#!/usr/local/bin/ocaml
open Netcgi

let text =3D Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&= amp;", double quotes, and Latin 1
     characters as character entities.  E.g. text = "<" =3D "&lt;", and
     text "=E4" =3D "&auml;" *)=

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =3D
  let out =3D cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\&= quot; \
        \" http://www.w3.org/TR/REC-html40/strict.dtd\= ">\n";
  out ("<html>\n<head><title>" ^ text titl= e ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =3D
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=3D\"iso-8859= -1\""
    ();
  let foo =3D cgi#argument_value "foo"
  let html =3D match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by    another connector entry point (FCGI, SCGI, AJP, Apache mod). *= )
let () =3D
  let buffered _ ch =3D new Netchannels.buffered_trans_channel ch in   Netcgi_cgi.run ~output_type:(`Transactional buffered) main


--

Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
./demo.ml: line 4: let: =3D: syntax error: operand expected (error token is= "=3D")
./demo.ml: line 5: demo.ml: command not foun= d
./demo.ml: line 6: characters: command not found
./demo.ml: line 7: text: command not found
./demo.ml: line 9: demo.ml: command not foun= d
./demo.ml: line 10: syntax error near unexpected token `('
./demo.ml: line 10: `let html_page (cgi:cgi) title html =3D'


--

On 7/8/06, Christophe TROESTLER <Christophe.Troestler@umh.ac.be> wrote: On Sat, 8 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <christos.jonathan.hayward@gmail.com> wro= te:
>
> I'm trying to figure out how to use CamlGI with OCaml, [..= .]

CamlGI code has been integrated into the Netcgi component
<= https://gps.dynxs.de/wwwsvn/trunk/code/src/netcgi/?root=3Dlib-ocamlnet2= >
of OcamlNet-2 <https://gps.dynxs.de/openapps/svnindex.cgi>, please use
tha= t instead.

> [...] script that [...] prints a webpage saying only "Yes= ", "No",
> "Other" or "Undefined" = depending on whether the CGI variable "foo"
> has value 1, = 0, some other defined value, or is undefined (never
> mind about multiple values)?

You can find examples in the e= xamples/ directory (add.ml is a very
simpl= e one).  As for the specific example you desire, it is attached.<= br>It is maybe a bit more complex that you expected because it
demonstrates additional features (text escaping, setting the header,buffered output).

Hope it helps,
ChriS


open Netcgi
let text =3D Netencoding.Html.encode_from_latin1
  (* Thi= s function encodes "<", ">", "&", d= ouble quotes, and Latin 1
     characters as character entities.  E= .g. text "<" =3D "&lt;", and
  &nbs= p;  text "=E4" =3D "&auml;" *)

(* Norma= lly you would use a template system instead of this *)
let html_page (cgi:cgi) title html =3D
  let out =3D cgi#o= ut_channel#output_string in
  out "<!DOCTYPE html PUBL= IC \"-//W3C//DTD HTML 4.0//EN\" \
    &nbs= p;   \" http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
 = ; out ("<html>\n<head><title>" ^ text titl= e ^"</title></head>
<body>\n");
 &nb= sp;out html;
  out "</body>\n</html>"

let main (c= gi:cgi) =3D
  cgi#set_header
    ~cache= :`No_cache
    ~content_type:"text/html; charse= t=3D\"iso-8859-1\""
    ();
 =  let foo =3D cgi#argument_value "foo"
  let html =3D match foo with
    | &q= uot;1" -> "Yes"
    | "0"= ; -> "No"
    | _ -> "Undefined= " in
  html_page cgi foo html

(* You can buffer or= not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run = by
   another connector entry point (FCGI, SCGI, AJP, Apache m= od). *)
let () =3D
  let buffered _ ch =3D new Netchannels.= buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main
<= br>



--
++ Jonathan Hayw= ard, jonathan.hayward@pobox.c= om
** To see an award-winning website with stories, essays, artwork,
** gam= es, and a four-dimensional maze, why not visit my home page?
** All of t= his is waiting for you at http://Jon= athansCorner.com

** If you'd like a Google Mail (gm= ail.com) account, please tell me! ------=_Part_10263_26416646.1152543722971--