]> jfr.im git - irc/rqf/shadowircd.git/commitdiff
[svn] Add mask_match(), like ircu mmatch().
authorjilles <redacted>
Sat, 14 Jul 2007 13:32:18 +0000 (06:32 -0700)
committerjilles <redacted>
Sat, 14 Jul 2007 13:32:18 +0000 (06:32 -0700)
This compares two masks and returns whether the "new" is
more specific than or equal to the "old". The difference
with match() is that a '?' in "old" does not match a '*' in
"new".

ChangeLog
include/irc_string.h
include/serno.h
src/match.c

index eb34f9f2c8ba9ef420c25204bacb8039e68c2c23..e8025be328a6680c63d1aee0fcf6da462cc434bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+jilles      2007/07/14 12:20:48 UTC    (20070714-3530)
+  Log:
+  add_id() for local client: do not collapse() the ban mask.
+  The code calling this already collapses the mask, and if
+  not, doing it here would cause a desync.
+  
+
+  Changes:     Modified:
+  +0 -2                trunk/src/chmode.c (File Modified) 
+
+
 nenolod     2007/07/07 08:08:23 UTC    (20070707-3528)
   Log:
   - fix dereference problems with not widely used polling engines
index d2bd104b9954402ccf6090c13ae65ec976c682ce..bfb69424c3f1a060ac476279209d260357c7092a 100644 (file)
@@ -21,7 +21,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: irc_string.h 678 2006-02-03 20:25:01Z jilles $
+ *  $Id: irc_string.h 3532 2007-07-14 13:32:18Z jilles $
  */
 
 #ifndef INCLUDED_irc_string_h
  * match - compare name with mask, mask may contain * and ? as wildcards
  * match - returns 1 on successful match, 0 otherwise
  *
+ * mask_match - compare one mask to another
  * match_esc - compare with support for escaping chars
  * match_cidr - compares u!h@addr with u!h@addr/cidr
  * match_ips - compares addr with addr/cidr in ascii form
  */
 extern int match(const char *mask, const char *name);
+extern int mask_match(const char *oldmask, const char *newmask);
 extern int match_esc(const char *mask, const char *name);
 extern int match_cidr(const char *mask, const char *name);
 extern int match_ips(const char *mask, const char *name);
index 8d7003b1587e3f09901e4ce531e8dbeb1df12c40..fc6dd76bdc78b9b1a9fee60229169dbf9231f962 100644 (file)
@@ -1 +1 @@
-#define SERNO "20070707-3528"
+#define SERNO "20070714-3530"
index ee77aeb8361a06d5e6c8c98271c778a16d0c89f1..7a9ad94aabb8f0804524c3ad29ec90cdf3aede44 100644 (file)
@@ -16,7 +16,7 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: match.c 3175 2007-02-01 00:02:35Z jilles $
+ * $Id: match.c 3532 2007-07-14 13:32:18Z jilles $
  *
  */
 #include "stdinc.h"
@@ -105,6 +105,79 @@ int match(const char *mask, const char *name)
        }
 }
 
+/** Check a mask against a mask.
+ * This test checks using traditional IRC wildcards only: '*' means
+ * match zero or more characters of any type; '?' means match exactly
+ * one character of any type.
+ * The difference between mask_match() and match() is that in mask_match()
+ * a '?' in mask does not match a '*' in name.
+ *
+ * @param[in] mask Existing wildcard-containing mask.
+ * @param[in] name New wildcard-containing mask.
+ * @return 1 if \a name is equal to or more specific than \a mask, 0 otherwise.
+ */
+int mask_match(const char *mask, const char *name)
+{
+       const char *m = mask, *n = name;
+       const char *m_tmp = mask, *n_tmp = name;
+       int star_p;
+
+       s_assert(mask != NULL);
+       s_assert(name != NULL);
+
+       for (;;)
+       {
+               switch (*m)
+               {
+                 case '\0':
+                         if (!*n)
+                                 return 1;
+                 backtrack:
+                         if (m_tmp == mask)
+                                 return 0;
+                         m = m_tmp;
+                         n = ++n_tmp;
+                         break;
+                 case '*':
+                 case '?':
+                         for (star_p = 0;; m++)
+                         {
+                                 if (*m == '*')
+                                         star_p = 1;
+                                 else if (*m == '?')
+                                 {
+                                         /* changed for mask_match() */
+                                         if (*n == '*' || !*n)
+                                                 goto backtrack;
+                                         n++;
+                                 }
+                                 else
+                                         break;
+                         }
+                         if (star_p)
+                         {
+                                 if (!*m)
+                                         return 1;
+                                 else
+                                 {
+                                         m_tmp = m;
+                                         for (n_tmp = n; *n && ToLower(*n) != ToLower(*m); n++);
+                                 }
+                         }
+                         /* and fall through */
+                 default:
+                         if (!*n)
+                                 return (*m != '\0' ? 0 : 1);
+                         if (ToLower(*m) != ToLower(*n))
+                                 goto backtrack;
+                         m++;
+                         n++;
+                         break;
+               }
+       }
+}
+
+
 /** Check a string against a mask.
  * This test checks using traditional IRC wildcards only: '*' means
  * match zero or more characters of any type; '?' means match exactly