libs/web: add up & down arrow icons
[oweals/luci.git] / libs / web / src / template_lualib.c
index 685613fbdcccad36dd9afd1c0964ac74d566464a..d3a5f89bbd5da892419c588e3f05bca0c06676e0 100644 (file)
@@ -29,8 +29,13 @@ int template_L_parse(lua_State *L)
                parser.flags   = 0;
                parser.bufsize = 0;
                parser.state   = T_STATE_TEXT_NEXT;
-               
-               if( !(lua_status = lua_load(L, template_reader, &parser, file)) )
+
+               lua_status = lua_load(L, template_reader, &parser, file);
+
+               (void) close(parser.fd);
+
+
+               if( lua_status == 0 )
                {
                        return 1;
                }
@@ -49,14 +54,50 @@ int template_L_parse(lua_State *L)
        return 3;
 }
 
+int template_L_sanitize_utf8(lua_State *L)
+{
+       size_t len = 0;
+       const char *str = luaL_checklstring(L, 1, &len);
+       char *res = sanitize_utf8(str, len);
+
+       if (res != NULL)
+       {
+               lua_pushstring(L, res);
+               free(res);
+
+               return 1;
+       }
+
+       return 0;
+}
+
+int template_L_sanitize_pcdata(lua_State *L)
+{
+       size_t len = 0;
+       const char *str = luaL_checklstring(L, 1, &len);
+       char *res = sanitize_pcdata(str, len);
+
+       if (res != NULL)
+       {
+               lua_pushstring(L, res);
+               free(res);
+
+               return 1;
+       }
+
+       return 0;
+}
+
+
 /* module table */
 static const luaL_reg R[] = {
-       {"parse",       template_L_parse},
-       {NULL,          NULL}
+       { "parse",                              template_L_parse },
+       { "sanitize_utf8",              template_L_sanitize_utf8 },
+       { "sanitize_pcdata",    template_L_sanitize_pcdata },
+       { NULL,                                 NULL }
 };
 
 LUALIB_API int luaopen_luci_template_parser(lua_State *L) {
        luaL_register(L, TEMPLATE_LUALIB_META, R);
        return 1;
 }
-