summaryrefslogtreecommitdiffstats
path: root/lib/Utils
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-11-12 16:58:07 +0100
committerKarel Klic <kklic@redhat.com>2009-11-12 16:58:07 +0100
commit32cee84a34c005fe0d2863f439007ec633687fa8 (patch)
tree149ca7014e4295de3788f28ae88e9d9d7003da46 /lib/Utils
parent5a8a8a6c99c9067e0dfcce839c32826a2badff0b (diff)
parent3938e6e075867ae3a349ba307ee672aa458d2662 (diff)
downloadabrt-32cee84a34c005fe0d2863f439007ec633687fa8.tar.gz
abrt-32cee84a34c005fe0d2863f439007ec633687fa8.tar.xz
abrt-32cee84a34c005fe0d2863f439007ec633687fa8.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/DebugDump.cpp28
-rw-r--r--lib/Utils/Makefile.am7
-rw-r--r--lib/Utils/abrt_xmlrpc.cpp76
-rw-r--r--lib/Utils/abrt_xmlrpc.h27
-rw-r--r--lib/Utils/parse_release.cpp38
-rw-r--r--lib/Utils/popen_and_save_output.cpp30
-rw-r--r--lib/Utils/stringops.cpp30
7 files changed, 229 insertions, 7 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index bf793bb..ba11d96 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -289,6 +289,13 @@ static void DeleteFileDir(const char *pDir)
static bool IsTextFile(const char *name)
{
+ /* Some files in our dump directories are known to always be textual */
+ if (strcmp(name, "backtrace") == 0
+ || strcmp(name, "cmdline") == 0
+ ) {
+ return true;
+ }
+
/* This idiotic library thinks that file containing just "0" is not text (!!)
magic_t m = magic_open(MAGIC_MIME_TYPE);
@@ -328,15 +335,22 @@ static bool IsTextFile(const char *name)
int r = full_read(fd, buf, sizeof(buf));
close(fd);
+ /* Every once in a while, even a text file contains a few garbled
+ * or unexpected non-ASCII chars. We should not declare it "binary".
+ */
+ const unsigned RATIO = 50;
+ unsigned total_chars = r + RATIO;
+ unsigned bad_chars = 1; /* 1 prevents division by 0 later */
while (--r >= 0)
{
- if (buf[r] >= 0x7f)
- return false;
- /* Among control chars, only '\t','\n' etc are allowed */
- if (buf[r] < ' ' && !isspace(buf[r]))
- return false;
+ if (buf[r] >= 0x7f
+ /* among control chars, only '\t','\n' etc are allowed */
+ || (buf[r] < ' ' && !isspace(buf[r]))
+ ) {
+ bad_chars++;
+ }
}
- return true;
+ return (total_chars / bad_chars) >= RATIO;
}
void CDebugDump::Delete()
@@ -471,7 +485,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool
{
if (is_regular_file(dent, m_sDebugDumpDir.c_str()))
{
- std::string fullname = m_sDebugDumpDir + '/' + dent->d_name;
+ std::string fullname = concat_path_file(m_sDebugDumpDir.c_str(), dent->d_name);
pFileName = dent->d_name;
if (IsTextFile(fullname.c_str()))
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index 68c925f..f752992 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -5,16 +5,20 @@ lib_LTLIBRARIES = libABRTUtils.la
# xconnect.cpp
libABRTUtils_la_SOURCES = \
+ stringops.cpp \
xfuncs.cpp \
encbase64.cpp \
read_write.cpp \
logging.cpp \
copyfd.cpp \
skip_whitespace.cpp \
+ popen_and_save_output.cpp \
+ parse_release.cpp \
CrashTypesSocket.cpp \
DebugDump.h DebugDump.cpp \
CommLayerInner.h CommLayerInner.cpp \
abrt_dbus.h abrt_dbus.cpp \
+ abrt_xmlrpc.h abrt_xmlrpc.cpp \
Plugin.h Plugin.cpp make_descr.cpp \
Polkit.h Polkit.cpp \
Action.h Database.h Reporter.h Analyzer.h \
@@ -30,6 +34,7 @@ libABRTUtils_la_CPPFLAGS = \
-DVAR_RUN=\"$(VAR_RUN)\" \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
+ $(XMLRPC_CFLAGS) $(XMLRPC_CLIENT_CFLAGS) \
$(POLKIT_CFLAGS) \
-D_GNU_SOURCE
libABRTUtils_la_LDFLAGS = \
@@ -37,8 +42,10 @@ libABRTUtils_la_LDFLAGS = \
$(DL_LIBS) \
$(DBUS_LIBS)
libABRTUtils_la_LIBADD = \
+ $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) \
$(POLKIT_LIBS)
+
install-data-local:
$(mkdir_p) '$(DESTDIR)/$(DEBUG_DUMPS_DIR)'
chmod 1777 '$(DESTDIR)/$(DEBUG_DUMPS_DIR)'
diff --git a/lib/Utils/abrt_xmlrpc.cpp b/lib/Utils/abrt_xmlrpc.cpp
new file mode 100644
index 0000000..11c431b
--- /dev/null
+++ b/lib/Utils/abrt_xmlrpc.cpp
@@ -0,0 +1,76 @@
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include "abrtlib.h"
+#include "abrt_xmlrpc.h"
+#include "ABRTException.h"
+
+void throw_if_xml_fault_occurred(xmlrpc_env *env)
+{
+ if (env->fault_occurred)
+ {
+ std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", env->fault_string, env->fault_code);
+ xmlrpc_env_clean(env); // this is needed ONLY if fault_occurred
+ xmlrpc_env_init(env); // just in case user catches ex and _continues_ to use env
+ error_msg("%s", errmsg.c_str()); // show error in daemon log
+ throw CABRTException(EXCEP_PLUGIN, errmsg);
+ }
+}
+
+void abrt_xmlrpc_conn::new_xmlrpc_client(const char* url, bool no_ssl_verify)
+{
+ m_pClient = NULL;
+ m_pServer_info = NULL;
+
+ xmlrpc_env env;
+ xmlrpc_env_init(&env);
+
+ /* This should be done at program startup, once.
+ * We do it in abrtd's main */
+ /* xmlrpc_client_setup_global_const(&env); */
+
+ struct xmlrpc_curl_xportparms curlParms;
+ memset(&curlParms, 0, sizeof(curlParms));
+ /* curlParms.network_interface = NULL; - done by memset */
+ curlParms.no_ssl_verifypeer = no_ssl_verify;
+ curlParms.no_ssl_verifyhost = no_ssl_verify;
+#ifdef VERSION
+ curlParms.user_agent = PACKAGE_NAME"/"VERSION;
+#else
+ curlParms.user_agent = "abrt";
+#endif
+
+ struct xmlrpc_clientparms clientParms;
+ memset(&clientParms, 0, sizeof(clientParms));
+ clientParms.transport = "curl";
+ clientParms.transportparmsP = &curlParms;
+ clientParms.transportparm_size = XMLRPC_CXPSIZE(user_agent);
+
+ xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS,
+ PACKAGE_NAME, VERSION,
+ &clientParms, XMLRPC_CPSIZE(transportparm_size),
+ &m_pClient);
+ throw_if_xml_fault_occurred(&env);
+
+ m_pServer_info = xmlrpc_server_info_new(&env, url);
+ if (env.fault_occurred)
+ {
+ xmlrpc_client_destroy(m_pClient);
+ m_pClient = NULL;
+ }
+ throw_if_xml_fault_occurred(&env);
+}
+
+void abrt_xmlrpc_conn::destroy_xmlrpc_client()
+{
+ if (m_pServer_info)
+ {
+ xmlrpc_server_info_free(m_pServer_info);
+ m_pServer_info = NULL;
+ }
+ if (m_pClient)
+ {
+ xmlrpc_client_destroy(m_pClient);
+ m_pClient = NULL;
+ }
+}
diff --git a/lib/Utils/abrt_xmlrpc.h b/lib/Utils/abrt_xmlrpc.h
new file mode 100644
index 0000000..e67ab19
--- /dev/null
+++ b/lib/Utils/abrt_xmlrpc.h
@@ -0,0 +1,27 @@
+#ifndef ABRT_XMLRPC_H_
+#define ABRT_XMLRPC_H_ 1
+
+#include <xmlrpc-c/base.h>
+#include <xmlrpc-c/client.h>
+
+/*
+ * Simple class holding XMLRPC connection data.
+ * Used mainly to ensure we always destroy xmlrpc client and server_info
+ * on return or throw.
+ */
+
+struct abrt_xmlrpc_conn {
+ xmlrpc_client* m_pClient;
+ xmlrpc_server_info* m_pServer_info;
+
+ abrt_xmlrpc_conn(const char* url, bool no_ssl_verify) { new_xmlrpc_client(url, no_ssl_verify); }
+ ~abrt_xmlrpc_conn() { destroy_xmlrpc_client(); }
+
+ void new_xmlrpc_client(const char* url, bool no_ssl_verify);
+ void destroy_xmlrpc_client();
+};
+
+/* Utility function */
+void throw_if_xml_fault_occurred(xmlrpc_env *env);
+
+#endif
diff --git a/lib/Utils/parse_release.cpp b/lib/Utils/parse_release.cpp
new file mode 100644
index 0000000..33d3edb
--- /dev/null
+++ b/lib/Utils/parse_release.cpp
@@ -0,0 +1,38 @@
+#include "abrtlib.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+using namespace std;
+
+void parse_release(const char *pRelease, string& pProduct, string& pVersion)
+{
+ if (strstr(pRelease, "Rawhide"))
+ {
+ pProduct = "Fedora";
+ pVersion = "rawhide";
+ return;
+ }
+ if (strstr(pRelease, "Fedora"))
+ {
+ pProduct = "Fedora";
+ }
+ else if (strstr(pRelease, "Red Hat Enterprise Linux"))
+ {
+ pProduct = "Red Hat Enterprise Linux ";
+ }
+
+ const char *release = strstr(pRelease, "release");
+ const char *space = release ? strchr(release, ' ') : NULL;
+
+ if (space++) while (*space != '\0' && *space != ' ')
+ {
+ /* Eat string like "5.2" */
+ pVersion += *space;
+ if (pProduct == "Red Hat Enterprise Linux ")
+ {
+ pProduct += *space;
+ }
+ space++;
+ }
+}
diff --git a/lib/Utils/popen_and_save_output.cpp b/lib/Utils/popen_and_save_output.cpp
new file mode 100644
index 0000000..4bcbcac
--- /dev/null
+++ b/lib/Utils/popen_and_save_output.cpp
@@ -0,0 +1,30 @@
+/*
+ * Utility routines.
+ *
+ * Licensed under GPLv2 or later, see file COPYING in this tarball for details.
+ */
+#include "abrtlib.h"
+
+using namespace std;
+
+string popen_and_save_output(const char *cmd)
+{
+ string result;
+
+ FILE *fp = popen(cmd, "r");
+ if (fp == NULL) /* fork or pipe failed; or out-of-mem */
+ {
+ return result;
+ }
+
+ size_t sz;
+ char buf[BUFSIZ + 1];
+ while ((sz = fread(buf, 1, sizeof(buf)-1, fp)) > 0)
+ {
+ buf[sz] = '\0';
+ result += buf;
+ }
+ pclose(fp);
+
+ return result;
+}
diff --git a/lib/Utils/stringops.cpp b/lib/Utils/stringops.cpp
new file mode 100644
index 0000000..1b3793f
--- /dev/null
+++ b/lib/Utils/stringops.cpp
@@ -0,0 +1,30 @@
+#include "abrtlib.h"
+
+void parse_args(const char *psArgs, vector_string_t& pArgs, int quote)
+{
+ unsigned ii;
+ bool is_quote = false;
+ std::string item;
+
+ for (ii = 0; psArgs[ii]; ii++)
+ {
+ if (quote != -1 && psArgs[ii] == quote)
+ {
+ is_quote = !is_quote;
+ }
+ else if (psArgs[ii] == ',' && !is_quote)
+ {
+ pArgs.push_back(item);
+ item.clear();
+ }
+ else
+ {
+ item += psArgs[ii];
+ }
+ }
+
+ if (item.size() != 0)
+ {
+ pArgs.push_back(item);
+ }
+}