2
0

lib661.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "memdebug.h"
  26. int test(char *URL)
  27. {
  28. CURLcode res;
  29. CURL *curl = NULL;
  30. char *newURL = NULL;
  31. struct curl_slist *slist = NULL;
  32. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  33. fprintf(stderr, "curl_global_init() failed\n");
  34. return TEST_ERR_MAJOR_BAD;
  35. }
  36. curl = curl_easy_init();
  37. if(!curl) {
  38. fprintf(stderr, "curl_easy_init() failed\n");
  39. res = TEST_ERR_MAJOR_BAD;
  40. goto test_cleanup;
  41. }
  42. /* test: CURLFTPMETHOD_SINGLECWD with absolute path should
  43. skip CWD to entry path */
  44. newURL = aprintf("%s/folderA/661", URL);
  45. test_setopt(curl, CURLOPT_URL, newURL);
  46. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  47. test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
  48. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  49. res = curl_easy_perform(curl);
  50. free(newURL);
  51. newURL = aprintf("%s/folderB/661", URL);
  52. test_setopt(curl, CURLOPT_URL, newURL);
  53. res = curl_easy_perform(curl);
  54. /* test: CURLFTPMETHOD_NOCWD with absolute path should
  55. never emit CWD (for both new and reused easy handle) */
  56. curl_easy_cleanup(curl);
  57. curl = curl_easy_init();
  58. if(!curl) {
  59. fprintf(stderr, "curl_easy_init() failed\n");
  60. res = TEST_ERR_MAJOR_BAD;
  61. goto test_cleanup;
  62. }
  63. free(newURL);
  64. newURL = aprintf("%s/folderA/661", URL);
  65. test_setopt(curl, CURLOPT_URL, newURL);
  66. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  67. test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
  68. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  69. res = curl_easy_perform(curl);
  70. /* curve ball: CWD /folderB before reusing connection with _NOCWD */
  71. free(newURL);
  72. newURL = aprintf("%s/folderB/661", URL);
  73. test_setopt(curl, CURLOPT_URL, newURL);
  74. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  75. res = curl_easy_perform(curl);
  76. free(newURL);
  77. newURL = aprintf("%s/folderA/661", URL);
  78. test_setopt(curl, CURLOPT_URL, newURL);
  79. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  80. res = curl_easy_perform(curl);
  81. /* test: CURLFTPMETHOD_NOCWD with home-relative path should
  82. not emit CWD for first FTP access after login */
  83. curl_easy_cleanup(curl);
  84. curl = curl_easy_init();
  85. if(!curl) {
  86. fprintf(stderr, "curl_easy_init() failed\n");
  87. res = TEST_ERR_MAJOR_BAD;
  88. goto test_cleanup;
  89. }
  90. slist = curl_slist_append(NULL, "SYST");
  91. if(!slist) {
  92. fprintf(stderr, "curl_slist_append() failed\n");
  93. res = TEST_ERR_MAJOR_BAD;
  94. goto test_cleanup;
  95. }
  96. test_setopt(curl, CURLOPT_URL, URL);
  97. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  98. test_setopt(curl, CURLOPT_NOBODY, 1L);
  99. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  100. test_setopt(curl, CURLOPT_QUOTE, slist);
  101. res = curl_easy_perform(curl);
  102. /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should
  103. not emit CWD for first FTP access after login */
  104. curl_easy_cleanup(curl);
  105. curl = curl_easy_init();
  106. if(!curl) {
  107. fprintf(stderr, "curl_easy_init() failed\n");
  108. res = TEST_ERR_MAJOR_BAD;
  109. goto test_cleanup;
  110. }
  111. test_setopt(curl, CURLOPT_URL, URL);
  112. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  113. test_setopt(curl, CURLOPT_NOBODY, 1L);
  114. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  115. test_setopt(curl, CURLOPT_QUOTE, slist);
  116. res = curl_easy_perform(curl);
  117. /* test: CURLFTPMETHOD_NOCWD with home-relative path should
  118. not emit CWD for second FTP access when not needed +
  119. bonus: see if path buffering survives curl_easy_reset() */
  120. curl_easy_reset(curl);
  121. test_setopt(curl, CURLOPT_URL, URL);
  122. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  123. test_setopt(curl, CURLOPT_NOBODY, 1L);
  124. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  125. test_setopt(curl, CURLOPT_QUOTE, slist);
  126. res = curl_easy_perform(curl);
  127. test_cleanup:
  128. curl_slist_free_all(slist);
  129. free(newURL);
  130. curl_easy_cleanup(curl);
  131. curl_global_cleanup();
  132. return (int)res;
  133. }