]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Fix not propagating rehashes properly across the network.
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 8ced78ae8ac720d880f14d34cdba42da5144ddc7..6fb2a0ed0ee8d2cfd2947aa849b1eced4f283c4d 100644 (file)
@@ -156,10 +156,11 @@ void InspIRCd::ProcessColors(file_cache& input)
                special_chars("\\c", "\x03"), // Color
                special_chars("\\i", "\x1D"), // Italic
                special_chars("\\m", "\x11"), // Monospace
+               special_chars("\\r", "\x16"), // Reverse
                special_chars("\\s", "\x1E"), // Strikethrough
                special_chars("\\u", "\x1F"), // Underline
                special_chars("\\x", "\x0F"), // Reset
-               special_chars("\\", "")
+               special_chars("", "")
        };
 
        for(file_cache::iterator it = input.begin(), it_end = input.end(); it != it_end; it++)
@@ -348,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;
@@ -391,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);
@@ -477,8 +516,11 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
 // This is overridden by a higher-quality algorithm when SSL support is loaded
 void InspIRCd::DefaultGenRandom(char* output, size_t max)
 {
-       for(unsigned int i=0; i < max; i++)
-#ifdef _WIN32
+#if defined HAS_ARC4RANDOM_BUF
+       arc4random_buf(output, max);
+#else
+       for (unsigned int i = 0; i < max; ++i)
+# ifdef _WIN32
        {
                unsigned int uTemp;
                if(rand_s(&uTemp) != 0)
@@ -486,7 +528,8 @@ void InspIRCd::DefaultGenRandom(char* output, size_t max)
                else
                        output[i] = uTemp;
        }
-#else
+# else
                output[i] = random();
+# endif
 #endif
 }