dns: extend CURLOPT_RESOLVE syntax for adding non-permanent entries

Extend the syntax of CURLOPT_RESOLVE strings: allow using a '+' prefix
(similar to the existing '-' prefix for removing entries) to add
DNS cache entries that will time out just like entries that are added
by libcurl itself.

Append " (non-permanent)" to info log message in case a non-permanent
entry is added.

Adjust relevant comments to reflect the new behavior.

Adjust documentation.

Extend unit1607 to test the new functionality.

Closes #6294
This commit is contained in:
Paul Groke 2020-12-10 17:38:14 +01:00 committed by Daniel Stenberg
parent 68dde8e330
commit 8324dc8b1a
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 82 additions and 40 deletions

View file

@ -49,6 +49,9 @@ struct testcase {
const char *host;
int port;
/* whether we expect a permanent or non-permanent cache entry */
bool permanent;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
@ -67,34 +70,37 @@ static const char skip = 0;
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1, 127.0.0.2",
"test.com", 80, { NULL, }
"test.com", 80, TRUE, { NULL, }
},
{ "TEST.com:80:,,127.0.0.1,,,127.0.0.2,,,,::1,,,",
"test.com", 80, { "127.0.0.1", "127.0.0.2", IPV6ONLY("::1"), }
"test.com", 80, TRUE, { "127.0.0.1", "127.0.0.2", IPV6ONLY("::1"), }
},
{ "test.com:80:::1,127.0.0.1",
"test.com", 80, { IPV6ONLY("::1"), "127.0.0.1", }
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:[::1],127.0.0.1",
"test.com", 80, { IPV6ONLY("::1"), "127.0.0.1", }
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:::1",
"test.com", 80, { IPV6ONLY("::1"), }
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:[::1]",
"test.com", 80, { IPV6ONLY("::1"), }
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:127.0.0.1",
"test.com", 80, { "127.0.0.1", }
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:,127.0.0.1",
"test.com", 80, { "127.0.0.1", }
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.1,",
"test.com", 80, { "127.0.0.1", }
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:0:127.0.0.1",
"test.com", 0, { "127.0.0.1", }
"test.com", 0, TRUE, { "127.0.0.1", }
},
{ "+test.com:80:127.0.0.1,",
"test.com", 80, FALSE, { "127.0.0.1", }
},
};
@ -188,10 +194,18 @@ UNITTEST_START
break;
}
if(dns->timestamp != 0) {
fprintf(stderr, "%s:%d tests[%d] failed. the timestamp is not zero. "
"for tests[%d].address[%d\n",
__FILE__, __LINE__, i, i, j);
if(dns->timestamp != 0 && tests[i].permanent) {
fprintf(stderr, "%s:%d tests[%d] failed. the timestamp is not zero "
"but tests[%d].permanent is TRUE\n",
__FILE__, __LINE__, i, i);
problem = true;
break;
}
if(dns->timestamp == 0 && !tests[i].permanent) {
fprintf(stderr, "%s:%d tests[%d] failed. the timestamp is zero "
"but tests[%d].permanent is FALSE\n",
__FILE__, __LINE__, i, i);
problem = true;
break;
}