]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-method.cc
merge patch from Daniel Hartwig to Show a error message if {,dist-}upgrade is used...
[apt.git] / apt-pkg / acquire-method.cc
index 2f29f793240f6462e24527795024f20cf38ad3fb..5bc1c159a9b968a3cd7b501cacc46799c3debee5 100644 (file)
@@ -15,6 +15,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
@@ -23,7 +25,6 @@
 #include <apt-pkg/hashes.h>
 
 #include <iostream>
 #include <apt-pkg/hashes.h>
 
 #include <iostream>
-#include <stdarg.h>
 #include <stdio.h>
 #include <sys/signal.h>
                                                                        /*}}}*/
 #include <stdio.h>
 #include <sys/signal.h>
                                                                        /*}}}*/
@@ -82,7 +83,7 @@ void pkgAcqMethod::Fail(bool Transient)
 void pkgAcqMethod::Fail(string Err,bool Transient)
 {
    // Strip out junk from the error messages
 void pkgAcqMethod::Fail(string Err,bool Transient)
 {
    // Strip out junk from the error messages
-   for (string::iterator I = Err.begin(); I != Err.end(); I++)
+   for (string::iterator I = Err.begin(); I != Err.end(); ++I)
    {
       if (*I == '\r') 
         *I = ' ';
    {
       if (*I == '\r') 
         *I = ' ';
@@ -94,12 +95,7 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
    {
       std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n"
                << "Message: " << Err << " " << IP << "\n";
    {
       std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n"
                << "Message: " << Err << " " << IP << "\n";
-      // Dequeue
-      FetchItem *Tmp = Queue;
-      Queue = Queue->Next;
-      delete Tmp;
-      if (Tmp == QueueBack)
-        QueueBack = Queue;
+      Dequeue();
    }
    else
       std::cout << "400 URI Failure\nURI: <UNKNOWN>\nMessage: " << Err << "\n";
    }
    else
       std::cout << "400 URI Failure\nURI: <UNKNOWN>\nMessage: " << Err << "\n";
@@ -167,6 +163,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
       std::cout << "SHA1-Hash: " << Res.SHA1Sum << "\n";
    if (Res.SHA256Sum.empty() == false)
       std::cout << "SHA256-Hash: " << Res.SHA256Sum << "\n";
       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";
    if (UsedMirror.empty() == false)
       std::cout << "UsedMirror: " << UsedMirror << "\n";
    if (Res.GPGVOutput.empty() == false)
    if (UsedMirror.empty() == false)
       std::cout << "UsedMirror: " << UsedMirror << "\n";
    if (Res.GPGVOutput.empty() == false)
@@ -200,19 +198,15 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
         std::cout << "Alt-SHA1-Hash: " << Alt->SHA1Sum << "\n";
       if (Alt->SHA256Sum.empty() == false)
         std::cout << "Alt-SHA256-Hash: " << Alt->SHA256Sum << "\n";
         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";
+     
       if (Alt->IMSHit == true)
         std::cout << "Alt-IMS-Hit: true\n";
    }
 
    std::cout << "\n" << std::flush;
       if (Alt->IMSHit == true)
         std::cout << "Alt-IMS-Hit: true\n";
    }
 
    std::cout << "\n" << std::flush;
-
-   // Dequeue
-   FetchItem *Tmp = Queue;
-   Queue = Queue->Next;
-   delete Tmp;
-   if (Tmp == QueueBack)
-      QueueBack = Queue;
+   Dequeue();
 }
                                                                        /*}}}*/
 // AcqMethod::MediaFail - Syncronous request for new media             /*{{{*/
 }
                                                                        /*}}}*/
 // AcqMethod::MediaFail - Syncronous request for new media             /*{{{*/
@@ -286,12 +280,12 @@ bool pkgAcqMethod::Configuration(string Message)
       I += Length + 1;
       
       for (; I < MsgEnd && *I == ' '; I++);
       I += Length + 1;
       
       for (; I < MsgEnd && *I == ' '; I++);
-      const char *Equals = I;
-      for (; Equals < MsgEnd && *Equals != '='; Equals++);
-      const char *End = Equals;
-      for (; End < MsgEnd && *End != '\n'; End++);
-      if (End == Equals)
+      const char *Equals = (const char*) memchr(I, '=', MsgEnd - I);
+      if (Equals == NULL)
         return false;
         return false;
+      const char *End = (const char*) memchr(Equals, '\n', MsgEnd - Equals);
+      if (End == NULL)
+        End = MsgEnd;
       
       Cnf.Set(DeQuoteString(string(I,Equals-I)),
              DeQuoteString(string(Equals+1,End-Equals-1)));
       
       Cnf.Set(DeQuoteString(string(I,Equals-I)),
              DeQuoteString(string(Equals+1,End-Equals-1)));
@@ -375,23 +369,34 @@ int pkgAcqMethod::Run(bool Single)
    return 0;
 }
                                                                        /*}}}*/
    return 0;
 }
                                                                        /*}}}*/
-// AcqMethod::Log - Send a log message                                 /*{{{*/
+// AcqMethod::PrintStatus - privately really send a log/status message /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // ---------------------------------------------------------------------
 /* */
