blob: 1077a8d1abc880a68ecc37b55eeaae5ed882e0c6 [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/*
Junxiao Shi3b081542017-07-04 18:37:34 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
4 * 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"
27#include "core/extended-error-message.hpp"
28#include "core/version.hpp"
Davide Pesaventoa997d292017-08-24 20:16:59 -040029
30#include <iostream>
Junxiao Shi3b081542017-07-04 18:37:34 +000031#include <unistd.h>
32
33namespace ndn {
34namespace tools {
35namespace autoconfig_server {
36
37static void
38usage(const char* programName)
39{
Davide Pesavento59769b12017-11-12 23:52:06 -050040 std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n"
41 << "\n"
42 << "Options:\n"
Junxiao Shi3b081542017-07-04 18:37:34 +000043 << " -h - print usage and exit\n"
44 << " -V - print version number and exit\n"
45 << " -p prefix - a local prefix of the HUB\n"
Davide Pesavento59769b12017-11-12 23:52:06 -050046 << " hub-face - a FaceUri to reach the HUB\n";
Junxiao Shi3b081542017-07-04 18:37:34 +000047}
48
Davide Pesavento59769b12017-11-12 23:52:06 -050049static int
Junxiao Shi3b081542017-07-04 18:37:34 +000050main(int argc, char** argv)
51{
52 Options options;
53
54 int opt = -1;
55 while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
56 switch (opt) {
57 case 'h':
58 usage(argv[0]);
59 return 0;
60 case 'V':
61 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
62 return 0;
63 case 'p':
64 options.routablePrefixes.emplace_back(::optarg);
65 break;
66 default:
67 usage(argv[0]);
68 return 2;
69 }
70 }
71
72 if (argc != ::optind + 1) {
73 usage(argv[0]);
74 return 2;
75 }
76
77 if (!options.hubFaceUri.parse(argv[::optind])) {
Davide Pesavento59769b12017-11-12 23:52:06 -050078 std::cerr << "ERROR: cannot parse HUB FaceUri" << std::endl;
Junxiao Shi3b081542017-07-04 18:37:34 +000079 return 2;
80 }
81
82 try {
83 Face face;
84 KeyChain keyChain;
85 Program program(options, face, keyChain);
86 program.run();
87 }
88 catch (const std::exception& e) {
89 std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
90 return 1;
91 }
92 return 0;
93}
94
95} // namespace autoconfig_server
96} // namespace tools
97} // namespace ndn
98
99int
100main(int argc, char** argv)
101{
102 return ndn::tools::autoconfig_server::main(argc, argv);
103}