netsurf: branch master updated. release/3.8-23-g7a61c95
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/7a61c957243f8f4fe4d8b...
...commit http://git.netsurf-browser.org/netsurf.git/commit/7a61c957243f8f4fe4d8b89...
...tree http://git.netsurf-browser.org/netsurf.git/tree/7a61c957243f8f4fe4d8b89dc...
The branch, master has been updated
via 7a61c957243f8f4fe4d8b89dc19e90aa98e98a25 (commit)
from 5b849b1e22f21cf349bee3103af949f62b344d83 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=7a61c957243f8f4fe4d...
commit 7a61c957243f8f4fe4d8b89dc19e90aa98e98a25
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
rewrite form_successful_controls_dom as form_dom_to_data
Trying to reason about error propagation and resource leakage within
the form submission code was impossible because of the
form_successful_controls_dom function.
This function was over six hundred lines long, had twenty six top
level local variables and six levels of indent in places.
This commit splits it out into thirteen shorter and more obvious
functions. The resulting operation is identical except errors are
properly propagated (all failures were reported as out of memory)
and resource management can be reasoned about.
The compiler appears to inline the entirety of the code from
form_submit() down excepting a handful of leaf functions. This
results in similar code output size as previous implementation.
The new implementation has a greater number of variables passed to sub
functions than desirable because multiple character sets are required
to encode names and values in the multipart data list. However as
noted the compiler effectively inlines all these functions so this
does not actually become a major problem.
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index f779f07..5a915b8 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -326,622 +326,946 @@ bool form_add_option(struct form_control *control, char *value, char *text,
return true;
}
+/** string allocation size for numeric values in multipart data */
+#define FETCH_DATA_INT_VALUE_SIZE 20
/**
- * Identify 'successful' controls via the DOM.
+ * append split key name and integer value to a multipart data list
*
- * All text strings in the successful controls list will be in the charset most
- * appropriate for submission. Therefore, no utf8_to_* processing should be
- * performed upon them.
- *
- * \todo The chosen charset needs to be made available such that it can be
- * included in the submission request (e.g. in the fetch's Content-Type header)
- *
- * See HTML 4.01 section 17.13.2.
- *
- * \param[in] form form to search for successful controls
- * \param[in] submit_button control used to submit the form, if any
- * \param[out] successful_controls updated to point to linked list of
- * fetch_multipart_data, NULL if no controls
- * \return NSERROR_OK on success or appropriate error code
+ * \param name key name
+ * \param ksfx key name suffix
+ * \param value The value to encode
+ * \param fetch_data_next_ptr The multipart data list to append to.
*/
static nserror
-form_successful_controls_dom(struct form *_form,
- struct form_control *_submit_button,
- struct fetch_multipart_data **successful_controls)
+fetch_data_list_add_sname(const char *name,
+ const char *ksfx,
+ int value,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
{
- dom_html_form_element *form = _form->node;
- dom_html_element *submit_button = (_submit_button != NULL) ? _submit_button->node : NULL;
- dom_html_collection *form_elements = NULL;
- dom_html_options_collection *options = NULL;
- dom_node *form_element = NULL, *option_element = NULL;
- dom_exception err;
- dom_string *nodename = NULL, *inputname = NULL, *inputvalue = NULL, *inputtype = NULL;
- struct fetch_multipart_data sentinel, *last_success, *success_new;
- bool had_submit = false, element_disabled, checked;
- char *charset, *rawfile_temp = NULL, *basename;
- uint32_t index, element_count;
- struct image_input_coords *coords;
+ struct fetch_multipart_data *fetch_data;
+ int keysize;
- last_success = &sentinel;
- sentinel.next = NULL;
+ fetch_data = calloc(1, sizeof(*fetch_data));
+ if (fetch_data == NULL) {
+ NSLOG(netsurf, INFO, "failed allocation for fetch data");
+ return NSERROR_NOMEM;
+ }
- /** \todo Replace this call with something DOMish */
- charset = form_acceptable_charset(_form);
- if (charset == NULL) {
- NSLOG(netsurf, INFO, "failed to find charset");
+ /* key name */
+ keysize = snprintf(fetch_data->name, 0, "%s%s", name, ksfx);
+ fetch_data->name = malloc(keysize + 1); /* allow for null */
+ if (fetch_data->name == NULL) {
+ free(fetch_data);
+ NSLOG(netsurf, INFO,
+ "keyname allocation failure for %s%s", name, ksfx);
return NSERROR_NOMEM;
}
+ snprintf(fetch_data->name, keysize + 1, "%s%s", name, ksfx);
+
+ /* value */
+ fetch_data->value = malloc(FETCH_DATA_INT_VALUE_SIZE);
+ if (fetch_data->value == NULL) {
+ free(fetch_data->name);
+ free(fetch_data);
+ NSLOG(netsurf, INFO, "value allocation failure");
+ return NSERROR_NOMEM;
+ }
+ snprintf(fetch_data->value, FETCH_DATA_INT_VALUE_SIZE, "%d", value);
-#define ENCODE_ITEM(i) (((i) == NULL) ? ( \
- form_encode_item("", 0, charset, _form->document_charset) \
- ):( \
- form_encode_item(dom_string_data(i), dom_string_byte_length(i), \
- charset, _form->document_charset) \
- ))
+ /* link into list */
+ **fetch_data_next_ptr = fetch_data;
+ *fetch_data_next_ptr = &fetch_data->next;
- err = dom_html_form_element_get_elements(form, &form_elements);
+ return NSERROR_OK;
+}
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get form elements");
- goto dom_no_memory;
- }
+/**
+ * append DOM string name/value pair to a multipart data list
+ *
+ * \param name key name
+ * \param value the value to associate with the key
+ * \param rawfile the raw file value to associate with the key.
+ * \param form_charset The form character set
+ * \param docu_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+fetch_data_list_add(dom_string *name,
+ dom_string *value,
+ const char *rawfile,
+ const char *form_charset,
+ const char *docu_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ struct fetch_multipart_data *fetch_data;
- err = dom_html_collection_get_length(form_elements, &element_count);
+ assert(name != NULL);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get form element count");
- goto dom_no_memory;
+ fetch_data = calloc(1, sizeof(*fetch_data));
+ if (fetch_data == NULL) {
+ NSLOG(netsurf, INFO, "failed allocation for fetch data");
+ return NSERROR_NOMEM;
}
- for (index = 0; index < element_count; index++) {
- if (form_element != NULL) {
- dom_node_unref(form_element);
- form_element = NULL;
- }
- if (nodename != NULL) {
- dom_string_unref(nodename);
- nodename = NULL;
- }
- if (inputname != NULL) {
- dom_string_unref(inputname);
- inputname = NULL;
- }
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
- inputvalue = NULL;
- }
- if (inputtype != NULL) {
- dom_string_unref(inputtype);
- inputtype = NULL;
- }
- if (options != NULL) {
- dom_html_options_collection_unref(options);
- options = NULL;
- }
- err = dom_html_collection_item(form_elements,
- index, &form_element);
- if (err != DOM_NO_ERR) {
+ fetch_data->name = form_encode_item(dom_string_data(name),
+ dom_string_byte_length(name),
+ form_charset,
+ docu_charset);
+ if (fetch_data->name == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode name for fetch data");
+ free(fetch_data);
+ return NSERROR_NOMEM;
+ }
+
+ if (value == NULL) {
+ fetch_data->value = strdup("");
+ } else {
+ fetch_data->value = form_encode_item(dom_string_data(value),
+ dom_string_byte_length(value),
+ form_charset,
+ docu_charset);
+ }
+ if (fetch_data->value == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode value for fetch data");
+ free(fetch_data->name);
+ free(fetch_data);
+ return NSERROR_NOMEM;
+ }
+
+ /* deal with raw file name */
+ if (rawfile != NULL) {
+ fetch_data->file = true;
+ fetch_data->rawfile = strdup(rawfile);
+ if (fetch_data->rawfile == NULL) {
NSLOG(netsurf, INFO,
- "Could not retrieve form element %d", index);
- goto dom_no_memory;
+ "Could not encode rawfile value for fetch data");
+ free(fetch_data->value);
+ free(fetch_data->name);
+ free(fetch_data);
+ return NSERROR_NOMEM;
}
+ }
- /* Form elements are one of:
- * HTMLButtonElement
- * HTMLInputElement
- * HTMLTextAreaElement
- * HTMLSelectElement
- */
- err = dom_node_get_node_name(form_element, &nodename);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get node name");
- goto dom_no_memory;
- }
+ /* link into list */
+ **fetch_data_next_ptr = fetch_data;
+ *fetch_data_next_ptr = &fetch_data->next;
- if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
- err = dom_html_text_area_element_get_disabled(
- (dom_html_text_area_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area disabled property");
- goto dom_no_memory;
- }
- err = dom_html_text_area_element_get_name(
- (dom_html_text_area_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
- err = dom_html_select_element_get_disabled(
- (dom_html_select_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select disabled property");
- goto dom_no_memory;
- }
- err = dom_html_select_element_get_name(
- (dom_html_select_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
- err = dom_html_input_element_get_disabled(
- (dom_html_input_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input disabled property");
- goto dom_no_memory;
- }
- err = dom_html_input_element_get_name(
- (dom_html_input_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
- err = dom_html_button_element_get_disabled(
- (dom_html_button_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button disabled property");
- goto dom_no_memory;
- }
- err = dom_html_button_element_get_name(
- (dom_html_button_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button name property");
- goto dom_no_memory;
- }
- } else {
- /* Unknown element type came through! */
- NSLOG(netsurf, INFO, "Unknown element type: %*s",
- (int)dom_string_byte_length(nodename),
- dom_string_data(nodename));
- goto dom_no_memory;
- }
- if (element_disabled)
- continue;
- if (inputname == NULL)
- continue;
+ return NSERROR_OK;
+}
- if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
- err = dom_html_text_area_element_get_value(
- (dom_html_text_area_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area content");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
- uint32_t options_count, option_index;
- err = dom_html_select_element_get_options(
- (dom_html_select_element *)form_element,
- &options);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select options collection");
- goto dom_no_memory;
- }
- err = dom_html_options_collection_get_length(
- options, &options_count);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select options collection length");
- goto dom_no_memory;
- }
- for(option_index = 0; option_index < options_count;
- ++option_index) {
- bool selected;
- if (option_element != NULL) {
- dom_node_unref(option_element);
- option_element = NULL;
- }
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
- inputvalue = NULL;
- }
- err = dom_html_options_collection_item(
- options, option_index, &option_element);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get options item %d",
- option_index);
- goto dom_no_memory;
- }
- err = dom_html_option_element_get_selected(
- (dom_html_option_element *)option_element,
- &selected);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get option selected property");
- goto dom_no_memory;
- }
- if (!selected)
- continue;
- err = dom_html_option_element_get_value(
- (dom_html_option_element *)option_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get option value");
- goto dom_no_memory;
- }
+/**
+ * process form HTMLTextAreaElement into multipart data.
+ *
+ * \param text_area_element The form select DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_textarea(dom_html_text_area_element *text_area_element,
+ const char *form_charset,
+ const char *doc_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputvalue;
+ nserror res;
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- NSLOG(netsurf, INFO,
- "Could not allocate data for option");
- goto dom_no_memory;
- }
+ /* check if element is disabled */
+ exp = dom_html_text_area_element_get_disabled(text_area_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- last_success->next = success_new;
- last_success = success_new;
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
+ }
- success_new->name = ENCODE_ITEM(inputname);
- if (success_new->name == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode name for option");
- goto dom_no_memory;
- }
- success_new->value = ENCODE_ITEM(inputvalue);
- if (success_new->value == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode value for option");
- goto dom_no_memory;
- }
- }
- continue;
- } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
- err = dom_html_button_element_get_type(
- (dom_html_button_element *) form_element,
- &inputtype);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button element type");
- goto dom_no_memory;
- }
- if (dom_string_caseless_isequal(
- inputtype, corestring_dom_submit)) {
-
- if (submit_button == NULL && !had_submit) {
- /* no button used, and first submit
- * node found, so use it
- */
- had_submit = true;
- } else if ((dom_node *)submit_button !=
- (dom_node *)form_element) {
- continue;
- }
+ /* obtain name property */
+ exp = dom_html_text_area_element_get_name(text_area_element,
+ &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- err = dom_html_button_element_get_value(
- (dom_html_button_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get submit button value");
- goto dom_no_memory;
- }
- /* Drop through to report successful button */
- } else {
- continue;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
- /* Things to consider here */
- /* Buttons -- only if the successful control */
- /* radio and checkbox -- only if selected */
- /* file -- also get the rawfile */
- /* everything else -- just value */
- err = dom_html_input_element_get_type(
- (dom_html_input_element *) form_element,
- &inputtype);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element type");
- goto dom_no_memory;
- }
- if (dom_string_caseless_isequal(
- inputtype, corestring_dom_submit)) {
-
- if (submit_button == NULL && !had_submit) {
- /* no button used, and first submit
- * node found, so use it
- */
- had_submit = true;
- } else if ((dom_node *)submit_button !=
- (dom_node *)form_element) {
- continue;
- }
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get submit button value");
- goto dom_no_memory;
- }
- /* Drop through to report the successful button */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_image)) {
- /* We *ONLY* use an image input if it was the
- * thing which activated us
- */
- if ((dom_node *)submit_button !=
- (dom_node *)form_element)
- continue;
-
- err = dom_node_get_user_data(
- form_element,
- corestring_dom___ns_key_image_coords_node_data,
- &coords);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get image XY data");
- goto dom_no_memory;
- }
- if (coords == NULL) {
- NSLOG(netsurf, INFO,
- "No XY data on the image input");
- goto dom_no_memory;
- }
-
- basename = ENCODE_ITEM(inputname);
- if (basename == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode basename");
- goto dom_no_memory;
- }
-
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate data for image.x");
- goto dom_no_memory;
- }
-
- last_success->next = success_new;
- last_success = success_new;
-
- success_new->name = malloc(strlen(basename) + 3);
- if (success_new->name == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate name for image.x");
- goto dom_no_memory;
- }
- sprintf(success_new->name, "%s.x", basename);
-
- success_new->value = malloc(20);
- if (success_new->value == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate value for image.x");
- goto dom_no_memory;
- }
- sprintf(success_new->value, "%d", coords->x);
-
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate data for image.y");
- goto dom_no_memory;
- }
-
- last_success->next = success_new;
- last_success = success_new;
-
- success_new->name = malloc(strlen(basename) + 3);
- if (success_new->name == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate name for image.y");
- goto dom_no_memory;
- }
- success_new->value = malloc(20);
- if (success_new->value == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate value for image.y");
- goto dom_no_memory;
- }
- sprintf(success_new->name, "%s.y", basename);
- sprintf(success_new->value, "%d", coords->y);
- free(basename);
- continue;
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_radio) ||
- dom_string_caseless_isequal(
- inputtype, corestring_dom_checkbox)) {
- err = dom_html_input_element_get_checked(
- (dom_html_input_element *)form_element,
- &checked);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element checked");
- goto dom_no_memory;
- }
- if (!checked)
- continue;
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element value");
- goto dom_no_memory;
- }
- if (inputvalue == NULL) {
- inputvalue = dom_string_ref(
- corestring_dom_on);
- }
- /* Fall through to simple allocation */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_file)) {
-
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get file value");
- goto dom_no_memory;
- }
- err = dom_node_get_user_data(
- form_element,
- corestring_dom___ns_key_file_name_node_data,
- &rawfile_temp);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get file rawname");
- goto dom_no_memory;
- }
- rawfile_temp = strdup(rawfile_temp != NULL ?
- rawfile_temp :
- "");
- if (rawfile_temp == NULL) {
- NSLOG(netsurf, INFO,
- "Could not copy file rawname");
- goto dom_no_memory;
- }
- /* Fall out to the allocation */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_reset) ||
- dom_string_caseless_isequal(
- inputtype, corestring_dom_button)) {
- /* Skip these */
- NSLOG(netsurf, INFO,
- "Skipping RESET and BUTTON");
- continue;
- } else {
- /* Everything else is treated as text values */
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input value");
- goto dom_no_memory;
- }
- /* Fall out to the allocation */
- }
- }
+ /* obtain text area value */
+ exp = dom_html_text_area_element_get_value(text_area_element,
+ &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area content. exp %d", exp);
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- NSLOG(netsurf, INFO,
- "Could not allocate data for generic");
- goto dom_no_memory;
- }
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
- last_success->next = success_new;
- last_success = success_new;
+ dom_string_unref(inputvalue);
+ dom_string_unref(inputname);
- success_new->name = ENCODE_ITEM(inputname);
- if (success_new->name == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode name for generic");
- goto dom_no_memory;
- }
- success_new->value = ENCODE_ITEM(inputvalue);
- if (success_new->value == NULL) {
+ return res;
+}
+
+static nserror
+form_dom_to_data_select_option(dom_html_option_element *option_element,
+ dom_string *keyname,
+ const char *form_charset,
+ const char *docu_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *value;
+ bool selected;
+
+ exp = dom_html_option_element_get_selected(option_element, &selected);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get option selected property");
+ return NSERROR_DOM;
+ }
+
+ if (!selected) {
+ /* unselected options do not add fetch data entries */
+ return NSERROR_OK;
+ }
+
+ exp = dom_html_option_element_get_value(option_element, &value);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get option value");
+ return NSERROR_DOM;
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(keyname,
+ value,
+ NULL,
+ form_charset,
+ docu_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(value);
+
+ return res;
+}
+
+/**
+ * process form HTMLSelectElement into multipart data.
+ *
+ * \param select_element The form select DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_select(dom_html_select_element *select_element,
+ const char *form_charset,
+ const char *doc_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res = NSERROR_OK;
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_html_options_collection *options = NULL;
+ uint32_t options_count;
+ uint32_t option_index;
+ dom_node *option_element = NULL;
+
+ /* check if element is disabled */
+ exp = dom_html_select_element_get_disabled(select_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
+ }
+
+ /* obtain name property */
+ exp = dom_html_select_element_get_name(select_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
+
+ /* get options collection */
+ exp = dom_html_select_element_get_options(select_element, &options);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select options collection");
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
+
+ /* get options collection length */
+ exp = dom_html_options_collection_get_length(options, &options_count);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select options collection length");
+ dom_html_options_collection_unref(options);
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
+
+ /* iterate over options collection */
+ for (option_index = 0; option_index < options_count; ++option_index) {
+ exp = dom_html_options_collection_item(options,
+ option_index,
+ &option_element);
+ if (exp != DOM_NO_ERR) {
NSLOG(netsurf, INFO,
- "Could not encode value for generic");
- goto dom_no_memory;
+ "Could not get options item %d", option_index);
+ res = NSERROR_DOM;
+ } else {
+ res = form_dom_to_data_select_option(
+ (dom_html_option_element *)option_element,
+ inputname,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
+
+ dom_node_unref(option_element);
}
- if (rawfile_temp != NULL) {
- success_new->file = true;
- success_new->rawfile = rawfile_temp;
- rawfile_temp = NULL;
+
+ if (res != NSERROR_OK) {
+ break;
}
}
- free(charset);
+ dom_html_options_collection_unref(options);
+ dom_string_unref(inputname);
+
+ return res;
+}
- if (form_element != NULL) {
- dom_node_unref(form_element);
+static nserror
+form_dom_to_data_input_submit(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+ nserror res;
+
+ if (*submit_button == NULL) {
+ /* caller specified no button so use this one */
+ *submit_button = (dom_html_element *)input_element;
+ } else if (*submit_button != (dom_html_element *)input_element) {
+ return NSERROR_OK;
}
- if (form_elements != NULL) {
- dom_html_collection_unref(form_elements);
+ /* matched button used to submit form */
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get submit button value");
+ return NSERROR_DOM;
}
- if (nodename != NULL) {
- dom_string_unref(nodename);
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+
+
+static nserror
+form_dom_to_data_input_image(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ struct image_input_coords *coords;
+ char *basename;
+
+ /* Only use an image input if it was the thing which activated us */
+ if (*submit_button != (dom_html_element *)input_element) {
+ return NSERROR_OK;
+ }
+
+ exp = dom_node_get_user_data((dom_node *)input_element,
+ corestring_dom___ns_key_image_coords_node_data,
+ &coords);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get image XY data");
+ return NSERROR_DOM;
+ }
+
+ if (coords == NULL) {
+ NSLOG(netsurf, INFO, "No XY data on the image input");
+ return NSERROR_DOM;
+ }
+
+ /* encode input name once */
+ basename = form_encode_item(dom_string_data(inputname),
+ dom_string_byte_length(inputname),
+ charset,
+ document_charset);
+ if (basename == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode basename");
+ return NSERROR_NOMEM;
+ }
+
+ res = fetch_data_list_add_sname(basename, ".x",
+ coords->x,
+ fetch_data_next_ptr);
+
+ if (res == NSERROR_OK) {
+ res = fetch_data_list_add_sname(basename, ".y",
+ coords->y,
+ fetch_data_next_ptr);
+ }
+
+ free(basename);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_checkbox(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ bool checked;
+ dom_string *inputvalue;
+
+ exp = dom_html_input_element_get_checked(input_element, &checked);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input element checked");
+ return NSERROR_DOM;
+ }
+
+ if (!checked) {
+ /* unchecked items do not generate a data entry */
+ return NSERROR_OK;
+ }
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input element value");
+ return NSERROR_DOM;
+ }
+
+ /* ensure a default value */
+ if (inputvalue == NULL) {
+ inputvalue = dom_string_ref(corestring_dom_on);
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_file(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+ const char *rawfile = NULL;
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get file value");
+ return NSERROR_DOM;
+ }
+
+ exp = dom_node_get_user_data((dom_node *)input_element,
+ corestring_dom___ns_key_file_name_node_data,
+ &rawfile);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get file rawname");
+ return NSERROR_DOM;
}
- if (inputname != NULL) {
+ if (rawfile == NULL) {
+ rawfile = "";
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ rawfile,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_text(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get input value");
+ return NSERROR_DOM;
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+/**
+ * process form input element into multipart data.
+ *
+ * \param input_element The form input DOM element to convert.
+ * \param charset The form character set
+ * \param document_charset The document character set for fallback
+ * \param submit_button The DOM element of the button submitting the form
+ * \param had_submit A boolean value indicating if the submit button
+ * has already been processed in the form element enumeration.
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_input(dom_html_input_element *input_element,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputtype;
+ nserror res;
+
+ /* check if element is disabled */
+ exp = dom_html_input_element_get_disabled(input_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* disabled element requires no more processing */
+ return NSERROR_OK;
+ }
+
+ /* obtain name property */
+ exp = dom_html_input_element_get_name(input_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (inputname == NULL) {
+ /* element with no name is not converted */
+ return NSERROR_OK;
+ }
+
+ /* get input type */
+ exp = dom_html_input_element_get_type(input_element, &inputtype);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get input element type");
dom_string_unref(inputname);
+ return NSERROR_DOM;
}
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
+ /* process according to input element type */
+ if (dom_string_caseless_isequal(inputtype, corestring_dom_submit)) {
+
+ res = form_dom_to_data_input_submit(input_element,
+ inputname,
+ charset,
+ document_charset,
+ submit_button,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_image)) {
+
+ res = form_dom_to_data_input_image(input_element,
+ inputname,
+ charset,
+ document_charset,
+ submit_button,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_radio) ||
+ dom_string_caseless_isequal(inputtype,
+ corestring_dom_checkbox)) {
+
+ res = form_dom_to_data_input_checkbox(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_file)) {
+
+ res = form_dom_to_data_input_file(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_reset) ||
+ dom_string_caseless_isequal(inputtype,
+ corestring_dom_button)) {
+ /* Skip these */
+ NSLOG(netsurf, INFO, "Skipping RESET and BUTTON");
+ res = NSERROR_OK;
+
+ } else {
+ /* Everything else is treated as text values */
+ res = form_dom_to_data_input_text(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
}
- if (options != NULL) {
- dom_html_options_collection_unref(options);
+ dom_string_unref(inputtype);
+ dom_string_unref(inputname);
+
+ return res;
+}
+
+/**
+ * process form HTMLButtonElement into multipart data.
+ *
+ * \param button_element The form button DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param submit_button The DOM element of the button submitting the form
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_button(dom_html_button_element *button_element,
+ const char *form_charset,
+ const char *doc_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputvalue;
+ dom_string *inputtype;
+ nserror res = NSERROR_OK;
+
+ /* check if element is disabled */
+ exp = dom_html_button_element_get_disabled(button_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Unabe to get disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
}
- if (option_element != NULL) {
- dom_node_unref(option_element);
+ /* only submit buttons can cause data elements */
+ exp = dom_html_button_element_get_type(button_element, &inputtype);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get button element type");
+ return NSERROR_DOM;
}
- if (inputtype != NULL) {
+ if (!dom_string_caseless_isequal(inputtype, corestring_dom_submit)) {
+ /* multipart data entry not required for non submit buttons */
dom_string_unref(inputtype);
+ return NSERROR_OK;
}
+ dom_string_unref(inputtype);
- if (rawfile_temp != NULL) {
- free(rawfile_temp);
+ /* only submision button generates an element */
+ if (*submit_button == NULL) {
+ /* no submission button selected yet so use this one */
+ *submit_button = (dom_html_element *)button_element;
+ }
+ if (*submit_button != (dom_html_element *)button_element) {
+ return NSERROR_OK;
}
- *successful_controls = sentinel.next;
+ /* obtain name property */
+ exp = dom_html_button_element_get_name(button_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get button name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- return NSERROR_OK;
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
-dom_no_memory:
- free(charset);
- fetch_multipart_data_destroy(sentinel.next);
+ /* get button value and add to fetch data list */
+ exp = dom_html_button_element_get_value(button_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get submit button value");
+ res = NSERROR_DOM;
+ } else {
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
- if (form_elements != NULL)
- dom_html_collection_unref(form_elements);
- if (form_element != NULL)
- dom_node_unref(form_element);
- if (nodename != NULL)
- dom_string_unref(nodename);
- if (inputname != NULL)
- dom_string_unref(inputname);
- if (inputvalue != NULL)
dom_string_unref(inputvalue);
- if (options != NULL)
- dom_html_options_collection_unref(options);
- if (option_element != NULL)
- dom_node_unref(option_element);
- if (inputtype != NULL)
- dom_string_unref(inputtype);
- if (rawfile_temp != NULL)
- free(rawfile_temp);
+ }
+
+ dom_string_unref(inputname);
+
+ return res;
+}
+
- return NSERROR_NOMEM;
+/**
+ * Construct multipart data list from 'successful' controls via the DOM.
+ *
+ * All text strings in the successful controls list will be in the charset most
+ * appropriate for submission. Therefore, no utf8_to_* processing should be
+ * performed upon them.
+ *
+ * \todo The chosen charset needs to be made available such that it can be
+ * included in the submission request (e.g. in the fetch's Content-Type header)
+ *
+ * See HTML 4.01 section 17.13.2.
+ *
+ * \note care is taken to abort even if the error is recoverable as it
+ * is not desirable to submit incomplete form data.
+ *
+ * \param[in] form form to search for successful controls
+ * \param[in] submit_button control used to submit the form, if any
+ * \param[out] fetch_data_out updated to point to linked list of
+ * fetch_multipart_data, NULL if no controls
+ * \return NSERROR_OK on success or appropriate error code
+ */
+static nserror
+form_dom_to_data(struct form *form,
+ struct form_control *submit_control,
+ struct fetch_multipart_data **fetch_data_out)
+{
+ nserror res = NSERROR_OK;
+ char *charset; /* form characterset */
+ dom_exception exp; /* the result from DOM operations */
+ dom_html_collection *elements = NULL; /* the dom form elements */
+ uint32_t element_count; /* the number of elements in the DOM form */
+ uint32_t element_idx; /* the index of thr enumerated element */
+ dom_node *element = NULL; /* the DOM form element */
+ dom_string *nodename = NULL; /* the DOM node name of the element */
+ struct fetch_multipart_data *fetch_data = NULL; /* fetch data list */
+ struct fetch_multipart_data **fetch_data_next = &fetch_data;
+ dom_html_element *submit_button;
+
+ /* obtain the submit_button DOM node from the control */
+ if (submit_control != NULL) {
+ submit_button = submit_control->node;
+ } else {
+ submit_button = NULL;
+ }
+
+ /** \todo Replace this call with something DOMish */
+ charset = form_acceptable_charset(form);
+ if (charset == NULL) {
+ NSLOG(netsurf, INFO, "failed to find charset");
+ return NSERROR_NOMEM;
+ }
+
+ /* obtain the form elements and count */
+ exp = dom_html_form_element_get_elements(form->node, &elements);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get form elements");
+ free(charset);
+ return NSERROR_DOM;
+ }
+
+ exp = dom_html_collection_get_length(elements, &element_count);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get form element count");
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ for (element_idx = 0; element_idx < element_count; element_idx++) {
+ /* obtain a form element */
+ exp = dom_html_collection_item(elements, element_idx, &element);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "retrieving form element %d failed with %d",
+ element_idx, exp);
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ /* node name from element */
+ exp = dom_node_get_node_name(element, &nodename);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "getting element node name %d failed with %d",
+ element_idx, exp);
+ dom_node_unref(element);
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
+ /* Form element is HTMLTextAreaElement */
+ res = form_dom_to_data_textarea(
+ (dom_html_text_area_element *)element,
+ charset,
+ form->document_charset,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
+ /* Form element is HTMLSelectElement */
+ res = form_dom_to_data_select(
+ (dom_html_select_element *)element,
+ charset,
+ form->document_charset,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
+ /* Form element is HTMLInputElement */
+ res = form_dom_to_data_input(
+ (dom_html_input_element *)element,
+ charset,
+ form->document_charset,
+ &submit_button,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
+ /* Form element is HTMLButtonElement */
+ res = form_dom_to_data_button(
+ (dom_html_button_element *)element,
+ charset,
+ form->document_charset,
+ &submit_button,
+ &fetch_data_next);
+
+ } else {
+ /* Form element is not handled */
+ NSLOG(netsurf, INFO,
+ "Unhandled element type: %*s",
+ (int)dom_string_byte_length(nodename),
+ dom_string_data(nodename));
+ res = NSERROR_DOM;
+
+ }
+
+ dom_string_unref(nodename);
+ dom_node_unref(element);
+
+ /* abort form element enumeration on error */
+ if (res != NSERROR_OK) {
+ goto form_dom_to_data_error;
+ }
+ }
+
+ *fetch_data_out = fetch_data;
+ dom_html_collection_unref(elements);
+ free(charset);
+
+ return NSERROR_OK;
+
+form_dom_to_data_error:
+ fetch_multipart_data_destroy(fetch_data);
+ dom_html_collection_unref(elements);
+ free(charset);
+
+ return res;
}
-#undef ENCODE_ITEM
/**
* Encode controls using application/x-www-form-urlencoded.
@@ -1087,8 +1411,11 @@ char *form_acceptable_charset(struct form *form)
* used iff converting to charset fails
* \return Pointer to converted string (on heap, caller frees), or NULL
*/
-char *form_encode_item(const char *item, uint32_t len, const char *charset,
- const char *fallback)
+char *
+form_encode_item(const char *item,
+ uint32_t len,
+ const char *charset,
+ const char *fallback)
{
nserror err;
char *ret = NULL;
@@ -1797,7 +2124,7 @@ form_submit(nsurl *page_url,
assert(form != NULL);
/* obtain list of controls from DOM */
- res = form_successful_controls_dom(form, submit_button, &success);
+ res = form_dom_to_data(form, submit_button, &success);
if (res != NSERROR_OK) {
return res;
}
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/form.c | 1439 ++++++++++++++++++++++++++----------------
1 file changed, 883 insertions(+), 556 deletions(-)
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index f779f07..5a915b8 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -326,622 +326,946 @@ bool form_add_option(struct form_control *control, char *value, char *text,
return true;
}
+/** string allocation size for numeric values in multipart data */
+#define FETCH_DATA_INT_VALUE_SIZE 20
/**
- * Identify 'successful' controls via the DOM.
+ * append split key name and integer value to a multipart data list
*
- * All text strings in the successful controls list will be in the charset most
- * appropriate for submission. Therefore, no utf8_to_* processing should be
- * performed upon them.
- *
- * \todo The chosen charset needs to be made available such that it can be
- * included in the submission request (e.g. in the fetch's Content-Type header)
- *
- * See HTML 4.01 section 17.13.2.
- *
- * \param[in] form form to search for successful controls
- * \param[in] submit_button control used to submit the form, if any
- * \param[out] successful_controls updated to point to linked list of
- * fetch_multipart_data, NULL if no controls
- * \return NSERROR_OK on success or appropriate error code
+ * \param name key name
+ * \param ksfx key name suffix
+ * \param value The value to encode
+ * \param fetch_data_next_ptr The multipart data list to append to.
*/
static nserror
-form_successful_controls_dom(struct form *_form,
- struct form_control *_submit_button,
- struct fetch_multipart_data **successful_controls)
+fetch_data_list_add_sname(const char *name,
+ const char *ksfx,
+ int value,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
{
- dom_html_form_element *form = _form->node;
- dom_html_element *submit_button = (_submit_button != NULL) ? _submit_button->node : NULL;
- dom_html_collection *form_elements = NULL;
- dom_html_options_collection *options = NULL;
- dom_node *form_element = NULL, *option_element = NULL;
- dom_exception err;
- dom_string *nodename = NULL, *inputname = NULL, *inputvalue = NULL, *inputtype = NULL;
- struct fetch_multipart_data sentinel, *last_success, *success_new;
- bool had_submit = false, element_disabled, checked;
- char *charset, *rawfile_temp = NULL, *basename;
- uint32_t index, element_count;
- struct image_input_coords *coords;
+ struct fetch_multipart_data *fetch_data;
+ int keysize;
- last_success = &sentinel;
- sentinel.next = NULL;
+ fetch_data = calloc(1, sizeof(*fetch_data));
+ if (fetch_data == NULL) {
+ NSLOG(netsurf, INFO, "failed allocation for fetch data");
+ return NSERROR_NOMEM;
+ }
- /** \todo Replace this call with something DOMish */
- charset = form_acceptable_charset(_form);
- if (charset == NULL) {
- NSLOG(netsurf, INFO, "failed to find charset");
+ /* key name */
+ keysize = snprintf(fetch_data->name, 0, "%s%s", name, ksfx);
+ fetch_data->name = malloc(keysize + 1); /* allow for null */
+ if (fetch_data->name == NULL) {
+ free(fetch_data);
+ NSLOG(netsurf, INFO,
+ "keyname allocation failure for %s%s", name, ksfx);
return NSERROR_NOMEM;
}
+ snprintf(fetch_data->name, keysize + 1, "%s%s", name, ksfx);
+
+ /* value */
+ fetch_data->value = malloc(FETCH_DATA_INT_VALUE_SIZE);
+ if (fetch_data->value == NULL) {
+ free(fetch_data->name);
+ free(fetch_data);
+ NSLOG(netsurf, INFO, "value allocation failure");
+ return NSERROR_NOMEM;
+ }
+ snprintf(fetch_data->value, FETCH_DATA_INT_VALUE_SIZE, "%d", value);
-#define ENCODE_ITEM(i) (((i) == NULL) ? ( \
- form_encode_item("", 0, charset, _form->document_charset) \
- ):( \
- form_encode_item(dom_string_data(i), dom_string_byte_length(i), \
- charset, _form->document_charset) \
- ))
+ /* link into list */
+ **fetch_data_next_ptr = fetch_data;
+ *fetch_data_next_ptr = &fetch_data->next;
- err = dom_html_form_element_get_elements(form, &form_elements);
+ return NSERROR_OK;
+}
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get form elements");
- goto dom_no_memory;
- }
+/**
+ * append DOM string name/value pair to a multipart data list
+ *
+ * \param name key name
+ * \param value the value to associate with the key
+ * \param rawfile the raw file value to associate with the key.
+ * \param form_charset The form character set
+ * \param docu_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+fetch_data_list_add(dom_string *name,
+ dom_string *value,
+ const char *rawfile,
+ const char *form_charset,
+ const char *docu_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ struct fetch_multipart_data *fetch_data;
- err = dom_html_collection_get_length(form_elements, &element_count);
+ assert(name != NULL);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get form element count");
- goto dom_no_memory;
+ fetch_data = calloc(1, sizeof(*fetch_data));
+ if (fetch_data == NULL) {
+ NSLOG(netsurf, INFO, "failed allocation for fetch data");
+ return NSERROR_NOMEM;
}
- for (index = 0; index < element_count; index++) {
- if (form_element != NULL) {
- dom_node_unref(form_element);
- form_element = NULL;
- }
- if (nodename != NULL) {
- dom_string_unref(nodename);
- nodename = NULL;
- }
- if (inputname != NULL) {
- dom_string_unref(inputname);
- inputname = NULL;
- }
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
- inputvalue = NULL;
- }
- if (inputtype != NULL) {
- dom_string_unref(inputtype);
- inputtype = NULL;
- }
- if (options != NULL) {
- dom_html_options_collection_unref(options);
- options = NULL;
- }
- err = dom_html_collection_item(form_elements,
- index, &form_element);
- if (err != DOM_NO_ERR) {
+ fetch_data->name = form_encode_item(dom_string_data(name),
+ dom_string_byte_length(name),
+ form_charset,
+ docu_charset);
+ if (fetch_data->name == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode name for fetch data");
+ free(fetch_data);
+ return NSERROR_NOMEM;
+ }
+
+ if (value == NULL) {
+ fetch_data->value = strdup("");
+ } else {
+ fetch_data->value = form_encode_item(dom_string_data(value),
+ dom_string_byte_length(value),
+ form_charset,
+ docu_charset);
+ }
+ if (fetch_data->value == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode value for fetch data");
+ free(fetch_data->name);
+ free(fetch_data);
+ return NSERROR_NOMEM;
+ }
+
+ /* deal with raw file name */
+ if (rawfile != NULL) {
+ fetch_data->file = true;
+ fetch_data->rawfile = strdup(rawfile);
+ if (fetch_data->rawfile == NULL) {
NSLOG(netsurf, INFO,
- "Could not retrieve form element %d", index);
- goto dom_no_memory;
+ "Could not encode rawfile value for fetch data");
+ free(fetch_data->value);
+ free(fetch_data->name);
+ free(fetch_data);
+ return NSERROR_NOMEM;
}
+ }
- /* Form elements are one of:
- * HTMLButtonElement
- * HTMLInputElement
- * HTMLTextAreaElement
- * HTMLSelectElement
- */
- err = dom_node_get_node_name(form_element, &nodename);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO, "Could not get node name");
- goto dom_no_memory;
- }
+ /* link into list */
+ **fetch_data_next_ptr = fetch_data;
+ *fetch_data_next_ptr = &fetch_data->next;
- if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
- err = dom_html_text_area_element_get_disabled(
- (dom_html_text_area_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area disabled property");
- goto dom_no_memory;
- }
- err = dom_html_text_area_element_get_name(
- (dom_html_text_area_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
- err = dom_html_select_element_get_disabled(
- (dom_html_select_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select disabled property");
- goto dom_no_memory;
- }
- err = dom_html_select_element_get_name(
- (dom_html_select_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
- err = dom_html_input_element_get_disabled(
- (dom_html_input_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input disabled property");
- goto dom_no_memory;
- }
- err = dom_html_input_element_get_name(
- (dom_html_input_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input name property");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
- err = dom_html_button_element_get_disabled(
- (dom_html_button_element *)form_element,
- &element_disabled);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button disabled property");
- goto dom_no_memory;
- }
- err = dom_html_button_element_get_name(
- (dom_html_button_element *)form_element,
- &inputname);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button name property");
- goto dom_no_memory;
- }
- } else {
- /* Unknown element type came through! */
- NSLOG(netsurf, INFO, "Unknown element type: %*s",
- (int)dom_string_byte_length(nodename),
- dom_string_data(nodename));
- goto dom_no_memory;
- }
- if (element_disabled)
- continue;
- if (inputname == NULL)
- continue;
+ return NSERROR_OK;
+}
- if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
- err = dom_html_text_area_element_get_value(
- (dom_html_text_area_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get text area content");
- goto dom_no_memory;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
- uint32_t options_count, option_index;
- err = dom_html_select_element_get_options(
- (dom_html_select_element *)form_element,
- &options);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select options collection");
- goto dom_no_memory;
- }
- err = dom_html_options_collection_get_length(
- options, &options_count);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get select options collection length");
- goto dom_no_memory;
- }
- for(option_index = 0; option_index < options_count;
- ++option_index) {
- bool selected;
- if (option_element != NULL) {
- dom_node_unref(option_element);
- option_element = NULL;
- }
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
- inputvalue = NULL;
- }
- err = dom_html_options_collection_item(
- options, option_index, &option_element);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get options item %d",
- option_index);
- goto dom_no_memory;
- }
- err = dom_html_option_element_get_selected(
- (dom_html_option_element *)option_element,
- &selected);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get option selected property");
- goto dom_no_memory;
- }
- if (!selected)
- continue;
- err = dom_html_option_element_get_value(
- (dom_html_option_element *)option_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get option value");
- goto dom_no_memory;
- }
+/**
+ * process form HTMLTextAreaElement into multipart data.
+ *
+ * \param text_area_element The form select DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_textarea(dom_html_text_area_element *text_area_element,
+ const char *form_charset,
+ const char *doc_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputvalue;
+ nserror res;
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- NSLOG(netsurf, INFO,
- "Could not allocate data for option");
- goto dom_no_memory;
- }
+ /* check if element is disabled */
+ exp = dom_html_text_area_element_get_disabled(text_area_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- last_success->next = success_new;
- last_success = success_new;
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
+ }
- success_new->name = ENCODE_ITEM(inputname);
- if (success_new->name == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode name for option");
- goto dom_no_memory;
- }
- success_new->value = ENCODE_ITEM(inputvalue);
- if (success_new->value == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode value for option");
- goto dom_no_memory;
- }
- }
- continue;
- } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
- err = dom_html_button_element_get_type(
- (dom_html_button_element *) form_element,
- &inputtype);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get button element type");
- goto dom_no_memory;
- }
- if (dom_string_caseless_isequal(
- inputtype, corestring_dom_submit)) {
-
- if (submit_button == NULL && !had_submit) {
- /* no button used, and first submit
- * node found, so use it
- */
- had_submit = true;
- } else if ((dom_node *)submit_button !=
- (dom_node *)form_element) {
- continue;
- }
+ /* obtain name property */
+ exp = dom_html_text_area_element_get_name(text_area_element,
+ &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- err = dom_html_button_element_get_value(
- (dom_html_button_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get submit button value");
- goto dom_no_memory;
- }
- /* Drop through to report successful button */
- } else {
- continue;
- }
- } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
- /* Things to consider here */
- /* Buttons -- only if the successful control */
- /* radio and checkbox -- only if selected */
- /* file -- also get the rawfile */
- /* everything else -- just value */
- err = dom_html_input_element_get_type(
- (dom_html_input_element *) form_element,
- &inputtype);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element type");
- goto dom_no_memory;
- }
- if (dom_string_caseless_isequal(
- inputtype, corestring_dom_submit)) {
-
- if (submit_button == NULL && !had_submit) {
- /* no button used, and first submit
- * node found, so use it
- */
- had_submit = true;
- } else if ((dom_node *)submit_button !=
- (dom_node *)form_element) {
- continue;
- }
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get submit button value");
- goto dom_no_memory;
- }
- /* Drop through to report the successful button */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_image)) {
- /* We *ONLY* use an image input if it was the
- * thing which activated us
- */
- if ((dom_node *)submit_button !=
- (dom_node *)form_element)
- continue;
-
- err = dom_node_get_user_data(
- form_element,
- corestring_dom___ns_key_image_coords_node_data,
- &coords);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get image XY data");
- goto dom_no_memory;
- }
- if (coords == NULL) {
- NSLOG(netsurf, INFO,
- "No XY data on the image input");
- goto dom_no_memory;
- }
-
- basename = ENCODE_ITEM(inputname);
- if (basename == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode basename");
- goto dom_no_memory;
- }
-
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate data for image.x");
- goto dom_no_memory;
- }
-
- last_success->next = success_new;
- last_success = success_new;
-
- success_new->name = malloc(strlen(basename) + 3);
- if (success_new->name == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate name for image.x");
- goto dom_no_memory;
- }
- sprintf(success_new->name, "%s.x", basename);
-
- success_new->value = malloc(20);
- if (success_new->value == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate value for image.x");
- goto dom_no_memory;
- }
- sprintf(success_new->value, "%d", coords->x);
-
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate data for image.y");
- goto dom_no_memory;
- }
-
- last_success->next = success_new;
- last_success = success_new;
-
- success_new->name = malloc(strlen(basename) + 3);
- if (success_new->name == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate name for image.y");
- goto dom_no_memory;
- }
- success_new->value = malloc(20);
- if (success_new->value == NULL) {
- free(basename);
- NSLOG(netsurf, INFO,
- "Could not allocate value for image.y");
- goto dom_no_memory;
- }
- sprintf(success_new->name, "%s.y", basename);
- sprintf(success_new->value, "%d", coords->y);
- free(basename);
- continue;
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_radio) ||
- dom_string_caseless_isequal(
- inputtype, corestring_dom_checkbox)) {
- err = dom_html_input_element_get_checked(
- (dom_html_input_element *)form_element,
- &checked);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element checked");
- goto dom_no_memory;
- }
- if (!checked)
- continue;
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input element value");
- goto dom_no_memory;
- }
- if (inputvalue == NULL) {
- inputvalue = dom_string_ref(
- corestring_dom_on);
- }
- /* Fall through to simple allocation */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_file)) {
-
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get file value");
- goto dom_no_memory;
- }
- err = dom_node_get_user_data(
- form_element,
- corestring_dom___ns_key_file_name_node_data,
- &rawfile_temp);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get file rawname");
- goto dom_no_memory;
- }
- rawfile_temp = strdup(rawfile_temp != NULL ?
- rawfile_temp :
- "");
- if (rawfile_temp == NULL) {
- NSLOG(netsurf, INFO,
- "Could not copy file rawname");
- goto dom_no_memory;
- }
- /* Fall out to the allocation */
- } else if (dom_string_caseless_isequal(
- inputtype, corestring_dom_reset) ||
- dom_string_caseless_isequal(
- inputtype, corestring_dom_button)) {
- /* Skip these */
- NSLOG(netsurf, INFO,
- "Skipping RESET and BUTTON");
- continue;
- } else {
- /* Everything else is treated as text values */
- err = dom_html_input_element_get_value(
- (dom_html_input_element *)form_element,
- &inputvalue);
- if (err != DOM_NO_ERR) {
- NSLOG(netsurf, INFO,
- "Could not get input value");
- goto dom_no_memory;
- }
- /* Fall out to the allocation */
- }
- }
+ /* obtain text area value */
+ exp = dom_html_text_area_element_get_value(text_area_element,
+ &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get text area content. exp %d", exp);
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
- success_new = calloc(1, sizeof(*success_new));
- if (success_new == NULL) {
- NSLOG(netsurf, INFO,
- "Could not allocate data for generic");
- goto dom_no_memory;
- }
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
- last_success->next = success_new;
- last_success = success_new;
+ dom_string_unref(inputvalue);
+ dom_string_unref(inputname);
- success_new->name = ENCODE_ITEM(inputname);
- if (success_new->name == NULL) {
- NSLOG(netsurf, INFO,
- "Could not encode name for generic");
- goto dom_no_memory;
- }
- success_new->value = ENCODE_ITEM(inputvalue);
- if (success_new->value == NULL) {
+ return res;
+}
+
+static nserror
+form_dom_to_data_select_option(dom_html_option_element *option_element,
+ dom_string *keyname,
+ const char *form_charset,
+ const char *docu_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *value;
+ bool selected;
+
+ exp = dom_html_option_element_get_selected(option_element, &selected);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get option selected property");
+ return NSERROR_DOM;
+ }
+
+ if (!selected) {
+ /* unselected options do not add fetch data entries */
+ return NSERROR_OK;
+ }
+
+ exp = dom_html_option_element_get_value(option_element, &value);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get option value");
+ return NSERROR_DOM;
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(keyname,
+ value,
+ NULL,
+ form_charset,
+ docu_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(value);
+
+ return res;
+}
+
+/**
+ * process form HTMLSelectElement into multipart data.
+ *
+ * \param select_element The form select DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_select(dom_html_select_element *select_element,
+ const char *form_charset,
+ const char *doc_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res = NSERROR_OK;
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_html_options_collection *options = NULL;
+ uint32_t options_count;
+ uint32_t option_index;
+ dom_node *option_element = NULL;
+
+ /* check if element is disabled */
+ exp = dom_html_select_element_get_disabled(select_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
+ }
+
+ /* obtain name property */
+ exp = dom_html_select_element_get_name(select_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
+
+ /* get options collection */
+ exp = dom_html_select_element_get_options(select_element, &options);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select options collection");
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
+
+ /* get options collection length */
+ exp = dom_html_options_collection_get_length(options, &options_count);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get select options collection length");
+ dom_html_options_collection_unref(options);
+ dom_string_unref(inputname);
+ return NSERROR_DOM;
+ }
+
+ /* iterate over options collection */
+ for (option_index = 0; option_index < options_count; ++option_index) {
+ exp = dom_html_options_collection_item(options,
+ option_index,
+ &option_element);
+ if (exp != DOM_NO_ERR) {
NSLOG(netsurf, INFO,
- "Could not encode value for generic");
- goto dom_no_memory;
+ "Could not get options item %d", option_index);
+ res = NSERROR_DOM;
+ } else {
+ res = form_dom_to_data_select_option(
+ (dom_html_option_element *)option_element,
+ inputname,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
+
+ dom_node_unref(option_element);
}
- if (rawfile_temp != NULL) {
- success_new->file = true;
- success_new->rawfile = rawfile_temp;
- rawfile_temp = NULL;
+
+ if (res != NSERROR_OK) {
+ break;
}
}
- free(charset);
+ dom_html_options_collection_unref(options);
+ dom_string_unref(inputname);
+
+ return res;
+}
- if (form_element != NULL) {
- dom_node_unref(form_element);
+static nserror
+form_dom_to_data_input_submit(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+ nserror res;
+
+ if (*submit_button == NULL) {
+ /* caller specified no button so use this one */
+ *submit_button = (dom_html_element *)input_element;
+ } else if (*submit_button != (dom_html_element *)input_element) {
+ return NSERROR_OK;
}
- if (form_elements != NULL) {
- dom_html_collection_unref(form_elements);
+ /* matched button used to submit form */
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get submit button value");
+ return NSERROR_DOM;
}
- if (nodename != NULL) {
- dom_string_unref(nodename);
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+
+
+static nserror
+form_dom_to_data_input_image(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ struct image_input_coords *coords;
+ char *basename;
+
+ /* Only use an image input if it was the thing which activated us */
+ if (*submit_button != (dom_html_element *)input_element) {
+ return NSERROR_OK;
+ }
+
+ exp = dom_node_get_user_data((dom_node *)input_element,
+ corestring_dom___ns_key_image_coords_node_data,
+ &coords);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get image XY data");
+ return NSERROR_DOM;
+ }
+
+ if (coords == NULL) {
+ NSLOG(netsurf, INFO, "No XY data on the image input");
+ return NSERROR_DOM;
+ }
+
+ /* encode input name once */
+ basename = form_encode_item(dom_string_data(inputname),
+ dom_string_byte_length(inputname),
+ charset,
+ document_charset);
+ if (basename == NULL) {
+ NSLOG(netsurf, INFO, "Could not encode basename");
+ return NSERROR_NOMEM;
+ }
+
+ res = fetch_data_list_add_sname(basename, ".x",
+ coords->x,
+ fetch_data_next_ptr);
+
+ if (res == NSERROR_OK) {
+ res = fetch_data_list_add_sname(basename, ".y",
+ coords->y,
+ fetch_data_next_ptr);
+ }
+
+ free(basename);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_checkbox(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ bool checked;
+ dom_string *inputvalue;
+
+ exp = dom_html_input_element_get_checked(input_element, &checked);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input element checked");
+ return NSERROR_DOM;
+ }
+
+ if (!checked) {
+ /* unchecked items do not generate a data entry */
+ return NSERROR_OK;
+ }
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input element value");
+ return NSERROR_DOM;
+ }
+
+ /* ensure a default value */
+ if (inputvalue == NULL) {
+ inputvalue = dom_string_ref(corestring_dom_on);
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_file(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+ const char *rawfile = NULL;
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get file value");
+ return NSERROR_DOM;
+ }
+
+ exp = dom_node_get_user_data((dom_node *)input_element,
+ corestring_dom___ns_key_file_name_node_data,
+ &rawfile);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get file rawname");
+ return NSERROR_DOM;
}
- if (inputname != NULL) {
+ if (rawfile == NULL) {
+ rawfile = "";
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ rawfile,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+static nserror
+form_dom_to_data_input_text(dom_html_input_element *input_element,
+ dom_string *inputname,
+ const char *charset,
+ const char *document_charset,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ nserror res;
+ dom_exception exp; /* the result from DOM operations */
+ dom_string *inputvalue;
+
+ exp = dom_html_input_element_get_value(input_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get input value");
+ return NSERROR_DOM;
+ }
+
+ /* add key/value pair to fetch data list */
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ dom_string_unref(inputvalue);
+
+ return res;
+}
+
+/**
+ * process form input element into multipart data.
+ *
+ * \param input_element The form input DOM element to convert.
+ * \param charset The form character set
+ * \param document_charset The document character set for fallback
+ * \param submit_button The DOM element of the button submitting the form
+ * \param had_submit A boolean value indicating if the submit button
+ * has already been processed in the form element enumeration.
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_input(dom_html_input_element *input_element,
+ const char *charset,
+ const char *document_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputtype;
+ nserror res;
+
+ /* check if element is disabled */
+ exp = dom_html_input_element_get_disabled(input_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* disabled element requires no more processing */
+ return NSERROR_OK;
+ }
+
+ /* obtain name property */
+ exp = dom_html_input_element_get_name(input_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get input name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (inputname == NULL) {
+ /* element with no name is not converted */
+ return NSERROR_OK;
+ }
+
+ /* get input type */
+ exp = dom_html_input_element_get_type(input_element, &inputtype);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get input element type");
dom_string_unref(inputname);
+ return NSERROR_DOM;
}
- if (inputvalue != NULL) {
- dom_string_unref(inputvalue);
+ /* process according to input element type */
+ if (dom_string_caseless_isequal(inputtype, corestring_dom_submit)) {
+
+ res = form_dom_to_data_input_submit(input_element,
+ inputname,
+ charset,
+ document_charset,
+ submit_button,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_image)) {
+
+ res = form_dom_to_data_input_image(input_element,
+ inputname,
+ charset,
+ document_charset,
+ submit_button,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_radio) ||
+ dom_string_caseless_isequal(inputtype,
+ corestring_dom_checkbox)) {
+
+ res = form_dom_to_data_input_checkbox(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_file)) {
+
+ res = form_dom_to_data_input_file(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
+ } else if (dom_string_caseless_isequal(inputtype,
+ corestring_dom_reset) ||
+ dom_string_caseless_isequal(inputtype,
+ corestring_dom_button)) {
+ /* Skip these */
+ NSLOG(netsurf, INFO, "Skipping RESET and BUTTON");
+ res = NSERROR_OK;
+
+ } else {
+ /* Everything else is treated as text values */
+ res = form_dom_to_data_input_text(input_element,
+ inputname,
+ charset,
+ document_charset,
+ fetch_data_next_ptr);
+
}
- if (options != NULL) {
- dom_html_options_collection_unref(options);
+ dom_string_unref(inputtype);
+ dom_string_unref(inputname);
+
+ return res;
+}
+
+/**
+ * process form HTMLButtonElement into multipart data.
+ *
+ * \param button_element The form button DOM element to convert.
+ * \param form_charset The form character set
+ * \param doc_charset The document character set for fallback
+ * \param submit_button The DOM element of the button submitting the form
+ * \param fetch_data_next_ptr The multipart data list being constructed.
+ * \return NSERROR_OK on success or appropriate error code.
+ */
+static nserror
+form_dom_to_data_button(dom_html_button_element *button_element,
+ const char *form_charset,
+ const char *doc_charset,
+ dom_html_element **submit_button,
+ struct fetch_multipart_data ***fetch_data_next_ptr)
+{
+ dom_exception exp; /* the result from DOM operations */
+ bool element_disabled;
+ dom_string *inputname;
+ dom_string *inputvalue;
+ dom_string *inputtype;
+ nserror res = NSERROR_OK;
+
+ /* check if element is disabled */
+ exp = dom_html_button_element_get_disabled(button_element,
+ &element_disabled);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Unabe to get disabled property. exp %d", exp);
+ return NSERROR_DOM;
+ }
+
+ if (element_disabled) {
+ /* allow enumeration to continue after disabled element */
+ return NSERROR_OK;
}
- if (option_element != NULL) {
- dom_node_unref(option_element);
+ /* only submit buttons can cause data elements */
+ exp = dom_html_button_element_get_type(button_element, &inputtype);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get button element type");
+ return NSERROR_DOM;
}
- if (inputtype != NULL) {
+ if (!dom_string_caseless_isequal(inputtype, corestring_dom_submit)) {
+ /* multipart data entry not required for non submit buttons */
dom_string_unref(inputtype);
+ return NSERROR_OK;
}
+ dom_string_unref(inputtype);
- if (rawfile_temp != NULL) {
- free(rawfile_temp);
+ /* only submision button generates an element */
+ if (*submit_button == NULL) {
+ /* no submission button selected yet so use this one */
+ *submit_button = (dom_html_element *)button_element;
+ }
+ if (*submit_button != (dom_html_element *)button_element) {
+ return NSERROR_OK;
}
- *successful_controls = sentinel.next;
+ /* obtain name property */
+ exp = dom_html_button_element_get_name(button_element, &inputname);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "Could not get button name property. exp %d", exp);
+ return NSERROR_DOM;
+ }
- return NSERROR_OK;
+ if (inputname == NULL) {
+ /* allow enumeration to continue after element with no name */
+ return NSERROR_OK;
+ }
-dom_no_memory:
- free(charset);
- fetch_multipart_data_destroy(sentinel.next);
+ /* get button value and add to fetch data list */
+ exp = dom_html_button_element_get_value(button_element, &inputvalue);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get submit button value");
+ res = NSERROR_DOM;
+ } else {
+ res = fetch_data_list_add(inputname,
+ inputvalue,
+ NULL,
+ form_charset,
+ doc_charset,
+ fetch_data_next_ptr);
- if (form_elements != NULL)
- dom_html_collection_unref(form_elements);
- if (form_element != NULL)
- dom_node_unref(form_element);
- if (nodename != NULL)
- dom_string_unref(nodename);
- if (inputname != NULL)
- dom_string_unref(inputname);
- if (inputvalue != NULL)
dom_string_unref(inputvalue);
- if (options != NULL)
- dom_html_options_collection_unref(options);
- if (option_element != NULL)
- dom_node_unref(option_element);
- if (inputtype != NULL)
- dom_string_unref(inputtype);
- if (rawfile_temp != NULL)
- free(rawfile_temp);
+ }
+
+ dom_string_unref(inputname);
+
+ return res;
+}
+
- return NSERROR_NOMEM;
+/**
+ * Construct multipart data list from 'successful' controls via the DOM.
+ *
+ * All text strings in the successful controls list will be in the charset most
+ * appropriate for submission. Therefore, no utf8_to_* processing should be
+ * performed upon them.
+ *
+ * \todo The chosen charset needs to be made available such that it can be
+ * included in the submission request (e.g. in the fetch's Content-Type header)
+ *
+ * See HTML 4.01 section 17.13.2.
+ *
+ * \note care is taken to abort even if the error is recoverable as it
+ * is not desirable to submit incomplete form data.
+ *
+ * \param[in] form form to search for successful controls
+ * \param[in] submit_button control used to submit the form, if any
+ * \param[out] fetch_data_out updated to point to linked list of
+ * fetch_multipart_data, NULL if no controls
+ * \return NSERROR_OK on success or appropriate error code
+ */
+static nserror
+form_dom_to_data(struct form *form,
+ struct form_control *submit_control,
+ struct fetch_multipart_data **fetch_data_out)
+{
+ nserror res = NSERROR_OK;
+ char *charset; /* form characterset */
+ dom_exception exp; /* the result from DOM operations */
+ dom_html_collection *elements = NULL; /* the dom form elements */
+ uint32_t element_count; /* the number of elements in the DOM form */
+ uint32_t element_idx; /* the index of thr enumerated element */
+ dom_node *element = NULL; /* the DOM form element */
+ dom_string *nodename = NULL; /* the DOM node name of the element */
+ struct fetch_multipart_data *fetch_data = NULL; /* fetch data list */
+ struct fetch_multipart_data **fetch_data_next = &fetch_data;
+ dom_html_element *submit_button;
+
+ /* obtain the submit_button DOM node from the control */
+ if (submit_control != NULL) {
+ submit_button = submit_control->node;
+ } else {
+ submit_button = NULL;
+ }
+
+ /** \todo Replace this call with something DOMish */
+ charset = form_acceptable_charset(form);
+ if (charset == NULL) {
+ NSLOG(netsurf, INFO, "failed to find charset");
+ return NSERROR_NOMEM;
+ }
+
+ /* obtain the form elements and count */
+ exp = dom_html_form_element_get_elements(form->node, &elements);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get form elements");
+ free(charset);
+ return NSERROR_DOM;
+ }
+
+ exp = dom_html_collection_get_length(elements, &element_count);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO, "Could not get form element count");
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ for (element_idx = 0; element_idx < element_count; element_idx++) {
+ /* obtain a form element */
+ exp = dom_html_collection_item(elements, element_idx, &element);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "retrieving form element %d failed with %d",
+ element_idx, exp);
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ /* node name from element */
+ exp = dom_node_get_node_name(element, &nodename);
+ if (exp != DOM_NO_ERR) {
+ NSLOG(netsurf, INFO,
+ "getting element node name %d failed with %d",
+ element_idx, exp);
+ dom_node_unref(element);
+ res = NSERROR_DOM;
+ goto form_dom_to_data_error;
+ }
+
+ if (dom_string_isequal(nodename, corestring_dom_TEXTAREA)) {
+ /* Form element is HTMLTextAreaElement */
+ res = form_dom_to_data_textarea(
+ (dom_html_text_area_element *)element,
+ charset,
+ form->document_charset,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_SELECT)) {
+ /* Form element is HTMLSelectElement */
+ res = form_dom_to_data_select(
+ (dom_html_select_element *)element,
+ charset,
+ form->document_charset,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_INPUT)) {
+ /* Form element is HTMLInputElement */
+ res = form_dom_to_data_input(
+ (dom_html_input_element *)element,
+ charset,
+ form->document_charset,
+ &submit_button,
+ &fetch_data_next);
+
+ } else if (dom_string_isequal(nodename, corestring_dom_BUTTON)) {
+ /* Form element is HTMLButtonElement */
+ res = form_dom_to_data_button(
+ (dom_html_button_element *)element,
+ charset,
+ form->document_charset,
+ &submit_button,
+ &fetch_data_next);
+
+ } else {
+ /* Form element is not handled */
+ NSLOG(netsurf, INFO,
+ "Unhandled element type: %*s",
+ (int)dom_string_byte_length(nodename),
+ dom_string_data(nodename));
+ res = NSERROR_DOM;
+
+ }
+
+ dom_string_unref(nodename);
+ dom_node_unref(element);
+
+ /* abort form element enumeration on error */
+ if (res != NSERROR_OK) {
+ goto form_dom_to_data_error;
+ }
+ }
+
+ *fetch_data_out = fetch_data;
+ dom_html_collection_unref(elements);
+ free(charset);
+
+ return NSERROR_OK;
+
+form_dom_to_data_error:
+ fetch_multipart_data_destroy(fetch_data);
+ dom_html_collection_unref(elements);
+ free(charset);
+
+ return res;
}
-#undef ENCODE_ITEM
/**
* Encode controls using application/x-www-form-urlencoded.
@@ -1087,8 +1411,11 @@ char *form_acceptable_charset(struct form *form)
* used iff converting to charset fails
* \return Pointer to converted string (on heap, caller frees), or NULL
*/
-char *form_encode_item(const char *item, uint32_t len, const char *charset,
- const char *fallback)
+char *
+form_encode_item(const char *item,
+ uint32_t len,
+ const char *charset,
+ const char *fallback)
{
nserror err;
char *ret = NULL;
@@ -1797,7 +2124,7 @@ form_submit(nsurl *page_url,
assert(form != NULL);
/* obtain list of controls from DOM */
- res = form_successful_controls_dom(form, submit_button, &success);
+ res = form_dom_to_data(form, submit_button, &success);
if (res != NSERROR_OK) {
return res;
}
--
NetSurf Browser
4 years, 12 months
libnslayout: branch tlsa/layout-nodes updated. fd5ccee08973a2a5ada67e87c8d76b8086cd6ec5
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnslayout.git/shortlog/fd5ccee08973a2a5a...
...commit http://git.netsurf-browser.org/libnslayout.git/commit/fd5ccee08973a2a5ada...
...tree http://git.netsurf-browser.org/libnslayout.git/tree/fd5ccee08973a2a5ada67...
The branch, tlsa/layout-nodes has been updated
discards 7852370aca24e96b7a398164094ba8dcb637b748 (commit)
via fd5ccee08973a2a5ada67e87c8d76b8086cd6ec5 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (7852370aca24e96b7a398164094ba8dcb637b748)
\
N -- N -- N (fd5ccee08973a2a5ada67e87c8d76b8086cd6ec5)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnslayout.git/commit/?id=fd5ccee08973a2a...
commit fd5ccee08973a2a5ada67e87c8d76b8086cd6ec5
Author: Michael Drake <michael.drake(a)codethink.co.uk>
Commit: Michael Drake <michael.drake(a)codethink.co.uk>
WIP: Layout node stuff. Not a lot here.
diff --git a/src/Makefile b/src/Makefile
index 7a6251d..b02f0b9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,6 +6,6 @@
# Released under the ISC License (see COPYING file)
# Sources
-DIR_SOURCES := layout.c
+DIR_SOURCES := layout.c node.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/node.c b/src/node.c
new file mode 100644
index 0000000..233e6c4
--- /dev/null
+++ b/src/node.c
@@ -0,0 +1,25 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/node.c
+ * Layout node handling
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "libnslayout/nslayout.h"
+
+#include "layout.h"
+#include "util/util.h"
+#include "util/dom-str.h"
+
+
+/**
+ * The layout node object.
+ */
+struct nsl_node {
+};
diff --git a/src/node.h b/src/node.h
new file mode 100644
index 0000000..b21352a
--- /dev/null
+++ b/src/node.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+/** \file src/node.h
+ * Layout node handling
+ */
+
+#ifndef nsl_node_h_
+#define nsl_node_h_
+
+typedef struct nsl_node nsl_node;
+
+/** Layout node types */
+enum nsl_node {
+ NSL_NODE_INLINE = 1,
+ NSL_NODE_BLOCK = ( 1 << 1),
+ NSL_NODE_FLEX = ( 2 << 1),
+ NSL_NODE_GRID = ( 3 << 1),
+ NSL_NODE_TABLE = ( 4 << 1),
+ NSL_NODE_TABLE_CAP = ( 5 << 1),
+ NSL_NODE_TABLE_COL_GROUP = ( 6 << 1),
+ NSL_NODE_TABLE_ROW_GROUP = ( 7 << 1),
+ NSL_NODE_TABLE_CELL = ( 8 << 1),
+ NSL_NODE_TABLE_COL = ( 9 << 1),
+ NSL_NODE_TABLE_ROW = (10 << 1),
+ NSL_NODE_INLINE_BLOCK = NSL_NODE_INLINE | NSL_NODE_BLOCK,
+ NSL_NODE_INLINE_FLEX = NSL_NODE_INLINE | NSL_NODE_FLEX,
+ NSL_NODE_INLINE_GRID = NSL_NODE_INLINE | NSL_NODE_GRID,
+ NSL_NODE_INLINE_TABLE = NSL_NODE_INLINE | NSL_NODE_TABLE,
+};
+
+/**
+ * Test whether a layout node participates in inline flow.
+ *
+ * \param[in] node Node to test.
+ * \return true if node participates in inline flow, false otherwise.
+ */
+static inline bool nsl_node_is_inline(struct nsl_node *node)
+{
+ return node->type & NSL_NODE_INLINE;
+}
+
+/**
+ * Test whether a layout node participates in block flow.
+ *
+ * \param[in] node Node to test.
+ * \return true if node participates in block flow, false otherwise.
+ */
+static inline bool nsl_node_is_block(struct nsl_node *node)
+{
+ return !nsl_node_is_inline(node);
+}
+
+nsl_error nsl__node_create(nsl_node **node_out);
+
+void nsl__node_destroy(nsl_node *node_out);
+
+#endif
-----------------------------------------------------------------------
Summary of changes:
src/node.h | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/node.h b/src/node.h
index 9e85db1..b21352a 100644
--- a/src/node.h
+++ b/src/node.h
@@ -13,6 +13,47 @@
typedef struct nsl_node nsl_node;
+/** Layout node types */
+enum nsl_node {
+ NSL_NODE_INLINE = 1,
+ NSL_NODE_BLOCK = ( 1 << 1),
+ NSL_NODE_FLEX = ( 2 << 1),
+ NSL_NODE_GRID = ( 3 << 1),
+ NSL_NODE_TABLE = ( 4 << 1),
+ NSL_NODE_TABLE_CAP = ( 5 << 1),
+ NSL_NODE_TABLE_COL_GROUP = ( 6 << 1),
+ NSL_NODE_TABLE_ROW_GROUP = ( 7 << 1),
+ NSL_NODE_TABLE_CELL = ( 8 << 1),
+ NSL_NODE_TABLE_COL = ( 9 << 1),
+ NSL_NODE_TABLE_ROW = (10 << 1),
+ NSL_NODE_INLINE_BLOCK = NSL_NODE_INLINE | NSL_NODE_BLOCK,
+ NSL_NODE_INLINE_FLEX = NSL_NODE_INLINE | NSL_NODE_FLEX,
+ NSL_NODE_INLINE_GRID = NSL_NODE_INLINE | NSL_NODE_GRID,
+ NSL_NODE_INLINE_TABLE = NSL_NODE_INLINE | NSL_NODE_TABLE,
+};
+
+/**
+ * Test whether a layout node participates in inline flow.
+ *
+ * \param[in] node Node to test.
+ * \return true if node participates in inline flow, false otherwise.
+ */
+static inline bool nsl_node_is_inline(struct nsl_node *node)
+{
+ return node->type & NSL_NODE_INLINE;
+}
+
+/**
+ * Test whether a layout node participates in block flow.
+ *
+ * \param[in] node Node to test.
+ * \return true if node participates in block flow, false otherwise.
+ */
+static inline bool nsl_node_is_block(struct nsl_node *node)
+{
+ return !nsl_node_is_inline(node);
+}
+
nsl_error nsl__node_create(nsl_node **node_out);
void nsl__node_destroy(nsl_node *node_out);
--
NetSurf Layout Engine
4 years, 12 months
netsurf: branch master updated. release/3.8-22-g5b849b1
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/5b849b1e22f21cf349bee...
...commit http://git.netsurf-browser.org/netsurf.git/commit/5b849b1e22f21cf349bee31...
...tree http://git.netsurf-browser.org/netsurf.git/tree/5b849b1e22f21cf349bee3103...
The branch, master has been updated
via 5b849b1e22f21cf349bee3103af949f62b344d83 (commit)
via dfc8f5aef4e49a8d23f906b4b36f6c37f07a2dc9 (commit)
via b0974557728a7553ad272040c86ecd81641bdf0f (commit)
via 64bc2a7931606f2165ab513f1d8f129c1f0735b0 (commit)
from a268252629a0f6b31e5f0189454144676dd7ffaa (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=5b849b1e22f21cf349b...
commit 5b849b1e22f21cf349bee3103af949f62b344d83
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Add a TODO for history context menu
diff --git a/frontends/amiga/ctxmenu.c b/frontends/amiga/ctxmenu.c
index a6755e6..f81e159 100644
--- a/frontends/amiga/ctxmenu.c
+++ b/frontends/amiga/ctxmenu.c
@@ -510,6 +510,7 @@ static bool ami_ctxmenu_history(int direction, struct gui_window_2 *gwin, const
IDoMethod(history_root, OM_ADDMEMBER, MStrip,
MA_Type, T_ITEM,
+ /* TODO: MA_Label should be in local charset */
MA_Label, browser_window_history_entry_get_title(entry),
MA_ID, id,
MA_Image, NULL,
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=dfc8f5aef4e49a8d23f...
commit dfc8f5aef4e49a8d23f906b4b36f6c37f07a2dc9
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Quick fix to convert helphints to correct charset
We should probably have our own strings for these
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index e337ede..e08ef59 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -4688,7 +4688,7 @@ static void gui_window_destroy(struct gui_window *g)
free(g->shared->svbuffer);
for(gid = 0; gid < GID_LAST; gid++)
- free(g->shared->helphints[gid]);
+ ami_utf8_free(g->shared->helphints[gid]);
ami_gui_win_list_remove(g->shared);
if(g->tab_node) {
diff --git a/frontends/amiga/misc.c b/frontends/amiga/misc.c
index 532d2f1..822d640 100755
--- a/frontends/amiga/misc.c
+++ b/frontends/amiga/misc.c
@@ -237,7 +237,8 @@ static nserror amiga_path_to_nsurl(const char *path, struct nsurl **url_out)
}
/**
- * returns a string with escape chars translated.
+ * returns a string with escape chars translated
+ * and string converted to local charset
* (based on remove_underscores from utils.c)
*/
@@ -259,7 +260,8 @@ char *translate_escape_chars(const char *s)
}
}
ret[ii] = '\0';
- return ret;
+
+ return ami_utf8_easy(ret);
}
/**
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=b0974557728a7553ad2...
commit b0974557728a7553ad272040c86ecd81641bdf0f
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Convert find window messages to local charset
diff --git a/frontends/amiga/search.c b/frontends/amiga/search.c
index 3392cca..e633362 100755
--- a/frontends/amiga/search.c
+++ b/frontends/amiga/search.c
@@ -81,11 +81,21 @@ enum
GID_S_LAST
};
+enum {
+ SSTR_TITLE = 0,
+ SSTR_CASE,
+ SSTR_SHOWALL,
+ SSTR_PREV,
+ SSTR_NEXT,
+ SSTR_LAST
+};
+
struct find_window {
struct ami_generic_window w;
struct Window *win;
Object *objects[GID_S_LAST];
struct gui_window *gwin;
+ char *message[SSTR_LAST];
};
static struct find_window *fwin = NULL;
@@ -144,57 +154,63 @@ void ami_search_open(struct gui_window *gwin)
fwin = calloc(1, sizeof(struct find_window));
+ /* Get local charset messages. If any of these are NULL it doesn't matter */
+ fwin->message[SSTR_TITLE] = ami_utf8_easy(messages_get("FindTextNS"));
+ fwin->message[SSTR_CASE] = ami_utf8_easy(messages_get("CaseSens"));
+ fwin->message[SSTR_SHOWALL] = ami_utf8_easy(messages_get("ShowAll"));
+ fwin->message[SSTR_PREV] = ami_utf8_easy(messages_get("Prev"));
+ fwin->message[SSTR_NEXT] = ami_utf8_easy(messages_get("Next"));
+
fwin->objects[OID_S_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
- WA_Title,messages_get("FindTextNS"),
+ WA_Title, fwin->message[SSTR_TITLE],
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
- WA_PubScreen,scrn,
- WINDOW_SharedPort,sport,
- WINDOW_UserData,fwin,
+ WA_PubScreen, scrn,
+ WINDOW_SharedPort, sport,
+ WINDOW_UserData, fwin,
WINDOW_IconifyGadget, FALSE,
- WINDOW_LockHeight,TRUE,
+ WINDOW_LockHeight, TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_ParentGroup, fwin->objects[GID_S_MAIN] = LayoutVObj,
LAYOUT_AddChild, fwin->objects[GID_S_SEARCHSTRING] = StringObj,
- GA_ID,GID_S_SEARCHSTRING,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ GA_ID, GID_S_SEARCHSTRING,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
StringEnd,
- CHILD_WeightedHeight,0,
+ CHILD_WeightedHeight, 0,
LAYOUT_AddChild, fwin->objects[GID_S_CASE] = CheckBoxObj,
- GA_ID,GID_S_CASE,
- GA_Text,messages_get("CaseSens"),
- GA_Selected,FALSE,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ GA_ID, GID_S_CASE,
+ GA_Text, fwin->message[SSTR_CASE],
+ GA_Selected, FALSE,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
CheckBoxEnd,
LAYOUT_AddChild, fwin->objects[GID_S_SHOWALL] = CheckBoxObj,
GA_ID,GID_S_SHOWALL,
- GA_Text,messages_get("ShowAll"),
- GA_Selected,FALSE,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ GA_Text, fwin->message[SSTR_SHOWALL],
+ GA_Selected, FALSE,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
CheckBoxEnd,
-
LAYOUT_AddChild, LayoutHObj,
LAYOUT_AddChild, fwin->objects[GID_S_PREV] = ButtonObj,
- GA_ID,GID_S_PREV,
- GA_RelVerify,TRUE,
- GA_Text,messages_get("Prev"),
- GA_TabCycle,TRUE,
- GA_Disabled,TRUE,
+ GA_ID, GID_S_PREV,
+ GA_RelVerify, TRUE,
+ GA_Text, fwin->message[SSTR_PREV],
+ GA_TabCycle, TRUE,
+ GA_Disabled, TRUE,
ButtonEnd,
- CHILD_WeightedHeight,0,
+ CHILD_WeightedHeight, 0,
LAYOUT_AddChild, fwin->objects[GID_S_NEXT] = ButtonObj,
- GA_ID,GID_S_NEXT,
- GA_RelVerify,TRUE,
- GA_Text,messages_get("Next"),
- GA_TabCycle,TRUE,
- GA_Disabled,TRUE,
+ GA_ID, GID_S_NEXT,
+ GA_RelVerify, TRUE,
+ GA_Text, fwin->message[SSTR_NEXT],
+ GA_TabCycle, TRUE,
+ GA_Disabled, TRUE,
ButtonEnd,
LayoutEnd,
CHILD_WeightedHeight,0,
@@ -215,6 +231,12 @@ void ami_search_close(void)
browser_window_search_clear(fwin->gwin->bw);
fwin->gwin->shared->searchwin = NULL;
DisposeObject(fwin->objects[OID_S_MAIN]);
+
+ /* Free local charset version of messages */
+ for(int i = 0; i < SSTR_LAST; i++) {
+ ami_utf8_free(fwin->message[i]);
+ }
+
ami_gui_win_list_remove(fwin);
fwin = NULL;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=64bc2a7931606f2165a...
commit 64bc2a7931606f2165ab513f1d8f129c1f0735b0
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Stop using the same large list of gadget constants everywhere
Saves a small amount of memory
diff --git a/frontends/amiga/download.c b/frontends/amiga/download.c
index 41ff6a6..895d929 100644
--- a/frontends/amiga/download.c
+++ b/frontends/amiga/download.c
@@ -80,10 +80,18 @@
#define APPNOTIFY_StopBackMsg ( TAG_USER + 17 )
#endif
+enum {
+ OID_D_MAIN = 0,
+ GID_D_MAIN,
+ GID_D_STATUS,
+ GID_D_CANCEL,
+ GID_D_LAST
+};
+
struct gui_download_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_D_LAST];
BPTR fh;
uint32 size;
uint32 downloaded;
@@ -183,7 +191,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
APPNOTIFY_StopBackMsg, bkm,
TAG_DONE);
} else {
- dw->objects[OID_MAIN] = WindowObj,
+ dw->objects[OID_D_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, dw->url,
WA_Activate, TRUE,
@@ -197,9 +205,9 @@ static struct gui_download_window *gui_download_window_create(download_context *
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, dw->objects[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, dw->objects[GID_STATUS] = FuelGaugeObj,
- GA_ID,GID_STATUS,
+ WINDOW_ParentGroup, dw->objects[GID_D_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, dw->objects[GID_D_STATUS] = FuelGaugeObj,
+ GA_ID,GID_D_STATUS,
GA_Text,messages_get("amiDownload"),
FUELGAUGE_Min,0,
FUELGAUGE_Max,total_size,
@@ -212,8 +220,8 @@ static struct gui_download_window *gui_download_window_create(download_context *
FuelGaugeEnd,
CHILD_NominalSize,TRUE,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, dw->objects[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, dw->objects[GID_D_CANCEL] = ButtonObj,
+ GA_ID,GID_D_CANCEL,
GA_RelVerify,TRUE,
GA_Text,messages_get("Abort"),
GA_TabCycle,TRUE,
@@ -221,7 +229,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
EndGroup,
EndWindow;
- dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]);
+ dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_D_MAIN]);
}
dw->ctx = ctx;
@@ -256,7 +264,7 @@ static nserror gui_download_window_data(struct gui_download_window *dw,
APPNOTIFY_Percentage, dw->progress,
TAG_DONE);
} else {
- RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL,
+ RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
FUELGAUGE_Level, dw->downloaded,
GA_Text, messages_get("amiDownload"),
FUELGAUGE_VarArgs, va,
@@ -271,7 +279,7 @@ static nserror gui_download_window_data(struct gui_download_window *dw,
APPNOTIFY_Percentage, 100,
TAG_DONE);
} else {
- RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL,
+ RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
FUELGAUGE_Level, dw->downloaded,
GA_Text, messages_get("amiDownloadU"),
FUELGAUGE_VarArgs, va,
@@ -330,8 +338,8 @@ static void gui_download_window_done(struct gui_download_window *dw)
downloads_in_progress--;
- if(dw->objects[OID_MAIN] != NULL) {
- DisposeObject(dw->objects[OID_MAIN]);
+ if(dw->objects[OID_D_MAIN] != NULL) {
+ DisposeObject(dw->objects[OID_D_MAIN]);
}
ami_gui_win_list_remove(dw);
@@ -378,14 +386,14 @@ static BOOL ami_download_window_event(void *w)
if(dw == NULL) return FALSE; /* We may not have a real window */
- while((result = RA_HandleInput(dw->objects[OID_MAIN], &code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(dw->objects[OID_D_MAIN], &code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_CANCEL:
+ case GID_D_CANCEL:
ami_download_window_abort(dw);
return TRUE;
break;
diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h
index bf4ec91..62390ce 100644
--- a/frontends/amiga/gui.h
+++ b/frontends/amiga/gui.h
@@ -43,7 +43,6 @@ enum
OID_MAIN = 0,
OID_VSCROLL,
OID_HSCROLL,
- OID_LAST, /* for compatibility */
GID_MAIN,
GID_TABLAYOUT,
GID_BROWSER,
@@ -66,15 +65,7 @@ enum
GID_ADDTAB_BM,
GID_TABS,
GID_TABS_FLAG,
- GID_USER,
- GID_PASS,
- GID_LOGIN,
- GID_CANCEL,
- GID_NEXT,
- GID_PREV,
GID_SEARCHSTRING,
- GID_SHOWALL,
- GID_CASE,
GID_TOOLBARLAYOUT,
GID_HOTLIST,
GID_HOTLISTLAYOUT,
diff --git a/frontends/amiga/login.c b/frontends/amiga/login.c
index ca17e7e..0948caa 100755
--- a/frontends/amiga/login.c
+++ b/frontends/amiga/login.c
@@ -61,10 +61,20 @@ enum {
AMI_LOGIN_MSG_MAX
};
+enum {
+ OID_L_MAIN = 0,
+ GID_L_MAIN,
+ GID_L_USER,
+ GID_L_PASS,
+ GID_L_LOGIN,
+ GID_L_CANCEL,
+ GID_L_LAST
+};
+
struct gui_login_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_L_LAST];
nserror (*cb)(const char *username, const char *password, void *pw);
void *cbpw;
nsurl *url;
@@ -128,7 +138,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
ami_utf8_free(pass_utf8);
}
- lw->objects[OID_MAIN] = WindowObj,
+ lw->objects[OID_L_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, nsurl_access(lw->url),
WA_Activate, TRUE,
@@ -142,7 +152,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, lw->objects[GID_MAIN] = LayoutVObj,
+ WINDOW_ParentGroup, lw->objects[GID_L_MAIN] = LayoutVObj,
LAYOUT_AddChild, StringObj,
STRINGA_TextVal, lwc_string_data(lw->host),
GA_ReadOnly,TRUE,
@@ -159,8 +169,8 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LABEL_Text, lw->messages[AMI_LOGIN_MSG_REALM],
LabelEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_USER] = StringObj,
- GA_ID,GID_USER,
+ LAYOUT_AddChild, lw->objects[GID_L_USER] = StringObj,
+ GA_ID,GID_L_USER,
GA_TabCycle,TRUE,
STRINGA_TextVal, lw->uname,
StringEnd,
@@ -168,8 +178,8 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LABEL_Text, lw->messages[AMI_LOGIN_MSG_USER],
LabelEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_PASS] = StringObj,
- GA_ID,GID_PASS,
+ LAYOUT_AddChild, lw->objects[GID_L_PASS] = StringObj,
+ GA_ID,GID_L_PASS,
STRINGA_HookType,SHK_PASSWORD,
GA_TabCycle,TRUE,
STRINGA_TextVal, lw->pwd,
@@ -179,15 +189,15 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LabelEnd,
CHILD_WeightedHeight,0,
LAYOUT_AddChild, LayoutHObj,
- LAYOUT_AddChild, lw->objects[GID_LOGIN] = ButtonObj,
- GA_ID,GID_LOGIN,
+ LAYOUT_AddChild, lw->objects[GID_L_LOGIN] = ButtonObj,
+ GA_ID,GID_L_LOGIN,
GA_RelVerify,TRUE,
GA_Text, lw->messages[AMI_LOGIN_MSG_LOGIN],
GA_TabCycle,TRUE,
ButtonEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, lw->objects[GID_L_CANCEL] = ButtonObj,
+ GA_ID,GID_L_CANCEL,
GA_RelVerify,TRUE,
GA_Text, lw->messages[AMI_LOGIN_MSG_CANCEL],
GA_TabCycle,TRUE,
@@ -197,7 +207,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
EndGroup,
EndWindow;
- lw->win = (struct Window *)RA_OpenWindow(lw->objects[OID_MAIN]);
+ lw->win = (struct Window *)RA_OpenWindow(lw->objects[OID_L_MAIN]);
ami_gui_win_list_add(lw, AMINS_LOGINWINDOW, &ami_login_table);
return NSERROR_OK;
@@ -211,7 +221,7 @@ static void ami_401login_close(void *w)
if (lw->cb != NULL)
lw->cb(NULL, NULL, lw->cbpw);
- DisposeObject(lw->objects[OID_MAIN]);
+ DisposeObject(lw->objects[OID_L_MAIN]);
lwc_string_unref(lw->host);
nsurl_unref(lw->url);
free(lw->realm);
@@ -230,8 +240,8 @@ static void ami_401login_login(struct gui_login_window *lw)
char *pass;
/* Get username and password from string gadgets */
- GetAttr(STRINGA_TextVal,lw->objects[GID_USER],(ULONG *)&user);
- GetAttr(STRINGA_TextVal,lw->objects[GID_PASS],(ULONG *)&pass);
+ GetAttr(STRINGA_TextVal,lw->objects[GID_L_USER],(ULONG *)&user);
+ GetAttr(STRINGA_TextVal,lw->objects[GID_L_PASS],(ULONG *)&pass);
/* Convert from local charset to UTF-8 */
char *user_utf8 = ami_to_utf8_easy(user);
@@ -260,19 +270,19 @@ static BOOL ami_401login_event(void *w)
ULONG result;
uint16 code;
- while((result = RA_HandleInput(lw->objects[OID_MAIN], &code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(lw->objects[OID_L_MAIN], &code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_LOGIN:
+ case GID_L_LOGIN:
ami_401login_login(lw);
return TRUE;
break;
- case GID_CANCEL:
+ case GID_L_CANCEL:
ami_401login_close(lw);
return TRUE;
break;
diff --git a/frontends/amiga/print.c b/frontends/amiga/print.c
index 8c85654..05f068b 100644
--- a/frontends/amiga/print.c
+++ b/frontends/amiga/print.c
@@ -73,6 +73,20 @@ bool ami_print_dump(void);
void ami_print_progress(void);
void ami_print_close_device(void);
+enum
+{
+ POID_MAIN = 0,
+ POID_LAST,
+ PGID_MAIN,
+ PGID_PRINTER,
+ PGID_SCALE,
+ PGID_COPIES,
+ PGID_PRINT,
+ PGID_CANCEL,
+ PGID_STATUS,
+ PGID_LAST
+};
+
const struct printer amiprinter = {
&amiplot,
ami_print_begin,
@@ -91,30 +105,19 @@ struct ami_printer_info
struct print_settings *ps;
int page;
int pages;
- Object *gadgets[GID_LAST];
- Object *objects[OID_LAST];
+ Object *gadgets[PGID_LAST];
+ Object *objects[POID_LAST];
struct Window *win;
};
struct ami_print_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[OID_LAST];
- Object *gadgets[GID_LAST];
+ Object *objects[POID_LAST];
+ Object *gadgets[PGID_LAST];
struct hlcache_handle *c;
};
-enum
-{
- PGID_MAIN=0,
- PGID_PRINTER,
- PGID_SCALE,
- PGID_COPIES,
- PGID_PRINT,
- PGID_CANCEL,
- PGID_LAST
-};
-
#define IFFPrefChunkCnt 2
static LONG IFFPrefChunks[] =
{
@@ -265,7 +268,7 @@ void ami_print_ui(struct hlcache_handle *c)
ami_print_ui_setup();
- pw->objects[OID_MAIN] = WindowObj,
+ pw->objects[POID_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, gadlab[PGID_PRINT],
WA_Activate, TRUE,
@@ -328,7 +331,7 @@ void ami_print_ui(struct hlcache_handle *c)
GA_TabCycle,TRUE,
ButtonEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, pw->gadgets[GID_CANCEL] = ButtonObj,
+ LAYOUT_AddChild, pw->gadgets[PGID_CANCEL] = ButtonObj,
GA_ID, PGID_CANCEL,
GA_RelVerify, TRUE,
GA_Text, gadlab[PGID_CANCEL],
@@ -339,13 +342,13 @@ void ami_print_ui(struct hlcache_handle *c)
EndGroup,
EndWindow;
- pw->win = (struct Window *)RA_OpenWindow(pw->objects[OID_MAIN]);
+ pw->win = (struct Window *)RA_OpenWindow(pw->objects[POID_MAIN]);
ami_gui_win_list_add(pw, AMINS_PRINTWINDOW, &ami_print_table);
}
static void ami_print_close(struct ami_print_window *pw)
{
- DisposeObject(pw->objects[OID_MAIN]);
+ DisposeObject(pw->objects[POID_MAIN]);
ami_gui_win_list_remove(pw);
ami_print_ui_free();
@@ -362,7 +365,7 @@ static BOOL ami_print_event(void *w)
int print_scale;
int printer_unit;
- while((result = RA_HandleInput(pw->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(pw->objects[POID_MAIN],&code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
@@ -509,7 +512,7 @@ bool ami_print_next_page(void)
{
ami_print_info.page++;
- RefreshSetGadgetAttrs((struct Gadget *)ami_print_info.gadgets[GID_STATUS],
+ RefreshSetGadgetAttrs((struct Gadget *)ami_print_info.gadgets[PGID_STATUS],
ami_print_info.win, NULL,
FUELGAUGE_Level, ami_print_info.page,
TAG_DONE);
@@ -519,7 +522,7 @@ bool ami_print_next_page(void)
void ami_print_end(void)
{
ami_plot_ra_free(ami_print_info.gg);
- DisposeObject(ami_print_info.objects[OID_MAIN]);
+ DisposeObject(ami_print_info.objects[POID_MAIN]);
ami_print_close_device();
ami_print_free();
@@ -554,7 +557,7 @@ bool ami_print_dump(void)
void ami_print_progress(void)
{
- ami_print_info.objects[OID_MAIN] = WindowObj,
+ ami_print_info.objects[POID_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, messages_get("Printing"),
WA_Activate, TRUE,
@@ -568,9 +571,9 @@ void ami_print_progress(void)
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, ami_print_info.gadgets[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, ami_print_info.gadgets[GID_STATUS] = FuelGaugeObj,
- GA_ID,GID_STATUS,
+ WINDOW_ParentGroup, ami_print_info.gadgets[PGID_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, ami_print_info.gadgets[PGID_STATUS] = FuelGaugeObj,
+ GA_ID,PGID_STATUS,
FUELGAUGE_Min,0,
FUELGAUGE_Max,ami_print_info.pages,
FUELGAUGE_Level,0,
@@ -582,8 +585,8 @@ void ami_print_progress(void)
CHILD_NominalSize,TRUE,
CHILD_WeightedHeight,0,
/*
- LAYOUT_AddChild, ami_print_info.gadgets[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, ami_print_info.gadgets[PGID_CANCEL] = ButtonObj,
+ GA_ID,PGID_CANCEL,
GA_Disabled,TRUE,
GA_RelVerify,TRUE,
GA_Text,messages_get("Abort"),
@@ -593,6 +596,6 @@ void ami_print_progress(void)
EndGroup,
EndWindow;
- ami_print_info.win = (struct Window *)RA_OpenWindow(ami_print_info.objects[OID_MAIN]);
+ ami_print_info.win = (struct Window *)RA_OpenWindow(ami_print_info.objects[POID_MAIN]);
}
diff --git a/frontends/amiga/search.c b/frontends/amiga/search.c
index 99ee5b4..3392cca 100755
--- a/frontends/amiga/search.c
+++ b/frontends/amiga/search.c
@@ -61,6 +61,7 @@
#include "amiga/search.h"
#include "amiga/object.h"
#include "amiga/theme.h"
+#include "amiga/utf8.h"
#ifndef NOF_ELEMENTS
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
@@ -68,10 +69,22 @@
static bool search_insert;
+enum
+{
+ OID_S_MAIN = 0,
+ GID_S_MAIN,
+ GID_S_NEXT,
+ GID_S_PREV,
+ GID_S_SEARCHSTRING,
+ GID_S_SHOWALL,
+ GID_S_CASE,
+ GID_S_LAST
+};
+
struct find_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_S_LAST];
struct gui_window *gwin;
};
@@ -131,7 +144,7 @@ void ami_search_open(struct gui_window *gwin)
fwin = calloc(1, sizeof(struct find_window));
- fwin->objects[OID_MAIN] = WindowObj,
+ fwin->objects[OID_S_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title,messages_get("FindTextNS"),
WA_Activate, TRUE,
@@ -145,22 +158,22 @@ void ami_search_open(struct gui_window *gwin)
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, fwin->objects[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, fwin->objects[GID_SEARCHSTRING] = StringObj,
- GA_ID,GID_SEARCHSTRING,
+ WINDOW_ParentGroup, fwin->objects[GID_S_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, fwin->objects[GID_S_SEARCHSTRING] = StringObj,
+ GA_ID,GID_S_SEARCHSTRING,
GA_TabCycle,TRUE,
GA_RelVerify,TRUE,
StringEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, fwin->objects[GID_CASE] = CheckBoxObj,
- GA_ID,GID_CASE,
+ LAYOUT_AddChild, fwin->objects[GID_S_CASE] = CheckBoxObj,
+ GA_ID,GID_S_CASE,
GA_Text,messages_get("CaseSens"),
GA_Selected,FALSE,
GA_TabCycle,TRUE,
GA_RelVerify,TRUE,
CheckBoxEnd,
- LAYOUT_AddChild, fwin->objects[GID_SHOWALL] = CheckBoxObj,
- GA_ID,GID_SHOWALL,
+ LAYOUT_AddChild, fwin->objects[GID_S_SHOWALL] = CheckBoxObj,
+ GA_ID,GID_S_SHOWALL,
GA_Text,messages_get("ShowAll"),
GA_Selected,FALSE,
GA_TabCycle,TRUE,
@@ -168,16 +181,16 @@ void ami_search_open(struct gui_window *gwin)
CheckBoxEnd,
LAYOUT_AddChild, LayoutHObj,
- LAYOUT_AddChild, fwin->objects[GID_PREV] = ButtonObj,
- GA_ID,GID_PREV,
+ LAYOUT_AddChild, fwin->objects[GID_S_PREV] = ButtonObj,
+ GA_ID,GID_S_PREV,
GA_RelVerify,TRUE,
GA_Text,messages_get("Prev"),
GA_TabCycle,TRUE,
GA_Disabled,TRUE,
ButtonEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, fwin->objects[GID_NEXT] = ButtonObj,
- GA_ID,GID_NEXT,
+ LAYOUT_AddChild, fwin->objects[GID_S_NEXT] = ButtonObj,
+ GA_ID,GID_S_NEXT,
GA_RelVerify,TRUE,
GA_Text,messages_get("Next"),
GA_TabCycle,TRUE,
@@ -188,20 +201,20 @@ void ami_search_open(struct gui_window *gwin)
EndGroup,
EndWindow;
- fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_MAIN]);
+ fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_S_MAIN]);
fwin->gwin = gwin;
ami_gui_win_list_add(fwin, AMINS_FINDWINDOW, &ami_search_table);
gwin->shared->searchwin = fwin;
- ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_MAIN], fwin->win,
- NULL, (ULONG)fwin->objects[GID_SEARCHSTRING]);
+ ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_S_MAIN], fwin->win,
+ NULL, (ULONG)fwin->objects[GID_S_SEARCHSTRING]);
}
void ami_search_close(void)
{
browser_window_search_clear(fwin->gwin->bw);
fwin->gwin->shared->searchwin = NULL;
- DisposeObject(fwin->objects[OID_MAIN]);
+ DisposeObject(fwin->objects[OID_S_MAIN]);
ami_gui_win_list_remove(fwin);
fwin = NULL;
}
@@ -213,29 +226,29 @@ static BOOL ami_search_event(void *w)
uint16 code;
search_flags_t flags;
- while((result = RA_HandleInput(fwin->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(fwin->objects[OID_S_MAIN],&code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_SEARCHSTRING:
+ case GID_S_SEARCHSTRING:
browser_window_search_clear(fwin->gwin->bw);
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_PREV],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
fwin->win, NULL,
GA_Disabled, FALSE,
TAG_DONE);
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_NEXT],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
fwin->win, NULL,
GA_Disabled, FALSE,
TAG_DONE);
/* fall through */
- case GID_NEXT:
+ case GID_S_NEXT:
search_insert = true;
flags = SEARCH_FLAG_FORWARDS |
ami_search_flags();
@@ -246,7 +259,7 @@ static BOOL ami_search_event(void *w)
ActivateWindow(fwin->gwin->shared->win);
break;
- case GID_PREV:
+ case GID_S_PREV:
search_insert = true;
flags = ~SEARCH_FLAG_FORWARDS &
ami_search_flags();
@@ -299,7 +312,7 @@ void ami_search_set_hourglass(bool active, void *p)
char *ami_search_string(void)
{
char *text;
- GetAttr(STRINGA_TextVal,fwin->objects[GID_SEARCHSTRING],(ULONG *)&text);
+ GetAttr(STRINGA_TextVal,fwin->objects[GID_S_SEARCHSTRING],(ULONG *)&text);
return text;
}
@@ -325,7 +338,7 @@ void ami_search_add_recent(const char *string, void *p)
void ami_search_set_forward_state(bool active, void *p)
{
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_NEXT],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
fwin->win, NULL,
GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
@@ -339,7 +352,7 @@ void ami_search_set_forward_state(bool active, void *p)
void ami_search_set_back_state(bool active, void *p)
{
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_PREV],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
fwin->win, NULL,
GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
}
@@ -352,8 +365,8 @@ search_flags_t ami_search_flags(void)
{
ULONG case_sensitive, showall;
search_flags_t flags;
- GetAttr(GA_Selected,fwin->objects[GID_CASE],(ULONG *)&case_sensitive);
- GetAttr(GA_Selected,fwin->objects[GID_SHOWALL],(ULONG *)&showall);
+ GetAttr(GA_Selected,fwin->objects[GID_S_CASE],(ULONG *)&case_sensitive);
+ GetAttr(GA_Selected,fwin->objects[GID_S_SHOWALL],(ULONG *)&showall);
flags = 0 | (case_sensitive ? SEARCH_FLAG_CASE_SENSITIVE : 0) |
(showall ? SEARCH_FLAG_SHOWALL : 0);
return flags;
-----------------------------------------------------------------------
Summary of changes:
frontends/amiga/ctxmenu.c | 1 +
frontends/amiga/download.c | 36 ++++++-----
frontends/amiga/gui.c | 2 +-
frontends/amiga/gui.h | 9 ---
frontends/amiga/login.c | 46 ++++++++------
frontends/amiga/misc.c | 6 +-
frontends/amiga/print.c | 61 ++++++++++---------
frontends/amiga/search.c | 143 +++++++++++++++++++++++++++-----------------
8 files changed, 177 insertions(+), 127 deletions(-)
diff --git a/frontends/amiga/ctxmenu.c b/frontends/amiga/ctxmenu.c
index a6755e6..f81e159 100644
--- a/frontends/amiga/ctxmenu.c
+++ b/frontends/amiga/ctxmenu.c
@@ -510,6 +510,7 @@ static bool ami_ctxmenu_history(int direction, struct gui_window_2 *gwin, const
IDoMethod(history_root, OM_ADDMEMBER, MStrip,
MA_Type, T_ITEM,
+ /* TODO: MA_Label should be in local charset */
MA_Label, browser_window_history_entry_get_title(entry),
MA_ID, id,
MA_Image, NULL,
diff --git a/frontends/amiga/download.c b/frontends/amiga/download.c
index 41ff6a6..895d929 100644
--- a/frontends/amiga/download.c
+++ b/frontends/amiga/download.c
@@ -80,10 +80,18 @@
#define APPNOTIFY_StopBackMsg ( TAG_USER + 17 )
#endif
+enum {
+ OID_D_MAIN = 0,
+ GID_D_MAIN,
+ GID_D_STATUS,
+ GID_D_CANCEL,
+ GID_D_LAST
+};
+
struct gui_download_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_D_LAST];
BPTR fh;
uint32 size;
uint32 downloaded;
@@ -183,7 +191,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
APPNOTIFY_StopBackMsg, bkm,
TAG_DONE);
} else {
- dw->objects[OID_MAIN] = WindowObj,
+ dw->objects[OID_D_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, dw->url,
WA_Activate, TRUE,
@@ -197,9 +205,9 @@ static struct gui_download_window *gui_download_window_create(download_context *
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, dw->objects[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, dw->objects[GID_STATUS] = FuelGaugeObj,
- GA_ID,GID_STATUS,
+ WINDOW_ParentGroup, dw->objects[GID_D_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, dw->objects[GID_D_STATUS] = FuelGaugeObj,
+ GA_ID,GID_D_STATUS,
GA_Text,messages_get("amiDownload"),
FUELGAUGE_Min,0,
FUELGAUGE_Max,total_size,
@@ -212,8 +220,8 @@ static struct gui_download_window *gui_download_window_create(download_context *
FuelGaugeEnd,
CHILD_NominalSize,TRUE,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, dw->objects[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, dw->objects[GID_D_CANCEL] = ButtonObj,
+ GA_ID,GID_D_CANCEL,
GA_RelVerify,TRUE,
GA_Text,messages_get("Abort"),
GA_TabCycle,TRUE,
@@ -221,7 +229,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
EndGroup,
EndWindow;
- dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]);
+ dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_D_MAIN]);
}
dw->ctx = ctx;
@@ -256,7 +264,7 @@ static nserror gui_download_window_data(struct gui_download_window *dw,
APPNOTIFY_Percentage, dw->progress,
TAG_DONE);
} else {
- RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL,
+ RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
FUELGAUGE_Level, dw->downloaded,
GA_Text, messages_get("amiDownload"),
FUELGAUGE_VarArgs, va,
@@ -271,7 +279,7 @@ static nserror gui_download_window_data(struct gui_download_window *dw,
APPNOTIFY_Percentage, 100,
TAG_DONE);
} else {
- RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL,
+ RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
FUELGAUGE_Level, dw->downloaded,
GA_Text, messages_get("amiDownloadU"),
FUELGAUGE_VarArgs, va,
@@ -330,8 +338,8 @@ static void gui_download_window_done(struct gui_download_window *dw)
downloads_in_progress--;
- if(dw->objects[OID_MAIN] != NULL) {
- DisposeObject(dw->objects[OID_MAIN]);
+ if(dw->objects[OID_D_MAIN] != NULL) {
+ DisposeObject(dw->objects[OID_D_MAIN]);
}
ami_gui_win_list_remove(dw);
@@ -378,14 +386,14 @@ static BOOL ami_download_window_event(void *w)
if(dw == NULL) return FALSE; /* We may not have a real window */
- while((result = RA_HandleInput(dw->objects[OID_MAIN], &code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(dw->objects[OID_D_MAIN], &code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_CANCEL:
+ case GID_D_CANCEL:
ami_download_window_abort(dw);
return TRUE;
break;
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index e337ede..e08ef59 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -4688,7 +4688,7 @@ static void gui_window_destroy(struct gui_window *g)
free(g->shared->svbuffer);
for(gid = 0; gid < GID_LAST; gid++)
- free(g->shared->helphints[gid]);
+ ami_utf8_free(g->shared->helphints[gid]);
ami_gui_win_list_remove(g->shared);
if(g->tab_node) {
diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h
index bf4ec91..62390ce 100644
--- a/frontends/amiga/gui.h
+++ b/frontends/amiga/gui.h
@@ -43,7 +43,6 @@ enum
OID_MAIN = 0,
OID_VSCROLL,
OID_HSCROLL,
- OID_LAST, /* for compatibility */
GID_MAIN,
GID_TABLAYOUT,
GID_BROWSER,
@@ -66,15 +65,7 @@ enum
GID_ADDTAB_BM,
GID_TABS,
GID_TABS_FLAG,
- GID_USER,
- GID_PASS,
- GID_LOGIN,
- GID_CANCEL,
- GID_NEXT,
- GID_PREV,
GID_SEARCHSTRING,
- GID_SHOWALL,
- GID_CASE,
GID_TOOLBARLAYOUT,
GID_HOTLIST,
GID_HOTLISTLAYOUT,
diff --git a/frontends/amiga/login.c b/frontends/amiga/login.c
index ca17e7e..0948caa 100755
--- a/frontends/amiga/login.c
+++ b/frontends/amiga/login.c
@@ -61,10 +61,20 @@ enum {
AMI_LOGIN_MSG_MAX
};
+enum {
+ OID_L_MAIN = 0,
+ GID_L_MAIN,
+ GID_L_USER,
+ GID_L_PASS,
+ GID_L_LOGIN,
+ GID_L_CANCEL,
+ GID_L_LAST
+};
+
struct gui_login_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_L_LAST];
nserror (*cb)(const char *username, const char *password, void *pw);
void *cbpw;
nsurl *url;
@@ -128,7 +138,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
ami_utf8_free(pass_utf8);
}
- lw->objects[OID_MAIN] = WindowObj,
+ lw->objects[OID_L_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, nsurl_access(lw->url),
WA_Activate, TRUE,
@@ -142,7 +152,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, lw->objects[GID_MAIN] = LayoutVObj,
+ WINDOW_ParentGroup, lw->objects[GID_L_MAIN] = LayoutVObj,
LAYOUT_AddChild, StringObj,
STRINGA_TextVal, lwc_string_data(lw->host),
GA_ReadOnly,TRUE,
@@ -159,8 +169,8 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LABEL_Text, lw->messages[AMI_LOGIN_MSG_REALM],
LabelEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_USER] = StringObj,
- GA_ID,GID_USER,
+ LAYOUT_AddChild, lw->objects[GID_L_USER] = StringObj,
+ GA_ID,GID_L_USER,
GA_TabCycle,TRUE,
STRINGA_TextVal, lw->uname,
StringEnd,
@@ -168,8 +178,8 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LABEL_Text, lw->messages[AMI_LOGIN_MSG_USER],
LabelEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_PASS] = StringObj,
- GA_ID,GID_PASS,
+ LAYOUT_AddChild, lw->objects[GID_L_PASS] = StringObj,
+ GA_ID,GID_L_PASS,
STRINGA_HookType,SHK_PASSWORD,
GA_TabCycle,TRUE,
STRINGA_TextVal, lw->pwd,
@@ -179,15 +189,15 @@ nserror gui_401login_open(nsurl *url, const char *realm,
LabelEnd,
CHILD_WeightedHeight,0,
LAYOUT_AddChild, LayoutHObj,
- LAYOUT_AddChild, lw->objects[GID_LOGIN] = ButtonObj,
- GA_ID,GID_LOGIN,
+ LAYOUT_AddChild, lw->objects[GID_L_LOGIN] = ButtonObj,
+ GA_ID,GID_L_LOGIN,
GA_RelVerify,TRUE,
GA_Text, lw->messages[AMI_LOGIN_MSG_LOGIN],
GA_TabCycle,TRUE,
ButtonEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, lw->objects[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, lw->objects[GID_L_CANCEL] = ButtonObj,
+ GA_ID,GID_L_CANCEL,
GA_RelVerify,TRUE,
GA_Text, lw->messages[AMI_LOGIN_MSG_CANCEL],
GA_TabCycle,TRUE,
@@ -197,7 +207,7 @@ nserror gui_401login_open(nsurl *url, const char *realm,
EndGroup,
EndWindow;
- lw->win = (struct Window *)RA_OpenWindow(lw->objects[OID_MAIN]);
+ lw->win = (struct Window *)RA_OpenWindow(lw->objects[OID_L_MAIN]);
ami_gui_win_list_add(lw, AMINS_LOGINWINDOW, &ami_login_table);
return NSERROR_OK;
@@ -211,7 +221,7 @@ static void ami_401login_close(void *w)
if (lw->cb != NULL)
lw->cb(NULL, NULL, lw->cbpw);
- DisposeObject(lw->objects[OID_MAIN]);
+ DisposeObject(lw->objects[OID_L_MAIN]);
lwc_string_unref(lw->host);
nsurl_unref(lw->url);
free(lw->realm);
@@ -230,8 +240,8 @@ static void ami_401login_login(struct gui_login_window *lw)
char *pass;
/* Get username and password from string gadgets */
- GetAttr(STRINGA_TextVal,lw->objects[GID_USER],(ULONG *)&user);
- GetAttr(STRINGA_TextVal,lw->objects[GID_PASS],(ULONG *)&pass);
+ GetAttr(STRINGA_TextVal,lw->objects[GID_L_USER],(ULONG *)&user);
+ GetAttr(STRINGA_TextVal,lw->objects[GID_L_PASS],(ULONG *)&pass);
/* Convert from local charset to UTF-8 */
char *user_utf8 = ami_to_utf8_easy(user);
@@ -260,19 +270,19 @@ static BOOL ami_401login_event(void *w)
ULONG result;
uint16 code;
- while((result = RA_HandleInput(lw->objects[OID_MAIN], &code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(lw->objects[OID_L_MAIN], &code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_LOGIN:
+ case GID_L_LOGIN:
ami_401login_login(lw);
return TRUE;
break;
- case GID_CANCEL:
+ case GID_L_CANCEL:
ami_401login_close(lw);
return TRUE;
break;
diff --git a/frontends/amiga/misc.c b/frontends/amiga/misc.c
index 532d2f1..822d640 100755
--- a/frontends/amiga/misc.c
+++ b/frontends/amiga/misc.c
@@ -237,7 +237,8 @@ static nserror amiga_path_to_nsurl(const char *path, struct nsurl **url_out)
}
/**
- * returns a string with escape chars translated.
+ * returns a string with escape chars translated
+ * and string converted to local charset
* (based on remove_underscores from utils.c)
*/
@@ -259,7 +260,8 @@ char *translate_escape_chars(const char *s)
}
}
ret[ii] = '\0';
- return ret;
+
+ return ami_utf8_easy(ret);
}
/**
diff --git a/frontends/amiga/print.c b/frontends/amiga/print.c
index 8c85654..05f068b 100644
--- a/frontends/amiga/print.c
+++ b/frontends/amiga/print.c
@@ -73,6 +73,20 @@ bool ami_print_dump(void);
void ami_print_progress(void);
void ami_print_close_device(void);
+enum
+{
+ POID_MAIN = 0,
+ POID_LAST,
+ PGID_MAIN,
+ PGID_PRINTER,
+ PGID_SCALE,
+ PGID_COPIES,
+ PGID_PRINT,
+ PGID_CANCEL,
+ PGID_STATUS,
+ PGID_LAST
+};
+
const struct printer amiprinter = {
&amiplot,
ami_print_begin,
@@ -91,30 +105,19 @@ struct ami_printer_info
struct print_settings *ps;
int page;
int pages;
- Object *gadgets[GID_LAST];
- Object *objects[OID_LAST];
+ Object *gadgets[PGID_LAST];
+ Object *objects[POID_LAST];
struct Window *win;
};
struct ami_print_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[OID_LAST];
- Object *gadgets[GID_LAST];
+ Object *objects[POID_LAST];
+ Object *gadgets[PGID_LAST];
struct hlcache_handle *c;
};
-enum
-{
- PGID_MAIN=0,
- PGID_PRINTER,
- PGID_SCALE,
- PGID_COPIES,
- PGID_PRINT,
- PGID_CANCEL,
- PGID_LAST
-};
-
#define IFFPrefChunkCnt 2
static LONG IFFPrefChunks[] =
{
@@ -265,7 +268,7 @@ void ami_print_ui(struct hlcache_handle *c)
ami_print_ui_setup();
- pw->objects[OID_MAIN] = WindowObj,
+ pw->objects[POID_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, gadlab[PGID_PRINT],
WA_Activate, TRUE,
@@ -328,7 +331,7 @@ void ami_print_ui(struct hlcache_handle *c)
GA_TabCycle,TRUE,
ButtonEnd,
CHILD_WeightedHeight,0,
- LAYOUT_AddChild, pw->gadgets[GID_CANCEL] = ButtonObj,
+ LAYOUT_AddChild, pw->gadgets[PGID_CANCEL] = ButtonObj,
GA_ID, PGID_CANCEL,
GA_RelVerify, TRUE,
GA_Text, gadlab[PGID_CANCEL],
@@ -339,13 +342,13 @@ void ami_print_ui(struct hlcache_handle *c)
EndGroup,
EndWindow;
- pw->win = (struct Window *)RA_OpenWindow(pw->objects[OID_MAIN]);
+ pw->win = (struct Window *)RA_OpenWindow(pw->objects[POID_MAIN]);
ami_gui_win_list_add(pw, AMINS_PRINTWINDOW, &ami_print_table);
}
static void ami_print_close(struct ami_print_window *pw)
{
- DisposeObject(pw->objects[OID_MAIN]);
+ DisposeObject(pw->objects[POID_MAIN]);
ami_gui_win_list_remove(pw);
ami_print_ui_free();
@@ -362,7 +365,7 @@ static BOOL ami_print_event(void *w)
int print_scale;
int printer_unit;
- while((result = RA_HandleInput(pw->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(pw->objects[POID_MAIN],&code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
@@ -509,7 +512,7 @@ bool ami_print_next_page(void)
{
ami_print_info.page++;
- RefreshSetGadgetAttrs((struct Gadget *)ami_print_info.gadgets[GID_STATUS],
+ RefreshSetGadgetAttrs((struct Gadget *)ami_print_info.gadgets[PGID_STATUS],
ami_print_info.win, NULL,
FUELGAUGE_Level, ami_print_info.page,
TAG_DONE);
@@ -519,7 +522,7 @@ bool ami_print_next_page(void)
void ami_print_end(void)
{
ami_plot_ra_free(ami_print_info.gg);
- DisposeObject(ami_print_info.objects[OID_MAIN]);
+ DisposeObject(ami_print_info.objects[POID_MAIN]);
ami_print_close_device();
ami_print_free();
@@ -554,7 +557,7 @@ bool ami_print_dump(void)
void ami_print_progress(void)
{
- ami_print_info.objects[OID_MAIN] = WindowObj,
+ ami_print_info.objects[POID_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
WA_Title, messages_get("Printing"),
WA_Activate, TRUE,
@@ -568,9 +571,9 @@ void ami_print_progress(void)
WINDOW_IconifyGadget, FALSE,
WINDOW_LockHeight,TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, ami_print_info.gadgets[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, ami_print_info.gadgets[GID_STATUS] = FuelGaugeObj,
- GA_ID,GID_STATUS,
+ WINDOW_ParentGroup, ami_print_info.gadgets[PGID_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, ami_print_info.gadgets[PGID_STATUS] = FuelGaugeObj,
+ GA_ID,PGID_STATUS,
FUELGAUGE_Min,0,
FUELGAUGE_Max,ami_print_info.pages,
FUELGAUGE_Level,0,
@@ -582,8 +585,8 @@ void ami_print_progress(void)
CHILD_NominalSize,TRUE,
CHILD_WeightedHeight,0,
/*
- LAYOUT_AddChild, ami_print_info.gadgets[GID_CANCEL] = ButtonObj,
- GA_ID,GID_CANCEL,
+ LAYOUT_AddChild, ami_print_info.gadgets[PGID_CANCEL] = ButtonObj,
+ GA_ID,PGID_CANCEL,
GA_Disabled,TRUE,
GA_RelVerify,TRUE,
GA_Text,messages_get("Abort"),
@@ -593,6 +596,6 @@ void ami_print_progress(void)
EndGroup,
EndWindow;
- ami_print_info.win = (struct Window *)RA_OpenWindow(ami_print_info.objects[OID_MAIN]);
+ ami_print_info.win = (struct Window *)RA_OpenWindow(ami_print_info.objects[POID_MAIN]);
}
diff --git a/frontends/amiga/search.c b/frontends/amiga/search.c
index 99ee5b4..e633362 100755
--- a/frontends/amiga/search.c
+++ b/frontends/amiga/search.c
@@ -61,6 +61,7 @@
#include "amiga/search.h"
#include "amiga/object.h"
#include "amiga/theme.h"
+#include "amiga/utf8.h"
#ifndef NOF_ELEMENTS
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
@@ -68,11 +69,33 @@
static bool search_insert;
+enum
+{
+ OID_S_MAIN = 0,
+ GID_S_MAIN,
+ GID_S_NEXT,
+ GID_S_PREV,
+ GID_S_SEARCHSTRING,
+ GID_S_SHOWALL,
+ GID_S_CASE,
+ GID_S_LAST
+};
+
+enum {
+ SSTR_TITLE = 0,
+ SSTR_CASE,
+ SSTR_SHOWALL,
+ SSTR_PREV,
+ SSTR_NEXT,
+ SSTR_LAST
+};
+
struct find_window {
struct ami_generic_window w;
struct Window *win;
- Object *objects[GID_LAST];
+ Object *objects[GID_S_LAST];
struct gui_window *gwin;
+ char *message[SSTR_LAST];
};
static struct find_window *fwin = NULL;
@@ -131,77 +154,89 @@ void ami_search_open(struct gui_window *gwin)
fwin = calloc(1, sizeof(struct find_window));
- fwin->objects[OID_MAIN] = WindowObj,
+ /* Get local charset messages. If any of these are NULL it doesn't matter */
+ fwin->message[SSTR_TITLE] = ami_utf8_easy(messages_get("FindTextNS"));
+ fwin->message[SSTR_CASE] = ami_utf8_easy(messages_get("CaseSens"));
+ fwin->message[SSTR_SHOWALL] = ami_utf8_easy(messages_get("ShowAll"));
+ fwin->message[SSTR_PREV] = ami_utf8_easy(messages_get("Prev"));
+ fwin->message[SSTR_NEXT] = ami_utf8_easy(messages_get("Next"));
+
+ fwin->objects[OID_S_MAIN] = WindowObj,
WA_ScreenTitle, ami_gui_get_screen_title(),
- WA_Title,messages_get("FindTextNS"),
+ WA_Title, fwin->message[SSTR_TITLE],
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
- WA_PubScreen,scrn,
- WINDOW_SharedPort,sport,
- WINDOW_UserData,fwin,
+ WA_PubScreen, scrn,
+ WINDOW_SharedPort, sport,
+ WINDOW_UserData, fwin,
WINDOW_IconifyGadget, FALSE,
- WINDOW_LockHeight,TRUE,
+ WINDOW_LockHeight, TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, fwin->objects[GID_MAIN] = LayoutVObj,
- LAYOUT_AddChild, fwin->objects[GID_SEARCHSTRING] = StringObj,
- GA_ID,GID_SEARCHSTRING,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ WINDOW_ParentGroup, fwin->objects[GID_S_MAIN] = LayoutVObj,
+ LAYOUT_AddChild, fwin->objects[GID_S_SEARCHSTRING] = StringObj,
+ GA_ID, GID_S_SEARCHSTRING,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
StringEnd,
- CHILD_WeightedHeight,0,
- LAYOUT_AddChild, fwin->objects[GID_CASE] = CheckBoxObj,
- GA_ID,GID_CASE,
- GA_Text,messages_get("CaseSens"),
- GA_Selected,FALSE,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ CHILD_WeightedHeight, 0,
+ LAYOUT_AddChild, fwin->objects[GID_S_CASE] = CheckBoxObj,
+ GA_ID, GID_S_CASE,
+ GA_Text, fwin->message[SSTR_CASE],
+ GA_Selected, FALSE,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
CheckBoxEnd,
- LAYOUT_AddChild, fwin->objects[GID_SHOWALL] = CheckBoxObj,
- GA_ID,GID_SHOWALL,
- GA_Text,messages_get("ShowAll"),
- GA_Selected,FALSE,
- GA_TabCycle,TRUE,
- GA_RelVerify,TRUE,
+ LAYOUT_AddChild, fwin->objects[GID_S_SHOWALL] = CheckBoxObj,
+ GA_ID,GID_S_SHOWALL,
+ GA_Text, fwin->message[SSTR_SHOWALL],
+ GA_Selected, FALSE,
+ GA_TabCycle, TRUE,
+ GA_RelVerify, TRUE,
CheckBoxEnd,
-
LAYOUT_AddChild, LayoutHObj,
- LAYOUT_AddChild, fwin->objects[GID_PREV] = ButtonObj,
- GA_ID,GID_PREV,
- GA_RelVerify,TRUE,
- GA_Text,messages_get("Prev"),
- GA_TabCycle,TRUE,
- GA_Disabled,TRUE,
+ LAYOUT_AddChild, fwin->objects[GID_S_PREV] = ButtonObj,
+ GA_ID, GID_S_PREV,
+ GA_RelVerify, TRUE,
+ GA_Text, fwin->message[SSTR_PREV],
+ GA_TabCycle, TRUE,
+ GA_Disabled, TRUE,
ButtonEnd,
- CHILD_WeightedHeight,0,
- LAYOUT_AddChild, fwin->objects[GID_NEXT] = ButtonObj,
- GA_ID,GID_NEXT,
- GA_RelVerify,TRUE,
- GA_Text,messages_get("Next"),
- GA_TabCycle,TRUE,
- GA_Disabled,TRUE,
+ CHILD_WeightedHeight, 0,
+ LAYOUT_AddChild, fwin->objects[GID_S_NEXT] = ButtonObj,
+ GA_ID, GID_S_NEXT,
+ GA_RelVerify, TRUE,
+ GA_Text, fwin->message[SSTR_NEXT],
+ GA_TabCycle, TRUE,
+ GA_Disabled, TRUE,
ButtonEnd,
LayoutEnd,
CHILD_WeightedHeight,0,
EndGroup,
EndWindow;
- fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_MAIN]);
+ fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_S_MAIN]);
fwin->gwin = gwin;
ami_gui_win_list_add(fwin, AMINS_FINDWINDOW, &ami_search_table);
gwin->shared->searchwin = fwin;
- ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_MAIN], fwin->win,
- NULL, (ULONG)fwin->objects[GID_SEARCHSTRING]);
+ ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_S_MAIN], fwin->win,
+ NULL, (ULONG)fwin->objects[GID_S_SEARCHSTRING]);
}
void ami_search_close(void)
{
browser_window_search_clear(fwin->gwin->bw);
fwin->gwin->shared->searchwin = NULL;
- DisposeObject(fwin->objects[OID_MAIN]);
+ DisposeObject(fwin->objects[OID_S_MAIN]);
+
+ /* Free local charset version of messages */
+ for(int i = 0; i < SSTR_LAST; i++) {
+ ami_utf8_free(fwin->message[i]);
+ }
+
ami_gui_win_list_remove(fwin);
fwin = NULL;
}
@@ -213,29 +248,29 @@ static BOOL ami_search_event(void *w)
uint16 code;
search_flags_t flags;
- while((result = RA_HandleInput(fwin->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
+ while((result = RA_HandleInput(fwin->objects[OID_S_MAIN],&code)) != WMHI_LASTMSG)
{
switch(result & WMHI_CLASSMASK) // class
{
case WMHI_GADGETUP:
switch(result & WMHI_GADGETMASK)
{
- case GID_SEARCHSTRING:
+ case GID_S_SEARCHSTRING:
browser_window_search_clear(fwin->gwin->bw);
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_PREV],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
fwin->win, NULL,
GA_Disabled, FALSE,
TAG_DONE);
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_NEXT],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
fwin->win, NULL,
GA_Disabled, FALSE,
TAG_DONE);
/* fall through */
- case GID_NEXT:
+ case GID_S_NEXT:
search_insert = true;
flags = SEARCH_FLAG_FORWARDS |
ami_search_flags();
@@ -246,7 +281,7 @@ static BOOL ami_search_event(void *w)
ActivateWindow(fwin->gwin->shared->win);
break;
- case GID_PREV:
+ case GID_S_PREV:
search_insert = true;
flags = ~SEARCH_FLAG_FORWARDS &
ami_search_flags();
@@ -299,7 +334,7 @@ void ami_search_set_hourglass(bool active, void *p)
char *ami_search_string(void)
{
char *text;
- GetAttr(STRINGA_TextVal,fwin->objects[GID_SEARCHSTRING],(ULONG *)&text);
+ GetAttr(STRINGA_TextVal,fwin->objects[GID_S_SEARCHSTRING],(ULONG *)&text);
return text;
}
@@ -325,7 +360,7 @@ void ami_search_add_recent(const char *string, void *p)
void ami_search_set_forward_state(bool active, void *p)
{
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_NEXT],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
fwin->win, NULL,
GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
@@ -339,7 +374,7 @@ void ami_search_set_forward_state(bool active, void *p)
void ami_search_set_back_state(bool active, void *p)
{
- RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_PREV],
+ RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
fwin->win, NULL,
GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
}
@@ -352,8 +387,8 @@ search_flags_t ami_search_flags(void)
{
ULONG case_sensitive, showall;
search_flags_t flags;
- GetAttr(GA_Selected,fwin->objects[GID_CASE],(ULONG *)&case_sensitive);
- GetAttr(GA_Selected,fwin->objects[GID_SHOWALL],(ULONG *)&showall);
+ GetAttr(GA_Selected,fwin->objects[GID_S_CASE],(ULONG *)&case_sensitive);
+ GetAttr(GA_Selected,fwin->objects[GID_S_SHOWALL],(ULONG *)&showall);
flags = 0 | (case_sensitive ? SEARCH_FLAG_CASE_SENSITIVE : 0) |
(showall ? SEARCH_FLAG_SHOWALL : 0);
return flags;
--
NetSurf Browser
4 years, 12 months
netsurf: branch master updated. release/3.8-18-ga268252
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/a268252629a0f6b31e5f0...
...commit http://git.netsurf-browser.org/netsurf.git/commit/a268252629a0f6b31e5f018...
...tree http://git.netsurf-browser.org/netsurf.git/tree/a268252629a0f6b31e5f01894...
The branch, master has been updated
via a268252629a0f6b31e5f0189454144676dd7ffaa (commit)
from 5c96acd6f119b71fc75e5d48465afca9fd13e87f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=a268252629a0f6b31e5...
commit a268252629a0f6b31e5f0189454144676dd7ffaa
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
gcc on openbsd is unable to reason about res variable usage and generates bogus warning
diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c
index 04d14aa..da4c67c 100644
--- a/content/handlers/html/html_interaction.c
+++ b/content/handlers/html/html_interaction.c
@@ -389,7 +389,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2 |
BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2);
- nserror res;
+ nserror res = NSERROR_OK;
if (drag_type != DRAGGING_NONE && !mouse &&
html->visible_select_menu != NULL) {
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/html_interaction.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c
index 04d14aa..da4c67c 100644
--- a/content/handlers/html/html_interaction.c
+++ b/content/handlers/html/html_interaction.c
@@ -389,7 +389,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2 |
BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2);
- nserror res;
+ nserror res = NSERROR_OK;
if (drag_type != DRAGGING_NONE && !mouse &&
html->visible_select_menu != NULL) {
--
NetSurf Browser
4 years, 12 months
netsurf: branch master updated. release/3.8-17-g5c96acd
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/5c96acd6f119b71fc75e5...
...commit http://git.netsurf-browser.org/netsurf.git/commit/5c96acd6f119b71fc75e5d4...
...tree http://git.netsurf-browser.org/netsurf.git/tree/5c96acd6f119b71fc75e5d484...
The branch, master has been updated
via 5c96acd6f119b71fc75e5d48465afca9fd13e87f (commit)
via 9100fcb4095cf8858d4cd2c613bff69ceb4f71ec (commit)
via 83512a6ff529c7c5cb6315167cba1cf132e6a67a (commit)
from 1a8fdb1462f8a506b2043877ab73cb86a9179ca6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=5c96acd6f119b71fc75...
commit 5c96acd6f119b71fc75e5d48465afca9fd13e87f
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
fix url encoding to be compatible with nsurl API changes.
As part of this fix the form submission error handling and
reporting has been improved.
diff --git a/content/fetch.h b/content/fetch.h
index 5521778..0b4b52a 100644
--- a/content/fetch.h
+++ b/content/fetch.h
@@ -74,16 +74,22 @@ typedef struct fetch_msg {
} data;
} fetch_msg;
-/** Fetch POST multipart data */
+/**
+ * Fetch POST multipart data
+ */
struct fetch_multipart_data {
- bool file; /**< Item is a file */
- char *name; /**< Name of item */
- char *value; /**< Item value */
- char *rawfile; /**< Raw filename if file is true */
+ struct fetch_multipart_data *next; /**< Next in linked list */
+
+ char *name; /**< Name of item */
+ char *value; /**< Item value */
- struct fetch_multipart_data *next; /**< Next in linked list */
+ char *rawfile; /**< Raw filename if file is true */
+ bool file; /**< Item is a file */
};
+/**
+ * ssl certificate information for certificate error message
+ */
struct ssl_cert_info {
long version; /**< Certificate version */
char not_before[32]; /**< Valid from date */
diff --git a/content/handlers/html/box_textarea.c b/content/handlers/html/box_textarea.c
index c19afbb..f0ba9f9 100644
--- a/content/handlers/html/box_textarea.c
+++ b/content/handlers/html/box_textarea.c
@@ -25,8 +25,11 @@
#include "utils/config.h"
#include "utils/log.h"
+#include "utils/messages.h"
#include "netsurf/keypress.h"
+#include "netsurf/misc.h"
#include "desktop/textarea.h"
+#include "desktop/gui_internal.h"
#include "html/html_internal.h"
#include "html/box.h"
@@ -41,6 +44,7 @@ bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key)
struct textarea *ta = gadget->data.text.ta;
struct form* form = box->gadget->form;
struct content *c = (struct content *) html;
+ nserror res;
assert(ta != NULL);
@@ -48,9 +52,16 @@ bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key)
switch (key) {
case NS_KEY_NL:
case NS_KEY_CR:
- if (form)
- form_submit(content_get_url(c), html->bw,
- form, 0);
+ if (form) {
+ res = form_submit(content_get_url(c),
+ html->bw,
+ form,
+ NULL);
+ if (res != NSERROR_OK) {
+ guit->misc->warning(messages_get_errorcode(res), NULL);
+ }
+
+ }
return true;
case NS_KEY_TAB:
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index 4a9d710..f779f07 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -327,10 +327,28 @@ bool form_add_option(struct form_control *control, char *value, char *text,
}
-/* exported interface documented in html/form_internal.h */
-bool form_successful_controls_dom(struct form *_form,
- struct form_control *_submit_button,
- struct fetch_multipart_data **successful_controls)
+/**
+ * Identify 'successful' controls via the DOM.
+ *
+ * All text strings in the successful controls list will be in the charset most
+ * appropriate for submission. Therefore, no utf8_to_* processing should be
+ * performed upon them.
+ *
+ * \todo The chosen charset needs to be made available such that it can be
+ * included in the submission request (e.g. in the fetch's Content-Type header)
+ *
+ * See HTML 4.01 section 17.13.2.
+ *
+ * \param[in] form form to search for successful controls
+ * \param[in] submit_button control used to submit the form, if any
+ * \param[out] successful_controls updated to point to linked list of
+ * fetch_multipart_data, NULL if no controls
+ * \return NSERROR_OK on success or appropriate error code
+ */
+static nserror
+form_successful_controls_dom(struct form *_form,
+ struct form_control *_submit_button,
+ struct fetch_multipart_data **successful_controls)
{
dom_html_form_element *form = _form->node;
dom_html_element *submit_button = (_submit_button != NULL) ? _submit_button->node : NULL;
@@ -352,7 +370,7 @@ bool form_successful_controls_dom(struct form *_form,
charset = form_acceptable_charset(_form);
if (charset == NULL) {
NSLOG(netsurf, INFO, "failed to find charset");
- return false;
+ return NSERROR_NOMEM;
}
#define ENCODE_ITEM(i) (((i) == NULL) ? ( \
@@ -685,6 +703,11 @@ bool form_successful_controls_dom(struct form *_form,
}
basename = ENCODE_ITEM(inputname);
+ if (basename == NULL) {
+ NSLOG(netsurf, INFO,
+ "Could not encode basename");
+ goto dom_no_memory;
+ }
success_new = calloc(1, sizeof(*success_new));
if (success_new == NULL) {
@@ -704,6 +727,8 @@ bool form_successful_controls_dom(struct form *_form,
"Could not allocate name for image.x");
goto dom_no_memory;
}
+ sprintf(success_new->name, "%s.x", basename);
+
success_new->value = malloc(20);
if (success_new->value == NULL) {
free(basename);
@@ -711,7 +736,6 @@ bool form_successful_controls_dom(struct form *_form,
"Could not allocate value for image.x");
goto dom_no_memory;
}
- sprintf(success_new->name, "%s.x", basename);
sprintf(success_new->value, "%d", coords->x);
success_new = calloc(1, sizeof(*success_new));
@@ -890,7 +914,7 @@ bool form_successful_controls_dom(struct form *_form,
*successful_controls = sentinel.next;
- return true;
+ return NSERROR_OK;
dom_no_memory:
free(charset);
@@ -915,73 +939,61 @@ dom_no_memory:
if (rawfile_temp != NULL)
free(rawfile_temp);
- return false;
+ return NSERROR_NOMEM;
}
#undef ENCODE_ITEM
/**
* Encode controls using application/x-www-form-urlencoded.
*
- * \param form form to which successful controls relate
- * \param control linked list of fetch_multipart_data
- * \param query_string iff true add '?' to the start of returned data
- * \return URL-encoded form, or 0 on memory exhaustion
+ * \param[in] form form to which successful controls relate
+ * \param[in] control linked list of fetch_multipart_data
+ * \param[out] encoded_out URL-encoded form data
+ * \return NSERROR_OK on success and \a encoded_out updated else appropriate error code
*/
-
-static char *form_url_encode(struct form *form,
+static nserror
+form_url_encode(struct form *form,
struct fetch_multipart_data *control,
- bool query_string)
+ char **encoded_out)
{
char *name, *value;
char *s, *s2;
unsigned int len, len1, len_init;
- nserror url_err;
+ nserror res;
- if (query_string)
- s = malloc(2);
- else
- s = malloc(1);
+ s = malloc(1);
- if (s == NULL)
- return NULL;
-
- if (query_string) {
- s[0] = '?';
- s[1] = '\0';
- len_init = len = 1;
- } else {
- s[0] = '\0';
- len_init = len = 0;
+ if (s == NULL) {
+ return NSERROR_NOMEM;
}
+ s[0] = '\0';
+ len_init = len = 0;
+
for (; control; control = control->next) {
- url_err = url_escape(control->name, true, NULL, &name);
- if (url_err == NSERROR_NOMEM) {
+ res = url_escape(control->name, true, NULL, &name);
+ if (res != NSERROR_OK) {
free(s);
- return NULL;
+ return res;
}
- assert(url_err == NSERROR_OK);
-
- url_err = url_escape(control->value, true, NULL, &value);
- if (url_err == NSERROR_NOMEM) {
+ res = url_escape(control->value, true, NULL, &value);
+ if (res != NSERROR_OK) {
free(name);
free(s);
- return NULL;
+ return res;
}
- assert(url_err == NSERROR_OK);
-
/* resize string to allow for new key/value pair,
* equals, amphersand and terminator
*/
len1 = len + strlen(name) + strlen(value) + 2;
s2 = realloc(s, len1 + 1);
- if (!s2) {
+ if (s2 == NULL) {
free(value);
free(name);
free(s);
- return NULL;
+ return NSERROR_NOMEM;
}
s = s2;
@@ -995,7 +1007,10 @@ static char *form_url_encode(struct form *form,
/* Replace trailing '&' */
s[len - 1] = '\0';
}
- return s;
+
+ *encoded_out = s;
+
+ return NSERROR_OK;
}
/**
@@ -1008,17 +1023,15 @@ char *form_acceptable_charset(struct form *form)
{
char *temp, *c;
- if (!form)
- return NULL;
-
if (!form->accept_charsets) {
/* no accept-charsets attribute for this form */
- if (form->document_charset)
+ if (form->document_charset) {
/* document charset present, so use it */
return strdup(form->document_charset);
- else
+ } else {
/* no document charset, so default to 8859-1 */
return strdup("ISO-8859-1");
+ }
}
/* make temporary copy of accept-charsets attribute */
@@ -1768,98 +1781,85 @@ void form_radio_set(struct form_control *radio)
}
-/**
- * Collect controls and submit a form.
- */
-
-void form_submit(nsurl *page_url, struct browser_window *target,
- struct form *form, struct form_control *submit_button)
+/* private interface described in html/form_internal.h */
+nserror
+form_submit(nsurl *page_url,
+ struct browser_window *target,
+ struct form *form,
+ struct form_control *submit_button)
{
- char *data = NULL;
- struct fetch_multipart_data *success;
+ nserror res;
+ char *data = NULL; /* encoded form data */
+ struct fetch_multipart_data *success = NULL; /* gcc is incapable of correctly reasoning about use and generates "maybe used uninitialised" warnings */
nsurl *action_url;
- nsurl *action_query;
- nserror error;
+ nsurl *query_url;
assert(form != NULL);
- if (form_successful_controls_dom(form, submit_button, &success) == false) {
- guit->misc->warning("NoMemory", 0);
- return;
+ /* obtain list of controls from DOM */
+ res = form_successful_controls_dom(form, submit_button, &success);
+ if (res != NSERROR_OK) {
+ return res;
}
/* Decompose action */
- if (nsurl_create(form->action, &action_url) != NSERROR_OK) {
- free(data);
+ res = nsurl_create(form->action, &action_url);
+ if (res != NSERROR_OK) {
fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- return;
+ return res;
}
switch (form->method) {
case method_GET:
- data = form_url_encode(form, success, true);
- if (data == NULL) {
- fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- return;
- }
-
- /* Replace query segment */
- error = nsurl_replace_query(action_url, data, &action_query);
- if (error != NSERROR_OK) {
- nsurl_unref(action_query);
+ res = form_url_encode(form, success, &data);
+ if (res == NSERROR_OK) {
+ /* Replace query segment */
+ res = nsurl_replace_query(action_url, data, &query_url);
+ if (res == NSERROR_OK) {
+ res = browser_window_navigate(target,
+ query_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
+
+ nsurl_unref(query_url);
+ }
free(data);
- fetch_multipart_data_destroy(success);
- guit->misc->warning(messages_get_errorcode(error), 0);
- return;
}
-
- /* Construct submit url */
- browser_window_navigate(target,
- action_query,
- page_url,
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
-
- nsurl_unref(action_query);
break;
case method_POST_URLENC:
- data = form_url_encode(form, success, false);
- if (data == NULL) {
- fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- nsurl_unref(action_url);
- return;
+ res = form_url_encode(form, success, &data);
+ if (res == NSERROR_OK) {
+ res = browser_window_navigate(target,
+ action_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ data,
+ NULL,
+ NULL);
+ free(data);
}
-
- browser_window_navigate(target,
- action_url,
- page_url,
- BW_NAVIGATE_HISTORY,
- data,
- NULL,
- NULL);
break;
case method_POST_MULTIPART:
- browser_window_navigate(target,
- action_url,
- page_url,
- BW_NAVIGATE_HISTORY,
- NULL,
- success,
- NULL);
+ res = browser_window_navigate(target,
+ action_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ success,
+ NULL);
break;
}
nsurl_unref(action_url);
fetch_multipart_data_destroy(success);
- free(data);
+
+ return res;
}
void form_gadget_update_value(struct form_control *control, char *value)
diff --git a/content/handlers/html/form_internal.h b/content/handlers/html/form_internal.h
index a77e823..f76f126 100644
--- a/content/handlers/html/form_internal.h
+++ b/content/handlers/html/form_internal.h
@@ -195,29 +195,6 @@ bool form_successful_controls(struct form *form,
struct fetch_multipart_data **successful_controls);
/**
- * Identify 'successful' controls via the DOM.
- *
- * All text strings in the successful controls list will be in the charset most
- * appropriate for submission. Therefore, no utf8_to_* processing should be
- * performed upon them.
- *
- * \todo The chosen charset needs to be made available such that it can be
- * included in the submission request (e.g. in the fetch's Content-Type header)
- *
- * See HTML 4.01 section 17.13.2.
- *
- * \param[in] form form to search for successful controls
- * \param[in] submit_button control used to submit the form, if any
- * \param[out] successful_controls updated to point to linked list of
- * fetch_multipart_data, 0 if no controls
- * \return true on success, false on memory exhaustion
- */
-bool form_successful_controls_dom(struct form *form,
- struct form_control *submit_button,
- struct fetch_multipart_data **successful_controls);
-
-
-/**
* Open a select menu for a select form control, creating it if necessary.
*
* \param client_data data passed to the redraw callback
@@ -268,8 +245,18 @@ void form_select_mouse_drag_end(struct form_control *control,
enum browser_mouse_state mouse, int x, int y);
void form_select_get_dimensions(struct form_control *control,
int *width, int *height);
-void form_submit(struct nsurl *page_url, struct browser_window *target,
+
+/**
+ * navigate browser window based on form submission.
+ *
+ * \param page_url content url
+ * \param target The browsing context in which the navigation will occour.
+ * \param form The form to submit.
+ * \param submit_button The control used to submit the form.
+ */
+nserror form_submit(struct nsurl *page_url, struct browser_window *target,
struct form *form, struct form_control *submit_button);
+
void form_radio_set(struct form_control *radio);
void form_gadget_update_value(struct form_control *control, char *value);
diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c
index 648d274..04d14aa 100644
--- a/content/handlers/html/html_interaction.c
+++ b/content/handlers/html/html_interaction.c
@@ -389,6 +389,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2 |
BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2);
+ nserror res;
+
if (drag_type != DRAGGING_NONE && !mouse &&
html->visible_select_menu != NULL) {
/* drag end: select menu */
@@ -875,9 +877,12 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
}
} else if (url) {
if (nsoption_bool(display_decoded_idn) == true) {
- if (nsurl_get_utf8(url, &url_s, &url_l) != NSERROR_OK) {
- /* Unable to obtain a decoded IDN. This is not a fatal error.
- * Ensure the string pointer is NULL so we use the encoded version. */
+ res = nsurl_get_utf8(url, &url_s, &url_l);
+ if (res != NSERROR_OK) {
+ /* Unable to obtain a decoded IDN. This is not
+ * a fatal error. Ensure the string pointer
+ * is NULL so we use the encoded version.
+ */
url_s = NULL;
}
}
@@ -1072,22 +1077,32 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
*/
switch (action) {
case ACTION_SUBMIT:
- form_submit(content_get_url(c),
- browser_window_find_target(bw, target, mouse),
- gadget->form, gadget);
+ res = form_submit(content_get_url(c),
+ browser_window_find_target(bw, target, mouse),
+ gadget->form,
+ gadget);
break;
+
case ACTION_GO:
- browser_window_navigate(browser_window_find_target(bw, target, mouse),
- url,
- content_get_url(c),
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
+ res = browser_window_navigate(
+ browser_window_find_target(bw, target, mouse),
+ url,
+ content_get_url(c),
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
break;
+
case ACTION_NONE:
+ res = NSERROR_OK;
break;
}
+
+ if (res != NSERROR_OK) {
+ guit->misc->warning(messages_get_errorcode(res), NULL);
+ }
+
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=9100fcb4095cf8858d4...
commit 9100fcb4095cf8858d4cd2c613bff69ceb4f71ec
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
improve nsurl query handling.
Alter the handling of query values within nsurl to be like fragments.
This ensures callers never have to care about the query punctuation,
e.g. the question mark
This also means the strings generated will no longer have trailing
question marks which now conforms to behaviour in whatwg url spec
on url serializing in section 4.5
diff --git a/test/nsurl.c b/test/nsurl.c
index ba02429..631e7ae 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -428,9 +428,9 @@ static const struct test_pairs join_tests[] = {
{ " ", "http://a/b/c/d;p?q" },
{ "/", "http://a/" },
{ " / ", "http://a/" },
- { " ? ", "http://a/b/c/d;p?" },
+ { " ? ", "http://a/b/c/d;p" },
{ " h ", "http://a/b/c/h" },
- { "//foo?", "http://foo/?" },
+ { "//foo?", "http://foo/" },
{ "//foo#bar", "http://foo/#bar" },
{ "//foo/", "http://foo/" },
{ "http://<!--#echo var=", "http://<!--/#echo%20var="},
@@ -531,21 +531,25 @@ END_TEST
*/
static const struct test_triplets replace_query_tests[] = {
{ "http://netsurf-browser.org/?magical=true",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win"},
{ "http://netsurf-browser.org/?magical=true#fragment",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win#fragment"},
{ "http://netsurf-browser.org/#fragment",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win#fragment"},
{ "http://netsurf-browser.org/path",
- "?magical=true",
+ "magical=true",
"http://netsurf-browser.org/path?magical=true"},
+ { "http://netsurf-browser.org/path?magical=true",
+ "",
+ "http://netsurf-browser.org/path"},
+
};
/**
@@ -655,7 +659,7 @@ static const struct test_compare component_tests[] = {
{ "http://u:p@a:66/b/c/d;p?q#f", "a", NSURL_HOST, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "66", NSURL_PORT, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "/b/c/d;p", NSURL_PATH, true },
- { "http://u:p@a:66/b/c/d;p?q#f", "?q", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q#f", "q", NSURL_QUERY, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "f", NSURL_FRAGMENT, true },
{ "file:", "file", NSURL_SCHEME, true },
@@ -667,6 +671,11 @@ static const struct test_compare component_tests[] = {
{ "file:", NULL, NSURL_QUERY, false },
{ "file:", NULL, NSURL_FRAGMENT, false },
+ { "http://u:p@a:66/b/c/d;p?q=v#f", "q=v", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v", "q=v", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v&q1=v1#f", "q=v&q1=v1", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v&q1=v1", "q=v&q1=v1", NSURL_QUERY, true },
+
};
@@ -1167,12 +1176,11 @@ START_TEST(nsurl_api_assert_replace_query3_test)
nsurl *url;
nsurl *res;
nserror err;
- const char *rel = "moo";
err = nsurl_create(base_str, &url);
ck_assert(err == NSERROR_OK);
- err = nsurl_replace_query(url, rel, &res);
+ err = nsurl_replace_query(url, NULL, &res);
ck_assert(err != NSERROR_OK);
nsurl_unref(url);
diff --git a/utils/nsurl.h b/utils/nsurl.h
index bc6e910..c6590bd 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -313,6 +313,9 @@ nserror nsurl_refragment(const nsurl *url, lwc_string *frag, nsurl **new_url);
* the created object.
*
* Any query component in url is replaced with query in new_url.
+ *
+ * Passing the empty string as a replacement will result in the query
+ * component being removed.
*/
nserror nsurl_replace_query(const nsurl *url, const char *query,
nsurl **new_url);
diff --git a/utils/nsurl/nsurl.c b/utils/nsurl/nsurl.c
index 4dbbe96..38c0e53 100644
--- a/utils/nsurl/nsurl.c
+++ b/utils/nsurl/nsurl.c
@@ -54,7 +54,7 @@
* Does nothing if the components are the same, so ensure match is
* preset to true.
*/
-#define nsurl__component_compare(c1, c2, match) \
+#define nsurl__component_compare(c1, c2, match) \
if (c1 && c2 && lwc_error_ok == \
lwc_string_isequal(c1, c2, match)) { \
/* do nothing */ \
@@ -364,7 +364,7 @@ nserror nsurl_get_utf8(const nsurl *url, char **url_s, size_t *url_l)
}
*url_l = scheme_len + idna_host_len + path_len + 1; /* +1 for \0 */
- *url_s = malloc(*url_l);
+ *url_s = malloc(*url_l);
if (*url_s == NULL) {
err = NSERROR_NOMEM;
@@ -574,57 +574,67 @@ nserror nsurl_refragment(const nsurl *url, lwc_string *frag, nsurl **new_url)
nserror nsurl_replace_query(const nsurl *url, const char *query,
nsurl **new_url)
{
- int query_len; /* Length of new query string, including '?' */
- int frag_len = 0; /* Length of fragment, including '#' */
- int base_len; /* Length of URL up to start of query */
- char *pos;
- size_t len;
- lwc_string *lwc_query;
+ int query_len; /* Length of new query string excluding '?' */
+ int frag_len = 0; /* Length of fragment, excluding '#' */
+ int base_len; /* Length of URL up to start of query */
+ char *pos; /* current position in output string */
+ size_t length; /* new url string length */
+ lwc_string *lwc_query = NULL;
assert(url != NULL);
assert(query != NULL);
- assert(query[0] == '?');
- /* Get the length of the new query */
- query_len = strlen(query);
+ length = query_len = strlen(query);
+ if (query_len > 0) {
+ length++; /* allow for '?' */
+
+ /* intern string */
+ if (lwc_intern_string(query,
+ query_len,
+ &lwc_query) != lwc_error_ok) {
+ return NSERROR_NOMEM;
+ }
+ }
/* Find the change in length from url to new_url */
base_len = url->length;
if (url->components.query != NULL) {
- base_len -= lwc_string_length(url->components.query);
+ base_len -= (1 + lwc_string_length(url->components.query));
}
if (url->components.fragment != NULL) {
- frag_len = 1 + lwc_string_length(url->components.fragment);
- base_len -= frag_len;
+ frag_len = lwc_string_length(url->components.fragment);
+ base_len -= (1 + frag_len);
+ length += frag_len + 1; /* allow for '#' */
}
- /* Set new_url's length */
- len = base_len + query_len + frag_len;
+ /* compute new url string length */
+ length += base_len;
/* Create NetSurf URL object */
- *new_url = malloc(sizeof(nsurl) + len + 1); /* Add 1 for \0 */
+ *new_url = malloc(sizeof(nsurl) + length + 1); /* Add 1 for \0 */
if (*new_url == NULL) {
+ if (query_len > 0) {
+ lwc_string_unref(lwc_query);
+ }
return NSERROR_NOMEM;
}
- if (lwc_intern_string(query, query_len, &lwc_query) != lwc_error_ok) {
- free(*new_url);
- return NSERROR_NOMEM;
- }
-
- (*new_url)->length = len;
+ (*new_url)->length = length;
/* Set string */
pos = (*new_url)->string;
memcpy(pos, url->string, base_len);
pos += base_len;
- memcpy(pos, query, query_len);
- pos += query_len;
+ if (query_len > 0) {
+ *pos = '?';
+ memcpy(++pos, query, query_len);
+ pos += query_len;
+ }
if (url->components.fragment != NULL) {
const char *frag = lwc_string_data(url->components.fragment);
*pos = '#';
- memcpy(++pos, frag, frag_len - 1);
- pos += frag_len - 1;
+ memcpy(++pos, frag, frag_len);
+ pos += frag_len;
}
*pos = '\0';
@@ -945,4 +955,3 @@ nserror nsurl_parent(const nsurl *url, nsurl **new_url)
return NSERROR_OK;
}
-
diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c
index 3e3c521..3b8816d 100644
--- a/utils/nsurl/parse.c
+++ b/utils/nsurl/parse.c
@@ -344,7 +344,7 @@ static void nsurl__get_string_markers(const char * const url_s,
* and in the case of mailto: when we assume there is an authority.
*/
if ((*pos == '/' && *(pos + 1) == '/') ||
- (is_http && ((joining && *pos == '/') ||
+ (is_http && ((joining && *pos == '/') ||
(joining == false &&
marker.scheme_end != marker.start))) ||
marker.scheme_type == NSURL_SCHEME_MAILTO) {
@@ -577,7 +577,7 @@ static size_t nsurl__remove_dot_segments(char *path, char *output)
/* Copy up to but not including next '/' */
while ((*path_pos != '/') && (*path_pos != '\0'))
- *output_pos++ = *path_pos++;
+ *output_pos++ = *path_pos++;
}
return output_pos - output;
@@ -671,7 +671,9 @@ static nserror nsurl__create_from_section(const char * const url_s,
break;
case URL_QUERY:
- start = pegs->query;
+ start = (*(url_s + pegs->query) != '?') ?
+ pegs->query :
+ pegs->query + 1;
end = pegs->fragment;
break;
@@ -1085,6 +1087,15 @@ static void nsurl__get_string_data(const struct nsurl_components *url,
*url_l += SLEN("@");
}
+ /* spanned query question mark */
+ if ((flags & ~(NSURL_F_QUERY | NSURL_F_FRAGMENT)) &&
+ (flags & NSURL_F_QUERY)) {
+ flags |= NSURL_F_QUERY_PUNCTUATION;
+
+ *url_l += SLEN("?");
+ }
+
+ /* spanned fragment hash mark */
if ((flags & ~NSURL_F_FRAGMENT) && (flags & NSURL_F_FRAGMENT)) {
flags |= NSURL_F_FRAGMENT_PUNCTUATION;
@@ -1158,6 +1169,8 @@ static void nsurl__get_string(const struct nsurl_components *url, char *url_s,
}
if (flags & NSURL_F_QUERY) {
+ if (flags & NSURL_F_QUERY_PUNCTUATION)
+ *(pos++) = '?';
memcpy(pos, lwc_string_data(url->query), l->query);
pos += l->query;
}
@@ -1557,4 +1570,3 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
return NSERROR_OK;
}
-
diff --git a/utils/nsurl/private.h b/utils/nsurl/private.h
index 4366ff6..06f143f 100644
--- a/utils/nsurl/private.h
+++ b/utils/nsurl/private.h
@@ -105,9 +105,10 @@ enum nsurl_string_flags {
NSURL_F_HOST |
NSURL_F_PORT),
NSURL_F_PATH = (1 << 8),
- NSURL_F_QUERY = (1 << 9),
- NSURL_F_FRAGMENT_PUNCTUATION = (1 << 10),
- NSURL_F_FRAGMENT = (1 << 11)
+ NSURL_F_QUERY_PUNCTUATION = (1 << 9),
+ NSURL_F_QUERY = (1 << 10),
+ NSURL_F_FRAGMENT_PUNCTUATION = (1 << 11),
+ NSURL_F_FRAGMENT = (1 << 12)
};
/**
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=83512a6ff529c7c5cb6...
commit 83512a6ff529c7c5cb6315167cba1cf132e6a67a
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
squash clang warning about increased alignment requirements.
diff --git a/frontends/gtk/gdk.c b/frontends/gtk/gdk.c
index fd82af5..2912862 100644
--- a/frontends/gtk/gdk.c
+++ b/frontends/gtk/gdk.c
@@ -33,7 +33,8 @@ convert_alpha(guchar *dest_data,
int x, y;
for (y = 0; y < height; y++) {
- guint32 *src = (guint32 *) src_data;
+ /* this cast is safe, the buffer is appropriately aligned */
+ guint32 *src = (void *) src_data;
for (x = 0; x < width; x++) {
guint alpha = src[x] >> 24;
-----------------------------------------------------------------------
Summary of changes:
content/fetch.h | 18 ++-
content/handlers/html/box_textarea.c | 17 ++-
content/handlers/html/form.c | 224 +++++++++++++++---------------
content/handlers/html/form_internal.h | 35 ++---
content/handlers/html/html_interaction.c | 41 ++++--
frontends/gtk/gdk.c | 3 +-
test/nsurl.c | 26 ++--
utils/nsurl.h | 3 +
utils/nsurl/nsurl.c | 65 +++++----
utils/nsurl/parse.c | 20 ++-
utils/nsurl/private.h | 7 +-
11 files changed, 256 insertions(+), 203 deletions(-)
diff --git a/content/fetch.h b/content/fetch.h
index 5521778..0b4b52a 100644
--- a/content/fetch.h
+++ b/content/fetch.h
@@ -74,16 +74,22 @@ typedef struct fetch_msg {
} data;
} fetch_msg;
-/** Fetch POST multipart data */
+/**
+ * Fetch POST multipart data
+ */
struct fetch_multipart_data {
- bool file; /**< Item is a file */
- char *name; /**< Name of item */
- char *value; /**< Item value */
- char *rawfile; /**< Raw filename if file is true */
+ struct fetch_multipart_data *next; /**< Next in linked list */
+
+ char *name; /**< Name of item */
+ char *value; /**< Item value */
- struct fetch_multipart_data *next; /**< Next in linked list */
+ char *rawfile; /**< Raw filename if file is true */
+ bool file; /**< Item is a file */
};
+/**
+ * ssl certificate information for certificate error message
+ */
struct ssl_cert_info {
long version; /**< Certificate version */
char not_before[32]; /**< Valid from date */
diff --git a/content/handlers/html/box_textarea.c b/content/handlers/html/box_textarea.c
index c19afbb..f0ba9f9 100644
--- a/content/handlers/html/box_textarea.c
+++ b/content/handlers/html/box_textarea.c
@@ -25,8 +25,11 @@
#include "utils/config.h"
#include "utils/log.h"
+#include "utils/messages.h"
#include "netsurf/keypress.h"
+#include "netsurf/misc.h"
#include "desktop/textarea.h"
+#include "desktop/gui_internal.h"
#include "html/html_internal.h"
#include "html/box.h"
@@ -41,6 +44,7 @@ bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key)
struct textarea *ta = gadget->data.text.ta;
struct form* form = box->gadget->form;
struct content *c = (struct content *) html;
+ nserror res;
assert(ta != NULL);
@@ -48,9 +52,16 @@ bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key)
switch (key) {
case NS_KEY_NL:
case NS_KEY_CR:
- if (form)
- form_submit(content_get_url(c), html->bw,
- form, 0);
+ if (form) {
+ res = form_submit(content_get_url(c),
+ html->bw,
+ form,
+ NULL);
+ if (res != NSERROR_OK) {
+ guit->misc->warning(messages_get_errorcode(res), NULL);
+ }
+
+ }
return true;
case NS_KEY_TAB:
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c
index 4a9d710..f779f07 100644
--- a/content/handlers/html/form.c
+++ b/content/handlers/html/form.c
@@ -327,10 +327,28 @@ bool form_add_option(struct form_control *control, char *value, char *text,
}
-/* exported interface documented in html/form_internal.h */
-bool form_successful_controls_dom(struct form *_form,
- struct form_control *_submit_button,
- struct fetch_multipart_data **successful_controls)
+/**
+ * Identify 'successful' controls via the DOM.
+ *
+ * All text strings in the successful controls list will be in the charset most
+ * appropriate for submission. Therefore, no utf8_to_* processing should be
+ * performed upon them.
+ *
+ * \todo The chosen charset needs to be made available such that it can be
+ * included in the submission request (e.g. in the fetch's Content-Type header)
+ *
+ * See HTML 4.01 section 17.13.2.
+ *
+ * \param[in] form form to search for successful controls
+ * \param[in] submit_button control used to submit the form, if any
+ * \param[out] successful_controls updated to point to linked list of
+ * fetch_multipart_data, NULL if no controls
+ * \return NSERROR_OK on success or appropriate error code
+ */
+static nserror
+form_successful_controls_dom(struct form *_form,
+ struct form_control *_submit_button,
+ struct fetch_multipart_data **successful_controls)
{
dom_html_form_element *form = _form->node;
dom_html_element *submit_button = (_submit_button != NULL) ? _submit_button->node : NULL;
@@ -352,7 +370,7 @@ bool form_successful_controls_dom(struct form *_form,
charset = form_acceptable_charset(_form);
if (charset == NULL) {
NSLOG(netsurf, INFO, "failed to find charset");
- return false;
+ return NSERROR_NOMEM;
}
#define ENCODE_ITEM(i) (((i) == NULL) ? ( \
@@ -685,6 +703,11 @@ bool form_successful_controls_dom(struct form *_form,
}
basename = ENCODE_ITEM(inputname);
+ if (basename == NULL) {
+ NSLOG(netsurf, INFO,
+ "Could not encode basename");
+ goto dom_no_memory;
+ }
success_new = calloc(1, sizeof(*success_new));
if (success_new == NULL) {
@@ -704,6 +727,8 @@ bool form_successful_controls_dom(struct form *_form,
"Could not allocate name for image.x");
goto dom_no_memory;
}
+ sprintf(success_new->name, "%s.x", basename);
+
success_new->value = malloc(20);
if (success_new->value == NULL) {
free(basename);
@@ -711,7 +736,6 @@ bool form_successful_controls_dom(struct form *_form,
"Could not allocate value for image.x");
goto dom_no_memory;
}
- sprintf(success_new->name, "%s.x", basename);
sprintf(success_new->value, "%d", coords->x);
success_new = calloc(1, sizeof(*success_new));
@@ -890,7 +914,7 @@ bool form_successful_controls_dom(struct form *_form,
*successful_controls = sentinel.next;
- return true;
+ return NSERROR_OK;
dom_no_memory:
free(charset);
@@ -915,73 +939,61 @@ dom_no_memory:
if (rawfile_temp != NULL)
free(rawfile_temp);
- return false;
+ return NSERROR_NOMEM;
}
#undef ENCODE_ITEM
/**
* Encode controls using application/x-www-form-urlencoded.
*
- * \param form form to which successful controls relate
- * \param control linked list of fetch_multipart_data
- * \param query_string iff true add '?' to the start of returned data
- * \return URL-encoded form, or 0 on memory exhaustion
+ * \param[in] form form to which successful controls relate
+ * \param[in] control linked list of fetch_multipart_data
+ * \param[out] encoded_out URL-encoded form data
+ * \return NSERROR_OK on success and \a encoded_out updated else appropriate error code
*/
-
-static char *form_url_encode(struct form *form,
+static nserror
+form_url_encode(struct form *form,
struct fetch_multipart_data *control,
- bool query_string)
+ char **encoded_out)
{
char *name, *value;
char *s, *s2;
unsigned int len, len1, len_init;
- nserror url_err;
+ nserror res;
- if (query_string)
- s = malloc(2);
- else
- s = malloc(1);
+ s = malloc(1);
- if (s == NULL)
- return NULL;
-
- if (query_string) {
- s[0] = '?';
- s[1] = '\0';
- len_init = len = 1;
- } else {
- s[0] = '\0';
- len_init = len = 0;
+ if (s == NULL) {
+ return NSERROR_NOMEM;
}
+ s[0] = '\0';
+ len_init = len = 0;
+
for (; control; control = control->next) {
- url_err = url_escape(control->name, true, NULL, &name);
- if (url_err == NSERROR_NOMEM) {
+ res = url_escape(control->name, true, NULL, &name);
+ if (res != NSERROR_OK) {
free(s);
- return NULL;
+ return res;
}
- assert(url_err == NSERROR_OK);
-
- url_err = url_escape(control->value, true, NULL, &value);
- if (url_err == NSERROR_NOMEM) {
+ res = url_escape(control->value, true, NULL, &value);
+ if (res != NSERROR_OK) {
free(name);
free(s);
- return NULL;
+ return res;
}
- assert(url_err == NSERROR_OK);
-
/* resize string to allow for new key/value pair,
* equals, amphersand and terminator
*/
len1 = len + strlen(name) + strlen(value) + 2;
s2 = realloc(s, len1 + 1);
- if (!s2) {
+ if (s2 == NULL) {
free(value);
free(name);
free(s);
- return NULL;
+ return NSERROR_NOMEM;
}
s = s2;
@@ -995,7 +1007,10 @@ static char *form_url_encode(struct form *form,
/* Replace trailing '&' */
s[len - 1] = '\0';
}
- return s;
+
+ *encoded_out = s;
+
+ return NSERROR_OK;
}
/**
@@ -1008,17 +1023,15 @@ char *form_acceptable_charset(struct form *form)
{
char *temp, *c;
- if (!form)
- return NULL;
-
if (!form->accept_charsets) {
/* no accept-charsets attribute for this form */
- if (form->document_charset)
+ if (form->document_charset) {
/* document charset present, so use it */
return strdup(form->document_charset);
- else
+ } else {
/* no document charset, so default to 8859-1 */
return strdup("ISO-8859-1");
+ }
}
/* make temporary copy of accept-charsets attribute */
@@ -1768,98 +1781,85 @@ void form_radio_set(struct form_control *radio)
}
-/**
- * Collect controls and submit a form.
- */
-
-void form_submit(nsurl *page_url, struct browser_window *target,
- struct form *form, struct form_control *submit_button)
+/* private interface described in html/form_internal.h */
+nserror
+form_submit(nsurl *page_url,
+ struct browser_window *target,
+ struct form *form,
+ struct form_control *submit_button)
{
- char *data = NULL;
- struct fetch_multipart_data *success;
+ nserror res;
+ char *data = NULL; /* encoded form data */
+ struct fetch_multipart_data *success = NULL; /* gcc is incapable of correctly reasoning about use and generates "maybe used uninitialised" warnings */
nsurl *action_url;
- nsurl *action_query;
- nserror error;
+ nsurl *query_url;
assert(form != NULL);
- if (form_successful_controls_dom(form, submit_button, &success) == false) {
- guit->misc->warning("NoMemory", 0);
- return;
+ /* obtain list of controls from DOM */
+ res = form_successful_controls_dom(form, submit_button, &success);
+ if (res != NSERROR_OK) {
+ return res;
}
/* Decompose action */
- if (nsurl_create(form->action, &action_url) != NSERROR_OK) {
- free(data);
+ res = nsurl_create(form->action, &action_url);
+ if (res != NSERROR_OK) {
fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- return;
+ return res;
}
switch (form->method) {
case method_GET:
- data = form_url_encode(form, success, true);
- if (data == NULL) {
- fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- return;
- }
-
- /* Replace query segment */
- error = nsurl_replace_query(action_url, data, &action_query);
- if (error != NSERROR_OK) {
- nsurl_unref(action_query);
+ res = form_url_encode(form, success, &data);
+ if (res == NSERROR_OK) {
+ /* Replace query segment */
+ res = nsurl_replace_query(action_url, data, &query_url);
+ if (res == NSERROR_OK) {
+ res = browser_window_navigate(target,
+ query_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
+
+ nsurl_unref(query_url);
+ }
free(data);
- fetch_multipart_data_destroy(success);
- guit->misc->warning(messages_get_errorcode(error), 0);
- return;
}
-
- /* Construct submit url */
- browser_window_navigate(target,
- action_query,
- page_url,
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
-
- nsurl_unref(action_query);
break;
case method_POST_URLENC:
- data = form_url_encode(form, success, false);
- if (data == NULL) {
- fetch_multipart_data_destroy(success);
- guit->misc->warning("NoMemory", 0);
- nsurl_unref(action_url);
- return;
+ res = form_url_encode(form, success, &data);
+ if (res == NSERROR_OK) {
+ res = browser_window_navigate(target,
+ action_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ data,
+ NULL,
+ NULL);
+ free(data);
}
-
- browser_window_navigate(target,
- action_url,
- page_url,
- BW_NAVIGATE_HISTORY,
- data,
- NULL,
- NULL);
break;
case method_POST_MULTIPART:
- browser_window_navigate(target,
- action_url,
- page_url,
- BW_NAVIGATE_HISTORY,
- NULL,
- success,
- NULL);
+ res = browser_window_navigate(target,
+ action_url,
+ page_url,
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ success,
+ NULL);
break;
}
nsurl_unref(action_url);
fetch_multipart_data_destroy(success);
- free(data);
+
+ return res;
}
void form_gadget_update_value(struct form_control *control, char *value)
diff --git a/content/handlers/html/form_internal.h b/content/handlers/html/form_internal.h
index a77e823..f76f126 100644
--- a/content/handlers/html/form_internal.h
+++ b/content/handlers/html/form_internal.h
@@ -195,29 +195,6 @@ bool form_successful_controls(struct form *form,
struct fetch_multipart_data **successful_controls);
/**
- * Identify 'successful' controls via the DOM.
- *
- * All text strings in the successful controls list will be in the charset most
- * appropriate for submission. Therefore, no utf8_to_* processing should be
- * performed upon them.
- *
- * \todo The chosen charset needs to be made available such that it can be
- * included in the submission request (e.g. in the fetch's Content-Type header)
- *
- * See HTML 4.01 section 17.13.2.
- *
- * \param[in] form form to search for successful controls
- * \param[in] submit_button control used to submit the form, if any
- * \param[out] successful_controls updated to point to linked list of
- * fetch_multipart_data, 0 if no controls
- * \return true on success, false on memory exhaustion
- */
-bool form_successful_controls_dom(struct form *form,
- struct form_control *submit_button,
- struct fetch_multipart_data **successful_controls);
-
-
-/**
* Open a select menu for a select form control, creating it if necessary.
*
* \param client_data data passed to the redraw callback
@@ -268,8 +245,18 @@ void form_select_mouse_drag_end(struct form_control *control,
enum browser_mouse_state mouse, int x, int y);
void form_select_get_dimensions(struct form_control *control,
int *width, int *height);
-void form_submit(struct nsurl *page_url, struct browser_window *target,
+
+/**
+ * navigate browser window based on form submission.
+ *
+ * \param page_url content url
+ * \param target The browsing context in which the navigation will occour.
+ * \param form The form to submit.
+ * \param submit_button The control used to submit the form.
+ */
+nserror form_submit(struct nsurl *page_url, struct browser_window *target,
struct form *form, struct form_control *submit_button);
+
void form_radio_set(struct form_control *radio);
void form_gadget_update_value(struct form_control *control, char *value);
diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c
index 648d274..04d14aa 100644
--- a/content/handlers/html/html_interaction.c
+++ b/content/handlers/html/html_interaction.c
@@ -389,6 +389,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2 |
BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2);
+ nserror res;
+
if (drag_type != DRAGGING_NONE && !mouse &&
html->visible_select_menu != NULL) {
/* drag end: select menu */
@@ -875,9 +877,12 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
}
} else if (url) {
if (nsoption_bool(display_decoded_idn) == true) {
- if (nsurl_get_utf8(url, &url_s, &url_l) != NSERROR_OK) {
- /* Unable to obtain a decoded IDN. This is not a fatal error.
- * Ensure the string pointer is NULL so we use the encoded version. */
+ res = nsurl_get_utf8(url, &url_s, &url_l);
+ if (res != NSERROR_OK) {
+ /* Unable to obtain a decoded IDN. This is not
+ * a fatal error. Ensure the string pointer
+ * is NULL so we use the encoded version.
+ */
url_s = NULL;
}
}
@@ -1072,22 +1077,32 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
*/
switch (action) {
case ACTION_SUBMIT:
- form_submit(content_get_url(c),
- browser_window_find_target(bw, target, mouse),
- gadget->form, gadget);
+ res = form_submit(content_get_url(c),
+ browser_window_find_target(bw, target, mouse),
+ gadget->form,
+ gadget);
break;
+
case ACTION_GO:
- browser_window_navigate(browser_window_find_target(bw, target, mouse),
- url,
- content_get_url(c),
- BW_NAVIGATE_HISTORY,
- NULL,
- NULL,
- NULL);
+ res = browser_window_navigate(
+ browser_window_find_target(bw, target, mouse),
+ url,
+ content_get_url(c),
+ BW_NAVIGATE_HISTORY,
+ NULL,
+ NULL,
+ NULL);
break;
+
case ACTION_NONE:
+ res = NSERROR_OK;
break;
}
+
+ if (res != NSERROR_OK) {
+ guit->misc->warning(messages_get_errorcode(res), NULL);
+ }
+
}
diff --git a/frontends/gtk/gdk.c b/frontends/gtk/gdk.c
index fd82af5..2912862 100644
--- a/frontends/gtk/gdk.c
+++ b/frontends/gtk/gdk.c
@@ -33,7 +33,8 @@ convert_alpha(guchar *dest_data,
int x, y;
for (y = 0; y < height; y++) {
- guint32 *src = (guint32 *) src_data;
+ /* this cast is safe, the buffer is appropriately aligned */
+ guint32 *src = (void *) src_data;
for (x = 0; x < width; x++) {
guint alpha = src[x] >> 24;
diff --git a/test/nsurl.c b/test/nsurl.c
index ba02429..631e7ae 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -428,9 +428,9 @@ static const struct test_pairs join_tests[] = {
{ " ", "http://a/b/c/d;p?q" },
{ "/", "http://a/" },
{ " / ", "http://a/" },
- { " ? ", "http://a/b/c/d;p?" },
+ { " ? ", "http://a/b/c/d;p" },
{ " h ", "http://a/b/c/h" },
- { "//foo?", "http://foo/?" },
+ { "//foo?", "http://foo/" },
{ "//foo#bar", "http://foo/#bar" },
{ "//foo/", "http://foo/" },
{ "http://<!--#echo var=", "http://<!--/#echo%20var="},
@@ -531,21 +531,25 @@ END_TEST
*/
static const struct test_triplets replace_query_tests[] = {
{ "http://netsurf-browser.org/?magical=true",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win"},
{ "http://netsurf-browser.org/?magical=true#fragment",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win#fragment"},
{ "http://netsurf-browser.org/#fragment",
- "?magical=true&result=win",
+ "magical=true&result=win",
"http://netsurf-browser.org/?magical=true&result=win#fragment"},
{ "http://netsurf-browser.org/path",
- "?magical=true",
+ "magical=true",
"http://netsurf-browser.org/path?magical=true"},
+ { "http://netsurf-browser.org/path?magical=true",
+ "",
+ "http://netsurf-browser.org/path"},
+
};
/**
@@ -655,7 +659,7 @@ static const struct test_compare component_tests[] = {
{ "http://u:p@a:66/b/c/d;p?q#f", "a", NSURL_HOST, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "66", NSURL_PORT, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "/b/c/d;p", NSURL_PATH, true },
- { "http://u:p@a:66/b/c/d;p?q#f", "?q", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q#f", "q", NSURL_QUERY, true },
{ "http://u:p@a:66/b/c/d;p?q#f", "f", NSURL_FRAGMENT, true },
{ "file:", "file", NSURL_SCHEME, true },
@@ -667,6 +671,11 @@ static const struct test_compare component_tests[] = {
{ "file:", NULL, NSURL_QUERY, false },
{ "file:", NULL, NSURL_FRAGMENT, false },
+ { "http://u:p@a:66/b/c/d;p?q=v#f", "q=v", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v", "q=v", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v&q1=v1#f", "q=v&q1=v1", NSURL_QUERY, true },
+ { "http://u:p@a:66/b/c/d;p?q=v&q1=v1", "q=v&q1=v1", NSURL_QUERY, true },
+
};
@@ -1167,12 +1176,11 @@ START_TEST(nsurl_api_assert_replace_query3_test)
nsurl *url;
nsurl *res;
nserror err;
- const char *rel = "moo";
err = nsurl_create(base_str, &url);
ck_assert(err == NSERROR_OK);
- err = nsurl_replace_query(url, rel, &res);
+ err = nsurl_replace_query(url, NULL, &res);
ck_assert(err != NSERROR_OK);
nsurl_unref(url);
diff --git a/utils/nsurl.h b/utils/nsurl.h
index bc6e910..c6590bd 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -313,6 +313,9 @@ nserror nsurl_refragment(const nsurl *url, lwc_string *frag, nsurl **new_url);
* the created object.
*
* Any query component in url is replaced with query in new_url.
+ *
+ * Passing the empty string as a replacement will result in the query
+ * component being removed.
*/
nserror nsurl_replace_query(const nsurl *url, const char *query,
nsurl **new_url);
diff --git a/utils/nsurl/nsurl.c b/utils/nsurl/nsurl.c
index 4dbbe96..38c0e53 100644
--- a/utils/nsurl/nsurl.c
+++ b/utils/nsurl/nsurl.c
@@ -54,7 +54,7 @@
* Does nothing if the components are the same, so ensure match is
* preset to true.
*/
-#define nsurl__component_compare(c1, c2, match) \
+#define nsurl__component_compare(c1, c2, match) \
if (c1 && c2 && lwc_error_ok == \
lwc_string_isequal(c1, c2, match)) { \
/* do nothing */ \
@@ -364,7 +364,7 @@ nserror nsurl_get_utf8(const nsurl *url, char **url_s, size_t *url_l)
}
*url_l = scheme_len + idna_host_len + path_len + 1; /* +1 for \0 */
- *url_s = malloc(*url_l);
+ *url_s = malloc(*url_l);
if (*url_s == NULL) {
err = NSERROR_NOMEM;
@@ -574,57 +574,67 @@ nserror nsurl_refragment(const nsurl *url, lwc_string *frag, nsurl **new_url)
nserror nsurl_replace_query(const nsurl *url, const char *query,
nsurl **new_url)
{
- int query_len; /* Length of new query string, including '?' */
- int frag_len = 0; /* Length of fragment, including '#' */
- int base_len; /* Length of URL up to start of query */
- char *pos;
- size_t len;
- lwc_string *lwc_query;
+ int query_len; /* Length of new query string excluding '?' */
+ int frag_len = 0; /* Length of fragment, excluding '#' */
+ int base_len; /* Length of URL up to start of query */
+ char *pos; /* current position in output string */
+ size_t length; /* new url string length */
+ lwc_string *lwc_query = NULL;
assert(url != NULL);
assert(query != NULL);
- assert(query[0] == '?');
- /* Get the length of the new query */
- query_len = strlen(query);
+ length = query_len = strlen(query);
+ if (query_len > 0) {
+ length++; /* allow for '?' */
+
+ /* intern string */
+ if (lwc_intern_string(query,
+ query_len,
+ &lwc_query) != lwc_error_ok) {
+ return NSERROR_NOMEM;
+ }
+ }
/* Find the change in length from url to new_url */
base_len = url->length;
if (url->components.query != NULL) {
- base_len -= lwc_string_length(url->components.query);
+ base_len -= (1 + lwc_string_length(url->components.query));
}
if (url->components.fragment != NULL) {
- frag_len = 1 + lwc_string_length(url->components.fragment);
- base_len -= frag_len;
+ frag_len = lwc_string_length(url->components.fragment);
+ base_len -= (1 + frag_len);
+ length += frag_len + 1; /* allow for '#' */
}
- /* Set new_url's length */
- len = base_len + query_len + frag_len;
+ /* compute new url string length */
+ length += base_len;
/* Create NetSurf URL object */
- *new_url = malloc(sizeof(nsurl) + len + 1); /* Add 1 for \0 */
+ *new_url = malloc(sizeof(nsurl) + length + 1); /* Add 1 for \0 */
if (*new_url == NULL) {
+ if (query_len > 0) {
+ lwc_string_unref(lwc_query);
+ }
return NSERROR_NOMEM;
}
- if (lwc_intern_string(query, query_len, &lwc_query) != lwc_error_ok) {
- free(*new_url);
- return NSERROR_NOMEM;
- }
-
- (*new_url)->length = len;
+ (*new_url)->length = length;
/* Set string */
pos = (*new_url)->string;
memcpy(pos, url->string, base_len);
pos += base_len;
- memcpy(pos, query, query_len);
- pos += query_len;
+ if (query_len > 0) {
+ *pos = '?';
+ memcpy(++pos, query, query_len);
+ pos += query_len;
+ }
if (url->components.fragment != NULL) {
const char *frag = lwc_string_data(url->components.fragment);
*pos = '#';
- memcpy(++pos, frag, frag_len - 1);
- pos += frag_len - 1;
+ memcpy(++pos, frag, frag_len);
+ pos += frag_len;
}
*pos = '\0';
@@ -945,4 +955,3 @@ nserror nsurl_parent(const nsurl *url, nsurl **new_url)
return NSERROR_OK;
}
-
diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c
index 3e3c521..3b8816d 100644
--- a/utils/nsurl/parse.c
+++ b/utils/nsurl/parse.c
@@ -344,7 +344,7 @@ static void nsurl__get_string_markers(const char * const url_s,
* and in the case of mailto: when we assume there is an authority.
*/
if ((*pos == '/' && *(pos + 1) == '/') ||
- (is_http && ((joining && *pos == '/') ||
+ (is_http && ((joining && *pos == '/') ||
(joining == false &&
marker.scheme_end != marker.start))) ||
marker.scheme_type == NSURL_SCHEME_MAILTO) {
@@ -577,7 +577,7 @@ static size_t nsurl__remove_dot_segments(char *path, char *output)
/* Copy up to but not including next '/' */
while ((*path_pos != '/') && (*path_pos != '\0'))
- *output_pos++ = *path_pos++;
+ *output_pos++ = *path_pos++;
}
return output_pos - output;
@@ -671,7 +671,9 @@ static nserror nsurl__create_from_section(const char * const url_s,
break;
case URL_QUERY:
- start = pegs->query;
+ start = (*(url_s + pegs->query) != '?') ?
+ pegs->query :
+ pegs->query + 1;
end = pegs->fragment;
break;
@@ -1085,6 +1087,15 @@ static void nsurl__get_string_data(const struct nsurl_components *url,
*url_l += SLEN("@");
}
+ /* spanned query question mark */
+ if ((flags & ~(NSURL_F_QUERY | NSURL_F_FRAGMENT)) &&
+ (flags & NSURL_F_QUERY)) {
+ flags |= NSURL_F_QUERY_PUNCTUATION;
+
+ *url_l += SLEN("?");
+ }
+
+ /* spanned fragment hash mark */
if ((flags & ~NSURL_F_FRAGMENT) && (flags & NSURL_F_FRAGMENT)) {
flags |= NSURL_F_FRAGMENT_PUNCTUATION;
@@ -1158,6 +1169,8 @@ static void nsurl__get_string(const struct nsurl_components *url, char *url_s,
}
if (flags & NSURL_F_QUERY) {
+ if (flags & NSURL_F_QUERY_PUNCTUATION)
+ *(pos++) = '?';
memcpy(pos, lwc_string_data(url->query), l->query);
pos += l->query;
}
@@ -1557,4 +1570,3 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
return NSERROR_OK;
}
-
diff --git a/utils/nsurl/private.h b/utils/nsurl/private.h
index 4366ff6..06f143f 100644
--- a/utils/nsurl/private.h
+++ b/utils/nsurl/private.h
@@ -105,9 +105,10 @@ enum nsurl_string_flags {
NSURL_F_HOST |
NSURL_F_PORT),
NSURL_F_PATH = (1 << 8),
- NSURL_F_QUERY = (1 << 9),
- NSURL_F_FRAGMENT_PUNCTUATION = (1 << 10),
- NSURL_F_FRAGMENT = (1 << 11)
+ NSURL_F_QUERY_PUNCTUATION = (1 << 9),
+ NSURL_F_QUERY = (1 << 10),
+ NSURL_F_FRAGMENT_PUNCTUATION = (1 << 11),
+ NSURL_F_FRAGMENT = (1 << 12)
};
/**
--
NetSurf Browser
4 years, 12 months
netsurf: branch master updated. release/3.8-14-g1a8fdb1
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/1a8fdb1462f8a506b2043...
...commit http://git.netsurf-browser.org/netsurf.git/commit/1a8fdb1462f8a506b204387...
...tree http://git.netsurf-browser.org/netsurf.git/tree/1a8fdb1462f8a506b2043877a...
The branch, master has been updated
via 1a8fdb1462f8a506b2043877ab73cb86a9179ca6 (commit)
from 22fd851e1438afba1486f3e7a48e47435e0171f7 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=1a8fdb1462f8a506b20...
commit 1a8fdb1462f8a506b2043877ab73cb86a9179ca6
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Change logging back to INFO
diff --git a/frontends/amiga/libs.c b/frontends/amiga/libs.c
index ace24bf..cbef3c2 100644
--- a/frontends/amiga/libs.c
+++ b/frontends/amiga/libs.c
@@ -62,7 +62,7 @@
NSLOG(netsurf, INFO, " -> opened v%d.%d", ((struct Library *)PREFIX##Base)->lib_Version, ((struct Library *)PREFIX##Base)->lib_Revision); \
I##PREFIX = (struct PREFIX##IFace *)GetInterface((struct Library *)PREFIX##Base, INTERFACE, INTVER, NULL); \
if(I##PREFIX == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to get %s interface v%d of %s", INTERFACE, INTVER, LIB); \
+ NSLOG(netsurf, INFO, "Failed to get %s interface v%d of %s", INTERFACE, INTVER, LIB); \
AMINS_LIB_CLOSE(PREFIX) \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open interface %s v%d\nof %s v%ld (fatal error - not an OS4 lib?)", INTERFACE, INTVER, LIB, LIBVER); \
@@ -72,7 +72,7 @@
} \
} \
} else { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", LIB, LIBVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", LIB, LIBVER); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%ld (fatal error)", LIB, LIBVER); \
ami_misc_fatal_error(error); \
@@ -104,7 +104,7 @@
} \
} \
if(PREFIX##Class == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", CLASS, CLASSVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", CLASS, CLASSVER); \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
@@ -126,7 +126,7 @@
if((PREFIX##Base = (struct PREFIX##Base *)OpenLibrary(LIB, LIBVER))) { \
NSLOG(netsurf, INFO, " -> opened v%d.%d", ((struct Library *)PREFIX##Base)->lib_Version, ((struct Library *)PREFIX##Base)->lib_Revision); \
} else { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", LIB, LIBVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", LIB, LIBVER); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", LIB, LIBVER); \
ami_misc_fatal_error(error); \
@@ -148,7 +148,7 @@
PREFIX##Class = CLASSGET##_GetClass(); \
} \
if(PREFIX##Class == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", CLASS, CLASSVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", CLASS, CLASSVER); \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
-----------------------------------------------------------------------
Summary of changes:
frontends/amiga/libs.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/frontends/amiga/libs.c b/frontends/amiga/libs.c
index ace24bf..cbef3c2 100644
--- a/frontends/amiga/libs.c
+++ b/frontends/amiga/libs.c
@@ -62,7 +62,7 @@
NSLOG(netsurf, INFO, " -> opened v%d.%d", ((struct Library *)PREFIX##Base)->lib_Version, ((struct Library *)PREFIX##Base)->lib_Revision); \
I##PREFIX = (struct PREFIX##IFace *)GetInterface((struct Library *)PREFIX##Base, INTERFACE, INTVER, NULL); \
if(I##PREFIX == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to get %s interface v%d of %s", INTERFACE, INTVER, LIB); \
+ NSLOG(netsurf, INFO, "Failed to get %s interface v%d of %s", INTERFACE, INTVER, LIB); \
AMINS_LIB_CLOSE(PREFIX) \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open interface %s v%d\nof %s v%ld (fatal error - not an OS4 lib?)", INTERFACE, INTVER, LIB, LIBVER); \
@@ -72,7 +72,7 @@
} \
} \
} else { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", LIB, LIBVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", LIB, LIBVER); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%ld (fatal error)", LIB, LIBVER); \
ami_misc_fatal_error(error); \
@@ -104,7 +104,7 @@
} \
} \
if(PREFIX##Class == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", CLASS, CLASSVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", CLASS, CLASSVER); \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
@@ -126,7 +126,7 @@
if((PREFIX##Base = (struct PREFIX##Base *)OpenLibrary(LIB, LIBVER))) { \
NSLOG(netsurf, INFO, " -> opened v%d.%d", ((struct Library *)PREFIX##Base)->lib_Version, ((struct Library *)PREFIX##Base)->lib_Revision); \
} else { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", LIB, LIBVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", LIB, LIBVER); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", LIB, LIBVER); \
ami_misc_fatal_error(error); \
@@ -148,7 +148,7 @@
PREFIX##Class = CLASSGET##_GetClass(); \
} \
if(PREFIX##Class == NULL) { \
- NSLOG(netsurf, ERROR, "Failed to open %s v%d", CLASS, CLASSVER); \
+ NSLOG(netsurf, INFO, "Failed to open %s v%d", CLASS, CLASSVER); \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
--
NetSurf Browser
5 years
netsurf: branch master updated. release/3.8-13-g22fd851
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/22fd851e1438afba1486f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/22fd851e1438afba1486f3e...
...tree http://git.netsurf-browser.org/netsurf.git/tree/22fd851e1438afba1486f3e7a...
The branch, master has been updated
via 22fd851e1438afba1486f3e7a48e47435e0171f7 (commit)
via c3d3023e4acd8015b3f53c6fb1d55f27417fe8df (commit)
from e4537cb37ed5b075c62723c9a49348c76eeb3d5c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=22fd851e1438afba148...
commit 22fd851e1438afba1486f3e7a48e47435e0171f7
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Fix compiler version comparison test
diff --git a/Makefile b/Makefile
index 04f3263..064ae69 100644
--- a/Makefile
+++ b/Makefile
@@ -323,7 +323,7 @@ CC_VERSION := $(shell $(CC) -dumpversion)
CC_MAJOR := $(word 1,$(subst ., ,$(CC_VERSION)))
CC_MINOR := $(word 2,$(subst ., ,$(CC_VERSION)))
define cc_ver_ge
-$(shell expr $(CC_MAJOR) \>= $(1) \& $(CC_MINOR) \>= $(2))
+$(shell expr $(CC_MAJOR) \> $(1) \| \( $(CC_MAJOR) = $(1) \& $(CC_MINOR) \>= $(2) \) )
endef
# CCACHE
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=c3d3023e4acd8015b3f...
commit c3d3023e4acd8015b3f53c6fb1d55f27417fe8df
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
stop overriding non test warning flags
diff --git a/test/Makefile b/test/Makefile
index 4f9dd22..85cc7c4 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -127,15 +127,15 @@ endef
$(eval $(call pkg_cfg_detect_lib,check,Check))
-COMMON_WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wcast-align \
+TEST_WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-declarations -Wuninitialized
ifneq ($(CC_MAJOR),2)
- COMMON_WARNFLAGS += -Wno-unused-parameter
+ TEST_WARNFLAGS += -Wno-unused-parameter
endif
BASE_TESTCFLAGS := -std=c99 -g \
- $(COMMON_WARNFLAGS) \
+ $(TEST_WARNFLAGS) \
-D_DEFAULT_SOURCE \
-D_POSIX_C_SOURCE=200809L \
-D_XOPEN_SOURCE=600 \
@@ -156,7 +156,7 @@ TESTLDFLAGS := -L$(TESTROOT) \
# malloc faliure injection generator
$(TESTROOT)/libmalloc_fig.so:test/malloc_fig.c
- $(CC) -shared -fPIC -I. -std=c99 $(COMMON_WARNFLAGS) $^ -o $@
+ $(CC) -shared -fPIC -I. -std=c99 $(TEST_WARNFLAGS) $^ -o $@
# Source files for all tests being compiled
TESTSOURCES :=
-----------------------------------------------------------------------
Summary of changes:
Makefile | 2 +-
test/Makefile | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 04f3263..064ae69 100644
--- a/Makefile
+++ b/Makefile
@@ -323,7 +323,7 @@ CC_VERSION := $(shell $(CC) -dumpversion)
CC_MAJOR := $(word 1,$(subst ., ,$(CC_VERSION)))
CC_MINOR := $(word 2,$(subst ., ,$(CC_VERSION)))
define cc_ver_ge
-$(shell expr $(CC_MAJOR) \>= $(1) \& $(CC_MINOR) \>= $(2))
+$(shell expr $(CC_MAJOR) \> $(1) \| \( $(CC_MAJOR) = $(1) \& $(CC_MINOR) \>= $(2) \) )
endef
# CCACHE
diff --git a/test/Makefile b/test/Makefile
index 4f9dd22..85cc7c4 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -127,15 +127,15 @@ endef
$(eval $(call pkg_cfg_detect_lib,check,Check))
-COMMON_WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wcast-align \
+TEST_WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-declarations -Wuninitialized
ifneq ($(CC_MAJOR),2)
- COMMON_WARNFLAGS += -Wno-unused-parameter
+ TEST_WARNFLAGS += -Wno-unused-parameter
endif
BASE_TESTCFLAGS := -std=c99 -g \
- $(COMMON_WARNFLAGS) \
+ $(TEST_WARNFLAGS) \
-D_DEFAULT_SOURCE \
-D_POSIX_C_SOURCE=200809L \
-D_XOPEN_SOURCE=600 \
@@ -156,7 +156,7 @@ TESTLDFLAGS := -L$(TESTROOT) \
# malloc faliure injection generator
$(TESTROOT)/libmalloc_fig.so:test/malloc_fig.c
- $(CC) -shared -fPIC -I. -std=c99 $(COMMON_WARNFLAGS) $^ -o $@
+ $(CC) -shared -fPIC -I. -std=c99 $(TEST_WARNFLAGS) $^ -o $@
# Source files for all tests being compiled
TESTSOURCES :=
--
NetSurf Browser
5 years
libutf8proc: branch master updated. release/2.2.0-1-1-gdee1a04
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libutf8proc.git/shortlog/dee1a04b6a0234857...
...commit http://git.netsurf-browser.org/libutf8proc.git/commit/dee1a04b6a023485733...
...tree http://git.netsurf-browser.org/libutf8proc.git/tree/dee1a04b6a02348573333...
The branch, master has been updated
via dee1a04b6a0234857333325dcfdedf8450994f95 (commit)
from 282f8e43de41a586a126dac07fec36f50b78c60f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libutf8proc.git/commit/?id=dee1a04b6a02348...
commit dee1a04b6a0234857333325dcfdedf8450994f95
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
remove duplicate definition left over from merge
diff --git a/include/libutf8proc/utf8proc.h b/include/libutf8proc/utf8proc.h
index 1fd79c6..f5cc1e1 100644
--- a/include/libutf8proc/utf8proc.h
+++ b/include/libutf8proc/utf8proc.h
@@ -552,12 +552,6 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_custom(
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
/**
- * Reencodes the sequence of unicode characters given by the pointer
- * 'buffer' and 'length'. See utf8proc_reencode for further details.
- */
-UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
-
-/**
* Reencodes the sequence of `length` codepoints pointed to by `buffer`
* UTF-8 data in-place (i.e., the result is also stored in `buffer`).
* Can optionally normalize the UTF-32 sequence prior to UTF-8 conversion.
-----------------------------------------------------------------------
Summary of changes:
include/libutf8proc/utf8proc.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/include/libutf8proc/utf8proc.h b/include/libutf8proc/utf8proc.h
index 1fd79c6..f5cc1e1 100644
--- a/include/libutf8proc/utf8proc.h
+++ b/include/libutf8proc/utf8proc.h
@@ -552,12 +552,6 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_custom(
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
/**
- * Reencodes the sequence of unicode characters given by the pointer
- * 'buffer' and 'length'. See utf8proc_reencode for further details.
- */
-UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
-
-/**
* Reencodes the sequence of `length` codepoints pointed to by `buffer`
* UTF-8 data in-place (i.e., the result is also stored in `buffer`).
* Can optionally normalize the UTF-32 sequence prior to UTF-8 conversion.
--
UTF8 Processing library (import)
5 years
netsurf: branch master updated. release/3.8-11-ge4537cb
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/e4537cb37ed5b075c6272...
...commit http://git.netsurf-browser.org/netsurf.git/commit/e4537cb37ed5b075c62723c...
...tree http://git.netsurf-browser.org/netsurf.git/tree/e4537cb37ed5b075c62723c9a...
The branch, master has been updated
via e4537cb37ed5b075c62723c9a49348c76eeb3d5c (commit)
from bd8991c2f6546d42008ade8dd4db133a120c44db (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=e4537cb37ed5b075c62...
commit e4537cb37ed5b075c62723c9a49348c76eeb3d5c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
allow comments to supress implicit fallthrough warnings
diff --git a/Makefile b/Makefile
index ae1c6a2..04f3263 100644
--- a/Makefile
+++ b/Makefile
@@ -491,6 +491,11 @@ ifeq ($(call cc_ver_ge,4,6),1)
COMMON_WARNFLAGS += -Wno-unused-but-set-variable
endif
+# Implicit fallthrough warnings suppressed by comment
+ifeq ($(call cc_ver_ge,7,1),1)
+ COMMON_WARNFLAGS += -Wimplicit-fallthrough=3
+endif
+
# deal with chaging warning flags for different platforms
ifeq ($(HOST),OpenBSD)
# OpenBSD headers are not compatible with redundant declaration warning
diff --git a/content/handlers/css/hints.c b/content/handlers/css/hints.c
index 3a15f8e..d3d27fb 100644
--- a/content/handlers/css/hints.c
+++ b/content/handlers/css/hints.c
@@ -1538,22 +1538,22 @@ css_error node_presentational_hint(void *pw, void *node,
css_hint_width(pw, node);
css_hint_table_cell_border_padding(pw, node);
css_hint_white_space_nowrap(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_TR:
css_hint_height(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_THEAD:
case DOM_HTML_ELEMENT_TYPE_TBODY:
case DOM_HTML_ELEMENT_TYPE_TFOOT:
css_hint_text_align_special(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_COL:
css_hint_vertical_align_table_cells(pw, node);
break;
case DOM_HTML_ELEMENT_TYPE_APPLET:
case DOM_HTML_ELEMENT_TYPE_IMG:
css_hint_margin_hspace_vspace(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_EMBED:
case DOM_HTML_ELEMENT_TYPE_IFRAME:
case DOM_HTML_ELEMENT_TYPE_OBJECT:
@@ -1576,7 +1576,7 @@ css_error node_presentational_hint(void *pw, void *node,
break;
case DOM_HTML_ELEMENT_TYPE_CAPTION:
css_hint_caption_side(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_DIV:
css_hint_text_align_special(pw, node);
break;
diff --git a/content/handlers/html/box.c b/content/handlers/html/box.c
index 52cf124..d9e6495 100644
--- a/content/handlers/html/box.c
+++ b/content/handlers/html/box.c
@@ -505,7 +505,7 @@ static inline struct box *box_move_xy(struct box *b, enum box_walk_dir dir,
rb = b;
break;
}
- /* Fall through */
+ /* fall through */
case BOX_WALK_NEXT_SIBLING:
do {
-----------------------------------------------------------------------
Summary of changes:
Makefile | 5 +++++
content/handlers/css/hints.c | 10 +++++-----
content/handlers/html/box.c | 2 +-
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index ae1c6a2..04f3263 100644
--- a/Makefile
+++ b/Makefile
@@ -491,6 +491,11 @@ ifeq ($(call cc_ver_ge,4,6),1)
COMMON_WARNFLAGS += -Wno-unused-but-set-variable
endif
+# Implicit fallthrough warnings suppressed by comment
+ifeq ($(call cc_ver_ge,7,1),1)
+ COMMON_WARNFLAGS += -Wimplicit-fallthrough=3
+endif
+
# deal with chaging warning flags for different platforms
ifeq ($(HOST),OpenBSD)
# OpenBSD headers are not compatible with redundant declaration warning
diff --git a/content/handlers/css/hints.c b/content/handlers/css/hints.c
index 3a15f8e..d3d27fb 100644
--- a/content/handlers/css/hints.c
+++ b/content/handlers/css/hints.c
@@ -1538,22 +1538,22 @@ css_error node_presentational_hint(void *pw, void *node,
css_hint_width(pw, node);
css_hint_table_cell_border_padding(pw, node);
css_hint_white_space_nowrap(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_TR:
css_hint_height(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_THEAD:
case DOM_HTML_ELEMENT_TYPE_TBODY:
case DOM_HTML_ELEMENT_TYPE_TFOOT:
css_hint_text_align_special(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_COL:
css_hint_vertical_align_table_cells(pw, node);
break;
case DOM_HTML_ELEMENT_TYPE_APPLET:
case DOM_HTML_ELEMENT_TYPE_IMG:
css_hint_margin_hspace_vspace(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_EMBED:
case DOM_HTML_ELEMENT_TYPE_IFRAME:
case DOM_HTML_ELEMENT_TYPE_OBJECT:
@@ -1576,7 +1576,7 @@ css_error node_presentational_hint(void *pw, void *node,
break;
case DOM_HTML_ELEMENT_TYPE_CAPTION:
css_hint_caption_side(pw, node);
- /* fallthrough */
+ /* fall through */
case DOM_HTML_ELEMENT_TYPE_DIV:
css_hint_text_align_special(pw, node);
break;
diff --git a/content/handlers/html/box.c b/content/handlers/html/box.c
index 52cf124..d9e6495 100644
--- a/content/handlers/html/box.c
+++ b/content/handlers/html/box.c
@@ -505,7 +505,7 @@ static inline struct box *box_move_xy(struct box *b, enum box_walk_dir dir,
rb = b;
break;
}
- /* Fall through */
+ /* fall through */
case BOX_WALK_NEXT_SIBLING:
do {
--
NetSurf Browser
5 years
netsurf: branch master updated. release/3.8-10-gbd8991c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/bd8991c2f6546d42008ad...
...commit http://git.netsurf-browser.org/netsurf.git/commit/bd8991c2f6546d42008ade8...
...tree http://git.netsurf-browser.org/netsurf.git/tree/bd8991c2f6546d42008ade8dd...
The branch, master has been updated
via bd8991c2f6546d42008ade8dd4db133a120c44db (commit)
from 40cdf498b9153685b4cefe576e59f6b41090912b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=bd8991c2f6546d42008...
commit bd8991c2f6546d42008ade8dd4db133a120c44db
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
fix framebuffer BUILD libpng flags on freebsd
diff --git a/frontends/framebuffer/Makefile b/frontends/framebuffer/Makefile
index 3c6f31b..d36728e 100644
--- a/frontends/framebuffer/Makefile
+++ b/frontends/framebuffer/Makefile
@@ -93,8 +93,13 @@ ifeq ($(HOST),OpenBSD)
BUILD_CFLAGS += $(shell $(PKG_CONFIG) --cflags libpng)
BUILD_LDFLAGS += $(shell $(PKG_CONFIG) --libs libpng)
else
- BUILD_CFLAGS +=
- BUILD_LDFLAGS += -lpng
+ ifeq ($(HOST),FreeBSD)
+ BUILD_CFLAGS += $(shell $(PKG_CONFIG) --cflags libpng)
+ BUILD_LDFLAGS += $(shell $(PKG_CONFIG) --libs libpng)
+ else
+ BUILD_CFLAGS +=
+ BUILD_LDFLAGS += -lpng
+ endif
endif
# Host tool to convert image bitmaps to source code.
-----------------------------------------------------------------------
Summary of changes:
frontends/framebuffer/Makefile | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/frontends/framebuffer/Makefile b/frontends/framebuffer/Makefile
index 3c6f31b..d36728e 100644
--- a/frontends/framebuffer/Makefile
+++ b/frontends/framebuffer/Makefile
@@ -93,8 +93,13 @@ ifeq ($(HOST),OpenBSD)
BUILD_CFLAGS += $(shell $(PKG_CONFIG) --cflags libpng)
BUILD_LDFLAGS += $(shell $(PKG_CONFIG) --libs libpng)
else
- BUILD_CFLAGS +=
- BUILD_LDFLAGS += -lpng
+ ifeq ($(HOST),FreeBSD)
+ BUILD_CFLAGS += $(shell $(PKG_CONFIG) --cflags libpng)
+ BUILD_LDFLAGS += $(shell $(PKG_CONFIG) --libs libpng)
+ else
+ BUILD_CFLAGS +=
+ BUILD_LDFLAGS += -lpng
+ endif
endif
# Host tool to convert image bitmaps to source code.
--
NetSurf Browser
5 years