2011-03-10 05:48:02 -05:00
|
|
|
/***************************************************************************
|
2008-04-16 17:11:46 -04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-03-10 05:48:02 -05:00
|
|
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2008-04-16 17:11:46 -04:00
|
|
|
*
|
2011-03-10 05:48:02 -05:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* 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-16 17:11:46 -04:00
|
|
|
* multi interface and 547 is easy interface.
|
|
|
|
*
|
|
|
|
* argv1 = URL
|
|
|
|
* argv2 = proxy
|
|
|
|
* argv3 = proxyuser:password
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include "testutil.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
2008-04-16 17:11:46 -04: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 10:26:18 -04:00
|
|
|
int res = 0;
|
|
|
|
CURL *curl = NULL;
|
2008-04-16 17:11:46 -04:00
|
|
|
int counter=0;
|
2010-02-05 13:07:19 -05:00
|
|
|
CURLM *m = NULL;
|
2008-04-16 17:11:46 -04:00
|
|
|
int running=1;
|
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
start_test_timing();
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
|
|
|
easy_init(curl);
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(curl, CURLOPT_URL, URL);
|
|
|
|
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
easy_setopt(curl, CURLOPT_HEADER, 1L);
|
2008-04-16 17:11:46 -04:00
|
|
|
|
|
|
|
/* read the POST data from a callback */
|
2011-10-21 10:26:18 -04: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);
|
2008-04-16 17:11:46 -04:00
|
|
|
/* We CANNOT do the POST fine without setting the size (or choose chunked)! */
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(curl, CURLOPT_POST, 1L);
|
2009-05-07 22:14:50 -04:00
|
|
|
#ifdef CURL_DOES_CONVERSIONS
|
|
|
|
/* Convert the POST data to ASCII. */
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
|
2009-05-07 22:14:50 -04:00
|
|
|
#endif
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
|
|
|
|
easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
|
|
|
|
easy_setopt(curl, CURLOPT_PROXYAUTH,
|
2008-05-22 17:49:52 -04:00
|
|
|
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
multi_init(m);
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
multi_add_handle(m, curl);
|
2008-04-16 17:11:46 -04:00
|
|
|
|
|
|
|
while (running) {
|
2011-10-21 10:26:18 -04:00
|
|
|
struct timeval timeout;
|
2011-08-26 05:10:58 -04:00
|
|
|
fd_set fdread, fdwrite, fdexcep;
|
2011-10-21 10:26:18 -04:00
|
|
|
int maxfd = -99;
|
|
|
|
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 100000L; /* 100 ms */
|
|
|
|
|
|
|
|
multi_perform(m, &running);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
|
2009-05-07 22:14:50 -04:00
|
|
|
#ifdef TPF
|
|
|
|
sleep(1); /* avoid ctl-10 dump */
|
|
|
|
#endif
|
2011-10-21 10:26:18 -04:00
|
|
|
|
|
|
|
if(!running)
|
|
|
|
break; /* done */
|
2011-08-26 05:10:58 -04:00
|
|
|
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04: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-16 17:11:46 -04:00
|
|
|
}
|
|
|
|
|
2010-02-05 13:07:19 -05:00
|
|
|
test_cleanup:
|
2008-04-16 17:11:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
/* proper cleanup sequence - type PA */
|
|
|
|
|
|
|
|
curl_multi_remove_handle(m, curl);
|
|
|
|
curl_multi_cleanup(m);
|
2010-02-05 13:07:19 -05:00
|
|
|
curl_easy_cleanup(curl);
|
2008-04-16 17:11:46 -04:00
|
|
|
curl_global_cleanup();
|
|
|
|
|
2008-04-17 07:59:46 -04:00
|
|
|
return res;
|
2008-04-16 17:11:46 -04:00
|
|
|
}
|
|
|
|
|