aboutsummaryrefslogtreecommitdiffstats
path: root/libccnx-portal/ccnx/api/ccnx_Portal/ccnx_PortalFactory.h
blob: e021b92d8f71db4b6dfdcfc01514801ec2498082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file ccnx_PortalFactory.h
 * @brief An API for creating Portals.
 *
 */
#ifndef CCNx_Portal_API_ccnx_PortalFactory_h
#define CCNx_Portal_API_ccnx_PortalFactory_h

struct CCNxPortalFactory;
/**
 * @typedef CCNxPortalFactory
 * @brief A Portal factory.
 */
typedef struct CCNxPortalFactory CCNxPortalFactory;

#include <parc/algol/parc_Properties.h>
#include <parc/security/parc_Identity.h>
#include <parc/security/parc_KeyId.h>

#include <ccnx/transport/common/transport.h>
#include <ccnx/transport/common/transport_MetaMessage.h>
#include <ccnx/api/ccnx_Portal/ccnx_Portal.h>

extern const char *CCNxPortalFactory_LocalRouterName;
extern const char *CCNxPortalFactory_LocalForwarder;
extern const char *CCNxPortalFactory_LocalRouterTimeout;

/**
 * Create a `CCNxPortalFactory` with the given {@link PARCIdentity}.
 *
 * If successful, a new reference to the given `PARCIdentity`
 * instance is acquired and released when the result is eventually released
 * via {@link ccnxPortalFactory_Release}.
 * The caller must release its original reference.
 *
 * The given `PARCIdentity` is the identity used for interacting with the Transport Framework when creating a new stack.
 * The default behaviour is that identity is also used for subsequent Content Object signing operations.
 * It is permissable, however, to set a different identity,
 * after a Portal API instance is created should its associated Transport Stack support setting a new identity.
 *
 * @param [in] identity A pointer to a `PARCIdentity` instance.
 *
 * @return non-NULL A pointer to a `CCNxPortalFactory` instance.
 * @return NULL Memory could not be allocated.
 *
 * Example:
 * @code
 * {
 *     char *subjectName = "An Example";
 *     char *keystoreName = "keystore";
 *     char *keystorePassword = "password";
 *
 *     bool success = parcPkcs12KeyStore_CreateFile(keystoreName, keystorePassword, subjectName, 1024, 30);
 *
 *     PARCIdentity *identity =
 *         parcIdentity_Create(parcIdentityFile_Create(keystoreName, keystorePassword), PARCIdentityFileAsPARCIdentity);
 *
 *     CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);
 *     parcIdentity_Release(&identity);
 *
 *     ccnxPortalFactory_Release(&factory);
 * }
 * @endcode
 *
 * @see {@link ccnxPortalFactory_Acquire}
 * @see {@link ccnxPortalFactory_Release}
 */
CCNxPortalFactory *ccnxPortalFactory_Create(const PARCIdentity *identity);

/**
 * Print a human readable representation of the given `CCNxPortalFactory` instance.
 *
 * @param [in] factory A pointer to the instance of `CCNxPortalFactory` to display.
 * @param [in] indentation The level of indentation to use to pretty-print the output.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalFactory *factory = ccnxPortalFactory_Create(...);
 *
 *     ccnxPortalFactory_Display(0, factory);
 *
 *     ccnxPortalFactory_Release(&factory);
 * }
 * @endcode
 *
 */
void ccnxPortalFactory_Display(const CCNxPortalFactory *factory, int indentation);

/**
 * Increase the number of references to a `CCNxPortalFactory` instance.
 *
 * Note that new `CCNxPortalFactory` is not created,
 * only that the given `CCNxPortalFactory` reference count is incremented.
 * Discard the reference by invoking `ccnxPortalFactory_Release`.
 *
 * @param [in] instance A pointer to a valid `CCNxPortalFactory`.
 *
 * @return The value of the input parameter @p instance.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalFactory *x = ccnxPortalFactory_Create(...);
 *
 *     CCNxPortalFactory *x2 = ccnxPortalFactory_Acquire(x);
 *
 *     ccnxPortalFactory_Release(&x);
 *     ccnxPortalFactory_Release(&x2);
 * }
 * @endcode
 *
 * @see {@link ccnxPortalFactory_Release}
 */
