From 898b01e72163a53aac3a93bda5181b5897299cb1 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 3 Oct 2011 20:28:29 +0000 Subject: More conversion to nsurl. (box->href, object params, imagemaps, (i)frames) svn path=/trunk/netsurf/; revision=12933 --- desktop/frames.c | 5 ++- render/box.c | 11 ++++-- render/box.h | 12 +++--- render/box_construct.c | 96 ++++++++++++++++++++++------------------------- render/html.c | 7 ++-- render/html.h | 4 +- render/html_interaction.c | 16 ++++---- render/imagemap.c | 28 +++++++------- render/imagemap.h | 4 +- utils/nsurl.c | 6 +++ 10 files changed, 100 insertions(+), 89 deletions(-) diff --git a/desktop/frames.c b/desktop/frames.c index 7ff7c00bc..412741181 100644 --- a/desktop/frames.c +++ b/desktop/frames.c @@ -242,7 +242,8 @@ void browser_window_create_iframes(struct browser_window *bw, window = &(bw->iframes[index++]); if (cur->url) { /* fetch iframe's content */ - browser_window_go_unverifiable(window, cur->url, + browser_window_go_unverifiable(window, + nsurl_access(cur->url), nsurl_access(content_get_url( bw->current_content)), false, bw->current_content); @@ -376,7 +377,7 @@ void browser_window_create_frameset(struct browser_window *bw, if (frame->url) { browser_window_go_unverifiable(window, - frame->url, + nsurl_access(frame->url), nsurl_access(content_get_url( parent)), true, diff --git a/render/box.c b/render/box.c index 00ba0852d..e26c2f565 100644 --- a/render/box.c +++ b/render/box.c @@ -86,6 +86,9 @@ static int box_talloc_destructor(struct box *b) css_select_results_destroy(b->styles); b->styles = NULL; } + + if (b->href != NULL) + nsurl_unref(b->href); return 0; } @@ -96,7 +99,7 @@ static int box_talloc_destructor(struct box *b) * \param styles selection results for the box, or NULL * \param style computed style for the box (not copied), or 0 * \param style_owned whether style is owned by this box - * \param href href for the box (not copied), or 0 + * \param href href for the box (copied), or 0 * \param target target for the box (not copied), or 0 * \param title title for the box (not copied), or 0 * \param id id for the box (not copied), or 0 @@ -108,7 +111,7 @@ static int box_talloc_destructor(struct box *b) */ struct box * box_create(css_select_results *styles, css_computed_style *style, - bool style_owned, const char *href, const char *target, + bool style_owned, nsurl *href, const char *target, const char *title, char *id, void *context) { unsigned int i; @@ -140,7 +143,7 @@ struct box * box_create(css_select_results *styles, css_computed_style *style, box->text = NULL; box->length = 0; box->space = 0; - box->href = href; + box->href = (href == NULL) ? NULL : nsurl_ref(href); box->target = target; box->title = title; box->columns = 1; @@ -943,7 +946,7 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth) if (box->style) nscss_dump_computed_style(stream, box->style); if (box->href) - fprintf(stream, " -> '%s'", box->href); + fprintf(stream, " -> '%s'", nsurl_access(box->href)); if (box->target) fprintf(stream, " |%s|", box->target); if (box->title) diff --git a/render/box.h b/render/box.h index 84975ee82..3addb83a2 100644 --- a/render/box.h +++ b/render/box.h @@ -213,7 +213,7 @@ struct box { /** Width of space after current text (depends on font and size). */ int space; - const char *href; /**< Link, or 0. */ + nsurl *href; /**< Link, or 0. */ const char *target; /**< Link target, or 0. */ const char *title; /**< Title, or 0. */ @@ -284,11 +284,11 @@ struct column { /** Parameters for and similar elements. */ struct object_params { - char *data; + nsurl *data; char *type; char *codetype; - char *codebase; - char *classid; + nsurl *codebase; + nsurl *classid; struct object_param *params; }; @@ -312,7 +312,7 @@ extern const char *TARGET_BLANK; void *box_style_alloc(void *ptr, size_t len, void *pw); struct box * box_create(css_select_results *styles, css_computed_style *style, - bool style_owned, const char *href, const char *target, + bool style_owned, nsurl *href, const char *target, const char *title, char *id, void *context); void box_add_child(struct box *parent, struct box *child); void box_insert_sibling(struct box *box, struct box *new_box); @@ -331,7 +331,7 @@ struct box *box_pick_text_box(struct html_content *html, struct box *box_find_by_id(struct box *box, const char *id); bool box_visible(struct box *box); void box_dump(FILE *stream, struct box *box, unsigned int depth); -bool box_extract_link(const char *rel, const char *base, char **result); +bool box_extract_link(const char *rel, nsurl *base, nsurl **result); bool box_handle_scrollbars(struct content *c, struct box *box, bool bottom, bool right); diff --git a/render/box_construct.c b/render/box_construct.c index 6345b1d5d..ba642f1f2 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -70,7 +70,7 @@ struct box_construct_props { /** Style from which to inherit, or NULL if none */ const css_computed_style *parent_style; /** Current link target, or NULL if none */ - const char *href; + nsurl *href; /** Current frame target, or NULL if none */ const char *target; /** Current title attribute, or NULL if none */ @@ -575,7 +575,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, return false; box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false, - props.href, props.target, props.title, id, + props.href, props.target, props.title, id, ctx->content); if (box == NULL) return false; @@ -1228,20 +1228,19 @@ bool box_pre(BOX_SPECIAL_PARAMS) bool box_a(BOX_SPECIAL_PARAMS) { bool ok; - char *url; + nsurl *url; xmlChar *s; if ((s = xmlGetProp(n, (const xmlChar *) "href"))) { ok = box_extract_link((const char *) s, - nsurl_access(content->base_url), &url); + content->base_url, &url); xmlFree(s); if (!ok) return false; if (url) { - box->href = talloc_strdup(content, url); - free(url); - if (!box->href) - return false; + if (box->href != NULL) + nsurl_unref(box->href); + box->href = url; } } @@ -1284,7 +1283,8 @@ bool box_a(BOX_SPECIAL_PARAMS) bool box_image(BOX_SPECIAL_PARAMS) { bool ok; - char *s, *url; + char *s; + nsurl *url; xmlChar *alt, *src; enum css_width_e wtype; enum css_height_e htype; @@ -1318,17 +1318,16 @@ bool box_image(BOX_SPECIAL_PARAMS) /* get image URL */ if (!(src = xmlGetProp(n, (const xmlChar *) "src"))) return true; - if (!box_extract_link((char *) src, nsurl_access(content->base_url), - &url)) + if (!box_extract_link((char *) src, content->base_url, &url)) return false; xmlFree(src); if (!url) return true; /* start fetch */ - ok = html_fetch_object(content, url, box, image_types, + ok = html_fetch_object(content, nsurl_access(url), box, image_types, content->base.available_width, 1000, false); - free(url); + nsurl_unref(url); wtype = css_computed_width(box->style, &value, &wunit); htype = css_computed_height(box->style, &value, &hunit); @@ -1377,17 +1376,13 @@ bool box_object(BOX_SPECIAL_PARAMS) /* codebase, classid, and data are URLs * (codebase is the base for the other two) */ if ((codebase = xmlGetProp(n, (const xmlChar *) "codebase"))) { - if (!box_extract_link((char *) codebase, - nsurl_access(content->base_url), + if (!box_extract_link((char *) codebase, content->base_url, ¶ms->codebase)) return false; xmlFree(codebase); } if (!params->codebase) - params->codebase = strdup(nsurl_access(content->base_url)); - - if (!params->codebase) - return false; + params->codebase = nsurl_ref(content->base_url); if ((classid = xmlGetProp(n, (const xmlChar *) "classid"))) { if (!box_extract_link((char *) classid, params->codebase, @@ -1408,12 +1403,12 @@ bool box_object(BOX_SPECIAL_PARAMS) return true; /* Don't include ourself */ - if (params->classid && strcmp(nsurl_access(content->base_url), - params->classid) == 0) + if (params->classid && nsurl_compare(content->base_url, + params->classid, NSURL_COMPLETE)) return true; - if (params->data && strcmp(nsurl_access(content->base_url), - params->data) == 0) + if (params->data && nsurl_compare(content->base_url, + params->data, NSURL_COMPLETE)) return true; /* codetype and type are MIME types */ @@ -1506,7 +1501,8 @@ bool box_object(BOX_SPECIAL_PARAMS) /* start fetch (MIME type is ok or not specified) */ if (!html_fetch_object(content, - params->data ? params->data : params->classid, + params->data ? nsurl_access(params->data) : + nsurl_access(params->classid), box, CONTENT_ANY, content->base.available_width, 1000, false)) return false; @@ -1551,7 +1547,8 @@ bool box_create_frameset(struct content_html_frames *f, xmlNode *n, html_content *content) { unsigned int row, col, index, i; unsigned int rows = 1, cols = 1; - char *s, *url; + char *s; + nsurl *url; struct frame_dimension *row_height = 0, *col_width = 0; xmlNode *c; struct content_html_frames *frame; @@ -1665,21 +1662,17 @@ bool box_create_frameset(struct content_html_frames *f, xmlNode *n, url = NULL; if ((s = (char *) xmlGetProp(c, (const xmlChar *) "src"))) { - box_extract_link(s, - nsurl_access(content->base_url), - &url); + box_extract_link(s, content->base_url, &url); xmlFree(s); } /* copy url */ if (url) { /* no self-references */ - if (strcmp(nsurl_access(content->base_url), - url)) - frame->url = talloc_strdup(content, - url); - free(url); - url = NULL; + if (nsurl_compare(content->base_url, url, + NSURL_COMPLETE)) + frame->url = url; + url = NULL; } /* fill in specified values */ @@ -1741,7 +1734,8 @@ bool box_create_frameset(struct content_html_frames *f, xmlNode *n, bool box_iframe(BOX_SPECIAL_PARAMS) { - char *url, *s; + nsurl *url; + char *s; struct content_html_iframe *iframe; int i; @@ -1760,7 +1754,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) if (!(s = (char *) xmlGetProp(n, (const xmlChar *) "src"))) return true; - if (!box_extract_link(s, nsurl_access(content->base_url), &url)) { + if (!box_extract_link(s, content->base_url, &url)) { xmlFree(s); return false; } @@ -1769,22 +1763,22 @@ bool box_iframe(BOX_SPECIAL_PARAMS) return true; /* don't include ourself */ - if (strcmp(nsurl_access(content->base_url), url) == 0) { - free(url); + if (nsurl_compare(content->base_url, url, NSURL_COMPLETE)) { + nsurl_unref(url); return true; } /* create a new iframe */ iframe = talloc(content, struct content_html_iframe); if (!iframe) { - free(url); + nsurl_unref(url); return false; } iframe->box = box; iframe->margin_width = 0; iframe->margin_height = 0; iframe->name = NULL; - iframe->url = talloc_strdup(content, url); + iframe->url = url; iframe->scrolling = SCROLLING_AUTO; iframe->border = true; @@ -2315,15 +2309,14 @@ bool box_embed(BOX_SPECIAL_PARAMS) /* src is a URL */ if (!(src = xmlGetProp(n, (const xmlChar *) "src"))) return true; - if (!box_extract_link((char *) src, nsurl_access(content->base_url), - ¶ms->data)) + if (!box_extract_link((char *) src, content->base_url, ¶ms->data)) return false; xmlFree(src); if (!params->data) return true; /* Don't include ourself */ - if (strcmp(nsurl_access(content->base_url), params->data) == 0) + if (nsurl_compare(content->base_url, params->data, NSURL_COMPLETE)) return true; /* add attributes as parameters to linked list */ @@ -2353,8 +2346,9 @@ bool box_embed(BOX_SPECIAL_PARAMS) box->object_params = params; /* start fetch */ - return html_fetch_object(content, params->data, box, CONTENT_ANY, - content->base.available_width, 1000, false); + return html_fetch_object(content, nsurl_access(params->data), box, + CONTENT_ANY, content->base.available_width, 1000, + false); } /** @@ -2399,11 +2393,11 @@ bool box_get_attribute(xmlNode *n, const char *attribute, * \return true on success, false on memory exhaustion */ -bool box_extract_link(const char *rel, const char *base, char **result) +bool box_extract_link(const char *rel, nsurl *base, nsurl **result) { char *s, *s1, *apos0 = 0, *apos1 = 0, *quot0 = 0, *quot1 = 0; unsigned int i, j, end; - url_func_result res; + nserror error; s1 = s = malloc(3 * strlen(rel) + 1); if (!s) @@ -2445,12 +2439,12 @@ bool box_extract_link(const char *rel, const char *base, char **result) } /* construct absolute URL */ - res = url_join(s1, base, result); + error = nsurl_join(base, s1, result); free(s); - if (res == URL_FUNC_NOMEM) + if (error != NSERROR_OK) { + *result = NULL; return false; - else if (res == URL_FUNC_FAILED) - return true; + } return true; } diff --git a/render/html.c b/render/html.c index 0c809adfb..31dc64ba4 100644 --- a/render/html.c +++ b/render/html.c @@ -2169,12 +2169,13 @@ void html_get_contextual_content(struct content *c, data->object = box->object; if (box->href) - data->link_url = box->href; + data->link_url = nsurl_access(box->href); if (box->usemap) { const char *target = NULL; - data->link_url = imagemap_get(html, box->usemap, - box_x, box_y, x, y, &target); + data->link_url = nsurl_access(imagemap_get(html, + box->usemap, box_x, box_y, x, y, + &target)); } } } diff --git a/render/html.h b/render/html.h index 4d4c8cefd..81e18d48e 100644 --- a/render/html.h +++ b/render/html.h @@ -102,7 +102,7 @@ struct content_html_frames { int margin_height; /** frame margin height */ char *name; /** frame name (for targetting) */ - char *url; /** frame url */ + nsurl *url; /** frame url */ bool no_resize; /** frame is not resizable */ frame_scrolling scrolling; /** scrolling characteristics */ @@ -120,7 +120,7 @@ struct content_html_iframe { int margin_height; /** frame margin height */ char *name; /** frame name (for targetting) */ - char *url; /** frame url */ + nsurl *url; /** frame url */ frame_scrolling scrolling; /** scrolling characteristics */ bool border; /** frame has a border */ diff --git a/render/html_interaction.c b/render/html_interaction.c index abe7d20f3..95993d594 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -168,7 +168,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw, html_content *html = (html_content *) c; enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE; const char *title = 0; - const char *url = 0; + nsurl *url = 0; const char *target = 0; char status_buffer[200]; const char *status = 0; @@ -543,22 +543,23 @@ void html_mouse_action(struct content *c, struct browser_window *bw, } else if (url) { if (title) { snprintf(status_buffer, sizeof status_buffer, "%s: %s", - url, title); + nsurl_access(url), title); status = status_buffer; } else - status = url; + status = nsurl_access(url); pointer = get_pointer_shape(bw, url_box, imagemap); if (mouse & BROWSER_MOUSE_CLICK_1 && mouse & BROWSER_MOUSE_MOD_1) { /* force download of link */ - browser_window_go_post(bw, url, 0, 0, false, - nsurl_access(content_get_url(h)), + browser_window_go_post(bw, nsurl_access(url), 0, 0, + false, nsurl_access(content_get_url(h)), true, true, 0); } else if (mouse & BROWSER_MOUSE_CLICK_2 && mouse & BROWSER_MOUSE_MOD_1) { - gui_window_save_link(bw->window, url, title); + gui_window_save_link(bw->window, + nsurl_access(url), title); } else if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2)) action = ACTION_GO; @@ -690,7 +691,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw, break; case ACTION_GO: browser_window_go(browser_window_find_target(bw, target, mouse), - url, nsurl_access(content_get_url(h)), true); + nsurl_access(url), + nsurl_access(content_get_url(h)), true); break; case ACTION_NONE: break; diff --git a/render/imagemap.c b/render/imagemap.c index 87002fd3d..cf91f31d3 100644 --- a/render/imagemap.c +++ b/render/imagemap.c @@ -43,7 +43,7 @@ typedef enum { struct mapentry { imagemap_entry_type type; /**< type of shape */ - char *url; /**< absolute url to go to */ + nsurl *url; /**< absolute url to go to */ char *target; /**< target frame (if any) */ union { struct { @@ -77,7 +77,7 @@ static bool imagemap_add(html_content *c, const char *key, static bool imagemap_create(html_content *c); static bool imagemap_extract_map(xmlNode *node, html_content *c, struct mapentry **entry); -static bool imagemap_addtolist(xmlNode *n, const char *base_url, +static bool imagemap_addtolist(xmlNode *n, nsurl *base_url, struct mapentry **entry); static void imagemap_freelist(struct mapentry *list); static unsigned int imagemap_hash(const char *key); @@ -203,11 +203,12 @@ void imagemap_dump(html_content *c) for (entry = map->list; entry; entry = entry->next) { switch (entry->type) { case IMAGEMAP_DEFAULT: - LOG(("\tDefault: %s", entry->url)); + LOG(("\tDefault: %s", nsurl_access( + entry->url))); break; case IMAGEMAP_RECT: LOG(("\tRectangle: %s: [(%d,%d),(%d,%d)]", - entry->url, + nsurl_access(entry->url), entry->bounds.rect.x0, entry->bounds.rect.y0, entry->bounds.rect.x1, @@ -215,13 +216,14 @@ void imagemap_dump(html_content *c) break; case IMAGEMAP_CIRCLE: LOG(("\tCircle: %s: [(%d,%d),%d]", - entry->url, + nsurl_access(entry->url), entry->bounds.circle.x, entry->bounds.circle.y, entry->bounds.circle.r)); break; case IMAGEMAP_POLY: - LOG(("\tPolygon: %s:", entry->url)); + LOG(("\tPolygon: %s:", nsurl_access( + entry->url))); for (j = 0; j != entry->bounds.poly.num; j++) { fprintf(stderr, "(%d,%d) ", @@ -316,7 +318,7 @@ bool imagemap_extract_map(xmlNode *node, html_content *c, */ if (strcmp((const char *) node->name, "area") == 0 || strcmp((const char *) node->name, "a") == 0) { - if (imagemap_addtolist(node, nsurl_access(c->base_url), + if (imagemap_addtolist(node, c->base_url, entry) == false) return false; } @@ -341,7 +343,7 @@ bool imagemap_extract_map(xmlNode *node, html_content *c, * \param entry Pointer to list of entries * \return false on memory exhaustion, true otherwise */ -bool imagemap_addtolist(xmlNode *n, const char *base_url, +bool imagemap_addtolist(xmlNode *n, nsurl *base_url, struct mapentry **entry) { char *shape, *coords = NULL, *href, *target = NULL; @@ -447,7 +449,7 @@ bool imagemap_addtolist(xmlNode *n, const char *base_url, if (target) { new_map->target = strdup(target); if (new_map->target == NULL) { - free(new_map->url); + nsurl_unref(new_map->url); free(new_map); xmlFree(target); xmlFree(href); @@ -529,7 +531,7 @@ bool imagemap_addtolist(xmlNode *n, const char *base_url, free(new_map->bounds.poly.ycoords); free(new_map->bounds.poly.xcoords); free(new_map->target); - free(new_map->url); + nsurl_unref(new_map->url); free(new_map); xmlFree(href); xmlFree(shape); @@ -544,7 +546,7 @@ bool imagemap_addtolist(xmlNode *n, const char *base_url, free(new_map->bounds.poly.ycoords); free(new_map->bounds.poly.xcoords); free(new_map->target); - free(new_map->url); + nsurl_unref(new_map->url); free(new_map); xmlFree(href); xmlFree(shape); @@ -606,7 +608,7 @@ void imagemap_freelist(struct mapentry *list) while (entry != NULL) { prev = entry; - free(entry->url); + nsurl_unref(entry->url); if (entry->target) free(entry->target); @@ -633,7 +635,7 @@ void imagemap_freelist(struct mapentry *list) * \param target Pointer to location to receive target pointer (if any) * \return The url associated with this area, or NULL if not found */ -const char *imagemap_get(struct html_content *c, const char *key, +nsurl *imagemap_get(struct html_content *c, const char *key, unsigned long x, unsigned long y, unsigned long click_x, unsigned long click_y, const char **target) diff --git a/render/imagemap.h b/render/imagemap.h index 01d07e73d..7877e5e04 100644 --- a/render/imagemap.h +++ b/render/imagemap.h @@ -21,6 +21,8 @@ #include +#include "utils/nsurl.h" + struct html_content; struct hlcache_handle; @@ -28,7 +30,7 @@ void imagemap_destroy(struct html_content *c); void imagemap_dump(struct html_content *c); bool imagemap_extract(xmlNode *node, struct html_content *c); -const char *imagemap_get(struct html_content *c, const char *key, +nsurl *imagemap_get(struct html_content *c, const char *key, unsigned long x, unsigned long y, unsigned long click_x, unsigned long click_y, const char **target); diff --git a/utils/nsurl.c b/utils/nsurl.c index acb269aea..88aef7862 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -839,6 +839,7 @@ nserror nsurl_create(const char const *url_s, nsurl **url) buff = malloc(length * 3 + 1); if (buff == NULL) { free(*url); + *url = NULL; return NSERROR_NOMEM; } @@ -855,6 +856,7 @@ nserror nsurl_create(const char const *url_s, nsurl **url) if (e != NSERROR_OK) { free(*url); + *url = NULL; return NSERROR_NOMEM; } @@ -862,6 +864,7 @@ nserror nsurl_create(const char const *url_s, nsurl **url) if (nsurl_get(*url, NSURL_WITH_FRAGMENT, &((*url)->string), &((*url)->length)) != NSERROR_OK) { free(*url); + *url = NULL; return NSERROR_NOMEM; } @@ -1392,6 +1395,7 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) buff = malloc(length + 5); if (buff == NULL) { free(*joined); + *joined = NULL; return NSERROR_NOMEM; } @@ -1501,6 +1505,7 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) if (error != NSERROR_OK) { free(*joined); + *joined = NULL; return NSERROR_NOMEM; } @@ -1508,6 +1513,7 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) if (nsurl_get(*joined, NSURL_WITH_FRAGMENT, &((*joined)->string), &((*joined)->length)) != NSERROR_OK) { free(*joined); + *joined = NULL; return NSERROR_NOMEM; } -- cgit v1.2.3