summaryrefslogtreecommitdiffstats
path: root/libccnx-common/ccnx/common/ccnx_ContentObject.h
blob: bff92433cc8ace19dbeb011831500eeb45651b80 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
/*
 * 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_ContentObject.h
 * @brief A CCNx ContentObject contains content to be sent in response to an Interest.
 *
 * The canonical CCN content object. A content object contains a payload, a {@link CCNxName},
 * and security binding information. It's sent in response to a CCN Interest.
 *
 * @see {@link CCNxInterest}
 *
 */

#ifndef libccnx_ccnx_ContentObject_h
#define libccnx_ccnx_ContentObject_h
#include <stdbool.h>

#include <ccnx/common/ccnx_Name.h>
#include <ccnx/common/ccnx_PayloadType.h>
#include <ccnx/common/ccnx_KeyLocator.h>

#include <ccnx/common/internal/ccnx_ContentObjectInterface.h>
#include <ccnx/common/internal/ccnx_TlvDictionary.h>

#include <parc/security/parc_Signature.h>

#include <parc/algol/parc_Buffer.h>

/**
 * @typedef CCNxContentObject
 * @brief The CCNx Content Object
 */
typedef CCNxTlvDictionary CCNxContentObject;

/**
 * Create a new instance of a `CCNxContentObject`, using dynamically allocated memory, with
 * the specified name and payload.
 *
 * The created instance must be released by calling {@link ccnxContentObject_Release()}.
 *
 * @param [in] contentName The CCNxName associated with this `CCNxContentObject`.
 * @param [in] payload The data to be encapsulated by this `CCNxContentObject`. May be NULL.
 *
 * @return A new instance of a `CCNxContentObject`.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 *
 * @see {@link ccnxContentObject_Release}
 */
CCNxContentObject *ccnxContentObject_CreateWithNameAndPayload(const CCNxName *contentName,
                                                              const PARCBuffer *payload);

/**
 * Create a new instance of a `CCNxContentObject`, using dynamically allocated memory, with
 * the specified payload. This will be a "nameless" Content Object.
 *
 * The created instance must be released by calling {@link ccnxContentObject_Release()}.
 *
 * @param [in] payload The data to be encapsulated by this `CCNxContentObject`. May be NULL.
 *
 * @return A new instance of a `CCNxContentObject`.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 *
 * @see {@link ccnxContentObject_Release}
 */
CCNxContentObject *ccnxContentObject_CreateWithPayload(const PARCBuffer *payload);

/**
 * Create a new instance of a `CCNxContentObject`, using dynamically allocated memory, with
 * the specified payload, using the specified {@link CCNxContentObjectInterface}.
 *
 * The created instance must be released by calling {@link ccnxContentObject_Release}().
 *
 * @param [in] implementation The interface's underlying implementation to use to build this ContentObject.
 * @param [in] contentName The CCNxName associated with this `CCNxContentObject`.
 * @param [in] type the type of the payload. Must be a valid {@link CCNxPayloadType}.
 * @param [in] payload The data to be encapsulated by this `CCNxContentObject`. May be NULL.
 *
 * @return A new instance of a `CCNxContentObject`.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject =
 *         ccnxContentObject_CreateWithImplAndPayload(&contentObjectImpl_Facade_V0,
 *                                                    name,
 *                                                    CCNxPayloadType_DATA,
 *                                                    payload);
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 *
 * @see ccnxContentObject_Release
 */
CCNxContentObject *ccnxContentObject_CreateWithImplAndPayload(const CCNxContentObjectInterface *implementation,
                                                              const CCNxName *contentName,
                                                              const CCNxPayloadType type,
                                                              const PARCBuffer *payload);


/**
 * Return a pointer to the {@link CCNxName} associated with this `CCNxContentObject`.
 *
 * This is memory managed by the `CCNxContentObject` and does not have to be released separately
 * unless {@link ccnxName_Acquire()} is called to acquire it.
 *
 * @param [in] contentObject An pointer to an instance of a `CCNxContentObject`.
 *
 * @return A pointer to the `CCNxName` associated with the specified `CCNxContentObject`.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     CCNxName *pointerToName = ccnxContentObject_GetName(contentObject);
 *
 *     ...
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 *
 * @see `CCNxName`
 */
CCNxName *ccnxContentObject_GetName(const CCNxContentObject *contentObject);

/**
 * Return a pointer to the payload associated with this `CCNxContentObject`.
 *
 * The returned pointer points to the {@link PARCBuffer} containing the `CCNxContentObject`'s payload.
 * This is memory managed by the `CCNxContentObject` and does not have to be released separately
 * unless {@link parcBuffer_Acquire()} is called to acquire it.
 *
 * @param [in] contentObject A pointer to an instance of a `CCNxContentObject`.
 *
 * @return A pointer to the `PARCBuffer` containing the specified `CCNxContentObject`'s payload.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     CCNxName *pointerToPayload = ccnxContentObject_GetPayload(contentObject);
 *
 *     ...
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 *
 * @see `PARCBuffer`
 */
PARCBuffer *ccnxContentObject_GetPayload(const CCNxContentObject *contentObject);

/**
 * Return the type of payload for this `CCNxContentObject`.
 *
 * The enumeration must be one of the defined values in {@link CCNxPayloadType}.
 *
 * @param [in] contentObject A pointer to an instance of a `CCNxContentObject`.
 *
 * @return The `CCNxContentObject` instances payload type.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     ...
 *
 *     CCNxPayloadType payloadType = ccnxContentObject_GetPayloadType(contentObject);
 *     if (payloadType == CCNx_PAYLOAD_DATA) {
 *         printf("Payload type is CCNx_PAYLOAD_DATA (raw data)");
 *     }
 *
 *     ...
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 */
CCNxPayloadType ccnxContentObject_GetPayloadType(const CCNxContentObject *contentObject);

/**
 * Set the number of the final chunk necessary to represent the content
 * in this ContentObject.
 *
 * The final chunk number is the 0-based count of the last chunk necessary
 * to encapsulate the content in this ContentObject. For example, if it would
 * take 10 chunks to encapsulate some content, the final chunk number would be 9.
 *
 * @param [in,out] contentObject A pointer to the `CCNxContentObject` to which to assign the final chunk number.
 * @param [in] finalChunkNumber The number of the final chunk
 *
 * @return `true` If the final chunk number was succesfully set.
 * @return `false` If the final chunk number could not be set. This might happen if the
 *         underlying transport format doesn't support final chunk numbers.
 * Example:
 * @code
 * {
 *     uint64_t finalChunkNumber = 2803;
 *     ccnxContentObject_SetFinalChunkNumber(contentObject, finalChunkNumber);
 * }
 * @endcode
 *
 * @see ccnxContentObject_GetFinalChunkNumber
 */
bool ccnxContentObject_SetFinalChunkNumber(CCNxContentObject *contentObject, const uint64_t finalChunkNumber);

/**
 * Returns `true` if this `CCNxContentObject` has a final chunk number.
 *
 * @param [in] contentObject A pointer to the `CCNxContentObject`
 *
 * @return `true` If the object has a final chunk number set.
 * @return `false` If the object has no final chunk number set.
 *
 * Example:
 * @code
 * {
 *     if (ccnxContentObject_HasFinalChunkNumber(contentObject)) {
 *        uint64_t finalChunkNumber = ccnxContentObject_GetFinalChunkNumber(contentObject);
 *        ...
 *     }
 * }
 * @endcode
 *
 * @see {@link ccnxContentObject_GetFinalChunkNumber}
 */
bool ccnxContentObject_HasFinalChunkNumber(const CCNxContentObject *contentObject);

/**
 * Return the final chunk number specified by this `CCNxContentObject`.
 *
 * @param [in] contentObject A pointer to the `CCNxContentObject` to get the final chunk number from.
 *
 * @return The final chunk number of the specified `CCNxContentObject`.
 *
 * Example:
 * @code
 * {
 *     uint64_t finalChunkNumber = ccnxContentObject_SetFinalChunkNumber(contentObject);
 * }
 * @endcode
 *
 * @see {@link ccnxContentObject_SetFinalChunkNumber}
 */
