gnome-pilot Evolution conduits ported to pilot-link 0.12pre4



I've ported the Evolution 2.6 (and 2.7 - they're the same) conduits to pilot-link 0.12pre4. They
are also backwards-compatible with pilot-link 0.11.8 (used the same mechanism that Matt put into
gnome-pilot 2.0.14preX). These have been working pretty well for me (i.e. no more problems than
the 0.11.8 versions). Note that evolution-data-server-1.6 seems to crash if you do a Copy From
Pilot and have a lot of calendar activites (bug in eds most likely, not the conduit).

I'm planning on submitting them to the evolution developers soon so they'll make it into Evolution
2.8. If pilot-link's API is changing between pre4 and the release, let me know.

As always, let me know if you have any problems with the conduits.

Thanks,
Nathan

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Index: address-conduit.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/conduit/address-conduit.c,v
retrieving revision 1.88
diff -u -r1.88 address-conduit.c
--- address-conduit.c	6 Dec 2005 08:43:37 -0000	1.88
+++ address-conduit.c	20 Aug 2006 19:50:34 -0000
@@ -462,6 +462,9 @@
 {
 	static char buff[ 4096 ];
 	struct Address addr;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t piBuf;
+#endif
 
 	if (remote == NULL) {
 		sprintf (buff, "[NULL]");
@@ -469,7 +472,14 @@
 	}
 
 	memset (&addr, 0, sizeof (struct Address));
+#ifdef PILOT_LINK_0_12
+	piBuf.data = remote->record;
+	piBuf.allocated = remote->length;
+	piBuf.used = remote->length;
+	unpack_Address(&addr, &piBuf, address_v1);
+#else
 	unpack_Address (&addr, remote->record, remote->length);
+#endif
 
 	g_snprintf (buff, 4096, "['%s' '%s' '%s']",
 		    addr.entry[entryLastname] ?
@@ -786,12 +796,23 @@
 	}
 }
 
+/* convert a local EAddrLocalRecord to a GnomePilotRecord for the PDA
+ * 
+ * @param local local Evolution address record
+ * @param ctxt conduit context
+ * @param record record to use for GnomePilotRecord. Allow the calling
+ *               function to determine if the record should be allocated
+ *               dynamically or statically.
+ * @param maxRecordLen size of *record (max amount of data that can be put
+ *                      into record)
+ */
 static GnomePilotRecord
 local_record_to_pilot_record (EAddrLocalRecord *local,
-			      EAddrConduitContext *ctxt)
+			      EAddrConduitContext *ctxt,
+			      unsigned char *record,
+			      int maxRecordLen)
 {
 	GnomePilotRecord p;
-	static char record[0xffff];
 	
 	g_assert (local->addr != NULL );
 	
@@ -804,8 +825,19 @@
 	p.secret = local->local.secret;
 
 	/* Generate pilot record structure */
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = record;
+		piBuf.allocated = maxRecordLen;
+		piBuf.used = 0;
+		p.length = pack_Address(local->addr, &piBuf, address_v1);
+		p.record = piBuf.data;
+	}
+#else
 	p.record = record;
-	p.length = pack_Address (local->addr, p.record, 0xffff);
+	p.length = pack_Address (local->addr, p.record, maxRecordLen);
+#endif
 
 	return p;	
 }
@@ -834,16 +866,41 @@
 	 */
 	if (local->local.ID != 0) {
 		struct Address addr;
-		char record[0xffff];
+#ifdef PILOT_LINK_0_12
+		pi_buffer_t *piBuf;
+#else
+		unsigned char record[0xffff];
+#endif
 		int cat = 0;
+		int dlpReadRetval = 0;
+
 		
-		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
-					ctxt->dbi->db_handle,
-					local->local.ID, &record, 
-					NULL, NULL, NULL, &cat) > 0) {
+#ifdef PILOT_LINK_0_12
+		piBuf = pi_buffer_new(0xffff);
+		if(piBuf == NULL) {
+			WARN( _("local_record_from_ecard: no more memory to allocate") );
+			return;
+		}
+		dlpReadRetval = dlp_ReadRecordById(ctxt->dbi->pilot_socket,
+		                                  ctxt->dbi->db_handle,
+		                                  local->local.ID, piBuf,
+		                                  NULL, NULL, &cat);
+
+#else
+		dlpReadRetval = dlp_ReadRecordById(ctxt->dbi->pilot_socket,
+						  ctxt->dbi->db_handle,
+						  local->local.ID, &record,
+						  NULL, NULL, NULL, &cat);
+#endif
+
+		if (dlpReadRetval > 0) {
 			local->local.category = cat;
 			memset (&addr, 0, sizeof (struct Address));
+#ifdef PILOT_LINK_0_12
+			unpack_Address(&addr, piBuf, address_v1);
+#else
 			unpack_Address (&addr, record, 0xffff);
+#endif
 			for (i = 0; i < 5; i++) {
 				if (addr.entry[entryPhone1 + i])
 					local->addr->entry[entryPhone1 + i] = 
@@ -858,6 +915,10 @@
 			}
 			free_Address (&addr);
 		}
+		
+#ifdef PILOT_LINK_0_12
+		pi_buffer_free(piBuf);
+#endif
 	}
 
 	local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
@@ -1022,7 +1083,17 @@
 
 	g_return_val_if_fail(remote!=NULL,NULL);
 	memset (&address, 0, sizeof (struct Address));
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = remote->record;
+		piBuf.allocated = remote->length;
+		piBuf.used = remote->length;
+		unpack_Address(&address, &piBuf, address_v1);
+	}
+#else
 	unpack_Address (&address, remote->record, remote->length);
+#endif
 
 	if (in_contact == NULL)
 		contact = e_contact_new ();
@@ -1212,7 +1283,11 @@
 	EBookQuery *query;
     	GList *l;
 	int len;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t *piBuf;
+#else
 	unsigned char *buf;
+#endif
 	char *filename;
 	char *change_id;
 	char *auth;
@@ -1302,9 +1377,26 @@
   	gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records);
   	gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records);
 
+#ifdef PILOT_LINK_0_12
+	piBuf = pi_buffer_new(0xffff);
+	if(piBuf == NULL) {
+		WARN (_("pre_sync(): Error allocating pi_buffer_t memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating pi_buffer_t memory"));
+		return -1;
+	}
+	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, -1, piBuf);
+#else
 	buf = (unsigned char*)g_malloc (0xffff);
+	if(buf == NULL) {
+		WARN (_("pre_sync(): Error allocating buf memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating buf memory"));
+		return -1;
+	}
 	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
 			      (unsigned char *)buf, 0xffff);
+#endif
 	
 	if (len < 0) {
 		WARN (_("Could not read pilot's Address application block"));
@@ -1313,8 +1405,13 @@
 					   _("Could not read pilot's Address application block"));
 		return -1;
 	}
+#ifdef PILOT_LINK_0_12
+	unpack_AddressAppInfo (&(ctxt->ai), piBuf->data, len);
+	pi_buffer_free(piBuf);
+#else
 	unpack_AddressAppInfo (&(ctxt->ai), buf, len);
 	g_free (buf);
+#endif
 
   	check_for_slow_setting (conduit, ctxt);
 	if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot
@@ -1494,6 +1591,7 @@
 {
 	GnomePilotRecord local_pilot;
 	int retval = 0;
+	static unsigned char record[0xffff];
 
 	LOG (g_message ("compare: local=%s remote=%s...\n",
 			print_local (local), print_remote (remote)));
@@ -1501,7 +1599,7 @@
 	g_return_val_if_fail (local != NULL, -1);
 	g_return_val_if_fail (remote != NULL, -1);
 
-	local_pilot = local_record_to_pilot_record (local, ctxt);
+	local_pilot = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	if (remote->length != local_pilot.length
 	    || memcmp (local_pilot.record, remote->record, remote->length))
@@ -1693,9 +1791,11 @@
 	 GnomePilotRecord *remote,
 	 EAddrConduitContext *ctxt)
 {
+	static unsigned char record[0xffff];
+	
 	LOG (g_message ( "prepare: encoding local %s\n", print_local (local) ));
 	
-	*remote = local_record_to_pilot_record (local, ctxt);
+	*remote = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 	
 	return 0;
 }
Index: calendar-conduit.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/conduits/calendar/calendar-conduit.c,v
retrieving revision 1.132
diff -u -r1.132 calendar-conduit.c
--- calendar-conduit.c	23 Dec 2005 04:39:34 -0000	1.132
+++ calendar-conduit.c	20 Aug 2006 19:50:48 -0000
@@ -413,6 +413,9 @@
 {
 	static char buff[ 4096 ];
 	struct Appointment appt;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t piBuf;
+#endif
 
 	if (remote == NULL) {
 		sprintf (buff, "[NULL]");
@@ -420,7 +423,14 @@
 	}
 
 	memset (&appt, 0, sizeof (struct Appointment));
+#ifdef PILOT_LINK_0_12
+	piBuf.data = remote->record;
+	piBuf.allocated = remote->length;
+	piBuf.used = remote->length;
+	unpack_Appointment(&appt, &piBuf, datebook_v1);
+#else
 	unpack_Appointment (&appt, remote->record, remote->length);
+#endif
 
 	g_snprintf (buff, 4096, "[%ld %ld '%s' '%s']",
 		    mktime (&appt.begin),
@@ -813,12 +823,23 @@
 	return TRUE;
 }
 
+/* convert a local ECalLocalRecord to a GnomePilotRecord for the PDA
+ * 
+ * @param local local Evolution Calendar record
+ * @param ctxt conduit context
+ * @param record record to use for GnomePilotRecord. Allow the calling
+ *               function to determine if the record should be allocated
+ *               dynamically or statically.
+ * @param maxRecordLen size of *record (max amount of data that can be put
+ *                      into record)
+ */
 static GnomePilotRecord
 local_record_to_pilot_record (ECalLocalRecord *local,
-			      ECalConduitContext *ctxt)
+			      ECalConduitContext *ctxt,
+			      unsigned char *record,
+			      int maxRecordLen)
 {
 	GnomePilotRecord p;
-	static char record[0xffff];
 
 	g_assert (local->comp != NULL);
 	g_assert (local->appt != NULL );
@@ -830,8 +851,19 @@
 	p.secret = local->local.secret;
 
 	/* Generate pilot record structure */
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = record;
+		piBuf.allocated = maxRecordLen;
+		piBuf.used = 0;
+		p.length = pack_Appointment(local->appt, &piBuf, datebook_v1);
+		p.record = piBuf.data;
+	}
+#else
 	p.record = record;
-	p.length = pack_Appointment (local->appt, p.record, 0xffff);
+	p.length = pack_Appointment (local->appt, p.record, maxRecordLen);
+#endif
 
 	return p;	
 }
@@ -867,22 +899,48 @@
          * we don't overwrite them 
 	 */
 	if (local->local.ID != 0) {
-		struct Appointment appt;		
-		char record[0xffff];
+		struct Appointment appt;
+#ifdef PILOT_LINK_0_12
+		pi_buffer_t *piBuf;
+#else
+		unsigned char record[0xffff];
+#endif
 		int cat = 0;
+		int dlpReadRetval = 0;
 		
-		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
-					ctxt->dbi->db_handle,
-					local->local.ID, &record, 
-					NULL, NULL, NULL, &cat) > 0) {
+#ifdef PILOT_LINK_0_12
+		piBuf = pi_buffer_new(0xffff);
+		if(piBuf == NULL) {
+			WARN( _("local_record_from_comp: no more memory to allocate") );
+			return;
+		}
+		dlpReadRetval = dlp_ReadRecordById (ctxt->dbi->pilot_socket,
+						    ctxt->dbi->db_handle,
+						    local->local.ID, piBuf,
+						    NULL, NULL, &cat);
+#else
+		dlpReadRetval = dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
+						    ctxt->dbi->db_handle,
+						    local->local.ID, &record,
+						    NULL, NULL, NULL, &cat);
+#endif
+		
+		if (dlpReadRetval > 0) {
 			local->local.category = cat;
 			memset (&appt, 0, sizeof (struct Appointment));
+#ifdef PILOT_LINK_0_12
+			unpack_Appointment (&appt, piBuf, datebook_v1);
+#else
 			unpack_Appointment (&appt, record, 0xffff);
+#endif
 			local->appt->alarm = appt.alarm;
 			local->appt->advance = appt.advance;
 			local->appt->advanceUnits = appt.advanceUnits;
 			free_Appointment (&appt);
 		}
+#ifdef PILOT_LINK_0_12
+		pi_buffer_free(piBuf);
+#endif
 	}
 
 	/* STOP: don't replace these with g_strdup, since free_Appointment
@@ -1144,7 +1202,17 @@
 	g_return_val_if_fail (remote != NULL, NULL);
 
 	memset (&appt, 0, sizeof (struct Appointment));
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = remote->record;
+		piBuf.allocated = remote->length;
+		piBuf.used = remote->length;
+		unpack_Appointment(&appt, &piBuf, datebook_v1);
+	}
+#else
 	unpack_Appointment (&appt, remote->record, remote->length);
+#endif
 
 	if (in_comp == NULL) {
 		comp = e_cal_component_new ();
@@ -1409,7 +1477,11 @@
 	GnomePilotConduitSyncAbs *abs_conduit;
 	GList *removed = NULL, *added = NULL, *l;
 	int len;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t *piBuf;
+#else
 	unsigned char *buf;
+#endif
 	char *filename, *change_id;
 	icalcomponent *icalcomp;
 	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
@@ -1521,9 +1593,26 @@
 	gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records);
 	gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records);
 
+#ifdef PILOT_LINK_0_12
+	piBuf = pi_buffer_new(0xffff);
+	if(piBuf == NULL) {
+		WARN (_("pre_sync(): Error allocating pi_buffer_t memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating pi_buffer_t memory"));
+		return -1;
+	}
+	len = dlp_ReadAppBlock(dbi->pilot_socket, dbi->db_handle, 0, -1, piBuf);
+#else
 	buf = (unsigned char*)g_malloc (0xffff);
+	if(buf == NULL) {
+		WARN (_("pre_sync(): Error allocating buf memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating buf memory"));
+		return -1;
+	}
 	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
 			      (unsigned char *)buf, 0xffff);
+#endif
 	
 	if (len < 0) {
 		WARN (_("Could not read pilot's Calendar application block"));
@@ -1532,8 +1621,13 @@
 					   _("Could not read pilot's Calendar application block"));
 		return -1;
 	}
+#ifdef PILOT_LINK_0_12
+	unpack_AppointmentAppInfo (&(ctxt->ai), piBuf->data, len);
+	pi_buffer_free(piBuf);
+#else
 	unpack_AppointmentAppInfo (&(ctxt->ai), buf, len);
 	g_free (buf);
+#endif
 
 	check_for_slow_setting (conduit, ctxt);
 	if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot
@@ -1715,6 +1809,7 @@
 	/* used by the quick compare */
 	GnomePilotRecord local_pilot;
 	int retval = 0;
+	static unsigned char record[0xffff];
 
 	LOG (g_message ("compare: local=%s remote=%s...\n",
 			print_local (local), print_remote (remote)));
@@ -1722,7 +1817,7 @@
 	g_return_val_if_fail (local!=NULL,-1);
 	g_return_val_if_fail (remote!=NULL,-1);
 
-	local_pilot = local_record_to_pilot_record (local, ctxt);
+	local_pilot = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	if (remote->length != local_pilot.length
 	    || memcmp (local_pilot.record, remote->record, remote->length))
@@ -1883,9 +1978,11 @@
 	 GnomePilotRecord *remote,
 	 ECalConduitContext *ctxt)
 {
+	static unsigned char record[0xffff];
+	
 	LOG (g_message ( "prepare: encoding local %s\n", print_local (local) ));
 
-	*remote = local_record_to_pilot_record (local, ctxt);
+	*remote = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	return 0;
 }
