/** * Destroy hashtable of imagemaps * * \param c The containing content */ void imagemap_destroy(html_content *c) { unsigned int i; assert(c != NULL); /* no imagemaps -> return */ if (c->imagemaps == NULL) return; for (i = 0; i != HASH_SIZE; i++) { struct imagemap *map, *next; map = c->imagemaps[i]; while (map != NULL) { next = map->next; imagemap_freelist(map->list); free(map->key); free(map); map = next; } } free(c->imagemaps); }
/** * 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; }