CCNxPortalFactory *ccnxPortalFactory_Acquire(const CCNxPortalFactory *instance);

/**
 * Release a previously acquired reference to the specified instance,
 * decrementing the reference count for the instance.
 *
 * The pointer to the instance is set to NULL as a side-effect of this function.
 *
 * If the invocation causes the last reference to the instance to be released,
 * the instance is deallocated and the instance's implementation will perform
 * additional cleanup and release other privately held references.
 *
 * @param [in,out] factoryPtr A pointer to a pointer to the instance to release.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalFactory *factory = ccnxPortalFactory_Create(...);
 *
 *     ccnxPortalFactory_Release(&factory);
 * }
 * @endcode
 */
void ccnxPortalFactory_Release(CCNxPortalFactory **factoryPtr);

/**
 * Get the {@link PARCIdentity} associated with the given `CCNxPortalFactory`.
 *
 * Note: a handle to the instance is not acquired, so you must not release it.
 *
 * @param [in] factory A pointer to a valid `CCNxPortalFactory`.
 *
 * @return A pointer to the internal `PARCIdentity` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalFactory *factory = ccnxPortalFactory_Create(...);
 *
 *     PARCIdentity *identity = ccnxPortalFactory_GetIdentity(factory);
 *
 *     ccnxPortalFactory_Release(&factory);
 * }
 * @endcode
 *
 * @see {@link ccnxPortalFactory_Create}
 */
const PARCIdentity *ccnxPortalFactory_GetIdentity(const CCNxPortalFactory *factory);

/**
 * Get the `{@link PARCKeyId} of the {@link PARCIdentity} bound to the given CCNxPortalFactory.
 *
 * @param [in] factory A pointer to a valid `CCNxPortalFactory`.
 *
 * @return A pointer to the internal `PARCKeyId` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxPortalFactory *factory = ccnxPortalFactory_Create(...);
 *
 *     PARCKeyId *keyId = ccnxPortalFactory_GetKeyId(factory);
 *
 *     ccnxPortalFactory_Release(&factory);
 * }
 * @endcode
 *
 * @see {@link ccnxPortalFactory_Create}
 */
const PARCKeyId *ccnxPortalFactory_GetKeyId(const CCNxPortalFactory *factory);

/**
 * @typedef CCNxStackImpl
 * @brief A function that creates a `CCNxPortal` given a factory and attributes.
 */
typedef CCNxPortal *(CCNxStackImpl)(const CCNxPortalFactory *factory, const CCNxPortalAttributes *attributes);

/**
 * Create an {@link CCNxPortal} instance of the specified communication type, protocol and attributes.
 *
 * @param [in] factory A pointer to a CCNxPortal factory to use to create the instance.
 * @param [in,out] stackImplementation A pointer to a function initializing the protocol implementation.
 *
 * @return NULL An error occurred in creating the instance. See the value of `errno`
 * @return non-NULL A pointer to a valid `CCNxPortal` instance.
 *
 * Example:
 * @code
 * {
 *     CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
 *
 *     ccnxPortal_Release(&portal);
 * }
 * @endcode
 *
 * @see {@link ccnxPortal_Release}
 */
CCNxPortal *ccnxPortalFactory_CreatePortal(const CCNxPortalFactory *factory, CCNxStackImpl *stackImplementation);

PARCProperties *ccnxPortalFactory_GetProperties(const CCNxPortalFactory *factory);

const char *ccnxPortalFactory_GetProperty(const CCNxPortalFactory *factory, const char *restrict name, const char *restrict defaultValue);

void ccnxPortalFactory_SetProperty(const CCNxPortalFactory *factory, const char *restrict name, const char *restrict value);

#endif  // CCNx_Portal_API_ccnx_Portal_h