From 3e4874062032e64e88407c0c9c546667d51988e0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 23 Aug 2013 02:14:45 +0100 Subject: [PATCH] Add flags to rcl parser creation. Allow RSPAMD_CL_FLAG_KEY_LOWERCASE flag to force all keys in rcl objects to be lowercased which is useful for parsing. --- src/rcl/rcl.h | 6 +++++- src/rcl/rcl_internal.h | 3 ++- src/rcl/rcl_parser.c | 11 +++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rcl/rcl.h b/src/rcl/rcl.h index 61ce88add..50555e248 100644 --- a/src/rcl/rcl.h +++ b/src/rcl/rcl.h @@ -62,6 +62,10 @@ enum rspamd_cl_emitter { RSPAMD_CL_EMIT_CONFIG }; +enum rspamd_cl_flags { + RSPAMD_CL_FLAG_KEY_LOWERCASE = 0x1 +}; + typedef struct rspamd_cl_object_s { gchar *key; /**< the key of an object */ union { @@ -249,7 +253,7 @@ struct rspamd_cl_parser; * @param pool pool to allocate memory from * @return new parser object */ -struct rspamd_cl_parser* rspamd_cl_parser_new (void); +struct rspamd_cl_parser* rspamd_cl_parser_new (gint flags); /** * Register new handler for a macro diff --git a/src/rcl/rcl_internal.h b/src/rcl/rcl_internal.h index dda08ddba..4d3294e77 100644 --- a/src/rcl/rcl_internal.h +++ b/src/rcl/rcl_internal.h @@ -95,12 +95,13 @@ struct rspamd_cl_pubkey { struct rspamd_cl_parser { enum rspamd_cl_parser_state state; enum rspamd_cl_parser_state prev_state; + guint recursion; + gint flags; rspamd_cl_object_t *top_obj; rspamd_cl_object_t *cur_obj; struct rspamd_cl_macro *macroes; struct rspamd_cl_stack *stack; struct rspamd_cl_chunk *chunks; - guint recursion; struct rspamd_cl_pubkey *keys; }; diff --git a/src/rcl/rcl_parser.c b/src/rcl/rcl_parser.c index 797c8850c..7ba9bb6bb 100644 --- a/src/rcl/rcl_parser.c +++ b/src/rcl/rcl_parser.c @@ -658,7 +658,12 @@ rspamd_cl_parse_key (struct rspamd_cl_parser *parser, /* Create a new object */ nobj = rspamd_cl_object_new (); nobj->key = g_malloc (end - c + 1); - rspamd_strlcpy (nobj->key, c, end - c + 1); + if (parser->flags & RSPAMD_CL_FLAG_KEY_LOWERCASE) { + rspamd_strlcpy_tolower (nobj->key, c, end - c + 1); + } + else { + rspamd_strlcpy (nobj->key, c, end - c + 1); + } if (got_quote) { rspamd_cl_unescape_json_string (nobj->key); @@ -1187,7 +1192,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err) } struct rspamd_cl_parser* -rspamd_cl_parser_new (void) +rspamd_cl_parser_new (gint flags) { struct rspamd_cl_parser *new; @@ -1196,6 +1201,8 @@ rspamd_cl_parser_new (void) rspamd_cl_parser_register_macro (new, "include", rspamd_cl_include_handler, new); rspamd_cl_parser_register_macro (new, "includes", rspamd_cl_includes_handler, new); + new->flags = flags; + return new; } -- 2.39.5