mirror of
https://github.com/curl/curl.git
synced 2026-07-27 23:53:06 +03:00
source cleanup: unify look, style and indent levels
By the use of a the new lib/checksrc.pl script that checks that our basic source style rules are followed.
This commit is contained in:
parent
592eda8e3f
commit
b903186fa0
88 changed files with 1411 additions and 1577 deletions
247
lib/formdata.c
247
lib/formdata.c
|
|
@ -20,87 +20,6 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
Debug the form generator stand-alone by compiling this source file with:
|
||||
|
||||
gcc -DHAVE_CONFIG_H -I../ -g -D_FORM_DEBUG -DCURLDEBUG -o formdata \
|
||||
-I../include formdata.c strequal.c memdebug.c mprintf.c strerror.c
|
||||
|
||||
(depending on circumstances you may need further externals added)
|
||||
|
||||
run the 'formdata' executable the output should end with:
|
||||
All Tests seem to have worked ...
|
||||
and the following parts should be there:
|
||||
|
||||
Content-Disposition: form-data; name="simple_COPYCONTENTS"
|
||||
value for simple COPYCONTENTS
|
||||
|
||||
Content-Disposition: form-data; name="COPYCONTENTS_+_CONTENTTYPE"
|
||||
Content-Type: image/gif
|
||||
value for COPYCONTENTS + CONTENTTYPE
|
||||
|
||||
Content-Disposition: form-data; name="PRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH"
|
||||
vlue for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH
|
||||
(or you might see P^@RNAME and v^@lue at the start)
|
||||
|
||||
Content-Disposition: form-data; name="simple_PTRCONTENTS"
|
||||
value for simple PTRCONTENTS
|
||||
|
||||
Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH"
|
||||
vlue for PTRCONTENTS + CONTENTSLENGTH
|
||||
(or you might see v^@lue at the start)
|
||||
|
||||
Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE"
|
||||
Content-Type: application/octet-stream
|
||||
vlue for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE
|
||||
(or you might see v^@lue at the start)
|
||||
|
||||
Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="formdata.h"
|
||||
Content-Type: text/html
|
||||
...
|
||||
|
||||
Content-Disposition: form-data; name="FILE1_+_FILE2"
|
||||
Content-Type: multipart/mixed, boundary=curlz1s0dkticx49MV1KGcYP5cvfSsz
|
||||
...
|
||||
Content-Disposition: attachment; filename="formdata.h"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
Content-Disposition: attachment; filename="Makefile.b32"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
|
||||
Content-Disposition: form-data; name="FILE1_+_FILE2_+_FILE3"
|
||||
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
|
||||
...
|
||||
Content-Disposition: attachment; filename="formdata.h"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
Content-Disposition: attachment; filename="Makefile.b32"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
Content-Disposition: attachment; filename="formdata.h"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
|
||||
|
||||
Content-Disposition: form-data; name="ARRAY: FILE1_+_FILE2_+_FILE3"
|
||||
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
|
||||
...
|
||||
Content-Disposition: attachment; filename="formdata.h"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
Content-Disposition: attachment; filename="Makefile.b32"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
Content-Disposition: attachment; filename="formdata.h"
|
||||
Content-Type: application/octet-stream
|
||||
...
|
||||
|
||||
Content-Disposition: form-data; name="FILECONTENT"
|
||||
...
|
||||
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
|
|
@ -382,7 +301,7 @@ static char *memdup(const char *src, size_t buffer_length)
|
|||
* CURL_FORMADD_NULL if a null pointer was given for a char
|
||||
* CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed
|
||||
* CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used
|
||||
* CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or an error)
|
||||
* CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error)
|
||||
* CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated
|
||||
* CURL_FORMADD_MEMORY if some allocation for string copying failed.
|
||||
* CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array
|
||||
|
|
@ -951,7 +870,7 @@ int curl_formget(struct curl_httppost *form, void *arg,
|
|||
if(rc != CURLE_OK)
|
||||
return (int)rc;
|
||||
|
||||
for (ptr = data; ptr; ptr = ptr->next) {
|
||||
for(ptr = data; ptr; ptr = ptr->next) {
|
||||
if(ptr->type == FORM_FILE) {
|
||||
char buffer[8192];
|
||||
size_t nread;
|
||||
|
|
@ -1478,168 +1397,6 @@ char *Curl_formpostheader(void *formp, size_t *len)
|
|||
return header;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _FORM_DEBUG
|
||||
int FormAddTest(const char * errormsg,
|
||||
struct curl_httppost **httppost,
|
||||
struct curl_httppost **last_post,
|
||||
...)
|
||||
{
|
||||
int result;
|
||||
va_list arg;
|
||||
va_start(arg, last_post);
|
||||
if((result = FormAdd(httppost, last_post, arg)))
|
||||
fprintf (stderr, "ERROR doing FormAdd ret: %d action: %s\n", result,
|
||||
errormsg);
|
||||
va_end(arg);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, argv_item_t argv[])
|
||||
{
|
||||
char name1[] = "simple_COPYCONTENTS";
|
||||
char name2[] = "COPYCONTENTS_+_CONTENTTYPE";
|
||||
char name3[] = "PTRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH";
|
||||
char name4[] = "simple_PTRCONTENTS";
|
||||
char name5[] = "PTRCONTENTS_+_CONTENTSLENGTH";
|
||||
char name6[] = "PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE";
|
||||
char name7[] = "FILE1_+_CONTENTTYPE";
|
||||
char name8[] = "FILE1_+_FILE2";
|
||||
char name9[] = "FILE1_+_FILE2_+_FILE3";
|
||||
char name10[] = "ARRAY: FILE1_+_FILE2_+_FILE3";
|
||||
char name11[] = "FILECONTENT";
|
||||
char value1[] = "value for simple COPYCONTENTS";
|
||||
char value2[] = "value for COPYCONTENTS + CONTENTTYPE";
|
||||
char value3[] = "value for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH";
|
||||
char value4[] = "value for simple PTRCONTENTS";
|
||||
char value5[] = "value for PTRCONTENTS + CONTENTSLENGTH";
|
||||
char value6[] = "value for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE";
|
||||
char value7[] = "formdata.h";
|
||||
char value8[] = "Makefile.b32";
|
||||
char type2[] = "image/gif";
|
||||
char type6[] = "text/plain";
|
||||
char type7[] = "text/html";
|
||||
int name3length = strlen(name3);
|
||||
int value3length = strlen(value3);
|
||||
int value5length = strlen(value5);
|
||||
int value6length = strlen(value6);
|
||||
int errors = 0;
|
||||
CURLcode rc;
|
||||
curl_off_t size;
|
||||
size_t nread;
|
||||
char buffer[4096];
|
||||
struct curl_httppost *httppost=NULL;
|
||||
struct curl_httppost *last_post=NULL;
|
||||
struct curl_forms forms[4];
|
||||
|
||||
struct FormData *form;
|
||||
struct Form formread;
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
Curl_srand(); /* Because we do not call curl_global_init() here. */
|
||||
|
||||
if(FormAddTest("simple COPYCONTENTS test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1,
|
||||
CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("COPYCONTENTS + CONTENTTYPE test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name2, CURLFORM_COPYCONTENTS, value2,
|
||||
CURLFORM_CONTENTTYPE, type2, CURLFORM_END))
|
||||
++errors;
|
||||
/* make null character at start to check that contentslength works
|
||||
correctly */
|
||||
name3[1] = '\0';
|
||||
value3[1] = '\0';
|
||||
if(FormAddTest("PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH test",
|
||||
&httppost, &last_post,
|
||||
CURLFORM_PTRNAME, name3, CURLFORM_COPYCONTENTS, value3,
|
||||
CURLFORM_CONTENTSLENGTH, value3length,
|
||||
CURLFORM_NAMELENGTH, name3length, CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("simple PTRCONTENTS test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name4, CURLFORM_PTRCONTENTS, value4,
|
||||
CURLFORM_END))
|
||||
++errors;
|
||||
/* make null character at start to check that contentslength works
|
||||
correctly */
|
||||
value5[1] = '\0';
|
||||
if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name5, CURLFORM_PTRCONTENTS, value5,
|
||||
CURLFORM_CONTENTSLENGTH, value5length, CURLFORM_END))
|
||||
++errors;
|
||||
/* make null character at start to check that contentslength works
|
||||
correctly */
|
||||
value6[1] = '\0';
|
||||
if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE test",
|
||||
&httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name6, CURLFORM_PTRCONTENTS, value6,
|
||||
CURLFORM_CONTENTSLENGTH, value6length,
|
||||
CURLFORM_CONTENTTYPE, type6, CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("FILE + CONTENTTYPE test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name7, CURLFORM_FILE, value7,
|
||||
CURLFORM_CONTENTTYPE, type7, CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("FILE1 + FILE2 test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name8, CURLFORM_FILE, value7,
|
||||
CURLFORM_FILE, value8, CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("FILE1 + FILE2 + FILE3 test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name9, CURLFORM_FILE, value7,
|
||||
CURLFORM_FILE, value8, CURLFORM_FILE, value7, CURLFORM_END))
|
||||
++errors;
|
||||
forms[0].option = CURLFORM_FILE;
|
||||
forms[0].value = value7;
|
||||
forms[1].option = CURLFORM_FILE;
|
||||
forms[1].value = value8;
|
||||
forms[2].option = CURLFORM_FILE;
|
||||
forms[2].value = value7;
|
||||
forms[3].option = CURLFORM_END;
|
||||
if(FormAddTest("FILE1 + FILE2 + FILE3 ARRAY test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name10, CURLFORM_ARRAY, forms,
|
||||
CURLFORM_END))
|
||||
++errors;
|
||||
if(FormAddTest("FILECONTENT test", &httppost, &last_post,
|
||||
CURLFORM_COPYNAME, name11, CURLFORM_FILECONTENT, value7,
|
||||
CURLFORM_END))
|
||||
++errors;
|
||||
|
||||
rc = Curl_getformdata(NULL, &form, httppost, NULL, &size);
|
||||
if(rc != CURLE_OK) {
|
||||
if(rc != CURLE_READ_ERROR) {
|
||||
const char *errortext = curl_easy_strerror(rc);
|
||||
fprintf(stdout, "\n==> Curl_getformdata error: %s\n", errortext);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Curl_FormInit(&formread, form);
|
||||
|
||||
for(;;) {
|
||||
nread = Curl_FormReader(buffer, 1, sizeof(buffer),
|
||||
(FILE *)&formread);
|
||||
|
||||
if(nread < 1)
|
||||
break;
|
||||
fwrite(buffer, nread, 1, stdout);
|
||||
}
|
||||
|
||||
fprintf(stdout, "size: ");
|
||||
fprintf(stdout, "%" FORMAT_OFF_T, size);
|
||||
fprintf(stdout, "\n");
|
||||
if(errors)
|
||||
fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
|
||||
else
|
||||
fprintf(stdout, "\nAll Tests seem to have worked (please check output)\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _FORM_DEBUG */
|
||||
|
||||
#else /* CURL_DISABLE_HTTP */
|
||||
CURLFORMcode curl_formadd(struct curl_httppost **httppost,
|
||||
struct curl_httppost **last_post,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue