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>
39 qsf_compare_tag_strings (
const xmlChar * node_name, gchar * tag_name)
41 return xmlStrcmp (node_name, (
const xmlChar *) tag_name);
45 qsf_strings_equal (
const xmlChar * node_name, gchar * tag_name)
47 if (0 == qsf_compare_tag_strings (node_name, tag_name))
55 qsf_is_element (xmlNodePtr a, xmlNsPtr ns, gchar * c)
57 g_return_val_if_fail (a != NULL, 0);
58 g_return_val_if_fail (ns != NULL, 0);
59 g_return_val_if_fail (c != NULL, 0);
60 if ((a->ns == ns) && (a->type == XML_ELEMENT_NODE) &&
61 qsf_strings_equal (a->name, c))
69 qsf_check_tag (
QsfParam * params, gchar * qof_type)
75 qsf_is_valid (
const gchar * schema_dir,
const gchar * schema_filename,
78 xmlSchemaParserCtxtPtr qsf_schema_file;
79 xmlSchemaPtr qsf_schema;
80 xmlSchemaValidCtxtPtr qsf_context;
84 g_return_val_if_fail (doc || schema_filename, FALSE);
85 schema_path = g_strdup_printf (
"%s/%s", schema_dir, schema_filename);
86 qsf_schema_file = xmlSchemaNewParserCtxt (schema_path);
87 qsf_schema = xmlSchemaParse (qsf_schema_file);
88 qsf_context = xmlSchemaNewValidCtxt (qsf_schema);
89 result = xmlSchemaValidateDoc (qsf_context, doc);
90 xmlSchemaFreeParserCtxt (qsf_schema_file);
91 xmlSchemaFreeValidCtxt (qsf_context);
92 xmlSchemaFree (qsf_schema);
107 qsfiter->v_fcn = &cb;
108 for (cur_node = parent->children; cur_node != NULL;
109 cur_node = cur_node->next)
111 cb (cur_node, qsfiter->ns, valid);
123 g_return_if_fail (params);
124 g_return_if_fail (qsfiter->ns);
126 for (cur_node = parent->children; cur_node != NULL;
127 cur_node = cur_node->next)
129 cb (cur_node, qsfiter->ns, params);
134 qsf_object_validation_handler (xmlNodePtr child, xmlNsPtr ns,
138 xmlChar *object_declaration;
141 gboolean is_registered;
145 is_registered = FALSE;
146 for (cur_node = child->children; cur_node != NULL;
147 cur_node = cur_node->next)
162 xmlFree (object_declaration);
164 g_hash_table_insert (valid->
object_table, object_declaration,
165 GINT_TO_POINTER (type));
180 is_our_qsf_object (
const gchar * path)
184 xmlNodePtr object_root;
188 g_return_val_if_fail ((path != NULL), FALSE);
189 doc = xmlParseFile (path);
196 PINFO (
" validation failed %s %s %s", QSF_SCHEMA_DIR,
200 object_root = xmlDocGetRootElement (doc);
202 valid.
object_table = g_hash_table_new (g_str_hash, g_str_equal);
205 qsfiter.ns = object_root->ns;
206 qsf_valid_foreach (object_root, qsf_object_validation_handler,
219 is_qsf_object (
const gchar * path)
223 g_return_val_if_fail ((path != NULL), FALSE);
228 doc = xmlParseFile (path);
247 xmlNodePtr object_root;
251 g_return_val_if_fail ((params != NULL), FALSE);
255 (_(
"The QSF XML file '%s' could not be found."), TRUE));
262 doc = xmlParseFile (params->
filepath);
266 (_(
"There was an error parsing the file '%s'."), TRUE));
272 (_(
"Invalid QSF Object file! The QSF object file '%s' "
273 " failed to validate against the QSF object schema. "
274 "The XML structure of the file is either not well-formed "
275 "or the file contains illegal data."), TRUE));
280 object_root = xmlDocGetRootElement (doc);
282 valid.
object_table = g_hash_table_new (g_str_hash, g_str_equal);
284 qsfiter.ns = object_root->ns;
285 qsf_valid_foreach (object_root, qsf_object_validation_handler,
294 qof_error_set_be (params->
be, params->err_nomap);
306 g_return_val_if_fail ((params != NULL), FALSE);
311 (_(
"The QSF XML file '%s' could not be found."), TRUE));
321 doc = xmlParseFile (path);
325 (_(
"There was an error parsing the file '%s'."), TRUE));
331 (_(
"Invalid QSF Object file! The QSF object file '%s' "
332 " failed to validate against the QSF object schema. "
333 "The XML structure of the file is either not well-formed "
334 "or the file contains illegal data."), TRUE));
340 for (maps = params->
map_files; maps; maps = maps->next)
343 result = is_qsf_object_with_map_be (maps->data, params);
356 qsf_supported_data_types (gpointer type, gpointer user_data)
360 g_return_if_fail (user_data != NULL);
361 g_return_if_fail (type != NULL);
373 qsf_parameter_handler (xmlNodePtr child, xmlNsPtr qsf_ns,
385 qsf_object_node_handler (xmlNodePtr child, xmlNsPtr qsf_ns,
390 gchar *tail, *object_count_s;
393 g_return_if_fail (child != NULL);
394 g_return_if_fail (qsf_ns != NULL);
402 object_set->object_count = 0;
403 object_set->parameters =
404 g_hash_table_new (g_str_hash, g_str_equal);
405 object_set->object_type = ((gchar *) xmlGetProp (child,
407 object_count_s = ((gchar *) xmlGetProp (child,
411 c = (gint64) strtol (object_count_s, &tail, 0);
412 object_set->object_count = (gint) c;
413 g_free (object_count_s);
419 qsf_node_foreach (child, qsf_parameter_handler, &qsfiter, params);
424 qsf_book_node_handler (xmlNodePtr child, xmlNsPtr ns,
QsfParam * params)
426 gchar *book_count_s, *tail;
428 xmlNodePtr child_node;
433 g_return_if_fail (child);
434 g_return_if_fail (params);
435 ENTER (
" child=%s", child->name);
442 book_count = (gint) strtol (book_count_s, &tail, 0);
444 g_free (book_count_s);
445 g_return_if_fail (book_count == 1);
448 child_node = child->children->next;
451 DEBUG (
" trying to set book GUID");
452 buffer = BAD_CAST xmlNodeGetContent (child_node);
459 qsf_node_foreach (child, qsf_object_node_handler, &qsfiter, params);