[tracker/wip/carlosg/sparql1.1: 112/145] libtracker-data: Prepare tracker_generate_uuid() to handle different prefixes
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql1.1: 112/145] libtracker-data: Prepare tracker_generate_uuid() to handle different prefixes
- Date: Thu, 18 Jul 2019 22:33:27 +0000 (UTC)
commit 8bff14884ddd91966bc89eaac2790042e7cbe298
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jul 7 19:27:42 2019 +0200
libtracker-data: Prepare tracker_generate_uuid() to handle different prefixes
src/libtracker-data/tracker-db-interface-sqlite.c | 2 +-
src/libtracker-data/tracker-uuid.c | 20 ++++++++++++++------
src/libtracker-data/tracker-uuid.h | 2 +-
3 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index b133b94ff..328024f51 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1752,7 +1752,7 @@ function_sparql_uuid (sqlite3_context *context,
do {
g_clear_pointer (&uuid, g_free);
- uuid = tracker_generate_uuid ();
+ uuid = tracker_generate_uuid ("urn:uuid");
sqlite3_reset (stmt);
sqlite3_bind_text (stmt, 1, uuid, -1, SQLITE_TRANSIENT);
diff --git a/src/libtracker-data/tracker-uuid.c b/src/libtracker-data/tracker-uuid.c
index e7962bcfd..f2b18967a 100644
--- a/src/libtracker-data/tracker-uuid.c
+++ b/src/libtracker-data/tracker-uuid.c
@@ -21,26 +21,34 @@
#include "config.h"
#include "tracker-uuid.h"
+#define DEFAULT_PREFIX "urn:uuid"
+
#if ! GLIB_CHECK_VERSION (2, 52, 0)
#include <uuid/uuid.h>
#endif
gchar *
-tracker_generate_uuid (void)
+tracker_generate_uuid (const gchar *uri_prefix)
{
gchar *result;
#if GLIB_CHECK_VERSION (2, 52, 0)
- gchar *uuid = g_uuid_string_random ();
- result = g_strdup_printf ("urn:uuid:%s", uuid);
- g_free (uuid);
+ result = g_uuid_string_random ();
#else
uuid_t base = { 0, };
gchar uuid[37];
uuid_generate (base);
uuid_unparse_lower (base, uuid);
- result = g_strdup_printf ("urn:uuid:%s", uuid);
+ result = g_strdup_printf (uuid);
#endif
- return result;
+ if (uri_prefix) {
+ gchar *uri;
+
+ uri = g_strdup_printf ("%s:%s", uri_prefix, result);
+ g_free (result);
+ return uri;
+ } else {
+ return result;
+ }
}
diff --git a/src/libtracker-data/tracker-uuid.h b/src/libtracker-data/tracker-uuid.h
index 744171e32..0393b7a5f 100644
--- a/src/libtracker-data/tracker-uuid.h
+++ b/src/libtracker-data/tracker-uuid.h
@@ -23,6 +23,6 @@
#include <glib.h>
-gchar * tracker_generate_uuid (void);
+gchar * tracker_generate_uuid (const gchar *uri_prefix);
#endif /* __TRACKER_UUID_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]