lib555.c (4032B)
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 "first.h" 34 35 #include "memdebug.h" 36 37 static const char uploadthis[] = "this is the blurb we want to upload\n"; 38 39 static size_t t555_read_cb(char *ptr, size_t size, size_t nmemb, void *clientp) 40 { 41 int *counter = (int *)clientp; 42 43 if(*counter) { 44 /* only do this once and then require a clearing of this */ 45 curl_mfprintf(stderr, "READ ALREADY DONE!\n"); 46 return 0; 47 } 48 (*counter)++; /* bump */ 49 50 if(size * nmemb >= strlen(uploadthis)) { 51 curl_mfprintf(stderr, "READ!\n"); 52 strcpy(ptr, uploadthis); 53 return strlen(uploadthis); 54 } 55 curl_mfprintf(stderr, "READ NOT FINE!\n"); 56 return 0; 57 } 58 59 static curlioerr t555_ioctl_callback(CURL *handle, int cmd, void *clientp) 60 { 61 int *counter = (int *)clientp; 62 (void)handle; /* unused */ 63 if(cmd == CURLIOCMD_RESTARTREAD) { 64 curl_mfprintf(stderr, "REWIND!\n"); 65 *counter = 0; /* clear counter to make the read callback restart */ 66 } 67 return CURLIOE_OK; 68 } 69 70 static CURLcode test_lib555(char *URL) 71 { 72 CURLcode res = CURLE_OK; 73 CURL *curl = NULL; 74 int counter = 0; 75 CURLM *m = NULL; 76 int running = 1; 77 78 start_test_timing(); 79 80 global_init(CURL_GLOBAL_ALL); 81 82 easy_init(curl); 83 84 easy_setopt(curl, CURLOPT_URL, URL); 85 easy_setopt(curl, CURLOPT_VERBOSE, 1L); 86 easy_setopt(curl, CURLOPT_HEADER, 1L); 87 88 /* read the POST data from a callback */ 89 easy_setopt(curl, CURLOPT_IOCTLFUNCTION, t555_ioctl_callback); 90 easy_setopt(curl, CURLOPT_IOCTLDATA, &counter); 91 92 easy_setopt(curl, CURLOPT_READFUNCTION, t555_read_cb); 93 easy_setopt(curl, CURLOPT_READDATA, &counter); 94 /* We CANNOT do the POST fine without setting the size (or choose 95 chunked)! */ 96 easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis)); 97 98 easy_setopt(curl, CURLOPT_POST, 1L); 99 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); 100 easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); 101 easy_setopt(curl, CURLOPT_PROXYAUTH, 102 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); 103 104 multi_init(m); 105 106 multi_add_handle(m, curl); 107 108 while(running) { 109 struct timeval timeout; 110 fd_set fdread, fdwrite, fdexcep; 111 int maxfd = -99; 112 113 timeout.tv_sec = 0; 114 timeout.tv_usec = 100000L; /* 100 ms */ 115 116 multi_perform(m, &running); 117 118 abort_on_test_timeout(); 119 120 if(!running) 121 break; /* done */ 122 123 FD_ZERO(&fdread); 124 FD_ZERO(&fdwrite); 125 FD_ZERO(&fdexcep); 126 127 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); 128 129 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 130 131 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 132 133 abort_on_test_timeout(); 134 } 135 136 test_cleanup: 137 138 /* proper cleanup sequence - type PA */ 139 140 curl_multi_remove_handle(m, curl); 141 curl_multi_cleanup(m); 142 curl_easy_cleanup(curl); 143 curl_global_cleanup(); 144 145 return res; 146 }