Project

General

Profile

0001-Added-better-error-handing-to-xml.c.patch

Git patch for xml.c - Ivan Krivyakov, 03 Aug 2016 11:56 PM

Download (5.58 KB)

View differences:

Subject: [PATCH 1/1] Added better error handing to xml.c

 lasso/xml/xml.c | 66 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 19 deletions(-)
lasso/xml/xml.c
68 68

  
69 69
#include "../key.h"
70 70

  
71
#define LOG_LEVEL_XML_DEBUG G_LOG_LEVEL_DEBUG /* change to G_LOG_LEVEL_WARNING so it shows in Apache log */
72

  
71 73
static void lasso_node_build_xmlNode_from_snippets(LassoNode *node, LassoNodeClass *class, xmlNode *xmlnode,
72 74
		struct XmlSnippet *snippets, gboolean lasso_dump);
73 75
static struct XmlSnippet* find_xml_snippet_by_name(LassoNode *node, char *name, LassoNodeClass **class_p);
......
1440 1442
static inline gboolean
1441 1443
node_match_snippet(xmlNode *parent, xmlNode *node, struct XmlSnippet *snippet)
1442 1444
{
1443
	gboolean rc = TRUE;
1444

  
1445 1445
	/* special case of ArtifactResponse */
1446 1446
	if (snippet->type & SNIPPET_ANY) {
1447
		message(LOG_LEVEL_XML_DEBUG, "Matching node %s vs SNIPPET_ANY: SUCCESS", node->name);
1447 1448
		return TRUE;
1448 1449
	} else {
1449
		rc = rc && lasso_strisequal(snippet->name, (char*)node->name);
1450
		rc = rc &&
1451
		    ((!snippet->ns_uri &&
1452
			lasso_equal_namespace(parent->ns, node->ns)) ||
1453
		    (node->ns &&
1454
		           lasso_strisequal((char*)node->ns->href, snippet->ns_uri)));
1455
		return rc;
1450
		if (!lasso_strisequal(snippet->name, (char*)node->name)) {
1451
			message(LOG_LEVEL_XML_DEBUG, "Matching node %s vs snippet %s: FAILURE names don't match", node->name, snippet->name);
1452
			return FALSE;
1453
		}
1454

  
1455
		if ((snippet->ns_uri == NULL) && lasso_equal_namespace(parent->ns, node->ns)) {
1456
			message(LOG_LEVEL_XML_DEBUG, "Matching node %s vs snippet %s: SUCCESS namespace prefixes match", node->name, snippet->name);
1457
			return TRUE;
1458
		}
1459

  
1460
		if ((node->ns != NULL) && lasso_strisequal((char*)node->ns->href, snippet->ns_uri)) {
1461
			message(LOG_LEVEL_XML_DEBUG, "Matching node %s vs snippet %s: SUCCESS namespace URIs match", node->name, snippet->name);
1462
			return TRUE;
1463
		}
1464

  
1465
		message(LOG_LEVEL_XML_DEBUG, "Matching node %s vs snippet %s: FAILURE", node->name, snippet->name);
1466
		return FALSE;
1456 1467
	}
1457 1468
}
1458 1469

  
......
1478 1489
	LassoNodeClass *node_class;
1479 1490
	gint rc = 0;
1480 1491

  
1492
	message(LOG_LEVEL_XML_DEBUG, "lasso_node_impl_init_from_xml <%s>", xmlnode->name);
1493

  
1481 1494
	if (! xmlnode) {
1482 1495
		rc = 1;
1483 1496
		goto cleanup;
......
1521 1534
						g_type_any = g_type;
1522 1535
						snippet_any = snippet;
1523 1536
					} else {
1524
						critical("Two any node snippet for class %s",
1537
						message(G_LOG_LEVEL_CRITICAL, "Two 'any' node snippet for class %s",
1525 1538
								g_type_name(G_TYPE_FROM_INSTANCE(node)));
1526 1539
					}
1527 1540
				}
......
1662 1675
				} \
1663 1676
				next_node_snippet(&class_iter, &snippet);
1664 1677
#define ERROR \
1665
				error("Element %s:%s cannot be parsed", \
1666
						t->ns != NULL ? (char*)t->ns->prefix : "<noprefix>", \
1667
						t->name); \
1678
				message(G_LOG_LEVEL_CRITICAL, "Element <%s:%s> was not expected at this location inside element <%s>. " \
1679
						"Please ensure the XML correctly follows XML schema", \
1680
						(t->ns == NULL) ? "<noprefix>" : ((t->ns->prefix == NULL)? (char*)t->ns->href : (char*)t->ns->prefix), \
1681
						t->name, \
1682
						xmlnode->name); \
1668 1683
				rc = 1; \
1669 1684
				goto cleanup;
1670 1685
			/* Find a matching snippet */
......
1702 1717
					case SNIPPET_NODE:
1703 1718
						subnode = lasso_node_new_from_xmlNode_with_type(t,
1704 1719
								matched_snippet->class_name);
1705
						if (is_snippet_type(matched_snippet, SNIPPET_NODE)) {
1706
							lasso_assign_new_gobject(*(LassoNode**)value, subnode);
1707
						} else {
1708
							lasso_list_add_new_gobject(*list, subnode);
1720
						if (subnode == NULL) {
1721
							message(G_LOG_LEVEL_CRITICAL, "Failed to create LassoNode from XML node");
1722
						}
1723
						else {
1724
							if (is_snippet_type(matched_snippet, SNIPPET_NODE)) {
1725
								lasso_assign_new_gobject(*(LassoNode**)value, subnode);
1726
							}
1727
							else {
1728
								lasso_list_add_new_gobject(*list, subnode);
1729
							}
1709 1730
						}
1710 1731
						break;
1711 1732
					case SNIPPET_NODE_IN_CHILD:
......
1846 1867
	}
1847 1868
cleanup:
1848 1869
	lasso_release_slist(class_list);
1870
	message(LOG_LEVEL_XML_DEBUG, "lasso_node_impl_init_from_xml </%s> rc=%d", xmlnode->name, rc);
1849 1871
	return rc;
1850 1872
}
1851 1873
#undef trace_snippet
......
2526 2548
	LassoNode *node;
2527 2549
	int rc = 0;
2528 2550

  
2529
	if (typename == NULL)
2551
	message(LOG_LEVEL_XML_DEBUG, "Processing node '%s' with type '%s'", xmlnode->name, typename); 
2552

  
2553
	if (typename == NULL) {
2530 2554
		return _lasso_node_new_from_xmlNode(xmlnode); /* will auto-detect */
2555
	}
2531 2556

  
2532 2557
	gtype = g_type_from_name(typename);
2533
	if (gtype == 0)
2558
	if (gtype == 0) {
2559
		message(G_LOG_LEVEL_CRITICAL, "Unable to get g_type from name '%s'", typename);
2534 2560
		return NULL;
2561
	}
2535 2562

  
2536 2563

  
2537 2564
	node = g_object_new(gtype, NULL);
......
2540 2567
	}
2541 2568
	rc = lasso_node_init_from_xml(node, xmlnode);
2542 2569
	if (rc) {
2570
		message(G_LOG_LEVEL_CRITICAL, "Lasso node initialization failed for node '%s', type '%s': error %d", xmlnode->name, typename, rc);
2543 2571
		lasso_node_destroy(node);
2544 2572
		return NULL;
2545 2573
	}
2546
-