summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/m_ctrace.c2
-rw-r--r--contrib/m_ltrace.c8
-rw-r--r--contrib/m_operspy.c8
-rw-r--r--include/irc_string.h3
-rw-r--r--modules/core/m_message.c2
-rw-r--r--modules/core/m_server.c8
-rw-r--r--modules/core/m_squit.c2
-rw-r--r--modules/m_dline.c8
-rw-r--r--modules/m_encap.c2
-rw-r--r--modules/m_etrace.c2
-rw-r--r--modules/m_kline.c8
-rw-r--r--modules/m_links.c2
-rw-r--r--modules/m_locops.c2
-rw-r--r--modules/m_module.c2
-rw-r--r--modules/m_pong.c2
-rw-r--r--modules/m_resv.c8
-rw-r--r--modules/m_stats.c4
-rw-r--r--modules/m_testmask.c6
-rw-r--r--modules/m_trace.c10
-rw-r--r--modules/m_who.c14
-rw-r--r--modules/m_whois.c2
-rw-r--r--modules/m_xline.c8
-rw-r--r--src/channel.c4
-rw-r--r--src/client.c6
-rw-r--r--src/conf.c16
-rw-r--r--src/hostmask.c12
-rw-r--r--src/match.c123
-rw-r--r--src/s_serv.c14
-rw-r--r--src/send.c6
29 files changed, 150 insertions, 144 deletions
diff --git a/contrib/m_ctrace.c b/contrib/m_ctrace.c
index 13e0b0a..7b4d658 100644
--- a/contrib/m_ctrace.c
+++ b/contrib/m_ctrace.c
@@ -80,7 +80,7 @@ do_ctrace(struct Client *source_p, int parc, char *parv[])
struct Client *target_p = ptr->data;
class_name = get_client_class(&target_p->localClient->confs);
- if ((class_name != NULL) && match(class_looking_for, class_name))
+ if ((class_name != NULL) && !match(class_looking_for, class_name))
report_this_status(source_p, target_p);
}
diff --git a/contrib/m_ltrace.c b/contrib/m_ltrace.c
index 25f0716..afdf2f5 100644
--- a/contrib/m_ltrace.c
+++ b/contrib/m_ltrace.c
@@ -98,7 +98,7 @@ do_ltrace(struct Client *source_p, int parc, char *parv[])
{
ac2ptr = ptr->data;
- if (match(tname, ac2ptr->name))
+ if (!match(tname, ac2ptr->name))
break;
else
ac2ptr = NULL;
@@ -123,7 +123,7 @@ do_ltrace(struct Client *source_p, int parc, char *parv[])
source_p->name, source_p->username,
source_p->host, source_p->servptr->name);
- doall = (parv[1] && (parc > 1)) ? match(tname, me.name) : 1;
+ doall = (parv[1] && (parc > 1)) ? !match(tname, me.name) : 1;
wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
dow = wilds || doall;
@@ -170,7 +170,7 @@ do_ltrace(struct Client *source_p, int parc, char *parv[])
if (!HasUMode(target_p, UMODE_OPER))
continue;
- if (!doall && wilds && !match(tname, target_p->name))
+ if (!doall && wilds && match(tname, target_p->name))
continue;
if (!dow && irccmp(tname, target_p->name))
@@ -184,7 +184,7 @@ do_ltrace(struct Client *source_p, int parc, char *parv[])
{
target_p = ptr->data;
- if (!doall && wilds && !match(tname, target_p->name))
+ if (!doall && wilds && match(tname, target_p->name))
continue;
if (!dow && irccmp(tname, target_p->name))
continue;
diff --git a/contrib/m_operspy.c b/contrib/m_operspy.c
index 59356be..1d2d050 100644
--- a/contrib/m_operspy.c
+++ b/contrib/m_operspy.c
@@ -520,10 +520,10 @@ who_global(struct Client *source_p, char *mask, int server_oper)
continue;
if (!mask ||
- match(mask, target_p->name) || match(mask, target_p->username) ||
- match(mask, target_p->host) || match(mask, target_p->servptr->name) ||
- match(mask, target_p->info) ||
- (MyClient(target_p) && match(mask, target_p->sockhost)))
+ !match(mask, target_p->name) || !match(mask, target_p->username) ||
+ !match(mask, target_p->host) || !match(mask, target_p->servptr->name) ||
+ !match(mask, target_p->info) ||
+ (MyClient(target_p) && !match(mask, target_p->sockhost)))
{
if (dlink_list_length(&target_p->channel))
{
diff --git a/include/irc_string.h b/include/irc_string.h
index 13a57c9..dee67df 100644
--- a/include/irc_string.h
+++ b/include/irc_string.h
@@ -47,11 +47,8 @@ extern int match_chan(const char *, const char *);
* collapse - collapse a string in place, converts multiple adjacent *'s
* into a single *.
* collapse - modifies the contents of pattern
- *
- * collapse_esc() - collapse with support for escaping chars
*/
extern char *collapse(char *);
-extern char *collapse_esc(char *);
/*
* NOTE: The following functions are NOT the same as strcasecmp
diff --git a/modules/core/m_message.c b/modules/core/m_message.c
index e72126d..f84e1a3 100644
--- a/modules/core/m_message.c
+++ b/modules/core/m_message.c
@@ -888,7 +888,7 @@ find_userhost(char *user, char *host, int *count)
if (!IsClient(c2ptr)) /* something other than a client */
continue;
- if ((!host || match(host, c2ptr->host)) &&
+ if ((!host || !match(host, c2ptr->host)) &&
irccmp(user, c2ptr->username) == 0)
{
(*count)++;
diff --git a/modules/core/m_server.c b/modules/core/m_server.c
index a1eb5e7..39fecd5 100644
--- a/modules/core/m_server.c
+++ b/modules/core/m_server.c
@@ -274,14 +274,14 @@ ms_server(struct Client *client_p, struct Client *source_p,
* leaf. If so, close the link.
*/
DLINK_FOREACH(ptr, conf->leaf_list.head)
- if (match(ptr->data, name))
+ if (!match(ptr->data, name))
{
llined = 1;
break;
}
DLINK_FOREACH(ptr, conf->hub_list.head)
- if (match(ptr->data, name))
+ if (!match(ptr->data, name))
{
hlined = 1;
break;
@@ -471,14 +471,14 @@ ms_sid(struct Client *client_p, struct Client *source_p,
* leaf. If so, close the link.
*/
DLINK_FOREACH(ptr, conf->leaf_list.head)
- if (match(ptr->data, parv[1]))
+ if (!match(ptr->data, parv[1]))
{
llined = 1;
break;
}
DLINK_FOREACH(ptr, conf->hub_list.head)
- if (match(ptr->data, parv[1]))
+ if (!match(ptr->data, parv[1]))
{
hlined = 1;
break;
diff --git a/modules/core/m_squit.c b/modules/core/m_squit.c
index 7ba9b43..fb15b3c 100644
--- a/modules/core/m_squit.c
+++ b/modules/core/m_squit.c
@@ -71,7 +71,7 @@ mo_squit(struct Client *client_p, struct Client *source_p,
if (IsServer(p) || IsMe(p))
{
- if (match(server, p->name))
+ if (!match(server, p->name))
{
target_p = p;
break;
diff --git a/modules/m_dline.c b/modules/m_dline.c
index a3b520d..7fd3142 100644
--- a/modules/m_dline.c
+++ b/modules/m_dline.c
@@ -183,7 +183,7 @@ mo_dline(struct Client *client_p, struct Client *source_p,
dlhost, reason);
/* Allow ON to apply local kline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -296,7 +296,7 @@ ms_dline(struct Client *client_p, struct Client *source_p,
"DLINE %s %s %s :%s",
parv[1], parv[2], parv[3], parv[4]);
- if (!match(parv[1], me.name))
+ if (match(parv[1], me.name))
return;
tkline_time = valid_tkline(parv[2], TK_SECONDS);
@@ -430,7 +430,7 @@ mo_undline(struct Client *client_p, struct Client *source_p,
"UNDLINE %s %s", target_server, addr);
/* Allow ON to apply local unkline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -464,7 +464,7 @@ me_undline(struct Client *client_p, struct Client *source_p,
addr = parv[2];
- if (!IsClient(source_p) || !match(parv[1], me.name))
+ if (!IsClient(source_p) || match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
diff --git a/modules/m_encap.c b/modules/m_encap.c
index bb312d4..7d24112 100644
--- a/modules/m_encap.c
+++ b/modules/m_encap.c
@@ -82,7 +82,7 @@ ms_encap(struct Client *client_p, struct Client *source_p,
sendto_match_servs(source_p, parv[1], CAP_ENCAP,
"ENCAP %s", buffer);
- if (!match(parv[1], me.name))
+ if (match(parv[1], me.name))
return;
if ((mptr = find_command(parv[2])) == NULL)
diff --git a/modules/m_etrace.c b/modules/m_etrace.c
index b98d8e3..0cf5062 100644
--- a/modules/m_etrace.c
+++ b/modules/m_etrace.c
@@ -105,7 +105,7 @@ do_etrace(struct Client *source_p, int parc, char *parv[])
if (wilds)
{
- if (match(tname, target_p->name))
+ if (!match(tname, target_p->name))
report_this_status(source_p, target_p, full_etrace);
}
else
diff --git a/modules/m_kline.c b/modules/m_kline.c
index 4b9e573..05fd865 100644
--- a/modules/m_kline.c
+++ b/modules/m_kline.c
@@ -105,7 +105,7 @@ mo_kline(struct Client *client_p, struct Client *source_p,
user, host, reason);
/* Allow ON to apply local kline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -146,7 +146,7 @@ me_kline(struct Client *client_p, struct Client *source_p,
if (parc != 6 || EmptyString(parv[5]))
return;
- if (!match(parv[1], me.name))
+ if (match(parv[1], me.name))
return;
tkline_time = valid_tkline(parv[2], TK_SECONDS);
@@ -332,7 +332,7 @@ mo_unkline(struct Client *client_p,struct Client *source_p,
target_server, user, host);
/* Allow ON to apply local unkline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -377,7 +377,7 @@ me_unkline(struct Client *client_p, struct Client *source_p,
kuser = parv[2];
khost = parv[3];
- if (!IsClient(source_p) || !match(parv[1], me.name))
+ if (!IsClient(source_p) || match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
diff --git a/modules/m_links.c b/modules/m_links.c
index 0ad525b..631d1d1 100644
--- a/modules/m_links.c
+++ b/modules/m_links.c
@@ -62,7 +62,7 @@ do_links(struct Client *source_p, int parc, char *parv[])
if (!HasUMode(source_p, UMODE_OPER))
continue;
- if (!EmptyString(mask) && !match(mask, target_p->name))
+ if (!EmptyString(mask) && match(mask, target_p->name))
continue;
/*
diff --git a/modules/m_locops.c b/modules/m_locops.c
index 99fe736..fd40ef3 100644
--- a/modules/m_locops.c
+++ b/modules/m_locops.c
@@ -71,7 +71,7 @@ ms_locops(struct Client *client_p, struct Client *source_p,
sendto_server(client_p, CAP_CLUSTER, 0, "LOCOPS %s :%s",
parv[1], parv[2]);
- if (!IsClient(source_p) || !match(parv[1], me.name))
+ if (!IsClient(source_p) || match(parv[1], me.name))
return;
if (find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
diff --git a/modules/m_module.c b/modules/m_module.c
index 755810c..02a8567 100644
--- a/modules/m_module.c
+++ b/modules/m_module.c
@@ -217,7 +217,7 @@ mo_module(struct Client *client_p, struct Client *source_p,
{
modp = ptr->data;
- if (parc > 2 && !match(parv[2], modp->name))
+ if (!EmpyString(parv[2]) && match(parv[2], modp->name))
continue;
sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
diff --git a/modules/m_pong.c b/modules/m_pong.c
index c12a0a6..6d472f7 100644
--- a/modules/m_pong.c
+++ b/modules/m_pong.c
@@ -58,7 +58,7 @@ ms_pong(struct Client *client_p, struct Client *source_p,
* That being the case, we will route, but only for registered clients (a
* case can be made to allow them only from servers). -Shadowfax
*/
- if (!EmptyString(destination) && !match(destination, me.name) &&
+ if (!EmptyString(destination) && match(destination, me.name) &&
irccmp(destination, me.id))
{
if ((target_p = hash_find_client(destination)) ||
diff --git a/modules/m_resv.c b/modules/m_resv.c
index 1cfd0e4..785c068 100644
--- a/modules/m_resv.c
+++ b/modules/m_resv.c
@@ -74,7 +74,7 @@ mo_resv(struct Client *client_p, struct Client *source_p,
"RESV %s %s :%s",
target_server, resv, reason);
/* Allow ON to apply local resv as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -137,7 +137,7 @@ ms_resv(struct Client *client_p, struct Client *source_p,
"RESV %s %s :%s",
parv[1], parv[2], parv[3]);
- if (!IsClient(source_p) || !match(parv[1], me.name))
+ if (!IsClient(source_p) || match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
@@ -171,7 +171,7 @@ mo_unresv(struct Client *client_p, struct Client *source_p,
target_server, resv);
/* Allow ON to apply local unresv as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -196,7 +196,7 @@ ms_unresv(struct Client *client_p, struct Client *source_p,
"UNRESV %s %s",
parv[1], parv[2]);
- if (!IsClient(source_p) || !match(parv[1], me.name))
+ if (!IsClient(source_p) || match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
diff --git a/modules/m_stats.c b/modules/m_stats.c
index 952a685..e90d762 100644
--- a/modules/m_stats.c
+++ b/modules/m_stats.c
@@ -1174,7 +1174,7 @@ parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
if (!irccmp(name, from))
*doall = 2;
- else if (match(name, from))
+ else if (!match(name, from))
*doall = 1;
*wilds = has_wildcards(name);
@@ -1206,7 +1206,7 @@ stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
continue;
- if (!doall && wilds && !match(name, target_p->name))
+ if (!doall && wilds && match(name, target_p->name))
continue;
if (!(doall || wilds) && irccmp(name, target_p->name))
continue;
diff --git a/modules/m_testmask.c b/modules/m_testmask.c
index 20da840..78d02d5 100644
--- a/modules/m_testmask.c
+++ b/modules/m_testmask.c
@@ -89,11 +89,11 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
{
const struct Client *target_p = ptr->data;
- if (!IsClient(target_p) || !match(given_nick, target_p->name))
+ if (!IsClient(target_p) || match(given_nick, target_p->name))
continue;
- if (match(given_user, target_p->username))
- if (match(given_host, target_p->host) || match(given_host, target_p->sockhost))
+ if (!match(given_user, target_p->username))
+ if (!match(given_host, target_p->host) || !match(given_host, target_p->sockhost))
++count[!MyConnect(target_p)];
}
diff --git a/modules/m_trace.c b/modules/m_trace.c
index 6116a75..77982fa 100644
--- a/modules/m_trace.c
+++ b/modules/m_trace.c
@@ -120,7 +120,7 @@ mo_trace(struct Client *client_p, struct Client *source_p,
{
ac2ptr = ptr->data;
- if (match(tname, ac2ptr->name))
+ if (!match(tname, ac2ptr->name))
break;
else
ac2ptr = NULL;
@@ -190,7 +190,7 @@ do_actual_trace(struct Client *source_p, int parc, char *parv[])
source_p->name, source_p->username,
source_p->host, source_p->servptr->name);
- if (match(tname, me.name))
+ if (!match(tname, me.name))
doall = 1;
else if (!MyClient(source_p) && !strcmp(tname, me.id))
{
@@ -244,7 +244,7 @@ do_actual_trace(struct Client *source_p, int parc, char *parv[])
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
continue;
- if (!doall && wilds && !match(tname, target_p->name))
+ if (!doall && wilds && match(tname, target_p->name))
continue;
if (!dow && irccmp(tname, target_p->name))
continue;
@@ -256,7 +256,7 @@ do_actual_trace(struct Client *source_p, int parc, char *parv[])
{
target_p = ptr->data;
- if (!doall && wilds && !match(tname, target_p->name))
+ if (!doall && wilds && match(tname, target_p->name))
continue;
if (!dow && irccmp(tname, target_p->name))
continue;
@@ -269,7 +269,7 @@ do_actual_trace(struct Client *source_p, int parc, char *parv[])
{
target_p = ptr->data;
- if (!doall && wilds && !match(tname, target_p->name))
+ if (!doall && wilds && match(tname, target_p->name))
continue;
if (!dow && irccmp(tname, target_p->name))
continue;
diff --git a/modules/m_who.c b/modules/m_who.c
index fa20fcd..a030715 100644
--- a/modules/m_who.c
+++ b/modules/m_who.c
@@ -171,11 +171,11 @@ who_common_channel(struct Client *source_p, struct Channel *chptr,
assert(target_p->servptr != NULL);
if ((mask == NULL) ||
- match(mask, target_p->name) || match(mask, target_p->username) ||
- match(mask, target_p->host) ||
+ !match(mask, target_p->name) || !match(mask, target_p->username) ||
+ !match(mask, target_p->host) ||
((!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER)) &&
- match(mask, target_p->servptr->name)) ||
- match(mask, target_p->info))
+ !match(mask, target_p->servptr->name)) ||
+ !match(mask, target_p->info))
{
do_who(source_p, target_p, NULL, "");
@@ -250,9 +250,9 @@ who_global(struct Client *source_p, char *mask, int server_oper)
assert(target_p->servptr != NULL);
if (!mask ||
- match(mask, target_p->name) || match(mask, target_p->username) ||
- match(mask, target_p->host) || match(mask, target_p->servptr->name) ||
- match(mask, target_p->info))
+ !match(mask, target_p->name) || !match(mask, target_p->username) ||
+ !match(mask, target_p->host) || !match(mask, target_p->servptr->name) ||
+ !match(mask, target_p->info))
{
do_who(source_p, target_p, NULL, "");
diff --git a/modules/m_whois.c b/modules/m_whois.c
index 682fc10..601c148 100644
--- a/modules/m_whois.c
+++ b/modules/m_whois.c
@@ -212,7 +212,7 @@ global_whois(struct Client *source_p, const char *nick)
if (!IsClient(target_p))
continue;
- if (!match(nick, target_p->name))
+ if (match(nick, target_p->name))
continue;
assert(target_p->servptr != NULL);
diff --git a/modules/m_xline.c b/modules/m_xline.c
index 037fc17..a0fcdbc 100644
--- a/modules/m_xline.c
+++ b/modules/m_xline.c
@@ -100,7 +100,7 @@ mo_xline(struct Client *client_p, struct Client *source_p,
target_server, gecos, (int)tkline_time, reason);
/* Allow ON to apply local xline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -193,7 +193,7 @@ relay_xline(struct Client *source_p, char *parv[])
"XLINE %s %s %s :%s",
parv[1], parv[2], parv[3], parv[4]);
- if (!match(parv[1], me.name))
+ if (match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
@@ -248,7 +248,7 @@ mo_unxline(struct Client *client_p, struct Client *source_p,
"UNXLINE %s %s", target_server, gecos);
/* Allow ON to apply local unxline as well if it matches */
- if (!match(target_server, me.name))
+ if (match(target_server, me.name))
return;
}
else
@@ -277,7 +277,7 @@ ms_unxline(struct Client *client_p, struct Client *source_p,
sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
"UNXLINE %s %s", parv[1], parv[2]);
- if (!match(parv[1], me.name))
+ if (match(parv[1], me.name))
return;
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
diff --git a/src/channel.c b/src/channel.c
index 28eade6..e6b0e46 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -595,12 +595,12 @@ find_bmask(const struct Client *who, const dlink_list *const list)
{
const struct Ban *bp = ptr->data;
- if (match(bp->name, who->name) && match(bp->username, who->username))
+ if (!match(bp->name, who->name) && !match(bp->username, who->username))
{
switch (bp->type)
{
case HM_HOST:
- if (match(bp->host, who->host) || match(bp->host, who->sockhost))
+ if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
return 1;
break;
case HM_IPV4:
diff --git a/src/client.c b/src/client.c
index ac21ea6..0ec54a3 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1121,9 +1121,9 @@ find_accept(const char *nick, const char *user,
{
struct split_nuh_item *accept_p = ptr->data;
- if (cmpfunc(accept_p->nickptr, nick) == do_match &&
- cmpfunc(accept_p->userptr, user) == do_match &&
- cmpfunc(accept_p->hostptr, host) == do_match)
+ if (!cmpfunc(accept_p->nickptr, nick) &&
+ !cmpfunc(accept_p->userptr, user) &&
+ !cmpfunc(accept_p->hostptr, host))
return accept_p;
}
diff --git a/src/conf.c b/src/conf.c
index 7d04bd0..765c47a 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -969,7 +969,7 @@ attach_connect_block(struct Client *client_p, const char *name,
{
conf = ptr->data;
- if (match(conf->name, name) == 0 || match(conf->host, host) == 0)
+ if (match(conf->name, name) || match(conf->host, host))
continue;
attach_conf(client_p, conf);
@@ -1001,7 +1001,7 @@ find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
if (conf->type == type)
{
if (conf->name && (irccmp(conf->name, name) == 0 ||
- match(conf->name, name)))
+ !match(conf->name, name)))
return conf;
}
}
@@ -1113,7 +1113,7 @@ find_matching_name_conf(enum maskitem_type type, const char *name, const char *u
continue;
if (EmptyString(conf->user) || EmptyString(conf->host))
return conf;
- if (match(conf->user, user) && match(conf->host, host))
+ if (!match(conf->user, user) && !match(conf->host, host))
return conf;
}
}
@@ -1124,9 +1124,9 @@ find_matching_name_conf(enum maskitem_type type, const char *name, const char *u
{
conf = ptr->data;
- if ((name != NULL) && match(name, conf->name))
+ if ((name != NULL) && !match(name, conf->name))
return conf;
- else if ((host != NULL) && match(host, conf->host))
+ else if ((host != NULL) && !match(host, conf->host))
return conf;
}
break;
@@ -1174,7 +1174,7 @@ find_exact_name_conf(enum maskitem_type type, const struct Client *who, const ch
return (conf);
if (EmptyString(conf->user) || EmptyString(conf->host))
return (conf);
- if (match(conf->user, user) && match(conf->host, host))
+ if (!match(conf->user, user) && !match(conf->host, host))
return (conf);
}
}
@@ -1194,12 +1194,12 @@ find_exact_name_conf(enum maskitem_type type, const struct Client *who, const ch
return conf;
if (EmptyString(conf->user) || EmptyString(conf->host))
return NULL;
- if (match(conf->user, who->username))
+ if (!match(conf->user, who->username))
{
switch (conf->htype)
{
case HM_HOST:
- if (match(conf->host, who->host) || match(conf->host, who->sockhost))
+ if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
return conf;
break;
diff --git a/src/hostmask.c b/src/hostmask.c
index 35a9fc3..1e85857 100644
--- a/src/hostmask.c
+++ b/src/hostmask.c
@@ -480,7 +480,7 @@ find_conf_by_address(const char *name, struct irc_ssaddr *addr, unsigned int typ
arec->masktype == HM_IPV6 &&
match_ipv6(addr, &arec->Mask.ipa.addr,
arec->Mask.ipa.bits) &&
- (type & 0x1 || cmpfunc(arec->username, username) == do_match) &&
+ (type & 0x1 || !cmpfunc(arec->username, username)) &&
(IsNeedPassword(arec->conf) || arec->conf->passwd == NULL ||
match_conf_password(password, arec->conf)))
{
@@ -505,7 +505,7 @@ find_conf_by_address(const char *name, struct irc_ssaddr *addr, unsigned int typ
arec->masktype == HM_IPV4 &&
match_ipv4(addr, &arec->Mask.ipa.addr,
arec->Mask.ipa.bits) &&
- (type & 0x1 || cmpfunc(arec->username, username) == do_match) &&
+ (type & 0x1 || !cmpfunc(arec->username, username)) &&
(IsNeedPassword(arec->conf) || arec->conf->passwd == NULL ||
match_conf_password(password, arec->conf)))
{
@@ -529,8 +529,8 @@ find_conf_by_address(const char *name, struct irc_ssaddr *addr, unsigned int typ
if ((arec->type == (type & ~0x1)) &&
arec->precedence > hprecv &&
(arec->masktype == HM_HOST) &&
- cmpfunc(arec->Mask.hostname, name) == do_match &&
- (type & 0x1 || cmpfunc(arec->username, username) == do_match) &&
+ !cmpfunc(arec->Mask.hostname, name) &&
+ (type & 0x1 || !cmpfunc(arec->username, username)) &&
(IsNeedPassword(arec->conf) || arec->conf->passwd == NULL ||
match_conf_password(password, arec->conf)))
{
@@ -551,8 +551,8 @@ find_conf_by_address(const char *name, struct irc_ssaddr *addr, unsigned int typ
if (arec->type == (type & ~0x1) &&
arec->precedence > hprecv &&
arec->masktype == HM_HOST &&
- cmpfunc(arec->Mask.hostname, name) == do_match &&
- (type & 0x1 || cmpfunc(arec->username, username) == do_match) &&
+ !cmpfunc(arec->Mask.hostname, name) &&
+ (type & 0x1 || cmpfunc(arec->username, username)) &&
(IsNeedPassword(arec->conf) || arec->conf->passwd == NULL ||
match_conf_password(password, arec->conf)))
{
diff --git a/src/match.c b/src/match.c
index 4c4513e..714809b 100644
--- a/src/match.c
+++ b/src/match.c
@@ -65,13 +65,13 @@ match(const char *mask, const char *name)
if (!*m)
{
if (!*n)
- return 1;
- if (!ma)
return 0;
+ if (!ma)
+ return 1;
for (m--; (m > (const unsigned char *)mask) && (*m == '?'); m--)
;
if (*m == '*')
- return 1;
+ return 0;
m = ma;
n = ++na;
}
@@ -79,13 +79,13 @@ match(const char *mask, const char *name)
{
while (*m == '*')
m++;
- return *m == 0;
+ return *m != '\0';
}
if (ToLower(*m) != ToLower(*n) && *m != '?' && (*m != '#' || !IsDigit(*n)))
{
if (!ma)
- return 0;
+ return 1;
m = ma;
n = ++na;
}
@@ -93,7 +93,7 @@ match(const char *mask, const char *name)
m++, n++;
}
- return 0;
+ return 1;
}
/* match_esc()
@@ -125,13 +125,13 @@ match_esc(const char *mask, const char *name)
if (!*m)
{
if (!*n)
- return 1;
- if (!ma)
return 0;
+ if (!ma)
+ return 1;
for (m--; (m > (const unsigned char *)mask) && (*m == '?'); m--)
;
if (*m == '*')
- return 1;
+ return 0;
m = ma;
n = ++na;
}
@@ -139,18 +139,18 @@ match_esc(const char *mask, const char *name)
{
while (*m == '*')
m++;
- return *m == 0;
+ return *m != '\0';
}
if (*m != '?' && (*m != '#' || IsDigit(*n)))
{
if (*m == '\\')
if (!*++m)
- return 0;
+ return 1;
if (ToLower(*m) != ToLower(*n))
{
if (!ma)
- return 0;
+ return 1;
m = ma;
n = ++na;
}
@@ -161,7 +161,7 @@ match_esc(const char *mask, const char *name)
m++, n++;
}
- return 0;
+ return 1;
}
/* match_chan()
@@ -179,63 +179,72 @@ match_chan(const char *mask, const char *name)
++name, ++mask;
}
- return match_esc(mask, name);
+ return match_esc(mask, name) == 0;
}
-/* collapse()
+/*
+ * collapse()
+ * Collapse a pattern string into minimal components.
+ * This particular version is "in place", so that it changes the pattern
+ * which is to be reduced to a "minimal" size.
*
- * collapses a string containing multiple *'s.
+ * (C) Carlo Wood - 6 Oct 1998
+ * Speedup rewrite by Andrea Cocito, December 1998.
+ * Note that this new optimized algorithm can *only* work in place.
*/
-char *
-collapse(char *pattern)
-{
- char *p = pattern, *po = pattern;
- char c;
-
- if (p == NULL)
- return NULL;
-
- while ((c = *p++))
- {
- if (c != '*')
- *po++ = c;
- else if (*p != '*')
- *po++ = '*';
- }
- *po = 0;
-
- return pattern;
-}
-
-/* collapse_esc()
- *
- * The collapse() function with support for escaping characters
+/*! \brief Collapse a mask string to remove redundancies.
+ * Specifically, it replaces a sequence of '*' followed by additional
+ * '*' or '?' with the same number of '?'s as the input, followed by
+ * one '*'. This minimizes useless backtracking when matching later.
+ * \param mask Mask string to collapse.
+ * \return Pointer to the start of the string.
*/
char *
-collapse_esc(char *pattern)
+collapse(char *mask)
{
- char *p = pattern, *po = pattern;
- char c;
+ int star = 0;
+ char *m = mask;
+ char *b = NULL;
- if (p == NULL)
- return NULL;
-
- while ((c = *p++))
+ if (m)
{
- if (c != '*')
+ do
{
- *po++ = c;
- if (c == '\\' && *p)
- *po++ = *p++;
- }
- else if (*p != '*')
- *po++ = '*';
+ if ((*m == '*') && ((m[1] == '*') || (m[1] == '?')))
+ {
+ b = m;
+
+ do
+ {
+ if (*m == '*')
+ star = 1;
+ else
+ {
+ if (star && (*m != '?'))
+ {
+ *b++ = '*';
+ star = 0;
+ }
+
+ *b++ = *m;
+
+ if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
+ *b++ = *++m;
+ }
+ } while (*m++);
+
+ break;
+ }
+ else
+ {
+ if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
+ m++;
+ }
+ } while (*m++);
}
- *po = 0;
-
- return pattern;
+ return mask;
}
/*
diff --git a/src/s_serv.c b/src/s_serv.c
index b6ccd60..c83b54d 100644
--- a/src/s_serv.c
+++ b/src/s_serv.c
@@ -170,7 +170,7 @@ hunt_server(struct Client *client_p, struct Client *source_p, const char *comman
if (parc <= server || EmptyString(parv[server]))
return HUNTED_ISME;
- if (!strcmp(parv[server], me.id) || match(parv[server], me.name))
+ if (!strcmp(parv[server], me.id) || !match(parv[server], me.name))
return HUNTED_ISME;
/* These are to pickup matches that would cause the following
@@ -213,7 +213,7 @@ hunt_server(struct Client *client_p, struct Client *source_p, const char *comman
{
target_tmp = ptr->data;
- if (match(parv[server], target_tmp->name))
+ if (!match(parv[server], target_tmp->name))
{
if (target_tmp->from == source_p->from && !MyConnect(target_tmp))
continue;
@@ -238,7 +238,7 @@ hunt_server(struct Client *client_p, struct Client *source_p, const char *comman
if (IsMe(target_p) || MyClient(target_p))
return HUNTED_ISME;
- if (!match(target_p->name, parv[server]))
+ if (match(target_p->name, parv[server]))
parv[server] = target_p->name;
/* This is a little kludgy but should work... */
@@ -389,15 +389,15 @@ check_server(const char *name, struct Client *client_p)
{
conf = ptr->data;
- if (!match(name, conf->name))
+ if (match(name, conf->name))
continue;
error = -3;
/* XXX: Fix me for IPv6 */
/* XXX sockhost is the IPv4 ip as a string */
- if (match(conf->host, client_p->host) ||
- match(conf->host, client_p->sockhost))
+ if (!match(conf->host, client_p->host) ||
+ !match(conf->host, client_p->sockhost))
{
error = -2;
@@ -1470,7 +1470,7 @@ find_servconn_in_progress(const char *name)
cptr = ptr->data;
if (cptr && cptr->name[0])
- if (match(name, cptr->name))
+ if (!match(name, cptr->name))
return cptr;
}
diff --git a/src/send.c b/src/send.c
index 903f089..7a3a8cb 100644
--- a/src/send.c
+++ b/src/send.c
@@ -707,9 +707,9 @@ static int
match_it(const struct Client *one, const char *mask, int what)
{
if (what == MATCH_HOST)
- return match(mask, one->host);
+ return !match(mask, one->host);
- return match(mask, one->servptr->name);
+ return !match(mask, one->servptr->name);
}
/* sendto_match_butone()
@@ -820,7 +820,7 @@ sendto_match_servs(struct Client *source_p, const char *mask, int cap,
if (target_p->from->localClient->serial == current_serial)
continue;
- if (match(mask, target_p->name))
+ if (!match(mask, target_p->name))
{
/*
* if we set the serial here, then we'll never do a