blob: c281148ed92baa799d6e25191f2523acd20ee877 [file] [log] [blame]
Junxiao Shi3b081542017-07-04 18:37:34 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa997d292017-08-24 20:16:59 -04002/*
Davide Pesavento97e33022019-02-14 16:00:50 -05003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi3b081542017-07-04 18:37:34 +00004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "program.hpp"
Junxiao Shi3b081542017-07-04 18:37:34 +000027#include "core/version.hpp"
Davide Pesaventoa997d292017-08-24 20:16:59 -040028
29#include <iostream>
Junxiao Shi3b081542017-07-04 18:37:34 +000030#include <unistd.h>
31
Davide Pesavento97e33022019-02-14 16:00:50 -050032#include <boost/exception/diagnostic_information.hpp>
33
Junxiao Shi3b081542017-07-04 18:37:34 +000034namespace ndn {
35namespace tools {
36namespace autoconfig_server {
37
38static void
39usage(const char* programName)
40{
Davide Pesavento59769b12017-11-12 23:52:06 -050041 std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n"
42 << "\n"
43 << "Options:\n"
Junxiao Shi3b081542017-07-04 18:37:34 +000044 << " -h - print usage and exit\n"
45 << " -V - print version number and exit\n"
Davide Pesavento97e33022019-02-14 16:00:50 -050046 << " -p prefix - a local prefix of the hub\n"
47 << " hub-face - a FaceUri to reach the hub\n";
Junxiao Shi3b081542017-07-04 18:37:34 +000048}
49
Davide Pesavento59769b12017-11-12 23:52:06 -050050static int
Junxiao Shi3b081542017-07-04 18:37:34 +000051main(int argc, char** argv)
52{
53 Options options;
54
55 int opt = -1;
56 while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
57 switch (opt) {
58 case 'h':
59 usage(argv[0]);
60 return 0;
61 case 'V':
62 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
63 return 0;
64 case 'p':
65 options.routablePrefixes.emplace_back(::optarg);
66 break;
67 default:
68 usage(argv[0]);
69 return 2;
70 }
71 }
72
73 if (argc != ::optind + 1) {
74 usage(argv[0]);
75 return 2;
76 }
77
78 if (!options.hubFaceUri.parse(argv[::optind])) {
Davide Pesavento97e33022019-02-14 16:00:50 -050079 std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl;
Junxiao Shi3b081542017-07-04 18:37:34 +000080 return 2;
81 }
82
83 try {
84 Face face;
85 KeyChain keyChain;
86 Program program(options, face, keyChain);
87 program.run();
88 }
89 catch (const std::exception& e) {
Davide Pesavento97e33022019-02-14 16:00:50 -050090 std::cerr << "ERROR: " << boost::diagnostic_information(e);
Junxiao Shi3b081542017-07-04 18:37:34 +000091 return 1;
92 }
93 return 0;
94}
95
96} // namespace autoconfig_server
97} // namespace tools
98} // namespace ndn
99
100int
101main(int argc, char** argv)
102{
103 return ndn::tools::autoconfig_server::main(argc, argv);
104}