blob: 54f744ff6a5796749c57361fb3549fda48a36479 [file] [log] [blame]
Junxiao Shi0eba1aa2014-10-25 09:54:08 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 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_MANAGEMENT_NFD_COMMAND_OPTIONS_HPP
23#define NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_HPP
24
25#include "../security/identity-certificate.hpp"
26
27namespace ndn {
28namespace nfd {
29
30/** \ingroup management
31 * \brief contains options for ControlCommand execution
32 * \note This type is intentionally copyable
33 */
34class CommandOptions
35{
36public:
37 CommandOptions();
38
39 /** \return command timeout
40 */
41 const time::milliseconds&
42 getTimeout() const
43 {
44 return m_timeout;
45 }
46
47 /** \brief sets command timeout
48 * \param timeout the new command timeout, must be positive
49 * \throw std::out_of_range if timeout is non-positive
50 * \return self
51 */
52 CommandOptions&
53 setTimeout(const time::milliseconds& timeout);
54
55 /** \return command prefix
56 */
57 const Name&
58 getPrefix() const
59 {
60 return m_prefix;
61 }
62
63 /** \brief sets command prefix
64 * \return self
65 */
66 CommandOptions&
67 setPrefix(const Name& prefix);
68
69public: // signing parameters
70 /** \brief indicates the selection of signing parameters
71 */
72 enum SigningParamsKind {
73 /** \brief picks the default signing identity and certificate
74 */
75 SIGNING_PARAMS_DEFAULT,
76 /** \brief picks the default certificate of a specific identity Name
77 */
78 SIGNING_PARAMS_IDENTITY,
79 /** \brief picks a specific identity certificate
80 */
81 SIGNING_PARAMS_CERTIFICATE
82 };
83
84 /** \return selection of signing parameters
85 */
86 SigningParamsKind
87 getSigningParamsKind() const
88 {
89 return m_signingParamsKind;
90 }
91
92 /** \return identity Name
93 * \pre getSigningParamsKind() == SIGNING_PARAMS_IDENTITY
94 */
95 const Name&
96 getSigningIdentity() const
97 {
98 BOOST_ASSERT(m_signingParamsKind == SIGNING_PARAMS_IDENTITY);
99 return m_identity;
100 }
101
102 /** \return certificate Name
103 * \pre getSigningParamsKind() == SIGNING_PARAMS_CERTIFICATE
104 */
105 const Name&
106 getSigningCertificate() const
107 {
108 BOOST_ASSERT(m_signingParamsKind == SIGNING_PARAMS_CERTIFICATE);
109 return m_identity;
110 }
111
112 /** \brief chooses to use default identity and certificate
113 * \post getSigningParamsKind() == SIGNING_PARAMS_DEFAULT
114 * \return self
115 */
116 CommandOptions&
117 setSigningDefault()
118 {
119 m_signingParamsKind = SIGNING_PARAMS_DEFAULT;
120 return *this;
121 }
122
123 /** \brief chooses to use a specific identity and its default certificate
124 * \post getSigningParamsKind() == SIGNING_PARAMS_IDENTITY
125 * \post getIdentityName() == identityName
126 * \return self
127 */
128 CommandOptions&
129 setSigningIdentity(const Name& identityName);
130
131 /** \brief chooses to use a specific identity certificate
132 * \param certificateName identity certificate Name
133 * \throw std::invalid_argument if certificateName is invalid
134 * \post getSigningParamsKind() == SIGNING_PARAMS_CERTIFICATE
135 * \post getIdentityCertificate() is a copy of certificate
136 * \return self
137 */
138 CommandOptions&
139 setSigningCertificate(const Name& certificateName);
140
141 /** \brief chooses to use a specific identity certificate
142 * \details This is equivalent to .setIdentityCertificate(certificate.getName())
143 */
144 CommandOptions&
145 setSigningCertificate(const IdentityCertificate& certificate);
146
147public:
148 /** \brief gives the default command timeout: 10000ms
149 */
150 static const time::milliseconds DEFAULT_TIMEOUT;
151
152 /** \brief gives the default command prefix: ndn:/localhost/nfd
153 */
154 static const Name DEFAULT_PREFIX;
155
156private:
157 time::milliseconds m_timeout;
158 Name m_prefix;
159 SigningParamsKind m_signingParamsKind;
160 Name m_identity; // identityName or certificateName
161};
162
163} // namespace nfd
164} // namespace ndn
165
166#endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_HPP