aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-31 14:53:33 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-31 14:53:33 +0100
commit50bae963e44e0312544b79a2ee4b4a3e8e37690f (patch)
tree039df235a844defc28c11ad3546a48ce9e8d2a3d
parent44c7c7e776487b5918c8570a6b876138953ec8ed (diff)
downloadrspamd-50bae963e44e0312544b79a2ee4b4a3e8e37690f.tar.gz
rspamd-50bae963e44e0312544b79a2ee4b4a3e8e37690f.zip
Add parser for boolean fields in a structure.
-rw-r--r--src/cfg_rcl.c23
-rw-r--r--src/cfg_rcl.h12
2 files changed, 35 insertions, 0 deletions
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index 6103627c1..b08e530ab 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -484,3 +484,26 @@ rspamd_rcl_parse_struct_string_list (struct config_file *cfg, rspamd_cl_object_t
return TRUE;
}
+
+gboolean
+rspamd_rcl_parse_struct_boolean (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;
+ gboolean *target;
+
+ target = (gboolean *)(((gchar *)pd->user_struct) + pd->offset);
+
+ if (obj->type == RSPAMD_CL_BOOLEAN) {
+ *target = obj->value.iv;
+ }
+ else if (obj->type == RSPAMD_CL_INT) {
+ *target = obj->value.iv;
+ }
+ else {
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot convert an object to boolean");
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/src/cfg_rcl.h b/src/cfg_rcl.h
index afe27d480..08ad3594c 100644
--- a/src/cfg_rcl.h
+++ b/src/cfg_rcl.h
@@ -172,4 +172,16 @@ gboolean rspamd_rcl_parse_struct_time (struct config_file *cfg, rspamd_cl_object
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);
+/**
+ * Parse a boolean field of a structure
+ * @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_boolean (struct config_file *cfg, rspamd_cl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err);
+
#endif /* CFG_RCL_H_ */