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 | /* |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 3 | * 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 Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 29 | |
| 30 | #include <iostream> |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 31 | #include <unistd.h> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace tools { |
| 35 | namespace autoconfig_server { |
| 36 | |
| 37 | static void |
| 38 | usage(const char* programName) |
| 39 | { |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame^] | 40 | std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n" |
| 41 | << "\n" |
| 42 | << "Options:\n" |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 43 | << " -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 Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame^] | 46 | << " hub-face - a FaceUri to reach the HUB\n"; |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame^] | 49 | static int |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 50 | main(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 Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame^] | 78 | std::cerr << "ERROR: cannot parse HUB FaceUri" << std::endl; |
Junxiao Shi | 3b08154 | 2017-07-04 18:37:34 +0000 | [diff] [blame] | 79 | 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 | |
| 99 | int |
| 100 | main(int argc, char** argv) |
| 101 | { |
| 102 | return ndn::tools::autoconfig_server::main(argc, argv); |
| 103 | } |