1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Make this source code use our internal *printf().

Also some minor edits.
This commit is contained in:
Daniel Stenberg 2004-05-11 11:29:02 +00:00
parent 9bf1ba2f7e
commit 5c592f7dd9

View File

@ -107,18 +107,17 @@ Content-Disposition: form-data; name="FILECONTENT"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <curl/curl.h> #include <curl/curl.h>
#include "formdata.h" #include "formdata.h"
#include "strequal.h" #include "strequal.h"
#include "memory.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef CURLDEBUG
#include "memdebug.h" #include "memdebug.h"
#endif
/* Length of the random boundary string. */ /* Length of the random boundary string. */
#define BOUNDARY_LENGTH 40 #define BOUNDARY_LENGTH 40
@ -779,8 +778,8 @@ static CURLcode AddFormData(struct FormData **formp,
*/ */
static CURLcode AddFormDataf(struct FormData **formp, static CURLcode AddFormDataf(struct FormData **formp,
size_t *size, size_t *size,
const char *fmt, ...) const char *fmt, ...)
{ {
char s[4096]; char s[4096];
va_list ap; va_list ap;
@ -900,15 +899,16 @@ CURLcode Curl_getFormData(struct FormData **finalform,
boundary = Curl_FormBoundary(); boundary = Curl_FormBoundary();
/* Make the first line of the output */ /* Make the first line of the output */
result = AddFormDataf(&form, 0, result = AddFormDataf(&form, NULL,
"Content-Type: multipart/form-data;" "Content-Type: multipart/form-data;"
" boundary=%s\r\n", " boundary=%s\r\n",
boundary); boundary);
if (result != CURLE_OK) { if (result) {
free(boundary); free(boundary);
return result; return result;
} }
/* we DO NOT count that line since that'll be part of the header! */ /* we DO NOT include that line in the total size of the POST, since it'll be
part of the header! */
firstform = form; firstform = form;
@ -916,26 +916,26 @@ CURLcode Curl_getFormData(struct FormData **finalform,
if(size) { if(size) {
result = AddFormDataf(&form, &size, "\r\n"); result = AddFormDataf(&form, &size, "\r\n");
if (result != CURLE_OK) if (result)
break; break;
} }
/* boundary */ /* boundary */
result = AddFormDataf(&form, &size, "--%s\r\n", boundary); result = AddFormDataf(&form, &size, "--%s\r\n", boundary);
if (result != CURLE_OK) if (result)
break; break;
result = AddFormData(&form, result = AddFormData(&form,
"Content-Disposition: form-data; name=\"", 0, &size); "Content-Disposition: form-data; name=\"", 0, &size);
if (result != CURLE_OK) if (result)
break; break;
result = AddFormData(&form, post->name, post->namelength, &size); result = AddFormData(&form, post->name, post->namelength, &size);
if (result != CURLE_OK) if (result)
break; break;
size += AddFormData(&form, "\"", 0, &size); size += AddFormData(&form, "\"", 0, &size);
if (result != CURLE_OK) if (result)
break; break;
if(post->more) { if(post->more) {
@ -945,10 +945,10 @@ CURLcode Curl_getFormData(struct FormData **finalform,
fileboundary = Curl_FormBoundary(); fileboundary = Curl_FormBoundary();
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\nContent-Type: multipart/mixed," "\r\nContent-Type: multipart/mixed,"
" boundary=%s\r\n", " boundary=%s\r\n",
fileboundary); fileboundary);
if (result != CURLE_OK) if (result)
break; break;
} }
@ -963,31 +963,31 @@ CURLcode Curl_getFormData(struct FormData **finalform,
if(post->more) { if(post->more) {
/* if multiple-file */ /* if multiple-file */
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\n--%s\r\nContent-Disposition: " "\r\n--%s\r\nContent-Disposition: "
"attachment; filename=\"%s\"", "attachment; filename=\"%s\"",
fileboundary, fileboundary,
(file->showfilename?file->showfilename: (file->showfilename?file->showfilename:
file->contents)); file->contents));
if (result != CURLE_OK) if (result)
break; break;
} }
else if((post->flags & HTTPPOST_FILENAME) || else if((post->flags & HTTPPOST_FILENAME) ||
(post->flags & HTTPPOST_BUFFER)) { (post->flags & HTTPPOST_BUFFER)) {
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"; filename=\"%s\"", "; filename=\"%s\"",
(post->showfilename?post->showfilename: (post->showfilename?post->showfilename:
post->contents)); post->contents));
if (result != CURLE_OK) if (result)
break; break;
} }
if(file->contenttype) { if(file->contenttype) {
/* we have a specified type */ /* we have a specified type */
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\nContent-Type: %s", "\r\nContent-Type: %s",
file->contenttype); file->contenttype);
if (result != CURLE_OK) if (result)
break; break;
} }
@ -995,11 +995,11 @@ CURLcode Curl_getFormData(struct FormData **finalform,
while( curList ) { while( curList ) {
/* Process the additional headers specified for this form */ /* Process the additional headers specified for this form */
result = AddFormDataf( &form, &size, "\r\n%s", curList->data ); result = AddFormDataf( &form, &size, "\r\n%s", curList->data );
if (result != CURLE_OK) if (result)
break; break;
curList = curList->next; curList = curList->next;
} }
if (result != CURLE_OK) { if (result) {
Curl_formclean(firstform); Curl_formclean(firstform);
free(boundary); free(boundary);
return result; return result;
@ -1020,7 +1020,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
#endif #endif
result = AddFormData(&form, "\r\n\r\n", 0, &size); result = AddFormData(&form, "\r\n\r\n", 0, &size);
if (result != CURLE_OK) if (result)
break; break;
if((post->flags & HTTPPOST_FILENAME) || if((post->flags & HTTPPOST_FILENAME) ||
@ -1041,10 +1041,10 @@ CURLcode Curl_getFormData(struct FormData **finalform,
if(fileread) { if(fileread) {
while((nread = fread(buffer, 1, 1024, fileread))) { while((nread = fread(buffer, 1, 1024, fileread))) {
result = AddFormData(&form, buffer, nread, &size); result = AddFormData(&form, buffer, nread, &size);
if (result != CURLE_OK) if (result)
break; break;
} }
if (result != CURLE_OK) { if (result) {
Curl_formclean(firstform); Curl_formclean(firstform);
free(boundary); free(boundary);
return result; return result;
@ -1062,10 +1062,10 @@ CURLcode Curl_getFormData(struct FormData **finalform,
} }
else if (post->flags & HTTPPOST_BUFFER) { else if (post->flags & HTTPPOST_BUFFER) {
/* include contents of buffer */ /* include contents of buffer */
result = AddFormData(&form, post->buffer, post->bufferlength, result = AddFormData(&form, post->buffer, post->bufferlength,
&size); &size);
if (result != CURLE_OK) if (result)
break; break;
} }
@ -1073,11 +1073,11 @@ CURLcode Curl_getFormData(struct FormData **finalform,
/* include the contents we got */ /* include the contents we got */
result = AddFormData(&form, post->contents, post->contentslength, result = AddFormData(&form, post->contents, post->contentslength,
&size); &size);
if (result != CURLE_OK) if (result)
break; break;
} }
} while((file = file->more)); /* for each specified file for this field */ } while((file = file->more)); /* for each specified file for this field */
if (result != CURLE_OK) { if (result) {
Curl_formclean(firstform); Curl_formclean(firstform);
free(boundary); free(boundary);
return result; return result;
@ -1090,12 +1090,12 @@ CURLcode Curl_getFormData(struct FormData **finalform,
"\r\n--%s--", "\r\n--%s--",
fileboundary); fileboundary);
free(fileboundary); free(fileboundary);
if (result != CURLE_OK) if (result)
break; break;
} }
} while((post=post->next)); /* for each field */ } while((post=post->next)); /* for each field */
if (result != CURLE_OK) { if (result) {
Curl_formclean(firstform); Curl_formclean(firstform);
free(boundary); free(boundary);
return result; return result;
@ -1105,7 +1105,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\n--%s--\r\n", "\r\n--%s--\r\n",
boundary); boundary);
if (result != CURLE_OK) { if (result) {
Curl_formclean(firstform); Curl_formclean(firstform);
free(boundary); free(boundary);
return result; return result;