Improve submtitting using http
This commit is contained in:
parent
170e4c9453
commit
61b488021e
@ -180,6 +180,9 @@ bool cmCTestSubmit::SubmitUsingHTTP(const std::string& localprefix,
|
|||||||
/* In windows, this will init the winsock stuff */
|
/* In windows, this will init the winsock stuff */
|
||||||
::curl_global_init(CURL_GLOBAL_ALL);
|
::curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
|
std::string::size_type cc, kk;
|
||||||
|
for ( cc = 0; cc < files.size(); cc ++ )
|
||||||
|
{
|
||||||
/* get a curl handle */
|
/* get a curl handle */
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl)
|
if(curl)
|
||||||
@ -202,39 +205,66 @@ bool cmCTestSubmit::SubmitUsingHTTP(const std::string& localprefix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type cc;
|
/* enable uploading */
|
||||||
for ( cc = 0; cc < files.size(); cc ++ )
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
/* HTTP PUT please */
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
|
||||||
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||||
|
|
||||||
|
std::string local_file = localprefix + "/" + files[cc];
|
||||||
|
std::string remote_file = remoteprefix + files[cc];
|
||||||
|
std::string ofile = "";
|
||||||
|
for ( kk = 0; kk < remote_file.size(); kk ++ )
|
||||||
|
{
|
||||||
|
char c = remote_file[kk];
|
||||||
|
char hex[4] = { 0, 0, 0, 0 };
|
||||||
|
hex[0] = c;
|
||||||
|
switch ( c )
|
||||||
|
{
|
||||||
|
case '+':
|
||||||
|
case '?':
|
||||||
|
case '/':
|
||||||
|
case '\\':
|
||||||
|
case '&':
|
||||||
|
case ' ':
|
||||||
|
case '=':
|
||||||
|
case '%':
|
||||||
|
sprintf(hex, "%%%02X", (int)c);
|
||||||
|
ofile.append(hex);
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ofile.append(hex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::string upload_as = url + "?FileName=" + ofile;
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if ( ::stat(local_file.c_str(), &st) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ftpfile = ::fopen(local_file.c_str(), "rb");
|
||||||
|
|
||||||
|
std::cout << "upload file: " << local_file.c_str() << " to "
|
||||||
|
<< upload_as.c_str() << " Size: " << st.st_size << std::endl;
|
||||||
|
|
||||||
|
|
||||||
// specify target
|
// specify target
|
||||||
::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
|
::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
|
||||||
|
|
||||||
|
// now specify which file to upload
|
||||||
|
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
|
||||||
|
|
||||||
|
// and give the size of the upload (optional)
|
||||||
|
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, st.st_size);
|
||||||
|
|
||||||
// Now run off and do what you've been told!
|
// Now run off and do what you've been told!
|
||||||
res = ::curl_easy_perform(curl);
|
res = ::curl_easy_perform(curl);
|
||||||
|
|
||||||
|
fclose(ftpfile);
|
||||||
if ( res )
|
if ( res )
|
||||||
{
|
{
|
||||||
std::cout << "Error when uploading" << std::endl;
|
std::cout << "Error when uploading" << std::endl;
|
||||||
@ -242,10 +272,10 @@ bool cmCTestSubmit::SubmitUsingHTTP(const std::string& localprefix,
|
|||||||
::curl_global_cleanup();
|
::curl_global_cleanup();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// always cleanup
|
// always cleanup
|
||||||
::curl_easy_cleanup(curl);
|
::curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
::curl_global_cleanup();
|
::curl_global_cleanup();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user