Coverage Report

Created: 2026-10-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/httrack/src/htspsl_selftest.c
Line
Count
Source
1
/* ------------------------------------------------------------ */
2
/*
3
HTTrack Website Copier, Offline Browser for Windows and Unix
4
Copyright (C) 2026 Xavier Roche and other contributors
5
6
SPDX-License-Identifier: GPL-3.0-or-later
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 3 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU 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, see <http://www.gnu.org/licenses/>.
20
21
Ethical use: we kindly ask that you NOT use this software to harvest email
22
addresses or to collect any other private information about people. Doing so
23
would dishonor our work and waste the many hours we have spent on it.
24
25
Please visit our Website: http://www.httrack.com
26
*/
27
28
/* ------------------------------------------------------------ */
29
/* File: htspsl_selftest.c subroutines:                         */
30
/*       self-tests for the Public Suffix List lookups          */
31
/* ------------------------------------------------------------ */
32
33
#include "htsselftest_int.h"
34
35
#include "htspsl.h"
36
37
/* Print the registrable domain of host, lowercased, or "null". */
38
0
static void print_registrable(const char *host) {
39
0
  char buf[256];
40
0
  const char *reg;
41
42
0
  buf[0] = '\0';
43
0
  strlncatbuff(buf, host, sizeof(buf), sizeof(buf) - 1);
44
0
  hts_lowcase(buf);
45
0
  reg = hts_psl_registrable_domain(buf);
46
0
  printf("%s\n", reg != NULL ? reg : "null");
47
0
}
48
49
/* -#test=psl <host>: the registrable domain of host under the list in use. */
50
0
static int st_psl(httrackp *opt, int argc, char **argv) {
51
0
  (void) opt;
52
0
  if (argc != 1) {
53
0
    fprintf(stderr, "psl: takes <host>\n");
54
0
    return 1;
55
0
  }
56
0
  print_registrable(argv[0]);
57
0
  return 0;
58
0
}
59
60
/* -#test=pslfile <file> <host>: look host up under a list file, print the
61
   file's stamp, then restore the default list. */
62
0
static int st_pslfile(httrackp *opt, int argc, char **argv) {
63
0
  (void) opt;
64
0
  if (argc != 2) {
65
0
    fprintf(stderr, "pslfile: takes <file> <host>\n");
66
0
    return 1;
67
0
  }
68
0
  if (hts_psl_load_file(argv[0], 1)) {
69
0
    print_registrable(argv[1]);
70
0
    printf("%s\n", hts_psl_version());
71
0
  } else {
72
0
    printf("unreadable\n");
73
0
  }
74
0
  hts_psl_init();
75
0
  return 0;
76
0
}
77
78
/* -#test=pslinit <file>: the stamp of the list a build configured with
79
   --with-psl-file=<file> would use, then restore the default list. */
80
0
static int st_pslinit(httrackp *opt, int argc, char **argv) {
81
0
  (void) opt;
82
0
  if (argc != 1) {
83
0
    fprintf(stderr, "pslinit: takes <file>\n");
84
0
    return 1;
85
0
  }
86
0
  hts_psl_init_from(argv[0]);
87
0
  printf("%s\n", hts_psl_version());
88
0
  hts_psl_init();
89
0
  return 0;
90
0
}
91
92
/* -#test=pslversion: the VERSION stamp of the list in use. */
93
0
static int st_pslversion(httrackp *opt, int argc, char **argv) {
94
0
  (void) opt;
95
0
  (void) argc;
96
0
  (void) argv;
97
  printf("%s\n", hts_psl_version());
98
0
  return 0;
99
0
}
100
101
const struct selftest_entry selftests_psl[] = {
102
    {"psl", "<host>", "registrable domain under the Public Suffix List",
103
     st_psl},
104
    {"pslfile", "<file> <host>", "registrable domain under a list file",
105
     st_pslfile},
106
    {"pslinit", "<file>", "VERSION stamp chosen for a list file", st_pslinit},
107
    {"pslversion", "", "VERSION stamp of the Public Suffix List in use",
108
     st_pslversion},
109
    {NULL, NULL, NULL, NULL},
110
};