lib1560.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907
  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. #ifndef CURL_DISABLE_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. /* normalize to lower case */
  548. {"https://[FE80:0:A:0:409B:0:0:0]:80/moo",
  549. "https://[fe80:0:a:0:409b::]:80/moo",
  550. 0, 0, CURLUE_OK},
  551. {"https://[::%25fakeit];80/moo",
  552. "",
  553. 0, 0, CURLUE_BAD_PORT_NUMBER},
  554. {"https://[fe80::20c:29ff:fe9c:409b]-80/moo",
  555. "",
  556. 0, 0, CURLUE_BAD_PORT_NUMBER},
  557. #ifdef USE_IDN
  558. {"https://räksmörgås.se/path?q#frag",
  559. "https://xn--rksmrgs-5wao1o.se/path?q#frag", 0, CURLU_PUNYCODE, CURLUE_OK},
  560. #endif
  561. /* unsupported schemes with no guessing enabled */
  562. {"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIEhUTUw+PG1ldGEgY",
  563. "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  564. {"d:anything-really", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  565. {"about:config", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  566. {"example://foo", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  567. {"mailto:infobot@example.com?body=send%20current-issue", "", 0, 0,
  568. CURLUE_UNSUPPORTED_SCHEME},
  569. {"about:80", "https://about:80/", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  570. /* percent encoded host names */
  571. {"http://example.com%40127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  572. {"http://example.com%21127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  573. {"http://example.com%3f127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  574. {"http://example.com%23127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  575. {"http://example.com%3a127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  576. {"http://example.com%09127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  577. {"http://example.com%2F127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
  578. {"https://%41", "https://A/", 0, 0, CURLUE_OK},
  579. {"https://%20", "", 0, 0, CURLUE_BAD_HOSTNAME},
  580. {"https://%41%0d", "", 0, 0, CURLUE_BAD_HOSTNAME},
  581. {"https://%25", "", 0, 0, CURLUE_BAD_HOSTNAME},
  582. {"https://_%c0_", "https://_\xC0_/", 0, 0, CURLUE_OK},
  583. {"https://_%c0_", "https://_%C0_/", 0, CURLU_URLENCODE, CURLUE_OK},
  584. /* IPv4 trickeries */
  585. {"https://16843009", "https://1.1.1.1/", 0, 0, CURLUE_OK},
  586. {"https://0177.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
  587. {"https://0111.02.0x3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
  588. {"https://0111.02.0x3.", "https://0111.02.0x3./", 0, 0, CURLUE_OK},
  589. {"https://0111.02.030", "https://73.2.0.24/", 0, 0, CURLUE_OK},
  590. {"https://0111.02.030.", "https://0111.02.030./", 0, 0, CURLUE_OK},
  591. {"https://0xff.0xff.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
  592. {"https://1.0xffffff", "https://1.255.255.255/", 0, 0, CURLUE_OK},
  593. /* IPv4 numerical overflows or syntax errors will not normalize */
  594. {"https://a127.0.0.1", "https://a127.0.0.1/", 0, 0, CURLUE_OK},
  595. {"https://\xff.127.0.0.1", "https://%FF.127.0.0.1/", 0, CURLU_URLENCODE,
  596. CURLUE_OK},
  597. {"https://127.-0.0.1", "https://127.-0.0.1/", 0, 0, CURLUE_OK},
  598. {"https://127.0. 1", "https://127.0.0.1/", 0, 0, CURLUE_MALFORMED_INPUT},
  599. {"https://1.2.3.256", "https://1.2.3.256/", 0, 0, CURLUE_OK},
  600. {"https://1.2.3.256.", "https://1.2.3.256./", 0, 0, CURLUE_OK},
  601. {"https://1.2.3.4.5", "https://1.2.3.4.5/", 0, 0, CURLUE_OK},
  602. {"https://1.2.0x100.3", "https://1.2.0x100.3/", 0, 0, CURLUE_OK},
  603. {"https://4294967296", "https://4294967296/", 0, 0, CURLUE_OK},
  604. {"https://123host", "https://123host/", 0, 0, CURLUE_OK},
  605. /* 40 bytes scheme is the max allowed */
  606. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
  607. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa://hostname/path",
  608. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  609. /* 41 bytes scheme is not allowed */
  610. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
  611. "",
  612. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_BAD_SCHEME},
  613. {"https://[fe80::20c:29ff:fe9c:409b%]:1234",
  614. "",
  615. 0, 0, CURLUE_BAD_IPV6},
  616. {"https://[fe80::20c:29ff:fe9c:409b%25]:1234",
  617. "https://[fe80::20c:29ff:fe9c:409b%2525]:1234/",
  618. 0, 0, CURLUE_OK},
  619. {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
  620. "https://[fe80::20c:29ff:fe9c:409b%25eth0]:1234/",
  621. 0, 0, CURLUE_OK},
  622. {"https://[::%25fakeit]/moo",
  623. "https://[::%25fakeit]/moo",
  624. 0, 0, CURLUE_OK},
  625. {"smtp.example.com/path/html",
  626. "smtp://smtp.example.com/path/html",
  627. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  628. {"https.example.com/path/html",
  629. "http://https.example.com/path/html",
  630. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  631. {"dict.example.com/path/html",
  632. "dict://dict.example.com/path/html",
  633. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  634. {"pop3.example.com/path/html",
  635. "pop3://pop3.example.com/path/html",
  636. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  637. {"ldap.example.com/path/html",
  638. "ldap://ldap.example.com/path/html",
  639. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  640. {"imap.example.com/path/html",
  641. "imap://imap.example.com/path/html",
  642. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  643. {"ftp.example.com/path/html",
  644. "ftp://ftp.example.com/path/html",
  645. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  646. {"example.com/path/html",
  647. "http://example.com/path/html",
  648. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  649. {"smtp.com/path/html",
  650. "smtp://smtp.com/path/html",
  651. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  652. {"dict.com/path/html",
  653. "dict://dict.com/path/html",
  654. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  655. {"pop3.com/path/html",
  656. "pop3://pop3.com/path/html",
  657. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  658. {"ldap.com/path/html",
  659. "ldap://ldap.com/path/html",
  660. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  661. {"imap.com/path/html",
  662. "imap://imap.com/path/html",
  663. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  664. {"ftp.com/path/html",
  665. "ftp://ftp.com/path/html",
  666. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  667. {"smtp/path/html",
  668. "http://smtp/path/html",
  669. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  670. {"dict/path/html",
  671. "http://dict/path/html",
  672. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  673. {"pop3/path/html",
  674. "http://pop3/path/html",
  675. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  676. {"ldap/path/html",
  677. "http://ldap/path/html",
  678. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  679. {"imap/path/html",
  680. "http://imap/path/html",
  681. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  682. {"ftp/path/html",
  683. "http://ftp/path/html",
  684. CURLU_GUESS_SCHEME, 0, CURLUE_OK},
  685. {"HTTP://test/", "http://test/", 0, 0, CURLUE_OK},
  686. {"http://HO0_-st..~./", "http://HO0_-st..~./", 0, 0, CURLUE_OK},
  687. {"http:/@example.com: 123/", "", 0, 0, CURLUE_MALFORMED_INPUT},
  688. {"http:/@example.com:123 /", "", 0, 0, CURLUE_MALFORMED_INPUT},
  689. {"http:/@example.com:123a/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
  690. {"http://host/file\r", "", 0, 0, CURLUE_MALFORMED_INPUT},
  691. {"http://host/file\n\x03", "", 0, 0, CURLUE_MALFORMED_INPUT},
  692. {"htt\x02://host/file", "",
  693. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
  694. {" http://host/file", "", 0, 0, CURLUE_MALFORMED_INPUT},
  695. /* here the password ends at the semicolon and options is 'word' */
  696. {"imap://user:pass;word@host/file",
  697. "imap://user:pass;word@host/file",
  698. 0, 0, CURLUE_OK},
  699. /* here the password has the semicolon */
  700. {"http://user:pass;word@host/file",
  701. "http://user:pass;word@host/file", 0, 0, CURLUE_OK},
  702. {"file:///file.txt#moo", "file:///file.txt#moo", 0, 0, CURLUE_OK},
  703. {"file:////file.txt", "file:////file.txt", 0, 0, CURLUE_OK},
  704. {"file:///file.txt", "file:///file.txt", 0, 0, CURLUE_OK},
  705. {"file:./", "file://", 0, 0, CURLUE_OK},
  706. {"http://example.com/hello/../here",
  707. "http://example.com/hello/../here",
  708. CURLU_PATH_AS_IS, 0, CURLUE_OK},
  709. {"http://example.com/hello/../here",
  710. "http://example.com/here",
  711. 0, 0, CURLUE_OK},
  712. {"http://example.com:80",
  713. "http://example.com/",
  714. 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
  715. {"tp://example.com/path/html",
  716. "",
  717. 0, 0, CURLUE_UNSUPPORTED_SCHEME},
  718. {"http://hello:fool@example.com",
  719. "",
  720. CURLU_DISALLOW_USER, 0, CURLUE_USER_NOT_ALLOWED},
  721. {"http:/@example.com:123",
  722. "http://@example.com:123/",
  723. 0, 0, CURLUE_OK},
  724. {"http:/:password@example.com",
  725. "http://:password@example.com/",
  726. 0, 0, CURLUE_OK},
  727. {"http://user@example.com?#",
  728. "http://user@example.com/",
  729. 0, 0, CURLUE_OK},
  730. {"http://user@example.com?",
  731. "http://user@example.com/",
  732. 0, 0, CURLUE_OK},
  733. {"http://user@example.com#anchor",
  734. "http://user@example.com/#anchor",
  735. 0, 0, CURLUE_OK},
  736. {"example.com/path/html",
  737. "https://example.com/path/html",
  738. CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
  739. {"example.com/path/html",
  740. "",
  741. 0, 0, CURLUE_BAD_SCHEME},
  742. {"http://user:password@example.com:1234/path/html?query=name#anchor",
  743. "http://user:password@example.com:1234/path/html?query=name#anchor",
  744. 0, 0, CURLUE_OK},
  745. {"http://example.com:1234/path/html?query=name#anchor",
  746. "http://example.com:1234/path/html?query=name#anchor",
  747. 0, 0, CURLUE_OK},
  748. {"http://example.com/path/html?query=name#anchor",
  749. "http://example.com/path/html?query=name#anchor",
  750. 0, 0, CURLUE_OK},
  751. {"http://example.com/path/html?query=name",
  752. "http://example.com/path/html?query=name",
  753. 0, 0, CURLUE_OK},
  754. {"http://example.com/path/html",
  755. "http://example.com/path/html",
  756. 0, 0, CURLUE_OK},
  757. {"tp://example.com/path/html",
  758. "tp://example.com/path/html",
  759. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  760. {"custom-scheme://host?expected=test-good",
  761. "custom-scheme://host/?expected=test-good",
  762. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
  763. {"custom-scheme://?expected=test-bad",
  764. "",
  765. CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_NO_HOST},
  766. {"custom-scheme://?expected=test-new-good",
  767. "custom-scheme:///?expected=test-new-good",
  768. CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
  769. {"custom-scheme://host?expected=test-still-good",
  770. "custom-scheme://host/?expected=test-still-good",
  771. CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
  772. {NULL, NULL, 0, 0, CURLUE_OK}
  773. };
  774. static int checkurl(const char *org, const char *url, const char *out)
  775. {
  776. if(strcmp(out, url)) {
  777. fprintf(stderr,
  778. "Org: %s\n"
  779. "Wanted: %s\n"
  780. "Got : %s\n",
  781. org, out, url);
  782. return 1;
  783. }
  784. return 0;
  785. }
  786. /* 1. Set the URL
  787. 2. Set components
  788. 3. Extract all components (not URL)
  789. */
  790. static const struct setgetcase setget_parts_list[] = {
  791. {"https://example.com/",
  792. "query=\"\",",
  793. "https | [11] | [12] | [13] | example.com | [15] | / | | [17]",
  794. 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
  795. {"https://example.com/",
  796. "fragment=\"\",",
  797. "https | [11] | [12] | [13] | example.com | [15] | / | [16] | ",
  798. 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
  799. {"https://example.com/",
  800. "query=\"\",",
  801. "https | [11] | [12] | [13] | example.com | [15] | / | [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=/get,",
  809. "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
  810. 0, 0, 0, CURLUE_OK},
  811. {"https://example.com",
  812. "path=g e t,",
  813. "https | [11] | [12] | [13] | example.com | [15] | /g%20e%20t | "
  814. "[16] | [17]",
  815. 0, CURLU_URLENCODE, 0, CURLUE_OK},
  816. {NULL, NULL, NULL, 0, 0, 0, CURLUE_OK}
  817. };
  818. /* !checksrc! disable SPACEBEFORECOMMA 1 */
  819. static const struct setcase set_parts_list[] = {
  820. {"https://example.com/",
  821. "host=%43url.se,",
  822. "https://%43url.se/",
  823. 0, 0, CURLUE_OK, CURLUE_OK},
  824. {"https://example.com/",
  825. "host=%25url.se,",
  826. "",
  827. 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  828. {"https://example.com/?param=value",
  829. "query=\"\",",
  830. "https://example.com/",
  831. 0, CURLU_APPENDQUERY | CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  832. {"https://example.com/",
  833. "host=\"\",",
  834. "https://example.com/",
  835. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  836. {"https://example.com/",
  837. "host=\"\",",
  838. "https://example.com/",
  839. 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  840. {"https://example.com",
  841. "path=get,",
  842. "https://example.com/get",
  843. 0, 0, CURLUE_OK, CURLUE_OK},
  844. {"https://example.com/",
  845. "scheme=ftp+-.123,",
  846. "ftp+-.123://example.com/",
  847. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  848. {"https://example.com/",
  849. "scheme=1234,",
  850. "https://example.com/",
  851. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  852. {"https://example.com/",
  853. "scheme=1http,",
  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. "scheme=.ftp,",
  866. "https://example.com/",
  867. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  868. {"https://example.com/",
  869. "host=example.com%2fmoo,",
  870. "",
  871. 0, /* get */
  872. 0, /* set */
  873. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  874. {"https://example.com/",
  875. "host=http://fake,",
  876. "",
  877. 0, /* get */
  878. 0, /* set */
  879. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  880. {"https://example.com/",
  881. "host=test%,",
  882. "",
  883. 0, /* get */
  884. 0, /* set */
  885. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  886. {"https://example.com/",
  887. "host=te st,",
  888. "",
  889. 0, /* get */
  890. 0, /* set */
  891. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  892. {"https://example.com/",
  893. "host=0xff,", /* '++' there's no automatic URL decode when setting this
  894. part */
  895. "https://0xff/",
  896. 0, /* get */
  897. 0, /* set */
  898. CURLUE_OK, CURLUE_OK},
  899. {"https://example.com/",
  900. "query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
  901. "https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2bLX8TPHs",
  902. CURLU_URLDECODE, /* decode on get */
  903. CURLU_URLENCODE, /* encode on set */
  904. CURLUE_OK, CURLUE_OK},
  905. {"https://example.com/",
  906. /* Set a bad scheme *including* :// */
  907. "scheme=https://,",
  908. "https://example.com/",
  909. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  910. {"https://example.com/",
  911. /* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
  912. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
  913. "https://example.com/",
  914. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  915. {"https://example.com/",
  916. /* set a 40 bytes scheme */
  917. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,",
  918. "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb://example.com/",
  919. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  920. {"https://[::1%25fake]:1234/",
  921. "zoneid=NULL,",
  922. "https://[::1]:1234/",
  923. 0, 0, CURLUE_OK, CURLUE_OK},
  924. {"https://host:1234/",
  925. "port=NULL,",
  926. "https://host/",
  927. 0, 0, CURLUE_OK, CURLUE_OK},
  928. {"https://host:1234/",
  929. "port=\"\",",
  930. "https://host:1234/",
  931. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  932. {"https://host:1234/",
  933. "port=56 78,",
  934. "https://host:1234/",
  935. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  936. {"https://host:1234/",
  937. "port=0,",
  938. "https://host:0/",
  939. 0, 0, CURLUE_OK, CURLUE_OK},
  940. {"https://host:1234/",
  941. "port=65535,",
  942. "https://host:65535/",
  943. 0, 0, CURLUE_OK, CURLUE_OK},
  944. {"https://host:1234/",
  945. "port=65536,",
  946. "https://host:1234/",
  947. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  948. {"https://host/",
  949. "path=%4A%4B%4C,",
  950. "https://host/%4a%4b%4c",
  951. 0, 0, CURLUE_OK, CURLUE_OK},
  952. {"https://host/mooo?q#f",
  953. "path=NULL,query=NULL,fragment=NULL,",
  954. "https://host/",
  955. 0, 0, CURLUE_OK, CURLUE_OK},
  956. {"https://user:secret@host/",
  957. "user=NULL,password=NULL,",
  958. "https://host/",
  959. 0, 0, CURLUE_OK, CURLUE_OK},
  960. {NULL,
  961. "scheme=https,user= @:,host=foobar,",
  962. "https://%20%20%20%40%3a@foobar/",
  963. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  964. /* Setting a host name with spaces is not OK: */
  965. {NULL,
  966. "scheme=https,host= ,path= ,user= ,password= ,query= ,fragment= ,",
  967. "[nothing]",
  968. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  969. {NULL,
  970. "scheme=https,host=foobar,path=/this /path /is /here,",
  971. "https://foobar/this%20/path%20/is%20/here",
  972. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  973. {NULL,
  974. "scheme=https,host=foobar,path=\xc3\xa4\xc3\xb6\xc3\xbc,",
  975. "https://foobar/%c3%a4%c3%b6%c3%bc",
  976. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  977. {"imap://user:secret;opt@host/",
  978. "options=updated,scheme=imaps,password=p4ssw0rd,",
  979. "imaps://user:p4ssw0rd;updated@host/",
  980. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  981. {"imap://user:secret;optit@host/",
  982. "scheme=https,",
  983. "https://user:secret@host/",
  984. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  985. {"file:///file#anchor",
  986. "scheme=https,host=example,",
  987. "https://example/file#anchor",
  988. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  989. {NULL, /* start fresh! */
  990. "scheme=file,host=127.0.0.1,path=/no,user=anonymous,",
  991. "file:///no",
  992. 0, 0, CURLUE_OK, CURLUE_OK},
  993. {NULL, /* start fresh! */
  994. "scheme=ftp,host=127.0.0.1,path=/no,user=anonymous,",
  995. "ftp://anonymous@127.0.0.1/no",
  996. 0, 0, CURLUE_OK, CURLUE_OK},
  997. {NULL, /* start fresh! */
  998. "scheme=https,host=example.com,",
  999. "https://example.com/",
  1000. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  1001. {"http://user:foo@example.com/path?query#frag",
  1002. "fragment=changed,",
  1003. "http://user:foo@example.com/path?query#changed",
  1004. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  1005. {"http://example.com/",
  1006. "scheme=foo,", /* not accepted */
  1007. "http://example.com/",
  1008. 0, 0, CURLUE_OK, CURLUE_UNSUPPORTED_SCHEME},
  1009. {"http://example.com/",
  1010. "scheme=https,path=/hello,fragment=snippet,",
  1011. "https://example.com/hello#snippet",
  1012. 0, 0, CURLUE_OK, CURLUE_OK},
  1013. {"http://example.com:80",
  1014. "user=foo,port=1922,",
  1015. "http://foo@example.com:1922/",
  1016. 0, 0, CURLUE_OK, CURLUE_OK},
  1017. {"http://example.com:80",
  1018. "user=foo,password=bar,",
  1019. "http://foo:bar@example.com:80/",
  1020. 0, 0, CURLUE_OK, CURLUE_OK},
  1021. {"http://example.com:80",
  1022. "user=foo,",
  1023. "http://foo@example.com:80/",
  1024. 0, 0, CURLUE_OK, CURLUE_OK},
  1025. {"http://example.com",
  1026. "host=www.example.com,",
  1027. "http://www.example.com/",
  1028. 0, 0, CURLUE_OK, CURLUE_OK},
  1029. {"http://example.com:80",
  1030. "scheme=ftp,",
  1031. "ftp://example.com:80/",
  1032. 0, 0, CURLUE_OK, CURLUE_OK},
  1033. {"custom-scheme://host",
  1034. "host=\"\",",
  1035. "custom-scheme://host/",
  1036. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK,
  1037. CURLUE_BAD_HOSTNAME},
  1038. {"custom-scheme://host",
  1039. "host=\"\",",
  1040. "custom-scheme:///",
  1041. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY,
  1042. CURLUE_OK, CURLUE_OK},
  1043. {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK}
  1044. };
  1045. static CURLUPart part2id(char *part)
  1046. {
  1047. if(!strcmp("url", part))
  1048. return CURLUPART_URL;
  1049. if(!strcmp("scheme", part))
  1050. return CURLUPART_SCHEME;
  1051. if(!strcmp("user", part))
  1052. return CURLUPART_USER;
  1053. if(!strcmp("password", part))
  1054. return CURLUPART_PASSWORD;
  1055. if(!strcmp("options", part))
  1056. return CURLUPART_OPTIONS;
  1057. if(!strcmp("host", part))
  1058. return CURLUPART_HOST;
  1059. if(!strcmp("port", part))
  1060. return CURLUPART_PORT;
  1061. if(!strcmp("path", part))
  1062. return CURLUPART_PATH;
  1063. if(!strcmp("query", part))
  1064. return CURLUPART_QUERY;
  1065. if(!strcmp("fragment", part))
  1066. return CURLUPART_FRAGMENT;
  1067. if(!strcmp("zoneid", part))
  1068. return CURLUPART_ZONEID;
  1069. return (CURLUPart)9999; /* bad input => bad output */
  1070. }
  1071. static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
  1072. {
  1073. const char *p = cmd;
  1074. CURLUcode uc;
  1075. /* make sure the last command ends with a comma too! */
  1076. while(p) {
  1077. char *e = strchr(p, ',');
  1078. if(e) {
  1079. size_t n = (size_t)(e - p);
  1080. char buf[80];
  1081. char part[80];
  1082. char value[80];
  1083. memset(part, 0, sizeof(part)); /* Avoid valgrind false positive. */
  1084. memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
  1085. memcpy(buf, p, n);
  1086. buf[n] = 0;
  1087. if(2 == sscanf(buf, "%79[^=]=%79[^,]", part, value)) {
  1088. CURLUPart what = part2id(part);
  1089. #if 0
  1090. /* for debugging this */
  1091. fprintf(stderr, "%s = \"%s\" [%d]\n", part, value, (int)what);
  1092. #endif
  1093. if(what > CURLUPART_ZONEID)
  1094. fprintf(stderr, "UNKNOWN part '%s'\n", part);
  1095. if(!strcmp("NULL", value))
  1096. uc = curl_url_set(u, what, NULL, setflags);
  1097. else if(!strcmp("\"\"", value))
  1098. uc = curl_url_set(u, what, "", setflags);
  1099. else
  1100. uc = curl_url_set(u, what, value, setflags);
  1101. if(uc)
  1102. return uc;
  1103. }
  1104. p = e + 1;
  1105. continue;
  1106. }
  1107. break;
  1108. }
  1109. return CURLUE_OK;
  1110. }
  1111. static const struct redircase set_url_list[] = {
  1112. {"http://example.org/",
  1113. "../path/././../../moo",
  1114. "http://example.org/moo",
  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/",
  1121. "///example.org/../path/../../",
  1122. "http://example.org/",
  1123. 0, 0, CURLUE_OK},
  1124. {"http://example.org/foo/bar",
  1125. ":23",
  1126. "http://example.org/foo/:23",
  1127. 0, 0, CURLUE_OK},
  1128. {"http://example.org/foo/bar",
  1129. "\\x",
  1130. "http://example.org/foo/\\x",
  1131. /* WHATWG disagrees */
  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. 0, 0, CURLUE_OK},
  1145. {"http://example.org/foo/bar",
  1146. "#",
  1147. "http://example.org/foo/bar",
  1148. /* This happens because the parser removes empty fragments */
  1149. 0, 0, CURLUE_OK},
  1150. {"http://example.org/foo/bar",
  1151. "?",
  1152. "http://example.org/foo/bar",
  1153. /* This happens because the parser removes empty queries */
  1154. 0, 0, CURLUE_OK},
  1155. {"http://example.org/foo/bar",
  1156. "?#",
  1157. "http://example.org/foo/bar",
  1158. /* This happens because the parser removes empty queries and fragments */
  1159. 0, 0, CURLUE_OK},
  1160. {"http://example.com/please/../gimme/%TESTNUMBER?foobar#hello",
  1161. "http://example.net/there/it/is/../../tes t case=/%TESTNUMBER0002? yes no",
  1162. "http://example.net/there/tes%20t%20case=/%TESTNUMBER0002?+yes+no",
  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, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
  1168. {"http://local.test?redirect=http://local.test:80?-321",
  1169. "http://local.test:80?-123",
  1170. "http://local.test:80/?-123",
  1171. 0, 0, CURLUE_OK},
  1172. {"http://example.org/static/favicon/wikipedia.ico",
  1173. "//fake.example.com/licenses/by-sa/3.0/",
  1174. "http://fake.example.com/licenses/by-sa/3.0/",
  1175. 0, 0, CURLUE_OK},
  1176. {"https://example.org/static/favicon/wikipedia.ico",
  1177. "//fake.example.com/licenses/by-sa/3.0/",
  1178. "https://fake.example.com/licenses/by-sa/3.0/",
  1179. 0, 0, CURLUE_OK},
  1180. {"file://localhost/path?query#frag",
  1181. "foo#another",
  1182. "file:///foo#another",
  1183. 0, 0, CURLUE_OK},
  1184. {"http://example.com/path?query#frag",
  1185. "https://two.example.com/bradnew",
  1186. "https://two.example.com/bradnew",
  1187. 0, 0, CURLUE_OK},
  1188. {"http://example.com/path?query#frag",
  1189. "../../newpage#foo",
  1190. "http://example.com/newpage#foo",
  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. "../newpage",
  1198. "http://user:foo@example.com/newpage",
  1199. 0, 0, CURLUE_OK},
  1200. {"http://user:foo@example.com/path?query#frag",
  1201. "http://?hi",
  1202. "http:///?hi",
  1203. 0, CURLU_NO_AUTHORITY, CURLUE_OK},
  1204. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1205. };
  1206. static int set_url(void)
  1207. {
  1208. int i;
  1209. int error = 0;
  1210. for(i = 0; set_url_list[i].in && !error; i++) {
  1211. CURLUcode rc;
  1212. CURLU *urlp = curl_url();
  1213. if(!urlp)
  1214. break;
  1215. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
  1216. set_url_list[i].urlflags);
  1217. if(!rc) {
  1218. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
  1219. set_url_list[i].setflags);
  1220. if(rc) {
  1221. fprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
  1222. __FILE__, __LINE__, set_url_list[i].set,
  1223. (int)rc, curl_url_strerror(rc));
  1224. error++;
  1225. }
  1226. else {
  1227. char *url = NULL;
  1228. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1229. if(rc) {
  1230. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1231. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1232. error++;
  1233. }
  1234. else {
  1235. if(checkurl(set_url_list[i].in, url, set_url_list[i].out)) {
  1236. error++;
  1237. }
  1238. }
  1239. curl_free(url);
  1240. }
  1241. }
  1242. else if(rc != set_url_list[i].ucode) {
  1243. fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
  1244. set_url_list[i].in, (int)rc, set_url_list[i].ucode);
  1245. error++;
  1246. }
  1247. curl_url_cleanup(urlp);
  1248. }
  1249. return error;
  1250. }
  1251. /* 1. Set a URL
  1252. 2. Set one or more parts
  1253. 3. Extract and compare all parts - not the URL
  1254. */
  1255. static int setget_parts(void)
  1256. {
  1257. int i;
  1258. int error = 0;
  1259. for(i = 0; setget_parts_list[i].set && !error; i++) {
  1260. CURLUcode rc;
  1261. CURLU *urlp = curl_url();
  1262. if(!urlp) {
  1263. error++;
  1264. break;
  1265. }
  1266. if(setget_parts_list[i].in)
  1267. rc = curl_url_set(urlp, CURLUPART_URL, setget_parts_list[i].in,
  1268. setget_parts_list[i].urlflags);
  1269. else
  1270. rc = CURLUE_OK;
  1271. if(!rc) {
  1272. char *url = NULL;
  1273. CURLUcode uc = updateurl(urlp, setget_parts_list[i].set,
  1274. setget_parts_list[i].setflags);
  1275. if(uc != setget_parts_list[i].pcode) {
  1276. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1277. setget_parts_list[i].set, (int)uc, setget_parts_list[i].pcode);
  1278. error++;
  1279. }
  1280. if(!uc) {
  1281. if(checkparts(urlp, setget_parts_list[i].set, setget_parts_list[i].out,
  1282. setget_parts_list[i].getflags))
  1283. error++; /* add */
  1284. }
  1285. curl_free(url);
  1286. }
  1287. else if(rc != CURLUE_OK) {
  1288. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1289. setget_parts_list[i].in, (int)rc, 0);
  1290. error++;
  1291. }
  1292. curl_url_cleanup(urlp);
  1293. }
  1294. return error;
  1295. }
  1296. static int set_parts(void)
  1297. {
  1298. int i;
  1299. int error = 0;
  1300. for(i = 0; set_parts_list[i].set && !error; i++) {
  1301. CURLUcode rc;
  1302. CURLU *urlp = curl_url();
  1303. if(!urlp) {
  1304. error++;
  1305. break;
  1306. }
  1307. if(set_parts_list[i].in)
  1308. rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
  1309. set_parts_list[i].urlflags);
  1310. else
  1311. rc = CURLUE_OK;
  1312. if(!rc) {
  1313. char *url = NULL;
  1314. CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
  1315. set_parts_list[i].setflags);
  1316. if(uc != set_parts_list[i].pcode) {
  1317. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1318. set_parts_list[i].set, (int)uc, set_parts_list[i].pcode);
  1319. error++;
  1320. }
  1321. if(!uc) {
  1322. /* only do this if it worked */
  1323. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1324. if(rc) {
  1325. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1326. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1327. error++;
  1328. }
  1329. else if(checkurl(set_parts_list[i].in, url, set_parts_list[i].out)) {
  1330. error++;
  1331. }
  1332. }
  1333. curl_free(url);
  1334. }
  1335. else if(rc != set_parts_list[i].ucode) {
  1336. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1337. set_parts_list[i].in, (int)rc, set_parts_list[i].ucode);
  1338. error++;
  1339. }
  1340. curl_url_cleanup(urlp);
  1341. }
  1342. return error;
  1343. }
  1344. static int get_url(void)
  1345. {
  1346. int i;
  1347. int error = 0;
  1348. for(i = 0; get_url_list[i].in && !error; i++) {
  1349. CURLUcode rc;
  1350. CURLU *urlp = curl_url();
  1351. if(!urlp) {
  1352. error++;
  1353. break;
  1354. }
  1355. rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
  1356. get_url_list[i].urlflags);
  1357. if(!rc) {
  1358. char *url = NULL;
  1359. rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
  1360. if(rc) {
  1361. fprintf(stderr, "%s:%d returned %d (%s). URL: '%s'\n",
  1362. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc),
  1363. get_url_list[i].in);
  1364. error++;
  1365. }
  1366. else {
  1367. if(checkurl(get_url_list[i].in, url, get_url_list[i].out)) {
  1368. error++;
  1369. }
  1370. }
  1371. curl_free(url);
  1372. }
  1373. if(rc != get_url_list[i].ucode) {
  1374. fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
  1375. get_url_list[i].in, (int)rc, get_url_list[i].ucode);
  1376. error++;
  1377. }
  1378. curl_url_cleanup(urlp);
  1379. }
  1380. return error;
  1381. }
  1382. static int get_parts(void)
  1383. {
  1384. int i;
  1385. int error = 0;
  1386. for(i = 0; get_parts_list[i].in && !error; i++) {
  1387. CURLUcode rc;
  1388. CURLU *urlp = curl_url();
  1389. if(!urlp) {
  1390. error++;
  1391. break;
  1392. }
  1393. rc = curl_url_set(urlp, CURLUPART_URL,
  1394. get_parts_list[i].in,
  1395. get_parts_list[i].urlflags);
  1396. if(rc != get_parts_list[i].ucode) {
  1397. fprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
  1398. get_parts_list[i].in, (int)rc, get_parts_list[i].ucode);
  1399. error++;
  1400. }
  1401. else if(get_parts_list[i].ucode) {
  1402. /* the expected error happened */
  1403. }
  1404. else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
  1405. get_parts_list[i].getflags))
  1406. error++;
  1407. curl_url_cleanup(urlp);
  1408. }
  1409. return error;
  1410. }
  1411. static const struct querycase append_list[] = {
  1412. {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02",
  1413. 0, CURLU_URLENCODE, CURLUE_OK},
  1414. {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3d#f",
  1415. 0, CURLU_URLENCODE, CURLUE_OK},
  1416. {"HTTP://test/?size=2#f", "name=joe doe",
  1417. "http://test/?size=2&name=joe+doe#f",
  1418. 0, CURLU_URLENCODE, CURLUE_OK},
  1419. {"HTTP://test/", "name=joe", "http://test/?name=joe", 0, 0, CURLUE_OK},
  1420. {"HTTP://test/?size=2", "name=joe", "http://test/?size=2&name=joe",
  1421. 0, 0, CURLUE_OK},
  1422. {"HTTP://test/?size=2&", "name=joe", "http://test/?size=2&name=joe",
  1423. 0, 0, CURLUE_OK},
  1424. {"HTTP://test/?size=2#f", "name=joe", "http://test/?size=2&name=joe#f",
  1425. 0, 0, CURLUE_OK},
  1426. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1427. };
  1428. static int append(void)
  1429. {
  1430. int i;
  1431. int error = 0;
  1432. for(i = 0; append_list[i].in && !error; i++) {
  1433. CURLUcode rc;
  1434. CURLU *urlp = curl_url();
  1435. if(!urlp) {
  1436. error++;
  1437. break;
  1438. }
  1439. rc = curl_url_set(urlp, CURLUPART_URL,
  1440. append_list[i].in,
  1441. append_list[i].urlflags);
  1442. if(rc)
  1443. error++;
  1444. else
  1445. rc = curl_url_set(urlp, CURLUPART_QUERY,
  1446. append_list[i].q,
  1447. append_list[i].qflags | CURLU_APPENDQUERY);
  1448. if(error)
  1449. ;
  1450. else if(rc != append_list[i].ucode) {
  1451. fprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
  1452. append_list[i].in, (int)rc, append_list[i].ucode);
  1453. error++;
  1454. }
  1455. else if(append_list[i].ucode) {
  1456. /* the expected error happened */
  1457. }
  1458. else {
  1459. char *url;
  1460. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1461. if(rc) {
  1462. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1463. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1464. error++;
  1465. }
  1466. else {
  1467. if(checkurl(append_list[i].in, url, append_list[i].out)) {
  1468. error++;
  1469. }
  1470. curl_free(url);
  1471. }
  1472. }
  1473. curl_url_cleanup(urlp);
  1474. }
  1475. return error;
  1476. }
  1477. static int scopeid(void)
  1478. {
  1479. CURLU *u = curl_url();
  1480. int error = 0;
  1481. CURLUcode rc;
  1482. char *url;
  1483. rc = curl_url_set(u, CURLUPART_URL,
  1484. "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
  1485. if(rc != CURLUE_OK) {
  1486. fprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
  1487. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1488. error++;
  1489. }
  1490. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1491. if(rc != CURLUE_OK) {
  1492. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1493. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1494. error++;
  1495. }
  1496. else {
  1497. curl_free(url);
  1498. }
  1499. rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
  1500. if(rc != CURLUE_OK) {
  1501. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1502. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1503. error++;
  1504. }
  1505. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1506. if(rc != CURLUE_OK) {
  1507. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1508. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1509. error++;
  1510. }
  1511. else {
  1512. curl_free(url);
  1513. }
  1514. rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
  1515. if(rc != CURLUE_OK) {
  1516. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1517. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1518. error++;
  1519. }
  1520. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1521. if(rc != CURLUE_OK) {
  1522. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1523. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1524. error++;
  1525. }
  1526. else {
  1527. curl_free(url);
  1528. }
  1529. rc = curl_url_set(u, CURLUPART_HOST,
  1530. "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
  1531. if(rc != CURLUE_OK) {
  1532. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1533. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1534. error++;
  1535. }
  1536. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1537. if(rc != CURLUE_OK) {
  1538. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1539. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1540. error++;
  1541. }
  1542. else {
  1543. curl_free(url);
  1544. }
  1545. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1546. if(rc != CURLUE_OK) {
  1547. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1548. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1549. error++;
  1550. }
  1551. else {
  1552. curl_free(url);
  1553. }
  1554. rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
  1555. if(rc != CURLUE_OK) {
  1556. fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
  1557. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1558. error++;
  1559. }
  1560. else {
  1561. curl_free(url);
  1562. }
  1563. rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
  1564. if(rc != CURLUE_OK) {
  1565. fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
  1566. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1567. error++;
  1568. }
  1569. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1570. if(rc != CURLUE_OK) {
  1571. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1572. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1573. error++;
  1574. }
  1575. else {
  1576. curl_free(url);
  1577. }
  1578. curl_url_cleanup(u);
  1579. return error;
  1580. }
  1581. static int get_nothing(void)
  1582. {
  1583. CURLU *u = curl_url();
  1584. if(u) {
  1585. char *p;
  1586. CURLUcode rc;
  1587. rc = curl_url_get(u, CURLUPART_SCHEME, &p, 0);
  1588. if(rc != CURLUE_NO_SCHEME)
  1589. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1590. rc = curl_url_get(u, CURLUPART_HOST, &p, 0);
  1591. if(rc != CURLUE_NO_HOST)
  1592. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1593. rc = curl_url_get(u, CURLUPART_USER, &p, 0);
  1594. if(rc != CURLUE_NO_USER)
  1595. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1596. rc = curl_url_get(u, CURLUPART_PASSWORD, &p, 0);
  1597. if(rc != CURLUE_NO_PASSWORD)
  1598. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1599. rc = curl_url_get(u, CURLUPART_OPTIONS, &p, 0);
  1600. if(rc != CURLUE_NO_OPTIONS)
  1601. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1602. rc = curl_url_get(u, CURLUPART_PATH, &p, 0);
  1603. if(rc != CURLUE_OK)
  1604. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1605. else
  1606. curl_free(p);
  1607. rc = curl_url_get(u, CURLUPART_QUERY, &p, 0);
  1608. if(rc != CURLUE_NO_QUERY)
  1609. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1610. rc = curl_url_get(u, CURLUPART_FRAGMENT, &p, 0);
  1611. if(rc != CURLUE_NO_FRAGMENT)
  1612. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1613. rc = curl_url_get(u, CURLUPART_ZONEID, &p, 0);
  1614. if(rc != CURLUE_NO_ZONEID)
  1615. fprintf(stderr, "unexpected return code %u on line %u\n", (int)rc,
  1616. __LINE__);
  1617. curl_url_cleanup(u);
  1618. }
  1619. return 0;
  1620. }
  1621. static const struct clearurlcase clear_url_list[] ={
  1622. {CURLUPART_SCHEME, "http", NULL, CURLUE_NO_SCHEME},
  1623. {CURLUPART_USER, "user", NULL, CURLUE_NO_USER},
  1624. {CURLUPART_PASSWORD, "password", NULL, CURLUE_NO_PASSWORD},
  1625. {CURLUPART_OPTIONS, "options", NULL, CURLUE_NO_OPTIONS},
  1626. {CURLUPART_HOST, "host", NULL, CURLUE_NO_HOST},
  1627. {CURLUPART_ZONEID, "eth0", NULL, CURLUE_NO_ZONEID},
  1628. {CURLUPART_PORT, "1234", NULL, CURLUE_NO_PORT},
  1629. {CURLUPART_PATH, "/hello", "/", CURLUE_OK},
  1630. {CURLUPART_QUERY, "a=b", NULL, CURLUE_NO_QUERY},
  1631. {CURLUPART_FRAGMENT, "anchor", NULL, CURLUE_NO_FRAGMENT},
  1632. {CURLUPART_URL, NULL, NULL, CURLUE_OK},
  1633. };
  1634. static int clear_url(void)
  1635. {
  1636. CURLU *u = curl_url();
  1637. int i, error = 0;
  1638. if(u) {
  1639. char *p = NULL;
  1640. CURLUcode rc;
  1641. for(i = 0; clear_url_list[i].in && !error; i++) {
  1642. rc = curl_url_set(u, clear_url_list[i].part, clear_url_list[i].in, 0);
  1643. if(rc != CURLUE_OK)
  1644. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1645. rc = curl_url_set(u, CURLUPART_URL, NULL, 0);
  1646. if(rc != CURLUE_OK)
  1647. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1648. rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
  1649. if(rc != clear_url_list[i].ucode || (clear_url_list[i].out &&
  1650. 0 != strcmp(p, clear_url_list[i].out))) {
  1651. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1652. error++;
  1653. }
  1654. if(rc == CURLUE_OK)
  1655. curl_free(p);
  1656. }
  1657. }
  1658. curl_url_cleanup(u);
  1659. return error;
  1660. }
  1661. static char total[128000];
  1662. static char bigpart[120000];
  1663. /*
  1664. * verify ridiculous URL part sizes
  1665. */
  1666. static int huge(void)
  1667. {
  1668. const char *smallpart = "c";
  1669. int i;
  1670. CURLU *urlp = curl_url();
  1671. CURLUcode rc;
  1672. CURLUPart part[]= {
  1673. CURLUPART_SCHEME,
  1674. CURLUPART_USER,
  1675. CURLUPART_PASSWORD,
  1676. CURLUPART_HOST,
  1677. CURLUPART_PATH,
  1678. CURLUPART_QUERY,
  1679. CURLUPART_FRAGMENT
  1680. };
  1681. int error = 0;
  1682. if(!urlp)
  1683. return 1;
  1684. bigpart[0] = '/'; /* for the path */
  1685. memset(&bigpart[1], 'a', sizeof(bigpart) - 2);
  1686. bigpart[sizeof(bigpart) - 1] = 0;
  1687. for(i = 0; i < 7; i++) {
  1688. char *partp;
  1689. msnprintf(total, sizeof(total),
  1690. "%s://%s:%s@%s/%s?%s#%s",
  1691. (i == 0) ? &bigpart[1] : smallpart,
  1692. (i == 1) ? &bigpart[1] : smallpart,
  1693. (i == 2) ? &bigpart[1] : smallpart,
  1694. (i == 3) ? &bigpart[1] : smallpart,
  1695. (i == 4) ? &bigpart[1] : smallpart,
  1696. (i == 5) ? &bigpart[1] : smallpart,
  1697. (i == 6) ? &bigpart[1] : smallpart);
  1698. rc = curl_url_set(urlp, CURLUPART_URL, total, CURLU_NON_SUPPORT_SCHEME);
  1699. if((!i && (rc != CURLUE_BAD_SCHEME)) ||
  1700. (i && rc)) {
  1701. printf("URL %u: failed to parse [%s]\n", i, total);
  1702. error++;
  1703. }
  1704. /* only extract if the parse worked */
  1705. if(!rc) {
  1706. curl_url_get(urlp, part[i], &partp, 0);
  1707. if(!partp || strcmp(partp, &bigpart[1 - (i == 4)])) {
  1708. printf("URL %u part %u: failure\n", i, part[i]);
  1709. error++;
  1710. }
  1711. curl_free(partp);
  1712. }
  1713. }
  1714. curl_url_cleanup(urlp);
  1715. return error;
  1716. }
  1717. static int urldup(void)
  1718. {
  1719. const char *url[] = {
  1720. "http://"
  1721. "user:pwd@"
  1722. "[2a04:4e42:e00::347%25eth0]"
  1723. ":80"
  1724. "/path"
  1725. "?query"
  1726. "#fraggie",
  1727. "https://example.com",
  1728. "https://user@example.com",
  1729. "https://user.pwd@example.com",
  1730. "https://user.pwd@example.com:1234",
  1731. "https://example.com:1234",
  1732. "example.com:1234",
  1733. "https://user.pwd@example.com:1234/path?query#frag",
  1734. NULL
  1735. };
  1736. CURLU *copy = NULL;
  1737. char *h_str = NULL, *copy_str = NULL;
  1738. CURLU *h = curl_url();
  1739. int i;
  1740. if(!h)
  1741. goto err;
  1742. for(i = 0; url[i]; i++) {
  1743. CURLUcode rc = curl_url_set(h, CURLUPART_URL, url[i],
  1744. CURLU_GUESS_SCHEME);
  1745. if(rc)
  1746. goto err;
  1747. copy = curl_url_dup(h);
  1748. rc = curl_url_get(h, CURLUPART_URL, &h_str, 0);
  1749. if(rc)
  1750. goto err;
  1751. rc = curl_url_get(copy, CURLUPART_URL, &copy_str, 0);
  1752. if(rc)
  1753. goto err;
  1754. if(strcmp(h_str, copy_str)) {
  1755. printf("Original: %s\nParsed: %s\nCopy: %s\n",
  1756. url[i], h_str, copy_str);
  1757. goto err;
  1758. }
  1759. curl_free(copy_str);
  1760. curl_free(h_str);
  1761. curl_url_cleanup(copy);
  1762. copy_str = NULL;
  1763. h_str = NULL;
  1764. copy = NULL;
  1765. }
  1766. curl_url_cleanup(h);
  1767. return 0;
  1768. err:
  1769. curl_free(copy_str);
  1770. curl_free(h_str);
  1771. curl_url_cleanup(copy);
  1772. curl_url_cleanup(h);
  1773. return 1;
  1774. }
  1775. CURLcode test(char *URL)
  1776. {
  1777. (void)URL; /* not used */
  1778. if(urldup())
  1779. return (CURLcode)11;
  1780. if(setget_parts())
  1781. return (CURLcode)10;
  1782. if(get_url())
  1783. return (CURLcode)3;
  1784. if(huge())
  1785. return (CURLcode)9;
  1786. if(get_nothing())
  1787. return (CURLcode)7;
  1788. if(scopeid())
  1789. return (CURLcode)6;
  1790. if(append())
  1791. return (CURLcode)5;
  1792. if(set_url())
  1793. return (CURLcode)1;
  1794. if(set_parts())
  1795. return (CURLcode)2;
  1796. if(get_parts())
  1797. return (CURLcode)4;
  1798. if(clear_url())
  1799. return (CURLcode)8;
  1800. printf("success\n");
  1801. return CURLE_OK;
  1802. }