2
0

lib1560.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  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/?param=value",
  817. "query=\"\",",
  818. "https://example.com/",
  819. 0, CURLU_APPENDQUERY | CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  820. {"https://example.com/",
  821. "host=\"\",",
  822. "https://example.com/",
  823. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  824. {"https://example.com/",
  825. "host=\"\",",
  826. "https://example.com/",
  827. 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  828. {"https://example.com",
  829. "path=get,",
  830. "https://example.com/get",
  831. 0, 0, CURLUE_OK, CURLUE_OK},
  832. {"https://example.com/",
  833. "scheme=ftp+-.123,",
  834. "ftp+-.123://example.com/",
  835. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  836. {"https://example.com/",
  837. "scheme=1234,",
  838. "https://example.com/",
  839. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  840. {"https://example.com/",
  841. "scheme=1http,",
  842. "https://example.com/",
  843. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  844. {"https://example.com/",
  845. "scheme=-ftp,",
  846. "https://example.com/",
  847. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  848. {"https://example.com/",
  849. "scheme=+ftp,",
  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. "host=example.com%2fmoo,",
  858. "",
  859. 0, /* get */
  860. 0, /* set */
  861. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  862. {"https://example.com/",
  863. "host=http://fake,",
  864. "",
  865. 0, /* get */
  866. 0, /* set */
  867. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  868. {"https://example.com/",
  869. "host=test%,",
  870. "",
  871. 0, /* get */
  872. 0, /* set */
  873. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  874. {"https://example.com/",
  875. "host=te st,",
  876. "",
  877. 0, /* get */
  878. 0, /* set */
  879. CURLUE_OK, CURLUE_BAD_HOSTNAME},
  880. {"https://example.com/",
  881. "host=0xff,", /* '++' there's no automatic URL decode when setting this
  882. part */
  883. "https://0xff/",
  884. 0, /* get */
  885. 0, /* set */
  886. CURLUE_OK, CURLUE_OK},
  887. {"https://example.com/",
  888. "query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
  889. "https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2bLX8TPHs",
  890. CURLU_URLDECODE, /* decode on get */
  891. CURLU_URLENCODE, /* encode on set */
  892. CURLUE_OK, CURLUE_OK},
  893. {"https://example.com/",
  894. /* Set a bad scheme *including* :// */
  895. "scheme=https://,",
  896. "https://example.com/",
  897. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  898. {"https://example.com/",
  899. /* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
  900. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
  901. "https://example.com/",
  902. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
  903. {"https://example.com/",
  904. /* set a 40 bytes scheme */
  905. "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,",
  906. "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb://example.com/",
  907. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  908. {"https://[::1%25fake]:1234/",
  909. "zoneid=NULL,",
  910. "https://[::1]:1234/",
  911. 0, 0, CURLUE_OK, CURLUE_OK},
  912. {"https://host:1234/",
  913. "port=NULL,",
  914. "https://host/",
  915. 0, 0, CURLUE_OK, CURLUE_OK},
  916. {"https://host:1234/",
  917. "port=\"\",",
  918. "https://host:1234/",
  919. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  920. {"https://host:1234/",
  921. "port=56 78,",
  922. "https://host:1234/",
  923. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  924. {"https://host:1234/",
  925. "port=0,",
  926. "https://host:0/",
  927. 0, 0, CURLUE_OK, CURLUE_OK},
  928. {"https://host:1234/",
  929. "port=65535,",
  930. "https://host:65535/",
  931. 0, 0, CURLUE_OK, CURLUE_OK},
  932. {"https://host:1234/",
  933. "port=65536,",
  934. "https://host:1234/",
  935. 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
  936. {"https://host/",
  937. "path=%4A%4B%4C,",
  938. "https://host/%4a%4b%4c",
  939. 0, 0, CURLUE_OK, CURLUE_OK},
  940. {"https://host/mooo?q#f",
  941. "path=NULL,query=NULL,fragment=NULL,",
  942. "https://host/",
  943. 0, 0, CURLUE_OK, CURLUE_OK},
  944. {"https://user:secret@host/",
  945. "user=NULL,password=NULL,",
  946. "https://host/",
  947. 0, 0, CURLUE_OK, CURLUE_OK},
  948. {NULL,
  949. "scheme=https,user= @:,host=foobar,",
  950. "https://%20%20%20%40%3a@foobar/",
  951. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  952. /* Setting a host name with spaces is not OK: */
  953. {NULL,
  954. "scheme=https,host= ,path= ,user= ,password= ,query= ,fragment= ,",
  955. "[nothing]",
  956. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
  957. {NULL,
  958. "scheme=https,host=foobar,path=/this /path /is /here,",
  959. "https://foobar/this%20/path%20/is%20/here",
  960. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  961. {NULL,
  962. "scheme=https,host=foobar,path=\xc3\xa4\xc3\xb6\xc3\xbc,",
  963. "https://foobar/%c3%a4%c3%b6%c3%bc",
  964. 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
  965. {"imap://user:secret;opt@host/",
  966. "options=updated,scheme=imaps,password=p4ssw0rd,",
  967. "imaps://user:p4ssw0rd;updated@host/",
  968. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  969. {"imap://user:secret;optit@host/",
  970. "scheme=https,",
  971. "https://user:secret@host/",
  972. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  973. {"file:///file#anchor",
  974. "scheme=https,host=example,",
  975. "https://example/file#anchor",
  976. 0, 0, CURLUE_NO_HOST, CURLUE_OK},
  977. {NULL, /* start fresh! */
  978. "scheme=file,host=127.0.0.1,path=/no,user=anonymous,",
  979. "file:///no",
  980. 0, 0, CURLUE_OK, CURLUE_OK},
  981. {NULL, /* start fresh! */
  982. "scheme=ftp,host=127.0.0.1,path=/no,user=anonymous,",
  983. "ftp://anonymous@127.0.0.1/no",
  984. 0, 0, CURLUE_OK, CURLUE_OK},
  985. {NULL, /* start fresh! */
  986. "scheme=https,host=example.com,",
  987. "https://example.com/",
  988. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  989. {"http://user:foo@example.com/path?query#frag",
  990. "fragment=changed,",
  991. "http://user:foo@example.com/path?query#changed",
  992. 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
  993. {"http://example.com/",
  994. "scheme=foo,", /* not accepted */
  995. "http://example.com/",
  996. 0, 0, CURLUE_OK, CURLUE_UNSUPPORTED_SCHEME},
  997. {"http://example.com/",
  998. "scheme=https,path=/hello,fragment=snippet,",
  999. "https://example.com/hello#snippet",
  1000. 0, 0, CURLUE_OK, CURLUE_OK},
  1001. {"http://example.com:80",
  1002. "user=foo,port=1922,",
  1003. "http://foo@example.com:1922/",
  1004. 0, 0, CURLUE_OK, CURLUE_OK},
  1005. {"http://example.com:80",
  1006. "user=foo,password=bar,",
  1007. "http://foo:bar@example.com:80/",
  1008. 0, 0, CURLUE_OK, CURLUE_OK},
  1009. {"http://example.com:80",
  1010. "user=foo,",
  1011. "http://foo@example.com:80/",
  1012. 0, 0, CURLUE_OK, CURLUE_OK},
  1013. {"http://example.com",
  1014. "host=www.example.com,",
  1015. "http://www.example.com/",
  1016. 0, 0, CURLUE_OK, CURLUE_OK},
  1017. {"http://example.com:80",
  1018. "scheme=ftp,",
  1019. "ftp://example.com:80/",
  1020. 0, 0, CURLUE_OK, CURLUE_OK},
  1021. {"custom-scheme://host",
  1022. "host=\"\",",
  1023. "custom-scheme://host/",
  1024. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK,
  1025. CURLUE_BAD_HOSTNAME},
  1026. {"custom-scheme://host",
  1027. "host=\"\",",
  1028. "custom-scheme:///",
  1029. CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY,
  1030. CURLUE_OK, CURLUE_OK},
  1031. {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK}
  1032. };
  1033. static CURLUPart part2id(char *part)
  1034. {
  1035. if(!strcmp("url", part))
  1036. return CURLUPART_URL;
  1037. if(!strcmp("scheme", part))
  1038. return CURLUPART_SCHEME;
  1039. if(!strcmp("user", part))
  1040. return CURLUPART_USER;
  1041. if(!strcmp("password", part))
  1042. return CURLUPART_PASSWORD;
  1043. if(!strcmp("options", part))
  1044. return CURLUPART_OPTIONS;
  1045. if(!strcmp("host", part))
  1046. return CURLUPART_HOST;
  1047. if(!strcmp("port", part))
  1048. return CURLUPART_PORT;
  1049. if(!strcmp("path", part))
  1050. return CURLUPART_PATH;
  1051. if(!strcmp("query", part))
  1052. return CURLUPART_QUERY;
  1053. if(!strcmp("fragment", part))
  1054. return CURLUPART_FRAGMENT;
  1055. if(!strcmp("zoneid", part))
  1056. return CURLUPART_ZONEID;
  1057. return (CURLUPart)9999; /* bad input => bad output */
  1058. }
  1059. static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
  1060. {
  1061. const char *p = cmd;
  1062. CURLUcode uc;
  1063. /* make sure the last command ends with a comma too! */
  1064. while(p) {
  1065. char *e = strchr(p, ',');
  1066. if(e) {
  1067. size_t n = (size_t)(e - p);
  1068. char buf[80];
  1069. char part[80];
  1070. char value[80];
  1071. memset(part, 0, sizeof(part)); /* Avoid valgrind false positive. */
  1072. memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
  1073. memcpy(buf, p, n);
  1074. buf[n] = 0;
  1075. if(2 == sscanf(buf, "%79[^=]=%79[^,]", part, value)) {
  1076. CURLUPart what = part2id(part);
  1077. #if 0
  1078. /* for debugging this */
  1079. fprintf(stderr, "%s = \"%s\" [%d]\n", part, value, (int)what);
  1080. #endif
  1081. if(what > CURLUPART_ZONEID)
  1082. fprintf(stderr, "UNKNOWN part '%s'\n", part);
  1083. if(!strcmp("NULL", value))
  1084. uc = curl_url_set(u, what, NULL, setflags);
  1085. else if(!strcmp("\"\"", value))
  1086. uc = curl_url_set(u, what, "", setflags);
  1087. else
  1088. uc = curl_url_set(u, what, value, setflags);
  1089. if(uc)
  1090. return uc;
  1091. }
  1092. p = e + 1;
  1093. continue;
  1094. }
  1095. break;
  1096. }
  1097. return CURLUE_OK;
  1098. }
  1099. static const struct redircase set_url_list[] = {
  1100. {"http://example.org/",
  1101. "../path/././../../moo",
  1102. "http://example.org/moo",
  1103. 0, 0, CURLUE_OK},
  1104. {"http://example.org/",
  1105. "//example.org/../path/../../",
  1106. "http://example.org/",
  1107. 0, 0, CURLUE_OK},
  1108. {"http://example.org/",
  1109. "///example.org/../path/../../",
  1110. "http://example.org/",
  1111. 0, 0, CURLUE_OK},
  1112. {"http://example.org/foo/bar",
  1113. ":23",
  1114. "http://example.org/foo/:23",
  1115. 0, 0, CURLUE_OK},
  1116. {"http://example.org/foo/bar",
  1117. "\\x",
  1118. "http://example.org/foo/\\x",
  1119. /* WHATWG disagrees */
  1120. 0, 0, CURLUE_OK},
  1121. {"http://example.org/foo/bar",
  1122. "#/",
  1123. "http://example.org/foo/bar#/",
  1124. 0, 0, CURLUE_OK},
  1125. {"http://example.org/foo/bar",
  1126. "?/",
  1127. "http://example.org/foo/bar?/",
  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. /* This happens because the parser removes empty fragments */
  1137. 0, 0, CURLUE_OK},
  1138. {"http://example.org/foo/bar",
  1139. "?",
  1140. "http://example.org/foo/bar",
  1141. /* This happens because the parser removes empty queries */
  1142. 0, 0, CURLUE_OK},
  1143. {"http://example.org/foo/bar",
  1144. "?#",
  1145. "http://example.org/foo/bar",
  1146. /* This happens because the parser removes empty queries and fragments */
  1147. 0, 0, CURLUE_OK},
  1148. {"http://example.com/please/../gimme/%TESTNUMBER?foobar#hello",
  1149. "http://example.net/there/it/is/../../tes t case=/%TESTNUMBER0002? yes no",
  1150. "http://example.net/there/tes%20t%20case=/%TESTNUMBER0002?+yes+no",
  1151. 0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
  1152. {"http://local.test?redirect=http://local.test:80?-321",
  1153. "http://local.test:80?-123",
  1154. "http://local.test:80/?-123",
  1155. 0, CURLU_URLENCODE|CURLU_ALLOW_SPACE, CURLUE_OK},
  1156. {"http://local.test?redirect=http://local.test:80?-321",
  1157. "http://local.test:80?-123",
  1158. "http://local.test:80/?-123",
  1159. 0, 0, CURLUE_OK},
  1160. {"http://example.org/static/favicon/wikipedia.ico",
  1161. "//fake.example.com/licenses/by-sa/3.0/",
  1162. "http://fake.example.com/licenses/by-sa/3.0/",
  1163. 0, 0, CURLUE_OK},
  1164. {"https://example.org/static/favicon/wikipedia.ico",
  1165. "//fake.example.com/licenses/by-sa/3.0/",
  1166. "https://fake.example.com/licenses/by-sa/3.0/",
  1167. 0, 0, CURLUE_OK},
  1168. {"file://localhost/path?query#frag",
  1169. "foo#another",
  1170. "file:///foo#another",
  1171. 0, 0, CURLUE_OK},
  1172. {"http://example.com/path?query#frag",
  1173. "https://two.example.com/bradnew",
  1174. "https://two.example.com/bradnew",
  1175. 0, 0, CURLUE_OK},
  1176. {"http://example.com/path?query#frag",
  1177. "../../newpage#foo",
  1178. "http://example.com/newpage#foo",
  1179. 0, 0, CURLUE_OK},
  1180. {"http://user:foo@example.com/path?query#frag",
  1181. "../../newpage",
  1182. "http://user:foo@example.com/newpage",
  1183. 0, 0, CURLUE_OK},
  1184. {"http://user:foo@example.com/path?query#frag",
  1185. "../newpage",
  1186. "http://user:foo@example.com/newpage",
  1187. 0, 0, CURLUE_OK},
  1188. {"http://user:foo@example.com/path?query#frag",
  1189. "http://?hi",
  1190. "http:///?hi",
  1191. 0, CURLU_NO_AUTHORITY, CURLUE_OK},
  1192. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1193. };
  1194. static int set_url(void)
  1195. {
  1196. int i;
  1197. int error = 0;
  1198. for(i = 0; set_url_list[i].in && !error; i++) {
  1199. CURLUcode rc;
  1200. CURLU *urlp = curl_url();
  1201. if(!urlp)
  1202. break;
  1203. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
  1204. set_url_list[i].urlflags);
  1205. if(!rc) {
  1206. rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
  1207. set_url_list[i].setflags);
  1208. if(rc) {
  1209. fprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
  1210. __FILE__, __LINE__, set_url_list[i].set,
  1211. (int)rc, curl_url_strerror(rc));
  1212. error++;
  1213. }
  1214. else {
  1215. char *url = NULL;
  1216. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1217. if(rc) {
  1218. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1219. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1220. error++;
  1221. }
  1222. else {
  1223. if(checkurl(set_url_list[i].in, url, set_url_list[i].out)) {
  1224. error++;
  1225. }
  1226. }
  1227. curl_free(url);
  1228. }
  1229. }
  1230. else if(rc != set_url_list[i].ucode) {
  1231. fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
  1232. set_url_list[i].in, (int)rc, set_url_list[i].ucode);
  1233. error++;
  1234. }
  1235. curl_url_cleanup(urlp);
  1236. }
  1237. return error;
  1238. }
  1239. /* 1. Set a URL
  1240. 2. Set one or more parts
  1241. 3. Extract and compare all parts - not the URL
  1242. */
  1243. static int setget_parts(void)
  1244. {
  1245. int i;
  1246. int error = 0;
  1247. for(i = 0; setget_parts_list[i].set && !error; i++) {
  1248. CURLUcode rc;
  1249. CURLU *urlp = curl_url();
  1250. if(!urlp) {
  1251. error++;
  1252. break;
  1253. }
  1254. if(setget_parts_list[i].in)
  1255. rc = curl_url_set(urlp, CURLUPART_URL, setget_parts_list[i].in,
  1256. setget_parts_list[i].urlflags);
  1257. else
  1258. rc = CURLUE_OK;
  1259. if(!rc) {
  1260. char *url = NULL;
  1261. CURLUcode uc = updateurl(urlp, setget_parts_list[i].set,
  1262. setget_parts_list[i].setflags);
  1263. if(uc != setget_parts_list[i].pcode) {
  1264. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1265. setget_parts_list[i].set, (int)uc, setget_parts_list[i].pcode);
  1266. error++;
  1267. }
  1268. if(!uc) {
  1269. if(checkparts(urlp, setget_parts_list[i].set, setget_parts_list[i].out,
  1270. setget_parts_list[i].getflags))
  1271. error++; /* add */
  1272. }
  1273. curl_free(url);
  1274. }
  1275. else if(rc != CURLUE_OK) {
  1276. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1277. setget_parts_list[i].in, (int)rc, 0);
  1278. error++;
  1279. }
  1280. curl_url_cleanup(urlp);
  1281. }
  1282. return error;
  1283. }
  1284. static int set_parts(void)
  1285. {
  1286. int i;
  1287. int error = 0;
  1288. for(i = 0; set_parts_list[i].set && !error; i++) {
  1289. CURLUcode rc;
  1290. CURLU *urlp = curl_url();
  1291. if(!urlp) {
  1292. error++;
  1293. break;
  1294. }
  1295. if(set_parts_list[i].in)
  1296. rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
  1297. set_parts_list[i].urlflags);
  1298. else
  1299. rc = CURLUE_OK;
  1300. if(!rc) {
  1301. char *url = NULL;
  1302. CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
  1303. set_parts_list[i].setflags);
  1304. if(uc != set_parts_list[i].pcode) {
  1305. fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
  1306. set_parts_list[i].set, (int)uc, set_parts_list[i].pcode);
  1307. error++;
  1308. }
  1309. if(!uc) {
  1310. /* only do this if it worked */
  1311. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1312. if(rc) {
  1313. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1314. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1315. error++;
  1316. }
  1317. else if(checkurl(set_parts_list[i].in, url, set_parts_list[i].out)) {
  1318. error++;
  1319. }
  1320. }
  1321. curl_free(url);
  1322. }
  1323. else if(rc != set_parts_list[i].ucode) {
  1324. fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
  1325. set_parts_list[i].in, (int)rc, set_parts_list[i].ucode);
  1326. error++;
  1327. }
  1328. curl_url_cleanup(urlp);
  1329. }
  1330. return error;
  1331. }
  1332. static int get_url(void)
  1333. {
  1334. int i;
  1335. int error = 0;
  1336. for(i = 0; get_url_list[i].in && !error; i++) {
  1337. CURLUcode rc;
  1338. CURLU *urlp = curl_url();
  1339. if(!urlp) {
  1340. error++;
  1341. break;
  1342. }
  1343. rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
  1344. get_url_list[i].urlflags);
  1345. if(!rc) {
  1346. char *url = NULL;
  1347. rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
  1348. if(rc) {
  1349. fprintf(stderr, "%s:%d returned %d (%s). URL: '%s'\n",
  1350. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc),
  1351. get_url_list[i].in);
  1352. error++;
  1353. }
  1354. else {
  1355. if(checkurl(get_url_list[i].in, url, get_url_list[i].out)) {
  1356. error++;
  1357. }
  1358. }
  1359. curl_free(url);
  1360. }
  1361. if(rc != get_url_list[i].ucode) {
  1362. fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
  1363. get_url_list[i].in, (int)rc, get_url_list[i].ucode);
  1364. error++;
  1365. }
  1366. curl_url_cleanup(urlp);
  1367. }
  1368. return error;
  1369. }
  1370. static int get_parts(void)
  1371. {
  1372. int i;
  1373. int error = 0;
  1374. for(i = 0; get_parts_list[i].in && !error; i++) {
  1375. CURLUcode rc;
  1376. CURLU *urlp = curl_url();
  1377. if(!urlp) {
  1378. error++;
  1379. break;
  1380. }
  1381. rc = curl_url_set(urlp, CURLUPART_URL,
  1382. get_parts_list[i].in,
  1383. get_parts_list[i].urlflags);
  1384. if(rc != get_parts_list[i].ucode) {
  1385. fprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
  1386. get_parts_list[i].in, (int)rc, get_parts_list[i].ucode);
  1387. error++;
  1388. }
  1389. else if(get_parts_list[i].ucode) {
  1390. /* the expected error happened */
  1391. }
  1392. else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
  1393. get_parts_list[i].getflags))
  1394. error++;
  1395. curl_url_cleanup(urlp);
  1396. }
  1397. return error;
  1398. }
  1399. static const struct querycase append_list[] = {
  1400. {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02",
  1401. 0, CURLU_URLENCODE, CURLUE_OK},
  1402. {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3d#f",
  1403. 0, CURLU_URLENCODE, CURLUE_OK},
  1404. {"HTTP://test/?size=2#f", "name=joe doe",
  1405. "http://test/?size=2&name=joe+doe#f",
  1406. 0, CURLU_URLENCODE, CURLUE_OK},
  1407. {"HTTP://test/", "name=joe", "http://test/?name=joe", 0, 0, CURLUE_OK},
  1408. {"HTTP://test/?size=2", "name=joe", "http://test/?size=2&name=joe",
  1409. 0, 0, CURLUE_OK},
  1410. {"HTTP://test/?size=2&", "name=joe", "http://test/?size=2&name=joe",
  1411. 0, 0, CURLUE_OK},
  1412. {"HTTP://test/?size=2#f", "name=joe", "http://test/?size=2&name=joe#f",
  1413. 0, 0, CURLUE_OK},
  1414. {NULL, NULL, NULL, 0, 0, CURLUE_OK}
  1415. };
  1416. static int append(void)
  1417. {
  1418. int i;
  1419. int error = 0;
  1420. for(i = 0; append_list[i].in && !error; i++) {
  1421. CURLUcode rc;
  1422. CURLU *urlp = curl_url();
  1423. if(!urlp) {
  1424. error++;
  1425. break;
  1426. }
  1427. rc = curl_url_set(urlp, CURLUPART_URL,
  1428. append_list[i].in,
  1429. append_list[i].urlflags);
  1430. if(rc)
  1431. error++;
  1432. else
  1433. rc = curl_url_set(urlp, CURLUPART_QUERY,
  1434. append_list[i].q,
  1435. append_list[i].qflags | CURLU_APPENDQUERY);
  1436. if(error)
  1437. ;
  1438. else if(rc != append_list[i].ucode) {
  1439. fprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
  1440. append_list[i].in, (int)rc, append_list[i].ucode);
  1441. error++;
  1442. }
  1443. else if(append_list[i].ucode) {
  1444. /* the expected error happened */
  1445. }
  1446. else {
  1447. char *url;
  1448. rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
  1449. if(rc) {
  1450. fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
  1451. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1452. error++;
  1453. }
  1454. else {
  1455. if(checkurl(append_list[i].in, url, append_list[i].out)) {
  1456. error++;
  1457. }
  1458. curl_free(url);
  1459. }
  1460. }
  1461. curl_url_cleanup(urlp);
  1462. }
  1463. return error;
  1464. }
  1465. static int scopeid(void)
  1466. {
  1467. CURLU *u = curl_url();
  1468. int error = 0;
  1469. CURLUcode rc;
  1470. char *url;
  1471. rc = curl_url_set(u, CURLUPART_URL,
  1472. "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
  1473. if(rc != CURLUE_OK) {
  1474. fprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
  1475. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1476. error++;
  1477. }
  1478. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1479. if(rc != CURLUE_OK) {
  1480. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1481. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1482. error++;
  1483. }
  1484. else {
  1485. curl_free(url);
  1486. }
  1487. rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
  1488. if(rc != CURLUE_OK) {
  1489. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1490. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1491. error++;
  1492. }
  1493. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1494. if(rc != CURLUE_OK) {
  1495. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1496. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1497. error++;
  1498. }
  1499. else {
  1500. curl_free(url);
  1501. }
  1502. rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
  1503. if(rc != CURLUE_OK) {
  1504. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1505. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1506. error++;
  1507. }
  1508. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1509. if(rc != CURLUE_OK) {
  1510. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1511. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1512. error++;
  1513. }
  1514. else {
  1515. curl_free(url);
  1516. }
  1517. rc = curl_url_set(u, CURLUPART_HOST,
  1518. "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
  1519. if(rc != CURLUE_OK) {
  1520. fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
  1521. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1522. error++;
  1523. }
  1524. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1525. if(rc != CURLUE_OK) {
  1526. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1527. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1528. error++;
  1529. }
  1530. else {
  1531. curl_free(url);
  1532. }
  1533. rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  1534. if(rc != CURLUE_OK) {
  1535. fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
  1536. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1537. error++;
  1538. }
  1539. else {
  1540. curl_free(url);
  1541. }
  1542. rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
  1543. if(rc != CURLUE_OK) {
  1544. fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
  1545. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1546. error++;
  1547. }
  1548. else {
  1549. curl_free(url);
  1550. }
  1551. rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
  1552. if(rc != CURLUE_OK) {
  1553. fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
  1554. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1555. error++;
  1556. }
  1557. rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  1558. if(rc != CURLUE_OK) {
  1559. fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
  1560. __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
  1561. error++;
  1562. }
  1563. else {
  1564. curl_free(url);
  1565. }
  1566. curl_url_cleanup(u);
  1567. return error;
  1568. }
  1569. static int get_nothing(void)
  1570. {
  1571. CURLU *u = curl_url();
  1572. if(u) {
  1573. char *p;
  1574. CURLUcode rc;
  1575. rc = curl_url_get(u, CURLUPART_SCHEME, &p, 0);
  1576. if(rc != CURLUE_NO_SCHEME)
  1577. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1578. rc = curl_url_get(u, CURLUPART_HOST, &p, 0);
  1579. if(rc != CURLUE_NO_HOST)
  1580. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1581. rc = curl_url_get(u, CURLUPART_USER, &p, 0);
  1582. if(rc != CURLUE_NO_USER)
  1583. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1584. rc = curl_url_get(u, CURLUPART_PASSWORD, &p, 0);
  1585. if(rc != CURLUE_NO_PASSWORD)
  1586. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1587. rc = curl_url_get(u, CURLUPART_OPTIONS, &p, 0);
  1588. if(rc != CURLUE_NO_OPTIONS)
  1589. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1590. rc = curl_url_get(u, CURLUPART_PATH, &p, 0);
  1591. if(rc != CURLUE_OK)
  1592. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1593. else
  1594. curl_free(p);
  1595. rc = curl_url_get(u, CURLUPART_QUERY, &p, 0);
  1596. if(rc != CURLUE_NO_QUERY)
  1597. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1598. rc = curl_url_get(u, CURLUPART_FRAGMENT, &p, 0);
  1599. if(rc != CURLUE_NO_FRAGMENT)
  1600. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1601. rc = curl_url_get(u, CURLUPART_ZONEID, &p, 0);
  1602. if(rc != CURLUE_NO_ZONEID)
  1603. fprintf(stderr, "unexpected return code %u on line %u\n", (int)rc,
  1604. __LINE__);
  1605. curl_url_cleanup(u);
  1606. }
  1607. return 0;
  1608. }
  1609. static const struct clearurlcase clear_url_list[] ={
  1610. {CURLUPART_SCHEME, "http", NULL, CURLUE_NO_SCHEME},
  1611. {CURLUPART_USER, "user", NULL, CURLUE_NO_USER},
  1612. {CURLUPART_PASSWORD, "password", NULL, CURLUE_NO_PASSWORD},
  1613. {CURLUPART_OPTIONS, "options", NULL, CURLUE_NO_OPTIONS},
  1614. {CURLUPART_HOST, "host", NULL, CURLUE_NO_HOST},
  1615. {CURLUPART_ZONEID, "eth0", NULL, CURLUE_NO_ZONEID},
  1616. {CURLUPART_PORT, "1234", NULL, CURLUE_NO_PORT},
  1617. {CURLUPART_PATH, "/hello", "/", CURLUE_OK},
  1618. {CURLUPART_QUERY, "a=b", NULL, CURLUE_NO_QUERY},
  1619. {CURLUPART_FRAGMENT, "anchor", NULL, CURLUE_NO_FRAGMENT},
  1620. {CURLUPART_URL, NULL, NULL, CURLUE_OK},
  1621. };
  1622. static int clear_url(void)
  1623. {
  1624. CURLU *u = curl_url();
  1625. int i, error = 0;
  1626. if(u) {
  1627. char *p = NULL;
  1628. CURLUcode rc;
  1629. for(i = 0; clear_url_list[i].in && !error; i++) {
  1630. rc = curl_url_set(u, clear_url_list[i].part, clear_url_list[i].in, 0);
  1631. if(rc != CURLUE_OK)
  1632. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1633. rc = curl_url_set(u, CURLUPART_URL, NULL, 0);
  1634. if(rc != CURLUE_OK)
  1635. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1636. rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
  1637. if(rc != clear_url_list[i].ucode || (clear_url_list[i].out &&
  1638. 0 != strcmp(p, clear_url_list[i].out))) {
  1639. fprintf(stderr, "unexpected return code line %u\n", __LINE__);
  1640. error++;
  1641. }
  1642. if(rc == CURLUE_OK)
  1643. curl_free(p);
  1644. }
  1645. }
  1646. curl_url_cleanup(u);
  1647. return error;
  1648. }
  1649. static char total[128000];
  1650. static char bigpart[120000];
  1651. /*
  1652. * verify ridiculous URL part sizes
  1653. */
  1654. static int huge(void)
  1655. {
  1656. const char *smallpart = "c";
  1657. int i;
  1658. CURLU *urlp = curl_url();
  1659. CURLUcode rc;
  1660. CURLUPart part[]= {
  1661. CURLUPART_SCHEME,
  1662. CURLUPART_USER,
  1663. CURLUPART_PASSWORD,
  1664. CURLUPART_HOST,
  1665. CURLUPART_PATH,
  1666. CURLUPART_QUERY,
  1667. CURLUPART_FRAGMENT
  1668. };
  1669. int error = 0;
  1670. if(!urlp)
  1671. return 1;
  1672. bigpart[0] = '/'; /* for the path */
  1673. memset(&bigpart[1], 'a', sizeof(bigpart) - 2);
  1674. bigpart[sizeof(bigpart) - 1] = 0;
  1675. for(i = 0; i < 7; i++) {
  1676. char *partp;
  1677. msnprintf(total, sizeof(total),
  1678. "%s://%s:%s@%s/%s?%s#%s",
  1679. (i == 0)? &bigpart[1] : smallpart,
  1680. (i == 1)? &bigpart[1] : smallpart,
  1681. (i == 2)? &bigpart[1] : smallpart,
  1682. (i == 3)? &bigpart[1] : smallpart,
  1683. (i == 4)? &bigpart[1] : smallpart,
  1684. (i == 5)? &bigpart[1] : smallpart,
  1685. (i == 6)? &bigpart[1] : smallpart);
  1686. rc = curl_url_set(urlp, CURLUPART_URL, total, CURLU_NON_SUPPORT_SCHEME);
  1687. if((!i && (rc != CURLUE_BAD_SCHEME)) ||
  1688. (i && rc)) {
  1689. printf("URL %u: failed to parse [%s]\n", i, total);
  1690. error++;
  1691. }
  1692. /* only extract if the parse worked */
  1693. if(!rc) {
  1694. curl_url_get(urlp, part[i], &partp, 0);
  1695. if(!partp || strcmp(partp, &bigpart[1 - (i == 4)])) {
  1696. printf("URL %u part %u: failure\n", i, part[i]);
  1697. error++;
  1698. }
  1699. curl_free(partp);
  1700. }
  1701. }
  1702. curl_url_cleanup(urlp);
  1703. return error;
  1704. }
  1705. static int urldup(void)
  1706. {
  1707. const char *url[] = {
  1708. "http://"
  1709. "user:pwd@"
  1710. "[2a04:4e42:e00::347%25eth0]"
  1711. ":80"
  1712. "/path"
  1713. "?query"
  1714. "#fraggie",
  1715. "https://example.com",
  1716. "https://user@example.com",
  1717. "https://user.pwd@example.com",
  1718. "https://user.pwd@example.com:1234",
  1719. "https://example.com:1234",
  1720. "example.com:1234",
  1721. "https://user.pwd@example.com:1234/path?query#frag",
  1722. NULL
  1723. };
  1724. CURLU *copy = NULL;
  1725. char *h_str = NULL, *copy_str = NULL;
  1726. CURLU *h = curl_url();
  1727. int i;
  1728. if(!h)
  1729. goto err;
  1730. for(i = 0; url[i]; i++) {
  1731. CURLUcode rc = curl_url_set(h, CURLUPART_URL, url[i],
  1732. CURLU_GUESS_SCHEME);
  1733. if(rc)
  1734. goto err;
  1735. copy = curl_url_dup(h);
  1736. rc = curl_url_get(h, CURLUPART_URL, &h_str, 0);
  1737. if(rc)
  1738. goto err;
  1739. rc = curl_url_get(copy, CURLUPART_URL, &copy_str, 0);
  1740. if(rc)
  1741. goto err;
  1742. if(strcmp(h_str, copy_str)) {
  1743. printf("Original: %s\nParsed: %s\nCopy: %s\n",
  1744. url[i], h_str, copy_str);
  1745. goto err;
  1746. }
  1747. curl_free(copy_str);
  1748. curl_free(h_str);
  1749. curl_url_cleanup(copy);
  1750. copy_str = NULL;
  1751. h_str = NULL;
  1752. copy = NULL;
  1753. }
  1754. curl_url_cleanup(h);
  1755. return 0;
  1756. err:
  1757. curl_free(copy_str);
  1758. curl_free(h_str);
  1759. curl_url_cleanup(copy);
  1760. curl_url_cleanup(h);
  1761. return 1;
  1762. }
  1763. CURLcode test(char *URL)
  1764. {
  1765. (void)URL; /* not used */
  1766. if(urldup())
  1767. return (CURLcode)11;
  1768. if(setget_parts())
  1769. return (CURLcode)10;
  1770. if(get_url())
  1771. return (CURLcode)3;
  1772. if(huge())
  1773. return (CURLcode)9;
  1774. if(get_nothing())
  1775. return (CURLcode)7;
  1776. if(scopeid())
  1777. return (CURLcode)6;
  1778. if(append())
  1779. return (CURLcode)5;
  1780. if(set_url())
  1781. return (CURLcode)1;
  1782. if(set_parts())
  1783. return (CURLcode)2;
  1784. if(get_parts())
  1785. return (CURLcode)4;
  1786. if(clear_url())
  1787. return (CURLcode)8;
  1788. printf("success\n");
  1789. return CURLE_OK;
  1790. }