]> jfr.im git - solanum.git/blame - include/match.h
Add documentation for extensions/filter
[solanum.git] / include / match.h
CommitLineData
4562c604
VY
1/*
2 * ircd-ratbox: A slightly useful ircd.
a4bf26dd 3 * match.h: A header for the ircd string functions.
4562c604
VY
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
4562c604
VY
23 */
24
25#ifndef INCLUDED_match_h
26#define INCLUDED_match_h
27
28#include "setup.h"
29#include "ircd_defs.h"
30
31/*
32 * match - compare name with mask, mask may contain * and ? as wildcards
33 * match - returns 1 on successful match, 0 otherwise
34 *
35 * mask_match - compare one mask to another
36 * match_esc - compare with support for escaping chars
37 * match_cidr - compares u!h@addr with u!h@addr/cidr
38 * match_ips - compares addr with addr/cidr in ascii form
39 */
40extern int match(const char *mask, const char *name);
41extern int mask_match(const char *oldmask, const char *newmask);
42extern int match_esc(const char *mask, const char *name);
43extern int match_cidr(const char *mask, const char *name);
44extern int match_ips(const char *mask, const char *name);
45
46/*
47 * comp_with_mask - compares to IP address
48 */
4b11f391
MU
49int comp_with_mask(void *addr, void *dest, unsigned int mask);
50int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, unsigned int mask);
4562c604
VY
51
52/*
55abcbb2 53 * collapse - collapse a string in place, converts multiple adjacent *'s
4562c604 54 * into a single *.
55abcbb2 55 * collapse - modifies the contents of pattern
4562c604
VY
56 *
57 * collapse_esc() - collapse with support for escaping chars
58 */
59extern char *collapse(char *pattern);
60extern char *collapse_esc(char *pattern);
61
a7d4a0ab
EK
62struct matchset {
63 char host[2][NAMELEN + USERLEN + HOSTLEN + 6];
64 char ip[2][NAMELEN + USERLEN + HOSTIPLEN + 6];
65};
66
67struct Client;
68
69void matchset_for_client(struct Client *who, struct matchset *m);
70bool client_matches_mask(struct Client *who, const char *mask);
71bool matches_mask(const struct matchset *m, const char *mask);
72
4562c604
VY
73/*
74 * irccmp - case insensitive comparison of s1 and s2
75 */
76extern int irccmp(const char *s1, const char *s2);
77/*
78 * ircncmp - counted case insensitive comparison of s1 and s2
79 */
80extern int ircncmp(const char *s1, const char *s2, int n);
81/*
82** canonize - reduce a string of duplicate list entries to contain
83** only the unique items.
84*/
85#ifdef NO_DUPE_MULTI_MESSAGES
86extern char *canonize(char *);
87#endif
88
89#define EmptyString(x) ((x) == NULL || *(x) == '\0')
90#define CheckEmpty(x) EmptyString(x) ? "" : x
91
92/*
93 * character macros
94 */
7e6b5384
EM
95extern const unsigned char irctolower_tab[];
96#define irctolower(c) (irctolower_tab[(unsigned char)(c)])
4562c604 97
7e6b5384
EM
98extern const unsigned char irctoupper_tab[];
99#define irctoupper(c) (irctoupper_tab[(unsigned char)(c)])
4562c604 100
f3b84221 101extern unsigned int CharAttrs[];
4562c604
VY
102
103#define PRINT_C 0x001
104#define CNTRL_C 0x002
105#define ALPHA_C 0x004
106#define PUNCT_C 0x008
107#define DIGIT_C 0x010
108#define SPACE_C 0x020
109#define NICK_C 0x040
110#define CHAN_C 0x080
111#define KWILD_C 0x100
112#define CHANPFX_C 0x200
113#define USER_C 0x400
114#define HOST_C 0x800
115#define NONEOS_C 0x1000
116#define SERV_C 0x2000
117#define EOL_C 0x4000
118#define MWILD_C 0x8000
119#define LET_C 0x10000 /* an actual letter */
120#define FCHAN_C 0x20000 /* a 'fake' channel char */
121
122#define IsHostChar(c) (CharAttrs[(unsigned char)(c)] & HOST_C)
123#define IsUserChar(c) (CharAttrs[(unsigned char)(c)] & USER_C)
124#define IsChanPrefix(c) (CharAttrs[(unsigned char)(c)] & CHANPFX_C)
125#define IsChanChar(c) (CharAttrs[(unsigned char)(c)] & CHAN_C)
126#define IsFakeChanChar(c) (CharAttrs[(unsigned char)(c)] & FCHAN_C)
127#define IsKWildChar(c) (CharAttrs[(unsigned char)(c)] & KWILD_C)
128#define IsMWildChar(c) (CharAttrs[(unsigned char)(c)] & MWILD_C)
129#define IsNickChar(c) (CharAttrs[(unsigned char)(c)] & NICK_C)
130#define IsServChar(c) (CharAttrs[(unsigned char)(c)] & (NICK_C | SERV_C))
131#define IsIdChar(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | LET_C))
132#define IsLetter(c) (CharAttrs[(unsigned char)(c)] & LET_C)
133#define IsCntrl(c) (CharAttrs[(unsigned char)(c)] & CNTRL_C)
134#define IsAlpha(c) (CharAttrs[(unsigned char)(c)] & ALPHA_C)
135#define IsSpace(c) (CharAttrs[(unsigned char)(c)] & SPACE_C)
136#define IsLower(c) (IsAlpha((c)) && ((unsigned char)(c) > 0x5f))
137#define IsUpper(c) (IsAlpha((c)) && ((unsigned char)(c) < 0x60))
138#define IsDigit(c) (CharAttrs[(unsigned char)(c)] & DIGIT_C)
139#define IsXDigit(c) (IsDigit(c) || ('a' <= (c) && (c) <= 'f') || \
140 ('A' <= (c) && (c) <= 'F'))
141#define IsAlNum(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | ALPHA_C))
142#define IsPrint(c) (CharAttrs[(unsigned char)(c)] & PRINT_C)
143#define IsAscii(c) ((unsigned char)(c) < 0x80)
144#define IsGraph(c) (IsPrint((c)) && ((unsigned char)(c) != 0x32))
145#define IsPunct(c) (!(CharAttrs[(unsigned char)(c)] & \
146 (CNTRL_C | ALPHA_C | DIGIT_C)))
147
148#define IsNonEOS(c) (CharAttrs[(unsigned char)(c)] & NONEOS_C)
149#define IsEol(c) (CharAttrs[(unsigned char)(c)] & EOL_C)
150
a4bf26dd
EM
151
152/* Below are used for radix trees and the like */
153static inline void irccasecanon(char *str)
154{
155 while (*str)
156 {
7e6b5384 157 *str = irctoupper(*str);
a4bf26dd
EM
158 str++;
159 }
160 return;
161}
162
163static inline void strcasecanon(char *str)
164{
165 while (*str)
166 {
167 *str = toupper((unsigned char)*str);
168 str++;
169 }
170 return;
171}
172
4562c604 173#endif /* INCLUDED_match_h */