1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCTestSubmit.h"
#include "cmSystemTools.h"
#include "curl/curl.h"
#include <sys/stat.h>
bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
const std::vector<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
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)
{
// enable uploading
::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
std::string::size_type cc;
for ( cc = 0; cc < files.size(); cc ++ )
{
std::string local_file = localprefix + "/" + files[cc];
std::string upload_as = url + "/" + remoteprefix + files[cc];
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() << std::endl;
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// specify target
::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!
res = ::curl_easy_perform(curl);
fclose(ftpfile);
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,
const std::string& remoteprefix,
const std::string& url)
{
CURL *curl;
CURLcode res = CURLcode();
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)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
std::string::size_type cc, kk;
for ( cc = 0; cc < files.size(); cc ++ )
{
std::string file = remoteprefix + files[cc];
std::string ofile = "";
for ( kk = 0; kk < file.size(); kk ++ )
{
char c = 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 turl = url + "?xmlfile=" + ofile;
std::cout << "Trigger url: " << turl.c_str() << std::endl;
curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
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::SubmitUsingSCP(const std::string& localprefix,
const std::vector<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
return false;
}
|