[Libreoffice-commits] core.git: 3 commits - desktop/Executable_minidump_upload.mk desktop/Module_desktop.mk desktop/source desktop/StaticLibrary_minidump.mk include/desktop svx/Library_svx.mk svx/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sat Jun 4 08:42:17 UTC 2016


 desktop/Executable_minidump_upload.mk       |    4 
 desktop/Module_desktop.mk                   |    4 
 desktop/StaticLibrary_minidump.mk           |   19 ++
 desktop/source/minidump/minidump.cxx        |  206 ++++++++++++++++++++++++++++
 desktop/source/minidump/minidump_upload.cxx |  205 ---------------------------
 include/desktop/minidump.hxx                |   19 ++
 svx/Library_svx.mk                          |   10 +
 svx/source/dialog/crashreportdlg.cxx        |    9 -
 8 files changed, 269 insertions(+), 207 deletions(-)

New commits:
commit d2796282721dd2ed4d2c67e4e8982fb32263b55d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jun 3 12:38:14 2016 +0200

    don't just silently ignore the return value
    
    Change-Id: Ia65c29b61e78de4b908b11cd803d93da4b7e3a2d
    Reviewed-on: https://gerrit.libreoffice.org/25864
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/desktop/source/minidump/minidump.cxx b/desktop/source/minidump/minidump.cxx
index 64303d4..c0d68c2 100644
--- a/desktop/source/minidump/minidump.cxx
+++ b/desktop/source/minidump/minidump.cxx
@@ -200,9 +200,7 @@ bool readConfig(const std::string& iniPath)
         return false;
     }
 
-    uploadContent(parameters);
-
-    return true;
+    return uploadContent(parameters);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 4e074fb8183ac8649c9cb202da4ce93526c1b6d8
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jun 3 12:37:18 2016 +0200

    integrate the minidump upload into the normal LibreOffice
    
    Change-Id: Id1808ceebf6c54698f7d1656a0ce96bcaece89ac
    Reviewed-on: https://gerrit.libreoffice.org/25863
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/desktop/source/minidump/minidump.cxx b/desktop/source/minidump/minidump.cxx
index 371d17c..64303d4 100644
--- a/desktop/source/minidump/minidump.cxx
+++ b/desktop/source/minidump/minidump.cxx
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include "minidump.hxx"
+#include <desktop/minidump.hxx>
 
 #include <map>
 #include <memory>
diff --git a/desktop/source/minidump/minidump_upload.cxx b/desktop/source/minidump/minidump_upload.cxx
index 7f8d617..6a581db 100644
--- a/desktop/source/minidump/minidump_upload.cxx
+++ b/desktop/source/minidump/minidump_upload.cxx
@@ -7,9 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include "minidump.hxx"
+#include <desktop/minidump.hxx>
 
