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",
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);
I->random_number_range_max = max;
}
- // now shuffle
+ // FIXME: now shuffle
return true;
}
{
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)
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;
}
"\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");
/*}}}*/
// 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)
{
/*}}}*/
// 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;
}