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 | /* |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 20 | #include "logger.hpp" |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 21 | #include "ndns-label.hpp" |
| 22 | #include "mgmt/management-tool.hpp" |
| 23 | #include "util/util.hpp" |
| 24 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 25 | #include <boost/program_options.hpp> |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 26 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 27 | #include <iostream> |
| 28 | |
| 29 | int |
| 30 | main(int argc, char* argv[]) |
| 31 | { |
| 32 | using std::string; |
| 33 | using namespace ndn; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 34 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 35 | string zoneStr; |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 36 | string db = ndns::getDefaultDatabaseFile(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 37 | bool printRaw = false; |
| 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() |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 44 | ("help,h", "print this help message and exit") |
| 45 | ("db,b", po::value<std::string>(&db)->default_value(db), "path to NDNS database file") |
| 46 | ; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 47 | |
| 48 | po::options_description config("Output Options"); |
| 49 | config.add_options() |
| 50 | ("printRaw,p", "Set to print raw data") |
| 51 | ; |
| 52 | |
| 53 | options.add(config); |
| 54 | |
| 55 | po::options_description hidden("Hidden Options"); |
| 56 | hidden.add_options() |
| 57 | ("zone", po::value<string>(&zoneStr), "zone name to investigate") |
| 58 | ; |
| 59 | |
| 60 | po::positional_options_description positional; |
| 61 | positional.add("zone", 1); |
| 62 | |
| 63 | po::options_description cmdlineOptions; |
| 64 | cmdlineOptions.add(options).add(hidden); |
| 65 | |
| 66 | // po::options_description config_file_options; |
| 67 | // config_file_options.add(config).add(hidden); |
| 68 | |
| 69 | po::parsed_options parsed = |
| 70 | po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run(); |
| 71 | |
| 72 | po::store(parsed, vm); |
| 73 | po::notify(vm); |
| 74 | |
| 75 | if (vm.count("help")) { |
| 76 | std::cout << "Usage: ndns-list-zone zone [-b db] [-p printRaw]" << std::endl |
| 77 | << std::endl; |
| 78 | std::cout << options << std::endl; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | if (vm.count("zone") == 0) { |
| 83 | std::cerr << "Error: zone must be specified" << std::endl; |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | if (vm.count("printRaw") != 0) { |
| 88 | printRaw = true; |
| 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 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 99 | KeyChain keyChain; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 100 | ndn::ndns::ManagementTool tool(db, keyChain); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 101 | tool.listZone(zoneName, std::cout, printRaw); |
| 102 | } |
| 103 | catch (const std::exception& ex) { |
| 104 | std::cerr << "Error: " << ex.what() << std::endl; |
| 105 | return 1; |
| 106 | } |
| 107 | } |