26 #include <libxml/xmlversion.h>
27 #include <libxml/xmlmemory.h>
28 #include <libxml/tree.h>
29 #include <libxml/parser.h>
30 #include <libxml/xmlschemas.h>
38 qsf_compare_tag_strings (
const xmlChar * node_name, gchar * tag_name)
40 return xmlStrcmp (node_name, (
const xmlChar *) tag_name);
44 qsf_strings_equal (
const xmlChar * node_name, gchar * tag_name)
46 if (0 == qsf_compare_tag_strings (node_name, tag_name))
54 qsf_is_element (xmlNodePtr a, xmlNsPtr ns, gchar * c)
56 g_return_val_if_fail (a != NULL, 0);
57 g_return_val_if_fail (ns != NULL, 0);
58 g_return_val_if_fail (c != NULL, 0);
59 if ((a->ns == ns) && (a->type == XML_ELEMENT_NODE) &&
60 qsf_strings_equal (a->name, c))
68 qsf_check_tag (
QsfParam * params, gchar * qof_type)
74 qsf_is_valid (
const gchar * schema_dir,
const gchar * schema_filename,
77 xmlSchemaParserCtxtPtr qsf_schema_file;
78 xmlSchemaPtr qsf_schema;
79 xmlSchemaValidCtxtPtr qsf_context;
83 g_return_val_if_fail (doc || schema_filename, FALSE);
84 schema_path = g_strdup_printf (
"%s/%s", schema_dir, schema_filename);
85 qsf_schema_file = xmlSchemaNewParserCtxt (schema_path);
86 qsf_schema = xmlSchemaParse (qsf_schema_file);
87 qsf_context = xmlSchemaNewValidCtxt (qsf_schema);
88 result = xmlSchemaValidateDoc (qsf_context, doc);
89 xmlSchemaFreeParserCtxt (qsf_schema_file);
90 xmlSchemaFreeValidCtxt (qsf_context);
91 xmlSchemaFree (qsf_schema);
106 qsfiter->v_fcn = &cb;
107 for (cur_node = parent->children; cur_node != NULL;
108 cur_node = cur_node->next)
110 cb (cur_node, qsfiter->ns, valid);
122 g_return_if_fail (params);
123 g_return_if_fail (qsfiter->ns);
125 for (cur_node = parent->children; cur_node != NULL;
126 cur_node = cur_node->next)
128 cb (cur_node, qsfiter->ns, params);
133 qsf_object_validation_handler (xmlNodePtr child, xmlNsPtr ns,
137 xmlChar *object_declaration;
140 gboolean is_registered;
144 is_registered = FALSE;
145 for (cur_node = child->children; cur_node != NULL;
146 cur_node = cur_node->next)
161 xmlFree (object_declaration);
163 g_hash_table_insert (valid->
object_table, object_declaration,
164 GINT_TO_POINTER (type));
179 is_our_qsf_object (
const gchar * path)
183 xmlNodePtr object_root;
187 g_return_val_if_fail ((path != NULL), FALSE);
188 doc = xmlParseFile (path);
195 PINFO (
" validation failed %s %s %s", QSF_SCHEMA_DIR,
199 object_root = xmlDocGetRootElement (doc);
201 valid.
object_table = g_hash_table_new (g_str_hash, g_str_equal);
204 qsfiter.ns = object_root->ns;
205 qsf_valid_foreach (object_root, qsf_object_validation_handler,
218 is_qsf_object (
const gchar * path)
222 g_return_val_if_fail ((path != NULL), FALSE);
227 doc = xmlParseFile (path);
246 xmlNodePtr object_root;
250 g_return_val_if_fail ((params != NULL), FALSE);
254 (_(
"The QSF XML file '%s' could not be found."), TRUE));
261 doc = xmlParseFile (params->
filepath);
265 (_(
"There was an error parsing the file '%s'."), TRUE));
271 (_(
"Invalid QSF Object file! The QSF object file '%s' "
272 " failed to validate against the QSF object schema. "
273 "The XML structure of the file is either not well-formed "
274 "or the file contains illegal data."), TRUE));
279 object_root = xmlDocGetRootElement (doc);
281 valid.
object_table = g_hash_table_new (g_str_hash, g_str_equal);
283 qsfiter.ns = object_root->ns;
284 qsf_valid_foreach (object_root, qsf_object_validation_handler,
293 qof_error_set_be (params->
be, params->err_nomap);
305 g_return_val_if_fail ((params != NULL), FALSE);
310 (_(
"The QSF XML file '%s' could not be found."), TRUE));
320 doc = xmlParseFile (path);
324 (_(
"There was an error parsing the file '%s'."), TRUE));
330 (_(
"Invalid QSF Object file! The QSF object file '%s' "
331 " failed to validate against the QSF object schema. "
332 "The XML structure of the file is either not well-formed "
333 "or the file contains illegal data."), TRUE));
339 for (maps = params->
map_files; maps; maps = maps->next)
342 result = is_qsf_object_with_map_be (maps->data, params);
355 qsf_supported_data_types (gpointer type, gpointer user_data)
359 g_return_if_fail (user_data != NULL);
360 g_return_if_fail (type != NULL);
372 qsf_parameter_handler (xmlNodePtr child, xmlNsPtr qsf_ns,
384 qsf_object_node_handler (xmlNodePtr child, xmlNsPtr qsf_ns,
389 gchar *tail, *object_count_s;
392 g_return_if_fail (child != NULL);
393 g_return_if_fail (qsf_ns != NULL);
401 object_set->object_count = 0;
402 object_set->parameters =
403 g_hash_table_new (g_str_hash, g_str_equal);
404 object_set->object_type = ((gchar *) xmlGetProp (child,
406 object_count_s = ((gchar *) xmlGetProp (child,
410 c = (gint64) strtol (object_count_s, &tail, 0);
411 object_set->object_count = (gint) c;
412 g_free (object_count_s);
418 qsf_node_foreach (child, qsf_parameter_handler, &qsfiter, params);
423 qsf_book_node_handler (xmlNodePtr child, xmlNsPtr ns,
QsfParam * params)
425 gchar *book_count_s, *tail;
427 xmlNodePtr child_node;
432 g_return_if_fail (child);
433 g_return_if_fail (params);
434 ENTER (
" child=%s", child->name);
441 book_count = (gint) strtol (book_count_s, &tail, 0);
443 g_free (book_count_s);
444 g_return_if_fail (book_count == 1);
447 child_node = child->children->next;
450 DEBUG (
" trying to set book GUID");
451 buffer = (gchar*) xmlNodeGetContent (child_node);
458 qsf_node_foreach (child, qsf_object_node_handler, &qsfiter, params);