implement c api wrapper
diff --git a/ccnx/sync-app-socket-c.cc b/ccnx/sync-app-socket-c.cc
index 4bdf384..cefd73c 100644
--- a/ccnx/sync-app-socket-c.cc
+++ b/ccnx/sync-app-socket-c.cc
@@ -21,29 +21,83 @@
  */
 
 #include "sync-app-socket.h"
+#include <boost/shared_array.hpp>
 using namespace std;
 using namespace Sync;
 
-class CallbackHolder{
+struct SyncAppSocketStruct;
+struct MissingDataInfoC
+{
+  const char *prefix;
+  int session;
+  int low;
+  int high;
+};
+
+class CallbackHolder {
 private:
   void (*m_callback)(const char *, const char *);
 
 public:
-  CallbackHolder(void (*callback)(const char*, const char*)):m_callback(callback){};
-  void callbackWrapper(string name, string data) {
-    m_callback(name.c_str(), data.c_str());
+  CallbackHolder(void (*callback)(const char*, const char*))
+    :m_callback(callback){};
+  
+  void callbackWrapper(const string &name, const string &data) {
+    if (m_callback != NULL)
+      (*m_callback)(name.c_str(), data.c_str());
   }
 };
 
-struct SyncAppSocketStruct;
+class UpdateCallbackHolder {
+private:
+  void (*m_callback)(const struct MissingDataInfoC*, const int, const SyncAppSocketStruct*);
+
+public:
+  UpdateCallbackHolder(void (*callback)(
+        const MissingDataInfoC*, 
+        const int, 
+        const SyncAppSocketStruct*))
+    :m_callback(callback){};
+
+  void callbackWrapper(const vector<MissingDataInfo> &mdi, SyncAppSocket* socket) {
+    boost::shared_array<MissingDataInfoC> mdic(new MissingDataInfoC[mdi.size()]);
+    int i;
+    
+    for (i = 0; i < mdi.size(); i++)
+    {
+      mdic[i].prefix = mdi[i].prefix.c_str();
+      mdic[i].session = mdi[i].low.getSession();
+      mdic[i].low = mdi[i].low.getSeq();
+      mdic[i].high = mdi[i].high.getSeq();
+    }
+    if (m_callback != NULL)
+      (*m_callback)(mdic.get(), i, (const SyncAppSocketStruct*) socket);
+  }
+};
+
+class RemoveCallbackHolder {
+private:
+  void (*m_callback)(const char*);
+
+public:
+  RemoveCallbackHolder(void (*callback)(const char*)):m_callback(callback){};
+  void callbackWrapper(const string &prefix) {
+    if (m_callback != NULL)
+      (*m_callback)(prefix.c_str());
+  }
+};
 
 extern "C"
 SyncAppSocketStruct *
-create_sync_app_socket(const char *prefix, void (*callback)(const char *, const char *)) 
+create_sync_app_socket(const char *prefix, 
+    void (*updatecallback)(const MissingDataInfoC*, const int, const SyncAppSocketStruct*),
+    void (*removecallback)(const char *))
 {
-  CallbackHolder *holder = new CallbackHolder(callback);
-  boost::function<void (string, string)> cb = bind(&CallbackHolder::callbackWrapper, holder, _1, _2);
-  SyncAppSocket *sock = new SyncAppSocket(prefix, cb);
+  boost::shared_ptr<UpdateCallbackHolder> uh(new UpdateCallbackHolder(updatecallback));
+  boost::shared_ptr<RemoveCallbackHolder> rh(new RemoveCallbackHolder(removecallback));
+  boost::function<void (const vector<MissingDataInfo>&, SyncAppSocket*)> ucb = bind(&UpdateCallbackHolder::callbackWrapper, uh, _1, _2);
+  boost::function<void (const string&)> rcb = bind(&RemoveCallbackHolder::callbackWrapper, rh, _1);
+  SyncAppSocket *sock = new SyncAppSocket(prefix, ucb, rcb);
   return (SyncAppSocketStruct *) sock;
 }
 
@@ -61,14 +115,28 @@
 int
 sync_app_socket_publish(SyncAppSocketStruct *sock, const char *prefix, int session, const char *buf, int freshness) 
 {
-  SyncAppSocket *temp = (SyncAppSocket *)sock;
-  return temp->publish(prefix, session, buf, freshness);
+  SyncAppSocket *temp = (SyncAppSocket*) sock;
+  return temp->publishString(prefix, session, buf, freshness);
 }
 
 extern "C"
 void
 sync_app_socket_remove(SyncAppSocketStruct *sock, const char *prefix) 
 {
-  SyncAppSocket *temp = (SyncAppSocket *)sock;
+  SyncAppSocket *temp = (SyncAppSocket*) sock;
   temp->remove(prefix);
 }
+
+extern "C"
+void
+sync_app_socket_fetch(SyncAppSocketStruct *sock, const char *prefix, int session, int sequence, 
+    void (*callback)(const char*, const char*), int retry = 0)
+{
+  SyncAppSocket *temp = (SyncAppSocket*) sock;
+  string s(prefix);
+  SeqNo seq(session, sequence);
+  boost::shared_ptr<CallbackHolder> h(new CallbackHolder(callback));
+  boost::function<void (const string&, const string&)> cb = bind(&CallbackHolder::callbackWrapper, h, _1, _2);
+
+  temp->fetchString(s, seq, cb, retry);
+}