blob: dc40c37e02b3f36a548c68cdef74c40f20171b71 [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Davide Pesaventod01c1a42019-01-21 21:42:45 -05003 * Copyright (c) 2014-2019, Regents of the University of California.
Jiewen Tan870b29b2014-11-17 19:09:49 -08004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Jiewen Tan870b29b2014-11-17 19:09:49 -080020#include "logger.hpp"
Davide Pesaventod01c1a42019-01-21 21:42:45 -050021#include "ndns-label.hpp"
22#include "mgmt/management-tool.hpp"
23#include "util/util.hpp"
24
Jiewen Tan870b29b2014-11-17 19:09:49 -080025#include <boost/program_options.hpp>
26#include <boost/filesystem.hpp>
27#include <string>
28
29int
30main(int argc, char* argv[])
31{
32 using std::string;
33 using namespace ndn;
Jiewen Tan870b29b2014-11-17 19:09:49 -080034
Jiewen Tan870b29b2014-11-17 19:09:49 -080035 string zoneStr;
Davide Pesaventod01c1a42019-01-21 21:42:45 -050036 string db = ndns::getDefaultDatabaseFile();
Jiewen Tan870b29b2014-11-17 19:09:49 -080037 string rrLabelStr;
38 string rrTypeStr;
39 try {
40 namespace po = boost::program_options;
41 po::variables_map vm;
42
43 po::options_description options("Generic Options");
44 options.add_options()
Davide Pesaventod01c1a42019-01-21 21:42:45 -050045 ("help,h", "print this help message and exit")
46 ("db,b", po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
Jiewen Tan870b29b2014-11-17 19:09:49 -080047 ;
48
49 po::options_description hidden("Hidden Options");
50 hidden.add_options()
51 ("zone", po::value<string>(&zoneStr), "host zone name")
52 ("label", po::value<string>(&rrLabelStr), "label of the resource record.")
53 ("type", po::value<string>(&rrTypeStr), "type of the resource record.")
54 ;
55
56 po::positional_options_description postion;
57 postion.add("zone", 1);
58 postion.add("label", 1);
59 postion.add("type", 1);
60
61 po::options_description cmdline_options;
62 cmdline_options.add(options).add(hidden);
63
64 po::parsed_options parsed =
65 po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run();
66
67 po::store(parsed, vm);
68 po::notify(vm);
69
70 if (vm.count("help")) {
71 std::cout << "Usage: ndns-get-rr zone label type [-b db]" << std::endl;
72 std::cout << options << std::endl;
73 return 0;
74 }
75
76 if (vm.count("zone") == 0) {
77 std::cerr << "Error: zone must be specified" << std::endl;
78 return 1;
79 }
80
81 if (vm.count("label") == 0) {
82 std::cerr << "Error: label must be specified" << std::endl;
83 return 1;
84 }
85
86 if (vm.count("type") == 0) {
87 std::cerr << "Error: type must be specified" << std::endl;
88 return 1;
89 }
90 }
91 catch (const std::exception& ex) {
92 std::cerr << "Parameter Error: " << ex.what() << std::endl;
93 return 1;
94 }
95
96 try {
97 Name zoneName(zoneStr);
98 Name label(rrLabelStr);
99 name::Component type(rrTypeStr);
100
Yumin Xia2c509c22017-02-09 14:37:36 -0800101 KeyChain keyChain;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800102 ndn::ndns::ManagementTool tool(db, keyChain);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800103 tool.getRrSet(zoneName, label, type, std::cout);
104 }
105 catch (const std::exception& ex) {
106 std::cerr << "Error: " << ex.what() << std::endl;
107 return 1;
108 }
109}