lib539.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, 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 http://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. if ((curl = curl_easy_init()) == NULL) {
  35. fprintf(stderr, "curl_easy_init() failed\n");
  36. curl_global_cleanup();
  37. return TEST_ERR_MAJOR_BAD;
  38. }
  39. /*
  40. * Begin with cURL set to use a single CWD to the URL's directory.
  41. */
  42. test_setopt(curl, CURLOPT_URL, URL);
  43. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  44. test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
  45. res = curl_easy_perform(curl);
  46. /*
  47. * Change the FTP_FILEMETHOD option to use full paths rather than a CWD
  48. * command. Alter the URL's path a bit, appending a "./". Use an innocuous
  49. * QUOTE command, after which cURL will CWD to ftp_conn->entrypath and then
  50. * (on the next call to ftp_statemach_act) find a non-zero ftpconn->dirdepth
  51. * even though no directories are stored in the ftpconn->dirs array (after a
  52. * call to freedirs).
  53. */
  54. newURL = malloc(strlen(URL) + 3);
  55. if (newURL == NULL) {
  56. curl_easy_cleanup(curl);
  57. curl_global_cleanup();
  58. return TEST_ERR_MAJOR_BAD;
  59. }
  60. newURL = strcat(strcpy(newURL, URL), "./");
  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. if(newURL)
  75. free(newURL);
  76. curl_easy_cleanup(curl);
  77. curl_global_cleanup();
  78. return (int)res;
  79. }