| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
 | 2 |  *                                  _   _ ____  _ | 
 | 3 |  *  Project                     ___| | | |  _ \| | | 
 | 4 |  *                             / __| | | | |_) | | | 
 | 5 |  *                            | (__| |_| |  _ <| |___ | 
 | 6 |  *                             \___|\___/|_| \_\_____| | 
 | 7 |  * | 
 | 8 |  * Copyright (C) 1998 - 2022, 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.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 |  * SPDX-License-Identifier: curl | 
 | 22 |  * | 
 | 23 |  ***************************************************************************/ | 
 | 24 | #include "test.h" | 
 | 25 |  | 
 | 26 | #include "testutil.h" | 
 | 27 | #include "memdebug.h" | 
 | 28 |  | 
 | 29 | struct chunk_data { | 
 | 30 |   int remains; | 
 | 31 |   int print_content; | 
 | 32 | }; | 
 | 33 |  | 
 | 34 | static | 
 | 35 | long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains); | 
 | 36 | static | 
 | 37 | long chunk_end(void *ptr); | 
 | 38 |  | 
 | 39 | static | 
 | 40 | long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains) | 
 | 41 | { | 
 | 42 |   struct chunk_data *ch_d = ptr; | 
 | 43 |   ch_d->remains = remains; | 
 | 44 |  | 
 | 45 |   printf("=============================================================\n"); | 
 | 46 |   printf("Remains:      %d\n", remains); | 
 | 47 |   printf("Filename:     %s\n", finfo->filename); | 
 | 48 |   if(finfo->strings.perm) { | 
 | 49 |     printf("Permissions:  %s", finfo->strings.perm); | 
 | 50 |     if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM) | 
 | 51 |       printf(" (parsed => %o)", finfo->perm); | 
 | 52 |     printf("\n"); | 
 | 53 |   } | 
 | 54 |   printf("Size:         %ldB\n", (long)finfo->size); | 
 | 55 |   if(finfo->strings.user) | 
 | 56 |     printf("User:         %s\n", finfo->strings.user); | 
 | 57 |   if(finfo->strings.group) | 
 | 58 |     printf("Group:        %s\n", finfo->strings.group); | 
 | 59 |   if(finfo->strings.time) | 
 | 60 |     printf("Time:         %s\n", finfo->strings.time); | 
 | 61 |   printf("Filetype:     "); | 
 | 62 |   switch(finfo->filetype) { | 
 | 63 |   case CURLFILETYPE_FILE: | 
 | 64 |     printf("regular file\n"); | 
 | 65 |     break; | 
 | 66 |   case CURLFILETYPE_DIRECTORY: | 
 | 67 |     printf("directory\n"); | 
 | 68 |     break; | 
 | 69 |   case CURLFILETYPE_SYMLINK: | 
 | 70 |     printf("symlink\n"); | 
 | 71 |     printf("Target:       %s\n", finfo->strings.target); | 
 | 72 |     break; | 
 | 73 |   default: | 
 | 74 |     printf("other type\n"); | 
 | 75 |     break; | 
 | 76 |   } | 
 | 77 |   if(finfo->filetype == CURLFILETYPE_FILE) { | 
 | 78 |     ch_d->print_content = 1; | 
 | 79 |     printf("Content:\n-----------------------" | 
 | 80 |            "--------------------------------------\n"); | 
 | 81 |   } | 
 | 82 |   if(strcmp(finfo->filename, "someothertext.txt") == 0) { | 
 | 83 |     printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n"); | 
 | 84 |     return CURL_CHUNK_BGN_FUNC_SKIP; | 
 | 85 |   } | 
 | 86 |   return CURL_CHUNK_BGN_FUNC_OK; | 
 | 87 | } | 
 | 88 |  | 
 | 89 | static | 
 | 90 | long chunk_end(void *ptr) | 
 | 91 | { | 
 | 92 |   struct chunk_data *ch_d = ptr; | 
 | 93 |   if(ch_d->print_content) { | 
 | 94 |     ch_d->print_content = 0; | 
 | 95 |     printf("-------------------------------------------------------------\n"); | 
 | 96 |   } | 
 | 97 |   if(ch_d->remains == 1) | 
 | 98 |     printf("=============================================================\n"); | 
 | 99 |   return CURL_CHUNK_END_FUNC_OK; | 
 | 100 | } | 
 | 101 |  | 
 | 102 | int test(char *URL) | 
 | 103 | { | 
 | 104 |   CURL *handle = NULL; | 
 | 105 |   CURLcode res = CURLE_OK; | 
 | 106 |   struct chunk_data chunk_data = {0, 0}; | 
 | 107 |   curl_global_init(CURL_GLOBAL_ALL); | 
 | 108 |   handle = curl_easy_init(); | 
 | 109 |   if(!handle) { | 
 | 110 |     res = CURLE_OUT_OF_MEMORY; | 
 | 111 |     goto test_cleanup; | 
 | 112 |   } | 
 | 113 |  | 
 | 114 |   test_setopt(handle, CURLOPT_URL, URL); | 
 | 115 |   test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); | 
 | 116 |   test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn); | 
 | 117 |   test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end); | 
 | 118 |   test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data); | 
 | 119 |  | 
 | 120 |   res = curl_easy_perform(handle); | 
 | 121 |  | 
 | 122 | test_cleanup: | 
 | 123 |   if(handle) | 
 | 124 |     curl_easy_cleanup(handle); | 
 | 125 |   curl_global_cleanup(); | 
 | 126 |   return res; | 
 | 127 | } |