blob: 647afc63def0c04ce6ea389d083e3c541cd6ea85 [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
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/* argv1 = URL
25 * argv2 = proxy
26 * argv3 = proxyuser:password
27 */
28
29#include "test.h"
30
31#include "memdebug.h"
32
33#define UPLOADTHIS "this is the blurb we want to upload\n"
34
35#ifndef LIB548
36static size_t readcallback(char *ptr,
37 size_t size,
38 size_t nmemb,
39 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 fprintf(stderr, "READ ALREADY DONE!\n");
46 return 0;
47 }
48 (*counter)++; /* bump */
49
50 if(size * nmemb > strlen(UPLOADTHIS)) {
51 fprintf(stderr, "READ!\n");
52 strcpy(ptr, UPLOADTHIS);
53 return strlen(UPLOADTHIS);
54 }
55 fprintf(stderr, "READ NOT FINE!\n");
56 return 0;
57}
58static curlioerr ioctlcallback(CURL *handle,
59 int cmd,
60 void *clientp)
61{
62 int *counter = (int *)clientp;
63 (void)handle; /* unused */
64 if(cmd == CURLIOCMD_RESTARTREAD) {
65 fprintf(stderr, "REWIND!\n");
66 *counter = 0; /* clear counter to make the read callback restart */
67 }
68 return CURLIOE_OK;
69}
70
71
72
73#endif
74
75int test(char *URL)
76{
77 CURLcode res;
78 CURL *curl;
79#ifndef LIB548
80 int counter = 0;
81#endif
82
83 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
84 fprintf(stderr, "curl_global_init() failed\n");
85 return TEST_ERR_MAJOR_BAD;
86 }
87
88 curl = curl_easy_init();
89 if(!curl) {
90 fprintf(stderr, "curl_easy_init() failed\n");
91 curl_global_cleanup();
92 return TEST_ERR_MAJOR_BAD;
93 }
94
95 test_setopt(curl, CURLOPT_URL, URL);
96 test_setopt(curl, CURLOPT_VERBOSE, 1L);
97 test_setopt(curl, CURLOPT_HEADER, 1L);
98#ifdef LIB548
99 /* set the data to POST with a mere pointer to a null-terminated string */
100 test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
101#else
102 /* 547 style, which means reading the POST data from a callback */
103 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
104 test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
105 test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
106 test_setopt(curl, CURLOPT_READDATA, &counter);
107 /* We CANNOT do the POST fine without setting the size (or choose
108 chunked)! */
109 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
110#endif
111 test_setopt(curl, CURLOPT_POST, 1L);
112 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
113 test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
114 test_setopt(curl, CURLOPT_PROXYAUTH,
115 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
116
117 res = curl_easy_perform(curl);
118
119test_cleanup:
120
121 curl_easy_cleanup(curl);
122 curl_global_cleanup();
123
124 return (int)res;
125}