lib1509.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2014, 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 
28 size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream);
29 size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream);
30 
31 static unsigned long realHeaderSize = 0;
32 
33 int test(char *URL)
34 {
35  long headerSize;
36  CURLcode code;
37  CURL *curl = NULL;
38  int res = 0;
39 
41 
42  easy_init(curl);
43 
44  easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
45 
46  easy_setopt(curl, CURLOPT_WRITEFUNCTION, *WriteOutput);
47  easy_setopt(curl, CURLOPT_HEADERFUNCTION, *WriteHeader);
48 
49  easy_setopt(curl, CURLOPT_HEADER, 1L);
50  easy_setopt(curl, CURLOPT_VERBOSE, 1L);
51  easy_setopt(curl, CURLOPT_URL, URL);
52  easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
53 
54  code = curl_easy_perform(curl);
55  if(CURLE_OK != code) {
56  fprintf(stderr, "%s:%d curl_easy_perform() failed, "
57  "with code %d (%s)\n",
58  __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
59  res = TEST_ERR_MAJOR_BAD;
60  goto test_cleanup;
61  }
62 
63  code = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
64  if(CURLE_OK != code) {
65  fprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
66  "with code %d (%s)\n",
67  __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
68  res = TEST_ERR_MAJOR_BAD;
69  goto test_cleanup;
70  }
71 
72  printf("header length is ........: %lu\n", headerSize);
73  printf("header length should be..: %lu\n", realHeaderSize);
74 
75 test_cleanup:
76 
77  curl_easy_cleanup(curl);
79 
80  return res;
81 }
82 
83 size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream)
84 {
85  fwrite(ptr, size, nmemb, stream);
86  return nmemb * size;
87 }
88 
89 size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream)
90 {
91  (void)ptr;
92  (void)stream;
93 
94  realHeaderSize += curlx_uztoul(size * nmemb);
95 
96  return nmemb * size;
97 }
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
static unsigned long realHeaderSize
Definition: lib1509.c:31
static int res
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
unsigned long curlx_uztoul(size_t uznum)
Definition: warnless.c:222
#define curl_easy_getinfo(handle, info, arg)
#define printf
Definition: curl_printf.h:40
#define easy_init(A)
Definition: test.h:145
size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: lib1509.c:83
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
void CURL
Definition: curl.h:102
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
int test(char *URL)
Definition: lib1509.c:33
size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: lib1509.c:89
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN const char * curl_easy_strerror(CURLcode)
Definition: strerror.c:57
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