lib576.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "testutil.h"
00025 #include "memdebug.h"
00026 
00027 typedef struct {
00028   int remains;
00029   int print_content;
00030 } chunk_data_t;
00031 
00032 static
00033 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains);
00034 static
00035 long chunk_end(void *ptr);
00036 
00037 static
00038 long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains)
00039 {
00040   chunk_data_t *ch_d = ptr;
00041   ch_d->remains = remains;
00042 
00043   printf("=============================================================\n");
00044   printf("Remains:      %d\n", remains);
00045   printf("Filename:     %s\n", finfo->filename);
00046   if(finfo->strings.perm) {
00047     printf("Permissions:  %s", finfo->strings.perm);
00048     if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM)
00049       printf(" (parsed => %o)", finfo->perm);
00050     printf("\n");
00051   }
00052   printf("Size:         %ldB\n", (long)finfo->size);
00053   if(finfo->strings.user)
00054     printf("User:         %s\n", finfo->strings.user);
00055   if(finfo->strings.group)
00056     printf("Group:        %s\n", finfo->strings.group);
00057   if(finfo->strings.time)
00058     printf("Time:         %s\n", finfo->strings.time);
00059   printf("Filetype:     ");
00060   switch(finfo->filetype) {
00061   case CURLFILETYPE_FILE:
00062     printf("regular file\n");
00063     break;
00064   case CURLFILETYPE_DIRECTORY:
00065     printf("directory\n");
00066     break;
00067   case CURLFILETYPE_SYMLINK:
00068     printf("symlink\n");
00069     printf("Target:       %s\n", finfo->strings.target);
00070     break;
00071   default:
00072     printf("other type\n");
00073     break;
00074   }
00075   if(finfo->filetype == CURLFILETYPE_FILE) {
00076     ch_d->print_content = 1;
00077     printf("Content:\n-----------------------"
00078            "--------------------------------------\n");
00079   }
00080   if(strcmp(finfo->filename, "someothertext.txt") == 0) {
00081     printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n");
00082     return CURL_CHUNK_BGN_FUNC_SKIP;
00083   }
00084   return CURL_CHUNK_BGN_FUNC_OK;
00085 }
00086 
00087 static
00088 long chunk_end(void *ptr)
00089 {
00090   chunk_data_t *ch_d = ptr;
00091   if(ch_d->print_content) {
00092     ch_d->print_content = 0;
00093     printf("-------------------------------------------------------------\n");
00094   }
00095   if(ch_d->remains == 1)
00096     printf("=============================================================\n");
00097   return CURL_CHUNK_END_FUNC_OK;
00098 }
00099 
00100 int test(char *URL)
00101 {
00102   CURL *handle = NULL;
00103   CURLcode res = CURLE_OK;
00104   chunk_data_t chunk_data = {0, 0};
00105   curl_global_init(CURL_GLOBAL_ALL);
00106   handle = curl_easy_init();
00107   if(!handle) {
00108     res = CURLE_OUT_OF_MEMORY;
00109     goto test_cleanup;
00110   }
00111 
00112   test_setopt(handle, CURLOPT_URL, URL);
00113   test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
00114   test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn);
00115   test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end);
00116   test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data);
00117 
00118   res = curl_easy_perform(handle);
00119 
00120 test_cleanup:
00121   if(handle)
00122     curl_easy_cleanup(handle);
00123   curl_global_cleanup();
00124   return res;
00125 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05