lib525.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include <fcntl.h>
00025 
00026 #include "testutil.h"
00027 #include "warnless.h"
00028 #include "memdebug.h"
00029 
00030 #define TEST_HANG_TIMEOUT 60 * 1000
00031 
00032 int test(char *URL)
00033 {
00034   int res = 0;
00035   CURL *curl = NULL;
00036   FILE *hd_src = NULL;
00037   int hd;
00038   int error;
00039   struct_stat file_info;
00040   CURLM *m = NULL;
00041   int running;
00042 
00043   start_test_timing();
00044 
00045   if(!libtest_arg2) {
00046 #ifdef LIB529
00047     /* test 529 */
00048     fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
00049 #else
00050     /* test 525 */
00051     fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
00052 #endif
00053     return TEST_ERR_USAGE;
00054   }
00055 
00056   hd_src = fopen(libtest_arg2, "rb");
00057   if(NULL == hd_src) {
00058     error = ERRNO;
00059     fprintf(stderr, "fopen failed with error: %d (%s)\n",
00060             error, strerror(error));
00061     fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
00062     return TEST_ERR_FOPEN;
00063   }
00064 
00065   /* get the file size of the local file */
00066   hd = fstat(fileno(hd_src), &file_info);
00067   if(hd == -1) {
00068     /* can't open file, bail out */
00069     error = ERRNO;
00070     fprintf(stderr, "fstat() failed with error: %d (%s)\n",
00071             error, strerror(error));
00072     fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
00073     fclose(hd_src);
00074     return TEST_ERR_FSTAT;
00075   }
00076 
00077   res_global_init(CURL_GLOBAL_ALL);
00078   if(res) {
00079     fclose(hd_src);
00080     return res;
00081   }
00082 
00083   easy_init(curl);
00084 
00085   /* enable uploading */
00086   easy_setopt(curl, CURLOPT_UPLOAD, 1L);
00087 
00088   /* specify target */
00089   easy_setopt(curl, CURLOPT_URL, URL);
00090 
00091   /* go verbose */
00092   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00093 
00094   /* use active FTP */
00095   easy_setopt(curl, CURLOPT_FTPPORT, "-");
00096 
00097   /* now specify which file to upload */
00098   easy_setopt(curl, CURLOPT_READDATA, hd_src);
00099 
00100   /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
00101      MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
00102      do so will give you a crash since a DLL may not use the variable's memory
00103      when passed in to it from an app like this. */
00104 
00105   /* Set the size of the file to upload (optional).  If you give a *_LARGE
00106      option you MUST make sure that the type of the passed-in argument is a
00107      curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
00108      make sure that to pass in a type 'long' argument. */
00109   easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
00110 
00111   multi_init(m);
00112 
00113   multi_add_handle(m, curl);
00114 
00115   for(;;) {
00116     struct timeval interval;
00117     fd_set rd, wr, exc;
00118     int maxfd = -99;
00119 
00120     interval.tv_sec = 1;
00121     interval.tv_usec = 0;
00122 
00123     multi_perform(m, &running);
00124 
00125     abort_on_test_timeout();
00126 
00127     if(!running)
00128       break; /* done */
00129 
00130     FD_ZERO(&rd);
00131     FD_ZERO(&wr);
00132     FD_ZERO(&exc);
00133 
00134     multi_fdset(m, &rd, &wr, &exc, &maxfd);
00135 
00136     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00137 
00138     select_test(maxfd+1, &rd, &wr, &exc, &interval);
00139 
00140     abort_on_test_timeout();
00141   }
00142 
00143 test_cleanup:
00144 
00145 #ifdef LIB529
00146   /* test 529 */
00147   /* proper cleanup sequence - type PA */
00148   curl_multi_remove_handle(m, curl);
00149   curl_multi_cleanup(m);
00150   curl_easy_cleanup(curl);
00151   curl_global_cleanup();
00152 #else
00153   /* test 525 */
00154   /* proper cleanup sequence - type PB */
00155   curl_multi_remove_handle(m, curl);
00156   curl_easy_cleanup(curl);
00157   curl_multi_cleanup(m);
00158   curl_global_cleanup();
00159 #endif
00160 
00161   /* close the local file */
00162   fclose(hd_src);
00163 
00164   return res;
00165 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05