lib547.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 /* argv1 = URL
23  * argv2 = proxy
24  * argv3 = proxyuser:password
25  */
26 
27 #include "test.h"
28 
29 #include "memdebug.h"
30 
31 #ifdef CURL_DOES_CONVERSIONS
32  /* ASCII representation with escape sequences for non-ASCII platforms */
33 # define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
34  "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
35  "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
36 #else
37 # define UPLOADTHIS "this is the blurb we want to upload\n"
38 #endif
39 
40 #ifndef LIB548
41 static size_t readcallback(void *ptr,
42  size_t size,
43  size_t nmemb,
44  void *clientp)
45 {
46  int *counter = (int *)clientp;
47 
48  if(*counter) {
49  /* only do this once and then require a clearing of this */
50  fprintf(stderr, "READ ALREADY DONE!\n");
51  return 0;
52  }
53  (*counter)++; /* bump */
54 
55  if(size * nmemb > strlen(UPLOADTHIS)) {
56  fprintf(stderr, "READ!\n");
57  strcpy(ptr, UPLOADTHIS);
58  return strlen(UPLOADTHIS);
59  }
60  fprintf(stderr, "READ NOT FINE!\n");
61  return 0;
62 }
63 static curlioerr ioctlcallback(CURL *handle,
64  int cmd,
65  void *clientp)
66 {
67  int *counter = (int *)clientp;
68  (void)handle; /* unused */
69  if(cmd == CURLIOCMD_RESTARTREAD) {
70  fprintf(stderr, "REWIND!\n");
71  *counter = 0; /* clear counter to make the read callback restart */
72  }
73  return CURLIOE_OK;
74 }
75 
76 
77 
78 #endif
79 
80 int test(char *URL)
81 {
82  CURLcode res;
83  CURL *curl;
84 #ifndef LIB548
85  int counter = 0;
86 #endif
87 
89  fprintf(stderr, "curl_global_init() failed\n");
90  return TEST_ERR_MAJOR_BAD;
91  }
92 
93  curl = curl_easy_init();
94  if(!curl) {
95  fprintf(stderr, "curl_easy_init() failed\n");
97  return TEST_ERR_MAJOR_BAD;
98  }
99 
100  test_setopt(curl, CURLOPT_URL, URL);
101  test_setopt(curl, CURLOPT_VERBOSE, 1L);
102  test_setopt(curl, CURLOPT_HEADER, 1L);
103 #ifdef LIB548
104  /* set the data to POST with a mere pointer to a zero-terminated string */
105  test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
106 #else
107  /* 547 style, which means reading the POST data from a callback */
108  test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
109  test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
110  test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
111  test_setopt(curl, CURLOPT_READDATA, &counter);
112  /* We CANNOT do the POST fine without setting the size (or choose
113  chunked)! */
114  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
115 #endif
116  test_setopt(curl, CURLOPT_POST, 1L);
117  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
118  test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
119  test_setopt(curl, CURLOPT_PROXYAUTH,
121 
122  res = curl_easy_perform(curl);
123 
124 test_cleanup:
125 
126  curl_easy_cleanup(curl);
128 
129  return (int)res;
130 }
131 
#define test_setopt(A, B, C)
Definition: test.h:47
#define CURLAUTH_BASIC
Definition: curl.h:697
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
static int res
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
static int counter[MAX_EASY_HANDLES]
int test(char *URL)
Definition: lib547.c:80
#define UPLOADTHIS
Definition: lib547.c:37
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
#define CURLAUTH_NTLM
Definition: curl.h:704
Definition: curl.h:455
curlioerr
Definition: curl.h:395
static curlioerr ioctlcallback(CURL *handle, int cmd, void *clientp)
Definition: lib547.c:63
char * libtest_arg3
Definition: first.c:76
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
#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
static size_t readcallback(void *ptr, size_t size, size_t nmemb, void *clientp)
Definition: lib547.c:41
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