lib539.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, 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.haxx.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;
  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. curl_global_cleanup();
  38. return TEST_ERR_MAJOR_BAD;
  39. }
  40. /*
  41. * Begin with curl set to use a single CWD to the URL's directory.
  42. */
  43. test_setopt(curl, CURLOPT_URL, URL);
  44. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  45. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  46. res = curl_easy_perform(curl);
  47. /*
  48. * Change the FTP_FILEMETHOD option to use full paths rather than a CWD
  49. * command. Alter the URL's path a bit, appending a "./". Use an innocuous
  50. * QUOTE command, after which curl will CWD to ftp_conn->entrypath and then
  51. * (on the next call to ftp_statemach_act) find a non-zero ftpconn->dirdepth
  52. * even though no directories are stored in the ftpconn->dirs array (after a
  53. * call to freedirs).
  54. */
  55. newURL = aprintf("%s./", URL);
  56. if(newURL == NULL) {
  57. curl_easy_cleanup(curl);
  58. curl_global_cleanup();
  59. return TEST_ERR_MAJOR_BAD;
  60. }
  61. slist = curl_slist_append(NULL, "SYST");
  62. if(slist == NULL) {
  63. free(newURL);
  64. curl_easy_cleanup(curl);
  65. curl_global_cleanup();
  66. return TEST_ERR_MAJOR_BAD;
  67. }
  68. test_setopt(curl, CURLOPT_URL, newURL);
  69. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
  70. test_setopt(curl, CURLOPT_QUOTE, slist);
  71. res = curl_easy_perform(curl);
  72. test_cleanup:
  73. curl_slist_free_all(slist);
  74. free(newURL);
  75. curl_easy_cleanup(curl);
  76. curl_global_cleanup();
  77. return (int)res;
  78. }