]> granicus.if.org Git - curl/commitdiff
Replaced Curl_FormReadOneLine with Curl_formpostheader as that is the only use
authorDaniel Stenberg <daniel@haxx.se>
Fri, 23 Apr 2004 10:37:52 +0000 (10:37 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 23 Apr 2004 10:37:52 +0000 (10:37 +0000)
for it. It saves one extra copy of the header.

I also added comments for several functions in formdata.c

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

index 58d1547af99d1880afe33480cc9f4f12171d229e..57ad283af81c792f79e153bb39b0f6c86798a234 100644 (file)
@@ -176,7 +176,7 @@ int FormParse(char *input,
              struct curl_httppost **httppost,
              struct curl_httppost **last_post)
 {
-  /* nextarg MUST be a string in the format 'name=contents' and we'll
+  /* 'input' MUST be a string in the format 'name=contents' and we'll
      build a linked list with the info */
   char name[256];
   char *contents;
@@ -975,9 +975,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
   return return_value;
 }
 
+/*
+ * curl_formadd() is a public API to add a section to the multipart formpost.
+ */
+
 CURLFORMcode curl_formadd(struct curl_httppost **httppost,
-                 struct curl_httppost **last_post,
-                 ...)
+                          struct curl_httppost **last_post,
+                          ...)
 {
   va_list arg;
   CURLFORMcode result;
@@ -987,6 +991,9 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost,
   return result;
 }
 
+/*
+ * AddFormData() adds a chunk of data to the FormData linked list.
+ */
 static size_t AddFormData(struct FormData **formp,
                           const void *line,
                           size_t length)
@@ -1014,9 +1021,12 @@ static size_t AddFormData(struct FormData **formp,
   return length;
 }
 
+/*
+ * AddFormDataf() adds printf()-style formatted data to the formdata chain.
+ */
 
 static size_t AddFormDataf(struct FormData **formp,
-                        const char *fmt, ...)
+                           const char *fmt, ...)
 {
   char s[4096];
   va_list ap;
@@ -1027,7 +1037,10 @@ static size_t AddFormDataf(struct FormData **formp,
   return AddFormData(formp, s, 0);
 }
 
-
+/*
+ * Curl_FormBoundary() creates a suitable boundary string and returns an
+ * allocated one.
+ */
 char *Curl_FormBoundary(void)
 {
   char *retstring;
@@ -1056,7 +1069,10 @@ char *Curl_FormBoundary(void)
   return retstring;
 }
 
-/* Used from http.c, this cleans a built FormData linked list */ 
+/*
+ * Curl_formclean() is used from http.c, this cleans a built FormData linked
+ * list
+ */ 
 void Curl_formclean(struct FormData *form)
 {
   struct FormData *next;
@@ -1069,7 +1085,10 @@ void Curl_formclean(struct FormData *form)
   } while((form=next)); /* continue */
 }
 
-/* external function to free up a whole form post chain */
+/*
+ * curl_formfree() is an external function to free up a whole form post
+ * chain
+ */
 void curl_formfree(struct curl_httppost *form)
 {
   struct curl_httppost *next;
@@ -1098,6 +1117,13 @@ void curl_formfree(struct curl_httppost *form)
   } while((form=next)); /* continue */
 }
 
+/*
+ * Curl_getFormData() converts a linked list of "meta data" into a complete
+ * (possibly huge) multipart formdata. The input list is in 'post', while the
+ * output resulting linked lists gets stored in '*finalform'. *sizep will get
+ * the total size of the whole POST.
+ */
+
 CURLcode Curl_getFormData(struct FormData **finalform,
                           struct curl_httppost *post,
                           curl_off_t *sizep)
@@ -1278,6 +1304,10 @@ CURLcode Curl_getFormData(struct FormData **finalform,
   return result;
 }
 
+/*
+ * Curl_FormInit() inits the struct 'form' points to with the 'formdata'
+ * and resets the 'sent' counter.
+ */
 int Curl_FormInit(struct Form *form, struct FormData *formdata )
 {
   if(!formdata)
@@ -1289,7 +1319,10 @@ int Curl_FormInit(struct Form *form, struct FormData *formdata )
   return 0;
 }
 