-void pkgAcqMethod::Log(const char *Format,...)
+void pkgAcqMethod::PrintStatus(char const * const header, const char* Format,
+                              va_list &args) const
 {
    string CurrentURI = "<UNKNOWN>";
    if (Queue != 0)
       CurrentURI = Queue->Uri;
 {
    string CurrentURI = "<UNKNOWN>";
    if (Queue != 0)
       CurrentURI = Queue->Uri;
-   fprintf(stdout, "101 Log\nURI: %s\nUsedMirror: %s\nMessage: ",
-          UsedMirror.c_str(), CurrentURI.c_str());
-
+   if (UsedMirror.empty() == true)
+      fprintf(stdout, "%s\nURI: %s\nMessage: ",
+             header, CurrentURI.c_str());
+   else
+      fprintf(stdout, "%s\nURI: %s\nUsedMirror: %s\nMessage: ",
+             header, CurrentURI.c_str(), UsedMirror.c_str());
+   vfprintf(stdout,Format,args);
+   std::cout << "\n\n" << std::flush;
+}
+                                                                       /*}}}*/
+// AcqMethod::Log - Send a log message                                 /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::Log(const char *Format,...)
+{
    va_list args;
    va_start(args,Format);
    va_list args;
    va_start(args,Format);
-   vfprintf(stdout,Format,args);
+   PrintStatus("101 Log", Format, args);
    va_end(args);
    va_end(args);
-
-   std::cout << "\n\n" << std::flush;
 }
                                                                        /*}}}*/
 // AcqMethod::Status - Send a status message                           /*{{{*/
 }
                                                                        /*}}}*/
 // AcqMethod::Status - Send a status message                           /*{{{*/
@@ -399,46 +404,22 @@ void pkgAcqMethod::Log(const char *Format,...)
 /* */
 void pkgAcqMethod::Status(const char *Format,...)
 {
 /* */
 void pkgAcqMethod::Status(const char *Format,...)
 {
-   string CurrentURI = "<UNKNOWN>";
-   if (Queue != 0)
-      CurrentURI = Queue->Uri;
-   fprintf(stdout, "102 Status\nURI: %s\nUsedMirror: %s\nMessage: ",
-          UsedMirror.c_str(), CurrentURI.c_str());
-
    va_list args;
    va_start(args,Format);
    va_list args;
    va_start(args,Format);
-   vfprintf(stdout,Format,args);
+   PrintStatus("102 Status", Format, args);
    va_end(args);
    va_end(args);
-
-   std::cout << "\n\n" << std::flush;
 }
                                                                        /*}}}*/
 // AcqMethod::Redirect - Send a redirect message                       /*{{{*/
 // ---------------------------------------------------------------------
 }
                                                                        /*}}}*/
 // AcqMethod::Redirect - Send a redirect message                       /*{{{*/
 // ---------------------------------------------------------------------
-/* This method sends the redirect message and also manipulates the queue
  to keep the pipeline synchronized. */
+/* This method sends the redirect message and dequeues the item as
* the worker will enqueue again later on to the right queue */
 void pkgAcqMethod::Redirect(const string &NewURI)
 {
 void pkgAcqMethod::Redirect(const string &NewURI)
 {
-   std::cout << "103 Redirect\nURI: ";
-   if (Queue != 0)
-      std::cout << Queue->Uri << "\n";
-   else
-      std::cout << "<UNKNOWN>\n";
-   std::cout << "New-URI: " << NewURI << "\n"
+   std::cout << "103 Redirect\nURI: " << Queue->Uri << "\n"
+            << "New-URI: " << NewURI << "\n"
             << "\n" << std::flush;
             << "\n" << std::flush;
-
-   // Change the URI for the request.
-   Queue->Uri = NewURI;
-
-   /* To keep the pipeline synchronized, move the current request to
-      the end of the queue, past the end of the current pipeline. */
-   FetchItem *I;
-   for (I = Queue; I->Next != 0; I = I->Next) ;
-   I->Next = Queue;
-   Queue = Queue->Next;
-   I->Next->Next = 0;
-   if (QueueBack == 0)
-      QueueBack = I->Next;
+   Dequeue();
 }
                                                                         /*}}}*/
 // AcqMethod::FetchResult::FetchResult - Constructor                   /*{{{*/
 }
                                                                         /*}}}*/
 // AcqMethod::FetchResult::FetchResult - Constructor                   /*{{{*/
@@ -458,5 +439,14 @@ void pkgAcqMethod::FetchResult::TakeHashes(Hashes &Hash)
    MD5Sum = Hash.MD5.Result();
    SHA1Sum = Hash.SHA1.Result();
    SHA256Sum = Hash.SHA256.Result();
    MD5Sum = Hash.MD5.Result();
    SHA1Sum = Hash.SHA1.Result();
    SHA256Sum = Hash.SHA256.Result();
+   SHA512Sum = Hash.SHA512.Result();
+}
+                                                                       /*}}}*/
+void pkgAcqMethod::Dequeue() {                                         /*{{{*/
+   FetchItem const * const Tmp = Queue;
+   Queue = Queue->Next;
+   if (Tmp == QueueBack)
+      QueueBack = Queue;
+   delete Tmp;
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/