Plumb the ownership up a bit.

The HTML function returning a DilloUrl now returns
ownership.  More releases scattered, but we can clean those
up in time.
This commit is contained in:
2025-04-13 15:40:46 -04:00
parent 61c879c218
commit 76bae93e1c
4 changed files with 31 additions and 39 deletions

View File

@ -1666,10 +1666,9 @@ void CssParser::parseImport(DilloHtml *html)
if (urlStr) { if (urlStr) {
if (importSyntaxIsOK && mediaIsSelected) { if (importSyntaxIsOK && mediaIsSelected) {
MSG("CssParser::parseImport(): @import %s\n", urlStr); MSG("CssParser::parseImport(): @import %s\n", urlStr);
DilloUrl *url = a_Html_url_new (html, urlStr, a_Url_str(*this->baseUrl), auto url = a_Html_url_new (html, urlStr, a_Url_str(*this->baseUrl),
this->baseUrl ? 1 : 0); this->baseUrl ? 1 : 0);
a_Html_load_stylesheet(html, url); a_Html_load_stylesheet(html, url.get());
delete url;
} }
dFree (urlStr); dFree (urlStr);
} }

View File

@ -373,7 +373,7 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize)
} }
} }
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action"))) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action")))
action = a_Html_url_new(html, attrbuf, NULL, 0); action = a_Html_url_new(html, attrbuf, NULL, 0).release();
else { else {
if (html->DocType != DT_HTML || html->DocTypeVersion <= 4.01f) if (html->DocType != DT_HTML || html->DocTypeVersion <= 4.01f)
BUG_MSG("<form> requires action attribute."); BUG_MSG("<form> requires action attribute.");
@ -607,7 +607,7 @@ void Html_tag_open_isindex(DilloHtml *html, const char *tag, int tagsize)
} }
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action"))) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action")))
action = a_Html_url_new(html, attrbuf, NULL, 0); action = a_Html_url_new(html, attrbuf, NULL, 0).release();
else else
action = a_Url_dup(*html->base_url).release(); action = a_Url_dup(*html->base_url).release();

View File

