ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/releases/8.2.21/src/irc_string.c
Revision: 2883
Committed: Mon Jan 20 18:17:57 2014 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/irc_string.c
File size: 6073 byte(s)
Log Message:
- irc_string.c:has_wildcards(): add support for character escaping

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * irc_string.c: IRC string functions.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "config.h"
26 #include "stdinc.h"
27 #include "irc_string.h"
28
29
30 int
31 has_wildcards(const char *str)
32 {
33 const unsigned char *p = (const unsigned char *)str;
34
35 for (; *p; ++p)
36 {
37 if (*p == '\\')
38 {
39 if (*++p == '\0')
40 return 0;
41 }
42 else if (IsMWildChar(*p))
43 return 1;
44 }
45
46 return 0;
47 }
48
49 /*
50 * myctime - This is like standard ctime()-function, but it zaps away
51 * the newline from the end of that string. Also, it takes
52 * the time value as parameter, instead of pointer to it.
53 * Note that it is necessary to copy the string to alternate
54 * buffer (who knows how ctime() implements it, maybe it statically
55 * has newline there and never 'refreshes' it -- zapping that
56 * might break things in other places...)
57 *
58 *
59 * Thu Nov 24 18:22:48 1986
60 */
61 const char *
62 myctime(time_t value)
63 {
64 static char buf[32];
65 char *p;
66
67 strlcpy(buf, ctime(&value), sizeof(buf));
68
69 if ((p = strchr(buf, '\n')) != NULL)
70 *p = '\0';
71 return buf;
72 }
73
74 /*
75 * strip_tabs(dst, src, length)
76 *
77 * Copies src to dst, while converting all \t (tabs) into spaces.
78 */
79 void
80 strip_tabs(char *dest, const char *src, size_t len)
81 {
82 char *d = dest;
83
84 /* Sanity check; we don't want anything nasty... */
85 assert(dest != NULL);
86 assert(src != NULL);
87 assert(len > 0);
88
89 for (; --len && *src; ++src)
90 *d++ = *src == '\t' ? ' ' : *src;
91
92 *d = '\0'; /* NUL terminate, thanks and goodbye */
93 }
94
95 /*
96 * strtoken - walk through a string of tokens, using a set of separators
97 * argv 9/90
98 *
99 */
100 #ifndef HAVE_STRTOK_R
101
102 char *
103 strtoken(char** save, char* str, const char* fs)
104 {
105 char* pos = *save; /* keep last position across calls */
106 char* tmp;
107
108 if (str)
109 pos = str; /* new string scan */
110
111 while (pos && *pos && strchr(fs, *pos) != NULL)
112 ++pos; /* skip leading separators */
113
114 if (!pos || !*pos)
115 return (pos = *save = NULL); /* string contains only sep's */
116
117 tmp = pos; /* now, keep position of the token */
118
119 while (*pos && strchr(fs, *pos) == NULL)
120 ++pos; /* skip content of the token */
121
122 if (*pos)
123 *pos++ = '\0'; /* remove first sep after the token */
124 else
125 pos = NULL; /* end of string */
126
127 *save = pos;
128 return tmp;
129 }
130 #endif /* !HAVE_STRTOK_R */
131
132 /* libio_basename()
133 *
134 * input - i.e. "/usr/local/ircd/modules/m_whois.so"
135 * output - i.e. "m_whois.so"
136 * side effects - this will be overwritten on subsequent calls
137 */
138 const char *
139 libio_basename(const char *path)
140 {
141 const char *s;
142
143 if ((s = strrchr(path, '/')) == NULL)
144 s = path;
145 else
146 s++;
147
148 return s;
149 }
150
151 /*
152 * strlcat and strlcpy were ripped from openssh 2.5.1p2
153 * They had the following Copyright info:
154 *
155 *
156 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
157 * All rights reserved.
158 *
159 * Redistribution and use in source and binary forms, with or without
160 * modification, are permitted provided that the following conditions
161 * are met:
162 * 1. Redistributions of source code must retain the above copyright
163 * notice, this list of conditions and the following disclaimer.
164 * 2. Redistributions in binary form must reproduce the above copyright
165 * notice, this list of conditions and the following disclaimer in the
166 * documentation and/or other materials provided with the distribution.
167 * 3. The name of the author may not be used to endorse or promote products
168 * derived from this software without specific prior written permission.
169 *
170 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
171 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
172 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
173 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
174 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
175 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
176 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
177 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
178 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
179 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180 */
181
182 #ifndef HAVE_STRLCAT
183 size_t
184 strlcat(char *dst, const char *src, size_t siz)
185 {
186 char *d = dst;
187 const char *s = src;
188 size_t n = siz, dlen;
189
190 while (n-- != 0 && *d != '\0')
191 d++;
192
193 dlen = d - dst;
194 n = siz - dlen;
195
196 if (n == 0)
197 return dlen + strlen(s);
198
199 while (*s != '\0')
200 {
201 if (n != 1)
202 {
203 *d++ = *s;
204 n--;
205 }
206
207 s++;
208 }
209
210 *d = '\0';
211 return dlen + (s - src); /* count does not include NUL */
212 }
213 #endif
214
215 #ifndef HAVE_STRLCPY
216 size_t
217 strlcpy(char *dst, const char *src, size_t siz)
218 {
219 char *d = dst;
220 const char *s = src;
221 size_t n = siz;
222
223 /* Copy as many bytes as will fit */
224 if (n != 0 && --n != 0)
225 {
226 do
227 {
228 if ((*d++ = *s++) == 0)
229 break;
230 } while (--n != 0);
231 }
232
233 /* Not enough room in dst, add NUL and traverse rest of src */
234 if (n == 0)
235 {
236 if (siz != 0)
237 *d = '\0'; /* NUL-terminate dst */
238 while (*s++)
239 ;
240 }
241
242 return s - src - 1; /* count does not include NUL */
243 }
244 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision