Altera_Forum
Honored Contributor
22 years agoModified web server that parses server-side text
This is a modified edition of the "web_server" example included with Nios II. It runs on MicroC/OS-II and the sockets-based LWIP stack. The attached files merely replace the provided http.c/http.h files found in the web_server example. The difference between original Altera-provided web server example and this are explicitly commented.
The idea is that you get a "pseudo" server-side include that more full-featured web servers offer. The chief limitation is that the text being replaced must match length with the token that is searched for; this allows the server to operate in a more efficient manner as it sends out the HTTP "content length" based on the file length from the file system. It also allows the server to send 'chunks' of a file without first checking to see if a token is present in the file; if a token is detected in a 'chunk' that is to be sent, the text is replaced. If necessary more of the file is read if the token is not completely read at the end of the file 'chunk'. This code has the additional feature of parsing strings embedded statically into HTML content and replacing them with text... in this case, the system IP/MAC address, etc. A string of "%macaddr123456789" embedded in the HTML would be replaced with a MAC address, such as "00:11:22:33:44:55". The code does the same for IP addresses, but since IP addresses (printed in decimal) can vary in length the code "pads" the new HTML with space characters. You can easily modify this example to print out something other than network settings at runtime in your application. The only restriction is that the string length of what you're displaying must be constant. No warranty expresed or implied, not an official Altera product; no support is offered on this modified example.