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

now supports all options in arrays, except the CURLFORM_ARRAY itself

This commit is contained in:
Daniel Stenberg 2002-03-13 12:10:20 +00:00
parent ce021b79a7
commit c819e234b8

View File

@ -678,16 +678,6 @@ FORMcode FormAdd(struct curl_httppost **httppost,
array_state = FALSE; array_state = FALSE;
continue; continue;
} }
else {
/* Check that the option is OK in an array.
TODO: make ALL options work in arrays */
if ( (option <= CURLFORM_ARRAY_START) ||
(option >= CURLFORM_ARRAY_END) ) {
return_value = FORMADD_ILLEGAL_ARRAY;
break;
}
}
} }
else { else {
/* This is not array-state, get next option */ /* This is not array-state, get next option */
@ -698,11 +688,16 @@ FORMcode FormAdd(struct curl_httppost **httppost,
switch (option) { switch (option) {
case CURLFORM_ARRAY: case CURLFORM_ARRAY:
forms = va_arg(params, struct curl_forms *); if(array_state)
if (forms) /* we don't support an array from within an array */
array_state = TRUE; return_value = FORMADD_ILLEGAL_ARRAY;
else else {
return_value = FORMADD_NULL; forms = va_arg(params, struct curl_forms *);
if (forms)
array_state = TRUE;
else
return_value = FORMADD_NULL;
}
break; break;
/* /*
@ -714,7 +709,7 @@ FORMcode FormAdd(struct curl_httppost **httppost,
if (current_form->name) if (current_form->name)
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
else { else {
char *name = va_arg(params, char *); char *name = array_state?array_value:va_arg(params, char *);
if (name) if (name)
current_form->name = name; /* store for the moment */ current_form->name = name; /* store for the moment */
else else
@ -725,7 +720,8 @@ FORMcode FormAdd(struct curl_httppost **httppost,
if (current_form->namelength) if (current_form->namelength)
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
else else
current_form->namelength = va_arg(params, long); current_form->namelength =
array_state?array_value:va_arg(params, long);
break; break;
/* /*
@ -737,7 +733,7 @@ FORMcode FormAdd(struct curl_httppost **httppost,
if (current_form->value) if (current_form->value)
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
else { else {
char *value = va_arg(params, char *); char *value = array_state?array_value:va_arg(params, char *);
if (value) if (value)
current_form->value = value; /* store for the moment */ current_form->value = value; /* store for the moment */
else else
@ -748,7 +744,8 @@ FORMcode FormAdd(struct curl_httppost **httppost,
if (current_form->contentslength) if (current_form->contentslength)
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
else else
current_form->contentslength = va_arg(params, long); current_form->contentslength =
array_state?array_value:va_arg(params, long);
break; break;
/* Get contents from a given file name */ /* Get contents from a given file name */
@ -756,7 +753,8 @@ FORMcode FormAdd(struct curl_httppost **httppost,
if (current_form->flags != 0) if (current_form->flags != 0)
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
else { else {
char *filename = va_arg(params, char *); char *filename = array_state?
array_value:va_arg(params, char *);
if (filename) { if (filename) {
current_form->value = strdup(filename); current_form->value = strdup(filename);
current_form->flags |= HTTPPOST_READFILE; current_form->flags |= HTTPPOST_READFILE;
@ -769,11 +767,9 @@ FORMcode FormAdd(struct curl_httppost **httppost,
/* We upload a file */ /* We upload a file */
case CURLFORM_FILE: case CURLFORM_FILE:
{ {
const char *filename = NULL; const char *filename = array_state?array_value:
if (array_state) va_arg(params, const char *);
filename = array_value;
else
filename = va_arg(params, const char *);
if (current_form->value) { if (current_form->value) {
if (current_form->flags & HTTPPOST_FILENAME) { if (current_form->flags & HTTPPOST_FILENAME) {
if (filename) { if (filename) {
@ -798,11 +794,8 @@ FORMcode FormAdd(struct curl_httppost **httppost,
} }
case CURLFORM_CONTENTTYPE: case CURLFORM_CONTENTTYPE:
{ {
const char *contenttype = NULL; const char *contenttype =
if (array_state) array_state?array_value:va_arg(params, const char *);
contenttype = array_value;
else
contenttype = va_arg(params, const char *);
if (current_form->contenttype) { if (current_form->contenttype) {
if (current_form->flags & HTTPPOST_FILENAME) { if (current_form->flags & HTTPPOST_FILENAME) {
if (contenttype) { if (contenttype) {
@ -827,11 +820,9 @@ FORMcode FormAdd(struct curl_httppost **httppost,
} }
case CURLFORM_CONTENTHEADER: case CURLFORM_CONTENTHEADER:
{ {
struct curl_slist* list = NULL; struct curl_slist* list = array_state?
if( array_state ) (struct curl_slist*)array_value:
list = (struct curl_slist*)array_value; va_arg(params, struct curl_slist*);
else
list = va_arg(params, struct curl_slist*);
if( current_form->contentheader ) if( current_form->contentheader )
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;
@ -842,7 +833,7 @@ FORMcode FormAdd(struct curl_httppost **httppost,
} }
case CURLFORM_FILENAME: case CURLFORM_FILENAME:
{ {
char *filename = array_state?(char *)array_value: char *filename = array_state?array_value:
va_arg(params, char *); va_arg(params, char *);
if( current_form->showfilename ) if( current_form->showfilename )
return_value = FORMADD_OPTION_TWICE; return_value = FORMADD_OPTION_TWICE;