]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-helper.cc
add GetSrvRecord helper to apt-pkg/contrib/srvrec.{cc,h}
[apt.git] / cmdline / apt-helper.cc
index e3652d1eeae7f97557f314a5246ff32f4f142e2f..aeeccf06d7a140563026c5ec34f2939cc7d5c2d6 100644 (file)
@@ -7,6 +7,7 @@
 // Include Files                                                       /*{{{*/
 #include <config.h>
 
+#include <apt-pkg/configuration.h>
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/init.h>
 
 #include <apt-private/acqprogress.h>
 #include <apt-private/private-output.h>
+#include <apt-private/private-download.h>
 #include <apt-private/private-cmndline.h>
+#include <apt-pkg/srvrec.h>
 
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-
-
+#include <iostream>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
-using namespace std;
 
-bool DoDownloadFile(CommandLine &CmdL)
+static bool DoDownloadFile(CommandLine &CmdL)
 {
    if (CmdL.FileSize() <= 2)
       return _error->Error(_("Must specify at least one pair url/filename"));
@@ -44,38 +41,51 @@ bool DoDownloadFile(CommandLine &CmdL)
    Fetcher.Setup(&Stat);
    std::string download_uri = CmdL.FileList[1];
    std::string targetfile = CmdL.FileList[2];
-   HashString hash;
+   std::string hash;
    if (CmdL.FileSize() > 3)
-      hash = HashString(CmdL.FileList[3]);
-   new pkgAcqFile(&Fetcher, download_uri, "", 0, "desc", "short-desc", 
+      hash = CmdL.FileList[3];
+   new pkgAcqFile(&Fetcher, download_uri, hash, 0, "desc", "short-desc", 
                   "dest-dir-ignored", targetfile);
    Fetcher.Run();
-   if (!FileExists(targetfile))
-   {
-      _error->Error(_("Download Failed"));
-      return false;
-   }
-   if(hash.empty() == false)
+   bool Failed = false;
+   if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true ||
+        FileExists(targetfile) == false)
+      return _error->Error(_("Download Failed"));
+   return true;
+}
+
+static bool DoSrvLookup(CommandLine &CmdL)
+{
+   if (CmdL.FileSize() < 1)
+      return _error->Error(_("Must specifc at least one srv record"));
+   
+   std::vector<SrvRec> srv_records;
+   for(int i=1; CmdL.FileList[i] != NULL; i++)
    {
-      if(hash.VerifyFile(targetfile) == false)
+      if(GetSrvRecords(CmdL.FileList[i], srv_records) == false)
+         _error->Warning(_("GetSrvRec failed for %s"), CmdL.FileList[i]);
+      for (std::vector<SrvRec>::const_iterator I = srv_records.begin();
+           I != srv_records.end(); ++I)
       {
-         _error->Error(_("HashSum Failed"));
-         Rename(targetfile, targetfile+".failed");
-         return false;
+         c1out << (*I).target.c_str() << " " 
+               << (*I).priority << " " 
+               << (*I).weight << " "
+               << (*I).port << " "
+               << std::endl;
       }
    }
    return true;
 }
 
-bool ShowHelp(CommandLine &CmdL)
+static bool ShowHelp(CommandLine &)
 {
-   ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
+   ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
            COMMON_ARCH,__DATE__,__TIME__);
 
    if (_config->FindB("version") == true)
      return true;
 
-   cout << 
+   std::cout <<
     _("Usage: apt-helper [options] command\n"
       "       apt-helper [options] download-file uri target-path\n"
       "\n"
@@ -93,6 +103,7 @@ int main(int argc,const char *argv[])                                        /*{{{*/
 {
    CommandLine::Dispatch Cmds[] = {{"help",&ShowHelp},
                                   {"download-file", &DoDownloadFile},
+                                  {"srv-lookup", &DoSrvLookup},
                                    {0,0}};
 
    std::vector<CommandLine::Args> Args = getCommandArgs(