blob: d6159f659801ef64b6eeb92c3759df7bd6ee5c21 [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
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
34 ndn::ndns::log::init();
35 string zoneStr;
36 string db;
37 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()
45 ("help,h", "print help message")
46 ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
47 "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
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 positional;
57 positional.add("zone", 1);
58 positional.add("label", 1);
59 positional.add("type", 1);
60
61 po::options_description cmdlineOptions;
62 cmdlineOptions.add(options).add(hidden);
63
64 // po::options_description configFileOptions;
65 // config_file_options.add(config).add(hidden);
66
67 po::parsed_options parsed =
68 po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run();
69
70 po::store(parsed, vm);
71 po::notify(vm);
72
73 if (vm.count("help")) {
74 std::cout << "Usage: ndns-remove-rr [-b db] zone label type" << std::endl
75 << std::endl;
76 std::cout << options << std::endl;
77 return 0;
78 }
79
80 if (vm.count("zone") == 0) {
81 std::cerr << "Error: zone, label, and type must be specified" << std::endl;
82 return 1;
83 }
84
85 if (vm.count("label") == 0) {
86 std::cerr << "Error: label and type must be specified" << std::endl;
87 return 1;
88 }
89
90 if (vm.count("type") == 0) {
91 std::cerr << "Error: type must be specified" << std::endl;
92 return 1;
93 }
94 }
95 catch (const std::exception& ex) {
96 std::cerr << "Parameter Error: " << ex.what() << std::endl;
97 return 1;
98 }
99
100 try {
101 Name zoneName(zoneStr);
102 Name label(rrLabelStr);
103 name::Component type(rrTypeStr);
104
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800105 ndn::KeyChain keyChain;
106 ndn::ndns::ManagementTool tool(db, keyChain);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800107 tool.removeRrSet(zoneName, label, type);
108
109 /// @todo Report how many records have been removed
110 // (or that the record was removed or record wasn't found)
111 }
112 catch (const std::exception& ex) {
113 std::cerr << "Error: " << ex.what() << std::endl;
114 return 1;
115 }
116}