lib1540.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 #include "test.h"
23 
24 #include "testutil.h"
25 #include "warnless.h"
26 #include "memdebug.h"
27 
30  int halted;
31  int counter; /* count write callback invokes */
32  int please; /* number of times xferinfo is called while halted */
33 };
34 
35 static int please_continue(void *userp,
36  curl_off_t dltotal,
37  curl_off_t dlnow,
38  curl_off_t ultotal,
39  curl_off_t ulnow)
40 {
41  struct transfer_status *st = (struct transfer_status *)userp;
42  (void)dltotal;
43  (void)dlnow;
44  (void)ultotal;
45  (void)ulnow;
46  if(st->halted) {
47  st->please++;
48  if(st->please == 2) {
49  /* waited enough, unpause! */
51  }
52  }
53  fprintf(stderr, "xferinfo: paused %d\n", st->halted);
54  return 0; /* go on */
55 }
56 
57 static size_t header_callback(void *ptr, size_t size, size_t nmemb,
58  void *userp)
59 {
60  size_t len = size * nmemb;
61  (void)userp;
62  (void)fwrite(ptr, size, nmemb, stdout);
63  return len;
64 }
65 
66 static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
67 {
68  struct transfer_status *st = (struct transfer_status *)userp;
69  size_t len = size * nmemb;
70  st->counter++;
71  if(st->counter > 1) {
72  /* the first call puts us on pause, so subsequent calls are after
73  unpause */
74  fwrite(ptr, size, nmemb, stdout);
75  return len;
76  }
77  printf("Got %d bytes but pausing!\n", (int)len);
78  st->halted = 1;
79  return CURL_WRITEFUNC_PAUSE;
80 }
81 
82 #define TEST_HANG_TIMEOUT 60 * 1000
83 
84 int test(char *URL)
85 {
86  CURL *curls = NULL;
87  int i = 0;
88  int res = 0;
89  struct transfer_status st;
90 
92 
93  memset(&st, 0, sizeof(st));
94 
96 
97  easy_init(curls);
98  st.easy = curls; /* to allow callbacks access */
99 
100  easy_setopt(curls, CURLOPT_URL, URL);
101  easy_setopt(curls, CURLOPT_WRITEFUNCTION, write_callback);
102  easy_setopt(curls, CURLOPT_WRITEDATA, &st);
103  easy_setopt(curls, CURLOPT_HEADERFUNCTION, header_callback);
104  easy_setopt(curls, CURLOPT_HEADERDATA, &st);
105 
106  easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, please_continue);
107  easy_setopt(curls, CURLOPT_XFERINFODATA, &st);
108  easy_setopt(curls, CURLOPT_NOPROGRESS, 0L);
109 
110  res = curl_easy_perform(curls);
111 
112 test_cleanup:
113 
114  curl_easy_cleanup(curls);
116 
117  if(res)
118  i = res;
119 
120  return i; /* return the final return code */
121 }
static size_t header_callback(void *ptr, size_t size, size_t nmemb, void *userp)
Definition: lib1540.c:57
#define CURL_WRITEFUNC_PAUSE
Definition: curl.h:241
CURL * easy
Definition: lib1540.c:29
#define global_init(A)
Definition: test.h:431
#define CURLPAUSE_CONT
Definition: curl.h:2712
#define easy_setopt(A, B, C)
Definition: test.h:190
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask)
static int res
#define CURLOPT_XFERINFODATA
Definition: curl.h:1086
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
Definition: lib1540.c:66
unsigned int i
Definition: unit1303.c:79
size_t len
Definition: curl_sasl.c:55
#define printf
Definition: curl_printf.h:40
#define easy_init(A)
Definition: test.h:145
static int please_continue(void *userp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Definition: lib1540.c:35
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
CURL_TYPEOF_CURL_OFF_T curl_off_t
Definition: system.h:420
void CURL
Definition: curl.h:102
int test(char *URL)
Definition: lib1540.c:84
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
#define start_test_timing()
Definition: test.h:383
size_t fwrite(const void *, size_t, size_t, FILE *)
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


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