tracker r1241 - in trunk: . data src/trackerd



Author: mr
Date: Thu Mar 27 09:41:29 2008
New Revision: 1241
URL: http://svn.gnome.org/viewvc/tracker?rev=1241&view=rev

Log:
	* data/sqlite-stored-procs.sql:
	* src/trackerd/tracker-dbus-files.c:
	(tracker_dbus_method_files_get_text_contents): Implemented the
	GetTextContents method. This fixes bug #514553.


Modified:
   trunk/ChangeLog
   trunk/data/sqlite-stored-procs.sql
   trunk/src/trackerd/tracker-dbus-files.c

Modified: trunk/data/sqlite-stored-procs.sql
==============================================================================
--- trunk/data/sqlite-stored-procs.sql	(original)
+++ trunk/data/sqlite-stored-procs.sql	Thu Mar 27 09:41:29 2008
@@ -70,6 +70,7 @@
 DeleteContent DELETE FROM ServiceContents where ServiceID = ? and MetadataId = ?;
 DeleteAllContents DELETE FROM ServiceContents where ServiceID = ?;
 GetContents Select uncompress (Content) from ServiceContents where ServiceID = ? and MetadataID = ? and Content is not null;
+GetFileContents Select substr(uncompress (Content), ?, ?) from ServiceContents where ServiceID = ?;
 GetAllContents Select uncompress (Content) from ServiceContents where ServiceID = ? and Content is not null;
 
 GetKeywordList Select distinct K.MetaDataValue, count(*) as totalcount from Services S, ServiceKeywordMetaData K where K.ServiceID = S.ID AND (S.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = ? or Parent = ?)) AND  K.MetaDataId = 19 group by K.MetaDataValue order by totalcount desc, K.MetaDataValue asc;

Modified: trunk/src/trackerd/tracker-dbus-files.c
==============================================================================
--- trunk/src/trackerd/tracker-dbus-files.c	(original)
+++ trunk/src/trackerd/tracker-dbus-files.c	Thu Mar 27 09:41:29 2008
@@ -361,8 +361,10 @@
 {
 	DBConnection *db_con;
 	DBusError    dbus_error;
-	char	     *uri;
+	char	     *uri, *service_id;
 	int	     offset, max_length;
+	char 	     *str_offset, *str_max_length;
+	char 	     ***res;
 
 /*
 		<!-- Get the "File.Content" field for a file and allows you to specify the offset and amount of text to retrieve  -->
@@ -389,52 +391,62 @@
 		return;
 	}
 
-	if (uri) {
-		char *name, *path, *str_offset, *str_max_length;
-		char ***res;
-
-		if (uri[0] == G_DIR_SEPARATOR) {
-			name = g_path_get_basename (uri);
-			path = g_path_get_dirname (uri);
-		} else {
-			name = tracker_get_vfs_name (uri);
-			path = tracker_get_vfs_path (uri);
-		}
-
-		str_offset = tracker_int_to_str (offset);
-		str_max_length = tracker_int_to_str (max_length);
-
-		res = tracker_exec_proc (db_con, "GetFileContents", 4, path, name, str_offset, str_max_length);
-
-		g_free (str_offset);
-		g_free (str_max_length);
-		g_free (path);
-		g_free (name);
-
-		if (res) {
-			char **row;
-
-			row = tracker_db_get_row (res, 0);
+	if (!uri) {
+		tracker_set_error (rec, "No uri was specified");
+		return;
+	}
 
-			if (row && row[0]) {
-				DBusMessage *reply;
-				const char  *result;
+	if (offset < 0) {
+		tracker_set_error (rec, "Offset must be positive");
+		return;
+	}
 
-				result = row[0];
+	if (max_length < 0) {
+		tracker_set_error (rec, "Length of content must be positive");
+		return;
+	}
 
-				reply = dbus_message_new_method_return (rec->message);
 
-				dbus_message_append_args (reply,
-							  DBUS_TYPE_STRING, &result,
-							  DBUS_TYPE_INVALID);
+	service_id = tracker_db_get_id (db_con, "Files", uri);
 
-				dbus_connection_send (rec->connection, reply, NULL);
-				dbus_message_unref (reply);
-			}
+	if (!service_id) {
+		service_id = tracker_db_get_id (db_con, "Emails", uri);
+	}
 
-			tracker_db_free_result (res);
-		}
+	if (!service_id) {
+		g_free (service_id);
+		tracker_set_error (rec, "Unable to retrieve serviceID for uri %s", uri);
+		return;		
+	} 
+	
+	str_offset = tracker_int_to_str (offset);
+	str_max_length = tracker_int_to_str (max_length);
+	res = tracker_exec_proc (db_con->blob, "GetFileContents", 
+				 3, str_offset, str_max_length, service_id);
+	g_free (str_offset);
+	g_free (str_max_length);
+	g_free (service_id);
+
+	const gchar *txt;
+
+	if (res && res[0][0]) {
+		txt = res[0][0];
+
+		DBusMessage *reply;
+
+		reply = dbus_message_new_method_return (rec->message);
+
+		dbus_message_append_args (reply,
+					  DBUS_TYPE_STRING, &txt,
+					  DBUS_TYPE_INVALID);
+
+		dbus_connection_send (rec->connection, reply, NULL);
+		dbus_message_unref (reply);
+		tracker_db_free_result (res);		
+	} else {
+		tracker_set_error (rec, "Contents of the URI not stored");
 	}
+	
 }
 
 



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