~ubuntu-branches/ubuntu/quantal/curl/quantal-updates

« back to all changes in this revision

Viewing changes to tests/libtest/lib539.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

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