Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 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" |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 27 | #include "core/version.hpp" |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 28 | |
| 29 | #include <iostream> |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 30 | #include <unistd.h> |
| 31 | |
Davide Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame^] | 32 | #include <boost/exception/diagnostic_information.hpp> |
| 33 | |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 34 | namespace ndn { |
| 35 | namespace tools { |
| 36 | namespace autoconfig_server { |
| 37 | |
| 38 | static void |
| 39 | usage(const char* programName) |
| 40 | { |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 41 | std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n" |
| 42 | << "\n" |
| 43 | << "Options:\n" |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 44 | << " -h - print usage and exit\n" |
| 45 | << " -V - print version number and exit\n" |
Davide Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame^] | 46 | << " -p prefix - a local prefix of the hub\n" |
| 47 | << " hub-face - a FaceUri to reach the hub\n"; |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 50 | static int |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 51 | main(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 Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame^] | 79 | std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl; |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 80 | 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 Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame^] | 90 | std::cerr << "ERROR: " << boost::diagnostic_information(e); |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 91 | return 1; |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | } // namespace autoconfig_server |
| 97 | } // namespace tools |
| 98 | } // namespace ndn |
| 99 | |
| 100 | int |
| 101 | main(int argc, char** argv) |
| 102 | { |
| 103 | return ndn::tools::autoconfig_server::main(argc, argv); |
| 104 | } |