aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-30 13:59:21 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-30 13:59:21 +0100
commit8f90db61cf5b50dcbc8c46f1b20e0a87fea4fb96 (patch)
tree41e8689bcc29deeb349bc300bcff725c835b26f0
parent82776e7dc0eed455fc7fdf144e96286abb3ef3bd (diff)
downloadrspamd-8f90db61cf5b50dcbc8c46f1b20e0a87fea4fb96.tar.gz
rspamd-8f90db61cf5b50dcbc8c46f1b20e0a87fea4fb96.zip
Add string list fields parser.
-rw-r--r--src/cfg_rcl.c45
-rw-r--r--src/cfg_rcl.h12
2 files changed, 57 insertions, 0 deletions
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index f2f48f912..b094b04ac 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -403,3 +403,48 @@ rspamd_rcl_parse_struct_time (struct config_file *cfg, rspamd_cl_object_t *obj,
return TRUE;
}
+
+gboolean
+rspamd_rcl_parse_struct_string_list (struct config_file *cfg, rspamd_cl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err)
+{
+ struct rspamd_rcl_struct_parser *pd = ud;
+ GList **target;
+ gchar *val;
+ rspamd_cl_object_t *cur;
+ const gsize num_str_len = 32;
+
+ target = (GList **)(((gchar *)pd->user_struct) + pd->offset);
+
+ if (obj->type != RSPAMD_CL_ARRAY) {
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "an array of strings is expected");
+ return FALSE;
+ }
+
+ for (cur = obj; cur != NULL; cur = cur->next) {
+ switch (cur->type) {
+ case RSPAMD_CL_STRING:
+ /* Direct assigning is safe, as curect is likely linked to the cfg mem_pool */
+ val = cur->value.sv;
+ break;
+ case RSPAMD_CL_INT:
+ val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
+ rspamd_snprintf (val, num_str_len, "%L", cur->value.iv);
+ break;
+ case RSPAMD_CL_FLOAT:
+ val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
+ rspamd_snprintf (val, num_str_len, "%f", cur->value.dv);
+ break;
+ case RSPAMD_CL_BOOLEAN:
+ val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
+ rspamd_snprintf (val, num_str_len, "%b", (gboolean)cur->value.iv);
+ break;
+ default:
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot convert an object or array to string");
+ return FALSE;
+ }
+ *target = g_list_prepend (*target, val);
+ }
+
+ return TRUE;
+}
diff --git a/src/cfg_rcl.h b/src/cfg_rcl.h
index 8c77009a2..283e84d82 100644
--- a/src/cfg_rcl.h
+++ b/src/cfg_rcl.h
@@ -149,4 +149,16 @@ gboolean rspamd_rcl_parse_struct_double (struct config_file *cfg, rspamd_cl_obje
gboolean rspamd_rcl_parse_struct_time (struct config_file *cfg, rspamd_cl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
+/**
+ * Parse a string list field of a structure presented by a GList* object
+ * @param cfg config pointer
+ * @param obj object to parse
+ * @param ud struct_parser structure (flags mean the exact structure used)
+ * @param section the current section
+ * @param err error pointer
+ * @return TRUE if a value has been successfully parsed
+ */
+gboolean rspamd_rcl_parse_struct_string_list (struct config_file *cfg, rspamd_cl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err);
+
#endif /* CFG_RCL_H_ */