A little bit closer to the action log functions
diff --git a/client/client.cc b/client/client.cc
index 8ab8013..df827ba 100644
--- a/client/client.cc
+++ b/client/client.cc
@@ -93,19 +93,13 @@
               if (ok == 0)
                 {
                   // Alex: the following code is platform specific :(
-                  
-                  char atimespec[26], mtimespec[26], ctimespec[26];
-                  ctime_r (&fileStats.st_atime, atimespec);
-                  ctime_r (&fileStats.st_mtime, mtimespec);
-                  ctime_r (&fileStats.st_ctime, ctimespec);
-
                   HashPtr fileHash = Hash::FromFileContent (argv[2]);
                   
                   notify->updateFile (argv[2],
                                       make_pair(reinterpret_cast<const ::Ice::Byte*> (fileHash->GetHash ()),
                                                 reinterpret_cast<const ::Ice::Byte*> (fileHash->GetHash ()) +
                                                 fileHash->GetHashBytes ()),
-                                      atimespec, mtimespec, ctimespec,
+                                      fileStats.st_atime, fileStats.st_mtime, fileStats.st_ctime,
                                       fileStats.st_mode);
                 }
               else
diff --git a/daemon/notify-i.cc b/daemon/notify-i.cc
index 0f8b004..43aa32e 100644
--- a/daemon/notify-i.cc
+++ b/daemon/notify-i.cc
@@ -32,9 +32,9 @@
 void
 NotifyI::updateFile (const ::std::string &filename,
                      const ::std::pair<const Ice::Byte*, const Ice::Byte*> &hashRaw,
-                     const ::std::string &atime,
-                     const ::std::string &mtime,
-                     const ::std::string &ctime,
+                     ::Ice::Long atime,
+                     ::Ice::Long mtime,
+                     ::Ice::Long ctime,
                      ::Ice::Int mode,
                      const ::Ice::Current&)
 {
diff --git a/daemon/notify-i.h b/daemon/notify-i.h
index a2cea97..42d4d7e 100644
--- a/daemon/notify-i.h
+++ b/daemon/notify-i.h
@@ -32,9 +32,9 @@
   virtual void
   updateFile (const ::std::string &filename,
               const ::std::pair<const Ice::Byte*, const Ice::Byte*> &hash,
-              const ::std::string &atime,
-              const ::std::string &mtime,
-              const ::std::string &ctime,
+              ::Ice::Long atime,
+              ::Ice::Long mtime,
+              ::Ice::Long ctime,
               ::Ice::Int mode,
               const ::Ice::Current& = ::Ice::Current());
 
diff --git a/include/ccnx-wrapper.h b/include/ccnx-wrapper.h
index 9b50ae8..4b9b3dd 100644
--- a/include/ccnx-wrapper.h
+++ b/include/ccnx-wrapper.h
@@ -60,9 +60,8 @@
   static string
   extractName(const unsigned char *data, const ccn_indexbuf *comps);
 
-protected:
   Bytes
-  createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
+  createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness = 2147/* max value for ccnx*/);
 
   int
   putToCcnd (const Bytes &contentObject);
diff --git a/src/action-item.proto b/src/action-item.proto
new file mode 100644
index 0000000..6d50065
--- /dev/null
+++ b/src/action-item.proto
@@ -0,0 +1,22 @@
+message ActionItem
+{
+  enum ActionType
+  {
+    UPDATE = 0;
+    DELETE = 1;
+  }
+  required ActionType action = 3;
+
+  required string filename = 4;
+  required uint64 version = 5;
+  required uint32 timestamp = 6;
+
+  optional bytes  file_hash = 7;
+  optional uint32 atime = 8;
+  optional uint32 mtime = 9;
+  optional uint32 ctime = 10;
+  optional uint32 mode  = 11;
+
+  optional string parent_device_name = 12;
+  optional uint64 parent_seq_no = 13;
+}
diff --git a/src/action-log.cc b/src/action-log.cc
index cf5156a..6d0c48b 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -20,50 +20,110 @@
  */
 
 #include "action-log.h"
+#include <action-item.pb.h>
 
 using namespace boost;
 using namespace std;
 
 ActionLog::ActionLog (const std::string &path, const std::string &localName)
-  : SyncLog (path)
-  , m_localName (localName)
+  : SyncLog (path, localName)
 {
 }
 
+tuple<sqlite3_int64, sqlite3_int64, sqlite3_int64>
+ActionLog::GetExistingRecord (const std::string &filename)
+{
+  // check if something already exists
+  sqlite3_stmt *stmt;
+  int res = sqlite3_prepare_v2 (m_db, "SELECT version,device_id,seq_no FROM ActionLog WHERE filename=? ORDER BY version DESC,device_id DESC LIMIT 1", -1, &stmt, 0);
+
+  if (res != SQLITE_OK)
+    {
+      BOOST_THROW_EXCEPTION (Error::Db ()
+                             << errmsg_info_str ("Some error with AddActionUpdate"));
+    }
+
+  sqlite3_bind_text (stmt, 1, filename.c_str (), filename.size (), SQLITE_STATIC);
+  if (sqlite3_step (stmt) == SQLITE_ROW)
+    {
+      // with parent with version number + 1
+      sqlite3_int64 version = sqlite3_column_int64 (stmt, 0) + 1;
+      sqlite3_int64 parent_device_id = sqlite3_column_int64 (stmt, 1);
+      sqlite3_int64 parent_seq_no = sqlite3_column_int64 (stmt, 0);
+
+      sqlite3_finalize (stmt);
+      return make_tuple (version, parent_device_id, parent_seq_no);
+    }
+
+  sqlite3_finalize (stmt);
+  return make_tuple ((sqlite3_int64)0, (sqlite3_int64)-1, (sqlite3_int64)-1);
+}
+
 // local add action. remote action is extracted from content object
 void
 ActionLog::AddActionUpdate (const std::string &filename,
                             const Hash &hash,
-                            const std::string &atime, const std::string &mtime, const std::string &ctime,
+                            time_t atime, time_t mtime, time_t ctime,
                             int mode)
 {
   int res = sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
+  
+  sqlite3_int64 seq_no = GetNextLocalSeqNo ();
+  sqlite3_int64 version = 0;
+  sqlite3_int64 parent_device_id = -1;
+  sqlite3_int64 parent_seq_no = -1;
 
-  // sqlite3_stmt *stmt;
-  // res += sqlite3_prepare_v2 (m_db, "SELECT version,device_id,seq_no FROM ActionLog WHERE filename=? ORDER BY version DESC,device_id DESC LIMIT 1", -1, &stmt, 0);
+  sqlite3_int64 action_time = time (0);
+  
+  tie (version, parent_device_id, parent_seq_no) = GetExistingRecord (filename);
+  
+  sqlite3_stmt *stmt;
+  sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
+                      "(device_id, seq_no, action, filename, version, action_timestamp, "
+                      "file_hash, file_atime, file_mtime, file_ctime, file_chmod, "
+                      "parent_device_id, parent_seq_no) "
+                      "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
+                      "        ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,"
+                      "        ?, ?)", -1, &stmt, 0);
 
-  // if (res != SQLITE_OK)
-  //   {
-  //     BOOST_THROW_EXCEPTION (Error::Db ()
-  //                            << errmsg_info_str ("Some error with AddActionUpdate"));
-  //   }
+  sqlite3_bind_int64 (stmt, 1, m_localDeviceId);
+  sqlite3_bind_int64 (stmt, 2, seq_no);
+  sqlite3_bind_int   (stmt, 3, 0);
+  sqlite3_bind_text  (stmt, 4, filename.c_str (), filename.size (), SQLITE_TRANSIENT);
+  sqlite3_bind_blob  (stmt, 5, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
 
-  // sqlite3_bind_text (stmt, 1, filename.c_str (), -1);
-  // if (sqlite3_step (stmt) == SQLITE_ROW)
-  //   {
-  //     // with parent
-  //     sqlite3_int64 version = sqlite3_value_int64 (stmt, 0) + 1;
-  //     sqlite3_int64 device_id = sqlite3_value_int64 (stmt, 1);
-  //     sqlite3_int64 seq_no = sqlite3_value_int64 (stmt, 0);
+  sqlite3_bind_int64 (stmt, 6, action_time);
+  
+  sqlite3_bind_int64 (stmt, 7, atime);
+  sqlite3_bind_int64 (stmt, 8, mtime);
+  sqlite3_bind_int64 (stmt, 9, ctime);
+  sqlite3_bind_int   (stmt, 10, mode);
 
-      
-  //   }
-  // else
-  //   {
-  //     // without parent
-      
-  //   }
+  if (parent_device_id > 0 && parent_seq_no > 0)
+    {
+      sqlite3_bind_int64 (stmt, 11, parent_device_id);
+      sqlite3_bind_int64 (stmt, 12, parent_seq_no);
+    }
+  else
+    {
+      sqlite3_bind_null (stmt, 11);
+      sqlite3_bind_null (stmt, 12);
+    }
+  
+  sqlite3_step (stmt);
 
+  // missing part: creating ContentObject for the action !!!
+
+  ActionItem item;
+  item.set_action (ActionItem::UPDATE);
+  item.set_filename (filename);
+  item.set_version (version);
+  item.set_timestamp (action_time);
+  item.set_file_hash (hash.GetHash (), hash.GetHashBytes ());
+  // item
+  
+  sqlite3_finalize (stmt); 
+                          
   res += sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
 }
 
