2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2008-04-17 05:11:46 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-04-04 02:28:34 +08:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2008-04-17 05:11:46 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 07:19:02 +08:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/* This test case is supposed to be identical to 547 except that this uses the
|
2008-04-17 05:11:46 +08:00
|
|
|
* multi interface and 547 is easy interface.
|
|
|
|
*
|
|
|
|
* argv1 = URL
|
|
|
|
* argv2 = proxy
|
|
|
|
* argv3 = proxyuser:password
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include "testutil.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
2008-04-17 05:11:46 +08:00
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2011-10-21 22:26:18 +08:00
|
|
|
int res = 0;
|
|
|
|
CURL *curl = NULL;
|
2008-04-17 05:11:46 +08:00
|
|
|
int counter=0;
|
2010-02-06 02:07:19 +08:00
|
|
|
CURLM *m = NULL;
|
2008-04-17 05:11:46 +08:00
|
|
|
int running=1;
|
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
start_test_timing();
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
|
|
|
easy_init(curl);
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_URL, URL);
|
|
|
|
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
easy_setopt(curl, CURLOPT_HEADER, 1L);
|
2008-04-17 05:11:46 +08:00
|
|
|
|
|
|
|
/* read the POST data from a callback */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
|
|
|
|
easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
|
|
|
|
easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
|
|
|
|
easy_setopt(curl, CURLOPT_READDATA, &counter);
|
2016-04-03 17:57:34 +08:00
|
|
|
/* We CANNOT do the POST fine without setting the size (or choose
|
|
|
|
chunked)! */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_POST, 1L);
|
2009-05-08 10:14:50 +08:00
|
|
|
#ifdef CURL_DOES_CONVERSIONS
|
|
|
|
/* Convert the POST data to ASCII. */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
|
2009-05-08 10:14:50 +08:00
|
|
|
#endif
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
|
|
|
|
easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
|
|
|
|
easy_setopt(curl, CURLOPT_PROXYAUTH,
|
2008-05-23 05:49:52 +08:00
|
|
|
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_init(m);
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_add_handle(m, curl);
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2016-04-03 17:57:34 +08:00
|
|
|
while(running) {
|
2011-10-21 22:26:18 +08:00
|
|
|
struct timeval timeout;
|
2011-08-26 17:10:58 +08:00
|
|
|
fd_set fdread, fdwrite, fdexcep;
|
2011-10-21 22:26:18 +08:00
|
|
|
int maxfd = -99;
|
|
|
|
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 100000L; /* 100 ms */
|
|
|
|
|
|
|
|
multi_perform(m, &running);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
|
2009-05-08 10:14:50 +08:00
|
|
|
#ifdef TPF
|
|
|
|
sleep(1); /* avoid ctl-10 dump */
|
|
|
|
#endif
|
2011-10-21 22:26:18 +08:00
|
|
|
|
|
|
|
if(!running)
|
|
|
|
break; /* done */
|
2011-08-26 17:10:58 +08:00
|
|
|
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
|
|
|
|
|
|
|
|
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
|
|
|
|
|
|
|
|
select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
2008-04-17 05:11:46 +08:00
|
|
|
}
|
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
test_cleanup:
|
2008-04-17 05:11:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
/* proper cleanup sequence - type PA */
|
|
|
|
|
|
|
|
curl_multi_remove_handle(m, curl);
|
|
|
|
curl_multi_cleanup(m);
|
2010-02-06 02:07:19 +08:00
|
|
|
curl_easy_cleanup(curl);
|
2008-04-17 05:11:46 +08:00
|
|
|
curl_global_cleanup();
|
|
|
|
|
2008-04-17 19:59:46 +08:00
|
|
|
return res;
|
2008-04-17 05:11:46 +08:00
|
|
|
}
|
|
|
|
|