# HG changeset patch # User jlarmour # Date 1195051153 0 # Node ID 4631139fc77477dd7d3b3b5398f9d7e0aa9433a5 # Parent a3ced1fc2e8969a950dd22769ff957dba32a8cb3 * 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 diff --git a/packages/net/athttpd/current/ChangeLog b/packages/net/athttpd/current/ChangeLog --- a/packages/net/athttpd/current/ChangeLog +++ b/packages/net/athttpd/current/ChangeLog @@ -1,8 +1,15 @@ 2007-11-12 Oyvind Harboe +2007-11-12 Jonathan Larmour + * 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 diff --git a/packages/net/athttpd/current/doc/athttpd.sgml b/packages/net/athttpd/current/doc/athttpd.sgml --- a/packages/net/athttpd/current/doc/athttpd.sgml +++ b/packages/net/athttpd/current/doc/athttpd.sgml @@ -1,3 +1,4 @@ + @@ -8,7 +9,7 @@ - + @@ -362,6 +363,41 @@ we can use: start_chunked "html"; end_chunked; No parameters. Send back an end of frame to the client. + + +tcl hello world example + +The following example demonstrates how to send a log file in the file +/ram/log to a web client. It replaces +newline characters with <br> so that it is formatted on the +browser correctly. + +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; + + + +The above file should exist on a filesystem +on the embedded target within its cgi-bin +directory, for example as /cgi-bin/hello.tcl. Thereafter +it may be accessed at the URL +http://TARGET_NAME/cgi-bin/hello.tcl. + + diff --git a/packages/net/athttpd/current/src/forms.c b/packages/net/athttpd/current/src/forms.c --- 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); diff --git a/packages/net/athttpd/current/src/http.c b/packages/net/athttpd/current/src/http.c --- 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);