return TRUE;
}
-static inline void
+/**
+ * Add new section to the configuration
+ * @param top top section
+ * @param name the name of the section
+ * @param handler handler function for all attributes
+ * @param type type of object handled by a handler
+ * @param required whether at least one of these sections is required
+ * @param strict_type turn on strict check for types for this section
+ * @return newly created structure
+ */
+static inline struct rspamd_rcl_section*
rspamd_rcl_add_section (struct rspamd_rcl_section *top,
const gchar *name, rspamd_rcl_handler_t handler,
enum rspamd_cl_type type, gboolean required, gboolean strict_type)
new->strict_type = strict_type;
HASH_ADD_KEYPTR (hh, top, new->name, strlen (new->name), new);
+ return new;
+}
+
+/**
+ * Add a default handler for a section
+ * @param section section pointer
+ * @param name name of param
+ * @param handler handler of param
+ * @param offset offset in a structure
+ * @param flags flags for the parser
+ * @return newly created structure
+ */
+static inline struct rspamd_rcl_default_handler_data *
+rspamd_rcl_add_default_handler (struct rspamd_rcl_section *section, const gchar *name,
+ rspamd_rcl_handler_t handler, gsize offset, gint flags)
+{
+ struct rspamd_rcl_default_handler_data *new;
+
+ new = g_slice_alloc0 (sizeof (struct rspamd_rcl_default_handler_data));
+ new->key = name;
+ new->handler = handler;
+ new->pd.offset = offset;
+ new->pd.flags = flags;
+
+ HASH_ADD_KEYPTR (hh, section->default_parser, new->key, strlen (new->key), new);
+ return new;
}
struct rspamd_rcl_section*
rspamd_rcl_config_init (void)
{
- struct rspamd_rcl_section *new;
+ struct rspamd_rcl_section *new, *sub;
new = g_slice_alloc0 (sizeof (struct rspamd_rcl_section));
/* TODO: add all known rspamd sections here */
- rspamd_rcl_add_section (new, "logging", rspamd_rcl_logging_handler, RSPAMD_CL_OBJECT,
+ sub = rspamd_rcl_add_section (new, "logging", rspamd_rcl_logging_handler, RSPAMD_CL_OBJECT,
FALSE, TRUE);
-
+ rspamd_rcl_add_default_handler (sub, "log_buffer", rspamd_rcl_parse_struct_integer,
+ G_STRUCT_OFFSET (struct config_file, log_buf_size), 0);
return new;
}
struct rspamd_rcl_section;
+struct rspamd_rcl_struct_parser {
+ gpointer user_struct;
+ goffset offset;
+ gsize size;
+ enum {
+ RSPAMD_CL_FLAG_TIME_FLOAT = 0x1 << 0,
+ RSPAMD_CL_FLAG_TIME_TIMEVAL = 0x1 << 1,
+ RSPAMD_CL_FLAG_TIME_TIMESPEC = 0x1 << 2,
+ RSPAMD_CL_FLAG_TIME_INTEGER = 0x1 << 3
+ } flags;
+};
+
/**
* Common handler type
* @param cfg configuration
typedef gboolean (*rspamd_rcl_handler_t) (struct config_file *cfg, rspamd_cl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
+struct rspamd_rcl_default_handler_data {
+ struct rspamd_rcl_struct_parser pd;
+ const gchar *key;
+ rspamd_rcl_handler_t handler;
+ UT_hash_handle hh;
+};
+
struct rspamd_rcl_section {
const gchar *name; /**< name of section */
rspamd_rcl_handler_t handler; /**< handler of section attributes */
gboolean strict_type; /**< whether we need strict type */
UT_hash_handle hh; /** hash handle */
struct rspamd_rcl_section *subsections; /**< hash table of subsections */
+ struct rspamd_rcl_default_handler_data *default_parser; /**< generic parsing fields */
};
/**
* which itself contains a struct pointer and the offset of a member in a
* specific structure
*/
-struct rspamd_rcl_struct_parser {
- gpointer user_struct;
- goffset offset;
- gsize size;
- enum {
- RSPAMD_CL_FLAG_TIME_FLOAT = 0x1 << 0,
- RSPAMD_CL_FLAG_TIME_TIMEVAL = 0x1 << 1,
- RSPAMD_CL_FLAG_TIME_TIMESPEC = 0x1 << 2,
- RSPAMD_CL_FLAG_TIME_INTEGER = 0x1 << 3
- } flags;
-};
/**
* Parse a string field of a structure