Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 4 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 7 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 11 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 15 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 18 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 19 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "pib.hpp" |
| 23 | |
| 24 | #include <ndn-cxx/util/io.hpp> |
| 25 | #include <ndn-cxx/util/config-file.hpp> |
| 26 | #include <ndn-cxx/security/key-chain.hpp> |
| 27 | |
| 28 | #include <boost/program_options/options_description.hpp> |
| 29 | #include <boost/program_options/variables_map.hpp> |
| 30 | #include <boost/program_options/parsers.hpp> |
| 31 | #include <boost/filesystem.hpp> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace pib { |
| 35 | |
| 36 | int |
| 37 | main(int argc, char** argv) |
| 38 | { |
| 39 | namespace po = boost::program_options; |
| 40 | namespace fs = boost::filesystem; |
| 41 | |
| 42 | std::string owner; |
| 43 | std::string dbDir; |
| 44 | std::string tpmLocator; |
| 45 | Face face; |
| 46 | |
| 47 | std::cerr << "hello" << std::endl; |
| 48 | |
| 49 | po::options_description description( |
| 50 | "General Usage\n" |
| 51 | " ndn-pib [-h] -o owner -d database_dir -t tpm_locator\n" |
| 52 | "General options"); |
| 53 | |
| 54 | description.add_options() |
| 55 | ("help,h", "produce help message") |
| 56 | ("owner,o", po::value<std::string>(&owner), |
| 57 | "Name of the owner, PIB will listen to /localhost/pib/[owner].") |
| 58 | ("database,d", po::value<std::string>(&dbDir), |
| 59 | "Absolute path to the directory of PIB database, /<database_dir>/pib.db") |
| 60 | ("tpm,t", po::value<std::string>(&tpmLocator), |
| 61 | "URI of the tpm. e.g., tpm-file:/var") |
| 62 | ; |
| 63 | |
| 64 | po::variables_map vm; |
| 65 | try { |
| 66 | po::store(po::parse_command_line(argc, argv, description), vm); |
| 67 | po::notify(vm); |
| 68 | } |
| 69 | catch (const std::exception& e) { |
| 70 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 71 | std::cerr << description << std::endl; |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | if (vm.count("help") != 0) { |
| 76 | std::cerr << description << std::endl; |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | try { |
| 81 | if (vm.count("owner") == 0 && vm.count("database") == 0 && vm.count("tpm") == 0) { |
| 82 | if (std::getenv("HOME")) { |
| 83 | fs::path pibDir(std::getenv("HOME")); |
| 84 | pibDir /= ".ndn/pib"; |
| 85 | dbDir = pibDir.string(); |
| 86 | } |
| 87 | else { |
| 88 | std::cerr << "ERROR: HOME variable is not set" << std::endl; |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | tpmLocator = KeyChain::getDefaultTpmLocator(); |
| 93 | |
| 94 | if (std::getenv("USER")) { |
| 95 | owner = std::string(std::getenv("USER")); |
| 96 | } |
| 97 | else { |
| 98 | std::cerr << "ERROR: HOME variable is not set" << std::endl; |
| 99 | return 1; |
| 100 | } |
| 101 | } |
| 102 | else if (vm.count("owner") == 0 || vm.count("database") == 0 || |
| 103 | vm.count("tpm") == 0) { |
| 104 | std::cerr << description << std::endl; |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | Pib pib(face, dbDir, tpmLocator, owner); |
| 109 | face.processEvents(); |
| 110 | } |
| 111 | catch (std::runtime_error& e) { |
| 112 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | } // namespace pib |
| 121 | } // namespace ndn |
| 122 | |
| 123 | int |
| 124 | main(int argc, char** argv) |
| 125 | { |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 126 | return ndn::pib::main(argc, argv); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 127 | } |