build: add -std=c++03 (in non C++11 mode) and -pedantic to the default CXXFLAGS
And fix the resulting warnings. The long-long-int warning is explicitly
suppressed because it's not trivial to workaround in a platform-independent
and ISO-conformant way without using C++11.
This commit also includes fix for the advisory check for C++11-enabled
compiler in common.hpp (gcc < 4.7 does not correctly define __cpluplus
macro).
Finally, when custom CXXFLAGS are specified, --with-c++11 does not force
-std=c++11 or -std=c++0x flags, but just performs mandatory checks for
std::shared_ptr and std::function.
Change-Id: Icf44627edfddd34301bd27a05882b62fcbf54329
diff --git a/src/common.hpp b/src/common.hpp
index 457ac23..79f6c1c 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -45,11 +45,18 @@
#define DEPRECATED(func) func
#endif
-#if NDN_CPP_HAVE_CXX11
+#ifdef NDN_CPP_HAVE_CXX11
-#if (__cplusplus < 201103L)
-#error "NDN-CPP-DEV library is configured and compiled in C++11 mode, but the current compiler is not C++11 enabled"
-#endif
+#if defined(__GNUC__)
+# if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
+# error "NDN-CPP-DEV library is configured and compiled in C++11 mode, but the current compiler is not C++11 enabled"
+# endif // !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
+#endif // defined(__GNUC__)
+
+#if defined(__clang__) && __cplusplus < 201103L
+# error "NDN-CPP-DEV library is configured and compiled in C++11 mode, but the current compiler is not C++11 enabled"
+#endif // defined(__clang__) && (__cplusplus < 201103L)
+
#include <memory>
#include <functional>
@@ -60,6 +67,7 @@
namespace func_lib = std;
using std::shared_ptr;
+using std::weak_ptr;
using std::make_shared;
using std::enable_shared_from_this;
@@ -77,6 +85,7 @@
#else
#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
@@ -89,6 +98,7 @@
namespace func_lib = boost;
using boost::shared_ptr;
+using boost::weak_ptr;
using boost::make_shared;
using boost::enable_shared_from_this;
@@ -101,7 +111,7 @@
} // namespace ndn
-#endif
+#endif // NDN_CPP_HAVE_CXX11
namespace ndn {
diff --git a/src/encoding/tlv-nrd.hpp b/src/encoding/tlv-nrd.hpp
index 6dcbbfd..9ca1a65 100644
--- a/src/encoding/tlv-nrd.hpp
+++ b/src/encoding/tlv-nrd.hpp
@@ -23,12 +23,12 @@
Cost = 104,
ExpirationPeriod = 105,
StrategyName = 106,
- Protocol = 107,
+ Protocol = 107
};
enum {
NDN_FORW_CHILD_INHERIT = 1,
- NDN_FORW_CAPTURE = 2,
+ NDN_FORW_CAPTURE = 2
};
} // namespace nrd
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 803df9f..60fad5d 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -65,13 +65,13 @@
enum SignatureType {
DigestSha256 = 0,
- SignatureSha256WithRsa = 1,
+ SignatureSha256WithRsa = 1
};
enum ConentType {
ContentType_Default = 0,
ContentType_Link = 1,
- ContentType_Key = 2,
+ ContentType_Key = 2
};
/**
diff --git a/src/security/certificate-cache-ttl.cpp b/src/security/certificate-cache-ttl.cpp
index 0997182..8dea438 100644
--- a/src/security/certificate-cache-ttl.cpp
+++ b/src/security/certificate-cache-ttl.cpp
@@ -11,7 +11,7 @@
#include "../util/logging.hpp"
-INIT_LOGGER("ndn.CertificateCacheTtl")
+INIT_LOGGER("ndn.CertificateCacheTtl");
using namespace std;
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 1ec2323..48664ea 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -68,7 +68,7 @@
enum
{
INTEREST_SIG_VALUE = -1,
- INTEREST_SIG_INFO = -2,
+ INTEREST_SIG_INFO = -2
};
public:
@@ -176,7 +176,7 @@
enum
{
INTEREST_SIG_VALUE = -1,
- INTEREST_SIG_INFO = -2,
+ INTEREST_SIG_INFO = -2
};
public:
FixedSignerChecker(uint32_t sigType,
diff --git a/src/security/conf/filter.hpp b/src/security/conf/filter.hpp
index 1db7498..7d5b833 100644
--- a/src/security/conf/filter.hpp
+++ b/src/security/conf/filter.hpp
@@ -42,7 +42,7 @@
{
RELATION_EQUAL,
RELATION_IS_PREFIX_OF,
- RELATION_IS_STRICT_PREFIX_OF,
+ RELATION_IS_STRICT_PREFIX_OF
};
RelationNameFilter(const Name& name, Relation relation)
diff --git a/src/security/conf/key-locator-checker.hpp b/src/security/conf/key-locator-checker.hpp
index 0f667f7..5785c59 100644
--- a/src/security/conf/key-locator-checker.hpp
+++ b/src/security/conf/key-locator-checker.hpp
@@ -28,7 +28,7 @@
{
RELATION_EQUAL,
RELATION_IS_PREFIX_OF,
- RELATION_IS_STRICT_PREFIX_OF,
+ RELATION_IS_STRICT_PREFIX_OF
};
virtual
diff --git a/src/security/key-chain.hpp b/src/security/key-chain.hpp
index cbc1f2a..ac03ce4 100644
--- a/src/security/key-chain.hpp
+++ b/src/security/key-chain.hpp
@@ -53,7 +53,7 @@
createIdentity(const Name& identityName)
{
Info::addIdentity(identityName);
-
+
Name keyName;
try
{
@@ -71,14 +71,14 @@
}
catch(InfoError& e)
{
- shared_ptr<IdentityCertificate> selfCert = selfSign(keyName);
+ shared_ptr<IdentityCertificate> selfCert = selfSign(keyName);
Info::addCertificateAsIdentityDefault(*selfCert);
certName = selfCert->getName();
}
return certName;
}
-
+
/**
* @brief Generate a pair of RSA keys for the specified identity.
*
@@ -92,7 +92,7 @@
{
return generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize);
}
-
+
/**
* @brief Generate a pair of RSA keys for the specified identity and set it as default key for the identity.
*
@@ -107,7 +107,7 @@
Name keyName = generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize);
Info::setDefaultKeyNameForIdentity(keyName);
-
+
return keyName;
}
@@ -118,7 +118,7 @@
* @param signingIdentity The signing identity.
* @param notBefore Refer to IdentityCertificate.
* @param notAfter Refer to IdentityCertificate.
- * @param subjectDescription Refer to IdentityCertificate.
+ * @param subjectDescription Refer to IdentityCertificate.
* @return IdentityCertificate.
*/
shared_ptr<IdentityCertificate>
@@ -131,7 +131,7 @@
{
if(keyName.size() < 1)
return shared_ptr<IdentityCertificate>();
-
+
std::string keyIdPrefix = keyName.get(-1).toEscapedString().substr(0, 4);
if(keyIdPrefix != "ksk-" && keyIdPrefix != "dsk-")
return shared_ptr<IdentityCertificate>();
@@ -177,7 +177,7 @@
}
certificate->encode();
-
+
return certificate;
}
@@ -185,7 +185,7 @@
* @brief Sign packet with default identity
*
* On return, signatureInfo and signatureValue in the packet are set.
- * If default identity does not exist,
+ * If default identity does not exist,
* a temporary identity will be created and set as default.
*
* @param packet The packet to be signed
@@ -219,7 +219,7 @@
sign(packet, *Info::defaultCertificate());
}
-
+
/**
* @brief Sign packet with a particular certificate.
*
@@ -228,7 +228,7 @@
* @throws SecPublicInfo::Error if certificate does not exist.
*/
template<typename T>
- void
+ void
sign(T& packet, const Name& certificateName)
{
if (!Info::doesCertificateExist(certificateName))
@@ -238,11 +238,11 @@
signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care
// For temporary usage, we support RSA + SHA256 only, but will support more.
- signPacketWrapper(packet, signature,
- IdentityCertificate::certificateNameToPublicKeyName(certificateName),
+ signPacketWrapper(packet, signature,
+ IdentityCertificate::certificateNameToPublicKeyName(certificateName),
DIGEST_ALGORITHM_SHA256);
}
-
+
/**
* @brief Sign the byte array using a particular certificate.
*
@@ -260,10 +260,10 @@
SignatureSha256WithRsa signature;
signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care
-
+
// For temporary usage, we support RSA + SHA256 only, but will support more.
- signature.setValue(Tpm::signInTpm(buffer, bufferLength,
- IdentityCertificate::certificateNameToPublicKeyName(certificateName),
+ signature.setValue(Tpm::signInTpm(buffer, bufferLength,
+ IdentityCertificate::certificateNameToPublicKeyName(certificateName),
DIGEST_ALGORITHM_SHA256));
return signature;
}
@@ -277,7 +277,7 @@
* @param identityName The signing identity name.
*/
template<typename T>
- void
+ void
signByIdentity(T& packet, const Name& identityName)
{
Name signingCertificateName;
@@ -287,14 +287,14 @@
}
catch(InfoError& e)
{
- signingCertificateName = createIdentity(identityName);
+ signingCertificateName = createIdentity(identityName);
// Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error.
}
// We either get or create the signing certificate, sign packet! (no exception unless fatal error in TPM)
sign(packet, signingCertificateName);
}
-
+
/**
* @brief Sign the byte array using the default certificate of a particular identity.
*
@@ -313,10 +313,10 @@
}
catch(InfoError& e)
{
- signingCertificateName = createIdentity(identityName);
+ signingCertificateName = createIdentity(identityName);
// Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error.
}
-
+
// We either get or create the signing certificate, sign data! (no exception unless fatal error in TPM)
return sign(buffer, bufferLength, signingCertificateName);
}
@@ -332,8 +332,8 @@
SignatureSha256 sig;
data.setSignature(sig);
- Block sigValue(Tlv::SignatureValue,
- crypto::sha256(data.wireEncode().value(),
+ Block sigValue(Tlv::SignatureValue,
+ crypto::sha256(data.wireEncode().value(),
data.wireEncode().value_size() - data.getSignature().getValue().size()));
data.setSignatureValue(sigValue);
@@ -359,7 +359,7 @@
}
shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>();
-
+
Name certificateName = keyName.getPrefix(-1);
certificateName.append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion();
@@ -397,9 +397,9 @@
/**
* @brief delete a certificate.
*
- * If the certificate to be deleted is current default system default,
+ * If the certificate to be deleted is current default system default,
* the method will not delete the certificate and return immediately.
- *
+ *
* @param certificateName The certificate to be deleted.
*/
void
@@ -421,9 +421,9 @@
/**
* @brief delete a key.
*
- * If the key to be deleted is current default system default,
+ * If the key to be deleted is current default system default,
* the method will not delete the key and return immediately.
- *
+ *
* @param keyName The key to be deleted.
*/
void
@@ -446,9 +446,9 @@
/**
* @brief delete an identity.
*
- * If the identity to be deleted is current default system default,
+ * If the identity to be deleted is current default system default,
* the method will not delete the identity and return immediately.
- *
+ *
* @param identity The identity to be deleted.
*/
void
@@ -467,9 +467,9 @@
std::vector<Name> nameList;
Info::getAllKeyNamesOfIdentity(identity, nameList, true);
Info::getAllKeyNamesOfIdentity(identity, nameList, false);
-
+
Info::deleteIdentityInfo(identity);
-
+
std::vector<Name>::const_iterator it = nameList.begin();
for(; it != nameList.end(); it++)
Tpm::deleteKeyPairInTpm(*it);
@@ -488,7 +488,7 @@
{
if (!Info::doesIdentityExist(identity))
throw InfoError("Identity does not exist!");
-
+
Name keyName = Info::getDefaultKeyNameForIdentity(identity);
ConstBufferPtr pkcs8;
@@ -501,14 +501,14 @@
throw InfoError("Fail to export PKCS8 of private key");
}
- shared_ptr<IdentityCertificate> cert;
+ shared_ptr<IdentityCertificate> cert;
try
{
cert = Info::getCertificate(Info::getDefaultCertificateNameForKey(keyName));
}
catch(InfoError& e)
{
- cert = selfSign(keyName);
+ cert = selfSign(keyName);
Info::addCertificateAsIdentityDefault(*cert);
}
@@ -528,16 +528,16 @@
{
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(securedBag.getCertificate().getName());
Name identity = keyName.getPrefix(-1);
-
+
// Add identity
Info::addIdentity(identity);
-
+
// Add key
Tpm::importPrivateKeyPkcs8IntoTpm(keyName, securedBag.getKey()->buf(), securedBag.getKey()->size(), passwordStr);
shared_ptr<PublicKey> pubKey = Tpm::getPublicKeyFromTpm(keyName.toUri());
Info::addPublicKey(keyName, KEY_TYPE_RSA, *pubKey); // HACK! We should set key type according to the pkcs8 info.
Info::setDefaultKeyNameForIdentity(keyName);
-
+
// Add cert
Info::addCertificateAsIdentityDefault(securedBag.getCertificate());
}
@@ -591,7 +591,7 @@
* @param keyName The name of the signing key.
* @param digestAlgorithm the digest algorithm.
* @throws Tpm::Error
- */
+ */
void
signPacketWrapper(Data& data, const SignatureSha256WithRsa& signature, const Name& keyName, DigestAlgorithm digestAlgorithm)
{
@@ -610,14 +610,14 @@
* @param keyName The name of the signing key.
* @param digestAlgorithm the digest algorithm.
* @throws Tpm::Error
- */
+ */
void
signPacketWrapper(Interest& interest, const SignatureSha256WithRsa& signature, const Name& keyName, DigestAlgorithm digestAlgorithm)
{
Name signedName = Name(interest.getName()).append(signature.getInfo());
- Block sigValue = Tpm::signInTpm(signedName.wireEncode().value(),
- signedName.wireEncode().value_size(),
+ Block sigValue = Tpm::signInTpm(signedName.wireEncode().value(),
+ signedName.wireEncode().value_size(),
keyName,
DIGEST_ALGORITHM_SHA256);
sigValue.encode();
@@ -634,17 +634,19 @@
#if defined(NDN_CPP_HAVE_OSX_SECURITY) and defined(NDN_CPP_WITH_OSX_KEYCHAIN)
-namespace ndn
-{
+namespace ndn {
+
typedef KeyChainImpl<SecPublicInfoSqlite3, SecTpmOsx> KeyChain;
-};
+
+} // namespace ndn
#else
-namespace ndn
-{
+namespace ndn {
+
typedef KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> KeyChain;
-};
+
+} // namespace ndn
#endif //NDN_CPP_HAVE_OSX_SECURITY
diff --git a/src/security/security-common.hpp b/src/security/security-common.hpp
index 1bea763..67a2315 100644
--- a/src/security/security-common.hpp
+++ b/src/security/security-common.hpp
@@ -13,7 +13,7 @@
enum KeyType {
KEY_TYPE_RSA,
// KEY_TYPE_DSA,
- KEY_TYPE_AES,
+ KEY_TYPE_AES
// KEY_TYPE_DES,
// KEY_TYPE_RC4,
// KEY_TYPE_RC2
@@ -24,7 +24,7 @@
KEY_CLASS_PRIVATE,
KEY_CLASS_SYMMETRIC
};
-
+
enum DigestAlgorithm {
// DIGEST_ALGORITHM_MD2,
// DIGEST_ALGORITHM_MD5,
@@ -34,13 +34,13 @@
enum EncryptMode {
ENCRYPT_MODE_DEFAULT,
- ENCRYPT_MODE_CFB_AES,
+ ENCRYPT_MODE_CFB_AES
// ENCRYPT_MODE_CBC_AES
};
enum AclType {
ACL_TYPE_PUBLIC,
- ACL_TYPE_PRIVATE,
+ ACL_TYPE_PRIVATE
};
}
diff --git a/src/util/logging.cpp b/src/util/logging.cpp
index 59c7b2a..0b969a0 100644
--- a/src/util/logging.cpp
+++ b/src/util/logging.cpp
@@ -26,21 +26,21 @@
#include <unistd.h>
void
-INIT_LOGGERS ()
+INIT_LOGGERS()
{
static bool configured = false;
if (configured) return;
- if (access ("log4cxx.properties", R_OK)==0)
- PropertyConfigurator::configureAndWatch ("log4cxx.properties");
+ if (access("log4cxx.properties", R_OK)==0)
+ PropertyConfigurator::configureAndWatch("log4cxx.properties");
else
{
- PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n"));
- ConsoleAppenderPtr appender (new ConsoleAppender (layout));
+ PatternLayoutPtr layout (new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
+ ConsoleAppenderPtr appender(new ConsoleAppender(layout));
BasicConfigurator::configure( appender );
- Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ());
+ Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
}
configured = true;
diff --git a/src/util/logging.hpp b/src/util/logging.hpp
index 3fc1c0a..9370af0 100644
--- a/src/util/logging.hpp
+++ b/src/util/logging.hpp
@@ -16,28 +16,28 @@
#include <log4cxx/logger.h>
#define MEMBER_LOGGER \
- static log4cxx::LoggerPtr staticModuleLogger;
+ static log4cxx::LoggerPtr staticModuleLogger
#define INIT_MEMBER_LOGGER(className,name) \
- log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger (name);
+ log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name)
#define INIT_LOGGER(name) \
- static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger (name);
+ static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
#define _LOG_DEBUG(x) \
- LOG4CXX_DEBUG(staticModuleLogger, x);
+ LOG4CXX_DEBUG(staticModuleLogger, x)
#define _LOG_TRACE(x) \
- LOG4CXX_TRACE(staticModuleLogger, x);
+ LOG4CXX_TRACE(staticModuleLogger, x)
#define _LOG_FUNCTION(x) \
- LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
+ LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")")
#define _LOG_FUNCTION_NOARGS \
- LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
+ LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()")
#define _LOG_ERROR(x) \
- LOG4CXX_ERROR(staticModuleLogger, x);
+ LOG4CXX_ERROR(staticModuleLogger, x)
#define _LOG_ERROR_COND(cond,x) \
if (cond) { _LOG_ERROR(x) }
@@ -46,11 +46,11 @@
if (cond) { _LOG_DEBUG(x) }
void
-INIT_LOGGERS ();
+INIT_LOGGERS()
#else // else NDN_CPP_HAVE_LOG4CXX
-#define INIT_LOGGER(name)
+#define INIT_LOGGER(name) struct LOGGING_DISABLED
#define _LOG_FUNCTION(x)
#define _LOG_FUNCTION_NOARGS
#define _LOG_TRACE(x)