tracker r2726 - in trunk: . src/tracker-extract src/tracker-indexer



Author: carlosg
Date: Wed Dec 17 15:57:57 2008
New Revision: 2726
URL: http://svn.gnome.org/viewvc/tracker?rev=2726&view=rev

Log:
2008-12-17  Carlos Garnacho  <carlos imendio com>

        * src/tracker-extract/tracker-extract.c (print_meta_table_data):
        Escapemetadata values so we allow multiline data and other stuff.
        * src/tracker-indexer/tracker-module-metadata-utils.c
        (metadata_utils_get_embedded): And compress it back here.

Modified:
   trunk/ChangeLog
   trunk/src/tracker-extract/tracker-extract.c
   trunk/src/tracker-indexer/tracker-module-metadata-utils.c

Modified: trunk/src/tracker-extract/tracker-extract.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract.c	(original)
+++ trunk/src/tracker-extract/tracker-extract.c	Wed Dec 17 15:57:57 2008
@@ -256,7 +256,7 @@
 		       gpointer value,
 		       gpointer user_data)
 {
-	gchar *value_utf8;
+	gchar *value_utf8, *value_escaped;
 
 	g_return_if_fail (key != NULL);
 	g_return_if_fail (value != NULL);
@@ -264,18 +264,21 @@
 	value_utf8 = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
 
 	if (value_utf8) {
+		value_escaped = g_strescape (value_utf8, NULL);
+
 		/* Replace any embedded semicolons or "=" as we use them for delimiters */
-		value_utf8 = g_strdelimit (value_utf8, ";", ',');
-		value_utf8 = g_strdelimit (value_utf8, "=", '-');
-		value_utf8 = g_strstrip (value_utf8);
-		
+		value_escaped = g_strdelimit (value_escaped, ";", ',');
+		value_escaped = g_strdelimit (value_escaped, "=", '-');
+		value_escaped = g_strstrip (value_escaped);
+
 		debug ("Extractor - Found '%s' = '%s'",
 		       (gchar*) key,
 		       value_utf8);
-		
-		g_print ("%s=%s;\n", (gchar*) key, value_utf8);
-		
+
+		g_print ("%s=%s;\n", (gchar*) key, value_escaped);
+
 		g_free (value_utf8);
+		g_free (value_escaped);
 	}
 }
 
@@ -376,22 +379,16 @@
 
 	/* Translators: this message will appear after the usage string */
 	/* and before the list of options.				*/
-	summary = g_strconcat (_("Given the following format (without quotes):"),
-			       "\n",
-			       "\n",
-			       "  '[filename]\\n[mime-type]'\n",
-			       "\n",
-			       _("This is interpreted from STDIN and then processed."),
-			       "\n",
+	summary = g_strconcat (_("This command works two ways:"),
 			       "\n",
-			       _("If this command is run without any arguments, "
-				 "it will wait for work to do."),
 			       "\n",
+			       _(" - Passing arguments:"),
 			       "\n",
-			       _("Here are some examples of how to use this command:"),
+			       "     tracker-extract [filename] [mime-type]\n",
 			       "\n",
+			       _(" - Reading filename/mime-type pairs from STDIN"),
 			       "\n",
-			       "  echo -e \"/home/foo/bar/baz.mp3\\naudio/x-mpeg\" | tracker-extract",
+			       "     echo -e \"/home/foo/bar/baz.mp3\\naudio/x-mpeg\" | tracker-extract",
 			       NULL);
 
 	g_option_context_set_summary (context, summary);

Modified: trunk/src/tracker-indexer/tracker-module-metadata-utils.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-module-metadata-utils.c	(original)
+++ trunk/src/tracker-indexer/tracker-module-metadata-utils.c	Wed Dec 17 15:57:57 2008
@@ -352,8 +352,8 @@
 	/* parse returned values and extract keys and associated metadata */
 	for (i = 0; values[i]; i++) {
 		gchar *meta_data, *sep;
-		const gchar *name, *value;
-		gchar *utf_value;
+		const gchar *name;
+		gchar *value, *utf_value;
 
 		meta_data = values[i];
 		sep = strchr (meta_data, '=');
@@ -366,18 +366,21 @@
 		 */
 		sep[0] = '\0';
 		name = meta_data;
-		value = sep + 1;
+		value = g_strcompress (sep + 1);
 
-		if (!name || !value)
+		if (!name || !value) {
+			g_free (value);
 			continue;
-		
+		}
+
 		field = tracker_ontology_get_field_by_name (name);
 
 		if (!field) {
 			g_warning ("Field name '%s' isn't described in the ontology", name);
+			g_free (value);
 			continue;
 		}
-		
+
 		if (tracker_field_get_multiple_values (field)) {
 			GStrv arr;
 			guint i;
@@ -391,11 +394,10 @@
 					utf_value = g_strdup (arr[i]);
 				}
 
-				if (!utf_value)
-					continue;
-
-				tracker_module_metadata_add_string (metadata, name, utf_value);
-				g_free (utf_value);
+				if (utf_value) {
+					tracker_module_metadata_add_string (metadata, name, utf_value);
+					g_free (utf_value);
+				}
 			}
 
 			g_strfreev (arr);
@@ -406,13 +408,13 @@
 				utf_value = g_strdup (value);
 			}
 
-			if (!utf_value) {
-				continue;
+			if (utf_value) {
+				tracker_module_metadata_add_string (metadata, name, utf_value);
+				g_free (utf_value);
 			}
-
-			tracker_module_metadata_add_string (metadata, name, utf_value);
-			g_free (utf_value);
 		}
+
+		g_free (value);
 	}
 
 	g_strfreev (values);



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