Patch for pilot-link




I don't remember if I sent you this patch yet or not but, just in case,
here it goes.

I mailed you earlier about completing the pi-sync stuff so that the gnome
people could use it in the gnome-pilot project.  I also asked if it was ok
to make some data type changes to solve potential problems on 64bit
machines.  In any case, much of the SyncAbs API and back end code has been
finished and is in use in some gnome-pilot conduits, largely due to the
work of Eskil Heyn Olsen.  I did most of the datatype changes that I
thought might be troublesome but still haven't been able to test on a
64bit system :(. 

I have attached a patch versus pilot-link.0.8.13 to this message.

Before building you should rerun aclocal and autoconf and all the fun gnu
configure stuff that needs to be run :), due to autoconf changes.

Please let me know if there are any problems. 

Thanks

Manish

Manish Vachharajani               Some Haiku: A crash reduces
<mvachhar@vger.rutgers.edu>                   your expensive computer
                                              to a simple stone - Unknown
Index: pilot-link/configure.in
diff -u pilot-link/configure.in:1.1.1.1 pilot-link/configure.in:1.2
--- pilot-link/configure.in:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/configure.in	Sat Jul 25 05:05:46 1998
@@ -547,7 +547,14 @@
 AC_SUBST(CPLIB)
 AC_SUBST(ARFLAGS)
 
-AC_CONFIG_HEADER(include/pi-config.h include/pi-sockaddr.h)
+AC_CHECK_SIZEOF(char)
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(void *)
+AC_CHECK_SIZEOF(long long)
+
+AC_CONFIG_HEADER(include/pi-types.h include/pi-config.h include/pi-sockaddr.h)
 
 if test $ac_cv_prog_cxx_works = yes; then
   cc_m='libcc/Makefile'
Index: pilot-link/pilot-file.c
diff -u pilot-link/pilot-file.c:1.1.1.1 pilot-link/pilot-file.c:1.2
--- pilot-link/pilot-file.c:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/pilot-file.c	Tue Oct 20 23:42:48 1998
@@ -182,7 +182,7 @@
   printf ("creation_time: %s\n", iso_time_str (ip->createDate));
   printf ("modified_time: %s\n", iso_time_str (ip->modifyDate));
   printf ("backup_time: %s\n", iso_time_str (ip->backupDate));
-  printf ("modification_number: %ld\n", ip->modnum);
+  printf ("modification_number: %d\n", ip->modnum);
   printf ("type: '%s', ", printlong(ip->type));
   printf ("creator: '%s'\n", printlong(ip->creator));
   printf ("\n");
@@ -225,7 +225,8 @@
 {
   int entnum;
   int size;
-  unsigned long type, uid;
+  unsigned long type;
+  pi_uid_t uid;
   int id;
   void *buf;
   int nentries;
@@ -266,7 +267,7 @@
         printf ("error reading %d\n\n", entnum);
         return;
       }
-      printf ("%d\t%d\t0x%x\t%d\t0x%lx\n", entnum, size, attrs, cat, uid);
+      printf ("%d\t%d\t0x%x\t%d\t0x%x\n", entnum, size, attrs, cat, uid);
       if (vflag) {
         dump(buf,size);
         printf ("\n");
@@ -281,8 +282,9 @@
 dump_record (struct pi_file *pf, struct DBInfo *ip, int record)
 {
   int size;
-  unsigned long type, uid;
-  int id;
+  unsigned long type;
+  pi_uid_t uid;
+  recordid_t id;
   void *buf;
   int attrs, cat;
 
@@ -312,7 +314,7 @@
       printf ("error reading record #%d\n\n", record);
       return;
     }
-    printf ("%d\t%d\t0x%x\t%d\t0x%lx\n", record, size, attrs, cat, uid);
+    printf ("%d\t%d\t0x%x\t%d\t0x%x\n", record, size, attrs, cat, uid);
     dump(buf,size);
   }
 
Index: pilot-link/dubious/sync-ical.c
diff -u pilot-link/dubious/sync-ical.c:1.1.1.1 pilot-link/dubious/sync-ical.c:1.2
--- pilot-link/dubious/sync-ical.c:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/dubious/sync-ical.c	Sun Jul 26 02:15:10 1998
@@ -105,15 +105,17 @@
 
 
 /* Define our own LocalRecord type. */
-struct LocalRecord {
-     StandardLocalRecord;
+struct IcalLocalRecord {
+     LocalRecord standard;
      char * item; /* non-null and a name if an Ical item */
      unsigned long deleted;  /* non-null if only a deletion ID */
 };
-                                        
+
+typedef struct IcalLocalRecord IcalLocalRecord;           
+                             
 /* Define our own SyncAbs type */
-struct SyncAbs {
-     StandardSyncAbs;
+struct IcalSyncAbs {
+     SyncAbs standard;
      /* items down here are equivalent of C++ class data.
      Any information needed to talk to databases, etc., goes in here.
       */
@@ -122,9 +124,11 @@
     int todo; /* Are we interested in todos or memos? */
 };
 
+typedef struct IcalSyncAbs IcalSyncAbs;
+
 /* Get a Pilot ID for a local record, or 0 if no Pilot ID has been set. Any
    local ID mechanism is not relevent, only IDs given by the Pilot. */
-unsigned long GetPilotID(SyncAbs * thisSA,LocalRecord * Local) {
+unsigned long GetPilotID(IcalSyncAbs * thisSA,IcalLocalRecord * Local) {
 	char * var;
 	/*char id[10];*/
 
@@ -146,7 +150,7 @@
 }
 
 /* Set the ID on a local record to match a given Pilot ID. */
-int SetPilotID(SyncAbs * thisSA,LocalRecord * Local, unsigned long ID) {
+int SetPilotID(IcalSyncAbs * thisSA,IcalLocalRecord * Local, unsigned long ID) {
 	char buf[40];
 	sprintf(buf,"%d%lu", thisSA->todo?1:0, ID);
 	Tcl_VarEval(thisSA->ical, Local->item, " option sync_id ",buf,NULL);
@@ -154,10 +158,10 @@
 }
 
 /* Given a PilotRecord, try and find a local record with a matching ID */
-int MatchRecord(SyncAbs * thisSA,  LocalRecord ** Local, PilotRecord * p) {
-	static LocalRecord lr;
+int MatchRecord(IcalSyncAbs * thisSA,  IcalLocalRecord ** Local, PilotRecord * p) {
+	static IcalLocalRecord lr;
 	char buf[40];
-	sprintf(buf,"%d%lu", thisSA->todo?1:0, p->ID);
+	sprintf(buf,"%d%u", thisSA->todo?1:0, p->ID);
 	
 	/* Check active items */
 	Tcl_VarEval(thisSA->ical,
@@ -205,16 +209,16 @@
 	}
 }
 
-/* Free up the LocalRecord returned by MatchRecord */
-int FreeMatch(SyncAbs * thisSA,LocalRecord ** Local) {
+/* Free up the IcalLocalRecord returned by MatchRecord */
+int FreeMatch(IcalSyncAbs * thisSA,IcalLocalRecord ** Local) {
 	*Local = 0;
 	return 0;
 }
 
 
-/* Iterate over all LocalRecords, in arbitrary order */
-int Iterate(SyncAbs * thisSA, LocalRecord ** Local) {
-	static LocalRecord lr;
+/* Iterate over all IcalLocalRecords, in arbitrary order */
+int Iterate(IcalSyncAbs * thisSA, IcalLocalRecord ** Local) {
+	static IcalLocalRecord lr;
 	
 	if (!*Local) {
 	  Tcl_VarEval(thisSA->ical,
@@ -267,9 +271,9 @@
 }
 
 /* Iterate over local records of a specified type. */
-int IterateSpecific(SyncAbs * thisSA, LocalRecord ** Local, int flag, int archived)
+int IterateSpecific(IcalSyncAbs * thisSA, IcalLocalRecord ** Local, int flag, int archived)
 {
-	static LocalRecord lr;
+	static IcalLocalRecord lr;
 	
 	if (!*Local) {
 	  Tcl_VarEval(thisSA->ical,
@@ -321,7 +325,7 @@
 }
 
 /* Given a PilotRecord, store it in the local database */
-int StoreRemote(SyncAbs * thisSA,PilotRecord* p) {
+int StoreRemote(IcalSyncAbs * thisSA,PilotRecord* p) {
 	struct Appointment a;
 	int j;
 	char buf[256];
@@ -344,7 +348,7 @@
 	  sprintf(buf, "%d", end-start+1);
 	  Tcl_VarEval(thisSA->ical,"$i length ",buf, NULL);
 	}
-	sprintf(buf, "%lu", p->ID);
+	sprintf(buf, "%u", p->ID);
         Tcl_VarEval(thisSA->ical,"$i option sync_id ",buf, NULL);
 	
         Tcl_VarEval(thisSA->ical,"$i text ",tclquote(a.description), NULL);
@@ -407,7 +411,7 @@
 
 
 /* Delete all local records */
-int DeleteAll(SyncAbs * thisSA) {
+int DeleteAll(IcalSyncAbs * thisSA) {
 
 	Tcl_VarEval(thisSA->ical,
 	  thisSA->cal," incalendar [", thisSA->cal, " main] item {\n",
@@ -427,20 +431,20 @@
 
 /* Get a Pilot ID for a local record, or 0 if no Pilot ID has been set. Any
    local ID mechanism is not relevent, only IDs given by the Pilot. */
-unsigned long GetPilotID(SyncAbs * thisSA,LocalRecord * Local) {
+unsigned long GetPilotID(IcalSyncAbs * thisSA,IcalLocalRecord * Local) {
 	return Local->ID;
 	return 1;
 }
 
 /* Set the ID on a local record to match a given Pilot ID. */
-int SetPilotID(SyncAbs * thisSA,LocalRecord * Local, unsigned long ID) {
+int SetPilotID(IcalSyncAbs * thisSA,IcalLocalRecord * Local, unsigned long ID) {
 	Local->ID = ID;
 	return 1;
 }
 
 /* Given a PilotRecord, try and find a local record with a matching ID */
-int MatchRecord(SyncAbs * thisSA,  LocalRecord ** Local, PilotRecord * p) {
-	LocalRecord * m = memos;
+int MatchRecord(IcalSyncAbs * thisSA,  IcalLocalRecord ** Local, PilotRecord * p) {
+	IcalLocalRecord * m = memos;
 	while(m) {
 		if(m->ID == p->ID)
 			break;
@@ -454,15 +458,15 @@
 	return 1;
 }
 
-/* Free up the LocalRecord returned by MatchRecord */
-int FreeMatch(SyncAbs * thisSA,LocalRecord ** Local) {
+/* Free up the IcalLocalRecord returned by MatchRecord */
+int FreeMatch(IcalSyncAbs * thisSA,IcalLocalRecord ** Local) {
 	*Local = 0;
 	return 0;
 }
 
-/* Iterate over all LocalRecords, in arbitrary order */
-int Iterate(SyncAbs * thisSA, LocalRecord ** Local) {
-	LocalRecord * m = *Local;
+/* Iterate over all IcalLocalRecords, in arbitrary order */
+int Iterate(IcalSyncAbs * thisSA, IcalLocalRecord ** Local) {
+	IcalLocalRecord * m = *Local;
 	if( !m) {
 		m = memos;
 	} else {
@@ -473,8 +477,8 @@
 }
 
 /* Iterate over local records of a specified type. */
-int IterateSpecific(SyncAbs * thisSA, LocalRecord ** Local, int flag, int archived) {
-	LocalRecord * m = *Local;
+int IterateSpecific(IcalSyncAbs * thisSA, IcalLocalRecord ** Local, int flag, int archived) {
+	IcalLocalRecord * m = *Local;
 	if( !m) {
 		m = memos;
 	} else {
@@ -495,7 +499,7 @@
 }
 
 /* Set status of local record */
-int SetStatus(SyncAbs * thisSA,LocalRecord * Local, int status) {
+int SetStatus(IcalSyncAbs * thisSA,IcalLocalRecord * Local, int status) {
 	Local->attr = status;
 	return 0;
 }
@@ -503,7 +507,7 @@
 /* There is no GetStatus, the abstract layer uses Local->attr */
 
 /* Set archival status of local record */
-int SetArchived(SyncAbs * thisSA,LocalRecord * Local,int archived) {
+int SetArchived(IcalSyncAbs * thisSA,IcalLocalRecord * Local,int archived) {
         Local->archived = archived;
 	return 0;
 }
@@ -511,8 +515,8 @@
 /* There is no GetStatus, the abstract layer uses Local->archived */
 
 /* Given a PilotRecord, store it in the local database */
-int StoreRemote(SyncAbs * thisSA,PilotRecord* p) {
-	LocalRecord * m;
+int StoreRemote(IcalSyncAbs * thisSA,PilotRecord* p) {
+	IcalLocalRecord * m;
 	int h;
 	struct stat stbuf;
 	
@@ -535,7 +539,7 @@
 		}
 	}
 	/* new record */
-	m = (LocalRecord*)malloc(sizeof(LocalRecord));
+	m = (IcalLocalRecord*)malloc(sizeof(IcalLocalRecord));
 	m->ID = p->ID;
 	m->attr = p->attr;
 	m->secret = p->secret;
@@ -558,7 +562,7 @@
 
 /* Given a local record, construct a PilotRecord suitable for transmission
 to a Pilot */
-PilotRecord * Transmit(SyncAbs* thisSA ,LocalRecord* Local) {
+PilotRecord * Transmit(IcalSyncAbs* thisSA ,IcalLocalRecord* Local) {
         static PilotRecord p;
 	int h = open(filename(Local->name),O_RDONLY);
 	
@@ -579,13 +583,13 @@
 }
 
 /* Free PilotRecord created by Transmit */
-int FreeTransmit(SyncAbs* thisSA,LocalRecord* Local,PilotRecord* Remote) {
+int FreeTransmit(IcalSyncAbs* thisSA,IcalLocalRecord* Local,PilotRecord* Remote) {
 	free(Remote->record);
 	return 0;
 }
 
 /* Find a local backup record and compare it to the pilot record for inequality */
-int CompareBackup(SyncAbs * thisSA, LocalRecord* m, PilotRecord* p) {
+int CompareBackup(IcalSyncAbs * thisSA, IcalLocalRecord* m, PilotRecord* p) {
 	char buffer[0xffff];
 	int r,len;
 
@@ -607,7 +611,7 @@
 }
 
 /* Compare a local record and pilot record for inequality */
-int Compare(SyncAbs * thisSA, LocalRecord * m, PilotRecord* p) {
+int Compare(IcalSyncAbs * thisSA, IcalLocalRecord * m, PilotRecord* p) {
 	char buffer[0xffff];
   	int r = open(filename(m->name),O_RDONLY);
   	int len = read(r,buffer,0xffff);
@@ -623,9 +627,9 @@
 }
 
 /* Delete all local records */
-int DeleteAll(SyncAbs * thisSA) {
+int DeleteAll(IcalSyncAbs * thisSA) {
 	while(memos) {
-		LocalRecord * m = memos;
+		IcalLocalRecord * m = memos;
 		memos = memos->next;
 		if(m->attr != RecordDeleted) {
 			unlink(filename(m->name));
@@ -637,9 +641,9 @@
 
 /* Do a local purge, deleting all records marked Deleted, and
    archiving all records marked for archiving */
-int Purge(SyncAbs * thisSA) {
-	LocalRecord * prev = 0;
-	LocalRecord * m = memos, *next;
+int Purge(IcalSyncAbs * thisSA) {
+	IcalLocalRecord * prev = 0;
+	IcalLocalRecord * m = memos, *next;
 	while(m) {
 		next = m->next;
 		if((m->attr == RecordDeleted) || (m->archived)) {
@@ -657,7 +661,7 @@
 }
 
 /* Add remote record to archive. l is non-NULL if there is a matching local record */
-int ArchiveRemote(SyncAbs * s, LocalRecord * l, PilotRecord * p) {
+int ArchiveRemote(IcalSyncAbs * s, IcalLocalRecord * l, PilotRecord * p) {
 	char name[256];
 	int h;
 	strcpy(name,"Memos/Archive/memoXXXXXX");
@@ -682,7 +686,7 @@
 typedef struct {
 	char recname[40];
 	long PilotID;
-} LocalRecord;*/
+} IcalLocalRecord;*/
 
 void dosend(char*text, int w) {
 	write(w,text,strlen(text));
@@ -702,36 +706,36 @@
   struct PilotUser U;
   int in[2], out[2];
   int ret;
-  struct SyncAbs abs;
-  /*struct SyncAbs abs;*/
+  struct IcalSyncAbs abs;
+  /*struct IcalSyncAbs abs;*/
 /*   = {MatchRecord, IsNew, IsModified, IsArchived, IsNothing,
                         AppendLocal, AppendArchive, StartIterator, NextIterator};*/
   /*LocalData ld;
-  LocalRecord *lrp;*/
+  IcalLocalRecord *lrp;*/
   Tcl_Interp ical;
 
 #if 0
   /* Set up abstraction structure */  
-  abs.MatchRecord = MatchRecord;
-  abs.Iterate = Iterate;
-  abs.IterateSpecific = IterateSpecific;
-  abs.SetStatus = SetStatus;
-  abs.SetArchived = SetArchived;
-  abs.SetPilotID = SetPilotID;
-  abs.GetPilotID = GetPilotID;
-  abs.StoreRemote = StoreRemote;
-  abs.ArchiveLocal = 0;             /* missing */
-  abs.ClearStatusArchiveLocal = 0;  /* likewise */
-  abs.ArchiveRemote = ArchiveRemote;
-  abs.DeleteAll = DeleteAll;
-  abs.Purge = Purge;
-  abs.CompareBackup = CompareBackup;
-  abs.Compare = Compare;
-  abs.Transmit = Transmit;
-  abs.FreeTransmit = FreeTransmit;
+  PILOT_SYNC_ABS(&abs)->MatchRecord = MatchRecord;
+  PILOT_SYNC_ABS(&abs)->Iterate = Iterate;
+  PILOT_SYNC_ABS(&abs)->IterateSpecific = IterateSpecific;
+  PILOT_SYNC_ABS(&abs)->SetStatus = SetStatus;
+  PILOT_SYNC_ABS(&abs)->SetArchived = SetArchived;
+  PILOT_SYNC_ABS(&abs)->SetPilotID = SetPilotID;
+  PILOT_SYNC_ABS(&abs)->GetPilotID = GetPilotID;
+  PILOT_SYNC_ABS(&abs)->StoreRemote = StoreRemote;
+  PILOT_SYNC_ABS(&abs)->ArchiveLocal = 0;             /* missing */
+  PILOT_SYNC_ABS(&abs)->ClearStatusArchiveLocal = 0;  /* likewise */
+  PILOT_SYNC_ABS(&abs)->ArchiveRemote = ArchiveRemote;
+  PILOT_SYNC_ABS(&abs)->DeleteAll = DeleteAll;
+  PILOT_SYNC_ABS(&abs)->Purge = Purge;
+  PILOT_SYNC_ABS(&abs)->CompareBackup = CompareBackup;
+  PILOT_SYNC_ABS(&abs)->Compare = Compare;
+  PILOT_SYNC_ABS(&abs)->Transmit = Transmit;
+  PILOT_SYNC_ABS(&abs)->FreeTransmit = FreeTransmit;
 #endif
-  abs.DeleteAll = DeleteAll;
-  abs.StoreRemote = StoreRemote;
+  PILOT_SYNC_ABS(&abs)->DeleteAll = DeleteAll;
+  PILOT_SYNC_ABS(&abs)->StoreRemote = StoreRemote;
 
 #if 0  
   abs.MatchRecord = MatchRecord;
Index: pilot-link/dubious/sync-memodir.c
diff -u pilot-link/dubious/sync-memodir.c:1.1.1.1 pilot-link/dubious/sync-memodir.c:1.2
--- pilot-link/dubious/sync-memodir.c:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/dubious/sync-memodir.c	Sun Jul 26 02:15:11 1998
@@ -40,25 +40,29 @@
 #include "pi-sync.h"
 
 /* Define our own LocalRecord type. */
-struct LocalRecord {
-        StandardLocalRecord;
+struct MemoLocalRecord {
+        LocalRecord standard;
         long ID;
 	time_t mtime;
 	char name[128];
-	LocalRecord * next;
+	struct MemoLocalRecord * next;
 };
 
-LocalRecord * memos = 0;
+typedef struct MemoLocalRecord MemoLocalRecord;
 
+MemoLocalRecord * memos = 0;
+
 /* Define our own SyncAbs type */
-struct SyncAbs {
-	StandardSyncAbs;
+struct MemoSyncAbs {
+	SyncAbs standard;
 	/* items down here are equivalent of C++ class data.
 	   Any information needed to talk to databases, etc., goes in here.
 	   If we were doing multiple memo dbs, then memos would belong in here instead
 	   of a global. */
 };
 
+typedef struct MemoSyncAbs MemoSyncAbs;
+
 char * filename(char * memo) {
 	static char buf[256];
 	sprintf(buf,"Memos/%s",memo);
@@ -111,7 +115,7 @@
 	}
 }
 
-char * newarchivename(PilotRecord * r, LocalRecord * l) {
+char * newarchivename(PilotRecord * r, MemoLocalRecord * l) {
 	static char buf[256];
 	static int i = 1;
 	struct stat stbuf;
@@ -130,20 +134,20 @@
 
 /* Get a Pilot ID for a local record, or 0 if no Pilot ID has been set. Any
    local ID mechanism is not relevent, only IDs given by the Pilot. */
-unsigned long GetPilotID(SyncAbs * thisSA,LocalRecord * Local) {
+unsigned long GetPilotID(MemoSyncAbs * thisSA,MemoLocalRecord * Local) {
 	return Local->ID;
 	/* return 1; */
 }
 
 /* Set the ID on a local record to match a given Pilot ID. */
-int SetPilotID(SyncAbs * thisSA,LocalRecord * Local, unsigned long ID) {
+int SetPilotID(MemoSyncAbs * thisSA,MemoLocalRecord * Local, unsigned long ID) {
 	Local->ID = ID;
 	return 1;
 }
 
 /* Given a PilotRecord, try and find a local record with a matching ID */
-int MatchRecord(SyncAbs * thisSA,  LocalRecord ** Local, PilotRecord * p) {
-	LocalRecord * m = memos;
+int MatchRecord(MemoSyncAbs * thisSA,  MemoLocalRecord ** Local, PilotRecord * p) {
+	MemoLocalRecord * m = memos;
 	while(m) {
 		if(m->ID == p->ID)
 			break;
@@ -157,15 +161,15 @@
 	return 1;
 }
 
-/* Free up the LocalRecord returned by MatchRecord */
-int FreeMatch(SyncAbs * thisSA,LocalRecord ** Local) {
+/* Free up the MemoLocalRecord returned by MatchRecord */
+int FreeMatch(MemoSyncAbs * thisSA,MemoLocalRecord ** Local) {
 	*Local = 0;
 	return 0;
 }
 
-/* Iterate over all LocalRecords, in arbitrary order */
-int Iterate(SyncAbs * thisSA, LocalRecord ** Local) {
-	LocalRecord * m = *Local;
+/* Iterate over all MemoLocalRecords, in arbitrary order */
+int Iterate(MemoSyncAbs * thisSA, MemoLocalRecord ** Local) {
+	MemoLocalRecord * m = *Local;
 	if( !m) {
 		m = memos;
 	} else {
@@ -176,8 +180,8 @@
 }
 
 /* Iterate over local records of a specified type. */
-int IterateSpecific(SyncAbs * thisSA, LocalRecord ** Local, int flag, int archived) {
-	LocalRecord * m = *Local;
+int IterateSpecific(MemoSyncAbs * thisSA, MemoLocalRecord ** Local, int flag, int archived) {
+	MemoLocalRecord * m = *Local;
 	if( !m) {
 		m = memos;
 	} else {
@@ -185,10 +189,10 @@
 	}
 	while(m) {
 	        if(archived) {
-	          if(m->archived)
+	          if(PILOT_LOCAL_RECORD(m)->archived)
 	        	break;
 	        } else {
-		  if(m->attr == flag)
+		  if(PILOT_LOCAL_RECORD(m)->attr == flag)
 			break;
 		}
 		m=m->next;
@@ -198,24 +202,24 @@
 }
 
 /* Set status of local record */
-int SetStatus(SyncAbs * thisSA,LocalRecord * Local, int status) {
-	Local->attr = status;
+int SetStatus(MemoSyncAbs * thisSA,MemoLocalRecord * Local, int status) {
+	PILOT_LOCAL_RECORD(Local)->attr = status;
 	return 0;
 }
 
 /* There is no GetStatus, the abstract layer used Local->attr */
 
 /* Set archival status of local record */
-int SetArchived(SyncAbs * thisSA,LocalRecord * Local,int archived) {
-        Local->archived = archived;
+int SetArchived(MemoSyncAbs * thisSA,MemoLocalRecord * Local,int archived) {
+        PILOT_LOCAL_RECORD(Local)->archived = archived;
 	return 0;
 }
 
 /* There is no GetStatus, the abstract layer used Local->archived */
 
 /* Given a PilotRecord, store it in the local database */
-int StoreRemote(SyncAbs * thisSA,PilotRecord* p) {
-	LocalRecord * m;
+int StoreRemote(MemoSyncAbs * thisSA,PilotRecord* p) {
+	MemoLocalRecord * m;
 	int h;
 	struct stat stbuf;
 	
@@ -238,10 +242,10 @@
 		}
 	}
 	/* new record */
-	m = (LocalRecord*)malloc(sizeof(LocalRecord));
+	m = (MemoLocalRecord*)malloc(sizeof(MemoLocalRecord));
 	m->ID = p->ID;
-	m->attr = p->attr;
-	m->secret = p->secret;
+	PILOT_LOCAL_RECORD(m)->attr = p->attr;
+	PILOT_LOCAL_RECORD(m)->secret = p->secret;
 	
 	strcpy(m->name, newfilename(p));
 	
@@ -261,7 +265,7 @@
 
 /* Given a local record, construct a PilotRecord suitable for transmission
 to a Pilot */
-PilotRecord * Transmit(SyncAbs* thisSA ,LocalRecord* Local) {
+PilotRecord * Transmit(MemoSyncAbs* thisSA ,MemoLocalRecord* Local) {
         static PilotRecord p;
 	int h = open(filename(Local->name),O_RDONLY);
 	
@@ -274,21 +278,21 @@
 	close(h);
 	
 	p.category = 0;
-	p.attr = Local->attr;
-	p.archived = Local->archived;
-	p.secret = Local->secret;
+	p.attr = PILOT_LOCAL_RECORD(Local)->attr;
+	p.archived = PILOT_LOCAL_RECORD(Local)->archived;
+	p.secret = PILOT_LOCAL_RECORD(Local)->secret;
 	
 	return &p;
 }
 
 /* Free PilotRecord created by Transmit */
-int FreeTransmit(SyncAbs* thisSA,LocalRecord* Local,PilotRecord* Remote) {
+int FreeTransmit(MemoSyncAbs* thisSA,MemoLocalRecord* Local,PilotRecord* Remote) {
 	free(Remote->record);
 	return 0;
 }
 
 /* Find a local backup record and compare it to the pilot record for inequality */
-int CompareBackup(SyncAbs * thisSA, LocalRecord* m, PilotRecord* p) {
+int CompareBackup(MemoSyncAbs * thisSA, MemoLocalRecord* m, PilotRecord* p) {
 	char buffer[0xffff];
 	int r,len;
 
@@ -310,7 +314,7 @@
 }
 
 /* Compare a local record and pilot record for inequality */
-int Compare(SyncAbs * thisSA, LocalRecord * m, PilotRecord* p) {
+int Compare(MemoSyncAbs * thisSA, MemoLocalRecord * m, PilotRecord* p) {
 	char buffer[0xffff];
   	int r = open(filename(m->name),O_RDONLY);
   	int len = read(r,buffer,0xffff);
@@ -326,11 +330,11 @@
 }
 
 /* Delete all local records */
-int DeleteAll(SyncAbs * thisSA) {
+int DeleteAll(MemoSyncAbs * thisSA) {
 	while(memos) {
-		LocalRecord * m = memos;
+		MemoLocalRecord * m = memos;
 		memos = memos->next;
-		if(m->attr != RecordDeleted) {
+		if(PILOT_LOCAL_RECORD(m)->attr != RecordDeleted) {
 			unlink(filename(m->name));
 		}
 		free(m);
@@ -340,12 +344,13 @@
 
 /* Do a local purge, deleting all records marked Deleted, and
    archiving all records marked for archiving */
-int Purge(SyncAbs * thisSA) {
-	LocalRecord * prev = 0;
-	LocalRecord * m = memos, *next;
+int Purge(MemoSyncAbs * thisSA) {
+	MemoLocalRecord * prev = 0;
+	MemoLocalRecord * m = memos, *next;
 	while(m) {
 		next = m->next;
-		if((m->attr == RecordDeleted) || (m->archived)) {
+		if((PILOT_LOCAL_RECORD(m)->attr 
+		    == RecordDeleted) || (PILOT_LOCAL_RECORD(m)->archived)) {
 			unlink(filename(m->name));
 			if(prev)
 				prev->next = next;
@@ -360,7 +365,7 @@
 }
 
 /* Add remote record to archive. l is non-NULL if there is a matching local record */
-int ArchiveRemote(SyncAbs * s, LocalRecord * l, PilotRecord * p) {
+int ArchiveRemote(MemoSyncAbs * s, MemoLocalRecord * l, PilotRecord * p) {
 	char name[256];
 	int h;
 	strcpy(name,"Memos/Archive/memoXXXXXX");
@@ -390,26 +395,27 @@
   DIR * d;
   int ret;
   FILE * f;
-  struct SyncAbs abs;
+  struct MemoSyncAbs abs;
 
   /* Set up abstraction structure */  
-  abs.MatchRecord = MatchRecord;
-  abs.Iterate = Iterate;
-  abs.IterateSpecific = IterateSpecific;
-  abs.SetStatus = SetStatus;
-  abs.SetArchived = SetArchived;
-  abs.SetPilotID = SetPilotID;
-  abs.GetPilotID = GetPilotID;
-  abs.StoreRemote = StoreRemote;
-  abs.ArchiveLocal = 0;             /* missing */
-  abs.ClearStatusArchiveLocal = 0;  /* likewise */
-  abs.ArchiveRemote = ArchiveRemote;
-  abs.DeleteAll = DeleteAll;
-  abs.Purge = Purge;
-  abs.CompareBackup = CompareBackup;
-  abs.Compare = Compare;
-  abs.Transmit = Transmit;
-  abs.FreeTransmit = FreeTransmit;
+  PILOT_SYNC_ABS(&abs)->MatchRecord = (SyncAbsMatchRecord)MatchRecord;
+  PILOT_SYNC_ABS(&abs)->Iterate = (SyncAbsIterate)Iterate;
+  PILOT_SYNC_ABS(&abs)->IterateSpecific = 
+    (SyncAbsIterateSpecific)IterateSpecific;
+  PILOT_SYNC_ABS(&abs)->SetStatus = (SyncAbsSetStatus)SetStatus;
+  PILOT_SYNC_ABS(&abs)->SetArchived = (SyncAbsSetArchived)SetArchived;
+  PILOT_SYNC_ABS(&abs)->SetPilotID = (SyncAbsSetPilotID)SetPilotID;
+  PILOT_SYNC_ABS(&abs)->GetPilotID = (SyncAbsGetPilotID)GetPilotID;
+  PILOT_SYNC_ABS(&abs)->StoreRemote = (SyncAbsStoreRemote)StoreRemote;
+  PILOT_SYNC_ABS(&abs)->ArchiveLocal = NULL;             /* missing */
+  PILOT_SYNC_ABS(&abs)->ClearStatusArchiveLocal = NULL;  /* likewise */
+  PILOT_SYNC_ABS(&abs)->ArchiveRemote = (SyncAbsArchiveRemote)ArchiveRemote;
+  PILOT_SYNC_ABS(&abs)->DeleteAll = (SyncAbsDeleteAll)DeleteAll;
+  PILOT_SYNC_ABS(&abs)->Purge = (SyncAbsPurge)Purge;
+  PILOT_SYNC_ABS(&abs)->CompareBackup = (SyncAbsCompareBackup)CompareBackup;
+  PILOT_SYNC_ABS(&abs)->Compare = (SyncAbsCompare)Compare;
+  PILOT_SYNC_ABS(&abs)->Transmit = (SyncAbsTransmit)Transmit;
+  PILOT_SYNC_ABS(&abs)->FreeTransmit = (SyncAbsFreeTransmit)FreeTransmit;
 
   fprintf(stderr, "A Warning be upon Ye: Here Be Dragons!\nThis program is incomplete, ill-considered, and unreliable!\nDo not Rely on without Consideration of Completing the program...\n\n");
   
@@ -449,13 +455,13 @@
   f = fopen(filename("Memos.dir"),"r");
   while (f && !feof(f)) {
   	long l;
-  	LocalRecord * m = (LocalRecord*)malloc(sizeof(LocalRecord));
+  	MemoLocalRecord * m = (MemoLocalRecord*)malloc(sizeof(MemoLocalRecord));
   	if(fscanf(f, "%lu %lu %s", &m->ID, &l, &m->name[0])<3)
   		break;
   	m->mtime = (time_t)l;
-  	m->attr = RecordNothing;
-  	m->secret = 0;
-  	m->archived = 0;
+  	PILOT_LOCAL_RECORD(m)->attr = RecordNothing;
+  	PILOT_LOCAL_RECORD(m)->secret = 0;
+  	PILOT_LOCAL_RECORD(m)->archived = 0;
   	m->next = memos;
   	printf("Read in memo '%s'\n",m->name);
   	memos = m;
@@ -466,7 +472,7 @@
   {
   	struct file * f = files;
   	while(f) {
-  		LocalRecord * m = memos;
+  		MemoLocalRecord * m = memos;
 		struct stat stbuf;
 		char buf[256];
 		sprintf(buf,"Memos/%s",f->name);
@@ -478,18 +484,18 @@
   			m=m->next;
   		}
   		if(!m) {
-  			m = (LocalRecord*)malloc(sizeof(LocalRecord));
+  			m = (MemoLocalRecord*)malloc(sizeof(MemoLocalRecord));
   			strcpy(m->name, f->name);
   			m->ID = 0;
-  			m->attr = RecordNew;
-  			m->secret = 0;
-  			m->archived = 0;
+  			PILOT_LOCAL_RECORD(m)->attr = RecordNew;
+  			PILOT_LOCAL_RECORD(m)->secret = 0;
+  			PILOT_LOCAL_RECORD(m)->archived = 0;
   			m->next = memos;
 			printf("Memo %s is new\n", m->name);
   			memos = m;
   		} else {
 			if(stbuf.st_mtime > m->mtime) {
-				m->attr = RecordModified;
+				PILOT_LOCAL_RECORD(m)->attr = RecordModified;
 				printf("Memo %s is modified\n", m->name);
 			}
   		}
@@ -500,7 +506,7 @@
 
   /* Iterate over memo list, marking deleted memos */
   {
-  	LocalRecord * m = memos;
+  	MemoLocalRecord * m = memos;
   	while(m) {
   		struct file * f = files;
   		while(f) {
@@ -509,7 +515,7 @@
   			f=f->next;
   		}
   		if(!f) {
-  			m->attr = RecordDeleted;
+  			PILOT_LOCAL_RECORD(m)->attr = RecordDeleted;
 			printf("Memo %s is deleted\n", m->name);
   		}
   		m=m->next;
@@ -595,7 +601,7 @@
 
   /* Backup current memos */
   {
-  	LocalRecord * m = memos;
+  	MemoLocalRecord * m = memos;
   	while(m) {
   		char buffer[0xffff];
   		int r = open(filename(m->name),O_RDONLY);
Index: pilot-link/include/pi-dlp.h
diff -u pilot-link/include/pi-dlp.h:1.1.1.1 pilot-link/include/pi-dlp.h:1.2
--- pilot-link/include/pi-dlp.h:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/include/pi-dlp.h	Thu Jul 30 01:27:22 1998
@@ -2,6 +2,7 @@
 #define _PILOT_DLP_H_
 
 #include "pi-args.h"
+#include "pi-types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -34,9 +35,9 @@
   int more;
   unsigned int flags;
   unsigned int miscFlags;
-  unsigned long type,creator;
+  pi_uint32 type,creator;
   unsigned int version;
-  unsigned long modnum;
+  pi_uint32 modnum;
   time_t createDate,modifyDate,backupDate;
   unsigned int index;
   char name[34];
Index: pilot-link/include/pi-file.h
diff -u pilot-link/include/pi-file.h:1.1.1.1 pilot-link/include/pi-file.h:1.2
--- pilot-link/include/pi-file.h:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/include/pi-file.h	Sat Jul 25 05:05:48 1998
@@ -2,6 +2,7 @@
 #define _PILOT_FILE_H_
 
 #include "pi-args.h"
+#include "pi-types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -10,7 +11,7 @@
 /* For DBInfo */
 #include "pi-dlp.h"
 
-typedef unsigned long pi_uid_t;
+typedef pi_uint32 pi_uid_t;
 
 struct pi_file; /* forward declaration */
 
Index: pilot-link/include/pi-macros.h
diff -u pilot-link/include/pi-macros.h:1.1.1.1 pilot-link/include/pi-macros.h:1.2
--- pilot-link/include/pi-macros.h:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/include/pi-macros.h	Sat Jul 25 05:05:49 1998
@@ -2,8 +2,9 @@
 #define _PILOT_MACROS_H_
 
 #include "pi-args.h"
+#include "pi-types.h"
 
-typedef unsigned long recordid_t;
+typedef pi_uint32 recordid_t;
 
 #ifdef __cplusplus
 extern "C" {
Index: pilot-link/include/pi-sync.h
diff -u pilot-link/include/pi-sync.h:1.1.1.1 pilot-link/include/pi-sync.h:1.9
--- pilot-link/include/pi-sync.h:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/include/pi-sync.h	Thu Sep 17 08:42:03 1998
@@ -31,55 +31,85 @@
    layout. It's very likely that this approach is less portable then using
    void*'s, but its less messy to read. */
 
-#define StandardLocalRecord \
-	int attr; \
-	int archived; \
-	int secret
-
-#define StandardSyncAbs \
-	int (*MatchRecord)(SyncAbs*, LocalRecord**, PilotRecord*); \
-	int (*FreeMatch)(SyncAbs*, LocalRecord**); \
-	int (*ArchiveLocal)(SyncAbs*, LocalRecord*); \
-	int (*ArchiveRemote)(SyncAbs*,LocalRecord*,PilotRecord*); \
-	int (*StoreRemote)(SyncAbs*,PilotRecord*); \
-	int (*ClearStatusArchiveLocal)(SyncAbs*,LocalRecord*); \
-	int (*Iterate)(SyncAbs*,LocalRecord**); \
-	int (*IterateSpecific)(SyncAbs*,LocalRecord**, int flag, int archived); \
-	int (*Purge)(SyncAbs*); \
-	int (*SetStatus)(SyncAbs*,LocalRecord*,int status); \
-	int (*SetArchived)(SyncAbs*,LocalRecord*, int); \
-	unsigned long (*GetPilotID)(SyncAbs*,LocalRecord*); \
-	int (*SetPilotID)(SyncAbs*,LocalRecord*,unsigned long); \
-	int (*Compare)(SyncAbs*,LocalRecord*,PilotRecord*); \
-	int (*CompareBackup)(SyncAbs*,LocalRecord*,PilotRecord*); \
-	int (*FreeTransmit)(SyncAbs*,LocalRecord*,PilotRecord*); \
-	int (*DeleteAll)(SyncAbs*); \
-	PilotRecord * (*Transmit)(SyncAbs*,LocalRecord*)
+  /*Ok, instead of doing this, just declare things like GTK+ does*/
 
-#ifdef Abstract_sync
 
-/* Only lib/sync should define Abstract_sync. All other code must
-   define their own LocalRecord and SyncAbs structures. */
+  /* Everyone should extend LocalRecord and SyncAbs for their conduits */
 
 struct LocalRecord {
-        StandardLocalRecord;
+	int attr;
+	int archived;
+	int secret;
 };
 
+#define SYNCABS_LOCALRECORD \
+	int attr; \
+	int archived; \
+	int secret;
+
+
+#define PILOT_LOCAL_RECORD(a) ((LocalRecord *)(a))
+
+typedef	int (*SyncAbsMatchRecord)(SyncAbs*, LocalRecord**, PilotRecord*);
+typedef	int (*SyncAbsFreeMatch)(SyncAbs*, LocalRecord**);
+typedef	int (*SyncAbsArchiveLocal)(SyncAbs*, LocalRecord*);
+typedef	int (*SyncAbsArchiveRemote)(SyncAbs*,LocalRecord*,PilotRecord*);
+typedef	int (*SyncAbsStoreRemote)(SyncAbs*,PilotRecord*);
+typedef	int (*SyncAbsClearStatusArchiveLocal)(SyncAbs*,LocalRecord*);
+typedef	int (*SyncAbsIterate)(SyncAbs*,LocalRecord**);
+typedef	int (*SyncAbsIterateSpecific)(SyncAbs*,LocalRecord**, int flag, int archived);
+typedef	int (*SyncAbsPurge)(SyncAbs*);
+typedef	int (*SyncAbsSetStatus)(SyncAbs*,LocalRecord*,int status);
+typedef	int (*SyncAbsSetArchived)(SyncAbs*,LocalRecord*, int);
+typedef	pi_uint32 (*SyncAbsGetPilotID)(SyncAbs*,LocalRecord*);
+typedef	int (*SyncAbsSetPilotID)(SyncAbs*,LocalRecord*,unsigned long);
+typedef	int (*SyncAbsCompare)(SyncAbs*,LocalRecord*,PilotRecord*);
+typedef	int (*SyncAbsCompareBackup)(SyncAbs*,LocalRecord*,PilotRecord*);
+typedef	int (*SyncAbsFreeTransmit)(SyncAbs*,LocalRecord*,PilotRecord*);
+typedef int (*SyncAbsDeleteAll)(SyncAbs*);
+typedef PilotRecord * (*SyncAbsTransmit)(SyncAbs*,LocalRecord*);
+typedef char* (*SyncAbsDatabaseName)(SyncAbs*);
+typedef pi_uint32 (*SyncAbsCreatorId)(SyncAbs*);
+
 struct SyncAbs {
-        StandardSyncAbs;
+	int (*MatchRecord)(SyncAbs*, LocalRecord**, PilotRecord*);
+	int (*FreeMatch)(SyncAbs*, LocalRecord**);
+	int (*ArchiveLocal)(SyncAbs*, LocalRecord*);
+	int (*ArchiveRemote)(SyncAbs*,LocalRecord*,PilotRecord*);
+	int (*StoreRemote)(SyncAbs*,PilotRecord*);
+	int (*ClearStatusArchiveLocal)(SyncAbs*,LocalRecord*);
+	int (*Iterate)(SyncAbs*,LocalRecord**);
+	int (*IterateSpecific)(SyncAbs*,LocalRecord**, int flag, int archived);
+	int (*Purge)(SyncAbs*);
+	int (*SetStatus)(SyncAbs*,LocalRecord*,int status);
+	int (*SetArchived)(SyncAbs*,LocalRecord*, int);
+	pi_uint32 (*GetPilotID)(SyncAbs*,LocalRecord*);
+	int (*SetPilotID)(SyncAbs*,LocalRecord*,unsigned long);
+	int (*Compare)(SyncAbs*,LocalRecord*,PilotRecord*);
+	int (*CompareBackup)(SyncAbs*,LocalRecord*,PilotRecord*);
+	int (*FreeTransmit)(SyncAbs*,LocalRecord*,PilotRecord*);
+        int (*DeleteAll)(SyncAbs*);
+	PilotRecord * (*Transmit)(SyncAbs*,LocalRecord*);
+        char* (*DatabaseName)(SyncAbs*);
+        pi_uint32 (*CreatorId)(SyncAbs*);
 };
 
-#endif
+#define PILOT_SYNC_ABS(a) ((SyncAbs *)(a))
 
 /* Erase all local records, and copy all remote records to local */
 extern int CopyFromRemote(int handle, int db, struct SyncAbs * s);
 /* Erase all remote records, and copy all local records to remote */
 extern int CopyToRemote(int handle, int db, struct SyncAbs * s);
+
 /* Synchronize local and remote using flags on remote */
 extern int FastSync(int handle, int db, struct SyncAbs * s );
 /* Synchronize by pulling all data off remote, and comparing to backup
    on local if flags show no change */
 extern int SlowSync(int handle, int db, struct SyncAbs * s );
+/* adds all new records on the remote device to the local base*/
+extern int MergeFromRemote(int handle, int db, struct SyncAbs * s );
+/* adds all new records in the local base to the remote */
+extern int MergeToRemote(int handle, int db, struct SyncAbs * s );
 
 #ifdef __cplusplus
 }
Index: pilot-link/include/pi-types.h.in
diff -u /dev/null pilot-link/include/pi-types.h.in:1.1
--- /dev/null	Wed Oct 21 03:41:18 1998
+++ pilot-link/include/pi-types.h.in	Sat Jul 25 05:05:51 1998
@@ -0,0 +1,27 @@
+#ifndef _PILOT_TYPES_H_
+#define _PILOT_TYPES_H_
+
+#undef SIZEOF_CHAR
+#undef SIZEOF_SHORT
+#undef SIZEOF_INT
+#undef SIZEOF_LONG
+
+#if (SIZEOF_CHAR == 1)
+typedef signed char	pi_int8;
+typedef unsigned char	pi_uint8;
+#endif /* SIZEOF_CHAR */
+
+#if (SIZEOF_SHORT == 2)
+typedef signed short	pi_int16;
+typedef unsigned short	pi_uint16;
+#endif /* SIZEOF_SHORT */
+
+#if (SIZEOF_INT == 4)
+typedef signed int	pi_int32;
+typedef unsigned int	pi_uint32;
+#elif (SIZEOF_LONG == 4)
+typedef signed long	pi_int32;
+typedef unsigned long	pi_uint32;
+#endif /* SIZEOF_INT */
+
+#endif /* _PILOT_TYPES_H_ */
Index: pilot-link/libsock/dlp.c
diff -u pilot-link/libsock/dlp.c:1.1.1.1 pilot-link/libsock/dlp.c:1.2
--- pilot-link/libsock/dlp.c:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/libsock/dlp.c	Tue Oct 20 23:42:50 1998
@@ -489,7 +489,7 @@
     if (!info->flags)
       fprintf(stderr, " None");
     fprintf(stderr, " (0x%2.2X)\n", info->flags);
-    fprintf(stderr, "        Modnum: %ld, Index: %d, Creation date: %s",
+    fprintf(stderr, "        Modnum: %d, Index: %d, Creation date: %s",
       info->modnum, info->index, ctime(&info->createDate));
     fprintf(stderr, "        Modification date: %s", ctime(&info->modifyDate));
     fprintf(stderr, "        Backup date: %s", ctime(&info->backupDate));
@@ -2222,7 +2222,7 @@
 
 #ifdef DLP_TRACE
   if (dlp_trace) {  
-    fprintf(stderr, " Wrote: Handle: %d, Record ID: 0x%8.8lX\n", fHandle, id);
+    fprintf(stderr, " Wrote: Handle: %d, Record ID: 0x%8.8X\n", fHandle, id);
   }
 #endif
   
Index: pilot-link/libsock/pi-file.c
diff -u pilot-link/libsock/pi-file.c:1.1.1.2 pilot-link/libsock/pi-file.c:1.2
--- pilot-link/libsock/pi-file.c:1.1.1.2	Sat Jul 25 04:36:19 1998
+++ pilot-link/libsock/pi-file.c	Tue Oct 20 23:42:51 1998
@@ -825,7 +825,7 @@
     }
   else
     for(j=0;j<l;j++) {
-	  unsigned long id;
+	  recordid_t id;
   	  int size;
   	  int attr;
   	  int category;
@@ -945,7 +945,7 @@
       }
     }
     for(j=0;j<pf->nentries;j++) {
-      unsigned long id;
+      recordid_t id;
       int size;
       int attr;
       int category;
@@ -1023,7 +1023,7 @@
       }
     }
     for(j=0;j<pf->nentries;j++) {
-      unsigned long id;
+      recordid_t id;
       int size;
       int attr;
       int category;
Index: pilot-link/libsock/sync.c
diff -u pilot-link/libsock/sync.c:1.1.1.1 pilot-link/libsock/sync.c:1.7
--- pilot-link/libsock/sync.c:1.1.1.1	Fri Jul 24 20:59:50 1998
+++ pilot-link/libsock/sync.c	Thu Sep 17 08:42:05 1998
@@ -42,26 +42,219 @@
 #include "pi-socket.h"
 #include "pi-dlp.h"
 
-#define Abstract_sync
 #include "pi-sync.h"
 
+#define LOG_CASE6 "case 6\n"
+#define LOG_CASE10 "case 10, conflict, pilots modified added to local and vice versa\n"
+
 /* Given a remote (Pilot) record, stored in a PilotRecord structure, determine what,
    if anything, should be done with it, by looking at its flags, and possibly looking
    it up in the local database. */
+
+/*
+void SyncRecord(struct PilotRecord * remote, struct SyncAbs * s) {
+  long local;
+  if( remote->attr & Archived ) {
+    if(!s->MatchRecord(remote->id,&local)) {
+      s->AppendArchive(remote);
+    } else {
+      if(!s->IsModified(local)) {
+        s->AppendArchive(remote);
+        s->SetArchive(local,0);
+        s->SetStatus(local,Pending);
+      } else {
+        if(s->NoStatus(local)) {
+          s->UseBackupStatus(remote);
+        }
+        if(s->IsModifed()) {
+          Etc 
+        }
+      }
+    }
+  }
+   Etc 
+}
+*/
+
+int AddToPilot(int handle,int db,LocalRecord *Local, struct SyncAbs *s) {
+  PilotRecord *p;
+  int retval;
+
+  p = s->Transmit(s,Local);
+  s->SetStatus(s,Local,RecordNothing);
+  p->attr = RecordNothing;
+  if(p->secret)
+    p->attr |= dlpRecAttrSecret ;
+  dlp_WriteRecord(handle,db,Local->secret?dlpRecAttrSecret:0,
+		  0,p->category,p->record,p->length,
+		  &retval);	   
+  s->FreeTransmit(s,Local,p);
+  return retval;
+}
+
 int SyncRecord(int handle, int db, PilotRecord * Remote, struct SyncAbs * s, int slowsync) {
-  /* --- Paraphrased code derived from Palm;s Conduit SDK elided --- */
-  abort(); /* For lack of anything better to do */
+  /* This is messy, but its my first attempt at implementing the
+     algoritm of conduit.pdf page 39-40. And yes, I'll try to collapse
+     the methods when I'm sure which are to do the same stuff
+     I've marked which of the possibilities from page 39-40 each case 
+     correlates to. case e1 is where neither local nor remote is modified.
+     eskil
+  */
+
+  LocalRecord *Local;
+  
+  s->MatchRecord(s,&Local,Remote);
+
+  if(Local) {
+    /* local record exists */
+    if(Remote->archived) {
+      /* CASE 12 ? */
+      printf("sync: case 12\n");
+      Remote->attr = 0;
+      Remote->archived = 0;
+      s->ArchiveRemote(s,Local,Remote);
+    } else {      
+      switch(Remote->attr) {
+
+      case RecordModified:
+	switch(Local->attr) {
+	case RecordModified:
+	  if(s->Compare(s,Local,Remote)!=0) {
+	    /* CASE 10 */
+	    printf("sync: case 10\n");
+	    AddToPilot(handle,db,Local,s);
+	    s->StoreRemote(s,Remote);
+	    dlp_AddSyncLogEntry(handle,LOG_CASE10);
+	  } else {
+	    /* CASE 9 */
+	    printf("sync: case 9\n");
+	    s->SetStatus(s,Local,RecordNothing);
+	  }
+	  break;
+	case RecordNothing:
+	  /* CASE 7*/
+	  printf("sync: case 7\n");
+	  s->StoreRemote(s,Remote);
+	  s->SetStatus(s,Local,RecordNothing);
+	  break;
+	case RecordDeleted:
+	  /* CASE 6 */
+	  printf("sync: case 6\n");
+	  s->StoreRemote(s,Remote);
+	  dlp_AddSyncLogEntry(handle,LOG_CASE6);
+	  break;
+	default:
+	  fprintf(stderr,"pilot-link:SyncRecord: Unhandle sync case (b) Remote.attr = %d, Local.attr = %d\n",
+		  Remote->attr,Local->attr);
+	  break;
+	}
+	break;
+
+      case RecordDeleted:
+	switch(Local->attr) {
+	case RecordModified:
+	  /* CASE 5 */
+	  printf("sync: case 5\n");
+	  AddToPilot(handle,db,Local,s);
+	  break;
+	case RecordDeleted:
+	  /* CASE 17 */
+	  printf("sync: case 17\n");
+	  s->ArchiveLocal(s,Local);
+	  dlp_DeleteRecord(handle,db,0,Remote->ID);
+	  break;
+	case RecordNothing:
+	  /* CASE 3 */
+	  printf("sync: case 3\n");
+	  /* can be collapsed with case RecordDeleted */
+	  dlp_DeleteRecord(handle,db,0,Remote->ID);
+	  break;
+	default:
+	  fprintf(stderr,"pilot-link:SyncRecord: Unhandle sync case (a) Remote.attr = %d, Local.attr = %d\n",
+		  Remote->attr,Local->attr);
+	  break;
+	}
+
+      case RecordNothing:
+	if(Local->archived) {
+	  /* CASE 16 */
+	  printf("sync: case 16\n");
+	  s->ArchiveLocal(s,Local);
+	  dlp_DeleteRecord(handle,db,0,Remote->ID);
+	} else 
+	  switch(Local->attr) {
+	  case RecordDeleted:
+	    /* CASE 4 */
+	    printf("sync: case 4\n");
+	    dlp_DeleteRecord(handle,db,0,Remote->ID);
+	    break;
+	  case RecordModified: {
+	    PilotRecord *p;
+	    /* CASE 8 */
+	    printf("sync: case 8\n");
+	    p = s->Transmit(s,Local);
+	    dlp_WriteRecord(handle,db,Local->secret?dlpRecAttrSecret:0,
+			    p->ID,p->category,p->record,p->length,
+			    NULL);
+	    s->SetStatus(s,Local,RecordNothing);
+	    s->FreeTransmit(s,Local,p);
+	  }
+	  break;
+	  case RecordNothing:
+	    /* CASE e1 */
+	    printf("sync: case e1\n");
+	    break;
+	  default:
+	    fprintf(stderr,"pilot-link:SyncRecord: Unhandle sync case (c) Remote.attr = %d, Local.attr = %d\n",
+		    Remote->attr,Local->attr);
+	    break;
+	  }
+	break;
+      }
+    } 
+    s->FreeMatch(s,&Local);
+  } else {
+    /* no local record exists */
+    if(Remote->archived) {
+      /* CASE 11 */
+      printf("sync: case 11\n");
+      Remote->attr = 0;
+      Remote->archived = 0;
+      s->ArchiveRemote(s,NULL,Remote);
+    } else {
+      /* CASE 1 */
+      printf("sync: case 1\n");
+      s->StoreRemote(s,Remote); /* maybe it'd be nice if StoreRemote returned a LocalRecord ? */
+      s->MatchRecord(s,&Local,Remote);
+      s->SetStatus(s,Local,RecordNothing);
+      s->FreeMatch(s,&Local);
+    }
+  }
+  
+  /* CASE 2 handled by MergeToRemote */
+
   return 0;
 }
 
-/* Iterate over local records, copying records to remote, or deleting, or
-    archiving, as flags dictate. This is the last step in any sync. */
-void MergeToRemote(int handle, int db, struct SyncAbs * s) {
+int MergeToRemote(int handle, int db, struct SyncAbs * s) {
   /* --- Paraphrased code derived from Palm's Conduit SDK elided --- */
-  abort(); /* For lack of anything better to do */
-  return;
+  /* abort();  For lack of anything better to do */
+  LocalRecord *local;  
+  local = NULL;
+  printf("mergetoremote: into loop\n");
+  while(s->IterateSpecific(s,&local,RecordNew,0)==0) {
+    s->SetPilotID(s,local,AddToPilot(handle,db,local,s));
+  }
+  printf("mergetoremote: out of loop\n");
+  return 0;
 }
 
+int MergeFromRemote(int handle, int db, struct SyncAbs * s) {
+  /* --- Paraphrased code derived from Palm's Conduit SDK elided --- */
+  abort();  /* For lack of anything better to do */
+  return 0;
+};
+
 /* Perform a "slow" sync. This requires that the local (PC) has
    consistent, accurate, and sufficient modification flags. All
    of the records on the remote (Pilot) are pulled in, and compared
@@ -90,6 +283,10 @@
 	}
 	
 	MergeToRemote(handle,db,s);
+
+	dlp_CleanUpDatabase(handle,db);
+	s->Purge(s);
+	dlp_ResetSyncFlags(handle,db);
 	
 	return retval;
 }
@@ -119,6 +316,10 @@
 	
 	MergeToRemote(handle,db,s);
 	
+	dlp_CleanUpDatabase(handle,db);
+	s->Purge(s);
+	dlp_ResetSyncFlags(handle,db);
+
 	return retval;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]