Imported Upstream version 7.59.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_CHUNK_BGN_FUNCTION.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2017, 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.haxx.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 .\" **************************************************************************
22 .\"
23 .TH CURLOPT_CHUNK_BGN_FUNCTION 3 "May 31, 2017" "libcurl 7.59.0" "curl_easy_setopt options"
24
25 .SH NAME
26 CURLOPT_CHUNK_BGN_FUNCTION \- callback before a transfer with FTP wildcardmatch
27 .SH SYNOPSIS
28 .nf
29 #include <curl/curl.h>
30
31 long chunk_bgn_callback(const void *transfer_info, void *ptr,
32                         int remains);
33
34 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_BGN_FUNCTION,
35                           chunk_bgn_callback);
36 .SH DESCRIPTION
37 Pass a pointer to your callback function, which should match the prototype
38 shown above.
39
40 This callback function gets called by libcurl before a part of the stream is
41 going to be transferred (if the transfer supports chunks).
42
43 The \fItransfer_info\fP pointer will point to a struct curl_fileinfo with
44 details about the file that is about to get transferred.
45
46 This callback makes sense only when using the \fICURLOPT_WILDCARDMATCH(3)\fP
47 option for now.
48
49 The target of transfer_info parameter is a "feature depended" structure. For
50 the FTP wildcard download, the target is curl_fileinfo structure (see
51 \fIcurl/curl.h\fP).  The parameter \fIptr\fP is a pointer given by
52 \fICURLOPT_CHUNK_DATA(3)\fP. The parameter remains contains number of chunks
53 remaining per the transfer. If the feature is not available, the parameter has
54 zero value.
55
56 Return \fICURL_CHUNK_BGN_FUNC_OK\fP if everything is fine,
57 \fICURL_CHUNK_BGN_FUNC_SKIP\fP if you want to skip the concrete chunk or
58 \fICURL_CHUNK_BGN_FUNC_FAIL\fP to tell libcurl to stop if some error occurred.
59 .SH DEFAULT
60 NULL
61 .SH PROTOCOLS
62 FTP
63 .SH EXAMPLE
64 .nf
65 static long file_is_coming(struct curl_fileinfo *finfo,
66                            struct callback_data *data,
67                            int remains)
68 {
69   printf("%3d %40s %10luB ", remains, finfo->filename,
70          (unsigned long)finfo->size);
71
72   switch(finfo->filetype) {
73   case CURLFILETYPE_DIRECTORY:
74     printf(" DIR\n");
75     break;
76   case CURLFILETYPE_FILE:
77     printf("FILE ");
78     break;
79   default:
80     printf("OTHER\n");
81     break;
82   }
83
84   if(finfo->filetype == CURLFILETYPE_FILE) {
85     /* do not transfer files >= 50B */
86     if(finfo->size > 50) {
87       printf("SKIPPED\n");
88       return CURL_CHUNK_BGN_FUNC_SKIP;
89     }
90
91     data->output = fopen(finfo->filename, "wb");
92     if(!data->output) {
93       return CURL_CHUNK_BGN_FUNC_FAIL;
94     }
95   }
96
97   return CURL_CHUNK_BGN_FUNC_OK;
98 }
99
100 int main()
101 {
102   /* data for callback */
103   struct callback_data callback_info;
104
105   /* callback is called before download of concrete file started */
106   curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
107   curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
108 }
109 .fi
110 .SH AVAILABILITY
111 This was added in 7.21.0
112 .SH RETURN VALUE
113 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
114 .SH "SEE ALSO"
115 .BR CURLOPT_CHUNK_END_FUNCTION "(3), " CURLOPT_WILDCARDMATCH "(3), "