Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/httpd/lua Enable checking arguments for...



details:   https://anonhg.NetBSD.org/src/rev/652cd6dff1d0
branches:  trunk
changeset: 318634:652cd6dff1d0
user:      sevan <sevan%NetBSD.org@localhost>
date:      Tue May 01 23:51:53 2018 +0000
description:
Enable checking arguments for validity.
Remove disabled code.
Fix function parameters.
Add support for Lua 5.3

diffstat:

 libexec/httpd/lua/glue.c |  47 +++++++++++++++++------------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)

diffs (103 lines):

diff -r ad55175e27bf -r 652cd6dff1d0 libexec/httpd/lua/glue.c
--- a/libexec/httpd/lua/glue.c  Tue May 01 23:41:51 2018 +0000
+++ b/libexec/httpd/lua/glue.c  Tue May 01 23:51:53 2018 +0000
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #define LUA_LIB
+#define LUA_USE_APICHECK
 #include <lua.h>
 #include <lauxlib.h>
 #include <lualib.h>
@@ -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 @@
        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 @@
        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 @@
        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 @@
 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;
 }



Home | Main Index | Thread Index | Old Index