diff options
Diffstat (limited to 'src/bootstrap')
-rw-r--r-- | src/bootstrap/Makefile | 3 | ||||
-rw-r--r-- | src/bootstrap/implementation.c | 426 | ||||
-rw-r--r-- | src/bootstrap/implementation.h | 14 | ||||
-rw-r--r-- | src/bootstrap/implregistry.c | 215 | ||||
-rw-r--r-- | src/bootstrap/init_fini.c | 83 |
5 files changed, 0 insertions, 741 deletions
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/bootstrap/init_fini.c b/src/bootstrap/init_fini.c deleted file mode 100644 index f3c7290..0000000 --- a/src/bootstrap/init_fini.c +++ /dev/null @@ -1,83 +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 <stdbool.h> - -#include <dom/bootstrap/init_fini.h> -#include <dom/bootstrap/implregistry.h> - -#include "utils/namespace.h" -#include "bootstrap/implementation.h" - -static bool __initialised; - -/** - * Initialise the dom library - * - * \param alloc Pointer to memory (de)allocation function - * \param pw Pointer to client-specific private data - * \return DOM_NO_ERR on success. - * - * This must be the first DOM library method called. - */ -dom_exception dom_initialise(dom_alloc alloc, void *pw) -{ - dom_exception err; - - /* Ensure we only initialise once */ - if (__initialised) { - return DOM_NO_ERR; - } - - err = _dom_namespace_initialise(alloc, pw); - if (err != DOM_NO_ERR) { - 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; -} - -/** - * Finalise the dom library - * - * \return DOM_NO_ERR on success. - * - * This must be the last DOM library method called. - */ -dom_exception dom_finalise(void) -{ - dom_exception err; - - /* Ensure we only finalise once */ - if (__initialised == false) { - return DOM_NO_ERR; - } - - _dom_implementation_finalise(); - - err = _dom_namespace_finalise(); - if (err != DOM_NO_ERR) { - return err; - } - - __initialised = false; - - return DOM_NO_ERR; -} - |