@ -171,21 +171,21 @@ void DilloHtml::bugMessage(const char *format, ... )
* Wrapper for a_Url_new that adds an error detection message. * Wrapper for a_Url_new that adds an error detection message.
* If use_base_url is TRUE, it uses base_url. Otherwise it uses html->base_url. * If use_base_url is TRUE, it uses base_url. Otherwise it uses html->base_url.
*/ */
DilloUrl *a_Html_url_new(DilloHtml *html, std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html,
const char *url_str, const char *base_url, const char *url_str, const char *base_url,
int use_base_url) int use_base_url)
{ {
if (!url_str) { if (!url_str) {
MSG("a_Html_url_new: URL is NULL\n"); MSG("a_Html_url_new: URL is NULL\n");
return NULL; return nullptr;
} }
DilloUrl *url = a_Url_new(url_str, std::unique_ptr< DilloUrl > url = a_Url_new(url_str,
(use_base_url) ? base_url : URL_STR_(html->base_url)).release(); (use_base_url) ? base_url : URL_STR_(html->base_url));
if (!url) { if (!url) {
BUG_MSG("URL is not valid '%s'.", url_str); BUG_MSG("URL is not valid '%s'.", url_str);
return NULL; return nullptr;
} }
int n_ic, n_ic_spc; int n_ic, n_ic_spc;
@ -1920,7 +1920,7 @@ static void Html_tag_open_frame (DilloHtml *html, const char *tag, int tagsize)
if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")))
return; return;
if (!(url = a_Html_url_new(html, attrbuf, NULL, 0))) if (!(url = a_Html_url_new(html, attrbuf, NULL, 0).release()))
return; return;
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) { if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
@ -2135,7 +2135,7 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
DilloImage *image; DilloImage *image;
if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) || if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) ||
!(url = a_Html_url_new(html, attrbuf, NULL, 0))) !(url = a_Html_url_new(html, attrbuf, NULL, 0).release()))
return NULL; return NULL;
alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL); alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL);
@ -2265,7 +2265,6 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize) static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
{ {
DilloImage *Image; DilloImage *Image;
DilloUrl *usemap_url;
const char *attrbuf; const char *attrbuf;
/* This avoids loading images. Useful for viewing suspicious HTML email. */ /* This avoids loading images. Useful for viewing suspicious HTML email. */
@ -2276,7 +2275,7 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
if (!Image) if (!Image)
return; return;
usemap_url = NULL; std::unique_ptr< DilloUrl > usemap_url;
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "usemap"))) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "usemap")))
/* TODO: usemap URLs outside of the document are not used. */ /* TODO: usemap URLs outside of the document are not used. */
usemap_url = a_Html_url_new(html, attrbuf, NULL, 0); usemap_url = a_Html_url_new(html, attrbuf, NULL, 0);
@ -2293,7 +2292,7 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
dwi->setIsMap(); dwi->setIsMap();
_MSG(" Html_tag_open_img: server-side map (ISMAP)\n"); _MSG(" Html_tag_open_img: server-side map (ISMAP)\n");
} else if (html->style ()->x_link != -1 && } else if (html->style ()->x_link != -1 &&
usemap_url == NULL) { usemap_url == nullptr) {
/* For simple links, we have to suppress the "image_pressed" signal. /* For simple links, we have to suppress the "image_pressed" signal.
* This is overridden for USEMAP images. */ * This is overridden for USEMAP images. */
// a_Dw_widget_set_button_sensitive (IM2DW(Image->dw), FALSE); // a_Dw_widget_set_button_sensitive (IM2DW(Image->dw), FALSE);
@ -2301,7 +2300,6 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
if (usemap_url) { if (usemap_url) {
dwi->setUseMap(&html->maps, new ::object::String(URL_STR(usemap_url))); dwi->setUseMap(&html->maps, new ::object::String(URL_STR(usemap_url)));
delete usemap_url;
} }
} }
@ -2312,7 +2310,6 @@ static void Html_tag_content_map(DilloHtml *html, const char *tag, int tagsize)
{ {
char *hash_name; char *hash_name;
const char *attrbuf; const char *attrbuf;
DilloUrl *url;
if (html->InFlags & IN_MAP) { if (html->InFlags & IN_MAP) {
BUG_MSG("Nested <map>."); BUG_MSG("Nested <map>.");
@ -2320,9 +2317,8 @@ static void Html_tag_content_map(DilloHtml *html, const char *tag, int tagsize)
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) {
html->InFlags |= IN_MAP; html->InFlags |= IN_MAP;
hash_name = dStrconcat("#", attrbuf, NULL); hash_name = dStrconcat("#", attrbuf, NULL);
url = a_Html_url_new(html, hash_name, NULL, 0); auto url = a_Html_url_new(html, hash_name, NULL, 0);
html->maps.startNewMap(new ::object::String(URL_STR(url))); html->maps.startNewMap(new ::object::String(URL_STR(url)));
delete url;
dFree(hash_name); dFree(hash_name);
} else { } else {
BUG_MSG("<map> requires name attribute."); BUG_MSG("<map> requires name attribute.");
@ -2451,7 +2447,7 @@ static void
} }
if (shape != NULL || type == BACKGROUND) { if (shape != NULL || type == BACKGROUND) {
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "href"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "href"))) {
url = a_Html_url_new(html, attrbuf, NULL, 0); url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
link = Html_set_new_link(html, &url); link = Html_set_new_link(html, &url);
@ -2469,7 +2465,8 @@ static void
*/ */
static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize) static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
{ {
DilloUrl *url, *base_url = NULL; DilloUrl *url;
std::unique_ptr< DilloUrl > base_url;
const char *attrbuf; const char *attrbuf;
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "codebase"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "codebase"))) {
@ -2478,7 +2475,7 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "data"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "data"))) {
url = a_Html_url_new(html, attrbuf, url = a_Html_url_new(html, attrbuf,
URL_STR(base_url), (base_url != NULL)); URL_STR(base_url), (base_url != NULL)).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) { if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
@ -2490,7 +2487,6 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
html->styleEngine->setNonCssHint(PROPERTY_X_LINK, CSS_TYPE_INTEGER, html->styleEngine->setNonCssHint(PROPERTY_X_LINK, CSS_TYPE_INTEGER,
Html_set_new_link(html, &url)); Html_set_new_link(html, &url));
} }
delete base_url;
} }
static void Html_tag_content_object(DilloHtml *html, const char *tag, static void Html_tag_content_object(DilloHtml *html, const char *tag,
@ -2516,7 +2512,7 @@ static void Html_tag_open_video(DilloHtml *html, const char *tag, int tagsize)
/* TODO: poster attr */ /* TODO: poster attr */
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
url = a_Html_url_new(html, attrbuf, NULL, 0); url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) { if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
@ -2548,7 +2544,7 @@ static void Html_tag_open_audio(DilloHtml *html, const char *tag, int tagsize)
} }
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
url = a_Html_url_new(html, attrbuf, NULL, 0); url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) { if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
@ -2583,7 +2579,7 @@ static void Html_tag_open_source(DilloHtml *html, const char *tag,
BUG_MSG("<source> requires src attribute."); BUG_MSG("<source> requires src attribute.");
return; return;
} else { } else {
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0); DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
@ -2621,7 +2617,7 @@ static void Html_tag_open_embed(DilloHtml *html, const char *tag, int tagsize)
const char *attrbuf; const char *attrbuf;
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) { if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0); DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
@ -2702,7 +2698,7 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
if (D_ASCII_TOLOWER(attrbuf[0]) == 'j') if (D_ASCII_TOLOWER(attrbuf[0]) == 'j')
attrbuf = Html_get_javascript_link(html); attrbuf = Html_get_javascript_link(html);
url = a_Html_url_new(html, attrbuf, NULL, 0); url = a_Html_url_new(html, attrbuf, NULL, 0).release();
dReturn_if_fail ( url != NULL ); dReturn_if_fail ( url != NULL );
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) { if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
@ -3125,7 +3121,6 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
const char *p, *equiv, *charset, *content; const char *p, *equiv, *charset, *content;
char delay_str[64], *mr_url; char delay_str[64], *mr_url;
DilloUrl *new_url;
int delay; int delay;
/* only valid inside HEAD */ /* only valid inside HEAD */
@ -3174,7 +3169,7 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
mr_url = dStrdup(""); mr_url = dStrdup("");
} }
new_url = a_Html_url_new(html, mr_url, NULL, 0); auto new_url = a_Html_url_new(html, mr_url, NULL, 0);
if (a_Url_cmp(*html->base_url, *new_url) == 0) { if (a_Url_cmp(*html->base_url, *new_url) == 0) {
/* redirection loop, or empty url string: ignore */ /* redirection loop, or empty url string: ignore */
@ -3186,8 +3181,8 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
if (URL_FLAGS(html->base_url) & URL_SpamSafe) { if (URL_FLAGS(html->base_url) & URL_SpamSafe) {
a_UIcmd_set_msg(html->bw, a_UIcmd_set_msg(html->bw,
"WARNING: local URL with META refresh. Aborting."); "WARNING: local URL with META refresh. Aborting.");
} else if (a_Capi_dpi_verify_request(html->bw, new_url)) { } else if (a_Capi_dpi_verify_request(html->bw, new_url.get())) {
a_UIcmd_redirection0((void*)html->bw, new_url); a_UIcmd_redirection0((void*)html->bw, new_url.get());
} }
} else { } else {
/* Send a custom HTML message. /* Send a custom HTML message.
@ -3206,7 +3201,6 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
} }
dStr_free(ds_msg, 1); dStr_free(ds_msg, 1);
} }
delete new_url;
dFree(mr_url); dFree(mr_url);
} else if (!dStrAsciiCasecmp(equiv, "content-type") && } else if (!dStrAsciiCasecmp(equiv, "content-type") &&
@ -3294,7 +3288,7 @@ void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
*/ */
static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize) static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize)
{ {
DilloUrl *url; std::unique_ptr< DilloUrl > url;
const char *attrbuf; const char *attrbuf;
//char *tag_str = dStrndup(tag, tagsize); //char *tag_str = dStrndup(tag, tagsize);
@ -3335,8 +3329,7 @@ static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize)
_MSG(" Html_tag_open_link(): addCssUrl %s\n", URL_STR(url)); _MSG(" Html_tag_open_link(): addCssUrl %s\n", URL_STR(url));
html->addCssUrl(url); html->addCssUrl(url.get());
delete url;
} }
/** /**
@ -3352,8 +3345,8 @@ static void Html_tag_open_base(DilloHtml *html, const char *tag, int tagsize)
bool_t html5 = html->DocType == DT_HTML && bool_t html5 = html->DocType == DT_HTML &&
html->DocTypeVersion >= 5.0f; html->DocTypeVersion >= 5.0f;
BaseUrl = html5 ? a_Html_url_new(html, attrbuf, NULL, 0) : BaseUrl = html5 ? a_Html_url_new(html, attrbuf, NULL, 0).release() :
a_Html_url_new(html, attrbuf, "", 1); a_Html_url_new(html, attrbuf, "", 1).release();
if (html5 || URL_SCHEME_(BaseUrl)) { if (html5 || URL_SCHEME_(BaseUrl)) {
/* Pass the URL_SpamSafe flag to the new base url */ /* Pass the URL_SpamSafe flag to the new base url */

View File

@ -277,7 +277,7 @@ char *a_Html_get_attr_wdef(DilloHtml *html,
const char *attrname, const char *attrname,
const char *def); const char *def);
DilloUrl *a_Html_url_new(DilloHtml *html, std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html,
const char *url_str, const char *base_url, const char *url_str, const char *base_url,
int use_base_url); int use_base_url);