1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 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.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 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 25/* This test case is supposed to be identical to 547 except that this uses the 26 * multi interface and 547 is easy interface. 27 * 28 * argv1 = URL 29 * argv2 = proxy 30 * argv3 = proxyuser:password 31 */ 32 33#include "test.h" 34#include "testutil.h" 35#include "warnless.h" 36#include "memdebug.h" 37 38#define TEST_HANG_TIMEOUT 60 * 1000 39 40static const char uploadthis[] = 41 "this is the blurb we want to upload\n"; 42 43static size_t readcallback(char *ptr, 44 size_t size, 45 size_t nmemb, 46 void *clientp) 47{ 48 int *counter = (int *)clientp; 49 50 if(*counter) { 51 /* only do this once and then require a clearing of this */ 52 fprintf(stderr, "READ ALREADY DONE!\n"); 53 return 0; 54 } 55 (*counter)++; /* bump */ 56 57 if(size * nmemb > strlen(uploadthis)) { 58 fprintf(stderr, "READ!\n"); 59 strcpy(ptr, uploadthis); 60 return strlen(uploadthis); 61 } 62 fprintf(stderr, "READ NOT FINE!\n"); 63 return 0; 64} 65static curlioerr ioctlcallback(CURL *handle, 66 int cmd, 67 void *clientp) 68{ 69 int *counter = (int *)clientp; 70 (void)handle; /* unused */ 71 if(cmd == CURLIOCMD_RESTARTREAD) { 72 fprintf(stderr, "REWIND!\n"); 73 *counter = 0; /* clear counter to make the read callback restart */ 74 } 75 return CURLIOE_OK; 76} 77 78 79int test(char *URL) 80{ 81 int res = 0; 82 CURL *curl = NULL; 83 int counter = 0; 84 CURLM *m = NULL; 85 int running = 1; 86 87 start_test_timing(); 88 89 global_init(CURL_GLOBAL_ALL); 90 91 easy_init(curl); 92 93 easy_setopt(curl, CURLOPT_URL, URL); 94 easy_setopt(curl, CURLOPT_VERBOSE, 1L); 95 easy_setopt(curl, CURLOPT_HEADER, 1L); 96 97 /* read the POST data from a callback */ 98 CURL_IGNORE_DEPRECATION( 99 easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback); 100 easy_setopt(curl, CURLOPT_IOCTLDATA, &counter); 101 ) 102 easy_setopt(curl, CURLOPT_READFUNCTION, readcallback); 103 easy_setopt(curl, CURLOPT_READDATA, &counter); 104 /* We CANNOT do the POST fine without setting the size (or choose 105 chunked)! */ 106 easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis)); 107 108 easy_setopt(curl, CURLOPT_POST, 1L); 109 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); 110 easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); 111 easy_setopt(curl, CURLOPT_PROXYAUTH, 112 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); 113 114 multi_init(m); 115 116 multi_add_handle(m, curl); 117 118 while(running) { 119 struct timeval timeout; 120 fd_set fdread, fdwrite, fdexcep; 121 int maxfd = -99; 122 123 timeout.tv_sec = 0; 124 timeout.tv_usec = 100000L; /* 100 ms */ 125 126 multi_perform(m, &running); 127 128 abort_on_test_timeout(); 129 130 if(!running) 131 break; /* done */ 132 133 FD_ZERO(&fdread); 134 FD_ZERO(&fdwrite); 135 FD_ZERO(&fdexcep); 136 137 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); 138 139 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 140 141 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 142 143 abort_on_test_timeout(); 144 } 145 146test_cleanup: 147 148 /* proper cleanup sequence - type PA */ 149 150 curl_multi_remove_handle(m, curl); 151 curl_multi_cleanup(m); 152 curl_easy_cleanup(curl); 153 curl_global_cleanup(); 154 155 return res; 156} 157