copy code from ccnpoke to support using keyname in
keylocator field (the right way to publish)

Change-Id: Iaa11bbc5382ba16c393f7c3207caeb284578abf2
diff --git a/ccnx/ccnx-wrapper.cpp b/ccnx/ccnx-wrapper.cpp
index 54ca745..7a83fe1 100644
--- a/ccnx/ccnx-wrapper.cpp
+++ b/ccnx/ccnx-wrapper.cpp
@@ -261,7 +261,7 @@
 }
 
 Bytes
-CcnxWrapper::createContentObject(const Name  &name, const void *buf, size_t len, int freshness)
+CcnxWrapper::createContentObject(const Name  &name, const void *buf, size_t len, int freshness, const Name &keyName)
 {
   {
     UniqueRecLock lock(m_mutex);
@@ -279,6 +279,28 @@
   struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT;
   sp.freshness = freshness;
 
+  if (keyName.size() > 0)
+  {
+    if (sp.template_ccnb == NULL)
+    {
+      sp.template_ccnb = ccn_charbuf_create();
+      ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG);
+    }
+    // no idea what the following 3 lines do, but it was there
+    else if (sp.template_ccnb->length > 0) {
+        sp.template_ccnb->length--;
+    }
+    ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyLocator, CCN_DTAG);
+    ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyName, CCN_DTAG);
+    CcnxCharbufPtr keyPtr = keyName.toCcnxCharbuf();
+    ccn_charbuf *keyBuf = keyPtr->getBuf();
+    ccn_charbuf_append(sp.template_ccnb, keyBuf->buf, keyBuf->length);
+    ccn_charbuf_append_closer(sp.template_ccnb); // </KeyName>
+    ccn_charbuf_append_closer(sp.template_ccnb); // </KeyLocator>
+    sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR;
+    ccn_charbuf_append_closer(sp.template_ccnb); // </SignedInfo>
+  }
+
   if (ccn_sign_content(m_handle, content, pname, &sp, buf, len) != 0)
   {
     BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str("sign content failed"));
@@ -288,6 +310,10 @@
   readRaw(bytes, content->buf, content->length);
 
   ccn_charbuf_destroy (&content);
+  if (sp.template_ccnb != NULL)
+  {
+    ccn_charbuf_destroy (&sp.template_ccnb);
+  }
 
   return bytes;
 }
@@ -318,9 +344,9 @@
 }
 
 int
-CcnxWrapper::publishData (const Name &name, const unsigned char *buf, size_t len, int freshness)
+CcnxWrapper::publishData (const Name &name, const unsigned char *buf, size_t len, int freshness, const Name &keyName)
 {
-  Bytes co = createContentObject(name, buf, len, freshness);
+  Bytes co = createContentObject(name, buf, len, freshness, keyName);
   return putToCcnd(co);
 }
 
diff --git a/ccnx/ccnx-wrapper.h b/ccnx/ccnx-wrapper.h
index 3fd3c23..69bebbd 100644
--- a/ccnx/ccnx-wrapper.h
+++ b/ccnx/ccnx-wrapper.h
@@ -66,13 +66,13 @@
   sendInterest (const Name &interest, const Closure &closure, const Selectors &selector = Selectors());
 
   int
-  publishData (const Name &name, const unsigned char *buf, size_t len, int freshness = DEFAULT_FRESHNESS/* max value for ccnx*/);
+  publishData (const Name &name, const unsigned char *buf, size_t len, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
 
   inline int
-  publishData (const Name &name, const Bytes &content, int freshness = DEFAULT_FRESHNESS/* max value for ccnx*/);
+  publishData (const Name &name, const Bytes &content, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
 
   inline int
-  publishData (const Name &name, const std::string &content, int freshness = DEFAULT_FRESHNESS/* max value for ccnx*/);
+  publishData (const Name &name, const std::string &content, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
 
   int
   publishUnsignedData(const Name &name, const unsigned char *buf, size_t len, int freshness = DEFAULT_FRESHNESS);
@@ -87,7 +87,7 @@
   getLocalPrefix ();
 
   Bytes
-  createContentObject(const Name &name, const void *buf, size_t len, int freshness = DEFAULT_FRESHNESS/* max value for ccnx*/);
+  createContentObject(const Name &name, const void *buf, size_t len, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
 
   int
   putToCcnd (const Bytes &contentObject);
@@ -128,15 +128,15 @@
 typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
 
 inline int
-CcnxWrapper::publishData (const Name &name, const Bytes &content, int freshness)
+CcnxWrapper::publishData (const Name &name, const Bytes &content, int freshness, const Name &keyName)
 {
-  return publishData(name, head(content), content.size(), freshness);
+  return publishData(name, head(content), content.size(), freshness, keyName);
 }
 
 inline int
-CcnxWrapper::publishData (const Name &name, const std::string &content, int freshness)
+CcnxWrapper::publishData (const Name &name, const std::string &content, int freshness, const Name &keyName)
 {
-  return publishData(name, reinterpret_cast<const unsigned char *> (content.c_str ()), content.size (), freshness);
+  return publishData(name, reinterpret_cast<const unsigned char *> (content.c_str ()), content.size (), freshness, keyName);
 }
 
 inline int