27static std::map<std::string, std::string>
readStrings(std::istream& file)
29 std::map<std::string, std::string> parameters;
36 std::getline(file,
line);
37 int sep =
line.find(
'=');
40 std::string key =
line.substr(0, sep);
42 parameters[key] =
value;
51 size_t nmemb,
void *userp)
56 std::string* response =
static_cast<std::string *
>(userp);
57 size_t real_size =
size * nmemb;
58 response->append(
static_cast<char const *
>(ptr), real_size);
62static void getProperty(
const std::string& key, std::string& value,
63 std::map<std::string, std::string>& parameters)
65 auto itr = parameters.find(key);
66 if (itr != parameters.end())
69 parameters.erase(itr);
73static std::string
generate_json(
const std::map<std::string, std::string>& parameters)
78 for (
auto itr = parameters.begin(), itrEnd = parameters.end(); itr != itrEnd; ++itr)
85 stream <<
"\"" << itr->first <<
"\": \"" << itr->second <<
"\"";
92static bool uploadContent(std::map<std::string, std::string>& parameters, std::string& response)
94 CURL* curl = curl_easy_init();
98 std::string proxy, proxy_user_pwd, ca_certificate_file, file, url, version;
101 getProperty(
"ProxyUserPW", proxy_user_pwd, parameters);
102 getProperty(
"CAFile", ca_certificate_file, parameters);
116 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
117 curl_easy_setopt(curl, CURLOPT_USERAGENT,
kUserAgent);
118 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,
false);
122 curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
124 curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANYSAFE);
126 if (!proxy_user_pwd.empty())
127 curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_pwd.c_str());
129 curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
":");
132 if (!ca_certificate_file.empty())
133 curl_easy_setopt(curl, CURLOPT_CAINFO, ca_certificate_file.c_str());
135 curl_mime* mime = curl_mime_init(curl);
137 curl_mimepart* part = curl_mime_addpart(mime);
138 curl_mime_name(part,
"AdditionalData");
139 curl_mime_data(part, additional_data.c_str(), CURL_ZERO_TERMINATED);
141 part = curl_mime_addpart(mime);
142 curl_mime_name(part,
"Version");
143 curl_mime_data(part, version.c_str(), CURL_ZERO_TERMINATED);
145 part = curl_mime_addpart(mime);
146 curl_mime_name(part,
"upload_file_minidump");
147 curl_mime_filedata(part, file.c_str());
149 curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
153 char buf[] =
"Expect:";
154 curl_slist* headerlist =
nullptr;
155 headerlist = curl_slist_append(headerlist, buf);
156 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
158 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
WriteCallback);
159 std::string response_body;
160 curl_easy_setopt(curl, CURLOPT_WRITEDATA,
161 static_cast<void *
>(&response_body));
164 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
166 CURLcode cc = curl_easy_perform(curl);
168 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
170 "Failed to send http request to " <<
173 curl_easy_strerror(cc));
175 if (headerlist !=
nullptr)
177 curl_slist_free_all(headerlist);
180 response = response_body;
190bool readConfig(
const std::string& iniPath, std::string * response)
193 std::wstring iniPathW;
194 const int nChars = MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1,
nullptr, 0);
195 auto buf = std::make_unique<wchar_t[]>(nChars);
196 if (MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1, buf.get(), nChars) != 0)
197 iniPathW = buf.get();
199 std::ifstream file = iniPathW.empty() ? std::ifstream(iniPath) : std::ifstream(iniPathW);
201 std::ifstream file(iniPath);
203 std::map<std::string, std::string> parameters =
readStrings(file);
206 if (parameters.find(
"DumpFile") == parameters.end())
208 if(response !=
nullptr)
209 *response =
"ini file needs to contain a key DumpFile!";
213 if (parameters.find(
"Version") == parameters.end())
215 if (response !=
nullptr)
216 *response =
"ini file needs to contain a key Version!";
220 if (parameters.find(
"URL") == parameters.end())
222 if (response !=
nullptr)
223 *response =
"ini file needs to contain a key URL!";
227 if (response !=
nullptr)
Reference< XOutputStream > stream
#define SAL_WARN_IF(condition, area, stream)
static bool uploadContent(std::map< std::string, std::string > ¶meters, std::string &response)
static size_t WriteCallback(void const *ptr, size_t size, size_t nmemb, void *userp)
static std::map< std::string, std::string > readStrings(std::istream &file)
static std::string generate_json(const std::map< std::string, std::string > ¶meters)
static void getProperty(const std::string &key, std::string &value, std::map< std::string, std::string > ¶meters)
bool readConfig(const std::string &iniPath, std::string *response)
Read+Send, Test and send info from the Dump.ini .
constexpr OUStringLiteral first