summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-03-05 11:00:00 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-03-05 11:00:00 +0000
commit7f0818c80cf6aca8f50a637a0f1c3bd5e810e227 (patch)
treee8264a3440a4eb921b2621a21ff325db6ba121bb /src
parent0d2b8501a93f78107fadf8b084486a2ad5c532cc (diff)
downloadlibdom-7f0818c80cf6aca8f50a637a0f1c3bd5e810e227.tar.gz
libdom-7f0818c80cf6aca8f50a637a0f1c3bd5e810e227.tar.bz2
Make hubbub parser binding build trees correctly (credit: Bo Yang)
svn path=/trunk/dom/; revision=6711
Diffstat (limited to 'src')
-rw-r--r--src/core/string.c8
-rw-r--r--src/utils/namespace.c91
2 files changed, 67 insertions, 32 deletions
diff --git a/src/core/string.c b/src/core/string.c
index 2540e26..3d30e3f 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -89,6 +89,14 @@ dom_exception dom_string_create(dom_alloc alloc, void *pw,
{
struct dom_string *ret;
+ if (ptr == NULL && len == 0) {
+ dom_string_ref(&empty_string);
+
+ *str = &empty_string;
+
+ return DOM_NO_ERR;
+ }
+
ret = alloc(NULL, sizeof(struct dom_string), pw);
if (ret == NULL)
return DOM_NO_MEM_ERR;
diff --git a/src/utils/namespace.c b/src/utils/namespace.c
index 8002b8e..ca5b01d 100644
--- a/src/utils/namespace.c
+++ b/src/utils/namespace.c
@@ -7,19 +7,31 @@
#include <string.h>
-#include <dom/core/string.h>
+#include <dom/dom.h>
#include "utils/namespace.h"
#include "utils/utils.h"
+
/** XML prefix */
static struct dom_string *xml;
-/** XML namespace URI */
-static struct dom_string *xml_ns;
/** XMLNS prefix */
static struct dom_string *xmlns;
-/** XMLNS namespace URI */
-static struct dom_string *xmlns_ns;
+
+/** The namespace strings */
+static const char *namespaces[DOM_NAMESPACE_COUNT] = {
+ NULL,
+ "http://www.w3.org/1999/xhtml",
+ "http://www.w3.org/1998/Math/MathML",
+ "http://www.w3.org/2000/svg",
+ "http://www.w3.org/1999/xlink",
+ "http://www.w3.org/XML/1998/namespace",
+ "http://www.w3.org/2000/xmlns/"
+};
+
+struct dom_string *dom_namespaces[DOM_NAMESPACE_COUNT] = {
+ NULL,
+};
/**
* Initialise the namespace component
@@ -30,6 +42,7 @@ static struct dom_string *xmlns_ns;
*/
dom_exception _dom_namespace_initialise(dom_alloc alloc, void *pw)
{
+ int i;
dom_exception err;
err = dom_string_create(alloc, pw,
@@ -39,31 +52,27 @@ dom_exception _dom_namespace_initialise(dom_alloc alloc, void *pw)
}
err = dom_string_create(alloc, pw,
- (const uint8_t *) "http://www.w3.org/XML/1998/namespace",
- SLEN("http://www.w3.org/XML/1998/namespace"),
- &xml_ns);
- if (err != DOM_NO_ERR) {
- dom_string_unref(xml);
- return err;
- }
-
- err = dom_string_create(alloc, pw,
(const uint8_t *) "xmlns", SLEN("xmlns"), &xmlns);
if (err != DOM_NO_ERR) {
- dom_string_unref(xml_ns);
dom_string_unref(xml);
+ xml = NULL;
+
return err;
}
- err = dom_string_create(alloc, pw,
- (const uint8_t *) "http://www.w3.org/2000/xmlns",
- SLEN("http://www.w3.org/2000/xmlns"),
- &xmlns_ns);
- if (err != DOM_NO_ERR) {
- dom_string_unref(xmlns);
- dom_string_unref(xml_ns);
- dom_string_unref(xml);
- return err;
+ for (i = 1; i < DOM_NAMESPACE_COUNT; i++) {
+ err = dom_string_create(
+ alloc, pw, (const uint8_t *) namespaces[i],
+ strlen(namespaces[i]), &dom_namespaces[i]);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(xmlns);
+ xmlns = NULL;
+
+ dom_string_unref(xml);
+ xml = NULL;
+
+ return err;
+ }
}
return DOM_NO_ERR;
@@ -76,10 +85,24 @@ dom_exception _dom_namespace_initialise(dom_alloc alloc, void *pw)
*/
dom_exception _dom_namespace_finalise(void)
{
- dom_string_unref(xmlns_ns);
- dom_string_unref(xmlns);
- dom_string_unref(xml_ns);
- dom_string_unref(xml);
+ int i;
+
+ if (xmlns != NULL) {
+ dom_string_unref(xmlns);
+ xmlns = NULL;
+ }
+
+ if (xml != NULL) {
+ dom_string_unref(xml);
+ xml = NULL;
+ }
+
+ for (i = 1; i < DOM_NAMESPACE_COUNT; i++) {
+ if (dom_namespaces[i] != NULL) {
+ dom_string_unref(dom_namespaces[i]);
+ dom_namespaces[i] = NULL;
+ }
+ }
return DOM_NO_ERR;
}
@@ -119,7 +142,8 @@ dom_exception _dom_namespace_validate_qname(struct dom_string *qname,
/* No prefix */
/* If namespace URI is for xmlns, ensure qname == "xmlns" */
if (namespace != NULL &&
- dom_string_cmp(namespace, xmlns_ns) == 0 &&
+ dom_string_cmp(namespace,
+ dom_namespaces[DOM_NAMESPACE_XMLNS]) == 0 &&
dom_string_cmp(qname, xmlns) != 0) {
return DOM_NAMESPACE_ERR;
}
@@ -140,20 +164,23 @@ dom_exception _dom_namespace_validate_qname(struct dom_string *qname,
/* Test for invalid XML namespace */
if (dom_string_cmp(prefix, xml) == 0 &&
- dom_string_cmp(namespace, xml_ns) != 0) {
+ dom_string_cmp(namespace,
+ dom_namespaces[DOM_NAMESPACE_XML]) != 0) {
dom_string_unref(prefix);
return DOM_NAMESPACE_ERR;
}
/* Test for invalid xmlns namespace */
if (dom_string_cmp(prefix, xmlns) == 0 &&
- dom_string_cmp(namespace, xmlns_ns) != 0) {
+ dom_string_cmp(namespace,
+ dom_namespaces[DOM_NAMESPACE_XMLNS]) != 0) {
dom_string_unref(prefix);
return DOM_NAMESPACE_ERR;
}
/* Test for presence of xmlns namespace with non xmlns prefix */
- if (dom_string_cmp(namespace, xmlns_ns) == 0 &&
+ if (dom_string_cmp(namespace,
+ dom_namespaces[DOM_NAMESPACE_XMLNS]) == 0 &&
dom_string_cmp(prefix, xmlns) != 0) {
dom_string_unref(prefix);
return DOM_NAMESPACE_ERR;