[tracker/wip/carlosg/portal: 8/29] libtracker-common: Add method to build dbus URI



commit 1c2f858a8a5b7b23207a720f892ec634627812bd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 23 23:33:01 2020 +0100

    libtracker-common: Add method to build dbus URI
    
    This is the inverse of tracker_util_parse_dbus_uri(), that we
    can build a DBus URI with.

 src/libtracker-common/libtracker-common.vapi |  3 +++
 src/libtracker-common/tracker-utils.c        | 29 ++++++++++++++++++++++++++++
 src/libtracker-common/tracker-utils.h        |  3 +++
 3 files changed, 35 insertions(+)
---
diff --git a/src/libtracker-common/libtracker-common.vapi b/src/libtracker-common/libtracker-common.vapi
index fa38e9f28..3915a7e9c 100644
--- a/src/libtracker-common/libtracker-common.vapi
+++ b/src/libtracker-common/libtracker-common.vapi
@@ -23,6 +23,9 @@ namespace Tracker {
        [CCode (cheader_filename = "libtracker-common/tracker-date-time.h")]
        public double string_to_date (string date_string, out int offset) throws DateError;
 
+       [CCode (cheader_filename = "libtracker-common/tracker-utils.h")]
+       public string? util_build_dbus_uri (GLib.BusType bus_type, string service, string? path);
+
        [CCode (cheader_filename = "libtracker-common/tracker-date-time.h")]
        public errordomain DateError {
                OFFSET,
diff --git a/src/libtracker-common/tracker-utils.c b/src/libtracker-common/tracker-utils.c
index 7c03530b4..b5f22174d 100644
--- a/src/libtracker-common/tracker-utils.c
+++ b/src/libtracker-common/tracker-utils.c
@@ -477,3 +477,32 @@ tracker_util_parse_dbus_uri (const gchar  *uri,
 
        return TRUE;
 }
+
+gchar *
+tracker_util_build_dbus_uri (GBusType     bus_type,
+                             const gchar *service,
+                             const gchar *path)
+{
+       GString *str;
+
+       if (!g_dbus_is_name (service))
+               return NULL;
+       if (path && path[0] != '/')
+               return NULL;
+
+       if (bus_type == G_BUS_TYPE_SESSION)
+               str = g_string_new ("dbus:");
+       else if (bus_type == G_BUS_TYPE_SYSTEM)
+               str = g_string_new ("dbus:system:");
+       else
+               return NULL;
+
+       g_string_append (str, service);
+
+       if (path) {
+               g_string_append_c (str, ':');
+               g_string_append (str, path);
+       }
+
+       return g_string_free (str, FALSE);
+}
diff --git a/src/libtracker-common/tracker-utils.h b/src/libtracker-common/tracker-utils.h
index 28ccee621..0b27b1643 100644
--- a/src/libtracker-common/tracker-utils.h
+++ b/src/libtracker-common/tracker-utils.h
@@ -54,6 +54,9 @@ gboolean tracker_util_parse_dbus_uri        (const gchar  *uri,
                                              GBusType     *bus_type,
                                              gchar       **service,
                                              gchar       **path);
+gchar * tracker_util_build_dbus_uri         (GBusType      bus_type,
+                                             const gchar  *service,
+                                             const gchar  *path);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]