lib553.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 and code is based on the bug recipe Joe Malicki provided for
24  * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
25  */
26 
27 #include "test.h"
28 
29 #include "memdebug.h"
30 
31 #define POSTLEN 40960
32 
33 static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
34 {
35  static size_t total = POSTLEN;
36  static char buf[1024];
37  (void)stream;
38 
39  memset(buf, 'A', sizeof(buf));
40 
41  size *= nmemb;
42  if(size > total)
43  size = total;
44 
45  if(size > sizeof(buf))
46  size = sizeof(buf);
47 
48  memcpy(ptr, buf, size);
49  total -= size;
50  return size;
51 }
52 
53 #define NUM_HEADERS 8
54 #define SIZE_HEADERS 5000
55 
56 static char buf[SIZE_HEADERS + 100];
57 
58 int test(char *URL)
59 {
60  CURL *curl;
62  int i;
63  struct curl_slist *headerlist = NULL, *hl;
64 
66  fprintf(stderr, "curl_global_init() failed\n");
67  return TEST_ERR_MAJOR_BAD;
68  }
69 
70  curl = curl_easy_init();
71  if(!curl) {
72  fprintf(stderr, "curl_easy_init() failed\n");
74  return TEST_ERR_MAJOR_BAD;
75  }
76 
77  for(i = 0; i < NUM_HEADERS; i++) {
78  int len = snprintf(buf, sizeof(buf), "Header%d: ", i);
79  memset(&buf[len], 'A', SIZE_HEADERS);
80  buf[len + SIZE_HEADERS] = 0; /* zero terminate */
81  hl = curl_slist_append(headerlist, buf);
82  if(!hl)
83  goto test_cleanup;
84  headerlist = hl;
85  }
86 
87  hl = curl_slist_append(headerlist, "Expect: ");
88  if(!hl)
89  goto test_cleanup;
90  headerlist = hl;
91 
92  test_setopt(curl, CURLOPT_URL, URL);
93  test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
94  test_setopt(curl, CURLOPT_POST, 1L);
95 #ifdef CURL_DOES_CONVERSIONS
96  /* Convert the POST data to ASCII */
97  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
98 #endif
99  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
100  test_setopt(curl, CURLOPT_VERBOSE, 1L);
101  test_setopt(curl, CURLOPT_HEADER, 1L);
102  test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
103 
104  res = curl_easy_perform(curl);
105 
106 test_cleanup:
107 
108  curl_easy_cleanup(curl);
109 
110  curl_slist_free_all(headerlist);
111 
113 
114  return (int)res;
115 }
int test(char *URL)
Definition: lib553.c:58
#define POSTLEN
Definition: lib553.c:31
#define test_setopt(A, B, C)
Definition: test.h:47
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
static int res
unsigned int i
Definition: unit1303.c:79
size_t len
Definition: curl_sasl.c:55
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
#define SIZE_HEADERS
Definition: lib553.c:54
memcpy(filename, filename1, strlen(filename1))
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: slist.c:89
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: lib553.c:33
Definition: curl.h:455
static char buf[SIZE_HEADERS+100]
Definition: lib553.c:56
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
void CURL
Definition: curl.h:102
size_t size
Definition: unit1302.c:52
#define fprintf
Definition: curl_printf.h:41
#define snprintf
Definition: curl_printf.h:42
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 NUM_HEADERS
Definition: lib553.c:53
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
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