Changeset 2114

Show
Ignore:
Timestamp:
06/09/07 16:13:08 (1 year ago)
Author:
dgollub
Message:

Update the XMLFormat to gnokii-contact converter to new
XMLFormat-contact layout.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/gnokii-sync/src/SConscript

    r2107 r2114  
    1111gnokii_sync = env.SharedLibrary('gnokii-sync', ['gnokii_sync.c', 'gnokii_calendar.c', 'gnokii_contact.c', 'gnokii_config.c', 'gnokii_comm.c'], LIBS = ['opensync', 'gnokii'], LIBPATH = '$prefix/$libsuffix') 
    1212gnokii_event = env.SharedLibrary('gnokii-event', ['gnokii_calendar_format.c'], LIBS = ['opensync'], LIBPATH = '$prefix/$libsuffix') 
    13 gnokii_contact = env.SharedLibrary('gnokii-contact', ['gnokii_contact_format.c'], LIBS = ['opensync'], LIBPATH = '$prefix/$libsuffix') 
     13gnokii_contact = env.SharedLibrary('gnokii-contact', ['gnokii_contact_format.c', 'gnokii_contact_utils.c'], LIBS = ['opensync'], LIBPATH = '$prefix/$libsuffix') 
    1414 
    1515 
  • plugins/gnokii-sync/src/gnokii_contact.c

    r2103 r2114  
    536536 
    537537        // Get changed contact note 
    538         contact = (gn_phonebook_entry *) osync_change_get_data(change); 
     538        osync_data_get_data(osync_change_get_data(change), &contact, NULL); 
    539539 
    540540        // Check for type of changes 
  • plugins/gnokii-sync/src/gnokii_contact_format.c

    r2103 r2114  
    216216} 
    217217 
     218static void _xmlfield_formattedname(gn_phonebook_entry *contact, OSyncXMLField *xmlfield) 
     219{ 
     220        const char *name = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     221        strncpy(contact->name, name, GN_PHONEBOOK_NAME_MAX_LENGTH); 
     222} 
     223 
     224static void _xmlfield_telephone(gn_phonebook_entry *contact, OSyncXMLField *xmlfield, int *subcount) 
     225{ 
     226        const char *tele = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     227 
     228        char *number = gnokii_contact_util_cleannumber(tele); 
     229        strncpy(contact->subentries[*subcount].data.number, number, GN_PHONEBOOK_NAME_MAX_LENGTH); 
     230        g_free(number); 
     231 
     232        contact->subentries[*subcount].entry_type = GN_PHONEBOOK_ENTRY_Number; 
     233 
     234        const char *type = osync_xmlfield_get_attr(xmlfield, "Type"); 
     235        const char *location = osync_xmlfield_get_attr(xmlfield, "Location"); 
     236 
     237        if (location && !strcasecmp(location, "Work")) 
     238                contact->subentries[*subcount].number_type = GN_PHONEBOOK_NUMBER_Work;  
     239        else if (location && !strcasecmp(location, "Home")) 
     240                contact->subentries[*subcount].number_type = GN_PHONEBOOK_NUMBER_Home;  
     241        else if (type && !strcasecmp(type, "Fax")) 
     242                contact->subentries[*subcount].number_type = GN_PHONEBOOK_NUMBER_Fax;  
     243        else if (type && !strcasecmp(type, "Cellular")) 
     244                contact->subentries[*subcount].number_type = GN_PHONEBOOK_NUMBER_Mobile;  
     245        else 
     246                contact->subentries[*subcount].number_type = GN_PHONEBOOK_NUMBER_General; 
     247 
     248        (*subcount)++; 
     249} 
     250 
     251static void _xmlfield_url(gn_phonebook_entry *contact, OSyncXMLField *xmlfield, int *subcount) 
     252{ 
     253        const char *url = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     254 
     255        contact->subentries[*subcount].entry_type = GN_PHONEBOOK_ENTRY_URL; 
     256        strncpy(contact->subentries[*subcount].data.number, url, GN_PHONEBOOK_NAME_MAX_LENGTH); 
     257        (*subcount)++; 
     258} 
     259 
     260static void _xmlfield_email(gn_phonebook_entry *contact, OSyncXMLField *xmlfield, int *subcount) 
     261{ 
     262        const char *email = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     263        contact->subentries[*subcount].entry_type = GN_PHONEBOOK_ENTRY_Email; 
     264        strncpy(contact->subentries[*subcount].data.number, email, GN_PHONEBOOK_NAME_MAX_LENGTH); 
     265 
     266        (*subcount)++; 
     267} 
     268 
     269static void _xmlfield_note(gn_phonebook_entry *contact, OSyncXMLField *xmlfield, int *subcount) 
     270{ 
     271        const char *note = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     272 
     273        contact->subentries[*subcount].entry_type = GN_PHONEBOOK_ENTRY_Note; 
     274        strncpy(contact->subentries[*subcount].data.number, note, GN_PHONEBOOK_NAME_MAX_LENGTH); 
     275        (*subcount)++; 
     276} 
     277 
     278static void _xmlfield_addresslabel(gn_phonebook_entry *contact, OSyncXMLField *xmlfield, int *subcount) 
     279{ 
     280        const char *label = osync_xmlfield_get_key_value(xmlfield, "Content"); 
     281        contact->subentries[*subcount].entry_type = GN_PHONEBOOK_ENTRY_Postal; 
     282        strncpy(contact->subentries[*subcount].data.number, label, GN_PHONEBOOK_NAME_MAX_LENGTH);  
     283        (*subcount)++; 
     284} 
     285 
     286static void _xmlfield_category(gn_phonebook_entry *contact, OSyncXMLField *xmlfield) 
     287{ 
     288        contact->caller_group = GN_PHONEBOOK_GROUP_None;  
     289 
     290        int i; 
     291        int numnodes = osync_xmlfield_get_key_count(xmlfield); 
     292        for (i=0; i < numnodes; i++) { 
     293                const char *category = osync_xmlfield_get_nth_key_value(xmlfield, i); 
     294                 
     295                if (!strcasecmp(category, "FAMILY")) { 
     296                        contact->caller_group = GN_PHONEBOOK_GROUP_Family;  
     297                } else if (!strcasecmp(category, "VIPS") || !strcasecmp(category, "VIP")) { // FIXME: evo2-sync workaround fix that in vformat plugin 
     298                        contact->caller_group = GN_PHONEBOOK_GROUP_Vips; 
     299                } else if (!strcasecmp(category, "FRIENDS")) { 
     300                        contact->caller_group = GN_PHONEBOOK_GROUP_Friends; 
     301                } else if (!strcasecmp(category, "WORK")) { 
     302                        contact->caller_group = GN_PHONEBOOK_GROUP_Work; 
     303                } else if (!strcasecmp(category, "OTHERS")) { 
     304                        contact->caller_group = GN_PHONEBOOK_GROUP_Others; 
     305                } 
     306 
     307        } 
     308} 
     309 
     310 
     311 
    218312/*  
    219313 * Converts from XML to the gnokii contact object type (gn_phonebook_entry). 
     
    224318                        output, outpsize, free_input, config, error); 
    225319 
    226         osync_trace(TRACE_SENSITIVE, "Input XML is:\n%s", osxml_write_to_string((xmlDoc *)input)); 
    227  
    228         char *tmp = NULL, *number = NULL; 
    229         xmlNode *cur = NULL; 
    230         xmlNode *sub = NULL; 
    231         xmlNode *root = xmlDocGetRootElement((xmlDoc *)input); 
    232         xmlXPathObject *xobj = NULL;  
    233         xmlNodeSet *nodes = NULL;  
    234         int numnodes = 0; 
     320        OSyncXMLFormat *xmlformat = (OSyncXMLFormat *)input; 
     321        unsigned int size; 
     322        char *str; 
     323        osync_xmlformat_assemble(xmlformat, &str, &size); 
     324        osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); 
     325        g_free(str); 
     326 
    235327        int subcount = 0; 
    236         int i; 
    237  
    238  
    239         if (!root) { 
    240                 osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get xml root element"); 
     328 
     329        // prepare contact  
     330        gn_phonebook_entry *contact = osync_try_malloc0(sizeof(gn_phonebook_entry), error); 
     331 
     332        if (strcmp("contact", osync_xmlformat_get_objtype(xmlformat))) { 
     333                osync_error_set(error, OSYNC_ERROR_GENERIC, "Wrong xmlformat: %s",  osync_xmlformat_get_objtype(xmlformat)); 
    241334                goto error; 
    242335        } 
    243336 
    244         if (xmlStrcmp(root->name, (const xmlChar *) "contact")) { 
    245                 osync_error_set(error, OSYNC_ERROR_GENERIC, "Wrong (contact) xml root element"); 
    246                 goto error; 
    247         } 
    248  
    249         // prepare contact  
    250         gn_phonebook_entry *contact = NULL; 
    251         contact = (gn_phonebook_entry *) malloc(sizeof(gn_phonebook_entry)); 
    252  
    253         memset(contact, 0, sizeof(gn_phonebook_entry)); 
    254  
    255         // FormattedName - XXX Also Node "Name"? 
    256          cur = osxml_get_node(root, "FormattedName"); 
    257          if (cur) { 
    258                  tmp = (char *) xmlNodeGetContent(cur); 
    259                  strncpy(contact->name, tmp, GN_PHONEBOOK_NAME_MAX_LENGTH); 
    260                  g_free(tmp); 
    261          } 
    262          
    263         // Telephone 
    264         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/Telephone"); 
    265         nodes = xobj->nodesetval; 
    266         numnodes = (nodes) ? nodes->nodeNr : 0; 
    267  
    268         for (i=0; i < numnodes; i++) { 
    269                 cur = nodes->nodeTab[i]; 
    270                 contact->subentries[subcount].entry_type = GN_PHONEBOOK_ENTRY_Number; 
    271                  
    272                 sub = osxml_get_node(cur, "Content"); 
    273                 tmp = (char *) xmlNodeGetContent(sub); 
    274                 number = gnokii_contact_util_cleannumber(tmp); 
    275                 strncpy(contact->subentries[subcount].data.number, number, GN_PHONEBOOK_NAME_MAX_LENGTH); 
    276                 g_free(tmp); 
    277                 g_free(number); 
    278  
    279                 sub = osxml_get_node(cur, "Type"); 
    280                 if (sub) { 
    281                         tmp = (char *) xmlNodeGetContent(sub); 
    282                         if (!strcasecmp(tmp, "Work")) 
    283                                 contact->subentries[subcount].number_type = GN_PHONEBOOK_NUMBER_Work;  
    284                         else if (!strcasecmp(tmp, "Home")) 
    285                                 contact->subentries[subcount].number_type = GN_PHONEBOOK_NUMBER_Home;  
    286                         else if (!strcasecmp(tmp, "Fax")) 
    287                                 contact->subentries[subcount].number_type = GN_PHONEBOOK_NUMBER_Fax;  
    288                         else if (!strcasecmp(tmp, "Cellular")) 
    289                                 contact->subentries[subcount].number_type = GN_PHONEBOOK_NUMBER_Mobile;  
    290                         else 
    291                                 contact->subentries[subcount].number_type = GN_PHONEBOOK_NUMBER_General; 
    292  
    293                         g_free(tmp); 
    294                 } 
    295                 subcount++; 
    296         } 
    297         xmlXPathFreeObject(xobj); 
    298  
    299         // URL  
    300         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/Url"); 
    301         nodes = xobj->nodesetval; 
    302         numnodes = (nodes) ? nodes->nodeNr : 0; 
    303  
    304         for (i=0; i < numnodes; i++) { 
    305                 cur = nodes->nodeTab[i]; 
    306  
    307                 contact->subentries[subcount].entry_type = GN_PHONEBOOK_ENTRY_URL; 
    308  
    309                 sub = osxml_get_node(cur, "Content"); 
    310                  
    311                 tmp = (char *) xmlNodeGetContent(sub); 
    312                 strncpy(contact->subentries[subcount].data.number, tmp, GN_PHONEBOOK_NAME_MAX_LENGTH); 
    313                 g_free(tmp); 
    314  
    315                 subcount++; 
    316         } 
    317         xmlXPathFreeObject(xobj); 
    318  
    319         // EMail 
    320         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/EMail"); 
    321         nodes = xobj->nodesetval; 
    322         numnodes = (nodes) ? nodes->nodeNr : 0; 
    323  
    324         for (i=0; i < numnodes; i++) { 
    325                 cur = nodes->nodeTab[i]; 
    326  
    327                 contact->subentries[subcount].entry_type = GN_PHONEBOOK_ENTRY_Email; 
    328                 sub = osxml_get_node(cur, "Content"); 
    329  
    330                 tmp = (char *) xmlNodeGetContent(sub); 
    331                 strncpy(contact->subentries[subcount].data.number, tmp, GN_PHONEBOOK_NAME_MAX_LENGTH); 
    332                 g_free(tmp); 
    333  
    334                 subcount++; 
    335         } 
    336         xmlXPathFreeObject(xobj); 
    337  
    338         // Note  
    339         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/Note"); 
    340         nodes = xobj->nodesetval; 
    341         numnodes = (nodes) ? nodes->nodeNr : 0; 
    342  
    343         for (i=0; i < numnodes; i++) { 
    344                 cur = nodes->nodeTab[i]; 
    345  
    346                 contact->subentries[subcount].entry_type = GN_PHONEBOOK_ENTRY_Note; 
    347                 sub = osxml_get_node(cur, "Content"); 
    348                 tmp = (char *) xmlNodeGetContent(sub); 
    349                 strncpy(contact->subentries[subcount].data.number, tmp, GN_PHONEBOOK_NAME_MAX_LENGTH); 
    350                 g_free(tmp); 
    351  
    352                 subcount++; 
    353         } 
    354         xmlXPathFreeObject(xobj); 
    355  
    356         // Category / Callergroup 
    357         // TODO - fix category - group  
    358         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/Categories"); 
    359         nodes = xobj->nodesetval; 
    360         numnodes = (nodes) ? nodes->nodeNr : 0; 
    361  
    362         osync_trace(TRACE_INTERNAL, "categories: %i", numnodes); 
    363  
    364         contact->caller_group = GN_PHONEBOOK_GROUP_None;  
    365         for (i=0; i < numnodes; i++) { 
    366                 cur = nodes->nodeTab[i]; 
    367                  
    368                 tmp = (char *) xmlNodeGetContent(cur); 
    369                 if (!strcasecmp(tmp, "FAMILY")) { 
    370                         contact->caller_group = GN_PHONEBOOK_GROUP_Family;  
    371                 } else if (!strcasecmp(tmp, "VIPS") || !strcasecmp(tmp, "VIP")) {       // we handle VIP and VIPs as VIP type needed for evo2  
    372                         contact->caller_group = GN_PHONEBOOK_GROUP_Vips; 
    373                 } else if (!strcasecmp(tmp, "FRIENDS")) { 
    374                         contact->caller_group = GN_PHONEBOOK_GROUP_Friends; 
    375                 } else if (!strcasecmp(tmp, "WORK")) { 
    376                         contact->caller_group = GN_PHONEBOOK_GROUP_Work; 
    377                 } else if (!strcasecmp(tmp, "OTHERS")) { 
    378                         contact->caller_group = GN_PHONEBOOK_GROUP_Others; 
    379                 } 
    380  
    381                 g_free(tmp); 
    382         } 
    383         xmlXPathFreeObject(xobj); 
    384  
    385         // TODO: Addresss, Organization?, Group  
    386  
    387         // Adress 
    388         xobj = osxml_get_nodeset((xmlDoc *)input, "/contact/AddressLabel"); 
    389         nodes = xobj->nodesetval; 
    390         numnodes = (nodes) ? nodes->nodeNr : 0; 
    391         for (i=0; i < numnodes; i++) { 
    392                 cur = nodes->nodeTab[i]; 
    393                  
    394                 contact->subentries[subcount].entry_type = GN_PHONEBOOK_ENTRY_Postal; 
    395  
    396                 sub = osxml_get_node(cur, "Content"); 
    397  
    398                 if (sub) {  
    399                         tmp = (char *) xmlNodeGetContent(sub); 
    400                         strncpy(contact->subentries[subcount].data.number, tmp, GN_PHONEBOOK_NAME_MAX_LENGTH);  
    401                         g_free(tmp); 
    402                 } 
    403  
    404                 subcount++; 
    405         } 
    406         xmlXPathFreeObject(xobj); 
     337        OSyncXMLField *xmlfield = osync_xmlformat_get_first_field(xmlformat); 
     338        for (; xmlfield; xmlfield = osync_xmlfield_get_next(xmlfield)) { 
     339                osync_trace(TRACE_INTERNAL, "Field: %s", osync_xmlfield_get_name(xmlfield)); 
     340 
     341                if (!strcmp("FormattedName", osync_xmlfield_get_name(xmlfield))) 
     342                        _xmlfield_formattedname(contact, xmlfield); 
     343                else if (!strcmp("Telephone", osync_xmlfield_get_name(xmlfield))) 
     344                        _xmlfield_telephone(contact, xmlfield, &subcount); 
     345                else if (!strcmp("Url", osync_xmlfield_get_name(xmlfield))) 
     346                        _xmlfield_url(contact, xmlfield, &subcount); 
     347                else if (!strcmp("EMail", osync_xmlfield_get_name(xmlfield))) 
     348                        _xmlfield_email(contact, xmlfield, &subcount); 
     349                else if (!strcmp("Note", osync_xmlfield_get_name(xmlfield))) 
     350                        _xmlfield_note(contact, xmlfield, &subcount); 
     351                else if (!strcmp("AddressLabel", osync_xmlfield_get_name(xmlfield))) 
     352                        _xmlfield_addresslabel(contact, xmlfield, &subcount); 
     353                else if (!strcmp("Categories", osync_xmlfield_get_name(xmlfield))) 
     354                        _xmlfield_category(contact, xmlfield); 
     355        } 
     356 
     357 
     358 
    407359 
    408360        contact->subentries_count = subcount;