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

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