Browse Source

cleanup

debian/1.8.y
Michael Vogt 7 years ago
parent
commit
cdeb54d462
  1. 10
      apt-pkg/contrib/srvrec.cc
  2. 2
      apt-pkg/contrib/srvrec.h
  3. 9
      cmdline/apt-helper.cc
  4. 18
      methods/connect.cc

10
apt-pkg/contrib/srvrec.cc

@ -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;
}

2
apt-pkg/contrib/srvrec.h

@ -3,7 +3,7 @@
/* ######################################################################
SRV record support
##################################################################### */
/*}}}*/
#ifndef SRVREC_H

9
cmdline/apt-helper.cc

@ -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");

18
methods/connect.cc

@ -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;
}

Loading…
Cancel
Save