Esempio n. 1
0
bool _get_next_domnodelist(dom_nodelist *list, unsigned int *iterator, dom_node **ret)
{
	dom_exception err;
	unsigned long len;

	err = dom_nodelist_get_length(list, &len);
	if (err != DOM_NO_ERR)
		return false;

	if (*iterator >= len)
		return false;

	err = dom_nodelist_item(list, (*iterator), ret);
	if (err != DOM_NO_ERR)
		return false;
	
	(*iterator)++;
	return true;
}
Esempio n. 2
0
/**
 * Extract an imagemap from html source
 *
 * \param node  XML node containing map
 * \param c     Content containing document
 * \param entry List of map entries
 * \param tname The sub-tags to consider on this pass
 * \return false on memory exhaustion, true otherwise
 */
static bool
imagemap_extract_map_entries(dom_node *node, html_content *c,
			     struct mapentry **entry, dom_string *tname)
{
	dom_nodelist *nlist;
	dom_exception exc;
	unsigned long ent;
	uint32_t tag_count;

	exc = dom_element_get_elements_by_tag_name(node, tname, &nlist);
	if (exc != DOM_NO_ERR) {
		return false;
	}

	exc = dom_nodelist_get_length(nlist, &tag_count);
	if (exc != DOM_NO_ERR) {
		dom_nodelist_unref(nlist);
		return false;
	}

	for (ent = 0; ent < tag_count; ++ent) {
		dom_node *subnode;

		exc = dom_nodelist_item(nlist, ent, &subnode);
		if (exc != DOM_NO_ERR) {
			dom_nodelist_unref(nlist);
			return false;
		}
		if (imagemap_addtolist(c, subnode, c->base_url,
				       entry, tname) == false) {
			dom_node_unref(subnode);
			dom_nodelist_unref(nlist);
			return false;
		}
		dom_node_unref(subnode);
	}

	dom_nodelist_unref(nlist);

	return true;
}
Esempio n. 3
0
/**
 * Extract all imagemaps from a document tree
 *
 * \param c The content to extract imagemaps from.
 * \return false on memory exhaustion, true otherwise
 */
nserror
imagemap_extract(html_content *c)
{
	dom_nodelist *nlist;
	dom_exception exc;
	unsigned long mapnr;
	uint32_t maybe_maps;
	nserror ret = NSERROR_OK;

	exc = dom_document_get_elements_by_tag_name(c->document,
						    corestring_dom_map,
						    &nlist);
	if (exc != DOM_NO_ERR) {
		return NSERROR_DOM;
	}

	exc = dom_nodelist_get_length(nlist, &maybe_maps);
	if (exc != DOM_NO_ERR) {
		ret = NSERROR_DOM;
		goto out_nlist;
	}

	for (mapnr = 0; mapnr < maybe_maps; ++mapnr) {
		dom_node *node;
		dom_string *name;
		exc = dom_nodelist_item(nlist, mapnr, &node);
		if (exc != DOM_NO_ERR) {
			ret = NSERROR_DOM;
			goto out_nlist;
		}

		exc = dom_element_get_attribute(node, corestring_dom_id,
						&name);
		if (exc != DOM_NO_ERR) {
			dom_node_unref(node);
			ret = NSERROR_DOM;
			goto out_nlist;
		}

		if (name == NULL) {
			exc = dom_element_get_attribute(node,
							corestring_dom_name,
							&name);
			if (exc != DOM_NO_ERR) {
				dom_node_unref(node);
				ret = NSERROR_DOM;
				goto out_nlist;
			}
		}

		if (name != NULL) {
			struct mapentry *entry = NULL;
			if (imagemap_extract_map(node, c, &entry) == false) {
				if (entry != NULL) {
					imagemap_freelist(entry);
				}

				dom_string_unref(name);
				dom_node_unref(node);
				ret = NSERROR_NOMEM; /** @todo check this */
				goto out_nlist;
			}

			/* imagemap_extract_map may not extract anything,
			 * so entry can still be NULL here. This isn't an
			 * error as it just means that we've encountered
			 * an incorrectly defined <map>...</map> block
			 */
			if ((entry != NULL) &&
			    (imagemap_add(c, name, entry) == false)) {
				imagemap_freelist(entry);

				dom_string_unref(name);
				dom_node_unref(node);
				ret = NSERROR_NOMEM; /** @todo check this */
				goto out_nlist;
			}
		}

		dom_string_unref(name);
		dom_node_unref(node);
	}

out_nlist:

	dom_nodelist_unref(nlist);

	return ret;
}