make: Global change: Move all public headers to include folder. Change source to including public headers using #include <ndn-cpp/*>. Split some header files to minimize exposing C .h files.
diff --git a/ndn-cpp/c/common.h b/ndn-cpp/c/common.h
deleted file mode 100644
index 48e2ec2..0000000
--- a/ndn-cpp/c/common.h
+++ /dev/null
@@ -1,14 +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/ndn-cpp-config.h>
-#include <stdint.h>
-#include <stddef.h>
-
-#endif
diff --git a/ndn-cpp/c/data.h b/ndn-cpp/c/data.h
index e085f79..8d14e05 100644
--- a/ndn-cpp/c/data.h
+++ b/ndn-cpp/c/data.h
@@ -7,6 +7,7 @@
#ifndef NDN_DATA_H
#define NDN_DATA_H
+#include <ndn-cpp/c/data-types.h>
#include "name.h"
#include "publisher-public-key-digest.h"
#include "key.h"
@@ -41,15 +42,6 @@
ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}
-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;
-
/**
* An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
*/
diff --git a/ndn-cpp/c/encoding/binary-xml-decoder.h b/ndn-cpp/c/encoding/binary-xml-decoder.h
index 3e16497..38fd450 100644
--- a/ndn-cpp/c/encoding/binary-xml-decoder.h
+++ b/ndn-cpp/c/encoding/binary-xml-decoder.h
@@ -7,7 +7,7 @@
#ifndef NDN_BINARYXMLDECODER_H
#define NDN_BINARYXMLDECODER_H
-#include "../common.h"
+#include <ndn-cpp/c/common.h>
#include "../errors.h"
#include "../util/blob.h"
diff --git a/ndn-cpp/c/encoding/binary-xml-element-reader.h b/ndn-cpp/c/encoding/binary-xml-element-reader.h
index c2b3777..89f8c8d 100644
--- a/ndn-cpp/c/encoding/binary-xml-element-reader.h
+++ b/ndn-cpp/c/encoding/binary-xml-element-reader.h
@@ -4,9 +4,10 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NDN_BINARYXMLELEMENTREADER_H
-#define NDN_BINARYXMLELEMENTREADER_H
+#ifndef NDN_BINARY_XML_ELEMENT_READER_H
+#define NDN_BINARY_XML_ELEMENT_READER_H
+#include <ndn-cpp/c/encoding/element-listener.h>
#include "../errors.h"
#include "binary-xml-structure-decoder.h"
#include "../util/dynamic-uint8-array.h"
@@ -14,25 +15,6 @@
#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;
-}
/**
* A BinaryXmlElementReader lets you call ndn_BinaryXmlElementReader_onReceivedData multiple times which uses an
diff --git a/ndn-cpp/c/encoding/binary-xml-key.h b/ndn-cpp/c/encoding/binary-xml-key.h
index 6aecd20..391fa72 100644
--- a/ndn-cpp/c/encoding/binary-xml-key.h
+++ b/ndn-cpp/c/encoding/binary-xml-key.h
@@ -7,8 +7,8 @@
#ifndef NDN_BINARYXMLKEY_H
#define NDN_BINARYXMLKEY_H
-#include "../errors.h"
#include "../key.h"
+#include "../errors.h"
#include "binary-xml-encoder.h"
#include "binary-xml-decoder.h"
diff --git a/ndn-cpp/c/encoding/binary-xml-structure-decoder.h b/ndn-cpp/c/encoding/binary-xml-structure-decoder.h
index 63420d2..54a92d5 100644
--- a/ndn-cpp/c/encoding/binary-xml-structure-decoder.h
+++ b/ndn-cpp/c/encoding/binary-xml-structure-decoder.h
@@ -7,7 +7,7 @@
#ifndef NDN_BINARYXMLSTRUCTUREDECODER_H
#define NDN_BINARYXMLSTRUCTUREDECODER_H
-#include "../common.h"
+#include <ndn-cpp/c/common.h>
#include "../errors.h"
#ifdef __cplusplus
diff --git a/ndn-cpp/c/forwarding-entry.h b/ndn-cpp/c/forwarding-entry.h
index 001fabc..48bbf5e 100644
--- a/ndn-cpp/c/forwarding-entry.h
+++ b/ndn-cpp/c/forwarding-entry.h
@@ -7,10 +7,10 @@
#ifndef NDN_FORWARDING_ENTRY_H
#define NDN_FORWARDING_ENTRY_H
-#include "common.h"
+#include <ndn-cpp/c/common.h>
+#include <ndn-cpp/c/forwarding-flags.h>
#include "name.h"
#include "publisher-public-key-digest.h"
-#include "forwarding-flags.h"
#ifdef __cplusplus
extern "C" {
diff --git a/ndn-cpp/c/forwarding-flags.c b/ndn-cpp/c/forwarding-flags.c
index e7477ed..4a7510d 100644
--- a/ndn-cpp/c/forwarding-flags.c
+++ b/ndn-cpp/c/forwarding-flags.c
@@ -5,7 +5,6 @@
*/
#include "forwarding-entry.h"
-#include "forwarding-flags.h"
void ndn_ForwardingFlags_initialize(struct ndn_ForwardingFlags *self)
{
diff --git a/ndn-cpp/c/forwarding-flags.h b/ndn-cpp/c/forwarding-flags.h
deleted file mode 100644
index ba6f6b5..0000000
--- a/ndn-cpp/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/ndn-cpp/c/interest.h b/ndn-cpp/c/interest.h
index 69428ac..12ca38e 100644
--- a/ndn-cpp/c/interest.h
+++ b/ndn-cpp/c/interest.h
@@ -7,6 +7,7 @@
#ifndef NDN_INTEREST_H
#define NDN_INTEREST_H
+#include <ndn-cpp/c/interest-types.h>
#include "name.h"
#include "publisher-public-key-digest.h"
@@ -14,11 +15,6 @@
extern "C" {
#endif
-typedef enum {
- ndn_Exclude_COMPONENT = 0,
- ndn_Exclude_ANY = 1
-} ndn_ExcludeType;
-
/**
* An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value.
*/
diff --git a/ndn-cpp/c/key.h b/ndn-cpp/c/key.h
index a933489..b7f8751 100644
--- a/ndn-cpp/c/key.h
+++ b/ndn-cpp/c/key.h
@@ -7,25 +7,13 @@
#ifndef NDN_KEY_H
#define NDN_KEY_H
+#include <ndn-cpp/c/key-types.h>
#include "name.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;
-
/**
* An ndn_KeyLocator holds the type of key locator and related data.
*/
diff --git a/ndn-cpp/c/name.h b/ndn-cpp/c/name.h
index d6badc1..78fcc9c 100644
--- a/ndn-cpp/c/name.h
+++ b/ndn-cpp/c/name.h
@@ -7,6 +7,7 @@
#ifndef NDN_NAME_H
#define NDN_NAME_H
+#include <ndn-cpp/c/common.h>
#include "errors.h"
#include "util/blob.h"
diff --git a/ndn-cpp/c/publisher-public-key-digest.h b/ndn-cpp/c/publisher-public-key-digest.h
index 85891bf..95faf1d 100644
--- a/ndn-cpp/c/publisher-public-key-digest.h
+++ b/ndn-cpp/c/publisher-public-key-digest.h
@@ -7,7 +7,7 @@
#ifndef NDN_PUBLISHERPUBLICKEYDIGEST_H
#define NDN_PUBLISHERPUBLICKEYDIGEST_H
-#include "common.h"
+#include <ndn-cpp/c/common.h>
#include "util/blob.h"
#ifdef __cplusplus
diff --git a/ndn-cpp/c/transport/socket-transport.h b/ndn-cpp/c/transport/socket-transport.h
index b0a0979..85e297e 100644
--- a/ndn-cpp/c/transport/socket-transport.h
+++ b/ndn-cpp/c/transport/socket-transport.h
@@ -8,7 +8,7 @@
#define NDN_SOCKETTRANSPORT_H
#include <sys/socket.h>
-#include "../common.h"
+#include <ndn-cpp/c/common.h>
#include "../errors.h"
#ifdef __cplusplus
diff --git a/ndn-cpp/c/util/blob.h b/ndn-cpp/c/util/blob.h
index 06dbce1..18bcd03 100644
--- a/ndn-cpp/c/util/blob.h
+++ b/ndn-cpp/c/util/blob.h
@@ -7,6 +7,8 @@
#ifndef NDN_BLOB_H
#define NDN_BLOB_H
+#include <ndn-cpp/c/common.h>
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/ndn-cpp/c/util/crypto.h b/ndn-cpp/c/util/crypto.h
index 5bec549..586108b 100644
--- a/ndn-cpp/c/util/crypto.h
+++ b/ndn-cpp/c/util/crypto.h
@@ -9,7 +9,7 @@
#include <openssl/ssl.h>
#include <openssl/rsa.h>
-#include "../common.h"
+#include <ndn-cpp/c/common.h>
#ifdef __cplusplus
extern "C" {
diff --git a/ndn-cpp/c/util/ndn_memory.h b/ndn-cpp/c/util/ndn_memory.h
index 9d23e2d..bdf6341 100644
--- a/ndn-cpp/c/util/ndn_memory.h
+++ b/ndn-cpp/c/util/ndn_memory.h
@@ -11,7 +11,7 @@
#ifndef NDN_MEMORY_H
#define NDN_MEMORY_H
-#include "../common.h"
+#include <ndn-cpp/c/common.h>
#ifdef __cplusplus
extern "C" {
diff --git a/ndn-cpp/common.cpp b/ndn-cpp/common.cpp
index fcebfba..ff420f9 100644
--- a/ndn-cpp/common.cpp
+++ b/ndn-cpp/common.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,7 +6,7 @@
*/
#include <sstream>
-#include "common.hpp"
+#include <ndn-cpp/common.hpp>
using namespace std;
diff --git a/ndn-cpp/common.hpp b/ndn-cpp/common.hpp
deleted file mode 100644
index b9b02c7..0000000
--- a/ndn-cpp/common.hpp
+++ /dev/null
@@ -1,65 +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_HPP
-#define NDN_COMMON_HPP
-
-#include <vector>
-// common.h includes ndn-cpp-config.h.
-#include "c/common.h"
-
-// 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; }
-#elif NDN_CPP_HAVE_BOOST_SHARED_PTR
-#include <boost/shared_ptr.hpp>
-#include <boost/make_shared.hpp>
-namespace ndn { namespace ptr_lib = boost; }
-#else
-// Use the boost header files in this distribution that were extracted with:
-// cd <INCLUDE DIRECTORY WITH boost SUBDIRECTORY>
-// dist/bin/bcp --namespace=ndnboost shared_ptr make_shared weak_ptr function bind <NDN-CPP ROOT>/include
-// cd <NDN-CPP ROOT>/include
-// mv boost ndnboost
-// cd ndnboost
-// (unset LANG; find . -type f -exec sed -i '' 's/\<boost\//\<ndnboost\//g' {} +)
-// (unset LANG; find . -type f -exec sed -i '' 's/\"boost\//\"ndnboost\//g' {} +)
-#include <ndnboost/shared_ptr.hpp>
-#include <ndnboost/make_shared.hpp>
-namespace ndn { namespace ptr_lib = ndnboost; }
-#endif
-
-// Depending on where ./configure found function, define the func_lib namespace.
-// We always use ndn::func_lib.
-#if NDN_CPP_HAVE_STD_FUNCTION
-#include <functional>
-namespace ndn { namespace func_lib = std; }
-#elif NDN_CPP_HAVE_BOOST_FUNCTION
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-namespace ndn { namespace func_lib = boost; }
-#else
-// 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 {
-
-/**
- * Return the hex representation of the bytes in array.
- * @param array The array of bytes.
- * @return Hex string.
- */
-std::string
-toHex(const std::vector<uint8_t>& array);
-
-}
-
-#endif
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index 98ffde0..6b2f570 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -1,12 +1,14 @@
+/* -*- 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 "common.hpp"
-#include "data.hpp"
-#include "sha256-with-rsa-signature.hpp"
+#include <ndn-cpp/common.hpp>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include "c/data.h"
using namespace std;
diff --git a/ndn-cpp/data.hpp b/ndn-cpp/data.hpp
deleted file mode 100644
index f8cc893..0000000
--- a/ndn-cpp/data.hpp
+++ /dev/null
@@ -1,302 +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_HPP
-#define NDN_DATA_HPP
-
-#include "common.hpp"
-#include "name.hpp"
-#include "util/signed-blob.hpp"
-#include "c/data.h"
-
-namespace ndn {
-
-/**
- * A Signature is an abstract base class providing methods to work with the signature information in a Data packet.
- * You must create an object of a subclass, for example Sha256WithRsaSignature.
- */
-class Signature {
-public:
- /**
- * Return a pointer to a new Signature which is a copy of this signature.
- * This is pure virtual, the subclass must implement it.
- */
- virtual ptr_lib::shared_ptr<Signature>
- clone() const = 0;
-
- /**
- * The virtual destructor.
- */
- virtual
- ~Signature();
-
- /**
- * Set the signatureStruct to point to the values in this signature object, without copying any memory.
- * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
- * This is pure virtual, the subclass must implement it.
- * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
- */
- virtual void
- get(struct ndn_Signature& signatureStruct) const = 0;
-
- /**
- * Clear this signature, and set the values by copying from the ndn_Signature struct.
- * This is pure virtual, the subclass must implement it.
- * @param signatureStruct a C ndn_Signature struct
- */
- virtual void
- set(const struct ndn_Signature& signatureStruct) = 0;
-};
-
-/**
- * An MetaInfo holds the meta info which is signed inside the data packet.
- */
-class MetaInfo {
-public:
- MetaInfo()
- {
- type_ = ndn_ContentType_DATA;
- freshnessSeconds_ = -1;
- }
-
- /**
- * Set the metaInfoStruct to point to the values in this meta info object, without copying any memory.
- * WARNING: The resulting pointers in metaInfoStruct are invalid after a further use of this object which could reallocate memory.
- * @param metaInfoStruct a C ndn_MetaInfo struct where the name components array is already allocated.
- */
- void
- get(struct ndn_MetaInfo& metaInfoStruct) const;
-
- /**
- * Clear this meta info, and set the values by copying from the ndn_MetaInfo struct.
- * @param metaInfoStruct a C ndn_MetaInfo struct
- */
- void
- set(const struct ndn_MetaInfo& metaInfoStruct);
-
- double
- getTimestampMilliseconds() const { return timestampMilliseconds_; }
-
- ndn_ContentType
- getType() const { return type_; }
-
- int
- getFreshnessSeconds() const { return freshnessSeconds_; }
-
- const Name::Component&
- getFinalBlockID() const { return finalBlockID_; }
-
- void
- setTimestampMilliseconds(double timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
-
- void
- setType(ndn_ContentType type) { type_ = type; }
-
- void
- setFreshnessSeconds(int freshnessSeconds) { freshnessSeconds_ = freshnessSeconds; }
-
- void
- setFinalBlockID(const std::vector<uint8_t>& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); }
-
- void
- setFinalBlockID(const uint8_t* finalBlockID, size_t finalBlockIdLength)
- {
- finalBlockID_ = Name::Component(finalBlockID, finalBlockIdLength);
- }
-
-private:
- double 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 */
- Name::Component finalBlockID_; /** size 0 for none */
-};
-
-class Data {
-public:
- /**
- * Create a new Data object with default values and where the signature is a blank Sha256WithRsaSignature.
- */
- Data();
-
- /**
- * Create a new Data object with the given name and default values and where the signature is a blank Sha256WithRsaSignature.
- * @param name A reference to the name which is copied.
- */
- Data(const Name& name);
-
- /**
- * Encode this Data for a particular wire format. Also, set the wireEncoding field to the encoded result.
- * This is not const because it updates the wireEncoding.
- * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
- * @return The encoded byte array.
- */
- SignedBlob
- wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
-
- /**
- * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input.
- * @param input The input byte array to be decoded.
- * @param inputLength The length of input.
- * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat().
- */
- void
- wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
-
- /**
- * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input.
- * @param input The input byte array to be decoded.
- * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat().
- */
- void
- wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireDecode(&input[0], input.size(), wireFormat);
- }
-
- /**
- * Set the dataStruct to point to the values in this interest, without copying any memory.
- * WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory.
- * @param dataStruct a C ndn_Data struct where the name components array is already allocated.
- */
- void
- get(struct ndn_Data& dataStruct) const;
-
- /**
- * Clear this data object, and set the values by copying from the ndn_Data struct.
- * @param dataStruct a C ndn_Data struct
- */
- void
- set(const struct ndn_Data& dataStruct);
-
- const Signature*
- getSignature() const { return signature_.get(); }
-
- Signature*
- getSignature()
- {
- // TODO: Should add an OnChanged listener instead of always calling onChanged.
- onChanged();
- return signature_.get();
- }
-
- const Name&
- getName() const { return name_; }
-
- Name&
- getName()
- {
- // TODO: Should add an OnChanged listener instead of always calling onChanged.
- onChanged();
- return name_;
- }
-
- const MetaInfo&
- getMetaInfo() const { return metaInfo_; }
-
- MetaInfo&
- getMetaInfo()
- {
- // TODO: Should add an OnChanged listener instead of always calling onChanged.
- onChanged();
- return metaInfo_;
- }
-
- const Blob&
- getContent() const { return content_; }
-
- /**
- * Return a pointer to the wireEncoding. It may be null.
- */
- const SignedBlob&
- getWireEncoding() const { return wireEncoding_; }
-
- /**
- * Set the signature to a copy of the given signature.
- * @param signature The signature object which is cloned.
- */
- void
- setSignature(const Signature& signature)
- {
- signature_ = signature.clone();
- onChanged();
- }
-
- /**
- * Set name to a copy of the given Name.
- * @param name The Name which is copied.
- */
- void
- setName(const Name& name)
- {
- name_ = name;
- onChanged();
- }
-
- /**
- * Set metaInfo to a copy of the given MetaInfo.
- * @param metaInfo The MetaInfo which is copied.
- */
- void
- setMetainfo(const MetaInfo& metaInfo)
- {
- metaInfo_ = metaInfo;
- onChanged();
- }
-
- /**
- * Set the content to a copy of the data in the vector.
- * @param content A vector whose contents are copied.
- */
- void
- setContent(const std::vector<uint8_t>& content)
- {
- content_ = content;
- onChanged();
- }
-
- void
- setContent(const uint8_t* content, size_t contentLength)
- {
- content_ = Blob(content, contentLength);
- onChanged();
- }
-
- /**
- * Set content to point to an existing byte array. IMPORTANT: After calling this,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param content A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- */
- void
- setContent(const ptr_lib::shared_ptr<std::vector<uint8_t> > &content)
- {
- content_ = content;
- onChanged();
- }
-
- void
- setContent(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &content)
- {
- content_ = content;
- onChanged();
- }
-
-private:
- /**
- * Clear the wire encoding.
- */
- void
- onChanged();
-
- ptr_lib::shared_ptr<Signature> signature_;
- Name name_;
- MetaInfo metaInfo_;
- Blob content_;
- SignedBlob wireEncoding_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/encoding/binary-xml-decoder.hpp b/ndn-cpp/encoding/binary-xml-decoder.hpp
index f75d4f0..3e371c3 100644
--- a/ndn-cpp/encoding/binary-xml-decoder.hpp
+++ b/ndn-cpp/encoding/binary-xml-decoder.hpp
@@ -1,3 +1,4 @@
+/* -*- 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>
diff --git a/ndn-cpp/encoding/binary-xml-element-reader.hpp b/ndn-cpp/encoding/binary-xml-element-reader.hpp
deleted file mode 100644
index f353e97..0000000
--- a/ndn-cpp/encoding/binary-xml-element-reader.hpp
+++ /dev/null
@@ -1,47 +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_BINARYXMLELEMENTREADER_HPP
-#define NDN_BINARYXMLELEMENTREADER_HPP
-
-#include "../c/encoding/binary-xml-element-reader.h"
-
-namespace ndn {
-
-/**
- * An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElement function which wraps
- * the onReceivedElement used by the ndn_ElementListener struct. You must extend this class to override onReceivedElement.
- */
-class ElementListener : public ndn_ElementListener {
-public:
- ElementListener()
- {
- ndn_ElementListener_initialize(this, staticOnReceivedElement);
- }
-
- /**
- * This is called when an entire binary XML element is received. You must extend this class to override this method.
- * @param element pointer to the binary XML element. This buffer is only valid during this call. If you need the data
- * later, you must copy.
- * @param elementLength length of element
- */
- virtual void
- onReceivedElement(const uint8_t *element, size_t elementLength) = 0;
-
-private:
- /**
- * Call the virtual method onReceivedElement. This is used to initialize the base ndn_ElementListener struct.
- * @param self
- * @param element
- * @param elementLength
- */
- static void
- staticOnReceivedElement(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength);
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/encoding/binary-xml-encoder.hpp b/ndn-cpp/encoding/binary-xml-encoder.hpp
index af495ca..33afb09 100644
--- a/ndn-cpp/encoding/binary-xml-encoder.hpp
+++ b/ndn-cpp/encoding/binary-xml-encoder.hpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -8,7 +9,7 @@
#define NDN_BINARYXMLENCODER_HPP
#include <vector>
-#include "../common.hpp"
+#include <ndn-cpp/common.hpp>
#include "../util/dynamic-uint8-vector.hpp"
#include "../c/encoding/binary-xml-encoder.h"
diff --git a/ndn-cpp/encoding/binary-xml-structure-decoder.hpp b/ndn-cpp/encoding/binary-xml-structure-decoder.hpp
index e953a1b..9ffd72b 100644
--- a/ndn-cpp/encoding/binary-xml-structure-decoder.hpp
+++ b/ndn-cpp/encoding/binary-xml-structure-decoder.hpp
@@ -1,3 +1,4 @@
+/* -*- 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>
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.cpp b/ndn-cpp/encoding/binary-xml-wire-format.cpp
index adb756a..9bd6759 100644
--- a/ndn-cpp/encoding/binary-xml-wire-format.cpp
+++ b/ndn-cpp/encoding/binary-xml-wire-format.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,15 +6,15 @@
*/
#include <stdexcept>
+#include <ndn-cpp/interest.hpp>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp/forwarding-entry.hpp>
+#include <ndn-cpp/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 "../interest.hpp"
-#include "../data.hpp"
-#include "../forwarding-entry.hpp"
#include "binary-xml-encoder.hpp"
#include "binary-xml-decoder.hpp"
-#include "binary-xml-wire-format.hpp"
using namespace std;
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.hpp b/ndn-cpp/encoding/binary-xml-wire-format.hpp
deleted file mode 100644
index c169669..0000000
--- a/ndn-cpp/encoding/binary-xml-wire-format.hpp
+++ /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_BINARYXMLWIREFORMAT_HPP
-#define NDN_BINARYXMLWIREFORMAT_HPP
-
-#include "wire-format.hpp"
-
-namespace ndn {
-
-/**
- * A BinaryXmlWireFormat extends WireFormat to override its virtual methods to implement encoding and decoding
- * using binary XML.
- */
-class BinaryXmlWireFormat : public WireFormat {
-public:
- /**
- * Encode interest in binary XML and return the encoding.
- * @param interest The Interest object to encode.
- * @return A Blob containing the encoding.
- */
- virtual Blob
- encodeInterest(const Interest& interest);
-
- /**
- * Decode input as an interest in binary XML and set the fields of the interest object.
- * @param interest The Interest object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- */
- virtual void
- decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength);
-
- /**
- * Encode data with binary XML and return the encoding.
- * @param data 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 call encodeData(const Data& data) to 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 call encodeData(const Data& data) to ignore this returned value.
- * @return A Blob containing the encoding.
- */
- virtual Blob
- encodeData
- (const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
-
- /**
- * Decode input as a data packet in binary XML and set the fields in the data object.
- * @param data The Data object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- * @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 call
- * decodeData(Data& data, const uint8_t *input, size_t inputLength) to 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 call
- * decodeData(Data& data, const uint8_t *input, size_t inputLength) to ignore this returned value.
- */
- virtual void
- decodeData
- (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
-
- /**
- * Encode forwardingEntry in binary XML and return the encoding.
- * @param forwardingEntry The ForwardingEntry object to encode.
- * @return A Blob containing the encoding.
- */
- virtual Blob
- encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
-
- /**
- * Decode input as a forwarding entry in binary XML and set the fields of the forwardingEntry object.
- * @param forwardingEntry The ForwardingEntry object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- */
- virtual void
- decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength);
-};
-
-}
-
-#endif
-
diff --git a/ndn-cpp/encoding/binary-xml-element-reader.cpp b/ndn-cpp/encoding/element-listener.cpp
similarity index 77%
rename from ndn-cpp/encoding/binary-xml-element-reader.cpp
rename to ndn-cpp/encoding/element-listener.cpp
index 559af7f..58bb875 100644
--- a/ndn-cpp/encoding/binary-xml-element-reader.cpp
+++ b/ndn-cpp/encoding/element-listener.cpp
@@ -1,10 +1,11 @@
+/* -*- 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 "binary-xml-element-reader.hpp"
+#include <ndn-cpp/encoding/element-listener.hpp>
namespace ndn {
diff --git a/ndn-cpp/encoding/wire-format.cpp b/ndn-cpp/encoding/wire-format.cpp
index cf7890e..8751d16 100644
--- a/ndn-cpp/encoding/wire-format.cpp
+++ b/ndn-cpp/encoding/wire-format.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,7 +6,7 @@
*/
#include <stdexcept>
-#include "wire-format.hpp"
+#include <ndn-cpp/encoding/wire-format.hpp>
using namespace std;
diff --git a/ndn-cpp/encoding/wire-format.hpp b/ndn-cpp/encoding/wire-format.hpp
deleted file mode 100644
index c5b4c6e..0000000
--- a/ndn-cpp/encoding/wire-format.hpp
+++ /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_WIREFORMAT_HPP
-#define NDN_WIREFORMAT_HPP
-
-#include "../common.hpp"
-#include "../util/blob.hpp"
-
-namespace ndn {
-
-class Interest;
-class Data;
-class ForwardingEntry;
-
-class WireFormat {
-public:
- /**
- * Encode interest and return the encoding. Your derived class should override.
- * @param interest The Interest object to encode.
- * @return A Blob containing the encoding.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual Blob
- encodeInterest(const Interest& interest);
-
- /**
- * Decode input as an interest and set the fields of the interest object. Your derived class should override.
- * @param interest The Interest object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual void
- decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength);
-
- /**
- * Encode data and return the encoding. Your derived class should override.
- * @param data 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 call encodeData(const Data& data) to 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 call encodeData(const Data& data) to ignore this returned value.
- * @return A Blob containing the encoding.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual Blob
- encodeData
- (const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
-
- /**
- * Encode data and return the encoding.
- * @param data The Data object to encode.
- * @return A Blob containing the encoding.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- Blob
- encodeData(const Data& data)
- {
- size_t dummyBeginOffset, dummyEndOffset;
- return encodeData(data, &dummyBeginOffset, &dummyEndOffset);
- }
-
- /**
- * Decode input as a data packet and set the fields in the data object. Your derived class should override.
- * @param data The Data object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- * @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 call
- * decodeData(Data& data, const uint8_t *input, size_t inputLength) to 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 call
- * decodeData(Data& data, const uint8_t *input, size_t inputLength) to ignore this returned value.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual void
- decodeData
- (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
-
- void
- decodeData(Data& data, const uint8_t *input, size_t inputLength)
- {
- size_t dummyBeginOffset, dummyEndOffset;
- decodeData(data, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
- }
-
- /**
- * Encode forwardingEntry and return the encoding. Your derived class should override.
- * @param forwardingEntry The ForwardingEntry object to encode.
- * @return A Blob containing the encoding.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual Blob
- encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
-
- /**
- * Decode input as a forwarding entry and set the fields of the forwardingEntry object. Your derived class should override.
- * @param forwardingEntry The ForwardingEntry object whose fields are updated.
- * @param input A pointer to the input buffer to decode.
- * @param inputLength The number of bytes in input.
- * @throw logic_error for unimplemented if the derived class does not override.
- */
- virtual void
- decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength);
-
- /**
- * Set the static default WireFormat used by default encoding and decoding methods.
- * @param wireFormat A Pointer to an object of a subclass of WireFormat. This does not make a copy and
- * the caller must ensure that the object remains allocated.
- */
- static void
- setDefaultWireFormat(WireFormat *wireFormat)
- {
- defaultWireFormat_ = wireFormat;
- }
-
- /**
- * Return the default WireFormat used by default encoding and decoding methods which was set with
- * setDefaultWireFormat.
- * @return A pointer to the WireFormat object.
- */
- static WireFormat*
- getDefaultWireFormat();
-
-private:
- /**
- * This is implemented by only one of the subclasses of WireFormat to return a new object used
- * as the initial value for the default WireFormat. If the application doesn't include that class, then the application
- * needs to include another subclass which defines WireFormat::newInitialDefaultWireFormat.
- * @return a new object, which is held by a shared_ptr and freed when the application exits.
- */
- static WireFormat*
- newInitialDefaultWireFormat();
-
- static WireFormat *defaultWireFormat_;
-};
-
-}
-
-#endif
-
diff --git a/ndn-cpp/face.cpp b/ndn-cpp/face.cpp
index d70023b..b137765 100644
--- a/ndn-cpp/face.cpp
+++ b/ndn-cpp/face.cpp
@@ -1,10 +1,11 @@
+/* -*- 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 "face.hpp"
+#include <ndn-cpp/face.hpp>
using namespace std;
diff --git a/ndn-cpp/face.hpp b/ndn-cpp/face.hpp
deleted file mode 100644
index 8eab12a..0000000
--- a/ndn-cpp/face.hpp
+++ /dev/null
@@ -1,156 +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_FACE_HPP
-#define NDN_FACE_HPP
-
-#include "node.hpp"
-#include "transport/tcp-transport.hpp"
-
-namespace ndn {
-
-/**
- * The Face class provides the main methods for NDN communication.
- */
-class Face {
-public:
- /**
- * Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo.
- * @param transport A shared_ptr to a Transport object used for communication.
- * @param transport A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
- */
- Face(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo)
- : node_(transport, connectionInfo)
- {
- }
-
- /**
- * Create a new Face for communication with an NDN hub at host:port using the default TcpTransport.
- * @param host The host of the NDN hub.
- * @param port The port of the NDN hub. If omitted. use 6363.
- */
- Face(const char *host, unsigned short port = 6363)
- : node_(ptr_lib::make_shared<TcpTransport>(),
- ptr_lib::make_shared<TcpTransport::ConnectionInfo>(host, port))
- {
- }
-
- /**
- * Send the Interest through the transport, read the entire response and call onData(interest, data).
- * @param interest A reference to the Interest. This copies the Interest.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- * @return The pending interest ID which can be used with removePendingInterest.
- */
- uint64_t
- expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
- {
- return node_.expressInterest(interest, onData, onTimeout);
- }
-
- /**
- * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- * @return The pending interest ID which can be used with removePendingInterest.
- */
- uint64_t
- expressInterest(const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
-
- /**
- * Encode name as an Interest, using a default interest lifetime.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- * @return The pending interest ID which can be used with removePendingInterest.
- */
- uint64_t
- expressInterest(const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
- {
- return expressInterest(name, 0, onData, onTimeout);
- }
-
- /**
- * Remove the pending interest entry with the pendingInterestId from the pending interest table.
- * This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name.
- * If there is no entry with the pendingInterestId, do nothing.
- * @param pendingInterestId The ID returned from expressInterest.
- */
- void
- removePendingInterest(uint64_t pendingInterestId)
- {
- node_.removePendingInterest(pendingInterestId);
- }
-
- /**
- * Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
- * @param prefix A reference to a Name for the prefix to register. This copies the Name.
- * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onRegisterFailed A function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix.
- * This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
- * @param flags The flags for finer control of which interests are forward to the application. If omitted, use
- * the default flags defined by the default ForwardingFlags constructor.
- * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
- * @return The registered prefix ID which can be used with removeRegisteredPrefix.
- */
- uint64_t
- registerPrefix
- (const Name& prefix, const OnInterest& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags = ForwardingFlags(),
- WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- return node_.registerPrefix(prefix, onInterest, onRegisterFailed, flags, wireFormat);
- }
-
- /**
- * Remove the registered prefix entry with the registeredPrefixId from the pending interest table.
- * This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name.
- * If there is no entry with the registeredPrefixId, do nothing.
- * @param registeredPrefixId The ID returned from registerPrefix.
- */
- void
- removeRegisteredPrefix(uint64_t registeredPrefixId)
- {
- node_.removeRegisteredPrefix(registeredPrefixId);
- }
-
- /**
- * Process any data to receive or call timeout callbacks.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- void
- processEvents()
- {
- // Just call Node's processEvents.
- node_.processEvents();
- }
-
- /**
- * Shut down and disconnect this Face.
- */
- void
- shutdown();
-
-private:
- Node node_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/forwarding-entry.cpp b/ndn-cpp/forwarding-entry.cpp
index 93c4d26..452d39b 100644
--- a/ndn-cpp/forwarding-entry.cpp
+++ b/ndn-cpp/forwarding-entry.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,8 +6,9 @@
*/
#include <stdexcept>
-#include "common.hpp"
-#include "forwarding-entry.hpp"
+#include <ndn-cpp/common.hpp>
+#include <ndn-cpp/forwarding-entry.hpp>
+#include "c/forwarding-entry.h"
using namespace std;
diff --git a/ndn-cpp/forwarding-entry.hpp b/ndn-cpp/forwarding-entry.hpp
deleted file mode 100644
index 1bd15fa..0000000
--- a/ndn-cpp/forwarding-entry.hpp
+++ /dev/null
@@ -1,118 +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_HPP
-#define NDN_FORWARDING_ENTRY_HPP
-
-#include <string>
-#include "name.hpp"
-#include "publisher-public-key-digest.hpp"
-#include "forwarding-flags.hpp"
-#include "c/forwarding-entry.h"
-
-namespace ndn {
-
-/**
- * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry.
- */
-class ForwardingEntry {
-public:
- ForwardingEntry
- (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest,
- int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds)
- : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest),
- faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds)
- {
- }
-
- ForwardingEntry()
- : faceId_(-1), freshnessSeconds_(-1)
- {
- forwardingFlags_.setActive(true);
- forwardingFlags_.setChildInherit(true);
- }
-
- Blob
- wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
- {
- return wireFormat.encodeForwardingEntry(*this);
- }
-
- void
- wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireFormat.decodeForwardingEntry(*this, input, inputLength);
- }
-
- void
- wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireDecode(&input[0], input.size(), wireFormat);
- }
-
- /**
- * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory.
- * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
- * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
- */
- void
- get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
-
- const std::string&
- getAction() const { return action_; }
-
- Name&
- getPrefix() { return prefix_; }
-
- const Name&
- getPrefix() const { return prefix_; }
-
- PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
- const PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
-
- int
- getFaceId() const { return faceId_; }
-
- const ForwardingFlags&
- getForwardingFlags() const { return forwardingFlags_; }
-
- int
- getFreshnessSeconds() const { return freshnessSeconds_; }
-
- /**
- * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
- * @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
- */
- void
- set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
-
- void
- setAction(const std::string& value) { action_ = value; }
-
- void
- setFaceId(int value) { faceId_ = value; }
-
- void
- setForwardingFlags(const ForwardingFlags& value) { forwardingFlags_ = value; }
-
- void
- setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
-
-private:
- std::string action_; /**< empty for none. */
- Name prefix_;
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
- int faceId_; /**< -1 for none. */
- ForwardingFlags forwardingFlags_;
- int freshnessSeconds_; /**< -1 for none. */
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/forwarding-flags.hpp b/ndn-cpp/forwarding-flags.hpp
deleted file mode 100644
index 7f06dfd..0000000
--- a/ndn-cpp/forwarding-flags.hpp
+++ /dev/null
@@ -1,134 +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_FORWARDING_FLAGS_HPP
-#define NDN_FORWARDING_FLAGS_HPP
-
-#include "c/forwarding-flags.h"
-
-namespace ndn {
-
-/**
- * A 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.
- */
-class ForwardingFlags : public ndn_ForwardingFlags {
-public:
- /**
- * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
- */
- ForwardingFlags()
- {
- ndn_ForwardingFlags_initialize(this);
- }
-
- ForwardingFlags(const struct ndn_ForwardingFlags &forwardingFlagsStruct)
- : ndn_ForwardingFlags(forwardingFlagsStruct)
- {
- }
-
- /**
- * Get the value of the "active" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getActive() const { return active; }
-
- /**
- * Get the value of the "childInherit" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getChildInherit() const { return childInherit; }
-
- /**
- * Get the value of the "advertise" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getAdvertise() const { return advertise; }
-
- /**
- * Get the value of the "last" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getLast() const { return last; }
-
- /**
- * Get the value of the "capture" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getCapture() const { return capture; }
-
- /**
- * Get the value of the "local" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getLocal() const { return local; }
-
- /**
- * Get the value of the "tap" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getTap() const { return tap; }
-
- /**
- * Get the value of the "captureOk" flag.
- * @return true if the flag is set, false if it is cleared.
- */
- bool getCaptureOk() const { return captureOk; }
-
- /**
- * Set the value of the "active" flag
- * @param value true to set the flag, false to clear it.
- */
- void setActive(bool value) { active = value ? 1 : 0; }
-
- /**
- * Set the value of the "childInherit" flag
- * @param value true to set the flag, false to clear it.
- */
- void setChildInherit(bool value) { childInherit = value ? 1 : 0; }
-
- /**
- * Set the value of the "advertise" flag
- * @param value true to set the flag, false to clear it.
- */
- void setAdvertise(bool value) { advertise = value ? 1 : 0; }
-
- /**
- * Set the value of the "last" flag
- * @param value true to set the flag, false to clear it.
- */
- void setLast(bool value) { last = value ? 1 : 0; }
-
- /**
- * Set the value of the "capture" flag
- * @param value true to set the flag, false to clear it.
- */
- void setCapture(bool value) { capture = value ? 1 : 0; }
-
- /**
- * Set the value of the "local" flag
- * @param value true to set the flag, false to clear it.
- */
- void setLocal(bool value) { local = value ? 1 : 0; }
-
- /**
- * Set the value of the "tap" flag
- * @param value true to set the flag, false to clear it.
- */
- void setTap(bool value) { tap = value ? 1 : 0; }
-
- /**
- * Set the value of the "captureOk" flag
- * @param value true to set the flag, false to clear it.
- */
- void setCaptureOk(bool value) { captureOk = value ? 1 : 0; }
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/interest.cpp b/ndn-cpp/interest.cpp
index e1a6af7..ceeffcd 100644
--- a/ndn-cpp/interest.cpp
+++ b/ndn-cpp/interest.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,14 +6,23 @@
*/
#include <stdexcept>
-#include "common.hpp"
-#include "interest.hpp"
+#include <ndn-cpp/common.hpp>
+#include <ndn-cpp/interest.hpp>
+#include "c/interest.h"
using namespace std;
namespace ndn {
void
+ExcludeEntry::get(struct ndn_ExcludeEntry& excludeEntryStruct) const
+{
+ excludeEntryStruct.type = type_;
+ if (type_ == ndn_Exclude_COMPONENT)
+ component_.get(excludeEntryStruct.component);
+}
+
+void
Exclude::get(struct ndn_Exclude& excludeStruct) const
{
if (excludeStruct.maxEntries < entries_.size())
diff --git a/ndn-cpp/interest.hpp b/ndn-cpp/interest.hpp
deleted file mode 100644
index de4f00e..0000000
--- a/ndn-cpp/interest.hpp
+++ /dev/null
@@ -1,290 +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_HPP
-#define NDN_INTEREST_HPP
-
-#include "name.hpp"
-#include "publisher-public-key-digest.hpp"
-#include "c/interest.h"
-
-namespace ndn {
-
-/**
- * An ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value.
- */
-class ExcludeEntry {
-public:
- /**
- * Create an ExcludeEntry of type ndn_Exclude_ANY
- */
- ExcludeEntry()
- : type_(ndn_Exclude_ANY)
- {
- }
-
- /**
- * Create an ExcludeEntry of type ndn_Exclude_COMPONENT
- */
- ExcludeEntry(uint8_t *component, size_t componentLen)
- : type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
- {
- }
-
- /**
- * Set the type in the excludeEntryStruct and to point to this component, without copying any memory.
- * WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory.
- * @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer
- */
- void
- get(struct ndn_ExcludeEntry& excludeEntryStruct) const
- {
- excludeEntryStruct.type = type_;
- if (type_ == ndn_Exclude_COMPONENT)
- component_.get(excludeEntryStruct.component);
- }
-
- ndn_ExcludeType getType() const { return type_; }
-
- const Name::Component& getComponent() const { return component_; }
-
-private:
- ndn_ExcludeType type_;
- Name::Component component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
-};
-
-/**
- * An Exclude holds a vector of ExcludeEntry.
- */
-class Exclude {
-public:
- /**
- * Create a new Exclude with no entries.
- */
- Exclude() {
- }
-
- size_t
- getEntryCount() const {
- return entries_.size();
- }
-
- const ExcludeEntry&
- getEntry(size_t i) const { return entries_[i]; }
-
- /**
- * Set the excludeStruct to point to the entries in this Exclude, without copying any memory.
- * WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory.
- * @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated
- */
- void
- get(struct ndn_Exclude& excludeStruct) const;
-
- /**
- * Clear this Exclude, and set the entries by copying from the ndn_Exclude struct.
- * @param excludeStruct a C ndn_Exclude struct
- */
- void
- set(const struct ndn_Exclude& excludeStruct);
-
- /**
- * Add a new entry of type ndn_Exclude_ANY
- */
- void
- addAny()
- {
- entries_.push_back(ExcludeEntry());
- }
-
- /**
- * Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength
- */
- void
- addComponent(uint8_t *component, size_t componentLen)
- {
- entries_.push_back(ExcludeEntry(component, componentLen));
- }
-
- /**
- * Clear all the entries.
- */
- void
- clear() {
- entries_.clear();
- }
-
- /**
- * Encode this Exclude with elements separated by "," and ndn_Exclude_ANY shown as "*".
- * @return the URI string
- */
- std::string toUri() const;
-
-private:
- std::vector<ExcludeEntry> entries_;
-};
-
-/**
- * An Interest holds a Name and other fields for an interest.
- */
-class Interest {
-public:
- Interest(const Name& name, int minSuffixComponents, int maxSuffixComponents,
- const PublisherPublicKeyDigest& publisherPublicKeyDigest, const Exclude& exclude, int childSelector, int answerOriginKind,
- int scope, double interestLifetimeMilliseconds, const std::vector<uint8_t>& nonce)
- : name_(name), minSuffixComponents_(minSuffixComponents), maxSuffixComponents_(maxSuffixComponents),
- publisherPublicKeyDigest_(publisherPublicKeyDigest), exclude_(exclude), childSelector_(childSelector),
- answerOriginKind_(answerOriginKind), scope_(scope), interestLifetimeMilliseconds_(interestLifetimeMilliseconds),
- nonce_(nonce)
- {
- }
-
- Interest(const Name& name, int minSuffixComponents, int maxSuffixComponents,
- const PublisherPublicKeyDigest& publisherPublicKeyDigest, const Exclude& exclude, int childSelector, int answerOriginKind,
- int scope, double interestLifetimeMilliseconds)
- : name_(name), minSuffixComponents_(minSuffixComponents), maxSuffixComponents_(maxSuffixComponents),
- publisherPublicKeyDigest_(publisherPublicKeyDigest), exclude_(exclude), childSelector_(childSelector),
- answerOriginKind_(answerOriginKind), scope_(scope), interestLifetimeMilliseconds_(interestLifetimeMilliseconds)
- {
- }
-
- Interest(const Name& name, double interestLifetimeMilliseconds)
- : name_(name)
- {
- construct();
- interestLifetimeMilliseconds_ = interestLifetimeMilliseconds;
- }
-
- Interest(const Name& name)
- : name_(name)
- {
- construct();
- }
-
- Interest()
- {
- construct();
- }
-
- Blob
- wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
- {
- return wireFormat.encodeInterest(*this);
- }
-
- void
- wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireFormat.decodeInterest(*this, input, inputLength);
- }
-
- void
- wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
- {
- wireDecode(&input[0], input.size(), wireFormat);
- }
-
- /**
- * Set the interestStruct to point to the components in this interest, without copying any memory.
- * WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory.
- * @param interestStruct a C ndn_Interest struct where the name components array is already allocated.
- */
- void
- get(struct ndn_Interest& interestStruct) const;
-
- Name&
- getName() { return name_; }
-
- const Name&
- getName() const { return name_; }
-
- int
- getMinSuffixComponents() const { return minSuffixComponents_; }
-
- int
- getMaxSuffixComponents() const { return maxSuffixComponents_; }
-
- PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
- const PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
-
- Exclude&
- getExclude() { return exclude_; }
-
- const Exclude&
- getExclude() const { return exclude_; }
-
- int
- getChildSelector() const { return childSelector_; }
-
- int
- getAnswerOriginKind() const { return answerOriginKind_; }
-
- int
- getScope() const { return scope_; }
-
- double
- getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; }
-
- const Blob&
- getNonce() const { return nonce_; }
-
- /**
- * Clear this interest, and set the values by copying from the interest struct.
- * @param interestStruct a C ndn_Interest struct
- */
- void
- set(const struct ndn_Interest& interestStruct);
-
- void
- setMinSuffixComponents(int value) { minSuffixComponents_ = value; }
-
- void
- setMaxSuffixComponents(int value) { maxSuffixComponents_ = value; }
-
- void
- setChildSelector(int value) { childSelector_ = value; }
-
- void
- setAnswerOriginKind(int value) { answerOriginKind_ = value; }
-
- void
- setScope(int value) { scope_ = value; }
-
- void
- setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; }
-
- void
- setNonce(const std::vector<uint8_t>& value) { nonce_ = value; }
-
-private:
- void
- construct()
- {
- minSuffixComponents_ = -1;
- maxSuffixComponents_ = -1;
- childSelector_ = -1;
- answerOriginKind_ = -1;
- scope_ = -1;
- interestLifetimeMilliseconds_ = -1.0;
- }
-
- Name name_;
- int minSuffixComponents_;
- int maxSuffixComponents_;
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
- Exclude exclude_;
- int childSelector_;
- int answerOriginKind_;
- int scope_;
- double interestLifetimeMilliseconds_;
- Blob nonce_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/key.cpp b/ndn-cpp/key.cpp
index db3ea58..0cf59ed 100644
--- a/ndn-cpp/key.cpp
+++ b/ndn-cpp/key.cpp
@@ -1,16 +1,18 @@
+/* -*- 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 "common.hpp"
-#include "key.hpp"
+#include <ndn-cpp/common.hpp>
+#include <ndn-cpp/key.hpp>
+#include "c/key.h"
using namespace std;
namespace ndn {
-
+
void
KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const
{
diff --git a/ndn-cpp/key.hpp b/ndn-cpp/key.hpp
deleted file mode 100644
index 6bfd779..0000000
--- a/ndn-cpp/key.hpp
+++ /dev/null
@@ -1,105 +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_HPP
-#define NDN_KEY_HPP
-
-#include <vector>
-#include "c/key.h"
-#include "name.hpp"
-
-namespace ndn {
-
-class KeyLocator {
-public:
- KeyLocator()
- : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1)
- {
- }
-
- /**
- * Clear the keyData and set the type to none.
- */
- void
- clear()
- {
- type_ = (ndn_KeyLocatorType)-1;
- keyNameType_ = (ndn_KeyNameType)-1;
- keyData_.reset();
- }
-
- /**
- * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory.
- * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
- * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
- */
- void
- get(struct ndn_KeyLocator& keyLocatorStruct) const;
-
- /**
- * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
- * @param keyLocatorStruct a C ndn_KeyLocator struct
- */
- void
- set(const struct ndn_KeyLocator& keyLocatorStruct);
-
- ndn_KeyLocatorType
- getType() const { return type_; }
-
- const Blob&
- getKeyData() const { return keyData_; }
-
- const Name&
- getKeyName() const { return keyName_; }
-
- Name&
- getKeyName() { return keyName_; }
-
- ndn_KeyNameType
- getKeyNameType() const { return keyNameType_; }
-
- void
- setType(ndn_KeyLocatorType type) { type_ = type; }
-
- void
- setKeyData(const std::vector<uint8_t>& keyData) { keyData_ = keyData; }
-
- void
- setKeyData(const uint8_t *keyData, size_t keyDataLength)
- {
- keyData_ = Blob(keyData, keyDataLength);
- }
-
- /**
- * Set keyData to point to an existing byte array. IMPORTANT: After calling this,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param keyData A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- */
- void
- setKeyData(const ptr_lib::shared_ptr<std::vector<uint8_t> > &keyData) { keyData_ = keyData; }
-
- void setKeyName(const Name &keyName) { keyName_ = keyName; }
-
- void
- setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
-
-private:
- ndn_KeyLocatorType type_; /**< -1 for none */
- Blob keyData_; /**< An array 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.
- */
- 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.) */
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/name.cpp b/ndn-cpp/name.cpp
index d74142e..4e619cc 100644
--- a/ndn-cpp/name.cpp
+++ b/ndn-cpp/name.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -6,7 +7,8 @@
#include <stdexcept>
#include <algorithm>
-#include "name.hpp"
+#include <ndn-cpp/name.hpp>
+#include "c/name.h"
using namespace std;
using namespace ndn::ptr_lib;
@@ -162,6 +164,20 @@
}
void
+Name::Component::get(struct ndn_NameComponent& componentStruct) const
+{
+ value_.get(componentStruct.value);
+}
+
+uint64_t
+Name::Component::toNumber() const
+{
+ struct ndn_NameComponent componentStruct;
+ get(componentStruct);
+ return ndn_NameComponent_toNumber(&componentStruct);
+}
+
+void
Name::set(const char *uri_cstr)
{
components_.clear();
diff --git a/ndn-cpp/name.hpp b/ndn-cpp/name.hpp
deleted file mode 100644
index 3adf841..0000000
--- a/ndn-cpp/name.hpp
+++ /dev/null
@@ -1,575 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_NAME_HPP
-#define NDN_NAME_HPP
-
-#include <vector>
-#include <string>
-#include <sstream>
-#include "c/name.h"
-#include "encoding/binary-xml-wire-format.hpp"
-#include "util/blob.hpp"
-
-namespace ndn {
-
-class Name {
-public:
- /**
- * A Name::Component is holds a read-only name component value.
- */
- class Component {
- public:
- /**
- * Create a new Name::Component with a null value.
- */
- Component()
- {
- }
-
- /**
- * Create a new Name::Component, copying the given value.
- * @param value The value byte array.
- */
- Component(const std::vector<uint8_t>& value)
- : value_(value)
- {
- }
-
- /**
- * Create a new Name::Component, copying the given value.
- * @param value Pointer to the value byte array.
- * @param valueLen Length of value.
- */
- Component(const uint8_t *value, size_t valueLen)
- : value_(value, valueLen)
- {
- }
-
- /**
- * Create a new Name::Component, taking another pointer to the Blob value.
- * @param value A blob with a pointer to an immutable array. The pointer is copied.
- */
- Component(const Blob &value)
- : value_(value)
- {
- }
-
- /**
- * Set the componentStruct to point to this component, without copying any memory.
- * WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
- * @param componentStruct The C ndn_NameComponent struct to receive the pointer.
- */
- void
- get(struct ndn_NameComponent& componentStruct) const
- {
- value_.get(componentStruct.value);
- }
-
- const Blob&
- getValue() const { return value_; }
-
- /**
- * Write this component value to result, escaping characters according to the NDN URI Scheme.
- * This also adds "..." to a value with zero or more ".".
- * @param value the buffer with the value to escape
- * @param result the string stream to write to.
- */
- void
- toEscapedString(std::ostringstream& result) const
- {
- Name::toEscapedString(*value_, result);
- }
-
- /**
- * Convert this component value by escaping characters according to the NDN URI Scheme.
- * This also adds "..." to a value with zero or more ".".
- * @return The escaped string.
- */
- std::string
- toEscapedString() const
- {
- return Name::toEscapedString(*value_);
- }
-
- /**
- * Interpret this name component as a network-ordered number and return an integer.
- * @return The integer number.
- */
- uint64_t
- toNumber() const
- {
- struct ndn_NameComponent componentStruct;
- get(componentStruct);
- return ndn_NameComponent_toNumber(&componentStruct);
- }
-
- /**
- * Interpret this name component as a network-ordered number with a marker and return an integer.
- * @param marker The required first byte of the component.
- * @return The integer number.
- * @throw runtime_error If the first byte of the component does not equal the marker.
- */
- uint64_t
- toNumberWithMarker(uint8_t marker) const;
-
- /**
- * Interpret this name component as a segment number according to NDN name conventions (a network-ordered number
- * where the first byte is the marker 0x00).
- * @return The integer segment number.
- * @throw runtime_error If the first byte of the component is not the expected marker.
- */
- uint64_t
- toSegment() const
- {
- return toNumberWithMarker(0x00);
- }
-
- /**
- * @deprecated Use toSegment.
- */
- uint64_t
- toSeqNum() const
- {
- return toSegment();
- }
-
- /**
- * Interpret this name component as a version number according to NDN name conventions (a network-ordered number
- * where the first byte is the marker 0xFD). Note that this returns the exact number from the component
- * without converting it to a time representation.
- * @return The integer segment number.
- * @throw runtime_error If the first byte of the component is not the expected marker.
- */
- uint64_t
- toVersion() const
- {
- return toNumberWithMarker(0xFD);
- }
-
- /**
- * Make a component value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
- * If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means this component value was not changed, and
- * the component should be skipped in a URI name.
- * @param escapedString The escaped string. It does not need to be null-terminated because we only scan to endOffset.
- * @param beginOffset The offset in escapedString of the beginning of the portion to decode.
- * @param endOffset The offset in escapedString of the end of the portion to decode.
- * @return The component value as a Blob, or a Blob with a null pointer if escapedString is not a valid escaped component.
- */
- static Blob
- makeFromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
-
- /**
- * Make a component as the encoded segment number.
- * @param segment The segment number.
- * @return The component value as a Blob.
- */
- static Blob
- makeSegment(unsigned long segment);
-
- private:
- Blob value_;
- };
-
- /**
- * Create a new Name with no components.
- */
- Name() {
- }
-
- /**
- * Create a new Name, copying the name components.
- * @param components A vector of Component
- */
- Name(const std::vector<Component>& components)
- : components_(components)
- {
- }
-
- /**
- * Parse the uri according to the NDN URI Scheme and create the name with the components.
- * @param uri The URI string.
- */
- Name(const char* uri)
- {
- set(uri);
- }
-
- /**
- * Parse the uri according to the NDN URI Scheme and create the name with the components.
- * @param uri The URI string.
- */
- Name(const std::string& uri)
- {
- set(uri.c_str());
- }
-
- /**
- * Set the nameStruct to point to the components in this name, without copying any memory.
- * WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory.
- * @param nameStruct A C ndn_Name struct where the components array is already allocated.
- */
- void
- get(struct ndn_Name& nameStruct) const;
-
- /**
- * Clear this name, and set the components by copying from the name struct.
- * @param nameStruct A C ndn_Name struct
- */
- void
- set(const struct ndn_Name& nameStruct);
-
- /**
- * Parse the uri according to the NDN URI Scheme and set the name with the components.
- * @param uri The URI string.
- */
- void
- set(const char *uri);
-
- /**
- * Append a new component, copying from value of length valueLength.
- * @return This name so that you can chain calls to append.
- */
- Name&
- append(const uint8_t *value, size_t valueLength)
- {
- components_.push_back(Component(value, valueLength));
- return *this;
- }
-
- /**
- * Append a new component, copying from value.
- * @return This name so that you can chain calls to append.
- */
- Name&
- append(const std::vector<uint8_t>& value)
- {
- components_.push_back(value);
- return *this;
- }
-
- Name&
- append(const Blob &value)
- {
- components_.push_back(value);
- return *this;
- }
-
- Name&
- append(const Component &value)
- {
- components_.push_back(value);
- return *this;
- }
-
- /**
- * Append the components of the given name to this name.
- * @param name The Name with components to append.
- * @return This name so that you can chain calls to append.
- */
- Name&
- append(const Name& name);
-
- /**
- * @deprecated Use append.
- */
- Name&
- appendComponent(const uint8_t *value, size_t valueLength)
- {
- return append(value, valueLength);
- }
-
- /**
- * @deprecated Use append.
- */
- Name&
- appendComponent(const std::vector<uint8_t>& value)
- {
- return append(value);
- }
-
- /**
- * @deprecated Use append.
- */
- Name&
- appendComponent(const Blob &value)
- {
- return append(value);
- }
-
- /**
- * @deprecated Use append.
- */
- Name&
- addComponent(const uint8_t *value, size_t valueLength)
- {
- return append(value, valueLength);
- }
-
- /**
- * @deprecated Use append.
- */
- Name&
- addComponent(const std::vector<uint8_t>& value)
- {
- return append(value);
- }
-
- /**
- * @deprecated Use append.
- */
- Name&
- addComponent(const Blob &value)
- {
- return append(value);
- }
-
- /**
- * Clear all the components.
- */
- void
- clear() {
- components_.clear();
- }
-
- /**
- * Get the number of components.
- * @return The number of components.
- */
- size_t
- getComponentCount() const {
- return components_.size();
- }
-
- /**
- * Get the component at the given index.
- * @param i The index of the component, starting from 0.
- * @return The name component at the index.
- */
- const Component&
- getComponent(size_t i) const { return components_[i]; }
-
- /**
- * Get a new name, constructed as a subset of components.
- * @param iStartComponent The index if the first component to get.
- * @param nComponents The number of components starting at iStartComponent.
- * @return A new name.
- */
- Name
- getSubName(size_t iStartComponent, size_t nComponents) const;
-
- /**
- * Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name.
- * @param iStartComponent The index if the first component to get.
- * @return A new name.
- */
- Name
- getSubName(size_t iStartComponent) const;
-
- /**
- * Return a new Name with the first nComponents components of this Name.
- * @param nComponents The number of prefix components.
- * @return A new Name.
- */
- Name
- getPrefix(size_t nComponents) const
- {
- return getSubName(0, nComponents);
- }
-
- /**
- * Encode this name as a URI.
- * @return The encoded URI.
- */
- std::string
- toUri() const;
-
- /**
- * @deprecated Use toUri().
- */
- std::string
- to_uri() const
- {
- return toUri();
- }
-
- /**
- * Append a component with the encoded segment number.
- * @param segment The segment number.
- * @return This name so that you can chain calls to append.
- */
- Name&
- appendSegment(unsigned long segment)
- {
- components_.push_back(Component(Component::makeSegment(segment)));
- return *this;
- }
-
- /**
- * Check if this name has the same component count and components as the given name.
- * @param name The Name to check.
- * @return true if the names are equal, otherwise false.
- */
- bool
- equals(const Name& name) const;
-
- /**
- * Check if the N components of this name are the same as the first N components of the given name.
- * @param name The Name to check.
- * @return true if this matches the given name, otherwise false. This always returns true if this name is empty.
- */
- bool
- match(const Name& name) const;
-
- /**
- * Write the value to result, escaping characters according to the NDN URI Scheme.
- * This also adds "..." to a value with zero or more ".".
- * @param value the buffer with the value to escape
- * @param result the string stream to write to.
- */
- static void
- toEscapedString(const std::vector<uint8_t>& value, std::ostringstream& result);
-
- /**
- * Convert the value by escaping characters according to the NDN URI Scheme.
- * This also adds "..." to a value with zero or more ".".
- * @param value the buffer with the value to escape
- * @return The escaped string.
- */
- static std::string
- toEscapedString(const std::vector<uint8_t>& value);
-
- //
- // vector equivalent interface.
- //
-
- /**
- * Get the number of components.
- * @return The number of components.
- */
- size_t
- size() const {
- return getComponentCount();
- }
-
- /**
- * Get the component at the given index.
- * @param i The index of the component, starting from 0.
- * @return The name component at the index.
- */
- const Component&
- get(size_t i) const { return getComponent(i); }
-
-
- const Component&
- operator [] (int i) const
- {
- return get(i);
- }
-
- /**
- * Append the component
- * @param component The component of type T.
- */
- template<class T> void
- push_back(const T &component)
- {
- append(component);
- }
-
- /**
- * Check if this name has the same component count and components as the given name.
- * @param name The Name to check.
- * @return true if the names are equal, otherwise false.
- */
- bool
- operator == (const Name &name) const { return equals(name); }
-
- /**
- * Check if this name has the same component count and components as the given name.
- * @param name The Name to check.
- * @return true if the names are not equal, otherwise false.
- */
- bool
- operator != (const Name &name) const { return !equals(name); }
-
- //
- // Iterator interface to name components.
- //
- typedef std::vector<Component>::iterator iterator;
- typedef std::vector<Component>::const_iterator const_iterator;
- typedef std::vector<Component>::reverse_iterator reverse_iterator;
- typedef std::vector<Component>::const_reverse_iterator const_reverse_iterator;
- typedef std::vector<Component>::reference reference;
- typedef std::vector<Component>::const_reference const_reference;
-
- typedef Component partial_type;
-
- /**
- * Begin iterator (const).
- */
- const_iterator
- begin() const { return components_.begin(); }
-
- /**
- * Begin iterator.
- */
- iterator
- begin() { return components_.begin(); }
-
- /**
- * End iterator (const).
- */
- const_iterator
- end() const { return components_.end(); }
-
- /**
- * End iterator.
- */
- iterator
- end() { return components_.end(); }
-
- /**
- * Reverse begin iterator (const).
- */
- const_reverse_iterator
- rbegin() const { return components_.rbegin(); }
-
- /**
- * Reverse begin iterator.
- */
- reverse_iterator
- rbegin() { return components_.rbegin(); }
-
- /**
- * Reverse end iterator (const).
- */
- const_reverse_iterator
- rend() const { return components_.rend(); }
-
- /**
- * Reverse end iterator.
- */
- reverse_iterator
- rend() { return components_.rend(); }
-
-private:
- std::vector<Component> components_;
-};
-
-inline std::ostream&
-operator << (std::ostream& os, const Name& name)
-{
- os << name.toUri();
- return os;
-}
-
-}
-
-#endif
-
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 30c0573..c145d50 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -6,13 +7,15 @@
#include <sys/time.h>
#include <stdexcept>
+#include "c/name.h"
+#include "c/interest.h"
#include "c/util/crypto.h"
-#include "encoding/binary-xml-decoder.hpp"
#include "c/encoding/binary-xml.h"
-#include "forwarding-entry.hpp"
-#include "security/key-chain.hpp"
-#include "sha256-with-rsa-signature.hpp"
-#include "node.hpp"
+#include "encoding/binary-xml-decoder.hpp"
+#include <ndn-cpp/forwarding-entry.hpp>
+#include <ndn-cpp/security/key-chain.hpp>
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/node.hpp>
using namespace std;
using namespace ndn::ptr_lib;
@@ -338,7 +341,8 @@
Node::PendingInterest::PendingInterest
(uint64_t pendingInterestId, const shared_ptr<const Interest>& interest, const OnData& onData, const OnTimeout& onTimeout)
-: pendingInterestId_(pendingInterestId), interest_(interest), onData_(onData), onTimeout_(onTimeout)
+: pendingInterestId_(pendingInterestId), interest_(interest), onData_(onData), onTimeout_(onTimeout),
+ interestStruct_(new struct ndn_Interest)
{
// Set up timeoutTime_.
if (interest_->getInterestLifetimeMilliseconds() >= 0.0)
@@ -352,8 +356,8 @@
nameComponents_.reserve(interest_->getName().getComponentCount());
excludeEntries_.reserve(interest_->getExclude().getEntryCount());
ndn_Interest_initialize
- (&interestStruct_, &nameComponents_[0], nameComponents_.capacity(), &excludeEntries_[0], excludeEntries_.capacity());
- interest_->get(interestStruct_);
+ (interestStruct_.get(), &nameComponents_[0], nameComponents_.capacity(), &excludeEntries_[0], excludeEntries_.capacity());
+ interest_->get(*interestStruct_);
}
bool
diff --git a/ndn-cpp/node.hpp b/ndn-cpp/node.hpp
deleted file mode 100644
index 24a2672..0000000
--- a/ndn-cpp/node.hpp
+++ /dev/null
@@ -1,332 +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_NODE_HPP
-#define NDN_NODE_HPP
-
-#include "common.hpp"
-#include "interest.hpp"
-#include "data.hpp"
-#include "transport/tcp-transport.hpp"
-#include "encoding/binary-xml-element-reader.hpp"
-#include "forwarding-flags.hpp"
-
-namespace ndn {
-
-/**
- * An OnData function object is used to pass a callback to expressInterest.
- */
-typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&, const ptr_lib::shared_ptr<Data>&)> OnData;
-
-/**
- * An OnTimeout function object is used to pass a callback to expressInterest.
- */
-typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&)> OnTimeout;
-
-/**
- * An OnInterest function object is used to pass a callback to registerPrefix.
- */
-typedef func_lib::function<void
- (const ptr_lib::shared_ptr<const Name>&, const ptr_lib::shared_ptr<const Interest>&, Transport&, uint64_t)> OnInterest;
-
-/**
- * An OnRegisterFailed function object is used to report when registerPrefix fails.
- */
-typedef func_lib::function<void(const ptr_lib::shared_ptr<const Name>&)> OnRegisterFailed;
-
-class Face;
-class KeyChain;
-
-class Node : public ElementListener {
-public:
- /**
- * Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo.
- * @param transport A shared_ptr to a Transport object used for communication.
- * @param transport A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
- */
- Node(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
-
- /**
- * Send the Interest through the transport, read the entire response and call onData(interest, data).
- * @param interest A reference to the Interest. This copies the Interest.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- * @return The pending interest ID which can be used with removePendingInterest.
- */
- uint64_t
- expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout);
-
- /**
- * Remove the pending interest entry with the pendingInterestId from the pending interest table.
- * This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name.
- * If there is no entry with the pendingInterestId, do nothing.
- * @param pendingInterestId The ID returned from expressInterest.
- */
- void
- removePendingInterest(uint64_t pendingInterestId);
-
- /**
- * Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
- * @param prefix A reference to a Name for the prefix to register. This copies the Name.
- * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onRegisterFailed A function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix.
- * This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
- * @param flags The flags for finer control of which interests are forward to the application.
- * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
- * @return The registered prefix ID which can be used with removeRegisteredPrefix.
- */
- uint64_t
- registerPrefix
- (const Name& prefix, const OnInterest& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags,
- WireFormat& wireFormat);
-
- /**
- * Remove the registered prefix entry with the registeredPrefixId from the pending interest table.
- * This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name.
- * If there is no entry with the registeredPrefixId, do nothing.
- * @param registeredPrefixId The ID returned from registerPrefix.
- */
- void
- removeRegisteredPrefix(uint64_t registeredPrefixId);
-
- /**
- * Process any data to receive. For each element received, call onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- void
- processEvents();
-
- const ptr_lib::shared_ptr<Transport>&
- getTransport() { return transport_; }
-
- const ptr_lib::shared_ptr<const Transport::ConnectionInfo>&
- getConnectionInfo() { return connectionInfo_; }
-
- void
- onReceivedElement(const uint8_t *element, size_t elementLength);
-
- void
- shutdown();
-
-private:
- class PendingInterest {
- public:
- /**
- * Create a new PitEntry and set the timeoutTime_ based on the current time and the interest lifetime.
- * @param pendingInterestId A unique ID for this entry, which you should get with getNextPendingInteresId().
- * @param interest A shared_ptr for the interest.
- * @param onData A function object to call when a matching data packet is received.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- */
- PendingInterest
- (uint64_t pendingInterestId, const ptr_lib::shared_ptr<const Interest>& interest, const OnData& onData,
- const OnTimeout& onTimeout);
-
- /**
- * Return the next unique pending interest ID.
- */
- static uint64_t
- getNextPendingInterestId()
- {
- return ++lastPendingInterestId_;
- }
-
- /**
- * Return the pendingInterestId given to the constructor.
- */
- uint64_t
- getPendingInterestId() { return pendingInterestId_; }
-
- const ptr_lib::shared_ptr<const Interest>&
- getInterest() { return interest_; }
-
- const OnData&
- getOnData() { return onData_; }
-
- /**
- * Get the struct ndn_Interest for the interest_.
- * WARNING: Assume that this PitEntry was created with new, so that no copy constructor is invoked between calls.
- * This class is private to Node and only used by its methods, so this should be OK.
- * TODO: Doesn't this functionality belong in the Interest class?
- * @return A reference to the ndn_Interest struct.
- * WARNING: The resulting pointers in are invalid uses getInterest() to manipulate the object which could reallocate memory.
- */
- const struct ndn_Interest&
- getInterestStruct()
- {
- return interestStruct_;
- }
-
- /**
- * If this interest is timed out, call onTimeout_ (if defined) and return true.
- * @param parent The parent Node for the UpcallInfo.
- * @param nowMilliseconds The current time in milliseconds from gettimeofday.
- * @return true if this interest timed out and the timeout callback was called, otherwise false.
- */
- bool
- checkTimeout(Node *parent, double nowMilliseconds);
-
- private:
- ptr_lib::shared_ptr<const Interest> interest_;
- std::vector<struct ndn_NameComponent> nameComponents_;
- std::vector<struct ndn_ExcludeEntry> excludeEntries_;
- struct ndn_Interest interestStruct_;
-
- static uint64_t lastPendingInterestId_; /**< A class variable used to get the next unique ID. */
- uint64_t pendingInterestId_; /**< A unique identifier for this entry so it can be deleted */
- const OnData onData_;
- const OnTimeout onTimeout_;
- double timeoutTimeMilliseconds_; /**< The time when the interest times out in milliseconds according to gettimeofday, or -1 for no timeout. */
- };
-
- class RegisteredPrefix {
- public:
- /**
- * Create a new PrefixEntry.
- * @param registeredPrefixId A unique ID for this entry, which you should get with getNextRegisteredPrefixId().
- * @param prefix A shared_ptr for the prefix.
- * @param onInterest A function object to call when a matching data packet is received.
- */
- RegisteredPrefix(uint64_t registeredPrefixId, const ptr_lib::shared_ptr<const Name>& prefix, const OnInterest& onInterest)
- : registeredPrefixId_(registeredPrefixId), prefix_(prefix), onInterest_(onInterest)
- {
- }
-
- /**
- * Return the next unique entry ID.
- */
- static uint64_t
- getNextRegisteredPrefixId()
- {
- return ++lastRegisteredPrefixId_;
- }
-
- /**
- * Return the registeredPrefixId given to the constructor.
- */
- uint64_t
- getRegisteredPrefixId() { return registeredPrefixId_; }
-
- const ptr_lib::shared_ptr<const Name>&
- getPrefix() { return prefix_; }
-
- const OnInterest&
- getOnInterest() { return onInterest_; }
-
- private:
- static uint64_t lastRegisteredPrefixId_; /**< A class variable used to get the next unique ID. */
- uint64_t registeredPrefixId_; /**< A unique identifier for this entry so it can be deleted */
- ptr_lib::shared_ptr<const Name> prefix_;
- const OnInterest onInterest_;
- };
-
- /**
- * An NdndIdFetcher receives the Data packet with the publisher public key digest for the connected NDN hub.
- * This class is a function object for the callbacks. It only holds a pointer to an Info object, so it is OK to copy the pointer.
- */
- class NdndIdFetcher {
- public:
- class Info;
- NdndIdFetcher(ptr_lib::shared_ptr<NdndIdFetcher::Info> info)
- : info_(info)
- {
- }
-
- /**
- * We received the ndnd ID.
- * @param interest
- * @param data
- */
- void
- operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData);
-
- /**
- * We timed out fetching the ndnd ID.
- * @param interest
- */
- void
- operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
-
- class Info {
- public:
- /**
- *
- * @param node
- * @param registeredPrefixId The PrefixEntry::getNextRegisteredPrefixId() which registerPrefix got so it could return it to the caller.
- * @param prefix
- * @param onInterest
- * @param onRegisterFailed
- * @param flags
- * @param wireFormat
- */
- Info(Node *node, uint64_t registeredPrefixId, const Name& prefix, const OnInterest& onInterest,
- const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, WireFormat& wireFormat)
- : node_(*node), registeredPrefixId_(registeredPrefixId), prefix_(new Name(prefix)), onInterest_(onInterest), onRegisterFailed_(onRegisterFailed),
- flags_(flags), wireFormat_(wireFormat)
- {
- }
-
- Node& node_;
- uint64_t registeredPrefixId_;
- ptr_lib::shared_ptr<const Name> prefix_;
- const OnInterest onInterest_;
- const OnRegisterFailed onRegisterFailed_;
- ForwardingFlags flags_;
- WireFormat& wireFormat_;
- };
-
- private:
- ptr_lib::shared_ptr<Info> info_;
- };
-
- /**
- * Find the entry from the pit_ where the name conforms to the entry's interest selectors, and
- * the entry interest name is the longest that matches name.
- * @param name The name to find the interest for (from the incoming data packet).
- * @return The index in pit_ of the pit entry, or -1 if not found.
- */
- int
- getEntryIndexForExpressedInterest(const Name& name);
-
- /**
- * Find the first entry from the registeredPrefixTable_ where the entry prefix is the longest that matches name.
- * @param name The name to find the PrefixEntry for (from the incoming interest packet).
- * @return A pointer to the entry, or 0 if not found.
- */
- RegisteredPrefix*
- getEntryForRegisteredPrefix(const Name& name);
-
- /**
- * Do the work of registerPrefix once we know we are connected with an ndndId_.
- * @param registeredPrefixId The PrefixEntry::getNextRegisteredPrefixId() which registerPrefix got so it could return it to the caller.
- * @param prefix
- * @param onInterest
- * @param onRegisterFailed
- * @param flags
- * @param wireFormat
- */
- void
- registerPrefixHelper
- (uint64_t registeredPrefixId, const ptr_lib::shared_ptr<const Name>& prefix, const OnInterest& onInterest,
- const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, WireFormat& wireFormat);
-
- ptr_lib::shared_ptr<Transport> transport_;
- ptr_lib::shared_ptr<const Transport::ConnectionInfo> connectionInfo_;
- std::vector<ptr_lib::shared_ptr<PendingInterest> > pendingInterestTable_;
- std::vector<ptr_lib::shared_ptr<RegisteredPrefix> > registeredPrefixTable_;
- Interest ndndIdFetcherInterest_;
- Blob ndndId_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/publisher-public-key-digest.cpp b/ndn-cpp/publisher-public-key-digest.cpp
new file mode 100644
index 0000000..a0667fa
--- /dev/null
+++ b/ndn-cpp/publisher-public-key-digest.cpp
@@ -0,0 +1,27 @@
+/* -*- 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/publisher-public-key-digest.h"
+#include <ndn-cpp/publisher-public-key-digest.hpp>
+
+using namespace std;
+
+namespace ndn {
+
+void
+PublisherPublicKeyDigest::get(struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct) const
+{
+ publisherPublicKeyDigest_.get(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
+}
+
+void
+PublisherPublicKeyDigest::set(const struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct)
+{
+ publisherPublicKeyDigest_ = Blob(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
+}
+
+}
diff --git a/ndn-cpp/publisher-public-key-digest.hpp b/ndn-cpp/publisher-public-key-digest.hpp
deleted file mode 100644
index 8069fa0..0000000
--- a/ndn-cpp/publisher-public-key-digest.hpp
+++ /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_PUBLISHERPUBLICKEYDIGEST_HPP
-#define NDN_PUBLISHERPUBLICKEYDIGEST_HPP
-
-#include <vector>
-#include "common.hpp"
-#include "c/publisher-public-key-digest.h"
-
-namespace ndn {
-
-/**
- * A PublisherPublicKeyDigest holds the publisher public key digest value, if any.
- * We make a separate class since this is used by multiple other classes.
- */
-class PublisherPublicKeyDigest {
-public:
- PublisherPublicKeyDigest() {
- }
-
- /**
- * Set the publisherPublicKeyDigestStruct to point to the entries in this PublisherPublicKeyDigest, without copying any memory.
- * WARNING: The resulting pointers in publisherPublicKeyDigestStruct are invalid after a further use of this object which could reallocate memory.
- * @param publisherPublicKeyDigestStruct a C ndn_PublisherPublicKeyDigest struct to receive the pointer
- */
- void
- get(struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct) const
- {
- publisherPublicKeyDigest_.get(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
- }
-
- /**
- * Clear this PublisherPublicKeyDigest, and copy from the ndn_PublisherPublicKeyDigest struct.
- * @param excludeStruct a C ndn_Exclude struct
- */
- void
- set(const struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct)
- {
- publisherPublicKeyDigest_ = Blob(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
- }
-
- const Blob&
- getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
-
- void
- setPublisherPublicKeyDigest(const std::vector<uint8_t>& publisherPublicKeyDigest)
- {
- publisherPublicKeyDigest_ = publisherPublicKeyDigest;
- }
-
- void
- setPublisherPublicKeyDigest(const uint8_t *publisherPublicKeyDigest, size_t publisherPublicKeyDigestLength)
- {
- publisherPublicKeyDigest_ = Blob(publisherPublicKeyDigest, publisherPublicKeyDigestLength);
- }
-
- /**
- * Set the publisher public key digest to point to an existing byte array. IMPORTANT: After calling this,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param signature A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- */
- void
- setPublisherPublicKeyDigest(const ptr_lib::shared_ptr<std::vector<uint8_t> > &publisherPublicKeyDigest)
- {
- publisherPublicKeyDigest_ = publisherPublicKeyDigest;
- }
-
- void
- setPublisherPublicKeyDigest(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &publisherPublicKeyDigest)
- {
- publisherPublicKeyDigest_ = publisherPublicKeyDigest;
- }
-
- /**
- * Clear the publisherPublicKeyDigest.
- */
- void
- clear()
- {
- publisherPublicKeyDigest_.reset();
- }
-
-private:
- Blob publisherPublicKeyDigest_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/certificate/certificate.hpp b/ndn-cpp/security/certificate/certificate.hpp
deleted file mode 100644
index 29626b3..0000000
--- a/ndn-cpp/security/certificate/certificate.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_CERTIFICATE_HPP
-#define NDN_CERTIFICATE_HPP
-
-#include "../../data.hpp"
-
-namespace ndn {
-
-class Certificate : public Data {
-
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/certificate/oid.cpp b/ndn-cpp/security/certificate/oid.cpp
index 6ae1942..b03d93e 100644
--- a/ndn-cpp/security/certificate/oid.cpp
+++ b/ndn-cpp/security/certificate/oid.cpp
@@ -8,7 +8,7 @@
#include <stdlib.h>
#include <sstream>
-#include "oid.hpp"
+#include <ndn-cpp/security/certificate/oid.hpp>
using namespace std;
diff --git a/ndn-cpp/security/certificate/oid.hpp b/ndn-cpp/security/certificate/oid.hpp
deleted file mode 100644
index bcbcfe9..0000000
--- a/ndn-cpp/security/certificate/oid.hpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_OID_HPP
-#define NDN_OID_HPP
-
-#include <vector>
-#include <string>
-
-namespace ndn {
-
-class OID {
-public:
- OID ()
- {
- }
-
- OID(const std::string& oid);
-
- OID(const std::vector<int>& oid)
- : oid_(oid)
- {
- }
-
- const std::vector<int> &
- getIntegerList() const
- {
- return oid_;
- }
-
- void
- setIntegerList(const std::vector<int>& value){
- oid_ = value;
- }
-
- std::string
- toString();
-
- bool operator == (const OID& oid)
- {
- return equal(oid);
- }
-
- bool operator != (const OID& oid)
- {
- return !equal(oid);
- }
-
-private:
- bool equal(const OID& oid);
-
- std::vector<int> oid_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/certificate/public-key.cpp b/ndn-cpp/security/certificate/public-key.cpp
index 3565ac3..cd88f7e 100644
--- a/ndn-cpp/security/certificate/public-key.cpp
+++ b/ndn-cpp/security/certificate/public-key.cpp
@@ -6,9 +6,9 @@
* See COPYING for copyright and distribution information.
*/
-#include "../security-exception.hpp"
+#include <ndn-cpp/security//security-exception.hpp>
#include "../../c/util/crypto.h"
-#include "public-key.hpp"
+#include <ndn-cpp/security/certificate/public-key.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/certificate/public-key.hpp b/ndn-cpp/security/certificate/public-key.hpp
deleted file mode 100644
index 7db3f49..0000000
--- a/ndn-cpp/security/certificate/public-key.hpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_PUBLIC_KEY_HPP
-#define NDN_PUBLIC_KEY_HPP
-
-#include "../../util/blob.hpp"
-#include "oid.hpp"
-#include "../security-common.hpp"
-
-namespace ndn {
-
-class PublicKey {
-public:
- /**
- * The default constructor.
- */
- PublicKey() {}
-
- /**
- * Constructor
- * @param algorithm The algorithm of the public key.
- * @param keyDer The blob of the PublicKeyInfo in terms of DER.
- */
- PublicKey(const OID& algorithm, const Blob& keyDer)
- : algorithm_(algorithm), keyDer_(keyDer)
- {
- }
-
-#if 0
- /**
- * Encode the public key into DER.
- * @return the encoded DER syntax tree.
- */
- Ptr<der::DerNode>
- toDer();
-#endif
-
- /**
- * Decode the public key from DER blob.
- * @param keyDer The DER blob.
- * @return The decoded public key.
- */
- static ptr_lib::shared_ptr<PublicKey>
- fromDer(const Blob& keyDer);
-
- /*
- * @brief get the digest of the public key
- * @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_SHA256 by default.
- */
- Blob
- getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
-
- /*
- * Get the raw bytes of the public key in DER format.
- */
- const Blob&
- getKeyDer() const { return keyDer_; }
-
-private:
- OID algorithm_; /**< Algorithm */
- Blob keyDer_; /**< PublicKeyInfo in DER */
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/encryption/encryption-manager.hpp b/ndn-cpp/security/encryption/encryption-manager.hpp
deleted file mode 100644
index 88a69c8..0000000
--- a/ndn-cpp/security/encryption/encryption-manager.hpp
+++ /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: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_ENCRYPTION_MANAGER_HPP
-#define NDN_ENCRYPTION_MANAGER_HPP
-
-#include "../../name.hpp"
-#include "../security-common.hpp"
-
-namespace ndn {
-
-class EncryptionManager {
-public:
- virtual ~EncryptionManager() {}
-
- virtual void
- createSymmetricKey(const Name& keyName, KeyType keyType, const Name& signkeyName = Name(), bool isSymmetric = true) = 0;
-
- virtual Blob
- encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = false,
- EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT) = 0;
-
- virtual Blob
- decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = false,
- EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT) = 0;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/identity/basic-identity-storage.cpp b/ndn-cpp/security/identity/basic-identity-storage.cpp
index e383a32..3cad5cc 100644
--- a/ndn-cpp/security/identity/basic-identity-storage.cpp
+++ b/ndn-cpp/security/identity/basic-identity-storage.cpp
@@ -15,9 +15,9 @@
#include <stdlib.h>
#include <sstream>
#include <fstream>
-#include "basic-identity-storage.hpp"
+#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
#include "../../util/logging.hpp"
-#include "../security-exception.hpp"
+#include <ndn-cpp/security//security-exception.hpp>
#include "ndn-cpp/data.hpp"
#if 0
diff --git a/ndn-cpp/security/identity/basic-identity-storage.hpp b/ndn-cpp/security/identity/basic-identity-storage.hpp
deleted file mode 100644
index 2e0db30..0000000
--- a/ndn-cpp/security/identity/basic-identity-storage.hpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_BASIC_IDENTITY_STORAGE_H
-#define NDN_BASIC_IDENTITY_STORAGE_H
-
-// Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_SQLITE3.
-#include <ndn-cpp/ndn-cpp-config.h>
-#ifdef NDN_CPP_HAVE_SQLITE3
-
-#include <sqlite3.h>
-#include "../../common.hpp"
-#include "identity-storage.hpp"
-
-namespace ndn
-{
-
-/**
- * BasicIdentityStorage extends IdentityStorage to implement a basic storage of identity, public keys and certificates
- * using SQLite.
- */
-class BasicIdentityStorage : public IdentityStorage {
-public:
- BasicIdentityStorage();
-
- /**
- * The virtual Destructor.
- */
- virtual
- ~BasicIdentityStorage();
-
- /**
- * Check if the specified identity already exists.
- * @param identityName The identity name.
- * @return true if the identity exists, otherwise false.
- */
- virtual bool
- doesIdentityExist(const Name& identityName);
-
- /**
- * Add a new identity. An exception will be thrown if the identity already exists.
- * @param identityName The identity name to be added.
- */
- virtual void
- addIdentity(const Name& identityName);
-
- /**
- * Revoke the identity.
- * @return true if the identity was revoked, false if not.
- */
- virtual bool
- revokeIdentity();
-
- /**
- * Generate a name for a new key belonging to the identity.
- * @param identityName The identity name.
- * @param useKsk If true, generate a KSK name, otherwise a DSK name.
- * @return The generated key name.
- */
- virtual Name
- getNewKeyName(const Name& identityName, bool useKsk);
-
- /**
- * Check if the specified key already exists.
- * @param keyName The name of the key.
- * @return true if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName);
-
- /**
- * Extract the key name from the certificate name.
- * @param certificateName The certificate name to be processed.
- */
- virtual Name
- getKeyNameForCertificate(const Name& certificateName);
-
- /**
- * Add a public key to the identity storage.
- * @param keyName The name of the public key to be added.
- * @param keyType Type of the public key to be added.
- * @param publicKeyDer A blob of the public key DER to be added.
- */
- virtual void
- addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer);
-
- /**
- * Get the public key DER blob from the identity storage.
- * @param keyName The name of the requested public key.
- * @return The DER Blob. If not found, return a Blob with a null pointer.
- */
- virtual Blob
- getKey(const Name& keyName);
-
- /**
- * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- activateKey(const Name& keyName);
-
- /**
- * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- deactivateKey(const Name& keyName);
-
- /**
- * Check if the specified certificate already exists.
- * @param certificateName The name of the certificate.
- * @return true if the certificate exists, otherwise false.
- */
- virtual bool
- doesCertificateExist(const Name& certificateName);
-
- /**
- * Add a certificate in to the identity storage without checking if the identity and key exists.
- * @param certificate The certificate to be added.
- */
- void
- addAnyCertificate (const Certificate& certificate);
-
- /**
- * Add a certificate to the identity storage.
- * @param certificate The certificate to be added.
- */
- virtual void
- addCertificate(const Certificate& certificate);
-
- /**
- * Get a certificate from the identity storage.
- * @param certificateName The name of the requested certificate.
- * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
- * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
- */
- virtual ptr_lib::shared_ptr<Certificate>
- getCertificate(const Name &certificateName, bool allowAny = false);
-
-
- /*****************************************
- * Get/Set Default *
- *****************************************/
-
- /**
- * Get the default identity.
- * @param return The name of default identity, or an empty name if there is no default.
- */
- virtual Name
- getDefaultIdentity();
-
- /**
- * Get the default key name for the specified identity.
- * @param identityName The identity name.
- * @return The default key name.
- */
- virtual Name
- getDefaultKeyNameForIdentity(const Name& identityName);
-
- /**
- * Get the default certificate name for the specified key.
- * @param keyName The key name.
- * @return The default certificate name.
- */
- virtual Name
- getDefaultCertificateNameForKey(const Name& keyName);
-
- /**
- * Set the default identity. If the identityName does not exist, then clear the default identity
- * so that getDefaultIdentity() returns an empty name.
- * @param identityName The default identity name.
- */
- virtual void
- setDefaultIdentity(const Name& identityName);
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param identityNameCheck (optional) The identity name to check the keyName.
- */
- virtual void
- setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name());
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param certificateName The certificate name.
- */
- virtual void
- setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
-
-private:
-
- virtual void
- updateKeyStatus(const Name& keyName, bool isActive);
-
- sqlite3 *database_;
-#if 0
- Time lastUpdated_;
-#endif
-};
-
-}
-
-#endif // NDN_CPP_HAVE_SQLITE3
-
-#endif
diff --git a/ndn-cpp/security/identity/identity-manager.cpp b/ndn-cpp/security/identity/identity-manager.cpp
index e669a20..e07b483 100644
--- a/ndn-cpp/security/identity/identity-manager.cpp
+++ b/ndn-cpp/security/identity/identity-manager.cpp
@@ -1,3 +1,4 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Yingdi Yu <yingdi@cs.ucla.edu>
@@ -9,9 +10,9 @@
#include <stdexcept>
#endif
#include "../../util/logging.hpp"
-#include "../../sha256-with-rsa-signature.hpp"
-#include "../security-exception.hpp"
-#include "identity-manager.hpp"
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/security-exception.hpp>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/identity/identity-manager.hpp b/ndn-cpp/security/identity/identity-manager.hpp
deleted file mode 100644
index c53607f..0000000
--- a/ndn-cpp/security/identity/identity-manager.hpp
+++ /dev/null
@@ -1,226 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_IDENTITY_MANAGER_HPP
-#define NDN_IDENTITY_MANAGER_HPP
-
-#include "../certificate/certificate.hpp"
-#include "identity-storage.hpp"
-#include "../certificate/public-key.hpp"
-#include "private-key-storage.hpp"
-
-namespace ndn {
-
-/**
- * An IdentityManager is the interface of operations related to identity, keys, and certificates.
- */
-class IdentityManager {
-public:
- IdentityManager(const ptr_lib::shared_ptr<IdentityStorage>& identityStorage, const ptr_lib::shared_ptr<PrivateKeyStorage>& privateKeyStorage)
- : identityStorage_(identityStorage), privateKeyStorage_(privateKeyStorage)
- {
- }
-
- /**
- * Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK.
- * @param identityName The name of the identity.
- * @return The key name of the auto-generated KSK of the identity.
- */
- Name
- createIdentity(const Name& identityName);
-
- /**
- * Get the default identity.
- * @return The default identity name.
- */
- Name
- getDefaultIdentity()
- {
- return identityStorage_->getDefaultIdentity();
- }
-
- /**
- * Generate a pair of RSA keys for the specified identity.
- * @param identityName The name of the identity.
- * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK).
- * @param keySize The size of the key.
- * @return The generated key name.
- */
- Name
- generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048);
-
- /**
- * Set a key as the default key of an identity.
- * @param keyName The name of the key.
- * @param identityName the name of the identity. If not specified, the identity name is inferred from the keyName.
- */
- void
- setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name())
- {
- identityStorage_->setDefaultKeyNameForIdentity(keyName, identityName);
- }
-
- /**
- * Get the default key for an identity.
- * @param identityName the name of the identity. If omitted, the identity name is inferred from the keyName.
- * @return The default key name.
- */
- Name
- getDefaultKeyNameForIdentity(const Name& identityName = Name())
- {
- return identityStorage_->getDefaultKeyNameForIdentity(identityName);
- }
-
- /**
- * Generate a pair of RSA keys for the specified identity and set it as default key for the identity.
- * @param identityName The name of the identity.
- * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK).
- * @param keySize The size of the key.
- * @return The generated key name.
- */
- Name
- generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048);
-
- /**
- * Get the public key with the specified name.
- * @param keyName The name of the key.
- * @return The public key.
- */
- ptr_lib::shared_ptr<PublicKey>
- getPublicKey(const Name& keyName)
- {
- return PublicKey::fromDer(identityStorage_->getKey(keyName));
- }
-
- /**
- * Add a certificate into the public key identity storage.
- * @param certificate The certificate to to added.
- */
- void
- addCertificate(const Certificate& certificate)
- {
- identityStorage_->addCertificate(certificate);
- }
-
- /**
- * Set the certificate as the default for its corresponding key.
- * @param certificateName The name of the certificate.
- */
- void
- setDefaultCertificateForKey(const Name& certificateName);
-
- /**
- * Add a certificate into the public key identity storage and set the certificate as the default for its corresponding identity.
- * @param certificate The certificate to be added.
- */
- void
- addCertificateAsIdentityDefault(const Certificate& certificate);
-
- /**
- * Add a certificate into the public key identity storage and set the certificate as the default of its corresponding key.
- * certificate the certificate to be added
- */
- void
- addCertificateAsDefault(const Certificate& certificate)
- {
- identityStorage_->addCertificate(certificate);
- setDefaultCertificateForKey(certificate.getName());
- }
-
- /**
- * Get a certificate with the specified name.
- * @param certificateName The name of the requested certificate.
- * @return the requested certificate which is valid.
- */
- ptr_lib::shared_ptr<Certificate>
- getCertificate(const Name& certificateName)
- {
- return identityStorage_->getCertificate(certificateName, false);
- }
-
- /**
- * Get a certificate even if the certificate is not valid anymore.
- * @param certificateName The name of the requested certificate.
- * @return the requested certificate.
- */
- ptr_lib::shared_ptr<Certificate>
- getAnyCertificate(const Name& certificateName)
- {
- return identityStorage_->getCertificate(certificateName, true);
- }
-
- /**
- * Get the default certificate name for the specified identity, which will be used when signing is performed based on identity.
- * @param identityName The name of the specified identity.
- * @return The requested certificate name.
- */
- Name
- getDefaultCertificateNameForIdentity(const Name& identityName)
- {
- return identityStorage_->getDefaultCertificateNameForIdentity(identityName);
- }
-
- /**
- * Get the default certificate name of the default identity, which will be used when signing is based on identity and
- * the identity is not specified.
- * @return The requested certificate name.
- */
- Name
- getDefaultCertificateName()
- {
- return identityStorage_->getDefaultCertificateNameForIdentity(getDefaultIdentity());
- }
-
-#if 0
- /**
- * sign blob based on certificate name
- * @param blob the blob to be signed
- * @param certificateName the signing certificate name
- * @return the generated signature
- */
- Ptr<Signature>
- signByCertificate(const Blob& blob, const Name& certificateName);
-#endif
-
- /**
- * Sign data packet based on the certificate name.
- * Note: the caller must make sure the timestamp in data is correct, for example with
- * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
- * @param data The Data object to sign and update its signature.
- * @param certificateName The Name identifying the certificate which identifies the signing key.
- * @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted.
- */
- void
- signByCertificate(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
-
-private:
- /**
- * Generate a key pair for the specified identity.
- * @param identityName The name of the specified identity.
- * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK).
- * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
- * @param keySize The size of the key pair.
- * @return The name of the generated key.
- */
- Name
- generateKeyPair(const Name& identityName, bool isKsk = false, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048);
-
- /**
- * Generate a self-signed certificate for a public key.
- * @param keyName The name of the public key.
- * @return The generated certificate.
- */
- ptr_lib::shared_ptr<Certificate>
- selfSign(const Name& keyName);
-
- ptr_lib::shared_ptr<IdentityStorage> identityStorage_;
- ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/identity/identity-storage.hpp b/ndn-cpp/security/identity/identity-storage.hpp
deleted file mode 100644
index db6ab0e..0000000
--- a/ndn-cpp/security/identity/identity-storage.hpp
+++ /dev/null
@@ -1,200 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_IDENTITY_STORAGE_HPP
-#define NDN_IDENTITY_STORAGE_HPP
-
-#include "../../name.hpp"
-#include "../security-common.hpp"
-
-namespace ndn {
-
-class Certificate;
-class Data;
-
-/**
- * IdentityStorage is a base class for the storage of identity, public keys and certificates.
- * Private keys are stored in PrivateKeyStorage.
- * This is an abstract base class. A subclass must implement the methods.
- */
-class IdentityStorage {
-public:
- /**
- * The virtual Destructor.
- */
- virtual
- ~IdentityStorage() {}
-
- /**
- * Check if the specified identity already exists.
- * @param identityName The identity name.
- * @return true if the identity exists, otherwise false.
- */
- virtual bool
- doesIdentityExist(const Name& identityName) = 0;
-
- /**
- * Add a new identity. An exception will be thrown if the identity already exists.
- * @param identityName The identity name to be added.
- */
- virtual void
- addIdentity(const Name& identityName) = 0;
-
- /**
- * Revoke the identity.
- * @return true if the identity was revoked, false if not.
- */
- virtual bool
- revokeIdentity() = 0;
-
- /**
- * Generate a name for a new key belonging to the identity.
- * @param identityName The identity name.
- * @param useKsk If true, generate a KSK name, otherwise a DSK name.
- * @return The generated key name.
- */
- virtual Name
- getNewKeyName(const Name& identityName, bool useKsk) = 0;
-
- /**
- * Check if the specified key already exists.
- * @param keyName The name of the key.
- * @return true if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName) = 0;
-
- /**
- * Extract the key name from the certificate name.
- * @param certificateName The certificate name to be processed.
- */
- virtual Name
- getKeyNameForCertificate(const Name& certificateName) = 0;
-
- /**
- * Add a public key to the identity storage.
- * @param keyName The name of the public key to be added.
- * @param keyType Type of the public key to be added.
- * @param publicKeyDer A blob of the public key DER to be added.
- */
- virtual void
- addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0;
-
- /**
- * Get the public key DER blob from the identity storage.
- * @param keyName The name of the requested public key.
- * @return The DER Blob. If not found, return a Blob with a null pointer.
- */
- virtual Blob
- getKey(const Name& keyName) = 0;
-
- /**
- * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- activateKey(const Name& keyName) = 0;
-
- /**
- * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- deactivateKey(const Name& keyName) = 0;
-
- /**
- * Check if the specified certificate already exists.
- * @param certificateName The name of the certificate.
- * @return true if the certificate exists, otherwise false.
- */
- virtual bool
- doesCertificateExist(const Name& certificateName) = 0;
-
- /**
- * Add a certificate to the identity storage.
- * @param certificate The certificate to be added.
- */
- virtual void
- addCertificate(const Certificate& certificate) = 0;
-
- /**
- * Get a certificate from the identity storage.
- * @param certificateName The name of the requested certificate.
- * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
- * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
- */
- virtual ptr_lib::shared_ptr<Certificate>
- getCertificate(const Name &certificateName, bool allowAny = false) = 0;
-
-
- /*****************************************
- * Get/Set Default *
- *****************************************/
-
- /**
- * Get the default identity.
- * @param return The name of default identity, or an empty name if there is no default.
- */
- virtual Name
- getDefaultIdentity() = 0;
-
- /**
- * Get the default key name for the specified identity.
- * @param identityName The identity name.
- * @return The default key name.
- */
- virtual Name
- getDefaultKeyNameForIdentity(const Name& identityName) = 0;
-
- /**
- * Get the default certificate name for the specified identity.
- * @param identityName The identity name.
- * @return The default certificate name.
- */
- Name
- getDefaultCertificateNameForIdentity(const Name& identityName)
- {
- return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
- }
-
- /**
- * Get the default certificate name for the specified key.
- * @param keyName The key name.
- * @return The default certificate name.
- */
- virtual Name
- getDefaultCertificateNameForKey(const Name& keyName) = 0;
-
- /**
- * Set the default identity. If the identityName does not exist, then clear the default identity
- * so that getDefaultIdentity() returns an empty name.
- * @param identityName The default identity name.
- */
- virtual void
- setDefaultIdentity(const Name& identityName) = 0;
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param identityNameCheck (optional) The identity name to check the keyName.
- */
- virtual void
- setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param certificateName The certificate name.
- */
- virtual void
- setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/identity/memory-identity-storage.cpp b/ndn-cpp/security/identity/memory-identity-storage.cpp
index bc2bd34..97b18f4 100644
--- a/ndn-cpp/security/identity/memory-identity-storage.cpp
+++ b/ndn-cpp/security/identity/memory-identity-storage.cpp
@@ -9,8 +9,8 @@
#include <stdexcept>
#endif
#include <algorithm>
-#include "../security-exception.hpp"
-#include "memory-identity-storage.hpp"
+#include <ndn-cpp/security/security-exception.hpp>
+#include <ndn-cpp/security/identity/memory-identity-storage.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/identity/memory-identity-storage.hpp b/ndn-cpp/security/identity/memory-identity-storage.hpp
deleted file mode 100644
index ba0ea5a..0000000
--- a/ndn-cpp/security/identity/memory-identity-storage.hpp
+++ /dev/null
@@ -1,189 +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_MEMORY_IDENTITY_STORAGE_HPP
-#define NDN_MEMORY_IDENTITY_STORAGE_HPP
-
-#include <vector>
-#include "identity-storage.hpp"
-
-namespace ndn {
-
-/**
- * MemoryIdentityStorage extends IdentityStorage and implements its methods to store identity, public key and certificate objects in memory.
- * The application must get the objects through its own means and add the objects to the MemoryIdentityStorage object.
- * To use permanent file-based storage, see BasicIdentityStorage.
- */
-class MemoryIdentityStorage : public IdentityStorage {
-public:
- /**
- * The virtual Destructor.
- */
- virtual
- ~MemoryIdentityStorage();
-
- /**
- * Check if the specified identity already exists.
- * @param identityName The identity name.
- * @return true if the identity exists, otherwise false.
- */
- virtual bool
- doesIdentityExist(const Name& identityName);
-
- /**
- * Add a new identity. An exception will be thrown if the identity already exists.
- * @param identityName The identity name to be added.
- */
- virtual void
- addIdentity(const Name& identityName);
-
- /**
- * Revoke the identity.
- * @return true if the identity was revoked, false if not.
- */
- virtual bool
- revokeIdentity();
-
- /**
- * Generate a name for a new key belonging to the identity.
- * @param identityName The identity name.
- * @param useKsk If true, generate a KSK name, otherwise a DSK name.
- * @return The generated key name.
- */
- virtual Name
- getNewKeyName(const Name& identityName, bool useKsk);
-
- /**
- * Check if the specified key already exists.
- * @param keyName The name of the key.
- * @return true if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName);
-
- /**
- * Extract the key name from the certificate name.
- * @param certificateName The certificate name to be processed.
- */
- virtual Name
- getKeyNameForCertificate(const Name& certificateName);
-
- /**
- * Add a public key to the identity storage.
- * @param keyName The name of the public key to be added.
- * @param keyType Type of the public key to be added.
- * @param publicKeyDer A blob of the public key DER to be added.
- */
- virtual void
- addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer);
-
- /**
- * Get the public key DER blob from the identity storage.
- * @param keyName The name of the requested public key.
- * @return The DER Blob. If not found, return a Blob with a null pointer.
- */
- virtual Blob
- getKey(const Name& keyName);
-
- /**
- * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- activateKey(const Name& keyName);
-
- /**
- * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
- * @param keyName name of the key
- */
- virtual void
- deactivateKey(const Name& keyName);
-
- /**
- * Check if the specified certificate already exists.
- * @param certificateName The name of the certificate.
- * @return true if the certificate exists, otherwise false.
- */
- virtual bool
- doesCertificateExist(const Name& certificateName);
-
- /**
- * Add a certificate to the identity storage.
- * @param certificate The certificate to be added.
- */
- virtual void
- addCertificate(const Certificate& certificate);
-
- /**
- * Get a certificate from the identity storage.
- * @param certificateName The name of the requested certificate.
- * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
- * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
- */
- virtual ptr_lib::shared_ptr<Certificate>
- getCertificate(const Name &certificateName, bool allowAny = false);
-
-
- /*****************************************
- * Get/Set Default *
- *****************************************/
-
- /**
- * Get the default identity.
- * @param return The name of default identity, or an empty name if there is no default.
- */
- virtual Name
- getDefaultIdentity();
-
- /**
- * Get the default key name for the specified identity.
- * @param identityName The identity name.
- * @return The default key name.
- */
- virtual Name
- getDefaultKeyNameForIdentity(const Name& identityName);
-
- /**
- * Get the default certificate name for the specified key.
- * @param keyName The key name.
- * @return The default certificate name.
- */
- virtual Name
- getDefaultCertificateNameForKey(const Name& keyName);
-
- /**
- * Set the default identity. If the identityName does not exist, then clear the default identity
- * so that getDefaultIdentity() returns an empty name.
- * @param identityName The default identity name.
- */
- virtual void
- setDefaultIdentity(const Name& identityName);
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param identityNameCheck (optional) The identity name to check the keyName.
- */
- virtual void
- setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name());
-
- /**
- * Set the default key name for the specified identity.
- * @param keyName The key name.
- * @param certificateName The certificate name.
- */
- virtual void
- setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
-
-private:
- std::vector<std::string> identityStore_; /**< A list of name URI. */
- std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/identity/memory-private-key-storage.cpp b/ndn-cpp/security/identity/memory-private-key-storage.cpp
index af2ac13..09f1c66 100644
--- a/ndn-cpp/security/identity/memory-private-key-storage.cpp
+++ b/ndn-cpp/security/identity/memory-private-key-storage.cpp
@@ -9,8 +9,8 @@
#include <stdexcept>
#endif
#include "../../c/util/crypto.h"
-#include "../security-exception.hpp"
-#include "memory-private-key-storage.hpp"
+#include <ndn-cpp/security/security-exception.hpp>
+#include <ndn-cpp/security/identity/memory-private-key-storage.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/identity/memory-private-key-storage.hpp b/ndn-cpp/security/identity/memory-private-key-storage.hpp
deleted file mode 100644
index 02f8fbc..0000000
--- a/ndn-cpp/security/identity/memory-private-key-storage.hpp
+++ /dev/null
@@ -1,132 +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_MEMORY_PRIVATE_KEY_STORAGE_HPP
-#define NDN_MEMORY_PRIVATE_KEY_STORAGE_HPP
-
-#include <map>
-#include "private-key-storage.hpp"
-
-struct rsa_st;
-
-namespace ndn {
-
-/**
- * MemoryPrivateKeyStorage extends PrivateKeyStorage to implement a simple in-memory private key store. You should
- * initialize by calling setKeyPairForKeyName.
- */
-class MemoryPrivateKeyStorage : public PrivateKeyStorage {
-public:
- /**
- * The virtual destructor
- */
- virtual
- ~MemoryPrivateKeyStorage();
-
- /**
- * Set the public and private key for the keyName.
- * @param keyName The key name.
- * @param publicKeyDer The public key DER byte array.
- * @param publicKeyDerLength The length of publicKeyDer.
- * @param privateKeyDer The private key DER byte array.
- * @param privateKeyDerLength The length of privateKeyDer.
- */
- void setKeyPairForKeyName
- (const Name& keyName, uint8_t *publicKeyDer, size_t publicKeyDerLength, uint8_t *privateKeyDer,
- size_t privateKeyDerLength);
-
- /**
- * Generate a pair of asymmetric keys.
- * @param keyName The name of the key pair.
- * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
- * @param keySize The size of the key pair.
- */
- virtual void
- generateKeyPair(const Name& keyName, KeyType keyType, int keySize);
-
- /**
- * Get the public key
- * @param keyName The name of public key.
- * @return The public key.
- */
- virtual ptr_lib::shared_ptr<PublicKey>
- getPublicKey(const Name& keyName);
-
- /**
- * Fetch the private key for keyName and sign the data, returning a signature Blob.
- * @param data Pointer to the input byte array.
- * @param dataLength The length of data.
- * @param keyName The name of the signing key.
- * @param digestAlgorithm the digest algorithm.
- * @return The signature, or a null pointer if signing fails.
- */
- virtual Blob
- sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
-
- /**
- * Decrypt data.
- * @param keyName The name of the decrypting key.
- * @param data The byte to be decrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The decrypted data.
- */
- virtual Blob
- decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
-
- /**
- * Encrypt data.
- * @param keyName The name of the encrypting key.
- * @param data The byte to be encrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The encrypted data.
- */
- virtual Blob
- encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
-
- /**
- * @brief Generate a symmetric key.
- * @param keyName The name of the key.
- * @param keyType The type of the key, e.g. KEY_TYPE_AES.
- * @param keySize The size of the key.
- */
- virtual void
- generateKey(const Name& keyName, KeyType keyType, int keySize);
-
- /**
- * Check if a particular key exists.
- * @param keyName The name of the key.
- * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
- * @return True if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName, KeyClass keyClass);
-
-private:
- /**
- * RsaPrivateKey is a simple class to hold an RSA private key.
- */
- class RsaPrivateKey {
- public:
- RsaPrivateKey(uint8_t *keyDer, size_t keyDerLength);
-
- ~RsaPrivateKey();
-
- struct rsa_st* getPrivateKey() { return privateKey_; }
-
- private:
- struct rsa_st* privateKey_;
- };
-
- std::map<std::string, ptr_lib::shared_ptr<PublicKey> > publicKeyStore_; /**< The map key is the keyName.toUri() */
- std::map<std::string, ptr_lib::shared_ptr<RsaPrivateKey> > privateKeyStore_; /**< The map key is the keyName.toUri() */
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/identity/osx-private-key-storage.cpp b/ndn-cpp/security/identity/osx-private-key-storage.cpp
index 5cca7ca..5728ad7 100644
--- a/ndn-cpp/security/identity/osx-private-key-storage.cpp
+++ b/ndn-cpp/security/identity/osx-private-key-storage.cpp
@@ -14,8 +14,8 @@
#include <CoreFoundation/CoreFoundation.h>
#include "../../util/logging.hpp"
-#include "osx-private-key-storage.hpp"
-#include "../security-exception.hpp"
+#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
+#include <ndn-cpp/security/security-exception.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/identity/osx-private-key-storage.hpp b/ndn-cpp/security/identity/osx-private-key-storage.hpp
deleted file mode 100644
index 729bf9e..0000000
--- a/ndn-cpp/security/identity/osx-private-key-storage.hpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_OSX_PRIVATEKEY_STORAGE_H
-#define NDN_OSX_PRIVATEKEY_STORAGE_H
-
-// Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_OSX_SECURITY 1.
-#include <ndn-cpp/ndn-cpp-config.h>
-#if NDN_CPP_HAVE_OSX_SECURITY
-
-#include "../../common.hpp"
-#include "private-key-storage.hpp"
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <Security/Security.h>
-#include <CoreServices/CoreServices.h>
-
-namespace ndn
-{
-
-class OSXPrivateKeyStorage : public PrivateKeyStorage {
-public:
- /**
- * constructor of OSXPrivateKeyStorage
- * @param keychainName the name of keychain
- */
- OSXPrivateKeyStorage(const std::string & keychainName = "");
-
- /**
- * destructor of OSXPrivateKeyStore
- */
- virtual
- ~OSXPrivateKeyStorage();
-
- /**
- * Generate a pair of asymmetric keys.
- * @param keyName The name of the key pair.
- * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
- * @param keySize The size of the key pair.
- */
- virtual void
- generateKeyPair(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048);
-
- /**
- * Get the public key
- * @param keyName The name of public key.
- * @return The public key.
- */
- virtual ptr_lib::shared_ptr<PublicKey>
- getPublicKey(const Name& keyName);
-
- /**
- * Fetch the private key for keyName and sign the data, returning a signature Blob.
- * @param data Pointer to the input byte array.
- * @param dataLength The length of data.
- * @param keyName The name of the signing key.
- * @param digestAlgorithm the digest algorithm.
- * @return The signature, or a null pointer if signing fails.
- */
- virtual Blob
- sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
-
- /**
- * Decrypt data.
- * @param keyName The name of the decrypting key.
- * @param data The byte to be decrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The decrypted data.
- */
- virtual Blob
- decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false);
-
- /**
- * Encrypt data.
- * @param keyName The name of the encrypting key.
- * @param data The byte to be encrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The encrypted data.
- */
- virtual Blob
- encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false);
-
- /**
- * Generate a symmetric key.
- * @param keyName The name of the key.
- * @param keyType The type of the key, e.g. KEY_TYPE_AES.
- * @param keySize The size of the key.
- */
- virtual void
- generateKey(const Name& keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256);
-
- /**
- * Check if a particular key exists.
- * @param keyName The name of the key.
- * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
- * @return True if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName, KeyClass keyClass);
-
- /**
- * configure ACL of a particular key
- * @param keyName the name of key
- * @param keyClass the class of key, e.g. Private Key
- * @param acl the new acl of the key
- * @param appPath the absolute path to the application
- * @returns true if setting succeeds
- */
- bool
- setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath);
-
- /**
- * verify data (test only)
- * @param keyName the name of key
- * @param pData the data to be verified
- * @param pSig the signature associated with the data
- * @param digestAlgo digest algorithm
- * @return true if signature can be verified, otherwise false
- */
- bool
- verifyData(const Name & keyName, const Blob & pData, const Blob & pSig, DigestAlgorithm digestAlgo = DIGEST_ALGORITHM_SHA256);
-
- private:
- /**
- * convert NDN name of a key to internal name of the key
- * @param keyName the NDN name of the key
- * @param keyClass the class of the key
- * @return the internal key name
- */
- std::string
- toInternalKeyName(const Name & keyName, KeyClass keyClass);
-
- /**
- * Get key
- * @param keyName the name of the key
- * @param keyClass the class of the key
- * @returns pointer to the key
- */
- SecKeychainItemRef
- getKey(const Name & keyName, KeyClass keyClass);
-
- /**
- * convert keyType to MAC OS symmetric key key type
- * @param keyType
- * @returns MAC OS key type
- */
- const CFTypeRef
- getSymKeyType(KeyType keyType);
-
- /**
- * convert keyType to MAC OS asymmetirc key type
- * @param keyType
- * @returns MAC OS key type
- */
- const CFTypeRef
- getAsymKeyType(KeyType keyType);
-
- /**
- * convert keyClass to MAC OS key class
- * @param keyClass
- * @returns MAC OS key class
- */
- const CFTypeRef
- getKeyClass(KeyClass keyClass);
-
- /**
- * convert digestAlgo to MAC OS algorithm id
- * @param digestAlgo
- * @returns MAC OS algorithm id
- */
- const CFStringRef
- getDigestAlgorithm(DigestAlgorithm digestAlgo);
-
- /**
- * convert format to MAC OS key format
- * @param format
- * @returns MAC OS keyformat
- */
- SecExternalFormat
- getFormat(KeyFormat format);
-
- /**
- * get the digest size of the corresponding algorithm
- * @param digestAlgo the digest algorithm
- * @return digest size
- */
- long
- getDigestSize(DigestAlgorithm digestAlgo);
-
- const std::string keyChainName_;
- SecKeychainRef keyChainRef_;
- SecKeychainRef originalDefaultKeyChain_;
-};
-
-}
-
-#endif NDN_CPP_HAVE_OSX_SECURITY
-
-#endif
diff --git a/ndn-cpp/security/identity/private-key-storage.hpp b/ndn-cpp/security/identity/private-key-storage.hpp
deleted file mode 100644
index 0ff0077..0000000
--- a/ndn-cpp/security/identity/private-key-storage.hpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_PRIVATE_KEY_STORAGE_HPP
-#define NDN_PRIVATE_KEY_STORAGE_HPP
-
-#include <string>
-#include "../../util/blob.hpp"
-#include "../certificate/public-key.hpp"
-#include "../security-common.hpp"
-#include "../../name.hpp"
-
-namespace ndn {
-
-class PrivateKeyStorage {
-public:
- /**
- * The virtual destructor.
- */
- virtual
- ~PrivateKeyStorage() {}
-
- /**
- * Generate a pair of asymmetric keys.
- * @param keyName The name of the key pair.
- * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
- * @param keySize The size of the key pair.
- */
- virtual void
- generateKeyPair(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) = 0;
-
- /**
- * Get the public key
- * @param keyName The name of public key.
- * @return The public key.
- */
- virtual ptr_lib::shared_ptr<PublicKey>
- getPublicKey(const Name& keyName) = 0;
-
- /**
- * Fetch the private key for keyName and sign the data, returning a signature Blob.
- * @param data Pointer to the input byte array.
- * @param dataLength The length of data.
- * @param keyName The name of the signing key.
- * @param digestAlgorithm the digest algorithm.
- * @return The signature, or a null pointer if signing fails.
- */
- virtual Blob
- sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) = 0;
-
- Blob
- sign(const Blob& data, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
- {
- sign(data.buf(), data.size(), keyName, digestAlgorithm);
- }
-
- /**
- * Decrypt data.
- * @param keyName The name of the decrypting key.
- * @param data The byte to be decrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The decrypted data.
- */
- virtual Blob
- decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
-
- Blob
- decrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
- {
- decrypt(keyName, data.buf(), data.size(), isSymmetric);
- }
-
- /**
- * Encrypt data.
- * @param keyName The name of the encrypting key.
- * @param data The byte to be encrypted.
- * @param dataLength the length of data.
- * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
- * @return The encrypted data.
- */
- virtual Blob
- encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
-
- Blob
- encrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
- {
- encrypt(keyName, data.buf(), data.size(), isSymmetric);
- }
-
- /**
- * @brief Generate a symmetric key.
- * @param keyName The name of the key.
- * @param keyType The type of the key, e.g. KEY_TYPE_AES.
- * @param keySize The size of the key.
- */
- virtual void
- generateKey(const Name& keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256) = 0;
-
- /**
- * Check if a particular key exists.
- * @param keyName The name of the key.
- * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
- * @return True if the key exists, otherwise false.
- */
- virtual bool
- doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/key-chain.cpp b/ndn-cpp/security/key-chain.cpp
index 5bcc4c1..3f47e3e 100644
--- a/ndn-cpp/security/key-chain.cpp
+++ b/ndn-cpp/security/key-chain.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -7,11 +8,11 @@
#include "../c/util/crypto.h"
#include "../c/encoding/binary-xml-data.h"
#include "../encoding/binary-xml-encoder.hpp"
-#include "../sha256-with-rsa-signature.hpp"
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
#include "../util/logging.hpp"
-#include "policy/policy-manager.hpp"
-#include "security-exception.hpp"
-#include "key-chain.hpp"
+#include <ndn-cpp/security/security-exception.hpp>
+#include <ndn-cpp/security/policy/policy-manager.hpp>
+#include <ndn-cpp/security/key-chain.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/key-chain.hpp b/ndn-cpp/security/key-chain.hpp
deleted file mode 100644
index 7114e4e..0000000
--- a/ndn-cpp/security/key-chain.hpp
+++ /dev/null
@@ -1,284 +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_CHAIN_HPP
-#define NDN_KEY_CHAIN_HPP
-
-#include "../data.hpp"
-#include "../face.hpp"
-#include "identity/identity-manager.hpp"
-#include "encryption/encryption-manager.hpp"
-
-namespace ndn {
-
-class PolicyManager;
-
-/**
- * An OnVerified function object is used to pass a callback to verifyData to report a successful verification.
- */
-typedef func_lib::function<void(const ptr_lib::shared_ptr<Data>& data)> OnVerified;
-
-/**
- * An OnVerifyFailed function object is used to pass a callback to verifyData to report a failed verification.
- */
-typedef func_lib::function<void(const ptr_lib::shared_ptr<Data>& data)> OnVerifyFailed;
-
-/**
- * Keychain is the main class of the security library.
- *
- * The Keychain class provides a set of interfaces to the security library such as identity management, policy configuration
- * and packet signing and verification.
- */
-class KeyChain {
-public:
- KeyChain
- (const ptr_lib::shared_ptr<IdentityManager>& identityManager, const ptr_lib::shared_ptr<PolicyManager>& policyManager);
-
- /*****************************************
- * Identity Management *
- *****************************************/
-
- /**
- * Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK.
- * @param identityName The name of the identity.
- * @return The key name of the auto-generated KSK of the identity.
- */
- Name
- createIdentity(const Name& identityName)
- {
- return identityManager_->createIdentity(identityName);
- }
-
- /**
- * Get the default identity.
- * @return The default identity name.
- */
- Name
- getDefaultIdentity()
- {
- return identityManager_->getDefaultIdentity();
- }
-
- /**
- * Generate a pair of RSA keys for the specified identity.
- * @param identityName The name of the identity.
- * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK).
- * @param keySize The size of the key.
- * @return The generated key name.
- */
- Name
- generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048)
- {
- return identityManager_->generateRSAKeyPair(identityName, isKsk, keySize);
- }
-
- /**
- * Set a key as the default key of an identity.
- * @param keyName The name of the key.
- * @param identityName the name of the identity. If not specified, the identity name is inferred from the keyName.
- */
- void
- setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name())
- {
- return identityManager_->setDefaultKeyForIdentity(keyName, identityName);
- }
-
- /**
- * Generate a pair of RSA keys for the specified identity and set it as default key for the identity.
- * @param identityName The name of the identity.
- * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK).
- * @param keySize The size of the key.
- * @return The generated key name.
- */
- Name
- generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048)
- {
- return identityManager_->generateRSAKeyPairAsDefault(identityName, isKsk, keySize);
- }
-
- /**
- * Create a public key signing request.
- * @param keyName The name of the key.
- * @returns The signing request data.
- */
- Blob
- createSigningRequest(const Name& keyName)
- {
- return identityManager_->getPublicKey(keyName)->getKeyDer();
- }
-
- /**
- * Install an identity certificate into the public key identity storage.
- * @param certificate The certificate to to added.
- */
- void
- installIdentityCertificate(const Certificate& certificate)
- {
- identityManager_->addCertificate(certificate);
- }
-
- /**
- * Set the certificate as the default for its corresponding key.
- * @param certificateName The name of the certificate.
- */
- void
- setDefaultCertificateForKey(const Name& certificateName)
- {
- identityManager_->setDefaultCertificateForKey(certificateName);
- }
-
- /**
- * Get a certificate with the specified name.
- * @param certificateName The name of the requested certificate.
- * @return the requested certificate.
- */
- ptr_lib::shared_ptr<Certificate>
- getCertificate(const Name& certificateName)
- {
- return identityManager_->getCertificate(certificateName);
- }
-
- /**
- * Get a certificate even if the certificate is not valid anymore.
- * @param certificateName The name of the requested certificate.
- * @return the requested certificate.
- */
- ptr_lib::shared_ptr<Certificate>
- getAnyCertificate(const Name& certificateName)
- {
- return identityManager_->getAnyCertificate(certificateName);
- }
-
- /**
- * Revoke a key
- * @param keyName the name of the key that will be revoked
- */
- void
- revokeKey(const Name & keyName)
- {
- //TODO: Implement
- }
-
- /**
- * Revoke a certificate
- * @param certificateName the name of the certificate that will be revoked
- */
- void
- revokeCertificate(const Name & certificateName)
- {
- //TODO: Implement
- }
-
- /*****************************************
- * Policy Management *
- *****************************************/
-
- const ptr_lib::shared_ptr<PolicyManager>&
- getPolicyManager() { return policyManager_; }
-
- /*****************************************
- * Sign/Verify *
- *****************************************/
-
- /**
- * Wire encode the Data object, sign it and set its signature.
- * Note: the caller must make sure the timestamp is correct, for example with
- * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
- * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding.
- * @param certificateName The certificate name of the key to use for signing. If omitted, infer the signing identity from the data packet name.
- * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
- */
- void
- sign(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
-
- /**
- * Wire encode the Data object, sign it and set its signature.
- * Note: the caller must make sure the timestamp is correct, for example with
- * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
- * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding.
- * @param identityName The identity name for the key to use for signing. If omitted, infer the signing identity from the data packet name.
- * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
- */
- void
- signByIdentity(Data& data, const Name& identityName = Name(), WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
-
- /**
- * Check the signature on the Data object and call either onVerify or onVerifyFailed.
- * We use callback functions because verify may fetch information to check the signature.
- * @param data The Data object with the signature to check. It is an error if data does not have a wireEncoding.
- * To set the wireEncoding, you can call data.wireDecode.
- * @param onVerified If the signature is verified, this calls onVerified(data).
- * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data).
- */
- void
- verifyData
- (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed, int stepCount = 0);
-
- /*****************************************
- * Encrypt/Decrypt *
- *****************************************/
-
- /**
- * Generate a symmetric key.
- * @param keyName The name of the generated key.
- * @param keyType The type of the key, e.g. KEY_TYPE_AES
- */
- void
- generateSymmetricKey(const Name& keyName, KeyType keyType)
- {
- encryptionManager_->createSymmetricKey(keyName, keyType);
- }
-
- /**
- * Encrypt a byte array.
- * @param keyName The name of the encrypting key.
- * @param data The byte array that will be encrypted.
- * @param dataLength The length of data.
- * @param useSymmetric If true then symmetric encryption is used, otherwise asymmetric encryption is used.
- * @param encryptMode the encryption mode
- * @return the encrypted data as an immutable Blob.
- */
- Blob
- encrypt(const Name &keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = true,
- EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT)
- {
- return encryptionManager_->encrypt(keyName, data, dataLength, useSymmetric, encryptMode);
- }
-
- /**
- * Decrypt a byte array.
- * @param keyName The name of the decrypting key.
- * @param data The byte array that will be decrypted.
- * @param dataLength The length of data.
- * @param useSymmetric If true then symmetric encryption is used, otherwise asymmetric encryption is used.
- * @param encryptMode the encryption mode
- * @return the decrypted data as an immutable Blob.
- */
- Blob
- decrypt(const Name &keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = true,
- EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT)
- {
- return encryptionManager_->decrypt(keyName, data, dataLength, useSymmetric, encryptMode);
- }
-
- /**
- * Set the Face which will be used to fetch required certificates.
- * @param face A pointer to the Face object.
- */
- void
- setFace(Face* face) { face_ = face; }
-
-private:
- ptr_lib::shared_ptr<IdentityManager> identityManager_;
- ptr_lib::shared_ptr<PolicyManager> policyManager_;
- ptr_lib::shared_ptr<EncryptionManager> encryptionManager_;
- Face* face_;
- const int maxSteps_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/policy/no-verify-policy-manager.cpp b/ndn-cpp/security/policy/no-verify-policy-manager.cpp
index 172845e..e49ae75 100644
--- a/ndn-cpp/security/policy/no-verify-policy-manager.cpp
+++ b/ndn-cpp/security/policy/no-verify-policy-manager.cpp
@@ -6,7 +6,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "no-verify-policy-manager.hpp"
+#include <ndn-cpp/security/policy/no-verify-policy-manager.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/security/policy/no-verify-policy-manager.hpp b/ndn-cpp/security/policy/no-verify-policy-manager.hpp
deleted file mode 100644
index 8b72eda..0000000
--- a/ndn-cpp/security/policy/no-verify-policy-manager.hpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_NO_VERIFY_POLICY_MANAGER_HPP
-#define NDN_NO_VERIFY_POLICY_MANAGER_HPP
-
-#include "policy-manager.hpp"
-
-namespace ndn {
-
-class NoVerifyPolicyManager : public PolicyManager {
-public:
- /**
- * The virtual destructor.
- */
- virtual
- ~NoVerifyPolicyManager();
-
- /**
- * Override to always skip verification and trust as valid.
- * @param data The received data packet.
- * @return true.
- */
- virtual bool
- skipVerifyAndTrust(const Data& data);
-
- /**
- * Override to return false for no verification rule for the received data.
- * @param data The received data packet.
- * @return false.
- */
- virtual bool
- requireVerify(const Data& data);
-
- /**
- * Override to call onVerified(data) and to indicate no further verification step.
- * @param data The Data object with the signature to check.
- * @param stepCount The number of verification steps that have been done, used to track the verification progress.
- * @param onVerified This does override to call onVerified(data).
- * @param onVerifyFailed Override to ignore this.
- * @return null for no further step.
- */
- virtual ptr_lib::shared_ptr<ValidationRequest>
- checkVerificationPolicy
- (const ptr_lib::shared_ptr<Data>& data, const int& stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed);
-
- /**
- * Override to always indicate that the signing certificate name and data name satisfy the signing policy.
- * @param dataName The name of data to be signed.
- * @param certificateName The name of signing certificate.
- * @return true to indicate that the signing certificate can be used to sign the data.
- */
- virtual bool
- checkSigningPolicy(const Name& dataName, const Name& certificateName);
-
- /**
- * Override to indicate that the signing identity cannot be inferred.
- * @param dataName The name of data to be signed.
- * @return An empty name because cannot infer.
- */
- virtual Name
- inferSigningIdentity(const Name& dataName);
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/policy/policy-manager.hpp b/ndn-cpp/security/policy/policy-manager.hpp
deleted file mode 100644
index 458f84f..0000000
--- a/ndn-cpp/security/policy/policy-manager.hpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_POLICY_MANAGER_HPP
-#define NDN_POLICY_MANAGER_HPP
-
-#include "../../data.hpp"
-#include "../key-chain.hpp"
-
-namespace ndn {
-
-class ValidationRequest;
-
-/**
- * A PolicyManager is an abstract base class to represent the policy for verifying data packets.
- * You must create an object of a subclass.
- */
-class PolicyManager {
-public:
- /**
- * The virtual destructor.
- */
- virtual
- ~PolicyManager() {}
-
- /**
- * Check if the received data packet can escape from verification and be trusted as valid.
- * @param data The received data packet.
- * @return true if the data does not need to be verified to be trusted as valid, otherwise false.
- */
- virtual bool
- skipVerifyAndTrust(const Data& data) = 0;
-
- /**
- * Check if this PolicyManager has a verification rule for the received data.
- * @param data The received data packet.
- * @return true if the data must be verified, otherwise false.
- */
- virtual bool
- requireVerify(const Data& data) = 0;
-
- /**
- * Check whether the received data packet complies with the verification policy, and get the indication of the next verification step.
- * @param data The Data object with the signature to check.
- * @param stepCount The number of verification steps that have been done, used to track the verification progress.
- * @param onVerified If the signature is verified, this calls onVerified(data).
- * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data).
- * @return the indication of next verification step, null if there is no further step.
- */
- virtual ptr_lib::shared_ptr<ValidationRequest>
- checkVerificationPolicy
- (const ptr_lib::shared_ptr<Data>& data, const int& stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed) = 0;
-
- /**
- * Check if the signing certificate name and data name satisfy the signing policy.
- * @param dataName The name of data to be signed.
- * @param certificateName The name of signing certificate.
- * @return true if the signing certificate can be used to sign the data, otherwise false.
- */
- virtual bool
- checkSigningPolicy(const Name& dataName, const Name& certificateName) = 0;
-
- /**
- * Infer the signing identity name according to the policy. If the signing identity cannot be inferred, return an empty name.
- * @param dataName The name of data to be signed.
- * @return The signing identity or an empty name if cannot infer.
- */
- virtual Name
- inferSigningIdentity(const Name& dataName) = 0;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/security-common.hpp b/ndn-cpp/security/security-common.hpp
deleted file mode 100644
index 1222480..0000000
--- a/ndn-cpp/security/security-common.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_SECURITY_COMMON_HPP
-#define NDN_SECURITY_COMMON_HPP
-
-namespace ndn {
-
-enum KeyType {
- KEY_TYPE_RSA,
- // KEY_TYPE_DSA,
- KEY_TYPE_AES,
- // KEY_TYPE_DES,
- // KEY_TYPE_RC4,
- // KEY_TYPE_RC2
-};
-
-enum KeyClass {
- KEY_CLASS_PUBLIC,
- KEY_CLASS_PRIVATE,
- KEY_CLASS_SYMMETRIC
-};
-
-enum KeyFormat {
- KEY_FORMAT_PUBLIC_OPENSSL,
-};
-
-enum DigestAlgorithm {
- // DIGEST_ALGORITHM_MD2,
- // DIGEST_ALGORITHM_MD5,
- // DIGEST_ALGORITHM_SHA1,
- DIGEST_ALGORITHM_SHA256
-};
-
-enum EncryptMode {
- ENCRYPT_MODE_DEFAULT,
- ENCRYPT_MODE_CFB_AES,
- // ENCRYPT_MODE_CBC_AES
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/security/security-exception.cpp b/ndn-cpp/security/security-exception.cpp
index b4bbd22..b4acfad 100644
--- a/ndn-cpp/security/security-exception.cpp
+++ b/ndn-cpp/security/security-exception.cpp
@@ -6,7 +6,7 @@
* See COPYING for copyright and distribution information.
*/
-#include "security-exception.hpp"
+#include <ndn-cpp/security/security-exception.hpp>
using namespace std;
namespace ndn {
diff --git a/ndn-cpp/security/security-exception.hpp b/ndn-cpp/security/security-exception.hpp
deleted file mode 100644
index f14948f..0000000
--- a/ndn-cpp/security/security-exception.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: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_SECURITY_EXCEPTION_HPP
-#define NDN_SECURITY_EXCEPTION_HPP
-
-#include <exception>
-#include <string>
-
-namespace ndn {
-
-class SecurityException : public std::exception {
-public:
- SecurityException(const std::string& errorMessage) throw();
-
- virtual ~SecurityException() throw();
-
- std::string Msg() { return errorMessage_; }
-
- virtual const char* what() const throw() { return errorMessage_.c_str(); }
-
-private:
- const std::string errorMessage_;
-};
-
-class UnrecognizedKeyFormatException : public SecurityException {
-public:
- UnrecognizedKeyFormatException(const std::string& errorMessage)
- : SecurityException(errorMessage)
- {
- }
-};
-
-class UnrecognizedDigestAlgorithmException : public SecurityException {
-public:
- UnrecognizedDigestAlgorithmException(const std::string& errorMessage)
- : SecurityException(errorMessage)
- {
- }
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/sha256-with-rsa-signature.cpp b/ndn-cpp/sha256-with-rsa-signature.cpp
index 3153551..bf4dfa6 100644
--- a/ndn-cpp/sha256-with-rsa-signature.cpp
+++ b/ndn-cpp/sha256-with-rsa-signature.cpp
@@ -1,10 +1,12 @@
+/* -*- 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 "sha256-with-rsa-signature.hpp"
+#include "c/data.h"
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
using namespace std;
using namespace ndn::ptr_lib;
diff --git a/ndn-cpp/sha256-with-rsa-signature.hpp b/ndn-cpp/sha256-with-rsa-signature.hpp
deleted file mode 100644
index 2d5c4ce..0000000
--- a/ndn-cpp/sha256-with-rsa-signature.hpp
+++ /dev/null
@@ -1,131 +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_SHA256_WITH_RSA_SIGNATURE_HPP
-#define NDN_SHA256_WITH_RSA_SIGNATURE_HPP
-
-#include "data.hpp"
-#include "key.hpp"
-#include "publisher-public-key-digest.hpp"
-
-namespace ndn {
-
-/**
- * A Sha256WithRsaSignature extends Signature and holds the signature bits and other info representing a
- * SHA256-with-RSA signature in a data packet.
- */
-class Sha256WithRsaSignature : public Signature {
-public:
- /**
- * Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
- */
- virtual ptr_lib::shared_ptr<Signature>
- clone() const;
-
- /**
- * Set the signatureStruct to point to the values in this signature object, without copying any memory.
- * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
- * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
- */
- virtual void
- get(struct ndn_Signature& signatureStruct) const;
-
- /**
- * Clear this signature, and set the values by copying from the ndn_Signature struct.
- * @param signatureStruct a C ndn_Signature struct
- */
- virtual void
- set(const struct ndn_Signature& signatureStruct);
-
- const Blob&
- getDigestAlgorithm() const { return digestAlgorithm_; }
-
- const Blob&
- getWitness() const { return witness_; }
-
- const Blob&
- getSignature() const { return signature_; }
-
- const PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
-
- PublisherPublicKeyDigest&
- getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
- const KeyLocator&
- getKeyLocator() const { return keyLocator_; }
-
- KeyLocator&
- getKeyLocator() { return keyLocator_; }
-
- void
- setDigestAlgorithm(const std::vector<uint8_t>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
-
- void
- setDigestAlgorithm(const uint8_t *digestAlgorithm, size_t digestAlgorithmLength)
- {
- digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
- }
-
- void
- setWitness(const std::vector<uint8_t>& witness) { witness_ = witness; }
-
- void
- setWitness(const uint8_t *witness, size_t witnessLength)
- {
- witness_ = Blob(witness, witnessLength);
- }
-
- void
- setSignature(const std::vector<uint8_t>& signature) { signature_ = signature; }
-
- void
- setSignature(const uint8_t *signature, size_t signatureLength)
- {
- signature_ = Blob(signature, signatureLength);
- }
-
- /**
- * Set signature to point to an existing byte array. IMPORTANT: After calling this,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param signature A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- */
- void
- setSignature(const ptr_lib::shared_ptr<std::vector<uint8_t> > &signature) { signature_ = signature; }
-
- void
- setSignature(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &signature) { signature_ = signature; }
-
- void
- setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
-
- void
- setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
-
- /**
- * Clear all the fields.
- */
- void
- clear()
- {
- digestAlgorithm_.reset();
- witness_.reset();
- signature_.reset();
- publisherPublicKeyDigest_.clear();
- keyLocator_.clear();
- }
-
-private:
- Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
- Blob witness_;
- Blob signature_;
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
- KeyLocator keyLocator_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/transport/tcp-transport.cpp b/ndn-cpp/transport/tcp-transport.cpp
index 9a712fb..cb8c1e6 100644
--- a/ndn-cpp/transport/tcp-transport.cpp
+++ b/ndn-cpp/transport/tcp-transport.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,9 +6,11 @@
*/
#include <stdexcept>
-#include "../node.hpp"
+#include <ndn-cpp/node.hpp>
+#include "../c/transport/tcp-transport.h"
+#include "../c/encoding/binary-xml-element-reader.h"
#include "../c/util/ndn_realloc.h"
-#include "tcp-transport.hpp"
+#include <ndn-cpp/transport/tcp-transport.hpp>
using namespace std;
@@ -17,20 +20,27 @@
{
}
+TcpTransport::TcpTransport()
+ : elementListener_(0), isConnected_(false), transport_(new struct ndn_TcpTransport), elementReader_(new struct ndn_BinaryXmlElementReader)
+{
+ ndn_TcpTransport_initialize(transport_.get());
+ elementReader_->partialData.array = 0;
+}
+
void
TcpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const TcpTransport::ConnectionInfo& tcpConnectionInfo = dynamic_cast<const TcpTransport::ConnectionInfo&>(connectionInfo);
ndn_Error error;
- if ((error = ndn_TcpTransport_connect(&transport_, (char *)tcpConnectionInfo.getHost().c_str(), tcpConnectionInfo.getPort())))
+ if ((error = ndn_TcpTransport_connect(transport_.get(), (char *)tcpConnectionInfo.getHost().c_str(), tcpConnectionInfo.getPort())))
throw std::runtime_error(ndn_getErrorString(error));
// TODO: This belongs in the socket listener.
const size_t initialLength = 1000;
// Automatically cast elementReader_ to (struct ndn_ElementListener *)
ndn_BinaryXmlElementReader_initialize
- (&elementReader_, &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
+ (elementReader_.get(), &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
isConnected_ = true;
elementListener_ = &elementListener;
@@ -40,7 +50,7 @@
TcpTransport::send(const uint8_t *data, size_t dataLength)
{
ndn_Error error;
- if ((error = ndn_TcpTransport_send(&transport_, (uint8_t *)data, dataLength)))
+ if ((error = ndn_TcpTransport_send(transport_.get(), (uint8_t *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
@@ -49,17 +59,17 @@
{
int receiveIsReady;
ndn_Error error;
- if ((error = ndn_TcpTransport_receiveIsReady(&transport_, &receiveIsReady)))
+ if ((error = ndn_TcpTransport_receiveIsReady(transport_.get(), &receiveIsReady)))
throw std::runtime_error(ndn_getErrorString(error));
if (!receiveIsReady)
return;
uint8_t buffer[8000];
size_t nBytes;
- if ((error = ndn_TcpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes)))
+ if ((error = ndn_TcpTransport_receive(transport_.get(), buffer, sizeof(buffer), &nBytes)))
throw std::runtime_error(ndn_getErrorString(error));
- ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
+ ndn_BinaryXmlElementReader_onReceivedData(elementReader_.get(), buffer, nBytes);
}
bool
@@ -72,15 +82,15 @@
TcpTransport::close()
{
ndn_Error error;
- if ((error = ndn_TcpTransport_close(&transport_)))
+ if ((error = ndn_TcpTransport_close(transport_.get())))
throw std::runtime_error(ndn_getErrorString(error));
}
TcpTransport::~TcpTransport()
{
- if (elementReader_.partialData.array)
+ if (elementReader_->partialData.array)
// Free the memory allocated in connect.
- free(elementReader_.partialData.array);
+ free(elementReader_->partialData.array);
}
}
diff --git a/ndn-cpp/transport/tcp-transport.hpp b/ndn-cpp/transport/tcp-transport.hpp
deleted file mode 100644
index e6c2a73..0000000
--- a/ndn-cpp/transport/tcp-transport.hpp
+++ /dev/null
@@ -1,105 +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_HPP
-#define NDN_TCPTRANSPORT_HPP
-
-#include <string>
-#include "../c/transport/tcp-transport.h"
-#include "../c/encoding/binary-xml-element-reader.h"
-#include "transport.hpp"
-
-namespace ndn {
-
-class TcpTransport : public Transport {
-public:
- /**
- * A TcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for the TCP connection.
- */
- class ConnectionInfo : public Transport::ConnectionInfo {
- public:
- /**
- * Create a ConnectionInfo with the given host and port.
- * @param host The host for the connection.
- * @param port The port number for the connection. If omitted, use 6363.
- */
- ConnectionInfo(const char *host, unsigned short port = 6363)
- : host_(host), port_(port)
- {
- }
-
- /**
- * Get the host given to the constructor.
- * @return A string reference for the host.
- */
- const std::string&
- getHost() const { return host_; }
-
- /**
- * Get the port given to the constructor.
- * @return The port number.
- */
- unsigned short
- getPort() const { return port_; }
-
- virtual
- ~ConnectionInfo();
-
- private:
- std::string host_;
- unsigned short port_;
- };
-
- TcpTransport()
- : elementListener_(0), isConnected_(false)
- {
- ndn_TcpTransport_initialize(&transport_);
- elementReader_.partialData.array = 0;
- }
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to a TcpTransport::ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void send(const uint8_t *data, size_t dataLength);
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should normally not call this directly since it is called by Face.processEvents.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void processEvents();
-
- virtual bool getIsConnected();
-
- /**
- * Close the connection to the host.
- */
- virtual void close();
-
- ~TcpTransport();
-
-private:
- struct ndn_TcpTransport transport_;
- bool isConnected_;
- ElementListener *elementListener_;
- // TODO: This belongs in the socket listener.
- ndn_BinaryXmlElementReader elementReader_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/transport/transport.cpp b/ndn-cpp/transport/transport.cpp
index b36b119..0dcf518 100644
--- a/ndn-cpp/transport/transport.cpp
+++ b/ndn-cpp/transport/transport.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,7 +6,7 @@
*/
#include <stdexcept>
-#include "transport.hpp"
+#include <ndn-cpp/transport/transport.hpp>
using namespace std;
diff --git a/ndn-cpp/transport/transport.hpp b/ndn-cpp/transport/transport.hpp
deleted file mode 100644
index 512a003..0000000
--- a/ndn-cpp/transport/transport.hpp
+++ /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.
- */
-
-#ifndef NDN_TRANSPORT_HPP
-#define NDN_TRANSPORT_HPP
-
-#include <vector>
-
-namespace ndn {
-
-class ElementListener;
-
-class Transport {
-public:
- /**
- * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport.
- */
- class ConnectionInfo {
- public:
- virtual ~ConnectionInfo();
- };
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void
- connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void
- send(const uint8_t *data, size_t dataLength);
-
- void
- send(const std::vector<uint8_t>& data)
- {
- send(&data[0], data.size());
- }
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will silently time out after a brief period if there is no data to receive.
- * You should repeatedly call this from an event loop.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void
- processEvents() = 0;
-
- virtual bool
- getIsConnected();
-
- /**
- * Close the connection. This base class implementation does nothing, but your derived class can override.
- */
- virtual void
- close();
-
- virtual ~Transport();
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/transport/udp-transport.cpp b/ndn-cpp/transport/udp-transport.cpp
index 4e65375..17250d4 100644
--- a/ndn-cpp/transport/udp-transport.cpp
+++ b/ndn-cpp/transport/udp-transport.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -5,9 +6,11 @@
*/
#include <stdexcept>
-#include "../face.hpp"
+#include <ndn-cpp/face.hpp>
+#include "../c/transport/udp-transport.h"
+#include "../c/encoding/binary-xml-element-reader.h"
#include "../c/util/ndn_realloc.h"
-#include "udp-transport.hpp"
+#include <ndn-cpp/transport/udp-transport.hpp>
using namespace std;
@@ -17,20 +20,27 @@
{
}
+UdpTransport::UdpTransport()
+ : elementListener_(0), isConnected_(false), transport_(new struct ndn_UdpTransport), elementReader_(new struct ndn_BinaryXmlElementReader)
+{
+ ndn_UdpTransport_initialize(transport_.get());
+ elementReader_->partialData.array = 0;
+}
+
void
UdpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const UdpTransport::ConnectionInfo& udpConnectionInfo = dynamic_cast<const UdpTransport::ConnectionInfo&>(connectionInfo);
ndn_Error error;
- if ((error = ndn_UdpTransport_connect(&transport_, (char *)udpConnectionInfo.getHost().c_str(), udpConnectionInfo.getPort())))
+ if ((error = ndn_UdpTransport_connect(transport_.get(), (char *)udpConnectionInfo.getHost().c_str(), udpConnectionInfo.getPort())))
throw std::runtime_error(ndn_getErrorString(error));
// TODO: This belongs in the socket listener.
const size_t initialLength = 1000;
// Automatically cast elementReader_ to (struct ndn_ElementListener *)
ndn_BinaryXmlElementReader_initialize
- (&elementReader_, &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
+ (elementReader_.get(), &elementListener, (uint8_t *)malloc(initialLength), initialLength, ndn_realloc);
isConnected_ = true;
elementListener_ = &elementListener;
@@ -40,7 +50,7 @@
UdpTransport::send(const uint8_t *data, size_t dataLength)
{
ndn_Error error;
- if ((error = ndn_UdpTransport_send(&transport_, (uint8_t *)data, dataLength)))
+ if ((error = ndn_UdpTransport_send(transport_.get(), (uint8_t *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
@@ -49,17 +59,17 @@
{
int receiveIsReady;
ndn_Error error;
- if ((error = ndn_UdpTransport_receiveIsReady(&transport_, &receiveIsReady)))
+ if ((error = ndn_UdpTransport_receiveIsReady(transport_.get(), &receiveIsReady)))
throw std::runtime_error(ndn_getErrorString(error));
if (!receiveIsReady)
return;
uint8_t buffer[8000];
size_t nBytes;
- if ((error = ndn_UdpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes)))
+ if ((error = ndn_UdpTransport_receive(transport_.get(), buffer, sizeof(buffer), &nBytes)))
throw std::runtime_error(ndn_getErrorString(error));
- ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
+ ndn_BinaryXmlElementReader_onReceivedData(elementReader_.get(), buffer, nBytes);
}
bool
@@ -72,15 +82,15 @@
UdpTransport::close()
{
ndn_Error error;
- if ((error = ndn_UdpTransport_close(&transport_)))
+ if ((error = ndn_UdpTransport_close(transport_.get())))
throw std::runtime_error(ndn_getErrorString(error));
}
UdpTransport::~UdpTransport()
{
- if (elementReader_.partialData.array)
+ if (elementReader_->partialData.array)
// Free the memory allocated in connect.
- free(elementReader_.partialData.array);
+ free(elementReader_->partialData.array);
}
}
diff --git a/ndn-cpp/transport/udp-transport.hpp b/ndn-cpp/transport/udp-transport.hpp
deleted file mode 100644
index a7a40b1..0000000
--- a/ndn-cpp/transport/udp-transport.hpp
+++ /dev/null
@@ -1,110 +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_HPP
-#define NDN_UDPTRANSPORT_HPP
-
-#include <string>
-#include "../c/transport/udp-transport.h"
-#include "../c/encoding/binary-xml-element-reader.h"
-#include "transport.hpp"
-
-namespace ndn {
-
-class UdpTransport : public Transport {
-public:
- /**
- * A UdpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for the UDP connection.
- */
- class ConnectionInfo : public Transport::ConnectionInfo {
- public:
- /**
- * Create a ConnectionInfo with the given host and port.
- * @param host The host for the connection.
- * @param port The port number for the connection. If omitted, use 6363.
- */
- ConnectionInfo(const char *host, unsigned short port = 6363)
- : host_(host), port_(port)
- {
- }
-
- /**
- * Get the host given to the constructor.
- * @return A string reference for the host.
- */
- const std::string&
- getHost() const { return host_; }
-
- /**
- * Get the port given to the constructor.
- * @return The port number.
- */
- unsigned short
- getPort() const { return port_; }
-
- virtual
- ~ConnectionInfo();
-
- private:
- std::string host_;
- unsigned short port_;
- };
-
- UdpTransport()
- : elementListener_(0), isConnected_(false)
- {
- ndn_UdpTransport_initialize(&transport_);
- elementReader_.partialData.array = 0;
- }
-
- /**
- * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
- * @param connectionInfo A reference to a TcpTransport::ConnectionInfo.
- * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
- */
- virtual void
- connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
-
- /**
- * Set data to the host
- * @param data A pointer to the buffer of data to send.
- * @param dataLength The number of bytes in data.
- */
- virtual void
- send(const uint8_t *data, size_t dataLength);
-
- /**
- * Process any data to receive. For each element received, call elementListener.onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should normally not call this directly since it is called by Face.processEvents.
- * @throw This may throw an exception for reading data or in the callback for processing the data. If you
- * call this from an main event loop, you may want to catch and log/disregard all exceptions.
- */
- virtual void
- processEvents();
-
- virtual bool
- getIsConnected();
-
- /**
- * Close the connection to the host.
- */
- virtual void
- close();
-
- ~UdpTransport();
-
-private:
- struct ndn_UdpTransport transport_;
- bool isConnected_;
- ElementListener *elementListener_;
- // TODO: This belongs in the socket listener.
- ndn_BinaryXmlElementReader elementReader_;
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/util/blob.cpp b/ndn-cpp/util/blob.cpp
new file mode 100644
index 0000000..4ce9598
--- /dev/null
+++ b/ndn-cpp/util/blob.cpp
@@ -0,0 +1,30 @@
+/* -*- 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/util/blob.hpp>
+
+using namespace std;
+
+namespace ndn {
+
+Blob::Blob(const struct ndn_Blob& blobStruct)
+ : ptr_lib::shared_ptr<const std::vector<uint8_t> >(new std::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/ndn-cpp/util/blob.hpp b/ndn-cpp/util/blob.hpp
deleted file mode 100644
index 2c238a6..0000000
--- a/ndn-cpp/util/blob.hpp
+++ /dev/null
@@ -1,120 +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_HPP
-#define NDN_BLOB_HPP
-
-#include "../common.hpp"
-#include "../c/util/blob.h"
-
-namespace ndn {
-
-/**
- * A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
- * This is like a JavaScript string which is a pointer to an immutable string.
- * It is OK to pass a pointer to the string because the new owner can't change the bytes
- * of the string. However, like a JavaScript string, it is possible to change the pointer, and so this does allow
- * the copy constructor and assignment to change the pointer. Also remember that the pointer can be null.
- * (Note that we could have made Blob derive directly from vector<uint8_t> and then explicitly use
- * a pointer to it like shared_ptr<Blob>, but this does not enforce immutability because we can't declare
- * Blob as derived from const vector<uint8_t>.)
- */
-class Blob : public ptr_lib::shared_ptr<const std::vector<uint8_t> > {
-public:
- /**
- * Create a new Blob with a null pointer.
- */
- Blob()
- {
- }
-
- /**
- * Create a new Blob with an immutable copy of the given array.
- * @param value A pointer to the byte array which is copied.
- * @param valueLength The length of value.
- */
- Blob(const uint8_t* value, size_t valueLength)
- : ptr_lib::shared_ptr<const std::vector<uint8_t> >(new std::vector<uint8_t>(value, value + valueLength))
- {
- }
-
- /**
- * Create a new Blob with an immutable copy of the array in the given vector.
- * If you want to transfer the array without copying, the the vector has to start as a
- * ptr_lib::shared_ptr<std::vector<uint8_t> > and you can use the Blob constructor with this type.
- * @param value A reference to a vector which is copied.
- */
- Blob(const std::vector<uint8_t> &value)
- : ptr_lib::shared_ptr<const std::vector<uint8_t> >(new std::vector<uint8_t>(value))
- {
- }
-
- /**
- * Create a new Blob with an immutable copy of the array in the given Blob struct.
- * @param blobStruct The C ndn_Blob struct to receive the pointer.
- */
- Blob(const struct ndn_Blob& blobStruct)
- : ptr_lib::shared_ptr<const std::vector<uint8_t> >(new std::vector<uint8_t>(blobStruct.value, blobStruct.value + blobStruct.length))
- {
- }
-
- /**
- * Create a new Blob to point to an existing byte array. IMPORTANT: After calling this constructor,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param value A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- */
- Blob(const ptr_lib::shared_ptr<std::vector<uint8_t> > &value)
- : ptr_lib::shared_ptr<const std::vector<uint8_t> >(value)
- {
- }
- Blob(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &value)
- : ptr_lib::shared_ptr<const std::vector<uint8_t> >(value)
- {
- }
-
- /**
- * Return the length of the immutable byte array.
- */
- size_t
- size() const
- {
- if (*this)
- return (*this)->size();
- else
- return 0;
- }
-
- /**
- * Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null.
- */
- const uint8_t*
- buf() const
- {
- if (*this)
- return &(*this)->front();
- else
- return 0;
- }
-
- /**
- * Set the blobStruct to point to this Blob's byte array, without copying any memory.
- * WARNING: The resulting pointer in blobStruct is invalid after a further use of this object which could reallocate memory.
- * @param blobStruct The C ndn_Blob struct to receive the pointer.
- */
- void
- get(struct ndn_Blob& blobStruct) const
- {
- blobStruct.length = size();
- if (size() > 0)
- blobStruct.value = (uint8_t*)buf();
- else
- blobStruct.value = 0;
- }
-};
-
-}
-
-#endif
diff --git a/ndn-cpp/util/changed-event.cpp b/ndn-cpp/util/changed-event.cpp
index 63b4569..08dcb98 100644
--- a/ndn-cpp/util/changed-event.cpp
+++ b/ndn-cpp/util/changed-event.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
diff --git a/ndn-cpp/util/changed-event.hpp b/ndn-cpp/util/changed-event.hpp
index ce4b20f..71be366 100644
--- a/ndn-cpp/util/changed-event.hpp
+++ b/ndn-cpp/util/changed-event.hpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -8,7 +9,7 @@
#define NDN_CHANGED_EVENT_HPP
#include <vector>
-#include "../common.hpp"
+#include <ndn-cpp/common.hpp>
namespace ndn {
diff --git a/ndn-cpp/util/dynamic-uint8-vector.cpp b/ndn-cpp/util/dynamic-uint8-vector.cpp
index ae1b621..197fc0e 100644
--- a/ndn-cpp/util/dynamic-uint8-vector.cpp
+++ b/ndn-cpp/util/dynamic-uint8-vector.cpp
@@ -1,3 +1,4 @@
+/* -*- 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>
diff --git a/ndn-cpp/util/dynamic-uint8-vector.hpp b/ndn-cpp/util/dynamic-uint8-vector.hpp
index 9550899..b69606d 100644
--- a/ndn-cpp/util/dynamic-uint8-vector.hpp
+++ b/ndn-cpp/util/dynamic-uint8-vector.hpp
@@ -1,3 +1,4 @@
+/* -*- 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>
@@ -8,7 +9,7 @@
#define NDN_DYNAMIC_UCHAR_VECTOR_HPP
#include <vector>
-#include "../common.hpp"
+#include <ndn-cpp/common.hpp>
#include "../c/util/dynamic-uint8-array.h"
namespace ndn {
diff --git a/ndn-cpp/util/logging.hpp b/ndn-cpp/util/logging.hpp
index 87d9ad5..f1afe72 100644
--- a/ndn-cpp/util/logging.hpp
+++ b/ndn-cpp/util/logging.hpp
@@ -9,7 +9,7 @@
#ifndef NDN_LOGGING_HPP
#define NDN_LOGGING_HPP
-#include "../common.hpp"
+#include <ndn-cpp//common.hpp>
#ifdef NDN_CPP_HAVE_LOG4CXX
diff --git a/ndn-cpp/util/signed-blob.hpp b/ndn-cpp/util/signed-blob.hpp
deleted file mode 100644
index dd94ae0..0000000
--- a/ndn-cpp/util/signed-blob.hpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#ifndef NDN_SIGNED_BLOB_HPP
-#define NDN_SIGNED_BLOB_HPP
-
-#include "blob.hpp"
-
-namespace ndn {
-
-/**
- * A SignedBlob extends Blob to keep the offsets of a signed portion (e.g., the bytes of Data packet).
- */
-class SignedBlob : public Blob {
-public:
- /**
- * Create a new SignedBlob with a null pointer.
- */
- SignedBlob()
- : signedPortionBeginOffset_(0), signedPortionEndOffset_(0)
- {
- }
-
- /**
- * Create a new SignedBlob with an immutable copy of the given array.
- * @param value A pointer to the byte array which is copied.
- * @param valueLength The length of value.
- * @param signedPortionBeginOffset The offset in the encoding of the beginning of the signed portion.
- * @param signedPortionEndOffset The offset in the encoding of the end of the signed portion.
- */
- SignedBlob
- (const uint8_t* value, size_t valueLength, size_t signedPortionBeginOffset, size_t signedPortionEndOffset)
- : Blob(value, valueLength), signedPortionBeginOffset_(signedPortionBeginOffset), signedPortionEndOffset_(signedPortionEndOffset)
- {
- }
-
- /**
- * Create a new SignedBlob with an immutable copy of the array in the given vector.
- * If you want to transfer the array without copying, the the vector has to start as a
- * ptr_lib::shared_ptr<std::vector<uint8_t> > and you can use the SignedBlob constructor with this type.
- * @param value A reference to a vector which is copied.
- * @param signedPortionBeginOffset The offset in the encoding of the beginning of the signed portion.
- * @param signedPortionEndOffset The offset in the encoding of the end of the signed portion.
- */
- SignedBlob
- (const std::vector<uint8_t> &value, size_t signedPortionBeginOffset, size_t signedPortionEndOffset)
- : Blob(value), signedPortionBeginOffset_(signedPortionBeginOffset), signedPortionEndOffset_(signedPortionEndOffset)
- {
- }
-
- /**
- * Create a new SignedBlob to point to an existing byte array. IMPORTANT: After calling this constructor,
- * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
- * @param value A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
- * @param signedPortionBeginOffset The offset in the array of the beginning of the signed portion.
- * @param signedPortionEndOffset The offset in the array of the end of the signed portion.
- */
- SignedBlob
- (const ptr_lib::shared_ptr<std::vector<uint8_t> > &value,
- size_t signedPortionBeginOffset, size_t signedPortionEndOffset)
- : Blob(value), signedPortionBeginOffset_(signedPortionBeginOffset), signedPortionEndOffset_(signedPortionEndOffset)
- {
- }
- SignedBlob
- (const ptr_lib::shared_ptr<const std::vector<uint8_t> > &value,
- size_t signedPortionBeginOffset, size_t signedPortionEndOffset)
- : Blob(value), signedPortionBeginOffset_(signedPortionBeginOffset), signedPortionEndOffset_(signedPortionEndOffset)
- {
- }
-
- /**
- * Return the length of the signed portion of the immutable byte array, or 0 of the pointer to the array is null.
- */
- size_t
- signedSize() const
- {
- if (*this)
- return signedPortionEndOffset_ - signedPortionBeginOffset_;
- else
- return 0;
- }
-
- /**
- * Return a const pointer to the first byte of the signed portion of the immutable byte array, or 0 if the
- * pointer to the array is null.
- */
- const uint8_t*
- signedBuf() const
- {
- if (*this)
- return &(*this)->front() + signedPortionBeginOffset_;
- else
- return 0;
- }
-
- /**
- * Return the offset in the array of the beginning of the signed portion.
- */
- size_t
- getSignedPortionBeginOffset() { return signedPortionBeginOffset_; }
-
- /**
- * Return the offset in the array of the end of the signed portion.
- */
- size_t
- getSignedPortionEndOffset() { return signedPortionEndOffset_; }
-
-private:
- size_t signedPortionBeginOffset_;
- size_t signedPortionEndOffset_;
-};
-
-}
-
-#endif