From: <svn...@op...> - 2009-10-21 17:39:15
|
Author: henrik Date: Wed Oct 21 19:39:00 2009 New Revision: 5878 URL: http://www.opensync.org/changeset/5878 Log: Fixed xmlformat-vcard.c so handle_xml_name_attribute and handle_xml_address_attribute does not invent empty properties. Fixes #1173 Modified: format-plugins/vformat/src/xmlformat-common.c format-plugins/vformat/src/xmlformat-common.h format-plugins/vformat/src/xmlformat-vcard.c Modified: format-plugins/vformat/src/xmlformat-common.c ============================================================================== --- format-plugins/vformat/src/xmlformat-common.c Wed Oct 21 19:03:09 2009 (r5877) +++ format-plugins/vformat/src/xmlformat-common.c Wed Oct 21 19:39:00 2009 (r5878) @@ -227,6 +227,36 @@ vformat_attribute_add_value(attr, tmp); } +void add_value_array(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *parameterNameArray[], int nParameters, const char *encoding) { + const char **parameterValueArray = malloc(nParameters*sizeof(char*)); + int n=-1; + int i; + for (i=0; i<nParameters; ++i) { + parameterValueArray[i]=osync_xmlfield_get_key_value(xmlfield, parameterNameArray[i]); + if (parameterValueArray[i]) n=i; + } + for (i=0; i<=n; ++i) { + const char *tmp = parameterValueArray[i]; + if (!tmp) continue; + if (needs_charset((unsigned char*)tmp)) + if (!vformat_attribute_has_param (attr, "CHARSET")) + vformat_attribute_add_param_with_value(attr, "CHARSET", "UTF-8"); + + /* XXX: This one breaks unit test case: conv_vcard_evolution2_special + TODO: Combine this with converter extension/config ... e.g. if a mobile needs QP! + */ + if (needs_encoding((unsigned char*)tmp, encoding)) { + if (!vformat_attribute_has_param (attr, "ENCODING")) + vformat_attribute_add_param_with_value(attr, "ENCODING", encoding); + vformat_attribute_add_value_decoded(attr, tmp, strlen(tmp) + 1); + } else + vformat_attribute_add_value(attr, tmp); + + } + free(parameterValueArray); +} + + void add_values(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *encoding) { int i, c = osync_xmlfield_get_key_count(xmlfield); Modified: format-plugins/vformat/src/xmlformat-common.h ============================================================================== --- format-plugins/vformat/src/xmlformat-common.h Wed Oct 21 19:03:09 2009 (r5877) +++ format-plugins/vformat/src/xmlformat-common.h Wed Oct 21 19:39:00 2009 (r5878) @@ -71,6 +71,7 @@ osync_bool needs_charset(const unsigned char *tmp); void add_value(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *name, const char *encoding); +void add_value_array(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *parameterNameArray[], int nParameters, const char *encoding); void add_values(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *encoding); void add_values_from_nth_field_on(VFormatAttribute *attr, OSyncXMLField *xmlfield, const char *encoding, int nth); Modified: format-plugins/vformat/src/xmlformat-vcard.c ============================================================================== --- format-plugins/vformat/src/xmlformat-vcard.c Wed Oct 21 19:03:09 2009 (r5877) +++ format-plugins/vformat/src/xmlformat-vcard.c Wed Oct 21 19:39:00 2009 (r5878) @@ -1213,17 +1213,13 @@ // g_free(content); //} +static const char* xml_address_parameters[] = { "PostOfficeBox", "ExtendedAddress", "Street", "Locality", "Region", "PostalCode", "Country" }; + static VFormatAttribute *handle_xml_address_attribute(VFormat *vcard, OSyncXMLField *xmlfield, const char *encoding) { osync_trace(TRACE_INTERNAL, "Handling address xml attribute"); VFormatAttribute *attr = vformat_attribute_new(NULL, "ADR"); - add_value(attr, xmlfield, "PostOfficeBox", encoding); - add_value(attr, xmlfield, "ExtendedAddress", encoding); - add_value(attr, xmlfield, "Street", encoding); - add_value(attr, xmlfield, "Locality", encoding); - add_value(attr, xmlfield, "Region", encoding); - add_value(attr, xmlfield, "PostalCode", encoding); - add_value(attr, xmlfield, "Country", encoding); + add_value_array(attr, xmlfield, xml_address_parameters, 7, encoding); vformat_add_attribute(vcard, attr); return attr; } @@ -1466,15 +1462,13 @@ return attr; } +static const char* xml_name_parameters[] = { "LastName", "FirstName", "Additional", "Prefix", "Suffix" }; + static VFormatAttribute *handle_xml_name_attribute(VFormat *vcard, OSyncXMLField *xmlfield, const char *encoding) { osync_trace(TRACE_INTERNAL, "Handling name xml attribute"); VFormatAttribute *attr = vformat_attribute_new(NULL, "N"); - add_value(attr, xmlfield, "LastName", encoding); - add_value(attr, xmlfield, "FirstName", encoding); - add_value(attr, xmlfield, "Additional", encoding); - add_value(attr, xmlfield, "Prefix", encoding); - add_value(attr, xmlfield, "Suffix", encoding); + add_value_array(attr, xmlfield, xml_name_parameters, 5, encoding); vformat_add_attribute(vcard, attr); return attr; } |