GnuCash  5.6-150-g038405b370+
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 gnu@gnu.org *
21  * *
22  ********************************************************************/
23 
24 #ifndef SIXTP_H
25 #define SIXTP_H
26 
27 #include <glib.h>
28 
29 #include <stdio.h>
30 
31 #include <stdarg.h>
32 #include "gnc-engine.h"
33 
34 #include "gnc-xml-helper.h"
35 #include "gnc-backend-xml.h"
36 
37 typedef struct sixtp_gdv2 sixtp_gdv2;
38 typedef void (*countCallbackFn) (sixtp_gdv2* gd, const char* type);
39 
40 typedef struct
41 {
42  int accounts_total;
43  int accounts_loaded;
44 
45  int books_total;
46  int books_loaded;
47 
48  int commodities_total;
49  int commodities_loaded;
50 
51  int transactions_total;
52  int transactions_loaded;
53 
54  int prices_total;
55  int prices_loaded;
56 
57  int schedXactions_total;
58  int schedXactions_loaded;
59 
60  int budgets_total;
61  int budgets_loaded;
62 } load_counter;
63 
64 struct sixtp_gdv2
65 {
66  QofBook* book;
67  load_counter counter;
68  countCallbackFn countCallback;
69  QofBePercentageFunc gui_display_fn;
70  gboolean exporting;
71 };
72 typedef struct _sixtp_child_result sixtp_child_result;
73 
74 typedef gboolean (*sixtp_start_handler) (GSList* sibling_data,
75  gpointer parent_data,
76  gpointer global_data,
77  gpointer* data_for_children,
78  gpointer* result,
79  const gchar* tag,
80  gchar** attrs);
81 
82 typedef gboolean (*sixtp_before_child_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  const gchar* child_tag);
90 
91 typedef gboolean (*sixtp_after_child_handler) (gpointer data_for_children,
92  GSList* data_from_children,
93  GSList* sibling_data,
94  gpointer parent_data,
95  gpointer global_data,
96  gpointer* result,
97  const gchar* tag,
98  const gchar* child_tag,
99  sixtp_child_result* child_result);
100 
101 typedef gboolean (*sixtp_end_handler) (gpointer data_for_children,
102  GSList* data_from_children,
103  GSList* sibling_data,
104  gpointer parent_data,
105  gpointer global_data,
106  gpointer* result,
107  const gchar* tag);
108 
109 typedef gboolean (*sixtp_characters_handler) (GSList* sibling_data,
110  gpointer parent_data,
111  gpointer global_data,
112  gpointer* result,
113  const char* text,
114  int length);
115 
116 typedef void (*sixtp_result_handler) (sixtp_child_result* result);
117 
118 typedef void (*sixtp_fail_handler) (gpointer data_for_children,
119  GSList* data_from_children,
120  GSList* sibling_data,
121  gpointer parent_data,
122  gpointer global_data,
123  gpointer* result,
124  const gchar* tag);
125 
126 typedef void (*sixtp_push_handler) (xmlParserCtxtPtr xml_context,
127  gpointer user_data);
128 
129 typedef struct sixtp
130 {
131  /* If you change this, don't forget to modify all the copy/etc. functions */
132  sixtp_start_handler start_handler;
133  sixtp_before_child_handler before_child;
134  sixtp_after_child_handler after_child;
135  sixtp_end_handler end_handler;
136  sixtp_characters_handler characters_handler;
137 
138  sixtp_fail_handler fail_handler;
139  /* called for failures before the close tag */
140 
141  sixtp_result_handler cleanup_result; /* called unless failure */
142  sixtp_result_handler cleanup_chars; /* called unless failure */
143 
144  sixtp_result_handler result_fail_handler;
145  /* called to cleanup results from this node on failure */
146 
147  sixtp_result_handler chars_fail_handler;
148  /* called to cleanup character results when cleaning up this node's
149  children. */
150 
151  GHashTable* child_parsers;
152 } sixtp;
153 
154 typedef enum
155 {
156  SIXTP_NO_MORE_HANDLERS,
157 
158  SIXTP_START_HANDLER_ID,
159  SIXTP_BEFORE_CHILD_HANDLER_ID,
160  SIXTP_AFTER_CHILD_HANDLER_ID,
161  SIXTP_END_HANDLER_ID,
162  SIXTP_CHARACTERS_HANDLER_ID,
163 
164  SIXTP_FAIL_HANDLER_ID,
165 
166  SIXTP_CLEANUP_RESULT_ID,
167  SIXTP_CLEANUP_CHARS_ID,
168 
169  SIXTP_RESULT_FAIL_ID,
170 
171  SIXTP_CHARS_FAIL_ID,
172 } sixtp_handler_type;
173 
174 /* completely invalid tag for xml */
175 #define SIXTP_MAGIC_CATCHER "&MAGIX&"
176 
177 typedef enum
178 {
179  SIXTP_CHILD_RESULT_CHARS,
180  SIXTP_CHILD_RESULT_NODE
181 } sixtp_child_result_type;
182 
184 {
185  sixtp_child_result_type type;
186  gchar* tag; /* NULL for a CHARS node. */
187  gpointer data;
188  gboolean should_cleanup;
189  sixtp_result_handler cleanup_handler;
190  sixtp_result_handler fail_handler;
191 };
192 
193 typedef struct sixtp_sax_data
194 {
195  gboolean parsing_ok;
196  GSList* stack;
197  gpointer global_data;
198  xmlParserCtxtPtr saxParserCtxt;
199  sixtp* bad_xml_parser;
201 
202 gboolean is_child_result_from_node_named (sixtp_child_result* cr,
203  const char* tag);
204 void sixtp_child_free_data (sixtp_child_result* result);
205 void sixtp_child_result_destroy (sixtp_child_result* r);
206 void sixtp_child_result_print (sixtp_child_result* cr, FILE* f);
207 
208 void sixtp_sax_start_handler (void* user_data, const xmlChar* name,
209  const xmlChar** attrs);
210 void sixtp_sax_characters_handler (void* user_data, const xmlChar* text,
211  int len);
212 void sixtp_sax_end_handler (void* user_data, const xmlChar* name);
213 
214 sixtp* sixtp_new (void);
215 void sixtp_destroy (sixtp* sp);
216 
217 void sixtp_handle_catastrophe (sixtp_sax_data* sax_data);
218 xmlEntityPtr sixtp_sax_get_entity_handler (void* user_data,
219  const xmlChar* name);
220 
221 gboolean sixtp_parse_file (sixtp* sixtp, const char* filename,
222  gpointer data_for_top_level, gpointer global_data,
223  gpointer* parse_result);
224 gboolean sixtp_parse_fd (sixtp* sixtp, FILE* fd,
225  gpointer data_for_top_level, gpointer global_data,
226  gpointer* parse_result);
227 gboolean sixtp_parse_buffer (sixtp* sixtp, char* bufp, int bufsz,
228  gpointer data_for_top_level, gpointer global_data,
229  gpointer* parse_result);
230 gboolean sixtp_parse_push (sixtp* sixtp, sixtp_push_handler push_handler,
231  gpointer push_user_data, gpointer data_for_top_level,
232  gpointer global_data, gpointer* parse_result);
233 
234 void sixtp_set_start (sixtp* parser, sixtp_start_handler start_handler);
235 void sixtp_set_before_child (sixtp* parser,
236  sixtp_before_child_handler handler);
237 void sixtp_set_after_child (sixtp* parser, sixtp_after_child_handler handler);
238 void sixtp_set_end (sixtp* parser, sixtp_end_handler end_handler);
239 void sixtp_set_chars (sixtp* parser, sixtp_characters_handler char_handler);
240 void sixtp_set_cleanup_result (sixtp* parser, sixtp_result_handler handler);
241 void sixtp_set_cleanup_chars (sixtp* parser, sixtp_result_handler handler);
242 void sixtp_set_fail (sixtp* parser, sixtp_fail_handler handler);
243 void sixtp_set_result_fail (sixtp* parser, sixtp_result_handler handler);
244 void sixtp_set_chars_fail (sixtp* parser, sixtp_result_handler handler);
245 
246 sixtp* sixtp_set_any (sixtp* tochange, gboolean cleanup, ...);
247 sixtp* sixtp_add_some_sub_parsers (sixtp* tochange, gboolean cleanup, ...);
248 
249 gboolean sixtp_add_sub_parser (sixtp* parser, const gchar* tag,
250  sixtp* sub_parser);
251 
252 QofBookFileType gnc_is_our_xml_file (const char* filename,
253  gboolean* with_encoding);
254 
255 QofBookFileType gnc_is_our_first_xml_chunk (char* chunk,
256  gboolean* with_encoding);
258 void sixtp_run_callback (sixtp_gdv2* data, const char* type);
259 
260 #endif /* _SIXTP_H_ */
Definition: sixtp.h:129
All type declarations for the whole Gnucash engine.
void(* QofBePercentageFunc)(const char *message, double percent)
DOCUMENT ME!
Definition: qofbackend.h:163
load and save data to files