]> git.saurik.com Git - apt.git/commitdiff
cleanup
authorMichael Vogt <mvo@debian.org>
Tue, 18 Aug 2015 13:41:02 +0000 (15:41 +0200)
committerMichael Vogt <mvo@debian.org>
Tue, 18 Aug 2015 13:41:02 +0000 (15:41 +0200)
apt-pkg/contrib/srvrec.cc
apt-pkg/contrib/srvrec.h
cmdline/apt-helper.cc
methods/connect.cc

index 70247c2aec9e286355dff23526d19928e5a53248..1dcda8b5490f5701f9f45032cc37be1303897604 100644 (file)
@@ -64,7 +64,7 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
       SrvRec rec;
       u_int16_t type, klass, priority, weight, port, dlen;
       char buf[MAXDNAME];
-      
+
       compressed_name_len = dn_skipname(pt, answer+answer_len);
       if (compressed_name_len < 0)
          return _error->Warning("dn_skipname failed (2): %i",
@@ -74,15 +74,15 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
          return _error->Warning("packet too short");
 
       // extract the data out of the result buffer
-      #define extract_u16(target, p) target = *p++ << 8; target |= *p++; 
+      #define extract_u16(target, p) target = *p++ << 8; target |= *p++;
 
       extract_u16(type, pt);
       if(type != T_SRV)
-         return _error->Warning("Unexpected type excepted %x != %x", 
+         return _error->Warning("Unexpected type excepted %x != %x",
                                 T_SRV, type);
       extract_u16(klass, pt);
       if(klass != C_IN)
-         return _error->Warning("Unexpected class excepted %x != %x", 
+         return _error->Warning("Unexpected class excepted %x != %x",
                                 C_IN, klass);
       pt += 4;  // ttl
       extract_u16(dlen, pt);
@@ -135,7 +135,7 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
       I->random_number_range_max = max;
    }
 
-   // now shuffle 
+   // FIXME: now shuffle 
 
    return true;
 }
index 79b318b48e23c0657b308fe8edfa179934a086ec..9323623a50a102d9f7c035952a0fb884cdea1381 100644 (file)
@@ -3,7 +3,7 @@
 /* ######################################################################
 
    SRV record support
-  
+
    ##################################################################### */
                                                                        /*}}}*/
 #ifndef SRVREC_H
index 482e64dd15cff48980187cfcee2d8e33481ca866..d235ac315f069e14c1d6c16e6edcadaad181a003 100644 (file)
@@ -86,8 +86,9 @@ static bool DoSrvLookup(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 1)
       return _error->Error(_("Must specifc at least one srv record"));
-   
+
    std::vector<SrvRec> srv_records;
+   c1out << "# target priority weight port" << std::endl;
    for(int i=1; CmdL.FileList[i] != NULL; i++)
    {
       if(GetSrvRecords(CmdL.FileList[i], srv_records) == false)
@@ -95,13 +96,14 @@ static bool DoSrvLookup(CommandLine &CmdL)
       for (std::vector<SrvRec>::const_iterator I = srv_records.begin();
            I != srv_records.end(); ++I)
       {
-         c1out << (*I).target.c_str() << " " 
-               << (*I).priority << " " 
+         c1out << (*I).target.c_str() << " "
+               << (*I).priority << " "
                << (*I).weight << " "
                << (*I).port << " "
                << std::endl;
       }
    }
+
    return true;
 }
 
@@ -120,6 +122,7 @@ static bool ShowHelp(CommandLine &)
       "\n"
       "Commands:\n"
       "   download-file - download the given uri to the target-path\n"
+      "   srv-lookup - lookup a SRV record (e.g. _http._tcp.ftp.debian.org)\n"
       "   auto-detect-proxy - detect proxy using apt.conf\n"
       "\n"
       "                       This APT helper has Super Meep Powers.\n");
index 8de4ad74799d29715bee12d8e97ad670d20b7e2b..9e0f01ee3478926426f969df1e44df54d74bfc62 100644 (file)
@@ -136,7 +136,7 @@ static bool DoConnect(struct addrinfo *Addr,std::string Host,
                                                                        /*}}}*/
 
 // Connect to a given Hostname 
-bool ConnectAfterSrvRecords(std::string Host,int Port,const char *Service,
+bool ConnectToHostname(std::string Host,int Port,const char *Service,
                             int DefPort,int &Fd,
                             unsigned long TimeOut,pkgAcqMethod *Owner)
 {
@@ -261,36 +261,34 @@ bool ConnectAfterSrvRecords(std::string Host,int Port,const char *Service,
                                                                        /*}}}*/
 // Connect - Connect to a server                                       /*{{{*/
 // ---------------------------------------------------------------------
-/* Performs a connection to the server */
+/* Performs a connection to the server (including SRV record lookup) */
 bool Connect(std::string Host,int Port,const char *Service,
                             int DefPort,int &Fd,
                             unsigned long TimeOut,pkgAcqMethod *Owner)
 {
-#if 0
    if (_error->PendingError() == true)
       return false;
-#endif
 
    if(LastHost != Host || LastPort != Port)
    {
       SrvRecords.clear();
       bool res = GetSrvRecords(Host, DefPort, SrvRecords);
    }
+   // we have no SrvRecords for this host, connect right away
    if(SrvRecords.size() == 0)
-      return ConnectAfterSrvRecords(Host, Port, Service, DefPort, Fd, 
+      return ConnectToHostname(Host, Port, Service, DefPort, Fd, 
                                     TimeOut, Owner);
 
-   bool connected = false;
+   // try to connect in the priority order of the srv records
    while(SrvRecords.size() > 0)
    {
       Host = SrvRecords[0].target;
-      connected = ConnectAfterSrvRecords(Host, Port, Service, DefPort, Fd, 
-                                         TimeOut, Owner);
-      if(connected == true)
+      if(ConnectToHostname(Host, Port, Service, DefPort, Fd, TimeOut, Owner))
          return true;
 
       // we couldn't connect to this one, use the next
       SrvRecords.erase(SrvRecords.begin());
-   } 
+   }
+
    return false;
 }