xref: /third_party/curl/tests/libtest/lib1560.c (revision 13498266)
113498266Sopenharmony_ci/***************************************************************************
213498266Sopenharmony_ci *                                  _   _ ____  _
313498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci *                             / __| | | | |_) | |
513498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci *
813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci *
1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci *
1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci * KIND, either express or implied.
2013498266Sopenharmony_ci *
2113498266Sopenharmony_ci * SPDX-License-Identifier: curl
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci ***************************************************************************/
2413498266Sopenharmony_ci
2513498266Sopenharmony_ci/*
2613498266Sopenharmony_ci * Note:
2713498266Sopenharmony_ci *
2813498266Sopenharmony_ci * Since the URL parser by default only accepts schemes that *this instance*
2913498266Sopenharmony_ci * of libcurl supports, make sure that the test1560 file lists all the schemes
3013498266Sopenharmony_ci * that this test will assume to be present!
3113498266Sopenharmony_ci */
3213498266Sopenharmony_ci
3313498266Sopenharmony_ci#include "test.h"
3413498266Sopenharmony_ci#if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN)
3513498266Sopenharmony_ci#define USE_IDN
3613498266Sopenharmony_ci#endif
3713498266Sopenharmony_ci
3813498266Sopenharmony_ci#include "testutil.h"
3913498266Sopenharmony_ci#include "warnless.h"
4013498266Sopenharmony_ci#include "memdebug.h" /* LAST include file */
4113498266Sopenharmony_ci
4213498266Sopenharmony_cistruct part {
4313498266Sopenharmony_ci  CURLUPart part;
4413498266Sopenharmony_ci  const char *name;
4513498266Sopenharmony_ci};
4613498266Sopenharmony_ci
4713498266Sopenharmony_ci
4813498266Sopenharmony_cistatic int checkparts(CURLU *u, const char *in, const char *wanted,
4913498266Sopenharmony_ci                      unsigned int getflags)
5013498266Sopenharmony_ci{
5113498266Sopenharmony_ci  int i;
5213498266Sopenharmony_ci  CURLUcode rc;
5313498266Sopenharmony_ci  char buf[256];
5413498266Sopenharmony_ci  char *bufp = &buf[0];
5513498266Sopenharmony_ci  size_t len = sizeof(buf);
5613498266Sopenharmony_ci  struct part parts[] = {
5713498266Sopenharmony_ci    {CURLUPART_SCHEME, "scheme"},
5813498266Sopenharmony_ci    {CURLUPART_USER, "user"},
5913498266Sopenharmony_ci    {CURLUPART_PASSWORD, "password"},
6013498266Sopenharmony_ci    {CURLUPART_OPTIONS, "options"},
6113498266Sopenharmony_ci    {CURLUPART_HOST, "host"},
6213498266Sopenharmony_ci    {CURLUPART_PORT, "port"},
6313498266Sopenharmony_ci    {CURLUPART_PATH, "path"},
6413498266Sopenharmony_ci    {CURLUPART_QUERY, "query"},
6513498266Sopenharmony_ci    {CURLUPART_FRAGMENT, "fragment"},
6613498266Sopenharmony_ci    {CURLUPART_URL, NULL}
6713498266Sopenharmony_ci  };
6813498266Sopenharmony_ci  memset(buf, 0, sizeof(buf));
6913498266Sopenharmony_ci
7013498266Sopenharmony_ci  for(i = 0; parts[i].name; i++) {
7113498266Sopenharmony_ci    char *p = NULL;
7213498266Sopenharmony_ci    size_t n;
7313498266Sopenharmony_ci    rc = curl_url_get(u, parts[i].part, &p, getflags);
7413498266Sopenharmony_ci    if(!rc && p) {
7513498266Sopenharmony_ci      msnprintf(bufp, len, "%s%s", buf[0]?" | ":"", p);
7613498266Sopenharmony_ci    }
7713498266Sopenharmony_ci    else
7813498266Sopenharmony_ci      msnprintf(bufp, len, "%s[%d]", buf[0]?" | ":"", (int)rc);
7913498266Sopenharmony_ci
8013498266Sopenharmony_ci    n = strlen(bufp);
8113498266Sopenharmony_ci    bufp += n;
8213498266Sopenharmony_ci    len -= n;
8313498266Sopenharmony_ci    curl_free(p);
8413498266Sopenharmony_ci  }
8513498266Sopenharmony_ci  if(strcmp(buf, wanted)) {
8613498266Sopenharmony_ci    fprintf(stderr, "in: %s\nwanted: %s\ngot:    %s\n", in, wanted, buf);
8713498266Sopenharmony_ci    return 1;
8813498266Sopenharmony_ci  }
8913498266Sopenharmony_ci  return 0;
9013498266Sopenharmony_ci}
9113498266Sopenharmony_ci
9213498266Sopenharmony_cistruct redircase {
9313498266Sopenharmony_ci  const char *in;
9413498266Sopenharmony_ci  const char *set;
9513498266Sopenharmony_ci  const char *out;
9613498266Sopenharmony_ci  unsigned int urlflags;
9713498266Sopenharmony_ci  unsigned int setflags;
9813498266Sopenharmony_ci  CURLUcode ucode;
9913498266Sopenharmony_ci};
10013498266Sopenharmony_ci
10113498266Sopenharmony_cistruct setcase {
10213498266Sopenharmony_ci  const char *in;
10313498266Sopenharmony_ci  const char *set;
10413498266Sopenharmony_ci  const char *out;
10513498266Sopenharmony_ci  unsigned int urlflags;
10613498266Sopenharmony_ci  unsigned int setflags;
10713498266Sopenharmony_ci  CURLUcode ucode; /* for the main URL set */
10813498266Sopenharmony_ci  CURLUcode pcode; /* for updating parts */
10913498266Sopenharmony_ci};
11013498266Sopenharmony_ci
11113498266Sopenharmony_cistruct setgetcase {
11213498266Sopenharmony_ci  const char *in;
11313498266Sopenharmony_ci  const char *set;
11413498266Sopenharmony_ci  const char *out;
11513498266Sopenharmony_ci  unsigned int urlflags; /* for setting the URL */
11613498266Sopenharmony_ci  unsigned int setflags; /* for updating parts */
11713498266Sopenharmony_ci  unsigned int getflags; /* for getting parts */
11813498266Sopenharmony_ci  CURLUcode pcode; /* for updating parts */
11913498266Sopenharmony_ci};
12013498266Sopenharmony_ci
12113498266Sopenharmony_cistruct testcase {
12213498266Sopenharmony_ci  const char *in;
12313498266Sopenharmony_ci  const char *out;
12413498266Sopenharmony_ci  unsigned int urlflags;
12513498266Sopenharmony_ci  unsigned int getflags;
12613498266Sopenharmony_ci  CURLUcode ucode;
12713498266Sopenharmony_ci};
12813498266Sopenharmony_ci
12913498266Sopenharmony_cistruct urltestcase {
13013498266Sopenharmony_ci  const char *in;
13113498266Sopenharmony_ci  const char *out;
13213498266Sopenharmony_ci  unsigned int urlflags; /* pass to curl_url() */
13313498266Sopenharmony_ci  unsigned int getflags; /* pass to curl_url_get() */
13413498266Sopenharmony_ci  CURLUcode ucode;
13513498266Sopenharmony_ci};
13613498266Sopenharmony_ci
13713498266Sopenharmony_cistruct querycase {
13813498266Sopenharmony_ci  const char *in;
13913498266Sopenharmony_ci  const char *q;
14013498266Sopenharmony_ci  const char *out;
14113498266Sopenharmony_ci  unsigned int urlflags; /* pass to curl_url() */
14213498266Sopenharmony_ci  unsigned int qflags; /* pass to curl_url_get() */
14313498266Sopenharmony_ci  CURLUcode ucode;
14413498266Sopenharmony_ci};
14513498266Sopenharmony_ci
14613498266Sopenharmony_cistruct clearurlcase {
14713498266Sopenharmony_ci  CURLUPart part;
14813498266Sopenharmony_ci  const char *in;
14913498266Sopenharmony_ci  const char *out;
15013498266Sopenharmony_ci  CURLUcode ucode;
15113498266Sopenharmony_ci};
15213498266Sopenharmony_ci
15313498266Sopenharmony_cistatic const struct testcase get_parts_list[] ={
15413498266Sopenharmony_ci  {"https://curl.se/#  ",
15513498266Sopenharmony_ci   "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | %20%20",
15613498266Sopenharmony_ci   CURLU_URLENCODE|CURLU_ALLOW_SPACE, 0, CURLUE_OK},
15713498266Sopenharmony_ci  {"", "", 0, 0, CURLUE_MALFORMED_INPUT},
15813498266Sopenharmony_ci  {" ", "", 0, 0, CURLUE_MALFORMED_INPUT},
15913498266Sopenharmony_ci  {"1h://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
16013498266Sopenharmony_ci  {"..://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
16113498266Sopenharmony_ci  {"-ht://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
16213498266Sopenharmony_ci  {"+ftp://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
16313498266Sopenharmony_ci  {"hej.hej://example.net",
16413498266Sopenharmony_ci   "hej.hej | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
16513498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
16613498266Sopenharmony_ci  {"ht-tp://example.net",
16713498266Sopenharmony_ci   "ht-tp | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
16813498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
16913498266Sopenharmony_ci  {"ftp+more://example.net",
17013498266Sopenharmony_ci   "ftp+more | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
17113498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
17213498266Sopenharmony_ci  {"f1337://example.net",
17313498266Sopenharmony_ci   "f1337 | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
17413498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
17513498266Sopenharmony_ci  {"https://user@example.net?hello# space ",
17613498266Sopenharmony_ci   "https | user | [12] | [13] | example.net | [15] | / | hello | %20space%20",
17713498266Sopenharmony_ci   CURLU_ALLOW_SPACE|CURLU_URLENCODE, 0, CURLUE_OK},
17813498266Sopenharmony_ci  {"https://test%test", "", 0, 0, CURLUE_BAD_HOSTNAME},
17913498266Sopenharmony_ci  {"https://example.com%252f%40@example.net",
18013498266Sopenharmony_ci   "https | example.com%2f@ | [12] | [13] | example.net | [15] | / "
18113498266Sopenharmony_ci   "| [16] | [17]",
18213498266Sopenharmony_ci   0, CURLU_URLDECODE, CURLUE_OK },
18313498266Sopenharmony_ci#ifdef USE_IDN
18413498266Sopenharmony_ci  {"https://räksmörgås.se",
18513498266Sopenharmony_ci   "https | [11] | [12] | [13] | xn--rksmrgs-5wao1o.se | "
18613498266Sopenharmony_ci   "[15] | / | [16] | [17]", 0, CURLU_PUNYCODE, CURLUE_OK},
18713498266Sopenharmony_ci  {"https://xn--rksmrgs-5wao1o.se",
18813498266Sopenharmony_ci   "https | [11] | [12] | [13] | räksmörgås.se | "
18913498266Sopenharmony_ci   "[15] | / | [16] | [17]", 0, CURLU_PUNY2IDN, CURLUE_OK},
19013498266Sopenharmony_ci#else
19113498266Sopenharmony_ci  {"https://räksmörgås.se",
19213498266Sopenharmony_ci   "https | [11] | [12] | [13] | [30] | [15] | / | [16] | [17]",
19313498266Sopenharmony_ci   0, CURLU_PUNYCODE, CURLUE_OK},
19413498266Sopenharmony_ci#endif
19513498266Sopenharmony_ci  /* https://ℂᵤⓇℒ。�� */
19613498266Sopenharmony_ci  {"https://"
19713498266Sopenharmony_ci   "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
19813498266Sopenharmony_ci   "https | [11] | [12] | [13] | ℂᵤⓇℒ。�� | [15] |"
19913498266Sopenharmony_ci   " / | [16] | [17]",
20013498266Sopenharmony_ci   0, 0, CURLUE_OK},
20113498266Sopenharmony_ci  {"https://"
20213498266Sopenharmony_ci   "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
20313498266Sopenharmony_ci   "https | [11] | [12] | [13] | "
20413498266Sopenharmony_ci   "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4 "
20513498266Sopenharmony_ci   "| [15] | / | [16] | [17]",
20613498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK},
20713498266Sopenharmony_ci  {"https://"
20813498266Sopenharmony_ci   "\xe2\x84\x82\xe1\xb5\xa4\xe2\x93\x87\xe2\x84\x92"
20913498266Sopenharmony_ci   "\xe3\x80\x82\xf0\x9d\x90\x92\xf0\x9f\x84\xb4",
21013498266Sopenharmony_ci   "https | [11] | [12] | [13] | "
21113498266Sopenharmony_ci   "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4 "
21213498266Sopenharmony_ci   "| [15] | / | [16] | [17]",
21313498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK},
21413498266Sopenharmony_ci  {"https://user@example.net?he l lo",
21513498266Sopenharmony_ci   "https | user | [12] | [13] | example.net | [15] | / | he+l+lo | [17]",
21613498266Sopenharmony_ci   CURLU_ALLOW_SPACE, CURLU_URLENCODE, CURLUE_OK},
21713498266Sopenharmony_ci  {"https://user@example.net?he l lo",
21813498266Sopenharmony_ci   "https | user | [12] | [13] | example.net | [15] | / | he l lo | [17]",
21913498266Sopenharmony_ci   CURLU_ALLOW_SPACE, 0, CURLUE_OK},
22013498266Sopenharmony_ci  {"https://exam{}[]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22113498266Sopenharmony_ci  {"https://exam{ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22213498266Sopenharmony_ci  {"https://exam}ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22313498266Sopenharmony_ci  {"https://exam]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22413498266Sopenharmony_ci  {"https://exam\\ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22513498266Sopenharmony_ci  {"https://exam$ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22613498266Sopenharmony_ci  {"https://exam'ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22713498266Sopenharmony_ci  {"https://exam\"ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22813498266Sopenharmony_ci  {"https://exam^ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
22913498266Sopenharmony_ci  {"https://exam`ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23013498266Sopenharmony_ci  {"https://exam*ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23113498266Sopenharmony_ci  {"https://exam<ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23213498266Sopenharmony_ci  {"https://exam>ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23313498266Sopenharmony_ci  {"https://exam=ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23413498266Sopenharmony_ci  {"https://exam;ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23513498266Sopenharmony_ci  {"https://example,net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23613498266Sopenharmony_ci  {"https://example&net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23713498266Sopenharmony_ci  {"https://example+net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23813498266Sopenharmony_ci  {"https://example(net", "", 0, 0, CURLUE_BAD_HOSTNAME},
23913498266Sopenharmony_ci  {"https://example)net", "", 0, 0, CURLUE_BAD_HOSTNAME},
24013498266Sopenharmony_ci  {"https://example.net/}",
24113498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.net | [15] | /} | [16] | [17]",
24213498266Sopenharmony_ci   0, 0, CURLUE_OK},
24313498266Sopenharmony_ci
24413498266Sopenharmony_ci  /* blank user is blank */
24513498266Sopenharmony_ci  {"https://:password@example.net",
24613498266Sopenharmony_ci   "https |  | password | [13] | example.net | [15] | / | [16] | [17]",
24713498266Sopenharmony_ci   0, 0, CURLUE_OK},
24813498266Sopenharmony_ci  /* blank user + blank password */
24913498266Sopenharmony_ci  {"https://:@example.net",
25013498266Sopenharmony_ci   "https |  |  | [13] | example.net | [15] | / | [16] | [17]",
25113498266Sopenharmony_ci   0, 0, CURLUE_OK},
25213498266Sopenharmony_ci  /* user-only (no password) */
25313498266Sopenharmony_ci  {"https://user@example.net",
25413498266Sopenharmony_ci   "https | user | [12] | [13] | example.net | [15] | / | [16] | [17]",
25513498266Sopenharmony_ci   0, 0, CURLUE_OK},
25613498266Sopenharmony_ci#ifdef USE_WEBSOCKETS
25713498266Sopenharmony_ci  {"ws://example.com/color/?green",
25813498266Sopenharmony_ci   "ws | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
25913498266Sopenharmony_ci   " [17]",
26013498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
26113498266Sopenharmony_ci  {"wss://example.com/color/?green",
26213498266Sopenharmony_ci   "wss | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
26313498266Sopenharmony_ci   " [17]",
26413498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
26513498266Sopenharmony_ci#endif
26613498266Sopenharmony_ci
26713498266Sopenharmony_ci  {"https://user:password@example.net/get?this=and#but frag then", "",
26813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
26913498266Sopenharmony_ci  {"https://user:password@example.net/get?this=and what", "",
27013498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
27113498266Sopenharmony_ci  {"https://user:password@example.net/ge t?this=and-what", "",
27213498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
27313498266Sopenharmony_ci  {"https://user:pass word@example.net/get?this=and-what", "",
27413498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
27513498266Sopenharmony_ci  {"https://u ser:password@example.net/get?this=and-what", "",
27613498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
27713498266Sopenharmony_ci  {"imap://user:pass;opt ion@server/path", "",
27813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
27913498266Sopenharmony_ci  /* no space allowed in scheme */
28013498266Sopenharmony_ci  {"htt ps://user:password@example.net/get?this=and-what", "",
28113498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME|CURLU_ALLOW_SPACE, 0, CURLUE_BAD_SCHEME},
28213498266Sopenharmony_ci  {"https://user:password@example.net/get?this=and what",
28313498266Sopenharmony_ci   "https | user | password | [13] | example.net | [15] | /get | "
28413498266Sopenharmony_ci   "this=and what | [17]",
28513498266Sopenharmony_ci   CURLU_ALLOW_SPACE, 0, CURLUE_OK},
28613498266Sopenharmony_ci  {"https://user:password@example.net/ge t?this=and-what",
28713498266Sopenharmony_ci   "https | user | password | [13] | example.net | [15] | /ge t | "
28813498266Sopenharmony_ci   "this=and-what | [17]",
28913498266Sopenharmony_ci   CURLU_ALLOW_SPACE, 0, CURLUE_OK},
29013498266Sopenharmony_ci  {"https://user:pass word@example.net/get?this=and-what",
29113498266Sopenharmony_ci   "https | user | pass word | [13] | example.net | [15] | /get | "
29213498266Sopenharmony_ci   "this=and-what | [17]",
29313498266Sopenharmony_ci   CURLU_ALLOW_SPACE, 0, CURLUE_OK},
29413498266Sopenharmony_ci  {"https://u ser:password@example.net/get?this=and-what",
29513498266Sopenharmony_ci   "https | u ser | password | [13] | example.net | [15] | /get | "
29613498266Sopenharmony_ci   "this=and-what | [17]",
29713498266Sopenharmony_ci   CURLU_ALLOW_SPACE, 0, CURLUE_OK},
29813498266Sopenharmony_ci  {"https://user:password@example.net/ge t?this=and-what",
29913498266Sopenharmony_ci   "https | user | password | [13] | example.net | [15] | /ge%20t | "
30013498266Sopenharmony_ci   "this=and-what | [17]",
30113498266Sopenharmony_ci   CURLU_ALLOW_SPACE | CURLU_URLENCODE, 0, CURLUE_OK},
30213498266Sopenharmony_ci  {"[0:0:0:0:0:0:0:1]",
30313498266Sopenharmony_ci   "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
30413498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK },
30513498266Sopenharmony_ci  {"[::1]",
30613498266Sopenharmony_ci   "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
30713498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK },
30813498266Sopenharmony_ci  {"[::]",
30913498266Sopenharmony_ci   "http | [11] | [12] | [13] | [::] | [15] | / | [16] | [17]",
31013498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK },
31113498266Sopenharmony_ci  {"https://[::1]",
31213498266Sopenharmony_ci   "https | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
31313498266Sopenharmony_ci   0, 0, CURLUE_OK },
31413498266Sopenharmony_ci  {"user:moo@ftp.example.com/color/#green?no-red",
31513498266Sopenharmony_ci   "ftp | user | moo | [13] | ftp.example.com | [15] | /color/ | [16] | "
31613498266Sopenharmony_ci   "green?no-red",
31713498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK },
31813498266Sopenharmony_ci  {"ftp.user:moo@example.com/color/#green?no-red",
31913498266Sopenharmony_ci   "http | ftp.user | moo | [13] | example.com | [15] | /color/ | [16] | "
32013498266Sopenharmony_ci   "green?no-red",
32113498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK },
32213498266Sopenharmony_ci#ifdef _WIN32
32313498266Sopenharmony_ci  {"file:/C:\\programs\\foo",
32413498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
32513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
32613498266Sopenharmony_ci  {"file://C:\\programs\\foo",
32713498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
32813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
32913498266Sopenharmony_ci  {"file:///C:\\programs\\foo",
33013498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
33113498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
33213498266Sopenharmony_ci  {"file://host.example.com/Share/path/to/file.txt",
33313498266Sopenharmony_ci   "file | [11] | [12] | [13] | host.example.com | [15] | "
33413498266Sopenharmony_ci   "//host.example.com/Share/path/to/file.txt | [16] | [17]",
33513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
33613498266Sopenharmony_ci#endif
33713498266Sopenharmony_ci  {"https://example.com/color/#green?no-red",
33813498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
33913498266Sopenharmony_ci   "green?no-red",
34013498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
34113498266Sopenharmony_ci  {"https://example.com/color/#green#no-red",
34213498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
34313498266Sopenharmony_ci   "green#no-red",
34413498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
34513498266Sopenharmony_ci  {"https://example.com/color/?green#no-red",
34613498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /color/ | green | "
34713498266Sopenharmony_ci   "no-red",
34813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
34913498266Sopenharmony_ci  {"https://example.com/#color/?green#no-red",
35013498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | / | [16] | "
35113498266Sopenharmony_ci   "color/?green#no-red",
35213498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
35313498266Sopenharmony_ci  {"https://example.#com/color/?green#no-red",
35413498266Sopenharmony_ci   "https | [11] | [12] | [13] | example. | [15] | / | [16] | "
35513498266Sopenharmony_ci   "com/color/?green#no-red",
35613498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
35713498266Sopenharmony_ci  {"http://[ab.be:1]/x", "",
35813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
35913498266Sopenharmony_ci  {"http://[ab.be]/x", "",
36013498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
36113498266Sopenharmony_ci  /* URL without host name */
36213498266Sopenharmony_ci  {"http://a:b@/x", "",
36313498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_NO_HOST},
36413498266Sopenharmony_ci  {"boing:80",
36513498266Sopenharmony_ci   "https | [11] | [12] | [13] | boing | 80 | / | [16] | [17]",
36613498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME|CURLU_GUESS_SCHEME, 0, CURLUE_OK},
36713498266Sopenharmony_ci  {"http://[fd00:a41::50]:8080",
36813498266Sopenharmony_ci   "http | [11] | [12] | [13] | [fd00:a41::50] | 8080 | / | [16] | [17]",
36913498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
37013498266Sopenharmony_ci  {"http://[fd00:a41::50]/",
37113498266Sopenharmony_ci   "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
37213498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
37313498266Sopenharmony_ci  {"http://[fd00:a41::50]",
37413498266Sopenharmony_ci   "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
37513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
37613498266Sopenharmony_ci  {"https://[::1%252]:1234",
37713498266Sopenharmony_ci   "https | [11] | [12] | [13] | [::1] | 1234 | / | [16] | [17]",
37813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
37913498266Sopenharmony_ci
38013498266Sopenharmony_ci  /* here's "bad" zone id */
38113498266Sopenharmony_ci  {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
38213498266Sopenharmony_ci   "https | [11] | [12] | [13] | [fe80::20c:29ff:fe9c:409b] | 1234 "
38313498266Sopenharmony_ci   "| / | [16] | [17]",
38413498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
38513498266Sopenharmony_ci  {"https://127.0.0.1:443",
38613498266Sopenharmony_ci   "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
38713498266Sopenharmony_ci   0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
38813498266Sopenharmony_ci  {"http://%3a:%3a@ex4mple/%3f+?+%3f+%23#+%23%3f%g7",
38913498266Sopenharmony_ci   "http | : | : | [13] | ex4mple | [15] | /?+ |  ? # | +#?%g7",
39013498266Sopenharmony_ci   0, CURLU_URLDECODE, CURLUE_OK},
39113498266Sopenharmony_ci  {"http://%3a:%3a@ex4mple/%3f?%3f%35#%35%3f%g7",
39213498266Sopenharmony_ci   "http | %3a | %3a | [13] | ex4mple | [15] | /%3f | %3f%35 | %35%3f%g7",
39313498266Sopenharmony_ci   0, 0, CURLUE_OK},
39413498266Sopenharmony_ci  {"http://HO0_-st%41/",
39513498266Sopenharmony_ci   "http | [11] | [12] | [13] | HO0_-stA | [15] | / | [16] | [17]",
39613498266Sopenharmony_ci   0, 0, CURLUE_OK},
39713498266Sopenharmony_ci  {"file://hello.html",
39813498266Sopenharmony_ci   "",
39913498266Sopenharmony_ci   0, 0, CURLUE_BAD_FILE_URL},
40013498266Sopenharmony_ci  {"http://HO0_-st/",
40113498266Sopenharmony_ci   "http | [11] | [12] | [13] | HO0_-st | [15] | / | [16] | [17]",
40213498266Sopenharmony_ci   0, 0, CURLUE_OK},
40313498266Sopenharmony_ci  {"imap://user:pass;option@server/path",
40413498266Sopenharmony_ci   "imap | user | pass | option | server | [15] | /path | [16] | [17]",
40513498266Sopenharmony_ci   0, 0, CURLUE_OK},
40613498266Sopenharmony_ci  {"http://user:pass;option@server/path",
40713498266Sopenharmony_ci   "http | user | pass;option | [13] | server | [15] | /path | [16] | [17]",
40813498266Sopenharmony_ci   0, 0, CURLUE_OK},
40913498266Sopenharmony_ci  {"file:/hello.html",
41013498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
41113498266Sopenharmony_ci   0, 0, CURLUE_OK},
41213498266Sopenharmony_ci  {"file:/h",
41313498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | /h | [16] | [17]",
41413498266Sopenharmony_ci   0, 0, CURLUE_OK},
41513498266Sopenharmony_ci  {"file:/",
41613498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | | [16] | [17]",
41713498266Sopenharmony_ci   0, 0, CURLUE_BAD_FILE_URL},
41813498266Sopenharmony_ci  {"file://127.0.0.1/hello.html",
41913498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
42013498266Sopenharmony_ci   0, 0, CURLUE_OK},
42113498266Sopenharmony_ci  {"file:////hello.html",
42213498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | //hello.html | [16] | [17]",
42313498266Sopenharmony_ci   0, 0, CURLUE_OK},
42413498266Sopenharmony_ci  {"file:///hello.html",
42513498266Sopenharmony_ci   "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
42613498266Sopenharmony_ci   0, 0, CURLUE_OK},
42713498266Sopenharmony_ci  {"https://127.0.0.1",
42813498266Sopenharmony_ci   "https | [11] | [12] | [13] | 127.0.0.1 | 443 | / | [16] | [17]",
42913498266Sopenharmony_ci   0, CURLU_DEFAULT_PORT, CURLUE_OK},
43013498266Sopenharmony_ci  {"https://127.0.0.1",
43113498266Sopenharmony_ci   "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
43213498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
43313498266Sopenharmony_ci  {"https://[::1]:1234",
43413498266Sopenharmony_ci   "https | [11] | [12] | [13] | [::1] | 1234 | / | [16] | [17]",
43513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
43613498266Sopenharmony_ci  {"https://127abc.com",
43713498266Sopenharmony_ci   "https | [11] | [12] | [13] | 127abc.com | [15] | / | [16] | [17]",
43813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
43913498266Sopenharmony_ci  {"https:// example.com?check", "",
44013498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
44113498266Sopenharmony_ci  {"https://e x a m p l e.com?check", "",
44213498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
44313498266Sopenharmony_ci  {"https://example.com?check",
44413498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | / | check | [17]",
44513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
44613498266Sopenharmony_ci  {"https://example.com:65536",
44713498266Sopenharmony_ci   "",
44813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
44913498266Sopenharmony_ci  {"https://example.com:-1#moo",
45013498266Sopenharmony_ci   "",
45113498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
45213498266Sopenharmony_ci  {"https://example.com:0#moo",
45313498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | 0 | / | "
45413498266Sopenharmony_ci   "[16] | moo",
45513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
45613498266Sopenharmony_ci  {"https://example.com:01#moo",
45713498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | 1 | / | "
45813498266Sopenharmony_ci   "[16] | moo",
45913498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
46013498266Sopenharmony_ci  {"https://example.com:1#moo",
46113498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | 1 | / | "
46213498266Sopenharmony_ci   "[16] | moo",
46313498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
46413498266Sopenharmony_ci  {"http://example.com#moo",
46513498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | [15] | / | "
46613498266Sopenharmony_ci   "[16] | moo",
46713498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
46813498266Sopenharmony_ci  {"http://example.com",
46913498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | [15] | / | "
47013498266Sopenharmony_ci   "[16] | [17]",
47113498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
47213498266Sopenharmony_ci  {"http://example.com/path/html",
47313498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
47413498266Sopenharmony_ci   "[16] | [17]",
47513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
47613498266Sopenharmony_ci  {"http://example.com/path/html?query=name",
47713498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
47813498266Sopenharmony_ci   "query=name | [17]",
47913498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
48013498266Sopenharmony_ci  {"http://example.com/path/html?query=name#anchor",
48113498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
48213498266Sopenharmony_ci   "query=name | anchor",
48313498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
48413498266Sopenharmony_ci  {"http://example.com:1234/path/html?query=name#anchor",
48513498266Sopenharmony_ci   "http | [11] | [12] | [13] | example.com | 1234 | /path/html | "
48613498266Sopenharmony_ci   "query=name | anchor",
48713498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
48813498266Sopenharmony_ci  {"http:///user:password@example.com:1234/path/html?query=name#anchor",
48913498266Sopenharmony_ci   "http | user | password | [13] | example.com | 1234 | /path/html | "
49013498266Sopenharmony_ci   "query=name | anchor",
49113498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
49213498266Sopenharmony_ci  {"https://user:password@example.com:1234/path/html?query=name#anchor",
49313498266Sopenharmony_ci   "https | user | password | [13] | example.com | 1234 | /path/html | "
49413498266Sopenharmony_ci   "query=name | anchor",
49513498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
49613498266Sopenharmony_ci  {"http://user:password@example.com:1234/path/html?query=name#anchor",
49713498266Sopenharmony_ci   "http | user | password | [13] | example.com | 1234 | /path/html | "
49813498266Sopenharmony_ci   "query=name | anchor",
49913498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
50013498266Sopenharmony_ci  {"http:/user:password@example.com:1234/path/html?query=name#anchor",
50113498266Sopenharmony_ci   "http | user | password | [13] | example.com | 1234 | /path/html | "
50213498266Sopenharmony_ci   "query=name | anchor",
50313498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
50413498266Sopenharmony_ci  {"http:////user:password@example.com:1234/path/html?query=name#anchor",
50513498266Sopenharmony_ci   "",
50613498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_SLASHES},
50713498266Sopenharmony_ci  {NULL, NULL, 0, 0, CURLUE_OK},
50813498266Sopenharmony_ci};
50913498266Sopenharmony_ci
51013498266Sopenharmony_cistatic const struct urltestcase get_url_list[] = {
51113498266Sopenharmony_ci  {"https://1.0x1000000", "https://1.0x1000000/", 0, 0, CURLUE_OK},
51213498266Sopenharmony_ci  {"https://0x7f.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
51313498266Sopenharmony_ci  {"https://1.2.3.256.com", "https://1.2.3.256.com/", 0, 0, CURLUE_OK},
51413498266Sopenharmony_ci  {"https://10.com", "https://10.com/", 0, 0, CURLUE_OK},
51513498266Sopenharmony_ci  {"https://1.2.com", "https://1.2.com/", 0, 0, CURLUE_OK},
51613498266Sopenharmony_ci  {"https://1.2.3.com", "https://1.2.3.com/", 0, 0, CURLUE_OK},
51713498266Sopenharmony_ci  {"https://1.2.com.99", "https://1.2.com.99/", 0, 0, CURLUE_OK},
51813498266Sopenharmony_ci  {"https://[fe80::0000:20c:29ff:fe9c:409b]:80/moo",
51913498266Sopenharmony_ci   "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
52013498266Sopenharmony_ci   0, 0, CURLUE_OK},
52113498266Sopenharmony_ci  {"https://[fe80::020c:29ff:fe9c:409b]:80/moo",
52213498266Sopenharmony_ci   "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
52313498266Sopenharmony_ci   0, 0, CURLUE_OK},
52413498266Sopenharmony_ci  {"https://[fe80:0000:0000:0000:020c:29ff:fe9c:409b]:80/moo",
52513498266Sopenharmony_ci   "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
52613498266Sopenharmony_ci   0, 0, CURLUE_OK},
52713498266Sopenharmony_ci  {"https://[fe80:0:0:0:409b::]:80/moo",
52813498266Sopenharmony_ci   "https://[fe80::409b:0:0:0]:80/moo",
52913498266Sopenharmony_ci   0, 0, CURLUE_OK},
53013498266Sopenharmony_ci  {"https://[::%25fakeit];80/moo",
53113498266Sopenharmony_ci   "",
53213498266Sopenharmony_ci   0, 0, CURLUE_BAD_PORT_NUMBER},
53313498266Sopenharmony_ci  {"https://[fe80::20c:29ff:fe9c:409b]-80/moo",
53413498266Sopenharmony_ci   "",
53513498266Sopenharmony_ci   0, 0, CURLUE_BAD_PORT_NUMBER},
53613498266Sopenharmony_ci#ifdef USE_IDN
53713498266Sopenharmony_ci  {"https://räksmörgås.se/path?q#frag",
53813498266Sopenharmony_ci   "https://xn--rksmrgs-5wao1o.se/path?q#frag", 0, CURLU_PUNYCODE, CURLUE_OK},
53913498266Sopenharmony_ci#endif
54013498266Sopenharmony_ci  /* unsupported schemes with no guessing enabled */
54113498266Sopenharmony_ci  {"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIEhUTUw+PG1ldGEgY",
54213498266Sopenharmony_ci   "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
54313498266Sopenharmony_ci  {"d:anything-really", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
54413498266Sopenharmony_ci  {"about:config", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
54513498266Sopenharmony_ci  {"example://foo", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
54613498266Sopenharmony_ci  {"mailto:infobot@example.com?body=send%20current-issue", "", 0, 0,
54713498266Sopenharmony_ci   CURLUE_UNSUPPORTED_SCHEME},
54813498266Sopenharmony_ci  {"about:80", "https://about:80/", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
54913498266Sopenharmony_ci  /* percent encoded host names */
55013498266Sopenharmony_ci  {"http://example.com%40127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55113498266Sopenharmony_ci  {"http://example.com%21127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55213498266Sopenharmony_ci  {"http://example.com%3f127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55313498266Sopenharmony_ci  {"http://example.com%23127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55413498266Sopenharmony_ci  {"http://example.com%3a127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55513498266Sopenharmony_ci  {"http://example.com%09127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55613498266Sopenharmony_ci  {"http://example.com%2F127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
55713498266Sopenharmony_ci  {"https://%41", "https://A/", 0, 0, CURLUE_OK},
55813498266Sopenharmony_ci  {"https://%20", "", 0, 0, CURLUE_BAD_HOSTNAME},
55913498266Sopenharmony_ci  {"https://%41%0d", "", 0, 0, CURLUE_BAD_HOSTNAME},
56013498266Sopenharmony_ci  {"https://%25", "", 0, 0, CURLUE_BAD_HOSTNAME},
56113498266Sopenharmony_ci  {"https://_%c0_", "https://_\xC0_/", 0, 0, CURLUE_OK},
56213498266Sopenharmony_ci  {"https://_%c0_", "https://_%C0_/", 0, CURLU_URLENCODE, CURLUE_OK},
56313498266Sopenharmony_ci
56413498266Sopenharmony_ci  /* IPv4 trickeries */
56513498266Sopenharmony_ci  {"https://16843009", "https://1.1.1.1/", 0, 0, CURLUE_OK},
56613498266Sopenharmony_ci  {"https://0177.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
56713498266Sopenharmony_ci  {"https://0111.02.0x3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
56813498266Sopenharmony_ci  {"https://0111.02.0x3.", "https://0111.02.0x3./", 0, 0, CURLUE_OK},
56913498266Sopenharmony_ci  {"https://0111.02.030", "https://73.2.0.24/", 0, 0, CURLUE_OK},
57013498266Sopenharmony_ci  {"https://0111.02.030.", "https://0111.02.030./", 0, 0, CURLUE_OK},
57113498266Sopenharmony_ci  {"https://0xff.0xff.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
57213498266Sopenharmony_ci  {"https://1.0xffffff", "https://1.255.255.255/", 0, 0, CURLUE_OK},
57313498266Sopenharmony_ci  /* IPv4 numerical overflows or syntax errors will not normalize */
57413498266Sopenharmony_ci  {"https://a127.0.0.1", "https://a127.0.0.1/", 0, 0, CURLUE_OK},
57513498266Sopenharmony_ci  {"https://\xff.127.0.0.1", "https://%FF.127.0.0.1/", 0, CURLU_URLENCODE,
57613498266Sopenharmony_ci   CURLUE_OK},
57713498266Sopenharmony_ci  {"https://127.-0.0.1", "https://127.-0.0.1/", 0, 0, CURLUE_OK},
57813498266Sopenharmony_ci  {"https://127.0. 1", "https://127.0.0.1/", 0, 0, CURLUE_MALFORMED_INPUT},
57913498266Sopenharmony_ci  {"https://1.2.3.256", "https://1.2.3.256/", 0, 0, CURLUE_OK},
58013498266Sopenharmony_ci  {"https://1.2.3.256.", "https://1.2.3.256./", 0, 0, CURLUE_OK},
58113498266Sopenharmony_ci  {"https://1.2.3.4.5", "https://1.2.3.4.5/", 0, 0, CURLUE_OK},
58213498266Sopenharmony_ci  {"https://1.2.0x100.3", "https://1.2.0x100.3/", 0, 0, CURLUE_OK},
58313498266Sopenharmony_ci  {"https://4294967296", "https://4294967296/", 0, 0, CURLUE_OK},
58413498266Sopenharmony_ci  {"https://123host", "https://123host/", 0, 0, CURLUE_OK},
58513498266Sopenharmony_ci  /* 40 bytes scheme is the max allowed */
58613498266Sopenharmony_ci  {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
58713498266Sopenharmony_ci   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa://hostname/path",
58813498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
58913498266Sopenharmony_ci  /* 41 bytes scheme is not allowed */
59013498266Sopenharmony_ci  {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
59113498266Sopenharmony_ci   "",
59213498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_BAD_SCHEME},
59313498266Sopenharmony_ci  {"https://[fe80::20c:29ff:fe9c:409b%]:1234",
59413498266Sopenharmony_ci   "",
59513498266Sopenharmony_ci   0, 0, CURLUE_BAD_IPV6},
59613498266Sopenharmony_ci  {"https://[fe80::20c:29ff:fe9c:409b%25]:1234",
59713498266Sopenharmony_ci   "https://[fe80::20c:29ff:fe9c:409b%2525]:1234/",
59813498266Sopenharmony_ci   0, 0, CURLUE_OK},
59913498266Sopenharmony_ci  {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
60013498266Sopenharmony_ci   "https://[fe80::20c:29ff:fe9c:409b%25eth0]:1234/",
60113498266Sopenharmony_ci   0, 0, CURLUE_OK},
60213498266Sopenharmony_ci  {"https://[::%25fakeit]/moo",
60313498266Sopenharmony_ci   "https://[::%25fakeit]/moo",
60413498266Sopenharmony_ci   0, 0, CURLUE_OK},
60513498266Sopenharmony_ci  {"smtp.example.com/path/html",
60613498266Sopenharmony_ci   "smtp://smtp.example.com/path/html",
60713498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
60813498266Sopenharmony_ci  {"https.example.com/path/html",
60913498266Sopenharmony_ci   "http://https.example.com/path/html",
61013498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
61113498266Sopenharmony_ci  {"dict.example.com/path/html",
61213498266Sopenharmony_ci   "dict://dict.example.com/path/html",
61313498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
61413498266Sopenharmony_ci  {"pop3.example.com/path/html",
61513498266Sopenharmony_ci   "pop3://pop3.example.com/path/html",
61613498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
61713498266Sopenharmony_ci  {"ldap.example.com/path/html",
61813498266Sopenharmony_ci   "ldap://ldap.example.com/path/html",
61913498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
62013498266Sopenharmony_ci  {"imap.example.com/path/html",
62113498266Sopenharmony_ci   "imap://imap.example.com/path/html",
62213498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
62313498266Sopenharmony_ci  {"ftp.example.com/path/html",
62413498266Sopenharmony_ci   "ftp://ftp.example.com/path/html",
62513498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
62613498266Sopenharmony_ci  {"example.com/path/html",
62713498266Sopenharmony_ci   "http://example.com/path/html",
62813498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
62913498266Sopenharmony_ci  {"smtp.com/path/html",
63013498266Sopenharmony_ci   "smtp://smtp.com/path/html",
63113498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
63213498266Sopenharmony_ci  {"dict.com/path/html",
63313498266Sopenharmony_ci   "dict://dict.com/path/html",
63413498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
63513498266Sopenharmony_ci  {"pop3.com/path/html",
63613498266Sopenharmony_ci   "pop3://pop3.com/path/html",
63713498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
63813498266Sopenharmony_ci  {"ldap.com/path/html",
63913498266Sopenharmony_ci   "ldap://ldap.com/path/html",
64013498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
64113498266Sopenharmony_ci  {"imap.com/path/html",
64213498266Sopenharmony_ci   "imap://imap.com/path/html",
64313498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
64413498266Sopenharmony_ci  {"ftp.com/path/html",
64513498266Sopenharmony_ci   "ftp://ftp.com/path/html",
64613498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
64713498266Sopenharmony_ci  {"smtp/path/html",
64813498266Sopenharmony_ci   "http://smtp/path/html",
64913498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
65013498266Sopenharmony_ci  {"dict/path/html",
65113498266Sopenharmony_ci   "http://dict/path/html",
65213498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
65313498266Sopenharmony_ci  {"pop3/path/html",
65413498266Sopenharmony_ci   "http://pop3/path/html",
65513498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
65613498266Sopenharmony_ci  {"ldap/path/html",
65713498266Sopenharmony_ci   "http://ldap/path/html",
65813498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
65913498266Sopenharmony_ci  {"imap/path/html",
66013498266Sopenharmony_ci   "http://imap/path/html",
66113498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
66213498266Sopenharmony_ci  {"ftp/path/html",
66313498266Sopenharmony_ci   "http://ftp/path/html",
66413498266Sopenharmony_ci   CURLU_GUESS_SCHEME, 0, CURLUE_OK},
66513498266Sopenharmony_ci  {"HTTP://test/", "http://test/", 0, 0, CURLUE_OK},
66613498266Sopenharmony_ci  {"http://HO0_-st..~./", "http://HO0_-st..~./", 0, 0, CURLUE_OK},
66713498266Sopenharmony_ci  {"http:/@example.com: 123/", "", 0, 0, CURLUE_MALFORMED_INPUT},
66813498266Sopenharmony_ci  {"http:/@example.com:123 /", "", 0, 0, CURLUE_MALFORMED_INPUT},
66913498266Sopenharmony_ci  {"http:/@example.com:123a/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
67013498266Sopenharmony_ci  {"http://host/file\r", "", 0, 0, CURLUE_MALFORMED_INPUT},
67113498266Sopenharmony_ci  {"http://host/file\n\x03", "", 0, 0, CURLUE_MALFORMED_INPUT},
67213498266Sopenharmony_ci  {"htt\x02://host/file", "",
67313498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
67413498266Sopenharmony_ci  {" http://host/file", "", 0, 0, CURLUE_MALFORMED_INPUT},
67513498266Sopenharmony_ci  /* here the password ends at the semicolon and options is 'word' */
67613498266Sopenharmony_ci  {"imap://user:pass;word@host/file",
67713498266Sopenharmony_ci   "imap://user:pass;word@host/file",
67813498266Sopenharmony_ci   0, 0, CURLUE_OK},
67913498266Sopenharmony_ci  /* here the password has the semicolon */
68013498266Sopenharmony_ci  {"http://user:pass;word@host/file",
68113498266Sopenharmony_ci   "http://user:pass;word@host/file", 0, 0, CURLUE_OK},
68213498266Sopenharmony_ci  {"file:///file.txt#moo", "file:///file.txt#moo", 0, 0, CURLUE_OK},
68313498266Sopenharmony_ci  {"file:////file.txt", "file:////file.txt", 0, 0, CURLUE_OK},
68413498266Sopenharmony_ci  {"file:///file.txt", "file:///file.txt", 0, 0, CURLUE_OK},
68513498266Sopenharmony_ci  {"file:./", "file://", 0, 0, CURLUE_OK},
68613498266Sopenharmony_ci  {"http://example.com/hello/../here",
68713498266Sopenharmony_ci   "http://example.com/hello/../here",
68813498266Sopenharmony_ci   CURLU_PATH_AS_IS, 0, CURLUE_OK},
68913498266Sopenharmony_ci  {"http://example.com/hello/../here",
69013498266Sopenharmony_ci   "http://example.com/here",
69113498266Sopenharmony_ci   0, 0, CURLUE_OK},
69213498266Sopenharmony_ci  {"http://example.com:80",
69313498266Sopenharmony_ci   "http://example.com/",
69413498266Sopenharmony_ci   0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
69513498266Sopenharmony_ci  {"tp://example.com/path/html",
69613498266Sopenharmony_ci   "",
69713498266Sopenharmony_ci   0, 0, CURLUE_UNSUPPORTED_SCHEME},
69813498266Sopenharmony_ci  {"http://hello:fool@example.com",
69913498266Sopenharmony_ci   "",
70013498266Sopenharmony_ci   CURLU_DISALLOW_USER, 0, CURLUE_USER_NOT_ALLOWED},
70113498266Sopenharmony_ci  {"http:/@example.com:123",
70213498266Sopenharmony_ci   "http://@example.com:123/",
70313498266Sopenharmony_ci   0, 0, CURLUE_OK},
70413498266Sopenharmony_ci  {"http:/:password@example.com",
70513498266Sopenharmony_ci   "http://:password@example.com/",
70613498266Sopenharmony_ci   0, 0, CURLUE_OK},
70713498266Sopenharmony_ci  {"http://user@example.com?#",
70813498266Sopenharmony_ci   "http://user@example.com/",
70913498266Sopenharmony_ci   0, 0, CURLUE_OK},
71013498266Sopenharmony_ci  {"http://user@example.com?",
71113498266Sopenharmony_ci   "http://user@example.com/",
71213498266Sopenharmony_ci   0, 0, CURLUE_OK},
71313498266Sopenharmony_ci  {"http://user@example.com#anchor",
71413498266Sopenharmony_ci   "http://user@example.com/#anchor",
71513498266Sopenharmony_ci   0, 0, CURLUE_OK},
71613498266Sopenharmony_ci  {"example.com/path/html",
71713498266Sopenharmony_ci   "https://example.com/path/html",
71813498266Sopenharmony_ci   CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
71913498266Sopenharmony_ci  {"example.com/path/html",
72013498266Sopenharmony_ci   "",
72113498266Sopenharmony_ci   0, 0, CURLUE_BAD_SCHEME},
72213498266Sopenharmony_ci  {"http://user:password@example.com:1234/path/html?query=name#anchor",
72313498266Sopenharmony_ci   "http://user:password@example.com:1234/path/html?query=name#anchor",
72413498266Sopenharmony_ci   0, 0, CURLUE_OK},
72513498266Sopenharmony_ci  {"http://example.com:1234/path/html?query=name#anchor",
72613498266Sopenharmony_ci   "http://example.com:1234/path/html?query=name#anchor",
72713498266Sopenharmony_ci   0, 0, CURLUE_OK},
72813498266Sopenharmony_ci  {"http://example.com/path/html?query=name#anchor",
72913498266Sopenharmony_ci   "http://example.com/path/html?query=name#anchor",
73013498266Sopenharmony_ci   0, 0, CURLUE_OK},
73113498266Sopenharmony_ci  {"http://example.com/path/html?query=name",
73213498266Sopenharmony_ci   "http://example.com/path/html?query=name",
73313498266Sopenharmony_ci   0, 0, CURLUE_OK},
73413498266Sopenharmony_ci  {"http://example.com/path/html",
73513498266Sopenharmony_ci   "http://example.com/path/html",
73613498266Sopenharmony_ci   0, 0, CURLUE_OK},
73713498266Sopenharmony_ci  {"tp://example.com/path/html",
73813498266Sopenharmony_ci   "tp://example.com/path/html",
73913498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
74013498266Sopenharmony_ci  {"custom-scheme://host?expected=test-good",
74113498266Sopenharmony_ci   "custom-scheme://host/?expected=test-good",
74213498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
74313498266Sopenharmony_ci  {"custom-scheme://?expected=test-bad",
74413498266Sopenharmony_ci   "",
74513498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_NO_HOST},
74613498266Sopenharmony_ci  {"custom-scheme://?expected=test-new-good",
74713498266Sopenharmony_ci   "custom-scheme:///?expected=test-new-good",
74813498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
74913498266Sopenharmony_ci  {"custom-scheme://host?expected=test-still-good",
75013498266Sopenharmony_ci   "custom-scheme://host/?expected=test-still-good",
75113498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
75213498266Sopenharmony_ci  {NULL, NULL, 0, 0, CURLUE_OK}
75313498266Sopenharmony_ci};
75413498266Sopenharmony_ci
75513498266Sopenharmony_cistatic int checkurl(const char *org, const char *url, const char *out)
75613498266Sopenharmony_ci{
75713498266Sopenharmony_ci  if(strcmp(out, url)) {
75813498266Sopenharmony_ci    fprintf(stderr,
75913498266Sopenharmony_ci            "Org:    %s\n"
76013498266Sopenharmony_ci            "Wanted: %s\n"
76113498266Sopenharmony_ci            "Got   : %s\n",
76213498266Sopenharmony_ci            org, out, url);
76313498266Sopenharmony_ci    return 1;
76413498266Sopenharmony_ci  }
76513498266Sopenharmony_ci  return 0;
76613498266Sopenharmony_ci}
76713498266Sopenharmony_ci
76813498266Sopenharmony_ci/* 1. Set the URL
76913498266Sopenharmony_ci   2. Set components
77013498266Sopenharmony_ci   3. Extract all components (not URL)
77113498266Sopenharmony_ci*/
77213498266Sopenharmony_cistatic const struct setgetcase setget_parts_list[] = {
77313498266Sopenharmony_ci  {"https://example.com",
77413498266Sopenharmony_ci   "path=get,",
77513498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
77613498266Sopenharmony_ci   0, 0, 0, CURLUE_OK},
77713498266Sopenharmony_ci  {"https://example.com",
77813498266Sopenharmony_ci   "path=/get,",
77913498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
78013498266Sopenharmony_ci   0, 0, 0, CURLUE_OK},
78113498266Sopenharmony_ci  {"https://example.com",
78213498266Sopenharmony_ci   "path=g e t,",
78313498266Sopenharmony_ci   "https | [11] | [12] | [13] | example.com | [15] | /g%20e%20t | "
78413498266Sopenharmony_ci   "[16] | [17]",
78513498266Sopenharmony_ci   0, CURLU_URLENCODE, 0, CURLUE_OK},
78613498266Sopenharmony_ci  {NULL, NULL, NULL, 0, 0, 0, CURLUE_OK}
78713498266Sopenharmony_ci};
78813498266Sopenharmony_ci
78913498266Sopenharmony_ci/* !checksrc! disable SPACEBEFORECOMMA 1 */
79013498266Sopenharmony_cistatic const struct setcase set_parts_list[] = {
79113498266Sopenharmony_ci  {"https://example.com/?param=value",
79213498266Sopenharmony_ci   "query=\"\",",
79313498266Sopenharmony_ci   "https://example.com/",
79413498266Sopenharmony_ci   0, CURLU_APPENDQUERY | CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
79513498266Sopenharmony_ci  {"https://example.com/",
79613498266Sopenharmony_ci   "host=\"\",",
79713498266Sopenharmony_ci   "https://example.com/",
79813498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
79913498266Sopenharmony_ci  {"https://example.com/",
80013498266Sopenharmony_ci   "host=\"\",",
80113498266Sopenharmony_ci   "https://example.com/",
80213498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
80313498266Sopenharmony_ci  {"https://example.com",
80413498266Sopenharmony_ci   "path=get,",
80513498266Sopenharmony_ci   "https://example.com/get",
80613498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
80713498266Sopenharmony_ci  {"https://example.com/",
80813498266Sopenharmony_ci   "scheme=ftp+-.123,",
80913498266Sopenharmony_ci   "ftp+-.123://example.com/",
81013498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
81113498266Sopenharmony_ci  {"https://example.com/",
81213498266Sopenharmony_ci   "scheme=1234,",
81313498266Sopenharmony_ci   "https://example.com/",
81413498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
81513498266Sopenharmony_ci  {"https://example.com/",
81613498266Sopenharmony_ci   "scheme=1http,",
81713498266Sopenharmony_ci   "https://example.com/",
81813498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
81913498266Sopenharmony_ci  {"https://example.com/",
82013498266Sopenharmony_ci   "scheme=-ftp,",
82113498266Sopenharmony_ci   "https://example.com/",
82213498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
82313498266Sopenharmony_ci  {"https://example.com/",
82413498266Sopenharmony_ci   "scheme=+ftp,",
82513498266Sopenharmony_ci   "https://example.com/",
82613498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
82713498266Sopenharmony_ci  {"https://example.com/",
82813498266Sopenharmony_ci   "scheme=.ftp,",
82913498266Sopenharmony_ci   "https://example.com/",
83013498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
83113498266Sopenharmony_ci  {"https://example.com/",
83213498266Sopenharmony_ci   "host=example.com%2fmoo,",
83313498266Sopenharmony_ci   "",
83413498266Sopenharmony_ci   0, /* get */
83513498266Sopenharmony_ci   0, /* set */
83613498266Sopenharmony_ci   CURLUE_OK, CURLUE_BAD_HOSTNAME},
83713498266Sopenharmony_ci  {"https://example.com/",
83813498266Sopenharmony_ci   "host=http://fake,",
83913498266Sopenharmony_ci   "",
84013498266Sopenharmony_ci   0, /* get */
84113498266Sopenharmony_ci   0, /* set */
84213498266Sopenharmony_ci   CURLUE_OK, CURLUE_BAD_HOSTNAME},
84313498266Sopenharmony_ci  {"https://example.com/",
84413498266Sopenharmony_ci   "host=test%,",
84513498266Sopenharmony_ci   "",
84613498266Sopenharmony_ci   0, /* get */
84713498266Sopenharmony_ci   0, /* set */
84813498266Sopenharmony_ci   CURLUE_OK, CURLUE_BAD_HOSTNAME},
84913498266Sopenharmony_ci  {"https://example.com/",
85013498266Sopenharmony_ci   "host=te st,",
85113498266Sopenharmony_ci   "",
85213498266Sopenharmony_ci   0, /* get */
85313498266Sopenharmony_ci   0, /* set */
85413498266Sopenharmony_ci   CURLUE_OK, CURLUE_BAD_HOSTNAME},
85513498266Sopenharmony_ci  {"https://example.com/",
85613498266Sopenharmony_ci   "host=0xff,", /* '++' there's no automatic URL decode when setting this
85713498266Sopenharmony_ci                  part */
85813498266Sopenharmony_ci   "https://0xff/",
85913498266Sopenharmony_ci   0, /* get */
86013498266Sopenharmony_ci   0, /* set */
86113498266Sopenharmony_ci   CURLUE_OK, CURLUE_OK},
86213498266Sopenharmony_ci
86313498266Sopenharmony_ci  {"https://example.com/",
86413498266Sopenharmony_ci   "query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
86513498266Sopenharmony_ci   "https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2bLX8TPHs",
86613498266Sopenharmony_ci   CURLU_URLDECODE, /* decode on get */
86713498266Sopenharmony_ci   CURLU_URLENCODE, /* encode on set */
86813498266Sopenharmony_ci   CURLUE_OK, CURLUE_OK},
86913498266Sopenharmony_ci
87013498266Sopenharmony_ci  {"https://example.com/",
87113498266Sopenharmony_ci   /* Set a bad scheme *including* :// */
87213498266Sopenharmony_ci   "scheme=https://,",
87313498266Sopenharmony_ci   "https://example.com/",
87413498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
87513498266Sopenharmony_ci  {"https://example.com/",
87613498266Sopenharmony_ci   /* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
87713498266Sopenharmony_ci   "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
87813498266Sopenharmony_ci   "https://example.com/",
87913498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
88013498266Sopenharmony_ci  {"https://example.com/",
88113498266Sopenharmony_ci   /* set a 40 bytes scheme */
88213498266Sopenharmony_ci   "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,",
88313498266Sopenharmony_ci   "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb://example.com/",
88413498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
88513498266Sopenharmony_ci  {"https://[::1%25fake]:1234/",
88613498266Sopenharmony_ci   "zoneid=NULL,",
88713498266Sopenharmony_ci   "https://[::1]:1234/",
88813498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
88913498266Sopenharmony_ci  {"https://host:1234/",
89013498266Sopenharmony_ci   "port=NULL,",
89113498266Sopenharmony_ci   "https://host/",
89213498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
89313498266Sopenharmony_ci  {"https://host:1234/",
89413498266Sopenharmony_ci   "port=\"\",",
89513498266Sopenharmony_ci   "https://host:1234/",
89613498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
89713498266Sopenharmony_ci  {"https://host:1234/",
89813498266Sopenharmony_ci   "port=56 78,",
89913498266Sopenharmony_ci   "https://host:1234/",
90013498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
90113498266Sopenharmony_ci  {"https://host:1234/",
90213498266Sopenharmony_ci   "port=0,",
90313498266Sopenharmony_ci   "https://host:1234/",
90413498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
90513498266Sopenharmony_ci  {"https://host:1234/",
90613498266Sopenharmony_ci   "port=65535,",
90713498266Sopenharmony_ci   "https://host:65535/",
90813498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
90913498266Sopenharmony_ci  {"https://host:1234/",
91013498266Sopenharmony_ci   "port=65536,",
91113498266Sopenharmony_ci   "https://host:1234/",
91213498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
91313498266Sopenharmony_ci  {"https://host/",
91413498266Sopenharmony_ci   "path=%4A%4B%4C,",
91513498266Sopenharmony_ci   "https://host/%4a%4b%4c",
91613498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
91713498266Sopenharmony_ci  {"https://host/mooo?q#f",
91813498266Sopenharmony_ci   "path=NULL,query=NULL,fragment=NULL,",
91913498266Sopenharmony_ci   "https://host/",
92013498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
92113498266Sopenharmony_ci  {"https://user:secret@host/",
92213498266Sopenharmony_ci   "user=NULL,password=NULL,",
92313498266Sopenharmony_ci   "https://host/",
92413498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
92513498266Sopenharmony_ci  {NULL,
92613498266Sopenharmony_ci   "scheme=https,user=   @:,host=foobar,",
92713498266Sopenharmony_ci   "https://%20%20%20%40%3a@foobar/",
92813498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
92913498266Sopenharmony_ci  /* Setting a host name with spaces is not OK: */
93013498266Sopenharmony_ci  {NULL,
93113498266Sopenharmony_ci   "scheme=https,host=  ,path= ,user= ,password= ,query= ,fragment= ,",
93213498266Sopenharmony_ci   "[nothing]",
93313498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
93413498266Sopenharmony_ci  {NULL,
93513498266Sopenharmony_ci   "scheme=https,host=foobar,path=/this /path /is /here,",
93613498266Sopenharmony_ci   "https://foobar/this%20/path%20/is%20/here",
93713498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
93813498266Sopenharmony_ci  {NULL,
93913498266Sopenharmony_ci   "scheme=https,host=foobar,path=\xc3\xa4\xc3\xb6\xc3\xbc,",
94013498266Sopenharmony_ci   "https://foobar/%c3%a4%c3%b6%c3%bc",
94113498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
94213498266Sopenharmony_ci  {"imap://user:secret;opt@host/",
94313498266Sopenharmony_ci   "options=updated,scheme=imaps,password=p4ssw0rd,",
94413498266Sopenharmony_ci   "imaps://user:p4ssw0rd;updated@host/",
94513498266Sopenharmony_ci   0, 0, CURLUE_NO_HOST, CURLUE_OK},
94613498266Sopenharmony_ci  {"imap://user:secret;optit@host/",
94713498266Sopenharmony_ci   "scheme=https,",
94813498266Sopenharmony_ci   "https://user:secret@host/",
94913498266Sopenharmony_ci   0, 0, CURLUE_NO_HOST, CURLUE_OK},
95013498266Sopenharmony_ci  {"file:///file#anchor",
95113498266Sopenharmony_ci   "scheme=https,host=example,",
95213498266Sopenharmony_ci   "https://example/file#anchor",
95313498266Sopenharmony_ci   0, 0, CURLUE_NO_HOST, CURLUE_OK},
95413498266Sopenharmony_ci  {NULL, /* start fresh! */
95513498266Sopenharmony_ci   "scheme=file,host=127.0.0.1,path=/no,user=anonymous,",
95613498266Sopenharmony_ci   "file:///no",
95713498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
95813498266Sopenharmony_ci  {NULL, /* start fresh! */
95913498266Sopenharmony_ci   "scheme=ftp,host=127.0.0.1,path=/no,user=anonymous,",
96013498266Sopenharmony_ci   "ftp://anonymous@127.0.0.1/no",
96113498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
96213498266Sopenharmony_ci  {NULL, /* start fresh! */
96313498266Sopenharmony_ci   "scheme=https,host=example.com,",
96413498266Sopenharmony_ci   "https://example.com/",
96513498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
96613498266Sopenharmony_ci  {"http://user:foo@example.com/path?query#frag",
96713498266Sopenharmony_ci   "fragment=changed,",
96813498266Sopenharmony_ci   "http://user:foo@example.com/path?query#changed",
96913498266Sopenharmony_ci   0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
97013498266Sopenharmony_ci  {"http://example.com/",
97113498266Sopenharmony_ci   "scheme=foo,", /* not accepted */
97213498266Sopenharmony_ci   "http://example.com/",
97313498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_UNSUPPORTED_SCHEME},
97413498266Sopenharmony_ci  {"http://example.com/",
97513498266Sopenharmony_ci   "scheme=https,path=/hello,fragment=snippet,",
97613498266Sopenharmony_ci   "https://example.com/hello#snippet",
97713498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
97813498266Sopenharmony_ci  {"http://example.com:80",
97913498266Sopenharmony_ci   "user=foo,port=1922,",
98013498266Sopenharmony_ci   "http://foo@example.com:1922/",
98113498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
98213498266Sopenharmony_ci  {"http://example.com:80",
98313498266Sopenharmony_ci   "user=foo,password=bar,",
98413498266Sopenharmony_ci   "http://foo:bar@example.com:80/",
98513498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
98613498266Sopenharmony_ci  {"http://example.com:80",
98713498266Sopenharmony_ci   "user=foo,",
98813498266Sopenharmony_ci   "http://foo@example.com:80/",
98913498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
99013498266Sopenharmony_ci  {"http://example.com",
99113498266Sopenharmony_ci   "host=www.example.com,",
99213498266Sopenharmony_ci   "http://www.example.com/",
99313498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
99413498266Sopenharmony_ci  {"http://example.com:80",
99513498266Sopenharmony_ci   "scheme=ftp,",
99613498266Sopenharmony_ci   "ftp://example.com:80/",
99713498266Sopenharmony_ci   0, 0, CURLUE_OK, CURLUE_OK},
99813498266Sopenharmony_ci  {"custom-scheme://host",
99913498266Sopenharmony_ci   "host=\"\",",
100013498266Sopenharmony_ci   "custom-scheme://host/",
100113498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK,
100213498266Sopenharmony_ci   CURLUE_BAD_HOSTNAME},
100313498266Sopenharmony_ci  {"custom-scheme://host",
100413498266Sopenharmony_ci   "host=\"\",",
100513498266Sopenharmony_ci   "custom-scheme:///",
100613498266Sopenharmony_ci   CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY,
100713498266Sopenharmony_ci   CURLUE_OK, CURLUE_OK},
100813498266Sopenharmony_ci
100913498266Sopenharmony_ci  {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK}
101013498266Sopenharmony_ci};
101113498266Sopenharmony_ci
101213498266Sopenharmony_cistatic CURLUPart part2id(char *part)
101313498266Sopenharmony_ci{
101413498266Sopenharmony_ci  if(!strcmp("url", part))
101513498266Sopenharmony_ci    return CURLUPART_URL;
101613498266Sopenharmony_ci  if(!strcmp("scheme", part))
101713498266Sopenharmony_ci    return CURLUPART_SCHEME;
101813498266Sopenharmony_ci  if(!strcmp("user", part))
101913498266Sopenharmony_ci    return CURLUPART_USER;
102013498266Sopenharmony_ci  if(!strcmp("password", part))
102113498266Sopenharmony_ci    return CURLUPART_PASSWORD;
102213498266Sopenharmony_ci  if(!strcmp("options", part))
102313498266Sopenharmony_ci    return CURLUPART_OPTIONS;
102413498266Sopenharmony_ci  if(!strcmp("host", part))
102513498266Sopenharmony_ci    return CURLUPART_HOST;
102613498266Sopenharmony_ci  if(!strcmp("port", part))
102713498266Sopenharmony_ci    return CURLUPART_PORT;
102813498266Sopenharmony_ci  if(!strcmp("path", part))
102913498266Sopenharmony_ci    return CURLUPART_PATH;
103013498266Sopenharmony_ci  if(!strcmp("query", part))
103113498266Sopenharmony_ci    return CURLUPART_QUERY;
103213498266Sopenharmony_ci  if(!strcmp("fragment", part))
103313498266Sopenharmony_ci    return CURLUPART_FRAGMENT;
103413498266Sopenharmony_ci  if(!strcmp("zoneid", part))
103513498266Sopenharmony_ci    return CURLUPART_ZONEID;
103613498266Sopenharmony_ci  return (CURLUPart)9999; /* bad input => bad output */
103713498266Sopenharmony_ci}
103813498266Sopenharmony_ci
103913498266Sopenharmony_cistatic CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
104013498266Sopenharmony_ci{
104113498266Sopenharmony_ci  const char *p = cmd;
104213498266Sopenharmony_ci  CURLUcode uc;
104313498266Sopenharmony_ci
104413498266Sopenharmony_ci  /* make sure the last command ends with a comma too! */
104513498266Sopenharmony_ci  while(p) {
104613498266Sopenharmony_ci    char *e = strchr(p, ',');
104713498266Sopenharmony_ci    if(e) {
104813498266Sopenharmony_ci      size_t n = (size_t)(e - p);
104913498266Sopenharmony_ci      char buf[80];
105013498266Sopenharmony_ci      char part[80];
105113498266Sopenharmony_ci      char value[80];
105213498266Sopenharmony_ci
105313498266Sopenharmony_ci      memset(part, 0, sizeof(part)); /* Avoid valgrind false positive. */
105413498266Sopenharmony_ci      memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
105513498266Sopenharmony_ci      memcpy(buf, p, n);
105613498266Sopenharmony_ci      buf[n] = 0;
105713498266Sopenharmony_ci      if(2 == sscanf(buf, "%79[^=]=%79[^,]", part, value)) {
105813498266Sopenharmony_ci        CURLUPart what = part2id(part);
105913498266Sopenharmony_ci#if 0
106013498266Sopenharmony_ci        /* for debugging this */
106113498266Sopenharmony_ci        fprintf(stderr, "%s = \"%s\" [%d]\n", part, value, (int)what);
106213498266Sopenharmony_ci#endif
106313498266Sopenharmony_ci        if(what > CURLUPART_ZONEID)
106413498266Sopenharmony_ci          fprintf(stderr, "UNKNOWN part '%s'\n", part);
106513498266Sopenharmony_ci
106613498266Sopenharmony_ci        if(!strcmp("NULL", value))
106713498266Sopenharmony_ci          uc = curl_url_set(u, what, NULL, setflags);
106813498266Sopenharmony_ci        else if(!strcmp("\"\"", value))
106913498266Sopenharmony_ci          uc = curl_url_set(u, what, "", setflags);
107013498266Sopenharmony_ci        else
107113498266Sopenharmony_ci          uc = curl_url_set(u, what, value, setflags);
107213498266Sopenharmony_ci        if(uc)
107313498266Sopenharmony_ci          return uc;
107413498266Sopenharmony_ci      }
107513498266Sopenharmony_ci      p = e + 1;
107613498266Sopenharmony_ci      continue;
107713498266Sopenharmony_ci    }
107813498266Sopenharmony_ci    break;
107913498266Sopenharmony_ci  }
108013498266Sopenharmony_ci  return CURLUE_OK;
108113498266Sopenharmony_ci}
108213498266Sopenharmony_ci
108313498266Sopenharmony_cistatic const struct redircase set_url_list[] = {
108413498266Sopenharmony_ci  {"http://example.com/please/../gimme/%TESTNUMBER?foobar#hello",
108513498266Sopenharmony_ci   "http://example.net/there/it/is/../../tes t case=/%TESTNUMBER0002? yes no",
108613498266Sopenharmony_ci   "http://example.net/there/tes%20t%20case=/%TESTNUMBER0002?+yes+no",
108713498266Sopenharmony_ci   0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
108813498266Sopenharmony_ci  {"http://local.test?redirect=http://local.test:80?-321",
108913498266Sopenharmony_ci   "http://local.test:80?-123",
109013498266Sopenharmony_ci   "http://local.test:80/?-123",
109113498266Sopenharmony_ci   0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
109213498266Sopenharmony_ci  {"http://local.test?redirect=http://local.test:80?-321",
109313498266Sopenharmony_ci   "http://local.test:80?-123",
109413498266Sopenharmony_ci   "http://local.test:80/?-123",
109513498266Sopenharmony_ci   0, 0, CURLUE_OK},
109613498266Sopenharmony_ci  {"http://example.org/static/favicon/wikipedia.ico",
109713498266Sopenharmony_ci   "//fake.example.com/licenses/by-sa/3.0/",
109813498266Sopenharmony_ci   "http://fake.example.com/licenses/by-sa/3.0/",
109913498266Sopenharmony_ci   0, 0, CURLUE_OK},
110013498266Sopenharmony_ci  {"https://example.org/static/favicon/wikipedia.ico",
110113498266Sopenharmony_ci   "//fake.example.com/licenses/by-sa/3.0/",
110213498266Sopenharmony_ci   "https://fake.example.com/licenses/by-sa/3.0/",
110313498266Sopenharmony_ci   0, 0, CURLUE_OK},
110413498266Sopenharmony_ci  {"file://localhost/path?query#frag",
110513498266Sopenharmony_ci   "foo#another",
110613498266Sopenharmony_ci   "file:///foo#another",
110713498266Sopenharmony_ci   0, 0, CURLUE_OK},
110813498266Sopenharmony_ci  {"http://example.com/path?query#frag",
110913498266Sopenharmony_ci   "https://two.example.com/bradnew",
111013498266Sopenharmony_ci   "https://two.example.com/bradnew",
111113498266Sopenharmony_ci   0, 0, CURLUE_OK},
111213498266Sopenharmony_ci  {"http://example.com/path?query#frag",
111313498266Sopenharmony_ci   "../../newpage#foo",
111413498266Sopenharmony_ci   "http://example.com/newpage#foo",
111513498266Sopenharmony_ci   0, 0, CURLUE_OK},
111613498266Sopenharmony_ci  {"http://user:foo@example.com/path?query#frag",
111713498266Sopenharmony_ci   "../../newpage",
111813498266Sopenharmony_ci   "http://user:foo@example.com/newpage",
111913498266Sopenharmony_ci   0, 0, CURLUE_OK},
112013498266Sopenharmony_ci  {"http://user:foo@example.com/path?query#frag",
112113498266Sopenharmony_ci   "../newpage",
112213498266Sopenharmony_ci   "http://user:foo@example.com/newpage",
112313498266Sopenharmony_ci   0, 0, CURLUE_OK},
112413498266Sopenharmony_ci  {"http://user:foo@example.com/path?query#frag",
112513498266Sopenharmony_ci   "http://?hi",
112613498266Sopenharmony_ci   "http:///?hi",
112713498266Sopenharmony_ci   0, CURLU_NO_AUTHORITY, CURLUE_OK},
112813498266Sopenharmony_ci  {NULL, NULL, NULL, 0, 0, CURLUE_OK}
112913498266Sopenharmony_ci};
113013498266Sopenharmony_ci
113113498266Sopenharmony_cistatic int set_url(void)
113213498266Sopenharmony_ci{
113313498266Sopenharmony_ci  int i;
113413498266Sopenharmony_ci  int error = 0;
113513498266Sopenharmony_ci
113613498266Sopenharmony_ci  for(i = 0; set_url_list[i].in && !error; i++) {
113713498266Sopenharmony_ci    CURLUcode rc;
113813498266Sopenharmony_ci    CURLU *urlp = curl_url();
113913498266Sopenharmony_ci    if(!urlp)
114013498266Sopenharmony_ci      break;
114113498266Sopenharmony_ci    rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
114213498266Sopenharmony_ci                      set_url_list[i].urlflags);
114313498266Sopenharmony_ci    if(!rc) {
114413498266Sopenharmony_ci      rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
114513498266Sopenharmony_ci                        set_url_list[i].setflags);
114613498266Sopenharmony_ci      if(rc) {
114713498266Sopenharmony_ci        fprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
114813498266Sopenharmony_ci                __FILE__, __LINE__, set_url_list[i].set,
114913498266Sopenharmony_ci                (int)rc, curl_url_strerror(rc));
115013498266Sopenharmony_ci        error++;
115113498266Sopenharmony_ci      }
115213498266Sopenharmony_ci      else {
115313498266Sopenharmony_ci        char *url = NULL;
115413498266Sopenharmony_ci        rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
115513498266Sopenharmony_ci        if(rc) {
115613498266Sopenharmony_ci          fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
115713498266Sopenharmony_ci                  __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
115813498266Sopenharmony_ci          error++;
115913498266Sopenharmony_ci        }
116013498266Sopenharmony_ci        else {
116113498266Sopenharmony_ci          if(checkurl(set_url_list[i].in, url, set_url_list[i].out)) {
116213498266Sopenharmony_ci            error++;
116313498266Sopenharmony_ci          }
116413498266Sopenharmony_ci        }
116513498266Sopenharmony_ci        curl_free(url);
116613498266Sopenharmony_ci      }
116713498266Sopenharmony_ci    }
116813498266Sopenharmony_ci    else if(rc != set_url_list[i].ucode) {
116913498266Sopenharmony_ci      fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
117013498266Sopenharmony_ci              set_url_list[i].in, (int)rc, set_url_list[i].ucode);
117113498266Sopenharmony_ci      error++;
117213498266Sopenharmony_ci    }
117313498266Sopenharmony_ci    curl_url_cleanup(urlp);
117413498266Sopenharmony_ci  }
117513498266Sopenharmony_ci  return error;
117613498266Sopenharmony_ci}
117713498266Sopenharmony_ci
117813498266Sopenharmony_ci/* 1. Set a URL
117913498266Sopenharmony_ci   2. Set one or more parts
118013498266Sopenharmony_ci   3. Extract and compare all parts - not the URL
118113498266Sopenharmony_ci*/
118213498266Sopenharmony_cistatic int setget_parts(void)
118313498266Sopenharmony_ci{
118413498266Sopenharmony_ci  int i;
118513498266Sopenharmony_ci  int error = 0;
118613498266Sopenharmony_ci
118713498266Sopenharmony_ci  for(i = 0; setget_parts_list[i].set && !error; i++) {
118813498266Sopenharmony_ci    CURLUcode rc;
118913498266Sopenharmony_ci    CURLU *urlp = curl_url();
119013498266Sopenharmony_ci    if(!urlp) {
119113498266Sopenharmony_ci      error++;
119213498266Sopenharmony_ci      break;
119313498266Sopenharmony_ci    }
119413498266Sopenharmony_ci    if(setget_parts_list[i].in)
119513498266Sopenharmony_ci      rc = curl_url_set(urlp, CURLUPART_URL, setget_parts_list[i].in,
119613498266Sopenharmony_ci                        setget_parts_list[i].urlflags);
119713498266Sopenharmony_ci    else
119813498266Sopenharmony_ci      rc = CURLUE_OK;
119913498266Sopenharmony_ci    if(!rc) {
120013498266Sopenharmony_ci      char *url = NULL;
120113498266Sopenharmony_ci      CURLUcode uc = updateurl(urlp, setget_parts_list[i].set,
120213498266Sopenharmony_ci                               setget_parts_list[i].setflags);
120313498266Sopenharmony_ci
120413498266Sopenharmony_ci      if(uc != setget_parts_list[i].pcode) {
120513498266Sopenharmony_ci        fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
120613498266Sopenharmony_ci                setget_parts_list[i].set, (int)uc, setget_parts_list[i].pcode);
120713498266Sopenharmony_ci        error++;
120813498266Sopenharmony_ci      }
120913498266Sopenharmony_ci      if(!uc) {
121013498266Sopenharmony_ci        if(checkparts(urlp, setget_parts_list[i].set, setget_parts_list[i].out,
121113498266Sopenharmony_ci                      setget_parts_list[i].getflags))
121213498266Sopenharmony_ci          error++;        /* add */
121313498266Sopenharmony_ci      }
121413498266Sopenharmony_ci      curl_free(url);
121513498266Sopenharmony_ci    }
121613498266Sopenharmony_ci    else if(rc != CURLUE_OK) {
121713498266Sopenharmony_ci      fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
121813498266Sopenharmony_ci              setget_parts_list[i].in, (int)rc, 0);
121913498266Sopenharmony_ci      error++;
122013498266Sopenharmony_ci    }
122113498266Sopenharmony_ci    curl_url_cleanup(urlp);
122213498266Sopenharmony_ci  }
122313498266Sopenharmony_ci  return error;
122413498266Sopenharmony_ci}
122513498266Sopenharmony_ci
122613498266Sopenharmony_cistatic int set_parts(void)
122713498266Sopenharmony_ci{
122813498266Sopenharmony_ci  int i;
122913498266Sopenharmony_ci  int error = 0;
123013498266Sopenharmony_ci
123113498266Sopenharmony_ci  for(i = 0; set_parts_list[i].set && !error; i++) {
123213498266Sopenharmony_ci    CURLUcode rc;
123313498266Sopenharmony_ci    CURLU *urlp = curl_url();
123413498266Sopenharmony_ci    if(!urlp) {
123513498266Sopenharmony_ci      error++;
123613498266Sopenharmony_ci      break;
123713498266Sopenharmony_ci    }
123813498266Sopenharmony_ci    if(set_parts_list[i].in)
123913498266Sopenharmony_ci      rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
124013498266Sopenharmony_ci                        set_parts_list[i].urlflags);
124113498266Sopenharmony_ci    else
124213498266Sopenharmony_ci      rc = CURLUE_OK;
124313498266Sopenharmony_ci    if(!rc) {
124413498266Sopenharmony_ci      char *url = NULL;
124513498266Sopenharmony_ci      CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
124613498266Sopenharmony_ci                               set_parts_list[i].setflags);
124713498266Sopenharmony_ci
124813498266Sopenharmony_ci      if(uc != set_parts_list[i].pcode) {
124913498266Sopenharmony_ci        fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
125013498266Sopenharmony_ci                set_parts_list[i].set, (int)uc, set_parts_list[i].pcode);
125113498266Sopenharmony_ci        error++;
125213498266Sopenharmony_ci      }
125313498266Sopenharmony_ci      if(!uc) {
125413498266Sopenharmony_ci        /* only do this if it worked */
125513498266Sopenharmony_ci        rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
125613498266Sopenharmony_ci
125713498266Sopenharmony_ci        if(rc) {
125813498266Sopenharmony_ci          fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
125913498266Sopenharmony_ci                  __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
126013498266Sopenharmony_ci          error++;
126113498266Sopenharmony_ci        }
126213498266Sopenharmony_ci        else if(checkurl(set_parts_list[i].in, url, set_parts_list[i].out)) {
126313498266Sopenharmony_ci          error++;
126413498266Sopenharmony_ci        }
126513498266Sopenharmony_ci      }
126613498266Sopenharmony_ci      curl_free(url);
126713498266Sopenharmony_ci    }
126813498266Sopenharmony_ci    else if(rc != set_parts_list[i].ucode) {
126913498266Sopenharmony_ci      fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
127013498266Sopenharmony_ci              set_parts_list[i].in, (int)rc, set_parts_list[i].ucode);
127113498266Sopenharmony_ci      error++;
127213498266Sopenharmony_ci    }
127313498266Sopenharmony_ci    curl_url_cleanup(urlp);
127413498266Sopenharmony_ci  }
127513498266Sopenharmony_ci  return error;
127613498266Sopenharmony_ci}
127713498266Sopenharmony_ci
127813498266Sopenharmony_cistatic int get_url(void)
127913498266Sopenharmony_ci{
128013498266Sopenharmony_ci  int i;
128113498266Sopenharmony_ci  int error = 0;
128213498266Sopenharmony_ci  for(i = 0; get_url_list[i].in && !error; i++) {
128313498266Sopenharmony_ci    CURLUcode rc;
128413498266Sopenharmony_ci    CURLU *urlp = curl_url();
128513498266Sopenharmony_ci    if(!urlp) {
128613498266Sopenharmony_ci      error++;
128713498266Sopenharmony_ci      break;
128813498266Sopenharmony_ci    }
128913498266Sopenharmony_ci    rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
129013498266Sopenharmony_ci                      get_url_list[i].urlflags);
129113498266Sopenharmony_ci    if(!rc) {
129213498266Sopenharmony_ci      char *url = NULL;
129313498266Sopenharmony_ci      rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
129413498266Sopenharmony_ci
129513498266Sopenharmony_ci      if(rc) {
129613498266Sopenharmony_ci        fprintf(stderr, "%s:%d returned %d (%s). URL: '%s'\n",
129713498266Sopenharmony_ci                __FILE__, __LINE__, (int)rc, curl_url_strerror(rc),
129813498266Sopenharmony_ci                get_url_list[i].in);
129913498266Sopenharmony_ci        error++;
130013498266Sopenharmony_ci      }
130113498266Sopenharmony_ci      else {
130213498266Sopenharmony_ci        if(checkurl(get_url_list[i].in, url, get_url_list[i].out)) {
130313498266Sopenharmony_ci          error++;
130413498266Sopenharmony_ci        }
130513498266Sopenharmony_ci      }
130613498266Sopenharmony_ci      curl_free(url);
130713498266Sopenharmony_ci    }
130813498266Sopenharmony_ci    if(rc != get_url_list[i].ucode) {
130913498266Sopenharmony_ci      fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
131013498266Sopenharmony_ci              get_url_list[i].in, (int)rc, get_url_list[i].ucode);
131113498266Sopenharmony_ci      error++;
131213498266Sopenharmony_ci    }
131313498266Sopenharmony_ci    curl_url_cleanup(urlp);
131413498266Sopenharmony_ci  }
131513498266Sopenharmony_ci  return error;
131613498266Sopenharmony_ci}
131713498266Sopenharmony_ci
131813498266Sopenharmony_cistatic int get_parts(void)
131913498266Sopenharmony_ci{
132013498266Sopenharmony_ci  int i;
132113498266Sopenharmony_ci  int error = 0;
132213498266Sopenharmony_ci  for(i = 0; get_parts_list[i].in && !error; i++) {
132313498266Sopenharmony_ci    CURLUcode rc;
132413498266Sopenharmony_ci    CURLU *urlp = curl_url();
132513498266Sopenharmony_ci    if(!urlp) {
132613498266Sopenharmony_ci      error++;
132713498266Sopenharmony_ci      break;
132813498266Sopenharmony_ci    }
132913498266Sopenharmony_ci    rc = curl_url_set(urlp, CURLUPART_URL,
133013498266Sopenharmony_ci                      get_parts_list[i].in,
133113498266Sopenharmony_ci                      get_parts_list[i].urlflags);
133213498266Sopenharmony_ci    if(rc != get_parts_list[i].ucode) {
133313498266Sopenharmony_ci      fprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
133413498266Sopenharmony_ci              get_parts_list[i].in, (int)rc, get_parts_list[i].ucode);
133513498266Sopenharmony_ci      error++;
133613498266Sopenharmony_ci    }
133713498266Sopenharmony_ci    else if(get_parts_list[i].ucode) {
133813498266Sopenharmony_ci      /* the expected error happened */
133913498266Sopenharmony_ci    }
134013498266Sopenharmony_ci    else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
134113498266Sopenharmony_ci                       get_parts_list[i].getflags))
134213498266Sopenharmony_ci      error++;
134313498266Sopenharmony_ci    curl_url_cleanup(urlp);
134413498266Sopenharmony_ci  }
134513498266Sopenharmony_ci  return error;
134613498266Sopenharmony_ci}
134713498266Sopenharmony_ci
134813498266Sopenharmony_cistatic const struct querycase append_list[] = {
134913498266Sopenharmony_ci  {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02",
135013498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK},
135113498266Sopenharmony_ci  {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3d#f",
135213498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK},
135313498266Sopenharmony_ci  {"HTTP://test/?size=2#f", "name=joe doe",
135413498266Sopenharmony_ci   "http://test/?size=2&name=joe+doe#f",
135513498266Sopenharmony_ci   0, CURLU_URLENCODE, CURLUE_OK},
135613498266Sopenharmony_ci  {"HTTP://test/", "name=joe", "http://test/?name=joe", 0, 0, CURLUE_OK},
135713498266Sopenharmony_ci  {"HTTP://test/?size=2", "name=joe", "http://test/?size=2&name=joe",
135813498266Sopenharmony_ci   0, 0, CURLUE_OK},
135913498266Sopenharmony_ci  {"HTTP://test/?size=2&", "name=joe", "http://test/?size=2&name=joe",
136013498266Sopenharmony_ci   0, 0, CURLUE_OK},
136113498266Sopenharmony_ci  {"HTTP://test/?size=2#f", "name=joe", "http://test/?size=2&name=joe#f",
136213498266Sopenharmony_ci   0, 0, CURLUE_OK},
136313498266Sopenharmony_ci  {NULL, NULL, NULL, 0, 0, CURLUE_OK}
136413498266Sopenharmony_ci};
136513498266Sopenharmony_ci
136613498266Sopenharmony_cistatic int append(void)
136713498266Sopenharmony_ci{
136813498266Sopenharmony_ci  int i;
136913498266Sopenharmony_ci  int error = 0;
137013498266Sopenharmony_ci  for(i = 0; append_list[i].in && !error; i++) {
137113498266Sopenharmony_ci    CURLUcode rc;
137213498266Sopenharmony_ci    CURLU *urlp = curl_url();
137313498266Sopenharmony_ci    if(!urlp) {
137413498266Sopenharmony_ci      error++;
137513498266Sopenharmony_ci      break;
137613498266Sopenharmony_ci    }
137713498266Sopenharmony_ci    rc = curl_url_set(urlp, CURLUPART_URL,
137813498266Sopenharmony_ci                      append_list[i].in,
137913498266Sopenharmony_ci                      append_list[i].urlflags);
138013498266Sopenharmony_ci    if(rc)
138113498266Sopenharmony_ci      error++;
138213498266Sopenharmony_ci    else
138313498266Sopenharmony_ci      rc = curl_url_set(urlp, CURLUPART_QUERY,
138413498266Sopenharmony_ci                        append_list[i].q,
138513498266Sopenharmony_ci                        append_list[i].qflags | CURLU_APPENDQUERY);
138613498266Sopenharmony_ci    if(error)
138713498266Sopenharmony_ci      ;
138813498266Sopenharmony_ci    else if(rc != append_list[i].ucode) {
138913498266Sopenharmony_ci      fprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
139013498266Sopenharmony_ci              append_list[i].in, (int)rc, append_list[i].ucode);
139113498266Sopenharmony_ci      error++;
139213498266Sopenharmony_ci    }
139313498266Sopenharmony_ci    else if(append_list[i].ucode) {
139413498266Sopenharmony_ci      /* the expected error happened */
139513498266Sopenharmony_ci    }
139613498266Sopenharmony_ci    else {
139713498266Sopenharmony_ci      char *url;
139813498266Sopenharmony_ci      rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
139913498266Sopenharmony_ci      if(rc) {
140013498266Sopenharmony_ci        fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
140113498266Sopenharmony_ci                __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
140213498266Sopenharmony_ci        error++;
140313498266Sopenharmony_ci      }
140413498266Sopenharmony_ci      else {
140513498266Sopenharmony_ci        if(checkurl(append_list[i].in, url, append_list[i].out)) {
140613498266Sopenharmony_ci          error++;
140713498266Sopenharmony_ci        }
140813498266Sopenharmony_ci        curl_free(url);
140913498266Sopenharmony_ci      }
141013498266Sopenharmony_ci    }
141113498266Sopenharmony_ci    curl_url_cleanup(urlp);
141213498266Sopenharmony_ci  }
141313498266Sopenharmony_ci  return error;
141413498266Sopenharmony_ci}
141513498266Sopenharmony_ci
141613498266Sopenharmony_cistatic int scopeid(void)
141713498266Sopenharmony_ci{
141813498266Sopenharmony_ci  CURLU *u = curl_url();
141913498266Sopenharmony_ci  int error = 0;
142013498266Sopenharmony_ci  CURLUcode rc;
142113498266Sopenharmony_ci  char *url;
142213498266Sopenharmony_ci
142313498266Sopenharmony_ci  rc = curl_url_set(u, CURLUPART_URL,
142413498266Sopenharmony_ci                    "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
142513498266Sopenharmony_ci  if(rc != CURLUE_OK) {
142613498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
142713498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
142813498266Sopenharmony_ci    error++;
142913498266Sopenharmony_ci  }
143013498266Sopenharmony_ci
143113498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
143213498266Sopenharmony_ci  if(rc != CURLUE_OK) {
143313498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
143413498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
143513498266Sopenharmony_ci    error++;
143613498266Sopenharmony_ci  }
143713498266Sopenharmony_ci  else {
143813498266Sopenharmony_ci    curl_free(url);
143913498266Sopenharmony_ci  }
144013498266Sopenharmony_ci
144113498266Sopenharmony_ci  rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
144213498266Sopenharmony_ci  if(rc != CURLUE_OK) {
144313498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
144413498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
144513498266Sopenharmony_ci    error++;
144613498266Sopenharmony_ci  }
144713498266Sopenharmony_ci
144813498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
144913498266Sopenharmony_ci  if(rc != CURLUE_OK) {
145013498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
145113498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
145213498266Sopenharmony_ci    error++;
145313498266Sopenharmony_ci  }
145413498266Sopenharmony_ci  else {
145513498266Sopenharmony_ci    curl_free(url);
145613498266Sopenharmony_ci  }
145713498266Sopenharmony_ci
145813498266Sopenharmony_ci  rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
145913498266Sopenharmony_ci  if(rc != CURLUE_OK) {
146013498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
146113498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
146213498266Sopenharmony_ci    error++;
146313498266Sopenharmony_ci  }
146413498266Sopenharmony_ci
146513498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
146613498266Sopenharmony_ci  if(rc != CURLUE_OK) {
146713498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
146813498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
146913498266Sopenharmony_ci    error++;
147013498266Sopenharmony_ci  }
147113498266Sopenharmony_ci  else {
147213498266Sopenharmony_ci    curl_free(url);
147313498266Sopenharmony_ci  }
147413498266Sopenharmony_ci
147513498266Sopenharmony_ci  rc = curl_url_set(u, CURLUPART_HOST,
147613498266Sopenharmony_ci                    "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
147713498266Sopenharmony_ci  if(rc != CURLUE_OK) {
147813498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
147913498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
148013498266Sopenharmony_ci    error++;
148113498266Sopenharmony_ci  }
148213498266Sopenharmony_ci
148313498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
148413498266Sopenharmony_ci  if(rc != CURLUE_OK) {
148513498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
148613498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
148713498266Sopenharmony_ci    error++;
148813498266Sopenharmony_ci  }
148913498266Sopenharmony_ci  else {
149013498266Sopenharmony_ci    curl_free(url);
149113498266Sopenharmony_ci  }
149213498266Sopenharmony_ci
149313498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
149413498266Sopenharmony_ci  if(rc != CURLUE_OK) {
149513498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
149613498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
149713498266Sopenharmony_ci    error++;
149813498266Sopenharmony_ci  }
149913498266Sopenharmony_ci  else {
150013498266Sopenharmony_ci    curl_free(url);
150113498266Sopenharmony_ci  }
150213498266Sopenharmony_ci
150313498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
150413498266Sopenharmony_ci  if(rc != CURLUE_OK) {
150513498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
150613498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
150713498266Sopenharmony_ci    error++;
150813498266Sopenharmony_ci  }
150913498266Sopenharmony_ci  else {
151013498266Sopenharmony_ci    curl_free(url);
151113498266Sopenharmony_ci  }
151213498266Sopenharmony_ci
151313498266Sopenharmony_ci  rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
151413498266Sopenharmony_ci  if(rc != CURLUE_OK) {
151513498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
151613498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
151713498266Sopenharmony_ci    error++;
151813498266Sopenharmony_ci  }
151913498266Sopenharmony_ci
152013498266Sopenharmony_ci  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
152113498266Sopenharmony_ci  if(rc != CURLUE_OK) {
152213498266Sopenharmony_ci    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
152313498266Sopenharmony_ci            __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
152413498266Sopenharmony_ci    error++;
152513498266Sopenharmony_ci  }
152613498266Sopenharmony_ci  else {
152713498266Sopenharmony_ci    curl_free(url);
152813498266Sopenharmony_ci  }
152913498266Sopenharmony_ci
153013498266Sopenharmony_ci  curl_url_cleanup(u);
153113498266Sopenharmony_ci
153213498266Sopenharmony_ci  return error;
153313498266Sopenharmony_ci}
153413498266Sopenharmony_ci
153513498266Sopenharmony_cistatic int get_nothing(void)
153613498266Sopenharmony_ci{
153713498266Sopenharmony_ci  CURLU *u = curl_url();
153813498266Sopenharmony_ci  if(u) {
153913498266Sopenharmony_ci    char *p;
154013498266Sopenharmony_ci    CURLUcode rc;
154113498266Sopenharmony_ci
154213498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_SCHEME, &p, 0);
154313498266Sopenharmony_ci    if(rc != CURLUE_NO_SCHEME)
154413498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
154513498266Sopenharmony_ci
154613498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_HOST, &p, 0);
154713498266Sopenharmony_ci    if(rc != CURLUE_NO_HOST)
154813498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
154913498266Sopenharmony_ci
155013498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_USER, &p, 0);
155113498266Sopenharmony_ci    if(rc != CURLUE_NO_USER)
155213498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
155313498266Sopenharmony_ci
155413498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_PASSWORD, &p, 0);
155513498266Sopenharmony_ci    if(rc != CURLUE_NO_PASSWORD)
155613498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
155713498266Sopenharmony_ci
155813498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_OPTIONS, &p, 0);
155913498266Sopenharmony_ci    if(rc != CURLUE_NO_OPTIONS)
156013498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
156113498266Sopenharmony_ci
156213498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_PATH, &p, 0);
156313498266Sopenharmony_ci    if(rc != CURLUE_OK)
156413498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
156513498266Sopenharmony_ci    else
156613498266Sopenharmony_ci      curl_free(p);
156713498266Sopenharmony_ci
156813498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_QUERY, &p, 0);
156913498266Sopenharmony_ci    if(rc != CURLUE_NO_QUERY)
157013498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
157113498266Sopenharmony_ci
157213498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_FRAGMENT, &p, 0);
157313498266Sopenharmony_ci    if(rc != CURLUE_NO_FRAGMENT)
157413498266Sopenharmony_ci      fprintf(stderr, "unexpected return code line %u\n", __LINE__);
157513498266Sopenharmony_ci
157613498266Sopenharmony_ci    rc = curl_url_get(u, CURLUPART_ZONEID, &p, 0);
157713498266Sopenharmony_ci    if(rc != CURLUE_NO_ZONEID)
157813498266Sopenharmony_ci      fprintf(stderr, "unexpected return code %u on line %u\n", (int)rc,
157913498266Sopenharmony_ci              __LINE__);
158013498266Sopenharmony_ci
158113498266Sopenharmony_ci    curl_url_cleanup(u);
158213498266Sopenharmony_ci  }
158313498266Sopenharmony_ci  return 0;
158413498266Sopenharmony_ci}
158513498266Sopenharmony_ci
158613498266Sopenharmony_cistatic const struct clearurlcase clear_url_list[] ={
158713498266Sopenharmony_ci  {CURLUPART_SCHEME, "http", NULL, CURLUE_NO_SCHEME},
158813498266Sopenharmony_ci  {CURLUPART_USER, "user", NULL, CURLUE_NO_USER},
158913498266Sopenharmony_ci  {CURLUPART_PASSWORD, "password", NULL, CURLUE_NO_PASSWORD},
159013498266Sopenharmony_ci  {CURLUPART_OPTIONS, "options", NULL, CURLUE_NO_OPTIONS},
159113498266Sopenharmony_ci  {CURLUPART_HOST, "host", NULL, CURLUE_NO_HOST},
159213498266Sopenharmony_ci  {CURLUPART_ZONEID, "eth0", NULL, CURLUE_NO_ZONEID},
159313498266Sopenharmony_ci  {CURLUPART_PORT, "1234", NULL, CURLUE_NO_PORT},
159413498266Sopenharmony_ci  {CURLUPART_PATH, "/hello", "/", CURLUE_OK},
159513498266Sopenharmony_ci  {CURLUPART_QUERY, "a=b", NULL, CURLUE_NO_QUERY},
159613498266Sopenharmony_ci  {CURLUPART_FRAGMENT, "anchor", NULL, CURLUE_NO_FRAGMENT},
159713498266Sopenharmony_ci  {CURLUPART_URL, NULL, NULL, CURLUE_OK},
159813498266Sopenharmony_ci};
159913498266Sopenharmony_ci
160013498266Sopenharmony_cistatic int clear_url(void)
160113498266Sopenharmony_ci{
160213498266Sopenharmony_ci  CURLU *u = curl_url();
160313498266Sopenharmony_ci  int i, error = 0;
160413498266Sopenharmony_ci  if(u) {
160513498266Sopenharmony_ci    char *p = NULL;
160613498266Sopenharmony_ci    CURLUcode rc;
160713498266Sopenharmony_ci
160813498266Sopenharmony_ci    for(i = 0; clear_url_list[i].in && !error; i++) {
160913498266Sopenharmony_ci      rc = curl_url_set(u, clear_url_list[i].part, clear_url_list[i].in, 0);
161013498266Sopenharmony_ci      if(rc != CURLUE_OK)
161113498266Sopenharmony_ci        fprintf(stderr, "unexpected return code line %u\n", __LINE__);
161213498266Sopenharmony_ci
161313498266Sopenharmony_ci      rc = curl_url_set(u, CURLUPART_URL, NULL, 0);
161413498266Sopenharmony_ci      if(rc != CURLUE_OK)
161513498266Sopenharmony_ci        fprintf(stderr, "unexpected return code line %u\n", __LINE__);
161613498266Sopenharmony_ci
161713498266Sopenharmony_ci      rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
161813498266Sopenharmony_ci      if(rc != clear_url_list[i].ucode || (clear_url_list[i].out &&
161913498266Sopenharmony_ci         0 != strcmp(p, clear_url_list[i].out))) {
162013498266Sopenharmony_ci
162113498266Sopenharmony_ci        fprintf(stderr, "unexpected return code line %u\n", __LINE__);
162213498266Sopenharmony_ci        error++;
162313498266Sopenharmony_ci      }
162413498266Sopenharmony_ci      if(rc == CURLUE_OK)
162513498266Sopenharmony_ci        curl_free(p);
162613498266Sopenharmony_ci    }
162713498266Sopenharmony_ci  }
162813498266Sopenharmony_ci
162913498266Sopenharmony_ci  curl_url_cleanup(u);
163013498266Sopenharmony_ci
163113498266Sopenharmony_ci  return error;
163213498266Sopenharmony_ci}
163313498266Sopenharmony_ci
163413498266Sopenharmony_cistatic char total[128000];
163513498266Sopenharmony_cistatic char bigpart[120000];
163613498266Sopenharmony_ci
163713498266Sopenharmony_ci/*
163813498266Sopenharmony_ci * verify ridiculous URL part sizes
163913498266Sopenharmony_ci */
164013498266Sopenharmony_cistatic int huge(void)
164113498266Sopenharmony_ci{
164213498266Sopenharmony_ci  const char *smallpart = "c";
164313498266Sopenharmony_ci  int i;
164413498266Sopenharmony_ci  CURLU *urlp = curl_url();
164513498266Sopenharmony_ci  CURLUcode rc;
164613498266Sopenharmony_ci  CURLUPart part[]= {
164713498266Sopenharmony_ci    CURLUPART_SCHEME,
164813498266Sopenharmony_ci    CURLUPART_USER,
164913498266Sopenharmony_ci    CURLUPART_PASSWORD,
165013498266Sopenharmony_ci    CURLUPART_HOST,
165113498266Sopenharmony_ci    CURLUPART_PATH,
165213498266Sopenharmony_ci    CURLUPART_QUERY,
165313498266Sopenharmony_ci    CURLUPART_FRAGMENT
165413498266Sopenharmony_ci  };
165513498266Sopenharmony_ci  int error = 0;
165613498266Sopenharmony_ci  if(!urlp)
165713498266Sopenharmony_ci    return 1;
165813498266Sopenharmony_ci  bigpart[0] = '/'; /* for the path */
165913498266Sopenharmony_ci  memset(&bigpart[1], 'a', sizeof(bigpart) - 2);
166013498266Sopenharmony_ci  bigpart[sizeof(bigpart) - 1] = 0;
166113498266Sopenharmony_ci
166213498266Sopenharmony_ci  for(i = 0; i <  7; i++) {
166313498266Sopenharmony_ci    char *partp;
166413498266Sopenharmony_ci    msnprintf(total, sizeof(total),
166513498266Sopenharmony_ci              "%s://%s:%s@%s/%s?%s#%s",
166613498266Sopenharmony_ci              (i == 0)? &bigpart[1] : smallpart,
166713498266Sopenharmony_ci              (i == 1)? &bigpart[1] : smallpart,
166813498266Sopenharmony_ci              (i == 2)? &bigpart[1] : smallpart,
166913498266Sopenharmony_ci              (i == 3)? &bigpart[1] : smallpart,
167013498266Sopenharmony_ci              (i == 4)? &bigpart[1] : smallpart,
167113498266Sopenharmony_ci              (i == 5)? &bigpart[1] : smallpart,
167213498266Sopenharmony_ci              (i == 6)? &bigpart[1] : smallpart);
167313498266Sopenharmony_ci    rc = curl_url_set(urlp, CURLUPART_URL, total, CURLU_NON_SUPPORT_SCHEME);
167413498266Sopenharmony_ci    if((!i && (rc != CURLUE_BAD_SCHEME)) ||
167513498266Sopenharmony_ci       (i && rc)) {
167613498266Sopenharmony_ci      printf("URL %u: failed to parse [%s]\n", i, total);
167713498266Sopenharmony_ci      error++;
167813498266Sopenharmony_ci    }
167913498266Sopenharmony_ci
168013498266Sopenharmony_ci    /* only extract if the parse worked */
168113498266Sopenharmony_ci    if(!rc) {
168213498266Sopenharmony_ci      curl_url_get(urlp, part[i], &partp, 0);
168313498266Sopenharmony_ci      if(!partp || strcmp(partp, &bigpart[1 - (i == 4)])) {
168413498266Sopenharmony_ci        printf("URL %u part %u: failure\n", i, part[i]);
168513498266Sopenharmony_ci        error++;
168613498266Sopenharmony_ci      }
168713498266Sopenharmony_ci      curl_free(partp);
168813498266Sopenharmony_ci    }
168913498266Sopenharmony_ci  }
169013498266Sopenharmony_ci  curl_url_cleanup(urlp);
169113498266Sopenharmony_ci  return error;
169213498266Sopenharmony_ci}
169313498266Sopenharmony_ci
169413498266Sopenharmony_cistatic int urldup(void)
169513498266Sopenharmony_ci{
169613498266Sopenharmony_ci  const char *url[] = {
169713498266Sopenharmony_ci    "http://"
169813498266Sopenharmony_ci    "user:pwd@"
169913498266Sopenharmony_ci    "[2a04:4e42:e00::347%25eth0]"
170013498266Sopenharmony_ci    ":80"
170113498266Sopenharmony_ci    "/path"
170213498266Sopenharmony_ci    "?query"
170313498266Sopenharmony_ci    "#fraggie",
170413498266Sopenharmony_ci    "https://example.com",
170513498266Sopenharmony_ci    "https://user@example.com",
170613498266Sopenharmony_ci    "https://user.pwd@example.com",
170713498266Sopenharmony_ci    "https://user.pwd@example.com:1234",
170813498266Sopenharmony_ci    "https://example.com:1234",
170913498266Sopenharmony_ci    "example.com:1234",
171013498266Sopenharmony_ci    "https://user.pwd@example.com:1234/path?query#frag",
171113498266Sopenharmony_ci    NULL
171213498266Sopenharmony_ci  };
171313498266Sopenharmony_ci  CURLU *copy = NULL;
171413498266Sopenharmony_ci  char *h_str = NULL, *copy_str = NULL;
171513498266Sopenharmony_ci  CURLU *h = curl_url();
171613498266Sopenharmony_ci  int i;
171713498266Sopenharmony_ci
171813498266Sopenharmony_ci  if(!h)
171913498266Sopenharmony_ci    goto err;
172013498266Sopenharmony_ci
172113498266Sopenharmony_ci  for(i = 0; url[i]; i++) {
172213498266Sopenharmony_ci    CURLUcode rc = curl_url_set(h, CURLUPART_URL, url[i],
172313498266Sopenharmony_ci                                CURLU_GUESS_SCHEME);
172413498266Sopenharmony_ci    if(rc)
172513498266Sopenharmony_ci      goto err;
172613498266Sopenharmony_ci    copy = curl_url_dup(h);
172713498266Sopenharmony_ci
172813498266Sopenharmony_ci    rc = curl_url_get(h, CURLUPART_URL, &h_str, 0);
172913498266Sopenharmony_ci    if(rc)
173013498266Sopenharmony_ci      goto err;
173113498266Sopenharmony_ci
173213498266Sopenharmony_ci    rc = curl_url_get(copy, CURLUPART_URL, &copy_str, 0);
173313498266Sopenharmony_ci    if(rc)
173413498266Sopenharmony_ci      goto err;
173513498266Sopenharmony_ci
173613498266Sopenharmony_ci    if(strcmp(h_str, copy_str)) {
173713498266Sopenharmony_ci      printf("Original:  %s\nParsed:    %s\nCopy:      %s\n",
173813498266Sopenharmony_ci             url[i], h_str, copy_str);
173913498266Sopenharmony_ci      goto err;
174013498266Sopenharmony_ci    }
174113498266Sopenharmony_ci    curl_free(copy_str);
174213498266Sopenharmony_ci    curl_free(h_str);
174313498266Sopenharmony_ci    curl_url_cleanup(copy);
174413498266Sopenharmony_ci    copy_str = NULL;
174513498266Sopenharmony_ci    h_str = NULL;
174613498266Sopenharmony_ci    copy = NULL;
174713498266Sopenharmony_ci  }
174813498266Sopenharmony_ci  curl_url_cleanup(h);
174913498266Sopenharmony_ci  return 0;
175013498266Sopenharmony_cierr:
175113498266Sopenharmony_ci  curl_free(copy_str);
175213498266Sopenharmony_ci  curl_free(h_str);
175313498266Sopenharmony_ci  curl_url_cleanup(copy);
175413498266Sopenharmony_ci  curl_url_cleanup(h);
175513498266Sopenharmony_ci  return 1;
175613498266Sopenharmony_ci}
175713498266Sopenharmony_ci
175813498266Sopenharmony_ciint test(char *URL)
175913498266Sopenharmony_ci{
176013498266Sopenharmony_ci  (void)URL; /* not used */
176113498266Sopenharmony_ci
176213498266Sopenharmony_ci  if(urldup())
176313498266Sopenharmony_ci    return 11;
176413498266Sopenharmony_ci
176513498266Sopenharmony_ci  if(setget_parts())
176613498266Sopenharmony_ci    return 10;
176713498266Sopenharmony_ci
176813498266Sopenharmony_ci  if(get_url())
176913498266Sopenharmony_ci    return 3;
177013498266Sopenharmony_ci
177113498266Sopenharmony_ci  if(huge())
177213498266Sopenharmony_ci    return 9;
177313498266Sopenharmony_ci
177413498266Sopenharmony_ci  if(get_nothing())
177513498266Sopenharmony_ci    return 7;
177613498266Sopenharmony_ci
177713498266Sopenharmony_ci  if(scopeid())
177813498266Sopenharmony_ci    return 6;
177913498266Sopenharmony_ci
178013498266Sopenharmony_ci  if(append())
178113498266Sopenharmony_ci    return 5;
178213498266Sopenharmony_ci
178313498266Sopenharmony_ci  if(set_url())
178413498266Sopenharmony_ci    return 1;
178513498266Sopenharmony_ci
178613498266Sopenharmony_ci  if(set_parts())
178713498266Sopenharmony_ci    return 2;
178813498266Sopenharmony_ci
178913498266Sopenharmony_ci  if(get_parts())
179013498266Sopenharmony_ci    return 4;
179113498266Sopenharmony_ci
179213498266Sopenharmony_ci  if(clear_url())
179313498266Sopenharmony_ci    return 8;
179413498266Sopenharmony_ci
179513498266Sopenharmony_ci  printf("success\n");
179613498266Sopenharmony_ci  return 0;
179713498266Sopenharmony_ci}
1798