mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
common: New function to validate domain names.
* common/mbox-util.c (is_valid_domain_name): New. * common/t-mbox-util.c (run_dns_test): New test. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
967d3649d2
commit
ddee9f9409
3 changed files with 93 additions and 2 deletions
|
@ -33,7 +33,7 @@
|
|||
|
||||
|
||||
static void
|
||||
run_test (void)
|
||||
run_mbox_test (void)
|
||||
{
|
||||
static struct
|
||||
{
|
||||
|
@ -93,13 +93,64 @@ run_test (void)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
run_dns_test (void)
|
||||
{
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
int valid;
|
||||
} testtbl[] =
|
||||
{
|
||||
{ "", 0 },
|
||||
{ ".", 0 },
|
||||
{ "-", 0 },
|
||||
{ "a", 1 },
|
||||
{ "ab", 1 },
|
||||
{ "a.b", 1 },
|
||||
{ "a.b.", 1 },
|
||||
{ ".a.b.", 0 },
|
||||
{ ".a.b", 0 },
|
||||
{ "-a.b", 0 },
|
||||
{ "a-.b", 0 },
|
||||
{ "a.-b", 0 },
|
||||
{ "a.b-", 0 },
|
||||
{ "a.b-.", 0 },
|
||||
{ "a..b", 0 },
|
||||
{ "ab.c", 1 },
|
||||
{ "a-b.c", 1 },
|
||||
{ "a-b-.c", 0 },
|
||||
{ "-a-b.c", 0 },
|
||||
{ "example.org", 1 },
|
||||
{ "x.example.org", 1 },
|
||||
{ "xy.example.org", 1 },
|
||||
{ "Xy.example.org", 1 },
|
||||
{ "-Xy.example.org", 0 },
|
||||
{ "Xy.example-.org", 0 },
|
||||
{ "foo.example.org..", 0 },
|
||||
{ "foo.example.org.", 1 },
|
||||
{ ".foo.example.org.", 0 },
|
||||
{ "..foo.example.org.", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
int idx;
|
||||
|
||||
for (idx=0; testtbl[idx].name; idx++)
|
||||
{
|
||||
if (is_valid_domain_name (testtbl[idx].name) != testtbl[idx].valid)
|
||||
fail (idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
run_test ();
|
||||
run_mbox_test ();
|
||||
run_dns_test ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue