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> 40 return xmlStrcmp (node_name, (
const xmlChar *) tag_name);
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) &&
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);
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));
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;
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;
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)
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,
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);
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);
QofErrorId qof_error_register(const gchar *err_message, gboolean use_file)
Generate and register a new error.
void qsf_object_validation_handler(xmlNodePtr child, xmlNsPtr ns, QsfValidator *valid)
Checks all incoming objects for QOF registration.
gint qsf_check_tag(QsfParam *params, gchar *qof_type)
shorthand function
#define PINFO(format, args...)
gboolean qof_class_is_registered(QofIdTypeConst obj_name)
gboolean is_qsf_object(const gchar *path)
Validate a QSF file and identify a suitable QSF map.
gboolean string_to_guid(const gchar *string, GUID *guid)
void qsf_valid_foreach(xmlNodePtr parent, QsfValidCB cb, struct QsfNodeIterate *qsfiter, QsfValidator *valid)
gboolean qsf_is_valid(const gchar *schema_dir, const gchar *schema_filename, xmlDocPtr doc)
Compares an xmlDoc in memory against the schema file.
gint32 QofErrorId
The ID of this error.
gboolean is_qsf_object_be(QsfParam *params)
Validate a QSF file and identify a suitable QSF map.
QofErrorId qof_error_check_be(QofBackend *be)
Check for errors.
Private QSF header - not for use by applications.
gint qsf_strings_equal(const xmlChar *node_name, gchar *tag_name)
shorthand function
#define LEAVE(format, args...)
gint qsf_compare_tag_strings(const xmlChar *node_name, gchar *tag_name)
shorthand function
gboolean is_our_qsf_object(const gchar *path)
Validate a QSF file.
One iterator, two typedefs.
gint qof_registered_count
QsfStatus
Status of various object during mapping.
void qsf_node_foreach(xmlNodePtr parent, QsfNodeCB cb, struct QsfNodeIterate *qsfiter, QsfParam *params)
#define DEBUG(format, args...)
QSF API - Backend, maps, objects and configuration.
gboolean is_qsf_object_with_map_be(gchar *map_path, QsfParam *params)
Validate a QSF file and a selected QSF map.
void(* QsfNodeCB)(xmlNodePtr, xmlNsPtr, QsfParam *)
map and qsf object callback
gboolean is_our_qsf_object_be(QsfParam *params)
Validate a QSF file and determine type.
#define QSF_OBJECT_SCHEMA
gint qsf_is_element(xmlNodePtr a, xmlNsPtr ns, gchar *c)
shorthand function
Holds a description of the QofObject.
void qof_entity_set_guid(QofEntity *ent, const GUID *guid)
void qsf_book_node_handler(xmlNodePtr child, xmlNsPtr qsf_ns, QsfParam *params)
Book and book-guid node handler.
GHashTable * object_table
#define ENTER(format, args...)
void qsf_object_node_handler(xmlNodePtr child, xmlNsPtr qsf_ns, QsfParam *params)
const gchar * QofLogModule
void(* QsfValidCB)(xmlNodePtr, xmlNsPtr, QsfValidator *)
validator callback