| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
|  | 2 | *                                  _   _ ____  _ | 
|  | 3 | *  Project                     ___| | | |  _ \| | | 
|  | 4 | *                             / __| | | | |_) | | | 
|  | 5 | *                            | (__| |_| |  _ <| |___ | 
|  | 6 | *                             \___|\___/|_| \_\_____| | 
|  | 7 | * | 
|  | 8 | * Copyright (C) 1998 - 2022, 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 |  | 
|  | 40 | static const char uploadthis[] = | 
|  | 41 | "this is the blurb we want to upload\n"; | 
|  | 42 |  | 
|  | 43 | static 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 | } | 
|  | 65 | static 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 |  | 
|  | 79 | int 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 | easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback); | 
|  | 99 | easy_setopt(curl, CURLOPT_IOCTLDATA, &counter); | 
|  | 100 | easy_setopt(curl, CURLOPT_READFUNCTION, readcallback); | 
|  | 101 | easy_setopt(curl, CURLOPT_READDATA, &counter); | 
|  | 102 | /* We CANNOT do the POST fine without setting the size (or choose | 
|  | 103 | chunked)! */ | 
|  | 104 | easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis)); | 
|  | 105 |  | 
|  | 106 | easy_setopt(curl, CURLOPT_POST, 1L); | 
|  | 107 | easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); | 
|  | 108 | easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); | 
|  | 109 | easy_setopt(curl, CURLOPT_PROXYAUTH, | 
|  | 110 | (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); | 
|  | 111 |  | 
|  | 112 | multi_init(m); | 
|  | 113 |  | 
|  | 114 | multi_add_handle(m, curl); | 
|  | 115 |  | 
|  | 116 | while(running) { | 
|  | 117 | struct timeval timeout; | 
|  | 118 | fd_set fdread, fdwrite, fdexcep; | 
|  | 119 | int maxfd = -99; | 
|  | 120 |  | 
|  | 121 | timeout.tv_sec = 0; | 
|  | 122 | timeout.tv_usec = 100000L; /* 100 ms */ | 
|  | 123 |  | 
|  | 124 | multi_perform(m, &running); | 
|  | 125 |  | 
|  | 126 | abort_on_test_timeout(); | 
|  | 127 |  | 
|  | 128 | if(!running) | 
|  | 129 | break; /* done */ | 
|  | 130 |  | 
|  | 131 | FD_ZERO(&fdread); | 
|  | 132 | FD_ZERO(&fdwrite); | 
|  | 133 | FD_ZERO(&fdexcep); | 
|  | 134 |  | 
|  | 135 | multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); | 
|  | 136 |  | 
|  | 137 | /* At this point, maxfd is guaranteed to be greater or equal than -1. */ | 
|  | 138 |  | 
|  | 139 | select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); | 
|  | 140 |  | 
|  | 141 | abort_on_test_timeout(); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | test_cleanup: | 
|  | 145 |  | 
|  | 146 | /* proper cleanup sequence - type PA */ | 
|  | 147 |  | 
|  | 148 | curl_multi_remove_handle(m, curl); | 
|  | 149 | curl_multi_cleanup(m); | 
|  | 150 | curl_easy_cleanup(curl); | 
|  | 151 | curl_global_cleanup(); | 
|  | 152 |  | 
|  | 153 | return res; | 
|  | 154 | } |