//* Web server acting as a gateway to connected embedded system *

#include "tnplib.h" #include <iostream> #include <cstdio> #include <cstring> using namespace std; inline void D(const char *errormessage) { #ifdef _DEBUG cerr << errormessage << endl; #endif } const char index_html[]= { // 0x000 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, 0x68, 0x74, 0x6d, 0x6c, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, 0x2f, 0x44, 0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x34, 0x2e, 0x30, 0x31, 0x2f, 0x2f, 0x45, 0x4e, 0x22, 0x3e, 0x0a, // 0x033 <!-- Copyright Dr. Aleksander Malinowski --> 0x3c, 0x21, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x44, 0x72, 0x2e, 0x20, 0x41, 0x6c, 0x65, 0x6b, 0x73, 0x61, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x4d, 0x61, 0x6c, 0x69, 0x6e, 0x6f, 0x77, 0x73, 0x6b, 0x69, 0x20, 0x2d, 0x2d, 0x3e, 0x0a, // 0x060 <html> 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0a, // 0x067 <head><title>eTCP Embedded Gateway Example</title><head> 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x65, 0x54, 0x43, 0x50, 0x20, 0x45, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x20, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0a, // 0x0a0 <body> 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0a, // 0x0a7 <h1>eTCP Embedded Gateway Example</h1> 0x3c, 0x68, 0x31, 0x3e, 0x65, 0x54, 0x43, 0x50, 0x20, 0x45, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x20, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3c, 0x2f, 0x68, 0x31, 0x3e, 0x0a, // 0x0ce <form method="get" action=""> 0x3c, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3d, 0x22, 0x67, 0x65, 0x74, 0x22, 0x20, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x22, 0x3e, 0x0a, // 0x0ed <!-- "" will call the same Web page again with parameters after ? --> 0x20, 0x20, 0x20, 0x20, 0x3c, 0x21, 0x2d, 0x2d, 0x20, 0x22, 0x22, 0x20, 0x77, 0x69, 0x6c, 0x6c, 0x20, 0x63, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x61, 0x6d, 0x65, 0x20, 0x57, 0x65, 0x62, 0x20, 0x70, 0x61, 0x67, 0x65, 0x20, 0x61, 0x67, 0x61, 0x69, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x3f, 0x20, 0x2d, 0x2d, 0x3e, 0x0a, // 0x137 <input type="text" name="t" value="" /> 0x20, 0x20, 0x20, 0x20, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x74, 0x65, 0x78, 0x74, 0x22, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x74, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x22, 0x20, 0x2f, 0x3e, 0x0a, // 0x165 <input type="submit" name="s" value="TXT" /> 0x20, 0x20, 0x20, 0x20, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x54, 0x58, 0x54, 0x22, 0x20, 0x2f, 0x3e, 0x0a, // 0x196 <table> 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x3e, 0x0a, // 0x1a2 <tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x72, 0x3e, 0x0a, // 0x1af <td><input type="submit" name="s" value="B01" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x31, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x1f1 <td><input type="submit" name="s" value="B02" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x32, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x233 <td><input type="submit" name="s" value="B03" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x33, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x275 <td><input type="submit" name="s" value="B04" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x34, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x2b7 </tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0x0a, // 0x2c5 <tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x72, 0x3e, 0x0a, // 0x2d2 <td><input type="submit" name="s" value="B05" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x35, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x314 <td><input type="submit" name="s" value="B06" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x36, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x356 <td><input type="submit" name="s" value="B07" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x37, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x398 <td><input type="submit" name="s" value="B08" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x38, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x3da </tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0x0a, // 0x3e8 <tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x72, 0x3e, 0x0a, // 0x3f5 <td><input type="submit" name="s" value="B09" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x30, 0x39, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x437 <td><input type="submit" name="s" value="B10" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x30, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x479 <td><input type="submit" name="s" value="B11" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x31, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x4bb <td><input type="submit" name="s" value="B12" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x32, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x4fd </tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0x0a, // 0x50b <tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x72, 0x3e, 0x0a, // 0x518 <td><input type="submit" name="s" value="B13" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x33, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x55a <td><input type="submit" name="s" value="B14" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x34, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x59c <td><input type="submit" name="s" value="B15" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x35, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x5de <td><input type="submit" name="s" value="B16" /></td> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x64, 0x3e, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x22, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x73, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x42, 0x31, 0x36, 0x22, 0x20, 0x2f, 0x3e, 0x3c, 0x2f, 0x74, 0x64, 0x3e, 0x0a, // 0x620 </tr> 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0x0a, // 0x62e </table> 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x3e, 0x0a, // 0x63b 0x0a, // 0x63c </form> 0x3c, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, 0x0a, // 0x644 </body> 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0a, // 0x64c </html> 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0a, 0x00, }; void ParseURL(const char * buffer, char * method, char * localurl, char * params) { const char * s; int j; method[0]='\0'; localurl[0]='\0'; params[0]='\0'; s=buffer; j=0; while (*s!=' ' && j<15) { method[j]=*s; ++s; ++j; } method[j]='\0'; if (*s!=' ') { method[0]='\0'; return; } ++s; if (strncmp( s, "http://", 7)==0) { s=s+7; while (*s!='\0' && *s!='/') ++s; if (*s!='/') return; } j=0; while (*s!='\0' && *s!=' ' && *s!='?') { localurl[j]=*s; ++s; ++j; } localurl[j]='\0'; if (*s=='?') { ++s; j=0; while (*s!='\0' && *s!=' ') { params[j]=*s; ++s; ++j; } params[j]='\0'; } } void ParseParameter(const char * buffer, char * paramname, char * paramvalue) { // Note: this is incomplete as it does not decode %dd back into singe characters, + into singe spape, etc. const char * s; unsigned int plen = strlen(paramname); // parameter name length unsigned int pcnt = 0; // paramter value length paramvalue[0]='\0'; s=buffer; while ( true ) { s = strstr(s, paramname); if ( s==NULL ) break; // not found if ( *(s+plen) == '=' ) break; // parameter found with the exact name else ++s; // it was close name but search again } if ( s!= NULL) { s = s+plen+1; while ( *s!='\0' && *s!='&') { // search for the end of the parameter (or end of buffer) paramvalue[pcnt]=*s; // copy while searching ++s; ++pcnt; } paramvalue[pcnt]='\0'; // terminate the string } } void SimpleHTTPServer(int port) { char buffer[65536]; char method[16]; char localurl[128]; char params[256]; char value[16]; int status; SOCKET serve = TCPStartServer(port, 2, 1); for (;;) { SOCKET visitor = TCPWaitForConnection(serve); status = TCPRecvLine(visitor, buffer, sizeof(buffer) ); if (status<0) continue; D(buffer); ParseURL(buffer, method, localurl, params); do { status = TCPRecvDumpLine(visitor); } while (status>0); if ( params[0]!='\0' ) { // if parameters string is non-empty // Process submitted form D("Process form submission"); ParseParameter(params, "s", value); if (strcmp(value,"TXT")==0 ) { D("Process text data:"); ParseParameter(params, "t", value); D(value); // this is the place to act in an embedded system // or to send a command to an embedded system from a gateway computer server // Remove this feature below in a real application if ( strcmp(value,"QUIT%21") == 0 ) { // Note %21 is encoded '!' D("TERMINATE the server gracefully"); break; } } else { D("Process button:"); D(value); // this is the place to act in an embedded system // or to send a command to an embedded system from a gateway computer server } } // Render a new form TCPSendLine(visitor, "HTTP/1.0 200 ok\nContent-type: text/html; charset=UTF-8\n\n"); TCPSendLine(visitor, index_html); D("Page sent"); TCPPrepClose(visitor); TCPStopClient(visitor); D("Done"); } } int main() { SocketLibStart(); SimpleHTTPServer(8088); SocketLibEnd(); return(0); }