2
0

lib1560.c 61 KB

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