blob: cdaf846ec202e29cab30b872504b5ebcc714f0f9 [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/*
Alexander Afanasyev08d18742018-03-15 16:31:28 -04003 * Copyright (c) 2014-2018, 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
20#include "mgmt/management-tool.hpp"
21#include "ndns-label.hpp"
22#include "logger.hpp"
23#include <boost/program_options.hpp>
24#include <boost/filesystem.hpp>
25#include <string>
26
27int
28main(int argc, char* argv[])
29{
30 using std::string;
31 using namespace ndn;
32 using namespace ndns;
33
Jiewen Tan870b29b2014-11-17 19:09:49 -080034 string zoneStr;
35 string db;
36 string rrLabelStr;
37 string rrTypeStr;
38 try {
39 namespace po = boost::program_options;
40 po::variables_map vm;
41
42 po::options_description options("Generic Options");
43 options.add_options()
44 ("help,h", "print help message")
45 ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
46 "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
47
48 po::options_description hidden("Hidden Options");
49 hidden.add_options()
50 ("zone", po::value<string>(&zoneStr), "host zone name")
51 ("label", po::value<string>(&rrLabelStr), "label of the resource record.")
52 ("type", po::value<string>(&rrTypeStr), "type of the resource record.")
53 ;
54
55 po::positional_options_description positional;
56 positional.add("zone", 1);
57 positional.add("label", 1);
58 positional.add("type", 1);
59
60 po::options_description cmdlineOptions;
61 cmdlineOptions.add(options).add(hidden);
62
63 // po::options_description configFileOptions;
64 // config_file_options.add(config).add(hidden);
65
66 po::parsed_options parsed =
67 po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run();
68
69 po::store(parsed, vm);
70 po::notify(vm);
71
72 if (vm.count("help")) {
73 std::cout << "Usage: ndns-remove-rr [-b db] zone label type" << std::endl
74 << std::endl;
75 std::cout << options << std::endl;
76 return 0;
77 }
78
79 if (vm.count("zone") == 0) {
80 std::cerr << "Error: zone, label, and type must be specified" << std::endl;
81 return 1;
82 }
83
84 if (vm.count("label") == 0) {
85 std::cerr << "Error: label and type must be specified" << std::endl;
86 return 1;
87 }
88
89 if (vm.count("type") == 0) {
90 std::cerr << "Error: type must be specified" << std::endl;
91 return 1;
92 }
93 }
94 catch (const std::exception& ex) {
95 std::cerr << "Parameter Error: " << ex.what() << std::endl;
96 return 1;
97 }
98
99 try {
100 Name zoneName(zoneStr);
101 Name label(rrLabelStr);
102 name::Component type(rrTypeStr);
103
Yumin Xia2c509c22017-02-09 14:37:36 -0800104 KeyChain keyChain;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800105 ndn::ndns::ManagementTool tool(db, keyChain);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800106 tool.removeRrSet(zoneName, label, type);
107
108 /// @todo Report how many records have been removed
109 // (or that the record was removed or record wasn't found)
110 }
111 catch (const std::exception& ex) {
112 std::cerr << "Error: " << ex.what() << std::endl;
113 return 1;
114 }
115}