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



commit 812125518d1c8e919ffa60141fa8e75b4fe6b63b
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Nov 24 14:59:08 2010 +0100

    libtracker-sparql: Added a function to generate a uuid urn to the client library
    
    Fixes NB#202291

 configure.ac                             |    3 ++-
 src/libtracker-sparql/tracker-utils.vala |   25 +++++++++++++++++++++++++
 tests/libtracker-extract/Makefile.am     |    1 +
 3 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d6d20fa..c13d3bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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])
 
diff --git a/src/libtracker-sparql/tracker-utils.vala b/src/libtracker-sparql/tracker-utils.vala
index 78fbd39..41251aa 100644
--- a/src/libtracker-sparql/tracker-utils.vala
+++ b/src/libtracker-sparql/tracker-utils.vala
@@ -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));
+	}
 }
diff --git a/tests/libtracker-extract/Makefile.am b/tests/libtracker-extract/Makefile.am
index ec12cda..25b81c4 100644
--- a/tests/libtracker-extract/Makefile.am
+++ b/tests/libtracker-extract/Makefile.am
@@ -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)
 



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