Add support for http submit. Also, add support for proxy, but it does not work yet.
This commit is contained in:
parent
a27c3fa008
commit
f722e3c669
@ -21,6 +21,71 @@
|
|||||||
#include "curl/curl.h"
|
#include "curl/curl.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
cmCTestSubmit::cmCTestSubmit() : m_HTTPProxy(), m_FTPProxy()
|
||||||
|
{
|
||||||
|
std::cout << "Setup proxy" << endl;
|
||||||
|
m_HTTPProxy = "";
|
||||||
|
m_HTTPProxyType = 0;
|
||||||
|
if ( getenv("HTTP_PROXY") )
|
||||||
|
{
|
||||||
|
m_HTTPProxyType = 1;
|
||||||
|
m_HTTPProxy = getenv("HTTP_PROXY");
|
||||||
|
if ( getenv("HTTP_PROXY_PORT") )
|
||||||
|
{
|
||||||
|
m_HTTPProxy += ":";
|
||||||
|
m_HTTPProxy += getenv("HTTP_PROXY_PORT");
|
||||||
|
}
|
||||||
|
if ( getenv("HTTP_PROXY_TYPE") )
|
||||||
|
{
|
||||||
|
std::string type = getenv("HTTP_PROXY_TYPE");
|
||||||
|
// HTTP/SOCKS4/SOCKS5
|
||||||
|
if ( type == "HTTP" )
|
||||||
|
{
|
||||||
|
m_HTTPProxyType = 1;
|
||||||
|
}
|
||||||
|
else if ( type == "SOCKS4" )
|
||||||
|
{
|
||||||
|
m_HTTPProxyType = 2;
|
||||||
|
}
|
||||||
|
else if ( type == "SOCKS5" )
|
||||||
|
{
|
||||||
|
m_HTTPProxyType = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_FTPProxy = "";
|
||||||
|
m_FTPProxyType = 0;
|
||||||
|
if ( getenv("FTP_PROXY") )
|
||||||
|
{
|
||||||
|
m_FTPProxyType = 1;
|
||||||
|
m_FTPProxy = getenv("FTP_PROXY");
|
||||||
|
if ( getenv("FTP_PROXY_PORT") )
|
||||||
|
{
|
||||||
|
m_FTPProxy += ":";
|
||||||
|
m_FTPProxy += getenv("FTP_PROXY_PORT");
|
||||||
|
}
|
||||||
|
if ( getenv("FTP_PROXY_TYPE") )
|
||||||
|
{
|
||||||
|
std::string type = getenv("FTP_PROXY_TYPE");
|
||||||
|
// HTTP/SOCKS4/SOCKS5
|
||||||
|
if ( type == "HTTP" )
|
||||||
|
{
|
||||||
|
m_FTPProxyType = 1;
|
||||||
|
}
|
||||||
|
else if ( type == "SOCKS4" )
|
||||||
|
{
|
||||||
|
m_FTPProxyType = 2;
|
||||||
|
}
|
||||||
|
else if ( type == "SOCKS5" )
|
||||||
|
{
|
||||||
|
m_FTPProxyType = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << this << " HTTP Proxy: " << m_HTTPProxy << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
|
bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
|
||||||
const std::vector<std::string>& files,
|
const std::vector<std::string>& files,
|
||||||
const std::string& remoteprefix,
|
const std::string& remoteprefix,
|
||||||
@ -37,6 +102,23 @@ bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
|
|||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl)
|
if(curl)
|
||||||
{
|
{
|
||||||
|
// Using proxy
|
||||||
|
if ( m_FTPProxyType > 0 )
|
||||||
|
{
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PROXY, m_FTPProxy.c_str());
|
||||||
|
switch (m_FTPProxyType)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// enable uploading
|
// enable uploading
|
||||||
::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
|
::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
|
||||||
|
|
||||||
@ -84,6 +166,90 @@ bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uploading files is simpler
|
||||||
|
bool cmCTestSubmit::SubmitUsingHTTP(const std::string& localprefix,
|
||||||
|
const std::vector<std::string>& files,
|
||||||
|
const std::string& remoteprefix,
|
||||||
|
const std::string& url)
|
||||||
|
{
|
||||||
|
std::cout << this << " Using proxy: " << m_HTTPProxy << std::endl;
|
||||||
|
CURL *curl;
|
||||||
|
CURLcode res;
|
||||||
|
FILE* ftpfile;
|
||||||
|
|
||||||
|
/* In windows, this will init the winsock stuff */
|
||||||
|
::curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
|
/* get a curl handle */
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if(curl)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Using proxy
|
||||||
|
if ( m_HTTPProxyType > 0 )
|
||||||
|
{
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PROXY, m_HTTPProxy.c_str());
|
||||||
|
switch (m_HTTPProxyType)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string::size_type cc;
|
||||||
|
for ( cc = 0; cc < files.size(); cc ++ )
|
||||||
|
{
|
||||||
|
std::string local_file = localprefix + "/" + files[cc];
|
||||||
|
std::string upload_as = url;
|
||||||
|
std::string remote_file = remoteprefix + files[cc];
|
||||||
|
|
||||||
|
struct HttpPost *formpost=NULL;
|
||||||
|
struct HttpPost *lastptr=NULL;
|
||||||
|
|
||||||
|
/* Fill in the file upload field */
|
||||||
|
curl_formadd(&formpost,
|
||||||
|
&lastptr,
|
||||||
|
CURLFORM_COPYNAME, "FileData",
|
||||||
|
CURLFORM_FILE, local_file.c_str(),
|
||||||
|
CURLFORM_END);
|
||||||
|
curl_formadd(&formpost,
|
||||||
|
&lastptr,
|
||||||
|
CURLFORM_COPYNAME, "FileName",
|
||||||
|
CURLFORM_COPYCONTENTS, remote_file.c_str(),
|
||||||
|
CURLFORM_END);
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||||
|
std::cout << "upload file: " << local_file.c_str() << " to "
|
||||||
|
<< upload_as.c_str() << std::endl;
|
||||||
|
|
||||||
|
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||||
|
// specify target
|
||||||
|
::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
|
||||||
|
|
||||||
|
// Now run off and do what you've been told!
|
||||||
|
res = ::curl_easy_perform(curl);
|
||||||
|
|
||||||
|
if ( res )
|
||||||
|
{
|
||||||
|
std::cout << "Error when uploading" << std::endl;
|
||||||
|
::curl_easy_cleanup(curl);
|
||||||
|
::curl_global_cleanup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// always cleanup
|
||||||
|
::curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
::curl_global_cleanup();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool cmCTestSubmit::TriggerUsingHTTP(const std::vector<std::string>& files,
|
bool cmCTestSubmit::TriggerUsingHTTP(const std::vector<std::string>& files,
|
||||||
const std::string& remoteprefix,
|
const std::string& remoteprefix,
|
||||||
const std::string& url)
|
const std::string& url)
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
class cmCTestSubmit
|
class cmCTestSubmit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmCTestSubmit() {}
|
cmCTestSubmit();
|
||||||
~cmCTestSubmit() {}
|
~cmCTestSubmit() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +38,10 @@ public:
|
|||||||
const std::vector<std::string>& files,
|
const std::vector<std::string>& files,
|
||||||
const std::string& remoteprefix,
|
const std::string& remoteprefix,
|
||||||
const std::string& url);
|
const std::string& url);
|
||||||
|
bool SubmitUsingHTTP(const std::string& localprefix,
|
||||||
|
const std::vector<std::string>& files,
|
||||||
|
const std::string& remoteprefix,
|
||||||
|
const std::string& url);
|
||||||
bool SubmitUsingSCP(const std::string& localprefix,
|
bool SubmitUsingSCP(const std::string& localprefix,
|
||||||
const std::vector<std::string>& files,
|
const std::vector<std::string>& files,
|
||||||
const std::string& remoteprefix,
|
const std::string& remoteprefix,
|
||||||
@ -46,6 +50,12 @@ public:
|
|||||||
bool TriggerUsingHTTP(const std::vector<std::string>& files,
|
bool TriggerUsingHTTP(const std::vector<std::string>& files,
|
||||||
const std::string& remoteprefix,
|
const std::string& remoteprefix,
|
||||||
const std::string& url);
|
const std::string& url);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_HTTPProxy;
|
||||||
|
int m_HTTPProxyType;
|
||||||
|
std::string m_FTPProxy;
|
||||||
|
int m_FTPProxyType;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user