2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2006-06-09 06:43:21 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
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
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
***************************************************************************/
|
2006-06-09 06:43:21 +08:00
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2007-02-09 09:11:14 +08:00
|
|
|
#include "testutil.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2006-10-20 23:39:54 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
2006-10-20 23:39:54 +08:00
|
|
|
|
2006-06-09 06:43:21 +08:00
|
|
|
int test(char *URL)
|
|
|
|
{
|
2006-06-09 16:25:16 +08:00
|
|
|
int res = 0;
|
2011-10-21 22:26:18 +08:00
|
|
|
CURL *curl = NULL;
|
|
|
|
FILE *hd_src = NULL;
|
2016-04-03 17:57:34 +08:00
|
|
|
int hd;
|
2006-10-26 22:30:11 +08:00
|
|
|
struct_stat file_info;
|
2010-02-06 02:07:19 +08:00
|
|
|
CURLM *m = NULL;
|
2011-10-21 22:26:18 +08:00
|
|
|
int running;
|
|
|
|
|
|
|
|
start_test_timing();
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
if(!libtest_arg2) {
|
|
|
|
#ifdef LIB529
|
|
|
|
/* test 529 */
|
|
|
|
fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
|
|
|
|
#else
|
|
|
|
/* test 525 */
|
2006-09-10 00:55:21 +08:00
|
|
|
fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
|
2011-10-21 22:26:18 +08:00
|
|
|
#endif
|
|
|
|
return TEST_ERR_USAGE;
|
2006-09-10 00:55:21 +08:00
|
|
|
}
|
|
|
|
|
2007-10-03 00:05:28 +08:00
|
|
|
hd_src = fopen(libtest_arg2, "rb");
|
2021-12-26 04:41:14 +08:00
|
|
|
if(!hd_src) {
|
2016-04-03 17:57:34 +08:00
|
|
|
fprintf(stderr, "fopen failed with error: %d (%s)\n",
|
2017-07-11 13:53:23 +08:00
|
|
|
errno, strerror(errno));
|
2011-10-21 22:26:18 +08:00
|
|
|
fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
|
|
|
|
return TEST_ERR_FOPEN;
|
2007-02-17 03:17:05 +08:00
|
|
|
}
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2010-04-07 13:51:05 +08:00
|
|
|
/* get the file size of the local file */
|
|
|
|
hd = fstat(fileno(hd_src), &file_info);
|
|
|
|
if(hd == -1) {
|
|
|
|
/* can't open file, bail out */
|
2011-10-21 22:26:18 +08:00
|
|
|
fprintf(stderr, "fstat() failed with error: %d (%s)\n",
|
2017-07-11 13:53:23 +08:00
|
|
|
errno, strerror(errno));
|
2011-10-21 22:26:18 +08:00
|
|
|
fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
|
2010-04-07 13:51:05 +08:00
|
|
|
fclose(hd_src);
|
2011-10-21 22:26:18 +08:00
|
|
|
return TEST_ERR_FSTAT;
|
2010-04-07 13:51:05 +08:00
|
|
|
}
|
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
res_global_init(CURL_GLOBAL_ALL);
|
|
|
|
if(res) {
|
2006-10-25 13:59:46 +08:00
|
|
|
fclose(hd_src);
|
2011-10-21 22:26:18 +08:00
|
|
|
return res;
|
2006-10-25 13:59:46 +08:00
|
|
|
}
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_init(curl);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* enable uploading */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* specify target */
|
2016-04-03 17:57:34 +08:00
|
|
|
easy_setopt(curl, CURLOPT_URL, URL);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* go verbose */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* use active FTP */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_FTPPORT, "-");
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* now specify which file to upload */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_READDATA, hd_src);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
/* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
|
|
|
|
MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
|
|
|
|
do so will give you a crash since a DLL may not use the variable's memory
|
|
|
|
when passed in to it from an app like this. */
|
|
|
|
|
|
|
|
/* Set the size of the file to upload (optional). If you give a *_LARGE
|
|
|
|
option you MUST make sure that the type of the passed-in argument is a
|
|
|
|
curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
|
|
|
|
make sure that to pass in a type 'long' argument. */
|
2011-10-21 22:26:18 +08:00
|
|
|
easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_init(m);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_add_handle(m, curl);
|
2006-10-20 23:39:54 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
for(;;) {
|
2006-06-09 06:43:21 +08:00
|
|
|
struct timeval interval;
|
2011-10-21 22:26:18 +08:00
|
|
|
fd_set rd, wr, exc;
|
|
|
|
int maxfd = -99;
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
interval.tv_sec = 1;
|
|
|
|
interval.tv_usec = 0;
|
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_perform(m, &running);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
|
|
|
|
if(!running)
|
|
|
|
break; /* done */
|
2006-06-09 06:43:21 +08:00
|
|
|
|
|
|
|
FD_ZERO(&rd);
|
|
|
|
FD_ZERO(&wr);
|
|
|
|
FD_ZERO(&exc);
|
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
multi_fdset(m, &rd, &wr, &exc, &maxfd);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2017-09-10 05:55:08 +08:00
|
|
|
select_test(maxfd + 1, &rd, &wr, &exc, &interval);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
abort_on_test_timeout();
|
2006-10-20 01:29:25 +08:00
|
|
|
}
|
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
test_cleanup:
|
|
|
|
|
2006-09-29 05:26:06 +08:00
|
|
|
#ifdef LIB529
|
|
|
|
/* test 529 */
|
2011-10-21 22:26:18 +08:00
|
|
|
/* proper cleanup sequence - type PA */
|
|
|
|
curl_multi_remove_handle(m, curl);
|
|
|
|
curl_multi_cleanup(m);
|
2006-09-29 05:26:06 +08:00
|
|
|
curl_easy_cleanup(curl);
|
2011-10-21 22:26:18 +08:00
|
|
|
curl_global_cleanup();
|
2006-09-29 05:26:06 +08:00
|
|
|
#else
|
|
|
|
/* test 525 */
|
2011-10-21 22:26:18 +08:00
|
|
|
/* proper cleanup sequence - type PB */
|
|
|
|
curl_multi_remove_handle(m, curl);
|
2006-06-09 06:43:21 +08:00
|
|
|
curl_easy_cleanup(curl);
|
2011-10-21 22:26:18 +08:00
|
|
|
curl_multi_cleanup(m);
|
|
|
|
curl_global_cleanup();
|
2006-09-29 05:26:06 +08:00
|
|
|
#endif
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
/* close the local file */
|
|
|
|
fclose(hd_src);
|
2006-06-09 06:43:21 +08:00
|
|
|
|
2006-06-09 16:25:16 +08:00
|
|
|
return res;
|
2006-06-09 06:43:21 +08:00
|
|
|
}
|