UHTTPD is a lightweight server with the default integration of the OPENWRT system, with the select mechanism having low performance requirements.
/usr/sbin/uhttpd-f-h/www-r wifibox-x/cgi-bin-l/slipt-l/usr/share/lua/wifibox/main.lua-t 60-t 30-k 20-a 1-n 3-n 100-r-P 0.0.0.0 80
This is a class of intelligent router uhttpd operating parameters, where-h specifies the root of the Web site, static file requests will be in this directory as the root directory,-l specifies the invoked LUA master handler,-x specifies the CGI run program, the source file running parameters are described below, Accessories for UTTTPD Full source
"Usage: %s -p [addr:]port [-h docroot]\n" "-f do not fork to background\n ""-c file Configuration file, default is '/etc /httpd.conf ' \ n ' "-p [addr:]port bind to specified address and port, multiple allowed\n "#ifdef  HAVE_TLS"-s [addr:]port like -p but Provide https on this port\n ""-c file asn.1 server certificate file\n ""-k file asn.1 server private key file\n "#endif"-h directory Specify the document root, default is '. ' \ n ""-e string use given virtual url as 404 error handler\n ""-I string Use given filename as index page for Directories\n ""-s do Not follow symbolic links outside of the docroot\n ""-D Do not allow directory listings, send 403 instead\n ""-r enable rfc1918 filter\n "#ifdef have_lua"-l string URL prefix for Lua handler, default is '/lua ' \ n ""-l file lua handler script, omit to disable lua\n "#endif#ifdef have_cgi "-x string url prefix for CGI handler, default is '/cgi-bin ' \ n ' "-i .ext=path use interpreter at path for files with the given extension\n "#endif # if defined (have_cgi) | | defined (Have_lua) "-t seconds cgi and lua script timeout in seconds, default is 60\n "#endif"-t seconds network timeout in seconds, default is 30\n ""-d string url decode given string\n ""-r string specify basic auth realm\n ""-m string md5 crypt given string\n "
Requests received by the UHTTPD server are divided into three categories, static file requests, CGI requests (processing form information), and LUA requests (powerful implementation of multi-function processing and invocation) based on request headers
The first is the LUA request, the UHTTPD server is written in C, the C language calls LUA program implementation, LUA requests the processing of related programs, the C language and the Lua language through the stack to transfer data, the following is a simple C language call LUA program instance
Add.c#include <stdio.h> #include "Lua.h" #include "Lualib.h" #include "Lauxlib.h"/*the lua interpreter*/lua_state* l; Intluaadd (int x, int y) { int sum;/*the function name*/ lua_getglobal (L, "add");/*the First argument*/ lua_pushnumber (L, x);/*the Second argument*/ lua_pushnumber (L, y);/*call the function with 2 arguments, return 1 result.*/ lua_call (l, 2, 1);/*get the result.*/ sum = (int) lua_tonumber (l, -1);/*cleanup the return*/ lua_pop (l,1); return sum;} Intmain (int argc, char *argv[]) { int sum;/* Initialize lua*/ l = lua_open ();/*load Lua base libraries*/ lual_openlibs (L);/*load the script*/ lual_dofile (l, "Add.lua");/*call the add function*/ sum = luaadd (10,&NBSP;15); *print the result*/ printf ("The sum is %d \n ", sum);/*cleanup lua*/ lua_close (L); return 0;}
Add.lua--add numbersfunction Add (x, y) return x + yend
UHTTPD schema invoke details Lua