Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MGMT_NFD_COMMAND_OPTIONS_HPP |
| 23 | #define NDN_MGMT_NFD_COMMAND_OPTIONS_HPP |
| 24 | |
| 25 | #include "../../security/signing-info.hpp" |
| 26 | |
| 27 | #define NDN_MGMT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
| 28 | |
| 29 | namespace ndn { |
| 30 | |
| 31 | namespace security { |
| 32 | namespace v1 { |
| 33 | class IdentityCertificate; |
| 34 | } // namespace v1 |
| 35 | } // namespace security |
| 36 | |
| 37 | namespace nfd { |
| 38 | |
| 39 | /** \ingroup management |
| 40 | * \brief contains options for ControlCommand execution |
| 41 | * \note This type is intentionally copyable |
| 42 | */ |
| 43 | class CommandOptions |
| 44 | { |
| 45 | public: |
| 46 | /** \brief constructs CommandOptions |
| 47 | * \post getTimeout() == DEFAULT_TIMEOUT |
| 48 | * \post getPrefix() == DEFAULT_PREFIX |
| 49 | * \post getSigningInfo().getSignerType() == SIGNER_TYPE_NULL |
| 50 | */ |
| 51 | CommandOptions(); |
| 52 | |
| 53 | /** \return command timeout |
| 54 | */ |
| 55 | const time::milliseconds& |
| 56 | getTimeout() const |
| 57 | { |
| 58 | return m_timeout; |
| 59 | } |
| 60 | |
| 61 | /** \brief sets command timeout |
| 62 | * \param timeout the new command timeout, must be positive |
| 63 | * \throw std::out_of_range if timeout is non-positive |
| 64 | * \return self |
| 65 | */ |
| 66 | CommandOptions& |
| 67 | setTimeout(const time::milliseconds& timeout); |
| 68 | |
| 69 | /** \return command prefix |
| 70 | */ |
| 71 | const Name& |
| 72 | getPrefix() const |
| 73 | { |
| 74 | return m_prefix; |
| 75 | } |
| 76 | |
| 77 | /** \brief sets command prefix |
| 78 | * \return self |
| 79 | */ |
| 80 | CommandOptions& |
| 81 | setPrefix(const Name& prefix); |
| 82 | |
| 83 | /** \return signing parameters |
| 84 | */ |
| 85 | const security::SigningInfo& |
| 86 | getSigningInfo() const |
| 87 | { |
| 88 | return m_signingInfo; |
| 89 | } |
| 90 | |
| 91 | /** \brief sets signing parameters |
| 92 | * \return self |
| 93 | */ |
| 94 | CommandOptions& |
| 95 | setSigningInfo(const security::SigningInfo& signingInfo); |
| 96 | |
| 97 | #ifdef NDN_MGMT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
| 98 | public: // signing parameters |
| 99 | /** \deprecated use getSigningInfo and setSigningInfo |
| 100 | * \brief indicates the selection of signing parameters |
| 101 | */ |
| 102 | enum SigningParamsKind { |
| 103 | /** \brief picks the default signing identity and certificate |
| 104 | */ |
| 105 | SIGNING_PARAMS_DEFAULT, |
| 106 | /** \brief picks the default certificate of a specific identity Name |
| 107 | */ |
| 108 | SIGNING_PARAMS_IDENTITY, |
| 109 | /** \brief picks a specific identity certificate |
| 110 | */ |
| 111 | SIGNING_PARAMS_CERTIFICATE |
| 112 | }; |
| 113 | |
| 114 | /** \deprecated use getSigningInfo and setSigningInfo |
| 115 | * \return selection of signing parameters |
| 116 | */ |
| 117 | DEPRECATED( |
| 118 | SigningParamsKind |
| 119 | getSigningParamsKind() const); |
| 120 | |
| 121 | /** \deprecated use getSigningInfo and setSigningInfo |
| 122 | * \return identity Name |
| 123 | * \pre getSigningParamsKind() == SIGNING_PARAMS_IDENTITY |
| 124 | */ |
| 125 | DEPRECATED( |
| 126 | const Name& |
| 127 | getSigningIdentity() const); |
| 128 | |
| 129 | /** \deprecated use getSigningInfo and setSigningInfo |
| 130 | * \return certificate Name |
| 131 | * \pre getSigningParamsKind() == SIGNING_PARAMS_CERTIFICATE |
| 132 | */ |
| 133 | DEPRECATED( |
| 134 | const Name& |
| 135 | getSigningCertificate() const); |
| 136 | |
| 137 | /** \deprecated use getSigningInfo and setSigningInfo |
| 138 | * \brief chooses to use default identity and certificate |
| 139 | * \post getSigningParamsKind() == SIGNING_PARAMS_DEFAULT |
| 140 | * \return self |
| 141 | */ |
| 142 | DEPRECATED( |
| 143 | CommandOptions& |
| 144 | setSigningDefault()); |
| 145 | |
| 146 | /** \deprecated use getSigningInfo and setSigningInfo |
| 147 | * \brief chooses to use a specific identity and its default certificate |
| 148 | * \post getSigningParamsKind() == SIGNING_PARAMS_IDENTITY |
| 149 | * \post getIdentityName() == identityName |
| 150 | * \return self |
| 151 | */ |
| 152 | DEPRECATED( |
| 153 | CommandOptions& |
| 154 | setSigningIdentity(const Name& identityName)); |
| 155 | |
| 156 | /** \deprecated use getSigningInfo and setSigningInfo |
| 157 | * \brief chooses to use a specific identity certificate |
| 158 | * \param certificateName identity certificate Name |
| 159 | * \throw std::invalid_argument if certificateName is invalid |
| 160 | * \post getSigningParamsKind() == SIGNING_PARAMS_CERTIFICATE |
| 161 | * \post getSigningCertificate() == certificateName |
| 162 | * \return self |
| 163 | */ |
| 164 | DEPRECATED( |
| 165 | CommandOptions& |
| 166 | setSigningCertificate(const Name& certificateName)); |
| 167 | |
| 168 | /** \deprecated use getSigningInfo and setSigningInfo |
| 169 | * \brief chooses to use a specific identity certificate |
| 170 | * \details This is equivalent to .setIdentityCertificate(certificate.getName()) |
| 171 | */ |
| 172 | DEPRECATED( |
| 173 | CommandOptions& |
| 174 | setSigningCertificate(const security::v1::IdentityCertificate& certificate)); |
| 175 | |
| 176 | #endif // NDN_MGMT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
| 177 | |
| 178 | public: |
| 179 | /** \brief gives the default command timeout: 10000ms |
| 180 | */ |
| 181 | static const time::milliseconds DEFAULT_TIMEOUT; |
| 182 | |
| 183 | /** \brief gives the default command prefix: ndn:/localhost/nfd |
| 184 | */ |
| 185 | static const Name DEFAULT_PREFIX; |
| 186 | |
| 187 | private: |
| 188 | time::milliseconds m_timeout; |
| 189 | Name m_prefix; |
| 190 | security::SigningInfo m_signingInfo; |
| 191 | }; |
| 192 | |
| 193 | } // namespace nfd |
| 194 | } // namespace ndn |
| 195 | |
| 196 | #endif // NDN_MGMT_NFD_COMMAND_OPTIONS_HPP |