urlapi: add CURLUPART_ZONEID to set and get

The zoneid can be used with IPv6 numerical addresses.

Updated test 1560 to verify.

Closes #3834
This commit is contained in:
Daniel Stenberg 2019-05-03 13:18:12 +02:00
parent 0eec832603
commit 2d0e9b40d3
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 74 additions and 23 deletions

View file

@ -38,6 +38,8 @@ we got https://[::1]/hello.html
we got https://example.com/hello.html
we got https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html
we got [fe80::20c:29ff:fe9c:409b]
we got eth0
we got https://[fe80::20c:29ff:fe9c:409b%25clown]/hello.html
success
</stdout>
</verify>

View file

@ -414,6 +414,10 @@ static int checkurl(const char *url, const char *out)
/* !checksrc! disable SPACEBEFORECOMMA 1 */
static struct setcase set_parts_list[] = {
{"https://[::1%25fake]:1234/",
"zoneid=NULL,",
"https://[::1]:1234/",
0, 0, CURLUE_OK, CURLUE_OK},
{"https://host:1234/",
"port=NULL,",
"https://host/",
@ -547,6 +551,8 @@ static CURLUPart part2id(char *part)
return CURLUPART_QUERY;
if(!strcmp("fragment", part))
return CURLUPART_FRAGMENT;
if(!strcmp("zoneid", part))
return CURLUPART_ZONEID;
return 9999; /* bad input => bad output */
}
@ -571,6 +577,9 @@ static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
/* for debugging this */
fprintf(stderr, "%s = %s [%d]\n", part, value, (int)what);
#endif
if(what > CURLUPART_ZONEID)
fprintf(stderr, "UNKNOWN part '%s'\n", part);
if(!strcmp("NULL", value))
uc = curl_url_set(u, what, NULL, setflags);
else if(!strcmp("\"\"", value))
@ -942,6 +951,35 @@ static int scopeid(void)
curl_free(url);
}
rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
if(rc != CURLUE_OK) {
fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d\n",
__FILE__, __LINE__, (int)rc);
error++;
}
else {
printf("we got %s\n", url);
curl_free(url);
}
rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
if(rc != CURLUE_OK) {
fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d\n",
__FILE__, __LINE__, (int)rc);
error++;
}
rc = curl_url_get(u, CURLUPART_URL, &url, 0);
if(rc != CURLUE_OK) {
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
__FILE__, __LINE__, (int)rc);
error++;
}
else {
printf("we got %s\n", url);
curl_free(url);
}
curl_url_cleanup(u);
return error;