diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-03-17 11:28:50 +0100 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-03-17 11:28:50 +0100 |
commit | 95d70559d649de94502179a22856b58dbb9d47c2 (patch) | |
tree | 2a592d606971c8c2269389f6831f8dbb2bac9918 | |
parent | 8c68c3576464947a43ada0d02cfb3313cb7ec697 (diff) | |
parent | 770a494819fa5c44b14ca013c4b433d278b2a75a (diff) | |
download | abrt-95d70559d649de94502179a22856b58dbb9d47c2.tar.gz abrt-95d70559d649de94502179a22856b58dbb9d47c2.tar.xz abrt-95d70559d649de94502179a22856b58dbb9d47c2.zip |
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | lib/MiddleWare/Plugin.h | 3 | ||||
-rw-r--r-- | lib/MiddleWare/PluginManager.cpp | 11 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.conf | 1 | ||||
-rw-r--r-- | lib/Plugins/Makefile.am | 3 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.cpp | 62 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.h | 5 |
7 files changed, 57 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac index 2975de51..d6d13af5 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,7 @@ PKG_CHECK_MODULES([GTK], [gtk+-2.0]) PKG_CHECK_MODULES([GLIB], [glib-2.0]) PKG_CHECK_MODULES([DBUSCPP], [dbus-c++-1]) PKG_CHECK_MODULES([RPM], [rpm]) +PKG_CHECK_MODULES([CURL], [libcurl]) AC_CHECK_HEADER([sys/inotify.h], [], [AC_MSG_ERROR([sys/inotify.h is needed to build abrt])]) diff --git a/lib/MiddleWare/Plugin.h b/lib/MiddleWare/Plugin.h index 210e94d8..014733d8 100644 --- a/lib/MiddleWare/Plugin.h +++ b/lib/MiddleWare/Plugin.h @@ -30,7 +30,8 @@ #define PLUGINS_MAGIC_NUMBER 1 #define PLUGINS_CONF_EXTENSION "conf" -#define PLUGINS_LIB_EXTENSIONS "so" +#define PLUGINS_LIB_EXTENSION "so" +#define PLUGINS_LIB_PREFIX "lib" class CPlugin { diff --git a/lib/MiddleWare/PluginManager.cpp b/lib/MiddleWare/PluginManager.cpp index 7d8eb4ef..e0def74a 100644 --- a/lib/MiddleWare/PluginManager.cpp +++ b/lib/MiddleWare/PluginManager.cpp @@ -37,7 +37,7 @@ CPluginManager::~CPluginManager() void CPluginManager::LoadPlugins() { - DIR *dir = opendir(m_sPlugisConfDir.c_str()); + DIR *dir = opendir(m_sPlugisLibDir.c_str()); struct dirent *dent = NULL; if (dir != NULL) { @@ -46,10 +46,11 @@ void CPluginManager::LoadPlugins() if (dent->d_type == DT_REG) { std::string name = dent->d_name; - std::string extension = name.substr(name.length()-sizeof(PLUGINS_CONF_EXTENSION)+1); - if (extension == PLUGINS_CONF_EXTENSION) + std::string extension = name.substr(name.length()-sizeof(PLUGINS_LIB_EXTENSION)+1); + if (extension == PLUGINS_LIB_EXTENSION) { - name.erase(name.length()-sizeof(PLUGINS_CONF_EXTENSION)); + name.erase(0, sizeof(PLUGINS_LIB_PREFIX) - 1); + name.erase(name.length() - sizeof(PLUGINS_LIB_EXTENSION)); LoadPlugin(name); } } @@ -75,7 +76,7 @@ void CPluginManager::LoadPlugin(const std::string& pName) CABRTPlugin* abrtPlugin = NULL; try { - std::string libPath = m_sPlugisLibDir + "/lib" + pName + "." + PLUGINS_LIB_EXTENSIONS; + std::string libPath = m_sPlugisLibDir + "/" + PLUGINS_LIB_PREFIX + pName + "." + PLUGINS_LIB_EXTENSION; abrtPlugin = new CABRTPlugin(libPath); if (abrtPlugin->GetMagicNumber() != PLUGINS_MAGIC_NUMBER || (abrtPlugin->GetType() < LANGUAGE && abrtPlugin->GetType() > DATABASE)) diff --git a/lib/Plugins/Kerneloops.conf b/lib/Plugins/Kerneloops.conf deleted file mode 100644 index 9783f9da..00000000 --- a/lib/Plugins/Kerneloops.conf +++ /dev/null @@ -1 +0,0 @@ -# no settings required diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 3655eda8..9759833e 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -18,7 +18,8 @@ libKerneloops_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEB # KerneloopsReporter libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h libKerneloopsReporter_la_LDFLAGS = -avoid-version -libKerneloopsReporter_la_LIBADD = -lcurl +libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) +libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(CURL_CFLAGS) # Mailx libMailx_la_SOURCES = Mailx.cpp Mailx.h diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index 645287ba..c886ff01 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -26,7 +26,8 @@ #include <iostream> -#define TABLE_NAME "abrt" +#define ABRT_TABLE "abrt" +#define SQLITE3_MASTER_TABLE "sqlite_master" CSQLite3::CSQLite3() : m_sDBPath("/var/cache/abrt/abrt-db"), @@ -36,7 +37,7 @@ CSQLite3::CSQLite3() : bool CSQLite3::Exist(const std::string& pUUID, const std::string& pUID) { vector_database_rows_t table; - GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "TABLE_NAME" WHERE " + GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "ABRT_TABLE" WHERE " DATABASE_COLUMN_UUID" = '"+pUUID+"' AND " DATABASE_COLUMN_UID" = '"+pUID+"';", table); if(table.empty()) @@ -101,22 +102,31 @@ void CSQLite3::GetTable(const std::string& pCommand, vector_database_rows_t& pTa void CSQLite3::Connect() { + if (!OpenDB()) + { + CreateDB(); + } + if (!CheckTable()) + { + CreateTable(); + } +} + +bool CSQLite3::OpenDB() +{ int ret = sqlite3_open_v2(m_sDBPath.c_str(), &m_pDB, SQLITE_OPEN_READWRITE, NULL); - if(ret == SQLITE_CANTOPEN) - { - Create(); - } - else if (ret != SQLITE_OK) + if (ret != SQLITE_OK && ret != SQLITE_CANTOPEN) { - throw std::string("SQLite3::Connect(): Could not open database.") + sqlite3_errmsg(m_pDB); + throw std::string("SQLite3::CheckDB(): Could not open database. ") + sqlite3_errmsg(m_pDB); } + return ret == SQLITE_OK; } -void CSQLite3::Create() +void CSQLite3::CreateDB() { int ret = sqlite3_open_v2(m_sDBPath.c_str(), &m_pDB, @@ -124,10 +134,22 @@ void CSQLite3::Create() NULL); if(ret != SQLITE_OK) { - throw std::string("SQLite3::Create(): Could not create database.") + sqlite3_errmsg(m_pDB); + throw std::string("SQLite3::Create(): Could not create database. ") + sqlite3_errmsg(m_pDB); } +} + +bool CSQLite3::CheckTable() +{ + vector_database_rows_t table; + GetTable("SELECT NAME FROM "SQLITE3_MASTER_TABLE" " + "WHERE TYPE='table' AND NAME='"ABRT_TABLE"';", table); + + return table.size() == 1; +} - Exec("CREATE TABLE "TABLE_NAME" (" +void CSQLite3::CreateTable() +{ + Exec("CREATE TABLE "ABRT_TABLE" (" DATABASE_COLUMN_UUID" VARCHAR NOT NULL," DATABASE_COLUMN_UID" VARCHAR NOT NULL," DATABASE_COLUMN_DEBUG_DUMP_PATH" VARCHAR NOT NULL," @@ -149,7 +171,7 @@ void CSQLite3::Insert(const std::string& pUUID, { if (!Exist(pUUID, pUID)) { - Exec("INSERT INTO "TABLE_NAME"(" + Exec("INSERT INTO "ABRT_TABLE"(" DATABASE_COLUMN_UUID"," DATABASE_COLUMN_UID"," DATABASE_COLUMN_DEBUG_DUMP_PATH"," @@ -162,7 +184,7 @@ void CSQLite3::Insert(const std::string& pUUID, } else { - Exec("UPDATE "TABLE_NAME" " + Exec("UPDATE "ABRT_TABLE" " "SET "DATABASE_COLUMN_COUNT" = "DATABASE_COLUMN_COUNT" + 1, " DATABASE_COLUMN_TIME" = '"+pTime+"' " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " @@ -174,12 +196,12 @@ void CSQLite3::Delete(const std::string& pUUID, const std::string& pUID) { if (pUID == "0") { - Exec("DELETE FROM "TABLE_NAME" " + Exec("DELETE FROM "ABRT_TABLE" " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); } else if (Exist(pUUID, pUID)) { - Exec("DELETE FROM "TABLE_NAME" " + Exec("DELETE FROM "ABRT_TABLE" " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } @@ -193,7 +215,7 @@ void CSQLite3::SetReported(const std::string& pUUID, const std::string& pUID) { if (Exist(pUUID, pUID)) { - Exec("UPDATE "TABLE_NAME" " + Exec("UPDATE "ABRT_TABLE" " "SET "DATABASE_COLUMN_REPORTED" = 1 " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); @@ -209,11 +231,11 @@ const vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) vector_database_rows_t table; if (pUID == "0") { - GetTable("SELECT * FROM "TABLE_NAME";", table); + GetTable("SELECT * FROM "ABRT_TABLE";", table); } else { - GetTable("SELECT * FROM "TABLE_NAME + GetTable("SELECT * FROM "ABRT_TABLE " WHERE "DATABASE_COLUMN_UID" = '"+pUID+"';", table); } @@ -226,13 +248,13 @@ const database_row_t CSQLite3::GetUUIDData(const std::string& pUUID, const std:: if (pUID == "0") { - GetTable("SELECT * FROM "TABLE_NAME" " + GetTable("SELECT * FROM "ABRT_TABLE" " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';", table); } else { - GetTable("SELECT * FROM "TABLE_NAME" " + GetTable("SELECT * FROM "ABRT_TABLE" " "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " "AND "DATABASE_COLUMN_UID" = '"+pUID+"';", table); diff --git a/lib/Plugins/SQLite3.h b/lib/Plugins/SQLite3.h index e3681d6c..4903f6a3 100644 --- a/lib/Plugins/SQLite3.h +++ b/lib/Plugins/SQLite3.h @@ -33,7 +33,10 @@ class CSQLite3 : public CDatabase std::string m_sDBPath; sqlite3* m_pDB; - void Create(); + bool OpenDB(); + bool CheckTable(); + void CreateDB(); + void CreateTable(); void Exec(const std::string& pCommand); void GetTable(const std::string& pCommand, vector_database_rows_t& pTable); bool Exist(const std::string& pUUID, const std::string& pUID); |