2008-04-16 23:11:46 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* This test case is supposed to be identical to 547 except that this uses the
|
|
|
|
* multi interface and 547 is easy interface.
|
|
|
|
*
|
|
|
|
* argv1 = URL
|
|
|
|
* argv2 = proxy
|
|
|
|
* argv3 = proxyuser:password
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include "testutil.h"
|
2008-09-20 06:26:55 +02:00
|
|
|
#include "memdebug.h"
|
2008-04-16 23:11:46 +02:00
|
|
|
|
|
|
|
#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
|
|
|
|
|
|
|
|
#define UPLOADTHIS "this is the blurb we want to upload\n"
|
|
|
|
|
|
|
|
static size_t readcallback(void *ptr,
|
|
|
|
size_t size,
|
|
|
|
size_t nmemb,
|
|
|
|
void *clientp)
|
|
|
|
{
|
|
|
|
int *counter = (int *)clientp;
|
|
|
|
|
|
|
|
if(*counter) {
|
|
|
|
/* only do this once and then require a clearing of this */
|
|
|
|
fprintf(stderr, "READ ALREADY DONE!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
(*counter)++; /* bump */
|
|
|
|
|
|
|
|
if(size * nmemb > strlen(UPLOADTHIS)) {
|
|
|
|
fprintf(stderr, "READ!\n");
|
|
|
|
strcpy(ptr, UPLOADTHIS);
|
|
|
|
return strlen(UPLOADTHIS);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "READ NOT FINE!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static curlioerr ioctlcallback(CURL *handle,
|
|
|
|
int cmd,
|
|
|
|
void *clientp)
|
|
|
|
{
|
|
|
|
int *counter = (int *)clientp;
|
|
|
|
(void)handle; /* unused */
|
|
|
|
if(cmd == CURLIOCMD_RESTARTREAD) {
|
|
|
|
fprintf(stderr, "REWIND!\n");
|
|
|
|
*counter = 0; /* clear counter to make the read callback restart */
|
|
|
|
}
|
|
|
|
return CURLIOE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2008-04-17 13:59:46 +02:00
|
|
|
int res;
|
2008-04-16 23:11:46 +02:00
|
|
|
CURL *curl;
|
|
|
|
int counter=0;
|
2010-02-05 19:07:19 +01:00
|
|
|
CURLM *m = NULL;
|
2008-04-16 23:11:46 +02:00
|
|
|
int running=1;
|
|
|
|
struct timeval mp_start;
|
|
|
|
char mp_timedout = FALSE;
|
|
|
|
|
|
|
|
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((curl = curl_easy_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_easy_init() failed\n");
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_URL, URL);
|
|
|
|
test_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
test_setopt(curl, CURLOPT_HEADER, 1L);
|
2008-04-16 23:11:46 +02:00
|
|
|
|
|
|
|
/* read the POST data from a callback */
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
|
|
|
|
test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
|
|
|
|
test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
|
|
|
|
test_setopt(curl, CURLOPT_READDATA, &counter);
|
2008-04-16 23:11:46 +02:00
|
|
|
/* We CANNOT do the POST fine without setting the size (or choose chunked)! */
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
|
2008-04-16 23:11:46 +02:00
|
|
|
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_POST, 1L);
|
2009-05-08 04:14:50 +02:00
|
|
|
#ifdef CURL_DOES_CONVERSIONS
|
|
|
|
/* Convert the POST data to ASCII. */
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
|
2009-05-08 04:14:50 +02:00
|
|
|
#endif
|
2010-02-05 19:07:19 +01:00
|
|
|
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
|
|
|
|
test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
|
|
|
|
test_setopt(curl, CURLOPT_PROXYAUTH,
|
2008-05-22 23:49:52 +02:00
|
|
|
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
|
2008-04-16 23:11:46 +02:00
|
|
|
|
|
|
|
if ((m = curl_multi_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_multi_init() failed\n");
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
|
|
|
|
fprintf(stderr, "curl_multi_add_handle() failed, "
|
|
|
|
"with code %d\n", res);
|
|
|
|
curl_multi_cleanup(m);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_timedout = FALSE;
|
|
|
|
mp_start = tutil_tvnow();
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
res = (int)curl_multi_perform(m, &running);
|
|
|
|
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
|
|
|
|
MULTI_PERFORM_HANG_TIMEOUT) {
|
|
|
|
mp_timedout = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2009-05-08 04:14:50 +02:00
|
|
|
#ifdef TPF
|
|
|
|
sleep(1); /* avoid ctl-10 dump */
|
|
|
|
#endif
|
2008-04-16 23:11:46 +02:00
|
|
|
if (running <= 0) {
|
|
|
|
fprintf(stderr, "nothing left running.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mp_timedout) {
|
|
|
|
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
|
|
|
|
fprintf(stderr, "ABORTING TEST, since it seems "
|
|
|
|
"that it would have run forever.\n");
|
|
|
|
res = TEST_ERR_RUNS_FOREVER;
|
|
|
|
}
|
|
|
|
|
2010-02-05 19:07:19 +01:00
|
|
|
test_cleanup:
|
2008-04-16 23:11:46 +02:00
|
|
|
|
2010-02-05 19:07:19 +01:00
|
|
|
if(m) {
|
|
|
|
curl_multi_remove_handle(m, curl);
|
|
|
|
curl_multi_cleanup(m);
|
|
|
|
}
|
|
|
|
curl_easy_cleanup(curl);
|
2008-04-16 23:11:46 +02:00
|
|
|
curl_global_cleanup();
|
|
|
|
|
2008-04-17 13:59:46 +02:00
|
|
|
return res;
|
2008-04-16 23:11:46 +02:00
|
|
|
}
|
|
|
|
|