CURLOPT_CHUNK_BGN_FUNCTION.3 3.8 KB

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