lib661.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. CURLcode 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. if(res != CURLE_REMOTE_FILE_NOT_FOUND)
  51. goto test_cleanup;
  52. curl_free(newURL);
  53. newURL = aprintf("%s/folderB/661", URL);
  54. test_setopt(curl, CURLOPT_URL, newURL);
  55. res = curl_easy_perform(curl);
  56. if(res != CURLE_REMOTE_FILE_NOT_FOUND)
  57. goto test_cleanup;
  58. /* test: CURLFTPMETHOD_NOCWD with absolute path should
  59. never emit CWD (for both new and reused easy handle) */
  60. curl_easy_cleanup(curl);
  61. curl = curl_easy_init();
  62. if(!curl) {
  63. fprintf(stderr, "curl_easy_init() failed\n");
  64. res = TEST_ERR_MAJOR_BAD;
  65. goto test_cleanup;
  66. }
  67. curl_free(newURL);
  68. newURL = aprintf("%s/folderA/661", URL);
  69. test_setopt(curl, CURLOPT_URL, newURL);
  70. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  71. test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
  72. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  73. res = curl_easy_perform(curl);
  74. if(res != CURLE_REMOTE_FILE_NOT_FOUND)
  75. goto test_cleanup;
  76. /* curve ball: CWD /folderB before reusing connection with _NOCWD */
  77. curl_free(newURL);
  78. newURL = aprintf("%s/folderB/661", URL);
  79. test_setopt(curl, CURLOPT_URL, newURL);
  80. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  81. res = curl_easy_perform(curl);
  82. if(res != CURLE_REMOTE_FILE_NOT_FOUND)
  83. goto test_cleanup;
  84. curl_free(newURL);
  85. newURL = aprintf("%s/folderA/661", URL);
  86. test_setopt(curl, CURLOPT_URL, newURL);
  87. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  88. res = curl_easy_perform(curl);
  89. if(res != CURLE_REMOTE_FILE_NOT_FOUND)
  90. goto test_cleanup;
  91. /* test: CURLFTPMETHOD_NOCWD with home-relative path should
  92. not emit CWD for first FTP access after login */
  93. curl_easy_cleanup(curl);
  94. curl = curl_easy_init();
  95. if(!curl) {
  96. fprintf(stderr, "curl_easy_init() failed\n");
  97. res = TEST_ERR_MAJOR_BAD;
  98. goto test_cleanup;
  99. }
  100. slist = curl_slist_append(NULL, "SYST");
  101. if(!slist) {
  102. fprintf(stderr, "curl_slist_append() failed\n");
  103. res = TEST_ERR_MAJOR_BAD;
  104. goto test_cleanup;
  105. }
  106. test_setopt(curl, CURLOPT_URL, URL);
  107. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  108. test_setopt(curl, CURLOPT_NOBODY, 1L);
  109. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  110. test_setopt(curl, CURLOPT_QUOTE, slist);
  111. res = curl_easy_perform(curl);
  112. if(res)
  113. goto test_cleanup;
  114. /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should
  115. not emit CWD for first FTP access after login */
  116. curl_easy_cleanup(curl);
  117. curl = curl_easy_init();
  118. if(!curl) {
  119. fprintf(stderr, "curl_easy_init() failed\n");
  120. res = TEST_ERR_MAJOR_BAD;
  121. goto test_cleanup;
  122. }
  123. test_setopt(curl, CURLOPT_URL, URL);
  124. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  125. test_setopt(curl, CURLOPT_NOBODY, 1L);
  126. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  127. test_setopt(curl, CURLOPT_QUOTE, slist);
  128. res = curl_easy_perform(curl);
  129. if(res)
  130. goto test_cleanup;
  131. /* test: CURLFTPMETHOD_NOCWD with home-relative path should
  132. not emit CWD for second FTP access when not needed +
  133. bonus: see if path buffering survives curl_easy_reset() */
  134. curl_easy_reset(curl);
  135. test_setopt(curl, CURLOPT_URL, URL);
  136. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  137. test_setopt(curl, CURLOPT_NOBODY, 1L);
  138. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  139. test_setopt(curl, CURLOPT_QUOTE, slist);
  140. res = curl_easy_perform(curl);
  141. test_cleanup:
  142. if(res)
  143. fprintf(stderr, "test encountered error %d\n", res);
  144. curl_slist_free_all(slist);
  145. curl_free(newURL);
  146. curl_easy_cleanup(curl);
  147. curl_global_cleanup();
  148. return res;
  149. }