uint64_t ccnxContentObject_GetFinalChunkNumber(const CCNxContentObject *contentObject);

/**
 * Associate the supplied keyId, signature, and keyLocator with the specified `CCNxContentObject`.
 *
 * @param [in,out] contentObject A pointer to the `CCNxContentObject` to update.
 * @param [in] keyId A pointer to the {@link PARCBuffer} containing the keyId to assign to the contentObject.
 * @param [in] signature A pointer to a {@link PARCSignature} to assign to the contentObject.
 * @param [in] keyLocator A pointer to a {@link CCNxKeyLocator} to assign to the contentObject. May be NULL.
 *
 * @return true if the signature payload was successfully set, false otherwise.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly");
 *     PARCBuffer *payload = parcBuffer_WrapCString("hello");
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     PARCBuffer *keyId = parcBuffer_WrapCString("keyhash");
 *     PARCBuffer *sigbits = parcBuffer_CreateFromArray((void *) "siggybits", strlen("siggybits"));
 *     PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARCCryptoHashType_SHA256, parcBuffer_Flip(sigbits));
 *
 *     ccnxContentObject_SetSignature(contentObject, keyId, signature, NULL);
 *
 *     parcBuffer_Release(&payload);
 *     parcBuffer_Release(&sigbits);
 *     parcBuffer_Release(&keyId);
 *     parcSignature_Release(&signature);
 *     ccnxName_Release(&name);
 *     ccnxContentObject_Release(&contentObject);
 * }
 * @endcode
 *
 * @see `PARCSignature`
 * @see `CCNxKeyLocator`
 * @see `PARCBuffer`
 */
bool ccnxContentObject_SetSignature(CCNxContentObject *contentObject, const PARCBuffer *keyId,
                                    const PARCSignature *signature, const CCNxKeyLocator *keyLocator);


/**
 * Get the associated keyId from the specified `CCNxContentObject`.
 *
 * @param [in] contentObject A pointer to the `CCNxContentObject`.
 *
 * @return PARCBuffer A PARCBuffer containing the keyId or NULL if there is no keyId associated with the object.
 *
 * Example:
 * @code
 * {
 *     PARCBuffer *keyId = ccnxContentObject_GetKeyId(contentObject);
 *     if (keyId != NULL) {
 *          ...
 *      }
 * }
 * @endcode
 *
 * @see `ccnxContentObject_SetSignature`
 */
PARCBuffer *ccnxContentObject_GetKeyId(const CCNxContentObject *contentObject);

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


/**
 * 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] contentObjectP A pointer to a pointer to the instance to release.
 *
 * Example:
 * @code
 * {
 *     CCNxContentObject *reference = ccnxContentObject_Acquire(contentObject);
 *
 *     ...
 *
 *     ccnxContentObject_Release(&reference);
 * }
 * @endcode
 *
 * @see {@link ccnxContentObject_Acquire}
 */
void ccnxContentObject_Release(CCNxContentObject **contentObjectP);

#ifdef Libccnx_DISABLE_VALIDATION
#  define ccnxContentObject_OptionalAssertValid(_instance_)
#else
#  define ccnxContentObject_OptionalAssertValid(_instance_) ccnxContentObject_AssertValid(_instance_)
#endif

/**
 * Assert that an instance of `CCNxContentObject` is valid.
 *
 * If the instance is not valid, terminate via {@link trapIllegalValue}
 *
 * Valid means the internal state of the type is consistent with its
 * required current or future behaviour.
 * This may include the validation of internal instances of types.
 *
 * @param [in] contentObject A pointer to the instance to check.
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);
 *
 *     ccnxContentObject_AssertValid(contentObject);
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 */
void ccnxContentObject_AssertValid(const CCNxContentObject *contentObject);

