void luaopen_ip (lua_State * L);
void luaopen_expression (lua_State * L);
void luaopen_logger (lua_State * L);
+void luaopen_text (lua_State *L);
gint rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task);
gint rspamd_lua_call_chain_filter (const gchar *function,
{NULL, NULL}
};
+/* Blob methods */
+struct rspamd_lua_text {
+ const gchar *start;
+ gsize len;
+};
+
+LUA_FUNCTION_DEF (text, len);
+LUA_FUNCTION_DEF (text, str);
+
+static const struct luaL_reg textlib_m[] = {
+ LUA_INTERFACE_DEF (text, len),
+ LUA_INTERFACE_DEF (text, str),
+ {"__tostring", lua_text_str},
+ {NULL, NULL}
+};
+
/* Utility functions */
struct rspamd_task *
lua_check_task (lua_State * L, gint pos)
return ud ? *((struct rspamd_url **)ud) : NULL;
}
+static struct rspamd_lua_text *
+lua_check_text (lua_State * L, gint pos)
+{
+ void *ud = luaL_checkudata (L, pos, "rspamd{text}");
+ luaL_argcheck (L, ud != NULL, pos, "'text' expected");
+ return ud ? (struct rspamd_lua_text *)ud : NULL;
+}
+
+/* Task methods */
+
static int
lua_task_create_empty (lua_State *L)
{
return 1;
}
+/* Text methods */
+static gint
+lua_text_len (lua_State *L)
+{
+ struct rspamd_lua_text *t = lua_check_text (L, 1);
+ gsize l = 0;
+
+ if (t != NULL) {
+ l = t->len;
+ }
+
+ lua_pushnumber (L, l);
+
+ return 1;
+}
+
+static gint
+lua_text_str (lua_State *L)
+{
+ struct rspamd_lua_text *t = lua_check_text (L, 1);
+
+ if (t != NULL) {
+ lua_pushlstring (L, t->start, t->len);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
/* Init part */
static gint
lua_pop (L, 1); /* remove metatable from stack */
}
+void
+luaopen_text (lua_State *L)
+{
+ rspamd_lua_new_class (L, "rspamd{text}", textlib_m);
+ lua_pop (L, 1);
+}
+
void
rspamd_lua_task_push (lua_State *L, struct rspamd_task *task)
{
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
}
+