1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
33 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains);
35 long chunk_end(void *ptr);
38 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains)
40 chunk_data_t *ch_d = ptr;
41 ch_d->remains = remains;
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);
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);
60 switch(finfo->filetype) {
61 case CURLFILETYPE_FILE:
62 printf("regular file\n");
64 case CURLFILETYPE_DIRECTORY:
65 printf("directory\n");
67 case CURLFILETYPE_SYMLINK:
69 printf("Target: %s\n", finfo->strings.target);
72 printf("other type\n");
75 if(finfo->filetype == CURLFILETYPE_FILE) {
76 ch_d->print_content = 1;
77 printf("Content:\n-------------------------------------------------------------\n");
79 if(strcmp(finfo->filename, "someothertext.txt") == 0) {
80 printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n");
81 return CURL_CHUNK_BGN_FUNC_SKIP;
83 return CURL_CHUNK_BGN_FUNC_OK;
87 long chunk_end(void *ptr)
89 chunk_data_t *ch_d = ptr;
90 if(ch_d->print_content) {
91 ch_d->print_content = 0;
92 printf("-------------------------------------------------------------\n");
94 if(ch_d->remains == 1)
95 printf("=============================================================\n");
96 return CURL_CHUNK_END_FUNC_OK;
102 CURLcode res = CURLE_OK;
103 chunk_data_t chunk_data = {0,0};
104 curl_global_init(CURL_GLOBAL_ALL);
105 handle = curl_easy_init();
107 res = CURLE_OUT_OF_MEMORY;
111 test_setopt(handle, CURLOPT_URL, URL);
112 test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
113 test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn);
114 test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end);
115 test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data);
117 res = curl_easy_perform(handle);
121 curl_easy_cleanup(handle);
122 curl_global_cleanup();