lib576.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "test.h"
  25. #include "testutil.h"
  26. #include "memdebug.h"
  27. struct chunk_data {
  28. int remains;
  29. int print_content;
  30. };
  31. static
  32. long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains)
  33. {
  34. struct chunk_data *ch_d = ptr;
  35. ch_d->remains = remains;
  36. printf("=============================================================\n");
  37. printf("Remains: %d\n", remains);
  38. printf("Filename: %s\n", finfo->filename);
  39. if(finfo->strings.perm) {
  40. printf("Permissions: %s", finfo->strings.perm);
  41. if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM)
  42. printf(" (parsed => %o)", finfo->perm);
  43. printf("\n");
  44. }
  45. printf("Size: %ldB\n", (long)finfo->size);
  46. if(finfo->strings.user)
  47. printf("User: %s\n", finfo->strings.user);
  48. if(finfo->strings.group)
  49. printf("Group: %s\n", finfo->strings.group);
  50. if(finfo->strings.time)
  51. printf("Time: %s\n", finfo->strings.time);
  52. printf("Filetype: ");
  53. switch(finfo->filetype) {
  54. case CURLFILETYPE_FILE:
  55. printf("regular file\n");
  56. break;
  57. case CURLFILETYPE_DIRECTORY:
  58. printf("directory\n");
  59. break;
  60. case CURLFILETYPE_SYMLINK:
  61. printf("symlink\n");
  62. printf("Target: %s\n", finfo->strings.target);
  63. break;
  64. default:
  65. printf("other type\n");
  66. break;
  67. }
  68. if(finfo->filetype == CURLFILETYPE_FILE) {
  69. ch_d->print_content = 1;
  70. printf("Content:\n"
  71. "-------------------------------------------------------------\n");
  72. }
  73. if(strcmp(finfo->filename, "someothertext.txt") == 0) {
  74. printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n");
  75. return CURL_CHUNK_BGN_FUNC_SKIP;
  76. }
  77. return CURL_CHUNK_BGN_FUNC_OK;
  78. }
  79. static
  80. long chunk_end(void *ptr)
  81. {
  82. struct chunk_data *ch_d = ptr;
  83. if(ch_d->print_content) {
  84. ch_d->print_content = 0;
  85. printf("-------------------------------------------------------------\n");
  86. }
  87. if(ch_d->remains == 1)
  88. printf("=============================================================\n");
  89. return CURL_CHUNK_END_FUNC_OK;
  90. }
  91. int test(char *URL)
  92. {
  93. CURL *handle = NULL;
  94. CURLcode res = CURLE_OK;
  95. struct chunk_data chunk_data = {0, 0};
  96. curl_global_init(CURL_GLOBAL_ALL);
  97. handle = curl_easy_init();
  98. if(!handle) {
  99. res = CURLE_OUT_OF_MEMORY;
  100. goto test_cleanup;
  101. }
  102. test_setopt(handle, CURLOPT_URL, URL);
  103. test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
  104. test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn);
  105. test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end);
  106. test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data);
  107. res = curl_easy_perform(handle);
  108. test_cleanup:
  109. if(handle)
  110. curl_easy_cleanup(handle);
  111. curl_global_cleanup();
  112. return res;
  113. }