diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2010-12-05 23:52:56 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2010-12-05 23:52:56 +0000 |
commit | ac42344d05ec326f0063133498ec1c040e924db2 (patch) | |
tree | 4041bc41d72721a94dc573e5be3cb0f80988e004 /src/core | |
parent | c9c2a632f38b736d6879caf00aa477ecf2e22dfb (diff) | |
download | libdom-ac42344d05ec326f0063133498ec1c040e924db2.tar.gz libdom-ac42344d05ec326f0063133498ec1c040e924db2.tar.bz2 |
Remove bootstrap infrastructure, and just make dom_implementation a stub.
We only support a single implementation, so all the registry and implementation list stuff is totally unnecesary and overcomplex
svn path=/trunk/dom/; revision=11017
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile | 2 | ||||
-rw-r--r-- | src/core/document.c | 29 | ||||
-rw-r--r-- | src/core/document.h | 10 | ||||
-rw-r--r-- | src/core/document_type.c | 15 | ||||
-rw-r--r-- | src/core/document_type.h | 3 | ||||
-rw-r--r-- | src/core/implementation.c | 147 | ||||
-rw-r--r-- | src/core/impllist.c | 97 | ||||
-rw-r--r-- | src/core/node.c | 20 |
8 files changed, 128 insertions, 195 deletions
diff --git a/src/core/Makefile b/src/core/Makefile index 46cb48d..c9da9c1 100644 --- a/src/core/Makefile +++ b/src/core/Makefile @@ -2,7 +2,7 @@ DIR_SOURCES := \ string.c node.c \ attr.c characterdata.c element.c \ - implementation.c impllist.c \ + implementation.c \ text.c typeinfo.c comment.c \ namednodemap.c nodelist.c \ cdatasection.c document_type.c entity_ref.c pi.c \ diff --git a/src/core/document.c b/src/core/document.c index ad25bd7..20ad789 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -11,7 +11,6 @@ #include <libwapcaplet/libwapcaplet.h> #include <dom/functypes.h> -#include <dom/bootstrap/implpriv.h> #include <dom/core/attr.h> #include <dom/core/element.h> #include <dom/core/document.h> @@ -71,7 +70,6 @@ static dom_exception dom_document_dup_node(dom_document *doc, /** * 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 @@ -83,8 +81,7 @@ static dom_exception dom_document_dup_node(dom_document *doc, * * The returned document will already be referenced. */ -dom_exception _dom_document_create(struct dom_implementation *impl, - dom_alloc alloc, void *pw, +dom_exception _dom_document_create(dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc) { @@ -105,7 +102,7 @@ dom_exception _dom_document_create(struct dom_implementation *impl, * reaches zero. Documents own themselves (this simplifies the * rest of the code, as it doesn't need to special case Documents) */ - err = _dom_document_initialise(d, impl, alloc, pw, daf); + err = _dom_document_initialise(d, alloc, pw, daf); if (err != DOM_NO_ERR) { /* Clean up document */ alloc(d, 0, pw); @@ -119,23 +116,19 @@ dom_exception _dom_document_create(struct dom_implementation *impl, /* Initialise the document */ dom_exception _dom_document_initialise(struct dom_document *doc, - struct dom_implementation *impl, dom_alloc alloc, void *pw, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf) { - assert(alloc != NULL); - assert(impl != NULL); - dom_exception err; lwc_string *name; lwc_error lerr; - + + assert(alloc != NULL); + lerr = lwc_intern_string("#document", SLEN("#document"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); - dom_implementation_ref(impl); - doc->impl = impl; - doc->nodelists = NULL; /* Set up document allocation context - must be first */ @@ -173,9 +166,6 @@ bool _dom_document_finalise(struct dom_document *doc) /* Ok, the document tree is empty, as is the list of nodes pending * deletion. Therefore, it is safe to destroy the document. */ - if (doc->impl != NULL) - dom_implementation_unref(doc->impl); - doc->impl = NULL; /* This is paranoia -- if there are any remaining nodelists, * then the document's reference count will be @@ -240,12 +230,11 @@ dom_exception _dom_document_get_doctype(struct dom_document *doc, * it has finished with it. */ dom_exception _dom_document_get_implementation(struct dom_document *doc, - struct dom_implementation **result) + dom_implementation **result) { - if (doc->impl != NULL) - dom_implementation_ref(doc->impl); + UNUSED(doc); - *result = doc->impl; + *result = (dom_implementation *) "libdom"; return DOM_NO_ERR; } diff --git a/src/core/document.h b/src/core/document.h index e657530..3939f9a 100644 --- a/src/core/document.h +++ b/src/core/document.h @@ -13,6 +13,7 @@ #include <dom/core/node.h> #include <dom/core/document.h> +#include <dom/core/implementation.h> #include "core/string.h" #include "core/node.h" @@ -49,8 +50,6 @@ struct dom_doc_nl; struct dom_document { struct dom_node_internal base; /**< Base node */ - struct dom_implementation *impl; /**< Owning implementation */ - struct dom_doc_nl *nodelists; /**< List of active nodelists */ struct dom_string *uri; /**< The uri of this document */ @@ -68,14 +67,13 @@ struct dom_document { }; /* Create a DOM document */ -dom_exception _dom_document_create(struct dom_implementation *impl, - dom_alloc alloc, void *pw, +dom_exception _dom_document_create(dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc); /* Initialise the document */ dom_exception _dom_document_initialise(struct dom_document *doc, - struct dom_implementation *impl, dom_alloc alloc, void *pw, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf); /* Finalise the document */ @@ -100,7 +98,7 @@ dom_exception _dom_document_create_string_from_lwcstring( dom_exception _dom_document_get_doctype(struct dom_document *doc, struct dom_document_type **result); dom_exception _dom_document_get_implementation(struct dom_document *doc, - struct dom_implementation **result); + dom_implementation **result); dom_exception _dom_document_get_document_element(struct dom_document *doc, struct dom_element **result); dom_exception _dom_document_create_element(struct dom_document *doc, diff --git a/src/core/document_type.c b/src/core/document_type.c index 1c9d0cb..7788b1d 100644 --- a/src/core/document_type.c +++ b/src/core/document_type.c @@ -10,7 +10,6 @@ #include <assert.h> #include <dom/core/document_type.h> -#include <dom/bootstrap/implpriv.h> #include "core/string.h" #include "core/document_type.h" @@ -25,8 +24,6 @@ struct dom_document_type { struct dom_node_internal base; /**< Base node */ - struct dom_implementation *impl; /**< Owning implementation */ - struct dom_string *public_id; /**< Doctype public ID */ struct dom_string *system_id; /**< Doctype system ID */ @@ -379,15 +376,3 @@ void _dom_document_type_get_resource_mgr( rm->pw = dt->res.pw; } -/** - * Get the implementation which created this dom_document_type - * - * \param dt The document type object - * \return the dom_implementation instance which creates this node. - */ -struct dom_implementation *_dom_document_type_get_impl( - struct dom_document_type *dt) -{ - return dt->impl; -} - diff --git a/src/core/document_type.h b/src/core/document_type.h index 93db617..4fd1c83 100644 --- a/src/core/document_type.h +++ b/src/core/document_type.h @@ -10,7 +10,6 @@ struct dom_document_type; struct dom_resource_mgr; -struct dom_implementation; /* Create a DOM document type */ dom_exception _dom_document_type_create(struct dom_string *qname, @@ -67,7 +66,5 @@ dom_exception _dom_dt_copy(struct dom_node_internal *new, /* Helper functions */ void _dom_document_type_get_resource_mgr( struct dom_document_type *dt, struct dom_resource_mgr *rm); -struct dom_implementation *_dom_document_type_get_impl( - struct dom_document_type *dt); #endif diff --git a/src/core/implementation.c b/src/core/implementation.c index 6713060..4dc8cf3 100644 --- a/src/core/implementation.c +++ b/src/core/implementation.c @@ -5,56 +5,38 @@ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org> */ -#include <dom/bootstrap/implpriv.h> #include <dom/core/implementation.h> -/** - * Claim a reference on a DOM implementation - * - * \param impl The implementation to claim a reference on - */ -void dom_implementation_ref(struct dom_implementation *impl) -{ - impl->refcnt++; -} +#include "core/document.h" +#include "core/document_type.h" -/** - * Release a reference from a DOM implementation - * - * \param impl The implementation to release the reference from - * - * If the reference count reaches zero, any memory claimed by the - * implementation will be released - */ -void dom_implementation_unref(struct dom_implementation *impl) -{ - if (--impl->refcnt == 0) { - impl->destroy(impl); - } -} +#include "utils/namespace.h" +#include "utils/utils.h" +#include "utils/validate.h" /** * Test whether a DOM implementation implements a specific feature * and version * - * \param impl The DOM implementation to query * \param feature The feature to test for * \param version The version number of the feature to test for * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ dom_exception dom_implementation_has_feature( - struct dom_implementation *impl, struct dom_string *feature, struct dom_string *version, bool *result) { - return impl->has_feature(impl, feature, version, result); + UNUSED(feature); + UNUSED(version); + UNUSED(result); + + return DOM_NOT_SUPPORTED_ERR; } /** * Create a document type node * - * \param impl The implementation to create the node * \param qname The qualified name of the document type * \param public_id The external subset public identifier * \param system_id The external subset system identifier @@ -75,19 +57,44 @@ dom_exception dom_implementation_has_feature( * finished with it. */ dom_exception dom_implementation_create_document_type( - struct dom_implementation *impl, struct dom_string *qname, - struct dom_string *public_id, struct dom_string *system_id, + struct dom_string *qname, struct dom_string *public_id, + struct dom_string *system_id, dom_alloc alloc, void *pw, struct dom_document_type **doctype) { - return impl->create_document_type(impl, qname, public_id, system_id, - alloc, pw, doctype); + struct dom_document_type *d; + struct dom_string *prefix = NULL, *lname = NULL; + dom_exception err; + + if (qname != NULL && _dom_validate_name(qname) == false) + return DOM_INVALID_CHARACTER_ERR; + + err = _dom_namespace_split_qname(qname, &prefix, &lname); + if (err != DOM_NO_ERR) + return err; + + if ((prefix != NULL && _dom_validate_ncname(prefix) == false) || + (lname != NULL && _dom_validate_ncname(lname) == false)) + return DOM_NAMESPACE_ERR; + + /* Create the doctype */ + err = _dom_document_type_create(qname, public_id, system_id, + alloc, pw, &d); + if (err != DOM_NO_ERR) + return err; + + *doctype = d; + if (prefix != NULL) + dom_string_unref(prefix); + if (lname != NULL) + dom_string_unref(lname); + + return DOM_NO_ERR; } /** * Create a document node * - * \param impl The implementation to create the node * \param namespace The namespace URI of the document element * \param qname The qualified name of the document element * \param doctype The type of document to create @@ -118,22 +125,81 @@ dom_exception dom_implementation_create_document_type( * finished with it. */ dom_exception dom_implementation_create_document( - struct dom_implementation *impl, struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc) { - return impl->create_document(impl, namespace, qname, doctype, alloc, - pw, daf, doc); + struct dom_document *d; + dom_exception err; + + if (qname != NULL && _dom_validate_name(qname) == false) + return DOM_INVALID_CHARACTER_ERR; + + err = _dom_namespace_validate_qname(qname, namespace); + if (err != DOM_NO_ERR) + return DOM_NAMESPACE_ERR; + + if (doctype != NULL && dom_node_get_parent(doctype) != NULL) + return DOM_WRONG_DOCUMENT_ERR; + + /* Create document object */ + err = _dom_document_create(alloc, pw, daf, &d); + if (err != DOM_NO_ERR) + return err; + + /* Set its doctype, if necessary */ + if (doctype != NULL) { + struct dom_node *ins_doctype = NULL; + + err = dom_node_append_child((struct dom_node *) d, + (struct dom_node *) doctype, &ins_doctype); + if (err != DOM_NO_ERR) { + dom_node_unref((struct dom_node *) d); + return err; + } + + /* Not interested in inserted doctype */ + if (ins_doctype != NULL) + dom_node_unref(ins_doctype); + } + + /* Create root element and attach it to document */ + if (qname != NULL) { + struct dom_element *e; + struct dom_node *inserted; + + err = dom_document_create_element_ns(d, namespace, qname, &e); + if (err != DOM_NO_ERR) { + dom_node_unref((struct dom_node *) d); + return err; + } + + err = dom_node_append_child((struct dom_node *) d, + (struct dom_node *) e, &inserted); + if (err != DOM_NO_ERR) { + dom_node_unref((struct dom_node *) e); + dom_node_unref((struct dom_node *) d); + return err; + } + + /* No longer interested in inserted node */ + dom_node_unref(inserted); + + /* Done with element */ + dom_node_unref((struct dom_node *) e); + } + + *doc = d; + + return DOM_NO_ERR; } /** * Retrieve a specialized object which implements the specified * feature and version * - * \param impl The implementation to create the object * \param feature The requested feature * \param version The version number of the feature * \param object Pointer to location to receive object @@ -143,9 +209,12 @@ dom_exception dom_implementation_create_document( * the provided memory (de)allocation function. */ dom_exception dom_implementation_get_feature( - struct dom_implementation *impl, struct dom_string *feature, struct dom_string *version, void **object) { - return impl->get_feature(impl, feature, version, object); + UNUSED(feature); + UNUSED(version); + UNUSED(object); + + return DOM_NOT_SUPPORTED_ERR; } diff --git a/src/core/impllist.c b/src/core/impllist.c deleted file mode 100644 index 2f25926..0000000 --- a/src/core/impllist.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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@netsurf-browser.org> - */ - -#include <dom/bootstrap/implpriv.h> -#include <dom/core/implementation.h> -#include <dom/core/impllist.h> - -extern void dom_implementation_list_destroy( - struct dom_implementation_list *list); - -/** - * Claim a reference on a DOM implementation list - * - * \param list The list to claim a reference on - */ -void dom_implementation_list_ref(struct dom_implementation_list *list) -{ - list->refcnt++; -} - -/** - * Release a reference from a DOM implementation list - * - * \param list The list to release the reference from - * - * If the reference count reaches zero, any memory claimed by the - * list will be released - */ -void dom_implementation_list_unref(struct dom_implementation_list *list) -{ - if (--list->refcnt == 0) { - dom_implementation_list_destroy(list); - } -} - -/** - * Retrieve the length of a DOM implementation list - * - * \param list The list to retrieve the length of - * \param length Pointer to location to receive result - * \return DOM_NO_ERR. - */ -dom_exception dom_implementation_list_get_length( - struct dom_implementation_list *list, unsigned long *length) -{ - unsigned long count = 0; - struct dom_implementation_list_item *i; - - for (i = list->head; i; i = i->next) - count++; - - *length = count; - - return DOM_NO_ERR; -} - -/** - * Retrieve an item by index from a DOM implementation list - * - * \param list The list to retrieve the item from - * \param index The list index to retrieve - * \param impl Pointer to location to receive result - * \return DOM_NO_ERR. - * - * ::index is a zero-based index into ::list. - * ::index lies in the range [0, length-1] - * - * The returned implementation will have had its reference count increased. - * The client should unref the implementation once it has finished with it. - */ -dom_exception dom_implementation_list_item( - struct dom_implementation_list *list, unsigned long index, - struct dom_implementation **impl) -{ - unsigned long idx = 0; - struct dom_implementation_list_item *i; - - for (i = list->head; i; i = i->next) { - if (idx == index) - break; - - idx++; - } - - if (i == NULL) { - *impl = NULL; - } else { - dom_implementation_ref(i->impl); - *impl = i->impl; - } - - return DOM_NO_ERR; -} diff --git a/src/core/node.c b/src/core/node.c index ef2baf2..d4007df 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -1295,15 +1295,11 @@ dom_exception _dom_node_is_supported(dom_node_internal *node, struct dom_string *feature, struct dom_string *version, bool *result) { - dom_document *doc; - dom_implementation *impl; bool has; - doc = node->owner; - assert(doc != NULL); - dom_document_get_implementation(doc, &impl); - assert(impl != NULL); - dom_implementation_has_feature(impl, feature, version, &has); + UNUSED(node); + + dom_implementation_has_feature(feature, version, &has); *result = has; @@ -1792,15 +1788,11 @@ dom_exception _dom_node_get_feature(dom_node_internal *node, struct dom_string *feature, struct dom_string *version, void **result) { - dom_document *doc; - dom_implementation *impl; bool has; - doc = node->owner; - assert(doc != NULL); - dom_document_get_implementation(doc, &impl); - assert(impl != NULL); - dom_implementation_has_feature(impl, feature, version, &has); + UNUSED(node); + + dom_implementation_has_feature(feature, version, &has); if (has) { *result = node; |