lib555.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 
38 #define UPLOADTHIS "this is the blurb we want to upload\n"
39 
40 static size_t readcallback(void *ptr,
41  size_t size,
42  size_t nmemb,
43  void *clientp)
44 {
45  int *counter = (int *)clientp;
46 
47  if(*counter) {
48  /* only do this once and then require a clearing of this */
49  fprintf(stderr, "READ ALREADY DONE!\n");
50  return 0;
51  }
52  (*counter)++; /* bump */
53 
54  if(size * nmemb > strlen(UPLOADTHIS)) {
55  fprintf(stderr, "READ!\n");
56  strcpy(ptr, UPLOADTHIS);
57  return strlen(UPLOADTHIS);
58  }
59  fprintf(stderr, "READ NOT FINE!\n");
60  return 0;
61 }
62 static curlioerr ioctlcallback(CURL *handle,
63  int cmd,
64  void *clientp)
65 {
66  int *counter = (int *)clientp;
67  (void)handle; /* unused */
68  if(cmd == CURLIOCMD_RESTARTREAD) {
69  fprintf(stderr, "REWIND!\n");
70  *counter = 0; /* clear counter to make the read callback restart */
71  }
72  return CURLIOE_OK;
73 }
74 
75 
76 int test(char *URL)
77 {
78  int res = 0;
79  CURL *curl = NULL;
80  int counter = 0;
81  CURLM *m = NULL;
82  int running = 1;
83 
85 
87 
88  easy_init(curl);
89 
90  easy_setopt(curl, CURLOPT_URL, URL);
91  easy_setopt(curl, CURLOPT_VERBOSE, 1L);
92  easy_setopt(curl, CURLOPT_HEADER, 1L);
93 
94  /* read the POST data from a callback */
95  easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
96  easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
97  easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
98  easy_setopt(curl, CURLOPT_READDATA, &counter);
99  /* We CANNOT do the POST fine without setting the size (or choose
100  chunked)! */
101  easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
102 
103  easy_setopt(curl, CURLOPT_POST, 1L);
104 #ifdef CURL_DOES_CONVERSIONS
105  /* Convert the POST data to ASCII. */
106  easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
107 #endif
108  easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
109  easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
110  easy_setopt(curl, CURLOPT_PROXYAUTH,
112 
113  multi_init(m);
114 
115  multi_add_handle(m, curl);
116 
117  while(running) {
118  struct timeval timeout;
119  fd_set fdread, fdwrite, fdexcep;
120  int maxfd = -99;
121 
122  timeout.tv_sec = 0;
123  timeout.tv_usec = 100000L; /* 100 ms */
124 
125  multi_perform(m, &running);
126 
128 
129 #ifdef TPF
130  sleep(1); /* avoid ctl-10 dump */
131 #endif
132 
133  if(!running)
134  break; /* done */
135 
136  FD_ZERO(&fdread);
137  FD_ZERO(&fdwrite);
138  FD_ZERO(&fdexcep);
139 
140  multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
141 
142  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
143 
144  select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
145 
147  }
148 
149 test_cleanup:
150 
151  /* proper cleanup sequence - type PA */
152 
153  curl_multi_remove_handle(m, curl);
155  curl_easy_cleanup(curl);
157 
158  return res;
159 }
160 
static size_t readcallback(void *ptr, size_t size, size_t nmemb, void *clientp)
Definition: lib555.c:40
#define select_test(A, B, C, D, E)
Definition: test.h:378
#define CURLAUTH_BASIC
Definition: curl.h:697
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
#define multi_add_handle(A, B)
Definition: test.h:238
UNITTEST_START char * ptr
Definition: unit1330.c:38
static int res
#define abort_on_test_timeout()
Definition: test.h:404
char * libtest_arg2
Definition: first.c:75
static int counter[MAX_EASY_HANDLES]
#define easy_init(A)
Definition: test.h:145
int test(char *URL)
Definition: lib555.c:76
#define multi_fdset(A, B, C, D, E)
Definition: test.h:323
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
static curlioerr ioctlcallback(CURL *handle, int cmd, void *clientp)
Definition: lib555.c:62
#define UPLOADTHIS
Definition: lib555.c:38
#define CURLAUTH_NTLM
Definition: curl.h:704
#define multi_perform(A, B)
Definition: test.h:293
curlioerr
Definition: curl.h:395
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle)
#define multi_init(A)
Definition: test.h:166
char * libtest_arg3
Definition: first.c:76
void CURLM
Definition: multi.h:58
void CURL
Definition: curl.h:102
#define CURLAUTH_DIGEST
Definition: curl.h:698
size_t size
Definition: unit1302.c:52
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static CURL * curl
Definition: sessioninfo.c:35
#define start_test_timing()
Definition: test.h:383
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15