diff --git a/tools/psl.c b/tools/psl.c index 3764599..ff28285 100644 --- a/tools/psl.c +++ b/tools/psl.c @@ -32,8 +32,10 @@ # include #endif +#include #include #include +#include #include static void usage(int err, FILE* f) @@ -135,8 +137,33 @@ int main(int argc, const char *const *argv) exit(2); } if (arg >= argv + argc) { - fprintf(stderr, "No domains given - aborting\n"); - exit(3); + if (isatty(STDIN_FILENO)) { + char buf[256], *domain; + size_t len; + + // read URLs from STDIN + while (fgets(buf, sizeof(buf), stdin)) { + for (domain = buf; isspace(*domain); domain++); // skip leading spaces + if (*domain == '#' || !*domain) continue; // skip empty lines and comments + for (len = strlen(domain); len && isspace(domain[len - 1]); len--); // skip trailing spaces + domain[len] = 0; + + if (mode == 1) + printf("%s: %d\n", domain, psl_is_public_suffix(psl, domain)); + else if (mode == 2) + printf("%s: %s\n", domain, psl_unregistrable_domain(psl, domain)); + else if (mode == 3) + printf("%s: %s\n", domain, psl_registrable_domain(psl, domain)); + else if (mode == 4) + printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, domain, cookie_domain)); + } + + psl_free(psl); + exit(0); + } else { + fprintf(stderr, "No domains given - aborting\n"); + exit(3); + } } }