diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
commit | fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b (patch) | |
tree | c84e6a5d4c5cd78a7a2cc3c7adbc7af5d0541682 /src/kvstorage_config.c | |
parent | e0483657ff6cf1adc828ccce457814d61fe90a0d (diff) | |
download | rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.tar.gz rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.zip |
Revert "Unify code style."
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
Diffstat (limited to 'src/kvstorage_config.c')
-rw-r--r-- | src/kvstorage_config.c | 252 |
1 files changed, 94 insertions, 158 deletions
diff --git a/src/kvstorage_config.c b/src/kvstorage_config.c index a29ae2454..362a47f49 100644 --- a/src/kvstorage_config.c +++ b/src/kvstorage_config.c @@ -21,9 +21,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "cfg_xml.h" #include "kvstorage_config.h" #include "main.h" +#include "cfg_xml.h" #ifdef WITH_DB #include "kvstorage_bdb.h" #endif @@ -68,7 +68,7 @@ struct kvstorage_config_parser { static void kvstorage_config_destroy (gpointer k) { - struct kvstorage_config *kconf = k; + struct kvstorage_config *kconf = k; if (kconf->name) { g_free (kconf->name); @@ -83,14 +83,12 @@ kvstorage_config_destroy (gpointer k) /* Init kvstorage */ static void -kvstorage_init_callback (const gpointer key, - const gpointer value, - gpointer unused) +kvstorage_init_callback (const gpointer key, const gpointer value, gpointer unused) { - struct kvstorage_config *kconf = value; - struct rspamd_kv_cache *cache; - struct rspamd_kv_backend *backend = NULL; - struct rspamd_kv_expire *expire = NULL; + struct kvstorage_config *kconf = value; + struct rspamd_kv_cache *cache; + struct rspamd_kv_backend *backend = NULL; + struct rspamd_kv_expire *expire = NULL; switch (kconf->cache.type) { case KVSTORAGE_TYPE_CACHE_HASH: @@ -115,22 +113,17 @@ kvstorage_init_callback (const gpointer key, backend = NULL; break; case KVSTORAGE_TYPE_BACKEND_FILE: - backend = rspamd_kv_file_new (kconf->backend.filename, - kconf->backend.sync_ops, - FILE_STORAGE_LEVELS, - kconf->backend.do_fsync, - kconf->backend.do_ref); + backend = rspamd_kv_file_new (kconf->backend.filename, kconf->backend.sync_ops, + FILE_STORAGE_LEVELS, kconf->backend.do_fsync, kconf->backend.do_ref); break; #ifdef WITH_DB case KVSTORAGE_TYPE_BACKEND_BDB: - backend = rspamd_kv_bdb_new (kconf->backend.filename, - kconf->backend.sync_ops); + backend = rspamd_kv_bdb_new (kconf->backend.filename, kconf->backend.sync_ops); break; #endif #ifdef WITH_SQLITE case KVSTORAGE_TYPE_BACKEND_SQLITE: - backend = rspamd_kv_sqlite_new (kconf->backend.filename, - kconf->backend.sync_ops); + backend = rspamd_kv_sqlite_new (kconf->backend.filename, kconf->backend.sync_ops); break; #endif } @@ -141,27 +134,20 @@ kvstorage_init_callback (const gpointer key, break; } - kconf->storage = rspamd_kv_storage_new (kconf->id, - kconf->name, - cache, - backend, - expire, - kconf->cache.max_elements, - kconf->cache.max_memory, - kconf->cache.no_overwrite); + kconf->storage = rspamd_kv_storage_new (kconf->id, kconf->name, cache, backend, expire, + kconf->cache.max_elements, kconf->cache.max_memory, kconf->cache.no_overwrite); } /* XML parse callbacks */ /* Called for open tags <foo bar="baz"> */ -void -kvstorage_xml_start_element (GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - gpointer user_data, - GError **error) +void kvstorage_xml_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) { - struct kvstorage_config_parser *kv_parser = user_data; + struct kvstorage_config_parser *kv_parser = user_data; switch (kv_parser->state) { case KVSTORAGE_STATE_INIT: @@ -173,12 +159,10 @@ kvstorage_xml_start_element (GMarkupParseContext *context, if (kv_parser->pool != NULL) { rspamd_mempool_delete (kv_parser->pool); } - kv_parser->pool = - rspamd_mempool_new (rspamd_mempool_suggest_size ()); + kv_parser->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Create new kvstorage_config */ - kv_parser->current_storage = - g_malloc0 (sizeof (struct kvstorage_config)); + kv_parser->current_storage = g_malloc0 (sizeof (struct kvstorage_config)); kv_parser->current_storage->id = last_id++; } if (g_ascii_strcasecmp (element_name, "type") == 0) { @@ -215,9 +199,8 @@ kvstorage_xml_start_element (GMarkupParseContext *context, } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -245,9 +228,8 @@ kvstorage_xml_start_element (GMarkupParseContext *context, } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected in backend definition", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected in backend definition", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -259,9 +241,8 @@ kvstorage_xml_start_element (GMarkupParseContext *context, } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected in expire definition", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected in expire definition", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -273,27 +254,24 @@ kvstorage_xml_start_element (GMarkupParseContext *context, } -#define CHECK_TAG(s) \ - do { \ - if (g_ascii_strcasecmp (element_name, kv_parser->cur_elt) == 0) { \ - kv_parser->state = (s); \ - } \ - else { \ - if (*error == NULL) *error = g_error_new ( \ - xml_error_quark (), XML_UNMATCHED_TAG, "element %s is unexpected in this state, expected %s", element_name, \ - kv_parser->cur_elt); \ - kv_parser->state = KVSTORAGE_STATE_ERROR; \ - } \ - } while (0) +#define CHECK_TAG(s) \ +do { \ +if (g_ascii_strcasecmp (element_name, kv_parser->cur_elt) == 0) { \ + kv_parser->state = (s); \ +} \ +else { \ + if (*error == NULL) *error = g_error_new (xml_error_quark (), XML_UNMATCHED_TAG, "element %s is unexpected in this state, expected %s", element_name, kv_parser->cur_elt); \ + kv_parser->state = KVSTORAGE_STATE_ERROR; \ +} \ +} while (0) /* Called for close tags </foo> */ -void -kvstorage_xml_end_element (GMarkupParseContext *context, - const gchar *element_name, - gpointer user_data, - GError **error) +void kvstorage_xml_end_element (GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) { - struct kvstorage_config_parser *kv_parser = user_data; + struct kvstorage_config_parser *kv_parser = user_data; switch (kv_parser->state) { case KVSTORAGE_STATE_INIT: @@ -303,9 +281,8 @@ kvstorage_xml_end_element (GMarkupParseContext *context, return; } if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "end element %s is unexpected, expected start element", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "end element %s is unexpected, expected start element", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; break; @@ -333,9 +310,8 @@ kvstorage_xml_end_element (GMarkupParseContext *context, } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -346,9 +322,8 @@ kvstorage_xml_end_element (GMarkupParseContext *context, } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", - element_name); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "element %s is unexpected", + element_name); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -361,19 +336,18 @@ kvstorage_xml_end_element (GMarkupParseContext *context, #undef CHECK_TAG /* text is not nul-terminated */ -void -kvstorage_xml_text (GMarkupParseContext *context, - const gchar *text, - gsize text_len, - gpointer user_data, - GError **error) +void kvstorage_xml_text (GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) { - struct kvstorage_config_parser *kv_parser = user_data; - gchar *err_str; + struct kvstorage_config_parser *kv_parser = user_data; + gchar *err_str; /* Strip space symbols */ while (*text && g_ascii_isspace (*text)) { - text++; + text ++; } if (*text == '\0') { /* Skip empty text */ @@ -384,9 +358,7 @@ kvstorage_xml_text (GMarkupParseContext *context, case KVSTORAGE_STATE_INIT: case KVSTORAGE_STATE_PARAM: if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, - "text is unexpected, expected start element"); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "text is unexpected, expected start element"); } kv_parser->state = KVSTORAGE_STATE_ERROR; break; @@ -394,14 +366,12 @@ kvstorage_xml_text (GMarkupParseContext *context, kv_parser->current_storage->id = strtoul (text, &err_str, 10); if ((gsize)(err_str - text) != text_len) { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "invalid number: %*s", - (int)text_len, text); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "invalid number: %*s", (int)text_len, text); } kv_parser->state = KVSTORAGE_STATE_ERROR; } else { - last_id++; + last_id ++; last_id = MAX (kv_parser->current_storage->id, last_id); } break; @@ -410,103 +380,77 @@ kvstorage_xml_text (GMarkupParseContext *context, rspamd_strlcpy (kv_parser->current_storage->name, text, text_len + 1); break; case KVSTORAGE_STATE_CACHE_MAX_ELTS: - kv_parser->current_storage->cache.max_elements = - rspamd_config_parse_limit (text, text_len); + kv_parser->current_storage->cache.max_elements = rspamd_config_parse_limit (text, text_len); break; case KVSTORAGE_STATE_CACHE_MAX_MEM: - kv_parser->current_storage->cache.max_memory = - rspamd_config_parse_limit (text, text_len); + kv_parser->current_storage->cache.max_memory = rspamd_config_parse_limit (text, text_len); break; case KVSTORAGE_STATE_CACHE_NO_OVERWRITE: - kv_parser->current_storage->cache.no_overwrite = - rspamd_config_parse_flag (text); + kv_parser->current_storage->cache.no_overwrite = rspamd_config_parse_flag (text); break; case KVSTORAGE_STATE_CACHE_TYPE: - if (g_ascii_strncasecmp (text, "hash", - MIN (text_len, sizeof ("hash") - 1)) == 0) { + if (g_ascii_strncasecmp (text, "hash", MIN (text_len, sizeof ("hash") - 1)) == 0) { kv_parser->current_storage->cache.type = KVSTORAGE_TYPE_CACHE_HASH; } - else if (g_ascii_strncasecmp (text, "radix", - MIN (text_len, sizeof ("radix") - 1)) == 0) { + else if (g_ascii_strncasecmp (text, "radix", MIN (text_len, sizeof ("radix") - 1)) == 0) { kv_parser->current_storage->cache.type = KVSTORAGE_TYPE_CACHE_RADIX; } #ifdef WITH_JUDY - else if (g_ascii_strncasecmp (text, "judy", - MIN (text_len, sizeof ("judy") - 1)) == 0) { + else if (g_ascii_strncasecmp (text, "judy", MIN (text_len, sizeof ("judy") - 1)) == 0) { kv_parser->current_storage->cache.type = KVSTORAGE_TYPE_CACHE_JUDY; } #endif else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "invalid cache type: %*s", - (int)text_len, text); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "invalid cache type: %*s", (int)text_len, text); } kv_parser->state = KVSTORAGE_STATE_ERROR; } break; case KVSTORAGE_STATE_BACKEND_TYPE: - if (g_ascii_strncasecmp (text, "null", - MIN (text_len, sizeof ("null") - 1)) == 0) { - kv_parser->current_storage->backend.type = - KVSTORAGE_TYPE_BACKEND_NULL; + if (g_ascii_strncasecmp (text, "null", MIN (text_len, sizeof ("null") - 1)) == 0) { + kv_parser->current_storage->backend.type = KVSTORAGE_TYPE_BACKEND_NULL; } - else if (g_ascii_strncasecmp (text, "file", - MIN (text_len, sizeof ("file") - 1)) == 0) { - kv_parser->current_storage->backend.type = - KVSTORAGE_TYPE_BACKEND_FILE; + else if (g_ascii_strncasecmp (text, "file", MIN (text_len, sizeof ("file") - 1)) == 0) { + kv_parser->current_storage->backend.type = KVSTORAGE_TYPE_BACKEND_FILE; } #ifdef WITH_DB - else if (g_ascii_strncasecmp (text, "bdb", - MIN (text_len, sizeof ("bdb") - 1)) == 0) { - kv_parser->current_storage->backend.type = - KVSTORAGE_TYPE_BACKEND_BDB; + else if (g_ascii_strncasecmp (text, "bdb", MIN (text_len, sizeof ("bdb") - 1)) == 0) { + kv_parser->current_storage->backend.type = KVSTORAGE_TYPE_BACKEND_BDB; } #endif #ifdef WITH_SQLITE - else if (g_ascii_strncasecmp (text, "sqlite", - MIN (text_len, sizeof ("sqlite") - 1)) == 0) { - kv_parser->current_storage->backend.type = - KVSTORAGE_TYPE_BACKEND_SQLITE; + else if (g_ascii_strncasecmp (text, "sqlite", MIN (text_len, sizeof ("sqlite") - 1)) == 0) { + kv_parser->current_storage->backend.type = KVSTORAGE_TYPE_BACKEND_SQLITE; } #endif else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "invalid backend type: %*s", - (int)text_len, text); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "invalid backend type: %*s", (int)text_len, text); } kv_parser->state = KVSTORAGE_STATE_ERROR; } break; case KVSTORAGE_STATE_BACKEND_FILENAME: kv_parser->current_storage->backend.filename = g_malloc (text_len + 1); - rspamd_strlcpy (kv_parser->current_storage->backend.filename, - text, - text_len + 1); + rspamd_strlcpy (kv_parser->current_storage->backend.filename, text, text_len + 1); break; case KVSTORAGE_STATE_BACKEND_SYNC_OPS: - kv_parser->current_storage->backend.sync_ops = - rspamd_config_parse_limit (text, text_len); + kv_parser->current_storage->backend.sync_ops = rspamd_config_parse_limit (text, text_len); break; case KVSTORAGE_STATE_BACKEND_DO_FSYNC: - kv_parser->current_storage->backend.do_fsync = - rspamd_config_parse_flag (text); + kv_parser->current_storage->backend.do_fsync = rspamd_config_parse_flag (text); break; case KVSTORAGE_STATE_BACKEND_DO_REF: - kv_parser->current_storage->backend.do_ref = rspamd_config_parse_flag ( - text); + kv_parser->current_storage->backend.do_ref = rspamd_config_parse_flag (text); break; case KVSTORAGE_STATE_EXPIRE_TYPE: - if (g_ascii_strncasecmp (text, "lru", - MIN (text_len, sizeof ("lru") - 1)) == 0) { + if (g_ascii_strncasecmp (text, "lru", MIN (text_len, sizeof ("lru") - 1)) == 0) { kv_parser->current_storage->expire.type = KVSTORAGE_TYPE_EXPIRE_LRU; } else { if (*error == NULL) { - *error = g_error_new ( - xml_error_quark (), XML_EXTRA_ELEMENT, "invalid expire type: %*s", - (int)text_len, text); + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "invalid expire type: %*s", (int)text_len, text); } kv_parser->state = KVSTORAGE_STATE_ERROR; } @@ -519,12 +463,12 @@ kvstorage_xml_text (GMarkupParseContext *context, } /* Called on error, including one set by other - * methods in the vtable. The GError should not be freed. - */ +* methods in the vtable. The GError should not be freed. +*/ void -kvstorage_xml_error (GMarkupParseContext *context, - GError *error, - gpointer user_data) +kvstorage_xml_error (GMarkupParseContext *context, + GError *error, + gpointer user_data) { msg_err ("kvstorage xml parser error: %s", error->message); } @@ -535,11 +479,9 @@ kvstorage_xml_error (GMarkupParseContext *context, static void kvstorage_cleanup (gpointer ud) { - struct kvstorage_config_parser *kv_parser = ud; + struct kvstorage_config_parser *kv_parser = ud; - g_hash_table_insert (storages, - &kv_parser->current_storage->id, - kv_parser->current_storage); + g_hash_table_insert (storages, &kv_parser->current_storage->id, kv_parser->current_storage); kv_parser->state = KVSTORAGE_STATE_INIT; g_hash_table_foreach (storages, kvstorage_init_callback, NULL); kv_parser->current_storage = NULL; @@ -551,22 +493,16 @@ kvstorage_cleanup (gpointer ud) void init_kvstorage_config (void) { - GMarkupParser *parser; - struct kvstorage_config_parser *kv_parser; + GMarkupParser *parser; + struct kvstorage_config_parser *kv_parser; if (storages == NULL) { - storages = g_hash_table_new_full (g_int_hash, - g_int_equal, - NULL, - kvstorage_config_destroy); + storages = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, kvstorage_config_destroy); } else { /* Create new global table */ g_hash_table_destroy (storages); - storages = g_hash_table_new_full (g_int_hash, - g_int_equal, - NULL, - kvstorage_config_destroy); + storages = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, kvstorage_config_destroy); } /* Create and register subparser */ @@ -584,7 +520,7 @@ init_kvstorage_config (void) } /* Get configuration for kvstorage with specified ID */ -struct kvstorage_config * +struct kvstorage_config* get_kvstorage_config (gint id) { if (storages == NULL) { |