2005-09-15 09:58:31 -04:00
|
|
|
/* The DOM node handling */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
2005-12-28 08:05:14 -05:00
|
|
|
#include "dom/node.h"
|
2005-12-28 14:45:55 -05:00
|
|
|
#include "dom/string.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "util/hash.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
|
|
|
|
|
2005-12-07 20:59:40 -05:00
|
|
|
static void done_dom_node_data(struct dom_node *node);
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* Node lists */
|
|
|
|
|
|
|
|
#define DOM_NODE_LIST_GRANULARITY 0x7
|
|
|
|
|
|
|
|
#define DOM_NODE_LIST_BLOCK_SIZE \
|
|
|
|
(ALIGN_MEMORY_SIZE(1, DOM_NODE_LIST_GRANULARITY) * sizeof(struct dom_node *))
|
|
|
|
|
|
|
|
/* The node list struct has one node pointer */
|
|
|
|
#define DOM_NODE_LIST_SIZE(size) \
|
|
|
|
((size - 1) * sizeof(struct dom_node *) + sizeof(struct dom_node_list))
|
|
|
|
|
|
|
|
static inline struct dom_node_list *
|
|
|
|
realloc_dom_node_list(struct dom_node_list **oldlist)
|
|
|
|
{
|
|
|
|
struct dom_node_list *list = *oldlist;
|
|
|
|
size_t size = list ? list->size : 0;
|
|
|
|
size_t oldsize = ALIGN_MEMORY_SIZE(size, DOM_NODE_LIST_GRANULARITY);
|
|
|
|
size_t newsize = ALIGN_MEMORY_SIZE(size + 1, DOM_NODE_LIST_GRANULARITY);
|
|
|
|
|
|
|
|
if (newsize <= oldsize) return list;
|
|
|
|
|
|
|
|
list = mem_realloc(list, DOM_NODE_LIST_SIZE(newsize));
|
|
|
|
if (!list) return NULL;
|
|
|
|
|
|
|
|
/* If this is the first reallocation clear the size */
|
|
|
|
if (!size) list->size = 0;
|
|
|
|
|
|
|
|
/* Clear the new block of entries */
|
|
|
|
memset(&list->entries[oldsize], 0, DOM_NODE_LIST_BLOCK_SIZE);
|
|
|
|
|
|
|
|
*oldlist = list;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dom_node_list *
|
|
|
|
add_to_dom_node_list(struct dom_node_list **list_ptr,
|
|
|
|
struct dom_node *node, int position)
|
|
|
|
{
|
|
|
|
struct dom_node_list *list;
|
|
|
|
|
|
|
|
assert(list_ptr && node);
|
|
|
|
|
|
|
|
list = realloc_dom_node_list(list_ptr);
|
|
|
|
if (!list) return NULL;
|
|
|
|
|
|
|
|
assertm(position < 0 || position <= list->size,
|
|
|
|
"position out of bound %d > %zu", position, list->size);
|
|
|
|
|
|
|
|
if (position < 0) {
|
|
|
|
position = list->size;
|
|
|
|
|
|
|
|
} else if (position < list->size) {
|
|
|
|
/* Make room if we have to add the node in the middle of the list */
|
|
|
|
struct dom_node **offset = &list->entries[position];
|
|
|
|
size_t size = (list->size - position) * sizeof(*offset);
|
|
|
|
|
|
|
|
memmove(offset + 1, offset, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
list->size++;
|
|
|
|
list->entries[position] = node;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2005-12-07 20:59:40 -05:00
|
|
|
static void
|
|
|
|
del_from_dom_node_list(struct dom_node_list *list, struct dom_node *node)
|
|
|
|
{
|
|
|
|
struct dom_node *entry;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!list) return;
|
|
|
|
|
2005-12-18 20:57:00 -05:00
|
|
|
foreach_dom_node (list, entry, i) {
|
2005-12-07 20:59:40 -05:00
|
|
|
size_t successors;
|
|
|
|
|
|
|
|
if (entry != node) continue;
|
|
|
|
|
|
|
|
successors = list->size - (i + 1);
|
|
|
|
if (successors)
|
|
|
|
memmove(&list->entries[i], &list->entries[i+1],
|
|
|
|
sizeof(*list->entries) * successors);
|
|
|
|
list->size--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
void
|
|
|
|
done_dom_node_list(struct dom_node_list *list)
|
|
|
|
{
|
|
|
|
struct dom_node *node;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(list);
|
|
|
|
|
2005-12-18 20:57:00 -05:00
|
|
|
foreach_dom_node (list, node, i) {
|
2005-12-07 20:59:40 -05:00
|
|
|
/* Avoid that the node start messing with the node list. */
|
|
|
|
done_dom_node_data(node);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mem_free(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Node map */
|
|
|
|
|
|
|
|
struct dom_node_search {
|
|
|
|
struct dom_node *key;
|
|
|
|
unsigned int from, pos, to;
|
|
|
|
};
|
|
|
|
|
2005-12-22 17:29:07 -05:00
|
|
|
#define INIT_DOM_NODE_SEARCH(key, list) \
|
|
|
|
{ (key), -1, 0, (list)->size, }
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-22 17:37:59 -05:00
|
|
|
int
|
|
|
|
dom_node_casecmp(struct dom_node *node1, struct dom_node *node2)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2005-12-22 17:35:17 -05:00
|
|
|
if (node1->type == node2->type) {
|
|
|
|
switch (node1->type) {
|
2005-09-15 09:58:31 -04:00
|
|
|
case DOM_NODE_ELEMENT:
|
2005-12-22 17:35:17 -05:00
|
|
|
if (node1->data.element.type && node2->data.element.type)
|
|
|
|
return node1->data.element.type - node2->data.element.type;
|
2005-12-15 16:02:02 -05:00
|
|
|
break;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
case DOM_NODE_ATTRIBUTE:
|
2005-12-22 17:35:17 -05:00
|
|
|
if (node1->data.attribute.type && node2->data.attribute.type)
|
|
|
|
return node1->data.attribute.type - node2->data.attribute.type;
|
2005-12-15 16:02:02 -05:00
|
|
|
break;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-22 17:35:17 -05:00
|
|
|
return dom_string_casecmp(&node1->string, &node2->string);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
get_bsearch_position(struct dom_node_list *list, int from, int to)
|
|
|
|
{
|
|
|
|
int pos = from + ((to - from) / 2);
|
|
|
|
|
|
|
|
assertm(0 <= pos && pos < list->size, "pos %d", pos);
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define has_bsearch_node(from, to) ((from) + 1 < (to))
|
|
|
|
|
|
|
|
static inline struct dom_node *
|
|
|
|
dom_node_list_bsearch(struct dom_node_search *search, struct dom_node_list *list)
|
|
|
|
{
|
|
|
|
assert(has_bsearch_node(search->from, search->to));
|
|
|
|
|
|
|
|
do {
|
|
|
|
int pos = get_bsearch_position(list, search->from, search->to);
|
|
|
|
struct dom_node *node = list->entries[pos];
|
2005-12-22 17:37:59 -05:00
|
|
|
int difference = dom_node_casecmp(search->key, node);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
search->pos = pos;
|
|
|
|
|
|
|
|
if (!difference) return node;
|
|
|
|
|
|
|
|
if (difference < 0) {
|
|
|
|
search->to = search->pos;
|
|
|
|
} else {
|
|
|
|
search->from = search->pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (has_bsearch_node(search->from, search->to));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-30 00:02:02 -05:00
|
|
|
int
|
|
|
|
get_dom_node_map_index(struct dom_node_list *list, struct dom_node *node)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2005-12-22 17:29:07 -05:00
|
|
|
struct dom_node_search search = INIT_DOM_NODE_SEARCH(node, list);
|
2005-09-15 09:58:31 -04:00
|
|
|
struct dom_node *match = dom_node_list_bsearch(&search, list);
|
|
|
|
|
|
|
|
return match ? search.pos : search.to;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dom_node *
|
|
|
|
get_dom_node_map_entry(struct dom_node_list *list, enum dom_node_type type,
|
2005-12-10 13:21:12 -05:00
|
|
|
uint16_t subtype, struct dom_string *name)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2006-01-27 22:09:31 -05:00
|
|
|
struct dom_node node = { type, 0, INIT_DOM_STRING(name->string, name->length) };
|
2005-12-22 17:29:07 -05:00
|
|
|
struct dom_node_search search = INIT_DOM_NODE_SEARCH(&node, list);
|
|
|
|
|
|
|
|
if (subtype) {
|
|
|
|
/* Set the subtype */
|
|
|
|
switch (type) {
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
node.data.element.type = subtype;
|
|
|
|
break;
|
|
|
|
case DOM_NODE_ATTRIBUTE:
|
|
|
|
node.data.attribute.type = subtype;
|
|
|
|
break;
|
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
node.data.proc_instruction.type = subtype;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return dom_node_list_bsearch(&search, list);
|
|
|
|
}
|
|
|
|
|
2006-01-15 23:10:22 -05:00
|
|
|
static int
|
|
|
|
get_dom_node_list_pos(struct dom_node_list *list, struct dom_node *node)
|
2005-12-24 21:46:01 -05:00
|
|
|
{
|
|
|
|
struct dom_node *entry;
|
|
|
|
int i;
|
|
|
|
|
2006-01-15 23:10:22 -05:00
|
|
|
assert(list);
|
2005-12-24 21:46:01 -05:00
|
|
|
|
2006-01-15 23:10:22 -05:00
|
|
|
foreach_dom_node (list, entry, i) {
|
2005-12-24 21:46:01 -05:00
|
|
|
if (entry == node)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-01-15 23:10:22 -05:00
|
|
|
int
|
|
|
|
get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
|
|
|
|
{
|
|
|
|
struct dom_node_list **list = get_dom_node_list(parent, node);
|
|
|
|
|
|
|
|
return list ? get_dom_node_list_pos(*list, node) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dom_node *
|
|
|
|
get_dom_node_prev(struct dom_node *node)
|
|
|
|
{
|
|
|
|
struct dom_node_list **list;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
assert(node->parent);
|
|
|
|
|
|
|
|
list = get_dom_node_list(node->parent, node);
|
|
|
|
if (!list) return NULL;
|
|
|
|
|
|
|
|
index = get_dom_node_list_pos(*list, node);
|
|
|
|
if (index > 0)
|
|
|
|
return (*list)->entries[index - 1];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-30 00:03:36 -05:00
|
|
|
struct dom_node *
|
|
|
|
get_dom_node_next(struct dom_node *node)
|
|
|
|
{
|
|
|
|
struct dom_node_list **list;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
assert(node->parent);
|
|
|
|
|
|
|
|
list = get_dom_node_list(node->parent, node);
|
|
|
|
if (!list) return NULL;
|
|
|
|
|
|
|
|
index = get_dom_node_list_pos(*list, node);
|
|
|
|
if (index + 1 < (*list)->size)
|
|
|
|
return (*list)->entries[index + 1];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-16 01:11:02 -05:00
|
|
|
struct dom_node *
|
|
|
|
get_dom_node_child(struct dom_node *parent, enum dom_node_type type,
|
|
|
|
int16_t subtype)
|
|
|
|
{
|
|
|
|
struct dom_node_list **list;
|
|
|
|
struct dom_node *node;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
list = get_dom_node_list_by_type(parent, type);
|
|
|
|
if (!list) return NULL;
|
|
|
|
|
|
|
|
foreach_dom_node (*list, node, index) {
|
|
|
|
if (node->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!subtype) return node;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
if (node->data.element.type == subtype)
|
|
|
|
return node;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_ATTRIBUTE:
|
|
|
|
if (node->data.attribute.type == subtype)
|
|
|
|
return node;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
if (node->data.attribute.type == subtype)
|
|
|
|
return node;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* Nodes */
|
|
|
|
|
|
|
|
struct dom_node *
|
2006-12-11 15:21:30 -05:00
|
|
|
init_dom_node_at(
|
|
|
|
#ifdef DEBUG_MEMLEAK
|
|
|
|
unsigned char *file, int line,
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
struct dom_node *parent, enum dom_node_type type,
|
2006-01-27 22:48:12 -05:00
|
|
|
struct dom_string *string, int allocated)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_MEMLEAK
|
|
|
|
struct dom_node *node = debug_mem_calloc(file, line, 1, sizeof(*node));
|
|
|
|
#else
|
|
|
|
struct dom_node *node = mem_calloc(1, sizeof(*node));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!node) return NULL;
|
|
|
|
|
|
|
|
node->type = type;
|
2005-12-07 19:35:48 -05:00
|
|
|
node->parent = parent;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-01-30 00:02:02 -05:00
|
|
|
/* Make it possible to add a node to a parent without allocating the
|
|
|
|
* strings. */
|
|
|
|
if (allocated >= 0) {
|
|
|
|
node->allocated = !!allocated;
|
|
|
|
} else if (parent) {
|
|
|
|
node->allocated = parent->allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->allocated) {
|
|
|
|
if (!init_dom_string(&node->string, string->string, string->length)) {
|
|
|
|
done_dom_node(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
copy_dom_string(&node->string, string);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
if (parent) {
|
|
|
|
struct dom_node_list **list = get_dom_node_list(parent, node);
|
|
|
|
int sort = (type == DOM_NODE_ATTRIBUTE);
|
|
|
|
int index;
|
|
|
|
|
2007-03-11 06:22:02 -04:00
|
|
|
assertm(list != NULL, "Adding node %d to bad parent %d",
|
2005-12-13 14:08:58 -05:00
|
|
|
node->type, parent->type);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
index = *list && (*list)->size > 0 && sort
|
|
|
|
? get_dom_node_map_index(*list, node) : -1;
|
|
|
|
|
|
|
|
if (!add_to_dom_node_list(list, node, index)) {
|
|
|
|
done_dom_node(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-12-07 20:59:40 -05:00
|
|
|
done_dom_node_data(struct dom_node *node)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
union dom_node_data *data;
|
|
|
|
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
data = &node->data;
|
|
|
|
|
|
|
|
switch (node->type) {
|
2005-12-07 20:32:23 -05:00
|
|
|
case DOM_NODE_ATTRIBUTE:
|
2006-01-27 22:48:12 -05:00
|
|
|
if (node->allocated)
|
2006-01-27 22:09:31 -05:00
|
|
|
done_dom_string(&data->attribute.value);
|
2005-12-07 20:32:23 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_DOCUMENT:
|
|
|
|
if (data->document.children)
|
|
|
|
done_dom_node_list(data->document.children);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
if (data->element.children)
|
|
|
|
done_dom_node_list(data->element.children);
|
|
|
|
|
|
|
|
if (data->element.map)
|
|
|
|
done_dom_node_list(data->element.map);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
if (data->proc_instruction.map)
|
|
|
|
done_dom_node_list(data->proc_instruction.map);
|
2006-01-27 22:48:12 -05:00
|
|
|
if (node->allocated)
|
2006-01-27 22:09:31 -05:00
|
|
|
done_dom_string(&data->proc_instruction.instruction);
|
2005-12-07 20:32:23 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
2006-01-27 22:48:12 -05:00
|
|
|
if (node->allocated)
|
|
|
|
done_dom_string(&node->string);
|
2005-09-15 09:58:31 -04:00
|
|
|
mem_free(node);
|
|
|
|
}
|
|
|
|
|
2005-12-07 20:59:40 -05:00
|
|
|
void
|
|
|
|
done_dom_node(struct dom_node *node)
|
|
|
|
{
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
if (node->parent) {
|
|
|
|
struct dom_node *parent = node->parent;
|
|
|
|
union dom_node_data *data = &parent->data;
|
|
|
|
|
|
|
|
switch (parent->type) {
|
|
|
|
case DOM_NODE_DOCUMENT:
|
|
|
|
del_from_dom_node_list(data->document.children, node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
del_from_dom_node_list(data->element.children, node);
|
|
|
|
del_from_dom_node_list(data->element.map, node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
del_from_dom_node_list(data->proc_instruction.map, node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-01 18:15:20 -05:00
|
|
|
|
2005-12-07 20:59:40 -05:00
|
|
|
done_dom_node_data(node);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#define set_node_name(name, namelen, str) \
|
|
|
|
do { (name) = (str); (namelen) = sizeof(str) - 1; } while (0)
|
|
|
|
|
2005-12-10 14:03:43 -05:00
|
|
|
struct dom_string *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_dom_node_name(struct dom_node *node)
|
|
|
|
{
|
2006-01-28 16:55:15 -05:00
|
|
|
static struct dom_string cdata_section_str = STATIC_DOM_STRING("#cdata-section");
|
|
|
|
static struct dom_string comment_str = STATIC_DOM_STRING("#comment");
|
|
|
|
static struct dom_string document_str = STATIC_DOM_STRING("#document");
|
|
|
|
static struct dom_string document_fragment_str = STATIC_DOM_STRING("#document-fragment");
|
|
|
|
static struct dom_string text_str = STATIC_DOM_STRING("#text");
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
switch (node->type) {
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_CDATA_SECTION:
|
|
|
|
return &cdata_section_str;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_COMMENT:
|
|
|
|
return &comment_str;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_DOCUMENT:
|
|
|
|
return &document_str;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_DOCUMENT_FRAGMENT:
|
|
|
|
return &document_fragment_str;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_TEXT:
|
|
|
|
return &text_str;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 14:05:01 -05:00
|
|
|
case DOM_NODE_ATTRIBUTE:
|
|
|
|
case DOM_NODE_DOCUMENT_TYPE:
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
case DOM_NODE_ENTITY:
|
|
|
|
case DOM_NODE_ENTITY_REFERENCE:
|
|
|
|
case DOM_NODE_NOTATION:
|
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
default:
|
|
|
|
return &node->string;
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-10 15:37:47 -05:00
|
|
|
struct dom_string *
|
|
|
|
get_dom_node_value(struct dom_node *node)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
assert(node);
|
|
|
|
|
|
|
|
switch (node->type) {
|
2005-12-10 15:50:40 -05:00
|
|
|
case DOM_NODE_ATTRIBUTE:
|
|
|
|
return &node->data.attribute.value;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 15:50:40 -05:00
|
|
|
case DOM_NODE_PROCESSING_INSTRUCTION:
|
|
|
|
return &node->data.proc_instruction.instruction;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 15:50:40 -05:00
|
|
|
case DOM_NODE_CDATA_SECTION:
|
|
|
|
case DOM_NODE_COMMENT:
|
|
|
|
case DOM_NODE_TEXT:
|
|
|
|
return &node->string;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-10 15:50:40 -05:00
|
|
|
case DOM_NODE_ENTITY_REFERENCE:
|
|
|
|
case DOM_NODE_NOTATION:
|
|
|
|
case DOM_NODE_DOCUMENT:
|
|
|
|
case DOM_NODE_DOCUMENT_FRAGMENT:
|
|
|
|
case DOM_NODE_DOCUMENT_TYPE:
|
|
|
|
case DOM_NODE_ELEMENT:
|
|
|
|
case DOM_NODE_ENTITY:
|
|
|
|
default:
|
|
|
|
return NULL;
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-10 13:28:37 -05:00
|
|
|
struct dom_string *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_dom_node_type_name(enum dom_node_type type)
|
|
|
|
{
|
2005-12-10 13:28:37 -05:00
|
|
|
static struct dom_string dom_node_type_names[DOM_NODES] = {
|
|
|
|
INIT_DOM_STRING(NULL, 0),
|
2006-01-28 16:55:15 -05:00
|
|
|
/* DOM_NODE_ELEMENT */ STATIC_DOM_STRING("element"),
|
|
|
|
/* DOM_NODE_ATTRIBUTE */ STATIC_DOM_STRING("attribute"),
|
|
|
|
/* DOM_NODE_TEXT */ STATIC_DOM_STRING("text"),
|
|
|
|
/* DOM_NODE_CDATA_SECTION */ STATIC_DOM_STRING("cdata-section"),
|
|
|
|
/* DOM_NODE_ENTITY_REFERENCE */ STATIC_DOM_STRING("entity-reference"),
|
|
|
|
/* DOM_NODE_ENTITY */ STATIC_DOM_STRING("entity"),
|
|
|
|
/* DOM_NODE_PROCESSING_INSTRUCTION */ STATIC_DOM_STRING("proc-instruction"),
|
|
|
|
/* DOM_NODE_COMMENT */ STATIC_DOM_STRING("comment"),
|
|
|
|
/* DOM_NODE_DOCUMENT */ STATIC_DOM_STRING("document"),
|
|
|
|
/* DOM_NODE_DOCUMENT_TYPE */ STATIC_DOM_STRING("document-type"),
|
|
|
|
/* DOM_NODE_DOCUMENT_FRAGMENT */ STATIC_DOM_STRING("document-fragment"),
|
|
|
|
/* DOM_NODE_NOTATION */ STATIC_DOM_STRING("notation"),
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
assert(type < DOM_NODES);
|
|
|
|
|
2005-12-10 13:28:37 -05:00
|
|
|
return &dom_node_type_names[type];
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|