CVS commit: src/libexec/httpd/lua

2018-05-04 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Fri May  4 19:45:27 UTC 2018

Modified Files:
src/libexec/httpd/lua: glue.c

Log Message:
Do not try and process empty requests. This resolves a crash when issuing a
carriage return to read_request() in foreground mode.
In the C daemon, a NULL check is performed on bozo_read_request in main.c
before moving on to bozo_process_request & bozo_clean_request. Here,
process_request & clean_request just return instead.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/libexec/httpd/lua/glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/lua/glue.c
diff -u src/libexec/httpd/lua/glue.c:1.3 src/libexec/httpd/lua/glue.c:1.4
--- src/libexec/httpd/lua/glue.c:1.3	Tue May  1 23:51:53 2018
+++ src/libexec/httpd/lua/glue.c	Fri May  4 19:45:27 2018
@@ -155,6 +155,9 @@ l_bozo_process_request(lua_State *L)
 	bozo_httpreq_t	*req;
 
 	req = lua_touserdata(L, 1);
+	if (req == NULL) {
+		return 0;
+	}
 	bozo_process_request(req);
 	lua_pushnumber(L, 1);
 	return 1;
@@ -167,6 +170,9 @@ l_bozo_clean_request(lua_State *L)
 	bozo_httpreq_t	*req;
 
 	req = lua_touserdata(L, 1);
+	if (req == NULL) {
+		return 0;
+	}
 	bozo_clean_request(req);
 	lua_pushnumber(L, 1);
 	return 1;



CVS commit: src/libexec/httpd/lua

2018-05-04 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Fri May  4 19:45:27 UTC 2018

Modified Files:
src/libexec/httpd/lua: glue.c

Log Message:
Do not try and process empty requests. This resolves a crash when issuing a
carriage return to read_request() in foreground mode.
In the C daemon, a NULL check is performed on bozo_read_request in main.c
before moving on to bozo_process_request & bozo_clean_request. Here,
process_request & clean_request just return instead.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/libexec/httpd/lua/glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Wed May  2 00:03:27 UTC 2018

Modified Files:
src/libexec/httpd/lua: optparse.lua

Log Message:
Unbreak script for Lua 5.3.
This change breaks support for older releases of Lua.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/libexec/httpd/lua/optparse.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Wed May  2 00:03:27 UTC 2018

Modified Files:
src/libexec/httpd/lua: optparse.lua

Log Message:
Unbreak script for Lua 5.3.
This change breaks support for older releases of Lua.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/libexec/httpd/lua/optparse.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/lua/optparse.lua
diff -u src/libexec/httpd/lua/optparse.lua:1.1.1.1 src/libexec/httpd/lua/optparse.lua:1.2
--- src/libexec/httpd/lua/optparse.lua:1.1.1.1	Mon May 10 03:30:04 2010
+++ src/libexec/httpd/lua/optparse.lua	Wed May  2 00:03:27 2018
@@ -42,7 +42,7 @@ function OptionParser(t)
   end
   function o.parse_args()
 -- expand options (e.g. "--input=file" -> "--input", "file")
-local arg = {unpack(arg)}
+local arg = {table.unpack(arg)}
 for i=#arg,1,-1 do local v = arg[i]
   local flag, val = v:match('^(%-%-%w+)=(.*)')
   if flag then



CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Wed May  2 00:00:30 UTC 2018

Modified Files:
src/libexec/httpd/lua: bozo.lua

Log Message:
Pass the expected httpd instance when calling set_pref()
process_request() only takes a single argument.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/httpd/lua/bozo.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/lua/bozo.lua
diff -u src/libexec/httpd/lua/bozo.lua:1.2 src/libexec/httpd/lua/bozo.lua:1.3
--- src/libexec/httpd/lua/bozo.lua:1.2	Wed Oct 28 09:20:15 2015
+++ src/libexec/httpd/lua/bozo.lua	Wed May  2 00:00:30 2018
@@ -32,7 +32,7 @@
 -- command line args
 dofile "optparse.lua"
 
-opt = OptionParser{usage="%prog [options] root [vhost]", version="20091105"}   
+opt = OptionParser{usage="%prog [options] root [vhost]", version="20180502"}   
 
 opt.add_option{"-C", "--cgimap", action="store", dest="cgimap", help="--cgimap 's t'"}
 opt.add_option{"-E", "--enable-user-cgibin", action="store_true", dest="enableusercgibin", help="--enable-user-cgibin"}
