1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at https://curl.haxx.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ***************************************************************************/ 22 23/* This test case is supposed to be identical to 547 except that this uses the 24 * multi interface and 547 is easy interface. 25 * 26 * argv1 = URL 27 * argv2 = proxy 28 * argv3 = proxyuser:password 29 */ 30 31#include "test.h" 32#include "testutil.h" 33#include "warnless.h" 34#include "memdebug.h" 35 36#define TEST_HANG_TIMEOUT 60 * 1000 37 38#define UPLOADTHIS "this is the blurb we want to upload\n" 39 40static size_t readcallback(void *ptr, 41 size_t size, 42 size_t nmemb, 43 void *clientp) 44{ 45 int *counter = (int *)clientp; 46 47 if(*counter) { 48 /* only do this once and then require a clearing of this */ 49 fprintf(stderr, "READ ALREADY DONE!\n"); 50 return 0; 51 } 52 (*counter)++; /* bump */ 53 54 if(size * nmemb > strlen(UPLOADTHIS)) { 55 fprintf(stderr, "READ!\n"); 56 strcpy(ptr, UPLOADTHIS); 57 return strlen(UPLOADTHIS); 58 } 59 fprintf(stderr, "READ NOT FINE!\n"); 60 return 0; 61} 62static curlioerr ioctlcallback(CURL *handle, 63 int cmd, 64 void *clientp) 65{ 66 int *counter = (int *)clientp; 67 (void)handle; /* unused */ 68 if(cmd == CURLIOCMD_RESTARTREAD) { 69 fprintf(stderr, "REWIND!\n"); 70 *counter = 0; /* clear counter to make the read callback restart */ 71 } 72 return CURLIOE_OK; 73} 74 75 76int test(char *URL) 77{ 78 int res = 0; 79 CURL *curl = NULL; 80 int counter = 0; 81 CURLM *m = NULL; 82 int running = 1; 83 84 start_test_timing(); 85 86 global_init(CURL_GLOBAL_ALL); 87 88 easy_init(curl); 89 90 easy_setopt(curl, CURLOPT_URL, URL); 91 easy_setopt(curl, CURLOPT_VERBOSE, 1L); 92 easy_setopt(curl, CURLOPT_HEADER, 1L); 93 94 /* read the POST data from a callback */ 95 easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback); 96 easy_setopt(curl, CURLOPT_IOCTLDATA, &counter); 97 easy_setopt(curl, CURLOPT_READFUNCTION, readcallback); 98 easy_setopt(curl, CURLOPT_READDATA, &counter); 99 /* We CANNOT do the POST fine without setting the size (or choose 100 chunked)! */ 101 easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS)); 102 103 easy_setopt(curl, CURLOPT_POST, 1L); 104#ifdef CURL_DOES_CONVERSIONS 105 /* Convert the POST data to ASCII. */ 106 easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L); 107#endif 108 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); 109 easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); 110 easy_setopt(curl, CURLOPT_PROXYAUTH, 111 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); 112 113 multi_init(m); 114 115 multi_add_handle(m, curl); 116 117 while(running) { 118 struct timeval timeout; 119 fd_set fdread, fdwrite, fdexcep; 120 int maxfd = -99; 121 122 timeout.tv_sec = 0; 123 timeout.tv_usec = 100000L; /* 100 ms */ 124 125 multi_perform(m, &running); 126 127 abort_on_test_timeout(); 128 129#ifdef TPF 130 sleep(1); /* avoid ctl-10 dump */ 131#endif 132 133 if(!running) 134 break; /* done */ 135 136 FD_ZERO(&fdread); 137 FD_ZERO(&fdwrite); 138 FD_ZERO(&fdexcep); 139 140 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); 141 142 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 143 144 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 145 146 abort_on_test_timeout(); 147 } 148 149test_cleanup: 150 151 /* proper cleanup sequence - type PA */ 152 153 curl_multi_remove_handle(m, curl); 154 curl_multi_cleanup(m); 155 curl_easy_cleanup(curl); 156 curl_global_cleanup(); 157 158 return res; 159} 160 161