diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-01 19:15:52 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-01 19:15:52 +0300 |
commit | 9a1ba2296dd152c8eb7d19a70de51721be836baa (patch) | |
tree | 46ba67bcd6e5833318b3ee5410b487fb9da59bb4 /src/util.c | |
parent | 06661f20cbb9d2f1d0f8a68fb7bc46dcd97c6276 (diff) | |
download | rspamd-9a1ba2296dd152c8eb7d19a70de51721be836baa.tar.gz rspamd-9a1ba2296dd152c8eb7d19a70de51721be836baa.zip |
* Add config routines for stat files
* Add function to resolve stat file name
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 90a536359..828c3d518 100644 --- a/src/util.c +++ b/src/util.c @@ -829,6 +829,65 @@ file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gcha writev (cfg->log_fd, out, sizeof (out) / sizeof (out[0])); } } + +/* Replace %r with rcpt value and %f with from value, new string is allocated in pool */ +char * +resolve_stat_filename (memory_pool_t *pool, char *pattern, char *rcpt, char *from) +{ + int need_to_format = 0, len = 0; + int rcptlen = strlen (rcpt); + int fromlen = strlen (from); + char *c = pattern, *new, *s; + + /* Calculate length */ + while (*c++) { + if (*c == '%' && *(c + 1) == 'r') { + len += rcptlen; + c += 2; + need_to_format = 1; + continue; + } + else if (*c == '%' && *(c + 1) == 'f') { + len += fromlen; + c += 2; + need_to_format = 1; + continue; + } + len ++; + } + + /* Do not allocate extra memory if we do not need to format string */ + if (!need_to_format) { + return pattern; + } + + /* Allocate new string */ + new = memory_pool_alloc (pool, len); + c = pattern; + s = new; + + /* Format string */ + while (*c ++) { + if (*c == '%' && *(c + 1) == 'r') { + c += 2; + memcpy (s, rcpt, rcptlen); + s += rcptlen; + continue; + } + else if (*c == '%' && *(c + 1) == 'r') { + c += 2; + memcpy (s, from, fromlen); + s += fromlen; + continue; + } + *s ++ = *c; + } + + *s = '\0'; + + return new; +} + /* * vi:ts=4 */ |