-#include<iostream>
+#include <iostream>
 
 int main(int argc, char** argv)
 {
diff --git a/desktop/source/minidump/minidump.hxx b/include/desktop/minidump.hxx
similarity index 100%
rename from desktop/source/minidump/minidump.hxx
rename to include/desktop/minidump.hxx
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index f664d40..c026002 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -40,6 +40,14 @@ $(eval $(call gb_Library_add_defs,svx,\
 
 $(eval $(call gb_Library_set_precompiled_header,svx,$(SRCDIR)/svx/inc/pch/precompiled_svx))
 
+ifeq ($(ENABLE_BREAKPAD),TRUE)
+
+$(eval $(call gb_Library_use_static_libraries,svx, \
+	minidump \
+))
+
+endif
+
 $(eval $(call gb_Library_use_libraries,svx,\
     basegfx \
     sb \
@@ -74,6 +82,8 @@ $(eval $(call gb_Library_use_libraries,svx,\
 
 $(eval $(call gb_Library_use_externals,svx,\
 	boost_headers \
+    $(call gb_Helper_optional,BREAKPAD, \
+		curl) \
 	icuuc \
 	icu_headers \
 ))
diff --git a/svx/source/dialog/crashreportdlg.cxx b/svx/source/dialog/crashreportdlg.cxx
index 5d74792..511199b 100644
--- a/svx/source/dialog/crashreportdlg.cxx
+++ b/svx/source/dialog/crashreportdlg.cxx
@@ -9,10 +9,12 @@
 
 #include "crashreportdlg.hxx"
 
+
 #include <config_folders.h>
 
 #include <rtl/bootstrap.hxx>
 #include <desktop/crashreport.hxx>
+#include <desktop/minidump.hxx>
 #include <osl/file.hxx>
 
 CrashReportDialog::CrashReportDialog(vcl::Window* pParent):
@@ -56,13 +58,8 @@ IMPL_LINK_TYPED(CrashReportDialog, BtnHdl, Button*, pBtn, void)
     if (pBtn == mpBtnSend.get())
     {
         std::string ini_path = CrashReporter::getIniFileName();
-        OUString aCommand;
-        osl::FileBase::getSystemPathFromFileURL(getLibDir() + "/minidump_upload" SAL_EXEEXTENSION, aCommand);
 
-        aCommand = aCommand;
-        OString aOStringCommand = rtl::OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8) + " " + ini_path.c_str();
-        int retVal = std::system(aOStringCommand.getStr());
-        SAL_WARN_IF(retVal != 0, "svx.dialog", "Failed to upload minidump. Error Code: " << retVal);
+        readConfig(ini_path);
         // TODO: moggi: return the id for the user to look it up
         Close();
     }
commit 2d1fc99275315bd6f45c1b73540f2b55e94bef9f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Jun 2 19:15:47 2016 +0200

    extract the minidump uploader code into a static lib
    
    The plan for the near future is to still ship the executable but replace
    the interal use if possible with using the static library.
    
    At some point when it is not needed for debugging anymore and everything
    works correctly we should only build the uploader executable in dev
    configurations. The huge disadvantage of the interal solution is that it
    is nearly impossible for a user to upload a crash report if LibO starts
    working correctly. Also LibO overwrites the file with the information
    after the upload whereas the executable does not.
    
    Change-Id: Ib9854946be3a34e580964c18e1a9c0cce16221d1
    Reviewed-on: https://gerrit.libreoffice.org/25862
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/desktop/Executable_minidump_upload.mk b/desktop/Executable_minidump_upload.mk
index 7fe9546..2c02023 100644
--- a/desktop/Executable_minidump_upload.mk
+++ b/desktop/Executable_minidump_upload.mk
@@ -13,6 +13,10 @@ $(eval $(call gb_Executable_use_libraries,minidump_upload,\
     sal \
 ))
 
+$(eval $(call gb_Executable_use_static_libraries,minidump_upload,\
+	minidump \
+))
+
 $(eval $(call gb_Executable_use_external,minidump_upload,curl))
 
 $(eval $(call gb_Executable_add_exception_objects,minidump_upload,\
diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk
index 430d48f..22d3647 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -17,7 +17,9 @@ $(eval $(call gb_Module_add_targets,desktop,\
     Library_deploymentmisc \
     Library_offacc \
     Library_sofficeapp \
-    $(if $(ENABLE_BREAKPAD),Library_crashreport) \
+    $(if $(ENABLE_BREAKPAD), \
+        Library_crashreport \
+        StaticLibrary_minidump) \
     $(if $(ENABLE_HEADLESS),,Library_spl) \
     Package_branding \
     $(if $(CUSTOM_BRAND_DIR),Package_branding_custom) \
diff --git a/desktop/StaticLibrary_minidump.mk b/desktop/StaticLibrary_minidump.mk
new file mode 100644
index 0000000..70cab1a
--- /dev/null
+++ b/desktop/StaticLibrary_minidump.mk
@@ -0,0 +1,19 @@
+# -*- 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_StaticLibrary_StaticLibrary,minidump))
+
+$(eval $(call gb_StaticLibrary_use_external,minidump,curl))
+
+$(eval $(call gb_StaticLibrary_add_exception_objects,minidump,\
+    desktop/source/minidump/minidump \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/desktop/source/minidump/minidump.cxx b/desktop/source/minidump/minidump.cxx
new file mode 100644
index 0000000..371d17c
--- /dev/null
+++ b/desktop/source/minidump/minidump.cxx
@@ -0,0 +1,208 @@
+/* -*- 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 "minidump.hxx"
+
+#include <map>
+#include <memory>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#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 = static_cast<std::string *>(userp);
+  size_t real_size = size * nmemb;
+  response->append(static_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);
+    }
+}
+
+std::string generate_json(const std::map<std::string, std::string>& parameters)
+{
+    std::ostringstream stream;
+    stream << "{\n";
+    bool first = true;
+    for (auto itr = parameters.begin(), itrEnd = parameters.end(); itr != itrEnd; ++itr)
+    {
+        if (!first)
+        {
+            stream << ",\n";
+        }
+        first = false;
+        stream << "\"" << itr->first << "\": \"" << itr->second << "\"";
+    }
+    stream << "\n}";
+
+    return stream.str();
+}
+
+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, url, version;
+
+    getProperty("Proxy", proxy, parameters);
+    getProperty("ProxyUserPW", proxy_user_pwd, parameters);
+    getProperty("CAFile", ca_certificate_file, parameters);
+
+    getProperty("DumpFile", file, parameters);
+    getProperty("URL", url, parameters);
+    getProperty("Version", version, parameters);
+    if (url.empty())
+        return false;
+
+    if (file.empty())
+        return false;
+
+    if (version.empty())
+        return false;
+
+    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;
+    std::string additional_data = generate_json(parameters);
+    curl_formadd(&formpost, &lastptr,
+            CURLFORM_COPYNAME, "AdditionalData",
+            CURLFORM_COPYCONTENTS, additional_data.c_str(),
+            CURLFORM_END);
+
+    curl_formadd(&formpost, &lastptr,
+            CURLFORM_COPYNAME, "Version",
+            CURLFORM_COPYCONTENTS, version.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 = nullptr;
+    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,
+            static_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
+
+    const char* error_description = curl_easy_strerror(cc);
+
+    if (formpost != nullptr)
+    {
+        curl_formfree(formpost);
+    }
+    if (headerlist != nullptr)
+    {
+        curl_slist_free_all(headerlist);
+    }
+
+    std::cerr << response_body << " " << error_description << std::endl;
+
+
+    if( CURLE_OK != cc )
+        return false;
+
+    return true;
+}
+
+bool readConfig(const std::string& iniPath)
+{
+    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;
+    }
+
+    uploadContent(parameters);
+
+    return true;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/minidump/minidump.hxx b/desktop/source/minidump/minidump.hxx
new file mode 100644
index 0000000..21d52e8
--- /dev/null
+++ b/desktop/source/minidump/minidump.hxx
@@ -0,0 +1,19 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_DESKTOP_MINIDUMP_MINIDUMP_HXX
+#define INCLUDED_DESKTOP_MINIDUMP_MINIDUMP_HXX
+
+#include <string>
+
+bool readConfig(const std::string& iniPath);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/minidump/minidump_upload.cxx b/desktop/source/minidump/minidump_upload.cxx
index 30eaaaa..7f8d617 100644
--- a/desktop/source/minidump/minidump_upload.cxx
+++ b/desktop/source/minidump/minidump_upload.cxx
@@ -7,207 +7,11 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <string>
-#include <map>
-#include <memory>
-#include <iostream>
-#include <fstream>
-#include <sstream>
+#include "minidump.hxx"
 
-#include <curl/curl.h>
+#include<iostream>
 
-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 = static_cast<std::string *>(userp);
-  size_t real_size = size * nmemb;
-  response->append(static_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);
-    }
-}
-
-std::string generate_json(const std::map<std::string, std::string>& parameters)
-{
-    std::ostringstream stream;
-    stream << "{\n";
-    bool first = true;
-    for (auto itr = parameters.begin(), itrEnd = parameters.end(); itr != itrEnd; ++itr)
-    {
-        if (!first)
-        {
-            stream << ",\n";
-        }
-        first = false;
-        stream << "\"" << itr->first << "\": \"" << itr->second << "\"";
-    }
-    stream << "\n}";
-
-    return stream.str();
-}
-
-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, url, version;
-
-    getProperty("Proxy", proxy, parameters);
-    getProperty("ProxyUserPW", proxy_user_pwd, parameters);
-    getProperty("CAFile", ca_certificate_file, parameters);
-
-    getProperty("DumpFile", file, parameters);
-    getProperty("URL", url, parameters);
-    getProperty("Version", version, parameters);
-    if (url.empty())
-        return false;
-
-    if (file.empty())
-        return false;
-
-    if (version.empty())
-        return false;
-
-    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;
-    std::string additional_data = generate_json(parameters);
-    curl_formadd(&formpost, &lastptr,
-            CURLFORM_COPYNAME, "AdditionalData",
-            CURLFORM_COPYCONTENTS, additional_data.c_str(),
-            CURLFORM_END);
-
-    curl_formadd(&formpost, &lastptr,
-            CURLFORM_COPYNAME, "Version",
-            CURLFORM_COPYCONTENTS, version.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 = nullptr;
-    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,
-            static_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
-
-    const char* error_description = curl_easy_strerror(cc);
-
-    if (formpost != nullptr)
-    {
-        curl_formfree(formpost);
-    }
-    if (headerlist != nullptr)
-    {
-        curl_slist_free_all(headerlist);
-    }
-
-    std::cerr << response_body << " " << error_description << 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;
-    }
-
-    uploadContent(parameters);
-
-    return true;
-}
-
-int main(int argc, char* argv[])
+int main(int argc, char** argv)
 {
     if (argc < 2)
     {
@@ -215,7 +19,8 @@ int main(int argc, char* argv[])
         return EXIT_FAILURE;
     }
 
-    if (!readConfig(argv))
+    std::string iniPath(argv[1]);
+    if (!readConfig(iniPath))
         return EXIT_FAILURE;
 
     return EXIT_SUCCESS;


More information about the Libreoffice-commits mailing list