1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2018, 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
38static const char uploadthis[] =
39#ifdef CURL_DOES_CONVERSIONS
40 /* ASCII representation with escape sequences for non-ASCII platforms */
41 "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62\x6c\x75\x72"
42 "\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20\x74\x6f\x20\x75\x70\x6c"
43 "\x6f\x61\x64\x0a";
44#else
45 "this is the blurb we want to upload\n";
46#endif
47
48static size_t readcallback(void *ptr,
49 size_t size,
50 size_t nmemb,
51 void *clientp)
52{
53 int *counter = (int *)clientp;
54
55 if(*counter) {
56 /* only do this once and then require a clearing of this */
57 fprintf(stderr, "READ ALREADY DONE!\n");
58 return 0;
59 }
60 (*counter)++; /* bump */
61
62 if(size * nmemb > strlen(uploadthis)) {
63 fprintf(stderr, "READ!\n");
64 strcpy(ptr, uploadthis);
65 return strlen(uploadthis);
66 }
67 fprintf(stderr, "READ NOT FINE!\n");
68 return 0;
69}
70static curlioerr ioctlcallback(CURL *handle,
71 int cmd,
72 void *clientp)
73{
74 int *counter = (int *)clientp;
75 (void)handle; /* unused */
76 if(cmd == CURLIOCMD_RESTARTREAD) {
77 fprintf(stderr, "REWIND!\n");
78 *counter = 0; /* clear counter to make the read callback restart */
79 }
80 return CURLIOE_OK;
81}
82
83
84int test(char *URL)
85{
86 int res = 0;
87 CURL *curl = NULL;
88 int counter = 0;
89 CURLM *m = NULL;
90 int running = 1;
91
92 start_test_timing();
93
94 global_init(CURL_GLOBAL_ALL);
95
96 easy_init(curl);
97
98 easy_setopt(curl, CURLOPT_URL, URL);
99 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
100 easy_setopt(curl, CURLOPT_HEADER, 1L);
101
102 /* read the POST data from a callback */
103 easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
104 easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
105 easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
106 easy_setopt(curl, CURLOPT_READDATA, &counter);
107 /* We CANNOT do the POST fine without setting the size (or choose
108 chunked)! */
109 easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis));
110
111 easy_setopt(curl, CURLOPT_POST, 1L);
112 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
113 easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
114 easy_setopt(curl, CURLOPT_PROXYAUTH,
115 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
116
117 multi_init(m);
118
119 multi_add_handle(m, curl);
120
121 while(running) {
122 struct timeval timeout;
123 fd_set fdread, fdwrite, fdexcep;
124 int maxfd = -99;
125
126 timeout.tv_sec = 0;
127 timeout.tv_usec = 100000L; /* 100 ms */
128
129 multi_perform(m, &running);
130
131 abort_on_test_timeout();
132
133#ifdef TPF
134 sleep(1); /* avoid ctl-10 dump */
135#endif
136
137 if(!running)
138 break; /* done */
139
140 FD_ZERO(&fdread);
141 FD_ZERO(&fdwrite);
142 FD_ZERO(&fdexcep);
143
144 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
145
146 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
147
148 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
149
150 abort_on_test_timeout();
151 }
152
153test_cleanup:
154
155 /* proper cleanup sequence - type PA */
156
157 curl_multi_remove_handle(m, curl);
158 curl_multi_cleanup(m);
159 curl_easy_cleanup(curl);
160 curl_global_cleanup();
161
162 return res;
163}
164