Checking for parameter validity.
[gdataplugin.git] / src / gdata_format.c
blob60f8a157d6ec71c5b7bdfda14a67d8899fb2ac95
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 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)
49 /* TODO: how to get path to XSLT file using 'config'? */
50 return FALSE;
53 osync_bool xmlevent_to_gevent(char *input, unsigned int inpsize,
54 char **output, unsigned int *outpsize,
55 osync_bool *free_input, const char *config,
56 void *userdata, OSyncError **error)
58 /* TODO: how to get path to XSLT file using 'config'? */
59 return FALSE;
62 osync_bool gcontact_to_xmlcontact(char *input, unsigned int inpsize,
63 char **output, unsigned int *outpsize,
64 osync_bool *free_input, const char *config,
65 void *userdata, OSyncError **error)
67 /* TODO: how to get path to XSLT file using 'config'? */
68 return FALSE;
71 osync_bool gevent_to_xmlevent(char *input, unsigned int inpsize,
72 char **output, unsigned int *outpsize,
73 osync_bool *free_input, const char *config,
74 void *userdata, OSyncError **error)
76 /* TODO: how to get path to XSLT file using 'config'? */
77 return FALSE;
81 osync_bool get_format_info(OSyncFormatEnv *env, OSyncError **error)
83 OSyncObjFormat *gcont = osync_objformat_new("google-contact", "contact", error);
84 if (!gcont)
85 return FALSE;
87 OSyncObjFormat *gevent = osync_objformat_new("google-event", "event", error);
88 if (!gevent)
89 return FALSE;
91 /* TODO: register (and write) auxiliary functions: compare/create/destroy/blah...*/
93 osync_format_env_register_objformat(env, gcont);
94 osync_objformat_unref(gcont);
96 osync_format_env_register_objformat(env, gevent);
97 osync_objformat_unref(gevent);
100 void *initialize(OSyncError **error)
102 struct xslt_resources *converter = NULL;
103 converter = xslt_new();
105 return converter;
108 void finalize(void *userdata)
110 struct xslt_resources *converter = NULL;
111 if (!userdata)
112 return;
113 else
114 fprintf(stderr, "\n\nuserdata is not NULL: %x\n", userdata);
116 converter = (struct xslt_resources *)userdata;
117 xslt_delete(converter);
120 osync_bool get_conversion_info(OSyncFormatEnv *env)
122 OSyncFormatConverter *conv = NULL;
123 OSyncError *error = NULL;
125 /* osync xml formats */
126 OSyncObjFormat *xml_contact = osync_format_env_find_objformat(env, "xmlformat-contact");
127 OSyncObjFormat *xml_event = osync_format_env_find_objformat(env, "xmlformat-event");
129 /* gdata formats */
130 OSyncObjFormat *gevent = osync_format_env_find_objformat(env, "google-event");
131 osync_assert(gevent);
132 OSyncObjFormat *gcontact = osync_format_env_find_objformat(env, "google-contact");
133 osync_assert(gcontact);
135 /* from xmlformat to gdata */
136 conv = osync_converter_new(OSYNC_CONVERTER_CONV, xml_contact, gcontact,
137 xmlcontact_to_gcontact, &error);
138 osync_assert(conv);
139 osync_converter_set_initialize_func(conv, initialize);
140 osync_converter_set_finalize_func(conv, finalize);
141 osync_format_env_register_converter(env, conv);
142 osync_converter_unref(conv);
144 conv = osync_converter_new(OSYNC_CONVERTER_CONV, xml_event, gevent,
145 xmlevent_to_gevent, &error);
146 osync_assert(conv);
147 osync_converter_set_initialize_func(conv, initialize);
148 osync_converter_set_finalize_func(conv, finalize);
149 osync_format_env_register_converter(env, conv);
150 osync_converter_unref(conv);
152 /* from gdata to xmlformat */
153 conv = osync_converter_new(OSYNC_CONVERTER_CONV, gcontact, xml_contact,
154 gcontact_to_xmlcontact, &error);
155 osync_assert(conv);
156 osync_converter_set_initialize_func(conv, initialize);
157 osync_converter_set_finalize_func(conv, finalize);
158 osync_format_env_register_converter(env, conv);
159 osync_converter_unref(conv);
161 conv = osync_converter_new(OSYNC_CONVERTER_CONV, gevent, xml_event,
162 gevent_to_xmlevent, &error);
163 osync_assert(conv);
164 osync_converter_set_initialize_func(conv, initialize);
165 osync_converter_set_finalize_func(conv, finalize);
167 osync_format_env_register_converter(env, conv);
168 osync_converter_unref(conv);
170 return TRUE;
173 int get_version(void)
175 return 1;