From babdc61a7bd46eb4d84bbff89b077aa20665742d Mon Sep 17 00:00:00 2001 From: sevan Date: Tue, 1 May 2018 23:51:53 +0000 Subject: [PATCH] Enable checking arguments for validity. Remove disabled code. Fix function parameters. Add support for Lua 5.3 --- libexec/httpd/lua/glue.c | 47 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/libexec/httpd/lua/glue.c b/libexec/httpd/lua/glue.c index f0fd240775b0..9752eb622077 100644 --- a/libexec/httpd/lua/glue.c +++ b/libexec/httpd/lua/glue.c @@ -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; }