Move C code into ndn-cpp/c
diff --git a/ndn-cpp/encoding/BinaryXML.h b/ndn-cpp/encoding/BinaryXML.h
deleted file mode 100644
index e39c785..0000000
--- a/ndn-cpp/encoding/BinaryXML.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more 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_CCNProtocolDataUnit = 17702112
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.c b/ndn-cpp/encoding/BinaryXMLDecoder.c
deleted file mode 100644
index 6a8900a..0000000
--- a/ndn-cpp/encoding/BinaryXMLDecoder.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#include "BinaryXML.h"
-#include "BinaryXMLDecoder.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);
-}
-
-char *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_BinaryXMLDecoder_decodeTypeAndVal: read past the end of the input";
-
- unsigned int octet = unsafeReadOctet(self);
-
- if (!gotFirstOctet) {
- if (octet == 0)
- return "ndn_BinaryXMLDecoder_decodeTypeAndVal: 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 0;
-}
-
-char *ndn_BinaryXMLDecoder_readDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag)
-{
- char *error;
- unsigned int type;
- unsigned int value;
- if (error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value))
- return error;
-
- if (type != ndn_BinaryXML_DTAG)
- return "ndn_BinaryXMLDecoder_readDTag: header type is not a DTAG";
-
- if (value != expectedTag)
- return "ndn_BinaryXMLDecoder_readDTag: did not get the expected DTAG";
-
- return 0;
-}
-
-char *ndn_BinaryXMLDecoder_readElementClose(struct ndn_BinaryXMLDecoder *self)
-{
- if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_readElementClose: read past the end of the input";
-
- if (unsafeReadOctet(self) != ndn_BinaryXML_CLOSE)
- return "ndn_BinaryXMLDecoder_readDTag: did not get the expected element close";
-
- return 0;
-}
-
-char *ndn_BinaryXMLDecoder_peekDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *gotExpectedTag)
-{
- // 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_BinaryXMLDecoder_readElementClose: read past the end of the input";
- if (unsafeGetOctet(self) == 0)
- return 0;
-
- unsigned int type;
- unsigned int value;
- unsigned int saveOffset = self->offset;
- char *error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value);
- // Restore offset.
- self->offset = saveOffset;
-
- if (error)
- return error;
-
- if (type == ndn_BinaryXML_DTAG && value == expectedTag)
- *gotExpectedTag = 1;
-
- return 0;
-}
-
-char *ndn_BinaryXMLDecoder_readBinaryDTagElement
- (struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int allowNull, unsigned char **value, unsigned int *valueLen)
-{
- char *error;
- if (error = ndn_BinaryXMLDecoder_readDTag(self, expectedTag))
- return error;
-
- if (allowNull) {
- if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_readBinaryDTagElement: 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 = 0;
- *valueLen = 0;
- return 0;
- }
- }
-
- unsigned int itemType;
- if (error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &itemType, valueLen))
- return error;
- // Ignore itemType.
- *value = self->input + self->offset;
- self->offset += *valueLen;
-
- if (error = ndn_BinaryXMLDecoder_readElementClose(self))
- return error;
-
- return 0;
-}
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.h b/ndn-cpp/encoding/BinaryXMLDecoder.h
deleted file mode 100644
index 0f3285b..0000000
--- a/ndn-cpp/encoding/BinaryXMLDecoder.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#ifndef NDN_BINARYXMLDECODER_H
-#define NDN_BINARYXMLDECODER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_BinaryXMLDecoder {
- unsigned char *input;
- unsigned int inputLength;
- unsigned int offset;
-};
-
-static inline void ndn_BinaryXMLDecoder_init(struct ndn_BinaryXMLDecoder *self, unsigned char *input, unsigned int inputLength)
-{
- self->input = input;
- self->inputLength = inputLength;
- self->offset = 0;
-}
-
-/**
- * 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 string for read past the end of the input or if the initial byte is zero
- */
-char *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 string, including an error if not the expected tag
- */
-char *ndn_BinaryXMLDecoder_readDTag(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 string, including an error if not the element close
- */
-char *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 string for read past the end of the input
- */
-char *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 return 0.
- * @param valueLen output the length of the binary data. However, if allowNull is 1 and the
- * binary data item is absent, then return 0.
- * @return 0 for success, else an error string, including an error if not the expected tag, or if allowNull is 0
- * and the binary data is absent
- */
-char *ndn_BinaryXMLDecoder_readBinaryDTagElement
- (struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int allowNull, unsigned char **value, unsigned int *valueLen);
-
-/**
- * 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, unsigned int offset)
-{
- self->offset = offset;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ndn-cpp/encoding/BinaryXMLEncoder.c b/ndn-cpp/encoding/BinaryXMLEncoder.c
deleted file mode 100644
index c70a44a..0000000
--- a/ndn-cpp/encoding/BinaryXMLEncoder.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#include "BinaryXML.h"
-#include "BinaryXMLEncoder.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)
-};
-
-/**
- * Return the number of bytes to encode a header of value x.
- */
-static unsigned int getNEncodingBytes(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;
-
- unsigned int 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;
-}
-
-char *ndn_BinaryXMLEncoder_encodeTypeAndValue(struct ndn_BinaryXMLEncoder *self, unsigned int type, unsigned int value)
-{
- if (type > ndn_BinaryXML_UDATA)
- return "ndn_BinaryXMLEncoder_encodeTypeAndValue: type is out of range";
-
- // Encode backwards. Calculate how many bytes we need.
- unsigned int nEncodingBytes = getNEncodingBytes(value);
- char *error;
- if (error = ndn_DynamicUCharArray_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.)
- unsigned int 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 getNEncodingBytes is correct.
- return "ndn_BinaryXMLEncoder_encodeTypeAndValue: : miscalculated N encoding bytes";
-
- self->offset+= nEncodingBytes;
-
- return 0;
-}
diff --git a/ndn-cpp/encoding/BinaryXMLEncoder.h b/ndn-cpp/encoding/BinaryXMLEncoder.h
deleted file mode 100644
index e606dee..0000000
--- a/ndn-cpp/encoding/BinaryXMLEncoder.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#ifndef NDN_BINARYXMLENCODER_H
-#define NDN_BINARYXMLENCODER_H
-
-#include "../util/DynamicUCharArray.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_BinaryXMLEncoder {
- struct ndn_DynamicUCharArray output; /**< receives the encoded output */
- unsigned int offset; /**< the offset into output.array for the next encoding */
-};
-
-/**
- * Initialize an ndn_BinaryXMLEncoder_init struct with the arguments for initializing the ndn_DynamicUCharArray.
- * @param self pointer to the ndn_BinaryXMLEncoder struct
- * @param outputArray the allocated array buffer to receive the encoding
- * @param outputArrayLength the length of outputArray
- * @param reallocFunction the realloc function used by ndn_DynamicUCharArray_ensureLength. If outputArrayLength
- * is large enough to receive the entire encoding, this can be 0.
- */
-static inline void ndn_BinaryXMLEncoder_init
- (struct ndn_BinaryXMLEncoder *self, unsigned char *outputArray, unsigned int outputArrayLength,
- unsigned char (*reallocFunction)(unsigned char *, unsigned int))
-{
- ndn_DynamicUCharArray_init(&self->output, outputArray, outputArrayLength, reallocFunction);
- self->offset = 0;
-}
-
-char *ndn_BinaryXMLEncoder_encodeTypeAndValue(struct ndn_BinaryXMLEncoder *self, unsigned int type, unsigned int value);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/ndn-cpp/encoding/BinaryXMLName.c b/ndn-cpp/encoding/BinaryXMLName.c
deleted file mode 100644
index 6a4aebb..0000000
--- a/ndn-cpp/encoding/BinaryXMLName.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#include "BinaryXMLDecoder.h"
-#include "BinaryXML.h"
-#include "BinaryXMLName.h"
-
-char *ndn_decodeBinaryXMLName(struct ndn_Name *name, unsigned char *input, unsigned int inputLength)
-{
- struct ndn_BinaryXMLDecoder decoder;
- ndn_BinaryXMLDecoder_init(&decoder, input, inputLength);
-
- char *error;
- if (error = ndn_BinaryXMLDecoder_readDTag(&decoder, ndn_BinaryXML_DTag_Name))
- return error;
-
- while (1) {
- int gotExpectedTag;
- if (error = ndn_BinaryXMLDecoder_peekDTag(&decoder, ndn_BinaryXML_DTag_Component, &gotExpectedTag))
- return error;
-
- if (!gotExpectedTag)
- // No more components.
- break;
-
- unsigned char *component;
- unsigned int componentLen;
- if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement(&decoder, ndn_BinaryXML_DTag_Component, 0, &component, &componentLen))
- return error;
-
- // Add the component to the name.
- if (name->nComponents >= name->maxComponents)
- return "ndn_decodeBinaryXMLName: read a component past the maximum number of components allowed in the name";
- ndn_NameComponent_init(name->components + name->nComponents, component, componentLen);
- ++name->nComponents;
- }
-
- if (error = ndn_BinaryXMLDecoder_readElementClose(&decoder))
- return error;
-
- return 0;
-}
diff --git a/ndn-cpp/encoding/BinaryXMLName.h b/ndn-cpp/encoding/BinaryXMLName.h
deleted file mode 100644
index 3a83b8c..0000000
--- a/ndn-cpp/encoding/BinaryXMLName.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#ifndef NDN_BINARYXMLNAME_H
-#define NDN_BINARYXMLNAME_H
-
-#include "../Name.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-char *ndn_decodeBinaryXMLName(struct ndn_Name *name, unsigned char *input, unsigned int inputLength);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/ndn-cpp/encoding/BinaryXMLStructureDecoder.c b/ndn-cpp/encoding/BinaryXMLStructureDecoder.c
deleted file mode 100644
index a2fd405..0000000
--- a/ndn-cpp/encoding/BinaryXMLStructureDecoder.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#include "../util/ndn_memory.h"
-#include "BinaryXML.h"
-#include "BinaryXMLDecoder.h"
-#include "BinaryXMLStructureDecoder.h"
-
-void ndn_BinaryXMLStructureDecoder_init(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;
-}
-
-char *ndn_BinaryXMLStructureDecoder_findElementEnd
- (struct ndn_BinaryXMLStructureDecoder *self, unsigned char *input, unsigned int inputLength)
-{
- if (self->gotElementEnd)
- // Someone is calling when we already got the end.
- return 0;
-
- struct ndn_BinaryXMLDecoder decoder;
- ndn_BinaryXMLDecoder_init(&decoder, input, inputLength);
-
- while (1) {
- if (self->offset >= inputLength)
- // All the cases assume we have some input. Return and wait for more.
- return 0;
-
- 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 0;
- }
- if (self->level < 0)
- return "ndn_BinaryXMLStructureDecoder_findElementEnd: Unexpected close tag";
-
- // Get ready for the next header.
- startHeader(self);
- continue;
- }
-
- unsigned int 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_BinaryXMLStructureDecoder_findElementEnd: Can't store more header bytes than the size of headerBuffer";
- self->useHeaderBuffer = 1;
- unsigned int nNewBytes = self->headerLength - startingHeaderLength;
- ndn_memcpy(self->headerBuffer + startingHeaderLength, input + (self->offset - nNewBytes), nNewBytes);
-
- return 0;
- }
- 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_BinaryXMLStructureDecoder_findElementEnd: Can't store more header bytes than the size of headerBuffer";
- unsigned int 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_init(&bufferDecoder, self->headerBuffer, sizeof(self->headerBuffer));
- if (ndn_BinaryXMLDecoder_decodeTypeAndValue(&bufferDecoder, &type, &value))
- return "ndn_BinaryXMLStructureDecoder_findElementEnd: Can't 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_BinaryXMLStructureDecoder_findElementEnd: Can't 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_BinaryXMLStructureDecoder_findElementEnd: Unrecognized header type";
- }
- else if (self->state == ndn_BinaryXMLStructureDecoder_READ_BYTES) {
- unsigned int nRemainingBytes = inputLength - self->offset;
- if (nRemainingBytes < self->nBytesToRead) {
- // Need more.
- self->offset += nRemainingBytes;
- self->nBytesToRead -= nRemainingBytes;
- return 0;
- }
- // 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_BinaryXMLStructureDecoder_findElementEnd: Unrecognized state";
- }
-}
diff --git a/ndn-cpp/encoding/BinaryXMLStructureDecoder.h b/ndn-cpp/encoding/BinaryXMLStructureDecoder.h
deleted file mode 100644
index 504a1bd..0000000
--- a/ndn-cpp/encoding/BinaryXMLStructureDecoder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Author: Jeff Thompson
- *
- * BSD license, See the LICENSE file for more information.
- */
-
-#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
-#define NDN_BINARYXMLSTRUCTUREDECODER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ndn_BinaryXMLStructureDecoder {
- int gotElementEnd; /**< boolean */
- unsigned int offset;
- int level;
- int state;
- unsigned int headerLength;
- int useHeaderBuffer; /**< boolean */
- // 10 bytes is enough to hold an encoded header with a type and a 64 bit value.
- unsigned char headerBuffer[10];
- int nBytesToRead;
-};
-
-enum {
- ndn_BinaryXMLStructureDecoder_READ_HEADER_OR_CLOSE,
- ndn_BinaryXMLStructureDecoder_READ_BYTES
-};
-
-void ndn_BinaryXMLStructureDecoder_init(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 string
- */
-char *ndn_BinaryXMLStructureDecoder_findElementEnd
- (struct ndn_BinaryXMLStructureDecoder *self, unsigned char *input, unsigned int inputLength);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index e771522..b453794 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -5,7 +5,7 @@
*/
#include <stdexcept>
-#include "BinaryXMLName.h"
+#include "../c/encoding/BinaryXMLName.h"
#include "../Name.hpp"
#include "BinaryXMLWireFormat.hpp"