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