build: Finalizing waf building system (removing legacy code)
Change-Id: Ie7e7cc84e19551e3dd5dd0405b14f289ea54e7cd
diff --git a/examples/wscript b/examples/wscript
index bafda9c..a3a5e8a 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -7,6 +7,6 @@
bld(features=['cxx', 'cxxprogram'],
target = '%s' % (str(app.change_ext('','.cpp'))),
source = app,
- use = 'ndn-cpp-dev',
- includes = "../include",
+ use = 'ndn-cpp-dev-stlib',
+ install_prefix = None,
)
diff --git a/include/ndn-cpp-dev/c/common.h b/include/ndn-cpp-dev/c/common.h
deleted file mode 100644
index 42edcef..0000000
--- a/include/ndn-cpp-dev/c/common.h
+++ /dev/null
@@ -1,33 +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_COMMON_H
-#define NDN_COMMON_H
-
-#include <ndn-cpp-dev/ndn-cpp-config.h>
-#include <stdint.h>
-// TODO: Is stddef.h portable?
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * A time interval represented as the number of milliseconds.
- */
-typedef int64_t ndn_Milliseconds;
-
-/**
- * The calendar time represented as the number of milliseconds since 1/1/1970.
- */
-typedef int64_t ndn_MillisecondsSince1970;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/c/data-types.h b/include/ndn-cpp-dev/c/data-types.h
deleted file mode 100644
index 668786b..0000000
--- a/include/ndn-cpp-dev/c/data-types.h
+++ /dev/null
@@ -1,27 +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_TYPES_H
-#define NDN_DATA_TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- ndn_ContentType_DATA = 0,
- ndn_ContentType_ENCR = 1,
- ndn_ContentType_GONE = 2,
- ndn_ContentType_KEY = 3,
- ndn_ContentType_LINK = 4,
- ndn_ContentType_NACK = 5
-} ndn_ContentType;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/c/encoding/element-listener.h b/include/ndn-cpp-dev/c/encoding/element-listener.h
deleted file mode 100644
index af88a85..0000000
--- a/include/ndn-cpp-dev/c/encoding/element-listener.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_ELEMENT_LISTENER_H
-#define NDN_ELEMENT_LISTENER_H
-
-#include "../common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** An ndn_ElementListener struct holds a function pointer onReceivedElement. You can extend this struct with data that
- * will be passed to onReceivedElement.
- */
-struct ndn_ElementListener {
- void (*onReceivedElement)(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength); /**< see ndn_ElementListener_initialize */
-};
-
-/**
- * Initialize an ndn_ElementListener struct to use the onReceivedElement function pointer.
- * @param self pointer to the ndn_ElementListener struct
- * @param onReceivedElement pointer to a function which is called when an entire binary XML element is received.
- * self is the pointer to this ndn_ElementListener struct. See ndn_BinaryXmlElementReader_onReceivedData.
- */
-static inline void ndn_ElementListener_initialize
- (struct ndn_ElementListener *self, void (*onReceivedElement)(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength))
-{
- self->onReceivedElement = onReceivedElement;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/c/forwarding-flags.h b/include/ndn-cpp-dev/c/forwarding-flags.h
deleted file mode 100644
index 863bf04..0000000
--- a/include/ndn-cpp-dev/c/forwarding-flags.h
+++ /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.
- */
-
-#ifndef NDN_FORWARDING_FLAGS_H
-#define NDN_FORWARDING_FLAGS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * An ndn_ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an interest for
- * a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding
- * bits are changed, amended or deprecated.
- */
-struct ndn_ForwardingFlags {
- int active; /**< 1 if the flag is set, 0 if cleared. */
- int childInherit;
- int advertise;
- int last;
- int capture;
- int local;
- int tap;
- int captureOk;
-};
-
-/**
- * Initialize an ndn_ForwardingFlags struct with the default with "active" and "childInherit" set and all other flags cleared.
- * @param self A pointer to the ndn_ForwardingFlags struct.
- */
-void ndn_ForwardingFlags_initialize(struct ndn_ForwardingFlags *self);
-
-/**
- * Get an integer with the bits set according to the flags as used by the ForwardingEntry message.
- * @param self A pointer to the ndn_ForwardingFlags struct.
- * @return An integer with the bits set.
- */
-int ndn_ForwardingFlags_getForwardingEntryFlags(struct ndn_ForwardingFlags *self);
-
-/**
- * Set the flags according to the bits in forwardingEntryFlags as used by the ForwardingEntry message.
- * @param self A pointer to the ndn_ForwardingFlags struct.
- * @param flags An integer with the bits set.
- */
-void ndn_ForwardingFlags_setForwardingEntryFlags(struct ndn_ForwardingFlags *self, int forwardingEntryFlags);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/c/interest-types.h b/include/ndn-cpp-dev/c/interest-types.h
deleted file mode 100644
index a464e17..0000000
--- a/include/ndn-cpp-dev/c/interest-types.h
+++ /dev/null
@@ -1,36 +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_TYPES_H
-#define NDN_INTEREST_TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- ndn_Exclude_COMPONENT = 0,
- ndn_Exclude_ANY = 1
-} ndn_ExcludeType;
-
-enum {
- ndn_Interest_CHILD_SELECTOR_LEFT = 0,
- ndn_Interest_CHILD_SELECTOR_RIGHT = 1,
-
- ndn_Interest_ANSWER_NO_CONTENT_STORE = 0,
- ndn_Interest_ANSWER_CONTENT_STORE = 1,
- ndn_Interest_ANSWER_GENERATED = 2,
- ndn_Interest_ANSWER_STALE = 4, // Stale answer OK
- ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack"
-
- ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/c/key-types.h b/include/ndn-cpp-dev/c/key-types.h
deleted file mode 100644
index 712aee8..0000000
--- a/include/ndn-cpp-dev/c/key-types.h
+++ /dev/null
@@ -1,31 +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_TYPES_H
-#define NDN_KEY_TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- ndn_KeyLocatorType_KEY = 1,
- ndn_KeyLocatorType_CERTIFICATE = 2,
- ndn_KeyLocatorType_KEYNAME = 3
-} ndn_KeyLocatorType;
-
-typedef enum {
- ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST = 1,
- ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST = 2,
- ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST = 3,
- ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST = 4
-} ndn_KeyNameType;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/ndn-cpp-dev/common.hpp b/include/ndn-cpp-dev/common.hpp
index 5efd3a0..95772b6 100644
--- a/include/ndn-cpp-dev/common.hpp
+++ b/include/ndn-cpp-dev/common.hpp
@@ -8,9 +8,12 @@
#ifndef NDN_COMMON_HPP
#define NDN_COMMON_HPP
+#include <ndn-cpp-dev/ndn-cpp-config.h>
+#include <stdint.h>
+// TODO: Is stddef.h portable?
+#include <stddef.h>
+
#include <vector>
-// common.h include ndn-cpp-config.h.
-#include "c/common.h"
#if NDN_CPP_HAVE_CXX11
@@ -18,9 +21,6 @@
#error "NDN-CPP-DEV library is configured and compiled in C++11 mode, but the current compiler is not C++11 enabled"
#endif
-// Depending on where ./configure found shared_ptr, define the ptr_lib namespace.
-// We always use ndn::ptr_lib.
-// #if NDN_CPP_HAVE_STD_SHARED_PTR
#include <memory>
namespace ndn { namespace ptr_lib = std; }
@@ -28,7 +28,7 @@
#include <functional>
namespace ndn { namespace func_lib = std; }
-#elif NDN_CPP_USE_SYSTEM_BOOST
+#else
// #if NDN_CPP_HAVE_BOOST_SHARED_PTR
#include <boost/shared_ptr.hpp>
@@ -41,37 +41,6 @@
#include <boost/bind.hpp>
namespace ndn { namespace func_lib = boost; }
-#else // use embedded boost headers
-/* Use the boost header files in this distribution that were extracted with:
-cd <BOOST DEVELOPMENT DIRECTORY WITH boost SUBDIRECTORY>
-dist/bin/bcp --namespace=ndnboost shared_ptr make_shared weak_ptr function bind any iostreams <NDN-CPP-DEV ROOT>/include
-cd <NDN-CPP-DEV ROOT>/include
-rm -rf boost.css boost.png Jamroot libs
-mv boost ndnboost
-cd ndnboost
-# Replace when including files.
-(unset LANG; find . -type f -exec sed -i '' 's/\<boost\//\<ndnboost\//g' {} +)
-(unset LANG; find . -type f -exec sed -i '' 's/\"boost\//\"ndnboost\//g' {} +)
-(unset LANG; find . -type f -exec sed -i '' 's/ boost\// ndnboost\//g' {} +)
-(unset LANG; find . -type f -exec sed -i '' 's/(boost\//(ndnboost\//g' {} +)
-# Replace macro definitions.
-(unset LANG; find . -type f -exec sed -i '' 's/BOOST_/NDNBOOST_/g' {} +)
-# Replace header include guards which don't start with BOOST_ . This may result in some with NDNBOOST twice, but that is OK.
-(unset LANG; find . -type f -exec sed -i '' 's/_DWA/_NDNBOOST_DWA/g' {} +)
-(unset LANG; find . -type f -exec sed -i '' 's/ UUID_/ NDNBOOST_UUID_/g' {} +)
-(unset LANG; find . -type f -exec sed -i '' 's/ FILE_boost/ FILE_ndnboost/g' {} +)
-# Replace the mpl_ barrier namespace. This should only change file adl_barrier.hpp.
-(unset LANG; find . -type f -exec sed -i '' 's/ mpl_/ ndnboost_mpl_/g' {} +)
- */
-#include <ndnboost/shared_ptr.hpp>
-#include <ndnboost/make_shared.hpp>
-namespace ndn { namespace ptr_lib = ndnboost; }
-
-// Use the boost header files in this distribution that were extracted as above:
-#include <ndnboost/function.hpp>
-#include <ndnboost/bind.hpp>
-namespace ndn { namespace func_lib = ndnboost; }
-
#endif
namespace ndn {
diff --git a/include/ndn-cpp-dev/c/util/crypto.h b/include/ndn-cpp-dev/util/crypto.hpp
similarity index 77%
rename from include/ndn-cpp-dev/c/util/crypto.h
rename to include/ndn-cpp-dev/util/crypto.hpp
index 43d47eb..8908a76 100644
--- a/include/ndn-cpp-dev/c/util/crypto.h
+++ b/include/ndn-cpp-dev/util/crypto.hpp
@@ -4,16 +4,15 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NDN_CRYPTO_H
-#define NDN_CRYPTO_H
+#ifndef NDN_UTIL_CRYPTO_HPP
+#define NDN_UTIL_CRYPTO_HPP
+
+#include "ndn-cpp-dev/common.hpp"
#include <openssl/ssl.h>
#include <openssl/rsa.h>
-#include <ndn-cpp-dev/c/common.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+namespace ndn {
/**
* Compute the sha-256 digest of data.
@@ -23,8 +22,6 @@
*/
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest);
-#ifdef __cplusplus
-}
-#endif
+} // namespace ndn
-#endif
+#endif // NDN_UTIL_CRYPTO_HPP
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;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ae99ab5..2e80613 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,13 +1,15 @@
-LDADD = ../libndn-cpp-dev.la @BOOST_SYSTEM_LIB@
+noinst_PROGRAMS=unit-tests
-noinst_PROGRAMS = \
- test-get-async \
- test-publish-async \
- test-encode-decode-benchmark
+# for i in `find . -name '*.cpp'`; do echo " $i \\"; done
+unit_tests_SOURCES = \
+ main.cpp \
+ test-encode-decode-certificate.cpp \
+ test-encode-decode-data.cpp \
+ test-encode-decode-interest.cpp \
+ test-encode-decode-forwarding-entry.cpp \
+ test-encode-decode-block.cpp \
+ test-sec-tpm-file.cpp \
+ test-faces.cpp
-test_encode_decode_benchmark_SOURCES = test-encode-decode-benchmark.cpp
-
-test_get_async_SOURCES = test-get-async.cpp
-
-test_publish_async_SOURCES = test-publish-async.cpp
+unit_tests_LDADD = ../libndn-cpp-dev.la @BOOST_SYSTEM_LIB@ @BOOST_UNIT_TEST_FRAMEWORK_LIB@ @OPENSSL_LIBS@ @CRYPTOPP_LIBS@ @OSX_SECURITY_LIBS@
diff --git a/tests_boost/main.cpp b/tests/main.cpp
similarity index 100%
rename from tests_boost/main.cpp
rename to tests/main.cpp
diff --git a/tests/test-encode-decode-benchmark.cpp b/tests/test-encode-decode-benchmark.cpp
deleted file mode 100644
index bb678f0..0000000
--- a/tests/test-encode-decode-benchmark.cpp
+++ /dev/null
@@ -1,481 +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 <iostream>
-#include <time.h>
-#include <sys/time.h>
-#include <sstream>
-#include <stdexcept>
-#include <ndn-cpp-dev/data.hpp>
-#include <ndn-cpp-dev/security/key-chain.hpp>
-// #include <ndn-cpp-dev/security/policy/self-verify-policy-manager.hpp>
-
-// Hack: Hook directly into non-API functions.
-#include "../src/c/encoding/binary-xml-decoder.h"
-#include "../src/c/data.h"
-#include "../src/c/encoding/binary-xml-data.h"
-#include <ndn-cpp-dev/c/util/crypto.h>
-
-using namespace std;
-using namespace ndn;
-
-static double
-getNowSeconds()
-{
- struct timeval t;
- gettimeofday(&t, 0);
- return t.tv_sec + t.tv_usec / 1000000.0;
-}
-
-static bool
-verifyRsaSignature
- (uint8_t* signedPortion, size_t signedPortionLength, uint8_t* signatureBits, size_t signatureBitsLength,
- uint8_t* publicKeyDer, size_t publicKeyDerLength)
-{
- // Set signedPortionDigest to the digest of the signed portion of the wire encoding.
- uint8_t signedPortionDigest[SHA256_DIGEST_LENGTH];
- ndn_digestSha256(signedPortion, signedPortionLength, signedPortionDigest);
-
- // Verify the signedPortionDigest.
- // Use a temporary pointer since d2i updates it.
- const uint8_t *derPointer = publicKeyDer;
- RSA *rsaPublicKey = d2i_RSA_PUBKEY(NULL, &derPointer, publicKeyDerLength);
- if (!rsaPublicKey) {
- // Don't expect this to happen.
- cout << "Error decoding public key in d2i_RSAPublicKey" << endl;
- return 0;
- }
- int success = RSA_verify
- (NID_sha256, signedPortionDigest, sizeof(signedPortionDigest), signatureBits, signatureBitsLength, rsaPublicKey);
- // Free the public key before checking for success.
- RSA_free(rsaPublicKey);
-
- // RSA_verify returns 1 for a valid signature.
- return (success == 1);
-}
-
-static uint8_t DEFAULT_PUBLIC_KEY_DER[] = {
-0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
-0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xE1, 0x7D, 0x30, 0xA7, 0xD8, 0x28, 0xAB, 0x1B, 0x84, 0x0B, 0x17,
-0x54, 0x2D, 0xCA, 0xF6, 0x20, 0x7A, 0xFD, 0x22, 0x1E, 0x08, 0x6B, 0x2A, 0x60, 0xD1, 0x6C, 0xB7, 0xF5, 0x44, 0x48, 0xBA,
-0x9F, 0x3F, 0x08, 0xBC, 0xD0, 0x99, 0xDB, 0x21, 0xDD, 0x16, 0x2A, 0x77, 0x9E, 0x61, 0xAA, 0x89, 0xEE, 0xE5, 0x54, 0xD3,
-0xA4, 0x7D, 0xE2, 0x30, 0xBC, 0x7A, 0xC5, 0x90, 0xD5, 0x24, 0x06, 0x7C, 0x38, 0x98, 0xBB, 0xA6, 0xF5, 0xDC, 0x43, 0x60,
-0xB8, 0x45, 0xED, 0xA4, 0x8C, 0xBD, 0x9C, 0xF1, 0x26, 0xA7, 0x23, 0x44, 0x5F, 0x0E, 0x19, 0x52, 0xD7, 0x32, 0x5A, 0x75,
-0xFA, 0xF5, 0x56, 0x14, 0x4F, 0x9A, 0x98, 0xAF, 0x71, 0x86, 0xB0, 0x27, 0x86, 0x85, 0xB8, 0xE2, 0xC0, 0x8B, 0xEA, 0x87,
-0x17, 0x1B, 0x4D, 0xEE, 0x58, 0x5C, 0x18, 0x28, 0x29, 0x5B, 0x53, 0x95, 0xEB, 0x4A, 0x17, 0x77, 0x9F, 0x02, 0x03, 0x01,
-0x00, 0x01
-};
-
-static uint8_t DEFAULT_PRIVATE_KEY_DER[] = {
-0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b, 0x84,
-0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7, 0xf5, 0x44,
-0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa, 0x89, 0xee, 0xe5,
-0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x7a, 0xc5, 0x90, 0xd5, 0x24, 0x06, 0x7c, 0x38, 0x98, 0xbb, 0xa6, 0xf5, 0xdc,
-0x43, 0x60, 0xb8, 0x45, 0xed, 0xa4, 0x8c, 0xbd, 0x9c, 0xf1, 0x26, 0xa7, 0x23, 0x44, 0x5f, 0x0e, 0x19, 0x52, 0xd7, 0x32,
-0x5a, 0x75, 0xfa, 0xf5, 0x56, 0x14, 0x4f, 0x9a, 0x98, 0xaf, 0x71, 0x86, 0xb0, 0x27, 0x86, 0x85, 0xb8, 0xe2, 0xc0, 0x8b,
-0xea, 0x87, 0x17, 0x1b, 0x4d, 0xee, 0x58, 0x5c, 0x18, 0x28, 0x29, 0x5b, 0x53, 0x95, 0xeb, 0x4a, 0x17, 0x77, 0x9f, 0x02,
-0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x1a, 0x4b, 0xfa, 0x4f, 0xa8, 0xc2, 0xdd, 0x69, 0xa1, 0x15, 0x96, 0x0b, 0xe8,
-0x27, 0x42, 0x5a, 0xf9, 0x5c, 0xea, 0x0c, 0xac, 0x98, 0xaa, 0xe1, 0x8d, 0xaa, 0xeb, 0x2d, 0x3c, 0x60, 0x6a, 0xfb, 0x45,
-0x63, 0xa4, 0x79, 0x83, 0x67, 0xed, 0xe4, 0x15, 0xc0, 0xb0, 0x20, 0x95, 0x6d, 0x49, 0x16, 0xc6, 0x42, 0x05, 0x48, 0xaa,
-0xb1, 0xa5, 0x53, 0x65, 0xd2, 0x02, 0x99, 0x08, 0xd1, 0x84, 0xcc, 0xf0, 0xcd, 0xea, 0x61, 0xc9, 0x39, 0x02, 0x3f, 0x87,
-0x4a, 0xe5, 0xc4, 0xd2, 0x07, 0x02, 0xe1, 0x9f, 0xa0, 0x06, 0xc2, 0xcc, 0x02, 0xe7, 0xaa, 0x6c, 0x99, 0x8a, 0xf8, 0x49,
-0x00, 0xf1, 0xa2, 0x8c, 0x0c, 0x8a, 0xb9, 0x4f, 0x6d, 0x73, 0x3b, 0x2c, 0xb7, 0x9f, 0x8a, 0xa6, 0x7f, 0x9b, 0x9f, 0xb7,
-0xa1, 0xcc, 0x74, 0x2e, 0x8f, 0xb8, 0xb0, 0x26, 0x89, 0xd2, 0xe5, 0x66, 0xe8, 0x8e, 0xa1, 0x02, 0x41, 0x00, 0xfc, 0xe7,
-0x52, 0xbc, 0x4e, 0x95, 0xb6, 0x1a, 0xb4, 0x62, 0xcc, 0xd8, 0x06, 0xe1, 0xdc, 0x7a, 0xa2, 0xb6, 0x71, 0x01, 0xaa, 0x27,
-0xfc, 0x99, 0xe5, 0xf2, 0x54, 0xbb, 0xb2, 0x85, 0xe1, 0x96, 0x54, 0x2d, 0xcb, 0xba, 0x86, 0xfa, 0x80, 0xdf, 0xcf, 0x39,
-0xe6, 0x74, 0xcb, 0x22, 0xce, 0x70, 0xaa, 0x10, 0x00, 0x73, 0x1d, 0x45, 0x0a, 0x39, 0x51, 0x84, 0xf5, 0x15, 0x8f, 0x37,
-0x76, 0x91, 0x02, 0x41, 0x00, 0xe4, 0x3f, 0xf0, 0xf4, 0xde, 0x79, 0x77, 0x48, 0x9b, 0x9c, 0x28, 0x45, 0x26, 0x57, 0x3c,
-0x71, 0x40, 0x28, 0x6a, 0xa1, 0xfe, 0xc3, 0xe5, 0x37, 0xa1, 0x03, 0xf6, 0x2d, 0xbe, 0x80, 0x64, 0x72, 0x69, 0x2e, 0x9b,
-0x4d, 0xe3, 0x2e, 0x1b, 0xfe, 0xe7, 0xf9, 0x77, 0x8c, 0x18, 0x53, 0x9f, 0xe2, 0xfe, 0x00, 0xbb, 0x49, 0x20, 0x47, 0xdf,
-0x01, 0x61, 0x87, 0xd6, 0xe3, 0x44, 0xb5, 0x03, 0x2f, 0x02, 0x40, 0x54, 0xec, 0x7c, 0xbc, 0xdd, 0x0a, 0xaa, 0xde, 0xe6,
-0xc9, 0xf2, 0x8d, 0x6c, 0x2a, 0x35, 0xf6, 0x3c, 0x63, 0x55, 0x29, 0x40, 0xf1, 0x32, 0x82, 0x9f, 0x53, 0xb3, 0x9e, 0x5f,
-0xc1, 0x53, 0x52, 0x3e, 0xac, 0x2e, 0x28, 0x51, 0xa1, 0x16, 0xdb, 0x90, 0xe3, 0x99, 0x7e, 0x88, 0xa4, 0x04, 0x7c, 0x92,
-0xae, 0xd2, 0xe7, 0xd4, 0xe1, 0x55, 0x20, 0x90, 0x3e, 0x3c, 0x6a, 0x63, 0xf0, 0x34, 0xf1, 0x02, 0x41, 0x00, 0x84, 0x5a,
-0x17, 0x6c, 0xc6, 0x3c, 0x84, 0xd0, 0x93, 0x7a, 0xff, 0x56, 0xe9, 0x9e, 0x98, 0x2b, 0xcb, 0x5a, 0x24, 0x4a, 0xff, 0x21,
-0xb4, 0x9e, 0x87, 0x3d, 0x76, 0xd8, 0x9b, 0xa8, 0x73, 0x96, 0x6c, 0x2b, 0x5c, 0x5e, 0xd3, 0xa6, 0xff, 0x10, 0xd6, 0x8e,
-0xaf, 0xa5, 0x8a, 0xcd, 0xa2, 0xde, 0xcb, 0x0e, 0xbd, 0x8a, 0xef, 0xae, 0xfd, 0x3f, 0x1d, 0xc0, 0xd8, 0xf8, 0x3b, 0xf5,
-0x02, 0x7d, 0x02, 0x41, 0x00, 0x8b, 0x26, 0xd3, 0x2c, 0x7d, 0x28, 0x38, 0x92, 0xf1, 0xbf, 0x15, 0x16, 0x39, 0x50, 0xc8,
-0x6d, 0x32, 0xec, 0x28, 0xf2, 0x8b, 0xd8, 0x70, 0xc5, 0xed, 0xe1, 0x7b, 0xff, 0x2d, 0x66, 0x8c, 0x86, 0x77, 0x43, 0xeb,
-0xb6, 0xf6, 0x50, 0x66, 0xb0, 0x40, 0x24, 0x6a, 0xaf, 0x98, 0x21, 0x45, 0x30, 0x01, 0x59, 0xd0, 0xc3, 0xfc, 0x7b, 0xae,
-0x30, 0x18, 0xeb, 0x90, 0xfb, 0x17, 0xd3, 0xce, 0xb5
-};
-
-/**
- * Loop to encode a data packet nIterations times using C++.
- * @param nIterations The number of iterations.
- * @param useComplex If true, use a large name, large content and all fields. If false, use a small name, small content
- * and only required fields.
- * @param useCrypto If true, sign the data packet. If false, use a blank signature.
- * @param encoding Set this to the wire encoding.
- * @return The number of seconds for all iterations.
- */
-static double
-benchmarkEncodeDataSecondsCpp(int nIterations, bool useComplex, bool useCrypto, Block& encoding)
-{
- Name name;
- Block content;
- if (useComplex) {
- // Use a large name and content.
- name = Name("/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00");
-
- ostringstream contentStream;
- int count = 1;
- contentStream << (count++);
- while (contentStream.str().length() < 1170)
- contentStream << " " << (count++);
- content = dataBlock(Tlv::Content, contentStream.str().c_str(), contentStream.str().length());
- }
- else {
- // Use a small name and content.
- name = Name("/test");
- content = dataBlock(Tlv::Content, "abc", 3);
- }
- std::cout << "Content size: " << content.value_size() << std::endl;
-
- // Initialize the KeyChain storage in case useCrypto is true.
- KeyChainImpl<SecPublicInfoMemory, SecTpmMemory> keyChain;
-
- Name keyName("/testname/dsk-123");
-
- // Initialize the storage.
- keyChain.addPublicKey(keyName, KEY_TYPE_RSA,
- PublicKey(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)));
-
- keyChain.setKeyPairForKeyName(keyName,
- DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER),
- DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER));
-
- keyChain.addCertificateAsKeyDefault(*keyChain.selfSign(keyName));
- Name certificateName = keyChain.getDefaultCertificateName();
-
- // Set up publisherPublicKeyDigest and signatureBits in case useCrypto is false.
- uint8_t signatureBitsArray[128];
- memset(signatureBitsArray, 0, sizeof(signatureBitsArray));
- Block signatureValue = dataBlock(Tlv::SignatureValue, signatureBitsArray, sizeof(signatureBitsArray));
-
- double start = getNowSeconds();
- for (int i = 0; i < nIterations; ++i) {
- Data data(name);
- data.setContent(content);
- if (useComplex) {
- data.setFreshnessPeriod(1000000);
- }
-
- if (useCrypto)
- // This sets the signature fields.
- keyChain.sign(data);
- else {
- // Imitate real sign method to set up the signature fields, but don't actually sign.
- SignatureSha256WithRsa signature;
- signature.setKeyLocator(certificateName);
- signature.setValue(signatureValue);
- data.setSignature(signature);
- }
-
- encoding = data.wireEncode();
- }
- double finish = getNowSeconds();
-
- return finish - start;
-}
-
-static void
-onVerified(const ptr_lib::shared_ptr<Data>& data)
-{
- // Do nothing since we expect it to verify.
-}
-
-static void
-onVerifyFailed(const ptr_lib::shared_ptr<Data>& data)
-{
- cout << "Signature verification: FAILED" << endl;
-}
-
-/**
- * Loop to decode a data packet nIterations times using C++.
- * @param nIterations The number of iterations.
- * @param useCrypto If true, verify the signature. If false, don't verify.
- * @param encoding The wire encoding to decode.
- * @return The number of seconds for all iterations.
- */
-static double
-benchmarkDecodeDataSecondsCpp(int nIterations, bool useCrypto, const ConstBufferPtr &encoding)
-{
- // // Initialize the KeyChain storage in case useCrypto is true.
- // ptr_lib::shared_ptr<MemoryIdentityStorage> identityStorage(new MemoryIdentityStorage());
- // identityStorage->addKey(keyName, KEY_TYPE_RSA, Blob(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)));
-
- // ptr_lib::shared_ptr<MemoryPrivateKeyStorage> privateKeyStorage(new MemoryPrivateKeyStorage());
- // KeyChain keyChain(identityStorage, privateKeyStorage);
-
- // Name keyName("/testname/DSK-123");
-
- size_t nameSize = 0;
- double start = getNowSeconds();
- for (int i = 0; i < nIterations; ++i) {
- Data data;
- data.wireDecode(encoding);
-
- // if (useCrypto)
- // keyChain.verifyData(data, onVerified, onVerifyFailed);
- }
- double finish = getNowSeconds();
-
- return finish - start;
-}
-
-/**
- * Loop to encode a data packet nIterations times using C.
- * @param nIterations The number of iterations.
- * @param useComplex If true, use a large name, large content and all fields. If false, use a small name, small content
- * and only required fields.
- * @param useCrypto If true, sign the data packet. If false, use a blank signature.
- * @param encoding Output buffer for the wire encoding.
- * @param maxEncodingLength The size of the encoding buffer.
- * @param encodingLength Return the number of output bytes in encoding.
- * @return The number of seconds for all iterations.
- */
-static double
-benchmarkEncodeDataSecondsC
- (int nIterations, bool useComplex, bool useCrypto, uint8_t* encoding, size_t maxEncodingLength, size_t *encodingLength)
-{
- struct ndn_Blob finalBlockId;
- ndn_Blob_initialize(&finalBlockId, (uint8_t*)"\x00", 1);
-
- struct ndn_NameComponent nameComponents[20];
- struct ndn_Name name;
- ndn_Name_initialize(&name, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
- Buffer contentBlob;
- struct ndn_Blob content;
- if (useComplex) {
- // Use a large name and content.
- ndn_Name_appendString(&name, (char*)"ndn");
- ndn_Name_appendString(&name, (char*)"ucla.edu");
- ndn_Name_appendString(&name, (char*)"apps");
- ndn_Name_appendString(&name, (char*)"lwndn-test");
- ndn_Name_appendString(&name, (char*)"numbers.txt");
- ndn_Name_appendString(&name, (char*)"\xFD\x05\x05\xE8\x0C\xCE\x1D");
- ndn_Name_appendBlob(&name, &finalBlockId);
-
- ostringstream contentStream;
- int count = 1;
- contentStream << (count++);
- while (contentStream.str().length() < 1170)
- contentStream << " " << (count++);
- contentBlob = Buffer((uint8_t*)contentStream.str().c_str(), contentStream.str().length());
- }
- else {
- // Use a small name and content.
- ndn_Name_appendString(&name, (char*)"test");
- contentBlob = Buffer((uint8_t*)"abc", 3);
- }
- ndn_Blob_initialize(&content, (uint8_t*)contentBlob.buf(), contentBlob.size());
-
- struct ndn_NameComponent certificateNameComponents[20];
- struct ndn_Name certificateName;
- ndn_Name_initialize(&certificateName, certificateNameComponents, sizeof(certificateNameComponents) / sizeof(certificateNameComponents[0]));
- ndn_Name_appendString(&certificateName, (char*)"testname");
- ndn_Name_appendString(&certificateName, (char*)"KEY");
- ndn_Name_appendString(&certificateName, (char*)"DSK-123");
- ndn_Name_appendString(&certificateName, (char*)"ID-CERT");
- ndn_Name_appendString(&certificateName, (char*)"0");
-
- // Set up publisherPublicKeyDigest and signatureBits in case useCrypto is false.
- uint8_t* publicKeyDer = DEFAULT_PUBLIC_KEY_DER;
- size_t publicKeyDerLength = sizeof(DEFAULT_PUBLIC_KEY_DER);
- uint8_t publisherPublicKeyDigestArray[SHA256_DIGEST_LENGTH];
- ndn_digestSha256(publicKeyDer, publicKeyDerLength, publisherPublicKeyDigestArray);
- struct ndn_Blob publisherPublicKeyDigest;
- ndn_Blob_initialize(&publisherPublicKeyDigest, publisherPublicKeyDigestArray, sizeof(publisherPublicKeyDigestArray));
- uint8_t signatureBitsArray[128];
- memset(signatureBitsArray, 0, sizeof(signatureBitsArray));
-
- // Set up the private key now in case useCrypto is true.
- // Use a temporary pointer since d2i updates it.
- const uint8_t *privateKeyDerPointer = DEFAULT_PRIVATE_KEY_DER;
- RSA *privateKey = d2i_RSAPrivateKey(NULL, &privateKeyDerPointer, sizeof(DEFAULT_PRIVATE_KEY_DER));
- if (!privateKey) {
- // Don't expect this to happen.
- cout << "Error decoding private key DER" << endl;
- return 0;
- }
-
- double start = getNowSeconds();
- for (int i = 0; i < nIterations; ++i) {
- struct ndn_Data data;
- ndn_Data_initialize(&data, name.components, name.maxComponents, certificateName.components, certificateName.maxComponents);
-
- data.name = name;
- data.content = content;
- if (useComplex) {
- data.metaInfo.timestampMilliseconds = 1.3e+12;
- data.metaInfo.freshnessSeconds = 1000;
- ndn_NameComponent_initialize(&data.metaInfo.finalBlockID, finalBlockId.value, finalBlockId.length);
- }
-
- struct ndn_DynamicUInt8Array output;
- struct ndn_BinaryXmlEncoder encoder;
- size_t signedPortionBeginOffset, signedPortionEndOffset;
- ndn_Error error;
-
- data.signature.keyLocator.type = ndn_KeyLocatorType_KEYNAME;
- data.signature.keyLocator.keyName = certificateName;
- data.signature.keyLocator.keyNameType = (ndn_KeyNameType)-1;
- data.signature.publisherPublicKeyDigest.publisherPublicKeyDigest = publisherPublicKeyDigest;
- if (useCrypto) {
- // Encode once to get the signed portion.
- ndn_DynamicUInt8Array_initialize(&output, encoding, maxEncodingLength, 0);
- ndn_BinaryXmlEncoder_initialize(&encoder, &output);
- if ((error = ndn_encodeBinaryXmlData(&data, &signedPortionBeginOffset, &signedPortionEndOffset, &encoder))) {
- cout << "Error in ndn_encodeBinaryXmlData: " << ndn_getErrorString(error) << endl;
- return 0;
- }
-
- // Imitate MemoryPrivateKeyStorage::sign.
- uint8_t digest[SHA256_DIGEST_LENGTH];
- ndn_digestSha256(encoding + signedPortionBeginOffset, signedPortionEndOffset - signedPortionBeginOffset, digest);
- unsigned int signatureBitsLength;
- if (!RSA_sign(NID_sha256, digest, sizeof(digest), signatureBitsArray, &signatureBitsLength, privateKey)) {
- // Don't expect this to happen.
- cout << "Error in RSA_sign" << endl;
- return 0;
- }
-
- ndn_Blob_initialize(&data.signature.signature, signatureBitsArray, signatureBitsLength);
- }
- else
- // Set up the signature, but don't sign.
- ndn_Blob_initialize(&data.signature.signature, signatureBitsArray, sizeof(signatureBitsArray));
-
- // Assume the encoding buffer is big enough so we don't need to dynamically reallocate.
- ndn_DynamicUInt8Array_initialize(&output, encoding, maxEncodingLength, 0);
- ndn_BinaryXmlEncoder_initialize(&encoder, &output);
- if ((error = ndn_encodeBinaryXmlData(&data, &signedPortionBeginOffset, &signedPortionEndOffset, &encoder))) {
- cout << "Error in ndn_encodeBinaryXmlData: " << ndn_getErrorString(error) << endl;
- return 0;
- }
- *encodingLength = encoder.offset;
- }
- double finish = getNowSeconds();
-
- if (privateKey)
- RSA_free(privateKey);
-
- return finish - start;
-}
-
-/**
- * Loop to decode a data packet nIterations times using C.
- * @param nIterations The number of iterations.
- * @param useCrypto If true, verify the signature. If false, don't verify.
- * @param encoding The buffer with wire encoding to decode.
- * @param encodingLength The number of bytes in the encoding.
- * @return The number of seconds for all iterations.
- */
-static double
-benchmarkDecodeDataSecondsC(int nIterations, bool useCrypto, uint8_t* encoding, size_t encodingLength)
-{
- double start = getNowSeconds();
- for (int i = 0; i < nIterations; ++i) {
- struct ndn_NameComponent nameComponents[100];
- struct ndn_NameComponent keyNameComponents[100];
- struct ndn_Data data;
- ndn_Data_initialize
- (&data, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
- keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
-
- ndn_BinaryXmlDecoder decoder;
- ndn_BinaryXmlDecoder_initialize(&decoder, encoding, encodingLength);
- size_t signedPortionBeginOffset, signedPortionEndOffset;
- ndn_Error error;
- if ((error = ndn_decodeBinaryXmlData(&data, &signedPortionBeginOffset, &signedPortionEndOffset, &decoder))) {
- cout << "Error in ndn_decodeBinaryXmlData: " << ndn_getErrorString(error) << endl;
- return 0;
- }
-
- if (useCrypto) {
- if (!verifyRsaSignature
- (encoding + signedPortionBeginOffset, signedPortionEndOffset - signedPortionBeginOffset,
- data.signature.signature.value, data.signature.signature.length,
- DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)))
- cout << "Signature verification: FAILED" << endl;
- }
- }
- double finish = getNowSeconds();
-
- return finish - start;
-}
-
-/**
- * Call benchmarkEncodeDataSecondsCpp and benchmarkDecodeDataSecondsCpp with appropriate nInterations. Print the
- * results to cout.
- * @param useComplex See benchmarkEncodeDataSecondsCpp.
- * @param useCrypto See benchmarkEncodeDataSecondsCpp and benchmarkDecodeDataSecondsCpp.
- */
-static void
-benchmarkEncodeDecodeDataCpp(bool useComplex, bool useCrypto)
-{
- Block encoding;
- {
- int nIterations = useCrypto ? 20000 : 200000;
- double duration = benchmarkEncodeDataSecondsCpp(nIterations, useComplex, useCrypto, encoding);
- cout << "Encode " << (useComplex ? "complex" : "simple ") << " data C++: Crypto? " << (useCrypto ? "yes" : "no ")
- << ", Duration sec, Hz: " << duration << ", " << (nIterations / duration) << endl;
- }
-
- BufferPtr wire = ptr_lib::make_shared<Buffer>(encoding.wire(), encoding.size());
- {
- int nIterations = useCrypto ? 10000 : 1000000;
- double duration = benchmarkDecodeDataSecondsCpp(nIterations, useCrypto, wire);
- cout << "Decode " << (useComplex ? "complex" : "simple ") << " data C++: Crypto? " << (useCrypto ? "yes" : "no ")
- << ", Duration sec, Hz: " << duration << ", " << (nIterations / duration) << endl;
- }
-}
-
-/**
- * Call benchmarkEncodeDataSecondsC and benchmarkDecodeDataSecondsC with appropriate nInterations. Print the
- * results to cout.
- * @param useComplex See benchmarkEncodeDataSecondsC.
- * @param useCrypto See benchmarkEncodeDataSecondsC and benchmarkDecodeDataSecondsC.
- */
-static void
-benchmarkEncodeDecodeDataC(bool useComplex, bool useCrypto)
-{
- uint8_t encoding[1500];
- size_t encodingLength;
- {
- int nIterations = useCrypto ? 20000 : 10000000;
- double duration = benchmarkEncodeDataSecondsC(nIterations, useComplex, useCrypto, encoding, sizeof(encoding), &encodingLength);
- cout << "Encode " << (useComplex ? "complex" : "simple ") << " data C: Crypto? " << (useCrypto ? "yes" : "no ")
- << ", Duration sec, Hz: " << duration << ", " << (nIterations / duration) << endl;
- }
- {
- int nIterations = useCrypto ? 150000 : 15000000;
- double duration = benchmarkDecodeDataSecondsC(nIterations, useCrypto, encoding, encodingLength);
- cout << "Decode " << (useComplex ? "complex" : "simple ") << " data C: Crypto? " << (useCrypto ? "yes" : "no ")
- << ", Duration sec, Hz: " << duration << ", " << (nIterations / duration) << endl;
- }
-}
-
-int
-main(int argc, char** argv)
-{
- try {
- benchmarkEncodeDecodeDataCpp(false, false);
- benchmarkEncodeDecodeDataCpp(true, false);
- benchmarkEncodeDecodeDataCpp(false, true);
- benchmarkEncodeDecodeDataCpp(true, true);
-
- benchmarkEncodeDecodeDataC(false, false);
- benchmarkEncodeDecodeDataC(true, false);
- benchmarkEncodeDecodeDataC(false, true);
- benchmarkEncodeDecodeDataC(true, true);
- } catch (std::exception& e) {
- cout << "exception: " << e.what() << endl;
- }
- return 0;
-}
diff --git a/tests_boost/test-encode-decode-block.cpp b/tests/test-encode-decode-block.cpp
similarity index 100%
rename from tests_boost/test-encode-decode-block.cpp
rename to tests/test-encode-decode-block.cpp
diff --git a/tests_boost/test-encode-decode-certificate.cpp b/tests/test-encode-decode-certificate.cpp
similarity index 100%
rename from tests_boost/test-encode-decode-certificate.cpp
rename to tests/test-encode-decode-certificate.cpp
diff --git a/tests_boost/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
similarity index 100%
rename from tests_boost/test-encode-decode-data.cpp
rename to tests/test-encode-decode-data.cpp
diff --git a/tests_boost/test-encode-decode-forwarding-entry.cpp b/tests/test-encode-decode-forwarding-entry.cpp
similarity index 100%
rename from tests_boost/test-encode-decode-forwarding-entry.cpp
rename to tests/test-encode-decode-forwarding-entry.cpp
diff --git a/tests_boost/test-encode-decode-interest.cpp b/tests/test-encode-decode-interest.cpp
similarity index 100%
rename from tests_boost/test-encode-decode-interest.cpp
rename to tests/test-encode-decode-interest.cpp
diff --git a/tests_boost/test-faces.cpp b/tests/test-faces.cpp
similarity index 100%
rename from tests_boost/test-faces.cpp
rename to tests/test-faces.cpp
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
deleted file mode 100644
index ce04cd8..0000000
--- a/tests/test-get-async.cpp
+++ /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 <cstdlib>
-#include <sstream>
-#include <iostream>
-#include <unistd.h>
-#include <ndn-cpp-dev/face.hpp>
-
-using namespace std;
-using namespace ndn;
-using namespace ndn::func_lib;
-#if NDN_CPP_HAVE_STD_FUNCTION
-// In the std library, the placeholders are in a different namespace than boost.
-using namespace func_lib::placeholders;
-#endif
-
-class Counter
-{
-public:
- Counter() {
- callbackCount_ = 0;
- }
-
- void onData(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& data)
- {
- ++callbackCount_;
- cout << "Got data packet with name " << data->getName().toUri() << endl;
- // cout << string(reinterpret_cast<const char*>(data->getContent().value()), data->getContent().value_size()) << endl;
- }
-
- void onTimeout(const ptr_lib::shared_ptr<const Interest>& interest)
- {
- ++callbackCount_;
- cout << "Time out for interest " << interest->getName().toUri() << endl;
- }
-
- int callbackCount_;
-};
-
-int main(int argc, char** argv)
-{
- try {
- Face face;
-
- // Counter holds data used by the callbacks.
- Counter counter;
-
- Name name1("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY");
- cout << "Express name " << name1.toUri() << endl;
- // Use bind to pass the counter object to the callbacks.
- face.expressInterest(name1, bind(&Counter::onData, &counter, _1, _2), bind(&Counter::onTimeout, &counter, _1));
-
- Name name2("/ndnx/ping");
- cout << "Express name " << name2.toUri() << endl;
- face.expressInterest(name2, bind(&Counter::onData, &counter, _1, _2), bind(&Counter::onTimeout, &counter, _1));
-
- Name name3("/test/timeout");
- cout << "Express name " << name3.toUri() << endl;
- face.expressInterest(name3, bind(&Counter::onData, &counter, _1, _2), bind(&Counter::onTimeout, &counter, _1));
-
- // The main event loop.
- face.processEvents();
-
- } catch (std::exception& e) {
- cout << "exception: " << e.what() << endl;
- }
- return 0;
-}
diff --git a/tests/test-publish-async.cpp b/tests/test-publish-async.cpp
deleted file mode 100644
index b6a680f..0000000
--- a/tests/test-publish-async.cpp
+++ /dev/null
@@ -1,139 +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 <cstdlib>
-#include <sstream>
-#include <iostream>
-#include <time.h>
-#include <unistd.h>
-#include <ndn-cpp-dev/face.hpp>
-#include <ndn-cpp-dev/security/key-chain.hpp>
-
-using namespace std;
-using namespace ndn;
-
-static uint8_t DEFAULT_PUBLIC_KEY_DER[] = {
-0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
-0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xE1, 0x7D, 0x30, 0xA7, 0xD8, 0x28, 0xAB, 0x1B, 0x84, 0x0B, 0x17,
-0x54, 0x2D, 0xCA, 0xF6, 0x20, 0x7A, 0xFD, 0x22, 0x1E, 0x08, 0x6B, 0x2A, 0x60, 0xD1, 0x6C, 0xB7, 0xF5, 0x44, 0x48, 0xBA,
-0x9F, 0x3F, 0x08, 0xBC, 0xD0, 0x99, 0xDB, 0x21, 0xDD, 0x16, 0x2A, 0x77, 0x9E, 0x61, 0xAA, 0x89, 0xEE, 0xE5, 0x54, 0xD3,
-0xA4, 0x7D, 0xE2, 0x30, 0xBC, 0x7A, 0xC5, 0x90, 0xD5, 0x24, 0x06, 0x7C, 0x38, 0x98, 0xBB, 0xA6, 0xF5, 0xDC, 0x43, 0x60,
-0xB8, 0x45, 0xED, 0xA4, 0x8C, 0xBD, 0x9C, 0xF1, 0x26, 0xA7, 0x23, 0x44, 0x5F, 0x0E, 0x19, 0x52, 0xD7, 0x32, 0x5A, 0x75,
-0xFA, 0xF5, 0x56, 0x14, 0x4F, 0x9A, 0x98, 0xAF, 0x71, 0x86, 0xB0, 0x27, 0x86, 0x85, 0xB8, 0xE2, 0xC0, 0x8B, 0xEA, 0x87,
-0x17, 0x1B, 0x4D, 0xEE, 0x58, 0x5C, 0x18, 0x28, 0x29, 0x5B, 0x53, 0x95, 0xEB, 0x4A, 0x17, 0x77, 0x9F, 0x02, 0x03, 0x01,
-0x00, 01
-};
-
-static uint8_t DEFAULT_PRIVATE_KEY_DER[] = {
-0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b, 0x84,
-0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7, 0xf5, 0x44,
-0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa, 0x89, 0xee, 0xe5,
-0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x7a, 0xc5, 0x90, 0xd5, 0x24, 0x06, 0x7c, 0x38, 0x98, 0xbb, 0xa6, 0xf5, 0xdc,
-0x43, 0x60, 0xb8, 0x45, 0xed, 0xa4, 0x8c, 0xbd, 0x9c, 0xf1, 0x26, 0xa7, 0x23, 0x44, 0x5f, 0x0e, 0x19, 0x52, 0xd7, 0x32,
-0x5a, 0x75, 0xfa, 0xf5, 0x56, 0x14, 0x4f, 0x9a, 0x98, 0xaf, 0x71, 0x86, 0xb0, 0x27, 0x86, 0x85, 0xb8, 0xe2, 0xc0, 0x8b,
-0xea, 0x87, 0x17, 0x1b, 0x4d, 0xee, 0x58, 0x5c, 0x18, 0x28, 0x29, 0x5b, 0x53, 0x95, 0xeb, 0x4a, 0x17, 0x77, 0x9f, 0x02,
-0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x1a, 0x4b, 0xfa, 0x4f, 0xa8, 0xc2, 0xdd, 0x69, 0xa1, 0x15, 0x96, 0x0b, 0xe8,
-0x27, 0x42, 0x5a, 0xf9, 0x5c, 0xea, 0x0c, 0xac, 0x98, 0xaa, 0xe1, 0x8d, 0xaa, 0xeb, 0x2d, 0x3c, 0x60, 0x6a, 0xfb, 0x45,
-0x63, 0xa4, 0x79, 0x83, 0x67, 0xed, 0xe4, 0x15, 0xc0, 0xb0, 0x20, 0x95, 0x6d, 0x49, 0x16, 0xc6, 0x42, 0x05, 0x48, 0xaa,
-0xb1, 0xa5, 0x53, 0x65, 0xd2, 0x02, 0x99, 0x08, 0xd1, 0x84, 0xcc, 0xf0, 0xcd, 0xea, 0x61, 0xc9, 0x39, 0x02, 0x3f, 0x87,
-0x4a, 0xe5, 0xc4, 0xd2, 0x07, 0x02, 0xe1, 0x9f, 0xa0, 0x06, 0xc2, 0xcc, 0x02, 0xe7, 0xaa, 0x6c, 0x99, 0x8a, 0xf8, 0x49,
-0x00, 0xf1, 0xa2, 0x8c, 0x0c, 0x8a, 0xb9, 0x4f, 0x6d, 0x73, 0x3b, 0x2c, 0xb7, 0x9f, 0x8a, 0xa6, 0x7f, 0x9b, 0x9f, 0xb7,
-0xa1, 0xcc, 0x74, 0x2e, 0x8f, 0xb8, 0xb0, 0x26, 0x89, 0xd2, 0xe5, 0x66, 0xe8, 0x8e, 0xa1, 0x02, 0x41, 0x00, 0xfc, 0xe7,
-0x52, 0xbc, 0x4e, 0x95, 0xb6, 0x1a, 0xb4, 0x62, 0xcc, 0xd8, 0x06, 0xe1, 0xdc, 0x7a, 0xa2, 0xb6, 0x71, 0x01, 0xaa, 0x27,
-0xfc, 0x99, 0xe5, 0xf2, 0x54, 0xbb, 0xb2, 0x85, 0xe1, 0x96, 0x54, 0x2d, 0xcb, 0xba, 0x86, 0xfa, 0x80, 0xdf, 0xcf, 0x39,
-0xe6, 0x74, 0xcb, 0x22, 0xce, 0x70, 0xaa, 0x10, 0x00, 0x73, 0x1d, 0x45, 0x0a, 0x39, 0x51, 0x84, 0xf5, 0x15, 0x8f, 0x37,
-0x76, 0x91, 0x02, 0x41, 0x00, 0xe4, 0x3f, 0xf0, 0xf4, 0xde, 0x79, 0x77, 0x48, 0x9b, 0x9c, 0x28, 0x45, 0x26, 0x57, 0x3c,
-0x71, 0x40, 0x28, 0x6a, 0xa1, 0xfe, 0xc3, 0xe5, 0x37, 0xa1, 0x03, 0xf6, 0x2d, 0xbe, 0x80, 0x64, 0x72, 0x69, 0x2e, 0x9b,
-0x4d, 0xe3, 0x2e, 0x1b, 0xfe, 0xe7, 0xf9, 0x77, 0x8c, 0x18, 0x53, 0x9f, 0xe2, 0xfe, 0x00, 0xbb, 0x49, 0x20, 0x47, 0xdf,
-0x01, 0x61, 0x87, 0xd6, 0xe3, 0x44, 0xb5, 0x03, 0x2f, 0x02, 0x40, 0x54, 0xec, 0x7c, 0xbc, 0xdd, 0x0a, 0xaa, 0xde, 0xe6,
-0xc9, 0xf2, 0x8d, 0x6c, 0x2a, 0x35, 0xf6, 0x3c, 0x63, 0x55, 0x29, 0x40, 0xf1, 0x32, 0x82, 0x9f, 0x53, 0xb3, 0x9e, 0x5f,
-0xc1, 0x53, 0x52, 0x3e, 0xac, 0x2e, 0x28, 0x51, 0xa1, 0x16, 0xdb, 0x90, 0xe3, 0x99, 0x7e, 0x88, 0xa4, 0x04, 0x7c, 0x92,
-0xae, 0xd2, 0xe7, 0xd4, 0xe1, 0x55, 0x20, 0x90, 0x3e, 0x3c, 0x6a, 0x63, 0xf0, 0x34, 0xf1, 0x02, 0x41, 0x00, 0x84, 0x5a,
-0x17, 0x6c, 0xc6, 0x3c, 0x84, 0xd0, 0x93, 0x7a, 0xff, 0x56, 0xe9, 0x9e, 0x98, 0x2b, 0xcb, 0x5a, 0x24, 0x4a, 0xff, 0x21,
-0xb4, 0x9e, 0x87, 0x3d, 0x76, 0xd8, 0x9b, 0xa8, 0x73, 0x96, 0x6c, 0x2b, 0x5c, 0x5e, 0xd3, 0xa6, 0xff, 0x10, 0xd6, 0x8e,
-0xaf, 0xa5, 0x8a, 0xcd, 0xa2, 0xde, 0xcb, 0x0e, 0xbd, 0x8a, 0xef, 0xae, 0xfd, 0x3f, 0x1d, 0xc0, 0xd8, 0xf8, 0x3b, 0xf5,
-0x02, 0x7d, 0x02, 0x41, 0x00, 0x8b, 0x26, 0xd3, 0x2c, 0x7d, 0x28, 0x38, 0x92, 0xf1, 0xbf, 0x15, 0x16, 0x39, 0x50, 0xc8,
-0x6d, 0x32, 0xec, 0x28, 0xf2, 0x8b, 0xd8, 0x70, 0xc5, 0xed, 0xe1, 0x7b, 0xff, 0x2d, 0x66, 0x8c, 0x86, 0x77, 0x43, 0xeb,
-0xb6, 0xf6, 0x50, 0x66, 0xb0, 0x40, 0x24, 0x6a, 0xaf, 0x98, 0x21, 0x45, 0x30, 0x01, 0x59, 0xd0, 0xc3, 0xfc, 0x7b, 0xae,
-0x30, 0x18, 0xeb, 0x90, 0xfb, 0x17, 0xd3, 0xce, 0xb5
-};
-
-class Echo {
-public:
- Echo(KeyChainImpl<SecPublicInfoMemory, SecTpmMemory> &keyChain, Face &face)
- : keyChain_(keyChain)
- , face_(face)
- , responseCount_(0)
- {
- }
-
- // onInterest.
- void operator()
- (const ptr_lib::shared_ptr<const Name>& prefix, const ptr_lib::shared_ptr<const Interest>& interest)
- {
- ++responseCount_;
-
- // Make and sign a Data packet.
- Data data(interest->getName());
- string content(string("Echo ") + interest->getName().toUri());
- data.setFreshnessPeriod(1000);
- data.setContent((const uint8_t *)&content[0], content.size());
-
- keyChain_.sign(data);
-
- // Put data on wire
- face_.put(data);
-
- // Unregister prefix to ensure that the processing thread finishes after Data
- // packet is send out to the forwarder
- face_.unsetInterestFilter(id_);
- }
-
- // onRegisterFailed.
- void operator()(const ptr_lib::shared_ptr<const Name>& prefix)
- {
- ++responseCount_;
- cout << "Register failed for prefix " << prefix->toUri() << endl;
- }
-
- KeyChainImpl<SecPublicInfoMemory, SecTpmMemory> &keyChain_;
- Face &face_;
- int responseCount_;
-
- const RegisteredPrefixId *id_;
-};
-
-int main(int argc, char** argv)
-{
- try {
- Face face;
-
- KeyChainImpl<SecPublicInfoMemory, SecTpmMemory> keyChain;
-
- Name keyName("/testname/dsk-123");
-
- // Initialize the storage.
- keyChain.addPublicKey(keyName, KEY_TYPE_RSA,
- PublicKey(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)));
-
- keyChain.setKeyPairForKeyName(keyName,
- DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER),
- DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER));
-
- keyChain.addCertificateAsKeyDefault(*keyChain.selfSign(keyName));
-
-
- Echo echo(keyChain, face);
- Name prefix("/testecho");
- cout << "Register prefix " << prefix.toUri() << endl;
- echo.id_ = face.setInterestFilter(prefix, func_lib::ref(echo), func_lib::ref(echo));
-
- face.processEvents();
- } catch (std::exception& e) {
- cout << "exception: " << e.what() << endl;
- }
- return 0;
-}
diff --git a/tests_boost/test-sec-tpm-file.cpp b/tests/test-sec-tpm-file.cpp
similarity index 100%
rename from tests_boost/test-sec-tpm-file.cpp
rename to tests/test-sec-tpm-file.cpp
diff --git a/tests/wscript b/tests/wscript
index bafda9c..73f722a 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -3,10 +3,10 @@
top = '..'
def build(bld):
- for app in bld.path.ant_glob('*.cpp'):
- bld(features=['cxx', 'cxxprogram'],
- target = '%s' % (str(app.change_ext('','.cpp'))),
- source = app,
- use = 'ndn-cpp-dev',
- includes = "../include",
- )
+ unittests = bld.program (
+ target="unit-tests",
+ features = "cxx cxxprogram",
+ source = bld.path.ant_glob(['**/*.cpp']),
+ use = 'lib-objects',
+ install_prefix = None,
+ )
diff --git a/tests_boost/Makefile.am b/tests_boost/Makefile.am
deleted file mode 100644
index 2e80613..0000000
--- a/tests_boost/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-
-noinst_PROGRAMS=unit-tests
-
-# for i in `find . -name '*.cpp'`; do echo " $i \\"; done
-unit_tests_SOURCES = \
- main.cpp \
- test-encode-decode-certificate.cpp \
- test-encode-decode-data.cpp \
- test-encode-decode-interest.cpp \
- test-encode-decode-forwarding-entry.cpp \
- test-encode-decode-block.cpp \
- test-sec-tpm-file.cpp \
- test-faces.cpp
-
-unit_tests_LDADD = ../libndn-cpp-dev.la @BOOST_SYSTEM_LIB@ @BOOST_UNIT_TEST_FRAMEWORK_LIB@ @OPENSSL_LIBS@ @CRYPTOPP_LIBS@ @OSX_SECURITY_LIBS@
diff --git a/tools/wscript b/tools/wscript
index bafda9c..f0114cf 100644
--- a/tools/wscript
+++ b/tools/wscript
@@ -7,6 +7,5 @@
bld(features=['cxx', 'cxxprogram'],
target = '%s' % (str(app.change_ext('','.cpp'))),
source = app,
- use = 'ndn-cpp-dev',
- includes = "../include",
+ use = 'ndn-cpp-dev-stlib',
)
diff --git a/waf b/waf
index f916f71..78a44f3 100755
--- a/waf
+++ b/waf
Binary files differ
diff --git a/wscript b/wscript
index b381eaa..1cf54d7 100644
--- a/wscript
+++ b/wscript
@@ -72,6 +72,10 @@
if Utils.unversioned_sys_platform () == "darwin":
conf.check_cxx(framework_name='CoreFoundation', uselib_store='OSX_COREFOUNDATION', mandatory=True)
+ conf.check_cxx(framework_name='CoreServices', uselib_store='OSX_CORESERVICES', mandatory=True)
+ conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY', define_name='HAVE_SECURITY',
+ use="OSX_COREFOUNDATION", mandatory=True)
+ conf.define('HAVE_OSX_SECURITY', 1)
conf.define ("PACKAGE_BUGREPORT", "ndn-lib@lists.cs.ucla.edu")
conf.define ("PACKAGE_NAME", NAME)
@@ -107,35 +111,48 @@
conf.env['USE_SYSTEM_BOOST'] = True
conf.define('USE_SYSTEM_BOOST', 1)
- conf.write_config_header('include/ndn-cpp/ndn-cpp-config.h', define_prefix='NDN_CPP_')
+ conf.write_config_header('include/ndn-cpp-dev/ndn-cpp-config.h', define_prefix='NDN_CPP_')
def build (bld):
libndn_cpp = bld (
- target="ndn-cpp-dev",
- vnum = "0.3.0",
- features=['cxx', 'cxxshlib', 'cxxstlib'],
+ target="lib-objects",
+ name = "lib-objects",
+ features=['cxx'],
source = bld.path.ant_glob(['src/**/*.cpp',
'new/**/*.cpp']),
use = 'BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3',
- includes = ". include",
+ includes = "include",
+ export_includes = "include",
)
if Utils.unversioned_sys_platform () == "darwin":
libndn_cpp.mac_app = True
- libndn_cpp.use += " OSX_COREFOUNDATION"
+ libndn_cpp.use += " OSX_COREFOUNDATION OSX_SECURITY"
+ shlib = bld(features = 'cxx cxxshlib',
+ vnum = "0.3.0",
+ target = "ndn-cpp-dev",
+ use = "lib-objects",
+ name = "ndn-cpp-dev-shlib",
+ )
+
+ stlib = bld(features = 'cxx cxxstlib',
+ target = "ndn-cpp-dev",
+ use = "lib-objects",
+ name = "ndn-cpp-dev-stlib",
+ )
+
+ bld (features = "subst",
+ source = "libndn-cpp-dev.pc.in",
+ target = "libndn-cpp-dev.pc",
+ install_path = "${LIBDIR}/pkgconfig",
+ )
+
# Unit tests
if bld.env['WITH_TESTS']:
- unittests = bld.program (
- target="unit-tests",
- features = "cxx cxxprogram",
- source = bld.path.ant_glob(['tests_boost/*.cpp']),
- use = 'ndn-cpp-dev',
- includes = ".",
- install_prefix = None,
- )
+ bld.recurse('tests')
- bld.recurse("tools examples tests")
+ bld.recurse("tools examples")
headers = bld.path.ant_glob(['src/**/*.hpp',
'src/**/*.h'])