projects
/
srvx.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add ircstrlower() function.
[srvx.git]
/
src
/
tools.c
diff --git
a/src/tools.c
b/src/tools.c
index 0da95dd62006c2273139afd5d1fdc6251c9e3608..10fb8d0fbec2ddcd986e343b6847f40953aa21ff 100644
(file)
--- a/
src/tools.c
+++ b/
src/tools.c
@@
-313,7
+313,7
@@
irc_pton(irc_in_addr_t *addr, unsigned char *bits, const char *input)
addr->in6[cpos + jj] = 0;
}
} else if (dot) {
addr->in6[cpos + jj] = 0;
}
} else if (dot) {
- u
nsigned in
t ip4;
+ u
int32_
t ip4;
pos = irc_pton_ip4(input, bits, &ip4);
if (pos) {
addr->in6[5] = htons(65535);
pos = irc_pton_ip4(input, bits, &ip4);
if (pos) {
addr->in6[5] = htons(65535);
@@
-385,25
+385,33
@@
irccasestr(const char *haystack, const char *needle) {
return NULL;
}
return NULL;
}
+char *
+ircstrlower(char *str) {
+ size_t ii;
+ for (ii = 0; str[ii] != '\0'; ++ii)
+ str[ii] = tolower(str[ii]);
+ return str;
+}
+
int
split_line(char *line, int irc_colon, int argv_size, char *argv[])
{
int argc = 0;
int n;
while (*line && (argc < argv_size)) {
int
split_line(char *line, int irc_colon, int argv_size, char *argv[])
{
int argc = 0;
int n;
while (*line && (argc < argv_size)) {
- while (*line == ' ')
+
while (*line == ' ')
*line++ = 0;
*line++ = 0;
- if (*line == ':' && irc_colon && argc > 0) {
- /* the rest is a single parameter */
- argv[argc++] = line + 1;
- break;
- }
+
if (*line == ':' && irc_colon && argc > 0) {
+
/* the rest is a single parameter */
+
argv[argc++] = line + 1;
+
break;
+
}
if (!*line)
break;
if (!*line)
break;
- argv[argc++] = line;
- if (argc >= argv_size)
+
argv[argc++] = line;
+
if (argc >= argv_size)
break;
break;
- while (*line != ' ' && *line)
+
while (*line != ' ' && *line)
line++;
}
#ifdef NDEBUG
line++;
}
#ifdef NDEBUG
@@
-430,7
+438,7
@@
int mmatch(const char *old_mask, const char *new_mask)
if (*m == '*')
{
while (*m == '*')
if (*m == '*')
{
while (*m == '*')
- m++;
+
m++;
wild = 1;
ma = m;
na = n;
wild = 1;
ma = m;
na = n;
@@
-439,25
+447,25
@@
int mmatch(const char *old_mask, const char *new_mask)
if (!*m)
{
if (!*n)
if (!*m)
{
if (!*n)
- return 0;
+
return 0;
for (m--; (m > old_mask) && (*m == '?'); m--)
for (m--; (m > old_mask) && (*m == '?'); m--)
- ;
+
;
if ((*m == '*') && (m > old_mask) && (m[-1] != '\\'))
if ((*m == '*') && (m > old_mask) && (m[-1] != '\\'))
- return 0;
+
return 0;
if (!wild)
if (!wild)
- return 1;
+
return 1;
m = ma;
/* Added to `mmatch' : Because '\?' and '\*' now is one character: */
if ((*na == '\\') && ((na[1] == '*') || (na[1] == '?')))
m = ma;
/* Added to `mmatch' : Because '\?' and '\*' now is one character: */
if ((*na == '\\') && ((na[1] == '*') || (na[1] == '?')))
- ++na;
+
++na;
n = ++na;
}
else if (!*n)
{
while (*m == '*')
n = ++na;
}
else if (!*n)
{
while (*m == '*')
- m++;
+
m++;
return (*m != 0);
}
if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
return (*m != 0);
}
if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?')))
@@
-494,23
+502,23
@@
int mmatch(const char *old_mask, const char *new_mask)
* cases upfront (which took 2 hours!)).
*/
if ((*m == '*' && !mq) ||
* cases upfront (which took 2 hours!)).
*/
if ((*m == '*' && !mq) ||
- ((!mq || nq) && tolower(*m) == tolower(*n)) ||
- (*m == '?' && !mq && (*n != '*' || nq)))
+
((!mq || nq) && tolower(*m) == tolower(*n)) ||
+
(*m == '?' && !mq && (*n != '*' || nq)))
{
if (*m)
{
if (*m)
- m++;
+
m++;
if (*n)
if (*n)
- n++;
+
n++;
}
else
{
if (!wild)
}
else
{
if (!wild)
- return 1;
+
return 1;
m = ma;
/* Added to `mmatch' : Because '\?' and '\*' now is one character: */
if ((*na == '\\') && ((na[1] == '*') || (na[1] == '?')))
m = ma;
/* Added to `mmatch' : Because '\?' and '\*' now is one character: */
if ((*na == '\\') && ((na[1] == '*') || (na[1] == '?')))
- ++na;
+
++na;
n = ++na;
}
n = ++na;
}
@@
-533,6
+541,8
@@
match_ircglob(const char *text, const char *glob)
return 0;
m = m_tmp;
n = ++n_tmp;
return 0;
m = m_tmp;
n = ++n_tmp;
+ if (!*n)
+ return 0;
break;
case '\\':
m++;
break;
case '\\':
m++;
@@
-703,20
+713,20
@@
sanitize_ircmask(char *input)
mask = input;
while(*input++ != '!')
{
mask = input;
while(*input++ != '!')
{
- length++;
+
length++;
}
if(length > NICKLEN)
{
}
if(length > NICKLEN)
{
- mask += NICKLEN;
- *mask++ = '!';
+
mask += NICKLEN;
+
*mask++ = '!';
- /* This flag is used to indicate following parts should
- be shifted. */
- flag = 1;
+
/* This flag is used to indicate following parts should
+
be shifted. */
+
flag = 1;
}
else
{
}
else
{
- mask = input;
+
mask = input;
}
/* The ident and host must be truncated at the beginning and
}
/* The ident and host must be truncated at the beginning and
@@
-725,46
+735,46
@@
sanitize_ircmask(char *input)
start = input;
while(*input++ != '@')
{
start = input;
while(*input++ != '@')
{
- length++;
+
length++;
}
if(length > USERLEN || flag)
{
}
if(length > USERLEN || flag)
{
- if(length > USERLEN)
- {
- start = input - USERLEN;
- *mask++ = '*';
- }
- while(*start != '@')
- {
- *mask++ = *start++;
- }
- *mask++ = '@';
-
- flag = 1;
+
if(length > USERLEN)
+
{
+
start = input - USERLEN;
+
*mask++ = '*';
+
}
+
while(*start != '@')
+
{
+
*mask++ = *start++;
+
}
+
*mask++ = '@';
+
+
flag = 1;
}
else
{
}
else
{
- mask = input;
+
mask = input;
}
length = 0;
start = input;
while(*input++)
{
}
length = 0;
start = input;
while(*input++)
{
- length++;
+
length++;
}
if(length > HOSTLEN || flag)
{
}
if(length > HOSTLEN || flag)
{
- if(length > HOSTLEN)
- {
- start = input - HOSTLEN;
- *mask++ = '*';
- }
- while(*start)
- {
- *mask++ = *start++;
- }
- *mask = '\0';
+
if(length > HOSTLEN)
+
{
+
start = input - HOSTLEN;
+
*mask++ = '*';
+
}
+
while(*start)
+
{
+
*mask++ = *start++;
+
}
+
*mask = '\0';
}
return output;
}
return output;
@@
-794,12
+804,14
@@
ParseInterval(const char *interval)
/* process the string, resetting the count if we find a unit character */
while ((c = *interval++)) {
/* process the string, resetting the count if we find a unit character */
while ((c = *interval++)) {
- if (isdigit((int)c)) {
- partial = partial*10 + c - '0';
- } else {
- seconds += TypeLength(c) * partial;
- partial = 0;
- }
+ if (isdigit((int)c)) {
+ partial = partial*10 + c - '0';
+ } else if (strchr("yMwdhms", c)) {
+ seconds += TypeLength(c) * partial;
+ partial = 0;
+ } else {
+ return 0;
+ }
}
/* assume the last chunk is seconds (the normal case) */
return seconds + partial;
}
/* assume the last chunk is seconds (the normal case) */
return seconds + partial;
@@
-851,12
+863,12
@@
unsplit_string(char *set[], unsigned int max, char *dest)
}
char *
}
char *
-intervalString(char *output,
time_t
interval, struct handle_info *hi)
+intervalString(char *output,
unsigned long
interval, struct handle_info *hi)
{
static const struct {
const char *msg_single;
const char *msg_plural;
{
static const struct {
const char *msg_single;
const char *msg_plural;
- long length;
+
unsigned
long length;
} unit[] = {
{ "MSG_YEAR", "MSG_YEARS", 365 * 24 * 60 * 60 },
{ "MSG_WEEK", "MSG_WEEKS", 7 * 24 * 60 * 60 },
} unit[] = {
{ "MSG_YEAR", "MSG_YEARS", 365 * 24 * 60 * 60 },
{ "MSG_WEEK", "MSG_WEEKS", 7 * 24 * 60 * 60 },
@@
-873,13
+885,13
@@
intervalString(char *output, time_t interval, struct handle_info *hi)
if(!interval)
{
msg = language_find_message(lang, "MSG_0_SECONDS");
if(!interval)
{
msg = language_find_message(lang, "MSG_0_SECONDS");
- return strcpy(output, msg);
+
return strcpy(output, msg);
}
for (type = 0, words = pos = 0;
interval && (words < 2) && (type < ArrayLength(unit));
type++) {
}
for (type = 0, words = pos = 0;
interval && (words < 2) && (type < ArrayLength(unit));
type++) {
- if (interval < unit[type].length)
+
if (interval < unit[type].length)
continue;
count = interval / unit[type].length;
interval = interval % unit[type].length;
continue;
count = interval / unit[type].length;
interval = interval % unit[type].length;