mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
curl: Modernize tiny test code used for build inside CMake
Drop unused code. Report the error message on failure. Format the source file using clang-format.
This commit is contained in:
1
Utilities/.gitattributes
vendored
1
Utilities/.gitattributes
vendored
@@ -5,3 +5,4 @@ SetupForDevelopment.sh export-ignore
|
|||||||
# Do not format third-party sources.
|
# Do not format third-party sources.
|
||||||
/KWIML/** -format.clang-format-6.0
|
/KWIML/** -format.clang-format-6.0
|
||||||
/cm*/** -format.clang-format-6.0
|
/cm*/** -format.clang-format-6.0
|
||||||
|
/cmcurl/curltest.c format.clang-format-6.0
|
||||||
|
@@ -1285,11 +1285,11 @@ endif()
|
|||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# CMake-specific curl code.
|
# CMake-specific curl code.
|
||||||
add_executable(LIBCURL curltest.c)
|
add_executable(curltest curltest.c)
|
||||||
target_link_libraries(LIBCURL cmcurl)
|
target_link_libraries(curltest cmcurl)
|
||||||
|
|
||||||
if(BUILD_TESTING AND CMAKE_CURL_TEST_URL)
|
if(BUILD_TESTING AND CMAKE_CURL_TEST_URL)
|
||||||
add_test(curl LIBCURL ${CMAKE_CURL_TEST_URL})
|
add_test(curl curltest ${CMAKE_CURL_TEST_URL})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
|
install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
|
||||||
|
@@ -1,159 +1,81 @@
|
|||||||
/* Prevent warnings on Visual Studio */
|
|
||||||
struct _RPC_ASYNC_STATE;
|
|
||||||
|
|
||||||
#include "curl/curl.h"
|
#include "curl/curl.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int GetFtpFile(void)
|
int test_curl(const char* url)
|
||||||
{
|
{
|
||||||
int retVal = 0;
|
CURL* curl;
|
||||||
CURL *curl;
|
CURLcode r;
|
||||||
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];
|
char proxy[1024];
|
||||||
int proxy_type = 0;
|
int proxy_type = 0;
|
||||||
|
|
||||||
if ( getenv("HTTP_PROXY") )
|
if (getenv("HTTP_PROXY")) {
|
||||||
{
|
|
||||||
proxy_type = 1;
|
proxy_type = 1;
|
||||||
if (getenv("HTTP_PROXY_PORT") )
|
if (getenv("HTTP_PROXY_PORT")) {
|
||||||
{
|
|
||||||
sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT"));
|
sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(proxy, "%s", getenv("HTTP_PROXY"));
|
sprintf(proxy, "%s", getenv("HTTP_PROXY"));
|
||||||
}
|
}
|
||||||
if ( getenv("HTTP_PROXY_TYPE") )
|
if (getenv("HTTP_PROXY_TYPE")) {
|
||||||
{
|
|
||||||
/* HTTP/SOCKS4/SOCKS5 */
|
/* HTTP/SOCKS4/SOCKS5 */
|
||||||
if ( strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0 )
|
if (strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0) {
|
||||||
{
|
|
||||||
proxy_type = 1;
|
proxy_type = 1;
|
||||||
}
|
} else if (strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0) {
|
||||||
else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0 )
|
|
||||||
{
|
|
||||||
proxy_type = 2;
|
proxy_type = 2;
|
||||||
}
|
} else if (strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0) {
|
||||||
else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0 )
|
|
||||||
{
|
|
||||||
proxy_type = 3;
|
proxy_type = 3;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl)
|
if (!curl) {
|
||||||
{
|
fprintf(stderr, "curl_easy_init failed\n");
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
return 1;
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
}
|
||||||
|
|
||||||
/* Using proxy */
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||||
if ( proxy_type > 0 )
|
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
||||||
{
|
|
||||||
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 */
|
if (proxy_type > 0) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url1);
|
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
|
||||||
res = curl_easy_perform(curl);
|
switch (proxy_type) {
|
||||||
if ( res != 0 )
|
case 2:
|
||||||
{
|
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
|
||||||
printf("Error fetching: %s\n", url1);
|
break;
|
||||||
retVal = 1;
|
case 3:
|
||||||
}
|
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||||
|
break;
|
||||||
/* get another document from the same server using the same
|
default:
|
||||||
connection */
|
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||||
/* 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;
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
r = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
if (r != CURLE_OK) {
|
||||||
|
fprintf(stderr, "error: fetching '%s' failed: %s\n", url,
|
||||||
|
curl_easy_strerror(r));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[])
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
int retVal = 0;
|
int r;
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
if (argc == 2) {
|
||||||
if(argc>1)
|
r = test_curl(argv[1]);
|
||||||
{
|
} else {
|
||||||
retVal += GetWebFiles(argv[1], 0);
|
fprintf(stderr, "error: no URL given as first argument\n");
|
||||||
}
|
r = 1;
|
||||||
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();
|
curl_global_cleanup();
|
||||||
|
return r;
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user