From 5da747ff564cdcfeff90c5f5cfcfac03bc48332b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 6 Jul 2007 14:32:44 +0000 Subject: Import DOM library. This is mainly stub functions atm (and is missing a number of key interfaces). svn path=/trunk/dom/; revision=3384 --- include/dom/core/attr.h | 37 +++++++++ include/dom/core/document.h | 105 ++++++++++++++++++++++++++ include/dom/core/exceptions.h | 34 +++++++++ include/dom/core/node.h | 170 ++++++++++++++++++++++++++++++++++++++++++ include/dom/core/string.h | 40 ++++++++++ include/dom/ctx.h | 26 +++++++ 6 files changed, 412 insertions(+) create mode 100644 include/dom/core/attr.h create mode 100644 include/dom/core/document.h create mode 100644 include/dom/core/exceptions.h create mode 100644 include/dom/core/node.h create mode 100644 include/dom/core/string.h create mode 100644 include/dom/ctx.h (limited to 'include/dom') diff --git a/include/dom/core/attr.h b/include/dom/core/attr.h new file mode 100644 index 0000000..782513e --- /dev/null +++ b/include/dom/core/attr.h @@ -0,0 +1,37 @@ +/* + * 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_core_attr_h_ +#define dom_core_attr_h_ + +#include + +#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); + +#endif diff --git a/include/dom/core/document.h b/include/dom/core/document.h new file mode 100644 index 0000000..347fdc4 --- /dev/null +++ b/include/dom/core/document.h @@ -0,0 +1,105 @@ +/* + * 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_core_document_h_ +#define dom_core_document_h_ + +#include + +#include + +struct dom_attr; +struct dom_configuration; +struct dom_ctx; +struct dom_document; +struct dom_document_type; +struct dom_element; +struct dom_implementation; +struct dom_node; +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, + 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, + 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, + struct dom_node **result); +dom_exception dom_document_create_attribute(struct dom_ctx *ctx, + struct dom_document *doc, struct dom_string *name, + 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, + 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, + 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, + 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, + struct dom_string *namespace, struct dom_string *qname, + struct dom_node **result); + +#endif diff --git a/include/dom/core/exceptions.h b/include/dom/core/exceptions.h new file mode 100644 index 0000000..d735013 --- /dev/null +++ b/include/dom/core/exceptions.h @@ -0,0 +1,34 @@ +/* + * 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_errors_h_ +#define dom_errors_h_ + +/* The DOM spec says that this is actually an unsigned short */ +typedef enum { + DOM_NO_ERR = 0, + DOM_INDEX_SIZE_ERR = 1, + DOM_DOMSTRING_SIZE_ERR = 2, + DOM_HIERARCHY_REQUEST_ERR = 3, + DOM_WRONG_DOCUMENT_ERR = 4, + DOM_INVALID_CHARACTER_ERR = 5, + DOM_NO_DATA_ALLOWED_ERR = 6, + DOM_NO_MODIFICATION_ALLOWED_ERR = 7, + DOM_NOT_FOUND_ERR = 8, + DOM_NOT_SUPPORTED_ERR = 9, + DOM_INUSE_ATTRIBUTE_ERR = 10, + DOM_INVALID_STATE_ERR = 11, + DOM_SYNTAX_ERR = 12, + DOM_INVALID_MODIFICATION_ERR = 13, + DOM_NAMESPACE_ERR = 14, + DOM_INVALID_ACCESS_ERR = 15, + DOM_VALIDATION_ERR = 16, + DOM_TYPE_MISMATCH_ERR = 17, + DOM_NO_MEM_ERR = (1<<16) /* our own internal error */ +} dom_exception; + +#endif diff --git a/include/dom/core/node.h b/include/dom/core/node.h new file mode 100644 index 0000000..e37d99b --- /dev/null +++ b/include/dom/core/node.h @@ -0,0 +1,170 @@ +/* + * 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_core_node_h_ +#define dom_core_node_h_ + +#include +#include + +#include + +struct dom_ctx; +struct dom_document; +struct dom_node; +struct dom_node_list; +struct dom_named_node_map; +struct dom_string; + +/** + * Bits defining position of a node in a document relative to some other node + */ +typedef enum { + DOM_DOCUMENT_POSITION_DISCONNECTED = 0x01, + DOM_DOCUMENT_POSITION_PRECEDING = 0x02, + DOM_DOCUMENT_POSITION_FOLLOWING = 0x04, + DOM_DOCUMENT_POSITION_CONTAINS = 0x08, + DOM_DOCUMENT_POSITION_CONTAINED_BY = 0x10, + DOM_DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20 +} dom_document_position; + +/** + * Type of node operation being notified to user_data_handler + */ +typedef enum { + DOM_NODE_CLONED = 1, + DOM_NODE_IMPORTED = 2, + DOM_NODE_DELETED = 3, + DOM_NODE_RENAMED = 4, + DOM_NODE_ADOPTED = 5 +} dom_node_operation; + +/** + * Type of handler function for user data registered on a DOM node + */ +typedef void (*dom_user_data_handler)(dom_node_operation operation, + struct dom_string *key, void *data, struct dom_node *src, + struct dom_node *dst); + +/** + * Type of a DOM node + */ +typedef enum { + DOM_ELEMENT_NODE = 1, + DOM_ATTRIBUTE_NODE = 2, + DOM_TEXT_NODE = 3, + DOM_CDATA_SECTION_NODE = 4, + DOM_ENTITY_REFERENCE_NODE = 5, + DOM_ENTITY_NODE = 6, + DOM_PROCESSING_INSTRUCTION_NODE = 7, + DOM_COMMENT_NODE = 8, + DOM_DOCUMENT_NODE = 9, + DOM_DOCUMENT_TYPE_NODE = 10, + DOM_DOCUMENT_FRAGMENT_NODE = 11, + DOM_NOTATION_NODE = 12 +} 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); + +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, + 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, + 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, + struct dom_node *old_child, + struct dom_node **result); +dom_exception dom_node_append_child(struct dom_ctx *ctx, + 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, + 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, + bool *result); +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_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, + struct dom_string **result); +dom_exception dom_node_is_equal(struct dom_ctx *ctx, + 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, + void **result); + +#endif diff --git a/include/dom/core/string.h b/include/dom/core/string.h new file mode 100644 index 0000000..f79eaa7 --- /dev/null +++ b/include/dom/core/string.h @@ -0,0 +1,40 @@ +/* + * 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_string_h_ +#define dom_string_h_ + +#include +#include + +#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); +/* Release a reference on a DOM string */ +void dom_string_unref(struct dom_ctx *ctx, 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); +/* Create a DOM string from a string of characters */ +dom_exception dom_string_create_from_ptr(struct dom_ctx *ctx, + 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, + 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); + +#endif diff --git a/include/dom/ctx.h b/include/dom/ctx.h new file mode 100644 index 0000000..f69ec65 --- /dev/null +++ b/include/dom/ctx.h @@ -0,0 +1,26 @@ +/* + * 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 -- cgit v1.2.3