]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-method.cc
fix 'Source' to 'Package' rename in apt-ftparchive
[apt.git] / apt-pkg / acquire-method.cc
index 5bc1c159a9b968a3cd7b501cacc46799c3debee5..c29ef469e18eb16d9e7d1c68187918819acaf6b2 100644 (file)
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
-
+#include <apt-pkg/md5.h>
+#include <apt-pkg/sha1.h>
+#include <apt-pkg/sha2.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <string>
+#include <vector>
 #include <iostream>
 #include <stdio.h>
-#include <sys/signal.h>
                                                                        /*}}}*/
 
 using namespace std;
@@ -94,7 +102,10 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
    if (Queue != 0)
    {
       std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n"
-               << "Message: " << Err << " " << IP << "\n";
+               << "Message: " << Err;
+      if (IP.empty() == false && _config->FindB("Acquire::Failure::ShowIP", true) == true)
+        std::cout << " " << IP;
+      std::cout << "\n";
       Dequeue();
    }
    else
@@ -110,6 +121,18 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
 
    std::cout << "\n" << std::flush;
 }
+                                                                       /*}}}*/
+// AcqMethod::DropPrivsOrDie - Drop privileges or die          /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::DropPrivsOrDie()
+{
+   if (!DropPrivileges()) {
+      Fail(false);
+      exit(112);       /* call the european emergency number */
+   }
+}
+
                                                                        /*}}}*/
 // AcqMethod::URIStart - Indicate a download is starting               /*{{{*/
 // ---------------------------------------------------------------------
@@ -139,6 +162,16 @@ void pkgAcqMethod::URIStart(FetchResult &Res)
 // AcqMethod::URIDone - A URI is finished                              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
+static void printHashStringList(HashStringList const * const list)
+{
+      for (HashStringList::const_iterator hash = list->begin(); hash != list->end(); ++hash)
+      {
+        // very old compatibility name for MD5Sum
+        if (hash->HashType() == "MD5Sum")
+           std::cout << "MD5-Hash: " << hash->HashValue() << "\n";
+        std::cout << hash->HashType() << "-Hash: " << hash->HashValue() << "\n";
+      }
+}
 void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
 {
    if (Queue == 0)
@@ -156,15 +189,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
    if (Res.LastModified != 0)
       std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified) << "\n";
 
-   if (Res.MD5Sum.empty() == false)
-      std::cout << "MD5-Hash: " << Res.MD5Sum << "\n"
-               << "MD5Sum-Hash: " << Res.MD5Sum << "\n";
-   if (Res.SHA1Sum.empty() == false)
-      std::cout << "SHA1-Hash: " << Res.SHA1Sum << "\n";
-   if (Res.SHA256Sum.empty() == false)
-      std::cout << "SHA256-Hash: " << Res.SHA256Sum << "\n";
-   if (Res.SHA512Sum.empty() == false)
-      std::cout << "SHA512-Hash: " << Res.SHA512Sum << "\n";
+   printHashStringList(&Res.Hashes);
+
    if (UsedMirror.empty() == false)
       std::cout << "UsedMirror: " << UsedMirror << "\n";
    if (Res.GPGVOutput.empty() == false)
@@ -192,15 +218,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
       if (Alt->LastModified != 0)
         std::cout << "Alt-Last-Modified: " << TimeRFC1123(Alt->LastModified) << "\n";
 
-      if (Alt->MD5Sum.empty() == false)
-        std::cout << "Alt-MD5-Hash: " << Alt->MD5Sum << "\n";
-      if (Alt->SHA1Sum.empty() == false)
-        std::cout << "Alt-SHA1-Hash: " << Alt->SHA1Sum << "\n";
-      if (Alt->SHA256Sum.empty() == false)
-        std::cout << "Alt-SHA256-Hash: " << Alt->SHA256Sum << "\n";
-      if (Alt->SHA512Sum.empty() == false)
-         std::cout << "Alt-SHA512-Hash: " << Alt->SHA512Sum << "\n";
-     
+      printHashStringList(&Alt->Hashes);
+
       if (Alt->IMSHit == true)
         std::cout << "Alt-IMS-Hit: true\n";
    }
@@ -347,6 +366,17 @@ int pkgAcqMethod::Run(bool Single)
               Tmp->LastModified = 0;
            Tmp->IndexFile = StringToBool(LookupTag(Message,"Index-File"),false);
            Tmp->FailIgnore = StringToBool(LookupTag(Message,"Fail-Ignore"),false);
+           Tmp->ExpectedHashes = HashStringList();
+           for (char const * const * t = HashString::SupportedHashes(); *t != NULL; ++t)
+           {
+              std::string tag = "Expected-";
+              tag.append(*t);
+              std::string const hash = LookupTag(Message, tag.c_str());
+              if (hash.empty() == false)
+                 Tmp->ExpectedHashes.push_back(HashString(*t, hash));
+           }
+            char *End;
+            Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
            Tmp->Next = 0;
            
            // Append it to the list
@@ -434,12 +464,9 @@ pkgAcqMethod::FetchResult::FetchResult() : LastModified(0),
 // ---------------------------------------------------------------------
 /* This hides the number of hashes we are supporting from the caller. 
    It just deals with the hash class. */
-void pkgAcqMethod::FetchResult::TakeHashes(Hashes &Hash)
+void pkgAcqMethod::FetchResult::TakeHashes(class Hashes &Hash)
 {
-   MD5Sum = Hash.MD5.Result();
-   SHA1Sum = Hash.SHA1.Result();
-   SHA256Sum = Hash.SHA256.Result();
-   SHA512Sum = Hash.SHA512.Result();
+   Hashes = Hash.GetHashStringList();
 }
                                                                        /*}}}*/
 void pkgAcqMethod::Dequeue() {                                         /*{{{*/
@@ -450,3 +477,5 @@ void pkgAcqMethod::Dequeue() {                                              /*{{{*/
    delete Tmp;
 }
                                                                        /*}}}*/
+
+pkgAcqMethod::~pkgAcqMethod() {}