summaryrefslogtreecommitdiffstats
path: root/lib/Utils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-15 12:43:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-15 12:43:01 +0200
commit0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a (patch)
tree13f92f2fc02d346d8474ef03fd0596e3e0447eda /lib/Utils
parent5f4a56f97f36e9cb844fcf3e4399cea67000a6bb (diff)
unify CommLayer, MiddleWare and Utils into Utils
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/Action.h47
-rw-r--r--lib/Utils/Analyzer.h56
-rw-r--r--lib/Utils/CommLayerInner.cpp69
-rw-r--r--lib/Utils/CommLayerInner.h23
-rw-r--r--lib/Utils/DBusClientProxy.cpp239
-rw-r--r--lib/Utils/DBusClientProxy.h108
-rw-r--r--lib/Utils/DBusCommon.h29
-rw-r--r--lib/Utils/Database.h126
-rw-r--r--lib/Utils/Makefile.am47
-rw-r--r--lib/Utils/Observer.h16
-rw-r--r--lib/Utils/Plugin.cpp27
-rw-r--r--lib/Utils/Plugin.h118
-rw-r--r--lib/Utils/Reporter.h47
-rw-r--r--lib/Utils/test.cpp108
14 files changed, 1048 insertions, 12 deletions
diff --git a/lib/Utils/Action.h b/lib/Utils/Action.h
new file mode 100644
index 0000000..1286feb
--- /dev/null
+++ b/lib/Utils/Action.h
@@ -0,0 +1,47 @@
+/*
+ Action.h - header file for action plugin
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef ACTION_H_
+#define ACTION_H_
+
+#include <string>
+#include "Plugin.h"
+
+/**
+ * An abstract class. The class defines an action plugin interface.
+ */
+class CAction : public CPlugin
+{
+ public:
+ /**
+ * A Method which performs particular action. As the first parameter it
+ * takes an action directory. It could be either a directory of actual
+ * crash or it could be a directory contains all crashes. It depends on
+ * who call the plugin. The plugin can takes arguments, but the plugin
+ * has to parse them by itself.
+ * @param pActionDir An actual directory.
+ * @param pArgs Plugin's arguments.
+ */
+ virtual void Run(const std::string& pActionDir,
+ const std::string& pArgs) = 0;
+};
+
+#endif /*ACTION_H_*/
diff --git a/lib/Utils/Analyzer.h b/lib/Utils/Analyzer.h
new file mode 100644
index 0000000..4fe586b
--- /dev/null
+++ b/lib/Utils/Analyzer.h
@@ -0,0 +1,56 @@
+/*
+ Analyzer.h - header file for analyzer plugin
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef ANALYZER_H_
+#define ANALYZER_H_
+
+#include <string>
+#include "Plugin.h"
+
+/**
+ * An abstract class. The class defines an analyzer plugin interface.
+ */
+class CAnalyzer : public CPlugin
+{
+ public:
+ /**
+ * A method, which gets a local UUID of particular crash. The local
+ * UUID is usualy computed from data which are stored in debugdump dir.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ * @return A local UUID.
+ */
+ virtual std::string GetLocalUUID(const std::string& pDebugDumpPath) = 0;
+ /**
+ * A method, which gets a global UUID of particular crash.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ * @return A global UUID.
+ */
+ virtual std::string GetGlobalUUID(const std::string& pDebugDumpPath) = 0;
+ /**
+ * A method, which takes care of getting all additional data needed
+ * for computing UUIDs and creating a report. This report could be send
+ * somewhere afterwards.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ */
+ virtual void CreateReport(const std::string& pDebugDumpPath) = 0;
+};
+
+#endif /*ANALYZER_H_*/
diff --git a/lib/Utils/CommLayerInner.cpp b/lib/Utils/CommLayerInner.cpp
new file mode 100644
index 0000000..b5b8db7
--- /dev/null
+++ b/lib/Utils/CommLayerInner.cpp
@@ -0,0 +1,69 @@
+#include <pthread.h>
+#include <map>
+#include "abrtlib.h"
+#include "CommLayerInner.h"
+
+static CObserver *s_pObs;
+
+typedef std::map<uint64_t, std::string> map_uint_str_t;
+static map_uint_str_t s_mapClientID;
+static pthread_mutex_t s_map_mutex;
+static bool s_map_mutex_inited;
+
+void init_daemon_logging(CObserver *pObs)
+{
+ s_pObs = pObs;
+ if (!s_map_mutex_inited)
+ {
+ pthread_mutex_init(&s_map_mutex, NULL);
+ s_map_mutex_inited = true;
+ }
+}
+
+void set_client_name(const char* name)
+{
+ uint64_t key = uint64_t(pthread_self());
+
+ pthread_mutex_lock(&s_map_mutex);
+ if (!name)
+ s_mapClientID.erase(key);
+ else
+ s_mapClientID[key] = name;
+ pthread_mutex_unlock(&s_map_mutex);
+}
+
+void warn_client(const std::string& pMessage)
+{
+ if (!s_pObs)
+ return;
+
+ uint64_t key = uint64_t(pthread_self());
+
+ pthread_mutex_lock(&s_map_mutex);
+ map_uint_str_t::const_iterator ki = s_mapClientID.find(key);
+ const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL);
+ pthread_mutex_unlock(&s_map_mutex);
+
+ if (peer)
+ s_pObs->Warning(pMessage, peer, key);
+ else /* Bug: someone tries to warn_client() without set_client_name()!? */
+ log("Hmm, stray %s: '%s'", __func__, pMessage.c_str());
+}
+
+void update_client(const std::string& pMessage)
+{
+ if (!s_pObs)
+ return;
+
+ uint64_t key = uint64_t(pthread_self());
+
+ pthread_mutex_lock(&s_map_mutex);
+ map_uint_str_t::const_iterator ki = s_mapClientID.find(key);
+ const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL);
+ pthread_mutex_unlock(&s_map_mutex);
+
+ if (peer)
+ s_pObs->Status(pMessage, peer, key);
+ else
+ log("Hmm, stray %s: '%s'", __func__, pMessage.c_str());
+}
diff --git a/lib/Utils/CommLayerInner.h b/lib/Utils/CommLayerInner.h
new file mode 100644
index 0000000..d161cfc
--- /dev/null
+++ b/lib/Utils/CommLayerInner.h
@@ -0,0 +1,23 @@
+#ifndef COMMLAYERINNER_H_
+#define COMMLAYERINNER_H_
+
+#include "Observer.h"
+
+void init_daemon_logging(CObserver *pObs);
+
+/*
+ * Set client's name (dbus ID). NULL unsets it.
+ */
+void set_client_name(const char* name);
+/* Ask a client to warn the user about a non-fatal, but unexpected condition.
+ * In GUI, it will usually be presented as a popup message.
+ */
+void warn_client(const std::string& pMessage);
+/* Logs a message to a client.
+ * In UI, it will usually appear as a new status line message in GUI,
+ * or as a new message line in CLI.
+ */
+void update_client(const std::string& pMessage);
+
+#endif /* COMMLAYERINNER_H_ */
+
diff --git a/lib/Utils/DBusClientProxy.cpp b/lib/Utils/DBusClientProxy.cpp
new file mode 100644
index 0000000..ccb48d5
--- /dev/null
+++ b/lib/Utils/DBusClientProxy.cpp
@@ -0,0 +1,239 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "DBusClientProxy.h"
+#include <iostream>
+
+namespace org {
+namespace freedesktop {
+namespace DBus {
+
+/* class DaemonWatcher_proxy */
+
+/* public: */
+
+DaemonWatcher_proxy::DaemonWatcher_proxy()
+: ::DBus::InterfaceProxy("org.freedesktop.DBus")
+{
+ m_pStateChangeHandler_cb_data = NULL;
+ m_pStateChangeHandler = NULL;
+ connect_signal(DaemonWatcher_proxy, NameOwnerChanged, _DaemonStateChanged);
+}
+
+void DaemonWatcher_proxy::ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data)
+{
+ m_pStateChangeHandler_cb_data = cb_data;
+ m_pStateChangeHandler = pStateChangeHandler;
+}
+
+/* private: */
+
+/* unmarshalers (to unpack the DBus message before calling the actual signal handler)
+ */
+void DaemonWatcher_proxy::_DaemonStateChanged(const ::DBus::SignalMessage &sig)
+{
+ ::DBus::MessageIter ri = sig.reader();
+ std::string name;
+ std::string old_owner;
+ std::string new_owner;
+ ri >> name;
+ ri >> old_owner;
+ ri >> new_owner;
+ if(name.compare("com.redhat.abrt") == 0)
+ {
+ if(new_owner.length() > 0)
+ {
+ if(m_pStateChangeHandler)
+ {
+ m_pStateChangeHandler(true,m_pStateChangeHandler_cb_data);
+ }
+ else
+ {
+ std::cout << "Daemon appeared!" << std::endl;
+ }
+ }
+ if(new_owner.length() == 0)
+ {
+ if(m_pStateChangeHandler)
+ {
+ m_pStateChangeHandler(false, m_pStateChangeHandler_cb_data);
+ }
+ else
+ {
+ std::cout << "Daemon dissapeared!" << std::endl;
+ }
+ }
+ }
+}
+
+} } } /* closing namespaces */
+
+
+/* class DaemonWatcher */
+
+/* public: */
+
+DaemonWatcher::DaemonWatcher(DBus::Connection &connection, const char *path, const char *name)
+: ::DBus::ObjectProxy(connection, path, name)
+{
+}
+DaemonWatcher::~DaemonWatcher()
+{
+ std::cout << "~DaemonWatcher" << std::endl;
+}
+
+
+/* class CDBusClient_proxy */
+
+/* public: */
+
+CDBusClient_proxy::CDBusClient_proxy()
+: DBus::InterfaceProxy(CC_DBUS_IFACE)
+{
+ connect_signal(CDBusClient_proxy, Crash, _Crash_stub);
+ connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub);
+ m_sConnName = "";
+}
+
+CDBusClient_proxy::CDBusClient_proxy(::DBus::Connection &pConnection)
+: DBus::InterfaceProxy(CC_DBUS_IFACE)
+{
+ gloop = g_main_loop_new(NULL, false);
+ //# define connect_signal(interface, signal, callback)
+ connect_signal(CDBusClient_proxy, Crash, _Crash_stub);
+ connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub);
+ m_sConnName = pConnection.unique_name();
+}
+
+/* methods exported by this interface,
+ * this functions will invoke the corresponding methods on the remote objects
+ */
+ /*
+
+ <
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ ...
+ >
+ */
+vector_crash_infos_t CDBusClient_proxy::GetCrashInfos()
+{
+ DBus::CallMessage call;
+ DBus::MessageIter wi = call.writer();
+
+ call.member("GetCrashInfos");
+ DBus::Message ret = invoke_method(call);
+ DBus::MessageIter ri = ret.reader();
+
+ vector_crash_infos_t argout;
+ ri >> argout;
+ return argout;
+}
+
+bool CDBusClient_proxy::DeleteDebugDump(const std::string& pUUID)
+{
+ DBus::CallMessage call;
+
+ DBus::MessageIter wi = call.writer();
+
+ wi << pUUID;
+ call.member("DeleteDebugDump");
+ DBus::Message ret = invoke_method(call);
+ DBus::MessageIter ri = ret.reader();
+
+ bool argout;
+ ri >> argout;
+ return argout;
+}
+
+map_crash_report_t CDBusClient_proxy::CreateReport(const std::string& pUUID)
+{
+ m_bJobDone = false;
+ DBus::CallMessage call;
+
+ DBus::MessageIter wi = call.writer();
+
+ wi << pUUID;
+ call.member("CreateReport");
+ DBus::Message ret = invoke_method(call);
+ DBus::MessageIter ri = ret.reader();
+ ri >> m_iPendingJobID;
+ //FIXME: what if the report is created before we start the loop? (we miss the signal and get stuck in the loop)
+ g_main_loop_run(gloop);
+ return GetJobResult(m_iPendingJobID);
+};
+
+void CDBusClient_proxy::Report(const map_crash_report_t& pReport)
+{
+ DBus::CallMessage call;
+
+ DBus::MessageIter wi = call.writer();
+
+ wi << pReport;
+ call.member("Report");
+ DBus::Message ret = invoke_method(call);
+ DBus::MessageIter ri = ret.reader();
+}
+
+map_crash_report_t CDBusClient_proxy::GetJobResult(uint64_t pJobID)
+{
+ DBus::CallMessage call;
+
+ DBus::MessageIter wi = call.writer();
+
+ wi << pJobID;
+ call.member("GetJobResult");
+ DBus::Message ret = invoke_method(call);
+ DBus::MessageIter ri = ret.reader();
+ map_crash_report_t argout;
+ ri >> argout;
+ return argout;
+}
+
+/* signal handlers for this interface
+ */
+void CDBusClient_proxy::Crash(const std::string& progname, const std::string& uid)
+{
+}
+
+/* private: */
+
+/* unmarshalers (to unpack the DBus message before calling the actual signal handler)
+ */
+void CDBusClient_proxy::_Crash_stub(const ::DBus::SignalMessage &sig)
+{
+ DBus::MessageIter ri = sig.reader();
+
+ std::string progname; ri >> progname;
+ std::string uid; ri >> uid;
+ Crash(progname, uid);
+}
+
+void CDBusClient_proxy::_JobDone_stub(const ::DBus::SignalMessage &sig)
+{
+ DBus::MessageIter ri = sig.reader();
+ std::string dest;
+ ri >> dest;
+ if(m_sConnName == dest)
+ {
+ ri >> m_iPendingJobID;
+ g_main_loop_quit(gloop);
+ }
+}
diff --git a/lib/Utils/DBusClientProxy.h b/lib/Utils/DBusClientProxy.h
new file mode 100644
index 0000000..e43805b
--- /dev/null
+++ b/lib/Utils/DBusClientProxy.h
@@ -0,0 +1,108 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef DBUSCLIENTPROXY_H_
+#define DBUSCLIENTPROXY_H_
+
+#include <dbus-c++/dbus.h>
+#include <dbus-c++/glib-integration.h>
+#include "DBusCommon.h"
+
+#define ABRT_NOT_RUNNING 0
+#define ABRT_RUNNING 1
+
+namespace org {
+namespace freedesktop {
+namespace DBus {
+
+class DaemonWatcher_proxy
+: public ::DBus::InterfaceProxy
+{
+private:
+ void *m_pStateChangeHandler_cb_data;
+ void (*m_pStateChangeHandler)(bool running, void* data);
+
+public:
+ DaemonWatcher_proxy();
+ void ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data);
+
+private:
+ /* unmarshalers (to unpack the DBus message before calling the actual signal handler)
+ */
+ void _DaemonStateChanged(const ::DBus::SignalMessage &sig);
+};
+
+} } }
+
+
+class DaemonWatcher
+: public org::freedesktop::DBus::DaemonWatcher_proxy,
+ public DBus::IntrospectableProxy,
+ public DBus::ObjectProxy
+{
+public:
+
+ DaemonWatcher(DBus::Connection &connection, const char *path, const char *name);
+ ~DaemonWatcher();
+};
+
+
+class CDBusClient_proxy
+: public DBus::InterfaceProxy
+{
+private:
+ bool m_bJobDone;
+ uint64_t m_iPendingJobID;
+ GMainLoop *gloop;
+ std::string m_sConnName;
+
+public:
+ CDBusClient_proxy();
+ CDBusClient_proxy(::DBus::Connection &pConnection);
+
+public:
+ /* methods exported by this interface,
+ * this functions will invoke the corresponding methods on the remote objects
+ */
+ /*
+ <
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage>
+ ...
+ >
+ */
+ vector_crash_infos_t GetCrashInfos();
+ bool DeleteDebugDump(const std::string& pUUID);
+ map_crash_report_t CreateReport(const std::string& pUUID);
+ void Report(const map_crash_report_t& pReport);
+ map_crash_report_t GetJobResult(uint64_t pJobID);
+
+public:
+ /* signal handlers for this interface
+ */
+ virtual void Crash(const std::string& progname, const std::string& uid);
+
+private:
+ /* unmarshalers (to unpack the DBus message before calling the actual signal handler)
+ */
+ void _Crash_stub(const ::DBus::SignalMessage &sig);
+ void _JobDone_stub(const ::DBus::SignalMessage &sig);
+};
+
+#endif
diff --git a/lib/Utils/DBusCommon.h b/lib/Utils/DBusCommon.h
new file mode 100644
index 0000000..b3e3af2
--- /dev/null
+++ b/lib/Utils/DBusCommon.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef DBUSCOMMON_H_
+#define DBUSCOMMON_H_
+
+#include "CrashTypes.h"
+
+#define CC_DBUS_NAME "com.redhat.abrt"
+#define CC_DBUS_PATH "/com/redhat/abrt"
+#define CC_DBUS_IFACE "com.redhat.abrt"
+
+#endif
diff --git a/lib/Utils/Database.h b/lib/Utils/Database.h
new file mode 100644
index 0000000..0fc31ee
--- /dev/null
+++ b/lib/Utils/Database.h
@@ -0,0 +1,126 @@
+/*
+ Database.h - header file for database plugin
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef DATABASE_H_
+#define DATABASE_H_
+
+#include <string>
+#include <vector>
+#include "Plugin.h"
+
+/**
+ * Table
+ * =====
+ * UUID | UID| DebugDumpPath | Count | Reported | Time | Message
+ *
+ * primary key (UUID, UID)
+ */
+
+#define DATABASE_COLUMN_UUID "UUID"
+#define DATABASE_COLUMN_UID "UID"
+#define DATABASE_COLUMN_DEBUG_DUMP_PATH "DebugDumpPath"
+#define DATABASE_COLUMN_COUNT "Count"
+#define DATABASE_COLUMN_REPORTED "Reported"
+#define DATABASE_COLUMN_TIME "Time"
+#define DATABASE_COLUMN_MESSAGE "Message"
+
+/**
+ * A struct contains one database row.
+ */
+typedef struct SDatabaseRow
+{
+ std::string m_sUUID; /**< A local UUID.*/
+ std::string m_sUID; /**< An UID of an user.*/
+ std::string m_sDebugDumpDir; /**< A debugdump directory of a crash.*/
+ std::string m_sCount; /**< Crash rate.*/
+ std::string m_sReported; /**< Is a row reported?*/
+ std::string m_sMessage; /**< if a row is reported, then there can be store message abotu that*/
+ std::string m_sTime; /**< Time of last occurred crash with same local UUID*/
+} database_row_t;
+
+/**
+ * A vector contains one or more database rows.
+ */
+typedef std::vector<database_row_t> vector_database_rows_t;
+
+/**
+ * An abstract class. The class defines a database plugin interface.
+ */
+class CDatabase : public CPlugin
+{
+ public:
+ /**
+ * A method, which connects to a database.
+ */
+ virtual void Connect() = 0;
+ /**
+ * A method, which disconnects from a database.
+ */
+ virtual void DisConnect() = 0;
+ /**
+ * A method, which inserts one row to a database.
+ * @param pUUID A local UUID of a crash.
+ * @param pUID An UID of an user.
+ * @param pDebugDumpPath A debugdump path.
+ * @param pTime Time when a crash occurs.
+ */
+ virtual void Insert(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pDebugDumpPath,
+ const std::string& pTime) = 0;
+ /**
+ * A method, which deletes one row in a database.
+ * @param pUUID A lodal UUID of a crash.
+ * @param pUID An UID of an user.
+ */
+ virtual void Delete(const std::string& pUUID,
+ const std::string& pUID) = 0;
+ /**
+ * A method, which sets that particular row was reported.
+ * @param pUUID A local UUID of a crash.
+ * @param pUID An UID of an user.
+ * @param pMessga A text explanation of reported problem (where
+ * it is stored etc...
+ */
+ virtual void SetReported(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pMessage) = 0;
+ /**
+ * A method, which gets all rows which belongs to particular user.
+ * If the user is root, then all rows are returned. If there are no
+ * rows, empty vector is returned.
+ * @param pUID An UID of an user.
+ * @return A vector of matched rows.
+ */
+ virtual vector_database_rows_t GetUIDData(const std::string& pUID) = 0;
+ /**
+ * A method, which returns one row accordind to UUID of a crash and
+ * UID of an user. If there are no row, empty row is returned.
+ * @param pUUID A UUID of a crash.
+ * @param pUID An UID of an user.
+ * @return A matched row.
+ */
+ virtual database_row_t GetUUIDData(const std::string& pUUID,
+ const std::string& pUID) = 0;
+};
+
+#endif /* DATABASE_H_ */
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index cb5b337..b662ae9 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -1,17 +1,40 @@
lib_LTLIBRARIES = libABRTUtils.la
-libABRTUtils_la_SOURCES = \
- DebugDump.cpp DebugDump.h \
- CrashTypesSocket.cpp \
- xfuncs.cpp \
- read_write.cpp \
- logging.cpp \
- copyfd.cpp \
- Polkit.cpp \
- Polkit.h
-libABRTUtils_la_LDFLAGS = -version-info 0:1:0
-libABRTUtils_la_LIBADD = -lmagic $(POLKIT_LIBS)
-libABRTUtils_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../../lib/CommLayer $(POLKIT_CFLAGS)
+libABRTUtils_la_SOURCES = \
+ xfuncs.cpp \
+ read_write.cpp \
+ logging.cpp \
+ copyfd.cpp \
+ CrashTypesSocket.cpp \
+ DebugDump.h DebugDump.cpp \
+ DBusClientProxy.h DBusClientProxy.cpp \
+ CommLayerInner.h CommLayerInner.cpp \
+ Plugin.h Plugin.cpp \
+ Polkit.h Polkit.cpp \
+ Action.h Database.h Reporter.h Analyzer.h \
+ Observer.h \
+ DBusCommon.h
+libABRTUtils_la_LDFLAGS = \
+ -version-info 0:1:0 \
+ $(DL_LIBS) \
+ $(RPM_LIBS) \
+ $(DBUSCPP_LIBS)
+libABRTUtils_la_LIBADD = \
+ -lmagic \
+ $(POLKIT_LIBS)
+libABRTUtils_la_CPPFLAGS = \
+ -Wall -Werror \
+ -I$(srcdir)/../../inc \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
+ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
+ -DCONF_DIR=\"$(CONF_DIR)\" \
+ -DVAR_RUN=\"$(VAR_RUN)\" \
+ $(RPM_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ $(DBUSCPP_CFLAGS) \
+ $(POLKIT_CFLAGS) \
+ -D_GNU_SOURCE
install-data-local:
$(mkdir_p) '$(DESTDIR)/$(DEBUG_DUMPS_DIR)'
diff --git a/lib/Utils/Observer.h b/lib/Utils/Observer.h
new file mode 100644
index 0000000..421dc0c
--- /dev/null
+++ b/lib/Utils/Observer.h
@@ -0,0 +1,16 @@
+#ifndef OBSERVER_H_
+#define OBSERVER_H_
+
+#include <string>
+#include <iostream>
+#include <stdint.h>
+#include "DBusCommon.h"
+
+class CObserver {
+ public:
+ virtual ~CObserver() {}
+ virtual void Status(const std::string& pMessage, const char* peer, uint64_t pDest) = 0;
+ virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pDest) = 0;
+};
+
+#endif
diff --git a/lib/Utils/Plugin.cpp b/lib/Utils/Plugin.cpp
new file mode 100644
index 0000000..161ead8
--- /dev/null
+++ b/lib/Utils/Plugin.cpp
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "Plugin.h"
+
+/* class CPlugin's virtuals */
+CPlugin::~CPlugin() {}
+void CPlugin::Init() {}
+void CPlugin::DeInit() {}
+void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) {}
+map_plugin_settings_t CPlugin::GetSettings() {return map_plugin_settings_t();}
diff --git a/lib/Utils/Plugin.h b/lib/Utils/Plugin.h
new file mode 100644
index 0000000..3929023
--- /dev/null
+++ b/lib/Utils/Plugin.h
@@ -0,0 +1,118 @@
+/*
+ Plugin.h - header file for plugin. It contains mandatory macros
+ and common function for plugins
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PLUGIN_H_
+#define PLUGIN_H_
+
+#include "abrt_types.h"
+
+#define PLUGINS_MAGIC_NUMBER 6
+
+#define PLUGINS_CONF_EXTENSION "conf"
+#define PLUGINS_LIB_EXTENSION "so"
+#define PLUGINS_LIB_PREFIX "lib"
+
+#if HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#if ENABLE_NLS
+ #include <libintl.h>
+ #define _(S) gettext(S)
+#else
+ #define _(S) (S)
+#endif
+
+/**
+ * An abstract class. The class defines a common plugin interface. If a plugin
+ * has some settings, then a *Settings(*) method has to be written.
+ */
+class CPlugin
+{
+ public:
+ /**
+ * A destructor.
+ */
+ virtual ~CPlugin();
+ /**
+ * A method, which initializes a plugin. It is not mandatory method.
+ */
+ virtual void Init();
+ /**
+ * A method, which deinitializes a plugin. It is not mandatory method.
+ */
+ virtual void DeInit();
+ /**
+ * A method, which takes a settings and apply them. It is not a mandatory method.
+ * @param pSettings Plugin's settings
+ */
+ virtual void SetSettings(const map_plugin_settings_t& pSettings);
+ /**
+ * A method, which return current settings. It is not mandatory method.
+ * @return Plugin's settings
+ */
+ virtual map_plugin_settings_t GetSettings();
+};
+
+/**
+ * An enum of plugin types.
+ */
+typedef enum {
+ ANALYZER, /**< An analyzer plugin*/
+ ACTION, /**< An action plugin*/
+ REPORTER, /**< A reporter plugin*/
+ DATABASE /**< A database plugin*/
+} plugin_type_t;
+
+/**
+ * A struct contains all needed data about particular plugin.
+ */
+typedef struct SPluginInfo
+{
+ const plugin_type_t m_Type; /**< Plugin type.*/
+ const char *const m_sName; /**< Plugin name.*/
+ const char *const m_sVersion; /**< Plugin version.*/
+ const char *const m_sDescription; /**< Plugin description.*/
+ const char *const m_sEmail; /**< Plugin author's email.*/
+ const char *const m_sWWW; /**< Plugin's home page.*/
+ const char *const m_sGTKBuilder; /**< Plugin's gui description.*/
+ const int m_nMagicNumber; /**< Plugin magical number.*/
+} plugin_info_t;
+
+#define PLUGIN_INFO(type, plugin_class, name, version, description, email, www, gtk_builder)\
+ extern "C" CPlugin* plugin_new()\
+ {\
+ return new plugin_class();\
+ }\
+ extern "C" const plugin_info_t plugin_info =\
+ {\
+ type,\
+ name,\
+ version,\
+ description,\
+ email,\
+ www,\
+ gtk_builder,\
+ PLUGINS_MAGIC_NUMBER,\
+ };
+
+#endif /* PLUGIN_H_ */
diff --git a/lib/Utils/Reporter.h b/lib/Utils/Reporter.h
new file mode 100644
index 0000000..c74a10c
--- /dev/null
+++ b/lib/Utils/Reporter.h
@@ -0,0 +1,47 @@
+/*
+ Reporter.h - header file for reporter plugin
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef REPORTER_H_
+#define REPORTER_H_
+
+#include <string>
+#include "Plugin.h"
+#include "CrashTypes.h"
+
+/**
+ * An abstract class. The class defines a reporter plugin interface.
+ */
+class CReporter : public CPlugin
+{
+ public:
+ /**
+ * A method, which reports a crash report to particular receiver.
+ * The plugin can takes arguments, but the plugin has to parse them
+ * by itself.
+ * @param pCrashReport A crash report.
+ * @param pArgs Plugin's arguments.
+ * @retun A message which can be displayed after a report is created.
+ */
+ virtual std::string Report(const map_crash_report_t& pCrashReport,
+ const std::string& pArgs) = 0;
+};
+
+#endif /* REPORTER_H_ */
diff --git a/lib/Utils/test.cpp b/lib/Utils/test.cpp
new file mode 100644
index 0000000..fbad1db
--- /dev/null
+++ b/lib/Utils/test.cpp
@@ -0,0 +1,108 @@
+/*
+ test.cpp - simple library test
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "MiddleWare.h"
+#include "DebugDump.h"
+#include "CrashTypes.h"
+#include <iostream>
+#include <sys/types.h>
+#include <unistd.h>
+#include <iostream>
+
+
+int main(int argc, char** argv)
+{
+
+ if (argc < 2)
+ {
+ std::cerr << "Usage: " << argv[0] << " <DebugDumpDir>" << std::endl;
+ return -1;
+ }
+ try
+ {
+ CMiddleWare middleWare(PLUGINS_CONF_DIR,
+ PLUGINS_LIB_DIR);
+ vector_map_string_t loaded_plugins;
+ middleWare.RegisterPlugin("CCpp");
+ middleWare.RegisterPlugin("Mailx");
+ middleWare.RegisterPlugin("Logger");
+ middleWare.RegisterPlugin("RunApp");
+ middleWare.RegisterPlugin("SQLite3");
+ middleWare.SetDatabase("SQLite3");
+ middleWare.SetOpenGPGCheck(false);
+ middleWare.AddActionOrReporter("Logger", "");
+ middleWare.AddAnalyzerActionOrReporter("CCpp", "Mailx", "");
+ middleWare.AddAnalyzerActionOrReporter("CCpp", "RunApp", "date");
+
+ loaded_plugins = middleWare.GetPluginsInfo();
+ std::cout << "Loaded plugins" << std::endl;
+ int ii;
+ for ( ii = 0; ii < loaded_plugins.size(); ii++)
+ {
+ std::cout << "-------------------------------------------" << std::endl;
+ map_plugin_settings_t settings;
+ std::cout << "Enabled: " << loaded_plugins[ii]["Enabled"] << std::endl;
+ std::cout << "Type: " << loaded_plugins[ii]["Type"] << std::endl;
+ std::cout << "Name: " << loaded_plugins[ii]["Name"] << std::endl;
+ std::cout << "Version: " << loaded_plugins[ii]["Version"] << std::endl;
+ std::cout << "Description: " << loaded_plugins[ii]["Description"] << std::endl;
+ std::cout << "Email: " << loaded_plugins[ii]["Email"] << std::endl;
+ std::cout << "WWW: " << loaded_plugins[ii]["WWW"] << std::endl;
+ std::cout << "GTKBuilder: " << loaded_plugins[ii]["GTKBuilder"] << std::endl;
+ if (loaded_plugins[ii]["Enabled"] == "yes")
+ {
+ std::cout << std::endl << "Settings: " << std::endl;
+ settings = middleWare.GetPluginSettings(loaded_plugins[ii]["Name"]);
+ map_plugin_settings_t::iterator it;
+ for (it = settings.begin(); it != settings.end(); it++)
+ {
+ std::cout << "\t" << it->first << ": " << it->second << std::endl;
+ }
+ }
+ std::cout << "-------------------------------------------" << std::endl;
+ }
+ /* Try to save it into DB */
+ map_crash_info_t crashInfo;
+ if (middleWare.SaveDebugDump(argv[1], crashInfo))
+ {
+ std::cout << "Application Crashed! " <<
+ crashInfo[CD_PACKAGE][CD_CONTENT] << ", " <<
+ crashInfo[CD_EXECUTABLE][CD_CONTENT] << ", " <<
+ crashInfo[CD_COUNT][CD_CONTENT] << ", " << std::endl;
+
+ /* Get Report, so user can change data (remove private stuff)
+ * If we do not want user interaction, just send data immediately
+ */
+ map_crash_report_t crashReport;
+ middleWare.CreateCrashReport(crashInfo[CD_UUID][CD_CONTENT],
+ crashInfo[CD_UID][CD_CONTENT],
+ crashReport);
+ /* Report crash */
+ middleWare.Report(crashReport);
+ }
+ }
+ catch (std::string sError)
+ {
+ std::cerr << sError << std::endl;
+ }
+
+ return 0;
+}