server.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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 ServerState::AddPartialFileToHashes(FileFd &File) /*{{{*/
  205. {
  206. File.Truncate(StartPos);
  207. return GetHashes()->AddFD(File, StartPos);
  208. }
  209. /*}}}*/
  210. bool ServerMethod::Configuration(string Message) /*{{{*/
  211. {
  212. if (pkgAcqMethod::Configuration(Message) == false)
  213. return false;
  214. DropPrivsOrDie();
  215. return true;
  216. }
  217. /*}}}*/
  218. // ServerMethod::DealWithHeaders - Handle the retrieved header data /*{{{*/
  219. // ---------------------------------------------------------------------
  220. /* We look at the header data we got back from the server and decide what
  221. to do. Returns DealWithHeadersResult (see http.h for details).
  222. */
  223. ServerMethod::DealWithHeadersResult
  224. ServerMethod::DealWithHeaders(FetchResult &Res)
  225. {
  226. // Not Modified
  227. if (Server->Result == 304)
  228. {
  229. unlink(Queue->DestFile.c_str());
  230. Res.IMSHit = true;
  231. Res.LastModified = Queue->LastModified;
  232. return IMS_HIT;
  233. }
  234. /* Redirect
  235. *
  236. * Note that it is only OK for us to treat all redirection the same
  237. * because we *always* use GET, not other HTTP methods. There are
  238. * three redirection codes for which it is not appropriate that we
  239. * redirect. Pass on those codes so the error handling kicks in.
  240. */
  241. if (AllowRedirect
  242. && (Server->Result > 300 && Server->Result < 400)
  243. && (Server->Result != 300 // Multiple Choices
  244. && Server->Result != 304 // Not Modified
  245. && Server->Result != 306)) // (Not part of HTTP/1.1, reserved)
  246. {
  247. if (Server->Location.empty() == true);
  248. else if (Server->Location[0] == '/' && Queue->Uri.empty() == false)
  249. {
  250. URI Uri = Queue->Uri;
  251. if (Uri.Host.empty() == false)
  252. NextURI = URI::SiteOnly(Uri);
  253. else
  254. NextURI.clear();
  255. NextURI.append(DeQuoteString(Server->Location));
  256. return TRY_AGAIN_OR_REDIRECT;
  257. }
  258. else
  259. {
  260. NextURI = DeQuoteString(Server->Location);
  261. URI tmpURI = NextURI;
  262. URI Uri = Queue->Uri;
  263. // same protocol redirects are okay
  264. if (tmpURI.Access == Uri.Access)
  265. return TRY_AGAIN_OR_REDIRECT;
  266. // as well as http to https
  267. else if (Uri.Access == "http" && tmpURI.Access == "https")
  268. return TRY_AGAIN_OR_REDIRECT;
  269. }
  270. /* else pass through for error message */
  271. }
  272. // retry after an invalid range response without partial data
  273. else if (Server->Result == 416)
  274. {
  275. struct stat SBuf;
  276. if (stat(Queue->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
  277. {
  278. bool partialHit = false;
  279. if (Queue->ExpectedHashes.usable() == true)
  280. {
  281. Hashes resultHashes(Queue->ExpectedHashes);
  282. FileFd file(Queue->DestFile, FileFd::ReadOnly);
  283. Server->Size = file.FileSize();
  284. Server->Date = file.ModificationTime();
  285. resultHashes.AddFD(file);
  286. HashStringList const hashList = resultHashes.GetHashStringList();
  287. partialHit = (Queue->ExpectedHashes == hashList);
  288. }
  289. else if ((unsigned long long)SBuf.st_size == Server->Size)
  290. partialHit = true;
  291. if (partialHit == true)
  292. {
  293. // the file is completely downloaded, but was not moved
  294. if (Server->HaveContent == true)
  295. {
  296. // Send to error page to dev/null
  297. FileFd DevNull("/dev/null",FileFd::WriteExists);
  298. Server->RunData(&DevNull);
  299. }
  300. Server->HaveContent = false;
  301. Server->StartPos = Server->Size;
  302. Server->Result = 200;
  303. }
  304. else if (unlink(Queue->DestFile.c_str()) == 0)
  305. {
  306. NextURI = Queue->Uri;
  307. return TRY_AGAIN_OR_REDIRECT;
  308. }
  309. }
  310. }
  311. /* We have a reply we dont handle. This should indicate a perm server
  312. failure */
  313. if (Server->Result < 200 || Server->Result >= 300)
  314. {
  315. std::string err;
  316. strprintf(err, "HttpError%u", Server->Result);
  317. SetFailReason(err);
  318. _error->Error("%u %s", Server->Result, Server->Code);
  319. if (Server->HaveContent == true)
  320. return ERROR_WITH_CONTENT_PAGE;
  321. return ERROR_UNRECOVERABLE;
  322. }
  323. // This is some sort of 2xx 'data follows' reply
  324. Res.LastModified = Server->Date;
  325. Res.Size = Server->Size;
  326. // Open the file
  327. delete File;
  328. File = new FileFd(Queue->DestFile,FileFd::WriteAny);
  329. if (_error->PendingError() == true)
  330. return ERROR_NOT_FROM_SERVER;
  331. FailFile = Queue->DestFile;
  332. FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
  333. FailFd = File->Fd();
  334. FailTime = Server->Date;
  335. if (Server->InitHashes(Queue->ExpectedHashes) == false || Server->AddPartialFileToHashes(*File) == false)
  336. {
  337. _error->Errno("read",_("Problem hashing file"));
  338. return ERROR_NOT_FROM_SERVER;
  339. }
  340. if (Server->StartPos > 0)
  341. Res.ResumePoint = Server->StartPos;
  342. SetNonBlock(File->Fd(),true);
  343. return FILE_IS_OPEN;
  344. }
  345. /*}}}*/
  346. // ServerMethod::SigTerm - Handle a fatal signal /*{{{*/
  347. // ---------------------------------------------------------------------
  348. /* This closes and timestamps the open file. This is necessary to get
  349. resume behavoir on user abort */
  350. void ServerMethod::SigTerm(int)
  351. {
  352. if (FailFd == -1)
  353. _exit(100);
  354. struct timeval times[2];
  355. times[0].tv_sec = FailTime;
  356. times[1].tv_sec = FailTime;
  357. times[0].tv_usec = times[1].tv_usec = 0;
  358. utimes(FailFile.c_str(), times);
  359. close(FailFd);
  360. _exit(100);
  361. }
  362. /*}}}*/
  363. // ServerMethod::Fetch - Fetch an item /*{{{*/
  364. // ---------------------------------------------------------------------
  365. /* This adds an item to the pipeline. We keep the pipeline at a fixed
  366. depth. */
  367. bool ServerMethod::Fetch(FetchItem *)
  368. {
  369. if (Server == 0)
  370. return true;
  371. // Queue the requests
  372. int Depth = -1;
  373. for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth;
  374. I = I->Next, Depth++)
  375. {
  376. if (Depth >= 0)
  377. {
  378. // If pipelining is disabled, we only queue 1 request
  379. if (Server->Pipeline == false)
  380. break;
  381. // if we have no hashes, do at most one such request
  382. // as we can't fixup pipeling misbehaviors otherwise
  383. else if (I->ExpectedHashes.usable() == false)
  384. break;
  385. }
  386. // Make sure we stick with the same server
  387. if (Server->Comp(I->Uri) == false)
  388. break;
  389. if (QueueBack == I)
  390. {
  391. QueueBack = I->Next;
  392. SendReq(I);
  393. continue;
  394. }
  395. }
  396. return true;
  397. }
  398. /*}}}*/
  399. // ServerMethod::Loop - Main loop /*{{{*/
  400. int ServerMethod::Loop()
  401. {
  402. typedef vector<string> StringVector;
  403. typedef vector<string>::iterator StringVectorIterator;
  404. map<string, StringVector> Redirected;
  405. signal(SIGTERM,SigTerm);
  406. signal(SIGINT,SigTerm);
  407. Server = 0;
  408. int FailCounter = 0;
  409. while (1)
  410. {
  411. // We have no commands, wait for some to arrive
  412. if (Queue == 0)
  413. {
  414. if (WaitFd(STDIN_FILENO) == false)
  415. return 0;
  416. }
  417. /* Run messages, we can accept 0 (no message) if we didn't
  418. do a WaitFd above.. Otherwise the FD is closed. */
  419. int Result = Run(true);
  420. if (Result != -1 && (Result != 0 || Queue == 0))
  421. {
  422. if(FailReason.empty() == false ||
  423. _config->FindB("Acquire::http::DependOnSTDIN", true) == true)
  424. return 100;
  425. else
  426. return 0;
  427. }
  428. if (Queue == 0)
  429. continue;
  430. // Connect to the server
  431. if (Server == 0 || Server->Comp(Queue->Uri) == false)
  432. {
  433. delete Server;
  434. Server = CreateServerState(Queue->Uri);
  435. }
  436. /* If the server has explicitly said this is the last connection
  437. then we pre-emptively shut down the pipeline and tear down
  438. the connection. This will speed up HTTP/1.0 servers a tad
  439. since we don't have to wait for the close sequence to
  440. complete */
  441. if (Server->Persistent == false)
  442. Server->Close();
  443. // Reset the pipeline
  444. if (Server->IsOpen() == false)
  445. QueueBack = Queue;
  446. // Connnect to the host
  447. if (Server->Open() == false)
  448. {
  449. Fail(true);
  450. delete Server;
  451. Server = 0;
  452. continue;
  453. }
  454. // Fill the pipeline.
  455. Fetch(0);
  456. // Fetch the next URL header data from the server.
  457. switch (Server->RunHeaders(File, Queue->Uri))
  458. {
  459. case ServerState::RUN_HEADERS_OK:
  460. break;
  461. // The header data is bad
  462. case ServerState::RUN_HEADERS_PARSE_ERROR:
  463. {
  464. _error->Error(_("Bad header data"));
  465. Fail(true);
  466. RotateDNS();
  467. continue;
  468. }
  469. // The server closed a connection during the header get..
  470. default:
  471. case ServerState::RUN_HEADERS_IO_ERROR:
  472. {
  473. FailCounter++;
  474. _error->Discard();
  475. Server->Close();
  476. Server->Pipeline = false;
  477. if (FailCounter >= 2)
  478. {
  479. Fail(_("Connection failed"),true);
  480. FailCounter = 0;
  481. }
  482. RotateDNS();
  483. continue;
  484. }
  485. };
  486. // Decide what to do.
  487. FetchResult Res;
  488. Res.Filename = Queue->DestFile;
  489. switch (DealWithHeaders(Res))
  490. {
  491. // Ok, the file is Open
  492. case FILE_IS_OPEN:
  493. {
  494. URIStart(Res);
  495. // Run the data
  496. bool Result = true;
  497. // ensure we don't fetch too much
  498. // we could do "Server->MaximumSize = Queue->MaximumSize" here
  499. // but that would break the clever pipeline messup detection
  500. // so instead we use the size of the biggest item in the queue
  501. Server->MaximumSize = FindMaximumObjectSizeInQueue();
  502. if (Server->HaveContent)
  503. Result = Server->RunData(File);
  504. /* If the server is sending back sizeless responses then fill in
  505. the size now */
  506. if (Res.Size == 0)
  507. Res.Size = File->Size();
  508. // Close the file, destroy the FD object and timestamp it
  509. FailFd = -1;
  510. delete File;
  511. File = 0;
  512. // Timestamp
  513. struct timeval times[2];
  514. times[0].tv_sec = times[1].tv_sec = Server->Date;
  515. times[0].tv_usec = times[1].tv_usec = 0;
  516. utimes(Queue->DestFile.c_str(), times);
  517. // Send status to APT
  518. if (Result == true)
  519. {
  520. Hashes * const resultHashes = Server->GetHashes();
  521. HashStringList const hashList = resultHashes->GetHashStringList();
  522. if (PipelineDepth != 0 && Queue->ExpectedHashes.usable() == true && Queue->ExpectedHashes != hashList)
  523. {
  524. // we did not get the expected hash… mhhh:
  525. // could it be that server/proxy messed up pipelining?
  526. FetchItem * BeforeI = Queue;
  527. for (FetchItem *I = Queue->Next; I != 0 && I != QueueBack; I = I->Next)
  528. {
  529. if (I->ExpectedHashes.usable() == true && I->ExpectedHashes == hashList)
  530. {
  531. // yes, he did! Disable pipelining and rewrite queue
  532. if (Server->Pipeline == true)
  533. {
  534. // FIXME: fake a warning message as we have no proper way of communicating here
  535. std::string out;
  536. strprintf(out, _("Automatically disabled %s due to incorrect response from server/proxy. (man 5 apt.conf)"), "Acquire::http::PipelineDepth");
  537. std::cerr << "W: " << out << std::endl;
  538. Server->Pipeline = false;
  539. // we keep the PipelineDepth value so that the rest of the queue can be fixed up as well
  540. }
  541. Rename(Res.Filename, I->DestFile);
  542. Res.Filename = I->DestFile;
  543. BeforeI->Next = I->Next;
  544. I->Next = Queue;
  545. Queue = I;
  546. break;
  547. }
  548. BeforeI = I;
  549. }
  550. }
  551. Res.TakeHashes(*resultHashes);
  552. URIDone(Res);
  553. }
  554. else
  555. {
  556. if (Server->IsOpen() == false)
  557. {
  558. FailCounter++;
  559. _error->Discard();
  560. Server->Close();
  561. if (FailCounter >= 2)
  562. {
  563. Fail(_("Connection failed"),true);
  564. FailCounter = 0;
  565. }
  566. QueueBack = Queue;
  567. }
  568. else
  569. {
  570. Server->Close();
  571. Fail(true);
  572. }
  573. }
  574. break;
  575. }
  576. // IMS hit
  577. case IMS_HIT:
  578. {
  579. URIDone(Res);
  580. break;
  581. }
  582. // Hard server error, not found or something
  583. case ERROR_UNRECOVERABLE:
  584. {
  585. Fail();
  586. break;
  587. }
  588. // Hard internal error, kill the connection and fail
  589. case ERROR_NOT_FROM_SERVER:
  590. {
  591. delete File;
  592. File = 0;
  593. Fail();
  594. RotateDNS();
  595. Server->Close();
  596. break;
  597. }
  598. // We need to flush the data, the header is like a 404 w/ error text
  599. case ERROR_WITH_CONTENT_PAGE:
  600. {
  601. Fail();
  602. // Send to content to dev/null
  603. File = new FileFd("/dev/null",FileFd::WriteExists);
  604. Server->RunData(File);
  605. delete File;
  606. File = 0;
  607. break;
  608. }
  609. // Try again with a new URL
  610. case TRY_AGAIN_OR_REDIRECT:
  611. {
  612. // Clear rest of response if there is content
  613. if (Server->HaveContent)
  614. {
  615. File = new FileFd("/dev/null",FileFd::WriteExists);
  616. Server->RunData(File);
  617. delete File;
  618. File = 0;
  619. }
  620. /* Detect redirect loops. No more redirects are allowed
  621. after the same URI is seen twice in a queue item. */
  622. StringVector &R = Redirected[Queue->DestFile];
  623. bool StopRedirects = false;
  624. if (R.empty() == true)
  625. R.push_back(Queue->Uri);
  626. else if (R[0] == "STOP" || R.size() > 10)
  627. StopRedirects = true;
  628. else
  629. {
  630. for (StringVectorIterator I = R.begin(); I != R.end(); ++I)
  631. if (Queue->Uri == *I)
  632. {
  633. R[0] = "STOP";
  634. break;
  635. }
  636. R.push_back(Queue->Uri);
  637. }
  638. if (StopRedirects == false)
  639. Redirect(NextURI);
  640. else
  641. Fail();
  642. break;
  643. }
  644. default:
  645. Fail(_("Internal error"));
  646. break;
  647. }
  648. FailCounter = 0;
  649. }
  650. return 0;
  651. }
  652. /*}}}*/
  653. /*{{{*/
  654. unsigned long long
  655. ServerMethod::FindMaximumObjectSizeInQueue() const
  656. {
  657. unsigned long long MaxSizeInQueue = 0;
  658. for (FetchItem *I = Queue; I != 0 && I != QueueBack; I = I->Next)
  659. MaxSizeInQueue = std::max(MaxSizeInQueue, I->MaximumSize);
  660. return MaxSizeInQueue;
  661. }
  662. /*}}}*/