Git init
[external/curl.git] / tests / libtest / lib539.c
1 /*****************************************************************************
2   *                                  _   _ ____  _
3   *  Project                     ___| | | |  _ \| |
4   *                             / __| | | | |_) | |
5   *                            | (__| |_| |  _ <| |___
6   *                             \___|\___/|_| \_\_____|
7   *
8   */
9
10 #include "test.h"
11
12 #include "memdebug.h"
13
14 int test(char *URL)
15 {
16    CURLcode res;
17    CURL *curl;
18    char *newURL = NULL;
19    struct curl_slist *slist = NULL;
20
21    if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
22      fprintf(stderr, "curl_global_init() failed\n");
23      return TEST_ERR_MAJOR_BAD;
24    }
25
26    if ((curl = curl_easy_init()) == NULL) {
27      fprintf(stderr, "curl_easy_init() failed\n");
28      curl_global_cleanup();
29      return TEST_ERR_MAJOR_BAD;
30    }
31
32    /*
33     * Begin with cURL set to use a single CWD to the URL's directory.
34     */
35    test_setopt(curl, CURLOPT_URL, URL);
36    test_setopt(curl, CURLOPT_VERBOSE, 1L);
37    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
38
39    res = curl_easy_perform(curl);
40
41    /*
42     * Change the FTP_FILEMETHOD option to use full paths rather than a CWD
43     * command.  Alter the URL's path a bit, appending a "./".  Use an innocuous
44     * QUOTE command, after which cURL will CWD to ftp_conn->entrypath and then
45     * (on the next call to ftp_statemach_act) find a non-zero ftpconn->dirdepth
46     * even though no directories are stored in the ftpconn->dirs array (after a
47     * call to freedirs).
48     */
49    newURL = malloc(strlen(URL) + 3);
50    if (newURL == NULL) {
51      curl_easy_cleanup(curl);
52      curl_global_cleanup();
53      return TEST_ERR_MAJOR_BAD;
54    }
55    newURL = strcat(strcpy(newURL, URL), "./");
56
57    slist = curl_slist_append (NULL, "SYST");
58    if (slist == NULL) {
59      free(newURL);
60      curl_easy_cleanup(curl);
61      curl_global_cleanup();
62      return TEST_ERR_MAJOR_BAD;
63    }
64
65    test_setopt(curl, CURLOPT_URL, newURL);
66    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
67    test_setopt(curl, CURLOPT_QUOTE, slist);
68
69    res = curl_easy_perform(curl);
70
71 test_cleanup:
72
73    curl_slist_free_all(slist);
74    if(newURL)
75      free(newURL);
76    curl_easy_cleanup(curl);
77    curl_global_cleanup();
78
79    return (int)res;
80 }