summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helperfuncs.cpp42
-rw-r--r--src/modules/m_chanhistory.cpp16
2 files changed, 41 insertions, 17 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 469c844be..6fb2a0ed0 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -349,9 +349,33 @@ void InspIRCd::CheckRoot()
#endif
}
-/** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array
- * lookups and pointer maths.
+/** A lookup table of values for multiplier characters used by
+ * InspIRCd::Duration(). In this lookup table, the indexes for
+ * the ascii values 'm' and 'M' have the value '60', the indexes
+ * for the ascii values 'D' and 'd' have a value of '86400', etc.
*/
+static const int duration_multi[] =
+{
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 86400, 1, 1, 1, 3600,
+ 1, 1, 1, 1, 60, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 604800, 1, 31557600, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 86400, 1, 1, 1, 3600, 1, 1, 1, 1, 60,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 604800, 1, 31557600,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+};
+
unsigned long InspIRCd::Duration(const std::string &str)
{
unsigned char multiplier = 0;
@@ -392,6 +416,20 @@ unsigned long InspIRCd::Duration(const std::string &str)
return total + subtotal;
}
+bool InspIRCd::IsValidDuration(const std::string& duration)
+{
+ for (std::string::const_iterator i = duration.begin(); i != duration.end(); ++i)
+ {
+ unsigned char c = *i;
+ if (((c >= '0') && (c <= '9')) || (c == 's') || (c == 'S'))
+ continue;
+
+ if (duration_multi[c] == 1)
+ return false;
+ }
+ return true;
+}
+
std::string InspIRCd::Format(va_list& vaList, const char* formatString)
{
static std::vector<char> formatBuffer(1024);
diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp
index 06840744b..08f4291c9 100644
--- a/src/modules/m_chanhistory.cpp
+++ b/src/modules/m_chanhistory.cpp
@@ -48,20 +48,6 @@ struct HistoryList
class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> >
{
- bool IsValidDuration(const std::string& duration)
- {
- for (std::string::const_iterator i = duration.begin(); i != duration.end(); ++i)
- {
- unsigned char c = *i;
- if (((c >= '0') && (c <= '9')) || (c == 's') || (c == 'S'))
- continue;
-
- if (duration_multi[c] == 1)
- return false;
- }
- return true;
- }
-
public:
unsigned int maxlines;
HistoryMode(Module* Creator)
@@ -79,7 +65,7 @@ class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> >
}
std::string duration(parameter, colon+1);
- if ((IS_LOCAL(source)) && ((duration.length() > 10) || (!IsValidDuration(duration))))
+ if ((IS_LOCAL(source)) && ((duration.length() > 10) || (!InspIRCd::IsValidDuration(duration))))
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
return MODEACTION_DENY;