GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sixtp.h
1 /********************************************************************
2  * sixtp.h -- header file for XML parsing *
3  * Copyright 2001 Gnumatic, Inc. *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program 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 *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21  * *
22  ********************************************************************/
23 
24 #ifndef SIXTP_H
25 #define SIXTP_H
26 
27 #include <glib.h>
28 #include <stdio.h>
29 
30 #include <stdarg.h>
31 
32 #include "gnc-xml-helper.h"
33 #include "gnc-engine.h"
34 #include "gnc-backend-xml.h"
35 
37 
38 typedef gboolean (*sixtp_start_handler)(GSList* sibling_data,
39  gpointer parent_data,
40  gpointer global_data,
41  gpointer *data_for_children,
42  gpointer *result,
43  const gchar *tag,
44  gchar **attrs);
45 
46 typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children,
47  GSList* data_from_children,
48  GSList* sibling_data,
49  gpointer parent_data,
50  gpointer global_data,
51  gpointer *result,
52  const gchar *tag,
53  const gchar *child_tag);
54 
55 typedef gboolean (*sixtp_after_child_handler)(gpointer data_for_children,
56  GSList* data_from_children,
57  GSList* sibling_data,
58  gpointer parent_data,
59  gpointer global_data,
60  gpointer *result,
61  const gchar *tag,
62  const gchar *child_tag,
63  sixtp_child_result *child_result);
64 
65 typedef gboolean (*sixtp_end_handler)(gpointer data_for_children,
66  GSList* data_from_children,
67  GSList* sibling_data,
68  gpointer parent_data,
69  gpointer global_data,
70  gpointer *result,
71  const gchar *tag);
72 
73 typedef gboolean (*sixtp_characters_handler)(GSList *sibling_data,
74  gpointer parent_data,
75  gpointer global_data,
76  gpointer *result,
77  const char *text,
78  int length);
79 
80 typedef void (*sixtp_result_handler)(sixtp_child_result *result);
81 
82 typedef void (*sixtp_fail_handler)(gpointer data_for_children,
83  GSList* data_from_children,
84  GSList* sibling_data,
85  gpointer parent_data,
86  gpointer global_data,
87  gpointer *result,
88  const gchar *tag);
89 
90 typedef void (*sixtp_push_handler)(xmlParserCtxtPtr xml_context,
91  gpointer user_data);
92 
93 typedef struct sixtp
94 {
95  /* If you change this, don't forget to modify all the copy/etc. functions */
96  sixtp_start_handler start_handler;
97  sixtp_before_child_handler before_child;
98  sixtp_after_child_handler after_child;
99  sixtp_end_handler end_handler;
100  sixtp_characters_handler characters_handler;
101 
102  sixtp_fail_handler fail_handler;
103  /* called for failures before the close tag */
104 
105  sixtp_result_handler cleanup_result; /* called unless failure */
106  sixtp_result_handler cleanup_chars; /* called unless failure */
107 
108  sixtp_result_handler result_fail_handler;
109  /* called to cleanup results from this node on failure */
110 
111  sixtp_result_handler chars_fail_handler;
112  /* called to cleanup character results when cleaning up this node's
113  children. */
114 
115  GHashTable *child_parsers;
116 } sixtp;
117 
118 typedef enum
119 {
120  SIXTP_NO_MORE_HANDLERS,
121 
122  SIXTP_START_HANDLER_ID,
123  SIXTP_BEFORE_CHILD_HANDLER_ID,
124  SIXTP_AFTER_CHILD_HANDLER_ID,
125  SIXTP_END_HANDLER_ID,
126  SIXTP_CHARACTERS_HANDLER_ID,
127 
128  SIXTP_FAIL_HANDLER_ID,
129 
130  SIXTP_CLEANUP_RESULT_ID,
131  SIXTP_CLEANUP_CHARS_ID,
132 
133  SIXTP_RESULT_FAIL_ID,
134 
135  SIXTP_CHARS_FAIL_ID,
136 } sixtp_handler_type;
137 
138 /* completely invalid tag for xml */
139 #define SIXTP_MAGIC_CATCHER "&MAGIX&"
140 
141 typedef enum
142 {
143  SIXTP_CHILD_RESULT_CHARS,
144  SIXTP_CHILD_RESULT_NODE
145 } sixtp_child_result_type;
146 
148 {
149  sixtp_child_result_type type;
150  gchar *tag; /* NULL for a CHARS node. */
151  gpointer data;
152  gboolean should_cleanup;
153  sixtp_result_handler cleanup_handler;
154  sixtp_result_handler fail_handler;
155 };
156 
157 typedef struct sixtp_sax_data
158 {
159  gboolean parsing_ok;
160  GSList *stack;
161  gpointer global_data;
162  xmlParserCtxtPtr saxParserCtxt;
163  sixtp *bad_xml_parser;
165 
166 
167 gboolean is_child_result_from_node_named(sixtp_child_result *cr,
168  const char *tag);
169 void sixtp_child_free_data(sixtp_child_result *result);
170 void sixtp_child_result_destroy(sixtp_child_result *r);
171 void sixtp_child_result_print(sixtp_child_result *cr, FILE *f);
172 
173 void sixtp_sax_start_handler(void *user_data, const xmlChar *name,
174  const xmlChar **attrs);
175 void sixtp_sax_characters_handler(void *user_data, const xmlChar *text,
176  int len);
177 void sixtp_sax_end_handler(void *user_data, const xmlChar *name);
178 
179 sixtp* sixtp_new(void);
180 void sixtp_destroy(sixtp *sp);
181 
182 void sixtp_handle_catastrophe(sixtp_sax_data *sax_data);
183 xmlEntityPtr sixtp_sax_get_entity_handler(void *user_data, const xmlChar *name);
184 
185 gboolean sixtp_parse_file(sixtp *sixtp, const char *filename,
186  gpointer data_for_top_level, gpointer global_data,
187  gpointer *parse_result);
188 gboolean sixtp_parse_fd(sixtp *sixtp, FILE *fd,
189  gpointer data_for_top_level, gpointer global_data,
190  gpointer *parse_result);
191 gboolean sixtp_parse_buffer(sixtp *sixtp, char *bufp, int bufsz,
192  gpointer data_for_top_level, gpointer global_data,
193  gpointer *parse_result);
194 gboolean sixtp_parse_push(sixtp *sixtp, sixtp_push_handler push_handler,
195  gpointer push_user_data, gpointer data_for_top_level,
196  gpointer global_data, gpointer *parse_result);
197 
198 void sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler);
199 void sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler);
200 void sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler);
201 void sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler);
202 void sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler);
203 void sixtp_set_cleanup_result(sixtp *parser, sixtp_result_handler handler);
204 void sixtp_set_cleanup_chars(sixtp *parser, sixtp_result_handler handler);
205 void sixtp_set_fail(sixtp *parser, sixtp_fail_handler handler);
206 void sixtp_set_result_fail(sixtp *parser, sixtp_result_handler handler);
207 void sixtp_set_chars_fail(sixtp *parser, sixtp_result_handler handler);
208 
209 sixtp* sixtp_set_any(sixtp *tochange, gboolean cleanup, ...);
210 sixtp* sixtp_add_some_sub_parsers(sixtp *tochange, gboolean cleanup, ...);
211 
212 gboolean sixtp_add_sub_parser(sixtp *parser, const gchar* tag,
213  sixtp *sub_parser);
214 
215 QofBookFileType gnc_is_our_xml_file(const char *filename,
216  gboolean *with_encoding);
217 
218 QofBookFileType gnc_is_our_first_xml_chunk(char *chunk, gboolean *with_encoding);
219 
220 
221 #endif /* _SIXTP_H_ */
Definition: sixtp.h:93
All type declarations for the whole Gnucash engine.
load and save data to files