summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/srvrec.cc10
-rw-r--r--apt-pkg/contrib/srvrec.h2
-rw-r--r--cmdline/apt-helper.cc9
-rw-r--r--methods/connect.cc18
4 files changed, 20 insertions, 19 deletions
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index 70247c2ae..1dcda8b54 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/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;
}
diff --git a/apt-pkg/contrib/srvrec.h b/apt-pkg/contrib/srvrec.h
index 79b318b48..9323623a5 100644
--- a/apt-pkg/contrib/srvrec.h
+++ b/apt-pkg/contrib/srvrec.h
@@ -3,7 +3,7 @@
/* ######################################################################
SRV record support
-
+
##################################################################### */
/*}}}*/
#ifndef SRVREC_H
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index 482e64dd1..d235ac315 100644
--- a/cmdline/apt-helper.cc
+++ b/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");
diff --git a/methods/connect.cc b/methods/connect.cc
index 8de4ad747..9e0f01ee3 100644
--- a/methods/connect.cc
+++ b/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;
}