static const gchar *M = "rspamd lua dns resolver";
-struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L);
-
/* Lua bindings */
LUA_FUNCTION_DEF (dns_resolver, init);
LUA_FUNCTION_DEF (dns_resolver, resolve_a);
};
struct rspamd_dns_resolver *
-lua_check_dns_resolver (lua_State * L)
+lua_check_dns_resolver (lua_State * L, gint pos)
{
- void *ud = rspamd_lua_check_udata (L, 1, "rspamd{resolver}");
- luaL_argcheck (L, ud != NULL, 1, "'resolver' expected");
+ void *ud = rspamd_lua_check_udata (L, pos, "rspamd{resolver}");
+ luaL_argcheck (L, ud != NULL, pos, "'resolver' expected");
return ud ? *((struct rspamd_dns_resolver **)ud) : NULL;
}
static int
lua_dns_resolver_resolve_a (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
if (dns_resolver) {
return lua_dns_resolver_resolve_common (L,
static int
lua_dns_resolver_resolve_ptr (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
if (dns_resolver) {
return lua_dns_resolver_resolve_common (L,
static int
lua_dns_resolver_resolve_txt (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
if (dns_resolver) {
return lua_dns_resolver_resolve_common (L,
static int
lua_dns_resolver_resolve_mx (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
if (dns_resolver) {
return lua_dns_resolver_resolve_common (L,
static int
lua_dns_resolver_resolve_ns (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
if (dns_resolver) {
return lua_dns_resolver_resolve_common (L,
static int
lua_dns_resolver_resolve (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L, 1);
int type;
type = lua_dns_get_type (L, 2);
*/
LUA_FUNCTION_DEF (task, get_resolver);
/***
- * @method task:inc_dns_req()
- * Increment number of DNS requests for the task. Is used just for logging purposes.
+ * @method task:set_resolver(resolver)
+ * Sets rspamd_resolver for a specified task.
*/
+LUA_FUNCTION_DEF (task, set_resolver);
+/***
+* @method task:inc_dns_req()
+* Increment number of DNS requests for the task. Is used just for logging purposes.
+*/
LUA_FUNCTION_DEF (task, inc_dns_req);
/***
* @method task:get_dns_req()
LUA_INTERFACE_DEF (task, get_queue_id),
LUA_INTERFACE_DEF (task, get_uid),
LUA_INTERFACE_DEF (task, get_resolver),
+ LUA_INTERFACE_DEF (task, set_resolver),
LUA_INTERFACE_DEF (task, inc_dns_req),
LUA_INTERFACE_DEF (task, get_dns_req),
LUA_INTERFACE_DEF (task, has_recipients),
return 1;
}
+static gint
+lua_task_set_resolver (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ struct rspamd_dns_resolver *resolver = lua_check_dns_resolver (L, 2);
+
+ if (task != NULL && resolver != NULL) {
+ task->resolver = resolver;
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 0;
+}
+
static gint
lua_task_inc_dns_req (lua_State *L)
{