This makes formposting with a specified file missing fail. curl_easy_perform
authorDaniel Stenberg <daniel@haxx.se>
Mon, 15 Apr 2002 11:19:03 +0000 (11:19 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 15 Apr 2002 11:19:03 +0000 (11:19 +0000)
will then return CURLE_READ_ERROR.

lib/formdata.c
lib/formdata.h
lib/http.c

index 08715d5b38eb7b19c6812e31d402b598c7a705ee..e032382b1dd2e79ed3a8bccafceda6587f9bda8b 100644 (file)
@@ -1044,22 +1044,24 @@ void curl_formfree(struct curl_httppost *form)
   } while((form=next)); /* continue */
 }
 
-struct FormData *Curl_getFormData(struct curl_httppost *post,
-                                  int *sizep)
+CURLcode Curl_getFormData(struct FormData **finalform,
+                          struct curl_httppost *post,
+                          int *sizep)
 {
   struct FormData *form = NULL;
   struct FormData *firstform;
-
   struct curl_httppost *file;
+  CURLcode result = CURLE_OK;
 
   int size =0;
   char *boundary;
   char *fileboundary=NULL;
   struct curl_slist* curList;
 
+  *finalform=NULL; /* default form is empty */
 
   if(!post)
-    return NULL; /* no input => no output! */
+    return result; /* no input => no output! */
 
   boundary = Curl_FormBoundary();
   
@@ -1166,20 +1168,24 @@ struct FormData *Curl_getFormData(struct curl_httppost *post,
 /*VMS?? Stream files are OK, as are FIXED & VAR files WITHOUT implied CC */
 /*VMS?? For implied CC, every record needs to have a \n appended & 1 added to SIZE */
        if(fileread) {
-         while((nread = fread(buffer, 1, 1024, fileread))) {
-           size += AddFormData(&form,
-                               buffer,
-                               nread);
-         }
+         while((nread = fread(buffer, 1, 1024, fileread)))
+           size += AddFormData(&form, buffer, nread);
+
           if(fileread != stdin)
             fclose(fileread);
        }
         else {
+#if 0
           /* File wasn't found, add a nothing field! */
          size += AddFormData(&form, "", 0);
+#endif
+          Curl_formclean(firstform);
+          free(boundary);
+          *finalform = NULL;
+          return CURLE_READ_ERROR;
        }
       }
- else {
     else {
        /* include the contents we got */
        size += AddFormData(&form, post->contents, post->contentslength);
       }
@@ -1205,7 +1211,9 @@ struct FormData *Curl_getFormData(struct curl_httppost *post,
 
   free(boundary);
 
-  return firstform;
+  *finalform=firstform;
+
+  return result;
 }
 
 int Curl_FormInit(struct Form *form, struct FormData *formdata )
index 3dad243a3d27c1b750909aa6e13c796fce2aaaa7..1657f4122394cf12961c1a2d07855a81a32b2103 100644 (file)
@@ -53,8 +53,10 @@ typedef struct FormInfo {
 
 int Curl_FormInit(struct Form *form, struct FormData *formdata );
 
-struct FormData *Curl_getFormData(struct HttpPost *post,
-                                  int *size);
+CURLcode
+Curl_getFormData(struct FormData **,
+                 struct HttpPost *post,
+                 int *size);
 
 /* fread() emulation */
 int Curl_FormReader(char *buffer,
index 75843350978ca43ea4adf7a0e022652757c4cefd..dc074aced58b0dd555585703a50cf367355807c2 100644 (file)
@@ -562,7 +562,13 @@ CURLcode Curl_http(struct connectdata *conn)
   if(HTTPREQ_POST_FORM == data->set.httpreq) {
     /* we must build the whole darned post sequence first, so that we have
        a size of the whole shebang before we start to send it */
-    http->sendit = Curl_getFormData(data->set.httppost, &http->postsize);
+     result = Curl_getFormData(&http->sendit, data->set.httppost,
+                               &http->postsize);
+     if(CURLE_OK != result) {
+       /* Curl_getFormData() doesn't use failf() */
+       failf(data, "failed creating formpost data");
+       return result;
+     }
   }
 
   if(!checkheaders(data, "Host:")) {