r3470 jmb - in /trunk/dom: bindings/xml/xmlbinding.c include/dom/bootstrap/implpriv.h src/core/implementation.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Jul 29 01:27:01 2007
New Revision: 3470
URL: http://source.netsurf-browser.org?rev=3470&view=rev
Log:
Comment fixes
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/src/core/implementation.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sun Jul 29 01:27:01 2007
@@ -13,7 +13,7 @@
#include "utils.h"
static dom_exception xml_dom_get_dom_implementation(
- struct dom_string *features,
+ struct dom_string *features,
struct dom_implementation **impl, dom_alloc alloc, void *pw);
static dom_exception xml_dom_get_dom_implementation_list(
struct dom_string *features,
@@ -86,7 +86,7 @@
* once it has finished with it.
*/
dom_exception xml_dom_get_dom_implementation(
- struct dom_string *features,
+ struct dom_string *features,
struct dom_implementation **impl, dom_alloc alloc, void *pw)
{
UNUSED(features);
@@ -258,8 +258,8 @@
* Any memory allocated by this call should be allocated using
* the provided memory (de)allocation function.
*
- * The doctype will be referenced, so the client need not do this
- * explicitly. The client must unref the doctype once it has
+ * The document will be referenced, so the client need not do this
+ * explicitly. The client must unref the document once it has
* finished with it.
*/
dom_exception xml_dom_implementation_create_document(
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Sun Jul 29 01:27:01 2007
@@ -13,7 +13,7 @@
* include this, as those types are defined here.
*
* The Document implementation includes this as it needs the declaration of
- * dom_document_set_doctype.
+ * dom_document_create and dom_document_set_doctype.
*
* No other client should be including this.
*/
@@ -117,8 +117,8 @@
* Any memory allocated by this call should be allocated using
* the provided memory (de)allocation function.
*
- * The doctype will be referenced, so the client need not do this
- * explicitly. The client must unref the doctype once it has
+ * The document will be referenced, so the client need not do this
+ * explicitly. The client must unref the document once it has
* finished with it.
*/
dom_exception (*create_document)(struct dom_implementation *impl,
Modified: trunk/dom/src/core/implementation.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/implementation.c?rev...
==============================================================================
--- trunk/dom/src/core/implementation.c (original)
+++ trunk/dom/src/core/implementation.c Sun Jul 29 01:27:01 2007
@@ -117,8 +117,8 @@
* Any memory allocated by this call should be allocated using
* the provided memory (de)allocation function.
*
- * The doctype will be referenced, so the client need not do this
- * explicitly. The client must unref the doctype once it has
+ * The document will be referenced, so the client need not do this
+ * explicitly. The client must unref the document once it has
* finished with it.
*/
dom_exception dom_implementation_create_document(
16 years, 2 months
r3469 jmb - /trunk/dom/docs/RefCnt
by netsurf@semichrome.net
Author: jmb
Date: Sun Jul 29 00:31:11 2007
New Revision: 3469
URL: http://source.netsurf-browser.org?rev=3469&view=rev
Log:
Improve description of the list of nodes pending deletion and how it is related to the process of deleting a Document.
Modified:
trunk/dom/docs/RefCnt
Modified: trunk/dom/docs/RefCnt
URL: http://source.netsurf-browser.org/trunk/dom/docs/RefCnt?rev=3469&r1=3468&...
==============================================================================
--- trunk/dom/docs/RefCnt (original)
+++ trunk/dom/docs/RefCnt Sun Jul 29 00:31:11 2007
@@ -100,3 +100,43 @@
list of nodes pending deletion).
2) The NodeList is destroyed.
+Destruction of Documents
+------------------------
+
+ Assumptions:
+
+ 1) Nodes within a document do not hold explicit references upon it.
+ 2) Container data structures which address nodes in a document hold
+ an explicit reference upon the document.
+ [FIXME: and upon the root node of the subtree they address -- this
+ implies that the explicit reference is unnecessary, as the
+ addressed node will be added to the list of nodes pending
+ deletion]
+ 3) A document has no parent (i.e. the parent pointer is always NULL).
+ 4) A given node may be located in either the document tree or the
+ list of nodes pending deletion. It may not be located in both
+ data structures simultaneously.
+ 5) Nodes in the list of nodes pending deletion are in use by the
+ client.
+
+ The above assumptions imply the following:
+
+ + If a document has a non-zero reference count, it is in use by
+ the client. (1,2)
+ + If the document's reference count reaches zero, it is no longer
+ in use and is eligible for deletion. (1,2,3)
+ + The document destructor must attempt to forcibly delete the
+ contents of the document tree as the nodes do not hold a reference
+ upon the document. (1)
+ + On destruction of a node, it must be removed from the list of nodes
+ pending deletion. (4)
+ + The document may not be destroyed if the list of nodes pending
+ deletion is non-empty after the destructor has attempted to
+ destroy the document tree. (4,5)
+
+ Therefore, document destruction proceeds as follows:
+
+ 1) Forcibly destroy the document tree.
+ 2) If the list of nodes pending deletion is non-empty, stop.
+ 3) The list of nodes pending deletion is empty, so destroy the
+ document.
16 years, 2 months
r3468 jmb - in /trunk/dom/src/core: document.c document.h node.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Jul 29 00:03:56 2007
New Revision: 3468
URL: http://source.netsurf-browser.org?rev=3468&view=rev
Log:
Implement Document destructor.
Fix handling of nodes within a document (they no longer explicitly reference the document)
Modified:
trunk/dom/src/core/document.c
trunk/dom/src/core/document.h
trunk/dom/src/core/node.c
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3468&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sun Jul 29 00:03:56 2007
@@ -138,8 +138,10 @@
}
}
- /* Initialise base class */
- err = dom_node_initialise(&d->base, d, DOM_DOCUMENT_NODE,
+ /* Initialise base class -- the Document has no parent, so
+ * destruction will be attempted as soon as its reference count
+ * reaches zero. */
+ err = dom_node_initialise(&d->base, NULL, DOM_DOCUMENT_NODE,
NULL, NULL);
if (err != DOM_NO_ERR) {
/* Clean up interned strings */
@@ -165,6 +167,79 @@
*doc = d;
return DOM_NO_ERR;
+}
+
+/**
+ * Destroy a document
+ *
+ * \param doc The document to destroy
+ *
+ * The contents of ::doc will be destroyed and ::doc will be freed.
+ */
+void dom_document_destroy(struct dom_document *doc)
+{
+ struct dom_node *c, *d;
+
+ /* Destroy children of this node */
+ for (c = doc->base.first_child; c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this child */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ /** \todo Ensure list of nodes pending deletion is empty. If not,
+ * then we can't yet destroy the document (its destruction will
+ * have to wait until the pending nodes are destroyed) */
+
+ /* Ok, the document tree is empty, as is the list of nodes pending
+ * deletion. Therefore, it is safe to destroy the document. */
+
+ /* Destroy the doctype (if there is one) */
+ if (doc->type != NULL) {
+ ((struct dom_node *) doc->type)->parent = NULL;
+
+ dom_node_destroy((struct dom_node *) doc->type);
+ }
+
+ doc->type = NULL;
+
+ if (doc->impl != NULL)
+ dom_implementation_unref(doc->impl);
+ doc->impl = NULL;
+
+ /* This is paranoia -- if there are any remaining nodelists or
+ * namednodemaps, then the document's reference count will be
+ * non-zero as these data structures reference the document because
+ * they are held by the client. */
+ doc->nodelists = NULL;
+ doc->maps = NULL;
+
+ /* Clean up interned strings */
+ for (int i = 0; i <= DOM_NODE_TYPE_COUNT; i++) {
+ if (doc->nodenames[i] != NULL)
+ dom_string_unref(doc->nodenames[i]);
+ }
+
+ /* Finalise base class */
+ dom_node_finalise(doc, &doc->base);
+
+ /* Free document */
+ doc->alloc(doc, 0, doc->pw);
}
/**
Modified: trunk/dom/src/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.h?rev=3468&...
==============================================================================
--- trunk/dom/src/core/document.h (original)
+++ trunk/dom/src/core/document.h Sun Jul 29 00:03:56 2007
@@ -18,6 +18,9 @@
struct dom_node;
struct dom_nodelist;
struct dom_string;
+
+/* Destroy a document */
+void dom_document_destroy(struct dom_document *doc);
/* Get base of document buffer */
const uint8_t *dom_document_get_base(struct dom_document *doc);
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3468&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sun Jul 29 00:03:56 2007
@@ -39,10 +39,11 @@
struct dom_document *owner = node->owner;
/* This function simply acts as a central despatcher
- * for type-specific destructors. It claims a reference upon the
- * owning document during destruction to ensure that the document
- * doesn't get destroyed before its contents. */
-
+ * for type-specific destructors. */
+
+ /* Claim a reference upon the owning document during destruction
+ * to ensure that the document doesn't get destroyed before its
+ * contents. */
dom_node_ref((struct dom_node *) owner);
switch (node->type) {
@@ -74,7 +75,7 @@
dom_comment_destroy(owner, (struct dom_comment *) node);
break;
case DOM_DOCUMENT_NODE:
- /** \todo document node */
+ dom_document_destroy((struct dom_document *) node);
break;
case DOM_DOCUMENT_TYPE_NODE:
/** \todo document type node */
@@ -88,6 +89,9 @@
break;
}
+ /* Release the reference we claimed on the document. If this is
+ * the last reference held on the document and the list of nodes
+ * pending deletion is empty, then the document will be destroyed. */
dom_node_unref((struct dom_node *) owner);
}
@@ -124,7 +128,24 @@
node->next = NULL;
node->attributes = NULL;
- dom_node_ref((struct dom_node *) doc);
+ /* Note: nodes do not reference the document to which they belong,
+ * as this would result in the document never being destroyed once
+ * the client has finished with it. The document will be aware of
+ * any nodes that it owns through 2 mechanisms:
+ *
+ * either a) Membership of the document tree
+ * or b) Membership of the list of nodes pending deletion
+ *
+ * It is not possible for any given node to be a member of both
+ * data structures at the same time.
+ *
+ * The document will not be destroyed until both of these
+ * structures are empty. It will forcibly attempt to empty
+ * the document tree on document destruction. Any still-referenced
+ * nodes at that time will be added to the list of nodes pending
+ * deletion. This list will not be forcibly emptied, as it contains
+ * those nodes (and their sub-trees) in use by client code.
+ */
node->owner = doc;
/** \todo Namespace handling */
@@ -170,7 +191,9 @@
if (node->namespace != NULL)
dom_string_unref(node->namespace);
- dom_node_unref((struct dom_node *) node->owner);
+ /** \todo check if this node is in list of nodes pending deletion.
+ * If so, it must be removed from the list, so the document gets
+ * destroyed once the list is empty (and no longer referenced) */
node->owner = NULL;
/* Paranoia */
16 years, 2 months
r3467 jmb - /trunk/dom/src/core/
by netsurf@semichrome.net
Author: jmb
Date: Sat Jul 28 21:41:41 2007
New Revision: 3467
URL: http://source.netsurf-browser.org?rev=3467&view=rev
Log:
Finalisation and destruction of nodes
Modified:
trunk/dom/src/core/attr.c
trunk/dom/src/core/attr.h
trunk/dom/src/core/cdatasection.c
trunk/dom/src/core/cdatasection.h
trunk/dom/src/core/characterdata.c
trunk/dom/src/core/characterdata.h
trunk/dom/src/core/comment.c
trunk/dom/src/core/comment.h
trunk/dom/src/core/doc_fragment.c
trunk/dom/src/core/doc_fragment.h
trunk/dom/src/core/document.c
trunk/dom/src/core/element.c
trunk/dom/src/core/element.h
trunk/dom/src/core/entity_ref.c
trunk/dom/src/core/entity_ref.h
trunk/dom/src/core/node.c
trunk/dom/src/core/node.h
trunk/dom/src/core/pi.c
trunk/dom/src/core/pi.h
trunk/dom/src/core/text.c
trunk/dom/src/core/text.h
Modified: trunk/dom/src/core/attr.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.c?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/attr.c (original)
+++ trunk/dom/src/core/attr.c Sat Jul 28 21:41:41 2007
@@ -80,6 +80,53 @@
}
/**
+ * Destroy an attribute node
+ *
+ * \param doc The owning document
+ * \param attr The attribute to destroy
+ *
+ * The contents of ::attr will be destroyed and ::attr will be freed
+ */
+void dom_attr_destroy(struct dom_document *doc, struct dom_attr *attr)
+{
+ struct dom_node *c, *d;
+
+ /* Destroy children of this node */
+ for (c = attr->base.first_child; c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this child */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ /* Now, clean up this node and destroy it */
+
+ if (attr->schema_type_info != NULL) {
+ /** \todo destroy schema type info */
+ }
+
+ attr->owner = NULL;
+
+ dom_node_finalise(doc, &attr->base);
+
+ dom_document_alloc(doc, attr, 0);
+}
+
+/**
* Retrieve an attribute's name
*
* \param attr Attribute to retrieve name from
Modified: trunk/dom/src/core/attr.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.h?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/attr.h (original)
+++ trunk/dom/src/core/attr.h Sat Jul 28 21:41:41 2007
@@ -16,5 +16,6 @@
dom_exception dom_attr_create(struct dom_document *doc,
struct dom_string *name, struct dom_attr **result);
+void dom_attr_destroy(struct dom_document *doc, struct dom_attr *attr);
#endif
Modified: trunk/dom/src/core/cdatasection.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/cdatasection.c?rev=3...
==============================================================================
--- trunk/dom/src/core/cdatasection.c (original)
+++ trunk/dom/src/core/cdatasection.c Sat Jul 28 21:41:41 2007
@@ -54,3 +54,21 @@
return DOM_NO_ERR;
}
+
+/**
+ * Destroy a CDATA section
+ *
+ * \param doc The owning document
+ * \param cdata The cdata section to destroy
+ *
+ * The contents of ::cdata will be destroyed and ::cdata will be freed.
+ */
+void dom_cdata_section_destroy(struct dom_document *doc,
+ struct dom_cdata_section *cdata)
+{
+ /* Clean up base node contents */
+ dom_text_finalise(doc, &cdata->base);
+
+ /* Destroy the node */
+ dom_document_alloc(doc, cdata, 0);
+}
Modified: trunk/dom/src/core/cdatasection.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/cdatasection.h?rev=3...
==============================================================================
--- trunk/dom/src/core/cdatasection.h (original)
+++ trunk/dom/src/core/cdatasection.h Sat Jul 28 21:41:41 2007
@@ -18,4 +18,7 @@
struct dom_string *name, struct dom_string *value,
struct dom_cdata_section **result);
+void dom_cdata_section_destroy(struct dom_document *doc,
+ struct dom_cdata_section *cdata);
+
#endif
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Sat Jul 28 21:41:41 2007
@@ -29,6 +29,20 @@
struct dom_string *name, struct dom_string *value)
{
return dom_node_initialise(&cdata->base, doc, type, name, value);
+}
+
+/**
+ * Finalise a character data node
+ *
+ * \param doc The owning document
+ * \param cdata The node to finalise
+ *
+ * The contents of ::cdata will be cleaned up. ::cdata will not be freed.
+ */
+void dom_characterdata_finalise(struct dom_document *doc,
+ struct dom_characterdata *cdata)
+{
+ dom_node_finalise(doc, &cdata->base);
}
/**
Modified: trunk/dom/src/core/characterdata.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.h?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.h (original)
+++ trunk/dom/src/core/characterdata.h Sat Jul 28 21:41:41 2007
@@ -21,4 +21,7 @@
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
+void dom_characterdata_finalise(struct dom_document *doc,
+ struct dom_characterdata *cdata);
+
#endif
Modified: trunk/dom/src/core/comment.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/comment.c?rev=3467&r...
==============================================================================
--- trunk/dom/src/core/comment.c (original)
+++ trunk/dom/src/core/comment.c Sat Jul 28 21:41:41 2007
@@ -54,3 +54,21 @@
return DOM_NO_ERR;
}
+
+/**
+ * Destroy a comment node
+ *
+ * \param doc The owning document
+ * \param comment The node to destroy
+ *
+ * The contents of ::comment will be destroyed and ::comment will be freed
+ */
+void dom_comment_destroy(struct dom_document *doc,
+ struct dom_comment *comment)
+{
+ /* Finalise base class contents */
+ dom_characterdata_finalise(doc, &comment->base);
+
+ /* Free node */
+ dom_document_alloc(doc, comment, 0);
+}
Modified: trunk/dom/src/core/comment.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/comment.h?rev=3467&r...
==============================================================================
--- trunk/dom/src/core/comment.h (original)
+++ trunk/dom/src/core/comment.h Sat Jul 28 21:41:41 2007
@@ -18,4 +18,7 @@
struct dom_string *name, struct dom_string *value,
struct dom_comment **result);
+void dom_comment_destroy(struct dom_document *doc,
+ struct dom_comment *comment);
+
#endif
Modified: trunk/dom/src/core/doc_fragment.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/doc_fragment.c?rev=3...
==============================================================================
--- trunk/dom/src/core/doc_fragment.c (original)
+++ trunk/dom/src/core/doc_fragment.c Sat Jul 28 21:41:41 2007
@@ -55,3 +55,45 @@
return DOM_NO_ERR;
}
+
+/**
+ * Destroy a document fragment
+ *
+ * \param doc The owning document
+ * \param frag The document fragment to destroy
+ *
+ * The contents of ::frag will be destroyed and ::frag will be freed.
+ */
+void dom_document_fragment_destroy(struct dom_document *doc,
+ struct dom_document_fragment *frag)
+{
+ struct dom_node *c, *d;
+
+ /* Destroy children of this node */
+ for (c = frag->base.first_child; c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this child */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ /* Finalise base class */
+ dom_node_finalise(doc, &frag->base);
+
+ /* Destroy fragment */
+ dom_document_alloc(doc, frag, 0);
+}
Modified: trunk/dom/src/core/doc_fragment.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/doc_fragment.h?rev=3...
==============================================================================
--- trunk/dom/src/core/doc_fragment.h (original)
+++ trunk/dom/src/core/doc_fragment.h Sat Jul 28 21:41:41 2007
@@ -18,4 +18,7 @@
struct dom_string *name, struct dom_string *value,
struct dom_document_fragment **result);
+void dom_document_fragment_destroy(struct dom_document *doc,
+ struct dom_document_fragment *frag);
+
#endif
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3467&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sat Jul 28 21:41:41 2007
@@ -15,7 +15,6 @@
#include "core/attr.h"
#include "core/cdatasection.h"
-#include "core/characterdata.h"
#include "core/comment.h"
#include "core/document.h"
#include "core/doc_fragment.h"
Modified: trunk/dom/src/core/element.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.c?rev=3467&r...
==============================================================================
--- trunk/dom/src/core/element.c (original)
+++ trunk/dom/src/core/element.c Sat Jul 28 21:41:41 2007
@@ -62,6 +62,75 @@
*result = el;
return DOM_NO_ERR;
+}
+
+/**
+ * Destroy an element
+ *
+ * \param doc The owning document
+ * \param element The element to destroy
+ *
+ * The contents of ::element will be destroyed and ::element will be freed.
+ */
+void dom_element_destroy(struct dom_document *doc,
+ struct dom_element *element)
+{
+ struct dom_node *c, *d;
+
+ /* Destroy children of this node */
+ for (c = element->base.first_child; c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this child */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ /* Destroy attributes attached to this node */
+ for (c = (struct dom_node *) element->base.attributes;
+ c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this attribute */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ if (element->schema_type_info != NULL) {
+ /** \todo destroy schema type info */
+ }
+
+ /* Finalise base class */
+ dom_node_finalise(doc, &element->base);
+
+ /* Free the element */
+ dom_document_alloc(doc, element, 0);
}
/**
Modified: trunk/dom/src/core/element.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.h?rev=3467&r...
==============================================================================
--- trunk/dom/src/core/element.h (original)
+++ trunk/dom/src/core/element.h Sat Jul 28 21:41:41 2007
@@ -17,4 +17,7 @@
dom_exception dom_element_create(struct dom_document *doc,
struct dom_string *name, struct dom_element **result);
+void dom_element_destroy(struct dom_document *doc,
+ struct dom_element *element);
+
#endif
Modified: trunk/dom/src/core/entity_ref.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/entity_ref.c?rev=346...
==============================================================================
--- trunk/dom/src/core/entity_ref.c (original)
+++ trunk/dom/src/core/entity_ref.c Sat Jul 28 21:41:41 2007
@@ -55,3 +55,45 @@
return DOM_NO_ERR;
}
+
+/**
+ * Destroy an entity reference
+ *
+ * \param doc The owning document
+ * \param entity The entity reference to destroy
+ *
+ * The contents of ::entity will be destroyed and ::entity will be freed.
+ */
+void dom_entity_reference_destroy(struct dom_document *doc,
+ struct dom_entity_reference *entity)
+{
+ struct dom_node *c, *d;
+
+ /* Destroy children of this node */
+ for (c = entity->base.first_child; c != NULL; c = d) {
+ d = c->next;
+
+ /* Detach child */
+ c->parent = NULL;
+
+ if (c->refcnt > 0) {
+ /* Something is using this child */
+
+ /** \todo add to list of nodes pending deletion */
+
+ continue;
+ }
+
+ /* Detach from sibling list */
+ c->previous = NULL;
+ c->next = NULL;
+
+ dom_node_destroy(c);
+ }
+
+ /* Finalise base class */
+ dom_node_finalise(doc, &entity->base);
+
+ /* Destroy fragment */
+ dom_document_alloc(doc, entity, 0);
+}
Modified: trunk/dom/src/core/entity_ref.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/entity_ref.h?rev=346...
==============================================================================
--- trunk/dom/src/core/entity_ref.h (original)
+++ trunk/dom/src/core/entity_ref.h Sat Jul 28 21:41:41 2007
@@ -18,4 +18,7 @@
struct dom_string *name, struct dom_string *value,
struct dom_entity_reference **result);
+void dom_entity_reference_destroy(struct dom_document *doc,
+ struct dom_entity_reference *entity);
+
#endif
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sat Jul 28 21:41:41 2007
@@ -8,9 +8,88 @@
#include <dom/core/document.h>
#include <dom/core/string.h>
+#include "core/attr.h"
+#include "core/cdatasection.h"
+#include "core/comment.h"
#include "core/document.h"
+#include "core/doc_fragment.h"
+#include "core/element.h"
+#include "core/entity_ref.h"
#include "core/node.h"
+#include "core/pi.h"
+#include "core/text.h"
#include "utils/utils.h"
+
+/**
+ * Destroy a DOM node
+ *
+ * \param node The node to destroy
+ *
+ * ::node's parent link must be NULL and its reference count must be 0.
+ *
+ * ::node will be freed.
+ *
+ * This function should only be called from dom_node_unref or type-specific
+ * destructors (for destroying child nodes). Anything else should not
+ * be attempting to destroy nodes -- they should simply be unreferencing
+ * them (so destruction will occur at the appropriate time).
+ */
+void dom_node_destroy(struct dom_node *node)
+{
+ struct dom_document *owner = node->owner;
+
+ /* This function simply acts as a central despatcher
+ * for type-specific destructors. It claims a reference upon the
+ * owning document during destruction to ensure that the document
+ * doesn't get destroyed before its contents. */
+
+ dom_node_ref((struct dom_node *) owner);
+
+ switch (node->type) {
+ case DOM_ELEMENT_NODE:
+ dom_element_destroy(owner, (struct dom_element *) node);
+ break;
+ case DOM_ATTRIBUTE_NODE:
+ dom_attr_destroy(owner, (struct dom_attr *) node);
+ break;
+ case DOM_TEXT_NODE:
+ dom_text_destroy(owner, (struct dom_text *) node);
+ break;
+ case DOM_CDATA_SECTION_NODE:
+ dom_cdata_section_destroy(owner,
+ (struct dom_cdata_section *) node);
+ break;
+ case DOM_ENTITY_REFERENCE_NODE:
+ dom_entity_reference_destroy(owner,
+ (struct dom_entity_reference *) node);
+ break;
+ case DOM_ENTITY_NODE:
+ /** \todo entity node */
+ break;
+ case DOM_PROCESSING_INSTRUCTION_NODE:
+ dom_processing_instruction_destroy(owner,
+ (struct dom_processing_instruction *) node);
+ break;
+ case DOM_COMMENT_NODE:
+ dom_comment_destroy(owner, (struct dom_comment *) node);
+ break;
+ case DOM_DOCUMENT_NODE:
+ /** \todo document node */
+ break;
+ case DOM_DOCUMENT_TYPE_NODE:
+ /** \todo document type node */
+ break;
+ case DOM_DOCUMENT_FRAGMENT_NODE:
+ dom_document_fragment_destroy(owner,
+ (struct dom_document_fragment *) node);
+ break;
+ case DOM_NOTATION_NODE:
+ /** \todo notation node */
+ break;
+ }
+
+ dom_node_unref((struct dom_node *) owner);
+}
/**
* Initialise a DOM node
@@ -61,6 +140,55 @@
}
/**
+ * Finalise a DOM node
+ *
+ * \param doc The owning document
+ * \param node The node to finalise
+ *
+ * The contents of ::node will be cleaned up. ::node will not be freed.
+ * All children of ::node should have been removed prior to finalisation.
+ */
+void dom_node_finalise(struct dom_document *doc, struct dom_node *node)
+{
+ struct dom_user_data *u, *v;
+
+ /* Destroy user data */
+ for (u = node->user_data; u != NULL; u = v) {
+ v = u->next;
+
+ dom_string_unref(u->key);
+
+ dom_document_alloc(doc, u, 0);
+ }
+
+ if (node->localname != NULL)
+ dom_string_unref(node->localname);
+
+ if (node->prefix != NULL)
+ dom_string_unref(node->prefix);
+
+ if (node->namespace != NULL)
+ dom_string_unref(node->namespace);
+
+ dom_node_unref((struct dom_node *) node->owner);
+ node->owner = NULL;
+
+ /* Paranoia */
+ node->attributes = NULL;
+ node->next = NULL;
+ node->previous = NULL;
+ node->last_child = NULL;
+ node->first_child = NULL;
+ node->parent = NULL;
+
+ if (node->value != NULL)
+ dom_string_unref(node->value);
+
+ if (node->name != NULL)
+ dom_string_unref(node->name);
+}
+
+/**
* Claim a reference on a DOM node
*
* \param node The node to claim a reference on
@@ -75,13 +203,16 @@
*
* \param node The node to release the reference from
*
- * If the reference count reaches zero, any memory claimed by the
- * node will be released
+ * If the reference count reaches zero and the node is not part of any
+ * document, any memory claimed by the node will be released.
*/
void dom_node_unref(struct dom_node *node)
{
- if (--node->refcnt == 0) {
- /** \todo implement */
+ if (node->refcnt > 0)
+ node->refcnt--;
+
+ if (node->refcnt == 0 && node->parent == NULL) {
+ dom_node_destroy(node);
}
}
Modified: trunk/dom/src/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.h?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/node.h (original)
+++ trunk/dom/src/core/node.h Sat Jul 28 21:41:41 2007
@@ -52,8 +52,12 @@
uint32_t refcnt; /**< Reference count */
};
+void dom_node_destroy(struct dom_node *node);
+
dom_exception dom_node_initialise(struct dom_node *node,
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
+void dom_node_finalise(struct dom_document *doc, struct dom_node *node);
+
#endif
Modified: trunk/dom/src/core/pi.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/pi.c?rev=3467&r1=346...
==============================================================================
--- trunk/dom/src/core/pi.c (original)
+++ trunk/dom/src/core/pi.c Sat Jul 28 21:41:41 2007
@@ -56,3 +56,21 @@
return DOM_NO_ERR;
}
+
+/**
+ * Destroy a processing instruction
+ *
+ * \param doc The owning document
+ * \param pi The processing instruction to destroy
+ *
+ * The contents of ::pi will be destroyed and ::pi will be freed.
+ */
+void dom_processing_instruction_destroy(struct dom_document *doc,
+ struct dom_processing_instruction *pi)
+{
+ /* Finalise base class */
+ dom_node_finalise(doc, &pi->base);
+
+ /* Free processing instruction */
+ dom_document_alloc(doc, pi, 0);
+}
Modified: trunk/dom/src/core/pi.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/pi.h?rev=3467&r1=346...
==============================================================================
--- trunk/dom/src/core/pi.h (original)
+++ trunk/dom/src/core/pi.h Sat Jul 28 21:41:41 2007
@@ -18,4 +18,7 @@
struct dom_string *name, struct dom_string *value,
struct dom_processing_instruction **result);
+void dom_processing_instruction_destroy(struct dom_document *doc,
+ struct dom_processing_instruction *pi);
+
#endif
Modified: trunk/dom/src/core/text.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.c?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/text.c (original)
+++ trunk/dom/src/core/text.c Sat Jul 28 21:41:41 2007
@@ -52,6 +52,23 @@
}
/**
+ * Destroy a text node
+ *
+ * \param doc The owning document
+ * \param text The text node to destroy
+ *
+ * The contents of ::text will be destroyed and ::text will be freed.
+ */
+void dom_text_destroy(struct dom_document *doc, struct dom_text *text)
+{
+ /* Finalise node */
+ dom_text_finalise(doc, text);
+
+ /* Free node */
+ dom_document_alloc(doc, text, 0);
+}
+
+/**
* Initialise a text node
*
* \param text The node to initialise
@@ -79,6 +96,19 @@
text->element_content_whitespace = false;
return DOM_NO_ERR;
+}
+
+/**
+ * Finalise a text node
+ *
+ * \param doc The owning document
+ * \param text The text node to finalise
+ *
+ * The contents of ::text will be cleaned up. ::text will not be freed.
+ */
+void dom_text_finalise(struct dom_document *doc, struct dom_text *text)
+{
+ dom_characterdata_finalise(doc, &text->base);
}
/**
Modified: trunk/dom/src/core/text.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.h?rev=3467&r1=3...
==============================================================================
--- trunk/dom/src/core/text.h (original)
+++ trunk/dom/src/core/text.h Sat Jul 28 21:41:41 2007
@@ -31,8 +31,12 @@
struct dom_string *name, struct dom_string *value,
struct dom_text **result);
+void dom_text_destroy(struct dom_document *doc, struct dom_text *text);
+
dom_exception dom_text_initialise(struct dom_text *text,
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
+void dom_text_finalise(struct dom_document *doc, struct dom_text *text);
+
#endif
16 years, 2 months
r3466 jmb - in /trunk/dom: include/dom/bootstrap/implpriv.h src/core/document.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Jul 28 18:27:49 2007
New Revision: 3466
URL: http://source.netsurf-browser.org?rev=3466&view=rev
Log:
Add Document constructor
Modified:
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/src/core/document.c
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Sat Jul 28 18:27:49 2007
@@ -244,6 +244,10 @@
dom_exception dom_register_source(struct dom_implementation_source *source,
dom_alloc alloc, void *pw);
+/* Create a DOM document */
+dom_exception dom_document_create(struct dom_implementation *impl,
+ dom_alloc alloc, void *pw, struct dom_document **doc);
+
/* Set a Document's DocumentType */
dom_exception dom_document_set_doctype(struct dom_document *doc,
struct dom_document_type *doctype);
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3466&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sat Jul 28 18:27:49 2007
@@ -5,9 +5,13 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+#include <string.h>
+
#include <dom/functypes.h>
#include <dom/bootstrap/implpriv.h>
#include <dom/core/document.h>
+#include <dom/core/implementation.h>
+#include <dom/core/string.h>
#include "core/attr.h"
#include "core/cdatasection.h"
@@ -54,16 +58,115 @@
struct dom_document_type *type; /**< Associated doctype */
+ struct dom_implementation *impl; /**< Owning implementation */
+
struct dom_doc_nl *nodelists; /**< List of active nodelists */
struct dom_doc_nnm *maps; /**< List of active namednodemaps */
/** Interned node name strings, indexed by node type */
- struct dom_string *nodenames[DOM_NODE_TYPE_COUNT];
+ /* Index 0 is unused */
+ struct dom_string *nodenames[DOM_NODE_TYPE_COUNT + 1];
dom_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
};
+
+/**
+ * Create a Document
+ *
+ * \param impl The DOM implementation owning the document
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \param doc Pointer to location to receive created document
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::impl will have its reference count increased.
+ *
+ * The returned document will already be referenced.
+ */
+dom_exception dom_document_create(struct dom_implementation *impl,
+ dom_alloc alloc, void *pw, struct dom_document **doc)
+{
+ static const char *names[DOM_NODE_TYPE_COUNT + 1] = {
+ NULL, /* Unused */
+ NULL, /* Element */
+ NULL, /* Attr */
+ "#text", /* Text */
+ "#cdata-section", /* CDATA section */
+ NULL, /* Entity reference */
+ NULL, /* Entity */
+ NULL, /* Processing instruction */
+ "#comment", /* Comment */
+ "#document", /* Document */
+ NULL, /* Document type */
+ "#document-fragment", /* Document fragment */
+ NULL /* Notation */
+ };
+ struct dom_document *d;
+ dom_exception err;
+
+ /* Create document */
+ d = alloc(NULL, sizeof(struct dom_document), pw);
+ if (d == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up document allocation context - must be first */
+ d->alloc = alloc;
+ d->pw = pw;
+
+ /* Initialise interned node names */
+ for (int i = 0; i <= DOM_NODE_TYPE_COUNT; i++) {
+ if (names[i] == NULL) {
+ /* Nothing to intern; skip this entry */
+ d->nodenames[i] = NULL;
+ continue;
+ }
+
+ /* Make string */
+ err = dom_string_create_from_const_ptr(d,
+ (const uint8_t *) names[i],
+ strlen(names[i]), &d->nodenames[i]);
+ if (err != DOM_NO_ERR) {
+ /* Failed, clean up strings we've created so far */
+ for (int j = 0; j < i; j++) {
+ if (d->nodenames[i] != NULL)
+ dom_string_unref(d->nodenames[i]);
+ }
+ /* And destroy document */
+ alloc(d, 0, pw);
+ return err;
+ }
+ }
+
+ /* Initialise base class */
+ err = dom_node_initialise(&d->base, d, DOM_DOCUMENT_NODE,
+ NULL, NULL);
+ if (err != DOM_NO_ERR) {
+ /* Clean up interned strings */
+ for (int i = 0; i <= DOM_NODE_TYPE_COUNT; i++) {
+ if (d->nodenames[i] != NULL)
+ dom_string_unref(d->nodenames[i]);
+ }
+ /* And document */
+ alloc(d, 0, pw);
+ return err;
+ }
+
+ /* Initialise remaining type-specific data */
+ d->type = NULL;
+
+ if (impl != NULL)
+ dom_implementation_ref(impl);
+ d->impl = impl;
+
+ d->nodelists = NULL;
+ d->maps = NULL;
+
+ *doc = d;
+
+ return DOM_NO_ERR;
+}
/**
* Retrieve the doctype of a document
@@ -252,8 +355,6 @@
struct dom_string *data,
struct dom_processing_instruction **result)
{
- /** \todo is the use of target as the node name correct? */
-
return dom_processing_instruction_create(doc, target, data, result);
}
16 years, 2 months
r3465 jmb - in /trunk/dom: bindings/xml/ include/dom/core/ src/core/
by netsurf@semichrome.net
Author: jmb
Date: Sat Jul 28 15:34:59 2007
New Revision: 3465
URL: http://source.netsurf-browser.org?rev=3465&view=rev
Log:
Sort out somewhat messy object construction.
We now have explicit types for all classes (rather than using the parent class for those which inherit but add no extra data content).
Added:
trunk/dom/src/core/cdatasection.c
trunk/dom/src/core/cdatasection.h
trunk/dom/src/core/comment.c
trunk/dom/src/core/comment.h
trunk/dom/src/core/doc_fragment.c
trunk/dom/src/core/doc_fragment.h
trunk/dom/src/core/entity_ref.c
trunk/dom/src/core/entity_ref.h
trunk/dom/src/core/pi.c
trunk/dom/src/core/pi.h
Modified:
trunk/dom/bindings/xml/xmlparser.c
trunk/dom/include/dom/core/document.h
trunk/dom/src/core/Makefile
trunk/dom/src/core/characterdata.c
trunk/dom/src/core/characterdata.h
trunk/dom/src/core/document.c
trunk/dom/src/core/node.c
trunk/dom/src/core/node.h
trunk/dom/src/core/text.c
trunk/dom/src/core/text.h
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sat Jul 28 15:34:59 2007
@@ -873,7 +873,7 @@
void xml_parser_add_cdata_section(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
- struct dom_text *cdata, *ins_cdata;
+ struct dom_cdata_section *cdata, *ins_cdata;
struct dom_string *data;
dom_exception err;
@@ -927,7 +927,7 @@
void xml_parser_add_entity_reference(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
- struct dom_node *entity, *ins_entity;
+ struct dom_entity_reference *entity, *ins_entity;
struct dom_string *name;
xmlNodePtr c;
dom_exception err;
@@ -988,7 +988,7 @@
void xml_parser_add_comment(xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
- struct dom_characterdata *comment, *ins_comment;
+ struct dom_comment *comment, *ins_comment;
struct dom_string *data;
dom_exception err;
Modified: trunk/dom/include/dom/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/document.h?r...
==============================================================================
--- trunk/dom/include/dom/core/document.h (original)
+++ trunk/dom/include/dom/core/document.h Sat Jul 28 15:34:59 2007
@@ -13,14 +13,19 @@
#include <dom/core/exceptions.h>
struct dom_attr;
+struct dom_cdata_section;
struct dom_characterdata;
+struct dom_comment;
struct dom_configuration;
struct dom_document;
+struct dom_document_fragment;
struct dom_document_type;
struct dom_element;
+struct dom_entity_reference;
struct dom_implementation;
struct dom_node;
struct dom_nodelist;
+struct dom_processing_instruction;
struct dom_string;
struct dom_text;
@@ -33,20 +38,22 @@
dom_exception dom_document_create_element(struct dom_document *doc,
struct dom_string *tag_name, struct dom_element **result);
dom_exception dom_document_create_document_fragment(struct dom_document *doc,
- struct dom_node **result);
+ struct dom_document_fragment **result);
dom_exception dom_document_create_text_node(struct dom_document *doc,
struct dom_string *data, struct dom_text **result);
dom_exception dom_document_create_comment(struct dom_document *doc,
- struct dom_string *data, struct dom_characterdata **result);
+ struct dom_string *data, struct dom_comment **result);
dom_exception dom_document_create_cdata_section(struct dom_document *doc,
- struct dom_string *data, struct dom_text **result);
+ struct dom_string *data, struct dom_cdata_section **result);
dom_exception dom_document_create_processing_instruction(
struct dom_document *doc, struct dom_string *target,
- struct dom_string *data, struct dom_node **result);
+ struct dom_string *data,
+ struct dom_processing_instruction **result);
dom_exception dom_document_create_attribute(struct dom_document *doc,
struct dom_string *name, struct dom_attr **result);
dom_exception dom_document_create_entity_reference(struct dom_document *doc,
- struct dom_string *name, struct dom_node **result);
+ struct dom_string *name,
+ struct dom_entity_reference **result);
dom_exception dom_document_get_elements_by_tag_name(struct dom_document *doc,
struct dom_string *tagname, struct dom_nodelist **result);
dom_exception dom_document_import_node(struct dom_document *doc,
Modified: trunk/dom/src/core/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/core/Makefile?rev=3465&r1...
==============================================================================
--- trunk/dom/src/core/Makefile (original)
+++ trunk/dom/src/core/Makefile Sat Jul 28 15:34:59 2007
@@ -22,8 +22,11 @@
CFLAGS += -I$(CURDIR)
# Objects
-OBJS = attr characterdata document document_type element implementation impllist \
- namednodemap node nodelist string text
+OBJS = attr cdatasection characterdata comment \
+ document document_type doc_fragment \
+ element entity_ref implementation impllist \
+ namednodemap node nodelist \
+ pi string text
.PHONY: clean debug distclean export release setup test
Added: trunk/dom/src/core/cdatasection.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/cdatasection.c?rev=3...
==============================================================================
--- trunk/dom/src/core/cdatasection.c (added)
+++ trunk/dom/src/core/cdatasection.c Sat Jul 28 15:34:59 2007
@@ -1,0 +1,56 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include "core/cdatasection.h"
+#include "core/document.h"
+#include "core/text.h"
+
+/**
+ * A DOM CDATA section
+ */
+struct dom_cdata_section {
+ struct dom_text base; /**< Base node */
+};
+
+/**
+ * Create a CDATA section
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_cdata_section_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_cdata_section **result)
+{
+ struct dom_cdata_section *c;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ c = dom_document_alloc(doc, NULL, sizeof(struct dom_cdata_section));
+ if (c == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_text_initialise(&c->base, doc, DOM_CDATA_SECTION_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, c, 0);
+ return err;
+ }
+
+ *result = c;
+
+ return DOM_NO_ERR;
+}
Added: trunk/dom/src/core/cdatasection.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/cdatasection.h?rev=3...
==============================================================================
--- trunk/dom/src/core/cdatasection.h (added)
+++ trunk/dom/src/core/cdatasection.h Sat Jul 28 15:34:59 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_cdatasection_h_
+#define dom_internal_core_cdatasection_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_cdata_section;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_cdata_section_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_cdata_section **result);
+
+#endif
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Sat Jul 28 15:34:59 2007
@@ -11,45 +11,6 @@
#include "core/characterdata.h"
#include "core/document.h"
#include "utils/utils.h"
-
-/**
- * Create a character data node of the given type
- *
- * \param doc The owning document
- * \param type The type of node to create
- * \param name The node name, or NULL
- * \param value The node value, or NULL
- * \param result Pointer to location to receive created node
- * \return DOM_NO_ERR on success, appropriate error otherwise
- *
- * ::doc, ::name and ::value will have their reference counts increased.
- *
- * The created node will already be referenced.
- */
-dom_exception dom_characterdata_create(struct dom_document *doc,
- dom_node_type type, struct dom_string *name,
- struct dom_string *value, struct dom_characterdata **result)
-{
- struct dom_characterdata *cdata;
- dom_exception err;
-
- /* Allocate object */
- cdata = dom_document_alloc(doc, NULL,
- sizeof(struct dom_characterdata));
- if (cdata == NULL)
- return DOM_NO_MEM_ERR;
-
- /* Initialise node contents */
- err = dom_characterdata_initialise(cdata, doc, type, name, value);
- if (err != DOM_NO_ERR) {
- dom_document_alloc(doc, cdata, 0);
- return err;
- }
-
- *result = cdata;
-
- return DOM_NO_ERR;
-}
/**
* Initialise a character data node
Modified: trunk/dom/src/core/characterdata.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.h?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.h (original)
+++ trunk/dom/src/core/characterdata.h Sat Jul 28 15:34:59 2007
@@ -17,10 +17,6 @@
struct dom_node base; /**< Base node */
};
-dom_exception dom_characterdata_create(struct dom_document *doc,
- dom_node_type type, struct dom_string *name,
- struct dom_string *value, struct dom_characterdata **result);
-
dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata,
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
Added: trunk/dom/src/core/comment.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/comment.c?rev=3465&v...
==============================================================================
--- trunk/dom/src/core/comment.c (added)
+++ trunk/dom/src/core/comment.c Sat Jul 28 15:34:59 2007
@@ -1,0 +1,56 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include "core/characterdata.h"
+#include "core/comment.h"
+#include "core/document.h"
+
+/**
+ * A DOM comment node
+ */
+struct dom_comment {
+ struct dom_characterdata base; /**< Base node */
+};
+
+/**
+ * Create a comment node
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_comment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_comment **result)
+{
+ struct dom_comment *c;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ c = dom_document_alloc(doc, NULL, sizeof(struct dom_comment));
+ if (c == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_characterdata_initialise(&c->base, doc, DOM_COMMENT_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, c, 0);
+ return err;
+ }
+
+ *result = c;
+
+ return DOM_NO_ERR;
+}
Added: trunk/dom/src/core/comment.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/comment.h?rev=3465&v...
==============================================================================
--- trunk/dom/src/core/comment.h (added)
+++ trunk/dom/src/core/comment.h Sat Jul 28 15:34:59 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_comment_h_
+#define dom_internal_core_comment_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_comment;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_comment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_comment **result);
+
+#endif
Added: trunk/dom/src/core/doc_fragment.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/doc_fragment.c?rev=3...
==============================================================================
--- trunk/dom/src/core/doc_fragment.c (added)
+++ trunk/dom/src/core/doc_fragment.c Sat Jul 28 15:34:59 2007
@@ -1,0 +1,57 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/doc_fragment.h"
+#include "core/node.h"
+
+/**
+ * A DOM document fragment
+ */
+struct dom_document_fragment {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create a document fragment
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_document_fragment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_document_fragment **result)
+{
+ struct dom_document_fragment *f;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ f = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_document_fragment));
+ if (f == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&f->base, doc, DOM_DOCUMENT_FRAGMENT_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, f, 0);
+ return err;
+ }
+
+ *result = f;
+
+ return DOM_NO_ERR;
+}
Added: trunk/dom/src/core/doc_fragment.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/doc_fragment.h?rev=3...
==============================================================================
--- trunk/dom/src/core/doc_fragment.h (added)
+++ trunk/dom/src/core/doc_fragment.h Sat Jul 28 15:34:59 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_documentfragment_h_
+#define dom_internal_core_documentfragment_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document_fragment;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_document_fragment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_document_fragment **result);
+
+#endif
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3465&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sat Jul 28 15:34:59 2007
@@ -10,12 +10,17 @@
#include <dom/core/document.h>
#include "core/attr.h"
+#include "core/cdatasection.h"
#include "core/characterdata.h"
+#include "core/comment.h"
#include "core/document.h"
+#include "core/doc_fragment.h"
#include "core/element.h"
+#include "core/entity_ref.h"
#include "core/namednodemap.h"
#include "core/node.h"
#include "core/nodelist.h"
+#include "core/pi.h"
#include "core/text.h"
#include "utils/utils.h"
@@ -161,9 +166,9 @@
* finished with it.
*/
dom_exception dom_document_create_document_fragment(struct dom_document *doc,
- struct dom_node **result)
-{
- return dom_node_create(doc, DOM_DOCUMENT_FRAGMENT_NODE,
+ struct dom_document_fragment **result)
+{
+ return dom_document_fragment_create(doc,
doc->nodenames[DOM_DOCUMENT_FRAGMENT_NODE],
NULL, result);
}
@@ -183,8 +188,8 @@
dom_exception dom_document_create_text_node(struct dom_document *doc,
struct dom_string *data, struct dom_text **result)
{
- return dom_text_create(doc, DOM_TEXT_NODE,
- doc->nodenames[DOM_TEXT_NODE], data, result);
+ return dom_text_create(doc, doc->nodenames[DOM_TEXT_NODE],
+ data, result);
}
/**
@@ -200,10 +205,10 @@
* finished with it.
*/
dom_exception dom_document_create_comment(struct dom_document *doc,
- struct dom_string *data, struct dom_characterdata **result)
-{
- return dom_characterdata_create(doc, DOM_COMMENT_NODE,
- doc->nodenames[DOM_COMMENT_NODE], data, result);
+ struct dom_string *data, struct dom_comment **result)
+{
+ return dom_comment_create(doc, doc->nodenames[DOM_COMMENT_NODE],
+ data, result);
}
/**
@@ -220,9 +225,9 @@
* finished with it.
*/
dom_exception dom_document_create_cdata_section(struct dom_document *doc,
- struct dom_string *data, struct dom_text **result)
-{
- return dom_text_create(doc, DOM_CDATA_SECTION_NODE,
+ struct dom_string *data, struct dom_cdata_section **result)
+{
+ return dom_cdata_section_create(doc,
doc->nodenames[DOM_CDATA_SECTION_NODE],
data, result);
}
@@ -245,12 +250,11 @@
dom_exception dom_document_create_processing_instruction(
struct dom_document *doc, struct dom_string *target,
struct dom_string *data,
- struct dom_node **result)
+ struct dom_processing_instruction **result)
{
/** \todo is the use of target as the node name correct? */
- return dom_node_create(doc, DOM_PROCESSING_INSTRUCTION_NODE,
- target, data, result);
+ return dom_processing_instruction_create(doc, target, data, result);
}
/**
@@ -287,10 +291,10 @@
* finished with it.
*/
dom_exception dom_document_create_entity_reference(struct dom_document *doc,
- struct dom_string *name, struct dom_node **result)
-{
- return dom_node_create(doc, DOM_ENTITY_REFERENCE_NODE,
- name, NULL, result);
+ struct dom_string *name,
+ struct dom_entity_reference **result)
+{
+ return dom_entity_reference_create(doc, name, NULL, result);
}
/**
Added: trunk/dom/src/core/entity_ref.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/entity_ref.c?rev=346...
==============================================================================
--- trunk/dom/src/core/entity_ref.c (added)
+++ trunk/dom/src/core/entity_ref.c Sat Jul 28 15:34:59 2007
@@ -1,0 +1,57 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/entity_ref.h"
+#include "core/node.h"
+
+/**
+ * A DOM entity reference
+ */
+struct dom_entity_reference {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create an entity reference
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_entity_reference_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_entity_reference **result)
+{
+ struct dom_entity_reference *e;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ e = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_entity_reference));
+ if (e == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&e->base, doc, DOM_ENTITY_REFERENCE_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, e, 0);
+ return err;
+ }
+
+ *result = e;
+
+ return DOM_NO_ERR;
+}
Added: trunk/dom/src/core/entity_ref.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/entity_ref.h?rev=346...
==============================================================================
--- trunk/dom/src/core/entity_ref.h (added)
+++ trunk/dom/src/core/entity_ref.h Sat Jul 28 15:34:59 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_entityreference_h_
+#define dom_internal_core_entityreference_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_entity_reference;
+struct dom_string;
+
+dom_exception dom_entity_reference_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_entity_reference **result);
+
+#endif
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3465&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sat Jul 28 15:34:59 2007
@@ -11,65 +11,6 @@
#include "core/document.h"
#include "core/node.h"
#include "utils/utils.h"
-
-/**
- * Create a DOM node of the given type
- *
- * \param doc The owning document
- * \param type The type of node to create
- * \param name The node name, or NULL
- * \param value The node value, or NULL
- * \param result Pointer to location to receive created node
- * \return DOM_NO_ERR on success, appropriate error otherwise
- *
- * ::doc, ::name and ::value will have their reference counts increased.
- *
- * The created node will already be referenced.
- */
-dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
- struct dom_string *name, struct dom_string *value,
- struct dom_node **result)
-{
- struct dom_node *node;
- dom_exception err;
-
- /* If there's a type-specific constructor, use that */
- switch (type) {
- case DOM_ELEMENT_NODE:
- return dom_document_create_element(doc, name,
- (struct dom_element **) result);
- case DOM_ATTRIBUTE_NODE:
- return dom_document_create_attribute(doc, name,
- (struct dom_attr **) result);
- case DOM_TEXT_NODE:
- return dom_document_create_text_node(doc, value,
- (struct dom_text **) result);
- case DOM_CDATA_SECTION_NODE:
- return dom_document_create_cdata_section(doc, value,
- (struct dom_text **) result);
- case DOM_COMMENT_NODE:
- return dom_document_create_comment(doc, value,
- (struct dom_characterdata **) result);
- default:
- break;
- }
-
- /* Otherwise, this is a generic node, so build it ourselves */
- node = dom_document_alloc(doc, NULL, sizeof(struct dom_node));
- if (node == NULL)
- return DOM_NO_MEM_ERR;
-
- /* Initialise node contents */
- err = dom_node_initialise(node, doc, type, name, value);
- if (err != DOM_NO_ERR) {
- dom_document_alloc(doc, node, 0);
- return err;
- }
-
- *result = node;
-
- return DOM_NO_ERR;
-}
/**
* Initialise a DOM node
Modified: trunk/dom/src/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.h?rev=3465&r1=3...
==============================================================================
--- trunk/dom/src/core/node.h (original)
+++ trunk/dom/src/core/node.h Sat Jul 28 15:34:59 2007
@@ -52,10 +52,6 @@
uint32_t refcnt; /**< Reference count */
};
-dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
- struct dom_string *name, struct dom_string *value,
- struct dom_node **result);
-
dom_exception dom_node_initialise(struct dom_node *node,
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
Added: trunk/dom/src/core/pi.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/pi.c?rev=3465&view=auto
==============================================================================
--- trunk/dom/src/core/pi.c (added)
+++ trunk/dom/src/core/pi.c Sat Jul 28 15:34:59 2007
@@ -1,0 +1,58 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/node.h"
+#include "core/pi.h"
+
+/**
+ * A DOM processing instruction
+ */
+struct dom_processing_instruction {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create a processing instruction
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_processing_instruction_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_processing_instruction **result)
+{
+ struct dom_processing_instruction *p;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ p = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_processing_instruction));
+ if (p == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&p->base, doc,
+ DOM_PROCESSING_INSTRUCTION_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, p, 0);
+ return err;
+ }
+
+ *result = p;
+
+ return DOM_NO_ERR;
+}
Added: trunk/dom/src/core/pi.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/pi.h?rev=3465&view=auto
==============================================================================
--- trunk/dom/src/core/pi.h (added)
+++ trunk/dom/src/core/pi.h Sat Jul 28 15:34:59 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_processinginstruction_h_
+#define dom_internal_core_processinginstruction_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_processing_instruction;
+struct dom_string;
+
+dom_exception dom_processing_instruction_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_processing_instruction **result);
+
+#endif
Modified: trunk/dom/src/core/text.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.c?rev=3465&r1=3...
==============================================================================
--- trunk/dom/src/core/text.c (original)
+++ trunk/dom/src/core/text.c Sat Jul 28 15:34:59 2007
@@ -14,20 +14,9 @@
#include "utils/utils.h"
/**
- * A DOM text node
- */
-struct dom_text {
- struct dom_characterdata base; /**< Base node */
-
- bool element_content_whitespace; /**< This node is element
- * content whitespace */
-};
-
-/**
* Create a text node
*
* \param doc The owning document
- * \param type The type of text node to create
* \param name The name of the node to create
* \param value The text content of the node
* \param result Pointer to location to receive created node
@@ -38,29 +27,56 @@
*
* The returned node will already be referenced.
*/
-dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+dom_exception dom_text_create(struct dom_document *doc,
struct dom_string *name, struct dom_string *value,
struct dom_text **result)
{
struct dom_text *t;
dom_exception err;
- /* Allocate the element */
+ /* Allocate the text node */
t = dom_document_alloc(doc, NULL, sizeof(struct dom_text));
if (t == NULL)
return DOM_NO_MEM_ERR;
- /* Initialise the base class */
- err = dom_characterdata_initialise(&t->base, doc, type, name, value);
+ /* And initialise the node */
+ err = dom_text_initialise(t, doc, DOM_TEXT_NODE, name, value);
if (err != DOM_NO_ERR) {
dom_document_alloc(doc, t, 0);
return err;
}
+ *result = t;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Initialise a text node
+ *
+ * \param text The node to initialise
+ * \param doc The owning document
+ * \param type The type of the node
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \return DOM_NO_ERR on success.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ */
+dom_exception dom_text_initialise(struct dom_text *text,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value)
+{
+ dom_exception err;
+
+ /* Initialise the base class */
+ err = dom_characterdata_initialise(&text->base, doc, type,
+ name, value);
+ if (err != DOM_NO_ERR)
+ return err;
+
/* Perform our type-specific initialisation */
- t->element_content_whitespace = false;
-
- *result = t;
+ text->element_content_whitespace = false;
return DOM_NO_ERR;
}
Modified: trunk/dom/src/core/text.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.h?rev=3465&r1=3...
==============================================================================
--- trunk/dom/src/core/text.h (original)
+++ trunk/dom/src/core/text.h Sat Jul 28 15:34:59 2007
@@ -8,16 +8,31 @@
#ifndef dom_internal_core_text_h_
#define dom_internal_core_text_h_
+#include <stdbool.h>
+
#include <dom/core/exceptions.h>
-#include "core/node.h"
+#include "core/characterdata.h"
struct dom_document;
struct dom_string;
-struct dom_text;
-dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+/**
+ * A DOM text node
+ */
+struct dom_text {
+ struct dom_characterdata base; /**< Base node */
+
+ bool element_content_whitespace; /**< This node is element
+ * content whitespace */
+};
+
+dom_exception dom_text_create(struct dom_document *doc,
struct dom_string *name, struct dom_string *value,
struct dom_text **result);
+dom_exception dom_text_initialise(struct dom_text *text,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value);
+
#endif
16 years, 2 months
r3464 jshaw - /trunk/dom/test/transform/test-to-c.xsl
by netsurf@semichrome.net
Author: jshaw
Date: Fri Jul 27 23:45:47 2007
New Revision: 3464
URL: http://source.netsurf-browser.org?rev=3464&view=rev
Log:
Improve infrastructure for generating parameters for method calls. Stub out guess-var-or-literal-type template.
Modified:
trunk/dom/test/transform/test-to-c.xsl
Modified: trunk/dom/test/transform/test-to-c.xsl
URL: http://source.netsurf-browser.org/trunk/dom/test/transform/test-to-c.xsl?...
==============================================================================
--- trunk/dom/test/transform/test-to-c.xsl (original)
+++ trunk/dom/test/transform/test-to-c.xsl Fri Jul 27 23:45:47 2007
@@ -184,12 +184,15 @@
<xsl:when test="@interface">
<xsl:variable name="interface" select="@interface"/>
<xsl:call-template name="produce-specific-method">
+ <!-- TODO: move vardefs up -->
+ <xsl:with-param name="vardefs" select="//*[local-name() = 'var']"/>
<xsl:with-param name="method" select="$domspec/library/interface[@name = $interface]/method[@name = $methodName]"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="methods" select="$domspec/library/interface/method[@name = $methodName]"/>
<xsl:call-template name="produce-specific-method">
+ <xsl:with-param name="vardefs" select="//*[local-name() = 'var']"/>
<xsl:with-param name="method" select="$methods[1]"/>
</xsl:call-template>
</xsl:otherwise>
@@ -258,7 +261,6 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- <xsl:message>attribute-cname: <xsl:value-of select="$attribute-cname"/></xsl:message>
<!--
The attribute type. This is either $attribute/@type, or
@@ -309,7 +311,152 @@
</xsl:template>
<xsl:template name="produce-specific-method">
+ <xsl:param name="vardefs"/>
+
+ <!-- a <method> from $domspec -->
<xsl:param name="method"/>
+
+ <!-- the current context node -->
+ <xsl:variable name="current-node" select="."/>
+
+ <!-- the object which contains the attribute -->
+ <xsl:variable name="obj" select="@obj"/>
+
+ <!-- the <var> for the $obj -->
+ <xsl:variable name="obj-var" select="//*[local-name() = 'var' and @name = $obj]"/>
+
+ <!-- the C-type on which the method is called -->
+ <xsl:variable name="interface-ctype">
+ <xsl:call-template name="get-ctype">
+ <xsl:with-param name="type" select="$method/parent::interface/@name"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="method-cname">
+ <xsl:choose>
+ <xsl:when test="$ctypes/types/type[@c = $interface-ctype]/method[@idl = $method/@name]/@c">
+ <xsl:value-of select="$ctypes/types/type[@c = $interface-ctype]/method[@idl = $method/@name]/@c"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$method/@name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- setup variables to hold parameter literals (for DOMStrings) -->
+ <xsl:for-each select="$method/parameters/param">
+ <xsl:variable name="paramDef" select="."/>
+ <xsl:variable name="value" select="$current-node/@*[name() = $paramDef/@name]"/>
+
+ <xsl:if test="starts-with($value, '"')">
+
+ <xsl:call-template name="produce-dom-string">
+ <xsl:with-param name="vardefs" select="$vardefs"/>
+
+ <!-- FIXME: xsl:number isn't sufficient to guarantee global uniqueness -->
+ <xsl:with-param name="var-name"><xsl:text>domString</xsl:text><xsl:number/></xsl:with-param>
+ <xsl:with-param name="string" select="$value"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+
+ <!-- function call -->
+ <xsl:text> err = </xsl:text>
+ <xsl:value-of select="$interface-ctype"/>
+ <xsl:text>_</xsl:text>
+ <xsl:value-of select="$method-cname"/>
+ <xsl:text>(</xsl:text>
+
+ <!-- the object to invoke the method upon -->
+ <xsl:call-template name="cast">
+ <xsl:with-param name="var-type" select="$obj-var/@type"/>
+ <xsl:with-param name="interface-type" select="$method/parent::interface/@name"/>
+ </xsl:call-template>
+ <xsl:value-of select="$obj"/>
+
+ <!-- method parameters -->
+ <xsl:for-each select="$method/parameters/param">
+ <xsl:variable name="paramDef" select="."/>
+ <xsl:variable name="value" select="$current-node/@*[name() = $paramDef/@name]"/>
+
+ <xsl:text>, </xsl:text>
+ <!-- TODO: cast, also, need to handle stuff like string constants (need turning into DOMStrings) -->
+
+ <xsl:call-template name="produce-param">
+ <xsl:with-param name="vardefs" select="$vardefs"/>
+ <xsl:with-param name="var-or-literal" select="$value"/>
+ <xsl:with-param name="interface-type" select="./@type"/>
+ </xsl:call-template>
+ </xsl:for-each>
+
+ <!-- return variable -->
+ <xsl:if test="@var">
+ <xsl:variable name="var" select="@var"/>
+
+ <!-- the <var> for the variable $var -->
+ <xsl:variable name="var-var" select="//*[local-name() = 'var' and @name = $var]"/>
+
+ <xsl:text>, </xsl:text>
+ <xsl:call-template name="cast">
+ <xsl:with-param name="var-type" select="$var-var/@type"/>
+ <xsl:with-param name="interface-type" select="$method/returns/@type"/>
+ </xsl:call-template>
+ <xsl:text>&</xsl:text>
+ <xsl:value-of select="$var"/>
+ </xsl:if>
+ <xsl:text>);</xsl:text>
+ <xsl:text>
+ assert(err == DOM_NO_ERR);
+</xsl:text>
+</xsl:template>
+
+<xsl:template name="produce-param">
+ <xsl:param name="vardefs"/>
+
+ <!-- a string that may be a literal or a variable name -->
+ <xsl:param name="var-or-literal"/>
+
+ <!-- the parameter's expected type -->
+ <xsl:param name="interface-type"/>
+
+ <!-- the IDL type of $var-or-literal -->
+ <xsl:variable name="var-type">
+ <xsl:call-template name="guess-var-or-literal-type">
+ <xsl:with-param name="vardefs" select="$vardefs"/>
+ <xsl:with-param name="var-or-literal" select="$var-or-literal"/>
+ <xsl:with-param name="interface-type" select="$interface-type"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="$var-type = 'DOMString'">
+ <!--
+ TODO use the dom_string that was generated for this param
+ before the method call. somehow need to link the unique
+ identifier used there so that we can reference it here. -->
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="cast">
+ <xsl:with-param name="var-type" select="$var-type"/>
+ <xsl:with-param name="interface-type" select="$interface-type"/>
+ </xsl:call-template>
+ <xsl:value-of select="$var-or-literal"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+</xsl:template>
+
+<!-- guesses at the IDL type of the supplied var or literal -->
+<xsl:template name="guess-var-or-literal-type">
+ <xsl:param name="vardefs"/>
+
+ <!-- the variable name or literal -->
+ <xsl:param name="var-or-literal"/>
+
+ <!-- the expected type of $var-or-literal -->
+ <xsl:param name="interface-type"/>
+
+ <!-- FIXME implement me -->
</xsl:template>
<xsl:template name="cast">
@@ -341,25 +488,6 @@
<xsl:text>) </xsl:text>
</xsl:if>
</xsl:template>
-
-<xsl:template name="get-ctype">
- <!--
- a type (e.g. Document, dom_node_type or int)
- if $type is already a C-style type, or was a primitive, this is
- used instead
- -->
- <xsl:param name="type"/>
-
- <xsl:choose>
- <xsl:when test="$ctypes/types/type[@idl = $type]/@c">
- <xsl:value-of select="$ctypes/types/type[@idl = $type]/@c"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$type"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
<!--
================================
@@ -415,6 +543,52 @@
<xsl:otherwise>
<xsl:value-of select="$var-ctype"/>
<xsl:text> *</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="produce-dom-string">
+ <xsl:param name="vardefs"/>
+
+ <!-- the variable name for the dom_string -->
+ <xsl:param name="var-name"/>
+
+ <!-- The string literal. Should already be enclosed in double quotes. -->
+ <xsl:param name="string"/>
+
+ <!-- a list of all Document variables -->
+ <xsl:variable name="docs" select="$vardefs[@type = 'Document']"/>
+
+ <xsl:text>
+ struct dom_string *</xsl:text><xsl:value-of select="$var-name"/>
+ <xsl:text>;
+ err = dom_string_create_from_const_ptr(</xsl:text>
+ <xsl:value-of select="$docs[1]/@name"/>
+ <xsl:text>, (uint8_t *) </xsl:text>
+ <xsl:value-of select="$string"/>
+ <xsl:text>, SLEN(</xsl:text>
+ <xsl:value-of select="$string"/>
+ <xsl:text>), &</xsl:text>
+ <xsl:value-of select="$var-name"/>
+ <xsl:text>);
+ assert(err == DOM_NO_ERR);
+</xsl:text>
+</xsl:template>
+
+<xsl:template name="get-ctype">
+ <!--
+ a type (e.g. Document, dom_node_type or int)
+ if $type is already a C-style type, or was a primitive, this is
+ used instead
+ -->
+ <xsl:param name="type"/>
+
+ <xsl:choose>
+ <xsl:when test="$ctypes/types/type[@idl = $type]/@c">
+ <xsl:value-of select="$ctypes/types/type[@idl = $type]/@c"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$type"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
16 years, 2 months
r3463 jmb - in /trunk/dom: include/dom/core/ src/core/
by netsurf@semichrome.net
Author: jmb
Date: Thu Jul 26 23:19:48 2007
New Revision: 3463
URL: http://source.netsurf-browser.org?rev=3463&view=rev
Log:
Implement type-specific node constructors and veneer the appropriate Document APIs onto them.
Added:
trunk/dom/src/core/attr.h
trunk/dom/src/core/element.h
trunk/dom/src/core/text.h
Modified:
trunk/dom/include/dom/core/node.h
trunk/dom/src/core/attr.c
trunk/dom/src/core/characterdata.c
trunk/dom/src/core/characterdata.h
trunk/dom/src/core/document.c
trunk/dom/src/core/document.h
trunk/dom/src/core/element.c
trunk/dom/src/core/namednodemap.h
trunk/dom/src/core/node.c
trunk/dom/src/core/node.h
trunk/dom/src/core/nodelist.h
trunk/dom/src/core/text.c
Modified: trunk/dom/include/dom/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/node.h?rev=3...
==============================================================================
--- trunk/dom/include/dom/core/node.h (original)
+++ trunk/dom/include/dom/core/node.h Thu Jul 26 23:19:48 2007
@@ -64,7 +64,10 @@
DOM_DOCUMENT_NODE = 9,
DOM_DOCUMENT_TYPE_NODE = 10,
DOM_DOCUMENT_FRAGMENT_NODE = 11,
- DOM_NOTATION_NODE = 12
+ DOM_NOTATION_NODE = 12,
+
+ /* And a count of the number of node types */
+ DOM_NODE_TYPE_COUNT = DOM_NOTATION_NODE
} dom_node_type;
Modified: trunk/dom/src/core/attr.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.c?rev=3463&r1=3...
==============================================================================
--- trunk/dom/src/core/attr.c (original)
+++ trunk/dom/src/core/attr.c Thu Jul 26 23:19:48 2007
@@ -9,6 +9,8 @@
#include <dom/core/attr.h>
+#include "core/attr.h"
+#include "core/document.h"
#include "core/node.h"
#include "utils/utils.h"
@@ -30,6 +32,52 @@
bool is_id; /**< Attribute is of type ID */
};
+
+/**
+ * Create an attribute node
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param result Pointer to location to receive created attribute
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::name is invalid,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc and ::name will have their reference counts increased.
+ *
+ * The returned attribute will already be referenced.
+ */
+dom_exception dom_attr_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_attr **result)
+{
+ struct dom_attr *a;
+ dom_exception err;
+
+ /** \todo Sanity check the attribute name */
+
+ /* Allocate the element */
+ a = dom_document_alloc(doc, NULL, sizeof(struct dom_attr));
+ if (a == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Initialise the base class */
+ err = dom_node_initialise(&a->base, doc, DOM_ATTRIBUTE_NODE,
+ name, NULL);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, a, 0);
+ return err;
+ }
+
+ /* Perform our type-specific initialisation */
+ a->specified = false;
+ a->owner = NULL;
+ a->schema_type_info = NULL;
+ a->is_id = false;
+
+ *result = a;
+
+ return DOM_NO_ERR;
+}
/**
* Retrieve an attribute's name
Added: trunk/dom/src/core/attr.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/attr.h?rev=3463&view...
==============================================================================
--- trunk/dom/src/core/attr.h (added)
+++ trunk/dom/src/core/attr.h Thu Jul 26 23:19:48 2007
@@ -1,0 +1,20 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_attr_h_
+#define dom_internal_core_attr_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_attr;
+struct dom_string;
+
+dom_exception dom_attr_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_attr **result);
+
+#endif
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Thu Jul 26 23:19:48 2007
@@ -9,7 +9,66 @@
#include <dom/core/string.h>
#include "core/characterdata.h"
+#include "core/document.h"
#include "utils/utils.h"
+
+/**
+ * Create a character data node of the given type
+ *
+ * \param doc The owning document
+ * \param type The type of node to create
+ * \param name The node name, or NULL
+ * \param value The node value, or NULL
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success, appropriate error otherwise
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The created node will already be referenced.
+ */
+dom_exception dom_characterdata_create(struct dom_document *doc,
+ dom_node_type type, struct dom_string *name,
+ struct dom_string *value, struct dom_characterdata **result)
+{
+ struct dom_characterdata *cdata;
+ dom_exception err;
+
+ /* Allocate object */
+ cdata = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_characterdata));
+ if (cdata == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Initialise node contents */
+ err = dom_characterdata_initialise(cdata, doc, type, name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, cdata, 0);
+ return err;
+ }
+
+ *result = cdata;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Initialise a character data node
+ *
+ * \param node The node to initialise
+ * \param doc The document which owns the node
+ * \param type The node type required
+ * \param name The node name, or NULL
+ * \param value The node value, or NULL
+ * \return DOM_NO_ERR on success.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ */
+dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value)
+{
+ return dom_node_initialise(&cdata->base, doc, type, name, value);
+}
/**
* Retrieve data from a character data node
Modified: trunk/dom/src/core/characterdata.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.h?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.h (original)
+++ trunk/dom/src/core/characterdata.h Thu Jul 26 23:19:48 2007
@@ -17,4 +17,12 @@
struct dom_node base; /**< Base node */
};
+dom_exception dom_characterdata_create(struct dom_document *doc,
+ dom_node_type type, struct dom_string *name,
+ struct dom_string *value, struct dom_characterdata **result);
+
+dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value);
+
#endif
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3463&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Thu Jul 26 23:19:48 2007
@@ -9,12 +9,17 @@
#include <dom/bootstrap/implpriv.h>
#include <dom/core/document.h>
+#include "core/attr.h"
#include "core/characterdata.h"
#include "core/document.h"
+#include "core/element.h"
#include "core/namednodemap.h"
#include "core/node.h"
#include "core/nodelist.h"
+#include "core/text.h"
#include "utils/utils.h"
+
+struct dom_document_type;
/**
* Item in list of active nodelists
@@ -42,9 +47,14 @@
struct dom_document {
struct dom_node base; /**< Base node */
+ struct dom_document_type *type; /**< Associated doctype */
+
struct dom_doc_nl *nodelists; /**< List of active nodelists */
struct dom_doc_nnm *maps; /**< List of active namednodemaps */
+
+ /** Interned node name strings, indexed by node type */
+ struct dom_string *nodenames[DOM_NODE_TYPE_COUNT];
dom_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
@@ -64,10 +74,12 @@
dom_exception dom_document_get_doctype(struct dom_document *doc,
struct dom_document_type **result)
{
- UNUSED(doc);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ if (doc->type != NULL)
+ dom_node_ref((struct dom_node *) doc->type);
+
+ *result = doc->type;
+
+ return DOM_NO_ERR;
}
/**
@@ -100,10 +112,20 @@
dom_exception dom_document_get_document_element(struct dom_document *doc,
struct dom_element **result)
{
- UNUSED(doc);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *root;
+
+ /* Find first element node in child list */
+ for (root = doc->base.first_child; root != NULL; root = root->next) {
+ if (root->type == DOM_ELEMENT_NODE)
+ break;
+ }
+
+ if (root != NULL)
+ dom_node_ref(root);
+
+ *result = (struct dom_element *) root;
+
+ return DOM_NO_ERR;
}
/**
@@ -115,6 +137,8 @@
* \return DOM_NO_ERR on success,
* DOM_INVALID_CHARACTER_ERR if ::tag_name is invalid.
*
+ * ::doc and ::tag_name will have their reference counts increased.
+ *
* The returned node will have its reference count increased. It is
* the responsibility of the caller to unref the node once it has
* finished with it.
@@ -122,11 +146,7 @@
dom_exception dom_document_create_element(struct dom_document *doc,
struct dom_string *tag_name, struct dom_element **result)
{
- UNUSED(doc);
- UNUSED(tag_name);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_element_create(doc, tag_name, result);
}
/**
@@ -143,10 +163,9 @@
dom_exception dom_document_create_document_fragment(struct dom_document *doc,
struct dom_node **result)
{
- UNUSED(doc);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_node_create(doc, DOM_DOCUMENT_FRAGMENT_NODE,
+ doc->nodenames[DOM_DOCUMENT_FRAGMENT_NODE],
+ NULL, result);
}
/**
@@ -164,11 +183,8 @@
dom_exception dom_document_create_text_node(struct dom_document *doc,
struct dom_string *data, struct dom_text **result)
{
- UNUSED(doc);
- UNUSED(data);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_text_create(doc, DOM_TEXT_NODE,
+ doc->nodenames[DOM_TEXT_NODE], data, result);
}
/**
@@ -186,11 +202,8 @@
dom_exception dom_document_create_comment(struct dom_document *doc,
struct dom_string *data, struct dom_characterdata **result)
{
- UNUSED(doc);
- UNUSED(data);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_characterdata_create(doc, DOM_COMMENT_NODE,
+ doc->nodenames[DOM_COMMENT_NODE], data, result);
}
/**
@@ -209,11 +222,9 @@
dom_exception dom_document_create_cdata_section(struct dom_document *doc,
struct dom_string *data, struct dom_text **result)
{
- UNUSED(doc);
- UNUSED(data);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_text_create(doc, DOM_CDATA_SECTION_NODE,
+ doc->nodenames[DOM_CDATA_SECTION_NODE],
+ data, result);
}
/**
@@ -236,12 +247,10 @@
struct dom_string *data,
struct dom_node **result)
{
- UNUSED(doc);
- UNUSED(target);
- UNUSED(data);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ /** \todo is the use of target as the node name correct? */
+
+ return dom_node_create(doc, DOM_PROCESSING_INSTRUCTION_NODE,
+ target, data, result);
}
/**
@@ -260,11 +269,7 @@
dom_exception dom_document_create_attribute(struct dom_document *doc,
struct dom_string *name, struct dom_attr **result)
{
- UNUSED(doc);
- UNUSED(name);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_attr_create(doc, name, result);
}
/**
@@ -284,11 +289,8 @@
dom_exception dom_document_create_entity_reference(struct dom_document *doc,
struct dom_string *name, struct dom_node **result)
{
- UNUSED(doc);
- UNUSED(name);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_node_create(doc, DOM_ENTITY_REFERENCE_NODE,
+ name, NULL, result);
}
/**
Modified: trunk/dom/src/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.h?rev=3463&...
==============================================================================
--- trunk/dom/src/core/document.h (original)
+++ trunk/dom/src/core/document.h Thu Jul 26 23:19:48 2007
@@ -5,8 +5,8 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
-#ifndef dom_internal_document_h_
-#define dom_internal_document_h_
+#ifndef dom_internal_core_document_h_
+#define dom_internal_core_document_h_
#include <inttypes.h>
#include <stddef.h>
Modified: trunk/dom/src/core/element.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.c?rev=3463&r...
==============================================================================
--- trunk/dom/src/core/element.c (original)
+++ trunk/dom/src/core/element.c Thu Jul 26 23:19:48 2007
@@ -7,6 +7,8 @@
#include <dom/core/element.h>
+#include "core/document.h"
+#include "core/element.h"
#include "core/node.h"
#include "utils/utils.h"
@@ -18,6 +20,49 @@
struct dom_type_info *schema_type_info; /**< Type information */
};
+
+/**
+ * Create an element node
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param result Pointer to location to receive created element
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::name is invalid,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc and ::name will have their reference counts increased.
+ *
+ * The returned element will already be referenced.
+ */
+dom_exception dom_element_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_element **result)
+{
+ struct dom_element *el;
+ dom_exception err;
+
+ /** \todo Sanity check the tag name */
+
+ /* Allocate the element */
+ el = dom_document_alloc(doc, NULL, sizeof(struct dom_element));
+ if (el == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Initialise the base class */
+ err = dom_node_initialise(&el->base, doc, DOM_ELEMENT_NODE,
+ name, NULL);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, el, 0);
+ return err;
+ }
+
+ /* Perform our type-specific initialisation */
+ el->schema_type_info = NULL;
+
+ *result = el;
+
+ return DOM_NO_ERR;
+}
/**
* Retrieve an element's tag name
Added: trunk/dom/src/core/element.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.h?rev=3463&v...
==============================================================================
--- trunk/dom/src/core/element.h (added)
+++ trunk/dom/src/core/element.h Thu Jul 26 23:19:48 2007
@@ -1,0 +1,20 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_element_h_
+#define dom_internal_core_element_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_element;
+struct dom_string;
+
+dom_exception dom_element_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_element **result);
+
+#endif
Modified: trunk/dom/src/core/namednodemap.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/namednodemap.h?rev=3...
==============================================================================
--- trunk/dom/src/core/namednodemap.h (original)
+++ trunk/dom/src/core/namednodemap.h Thu Jul 26 23:19:48 2007
@@ -5,8 +5,8 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
-#ifndef dom_internal_namednodemap_h_
-#define dom_internal_namednodemap_h_
+#ifndef dom_internal_core_namednodemap_h_
+#define dom_internal_core_namednodemap_h_
#include <stdbool.h>
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3463&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Thu Jul 26 23:19:48 2007
@@ -5,6 +5,7 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+#include <dom/core/document.h>
#include <dom/core/string.h>
#include "core/document.h"
@@ -12,58 +13,108 @@
#include "utils/utils.h"
/**
- * Create a DOM node
- *
+ * Create a DOM node of the given type
+ *
+ * \param doc The owning document
+ * \param type The type of node to create
+ * \param name The node name, or NULL
+ * \param value The node value, or NULL
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success, appropriate error otherwise
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The created node will already be referenced.
+ */
+dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_node **result)
+{
+ struct dom_node *node;
+ dom_exception err;
+
+ /* If there's a type-specific constructor, use that */
+ switch (type) {
+ case DOM_ELEMENT_NODE:
+ return dom_document_create_element(doc, name,
+ (struct dom_element **) result);
+ case DOM_ATTRIBUTE_NODE:
+ return dom_document_create_attribute(doc, name,
+ (struct dom_attr **) result);
+ case DOM_TEXT_NODE:
+ return dom_document_create_text_node(doc, value,
+ (struct dom_text **) result);
+ case DOM_CDATA_SECTION_NODE:
+ return dom_document_create_cdata_section(doc, value,
+ (struct dom_text **) result);
+ case DOM_COMMENT_NODE:
+ return dom_document_create_comment(doc, value,
+ (struct dom_characterdata **) result);
+ default:
+ break;
+ }
+
+ /* Otherwise, this is a generic node, so build it ourselves */
+ node = dom_document_alloc(doc, NULL, sizeof(struct dom_node));
+ if (node == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Initialise node contents */
+ err = dom_node_initialise(node, doc, type, name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, node, 0);
+ return err;
+ }
+
+ *result = node;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Initialise a DOM node
+ *
+ * \param node The node to initialise
* \param doc The document which owns the node
* \param type The node type required
* \param name The node name, or NULL
* \param value The node value, or NULL
- * \param node Pointer to location to receive created node
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * The returned node will be referenced, so there is no need for the caller
- * to explicitly reference it.
- */
-dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
- struct dom_string *name, struct dom_string *value,
- struct dom_node **node)
-{
- struct dom_node *n;
-
- n = dom_document_alloc(doc, NULL, sizeof(struct dom_node));
- if (n == NULL)
- return DOM_NO_MEM_ERR;
-
+ * \return DOM_NO_ERR on success.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ */
+dom_exception dom_node_initialise(struct dom_node *node,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value)
+{
if (name != NULL)
dom_string_ref(name);
- n->name = name;
+ node->name = name;
if (value != NULL)
dom_string_ref(value);
- n->value = value;
-
- n->type = type;
-
- n->parent = NULL;
- n->first_child = NULL;
- n->last_child = NULL;
- n->previous = NULL;
- n->next = NULL;
- n->attributes = NULL;
+ node->value = value;
+
+ node->type = type;
+
+ node->parent = NULL;
+ node->first_child = NULL;
+ node->last_child = NULL;
+ node->previous = NULL;
+ node->next = NULL;
+ node->attributes = NULL;
dom_node_ref((struct dom_node *) doc);
- n->owner = doc;
+ node->owner = doc;
/** \todo Namespace handling */
- n->namespace = NULL;
- n->prefix = NULL;
- n->localname = NULL;
-
- n->user_data = NULL;
-
- n->refcnt = 1;
-
- *node = n;
+ node->namespace = NULL;
+ node->prefix = NULL;
+ node->localname = NULL;
+
+ node->user_data = NULL;
+
+ node->refcnt = 1;
return DOM_NO_ERR;
}
Modified: trunk/dom/src/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.h?rev=3463&r1=3...
==============================================================================
--- trunk/dom/src/core/node.h (original)
+++ trunk/dom/src/core/node.h Thu Jul 26 23:19:48 2007
@@ -54,6 +54,10 @@
dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value,
- struct dom_node **node);
+ struct dom_node **result);
+
+dom_exception dom_node_initialise(struct dom_node *node,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value);
#endif
Modified: trunk/dom/src/core/nodelist.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/nodelist.h?rev=3463&...
==============================================================================
--- trunk/dom/src/core/nodelist.h (original)
+++ trunk/dom/src/core/nodelist.h Thu Jul 26 23:19:48 2007
@@ -5,8 +5,8 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
-#ifndef dom_internal_nodelist_h_
-#define dom_internal_nodelist_h_
+#ifndef dom_internal_core_nodelist_h_
+#define dom_internal_core_nodelist_h_
#include <stdbool.h>
Modified: trunk/dom/src/core/text.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.c?rev=3463&r1=3...
==============================================================================
--- trunk/dom/src/core/text.c (original)
+++ trunk/dom/src/core/text.c Thu Jul 26 23:19:48 2007
@@ -9,14 +9,61 @@
#include <dom/core/text.h>
#include "core/characterdata.h"
+#include "core/document.h"
+#include "core/text.h"
#include "utils/utils.h"
+/**
+ * A DOM text node
+ */
struct dom_text {
struct dom_characterdata base; /**< Base node */
bool element_content_whitespace; /**< This node is element
* content whitespace */
};
+
+/**
+ * Create a text node
+ *
+ * \param doc The owning document
+ * \param type The type of text node to create
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_text **result)
+{
+ struct dom_text *t;
+ dom_exception err;
+
+ /* Allocate the element */
+ t = dom_document_alloc(doc, NULL, sizeof(struct dom_text));
+ if (t == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Initialise the base class */
+ err = dom_characterdata_initialise(&t->base, doc, type, name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, t, 0);
+ return err;
+ }
+
+ /* Perform our type-specific initialisation */
+ t->element_content_whitespace = false;
+
+ *result = t;
+
+ return DOM_NO_ERR;
+}
/**
* Split a text node at a given character offset
Added: trunk/dom/src/core/text.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.h?rev=3463&view...
==============================================================================
--- trunk/dom/src/core/text.h (added)
+++ trunk/dom/src/core/text.h Thu Jul 26 23:19:48 2007
@@ -1,0 +1,23 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_text_h_
+#define dom_internal_core_text_h_
+
+#include <dom/core/exceptions.h>
+
+#include "core/node.h"
+
+struct dom_document;
+struct dom_string;
+struct dom_text;
+
+dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_text **result);
+
+#endif
16 years, 2 months
r3462 jmb - in /trunk/dom: bindings/xml/xmlparser.c include/dom/bootstrap/implpriv.h src/core/document.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Jul 26 14:17:08 2007
New Revision: 3462
URL: http://source.netsurf-browser.org?rev=3462&view=rev
Log:
Add ability to set a document's doctype after the document has been created
Modified:
trunk/dom/bindings/xml/xmlparser.c
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/src/core/document.c
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Thu Jul 26 14:17:08 2007
@@ -13,6 +13,7 @@
#include <libxml/SAX2.h>
#include <libxml/xmlerror.h>
+#include <dom/bootstrap/implpriv.h>
#include <dom/dom.h>
#include "xmlerror.h"
@@ -1089,9 +1090,13 @@
dom_string_unref(public_id);
dom_string_unref(qname);
- /** \todo Add doctype to document (requires some libdom-internal API
- * -- doctypes are immutable in the DOM) */
- UNUSED(parent);
+ /* Add doctype to document */
+ err = dom_document_set_doctype((struct dom_document *) parent,
+ doctype);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) doctype);
+ return;
+ }
/* Link nodes together */
err = xml_parser_link_nodes(parser, (struct dom_node *) doctype,
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Thu Jul 26 14:17:08 2007
@@ -11,6 +11,9 @@
*
* The DOMImplementation and DOMImplementationList implementations also
* include this, as those types are defined here.
+ *
+ * The Document implementation includes this as it needs the declaration of
+ * dom_document_set_doctype.
*
* No other client should be including this.
*/
@@ -241,4 +244,8 @@
dom_exception dom_register_source(struct dom_implementation_source *source,
dom_alloc alloc, void *pw);
+/* Set a Document's DocumentType */
+dom_exception dom_document_set_doctype(struct dom_document *doc,
+ struct dom_document_type *doctype);
+
#endif
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3462&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Thu Jul 26 14:17:08 2007
@@ -6,6 +6,7 @@
*/
#include <dom/functypes.h>
+#include <dom/bootstrap/implpriv.h>
#include <dom/core/document.h>
#include "core/characterdata.h"
@@ -752,6 +753,35 @@
return DOM_NOT_SUPPORTED_ERR;
}
+/* */
+/* ----------------------------------------------------------------------- */
+/* */
+
+/**
+ * Set a Document's Document Type
+ *
+ * \param doc Document to set type of
+ * \param doctype The doctype to apply
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_MODIFICATION_ERR if ::doc already has a doctype.
+ *
+ * The doctype will have its reference count increased. It is the
+ * responsibility of the caller to unref the doctype once it has finished
+ * with it.
+ */
+dom_exception dom_document_set_doctype(struct dom_document *doc,
+ struct dom_document_type *doctype)
+{
+ UNUSED(doc);
+ UNUSED(doctype);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+/* */
+/* ----------------------------------------------------------------------- */
+/* */
+
/**
* Acquire a pointer to the base of the document buffer
*
16 years, 2 months
r3461 jmb - /trunk/dom/bindings/xml/xmlparser.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Jul 22 22:46:06 2007
New Revision: 3461
URL: http://source.netsurf-browser.org?rev=3461&view=rev
Log:
Further work on libxml binding.
This is now has support for enough node types to allow the XML-based testsuite to run sensibly. (The core library is missing a bunch of functionality that the testsuite requires, like the creation of nodes)
Insertion of DocumentType nodes into a Document is mostly there -- the remainder is waiting on a suitable API in the core library.
Modified:
trunk/dom/bindings/xml/xmlparser.c
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sun Jul 22 22:46:06 2007
@@ -37,6 +37,14 @@
static void xml_parser_add_element_node(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
static void xml_parser_add_text_node(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child);
+static void xml_parser_add_cdata_section(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child);
+static void xml_parser_add_entity_reference(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child);
+static void xml_parser_add_comment(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child);
+static void xml_parser_add_document_type(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
static void xml_parser_internal_subset(void *ctx, const xmlChar *name,
@@ -81,6 +89,8 @@
bool complete; /**< Indicate stream completion */
struct dom_string *udkey; /**< Key for DOM node user data */
+
+ struct dom_implementation *impl;/**< DOM implementation */
xml_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
@@ -141,6 +151,7 @@
xml_alloc alloc, void *pw)
{
xml_parser *parser;
+ struct dom_string *features;
dom_exception err;
UNUSED(enc);
@@ -162,7 +173,7 @@
parser->complete = false;
/* Create key for user data registration */
- err = dom_string_create_from_ptr_no_doc(alloc, pw,
+ err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
(const uint8_t *) "__xmlnode", SLEN("__xmlnode"),
&parser->udkey);
if (err != DOM_NO_ERR) {
@@ -171,6 +182,31 @@
return NULL;
}
+ /* Get DOM implementation */
+ /* Create a string representation of the features we want */
+ err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
+ (const uint8_t *) "XML", SLEN("XML"), &features);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(parser->udkey);
+ xmlFreeParserCtxt(parser->xml_ctx);
+ alloc(parser, 0, pw);
+ return NULL;
+ }
+
+ /* Now, try to get an appropriate implementation from the registry */
+ err = dom_implregistry_get_dom_implementation(features,
+ &parser->impl, (dom_alloc) alloc, pw);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(features);
+ dom_string_unref(parser->udkey);
+ xmlFreeParserCtxt(parser->xml_ctx);
+ alloc(parser, 0, pw);
+ return NULL;
+ }
+
+ /* No longer need the features string */
+ dom_string_unref(features);
+
parser->alloc = alloc;
parser->pw = pw;
@@ -184,6 +220,8 @@
*/
void xml_parser_destroy(xml_parser *parser)
{
+ dom_implementation_unref(parser->impl);
+
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
@@ -257,48 +295,29 @@
void xml_parser_start_document(void *ctx)
{
xml_parser *parser = (xml_parser *) ctx;
- struct dom_implementation *impl;
- struct dom_string *features;
struct dom_document *doc;
dom_exception err;
/* Invoke libxml2's default behaviour */
xmlSAX2StartDocument(parser->xml_ctx);
- /* Create a string representation of the features we want */
- err = dom_string_create_from_ptr_no_doc((dom_alloc) parser->alloc,
- parser->pw, (const uint8_t *) "XML", SLEN("XML"),
- &features);
- if (err != DOM_NO_ERR)
- return;
-
- /* Now, try to get an appropriate implementation from the registry */
- err = dom_implregistry_get_dom_implementation(features, &impl,
- (dom_alloc) parser->alloc, parser->pw);
- if (err != DOM_NO_ERR) {
- dom_string_unref(features);
- return;
- }
-
- /* No longer need the features string */
- dom_string_unref(features);
-
/* Attempt to create a document */
- err = dom_implementation_create_document(impl, /* namespace */ NULL,
- /* qname */ NULL, /* doctype */ NULL,
- &doc, (dom_alloc) parser->alloc, parser->pw);
- if (err != DOM_NO_ERR) {
- dom_implementation_unref(impl);
- return;
- }
-
- /* No longer need the implementation */
- dom_implementation_unref(impl);
+ err = dom_implementation_create_document(parser->impl,
+ /* namespace */ NULL,
+ /* qname */ NULL,
+ /* doctype */ NULL,
+ &doc,
+ (dom_alloc) parser->alloc,
+ parser->pw);
+ if (err != DOM_NO_ERR) {
+ return;
+ }
/* Link nodes together */
err = xml_parser_link_nodes(parser, (struct dom_node *) doc,
(xmlNodePtr) parser->xml_ctx->myDoc);
if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) doc);
return;
}
@@ -514,6 +533,31 @@
void xml_parser_add_node(xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
+ static const char *node_types[] = {
+ "THIS_IS_NOT_A_NODE",
+ "XML_ELEMENT_NODE",
+ "XML_ATTRIBUTE_NODE",
+ "XML_TEXT_NODE",
+ "XML_CDATA_SECTION_NODE",
+ "XML_ENTITY_REF_NODE",
+ "XML_ENTITY_NODE",
+ "XML_PI_NODE",
+ "XML_COMMENT_NODE",
+ "XML_DOCUMENT_NODE",
+ "XML_DOCUMENT_TYPE_NODE",
+ "XML_DOCUMENT_FRAG_NODE",
+ "XML_NOTATION_NODE",
+ "XML_HTML_DOCUMENT_NODE",
+ "XML_DTD_NODE",
+ "XML_ELEMENT_DECL",
+ "XML_ATTRIBUTE_DECL",
+ "XML_ENTITY_DECL",
+ "XML_NAMESPACE_DECL",
+ "XML_XINCLUDE_START",
+ "XML_XINCLUDE_END",
+ "XML_DOCB_DOCUMENT_NODE"
+ };
+
switch (child->type) {
case XML_ELEMENT_NODE:
xml_parser_add_element_node(parser, parent, child);
@@ -522,11 +566,20 @@
xml_parser_add_text_node(parser, parent, child);
break;
case XML_CDATA_SECTION_NODE:
+ xml_parser_add_cdata_section(parser, parent, child);
+ break;
case XML_ENTITY_REF_NODE:
+ xml_parser_add_entity_reference(parser, parent, child);
+ break;
case XML_COMMENT_NODE:
+ xml_parser_add_comment(parser, parent, child);
+ break;
case XML_DTD_NODE:
+ xml_parser_add_document_type(parser, parent, child);
+ break;
default:
- fprintf(stderr, "Unsupported node type: %d\n", child->type);
+ fprintf(stderr, "Unsupported node type: %s\n",
+ node_types[child->type]);
}
}
@@ -809,6 +862,249 @@
dom_node_unref((struct dom_node *) text);
}
+/**
+ * Add a cdata section to the DOM
+ *
+ * \param parser The parser context
+ * \param parent The parent DOM node
+ * \param child The xmlNode to mirror in the DOM as a child of parent
+ */
+void xml_parser_add_cdata_section(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child)
+{
+ struct dom_text *cdata, *ins_cdata;
+ struct dom_string *data;
+ dom_exception err;
+
+ /* Create DOM string data for cdata section */
+ err = dom_string_create_from_const_ptr(parser->doc, child->content,
+ strlen((const char *) child->content), &data);
+ if (err != DOM_NO_ERR)
+ return;
+
+ /* Create text node */
+ err = dom_document_create_cdata_section(parser->doc, data, &cdata);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(data);
+ return;
+ }
+
+ /* No longer need data */
+ dom_string_unref(data);
+
+ /* Append cdata section to parent */
+ err = dom_node_append_child(parent, (struct dom_node *) cdata,
+ (struct dom_node **) &ins_cdata);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) cdata);
+ return;
+ }
+
+ /* We're not interested in the inserted cdata section */
+ if (ins_cdata != NULL)
+ dom_node_unref((struct dom_node *) ins_cdata);
+
+ /* Link nodes together */
+ err = xml_parser_link_nodes(parser, (struct dom_node *) cdata,
+ child);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) cdata);
+ return;
+ }
+
+ /* No longer interested in cdata section */
+ dom_node_unref((struct dom_node *) cdata);
+}
+
+/**
+ * Add an entity reference to the DOM
+ *
+ * \param parser The parser context
+ * \param parent The parent DOM node
+ * \param child The xmlNode to mirror in the DOM as a child of parent
+ */
+void xml_parser_add_entity_reference(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child)
+{
+ struct dom_node *entity, *ins_entity;
+ struct dom_string *name;
+ xmlNodePtr c;
+ dom_exception err;
+
+ /* Create name of entity reference */
+ err = dom_string_create_from_const_ptr(parser->doc, child->name,
+ strlen((const char *) child->name), &name);
+ if (err != DOM_NO_ERR)
+ return;
+
+ /* Create text node */
+ err = dom_document_create_entity_reference(parser->doc, name,
+ &entity);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(name);
+ return;
+ }
+
+ /* No longer need name */
+ dom_string_unref(name);
+
+ /* Mirror subtree (reference value) */
+ for (c = child->children; c != NULL; c = c->next) {
+ xml_parser_add_node(parser, (struct dom_node *) entity, c);
+ }
+
+ /* Append entity reference to parent */
+ err = dom_node_append_child(parent, (struct dom_node *) entity,
+ (struct dom_node **) &ins_entity);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) entity);
+ return;
+ }
+
+ /* We're not interested in the inserted entity reference */
+ if (ins_entity != NULL)
+ dom_node_unref((struct dom_node *) ins_entity);
+
+ /* Link nodes together */
+ err = xml_parser_link_nodes(parser, (struct dom_node *) entity,
+ child);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) entity);
+ return;
+ }
+
+ /* No longer interested in entity reference */
+ dom_node_unref((struct dom_node *) entity);
+}
+
+/**
+ * Add a comment to the DOM
+ *
+ * \param parser The parser context
+ * \param parent The parent DOM node
+ * \param child The xmlNode to mirror in the DOM as a child of parent
+ */
+void xml_parser_add_comment(xml_parser *parser, struct dom_node *parent,
+ xmlNodePtr child)
+{
+ struct dom_characterdata *comment, *ins_comment;
+ struct dom_string *data;
+ dom_exception err;
+
+ /* Create DOM string data for comment */
+ err = dom_string_create_from_const_ptr(parser->doc, child->content,
+ strlen((const char *) child->content), &data);
+ if (err != DOM_NO_ERR)
+ return;
+
+ /* Create comment */
+ err = dom_document_create_comment(parser->doc, data, &comment);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(data);
+ return;
+ }
+
+ /* No longer need data */
+ dom_string_unref(data);
+
+ /* Append comment to parent */
+ err = dom_node_append_child(parent, (struct dom_node *) comment,
+ (struct dom_node **) &ins_comment);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) comment);
+ return;
+ }
+
+ /* We're not interested in the inserted comment */
+ if (ins_comment != NULL)
+ dom_node_unref((struct dom_node *) ins_comment);
+
+ /* Link nodes together */
+ err = xml_parser_link_nodes(parser, (struct dom_node *) comment,
+ child);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) comment);
+ return;
+ }
+
+ /* No longer interested in comment */
+ dom_node_unref((struct dom_node *) comment);
+}
+
+/**
+ * Add a document type to the DOM
+ *
+ * \param parser The parser context
+ * \param parent The parent DOM node
+ * \param child The xmlNode to mirror in the DOM as a child of parent
+ */
+void xml_parser_add_document_type(xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child)
+{
+ xmlDtdPtr dtd = (xmlDtdPtr) child;
+ struct dom_document_type *doctype;
+ struct dom_string *qname, *public_id, *system_id;
+ dom_exception err;
+
+ /* Create qname for doctype */
+ err = dom_string_create_from_const_ptr(parser->doc, dtd->name,
+ strlen((const char *) dtd->name), &qname);
+ if (err != DOM_NO_ERR)
+ return;
+
+ /* Create public ID for doctype */
+ err = dom_string_create_from_const_ptr(parser->doc,
+ dtd->ExternalID,
+ strlen((const char *) dtd->ExternalID),
+ &public_id);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(qname);
+ return;
+ }
+
+ /* Create system ID for doctype */
+ err = dom_string_create_from_const_ptr(parser->doc,
+ dtd->SystemID,
+ strlen((const char *) dtd->SystemID),
+ &system_id);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(public_id);
+ dom_string_unref(qname);
+ return;
+ }
+
+ /* Create doctype */
+ err = dom_implementation_create_document_type(parser->impl,
+ qname, public_id, system_id, &doctype,
+ (dom_alloc) parser->alloc, parser->pw);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(system_id);
+ dom_string_unref(public_id);
+ dom_string_unref(qname);
+ return;
+ }
+
+ /* No longer need qname, public_id, system_id */
+ dom_string_unref(system_id);
+ dom_string_unref(public_id);
+ dom_string_unref(qname);
+
+ /** \todo Add doctype to document (requires some libdom-internal API
+ * -- doctypes are immutable in the DOM) */
+ UNUSED(parent);
+
+ /* Link nodes together */
+ err = xml_parser_link_nodes(parser, (struct dom_node *) doctype,
+ child);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) doctype);
+ return;
+ }
+
+ /* No longer interested in doctype */
+ dom_node_unref((struct dom_node *) doctype);
+}
+
/* */
/* ------------------------------------------------------------------------*/
/* */
16 years, 2 months