summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindings/hubbub/parser.c33
-rw-r--r--bindings/xml/xmlparser.c36
-rw-r--r--include/dom/bootstrap/implpriv.h246
-rw-r--r--include/dom/bootstrap/implregistry.h32
-rw-r--r--include/dom/bootstrap/init_fini.h21
-rw-r--r--include/dom/core/document.h8
-rw-r--r--include/dom/core/implementation.h10
-rw-r--r--include/dom/core/impllist.h27
-rw-r--r--include/dom/dom.h7
-rw-r--r--src/Makefile1
-rw-r--r--src/bootstrap/Makefile3
-rw-r--r--src/bootstrap/implementation.c426
-rw-r--r--src/bootstrap/implementation.h14
-rw-r--r--src/bootstrap/implregistry.c215
-rw-r--r--src/core/Makefile2
-rw-r--r--src/core/document.c29
-rw-r--r--src/core/document.h10
-rw-r--r--src/core/document_type.c15
-rw-r--r--src/core/document_type.h3
-rw-r--r--src/core/implementation.c147
-rw-r--r--src/core/impllist.c97
-rw-r--r--src/core/node.c20
-rw-r--r--src/dom.c (renamed from src/bootstrap/init_fini.c)16
-rw-r--r--test/DOMTSHandler.pm1
-rw-r--r--test/testutils/domtsasserts.c4
25 files changed, 144 insertions, 1279 deletions
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index c7fc608..5566662 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -38,8 +38,6 @@ struct dom_hubbub_parser {
bool complete; /**< Indicate stream completion */
- struct dom_implementation *impl;/**< DOM implementation */
-
dom_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
@@ -118,7 +116,6 @@ dom_hubbub_parser *dom_hubbub_parser_create(
hubbub_parser_optparams params;
hubbub_error error;
dom_exception err;
- struct dom_string *features;
parser = alloc(NULL, sizeof(dom_hubbub_parser), pw);
if (parser == NULL) {
@@ -132,7 +129,6 @@ dom_hubbub_parser *dom_hubbub_parser_create(
parser->encoding_source = enc != NULL ? ENCODING_SOURCE_HEADER
: ENCODING_SOURCE_DETECTED;
parser->complete = false;
- parser->impl = NULL;
parser->alloc = alloc;
parser->pw = pw;
@@ -146,34 +142,10 @@ dom_hubbub_parser *dom_hubbub_parser_create(
return NULL;
}
- /* Create string representation of the features we want */
- err = dom_string_create(alloc, pw,
- (const uint8_t *) "HTML", SLEN("HTML"), &features);
- if (err != DOM_NO_ERR) {
- hubbub_parser_destroy(parser->parser);
- alloc(parser, 0, pw);
- msg(DOM_MSG_CRITICAL, mctx, "No memory for feature string");
- return NULL;
- }
-
- /* Now, try to get an appropriate implementation from the registry */
- err = dom_implregistry_get_dom_implementation(features,
- &parser->impl);
- if (err != DOM_NO_ERR) {
- dom_string_unref(features);
- hubbub_parser_destroy(parser->parser);
- alloc(parser, 0, pw);
- msg(DOM_MSG_ERROR, mctx, "No suitable DOMImplementation");
- return NULL;
- }
-
- /* No longer need the feature string */
- dom_string_unref(features);
-
/* TODO: Just pass the dom_events_default_action_fetcher a NULL,
* we should pass the real function when we integrate libDOM with
* Netsurf */
- err = dom_implementation_create_document(parser->impl, NULL, NULL, NULL,
+ err = dom_implementation_create_document(NULL, NULL, NULL,
alloc, pw, NULL, &parser->doc);
if (err != DOM_NO_ERR) {
hubbub_parser_destroy(parser->parser);
@@ -204,7 +176,6 @@ dom_hubbub_parser *dom_hubbub_parser_create(
*/
void dom_hubbub_parser_destroy(dom_hubbub_parser *parser)
{
- dom_implementation_unref(parser->impl);
hubbub_parser_destroy(parser->parser);
parser->parser = NULL;
@@ -386,7 +357,7 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
goto clean2;
}
- err = dom_implementation_create_document_type(dom_parser->impl, qname,
+ err = dom_implementation_create_document_type(qname,
public_id, system_id, dom_parser->alloc,
dom_parser->pw, &dtype);
if (err != DOM_NO_ERR) {
diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c
index 8e1013f..f8b3cb9 100644
--- a/bindings/xml/xmlparser.c
+++ b/bindings/xml/xmlparser.c
@@ -13,7 +13,6 @@
#include <libxml/SAX2.h>
#include <libxml/xmlerror.h>
-#include <dom/bootstrap/implpriv.h>
#include <dom/dom.h>
#include <libwapcaplet/libwapcaplet.h>
@@ -97,8 +96,6 @@ struct dom_xml_parser {
struct dom_string *udkey; /**< Key for DOM node user data */
- struct dom_implementation *impl;/**< DOM implementation */
-
dom_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
@@ -163,7 +160,6 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
dom_alloc alloc, void *pw, dom_msg msg, void *mctx)
{
dom_xml_parser *parser;
- struct dom_string *features;
dom_exception err;
int ret;
@@ -204,32 +200,6 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
return NULL;
}
- /* Create a string representation of the features we want */
- err = dom_string_create((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);
- msg(DOM_MSG_CRITICAL, mctx, "No memory for feature string");
- return NULL;
- }
-
- /* Now, try to get an appropriate implementation from the registry */
- err = dom_implregistry_get_dom_implementation(features,
- &parser->impl);
- if (err != DOM_NO_ERR) {
- dom_string_unref(features);
- dom_string_unref(parser->udkey);
- xmlFreeParserCtxt(parser->xml_ctx);
- alloc(parser, 0, pw);
- msg(DOM_MSG_ERROR, mctx, "No suitable DOMImplementation");
- return NULL;
- }
-
- /* No longer need the feature string */
- dom_string_unref(features);
-
parser->alloc = alloc;
parser->pw = pw;
@@ -246,8 +216,6 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
*/
void dom_xml_parser_destroy(dom_xml_parser *parser)
{
- dom_implementation_unref(parser->impl);
-
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
@@ -346,7 +314,7 @@ void xml_parser_start_document(void *ctx)
/* TODO: Just pass the dom_events_default_action_fetcher a NULL,
* we should pass the real function when we integrate libDOM with
* Netsurf */
- err = dom_implementation_create_document(parser->impl,
+ err = dom_implementation_create_document(
/* namespace */ NULL,
/* qname */ NULL,
/* doctype */ NULL,
@@ -1235,7 +1203,7 @@ void xml_parser_add_document_type(dom_xml_parser *parser,
}
/* Create doctype */
- err = dom_implementation_create_document_type(parser->impl,
+ err = dom_implementation_create_document_type(
qname, public_id, system_id,
parser->alloc, parser->pw, &doctype);
if (err != DOM_NO_ERR) {
diff --git a/include/dom/bootstrap/implpriv.h b/include/dom/bootstrap/implpriv.h
deleted file mode 100644
index 89d3f96..0000000
--- a/include/dom/bootstrap/implpriv.h
+++ /dev/null
@@ -1,246 +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>
- */
-
-/** \file
- * This file defines all the grubby details that implementation backends
- * need to know in order to permit themselves to be bootstrapped.
- *
- * 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_create and dom_document_set_doctype.
- *
- * The DocumentType implementation includes this as it needs the declaration
- * of dom_document_type_create.
- *
- * No other client should be including this.
- */
-
-#ifndef dom_bootstrap_implpriv_h_
-#define dom_bootstrap_implpriv_h_
-
-#include <inttypes.h>
-#include <stdbool.h>
-
-#include <dom/core/exceptions.h>
-#include <dom/events/document_event.h>
-#include <dom/functypes.h>
-#include <dom/core/string.h>
-
-struct dom_document;
-struct dom_document_type;
-
-/**
- * DOM Implementation
- */
-struct dom_implementation {
- /**
- * 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 (*has_feature)(struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- bool *result);
-
- /**
- * 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
- * \param doctype Pointer to location to receive result
- * \return DOM_NO_ERR on success,
- * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
- * DOM_NAMESPACE_ERR if ::qname is malformed,
- * DOM_NOT_SUPPORTED_ERR if ::impl does not support the
- * feature "XML" and the language
- * exposed through Document does
- * not support XML namespaces.
- *
- * 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
- * finished with it.
- */
- dom_exception (*create_document_type)(
- struct dom_implementation *impl,
- struct dom_string *qname,
- struct dom_string *public_id,
- struct dom_string *system_id,
- dom_alloc alloc, void *pw,
- struct dom_document_type **doctype);
-
- /**
- * 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
- * \param doc Pointer to location to receive result
- * \return DOM_NO_ERR on success,
- * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
- * DOM_NAMESPACE_ERR if ::qname is malformed, or if
- * ::qname has a prefix and
- * ::namespace is NULL, or if
- * ::qname is NULL and ::namespace
- * is non-NULL, or if ::qname has
- * a prefix "xml" and ::namespace
- * is not
- * "http://www.w3.org/XML/1998/namespace",
- * or if ::impl does not support
- * the "XML" feature and
- * ::namespace is non-NULL,
- * DOM_WRONG_DOCUMENT_ERR if ::doctype is already being
- * used by a document, or if it
- * was not created by ::impl,
- * DOM_NOT_SUPPORTED_ERR if ::impl does not support the
- * feature "XML" and the language
- * exposed through Document does
- * not support XML namespaces.
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- *
- * 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,
- 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);
-
- /**
- * 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
- * \return DOM_NO_ERR.
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- */
- dom_exception (*get_feature)(struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- void **object);
-
- /**
- * Destroy a DOM implementation instance
- *
- * \param impl The instance to destroy
- */
- void (*destroy)(struct dom_implementation *impl);
-
- uint32_t refcnt; /**< Reference count */
-};
-
-
-/**
- * An item in a DOM Implementation List
- */
-struct dom_implementation_list_item {
- struct dom_implementation *impl; /**< Implementation */
-
- struct dom_implementation_list_item *next; /**< Next in list */
- struct dom_implementation_list_item *prev; /**< Prev in list */
-};
-
-/**
- * DOM Implementation List
- */
-struct dom_implementation_list {
- struct dom_implementation_list_item *head; /**< Head of list */
-
- uint32_t refcnt; /**< Reference count */
-
- /**
- * Destroy a DOM implementation instance
- *
- * \param impl The instance to destroy
- */
- void (*destroy)(struct dom_implementation_list *impllist);
-};
-
-
-/**
- * DOM Implementation Source
- *
- * This is simply a pair of function pointers in a struct.
- *
- * This is assumed to be statically allocated within the backend.
- */
-struct dom_implementation_source {
- /**
- * Get a DOM implementation that supports the requested features
- *
- * \param features String containing required features
- * \param impl Pointer to location to receive implementation
- * \param alloc Function to (de)allocate memory
- * \param pw Pointer to client-specific private data
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function. The implementation's
- * destroy() method will be called once it is no longer used.
- *
- * The implementation will be referenced, so the client need not
- * do this explicitly. The client must unref the implementation
- * once it has finished with it.
- */
- dom_exception (*get_dom_implementation)(
- struct dom_string *features,
- struct dom_implementation **impl);
-
- /**
- * Get a list of DOM implementations that support the requested
- * features
- *
- * \param features String containing required features
- * \param list Pointer to location to receive list
- * \param alloc Function to (de)allocate memory
- * \param pw Pointer to client-specific private data
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function. The ::alloc/::pw
- * pair must be stored on the list object, such that the list
- * and its contents may be freed once they are no longer needed.
- *
- * List nodes reference the implementation objects they point to.
- *
- * The list will be referenced, so the client need not do this
- * explicitly. The client must unref the list once it has finished
- * with it.
- */
- dom_exception (*get_dom_implementation_list)(
- struct dom_string *features,
- struct dom_implementation_list **list);
-};
-
-/* Register a source with the DOM library */
-dom_exception dom_register_source(struct dom_implementation_source *source);
-
-#endif
diff --git a/include/dom/bootstrap/implregistry.h b/include/dom/bootstrap/implregistry.h
deleted file mode 100644
index e14738c..0000000
--- a/include/dom/bootstrap/implregistry.h
+++ /dev/null
@@ -1,32 +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>
- */
-
-#ifndef dom_bootstrap_implregistry_h_
-#define dom_bootstrap_implregistry_h_
-
-#include <dom/core/exceptions.h>
-#include <dom/functypes.h>
-
-struct dom_implementation;
-struct dom_implementation_list;
-struct dom_string;
-
-/* Initialise the implementation registry */
-dom_exception dom_implregistry_initialise(
- dom_alloc allocator, void *ptr);
-
-/* Retrieve a DOM implementation from the registry */
-dom_exception dom_implregistry_get_dom_implementation(
- struct dom_string *features,
- struct dom_implementation **impl);
-
-/* Get a list of DOM implementations that support the requested features */
-dom_exception dom_implregistry_get_dom_implementation_list(
- struct dom_string *features,
- struct dom_implementation_list **list);
-
-#endif
diff --git a/include/dom/bootstrap/init_fini.h b/include/dom/bootstrap/init_fini.h
deleted file mode 100644
index 5773af6..0000000
--- a/include/dom/bootstrap/init_fini.h
+++ /dev/null
@@ -1,21 +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>
- */
-
-#ifndef dom_bootstrap_init_fini_h_
-#define dom_bootstrap_init_fini_h_
-
-#include <dom/functypes.h>
-#include <dom/core/exceptions.h>
-
-/* Initialise the DOM library */
-dom_exception dom_initialise(dom_alloc alloc, void *pw);
-
-/* Finalise the DOM library */
-dom_exception dom_finalise(void);
-
-#endif
-
diff --git a/include/dom/core/document.h b/include/dom/core/document.h
index 1fe9752..ebe82b8 100644
--- a/include/dom/core/document.h
+++ b/include/dom/core/document.h
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <dom/core/exceptions.h>
+#include <dom/core/implementation.h>
#include <dom/core/node.h>
struct dom_attr;
@@ -25,7 +26,6 @@ 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;
@@ -43,7 +43,7 @@ typedef struct dom_document_vtable {
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,
@@ -127,13 +127,13 @@ static inline dom_exception dom_document_get_doctype(struct dom_document *doc,
(dom_document *) (d), (struct dom_document_type **) (r))
static inline dom_exception dom_document_get_implementation(
- struct dom_document *doc, struct dom_implementation **result)
+ struct dom_document *doc, dom_implementation **result)
{
return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
dom_document_get_implementation(doc, result);
}
#define dom_document_get_implementation(d, r) dom_document_get_implementation(\
- (dom_document *) (d), (struct dom_implementation **) (r))
+ (dom_document *) (d), (dom_implementation **) (r))
static inline dom_exception dom_document_get_document_element(
struct dom_document *doc, struct dom_element **result)
diff --git a/include/dom/core/implementation.h b/include/dom/core/implementation.h
index 7865b10..6fb381c 100644
--- a/include/dom/core/implementation.h
+++ b/include/dom/core/implementation.h
@@ -18,24 +18,19 @@
struct dom_document;
struct dom_document_type;
-typedef struct dom_implementation dom_implementation;
-
-void dom_implementation_ref(struct dom_implementation *impl);
-void dom_implementation_unref(struct dom_implementation *impl);
+typedef const char *dom_implementation;
dom_exception dom_implementation_has_feature(
- struct dom_implementation *impl,
struct dom_string *feature, struct dom_string *version,
bool *result);
dom_exception dom_implementation_create_document_type(
- struct dom_implementation *impl, struct dom_string *qname,
+ struct dom_string *qname,
struct dom_string *public_id, struct dom_string *system_id,
dom_alloc alloc, void *pw,
struct dom_document_type **doctype);
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,
@@ -43,7 +38,6 @@ dom_exception dom_implementation_create_document(
struct dom_document **doc);
dom_exception dom_implementation_get_feature(
- struct dom_implementation *impl,
struct dom_string *feature, struct dom_string *version,
void **object);
diff --git a/include/dom/core/impllist.h b/include/dom/core/impllist.h
deleted file mode 100644
index 8773066..0000000
--- a/include/dom/core/impllist.h
+++ /dev/null
@@ -1,27 +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>
- */
-
-#ifndef dom_core_impllist_h_
-#define dom_core_impllist_h_
-
-#include <dom/core/exceptions.h>
-
-struct dom_implementation;
-
-typedef struct dom_implementation_list dom_implementation_list;
-
-void dom_implementation_list_ref(struct dom_implementation_list *list);
-void dom_implementation_list_unref(struct dom_implementation_list *list);
-
-dom_exception dom_implementation_list_get_length(
- struct dom_implementation_list *list, unsigned long *length);
-
-dom_exception dom_implementation_list_item(
- struct dom_implementation_list *list, unsigned long index,
- struct dom_implementation **impl);
-
-#endif
diff --git a/include/dom/dom.h b/include/dom/dom.h
index 3a0a138..d39b85f 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -17,9 +17,6 @@
/* Base library headers */
#include <dom/functypes.h>
-/* DOM bootstrap headers */
-#include <dom/bootstrap/implregistry.h>
-
/* DOM core headers */
#include <dom/core/attr.h>
#include <dom/core/characterdata.h>
@@ -28,7 +25,6 @@
#include <dom/core/element.h>
#include <dom/core/exceptions.h>
#include <dom/core/implementation.h>
-#include <dom/core/impllist.h>
#include <dom/core/namednodemap.h>
#include <dom/core/node.h>
#include <dom/core/cdatasection.h>
@@ -58,4 +54,7 @@ typedef enum dom_namespace {
extern struct dom_string *dom_namespaces[DOM_NAMESPACE_COUNT];
+dom_exception dom_initialise(dom_alloc alloc, void *pw);
+dom_exception dom_finalise(void);
+
#endif
diff --git a/src/Makefile b/src/Makefile
index 3cbaf86..2940156 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,2 +1,3 @@
+DIR_SOURCES := dom.c
include build/makefiles/Makefile.subdir
diff --git a/src/bootstrap/Makefile b/src/bootstrap/Makefile
deleted file mode 100644
index e969d87..0000000
--- a/src/bootstrap/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-DIR_SOURCES := implregistry.c init_fini.c implementation.c
-
-include build/makefiles/Makefile.subdir
diff --git a/src/bootstrap/implementation.c b/src/bootstrap/implementation.c
deleted file mode 100644
index a27edfc..0000000
--- a/src/bootstrap/implementation.c
+++ /dev/null
@@ -1,426 +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>
- * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
- */
-
-/**
- * Note: The DOMImplementation Object here is a singleton object. It is
- * initialised when the libDOM is initialised, it registers itself into
- * the implreg and clients of it can get it by calling:
- *
- * dom_implregistry_get_dom_implementation or
- * dom_implregistry_get_dom_implementation_list
- *
- */
-
-#include <dom/bootstrap/implpriv.h>
-#include <dom/bootstrap/implregistry.h>
-#include <dom/dom.h>
-
-#include <libwapcaplet/libwapcaplet.h>
-
-#include "core/node.h"
-#include "core/document.h"
-#include "core/document_type.h"
-
-#include "utils/utils.h"
-#include "utils/validate.h"
-#include "utils/namespace.h"
-
-#include "bootstrap/implementation.h"
-
-static dom_alloc _alloc;
-static void *_pw;
-
-static dom_exception impl_get_dom_implementation(
- struct dom_string *features,
- struct dom_implementation **impl);
-static dom_exception impl_get_dom_implementation_list(
- struct dom_string *features,
- struct dom_implementation_list **list);
-
-static dom_exception impl_implementation_has_feature(
- struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- bool *result);
-static dom_exception impl_implementation_create_document_type(
- struct dom_implementation *impl,
- struct dom_string *qname,
- struct dom_string *public_id,
- struct dom_string *system_id,
- dom_alloc alloc, void *pw,
- struct dom_document_type **doctype);
-static dom_exception impl_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);
-static dom_exception impl_implementation_get_feature(
- struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- void **object);
-static void dom_implementation_destroy(struct dom_implementation *impl);
-
-
-static struct dom_implementation_source dom_impl_src = {
- impl_get_dom_implementation,
- impl_get_dom_implementation_list
-};
-
-static struct dom_implementation dom_impl = {
- impl_implementation_has_feature,
- impl_implementation_create_document_type,
- impl_implementation_create_document,
- impl_implementation_get_feature,
- dom_implementation_destroy,
- 0
-};
-
-/**
- * Get a DOM implementation that supports the requested features
- *
- * \param features String containing required features
- * \param impl Pointer to location to receive implementation
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function. The implementation's
- * destroy() method will be called once it is no longer used.
- *
- * The implementation will be referenced, so the client need not
- * do this explicitly. The client must unref the implementation
- * once it has finished with it.
- */
-dom_exception impl_get_dom_implementation(
- struct dom_string *features,
- struct dom_implementation **impl)
-{
- UNUSED(features);
-
- dom_impl.refcnt++;
-
- *impl = &dom_impl;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Get a list of DOM implementations that support the requested
- * features
- *
- * \param features String containing required features
- * \param list Pointer to location to receive list
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function. The ::alloc/::pw
- * pair must be stored on the list object, such that the list
- * and its contents may be freed once they are no longer needed.
- *
- * List nodes reference the implementation objects they point to.
- *
- * The list will be referenced, so the client need not do this
- * explicitly. The client must unref the list once it has finished
- * with it.
- */
-dom_exception impl_get_dom_implementation_list(
- struct dom_string *features,
- struct dom_implementation_list **list)
-{
- struct dom_implementation_list *l;
- struct dom_implementation_list_item *i;
-
- UNUSED(features);
-
- l = _alloc(NULL, sizeof(struct dom_implementation_list), _pw);
- if (l == NULL)
- return DOM_NO_MEM_ERR;
-
- i = _alloc(NULL, sizeof(struct dom_implementation_list_item), _pw);
- if (i == NULL) {
- _alloc(l, 0, _pw);
- return DOM_NO_MEM_ERR;
- }
-
- i->impl = &dom_impl;
- i->next = NULL;
- i->prev = NULL;
-
- l->head = i;
-
- l->refcnt = 1;
-
- *list = l;
-
- return DOM_NO_ERR;
-}
-
-/**
- * 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 impl_implementation_has_feature(
- struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- bool *result)
-{
- UNUSED(impl);
- 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
- * \param doctype Pointer to location to receive result
- * \return DOM_NO_ERR on success,
- * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
- * DOM_NAMESPACE_ERR if ::qname is malformed.
- *
- * 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
- * finished with it.
- */
-dom_exception impl_implementation_create_document_type(
- struct dom_implementation *impl,
- struct dom_string *qname,
- struct dom_string *public_id,
- struct dom_string *system_id,
- dom_alloc alloc, void *pw,
- struct dom_document_type **doctype)
-{
- struct dom_document_type *d;
- struct dom_string *prefix = NULL, *lname = NULL;
- dom_exception err;
-
- UNUSED(impl);
-
- 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
- * \param doc Pointer to location to receive result
- * \return DOM_NO_ERR on success,
- * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
- * DOM_NAMESPACE_ERR if ::qname is malformed, or if
- * ::qname has a prefix and
- * ::namespace is NULL, or if
- * ::qname is NULL and ::namespace
- * is non-NULL, or if ::qname has
- * a prefix "xml" and ::namespace
- * is not
- * "http://www.w3.org/XML/1998/namespace",
- * or if ::impl does not support
- * the "XML" feature and
- * ::namespace is non-NULL,
- * DOM_WRONG_DOCUMENT_ERR if ::doctype is already being
- * used by a document, or if it
- * was not created by ::impl,
- * DOM_NOT_SUPPORTED_ERR if ::impl does not support the
- * feature "XML" and the language
- * exposed through Document does
- * not support XML namespaces.
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- *
- * 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 impl_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)
-{
- 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) {
- if (dom_node_get_parent(doctype) != NULL ||
- _dom_document_type_get_impl(doctype) !=
- impl)
- return DOM_WRONG_DOCUMENT_ERR;
- }
-
- /* Create document object */
- err = _dom_document_create(impl, 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
- * \return DOM_NO_ERR.
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- */
-dom_exception impl_implementation_get_feature(
- struct dom_implementation *impl,
- struct dom_string *feature,
- struct dom_string *version,
- void **object)
-{
- UNUSED(impl);
- UNUSED(feature);
- UNUSED(version);
- UNUSED(object);
-
- return DOM_NOT_SUPPORTED_ERR;
-}
-
-/**
- * Destroy a DOM implementation instance
- *
- * \param impl The instance to destroy
- */
-void dom_implementation_destroy(struct dom_implementation *impl)
-{
- UNUSED(impl);
-
- /* Nothing to do -- we're statically allocated */
-}
-
-/**
- * Initialise the DOM implementation
- *
- * \param alloc Pointer to memory (de)allocation function
- * \param pw Pointer to client-specific private data
- * \return DOM_NO_ERR on success
- */
-dom_exception _dom_implementation_initialise(dom_alloc alloc, void *pw)
-{
- _alloc = alloc;
- _pw = pw;
-
- return dom_register_source(&dom_impl_src);
-}
-
-/**
- * Finalise the DOM implementation
- */
-void _dom_implementation_finalise(void)
-{
- _alloc = NULL;
- _pw = NULL;
-}
-
-
diff --git a/src/bootstrap/implementation.h b/src/bootstrap/implementation.h
deleted file mode 100644
index f62077c..0000000
--- a/src/bootstrap/implementation.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * This file is part of libdom.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
- */
-
-#ifndef dom_bootstrap_implementation_h_
-#define dom_bootstrap_implementation_h_
-
-dom_exception _dom_implementation_initialise(dom_alloc alloc, void *pw);
-void _dom_implementation_finalise(void);
-
-#endif
diff --git a/src/bootstrap/implregistry.c b/src/bootstrap/implregistry.c
deleted file mode 100644
index 91e4068..0000000
--- a/src/bootstrap/implregistry.c
+++ /dev/null
@@ -1,215 +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 <stddef.h>
-
-#include <dom/bootstrap/implpriv.h>
-#include <dom/bootstrap/implregistry.h>
-
-#include <dom/core/impllist.h>
-#include <dom/core/implementation.h>
-
-void dom_implementation_list_destroy(struct dom_implementation_list *list);
-
-/**
- * Item in list of registered DOM implementation sources
- */
-struct dom_impl_src_item {
- struct dom_implementation_source *source; /**< Source */
-
- struct dom_impl_src_item *next; /**< Next in list */
- struct dom_impl_src_item *prev; /**< Previous in list */
-};
-
-static struct dom_impl_src_item *sources; /**< List of registered sources */
-static dom_alloc alloc;
-static void *pw;
-
-/**
- * Initialise the implementation registry
- *
- * \param allocator The memory allocator
- * \param ptr Private data pointer of allocator
- * \return DOM_NO_ERR on success
- */
-dom_exception dom_implregistry_initialise(
- dom_alloc allocator, void *ptr)
-{
- alloc = allocator;
- pw = ptr;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Retrieve a DOM implementation from the registry
- *
- * \param features String containing required features
- * \param impl Pointer to location to receive implementation
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function. The implementation's
- * destroy() method will be called once it is no longer used.
- *
- * The implementation will be referenced, so the client need not
- * do this explicitly. The client must unref the implementation
- * once it has finished with it.
- */
-dom_exception dom_implregistry_get_dom_implementation(
- struct dom_string *features,
- struct dom_implementation **impl)
-{
- struct dom_impl_src_item *item;
- struct dom_implementation *found = NULL;
- dom_exception err;
-
- for (item = sources; item; item = item->next) {
- err = item->source->get_dom_implementation(features, &found);
- if (err != DOM_NO_ERR)
- return err;
-
- if (found != NULL)
- break;
- }
-
- *impl = found;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Get a list of DOM implementations that support the requested
- * features
- *
- * \param features String containing required features
- * \param list Pointer to location to receive list
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- *
- * List nodes reference the implementation objects they point to.
- *
- * The list will be referenced, so the client need not do this
- * explicitly. The client must unref the list once it has finished
- * with it.
- */
-dom_exception dom_implregistry_get_dom_implementation_list(
- struct dom_string *features,
- struct dom_implementation_list **list)
-{
- struct dom_implementation_list *l;
- struct dom_impl_src_item *item;
- dom_exception err;
-
- l = alloc(NULL, sizeof(struct dom_implementation_list), pw);
- if (l == NULL)
- return DOM_NO_MEM_ERR;
-
- l->head = NULL;
- l->refcnt = 1;
- l->destroy = dom_implementation_list_destroy;
-
- for (item = sources; item; item = item->next) {
- struct dom_implementation_list *plist = NULL;
- struct dom_implementation_list_item *plast = NULL;
-
- err = item->source->get_dom_implementation_list(features,
- &plist);
- if (err != DOM_NO_ERR) {
- dom_implementation_list_unref(l);
- return err;
- }
-
- if (plist == NULL)
- continue;
-
- if (plist->head == NULL) {
- dom_implementation_list_unref(plist);
- continue;
- }
-
- /* Get last item in list for this source */
- for (plast = plist->head; plast; plast = plast->next) {
- if (plast->next == NULL)
- break;
- }
-
- /* Prepend list for this source onto result list */
- plast->next = l->head;
- if (l->head != NULL)
- l->head->prev = plast;
- l->head = plist->head;
-
- /* Invalidate entire content of list for this source */
- plist->head = NULL;
-
- /* And unref it */
- dom_implementation_list_unref(plist);
- }
-
- if (l->head == NULL) {
- *list = NULL;
- dom_implementation_list_unref(l);
- } else {
- *list = l;
- }
-
- return DOM_NO_ERR;
-}
-
-/**
- * Register a DOM implementation source with the DOM library
- *
- * \param source The implementation source to register
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
- */
-dom_exception dom_register_source(struct dom_implementation_source *source)
-{
- struct dom_impl_src_item *item;
-
- item = alloc(NULL, sizeof(struct dom_impl_src_item), pw);
- if (item == NULL)
- return DOM_NO_MEM_ERR;
-
- item->source = source;
-
- item->next = sources;
- item->prev = NULL;
-
- if (sources != NULL)
- sources->prev = item;
-
- sources = item;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Destroy a dom_implementation_list
- *
- * \param list The list to destory
- */
-void dom_implementation_list_destroy(struct dom_implementation_list *list)
-{
- struct dom_implementation_list_item *i, *j;
-
- /* Destroy all list entries */
- for (i = list->head; i; i = j) {
- j = i->next;
-
- /* Unreference the implementation */
- dom_implementation_unref(i->impl);
-
- /* And free the entry */
- alloc(i, 0, pw);
- }
-
- /* Free the list object */
- alloc(list, 0, pw);
-}
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;
diff --git a/src/bootstrap/init_fini.c b/src/dom.c
index f3c7290..b163d28 100644
--- a/src/bootstrap/init_fini.c
+++ b/src/dom.c
@@ -7,11 +7,9 @@
#include <stdbool.h>
-#include <dom/bootstrap/init_fini.h>
-#include <dom/bootstrap/implregistry.h>
+#include <dom/dom.h>
#include "utils/namespace.h"
-#include "bootstrap/implementation.h"
static bool __initialised;
@@ -38,16 +36,6 @@ dom_exception dom_initialise(dom_alloc alloc, void *pw)
return err;
}
- err = dom_implregistry_initialise(alloc, pw);
- if (err != DOM_NO_ERR) {
- return err;
- }
-
- err = _dom_implementation_initialise(alloc, pw);
- if (err != DOM_NO_ERR) {
- return err;
- }
-
__initialised = true;
return DOM_NO_ERR;
@@ -69,8 +57,6 @@ dom_exception dom_finalise(void)
return DOM_NO_ERR;
}
- _dom_implementation_finalise();
-
err = _dom_namespace_finalise();
if (err != DOM_NO_ERR) {
return err;
diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm
index ce392c0..0bd4b81 100644
--- a/test/DOMTSHandler.pm
+++ b/test/DOMTSHandler.pm
@@ -362,7 +362,6 @@ sub generate_main {
#include <dom/dom.h>
#include <dom/functypes.h>
-#include <dom/bootstrap/init_fini.h>
#include <domts.h>
diff --git a/test/testutils/domtsasserts.c b/test/testutils/domtsasserts.c
index bd0eab1..488f294 100644
--- a/test/testutils/domtsasserts.c
+++ b/test/testutils/domtsasserts.c
@@ -14,8 +14,6 @@
#include "domts.h"
-extern dom_implementation *doc_impl;
-
void __assert2(const char *expr, const char *function,
const char *file, int line)
{
@@ -237,7 +235,7 @@ bool has_feature(char *feature, char *version)
return false;
}
- err = dom_implementation_has_feature(doc_impl, df, dv, &ret);
+ err = dom_implementation_has_feature(df, dv, &ret);
/* Here, when we come with exception, we should return false,
* TODO: this need to be improved, but I can't figure out how */
if (err != DOM_NO_ERR) {