Author: jmb
Date: Tue Jan 30 23:19:21 2007
New Revision: 3159
URL:
http://svn.semichrome.net?rev=3159&view=rev
Log:
Bring handling of submission of blank file inputs in line with other browsers.
Tidy up fetch_post_convert while I'm at it.
Modified:
trunk/netsurf/content/fetch.c
trunk/netsurf/render/form.c
Modified: trunk/netsurf/content/fetch.c
URL:
http://svn.semichrome.net/trunk/netsurf/content/fetch.c?rev=3159&r1=3...
==============================================================================
--- trunk/netsurf/content/fetch.c (original)
+++ trunk/netsurf/content/fetch.c Tue Jan 30 23:19:21 2007
@@ -213,7 +213,7 @@
{
CURLcode code;
char *ua = make_useragent();
-
+
if (ua != NULL)
user_agent = ua;
@@ -1354,17 +1354,15 @@
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 @@
leafname = malloc(leaflen + 1);
if (!leafname) {
LOG(("malloc failed"));
- free(mimetype);
continue;
}
memcpy(leafname, temp, leaflen + 1);
@@ -1392,23 +1389,58 @@
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));
}
}
Modified: trunk/netsurf/render/form.c
URL:
http://svn.semichrome.net/trunk/netsurf/render/form.c?rev=3159&r1=315...
==============================================================================
--- trunk/netsurf/render/form.c (original)
+++ trunk/netsurf/render/form.c Tue Jan 30 23:19:21 2007
@@ -38,8 +38,8 @@
* \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 @@
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 @@
}
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;