|
|
a60cd7 |
From fcdd55f0dd8fb7ffbf1bfaf3f701a0ffa005bf00 Mon Sep 17 00:00:00 2001
|
|
|
a60cd7 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
Date: Tue, 24 Mar 2015 20:54:40 +0100
|
|
|
a60cd7 |
Subject: [PATCH] libabrt: add wrappers TestElemeExists and GetInfo for one
|
|
|
a60cd7 |
element
|
|
|
a60cd7 |
|
|
|
a60cd7 |
To conveniently use the DBus methods.
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Related: #1224984
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
---
|
|
|
a60cd7 |
src/include/libabrt.h | 18 +++++++++++
|
|
|
a60cd7 |
src/lib/problem_api_dbus.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
a60cd7 |
2 files changed, 93 insertions(+)
|
|
|
a60cd7 |
|
|
|
a60cd7 |
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
|
|
|
a60cd7 |
index 6a51c80..5d74aa3 100644
|
|
|
a60cd7 |
--- a/src/include/libabrt.h
|
|
|
a60cd7 |
+++ b/src/include/libabrt.h
|
|
|
a60cd7 |
@@ -140,6 +140,24 @@ void koops_print_suspicious_strings_filtered(const regex_t **filterout);
|
|
|
a60cd7 |
int chown_dir_over_dbus(const char *problem_dir_path);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
/**
|
|
|
a60cd7 |
+ @brief Checks whether the given element name exists
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ Might require authorization
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ @return Positive number if such an element exist, 0 if doesn't and negative number if an error occurs.
|
|
|
a60cd7 |
+ */
|
|
|
a60cd7 |
+int test_exist_over_dbus(const char *problem_id, const char *element_name);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+/**
|
|
|
a60cd7 |
+ @ Returns value of the given element name
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ Might require authorization
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ @return malloced string or NULL if no such an element exists; ERR_PTR in case of any error.
|
|
|
a60cd7 |
+ */
|
|
|
a60cd7 |
+char *load_text_over_dbus(const char *problem_id, const char *element_name);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+/**
|
|
|
a60cd7 |
@brief Delets multiple problems specified by their id (as returned from problem_data_save)
|
|
|
a60cd7 |
|
|
|
a60cd7 |
@param problem_dir_paths List of problem ids
|
|
|
a60cd7 |
diff --git a/src/lib/problem_api_dbus.c b/src/lib/problem_api_dbus.c
|
|
|
a60cd7 |
index 549175c..5148932 100644
|
|
|
a60cd7 |
--- a/src/lib/problem_api_dbus.c
|
|
|
a60cd7 |
+++ b/src/lib/problem_api_dbus.c
|
|
|
a60cd7 |
@@ -227,3 +227,78 @@ problem_data_t *get_full_problem_data_over_dbus(const char *problem_dir_path)
|
|
|
a60cd7 |
|
|
|
a60cd7 |
return pd;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+int test_exist_over_dbus(const char *problem_id, const char *element_name)
|
|
|
a60cd7 |
+{
|
|
|
a60cd7 |
+ INITIALIZE_LIBABRT();
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GDBusProxy *proxy = get_dbus_proxy();
|
|
|
a60cd7 |
+ if (!proxy)
|
|
|
a60cd7 |
+ return -1;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GError *error = NULL;
|
|
|
a60cd7 |
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
|
|
|
a60cd7 |
+ "TestElementExists",
|
|
|
a60cd7 |
+ g_variant_new("(ss)", problem_id, element_name),
|
|
|
a60cd7 |
+ G_DBUS_CALL_FLAGS_NONE,
|
|
|
a60cd7 |
+ -1,
|
|
|
a60cd7 |
+ NULL,
|
|
|
a60cd7 |
+ &error);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ if (error)
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ error_msg(_("Can't test whether the element exists over abrt-dbus: %s"), error->message);
|
|
|
a60cd7 |
+ g_error_free(error);
|
|
|
a60cd7 |
+ return -1;
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ gboolean retval;
|
|
|
a60cd7 |
+ g_variant_get(result, "(b)", &retval);
|
|
|
a60cd7 |
+ g_variant_unref(result);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ return retval;
|
|
|
a60cd7 |
+}
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+char *load_text_over_dbus(const char *problem_id, const char *element_name)
|
|
|
a60cd7 |
+{
|
|
|
a60cd7 |
+ INITIALIZE_LIBABRT();
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GDBusProxy *proxy = get_dbus_proxy();
|
|
|
a60cd7 |
+ if (!proxy)
|
|
|
a60cd7 |
+ return ERR_PTR;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
|
|
|
a60cd7 |
+ g_variant_builder_add(builder, "s", element_name);
|
|
|
a60cd7 |
+ GVariant *params = g_variant_new("(sas)", problem_id, builder);
|
|
|
a60cd7 |
+ g_variant_builder_unref(builder);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GError *error = NULL;
|
|
|
a60cd7 |
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
|
|
|
a60cd7 |
+ "GetInfo",
|
|
|
a60cd7 |
+ params,
|
|
|
a60cd7 |
+ G_DBUS_CALL_FLAGS_NONE,
|
|
|
a60cd7 |
+ -1,
|
|
|
a60cd7 |
+ NULL,
|
|
|
a60cd7 |
+ &error);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ if (error)
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
|
|
|
a60cd7 |
+ g_error_free(error);
|
|
|
a60cd7 |
+ return ERR_PTR;
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ GVariant *values = g_variant_get_child_value(result, 0);
|
|
|
a60cd7 |
+ g_variant_unref(result);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ char *retval = NULL;
|
|
|
a60cd7 |
+ if (g_variant_n_children(values) == 1)
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ GVariant *contents = g_variant_get_child_value(values, 0);
|
|
|
a60cd7 |
+ gchar *key;
|
|
|
a60cd7 |
+ g_variant_get(contents, "{&ss}", &key, &retval);
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ g_variant_unref(values);
|
|
|
a60cd7 |
+ return retval;
|
|
|
a60cd7 |
+}
|
|
|
a60cd7 |
--
|
|
|
a60cd7 |
2.4.3
|
|
|
a60cd7 |
|