blob: 9268bacd1d22d74d3b6f3320f836edb01b4437a5 [file] [log] [blame]
shockjiang99ad3892014-08-03 14:56:13 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
shockjiang85312022014-07-27 23:22:16 -07004 *
shockjiang99ad3892014-08-03 14:56:13 -07005 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
shockjiang85312022014-07-27 23:22:16 -07007 *
shockjiang99ad3892014-08-03 14:56:13 -07008 * 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/>.
shockjiang85312022014-07-27 23:22:16 -070018 */
19
shockjiang85312022014-07-27 23:22:16 -070020#include "app/name-server.hpp"
shockjiang99ad3892014-08-03 14:56:13 -070021#include "boost/program_options.hpp"
22#include "boost/filesystem.hpp"
shockjiang85312022014-07-27 23:22:16 -070023
24int main(int argc, char * argv[])
25{
shockjiang99ad3892014-08-03 14:56:13 -070026 string route = "/";
27 string zoneName = "/";
28 string dbfile="src/db/ndns-local.db";
29 string hint = "/";
shockjiang85312022014-07-27 23:22:16 -070030
shockjiang99ad3892014-08-03 14:56:13 -070031 try{
32
33 namespace po = boost::program_options;
34 po::variables_map vm;
35
36
37 po::options_description generic("Generic Options");
38 generic.add_options()
39 ("help,h", "print help message")
40 ;
41
42
43 po::options_description config("Configuration");
44 config.add_options()
45 ("dbfile,f", po::value<std::string>(&dbfile), "set database file. default: src/db/ndns-local.db")
46 ("hint,H", po::value<std::string>(&hint), "set Forwarding Hint, which is disable by default")
47 ;
48
49
50 po::options_description hidden("Hidden Options");
51 hidden.add_options()
52 ("prefix,p", po::value<string>(&route), "routable prefix of the server")
53 ("zone,z", po::value<string>(&zoneName), "name of the zone")
54 ;
55
56 po::positional_options_description postion;
57 postion.add("prefix", 1);
58 postion.add("zone", 1);
59
60
61
62
63 po::options_description cmdline_options;
64 cmdline_options.add(generic).add(config).add(hidden);
65
66 po::options_description config_file_options;
67 config_file_options.add(config).add(hidden);
68
69 po::options_description visible("Allowed options");
70 visible.add(generic).add(config);
71
72
73 po::parsed_options parsed = po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run();
74
75
76 po::store(parsed, vm);
77 po::notify(vm);
78
79 if (vm.count("help"))
80 {
81 cout<<"E.g: name-server-daemon /name/of/zone /routable/prefix/announced"<<endl;
82 cout<<visible<<endl;
83 return 0;
84 }
85
86 cout<<"zone="<<zoneName<<" routablePrefix="<<route<<" dbfile="<<dbfile<<endl;
87 }
88 catch(const std::exception& ex)
shockjiang85312022014-07-27 23:22:16 -070089 {
shockjiang99ad3892014-08-03 14:56:13 -070090 cout << "Parameter Error: " << ex.what() << endl;
91 return 0;
92 }
93 catch(...)
94 {
95 cout << "Parameter Unknown error" << endl;
96 return 0;
shockjiang85312022014-07-27 23:22:16 -070097 }
98
shockjiang99ad3892014-08-03 14:56:13 -070099
100
101 ndn::ndns::NameServer server(argv[0], route.c_str(), zoneName.c_str(), dbfile);
102
103 if (hint != "/") {
104 server.setEnableForwardingHint(1);
105 server.setForwardingHint(Name(hint));
106 }
107
108
shockjiang85312022014-07-27 23:22:16 -0700109 server.run();
110
111 cout<<"the server ends with hasError="<<server.hasError()<<endl;
112
113 if (server.hasError()){
114 return 0;
115 } else {
116 return 1;
117 }
118
119}
120