X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/de9510bcaba3fc0377e09259f8b49921c421d269..a45e6ec72a6e2d09a5a777978fa653ff7c97db60:/src/tools.c?ds=sidebyside diff --git a/src/tools.c b/src/tools.c index a778207..b1e7b62 100644 --- a/src/tools.c +++ b/src/tools.c @@ -245,68 +245,69 @@ int mmatch(const char *old_mask, const char *new_mask) int match_ircglob(const char *text, const char *glob) { - unsigned int star_p, q_cnt; - while (1) { - switch (*glob) { - case 0: - return !*text; - case '\\': - glob++; - /* intentionally not tolower(...) so people can force - * capitalization, or we can overload \ in the future */ - if (*text++ != *glob++) - return 0; - break; - case '*': - case '?': - star_p = q_cnt = 0; - do { - if (*glob == '*') - star_p = 1; - else if (*glob == '?') - q_cnt++; - else - break; - glob++; - } while (1); - while (q_cnt) { - if (!*text++) - return 0; - q_cnt--; - } - if (star_p) { - /* if this is the last glob character, it will match any text */ - if (!*glob) - return 1; - /* Thanks to the loop above, we know that the next - * character is a normal character. So just look for - * the right character. - */ - for (; *text; text++) { - if ((tolower(*text) == tolower(*glob)) - && match_ircglob(text+1, glob+1)) { - return 1; - } - } - return 0; - } - /* if !star_p, fall through to normal character case, - * first checking to see if ?s carried us to the end */ - if (!*glob && !*text) + const char *m = glob, *n = text; + const char *m_tmp = glob, *n_tmp = text; + int star_p; + + for (;;) switch (*m) { + case '\0': + if (!*n) + return 1; + backtrack: + if (m_tmp == glob) + return 0; + m = m_tmp; + n = ++n_tmp; + break; + case '\\': + m++; + /* allow escaping to force capitalization */ + if (*m++ != *n++) + return 0; + break; + case '*': case '?': + for (star_p = 0; ; m++) { + if (*m == '*') + star_p = 1; + else if (*m == '?') { + if (!*n++) + goto backtrack; + } else break; + } + if (star_p) { + if (!*m) return 1; - default: - if (!*text) - return 0; - while (*text && *glob && *glob != '*' && *glob != '?' && *glob != '\\') { - if (tolower(*text++) != tolower(*glob++)) + else if (*m == '\\') { + m_tmp = ++m; + if (!*m) return 0; - } - } + for (n_tmp = n; *n && *n != *m; n++) ; + } else { + m_tmp = m; + for (n_tmp = n; *n && tolower(*n) != tolower(*m); n++) ; + } + } + /* and fall through */ + default: + if (!*n) + return *m == '\0'; + if (tolower(*m) != tolower(*n)) + goto backtrack; + m++; + n++; + break; } } extern const char *hidden_host_suffix; +/* Prevent *@* *@** *@*a* type masks, while allowing anything else. This is the best way iv found to detect + * a global matching mask; if it matches this string, it'll match almost anything :) */ +int is_overmask(char *mask) +{ + return(match_ircglob("abcdefghijklmnopqrstuv!frcmbghilnrtoasde@apdic.yfa.dsfsdaffsdasfdasfd.abcdefghijklmnopqrstuvwxyz.asdfasfdfsdsfdasfda.ydfbe", mask)); +} + int user_matches_glob(struct userNode *user, const char *orig_glob, int include_nick) { /* A new glob function, the old one had many false positives. @@ -588,7 +589,7 @@ TypeLength(char type) { switch (type) { case 'y': return 365*24*60*60; - case 'M': return 31*24*60*60; + case 'M': return 30*24*60*60; case 'w': return 7*24*60*60; case 'd': return 24*60*60; case 'h': return 60*60; @@ -598,6 +599,10 @@ TypeLength(char type) } } +/* This function is not entirely accurate as it does not take into account leap units + * or varying months. TODO: use proper dateadd functions to calculate real seconds + * from now for the units (eg 1M should be give us seconds till todays date next month) + */ unsigned long ParseInterval(const char *interval) { @@ -935,7 +940,7 @@ tools_cleanup(void) * multiple dilimiters, which can really * offset tokens and cause huge corruption * so this function will use strsep but - * act like strtok in that sence. + * act like strtok in that sense. */ char *mysep(char **sepstr, char *delim) {