Another set of local ownership down.
This commit is contained in:
106
src/form.cc
106
src/form.cc
@ -447,7 +447,6 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
DilloHtmlInputType inp_type;
|
DilloHtmlInputType inp_type;
|
||||||
Resource *resource = NULL;
|
Resource *resource = NULL;
|
||||||
Embed *embed = NULL;
|
Embed *embed = NULL;
|
||||||
char *value, *name, *type, *init_str, *placeholder = NULL;
|
|
||||||
const char *attrbuf, *label;
|
const char *attrbuf, *label;
|
||||||
bool init_val = false;
|
bool init_val = false;
|
||||||
ResourceFactory *factory;
|
ResourceFactory *factory;
|
||||||
@ -464,61 +463,62 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
factory = HT2LT(html)->getResourceFactory();
|
factory = HT2LT(html)->getResourceFactory();
|
||||||
|
|
||||||
/* Get 'value', 'name' and 'type' */
|
/* Get 'value', 'name' and 'type' */
|
||||||
value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
auto value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
||||||
name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
auto name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
||||||
type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
|
auto type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
|
||||||
|
std::optional< std::string > init_str;
|
||||||
|
std::optional< std::string > placeholder;
|
||||||
|
|
||||||
init_str = NULL;
|
|
||||||
inp_type = DILLO_HTML_INPUT_UNKNOWN;
|
inp_type = DILLO_HTML_INPUT_UNKNOWN;
|
||||||
if (!dStrAsciiCasecmp(type, "password")) {
|
if (!dStrAsciiCasecmp(type.value().c_str(), "password")) {
|
||||||
inp_type = DILLO_HTML_INPUT_PASSWORD;
|
inp_type = DILLO_HTML_INPUT_PASSWORD;
|
||||||
placeholder = a_Html_get_attr_wdef(html, tag,tagsize,"placeholder",NULL);
|
placeholder = a_Html_get_attr_wdef(html, tag,tagsize,"placeholder",NULL);
|
||||||
attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
|
attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
|
||||||
int size = Html_input_get_size(html, attrbuf);
|
int size = Html_input_get_size(html, attrbuf);
|
||||||
resource = factory->createEntryResource (size, true, NULL, placeholder);
|
resource = factory->createEntryResource (size, true, NULL, placeholder.value().c_str());
|
||||||
init_str = value;
|
init_str = value;
|
||||||
} else if (!dStrAsciiCasecmp(type, "checkbox")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "checkbox")) {
|
||||||
inp_type = DILLO_HTML_INPUT_CHECKBOX;
|
inp_type = DILLO_HTML_INPUT_CHECKBOX;
|
||||||
resource = factory->createCheckButtonResource(false);
|
resource = factory->createCheckButtonResource(false);
|
||||||
init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL);
|
init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL);
|
||||||
init_str = (value) ? value : dStrdup("on");
|
init_str = value.value_or( "on" );
|
||||||
} else if (!dStrAsciiCasecmp(type, "radio")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "radio")) {
|
||||||
inp_type = DILLO_HTML_INPUT_RADIO;
|
inp_type = DILLO_HTML_INPUT_RADIO;
|
||||||
RadioButtonResource *rb_r = NULL;
|
RadioButtonResource *rb_r = NULL;
|
||||||
std::shared_ptr input = Html_get_radio_input(html, name);
|
std::shared_ptr input = Html_get_radio_input(html, name ? name.value().c_str() : nullptr);
|
||||||
if (input)
|
if (input)
|
||||||
rb_r = (RadioButtonResource*) input->embed->getResource();
|
rb_r = (RadioButtonResource*) input->embed->getResource();
|
||||||
resource = factory->createRadioButtonResource(rb_r, false);
|
resource = factory->createRadioButtonResource(rb_r, false);
|
||||||
init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL);
|
init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL);
|
||||||
init_str = value;
|
init_str = value;
|
||||||
} else if (!dStrAsciiCasecmp(type, "hidden")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "hidden")) {
|
||||||
inp_type = DILLO_HTML_INPUT_HIDDEN;
|
inp_type = DILLO_HTML_INPUT_HIDDEN;
|
||||||
init_str = value;
|
init_str = value;
|
||||||
int size = Html_input_get_size(html, NULL);
|
int size = Html_input_get_size(html, NULL);
|
||||||
resource = factory->createEntryResource(size, false, name, NULL);
|
resource = factory->createEntryResource(size, false, name ? name.value().c_str() : nullptr, NULL);
|
||||||
} else if (!dStrAsciiCasecmp(type, "submit")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "submit")) {
|
||||||
inp_type = DILLO_HTML_INPUT_SUBMIT;
|
inp_type = DILLO_HTML_INPUT_SUBMIT;
|
||||||
init_str = (value) ? value : dStrdup("submit");
|
init_str = value.value_or("submit");
|
||||||
resource = factory->createLabelButtonResource(init_str);
|
resource = factory->createLabelButtonResource(init_str.value().c_str());
|
||||||
} else if (!dStrAsciiCasecmp(type, "reset")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "reset")) {
|
||||||
inp_type = DILLO_HTML_INPUT_RESET;
|
inp_type = DILLO_HTML_INPUT_RESET;
|
||||||
init_str = (value) ? value : dStrdup("Reset");
|
init_str = value.value_or( "Reset" );
|
||||||
resource = factory->createLabelButtonResource(init_str);
|
resource = factory->createLabelButtonResource(init_str.value().c_str());
|
||||||
} else if (!dStrAsciiCasecmp(type, "image")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "image")) {
|
||||||
if (URL_FLAGS(html->base_url) & URL_SpamSafe) {
|
if (URL_FLAGS(html->base_url) & URL_SpamSafe) {
|
||||||
/* Don't request the image; make a text submit button instead */
|
/* Don't request the image; make a text submit button instead */
|
||||||
inp_type = DILLO_HTML_INPUT_SUBMIT;
|
inp_type = DILLO_HTML_INPUT_SUBMIT;
|
||||||
attrbuf = a_Html_get_attr(html, tag, tagsize, "alt");
|
attrbuf = a_Html_get_attr(html, tag, tagsize, "alt");
|
||||||
label = attrbuf ? attrbuf : value ? value : name ? name : "Submit";
|
label = attrbuf ? attrbuf : value.value_or( name.value_or( "Submit" ) ).c_str();
|
||||||
init_str = dStrdup(label);
|
init_str = label;
|
||||||
resource = factory->createLabelButtonResource(init_str);
|
resource = factory->createLabelButtonResource(init_str.value().c_str());
|
||||||
} else {
|
} else {
|
||||||
inp_type = DILLO_HTML_INPUT_IMAGE;
|
inp_type = DILLO_HTML_INPUT_IMAGE;
|
||||||
/* use a dw_image widget */
|
/* use a dw_image widget */
|
||||||
embed = Html_input_image(html, tag, tagsize);
|
embed = Html_input_image(html, tag, tagsize);
|
||||||
init_str = value;
|
init_str = value;
|
||||||
}
|
}
|
||||||
} else if (!dStrAsciiCasecmp(type, "file")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "file")) {
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
if (html->InFlags & IN_FORM) {
|
if (html->InFlags & IN_FORM) {
|
||||||
DilloHtmlForm *form = html->getCurrentForm();
|
DilloHtmlForm *form = html->getCurrentForm();
|
||||||
@ -536,14 +536,14 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
}
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
inp_type = DILLO_HTML_INPUT_FILE;
|
inp_type = DILLO_HTML_INPUT_FILE;
|
||||||
init_str = dStrdup("File selector");
|
init_str = "File selector";
|
||||||
resource = factory->createLabelButtonResource(init_str);
|
resource = factory->createLabelButtonResource(init_str.value().c_str());
|
||||||
}
|
}
|
||||||
} else if (!dStrAsciiCasecmp(type, "button")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "button")) {
|
||||||
inp_type = DILLO_HTML_INPUT_BUTTON;
|
inp_type = DILLO_HTML_INPUT_BUTTON;
|
||||||
if (value) {
|
if (value) {
|
||||||
init_str = value;
|
init_str = value;
|
||||||
resource = factory->createLabelButtonResource(init_str);
|
resource = factory->createLabelButtonResource(init_str.value().c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Text input, which also is the default */
|
/* Text input, which also is the default */
|
||||||
@ -551,15 +551,15 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
placeholder = a_Html_get_attr_wdef(html, tag,tagsize,"placeholder",NULL);
|
placeholder = a_Html_get_attr_wdef(html, tag,tagsize,"placeholder",NULL);
|
||||||
attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
|
attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
|
||||||
int size = Html_input_get_size(html, attrbuf);
|
int size = Html_input_get_size(html, attrbuf);
|
||||||
resource = factory->createEntryResource(size, false, NULL, placeholder);
|
resource = factory->createEntryResource(size, false, NULL, placeholder.value().c_str());
|
||||||
init_str = value;
|
init_str = value;
|
||||||
}
|
}
|
||||||
if (resource)
|
if (resource)
|
||||||
embed = new Embed (resource);
|
embed = new Embed (resource);
|
||||||
|
|
||||||
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
|
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
|
||||||
Html_add_input(html, inp_type, embed, name,
|
Html_add_input(html, inp_type, embed, name ? name.value().c_str() : nullptr,
|
||||||
(init_str) ? init_str : "", init_val);
|
init_str.value_or( "" ).c_str(), init_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embed != NULL && inp_type != DILLO_HTML_INPUT_IMAGE &&
|
if (embed != NULL && inp_type != DILLO_HTML_INPUT_IMAGE &&
|
||||||
@ -587,12 +587,6 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
}
|
}
|
||||||
HT2TB(html)->addWidget (embed, html->backgroundStyle());
|
HT2TB(html)->addWidget (embed, html->backgroundStyle());
|
||||||
}
|
}
|
||||||
dFree(type);
|
|
||||||
dFree(name);
|
|
||||||
if (init_str != value)
|
|
||||||
dFree(init_str);
|
|
||||||
dFree(placeholder);
|
|
||||||
dFree(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -754,7 +748,7 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
html->InFlags |= IN_SELECT;
|
html->InFlags |= IN_SELECT;
|
||||||
html->InFlags &= ~IN_OPTION;
|
html->InFlags &= ~IN_OPTION;
|
||||||
|
|
||||||
char *name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
auto name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
||||||
ResourceFactory *factory = HT2LT(html)->getResourceFactory ();
|
ResourceFactory *factory = HT2LT(html)->getResourceFactory ();
|
||||||
DilloHtmlInputType type;
|
DilloHtmlInputType type;
|
||||||
SelectionResource *res;
|
SelectionResource *res;
|
||||||
@ -789,9 +783,8 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
}
|
}
|
||||||
HT2TB(html)->addWidget (embed, html->backgroundStyle ());
|
HT2TB(html)->addWidget (embed, html->backgroundStyle ());
|
||||||
|
|
||||||
Html_add_input(html, type, embed, name, NULL, false);
|
Html_add_input(html, type, embed, name.value().c_str(), NULL, false);
|
||||||
a_Html_stash_init(html);
|
a_Html_stash_init(html);
|
||||||
dFree(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -838,16 +831,16 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
if (input &&
|
if (input &&
|
||||||
(input->type == DILLO_HTML_INPUT_SELECT ||
|
(input->type == DILLO_HTML_INPUT_SELECT ||
|
||||||
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
||||||
char *label = a_Html_get_attr_wdef(html, tag, tagsize, "label", NULL);
|
auto label = a_Html_get_attr_wdef(html, tag, tagsize, "label", NULL);
|
||||||
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
||||||
|
|
||||||
if (!label) {
|
if (!label) {
|
||||||
BUG_MSG("<optgroup> requires label attribute.");
|
BUG_MSG("<optgroup> requires label attribute.");
|
||||||
label = dStrdup("");
|
label = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
DilloHtmlOptgroup *opt =
|
DilloHtmlOptgroup *opt =
|
||||||
new DilloHtmlOptgroup (label, enabled);
|
new DilloHtmlOptgroup (dStrdup(label.value().c_str()), enabled);
|
||||||
|
|
||||||
input->select->addOpt(opt);
|
input->select->addOpt(opt);
|
||||||
}
|
}
|
||||||
@ -891,13 +884,13 @@ void Html_tag_open_option(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
if (input &&
|
if (input &&
|
||||||
(input->type == DILLO_HTML_INPUT_SELECT ||
|
(input->type == DILLO_HTML_INPUT_SELECT ||
|
||||||
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
||||||
char *value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
auto value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
||||||
char *label = a_Html_get_attr_wdef(html, tag, tagsize, "label", NULL);
|
auto label = a_Html_get_attr_wdef(html, tag, tagsize, "label", NULL);
|
||||||
bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL);
|
bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL);
|
||||||
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
||||||
|
|
||||||
DilloHtmlOption *option =
|
DilloHtmlOption *option =
|
||||||
new DilloHtmlOption (value, label, selected, enabled);
|
new DilloHtmlOption (dStrdup( value.value().c_str() ), dStrdup( label.value().c_str() ), selected, enabled);
|
||||||
|
|
||||||
input->select->addOpt(option);
|
input->select->addOpt(option);
|
||||||
}
|
}
|
||||||
@ -923,30 +916,28 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
* bit simpler. May be changed in the future.
|
* bit simpler. May be changed in the future.
|
||||||
*/
|
*/
|
||||||
DilloHtmlInputType inp_type;
|
DilloHtmlInputType inp_type;
|
||||||
char *type;
|
|
||||||
|
|
||||||
assert((html->InFlags & (IN_BUTTON | IN_SELECT | IN_TEXTAREA)) == 0);
|
assert((html->InFlags & (IN_BUTTON | IN_SELECT | IN_TEXTAREA)) == 0);
|
||||||
|
|
||||||
html->InFlags |= IN_BUTTON;
|
html->InFlags |= IN_BUTTON;
|
||||||
type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
|
auto type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
|
||||||
|
|
||||||
if (!dStrAsciiCasecmp(type, "button")) {
|
if (!dStrAsciiCasecmp(type.value().c_str(), "button")) {
|
||||||
inp_type = DILLO_HTML_INPUT_BUTTON;
|
inp_type = DILLO_HTML_INPUT_BUTTON;
|
||||||
} else if (!dStrAsciiCasecmp(type, "reset")) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "reset")) {
|
||||||
inp_type = DILLO_HTML_INPUT_BUTTON_RESET;
|
inp_type = DILLO_HTML_INPUT_BUTTON_RESET;
|
||||||
} else if (!dStrAsciiCasecmp(type, "submit") || !*type) {
|
} else if (!dStrAsciiCasecmp(type.value().c_str(), "submit") || type.value().empty()) {
|
||||||
/* submit button is the default */
|
/* submit button is the default */
|
||||||
inp_type = DILLO_HTML_INPUT_BUTTON_SUBMIT;
|
inp_type = DILLO_HTML_INPUT_BUTTON_SUBMIT;
|
||||||
} else {
|
} else {
|
||||||
inp_type = DILLO_HTML_INPUT_UNKNOWN;
|
inp_type = DILLO_HTML_INPUT_UNKNOWN;
|
||||||
BUG_MSG("<button> type unknown: '%s'.", type);
|
BUG_MSG("<button> type unknown: '%s'.", type.value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
|
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
|
||||||
/* Render the button */
|
/* Render the button */
|
||||||
Embed *embed;
|
Embed *embed;
|
||||||
const char *attrbuf;
|
const char *attrbuf;
|
||||||
char *name, *value;
|
|
||||||
|
|
||||||
if (prefs.show_tooltip &&
|
if (prefs.show_tooltip &&
|
||||||
(attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) {
|
(attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) {
|
||||||
@ -970,14 +961,11 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
|
|
||||||
S_TOP(html)->textblock = html->dw = page_p;
|
S_TOP(html)->textblock = html->dw = page_p;
|
||||||
|
|
||||||
value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
auto value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
|
||||||
name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
auto name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
|
||||||
|
|
||||||
Html_add_input(html, inp_type, embed, name, value, FALSE);
|
Html_add_input(html, inp_type, embed, name.value().c_str(), value.value().c_str(), FALSE);
|
||||||
dFree(name);
|
|
||||||
dFree(value);
|
|
||||||
}
|
}
|
||||||
dFree(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
60
src/html.cc
60
src/html.cc
@ -1045,7 +1045,6 @@ static const char *Html_parse_entity(DilloHtml *html, const char *token,
|
|||||||
int toksize, int *entsize, bool_t is_attr)
|
int toksize, int *entsize, bool_t is_attr)
|
||||||
{
|
{
|
||||||
const char *ret = NULL;
|
const char *ret = NULL;
|
||||||
char *tok;
|
|
||||||
|
|
||||||
if (toksize > 50) {
|
if (toksize > 50) {
|
||||||
/* In pathological cases, attributes can be megabytes long and filled
|
/* In pathological cases, attributes can be megabytes long and filled
|
||||||
@ -1056,18 +1055,18 @@ static const char *Html_parse_entity(DilloHtml *html, const char *token,
|
|||||||
}
|
}
|
||||||
|
|
||||||
token++;
|
token++;
|
||||||
tok = dStrndup(token, (uint_t)toksize);
|
std::string tok= token;
|
||||||
|
while( tok.size() > toksize ) tok.pop_back();
|
||||||
|
|
||||||
if (*tok == '#') {
|
if (tok.front() == '#') {
|
||||||
ret = Html_parse_numeric_charref(html, tok+1, is_attr, entsize);
|
ret = Html_parse_numeric_charref(html, tok.data()+1, is_attr, entsize);
|
||||||
} else if (isalpha(*tok)) {
|
} else if (isalpha(tok.front())) {
|
||||||
ret = Html_parse_named_charref(html, tok, is_attr, entsize);
|
ret = Html_parse_named_charref(html, tok.data(), is_attr, entsize);
|
||||||
} else if (prefs.show_extra_warnings &&
|
} else if (prefs.show_extra_warnings &&
|
||||||
(!(html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f))) {
|
(!(html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f))) {
|
||||||
// HTML5 doesn't mind literal '&'s.
|
// HTML5 doesn't mind literal '&'s.
|
||||||
BUG_MSG("Literal '&'.");
|
BUG_MSG("Literal '&'.");
|
||||||
}
|
}
|
||||||
dFree(tok);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2068,7 +2067,6 @@ static void Html_tag_open_abbr(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
*/
|
*/
|
||||||
void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
|
void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
|
||||||
{
|
{
|
||||||
char *width_ptr, *height_ptr;
|
|
||||||
const char *attrbuf;
|
const char *attrbuf;
|
||||||
CssLength l_w = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
|
CssLength l_w = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
|
||||||
CssLength l_h = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
|
CssLength l_h = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
|
||||||
@ -2079,17 +2077,17 @@ void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
html->styleEngine->setNonCssHint(PROPERTY_X_TOOLTIP, CSS_TYPE_STRING,
|
html->styleEngine->setNonCssHint(PROPERTY_X_TOOLTIP, CSS_TYPE_STRING,
|
||||||
attrbuf);
|
attrbuf);
|
||||||
}
|
}
|
||||||
width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL);
|
auto width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL);
|
||||||
height_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "height", NULL);
|
auto height_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "height", NULL);
|
||||||
// Check for malicious values
|
// Check for malicious values
|
||||||
// TODO: the same for percentage and relative lengths.
|
// TODO: the same for percentage and relative lengths.
|
||||||
if (width_ptr) {
|
if (width_ptr.has_value()) {
|
||||||
l_w = a_Html_parse_length (html, width_ptr);
|
l_w = a_Html_parse_length (html, width_ptr.value().c_str());
|
||||||
w = (int) (CSS_LENGTH_TYPE(l_w) == CSS_LENGTH_TYPE_PX ?
|
w = (int) (CSS_LENGTH_TYPE(l_w) == CSS_LENGTH_TYPE_PX ?
|
||||||
CSS_LENGTH_VALUE(l_w) : 0);
|
CSS_LENGTH_VALUE(l_w) : 0);
|
||||||
}
|
}
|
||||||
if (height_ptr) {
|
if (height_ptr.has_value()) {
|
||||||
l_h = a_Html_parse_length (html, height_ptr);
|
l_h = a_Html_parse_length (html, height_ptr.value().c_str());
|
||||||
h = (int) (CSS_LENGTH_TYPE(l_h) == CSS_LENGTH_TYPE_PX ?
|
h = (int) (CSS_LENGTH_TYPE(l_h) == CSS_LENGTH_TYPE_PX ?
|
||||||
CSS_LENGTH_VALUE(l_h) : 0);
|
CSS_LENGTH_VALUE(l_h) : 0);
|
||||||
}
|
}
|
||||||
@ -2105,9 +2103,7 @@ void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
if (w < 0 || h < 0 ||
|
if (w < 0 || h < 0 ||
|
||||||
w > IMAGE_MAX_AREA || h > IMAGE_MAX_AREA ||
|
w > IMAGE_MAX_AREA || h > IMAGE_MAX_AREA ||
|
||||||
(h > 0 && w > IMAGE_MAX_AREA / h)) {
|
(h > 0 && w > IMAGE_MAX_AREA / h)) {
|
||||||
dFree(width_ptr);
|
width_ptr = height_ptr = std::nullopt;
|
||||||
dFree(height_ptr);
|
|
||||||
width_ptr = height_ptr = NULL;
|
|
||||||
MSG("a_Html_common_image_attrs: suspicious image size request %d x %d\n",
|
MSG("a_Html_common_image_attrs: suspicious image size request %d x %d\n",
|
||||||
w, h);
|
w, h);
|
||||||
} else {
|
} else {
|
||||||
@ -2130,16 +2126,11 @@ void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
* We know a_Html_image_new() will use size() as its next index */
|
* We know a_Html_image_new() will use size() as its next index */
|
||||||
html->styleEngine->setNonCssHint (PROPERTY_X_IMG, CSS_TYPE_INTEGER,
|
html->styleEngine->setNonCssHint (PROPERTY_X_IMG, CSS_TYPE_INTEGER,
|
||||||
html->images->size());
|
html->images->size());
|
||||||
|
|
||||||
|
|
||||||
dFree(width_ptr);
|
|
||||||
dFree(height_ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
|
DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
|
||||||
{
|
{
|
||||||
bool load_now;
|
bool load_now;
|
||||||
char *alt_ptr;
|
|
||||||
const char *attrbuf;
|
const char *attrbuf;
|
||||||
DilloUrl *url;
|
DilloUrl *url;
|
||||||
DilloImage *image;
|
DilloImage *image;
|
||||||
@ -2148,13 +2139,12 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
!(url = a_Html_url_new(html, attrbuf, NULL, 0).release()))
|
!(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);
|
auto alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL);
|
||||||
if (!alt_ptr || !*alt_ptr) {
|
if (!alt_ptr.has_value() || alt_ptr.value().empty()) {
|
||||||
dFree(alt_ptr);
|
alt_ptr = "[IMG]";
|
||||||
alt_ptr = dStrdup("[IMG]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dw::Image *dw = new dw::Image(alt_ptr);
|
dw::Image *dw = new dw::Image(alt_ptr.value().c_str());
|
||||||
image =
|
image =
|
||||||
a_Image_new(html->dw->getLayout(), (void*)(dw::core::ImgRenderer*)dw, 0, 0);
|
a_Image_new(html->dw->getLayout(), (void*)(dw::core::ImgRenderer*)dw, 0, 0);
|
||||||
|
|
||||||
@ -2184,7 +2174,6 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
hi->image = image;
|
hi->image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
dFree(alt_ptr);
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2953,18 +2942,16 @@ static void Html_tag_close_li(DilloHtml *html)
|
|||||||
*/
|
*/
|
||||||
static void Html_tag_open_hr(DilloHtml *html, const char *tag, int tagsize)
|
static void Html_tag_open_hr(DilloHtml *html, const char *tag, int tagsize)
|
||||||
{
|
{
|
||||||
char *width_ptr;
|
|
||||||
const char *attrbuf;
|
const char *attrbuf;
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
|
|
||||||
width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL);
|
auto width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL);
|
||||||
if (width_ptr) {
|
if (width_ptr.has_value()) {
|
||||||
if (html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f)
|
if (html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f)
|
||||||
BUG_MSG("<hr> width attribute is obsolete.");
|
BUG_MSG("<hr> width attribute is obsolete.");
|
||||||
html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH,
|
html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH,
|
||||||
CSS_TYPE_LENGTH_PERCENTAGE,
|
CSS_TYPE_LENGTH_PERCENTAGE,
|
||||||
a_Html_parse_length (html, width_ptr));
|
a_Html_parse_length (html, width_ptr.value().c_str()));
|
||||||
dFree(width_ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) {
|
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) {
|
||||||
@ -4277,15 +4264,16 @@ const char *a_Html_get_attr(DilloHtml *html,
|
|||||||
* Call a_Html_get_attr() and dStrdup() the returned string.
|
* Call a_Html_get_attr() and dStrdup() the returned string.
|
||||||
* If the attribute isn't found a copy of 'def' is returned.
|
* If the attribute isn't found a copy of 'def' is returned.
|
||||||
*/
|
*/
|
||||||
char *a_Html_get_attr_wdef(DilloHtml *html,
|
std::optional< std::string > a_Html_get_attr_wdef(DilloHtml *html,
|
||||||
const char *tag,
|
const char *tag,
|
||||||
int tagsize,
|
int tagsize,
|
||||||
const char *attrname,
|
const char *attrname,
|
||||||
const char *def)
|
const char *def)
|
||||||
{
|
{
|
||||||
const char *attrbuf = a_Html_get_attr(html, tag, tagsize, attrname);
|
const char *attrbuf = a_Html_get_attr(html, tag, tagsize, attrname);
|
||||||
|
if( attrbuf ) return attrbuf;
|
||||||
return attrbuf ? dStrdup(attrbuf) : dStrdup(def);
|
if( def ) return def;
|
||||||
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "url.hh"
|
#include "url.hh"
|
||||||
#include "bw.hh"
|
#include "bw.hh"
|
||||||
@ -271,7 +272,7 @@ const char *a_Html_get_attr(DilloHtml *html,
|
|||||||
int tagsize,
|
int tagsize,
|
||||||
const char *attrname);
|
const char *attrname);
|
||||||
|
|
||||||
char *a_Html_get_attr_wdef(DilloHtml *html,
|
std::optional< std::string > a_Html_get_attr_wdef(DilloHtml *html,
|
||||||
const char *tag,
|
const char *tag,
|
||||||
int tagsize,
|
int tagsize,
|
||||||
const char *attrname,
|
const char *attrname,
|
||||||
|
|||||||
Reference in New Issue
Block a user