Fixed potential uninitialized variable usage (compiler warning)
[opensync/google-calendar-cdf.git] / src / gdata_format.c
blob3680dd4c57613ec6556bdb949c1f62bd911834f8
1 /*
2 * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org>
3 * Copyright (C) 2008 Instituto Nokia de Tecnologia
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /**
22 * @file gdata_format.c
23 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
24 * @date Wed Sep 3 12:33:08 2008
26 * @brief A google data (contacts/calendar events) format plugin.
28 * It seems to be requirement to make the whole thing work, yada, yada, yada. I'm taking
29 * as a base the mock_format.c/vformat-xmlformat.c files from opensync trunk and
30 * hoping for the best.
31 * \todo:
32 * - make the convertion (should be easy thanks to xslt_aux functions)
36 #include "xslt_aux.h"
38 #include <glib.h>
39 #include <opensync/opensync.h>
40 #include <opensync/opensync-xmlformat.h>
41 #include <opensync/opensync-format.h>
42 #include <opensync/opensync-time.h>
44 static osync_bool xmlcontact_to_gcontact(char *input, unsigned int inpsize,
45 char **output, unsigned int *outpsize,
46 osync_bool *free_input, const char *config,
47 void *userdata, OSyncError **error);
48 static osync_bool xmlevent_to_gevent(char *input, unsigned int inpsize,
49 char **output, unsigned int *outpsize,
50 osync_bool *free_input, const char *config,
51 void *userdata, OSyncError **error);
52 static osync_bool gcontact_to_xmlcontact(char *input, unsigned int inpsize,
53 char **output, unsigned int *outpsize,
54 osync_bool *free_input, const char *config,
55 void *userdata, OSyncError **error);
56 static osync_bool gevent_to_xmlevent(char *input, unsigned int inpsize,
57 char **output, unsigned int *outpsize,
58 osync_bool *free_input, const char *config,
59 void *userdata, OSyncError **error);
60 static void *gc_data_initialize(const char *config, OSyncError **error);
61 static osync_bool gc_data_finalize(void *userdata, OSyncError **error);
65 static osync_bool xmlcontact_to_gcontact(char *input, unsigned int inpsize,
66 char **output, unsigned int *outpsize,
67 osync_bool *free_input, const char *config,
68 void *userdata, OSyncError **error)
70 // TODO: how to get path to XSLT file using 'config'?
71 return FALSE;
74 static osync_bool xmlevent_to_gevent(char *input, unsigned int inpsize,
75 char **output, unsigned int *outpsize,
76 osync_bool *free_input, const char *config,
77 void *userdata, OSyncError **error)
79 // TODO: how to get path to XSLT file using 'config'?
80 return FALSE;
83 static osync_bool gcontact_to_xmlcontact(char *input, unsigned int inpsize,
84 char **output, unsigned int *outpsize,
85 osync_bool *free_input, const char *config,
86 void *userdata, OSyncError **error)
88 // TODO: how to get path to XSLT file using 'config'?
89 return FALSE;
92 static osync_bool gevent_to_xmlevent(char *input, unsigned int inpsize,
93 char **output, unsigned int *outpsize,
94 osync_bool *free_input, const char *config,
95 void *userdata, OSyncError **error)
97 // TODO: how to get path to XSLT file using 'config'?
98 return FALSE;
101 static void *gc_data_initialize(const char *config, OSyncError **error)
103 struct xslt_resources *converter = NULL;
104 converter = xslt_new();
106 return converter;
109 static osync_bool gc_data_finalize(void *userdata, OSyncError **error)
111 struct xslt_resources *converter = NULL;
112 if (!userdata)
113 return TRUE;
115 converter = (struct xslt_resources *)userdata;
116 xslt_delete(converter);
117 return TRUE;
121 osync_bool get_format_info(OSyncFormatEnv *env, OSyncError **error)
123 OSyncObjFormat *gcont = NULL;
124 OSyncObjFormat *gevent = NULL;
126 gcont = osync_objformat_new("google-contact", "contact", error);
127 if (!gcont)
128 goto error;
130 gevent = osync_objformat_new("google-event", "event", error);
131 if (!gevent)
132 goto error;
134 // TODO: register (and write) auxiliary functions:
135 // compare/create/destroy/blah...
137 if( !osync_format_env_register_objformat(env, gcont, error) )
138 goto error;
139 osync_objformat_unref(gcont);
141 if( !osync_format_env_register_objformat(env, gevent, error) )
142 goto error;
143 osync_objformat_unref(gevent);
145 return TRUE;
146 error:
147 if( gcont )
148 osync_objformat_unref(gcont);
149 if( gevent )
150 osync_objformat_unref(gevent);
151 return FALSE;
154 osync_bool get_conversion_info(OSyncFormatEnv *env)
156 OSyncFormatConverter *conv = NULL;
157 OSyncError *error = NULL;
159 // osync xml formats
160 OSyncObjFormat *xml_contact = osync_format_env_find_objformat(env, "xmlformat-contact");
161 OSyncObjFormat *xml_event = osync_format_env_find_objformat(env, "xmlformat-event");
163 // gdata formats
164 OSyncObjFormat *gevent = osync_format_env_find_objformat(env, "google-event");
165 osync_assert(gevent);
166 OSyncObjFormat *gcontact = osync_format_env_find_objformat(env, "google-contact");
167 osync_assert(gcontact);
169 // from xmlformat to gdata
170 conv = osync_converter_new(OSYNC_CONVERTER_CONV, xml_contact, gcontact,
171 xmlcontact_to_gcontact, &error);
172 osync_assert(conv);
173 osync_converter_set_initialize_func(conv, gc_data_initialize);
174 osync_converter_set_finalize_func(conv, gc_data_finalize);
175 if( !osync_format_env_register_converter(env, conv, &error) )
176 goto error;
177 osync_converter_unref(conv);
179 conv = osync_converter_new(OSYNC_CONVERTER_CONV, xml_event, gevent,
180 xmlevent_to_gevent, &error);
181 osync_assert(conv);
182 osync_converter_set_initialize_func(conv, gc_data_initialize);
183 osync_converter_set_finalize_func(conv, gc_data_finalize);
184 if( !osync_format_env_register_converter(env, conv, &error) )
185 goto error;
186 osync_converter_unref(conv);
188 // from gdata to xmlformat
189 conv = osync_converter_new(OSYNC_CONVERTER_CONV, gcontact, xml_contact,
190 gcontact_to_xmlcontact, &error);
191 osync_assert(conv);
192 osync_converter_set_initialize_func(conv, gc_data_initialize);
193 osync_converter_set_finalize_func(conv, gc_data_finalize);
194 if( !osync_format_env_register_converter(env, conv, &error) )
195 goto error;
196 osync_converter_unref(conv);
198 conv = osync_converter_new(OSYNC_CONVERTER_CONV, gevent, xml_event,
199 gevent_to_xmlevent, &error);
200 osync_assert(conv);
201 osync_converter_set_initialize_func(conv, gc_data_initialize);
202 osync_converter_set_finalize_func(conv, gc_data_finalize);
204 if( !osync_format_env_register_converter(env, conv, &error) )
205 goto error;
206 osync_converter_unref(conv);
208 return TRUE;
210 error:
211 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__,
212 osync_error_print(&error));
213 osync_error_unref(&error);
214 if( conv )
215 osync_converter_unref(conv);
216 return FALSE;
219 int get_version(void)
221 return 1;