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
|
|
|
|
*/
|
|
|
|
extern int match(const char *mask, const char *name);
|
2016-08-18 10:43:06 +02:00
|
|
|
extern int match_mask(const char *oldmask, const char *newmask);
|
2008-04-20 07:47:38 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
extern char *collapse(char *pattern);
|
|
|
|
extern char *collapse_esc(char *pattern);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* irccmp - case insensitive comparison of s1 and s2
|
|
|
|
*/
|
|
|
|
extern int irccmp(const char *s1, const char *s2);
|
|
|
|
/*
|
|
|
|
* ircncmp - counted case insensitive comparison of s1 and s2
|
|
|
|
*/
|
|
|
|
extern int ircncmp(const char *s1, const char *s2, int n);
|
|
|
|
|
2016-03-06 21:17:19 +01:00
|
|
|
/* Below are used for radix trees and the like */
|
|
|
|
static inline void irccasecanon(char *str)
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
2016-08-16 11:12:01 +02:00
|
|
|
*str = rfc1459::toupper(*str);
|
2016-03-06 21:17:19 +01:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void strcasecanon(char *str)
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
*str = toupper((unsigned char)*str);
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|
|
|
|
#endif // __cplusplus
|