/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2002 Match Grun
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <dlfcn.h>
+#include <netinet/in.h>
#ifdef HAVE_LIBPISOCK_PI_ARGS_H
# include <libpisock/pi-args.h>
#include "addritem.h"
#include "addrcache.h"
#include "jpilot.h"
+#include "adbookbase.h"
#define JPILOT_DBHOME_DIR ".jpilot"
#define JPILOT_DBHOME_FILE "AddressDB.pdb"
/* Shamelessly copied from JPilot (libplugin.h) */
typedef struct {
- unsigned long header_len;
- unsigned long header_version;
- unsigned long rec_len;
- unsigned long unique_id;
- unsigned long rt; /* Record Type */
- unsigned char attrib;
+ unsigned long header_len;
+ unsigned long header_version;
+ unsigned long rec_len;
+ unsigned long unique_id;
+ unsigned long rt; /* Record Type */
+ unsigned char attrib;
} PC3RecordHeader;
/*
JPilotFile *jpilot_create() {
JPilotFile *pilotFile;
pilotFile = g_new0( JPilotFile, 1 );
- pilotFile->name = NULL;
+ pilotFile->type = ADBOOKTYPE_JPILOT;
+ pilotFile->addressCache = addrcache_create();
+ pilotFile->accessFlag = FALSE;
+ pilotFile->retVal = MGU_SUCCESS;
+
pilotFile->file = NULL;
pilotFile->path = NULL;
- pilotFile->addressCache = addrcache_create();
pilotFile->readMetadata = FALSE;
pilotFile->customLabels = NULL;
pilotFile->labelInd = NULL;
- pilotFile->retVal = MGU_SUCCESS;
- pilotFile->accessFlag = FALSE;
pilotFile->havePC3 = FALSE;
pilotFile->pc3ModifyTime = 0;
return pilotFile;
*/
void jpilot_set_name( JPilotFile* pilotFile, const gchar *value ) {
g_return_if_fail( pilotFile != NULL );
- pilotFile->name = mgu_replace_string( pilotFile->name, value );
+ addrcache_set_name( pilotFile->addressCache, value );
}
void jpilot_set_file( JPilotFile* pilotFile, const gchar *value ) {
g_return_if_fail( pilotFile != NULL );
}
gchar *jpilot_get_name( JPilotFile *pilotFile ) {
g_return_val_if_fail( pilotFile != NULL, NULL );
- return pilotFile->name;
+ return addrcache_get_name( pilotFile->addressCache );
}
/*
}
/*
- * Return filespec of PC3 file corresponding to JPilot PDB file.
- * Note: Filespec should be g_free() when done.
- */
+* Return filespec of PC3 file corresponding to JPilot PDB file.
+* Note: Filespec should be g_free() when done.
+*/
static gchar *jpilot_get_pc3_file( JPilotFile *pilotFile ) {
gchar *fileSpec, *r;
gint i, len, pos;
gchar *pcFile;
/* Check main file */
- if( addrcache_check_file( pilotFile->addressCache, pilotFile->path ) ) return TRUE;
+ if( addrcache_check_file( pilotFile->addressCache, pilotFile->path ) )
+ return TRUE;
/* Test PC3 file */
if( ! pilotFile->havePC3 ) return FALSE;
void jpilot_free( JPilotFile *pilotFile ) {
g_return_if_fail( pilotFile != NULL );
- /* Free internal stuff */
- g_free( pilotFile->path );
-
/* Release custom labels */
jpilot_clear_custom_labels( pilotFile );
/* Clear cache */
addrcache_clear( pilotFile->addressCache );
addrcache_free( pilotFile->addressCache );
- pilotFile->addressCache = NULL;
+
+ /* Free internal stuff */
+ g_free( pilotFile->path );
+
+ pilotFile->file = NULL;
+ pilotFile->path = NULL;
pilotFile->readMetadata = FALSE;
- pilotFile->accessFlag = FALSE;
pilotFile->havePC3 = FALSE;
pilotFile->pc3ModifyTime = 0;
+ pilotFile->type = ADBOOKTYPE_NONE;
+ pilotFile->addressCache = NULL;
+ pilotFile->accessFlag = FALSE;
+ pilotFile->retVal = MGU_SUCCESS;
+
/* Now release file object */
g_free( pilotFile );
}
addrcache_print( pilotFile->addressCache, stream );
fprintf( stream, " ret val: %d\n", pilotFile->retVal );
fprintf( stream, " have pc3: %s\n", pilotFile->havePC3 ? "yes" : "no" );
- fprintf( stream, " pc3 time: %d\n", pilotFile->pc3ModifyTime );
+ fprintf( stream, " pc3 time: %lu\n", pilotFile->pc3ModifyTime );
addritem_print_item_folder( pilotFile->addressCache->rootFolder, stream );
}
}
addrcache_print( pilotFile->addressCache, stream );
fprintf( stream, " have pc3: %s\n", pilotFile->havePC3 ? "yes" : "no" );
- fprintf( stream, " pc3 time: %d\n", pilotFile->pc3ModifyTime );
+ fprintf( stream, " pc3 time: %lu\n", pilotFile->pc3ModifyTime );
}
/* Shamelessly copied from JPilot (libplugin.c) */
num = fread(&l, sizeof(l), 1, pc_in);
if (feof(pc_in)) {
return -1;
- }
+ }
if (num!=1) {
return num;
}
num = fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in);
if (feof(pc_in)) {
return -1;
- }
+ }
if (num!=1) {
return num;
}
PC3RecordHeader header;
int rec_len, num;
char *record;
-
+
if(feof(in)) {
- return MGU_EOF;
+ return MGU_EOF;
}
num = read_header(in, &header);
if (num < 1) {
if (ferror(in)) {
- return MGU_ERROR_READ;
+ return MGU_ERROR_READ;
}
if (feof(in)) {
- return MGU_EOF;
+ return MGU_EOF;
}
}
rec_len = header.rec_len;
if (num != 1) {
if (ferror(in)) {
free(record);
- return MGU_ERROR_READ;
+ return MGU_ERROR_READ;
}
}
br->rt = header.rt;
recs_returned = 0;
if( pilotFile->path == NULL ) {
- return MGU_BAD_ARGS;
+ return MGU_BAD_ARGS;
}
-
+
in = fopen( pilotFile->path, "r" );
if (!in) {
- return MGU_OPEN_FILE;
+ return MGU_OPEN_FILE;
}
/* Read the database header */
return MGU_ERROR_READ;
}
if (feof(in)) {
+ fclose(in);
return MGU_EOF;
}
}
num_records = dbh.number_of_records;
out_of_order = 0;
prev_offset = 0;
-
- for (i=1; i<num_records+1; i++) {
+
+ for (i = 1; i < num_records + 1; i++) {
num = fread(&rh, sizeof(record_header), 1, in);
if (num != 1) {
if (ferror(in)) {
break;
}
if (feof(in)) {
+ fclose(in);
return MGU_EOF;
}
}
temp_br->size = rec_size;
*records = g_list_append(*records, temp_br);
-
+
recs_returned++;
}
}
pc_in = fopen( pcFile, "r");
g_free( pcFile );
- if( pc_in==NULL ) {
+ if( pc_in == NULL ) {
return MGU_SUCCESS;
}
return MGU_SUCCESS;
}
-#define FULLNAME_BUFSIZE 256
-#define EMAIL_BUFSIZE 256
+#define FULLNAME_BUFSIZE 256
+#define EMAIL_BUFSIZE 256
/*
* Unpack address, building new data inside cache.
*/
addrEnt = addr.entry;
attrib = buf->attrib;
unique_id = buf->unique_id;
- cat_id = attrib & 0x0F;
+ cat_id = attrib & 0x0F;
*fullName = *bufEMail = '\0';
if( addrEnt[ IND_LABEL_FIRSTNAME ] ) {
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 );
+ addrcache_person_add_email
+ ( pilotFile->addressCache, person, email );
}
}
}
addritem_email_set_address( email, bufEMail );
addritem_email_set_remarks( email, ai->labels[ind] );
addrcache_id_email( pilotFile->addressCache, email );
- addrcache_person_add_email(
- pilotFile->addressCache, person, 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 {
+ addrcache_folder_add_person
+ ( pilotFile->addressCache, folderInd[cat_id], person );
+ } else {
/* Add to root folder */
addrcache_add_person( pilotFile->addressCache, person );
}
- }
- else {
+ } else {
addritem_free_item_person( person );
person = NULL;
}
free(buf);
}
if( num <= 0 ) {
- /*
- fprintf( stderr, "error reading '%s'\n", pilotFile->path );
- */
pilotFile->retVal = MGU_ERROR_READ;
return pilotFile->retVal;
}
/*
* Load list with character strings of label names. Only none blank names
* are loaded.
+* Return: list of labels. Should by g_free()'d when done.
*/
GList *jpilot_load_custom_label( JPilotFile *pilotFile, GList *labelList ) {
gint i;
* Validate that all parameters specified.
* Return: TRUE if data is good.
*/
-gboolean jpilot_validate( const JPilotFile *pilotFile ) {
+gboolean jpilot_validate( JPilotFile *pilotFile ) {
gboolean retVal;
+ gchar *name;
g_return_val_if_fail( pilotFile != NULL, FALSE );
else {
retVal = FALSE;
}
- if( pilotFile->name ) {
- if( strlen( pilotFile->name ) < 1 ) retVal = FALSE;
+ name = jpilot_get_name( pilotFile );
+ if( name ) {
+ if( strlen( name ) < 1 ) retVal = FALSE;
}
else {
retVal = FALSE;
if( labelName ) {
node = pilotFile->customLabels;
while( node ) {
- if( g_strcasecmp( labelName, node->data ) == 0 ) {
+ if( g_strcasecmp( labelName, ( gchar * ) node->data ) == 0 ) {
retVal = TRUE;
break;
}
* Return: TRUE if library available.
*/
gboolean jpilot_test_pilot_lib( void ) {
- void *handle, *fun;
-
- handle = dlopen( PILOT_LINK_LIB_NAME, RTLD_LAZY );
- if( ! handle ) {
- return FALSE;
- }
-
- /* Test for symbols we need */
- fun = dlsym( handle, "unpack_Address" );
- if( ! fun ) {
- dlclose( handle );
- return FALSE;
- }
-
- fun = dlsym( handle, "unpack_AddressAppInfo" );
- if( ! fun ) {
- dlclose( handle );
- return FALSE;
- }
- dlclose( handle );
return TRUE;
}