From 369b505bc0aed841c8e7452f2be09a95900885db Mon Sep 17 00:00:00 2001 From: asterix Date: Fri, 30 Sep 2011 16:25:52 +0000 Subject: [PATCH] Add comments.bertos/net/http.c git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5127 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/http.h | 11 +++---- .../examples/sam3x-ek_http_server/main.c | 29 +++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/bertos/net/http.h b/bertos/net/http.h index 49701295..53d8100d 100644 --- a/bertos/net/http.h +++ b/bertos/net/http.h @@ -56,14 +56,15 @@ typedef int (*http_handler_t)(struct netconn *client, const char *name, char *re typedef struct HttpCGI { - unsigned type; - const char *name; - http_handler_t handler; + unsigned type; ///< Strategy to find string in the cgi table. + const char *name; ///< Request string from GET request + http_handler_t handler; ///< Callback to process the special request } HttpCGI; + #define CGI_MATCH_NONE 0 -#define CGI_MATCH_NAME 1 -#define CGI_MATCH_EXT 2 +#define CGI_MATCH_NAME 1 ///< Select item in table only if string match +#define CGI_MATCH_EXT 2 ///< Select item in table if the extention match void http_sendOk(struct netconn *client); void http_sendFileNotFound(struct netconn *client); diff --git a/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c b/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c index ddb361de..c3a1a4b1 100644 --- a/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c +++ b/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c @@ -37,8 +37,7 @@ * * This simple web server read the site's pages from SD card, and manage * the cases where SD is not present or page not found, using embedded pages. - * Quering from browser the /status page, the server return a json dictionary where are store - * some board status info, like board temperature, up-time, etc. + * Quering from browser some cgi page, the server return a json dictionary. */ @@ -140,6 +139,7 @@ static NORETURN void status_process(void) } } +/* Macro to unpack the ip addres from lwip format */ #define IP_ADDR_TO_INT_TUPLE(addr) \ (int)((addr) >> 0 & 0xff), \ (int)((addr) >> 8 & 0xff), \ @@ -149,6 +149,9 @@ static NORETURN void status_process(void) static uint8_t tx_buf[2048]; +/* + * Return a JSON string of board status. + */ static int cgi_status(struct netconn *client, const char *name, char *revc_buf, size_t revc_len) { (void)revc_buf; @@ -180,6 +183,9 @@ static int cgi_logo(struct netconn *client, const char *name, char *revc_buf, si return 0; } +/* + * Return the internal micro temperature string. + */ static int cgi_temp(struct netconn *client, const char *name, char *revc_buf, size_t revc_len) { (void)revc_buf; @@ -193,6 +199,9 @@ static int cgi_temp(struct netconn *client, const char *name, char *revc_buf, si return 0; } +/* + * Reply to client the request string. + */ static int cgi_echo(struct netconn *client, const char *name, char *revc_buf, size_t revc_len) { (void)name; @@ -202,6 +211,15 @@ static int cgi_echo(struct netconn *client, const char *name, char *revc_buf, si return 0; } + +/* + * Default function that http server call every client request, if it doesn't match a cgi table. + * In this implementation all client request are associate to real file stored on FAT file + * sistem on SD card. If the file there is not on SD card the server reply to client the + * error File not found, and send an harcoded page. In the same way, the server reply + * error page if the SD card is not present. + * + */ static int http_htmPageLoad(struct netconn *client, const char *name, char *revc_buf, size_t revc_len) { (void)revc_buf; @@ -271,6 +289,10 @@ static int http_htmPageLoad(struct netconn *client, const char *name, char *revc return 0; } +/* + * Return to client a string that display the CHIP ID information. + * See datasheet for more detail. + */ static int cgi_chipInfo(struct netconn *client, const char *name, char *revc_buf, size_t revc_len) { (void)revc_buf; @@ -300,6 +322,9 @@ static int cgi_error(struct netconn *client, const char *name, char *revc_buf, s return -1; } +/* + * Static cgi table where we associate callback to page. + */ static HttpCGI cgi_table[] = { { CGI_MATCH_NAME, "echo", cgi_echo }, -- 2.25.1