aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-14 03:34:29 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-14 03:34:29 +0100
commit56858a97dd32f2e45a8ef023ca7dfe1e5f5d7460 (patch)
treed6a1771a0c7e91b66b5a3452881e5dd2b04be1ee
parent331d1842b9e86efdedd31b67d5ff231ac0b239fa (diff)
downloadxK-56858a97dd32f2e45a8ef023ca7dfe1e5f5d7460.tar.gz
xK-56858a97dd32f2e45a8ef023ca7dfe1e5f5d7460.tar.xz
xK-56858a97dd32f2e45a8ef023ca7dfe1e5f5d7460.zip
degesch: Lua: allow simulating user input
Also added UTF-8 validation to buffer:log() while I'm at it.
-rw-r--r--degesch.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index d736a9c..fe503aa 100644
--- a/degesch.c
+++ b/degesch.c
@@ -7432,6 +7432,15 @@ lua_plugin_handle_string_filter_result (struct lua_plugin *self,
return true;
}
+static const char *
+lua_plugin_check_utf8 (lua_State *L, int arg)
+{
+ size_t len;
+ const char *s = luaL_checklstring (L, arg, &len);
+ luaL_argcheck (L, utf8_validate (s, len), 1, "must be valid UTF-8");
+ return s;
+}
+
static void
lua_plugin_log_error
(struct lua_plugin *self, const char *where, struct error *error)
@@ -7548,7 +7557,7 @@ lua_buffer_log (lua_State *L)
{
struct lua_buffer *wrapper = luaL_checkudata (L, 1, XLUA_BUFFER_METATABLE);
luaL_argcheck (L, wrapper->buffer, 1, "dead reference used");
- const char *message = luaL_checkstring (L, 2);
+ const char *message = lua_plugin_check_utf8 (L, 2);
struct buffer *buffer = wrapper->buffer;
log_full (wrapper->plugin->ctx, buffer->server, buffer,
@@ -7556,12 +7565,25 @@ lua_buffer_log (lua_State *L)
return 0;
}
+static int
+lua_buffer_execute (lua_State *L)
+{
+ struct lua_buffer *wrapper = luaL_checkudata (L, 1, XLUA_BUFFER_METATABLE);
+ luaL_argcheck (L, wrapper->buffer, 1, "dead reference used");
+ const char *line = lua_plugin_check_utf8 (L, 2);
+
+ struct buffer *buffer = wrapper->buffer;
+ process_input_utf8 (wrapper->plugin->ctx, buffer, line, 0);
+ return 0;
+}
+
static luaL_Reg lua_buffer_table[] =
{
// TODO: some useful methods or values
{ "__gc", lua_buffer_gc },
{ "get_server", lua_buffer_get_server },
{ "log", lua_buffer_log },
+ { "execute", lua_buffer_execute },
{ NULL, NULL }
};