summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-11-25 23:48:20 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-02-26 11:29:49 +0000
commitbf250abe262a25e6508a6dd0c0b7f3275d93e216 (patch)
tree2d84af03f59a0fa253f42b9c11f9aac5f9ada5e1 /desktop
parent97474cae830524fe57887d26743760bd49bb47ec (diff)
write an own minidump uploader
This one is platform independent and uses a key-value file. Change-Id: I28a4483763666a5a8520874bf8e984eaaf24e9c0 Reviewed-on: https://gerrit.libreoffice.org/22557 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/Executable_minidump_upload.mk22
-rw-r--r--desktop/Module_desktop.mk1
-rw-r--r--desktop/source/minidump/minidump_upload.cxx202
3 files changed, 225 insertions, 0 deletions
diff --git a/desktop/Executable_minidump_upload.mk b/desktop/Executable_minidump_upload.mk
new file mode 100644
index 000000000000..7fe9546a9624
--- /dev/null
+++ b/desktop/Executable_minidump_upload.mk
@@ -0,0 +1,22 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,minidump_upload))
+
+$(eval $(call gb_Executable_use_libraries,minidump_upload,\
+ sal \
+))
+
+$(eval $(call gb_Executable_use_external,minidump_upload,curl))
+
+$(eval $(call gb_Executable_add_exception_objects,minidump_upload,\
+ desktop/source/minidump/minidump_upload \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk
index d74d40629a28..c87a777f27f0 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -33,6 +33,7 @@ ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
$(eval $(call gb_Module_add_targets,desktop,\
Executable_soffice_bin \
Executable_unopkg_bin \
+ Executable_minidump_upload \
Library_migrationoo2 \
Library_migrationoo3 \
Library_unopkgapp \
diff --git a/desktop/source/minidump/minidump_upload.cxx b/desktop/source/minidump/minidump_upload.cxx
new file mode 100644
index 000000000000..220286a4fba0
--- /dev/null
+++ b/desktop/source/minidump/minidump_upload.cxx
@@ -0,0 +1,202 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <string>
+#include <map>
+#include <memory>
+#include <iostream>
+#include <fstream>
+
+#include <curl/curl.h>
+
+static const char kUserAgent[] = "Breakpad/1.0 (Linux)";
+
+std::map<std::string, std::string> readStrings(std::istream& file)
+{
+ std::map<std::string, std::string> parameters;
+
+
+ while (!file.eof())
+ {
+ std::string line;
+ std::getline(file, line);
+ int sep = line.find('=');
+ if (sep >= 0)
+ {
+ std::string key = line.substr(0, sep);
+ std::string value = line.substr(sep + 1);
+ parameters[key] = value;
+ }
+ }
+
+ return parameters;
+}
+
+// Callback to get the response data from server.
+static size_t WriteCallback(void *ptr, size_t size,
+ size_t nmemb, void *userp)
+{
+ if (!userp)
+ return 0;
+
+ std::string* response = reinterpret_cast<std::string *>(userp);
+ size_t real_size = size * nmemb;
+ response->append(reinterpret_cast<char *>(ptr), real_size);
+ return real_size;
+}
+
+void getProperty(const std::string& key, std::string& value,
+ std::map<std::string, std::string>& parameters)
+{
+ auto itr = parameters.find(key);
+ if (itr != parameters.end())
+ {
+ value = itr->second;
+ parameters.erase(itr);
+ }
+}
+
+bool uploadContent(std::map<std::string, std::string>& parameters)
+{
+ CURL* curl = curl_easy_init();
+ if (!curl)
+ return false;
+
+ std::string proxy, proxy_user_pwd, ca_certificate_file, file;
+
+ std::string url = "http://libreofficecrash.org/submit";
+
+ getProperty("Proxy", proxy, parameters);
+ getProperty("ProxyUserPW", proxy_user_pwd, parameters);
+ getProperty("CAFile", ca_certificate_file, parameters);
+
+ getProperty("DumpFile", file, parameters);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ curl_easy_setopt(curl, CURLOPT_USERAGENT, kUserAgent);
+ // Set proxy information if necessary.
+ if (!proxy.empty())
+ curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
+ if (!proxy_user_pwd.empty())
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_pwd.c_str());
+
+ if (!ca_certificate_file.empty())
+ curl_easy_setopt(curl, CURLOPT_CAINFO, ca_certificate_file.c_str());
+
+ curl_httppost* formpost = nullptr;
+ curl_httppost* lastptr = nullptr;
+ for (auto itr = parameters.begin(), itEnd = parameters.end(); itr != itEnd; ++itr)
+ {
+ curl_formadd(&formpost, &lastptr,
+ CURLFORM_COPYNAME, itr->first.c_str(),
+ CURLFORM_COPYCONTENTS, itr->second.c_str(),
+ CURLFORM_END);
+ }
+
+ std::string response_body;
+ long response_code;
+ curl_formadd(&formpost, &lastptr,
+ CURLFORM_COPYNAME, "upload_file_minidump",
+ CURLFORM_FILE, file.c_str(),
+ CURLFORM_END);
+
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+
+
+ // Disable 100-continue header.
+ char buf[] = "Expect:";
+ curl_slist* headerlist = NULL;
+ headerlist = curl_slist_append(headerlist, buf);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
+
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA,
+ reinterpret_cast<void *>(&response_body));
+
+ // Fail if 400+ is returned from the web server.
+ curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+
+ CURLcode cc = curl_easy_perform(curl);
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
+#ifndef NDEBUG
+ if (cc != CURLE_OK)
+ fprintf(stderr, "Failed to send http request to %s, error: %s\n",
+ url.c_str(),
+ curl_easy_strerror(cc));
+#endif
+ /*
+ * TODO
+ if (error_description != NULL)
+ *error_description = curl_easy_strerror(cc);
+ */
+
+ if (formpost != NULL)
+ {
+ curl_formfree(formpost);
+ }
+ if (headerlist != NULL)
+ {
+ curl_slist_free_all(headerlist);
+ }
+
+ std::cerr << response_body << std::endl;
+
+
+ if( CURLE_OK != cc )
+ return false;
+
+ return true;
+}
+
+bool readConfig(char** argv)
+{
+ std::string iniPath = argv[1];
+
+ std::ifstream file(iniPath);
+ std::map<std::string, std::string> parameters = readStrings(file);
+
+ // make sure that at least the mandatory parameters are in there
+ if (parameters.find("DumpFile") == parameters.end())
+ {
+ std::cerr << "ini file needs to contain a key DumpFile!";
+ return false;
+ }
+
+ if (parameters.find("Version") == parameters.end())
+ {
+ std::cerr << "ini file needs to contain a key Version!";
+ return false;
+ }
+
+ if (parameters.find("ProductName") == parameters.end())
+ {
+ std::cerr << "ini file needs to contain a ket ProductName!";
+ return false;
+ }
+
+ uploadContent(parameters);
+
+ return true;
+}
+
+int main(int argc, char* argv[])
+{
+ if (argc < 2)
+ {
+ std::cerr << "minidump_upload path_to_ini_file" << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ if (!readConfig(argv))
+ return EXIT_FAILURE;
+
+ return EXIT_SUCCESS;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */