From: <svn...@op...> - 2010-08-16 18:52:19
|
Author: cdfrey Date: Mon Aug 16 20:52:10 2010 New Revision: 6096 URL: http://www.opensync.org/changeset/6096 Log: Make sure vformat output does not have separators in timestamps The vformat RFCs do not allow separators in their timestamps, even though they are based on the ISO 8601 spec. It may happen that the plugins create xmlformat data with ISO 8601 timestamps, even though this is not technically supposed to happen. If it does, the best tactic is to convert the timestamp to the RFC format using osync_time_timestamp(). Modified: format-plugins/vformat/src/xmlformat-common.c format-plugins/vformat/src/xmlformat-common.h format-plugins/vformat/src/xmlformat-vcalendar.c Modified: format-plugins/vformat/src/xmlformat-common.c ============================================================================== --- format-plugins/vformat/src/xmlformat-common.c Mon Aug 16 20:52:03 2010 (r6095) +++ format-plugins/vformat/src/xmlformat-common.c Mon Aug 16 20:52:10 2010 (r6096) @@ -149,6 +149,40 @@ return attr; } +VFormatAttribute *handle_xml_attribute_simple_content_timestamp(VFormat *vformat, OSyncXMLField *xmlfield, const char *name, const char *encoding) +{ + g_assert(vformat); + g_assert(xmlfield); + g_assert(name); + + VFormatAttribute *attr = vformat_attribute_new(NULL, name); + + const char *tmp = osync_xmlfield_get_key_value(xmlfield, "Content"); + char *timestamp = NULL; + if( tmp ) { + // vformat must not have any separators in its timestamp, + // so run the timestamp through osync_time_timestamp() + // just to make sure it is in a valid state, in case + // a plugin gave us an ISO 8601 timestamp + timestamp = osync_time_timestamp(tmp); + } + else { + timestamp = strdup(""); + } + + add_value_data(attr, xmlfield, timestamp, encoding); + + // TODO timezone +// char *tzid = osxml_find_node(xmlfield, "TimezoneID") +// vformat_attribute_add_param_with_value(attr, "TZID", tzid); +// g_free(tzid); + + vformat_add_attribute(vformat, attr); + + osync_free(timestamp); + return attr; +} + VFormatAttribute *handle_xml_categories_attribute(VFormat *vformat, OSyncXMLField *xmlfield, const char *encoding) { return handle_xml_attribute_simple_content(vformat, xmlfield, "CATEGORIES", encoding); Modified: format-plugins/vformat/src/xmlformat-common.h ============================================================================== --- format-plugins/vformat/src/xmlformat-common.h Mon Aug 16 20:52:03 2010 (r6095) +++ format-plugins/vformat/src/xmlformat-common.h Mon Aug 16 20:52:10 2010 (r6096) @@ -62,6 +62,7 @@ /** XML Attributes **/ VFormatAttribute *handle_xml_attribute_simple_content(VFormat *vformat, OSyncXMLField *xmlfield, const char *name, const char *encoding); +VFormatAttribute *handle_xml_attribute_simple_content_timestamp(VFormat *vformat, OSyncXMLField *xmlfield, const char *name, const char *encoding); VFormatAttribute *handle_xml_categories_attribute(VFormat *vcard, OSyncXMLField *xmlfield, const char *encoding); VFormatAttribute *handle_xml_class_attribute(VFormat *vcard, OSyncXMLField *xmlfield, const char *encoding); VFormatAttribute *handle_xml_uid_attribute(VFormat *vcard, OSyncXMLField *xmlfield, const char *encoding); Modified: format-plugins/vformat/src/xmlformat-vcalendar.c ============================================================================== --- format-plugins/vformat/src/xmlformat-vcalendar.c Mon Aug 16 20:52:03 2010 (r6095) +++ format-plugins/vformat/src/xmlformat-vcalendar.c Mon Aug 16 20:52:10 2010 (r6096) @@ -970,26 +970,12 @@ VFormatAttribute *handle_xml_due_attribute(VFormat *vevent, OSyncXMLField *xmlfield, const char *encoding) { - /*TODO timezone*/ - VFormatAttribute *attr = vformat_attribute_new(NULL, "DUE"); - add_value(attr, xmlfield, "Content", encoding); -// char *tzid = osxml_find_node(xmlfield, "TimezoneID") -// vformat_attribute_add_param_with_value(attr, "TZID", tzid); -// g_free(tzid); - vformat_add_attribute(vevent, attr); - return attr; + return handle_xml_attribute_simple_content_timestamp(vevent, xmlfield, "DUE", encoding); } VFormatAttribute *handle_xml_dtstart_attribute(VFormat *vevent, OSyncXMLField *xmlfield, const char *encoding) { - /* TODO timezone */ - VFormatAttribute *attr = vformat_attribute_new(NULL, "DTSTART"); - add_value(attr, xmlfield, "Content", encoding); -// char *tzid = osxml_find_node(xmlfield, "TimezoneID") -// vformat_attribute_add_param_with_value(attr, "TZID", tzid); -// g_free(tzid); - vformat_add_attribute(vevent, attr); - return attr; + return handle_xml_attribute_simple_content_timestamp(vevent, xmlfield, "DTSTART", encoding); } VFormatAttribute *handle_xml_percent_complete_attribute(VFormat *vevent, OSyncXMLField *xmlfield, const char *encoding) @@ -1105,14 +1091,7 @@ VFormatAttribute *handle_xml_dtend_attribute(VFormat *vevent, OSyncXMLField *xmlfield, const char *encoding) { - /* TODO timezone */ - VFormatAttribute *attr = vformat_attribute_new(NULL, "DTEND"); - add_value(attr, xmlfield, "Content", encoding); -// char *tzid = osxml_find_node(xmlfield, "TimezoneID") -// vformat_attribute_add_param_with_value(attr, "TZID", tzid); -// g_free(tzid); - vformat_add_attribute(vevent, attr); - return attr; + return handle_xml_attribute_simple_content_timestamp(vevent, xmlfield, "DTEND", encoding); } VFormatAttribute *handle_xml_transp_attribute(VFormat *vevent, OSyncXMLField *xmlfield, const char *encoding) |