blob: 4fc2066e0f8088d5ba1a1efc4a85938b228e06f4 [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
27
28// @todo combine this command with ndns-add-rr
29int
30main(int argc, char* argv[])
31{
32 using std::string;
33 using namespace ndn;
34 using namespace ndns;
35
36 ndn::ndns::log::init();
37 int ttlInt = -1;
38 string zoneStr;
39 string dskStr;
40 string db;
41 string file = "-";
42 try {
43 namespace po = boost::program_options;
44 po::variables_map vm;
45
46 po::options_description options("Generic Options");
47 options.add_options()
48 ("help,h", "print help message")
49 ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
50 "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
51 ;
52
53 po::options_description config("Record Options");
54 config.add_options()
55 ("file,f", po::value<string>(&file), "Path to the data. Default is stdin(-)")
56 ("dsk,d", po::value<std::string>(&dskStr), "Set the name of DSK's certificate. "
57 "Default: use default DSK and its default certificate")
58 ("ttl,a", po::value<int>(&ttlInt), "Set ttl of the rrset. Default: 3600 seconds")
59 ;
60
61 options.add(config);
62
63 po::options_description hidden("Hidden Options");
64 hidden.add_options()
65 ("zone", po::value<string>(&zoneStr), "host zone name")
66 ;
67
68 po::positional_options_description postion;
69 postion.add("zone", 1);
70 postion.add("file", 1);
71
72 po::options_description cmdlineOptions;
73 cmdlineOptions.add(options).add(hidden);
74
75 // po::options_description config_file_options;
76 // config_file_options.add(config).add(hidden);
77
78 po::parsed_options parsed =
79 po::command_line_parser(argc, argv).options(cmdlineOptions).positional(postion).run();
80
81 po::store(parsed, vm);
82 po::notify(vm);
83
84 if (vm.count("help")) {
85 std::cout << "Usage: ndns-add-rr-from-file [-b db] zone [-f file] [-d dskCert] [-a ttl]"
86 " [file]" << std::endl
87 << std::endl;
88 std::cout << options << std::endl;
89 return 0;
90 }
91
92 if (vm.count("zone") == 0) {
93 std::cerr << "Error: zone must be specified" << std::endl;
94 return 1;
95 }
96 }
97 catch (const std::exception& ex) {
98 std::cerr << "Parameter Error: " << ex.what() << std::endl;
99 return 1;
100 }
101
102 try {
103 Name zoneName(zoneStr);
104 Name dskName(dskStr);
105 time::seconds ttl;
106 if (ttlInt == -1)
107 ttl = ndns::DEFAULT_CACHE_TTL;
108 else
109 ttl = time::seconds(ttlInt);
110
111 ndn::ndns::ManagementTool tool(db);
112 tool.addRrSet(zoneName, file, ttl, dskName);
113 }
114 catch (const std::exception& ex) {
115 std::cerr << "Error: " << ex.what() << std::endl;
116 return 1;
117 }
118}