return ret;
}
-gboolean
+struct rspamd_map *
rspamd_map_add (struct rspamd_config *cfg,
const gchar *map_line,
const gchar *description,
/* First of all detect protocol line */
if (rspamd_map_check_proto (cfg, map_line, new_map) == NULL) {
- return FALSE;
+ return NULL;
}
new_map->read_callback = read_callback;
if (errno != ENOENT) {
msg_err_config ("cannot open file '%s': %s", def, strerror
(errno));
- return FALSE;
+ return NULL;
}
msg_info_config (
if (http_parser_parse_url (new_map->uri, strlen (new_map->uri), TRUE,
&up) != 0) {
msg_err_config ("cannot parse HTTP url: %s", new_map->uri);
- return FALSE;
+ return NULL;
}
else {
if (!(up.field_set & 1 << UF_HOST)) {
msg_err_config ("cannot parse HTTP url: %s: no host", new_map->uri);
- return FALSE;
+ return NULL;
}
tok.begin = new_map->uri + up.field_data[UF_HOST].off;
cfg->maps = g_list_prepend (cfg->maps, new_map);
- return TRUE;
+ return new_map;
}
static gchar*
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *map_line, *description;
struct rspamd_lua_map *map, **pmap;
+ struct rspamd_map *m;
if (cfg) {
map_line = luaL_checkstring (L, 2);
map->data.radix = radix_create_compressed ();
map->type = RSPAMD_LUA_MAP_RADIX;
- if (!rspamd_map_add (cfg, map_line, description,
+ if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_radix_read,
rspamd_radix_fin,
- (void **)&map->data.radix)) {
+ (void **)&map->data.radix)) == NULL) {
msg_warn_config ("invalid radix map %s", map_line);
radix_destroy_compressed (map->data.radix);
lua_pushnil (L);
return 1;
}
+ map->map = m;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *map_line, *description;
struct rspamd_lua_map *map, **pmap;
+ struct rspamd_map *m;
if (cfg) {
map_line = luaL_checkstring (L, 2);
rspamd_strcase_equal);
map->type = RSPAMD_LUA_MAP_SET;
- if (!rspamd_map_add (cfg, map_line, description,
+ if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_hosts_read,
rspamd_hosts_fin,
- (void **)&map->data.hash)) {
+ (void **)&map->data.hash)) == NULL) {
msg_warn_config ("invalid set map %s", map_line);
g_hash_table_destroy (map->data.hash);
lua_pushnil (L);
return 1;
}
+ map->map = m;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *map_line, *description;
struct rspamd_lua_map *map, **pmap;
+ struct rspamd_map *m;
if (cfg) {
map_line = luaL_checkstring (L, 2);
rspamd_strcase_equal);
map->type = RSPAMD_LUA_MAP_HASH;
- if (!rspamd_map_add (cfg, map_line, description,
+ if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_kv_list_read,
rspamd_kv_list_fin,
- (void **)&map->data.hash)) {
+ (void **)&map->data.hash)) == NULL) {
msg_warn_config ("invalid hash map %s", map_line);
g_hash_table_destroy (map->data.hash);
lua_pushnil (L);
return 1;
}
+ map->map = m;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
const gchar *map_line, *description;
struct lua_map_callback_data *cbdata, **pcbdata;
struct rspamd_lua_map *map;
+ struct rspamd_map *m;
int cbidx;
if (cfg) {
pcbdata = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (cbdata));
*pcbdata = cbdata;
- if (!rspamd_map_add (cfg, map_line, description, lua_map_read, lua_map_fin,
- (void **)pcbdata)) {
+ if ((m = rspamd_map_add (cfg, map_line, description,
+ lua_map_read, lua_map_fin,
+ (void **)pcbdata)) == NULL) {
msg_warn_config ("invalid hash map %s", map_line);
lua_pushboolean (L, false);
}
else {
+ map->map = m;
lua_pushboolean (L, true);
}
}