lib1560.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. /*
  25. * Note:
  26. *
  27. * Since the URL parser by default only accepts schemes that *this instance*
  28. * of libcurl supports, make sure that the test1560 file lists all the schemes
  29. * that this test will assume to be present!
  30. */
  31. #include "test.h"
  32. #if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
  33. #define USE_IDN
  34. #endif
  35. #include "testutil.h"
  36. #include "warnless.h"
  37. #include "memdebug.h" /* LAST include file */
  38. struct part {
  39. CURLUPart part;
  40. const char *name;
  41. };
  42. static int checkparts(CURLU *u, const char *in, const char *wanted,
  43. unsigned int getflags)
  44. {
  45. int i;
  46. CURLUcode rc;
  47. char buf[256];
  48. char *bufp = &buf[0];
  49. size_t len = sizeof(buf);
  50. struct part parts[] = {
  51. {CURLUPART_SCHEME, "scheme"},
  52. {CURLUPART_USER, "user"},
  53. {CURLUPART_PASSWORD, "password"},
  54. {CURLUPART_OPTIONS, "options"},
  55. {CURLUPART_HOST, "host"},
  56. {CURLUPART_PORT, "port"},
  57. {CURLUPART_PATH, "path"},
  58. {CURLUPART_QUERY, "query"},
  59. {CURLUPART_FRAGMENT, "fragment"},
  60. {CURLUPART_URL, NULL}
  61. };
  62. memset(buf, 0, sizeof(buf));
  63. for(i = 0; parts[i].name; i++) {
  64. char *p = NULL;
  65. size_t n;
  66. rc = curl_url_get(u, parts[i].part, &p, getflags);
  67. if(!rc && p) {
  68. msnprintf(bufp, len, "%s%s", buf[0]?" | ":"", p);
  69. }
  70. else
  71. msnprintf(bufp, len, "%s[%d]", buf[0]?" | ":"", (int)rc);
  72. n = strlen(bufp);
  73. bufp += n;
  74. len -= n;
  75. curl_free(p);
  76. }
  77. if(strcmp(buf, wanted)) {
  78. fprintf(stderr, "in: %s\nwanted: %s\ngot: %s\n", in, wanted, buf);
  79. return 1;
  80. }
  81. return 0;
  82. }
  83. struct redircase {
  84. const char *in;
  85. const char *set;
  86. const char *out;
  87. unsigned int urlflags;
  88. unsigned int setflags;
  89. CURLUcode ucode;
  90. };
  91. struct setcase {
  92. const char *in;
  93. const char *set;
  94. const char *out;
  95. unsigned int urlflags;
  96. unsigned int setflags;
  97. CURLUcode ucode; /* for the main URL set */
  98. CURLUcode pcode; /* for updating parts */
  99. };
  100. struct setgetcase {
  101. const char *in;
  102. const char *set;
  103. const char *out;
  104. unsigned int urlflags; /* for setting the URL */
  105. unsigned int setflags; /* for updating parts */
  106. unsigned int getflags; /* for getting parts */
  107. CURLUcode pcode; /* for updating parts */
  108. };
  109. struct testcase {
  110. const char *in;
  111. const char *out;
  112. unsigned int urlflags;
  113. unsigned int getflags;
  114. CURLUcode ucode;
  115. };
  116. struct urltestcase {
  117. const char *in;
  118. const char *out;
  119. unsigned int urlflags; /* pass to curl_url() */
  120. unsigned int getflags; /* pass to curl_url_get() */
  121. CURLUcode ucode;
  122. };
  123. struct querycase {
  124. const char *in;
  125. const char *q;
  126. const char *out;
  127. unsigned int urlflags; /* pass to curl_url() */
  128. unsigned int qflags; /* pass to curl_url_get() */
  129. CURLUcode ucode;
  130. };
  131. struct clearurlcase {
  132. CURLUPart part;
  133. const char *in;
  134. const char *out;
  135. CURLUcode ucode;
  136. };
  137. static const struct testcase get_parts_list[] ={
  138. {"curl.se",
  139. "[10] | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
  140. CURLU_GUESS_SCHEME, CURLU_NO_GUESS_SCHEME, CURLUE_OK},
  141. {"https://curl.se:0/#",
  142. "https | [11] | [12] | [13] | curl.se | 0 | / | [16] | ",
  143. 0, CURLU_GET_EMPTY, CURLUE_OK},
  144. {"https://curl.se/#",
  145. "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | ",
  146. 0, CURLU_GET_EMPTY, CURLUE_OK},
  147. {"https://curl.se/?#",
  148. "https | [11] | [12] | [13] | curl.se | [15] | / | | ",
  149. 0, CURLU_GET_EMPTY, CURLUE_OK},
  150. {"https://curl.se/?",
  151. "https | [11] | [12] | [13] | curl.se | [15] | / | | [17]",
  152. 0, CURLU_GET_EMPTY, CURLUE_OK},
  153. {"https://curl.se/?",
  154. "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
  155. 0, 0, CURLUE_OK},
  156. {"https://curl.se/?#",
  157. "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
  158. 0, 0, CURLUE_OK},
  159. {"https://curl.se/# ",
  160. "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | %20%20",
  161. CURLU_URLENCODE|CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  162. {"", "", 0, 0, CURLUE_MALFORMED_INPUT},
  163. {" ", "", 0, 0, CURLUE_MALFORMED_INPUT},
  164. {"1h://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
  165. {"..://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
  166. {"-ht://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
  167. {"+ftp://example.net", "", 0, 0, CURLUE_BAD_SCHEME},
  168. {"hej.hej://example.net",
  169. "hej.hej | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
  170. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  171. {"ht-tp://example.net",
  172. "ht-tp | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
  173. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  174. {"ftp+more://example.net",
  175. "ftp+more | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
  176. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  177. {"f1337://example.net",
  178. "f1337 | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
  179. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  180. {"https://user@example.net?hello# space ",
  181. "https | user | [12] | [13] | example.net | [15] | / | hello | %20space%20",
  182. CURLU_ALLOW_SPACE|CURLU_URLENCODE, 0, CURLUE_OK},
  183. {"https://test%test", "", 0, 0, CURLUE_BAD_HOSTNAME},
  184. {"https://example.com%252f%40@example.net",
  185. "https | example.com%2f@ | [12] | [13] | example.net | [15] | / "
  186. "| [16] | [17]",
  187. 0, CURLU_URLDECODE, CURLUE_OK },
  188. #ifdef USE_IDN
  189. {"https://räksmörgås.se",
  190. "https | [11] | [12] | [13] | xn--rksmrgs-5wao1o.se | "
  191. "[15] | / | [16] | [17]", 0, CURLU_PUNYCODE, CURLUE_OK},
  192. {"https://xn--rksmrgs-5wao1o.se",
  193. "https | [11] | [12] | [13] | räksmörgås.se | "
  194. "[15] | / | [16] | [17]", 0, CURLU_PUNY2IDN, CURLUE_OK},
  195. #else
  196. {"https://räksmörgås.se",
  197. "https | [11] | [12] | [13] | [30] | [15] | / | [16] | [17]",
  198. 0, CURLU_PUNYCODE, CURLUE_OK},
  199. #endif
  200. /* https://ℂᵤⓇℒ。𝐒🄴 */
  201. {"https://"
  202. "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
  203. "https | [11] | [12] | [13] | ℂᵤⓇℒ。𝐒🄴 | [15] |"
  204. " / | [16] | [17]",
  205. 0, 0, CURLUE_OK},
  206. {"https://"
  207. "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
  208. "https | [11] | [12] | [13] | "
  209. "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4 "
  210. "| [15] | / | [16] | [17]",
  211. 0, CURLU_URLENCODE, CURLUE_OK},
  212. {"https://"
  213. "\xe2\x84\x82\xe1\xb5\xa4\xe2\x93\x87\xe2\x84\x92"
  214. "\xe3\x80\x82\xf0\x9d\x90\x92\xf0\x9f\x84\xb4",
  215. "https | [11] | [12] | [13] | "
  216. "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4 "
  217. "| [15] | / | [16] | [17]",
  218. 0, CURLU_URLENCODE, CURLUE_OK},
  219. {"https://user@example.net?he l lo",
  220. "https | user | [12] | [13] | example.net | [15] | / | he+l+lo | [17]",
  221. CURLU_ALLOW_SPACE, CURLU_URLENCODE, CURLUE_OK},
  222. {"https://user@example.net?he l lo",
  223. "https | user | [12] | [13] | example.net | [15] | / | he l lo | [17]",
  224. CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  225. {"https://exam{}[]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  226. {"https://exam{ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  227. {"https://exam}ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  228. {"https://exam]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  229. {"https://exam\\ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  230. {"https://exam$ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  231. {"https://exam'ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  232. {"https://exam\"ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  233. {"https://exam^ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  234. {"https://exam`ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  235. {"https://exam*ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  236. {"https://exam<ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  237. {"https://exam>ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  238. {"https://exam=ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  239. {"https://exam;ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  240. {"https://example,net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  241. {"https://example&net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  242. {"https://example+net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  243. {"https://example(net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  244. {"https://example)net", "", 0, 0, CURLUE_BAD_HOSTNAME},
  245. {"https://example.net/}",
  246. "https | [11] | [12] | [13] | example.net | [15] | /} | [16] | [17]",
  247. 0, 0, CURLUE_OK},
  248. /* blank user is blank */
  249. {"https://:password@example.net",
  250. "https | | password | [13] | example.net | [15] | / | [16] | [17]",
  251. 0, 0, CURLUE_OK},
  252. /* blank user + blank password */
  253. {"https://:@example.net",
  254. "https | | | [13] | example.net | [15] | / | [16] | [17]",
  255. 0, 0, CURLUE_OK},
  256. /* user-only (no password) */
  257. {"https://user@example.net",
  258. "https | user | [12] | [13] | example.net | [15] | / | [16] | [17]",
  259. 0, 0, CURLUE_OK},
  260. #ifdef USE_WEBSOCKETS
  261. {"ws://example.com/color/?green",
  262. "ws | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
  263. " [17]",
  264. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  265. {"wss://example.com/color/?green",
  266. "wss | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
  267. " [17]",
  268. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  269. #endif
  270. {"https://user:password@example.net/get?this=and#but frag then", "",
  271. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  272. {"https://user:password@example.net/get?this=and what", "",
  273. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  274. {"https://user:password@example.net/ge t?this=and-what", "",
  275. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  276. {"https://user:pass word@example.net/get?this=and-what", "",
  277. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  278. {"https://u ser:password@example.net/get?this=and-what", "",
  279. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  280. {"imap://user:pass;opt ion@server/path", "",
  281. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  282. /* no space allowed in scheme */
  283. {"htt ps://user:password@example.net/get?this=and-what", "",
  284. CURLU_NON_SUPPORT_SCHEME|CURLU_ALLOW_SPACE, 0, CURLUE_BAD_SCHEME},
  285. {"https://user:password@example.net/get?this=and what",
  286. "https | user | password | [13] | example.net | [15] | /get | "
  287. "this=and what | [17]",
  288. CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  289. {"https://user:password@example.net/ge t?this=and-what",
  290. "https | user | password | [13] | example.net | [15] | /ge t | "
  291. "this=and-what | [17]",
  292. CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  293. {"https://user:pass word@example.net/get?this=and-what",
  294. "https | user | pass word | [13] | example.net | [15] | /get | "
  295. "this=and-what | [17]",
  296. CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  297. {"https://u ser:password@example.net/get?this=and-what",
  298. "https | u ser | password | [13] | example.net | [15] | /get | "
  299. "this=and-what | [17]",
  300. CURLU_ALLOW_SPACE, 0, CURLUE_OK},
  301. {"https://user:password@example.net/ge t?this=and-what",
  302. "https | user | password | [13] | example.net | [15] | /ge%20t | "
  303. "this=and-what | [17]",
  304. CURLU_ALLOW_SPACE | CURLU_URLENCODE, 0, CURLUE_OK},
  305. {"[0:0:0:0:0:0:0:1]",
  306. "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
  307. CURLU_GUESS_SCHEME, 0, CURLUE_OK },
  308. {"[::1]",
  309. "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
  310. CURLU_GUESS_SCHEME, 0, CURLUE_OK },
  311. {"[::]",
  312. "http | [11] | [12] | [13] | [::] | [15] | / | [16] | [17]",
  313. CURLU_GUESS_SCHEME, 0, CURLUE_OK },
  314. {"https://[::1]",
  315. "https | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
  316. 0, 0, CURLUE_OK },
  317. {"user:moo@ftp.example.com/color/#green?no-red",
  318. "ftp | user | moo | [13] | ftp.example.com | [15] | /color/ | [16] | "
  319. "green?no-red",
  320. CURLU_GUESS_SCHEME, 0, CURLUE_OK },
  321. {"ftp.user:moo@example.com/color/#green?no-red",
  322. "http | ftp.user | moo | [13] | example.com | [15] | /color/ | [16] | "
  323. "green?no-red",
  324. CURLU_GUESS_SCHEME, 0, CURLUE_OK },
  325. #ifdef _WIN32
  326. {"file:/C:\\programs\\foo",
  327. "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
  328. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  329. {"file://C:\\programs\\foo",
  330. "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
  331. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  332. {"file:///C:\\programs\\foo",
  333. "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
  334. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  335. {"file://host.example.com/Share/path/to/file.txt",
  336. "file | [11] | [12] | [13] | host.example.com | [15] | "
  337. "//host.example.com/Share/path/to/file.txt | [16] | [17]",
  338. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  339. #endif
  340. {"https://example.com/color/#green?no-red",
  341. "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
  342. "green?no-red",
  343. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  344. {"https://example.com/color/#green#no-red",
  345. "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
  346. "green#no-red",
  347. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  348. {"https://example.com/color/?green#no-red",
  349. "https | [11] | [12] | [13] | example.com | [15] | /color/ | green | "
  350. "no-red",
  351. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  352. {"https://example.com/#color/?green#no-red",
  353. "https | [11] | [12] | [13] | example.com | [15] | / | [16] | "
  354. "color/?green#no-red",
  355. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  356. {"https://example.#com/color/?green#no-red",
  357. "https | [11] | [12] | [13] | example. | [15] | / | [16] | "
  358. "com/color/?green#no-red",
  359. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
  360. {"http://[ab.be:1]/x", "",
  361. CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
  362. {"http://[ab.be]/x", "",
  363. CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
  364. /* URL without host name */
  365. {"http://a:b@/x", "",
  366. CURLU_DEFAULT_SCHEME, 0, CURLUE_NO_HOST},
  367. {"boing:80",
  368. "https | [11] | [12] | [13] | boing | 80 | / | [16] | [17]",
  369. CURLU_DEFAULT_SCHEME|CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  370. {"http://[fd00:a41::50]:8080",
  371. "http | [11] | [12] | [13] | [fd00:a41::50] | 8080 | / | [16] | [17]",
  372. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  373. {"http://[fd00:a41::50]/",
  374. "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
  375. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  376. {"http://[fd00:a41::50]",
  377. "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
  378. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  379. {"https://[::1%252]:1234",
  380. "https | [11] | [12] | [13] | [::1] | 1234 | / | [16] | [17]",
  381. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  382. /* here's "bad" zone id */
  383. {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
  384. "https | [11] | [12] | [13] | [fe80::20c:29ff:fe9c:409b] | 1234 "
  385. "| / | [16] | [17]",
  386. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  387. {"https://127.0.0.1:443",
  388. "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
  389. 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
  390. {"http://%3a:%3a@ex4mple/%3f+?+%3f+%23#+%23%3f%g7",
  391. "http | : | : | [13] | ex4mple | [15] | /?+ | ? # | +#?%g7",
  392. 0, CURLU_URLDECODE, CURLUE_OK},
  393. {"http://%3a:%3a@ex4mple/%3f?%3f%35#%35%3f%g7",
  394. "http | %3a | %3a | [13] | ex4mple | [15] | /%3f | %3f%35 | %35%3f%g7",
  395. 0, 0, CURLUE_OK},
  396. {"http://HO0_-st%41/",
  397. "http | [11] | [12] | [13] | HO0_-stA | [15] | / | [16] | [17]",
  398. 0, 0, CURLUE_OK},
  399. {"file://hello.html",
  400. "",
  401. 0, 0, CURLUE_BAD_FILE_URL},
  402. {"http://HO0_-st/",
  403. "http | [11] | [12] | [13] | HO0_-st | [15] | / | [16] | [17]",
  404. 0, 0, CURLUE_OK},
  405. {"imap://user:pass;option@server/path",
  406. "imap | user | pass | option | server | [15] | /path | [16] | [17]",
  407. 0, 0, CURLUE_OK},
  408. {"http://user:pass;option@server/path",
  409. "http | user | pass;option | [13] | server | [15] | /path | [16] | [17]",
  410. 0, 0, CURLUE_OK},
  411. {"file:/hello.html",
  412. "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
  413. 0, 0, CURLUE_OK},
  414. {"file:/h",
  415. "file | [11] | [12] | [13] | [14] | [15] | /h | [16] | [17]",
  416. 0, 0, CURLUE_OK},
  417. {"file:/",
  418. "file | [11] | [12] | [13] | [14] | [15] | | [16] | [17]",
  419. 0, 0, CURLUE_BAD_FILE_URL},
  420. {"file://127.0.0.1/hello.html",
  421. "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
  422. 0, 0, CURLUE_OK},
  423. {"file:////hello.html",
  424. "file | [11] | [12] | [13] | [14] | [15] | //hello.html | [16] | [17]",
  425. 0, 0, CURLUE_OK},
  426. {"file:///hello.html",
  427. "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
  428. 0, 0, CURLUE_OK},
  429. {"https://127.0.0.1",
  430. "https | [11] | [12] | [13] | 127.0.0.1 | 443 | / | [16] | [17]",
  431. 0, CURLU_DEFAULT_PORT, CURLUE_OK},
  432. {"https://127.0.0.1",
  433. "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
  434. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  435. {"https://[::1]:1234",
  436. "https | [11] | [12] | [13] | [::1] | 1234 | / | [16] | [17]",
  437. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  438. {"https://127abc.com",
  439. "https | [11] | [12] | [13] | 127abc.com | [15] | / | [16] | [17]",
  440. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  441. {"https:// example.com?check", "",
  442. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  443. {"https://e x a m p l e.com?check", "",
  444. CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  445. {"https://example.com?check",
  446. "https | [11] | [12] | [13] | example.com | [15] | / | check | [17]",
  447. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  448. {"https://example.com:65536",
  449. "",
  450. CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
  451. {"https://example.com:-1#moo",
  452. "",
  453. CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
  454. {"https://example.com:0#moo",
  455. "https | [11] | [12] | [13] | example.com | 0 | / | "
  456. "[16] | moo",
  457. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  458. {"https://example.com:01#moo",
  459. "https | [11] | [12] | [13] | example.com | 1 | / | "
  460. "[16] | moo",
  461. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  462. {"https://example.com:1#moo",
  463. "https | [11] | [12] | [13] | example.com | 1 | / | "
  464. "[16] | moo",
  465. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  466. {"http://example.com#moo",
  467. "http | [11] | [12] | [13] | example.com | [15] | / | "
  468. "[16] | moo",
  469. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  470. {"http://example.com",
  471. "http | [11] | [12] | [13] | example.com | [15] | / | "
  472. "[16] | [17]",
  473. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  474. {"http://example.com/path/html",
  475. "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
  476. "[16] | [17]",
  477. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  478. {"http://example.com/path/html?query=name",
  479. "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
  480. "query=name | [17]",
  481. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  482. {"http://example.com/path/html?query=name#anchor",
  483. "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
  484. "query=name | anchor",
  485. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  486. {"http://example.com:1234/path/html?query=name#anchor",
  487. "http | [11] | [12] | [13] | example.com | 1234 | /path/html | "
  488. "query=name | anchor",
  489. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  490. {"http:///user:password@example.com:1234/path/html?query=name#anchor",
  491. "http | user | password | [13] | example.com | 1234 | /path/html | "
  492. "query=name | anchor",
  493. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  494. {"https://user:password@example.com:1234/path/html?query=name#anchor",
  495. "https | user | password | [13] | example.com | 1234 | /path/html | "
  496. "query=name | anchor",
  497. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  498. {"http://user:password@example.com:1234/path/html?query=name#anchor",
  499. "http | user | password | [13] | example.com | 1234 | /path/html | "
  500. "query=name | anchor",
  501. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  502. {"http:/user:password@example.com:1234/path/html?query=name#anchor",
  503. "http | user | password | [13] | example.com | 1234 | /path/html | "
  504. "query=name | anchor",
  505. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  506. {"http:////user:password@example.com:1234/path/html?query=name#anchor",
  507. "",
  508. CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_SLASHES},
  509. {NULL, NULL, 0, 0, CURLUE_OK},
  510. };
  511. static const struct urltestcase get_url_list[] = {
  512. {"example.com",
  513. "example.com/",
  514. CURLU_GUESS_SCHEME, CURLU_NO_GUESS_SCHEME, CURLUE_OK},
  515. {"http://user@example.com?#",
  516. "http://user@example.com/?#",
  517. 0, CURLU_GET_EMPTY, CURLUE_OK},
  518. /* WHATWG disgrees, it wants "https:/0.0.0.0/" */
  519. {"https://0x.0x.0", "https://0x.0x.0/", 0, 0, CURLUE_OK},
  520. {"https://example.com:000000000000000000000443/foo",
  521. "https://example.com/foo",
  522. 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
  523. {"https://example.com:000000000000000000000/foo",
  524. "https://example.com:0/foo",
  525. 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
  526. {"https://192.0x0000A80001", "https://192.168.0.1/", 0, 0, CURLUE_OK},
  527. {"https://0xffffffff", "https://255.255.255.255/", 0, 0, CURLUE_OK},
  528. {"https://1.0x1000000", "https://1.0x1000000/", 0, 0, CURLUE_OK},
  529. {"https://0x7f.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
  530. {"https://1.2.3.256.com", "https://1.2.3.256.com/", 0, 0, CURLUE_OK},
  531. {"https://10.com", "https://10.com/", 0, 0, CURLUE_OK},
  532. {"https://1.2.com", "https://1.2.com/", 0, 0, CURLUE_OK},
  533. {"https://1.2.3.com", "https://1.2.3.com/", 0, 0, CURLUE_OK},
  534. {"https://1.2.com.99", "https://1.2.com.99/", 0, 0, CURLUE_OK},
  535. {"https://[fe80::0000:20c:29ff:fe9c:409b]:80/moo",
  536. "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
  537. 0, 0, CURLUE_OK},
  538. {"https://[fe80::020c:29ff:fe9c:409b]:80/moo",
  539. "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
  540. 0, 0, CURLUE_OK},
  541. {"https://[fe80:0000:0000:0000:020c:29ff:fe9c:409b]:80/moo",
  542. "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
  543. 0, 0, CURLUE_OK},
  544. {"https://[fe80:0:0:0:409b::]:80/moo",
  545. "https://[fe80::409b:0:0:0]:80/moo",
  546. 0, 0, CURLUE_OK},
  547. {"https://[::%25fakeit];80/moo",
  548. "",
  549. 0, 0, CURLUE_BAD_PORT_NUMBER},
  550. {"https://[fe80::20c:29ff:fe9c:409b]-80/moo",
  551. "",
  552. 0, 0, CURLUE_BAD_PORT_NUMBER},
  553. #ifdef USE_IDN
  554. {"https://räksmörgås.se/path?q#frag",
  555. "https://xn--rksmrgs-5wao1o.se/path?q#frag", 0, CURLU_PUNYCODE, CURLUE_OK},
  556. #endif
  557. /* unsupported schemes with no guessing enabled */
  558. {"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIEhUTUw+PG1ldGEgY",
  559. "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  560. {"d:anything-really", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  561. {"about:config", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  562. {"example://foo", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  563. {"mailto:infobot@example.com?body=send%20current-issue", "", 0, 0,
  564. CURLUE_UNSUPPORTED_SCHEME},
  565. {"about:80", "https://about:80/", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  566. /* percent encoded host names */
  567. {"http://example.com%40127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  568. {"http://example.com%21127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  569. {"http://example.com%3f127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  570. {"http://example.com%23127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  571. {"http://example.com%3a127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  572. {"http://example.com%09127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  573. {"http://example.com%2F127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  574. {"https://%41", "https://A/", 0, 0, CURLUE_OK},
  575. {"https://%20", "", 0, 0, CURLUE_BAD_HOSTNAME},
  576. {"https://%41%0d", "", 0, 0, CURLUE_BAD_HOSTNAME},
  577. {"https://%25", "", 0, 0, CURLUE_BAD_HOSTNAME},
  578. {"https://_%c0_", "https://_\xC0_/", 0, 0, CURLUE_OK},
  579. {"https://_%c0_", "https://_%C0_/", 0, CURLU_URLENCODE, CURLUE_OK},
  580. /* IPv4 trickeries */
  581. {"https://16843009", "https://1.1.1.1/", 0, 0, CURLUE_OK},
  582. {"https://0177.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
  583. {"https://0111.02.0x3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
  584. {"https://0111.02.0x3.", "https://0111.02.0x3./", 0, 0, CURLUE_OK},
  585. {"https://0111.02.030", "https://73.2.0.24/", 0, 0, CURLUE_OK},
  586. {"https://0111.02.030.", "https://0111.02.030./", 0, 0, CURLUE_OK},
  587. {"https://0xff.0xff.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
  588. {"https://1.0xffffff", "https://1.255.255.255/", 0, 0, CURLUE_OK},
  589. /* IPv4 numerical overflows or syntax errors will not normalize */
  590. {"https://a127.0.0.1", "https://a127.0.0.1/", 0, 0, CURLUE_OK},
  591. {"https://\xff.127.0.0.1", "https://%FF.127.0.0.1/", 0, CURLU_URLENCODE,
  592. CURLUE_OK},
  593. {"https://127.-0.0.1", "https://127.-0.0.1/", 0, 0, CURLUE_OK},
  594. {"https://127.0. 1", "https://127.0.0.1/", 0, 0, CURLUE_MALFORMED_INPUT},
  595. {"https://1.2.3.256", "https://1.2.3.256/", 0, 0, CURLUE_OK},
  596. {"https://1.2.3.256.", "https://1.2.3.256./", 0, 0, CURLUE_OK},
  597. {"https://1.2.3.4.5", "https://1.2.3.4.5/", 0, 0, CURLUE_OK},
  598. {"https://1.2.0x100.3", "https://1.2.0x100.3/", 0, 0, CURLUE_OK},
  599. {"https://4294967296", "https://4294967296/", 0, 0, CURLUE_OK},
  600. {"https://123host", "https://123host/", 0, 0, CURLUE_OK},
  601. /* 40 bytes scheme is the max allowed */
  602. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
  603. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa://hostname/path",
  604. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  605. /* 41 bytes scheme is not allowed */
  606. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
  607. "",
  608. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_BAD_SCHEME},
  609. {"https://[fe80::20c:29ff:fe9c:409b%]:1234",
  610. "",
  611. 0, 0, CURLUE_BAD_IPV6},
  612. {"https://[fe80::20c:29ff:fe9c:409b%25]:1234",
  613. "https://[fe80::20c:29ff:fe9c:409b%2525]:1234/",
  614. 0, 0, CURLUE_OK},
  615. {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
  616. "https://[fe80::20c:29ff:fe9c:409b%25eth0]:1234/",
  617. 0, 0, CURLUE_OK},
  618. {"https://[::%25fakeit]/moo",
  619. "https://[::%25fakeit]/moo",
  620. 0, 0, CURLUE_OK},
  621. {"smtp.example.com/path/html",
  622. "smtp://smtp.example.com/path/html",
  623. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  624. {"https.example.com/path/html",
  625. "http://https.example.com/path/html",
  626. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  627. {"dict.example.com/path/html",
  628. "dict://dict.example.com/path/html",
  629. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  630. {"pop3.example.com/path/html",
  631. "pop3://pop3.example.com/path/html",
  632. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  633. {"ldap.example.com/path/html",
  634. "ldap://ldap.example.com/path/html",
  635. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  636. {"imap.example.com/path/html",
  637. "imap://imap.example.com/path/html",
  638. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  639. {"ftp.example.com/path/html",
  640. "ftp://ftp.example.com/path/html",
  641. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  642. {"example.com/path/html",
  643. "http://example.com/path/html",
  644. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  645. {"smtp.com/path/html",
  646. "smtp://smtp.com/path/html",
  647. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  648. {"dict.com/path/html",
  649. "dict://dict.com/path/html",
  650. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  651. {"pop3.com/path/html",
  652. "pop3://pop3.com/path/html",
  653. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  654. {"ldap.com/path/html",
  655. "ldap://ldap.com/path/html",
  656. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  657. {"imap.com/path/html",
  658. "imap://imap.com/path/html",
  659. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  660. {"ftp.com/path/html",
  661. "ftp://ftp.com/path/html",
  662. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  663. {"smtp/path/html",
  664. "http://smtp/path/html",
  665. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  666. {"dict/path/html",
  667. "http://dict/path/html",
  668. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  669. {"pop3/path/html",
  670. "http://pop3/path/html",
  671. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  672. {"ldap/path/html",
  673. "http://ldap/path/html",
  674. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  675. {"imap/path/html",
  676. "http://imap/path/html",
  677. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  678. {"ftp/path/html",
  679. "http://ftp/path/html",
  680. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  681. {"HTTP://test/", "http://test/", 0, 0, CURLUE_OK},
  682. {"http://HO0_-st..~./", "http://HO0_-st..~./", 0, 0, CURLUE_OK},
  683. {"http:/@example.com: 123/", "", 0, 0, CURLUE_MALFORMED_INPUT},
  684. {"http:/@example.com:123 /", "", 0, 0, CURLUE_MALFORMED_INPUT},
  685. {"http:/@example.com:123a/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
  686. {"http://host/file\r", "", 0, 0, CURLUE_MALFORMED_INPUT},
  687. {"http://host/file\n\x03", "", 0, 0, CURLUE_MALFORMED_INPUT},
  688. {"htt\x02://host/file", "",
  689. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  690. {" http://host/file", "", 0, 0, CURLUE_MALFORMED_INPUT},
  691. /* here the password ends at the semicolon and options is 'word' */
  692. {"imap://user:pass;word@host/file",
  693. "imap://user:pass;word@host/file",
  694. 0, 0, CURLUE_OK},
  695. /* here the password has the semicolon */
  696. {"http://user:pass;word@host/file",
  697. "http://user:pass;word@host/file", 0, 0, CURLUE_OK},
  698. {"file:///file.txt#moo", "file:///file.txt#moo", 0, 0, CURLUE_OK},
  699. {"file:////file.txt", "file:////file.txt", 0, 0, CURLUE_OK},
  700. {"file:///file.txt", "file:///file.txt", 0, 0, CURLUE_OK},
  701. {"file:./", "file://", 0, 0, CURLUE_OK},
  702. {"http://example.com/hello/../here",
  703. "http://example.com/hello/../here",
  704. CURLU_PATH_AS_IS, 0, CURLUE_OK},
  705. {"http://example.com/hello/../here",
  706. "http://example.com/here",
  707. 0, 0, CURLUE_OK},
  708. {"http://example.com:80",
  709. "http://example.com/",
  710. 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
  711. {"tp://example.com/path/html",
  712. "",
  713. 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  714. {"http://hello:fool@example.com",
  715. "",
  716. CURLU_DISALLOW_USER, 0, CURLUE_USER_NOT_ALLOWED},
  717. {"http:/@example.com:123",
  718. "http://@example.com:123/",
  719. 0, 0, CURLUE_OK},
  720. {"http:/:password@example.com",
  721. "http://:password@example.com/",
  722. 0, 0, CURLUE_OK},
  723. {"http://user@example.com?#",
  724. "http://user@example.com/",
  725. 0, 0, CURLUE_OK},
  726. {"http://user@example.com?",
  727. "http://user@example.com/",
  728. 0, 0, CURLUE_OK},
  729. {"http://user@example.com#anchor",
  730. "http://user@example.com/#anchor",
  731. 0, 0, CURLUE_OK},
  732. {"example.com/path/html",
  733. "https://example.com/path/html",
  734. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  735. {"example.com/path/html",
  736. "",
  737. 0, 0, CURLUE_BAD_SCHEME},
  738. {"http://user:password@example.com:1234/path/html?query=name#anchor",
  739. "http://user:password@example.com:1234/path/html?query=name#anchor",
  740. 0, 0, CURLUE_OK},
  741. {"http://example.com:1234/path/html?query=name#anchor",
  742. "http://example.com:1234/path/html?query=name#anchor",
  743. 0, 0, CURLUE_OK},
  744. {"http://example.com/path/html?query=name#anchor",
  745. "http://example.com/path/html?query=name#anchor",
  746. 0, 0, CURLUE_OK},
  747. {"http://example.com/path/html?query=name",
  748. "http://example.com/path/html?query=name",
  749. 0, 0, CURLUE_OK},
  750. {"http://example.com/path/html",
  751. "http://example.com/path/html",
  752. 0, 0, CURLUE_OK},
  753. {"tp://example.com/path/html",
  754. "tp://example.com/path/html",
  755. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  756. {"custom-scheme://host?expected=test-good",
  757. "custom-scheme://host/?expected=test-good",
  758. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  759. {"custom-scheme://?expected=test-bad",
  760. "",
  761. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_NO_HOST},
  762. {"custom-scheme://?expected=test-new-good",
  763. "custom-scheme:///?expected=test-new-good",
  764. CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
  765. {"custom-scheme://host?expected=test-still-good",
  766. "custom-scheme://host/?expected=test-still-good",
  767. CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
  768. {NULL, NULL, 0, 0, CURLUE_OK}
  769. };
  770. static int checkurl(const char *org, const char *url, const char *out)
  771. {
  772. if(strcmp(out, url)) {
  773. fprintf(stderr,
  774. "Org: %s\n"
  775. "Wanted: %s\n"
  776. "Got : %s\n",
  777. org, out, url);
  778. return 1;
  779. }
  780. return 0;
  781. }
  782. /* 1. Set the URL
  783. 2. Set components
  784. 3. Extract all components (not URL)
  785. */
  786. static const struct setgetcase setget_parts_list[] = {
  787. {"https://example.com/",
  788. "query=\"\",",
  789. "https | [11] | [12] | [13] | example.com | [15] | / | | [17]",
  790. 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
  791. {"https://example.com/",
  792. "fragment=\"\",",
  793. "https | [11] | [12] | [13] | example.com | [15] | / | [16] | ",
  794. 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
  795. {"https://example.com/",
  796. "query=\"\",",
  797. "https | [11] | [12] | [13] | example.com | [15] | / | [16] | [17]",
  798. 0, 0, 0, CURLUE_OK},
  799. {"https://example.com",
  800. "path=get,",
  801. "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
  802. 0, 0, 0, CURLUE_OK},
  803. {"https://example.com",
  804. "path=/get,",
  805. "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
  806. 0, 0, 0, CURLUE_OK},
  807. {"https://example.com",
  808. "path=g e t,",
  809. "https | [11] | [12] | [13] | example.com | [15] | /g%20e%20t | "
  810. "[16] | [17]",
  811. 0, CURLU_URLENCODE, 0, CURLUE_OK},
  812. {NULL, NULL, NULL, 0, 0, 0, CURLUE_OK}
  813. };
  814. /* !checksrc! disable SPACEBEFORECOMMA 1 */
  815. static const struct setcase set_parts_list[] = {
  816. {"https://example.com/",
  817. "host=%43url.se,",
  818. "https://%43url.se/",
  819. 0, 0, CURLUE_OK, CURLUE_OK},
  820. {"https://example.com/",
  821. "host=%25url.se,",
  822. "",
  823. 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  824. {"https://example.com/?param=value",
  825. "query=\"\",",
  826. "https://example.com/",
  827. 0, CURLU_APPENDQUERY | CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  828. {"https://example.com/",
  829. "host=\"\",",
  830. "https://example.com/",
  831. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  832. {"https://example.com/",
  833. "host=\"\",",
  834. "https://example.com/",
  835. 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  836. {"https://example.com",
  837. "path=get,",
  838. "https://example.com/get",
  839. 0, 0, CURLUE_OK, CURLUE_OK},
  840. {"https://example.com/",
  841. "scheme=ftp+-.123,",
  842. "ftp+-.123://example.com/",
  843. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  844. {"https://example.com/",
  845. "scheme=1234,",
  846. "https://example.com/",
  847. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  848. {"https://example.com/",
  849. "scheme=1http,",
  850. "https://example.com/",
  851. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  852. {"https://example.com/",
  853. "scheme=-ftp,",
  854. "https://example.com/",
  855. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  856. {"https://example.com/",
  857. "scheme=+ftp,",
  858. "https://example.com/",
  859. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  860. {"https://example.com/",
  861. "scheme=.ftp,",
  862. "https://example.com/",
  863. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  864. {"https://example.com/",
  865. "host=example.com%2fmoo,",
  866. "",
  867. 0, /* get */
  868. 0, /* set */
  869. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  870. {"https://example.com/",
  871. "host=http://fake,",
  872. "",
  873. 0, /* get */
  874. 0, /* set */
  875. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  876. {"https://example.com/",
  877. "host=test%,",
  878. "",
  879. 0, /* get */
  880. 0, /* set */
  881. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  882. {"https://example.com/",
  883. "host=te st,",
  884. "",
  885. 0, /* get */
  886. 0, /* set */
  887. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  888. {"https://example.com/",
  889. "host=0xff,", /* '++' there's no automatic URL decode when setting this
  890. part */
  891. "https://0xff/",
  892. 0, /* get */
  893. 0, /* set */
  894. CURLUE_OK, CURLUE_OK},
  895. {"https://example.com/",
  896. "query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
  897. "https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2bLX8TPHs",
  898. CURLU_URLDECODE, /* decode on get */
  899. CURLU_URLENCODE, /* encode on set */
  900. CURLUE_OK, CURLUE_OK},
  901. {"https://example.com/",
  902. /* Set a bad scheme *including* :// */
  903. "scheme=https://,",
  904. "https://example.com/",
  905. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  906. {"https://example.com/",
  907. /* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
  908. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
  909. "https://example.com/",
  910. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  911. {"https://example.com/",
  912. /* set a 40 bytes scheme */
  913. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,",
  914. "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb://example.com/",
  915. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  916. {"https://[::1%25fake]:1234/",
  917. "zoneid=NULL,",
  918. "https://[::1]:1234/",
  919. 0, 0, CURLUE_OK, CURLUE_OK},
  920. {"https://host:1234/",
  921. "port=NULL,",
  922. "https://host/",
  923. 0, 0, CURLUE_OK, CURLUE_OK},
  924. {"https://host:1234/",
  925. "port=\"\",",
  926. "https://host:1234/",
  927. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  928. {"https://host:1234/",
  929. "port=56 78,",
  930. "https://host:1234/",
  931. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  932. {"https://host:1234/",
  933. "port=0,",
  934. "https://host:0/",
  935. 0, 0, CURLUE_OK, CURLUE_OK},
  936. {"https://host:1234/",
  937. "port=65535,",
  938. "https://host:65535/",
  939. 0, 0, CURLUE_OK, CURLUE_OK},
  940. {"https://host:1234/",
  941. "port=65536,",
  942. "https://host:1234/",
  943. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  944. {"https://host/",
  945. "path=%4A%4B%4C,",
  946. "https://host/%4a%4b%4c",
  947. 0, 0, CURLUE_OK, CURLUE_OK},
  948. {"https://host/mooo?q#f",
  949. "path=NULL,query=NULL,fragment=NULL,",
  950. "https://host/",
  951. 0, 0, CURLUE_OK, CURLUE_OK},
  952. {"https://user:secret@host/",
  953. "user=NULL,password=NULL,",
  954. "https://host/",
  955. 0, 0, CURLUE_OK, CURLUE_OK},
  956. {NULL,
  957. "scheme=https,user= @:,host=foobar,",
  958. "https://%20%20%20%40%3a@foobar/",
  959. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  960. /* Setting a host name with spaces is not OK: */
  961. {NULL,
  962. "scheme=https,host= ,path= ,user= ,password= ,query= ,fragment= ,",
  963. "[nothing]",
  964. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  965. {NULL,
  966. "scheme=https,host=foobar,path=/this /path /is /here,",
  967. "https://foobar/this%20/path%20/is%20/here",
  968. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  969. {NULL,
  970. "scheme=https,host=foobar,path=\xc3\xa4\xc3\xb6\xc3\xbc,",
  971. "https://foobar/%c3%a4%c3%b6%c3%bc",
  972. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  973. {"imap://user:secret;opt@host/",
  974. "options=updated,scheme=imaps,password=p4ssw0rd,",
  975. "imaps://user:p4ssw0rd;updated@host/",
  976. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  977. {"imap://user:secret;optit@host/",
  978. "scheme=https,",
  979. "https://user:secret@host/",
  980. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  981. {"file:///file#anchor",
  982. "scheme=https,host=example,",
  983. "https://example/file#anchor",
  984. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  985. {NULL, /* start fresh! */
  986. "scheme=file,host=127.0.0.1,path=/no,user=anonymous,",
  987. "file:///no",
  988. 0, 0, CURLUE_OK, CURLUE_OK},
  989. {NULL, /* start fresh! */
  990. "scheme=ftp,host=127.0.0.1,path=/no,user=anonymous,",
  991. "ftp://anonymous@127.0.0.1/no",
  992. 0, 0, CURLUE_OK, CURLUE_OK},
  993. {NULL, /* start fresh! */
  994. "scheme=https,host=example.com,",
  995. "https://example.com/",
  996. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  997. {"http://user:foo@example.com/path?query#frag",
  998. "fragment=changed,",
  999. "http://user:foo@example.com/path?query#changed",
  1000. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  1001. {"http://example.com/",
  1002. "scheme=foo,", /* not accepted */
  1003. "http://example.com/",
  1004. 0, 0, CURLUE_OK, CURLUE_UNSUPPORTED_SCHEME},
  1005. {"http://example.com/",
  1006. "scheme=https,path=/hello,fragment=snippet,",
  1007. "https://example.com/hello#snippet",
  1008. 0, 0, CURLUE_OK, CURLUE_OK},
  1009. {"http://example.com:80",
  1010. "user=foo,port=1922,",
  1011. "http://foo@example.com:1922/",
  1012. 0, 0, CURLUE_OK, CURLUE_OK},
  1013. {"http://example.com:80",
  1014. "user=foo,password=bar,",
  1015. "http://foo:bar@example.com:80/",
  1016. 0, 0, CURLUE_OK, CURLUE_OK},
  1017. {"http://example.com:80",
  1018. "user=foo,",
  1019. "http://foo@example.com:80/",
  1020. 0, 0, CURLUE_OK, CURLUE_OK},
  1021. {"http://example.com",
  1022. "host=www.example.com,",
  1023. "http://www.example.com/",
  1024. 0, 0, CURLUE_OK, CURLUE_OK},
  1025. {"http://example.com:80",
  1026. "scheme=ftp,",
  1027. "ftp://example.com:80/",
  1028. 0, 0, CURLUE_OK, CURLUE_OK},
  1029. {"custom-scheme://host",
  1030. "host=\"\",",
  1031. "custom-scheme://host/",
  1032. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK,
  1033. CURLUE_BAD_HOSTNAME},
  1034. {"custom-scheme://host",
  1035. "host=\"\",",
  1036. "custom-scheme:///",
  1037. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY,
  1038. CURLUE_OK, CURLUE_OK},
  1039. {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK}
  1040. };
  1041. static CURLUPart part2id(char *part)
  1042. {
  1043. if(!strcmp("url", part))
  1044. return CURLUPART_URL;
  1045. if(!strcmp("scheme", part))
  1046. return CURLUPART_SCHEME;
  1047. if(!strcmp("user", part))
  1048. return CURLUPART_USER;
  1049. if(!strcmp("password", part))
  1050. return CURLUPART_PASSWORD;
  1051. if(!strcmp("options", part))
  1052. return CURLUPART_OPTIONS;
  1053. if(!strcmp("host", part))
  1054. return CURLUPART_HOST;
  1055. if(!strcmp("port", part))
  1056. return CURLUPART_PORT;
  1057. if(!strcmp("path", part))
  1058. return CURLUPART_PATH;
  1059. if(!strcmp("query", part))
  1060. return CURLUPART_QUERY;
  1061. if(!strcmp("fragment", part))
  1062. return CURLUPART_FRAGMENT;
  1063. if(!strcmp("zoneid", part))
  1064. return CURLUPART_ZONEID;
  1065. return (CURLUPart)9999; /* bad input => bad output */
  1066. }
  1067. static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
  1068. {
  1069. const char *p = cmd;
  1070. CURLUcode uc;
  1071. /* make sure the last command ends with a comma too! */
  1072. while(p) {
  1073. char *e = strchr(p, ',');
  1074. if(e) {
  1075. size_t n = (size_t)(e - p);
  1076. char buf[80];
  1077. char part[80];
  1078. char value[80];
  1079. memset(part, 0, sizeof(part)); /* Avoid valgrind false positive. */
  1080. memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
  1081. memcpy(buf, p, n);
  1082. buf[n] = 0;
  1083. if(2 == sscanf(buf, "%79[^=]=%79[^,]", part, value)) {
  1084. CURLUPart what = part2id(part);
  1085. #if 0
  1086. /* for debugging this */
  1087. fprintf(stderr, "%s = \"%s\" [%d]\n", part, value, (int)what);
  1088. #endif
  1089. if(what > CURLUPART_ZONEID)
  1090. fprintf(stderr, "UNKNOWN part '%s'\n", part);
  1091. if(!strcmp("NULL", value))
  1092. uc = curl_url_set(u, what, NULL, setflags);
  1093. else if(!strcmp("\"\"", value))
  1094. uc = curl_url_set(u, what, "", setflags);
  1095. else
  1096. uc = curl_url_set(u, what, value, setflags);
  1097. if(uc)
  1098. return uc;
  1099. }
  1100. p = e + 1;
  1101. continue;
  1102. }
  1103. break;
  1104. }
  1105. return CURLUE_OK;
  1106. }
  1107. static const struct redircase set_url_list[] = {
  1108. {"http://example.org/",
  1109. "../path/././../../moo",
  1110. "http://example.org/moo",
  1111. 0, 0, CURLUE_OK},
  1112. {"http://example.org/",
  1113. "//example.org/../path/../../",
  1114. "http://example.org/",
  1115. 0, 0, CURLUE_OK},
  1116. {"http://example.org/",
  1117. "///example.org/../path/../../",
  1118. "http://example.org/",
  1119. 0, 0, CURLUE_OK},
  1120. {"http://example.org/foo/bar",
  1121. ":23",
  1122. "http://example.org/foo/:23",
  1123. 0, 0, CURLUE_OK},
  1124. {"http://example.org/foo/bar",
  1125. "\\x",
  1126. "http://example.org/foo/\\x",
  1127. /* WHATWG disagrees */
  1128. 0, 0, CURLUE_OK},
  1129. {"http://example.org/foo/bar",
  1130. "#/",
  1131. "http://example.org/foo/bar#/",
  1132. 0, 0, CURLUE_OK},
  1133. {"http://example.org/foo/bar",
  1134. "?/",
  1135. "http://example.org/foo/bar?/",
  1136. 0, 0, CURLUE_OK},
  1137. {"http://example.org/foo/bar",
  1138. "#;?",
  1139. "http://example.org/foo/bar#;?",
  1140. 0, 0, CURLUE_OK},
  1141. {"http://example.org/foo/bar",
  1142. "#",
  1143. "http://example.org/foo/bar",
  1144. /* This happens because the parser removes empty fragments */
  1145. 0, 0, CURLUE_OK},
  1146. {"http://example.org/foo/bar",
  1147. "?",
  1148. "http://example.org/foo/bar",
  1149. /* This happens because the parser removes empty queries */
  1150. 0, 0, CURLUE_OK},
  1151. {"http://example.org/foo/bar",
  1152. "?#",
  1153. "http://example.org/foo/bar",
  1154. /* This happens because the parser removes empty queries and fragments */
  1155. 0, 0, CURLUE_OK},
  1156. {"http://example.com/please/../gimme/%TESTNUMBER?foobar#hello",
  1157. "http://example.net/there/it/is/../../tes t case=/%TESTNUMBER0002? yes no",
  1158. "http://example.net/there/tes%20t%20case=/%TESTNUMBER0002?+yes+no",
  1159. 0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
  1160. {"http://local.test?redirect=http://local.test:80?-321",
  1161. "http://local.test:80?-123",
  1162. "http://local.test:80/?-123",
  1163. 0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
  1164. {"http://local.test?redirect=http://local.test:80?-321",
  1165. "http://local.test:80?-123",
  1166. "http://local.test:80/?-123",
  1167. 0, 0, CURLUE_OK},
  1168. {"http://example.org/static/favicon/wikipedia.ico",
  1169. "//fake.example.com/licenses/by-sa/3.0/",
  1170. "http://fake.example.com/licenses/by-sa/3.0/",
  1171. 0, 0, CURLUE_OK},
  1172. {"https://example.org/static/favicon/wikipedia.ico",
  1173. "//fake.example.com/licenses/by-sa/3.0/",
  1174. "https://fake.example.com/licenses/by-sa/3.0/",
  1175. 0, 0, CURLUE_OK},
  1176. {"file://localhost/path?query#frag",
  1177. "foo#another",
  1178. "file:///foo#another",
  1179. 0, 0, CURLUE_OK},
  1180. {"http://example.com/path?query#frag",
  1181. "https://two.example.com/bradnew",
  1182. "https://two.example.com/bradnew",
  1183. 0, 0, CURLUE_OK},
  1184. {"http://example.com/path?query#frag",
  1185. "../../newpage#foo",
  1186. "http://example.com/newpage#foo",
  1187. 0, 0, CURLUE_OK},
  1188. {"http://user:foo@example.com/path?query#frag",
  1189. "../../newpage",
  1190. "http://user:foo@example.com/newpage",
  1191. 0, 0, CURLUE_OK},
  1192. {"http://user:foo@example.com/path?query#frag",
  1193. "../newpage",
  1194. "http://user:foo@example.com/newpage",
  1195. 0, 0, CURLUE_OK},
  1196. {"http://user:foo@example.com/path?query#frag",
  1197. "http://?hi",
  1198. "http:///?hi",
  1199. 0, CURLU_NO_AUTHORITY, CURLUE_OK},
  1200. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1201. };
  1202. static int set_url(void)
  1203. {
  1204. int i;
  1205. int error = 0;
  1206. for(i = 0; set_url_list[i].in && !error; i++) {
  1207. CURLUcode rc;
  1208. CURLU *urlp = curl_url();
  1209. if(!urlp)
  1210. break;
  1211. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
  1212. set_url_list[i].urlflags);
  1213. if(!rc) {
  1214. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
  1215. set_url_list[i].setflags);
  1216. if(rc) {
  1217. fprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
  1218. __FILE__, __LINE__, set_url_list[i].set,
  1219. (int)rc, curl_url_strerror(rc));
  1220. error++;
  1221. }
  1222. else {
  1223. char *url = NULL;
  1224. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1225. if(rc) {
  1226. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1227. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1228. error++;
  1229. }
  1230. else {
  1231. if(checkurl(set_url_list[i].in, url, set_url_list[i].out)) {
  1232. error++;
  1233. }
  1234. }
  1235. curl_free(url);
  1236. }
  1237. }
  1238. else if(rc != set_url_list[i].ucode) {
  1239. fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
  1240. set_url_list[i].in, (int)rc, set_url_list[i].ucode);
  1241. error++;
  1242. }
  1243. curl_url_cleanup(urlp);
  1244. }
  1245. return error;
  1246. }
  1247. /* 1. Set a URL
  1248. 2. Set one or more parts
  1249. 3. Extract and compare all parts - not the URL
  1250. */
  1251. static int setget_parts(void)
  1252. {
  1253. int i;
  1254. int error = 0;
  1255. for(i = 0; setget_parts_list[i].set && !error; i++) {
  1256. CURLUcode rc;
  1257. CURLU *urlp = curl_url();
  1258. if(!urlp) {
  1259. error++;
  1260. break;
  1261. }
  1262. if(setget_parts_list[i].in)
  1263. rc = curl_url_set(urlp, CURLUPART_URL, setget_parts_list[i].in,
  1264. setget_parts_list[i].urlflags);
  1265. else
  1266. rc = CURLUE_OK;
  1267. if(!rc) {
  1268. char *url = NULL;
  1269. CURLUcode uc = updateurl(urlp, setget_parts_list[i].set,
  1270. setget_parts_list[i].setflags);
  1271. if(uc != setget_parts_list[i].pcode) {
  1272. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1273. setget_parts_list[i].set, (int)uc, setget_parts_list[i].pcode);
  1274. error++;
  1275. }
  1276. if(!uc) {
  1277. if(checkparts(urlp, setget_parts_list[i].set, setget_parts_list[i].out,
  1278. setget_parts_list[i].getflags))
  1279. error++; /* add */
  1280. }
  1281. curl_free(url);
  1282. }
  1283. else if(rc != CURLUE_OK) {
  1284. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1285. setget_parts_list[i].in, (int)rc, 0);
  1286. error++;
  1287. }
  1288. curl_url_cleanup(urlp);
  1289. }
  1290. return error;
  1291. }
  1292. static int set_parts(void)
  1293. {
  1294. int i;
  1295. int error = 0;
  1296. for(i = 0; set_parts_list[i].set && !error; i++) {
  1297. CURLUcode rc;
  1298. CURLU *urlp = curl_url();
  1299. if(!urlp) {
  1300. error++;
  1301. break;
  1302. }
  1303. if(set_parts_list[i].in)
  1304. rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
  1305. set_parts_list[i].urlflags);
  1306. else
  1307. rc = CURLUE_OK;
  1308. if(!rc) {
  1309. char *url = NULL;
  1310. CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
  1311. set_parts_list[i].setflags);
  1312. if(uc != set_parts_list[i].pcode) {
  1313. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1314. set_parts_list[i].set, (int)uc, set_parts_list[i].pcode);
  1315. error++;
  1316. }
  1317. if(!uc) {
  1318. /* only do this if it worked */
  1319. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1320. if(rc) {
  1321. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1322. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1323. error++;
  1324. }
  1325. else if(checkurl(set_parts_list[i].in, url, set_parts_list[i].out)) {
  1326. error++;
  1327. }
  1328. }
  1329. curl_free(url);
  1330. }
  1331. else if(rc != set_parts_list[i].ucode) {
  1332. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1333. set_parts_list[i].in, (int)rc, set_parts_list[i].ucode);
  1334. error++;
  1335. }
  1336. curl_url_cleanup(urlp);
  1337. }
  1338. return error;
  1339. }
  1340. static int get_url(void)
  1341. {
  1342. int i;
  1343. int error = 0;
  1344. for(i = 0; get_url_list[i].in && !error; i++) {
  1345. CURLUcode rc;
  1346. CURLU *urlp = curl_url();
  1347. if(!urlp) {
  1348. error++;
  1349. break;
  1350. }
  1351. rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
  1352. get_url_list[i].urlflags);
  1353. if(!rc) {
  1354. char *url = NULL;
  1355. rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
  1356. if(rc) {
  1357. fprintf(stderr, "%s:%d returned %d (%s). URL: '%s'\n",
  1358. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc),
  1359. get_url_list[i].in);
  1360. error++;
  1361. }
  1362. else {
  1363. if(checkurl(get_url_list[i].in, url, get_url_list[i].out)) {
  1364. error++;
  1365. }
  1366. }
  1367. curl_free(url);
  1368. }
  1369. if(rc != get_url_list[i].ucode) {
  1370. fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
  1371. get_url_list[i].in, (int)rc, get_url_list[i].ucode);
  1372. error++;
  1373. }
  1374. curl_url_cleanup(urlp);
  1375. }
  1376. return error;
  1377. }
  1378. static int get_parts(void)
  1379. {
  1380. int i;
  1381. int error = 0;
  1382. for(i = 0; get_parts_list[i].in && !error; i++) {
  1383. CURLUcode rc;
  1384. CURLU *urlp = curl_url();
  1385. if(!urlp) {
  1386. error++;
  1387. break;
  1388. }
  1389. rc = curl_url_set(urlp, CURLUPART_URL,
  1390. get_parts_list[i].in,
  1391. get_parts_list[i].urlflags);
  1392. if(rc != get_parts_list[i].ucode) {
  1393. fprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
  1394. get_parts_list[i].in, (int)rc, get_parts_list[i].ucode);
  1395. error++;
  1396. }
  1397. else if(get_parts_list[i].ucode) {
  1398. /* the expected error happened */
  1399. }
  1400. else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
  1401. get_parts_list[i].getflags))
  1402. error++;
  1403. curl_url_cleanup(urlp);
  1404. }
  1405. return error;
  1406. }
  1407. static const struct querycase append_list[] = {
  1408. {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02",
  1409. 0, CURLU_URLENCODE, CURLUE_OK},
  1410. {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3d#f",
  1411. 0, CURLU_URLENCODE, CURLUE_OK},
  1412. {"HTTP://test/?size=2#f", "name=joe doe",
  1413. "http://test/?size=2&name=joe+doe#f",
  1414. 0, CURLU_URLENCODE, CURLUE_OK},
  1415. {"HTTP://test/", "name=joe", "http://test/?name=joe", 0, 0, CURLUE_OK},
  1416. {"HTTP://test/?size=2", "name=joe", "http://test/?size=2&name=joe",
  1417. 0, 0, CURLUE_OK},
  1418. {"HTTP://test/?size=2&", "name=joe", "http://test/?size=2&name=joe",
  1419. 0, 0, CURLUE_OK},
  1420. {"HTTP://test/?size=2#f", "name=joe", "http://test/?size=2&name=joe#f",
  1421. 0, 0, CURLUE_OK},
  1422. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1423. };
  1424. static int append(void)
  1425. {
  1426. int i;
  1427. int error = 0;
  1428. for(i = 0; append_list[i].in && !error; i++) {
  1429. CURLUcode rc;
  1430. CURLU *urlp = curl_url();
  1431. if(!urlp) {
  1432. error++;
  1433. break;
  1434. }
  1435. rc = curl_url_set(urlp, CURLUPART_URL,
  1436. append_list[i].in,
  1437. append_list[i].urlflags);
  1438. if(rc)
  1439. error++;
  1440. else
  1441. rc = curl_url_set(urlp, CURLUPART_QUERY,
  1442. append_list[i].q,
  1443. append_list[i].qflags | CURLU_APPENDQUERY);
  1444. if(error)
  1445. ;
  1446. else if(rc != append_list[i].ucode) {
  1447. fprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
  1448. append_list[i].in, (int)rc, append_list[i].ucode);
  1449. error++;
  1450. }
  1451. else if(append_list[i].ucode) {
  1452. /* the expected error happened */
  1453. }
  1454. else {
  1455. char *url;
  1456. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1457. if(rc) {
  1458. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1459. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1460. error++;
  1461. }
  1462. else {
  1463. if(checkurl(append_list[i].in, url, append_list[i].out)) {
  1464. error++;
  1465. }
  1466. curl_free(url);
  1467. }
  1468. }
  1469. curl_url_cleanup(urlp);
  1470. }
  1471. return error;
  1472. }
  1473. static int scopeid(void)
  1474. {
  1475. CURLU *u = curl_url();
  1476. int error = 0;
  1477. CURLUcode rc;
  1478. char *url;
  1479. rc = curl_url_set(u, CURLUPART_URL,
  1480. "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
  1481. if(rc != CURLUE_OK) {
  1482. fprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
  1483. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1484. error++;
  1485. }
  1486. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1487. if(rc != CURLUE_OK) {
  1488. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1489. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1490. error++;
  1491. }
  1492. else {
  1493. curl_free(url);
  1494. }
  1495. rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
  1496. if(rc != CURLUE_OK) {
  1497. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1498. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1499. error++;
  1500. }
  1501. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1502. if(rc != CURLUE_OK) {
  1503. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1504. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1505. error++;
  1506. }
  1507. else {
  1508. curl_free(url);
  1509. }
  1510. rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
  1511. if(rc != CURLUE_OK) {
  1512. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1513. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1514. error++;
  1515. }
  1516. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1517. if(rc != CURLUE_OK) {
  1518. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1519. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1520. error++;
  1521. }
  1522. else {
  1523. curl_free(url);
  1524. }
  1525. rc = curl_url_set(u, CURLUPART_HOST,
  1526. "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
  1527. if(rc != CURLUE_OK) {
  1528. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1529. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1530. error++;
  1531. }
  1532. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1533. if(rc != CURLUE_OK) {
  1534. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1535. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1536. error++;
  1537. }
  1538. else {
  1539. curl_free(url);
  1540. }
  1541. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1542. if(rc != CURLUE_OK) {
  1543. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1544. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1545. error++;
  1546. }
  1547. else {
  1548. curl_free(url);
  1549. }
  1550. rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
  1551. if(rc != CURLUE_OK) {
  1552. fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
  1553. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1554. error++;
  1555. }
  1556. else {
  1557. curl_free(url);
  1558. }
  1559. rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
  1560. if(rc != CURLUE_OK) {
  1561. fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
  1562. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1563. error++;
  1564. }
  1565. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1566. if(rc != CURLUE_OK) {
  1567. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1568. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1569. error++;
  1570. }
  1571. else {
  1572. curl_free(url);
  1573. }
  1574. curl_url_cleanup(u);
  1575. return error;
  1576. }
  1577. static int get_nothing(void)
  1578. {
  1579. CURLU *u = curl_url();
  1580. if(u) {
  1581. char *p;
  1582. CURLUcode rc;
  1583. rc = curl_url_get(u, CURLUPART_SCHEME, &p, 0);
  1584. if(rc != CURLUE_NO_SCHEME)
  1585. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1586. rc = curl_url_get(u, CURLUPART_HOST, &p, 0);
  1587. if(rc != CURLUE_NO_HOST)
  1588. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1589. rc = curl_url_get(u, CURLUPART_USER, &p, 0);
  1590. if(rc != CURLUE_NO_USER)
  1591. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1592. rc = curl_url_get(u, CURLUPART_PASSWORD, &p, 0);
  1593. if(rc != CURLUE_NO_PASSWORD)
  1594. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1595. rc = curl_url_get(u, CURLUPART_OPTIONS, &p, 0);
  1596. if(rc != CURLUE_NO_OPTIONS)
  1597. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1598. rc = curl_url_get(u, CURLUPART_PATH, &p, 0);
  1599. if(rc != CURLUE_OK)
  1600. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1601. else
  1602. curl_free(p);
  1603. rc = curl_url_get(u, CURLUPART_QUERY, &p, 0);
  1604. if(rc != CURLUE_NO_QUERY)
  1605. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1606. rc = curl_url_get(u, CURLUPART_FRAGMENT, &p, 0);
  1607. if(rc != CURLUE_NO_FRAGMENT)
  1608. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1609. rc = curl_url_get(u, CURLUPART_ZONEID, &p, 0);
  1610. if(rc != CURLUE_NO_ZONEID)
  1611. fprintf(stderr, "unexpected return code %u on line %u\n", (int)rc,
  1612. __LINE__);
  1613. curl_url_cleanup(u);
  1614. }
  1615. return 0;
  1616. }
  1617. static const struct clearurlcase clear_url_list[] ={
  1618. {CURLUPART_SCHEME, "http", NULL, CURLUE_NO_SCHEME},
  1619. {CURLUPART_USER, "user", NULL, CURLUE_NO_USER},
  1620. {CURLUPART_PASSWORD, "password", NULL, CURLUE_NO_PASSWORD},
  1621. {CURLUPART_OPTIONS, "options", NULL, CURLUE_NO_OPTIONS},
  1622. {CURLUPART_HOST, "host", NULL, CURLUE_NO_HOST},
  1623. {CURLUPART_ZONEID, "eth0", NULL, CURLUE_NO_ZONEID},
  1624. {CURLUPART_PORT, "1234", NULL, CURLUE_NO_PORT},
  1625. {CURLUPART_PATH, "/hello", "/", CURLUE_OK},
  1626. {CURLUPART_QUERY, "a=b", NULL, CURLUE_NO_QUERY},
  1627. {CURLUPART_FRAGMENT, "anchor", NULL, CURLUE_NO_FRAGMENT},
  1628. {CURLUPART_URL, NULL, NULL, CURLUE_OK},
  1629. };
  1630. static int clear_url(void)
  1631. {
  1632. CURLU *u = curl_url();
  1633. int i, error = 0;
  1634. if(u) {
  1635. char *p = NULL;
  1636. CURLUcode rc;
  1637. for(i = 0; clear_url_list[i].in && !error; i++) {
  1638. rc = curl_url_set(u, clear_url_list[i].part, clear_url_list[i].in, 0);
  1639. if(rc != CURLUE_OK)
  1640. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1641. rc = curl_url_set(u, CURLUPART_URL, NULL, 0);
  1642. if(rc != CURLUE_OK)
  1643. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1644. rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
  1645. if(rc != clear_url_list[i].ucode || (clear_url_list[i].out &&
  1646. 0 != strcmp(p, clear_url_list[i].out))) {
  1647. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1648. error++;
  1649. }
  1650. if(rc == CURLUE_OK)
  1651. curl_free(p);
  1652. }
  1653. }
  1654. curl_url_cleanup(u);
  1655. return error;
  1656. }
  1657. static char total[128000];
  1658. static char bigpart[120000];
  1659. /*
  1660. * verify ridiculous URL part sizes
  1661. */
  1662. static int huge(void)
  1663. {
  1664. const char *smallpart = "c";
  1665. int i;
  1666. CURLU *urlp = curl_url();
  1667. CURLUcode rc;
  1668. CURLUPart part[]= {
  1669. CURLUPART_SCHEME,
  1670. CURLUPART_USER,
  1671. CURLUPART_PASSWORD,
  1672. CURLUPART_HOST,
  1673. CURLUPART_PATH,
  1674. CURLUPART_QUERY,
  1675. CURLUPART_FRAGMENT
  1676. };
  1677. int error = 0;
  1678. if(!urlp)
  1679. return 1;
  1680. bigpart[0] = '/'; /* for the path */
  1681. memset(&bigpart[1], 'a', sizeof(bigpart) - 2);
  1682. bigpart[sizeof(bigpart) - 1] = 0;
  1683. for(i = 0; i < 7; i++) {
  1684. char *partp;
  1685. msnprintf(total, sizeof(total),
  1686. "%s://%s:%s@%s/%s?%s#%s",
  1687. (i == 0) ? &bigpart[1] : smallpart,
  1688. (i == 1) ? &bigpart[1] : smallpart,
  1689. (i == 2) ? &bigpart[1] : smallpart,
  1690. (i == 3) ? &bigpart[1] : smallpart,
  1691. (i == 4) ? &bigpart[1] : smallpart,
  1692. (i == 5) ? &bigpart[1] : smallpart,
  1693. (i == 6) ? &bigpart[1] : smallpart);
  1694. rc = curl_url_set(urlp, CURLUPART_URL, total, CURLU_NON_SUPPORT_SCHEME);
  1695. if((!i && (rc != CURLUE_BAD_SCHEME)) ||
  1696. (i && rc)) {
  1697. printf("URL %u: failed to parse [%s]\n", i, total);
  1698. error++;
  1699. }
  1700. /* only extract if the parse worked */
  1701. if(!rc) {
  1702. curl_url_get(urlp, part[i], &partp, 0);
  1703. if(!partp || strcmp(partp, &bigpart[1 - (i == 4)])) {
  1704. printf("URL %u part %u: failure\n", i, part[i]);
  1705. error++;
  1706. }
  1707. curl_free(partp);
  1708. }
  1709. }
  1710. curl_url_cleanup(urlp);
  1711. return error;
  1712. }
  1713. static int urldup(void)
  1714. {
  1715. const char *url[] = {
  1716. "http://"
  1717. "user:pwd@"
  1718. "[2a04:4e42:e00::347%25eth0]"
  1719. ":80"
  1720. "/path"
  1721. "?query"
  1722. "#fraggie",
  1723. "https://example.com",
  1724. "https://user@example.com",
  1725. "https://user.pwd@example.com",
  1726. "https://user.pwd@example.com:1234",
  1727. "https://example.com:1234",
  1728. "example.com:1234",
  1729. "https://user.pwd@example.com:1234/path?query#frag",
  1730. NULL
  1731. };
  1732. CURLU *copy = NULL;
  1733. char *h_str = NULL, *copy_str = NULL;
  1734. CURLU *h = curl_url();
  1735. int i;
  1736. if(!h)
  1737. goto err;
  1738. for(i = 0; url[i]; i++) {
  1739. CURLUcode rc = curl_url_set(h, CURLUPART_URL, url[i],
  1740. CURLU_GUESS_SCHEME);
  1741. if(rc)
  1742. goto err;
  1743. copy = curl_url_dup(h);
  1744. rc = curl_url_get(h, CURLUPART_URL, &h_str, 0);
  1745. if(rc)
  1746. goto err;
  1747. rc = curl_url_get(copy, CURLUPART_URL, &copy_str, 0);
  1748. if(rc)
  1749. goto err;
  1750. if(strcmp(h_str, copy_str)) {
  1751. printf("Original: %s\nParsed: %s\nCopy: %s\n",
  1752. url[i], h_str, copy_str);
  1753. goto err;
  1754. }
  1755. curl_free(copy_str);
  1756. curl_free(h_str);
  1757. curl_url_cleanup(copy);
  1758. copy_str = NULL;
  1759. h_str = NULL;
  1760. copy = NULL;
  1761. }
  1762. curl_url_cleanup(h);
  1763. return 0;
  1764. err:
  1765. curl_free(copy_str);
  1766. curl_free(h_str);
  1767. curl_url_cleanup(copy);
  1768. curl_url_cleanup(h);
  1769. return 1;
  1770. }
  1771. CURLcode test(char *URL)
  1772. {
  1773. (void)URL; /* not used */
  1774. if(urldup())
  1775. return (CURLcode)11;
  1776. if(setget_parts())
  1777. return (CURLcode)10;
  1778. if(get_url())
  1779. return (CURLcode)3;
  1780. if(huge())
  1781. return (CURLcode)9;
  1782. if(get_nothing())
  1783. return (CURLcode)7;
  1784. if(scopeid())
  1785. return (CURLcode)6;
  1786. if(append())
  1787. return (CURLcode)5;
  1788. if(set_url())
  1789. return (CURLcode)1;
  1790. if(set_parts())
  1791. return (CURLcode)2;
  1792. if(get_parts())
  1793. return (CURLcode)4;
  1794. if(clear_url())
  1795. return (CURLcode)8;
  1796. printf("success\n");
  1797. return CURLE_OK;
  1798. }