diff options
author | Brad King <brad.king@kitware.com> | 2014-11-10 15:43:10 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-11-10 15:43:10 (GMT) |
commit | 75f3a282b76baf615b17767d3768b781bfc463a7 (patch) | |
tree | 87dd923a0fa7e35491f7bec4b07e06966548a08a /Utilities/cmcurl/curltest.c | |
parent | a1f964ef6897343cd47f904b7cf7ad94b2b65e70 (diff) | |
parent | c02c747b85cf7bba8e81a955722122e844688d4c (diff) | |
download | CMake-75f3a282b76baf615b17767d3768b781bfc463a7.zip CMake-75f3a282b76baf615b17767d3768b781bfc463a7.tar.gz CMake-75f3a282b76baf615b17767d3768b781bfc463a7.tar.bz2 |
Merge topic 'update-curl'
c02c747b Tests: Update expected CTestTestFailedSubmit output
a427ed0c curl: Skip sanity check that triggers Clang warning
17b24d55 curl: Disable warnings to avoid changing 3rd party code
4c3bd340 curl: Skip check for inet_pton on Windows
54cb23c6 curl: Restore installation of OpenSSL DLLs
c50f0327 curl: Restore CURL_CA_BUNDLE option
681693c9 curl: Restore CMake-specific zlib selection code
10d80b68 curl: Restore CMake-specific test and install code
19593042 curl: Configure build to work within CMake
cf54aebb curl: Fix curl.h inclusion of curlbuild.h from CMake sources
c17e3207 curl: Use arch-aware CHECK_TYPE_SIZE results
1f7cb7e2 curl: Fix detection of headers with dependencies
b18c9044 curl: Drop inclusion of .rc file for static lib
860f0a2d curl: Select file APIs on Windows
5a3b55ed curl: Do not use 'dl' on HP-UX
59242702 curl: Simplify if() conditions on check result variables
...
Diffstat (limited to 'Utilities/cmcurl/curltest.c')
-rw-r--r-- | Utilities/cmcurl/curltest.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/Utilities/cmcurl/curltest.c b/Utilities/cmcurl/curltest.c new file mode 100644 index 0000000..210868e --- /dev/null +++ b/Utilities/cmcurl/curltest.c @@ -0,0 +1,159 @@ +/* Prevent warnings on Visual Studio */ +struct _RPC_ASYNC_STATE; + +#include "curl/curl.h" +#include <stdlib.h> +#include <string.h> + +int GetFtpFile(void) +{ + int retVal = 0; + CURL *curl; + CURLcode res; + curl = curl_easy_init(); + if(curl) + { + /* Get curl 7.9.2 from sunet.se's FTP site: */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_HEADER, 1); + curl_easy_setopt(curl, CURLOPT_URL, + "ftp://public.kitware.com/pub/cmake/cygwin/setup.hint"); + res = curl_easy_perform(curl); + if ( res != 0 ) + { + printf("Error fetching: ftp://public.kitware.com/pub/cmake/cygwin/setup.hint\n"); + retVal = 1; + } + + /* always cleanup */ + curl_easy_cleanup(curl); + } + else + { + printf("Cannot create curl object\n"); + retVal = 1; + } + return retVal; +} + +int GetWebFiles(char *url1, char *url2) +{ + int retVal = 0; + CURL *curl; + CURLcode res; + + char proxy[1024]; + int proxy_type = 0; + + if ( getenv("HTTP_PROXY") ) + { + proxy_type = 1; + if (getenv("HTTP_PROXY_PORT") ) + { + sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT")); + } + else + { + sprintf(proxy, "%s", getenv("HTTP_PROXY")); + } + if ( getenv("HTTP_PROXY_TYPE") ) + { + /* HTTP/SOCKS4/SOCKS5 */ + if ( strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0 ) + { + proxy_type = 1; + } + else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0 ) + { + proxy_type = 2; + } + else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0 ) + { + proxy_type = 3; + } + } + } + + curl = curl_easy_init(); + if(curl) + { + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_HEADER, 1); + + /* Using proxy */ + if ( proxy_type > 0 ) + { + curl_easy_setopt(curl, CURLOPT_PROXY, proxy); + switch (proxy_type) + { + case 2: + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); + break; + case 3: + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + break; + default: + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); + } + } + + /* get the first document */ + curl_easy_setopt(curl, CURLOPT_URL, url1); + res = curl_easy_perform(curl); + if ( res != 0 ) + { + printf("Error fetching: %s\n", url1); + retVal = 1; + } + + /* get another document from the same server using the same + connection */ + /* avoid warnings about url2 since below block is commented out: */ + (void) url2; + /* + curl_easy_setopt(curl, CURLOPT_URL, url2); + res = curl_easy_perform(curl); + if ( res != 0 ) + { + printf("Error fetching: %s\n", url2); + retVal = 1; + } + */ + + /* always cleanup */ + curl_easy_cleanup(curl); + } + else + { + printf("Cannot create curl object\n"); + retVal = 1; + } + + return retVal; +} + + +int main(int argc, char **argv) +{ + int retVal = 0; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + if(argc>1) + { + retVal += GetWebFiles(argv[1], 0); + } + else + { + printf("error: first argument should be a url to download\n"); + retVal = 1; + } + + /* Do not check the output of FTP socks5 cannot handle FTP yet */ + /* GetFtpFile(); */ + /* do not test ftp right now because we don't enable that port */ + + curl_global_cleanup(); + + return retVal; +} |