]>
jfr.im git - irc/evilnet/x3.git/blob - src/tools.c
1 /* tools.c - miscellaneous utility functions
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * srvx is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 #ifdef HAVE_SYS_SOCKET_H
30 #include <sys/socket.h>
32 #ifdef HAVE_ARPA_INET_H
33 #include <arpa/inet.h>
37 #define NUMNICKBASE (1 << NUMNICKLOG)
38 #define NUMNICKMASK (NUMNICKBASE - 1)
40 /* Yes, P10's encoding here is almost-but-not-quite MIME Base64. Yay
41 * for gratuitous incompatibilities. */
42 static const char convert2y
[256] = {
43 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
44 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
45 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
46 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']'
49 static const unsigned char convert2n
[256] = {
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 52,53,54,55,56,57,58,59,60,61, 0, 0, 0, 0, 0, 0,
54 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
55 15,16,17,18,19,20,21,22,23,24,25,62, 0,63, 0, 0,
56 0,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
57 41,42,43,44,45,46,47,48,49,50,51, 0, 0, 0, 0, 0
61 base64toint(const char* s
, int count
)
65 i
= (i
<< NUMNICKLOG
) + convert2n
[(unsigned char)*s
++];
71 const char* inttobase64(char* buf
, unsigned int v
, unsigned int count
)
75 buf
[--count
] = convert2y
[(unsigned char)(v
& NUMNICKMASK
)];
81 static char irc_tolower
[256];
83 #define tolower(X) irc_tolower[(unsigned char)(X)]
86 irccasecmp(const char *stra
, const char *strb
) {
87 while (*stra
&& (tolower(*stra
) == tolower(*strb
)))
89 return tolower(*stra
) - tolower(*strb
);
93 ircncasecmp(const char *stra
, const char *strb
, unsigned int len
) {
95 while (*stra
&& (tolower(*stra
) == tolower(*strb
)) && len
)
96 stra
++, strb
++, len
--;
97 return tolower(*stra
) - tolower(*strb
);
101 irccasestr(const char *haystack
, const char *needle
) {
102 unsigned int hay_len
= strlen(haystack
), needle_len
= strlen(needle
), pos
;
103 if (hay_len
< needle_len
)
105 for (pos
=0; pos
<hay_len
+1-needle_len
; ++pos
) {
106 if ((tolower(haystack
[pos
]) == tolower(*needle
))
107 && !ircncasecmp(haystack
+pos
, needle
, needle_len
))
114 split_line(char *line
, int irc_colon
, int argv_size
, char *argv
[])
118 while (*line
&& (argc
< argv_size
)) {
121 if (*line
== ':' && irc_colon
&& argc
> 0) {
122 /* the rest is a single parameter */
123 argv
[argc
++] = line
+ 1;
129 if (argc
>= argv_size
)
131 while (*line
!= ' ' && *line
)
137 for (n
=argc
; n
<argv_size
; n
++)
138 argv
[n
] = (char*)0xFEEDBEEF;
143 /* This is ircu's mmatch() function, from match.c. */
144 int mmatch(const char *old_mask
, const char *new_mask
)
146 register const char *m
= old_mask
;
147 register const char *n
= new_mask
;
168 for (m
--; (m
> old_mask
) && (*m
== '?'); m
--)
170 if ((*m
== '*') && (m
> old_mask
) && (m
[-1] != '\\'))
176 /* Added to `mmatch' : Because '\?' and '\*' now is one character: */
177 if ((*na
== '\\') && ((na
[1] == '*') || (na
[1] == '?')))
188 if ((*m
== '\\') && ((m
[1] == '*') || (m
[1] == '?')))
196 /* Added to `mmatch' : Because '\?' and '\*' now is one character: */
197 if ((*n
== '\\') && ((n
[1] == '*') || (n
[1] == '?')))
206 * This `if' has been changed compared to match() to do the following:
208 * old (m) new (n) boolean expression
209 * * any (*m == '*' && !mq) ||
210 * ? any except '*' (*m == '?' && !mq && (*n != '*' || nq)) ||
211 * any except * or ? same as m (!((*m == '*' || *m == '?') && !mq) &&
212 * toLower(*m) == toLower(*n) &&
213 * !((mq && !nq) || (!mq && nq)))
215 * Here `any' also includes \* and \? !
217 * After reworking the boolean expressions, we get:
218 * (Optimized to use boolean shortcircuits, with most frequently occuring
219 * cases upfront (which took 2 hours!)).
221 if ((*m
== '*' && !mq
) ||
222 ((!mq
|| nq
) && tolower(*m
) == tolower(*n
)) ||
223 (*m
== '?' && !mq
&& (*n
!= '*' || nq
)))
236 /* Added to `mmatch' : Because '\?' and '\*' now is one character: */
237 if ((*na
== '\\') && ((na
[1] == '*') || (na
[1] == '?')))
246 match_ircglob(const char *text
, const char *glob
)
248 const char *m
= glob
, *n
= text
;
249 const char *m_tmp
= glob
, *n_tmp
= text
;
252 for (;;) switch (*m
) {
264 /* allow escaping to force capitalization */
269 for (star_p
= 0; ; m
++) {
272 else if (*m
== '?') {
280 else if (*m
== '\\') {
284 for (n_tmp
= n
; *n
&& *n
!= *m
; n
++) ;
287 for (n_tmp
= n
; *n
&& tolower(*n
) != tolower(*m
); n
++) ;
290 /* and fall through */
294 if (tolower(*m
) != tolower(*n
))
302 extern const char *hidden_host_suffix
;
304 /* Prevent *@* *@** *@*a* type masks, while allowing anything else. This is the best way iv found to detect
305 * a global matching mask; if it matches this string, it'll match almost anything :) */
306 int is_overmask(char *mask
)
308 return(match_ircglob("abcdefghijklmnopqrstuv!frcmbghilnrtoasde@apdic.yfa.dsfsdaffsdasfdasfd.abcdefghijklmnopqrstuvwxyz.asdfasfdfsdsfdasfda.ydfbe", mask
));
311 int user_matches_glob(struct userNode
*user
, const char *orig_glob
, int include_nick
)
313 /* A new glob function, the old one had many false positives.
314 * look at IsSetHost(user) etc and include_nick, build a nick!user@host string
315 * from user and save it in a variable. Compare with match_ircglob() and
316 * return the results. Match any of the possible user@host combos (ugh) -Rubin
320 char *matchstr_full
= NULL
;
322 if(IsSetHost(user
)) /* S: line sethosts */
324 /* Grab host and user from sethost instead of real host */
326 buff
= alloca(strlen(user
->sethost
) + 1);
327 strcpy(buff
, user
->sethost
);
328 matchstr_user
= mysep(&buff
, "@");
329 matchstr_host
= mysep(&buff
, "@");
331 matchstr_full
= alloca(strlen(user
->nick
) + strlen(matchstr_user
) + strlen(matchstr_host
) + 4);
333 sprintf(matchstr_full
, "%s!%s@%s", user
->nick
, matchstr_user
, matchstr_host
);
335 sprintf(matchstr_full
, "%s@%s", matchstr_user
, matchstr_host
);
336 if(match_ircglob(matchstr_full
, orig_glob
))
339 else if(IsFakeHost(user
)) /* Fakehost */
341 matchstr_full
= alloca(strlen(user
->nick
) + strlen(user
->ident
) + strlen(user
->fakehost
) + 4);
343 sprintf(matchstr_full
, "%s!%s@%s", user
->nick
, user
->ident
, user
->fakehost
);
345 sprintf(matchstr_full
, "%s@%s", user
->ident
, user
->fakehost
);
346 if(match_ircglob(matchstr_full
, orig_glob
))
349 else if(hidden_host_suffix
&& user
->handle_info
) /* name.users.network.org host */
351 matchstr_host
= alloca(strlen(user
->handle_info
->handle
) + strlen(hidden_host_suffix
) + 2);
352 sprintf(matchstr_host
, "%s.%s", user
->handle_info
->handle
, hidden_host_suffix
);
353 matchstr_user
= user
->ident
;
355 matchstr_full
= alloca(strlen(user
->nick
) + strlen(user
->ident
) + strlen(matchstr_host
) + 4);
357 sprintf(matchstr_full
, "%s!%s@%s", user
->nick
, user
->ident
, matchstr_host
);
359 sprintf(matchstr_full
, "%s@%s", user
->ident
, matchstr_host
);
360 if(match_ircglob(matchstr_full
, orig_glob
))
364 /* Check normal hostname */
365 matchstr_full
= alloca(strlen(user
->nick
) + strlen(user
->ident
) + strlen(user
->hostname
) + 4);
367 sprintf(matchstr_full
, "%s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
369 sprintf(matchstr_full
, "%s@%s", user
->ident
, user
->hostname
);
370 if(match_ircglob(matchstr_full
, orig_glob
))
373 /* Check IP hostname (could skip this if same as above?)*/
374 matchstr_host
= inet_ntoa(user
->ip
);
375 matchstr_full
= alloca(strlen(user
->nick
) + strlen(user
->ident
) + strlen(matchstr_host
) + 4);
377 sprintf(matchstr_full
, "%s!%s@%s", user
->nick
, user
->ident
, matchstr_host
);
379 sprintf(matchstr_full
, "%s@%s", user
->ident
, matchstr_host
);
380 if(match_ircglob(matchstr_full
, orig_glob
))
383 return(0); /* Didnt match anything */
387 user_matches_glob_broken(struct userNode
*user
, const char *orig_glob
, int include_nick
)
390 char *setident
= NULL
, *sethostname
= NULL
; // sethost - reed/apples
392 /* Make a writable copy of the glob */
393 glob
= alloca(strlen(orig_glob
)+1);
394 strcpy(glob
, orig_glob
);
395 /* Check the nick, if it's present */
397 if (!(marker
= strchr(glob
, '!'))) {
398 log_module(MAIN_LOG
, LOG_ERROR
, "user_matches_glob(\"%s\", \"%s\", %d) called, and glob doesn't include a '!'", user
->nick
, orig_glob
, include_nick
);
402 if (!match_ircglob(user
->nick
, glob
)) return 0;
405 /* Check the ident */
406 if (!(marker
= strchr(glob
, '@'))) {
407 log_module(MAIN_LOG
, LOG_ERROR
, "user_matches_glob(\"%s\", \"%s\", %d) called, and glob doesn't include an '@'", user
->nick
, orig_glob
, include_nick
);
412 // sethost - reed/apples
413 if (IsSetHost(user
)) {
414 setident
= alloca(strcspn(user
->sethost
, "@")+2);
415 safestrncpy(setident
, user
->sethost
, strcspn(user
->sethost
, "@")+1);
416 sethostname
= strchr(user
->sethost
, '@') + 1;
419 if (!match_ircglob(user
->ident
, glob
) && (IsSetHost(user
) && !match_ircglob(setident
, glob
)))
422 /* If it might be an IP glob, test that. */
423 if (!glob
[strspn(glob
, "0123456789./*?")]
424 && match_ircglob(inet_ntoa(user
->ip
), glob
))
426 /* Check for a fakehost match. */
427 if (IsFakeHost(user
) && match_ircglob(user
->fakehost
, glob
))
429 if (IsSetHost(user
) && match_ircglob(sethostname
, glob
))
431 /* Check for an account match. */
432 if (hidden_host_suffix
&& user
->handle_info
) {
433 char hidden_host
[HOSTLEN
+1];
434 snprintf(hidden_host
, sizeof(hidden_host
), "%s.%s", user
->handle_info
->handle
, hidden_host_suffix
);
435 if (match_ircglob(hidden_host
, glob
))
438 /* None of the above; could only be a hostname match. */
439 return match_ircglob(user
->hostname
, glob
);
443 is_ircmask(const char *text
)
445 while (*text
&& (isalnum((char)*text
) || strchr("-_[]|\\`^{}?*", *text
)))
449 while (*text
&& *text
!= '@' && !isspace((char)*text
))
453 while (*text
&& !isspace((char)*text
))
459 is_gline(const char *text
)
463 text
+= strcspn(text
, "@!% \t\r\n");
468 while (*text
&& (isalnum((char)*text
) || strchr(".-?*:", *text
)))
474 is_shun(const char *text
)
478 text
+= strcspn(text
, "@!% \t\r\n");
483 while (*text
&& (isalnum((char)*text
) || strchr(".-?*:", *text
)))
489 split_ircmask(char *text
, char **nick
, char **ident
, char **host
)
494 while (isalnum((char)*text
) || strchr("=[]\\`^{}?*", *text
))
496 if (*text
!= '!' || ((text
- start
) > NICKLEN
))
503 while (*text
&& *text
!= '@' && !isspace((char)*text
))
505 if (*text
!= '@' || ((text
- start
) > USERLEN
))
512 while (*text
&& (isalnum((char)*text
) || strchr(".-?*:", *text
)))
516 return !*text
&& ((text
- start
) <= HOSTLEN
) && nick
&& ident
&& host
;
520 sanitize_ircmask(char *input
)
522 unsigned int length
, flag
;
523 char *mask
, *start
, *output
;
525 /* Sanitize everything in place; input *must* be a valid
530 /* The nick is truncated at the end. */
533 while(*input
++ != '!')
542 /* This flag is used to indicate following parts should
551 /* The ident and host must be truncated at the beginning and
552 replaced with a '*' to be compatible with ircu. */
555 while(*input
++ != '@')
559 if(length
> USERLEN
|| flag
)
563 start
= input
- USERLEN
;
585 if(length
> HOSTLEN
|| flag
)
589 start
= input
- HOSTLEN
;
603 TypeLength(char type
)
606 case 'y': return 365*24*60*60;
607 case 'M': return 30*24*60*60;
608 case 'w': return 7*24*60*60;
609 case 'd': return 24*60*60;
610 case 'h': return 60*60;
617 /* This function is not entirely accurate as it does not take into account leap units
618 * or varying months. TODO: use proper dateadd functions to calculate real seconds
619 * from now for the units (eg 1M should be give us seconds till todays date next month)
622 ParseInterval(const char *interval
)
624 unsigned long seconds
= 0;
628 /* process the string, resetting the count if we find a unit character */
629 while ((c
= *interval
++)) {
630 if (isdigit((int)c
)) {
631 partial
= partial
*10 + c
- '0';
633 seconds
+= TypeLength(c
) * partial
;
637 /* assume the last chunk is seconds (the normal case) */
638 return seconds
+ partial
;
642 GetSizeMultiplier(char type
)
645 case 'G': case 'g': return 1024*1024*1024;
646 case 'M': case 'm': return 1024*1024;
647 case 'K': case 'k': return 1024;
648 case 'B': case 'b': return 1;
654 ParseVolume(const char *volume
)
656 unsigned long accum
= 0, partial
= 0;
658 while ((c
= *volume
++)) {
659 if (isdigit((int)c
)) {
660 partial
= partial
*10 + c
- '0';
662 accum
+= GetSizeMultiplier(c
) * partial
;
666 return accum
+ partial
;
670 parse_ipmask(const char *str
, struct in_addr
*addr
, unsigned long *mask
)
673 unsigned long t_a
, t_m
;
677 addr
->s_addr
= htonl(t_a
);
685 accum
= (accum
* 10) + *str
++ - '0';
686 } while (isdigit(*str
));
689 t_a
= (t_a
<< 8) | accum
;
690 t_m
= (t_m
<< 8) | 255;
694 while (*str
== '*') {
701 } else if (*str
== 0) {
709 } else if (*str
== '/') {
713 accum
= (accum
* 10) + *str
++ - '0';
714 } while (isdigit(*str
));
715 while (pos
< start
+accum
&& pos
< 32) {
716 t_a
= (t_a
<< 1) | 0;
717 t_m
= (t_m
<< 1) | 1;
720 if (pos
!= start
+accum
)
722 } else if (*str
== 0)
731 addr
->s_addr
= htonl(t_a
);
738 unsplit_string(char *set
[], unsigned int max
, char *dest
)
740 static char unsplit_buffer
[MAXLEN
*2];
741 unsigned int ii
, jj
, pos
;
744 dest
= unsplit_buffer
;
745 for (ii
=pos
=0; ii
<max
; ii
++) {
746 for (jj
=0; set
[ii
][jj
]; jj
++)
747 dest
[pos
++] = set
[ii
][jj
];
755 intervalString(char *output
, time_t interval
, struct handle_info
*hi
)
757 static const struct {
758 const char *msg_single
;
759 const char *msg_plural
;
762 { "MSG_YEAR", "MSG_YEARS", 365 * 24 * 60 * 60 },
763 { "MSG_WEEK", "MSG_WEEKS", 7 * 24 * 60 * 60 },
764 { "MSG_DAY", "MSG_DAYS", 24 * 60 * 60 },
765 { "MSG_HOUR", "MSG_HOURS", 60 * 60 },
766 { "MSG_MINUTE", "MSG_MINUTES", 60 },
767 { "MSG_SECOND", "MSG_SECONDS", 1 }
769 struct language
*lang
;
771 unsigned int type
, words
, pos
, count
;
773 lang
= hi
? hi
->language
: lang_C
;
776 msg
= language_find_message(lang
, "MSG_0_SECONDS");
777 return strcpy(output
, msg
);
780 for (type
= 0, words
= pos
= 0;
781 interval
&& (words
< 2) && (type
< ArrayLength(unit
));
783 if (interval
< unit
[type
].length
)
785 count
= interval
/ unit
[type
].length
;
786 interval
= interval
% unit
[type
].length
;
789 msg
= language_find_message(lang
, "MSG_AND");
790 pos
+= sprintf(output
+ pos
, "%s ", msg
);
793 msg
= language_find_message(lang
, unit
[type
].msg_single
);
795 msg
= language_find_message(lang
, unit
[type
].msg_plural
);
796 pos
+= sprintf(output
+ pos
, "%d%s", count
, msg
);
804 getipbyname(const char *name
, unsigned long *ip
)
806 struct hostent
*he
= gethostbyname(name
);
809 if (he
->h_addrtype
!= AF_INET
)
811 memcpy(ip
, he
->h_addr_list
[0], sizeof(*ip
));
815 DEFINE_LIST(string_buffer
, char)
818 string_buffer_append_substring(struct string_buffer
*buf
, const char *tail
, unsigned int len
)
820 while (buf
->used
+ len
>= buf
->size
) {
825 buf
->list
= realloc(buf
->list
, buf
->size
*sizeof(buf
->list
[0]));
827 memcpy(buf
->list
+ buf
->used
, tail
, len
+1);
832 string_buffer_append_string(struct string_buffer
*buf
, const char *tail
)
834 string_buffer_append_substring(buf
, tail
, strlen(tail
));
838 string_buffer_append_vprintf(struct string_buffer
*buf
, const char *fmt
, va_list args
)
844 VA_COPY(working
, args
);
846 if (!buf
->list
|| ((buf
->used
+ buf
->size
) < len
)) {
847 buf
->size
= buf
->used
+ len
;
848 buf
->list
= realloc(buf
->list
, buf
->size
);
850 ret
= vsnprintf(buf
->list
+ buf
->used
, buf
->size
- buf
->used
, fmt
, working
);
852 /* pre-C99 behavior; double buffer size until it is big enough */
854 VA_COPY(working
, args
);
855 while ((ret
= vsnprintf(buf
->list
+ buf
->used
, buf
->size
- buf
->used
, fmt
, working
)) <= 0) {
857 buf
->list
= realloc(buf
->list
, buf
->size
);
859 VA_COPY(working
, args
);
862 } else if (buf
->used
+ ret
< buf
->size
) {
863 /* no need to increase allocation size */
866 /* now we know exactly how much space we need */
867 if (buf
->size
<= buf
->used
+ ret
) {
868 buf
->size
= buf
->used
+ ret
+ 1;
869 buf
->list
= realloc(buf
->list
, buf
->size
);
872 VA_COPY(working
, args
);
873 buf
->used
+= vsnprintf(buf
->list
+ buf
->used
, buf
->size
, fmt
, working
);
879 void string_buffer_append_printf(struct string_buffer
*buf
, const char *fmt
, ...)
883 string_buffer_append_vprintf(buf
, fmt
, args
);
887 string_buffer_replace(struct string_buffer
*buf
, unsigned int from
, unsigned int len
, const char *repl
)
889 unsigned int repl_len
= strlen(repl
);
890 if (from
> buf
->used
)
892 if (len
+ from
> buf
->used
)
893 len
= buf
->used
- from
;
894 buf
->used
= buf
->used
+ repl_len
- len
;
895 if (buf
->size
<= buf
->used
) {
896 while (buf
->used
>= buf
->size
)
898 buf
->list
= realloc(buf
->list
, buf
->size
*sizeof(buf
->list
[0]));
900 memmove(buf
->list
+from
+repl_len
, buf
->list
+from
+len
, strlen(buf
->list
+from
+len
));
901 strcpy(buf
->list
+from
, repl
);
904 struct string_list str_tab
;
907 strtab(unsigned int ii
) {
910 if (ii
> str_tab
.size
) {
911 unsigned int old_size
= str_tab
.size
;
912 while (ii
>= str_tab
.size
)
914 str_tab
.list
= realloc(str_tab
.list
, str_tab
.size
*sizeof(str_tab
.list
[0]));
915 memset(str_tab
.list
+old_size
, 0, (str_tab
.size
-old_size
)*sizeof(str_tab
.list
[0]));
917 if (!str_tab
.list
[ii
]) {
918 str_tab
.list
[ii
] = malloc(12);
919 sprintf(str_tab
.list
[ii
], "%u", ii
);
921 return str_tab
.list
[ii
];
927 unsigned int upr
, lwr
;
928 for (lwr
=0; lwr
<256; ++lwr
)
930 for (upr
='A', lwr
='a'; lwr
<= 'z'; ++upr
, ++lwr
)
932 #ifdef WITH_PROTOCOL_P10
933 for (upr
='[', lwr
='{'; lwr
<= '~'; ++upr
, ++lwr
)
935 for (upr
=0xc0, lwr
=0xe0; lwr
<= 0xf6; ++upr
, ++lwr
)
937 for (upr
=0xd8, lwr
=0xf8; lwr
<= 0xfe; ++upr
, ++lwr
)
941 str_tab
.list
= calloc(str_tab
.size
, sizeof(str_tab
.list
[0]));
948 for (ii
=0; ii
<str_tab
.size
; ++ii
)
949 free(str_tab
.list
[ii
]);
953 /* mysep() is my answer to the strtok/strsep
954 * issue. strsep is nice but doesn't skip
955 * multiple dilimiters, which can really
956 * offset tokens and cause huge corruption
957 * so this function will use strsep but
958 * act like strtok in that sense.
960 char *mysep(char **sepstr
, char *delim
)
964 if(!*sepstr
|| !**sepstr
)
969 retstr
= strsep(sepstr
, delim
);
970 }while (retstr
&& !(*retstr
));
975 char *time2str(time_t thetime
)
979 buf
= ctime(&thetime
);
980 tmp
= (char *)strchr(buf
, '\n');
985 char* x3_strtok(char **save
, char *str
, char *fs
)
987 char *pos
= *save
; /* keep last position across calls */
991 pos
= str
; /* new string scan */
993 while (pos
&& *pos
&& strchr(fs
, *pos
) != NULL
)
994 pos
++; /* skip leading separators */
997 return (pos
= *save
= NULL
); /* string contains only sep's */
999 tmp
= pos
; /* now, keep position of the token */
1001 while (*pos
&& strchr(fs
, *pos
) == NULL
)
1002 pos
++; /* skip content of the token */
1005 *pos
++ = '\0'; /* remove first sep after the token */
1007 pos
= NULL
; /* end of string */
1013 int valid_email(const char *email
)
1016 for (i
=0;i
<strlen(email
);i
++)
1018 if(!isalnum(email
[i
]) &&
1026 if(strchr(email
, '@') == NULL
)