* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef _DEFAULT_SOURCE
+# define _DEFAULT_SOURCE
+#endif
+
#define _BSD_SOURCE
#define _GNU_SOURCE
#define _XOPEN_SOURCE 700
#include <signal.h>
#include <libubox/usock.h>
+#include <libubox/utils.h>
#include "uhttpd.h"
#include "tls.h"
" -t seconds CGI, Lua and UBUS script timeout in seconds, default is 60\n"
" -T seconds Network timeout in seconds, default is 30\n"
" -k seconds HTTP keepalive timeout\n"
+ " -A seconds TCP keepalive timeout, default is unset\n"
" -d string URL decode given string\n"
" -r string Specify basic auth realm\n"
" -m string MD5 crypt given string\n"
conf.cgi_prefix = "/cgi-bin";
conf.cgi_path = "/sbin:/usr/sbin:/bin:/usr/bin";
INIT_LIST_HEAD(&conf.cgi_alias);
+ INIT_LIST_HEAD(&conf.lua_prefix);
}
static void init_defaults_post(void)
str[len + 1] = 0;
}
+#ifdef HAVE_LUA
+static void add_lua_prefix(const char *prefix, const char *handler) {
+ struct lua_prefix *p;
+ char *pprefix, *phandler;
+
+ p = calloc_a(sizeof(*p),
+ &pprefix, strlen(prefix) + 1,
+ &phandler, strlen(handler) + 1);
+
+ if (!p)
+ return;
+
+ p->prefix = strcpy(pprefix, prefix);
+ p->handler = strcpy(phandler, handler);
+
+ list_add_tail(&p->list, &conf.lua_prefix);
+}
+#endif
+
int main(int argc, char **argv)
{
struct alias *alias;
int n_tls = 0;
const char *tls_key = NULL, *tls_crt = NULL;
#endif
+#ifdef HAVE_LUA
+ const char *lua_prefix = NULL, *lua_handler = NULL;
+#endif
BUILD_BUG_ON(sizeof(uh_buf) < PATH_MAX);
init_defaults_pre();
signal(SIGPIPE, SIG_IGN);
- while ((ch = getopt(argc, argv, "A:aC:c:Dd:E:fh:I:i:K:k:L:l:m:N:n:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
+ while ((ch = getopt(argc, argv, "A:aC:c:Dd:E:fh:H:I:i:K:k:L:l:m:N:n:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
switch(ch) {
#ifdef HAVE_TLS
case 'C':
conf.docroot = strdup(uh_buf);
break;
+ case 'H':
+ if (uh_handler_add(optarg)) {
+ fprintf(stderr, "Error: Failed to load handler script %s\n",
+ optarg);
+ exit(1);
+ }
+ break;
+
case 'E':
if (optarg[0] != '/') {
fprintf(stderr, "Error: Invalid error handler: %s\n",
#ifdef HAVE_LUA
case 'l':
- conf.lua_prefix = optarg;
- break;
-
case 'L':
- conf.lua_handler = optarg;
+ if (ch == 'l') {
+ if (lua_prefix)
+ fprintf(stderr, "uhttpd: Ignoring previous -%c %s\n",
+ ch, lua_prefix);
+
+ lua_prefix = optarg;
+ }
+ else {
+ if (lua_handler)
+ fprintf(stderr, "uhttpd: Ignoring previous -%c %s\n",
+ ch, lua_handler);
+
+ lua_handler = optarg;
+ }
+
+ if (lua_prefix && lua_handler) {
+ add_lua_prefix(lua_prefix, lua_handler);
+ lua_prefix = NULL;
+ lua_handler = NULL;
+ }
+
break;
#else
case 'l':
#endif
#ifdef HAVE_LUA
- if (conf.lua_handler || conf.lua_prefix) {
- if (!conf.lua_handler || !conf.lua_prefix) {
- fprintf(stderr, "Need handler and prefix to enable Lua support\n");
- return 1;
- }
- if (uh_plugin_init("uhttpd_lua.so"))
- return 1;
+ if (lua_handler || lua_prefix) {
+ fprintf(stderr, "Need handler and prefix to enable Lua support\n");
+ return 1;
}
+
+ if (!list_empty(&conf.lua_prefix) && uh_plugin_init("uhttpd_lua.so"))
+ return 1;
#endif
#ifdef HAVE_UBUS
if (conf.ubus_prefix && uh_plugin_init("uhttpd_ubus.so"))