@@ -75,22 +75,22 @@ prefs = bozohttpd.init_prefs()
 -- parse command line args
 options,args = opt.parse_args()
 if options.portnum then
-bozohttpd.set_pref(prefs, "port number", options.portnum)
+bozohttpd.set_pref(httpd, prefs, "port number", options.portnum)
 end
 if options.background then
-bozohttpd.set_pref(prefs, "background", options.background)
+bozohttpd.set_pref(httpd, prefs, "background", options.background)
 end
 if options.numeric then
-bozohttpd.set_pref(prefs, "numeric", "true")
+bozohttpd.set_pref(httpd, prefs, "numeric", "true")
 end
 if options.logstderr then
-bozohttpd.set_pref(prefs, "log to stderr", "true")
+bozohttpd.set_pref(httpd, prefs, "log to stderr", "true")
 end
 if options.foreground then
-bozohttpd.set_pref(prefs, "foreground", "true")
+bozohttpd.set_pref(httpd, prefs, "foreground", "true")
 end
 if options.trustedref then
-bozohttpd.set_pref(prefs, "trusted referal", "true")
+bozohttpd.set_pref(httpd, prefs, "trusted referal", "true")
 end
 if options.dynmime then
 	suffix, type, s1, s2 = string.find(options.dynmime,
@@ -98,29 +98,29 @@ if options.dynmime then
 bozohttpd.dynamic_mime(httpd, suffix, type, s1, s2)
 end
 if options.serversw then
-bozohttpd.set_pref(prefs, "server software", options.serversw)
+bozohttpd.set_pref(httpd, prefs, "server software", options.serversw)
 end
 if options.ssl then
 	cert, priv = string.find(options.ssl, "(%S+)%s+(%S+)")
 bozohttpd.dynamic_mime(httpd, cert, priv)
 end
 if options.username then
-bozohttpd.set_pref(prefs, "username", options.username)
+bozohttpd.set_pref(httpd, prefs, "username", options.username)
 end
 if options.unknownslash then
-bozohttpd.set_pref(prefs, "unknown slash", "true")
+bozohttpd.set_pref(httpd, prefs, "unknown slash", "true")
 end
 if options.virtbase then
-bozohttpd.set_pref(prefs, "virtual base", options.virtbase)
+bozohttpd.set_pref(httpd, prefs, "virtual base", options.virtbase)
 end
 if options.indexhtml then
-bozohttpd.set_pref(prefs, "index.html", options.indexhtml)
+bozohttpd.set_pref(httpd, prefs, "index.html", options.indexhtml)
 end
 if options.dirtyenv then
-bozohttpd.set_pref(prefs, "dirty environment", "true")
+bozohttpd.set_pref(httpd, prefs, "dirty environment", "true")
 end
 if options.bindaddr then
-bozohttpd.set_pref(prefs, "bind address", options.bindaddr)
+bozohttpd.set_pref(httpd, prefs, "bind address", options.bindaddr)
 end
 if options.cgibin then
 bozohttpd.cgi_setbin(httpd, options.cgibin)
@@ -130,22 +130,22 @@ if options.cgimap then
 bozohttpd.cgi_map(httpd, name, handler)
 end
 if options.public_html then
-bozohttpd.set_pref(prefs, "public_html", options.public_html)
+bozohttpd.set_pref(httpd, prefs, "public_html", options.public_html)
 end
 if options.chroot then
-bozohttpd.set_pref(prefs, "chroot dir", options.chroot)
+bozohttpd.set_pref(httpd, prefs, "chroot dir", options.chroot)
 end
 if options.enableusers then
-bozohttpd.set_pref(prefs, "enable users", "true")
+bozohttpd.set_pref(httpd, prefs, "enable users", "true")
 end
 if options.hidedots then
-bozohttpd.set_pref(prefs, "hide dots", "true")
+bozohttpd.set_pref(httpd, prefs, "hide dots", "true")
 end
 if options.enableusercgibin then
-bozohttpd.set_pref(prefs, "enable user cgibin", "true")
+bozohttpd.set_pref(httpd, prefs, "enable user cgibin", "true")
 end
 if options.dirindex then
-bozohttpd.set_pref(prefs, "directory indexing", "true")
+bozohttpd.set_pref(httpd, prefs, "directory indexing", "true")
 

CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Wed May  2 00:00:30 UTC 2018

Modified Files:
src/libexec/httpd/lua: bozo.lua

Log Message:
Pass the expected httpd instance when calling set_pref()
process_request() only takes a single argument.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/httpd/lua/bozo.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue May  1 23:51:53 UTC 2018

Modified Files:
src/libexec/httpd/lua: glue.c

Log Message:
Enable checking arguments for validity.
Remove disabled code.
Fix function parameters.
Add support for Lua 5.3


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/httpd/lua/glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/lua/glue.c
diff -u src/libexec/httpd/lua/glue.c:1.2 src/libexec/httpd/lua/glue.c:1.3
--- src/libexec/httpd/lua/glue.c:1.2	Sun Dec 27 10:21:35 2015
+++ src/libexec/httpd/lua/glue.c	Tue May  1 23:51:53 2018
@@ -38,6 +38,7 @@
 #include 
 
 #define LUA_LIB
+#define LUA_USE_APICHECK
 #include 
 #include 
 #include 
@@ -48,24 +49,6 @@
 
 int luaopen_bozohttpd(lua_State *);
 
-#if 0
-typedef struct strarg_t {
-	const char	*s;	/* string */
-	const int	 n;	/* corresponding int value */
-} strarg_t;
-
-/* map a string onto an int */
-static int
-findtype(strarg_t *strs, const char *s)
-{
-	strarg_t	*sp;
-
-	for (sp = strs ; sp->s && strcasecmp(sp->s, s) != 0 ; sp++) {
-	}
-	return sp->n;
-}
-#endif
-
 /* init() */
 static int
 l_new(lua_State *L)
@@ -102,18 +85,20 @@ l_init_prefs(lua_State *L)
 	return 1;
 }
 
