Blame SOURCES/0131-libabrt-add-wrappers-TestElemeExists-and-GetInfo-for.patch

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