From b1e5199723b88aa630adc9367d1dc2c6839ceb84 Mon Sep 17 00:00:00 2001 From: Jan Bayer Date: Wed, 4 Oct 2023 19:02:01 +0200 Subject: [PATCH] adding --domain to CLI interface --- README.md | 1 + src/ctld.c | 12 ++++++++++-- test/test.sh | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e3fa269..3dc851a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ ctld [OPTIONS] FILE --rd Print registered domain --fqdn Print fully-qualified-domain-name --private Use private suffix list as well + --domain Print effective 2nd level label --err Print Errors only --custom= Add a comma-separated list of custom suffixes (no space) -h , --help Print this help message diff --git a/src/ctld.c b/src/ctld.c index 370d46b..373bbc4 100644 --- a/src/ctld.c +++ b/src/ctld.c @@ -27,6 +27,7 @@ int main(int argc, char ** argv){ {.short_option=0, .long_option = "tld", .has_param = NO_PARAM, .help="Print suffix", .tag="print_tld"}, {.short_option=0, .long_option = "rd", .has_param = NO_PARAM, .help="Print registered domain", .tag="print_rd"}, {.short_option=0, .long_option = "fqdn", .has_param = NO_PARAM, .help="Print fully-qualified-domain-name", .tag="print_fqdn"}, + {.short_option=0, .long_option = "domain", .has_param = NO_PARAM, .help="Print effective 2nd level label", .tag="print_domain"}, {.short_option=0, .long_option = "private", .has_param = NO_PARAM, .help="Use private suffix list as well", .tag="use_private"}, {.short_option=0, .long_option = "err", .has_param = NO_PARAM, .help="Print Errors only", .tag="print_err"}, {.short_option=0, .long_option = "custom", .has_param = HAS_PARAM, .help="Add a comma-separated list of custom suffixes (no space)", .tag="custom_suffix"}, @@ -41,7 +42,7 @@ int main(int argc, char ** argv){ arg_show_help(&cmd, argc, argv); return 1; } - int print_tld, print_rd, print_fqdn, use_private, print_err; + int print_tld, print_rd, print_fqdn, print_domain, use_private, print_err; if (arg_is_tag_set(pargs, "print_help")){ arg_show_help(&cmd, argc, argv); return 0; @@ -53,6 +54,7 @@ int main(int argc, char ** argv){ print_tld = arg_is_tag_set(pargs, "print_tld")?1:0; print_rd = arg_is_tag_set(pargs, "print_rd")?1:0; print_fqdn = arg_is_tag_set(pargs, "print_fqdn")?1:0; + print_domain = arg_is_tag_set(pargs, "print_domain")?1:0; use_private = arg_is_tag_set(pargs, "use_private")?1:0; print_err = arg_is_tag_set(pargs, "print_err")?1:0; char * filename = cmd.extra?cmd.extra:NULL; @@ -75,7 +77,7 @@ int main(int argc, char ** argv){ return 1; } // set this as the default option - if (print_rd == 0 && print_tld == 0 && print_fqdn == 0) + if (print_rd == 0 && print_tld == 0 && print_fqdn == 0 && print_domain == 0) print_rd = 1; char * l = NULL; @@ -218,6 +220,12 @@ int main(int argc, char ** argv){ printf("\t"); PRINTIFSET(result->suffix); p++; + } + if (print_domain){ + if (p) + printf("\t"); + PRINTIFSET(result->domain); + p++; } printf("\n"); } diff --git a/test/test.sh b/test/test.sh index f8f8f0e..286d379 100755 --- a/test/test.sh +++ b/test/test.sh @@ -9,3 +9,7 @@ test $(echo "http://xn--npth-5q5a1g.nạpthẻ.vn/app" | ./bin/ctld --rd) == 'xn test $(echo "nạpthẻ.vn" | ./bin/ctld --rd) == 'xn--npth-5q5a1g.vn' || echo $FAIL test $(echo "xn--npth-5q5a1g.nạpthẻ.vn" | ./bin/ctld --rd) == 'xn--npth-5q5a1g.vn' || echo $FAIL + +test $(echo "xn--npth-5q5a1g.nạpthẻ.vn" | ./bin/ctld --domain) == 'xn--npth-5q5a1g' || echo $FAIL +test $(echo "https://freefire.xn--npth-5q5a1g.vn/app" | ./bin/ctld --domain) == 'xn--npth-5q5a1g' || echo $FAIL +test $(echo "https://test.vic.edu.au/app" | ./bin/ctld --domain) == 'test' || echo $FAIL \ No newline at end of file