-/* fread() emulation */
+/*
+ * Curl_FormReader() is the fread() emulation function that will be used to
+ * deliver the formdata to the transfer loop and then sent away to the peer.
+ */
 size_t Curl_FormReader(char *buffer,
                        size_t size,
                        size_t nitems,
@@ -1335,48 +1368,25 @@ size_t Curl_FormReader(char *buffer,
   return gotsize;
 }
 
-/* possible (old) fread() emulation that copies at most one line */
-size_t Curl_FormReadOneLine(char *buffer,
-                            size_t size,
-                            size_t nitems,
-                            FILE *mydata)
+/*
+ * Curl_formpostheader() returns the first line of the formpost, the
+ * request-header part (which is not part of the request-body like the rest of
+ * the post).
+ */
+char *Curl_formpostheader(void *formp, size_t *len)
 {
-  struct Form *form;
-  size_t wantedsize;
-  size_t gotsize;
-
-  form=(struct Form *)mydata;
-
-  wantedsize = size * nitems;
+  char *header;
+  struct Form *form=(struct Form *)formp;
 
   if(!form->data)
-    return 0; /* nothing, error, empty */
-
-  do {
-  
-    if( (form->data->length - form->sent ) > wantedsize ) {
-
-      memcpy(buffer, form->data->line + form->sent, wantedsize);
-
-      form->sent += wantedsize;
+    return 0; /* nothing, ERROR! */
 
-      return wantedsize;
-    }
-
-    memcpy(buffer,
-           form->data->line + form->sent,
-           gotsize = (form->data->length - form->sent) );
-
-    form->sent = 0;
+  header = form->data->line;
+  *len = form->data->length;
 
-    form->data = form->data->next; /* advance */
-
-  } while(!gotsize && form->data);
-  /* If we got an empty line and we have more data, we proceed to the next
-     line immediately to avoid returning zero before we've reached the end.
-     This is the bug reported November 22 1999 on curl 6.3. (Daniel) */
+  form->data = form->data->next; /* advance */
 
-  return gotsize;
+  return header;
 }
 
 
index df6ae3ac07e97dca553d79917bd519f00a98b547..d087fa7cab3e88064f5db773d4cebe7114b2eccc 100644 (file)
@@ -65,11 +65,12 @@ size_t Curl_FormReader(char *buffer,
                        size_t nitems,
                        FILE *mydata);
 
-/* possible (old) fread() emulation that copies at most one line */
-size_t Curl_FormReadOneLine(char *buffer,
-                            size_t size,
-                            size_t nitems,
-                            FILE *mydata);
+/*
+ * Curl_formpostheader() returns the first line of the formpost, the
+ * request-header part (which is not part of the request-body like the rest of
+ * the post).
+ */
+char *Curl_formpostheader(void *formp, size_t *len);
 
 char *Curl_FormBoundary(void);
 
index 0c81752d3c970eb3f5379bb90e6d47924a35acb9..1e95e1083058b3b5b1c474f9dba69eb8319b4291 100644 (file)
@@ -1686,7 +1686,7 @@ CURLcode Curl_http(struct connectdata *conn)
       }
 
       if(!checkheaders(data, "Content-Type:")) {
-        /* Get Content-Type: line from Curl_FormReadOneLine, which happens
+        /* Get Content-Type: line from Curl_formpostheader, which happens
            to always be the first line. We can know this for sure since
            we always build the formpost linked list the same way!
 
@@ -1694,13 +1694,11 @@ CURLcode Curl_http(struct connectdata *conn)
            string etc why disabling this header is likely to not make things
            work, but we support it anyway.
         */
-        char contentType[256];
+        char *contentType;
         size_t linelength=0;
-        linelength = Curl_FormReadOneLine(contentType,
-                                          sizeof(contentType),
-                                          1,
-                                          (FILE *)&http->form);
-        if(!linelength) {
+        contentType = Curl_formpostheader((void *)&http->form,
+                                          &linelength);
+        if(!contentType) {
           failf(data, "Could not get Content-Type header line!");
           return CURLE_HTTP_POST_ERROR;
         }