Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl / Testing / curltest.c
blob67c142f172aaca203db1b69bb2b7f95ce23481ff
1 /* Prevent warnings on Visual Studio */
2 struct _RPC_ASYNC_STATE;
4 #include "curl/curl.h"
5 #include <stdlib.h>
6 #include <string.h>
8 int GetFtpFile(void)
10 int retVal = 0;
11 CURL *curl;
12 CURLcode res;
13 curl = curl_easy_init();
14 if(curl)
16 /* Get curl 7.9.2 from sunet.se's FTP site: */
17 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
18 curl_easy_setopt(curl, CURLOPT_HEADER, 1);
19 curl_easy_setopt(curl, CURLOPT_URL,
20 "ftp://public.kitware.com/pub/cmake/cygwin/setup.hint");
21 res = curl_easy_perform(curl);
22 if ( res != 0 )
24 printf("Error fetching: ftp://public.kitware.com/pub/cmake/cygwin/setup.hint\n");
25 retVal = 1;
28 /* always cleanup */
29 curl_easy_cleanup(curl);
31 else
33 printf("Cannot create curl object\n");
34 retVal = 1;
36 return retVal;
39 int GetWebFile(void)
41 int retVal = 0;
42 CURL *curl;
43 CURLcode res;
45 char proxy[1024];
46 int proxy_type = 0;
48 if ( getenv("HTTP_PROXY") )
50 proxy_type = 1;
51 if (getenv("HTTP_PROXY_PORT") )
53 sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT"));
55 else
57 sprintf(proxy, "%s", getenv("HTTP_PROXY"));
59 if ( getenv("HTTP_PROXY_TYPE") )
61 /* HTTP/SOCKS4/SOCKS5 */
62 if ( strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0 )
64 proxy_type = 1;
66 else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0 )
68 proxy_type = 2;
70 else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0 )
72 proxy_type = 3;
77 curl = curl_easy_init();
78 if(curl)
80 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
81 curl_easy_setopt(curl, CURLOPT_HEADER, 1);
83 /* Using proxy */
84 if ( proxy_type > 0 )
86 curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
87 switch (proxy_type)
89 case 2:
90 curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
91 break;
92 case 3:
93 curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
94 break;
95 default:
96 curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
100 /* get the first document */
101 curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/page1.html");
102 res = curl_easy_perform(curl);
103 if ( res != 0 )
105 printf("Error fetching: http://www.cmake.org/page1.html\n");
106 retVal = 1;
109 /* get another document from the same server using the same
110 connection */
112 curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/page2.html");
113 res = curl_easy_perform(curl);
114 if ( res != 0 )
116 printf("Error fetching: http://www.cmake.org/page2.html\n");
117 retVal = 1;
121 /* always cleanup */
122 curl_easy_cleanup(curl);
124 else
126 printf("Cannot create curl object\n");
127 retVal = 1;
130 return retVal;
133 int main(/*int argc, char **argv*/)
135 int retVal = 0;
136 curl_global_init(CURL_GLOBAL_DEFAULT);
137 retVal += GetWebFile();
139 /* Do not check the output of FTP socks5 cannot handle FTP yet */
140 /* GetFtpFile(); */
141 /* do not test ftp right now because we don't enable that port */
142 curl_global_cleanup();
143 return retVal;