2008-04-20 07:47:38 +02:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
2016-03-06 21:17:19 +01:00
|
|
|
* match.h: A header for the ircd string functions.
|
2008-04-20 07:47:38 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2004 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-07-31 04:54:48 +02:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_MATCH_H
|
2008-04-20 07:47:38 +02:00
|
|
|
|
2016-08-18 10:51:49 +02:00
|
|
|
#define EmptyString(x) ((x) == NULL || *(x) == '\0')
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace ircd {
|
|
|
|
|
2008-04-20 07:47:38 +02:00
|
|
|
/*
|
|
|
|
* match - compare name with mask, mask may contain * and ? as wildcards
|
|
|
|
* match - returns 1 on successful match, 0 otherwise
|
|
|
|
*
|
2016-08-18 10:43:06 +02:00
|
|
|
* match_mask - like match() but a '?' in mask does not match a '*' in name
|
2008-04-20 07:47:38 +02:00
|
|
|
* 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
|
|
|
|
*/
|
2016-08-18 12:08:57 +02:00
|
|
|
bool match(const char *const &mask, const char *const &name);
|
|
|
|
bool match(const std::string &mask, const std::string &name);
|
|
|
|
bool match_mask(const char *const &mask, const char *const &name);
|
|
|
|
bool match_mask(const std::string &mask, const std::string &name);
|
|
|
|
bool match_cidr(const char *const &mask, const char *const &name);
|
|
|
|
bool match_cidr(const std::string &mask, const std::string &name);
|
|
|
|
bool match_ips(const char *const &mask, const char *const &name);
|
|
|
|
bool match_ips(const std::string &mask, const std::string &name);
|
|
|
|
int match_esc(const char *const &mask, const char *const &name);
|
|
|
|
int match_esc(const std::string &mask, const std::string &name);
|
2008-04-20 07:47:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* comp_with_mask - compares to IP address
|
|
|
|
*/
|
2016-03-24 00:11:42 +01:00
|
|
|
int comp_with_mask(void *addr, void *dest, unsigned int mask);
|
|
|
|
int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, unsigned int mask);
|
2008-04-20 07:47:38 +02:00
|
|
|
|
|
|
|
/*
|
2014-03-03 05:25:47 +01:00
|
|
|
* collapse - collapse a string in place, converts multiple adjacent *'s
|
2008-04-20 07:47:38 +02:00
|
|
|
* into a single *.
|
2014-03-03 05:25:47 +01:00
|
|
|
* collapse - modifies the contents of pattern
|
2008-04-20 07:47:38 +02:00
|
|
|
*
|
|
|
|
* collapse_esc() - collapse with support for escaping chars
|
|
|
|
*/
|
2016-08-18 12:08:57 +02:00
|
|
|
char *collapse(char *const &pattern);
|
|
|
|
char *collapse_esc(char *const &pattern);
|
2008-04-20 07:47:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* irccmp - case insensitive comparison of s1 and s2
|
|
|
|
*/
|
2016-08-18 12:08:57 +02:00
|
|
|
int irccmp(const char *const &s1, const char *const &s2);
|
|
|
|
int irccmp(const std::string &s1, const std::string &s2);
|
|
|
|
int ircncmp(const char *const &s1, const char *const &s2, size_t n);
|
2008-04-20 07:47:38 +02:00
|
|
|
|
2016-03-06 21:17:19 +01:00
|
|
|
/* Below are used for radix trees and the like */
|
2016-08-18 12:08:57 +02:00
|
|
|
inline void
|
|
|
|
irccasecanon(char *str)
|
2016-03-06 21:17:19 +01:00
|
|
|
{
|
2016-08-18 12:08:57 +02:00
|
|
|
for (; *str; ++str)
|
|
|
|
*str = rfc1459::toupper(*str);
|
2016-03-06 21:17:19 +01:00
|
|
|
}
|
|
|
|
|
2016-08-18 12:08:57 +02:00
|
|
|
inline void
|
|
|
|
strcasecanon(char *str)
|
2016-03-06 21:17:19 +01:00
|
|
|
{
|
2016-08-18 12:08:57 +02:00
|
|
|
for (; *str; ++str)
|
|
|
|
*str = toupper(uint8_t(*str));
|
2016-03-06 21:17:19 +01:00
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|
|
|
|
#endif // __cplusplus
|