WEB Server

tcpip_layer4

Internet Protocol Suite

uIP contains WEB Server sample application in apps/webserver. The Application Layer for this implementation uses that one.

WEB Server Processing Flow

WEB Server application handles HTTP(HyperText Transfer Protocol). The server accepts HTTP request message and returns response message. When the server finds GET method in a request message, HTML file name is set and the server seeks internal file system. If the file exists, the server returns HTML as a response.

HTTP processing flow is handled in UIP_APP_CALL().(httpd_appcall is defined as UIP_APP_CALL in webserver.h)

ether_pic6

HTTP Processing Flow Chart

HTML Preparation

Web Server example application also contains “makefsdata” perl script. This script converts HTML files in http-fs sub directory into unsigned char arrays as a file named “httpd-fsdata.c”. httpd-fsdata.c is compiled with other source codes, and HTML files are stored as a part of the final executable object.

CGI Modification and Addition

When the file extension requested by GET method is .shtml, handle_script() is called and starts CGI processing. If “%!” is in the .shtml file, the CGI function based on the string followed by “%!” is executed. After the execution, HTML strings are generated and returned as the response message.

A few CGI samples and predefined macros are available in apps/webserver/httpd-cgi.c. These are good examples to add new CGIs.The following shows an example to add new CGI.
Example: Add CGI “cpu-stats” for displaying CPU clock configuration
1.CGI name definition to be written in shtml
New CGI is added by predefined macro “HTTPD_CGI_CALL”. In this case, new CGI named cpu-stats is added.

2. Modify *calls[] array
Add cpu in *calls[] array.

3. Add protothread for new CGI
Add new protothread named cpu_stats by using protosocket library. protothread is light-weight, stackless thread, and protosocket library is a socket interface provided by uIP.

4.Add string generation function
Add new function named generate_cpu_stats. The function generates HTML strings and stores them into uip_appdata global variable. The function returns the length of strings stored in uip_appdata.


スポンサーリンク







  • このエントリーをはてなブックマークに追加
スポンサーリンク