summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-01-30 23:19:21 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-01-30 23:19:21 +0000
commit8cf2e40daa778e71a384d4e7394c363b71d6fc63 (patch)
tree7645e036f7c8ba8b386692d5639dcd41901639e3
parent5426a708a9010d04cf8baed45ce9909a09088ef6 (diff)
downloadnetsurf-8cf2e40daa778e71a384d4e7394c363b71d6fc63.tar.gz
netsurf-8cf2e40daa778e71a384d4e7394c363b71d6fc63.tar.bz2
Bring handling of submission of blank file inputs in line with other browsers.
Tidy up fetch_post_convert while I'm at it. svn path=/trunk/netsurf/; revision=3159
-rw-r--r--content/fetch.c56
-rw-r--r--render/form.c17
2 files changed, 56 insertions, 17 deletions
diff --git a/content/fetch.c b/content/fetch.c
index cead364a2..4ce383397 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -213,7 +213,7 @@ void fetch_init(void)
{
CURLcode code;
char *ua = make_useragent();
-
+
if (ua != NULL)
user_agent = ua;
@@ -1354,17 +1354,15 @@ bool fetch_process_headers(struct fetch *f)
struct curl_httppost *fetch_post_convert(struct form_successful_control *control)
{
struct curl_httppost *post = 0, *last = 0;
- char *mimetype = 0;
- char *leafname = 0;
-#ifdef riscos
- char *temp;
- int leaflen;
-#endif
+ CURLFORMcode code;
for (; control; control = control->next) {
if (control->file) {
- mimetype = fetch_mimetype(control->value);
+ char *leafname = 0;
#ifdef riscos
+ char *temp;
+ int leaflen;
+
temp = strrchr(control->value, '.');
if (!temp)
temp = control->value; /* already leafname */
@@ -1376,7 +1374,6 @@ struct curl_httppost *fetch_post_convert(struct form_successful_control *control
leafname = malloc(leaflen + 1);
if (!leafname) {
LOG(("malloc failed"));
- free(mimetype);
continue;
}
memcpy(leafname, temp, leaflen + 1);
@@ -1392,23 +1389,58 @@ struct curl_httppost *fetch_post_convert(struct form_successful_control *control
else
leafname += 1;
#endif
- curl_formadd(&post, &last,
+ /* We have to special case filenames of "", so curl
+ * a) actually attempts the fetch and
+ * b) doesn't attempt to open the file ""
+ */
+ if (control->value[0] == '\0') {
+ /* dummy buffer - needs to be static so
+ * pointer's still valid when we go out
+ * of scope (not that libcurl should be
+ * attempting to access it, of course). */
+ static char buf;
+
+ code = curl_formadd(&post, &last,
+ CURLFORM_COPYNAME, control->name,
+ CURLFORM_BUFFER, control->value,
+ /* needed, as basename("") == "." */
+ CURLFORM_FILENAME, "",
+ CURLFORM_BUFFERPTR, &buf,
+ CURLFORM_BUFFERLENGTH, 0,
+ CURLFORM_CONTENTTYPE,
+ "application/octet-stream",
+ CURLFORM_END);
+ if (code != CURL_FORMADD_OK)
+ LOG(("curl_formadd: %d (%s)",
+ code, control->name));
+ } else {
+ char *mimetype = fetch_mimetype(control->value);
+ code = curl_formadd(&post, &last,
CURLFORM_COPYNAME, control->name,
CURLFORM_FILE, control->value,
CURLFORM_FILENAME, leafname,
CURLFORM_CONTENTTYPE,
(mimetype != 0 ? mimetype : "text/plain"),
CURLFORM_END);
+ if (code != CURL_FORMADD_OK)
+ LOG(("curl_formadd: %d (%s=%s)",
+ code, control->name,
+ control->value));
+ free(mimetype);
+ }
#ifdef riscos
free(leafname);
#endif
- free(mimetype);
}
else {
- curl_formadd(&post, &last,
+ code = curl_formadd(&post, &last,
CURLFORM_COPYNAME, control->name,
CURLFORM_COPYCONTENTS, control->value,
CURLFORM_END);
+ if (code != CURL_FORMADD_OK)
+ LOG(("curl_formadd: %d (%s=%s)", code,
+ control->name,
+ control->value));
}
}
diff --git a/render/form.c b/render/form.c
index 191985694..c646cab76 100644
--- a/render/form.c
+++ b/render/form.c
@@ -38,8 +38,8 @@ static char *form_acceptable_charset(struct form *form);
* \return a new structure, or 0 on memory exhaustion
*/
-struct form *form_new(char *action, char *target, form_method method, char *charset,
- char *doc_charset)
+struct form *form_new(char *action, char *target, form_method method,
+ char *charset, char *doc_charset)
{
struct form *form;
@@ -387,8 +387,14 @@ bool form_successful_controls(struct form *form,
case GADGET_FILE:
/* file */
- if (!control->value)
- continue;
+ /* Handling of blank file entries is
+ * implementation defined - we're perfectly
+ * within our rights to treat it as an
+ * unsuccessful control. Unfortunately, every
+ * other browser submits the field with
+ * a blank filename and no content. So,
+ * that's what we have to do, too.
+ */
success_new = malloc(sizeof(*success_new));
if (!success_new) {
LOG(("malloc failed"));
@@ -396,7 +402,8 @@ bool form_successful_controls(struct form *form,
}
success_new->file = true;
success_new->name = strdup(control->name);
- success_new->value = strdup(control->value);
+ success_new->value = strdup(control->value ?
+ control->value : "");
success_new->next = 0;
last_success->next = success_new;
last_success = success_new;