author | Mikael Berthe <mikael@lilotux.net> |
Mon, 26 Sep 2005 22:08:48 +0200 | |
changeset 452 | dfd9c62b3a39 |
parent 428 | 4470868f90e5 |
child 456 | 471c9ccde028 |
permissions | -rw-r--r-- |
241 | 1 |
/* |
2 |
* utils.c -- Various utility functions |
|
393 | 3 |
* |
241 | 4 |
* Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
5 |
* ut_* functions are derived from Cabber debug/log code. |
|
6 |
* from_iso8601() comes from the Gaim project. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
11 |
* your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, but |
|
14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
* General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
21 |
* USA |
|
22 |
*/ |
|
23 |
||
24 | 24 |
#include <stdio.h> |
25 |
#include <stdlib.h> |
|
77 | 26 |
#include <string.h> |
24 | 27 |
#include <stdarg.h> |
28 |
#include <time.h> |
|
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
29 |
#include <unistd.h> |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
30 |
#include <sys/types.h> |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
31 |
#include <sys/stat.h> |
452 | 32 |
#include <ctype.h> |
24 | 33 |
|
241 | 34 |
#include <config.h> |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
35 |
#include "logprint.h" |
241 | 36 |
|
76 | 37 |
static int DebugEnabled; |
77 | 38 |
static char *FName; |
24 | 39 |
|
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
241
diff
changeset
|
40 |
void ut_InitDebug(unsigned int level, const char *filename) |
24 | 41 |
{ |
77 | 42 |
FILE *fp; |
428
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
43 |
struct stat buf; |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
44 |
int err; |
77 | 45 |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
46 |
if (level < 1) { |
138 | 47 |
DebugEnabled = 0; |
48 |
FName = NULL; |
|
49 |
return; |
|
50 |
} |
|
51 |
||
52 |
if (filename) |
|
53 |
FName = strdup(filename); |
|
77 | 54 |
else { |
138 | 55 |
FName = getenv("HOME"); |
56 |
if (!FName) |
|
57 |
FName = "/tmp/mcabberlog"; |
|
58 |
else { |
|
59 |
char *tmpname = malloc(strlen(FName) + 12); |
|
60 |
strcpy(tmpname, FName); |
|
61 |
strcat(tmpname, "/mcabberlog"); |
|
62 |
FName = tmpname; |
|
63 |
} |
|
77 | 64 |
} |
24 | 65 |
|
66 |
DebugEnabled = level; |
|
76 | 67 |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
68 |
fp = fopen(FName, "a"); |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
69 |
if (!fp) { |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
70 |
fprintf(stderr, "ERROR: Cannot open tracelog file\n"); |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
71 |
return; |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
72 |
} |
428
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
73 |
|
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
74 |
err = fstat(fileno(fp), &buf); |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
75 |
if (err || buf.st_uid != geteuid()) { |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
76 |
fclose(fp); |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
77 |
DebugEnabled = 0; |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
78 |
FName = NULL; |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
79 |
if (err) { |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
80 |
fprintf(stderr, "ERROR: cannot stat the tracelog file!\n"); |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
81 |
} else { |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
82 |
fprintf(stderr, "ERROR: tracelog file does not belong to you!\n"); |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
83 |
} |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
84 |
return; |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
85 |
} |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
86 |
fchmod(fileno(fp), S_IRUSR|S_IWUSR); |
4470868f90e5
Check the tracelog file actually belongs to the user (if logging enabled)
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
87 |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
88 |
fprintf(fp, "New trace log started.\n" |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
89 |
"----------------------\n"); |
24 | 90 |
fclose(fp); |
91 |
} |
|
92 |
||
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
93 |
void ut_WriteLog(unsigned int flag, const char *data) |
24 | 94 |
{ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
95 |
if (!DebugEnabled || !FName) return; |
393 | 96 |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
97 |
if (((DebugEnabled == 2) && (flag & (LPRINT_LOG|LPRINT_DEBUG))) || |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
98 |
((DebugEnabled == 1) && (flag & LPRINT_LOG))) { |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
99 |
FILE *fp = fopen(FName, "a+"); |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
100 |
if (!fp) { |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
101 |
scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file"); |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
102 |
return; |
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
103 |
} |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
104 |
fputs(data, fp); |
24 | 105 |
fclose(fp); |
106 |
} |
|
107 |
} |
|
108 |
||
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
109 |
// checkset_perm(name, setmode) |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
110 |
// Check the permissions of the "name" file/dir |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
111 |
// If setmode is true, correct the permissions if they are wrong |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
112 |
// Return values: -1 == bad file/dir, 0 == success, 1 == cannot correct |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
113 |
int checkset_perm(const char *name, unsigned int setmode) |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
114 |
{ |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
115 |
int fd; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
116 |
struct stat buf; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
117 |
|
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
118 |
fd = lstat(name, &buf); |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
119 |
if (fd == -1) return -1; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
120 |
|
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
121 |
if (buf.st_uid != geteuid()) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
122 |
scr_LogPrint(LPRINT_LOGNORM, "Wrong file owner [%s]", name); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
123 |
return 1; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
124 |
} |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
125 |
|
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
126 |
if (buf.st_mode & (S_IRGRP | S_IWGRP | S_IXGRP) || |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
127 |
buf.st_mode & (S_IROTH | S_IWOTH | S_IXOTH)) { |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
128 |
if (setmode) { |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
129 |
mode_t newmode = 0; |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
130 |
scr_LogPrint(LPRINT_LOGNORM, "Bad permissions [%s]", name); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
131 |
if (S_ISDIR(buf.st_mode)) |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
132 |
newmode |= S_IXUSR; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
133 |
newmode |= S_IRUSR | S_IWUSR; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
134 |
if (chmod(name, newmode)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
135 |
scr_LogPrint(LPRINT_LOGNORM, "WARNING: Failed to correct permissions!"); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
136 |
return 1; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
137 |
} |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
138 |
scr_LogPrint(LPRINT_LOGNORM, "Permissions have been corrected"); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
139 |
} else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
140 |
scr_LogPrint(LPRINT_LOGNORM, "WARNING: Bad permissions [%s]", name); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
141 |
return 1; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
142 |
} |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
143 |
} |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
144 |
|
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
145 |
return 0; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
146 |
} |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
147 |
|
241 | 148 |
// to_iso8601(dststr, timestamp) |
149 |
// Convert timestamp to iso8601 format, and store it in dststr. |
|
150 |
// NOTE: dststr should be at last 19 chars long. |
|
151 |
// Return should be 0 |
|
152 |
int to_iso8601(char *dststr, time_t timestamp) |
|
153 |
{ |
|
154 |
struct tm *tm_time; |
|
155 |
int ret; |
|
156 |
||
157 |
tm_time = gmtime(×tamp); |
|
158 |
||
159 |
ret = snprintf(dststr, 19, "%.4d%02d%02dT%02d:%02d:%02dZ", |
|
160 |
1900+tm_time->tm_year, tm_time->tm_mon+1, tm_time->tm_mday, |
|
161 |
tm_time->tm_hour, tm_time->tm_min, tm_time->tm_sec); |
|
162 |
||
163 |
return ((ret == -1) ? -1 : 0); |
|
164 |
} |
|
165 |
||
166 |
// from_iso8601(timestamp, utc) |
|
167 |
// This function comes from the Gaim project, gaim_str_to_time(). |
|
168 |
// (Actually date may not be pure iso-8601) |
|
169 |
// Thanks, guys! |
|
170 |
time_t from_iso8601(const char *timestamp, int utc) |
|
171 |
{ |
|
172 |
struct tm t; |
|
173 |
time_t retval = 0; |
|
174 |
char buf[32]; |
|
175 |
char *c; |
|
176 |
int tzoff = 0; |
|
177 |
||
178 |
time(&retval); |
|
179 |
localtime_r(&retval, &t); |
|
180 |
||
181 |
snprintf(buf, sizeof(buf), "%s", timestamp); |
|
182 |
c = buf; |
|
183 |
||
184 |
/* 4 digit year */ |
|
185 |
if (!sscanf(c, "%04d", &t.tm_year)) return 0; |
|
186 |
c+=4; |
|
187 |
if (*c == '-') |
|
188 |
c++; |
|
189 |
||
190 |
t.tm_year -= 1900; |
|
191 |
||
192 |
/* 2 digit month */ |
|
193 |
if (!sscanf(c, "%02d", &t.tm_mon)) return 0; |
|
194 |
c+=2; |
|
195 |
if (*c == '-') |
|
196 |
c++; |
|
197 |
||
198 |
t.tm_mon -= 1; |
|
199 |
||
200 |
/* 2 digit day */ |
|
201 |
if (!sscanf(c, "%02d", &t.tm_mday)) return 0; |
|
202 |
c+=2; |
|
203 |
if (*c == 'T' || *c == '.') { /* we have more than a date, keep going */ |
|
204 |
c++; /* skip the "T" */ |
|
205 |
||
206 |
/* 2 digit hour */ |
|
207 |
if (sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 || |
|
208 |
sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) { |
|
209 |
int tzhrs, tzmins; |
|
210 |
c+=8; |
|
211 |
if (*c == '.') /* dealing with precision we don't care about */ |
|
212 |
c += 4; |
|
213 |
||
214 |
if ((*c == '+' || *c == '-') && |
|
215 |
sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) { |
|
216 |
tzoff = tzhrs*60*60 + tzmins*60; |
|
217 |
if (*c == '+') |
|
218 |
tzoff *= -1; |
|
219 |
} |
|
220 |
||
221 |
if (tzoff || utc) { |
|
222 |
||
223 |
//#ifdef HAVE_TM_GMTOFF |
|
224 |
tzoff += t.tm_gmtoff; |
|
225 |
//#else |
|
226 |
//# ifdef HAVE_TIMEZONE |
|
227 |
// tzset(); /* making sure */ |
|
228 |
// tzoff -= timezone; |
|
229 |
//# endif |
|
230 |
//#endif |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
t.tm_isdst = -1; |
|
236 |
||
237 |
retval = mktime(&t); |
|
238 |
||
239 |
retval += tzoff; |
|
240 |
||
241 |
return retval; |
|
242 |
} |
|
419 | 243 |
|
244 |
// Should only be used for delays < 1s |
|
245 |
inline void safe_usleep(unsigned int usec) |
|
246 |
{ |
|
247 |
struct timespec req; |
|
248 |
req.tv_sec = 0; |
|
249 |
req.tv_nsec = (long)usec * 1000L; |
|
250 |
nanosleep(&req, NULL); |
|
251 |
} |
|
452 | 252 |
|
253 |
/** |
|
254 |
* Derived from libjabber/jid.c, because the libjabber version is not |
|
255 |
* really convenient for our usage. |
|
256 |
* |
|
257 |
* Check if the full JID is valid |
|
258 |
* Return 0 if it is valid, non zero otherwise |
|
259 |
*/ |
|
260 |
int check_jid_syntax(char *jid) |
|
261 |
{ |
|
262 |
char *str; |
|
263 |
char *domain, *resource; |
|
264 |
int domlen; |
|
265 |
||
266 |
if (!jid) return 1; |
|
267 |
||
268 |
domain = strchr(jid, '@'); |
|
269 |
if (!domain) return 1; |
|
270 |
||
271 |
/* node identifiers may not be longer than 1023 bytes */ |
|
272 |
if ((domain == jid) || (domain-jid > 1023)) |
|
273 |
return 1; |
|
274 |
domain++; |
|
275 |
||
276 |
/* check for low and invalid ascii characters in the username */ |
|
277 |
for (str = jid; *str != '@'; str++) { |
|
278 |
if (*str <= 32 || *str == ':' || *str == '@' || |
|
279 |
*str == '<' || *str == '>' || *str == '\'' || |
|
280 |
*str == '"' || *str == '&') { |
|
281 |
return 1; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/* the username is okay as far as we can tell without LIBIDN */ |
|
286 |
||
287 |
resource = strchr(domain, '/'); |
|
288 |
||
289 |
/* the resource is optional */ |
|
290 |
if (resource) { |
|
291 |
domlen = resource - domain; |
|
292 |
resource++; |
|
293 |
/* resources may not be longer than 1023 bytes */ |
|
294 |
if ((*resource == '\0') || strlen(resource) > 1023) |
|
295 |
return 1; |
|
296 |
} else { |
|
297 |
domlen = strlen(domain); |
|
298 |
} |
|
299 |
||
300 |
/* there must be a domain identifier */ |
|
301 |
if (domlen == 0) return 1; |
|
302 |
||
303 |
/* and it must not be longer than 1023 bytes */ |
|
304 |
if (domlen > 1023) return 1; |
|
305 |
||
306 |
/* make sure the hostname is valid characters */ |
|
307 |
for (str = domain; *str != '\0' && *str != '/'; str++) { |
|
308 |
if (!(isalnum(*str) || *str == '.' || *str == '-' || *str == '_')) |
|
309 |
return 1; |
|
310 |
} |
|
311 |
||
312 |
/* it's okay as far as we can tell without LIBIDN */ |
|
313 |
return 0; |
|
314 |
} |
|
315 |
||
316 |
void mc_strtolower(char *str) |
|
317 |
{ |
|
318 |
if (!str) return; |
|
319 |
for ( ; *str; str++) |
|
320 |
*str = tolower(*str); |
|
321 |
} |