Commit 81212551 authored by Philip Van Hoof's avatar Philip Van Hoof

libtracker-sparql: Added a function to generate a uuid urn to the client library

Fixes NB#202291
parent 6ced7e64
......@@ -271,7 +271,8 @@ PKG_CHECK_MODULES(LIBTRACKER_MINER, [$LIBTRACKER_MINER_REQUIRED])
# Check requirements for libtracker-sparql
LIBTRACKER_SPARQL_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
gio-unix-2.0 >= $GLIB_REQUIRED"
gio-unix-2.0 >= $GLIB_REQUIRED
uuid"
PKG_CHECK_MODULES(LIBTRACKER_SPARQL, [$LIBTRACKER_SPARQL_REQUIRED])
......
......@@ -85,4 +85,29 @@ namespace Tracker.Sparql {
return str.str;
}
[CCode (cname = "uuid_generate")]
public extern static void uuid_generate ([CCode (array_length = false)] uchar[] uuid);
public string get_uuid_urn (string user_bnodeid) {
var checksum = new Checksum (ChecksumType.SHA1);
uchar[] base_uuid = new uchar[16];
uuid_generate (base_uuid);
// base UUID, unique per file
checksum.update (base_uuid, 16);
// node ID
checksum.update ((uchar[]) user_bnodeid, -1);
string sha1 = checksum.get_string ();
// generate name based uuid
return "urn:uuid:%.8s-%.4s-%.4s-%.4s-%.12s".printf (sha1,
sha1.offset (8),
sha1.offset (12),
sha1.offset (16),
sha1.offset (20));
}
}
......@@ -17,6 +17,7 @@ LDADD = \
$(top_builddir)/tests/common/libtracker-testcommon.la \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
$(top_builddir)/src/libtracker-extract/libtracker-extract-@TRACKER_API_VERSION@.la \
$(top_builddir)/src/libtracker-sparql/libtracker-sparql-@TRACKER_API_VERSION@.la \
$(BUILD_LIBS) \
$(LIBTRACKER_EXTRACT_LIBS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment