Пример #1
0
/***********************************************************************
 *
 * Function:    sync_CopyFromPilot
 *
 * Summary:     Copy all device records from the Palm to the desktop
 *
 * Parameters:  None
 *
 * Returns:     0 on success, non-zero otherwise
 *
 ***********************************************************************/
int sync_CopyFromPilot(SyncHandler * sh)
{
	int 	dbhandle,	
		i,	
		slow 	= 0,
		result 	= 0;
	pi_buffer_t *recbuf;

	DesktopRecord *drecord = NULL;
	PilotRecord *precord = sync_NewPilotRecord(DLP_BUF_SIZE);

	result = open_db(sh, &dbhandle);
	if (result < 0)
		goto cleanup;

	result = sh->Pre(sh, dbhandle, &slow);
	if (result < 0)
		goto cleanup;

	while (sh->ForEach(sh, &drecord) == 0 && drecord) {
		result = sh->DeleteRecord(sh, drecord);
		if (result < 0)
			goto cleanup;
	}

	i = 0;
	recbuf = pi_buffer_new(DLP_BUF_SIZE);
	while (dlp_ReadRecordByIndex(sh->sd, dbhandle, i, recbuf, &precord->recID,
		   &precord->flags, &precord->catID) > 0) {
		precord->len = recbuf->used;
		if (precord->len > DLP_BUF_SIZE)
			precord->len = DLP_BUF_SIZE;
		memcpy(precord->buffer, recbuf->data, precord->len);
		result = sh->AddRecord(sh, precord);
		if (result < 0) {
			pi_buffer_free(recbuf);
			goto cleanup;
		}

		i++;
	}
	pi_buffer_free (recbuf);

	result = sh->Post(sh, dbhandle);

cleanup:
	close_db(sh, dbhandle);
	sync_FreePilotRecord (precord);
	return result;
}
Пример #2
0
/***********************************************************************
 *
 * Function:    sync_MergeFromPilot_fast
 *
 * Summary:     er, fast merge from Palm to desktop
 *
 * Parameters:  None
 *
 * Returns:     0 if success, nonzero otherwise
 *
 ***********************************************************************/
static int
sync_MergeFromPilot_fast(SyncHandler * sh, int dbhandle,
			 RecordModifier rec_mod)
{
	int 	result = 0;
	PilotRecord *precord 	= sync_NewPilotRecord(DLP_BUF_SIZE);
	DesktopRecord *drecord 	= NULL;
	RecordQueue rq 		= { 0, NULL };
	pi_buffer_t *recbuf = pi_buffer_new(DLP_BUF_SIZE);
	
	while (dlp_ReadNextModifiedRec(sh->sd, dbhandle, recbuf,
				       &precord->recID, NULL,
				       &precord->flags,
				       &precord->catID) >= 0) {
		int count = rq.count;
		precord->len = recbuf->used;
		if (precord->len > DLP_BUF_SIZE)
			precord->len = DLP_BUF_SIZE;
		memcpy(precord->buffer, recbuf->data, precord->len);
		ErrorCheck(sh->Match(sh, precord, &drecord));
		ErrorCheck(sync_record
			   (sh, dbhandle, drecord, precord, &rq, rec_mod));

		if (drecord && rq.count == count)
			ErrorCheck(sh->FreeMatch(sh, drecord));
	}
	pi_buffer_free(recbuf);
	sync_FreePilotRecord(precord);

	result = sync_MergeFromPilot_process(sh, dbhandle, &rq, rec_mod);

	return result;
}
Пример #3
0
int pc_contact_write(struct Contact *cont, PCRecType rt, unsigned char attrib,
                     unsigned int *unique_id)
{
   pi_buffer_t *RecordBuffer;
   int i;
   buf_rec br;
   long char_set;

   get_pref(PREF_CHAR_SET, &char_set, NULL);
   if (char_set != CHAR_SET_LATIN1) {
      for (i = 0; i < 39; i++) {
         if (cont->entry[i]) 
            charset_j2p(cont->entry[i], strlen(cont->entry[i])+1, char_set);
      }
   }

   RecordBuffer = pi_buffer_new(0);
   jp_pack_Contact(cont, RecordBuffer);
   if (!RecordBuffer->used) {
      PRINT_FILE_LINE;
      jp_logf(JP_LOG_WARN, "jp_pack_Contact %s\n", _("error"));
      pi_buffer_free(RecordBuffer);
      return EXIT_FAILURE;
   }
   br.rt=rt;
   br.attrib = attrib;

   br.buf = RecordBuffer->data;
   br.size = RecordBuffer->used;
   /* Keep unique ID intact */
   if (unique_id) {
      br.unique_id = *unique_id;
   } else {
      br.unique_id = 0;
   }

   jp_pc_write("ContactsDB-PAdd", &br);
   if (unique_id) {
      *unique_id = br.unique_id;
   }

   pi_buffer_free(RecordBuffer);

   return EXIT_SUCCESS;
}
Пример #4
0
static GnomePilotRecord
local_record_to_pilot_record (EMemoLocalRecord *local,
			      EMemoConduitContext *ctxt)
{
	GnomePilotRecord p;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#else
	static char record[0xffff];
#endif

	memset(&p, 0, sizeof (p));

	g_assert (local->comp != NULL);
	g_assert (local->memo != NULL );

	LOG (g_message ( "local_record_to_pilot_record\n" ));

	memset (&p, 0, sizeof (GnomePilotRecord));

	p.ID = local->local.ID;
	p.category = local->local.category;
	p.attr = local->local.attr;
	p.archived = local->local.archived;
	p.secret = local->local.secret;

	/* Generate pilot record structure */
#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return p;
	}

	pack_Memo (local->memo, buffer, memo_v1);
	p.record = g_new0(unsigned char, buffer->used);
	p.length = buffer->used;
	memcpy(p.record, buffer->data, buffer->used);

	pi_buffer_free(buffer);
#else
	p.record = (unsigned char *)record;
	p.length = pack_Memo (local->memo, p.record, 0xffff);
#endif
	return p;
}
Пример #5
0
static char *print_remote (GnomePilotRecord *remote)
{
	static char buff[ 4096 ];
	struct Address addr;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#endif

	if (remote == NULL) {
		sprintf (buff, "[NULL]");
		return buff;
	}

	memset (&addr, 0, sizeof (struct Address));
#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		sprintf (buff, "[NULL]");
		return buff;
	}
	if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){
		sprintf (buff, "[NULL]");
		return buff;
	}
	unpack_Address (&addr, buffer, address_v1);
	pi_buffer_free(buffer);
#else
	unpack_Address (&addr, remote->record, remote->length);
#endif

	g_snprintf (buff, 4096, "['%s' '%s' '%s']",
		    addr.entry[entryLastname] ?
		    addr.entry[entryLastname] : "",
		    addr.entry[entryFirstname] ?
		    addr.entry[entryFirstname] : "",
		    addr.entry[entryCompany] ?
		    addr.entry[entryCompany] : "");

	free_Address (&addr);

	return buff;
}
Пример #6
0
/***********************************************************************
 *
 * Function:    sync_MergeToPilot_fast
 *
 * Summary:     Fast merge from desktop to Palm
 *
 * Parameters:  None
 *
 * Returns:     0 on success, non-zero otherwise
 *
 ***********************************************************************/
static int
sync_MergeToPilot_fast(SyncHandler * sh, int dbhandle,
		       RecordModifier rec_mod)
{
	int 	result 		= 0;
	PilotRecord *precord 	= NULL;
	DesktopRecord *drecord 	= NULL;
	RecordQueue rq 		= { 0, NULL };
	pi_buffer_t *recbuf = pi_buffer_new(DLP_BUF_SIZE);

	while (sh->ForEachModified(sh, &drecord) == 0 && drecord) {
		if (drecord->recID != 0) {
			precord = sync_NewPilotRecord(DLP_BUF_SIZE);
			precord->recID = drecord->recID;
			PilotCheck(dlp_ReadRecordById(sh->sd, dbhandle,
						      precord->recID,
						      recbuf,
						      NULL,
						      &precord->flags,
						      &precord->catID));
			precord->len = recbuf->used;
			if (precord->len > DLP_BUF_SIZE)
				precord->len = DLP_BUF_SIZE;
			memcpy(precord->buffer, recbuf->data, precord->len);
		}

		ErrorCheck(sync_record
			   (sh, dbhandle, drecord, precord, &rq, rec_mod));

		if (precord)
			sync_FreePilotRecord (precord);
		precord = NULL;
	}
	pi_buffer_free(recbuf);

	result = sync_MergeFromPilot_process(sh, dbhandle, &rq, rec_mod);

	return result;
}
Пример #7
0
static char *print_remote (GnomePilotRecord *remote)
{
	static char buff[ 64 ];
	struct Memo memo;
#ifdef PILOT_LINK_0_12
	pi_buffer_t *buffer;
#endif

	if (remote == NULL) {
		sprintf (buff, "[NULL]");
		return buff;
	}

	memset (&memo, 0, sizeof (struct Memo));
#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		sprintf (buff, "[NULL]");
		return buff;
	}
	if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){
		sprintf (buff, "[NULL]");
		return buff;
	}
	unpack_Memo (&memo, buffer, memo_v1);

	pi_buffer_free(buffer);
#else
	unpack_Memo (&memo, remote->record, remote->length);
#endif
	g_snprintf (buff, 64, "['%s']",
		    memo.text ?
		    memo.text : "");

	free_Memo (&memo);

	return buff;
}
Пример #8
0
/*
 * Unpack address, building new data inside cache.
 */
static void jpilot_load_address( JPilotFile *pilotFile, buf_rec *buf, ItemFolder *folderInd[] ) {
	struct Address addr;
	gchar **addrEnt;
	gint num, k;
	gint cat_id = 0;
	guint unique_id;
	guchar attrib;
	gchar fullName[ FULLNAME_BUFSIZE ];
	gchar bufEMail[ EMAIL_BUFSIZE ];
	ItemPerson *person;
	ItemEMail *email;
	gint *indPhoneLbl;
	gchar *labelEntry;
	GList *node;
	gchar* extID;
	struct AddressAppInfo *ai;
	gchar **firstName = NULL;
	gchar **lastName = NULL;
#if (PILOT_LINK_MAJOR > 11)
	pi_buffer_t *RecordBuffer;
#endif /* PILOT_LINK_0_12 */

	/* Retrieve address */
#if (PILOT_LINK_MAJOR < 12)
	num = unpack_Address( & addr, buf->buf, buf->size );
	if( num > 0 ) {
#else /* PILOT_LINK_0_12 */
	RecordBuffer = pi_buffer_new(buf->size);
	memcpy(RecordBuffer->data, buf->buf, buf->size);
	RecordBuffer->used = buf->size;
	num = unpack_Address( & addr, RecordBuffer, address_v1 );
	pi_buffer_free(RecordBuffer);
	if (num != -1) {
#endif
		gchar *nameConv;

		addrEnt = addr.entry;
		attrib = buf->attrib;
		unique_id = buf->unique_id;
		cat_id = attrib & 0x0F;

		*fullName = *bufEMail = '\0';

		if( addrEnt[ IND_LABEL_FIRSTNAME ] ) {
			firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 );
		}
		if( addrEnt[ IND_LABEL_LASTNAME ] ) {
			lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 );
		}

		if( name_order == FAMILY_LAST ) {
			g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s",
				    firstName ? firstName[0] : "",
				    lastName ? lastName[0] : "" );
		}
		else {
			g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s",
				    lastName ? lastName[0] : "",
				    firstName ? firstName[0] : "" );
		}

		if( firstName ) {
			g_strfreev( firstName );
		}
		if( lastName ) {
			g_strfreev( lastName );
		}

		g_strstrip( fullName );

		nameConv = jpilot_convert_encoding( fullName );
		strncpy2( fullName, nameConv, FULLNAME_BUFSIZE );
		g_free( nameConv );

		person = addritem_create_item_person();
		addritem_person_set_common_name( person, fullName );
		addritem_person_set_first_name( person, addrEnt[ IND_LABEL_FIRSTNAME ] );
		addritem_person_set_last_name( person, addrEnt[ IND_LABEL_LASTNAME ] );
		addrcache_id_person( pilotFile->addressCache, person );

		extID = g_strdup_printf( "%d", unique_id );
		addritem_person_set_external_id( person, extID );
		g_free( extID );
		extID = NULL;

		/* Pointer to address metadata. */
		ai = & pilotFile->addrInfo;

		/* Add entry for each email address listed under phone labels. */
		indPhoneLbl = addr.phoneLabel;
		for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) {
			gint ind;

			ind = indPhoneLbl[k];
			/*
			* fprintf( stdout, "%d : %d : %20s : %s\n", k, ind,
			* ai->phoneLabels[ind], addrEnt[3+k] );
			*/
			if( indPhoneLbl[k] == IND_PHONE_EMAIL ) {
				labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ];
				if( labelEntry ) {
					strcpy( bufEMail, labelEntry );
					g_strchug( bufEMail );
					g_strchomp( bufEMail );

					email = addritem_create_item_email();
					addritem_email_set_address( email, bufEMail );
					addrcache_id_email( pilotFile->addressCache, email );
					addrcache_person_add_email
						( pilotFile->addressCache, person, email );
				}
			}
		}

		/* Add entry for each custom label */
		node = pilotFile->labelInd;
		while( node ) {
			gint ind;

			ind = GPOINTER_TO_INT( node->data );
			if( ind > -1 ) {
				/*
				* fprintf( stdout, "%d : %20s : %s\n", ind, ai->labels[ind],
				* addrEnt[ind] );
				*/
				labelEntry = addrEnt[ind];
				if( labelEntry ) {
					gchar *convertBuff;

					strcpy( bufEMail, labelEntry );
					g_strchug( bufEMail );
					g_strchomp( bufEMail );

					email = addritem_create_item_email();
					addritem_email_set_address( email, bufEMail );

					convertBuff = jpilot_convert_encoding( ai->labels[ind] );
					addritem_email_set_remarks( email, convertBuff );
					g_free( convertBuff );

					addrcache_id_email( pilotFile->addressCache, email );
					addrcache_person_add_email
						( pilotFile->addressCache, person, email );
				}
			}

			node = g_list_next( node );
		}

		if( person->listEMail ) {
			if( cat_id > -1 && cat_id < JPILOT_NUM_CATEG ) {
				/* Add to specified category */
				addrcache_folder_add_person
					( pilotFile->addressCache, folderInd[cat_id], person );
			}
			else {
				/* Add to root folder */
				addrcache_add_person( pilotFile->addressCache, person );
			}
		}
		else {
			addritem_free_item_person( person );
			person = NULL;
		}
	}
}

/*
 * Free up address list.
 */
static void jpilot_free_addrlist( GList *records ) {
	GList *node;
	buf_rec *br;

	node = records;
	while( node ) {
		br = node->data;
		free( br );
		node->data = NULL;
		node = g_list_next( node );
	}

	/* Free up list */
	g_list_free( records );
}
Пример #9
0
int main(int argc, const char *argv[])
{
	int 	c,		/* switch */
		db,
		sd 		= -1,
		i,
		read_todos 	= -1;
	FILE 	*ical = NULL;
	char 	cmd[255],
		*ptext 		= NULL,
		*icalfile 	= NULL,
		*pubtext 	= NULL;
	struct ToDoAppInfo tai;
	pi_buffer_t *recbuf,
	    *appblock;

	poptContext pc;

	struct poptOption options[] = {
		USERLAND_RESERVED_OPTIONS
		{"datebook", 'd', POPT_ARG_VAL, &read_todos, 0,
		 "Datebook only, no ToDos", NULL},
		{"pubtext", 't', POPT_ARG_STRING, &ptext, 0,
		 "Replace text of items not started with a bullet with <pubtext>",
		 "pubtext"},
		{"file", 'f', POPT_ARG_STRING, &icalfile, 0,
		 "Write the ical formatted data to <file> (overwrites existing <file>)",
		 "file"},
		POPT_TABLEEND
	};

	pc = poptGetContext("read-ical", argc, argv, options, 0);
	poptSetOtherOptionHelp(pc,"\n\n"
		"   Dumps the DatebookDB and/or ToDo applications to ical format.\n"
		"   Requires the program 'ical'.\n\n");

	if (argc < 2) {
		poptPrintUsage(pc,stderr,0);
		return 1;
	}

	while ((c = poptGetNextOpt(pc)) >= 0) {
		fprintf(stderr,"   ERROR: Unhandled option %d.\n",c);
		return 1;
	}

	if (c < -1) {
		plu_badoption(pc,c);
		return 1;
	}


	if (icalfile == NULL) {
		fprintf(stderr, "   ERROR: ical filename not specified. Please use the -f option.\n");
		return 1;
	}

        sd = plu_connect();
        if (sd < 0)
                goto error;

	unlink(icalfile);
	sprintf(cmd, "ical -list -f - -calendar %s", icalfile);
	ical = popen(cmd, "w");
	if (ical == NULL) {
		int e = errno;
		fprintf(stderr,"   ERROR: cannot start communication with ical.\n"
			"          %s\n",strerror(e));
		return 1;
	}
	fprintf(ical, "calendar cal $ical(calendar)\n");

        if (dlp_OpenConduit(sd) < 0)
                goto error_close;


	if (read_todos) {
		/* Open the ToDo database, store access handle in db */
		if (dlp_OpenDB
		    (sd, 0, 0x80 | 0x40, "ToDoDB", &db) < 0) {
			fprintf(stderr,"   ERROR: Unable to open ToDoDB on Palm.\n");
			dlp_AddSyncLogEntry(sd, "Unable to open ToDoDB.\n");
			goto error_close;
		}

		appblock = pi_buffer_new(0xffff);
		dlp_ReadAppBlock(sd, db, 0, 0xffff, appblock);
		unpack_ToDoAppInfo(&tai, appblock->data, appblock->used);
		pi_buffer_free(appblock);

		recbuf = pi_buffer_new (0xffff);

		for (i = 0;; i++) {
			int 	attr,
				category;
			char 	id_buf[255];
			struct 	ToDo t;
			recordid_t id_;

			int len = dlp_ReadRecordByIndex(sd, db, i, recbuf, &id_, &attr, &category);

			if (len < 0)
				break;

			/* Skip deleted records */
			if ((attr & dlpRecAttrDeleted)
			    || (attr & dlpRecAttrArchived))
				continue;

			unpack_ToDo(&t, recbuf, todo_v1);

			fprintf(ical, "set n [notice]\n");

			/* '\x95' is the "bullet" chcter */
			fprintf(ical, "$n text %s\n", tclquote((pubtext && t.description[0] != '\x95') ? pubtext : t.description));
			fprintf(ical, "$n date [date today]\n");
			fprintf(ical, "$n todo 1\n");
			fprintf(ical, "$n option Priority %d\n", t.priority);
			sprintf(id_buf, "%lx", id_);
			fprintf(ical, "$n option PilotRecordId %s\n", id_buf);
			fprintf(ical, "$n done %d\n", t.complete ? 1 : 0);
			fprintf(ical, "cal add $n\n");

			free_ToDo(&t);
		}
		pi_buffer_free(recbuf);

		/* Close the database */
		dlp_CloseDB(sd, db);

		dlp_AddSyncLogEntry(sd, "Successfully read todos from Palm.\nThank you for using pilot-link.\n");
	}

	/* Open the Datebook's database, store access handle in db */
	if (dlp_OpenDB
	    (sd, 0, 0x80 | 0x40, "DatebookDB", &db) < 0) {
		fprintf(stderr,"   ERROR: Unable to open DatebookDB on Palm.\n");
		dlp_AddSyncLogEntry(sd, "Unable to open DatebookDB.\n");
		goto error_close;
	}

	recbuf = pi_buffer_new (0xffff);

	for (i = 0;; i++) {
		int 	j,
			attr;
		char 	id_buf[255];
		struct 	Appointment a;
		recordid_t id_;

		int len =
		    dlp_ReadRecordByIndex(sd, db, i, recbuf, &id_, &attr, 0);

		if (len < 0)
			break;

		/* Skip deleted records */
		if ((attr & dlpRecAttrDeleted)
		    || (attr & dlpRecAttrArchived))
			continue;

		unpack_Appointment(&a, recbuf, datebook_v1);

		if (a.event) {
			fprintf(ical, "set i [notice]\n");

		} else {
			int 	start,
				end;

			fprintf(ical, "set i [appointment]\n");

			start =
			    a.begin.tm_hour * 60 +
			    a.begin.tm_min;
			end =
			    a.end.tm_hour * 60 +
			    a.end.tm_min;

			fprintf(ical, "$i starttime %d\n", start);
			fprintf(ical, "$i length %d\n", end - start);
		}

		/* Don't hilight private (secret) records */
		if (attr & dlpRecAttrSecret) {
			fprintf(ical, "$i hilite never\n");
		}

		/* Handle alarms */
		if (a.alarm) {
			if (a.event) {
				if (a.advanceUnits == 2) {
					fprintf(ical, "$i earlywarning %d\n", a.advance);
				} else {
					printf("Minute or hour alarm on untimed event ignored: %s\n", a.description);
				}
			} else {
				switch (a.advanceUnits) {
				  case 0:
					  fprintf(ical, "$i alarms { %d }\n", a.advance);
					  break;
				  case 1:
					  fprintf(ical, "$i alarms { %d }\n", a.advance * 60);
					  break;
				  case 2:
					  fprintf(ical, "$i earlywarning %d\n", a.advance);
					  break;
				}
			}
		}

		/* '\x95' is the "bullet" chcter */
		fprintf(ical, "$i text %s\n",
			tclquote((pubtext
				  && a.description[0] !=
				  '\x95') ? pubtext : a.
				 description));

		fprintf(ical,
			"set begin [date make %d %d %d]\n",
			a.begin.tm_mday,
			a.begin.tm_mon + 1,
			a.begin.tm_year + 1900);

		if (a.repeatFrequency) {
			if (a.repeatType == repeatDaily) {
				fprintf(ical,
					"$i dayrepeat %d $begin\n", a.repeatFrequency);
			} else if (a.repeatType == repeatMonthlyByDate) {
				fprintf(ical, "$i month_day %d $begin %d\n", a.begin.tm_mon + 1, a.repeatFrequency);
			} else if (a.repeatType == repeatMonthlyByDay) {
				if (a.repeatDay >= domLastSun) {
					fprintf(ical, "$i month_last_week_day %d 1 $begin %d\n", a.repeatDay % 7 + 1, a.repeatFrequency);
				} else {
					fprintf(ical, "$i month_week_day %d %d $begin %d\n", a.repeatDay % 7 + 1, a.repeatDay / 7 + 1, a.repeatFrequency);
				}
			} else if (a.repeatType == repeatWeekly) {
				/*
				 * Handle the case where the user said weekly repeat, but
				 * really meant daily repeat every n*7 days.  Note: We can't
				 * do days of the week and a repeat-frequency > 1, so do the
				 * best we can and go on.
				 */
				if (a.repeatFrequency > 1) {
					int ii, found;

					for (ii = 0, found = 0; ii < 7; ii++) {
						if (a.repeatDays [ii])
							found++;
					}
					if (found > 1) {
						fprintf(stderr,"   WARNING: Incomplete translation of %s\n", a.description);
					}
					fprintf(ical, "$i dayrepeat %d $begin\n", a.repeatFrequency * 7);
				} else {
					int ii;

					fprintf(ical, "$i weekdays ");
					for (ii = 0; ii < 7; ii++)
						if (a.repeatDays [ii])
							fprintf(ical, "%d ", ii + 1);
					fprintf(ical, "\n");
				}
			} else if (a.repeatType == repeatYearly) {
				fprintf(ical, "$i monthrepeat %d $begin\n", 12 * a.repeatFrequency);
			}
			fprintf(ical, "$i start $begin\n");
			if (!a.repeatForever)
				fprintf(ical,
					"$i finish [date make %d %d %d]\n",
					a.repeatEnd.tm_mday, a.repeatEnd.tm_mon + 1, a.repeatEnd.tm_year + 1900);
			if (a.exceptions)
				for (j = 0; j < a.exceptions; j++)
					fprintf(ical, "$i deletion [date make %d %d %d]\n", a.exception[j].tm_mday, a.exception[j].tm_mon + 1, a.exception[j].tm_year + 1900);
		} else
			fprintf(ical, "$i date $begin\n");

		sprintf(id_buf, "%lx", id_);
		fprintf(ical, "$i option PilotRecordId %s\n", id_buf);
		fprintf(ical, "cal add $i\n");

		free_Appointment(&a);

	}

	pi_buffer_free (recbuf);

	fprintf(ical, "cal save [cal main]\n");
	fprintf(ical, "exit\n");

	pclose(ical);

	/* Close the database */
	dlp_CloseDB(sd, db);

	dlp_AddSyncLogEntry(sd, "read-ical successfully read Datebook from Palm.\n"
				"Thank you for using pilot-link.\n");
	dlp_EndOfSync(sd, 0);
	pi_close(sd);
	return 0;

error_close:
	if (ical) {
		/* explicitly do NOT save on failure. since we've already unlinked
		   the original ical file, we've still destroyed something. */
		fprintf(ical, "exit\n");
		pclose(ical);
	}
        pi_close(sd);

error:
        return -1;
}
Пример #10
0
static void
local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrConduitContext *ctxt)
{
	EContactAddress *address = NULL;
	int phone = entryPhone1;
	EContactField field;
	gboolean syncable;
	int i;

	g_return_if_fail (local != NULL);
	g_return_if_fail (contact != NULL);

	local->contact = g_object_ref (contact);
	local->local.ID = e_pilot_map_lookup_pid (ctxt->map, e_contact_get_const (contact, E_CONTACT_UID), TRUE);

	compute_status (ctxt, local, e_contact_get_const (contact, E_CONTACT_UID));

	local->addr = g_new0 (struct Address, 1);

	/* Handle the fields and category we don't sync by making sure
         * we don't overwrite them
	 */
	if (local->local.ID != 0) {
		struct Address addr;
		int cat = 0;
#ifdef PILOT_LINK_0_12
		pi_buffer_t * record;
		record = pi_buffer_new(DLP_BUF_SIZE);
		if(record == NULL){
			pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
			return;
		}
#else
		char record[0xffff];
#endif

		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket,
					ctxt->dbi->db_handle,
#ifdef PILOT_LINK_0_12
					local->local.ID, record,
					NULL, NULL, &cat) > 0) {
#else
					local->local.ID, &record,
					NULL, NULL, NULL, &cat) > 0) {
#endif
			local->local.category = cat;
			memset (&addr, 0, sizeof (struct Address));
#ifdef PILOT_LINK_0_12
			unpack_Address (&addr, record, address_v1);
#else
			unpack_Address (&addr, (unsigned char *)record, 0xffff);
#endif
			for (i = 0; i < 5; i++) {
				if (addr.entry[entryPhone1 + i])
					local->addr->entry[entryPhone1 + i] =
						strdup (addr.entry[entryPhone1 + i]);
				local->addr->phoneLabel[i] = addr.phoneLabel[i];
			}
			local->addr->showPhone = addr.showPhone;
			for (i = 0; i < 4; i++) {
				if (addr.entry[entryCustom1 + i])
					local->addr->entry[entryCustom1 + i] =
						strdup (addr.entry[entryCustom1 + i]);
			}
			free_Address (&addr);
		}
#ifdef PILOT_LINK_0_12
		pi_buffer_free (record);
#endif
	}

	local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
	local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
	local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG));
	local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE));

	/* See if the default has something in it */
	if ((address = e_contact_get (contact, ctxt->cfg->default_address))) {
		field = ctxt->cfg->default_address;
	} else {
		/* Try to find a non-empty address field */
		for (field = E_CONTACT_FIRST_ADDRESS_ID; field <= E_CONTACT_LAST_ADDRESS_ID; field++) {
			if ((address = e_contact_get (contact, field)))
				break;
		}
	}

	if (address) {
		char *add;

		/* If the address has 2 lines, make sure both get added */
		if (address->ext != NULL &&
		    strlen (address->ext) > 0) {
			add = g_strconcat (address->street, "\n", address->ext, NULL);
			LOG (g_warning ("Address has two lines: [%s]\n", add));
		}
		else {
			add = g_strdup (address->street);
			LOG (g_warning ("Address has only one line: [%s]\n", add));
		}
		local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add);
		g_free (add);

		local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality);
		local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region);
		local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code);
		local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country);

		e_contact_address_free (address);
	}

	/* Phone numbers */

	/* See if everything is syncable */
	syncable = is_syncable (ctxt, local);

	if (syncable) {
		INFO ("Syncable");

		/* Sync by priority */
		for (i = 0, phone = entryPhone1;
		     priority[i] != E_CONTACT_FIELD_LAST && phone <= entryPhone5; i++) {
			const char *phone_str;

			phone_str = e_contact_get_const (contact, priority[i]);
			if (phone_str && *phone_str) {
				clear_entry_text (*local->addr, phone);
				local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str);
				local->addr->phoneLabel[phone - entryPhone1] = priority_label[i];
				phone++;
			}
		}
		for ( ; phone <= entryPhone5; phone++)
			local->addr->phoneLabel[phone - entryPhone1] = phone - entryPhone1;
		local->addr->showPhone = 0;
	} else {
		EContactField next_mail, next_home, next_work, next_fax;
		EContactField next_other, next_main, next_pager, next_mobile;

		INFO ("Not Syncable");
		get_next_init (&next_mail, &next_home, &next_work, &next_fax,
			       &next_other, &next_main, &next_pager, &next_mobile);

		/* Not completely syncable, so do the best we can */
		for (i = entryPhone1; i <= entryPhone5; i++) {
			int phonelabel = local->addr->phoneLabel[i - entryPhone1];
			const char *phone_str = NULL;

			if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
				phone_str = e_contact_get_const (contact, next_mail);
				next_mail = get_next_mail (&next_mail);
			} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
  				phone_str = e_contact_get_const (contact, next_home);
				next_home = get_next_home (&next_home);
			} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
				phone_str = e_contact_get_const (contact, next_work);
				next_work = get_next_work (&next_work);
			} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
				phone_str = e_contact_get_const (contact, next_fax);
				next_fax = get_next_fax (&next_fax);
			} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
				phone_str = e_contact_get_const (contact, next_other);
				next_other = get_next_other (&next_other);
			} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
				phone_str = e_contact_get_const (contact, next_main);
				next_main = get_next_main (&next_main);
			} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
				phone_str = e_contact_get_const (contact, next_pager);
				next_pager = get_next_pager (&next_pager);
			} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
				phone_str = e_contact_get_const (contact, next_mobile);
				next_mobile = get_next_mobile (&next_mobile);
			}

			if (phone_str && *phone_str) {
				clear_entry_text (*local->addr, i);
				local->addr->entry[i] = e_pilot_utf8_to_pchar (phone_str);
			}
		}
	}

	/* Note */
	local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE));
}
Пример #11
0
/* Pilot syncing callbacks */
static gint
pre_sync (GnomePilotConduit *conduit,
	  GnomePilotDBInfo *dbi,
	  EAddrConduitContext *ctxt)
{
	GnomePilotConduitSyncAbs *abs_conduit;
	EBookQuery *query;
    	GList *l;
	int len;
	char *filename;
	char *change_id;
	char *auth;
	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
#ifdef PILOT_LINK_0_12
	pi_buffer_t *buffer;
#else
	unsigned char *buf;
#endif

	abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit);

	LOG (g_message ( "---------------------------------------------------------\n" ));
	LOG (g_message ( "pre_sync: Addressbook Conduit v.%s", CONDUIT_VERSION ));
	/* g_message ("Addressbook Conduit v.%s", CONDUIT_VERSION); */

	ctxt->dbi = dbi;

	if (ctxt->cfg->source) {
		ctxt->ebook = e_book_new (ctxt->cfg->source, NULL);
	} else {
		ctxt->ebook = e_book_new_default_addressbook (NULL);
	}
	auth = (gchar *)e_source_get_property (ctxt->cfg->source, "auth");
	if (auth) {
		LOG (g_message ("contacts needs authentication\n"));
		g_signal_connect (ctxt->ebook, "auth_required",
				  G_CALLBACK (addressbook_authenticate), ctxt->cfg->source);
	}
	if (!ctxt->ebook || !e_book_open (ctxt->ebook, TRUE, NULL)) {
		WARN(_("Could not load addressbook"));
		gnome_pilot_conduit_error (conduit, _("Could not load addressbook"));

		return -1;
	}

	/* Load the uid <--> pilot id mappings */
	filename = map_name (ctxt);
	e_pilot_map_read (filename, &ctxt->map);
	g_free (filename);

	/* Get a list of all contacts */
	if (!(query = e_book_query_any_field_contains (""))) {
		LOG (g_warning ("Failed to get EBookQuery"));
		return -1;
	}

	if (!e_book_get_contacts (ctxt->ebook, query, &ctxt->cards, NULL)) {
		LOG (g_warning ("Failed to get Contacts"));
		e_book_query_unref (query);
		return -1;
	}

	e_book_query_unref (query);

	/* Count and hash the changes */
	change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id);
	if (!e_book_get_changes (ctxt->ebook, change_id, &ctxt->changed, NULL))
		return -1;
	ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal);
	g_free (change_id);

	for (l = ctxt->changed; l != NULL; l = l->next) {
		EBookChange *ebc = l->data;
		const char *uid;

		uid = e_contact_get_const (ebc->contact, E_CONTACT_UID);
		if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) {

			g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ebc);

			switch (ebc->change_type) {
			case E_BOOK_CHANGE_CARD_ADDED:
				add_records++;
				break;
			case E_BOOK_CHANGE_CARD_MODIFIED:
				mod_records++;
				break;
			case E_BOOK_CHANGE_CARD_DELETED:
				del_records++;
				break;
			}
		} else if (ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
			e_pilot_map_remove_by_uid (ctxt->map, uid);
		}
	}

	/* Set the count information */
  	num_records = g_list_length (ctxt->cards);
  	gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records);
  	gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records);
  	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
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		return pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
	}

	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
			      DLP_BUF_SIZE, buffer);
#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 Address application block"));
		WARN ("dlp_ReadAppBlock(...) = %d", len);
		gnome_pilot_conduit_error (conduit,
					   _("Could not read pilot's Address application block"));
		return -1;
	}
#ifdef PILOT_LINK_0_12
	unpack_AddressAppInfo (&(ctxt->ai), buffer->data, len);
	pi_buffer_free (buffer);
#else
	unpack_AddressAppInfo (&(ctxt->ai), buf, len);
	g_free (buf);
#endif
  	check_for_slow_setting (conduit, ctxt);
	if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot
	    || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot)
		ctxt->map->write_touched_only = TRUE;

	return 0;
}
Пример #12
0
static EContact *
ecard_from_remote_record(EAddrConduitContext *ctxt,
			 GnomePilotRecord *remote,
			 EContact *in_contact)
{
	struct Address address;
	EContact *contact;
	EContactName *name;
	EContactAddress *eaddress;
	EContactField mailing_address;
	char *txt, *find, *full_name;
	EContactField next_mail, next_home, next_work, next_fax;
	EContactField next_other, next_main, next_pager, next_mobile;
	int i;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#endif
	g_return_val_if_fail(remote!=NULL,NULL);
	memset (&address, 0, sizeof (struct Address));
#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return NULL;
	}

	if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){
		pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return NULL;
	}
	unpack_Address (&address, buffer, address_v1);
	pi_buffer_free(buffer);
#else
	unpack_Address (&address, remote->record, remote->length);
#endif
	if (in_contact == NULL)
		contact = e_contact_new ();
	else
		contact = e_contact_duplicate (in_contact);

	/* Name */
	name = e_contact_name_new ();
	name->given = get_entry_text (address, entryFirstname);
	name->family = get_entry_text (address, entryLastname);

	full_name = e_contact_name_to_string (name);
	e_contact_set (contact, E_CONTACT_FULL_NAME, full_name);
	e_contact_name_free (name);

	/* File As */
	if (!full_name || !*full_name)
		set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany);

	g_free (full_name);

	/* Title and Company */
	set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle);
	set_contact_text (contact, E_CONTACT_ORG, address, entryCompany);

	/* Address */
	mailing_address = -1;
	if ((eaddress = e_contact_get (contact, ctxt->cfg->default_address))) {
		mailing_address = ctxt->cfg->default_address;
		e_contact_address_free (eaddress);
	} else {
		for (i = E_CONTACT_FIRST_ADDRESS_ID; i <= E_CONTACT_LAST_ADDRESS_ID; i++) {
			if ((eaddress = e_contact_get (contact, i))) {
				e_contact_address_free (eaddress);
				mailing_address = i;
				break;
			}
		}
	}

	if (mailing_address == -1)
		mailing_address = ctxt->cfg->default_address;

	eaddress = g_new0 (EContactAddress, 1);

	txt = get_entry_text (address, entryAddress);
	if (txt && (find = strchr (txt, '\n')) != NULL) {
		*find = '\0';
		find++;
	} else {
		find = NULL;
	}

	eaddress->street = txt;
	eaddress->ext = find != NULL ? g_strdup (find) : g_strdup ("");
	eaddress->locality = get_entry_text (address, entryCity);
	eaddress->region = get_entry_text (address, entryState);
	eaddress->country = get_entry_text (address, entryCountry);
	eaddress->code = get_entry_text (address, entryZip);

	e_contact_set (contact, mailing_address, eaddress);
	e_contact_address_free (eaddress);

	/* Phone numbers */
	get_next_init (&next_mail, &next_home, &next_work, &next_fax,
		       &next_other, &next_main, &next_pager, &next_mobile);

	for (i = entryPhone1; i <= entryPhone5; i++) {
		int phonelabel = address.phoneLabel[i - entryPhone1];
		char *phonenum = get_entry_text (address, i);

		if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
			e_contact_set (contact, next_mail, phonenum);
			next_mail = get_next_mail (&next_mail);
		} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
			e_contact_set (contact, next_home, phonenum);
			next_home = get_next_home (&next_home);
		} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
			e_contact_set (contact, next_work, phonenum);
			next_work = get_next_work (&next_work);
		} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
			e_contact_set (contact, next_fax, phonenum);
			next_fax = get_next_fax (&next_fax);
		} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
			e_contact_set (contact, next_other, phonenum);
			next_other = get_next_other (&next_other);
		} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
			e_contact_set (contact, next_main, phonenum);
			next_main = get_next_main (&next_main);
		} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
			e_contact_set (contact, next_pager, phonenum);
			next_pager = get_next_pager (&next_pager);
		} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
			e_contact_set (contact, next_mobile, phonenum);
			next_mobile = get_next_mobile (&next_mobile);
		}

		g_free (phonenum);
	}

	/* Note */
	set_contact_text (contact, E_CONTACT_NOTE, address, entryNote);

	free_Address(&address);

	return contact;
}
Пример #13
0
/* Pilot syncing callbacks */
static gint
pre_sync (GnomePilotConduit *conduit,
	  GnomePilotDBInfo *dbi,
	  EMemoConduitContext *ctxt)
{
	GnomePilotConduitSyncAbs *abs_conduit;
	GList *l;
	int len;
	unsigned char *buf;
	char *filename, *change_id;
	icalcomponent *icalcomp;
	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#endif

	abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit);

	LOG (g_message ( "---------------------------------------------------------\n" ));
	LOG (g_message ( "pre_sync: Memo Conduit v.%s", CONDUIT_VERSION ));
	g_message ("Memo Conduit v.%s", CONDUIT_VERSION);

	ctxt->dbi = dbi;
	ctxt->client = NULL;

	if (start_calendar_server (ctxt) != 0) {
		WARN(_("Could not start evolution-data-server"));
		gnome_pilot_conduit_error (conduit, _("Could not start evolution-data-server"));
		return -1;
	}

	/* Get the timezone */
	ctxt->timezone = get_default_timezone ();
	if (ctxt->timezone == NULL)
		return -1;
	LOG (g_message ( "  Using timezone: %s", icaltimezone_get_tzid (ctxt->timezone) ));

	/* Set the default timezone on the backend. */
	if (ctxt->timezone && !e_cal_set_default_timezone (ctxt->client, ctxt->timezone, NULL))
		return -1;

	/* Get the default component */
	if (!e_cal_get_default_object (ctxt->client, &icalcomp, NULL))
		return -1;

	ctxt->default_comp = e_cal_component_new ();
	if (!e_cal_component_set_icalcomponent (ctxt->default_comp, icalcomp)) {
		g_object_unref (ctxt->default_comp);
		icalcomponent_free (icalcomp);
		return -1;
	}

	/* Load the uid <--> pilot id map */
	filename = map_name (ctxt);
	e_pilot_map_read (filename, &ctxt->map);
	g_free (filename);

	/* Get the local database */
	if (!e_cal_get_object_list_as_comp (ctxt->client, "#t", &ctxt->comps, NULL))
		return -1;

	/* Count and hash the changes */
	change_id = g_strdup_printf ("pilot-sync-evolution-memo-%d", ctxt->cfg->pilot_id);
	if (!e_cal_get_changes (ctxt->client, change_id, &ctxt->changed, NULL))
		return -1;

	ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal);
	g_free (change_id);

	for (l = ctxt->changed; l != NULL; l = l->next) {
		ECalChange *ccc = l->data;
		const char *uid;

		e_cal_component_get_uid (ccc->comp, &uid);
		if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) {

			g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ccc);

			switch (ccc->type) {
			case E_CAL_CHANGE_ADDED:
				add_records++;
				break;
			case E_CAL_CHANGE_MODIFIED:
				mod_records++;
				break;
			case E_CAL_CHANGE_DELETED:
				del_records++;
				break;
			}
		} else if (ccc->type == E_CAL_CHANGE_DELETED) {
			e_pilot_map_remove_by_uid (ctxt->map, uid);
		}
	}

	/* Set the count information */
	num_records = g_list_length (ctxt->comps);
	gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records);
	gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records);
	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);

	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
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return -1;
	}

 	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
				DLP_BUF_SIZE,
				buffer);
#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 Memo application block"));
		WARN ("dlp_ReadAppBlock(...) = %d", len);
		gnome_pilot_conduit_error (conduit,
					   _("Could not read pilot's Memo application block"));
		return -1;
	}
#ifdef PILOT_LINK_0_12
	buf = g_new0 (unsigned char,buffer->used);
	memcpy(buf, buffer->data, buffer->used);
 	unpack_MemoAppInfo (&(ctxt->ai), buf, len);
	pi_buffer_free(buffer);
#else
	unpack_MemoAppInfo (&(ctxt->ai), buf, len);
#endif

	g_free (buf);

	lastDesktopUniqueID = 128;

	check_for_slow_setting (conduit, ctxt);
	if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot
	    || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot)
		ctxt->map->write_touched_only = TRUE;

	return 0;
}
Пример #14
0
/***********************************************************************
 *
 * Function:    sync_MergeFromPilot_slow
 *
 * Summary:     uh, slow merge from Palm to desktop
 *
 * Parameters:  None
 *
 * Returns:     0 if success, nonzero otherwise
 *
 ***********************************************************************/
static int
sync_MergeFromPilot_slow(SyncHandler * sh, int dbhandle,
			 RecordModifier rec_mod)
{
	int 	i,
		parch, 
		psecret,
		result = 0;
	pi_buffer_t *recbuf;

	PilotRecord *precord 	= sync_NewPilotRecord(DLP_BUF_SIZE);
	DesktopRecord *drecord 	= NULL;
	RecordQueue rq 		= { 0, NULL };

	i = 0;
	recbuf = pi_buffer_new(DLP_BUF_SIZE);
	while (dlp_ReadRecordByIndex
	       (sh->sd, dbhandle, i, recbuf, &precord->recID,
			&precord->flags, &precord->catID) > 0) {
		int 	count = rq.count;

		precord->len = recbuf->used;
		if (precord->len > DLP_BUF_SIZE)
			precord->len = DLP_BUF_SIZE;
		memcpy(precord->buffer, recbuf->data, precord->len);
		
		ErrorCheck(sh->Match(sh, precord, &drecord));

		/* Since this is a slow sync, we must calculate the flags */
		parch = precord->flags & dlpRecAttrArchived;
		psecret = precord->flags & dlpRecAttrSecret;

		precord->flags = 0;
		if (drecord == NULL) {
			precord->flags = precord->flags | dlpRecAttrDirty;
		} else {
			int comp;

			comp = sh->Compare(sh, precord, drecord);
			if (comp != 0) {
				precord->flags =
				    precord->flags | dlpRecAttrDirty;
			}
		}
		if (parch)
			precord->flags =
			    precord->flags | dlpRecAttrArchived;
		if (psecret)
			precord->flags = precord->flags | dlpRecAttrSecret;

		ErrorCheck(sync_record
			   (sh, dbhandle, drecord, precord, &rq, rec_mod));

		if (drecord && rq.count == count)
			ErrorCheck(sh->FreeMatch(sh, drecord));

		i++;
	}
	pi_buffer_free(recbuf);

	sync_FreePilotRecord(precord);

	result = sync_MergeFromPilot_process(sh, dbhandle, &rq, rec_mod);

	return result;
}
Пример #15
0
int main(int argc, const char *argv[]) {
	int 	c,			/* switch */
		db,
		l,
		sd 			= -1;

	enum { mode_none, mode_read, mode_write, mode_delete_all, mode_delete }
		run_mode = mode_none;

	const char
        	*progname 		= argv[0];

	char 	*defaultcategoryname 	= 0,
		*deletecategory 	= 0,
		*wrFilename		= NULL,
		*rdFilename		= NULL,
		buf[0xffff];

	int writehuman = 0;

	pi_buffer_t *appblock;

	struct 	AddressAppInfo 	aai;
	struct 	PilotUser 	User;
        struct  SysInfo         info;

	poptContext po;

	struct poptOption options[] = {
		USERLAND_RESERVED_OPTIONS
	        {"delete-all",	 0 , POPT_ARG_NONE, NULL,  mode_delete_all, "Delete all Palm records in all categories", NULL},
	        {"delimiter",	't', POPT_ARG_INT,  &tabledelim,          0, "Include category, use delimiter (3=tab, 2=;, 1=,)", "<delimeter>"},
        	{"delete-category",	'd', POPT_ARG_STRING, &deletecategory,'d', "Delete old Palm records in <category>", "category"},
	        {"category",	'c', POPT_ARG_STRING, &defaultcategoryname, 0, "Category to install to", "category"},
        	{"augment",	'a', POPT_ARG_NONE, &augment,             0, "Augment records with additional information", NULL},
	        {"read",	'r', POPT_ARG_STRING, &rdFilename, 'r', "Read records from <file> and install them to Palm", "file"},
        	{"write",	'w', POPT_ARG_STRING, &wrFilename, 'w', "Get records from Palm and write them to <file>", "file"},
		{"human-readable",'C', POPT_ARG_NONE, &writehuman, 0, "Write generic human-readable output instead of CSV", NULL},
	        POPT_TABLEEND
	};

	const char *mode_error = "   ERROR: Specify exactly one of read, write, delete or delete all.\n";

	po = poptGetContext("pilot-addresses", argc, argv, options, 0);
	poptSetOtherOptionHelp(po,"\n\n"
		"   Reads addresses from a file and installs on the Palm, or\n"
		"   writes addresses from the Palm to a file.\n\n"
		"   Provide exactly one of --read or --write.\n\n");
	plu_popt_alias(po,"delall",0,"--bad-option --delete-all");
	plu_popt_alias(po,"delcat",0,"--bad-option --delete-category");
	plu_popt_alias(po,"install",0,"--bad-option --category");
	/* Useful alias */
	plu_popt_alias(po,"no-csv",0,"--human-readable");

	if (argc < 2) {
		poptPrintUsage(po,stderr,0);
		return 1;
	}

	while ((c = poptGetNextOpt(po)) >= 0) {
		switch (c) {
		/* These are the mode-setters. delete-all does it through
		 * popt hooks, since it doesn't take an argument.
		 *
		 * Special case is that you can mix -w and -d to write the
		 * file and then delete a category.
		 */
		case mode_delete_all :
			if (run_mode != mode_none) {
				fprintf(stderr,"%s",mode_error);
				return 1;
			}
			run_mode = mode_delete_all;
			break;
		case 'r':
			if (run_mode != mode_none) {
				fprintf(stderr,"%s",mode_error);
				return 1;
			}
			run_mode = mode_read;
			break;
		case 'w':
			if ((run_mode != mode_none) && (run_mode != mode_delete)) {
				fprintf(stderr,"%s",mode_error);
				return 1;
			}
			run_mode = mode_write;
			break;
		case 'd':
			if ((run_mode != mode_none) && (run_mode != mode_write)) {
				fprintf(stderr,"%s",mode_error);
				return 1;
			}
			run_mode = mode_delete;
			break;
		default:
			fprintf(stderr,"   ERROR: Unhandled option %d.\n",c);
			return 1;
		}
	}

	if (c < -1)
		plu_badoption(po,c);

	if (mode_none == run_mode) {
		fprintf(stderr,"%s",mode_error);
		return 1;
	}

	/* The first implies that -t was given; the second that it wasn't,
	   so use default, and the third if handles weird values. */
	if ((tabledelim < 0) || (tabledelim > sizeof(tabledelim))) {
		fprintf(stderr,"   ERROR: Invalid delimiter number %d (use 0-%d).\n",
			tabledelim,(int)(sizeof(tabledelim)));
		return 1;
	}

	sd = plu_connect();

	if (sd < 0)
		goto error;

        if (dlp_ReadUserInfo(sd, &User) < 0)
                goto error_close;

        if (dlp_ReadSysInfo(sd,&info) < 0) {
                fprintf(stderr,"   ERROR: Could not read Palm System Information.\n");
                return -1;
        }

        if (info.romVersion > 0x05003000) {
                printf("   PalmOS 5.x (Garnet) and later devices are not currently supported by this\n"
                       "   tool. The data format of the AddressBook has changed. The legacy format\n"
                       "   is called \"Classic\" and PalmOS 5.x and later uses \"Extended\" databases\n"
                       "   with a different structure. Your Palm has \"Contacts\", and this tool reads\n"
                       "   the \"AddressBook\" database. (Found OS version: %x)\n\n"

                       "   Due to this change, pilot-addresses and other tools must be rewritten to\n"
                       "   compensate. Sorry about the inconvenience.\n\n", info.romVersion);

		/* return -1; FIXME: Need to adjust this to clealy detect OS version and rewrite */
        }

	/* Open the AddressDB.pdb database, store access handle in db */
	if (dlp_OpenDB(sd, 0, 0x80 | 0x40, "AddressDB", &db) < 0) {
		puts("Unable to open AddressDB");
		dlp_AddSyncLogEntry(sd, "Unable to open AddressDB.\n");
		goto error_close;
	}

	appblock = pi_buffer_new(0xffff);
	l = dlp_ReadAppBlock(sd, db, 0, 0xffff, appblock);
	unpack_AddressAppInfo(&aai, appblock->data, l);
	pi_buffer_free(appblock);

	if (defaultcategoryname) {
		defaultcategory =
		    plu_findcategory(&aai.category,defaultcategoryname,
		    	PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);
	} else {
		defaultcategory = 0;	/* Unfiled */
	}

	switch(run_mode) {
		FILE *f;
		int i;
		int old_quiet;
	case mode_none:
		/* impossible */
		fprintf(stderr,"%s",mode_error);
		break;
	case mode_write:
		/* FIXME - Must test for existing file first! DD 2002/03/18 */
		if (strcmp(wrFilename,"-") == 0) {
			f = stdout;
			old_quiet = plu_quiet;
			plu_quiet = 1;
		} else {
			f = fopen(wrFilename, "w");
		}
		if (f == NULL) {
			sprintf(buf, "%s: %s", progname, wrFilename);
			perror(buf);
			goto error_close;
		}
		write_file(f, sd, db, &aai, writehuman);
		if (f == stdout) {
			plu_quiet = old_quiet;
		}
		if (deletecategory) {
			dlp_DeleteCategory(sd, db,
				plu_findcategory(&aai.category,deletecategory,PLU_CAT_CASE_INSENSITIVE | PLU_CAT_WARN_UNKNOWN));
		}
		if (f != stdout) {
			fclose(f);
		}
		break;
	case mode_read:
		f = fopen(rdFilename, "r");

		if (f == NULL) {
			fprintf(stderr, "Unable to open input file");
			fprintf(stderr, " '%s' (%s)\n\n",
				rdFilename, strerror(errno));
			fprintf(stderr, "Please make sure the file");
			fprintf(stderr, "'%s' exists, and that\n",
				rdFilename);
			fprintf(stderr, "it is readable by this user");
			fprintf(stderr, " before launching.\n\n");

			goto error_close;
		}
		read_file(f, sd, db, &aai);
		fclose(f);
		break;
	case mode_delete:
		i = plu_findcategory (&aai.category,deletecategory,PLU_CAT_CASE_INSENSITIVE | PLU_CAT_WARN_UNKNOWN);
		if (i>=0) {
			dlp_DeleteCategory(sd, db, i);
		}
		break;
	case mode_delete_all:
		for (i = 0; i < 16; i++)
			if (aai.category.name[i][0])
				dlp_DeleteCategory(sd, db, i);
		break;
	}

	/* Close the database */
	dlp_CloseDB(sd, db);

	/* Tell the user who it is, with a different PC id. */
	User.lastSyncPC = 0x00010000;
	User.successfulSyncDate = time(NULL);
	User.lastSyncDate = User.successfulSyncDate;
	dlp_WriteUserInfo(sd, &User);

	if (run_mode == mode_read) {
		dlp_AddSyncLogEntry(sd, "Wrote entries to Palm Address Book.\n");
	} else if (run_mode == mode_write) {
		dlp_AddSyncLogEntry(sd, "Successfully read Address Book from Palm.\n");
	}

	dlp_EndOfSync(sd, 0);
	pi_close(sd);

	return 0;

error_close:
        pi_close(sd);

error:
        return -1;
}
Пример #16
0
/***********************************************************************
 *
 * Function:    read_file
 *
 * Summary:    	Open specified file and read into address records
 *
 * Parameters:  filehandle
 *
 * Returns:
 *
 ***********************************************************************/
int read_file(FILE *f, int sd, int db, struct AddressAppInfo *aai) {
	int 	i	= -1,
		l,
		attribute,
		category;
	char 	buf[0xffff];
	int showPhone = -1;

	pi_buffer_t *record;

	struct 	Address addr;

	int fields = 0; /* Number of fields in this entry */
	int count = 0; /* Number of entries read */
	const char *progress = "   Reading CSV entries, writing to Palm Address Book... ";

	if (!plu_quiet) {
		printf("%s",progress);
		fflush(stdout);
	}

	while (!feof(f)) {
		fields = 0;
		l = getc(f);
		if (feof(f) || (l<0)) {
			break;
		}
		if ('#' == l) {
			/* skip remainder of line */
			while (!feof(f) && (l!='\n') && (l>=0)) {
				l = getc(f);
			}
			continue;
		} else {
			ungetc(l,f);
		}
		i = read_field(buf, f, sizeof(buf));
		/* fprintf(stderr,"* Field=%s\n",buf); */

		memset(&addr, 0, sizeof(addr));
		addr.showPhone = 0;
		showPhone = -1; /* None specified this record */

		if ((i == term_semi) && (tabledelim != term_semi)) {
			/* This is an augmented entry */
			category = plu_findcategory(&aai->category,buf,
				PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);
			i = read_field(buf, f, sizeof(buf));
			if (i == term_semi) {
				showPhone = match_phone(buf, aai);
				i = read_field(buf, f, sizeof(buf));
			}
		} else {
			category = defaultcategory;
		}

		if (i < 0)
			break;

		attribute = 0;

		for (l = 0; (i >= 0) && (l < 21); l++) {
			int l2 = realentry[l];

			if ((l2 >= 3) && (l2 <= 7)) {
				if ((i != term_semi) || (tabledelim == term_semi)) {
					addr.phoneLabel[l2 - 3] = l2 - 3;
				}
				else {
					addr.phoneLabel[l2 - 3] = match_phone(buf, aai);
					i = read_field(buf, f, sizeof(buf));
				}
				if (buf[0]) {
					addr.entry[l2] = strdup(buf);
					++fields;
				} else {
					addr.entry[l2] = NULL;
				}
			} else if (19 <= l2) {
				if (19 == l2) {
					attribute = (atoi(buf) ? dlpRecAttrSecret : 0);
				}
				if (20 == l2) {
					category = plu_findcategory(&aai->category,buf,
						PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);
				}
			} else {
				if (buf[0]) {
					addr.entry[l2] = strdup(buf);
					++fields;
				} else {
					addr.entry[l2] = NULL;
				}

			}

			if (i == 0)
				break;

			i = read_field(buf, f, sizeof(buf));
		}


		while (i > 0) {	/* Too many fields in record */
			i = read_field(buf, f, sizeof(buf));
		}

		if (showPhone >= 0) {
			/* Find which label matches the category to display */
			addr.showPhone = 0;
			for (i=0; i<5; ++i) {
				if (showPhone == addr.phoneLabel[i]) {
					addr.showPhone = i;
					break;
				}
			}
		}

		if (fields>0) {
		        record = pi_buffer_new(0);
			pack_Address(&addr, record, address_v1);
			dlp_WriteRecord(sd, db, attribute, 0, category,
					(unsigned char *) record->data, record->used, 0);
			pi_buffer_free(record);
			++count;
		}
		free_Address(&addr);

		if (!plu_quiet) {
			printf("\r%s%d",progress,count);
			fflush(stdout);
		}

	}

	if (!plu_quiet) {
		printf("\r%s%d\n   Done.\n",progress,count);
		fflush(stdout);
	}
	return 0;
}
Пример #17
0
int
main (int argc, char **argv)
{
	int sd;
	int result;
	struct SysInfo s;
	struct PilotUser u1, u2;
	struct NetSyncInfo n1, n2;
	struct CardInfo c;
	struct DBInfo dbi;
	struct DBSizeInfo dbsi;
	unsigned long romVersion;
	time_t t1, t2;	
	int handle;
	unsigned char pref1[256], pref2[256];
	unsigned char ablock1[256];
	unsigned char sblock1[256];
	unsigned char ires1[256];
	unsigned char dres1[256];
	unsigned char record1[256], record2[256], record3[256];
	recordid_t rid1, rid2, rid3, rlist[4];
	int index, id_, count;
	unsigned long type;
	int cardno;
	int i;
	pi_buffer_t *record4,
		*dres2,
		*ires2,
		*appblock;

	record4 = pi_buffer_new (sizeof(record1));
	ires2 = pi_buffer_new (sizeof (ires1));
	dres2 = pi_buffer_new (sizeof (dres1));
	appblock = pi_buffer_new(256);
	
	sd = pilot_connect (argv[1]);

	t1 = time (NULL);
	LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "DLPTEST Starting at %s", ctime (&t1)));

	/*********************************************************************
	 *
	 * Test: Open Conduit
	 *
	 * Direct Testing Functions:
	 *   dlp_OpenConduit
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_OpenConduit (sd);
	CHECK_RESULT(dlp_OpenConduit);

	/*********************************************************************
	 *
	 * Test: System Information
	 *
	 * Direct Testing Functions:
	 *   dlp_ReadSysInfo
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_ReadSysInfo (sd, &s);
	CHECK_RESULT(dlp_ReadSysInfo);
	
	/*********************************************************************
	 *
	 * Test: User Info
	 *
	 * Direct Testing Functions:
	 *   dlp_WriteUserInfo
	 *   dlp_ReadUserInfo
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	memset (&u1, '\0', sizeof (struct PilotUser));
	memset (&u2, '\0', sizeof (struct PilotUser));
	u1.passwordLength = 0;
	strcpy (u1.username, "Test User");
	strcpy (u1.password, "");
	u1.userID = 500;
	u1.viewerID = 5000;
	u1.lastSyncPC = 111111;
	u1.successfulSyncDate = time(NULL);
	u1.lastSyncDate = time(NULL) + 100;

	result = dlp_WriteUserInfo (sd, &u1);
	CHECK_RESULT(dlp_WriteUserInfo);
	result = dlp_ReadUserInfo (sd, &u2);
	CHECK_RESULT(dlp_ReadUserInfo);
	if (memcmp(&u1, &u2, sizeof(struct PilotUser) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST User info mismatch\n"));
		goto error;
	}

	/*********************************************************************
	 *
	 * Test: Feature
	 *
	 * Direct Testing Functions:
	 *   dlp_ReadFeature
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	romVersion = 0;

	result = dlp_ReadFeature(sd, makelong("psys"), 1, &romVersion);
	CHECK_RESULT(dlp_ReadFeature);
	if (romVersion != s.romVersion) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Rom Version mismatch\n"));
		goto error;
	}
	
	/*********************************************************************
	 *
	 * Test: Net Sync Info
	 *
	 * Direct Testing Functions:
	 *   dlp_WriteNetSyncInfo
	 *   dlp_ReadNetSyncInfo
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
#if DLP_1_1
	memset (&n1, '\0', sizeof (struct NetSyncInfo));
	memset (&n2, '\0', sizeof (struct NetSyncInfo));
	n1.lanSync = 0;
	strcpy (n1.hostName, "localhost");
	strcpy (n1.hostAddress, "192.168.1.1");
	strcpy (n1.hostSubnetMask, "255.255.255.0");

	result = dlp_WriteNetSyncInfo (sd, &n1);
	CHECK_RESULT(dlp_WriteNetSyncInfo);
	result = dlp_ReadNetSyncInfo (sd, &n2);
	CHECK_RESULT(dlp_ReadNetSyncInfo);
	if (memcmp(&n1, &n2, sizeof(struct NetSyncInfo) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Net sync info mismatch\n"));
		goto error;
	}
#endif

	/*********************************************************************
	 *
	 * Test: Time
	 *
	 * Direct Testing Functions:
	 *   dlp_SetSysDateTime
	 *   dlp_GetSysDateTime
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	t1 = time(NULL);

	dlp_SetSysDateTime (sd, t1);
	CHECK_RESULT(dlp_SetSysDateTime);
	dlp_GetSysDateTime (sd, &t2);
	CHECK_RESULT(dlp_GetSysDateTime);
	if (t2 > t1 + 1) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST System Time Mismatch\n"));
		goto error;
	}

	/*********************************************************************
	 *
	 * Test: Storage Information
	 *
	 * Direct Testing Functions:
	 *   dlp_ReadStorageInfo
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	c.more = 1;
	for (i = 0; c.more != 0; i++) {
		result = dlp_ReadStorageInfo (sd, i, &c);
		CHECK_RESULT(dlp_ReadStorageInfo);
	}

	/*********************************************************************
	 *
	 * Test: Database List
	 *
	 * Direct Testing Functions:
	 *   dlp_ReadDBList
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	dbi.more = 1;
	for (i = 0; dbi.more != 0; i++) {
		result = dlp_ReadDBList (sd, 0, dlpDBListRAM | dlpDBListROM, i, record4);
		CHECK_RESULT(dlp_ReadDBList);
		memcpy(&dbi, record4->data, sizeof(struct DBInfo));
	}

	/*********************************************************************
	 *
	 * Test: Existing Database
	 *
	 * Direct Testing Functions:
	 *   dlp_OpenDB
	 *   dlp_CloseDB
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "ToDoDB", &handle);
	CHECK_RESULT(dlp_OpenDB);
	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);

	/*********************************************************************
	 *
	 * Test: New Database
	 *
	 * Direct Testing Functions:
	 *   dlp_CreateDB
	 *   dlp_CloseDB
	 *   dlp_DeleteDB
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_CreateDB (sd, CREATOR, DATA, 0, dlpDBFlagResource, 1, "TestResource", &handle);
	CHECK_RESULT(dlp_CreateDB);
	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);
	result = dlp_DeleteDB (sd, 0, "TestResource");
	CHECK_RESULT(dlp_DeleteDB);

	/*********************************************************************
	 *
	 * Test: Database Info and Searching
	 *
	 * Direct Testing Functions:
	 *   dlp_SetDBInfo
	 *   dlp_FindDBByName
	 *   dlp_FindDBByOpenHandle
	 *   dlp_FindDBByTypeCreator
	 *
	 * Indirect Testing Functions:
	 *   dlp_CreateDB
	 *   dlp_OpenDB
	 *   dlp_ReadDBList
	 *   dlp_CloseDB
	 *   dlp_DeleteDB
	 *
	 *********************************************************************/
#if DLP_1_2
	result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle);
	CHECK_RESULT(dlp_CreateDB);
	result = dlp_SetDBInfo (sd, handle, dlpDBFlagBackup, dlpDBFlagCopyPrevention, 0, 0, 0, 0, 0, 0);
	CHECK_RESULT(dlp_SetDBInfo);	
	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);

	result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "TestRecord", &handle);
	CHECK_RESULT(dlp_OpenDB);
	
	result = dlp_FindDBByOpenHandle (sd, handle, &cardno, NULL, &dbi, &dbsi);
	CHECK_RESULT(dlp_FindDBByOpenHandle);
	if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with openhandle\n"));
		goto error;
	}

	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);
	
	result = dlp_FindDBByName (sd, 0, "TestRecord", NULL, NULL, &dbi, &dbsi);
	CHECK_RESULT(dlp_FindDBByName);
	if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with name\n"));
		goto error;
	}

	result = dlp_FindDBByTypeCreator (sd, DATA, CREATOR, 1, 0, &cardno, NULL, NULL, &dbi, &dbsi);
	CHECK_RESULT(dlp_FindDBByName);
	if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with type/creator\n"));
		goto error;
	}

	result = dlp_DeleteDB (sd, 0, "TestRecord");
	CHECK_RESULT(dlp_DeleteDB);
#endif

	/*********************************************************************
	 *
	 * Test: App Preference
	 *
	 * Direct Testing Functions:
	 *   dlp_WriteAppPreference
	 *   dlp_ReadAppPreference
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	memset (pref1, '\0', sizeof (pref1));
	memset (pref2, '\0', sizeof (pref2));
	pref1[9] = 'T';
	pref2[10] = 'T';
	
	result = dlp_WriteAppPreference (sd, CREATOR, 0, 1, 1, pref1, sizeof(pref1));
	CHECK_RESULT(dlp_WriteAppPrefence);
	result = dlp_ReadAppPreference (sd, CREATOR, 0, 1, sizeof(pref2), pref2, NULL, NULL);
	CHECK_RESULT(dlp_ReadAppPreference);
	if (memcmp(&pref1, &pref2, sizeof(pref1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Preference mismatch\n"));
		goto error;
	}

	/*********************************************************************
	 *
	 * Test: Record
	 *
	 * Direct Testing Functions:
	 *   dlp_WriteAppBlock
	 *   dlp_ReadAppBlock
	 *   dlp_WriteSortBlock
	 *   dlp_ReadSortBlock
	 *   dlp_WriteRecord
	 *   dlp_ReadOpenDBInfo
	 *   dlp_ReadRecordById
	 *   dlp_ReadRecordByIndex
	 *   dlp_ReadNextModifiedRec
	 *   dlp_ReadNextRecInCategory
	 *   dlp_ReadNextModifiedRecInCategory
	 *   dlp_MoveCategory
	 *   dlp_DeleteRecord
	 *   dlp_DeleteCategory
	 *   dlp_ResetDBIndex
	 *
	 * Indirect Testing Functions:
	 *   dlp_CreateDB
	 *   dlp_CloseDB
	 *   dlp_DeleteDB
	 *
	 *********************************************************************/
	memset (ablock1, '\0', sizeof (ablock1));
	memset (sblock1, '\0', sizeof (sblock1));
	memset (record1, '\0', sizeof (record1));
	memset (record2, '\0', sizeof (record2));
	memset (record3, '\0', sizeof (record3));
	ablock1[3] = 'T';
	sblock1[17] = 'T';
	record1[32] = 'T';
	record2[33] = 'T';
	record3[34] = 'T';
	
	result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle);
	CHECK_RESULT(dlp_CreateDB);

	/* Write and read back an app block */
	result = dlp_WriteAppBlock (sd, handle, ablock1, sizeof(ablock1));
	CHECK_RESULT(dlp_WriteAppBlock);
	result = dlp_ReadAppBlock (sd, handle, 0, sizeof(ablock1), appblock);
	CHECK_RESULT(dlp_ReadAppBlock);
	if (result != sizeof(ablock1) || memcmp(ablock1, appblock->data, sizeof(ablock1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST App block mismatch\n"));
		goto error;
	}

	/* Write and read back a sort block */
	result = dlp_WriteSortBlock (sd, handle, sblock1, sizeof(sblock1));
	CHECK_RESULT(dlp_WriteSortBlock);
	result = dlp_ReadSortBlock (sd, handle, 0, sizeof(sblock1), appblock);
	CHECK_RESULT(dlp_ReadSortBlock);
	if (result != sizeof(sblock1) || memcmp(sblock1, appblock->data, sizeof(sblock1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST App block mismatch\n"));
		goto error;
	}
	
	/* Write some records out */
	result = dlp_WriteRecord (sd, handle, 0, 0, 1, record1, sizeof(record1), &rid1);
	CHECK_RESULT(dlp_WriteRecord);
	result = dlp_WriteRecord (sd, handle, dlpRecAttrDirty, 0, 2, record2, sizeof(record2), &rid2);
	CHECK_RESULT(dlp_WriteRecord);
	result = dlp_WriteRecord (sd, handle, 0, 0, 3, record3, sizeof(record3), &rid3);
	CHECK_RESULT(dlp_WriteRecord);

	/* Get the db info */
	result = dlp_ReadOpenDBInfo (sd, handle, &count);
	CHECK_RESULT(dlp_ReadOpenDBInfo);
	if (count != 3) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong open database info\n"));
		goto error;
	}

	/* Get the id list */
	result = dlp_ReadRecordIDList (sd, handle, 0, 0, 4, rlist, &count);
	CHECK_RESULT(dlp_ReadRecordIDList);
	if (count != 3) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong record id list length\n"));
		goto error;
	}
	for (i = 0; i < 3; i++) {
		if (rlist[i] != rid1 && rlist[i] != rid2 && rlist[i] != rid3) {
			LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong record id\n"));
			goto error;			
		}
	}
	
	/* Try reading the records in various ways */
	result = dlp_ReadRecordById (sd, handle, rid1, record4, &index, NULL, NULL);
	CHECK_RESULT(dlp_ReadRecordById);
	if (memcmp(record1, record4->data, sizeof(record1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Record by Id mismatch\n"));
		goto error;
	}
	result = dlp_ReadRecordByIndex (sd, handle, index, record4, NULL, NULL, NULL);
	CHECK_RESULT(dlp_ReadRecordByIndex);
	if (memcmp(record1, record4->data, sizeof(record1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Record by index mismatch\n"));
		goto error;
	}
	result = dlp_ReadNextModifiedRec (sd, handle, record4, NULL, NULL, NULL, NULL);
	CHECK_RESULT(dlp_ReadNextModifiedRec);
	if (memcmp(record2, record4->data, sizeof(record2) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Next modified record mismatch\n"));
		goto error;
	}
	
	/* Reset because of the above next modified record call */
	result = dlp_ResetDBIndex (sd, handle);
	CHECK_RESULT(dlp_ResetDBIndex)

	/* This is a DLP 1.1 call, but pilot-link has a 1.0 implementation */
	result = dlp_ReadNextRecInCategory (sd, handle, 3, record4, NULL, NULL, NULL);
	CHECK_RESULT(dlp_ReadNextRecInCategory)
	if (memcmp(record3, record4->data, sizeof(record3) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextRecInCategory mismatch\n"));
		goto error;
	}

	/* Reset because of the above next record in category call */
	result = dlp_ResetDBIndex (sd, handle);
	CHECK_RESULT(dlp_ResetDBIndex)

	/* This is a DLP 1.1 call, but pilot-link has a 1.0 implementation */
	result = dlp_ReadNextModifiedRecInCategory (sd, handle, 2, record4, NULL, NULL, NULL);
	CHECK_RESULT(dlp_ReadNextModifiedRecInCategory)
	if (memcmp(record2, record4->data, sizeof(record2) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextModifiedRecInCategory mismatch\n"));
		goto error;
	}

	/* Reset because of the above next modified record in category call */
	result = dlp_ResetDBIndex (sd, handle);
	CHECK_RESULT(dlp_ResetDBIndex)

	/* Move a category and try to read the record back in */
	result = dlp_MoveCategory (sd, handle, 1, 4);
	CHECK_RESULT(dlp_MoveCategory)
	result = dlp_ReadNextRecInCategory (sd, handle, 4, record4, NULL, NULL, NULL);
	CHECK_RESULT(dlp_ReadNextRecInCategory)
	if (memcmp(record1, record4->data, sizeof(record1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextRecInCategory mismatch\n"));
		goto error;
	}
	
	/* Delete records in various ways */
	result = dlp_DeleteRecord (sd, handle, 0, rid1);
	CHECK_RESULT(dlp_DeleteRecord <Single>);
	result = dlp_ReadRecordById (sd, handle, rid1, record4, NULL, NULL, NULL);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted record could still be read\n"));
		goto error;
	}
	result = dlp_DeleteCategory (sd, handle, 3);
	CHECK_RESULT(dlp_DeleteCategory);
	result = dlp_ReadRecordById (sd, handle, rid3, record4, NULL, NULL, NULL);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted category could still be read\n"));
		goto error;
	}
	result = dlp_DeleteRecord (sd, handle, 1, 0);
	CHECK_RESULT(dlp_DeleteRecord <All>);
	result = dlp_ReadRecordById (sd, handle, rid2, record4, NULL, NULL, NULL);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted all record could still be read\n"));
		goto error;
	}

	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);
	result = dlp_DeleteDB (sd, 0, "TestRecord");
	CHECK_RESULT(dlp_DeleteDB);

	/*********************************************************************
	 *
	 * Test: Resource
	 *
	 * Direct Testing Functions:
	 *   dlp_WriteResource
	 *   dlp_ReadResourceByType
	 *   dlp_ReadResourceByIndex
	 *   dlp_DeleteResource
	 *
	 * Indirect Testing Functions:
	 *   dlp_CreateDB
	 *   dlp_CloseDB
	 *   dlp_DeleteDB
	 *
	 *********************************************************************/
	memset (ires1, '\0', sizeof (ires1));
	memset (dres1, '\0', sizeof (dres1));
	ires1[3] = 'T';
	dres1[4] = 'T';

	result = dlp_CreateDB (sd, CREATOR, DATA, 0, dlpDBFlagResource, 1, "TestResource", &handle);
	CHECK_RESULT(dlp_CreateDB);

	/* Write out some resources */
	result = dlp_WriteResource (sd, handle, INFO, 1, ires1, sizeof(ires1));
	CHECK_RESULT(dlp_WriteResource);
	result = dlp_WriteResource (sd, handle, DATA, 0, dres1, sizeof(dres1));
	CHECK_RESULT(dlp_WriteResource);

	/* Read in the resources by various methods */
	result = dlp_ReadResourceByType (sd, handle, INFO, 1, ires2, &index);
	CHECK_RESULT(dlp_ReadResourceByType)
	if (memcmp(ires1, ires2->data, sizeof(ires1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by type mismatch\n"));
		goto error;
	}
	result = dlp_ReadResourceByIndex (sd, handle, index, ires2, &type, &id_);
	CHECK_RESULT(dlp_ReadResourceByIndex)
	if (memcmp(ires1, ires2->data, sizeof(ires1) != 0)) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index mismatch\n"));
		goto error;
	}
	if (type != INFO) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index return type mismatch\n"));
		goto error;
	}
	if (id_ != 1) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index return id mismatch\n"));
		goto error;
	}

	/* Delete resources by the various methods */
	result = dlp_DeleteResource (sd, handle, 0, INFO, 1);
	CHECK_RESULT(dlp_DeleteResource <Single>)
	result = dlp_ReadResourceByType (sd, handle, INFO, 1, ires2, &index);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted resource could still be read\n"));
		goto error;
	}
	result = dlp_DeleteResource (sd, handle, 1, INFO, 1);
	CHECK_RESULT(dlp_DeleteResource <All>)
	result = dlp_ReadResourceByType (sd, handle, DATA, 0, dres2, &index);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted all resource could still be read\n"));
		goto error;
	}

	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB)
	result = dlp_DeleteDB (sd, 0, "TestResource");
	CHECK_RESULT(dlp_DeleteDB)

	/*********************************************************************
	 *
	 * Test: Database Cleanup
	 *
	 * Direct Testing Functions:
	 *   dlp_CleanUpDatabase
	 *   dlp_ResetSyncFlags
	 *
	 * Indirect Testing Functions:
	 *   dlp_CreateDB
	 *   dlp_WriteRecord
	 *   dlp_CloseDB
	 *   dlp_DeleteDB
	 *
	 *********************************************************************/
	result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle);
	CHECK_RESULT(dlp_CreateDB);

	/* Create dummy records */
	result = dlp_WriteRecord (sd, handle, dlpRecAttrDeleted, 0, 0, record1, sizeof(record1), &rid1);
	CHECK_RESULT(dlp_WriteRecord);
	result = dlp_WriteRecord (sd, handle, dlpRecAttrDirty, 0, 0, record2, sizeof(record2), &rid2);
	CHECK_RESULT(dlp_WriteRecord);

	/* Call the test functions */
	result = dlp_CleanUpDatabase (sd, handle);
	CHECK_RESULT(dlp_CleanUpDatabase);
	result = dlp_ResetSyncFlags (sd, handle);
	CHECK_RESULT(dlp_ResetSyncFlags);

	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);

	/* Confirm the test functions worked */
	result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "TestRecord", &handle);
	CHECK_RESULT(dlp_OpenDB);

	result = dlp_ReadRecordById (sd, handle, rid1, record4, NULL, NULL, NULL);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Cleaned up record could still be read\n"));
		goto error;
	}
	result = dlp_ReadNextModifiedRec (sd, handle, record4, NULL, NULL, NULL, NULL);
	if (result >= 0) {
		LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Modified recorded could still be read\n"));
		goto error;
	}

	result = dlp_CloseDB (sd, handle);
	CHECK_RESULT(dlp_CloseDB);
	result = dlp_DeleteDB (sd, 0, "TestRecord");
	CHECK_RESULT(dlp_DeleteDB);

	/*********************************************************************
	 *
	 * Test: Sync Log
	 *
	 * Direct Testing Functions:
	 *   dlp_AddSyncLogEntry
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_AddSyncLogEntry (sd, "dlp-test added sync log entry");
	CHECK_RESULT(dlp_AddSyncLogEntry);

	/*********************************************************************
	 *
	 * Test: End Sync
	 *
	 * Direct Testing Functions:
	 *   dlp_EndOfSync
	 *
	 * Indirect Testing Functions:
	 *   None
	 *
	 *********************************************************************/
	result = dlp_EndOfSync (sd, dlpEndCodeNormal);
	CHECK_RESULT(dlp_EndOfSync);

	t1 = time (NULL);
	LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "DLPTEST Ending at %s", ctime (&t1)));

 error:
	pi_close (sd);
	pi_buffer_free (record4);
	pi_buffer_free (ires2);
	pi_buffer_free (dres2);
	pi_buffer_free(appblock);
	return 0;
}
Пример #18
0
/***********************************************************************
 *
 * Function:    fetch_wavs
 *
 * Summary:     Grab the voice memos matching 'Vpad' on the device
 *
 * Parameters:  None
 *
 * Returns:     0
 *
 ***********************************************************************/
int fetch_wavs(int sd, char *dbname)
{
	FILE *out;
	recordid_t id_;
	int 	index,
		db,
		attr,
		category,
		ret,
		start;

	struct DBInfo info;
	char creator[5];
	char type[5];
	pi_buffer_t *buffer;

        int booldb = TRUE;

        long wWaveLength;
        long formatChunkSize;
        long dataChunkSize;

        start = 0;

	buffer = pi_buffer_new (65536);

	while (dlp_ReadDBList(sd, 0, dlpOpenRead, start, buffer) > 0) {
		memcpy(&info, buffer->data, sizeof(struct DBInfo));
		start = info.index + 1;
		creator[0] = (info.creator & 0xFF000000) >> 24;
		creator[1] = (info.creator & 0x00FF0000) >> 16;
		creator[2] = (info.creator & 0x0000FF00) >> 8;
		creator[3] = (info.creator & 0x000000FF);
		creator[4] = '\0';
		type[0] = (info.type & 0xFF000000) >> 24;
		type[1] = (info.type & 0x00FF0000) >> 16;
		type[2] = (info.type & 0x0000FF00) >> 8;
		type[3] = (info.type & 0x000000FF);
		type[4] = '\0';

		if (!strcmp(dbname, "all")) {
			booldb = FALSE;
		} else {
			booldb = strcmp(info.name, dbname);
		}

                if (!(strcmp(creator, "Vpad") || strcmp(type, "strm") || booldb)) {
			memset (buffer->data, 0, buffer->allocated);
			if (!plu_quiet) {
				printf("Fetching '%s' (Creator ID '%s')... ",
					info.name, creator);
			}
                        ret =
                            dlp_OpenDB(sd, 0, dlpOpenRead, info.name, &db);
                        if (ret < 0) {
                                fprintf(stderr, "   WARNING: Unable to open %s\n",
                                        info.name);
                                continue;
                        }

                        out = fopen(info.name, "w");
                        if (!out) {
                                fprintf(stderr,
                                        "   WARNING: Failed, unable to create file %s\n",
                                        info.name);
				dlp_CloseDB(sd,db);
                                continue;
                        }

                        formatChunkSize = write_header(out);

                        index = 0;
                        dataChunkSize = 0;
                        ret = 1;
                        while (ret > 0) {
								ret =
                                    dlp_ReadRecordByIndex
                                    PI_ARGS((sd, db, index, buffer, &id_,
                                             &attr, &category));
				if (ret > 0) {
                                  dataChunkSize = write_data(buffer->data, index, buffer->used, dataChunkSize, out);
				}
				index++;
                        }
			wWaveLength = 4 + 4 + 4 + formatChunkSize + 4 + 4 + dataChunkSize;
                        fseek(out, 44, SEEK_SET);
                        fwrite(&dataChunkSize, 4, 1, out);
                        fseek(out, 4, SEEK_SET);
			fwrite(&wWaveLength, 4, 1, out);
                        dlp_CloseDB(sd, db);
                        fclose(out);
			if (!plu_quiet) {
                        	printf("OK\n");
			}
                }
        }
		pi_buffer_free(buffer);
        return 0;
}
Пример #19
0
/***********************************************************************
 *
 * Function:    sync_MergeToPilot_slow
 *
 * Summary:     Slow merge from desktop to Palm
 *
 * Parameters:  None
 *
 * Returns:     0 on success, non-zero otherwise
 *
 ***********************************************************************/
static int
sync_MergeToPilot_slow(SyncHandler * sh, int dbhandle,
		       RecordModifier rec_mod)
{
	int 	darch,
		dsecret,
		result 		= 0;
	PilotRecord *precord 	= NULL;
	DesktopRecord *drecord 	= NULL;
	RecordQueue rq 		= { 0, NULL };
	pi_buffer_t *recbuf = pi_buffer_new(DLP_BUF_SIZE);

	while (sh->ForEach(sh, &drecord) == 0 && drecord) {
		if (drecord->recID != 0) {
			precord = sync_NewPilotRecord(DLP_BUF_SIZE);
			precord->recID = drecord->recID;
			PilotCheck(dlp_ReadRecordById(sh->sd, dbhandle,
						      precord->recID,
						      recbuf,
						      NULL,
						      &precord->flags,
						      &precord->catID));
			precord->len = recbuf->used;
			if (precord->len > DLP_BUF_SIZE)
				precord->len = DLP_BUF_SIZE;
			memcpy(precord->buffer, recbuf->data, precord->len);
		}

		/* Since this is a slow sync, we must calculate the flags */
		darch = drecord->flags & dlpRecAttrArchived;
		dsecret = drecord->flags & dlpRecAttrSecret;

		drecord->flags = 0;
		if (precord == NULL) {
			drecord->flags = drecord->flags | dlpRecAttrDirty;
		} else {
			int comp;

			comp = sh->Compare(sh, precord, drecord);
			if (comp != 0) {
				drecord->flags =
				    drecord->flags | dlpRecAttrDirty;
			}
		}
		if (darch)
			drecord->flags =
			    drecord->flags | dlpRecAttrArchived;
		if (dsecret)
			drecord->flags = drecord->flags | dlpRecAttrSecret;

		ErrorCheck(sync_record
			   (sh, dbhandle, drecord, precord, &rq, rec_mod));

		if (precord)
			sync_FreePilotRecord (precord);
		precord = NULL;
	}
	pi_buffer_free(recbuf);

	result = sync_MergeFromPilot_process(sh, dbhandle, &rq, rec_mod);

	return result;
}
Пример #20
0
int write_file(FILE *out, int sd, int db, struct AddressAppInfo *aai, int human) {
	int 	i,
		j,
		attribute,
		category;
	struct 	Address addr;
	pi_buffer_t *buf;

	int count = 0;
	const char *progress = "   Writing Palm Address Book entries to file... ";

	if (!human) {
		/* Print out the header and fields with fields intact. Note we
		'ignore' the last field (Private flag) and print our own here, so
		we don't have to chop off the trailing comma at the end. Hacky. */
		fprintf(out, "# ");
		for (j = 0; j < 21; j++) {
			write_field(out, tableheads[j],
				j<20 ? tabledelim : term_newline);
		}
		if (augment) {
			fprintf(out,"### This in an augmented (non-standard) CSV file.\n");
		}
	}

	if (!plu_quiet) {
		printf("%s",progress);
		fflush(stdout);
	}

	buf = pi_buffer_new (0xffff);
	for (i = 0;
	     (j =
	      dlp_ReadRecordByIndex(sd, db, i, buf, 0,
				    &attribute, &category)) >= 0;
	     i++) {


		if (attribute & dlpRecAttrDeleted)
			continue;
		unpack_Address(&addr, buf, address_v1);

		if (!human) {
			write_record_CSV(out,aai,&addr,attribute,category);
		} else {
			write_record_human(aai,&addr,category);
		}


		++count;
		if (!plu_quiet) {
			printf("\r%s%d",progress,count);
			fflush(stdout);
		}
	}
	pi_buffer_free (buf);

	if (!plu_quiet) {
		printf("\r%s%d\n   Done.\n",progress,count);
		fflush(stdout);
	}
	return 0;
}
Пример #21
0
/*
 * converts a ECalComponent object to a EMemoLocalRecord
 */
static void
local_record_from_comp (EMemoLocalRecord *local, ECalComponent *comp, EMemoConduitContext *ctxt)
{
	const char *uid;
	GSList *d_list = NULL;
	ECalComponentText *description;
	ECalComponentClassification classif;

	LOG (g_message ( "local_record_from_comp\n" ));

	g_return_if_fail (local != NULL);
	g_return_if_fail (comp != NULL);

	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) {
#ifdef PILOT_LINK_0_12
		struct Memo memo;
		pi_buffer_t * record;
#else
		char record[0xffff];
#endif
		int cat = 0;

#ifdef PILOT_LINK_0_12
		record = pi_buffer_new(DLP_BUF_SIZE);
		if(record == NULL){
			pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
			return;
		}
#endif

		LOG(fprintf(stderr, "local_record_from_comp: calling dlp_ReadRecordById\n"));
		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket,
					ctxt->dbi->db_handle,
#ifdef PILOT_LINK_0_12
					local->local.ID, record,
					NULL, NULL, &cat) > 0) {
			local->local.category = cat;
			memset (&memo, 0, sizeof (struct Memo));
			unpack_Memo (&memo, record, memo_v1);
			local->memo->text = strdup (memo.text);
			free_Memo (&memo);
		}
		pi_buffer_free (record);
#else
					local->local.ID, &record,
					NULL, NULL, NULL, &cat) > 0) {
			local->local.category = cat;
		}
#endif
		LOG(fprintf(stderr, "local_record_from_comp: done calling dlp_ReadRecordById\n"));
	}

	/*Category support*/
	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));

	/* STOP: don't replace these with g_strdup, since free_Memo
	   uses free to deallocate */

	e_cal_component_get_description_list (comp, &d_list);
	if (d_list) {
		description = (ECalComponentText *) d_list->data;
		if (description && description->value){
			local->memo->text = e_pilot_utf8_to_pchar (description->value);
		}
		else{
			local->memo->text = NULL;
		}
	} else {
		local->memo->text = NULL;
	}

	e_cal_component_get_classification (comp, &classif);

	if (classif == E_CAL_COMPONENT_CLASS_PRIVATE)
		local->local.secret = 1;
	else
		local->local.secret = 0;

	local->local.archived = 0;
}
Пример #22
0
int main(int argc, const char *argv[])
{
	int 	db,
		sd		= -1,
		i,
		l,
		category,
		po_err		= -1,
		replace_category = 0;

	char
		*category_name 	= NULL,
		*expenseType	= NULL,
		*paymentType	= NULL;
	size_t size;
	int found;

	unsigned char buf[0xffff];
	unsigned char *b;
	pi_buffer_t *appblock;

	struct 	PilotUser User;
	struct 	ExpenseAppInfo eai;
	struct 	Expense theExpense;

	poptContext po;

	struct poptOption options[] = {
		USERLAND_RESERVED_OPTIONS
	        {"ptype", 	't', POPT_ARG_STRING, &paymentType, 0,"Payment type (Cash, Check, etc.)"},
        	{"etype", 	'e', POPT_ARG_STRING, &expenseType, 0, "Expense type (Airfare, Hotel, etc.)"},
	        {"amount", 	'a', POPT_ARG_STRING, &theExpense.amount, 0, "Payment amount"},
        	{"vendor", 	'V', POPT_ARG_STRING, &theExpense.vendor, 0, "Expense vendor name (Joe's Restaurant)"},
	        {"city", 	'i', POPT_ARG_STRING, &theExpense.city, 0, "Location/city for this expense entry"},
        	{"guests", 	'g', POPT_ARG_STRING, &theExpense.attendees, 0, "Number of guests for this expense entry","NUMBER"},
	        {"note", 	'n', POPT_ARG_STRING, &theExpense.note, 0, "Notes for this expense entry"},
        	{"category", 	'c', POPT_ARG_STRING, &category_name, 0, "Install entry into this category", "CATEGORY" },
                {"replace", 	0, POPT_ARG_VAL, &replace_category, 1, "Replace all entries in category by this one"},
        	POPT_TABLEEND
	};

	/* Zero 'em out to be sure. */
	theExpense.amount=theExpense.vendor=theExpense.city=
	theExpense.attendees=theExpense.note = NULL ;

	po = poptGetContext("pilot-install-expenses", argc, argv, options, 0);
	poptSetOtherOptionHelp(po,"\n\n"
		"   Install Expense application entries to your Palm device\n\n"
		"   Example arguments:\n"
		"     %s -p /dev/pilot -c Unfiled -t Cash -e Meals -a 10.00 -V McDonalds \n"
		"                      -g 21 -l \"San Francisco\" -N \"This is a note\"\n\n");

	if (argc < 2) {
		poptPrintUsage(po,stderr,0);
		return 1;
        }

	 while ((po_err = poptGetNextOpt(po)) >= 0) {
		fprintf(stderr,"   ERROR: Unhandled option %d.\n",po_err);
		return 1;
	}

	theExpense.type = etBus;
	found = 0;
	for (i = 0; expenseType && ExpenseTypeNames[i] != NULL; i++)
	{
		if (strcasecmp(expenseType, ExpenseTypeNames[i]) == 0)
		{
			theExpense.type = i;
			found = 1;
			break;
		}
	}
	if (!found) {
		fprintf(stderr,"   WARNING: Expense type '%s' not recognized, using 'Bus Fare'.\n",expenseType);
	}

	theExpense.payment = epCash;
	found = 0;
	for (i = 0; paymentType && ExpensePaymentNames[i] != NULL; i++)
	{
		if (strcasecmp(paymentType, ExpensePaymentNames[i]) == 0)
		{
			theExpense.payment = i;
			found = 1;
			break;
		}
	}
	if (!found) {
		fprintf(stderr,"   WARNING: Payment type '%s' not recognized, using 'Cash'.\n", paymentType);
	}

	if (replace_category && (!category_name)) {
		fprintf(stderr,
			"   ERROR: category required when specifying replace\n");
		return 1;
	}


	if (!(theExpense.amount || theExpense.vendor || theExpense.city ||
		theExpense.attendees ||theExpense.note)) {
		fprintf(stderr,"   ERROR: Must specify at least one of amount, vendor, city, attendees or note.\n");
		return 1;
	}

	sd = plu_connect();
	if (sd < 0)
		goto error;

	if (dlp_OpenConduit(sd) < 0)
		goto error_close;

	dlp_ReadUserInfo(sd, &User);
	dlp_OpenConduit(sd);

	/* Open the Expense's database, store access handle in db */
	if (dlp_OpenDB(sd, 0, 0x80 | 0x40, Expense_DB, &db) < 0) {
		fprintf(stderr,"   ERROR: Unable to open ExpenseDB on Palm.");
		dlp_AddSyncLogEntry(sd, "Unable to open ExpenseDB.\n");
		goto error_close;
	}

	appblock = pi_buffer_new(0xffff);
	l = dlp_ReadAppBlock(sd, db, 0, 0xffff, appblock);
	unpack_ExpenseAppInfo(&eai, appblock->data, l);
	pi_buffer_free(appblock);

	category = 0;	/* unfiled */
	if (category_name) {
		category = plu_findcategory(&eai.category,category_name,
			PLU_CAT_CASE_INSENSITIVE | PLU_CAT_WARN_UNKNOWN);
		if (category < 0) {
			goto error_close;
		}

		if (replace_category) {
			dlp_DeleteCategory(sd, db, category);
		}

	}

		theExpense.currency 	= 0;

		if (!theExpense.amount) {
			theExpense.amount = "";
		}
		if (!theExpense.vendor) {
			theExpense.vendor = "";
		}
		if (!theExpense.city) {
			theExpense.city = "";
		}
		if (!theExpense.attendees) {
			theExpense.attendees 	= "";
		}
		if (!theExpense.note) {
			theExpense.note = "";
		}

		b = buf;

		/* Date */
		*(b++) 	= 0xc3;
		*(b++) 	= 0x45;

		*(b++) 	= theExpense.type;
		*(b++) 	= theExpense.payment;
		*(b++) 	= theExpense.currency;
		*(b++) 	= 0x00;

		strcpy(b, theExpense.amount);
		b += strlen(theExpense.amount) + 1;

		strcpy(b, theExpense.vendor);
		b += strlen(theExpense.vendor) + 1;

		strcpy(b, theExpense.city);
		b += strlen(theExpense.city) + 1;

		strcpy(b, theExpense.attendees);
		b += strlen(theExpense.attendees) + 1;

		strcpy(b, theExpense.note);
		b += strlen(theExpense.note) + 1;

		size = b - buf;
		dlp_WriteRecord(sd, (unsigned char)db, 0, 0, category,
				(unsigned char *)buf, size, 0);

	/* Close the database */
	dlp_CloseDB(sd, db);

	/* Tell the user who it is, with a different PC id. */
	User.lastSyncPC 	= 0x00010000;
	User.successfulSyncDate = time(NULL);
	User.lastSyncDate 	= User.successfulSyncDate;
	dlp_WriteUserInfo(sd, &User);

	dlp_AddSyncLogEntry(sd, "Wrote expense entry to Palm.\n");
	dlp_EndOfSync(sd, 0);
	pi_close(sd);
	poptFreeContext(po);
	return 0;

error_close:
	pi_close(sd);

error:
	return -1;
}
Пример #23
0
static ECalComponent *
comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
			 GnomePilotRecord *remote,
			 ECalComponent *in_comp,
			 icaltimezone *timezone,
			 struct MemoAppInfo *ai)
{
	ECalComponent *comp;
	struct Memo memo;
	struct icaltimetype now;
	icaltimezone *utc_zone;
	char *txt, *txt2, *txt3;
	int i;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#endif
	g_return_val_if_fail (remote != NULL, NULL);

#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		return NULL;
	}

	if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){
		return NULL;
	}

	unpack_Memo (&memo, buffer, memo_v1);
	pi_buffer_free(buffer);
#else
	memset (&memo, 0, sizeof (struct Memo));
	unpack_Memo (&memo, remote->record, remote->length);
#endif

	utc_zone = icaltimezone_get_utc_timezone ();
	now = icaltime_from_timet_with_zone (time (NULL), FALSE,
					     utc_zone);

	if (in_comp == NULL) {
		comp = e_cal_component_new ();
		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL);
		e_cal_component_set_created (comp, &now);
	} else {
		comp = e_cal_component_clone (in_comp);
	}

	e_cal_component_set_last_modified (comp, &now);

	/*Category support*/
	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category));

	/* The iCal description field */
	if (!memo.text) {
		e_cal_component_set_comment_list (comp, NULL);
		e_cal_component_set_summary(comp, NULL);
	} else {
		int idxToUse = -1, ntext = strlen(memo.text);
		gboolean foundNL = FALSE;
		GSList l;
		ECalComponentText text, sumText;

		for(i = 0; i<ntext && i<50; i++){
			if(memo.text[i] == '\n'){
				idxToUse = i;
				foundNL = TRUE;
				break;
			}
		}

		if(foundNL == FALSE){
			if(ntext > 50){
				txt2 = g_strndup(memo.text, 50);
			}
			else{
				txt2 = g_strdup(memo.text);

			}
		}
		else{
			txt2 = g_strndup(memo.text, idxToUse); /* cuts off '\n' */

		}

		sumText.value = txt3 = e_pilot_utf8_from_pchar(txt2);
		sumText.altrep = NULL;

		text.value = txt = e_pilot_utf8_from_pchar (memo.text);
		text.altrep = NULL;
		l.data = &text;
		l.next = NULL;

		e_cal_component_set_summary(comp, &sumText);
		e_cal_component_set_description_list (comp, &l);
		free (txt);
		g_free(txt2);
		free(txt3);
	}


	e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_NONE);

	if (remote->secret)
		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PRIVATE);
	else
		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PUBLIC);

	e_cal_component_commit_sequence (comp);

	free_Memo(&memo);

	return comp;
}