lib1526.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2016, Vijay Panghal, <vpanghal@maginatics.com>, 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 /*
24  * This unit test PUT http data over proxy. Proxy header will be different
25  * from server http header
26  */
27 
28 #include "test.h"
29 
30 #include "memdebug.h"
31 
32 static char data [] = "Hello Cloud!\n";
33 
34 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
35 {
36  size_t amount = nmemb * size; /* Total bytes curl wants */
37  if(amount < strlen(data)) {
38  return strlen(data);
39  }
40  (void)stream;
41  memcpy(ptr, data, strlen(data));
42  return strlen(data);
43 }
44 
45 int test(char *URL)
46 {
47  CURL *curl = NULL;
49  /* http and proxy header list*/
50  struct curl_slist *hhl = NULL, *phl = NULL, *tmp = NULL;
51 
53  fprintf(stderr, "curl_global_init() failed\n");
54  return TEST_ERR_MAJOR_BAD;
55  }
56 
57  curl = curl_easy_init();
58  if(!curl) {
59  fprintf(stderr, "curl_easy_init() failed\n");
61  return TEST_ERR_MAJOR_BAD;
62  }
63 
64  hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
65  phl = curl_slist_append(phl, "User-Agent: Proxy Agent");
66  if(!hhl || !phl) {
67  goto test_cleanup;
68  }
69  tmp = curl_slist_append(phl, "Expect:");
70  if(!tmp) {
71  goto test_cleanup;
72  }
73  phl = tmp;
74 
75  test_setopt(curl, CURLOPT_URL, URL);
76  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
77  test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
78  test_setopt(curl, CURLOPT_PROXYHEADER, phl);
79  test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
80  test_setopt(curl, CURLOPT_POST, 0L);
81  test_setopt(curl, CURLOPT_UPLOAD, 1L);
82  test_setopt(curl, CURLOPT_VERBOSE, 1L);
83  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
84  test_setopt(curl, CURLOPT_HEADER, 1L);
85  test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
86  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
87  test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
88  test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data));
89 
90  res = curl_easy_perform(curl);
91 
92 test_cleanup:
93 
94  curl_easy_cleanup(curl);
95 
97 
99 
101 
102  return (int)res;
103 }
104 
#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
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: lib1526.c:34
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
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
#define CURLHEADER_SEPARATE
Definition: curl.h:841
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
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
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
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
int test(char *URL)
Definition: lib1526.c:45
size_t fwrite(const void *, size_t, size_t, FILE *)
Definition: debug.c:29
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