Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 5 | * This file is part of NDN DeLorean, An Authentication System for Data Archives in |
| 6 | * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors |
| 7 | * and contributors. |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 8 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 9 | * NDN DeLorean is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License as published by the Free Software |
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
| 12 | * version. |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 13 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 14 | * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 16 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 17 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License along with NDN |
| 19 | * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Yingdi Yu | 6ff3193 | 2015-03-23 13:30:07 -0700 | [diff] [blame] | 22 | #include "../core/logger.hpp" |
| 23 | |
| 24 | #include <boost/program_options/options_description.hpp> |
| 25 | #include <boost/program_options/variables_map.hpp> |
| 26 | #include <boost/program_options/parsers.hpp> |
| 27 | #include <boost/filesystem.hpp> |
| 28 | |
| 29 | |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 30 | int |
| 31 | main(int argc, char** argv) |
| 32 | { |
Yingdi Yu | 6ff3193 | 2015-03-23 13:30:07 -0700 | [diff] [blame] | 33 | namespace po = boost::program_options; |
| 34 | namespace fs = boost::filesystem; |
| 35 | |
| 36 | std::string configFile; |
| 37 | |
| 38 | po::options_description description("General Usage\n" |
| 39 | " nsl [-h] [-c config]\n" |
| 40 | "General options"); |
| 41 | description.add_options() |
| 42 | ("help,h", "produce help message") |
| 43 | ("config,c", po::value<std::string>(&configFile)) |
| 44 | ; |
| 45 | |
| 46 | po::variables_map vm; |
| 47 | try { |
| 48 | po::store(po::parse_command_line(argc, argv, description), vm); |
| 49 | po::notify(vm); |
| 50 | } |
| 51 | catch (const std::exception& e) { |
| 52 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 53 | std::cerr << description << std::endl; |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | if (vm.count("help") != 0) { |
| 58 | std::cerr << description << std::endl; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | if (vm.count("config") == 0) { |
| 63 | |
| 64 | if (!getenv("HOME")) { |
| 65 | configFile = "/usr/local/etc/ndn/nsl.conf"; |
| 66 | } |
| 67 | else { |
| 68 | configFile = getenv("HOME"); |
| 69 | configFile += "/.ndn/nsl.conf"; |
| 70 | } |
| 71 | |
| 72 | if (!fs::exists(fs::path(configFile))) { |
| 73 | std::cerr << "ERROR: config file is not available: " << configFile << std::endl; |
| 74 | return 1; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | try { |
| 79 | ndn::Face face; |
| 80 | nsl::Logger(face, configFile); |
| 81 | face.processEvents(); |
| 82 | } |
| 83 | catch (std::runtime_error& e) { |
| 84 | std::cerr << e.what() << std::endl; |
| 85 | return 1; |
| 86 | } |
| 87 | |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |