From 0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Sep 2009 12:43:01 +0200 Subject: unify CommLayer, MiddleWare and Utils into Utils Signed-off-by: Denys Vlasenko --- configure.ac | 2 - lib/CommLayer/CommLayerInner.cpp | 69 ----------- lib/CommLayer/CommLayerInner.h | 23 ---- lib/CommLayer/DBusClientProxy.cpp | 239 -------------------------------------- lib/CommLayer/DBusClientProxy.h | 108 ----------------- lib/CommLayer/DBusCommon.h | 29 ----- lib/CommLayer/Makefile.am | 32 ----- lib/CommLayer/Observer.h | 16 --- lib/Makefile.am | 2 +- lib/MiddleWare/Action.h | 47 -------- lib/MiddleWare/Analyzer.h | 56 --------- lib/MiddleWare/Database.h | 126 -------------------- lib/MiddleWare/Makefile.am | 34 ------ lib/MiddleWare/Plugin.cpp | 27 ----- lib/MiddleWare/Plugin.h | 118 ------------------- lib/MiddleWare/Reporter.h | 47 -------- lib/MiddleWare/test.cpp | 108 ----------------- lib/Plugins/Makefile.am | 24 ++-- lib/Utils/Action.h | 47 ++++++++ lib/Utils/Analyzer.h | 56 +++++++++ lib/Utils/CommLayerInner.cpp | 69 +++++++++++ lib/Utils/CommLayerInner.h | 23 ++++ lib/Utils/DBusClientProxy.cpp | 239 ++++++++++++++++++++++++++++++++++++++ lib/Utils/DBusClientProxy.h | 108 +++++++++++++++++ lib/Utils/DBusCommon.h | 29 +++++ lib/Utils/Database.h | 126 ++++++++++++++++++++ lib/Utils/Makefile.am | 47 ++++++-- lib/Utils/Observer.h | 16 +++ lib/Utils/Plugin.cpp | 27 +++++ lib/Utils/Plugin.h | 118 +++++++++++++++++++ lib/Utils/Reporter.h | 47 ++++++++ lib/Utils/test.cpp | 108 +++++++++++++++++ src/Applet/Makefile.am | 16 +-- src/CLI/Makefile.am | 16 ++- src/Daemon/Makefile.am | 7 +- src/Hooks/Makefile.am | 26 ++--- 36 files changed, 1095 insertions(+), 1137 deletions(-) delete mode 100644 lib/CommLayer/CommLayerInner.cpp delete mode 100644 lib/CommLayer/CommLayerInner.h delete mode 100644 lib/CommLayer/DBusClientProxy.cpp delete mode 100644 lib/CommLayer/DBusClientProxy.h delete mode 100644 lib/CommLayer/DBusCommon.h delete mode 100644 lib/CommLayer/Makefile.am delete mode 100644 lib/CommLayer/Observer.h delete mode 100644 lib/MiddleWare/Action.h delete mode 100644 lib/MiddleWare/Analyzer.h delete mode 100644 lib/MiddleWare/Database.h delete mode 100644 lib/MiddleWare/Makefile.am delete mode 100644 lib/MiddleWare/Plugin.cpp delete mode 100644 lib/MiddleWare/Plugin.h delete mode 100644 lib/MiddleWare/Reporter.h delete mode 100644 lib/MiddleWare/test.cpp create mode 100644 lib/Utils/Action.h create mode 100644 lib/Utils/Analyzer.h create mode 100644 lib/Utils/CommLayerInner.cpp create mode 100644 lib/Utils/CommLayerInner.h create mode 100644 lib/Utils/DBusClientProxy.cpp create mode 100644 lib/Utils/DBusClientProxy.h create mode 100644 lib/Utils/DBusCommon.h create mode 100644 lib/Utils/Database.h create mode 100644 lib/Utils/Observer.h create mode 100644 lib/Utils/Plugin.cpp create mode 100644 lib/Utils/Plugin.h create mode 100644 lib/Utils/Reporter.h create mode 100644 lib/Utils/test.cpp diff --git a/configure.ac b/configure.ac index ff427536..95999a49 100644 --- a/configure.ac +++ b/configure.ac @@ -76,8 +76,6 @@ AC_CONFIG_FILES([ Makefile lib/Makefile lib/Utils/Makefile - lib/MiddleWare/Makefile - lib/CommLayer/Makefile lib/Plugins/Makefile lib/Python/Makefile src/Makefile diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp deleted file mode 100644 index b5b8db78..00000000 --- a/lib/CommLayer/CommLayerInner.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include "abrtlib.h" -#include "CommLayerInner.h" - -static CObserver *s_pObs; - -typedef std::map 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/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h deleted file mode 100644 index d161cfc7..00000000 --- a/lib/CommLayer/CommLayerInner.h +++ /dev/null @@ -1,23 +0,0 @@ -#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/CommLayer/DBusClientProxy.cpp b/lib/CommLayer/DBusClientProxy.cpp deleted file mode 100644 index ccb48d53..00000000 --- a/lib/CommLayer/DBusClientProxy.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - 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 - -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 - */ - /* - - < - - - - ... - > - */ -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/CommLayer/DBusClientProxy.h b/lib/CommLayer/DBusClientProxy.h deleted file mode 100644 index e43805bf..00000000 --- a/lib/CommLayer/DBusClientProxy.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - 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 -#include -#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 - */ - /* - < - - - - ... - > - */ - 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/CommLayer/DBusCommon.h b/lib/CommLayer/DBusCommon.h deleted file mode 100644 index b3e3af2c..00000000 --- a/lib/CommLayer/DBusCommon.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - 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/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am deleted file mode 100644 index be0c52bf..00000000 --- a/lib/CommLayer/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -lib_LTLIBRARIES = libABRTCommLayer.la - -libABRTCommLayer_la_SOURCES = \ - DBusClientProxy.h DBusClientProxy.cpp \ - CommLayerInner.h CommLayerInner.cpp \ - Observer.h \ - DBusCommon.h -libABRTCommLayer_la_LIBADD = \ - ../../lib/MiddleWare/libABRTMiddleWare.la \ - $(DL_LIBS) $(DBUSCPP_LIBS) -libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 -libABRTCommLayer_la_CPPFLAGS = \ - -Wall -Werror \ - -I$(srcdir)/../../inc \ - -I$(srcdir)/../../lib/MiddleWare \ - -I$(srcdir)/../../lib/DBus \ - -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)\" \ - $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ - -D_GNU_SOURCE - -#check_PROGRAMS = test -#test_SOURCES = test.cpp -#test_LDADD = ../Utils/libABRTUtils.la libABRTCommLayer.la $(DL_LIBS) $(RPM_LIBS) -#test_CPPFLAGS = -I$(srcdir)/../Utils \ -# -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -# -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -# -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -# -DCONF_DIR=\"$(CONF_DIR)\" diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h deleted file mode 100644 index 421dc0cc..00000000 --- a/lib/CommLayer/Observer.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef OBSERVER_H_ -#define OBSERVER_H_ - -#include -#include -#include -#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/Makefile.am b/lib/Makefile.am index 53a42fe4..6be37e8c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = Utils MiddleWare Plugins CommLayer Python +SUBDIRS = Utils Plugins Python diff --git a/lib/MiddleWare/Action.h b/lib/MiddleWare/Action.h deleted file mode 100644 index 1286feba..00000000 --- a/lib/MiddleWare/Action.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 -#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/MiddleWare/Analyzer.h b/lib/MiddleWare/Analyzer.h deleted file mode 100644 index 4fe586b8..00000000 --- a/lib/MiddleWare/Analyzer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - 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 -#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/MiddleWare/Database.h b/lib/MiddleWare/Database.h deleted file mode 100644 index 0fc31ee7..00000000 --- a/lib/MiddleWare/Database.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - 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 -#include -#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 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/MiddleWare/Makefile.am b/lib/MiddleWare/Makefile.am deleted file mode 100644 index 0db4f79e..00000000 --- a/lib/MiddleWare/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -lib_LTLIBRARIES = libABRTMiddleWare.la - -libABRTMiddleWare_la_SOURCES = \ - Plugin.cpp Plugin.h \ - Action.h Database.h Reporter.h Analyzer.h -libABRTMiddleWare_la_LIBADD = \ - $(DL_LIBS) \ - ../Utils/libABRTUtils.la \ - $(RPM_LIBS) -libABRTMiddleWare_la_LDFLAGS = -version-info 0:1:0 -libABRTMiddleWare_la_CPPFLAGS = \ - -I$(srcdir)/../../inc \ - -I$(srcdir)/../Utils \ - -I$(srcdir)/../CommLayer \ - $(RPM_CFLAGS) - -# disabled: MiddleWare.* is moved to src/Daemon/ now -# -#check_PROGRAMS = test -# -#test_SOURCES = test.cpp -#test_LDADD = \ -# ../Utils/libABRTUtils.la \ -# ../CommLayer/libABRTCommLayer.la \ -# libABRTMiddleWare.la \ -# $(DL_LIBS) $(RPM_LIBS) -#test_CPPFLAGS = \ -# -I$(srcdir)/../../inc \ -# -I$(srcdir)/../Utils \ -# -I$(srcdir)/../CommLayer\ -# -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -# -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -# -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -# -DCONF_DIR=\"$(CONF_DIR)\" diff --git a/lib/MiddleWare/Plugin.cpp b/lib/MiddleWare/Plugin.cpp deleted file mode 100644 index 161ead8a..00000000 --- a/lib/MiddleWare/Plugin.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - 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/MiddleWare/Plugin.h b/lib/MiddleWare/Plugin.h deleted file mode 100644 index 39290231..00000000 --- a/lib/MiddleWare/Plugin.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - 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 -#endif - -#if ENABLE_NLS - #include - #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/MiddleWare/Reporter.h b/lib/MiddleWare/Reporter.h deleted file mode 100644 index c74a10c3..00000000 --- a/lib/MiddleWare/Reporter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 -#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/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp deleted file mode 100644 index fbad1db9..00000000 --- a/lib/MiddleWare/test.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - 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 -#include -#include -#include - - -int main(int argc, char** argv) -{ - - if (argc < 2) - { - std::cerr << "Usage: " << argv[0] << " " << 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; -} diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 02c821ad..cbd29dc9 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer +AM_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils pluginslibdir=$(PLUGINS_LIB_DIR) pluginslib_LTLIBRARIES = libCCpp.la \ libMailx.la \ @@ -36,39 +36,39 @@ install-data-hook: libCCpp_la_SOURCES = CCpp.cpp CCpp.h libCCpp_la_LDFLAGS = -avoid-version libCCpp_la_LIBADD = $(NSS_LIBS) -libCCpp_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) +libCCpp_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) # Kerneloops libKerneloops_la_SOURCES = Kerneloops.cpp Kerneloops.h libKerneloops_la_LDFLAGS = -avoid-version -libKerneloops_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +libKerneloops_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils # KerneloopsReporter libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h libKerneloopsReporter_la_LDFLAGS = -avoid-version libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) -libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # KerneloopsScanner libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h libKerneloopsScanner_la_LDFLAGS = -avoid-version -libKerneloopsScanner_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" +libKerneloopsScanner_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" # Mailx libMailx_la_SOURCES = Mailx.cpp Mailx.h libMailx_la_LDFLAGS = -avoid-version -libMailx_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libMailx_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # SQLite3 libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h libSQLite3_la_LDFLAGS = -avoid-version libSQLite3_la_LIBADD = $(SQLITE3_LIBS) -libSQLite3_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"' +libSQLite3_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"' # Logger libLogger_la_SOURCES = Logger.cpp Logger.h libLogger_la_LDFLAGS = -avoid-version -libLogger_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libLogger_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # RunApp libRunApp_la_SOURCES = RunApp.h RunApp.cpp @@ -82,22 +82,22 @@ libSOSreport_la_LDFLAGS = -avoid-version libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) $(NSS_LIBS) libBugzilla_la_LDFLAGS = -avoid-version -libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) $(NSS_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # TicketUploader libTicketUploader_la_SOURCES = TicketUploader.h TicketUploader.cpp libTicketUploader_la_LDFLAGS = -avoid-version libTicketUploader_la_LIBADD = $(CURL_LIBS) -libTicketUploader_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libTicketUploader_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # Python libPython_la_SOURCES = Python.h Python.cpp #libPython_la_LIBADD = $(NSS_LIBS) libPython_la_LDFLAGS = -avoid-version -libPython_la_CPPFLAGS = $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +libPython_la_CPPFLAGS = $(NSS_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../Utils # FileTrasfer libFileTransfer_la_SOURCES = FileTransfer.cpp FileTransfer.h libFileTransfer_la_LDFLAGS = -avoid-version libFileTransfer_la_LIBADD = $(CURL_LIBS) -libFileTransfer_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(CURL_CFLAGS) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" +libFileTransfer_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils $(CURL_CFLAGS) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" diff --git a/lib/Utils/Action.h b/lib/Utils/Action.h new file mode 100644 index 00000000..1286feba --- /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 +#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 00000000..4fe586b8 --- /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 +#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 00000000..b5b8db78 --- /dev/null +++ b/lib/Utils/CommLayerInner.cpp @@ -0,0 +1,69 @@ +#include +#include +#include "abrtlib.h" +#include "CommLayerInner.h" + +static CObserver *s_pObs; + +typedef std::map 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 00000000..d161cfc7 --- /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 00000000..ccb48d53 --- /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 + +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 + */ + /* + + < + + + + ... + > + */ +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 00000000..e43805bf --- /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 +#include +#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 + */ + /* + < + + + + ... + > + */ + 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 00000000..b3e3af2c --- /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 00000000..0fc31ee7 --- /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 +#include +#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 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 cb5b3377..b662ae9a 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 00000000..421dc0cc --- /dev/null +++ b/lib/Utils/Observer.h @@ -0,0 +1,16 @@ +#ifndef OBSERVER_H_ +#define OBSERVER_H_ + +#include +#include +#include +#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 00000000..161ead8a --- /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 00000000..39290231 --- /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 +#endif + +#if ENABLE_NLS + #include + #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 00000000..c74a10c3 --- /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 +#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 00000000..fbad1db9 --- /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 +#include +#include +#include + + +int main(int argc, char** argv) +{ + + if (argc < 2) + { + std::cerr << "Usage: " << argv[0] << " " << 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; +} diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am index 5190649b..1c810350 100644 --- a/src/Applet/Makefile.am +++ b/src/Applet/Makefile.am @@ -7,17 +7,19 @@ abrt_applet_CPPFLAGS = \ -Wall -Werror \ -I../Daemon/ \ -I$(srcdir)/../../inc \ - -I$(srcdir)/../../lib/CommLayer \ - -I$(srcdir)/../../lib/MiddleWare \ + -I$(srcdir)/../../lib/Utils \ + -I/usr/include/glib-2.0 \ + -I/usr/lib/glib-2.0/include \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DBIN_DIR=\"$(bindir)\" \ - $(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) $(LIBNOTIFY_CFLAGS) \ - -I/usr/include/glib-2.0 \ - -I/usr/lib/glib-2.0/include + $(DBUS_GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(DBUSCPP_CFLAGS) \ + $(LIBNOTIFY_CFLAGS) abrt_applet_LDADD = \ - ../../lib/CommLayer/libABRTCommLayer.la \ - $(DL_LIBS) $(GTK_LIBS) \ + ../../lib/Utils/libABRTUtils.la \ -lglib-2.0 -lgthread-2.0 \ + $(DL_LIBS) $(GTK_LIBS) \ $(DBUSCPP_LIBS) $(LIBNOTIFY_LIBS) EXTRA_DIST = abrt-applet.desktop popup.GtkBuilder diff --git a/src/CLI/Makefile.am b/src/CLI/Makefile.am index be896020..9823965e 100644 --- a/src/CLI/Makefile.am +++ b/src/CLI/Makefile.am @@ -3,15 +3,19 @@ #abrt_cli_CPPFLAGS = -I$(srcdir)/../../inc -DVAR_RUN=\"$(VAR_RUN)\" bin_PROGRAMS = abrt-cli + abrt_cli_SOURCES = \ CLI.cpp \ ABRTSocket.h ABRTSocket.cpp \ CommLayerClientDBus.h CommLayerClientDBus.cpp abrt_cli_CPPFLAGS = \ - $(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) $(LIBNOTIFY_CFLAGS) \ - -I$(srcdir)/../../inc -DVAR_RUN=\"$(VAR_RUN)\" \ - -I$(srcdir)/../../lib/CommLayer \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/Utils \ + -DVAR_RUN=\"$(VAR_RUN)\" \ $(ENABLE_SOCKET_OR_DBUS) \ - -I../../lib/MiddleWare - -abrt_cli_LDADD = ../../lib/CommLayer/libABRTCommLayer.la + $(DBUS_GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(DBUSCPP_CFLAGS) \ + $(LIBNOTIFY_CFLAGS) +abrt_cli_LDADD = \ + ../../lib/Utils/libABRTUtils.la diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index f6bb9c15..a4698afc 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -1,7 +1,7 @@ sbin_PROGRAMS = abrtd # FIXME: we still link against dbus-c++ (not just dbus) -# because lib/CommLayer links it in +# because lib/Utils links it in abrtd_SOURCES = \ ABRTPlugin.cpp ABRTPlugin.h \ @@ -16,8 +16,6 @@ abrtd_SOURCES = \ Settings.h Settings.cpp abrtd_CPPFLAGS = \ -I$(srcdir)/../../inc \ - -I$(srcdir)/../../lib/MiddleWare \ - -I$(srcdir)/../../lib/CommLayer \ -I$(srcdir)/../../lib/Utils \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ @@ -27,8 +25,7 @@ abrtd_CPPFLAGS = \ $(GLIB_CFLAGS) $(DBUS_CFLAGS) \ $(ENABLE_SOCKET_OR_DBUS) abrtd_LDADD = \ - ../../lib/MiddleWare/libABRTMiddleWare.la \ - ../../lib/CommLayer/libABRTCommLayer.la \ + ../../lib/Utils/libABRTUtils.la \ $(DL_LIBS) $(DBUS_LIBS) $(RPM_LIBS) dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am index b2e90eb4..2831cf9e 100644 --- a/src/Hooks/Makefile.am +++ b/src/Hooks/Makefile.am @@ -10,19 +10,19 @@ hookCCpp_CPPFLAGS = -I$(srcdir)/../../inc \ -DVAR_RUN=\"$(VAR_RUN)\" # dumpoops -dumpoops_SOURCES = dumpoops.cpp -dumpoops_LDADD = ../../lib/Utils/libABRTUtils.la \ - ../../lib/MiddleWare/libABRTMiddleWare.la \ - ../../lib/CommLayer/libABRTCommLayer.la -dumpoops_CPPFLAGS = -I$(srcdir)/../../inc \ - -I$(srcdir)/../../lib/Utils \ - -I$(srcdir)/../../lib/Plugins \ - -I$(srcdir)/../../lib/MiddleWare \ - -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)\" +dumpoops_SOURCES = \ + dumpoops.cpp +dumpoops_LDADD = \ + ../../lib/Utils/libABRTUtils.la +dumpoops_CPPFLAGS = \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/Utils \ + -I$(srcdir)/../../lib/Plugins \ + -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)\" python_PYTHON = sitecustomize.py abrt_exception_handler.py EXTRA_DIST = abrt_exception_handler.py.in -- cgit