CURLOPT_CHUNK_BGN_FUNCTION.3 3.5 KB

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