Mercurial > ecos
changeset 2449:4631139fc774
* doc/athttpd.sgml: added an example of a tcl script.
* src/http.c, forms.c: serve cgi requests before file system requests,
that way it isn't possible to download the actual cgi/.o script and
cgi works even if the http root directory is above the cgi directory.
* src/http.c: if only tcl cgi is enabled, cgi requests are now
forwarded to tcl
| author | jlarmour |
|---|---|
| date | Wed, 14 Nov 2007 14:39:13 +0000 |
| parents | a3ced1fc2e89 |
| children | 0f68ebea87e6 |
| files | packages/net/athttpd/current/ChangeLog packages/net/athttpd/current/doc/athttpd.sgml packages/net/athttpd/current/src/forms.c packages/net/athttpd/current/src/http.c |
| diffstat | 4 files changed, 68 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/net/athttpd/current/ChangeLog +++ b/packages/net/athttpd/current/ChangeLog @@ -1,8 +1,15 @@ 2007-11-12 Oyvind Harboe <oyvind.harboe@zylin.com> +2007-11-12 Jonathan Larmour <jifl@eCosCentric.com> + * doc/athttpd.sgml: added an example of a tcl script. + * src/http.c, forms.c: serve cgi requests before file system requests, + that way it isn't possible to download the actual cgi/.o script and + cgi works even if the http root directory is above the cgi directory. + * src/http.c: if only tcl cgi is enabled, cgi requests are now + forwarded to tcl * include/jim.h: include file order fix; now compiles again. - * doc/athttpd.cdl: Fixed typos in doc. Return value from handler is not - used, recommend returning 0 in doc. + * doc/athttpd.sgml: Fixed typos in doc. Return value from handler is + not used, recommend returning 0 in doc. 2006-12-03 Anthony Tonizzo <atonizzo@gmail.com>
--- a/packages/net/athttpd/current/doc/athttpd.sgml +++ b/packages/net/athttpd/current/doc/athttpd.sgml @@ -1,3 +1,4 @@ +<!-- DOCTYPE part PUBLIC "-//OASIS//DTD DocBook V3.1//EN" --> <!-- =============================================================== --> <!-- --> <!-- athttpd.sgml --> @@ -8,7 +9,7 @@ <!-- ####COPYRIGHTBEGIN#### --> <!-- --> <!-- =============================================================== --> -<!-- Copyright (C) 2003, 2004 eCosCentric Ltd. --> +<!-- Copyright (C) 2003, 2004, 2007 eCosCentric Ltd. --> <!-- This material may be distributed only subject to the terms --> <!-- and conditions set forth in the Open Publication License, v1.0 --> <!-- or later (the latest version is presently available at --> @@ -362,6 +363,41 @@ we can use: start_chunked "html"; <programlisting width=72>end_chunked;</programlisting> <para>No parameters. Send back an end of frame to the client.</para> </sect3> + +<sect3 id="athttpd-tcl-hello-world"> +<title>tcl hello world example</title> +<para> +The following example demonstrates how to send a log file in the file +<filename>/ram/log</filename> to a web client. It replaces +newline characters with <literal><br></literal> so that it is formatted on the +browser correctly. +<programlisting width=72> +start_chunked "html"; + +set fp [aio.open "/ram/log" r]; +$fp seek 0 end; +set fsize [$fp tell]; +$fp seek 0 start; +set data "abcxxx"; +set data [$fp read $fsize]; +$fp close; +set data [string map {\n <br>} $data]; + +set datax ""; +append datax "<html><body>" $data "</body></html>"; + +write_chunked $datax; +end_chunked; +</programlisting> +</para> +<para> +The above file should exist on a filesystem +on the embedded target within its <filename class=directory>cgi-bin</filename> +directory, for example as <filename>/cgi-bin/hello.tcl</filename>. Thereafter +it may be accessed at the URL +<literal>http://<replaceable>TARGET_NAME</replaceable>/cgi-bin/hello.tcl</literal>. +</para> +</sect3> </sect2> </sect1>
--- a/packages/net/athttpd/current/src/forms.c +++ b/packages/net/athttpd/current/src/forms.c @@ -252,16 +252,6 @@ cyg_httpd_handle_method_POST(void) if (httpstate.mode & CYG_HTTPD_MODE_FORM_DATA) cyg_httpd_store_form_data(httpstate.post_data); - handler h = cyg_httpd_find_handler(); - if (h != 0) - { - // A handler was found. We'll call the function associated to it. - h(&httpstate); - free(httpstate.post_data); - httpstate.post_data = NULL; - return; - } - #if defined(CYGOPT_NET_ATHTTPD_USE_CGIBIN_OBJLOADER) || \ defined(CYGOPT_NET_ATHTTPD_USE_CGIBIN_TCL) // See if we are trying to execute a CGI via one of the supported methods. @@ -282,6 +272,17 @@ cyg_httpd_handle_method_POST(void) return; } #endif + + handler h = cyg_httpd_find_handler(); + if (h != 0) + { + // A handler was found. We'll call the function associated to it. + h(&httpstate); + free(httpstate.post_data); + httpstate.post_data = NULL; + return; + } + // No handler of any kind for a post request. Must send 404. cyg_httpd_send_error(CYG_HTTPD_STATUS_NOT_FOUND);
--- a/packages/net/athttpd/current/src/http.c +++ b/packages/net/athttpd/current/src/http.c @@ -9,7 +9,7 @@ * ------------------------------------------- * This file is part of eCos, the Embedded Configurable Operating * System. - * Copyright (C) 2005 eCosCentric Ltd. + * Copyright (C) 2005, 2007 eCosCentric Ltd. * * eCos is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -708,15 +708,7 @@ cyg_httpd_format_header(void) void cyg_httpd_handle_method_GET(void) { - // Use defined handlers take precedence over other forms of response. - handler h = cyg_httpd_find_handler(); - if (h != 0) - { - h(&httpstate); - return; - } - -#ifdef CYGOPT_NET_ATHTTPD_USE_CGIBIN_OBJLOADER +#if defined(CYGOPT_NET_ATHTTPD_USE_CGIBIN_OBJLOADER) || defined(CYGOPT_NET_ATHTTPD_USE_CGIBIN_TCL) // If the URL is a CGI script, there is a different directory... if (httpstate.url[0] == '/' && !strncmp(httpstate.url + 1, @@ -730,6 +722,15 @@ cyg_httpd_handle_method_GET(void) // will likely generate a 404. #endif + // Use defined handlers take precedence over other forms of response. + handler h = cyg_httpd_find_handler(); + if (h != 0) + { + h(&httpstate); + return; + } + + #ifdef CYGOPT_NET_ATHTTPD_USE_FS // No handler, we'll redirect to the file system. cyg_httpd_send_file(httpstate.url);