/**
 * Produce a null-terminated C-string representation of the specified instance.
 *
 * The non-null result must be freed by the caller via {@link parcMemory_Deallocate}.
 *
 * @param [in] instance A pointer to the instance.
 *
 * @return NULL  Memory could not be allocated.
 * @return non-NULL A null-terminated string that must be deallocated via `parcMemory_Deallocate`.
 *
 * Example:
 * @code
 * {
 *     ...
 *     char *stringRep = ccnxContentObject_ToString(contentObject);
 *     parcMemory_Deallocate(&stringRep);
 * }
 * @endcode
 * @see `parcMemory_Deallocate`
 */
char *ccnxContentObject_ToString(const CCNxContentObject *contentObject);

/**
 * Determine if two `CCNxContentObject` instances are equal.
 *
 * The following equivalence relations on non-null `CCNxContentObject` instances are maintained:
 *
 *  * It is reflexive: for any non-null reference value x, `ccnxContentObject_Equals(x, x)`
 *      must return true.
 *
 *  * It is symmetric: for any non-null reference values x and y,
 *    `ccnxContentObject_Equals(x, y)` must return true if and only if
 *        `ccnxContentObject_Equals(y, x)` returns true.
 *
 *  * It is transitive: for any non-null reference values x, y, and z, if
 *        `ccnxContentObject_Equals(x, y)` returns true and
 *        `ccnxContentObject_Equals(y, z)` returns true,
 *        then  `ccnxContentObject_Equals(x, z)` must return true.
 *
 *  * It is consistent: for any non-null reference values x and y, multiple
 *      invocations of `ccnxContentObject_Equals(x, y)` consistently return true or
 *      consistently return false.
 *
 *  * For any non-null reference value x, `ccnxContentObject_Equals(x, NULL)` must
 *      return false.
 *
 * @param objectA A pointer to a `CCNxContentObject` instance.
 * @param objectB A pointer to a `CCNxContentObject` instance.
 * @return true if the two `CCNxContentObject` instances are equal.
 *
 * Example:
 * @code
 * @endcode
 */
bool ccnxContentObject_Equals(const CCNxContentObject *objectA, const CCNxContentObject *objectB);

/**
 * Get the ExpiryTime of the specified `ContentObject` instance.
 *
 * The ExpiryTime is the time at which the Payload expires, as expressed by a timestamp containing the number of
 * milliseconds since the epoch in UTC. A cache or end system should not respond with a Content Object past its
 * ExpiryTime. Routers forwarding a Content Object do not need to check the ExpiryTime. If the ExpiryTime field
 * is missing, the Content Object has no expressed expiration and a cache or end system may use the Content
 * Object for as long as it desires.
 *
 * Note: Calling this method on a `CCNxContentObject` that has no expiry time will cause a trap. Before calling,
 * check that an ExpiryTime exists by calling {@link ccnxContentObject_HasExpiryTime} first.
 *
 * @param [in] instance A pointer to a `CCNxContentObject` instance.
 *
 * @return the ExpiryTime of the specified ContentObject.
 *
 * Example:
 * @code
 * {
 *     CCNxContentObject *contentObject = ccnxContentObject_Create<...>;
 *
 *     if (ccnxContentObject_HasExpiryTime(contentObject) {
 *         uint64_t expiryTime = ccnxContentObject_GetExpiryTime(contentObject);
 *     } else {
 *         ccnxContentObject_SetExpiryTime(contentObject, 1478188800000ULL);
 *     }
 * }
 * @endcode
 * @see `ccnxContentObject_HasExpiryTime`
 * @see `ccnxContentObject_SetExpiryTime`
 */
uint64_t ccnxContentObject_GetExpiryTime(const CCNxContentObject *contentObject);

/**
 * Set the ExpiryTime of the specified `ContentObject` instance.
 *
 * See {@link ccnxContentObject_GetExpiryTime} for a description of ExpiryTime.
 *
 * @param [in] instance A pointer to the `CCNxContentObject` instance to be updated.
 * @param [in] expiryTime The ExpiryTime to set.
 *
 * @return true, if the ExpiryTime was succesfully set.
 *
 * Example:
 * @code
 * {
 *     CCNxContentObject *contentObject = ccnxContentObject_Create<...>;
 *
 *     if (ccnxContentObject_HasExpiryTime(contentObject) {
 *         uint64_t expiryTime = ccnxContentObject_GetExpiryTime(contentObject);
 *     } else {
 *         ccnxContentObject_SetExpiryTime(contentObject, 1478188800000ULL);
 *     }
 * }
 * @endcode
 * @see `ccnxContentObject_GetExpiryTime`
 * @see `ccnxContentObject_HasExpiryTime`
 */
bool ccnxContentObject_SetExpiryTime(CCNxContentObject *contentObject, const uint64_t expiryTime);

/**
 * Test whether the specified `ContentObject` instance has an ExpiryTime set.
 *
 * See {@link ccnxContentObject_GetExpiryTime} for a description of ExpiryTime.
 *
 * @param [in] instance A pointer to the `CCNxContentObject` instance to be updated.
 *
 * @return true, if the specified `CCNxContentObject` has an ExpiryTime.
 *
 * Example:
 * @code
 * {
 *     CCNxContentObject *contentObject = ccnxContentObject_Create<...>;
 *
 *     if (ccnxContentObject_HasExpiryTime(contentObject) {
 *         uint64_t expiryTime = ccnxContentObject_GetExpiryTime(contentObject);
 *     } else {
 *         ccnxContentObject_SetExpiryTime(contentObject, 1478188800000ULL);
 *     }
 * }
 * @endcode
 * @see `ccnxContentObject_GetExpiryTime`
 * @see `ccnxContentObject_SetExpiryTime`
 */
bool ccnxContentObject_HasExpiryTime(const CCNxContentObject *contentObject);

uint64_t ccnxContentObject_GetPathLabel(const CCNxContentObject *contentObject);
bool ccnxContentObject_SetPathLabel(CCNxContentObject *contentObject, const uint64_t pathLabel);
bool ccnxContentObject_HasPathLabel(const CCNxContentObject *contentObject);

/**
 * Set a payload on the specified `CCnxContentObject` instance.
 *
 * Currently, a payload may only be set once on a `CCnxContentObject` once, and may not be replaced.
 *
 * @param [in] contentObject A pointer to the `CCNxContentObject` instance to be updated.
 * @param [in] payloadType The type of payload. See {@link CCNxPayloadType} for available types.
 * @param [in] payload A pointer to the {@link PARCBuffer} to assign as the payload..
 *
 * @return true, if the payload was successfully added to the specified `CCNxContentObject`
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, NULL);
 *
 *     CCNxName *pointerToPayload = ccnxContentObject_GetPayload(contentObject);
 *     if (pointerToPayload == NULL) {
 *         ccnxContentObject_SetPayload(contentObject, CCNxPayloadType_DATA, payload);
 *     }
 *
 *     ...
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 * @see `CCNxPayloadType`
 * @see `PARCBuffer`
 * @see `ccnxContentObject_GetPayload`
 */
bool ccnxContentObject_SetPayload(CCNxContentObject *contentObject, CCNxPayloadType payloadType, const PARCBuffer *payload);

/**
 * Get the {@link CCNxPayloadType} of the specified `CCnxContentObject` instance.
 *
 * @param [in] instance A pointer to the `CCNxContentObject` instance to be updated.
 *
 * @return true, if the payload was successfully added to the specified `CCNxContentObject`
 *
 * Example:
 * @code
 * {
 *     CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
 *     PARCBuffer *payload = parcBuffer_Allocate(<...>);
 *
 *     CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, NULL);
 *
 *     CCNxName *pointerToPayload = ccnxContentObject_GetPayload(contentObject);
 *     if (pointerToPayload == NULL) {
 *         ccnxContentObject_SetPayload(contentObject, CCNxPayloadType_DATA, payload);
 *     }
 *
 *     ...
 *
 *     ccnxContentObject_Release(&contentObject);
 *     ccnxName_Release(&name);
 *     parcBuffer_Release(&payload);
 * }
 * @endcode
 * @see `CCNxPayloadType`
 * @see `PARCBuffer`
 * @see `ccnxContentObject_GetPayload`
 */
CCNxPayloadType ccnxContentObject_GetPayloadType(const CCNxContentObject *contentObject);
#endif // libccnx_ccnx_ContentObject_h