summaryrefslogtreecommitdiff
path: root/src/core/implementation.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-12-05 23:52:56 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-12-05 23:52:56 +0000
commitac42344d05ec326f0063133498ec1c040e924db2 (patch)
tree4041bc41d72721a94dc573e5be3cb0f80988e004 /src/core/implementation.c
parentc9c2a632f38b736d6879caf00aa477ecf2e22dfb (diff)
downloadlibdom-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/implementation.c')
-rw-r--r--src/core/implementation.c147
1 files changed, 108 insertions, 39 deletions
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;
}