Home |
Server Side Includes (CGI) |
Server Side Includes (CGI)Keywords can be included in a web page such that when the web page is requested, it will cause the Web server to execute a user-supplied function specified on the web page. The called function can send data directly to the browser as part of the requested document. This allows the inclusion of realtime data directly into a loading HTML document. Server Side Includes are implemented in the Web server via one or more user-supplied tables of names and function pointers which reference callback functions of type struct get_function_entry. Such tables can be passed to the Web server at program initialization through function http_add_get_functions. Example:static struct get_function_entry my_get_functions[] = { {"cgi_demo.fn", cgi_demo }, {"cgi_demo2.c", cgi_demo2 }, {"push_demo.fn", push_demo }, {"", END_OF_TABLE} }; ... http_add_get_functions(my_get_functions); When the Web server encounters a reference to a CGI function call in an .htm, .html, or .shtml file, or a file specified through function http_ssi_files, such as: <!--#exec cgi="/cgi_demo.fn"--> it will scan the table for the given CGI function name. In this example, "cgi_demo.fn" is the first entry and the corresponding user supplied C/C++ function cgi_demo() is called. Function cgi_demo() can then send arbitrary HTML data to the browser using function xn_line_put. Instead of the CGI comment, the browser will receive whatever the cgi_demo() callback has sent it. Functions listed in a get_function_entry array can also be invoked directly from an URL. In this case, the function must supply all data expected by the Web browser, including the HTTP header. Example:// first, send the MIME header followed by an empty line Send(io_context, "HTTP/1.1 200 Document follows\r\n" "Content-Type: text/html\r\n" "\r\n", PUT_QUE); Send(io_context, "<html><head>" ... Please note that GET function handlers are executed in the context of the Web server thread which does not maintain a floating point context. If the handler contains floating point calculations, it must first call function RTKProtect8087. See demo program WebServer for several complete CGI examples.
|