tiny
diff --git a/model/sync-ccnx-wrapper.cc b/model/sync-ccnx-wrapper.cc
index 0684cea..6b25dfa 100644
--- a/model/sync-ccnx-wrapper.cc
+++ b/model/sync-ccnx-wrapper.cc
@@ -23,7 +23,7 @@
#include "sync-ccnx-wrapper.h"
#include <poll.h>
#include <boost/throw_exception.hpp>
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
+typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
using namespace std;
using namespace boost;
@@ -37,9 +37,8 @@
, m_running (true)
{
m_handle = ccn_create();
- if (ccn_connect(m_handle, NULL) < 0)
- BOOST_THROW_EXCEPTION (CcnxOperationException()
- << errmsg_info_str("connection to ccnd failed"));
+ if (ccn_connect(m_handle, NULL) < 0)
+ BOOST_THROW_EXCEPTION (CcnxOperationException() << errmsg_info_str("connection to ccnd failed"));
initKeyStore();
createKeyLocator();
m_thread = thread (&CcnxWrapper::ccnLoop, this);
@@ -92,12 +91,10 @@
void
CcnxWrapper::initKeyStore ()
{
- ccn_charbuf *temp = ccn_charbuf_create ();
m_keyStore = ccn_keystore_create ();
- string keyStoreFile = string(getenv("HOME")) + string("/.ccnx/.ccnx_keystore");
- if (ccn_keystore_init (m_keyStore, (char *)keyStoreFile.c_str(), (char*)"Th1s1sn0t8g00dp8ssw0rd.") < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str(keyStoreFile.c_str()));
- ccn_charbuf_destroy (&temp);
+ string keyStoreFile = string(getenv("HOME")) + string("/.ccnx/.ccnx_keystore");
+ if (ccn_keystore_init (m_keyStore, (char *)keyStoreFile.c_str(), (char*)"Th1s1sn0t8g00dp8ssw0rd.") < 0)
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str(keyStoreFile.c_str()));
}
void
@@ -144,11 +141,11 @@
if(ccn_encode_ContentObject(content, pname, signed_info,
dataBuffer.c_str(), dataBuffer.length (),
NULL, getPrivateKey()) < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("encode content failed"));
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("encode content failed"));
recursive_mutex::scoped_lock lock(m_mutex);
if (ccn_put(m_handle, content->buf, content->length) < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("ccnput failed"));
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("ccnput failed"));
ccn_charbuf_destroy (&pname);
ccn_charbuf_destroy (&signed_info);
@@ -184,7 +181,8 @@
size_t size;
interest += "/";
ccn_name_comp_get(info->interest_ccnb, info->interest_comps, i, (const unsigned char **)&comp, &size);
- interest += comp;
+ string compStr(comp, size);
+ interest += compStr;
}
(*f) (interest);
return CCN_UPCALL_RESULT_OK;
@@ -200,7 +198,7 @@
switch (kind)
{
case CCN_UPCALL_FINAL: // effecitve in unit tests
- delete f;
+ delete f;
delete selfp;
return CCN_UPCALL_RESULT_OK;
@@ -214,7 +212,8 @@
char *pcontent;
size_t len;
if (ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E], info->pco, (const unsigned char **)&pcontent, &len) < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("decode ContentObject failed"));
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("decode ContentObject failed"));
+ string content(pcontent, len);
string name;
for (int i = 0; i < info->content_comps->n - 1; i++)
@@ -223,10 +222,10 @@
size_t size;
name += "/";
ccn_name_comp_get(info->content_ccnb, info->content_comps, i, (const unsigned char **)&comp, &size);
- name += comp;
+ string compStr(comp, size);
+ name += compStr;
}
- // this will crash when content doesn't have \0 ending
- (*f) (name, (string)pcontent);
+ (*f) (name, content);
return CCN_UPCALL_RESULT_OK;
}
@@ -234,14 +233,14 @@
{
ccn_charbuf *pname = ccn_charbuf_create();
ccn_closure *dataClosure = new ccn_closure;
-
+
ccn_name_from_uri (pname, strInterest.c_str());
dataClosure->data = new DataCallback (dataCallback); // should be removed when closure is removed
-
+
dataClosure->p = &incomingData;
recursive_mutex::scoped_lock lock(m_mutex);
if (ccn_express_interest (m_handle, pname, dataClosure, NULL) < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("express interest failed"));
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("express interest failed"));
ccn_charbuf_destroy (&pname);
}
@@ -255,7 +254,7 @@
interestClosure->data = new InterestCallback (interestCallback); // should be removed when closure is removed
interestClosure->p = &incomingInterest;
if(ccn_set_interest_filter (m_handle, pname, interestClosure) < 0)
- BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("set interest filter failed"));
+ BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("set interest filter failed"));
ccn_charbuf_destroy(&pname);
}