lib555.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 
00023 /* This test case is supposed to be identical to 547 except that this uses the
00024  * multi interface and 547 is easy interface.
00025  *
00026  * argv1 = URL
00027  * argv2 = proxy
00028  * argv3 = proxyuser:password
00029  */
00030 
00031 #include "test.h"
00032 #include "testutil.h"
00033 #include "warnless.h"
00034 #include "memdebug.h"
00035 
00036 #define TEST_HANG_TIMEOUT 60 * 1000
00037 
00038 #define UPLOADTHIS "this is the blurb we want to upload\n"
00039 
00040 static size_t readcallback(void  *ptr,
00041                            size_t size,
00042                            size_t nmemb,
00043                            void *clientp)
00044 {
00045   int *counter = (int *)clientp;
00046 
00047   if(*counter) {
00048     /* only do this once and then require a clearing of this */
00049     fprintf(stderr, "READ ALREADY DONE!\n");
00050     return 0;
00051   }
00052   (*counter)++; /* bump */
00053 
00054   if(size * nmemb > strlen(UPLOADTHIS)) {
00055     fprintf(stderr, "READ!\n");
00056     strcpy(ptr, UPLOADTHIS);
00057     return strlen(UPLOADTHIS);
00058   }
00059   fprintf(stderr, "READ NOT FINE!\n");
00060   return 0;
00061 }
00062 static curlioerr ioctlcallback(CURL *handle,
00063                                int cmd,
00064                                void *clientp)
00065 {
00066   int *counter = (int *)clientp;
00067   (void)handle; /* unused */
00068   if(cmd == CURLIOCMD_RESTARTREAD) {
00069     fprintf(stderr, "REWIND!\n");
00070     *counter = 0; /* clear counter to make the read callback restart */
00071   }
00072   return CURLIOE_OK;
00073 }
00074 
00075 
00076 int test(char *URL)
00077 {
00078   int res = 0;
00079   CURL *curl = NULL;
00080   int counter=0;
00081   CURLM *m = NULL;
00082   int running=1;
00083 
00084   start_test_timing();
00085 
00086   global_init(CURL_GLOBAL_ALL);
00087 
00088   easy_init(curl);
00089 
00090   easy_setopt(curl, CURLOPT_URL, URL);
00091   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00092   easy_setopt(curl, CURLOPT_HEADER, 1L);
00093 
00094   /* read the POST data from a callback */
00095   easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
00096   easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
00097   easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
00098   easy_setopt(curl, CURLOPT_READDATA, &counter);
00099   /* We CANNOT do the POST fine without setting the size (or choose
00100      chunked)! */
00101   easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
00102 
00103   easy_setopt(curl, CURLOPT_POST, 1L);
00104 #ifdef CURL_DOES_CONVERSIONS
00105   /* Convert the POST data to ASCII. */
00106   easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00107 #endif
00108   easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00109   easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
00110   easy_setopt(curl, CURLOPT_PROXYAUTH,
00111                    (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
00112 
00113   multi_init(m);
00114 
00115   multi_add_handle(m, curl);
00116 
00117   while(running) {
00118     struct timeval timeout;
00119     fd_set fdread, fdwrite, fdexcep;
00120     int maxfd = -99;
00121 
00122     timeout.tv_sec = 0;
00123     timeout.tv_usec = 100000L; /* 100 ms */
00124 
00125     multi_perform(m, &running);
00126 
00127     abort_on_test_timeout();
00128 
00129 #ifdef TPF
00130     sleep(1); /* avoid ctl-10 dump */
00131 #endif
00132 
00133     if(!running)
00134       break; /* done */
00135 
00136     FD_ZERO(&fdread);
00137     FD_ZERO(&fdwrite);
00138     FD_ZERO(&fdexcep);
00139 
00140     multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
00141 
00142     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00143 
00144     select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00145 
00146     abort_on_test_timeout();
00147   }
00148 
00149 test_cleanup:
00150 
00151   /* proper cleanup sequence - type PA */
00152 
00153   curl_multi_remove_handle(m, curl);
00154   curl_multi_cleanup(m);
00155   curl_easy_cleanup(curl);
00156   curl_global_cleanup();
00157 
00158   return res;
00159 }
00160 


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