Extending ccnx-name and fixing bug with toString
diff --git a/src/action-log.cc b/src/action-log.cc
index c63424d..ff8e257 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -24,9 +24,12 @@
 
 using namespace boost;
 using namespace std;
+using namespace Ccnx;
 
-ActionLog::ActionLog (const std::string &path, const std::string &localName)
+ActionLog::ActionLog (Ccnx::CcnxWrapperPtr ccnx, const std::string &path, const std::string &localName, const std::string &sharedFolder)
   : SyncLog (path, localName)
+  , m_ccnx (ccnx)
+  , m_sharedFolderName (sharedFolder)
 {
   int res = sqlite3_create_function (m_db, "apply_action", -1, SQLITE_ANY, reinterpret_cast<void*> (this),
                                  ActionLog::apply_action_xFun,
@@ -163,8 +166,8 @@
 
   if (parent_device_id > 0 && parent_seq_no > 0)
     {
-      cout << Ccnx::Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
-                          parent_device_name.size ()) << endl;
+      cout << Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
+                    parent_device_name.size ()) << endl;
       
       item.set_parent_device_name (parent_device_name);
       item.set_parent_seq_no (parent_seq_no);
@@ -222,10 +225,7 @@
 
   sqlite3_bind_int64 (stmt, 7, parent_device_id);
   sqlite3_bind_int64 (stmt, 8, parent_seq_no);
-  
-  sqlite3_step (stmt);
 
-  // missing part: creating ContentObject for the action !!!
 
   ActionItem item;
   item.set_action (ActionItem::UPDATE);
@@ -235,8 +235,25 @@
   item.set_parent_device_name (parent_device_name);
   item.set_parent_seq_no (parent_seq_no);
 
-  cout << Ccnx::Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
-                      parent_device_name.size ()) << endl;
+  string item_msg;
+  item.SerializeToString (&item_msg);
+  Name actionName (m_localName);
+  actionName
+    .appendComp ("action")
+    .appendComp (m_sharedFolderName)
+    .appendComp (reinterpret_cast<void*> (seq_no), sizeof (seq_no));
+  
+  // Bytes actionData = m_ccnx->createContentObject (?name, item_msg.c_str (), item_msg.size ());
+
+  
+  // sqlite3_bind_blob (stmt, 10, item_msg.c_str (), item_msg.size (), SQLITE_TRANSIENT);
+  
+  sqlite3_step (stmt);
+
+
+  
+  // cout << Ccnx::Name (reinterpret_cast<const unsigned char *> (parent_device_name.c_str ()),
+  //                     parent_device_name.size ()) << endl;
   
   // assign name to the action, serialize action, and create content object
   
diff --git a/src/action-log.h b/src/action-log.h
index f6cc0a7..323f6a3 100644
--- a/src/action-log.h
+++ b/src/action-log.h
@@ -24,6 +24,7 @@
 
 #include "sync-log.h"
 #include <boost/tuple/tuple.hpp>
+#include <ccnx-wrapper.h>
 
 class ActionLog;
 typedef boost::shared_ptr<ActionLog> ActionLogPtr;
@@ -31,7 +32,7 @@
 class ActionLog : public SyncLog
 {
 public:
-  ActionLog (const std::string &path, const std::string &localName);
+  ActionLog (Ccnx::CcnxWrapperPtr ccnx, const std::string &path, const std::string &localName, const std::string &sharedFolder);
 
   void
   AddActionUpdate (const std::string &filename,
@@ -52,7 +53,9 @@
   static void
   apply_action_xFun (sqlite3_context *context, int argc, sqlite3_value **argv);
   
-protected:
+private:
+  Ccnx::CcnxWrapperPtr m_ccnx;
+  Ccnx::Name m_sharedFolderName;
 };
 
 #endif // ACTION_LOG_H
diff --git a/src/ccnx-name.cpp b/src/ccnx-name.cpp
index 3803987..28761dd 100644
--- a/src/ccnx-name.cpp
+++ b/src/ccnx-name.cpp
@@ -165,10 +165,59 @@
 Name::appendComp(const string &compStr)
 {
   Bytes comp(compStr.begin(), compStr.end());
-  appendComp(comp);
+  return appendComp(comp);
+}
+
+Name &
+Name::appendComp(const Name &name)
+{
+  for (vector<Bytes>::const_iterator i = name.m_comps.begin (); i != name.m_comps.end (); i++)
+    {
+      appendComp (*i);
+    }
   return *this;
 }
 
+Name &
+Name::appendComp (const void *buf, size_t size)
+{
+  Bytes comp (reinterpret_cast<const unsigned char*> (buf), reinterpret_cast<const unsigned char*> (buf) + size);
+  return appendComp(comp);
+}
+
+Name &
+Name::appendComp(uint64_t number)
+{
+  Bytes comp;
+  comp.push_back (0);
+  
+  while (number > 0)
+    {
+      comp.push_back (static_cast<unsigned char> (number & 0xFF));
+      number >>= 8;
+    }
+  return appendComp (comp);
+}
+
+uint64_t
+Name::getCompAsInt (int index) const
+{
+  Bytes comp = getComp(index);
+  if (comp.size () < 1 ||
+      comp[0] != 0)
+    {
+      boost::throw_exception(NameException()
+                             << error_info_str("Non integer component: " + getCompAsString(index)));
+    }
+  uint64_t ret = 0;
+  for (int i = comp.size () - 1; i >= 1; i--)
+    {
+      ret <<= 8;
+      ret |= comp [i];
+    }
+  return ret;
+}
+
 Bytes
 Name::getComp(int index) const
 {
@@ -194,7 +243,7 @@
     }
     else
     {
-      ss << "%" << hex << setfill('0') << setw(2) << ch;
+      ss << "%" << hex << setfill('0') << setw(2) << (unsigned int)ch;
     }
   }