Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 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 | #include <iostream> |
| 27 | |
| 28 | int |
| 29 | main(int argc, char* argv[]) |
| 30 | { |
| 31 | using std::string; |
| 32 | using namespace ndn; |
| 33 | using namespace ndns; |
| 34 | |
| 35 | ndn::ndns::log::init(); |
| 36 | string zoneStr; |
| 37 | string db; |
| 38 | bool printRaw = false; |
| 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 config("Output Options"); |
| 50 | config.add_options() |
| 51 | ("printRaw,p", "Set to print raw data") |
| 52 | ; |
| 53 | |
| 54 | options.add(config); |
| 55 | |
| 56 | po::options_description hidden("Hidden Options"); |
| 57 | hidden.add_options() |
| 58 | ("zone", po::value<string>(&zoneStr), "zone name to investigate") |
| 59 | ; |
| 60 | |
| 61 | po::positional_options_description positional; |
| 62 | positional.add("zone", 1); |
| 63 | |
| 64 | po::options_description cmdlineOptions; |
| 65 | cmdlineOptions.add(options).add(hidden); |
| 66 | |
| 67 | // po::options_description config_file_options; |
| 68 | // config_file_options.add(config).add(hidden); |
| 69 | |
| 70 | po::parsed_options parsed = |
| 71 | po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run(); |
| 72 | |
| 73 | po::store(parsed, vm); |
| 74 | po::notify(vm); |
| 75 | |
| 76 | if (vm.count("help")) { |
| 77 | std::cout << "Usage: ndns-list-zone zone [-b db] [-p printRaw]" << std::endl |
| 78 | << std::endl; |
| 79 | std::cout << options << std::endl; |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | if (vm.count("zone") == 0) { |
| 84 | std::cerr << "Error: zone must be specified" << std::endl; |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | if (vm.count("printRaw") != 0) { |
| 89 | printRaw = true; |
| 90 | } |
| 91 | } |
| 92 | catch (const std::exception& ex) { |
| 93 | std::cerr << "Parameter Error: " << ex.what() << std::endl; |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | try { |
| 98 | Name zoneName(zoneStr); |
| 99 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 100 | KeyChain keyChain; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 101 | ndn::ndns::ManagementTool tool(db, keyChain); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 102 | tool.listZone(zoneName, std::cout, printRaw); |
| 103 | } |
| 104 | catch (const std::exception& ex) { |
| 105 | std::cerr << "Error: " << ex.what() << std::endl; |
| 106 | return 1; |
| 107 | } |
| 108 | } |