CURLOPT_CHUNK_BGN_FUNCTION.3 4.3 KB

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