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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 713F2BB83 for ; Sat, 8 Jul 2006 22:48:26 +0200 (CEST) Received: from hedwig1.umh.ac.be (hedwig2.umh.ac.be [193.190.193.73]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k68KmNAU019702 for ; Sat, 8 Jul 2006 22:48:26 +0200 Received: from poincare.swapping.umh.ac.be (pri-010.umh.ac.be [10.101.0.10]) by hedwig1.umh.ac.be (8.13.6/8.13.6) with ESMTP id k68KnrrH385076; Sat, 8 Jul 2006 22:49:53 +0200 Received: from localhost ([127.0.0.1]) by poincare.swapping.umh.ac.be with esmtp (Exim 4.62) (envelope-from ) id 1FzJiX-00078Z-1W; Sat, 08 Jul 2006 22:47:57 +0200 Date: Sat, 08 Jul 2006 22:47:56 +0200 (CEST) Message-Id: <20060708.224756.70330795.Christophe.Troestler@umh.ac.be> To: christos.jonathan.hayward@gmail.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] "Hello web" please From: Christophe TROESTLER In-Reply-To: References: X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: Universite de Mons-Hainaut (http://math.umh.ac.be/an/) X-Spook: BATF chameleon man gamma bootleg Rumsfeld Ft. Meade cypherpunk Mossad JSOFC3IP pink noise X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Operating-System: Debian GNU/Linux (http://www.debian.org/) X-Mailer: Mew version 4.2.52 on Emacs 22.0.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Jul__8_22_47_56_2006_159)--" Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.1 (www dot roaringpenguin dot com slash mimedefang) X-Miltered: at concorde with ID 44B01A17.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 troestler:01 christophe:01 troestler:01 umh:01 ocaml:01 netcgi:01 netcgi:01 ocamlnet-:01 foo:01 escaping:01 buffered:01 netencoding:01 encodes:01 foo:01 X-Attachments: name="hello.ml" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 ----Next_Part(Sat_Jul__8_22_47_56_2006_159)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit On Sat, 8 Jul 2006, "Jonathan Hayward http://JonathansCorner.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 ----Next_Part(Sat_Jul__8_22_47_56_2006_159)-- Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="hello.ml" open Netcgi let text = Netencoding.Html.encode_from_latin1 (* This function encodes "<", ">", "&", double quotes, and Latin 1 characters as character entities. E.g. text "<" = "<", and text "ä" = "ä" *) (* Normally you would use a template system instead of this *) let html_page (cgi:cgi) title html = let out = cgi#out_channel#output_string in out "\n"; out ("\n" ^ text title ^" \n"); out html; out "\n" let main (cgi:cgi) = cgi#set_header ~cache:`No_cache ~content_type:"text/html; charset=\"iso-8859-1\"" (); let foo = cgi#argument_value "foo" let html = 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 () = let buffered _ ch = new Netchannels.buffered_trans_channel ch in Netcgi_cgi.run ~output_type:(`Transactional buffered) main ----Next_Part(Sat_Jul__8_22_47_56_2006_159)----