-/* bozo_set_pref(prefs, name, value) */
+/* bozo_set_pref(httpd, prefs, name, value) */
 static int
 l_bozo_set_pref(lua_State *L)
 {
+	bozohttpd_t	*httpd;
 	bozoprefs_t	*prefs;
 	const char	*name;
 	const char	*value;
 
-	prefs = lua_touserdata(L, 1);
-	name = luaL_checkstring(L, 2);
-	value = luaL_checkstring(L, 3);
-	lua_pushnumber(L, bozo_set_pref(prefs, name, value));
+	httpd = lua_touserdata(L, 1);
+	prefs = lua_touserdata(L, 2);
+	name = luaL_checkstring(L, 3);
+	value = luaL_checkstring(L, 4);
+	lua_pushnumber(L, bozo_set_pref(httpd, prefs, name, value));
 	return 1;
 }
 
@@ -163,16 +148,14 @@ l_bozo_read_request(lua_State *L)
 	return 1;
 }
 
-/* bozo_process_request(httpd, req) */
+/* bozo_process_request(req) */
 static int
 l_bozo_process_request(lua_State *L)
 {
 	bozo_httpreq_t	*req;
-	bozohttpd_t	*httpd;
 
-	httpd = lua_touserdata(L, 1);
-	req = lua_touserdata(L, 2);
-	bozo_process_request(httpd, req);
+	req = lua_touserdata(L, 1);
+	bozo_process_request(req);
 	lua_pushnumber(L, 1);
 	return 1;
 }
@@ -250,7 +233,7 @@ l_bozo_cgi_map(lua_State *L)
 	return 1;
 }
 
-const struct luaL_reg libluabozohttpd[] = {
+const struct luaL_Reg libluabozohttpd[] = {
 	{ "new",		l_new },
 	{ "init_httpd",		l_init_httpd },
 	{ "init_prefs",		l_init_prefs },
@@ -273,6 +256,10 @@ const struct luaL_reg libluabozohttpd[] 
 int 
 luaopen_bozohttpd(lua_State *L)
 {
-	luaL_openlib(L, "bozohttpd", libluabozohttpd, 0);
+#if LUA_VERSION_NUM >= 502
+luaL_newlib(L, libluabozohttpd);
+#else
+luaL_register(L, "bozohttpd", libluabozohttpd); 
+#endif
 	return 1;
 }



CVS commit: src/libexec/httpd/lua

2018-05-01 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue May  1 23:51:53 UTC 2018

Modified Files:
src/libexec/httpd/lua: glue.c

Log Message:
Enable checking arguments for validity.
Remove disabled code.
Fix function parameters.
Add support for Lua 5.3


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/httpd/lua/glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.