diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-01 11:08:43 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-01 11:08:43 +0100 |
commit | 6bd388ae930900bef74532f810c4411650761868 (patch) | |
tree | bb164cd166ae1a43c2c7214d6961f0acda622ec8 | |
parent | 083e6ac5ce374e1e9759c7998dd04b9525333eb4 (diff) | |
download | rspamd-6bd388ae930900bef74532f810c4411650761868.tar.gz rspamd-6bd388ae930900bef74532f810c4411650761868.zip |
[Minor] Add flags for rspamd_lua_parse_table_arguments
-rw-r--r-- | src/lua/lua_common.c | 51 | ||||
-rw-r--r-- | src/lua/lua_common.h | 9 | ||||
-rw-r--r-- | src/lua/lua_config.c | 6 | ||||
-rw-r--r-- | src/lua/lua_dns.c | 1 | ||||
-rw-r--r-- | src/lua/lua_dns_resolver.c | 1 | ||||
-rw-r--r-- | src/lua/lua_map.c | 1 | ||||
-rw-r--r-- | src/lua/lua_task.c | 8 | ||||
-rw-r--r-- | src/lua/lua_tcp.c | 1 | ||||
-rw-r--r-- | src/lua/lua_worker.c | 1 | ||||
-rw-r--r-- | src/plugins/dkim_check.c | 1 |
10 files changed, 65 insertions, 15 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 785042b8e..354a932f9 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1238,7 +1238,9 @@ rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func) gboolean rspamd_lua_parse_table_arguments (lua_State *L, gint pos, - GError **err, const gchar *extraction_pattern, ...) + GError **err, + enum rspamd_lua_parse_arguments_flags how, + const gchar *extraction_pattern, ...) { const gchar *p, *key = NULL, *end, *cls; va_list ap; @@ -1314,7 +1316,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, const gchar **)) = NULL; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, const gchar **)) = NULL; + } } else { g_set_error (err, @@ -1341,7 +1346,9 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, gint64 *)) = 0; + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, gint64 *)) = 0; + } } else { g_set_error (err, @@ -1372,7 +1379,11 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, gint *)) = -1; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, gint *)) = -1; + } + if (is_table) { lua_pop (L, 1); } @@ -1404,7 +1415,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, gboolean *)) = 0; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, gboolean *)) = 0; + } } else { g_set_error (err, @@ -1432,7 +1446,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, gdouble *)) = 0; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, gdouble *)) = 0; + } } else { g_set_error (err, @@ -1460,7 +1477,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, gdouble *)) = NAN; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, gdouble *)) = NAN; + } } else { g_set_error (err, @@ -1491,8 +1511,11 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, const char **)) = NULL; - *valuelen = 0; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, const char **)) = NULL; + *valuelen = 0; + } } else { g_set_error (err, @@ -1520,7 +1543,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, } else { failed = TRUE; - *(va_arg (ap, ucl_object_t **)) = NULL; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, ucl_object_t **)) = NULL; + } } if (is_table) { @@ -1530,7 +1556,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos, case 'U': if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; - *(va_arg (ap, void **)) = NULL; + + if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { + *(va_arg (ap, void **)) = NULL; + } } else if (t != LUA_TUSERDATA) { g_set_error (err, diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 32b17a2fc..93bb5a28e 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -321,6 +321,10 @@ struct rspamd_async_session* lua_check_session (lua_State * L, gint pos); struct ev_loop* lua_check_ev_base (lua_State * L, gint pos); struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L, gint pos); +enum rspamd_lua_parse_arguments_flags { + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0, + RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING, +}; /** * Extract an arguments from lua table according to format string. Supported arguments are: * [*]key=S|I|N|B|V|U{a-z};[key=...] @@ -337,11 +341,14 @@ struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L, gint pos); * @param L lua state * @param pos at which pos start extraction * @param err error pointer + * @param how extraction type * @param extraction_pattern static pattern * @return TRUE if a table has been parsed */ gboolean rspamd_lua_parse_table_arguments (lua_State *L, gint pos, - GError **err, const gchar *extraction_pattern, ...); + GError **err, + enum rspamd_lua_parse_arguments_flags how, + const gchar *extraction_pattern, ...); gint rspamd_lua_traceback (lua_State *L); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index c171c483a..18baf8551 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1892,6 +1892,7 @@ lua_config_register_symbol (lua_State * L) if (cfg) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "name=S;weight=N;callback=F;flags=S;type=S;priority=I;parent=D;" "score=D;description=S;group=S;one_shot=B;nshots=I;" "allowed_ids=S;forbidden_ids=S", @@ -2227,6 +2228,7 @@ lua_config_set_metric_symbol (lua_State * L) if (lua_type (L, 2) == LUA_TTABLE) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*name=S;score=N;description=S;" "group=S;one_shot=B;one_param=B;priority=N;flags=S;" "nshots=I", @@ -2376,6 +2378,7 @@ lua_config_set_metric_action (lua_State * L) if (lua_type (L, 2) == LUA_TTABLE) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*action=S;score=N;" "priority=N", &name, &threshold, @@ -2881,6 +2884,7 @@ lua_config_register_regexp (lua_State *L) */ if (cfg != NULL) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*re=U{regexp};*type=S;header=S;pcre_only=B", &re, &type_str, &header_str, &pcre_only)) { msg_err_config ("cannot get parameters list: %e", err); @@ -2947,6 +2951,7 @@ lua_config_replace_regexp (lua_State *L) if (cfg != NULL) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*old_re=U{regexp};*new_re=U{regexp}", &old_re, &new_re)) { msg_err_config ("cannot get parameters list: %e", err); @@ -3686,6 +3691,7 @@ lua_config_add_doc (lua_State *L) if (cfg && option && doc_string) { if (lua_type (L, 5) == LUA_TTABLE) { if (!rspamd_lua_parse_table_arguments (L, 5, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "type=S;default=S;required=B", &type_str, &default_value, &required)) { msg_err_config ("cannot get parameters list: %e", err); diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 033b07fb4..0fdbe3f70 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -51,6 +51,7 @@ lua_dns_request (lua_State *L) /* Check arguments */ if (!rspamd_lua_parse_table_arguments (L, 1, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*name=S;task=U{task};*type=S;forced=B;session=U{session};config=U{config}", &to_resolve, &task, diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c index 382e9e985..a4e3b4b03 100644 --- a/src/lua/lua_dns_resolver.c +++ b/src/lua/lua_dns_resolver.c @@ -360,6 +360,7 @@ lua_dns_resolver_resolve_common (lua_State *L, /* Check arguments */ if (!rspamd_lua_parse_table_arguments (L, first, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "session=U{session};mempool=U{mempool};*name=S;*callback=F;" "option=S;task=U{task};forced=B", &session, &pool, &to_resolve, &cbref, &user_str, &task, &forced)) { diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 3ba7d0ed1..9c90cdf55 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -493,6 +493,7 @@ lua_config_add_map (lua_State *L) if (cfg) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*url=O;description=S;callback=F;type=S", &map_obj, &description, &cbidx, &type)) { ret = luaL_error (L, "invalid table arguments: %s", err->message); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 0ffe4b8c5..f9033eef8 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -5011,6 +5011,7 @@ lua_task_store_in_file (lua_State *L) if (task) { if (lua_istable (L, 2)) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "filename=S;tmpmask=S;mode=I;force_new=B;keep=B", &fname, &tmpmask, &mode, &force_new, &keep)) { msg_err_task ("cannot get parameters list: %e", err); @@ -5112,9 +5113,10 @@ lua_task_process_regexp (lua_State *L) */ if (task != NULL) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, - "*re=U{regexp};*type=S;header=V;strong=B", - &re, &type_str, &header_len, &header_str, - &strong)) { + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, + "*re=U{regexp};*type=S;header=V;strong=B", + &re, &type_str, &header_len, &header_str, + &strong)) { msg_err_task ("cannot get parameters list: %e", err); if (err) { diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index e2f55e78b..371e72d5c 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -1797,6 +1797,7 @@ lua_tcp_connect_sync (lua_State *L) struct ev_loop *ev_base = NULL; int arguments_validated = rspamd_lua_parse_table_arguments (L, 1, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "task=U{task};session=U{session};resolver=U{resolver};ev_base=U{ev_base};" "*host=S;*port=I;timeout=D;config=U{config}", &task, &session, &resolver, &ev_base, diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c index 73f8baea1..8b69b71ef 100644 --- a/src/lua/lua_worker.c +++ b/src/lua/lua_worker.c @@ -546,6 +546,7 @@ lua_worker_spawn_process (lua_State *L) gint func_cbref, cb_cbref; if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "func=F;exec=S;stdin=V;*on_complete=F", &func_cbref, &cmdline, &inputlen, &input, &cb_cbref)) { msg_err ("cannot get parameters list: %e", err); diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index e1edbccd8..7d3475867 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -701,6 +701,7 @@ lua_dkim_sign_handler (lua_State *L) * - key */ if (!rspamd_lua_parse_table_arguments (L, 2, &err, + RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "key=V;rawkey=V;*domain=S;*selector=S;no_cache=B;headers=S;" "sign_type=S;arc_idx=I;arc_cv=S;expire=I;pubkey=S;" "strict_pubkey_check=B", |