From f106fecc1d7d0250d1d76c2ba837dc0c870c5fff Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 20 May 2014 13:15:51 +0200 Subject: add GetSrvRecord helper to apt-pkg/contrib/srvrec.{cc,h} --- cmdline/apt-helper.cc | 25 +++++++++++++++++++++++++ cmdline/makefile | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc index 2c1107d90..aeeccf06d 100644 --- a/cmdline/apt-helper.cc +++ b/cmdline/apt-helper.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,29 @@ static bool DoDownloadFile(CommandLine &CmdL) return true; } +static bool DoSrvLookup(CommandLine &CmdL) +{ + if (CmdL.FileSize() < 1) + return _error->Error(_("Must specifc at least one srv record")); + + std::vector srv_records; + for(int i=1; CmdL.FileList[i] != NULL; i++) + { + if(GetSrvRecords(CmdL.FileList[i], srv_records) == false) + _error->Warning(_("GetSrvRec failed for %s"), CmdL.FileList[i]); + for (std::vector::const_iterator I = srv_records.begin(); + I != srv_records.end(); ++I) + { + c1out << (*I).target.c_str() << " " + << (*I).priority << " " + << (*I).weight << " " + << (*I).port << " " + << std::endl; + } + } + return true; +} + static bool ShowHelp(CommandLine &) { ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, @@ -79,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 Args = getCommandArgs( diff --git a/cmdline/makefile b/cmdline/makefile index c4a249cd6..a24738e63 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -49,7 +49,7 @@ include $(PROGRAM_H) # The apt-helper PROGRAM=apt-helper -SLIBS = -lapt-pkg -lapt-private $(INTLLIBS) +SLIBS = -lapt-pkg -lapt-private $(INTLLIBS) -lresolv LIB_MAKES = apt-pkg/makefile SOURCE = apt-helper.cc include $(PROGRAM_H) -- cgit v1.2.3 From cdeb54d4626ddc841d8898a8283084a8de3b25ee Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 18 Aug 2015 15:41:02 +0200 Subject: cleanup --- cmdline/apt-helper.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cmdline') 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 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::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"); -- cgit v1.2.3