From: <dg...@su...> - 2009-01-20 16:08:31
|
Author: savago Date: Tue Jan 20 17:07:23 2009 New Revision: 5209 URL: http://www.opensync.org/changeset/5209 Log: Moving converter creation and registration to a function to avoid code duplication. Modified: format-plugins/xsltformat/src/xsltformat.c Modified: format-plugins/xsltformat/src/xsltformat.c ============================================================================== --- format-plugins/xsltformat/src/xsltformat.c Tue Jan 20 16:46:07 2009 (r5208) +++ format-plugins/xsltformat/src/xsltformat.c Tue Jan 20 17:07:23 2009 (r5209) @@ -201,6 +201,28 @@ } +static osync_bool reg_conv(OSyncFormatEnv *env, + OSyncObjFormat *from, OSyncObjFormat *to, + OSyncFormatConvertFunc convert_func, + OSyncFormatConverterInitializeFunc initialize_func, + OSyncFormatConverterFinalizeFunc finalize_func) +{ + OSyncError *error = NULL; + OSyncFormatConverter *conv = osync_converter_new(OSYNC_CONVERTER_CONV, + from, to, + convert_func, &error); + if (!conv) + return FALSE; + + osync_converter_set_initialize_func(conv, initialize_func); + osync_converter_set_finalize_func(conv, finalize_func); + osync_format_env_register_converter(env, conv); + osync_converter_unref(conv); + + return TRUE; + +} + osync_bool get_conversion_info(OSyncFormatEnv *env, OSyncError **error) { /* Supported formats */ @@ -218,27 +240,18 @@ } /* XSLT to xml-contact */ - OSyncFormatConverter *conv = osync_converter_new(OSYNC_CONVERTER_CONV, - xslt_contact, xml_contact, - conv_xslt_to_contact, error); - if (!conv) + osync_bool result = reg_conv(env, xslt_contact, xml_contact, + conv_xslt_to_contact, + initialize_xslt, finalize_xslt); + if (!result) return FALSE; - osync_converter_set_initialize_func(conv, initialize_xslt); - osync_converter_set_finalize_func(conv, finalize_xslt); - osync_format_env_register_converter(env, conv); - osync_converter_unref(conv); /* xml-contact to XSLT */ - conv = osync_converter_new(OSYNC_CONVERTER_CONV, - xml_contact, xslt_contact, - conv_contact_to_xslt, error); - if (!conv) - return FALSE; - osync_converter_set_initialize_func(conv, initialize_xslt); - osync_converter_set_finalize_func(conv, finalize_xslt); - osync_format_env_register_converter(env, conv); - osync_converter_unref(conv); - return TRUE; + result = reg_conv(env, xml_contact, xslt_contact, + conv_contact_to_xslt, + initialize_xslt, finalize_xslt); + return result; + } int get_version(void) |