diff --git a/src/action-log.h b/src/action-log.h
index 6827cba..0ffd64f 100644
--- a/src/action-log.h
+++ b/src/action-log.h
@@ -23,29 +23,30 @@
 #define ACTION_LOG_H
 
 #include "sync-log.h"
+#include <boost/tuple/tuple.hpp>
 
 class ActionLog : public SyncLog
 {
 public:
   ActionLog (const std::string &path, const std::string &localName);
 
-  
-  
-  
   void
   AddActionUpdate (const std::string &filename,
-                        const Hash &hash,
-                        const std::string &atime, const std::string &mtime, const std::string &ctime,
-                        int mode);
+                   const Hash &hash,
+                   time_t atime, time_t mtime, time_t ctime,
+                   int mode);
 
   void
   AddActionMove (const std::string &oldFile, const std::string &newFile);
-
+  
   void
   AddActionDelete (const std::string &filename);
+
+private:
+  boost::tuple<sqlite3_int64, sqlite3_int64, sqlite3_int64>
+  GetExistingRecord (const std::string &filename);
   
 protected:
-  std::string m_localName;
 };
 
 #endif // ACTION_LOG_H
diff --git a/src/chronoshare-client.ice b/src/chronoshare-client.ice
index be40c3e..e3bf8e2 100644
--- a/src/chronoshare-client.ice
+++ b/src/chronoshare-client.ice
@@ -25,7 +25,7 @@
   
   interface Notify 
   {
-    void updateFile (string filename, ["cpp:array"] HashBytes fileHash, string atime, string mtime, string ctime, int mode);
+    void updateFile (string filename, ["cpp:array"] HashBytes fileHash, long atime, long mtime, long ctime, int mode);
 
     void moveFile (string origFilename, string newFilename);
 
diff --git a/src/sync-log.cc b/src/sync-log.cc
index 3e49c69..93d4a3e 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -26,6 +26,51 @@
 using namespace boost;
 using namespace std;
 
+SyncLog::SyncLog (const std::string &path, const std::string &localName)
+  : DbHelper (path)
+  , m_localName (localName)
+{
+  UpdateDeviceSeqno (localName, 0);
+  
+  sqlite3_stmt *stmt;
+  int res = sqlite3_prepare_v2 (m_db, "SELECT device_id, seq_no FROM SyncNodes WHERE device_name=?", -1, &stmt, 0);
+  sqlite3_bind_text (stmt, 1, m_localName.c_str (), m_localName.size (), SQLITE_STATIC);
+
+  if (sqlite3_step (stmt) == SQLITE_ROW)
+    {
+      m_localDeviceId = sqlite3_column_int64 (stmt, 0);
+    }
+  else
+    {
+      BOOST_THROW_EXCEPTION (Error::Db ()
+                             << errmsg_info_str ("Impossible thing in SyncLog::SyncLog"));
+    }
+  sqlite3_finalize (stmt);
+}
+
+
+sqlite3_int64
+SyncLog::GetNextLocalSeqNo ()
+{
+  sqlite3_stmt *stmt_seq;
+  sqlite3_prepare_v2 (m_db, "SELECT seq_no FROM SyncNodes WHERE device_id = ?", -1, &stmt_seq, 0);
+  sqlite3_bind_int64 (stmt_seq, 1, m_localDeviceId);
+
+  if (sqlite3_step (stmt_seq) != SQLITE_ROW)
+    {
+      BOOST_THROW_EXCEPTION (Error::Db ()
+                             << errmsg_info_str ("Impossible thing in ActionLog::AddActionUpdate"));
+    }
+  
+  sqlite3_int64 seq_no = sqlite3_column_int64 (stmt_seq, 0) + 1; 
+  sqlite3_finalize (stmt_seq);
+
+  UpdateDeviceSeqNo (m_localDeviceId, seq_no);
+  
+  return seq_no;
+}
+
+
 HashPtr
 SyncLog::RememberStateInStateLog ()
 {
@@ -130,7 +175,7 @@
 }
 
 void
-SyncLog::UpdateDeviceSeqno (const std::string &name, uint64_t seqNo)
+SyncLog::UpdateDeviceSeqno (const std::string &name, sqlite3_int64 seqNo)
 {
   sqlite3_stmt *stmt;
   // update is performed using trigger
@@ -144,11 +189,32 @@
   if (res != SQLITE_OK)
     {
       BOOST_THROW_EXCEPTION (Error::Db ()
-                             << errmsg_info_str ("Some error with UpdateDeviceSeqno"));
+                             << errmsg_info_str ("Some error with UpdateDeviceSeqno (name)"));
     }
   sqlite3_finalize (stmt);
 }
 
