]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * irc_string.h: A header for the ircd string functions. | |
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 | |
23 | * | |
24 | * $Id: irc_string.h 678 2006-02-03 20:25:01Z jilles $ | |
25 | */ | |
26 | ||
27 | #ifndef INCLUDED_irc_string_h | |
28 | #define INCLUDED_irc_string_h | |
29 | ||
30 | #include "setup.h" | |
31 | #include "ircd_defs.h" | |
32 | ||
33 | /* | |
34 | * match - compare name with mask, mask may contain * and ? as wildcards | |
35 | * match - returns 1 on successful match, 0 otherwise | |
36 | * | |
37 | * match_esc - compare with support for escaping chars | |
38 | * match_cidr - compares u!h@addr with u!h@addr/cidr | |
39 | * match_ips - compares addr with addr/cidr in ascii form | |
40 | */ | |
41 | extern int match(const char *mask, const char *name); | |
42 | extern int match_esc(const char *mask, const char *name); | |
43 | extern int match_cidr(const char *mask, const char *name); | |
44 | extern int match_ips(const char *mask, const char *name); | |
45 | ||
46 | /* | |
47 | * comp_with_mask - compares to IP address | |
48 | */ | |
49 | int comp_with_mask(void *addr, void *dest, u_int mask); | |
50 | int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, u_int mask); | |
51 | ||
52 | /* | |
53 | * collapse - collapse a string in place, converts multiple adjacent *'s | |
54 | * into a single *. | |
55 | * collapse - modifies the contents of pattern | |
56 | * | |
57 | * collapse_esc() - collapse with support for escaping chars | |
58 | */ | |
59 | extern char *collapse(char *pattern); | |
60 | extern char *collapse_esc(char *pattern); | |
61 | ||
62 | /* | |
63 | * irccmp - case insensitive comparison of s1 and s2 | |
64 | */ | |
65 | extern int irccmp(const char *s1, const char *s2); | |
66 | /* | |
67 | * ircncmp - counted case insensitive comparison of s1 and s2 | |
68 | */ | |
69 | extern int ircncmp(const char *s1, const char *s2, int n); | |
70 | /* | |
71 | ** canonize - reduce a string of duplicate list entries to contain | |
72 | ** only the unique items. | |
73 | */ | |
74 | #ifdef NO_DUPE_MULTI_MESSAGES | |
75 | extern char *canonize(char *); | |
76 | #endif | |
77 | /* | |
78 | * inetntoa - optimized inet_ntoa | |
79 | */ | |
80 | const char *inetntoa(const char *in_addr); | |
81 | ||
82 | /* | |
83 | * inetntop() | |
84 | * inetpton() | |
85 | * portable interfaces for inet_ntop() and inet_pton() | |
86 | */ | |
87 | const char *inetntop(int af, const void *src, char *dst, unsigned int size); | |
88 | int inetpton(int af, const char *src, void *dst); | |
89 | const char *inetntop_sock(struct sockaddr *src, char *dst, unsigned int size); | |
90 | int inetpton_sock(const char *src, struct sockaddr *dst); | |
91 | ||
92 | #ifndef HAVE_STRLCPY | |
93 | size_t strlcpy(char *dst, const char *src, size_t siz); | |
94 | #endif | |
95 | ||
96 | #ifndef HAVE_STRLCAT | |
97 | size_t strlcat(char *dst, const char *src, size_t siz); | |
98 | #endif | |
99 | ||
100 | #ifdef HAVE_STRDUP | |
101 | #define DupString(x,y) do { x = strdup(y); if(x == NULL) outofmemory(); } while(0) | |
102 | #else | |
103 | #define DupString(x,y) do { x = malloc(strlen(y) + 1); if(x == NULL) outofmemory(); strcpy(x, y); } while(0) | |
104 | #endif | |
105 | ||
106 | #ifdef HAVE_STRNDUP | |
107 | #define DupNString(x, y, len) do { x = strndup(y, len); if(x == NULL) outofmemory(); } while (0) | |
108 | #else | |
109 | #define DupNString(x, y, len) do { x = malloc(len+1); if(x == NULL) outofmemory(); strlcpy(x, y, len+1); } while(0) | |
110 | #endif | |
111 | ||
112 | /* | |
113 | * clean_string - cleanup control and high ascii characters | |
114 | * -Dianora | |
115 | */ | |
116 | char *clean_string(char *dest, const unsigned char *src, size_t len); | |
117 | ||
118 | /* | |
119 | * strip_colour - remove colour codes from a string | |
120 | * -asuffield (?) | |
121 | */ | |
122 | char *strip_colour(char *string); | |
123 | ||
124 | /* | |
125 | * strip_tabs - convert tabs to spaces | |
126 | * - jdc | |
127 | */ | |
128 | char *strip_tabs(char *dest, const unsigned char *src, size_t len); | |
129 | ||
130 | const char *myctime(time_t); | |
131 | ||
132 | #define EmptyString(x) (!(x) || (*(x) == '\0')) | |
133 | #define CheckEmpty(x) EmptyString(x) ? "" : x | |
134 | ||
135 | char *strtoken(char **save, char *str, const char *fs); | |
136 | ||
137 | unsigned char *ircd_base64_encode(const unsigned char *str, int length); | |
138 | unsigned char *ircd_base64_decode(const unsigned char *str, int length, int *ret); | |
139 | ||
140 | /* | |
141 | * character macros | |
142 | */ | |
143 | extern const unsigned char ToLowerTab[]; | |
144 | #define ToLower(c) (ToLowerTab[(unsigned char)(c)]) | |
145 | ||
146 | extern const unsigned char ToUpperTab[]; | |
147 | #define ToUpper(c) (ToUpperTab[(unsigned char)(c)]) | |
148 | ||
149 | extern const unsigned int CharAttrs[]; | |
150 | ||
151 | #define PRINT_C 0x001 | |
152 | #define CNTRL_C 0x002 | |
153 | #define ALPHA_C 0x004 | |
154 | #define PUNCT_C 0x008 | |
155 | #define DIGIT_C 0x010 | |
156 | #define SPACE_C 0x020 | |
157 | #define NICK_C 0x040 | |
158 | #define CHAN_C 0x080 | |
159 | #define KWILD_C 0x100 | |
160 | #define CHANPFX_C 0x200 | |
161 | #define USER_C 0x400 | |
162 | #define HOST_C 0x800 | |
163 | #define NONEOS_C 0x1000 | |
164 | #define SERV_C 0x2000 | |
165 | #define EOL_C 0x4000 | |
166 | #define MWILD_C 0x8000 | |
167 | #define LET_C 0x10000 /* an actual letter */ | |
168 | #define FCHAN_C 0x20000 /* a 'fake' channel char */ | |
169 | ||
170 | #define IsHostChar(c) (CharAttrs[(unsigned char)(c)] & HOST_C) | |
171 | #define IsUserChar(c) (CharAttrs[(unsigned char)(c)] & USER_C) | |
172 | #define IsChanPrefix(c) (CharAttrs[(unsigned char)(c)] & CHANPFX_C) | |
173 | #define IsChanChar(c) (CharAttrs[(unsigned char)(c)] & CHAN_C) | |
174 | #define IsFakeChanChar(c) (CharAttrs[(unsigned char)(c)] & FCHAN_C) | |
175 | #define IsKWildChar(c) (CharAttrs[(unsigned char)(c)] & KWILD_C) | |
176 | #define IsMWildChar(c) (CharAttrs[(unsigned char)(c)] & MWILD_C) | |
177 | #define IsNickChar(c) (CharAttrs[(unsigned char)(c)] & NICK_C) | |
178 | #define IsServChar(c) (CharAttrs[(unsigned char)(c)] & (NICK_C | SERV_C)) | |
179 | #define IsIdChar(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | LET_C)) | |
180 | #define IsLetter(c) (CharAttrs[(unsigned char)(c)] & LET_C) | |
181 | #define IsCntrl(c) (CharAttrs[(unsigned char)(c)] & CNTRL_C) | |
182 | #define IsAlpha(c) (CharAttrs[(unsigned char)(c)] & ALPHA_C) | |
183 | #define IsSpace(c) (CharAttrs[(unsigned char)(c)] & SPACE_C) | |
184 | #define IsLower(c) (IsAlpha((c)) && ((unsigned char)(c) > 0x5f)) | |
185 | #define IsUpper(c) (IsAlpha((c)) && ((unsigned char)(c) < 0x60)) | |
186 | #define IsDigit(c) (CharAttrs[(unsigned char)(c)] & DIGIT_C) | |
187 | #define IsXDigit(c) (IsDigit(c) || ('a' <= (c) && (c) <= 'f') || \ | |
188 | ('A' <= (c) && (c) <= 'F')) | |
189 | #define IsAlNum(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | ALPHA_C)) | |
190 | #define IsPrint(c) (CharAttrs[(unsigned char)(c)] & PRINT_C) | |
191 | #define IsAscii(c) ((unsigned char)(c) < 0x80) | |
192 | #define IsGraph(c) (IsPrint((c)) && ((unsigned char)(c) != 0x32)) | |
193 | #define IsPunct(c) (!(CharAttrs[(unsigned char)(c)] & \ | |
194 | (CNTRL_C | ALPHA_C | DIGIT_C))) | |
195 | ||
196 | #define IsNonEOS(c) (CharAttrs[(unsigned char)(c)] & NONEOS_C) | |
197 | #define IsEol(c) (CharAttrs[(unsigned char)(c)] & EOL_C) | |
198 | ||
199 | #endif /* INCLUDED_irc_string_h */ |