lib578.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 "memdebug.h"
25 
26 /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
27 static char data[]="this is a short string.\n";
28 
29 static size_t data_size = sizeof(data) / sizeof(char);
30 
31 static int progress_callback(void *clientp, double dltotal, double dlnow,
32  double ultotal, double ulnow)
33 {
34  FILE *moo = fopen(libtest_arg2, "wb");
35 
36  (void)clientp; /* UNUSED */
37  (void)dltotal; /* UNUSED */
38  (void)dlnow; /* UNUSED */
39 
40  if(moo) {
41  if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
42  fprintf(moo, "PASSED, UL data matched data size\n");
43  else
44  fprintf(moo, "Progress callback called with UL %f out of %f\n",
45  ulnow, ultotal);
46  fclose(moo);
47  }
48  return 0;
49 }
50 
51 int test(char *URL)
52 {
53  CURL *curl;
55 
57  fprintf(stderr, "curl_global_init() failed\n");
58  return TEST_ERR_MAJOR_BAD;
59  }
60 
61  curl = curl_easy_init();
62  if(!curl) {
63  fprintf(stderr, "curl_easy_init() failed\n");
65  return TEST_ERR_MAJOR_BAD;
66  }
67 
68  /* First set the URL that is about to receive our POST. */
69  test_setopt(curl, CURLOPT_URL, URL);
70 
71  /* Now specify we want to POST data */
72  test_setopt(curl, CURLOPT_POST, 1L);
73 
74 #ifdef CURL_DOES_CONVERSIONS
75  /* Convert the POST data to ASCII */
76  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
77 #endif
78 
79  /* Set the expected POST size */
80  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data_size);
81  test_setopt(curl, CURLOPT_POSTFIELDS, data);
82 
83  /* we want to use our own progress function */
84  test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
85  test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
86 
87  /* pointer to pass to our read function */
88 
89  /* get verbose debug output please */
90  test_setopt(curl, CURLOPT_VERBOSE, 1L);
91 
92  /* include headers in the output */
93  test_setopt(curl, CURLOPT_HEADER, 1L);
94 
95  /* Perform the request, res will get the return code */
96  res = curl_easy_perform(curl);
97 
98 test_cleanup:
99 
100  /* always cleanup */
101  curl_easy_cleanup(curl);
103 
104  return res;
105 }
#define test_setopt(A, B, C)
Definition: test.h:47
int test(char *URL)
Definition: lib578.c:51
CURLcode
Definition: curl.h:454
static int res
static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Definition: lib578.c:31
static size_t data_size
Definition: lib578.c:29
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
static char data[]
Definition: lib578.c:27
curl_easy_setopt expects a curl_off_t argument for this option curl_easy_setopt expects a curl_write_callback argument for this option curl_easy_setopt expects a curl_ioctl_callback argument for this option curl_easy_setopt expects a curl_opensocket_callback argument for this option curl_easy_setopt expects a curl_debug_callback argument for this option curl_easy_setopt expects a curl_conv_callback argument for this option curl_easy_setopt expects a private data pointer as argument for this option curl_easy_setopt expects a FILE *argument for this option curl_easy_setopt expects a struct curl_httppost *argument for this option curl_easy_setopt expects a struct curl_slist *argument for this option curl_easy_getinfo expects a pointer to char *for this info curl_easy_getinfo expects a pointer to double for this info curl_easy_getinfo expects a pointer to struct curl_tlssessioninfo *for this info curl_easy_getinfo expects a pointer to curl_socket_t for this info size_t
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
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
#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
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