lib576.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2016, 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 "memdebug.h"
26 
27 typedef struct {
28  int remains;
30 } chunk_data_t;
31 
32 static
33 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains);
34 static
35 long chunk_end(void *ptr);
36 
37 static
38 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains)
39 {
40  chunk_data_t *ch_d = ptr;
41  ch_d->remains = remains;
42 
43  printf("=============================================================\n");
44  printf("Remains: %d\n", remains);
45  printf("Filename: %s\n", finfo->filename);
46  if(finfo->strings.perm) {
47  printf("Permissions: %s", finfo->strings.perm);
48  if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM)
49  printf(" (parsed => %o)", finfo->perm);
50  printf("\n");
51  }
52  printf("Size: %ldB\n", (long)finfo->size);
53  if(finfo->strings.user)
54  printf("User: %s\n", finfo->strings.user);
55  if(finfo->strings.group)
56  printf("Group: %s\n", finfo->strings.group);
57  if(finfo->strings.time)
58  printf("Time: %s\n", finfo->strings.time);
59  printf("Filetype: ");
60  switch(finfo->filetype) {
61  case CURLFILETYPE_FILE:
62  printf("regular file\n");
63  break;
65  printf("directory\n");
66  break;
68  printf("symlink\n");
69  printf("Target: %s\n", finfo->strings.target);
70  break;
71  default:
72  printf("other type\n");
73  break;
74  }
75  if(finfo->filetype == CURLFILETYPE_FILE) {
76  ch_d->print_content = 1;
77  printf("Content:\n-----------------------"
78  "--------------------------------------\n");
79  }
80  if(strcmp(finfo->filename, "someothertext.txt") == 0) {
81  printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n");
83  }
85 }
86 
87 static
88 long chunk_end(void *ptr)
89 {
90  chunk_data_t *ch_d = ptr;
91  if(ch_d->print_content) {
92  ch_d->print_content = 0;
93  printf("-------------------------------------------------------------\n");
94  }
95  if(ch_d->remains == 1)
96  printf("=============================================================\n");
98 }
99 
100 int test(char *URL)
101 {
102  CURL *handle = NULL;
104  chunk_data_t chunk_data = {0, 0};
106  handle = curl_easy_init();
107  if(!handle) {
108  res = CURLE_OUT_OF_MEMORY;
109  goto test_cleanup;
110  }
111 
112  test_setopt(handle, CURLOPT_URL, URL);
113  test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
114  test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn);
115  test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end);
116  test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data);
117 
118  res = curl_easy_perform(handle);
119 
120 test_cleanup:
121  if(handle)
122  curl_easy_cleanup(handle);
124  return res;
125 }
unsigned int flags
Definition: curl.h:296
#define CURL_CHUNK_END_FUNC_OK
Definition: curl.h:317
#define test_setopt(A, B, C)
Definition: test.h:47
unsigned int perm
Definition: curl.h:281
#define CURLFINFOFLAG_KNOWN_PERM
Definition: curl.h:267
struct curl_fileinfo::@5 strings
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
char * target
Definition: curl.h:293
static int res
char * user
Definition: curl.h:291
static long chunk_end(void *ptr)
Definition: lib576.c:88
int print_content
Definition: lib576.c:29
static long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains)
Definition: lib576.c:38
curl_off_t size
Definition: curl.h:284
#define printf
Definition: curl_printf.h:40
int remains
Definition: lib576.c:28
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
curlfiletype filetype
Definition: curl.h:279
int test(char *URL)
Definition: lib576.c:100
char * group
Definition: curl.h:292
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
time_t time
Definition: curl.h:280
void CURL
Definition: curl.h:102
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 CURL_CHUNK_BGN_FUNC_OK
Definition: curl.h:305
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)
#define CURL_CHUNK_BGN_FUNC_SKIP
Definition: curl.h:307
char * filename
Definition: curl.h:278


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15