Changeset 2439

Show
Ignore:
Timestamp:
08/11/07 09:05:56 (1 year ago)
Author:
paule
Message:

Fix code for converting todos, events & notes for xmlformat changes. Largely untested and alarm conversion code not complete due to vformat plugin not yet being finished.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/opie-sync/src/opie_format.c

    r2436 r2439  
    339339 
    340340        if (osync_xmlformat_validate(out_xmlformat) == FALSE) 
    341                                        osync_trace(TRACE_INTERNAL, "XMLFORMAT CONTACT: Not valid!"); 
     341                osync_trace(TRACE_INTERNAL, "XMLFORMAT CONTACT: Not valid!"); 
    342342        else 
    343                                        osync_trace(TRACE_INTERNAL, "XMLFORMAT CONTACT: VAILD"); 
     343                osync_trace(TRACE_INTERNAL, "XMLFORMAT CONTACT: VALID"); 
    344344 
    345345        osync_trace(TRACE_EXIT, "%s", __func__); 
     
    573573        osync_trace(TRACE_ENTRY, "%s(%p, %p, %i, %p, %p, %p, %p)", __func__, input, inpsize, output, outpsize, free_input, config, error); 
    574574        struct _xmlAttr *iprop; 
    575         xmlNode *on_curr; 
    576575        int j; 
     576        OSyncXMLField *out_xmlfield = NULL; 
    577577                 
    578578        /* Get the root node of the input document */ 
     
    590590         
    591591        /* Create a new output xml document */ 
    592         xmlDoc *odoc = xmlNewDoc((xmlChar*)"1.0"); 
    593         xmlNode *on_root = osxml_node_add_root(odoc, "vcal"); 
    594         on_root = xmlNewTextChild(on_root, NULL, (xmlChar*)"Todo", NULL); 
     592        OSyncXMLFormat *out_xmlformat = osync_xmlformat_new("todo", error); 
    595593         
    596594        if(!strcasecmp(icur->name, "Task")) 
     
    603601                                if(!strcasecmp(iprop->name, "Summary"))  
    604602                                { 
    605                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Summary", NULL); 
    606                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     603                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Summary", error); 
     604                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    607605                                } 
    608606                                else if(!strcasecmp(iprop->name, "Description")) 
    609607                                { 
    610                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Description", NULL); 
    611                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     608                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Description", error); 
     609                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    612610                                } 
    613611                                else if(!strcasecmp(iprop->name, "Priority")) 
     
    616614                                        int priority = atoi(iprop->children->content); 
    617615                                        char *prio = g_strdup_printf("%d", priority); 
    618                                         on_curr = xmlNewTextChild(on_root, NULL, (xmlChar*)"Priority", NULL); 
    619                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)prio); 
     616                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Priority", error); 
     617                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", prio); 
    620618                                        g_free(prio); 
    621619                                } 
    622620                                else if(!strcasecmp(iprop->name, "Progress")) 
    623621                                { 
    624                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"PercentComplete", NULL); 
    625                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     622                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "PercentComplete", error); 
     623                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    626624                                } 
    627625                                else if(!strcasecmp(iprop->name, "State")) 
     
    643641                                                        status = "NEEDS-ACTION"; 
    644642                                        } 
    645                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Status", NULL); 
    646                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)status); 
     643                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Status", error); 
     644                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    647645                                } 
    648646                                else if(!strcasecmp(iprop->name, "StartDate")) 
    649647                                { 
    650                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"DateStarted", NULL); 
    651                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
    652                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Value", (xmlChar*)"DATE"); 
     648                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "DateStarted", error); 
     649                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
     650                                        osync_xmlfield_set_key_value(out_xmlfield, "Value", "DATE"); /* FIXME I doubt this is still valid */ 
    653651                                } 
    654652                                else if(!strcasecmp(iprop->name, "Uid")) 
    655653                                { 
    656                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Uid", NULL); 
    657                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     654                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Uid", error); 
     655                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    658656                                } 
    659657                                else if(!strcasecmp(iprop->name, "Categories")) 
    660658                                { 
    661659                                        gchar** categorytokens = g_strsplit(iprop->children->content, "|", 0); 
    662                                         xmlNode *on_categories = xmlNewTextChild(on_root, NULL, (xmlChar*)"Categories", NULL); 
     660                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Categories", error); 
    663661                                        for(j=0;categorytokens[j]!=NULL;j++)  
    664662                                        { 
    665                                                 xmlNewTextChild(on_categories, NULL, (xmlChar*)"Category", (xmlChar*)categorytokens[j]); 
     663                                                osync_xmlfield_add_key_value(out_xmlfield, "Category", categorytokens[j]); 
    666664                                        } 
    667665                                        g_strfreev(categorytokens); 
     
    676674                                char *completeDate = xmlGetProp(icur, "CompletedDate"); 
    677675                                if(completeDate) {  
    678                                         on_curr = xmlNewTextChild(on_root, NULL, (xmlChar*)"Completed", NULL); 
    679                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)completeDate); 
     676                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Completed", error); 
     677                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", completeDate); 
    680678                                        // RFC2445 says the default value type is DATE-TIME. But Opie only 
    681679                                        // stores DATE as completed date => alter VALUE to DATE 
    682                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Value", (xmlChar*)"DATE"); 
     680                                        osync_xmlfield_set_key_value(out_xmlfield, "Value", "DATE"); /* FIXME I doubt this is still valid */ 
    683681                                        xmlFree(completeDate); 
    684682                                } 
     
    701699                                        char *duedatestr = g_strdup_printf("%04d%02d%02d", dateyear, datemonth, dateday); 
    702700                                        duedate = g_date_new_dmy(dateday, datemonth, dateyear); 
    703                                         on_curr = xmlNewTextChild(on_root, NULL, (xmlChar*)"DateDue", NULL); 
    704                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)duedatestr); 
     701                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "DateDue", error); 
     702                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", duedatestr); 
    705703                                        g_free(duedatestr); 
    706704                                        // RFC2445 says the default value type is DATE-TIME. But Opie only 
    707705                                        // stores DATE as due date => alter VALUE to DATE 
    708                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Value", (xmlChar*)"DATE"); 
     706                                        osync_xmlfield_set_key_value(out_xmlfield, "Value", "DATE"); /* FIXME I doubt this is still valid */ 
    709707                                } 
    710708                                if(datedaystr)   xmlFree(datedaystr); 
     
    716714         
    717715                /* Recurrence */ 
    718                 xml_recur_attr_to_node(icur, on_root, duedate); 
     716                xml_recur_attr_to_xmlfield(icur, out_xmlformat, duedate, error); 
    719717                 
    720718                /* Alarms */ 
    721719                char *alarmstr = xmlGetProp(icur, "Alarms"); 
    722720                if(alarmstr) { 
    723                         xml_todo_alarm_attr_to_node(alarmstr, on_root, NULL); 
     721                        xml_todo_alarm_attr_to_xmlfield(alarmstr, out_xmlformat, NULL, error); 
    724722                        xmlFree(alarmstr); 
    725723                } 
     
    730728 
    731729        *free_input = TRUE; 
    732         *output = (char *)odoc
    733         *outpsize = sizeof(odoc); 
     730        *output = (char *)out_xmlformat
     731        *outpsize = sizeof(out_xmlformat); 
    734732         
    735733        xmlFreeDoc(idoc); 
    736734 
    737         osync_trace(TRACE_INTERNAL, "Output XML is:\n%s", osxml_write_to_string((xmlDoc *)odoc)); 
     735        // FIXME: remove this later? 
     736        osync_xmlformat_sort(out_xmlformat); 
     737         
     738        unsigned int size; 
     739        char *str; 
     740        osync_xmlformat_assemble(out_xmlformat, &str, &size); 
     741        osync_trace(TRACE_INTERNAL, "Output XMLFormat is:\n%s", str); 
     742        g_free(str); 
     743 
     744        if (osync_xmlformat_validate(out_xmlformat) == FALSE) 
     745                osync_trace(TRACE_INTERNAL, "XMLFORMAT TODO: Not valid!"); 
     746        else 
     747                osync_trace(TRACE_INTERNAL, "XMLFORMAT TODO: VALID"); 
    738748         
    739749        osync_trace(TRACE_EXIT, "%s", __func__); 
     
    750760static osync_bool conv_xml_todo_to_opie_xml_todo(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, OSyncError **error) 
    751761{ 
    752         xmlNode *icur; 
     762        const char *completedstr = NULL; 
     763        const char *startedstr = NULL; 
     764        const char *duestr = NULL; 
     765                         
    753766        osync_trace(TRACE_ENTRY, "%s(%p, %p, %i, %p, %p, %p, %p)",  
    754767                                                        __func__, input, inpsize, output,  
    755768                                                        outpsize, free_input, config, error); 
    756769 
    757         osync_trace(TRACE_INTERNAL, "Input XML is:\n%s",  
    758                                                         osxml_write_to_string((xmlDoc *)input)); 
    759          
    760         /* Get the root node of the input document */ 
    761         xmlNode *root = xmlDocGetRootElement((xmlDoc *)input); 
    762         if (!root) { 
    763                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    764                                                                                 "Unable to get xml root element"); 
     770        OSyncXMLFormat *in_xmlformat = (OSyncXMLFormat *)input; 
     771        unsigned int size; 
     772        char *str; 
     773        osync_xmlformat_assemble(in_xmlformat, &str, &size); 
     774        osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); 
     775        g_free(str); 
     776 
     777        if (strcmp("todo", osync_xmlformat_get_objtype(in_xmlformat))) { 
     778                osync_error_set(error, OSYNC_ERROR_GENERIC, "Wrong xmlformat: %s",  osync_xmlformat_get_objtype(in_xmlformat)); 
    765779                goto error; 
    766780        } 
    767          
    768         if (xmlStrcmp(root->name, (const xmlChar *)"vcal")) { 
    769                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    770                                                                                 "Wrong xml root element"); 
    771                 goto error; 
    772         } 
    773  
    774         root = osxml_get_node(root, "Todo"); 
    775         if (!root) { 
    776                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    777                                                                                 "Unable to find Todo node inside vcal node"); 
    778                 goto error; 
    779         } 
    780          
     781 
    781782        /* Create a new output xml document */ 
    782783        xmlDoc *odoc = xmlNewDoc((xmlChar*)"1.0"); 
    783784        xmlNode *on_todo = osxml_node_add_root(odoc, "Task"); 
    784785         
    785         /* Summary */ 
    786         icur = osxml_get_node(root, "Summary"); 
    787         if (icur) { 
    788                 xml_node_to_attr(icur, "Content", on_todo, "Summary"); 
    789         } 
    790  
    791         /* Description */ 
    792         icur = osxml_get_node(root, "Description"); 
    793         if (icur) { 
    794                 xml_node_to_attr(icur, "Content", on_todo, "Description"); 
    795         } 
    796  
    797         /* Priority */ 
    798         icur = osxml_get_node(root, "Priority"); 
    799         if (icur) { 
    800                 /* Priority is 1-5 on Opie, 0-9 in OpenSync XML (0 = undefined) */ 
    801                 icur = osxml_get_node(icur, "Content"); 
    802                 if (icur) { 
    803                         char *prio = (char *)xmlNodeGetContent(icur); 
     786        OSyncXMLField *in_xmlfield = osync_xmlformat_get_first_field(in_xmlformat); 
     787        while(in_xmlfield) { 
     788                const char *fieldname = osync_xmlfield_get_name(in_xmlfield); 
     789                if(!strcmp("Summary", fieldname)) { 
     790                        xmlfield_key_to_attr(in_xmlfield, "Content", on_todo, "Summary"); 
     791                } 
     792                else if(!strcmp("Description", fieldname)) { 
     793                        xmlfield_key_to_attr(in_xmlfield, "Content", on_todo, "Description"); 
     794                } 
     795                else if(!strcmp("Priority", fieldname)) { 
     796                        /* Priority is 1-5 on Opie, 0-9 in OpenSync XML (0 = undefined) */ 
     797                        const char *prio = osync_xmlfield_get_key_value(in_xmlfield, "Content"); 
    804798                        if (prio) { 
    805799                                int priority = atoi(prio); 
    806                                 xmlFree(prio); 
    807800                                if (priority < 1) { 
    808801                                        /* Invalid or (more likely) unspecified priority */ 
     
    812805                                        priority = 5; 
    813806                                } 
    814                                 prio = g_strdup_printf("%d", priority); 
    815                                 xmlSetProp(on_todo, "Priority", prio); 
    816                                 g_free(prio); 
    817                         } 
    818                 } 
    819         } 
    820          
    821         /* Completed */ 
    822         icur = osxml_get_node(root, "Completed"); 
    823         if (icur) { 
    824                 icur = osxml_get_node(icur, "Content"); 
    825                 if (icur) { 
    826                         char *completedstr = (char *) xmlNodeGetContent(icur); 
    827                         struct tm *completed = osync_time_vtime2tm(completedstr); 
    828                         xmlFree(completedstr); 
    829                         completedstr = g_strdup_printf("%04d%02d%02d", completed->tm_year + 1900, (completed->tm_mon + 1), completed->tm_mday); 
    830                         xmlSetProp(on_todo, "Completed", "1"); 
    831                         xmlSetProp(on_todo, "CompletedDate", completedstr); 
    832                         g_free(completedstr); 
    833                         g_free(completed); 
    834                 } 
    835         } 
    836         else { 
     807                                char *prio_str = g_strdup_printf("%d", priority); 
     808                                xmlSetProp(on_todo, "Priority", prio_str); 
     809                                g_free(prio_str); 
     810                        } 
     811                } 
     812                else if(!strcmp("Categories", fieldname)) { 
     813                        xmlfield_categories_to_attr(in_xmlfield, on_todo, "Categories"); 
     814                } 
     815                else if(!strcmp("Completed", fieldname)) { 
     816                        completedstr = osync_xmlfield_get_key_value(in_xmlfield, "Content"); 
     817                        if(completedstr) { 
     818                                struct tm *completed = osync_time_vtime2tm(completedstr); 
     819                                char *completedstr_out = g_strdup_printf("%04d%02d%02d", completed->tm_year + 1900, (completed->tm_mon + 1), completed->tm_mday); 
     820                                xmlSetProp(on_todo, "Completed", "1"); 
     821                                xmlSetProp(on_todo, "CompletedDate", completedstr_out); 
     822                                g_free(completedstr_out); 
     823                                g_free(completed); 
     824                        } 
     825                } 
     826                else if(!strcmp("DateStarted", fieldname)) { 
     827                        startedstr = osync_xmlfield_get_key_value(in_xmlfield, "Content"); 
     828                        if(startedstr) { 
     829                                struct tm *started = osync_time_vtime2tm(startedstr); 
     830                                char *startedstr_out = g_strdup_printf("%04d%02d%02d", (started->tm_year + 1900), (started->tm_mon + 1), started->tm_mday); 
     831                                xmlSetProp(on_todo, "StartDate", startedstr_out); 
     832                                g_free(startedstr_out); 
     833                                g_free(started); 
     834                        } 
     835                } 
     836                else if(!strcmp("DateDue", fieldname)) { 
     837                        duestr = osync_xmlfield_get_key_value(in_xmlfield, "Content"); 
     838                        if(duestr) { 
     839                                struct tm *due = osync_time_vtime2tm(duestr); 
     840                                char *dueyear  = g_strdup_printf("%04d", (due->tm_year + 1900)); 
     841                                char *duemonth = g_strdup_printf("%02d", (due->tm_mon + 1)); 
     842                                char *dueday   = g_strdup_printf("%02d", due->tm_mday); 
     843                                xmlSetProp(on_todo, "HasDate",   "1"); 
     844                                xmlSetProp(on_todo, "DateYear",  dueyear); 
     845                                xmlSetProp(on_todo, "DateMonth", duemonth); 
     846                                xmlSetProp(on_todo, "DateDay",   dueday); 
     847                                g_free(dueyear); 
     848                                g_free(duemonth); 
     849                                g_free(dueday); 
     850                                g_free(due); 
     851                        } 
     852                } 
     853                else if(!strcmp("PercentComplete", fieldname)) { 
     854                        xmlfield_key_to_attr(in_xmlfield, "Content", on_todo, "Progress"); 
     855                } 
     856                else if(!strcmp("Status", fieldname)) { 
     857                        const char *status = osync_xmlfield_get_key_value(in_xmlfield, "Content"); 
     858                        if(status) { 
     859                                int state; 
     860                                if(!strcasecmp(status, "IN-PROCESS")) { 
     861                                        state = OPIE_TODO_STATE_NOT_STARTED; 
     862                                } 
     863                                else if (!strcasecmp(status, "CANCELLED")) { 
     864                                        state = OPIE_TODO_STATE_POSTPONED; 
     865                                } 
     866                                else if (!strcasecmp(status, "COMPLETED")) { 
     867                                        state = OPIE_TODO_STATE_FINISHED; 
     868                                } 
     869                                else { 
     870                                        state = OPIE_TODO_STATE_NOT_STARTED; 
     871                                } 
     872                                char *statestr = g_strdup_printf("%d", state); 
     873                                xmlSetProp(on_todo, "State", statestr);  
     874                                g_free(statestr); 
     875                        } 
     876                } 
     877                else if(!strcmp("Uid", fieldname)) { 
     878                        xmlfield_key_to_attr(in_xmlfield, "Content", on_todo, "Uid"); 
     879                } 
     880                else if(!strcmp("RecurrenceRule", fieldname)) { 
     881                        xmlfield_recur_to_attr(in_xmlfield, on_todo); 
     882                } 
     883                 
     884                in_xmlfield = osync_xmlfield_get_next(in_xmlfield); 
     885        } 
     886         
     887        /* Convert alarms */ 
     888        xmlformat_todo_alarms_to_attr(in_xmlformat, on_todo); 
     889         
     890        if(!completedstr) 
    837891                xmlSetProp(on_todo, "Completed", "0"); 
    838         } 
    839          
    840         /* Start date */ 
    841         icur = osxml_get_node(root, "DateStarted"); 
    842         if (icur) { 
    843                 icur = osxml_get_node(icur, "Content"); 
    844                 if (icur) { 
    845                         char *startedstr = (char *) xmlNodeGetContent(icur); 
    846                         struct tm *started = osync_time_vtime2tm(startedstr); 
    847                         xmlFree(startedstr); 
    848                         startedstr = g_strdup_printf("%04d%02d%02d", (started->tm_year + 1900), (started->tm_mon + 1), started->tm_mday); 
    849                         xmlSetProp(on_todo, "StartDate", startedstr); 
    850                         g_free(startedstr); 
    851                         g_free(started); 
    852                 } 
    853         } 
    854         else { 
     892         
     893        if(!startedstr) 
    855894                xmlSetProp(on_todo, "StartDate", "0"); 
    856         } 
    857          
    858         /* Due date */ 
    859         icur = osxml_get_node(root, "DateDue"); 
    860         if (icur) { 
    861                 icur = osxml_get_node(icur, "Content"); 
    862                 if (icur) { 
    863                         char *duestr = (char *) xmlNodeGetContent(icur); 
    864                         struct tm *due = osync_time_vtime2tm(duestr); 
    865                         xmlFree(duestr); 
    866                         char *dueyear  = g_strdup_printf("%04d", (due->tm_year + 1900)); 
    867                         char *duemonth = g_strdup_printf("%02d", (due->tm_mon + 1)); 
    868                         char *dueday   = g_strdup_printf("%02d", due->tm_mday); 
    869                         xmlSetProp(on_todo, "HasDate",   "1"); 
    870                         xmlSetProp(on_todo, "DateYear",  dueyear); 
    871                         xmlSetProp(on_todo, "DateMonth", duemonth); 
    872                         xmlSetProp(on_todo, "DateDay",   dueday); 
    873                         g_free(dueyear); 
    874                         g_free(duemonth); 
    875                         g_free(dueday); 
    876                         g_free(due); 
    877                 } 
    878         } 
    879         else { 
     895         
     896        if(!duestr) 
    880897                xmlSetProp(on_todo, "HasDate", "0"); 
    881         } 
    882          
    883         /* Progress */   
    884         icur = osxml_get_node(root, "PercentComplete"); 
    885         if (icur) { 
    886                 xml_node_to_attr(icur, "Content", on_todo, "Progress"); 
    887         } 
    888          
    889         /* State */ 
    890         icur = osxml_get_node(root, "Status"); 
    891         if (icur) { 
    892                 icur = osxml_get_node(icur, "Content"); 
    893                 if (icur) { 
    894                         char *status = (char *) xmlNodeGetContent(icur); 
    895                         int state; 
    896                         if(!strcasecmp(status, "IN-PROCESS")) { 
    897                                 state = OPIE_TODO_STATE_NOT_STARTED; 
    898                         } 
    899                         else if (!strcasecmp(status, "CANCELLED")) { 
    900                                 state = OPIE_TODO_STATE_POSTPONED; 
    901                         } 
    902                         else if (!strcasecmp(status, "COMPLETED")) { 
    903                                 state = OPIE_TODO_STATE_FINISHED; 
    904                         } 
    905                         else { 
    906                                 state = OPIE_TODO_STATE_NOT_STARTED; 
    907                         } 
    908                         char *statestr = g_strdup_printf("%d", state); 
    909                         xmlSetProp(on_todo, "State", statestr);  
    910                         g_free(statestr); 
    911                         xmlFree(status); 
    912                 } 
    913         } 
    914          
    915         /* Recurrence */ 
    916         xml_recur_node_to_attr(root, on_todo); 
    917          
    918         /* Alarms */ 
    919         xml_todo_alarm_node_to_attr(root, on_todo); 
    920          
    921         /* Categories */ 
    922         xml_categories_to_attr(root, on_todo, "Categories"); 
    923  
    924         /* UID */ 
    925         icur = osxml_get_node(root, "Uid"); 
    926         if (icur) 
    927                 xml_node_to_attr(icur, "Content", on_todo, "Uid"); 
    928898         
    929899        *free_input = TRUE; 
     
    949919        osync_trace(TRACE_ENTRY, "%s(%p, %p, %i, %p, %p, %p, %p)", __func__, input, inpsize, output, outpsize, free_input, config, error); 
    950920        struct _xmlAttr *iprop; 
    951         xmlNode *on_curr
     921        OSyncXMLField *out_xmlfield = NULL
    952922        GDate *startdate = NULL; 
    953923        int j; 
     
    967937         
    968938        /* Create a new output xml document */ 
    969         xmlDoc *odoc = xmlNewDoc((xmlChar*)"1.0"); 
    970         xmlNode *on_root = osxml_node_add_root(odoc, "vcal"); 
    971         on_root = xmlNewTextChild(on_root, NULL, (xmlChar*)"Event", NULL); 
     939        OSyncXMLFormat *out_xmlformat = osync_xmlformat_new("event", error); 
    972940         
    973941        if(!strcasecmp(icur->name, "event")) 
     
    983951                } 
    984952                 
    985                 /* this is a todo element - the attributes are the data we care about */ 
     953                /* this is an event element - the attributes are the data we care about */ 
    986954                for (iprop = icur->properties; iprop; iprop=iprop->next)  
    987955                { 
     
    990958                                if(!strcasecmp(iprop->name, "description")) 
    991959                                { 
    992                                         xmlNode *on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Summary", NULL); 
    993                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     960                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Summary", error); 
     961                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    994962                                } 
    995963                                else if(!strcasecmp(iprop->name, "note"))  
    996964                                { 
    997                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Description", NULL); 
    998                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     965                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Description", error); 
     966                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    999967                                } 
    1000968                                else if(!strcasecmp(iprop->name, "location"))  
    1001969                                { 
    1002                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Location", NULL); 
    1003                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     970                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Location", error); 
     971                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    1004972                                } 
    1005973                                else if(!strcasecmp(iprop->name, "created"))  
    1006974                                { 
    1007975                                        time_t createtime = (time_t)atoi(iprop->children->content); 
    1008                                         char *createvtime = osync_time_unix2vtime(&createtime);  
    1009                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"DateCreated", NULL); 
    1010                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)createvtime); 
     976                                        char *createvtime = osync_time_unix2vtime(&createtime); 
     977                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "DateCreated", error); 
     978                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    1011979                                        g_free(createvtime); 
    1012980                                } 
    1013981                                else if(!strcasecmp(iprop->name, "start"))  
    1014982                                { 
    1015                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"DateStarted", NULL); 
     983                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "DateStarted", error); 
    1016984                                        time_t starttime = (time_t)atoi(iprop->children->content); 
    1017985                                        if(allday) { 
     
    1019987                                                localtime_r(&starttime, localtm); 
    1020988                                                char *startvdate = g_strdup_printf("%04d%02d%02d", localtm->tm_year + 1900, (localtm->tm_mon + 1), localtm->tm_mday); 
    1021                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)startvdate); 
    1022                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Value", (xmlChar*)"DATE"); 
     989                                                osync_xmlfield_set_key_value(out_xmlfield, "Content", startvdate); 
     990                                                osync_xmlfield_set_key_value(out_xmlfield, "Value", "DATE"); 
    1023991                                                g_free(startvdate); 
    1024992                                                g_free(localtm); 
     
    1026994                                        else { 
    1027995                                                char *startvtime = osync_time_unix2vtime(&starttime);  
    1028                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)startvtime); 
     996                                                osync_xmlfield_set_key_value(out_xmlfield, "Content", startvtime); 
    1029997                                                g_free(startvtime); 
    1030998                                        } 
     
    10431011                                else if(!strcasecmp(iprop->name, "end"))  
    10441012                                { 
    1045                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"DateEnd", NULL); 
     1013                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "DateEnd", error); 
    10461014                                        time_t endtime = (time_t)atoi(iprop->children->content); 
    10471015                                        if(allday) { 
     
    10501018                                                localtime_r(&endtime, localtm); 
    10511019                                                char *endvdate = g_strdup_printf("%04d%02d%02d", localtm->tm_year + 1900, (localtm->tm_mon + 1), localtm->tm_mday); 
    1052                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)endvdate); 
    1053                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Value", (xmlChar*)"DATE"); 
     1020                                                osync_xmlfield_set_key_value(out_xmlfield, "Content", endvdate); 
     1021                                                osync_xmlfield_set_key_value(out_xmlfield, "Value", "DATE"); 
    10541022                                                g_free(endvdate); 
    10551023                                                g_free(localtm); 
    10561024                                        } 
    10571025                                        else { 
    1058                                                 char *endvtime = osync_time_unix2vtime(&endtime);  
    1059                                                 xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)endvtime); 
     1026                                                char *endvtime = osync_time_unix2vtime(&endtime); 
     1027                                                osync_xmlfield_set_key_value(out_xmlfield, "Content", endvtime); 
    10601028                                                g_free(endvtime); 
    10611029                                        } 
     
    10641032                                { 
    10651033                                        gchar** categorytokens = g_strsplit(iprop->children->content, "|", 0); 
    1066                                         xmlNode *on_categories = xmlNewTextChild(on_root, NULL, (xmlChar*)"Categories", NULL); 
     1034                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Categories", error); 
    10671035                                        for(j=0;categorytokens[j]!=NULL;j++)  
    10681036                                        { 
    1069                                                 xmlNewTextChild(on_categories, NULL, (xmlChar*)"Category", (xmlChar*)categorytokens[j]); 
     1037                                                osync_xmlfield_add_key_value(out_xmlfield, "Category", categorytokens[j]); 
    10701038                                        } 
    10711039                                        g_strfreev(categorytokens); 
     
    10731041                                else if(!strcasecmp(iprop->name, "uid"))  
    10741042                                { 
    1075                                         on_curr = xmlNewTextChild( on_root, NULL, (xmlChar*)"Uid", NULL); 
    1076                                         xmlNewTextChild(on_curr, NULL, (xmlChar*)"Content", (xmlChar*)iprop->children->content); 
     1043                                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Uid", error); 
     1044                                        osync_xmlfield_set_key_value(out_xmlfield, "Content", iprop->children->content); 
    10771045                                } 
    10781046                        } 
     
    10851053                char *alarmminsstr = xmlGetProp(icur, "alarm"); 
    10861054                if(alarmminsstr) { 
    1087                         xmlNode *on_alarm = xmlNewTextChild( on_root, NULL, (xmlChar*)"Alarm", NULL); 
     1055                        /* FIXME since alarm support is not complete in the OpenSync xmlformat code, the code  
     1056                           below is not finished */ 
     1057/* 
     1058                        out_xmlfield = osync_xmlfield_new(out_xmlformat, "Alarm", error); 
    10881059                         
    10891060                        int alarmsound = 0; 
     
    10951066                        } 
    10961067                        if(alarmsound == 1) 
    1097                                 xmlNewTextChild( on_alarm, NULL, (xmlChar*)"AlarmAction", (xmlChar*)"AUDIO"); 
     1068                                osync_xmlfield_set_key_value(out_xmlfield, "AlarmAction", "AUDIO"); 
    10981069                        else 
    1099                                 xmlNewTextChild( on_alarm, NULL, (xmlChar*)"AlarmAction", (xmlChar*)"DISPLAY"); 
     1070                                osync_xmlfield_set_key_value(out_xmlfield, "AlarmAction", "DISPLAY"); 
    11001071                         
    11011072                        int alarmseconds = -(atoi(alarmminsstr) * 60); 
     
    11051076                        xmlNewTextChild( on_atrigger, NULL, (xmlChar*)"Value", (xmlChar*)"DURATION"); 
    11061077                        xmlFree(alarmminsstr); 
     1078*/ 
    11071079                } 
    11081080                 
    11091081                /* Recurrence */ 
    1110                 xml_recur_attr_to_node(icur, on_root, startdate); 
     1082                xml_recur_attr_to_xmlfield(icur, out_xmlformat, startdate, error); 
    11111083        } 
    11121084 
    11131085        *free_input = TRUE; 
    1114         *output = (char *)odoc
    1115         *outpsize = sizeof(odoc); 
     1086        *output = (char *)out_xmlformat
     1087        *outpsize = sizeof(out_xmlformat); 
    11161088         
    11171089        xmlFreeDoc(idoc); 
    11181090 
    1119         osync_trace(TRACE_INTERNAL, "Output XML is:\n%s", osxml_write_to_string((xmlDoc *)odoc)); 
     1091        // FIXME: remove this later? 
     1092        osync_xmlformat_sort(out_xmlformat); 
     1093         
     1094        unsigned int size; 
     1095        char *str; 
     1096        osync_xmlformat_assemble(out_xmlformat, &str, &size); 
     1097        osync_trace(TRACE_INTERNAL, "Output XMLFormat is:\n%s", str); 
     1098        g_free(str); 
     1099 
     1100        if (osync_xmlformat_validate(out_xmlformat) == FALSE) 
     1101                osync_trace(TRACE_INTERNAL, "XMLFORMAT EVENT: Not valid!"); 
     1102        else 
     1103                osync_trace(TRACE_INTERNAL, "XMLFORMAT EVENT: VALID"); 
    11201104         
    11211105        osync_trace(TRACE_EXIT, "%s", __func__); 
     
    11331117static osync_bool conv_xml_event_to_opie_xml_event(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, OSyncError **error) 
    11341118{ 
    1135         xmlNode *icur; 
    11361119        time_t start_time = 0; 
    11371120        time_t end_time = 0; 
     
    11411124                                                        outpsize, free_input, config, error); 
    11421125 
    1143         osync_trace(TRACE_INTERNAL, "Input XML is:\n%s",  
    1144                                                         osxml_write_to_string((xmlDoc *)input)); 
    1145          
    1146         /* Get the root node of the input document */ 
    1147         xmlNode *root = xmlDocGetRootElement((xmlDoc *)input); 
    1148         if (!root) { 
    1149                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    1150                                                                                 "Unable to get xml root element"); 
    1151                 goto error; 
    1152         } 
    1153          
    1154         if (xmlStrcmp(root->name, (const xmlChar *)"vcal")) { 
    1155                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    1156                                                                                 "Wrong xml root element"); 
    1157                 goto error; 
    1158         } 
    1159  
    1160         root = osxml_get_node(root, "Event"); 
    1161         if (!root) { 
    1162                 osync_error_set(error, OSYNC_ERROR_GENERIC,  
    1163                                                                                 "Unable to find Event node inside vcal node"); 
     1126        OSyncXMLFormat *in_xmlformat = (OSyncXMLFormat *)input; 
     1127      &n