55 |
} |
} |
56 |
else /* Find the end of the token. */ |
else /* Find the end of the token. */ |
57 |
end = strpbrk (begin, delim); |
end = strpbrk (begin, delim); |
58 |
if ( end ){ |
if (end) { |
59 |
/* Terminate the token and set *STRINGP past NUL character. */ |
/* Terminate the token and set *STRINGP past NUL character. */ |
60 |
*end++ = '\0'; |
*end++ = '\0'; |
61 |
*stringp = end; |
*stringp = end; |
90 |
} |
} |
91 |
|
|
92 |
|
|
93 |
|
/* Check if @fname is a valid file name on a Window file system. |
94 |
|
If is_path = 1, @fname is treated as a file name without any separators. */ |
95 |
|
int |
96 |
|
check_file_name (const char *fname, int is_path) |
97 |
|
{ |
98 |
|
const char *not_allowed = "/*?\"<>|"; |
99 |
|
size_t i; |
100 |
|
|
101 |
|
/* If we are not in path mode (@is_path = 1) we also consider |
102 |
|
path separators as illegal chars. */ |
103 |
|
if (!is_path) { |
104 |
|
if (strchr (fname, ':') || strchr (fname, '\\')) |
105 |
|
return -1; |
106 |
|
} |
107 |
|
|
108 |
|
for (i=0; i < strlen (fname); i++) { |
109 |
|
if (strchr (not_allowed, fname[i])) |
110 |
|
return -1; |
111 |
|
} |
112 |
|
return 0; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
/* Check if the email address @email only contain valid characters. |
/* Check if the email address @email only contain valid characters. |
117 |
Return 0 on success. */ |
Return 0 on success. */ |
118 |
int |
int |
119 |
check_email_address (const char *email) |
check_email_address (const char *email) |
120 |
{ |
{ |
121 |
const char *allowed = "@._-%+;"; |
const char *allowed = "@._-%+;"; |
122 |
size_t i; |
size_t i, len = strlen (email); |
123 |
|
|
124 |
if (!strchr (email, '@')) |
if (len < 3 || !strchr (email, '@')) |
125 |
return -1; |
return -1; |
126 |
for (i=0; i < strlen (email); i++) { |
for (i=0; i < len; i++) { |
127 |
if (isdigit (email[i]) || isalpha (email[i]) |
if (isxdigit (email[i]) || isalpha (email[i]) |
128 |
|| strchr (allowed, email[i])) |
|| strchr (allowed, email[i])) |
129 |
continue; |
continue; |
130 |
else |
else |
145 |
if (end > strlen (str) || begin > strlen (str) || (end-begin) < 0) |
if (end > strlen (str) || begin > strlen (str) || (end-begin) < 0) |
146 |
return NULL; |
return NULL; |
147 |
|
|
148 |
/*p = new char[end-begin+1]; XXX: fixme*/ |
p = new char[end-begin+1]; |
|
p = (char*)calloc (1, end-begin+1); |
|
149 |
if (!p) |
if (!p) |
150 |
abort (); |
abort (); |
151 |
|
|
154 |
p[pos] = '\0'; |
p[pos] = '\0'; |
155 |
return p; |
return p; |
156 |
} |
} |
157 |
|
|
158 |
|
|
159 |
|
/* Remove %AB sequences from the input buffer @in |
160 |
|
and store the raw data in @out. */ |
161 |
|
void |
162 |
|
unhexify_buffer (const char *in, char **r_out) |
163 |
|
{ |
164 |
|
char temp[3], *out; |
165 |
|
size_t len, pos, i=0; |
166 |
|
|
167 |
|
len = strlen (in); |
168 |
|
out = new char[len+1]; |
169 |
|
if (!out) |
170 |
|
abort (); |
171 |
|
memset (out, 0, len+1); |
172 |
|
for (pos = 0; pos < len; pos++) { |
173 |
|
if (in[pos] == '%' && in[pos+1] == '%') |
174 |
|
out[i++] = '%'; |
175 |
|
else if (in[pos] == '%') { |
176 |
|
temp[0] = in[++pos]; |
177 |
|
temp[1] = in[++pos]; |
178 |
|
temp[2] = 0; |
179 |
|
out[i++] = (char)strtoul (temp, NULL, 16); |
180 |
|
} |
181 |
|
else |
182 |
|
out[i++] = in[pos]; |
183 |
|
} |
184 |
|
out[i] = 0; |
185 |
|
*r_out = out; |
186 |
|
} |