lib661.c 5.0 KB

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