+void
+SyncLog::UpdateDeviceSeqNo (sqlite3_int64 deviceId, sqlite3_int64 seqNo)
+{
+  sqlite3_stmt *stmt;
+  // update is performed using trigger
+  int res = sqlite3_prepare (m_db, "INSERT INTO SyncNodes (device_id, seq_no) VALUES (?,?);", 
+                             -1, &stmt, 0);
+
+  res += sqlite3_bind_int64 (stmt, 1, deviceId);
+  res += sqlite3_bind_int64 (stmt, 2, seqNo);
+  sqlite3_step (stmt);
+  
+  if (res != SQLITE_OK)
+    {
+      BOOST_THROW_EXCEPTION (Error::Db ()
+                             << errmsg_info_str ("Some error with UpdateDeviceSeqNo (id)"));
+    }
+  sqlite3_finalize (stmt);
+}
+
+
 SyncStateMsgPtr
 SyncLog::FindStateDifferences (const std::string &oldHash, const std::string &newHash)
 {
diff --git a/src/sync-log.h b/src/sync-log.h
index 5705e45..bef41a7 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -30,14 +30,17 @@
 class SyncLog : public DbHelper
 {
 public:
-  SyncLog (const std::string &path)
-    : DbHelper (path)
-  {
-  }
+  SyncLog (const std::string &path, const std::string &localName);
 
+  sqlite3_int64
+  GetNextLocalSeqNo (); // side effect: local seq_no will be increased
+
+  void
+  UpdateDeviceSeqNo (sqlite3_int64 deviceId, sqlite3_int64 seqNo);
+  
   // done
   void
-  UpdateDeviceSeqno (const std::string &name, uint64_t seqNo);
+  UpdateDeviceSeqno (const std::string &name, sqlite3_int64 seqNo);
 
   // std::string
   // LookupForwardingAlias (const std::string &deviceName);
@@ -66,6 +69,11 @@
 
   SyncStateMsgPtr
   FindStateDifferences (const Hash &oldHash, const Hash &newHash);  
+
+protected:
+  std::string m_localName;
+  sqlite3_int64 m_localDeviceId;
+  
 };
 
 
diff --git a/wscript b/wscript
index f221147..4c6b7c5 100644
--- a/wscript
+++ b/wscript
@@ -111,6 +111,7 @@
                   'src/sync-log.cc',
                   'src/action-log.cc',
                   'src/sync-state.proto',
+                  'src/action-item.proto',
                   ],
         use = "BOOST CCNX SSL SQLITE3 ICE common",
         includes = ['include', 'src'],