/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2003 Match Grun
+ * Copyright (C) 2001-2012 Match Grun and the Claws Mail team
*
* 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
/*
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#ifdef USE_JPILOT
# include <libpisock/pi-args.h>
# include <libpisock/pi-appinfo.h>
# include <libpisock/pi-address.h>
+# include <libpisock/pi-version.h>
#else
# include <pi-args.h>
# include <pi-appinfo.h>
# include <pi-address.h>
+# include <pi-version.h>
#endif
#include "mgutils.h"
FAMILY_FIRST = 1
} name_order;
-gboolean convert_charcode;
+gboolean convert_charcode = TRUE;
+
+static const gchar *jpilot_get_charset(void)
+{
+ static const gchar *charset = NULL;
+
+ if (charset == NULL)
+ charset = getenv("PILOT_CHARSET");
+
+ if (charset == NULL)
+ charset = CS_CP1252;
+
+ return charset;
+}
/*
* Create new pilot file object.
* Properties...
*/
void jpilot_set_name( JPilotFile* pilotFile, const gchar *value ) {
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
addrcache_set_name( pilotFile->addressCache, value );
}
void jpilot_set_file( JPilotFile* pilotFile, const gchar *value ) {
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
addrcache_refresh( pilotFile->addressCache );
pilotFile->readMetadata = FALSE;
pilotFile->path = mgu_replace_string( pilotFile->path, value );
}
void jpilot_set_accessed( JPilotFile *pilotFile, const gboolean value ) {
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
pilotFile->addressCache->accessFlag = value;
}
gint jpilot_get_status( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, -1 );
+ cm_return_val_if_fail( pilotFile != NULL, -1 );
return pilotFile->retVal;
}
ItemFolder *jpilot_get_root_folder( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
return addrcache_get_root_folder( pilotFile->addressCache );
}
gchar *jpilot_get_name( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
return addrcache_get_name( pilotFile->addressCache );
}
* \return <i>TRUE</i> if file was read.
*/
gboolean jpilot_get_read_flag( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, FALSE );
+ cm_return_val_if_fail( pilotFile != NULL, FALSE );
return pilotFile->addressCache->dataRead;
}
void jpilot_clear_custom_labels( JPilotFile *pilotFile ) {
GList *node;
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
/* Release custom labels */
mgu_free_dlist( pilotFile->customLabels );
* \param pilotFile JPilot control data.
*/
void jpilot_add_custom_label( JPilotFile *pilotFile, const gchar *labelName ) {
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
if( labelName ) {
gchar *labelCopy = g_strdup( labelName );
GList *retVal = NULL;
GList *node;
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
node = pilotFile->customLabels;
while( node ) {
*/
static gboolean jpilot_mark_files( JPilotFile *pilotFile ) {
gboolean retVal = FALSE;
- struct stat filestat;
+ GStatBuf filestat;
gchar *pcFile;
/* Mark PDB file cache */
pilotFile->pc3ModifyTime = 0;
pcFile = jpilot_get_pc3_file( pilotFile );
if( pcFile == NULL ) return retVal;
- if( 0 == stat( pcFile, &filestat ) ) {
+ if( 0 == g_stat( pcFile, &filestat ) ) {
pilotFile->havePC3 = TRUE;
pilotFile->pc3ModifyTime = filestat.st_mtime;
retVal = TRUE;
*/
static gboolean jpilot_check_files( JPilotFile *pilotFile ) {
gboolean retVal = TRUE;
- struct stat filestat;
+ GStatBuf filestat;
gchar *pcFile;
/* Check main file */
pcFile = jpilot_get_pc3_file( pilotFile );
if( pcFile == NULL ) return FALSE;
- if( 0 == stat( pcFile, &filestat ) ) {
+ if( 0 == g_stat( pcFile, &filestat ) ) {
if( filestat.st_mtime == pilotFile->pc3ModifyTime ) retVal = FALSE;
}
g_free( pcFile );
* Return: TRUE if file was modified.
*/
gboolean jpilot_get_modified( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, FALSE );
+ cm_return_val_if_fail( pilotFile != NULL, FALSE );
pilotFile->addressCache->modified = jpilot_check_files( pilotFile );
return pilotFile->addressCache->modified;
}
-void jpilot_set_modified( JPilotFile *pilotFile, const gboolean value ) {
- g_return_if_fail( pilotFile != NULL );
- pilotFile->addressCache->modified = value;
-}
gboolean jpilot_get_accessed( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, FALSE );
+ cm_return_val_if_fail( pilotFile != NULL, FALSE );
return pilotFile->addressCache->accessFlag;
}
* \param pilotFile JPilot control data.
*/
void jpilot_free( JPilotFile *pilotFile ) {
- g_return_if_fail( pilotFile != NULL );
+ cm_return_if_fail( pilotFile != NULL );
/* Release custom labels */
jpilot_clear_custom_labels( pilotFile );
g_free( pilotFile );
}
-/*
-* Refresh internal variables to force a file read.
-*/
-void jpilot_force_refresh( JPilotFile *pilotFile ) {
- addrcache_refresh( pilotFile->addressCache );
-}
-
-/*
-* Print object to specified stream.
-*/
-void jpilot_print_file( JPilotFile *pilotFile, FILE *stream ) {
- GList *node;
-
- g_return_if_fail( pilotFile != NULL );
-
- fprintf( stream, "JPilotFile:\n" );
- fprintf( stream, "file spec: '%s'\n", pilotFile->path );
- fprintf( stream, " metadata: %s\n", pilotFile->readMetadata ? "yes" : "no" );
- fprintf( stream, " ret val: %d\n", pilotFile->retVal );
-
- node = pilotFile->customLabels;
- while( node ) {
- fprintf( stream, " c label: %s\n", (gchar *)node->data );
- node = g_list_next( node );
- }
-
- node = pilotFile->labelInd;
- while( node ) {
- fprintf( stream, " labelind: %d\n", GPOINTER_TO_INT(node->data) );
- node = g_list_next( node );
- }
-
- 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: %lu\n", pilotFile->pc3ModifyTime );
- addritem_print_item_folder( pilotFile->addressCache->rootFolder, stream );
-}
-
-/*
-* Print summary of object to specified stream.
-*/
-void jpilot_print_short( JPilotFile *pilotFile, FILE *stream ) {
- GList *node;
- g_return_if_fail( pilotFile != NULL );
- fprintf( stream, "JPilotFile:\n" );
- fprintf( stream, "file spec: '%s'\n", pilotFile->path );
- fprintf( stream, " metadata: %s\n", pilotFile->readMetadata ? "yes" : "no" );
- fprintf( stream, " ret val: %d\n", pilotFile->retVal );
-
- node = pilotFile->customLabels;
- while( node ) {
- fprintf( stream, " c label: %s\n", (gchar *)node->data );
- node = g_list_next( node );
- }
-
- node = pilotFile->labelInd;
- while( node ) {
- fprintf( stream, " labelind: %d\n", GPOINTER_TO_INT(node->data) );
- node = g_list_next( node );
- }
- addrcache_print( pilotFile->addressCache, stream );
- fprintf( stream, " have pc3: %s\n", pilotFile->havePC3 ? "yes" : "no" );
- fprintf( stream, " pc3 time: %lu\n", pilotFile->pc3ModifyTime );
-}
-
/* Shamelessly copied from JPilot (libplugin.c) */
static unsigned int bytes_to_bin(unsigned char *bytes, unsigned int num_bytes) {
unsigned int i, n;
/* Exact value of "Jan 1, 1970 0:00:00 GMT" - "Jan 1, 1904 0:00:00 GMT" */
#define PILOT_TIME_DELTA (unsigned)(2082844800)
-time_t pilot_time_to_unix_time ( unsigned long raw_time ) {
+static time_t pilot_time_to_unix_time ( unsigned long raw_time ) {
return (time_t)(raw_time - PILOT_TIME_DELTA);
}
DBHeader dbh;
unsigned int offset;
record_header rh;
+ int r;
fseek(in, 0, SEEK_SET);
- fread(&rdbh, sizeof(RawDBHeader), 1, in);
+ r = fread(&rdbh, sizeof(RawDBHeader), 1, in);
+ if (r < 1)
+ return MGU_ERROR_READ;
if (feof(in)) {
return MGU_EOF;
}
return MGU_SUCCESS;
}
- fread(&rh, sizeof(record_header), 1, in);
+ r = fread(&rh, sizeof(record_header), 1, in);
+ if (r < 1)
+ return MGU_ERROR_READ;
+
offset = ((rh.Offset[0]*256+rh.Offset[1])*256+rh.Offset[2])*256+rh.Offset[3];
*size=offset - dbh.app_info_offset;
*buf_size=0;
if( pilotFile->path ) {
- in = fopen( pilotFile->path, "rb" );
+ in = g_fopen( pilotFile->path, "rb" );
if( !in ) {
return MGU_OPEN_FILE;
}
return MGU_ERROR_READ;
}
- fseek(in, dbh.app_info_offset, SEEK_SET);
+ if (fseek(in, dbh.app_info_offset, SEEK_SET) < 0) {
+ fclose(in);
+ return MGU_ERROR_READ;
+ }
*buf = ( char * ) malloc(rec_size);
if (!(*buf)) {
fclose(in);
unsigned char packed_header[256];
int num;
+ memset(header, 0, sizeof(PC3RecordHeader));
+
num = fread(&l, sizeof(l), 1, pc_in);
if (feof(pc_in)) {
return -1;
}
memcpy(packed_header, &l, sizeof(l));
len=ntohl(l);
- if (len > 255) {
+ if (len > 255 || len < sizeof(l)) {
return -1;
}
num = fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in);
}
num = read_header( in, &header );
if( num < 1 ) {
- if( ferror( in ) ) {
+ if( ferror( in ) )
return MGU_ERROR_READ;
- }
- if( feof( in ) ) {
+ else if( feof( in ) )
return MGU_EOF;
- }
+ else
+ return -1;
}
rec_len = header.rec_len;
record = malloc( rec_len );
char *buf;
GList *temp_list;
int num_records, recs_returned, i, num, r;
- unsigned int offset, prev_offset, next_offset, rec_size;
+ unsigned int offset, prev_offset, next_offset = 0, rec_size;
int out_of_order;
long fpos; /*file position indicator */
- unsigned char attrib;
- unsigned int unique_id;
+ unsigned char attrib = '\0';
+ unsigned int unique_id = 0;
mem_rec_header *mem_rh, *temp_mem_rh, *last_mem_rh;
record_header rh;
RawDBHeader rdbh;
return MGU_BAD_ARGS;
}
- in = fopen( pilotFile->path, "rb" );
- if( ! in ) {
+ in = g_fopen( pilotFile->path, "rb" );
+ if (!in) {
return MGU_OPEN_FILE;
}
}
if( feof( in ) ) {
fclose( in );
+ if (mem_rh)
+ free_mem_rec_header( &mem_rh );
return MGU_EOF;
}
}
unique_id = mem_rh->unique_id;
}
}
- fseek( in, next_offset, SEEK_SET );
+ if (fseek( in, next_offset, SEEK_SET ) < 0) {
+ free_mem_rec_header( &mem_rh );
+ fclose(in);
+ return MGU_ERROR_READ;
+ }
while( ! feof( in ) ) {
fpos = ftell( in );
if( out_of_order ) {
/* Read the PC3 file, if present */
pcFile = jpilot_get_pc3_file( pilotFile );
if( pcFile == NULL ) return MGU_SUCCESS;
- pc_in = fopen( pcFile, "rb" );
+ pc_in = g_fopen( pcFile, "rb");
g_free( pcFile );
if( pc_in == NULL ) {
if( labelEntry ) {
*buffer = '\0';
- strcpy( buffer, labelEntry );
+ g_strlcpy( buffer, labelEntry, sizeof(buffer) );
node = list = jpilot_parse_email( buffer );
while( node ) {
- gchar convertBuff[JPILOT_LEN_LABEL];
email = addritem_create_item_email();
addritem_email_set_address( email, node->data );
if (convert_charcode) {
- gchar *convertBuff;
- convertBuff = conv_codeset_strdup( labelEntry, CS_SHIFT_JIS, CS_INTERNAL );
- addritem_email_set_remarks( email, convertBuff );
+ gchar *convertBuff = NULL;
+ convertBuff = conv_codeset_strdup( labelEntry,
+ jpilot_get_charset(),
+ CS_INTERNAL );
+ if (convertBuff)
+ addritem_email_set_remarks( email, convertBuff );
g_free( convertBuff );
}
else {
{
struct Address addr;
gchar **addrEnt;
- gint num, k;
+ gint k;
gint cat_id = 0;
guint unique_id;
guchar attrib;
gchar *labelEntry;
GList *node;
gchar* extID;
- struct AddressAppInfo *ai;
gchar **firstName = NULL;
gchar **lastName = NULL;
+#if (PILOT_LINK_MAJOR > 11)
+ pi_buffer_t *RecordBuffer;
+ RecordBuffer = pi_buffer_new(buf->size);
- /* Retrieve address */
- num = unpack_Address( & addr, buf->buf, buf->size );
- if( num > 0 ) {
- addrEnt = addr.entry;
- attrib = buf->attrib;
- unique_id = buf->unique_id;
- cat_id = attrib & 0x0F;
+ memcpy(RecordBuffer->data, buf->buf, buf->size);
+ RecordBuffer->used = buf->size;
+ if (unpack_Address(&addr, RecordBuffer, address_v1) == -1) {
+ pi_buffer_free(RecordBuffer);
+ return;
+ }
+ pi_buffer_free(RecordBuffer);
+#else
+ gint num;
- *fullName = '\0';
+ num = unpack_Address(&addr, buf->buf, buf->size);
+ if (num <= 0) {
+ return;
+ }
+#endif /* PILOT_LINK_0_12 */
- if( addrEnt[ IND_LABEL_FIRSTNAME ] ) {
- firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 );
- }
+ addrEnt = addr.entry;
+ attrib = buf->attrib;
+ unique_id = buf->unique_id;
+ cat_id = attrib & 0x0F;
- if( addrEnt[ IND_LABEL_LASTNAME ] ) {
- lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 );
- }
+ *fullName = '\0';
+ if( addrEnt[ IND_LABEL_FIRSTNAME ] ) {
+ firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\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( addrEnt[ IND_LABEL_LASTNAME ] ) {
+ lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 );
+ }
- if( firstName ) {
- g_strfreev( firstName );
- }
- if( lastName ) {
- g_strfreev( lastName );
- }
+ 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] : "" );
+ }
- g_strstrip( fullName );
+ if( firstName ) {
+ g_strfreev( firstName );
+ }
+ if( lastName ) {
+ g_strfreev( lastName );
+ }
- if( convert_charcode ) {
- gchar *nameConv;
- nameConv = conv_codeset_strdup( fullName, CS_SHIFT_JIS, CS_INTERNAL );
+ g_strstrip( fullName );
+
+ if( convert_charcode ) {
+ gchar *nameConv = NULL;
+ nameConv = conv_codeset_strdup( fullName,
+ jpilot_get_charset(),
+ CS_INTERNAL );
+ if (nameConv)
strncpy2( fullName, nameConv, FULLNAME_BUFSIZE );
- g_free( nameConv );
+ 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;
+
+ /* Add entry for each email address listed under phone labels. */
+ indPhoneLbl = addr.phoneLabel;
+ for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) {
+ if( indPhoneLbl[k] == IND_PHONE_EMAIL ) {
+ labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ];
+ jpilot_parse_label( pilotFile, labelEntry, person );
}
+ }
- 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;
+ /* Add entry for each custom label */
+ node = pilotFile->labelInd;
+ while( node ) {
+ gint ind;
- ind = indPhoneLbl[k];
+ ind = GPOINTER_TO_INT( node->data );
+ if( ind > -1 ) {
/*
- * fprintf( stdout, "%d : %d : %20s : %s\n", k, ind,
- * ai->phoneLabels[ind], addrEnt[3+k] );
+ * g_print( "%d : %20s : %s\n", ind, ai->labels[ind],
+ * addrEnt[ind] );
*/
- if( indPhoneLbl[k] == IND_PHONE_EMAIL ) {
- labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ];
- jpilot_parse_label( pilotFile, labelEntry, person );
- }
- }
-
- /* 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];
- jpilot_parse_label( pilotFile, labelEntry, person );
- }
-
- node = g_list_next( node );
+ labelEntry = addrEnt[ind];
+ jpilot_parse_label( pilotFile, labelEntry, person );
}
- 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;
- }
+ node = g_list_next( node );
}
+ if( person->listEMail ) {
+ /* Add to specified category */
+ addrcache_folder_add_person(
+ pilotFile->addressCache,
+ folderInd[cat_id], person );
+ }
+ else {
+ addritem_free_item_person( person );
+ person = NULL;
+ }
/* Free up pointer allocated inside address */
free_Address( & addr );
}
unsigned char *buf;
int num;
- g_return_val_if_fail( pilotFile != NULL, -1 );
+ cm_return_val_if_fail( pilotFile != NULL, -1 );
pilotFile->readMetadata = FALSE;
addrcache_clear( pilotFile->addressCache );
struct AddressAppInfo *ai;
GList *node;
- g_return_val_if_fail( pilotFile != NULL, -1 );
+ cm_return_val_if_fail( pilotFile != NULL, -1 );
/* Release indexes */
node = pilotFile->labelInd;
gint i;
for( i = 0; i < JPILOT_NUM_LABELS; i++ ) {
gchar *labelName = ai->labels[i];
- gchar convertBuff[ JPILOT_LEN_LABEL ];
if( convert_charcode ) {
- labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
- strncpy2( convertBuff, labelName, JPILOT_LEN_LABEL );
- g_free( labelName );
- labelName = convertBuff;
+ gchar *convertBuff = NULL;
+ convertBuff = conv_codeset_strdup( labelName,
+ jpilot_get_charset(),
+ CS_INTERNAL );
+ if (convertBuff) {
+ labelName = convertBuff;
+ }
}
if( g_utf8_collate( labelName, lbl ) == 0 ) {
return retVal;
}
-/**
- * Load list with character strings of label names.
- * \param pilotFile JPilot control data.
- * \param labelList List of label names to load.
- * \return List of label names loaded.
- */
-GList *jpilot_load_label( JPilotFile *pilotFile, GList *labelList ) {
- int i;
-
- g_return_val_if_fail( pilotFile != NULL, NULL );
-
- if( pilotFile->readMetadata ) {
- struct AddressAppInfo *ai = & pilotFile->addrInfo;
- for( i = 0; i < JPILOT_NUM_LABELS; i++ ) {
- gchar *labelName = ai->labels[i];
-
- if( labelName ) {
- if( convert_charcode ) {
- labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
- }
- else {
- labelName = g_strdup( labelName );
- }
- labelList = g_list_append( labelList, labelName );
- }
- else {
- labelList = g_list_append(
- labelList, g_strdup( "" ) );
- }
- }
- }
- return labelList;
-}
-
-/**
- * Return category name for specified category ID.
- * \param pilotFile JPilot control data.
- * \param catID Category ID.
- * \return Category name, or empty string if not invalid ID. Name should be
- * <code>g_free()</code> when done.
- */
-gchar *jpilot_get_category_name( JPilotFile *pilotFile, gint catID ) {
- gchar *catName = NULL;
-
- g_return_val_if_fail( pilotFile != NULL, NULL );
-
- if( pilotFile->readMetadata ) {
- struct AddressAppInfo *ai = & pilotFile->addrInfo;
- struct CategoryAppInfo *cat = & ai->category;
- if( catID < 0 || catID > JPILOT_NUM_CATEG ) {
- }
- else {
- catName = g_strdup( cat->name[catID] );
- }
- }
- if( ! catName ) catName = g_strdup( "" );
- return catName;
-}
-
-/**
- * Load list with character strings of phone label names.
- * \param pilotFile JPilot control data.
- * \param labelList List of label names to load.
- * \return List of label names loaded.
- */
-GList *jpilot_load_phone_label( JPilotFile *pilotFile, GList *labelList ) {
- gint i;
-
- g_return_val_if_fail( pilotFile != NULL, NULL );
-
- if( pilotFile->readMetadata ) {
- struct AddressAppInfo *ai = & pilotFile->addrInfo;
- for( i = 0; i < JPILOT_NUM_PHONELABELS; i++ ) {
- gchar *labelName = ai->phoneLabels[i];
- if( labelName ) {
- labelList = g_list_append(
- labelList, g_strdup( labelName ) );
- }
- else {
- labelList = g_list_append(
- labelList, g_strdup( "" ) );
- }
- }
- }
- return labelList;
-}
-
/**
* Load list with character strings of custom label names. Only none blank
* names are loaded.
GList *jpilot_load_custom_label( JPilotFile *pilotFile, GList *labelList ) {
gint i;
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
if( pilotFile->readMetadata ) {
struct AddressAppInfo *ai = & pilotFile->addrInfo;
g_strchug( labelName );
if( *labelName != '\0' ) {
if( convert_charcode ) {
- labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
+ gchar *convertBuff = NULL;
+ convertBuff = conv_codeset_strdup( labelName,
+ jpilot_get_charset(),
+ CS_INTERNAL );
+ if (convertBuff) {
+ labelName = convertBuff;
+ }
}
else {
labelName = g_strdup( labelName );
return labelList;
}
-/**
- * Load list with character strings of category names.
- * \param pilotFile JPilot control data.
- * \return List of label names loaded. Should be freed when done.
- */
-GList *jpilot_get_category_list( JPilotFile *pilotFile ) {
- GList *catList = NULL;
- gint i;
-
- g_return_val_if_fail( pilotFile != NULL, NULL );
-
- if( pilotFile->readMetadata ) {
- struct AddressAppInfo *ai = & pilotFile->addrInfo;
- struct CategoryAppInfo *cat = & ai->category;
- for( i = 0; i < JPILOT_NUM_CATEG; i++ ) {
- gchar *catName = cat->name[i];
- if( catName ) {
- catList = g_list_append(
- catList, g_strdup( catName ) );
- }
- else {
- catList = g_list_append(
- catList, g_strdup( "" ) );
- }
- }
- }
- return catList;
-}
-
/**
* Build folder in address book for each category.
* \param pilotFile JPilot control data.
ItemFolder *folder = addritem_create_item_folder();
if( convert_charcode ) {
- gchar *catName;
- catName = conv_codeset_strdup( cat->name[i], CS_SHIFT_JIS, CS_INTERNAL );
- addritem_folder_set_name( folder, catName );
- g_free( catName );
+ gchar *convertBuff = NULL;
+ convertBuff = conv_codeset_strdup( cat->name[i],
+ jpilot_get_charset(),
+ CS_INTERNAL );
+ if (convertBuff) {
+ addritem_folder_set_name( folder, convertBuff );
+ g_free( convertBuff );
+ } else {
+ addritem_folder_set_name( folder, cat->name[i] );
+ }
}
else {
addritem_folder_set_name( folder, cat->name[i] );
const gchar *cur_locale;
name_order = FAMILY_LAST;
- convert_charcode = FALSE;
cur_locale = conv_get_current_locale();
name_order = FAMILY_FIRST;
}
- if( conv_get_locale_charset() == C_EUC_JP ) {
- convert_charcode = TRUE;
- }
-
- g_return_val_if_fail( pilotFile != NULL, -1 );
+ cm_return_val_if_fail( pilotFile != NULL, -1 );
pilotFile->retVal = MGU_SUCCESS;
pilotFile->addressCache->accessFlag = FALSE;
* \return List of persons.
*/
GList *jpilot_get_list_person( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
return addrcache_get_list_person( pilotFile->addressCache );
}
* \return List of ItemFolder objects. This should not be freed.
*/
GList *jpilot_get_list_folder( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
return addrcache_get_list_folder( pilotFile->addressCache );
}
* \return List of items, or NULL if none.
*/
GList *jpilot_get_all_persons( JPilotFile *pilotFile ) {
- g_return_val_if_fail( pilotFile != NULL, NULL );
+ cm_return_val_if_fail( pilotFile != NULL, NULL );
return addrcache_get_all_persons( pilotFile->addressCache );
}
-/**
- * Validate that all parameters specified.
- * \param pilotFile JPilot control data.
- * \return <i>TRUE</i> if data is good.
- */
-gboolean jpilot_validate( JPilotFile *pilotFile ) {
- gboolean retVal;
- gchar *name;
-
- g_return_val_if_fail( pilotFile != NULL, FALSE );
-
- retVal = TRUE;
- if( pilotFile->path ) {
- if( strlen( pilotFile->path ) < 1 ) retVal = FALSE;
- }
- else {
- retVal = FALSE;
- }
- name = jpilot_get_name( pilotFile );
- if( name ) {
- if( strlen( name ) < 1 ) retVal = FALSE;
- }
- else {
- retVal = FALSE;
- }
- return retVal;
-}
-
#define WORK_BUFLEN 1024
/**
*/
gchar *jpilot_find_pilotdb( void ) {
const gchar *homedir;
- gchar str[ WORK_BUFLEN ];
+ gchar str[ WORK_BUFLEN + 1 ];
gint len;
FILE *fp;
homedir = get_home_dir();
if( ! homedir ) return g_strdup( "" );
- strcpy( str, homedir );
+ g_strlcpy( str, homedir , sizeof(str));
len = strlen( str );
if( len > 0 ) {
if( str[ len-1 ] != G_DIR_SEPARATOR ) {
str[ ++len ] = '\0';
}
}
- strcat( str, JPILOT_DBHOME_DIR );
- strcat( str, G_DIR_SEPARATOR_S );
- strcat( str, JPILOT_DBHOME_FILE );
+ strncat( str, JPILOT_DBHOME_DIR, WORK_BUFLEN - strlen(str) );
+ strncat( str, G_DIR_SEPARATOR_S, WORK_BUFLEN - strlen(str) );
+ strncat( str, JPILOT_DBHOME_FILE, WORK_BUFLEN - strlen(str) );
/* Attempt to open */
- if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+ if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
fclose( fp );
}
else {
return g_strdup( str );
}
-/**
- * Attempt to read file, testing for valid JPilot format.
- * \param fileSpec File specification to read.
- * \return <i>TRUE<i> if file appears to be valid format.
- */
-gint jpilot_test_read_file( const gchar *fileSpec ) {
- JPilotFile *pilotFile;
- gint retVal;
-
- if( fileSpec ) {
- pilotFile = jpilot_create_path( fileSpec );
- retVal = jpilot_read_metadata( pilotFile );
- jpilot_free( pilotFile );
- pilotFile = NULL;
- }
- else {
- retVal = MGU_NO_FILE;
- }
- return retVal;
-}
-
/**
* Check whether label is in list of custom labels.
* \param pilotFile JPilot control data.
gboolean retVal;
GList *node;
- g_return_val_if_fail( pilotFile != NULL, FALSE );
+ cm_return_val_if_fail( pilotFile != NULL, FALSE );
retVal = FALSE;
if( labelName ) {