fixed locale/charset support
This commit is contained in:
parent
935b44b3ea
commit
a0a9e76261
43
tools/psl.c
43
tools/psl.c
|
@ -73,6 +73,10 @@ int main(int argc, const char *const *argv)
|
||||||
const char *const *arg, *psl_file = NULL, *cookie_domain = NULL;
|
const char *const *arg, *psl_file = NULL, *cookie_domain = NULL;
|
||||||
psl_ctx_t *psl = (psl_ctx_t *) psl_builtin();
|
psl_ctx_t *psl = (psl_ctx_t *) psl_builtin();
|
||||||
|
|
||||||
|
/* set current locale according to the environment variables */
|
||||||
|
#include <locale.h>
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
for (arg = argv + 1; arg < argv + argc; arg++) {
|
for (arg = argv + 1; arg < argv + argc; arg++) {
|
||||||
if (!strncmp(*arg, "--", 2)) {
|
if (!strncmp(*arg, "--", 2)) {
|
||||||
if (!strcmp(*arg, "--is-public-suffix"))
|
if (!strcmp(*arg, "--is-public-suffix"))
|
||||||
|
@ -137,9 +141,9 @@ int main(int argc, const char *const *argv)
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
if (arg >= argv + argc) {
|
if (arg >= argv + argc) {
|
||||||
if (isatty(STDIN_FILENO)) {
|
char buf[256], *domain, *lower;
|
||||||
char buf[256], *domain;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int rc;
|
||||||
|
|
||||||
// read URLs from STDIN
|
// read URLs from STDIN
|
||||||
while (fgets(buf, sizeof(buf), stdin)) {
|
while (fgets(buf, sizeof(buf), stdin)) {
|
||||||
|
@ -148,22 +152,30 @@ int main(int argc, const char *const *argv)
|
||||||
for (len = strlen(domain); len && isspace(domain[len - 1]); len--); // skip trailing spaces
|
for (len = strlen(domain); len && isspace(domain[len - 1]); len--); // skip trailing spaces
|
||||||
domain[len] = 0;
|
domain[len] = 0;
|
||||||
|
|
||||||
if (mode == 1)
|
if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &lower)) != 0)
|
||||||
printf("%s: %d\n", domain, psl_is_public_suffix(psl, domain));
|
fprintf(stderr, "%s: Failed to convert to lowercase UTF-8 (%d)\n", domain, rc);
|
||||||
|
else if (mode == 1)
|
||||||
|
printf("%s: %d (%s)\n", domain, psl_is_public_suffix(psl, lower), lower);
|
||||||
else if (mode == 2)
|
else if (mode == 2)
|
||||||
printf("%s: %s\n", domain, psl_unregistrable_domain(psl, domain));
|
printf("%s: %s\n", domain, psl_unregistrable_domain(psl, lower));
|
||||||
else if (mode == 3)
|
else if (mode == 3)
|
||||||
printf("%s: %s\n", domain, psl_registrable_domain(psl, domain));
|
printf("%s: %s\n", domain, psl_registrable_domain(psl, lower));
|
||||||
else if (mode == 4)
|
else if (mode == 4) {
|
||||||
printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, domain, cookie_domain));
|
char *cookie_domain_lower;
|
||||||
|
|
||||||
|
if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &cookie_domain_lower)) != 0)
|
||||||
|
fprintf(stderr, "%s: Failed to convert cookie domain '%s' to lowercase UTF-8 (%d)\n", domain, cookie_domain, rc);
|
||||||
|
else
|
||||||
|
printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, lower, cookie_domain));
|
||||||
|
|
||||||
|
free(cookie_domain_lower);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
psl_free(psl);
|
psl_free(psl);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
|
||||||
fprintf(stderr, "No domains given - aborting\n");
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +211,13 @@ int main(int argc, const char *const *argv)
|
||||||
printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time()));
|
printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time()));
|
||||||
printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time()));
|
printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time()));
|
||||||
printf("builtin SHA1 file hash: %s\n", psl_builtin_sha1sum());
|
printf("builtin SHA1 file hash: %s\n", psl_builtin_sha1sum());
|
||||||
|
|
||||||
|
#ifdef WITH_LIBICU
|
||||||
|
#include <unicode/uloc.h>
|
||||||
|
#include <unicode/ucnv.h>
|
||||||
|
printf("uloc_getDefault=%s\n", uloc_getDefault());
|
||||||
|
printf("ucnv_getDefaultName=%s\n", ucnv_getDefaultName());
|
||||||
|
#endif
|
||||||
} else
|
} else
|
||||||
printf("No builtin PSL data available\n");
|
printf("No builtin PSL data available\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue