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