server.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. HTTP and HTTPS share a lot of common code and these classes are
  5. exactly the dumping ground for this common code
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <config.h>
  10. #include <apt-pkg/acquire-method.h>
  11. #include <apt-pkg/configuration.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/fileutl.h>
  14. #include <apt-pkg/strutl.h>
  15. #include <ctype.h>
  16. #include <signal.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <sys/stat.h>
  20. #include <sys/time.h>
  21. #include <time.h>
  22. #include <unistd.h>
  23. #include <iostream>
  24. #include <limits>
  25. #include <map>
  26. #include <string>
  27. #include <vector>
  28. #include "server.h"
  29. #include <apti18n.h>
  30. /*}}}*/
  31. using namespace std;
  32. string ServerMethod::FailFile;
  33. int ServerMethod::FailFd = -1;
  34. time_t ServerMethod::FailTime = 0;
  35. // ServerState::RunHeaders - Get the headers before the data /*{{{*/
  36. // ---------------------------------------------------------------------
  37. /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
  38. parse error occurred */
  39. ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File,
  40. const std::string &Uri)
  41. {
  42. State = Header;
  43. Owner->Status(_("Waiting for headers"));
  44. Major = 0;
  45. Minor = 0;
  46. Result = 0;
  47. Size = 0;
  48. JunkSize = 0;
  49. StartPos = 0;
  50. Encoding = Closes;
  51. HaveContent = false;
  52. time(&Date);
  53. do
  54. {
  55. string Data;
  56. if (ReadHeaderLines(Data) == false)
  57. continue;
  58. if (Owner->Debug == true)
  59. clog << "Answer for: " << Uri << endl << Data;
  60. for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
  61. {
  62. string::const_iterator J = I;
  63. for (; J != Data.end() && *J != '\n' && *J != '\r'; ++J);
  64. if (HeaderLine(string(I,J)) == false)
  65. return RUN_HEADERS_PARSE_ERROR;
  66. I = J;
  67. }
  68. // 100 Continue is a Nop...
  69. if (Result == 100)
  70. continue;
  71. // Tidy up the connection persistence state.
  72. if (Encoding == Closes && HaveContent == true)
  73. Persistent = false;
  74. return RUN_HEADERS_OK;
  75. }
  76. while (LoadNextResponse(false, File) == true);
  77. return RUN_HEADERS_IO_ERROR;
  78. }
  79. /*}}}*/
  80. // ServerState::HeaderLine - Process a header line /*{{{*/
  81. // ---------------------------------------------------------------------
  82. /* */
  83. bool ServerState::HeaderLine(string Line)
  84. {
  85. if (Line.empty() == true)
  86. return true;
  87. string::size_type Pos = Line.find(' ');
  88. if (Pos == string::npos || Pos+1 > Line.length())
  89. {
  90. // Blah, some servers use "connection:closes", evil.
  91. Pos = Line.find(':');
  92. if (Pos == string::npos || Pos + 2 > Line.length())
  93. return _error->Error(_("Bad header line"));
  94. Pos++;
  95. }
  96. // Parse off any trailing spaces between the : and the next word.
  97. string::size_type Pos2 = Pos;
  98. while (Pos2 < Line.length() && isspace(Line[Pos2]) != 0)
  99. Pos2++;
  100. string Tag = string(Line,0,Pos);
  101. string Val = string(Line,Pos2);
  102. if (stringcasecmp(Tag.c_str(),Tag.c_str()+4,"HTTP") == 0)
  103. {
  104. // Evil servers return no version
  105. if (Line[4] == '/')
  106. {
  107. int const elements = sscanf(Line.c_str(),"HTTP/%3u.%3u %3u%359[^\n]",&Major,&Minor,&Result,Code);
  108. if (elements == 3)
  109. {
  110. Code[0] = '\0';
  111. if (Owner != NULL && Owner->Debug == true)
  112. clog << "HTTP server doesn't give Reason-Phrase for " << Result << std::endl;
  113. }
  114. else if (elements != 4)
  115. return _error->Error(_("The HTTP server sent an invalid reply header"));
  116. }
  117. else
  118. {
  119. Major = 0;
  120. Minor = 9;
  121. if (sscanf(Line.c_str(),"HTTP %3u%359[^\n]",&Result,Code) != 2)
  122. return _error->Error(_("The HTTP server sent an invalid reply header"));
  123. }
  124. /* Check the HTTP response header to get the default persistence
  125. state. */
  126. if (Major < 1)
  127. Persistent = false;
  128. else
  129. {
  130. if (Major == 1 && Minor == 0)
  131. Persistent = false;
  132. else
  133. Persistent = true;
  134. }
  135. return true;
  136. }
  137. if (stringcasecmp(Tag,"Content-Length:") == 0)
  138. {
  139. if (Encoding == Closes)
  140. Encoding = Stream;
  141. HaveContent = true;
  142. unsigned long long * SizePtr = &Size;
  143. if (Result == 416)
  144. SizePtr = &JunkSize;
  145. *SizePtr = strtoull(Val.c_str(), NULL, 10);
  146. if (*SizePtr >= std::numeric_limits<unsigned long long>::max())
  147. return _error->Errno("HeaderLine", _("The HTTP server sent an invalid Content-Length header"));
  148. else if (*SizePtr == 0)
  149. HaveContent = false;
  150. return true;
  151. }
  152. if (stringcasecmp(Tag,"Content-Type:") == 0)
  153. {
  154. HaveContent = true;
  155. return true;
  156. }
  157. if (stringcasecmp(Tag,"Content-Range:") == 0)
  158. {
  159. HaveContent = true;
  160. // §14.16 says 'byte-range-resp-spec' should be a '*' in case of 416
  161. if (Result == 416 && sscanf(Val.c_str(), "bytes */%llu",&Size) == 1)
  162. ; // we got the expected filesize which is all we wanted
  163. else if (sscanf(Val.c_str(),"bytes %llu-%*u/%llu",&StartPos,&Size) != 2)
  164. return _error->Error(_("The HTTP server sent an invalid Content-Range header"));
  165. if ((unsigned long long)StartPos > Size)
  166. return _error->Error(_("This HTTP server has broken range support"));
  167. return true;
  168. }
  169. if (stringcasecmp(Tag,"Transfer-Encoding:") == 0)
  170. {
  171. HaveContent = true;
  172. if (stringcasecmp(Val,"chunked") == 0)
  173. Encoding = Chunked;
  174. return true;
  175. }
  176. if (stringcasecmp(Tag,"Connection:") == 0)
  177. {
  178. if (stringcasecmp(Val,"close") == 0)
  179. Persistent = false;
  180. if (stringcasecmp(Val,"keep-alive") == 0)
  181. Persistent = true;
  182. return true;
  183. }
  184. if (stringcasecmp(Tag,"Last-Modified:") == 0)
  185. {
  186. if (RFC1123StrToTime(Val.c_str(), Date) == false)
  187. return _error->Error(_("Unknown date format"));
  188. return true;
  189. }
  190. if (stringcasecmp(Tag,"Location:") == 0)
  191. {
  192. Location = Val;
  193. return true;
  194. }
  195. return true;
  196. }
  197. /*}}}*/
  198. // ServerState::ServerState - Constructor /*{{{*/
  199. ServerState::ServerState(URI Srv, ServerMethod *Owner) : ServerName(Srv), TimeOut(120), Owner(Owner)
  200. {
  201. Reset();
  202. }
  203. /*}}}*/
  204. bool ServerMethod::Configuration(string Message) /*{{{*/
  205. {
  206. if (pkgAcqMethod::Configuration(Message) == false)
  207. return false;
  208. DropPrivsOrDie();
  209. return true;
  210. }
  211. /*}}}*/
  212. // ServerMethod::DealWithHeaders - Handle the retrieved header data /*{{{*/
  213. // ---------------------------------------------------------------------
  214. /* We look at the header data we got back from the server and decide what
  215. to do. Returns DealWithHeadersResult (see http.h for details).
  216. */
  217. ServerMethod::DealWithHeadersResult
  218. ServerMethod::DealWithHeaders(FetchResult &Res)
  219. {
  220. // Not Modified
  221. if (Server->Result == 304)
  222. {
  223. unlink(Queue->DestFile.c_str());
  224. Res.IMSHit = true;
  225. Res.LastModified = Queue->LastModified;
  226. return IMS_HIT;
  227. }
  228. /* Redirect
  229. *
  230. * Note that it is only OK for us to treat all redirection the same
  231. * because we *always* use GET, not other HTTP methods. There are
  232. * three redirection codes for which it is not appropriate that we
  233. * redirect. Pass on those codes so the error handling kicks in.
  234. */
  235. if (AllowRedirect
  236. && (Server->Result > 300 && Server->Result < 400)
  237. && (Server->Result != 300 // Multiple Choices
  238. && Server->Result != 304 // Not Modified
  239. && Server->Result != 306)) // (Not part of HTTP/1.1, reserved)
  240. {
  241. if (Server->Location.empty() == true);
  242. else if (Server->Location[0] == '/' && Queue->Uri.empty() == false)
  243. {
  244. URI Uri = Queue->Uri;
  245. if (Uri.Host.empty() == false)
  246. NextURI = URI::SiteOnly(Uri);
  247. else
  248. NextURI.clear();
  249. NextURI.append(DeQuoteString(Server->Location));
  250. return TRY_AGAIN_OR_REDIRECT;
  251. }
  252. else
  253. {
  254. NextURI = DeQuoteString(Server->Location);
  255. URI tmpURI = NextURI;
  256. URI Uri = Queue->Uri;
  257. // same protocol redirects are okay
  258. if (tmpURI.Access == Uri.Access)
  259. return TRY_AGAIN_OR_REDIRECT;
  260. // as well as http to https
  261. else if (Uri.Access == "http" && tmpURI.Access == "https")
  262. return TRY_AGAIN_OR_REDIRECT;
  263. }
  264. /* else pass through for error message */
  265. }
  266. // retry after an invalid range response without partial data
  267. else if (Server->Result == 416)
  268. {
  269. struct stat SBuf;
  270. if (stat(Queue->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
  271. {
  272. if ((unsigned long long)SBuf.st_size == Server->Size)
  273. {
  274. // the file is completely downloaded, but was not moved
  275. if (Server->HaveContent == true)
  276. {
  277. // Send to error page to dev/null
  278. FileFd DevNull("/dev/null",FileFd::WriteExists);
  279. Server->RunData(&DevNull);
  280. }
  281. Server->HaveContent = false;
  282. Server->StartPos = Server->Size;
  283. Server->Result = 200;
  284. }
  285. else if (unlink(Queue->DestFile.c_str()) == 0)
  286. {
  287. NextURI = Queue->Uri;
  288. return TRY_AGAIN_OR_REDIRECT;
  289. }
  290. }
  291. }
  292. /* We have a reply we dont handle. This should indicate a perm server
  293. failure */
  294. if (Server->Result < 200 || Server->Result >= 300)
  295. {
  296. std::string err;
  297. strprintf(err, "HttpError%u", Server->Result);
  298. SetFailReason(err);
  299. _error->Error("%u %s", Server->Result, Server->Code);
  300. if (Server->HaveContent == true)
  301. return ERROR_WITH_CONTENT_PAGE;
  302. return ERROR_UNRECOVERABLE;
  303. }
  304. // This is some sort of 2xx 'data follows' reply
  305. Res.LastModified = Server->Date;
  306. Res.Size = Server->Size;
  307. // Open the file
  308. delete File;
  309. File = new FileFd(Queue->DestFile,FileFd::WriteAny);
  310. if (_error->PendingError() == true)
  311. return ERROR_NOT_FROM_SERVER;
  312. FailFile = Queue->DestFile;
  313. FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
  314. FailFd = File->Fd();
  315. FailTime = Server->Date;
  316. if (Server->InitHashes(*File, Queue->ExpectedHashes) == false)
  317. {
  318. _error->Errno("read",_("Problem hashing file"));
  319. return ERROR_NOT_FROM_SERVER;
  320. }
  321. if (Server->StartPos > 0)
  322. Res.ResumePoint = Server->StartPos;
  323. SetNonBlock(File->Fd(),true);
  324. return FILE_IS_OPEN;
  325. }
  326. /*}}}*/
  327. // ServerMethod::SigTerm - Handle a fatal signal /*{{{*/
  328. // ---------------------------------------------------------------------
  329. /* This closes and timestamps the open file. This is necessary to get
  330. resume behavoir on user abort */
  331. void ServerMethod::SigTerm(int)
  332. {
  333. if (FailFd == -1)
  334. _exit(100);
  335. struct timeval times[2];
  336. times[0].tv_sec = FailTime;
  337. times[1].tv_sec = FailTime;
  338. times[0].tv_usec = times[1].tv_usec = 0;
  339. utimes(FailFile.c_str(), times);
  340. close(FailFd);
  341. _exit(100);
  342. }
  343. /*}}}*/
  344. // ServerMethod::Fetch - Fetch an item /*{{{*/
  345. // ---------------------------------------------------------------------
  346. /* This adds an item to the pipeline. We keep the pipeline at a fixed
  347. depth. */
  348. bool ServerMethod::Fetch(FetchItem *)
  349. {
  350. if (Server == 0)
  351. return true;
  352. // Queue the requests
  353. int Depth = -1;
  354. for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth;
  355. I = I->Next, Depth++)
  356. {
  357. if (Depth >= 0)
  358. {
  359. // If pipelining is disabled, we only queue 1 request
  360. if (Server->Pipeline == false)
  361. break;
  362. // if we have no hashes, do at most one such request
  363. // as we can't fixup pipeling misbehaviors otherwise
  364. else if (I->ExpectedHashes.usable() == false)
  365. break;
  366. }
  367. // Make sure we stick with the same server
  368. if (Server->Comp(I->Uri) == false)
  369. break;
  370. if (QueueBack == I)
  371. {
  372. QueueBack = I->Next;
  373. SendReq(I);
  374. continue;
  375. }
  376. }
  377. return true;
  378. }
  379. /*}}}*/
  380. // ServerMethod::Loop - Main loop /*{{{*/
  381. int ServerMethod::Loop()
  382. {
  383. typedef vector<string> StringVector;
  384. typedef vector<string>::iterator StringVectorIterator;
  385. map<string, StringVector> Redirected;
  386. signal(SIGTERM,SigTerm);
  387. signal(SIGINT,SigTerm);
  388. Server = 0;
  389. int FailCounter = 0;
  390. while (1)
  391. {
  392. // We have no commands, wait for some to arrive
  393. if (Queue == 0)
  394. {
  395. if (WaitFd(STDIN_FILENO) == false)
  396. return 0;
  397. }
  398. /* Run messages, we can accept 0 (no message) if we didn't
  399. do a WaitFd above.. Otherwise the FD is closed. */
  400. int Result = Run(true);
  401. if (Result != -1 && (Result != 0 || Queue == 0))
  402. {
  403. if(FailReason.empty() == false ||
  404. _config->FindB("Acquire::http::DependOnSTDIN", true) == true)
  405. return 100;
  406. else
  407. return 0;
  408. }
  409. if (Queue == 0)
  410. continue;
  411. // Connect to the server
  412. if (Server == 0 || Server->Comp(Queue->Uri) == false)
  413. {
  414. delete Server;
  415. Server = CreateServerState(Queue->Uri);
  416. }
  417. /* If the server has explicitly said this is the last connection
  418. then we pre-emptively shut down the pipeline and tear down
  419. the connection. This will speed up HTTP/1.0 servers a tad
  420. since we don't have to wait for the close sequence to
  421. complete */
  422. if (Server->Persistent == false)
  423. Server->Close();
  424. // Reset the pipeline
  425. if (Server->IsOpen() == false)
  426. QueueBack = Queue;
  427. // Connnect to the host
  428. if (Server->Open() == false)
  429. {
  430. Fail(true);
  431. delete Server;
  432. Server = 0;
  433. continue;
  434. }
  435. // Fill the pipeline.
  436. Fetch(0);
  437. // Fetch the next URL header data from the server.
  438. switch (Server->RunHeaders(File, Queue->Uri))
  439. {
  440. case ServerState::RUN_HEADERS_OK:
  441. break;
  442. // The header data is bad
  443. case ServerState::RUN_HEADERS_PARSE_ERROR:
  444. {
  445. _error->Error(_("Bad header data"));
  446. Fail(true);
  447. RotateDNS();
  448. continue;
  449. }
  450. // The server closed a connection during the header get..
  451. default:
  452. case ServerState::RUN_HEADERS_IO_ERROR:
  453. {
  454. FailCounter++;
  455. _error->Discard();
  456. Server->Close();
  457. Server->Pipeline = false;
  458. if (FailCounter >= 2)
  459. {
  460. Fail(_("Connection failed"),true);
  461. FailCounter = 0;
  462. }
  463. RotateDNS();
  464. continue;
  465. }
  466. };
  467. // Decide what to do.
  468. FetchResult Res;
  469. Res.Filename = Queue->DestFile;
  470. switch (DealWithHeaders(Res))
  471. {
  472. // Ok, the file is Open
  473. case FILE_IS_OPEN:
  474. {
  475. URIStart(Res);
  476. // Run the data
  477. bool Result = true;
  478. // ensure we don't fetch too much
  479. // we could do "Server->MaximumSize = Queue->MaximumSize" here
  480. // but that would break the clever pipeline messup detection
  481. // so instead we use the size of the biggest item in the queue
  482. Server->MaximumSize = FindMaximumObjectSizeInQueue();
  483. if (Server->HaveContent)
  484. Result = Server->RunData(File);
  485. /* If the server is sending back sizeless responses then fill in
  486. the size now */
  487. if (Res.Size == 0)
  488. Res.Size = File->Size();
  489. // Close the file, destroy the FD object and timestamp it
  490. FailFd = -1;
  491. delete File;
  492. File = 0;
  493. // Timestamp
  494. struct timeval times[2];
  495. times[0].tv_sec = times[1].tv_sec = Server->Date;
  496. times[0].tv_usec = times[1].tv_usec = 0;
  497. utimes(Queue->DestFile.c_str(), times);
  498. // Send status to APT
  499. if (Result == true)
  500. {
  501. Hashes * const resultHashes = Server->GetHashes();
  502. HashStringList const hashList = resultHashes->GetHashStringList();
  503. if (PipelineDepth != 0 && Queue->ExpectedHashes.usable() == true && Queue->ExpectedHashes != hashList)
  504. {
  505. // we did not get the expected hash… mhhh:
  506. // could it be that server/proxy messed up pipelining?
  507. FetchItem * BeforeI = Queue;
  508. for (FetchItem *I = Queue->Next; I != 0 && I != QueueBack; I = I->Next)
  509. {
  510. if (I->ExpectedHashes.usable() == true && I->ExpectedHashes == hashList)
  511. {
  512. // yes, he did! Disable pipelining and rewrite queue
  513. if (Server->Pipeline == true)
  514. {
  515. // FIXME: fake a warning message as we have no proper way of communicating here
  516. std::string out;
  517. strprintf(out, _("Automatically disabled %s due to incorrect response from server/proxy. (man 5 apt.conf)"), "Acquire::http::PipelineDepth");
  518. std::cerr << "W: " << out << std::endl;
  519. Server->Pipeline = false;
  520. // we keep the PipelineDepth value so that the rest of the queue can be fixed up as well
  521. }
  522. Rename(Res.Filename, I->DestFile);
  523. Res.Filename = I->DestFile;
  524. BeforeI->Next = I->Next;
  525. I->Next = Queue;
  526. Queue = I;
  527. break;
  528. }
  529. BeforeI = I;
  530. }
  531. }
  532. Res.TakeHashes(*resultHashes);
  533. URIDone(Res);
  534. }
  535. else
  536. {
  537. if (Server->IsOpen() == false)
  538. {
  539. FailCounter++;
  540. _error->Discard();
  541. Server->Close();
  542. if (FailCounter >= 2)
  543. {
  544. Fail(_("Connection failed"),true);
  545. FailCounter = 0;
  546. }
  547. QueueBack = Queue;
  548. }
  549. else
  550. {
  551. Server->Close();
  552. Fail(true);
  553. }
  554. }
  555. break;
  556. }
  557. // IMS hit
  558. case IMS_HIT:
  559. {
  560. URIDone(Res);
  561. break;
  562. }
  563. // Hard server error, not found or something
  564. case ERROR_UNRECOVERABLE:
  565. {
  566. Fail();
  567. break;
  568. }
  569. // Hard internal error, kill the connection and fail
  570. case ERROR_NOT_FROM_SERVER:
  571. {
  572. delete File;
  573. File = 0;
  574. Fail();
  575. RotateDNS();
  576. Server->Close();
  577. break;
  578. }
  579. // We need to flush the data, the header is like a 404 w/ error text
  580. case ERROR_WITH_CONTENT_PAGE:
  581. {
  582. Fail();
  583. // Send to content to dev/null
  584. File = new FileFd("/dev/null",FileFd::WriteExists);
  585. Server->RunData(File);
  586. delete File;
  587. File = 0;
  588. break;
  589. }
  590. // Try again with a new URL
  591. case TRY_AGAIN_OR_REDIRECT:
  592. {
  593. // Clear rest of response if there is content
  594. if (Server->HaveContent)
  595. {
  596. File = new FileFd("/dev/null",FileFd::WriteExists);
  597. Server->RunData(File);
  598. delete File;
  599. File = 0;
  600. }
  601. /* Detect redirect loops. No more redirects are allowed
  602. after the same URI is seen twice in a queue item. */
  603. StringVector &R = Redirected[Queue->DestFile];
  604. bool StopRedirects = false;
  605. if (R.empty() == true)
  606. R.push_back(Queue->Uri);
  607. else if (R[0] == "STOP" || R.size() > 10)
  608. StopRedirects = true;
  609. else
  610. {
  611. for (StringVectorIterator I = R.begin(); I != R.end(); ++I)
  612. if (Queue->Uri == *I)
  613. {
  614. R[0] = "STOP";
  615. break;
  616. }
  617. R.push_back(Queue->Uri);
  618. }
  619. if (StopRedirects == false)
  620. Redirect(NextURI);
  621. else
  622. Fail();
  623. break;
  624. }
  625. default:
  626. Fail(_("Internal error"));
  627. break;
  628. }
  629. FailCounter = 0;
  630. }
  631. return 0;
  632. }
  633. /*}}}*/
  634. /*{{{*/
  635. unsigned long long
  636. ServerMethod::FindMaximumObjectSizeInQueue() const
  637. {
  638. unsigned long long MaxSizeInQueue = 0;
  639. for (FetchItem *I = Queue; I != 0 && I != QueueBack; I = I->Next)
  640. MaxSizeInQueue = std::max(MaxSizeInQueue, I->MaximumSize);
  641. return MaxSizeInQueue;
  642. }
  643. /*}}}*/