quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib576.c (3958B)


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