CURLOPT_CHUNK_BGN_FUNCTION.3 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. .\"
  25. .TH CURLOPT_CHUNK_BGN_FUNCTION 3 "19 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_CHUNK_BGN_FUNCTION \- callback before a transfer with FTP wildcard match
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. struct curl_fileinfo {
  32. char *filename;
  33. curlfiletype filetype;
  34. time_t time; /* always zero! */
  35. unsigned int perm;
  36. int uid;
  37. int gid;
  38. curl_off_t size;
  39. long int hardlinks;
  40. struct {
  41. /* If some of these fields is not NULL, it is a pointer to b_data. */
  42. char *time;
  43. char *perm;
  44. char *user;
  45. char *group;
  46. char *target; /* pointer to the target filename of a symlink */
  47. } strings;
  48. unsigned int flags;
  49. /* used internally */
  50. char *b_data;
  51. size_t b_size;
  52. size_t b_used;
  53. };
  54. long chunk_bgn_callback(const void *transfer_info, void *ptr,
  55. int remains);
  56. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_BGN_FUNCTION,
  57. chunk_bgn_callback);
  58. .SH DESCRIPTION
  59. Pass a pointer to your callback function, which should match the prototype
  60. shown above.
  61. This callback function gets called by libcurl before a part of the stream is
  62. going to be transferred (if the transfer supports chunks).
  63. The \fItransfer_info\fP pointer will point to a \fBcurl_fileinfo\fP struct
  64. with details about the file that is about to get transferred.
  65. This callback makes sense only when using the \fICURLOPT_WILDCARDMATCH(3)\fP
  66. option for now.
  67. The target of transfer_info parameter is a "feature depended" structure. For
  68. the FTP wildcard download, the target is \fBcurl_fileinfo\fP structure (see
  69. \fIcurl/curl.h\fP). The parameter \fIptr\fP is a pointer given by
  70. \fICURLOPT_CHUNK_DATA(3)\fP. The parameter remains contains number of chunks
  71. remaining per the transfer. If the feature is not available, the parameter has
  72. zero value.
  73. Return \fICURL_CHUNK_BGN_FUNC_OK\fP if everything is fine,
  74. \fICURL_CHUNK_BGN_FUNC_SKIP\fP if you want to skip the concrete chunk or
  75. \fICURL_CHUNK_BGN_FUNC_FAIL\fP to tell libcurl to stop if some error occurred.
  76. .SH DEFAULT
  77. NULL
  78. .SH PROTOCOLS
  79. FTP
  80. .SH EXAMPLE
  81. .nf
  82. static long file_is_coming(struct curl_fileinfo *finfo,
  83. struct callback_data *data,
  84. int remains)
  85. {
  86. printf("%3d %40s %10luB ", remains, finfo->filename,
  87. (unsigned long)finfo->size);
  88. switch(finfo->filetype) {
  89. case CURLFILETYPE_DIRECTORY:
  90. printf(" DIR\\n");
  91. break;
  92. case CURLFILETYPE_FILE:
  93. printf("FILE ");
  94. break;
  95. default:
  96. printf("OTHER\\n");
  97. break;
  98. }
  99. if(finfo->filetype == CURLFILETYPE_FILE) {
  100. /* do not transfer files >= 50B */
  101. if(finfo->size > 50) {
  102. printf("SKIPPED\\n");
  103. return CURL_CHUNK_BGN_FUNC_SKIP;
  104. }
  105. data->output = fopen(finfo->filename, "wb");
  106. if(!data->output) {
  107. return CURL_CHUNK_BGN_FUNC_FAIL;
  108. }
  109. }
  110. return CURL_CHUNK_BGN_FUNC_OK;
  111. }
  112. int main()
  113. {
  114. /* data for callback */
  115. struct callback_data callback_info;
  116. /* callback is called before download of concrete file started */
  117. curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
  118. curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
  119. }
  120. .fi
  121. .SH AVAILABILITY
  122. This was added in 7.21.0
  123. .SH RETURN VALUE
  124. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  125. .SH "SEE ALSO"
  126. .BR CURLOPT_CHUNK_END_FUNCTION "(3), " CURLOPT_WILDCARDMATCH "(3), "