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