From 0374d53d28b227e537768417b6b7f86ab1b5ca65 Mon Sep 17 00:00:00 2001 From: rburchell Date: Mon, 16 Feb 2009 15:05:46 +0000 Subject: Add 'w' and 'y' support to dotime(), also prevent a possible overflow - thanks to DP. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2093 5417fbe8-f217-4b02-8779-1006273d7864 --- src/config.c | 9 ++++++++- src/misc.c | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 6cc27aff9..42086cfae 100644 --- a/src/config.c +++ b/src/config.c @@ -1159,7 +1159,7 @@ int ServerConfig::Read(bool bail) if (ConfValue(config_data, static_cast(MultiValues[Index].tag), static_cast(MultiValues[Index].items[valuenum]), static_cast(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines)) { - int time = dotime(item.c_str()); + time_t time = dotime(item.c_str()); vl.push_back(ValueItem(time)); } else vl.push_back(ValueItem(0)); @@ -1515,6 +1515,13 @@ ValueItem::ValueItem(int value) : v("") v = n.str(); } +ValueItem::ValueItem(time_t value) : v("") +{ + std::stringstream n; + n << value; + v = n.str(); +} + ValueItem::ValueItem(bool value) : v("") { std::stringstream n; diff --git a/src/misc.c b/src/misc.c index 9de7cfdca..2acbb6087 100644 --- a/src/misc.c +++ b/src/misc.c @@ -325,9 +325,9 @@ int process_numlist(const char *numstr, int *count_ret, * of seconds), or an integer followed by one of these characters: * "s" (seconds), "m" (minutes), "h" (hours), or "d" (days). * @param s String to convert - * @return int + * @return time_t */ -int dotime(const char *s) +time_t dotime(const char *s) { int amount; @@ -346,6 +346,10 @@ int dotime(const char *s) return amount * 3600; case 'd': return amount * 86400; + case 'w': + return amount * 86400 * 7; + case 'y': + return amount * 86400 * 365; default: return -1; } -- cgit