Adding and finishing test for adding remotely fetched actions
diff --git a/ccnx/ccnx-common.h b/ccnx/ccnx-common.h
index 96f60ff..6d17116 100644
--- a/ccnx/ccnx-common.h
+++ b/ccnx/ccnx-common.h
@@ -89,9 +89,9 @@
 inline BytesPtr
 serializeMsg(const Msg &msg)
 {
-  int size = msg->ByteSize ();
+  int size = msg.ByteSize ();
   BytesPtr bytes (new Bytes (size));
-  msg->SerializeToArray (head(*bytes), size);
+  msg.SerializeToArray (head(*bytes), size);
   return bytes;
 }
 
diff --git a/ccnx/ccnx-name.h b/ccnx/ccnx-name.h
index 72f790a..b32c419 100644
--- a/ccnx/ccnx-name.h
+++ b/ccnx/ccnx-name.h
@@ -137,6 +137,9 @@
   Name
   getPartialName(int start, int n = -1) const;
 
+  inline Name
+  getPartialNameFromBack(int start, int n = -1) const;
+
   std::string
   toString() const;
 
@@ -181,6 +184,12 @@
   return getCompAsInt (m_comps.size () - 1 - index);
 }
 
+Name
+Name::getPartialNameFromBack(int start, int n/* = -1*/) const
+{
+  return getPartialName (m_comps.size () - 1 - start, n);
+}
+
 
 } // Ccnx
 #endif
diff --git a/src/action-log.cc b/src/action-log.cc
index 6254e1e..becbfe3 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -498,6 +498,25 @@
   Name name = actionPco->name ();
   // <device_name>/"action"/<shared_folder_name_one_component>/<seqno>
 
+  uint64_t seqno = name.getCompFromBackAsInt (0);
+  string sharedFolder = name.getCompFromBackAsString (1);
+
+  if (sharedFolder != m_sharedFolderName)
+    {
+      BOOST_THROW_EXCEPTION (Error::ActionLog () << errmsg_info_str ("Action doesn't belong to this shared folder"));
+    }
+
+  string action = name.getCompFromBackAsString (2);
+
+  if (action != "action")
+    {
+      BOOST_THROW_EXCEPTION (Error::ActionLog () << errmsg_info_str ("not an action"));
+    }
+  Name deviceName = name.getPartialName (0, name.size ()-3);
+
+  _LOG_DEBUG ("From [" << name << "] extracted deviceName: " << deviceName << ", sharedFolder: " << sharedFolder << ", seqno: " << seqno);
+
+  AddRemoteAction (deviceName, seqno, actionPco);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////
diff --git a/src/file-item.proto b/src/file-item.proto
new file mode 100644
index 0000000..937226b
--- /dev/null
+++ b/src/file-item.proto
@@ -0,0 +1,18 @@
+message FileItem
+{
+  enum FileType
+  {
+    LATEST = 0;
+    OLDEST = 1;
+  }
+  required FileType type = 1;
+
+  required string filename = 2;
+  required bytes  device_name = 3;
+  required uint64 seq_no = 4;
+
+  required bytes  file_hash = 5;
+  required uint32 mtime = 6;
+  required uint32 mode  = 7;
+  required uint64 seg_num = 8;
+}
diff --git a/src/sync-core.cc b/src/sync-core.cc
index d85093b..9d2003d 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -82,7 +82,7 @@
 
   // reply sync Interest with oldHash as last component
   Name syncName = Name (m_syncPrefix)(oldHash->GetHash(), oldHash->GetHashBytes());
-  BytesPtr syncData = serializeMsg (msg);
+  BytesPtr syncData = serializeMsg (*msg);
 
   m_ccnx->publishData(syncName, *syncData, FRESHNESS);
   _LOG_TRACE (m_log->GetLocalName () << " publishes: " << *oldHash);
@@ -125,7 +125,7 @@
     // we know the hash, should reply everything
     SyncStateMsgPtr msg = m_log->FindStateDifferences(*(Hash::Origin), *m_rootHash);
 
-    BytesPtr syncData = serializeMsg (msg);
+    BytesPtr syncData = serializeMsg (*msg);
     m_ccnx->publishData(name, *syncData, FRESHNESS);
     _LOG_TRACE (m_log->GetLocalName () << " publishes " << hash);
     _LOG_TRACE (msg);
@@ -153,7 +153,7 @@
     _LOG_TRACE ("found hash in sync log");
     SyncStateMsgPtr msg = m_log->FindStateDifferences(*hash, *m_rootHash);
 
-    BytesPtr syncData = serializeMsg (msg);
+    BytesPtr syncData = serializeMsg (*msg);
     m_ccnx->publishData(name, *syncData, FRESHNESS);
     _LOG_TRACE (m_log->GetLocalName () << " publishes: " << *hash);
     _LOG_TRACE (msg);
diff --git a/test/test-action-log.cc b/test/test-action-log.cc
index efa485f..985af5c 100644
--- a/test/test-action-log.cc
+++ b/test/test-action-log.cc
@@ -110,6 +110,24 @@
   BOOST_CHECK_EQUAL (action->parent_seq_no (), 1);
   BOOST_CHECK_EQUAL (action->version (), 1);
 
+  BOOST_CHECK_NO_THROW (actionLog->AddRemoteAction (pco));
+  BOOST_CHECK_EQUAL (actionLog->LogSize (), 2);
+
+  // create a real remote action
+  ActionItem item;
+  item.set_action (ActionItem::UPDATE);
+  item.set_filename ("file.txt");
+  item.set_version (2);
+  item.set_timestamp (time (NULL));
+
+  BytesPtr item_msg = serializeMsg (item);
+  Name actionName = Name ("/zhenkai")("action")("top-secret")(1);
+  Bytes actionData = ccnx->createContentObject (actionName, head (*item_msg), item_msg->size ());
+
+  pco = make_shared<ParsedContentObject> (actionData);
+  BOOST_CHECK_NO_THROW (actionLog->AddRemoteAction (pco));
+  BOOST_CHECK_EQUAL (actionLog->LogSize (), 3);
+
   remove_all (tmpdir);
 }