summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-12-08 14:51:47 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2010-12-08 14:51:47 +0100
commit816f3e001271ed8ab7fdadb6d90aeb2c61362dac (patch)
treea7e453859a80fb47c7c74cb37791e35ad50f1d97 /src/lib
parent3a9554929de070297a0e816eb2839291335a9403 (diff)
downloadabrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.tar.gz
abrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.tar.xz
abrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.zip
removal of C++isms from libabrt, part 1
This patch converts libabrt usage of C++ map<string, string> to a glib-based container, GHashTable. It is typedef-ed to map_string_h. We can't typedef it to map_string_t, since other parts of ABRT (daemon, cli) still use that name for C++ container. Also, exceptions are removed everywhere. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/abrt_dbus.c28
-rw-r--r--src/lib/abrt_dbus.h1
-rw-r--r--src/lib/abrt_types.c (renamed from src/lib/ABRTException.cpp)30
-rw-r--r--src/lib/abrt_xmlrpc.cpp4
-rw-r--r--src/lib/load_plugin_settings.cpp36
6 files changed, 68 insertions, 33 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 015632fd..8212ebf7 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -40,7 +40,7 @@ libabrt_la_SOURCES = \
run_event.c \
crash_dump.cpp \
create_crash_dump_dir.cpp \
- ABRTException.cpp \
+ abrt_types.c \
hooklib.c hooklib.h \
parse_release.cpp \
parse_options.c parse_options.h
diff --git a/src/lib/abrt_dbus.c b/src/lib/abrt_dbus.c
index 2ba5fa12..69ac1241 100644
--- a/src/lib/abrt_dbus.c
+++ b/src/lib/abrt_dbus.c
@@ -156,6 +156,34 @@ void store_string(DBusMessageIter* iter, const char* val)
free((char*)sanitized);
}
+/* Helper for storing map_string */
+void store_map_string(DBusMessageIter* dbus_iter, map_string_h *val)
+{
+ DBusMessageIter sub_iter;
+ /* map_string is a map. map in dbus is an array of two element structs "({...})":
+ * "s" (string) for key and "s" for value (in this case, also string) */
+ if (!dbus_message_iter_open_container(dbus_iter, DBUS_TYPE_ARRAY, "{ss}", &sub_iter))
+ die_out_of_memory();
+
+ GHashTableIter iter;
+ char *name;
+ char *value;
+ g_hash_table_iter_init(&iter, val);
+ while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value))
+ {
+ DBusMessageIter sub_sub_iter;
+ if (!dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, NULL, &sub_sub_iter))
+ die_out_of_memory();
+ store_string(&sub_sub_iter, name);
+ store_string(&sub_sub_iter, value);
+ if (!dbus_message_iter_close_container(&sub_iter, &sub_sub_iter))
+ die_out_of_memory();
+ }
+
+ if (!dbus_message_iter_close_container(dbus_iter, &sub_iter))
+ die_out_of_memory();
+}
+
/* Helpers for storing crash_data */
static void store_crash_item(DBusMessageIter* iter, struct crash_item *val)
diff --git a/src/lib/abrt_dbus.h b/src/lib/abrt_dbus.h
index b971280c..2f32b26f 100644
--- a/src/lib/abrt_dbus.h
+++ b/src/lib/abrt_dbus.h
@@ -85,6 +85,7 @@ void store_uint64(DBusMessageIter* iter, uint64_t val);
void store_string(DBusMessageIter* iter, const char* val);
void store_crash_data(DBusMessageIter* iter, crash_data_t *val);
void store_vector_of_crash_data(DBusMessageIter* iter, vector_of_crash_data_t *val);
+void store_map_string(DBusMessageIter* iter, map_string_h *val);
/*
* Helpers for parsing DBus messages
diff --git a/src/lib/ABRTException.cpp b/src/lib/abrt_types.c
index 0ae5d452..42100075 100644
--- a/src/lib/ABRTException.cpp
+++ b/src/lib/abrt_types.c
@@ -1,6 +1,6 @@
/*
- Copyright (C) 2010 ABRT team
- Copyright (C) 2010 RedHat Inc
+ Copyright (C) 2010 ABRT Team
+ Copyright (C) 2010 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
@@ -16,18 +16,22 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "abrt_exception.h"
+#include "abrtlib.h"
-CABRTException::CABRTException(abrt_exception_t type, const char* fmt, ...)
+map_string_h *new_map_string(void)
{
- m_type = type;
- va_list ap;
- va_start(ap, fmt);
- m_what = xvasprintf(fmt, ap);
- va_end(ap);
+ return g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
}
-CABRTException::CABRTException(const CABRTException& rhs):
- m_type(rhs.m_type),
- m_what(xstrdup(rhs.m_what))
-{}
+void free_map_string(map_string_h *ms)
+{
+ if (ms)
+ g_hash_table_destroy(ms);
+}
+
+const char *get_map_string_item_or_empty(map_string_h *ms, const char *key)
+{
+ const char *v = (const char*)g_hash_table_lookup(ms, key);
+ if (!v) v = "";
+ return v;
+}
diff --git a/src/lib/abrt_xmlrpc.cpp b/src/lib/abrt_xmlrpc.cpp
index bf74f05b..6dfa8313 100644
--- a/src/lib/abrt_xmlrpc.cpp
+++ b/src/lib/abrt_xmlrpc.cpp
@@ -18,15 +18,13 @@
*/
#include "abrtlib.h"
#include "abrt_xmlrpc.h"
-#include "abrt_exception.h"
void throw_xml_fault(xmlrpc_env *env)
{
std::string errmsg = ssprintf("XML-RPC Fault(%d): %s", env->fault_code, env->fault_string);
xmlrpc_env_clean(env); // this is needed ONLY if fault_occurred
xmlrpc_env_init(env); // just in case user catches ex and _continues_ to use env
- error_msg("%s", errmsg.c_str()); // show error in daemon log
- throw CABRTException(EXCEP_PLUGIN, errmsg.c_str());
+ error_msg_and_die("%s", errmsg.c_str()); // show error in daemon log
}
void throw_if_xml_fault_occurred(xmlrpc_env *env)
diff --git a/src/lib/load_plugin_settings.cpp b/src/lib/load_plugin_settings.cpp
index 1052f19e..0f389069 100644
--- a/src/lib/load_plugin_settings.cpp
+++ b/src/lib/load_plugin_settings.cpp
@@ -18,8 +18,10 @@
*/
#include "abrtlib.h"
-bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
- bool skipKeysWithoutValue /*= true*/)
+/* Returns NULL if open failed.
+ * Returns empty hash if conf file is empty.
+ */
+bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue)
{
FILE *fp = stdin;
if (strcmp(pPath, "-") != 0)
@@ -36,8 +38,13 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
bool is_value = false;
bool valid = false;
bool in_quote = false;
- std::string key;
- std::string value;
+ /* We are reusing line buffer to form temporary
+ * "key\0value\0..." in its beginning
+ */
+ char *key = line;
+ char *value = line;
+ char *cur = line;
+
for (ii = 0; line[ii] != '\0'; ii++)
{
if (line[ii] == '"')
@@ -48,7 +55,7 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
{
continue;
}
- if (line[ii] == '#' && !in_quote && key == "")
+ if (line[ii] == '#' && !in_quote && cur == line)
{
break;
}
@@ -56,39 +63,36 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings,
{
is_value = true;
valid = true;
+ *cur++ = '\0'; /* terminate key */
+ value = cur; /* remember where value starts */
continue;
}
- if (!is_value)
- {
- key += line[ii];
- }
- else
- {
- value += line[ii];
- }
+ *cur++ = line[ii]; /* store next key or value char */
}
+ *cur++ = '\0'; /* terminate value */
/* Skip broken or empty lines. */
if (!valid)
goto free_line;
/* Skip lines with empty key. */
- if (key.length() == 0)
+ if (key[0] == '\0')
goto free_line;
- if (skipKeysWithoutValue && value.length() == 0)
+ if (skipKeysWithoutValue && value[0] == '\0')
goto free_line;
/* Skip lines with unclosed quotes. */
if (in_quote)
goto free_line;
- pSettings[key] = value;
+ g_hash_table_replace(settings, xstrdup(key), xstrdup(value));
free_line:
free(line);
}
if (fp != stdin)
fclose(fp);
+
return true;
}