build: Finalizing waf building system (removing legacy code)
Change-Id: Ie7e7cc84e19551e3dd5dd0405b14f289ea54e7cd
diff --git a/src/c/data.h b/src/c/data.h
deleted file mode 100644
index ffaa83c..0000000
--- a/src/c/data.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_DATA_H
-#define NDN_DATA_H
-
-#include <ndn-cpp-dev/c/data-types.h>
-#include "name.h"
-#include "publisher-public-key-digest.h"
-#include "key-locator.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
- */
-struct ndn_Signature {
- struct ndn_Blob digestAlgorithm; /**< A Blob whose value is a pointer to a pre-allocated buffer. 0 for none.
- * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
- struct ndn_Blob witness; /**< A Blob whose value is a pointer to pre-allocated buffer. 0 for none. */
- struct ndn_Blob signature;
- struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
- struct ndn_KeyLocator keyLocator;
-};
-
-/**
- * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
- * @param self A pointer to the ndn_MetaInfo struct.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
- * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
- */
-static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) {
- ndn_Blob_initialize(&self->digestAlgorithm, 0, 0);
- ndn_Blob_initialize(&self->witness, 0, 0);
- ndn_Blob_initialize(&self->signature, 0, 0);
- ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
- ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
-}
-
-/**
- * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
- */
-struct ndn_MetaInfo {
- ndn_MillisecondsSince1970 timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
- ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
- int freshnessSeconds; /**< -1 for none */
- struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
-};
-
-/**
- * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
- * @param self A pointer to the ndn_MetaInfo struct.
- */
-static inline void ndn_MetaInfo_initialize
- (struct ndn_MetaInfo *self) {
- self->type = ndn_ContentType_DATA;
- self->freshnessSeconds = -1;
- ndn_NameComponent_initialize(&self->finalBlockID, 0, 0);
-}
-
-struct ndn_Data {
- struct ndn_Signature signature;
- struct ndn_Name name;
- struct ndn_MetaInfo metaInfo;
- struct ndn_Blob content; /**< A Blob with a pointer to the content. */
-};
-
-/**
- * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
- * and defaults for all the values.
- * @param self A pointer to the ndn_Data struct.
- * @param nameComponents The pre-allocated array of ndn_NameComponent.
- * @param maxNameComponents The number of elements in the allocated nameComponents array.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
- * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
- */
-static inline void ndn_Data_initialize
- (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
- struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents)
-{
- ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
- ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
- ndn_MetaInfo_initialize(&self->metaInfo);
- ndn_Blob_initialize(&self->content, 0, 0);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-data.c b/src/c/encoding/binary-xml-data.c
deleted file mode 100644
index d8013cf..0000000
--- a/src/c/encoding/binary-xml-data.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from ContentObject.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-#include "binary-xml-name.h"
-#include "binary-xml-publisher-public-key-digest.h"
-#include "binary-xml-data.h"
-#include "binary-xml-key.h"
-
-static ndn_Error encodeSignature(struct ndn_Signature *signature, struct ndn_BinaryXmlEncoder *encoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Signature)))
- return error;
-
- // TODO: Check if digestAlgorithm is the same as the default, and skip it, otherwise encode it as UDATA.
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalBlobDTagElement(encoder, ndn_BinaryXml_DTag_Witness, &signature->witness)))
- return error;
-
- // Require a signature.
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_SignatureBits, &signature->signature)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-static ndn_Error decodeSignature(struct ndn_Signature *signature, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Signature)))
- return error;
-
- /* TODO: digestAlgorithm as UDATA */ signature->digestAlgorithm.value = 0; signature->digestAlgorithm.length = 0;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_Witness, 0, &signature->witness)))
- return error;
-
- // Require a signature.
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_SignatureBits, 0, &signature->signature)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-static ndn_Error encodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlEncoder *encoder)
-{
- if ((int)metaInfo->type < 0)
- return NDN_ERROR_success;
-
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_SignedInfo)))
- return error;
-
- // This will skip encoding if there is no publisherPublicKeyDigest.
- if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, encoder)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
- (encoder, ndn_BinaryXml_DTag_Timestamp, metaInfo->timestampMilliseconds)))
- return error;
-
- if (!((int)metaInfo->type < 0 || metaInfo->type == ndn_ContentType_DATA)) {
- // Not the default of DATA, so we need to encode the type.
- struct ndn_Blob typeBytes;
- typeBytes.length = 3;
- if (metaInfo->type == ndn_ContentType_ENCR)
- typeBytes.value = (uint8_t *)"\x10\xD0\x91";
- else if (metaInfo->type == ndn_ContentType_GONE)
- typeBytes.value = (uint8_t *)"\x18\xE3\x44";
- else if (metaInfo->type == ndn_ContentType_KEY)
- typeBytes.value = (uint8_t *)"\x28\x46\x3F";
- else if (metaInfo->type == ndn_ContentType_LINK)
- typeBytes.value = (uint8_t *)"\x2C\x83\x4A";
- else if (metaInfo->type == ndn_ContentType_NACK)
- typeBytes.value = (uint8_t *)"\x34\x00\x8A";
- else
- return NDN_ERROR_unrecognized_ndn_ContentType;
-
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Type, &typeBytes)))
- return error;
- }
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_FreshnessSeconds, metaInfo->freshnessSeconds)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_FinalBlockID, &metaInfo->finalBlockID.value)))
- return error;
-
- // This will skip encoding if there is no key locator.
- if ((error = ndn_encodeBinaryXmlKeyLocator(&signature->keyLocator, encoder)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-static ndn_Error decodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_SignedInfo)))
- return error;
-
- if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, decoder)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (decoder, ndn_BinaryXml_DTag_Timestamp, &metaInfo->timestampMilliseconds)))
- return error;
-
- struct ndn_Blob typeBytes;
- if ((error = ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_Type, 0, &typeBytes)))
- return error;
- if (typeBytes.length == 0)
- // The default Type is DATA.
- metaInfo->type = ndn_ContentType_DATA;
- else if (typeBytes.length == 3) {
- // All the recognized content types are 3 bytes.
- if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x0C\x04\xC0", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_DATA;
- else if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x10\xD0\x91", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_ENCR;
- else if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x18\xE3\x44", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_GONE;
- else if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x28\x46\x3F", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_KEY;
- else if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x2C\x83\x4A", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_LINK;
- else if (ndn_memcmp(typeBytes.value, (uint8_t *)"\x34\x00\x8A", typeBytes.length) == 0)
- metaInfo->type = ndn_ContentType_NACK;
- else
- return NDN_ERROR_unrecognized_ndn_ContentType;
- }
- else
- return NDN_ERROR_unrecognized_ndn_ContentType;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_FreshnessSeconds, &metaInfo->freshnessSeconds)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_FinalBlockID, 0, &metaInfo->finalBlockID.value)))
- return error;
-
- if ((error = ndn_decodeOptionalBinaryXmlKeyLocator(&signature->keyLocator, decoder)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_encodeBinaryXmlData
- (struct ndn_Data *data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_BinaryXmlEncoder *encoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_ContentObject)))
- return error;
-
- if ((error = encodeSignature(&data->signature, encoder)))
- return error;
-
- *signedPortionBeginOffset = encoder->offset;
-
- if ((error = ndn_encodeBinaryXmlName(&data->name, encoder)))
- return error;
-
- if ((error = encodeSignedInfo(&data->signature, &data->metaInfo, encoder)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Content, &data->content)))
- return error;
-
- *signedPortionEndOffset = encoder->offset;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlData
- (struct ndn_Data *data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_ContentObject)))
- return error;
-
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Signature, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = decodeSignature(&data->signature, decoder)))
- return error;
- }
- else
- ndn_Signature_initialize(&data->signature, data->signature.keyLocator.keyName.components, data->signature.keyLocator.keyName.maxComponents);
-
- *signedPortionBeginOffset = decoder->offset;
-
- if ((error = ndn_decodeBinaryXmlName(&data->name, decoder)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_SignedInfo, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = decodeSignedInfo(&data->signature, &data->metaInfo, decoder)))
- return error;
- }
- else
- ndn_MetaInfo_initialize(&data->metaInfo);
-
- // Require a Content element, but set allowNull to allow a missing BLOB.
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Content, 1, &data->content)))
- return error;
-
- *signedPortionEndOffset = decoder->offset;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-data.h b/src/c/encoding/binary-xml-data.h
deleted file mode 100644
index f5865ba..0000000
--- a/src/c/encoding/binary-xml-data.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARY_XML_DATA_H
-#define NDN_BINARY_XML_DATA_H
-
-#include "../errors.h"
-#include "../data.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Encode the data packet as binary XML.
- * @param data Pointer to the data object to encode.
- * @param signedPortionBeginOffset Return the offset in the encoding of the beginning of the signed portion.
- * If you are not encoding in order to sign, you can ignore this returned value.
- * @param signedPortionEndOffset Return the offset in the encoding of the end of the signed portion.
- * If you are not encoding in order to sign, you can ignore this returned value.
- * @param encoder Pointer to the ndn_BinaryXmlEncoder struct which receives the encoding.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_encodeBinaryXmlData
- (struct ndn_Data *data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_BinaryXmlEncoder *encoder);
-
-/**
- * Decode the data packet as binary XML and set the fields in the data object.
- * @param data Pointer to the data object whose fields are updated.
- * @param signedPortionBeginOffset Return the offset in the input buffer of the beginning of the signed portion.
- * If you are not decoding in order to verify, you can ignore this returned value.
- * @param signedPortionEndOffset Return the offset in the input buffer of the end of the signed portion.
- * If you are not decoding in order to verify, you can ignore this returned value.
- * @param decoder Pointer to the ndn_BinaryXmlDecoder struct which has been initialized with the buffer to decode.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_decodeBinaryXmlData
- (struct ndn_Data *data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-decoder.c b/src/c/encoding/binary-xml-decoder.c
deleted file mode 100644
index 110ce51..0000000
--- a/src/c/encoding/binary-xml-decoder.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from BinaryXMLDecoder.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml.h"
-#include "binary-xml-decoder.h"
-
-/**
- * Return the octet at self->offset, converting to unsigned int. Increment self->offset.
- * This does not check for reading past the end of the input, so this is called "unsafe".
- */
-static inline unsigned int unsafeReadOctet(struct ndn_BinaryXmlDecoder *self)
-{
- return (unsigned int)(self->input[self->offset++] & 0xff);
-}
-
-/**
- * Return the octet at self->offset, converting to unsigned int. Do not increment self->offset.
- * This does not check for reading past the end of the input, so this is called "unsafe".
- */
-static inline unsigned int unsafeGetOctet(struct ndn_BinaryXmlDecoder *self)
-{
- return (unsigned int)(self->input[self->offset] & 0xff);
-}
-
-/**
- * Parse the value as a decimal unsigned integer. This does not check for whitespace or + sign.
- * If valueLength is 0, this succeeds with resultOut 0.
- * @param value
- * @param valueLength
- * @param resultOut output the parsed integer.
- * @return 0 for success, else an error code, including if an element of value is not a decimal digit.
- */
-static ndn_Error parseUnsignedDecimalInt(uint8_t *value, size_t valueLength, unsigned int *resultOut)
-{
- unsigned int result = 0;
-
- size_t i;
- for (i = 0; i < valueLength; ++i) {
- uint8_t digit = value[i];
- if (!(digit >= '0' && digit <= '9'))
- return NDN_ERROR_element_of_value_is_not_a_decimal_digit;
-
- result *= 10;
- result += (unsigned int)(digit - '0');
- }
-
- *resultOut = result;
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_decodeTypeAndValue(struct ndn_BinaryXmlDecoder *self, unsigned int *type, unsigned int *valueOut)
-{
- unsigned int value = 0;
- int gotFirstOctet = 0;
-
- while (1) {
- if (self->offset >= self->inputLength)
- return NDN_ERROR_read_past_the_end_of_the_input;
-
- unsigned int octet = unsafeReadOctet(self);
-
- if (!gotFirstOctet) {
- if (octet == 0)
- return NDN_ERROR_the_first_header_octet_may_not_be_zero;
-
- gotFirstOctet = 1;
- }
-
- if (octet & ndn_BinaryXml_TT_FINAL) {
- // Finished.
- *type = octet & ndn_BinaryXml_TT_MASK;
- value = (value << ndn_BinaryXml_TT_VALUE_BITS) | ((octet >> ndn_BinaryXml_TT_BITS) & ndn_BinaryXml_TT_VALUE_MASK);
- break;
- }
-
- value = (value << ndn_BinaryXml_REGULAR_VALUE_BITS) | (octet & ndn_BinaryXml_REGULAR_VALUE_MASK);
- }
-
- *valueOut = value;
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readElementStartDTag(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag)
-{
- if (self->offset == self->previouslyPeekedDTagStartOffset) {
- // peekDTag already decoded this DTag.
- if (self->previouslyPeekedDTag != expectedTag)
- return NDN_ERROR_did_not_get_the_expected_DTAG;
-
- // Fast forward past the header.
- self->offset = self->previouslyPeekedDTagEndOffset;
- }
- else {
- ndn_Error error;
- unsigned int type;
- unsigned int value;
- if ((error = ndn_BinaryXmlDecoder_decodeTypeAndValue(self, &type, &value)))
- return error;
-
- if (type != ndn_BinaryXml_DTAG)
- return NDN_ERROR_header_type_is_not_a_DTAG;
-
- if (value != expectedTag)
- return NDN_ERROR_did_not_get_the_expected_DTAG;
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readElementClose(struct ndn_BinaryXmlDecoder *self)
-{
- if (self->offset >= self->inputLength)
- return NDN_ERROR_read_past_the_end_of_the_input;
-
- if (unsafeReadOctet(self) != ndn_BinaryXml_CLOSE)
- return NDN_ERROR_did_not_get_the_expected_element_close;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_peekDTag(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int *gotExpectedTag)
-{
- if (self->offset == self->previouslyPeekedDTagStartOffset)
- // We already decoded this DTag.
- *gotExpectedTag = (self->previouslyPeekedDTag == expectedTag ? 1 : 0);
- else {
- // Default to 0.
- *gotExpectedTag = 0;
-
- // First check if it is an element close (which cannot be the expected tag).
- if (self->offset >= self->inputLength)
- return NDN_ERROR_read_past_the_end_of_the_input;
- if (unsafeGetOctet(self) == ndn_BinaryXml_CLOSE)
- return NDN_ERROR_success;
-
- unsigned int type;
- unsigned int value;
- size_t saveOffset = self->offset;
- ndn_Error error = ndn_BinaryXmlDecoder_decodeTypeAndValue(self, &type, &value);
- // readElementStartDTag will use this to fast forward.
- self->previouslyPeekedDTagEndOffset = self->offset;
- // Restore offset.
- self->offset = saveOffset;
-
- if (error)
- return error;
-
- if (type == ndn_BinaryXml_DTAG) {
- self->previouslyPeekedDTagStartOffset = saveOffset;
- self->previouslyPeekedDTag = value;
-
- if (value == expectedTag)
- *gotExpectedTag = 1;
- }
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readBinaryDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int allowNull, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(self, expectedTag)))
- return error;
-
- if (allowNull) {
- if (self->offset >= self->inputLength)
- return NDN_ERROR_read_past_the_end_of_the_input;
-
- if (unsafeGetOctet(self) == ndn_BinaryXml_CLOSE) {
- // The binary item is missing, and this is allowed, so read the element close and return a null value.
- ++self->offset;
- value->value = 0;
- value->length = 0;
- return NDN_ERROR_success;
- }
- }
-
- unsigned int itemType;
- unsigned int uintValueLength;
- if ((error = ndn_BinaryXmlDecoder_decodeTypeAndValue(self, &itemType, &uintValueLength)))
- return error;
- // Ignore itemType.
- value->value = self->input + self->offset;
- value->length = (size_t)uintValueLength;
- self->offset += value->length;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int allowNull, struct ndn_Blob *value)
-{
- ndn_Error error;
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(self, expectedTag, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(self, expectedTag, allowNull, value)))
- return error;
- }
- else {
- value->value = 0;
- value->length = 0;
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readUDataDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(self, expectedTag)))
- return error;
-
- unsigned int itemType;
- unsigned int uintValueLength;
- if ((error = ndn_BinaryXmlDecoder_decodeTypeAndValue(self, &itemType, &uintValueLength)))
- return error;
- if (itemType != ndn_BinaryXml_UDATA)
- return NDN_ERROR_item_is_not_UDATA;
- value->value = self->input + self->offset;
- value->length = uintValueLength;
- self->offset += value->length;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readOptionalUDataDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, struct ndn_Blob *value)
-{
- ndn_Error error;
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(self, expectedTag, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = ndn_BinaryXmlDecoder_readUDataDTagElement(self, expectedTag, value)))
- return error;
- }
- else {
- value->value = 0;
- value->length = 0;
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readUnsignedIntegerDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, unsigned int *value)
-{
- struct ndn_Blob udataValue;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readUDataDTagElement(self, expectedTag, &udataValue)))
- return error;
-
- if ((error = parseUnsignedDecimalInt(udataValue.value, udataValue.length, value)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int *value)
-{
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(self, expectedTag, &gotExpectedTag)))
- return error;
-
- if (!gotExpectedTag) {
- *value = -1;
- return NDN_ERROR_success;
- }
-
- unsigned int unsignedValue;
- if ((error = ndn_BinaryXmlDecoder_readUnsignedIntegerDTagElement(self, expectedTag, &unsignedValue)))
- return error;
-
- *value = (int)unsignedValue;
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
-{
- ndn_Error error;
- struct ndn_Blob bytes;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(self, expectedTag, 0, &bytes)))
- return error;
-
- *milliseconds = 1000.0 * ndn_BinaryXmlDecoder_unsignedBigEndianToDouble(bytes.value, bytes.length) / 4096.0;
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
-{
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(self, expectedTag, &gotExpectedTag)))
- return error;
-
- if (!gotExpectedTag) {
- *milliseconds = -1.0;
- return NDN_ERROR_success;
- }
-
- if ((error = ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement(self, expectedTag, milliseconds)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-double ndn_BinaryXmlDecoder_unsignedBigEndianToDouble(uint8_t *bytes, size_t bytesLength)
-{
- double result = 0.0;
- size_t i;
- for (i = 0; i < bytesLength; ++i) {
- result *= 256.0;
- result += (double)bytes[i];
- }
-
- return result;
-}
diff --git a/src/c/encoding/binary-xml-decoder.h b/src/c/encoding/binary-xml-decoder.h
deleted file mode 100644
index 8fe1469..0000000
--- a/src/c/encoding/binary-xml-decoder.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLDECODER_H
-#define NDN_BINARYXMLDECODER_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include "../errors.h"
-#include "../util/blob.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_BinaryXmlDecoder {
- uint8_t *input;
- size_t inputLength;
- size_t offset;
- // peekDTag sets and checks these, and readElementStartDTag uses them to avoid reading again.
- size_t previouslyPeekedDTagStartOffset;
- size_t previouslyPeekedDTagEndOffset;
- unsigned int previouslyPeekedDTag;
-};
-
-static inline void ndn_BinaryXmlDecoder_initialize(struct ndn_BinaryXmlDecoder *self, uint8_t *input, size_t inputLength)
-{
- self->input = input;
- self->inputLength = inputLength;
- self->offset = 0;
- self->previouslyPeekedDTagStartOffset = (size_t)-1;
-}
-
-/**
- * Decode the header's type and value from self's input starting at offset. Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param type output for the header type
- * @param value output for the header value
- * @return 0 for success, else an error code for read past the end of the input or if the initial byte is zero
- */
-ndn_Error ndn_BinaryXmlDecoder_decodeTypeAndValue(struct ndn_BinaryXmlDecoder *self, unsigned int *type, unsigned int *value);
-
-/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
- * Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @return 0 for success, else an error code, including an error if not the expected tag
- */
-ndn_Error ndn_BinaryXmlDecoder_readElementStartDTag(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag);
-
-/**
- * Read one byte from self's input starting at offset, expecting it to be the element close.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including an error if not the element close
- */
-ndn_Error ndn_BinaryXmlDecoder_readElementClose(struct ndn_BinaryXmlDecoder *self);
-
-/**
- * Decode the header from self's input starting at offset, and if it is a DTAG where the value is the expectedTag,
- * then set gotExpectedTag to 1, else 0. Do not update offset, including if returning an error.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param gotExpectedTag output a 1 if got the expected tag, else 0
- * @return 0 for success, else an error code for read past the end of the input
- */
-ndn_Error ndn_BinaryXmlDecoder_peekDTag(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int *gotExpectedTag);
-
-/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
- * Then read one item of any type (presumably BLOB, UDATA, TAG or ATTR) and return the item's value and length.
- * However, if allowNull is 1, then the item may be absent.
- * Finally, read the element close. Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param allowNull 1 if the binary item may be missing
- * @param value output a pointer to the binary data inside self's input buffer. However, if allowNull is 1 and the
- * binary data item is absent, then set value and length to 0.
- * @return 0 for success, else an error code, including an error if not the expected tag, or if allowNull is 0
- * and the binary data is absent
- */
-ndn_Error ndn_BinaryXmlDecoder_readBinaryDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int allowNull, struct ndn_Blob *value);
-
-/**
- * Peek at the next element and if it is the expectedTag, call ndn_BinaryXmlDecoder_readBinaryDTagElement.
- * Otherwise, set value and valueLength to 0.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param allowNull 1 if the binary item may be missing
- * @param value output a pointer to the binary data inside self's input buffer. However, if allowNull is 1 and the
- * binary data item is absent, then set value and length to 0.
- * @return 0 for success, else an error code, including if allowNull is 0 and the binary data is absent
- */
-ndn_Error ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int allowNull, struct ndn_Blob *value);
-
-/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
- * Then read one item expecting it to be type UDATA, and return the item's value and length.
- * Finally, read the element close. Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param value output a pointer to the binary data inside self's input buffer.
- * @return 0 for success, else an error code, including an error if not the expected tag, or if the item is not UDATA.
- */
-ndn_Error ndn_BinaryXmlDecoder_readUDataDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, struct ndn_Blob *value);
-
-/**
- * Peek at the next element and if it is the expectedTag, call ndn_BinaryXmlDecoder_readUDataDTagElement.
- * Otherwise, set value and valueLength to 0.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param value output a pointer to the binary data inside self's input buffer. However, if allowNull is 1 and the
- * binary data item is absent, then set value and length to 0.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_BinaryXmlDecoder_readOptionalUDataDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, struct ndn_Blob *value);
-
-/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
- * Then read one item expecting it to be type UDATA, parse it as an unsigned decimal integer and return the integer.
- * Finally, read the element close. Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param value output the unsigned integer
- * @return 0 for success, else an error code, including an error if not the expected tag, or if the item is not UDATA,
- * or can't parse the integer
- */
-ndn_Error ndn_BinaryXmlDecoder_readUnsignedIntegerDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, unsigned int *value);
-
-/**
- * Peek at the next element, and if it has the expectedTag then call ndn_BinaryXmlDecoder_readUnsignedIntegerDTagElement.
- * Otherwise, set value to -1.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param value output the unsigned integer cast to int, or -1 if the next element doesn't have expectedTag.
- * @return 0 for success, else an error code, including an error if the item is not UDATA,
- * or can't parse the integer
- */
-ndn_Error ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, int *value);
-
-/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
- * Then read one item, parse it as an unsigned big endian integer in 4096 ticks per second, and convert it to milliseconds.
- * Finally, read the element close. Update offset.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param milliseconds output the number of milliseconds
- * @return 0 for success, else an error code, including an error if not the expected tag
- */
-ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
-
-/**
- * Peek at the next element, and if it has the expectedTag then call ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement.
- * Otherwise, set value to -1.0 .
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param expectedTag the expected value for DTAG
- * @param milliseconds output the number of milliseconds, or -1.0 if the next element doesn't have expectedTag.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
-
-/**
- * Interpret the bytes as an unsigned big endian integer and convert to a double. Don't check for overflow.
- * We use a double because it is large enough to represent NDN time (4096 ticks per second since 1970).
- * @param bytes pointer to the array of bytes
- * @param bytesLength the length of bytes
- * @return the result
- */
-double ndn_BinaryXmlDecoder_unsignedBigEndianToDouble(uint8_t *bytes, size_t bytesLength);
-
-/**
- * Set the offset into the input, used for the next read.
- * @param self pointer to the ndn_BinaryXmlDecoder struct
- * @param offset the new offset
- */
-static inline void ndn_BinaryXmlDecoder_seek(struct ndn_BinaryXmlDecoder *self, size_t offset)
-{
- self->offset = offset;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-element-reader.c b/src/c/encoding/binary-xml-element-reader.c
deleted file mode 100644
index 350a978..0000000
--- a/src/c/encoding/binary-xml-element-reader.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml-element-reader.h"
-
-ndn_Error ndn_BinaryXmlElementReader_onReceivedData
- (struct ndn_BinaryXmlElementReader *self, uint8_t *data, size_t dataLength)
-{
- // Process multiple objects in the data.
- while(1) {
- // Scan the input to check if a whole binary XML object has been read.
- ndn_BinaryXmlStructureDecoder_seek(&self->structureDecoder, 0);
-
- ndn_Error error;
- if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(&self->structureDecoder, data, dataLength)))
- return error;
- if (self->structureDecoder.gotElementEnd) {
- // Got the remainder of an element. Report to the caller.
- if (self->usePartialData) {
- // We have partial data from a previous call, so append this data and point to partialData.
- if ((error = ndn_DynamicUInt8Array_set(&self->partialData, data, self->structureDecoder.offset, self->partialDataLength)))
- return error;
- self->partialDataLength += dataLength;
-
- (*self->elementListener->onReceivedElement)(self->elementListener, self->partialData.array, self->partialDataLength);
- // Assume we don't need to use partialData anymore until needed.
- self->usePartialData = 0;
- }
- else
- // We are not using partialData, so just point to the input data buffer.
- (*self->elementListener->onReceivedElement)(self->elementListener, data, self->structureDecoder.offset);
-
- // Need to read a new object.
- data += self->structureDecoder.offset;
- dataLength -= self->structureDecoder.offset;
- ndn_BinaryXmlStructureDecoder_initialize(&self->structureDecoder);
- if (dataLength == 0)
- // No more data in the packet.
- return NDN_ERROR_success;
-
- // else loop back to decode.
- }
- else {
- // Save remaining data for a later call.
- if (!self->usePartialData) {
- self->usePartialData = 1;
- self->partialDataLength = 0;
- }
-
- if ((error = ndn_DynamicUInt8Array_set(&self->partialData, data, dataLength, self->partialDataLength)))
- return error;
- self->partialDataLength += dataLength;
-
- return NDN_ERROR_success;
- }
- }
-}
diff --git a/src/c/encoding/binary-xml-element-reader.h b/src/c/encoding/binary-xml-element-reader.h
deleted file mode 100644
index 194f397..0000000
--- a/src/c/encoding/binary-xml-element-reader.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARY_XML_ELEMENT_READER_H
-#define NDN_BINARY_XML_ELEMENT_READER_H
-
-#include <ndn-cpp-dev/c/encoding/element-listener.h>
-#include "../errors.h"
-#include "binary-xml-structure-decoder.h"
-#include "../util/dynamic-uint8-array.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * A BinaryXmlElementReader lets you call ndn_BinaryXmlElementReader_onReceivedData multiple times which uses an
- * ndn_BinaryXmlStructureDecoder to detect the end of a binary XML element and calls
- * (*elementListener->onReceivedElement)(element, elementLength) with the element.
- * This handles the case where a single call to onReceivedData may contain multiple elements.
- */
-struct ndn_BinaryXmlElementReader {
- struct ndn_ElementListener *elementListener;
- struct ndn_BinaryXmlStructureDecoder structureDecoder;
- int usePartialData;
- struct ndn_DynamicUInt8Array partialData;
- size_t partialDataLength;
-};
-
-/**
- * Initialize an ndn_BinaryXmlElementReader struct with the elementListener and a buffer for saving partial data.
- * @param self pointer to the ndn_BinaryXmlElementReader struct
- * @param elementListener pointer to the ndn_ElementListener used by ndn_BinaryXmlElementReader_onReceivedData.
- * @param buffer the allocated buffer. If reallocFunction is null, this should be large enough to save a full element, perhaps 8000 bytes.
- * @param bufferLength the length of the buffer
- * @param reallocFunction see ndn_DynamicUInt8Array_ensureLength. This may be 0.
- */
-static inline void ndn_BinaryXmlElementReader_initialize
- (struct ndn_BinaryXmlElementReader *self, struct ndn_ElementListener *elementListener,
- uint8_t *buffer, size_t bufferLength, uint8_t * (*reallocFunction)(struct ndn_DynamicUInt8Array *self, uint8_t *, size_t))
-{
- self->elementListener = elementListener;
- ndn_BinaryXmlStructureDecoder_initialize(&self->structureDecoder);
- self->usePartialData = 0;
- ndn_DynamicUInt8Array_initialize(&self->partialData, buffer, bufferLength, reallocFunction);
-}
-
-/**
- * Continue to read binary XML data until the end of an element, then call (*elementListener->onReceivedElement)(element, elementLength).
- * The buffer passed to onReceivedElement is only valid during this call. If you need the data later, you must copy.
- * @param self pointer to the ndn_BinaryXmlElementReader struct
- * @param data pointer to the buffer with the binary XML bytes
- * @param dataLength length of data
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlElementReader_onReceivedData
- (struct ndn_BinaryXmlElementReader *self, uint8_t *data, size_t dataLength);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-encoder.c b/src/c/encoding/binary-xml-encoder.c
deleted file mode 100644
index e27cbbc..0000000
--- a/src/c/encoding/binary-xml-encoder.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from BinaryXMLEncoder.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include <math.h>
-#include "../util/ndn_memory.h"
-#include "binary-xml.h"
-#include "binary-xml-encoder.h"
-
-enum {
- ENCODING_LIMIT_1_BYTE = ((1 << ndn_BinaryXml_TT_VALUE_BITS) - 1),
- ENCODING_LIMIT_2_BYTES = ((1 << (ndn_BinaryXml_TT_VALUE_BITS + ndn_BinaryXml_REGULAR_VALUE_BITS)) - 1),
- ENCODING_LIMIT_3_BYTES = ((1 << (ndn_BinaryXml_TT_VALUE_BITS + 2 * ndn_BinaryXml_REGULAR_VALUE_BITS)) - 1)
-};
-
-/**
- * Call ndn_DynamicUInt8Array_ensureLength to ensure that there is enough room in the output, and copy
- * array to the output. This does not write a header.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param array the array to copy
- * @param arrayLength the length of the array
- * @return 0 for success, else an error code
- */
-static ndn_Error writeArray(struct ndn_BinaryXmlEncoder *self, uint8_t *array, size_t arrayLength)
-{
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + arrayLength)))
- return error;
-
- ndn_memcpy(self->output->array + self->offset, array, arrayLength);
- self->offset += arrayLength;
-
- return NDN_ERROR_success;
-}
-
-/**
- * Return the number of bytes to encode a header of value x.
- */
-static size_t getNHeaderEncodingBytes(unsigned int x)
-{
- // Do a quick check for pre-compiled results.
- if (x <= ENCODING_LIMIT_1_BYTE)
- return 1;
- if (x <= ENCODING_LIMIT_2_BYTES)
- return 2;
- if (x <= ENCODING_LIMIT_3_BYTES)
- return 3;
-
- size_t nBytes = 1;
-
- // Last byte gives you TT_VALUE_BITS.
- // Remainder each gives you REGULAR_VALUE_BITS.
- x >>= ndn_BinaryXml_TT_VALUE_BITS;
- while (x != 0) {
- ++nBytes;
- x >>= ndn_BinaryXml_REGULAR_VALUE_BITS;
- }
-
- return nBytes;
-}
-
-/**
- * Reverse the length bytes in array.
- * @param array
- * @param length
- */
-static void reverse(uint8_t *array, size_t length)
-{
- if (length == 0)
- return;
-
- uint8_t *left = array;
- uint8_t *right = array + length - 1;
- while (left < right) {
- // Swap.
- uint8_t temp = *left;
- *left = *right;
- *right = temp;
-
- ++left;
- --right;
- }
-}
-
-/**
- * Write x as an unsigned decimal integer to the output with the digits in reverse order, using ndn_DynamicUInt8Array_ensureLength.
- * This does not write a header.
- * We encode in reverse order, because this is the natural way to encode the digits, and the caller can reverse as needed.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param x the unsigned int to write
- * @return 0 for success, else an error code
- */
-static ndn_Error encodeReversedUnsignedDecimalInt(struct ndn_BinaryXmlEncoder *self, unsigned int x)
-{
- while (1) {
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + 1)))
- return error;
-
- self->output->array[self->offset++] = (uint8_t)(x % 10 + '0');
- x /= 10;
-
- if (x == 0)
- break;
- }
-
- return NDN_ERROR_success;
-}
-
-/**
- * Reverse the buffer in self->output->array from startOffset to the current offset, then shift it right by the amount
- * needed to prefix a header with type, then encode the header at startOffset.
- * We reverse and shift in the same function to avoid unnecessary copying if we first reverse then shift.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param startOffset the offset in self->output->array of the start of the buffer to shift right
- * @param type the header type
- * @return 0 for success, else an error code
- */
-static ndn_Error reverseBufferAndInsertHeader
- (struct ndn_BinaryXmlEncoder *self, size_t startOffset, unsigned int type)
-{
- size_t nBufferBytes = self->offset - startOffset;
- size_t nHeaderBytes = getNHeaderEncodingBytes(nBufferBytes);
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + nHeaderBytes)))
- return error;
-
- // To reverse and shift at the same time, we first shift nHeaderBytes to the destination while reversing,
- // then reverse the remaining bytes in place.
- uint8_t *from = self->output->array + startOffset;
- uint8_t *fromEnd = from + nHeaderBytes;
- uint8_t *to = self->output->array + startOffset + nBufferBytes + nHeaderBytes - 1;
- while (from < fromEnd)
- *(to--) = *(from++);
- // Reverse the remaining bytes in place (if any).
- if (nBufferBytes > nHeaderBytes)
- reverse(self->output->array + startOffset + nHeaderBytes, nBufferBytes - nHeaderBytes);
-
- // Override the offset to force encodeTypeAndValue to encode at startOffset, then fix the offset.
- self->offset = startOffset;
- if ((error = ndn_BinaryXmlEncoder_encodeTypeAndValue(self, type, nBufferBytes)))
- // We don't really expect to get an error, since we have already ensured the length.
- return error;
- self->offset = startOffset + nHeaderBytes + nBufferBytes;
-
- return NDN_ERROR_success;
-}
-
-/**
- * Split the absolute value of x, rounded to an integer into 32 bit unsigned integers hi32 and lo32.
- * We need this because not all C compilers support 64 bit long long integers, so we carry around
- * a high precision value as a double, which we assume has more than 32 bits.
- * But we want to do bit-wise operations on integers.
- * @param x the double value
- * @param hi32 output the high 32 bits
- * @param lo32 output the low 32 bits
- */
-static inline void splitAbsDouble(double x, unsigned long *hi32, unsigned long *lo32)
-{
- if (x < 0)
- x = -x;
- x = round(x);
-
- double twoPower32 = 4294967296.0;
- double lo32Double = fmod(x, twoPower32);
- *lo32 = (unsigned long)lo32Double;
- *hi32 = (unsigned long)((x - lo32Double) / twoPower32);
-}
-
-ndn_Error ndn_BinaryXmlEncoder_encodeTypeAndValue(struct ndn_BinaryXmlEncoder *self, unsigned int type, unsigned int value)
-{
- if (type > ndn_BinaryXml_UDATA)
- return NDN_ERROR_header_type_is_out_of_range;
-
- // Encode backwards. Calculate how many bytes we need.
- size_t nEncodingBytes = getNHeaderEncodingBytes(value);
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + nEncodingBytes)))
- return error;
-
- // Bottom 4 bits of value go in last byte with tag.
- self->output->array[self->offset + nEncodingBytes - 1] =
- ((ndn_BinaryXml_TT_MASK & type) |
- ((ndn_BinaryXml_TT_VALUE_MASK & value) << ndn_BinaryXml_TT_BITS)) |
- ndn_BinaryXml_TT_FINAL; // set top bit for last byte
- value >>= ndn_BinaryXml_TT_VALUE_BITS;
-
- // Rest of value goes into preceding bytes, 7 bits per byte. (Zero top bit is "more" flag.)
- size_t i = self->offset + nEncodingBytes - 2;
- while (value != 0 && i >= self->offset) {
- self->output->array[i] = (value & ndn_BinaryXml_REGULAR_VALUE_MASK);
- value >>= ndn_BinaryXml_REGULAR_VALUE_BITS;
- --i;
- }
- if (value != 0)
- // This should not happen if getNHeaderEncodingBytes is correct.
- return NDN_ERROR_encodeTypeAndValue_miscalculated_N_encoding_bytes;
-
- self->offset+= nEncodingBytes;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeElementClose(struct ndn_BinaryXmlEncoder *self)
-{
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + 1)))
- return error;
-
- self->output->array[self->offset] = ndn_BinaryXml_CLOSE;
- self->offset += 1;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeBlob(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_encodeTypeAndValue(self, ndn_BinaryXml_BLOB, value->length)))
- return error;
-
- if ((error = writeArray(self, value->value, value->length)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeBlobDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(self, tag)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeBlob(self, value)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeUData(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_encodeTypeAndValue(self, ndn_BinaryXml_UDATA, value->length)))
- return error;
-
- if ((error = writeArray(self, value->value, value->length)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeUDataDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(self, tag)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeUData(self, value)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalInt(struct ndn_BinaryXmlEncoder *self, unsigned int value)
-{
- // First write the decimal int (to find out how many bytes it is), then shift it forward to make room for the header.
- size_t startOffset = self->offset;
-
- ndn_Error error;
- if ((error = encodeReversedUnsignedDecimalInt(self, value)))
- return error;
-
- if ((error = reverseBufferAndInsertHeader(self, startOffset, ndn_BinaryXml_UDATA)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, unsigned int value)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(self, tag)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeUnsignedDecimalInt(self, value)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeAbsDoubleBigEndianBlob(struct ndn_BinaryXmlEncoder *self, double value)
-{
- unsigned long hi32, lo32;
- splitAbsDouble(value, &hi32, &lo32);
-
- // First encode the big endian backwards, then reverseBufferAndInsertHeader will reverse it.
- size_t startOffset = self->offset;
-
- ndn_Error error;
- while (lo32 != 0) {
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + 1)))
- return error;
-
- self->output->array[self->offset++] = (uint8_t)(lo32 & 0xff);
- lo32 >>= 8;
- }
-
- if (hi32 != 0) {
- // Pad the lo values out to 4 bytes.
- while (self->offset - startOffset < 4) {
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + 1)))
- return error;
-
- self->output->array[self->offset++] = 0;
- }
-
- // Encode hi32
- while (hi32 != 0) {
- if ((error = ndn_DynamicUInt8Array_ensureLength(self->output, self->offset + 1)))
- return error;
-
- self->output->array[self->offset++] = (uint8_t)(hi32 & 0xff);
- hi32 >>= 8;
- }
- }
-
- if ((error = reverseBufferAndInsertHeader(self, startOffset, ndn_BinaryXml_BLOB)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, double milliseconds)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(self, tag)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeAbsDoubleBigEndianBlob(self, (milliseconds / 1000.0) * 4096.0)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(self)))
- return error;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-encoder.h b/src/c/encoding/binary-xml-encoder.h
deleted file mode 100644
index 81fa6b9..0000000
--- a/src/c/encoding/binary-xml-encoder.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLENCODER_H
-#define NDN_BINARYXMLENCODER_H
-
-#include "../errors.h"
-#include "../util/dynamic-uint8-array.h"
-#include "../util/blob.h"
-#include "binary-xml.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** An ndn_BinaryXmlEncoder struct is used by all the encoding functions. You should initialize it with
- * ndn_BinaryXmlEncoder_initialize.
- */
-struct ndn_BinaryXmlEncoder {
- struct ndn_DynamicUInt8Array *output; /**< A pointer to a ndn_DynamicUInt8Array which receives the encoded output */
- size_t offset; /**< the offset into output.array for the next encoding */
-};
-
-/**
- * Initialize an ndn_BinaryXmlEncoder_initialize struct with the arguments for initializing the ndn_DynamicUInt8Array.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param output A pointer to a ndn_DynamicUInt8Array struct which receives the encoded output. The struct must
- * remain valid during the entire life of this ndn_BinaryXmlEncoder. If the output->realloc
- * function pointer is null, its array must be large enough to receive the entire encoding.
- */
-static inline void ndn_BinaryXmlEncoder_initialize(struct ndn_BinaryXmlEncoder *self, struct ndn_DynamicUInt8Array *output)
-{
- self->output = output;
- self->offset = 0;
-}
-
-/**
- * Encode a header with the type and value and write it to self->output.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param type the header type
- * @param value the header value
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_encodeTypeAndValue(struct ndn_BinaryXmlEncoder *self, unsigned int type, unsigned int value);
-
-/**
- * Write an element start header using DTAG with the tag to self->output.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @return 0 for success, else an error code
- */
-static inline ndn_Error ndn_BinaryXmlEncoder_writeElementStartDTag(struct ndn_BinaryXmlEncoder *self, unsigned int tag)
-{
- return ndn_BinaryXmlEncoder_encodeTypeAndValue(self, ndn_BinaryXml_DTAG, tag);
-}
-
-/**
- * Write an element close to self->output.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeElementClose(struct ndn_BinaryXmlEncoder *self);
-
-/**
- * Write a BLOB header, then the bytes of the blob value to self->output.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeBlob(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value);
-
-/**
- * Write an element start header using DTAG with the tag to self->output, then the blob, then an element close.
- * (If you want to just write the blob, use ndn_BinaryXmlEncoder_writeBlob .)
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeBlobDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value);
-
-/**
- * If value or valueLen is 0 then do nothing, otherwise call ndn_BinaryXmlEncoder_writeBlobDTagElement.
- * @param self A pointer to the ndn_BinaryXmlEncoder struct.
- * @param tag The DTAG tag.
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-static inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalBlobDTagElement
- (struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
-{
- if (value->value && value->length > 0)
- return ndn_BinaryXmlEncoder_writeBlobDTagElement(self, tag, value);
- else
- return NDN_ERROR_success;
-}
-
-/**
- * Write a UDATA header, then the bytes of the UDATA value to self->output.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeUData(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value);
-
-/**
- * Write an element start header using DTAG with the tag to self->output, then the UDATA value, then an element close.
- * (If you want to just write the UDATA value, use ndn_BinaryXmlEncoder_writeUData .)
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeUDataDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value);
-
-/**
- * If value or valueLen is 0 then do nothing, otherwise call ndn_BinaryXmlEncoder_writeUDataDTagElement.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param value A Blob with the array of bytes for the value.
- * @return 0 for success, else an error code
- */
-static inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalUDataDTagElement
- (struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
-{
- if (value->value && value->length > 0)
- return ndn_BinaryXmlEncoder_writeUDataDTagElement(self, tag, value);
- else
- return NDN_ERROR_success;
-}
-
-/**
- * Write a UDATA header, then the value as an unsigned decimal integer.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param value the unsigned int
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalInt(struct ndn_BinaryXmlEncoder *self, unsigned int value);
-
-/**
- * Write an element start header using DTAG with the tag to self->output, then the value as an unsigned decimal integer,
- * then an element close.
- * (If you want to just write the integer, use ndn_BinaryXmlEncoder_writeUnsignedDecimalInt .)
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param value the unsigned int
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, unsigned int value);
-
-/**
- * If value is negative then do nothing, otherwise call ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param value negative for none, otherwise use (unsigned int)value
- * @return 0 for success, else an error code
- */
-static inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, int value)
-{
- if (value >= 0)
- return ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement(self, tag, (size_t)value);
- else
- return NDN_ERROR_success;
-}
-
-/**
- * Write a BLOB header, then the absolute value of value, rounded to an integer, to self->output encoded as big endian.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param value the double to encode as big endian. If value is 0, the big endian encoding has zero bytes.
- * The value is converted to absolute value.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeAbsDoubleBigEndianBlob(struct ndn_BinaryXmlEncoder *self, double value);
-
-/**
- * Write an element start header using DTAG with the tag to self->output, then the absolute value of milliseconds
- * as a big endian BLOB converted to 4096 ticks per second, then an element close.
- * (If you want to just write the integer, use ndn_BinaryXmlEncoder_writeUnsignedDecimalInt .)
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param milliseconds the the number of milliseconds
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, double milliseconds);
-
-/**
- * If milliseconds is negative then do nothing, otherwise call ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement.
- * @param self pointer to the ndn_BinaryXmlEncoder struct
- * @param tag the DTAG tag
- * @param milliseconds negative for none, otherwise the number of milliseconds
- * @return 0 for success, else an error code
- */
-static inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
- (struct ndn_BinaryXmlEncoder *self, unsigned int tag, double milliseconds)
-{
- if (milliseconds >= 0)
- return ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement(self, tag, milliseconds);
- else
- return NDN_ERROR_success;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/encoding/binary-xml-forwarding-entry.c b/src/c/encoding/binary-xml-forwarding-entry.c
deleted file mode 100644
index d7ed52a..0000000
--- a/src/c/encoding/binary-xml-forwarding-entry.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from ForwardingEntry.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml.h"
-#include "binary-xml-forwarding-entry.h"
-#include "binary-xml-name.h"
-#include "binary-xml-key.h"
-#include "binary-xml-publisher-public-key-digest.h"
-
-ndn_Error ndn_encodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlEncoder *encoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_ForwardingEntry)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUDataDTagElement
- (encoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action)))
- return error;
- if ((error = ndn_encodeBinaryXmlName(&forwardingEntry->prefix, encoder)))
- return error;
- // This will skip encoding if there is no publisherPublicKeyDigest.
- if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, encoder)))
- return error;
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_FaceID, forwardingEntry->faceId)))
- return error;
- if ((error = ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_ForwardingFlags,
- ndn_ForwardingFlags_getForwardingEntryFlags(&forwardingEntry->forwardingFlags))))
- return error;
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_FreshnessSeconds, forwardingEntry->freshnessSeconds)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_ForwardingEntry)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalUDataDTagElement
- (decoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action)))
- return error;
- if ((error = ndn_decodeBinaryXmlName(&forwardingEntry->prefix, decoder)))
- return error;
- if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, decoder)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_FaceID, &forwardingEntry->faceId)))
- return error;
-
- int forwardingEntryFlags;
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_ForwardingFlags, &forwardingEntryFlags)))
- return error;
- if (forwardingEntryFlags >= 0)
- ndn_ForwardingFlags_setForwardingEntryFlags(&forwardingEntry->forwardingFlags, forwardingEntryFlags);
- else
- // This sets the default flags.
- ndn_ForwardingFlags_initialize(&forwardingEntry->forwardingFlags);
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_FreshnessSeconds, &forwardingEntry->freshnessSeconds)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-forwarding-entry.h b/src/c/encoding/binary-xml-forwarding-entry.h
deleted file mode 100644
index b08f292..0000000
--- a/src/c/encoding/binary-xml-forwarding-entry.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARY_XML_FORWARDING_ENTRY_H
-#define NDN_BINARY_XML_FORWARDING_ENTRY_H
-
-#include "../errors.h"
-#include "../forwarding-entry.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Encode the ndn_ForwardingEntry struct using Binary XML.
- * @param forwardingEntry pointer to the ndn_ForwardingEntry struct
- * @param encoder pointer to the ndn_BinaryXmlEncoder struct
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_encodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlEncoder *encoder);
-
-/**
- * Expect the next element to be a Binary XML ForwardingEntry and decode into the ndn_ForwardingEntry struct.
- * @param forwardingEntry pointer to the ndn_ForwardingEntry struct
- * @param decoder pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including if the next element is not KeyLocator.
- */
-ndn_Error ndn_decodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-interest.c b/src/c/encoding/binary-xml-interest.c
deleted file mode 100644
index 00da3e4..0000000
--- a/src/c/encoding/binary-xml-interest.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from Interest.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-#include "binary-xml-name.h"
-#include "binary-xml-publisher-public-key-digest.h"
-#include "binary-xml-interest.h"
-
-static ndn_Error encodeExclude(struct ndn_Exclude *exclude, struct ndn_BinaryXmlEncoder *encoder)
-{
- if (exclude->nEntries == 0)
- return NDN_ERROR_success;
-
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Exclude)))
- return error;
-
- // TODO: Do we want to order the components (except for ANY)?
- size_t i;
- for (i = 0; i < exclude->nEntries; ++i) {
- struct ndn_ExcludeEntry *entry = &exclude->entries[i];
-
- if (entry->type == ndn_Exclude_COMPONENT) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Component, &entry->component.value)))
- return error;
- }
- else if (entry->type == ndn_Exclude_ANY) {
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Any)))
- return error;
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
- }
- else
- return NDN_ERROR_unrecognized_ndn_ExcludeType;
- }
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-static ndn_Error decodeExclude(struct ndn_Exclude *exclude, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Exclude)))
- return error;
-
- exclude->nEntries = 0;
- while (1) {
- int gotExpectedTag;
-
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Component, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- // Component
- struct ndn_Blob component;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Component, 0, &component)))
- return error;
-
- // Add the component entry.
- if (exclude->nEntries >= exclude->maxEntries)
- return NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude;
- ndn_ExcludeEntry_initialize(exclude->entries + exclude->nEntries, ndn_Exclude_COMPONENT, component.value, component.length);
- ++exclude->nEntries;
-
- continue;
- }
-
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Any, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- // Any
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Any)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- // Add the any entry.
- if (exclude->nEntries >= exclude->maxEntries)
- return NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude;
- ndn_ExcludeEntry_initialize(exclude->entries + exclude->nEntries, ndn_Exclude_ANY, 0, 0);
- ++exclude->nEntries;
-
- continue;
- }
-
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Bloom, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- // Skip the Bloom and treat it as Any.
- struct ndn_Blob value;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Bloom, 0, &value)))
- return error;
-
- // Add the any entry.
- if (exclude->nEntries >= exclude->maxEntries)
- return NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude;
- ndn_ExcludeEntry_initialize(exclude->entries + exclude->nEntries, ndn_Exclude_ANY, 0, 0);
- ++exclude->nEntries;
-
- continue;
- }
-
- // Else no more entries.
- break;
- }
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_encodeBinaryXmlInterest(struct ndn_Interest *interest, struct ndn_BinaryXmlEncoder *encoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Interest)))
- return error;
-
- if ((error = ndn_encodeBinaryXmlName(&interest->name, encoder)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_MinSuffixComponents, interest->minSuffixComponents)))
- return error;
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_MaxSuffixComponents, interest->maxSuffixComponents)))
- return error;
-
- // This will skip encoding if there is no publisherPublicKeyDigest.
- if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&interest->publisherPublicKeyDigest, encoder)))
- return error;
-
- // This will skip encoding if there is no exclude.
- if ((error = encodeExclude(&interest->exclude, encoder)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_ChildSelector, interest->childSelector)))
- return error;
- if (interest->answerOriginKind >= 0 && interest->answerOriginKind != ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND) {
- if ((error = ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_AnswerOriginKind, (unsigned int)interest->answerOriginKind)))
- return error;
- }
- if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
- (encoder, ndn_BinaryXml_DTag_Scope, interest->scope)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
- (encoder, ndn_BinaryXml_DTag_InterestLifetime, interest->interestLifetimeMilliseconds)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeOptionalBlobDTagElement(encoder, ndn_BinaryXml_DTag_Nonce, &interest->nonce)))
- return error;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlInterest(struct ndn_Interest *interest, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Interest)))
- return error;
-
- if ((error = ndn_decodeBinaryXmlName(&interest->name, decoder)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_MinSuffixComponents, &interest->minSuffixComponents)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_MaxSuffixComponents, &interest->maxSuffixComponents)))
- return error;
-
- if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&interest->publisherPublicKeyDigest, decoder)))
- return error;
-
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Exclude, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = decodeExclude(&interest->exclude, decoder)))
- return error;
- }
- else
- interest->exclude.nEntries = 0;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_ChildSelector, &interest->childSelector)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_AnswerOriginKind, &interest->answerOriginKind)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
- (decoder, ndn_BinaryXml_DTag_Scope, &interest->scope)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
- (decoder, ndn_BinaryXml_DTag_InterestLifetime, &interest->interestLifetimeMilliseconds)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readOptionalBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_Nonce, 0, &interest->nonce)))
- return error;
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-interest.h b/src/c/encoding/binary-xml-interest.h
deleted file mode 100644
index 532afe4..0000000
--- a/src/c/encoding/binary-xml-interest.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLINTEREST_H
-#define NDN_BINARYXMLINTEREST_H
-
-#include "../errors.h"
-#include "../interest.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ndn_Error ndn_encodeBinaryXmlInterest(struct ndn_Interest *interest, struct ndn_BinaryXmlEncoder *encoder);
-
-ndn_Error ndn_decodeBinaryXmlInterest(struct ndn_Interest *interest, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/encoding/binary-xml-key.c b/src/c/encoding/binary-xml-key.c
deleted file mode 100644
index bc55911..0000000
--- a/src/c/encoding/binary-xml-key.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from Key.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml.h"
-#include "binary-xml-structure-decoder.h"
-#include "binary-xml-key.h"
-#include "binary-xml-name.h"
-
-static ndn_Error decodeKeyNameData(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder)
-{
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- // Key name data is omitted.
- keyLocator->keyNameType = -1;
- keyLocator->keyData.length = 0;
- }
- }
- }
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_encodeBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlEncoder *encoder)
-{
- if ((int)keyLocator->type < 0)
- return NDN_ERROR_success;
-
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_KeyLocator)))
- return error;
-
- if (keyLocator->type == ndn_KeyLocatorType_KEY) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Key, &keyLocator->keyData)))
- return error;
- }
- else if (keyLocator->type == ndn_KeyLocatorType_CERTIFICATE) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Certificate, &keyLocator->keyData)))
- return error;
- }
- else if (keyLocator->type == ndn_KeyLocatorType_KEYNAME) {
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_KeyName)))
- return error;
- if ((error = ndn_encodeBinaryXmlName(&keyLocator->keyName, encoder)))
- return error;
-
- if ((int)keyLocator->keyNameType >= 0 && keyLocator->keyData.length > 0) {
- if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &keyLocator->keyData)))
- return error;
- }
- else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, &keyLocator->keyData)))
- return error;
- }
- else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, &keyLocator->keyData)))
- return error;
- }
- else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, &keyLocator->keyData)))
- return error;
- }
- else
- return NDN_ERROR_unrecognized_ndn_KeyNameType;
- }
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
- }
- else
- return NDN_ERROR_unrecognized_ndn_KeyLocatorType;
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_KeyLocator)))
- return error;
-
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Key, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->type = ndn_KeyLocatorType_KEY;
-
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Key, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Certificate, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->type = ndn_KeyLocatorType_CERTIFICATE;
-
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_Certificate, 0, &keyLocator->keyData)))
- return error;
- }
- else {
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_KeyName, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- keyLocator->type = ndn_KeyLocatorType_KEYNAME;
-
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_KeyName)))
- return error;
- if ((error = ndn_decodeBinaryXmlName(&keyLocator->keyName, decoder)))
- return error;
- if ((error = decodeKeyNameData(keyLocator, decoder)))
- return error;
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
- }
- else
- return NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type;
- }
- }
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeOptionalBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder)
-{
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_KeyLocator, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = ndn_decodeBinaryXmlKeyLocator(keyLocator, decoder)))
- return error;
- }
- else
- ndn_KeyLocator_initialize(keyLocator, keyLocator->keyName.components, keyLocator->keyName.maxComponents);
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-key.h b/src/c/encoding/binary-xml-key.h
deleted file mode 100644
index efd8f54..0000000
--- a/src/c/encoding/binary-xml-key.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLKEY_H
-#define NDN_BINARYXMLKEY_H
-
-#include "../key-locator.h"
-#include "../errors.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Encode the ndn_KeyLocator struct using Binary XML. If keyLocator->type is -1, then do nothing.
- * @param keyLocator pointer to the ndn_KeyLocator struct
- * @param encoder pointer to the ndn_BinaryXmlEncoder struct
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_encodeBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlEncoder *encoder);
-
-/**
- * Expect the next element to be a Binary XML KeyLocator and decode into the ndn_KeyLocator struct.
- * @param keyLocator pointer to the ndn_KeyLocator struct
- * @param decoder pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including if the next element is not KeyLocator.
- */
-ndn_Error ndn_decodeBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder);
-
-/**
- * Peek the next element and if it is a Binary XML KeyLocator and decode into the ndn_KeyLocator struct.
- * Otherwise, set the ndn_KeyLocator struct to none.
- * @param keyLocator pointer to the ndn_KeyLocator struct
- * @param decoder pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including if the next element is not KeyLocator.
- */
-ndn_Error ndn_decodeOptionalBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-name.c b/src/c/encoding/binary-xml-name.c
deleted file mode 100644
index 8df81c3..0000000
--- a/src/c/encoding/binary-xml-name.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from Name.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-#include "binary-xml-name.h"
-
-ndn_Error ndn_encodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlEncoder *encoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Name)))
- return error;
-
- size_t i;
- for (i = 0; i < name->nComponents; ++i) {
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Component, &name->components[i].value)))
- return error;
- }
-
- if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Name)))
- return error;
-
- name->nComponents = 0;
- while (1) {
- int gotExpectedTag;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Component, &gotExpectedTag)))
- return error;
-
- if (!gotExpectedTag)
- // No more components.
- break;
-
- struct ndn_Blob component;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Component, 0, &component)))
- return error;
- if ((error = ndn_Name_appendBlob(name, &component)))
- return error;
- }
-
- if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
- return error;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-name.h b/src/c/encoding/binary-xml-name.h
deleted file mode 100644
index 369dfc5..0000000
--- a/src/c/encoding/binary-xml-name.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLNAME_H
-#define NDN_BINARYXMLNAME_H
-
-#include "../errors.h"
-#include "../name.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ndn_Error ndn_encodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlEncoder *encoder);
-
-ndn_Error ndn_decodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/encoding/binary-xml-publisher-public-key-digest.c b/src/c/encoding/binary-xml-publisher-public-key-digest.c
deleted file mode 100644
index 4748147..0000000
--- a/src/c/encoding/binary-xml-publisher-public-key-digest.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * Derived from PublisherPublicKeyDigest.js by Meki Cheraoui.
- * See COPYING for copyright and distribution information.
- */
-
-#include "binary-xml.h"
-#include "binary-xml-publisher-public-key-digest.h"
-
-ndn_Error ndn_encodeBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlEncoder *encoder)
-{
- if (!publisherPublicKeyDigest->publisherPublicKeyDigest.value || publisherPublicKeyDigest->publisherPublicKeyDigest.length == 0)
- return NDN_ERROR_success;
-
- ndn_Error error;
- if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &publisherPublicKeyDigest->publisherPublicKeyDigest)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
-{
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest)))
- return error;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
-{
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)))
- return error;
- if (gotExpectedTag) {
- if ((error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder)))
- return error;
- }
- else {
- publisherPublicKeyDigest->publisherPublicKeyDigest.value = 0;
- publisherPublicKeyDigest->publisherPublicKeyDigest.length = 0;
- }
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/encoding/binary-xml-publisher-public-key-digest.h b/src/c/encoding/binary-xml-publisher-public-key-digest.h
deleted file mode 100644
index 2d76205..0000000
--- a/src/c/encoding/binary-xml-publisher-public-key-digest.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLPUBLISHERPUBLICKEYDIGEST_H
-#define NDN_BINARYXMLPUBLISHERPUBLICKEYDIGEST_H
-
-#include "../errors.h"
-#include "../publisher-public-key-digest.h"
-#include "binary-xml-encoder.h"
-#include "binary-xml-decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Encode the ndn_PublisherPublicKeyDigest struct using Binary XML. If publisherPublicKeyDigest->publisherPublicKeyDigest or
- * publisherPublicKeyDigestLength is 0, then do nothing.
- * @param publisherPublicKeyDigest pointer to the ndn_PublisherPublicKeyDigest struct
- * @param encoder pointer to the ndn_BinaryXmlEncoder struct
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_encodeBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlEncoder *encoder);
-
-/**
- * Expect the next element to be a Binary XML PublisherPublicKeyDigest and decode into the ndn_PublisherPublicKeyDigest struct.
- * @param publisherPublicKeyDigest pointer to the ndn_PublisherPublicKeyDigest struct
- * @param decoder pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including if the next element is not PublisherPublicKeyDigest.
- */
-ndn_Error ndn_decodeBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder);
-
-/**
- * Peek the next element and if it is a Binary XML PublisherPublicKeyDigest and decode into the ndn_PublisherPublicKeyDigest struct.
- * Otherwise, set the ndn_PublisherPublicKeyDigest struct to none.
- * @param publisherPublicKeyDigest pointer to the ndn_PublisherPublicKeyDigest struct
- * @param decoder pointer to the ndn_BinaryXmlDecoder struct
- * @return 0 for success, else an error code, including if the next element is not PublisherPublicKeyDigest.
- */
-ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest
- (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml-structure-decoder.c b/src/c/encoding/binary-xml-structure-decoder.c
deleted file mode 100644
index a8e2f09..0000000
--- a/src/c/encoding/binary-xml-structure-decoder.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "../util/ndn_memory.h"
-#include "binary-xml.h"
-#include "binary-xml-decoder.h"
-#include "binary-xml-structure-decoder.h"
-
-void ndn_BinaryXmlStructureDecoder_initialize(struct ndn_BinaryXmlStructureDecoder *self)
-{
- self->gotElementEnd = 0;
- self->offset = 0;
- self->level = 0;
- self->state = ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE;
- self->headerLength = 0;
- self->useHeaderBuffer = 0;
- self->nBytesToRead = 0;
-}
-
-/**
- * Set the state to READ_HEADER_OR_CLOSE and set up to start reading the header.
- */
-static inline void startHeader(struct ndn_BinaryXmlStructureDecoder *self)
-{
- self->headerLength = 0;
- self->useHeaderBuffer = 0;
- self->state = ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE;
-}
-
-ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd
- (struct ndn_BinaryXmlStructureDecoder *self, uint8_t *input, size_t inputLength)
-{
- if (self->gotElementEnd)
- // Someone is calling when we already got the end.
- return NDN_ERROR_success;
-
- struct ndn_BinaryXmlDecoder decoder;
- ndn_BinaryXmlDecoder_initialize(&decoder, input, inputLength);
-
- while (1) {
- if (self->offset >= inputLength)
- // All the cases assume we have some input. Return and wait for more.
- return NDN_ERROR_success;
-
- if (self->state == ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE) {
- // First check for CLOSE.
- if (self->headerLength == 0 && input[self->offset] == ndn_BinaryXml_CLOSE) {
- ++self->offset;
- // Close the level.
- --self->level;
- if (self->level == 0) {
- // Finished.
- self->gotElementEnd = 1;
- return NDN_ERROR_success;
- }
- if (self->level < 0)
- return NDN_ERROR_findElementEnd_unexpected_close_tag;
-
- // Get ready for the next header.
- startHeader(self);
- continue;
- }
-
- size_t startingHeaderLength = self->headerLength;
- while (1) {
- if (self->offset >= inputLength) {
- // We can't get all of the header bytes from this input. Save in headerBuffer.
- if (self->headerLength > sizeof(self->headerBuffer))
- return NDN_ERROR_cannot_store_more_header_bytes_than_the_size_of_headerBuffer;
- self->useHeaderBuffer = 1;
- size_t nNewBytes = self->headerLength - startingHeaderLength;
- ndn_memcpy(self->headerBuffer + startingHeaderLength, input + (self->offset - nNewBytes), nNewBytes);
-
- return NDN_ERROR_success;
- }
- unsigned int headerByte = (unsigned int)input[self->offset++];
- ++self->headerLength;
- if (headerByte & ndn_BinaryXml_TT_FINAL)
- // Break and read the header.
- break;
- }
-
- unsigned int type;
- unsigned int value;
- if (self->useHeaderBuffer) {
- // Copy the remaining bytes into headerBuffer.
- if (self->headerLength > sizeof(self->headerBuffer))
- return NDN_ERROR_cannot_store_more_header_bytes_than_the_size_of_headerBuffer;
- size_t nNewBytes = self->headerLength - startingHeaderLength;
- ndn_memcpy(self->headerBuffer + startingHeaderLength, input + (self->offset - nNewBytes), nNewBytes);
-
- // Use a local decoder just for the headerBuffer.
- struct ndn_BinaryXmlDecoder bufferDecoder;
- ndn_BinaryXmlDecoder_initialize(&bufferDecoder, self->headerBuffer, sizeof(self->headerBuffer));
- if (ndn_BinaryXmlDecoder_decodeTypeAndValue(&bufferDecoder, &type, &value))
- return NDN_ERROR_findElementEnd_cannot_read_header_type_and_value;
- }
- else {
- // We didn't have to use the headerBuffer.
- ndn_BinaryXmlDecoder_seek(&decoder, self->offset - self->headerLength);
- if (ndn_BinaryXmlDecoder_decodeTypeAndValue(&decoder, &type, &value))
- return NDN_ERROR_findElementEnd_cannot_read_header_type_and_value;
- }
-
- // Set the next state based on the type.
- if (type == ndn_BinaryXml_DATTR)
- // We already consumed the item. READ_HEADER_OR_CLOSE again.
- // Binary XML has rules about what must follow an attribute, but we are just scanning.
- startHeader(self);
- else if (type == ndn_BinaryXml_DTAG || type == ndn_BinaryXml_EXT) {
- // Start a new level and READ_HEADER_OR_CLOSE again.
- ++self->level;
- startHeader(self);
- }
- else if (type == ndn_BinaryXml_TAG || type == ndn_BinaryXml_ATTR) {
- if (type == ndn_BinaryXml_TAG)
- // Start a new level and read the tag.
- ++self->level;
- // Minimum tag or attribute length is 1.
- self->nBytesToRead = value + 1;
- self->state = ndn_BinaryXmlStructureDecoder_READ_BYTES;
- // Binary XML has rules about what must follow an attribute, but we are just scanning.
- }
- else if (type == ndn_BinaryXml_BLOB || type == ndn_BinaryXml_UDATA) {
- self->nBytesToRead = value;
- self->state = ndn_BinaryXmlStructureDecoder_READ_BYTES;
- }
- else
- return NDN_ERROR_findElementEnd_unrecognized_header_type;
- }
- else if (self->state == ndn_BinaryXmlStructureDecoder_READ_BYTES) {
- size_t nRemainingBytes = inputLength - self->offset;
- if (nRemainingBytes < self->nBytesToRead) {
- // Need more.
- self->offset += nRemainingBytes;
- self->nBytesToRead -= nRemainingBytes;
- return NDN_ERROR_success;
- }
- // Got the bytes. Read a new header or close.
- self->offset += self->nBytesToRead;
- startHeader(self);
- }
- else
- // We don't expect this to happen.
- return NDN_ERROR_findElementEnd_unrecognized_state;
- }
-}
diff --git a/src/c/encoding/binary-xml-structure-decoder.h b/src/c/encoding/binary-xml-structure-decoder.h
deleted file mode 100644
index da5ad08..0000000
--- a/src/c/encoding/binary-xml-structure-decoder.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
-#define NDN_BINARYXMLSTRUCTUREDECODER_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include "../errors.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_BinaryXmlStructureDecoder {
- int gotElementEnd; /**< boolean */
- size_t offset;
- int level;
- int state;
- size_t headerLength;
- int useHeaderBuffer; /**< boolean */
- // 10 bytes is enough to hold an encoded header with a type and a 64 bit value.
- uint8_t headerBuffer[10];
- int nBytesToRead;
-};
-
-enum {
- ndn_BinaryXmlStructureDecoder_READ_HEADER_OR_CLOSE,
- ndn_BinaryXmlStructureDecoder_READ_BYTES
-};
-
-void ndn_BinaryXmlStructureDecoder_initialize(struct ndn_BinaryXmlStructureDecoder *self);
-
-/**
- * Continue scanning input starting from self->offset to find the element end. On return, you must check
- * self->gotElementEnd: If the end of the element which started at offset 0 is found,
- * then self->gotElementEnd is 1 and self->offset is the length of the element. Otherwise, self-forElementEnd is 0
- * which means you should read more into input and call again.
- * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
- * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
- * @param inputLength the number of bytes in input.
- * @return 0 for success, else an error code
- */
-ndn_Error ndn_BinaryXmlStructureDecoder_findElementEnd
- (struct ndn_BinaryXmlStructureDecoder *self, uint8_t *input, size_t inputLength);
-
-/**
- * Set the offset into the input, used for the next read.
- * @param self pointer to the ndn_BinaryXmlStructureDecoder struct
- * @param offset the new offset
- */
-static inline void ndn_BinaryXmlStructureDecoder_seek(struct ndn_BinaryXmlStructureDecoder *self, size_t offset)
-{
- self->offset = offset;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/encoding/binary-xml.h b/src/c/encoding/binary-xml.h
deleted file mode 100644
index dc6958b..0000000
--- a/src/c/encoding/binary-xml.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXML_H
-#define NDN_BINARYXML_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum {
- ndn_BinaryXml_EXT = 0x00,
- ndn_BinaryXml_TAG = 0x01,
- ndn_BinaryXml_DTAG = 0x02,
- ndn_BinaryXml_ATTR = 0x03,
- ndn_BinaryXml_DATTR = 0x04,
- ndn_BinaryXml_BLOB = 0x05,
- ndn_BinaryXml_UDATA = 0x06,
- ndn_BinaryXml_CLOSE = 0x0,
-
- ndn_BinaryXml_TT_BITS = 3,
- ndn_BinaryXml_TT_MASK = ((1 << ndn_BinaryXml_TT_BITS) - 1),
- ndn_BinaryXml_TT_VALUE_BITS = 4,
- ndn_BinaryXml_TT_VALUE_MASK = ((1 << (ndn_BinaryXml_TT_VALUE_BITS)) - 1),
- ndn_BinaryXml_REGULAR_VALUE_BITS = 7,
- ndn_BinaryXml_REGULAR_VALUE_MASK = ((1 << ndn_BinaryXml_REGULAR_VALUE_BITS) - 1),
- ndn_BinaryXml_TT_FINAL = 0x80,
-
- ndn_BinaryXml_DTag_Any = 13,
- ndn_BinaryXml_DTag_Name = 14,
- ndn_BinaryXml_DTag_Component = 15,
- ndn_BinaryXml_DTag_Certificate = 16,
- ndn_BinaryXml_DTag_Collection = 17,
- ndn_BinaryXml_DTag_CompleteName = 18,
- ndn_BinaryXml_DTag_Content = 19,
- ndn_BinaryXml_DTag_SignedInfo = 20,
- ndn_BinaryXml_DTag_ContentDigest = 21,
- ndn_BinaryXml_DTag_ContentHash = 22,
- ndn_BinaryXml_DTag_Count = 24,
- ndn_BinaryXml_DTag_Header = 25,
- ndn_BinaryXml_DTag_Interest = 26, /* 20090915 */
- ndn_BinaryXml_DTag_Key = 27,
- ndn_BinaryXml_DTag_KeyLocator = 28,
- ndn_BinaryXml_DTag_KeyName = 29,
- ndn_BinaryXml_DTag_Length = 30,
- ndn_BinaryXml_DTag_Link = 31,
- ndn_BinaryXml_DTag_LinkAuthenticator = 32,
- ndn_BinaryXml_DTag_NameComponentCount = 33, /* DeprecatedInInterest */
- ndn_BinaryXml_DTag_RootDigest = 36,
- ndn_BinaryXml_DTag_Signature = 37,
- ndn_BinaryXml_DTag_Start = 38,
- ndn_BinaryXml_DTag_Timestamp = 39,
- ndn_BinaryXml_DTag_Type = 40,
- ndn_BinaryXml_DTag_Nonce = 41,
- ndn_BinaryXml_DTag_Scope = 42,
- ndn_BinaryXml_DTag_Exclude = 43,
- ndn_BinaryXml_DTag_Bloom = 44,
- ndn_BinaryXml_DTag_BloomSeed = 45,
- ndn_BinaryXml_DTag_AnswerOriginKind = 47,
- ndn_BinaryXml_DTag_InterestLifetime = 48,
- ndn_BinaryXml_DTag_Witness = 53,
- ndn_BinaryXml_DTag_SignatureBits = 54,
- ndn_BinaryXml_DTag_DigestAlgorithm = 55,
- ndn_BinaryXml_DTag_BlockSize = 56,
- ndn_BinaryXml_DTag_FreshnessSeconds = 58,
- ndn_BinaryXml_DTag_FinalBlockID = 59,
- ndn_BinaryXml_DTag_PublisherPublicKeyDigest = 60,
- ndn_BinaryXml_DTag_PublisherCertificateDigest = 61,
- ndn_BinaryXml_DTag_PublisherIssuerKeyDigest = 62,
- ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest = 63,
- ndn_BinaryXml_DTag_ContentObject = 64, /* 20090915 */
- ndn_BinaryXml_DTag_WrappedKey = 65,
- ndn_BinaryXml_DTag_WrappingKeyIdentifier = 66,
- ndn_BinaryXml_DTag_WrapAlgorithm = 67,
- ndn_BinaryXml_DTag_KeyAlgorithm = 68,
- ndn_BinaryXml_DTag_Label = 69,
- ndn_BinaryXml_DTag_EncryptedKey = 70,
- ndn_BinaryXml_DTag_EncryptedNonceKey = 71,
- ndn_BinaryXml_DTag_WrappingKeyName = 72,
- ndn_BinaryXml_DTag_Action = 73,
- ndn_BinaryXml_DTag_FaceID = 74,
- ndn_BinaryXml_DTag_IPProto = 75,
- ndn_BinaryXml_DTag_Host = 76,
- ndn_BinaryXml_DTag_Port = 77,
- ndn_BinaryXml_DTag_MulticastInterface = 78,
- ndn_BinaryXml_DTag_ForwardingFlags = 79,
- ndn_BinaryXml_DTag_FaceInstance = 80,
- ndn_BinaryXml_DTag_ForwardingEntry = 81,
- ndn_BinaryXml_DTag_MulticastTTL = 82,
- ndn_BinaryXml_DTag_MinSuffixComponents = 83,
- ndn_BinaryXml_DTag_MaxSuffixComponents = 84,
- ndn_BinaryXml_DTag_ChildSelector = 85,
- ndn_BinaryXml_DTag_RepositoryInfo = 86,
- ndn_BinaryXml_DTag_Version = 87,
- ndn_BinaryXml_DTag_RepositoryVersion = 88,
- ndn_BinaryXml_DTag_GlobalPrefix = 89,
- ndn_BinaryXml_DTag_LocalName = 90,
- ndn_BinaryXml_DTag_Policy = 91,
- ndn_BinaryXml_DTag_Namespace = 92,
- ndn_BinaryXml_DTag_GlobalPrefixName = 93,
- ndn_BinaryXml_DTag_PolicyVersion = 94,
- ndn_BinaryXml_DTag_KeyValueSet = 95,
- ndn_BinaryXml_DTag_KeyValuePair = 96,
- ndn_BinaryXml_DTag_IntegerValue = 97,
- ndn_BinaryXml_DTag_DecimalValue = 98,
- ndn_BinaryXml_DTag_StringValue = 99,
- ndn_BinaryXml_DTag_BinaryValue = 100,
- ndn_BinaryXml_DTag_NameValue = 101,
- ndn_BinaryXml_DTag_Entry = 102,
- ndn_BinaryXml_DTag_ACL = 103,
- ndn_BinaryXml_DTag_ParameterizedName = 104,
- ndn_BinaryXml_DTag_Prefix = 105,
- ndn_BinaryXml_DTag_Suffix = 106,
- ndn_BinaryXml_DTag_Root = 107,
- ndn_BinaryXml_DTag_ProfileName = 108,
- ndn_BinaryXml_DTag_Parameters = 109,
- ndn_BinaryXml_DTag_InfoString = 110,
- ndn_BinaryXml_DTag_StatusResponse = 112,
- ndn_BinaryXml_DTag_StatusCode = 113,
- ndn_BinaryXml_DTag_StatusText = 114,
- ndn_BinaryXml_DTag_SyncNode = 115,
- ndn_BinaryXml_DTag_SyncNodeKind = 116,
- ndn_BinaryXml_DTag_SyncNodeElement = 117,
- ndn_BinaryXml_DTag_SyncVersion = 118,
- ndn_BinaryXml_DTag_SyncNodeElements = 119,
- ndn_BinaryXml_DTag_SyncContentHash = 120,
- ndn_BinaryXml_DTag_SyncLeafCount = 121,
- ndn_BinaryXml_DTag_SyncTreeDepth = 122,
- ndn_BinaryXml_DTag_SyncByteCount = 123,
- ndn_BinaryXml_DTag_SyncConfigSlice = 124,
- ndn_BinaryXml_DTag_SyncConfigSliceList = 125,
- ndn_BinaryXml_DTag_SyncConfigSliceOp = 126,
- ndn_BinaryXml_DTag_SyncNodeDeltas = 127,
- ndn_BinaryXml_DTag_SequenceNumber = 256,
- ndn_BinaryXml_DTag_NDNProtocolDataUnit = 20587744 // the encoded empty element, viewed as a string is "NDN\202\000"
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/errors.c b/src/c/errors.c
deleted file mode 100644
index 3b6b8bb..0000000
--- a/src/c/errors.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "errors.h"
-
-char *ndn_getErrorString(int error)
-{
- switch (error) {
- case NDN_ERROR_success:
- return "Success";
- case NDN_ERROR_element_of_value_is_not_a_decimal_digit:
- return "Element of value is not a decimal digit";
- case NDN_ERROR_read_past_the_end_of_the_input:
- return "Read past the end of the input";
- case NDN_ERROR_the_first_header_octet_may_not_be_zero:
- return "The first header octet may not be zero";
- case NDN_ERROR_header_type_is_not_a_DTAG:
- return "Header type is not a DTAG";
- case NDN_ERROR_did_not_get_the_expected_DTAG:
- return "Did not get the expected DTAG";
- case NDN_ERROR_did_not_get_the_expected_element_close:
- return "Did not get the expected element close";
- case NDN_ERROR_item_is_not_UDATA:
- return "Item is not UDATA";
- case NDN_ERROR_header_type_is_out_of_range:
- return "Header type is out of range";
- case NDN_ERROR_encodeTypeAndValue_miscalculated_N_encoding_bytes:
- return "EncodeTypeAndValue miscalculated N encoding bytes";
- case NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name:
- return "Attempt to add a component past the maximum number of components allowed in the name";
- case NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude:
- return "Read an entry past the maximum number of entries allowed in the exclude";
- case NDN_ERROR_findElementEnd_unexpected_close_tag:
- return "FindElementEnd unexpected close tag";
- case NDN_ERROR_cannot_store_more_header_bytes_than_the_size_of_headerBuffer:
- return "Cannot store more header bytes than the size of headerBuffer";
- case NDN_ERROR_findElementEnd_cannot_read_header_type_and_value:
- return "FindElementEnd cannot read header type and value";
- case NDN_ERROR_findElementEnd_unrecognized_header_type:
- return "FindElementEnd unrecognized header type";
- case NDN_ERROR_findElementEnd_unrecognized_state:
- return "FindElementEnd unrecognized state";
- case NDN_ERROR_DynamicUInt8Array_realloc_function_pointer_not_supplied:
- return "DynamicUInt8Array realloc function pointer not supplied";
- case NDN_ERROR_DynamicUInt8Array_realloc_failed:
- return "DynamicUInt8Array realloc failed";
- case NDN_ERROR_unrecognized_ndn_ExcludeType:
- return "Unrecognized ndn_ExcludeType";
- case NDN_ERROR_unrecognized_ndn_ContentType:
- return "Unrecognized ndn_ContentType";
- case NDN_ERROR_unrecognized_ndn_KeyLocatorType:
- return "Unrecognized ndn_KeyLocatorType";
- case NDN_ERROR_unrecognized_ndn_KeyNameType:
- return "Unrecognized ndn_KeyNameType";
- case NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type:
- return "decodeBinaryXmlKeyLocator unrecognized key locator type";
- case NDN_ERROR_unrecognized_ndn_SocketTransport:
- return "Unrecognized ndn_SocketTransport";
- case NDN_ERROR_SocketTransport_error_in_getaddrinfo:
- return "SocketTransport error in getaddrinfo";
- case NDN_ERROR_SocketTransport_cannot_connect_to_socket:
- return "SocketTransport cannot connect to socket";
- case NDN_ERROR_SocketTransport_socket_is_not_open:
- return "SocketTransport socket is not open";
- case NDN_ERROR_SocketTransport_error_in_send:
- return "SocketTransport error in send";
- case NDN_ERROR_SocketTransport_error_in_poll:
- return "SocketTransport error in poll";
- case NDN_ERROR_SocketTransport_error_in_recv:
- return "SocketTransport error in recv";
- case NDN_ERROR_SocketTransport_error_in_close:
- return "SocketTransport error in close";
- case NDN_ERROR_Name_component_does_not_begin_with_the_expected_marker:
- return "Name component does not begin with the expected marker";
- case NDN_ERROR_Time_functions_are_not_supported_by_the_standard_library:
- return "Time functions are not supported by the standard library";
- case NDN_ERROR_Calendar_time_value_out_of_range:
- return "Calendar time value out of range";
- default:
- return "unrecognized ndn_Error code";
- }
-}
diff --git a/src/c/errors.h b/src/c/errors.h
deleted file mode 100644
index 5906aa3..0000000
--- a/src/c/errors.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Define error codes and ndn_getErrorString to convert to a string.
- * Copyright (C) 2013 Regents of the University of California.
- * @author, Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_ERRORS_H
-#define NDN_ERRORS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- NDN_ERROR_success = 0,
- NDN_ERROR_element_of_value_is_not_a_decimal_digit,
- NDN_ERROR_read_past_the_end_of_the_input,
- NDN_ERROR_the_first_header_octet_may_not_be_zero,
- NDN_ERROR_header_type_is_not_a_DTAG,
- NDN_ERROR_did_not_get_the_expected_DTAG,
- NDN_ERROR_did_not_get_the_expected_element_close,
- NDN_ERROR_item_is_not_UDATA,
- NDN_ERROR_header_type_is_out_of_range,
- NDN_ERROR_encodeTypeAndValue_miscalculated_N_encoding_bytes,
- NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name,
- NDN_ERROR_read_an_entry_past_the_maximum_number_of_entries_allowed_in_the_exclude,
- NDN_ERROR_findElementEnd_unexpected_close_tag,
- NDN_ERROR_cannot_store_more_header_bytes_than_the_size_of_headerBuffer,
- NDN_ERROR_findElementEnd_cannot_read_header_type_and_value,
- NDN_ERROR_findElementEnd_unrecognized_header_type,
- NDN_ERROR_findElementEnd_unrecognized_state,
- NDN_ERROR_DynamicUInt8Array_realloc_function_pointer_not_supplied,
- NDN_ERROR_DynamicUInt8Array_realloc_failed,
- NDN_ERROR_unrecognized_ndn_ExcludeType,
- NDN_ERROR_unrecognized_ndn_ContentType,
- NDN_ERROR_unrecognized_ndn_KeyLocatorType,
- NDN_ERROR_unrecognized_ndn_KeyNameType,
- NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type,
- NDN_ERROR_unrecognized_ndn_SocketTransport,
- NDN_ERROR_SocketTransport_error_in_getaddrinfo,
- NDN_ERROR_SocketTransport_cannot_connect_to_socket,
- NDN_ERROR_SocketTransport_socket_is_not_open,
- NDN_ERROR_SocketTransport_error_in_send,
- NDN_ERROR_SocketTransport_error_in_poll,
- NDN_ERROR_SocketTransport_error_in_recv,
- NDN_ERROR_SocketTransport_error_in_close,
- NDN_ERROR_Name_component_does_not_begin_with_the_expected_marker,
- NDN_ERROR_Time_functions_are_not_supported_by_the_standard_library,
- NDN_ERROR_Calendar_time_value_out_of_range
-} ndn_Error;
-
-/**
- * Convert the error code to its string.
- * @param error the error code
- * @return the error string or "unrecognized ndn_Error code"
- */
-char *ndn_getErrorString(int error);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/forwarding-entry.h b/src/c/forwarding-entry.h
deleted file mode 100644
index 38ead4c..0000000
--- a/src/c/forwarding-entry.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_FORWARDING_ENTRY_H
-#define NDN_FORWARDING_ENTRY_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include <ndn-cpp-dev/c/forwarding-flags.h>
-#include "name.h"
-#include "publisher-public-key-digest.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- ndn_ForwardingEntryFlags_ACTIVE = 1,
- ndn_ForwardingEntryFlags_CHILD_INHERIT = 2,
- ndn_ForwardingEntryFlags_ADVERTISE = 4,
- ndn_ForwardingEntryFlags_LAST = 8,
- ndn_ForwardingEntryFlags_CAPTURE = 16,
- ndn_ForwardingEntryFlags_LOCAL = 32,
- ndn_ForwardingEntryFlags_TAP = 64,
- ndn_ForwardingEntryFlags_CAPTURE_OK = 128
-} ndn_ForwardingEntryFlags;
-
-/**
- * An ndn_ForwardingEntry holds fields for a ForwardingEntry which is used to register a prefix with a hub.
- */
-struct ndn_ForwardingEntry {
- struct ndn_Blob action; /**< A Blob whose value is a pointer to a pre-allocated buffer. 0 for none. */
- struct ndn_Name prefix;
- struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
- int faceId; /**< -1 for none. */
- struct ndn_ForwardingFlags forwardingFlags;
- int freshnessSeconds; /**< -1 for none. */
-};
-
-/**
- * Initialize an ndn_ForwardingEntry struct with the pre-allocated prefixNameComponents,
- * and defaults for all the values.
- * @param self pointer to the ndn_Interest struct
- * @param prefixNameComponents the pre-allocated array of ndn_NameComponent
- * @param maxPrefixNameComponents the number of elements in the allocated prefixNameComponents array
- */
-static inline void ndn_ForwardingEntry_initialize
- (struct ndn_ForwardingEntry *self, struct ndn_NameComponent *prefixNameComponents, size_t maxPrefixNameComponents)
-{
- ndn_Blob_initialize(&self->action, 0, 0);
- ndn_Name_initialize(&self->prefix, prefixNameComponents, maxPrefixNameComponents);
- ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
- self->faceId = -1;
- ndn_ForwardingFlags_initialize(&self->forwardingFlags);
- self->freshnessSeconds = -1;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/forwarding-flags.c b/src/c/forwarding-flags.c
deleted file mode 100644
index be52a8b..0000000
--- a/src/c/forwarding-flags.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "forwarding-entry.h"
-
-void ndn_ForwardingFlags_initialize(struct ndn_ForwardingFlags *self)
-{
- self->active = 1;
- self->childInherit = 1;
- self->advertise = 0;
- self->last = 0;
- self->capture = 0;
- self->local = 0;
- self->tap = 0;
- self->captureOk = 0;
-}
-
-int ndn_ForwardingFlags_getForwardingEntryFlags(struct ndn_ForwardingFlags *self)
-{
- int result = 0;
-
- if (self->active)
- result |= ndn_ForwardingEntryFlags_ACTIVE;
- if (self->childInherit)
- result |= ndn_ForwardingEntryFlags_CHILD_INHERIT;
- if (self->advertise)
- result |= ndn_ForwardingEntryFlags_ADVERTISE;
- if (self->last)
- result |= ndn_ForwardingEntryFlags_LAST;
- if (self->capture)
- result |= ndn_ForwardingEntryFlags_CAPTURE;
- if (self->local)
- result |= ndn_ForwardingEntryFlags_LOCAL;
- if (self->tap)
- result |= ndn_ForwardingEntryFlags_TAP;
- if (self->captureOk)
- result |= ndn_ForwardingEntryFlags_CAPTURE_OK;
-
- return result;
-}
-
-void ndn_ForwardingFlags_setForwardingEntryFlags(struct ndn_ForwardingFlags *self, int forwardingEntryFlags)
-{
- self->active = (forwardingEntryFlags & ndn_ForwardingEntryFlags_ACTIVE) ? 1 : 0;
- self->childInherit = (forwardingEntryFlags & ndn_ForwardingEntryFlags_CHILD_INHERIT) ? 1 : 0;
- self->advertise = (forwardingEntryFlags & ndn_ForwardingEntryFlags_ADVERTISE) ? 1 : 0;
- self->last = (forwardingEntryFlags & ndn_ForwardingEntryFlags_LAST) ? 1 : 0;
- self->capture = (forwardingEntryFlags & ndn_ForwardingEntryFlags_CAPTURE) ? 1 : 0;
- self->local = (forwardingEntryFlags & ndn_ForwardingEntryFlags_LOCAL) ? 1 : 0;
- self->tap = (forwardingEntryFlags & ndn_ForwardingEntryFlags_TAP) ? 1 : 0;
- self->captureOk = (forwardingEntryFlags & ndn_ForwardingEntryFlags_CAPTURE_OK) ? 1 : 0;
-}
diff --git a/src/c/interest.c b/src/c/interest.c
deleted file mode 100644
index 44c3ff6..0000000
--- a/src/c/interest.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "util/ndn_memory.h"
-#include "interest.h"
-
-int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2)
-{
- if (component1->value.length < component2->value.length)
- return -1;
- if (component1->value.length > component2->value.length)
- return 1;
-
- // The components are equal length. Just do a byte compare.
- return ndn_memcmp(component1->value.value, component2->value.value, component1->value.length);
-}
-
-int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component)
-{
- size_t i;
- for (i = 0; i < self->nEntries; ++i) {
- if (self->entries[i].type == ndn_Exclude_ANY) {
- struct ndn_ExcludeEntry *lowerBound = 0;
- if (i > 0)
- lowerBound = self->entries + (i - 1);
-
- // Find the upper bound, possibly skipping over multiple ANY in a row.
- size_t iUpperBound;
- struct ndn_ExcludeEntry *upperBound = 0;
- for (iUpperBound = i + 1; iUpperBound < self->nEntries; ++iUpperBound) {
- if (self->entries[iUpperBound].type == ndn_Exclude_COMPONENT) {
- upperBound = self->entries + iUpperBound;
- break;
- }
- }
-
- // If lowerBound != 0, we already checked component equals lowerBound on the last pass.
- // If upperBound != 0, we will check component equals upperBound on the next pass.
- if (upperBound != 0) {
- if (lowerBound != 0) {
- if (ndn_Exclude_compareComponents(component, &lowerBound->component) > 0 &&
- ndn_Exclude_compareComponents(component, &upperBound->component) < 0)
- return 1;
- }
- else {
- if (ndn_Exclude_compareComponents(component, &upperBound->component) < 0)
- return 1;
- }
-
- // Make i equal iUpperBound on the next pass.
- i = iUpperBound - 1;
- }
- else {
- if (lowerBound != 0) {
- if (ndn_Exclude_compareComponents(component, &lowerBound->component) > 0)
- return 1;
- }
- else
- // this.values has only ANY.
- return 1;
- }
- }
- else {
- if (ndn_Exclude_compareComponents(component, &self->entries[i].component) == 0)
- return 1;
- }
- }
-
- return 0;
-}
-
-int ndn_Interest_matchesName(struct ndn_Interest *self, struct ndn_Name *name)
-{
- if (!ndn_Name_match(&self->name, name))
- return 0;
-
- if (self->minSuffixComponents >= 0 &&
- // Add 1 for the implicit digest.
- !(name->nComponents + 1 - self->name.nComponents >= self->minSuffixComponents))
- return 0;
- if (self->maxSuffixComponents >= 0 &&
- // Add 1 for the implicit digest.
- !(name->nComponents + 1 - self->name.nComponents <= self->maxSuffixComponents))
- return 0;
- if (self->exclude.nEntries > 0 && name->nComponents > self->name.nComponents &&
- ndn_Exclude_matches(&self->exclude, name->components + self->name.nComponents))
- return 0;
-
- return 1;
-}
diff --git a/src/c/interest.h b/src/c/interest.h
deleted file mode 100644
index 8f0a587..0000000
--- a/src/c/interest.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_INTEREST_H
-#define NDN_INTEREST_H
-
-#include <ndn-cpp-dev/c/interest-types.h>
-#include "name.h"
-#include "publisher-public-key-digest.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value.
- */
-struct ndn_ExcludeEntry {
- ndn_ExcludeType type;
- struct ndn_NameComponent component;
-};
-
-/**
- *
- * @param self pointer to the ndn_NameComponent struct
- * @param type one of the ndn_ExcludeType enum
- * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT
- * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT
- */
-static inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, uint8_t *component, size_t componentLength)
-{
- self->type = type;
- ndn_NameComponent_initialize(&self->component, component, componentLength);
-}
-
-/**
- * An ndn_Exclude holds an array of ndn_ExcludeEntry.
- */
-struct ndn_Exclude {
- struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */
- size_t maxEntries; /**< the number of elements in the allocated entries array */
- size_t nEntries; /**< the number of entries in the exclude, 0 for no exclude */
-};
-/**
- * Initialize an ndn_Exclude struct with the entries array.
- * @param self A pointer to the ndn_Exclude struct.
- * @param entries the pre-allocated array of ndn_ExcludeEntry
- * @param maxEntries the number of elements in the allocated entries array
- */
-static inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, size_t maxEntries)
-{
- self->entries = entries;
- self->maxEntries = maxEntries;
- self->nEntries = 0;
-}
-
-/**
- * Compare the components using NDN component ordering.
- * A component is less if it is shorter, otherwise if equal length do a byte comparison.
- * @param component1 A pointer to the first name component.
- * @param component2 A pointer to the second name component.
- * @return -1 if component1 is less than component2, 1 if greater or 0 if equal.
- */
-int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2);
-
-/**
- * Check if the component matches any of the exclude criteria.
- * @param self A pointer to the ndn_Exclude struct.
- * @param component A pointer to the name component to check.
- * @return 1 if the component matches any of the exclude criteria, otherwise 0.
- */
-int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component);
-
-/**
- * An ndn_Interest holds an ndn_Name and other fields for an interest.
- */
-struct ndn_Interest {
- struct ndn_Name name;
- int minSuffixComponents; /**< -1 for none */
- int maxSuffixComponents; /**< -1 for none */
- struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
- struct ndn_Exclude exclude;
- int childSelector; /**< -1 for none */
- int answerOriginKind; /**< -1 for none */
- int scope; /**< -1 for none */
- ndn_Milliseconds interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
- struct ndn_Blob nonce; /**< The blob whose value is a pointer to a pre-allocated buffer. 0 for none */
-};
-
-/**
- * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries,
- * and defaults for all the values.
- * @param self pointer to the ndn_Interest struct
- * @param nameComponents the pre-allocated array of ndn_NameComponent
- * @param maxNameComponents the number of elements in the allocated nameComponents array
- * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry
- * @param maxExcludeEntries the number of elements in the allocated excludeEntries array
- */
-static inline void ndn_Interest_initialize
- (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
- struct ndn_ExcludeEntry *excludeEntries, size_t maxExcludeEntries)
-{
- ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
- self->minSuffixComponents = -1;
- self->maxSuffixComponents = -1;
- ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
- ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries);
- self->childSelector = -1;
- self->answerOriginKind = -1;
- self->scope = -1;
- self->interestLifetimeMilliseconds = -1.0;
- ndn_Blob_initialize(&self->nonce, 0, 0);
-}
-
-/**
- * Check if self's name matches the given name (using ndn_Name_match) and the given name also conforms to the
- * interest selectors.
- * @param self A pointer to the ndn_Interest struct.
- * @param name A pointer to the name to check.
- * @return 1 if the name and interest selectors match, 0 otherwise.
- */
-int ndn_Interest_matchesName(struct ndn_Interest *self, struct ndn_Name *name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/key-locator.h b/src/c/key-locator.h
deleted file mode 100644
index 1275ba9..0000000
--- a/src/c/key-locator.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_KEY_LOCATOR_H
-#define NDN_KEY_LOCATOR_H
-
-#include <ndn-cpp-dev/c/key-types.h>
-#include "name.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_KeyLocator holds the type of key locator and related data.
- */
-struct ndn_KeyLocator {
- ndn_KeyLocatorType type; /**< -1 for none */
- struct ndn_Blob keyData; /**< A Blob whose value is a pointer to a pre-allocated buffer for the key data as follows:
- * If type is ndn_KeyLocatorType_KEY, the key data.
- * If type is ndn_KeyLocatorType_CERTIFICATE, the certificate data.
- * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest.
- * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest.
- * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest.
- * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest.
- */
- struct ndn_Name keyName; /**< The key name (only used if type is ndn_KeyLocatorType_KEYNAME.) */
- ndn_KeyNameType keyNameType; /**< The type of data for keyName, -1 for none. (only used if type is ndn_KeyLocatorType_KEYNAME.) */
-};
-
-/**
- * Initialize an ndn_KeyLocator struct with the pre-allocated nameComponents, and defaults for all the values.
- * @param self A pointer to the ndn_KeyLocator struct.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent.
- * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
- */
-static inline void ndn_KeyLocator_initialize
- (struct ndn_KeyLocator *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) {
- self->type = (ndn_KeyLocatorType)-1;
- ndn_Blob_initialize(&self->keyData, 0, 0);
- ndn_Name_initialize(&self->keyName, keyNameComponents, maxKeyNameComponents);
- self->keyNameType = (ndn_KeyNameType)-1;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/name.c b/src/c/name.c
deleted file mode 100644
index 147d583..0000000
--- a/src/c/name.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <string.h>
-#include "util/ndn_memory.h"
-#include "name.h"
-
-uint64_t ndn_NameComponent_toNumber(struct ndn_NameComponent *self)
-{
- uint64_t result = 0;
- size_t i;
- for (i = 0; i < self->value.length; ++i) {
- result *= 256;
- result += (uint64_t)self->value.value[i];
- }
-
- return result;
-}
-
-ndn_Error ndn_NameComponent_toNumberWithMarker(struct ndn_NameComponent *self, uint8_t marker, uint64_t *result)
-{
- if (self->value.length == 0 || self->value.value[0] != marker)
- return NDN_ERROR_Name_component_does_not_begin_with_the_expected_marker;
-
- uint64_t localResult = 0;
- size_t i;
- for (i = 1; i < self->value.length; ++i) {
- localResult *= 256;
- localResult += (uint64_t)self->value.value[i];
- }
-
- *result = localResult;
- return NDN_ERROR_success;
-}
-
-int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name)
-{
- // This name is longer than the name we are checking it against.
- if (self->nComponents > name->nComponents)
- return 0;
-
- // Check if at least one of given components doesn't match.
- size_t i;
- for (i = 0; i < self->nComponents; ++i) {
- struct ndn_NameComponent *selfComponent = self->components + i;
- struct ndn_NameComponent *nameComponent = name->components + i;
-
- if (selfComponent->value.length != nameComponent->value.length ||
- ndn_memcmp(selfComponent->value.value, nameComponent->value.value, selfComponent->value.length) != 0)
- return 0;
- }
-
- return 1;
-}
-
-ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, uint8_t* value, size_t valueLength)
-{
- if (self->nComponents >= self->maxComponents)
- return NDN_ERROR_attempt_to_add_a_component_past_the_maximum_number_of_components_allowed_in_the_name;
- ndn_NameComponent_initialize(self->components + self->nComponents, value, valueLength);
- ++self->nComponents;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_Name_appendString(struct ndn_Name *self, char* value)
-{
- return ndn_Name_appendComponent(self, (uint8_t*)value, strlen(value));
-}
diff --git a/src/c/name.h b/src/c/name.h
deleted file mode 100644
index c28f1b1..0000000
--- a/src/c/name.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_NAME_H
-#define NDN_NAME_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include "errors.h"
-#include "util/blob.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_NameComponent holds a pointer to the component value.
- */
-struct ndn_NameComponent {
- struct ndn_Blob value; /**< A Blob with a pointer to the pre-allocated buffer for the component value */
-};
-
-/**
- *
- * @param self pointer to the ndn_NameComponent struct
- * @param value the pre-allocated buffer for the component value
- * @param valueLength the number of bytes in value
- */
-static inline void ndn_NameComponent_initialize(struct ndn_NameComponent *self, uint8_t *value, size_t valueLength)
-{
- ndn_Blob_initialize(&self->value, value, valueLength);
-}
-
-/**
- * Interpret the name component as a network-ordered number and return an integer.
- * @param self A pointer to the ndn_NameComponent struct.
- * @return The integer number.
- */
-uint64_t ndn_NameComponent_toNumber(struct ndn_NameComponent *self);
-
-/**
- * Interpret the name component as a network-ordered number with a marker and return an integer.
- * @param self A pointer to the ndn_NameComponent struct.
- * @param marker The required first byte of the component.
- * @param result Return the integer number.
- * @return 0 for success, or an error code if the first byte of the component does not equal the marker.
- */
-ndn_Error ndn_NameComponent_toNumberWithMarker(struct ndn_NameComponent *self, uint8_t marker, uint64_t *result);
-
-/**
- * An ndn_Name holds an array of ndn_NameComponent.
- */
-struct ndn_Name {
- struct ndn_NameComponent *components; /**< pointer to the array of components. */
- size_t maxComponents; /**< the number of elements in the allocated components array */
- size_t nComponents; /**< the number of components in the name */
-};
-
-/**
- * Initialize an ndn_Name struct with the components array.
- * @param self pointer to the ndn_Name struct
- * @param components the pre-allocated array of ndn_NameComponent
- * @param maxComponents the number of elements in the allocated components array
- */
-static inline void ndn_Name_initialize(struct ndn_Name *self, struct ndn_NameComponent *components, size_t maxComponents)
-{
- self->components = components;
- self->maxComponents = maxComponents;
- self->nComponents = 0;
-}
-
-/**
- * Return true if the N components of this name are the same as the first N components of the given name.
- * @param self A pointer to the ndn_Name struct.
- * @param name A pointer to the other name to match.
- * @return 1 if this matches the given name, 0 otherwise. This always returns 1 if this name is empty.
- */
-int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name);
-
-/**
- * Append a component to this name with the bytes in the given array.
- * @param self pointer to the ndn_Name struct.
- * @param value The bytes of the component. This does not copy the bytes.
- * @param valueLength The number of bytes in value.
- * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
- */
-ndn_Error ndn_Name_appendComponent(struct ndn_Name *self, uint8_t* value, size_t valueLength);
-
-/**
- * Append a component to this name with the bytes in the given blob.
- * @param self pointer to the ndn_Name struct.
- * @param value An ndn_Blob with the bytes of the component. This does not copy the bytes.
- * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
- */
-static inline ndn_Error ndn_Name_appendBlob(struct ndn_Name *self, struct ndn_Blob *value)
-{
- return ndn_Name_appendComponent(self, value->value, value->length);
-}
-
-/**
- * Append a component to this name with the bytes in raw string value.
- * @param self pointer to the ndn_Name struct.
- * @param value The null-terminated string, treated as a byte array. This does not copy the bytes.
- * @return 0 for success, or an error code if there is no more room in the components array (nComponents is already maxComponents).
- */
-ndn_Error ndn_Name_appendString(struct ndn_Name *self, char* value);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/publisher-public-key-digest.h b/src/c/publisher-public-key-digest.h
deleted file mode 100644
index 771ac32..0000000
--- a/src/c/publisher-public-key-digest.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_PUBLISHERPUBLICKEYDIGEST_H
-#define NDN_PUBLISHERPUBLICKEYDIGEST_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include "util/blob.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * A PublisherPublicKeyDigest holds a pointer to the publisher public key digest value, if any.
- * We make a separate struct since this is used by multiple other structs.
- */
-struct ndn_PublisherPublicKeyDigest {
- struct ndn_Blob publisherPublicKeyDigest; /**< A Blob whose value is a pointer to pre-allocated buffer. 0 for none */
-};
-
-/**
- * Initialize an ndn_PublisherPublicKeyDigest struct with 0 for none.
- */
-static inline void ndn_PublisherPublicKeyDigest_initialize(struct ndn_PublisherPublicKeyDigest *self)
-{
- ndn_Blob_initialize(&self->publisherPublicKeyDigest, 0, 0);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/transport/socket-transport.c b/src/c/transport/socket-transport.c
deleted file mode 100644
index 09a5b57..0000000
--- a/src/c/transport/socket-transport.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "socket-transport.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <poll.h>
-#include "../util/ndn_memory.h"
-
-ndn_Error ndn_SocketTransport_connect(struct ndn_SocketTransport *self, ndn_SocketType socketType, char *host, unsigned short port)
-{
- if (self->socketDescriptor >= 0) {
- close(self->socketDescriptor);
- self->socketDescriptor = -1;
- }
-
- struct addrinfo hints;
- ndn_memset((uint8_t *)&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- if (socketType == SOCKET_TCP)
- hints.ai_socktype = SOCK_STREAM;
- else if (socketType == SOCKET_UDP)
- hints.ai_socktype = SOCK_DGRAM;
- else
- return NDN_ERROR_unrecognized_ndn_SocketTransport;
-
- char portString[10];
- sprintf(portString, "%d", port);
-
- struct addrinfo *serverInfo;
- if (getaddrinfo(host, portString, &hints, &serverInfo) != 0)
- return NDN_ERROR_SocketTransport_error_in_getaddrinfo;
-
- // loop through all the results and connect to the first we can
- struct addrinfo *p;
- int socketDescriptor;
- for(p = serverInfo; p != NULL; p = p->ai_next) {
- if ((socketDescriptor = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
- continue;
-
- if (connect(socketDescriptor, p->ai_addr, p->ai_addrlen) == -1) {
- close(socketDescriptor);
- continue;
- }
-
- break;
- }
-
- if (p == NULL) {
- freeaddrinfo(serverInfo);
- return NDN_ERROR_SocketTransport_cannot_connect_to_socket;
- }
-
- freeaddrinfo(serverInfo);
- self->socketDescriptor = socketDescriptor;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_SocketTransport_send(struct ndn_SocketTransport *self, uint8_t *data, size_t dataLength)
-{
- if (self->socketDescriptor < 0)
- return NDN_ERROR_SocketTransport_socket_is_not_open;
-
- int nBytes;
- while (1) {
- if ((nBytes = send(self->socketDescriptor, data, dataLength, 0)) < 0)
- return NDN_ERROR_SocketTransport_error_in_send;
- if (nBytes >= dataLength)
- break;
-
- // Send more.
- dataLength -= nBytes;
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_SocketTransport_receiveIsReady(struct ndn_SocketTransport *self, int *receiveIsReady)
-{
- // Default to not ready.
- *receiveIsReady = 0;
-
- if (self->socketDescriptor < 0)
- // The socket is not open. Just silently return.
- return NDN_ERROR_success;
-
- struct pollfd pollInfo[1];
- pollInfo[0].fd = self->socketDescriptor;
- pollInfo[0].events = POLLIN;
-
- int pollResult = poll(pollInfo, 1, 0);
-
- if (pollResult < 0)
- return NDN_ERROR_SocketTransport_error_in_poll;
- else if (pollResult == 0)
- // Timeout, so no data ready.
- return NDN_ERROR_success;
- else {
- if (pollInfo[0].revents & POLLIN)
- *receiveIsReady = 1;
- }
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_SocketTransport_receive
- (struct ndn_SocketTransport *self, uint8_t *buffer, size_t bufferLength, size_t *nBytesOut)
-{
- if (self->socketDescriptor < 0)
- return NDN_ERROR_SocketTransport_socket_is_not_open;
-
- int nBytes;
- if ((nBytes = recv(self->socketDescriptor, buffer, bufferLength, 0)) == -1)
- return NDN_ERROR_SocketTransport_error_in_recv;
-
- *nBytesOut = (size_t)nBytes;
-
- return NDN_ERROR_success;
-}
-
-ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self)
-{
- if (self->socketDescriptor < 0)
- // Already closed. Do nothing.
- return NDN_ERROR_success;
-
- if (close(self->socketDescriptor) != 0)
- return NDN_ERROR_SocketTransport_error_in_close;
-
- self->socketDescriptor = -1;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/transport/socket-transport.h b/src/c/transport/socket-transport.h
deleted file mode 100644
index d1dbb56..0000000
--- a/src/c/transport/socket-transport.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_SOCKETTRANSPORT_H
-#define NDN_SOCKETTRANSPORT_H
-
-#include <sys/socket.h>
-#include <ndn-cpp-dev/c/common.h>
-#include "../errors.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- SOCKET_TCP,
- SOCKET_UDP
-} ndn_SocketType;
-
-struct ndn_SocketTransport {
- int socketDescriptor; /**< -1 if not connected */
-};
-
-/**
- * Initialize the ndn_SocketTransport struct with default values for no connection yet.
- * @param self A pointer to the ndn_SocketTransport struct.
- */
-static inline void ndn_SocketTransport_initialize(struct ndn_SocketTransport *self)
-{
- self->socketDescriptor = -1;
-}
-
-/**
- * Connect with TCP or UDP to the host:port.
- * @param self A pointer to the ndn_SocketTransport struct.
- * @param socketType SOCKET_TCP or SOCKET_UDP.
- * @param host The host to connect to.
- * @param port The port to connect to.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_SocketTransport_connect(struct ndn_SocketTransport *self, ndn_SocketType socketType, char *host, unsigned short port);
-
-/**
- * Send data to the socket.
- * @param self A pointer to the ndn_SocketTransport struct.
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_SocketTransport_send(struct ndn_SocketTransport *self, uint8_t *data, size_t dataLength);
-
-/**
- * Check if there is data ready on the socket to be received with ndn_SocketTransport_receive.
- * This does not block, and returns immediately.
- * @param self A pointer to the ndn_SocketTransport struct.
- * @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_SocketTransport_receiveIsReady(struct ndn_SocketTransport *self, int *receiveIsReady);
-
-/**
- * Receive data from the socket. NOTE: This is a blocking call. You should first call ndn_SocketTransport_receiveIsReady
- * to make sure there is data ready to receive.
- * @param self A pointer to the ndn_SocketTransport struct.
- * @param buffer A pointer to the buffer to receive the data.
- * @param bufferLength The maximum length of buffer.
- * @param nBytes Return the number of bytes received into buffer.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_SocketTransport_receive
- (struct ndn_SocketTransport *self, uint8_t *buffer, size_t bufferLength, size_t *nBytes);
-
-/**
- * Close the socket.
- * @param self A pointer to the ndn_SocketTransport struct.
- * @return 0 for success, else an error code.
- */
-ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/transport/tcp-transport.h b/src/c/transport/tcp-transport.h
deleted file mode 100644
index 55f2e8e..0000000
--- a/src/c/transport/tcp-transport.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_TCPTRANSPORT_H
-#define NDN_TCPTRANSPORT_H
-
-#include "socket-transport.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_TcpTransport {
- struct ndn_SocketTransport base;
-};
-
-/**
- * Initialize the ndn_TcpTransport struct with default values for no connection yet.
- * @param self A pointer to the ndn_TcpTransport struct.
- */
-static inline void ndn_TcpTransport_initialize(struct ndn_TcpTransport *self)
-{
- ndn_SocketTransport_initialize(&self->base);
-}
-
-/**
- * Connect with TCP to the host:port.
- * @param self A pointer to the ndn_TcpTransport struct.
- * @param host The host to connect to.
- * @param port The port to connect to.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_TcpTransport_connect(struct ndn_TcpTransport *self, char *host, unsigned short port)
-{
- return ndn_SocketTransport_connect(&self->base, SOCKET_TCP, host, port);
-}
-
-/**
- * Send data to the socket.
- * @param self A pointer to the ndn_TcpTransport struct.
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_TcpTransport_send(struct ndn_TcpTransport *self, uint8_t *data, size_t dataLength)
-{
- return ndn_SocketTransport_send(&self->base, data, dataLength);
-}
-
-/**
- * Check if there is data ready on the socket to be received with ndn_TcpTransport_receive.
- * This does not block, and returns immediately.
- * @param self A pointer to the ndn_TcpTransport struct.
- * @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_TcpTransport_receiveIsReady(struct ndn_TcpTransport *self, int *receiveIsReady)
-{
- return ndn_SocketTransport_receiveIsReady(&self->base, receiveIsReady);
-}
-
-/**
- * Receive data from the socket. NOTE: This is a blocking call. You should first call ndn_SocketTransport_receiveIsReady
- * to make sure there is data ready to receive.
- * @param self A pointer to the ndn_TcpTransport struct.
- * @param buffer A pointer to the buffer to receive the data.
- * @param bufferLength The maximum length of buffer.
- * @param nBytes Return the number of bytes received into buffer.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_TcpTransport_receive
- (struct ndn_TcpTransport *self, uint8_t *buffer, size_t bufferLength, size_t *nBytes)
-{
- return ndn_SocketTransport_receive(&self->base, buffer, bufferLength, nBytes);
-}
-
-/**
- * Close the socket.
- * @param self A pointer to the ndn_TcpTransport struct.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_TcpTransport_close(struct ndn_TcpTransport *self)
-{
- return ndn_SocketTransport_close(&self->base);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/transport/udp-transport.h b/src/c/transport/udp-transport.h
deleted file mode 100644
index 20d106b..0000000
--- a/src/c/transport/udp-transport.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_UDPTRANSPORT_H
-#define NDN_UDPTRANSPORT_H
-
-#include "socket-transport.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_UdpTransport {
- struct ndn_SocketTransport base;
-};
-
-/**
- * Initialize the ndn_UdpTransport struct with default values for no connection yet.
- * @param self A pointer to the ndn_UdpTransport struct.
- */
-static inline void ndn_UdpTransport_initialize(struct ndn_UdpTransport *self)
-{
- ndn_SocketTransport_initialize(&self->base);
-}
-
-/**
- * Connect with UDP to the host:port.
- * @param self A pointer to the ndn_UdpTransport struct.
- * @param host The host to connect to.
- * @param port The port to connect to.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_UdpTransport_connect(struct ndn_UdpTransport *self, char *host, unsigned short port)
-{
- return ndn_SocketTransport_connect(&self->base, SOCKET_UDP, host, port);
-}
-
-/**
- * Send data to the socket.
- * @param self A pointer to the ndn_UdpTransport struct.
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_UdpTransport_send(struct ndn_UdpTransport *self, uint8_t *data, size_t dataLength)
-{
- return ndn_SocketTransport_send(&self->base, data, dataLength);
-}
-
-/**
- * Check if there is data ready on the socket to be received with ndn_UdpTransport_receive.
- * This does not block, and returns immediately.
- * @param self A pointer to the ndn_UdpTransport struct.
- * @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_UdpTransport_receiveIsReady(struct ndn_UdpTransport *self, int *receiveIsReady)
-{
- return ndn_SocketTransport_receiveIsReady(&self->base, receiveIsReady);
-}
-
-/**
- * Receive data from the socket. NOTE: This is a blocking call. You should first call ndn_SocketTransport_receiveIsReady
- * to make sure there is data ready to receive.
- * @param self A pointer to the ndn_UdpTransport struct.
- * @param buffer A pointer to the buffer to receive the data.
- * @param bufferLength The maximum length of buffer.
- * @param nBytes Return the number of bytes received into buffer.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_UdpTransport_receive
- (struct ndn_UdpTransport *self, uint8_t *buffer, size_t bufferLength, size_t *nBytes)
-{
- return ndn_SocketTransport_receive(&self->base, buffer, bufferLength, nBytes);
-}
-
-/**
- * Close the socket.
- * @param self A pointer to the ndn_UdpTransport struct.
- * @return 0 for success, else an error code.
- */
-static inline ndn_Error ndn_UdpTransport_close(struct ndn_UdpTransport *self)
-{
- return ndn_SocketTransport_close(&self->base);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/util/blob.h b/src/c/util/blob.h
deleted file mode 100644
index 94bbaf9..0000000
--- a/src/c/util/blob.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BLOB_H
-#define NDN_BLOB_H
-
-#include <ndn-cpp-dev/c/common.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_Blob holds a pointer to a read-only pre-allocated buffer and its length.
- */
-struct ndn_Blob {
- uint8_t *value; /**< pointer to the pre-allocated buffer for the value. Must be treated as read only. */
- size_t length; /**< the number of bytes in value. */
-};
-
-/**
- * Initialize the ndn_Blob struct with the given value.
- * @param self pointer to the ndn_Blob struct.
- * @param value The pre-allocated buffer for the value, or 0 for none.
- * @param length The number of bytes in value.
- */
-static inline void ndn_Blob_initialize(struct ndn_Blob *self, uint8_t *value, size_t length)
-{
- self->value = value;
- self->length = length;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/util/dynamic-uint8-array.c b/src/c/util/dynamic-uint8-array.c
deleted file mode 100644
index 23bfd7c..0000000
--- a/src/c/util/dynamic-uint8-array.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "dynamic-uint8-array.h"
-
-ndn_Error ndn_DynamicUInt8Array_reallocArray(struct ndn_DynamicUInt8Array *self, size_t length)
-{
- if (!self->realloc)
- return NDN_ERROR_DynamicUInt8Array_realloc_function_pointer_not_supplied;
-
- // See if double is enough.
- size_t newLength = self->length * 2;
- if (length > newLength)
- // The needed length is much greater, so use it.
- newLength = length;
-
- uint8_t *newArray = (*self->realloc)(self, self->array, newLength);
- if (!newArray)
- return NDN_ERROR_DynamicUInt8Array_realloc_failed;
-
- self->array = newArray;
- self->length = newLength;
-
- return NDN_ERROR_success;
-}
diff --git a/src/c/util/dynamic-uint8-array.h b/src/c/util/dynamic-uint8-array.h
deleted file mode 100644
index 6548662..0000000
--- a/src/c/util/dynamic-uint8-array.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_DYNAMICUCHARARRAY_H
-#define NDN_DYNAMICUCHARARRAY_H
-
-#include "../errors.h"
-#include "ndn_memory.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_DynamicUInt8Array {
- uint8_t *array; /**< the allocated array buffer */
- size_t length; /**< the length of the allocated array buffer */
- uint8_t * (*realloc)
- (struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length); /**< a pointer to a function that reallocates array and returns a new pointer to a buffer of
- * length bytes, or 0 for error. On success, the contents of the old buffer are copied to the new one.
- * On success, the original array pointer will no longer be used.
- * self is a pointer to the struct ndn_DynamicUInt8Array which is calling realloc.
- * This function pointer may be 0 (which causes an error if a reallocate is necessary). */
-};
-
-/**
- * Initialize an ndn_DynamicUInt8Array struct with the given array buffer.
- * @param self pointer to the ndn_DynamicUInt8Array struct
- * @param array the allocated array buffer
- * @param length the length of the allocated array buffer
- * @param reallocFunction see ndn_DynamicUInt8Array_ensureLength. This may be 0.
- */
-static inline void ndn_DynamicUInt8Array_initialize
- (struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length,
- uint8_t * (*reallocFunction)(struct ndn_DynamicUInt8Array *self, uint8_t *, size_t))
-{
- self->array = array;
- self->length = length;
- self->realloc = reallocFunction;
-}
-
-/**
- * Do the work of ndn_DynamicUInt8Array_ensureLength if realloc is necessary.
- * If the self->realloc function pointer is null, then return an error.
- * If not null, call self->realloc to reallocate self->array, and update self->length (which may be greater than length).
- * @param self pointer to the ndn_DynamicUInt8Array struct
- * @param length the needed minimum size for self->length
- * @return 0 for success, else an error code if can't reallocate the array
- */
-ndn_Error ndn_DynamicUInt8Array_reallocArray(struct ndn_DynamicUInt8Array *self, size_t length);
-
-/**
- * Ensure that self->length is greater than or equal to length. If it is, just return 0 for success.
- * Otherwise, if the self->realloc function pointer is null, then return an error.
- * If not null, call self->realloc to reallocate self->array, and update self->length (which may be greater than length).
- * @param self pointer to the ndn_DynamicUInt8Array struct
- * @param length the needed minimum size for self->length
- * @return 0 for success, else an error code if need to reallocate the array but can't
- */
-static inline ndn_Error ndn_DynamicUInt8Array_ensureLength(struct ndn_DynamicUInt8Array *self, size_t length)
-{
- if (self->length >= length)
- return NDN_ERROR_success;
-
- return ndn_DynamicUInt8Array_reallocArray(self, length);
-}
-
-/**
- * Copy value into self->array at offset, using ndn_DynamicUInt8Array_ensureLength to make sure self->array has enough length.
- * @param self pointer to the ndn_DynamicUInt8Array struct
- * @param value the buffer to copy from
- * @param valueLength the length of the value buffer
- * @param offset the offset in self->array to copy to
- * @return 0 for success, else an error code if need to reallocate the array but can't
- */
-static inline ndn_Error ndn_DynamicUInt8Array_set
- (struct ndn_DynamicUInt8Array *self, uint8_t *value, size_t valueLength, size_t offset)
-{
- ndn_Error error;
- if ((error = ndn_DynamicUInt8Array_ensureLength(self, valueLength + offset)))
- return error;
- ndn_memcpy(self->array + offset, value, valueLength);
- return NDN_ERROR_success;
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/util/ndn_memory.c b/src/c/util/ndn_memory.c
deleted file mode 100644
index a9c3510..0000000
--- a/src/c/util/ndn_memory.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "ndn_memory.h"
-
-#if !NDN_CPP_HAVE_MEMCMP
-int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; i++) {
- if (buf1[i] > buf2[i])
- return 1;
- else if (buf1[i] < buf2[i])
- return -1;
- }
-
- return 0;
-}
-#else
-int ndn_memcmp_stub_to_avoid_empty_file_warning = 0;
-#endif
-
-#if !NDN_CPP_HAVE_MEMCPY
-void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; i++)
- dest[i] = src[i];
-}
-#else
-int ndn_memcpy_stub_to_avoid_empty_file_warning = 0;
-#endif
-
-#if !NDN_CPP_HAVE_MEMSET
-void ndn_memset(uint8_t *dest, int val, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; i++)
- dest[i] = (uint8_t)val;
-}
-#else
-int ndn_memset_stub_to_avoid_empty_file_warning = 0;
-#endif
diff --git a/src/c/util/ndn_memory.h b/src/c/util/ndn_memory.h
deleted file mode 100644
index d0779be..0000000
--- a/src/c/util/ndn_memory.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-/*
- * Based on NDN_CPP_HAVE_MEMCPY and NDN_CPP_HAVE_MEMSET in ndn-cpp-config.h, use the library version or a local implementation of memcmp, memcpy and memset.
- */
-
-#ifndef NDN_MEMORY_H
-#define NDN_MEMORY_H
-
-#include <ndn-cpp-dev/c/common.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if NDN_CPP_HAVE_MEMCMP
-#include <memory.h>
-/**
- * Use the library version of memcmp.
- */
-static inline int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len) { return memcmp(buf1, buf2, len); }
-#else
-/**
- * Use a local implementation of memcmp instead of the library version.
- */
-int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len);
-#endif
-
-#if NDN_CPP_HAVE_MEMCPY
-#include <memory.h>
-/**
- * Use the library version of memcpy.
- */
-static inline void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len) { memcpy(dest, src, len); }
-#else
-/**
- * Use a local implementation of memcpy instead of the library version.
- */
-void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len);
-#endif
-
-#if NDN_CPP_HAVE_MEMSET
-#include <memory.h>
-/**
- * Use the library version of memset.
- */
-static inline void ndn_memset(uint8_t *dest, int val, size_t len) { memset(dest, val, len); }
-#else
-/**
- * Use a local implementation of memset instead of the library version.
- */
-void ndn_memset(uint8_t *dest, int val, size_t len);
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/c/util/ndn_realloc.c b/src/c/util/ndn_realloc.c
deleted file mode 100644
index f3147f4..0000000
--- a/src/c/util/ndn_realloc.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <stdlib.h>
-#include "ndn_realloc.h"
-
-uint8_t *ndn_realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length)
-{
- return (uint8_t *)realloc(array, length);
-}
diff --git a/src/c/util/ndn_realloc.h b/src/c/util/ndn_realloc.h
deleted file mode 100644
index 7aeb6af..0000000
--- a/src/c/util/ndn_realloc.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_NDN_REALLOC_H
-#define NDN_NDN_REALLOC_H
-
-#include "dynamic-uint8-array.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Wrap the C stdlib realloc to convert to/from void * to uint8_t *.
- * This can be used by ndn_DynamicUInt8Array_initialize.
- * @param self This is ignored.
- * @param array the allocated array buffer to realloc.
- * @param length the length for the new array buffer.
- * @return the new allocated array buffer.
- */
-uint8_t *ndn_realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/c/util/time.h b/src/c/util/time.h
deleted file mode 100644
index 674ef21..0000000
--- a/src/c/util/time.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_TIME_H
-#define NDN_TIME_H
-
-#include <ndn-cpp-dev/c/common.h>
-#include "../errors.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Use gettimeofday to return the current time in milliseconds.
- * @return The current time in milliseconds since 1/1/1970, including fractions of a millisecond according to timeval.tv_usec.
- */
-ndn_MillisecondsSince1970
-ndn_getNowMilliseconds();
-
-/**
- * Convert the time from milliseconds to an ISO time string, for example "20131018T184138.423355".
- * @param milliseconds The time in milliseconds since 1/1/1970, including fractions of a millisecond.
- * @param isoString A buffer of at least 23 bytes to receive the null-terminated ISO time string.
- * @return 0 for success, else an error code including if we don't have necessary standard library support.
- */
-ndn_Error
-ndn_toIsoString(ndn_MillisecondsSince1970 milliseconds, char *isoString);
-
-/**
- * Parse the ISO time string and return the time in milliseconds.
- * @param isoString The ISO time string, for example "20131018T184138.423355".
- * @param milliseconds Return the time in milliseconds since 1/1/1970, including fractions of a millisecond.
- * @return 0 for success, else an error code including if we don't have necessary standard library support.
- */
-ndn_Error
-ndn_fromIsoString(const char* isoString, ndn_MillisecondsSince1970 *milliseconds);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/encoding/binary-xml-decoder.hpp b/src/encoding/binary-xml-decoder.hpp
deleted file mode 100644
index e7583e5..0000000
--- a/src/encoding/binary-xml-decoder.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLDECODER_HPP
-#define NDN_BINARYXMLDECODER_HPP
-
-#include <stdexcept>
-#include "../c/errors.h"
-#include "../c/encoding/binary-xml-decoder.h"
-
-using namespace std;
-
-namespace ndn {
-
-/**
- * A BinaryXmlDecoder extends a C ndn_BinaryXmlDecoder struct and wraps related functions.
- */
-class BinaryXmlDecoder : public ndn_BinaryXmlDecoder {
-public:
- /**
- * Initialize the base ndn_BinaryXmlDecoder struct with the input.
- */
- BinaryXmlDecoder(const uint8_t *input, size_t inputLength)
- {
- ndn_BinaryXmlDecoder_initialize(this, (uint8_t *)input, inputLength);
- }
-
- /**
- * Decode the header from the input starting at offset, and if it is a DTAG where the value is the expectedTag,
- * then return true, else false. Do not update offset, including if throwing an exception.
- * @param expectedTag the expected value for DTAG
- * @return true if got the expected tag, else false
- */
- bool
- peekDTag(unsigned int expectedTag)
- {
- int gotExpectedTag;
- ndn_Error error;
- if ((error = ndn_BinaryXmlDecoder_peekDTag(this, expectedTag, &gotExpectedTag)))
- throw runtime_error(ndn_getErrorString(error));
-
- return gotExpectedTag;
- }
-};
-
-}
-
-#endif
diff --git a/src/encoding/binary-xml-encoder.hpp b/src/encoding/binary-xml-encoder.hpp
deleted file mode 100644
index 6ae3913..0000000
--- a/src/encoding/binary-xml-encoder.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLENCODER_HPP
-#define NDN_BINARYXMLENCODER_HPP
-
-#include <vector>
-#include <ndn-cpp-dev/common.hpp>
-#include "../util/dynamic-uint8-vector.hpp"
-#include "../c/encoding/binary-xml-encoder.h"
-
-namespace ndn {
-
-/**
- * A BinaryXmlEncoder extends a C ndn_BinaryXmlEncoder struct and wraps related functions.
- */
-class BinaryXmlEncoder : public ndn_BinaryXmlEncoder {
-public:
- /**
- * Initialize the base ndn_BinaryXmlEncoder struct with the initialLength. Use simpleRealloc.
- * @param initialLength The initial size of the output. If omitted, use 16.
- */
- BinaryXmlEncoder(size_t initialLength = 16)
- : output_(16)
- {
- ndn_BinaryXmlEncoder_initialize(this, &output_);
- }
-
- /**
- * Resize the output vector to the correct encoding length and return.
- * @return The encoding as a shared_ptr. Assume that the caller now owns the vector.
- */
- const ptr_lib::shared_ptr<std::vector<uint8_t> >&
- getOutput()
- {
- output_.get()->resize(offset);
- return output_.get();
- }
-
- DynamicUInt8Vector output_;
-};
-
-}
-
-#endif
diff --git a/src/encoding/binary-xml-structure-decoder.hpp b/src/encoding/binary-xml-structure-decoder.hpp
deleted file mode 100644
index 2707763..0000000
--- a/src/encoding/binary-xml-structure-decoder.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BINARYXMLSTRUCTUREDECODER_HPP
-#define NDN_BINARYXMLSTRUCTUREDECODER_HPP
-
-#include <stdexcept>
-#include "../c/encoding/BinaryXMLStructureDecoder.h"
-
-namespace ndn {
-
-/**
- * A BinaryXmlStructureDecoder extends a C ndn_BinaryXmlStructureDecoder struct and wraps related functions.
- */
-class BinaryXmlStructureDecoder : private ndn_BinaryXmlStructureDecoder {
-public:
- BinaryXmlStructureDecoder()
- {
- ndn_BinaryXmlStructureDecoder_initialize(this);
- }
-
- /**
- * Continue scanning input starting from getOffset() to find the element end.
- * If the end of the element which started at offset 0 is found, then return true and getOffset() is the length of
- * the element. Otherwise return false, which means you should read more into input and call again.
- * @param input the input buffer. You have to pass in input each time because the buffer could be reallocated.
- * @param inputLength the number of bytes in input.
- * @return true if found the element end, false if need to read more. (This is the same as returning gotElementEnd().)
- */
- bool
- findElementEnd(uint8_t *input, size_t inputLength)
- {
- ndn_Error error;
- if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength)))
- throw runtime_error(ndn_getErrorString(error));
- return gotElementEnd();
- }
-
- size_t
- getOffset() const { return offset; }
-
- bool
- gotElementEnd() const { return gotElementEnd != 0; }
-};
-
-}
-
-#endif
diff --git a/src/encoding/binary-xml-wire-format.cpp b/src/encoding/binary-xml-wire-format.cpp
deleted file mode 100644
index dce8b7b..0000000
--- a/src/encoding/binary-xml-wire-format.cpp
+++ /dev/null
@@ -1,336 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <stdexcept>
-#include <ndn-cpp-dev/interest.hpp>
-#include <ndn-cpp-dev/data.hpp>
-#include <ndn-cpp-dev/forwarding-entry.hpp>
-#include <ndn-cpp-dev/encoding/binary-xml-wire-format.hpp>
-#include "../c/encoding/binary-xml-interest.h"
-#include "../c/encoding/binary-xml-data.h"
-#include "../c/encoding/binary-xml-forwarding-entry.h"
-#include "binary-xml-encoder.hpp"
-#include "binary-xml-decoder.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-namespace c {
-
-class Exclude : public ndn::Exclude
-{
-public:
- void
- get(struct ndn_Exclude& excludeStruct) const
- {
- if (excludeStruct.maxEntries < size())
- throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
-
- int entries = 0;
- for (Exclude::const_reverse_iterator i = rbegin (); i != rend (); i++)
- {
- if (!i->first.empty())
- {
- excludeStruct.entries[entries].type = ndn_Exclude_COMPONENT;
- excludeStruct.entries[entries].component.value.value = const_cast<uint8_t*>(i->first.getValue().buf());
- excludeStruct.entries[entries].component.value.length = i->first.getValue().size();
- ++entries;
- }
- if (i->second)
- {
- excludeStruct.entries[entries].type = ndn_Exclude_ANY;
- ++entries;
- }
- }
-
- excludeStruct.nEntries = entries;
- }
-
- void
- set(const struct ndn_Exclude& excludeStruct)
- {
- clear();
-
- if (excludeStruct.nEntries == 0)
- return;
-
- int i = 0;
- if (excludeStruct.entries[i].type == ndn_Exclude_ANY) {
- appendExclude("/", true);
- i++;
- }
-
- while (i < excludeStruct.nEntries) {
- ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
-
- if (entry->type != ndn_Exclude_COMPONENT)
- throw runtime_error("unrecognized ndn_ExcludeType");
-
- Name::Component excludedComponent (entry->component.value.value, entry->component.value.length);
- ++i;
- entry = &excludeStruct.entries[i];
-
- if (i < excludeStruct.nEntries) {
- if (entry->type == ndn_Exclude_ANY) {
- appendExclude(excludedComponent, true);
- ++i;
- }
- else
- appendExclude(excludedComponent, false);
- }
- else
- appendExclude(excludedComponent, false);
- }
- }
-};
-
-class Name : public ndn::Name
-{
-public:
- void
- get(struct ndn_Name& nameStruct) const
- {
- if (nameStruct.maxComponents < size())
- throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
-
- nameStruct.nComponents = size();
- for (size_t i = 0; i < nameStruct.nComponents; ++i) {
- nameStruct.components[i].value.value = const_cast<uint8_t*>(ndn::Name::get(i).getValue().buf());
- nameStruct.components[i].value.length = ndn::Name::get(i).getValue().size();
- }
- }
-
- void
- set(const struct ndn_Name& nameStruct)
- {
- clear();
- for (size_t i = 0; i < nameStruct.nComponents; ++i)
- append(nameStruct.components[i].value.value, nameStruct.components[i].value.length);
- }
-};
-
-class Interest : public ndn::Interest
-{
-public:
- void
- get(struct ndn_Interest& interestStruct) const
- {
- reinterpret_cast<const c::Name&>(getName()).get(interestStruct.name);
- interestStruct.minSuffixComponents = getMinSuffixComponents();
- interestStruct.maxSuffixComponents = getMaxSuffixComponents();
- // publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
- reinterpret_cast<const c::Exclude&>(getExclude()).get(interestStruct.exclude);
- interestStruct.childSelector = getChildSelector();
- interestStruct.answerOriginKind = getMustBeFresh() ?
- (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED)
- :
- (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED | ndn_Interest_ANSWER_STALE);
- interestStruct.scope = getScope();
- interestStruct.interestLifetimeMilliseconds = getInterestLifetime();
-
- interestStruct.nonce.length = 4;
- interestStruct.nonce.value = const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(getNonce()));
- }
-
- void
- set(const struct ndn_Interest& interestStruct)
- {
- reinterpret_cast<c::Name&>(getName()).set(interestStruct.name);
- setMinSuffixComponents(interestStruct.minSuffixComponents);
- setMaxSuffixComponents(interestStruct.maxSuffixComponents);
-
- // publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
-
- reinterpret_cast<c::Exclude&>(getExclude()).set(interestStruct.exclude);
- setChildSelector(interestStruct.childSelector);
- // answerOriginKind_ = interestStruct.answerOriginKind;
- setScope(interestStruct.scope);
- setInterestLifetime(interestStruct.interestLifetimeMilliseconds);
-
- setNonce(*reinterpret_cast<uint32_t*>(interestStruct.nonce.value));
- }
-};
-
-class Data : public ndn::Data
-{
-public:
- void
- get(struct ndn_Data& dataStruct) const
- {
- // signature_->get(dataStruct.signature);
- // name_.get(dataStruct.name);
- // metaInfo_.get(dataStruct.metaInfo);
- // content_.get(dataStruct.content);
- }
-
- void
- set(const struct ndn_Data& dataStruct)
- {
- // signature_->set(dataStruct.signature);
- // name_.set(dataStruct.name);
- // metaInfo_.set(dataStruct.metaInfo);
- // content_ = Blob(dataStruct.content);
- }
-};
-
-class ForwardingEntry : public ndn::ForwardingEntry
-{
-public:
- void
- get(struct ndn_ForwardingEntry& forwardingEntryStruct) const
- {
- reinterpret_cast<const c::Name&>(getPrefix()).get(forwardingEntryStruct.prefix);
- // publisherPublicKeyDigest_.get(forwardingEntryStruct.publisherPublicKeyDigest);
- forwardingEntryStruct.faceId = getFaceId();
- // forwardingEntryStruct.forwardingFlags = getForwardingFlags();
- forwardingEntryStruct.freshnessSeconds = getFreshnessPeriod() / 1000;
-
- forwardingEntryStruct.action.length = getAction().size();
- if (getAction().size() > 0)
- forwardingEntryStruct.action.value = (uint8_t *)&getAction();
- else
- forwardingEntryStruct.action.value = 0;
- }
-
- void
- set(const struct ndn_ForwardingEntry& forwardingEntryStruct)
- {
- if (forwardingEntryStruct.action.value && forwardingEntryStruct.action.length > 0)
- setAction(string(forwardingEntryStruct.action.value, forwardingEntryStruct.action.value + forwardingEntryStruct.action.length));
- else
- setAction("");
-
- Name prefix;
- reinterpret_cast<c::Name&>(prefix).set(forwardingEntryStruct.prefix);
- setPrefix(prefix);
- // publisherPublicKeyDigest_.set(forwardingEntryStruct.publisherPublicKeyDigest);
- setFaceId(forwardingEntryStruct.faceId);
- // setForwardingFlags(forwardingEntryStruct.forwardingFlags);
- setFreshnessPeriod(forwardingEntryStruct.freshnessSeconds * 1000);
- }
-};
-
-}
-
-
-// This is declared in the WireFormat class.
-WireFormat*
-WireFormat::newInitialDefaultWireFormat()
-{
- return new BinaryXmlWireFormat();
-}
-
-Blob
-BinaryXmlWireFormat::encodeInterest(const Interest& interest)
-{
- struct ndn_NameComponent nameComponents[100];
- struct ndn_ExcludeEntry excludeEntries[100];
- struct ndn_Interest interestStruct;
- ndn_Interest_initialize
- (&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
- excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]));
- reinterpret_cast<const c::Interest&>(interest).get(interestStruct);
-
- BinaryXmlEncoder encoder;
- ndn_Error error;
- if ((error = ndn_encodeBinaryXmlInterest(&interestStruct, &encoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- return encoder.getOutput();
-}
-
-void
-BinaryXmlWireFormat::decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength)
-{
- struct ndn_NameComponent nameComponents[100];
- struct ndn_ExcludeEntry excludeEntries[100];
- struct ndn_Interest interestStruct;
- ndn_Interest_initialize
- (&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
- excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]));
-
- BinaryXmlDecoder decoder(input, inputLength);
- ndn_Error error;
- if ((error = ndn_decodeBinaryXmlInterest(&interestStruct, &decoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- reinterpret_cast<c::Interest&>(interest).set(interestStruct);
-}
-
-Blob
-BinaryXmlWireFormat::encodeData(const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
-{
- struct ndn_NameComponent nameComponents[100];
- struct ndn_NameComponent keyNameComponents[100];
- struct ndn_Data dataStruct;
- ndn_Data_initialize
- (&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
- keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
- reinterpret_cast<const c::Data&>(data).get(dataStruct);
-
- BinaryXmlEncoder encoder(1500);
- ndn_Error error;
- if ((error = ndn_encodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &encoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- return encoder.getOutput();
-}
-
-void
-BinaryXmlWireFormat::decodeData
- (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
-{
- struct ndn_NameComponent nameComponents[100];
- struct ndn_NameComponent keyNameComponents[100];
- struct ndn_Data dataStruct;
- ndn_Data_initialize
- (&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
- keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
-
- BinaryXmlDecoder decoder(input, inputLength);
- ndn_Error error;
- if ((error = ndn_decodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &decoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- reinterpret_cast<c::Data&>(data).set(dataStruct);
-}
-
-Blob
-BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
-{
- struct ndn_NameComponent prefixNameComponents[100];
- struct ndn_ForwardingEntry forwardingEntryStruct;
- ndn_ForwardingEntry_initialize
- (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
- reinterpret_cast<const c::ForwardingEntry&>(forwardingEntry).get(forwardingEntryStruct);
-
- BinaryXmlEncoder encoder;
- ndn_Error error;
- if ((error = ndn_encodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &encoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- return encoder.getOutput();
-}
-
-void
-BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength)
-{
- struct ndn_NameComponent prefixNameComponents[100];
- struct ndn_ForwardingEntry forwardingEntryStruct;
- ndn_ForwardingEntry_initialize
- (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
-
- BinaryXmlDecoder decoder(input, inputLength);
- ndn_Error error;
- if ((error = ndn_decodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &decoder)))
- throw runtime_error(ndn_getErrorString(error));
-
- reinterpret_cast<c::ForwardingEntry&>(forwardingEntry).set(forwardingEntryStruct);
-}
-
-}
diff --git a/src/encoding/element-listener.cpp b/src/encoding/element-listener.cpp
deleted file mode 100644
index 3b56717..0000000
--- a/src/encoding/element-listener.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <ndn-cpp-dev/encoding/element-listener.hpp>
-
-namespace ndn {
-
-void
-ElementListener::staticOnReceivedElement(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength)
-{
- ((ElementListener *)self)->onReceivedElement(element, elementLength);
-}
-
-}
diff --git a/src/encoding/wire-format.cpp b/src/encoding/wire-format.cpp
deleted file mode 100644
index cff24e5..0000000
--- a/src/encoding/wire-format.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <stdexcept>
-#include <ndn-cpp-dev/encoding/wire-format.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-static bool gotInitialDefaultWireFormat = false;
-
-WireFormat* WireFormat::defaultWireFormat_ = 0;
-
-WireFormat*
-WireFormat::getDefaultWireFormat()
-{
- if (!defaultWireFormat_ && !gotInitialDefaultWireFormat) {
- // There is no defaultWireFormat_ and we have not yet initialized initialDefaultWireFormat_, so initialize and use it.
- gotInitialDefaultWireFormat = true;
- // NOTE: This allocates one object which we never free for the life of the application.
- defaultWireFormat_ = newInitialDefaultWireFormat();
- }
-
- return defaultWireFormat_;
-}
-
-Blob
-WireFormat::encodeInterest(const Interest& interest)
-{
- throw logic_error("unimplemented");
-}
-
-void
-WireFormat::decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength)
-{
- throw logic_error("unimplemented");
-}
-
-Blob
-WireFormat::encodeData(const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
-{
- throw logic_error("unimplemented");
-}
-
-void
-WireFormat::decodeData
- (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
-{
- throw logic_error("unimplemented");
-}
-
-Blob
-WireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
-{
- throw logic_error("unimplemented");
-}
-
-void
-WireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength)
-{
- throw logic_error("unimplemented");
-}
-
-}
diff --git a/src/name.cpp b/src/name.cpp
index 7a3d171..3e2d1fe 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -10,8 +10,7 @@
#include <algorithm>
#include <string.h>
#include <ndn-cpp-dev/name.hpp>
-#include "c/util/ndn_memory.h"
-#include "c/util/time.h"
+#include "util/time.hpp"
#include "util/string-helper.hpp"
@@ -91,7 +90,7 @@
return 1;
// The components are equal length. Just do a byte compare.
- return ndn_memcmp(getValue().buf(), other.getValue().buf(), getValue().size());
+ return memcmp(getValue().buf(), other.getValue().buf(), getValue().size());
}
// const Block &
diff --git a/src/node.cpp b/src/node.cpp
index fe192cc..fb216ca 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -6,7 +6,7 @@
*/
#include <stdexcept>
-#include "c/util/time.h"
+#include "util/time.hpp"
#include <ndn-cpp-dev/forwarding-entry.hpp>
#include <ndn-cpp-dev/face-instance.hpp>
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index 8b68ac6..2072091 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -17,7 +17,8 @@
#include <fstream>
#include <boost/filesystem.hpp>
#include "../util/logging.hpp"
-#include "../c/util/time.h"
+#include "../util/time.hpp"
+
#include <ndn-cpp-dev/data.hpp>
#include <ndn-cpp-dev/security/identity-certificate.hpp>
#include <ndn-cpp-dev/security/sec-public-info-sqlite3.hpp>
diff --git a/src/transport/tcp-transport.cpp b/src/transport/tcp-transport.cpp
index f75dcd2..2e78cc3 100644
--- a/src/transport/tcp-transport.cpp
+++ b/src/transport/tcp-transport.cpp
@@ -10,7 +10,6 @@
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/transport/tcp-transport.hpp>
-#include "../c/util/ndn_memory.h"
#include <boost/asio.hpp>
#if NDN_CPP_HAVE_CXX11
@@ -179,7 +178,8 @@
if (partialDataSize_ > 0)
{
size_t newDataSize = std::min(bytes_recvd, MAX_LENGTH-partialDataSize_);
- ndn_memcpy(partialData_ + partialDataSize_, inputBuffer_, newDataSize);
+ std::copy(inputBuffer_, inputBuffer_ + newDataSize, partialData_ + partialDataSize_);
+
partialDataSize_ += newDataSize;
size_t offset = 0;
@@ -194,7 +194,7 @@
offset = 0;
partialDataSize_ = bytes_recvd - newDataSize;
- ndn_memcpy(partialData_, inputBuffer_ + newDataSize, partialDataSize_);
+ std::copy(inputBuffer_ + newDataSize, inputBuffer_ + newDataSize + partialDataSize_, partialData_);
processAll(partialData_, offset, partialDataSize_);
@@ -212,7 +212,7 @@
if (offset > 0)
{
partialDataSize_ -= offset;
- ndn_memcpy(partialData_, partialData_ + offset, partialDataSize_);
+ std::copy(partialData_ + offset, partialData_ + offset + partialDataSize_, partialData_);
}
else if (offset == 0 && partialDataSize_ == MAX_LENGTH)
{
@@ -235,7 +235,7 @@
if (offset > 0)
{
partialDataSize_ = bytes_recvd - offset;
- ndn_memcpy(partialData_, inputBuffer_ + offset, partialDataSize_);
+ std::copy(inputBuffer_ + offset, inputBuffer_ + offset + partialDataSize_, partialData_);
}
}
}
diff --git a/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
index 954b12c..5d26e15 100644
--- a/src/transport/unix-transport.cpp
+++ b/src/transport/unix-transport.cpp
@@ -10,7 +10,6 @@
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/transport/unix-transport.hpp>
-#include "../c/util/ndn_memory.h"
#include <boost/asio.hpp>
#if NDN_CPP_HAVE_CXX11
@@ -148,7 +147,8 @@
if (partialDataSize_ > 0)
{
size_t newDataSize = std::min(bytes_recvd, MAX_LENGTH-partialDataSize_);
- ndn_memcpy(partialData_ + partialDataSize_, inputBuffer_, newDataSize);
+ std::copy(inputBuffer_, inputBuffer_ + newDataSize, partialData_ + partialDataSize_);
+
partialDataSize_ += newDataSize;
size_t offset = 0;
@@ -163,7 +163,7 @@
offset = 0;
partialDataSize_ = bytes_recvd - newDataSize;
- ndn_memcpy(partialData_, inputBuffer_ + newDataSize, partialDataSize_);
+ std::copy(inputBuffer_ + newDataSize, inputBuffer_ + newDataSize + partialDataSize_, partialData_);
processAll(partialData_, offset, partialDataSize_);
@@ -181,7 +181,7 @@
if (offset > 0)
{
partialDataSize_ -= offset;
- ndn_memcpy(partialData_, partialData_ + offset, partialDataSize_);
+ std::copy(partialData_ + offset, partialData_ + offset + partialDataSize_, partialData_);
}
else if (offset == 0 && partialDataSize_ == MAX_LENGTH)
{
@@ -204,7 +204,7 @@
if (offset > 0)
{
partialDataSize_ = bytes_recvd - offset;
- ndn_memcpy(partialData_, inputBuffer_ + offset, partialDataSize_);
+ std::copy(inputBuffer_ + offset, inputBuffer_ + offset + partialDataSize_, partialData_);
}
}
}
diff --git a/src/util/blob-stream.hpp b/src/util/blob-stream.hpp
deleted file mode 100644
index 3bad4b7..0000000
--- a/src/util/blob-stream.hpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BLOB_STREAM_HPP
-#define NDN_BLOB_STREAM_HPP
-
-#include <ndn-cpp-dev/common.hpp>
-
-#if NDN_CPP_USE_SYSTEM_BOOST
-#include <boost/iostreams/detail/ios.hpp>
-#include <boost/iostreams/categories.hpp>
-#include <boost/iostreams/stream.hpp>
-namespace ndnboost = boost;
-#else
-// We can use ndnboost::iostreams because this is internal and will not conflict with the application if it uses boost::iostreams.
-#include <ndnboost/iostreams/detail/ios.hpp>
-#include <ndnboost/iostreams/categories.hpp>
-#include <ndnboost/iostreams/stream.hpp>
-#endif
-
-namespace ndn {
-
-class blob_append_device {
-public:
- typedef char char_type;
- typedef ndnboost::iostreams::sink_tag category;
-
- blob_append_device(std::vector<uint8_t>& container)
- : container_(container)
- {
- }
-
- std::streamsize
- write(const char_type* s, std::streamsize n)
- {
- std::copy(s, s+n, std::back_inserter(container_));
- return n;
- }
-
-protected:
- std::vector<uint8_t>& container_;
-};
-
-/**
- * This is called "blob_stream" but it doesn't use an ndn::Blob which is immutable. It uses a pointer to a vector<uint8_t>.
- * This is inteded for internal library use, not exported in the API.
- */
-struct blob_stream : public ndnboost::iostreams::stream<blob_append_device>
-{
- blob_stream()
- : buffer_(new std::vector<uint8_t>())
- , device_(*buffer_)
- {
- open(device_);
- }
-
- ptr_lib::shared_ptr<std::vector<uint8_t> >
- buf()
- {
- flush();
- return buffer_;
- }
-
-private:
- ptr_lib::shared_ptr<std::vector<uint8_t> > buffer_;
- blob_append_device device_;
-};
-
-}
-
-#endif
diff --git a/src/util/blob.cpp b/src/util/blob.cpp
deleted file mode 100644
index 46297c6..0000000
--- a/src/util/blob.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "../c/util/blob.h"
-#include <ndn-cpp-dev/util/blob.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-Blob::Blob(const struct ndn_Blob& blobStruct)
- : ptr_lib::shared_ptr<const vector<uint8_t> >(new vector<uint8_t>(blobStruct.value, blobStruct.value + blobStruct.length))
-{
-}
-
-void
-Blob::get(struct ndn_Blob& blobStruct) const
-{
- blobStruct.length = size();
- if (size() > 0)
- blobStruct.value = (uint8_t*)buf();
- else
- blobStruct.value = 0;
-}
-
-}
diff --git a/src/util/changed-event.cpp b/src/util/changed-event.cpp
deleted file mode 100644
index 08dcb98..0000000
--- a/src/util/changed-event.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "changed-event.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-void
-ChangedEvent::fire()
-{
- for (size_t i = 0; i < listeners_.size(); ++i)
- listeners_[i]();
-}
-
-}
diff --git a/src/util/changed-event.hpp b/src/util/changed-event.hpp
deleted file mode 100644
index aee8549..0000000
--- a/src/util/changed-event.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_CHANGED_EVENT_HPP
-#define NDN_CHANGED_EVENT_HPP
-
-#include <vector>
-#include <ndn-cpp-dev/common.hpp>
-
-namespace ndn {
-
-/**
- * An OnChanged function object is called to notify a listener of a changed event.
- */
-typedef func_lib::function<void()> OnChanged;
-
-class ChangedEvent {
-public:
- /**
- * Add onChanged to the listener list. This does not check if a duplicate is already in the list.
- * @param onChanged The OnChanged function object.
- */
- void
- add(OnChanged onChanged)
- {
- listeners_.push_back(onChanged);
- }
-
- /**
- * Call all the listeners.
- */
- void
- fire();
-
-#if 0
-private:
-#endif
- std::vector<OnChanged> listeners_;
-};
-
-}
-
-#endif
diff --git a/src/c/util/crypto.c b/src/util/crypto.cpp
similarity index 82%
rename from src/c/util/crypto.c
rename to src/util/crypto.cpp
index 384e5b8..ce17259 100644
--- a/src/c/util/crypto.c
+++ b/src/util/crypto.cpp
@@ -4,7 +4,9 @@
* See COPYING for copyright and distribution information.
*/
-#include "ndn-cpp-dev/c/util/crypto.h"
+#include "ndn-cpp-dev/util/crypto.hpp"
+
+namespace ndn {
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
{
@@ -13,3 +15,5 @@
SHA256_Update(&sha256, data, dataLength);
SHA256_Final(digest, &sha256);
}
+
+} // namespace ndn
diff --git a/src/util/dynamic-uint8-vector.cpp b/src/util/dynamic-uint8-vector.cpp
deleted file mode 100644
index 197fc0e..0000000
--- a/src/util/dynamic-uint8-vector.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "dynamic-uint8-vector.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-DynamicUInt8Vector::DynamicUInt8Vector(size_t initialLength)
-: vector_(new vector<uint8_t>(initialLength))
-{
- ndn_DynamicUInt8Array_initialize(this, &vector_->front(), initialLength, DynamicUInt8Vector::realloc);
-}
-
-uint8_t*
-DynamicUInt8Vector::realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length)
-{
- // Because this method is private, assume there is not a problem with upcasting.
- DynamicUInt8Vector *thisObject = (DynamicUInt8Vector *)self;
-
- if (array != &thisObject->vector_->front())
- // We don't expect this to ever happen. The caller didn't pass the array from this object.
- return 0;
-
- thisObject->vector_->resize(length);
- return &thisObject->vector_->front();
-}
-
-}
diff --git a/src/util/dynamic-uint8-vector.hpp b/src/util/dynamic-uint8-vector.hpp
deleted file mode 100644
index 55ed1ee..0000000
--- a/src/util/dynamic-uint8-vector.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_DYNAMIC_UCHAR_VECTOR_HPP
-#define NDN_DYNAMIC_UCHAR_VECTOR_HPP
-
-#include <vector>
-#include <ndn-cpp-dev/common.hpp>
-#include "../c/util/dynamic-uint8-array.h"
-
-namespace ndn {
-
-/**
- * A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr<vector<uint8_t> > for use with
- * C functions which need an ndn_DynamicUInt8Array.
- */
-class DynamicUInt8Vector : public ndn_DynamicUInt8Array {
-public:
- /**
- * Create a new DynamicUInt8Vector with an initial length.
- * @param initialLength The initial size of the allocated vector.
- */
- DynamicUInt8Vector(size_t initialLength);
-
- /**
- * Get the shared_ptr to the allocated vector.
- * @return The shared_ptr to the allocated vector.
- */
- ptr_lib::shared_ptr<std::vector<uint8_t> >&
- get() { return vector_; }
-
-private:
- /**
- * Implement the static realloc function using vector resize.
- * @param self A pointer to this object.
- * @param array Should be the front of the vector.
- * @param length The new length for the vector.
- * @return The front of the allocated vector.
- */
- static uint8_t*
- realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length);
-
- ptr_lib::shared_ptr<std::vector<uint8_t> > vector_;
-};
-
-}
-
-#endif
diff --git a/src/util/ndnd-id-fetcher.hpp b/src/util/ndnd-id-fetcher.hpp
index 6a1224e..e10eb38 100644
--- a/src/util/ndnd-id-fetcher.hpp
+++ b/src/util/ndnd-id-fetcher.hpp
@@ -9,7 +9,7 @@
#define NDN_NDND_ID_FETCHER_HPP
#include <ndn-cpp-dev/common.hpp>
-#include "ndn-cpp-dev/c/util/crypto.h"
+#include "ndn-cpp-dev/util/crypto.hpp"
namespace ndn {
diff --git a/src/c/util/time.c b/src/util/time.cpp
similarity index 76%
rename from src/c/util/time.c
rename to src/util/time.cpp
index 00719c2..03eb81b 100644
--- a/src/c/util/time.c
+++ b/src/util/time.cpp
@@ -14,9 +14,11 @@
#include <math.h>
#include <string.h>
#include <stdio.h>
-#include "time.h"
+#include "time.hpp"
-ndn_MillisecondsSince1970
+namespace ndn {
+
+MillisecondsSince1970
ndn_getNowMilliseconds()
{
struct timeval t;
@@ -25,15 +27,15 @@
return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
}
-ndn_Error
-ndn_toIsoString(ndn_MillisecondsSince1970 milliseconds, char *isoString)
+int
+ndn_toIsoString(MillisecondsSince1970 milliseconds, char *isoString)
{
#if NDN_CPP_HAVE_GMTIME_SUPPORT
if (milliseconds < 0)
- return NDN_ERROR_Calendar_time_value_out_of_range;
+ return -1;
else if (milliseconds > 2e14)
// 2e14 is about the year 8300. We don't want to go over a 4-digit year.
- return NDN_ERROR_Calendar_time_value_out_of_range;
+ return -1;
double secondsSince1970 = milliseconds / 1000.0;
char fractionBuffer[10];
@@ -48,14 +50,14 @@
sprintf(isoString, "%04d%02d%02dT%02d%02d%02d%s", 1900 + gmt->tm_year, gmt->tm_mon + 1, gmt->tm_mday,
gmt->tm_hour, gmt->tm_min, gmt->tm_sec, fraction);
- return NDN_ERROR_success;
+ return 0;
#else
- return NDN_ERROR_Time_functions_are_not_supported_by_the_standard_library;
+ return -1;
#endif
}
-ndn_Error
-ndn_fromIsoString(const char* isoString, ndn_MillisecondsSince1970 *milliseconds)
+int
+ndn_fromIsoString(const char* isoString, MillisecondsSince1970 *milliseconds)
{
#if NDN_CPP_HAVE_GMTIME_SUPPORT
// Initialize time zone, etc.
@@ -74,8 +76,10 @@
tm1.tm_sec = 0;
*milliseconds = (timegm(&tm1) + seconds) * 1000.0;
- return NDN_ERROR_success;
+ return 0;
#else
- return NDN_ERROR_Time_functions_are_not_supported_by_the_standard_library;
+ return -1;
#endif
}
+
+} // namespace ndn
diff --git a/src/util/time.hpp b/src/util/time.hpp
index 90482d9..5e5dc7c 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -8,11 +8,19 @@
#ifndef NDN_TIME_HPP
#define NDN_TIME_HPP
-#include <stdexcept>
-#include "../c/util/time.h"
+#include "ndn-cpp-dev/common.hpp"
namespace ndn {
+MillisecondsSince1970
+ndn_getNowMilliseconds();
+
+int
+ndn_toIsoString(MillisecondsSince1970 milliseconds, char *isoString);
+
+int
+ndn_fromIsoString(const char* isoString, MillisecondsSince1970 *milliseconds);
+
/**
* Convert to the ISO string representation of the time.
* @param time Milliseconds since 1/1/1970.
@@ -22,9 +30,9 @@
toIsoString(const MillisecondsSince1970& time)
{
char isoString[25];
- ndn_Error error;
+ int error;
if ((error = ndn_toIsoString(time, isoString)))
- throw std::runtime_error(ndn_getErrorString(error));
+ throw std::runtime_error("toIsoString");
return isoString;
}
@@ -38,9 +46,9 @@
fromIsoString(const std::string& isoString)
{
MillisecondsSince1970 milliseconds;
- ndn_Error error;
+ int error;
if ((error = ndn_fromIsoString(isoString.c_str(), &milliseconds)))
- throw std::runtime_error(ndn_getErrorString(error));
+ throw std::runtime_error("fromIsoString");
return milliseconds;
}