static void addrconduit_destroy_record (EAddrLocalRecord *local) { g_object_unref (local->contact); free_Address (local->addr); g_free (local->addr); g_free (local); }
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; }
/*********************************************************************** * * 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; }
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)); }
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; }
/** * Unpack address, building new data inside cache. * \param pilotFile JPilot control data. * \param buf Record buffer. * \param folderInd Array of (category) folders to load. */ 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 ]; ItemPerson *person; gint *indPhoneLbl; gchar *labelEntry; GList *node; gchar* extID; struct AddressAppInfo *ai; gchar **firstName = NULL; gchar **lastName = NULL; /* 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; *fullName = '\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 ); if( convert_charcode ) { gchar *nameConv; nameConv = g_strdup( fullName ); conv_sjistoeuc( fullName, FULLNAME_BUFSIZE, 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; /* 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 ]; jpilot_parse_label( pilotFile, labelEntry, person ); } } /* Add entry for each custom label */ node = pilotFile->labelInd; while( node ) { gchar convertBuff[JPILOT_LEN_LABEL]; 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 ); } 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 pointer allocated inside address */ free_Address( & addr ); }