Index: acinclude.m4
===================================================================
RCS file: /cvs/gnome/evolution/acinclude.m4,v
retrieving revision 1.9
diff -u -r1.9 acinclude.m4
--- acinclude.m4	12 Jun 2006 12:52:02 -0000	1.9
+++ acinclude.m4	20 Aug 2006 20:05:03 -0000
@@ -268,3 +268,119 @@
   AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)
   AM_CONDITIONAL(GTK_DOC_USE_LIBTOOL, test -n "$LIBTOOL")
 ])
+
+# PILOT_LINK_CHECK
+# Adds --with-pisock and determines the verion of the pisock
+#
+
+AC_SUBST(PISOCK_CFLAGS)
+AC_SUBST(PISOCK_LIBS)
+
+AC_DEFUN([PILOT_LINK_HOOK],[
+	AC_ARG_WITH(pisock,
+	[  --with-pisock            Specify prefix for pisock files],[
+	if test x$withval = xyes; then
+	    dnl Note that an empty true branch is not valid sh syntax.
+	    ifelse([$1], [], :, [$1])
+	else
+	    PISOCK_CFLAGS="-I$withval/include"
+	    incdir="$withval/include"
+	    PISOCK_LIBS="-L$withval/lib -lpisock -lpisync"
+	    AC_MSG_CHECKING("for existance of $withval/lib/libpisock.so")
+	    if test -r $withval/lib/libpisock.so; then
+		AC_MSG_RESULT(yes)
+	    else
+		AC_MSG_ERROR([Unable to find libpisock. Try  http://www.pilot-link.org.])
+	    fi
+	fi
+	])
+
+	if test x$PISOCK_CFLAGS = x; then
+	    AC_CHECK_HEADER(pi-version.h, [incdir="/usr/include"], [
+	    AC_CHECK_HEADER(libpisock/pi-version.h, [PISOCK_CFLAGS="-I/usr/include/libpisock"
+	                                             piversion_include="libpisock/pi-version.h"
+						     incdir="/usr/include/libpisock"
+                                                    ], [
+	    AC_CHECK_HEADER($prefix/include/pi-version.h, [PISOCK_CFLAGS="-I$prefix/include/libpisock"
+	                                                   piversion_include="$prefix/include/pi-version.h"
+						           if test x$PISOCK_LIBDIR = x; then
+							      incdir="$prefix/include"
+							      PISOCK_LIBS="-L$prefix/lib -lpisock -lpisync"
+                                                           fi							  ],
+	    AC_MSG_ERROR([Unable to find pi-version.h])) 
+	    ])
+	    ])
+	fi
+		
+	if test "x$PISOCK_LIBS" = "x"; then
+		AC_CHECK_LIB(pisock, pi_accept, [ PISOCK_LIBS="-lpisock -lpisync"], 
+			[ AC_MSG_ERROR([Unable to find libpisock. Try http://www.pilot-link.org.]) ])
+	fi
+	
+	AC_ARG_ENABLE(pilotlinktest,
+		[  --enable-pilotlinktest   Test for correct version of pilot-link],
+		[testplversion=$enableval],
+		[ testplversion=yes ]
+	)
+
+	if test x$piversion_include = x; then
+		piversion_include="pi-version.h"
+	fi
+
+	pi_major=`cat $incdir/pi-version.h|grep '#define PILOT_LINK_VERSION'|sed 's/#define PILOT_LINK_VERSION \([[0-9]]*\)/\1/'`
+	pi_minor=`cat $incdir/pi-version.h|grep '#define PILOT_LINK_MAJOR'|sed 's/#define PILOT_LINK_MAJOR \([[0-9]]*\)/\1/'`
+	pi_micro=`cat $incdir/pi-version.h|grep '#define PILOT_LINK_MINOR'|sed 's/#define PILOT_LINK_MINOR \([[0-9]]*\)/\1/'`
+	pi_patch=`cat $incdir/pi-version.h|grep '#define PILOT_LINK_PATCH'|sed 's/#define PILOT_LINK_PATCH \"\(.*\)\"/\1/'`
+
+	PILOT_LINK_MAJOR="$pi_major"
+	PILOT_LINK_MINOR="$pi_minor"
+	PILOT_LINK_MICRO="$pi_micro"
+	PILOT_LINK_PATCH="$pi_patch"
+	PILOT_LINK_VERSION="$pi_major.$pi_minor.$pi_micro$pi_patch"
+
+	if test x$testplversion = xyes; then
+		AC_MSG_CHECKING([for pilot-link version >= $1])
+		pl_ma=`echo $1|sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+		pl_mi=`echo $1|sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+		pl_mc=`echo $1|sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+		CFLAGS_save="$CFLAGS"
+		CFLAGS="$CFLAGS $PISOCK_CFLAGS"
+		AC_TRY_RUN(
+			[
+			#include <$piversion_include>
+			int main(int argc,char *argv[]) {
+				if (PILOT_LINK_VERSION == $pl_ma) {
+					if (PILOT_LINK_MAJOR == $pl_mi) {
+						if (PILOT_LINK_MINOR >= $pl_mc) {
+							return 0;
+				       	  	}
+					} else if (PILOT_LINK_MAJOR > $pl_mi) {
+						return 0;
+					}
+				} else if (PILOT_LINK_VERSION > $pl_ma) {
+					return 0;
+				}
+				return 1;
+			}
+			],
+			[AC_MSG_RESULT([yes (found $PILOT_LINK_VERSION)])],
+			[AC_MSG_ERROR([pilot-link >= $1 required])],
+			[AC_MSG_WARN([No action taken for crosscompile])]
+		)
+		CFLAGS="$CFLAGS_save"
+	fi
+
+	unset piversion_include
+	unset pi_verion
+	unset pi_major
+	unset pi_minor
+	unset pi_patch
+	unset incdir
+	unset pl_mi
+	unset pl_ma
+	unset pl_ve
+])
+
+AC_DEFUN([PILOT_LINK_CHECK],[
+	PILOT_LINK_HOOK($1,[],nofailure)
+])
\ No newline at end of file
Index: configure.in
===================================================================
RCS file: /cvs/gnome/evolution/configure.in,v
retrieving revision 1.911
diff -u -r1.911 configure.in
--- configure.in	7 Aug 2006 19:02:36 -0000	1.911
+++ configure.in	20 Aug 2006 20:05:23 -0000
@@ -606,8 +606,22 @@
 	fi
 fi
 AM_CONDITIONAL(ENABLE_PILOT_CONDUITS, test "x$enable_pilot_conduits" = "xyes")
+dnl ******************************
+dnl If pilot conduits are enabled, check version of pilot-link
+dnl ******************************
 if test x$enable_pilot_conduits = xyes; then
    msg_pilot=yes
+
+   PILOT_LINK_CHECK(0.11.4)
+   AC_SUBST(PILOT_LINK_MAJOR)
+   AC_SUBST(PILOT_LINK_MINOR)
+   AC_SUBST(PILOT_LINK_MICRO)
+   AC_SUBST(PILOT_LINK_PATCH)
+   AC_SUBST(PILOT_LINK_VERSION)
+
+   if test $PILOT_LINK_MINOR -ge 12; then
+      AC_DEFINE(PILOT_LINK_0_12,,[Building against pilot-link 0.12.0 or greater])
+   fi
 else
    msg_pilot=no
 fi
Index: memo-conduit.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/conduits/memo/memo-conduit.c,v
retrieving revision 1.1
diff -u -r1.1 memo-conduit.c
--- memo-conduit.c	19 Oct 2005 11:39:35 -0000	1.1
+++ memo-conduit.c	20 Aug 2006 19:50:59 -0000
@@ -331,6 +331,9 @@
 {
 	static char buff[ 64 ];
 	struct Memo memo;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t piBuf;
+#endif
 
 	if (remote == NULL) {
 		sprintf (buff, "[NULL]");
@@ -338,7 +341,15 @@
 	}
 
 	memset (&memo, 0, sizeof (struct Memo));
+#ifdef PILOT_LINK_0_12
+	piBuf.data = remote->record;
+	piBuf.allocated = remote->length;
+	piBuf.used = remote->length;
+	unpack_Memo(&memo, &piBuf, memo_v1);
+#else
+	
 	unpack_Memo (&memo, remote->record, remote->length);
+#endif
 
 	g_snprintf (buff, 64, "['%s']",
 		    memo.text ?
@@ -446,12 +457,24 @@
 	}
 }
 
+/**
+ * convert a local EMemoLocalRecord to a GnomePilotRecord for the PDA
+ * 
+ * @param local local Evolution memo record
+ * @param ctxt conduit context
+ * @param record record to use for GnomePilotRecord. Allow the calling
+ *               function to determine if the record should be allocated
+ *               dynamically or statically.
+ * @param maxRecordLen size of *record (max amount of data that can be put
+ *                      into record)
+ */
 static GnomePilotRecord
 local_record_to_pilot_record (EMemoLocalRecord *local,
-			      EMemoConduitContext *ctxt)
+			      EMemoConduitContext *ctxt,
+			      unsigned char *record,
+			      int maxRecordLen)
 {
 	GnomePilotRecord p;
-	static char record[0xffff];
 
 	g_assert (local->comp != NULL);
 	g_assert (local->memo != NULL );
@@ -465,8 +488,19 @@
 	p.secret = local->local.secret;
 
 	/* Generate pilot record structure */
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = record;
+		piBuf.allocated = maxRecordLen;
+		piBuf.used = 0;
+		p.length = pack_Memo(local->memo, &piBuf, memo_v1);
+		p.record = piBuf.data;
+	}
+#else
 	p.record = record;
 	p.length = pack_Memo (local->memo, p.record, 0xffff);
+#endif
 
 	return p;	
 }
@@ -483,53 +517,39 @@
 {
 	int i, j;
 	int retval = 0; /* 0 is the Unfiled category */
-	LOG(fprintf(stderr, "add_category_if_possible: called\n"));
+	LOG(g_message("add_category_if_possible\n"));
 	
 	for(i=0; i<16; i++){
 		/* if strlen is 0, then the category is empty
 		   the PalmOS doesn't let 0-length strings for
 		   categories */
-		LOG(fprintf(stderr, "add_category_if_possible: calling strlen, i==%d\n", i));
 		if(strlen(category->name[i]) == 0){
 			int cat_to_add_len;
-			LOG(fprintf(stderr, "add_category_if_possible: strlen == 0\n"));
 			
 			cat_to_add_len = strlen(cat_to_add);
-			LOG(fprintf(stderr, "add_category_if_possible: cat_to_add_len: %d\n",
-					cat_to_add_len));
 			retval = i;
 			
 			/* only 15 characters for category, 16th is
 			 * '\0' can't do direct mem transfer due to
 			 * declaration type
 			 */
-			LOG(fprintf(stderr, "add_category_if_possible: copying first 15 of category\n"));
 			for(j=0; j<cat_to_add_len; j++){
 				category->name[i][j] = cat_to_add[j];
 			}
-			LOG(fprintf(stderr,
-				"add_category_if_possible: setting from %d to i==15 to \\0\n",
-				cat_to_add_len));
 
 			for(j=cat_to_add_len; j<16; j++)
 				category->name[i][j] = '\0';
 			
-			LOG(fprintf(stderr, "add_category_if_possible: setting ID[%d] to %d\n",
-				category->ID[i], lastDesktopUniqueID));
 			category->ID[i] = lastDesktopUniqueID;
 			lastDesktopUniqueID++;
-			
-			LOG(fprintf(stderr, "add_category_if_possible: setting renamed[%d] to TRUE\n", i));
 			category->renamed[i] = TRUE;
 			
-			LOG(g_message("*** adding category '%s', ID %d ***",
-				category->name[i], category->ID[i]));
 			break;
 		}
 	}
 	
 	if(retval == 0){
-		LOG(g_message("*** not adding category - category list already full ***"));
+		LOG(g_warning( _("*** not adding category - category list already full ***") ));
 	}
 	
 	return retval;
@@ -554,31 +574,45 @@
 	local->comp = comp;
 	g_object_ref (comp);
 
-	LOG(fprintf(stderr, "local_record_from_comp: calling e_cal_component_get_uid\n"));
 	e_cal_component_get_uid (local->comp, &uid);
-	LOG(fprintf(stderr, "local_record_from_comp: got UID - %s, calling e_pilot_map_lookup_pid\n", uid));
 	local->local.ID = e_pilot_map_lookup_pid (ctxt->map, uid, TRUE);
-	LOG(fprintf(stderr, "local_record_from_comp: local->local.ID == %lu\n", local->local.ID));
 
 	compute_status (ctxt, local, uid);
-	
-	LOG(fprintf(stderr, "local_record_from_comp: local->local.attr: %d\n", local->local.attr));
 
 	local->memo = g_new0 (struct Memo,1);
 
 	/* Don't overwrite the category */
 	if (local->local.ID != 0) {
-		char record[0xffff];
 		int cat = 0;
+		int dlpReadRetval = 0;
+#ifdef PILOT_LINK_0_12
+		pi_buffer_t *piBuf;
+		piBuf = pi_buffer_new(0xffff);
+		if(piBuf == NULL) {
+			WARN( _("local_record_from_comp: no more memory to allocate") );
+			return;
+		}
 		
-		LOG(fprintf(stderr, "local_record_from_comp: calling dlp_ReadRecordById\n"));
-		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
-					ctxt->dbi->db_handle,
-					local->local.ID, &record, 
-					NULL, NULL, NULL, &cat) > 0) {
+		dlpReadRetval = dlp_ReadRecordById(ctxt->dbi->pilot_socket,
+						   ctxt->dbi->db_handle,
+						   local->local.ID, piBuf,
+						   NULL, NULL, &cat);
+#else
+		unsigned char record[0xffff];
+		dlpReadRetval = dlp_ReadRecordById(ctxt->dbi->pilot_socket, 
+						   ctxt->dbi->db_handle,
+						   local->local.ID, &record, 
+						   NULL, NULL, NULL, &cat);
+#endif
+
+		
+		if (dlpReadRetval > 0) {
 			local->local.category = cat;
 		}
-		LOG(fprintf(stderr, "local_record_from_comp: done calling dlp_ReadRecordById\n"));
+		
+#ifdef PILOT_LINK_0_12
+		pi_buffer_free(piBuf);
+#endif
 	}
 	
 	/*
@@ -589,34 +623,23 @@
 		int cat = -1;
 		int i;
 		
-		LOG(fprintf(stderr, "local_record_from_comp: trying to set category"));
-		LOG(fprintf(stderr, "local_record_from_comp: calling e_cal_component_get_categories_list\n"));
-		
 		e_cal_component_get_categories_list(comp, &categ_list_head);
-		LOG(fprintf(stderr, "local_record_from_comp: got list, setting categ_list_cur to head\n"));
 		
 		categ_list_cur = categ_list_head;
 		while (categ_list_cur && cat == -1)
 		{	
-			LOG(fprintf(stderr, "local_record_from_comp: iterating, data == %s",
-				(char *)categ_list_cur->data));
 			for(i=0; i<16; i++){
-				LOG(fprintf(stderr, "local_record_from_comp: i == %d\n", i));
 				if(strcmp((char *)categ_list_cur->data,
 					  ctxt->ai.category.name[i]) == 0){
 					cat = i;
-					LOG(fprintf(stderr, "local_record_from_comp: found category, name: %s\n",
-							ctxt->ai.category.name[i]));
 					break;
 				}
 			}
 			
-			LOG(fprintf(stderr, "local_record_from_comp: calling g_slist_next\n"));
 			categ_list_cur = g_slist_next(categ_list_cur);
 		}
 		
 		if(cat != -1){
-			LOG(fprintf(stderr, "local_record_from_comp: setting category\n"));
 			local->local.category = cat;
 		}
 		else if(categ_list_head != NULL){
@@ -708,7 +731,18 @@
 	g_return_val_if_fail (remote != NULL, NULL);
 
 	memset (&memo, 0, sizeof (struct Memo));
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = remote->record;
+		piBuf.allocated = remote->length;
+		piBuf.used = remote->length;
+		unpack_Memo(&memo, &piBuf, memo_v1);
+	}
+#else
+
 	unpack_Memo (&memo, remote->record, remote->length);
+#endif
 
 	utc_zone = icaltimezone_get_utc_timezone ();
 	now = icaltime_from_timet_with_zone (time (NULL), FALSE, 
@@ -836,7 +870,11 @@
 	GnomePilotConduitSyncAbs *abs_conduit;
 	GList *l;
 	int len;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t *piBuf;
+#else
 	unsigned char *buf;
+#endif
 	char *filename, *change_id;
 	icalcomponent *icalcomp;
 	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
@@ -929,9 +967,26 @@
 	g_message("num_records: %d\nadd_records: %d\nmod_records: %d\ndel_records: %d\n",
 		num_records, add_records, mod_records, del_records);
 
+#ifdef PILOT_LINK_0_12
+	piBuf = pi_buffer_new(0xffff);
+	if(piBuf == NULL) {
+		WARN (_("pre_sync(): Error allocating pi_buffer_t memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating pi_buffer_t memory"));
+		return -1;
+	}
+	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, -1, piBuf);
+#else
 	buf = (unsigned char*)g_malloc (0xffff);
+	if(buf == NULL) {
+		WARN (_("pre_sync(): Error allocating buf memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating buf memory"));
+		return -1;
+	}
 	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
 			      (unsigned char *)buf, 0xffff);
+#endif
 	
 	if (len < 0) {
 		WARN (_("Could not read pilot's Memo application block"));
@@ -940,8 +995,14 @@
 					   _("Could not read pilot's Memo application block"));
 		return -1;
 	}
+	
+#ifdef PILOT_LINK_0_12
+	unpack_MemoAppInfo (&(ctxt->ai), piBuf->data, len);
+	pi_buffer_free(piBuf);
+#else
 	unpack_MemoAppInfo (&(ctxt->ai), buf, len);
 	g_free (buf);
+#endif
 	
 	lastDesktopUniqueID = 128;
 
@@ -963,6 +1024,9 @@
 	unsigned char *buf;
 	int dlpRetVal, len;
 
+	/* Write AppBlock to PDA - updates categories */
+	/* NOTE: not changed for pilot-link 0.12 because the two
+	 * functions below didn't change */
 	buf = (unsigned char*)g_malloc (0xffff);
 	
 	len = pack_MemoAppInfo (&(ctxt->ai), buf, 0xffff);
@@ -1156,6 +1220,7 @@
 	/* used by the quick compare */
 	GnomePilotRecord local_pilot;
 	int retval = 0;
+	static unsigned char record[0xffff];
 
 	LOG (g_message ("compare: local=%s remote=%s...\n",
 			print_local (local), print_remote (remote)));
@@ -1163,7 +1228,7 @@
 	g_return_val_if_fail (local!=NULL,-1);
 	g_return_val_if_fail (remote!=NULL,-1);
 
-	local_pilot = local_record_to_pilot_record (local, ctxt);
+	local_pilot = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	if (remote->length != local_pilot.length
 	    || memcmp (local_pilot.record, remote->record, remote->length))
@@ -1319,9 +1384,10 @@
 	 GnomePilotRecord *remote,
 	 EMemoConduitContext *ctxt)
 {
+	static unsigned char record[0xffff];
 	LOG (g_message ( "prepare: encoding local %s\n", print_local (local) ));
 
-	*remote = local_record_to_pilot_record (local, ctxt);
+	*remote = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	return 0;
 }
Index: todo-conduit.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/conduits/todo/todo-conduit.c,v
retrieving revision 1.98
diff -u -r1.98 todo-conduit.c
--- todo-conduit.c	13 May 2006 07:58:02 -0000	1.98
+++ todo-conduit.c	20 Aug 2006 19:51:13 -0000
@@ -409,7 +409,17 @@
 	}
 
 	memset (&todo, 0, sizeof (struct ToDo));
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = remote->record;
+		piBuf.allocated = remote->length;
+		piBuf.used = remote->length;
+		unpack_ToDo(&todo, &piBuf, todo_v1);
+	}
+#else
 	unpack_ToDo (&todo, remote->record, remote->length);
+#endif
 
 	g_snprintf (buff, 4096, "[%d %ld %d %d '%s' '%s' %d]",
 		    todo.indefinite,
@@ -589,12 +599,24 @@
 	}
 }
 
+/**
+ * convert a local EMemoLocalRecord to a GnomePilotRecord for the PDA
+ * 
+ * @param local local Evolution memo record
+ * @param ctxt conduit context
+ * @param record record to use for GnomePilotRecord. Allow the calling
+ *               function to determine if the record should be allocated
+ *               dynamically or statically.
+ * @param maxRecordLen size of *record (max amount of data that can be put
+ *                      into record)
+ */
 static GnomePilotRecord
 local_record_to_pilot_record (EToDoLocalRecord *local,
-			      EToDoConduitContext *ctxt)
+			      EToDoConduitContext *ctxt,
+			      unsigned char *record,
+			      int maxRecordLen)
 {
 	GnomePilotRecord p;
-	static char record[0xffff];
 
 	g_assert (local->comp != NULL);
 	g_assert (local->todo != NULL );
@@ -608,8 +630,19 @@
 	p.secret = local->local.secret;
 
 	/* Generate pilot record structure */
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = record;
+		piBuf.allocated = maxRecordLen;
+		piBuf.used = 0;
+		p.length = pack_ToDo(local->todo, &piBuf, todo_v1);
+		p.record = piBuf.data;
+	}
+#else
 	p.record = record;
 	p.length = pack_ToDo (local->todo, p.record, 0xffff);
+#endif
 
 	return p;	
 }
@@ -696,15 +729,33 @@
 
 	/* Don't overwrite the category */
 	if (local->local.ID != 0) {
-		char record[0xffff];
 		int cat = 0;
-		
-		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
-					ctxt->dbi->db_handle,
-					local->local.ID, &record, 
-					NULL, NULL, NULL, &cat) > 0) {
+		int dlpReadRetval = 0;
+#ifdef PILOT_LINK_0_12
+		pi_buffer_t *piBuf = pi_buffer_new(0xffff);
+		if(piBuf == NULL) {
+			WARN( _("local_record_from_comp: no more memory to allocate") );
+			return;
+		}
+		dlpReadRetval = dlp_ReadRecordById(ctxt->dbi->pilot_socket,
+						   ctxt->dbi->db_handle,
+						   local->local.ID, piBuf,
+						   NULL, NULL, &cat);
+#else
+		char record[0xffff];
+		dlpReadRetval = dlp_ReadRecordById (ctxt->dbi->pilot_socket, 
+						    ctxt->dbi->db_handle,
+						    local->local.ID, &record, 
+						    NULL, NULL, NULL, &cat);
+#endif
+
+		if (dlpReadRetval > 0) {
 			local->local.category = cat;
 		}
+		
+#ifdef PILOT_LINK_0_12
+		pi_buffer_free(piBuf);
+#endif
 	}
 	
 	/*
@@ -864,7 +915,17 @@
 	g_return_val_if_fail (remote != NULL, NULL);
 
 	memset (&todo, 0, sizeof (struct ToDo));
+#ifdef PILOT_LINK_0_12
+	{
+		pi_buffer_t piBuf;
+		piBuf.data = remote->record;
+		piBuf.allocated = remote->length;
+		piBuf.used = remote->length;
+		unpack_ToDo(&todo, &piBuf, todo_v1);
+	}
+#else
 	unpack_ToDo (&todo, remote->record, remote->length);
+#endif
 
 	utc_zone = icaltimezone_get_utc_timezone ();
 	now = icaltime_from_timet_with_zone (time (NULL), FALSE, 
@@ -1014,7 +1075,11 @@
 	GnomePilotConduitSyncAbs *abs_conduit;
 	GList *l;
 	int len;
+#ifdef PILOT_LINK_0_12
+	pi_buffer_t *piBuf;
+#else
 	unsigned char *buf;
+#endif
 	char *filename, *change_id;
 	icalcomponent *icalcomp;
 	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
@@ -1104,9 +1169,20 @@
 	g_message("num_records: %d\nadd_records: %d\nmod_records: %d\ndel_records: %d\n",
 			num_records, add_records, mod_records, del_records);
 
+#ifdef PILOT_LINK_0_12
+	piBuf = pi_buffer_new(0xffff);
+	if(piBuf == NULL) {
+		WARN (_("pre_sync(): Error allocating pi_buffer_t memory"));
+		gnome_pilot_conduit_error (conduit,
+			_("pre_sync(): Error allocating pi_buffer_t memory"));
+		return -1;
+	}
+	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, -1, piBuf);
+#else
 	buf = (unsigned char*)g_malloc (0xffff);
 	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
 			      (unsigned char *)buf, 0xffff);
+#endif
 	
 	if (len < 0) {
 		WARN (_("Could not read pilot's ToDo application block"));
@@ -1115,8 +1191,14 @@
 					   _("Could not read pilot's ToDo application block"));
 		return -1;
 	}
+
+#ifdef PILOT_LINK_0_12
+	unpack_ToDoAppInfo (&(ctxt->ai), piBuf->data, len);
+	pi_buffer_free(piBuf);
+#else
 	unpack_ToDoAppInfo (&(ctxt->ai), buf, len);
 	g_free (buf);
+#endif
 	
 	lastDesktopUniqueID = 128;
 
@@ -1138,6 +1220,9 @@
 	unsigned char *buf;
 	int dlpRetVal, len;
 
+	/* Write AppBlock to PDA - updates categories */
+	/* NOTE: not changed for pilot-link 0.12 because the two
+	 * functions below didn't change */
 	buf = (unsigned char*)g_malloc (0xffff);
 	
 	len = pack_ToDoAppInfo (&(ctxt->ai), buf, 0xffff);
@@ -1320,6 +1405,7 @@
 	/* used by the quick compare */
 	GnomePilotRecord local_pilot;
 	int retval = 0;
+	static unsigned char record[0xffff];
 
 	LOG (g_message ("compare: local=%s remote=%s...\n",
 			print_local (local), print_remote (remote)));
@@ -1327,7 +1413,7 @@
 	g_return_val_if_fail (local!=NULL,-1);
 	g_return_val_if_fail (remote!=NULL,-1);
 
-	local_pilot = local_record_to_pilot_record (local, ctxt);
+	local_pilot = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	if (remote->length != local_pilot.length
 	    || memcmp (local_pilot.record, remote->record, remote->length))
@@ -1484,9 +1570,11 @@
 	 GnomePilotRecord *remote,
 	 EToDoConduitContext *ctxt)
 {
+	static unsigned char record[0xffff];
+
 	LOG (g_message ( "prepare: encoding local %s\n", print_local (local) ));
 
-	*remote = local_record_to_pilot_record (local, ctxt);
+	*remote = local_record_to_pilot_record (local, ctxt, record, sizeof(record));
 
 	return 0;
 }


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