From d39dbc93d93f537962fe998031ade04d7ee6ca6a Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 6 Jul 2007 21:42:18 +0000 Subject: Purge all trace of the ballache that was dom_ctx. Document the functions in document.c svn path=/trunk/dom/; revision=3385 --- docs/Todo | 7 - include/dom/core/attr.h | 27 +- include/dom/core/document.h | 123 ++++----- include/dom/core/exceptions.h | 4 +- include/dom/core/node.h | 149 +++++------ include/dom/core/string.h | 18 +- include/dom/ctx.h | 26 -- include/dom/functypes.h | 18 ++ src/core/attr.c | 44 +--- src/core/document.c | 577 +++++++++++++++++++++++++++++++++++------- src/core/document.h | 6 +- src/core/node.c | 264 +++++++------------ src/core/node.h | 3 +- src/core/string.c | 75 +++--- 14 files changed, 779 insertions(+), 562 deletions(-) delete mode 100644 include/dom/ctx.h create mode 100644 include/dom/functypes.h diff --git a/docs/Todo b/docs/Todo index 507eee9..2deb965 100644 --- a/docs/Todo +++ b/docs/Todo @@ -1,13 +1,6 @@ TODO list ========= - + Sort out the mess that is dom_ctx - I really don't like it; everything (except dom_strings) - should be allocated in the context of a document and, thus, the context is easily found - through foo->owner->blah. dom_strings are somewhat awkward here, as they aren't necessarily - allocated in the context of a document, but they still need access to an allocator. Perhaps - the simplest solution is for the string constructors to take an allocator and private word - as parameters, then store them within the string. This does, however, add an overhead of - 8 (or 16 on 64bit platforms) bytes per dom_string, which isn't exactly great. + Fill out stub functions for DOM3 core + Rest of DOM level 3 + DOM level 2 diff --git a/include/dom/core/attr.h b/include/dom/core/attr.h index 782513e..8807686 100644 --- a/include/dom/core/attr.h +++ b/include/dom/core/attr.h @@ -12,26 +12,23 @@ #include -struct dom_ctx; struct dom_element; struct dom_typeinfo; struct dom_node; struct dom_attr; struct dom_string; -dom_exception dom_attr_get_name(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string **result); -dom_exception dom_attr_get_specified(struct dom_ctx *ctx, - struct dom_attr *attr, bool *result); -dom_exception dom_attr_get_value(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string **result); -dom_exception dom_attr_set_value(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string *value); -dom_exception dom_attr_get_owner(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_element **result); -dom_exception dom_attr_get_typeinfo(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_typeinfo **result); -dom_exception dom_attr_is_id(struct dom_ctx *ctx, - struct dom_attr *attr, bool *result); +dom_exception dom_attr_get_name(struct dom_attr *attr, + struct dom_string **result); +dom_exception dom_attr_get_specified(struct dom_attr *attr, bool *result); +dom_exception dom_attr_get_value(struct dom_attr *attr, + struct dom_string **result); +dom_exception dom_attr_set_value(struct dom_attr *attr, + struct dom_string *value); +dom_exception dom_attr_get_owner(struct dom_attr *attr, + struct dom_element **result); +dom_exception dom_attr_get_typeinfo(struct dom_attr *attr, + struct dom_typeinfo **result); +dom_exception dom_attr_is_id(struct dom_attr *attr, bool *result); #endif diff --git a/include/dom/core/document.h b/include/dom/core/document.h index 347fdc4..96b8dca 100644 --- a/include/dom/core/document.h +++ b/include/dom/core/document.h @@ -14,7 +14,6 @@ struct dom_attr; struct dom_configuration; -struct dom_ctx; struct dom_document; struct dom_document_type; struct dom_element; @@ -24,81 +23,69 @@ struct dom_nodelist; struct dom_string; struct dom_text; -dom_exception dom_document_get_doctype(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_document_type **result); -dom_exception dom_document_get_implementation(struct dom_ctx *ctx, - struct dom_document *doc, +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_exception dom_document_get_element(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_element **result); -dom_exception dom_document_create_element(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *tag_name, +dom_exception dom_document_get_element(struct dom_document *doc, struct dom_element **result); -dom_exception dom_document_create_document_fragment(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node **result); -dom_exception dom_document_create_text_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *data, - struct dom_text **result); -dom_exception dom_document_create_cdata_section(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *data, - struct dom_text **result); -dom_exception dom_document_create_processing_instruction(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *target, - struct dom_string *data, +dom_exception dom_document_create_element(struct dom_document *doc, + struct dom_string *tag_name, struct dom_element **result); +dom_exception dom_document_create_document_fragment(struct dom_document *doc, struct dom_node **result); -dom_exception dom_document_create_attribute(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *name, +dom_exception dom_document_create_text_node(struct dom_document *doc, + struct dom_string *data, struct dom_text **result); +dom_exception dom_document_create_cdata_section(struct dom_document *doc, + struct dom_string *data, struct dom_text **result); +dom_exception dom_document_create_processing_instruction( + struct dom_document *doc, struct dom_string *target, + struct dom_string *data, struct dom_node **result); +dom_exception dom_document_create_attribute(struct dom_document *doc, + struct dom_string *name, struct dom_attr **result); +dom_exception dom_document_create_entity_reference(struct dom_document *doc, + struct dom_string *name, struct dom_node **result); +dom_exception dom_document_get_elements_by_tag_name(struct dom_document *doc, + struct dom_string *tagname, struct dom_nodelist **result); +dom_exception dom_document_import_node(struct dom_document *doc, + struct dom_node *node, bool deep, struct dom_node **result); +dom_exception dom_document_create_element_ns(struct dom_document *doc, + struct dom_string *namespace, struct dom_string *qname, + struct dom_element **result); +dom_exception dom_document_create_attribute_ns(struct dom_document *doc, + struct dom_string *namespace, struct dom_string *qname, struct dom_attr **result); -dom_exception dom_document_create_entity_reference(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *name, - struct dom_node **result); -dom_exception dom_document_get_elements_by_tag_name(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *tagname, - struct dom_nodelist **result); -dom_exception dom_document_import_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, - bool deep, struct dom_node **result); -dom_exception dom_document_create_element_ns(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *namespace, - struct dom_string *qname, struct dom_element **result); -dom_exception dom_document_create_attribute_ns(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *namespace, - struct dom_string *qname, struct dom_attr **result); -dom_exception dom_document_get_elements_by_tag_name_ns(struct dom_ctx *ctx, +dom_exception dom_document_get_elements_by_tag_name_ns( struct dom_document *doc, struct dom_string *namespace, struct dom_string *localname, struct dom_nodelist **result); -dom_exception dom_document_get_element_by_id(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *id, - struct dom_element **result); -dom_exception dom_document_get_input_encoding(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result); -dom_exception dom_document_get_xml_encoding(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result); -dom_exception dom_document_get_xml_standalone(struct dom_ctx *ctx, +dom_exception dom_document_get_element_by_id(struct dom_document *doc, + struct dom_string *id, struct dom_element **result); +dom_exception dom_document_get_input_encoding(struct dom_document *doc, + struct dom_string **result); +dom_exception dom_document_get_xml_encoding(struct dom_document *doc, + struct dom_string **result); +dom_exception dom_document_get_xml_standalone(struct dom_document *doc, + bool *result); +dom_exception dom_document_set_xml_standalone(struct dom_document *doc, + bool standalone); +dom_exception dom_document_get_xml_version(struct dom_document *doc, + struct dom_string **result); +dom_exception dom_document_set_xml_version(struct dom_document *doc, + struct dom_string *version); +dom_exception dom_document_get_strict_error_checking( struct dom_document *doc, bool *result); -dom_exception dom_document_set_xml_standalone(struct dom_ctx *ctx, - struct dom_document *doc, bool standalone); -dom_exception dom_document_get_xml_version(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result); -dom_exception dom_document_set_xml_version(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *version); -dom_exception dom_document_get_strict_error_checking(struct dom_ctx *ctx, - struct dom_document *doc, bool *result); -dom_exception dom_document_set_strict_error_checking(struct dom_ctx *ctx, +dom_exception dom_document_set_strict_error_checking( struct dom_document *doc, bool strict); -dom_exception dom_document_get_uri(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result); -dom_exception dom_document_set_uri(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *uri); -dom_exception dom_document_adopt_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, - struct dom_node **result); -dom_exception dom_document_get_dom_config(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_configuration **result); -dom_exception dom_document_normalize(struct dom_ctx *ctx, - struct dom_document *doc); -dom_exception dom_document_rename_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, +dom_exception dom_document_get_uri(struct dom_document *doc, + struct dom_string **result); +dom_exception dom_document_set_uri(struct dom_document *doc, + struct dom_string *uri); +dom_exception dom_document_adopt_node(struct dom_document *doc, + struct dom_node *node, struct dom_node **result); +dom_exception dom_document_get_dom_config(struct dom_document *doc, + struct dom_configuration **result); +dom_exception dom_document_normalize(struct dom_document *doc); +dom_exception dom_document_rename_node(struct dom_document *doc, + struct dom_node *node, struct dom_string *namespace, struct dom_string *qname, struct dom_node **result); diff --git a/include/dom/core/exceptions.h b/include/dom/core/exceptions.h index d735013..18a2b6e 100644 --- a/include/dom/core/exceptions.h +++ b/include/dom/core/exceptions.h @@ -5,8 +5,8 @@ * Copyright 2007 John-Mark Bell */ -#ifndef dom_errors_h_ -#define dom_errors_h_ +#ifndef dom_core_exceptions_h_ +#define dom_core_exceptions_h_ /* The DOM spec says that this is actually an unsigned short */ typedef enum { diff --git a/include/dom/core/node.h b/include/dom/core/node.h index e37d99b..e335007 100644 --- a/include/dom/core/node.h +++ b/include/dom/core/node.h @@ -13,7 +13,6 @@ #include -struct dom_ctx; struct dom_document; struct dom_node; struct dom_node_list; @@ -69,102 +68,86 @@ typedef enum { } dom_node_type; -void dom_node_ref(struct dom_ctx *ctx, struct dom_node *node); -void dom_node_unref(struct dom_ctx *ctx, struct dom_node *node); +void dom_node_ref(struct dom_node *node); +void dom_node_unref(struct dom_node *node); -dom_exception dom_node_get_name(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_get_value(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_set_value(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *value); -dom_exception dom_node_get_type(struct dom_ctx *ctx, - struct dom_node *node, dom_node_type *result); -dom_exception dom_node_get_parent(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result); -dom_exception dom_node_get_children(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node_list **result); -dom_exception dom_node_get_first_child(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result); -dom_exception dom_node_get_last_child(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result); -dom_exception dom_node_get_previous(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result); -dom_exception dom_node_get_next(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result); -dom_exception dom_node_get_attributes(struct dom_ctx *ctx, - struct dom_node *node, struct dom_named_node_map **result); -dom_exception dom_node_get_owner(struct dom_ctx *ctx, - struct dom_node *node, struct dom_document **result); -dom_exception dom_node_insert_before(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_get_name(struct dom_node *node, + struct dom_string **result); +dom_exception dom_node_get_value(struct dom_node *node, + struct dom_string **result); +dom_exception dom_node_set_value(struct dom_node *node, + struct dom_string *value); +dom_exception dom_node_get_type(struct dom_node *node, + dom_node_type *result); +dom_exception dom_node_get_parent(struct dom_node *node, + struct dom_node **result); +dom_exception dom_node_get_children(struct dom_node *node, + struct dom_node_list **result); +dom_exception dom_node_get_first_child(struct dom_node *node, + struct dom_node **result); +dom_exception dom_node_get_last_child(struct dom_node *node, + struct dom_node **result); +dom_exception dom_node_get_previous(struct dom_node *node, + struct dom_node **result); +dom_exception dom_node_get_next(struct dom_node *node, + struct dom_node **result); +dom_exception dom_node_get_attributes(struct dom_node *node, + struct dom_named_node_map **result); +dom_exception dom_node_get_owner(struct dom_node *node, + struct dom_document **result); +dom_exception dom_node_insert_before(struct dom_node *node, struct dom_node *new_child, struct dom_node *ref_child, struct dom_node **result); -dom_exception dom_node_replace_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_replace_child(struct dom_node *node, struct dom_node *new_child, struct dom_node *old_child, struct dom_node **result); -dom_exception dom_node_remove_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_remove_child(struct dom_node *node, struct dom_node *old_child, struct dom_node **result); -dom_exception dom_node_append_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_append_child(struct dom_node *node, struct dom_node *new_child, struct dom_node **result); -dom_exception dom_node_has_children(struct dom_ctx *ctx, - struct dom_node *node, bool *result); -dom_exception dom_node_clone(struct dom_ctx *ctx, - struct dom_node *node, bool deep, +dom_exception dom_node_has_children(struct dom_node *node, bool *result); +dom_exception dom_node_clone(struct dom_node *node, bool deep, struct dom_node **result); -dom_exception dom_node_normalize(struct dom_ctx *ctx, - struct dom_node *node); -dom_exception dom_node_is_supported(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *feature, - struct dom_node *version, bool *result); -dom_exception dom_node_get_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_get_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_set_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *prefix); -dom_exception dom_node_get_local_name(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_has_attributes(struct dom_ctx *ctx, - struct dom_node *node, bool *result); -dom_exception dom_node_get_base(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_compare_document_position(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, - uint16_t *result); -dom_exception dom_node_get_text_content(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result); -dom_exception dom_node_set_text_content(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *content); -dom_exception dom_node_is_same(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, +dom_exception dom_node_normalize(struct dom_node *node); +dom_exception dom_node_is_supported(struct dom_node *node, + struct dom_string *feature, struct dom_node *version, bool *result); -dom_exception dom_node_lookup_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *namespace, +dom_exception dom_node_get_namespace(struct dom_node *node, struct dom_string **result); -dom_exception dom_node_is_default_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *namespace, - bool *result); -dom_exception dom_node_lookup_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *prefix, +dom_exception dom_node_get_prefix(struct dom_node *node, + struct dom_string **result); +dom_exception dom_node_set_prefix(struct dom_node *node, + struct dom_string *prefix); +dom_exception dom_node_get_local_name(struct dom_node *node, struct dom_string **result); -dom_exception dom_node_is_equal(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, +dom_exception dom_node_has_attributes(struct dom_node *node, bool *result); +dom_exception dom_node_get_base(struct dom_node *node, + struct dom_string **result); +dom_exception dom_node_compare_document_position(struct dom_node *node, + struct dom_node *other, uint16_t *result); +dom_exception dom_node_get_text_content(struct dom_node *node, + struct dom_string **result); +dom_exception dom_node_set_text_content(struct dom_node *node, + struct dom_string *content); +dom_exception dom_node_is_same(struct dom_node *node, struct dom_node *other, bool *result); -dom_exception dom_node_get_feature(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *feature, - struct dom_string *version, void **result); -dom_exception dom_node_set_user_data(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *key, - void *data, dom_user_data_handler handler, - void **result); -dom_exception dom_node_get_user_data(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *key, +dom_exception dom_node_lookup_prefix(struct dom_node *node, + struct dom_string *namespace, struct dom_string **result); +dom_exception dom_node_is_default_namespace(struct dom_node *node, + struct dom_string *namespace, bool *result); +dom_exception dom_node_lookup_namespace(struct dom_node *node, + struct dom_string *prefix, struct dom_string **result); +dom_exception dom_node_is_equal(struct dom_node *node, + struct dom_node *other, bool *result); +dom_exception dom_node_get_feature(struct dom_node *node, + struct dom_string *feature, struct dom_string *version, void **result); +dom_exception dom_node_set_user_data(struct dom_node *node, + struct dom_string *key, void *data, + dom_user_data_handler handler, void **result); +dom_exception dom_node_get_user_data(struct dom_node *node, + struct dom_string *key, void **result); #endif diff --git a/include/dom/core/string.h b/include/dom/core/string.h index f79eaa7..f591464 100644 --- a/include/dom/core/string.h +++ b/include/dom/core/string.h @@ -13,28 +13,26 @@ #include -struct dom_ctx; struct dom_document; struct dom_string; /* Claim a reference on a DOM string */ -void dom_string_ref(struct dom_ctx *ctx, struct dom_string *str); +void dom_string_ref(struct dom_string *str); /* Release a reference on a DOM string */ -void dom_string_unref(struct dom_ctx *ctx, struct dom_string *str); +void dom_string_unref(struct dom_string *str); /* Create a DOM string from an offset into the document buffer */ -dom_exception dom_string_create_from_off(struct dom_ctx *ctx, - struct dom_document *doc, uint32_t off, size_t len, - struct dom_string **str); +dom_exception dom_string_create_from_off(struct dom_document *doc, + uint32_t off, size_t len, struct dom_string **str); /* Create a DOM string from a string of characters */ -dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, +dom_exception dom_string_create_from_ptr(struct dom_document *doc, const uint8_t *ptr, size_t len, struct dom_string **str); /* Create a DOM string from a constant string of characters */ -dom_exception dom_string_create_from_const_ptr(struct dom_ctx *ctx, +dom_exception dom_string_create_from_const_ptr(struct dom_document *doc, const uint8_t *ptr, size_t len, struct dom_string **str); /* Get a pointer to the string of characters within a DOM string */ -dom_exception dom_string_get_data(struct dom_ctx *ctx, - struct dom_string *str, const uint8_t **data, size_t *len); +dom_exception dom_string_get_data(struct dom_string *str, + const uint8_t **data, size_t *len); #endif diff --git a/include/dom/ctx.h b/include/dom/ctx.h deleted file mode 100644 index f69ec65..0000000 --- a/include/dom/ctx.h +++ /dev/null @@ -1,26 +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 - */ - -#ifndef dom_ctx_h_ -#define dom_ctx_h_ - -#include - -/** - * Type of allocation function for DOM implementation - */ -typedef void *(*dom_alloc)(void *ptr, size_t size, void *pw); - -/** - * DOM allocation context - */ -struct dom_ctx { - dom_alloc alloc; /**< Memory (de)allocation function */ - void *pw; /**< Pointer to client data */ -}; - -#endif diff --git a/include/dom/functypes.h b/include/dom/functypes.h new file mode 100644 index 0000000..85348a2 --- /dev/null +++ b/include/dom/functypes.h @@ -0,0 +1,18 @@ +/* + * This file is part of libdom. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2007 John-Mark Bell + */ + +#ifndef dom_functypes_h_ +#define dom_functypes_h_ + +#include + +/** + * Type of allocation function for DOM implementation + */ +typedef void *(*dom_alloc)(void *ptr, size_t size, void *pw); + +#endif diff --git a/src/core/attr.c b/src/core/attr.c index 32fa66f..5414ce0 100644 --- a/src/core/attr.c +++ b/src/core/attr.c @@ -32,7 +32,6 @@ struct dom_attr { /** * Retrieve an attribute's name * - * \param ctx The context in which the attribute resides * \param attr Attribute to retrieve name from * \param result Pointer to location to receive result * \return DOM_NO_ERR. @@ -41,10 +40,9 @@ struct dom_attr { * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_attr_get_name(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string **result) +dom_exception dom_attr_get_name(struct dom_attr *attr, + struct dom_string **result) { - UNUSED(ctx); UNUSED(attr); UNUSED(result); @@ -54,15 +52,12 @@ dom_exception dom_attr_get_name(struct dom_ctx *ctx, /** * Determine if attribute was specified or defaulted * - * \param ctx The context in which the attribute resides * \param attr Attribute to inspect * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_attr_get_specified(struct dom_ctx *ctx, - struct dom_attr *attr, bool *result) +dom_exception dom_attr_get_specified(struct dom_attr *attr, bool *result) { - UNUSED(ctx); *result = attr->specified; @@ -72,7 +67,6 @@ dom_exception dom_attr_get_specified(struct dom_ctx *ctx, /** * Retrieve an attribute's value * - * \param ctx The context in which the attribute resides * \param attr Attribute to retrieve value from * \param result Pointer to location to receive result * \return DOM_NO_ERR. @@ -81,10 +75,9 @@ dom_exception dom_attr_get_specified(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_attr_get_value(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string **result) +dom_exception dom_attr_get_value(struct dom_attr *attr, + struct dom_string **result) { - UNUSED(ctx); UNUSED(attr); UNUSED(result); @@ -94,16 +87,14 @@ dom_exception dom_attr_get_value(struct dom_ctx *ctx, /** * Set an attribute's value * - * \param ctx The context in which the attribute resides * \param attr Attribute to retrieve value from * \param value New value for attribute * \return DOM_NO_ERR on success, * DOM_NO_MODIFICATION_ALLOWED_ERR if attribute is readonly. */ -dom_exception dom_attr_set_value(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_string *value) +dom_exception dom_attr_set_value(struct dom_attr *attr, + struct dom_string *value) { - UNUSED(ctx); UNUSED(attr); UNUSED(value); @@ -113,7 +104,6 @@ dom_exception dom_attr_set_value(struct dom_ctx *ctx, /** * Retrieve the owning element of an attribute * - * \param ctx The context in which the attribute resides * \param attr The attribute to extract owning element from * \param result Pointer to location to receive result * \return DOM_NO_ERR. @@ -121,12 +111,12 @@ dom_exception dom_attr_set_value(struct dom_ctx *ctx, * The returned node will have its reference count increased. The caller * should unref it once it has finished with it. */ -dom_exception dom_attr_get_owner(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_element **result) +dom_exception dom_attr_get_owner(struct dom_attr *attr, + struct dom_element **result) { /* If there is an owning element, increase its reference count */ if (attr->owner != NULL) - dom_node_ref(ctx, (struct dom_node *) attr->owner); + dom_node_ref((struct dom_node *) attr->owner); *result = attr->owner; @@ -136,18 +126,16 @@ dom_exception dom_attr_get_owner(struct dom_ctx *ctx, /** * Retrieve an attribute's type information * - * \param ctx The context in which the attribute resides - * \param attr The attribute to extract type information from + * \param attr The attribute to extract type information from * \param result Pointer to location to receive result * \return DOM_NO_ERR. * * The returned typeinfo will have its reference count increased. The caller * should unref it once it has finished with it. */ -dom_exception dom_attr_get_typeinfo(struct dom_ctx *ctx, - struct dom_attr *attr, struct dom_typeinfo **result) +dom_exception dom_attr_get_typeinfo(struct dom_attr *attr, + struct dom_typeinfo **result) { - UNUSED(ctx); UNUSED(attr); UNUSED(result); @@ -157,16 +145,12 @@ dom_exception dom_attr_get_typeinfo(struct dom_ctx *ctx, /** * Determine if an attribute if of type ID * - * \param ctx The context in which the attribute resides * \param attr The attribute to inspect * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_attr_is_id(struct dom_ctx *ctx, - struct dom_attr *attr, bool *result) +dom_exception dom_attr_is_id(struct dom_attr *attr, bool *result) { - UNUSED(ctx); - *result = attr->is_id; return DOM_NO_ERR; diff --git a/src/core/document.c b/src/core/document.c index 1d54dfd..6edce6e 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -5,8 +5,10 @@ * Copyright 2007 John-Mark Bell */ +#include #include +#include "core/document.h" #include "core/node.h" #include "utils/utils.h" @@ -15,45 +17,83 @@ */ struct dom_document { struct dom_node base; /**< Base node */ -}; + dom_alloc alloc; /**< Memory (de)allocation function */ + void *pw; /**< Pointer to client data */ +}; -dom_exception dom_document_get_doctype(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_document_type **result) +/** + * Retrieve the doctype of a document + * + * \param doc The document to retrieve the doctype from + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_get_doctype(struct dom_document *doc, + struct dom_document_type **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_implementation(struct dom_ctx *ctx, - struct dom_document *doc, +/** + * Retrieve the DOM implementation that handles this document + * + * \param doc The document to retrieve the implementation from + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + */ +dom_exception dom_document_get_implementation(struct dom_document *doc, struct dom_implementation **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_element(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_element **result) +/** + * Retrieve the document element of a document + * + * \param doc The document to retrieve the document element from + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_get_element(struct dom_document *doc, + struct dom_element **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_element(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *tag_name, - struct dom_element **result) +/** + * Create an element + * + * \param doc The document owning the element + * \param tag_name The name of the element + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::tag_name is invalid. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_element(struct dom_document *doc, + struct dom_string *tag_name, struct dom_element **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(tag_name); UNUSED(result); @@ -61,21 +101,41 @@ dom_exception dom_document_create_element(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_document_fragment(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node **result) +/** + * Create a document fragment + * + * \param doc The document owning the fragment + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_document_fragment(struct dom_document *doc, + struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_text_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *data, - struct dom_text **result) +/** + * Create a text node + * + * \param doc The document owning the node + * \param data The data for the node + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_text_node(struct dom_document *doc, + struct dom_string *data, struct dom_text **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(data); UNUSED(result); @@ -83,11 +143,22 @@ dom_exception dom_document_create_text_node(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_cdata_section(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *data, - struct dom_text **result) +/** + * Create a CDATA section + * + * \param doc The document owning the section + * \param data The data for the section contents + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_NOT_SUPPORTED_ERR if this is an HTML document. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_cdata_section(struct dom_document *doc, + struct dom_string *data, struct dom_text **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(data); UNUSED(result); @@ -95,12 +166,26 @@ dom_exception dom_document_create_cdata_section(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_processing_instruction(struct dom_ctx *ctx, +/** + * Create a processing instruction + * + * \param doc The document owning the instruction + * \param target The instruction target + * \param data The data for the node + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::target is invalid, + * DOM_NOT_SUPPORTED_ERR if this is an HTML document. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_processing_instruction( struct dom_document *doc, struct dom_string *target, struct dom_string *data, struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(target); UNUSED(data); @@ -109,11 +194,22 @@ dom_exception dom_document_create_processing_instruction(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_attribute(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *name, - struct dom_attr **result) +/** + * Create an attribute + * + * \param doc The document owning the attribute + * \param name The name of the attribute + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::name is invalid. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_attribute(struct dom_document *doc, + struct dom_string *name, struct dom_attr **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(name); UNUSED(result); @@ -121,11 +217,23 @@ dom_exception dom_document_create_attribute(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_entity_reference(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *name, - struct dom_node **result) +/** + * Create an entity reference + * + * \param doc The document owning the reference + * \param name The name of the entity to reference + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::name is invalid, + * DOM_NOT_SUPPORTED_ERR if this is an HTML document. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_entity_reference(struct dom_document *doc, + struct dom_string *name, struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(name); UNUSED(result); @@ -133,11 +241,21 @@ dom_exception dom_document_create_entity_reference(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_elements_by_tag_name(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *tagname, - struct dom_nodelist **result) +/** + * Retrieve a list of all elements with a given tag name + * + * \param doc The document to search in + * \param tagname The tag name to search for ("*" for all) + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned list will have its reference count increased. It is + * the responsibility of the caller to unref the list once it has + * finished with it. + */ +dom_exception dom_document_get_elements_by_tag_name(struct dom_document *doc, + struct dom_string *tagname, struct dom_nodelist **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(tagname); UNUSED(result); @@ -145,11 +263,24 @@ dom_exception dom_document_get_elements_by_tag_name(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_import_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, - bool deep, struct dom_node **result) +/** + * Import a node from another document into this one + * + * \param doc The document to import into + * \param node The node to import + * \param deep Whether to copy the node's subtree + * \param result Pointer to location to receive imported node in this document. + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if any of the names are invalid, + * DOM_NOT_SUPPORTED_ERR if the type of ::node is unsupported + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_import_node(struct dom_document *doc, + struct dom_node *node, bool deep, struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(node); UNUSED(deep); @@ -158,11 +289,38 @@ dom_exception dom_document_import_node(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_element_ns(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *namespace, - struct dom_string *qname, struct dom_element **result) +/** + * Create an element from the qualified name and namespace URI + * + * \param doc The document owning the element + * \param namespace The namespace URI to use + * \param qname The qualified name of the element + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::tag_name is invalid, + * DOM_NAMESPACE_ERR if ::qname is malformed, or it has a + * prefix and ::namespace is NULL, or + * ::qname has a prefix "xml" and + * ::namespace is not + * "http://www.w3.org/XML/1998/namespace", + * or ::qname has a prefix "xmlns" and + * ::namespace is not + * "http://www.w3.org/2000/xmlns", or + * ::namespace is + * "http://www.w3.org/2000/xmlns" and + * ::qname is not (or is not prefixed by) + * "xmlns", + * DOM_NOT_SUPPORTED_ERR if ::doc does not support the "XML" + * feature. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_element_ns(struct dom_document *doc, + struct dom_string *namespace, struct dom_string *qname, + struct dom_element **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(namespace); UNUSED(qname); @@ -171,11 +329,38 @@ dom_exception dom_document_create_element_ns(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_create_attribute_ns(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *namespace, - struct dom_string *qname, struct dom_attr **result) +/** + * Create an attribute from the qualified name and namespace URI + * + * \param doc The document owning the attribute + * \param namespace The namespace URI to use + * \param qname The qualified name of the attribute + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::tag_name is invalid, + * DOM_NAMESPACE_ERR if ::qname is malformed, or it has a + * prefix and ::namespace is NULL, or + * ::qname has a prefix "xml" and + * ::namespace is not + * "http://www.w3.org/XML/1998/namespace", + * or ::qname has a prefix "xmlns" and + * ::namespace is not + * "http://www.w3.org/2000/xmlns", or + * ::namespace is + * "http://www.w3.org/2000/xmlns" and + * ::qname is not (or is not prefixed by) + * "xmlns", + * DOM_NOT_SUPPORTED_ERR if ::doc does not support the "XML" + * feature. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_create_attribute_ns(struct dom_document *doc, + struct dom_string *namespace, struct dom_string *qname, + struct dom_attr **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(namespace); UNUSED(qname); @@ -184,11 +369,23 @@ dom_exception dom_document_create_attribute_ns(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_elements_by_tag_name_ns(struct dom_ctx *ctx, +/** + * Retrieve a list of all elements with a given local name and namespace URI + * + * \param doc The document to search in + * \param namespace The namespace URI + * \param localname The local name + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned list will have its reference count increased. It is + * the responsibility of the caller to unref the list once it has + * finished with it. + */ +dom_exception dom_document_get_elements_by_tag_name_ns( struct dom_document *doc, struct dom_string *namespace, struct dom_string *localname, struct dom_nodelist **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(namespace); UNUSED(localname); @@ -197,11 +394,21 @@ dom_exception dom_document_get_elements_by_tag_name_ns(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_element_by_id(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *id, - struct dom_element **result) +/** + * Retrieve the element that matches the specified ID + * + * \param doc The document to search in + * \param id The ID to search for + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_get_element_by_id(struct dom_document *doc, + struct dom_string *id, struct dom_element **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(id); UNUSED(result); @@ -209,111 +416,208 @@ dom_exception dom_document_get_element_by_id(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_input_encoding(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result) +/** + * Retrieve the input encoding of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned string will have its reference count increased. It is + * the responsibility of the caller to unref the string once it has + * finished with it. + */ +dom_exception dom_document_get_input_encoding(struct dom_document *doc, + struct dom_string **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_xml_encoding(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result) +/** + * Retrieve the XML encoding of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned string will have its reference count increased. It is + * the responsibility of the caller to unref the string once it has + * finished with it. + */ +dom_exception dom_document_get_xml_encoding(struct dom_document *doc, + struct dom_string **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_xml_standalone(struct dom_ctx *ctx, - struct dom_document *doc, bool *result) +/** + * Retrieve the standalone status of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + */ +dom_exception dom_document_get_xml_standalone(struct dom_document *doc, + bool *result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_set_xml_standalone(struct dom_ctx *ctx, - struct dom_document *doc, bool standalone) +/** + * Set the standalone status of the document + * + * \param doc The document to query + * \param standalone Standalone status to use + * \return DOM_NO_ERR on success, + * DOM_NOT_SUPPORTED_ERR if the document does not support the "XML" + * feature. + */ +dom_exception dom_document_set_xml_standalone(struct dom_document *doc, + bool standalone) { - UNUSED(ctx); UNUSED(doc); UNUSED(standalone); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_xml_version(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result) +/** + * Retrieve the XML version of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned string will have its reference count increased. It is + * the responsibility of the caller to unref the string once it has + * finished with it. + */ +dom_exception dom_document_get_xml_version(struct dom_document *doc, + struct dom_string **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_set_xml_version(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *version) +/** + * Set the XML version of the document + * + * \param doc The document to query + * \param version XML version to use + * \return DOM_NO_ERR on success, + * DOM_NOT_SUPPORTED_ERR if the document does not support the "XML" + * feature. + */ +dom_exception dom_document_set_xml_version(struct dom_document *doc, + struct dom_string *version) { - UNUSED(ctx); UNUSED(doc); UNUSED(version); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_strict_error_checking(struct dom_ctx *ctx, +/** + * Retrieve the error checking mode of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + */ +dom_exception dom_document_get_strict_error_checking( struct dom_document *doc, bool *result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_set_strict_error_checking(struct dom_ctx *ctx, +/** + * Set the error checking mode of the document + * + * \param doc The document to query + * \param strict Whether to use strict error checking + * \return DOM_NO_ERR. + */ +dom_exception dom_document_set_strict_error_checking( struct dom_document *doc, bool strict) { - UNUSED(ctx); UNUSED(doc); UNUSED(strict); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_uri(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string **result) +/** + * Retrieve the URI of the document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned string will have its reference count increased. It is + * the responsibility of the caller to unref the string once it has + * finished with it. + */ +dom_exception dom_document_get_uri(struct dom_document *doc, + struct dom_string **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_set_uri(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_string *uri) +/** + * Set the URI of the document + * + * \param doc The document to query + * \param uri The URI to use + * \return DOM_NO_ERR. + * + * The returned string will have its reference count increased. It is + * the responsibility of the caller to unref the string once it has + * finished with it. + */ +dom_exception dom_document_set_uri(struct dom_document *doc, + struct dom_string *uri) { - UNUSED(ctx); UNUSED(doc); UNUSED(uri); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_adopt_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, - struct dom_node **result) +/** + * Attempt to adopt a node from another document into this document + * + * \param doc The document to adopt into + * \param node The node to adopt + * \param result Pointer to location to receive adopted node + * \return DOM_NO_ERR on success, + * DOM_NO_MODIFICATION_ALLOWED_ERR if ::node is readonly, + * DOM_NOT_SUPPORTED_ERR if ::node is of type Document or + * DocumentType + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_adopt_node(struct dom_document *doc, + struct dom_node *node, struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(node); UNUSED(result); @@ -321,31 +625,75 @@ dom_exception dom_document_adopt_node(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_get_dom_config(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_configuration **result) +/** + * Retrieve the DOM configuration associated with a document + * + * \param doc The document to query + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned object will have its reference count increased. It is + * the responsibility of the caller to unref the object once it has + * finished with it. + */ +dom_exception dom_document_get_dom_config(struct dom_document *doc, + struct dom_configuration **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(result); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_normalize(struct dom_ctx *ctx, - struct dom_document *doc) +/** + * Normalize a document + * + * \param doc The document to normalize + * \return DOM_NO_ERR. + */ +dom_exception dom_document_normalize(struct dom_document *doc) { - UNUSED(ctx); UNUSED(doc); return DOM_NOT_SUPPORTED_ERR; } -dom_exception dom_document_rename_node(struct dom_ctx *ctx, - struct dom_document *doc, struct dom_node *node, +/** + * Rename a node in a document + * + * \param doc The document containing the node + * \param node The node to rename + * \param namespace The new namespace for the node + * \param qname The new qualified name for the node + * \param result Pointer to location to receive renamed node + * \return DOM_NO_ERR on success, + * DOM_INVALID_CHARACTER_ERR if ::tag_name is invalid, + * DOM_WRONG_DOCUMENT_ERR if ::node was created in a different + * document + * DOM_NAMESPACE_ERR if ::qname is malformed, or it has a + * prefix and ::namespace is NULL, or + * ::qname has a prefix "xml" and + * ::namespace is not + * "http://www.w3.org/XML/1998/namespace", + * or ::qname has a prefix "xmlns" and + * ::namespace is not + * "http://www.w3.org/2000/xmlns", or + * ::namespace is + * "http://www.w3.org/2000/xmlns" and + * ::qname is not (or is not prefixed by) + * "xmlns", + * DOM_NOT_SUPPORTED_ERR if ::doc does not support the "XML" + * feature. + * + * The returned node will have its reference count increased. It is + * the responsibility of the caller to unref the node once it has + * finished with it. + */ +dom_exception dom_document_rename_node(struct dom_document *doc, + struct dom_node *node, struct dom_string *namespace, struct dom_string *qname, struct dom_node **result) { - UNUSED(ctx); UNUSED(doc); UNUSED(node); UNUSED(namespace); @@ -354,3 +702,36 @@ dom_exception dom_document_rename_node(struct dom_ctx *ctx, return DOM_NOT_SUPPORTED_ERR; } + +/** + * Acquire a pointer to the base of the document buffer + * + * \param doc Document to retrieve pointer from + * \return Pointer to document buffer + * + * The document buffer is _not_ reference counted (as it is an implicit part + * of the document). It is destroyed with the document, and thus after all + * users have been destroyed. + */ +const uint8_t *dom_document_get_base(struct dom_document *doc) +{ + UNUSED(doc); + + return NULL; +} + +/** + * (De)allocate memory with a document's context + * + * \param doc The document context to allocate from + * \param ptr Pointer to data to reallocate, or NULL to alloc new + * \param size Required size of data, or 0 to free + * \return Pointer to allocated data or NULL on failure + * + * This call (modulo ::doc) has the same semantics as realloc(). + * It is a thin veneer over the client-provided allocation function. + */ +void *dom_document_alloc(struct dom_document *doc, void *ptr, size_t size) +{ + return doc->alloc(ptr, size, doc->pw); +} diff --git a/src/core/document.h b/src/core/document.h index 399b2c8..7c18fe9 100644 --- a/src/core/document.h +++ b/src/core/document.h @@ -9,11 +9,11 @@ #define dom_internal_document_h_ #include +#include -struct dom_ctx; struct dom_document; -const uint8_t *dom_document_get_base(struct dom_ctx *ctx, - struct dom_document *doc); +const uint8_t *dom_document_get_base(struct dom_document *doc); +void *dom_document_alloc(struct dom_document *doc, void *ptr, size_t size); #endif diff --git a/src/core/node.c b/src/core/node.c index 4c2af88..468965b 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -5,15 +5,13 @@ * Copyright 2007 John-Mark Bell */ -#include - +#include "core/document.h" #include "core/node.h" #include "utils/utils.h" /** * Create a DOM node * - * \param ctx The context in which the node resides * \param doc The document which owns the node * \param type The node type required * \param name The node name, or NULL @@ -24,23 +22,22 @@ * The returned node will be referenced, so there is no need for the caller * to explicitly reference it. */ -dom_exception dom_node_create(struct dom_ctx *ctx, - struct dom_document *doc, dom_node_type type, +dom_exception dom_node_create(struct dom_document *doc, dom_node_type type, struct dom_string *name, struct dom_string *value, struct dom_node **node) { struct dom_node *n; - n = ctx->alloc(NULL, sizeof(struct dom_node), ctx->pw); + n = dom_document_alloc(doc, NULL, sizeof(struct dom_node)); if (n == NULL) return DOM_NO_MEM_ERR; if (name != NULL) - dom_string_ref(ctx, name); + dom_string_ref(name); n->name = name; if (value != NULL) - dom_string_ref(ctx, value); + dom_string_ref(value); n->value = value; n->type = type; @@ -52,7 +49,7 @@ dom_exception dom_node_create(struct dom_ctx *ctx, n->next = NULL; n->attributes = NULL; - dom_node_ref(ctx, (struct dom_node *) doc); + dom_node_ref((struct dom_node *) doc); n->owner = doc; /** \todo Namespace handling */ @@ -72,29 +69,23 @@ dom_exception dom_node_create(struct dom_ctx *ctx, /** * Claim a reference on a DOM node * - * \param ctx The context in which the node resides * \param node The node to claim a reference on */ -void dom_node_ref(struct dom_ctx *ctx, struct dom_node *node) +void dom_node_ref(struct dom_node *node) { - UNUSED(ctx); - node->refcnt++; } /** * Release a reference on a DOM node * - * \param ctx The context in which the node resides * \param node The node to release the reference from * * If the reference count reaches zero, any memory claimed by the * node will be released */ -void dom_node_unref(struct dom_ctx *ctx, struct dom_node *node) +void dom_node_unref(struct dom_node *node) { - UNUSED(ctx); - if (--node->refcnt == 0) { /** \todo implement */ } @@ -103,7 +94,6 @@ void dom_node_unref(struct dom_ctx *ctx, struct dom_node *node) /** * Retrieve the name of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the name of * \param result Pointer to location to receive node name * \return DOM_NO_ERR. @@ -112,10 +102,9 @@ void dom_node_unref(struct dom_ctx *ctx, struct dom_node *node) * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_get_name(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_name(struct dom_node *node, + struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -125,7 +114,6 @@ dom_exception dom_node_get_name(struct dom_ctx *ctx, /** * Retrieve the value of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the value of * \param result Pointer to location to receive node value * \return DOM_NO_ERR. @@ -137,10 +125,9 @@ dom_exception dom_node_get_name(struct dom_ctx *ctx, * DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in * this implementation; dom_strings are unbounded. */ -dom_exception dom_node_get_value(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_value(struct dom_node *node, + struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -150,7 +137,6 @@ dom_exception dom_node_get_value(struct dom_ctx *ctx, /** * Set the value of a DOM node * - * \param ctx The context in which the node resides * \param node Node to set the value of * \param value New value for node * \return DOM_NO_ERR on success, @@ -161,10 +147,9 @@ dom_exception dom_node_get_value(struct dom_ctx *ctx, * should unref it after the call (as the caller should have already claimed * a reference on the string). The node's existing value will be unrefed. */ -dom_exception dom_node_set_value(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *value) +dom_exception dom_node_set_value(struct dom_node *node, + struct dom_string *value) { - UNUSED(ctx); UNUSED(node); UNUSED(value); @@ -174,16 +159,12 @@ dom_exception dom_node_set_value(struct dom_ctx *ctx, /** * Retrieve the type of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the type of * \param result Pointer to location to receive node type * \return DOM_NO_ERR. */ -dom_exception dom_node_get_type(struct dom_ctx *ctx, - struct dom_node *node, dom_node_type *result) +dom_exception dom_node_get_type(struct dom_node *node, dom_node_type *result) { - UNUSED(ctx); - *result = node->type; return DOM_NO_ERR; @@ -192,7 +173,6 @@ dom_exception dom_node_get_type(struct dom_ctx *ctx, /** * Retrieve the parent of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the parent of * \param result Pointer to location to receive node parent * \return DOM_NO_ERR. @@ -201,12 +181,12 @@ dom_exception dom_node_get_type(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_parent(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result) +dom_exception dom_node_get_parent(struct dom_node *node, + struct dom_node **result) { /* If there is a parent node, then increase its reference count */ if (node->parent != NULL) - dom_node_ref(ctx, node->parent); + dom_node_ref(node->parent); *result = node->parent; @@ -216,17 +196,15 @@ dom_exception dom_node_get_parent(struct dom_ctx *ctx, /** * Retrieve a list of children of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the children of * \param result Pointer to location to receive child list * \return DOM_NO_ERR. * * \todo Work out reference counting semantics of dom_node_list */ -dom_exception dom_node_get_children(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node_list **result) +dom_exception dom_node_get_children(struct dom_node *node, + struct dom_node_list **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -236,7 +214,6 @@ dom_exception dom_node_get_children(struct dom_ctx *ctx, /** * Retrieve the first child of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the first child of * \param result Pointer to location to receive node's first child * \return DOM_NO_ERR. @@ -245,12 +222,12 @@ dom_exception dom_node_get_children(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_first_child(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result) +dom_exception dom_node_get_first_child(struct dom_node *node, + struct dom_node **result) { /* If there is a first child, increase its reference count */ if (node->first_child != NULL) - dom_node_ref(ctx, node->first_child); + dom_node_ref(node->first_child); *result = node->first_child; @@ -260,7 +237,6 @@ dom_exception dom_node_get_first_child(struct dom_ctx *ctx, /** * Retrieve the last child of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the last child of * \param result Pointer to location to receive node's last child * \return DOM_NO_ERR. @@ -269,12 +245,12 @@ dom_exception dom_node_get_first_child(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_last_child(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result) +dom_exception dom_node_get_last_child(struct dom_node *node, + struct dom_node **result) { /* If there is a last child, increase its reference count */ if (node->last_child != NULL) - dom_node_ref(ctx, node->last_child); + dom_node_ref(node->last_child); *result = node->last_child; @@ -284,7 +260,6 @@ dom_exception dom_node_get_last_child(struct dom_ctx *ctx, /** * Retrieve the previous sibling of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the previous sibling of * \param result Pointer to location to receive node's previous sibling * \return DOM_NO_ERR. @@ -293,12 +268,12 @@ dom_exception dom_node_get_last_child(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_previous(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result) +dom_exception dom_node_get_previous(struct dom_node *node, + struct dom_node **result) { /* If there is a previous sibling, increase its reference count */ if (node->previous != NULL) - dom_node_ref(ctx, node->previous); + dom_node_ref(node->previous); *result = node->previous; @@ -308,7 +283,6 @@ dom_exception dom_node_get_previous(struct dom_ctx *ctx, /** * Retrieve the subsequent sibling of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the subsequent sibling of * \param result Pointer to location to receive node's subsequent sibling * \return DOM_NO_ERR. @@ -317,12 +291,12 @@ dom_exception dom_node_get_previous(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_next(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node **result) +dom_exception dom_node_get_next(struct dom_node *node, + struct dom_node **result) { /* If there is a subsequent sibling, increase its reference count */ if (node->next != NULL) - dom_node_ref(ctx, node->next); + dom_node_ref(node->next); *result = node->next; @@ -332,17 +306,15 @@ dom_exception dom_node_get_next(struct dom_ctx *ctx, /** * Retrieve a map of attributes associated with a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the attributes of * \param result Pointer to location to receive attribute map * \return DOM_NO_ERR. * * \todo Work out reference counting semantics of dom_named_node_map */ -dom_exception dom_node_get_attributes(struct dom_ctx *ctx, - struct dom_node *node, struct dom_named_node_map **result) +dom_exception dom_node_get_attributes(struct dom_node *node, + struct dom_named_node_map **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -352,7 +324,6 @@ dom_exception dom_node_get_attributes(struct dom_ctx *ctx, /** * Retrieve the owning document of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the owner of * \param result Pointer to location to receive node's owner * \return DOM_NO_ERR. @@ -361,12 +332,12 @@ dom_exception dom_node_get_attributes(struct dom_ctx *ctx, * the responsibility of the caller to unref the node once it has * finished with it. */ -dom_exception dom_node_get_owner(struct dom_ctx *ctx, - struct dom_node *node, struct dom_document **result) +dom_exception dom_node_get_owner(struct dom_node *node, + struct dom_document **result) { /* If there is an owner, increase its reference count */ if (node->owner != NULL) - dom_node_ref(ctx, (struct dom_node *) node->owner); + dom_node_ref((struct dom_node *) node->owner); *result = node->owner; @@ -376,7 +347,6 @@ dom_exception dom_node_get_owner(struct dom_ctx *ctx, /** * Insert a child into a node * - * \param ctx The context in which the nodes reside * \param node Node to insert into * \param new_child Node to insert * \param ref_child Node to insert before, or NULL to insert as last child @@ -405,12 +375,10 @@ dom_exception dom_node_get_owner(struct dom_ctx *ctx, * ::new_child's reference count will be increased. The caller should unref * it (as they should already have held a reference on the node) */ -dom_exception dom_node_insert_before(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_insert_before(struct dom_node *node, struct dom_node *new_child, struct dom_node *ref_child, struct dom_node **result) { - UNUSED(ctx); UNUSED(node); UNUSED(new_child); UNUSED(ref_child); @@ -422,7 +390,6 @@ dom_exception dom_node_insert_before(struct dom_ctx *ctx, /** * Replace a node's child with a new one * - * \param ctx The context in which the nodes reside * \param node Node whose child to replace * \param new_child Replacement node * \param old_child Child to replace @@ -456,12 +423,10 @@ dom_exception dom_node_insert_before(struct dom_ctx *ctx, * transferred to the caller). The caller should unref ::old_child once it * is finished with it. */ -dom_exception dom_node_replace_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_replace_child(struct dom_node *node, struct dom_node *new_child, struct dom_node *old_child, struct dom_node **result) { - UNUSED(ctx); UNUSED(node); UNUSED(new_child); UNUSED(old_child); @@ -473,7 +438,6 @@ dom_exception dom_node_replace_child(struct dom_ctx *ctx, /** * Remove a child from a node * - * \param ctx The context in which the nodes reside * \param node Node whose child to replace * \param old_child Child to remove * \param result Pointer to location to receive removed node @@ -489,12 +453,10 @@ dom_exception dom_node_replace_child(struct dom_ctx *ctx, * transferred to the caller). The caller should unref ::old_child once it * is finished with it. */ -dom_exception dom_node_remove_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_remove_child(struct dom_node *node, struct dom_node *old_child, struct dom_node **result) { - UNUSED(ctx); UNUSED(node); UNUSED(old_child); UNUSED(result); @@ -505,7 +467,6 @@ dom_exception dom_node_remove_child(struct dom_ctx *ctx, /** * Append a child to the end of a node's child list * - * \param ctx The context in which the nodes reside * \param node Node to insert into * \param new_child Node to append * \param result Pointer to location to receive node being inserted @@ -531,28 +492,23 @@ dom_exception dom_node_remove_child(struct dom_ctx *ctx, * ::new_child's reference count will be increased. The caller should unref * it (as they should already have held a reference on the node) */ -dom_exception dom_node_append_child(struct dom_ctx *ctx, - struct dom_node *node, +dom_exception dom_node_append_child(struct dom_node *node, struct dom_node *new_child, struct dom_node **result) { /* This is just a veneer over insert_before */ - return dom_node_insert_before(ctx, node, new_child, NULL, result); + return dom_node_insert_before(node, new_child, NULL, result); } /** * Determine if a node has any children * - * \param ctx The context in which the node resides * \param node Node to inspect * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_has_children(struct dom_ctx *ctx, - struct dom_node *node, bool *result) +dom_exception dom_node_has_children(struct dom_node *node, bool *result) { - UNUSED(ctx); - *result = node->first_child != NULL; return DOM_NO_ERR; @@ -561,7 +517,6 @@ dom_exception dom_node_has_children(struct dom_ctx *ctx, /** * Clone a DOM node * - * \param ctx The context in which the node resides * \param node The node to clone * \param deep True to deep-clone the node's sub-tree * \param result Pointer to location to receive result @@ -598,11 +553,9 @@ dom_exception dom_node_has_children(struct dom_ctx *ctx, * \todo work out what happens when cloning Document, DocumentType, Entity * and Notation nodes. */ -dom_exception dom_node_clone(struct dom_ctx *ctx, - struct dom_node *node, bool deep, +dom_exception dom_node_clone(struct dom_node *node, bool deep, struct dom_node **result) { - UNUSED(ctx); UNUSED(node); UNUSED(deep); UNUSED(result); @@ -613,7 +566,6 @@ dom_exception dom_node_clone(struct dom_ctx *ctx, /** * Normalize a DOM node * - * \param ctx The context in which the node resides * \param node The node to normalize * \return DOM_NO_ERR. * @@ -621,10 +573,8 @@ dom_exception dom_node_clone(struct dom_ctx *ctx, * including Attr nodes into "normal" form, where only structure separates * Text nodes. */ -dom_exception dom_node_normalize(struct dom_ctx *ctx, - struct dom_node *node) +dom_exception dom_node_normalize(struct dom_node *node) { - UNUSED(ctx); UNUSED(node); return DOM_NOT_SUPPORTED_ERR; @@ -634,18 +584,16 @@ dom_exception dom_node_normalize(struct dom_ctx *ctx, * Test whether the DOM implementation implements a specific feature and * that feature is supported by the node. * - * \param ctx The context in which the node resides * \param node The node to test * \param feature The name of the feature to test * \param version The version number of the feature to test * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_is_supported(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *feature, - struct dom_node *version, bool *result) +dom_exception dom_node_is_supported(struct dom_node *node, + struct dom_string *feature, struct dom_node *version, + bool *result) { - UNUSED(ctx); UNUSED(node); UNUSED(feature); UNUSED(version); @@ -657,7 +605,6 @@ dom_exception dom_node_is_supported(struct dom_ctx *ctx, /** * Retrieve the namespace of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the namespace of * \param result Pointer to location to receive node's namespace * \return DOM_NO_ERR. @@ -666,12 +613,12 @@ dom_exception dom_node_is_supported(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_get_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_namespace(struct dom_node *node, + struct dom_string **result) { /* If there is a namespace, increase its reference count */ if (node->namespace != NULL) - dom_string_ref(ctx, node->namespace); + dom_string_ref(node->namespace); *result = node->namespace; @@ -681,7 +628,6 @@ dom_exception dom_node_get_namespace(struct dom_ctx *ctx, /** * Retrieve the prefix of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the prefix of * \param result Pointer to location to receive node's prefix * \return DOM_NO_ERR. @@ -690,12 +636,12 @@ dom_exception dom_node_get_namespace(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_get_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_prefix(struct dom_node *node, + struct dom_string **result) { /* If there is a prefix, increase its reference count */ if (node->prefix != NULL) - dom_string_ref(ctx, node->prefix); + dom_string_ref(node->prefix); *result = node->prefix; @@ -705,7 +651,6 @@ dom_exception dom_node_get_prefix(struct dom_ctx *ctx, /** * Set the prefix of a DOM node * - * \param ctx The context in which the node resides * \param node The node to set the prefix of * \param prefix Pointer to prefix string * \return DOM_NO_ERR on success, @@ -726,10 +671,9 @@ dom_exception dom_node_get_prefix(struct dom_ctx *ctx, * and the qualifiedName of ::node * is "xmlns". */ -dom_exception dom_node_set_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *prefix) +dom_exception dom_node_set_prefix(struct dom_node *node, + struct dom_string *prefix) { - UNUSED(ctx); UNUSED(node); UNUSED(prefix); @@ -739,7 +683,6 @@ dom_exception dom_node_set_prefix(struct dom_ctx *ctx, /** * Retrieve the local part of a node's qualified name * - * \param ctx The context in which the node resides * \param node The node to retrieve the local name of * \param result Pointer to location to receive local name * \return DOM_NO_ERR. @@ -748,12 +691,12 @@ dom_exception dom_node_set_prefix(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_get_local_name(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_local_name(struct dom_node *node, + struct dom_string **result) { /* If there is a local name, increase its reference count */ if (node->localname != NULL) - dom_string_ref(ctx, node->localname); + dom_string_ref(node->localname); *result = node->localname; @@ -763,16 +706,12 @@ dom_exception dom_node_get_local_name(struct dom_ctx *ctx, /** * Determine if a node has any attributes * - * \param ctx The context in which the node resides * \param node Node to inspect * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_has_attributes(struct dom_ctx *ctx, - struct dom_node *node, bool *result) +dom_exception dom_node_has_attributes(struct dom_node *node, bool *result) { - UNUSED(ctx); - *result = node->attributes != NULL; return DOM_NO_ERR; @@ -781,7 +720,6 @@ dom_exception dom_node_has_attributes(struct dom_ctx *ctx, /** * Retrieve the base URI of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the base URI of * \param result Pointer to location to receive base URI * \return DOM_NO_ERR. @@ -790,10 +728,9 @@ dom_exception dom_node_has_attributes(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_get_base(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_base(struct dom_node *node, + struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -803,7 +740,6 @@ dom_exception dom_node_get_base(struct dom_ctx *ctx, /** * Compare the positions of two nodes in a DOM tree * - * \param ctx The context in which the nodes reside * \param node The reference node * \param other The node to compare * \param result Pointer to location to receive result @@ -813,11 +749,9 @@ dom_exception dom_node_get_base(struct dom_ctx *ctx, * * The result is a bitfield of dom_document_position values. */ -dom_exception dom_node_compare_document_position(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, - uint16_t *result) +dom_exception dom_node_compare_document_position(struct dom_node *node, + struct dom_node *other, uint16_t *result) { - UNUSED(ctx); UNUSED(node); UNUSED(other); UNUSED(result); @@ -828,7 +762,6 @@ dom_exception dom_node_compare_document_position(struct dom_ctx *ctx, /** * Retrieve the text content of a DOM node * - * \param ctx The context in which the node resides * \param node The node to retrieve the text content of * \param result Pointer to location to receive text content * \return DOM_NO_ERR. @@ -840,10 +773,9 @@ dom_exception dom_node_compare_document_position(struct dom_ctx *ctx, * DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in * this implementation; dom_strings are unbounded. */ -dom_exception dom_node_get_text_content(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string **result) +dom_exception dom_node_get_text_content(struct dom_node *node, + struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(result); @@ -853,7 +785,6 @@ dom_exception dom_node_get_text_content(struct dom_ctx *ctx, /** * Set the text content of a DOM node * - * \param ctx The context in which the node resides * \param node The node to set the text content of * \param content New text content for node * \return DOM_NO_ERR on success, @@ -862,10 +793,9 @@ dom_exception dom_node_get_text_content(struct dom_ctx *ctx, * Any child nodes ::node may have are removed and replaced with a single * Text node containing the new content. */ -dom_exception dom_node_set_text_content(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *content) +dom_exception dom_node_set_text_content(struct dom_node *node, + struct dom_string *content) { - UNUSED(ctx); UNUSED(node); UNUSED(content); @@ -875,7 +805,6 @@ dom_exception dom_node_set_text_content(struct dom_ctx *ctx, /** * Determine if two DOM nodes are the same * - * \param ctx The context in which the nodes reside * \param node The node to compare * \param other The node to compare against * \param result Pointer to location to receive result @@ -883,12 +812,9 @@ dom_exception dom_node_set_text_content(struct dom_ctx *ctx, * * This tests if the two nodes reference the same object. */ -dom_exception dom_node_is_same(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, +dom_exception dom_node_is_same(struct dom_node *node, struct dom_node *other, bool *result) { - UNUSED(ctx); - *result = (node == other); return DOM_NO_ERR; @@ -897,7 +823,6 @@ dom_exception dom_node_is_same(struct dom_ctx *ctx, /** * Lookup the prefix associated with the given namespace URI * - * \param ctx The context in which the node resides * \param node The node to start prefix search from * \param namespace The namespace URI * \param result Pointer to location to receive result @@ -907,11 +832,9 @@ dom_exception dom_node_is_same(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_lookup_prefix(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *namespace, - struct dom_string **result) +dom_exception dom_node_lookup_prefix(struct dom_node *node, + struct dom_string *namespace, struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(namespace); UNUSED(result); @@ -922,17 +845,14 @@ dom_exception dom_node_lookup_prefix(struct dom_ctx *ctx, /** * Determine if the specified namespace is the default namespace * - * \param ctx The context in which the node resides * \param node The node to query * \param namespace The namespace URI to test * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_is_default_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *namespace, - bool *result) +dom_exception dom_node_is_default_namespace(struct dom_node *node, + struct dom_string *namespace, bool *result) { - UNUSED(ctx); UNUSED(node); UNUSED(namespace); UNUSED(result); @@ -943,7 +863,6 @@ dom_exception dom_node_is_default_namespace(struct dom_ctx *ctx, /** * Lookup the namespace URI associated with the given prefix * - * \param ctx The context in which the node resides * \param node The node to start namespace search from * \param prefix The prefix to look for, or NULL to find default. * \param result Pointer to location to receive result @@ -953,11 +872,9 @@ dom_exception dom_node_is_default_namespace(struct dom_ctx *ctx, * the responsibility of the caller to unref the string once it has * finished with it. */ -dom_exception dom_node_lookup_namespace(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *prefix, - struct dom_string **result) +dom_exception dom_node_lookup_namespace(struct dom_node *node, + struct dom_string *prefix, struct dom_string **result) { - UNUSED(ctx); UNUSED(node); UNUSED(prefix); UNUSED(result); @@ -968,7 +885,6 @@ dom_exception dom_node_lookup_namespace(struct dom_ctx *ctx, /** * Determine if two DOM nodes are equal * - * \param ctx The context in which the nodes reside * \param node The node to compare * \param other The node to compare against * \param result Pointer to location to receive result @@ -985,11 +901,9 @@ dom_exception dom_node_lookup_namespace(struct dom_ctx *ctx, * + The node entities are equal * + The node notations are equal */ -dom_exception dom_node_is_equal(struct dom_ctx *ctx, - struct dom_node *node, struct dom_node *other, - bool *result) +dom_exception dom_node_is_equal(struct dom_node *node, + struct dom_node *other, bool *result) { - UNUSED(ctx); UNUSED(node); UNUSED(other); UNUSED(result); @@ -1001,18 +915,16 @@ dom_exception dom_node_is_equal(struct dom_ctx *ctx, * Retrieve an object which implements the specialized APIs of the specified * feature and version. * - * \param ctx The context in which the node resides * \param node The node to query * \param feature The requested feature * \param version The version number of the feature * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_get_feature(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *feature, - struct dom_string *version, void **result) +dom_exception dom_node_get_feature(struct dom_node *node, + struct dom_string *feature, struct dom_string *version, + void **result) { - UNUSED(ctx); UNUSED(node); UNUSED(feature); UNUSED(version); @@ -1024,7 +936,6 @@ dom_exception dom_node_get_feature(struct dom_ctx *ctx, /** * Associate an object to a key on this node * - * \param ctx The context in which the node resides * \param node The node to insert object into * \param key The key associated with the object * \param data The object to associate with key, or NULL to remove @@ -1032,12 +943,10 @@ dom_exception dom_node_get_feature(struct dom_ctx *ctx, * \param result Pointer to location to receive previously associated object * \return DOM_NO_ERR. */ -dom_exception dom_node_set_user_data(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *key, - void *data, dom_user_data_handler handler, - void **result) +dom_exception dom_node_set_user_data(struct dom_node *node, + struct dom_string *key, void *data, + dom_user_data_handler handler, void **result) { - UNUSED(ctx); UNUSED(node); UNUSED(key); UNUSED(data); @@ -1050,17 +959,14 @@ dom_exception dom_node_set_user_data(struct dom_ctx *ctx, /** * Retrieves the object associated to a key on this node * - * \param ctx The context in which the node resides * \param node The node to retrieve object from * \param key The key to search for * \param result Pointer to location to receive result * \return DOM_NO_ERR. */ -dom_exception dom_node_get_user_data(struct dom_ctx *ctx, - struct dom_node *node, struct dom_string *key, - void **result) +dom_exception dom_node_get_user_data(struct dom_node *node, + struct dom_string *key, void **result) { - UNUSED(ctx); UNUSED(node); UNUSED(key); UNUSED(result); diff --git a/src/core/node.h b/src/core/node.h index b39ac40..bfd7fa0 100644 --- a/src/core/node.h +++ b/src/core/node.h @@ -52,8 +52,7 @@ struct dom_node { uint32_t refcnt; /**< Reference count */ }; -dom_exception dom_node_create(struct dom_ctx *ctx, - struct dom_document *doc, dom_node_type type, +dom_exception dom_node_create(struct dom_document *doc, dom_node_type type, struct dom_string *name, struct dom_string *value, struct dom_node **node); diff --git a/src/core/string.c b/src/core/string.c index 070af75..a60fa94 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -8,7 +8,6 @@ #include #include -#include #include #include "core/document.h" @@ -26,57 +25,51 @@ struct dom_string { enum { DOM_STRING_PTR, DOM_STRING_CONST_PTR, DOM_STRING_OFFSET - } type; + } type; /**< String type */ union { uint8_t *ptr; const uint8_t *cptr; - struct { - struct dom_document *doc; - uint32_t off; - } offset; - } data; + uint32_t offset; + } data; /**< Type-specific data */ - size_t len; + size_t len; /**< Byte length of string */ - uint32_t refcnt; + struct dom_document *doc; /**< Owning document */ + + uint32_t refcnt; /**< Reference count */ }; /** * Claim a reference on a DOM string * - * \param ctx The context in which the string resides * \param str The string to claim a reference on */ -void dom_string_ref(struct dom_ctx *ctx, struct dom_string *str) +void dom_string_ref(struct dom_string *str) { - UNUSED(ctx); - str->refcnt++; } /** * Release a reference on a DOM string * - * \param ctx The context in which the string resides * \param str The string to release the reference from * * If the reference count reaches zero, any memory claimed by the * string will be released */ -void dom_string_unref(struct dom_ctx *ctx, struct dom_string *str) +void dom_string_unref(struct dom_string *str) { if (--str->refcnt == 0) { if (str->type == DOM_STRING_PTR) - ctx->alloc(str->data.ptr, 0, ctx->pw); + dom_document_alloc(str->doc, str->data.ptr, 0); - ctx->alloc(str, 0, ctx->pw); + dom_document_alloc(str->doc, str, 0); } } /** * Create a DOM string from an offset into the document buffer * - * \param ctx The context in which the string resides * \param doc The document in which the string resides * \param off Offset from start of document buffer * \param len Length, in bytes, of string @@ -86,21 +79,23 @@ void dom_string_unref(struct dom_ctx *ctx, struct dom_string *str) * The returned string will already be referenced, so there is no need * to explicitly reference it. */ -dom_exception dom_string_create_from_off(struct dom_ctx *ctx, - struct dom_document *doc, uint32_t off, size_t len, - struct dom_string **str) +dom_exception dom_string_create_from_off(struct dom_document *doc, + uint32_t off, size_t len, struct dom_string **str) { struct dom_string *ret; - ret = ctx->alloc(NULL, sizeof(struct dom_string), ctx->pw); + ret = dom_document_alloc(doc, NULL, sizeof(struct dom_string)); if (ret == NULL) return DOM_NO_MEM_ERR; ret->type = DOM_STRING_OFFSET; - ret->data.offset.doc = doc; - ret->data.offset.off = off; + + ret->data.offset = off; + ret->len = len; + ret->doc = doc; + ret->refcnt = 1; *str = ret; @@ -111,7 +106,7 @@ dom_exception dom_string_create_from_off(struct dom_ctx *ctx, /** * Create a DOM string from a string of characters * - * \param ctx The context in which the string resides + * \param doc The document in which the string resides * \param ptr Pointer to string of characters * \param len Length, in bytes, of string of characters * \param str Pointer to location to receive pointer to new string @@ -123,18 +118,18 @@ dom_exception dom_string_create_from_off(struct dom_ctx *ctx, * The string of characters passed in will be copied for use by the * returned DOM string. */ -dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, +dom_exception dom_string_create_from_ptr(struct dom_document *doc, const uint8_t *ptr, size_t len, struct dom_string **str) { struct dom_string *ret; - ret = ctx->alloc(NULL, sizeof(struct dom_string), ctx->pw); + ret = dom_document_alloc(doc, NULL, sizeof(struct dom_string)); if (ret == NULL) return DOM_NO_MEM_ERR; - ret->data.ptr = ctx->alloc(NULL, len, ctx->pw); + ret->data.ptr = dom_document_alloc(doc, NULL, len); if (ret->data.ptr == NULL) { - ctx->alloc(ret, 0, ctx->pw); + dom_document_alloc(doc, ret, 0); return DOM_NO_MEM_ERR; } @@ -144,6 +139,8 @@ dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, ret->len = len; + ret->doc = doc; + ret->refcnt = 1; *str = ret; @@ -154,7 +151,7 @@ dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, /** * Create a DOM string from a constant string of characters * - * \param ctx The context in which the string resides + * \param doc The document in which the string resides * \param ptr Pointer to string of characters * \param len Length, in bytes, of string of characters * \param str Pointer to location to receive pointer to new string @@ -166,21 +163,23 @@ dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, * The string of characters passed in will _not_ be copied for use by the * returned DOM string. */ -dom_exception dom_string_create_from_const_ptr(struct dom_ctx *ctx, +dom_exception dom_string_create_from_const_ptr(struct dom_document *doc, const uint8_t *ptr, size_t len, struct dom_string **str) { struct dom_string *ret; - ret = ctx->alloc(NULL, sizeof(struct dom_string), ctx->pw); + ret = dom_document_alloc(doc, NULL, sizeof(struct dom_string)); if (ret == NULL) return DOM_NO_MEM_ERR; - ret->data.cptr = ptr; - ret->type = DOM_STRING_CONST_PTR; + ret->data.cptr = ptr; + ret->len = len; + ret->doc = doc; + ret->refcnt = 1; *str = ret; @@ -191,7 +190,6 @@ dom_exception dom_string_create_from_const_ptr(struct dom_ctx *ctx, /** * Get a pointer to the string of characters within a DOM string * - * \param ctx The context in which the string resides * \param str Pointer to DOM string to retrieve pointer from * \param data Pointer to location to receive data * \param len Pointer to location to receive byte length of data @@ -200,8 +198,8 @@ dom_exception dom_string_create_from_const_ptr(struct dom_ctx *ctx, * The caller must have previously claimed a reference on the DOM string. * The returned pointer must not be freed. */ -dom_exception dom_string_get_data(struct dom_ctx *ctx, - struct dom_string *str, const uint8_t **data, size_t *len) +dom_exception dom_string_get_data(struct dom_string *str, + const uint8_t **data, size_t *len) { switch (str->type) { case DOM_STRING_PTR: @@ -211,8 +209,7 @@ dom_exception dom_string_get_data(struct dom_ctx *ctx, *data = str->data.cptr; break; case DOM_STRING_OFFSET: - *data = dom_document_get_base(ctx, str->data.offset.doc) + - str->data.offset.off; + *data = dom_document_get_base(str->doc) + str->data.offset; break; } -- cgit v1.2.3