summaryrefslogtreecommitdiffstats
path: root/src/cfg_utils.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-01 19:45:35 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-01 19:45:35 +0400
commit6be82def714f297d54302953286223b4afb07208 (patch)
treeb156eea2e245efeb95702cc6bae6beaa02341440 /src/cfg_utils.c
parenta43a37453f497a919fb4a5358615d89f18706935 (diff)
downloadrspamd-6be82def714f297d54302953286223b4afb07208.tar.gz
rspamd-6be82def714f297d54302953286223b4afb07208.zip
* Add dumper to XML file (not all sections yet)
* Add checksum to config files * Some config parsing reorganizations: - post_load_config should be called after xml initialization - xml state machine is corrected to read main section variables - some linting is added to xml (checking of elements parity)
Diffstat (limited to 'src/cfg_utils.c')
-rw-r--r--src/cfg_utils.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index d2f75e11c..18677a1ca 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -230,6 +230,9 @@ free_config (struct config_file *cfg)
g_hash_table_remove_all (cfg->cfg_params);
g_hash_table_unref (cfg->cfg_params);
g_hash_table_destroy (cfg->classifiers_symbols);
+ if (cfg->checksum) {
+ g_free (cfg->checksum);
+ }
g_list_free (cfg->classifiers);
g_list_free (cfg->metrics_list);
memory_pool_delete (cfg->cfg_pool);
@@ -499,6 +502,37 @@ fill_cfg_params (struct config_file *cfg)
}
+gboolean
+get_config_checksum (struct config_file *cfg)
+{
+ int fd;
+ void *map;
+ struct stat st;
+
+ /* Compute checksum for config file that should be used by xml dumper */
+ if ((fd = open (cfg->cfg_name, O_RDONLY)) == -1) {
+ msg_err ("config file %s is no longer available, cannot calculate checksum");
+ return FALSE;
+ }
+ if (stat (cfg->cfg_name, &st) == -1) {
+ msg_err ("cannot stat %s: %s", cfg->cfg_name, strerror (errno));
+ return FALSE;
+ }
+
+ /* Now mmap this file to simplify reading process */
+ if ((map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+ msg_err ("cannot mmap %s: %s", cfg->cfg_name, strerror (errno));
+ close (fd);
+ return FALSE;
+ }
+ close (fd);
+
+ /* Get checksum for a file */
+ cfg->checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, map, st.st_size);
+ munmap (map, st.st_size);
+
+ return TRUE;
+}
/*
* Perform post load actions
*/
@@ -539,7 +573,7 @@ post_load_config (struct config_file *cfg)
cfg->metrics_list = g_list_prepend (cfg->metrics_list, def_metric);
g_hash_table_insert (cfg->metrics, DEFAULT_METRIC, def_metric);
}
-
+
}