summaryrefslogtreecommitdiffstats
path: root/debian/opensync/opensync-0.22/formats/vformats-xml/xmldoc.c
blob: 3bf998dfc04686a62e418bab51a8635641e9c8d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * xmldoc - serialised textual versions of the XML event formats, for external plugins
 * Copyright (C) 2006  Andrew Baumann <andrewb@cse.unsw.edu.au>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

#include "xml-support.h"

static osync_bool from_xml(void *conv_data, char *input, int inpsize, char **output, int *outpsize, osync_bool *free_input, OSyncError **error)
{
	*free_input = TRUE;
	return osxml_marshall(input, inpsize, output, outpsize, error);
}

static osync_bool to_xml(void *conv_data, char *input, int inpsize, char **output, int *outpsize, osync_bool *free_input, OSyncError **error)
{
	*free_input = TRUE;
	return osxml_demarshall(input, inpsize, output, outpsize, error);
}

static osync_bool copy_string(const char *input, int inpsize, char **output, int *outpsize)
{
	*output = strdup(input);
	*outpsize = inpsize;
	return TRUE;
}

static void destroy(char *input, size_t inpsize)
{
	free(input);
}

void get_info(OSyncEnv *env)
{
	osync_env_register_objtype(env, "event");
	osync_env_register_objformat(env, "event", "xml-event-doc");
	osync_env_format_set_destroy_func(env, "xml-event-doc", destroy);
	osync_env_format_set_copy_func(env, "xml-event-doc", copy_string);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-event", "xml-event-doc", from_xml);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-event-doc", "xml-event", to_xml);

	osync_env_register_objtype(env, "todo");
	osync_env_register_objformat(env, "todo", "xml-todo-doc");
	osync_env_format_set_destroy_func(env, "xml-todo-doc", destroy);
	osync_env_format_set_copy_func(env, "xml-todo-doc", copy_string);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-todo", "xml-todo-doc", from_xml);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-todo-doc", "xml-todo", to_xml);

	osync_env_register_objtype(env, "contact");
	osync_env_register_objformat(env, "contact", "xml-contact-doc");
	osync_env_format_set_destroy_func(env, "xml-contact-doc", destroy);
	osync_env_format_set_copy_func(env, "xml-contact-doc", copy_string);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-contact", "xml-contact-doc", from_xml);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-contact-doc", "xml-contact", to_xml);

	osync_env_register_objtype(env, "note");
	osync_env_register_objformat(env, "note", "xml-note-doc");
	osync_env_format_set_destroy_func(env, "xml-note-doc", destroy);
	osync_env_format_set_copy_func(env, "xml-note-doc", copy_string);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-note", "xml-note-doc", from_xml);
	osync_env_register_converter(env, CONVERTER_CONV, "xml-note-doc", "xml-note", to_xml);
}