]> git.saurik.com Git - apt.git/blobdiff - methods/server.cc
Merge remote-tracking branch 'donkult/debian/experimental' into debian/experimental
[apt.git] / methods / server.cc
index ef90c809c115512a7a470049d0f95267dbda4324..c91d3b21822f24c5a6515f548e65d290d4f60eb9 100644 (file)
 // Include Files                                                       /*{{{*/
 #include <config.h>
 
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/hashes.h>
-#include <apt-pkg/netrc.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
 
-#include <fcntl.h>
+#include <ctype.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include <unistd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <climits>
 #include <iostream>
+#include <limits>
 #include <map>
+#include <string>
+#include <vector>
 
-// Internet stuff
-#include <netdb.h>
-
-#include "config.h"
-#include "connect.h"
-#include "rfc2553emu.h"
-#include "http.h"
+#include "server.h"
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -119,10 +114,10 @@ bool ServerState::HeaderLine(string Line)
    string::size_type Pos2 = Pos;
    while (Pos2 < Line.length() && isspace(Line[Pos2]) != 0)
       Pos2++;
-      
+
    string Tag = string(Line,0,Pos);
    string Val = string(Line,Pos2);
-   
+
    if (stringcasecmp(Tag.c_str(),Tag.c_str()+4,"HTTP") == 0)
    {
       // Evil servers return no version
@@ -159,14 +154,14 @@ bool ServerState::HeaderLine(string Line)
       }
 
       return true;
-   }      
-      
+   }
+
    if (stringcasecmp(Tag,"Content-Length:") == 0)
    {
       if (Encoding == Closes)
         Encoding = Stream;
       HaveContent = true;
-      
+
       // The length is already set from the Content-Range header
       if (StartPos != 0)
         return true;
@@ -184,7 +179,7 @@ bool ServerState::HeaderLine(string Line)
       HaveContent = true;
       return true;
    }
-   
+
    if (stringcasecmp(Tag,"Content-Range:") == 0)
    {
       HaveContent = true;
@@ -201,12 +196,12 @@ bool ServerState::HeaderLine(string Line)
         return _error->Error(_("This HTTP server has broken range support"));
       return true;
    }
-   
+
    if (stringcasecmp(Tag,"Transfer-Encoding:") == 0)
    {
       HaveContent = true;
       if (stringcasecmp(Val,"chunked") == 0)
-        Encoding = Chunked;      
+        Encoding = Chunked;
       return true;
    }
 
@@ -218,7 +213,7 @@ bool ServerState::HeaderLine(string Line)
         Persistent = true;
       return true;
    }
-   
+
    if (stringcasecmp(Tag,"Last-Modified:") == 0)
    {
       if (RFC1123StrToTime(Val.c_str(), Date) == false)
@@ -397,9 +392,16 @@ bool ServerMethod::Fetch(FetchItem *)
    for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth; 
        I = I->Next, Depth++)
    {
-      // If pipelining is disabled, we only queue 1 request
-      if (Server->Pipeline == false && Depth >= 0)
-        break;
+      if (Depth >= 0)
+      {
+        // If pipelining is disabled, we only queue 1 request
+        if (Server->Pipeline == false)
+           break;
+        // if we have no hashes, do at most one such request
+        // as we can't fixup pipeling misbehaviors otherwise
+        else if (I->ExpectedHashes.usable() == false)
+           break;
+      }
       
       // Make sure we stick with the same server
       if (Server->Comp(I->Uri) == false)
@@ -413,7 +415,7 @@ bool ServerMethod::Fetch(FetchItem *)
    }
    
    return true;
-};
+}
                                                                        /*}}}*/
 // ServerMethod::Loop - Main loop                                      /*{{{*/
 int ServerMethod::Loop()
@@ -551,7 +553,38 @@ int ServerMethod::Loop()
            // Send status to APT
            if (Result == true)
            {
-              Res.TakeHashes(*Server->GetHashes());
+              Hashes * const resultHashes = Server->GetHashes();
+              HashStringList const hashList = resultHashes->GetHashStringList();
+              if (PipelineDepth != 0 && Queue->ExpectedHashes.usable() == true && Queue->ExpectedHashes != hashList)
+              {
+                 // we did not get the expected hash… mhhh:
+                 // could it be that server/proxy messed up pipelining?
+                 FetchItem * BeforeI = Queue;
+                 for (FetchItem *I = Queue->Next; I != 0 && I != QueueBack; I = I->Next)
+                 {
+                    if (I->ExpectedHashes.usable() == true && I->ExpectedHashes == hashList)
+                    {
+                       // yes, he did! Disable pipelining and rewrite queue
+                       if (Server->Pipeline == true)
+                       {
+                          // FIXME: fake a warning message as we have no proper way of communicating here
+                          std::string out;
+                          strprintf(out, _("Automatically disabled %s due to incorrect response from server/proxy. (man 5 apt.conf)"), "Acquire::http::PipelineDepth");
+                          std::cerr << "W: " << out << std::endl;
+                          Server->Pipeline = false;
+                          // we keep the PipelineDepth value so that the rest of the queue can be fixed up as well
+                       }
+                       Rename(Res.Filename, I->DestFile);
+                       Res.Filename = I->DestFile;
+                       BeforeI->Next = I->Next;
+                       I->Next = Queue;
+                       Queue = I;
+                       break;
+                    }
+                    BeforeI = I;
+                 }
+              }
+              Res.TakeHashes(*resultHashes);
               URIDone(Res);
            }
            else