[packagekit] packagekit: Branch 'master' - 12 commits

Richard Hughes hughsient at kemper.freedesktop.org
Wed Oct 31 14:31:31 PDT 2007


 backends/pisi/pk-backend-pisi.c |    2 
 client/pk-console.c             |   46 ----
 libpackagekit/pk-common.c       |  389 ++++++++++++++++++++++++++++++++++------
 libpackagekit/pk-common.h       |   22 +-
 libpackagekit/pk-package-id.c   |   33 ++-
 python/packagekit/backend.py    |   18 +
 src/pk-backend.c                |    6 
 src/pk-engine.c                 |   31 +--
 src/pk-spawn.c                  |    3 
 src/pk-transaction-id.c         |    2 
 10 files changed, 424 insertions(+), 128 deletions(-)

New commits:
commit dc256adcb68c9ec73ef0f18dec8c540f5fbbee79
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 21:30:31 2007 +0000

    abstract the strpad stuff better

diff --git a/client/pk-console.c b/client/pk-console.c
index 226a966..e5e546c 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -68,17 +68,17 @@ pk_console_package_cb (PkClient *client, PkInfoEnum info, const gchar *package_i
 	}
 
 	/* pass this out */
-	info_text = pk_strpad (pk_info_enum_to_text (info), 12, NULL);
+	info_text = pk_strpad (pk_info_enum_to_text (info), 12);
 
 	spacing = pk_package_id_new ();
 	ident = pk_package_id_new_from_string (package_id);
 
 	/* these numbers are guesses */
 	extra = 0;
-	spacing->name = pk_strpad (ident->name, 20, &extra);
-	spacing->arch = pk_strpad (ident->arch, 7-extra, &extra);
-	spacing->version = pk_strpad (ident->version, 15-extra, &extra);
-	spacing->data = pk_strpad (ident->data, 12-extra, &extra);
+	spacing->name = pk_strpad_extra (ident->name, 20, &extra);
+	spacing->arch = pk_strpad_extra (ident->arch, 7, &extra);
+	spacing->version = pk_strpad_extra (ident->version, 15, &extra);
+	spacing->data = pk_strpad_extra (ident->data, 12, &extra);
 
 	/* pretty print */
 	g_print ("%s %s %s %s %s %s\n", info_text, spacing->name,
@@ -137,7 +137,7 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 			   const gchar *description, gboolean enabled, gpointer data)
 {
 	gchar *repo;
-	repo = pk_strpad (repo_id, 28, NULL);
+	repo = pk_strpad (repo_id, 28);
 	if (enabled == TRUE) {
 		g_print ("  enabled   %s %s\n", repo, description);
 	} else {
diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 2f7c2be..25fb20b 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -333,38 +333,61 @@ out:
  * pk_strpad:
  * @data: the input string
  * @length: the desired length of the output string, with padding
- * @extra: if we are running with a deficit, we might have a positive offset
  **/
 gchar *
-pk_strpad (const gchar *data, guint length, guint *extra)
+pk_strpad (const gchar *data, guint length)
 {
 	gint size;
 	gchar *text;
 	gchar *padding;
 
-	if (extra != NULL) {
-		*extra = 0;
-	}
-	size = length;
-	if (data != NULL) {
-		/* ITS4: ignore, only used for formatting */
-		size = (length - strlen(data));
-		if (size < 0) {
-			if (extra != NULL) {
-				*extra = -size;
-			}
-			size = 0;
-		}
-	}
-	padding = g_strnfill (size, ' ');
 	if (data == NULL) {
-		return padding;
+		return g_strnfill (length, ' ');
+	}
+
+	/* ITS4: ignore, only used for formatting */
+	size = (length - strlen(data));
+	if (size <= 0) {
+		return g_strdup (data);
 	}
+
+	padding = g_strnfill (size, ' ');
 	text = g_strdup_printf ("%s%s", data, padding);
 	g_free (padding);
 	return text;
 }
 
+/**
+ * pk_strpad_extra:
+ * @data: the input string
+ * @length: the desired length of the output string, with padding
+ * @extra: if we are running with a deficit, we might have a positive offset
+ **/
+gchar *
+pk_strpad_extra (const gchar *data, guint length, guint *extra)
+{
+	gint size;
+	gchar *text;
+
+	/* can we just do the simple version? */
+	if (data == NULL || extra == NULL) {
+		return pk_strpad (data, length);
+	}
+
+	/* work out what we want to do */
+	size = length - *extra;
+
+	if (size < 0) {
+		size = 0;
+	}
+
+	/* do the padding */
+	text = pk_strpad (data, size);
+	*extra = strlen (text) - size;
+
+	return text;
+}
+
 /***************************************************************************
  ***                          MAKE CHECK TESTS                           ***
  ***************************************************************************/
@@ -754,7 +777,102 @@ libst_common (LibSelfTest *test)
 	}
 	g_free (text_safe);
 
+	/************************************************************
+	 ****************         Padding          ******************
+	 ************************************************************/
+	libst_title (test, "pad smaller");
+	text_safe = pk_strpad ("richard", 10);
+	if (pk_strequal (text_safe, "richard   ") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s'", text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "pad NULL");
+	text_safe = pk_strpad (NULL, 10);
+	if (pk_strequal (text_safe, "          ") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s'", text_safe);
+	}
+	g_free (text_safe);
+
 	/************************************************************/
+	libst_title (test, "pad nothing");
+	text_safe = pk_strpad ("", 10);
+	if (pk_strequal (text_safe, "          ") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s'", text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "pad over");
+	text_safe = pk_strpad ("richardhughes", 10);
+	if (pk_strequal (text_safe, "richardhughes") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s'", text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "pad zero");
+	text_safe = pk_strpad ("rich", 0);
+	if (pk_strequal (text_safe, "rich") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s'", text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************
+	 ****************         Padding          ******************
+	 ************************************************************/
+	libst_title (test, "pad smaller, no extra");
+	length = 0;
+	text_safe = pk_strpad_extra ("richard", 10, &length);
+	if (length == 0 && pk_strequal (text_safe, "richard   ") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s', extra %i", text_safe, length);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "pad over, no extra");
+	length = 0;
+	text_safe = pk_strpad_extra ("richardhughes", 10, &length);
+	if (length == 3 && pk_strequal (text_safe, "richardhughes") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s', extra %i", text_safe, length);
+	}
+
+	/************************************************************/
+	g_free (text_safe);
+	libst_title (test, "pad smaller, 1 extra");
+	length = 1;
+	text_safe = pk_strpad_extra ("richard", 10, &length);
+	if (length == 0 && pk_strequal (text_safe, "richard  ") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s', extra %i", text_safe, length);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "pad over, 1 extra");
+	length = 1;
+	text_safe = pk_strpad_extra ("richardhughes", 10, &length);
+	if (length == 4 && pk_strequal (text_safe, "richardhughes") == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the padd '%s', extra %i", text_safe, length);
+	}
 
 	/************************************************************
 	 ****************       REPLACE CHARS      ******************
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 1c2a0fe..36e9d66 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -37,6 +37,8 @@ gboolean	 pk_strvalidate				(const gchar	*text);
 gboolean	 pk_strequal				(const gchar	*id1,
 							 const gchar	*id2);
 gchar		*pk_strpad				(const gchar	*data,
+							 guint		 length);
+gchar		*pk_strpad_extra			(const gchar	*data,
 							 guint		 length,
 							 guint		*extra);
 gchar		*pk_strsafe				(const gchar	*text);
commit 9a04fd4bf5d89323e37a5f4aaf282338b56f1c4d
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 20:24:25 2007 +0000

    add pk_strpad for the padding. initial version. untested

diff --git a/client/pk-console.c b/client/pk-console.c
index b4d032f..226a966 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -34,6 +34,7 @@
 #include <pk-client.h>
 #include <pk-package-id.h>
 #include <pk-enum-list.h>
+#include <pk-common.h>
 #include <pk-connection.h>
 
 #define PROGRESS_BAR_PADDING 22
@@ -51,39 +52,6 @@ typedef struct {
 } PulseState;
 
 /**
- * pk_console_pad_string:
- **/
-static gchar *
-pk_console_pad_string (const gchar *data, guint length, guint *extra)
-{
-	gint size;
-	gchar *text;
-	gchar *padding;
-
-	if (extra != NULL) {
-		*extra = 0;
-	}
-	size = length;
-	if (data != NULL) {
-		/* ITS4: ignore, only used for formatting */
-		size = (length - strlen(data));
-		if (size < 0) {
-			if (extra != NULL) {
-				*extra = -size;
-			}
-			size = 0;
-		}
-	}
-	padding = g_strnfill (size, ' ');
-	if (data == NULL) {
-		return padding;
-	}
-	text = g_strdup_printf ("%s%s", data, padding);
-	g_free (padding);
-	return text;
-}
-
-/**
  * pk_console_package_cb:
  **/
 static void
@@ -100,17 +68,17 @@ pk_console_package_cb (PkClient *client, PkInfoEnum info, const gchar *package_i
 	}
 
 	/* pass this out */
-	info_text = pk_console_pad_string (pk_info_enum_to_text (info), 12, NULL);
+	info_text = pk_strpad (pk_info_enum_to_text (info), 12, NULL);
 
 	spacing = pk_package_id_new ();
 	ident = pk_package_id_new_from_string (package_id);
 
 	/* these numbers are guesses */
 	extra = 0;
-	spacing->name = pk_console_pad_string (ident->name, 20, &extra);
-	spacing->arch = pk_console_pad_string (ident->arch, 7-extra, &extra);
-	spacing->version = pk_console_pad_string (ident->version, 15-extra, &extra);
-	spacing->data = pk_console_pad_string (ident->data, 12-extra, &extra);
+	spacing->name = pk_strpad (ident->name, 20, &extra);
+	spacing->arch = pk_strpad (ident->arch, 7-extra, &extra);
+	spacing->version = pk_strpad (ident->version, 15-extra, &extra);
+	spacing->data = pk_strpad (ident->data, 12-extra, &extra);
 
 	/* pretty print */
 	g_print ("%s %s %s %s %s %s\n", info_text, spacing->name,
@@ -169,7 +137,7 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 			   const gchar *description, gboolean enabled, gpointer data)
 {
 	gchar *repo;
-	repo = pk_console_pad_string (repo_id, 28, NULL);
+	repo = pk_strpad (repo_id, 28, NULL);
 	if (enabled == TRUE) {
 		g_print ("  enabled   %s %s\n", repo, description);
 	} else {
diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index c116c38..2f7c2be 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -329,6 +329,42 @@ out:
 	return ret;
 }
 
+/**
+ * pk_strpad:
+ * @data: the input string
+ * @length: the desired length of the output string, with padding
+ * @extra: if we are running with a deficit, we might have a positive offset
+ **/
+gchar *
+pk_strpad (const gchar *data, guint length, guint *extra)
+{
+	gint size;
+	gchar *text;
+	gchar *padding;
+
+	if (extra != NULL) {
+		*extra = 0;
+	}
+	size = length;
+	if (data != NULL) {
+		/* ITS4: ignore, only used for formatting */
+		size = (length - strlen(data));
+		if (size < 0) {
+			if (extra != NULL) {
+				*extra = -size;
+			}
+			size = 0;
+		}
+	}
+	padding = g_strnfill (size, ' ');
+	if (data == NULL) {
+		return padding;
+	}
+	text = g_strdup_printf ("%s%s", data, padding);
+	g_free (padding);
+	return text;
+}
+
 /***************************************************************************
  ***                          MAKE CHECK TESTS                           ***
  ***************************************************************************/
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 179ff92..1c2a0fe 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -36,6 +36,9 @@ gboolean	 pk_strzero				(const gchar	*text);
 gboolean	 pk_strvalidate				(const gchar	*text);
 gboolean	 pk_strequal				(const gchar	*id1,
 							 const gchar	*id2);
+gchar		*pk_strpad				(const gchar	*data,
+							 guint		 length,
+							 guint		*extra);
 gchar		*pk_strsafe				(const gchar	*text);
 gchar		**pk_strsplit				(const gchar	*id,
 							 guint		 parts);
commit 4c34e0d8c14128b973104f604f8b4cc9d860b5a0
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 19:38:59 2007 +0000

    Revert "split pkcon into a main and class so that we can add self test functionality"
    
    This reverts commit bddb769d6cc0e63b7e7b41f76a07fa517af91acb.
    
    I've changed my mind. This can be abstracted into libpackagekit.

diff --git a/client/.gitignore b/client/.gitignore
index 53a091d..da99461 100644
--- a/client/.gitignore
+++ b/client/.gitignore
@@ -5,7 +5,6 @@ pk-marshal.h
 pk-marshal.c
 pkcon
 pkmon
-pk-self-test
 pk-update-icon
 pk-application
 *.glade.bak
diff --git a/client/Makefile.am b/client/Makefile.am
index d9aacc8..57fb4ed 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -14,11 +14,6 @@ INCLUDES =						\
 	-DVERSION="\"$(VERSION)\"" 			\
 	-DPK_DATA=\"$(pkgdatadir)\"			\
 	-I$(top_srcdir)/libpackagekit			\
-	-I$(top_srcdir)/libselftest			\
-	$(NULL)
-
-SELFTEST_LIBS =						\
-	$(top_builddir)/libselftest/libselftest.la	\
 	$(NULL)
 
 PK_LIBS =						\
@@ -31,9 +26,7 @@ bin_PROGRAMS =						\
 	$(NULL)
 
 pkcon_SOURCES =						\
-	pk-console.h					\
 	pk-console.c					\
-	pk-console-main.c				\
 	$(NULL)
 
 pkcon_LDADD =						\
@@ -52,35 +45,11 @@ pkmon_LDADD =						\
 	$(PK_LIBS)					\
 	$(NULL)
 
-check_PROGRAMS =					\
-	pk-self-test
-
-noinst_PROGRAMS =					\
-	pk-self-test
-
-pk_self_test_SOURCES =					\
-	pk-console.h					\
-	pk-console.c					\
-	pk-self-test.c					\
-	$(NULL)
-
-pk_self_test_LDADD =					\
-	$(GLIB_LIBS)					\
-	$(DBUS_LIBS)					\
-	$(SELFTEST_LIBS)				\
-	$(PK_LIBS)					\
-	$(NULL)
-
-pk_self_test_CPPFLAGS=	\
-	-DPK_BUILD_TESTS
-
 clean-local:
 	rm -f *~
 
 CLEANFILES = $(BUILT_SOURCES)
 
-TESTS = pk-self-test
-
 DISTCLEANFILES =					\
 	$(NULL)
 
diff --git a/client/pk-console-main.c b/client/pk-console-main.c
deleted file mode 100644
index 484ea17..0000000
--- a/client/pk-console-main.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-
-#include "pk-console.h"
-
-const gchar *summary =
-	"PackageKit Console Interface\n"
-	"\n"
-	"Subcommands:\n"
-	"  search name|details|group|file data\n"
-	"  install <package_id>\n"
-	"  install-file <file>\n"
-	"  remove <package_id>\n"
-	"  update <package_id>\n"
-	"  refresh\n"
-	"  resolve\n"
-	"  force-refresh\n"
-	"  update-system\n"
-	"  get updates\n"
-	"  get depends <package_id>\n"
-	"  get requires <package_id>\n"
-	"  get description <package_id>\n"
-	"  get files <package_id>\n"
-	"  get updatedetail <package_id>\n"
-	"  get actions\n"
-	"  get groups\n"
-	"  get filters\n"
-	"  get transactions\n"
-	"  get repos\n"
-	"  enable-repo <repo_id>\n"
-	"  disable-repo <repo_id>\n"
-	"  set-repo-data <repo_id> <parameter> <value>\n"
-	"\n"
-	"  package_id is typically gimp;2:2.4.0-0.rc1.1.fc8;i386;development";
-
-/**
- * main:
- **/
-int
-main (int argc, char *argv[])
-{
-	GError *error = NULL;
-	gboolean verbose = FALSE;
-	gboolean program_version = FALSE;
-	gboolean nowait = FALSE;
-	GOptionContext *context;
-	gchar *options_help;
-
-	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-			"Show extra debugging information", NULL },
-		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
-			"Show the program version and exit", NULL},
-		{ "nowait", 'n', 0, G_OPTION_ARG_NONE, &nowait,
-			"Exit without waiting for actions to complete", NULL},
-		{ NULL}
-	};
-
-	if (! g_thread_supported ()) {
-		g_thread_init (NULL);
-	}
-	dbus_g_thread_init ();
-	g_type_init ();
-
-	context = g_option_context_new (_("SUBCOMMAND"));
-	g_option_context_set_summary (context, summary) ;
-	g_option_context_add_main_entries (context, options, NULL);
-	g_option_context_parse (context, &argc, &argv, NULL);
-	/* Save the usage string in case command parsing fails. */
-	options_help = g_option_context_get_help (context, TRUE, NULL);
-	g_option_context_free (context);
-
-	if (program_version == TRUE) {
-		g_print (VERSION "\n");
-		return 0;
-	}
-
-	if (argc < 2) {
-		g_print (options_help);
-		return 1;
-	}
-
-	/* run the commands */
-	pk_console_run (argc, argv, !nowait, &error);
-	if (error != NULL) {
-		g_print ("Error:\n  %s\n\n", error->message);
-		g_error_free (error);
-		g_print (options_help);
-	}
-
-	g_free (options_help);
-	return 0;
-}
-
diff --git a/client/pk-console.c b/client/pk-console.c
index 704e658..b4d032f 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -31,7 +31,6 @@
 #include <dbus/dbus-glib.h>
 
 #include <pk-debug.h>
-#include <pk-common.h>
 #include <pk-client.h>
 #include <pk-package-id.h>
 #include <pk-enum-list.h>
@@ -52,22 +51,6 @@ typedef struct {
 } PulseState;
 
 /**
- * pk_console_get_terminal_columns:
- **/
-static guint
-pk_console_get_terminal_columns (void)
-{
-	struct winsize ws;
-
-	ioctl (1, TIOCGWINSZ, &ws);
-	if (ws.ws_col < MINIMUM_COLUMNS) {
-		return MINIMUM_COLUMNS;
-	}
-
-	return ws.ws_col;
-}
-
-/**
  * pk_console_pad_string:
  **/
 static gchar *
@@ -76,14 +59,7 @@ pk_console_pad_string (const gchar *data, guint length, guint *extra)
 	gint size;
 	gchar *text;
 	gchar *padding;
-	guint console_size;
-	console_size = pk_console_get_terminal_columns ();
 
-	/* don't span a small console */
-	if (length > console_size) {
-	        pk_debug ("reducing padding from %i to %i", length, console_size);
-	        length = console_size;
-	}
 	if (extra != NULL) {
 		*extra = 0;
 	}
@@ -100,7 +76,6 @@ pk_console_pad_string (const gchar *data, guint length, guint *extra)
 	}
 	padding = g_strnfill (size, ' ');
 	if (data == NULL) {
-		*extra = 0;
 		return padding;
 	}
 	text = g_strdup_printf ("%s%s", data, padding);
@@ -204,6 +179,22 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 }
 
 /**
+ * pk_console_get_terminal_columns:
+ **/
+static guint
+pk_console_get_terminal_columns (void)
+{
+	struct winsize ws;
+
+	ioctl (1, TIOCGWINSZ, &ws);
+	if (ws.ws_col < MINIMUM_COLUMNS) {
+		return MINIMUM_COLUMNS;
+	}
+
+	return ws.ws_col;
+}
+
+/**
  * pk_console_draw_progress_bar:
  **/
 static void
@@ -342,6 +333,36 @@ pk_console_progress_changed_cb (PkClient *client, guint percentage, guint subper
 	}
 }
 
+const gchar *summary =
+	"PackageKit Console Interface\n"
+	"\n"
+	"Subcommands:\n"
+	"  search name|details|group|file data\n"
+	"  install <package_id>\n"
+	"  install-file <file>\n"
+	"  remove <package_id>\n"
+	"  update <package_id>\n"
+	"  refresh\n"
+	"  resolve\n"
+	"  force-refresh\n"
+	"  update-system\n"
+	"  get updates\n"
+	"  get depends <package_id>\n"
+	"  get requires <package_id>\n"
+	"  get description <package_id>\n"
+	"  get files <package_id>\n"
+	"  get updatedetail <package_id>\n"
+	"  get actions\n"
+	"  get groups\n"
+	"  get filters\n"
+	"  get transactions\n"
+	"  get repos\n"
+	"  enable-repo <repo_id>\n"
+	"  disable-repo <repo_id>\n"
+	"  set-repo-data <repo_id> <parameter> <value>\n"
+	"\n"
+	"  package_id is typically gimp;2:2.4.0-0.rc1.1.fc8;i386;development";
+
 /**
  * pk_client_wait:
  **/
@@ -874,19 +895,69 @@ pk_connection_changed_cb (PkConnection *pconnection, gboolean connected, gpointe
 }
 
 /**
- * pk_console_run:
+ * main:
  **/
-gboolean
-pk_console_run (int argc, char *argv[], gboolean wait_override, GError **error)
+int
+main (int argc, char *argv[])
 {
+	DBusGConnection *system_connection;
+	GError *error = NULL;
 	PkClient *client;
 	PkConnection *pconnection;
+	gboolean verbose = FALSE;
+	gboolean program_version = FALSE;
+	gboolean nowait = FALSE;
+	GOptionContext *context;
+	gchar *options_help;
+
+	const GOptionEntry options[] = {
+		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+			"Show extra debugging information", NULL },
+		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
+			"Show the program version and exit", NULL},
+		{ "nowait", 'n', 0, G_OPTION_ARG_NONE, &nowait,
+			"Exit without waiting for actions to complete", NULL},
+		{ NULL}
+	};
+
+	if (! g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
+	dbus_g_thread_init ();
+	g_type_init ();
 
 	/* check if we are on console */
 	if (isatty (fileno (stdout)) == 1) {
 		is_console = TRUE;
 	}
 
+	/* check dbus connections, exit if not valid */
+	system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (error) {
+		pk_warning ("%s", error->message);
+		g_error_free (error);
+		g_error ("This program cannot start until you start the dbus system service.");
+	}
+
+	context = g_option_context_new (_("SUBCOMMAND"));
+	g_option_context_set_summary (context, summary) ;
+	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	/* Save the usage string in case command parsing fails. */
+	options_help = g_option_context_get_help (context, TRUE, NULL);
+	g_option_context_free (context);
+
+	if (program_version == TRUE) {
+		g_print (VERSION "\n");
+		return 0;
+	}
+
+	if (argc < 2) {
+		g_print (options_help);
+		return 1;
+	}
+
+	pk_debug_init (verbose);
 	loop = g_main_loop_new (NULL, FALSE);
 
 	pconnection = pk_connection_new ();
@@ -916,39 +987,15 @@ pk_console_run (int argc, char *argv[], gboolean wait_override, GError **error)
 			  G_CALLBACK (pk_console_error_code_cb), NULL);
 
 	/* run the commands */
-	pk_console_process_commands (client, argc, argv, wait_override, error);
-	g_object_unref (client);
-	return TRUE;
-}
-
-
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef PK_BUILD_TESTS
-#include <libselftest.h>
-
-void
-libst_console (LibSelfTest *test)
-{
-	gchar *text;
-	guint extra = 0;
-
-	if (libst_start (test, "PkConsole", CLASS_AUTO) == FALSE) {
-		return;
+	pk_console_process_commands (client, argc, argv, !nowait, &error);
+	if (error != NULL) {
+		g_print ("Error:\n  %s\n\n", error->message);
+		g_error_free (error);
+		g_print (options_help);
 	}
 
-	/************************************************************/
-	libst_title (test, "pad small string");
-	text = pk_console_pad_string ("richard", 10, &extra);
-	if (pk_strequal (text, "richard   ") == TRUE && extra == 0) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "padded incorrectly '%s', extra %i", text, extra);
-	}
-	g_free (text);
+	g_free (options_help);
+	g_object_unref (client);
 
-	libst_end (test);
+	return 0;
 }
-#endif
-
diff --git a/client/pk-console.h b/client/pk-console.h
deleted file mode 100644
index dc97f15..0000000
--- a/client/pk-console.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __PK_CONSOLE_H
-#define __PK_CONSOLE_H
-
-#include <glib.h>
-
-gboolean	 pk_console_run			(int argc, char *argv[],
-						 gboolean	 wait_override,
-						 GError		**error);
-
-#endif /* __PK_CONSOLE_H */
diff --git a/client/pk-self-test.c b/client/pk-self-test.c
deleted file mode 100644
index cfbea19..0000000
--- a/client/pk-self-test.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <glib.h>
-#include <glib-object.h>
-#include <libselftest.h>
-#include <pk-debug.h>
-
-/* prototypes */
-void libst_console (LibSelfTest *test);
-
-int
-main (int argc, char **argv)
-{
-	LibSelfTest test;
-
-	if (! g_thread_supported ()) {
-		g_thread_init (NULL);
-	}
-	g_type_init ();
-	libst_init (&test);
-	pk_debug_init (TRUE);
-
-	/* tests go here */
-	libst_console (&test);
-
-	return (libst_finish (&test));
-}
-
commit bddb769d6cc0e63b7e7b41f76a07fa517af91acb
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 19:36:35 2007 +0000

    split pkcon into a main and class so that we can add self test functionality

diff --git a/client/.gitignore b/client/.gitignore
index da99461..53a091d 100644
--- a/client/.gitignore
+++ b/client/.gitignore
@@ -5,6 +5,7 @@ pk-marshal.h
 pk-marshal.c
 pkcon
 pkmon
+pk-self-test
 pk-update-icon
 pk-application
 *.glade.bak
diff --git a/client/Makefile.am b/client/Makefile.am
index 57fb4ed..d9aacc8 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -14,6 +14,11 @@ INCLUDES =						\
 	-DVERSION="\"$(VERSION)\"" 			\
 	-DPK_DATA=\"$(pkgdatadir)\"			\
 	-I$(top_srcdir)/libpackagekit			\
+	-I$(top_srcdir)/libselftest			\
+	$(NULL)
+
+SELFTEST_LIBS =						\
+	$(top_builddir)/libselftest/libselftest.la	\
 	$(NULL)
 
 PK_LIBS =						\
@@ -26,7 +31,9 @@ bin_PROGRAMS =						\
 	$(NULL)
 
 pkcon_SOURCES =						\
+	pk-console.h					\
 	pk-console.c					\
+	pk-console-main.c				\
 	$(NULL)
 
 pkcon_LDADD =						\
@@ -45,11 +52,35 @@ pkmon_LDADD =						\
 	$(PK_LIBS)					\
 	$(NULL)
 
+check_PROGRAMS =					\
+	pk-self-test
+
+noinst_PROGRAMS =					\
+	pk-self-test
+
+pk_self_test_SOURCES =					\
+	pk-console.h					\
+	pk-console.c					\
+	pk-self-test.c					\
+	$(NULL)
+
+pk_self_test_LDADD =					\
+	$(GLIB_LIBS)					\
+	$(DBUS_LIBS)					\
+	$(SELFTEST_LIBS)				\
+	$(PK_LIBS)					\
+	$(NULL)
+
+pk_self_test_CPPFLAGS=	\
+	-DPK_BUILD_TESTS
+
 clean-local:
 	rm -f *~
 
 CLEANFILES = $(BUILT_SOURCES)
 
+TESTS = pk-self-test
+
 DISTCLEANFILES =					\
 	$(NULL)
 
diff --git a/client/pk-console-main.c b/client/pk-console-main.c
new file mode 100644
index 0000000..484ea17
--- /dev/null
+++ b/client/pk-console-main.c
@@ -0,0 +1,123 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus-glib.h>
+
+#include "pk-console.h"
+
+const gchar *summary =
+	"PackageKit Console Interface\n"
+	"\n"
+	"Subcommands:\n"
+	"  search name|details|group|file data\n"
+	"  install <package_id>\n"
+	"  install-file <file>\n"
+	"  remove <package_id>\n"
+	"  update <package_id>\n"
+	"  refresh\n"
+	"  resolve\n"
+	"  force-refresh\n"
+	"  update-system\n"
+	"  get updates\n"
+	"  get depends <package_id>\n"
+	"  get requires <package_id>\n"
+	"  get description <package_id>\n"
+	"  get files <package_id>\n"
+	"  get updatedetail <package_id>\n"
+	"  get actions\n"
+	"  get groups\n"
+	"  get filters\n"
+	"  get transactions\n"
+	"  get repos\n"
+	"  enable-repo <repo_id>\n"
+	"  disable-repo <repo_id>\n"
+	"  set-repo-data <repo_id> <parameter> <value>\n"
+	"\n"
+	"  package_id is typically gimp;2:2.4.0-0.rc1.1.fc8;i386;development";
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+	GError *error = NULL;
+	gboolean verbose = FALSE;
+	gboolean program_version = FALSE;
+	gboolean nowait = FALSE;
+	GOptionContext *context;
+	gchar *options_help;
+
+	const GOptionEntry options[] = {
+		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+			"Show extra debugging information", NULL },
+		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
+			"Show the program version and exit", NULL},
+		{ "nowait", 'n', 0, G_OPTION_ARG_NONE, &nowait,
+			"Exit without waiting for actions to complete", NULL},
+		{ NULL}
+	};
+
+	if (! g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
+	dbus_g_thread_init ();
+	g_type_init ();
+
+	context = g_option_context_new (_("SUBCOMMAND"));
+	g_option_context_set_summary (context, summary) ;
+	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	/* Save the usage string in case command parsing fails. */
+	options_help = g_option_context_get_help (context, TRUE, NULL);
+	g_option_context_free (context);
+
+	if (program_version == TRUE) {
+		g_print (VERSION "\n");
+		return 0;
+	}
+
+	if (argc < 2) {
+		g_print (options_help);
+		return 1;
+	}
+
+	/* run the commands */
+	pk_console_run (argc, argv, !nowait, &error);
+	if (error != NULL) {
+		g_print ("Error:\n  %s\n\n", error->message);
+		g_error_free (error);
+		g_print (options_help);
+	}
+
+	g_free (options_help);
+	return 0;
+}
+
diff --git a/client/pk-console.c b/client/pk-console.c
index b4d032f..704e658 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -31,6 +31,7 @@
 #include <dbus/dbus-glib.h>
 
 #include <pk-debug.h>
+#include <pk-common.h>
 #include <pk-client.h>
 #include <pk-package-id.h>
 #include <pk-enum-list.h>
@@ -51,6 +52,22 @@ typedef struct {
 } PulseState;
 
 /**
+ * pk_console_get_terminal_columns:
+ **/
+static guint
+pk_console_get_terminal_columns (void)
+{
+	struct winsize ws;
+
+	ioctl (1, TIOCGWINSZ, &ws);
+	if (ws.ws_col < MINIMUM_COLUMNS) {
+		return MINIMUM_COLUMNS;
+	}
+
+	return ws.ws_col;
+}
+
+/**
  * pk_console_pad_string:
  **/
 static gchar *
@@ -59,7 +76,14 @@ pk_console_pad_string (const gchar *data, guint length, guint *extra)
 	gint size;
 	gchar *text;
 	gchar *padding;
+	guint console_size;
+	console_size = pk_console_get_terminal_columns ();
 
+	/* don't span a small console */
+	if (length > console_size) {
+	        pk_debug ("reducing padding from %i to %i", length, console_size);
+	        length = console_size;
+	}
 	if (extra != NULL) {
 		*extra = 0;
 	}
@@ -76,6 +100,7 @@ pk_console_pad_string (const gchar *data, guint length, guint *extra)
 	}
 	padding = g_strnfill (size, ' ');
 	if (data == NULL) {
+		*extra = 0;
 		return padding;
 	}
 	text = g_strdup_printf ("%s%s", data, padding);
@@ -179,22 +204,6 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
 }
 
 /**
- * pk_console_get_terminal_columns:
- **/
-static guint
-pk_console_get_terminal_columns (void)
-{
-	struct winsize ws;
-
-	ioctl (1, TIOCGWINSZ, &ws);
-	if (ws.ws_col < MINIMUM_COLUMNS) {
-		return MINIMUM_COLUMNS;
-	}
-
-	return ws.ws_col;
-}
-
-/**
  * pk_console_draw_progress_bar:
  **/
 static void
@@ -333,36 +342,6 @@ pk_console_progress_changed_cb (PkClient *client, guint percentage, guint subper
 	}
 }
 
-const gchar *summary =
-	"PackageKit Console Interface\n"
-	"\n"
-	"Subcommands:\n"
-	"  search name|details|group|file data\n"
-	"  install <package_id>\n"
-	"  install-file <file>\n"
-	"  remove <package_id>\n"
-	"  update <package_id>\n"
-	"  refresh\n"
-	"  resolve\n"
-	"  force-refresh\n"
-	"  update-system\n"
-	"  get updates\n"
-	"  get depends <package_id>\n"
-	"  get requires <package_id>\n"
-	"  get description <package_id>\n"
-	"  get files <package_id>\n"
-	"  get updatedetail <package_id>\n"
-	"  get actions\n"
-	"  get groups\n"
-	"  get filters\n"
-	"  get transactions\n"
-	"  get repos\n"
-	"  enable-repo <repo_id>\n"
-	"  disable-repo <repo_id>\n"
-	"  set-repo-data <repo_id> <parameter> <value>\n"
-	"\n"
-	"  package_id is typically gimp;2:2.4.0-0.rc1.1.fc8;i386;development";
-
 /**
  * pk_client_wait:
  **/
@@ -895,69 +874,19 @@ pk_connection_changed_cb (PkConnection *pconnection, gboolean connected, gpointe
 }
 
 /**
- * main:
+ * pk_console_run:
  **/
-int
-main (int argc, char *argv[])
+gboolean
+pk_console_run (int argc, char *argv[], gboolean wait_override, GError **error)
 {
-	DBusGConnection *system_connection;
-	GError *error = NULL;
 	PkClient *client;
 	PkConnection *pconnection;
-	gboolean verbose = FALSE;
-	gboolean program_version = FALSE;
-	gboolean nowait = FALSE;
-	GOptionContext *context;
-	gchar *options_help;
-
-	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-			"Show extra debugging information", NULL },
-		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
-			"Show the program version and exit", NULL},
-		{ "nowait", 'n', 0, G_OPTION_ARG_NONE, &nowait,
-			"Exit without waiting for actions to complete", NULL},
-		{ NULL}
-	};
-
-	if (! g_thread_supported ()) {
-		g_thread_init (NULL);
-	}
-	dbus_g_thread_init ();
-	g_type_init ();
 
 	/* check if we are on console */
 	if (isatty (fileno (stdout)) == 1) {
 		is_console = TRUE;
 	}
 
-	/* check dbus connections, exit if not valid */
-	system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
-	if (error) {
-		pk_warning ("%s", error->message);
-		g_error_free (error);
-		g_error ("This program cannot start until you start the dbus system service.");
-	}
-
-	context = g_option_context_new (_("SUBCOMMAND"));
-	g_option_context_set_summary (context, summary) ;
-	g_option_context_add_main_entries (context, options, NULL);
-	g_option_context_parse (context, &argc, &argv, NULL);
-	/* Save the usage string in case command parsing fails. */
-	options_help = g_option_context_get_help (context, TRUE, NULL);
-	g_option_context_free (context);
-
-	if (program_version == TRUE) {
-		g_print (VERSION "\n");
-		return 0;
-	}
-
-	if (argc < 2) {
-		g_print (options_help);
-		return 1;
-	}
-
-	pk_debug_init (verbose);
 	loop = g_main_loop_new (NULL, FALSE);
 
 	pconnection = pk_connection_new ();
@@ -987,15 +916,39 @@ main (int argc, char *argv[])
 			  G_CALLBACK (pk_console_error_code_cb), NULL);
 
 	/* run the commands */
-	pk_console_process_commands (client, argc, argv, !nowait, &error);
-	if (error != NULL) {
-		g_print ("Error:\n  %s\n\n", error->message);
-		g_error_free (error);
-		g_print (options_help);
+	pk_console_process_commands (client, argc, argv, wait_override, error);
+	g_object_unref (client);
+	return TRUE;
+}
+
+
+/***************************************************************************
+ ***                          MAKE CHECK TESTS                           ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libst_console (LibSelfTest *test)
+{
+	gchar *text;
+	guint extra = 0;
+
+	if (libst_start (test, "PkConsole", CLASS_AUTO) == FALSE) {
+		return;
 	}
 
-	g_free (options_help);
-	g_object_unref (client);
+	/************************************************************/
+	libst_title (test, "pad small string");
+	text = pk_console_pad_string ("richard", 10, &extra);
+	if (pk_strequal (text, "richard   ") == TRUE && extra == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "padded incorrectly '%s', extra %i", text, extra);
+	}
+	g_free (text);
 
-	return 0;
+	libst_end (test);
 }
+#endif
+
diff --git a/client/pk-console.h b/client/pk-console.h
new file mode 100644
index 0000000..dc97f15
--- /dev/null
+++ b/client/pk-console.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PK_CONSOLE_H
+#define __PK_CONSOLE_H
+
+#include <glib.h>
+
+gboolean	 pk_console_run			(int argc, char *argv[],
+						 gboolean	 wait_override,
+						 GError		**error);
+
+#endif /* __PK_CONSOLE_H */
diff --git a/client/pk-self-test.c b/client/pk-self-test.c
new file mode 100644
index 0000000..cfbea19
--- /dev/null
+++ b/client/pk-self-test.c
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libselftest.h>
+#include <pk-debug.h>
+
+/* prototypes */
+void libst_console (LibSelfTest *test);
+
+int
+main (int argc, char **argv)
+{
+	LibSelfTest test;
+
+	if (! g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
+	g_type_init ();
+	libst_init (&test);
+	pk_debug_init (TRUE);
+
+	/* tests go here */
+	libst_console (&test);
+
+	return (libst_finish (&test));
+}
+
commit 102e7d1da91a4c1087409665f1ef69e8255d107c
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 18:53:47 2007 +0000

    use the new pk_str* functions which are more secure and much faster

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index f208a49..c116c38 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -87,8 +87,7 @@ pk_filter_check (const gchar *filter)
 		pk_warning ("filter null");
 		return FALSE;
 	}
-	/* ITS4: ignore, not used for allocation */
-	if (strlen (filter) == 0) {
+	if (pk_strzero (filter) == TRUE) {
 		pk_warning ("filter zero length");
 		return FALSE;
 	}
@@ -99,8 +98,7 @@ pk_filter_check (const gchar *filter)
 	ret = FALSE;
 	for (i=0; i<length; i++) {
 		/* only one wrong part is enough to fail the filter */
-		/* ITS4: ignore, not used for allocation */
-		if (strlen (sections[i]) == 0) {
+		if (pk_strzero (sections[i]) == TRUE) {
 			goto out;
 		}
 		if (pk_filter_check_part (sections[i]) == FALSE) {
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
index 57f8e01..b06bcc2 100644
--- a/libpackagekit/pk-package-id.c
+++ b/libpackagekit/pk-package-id.c
@@ -78,19 +78,19 @@ pk_package_id_new_from_string (const gchar *package_id)
 	/* create new object */
 	ident = pk_package_id_new ();
 	/* ITS4: ignore, not used for allocation */
-	if (strlen (sections[0]) > 0) {
+	if (pk_strzero (sections[0]) == FALSE) {
 		ident->name = g_strdup (sections[0]);
 	}
 	/* ITS4: ignore, not used for allocation */
-	if (strlen (sections[1]) > 0) {
+	if (pk_strzero (sections[1]) == FALSE) {
 		ident->version = g_strdup (sections[1]);
 	}
 	/* ITS4: ignore, not used for allocation */
-	if (strlen (sections[2]) > 0) {
+	if (pk_strzero (sections[2]) == FALSE) {
 		ident->arch = g_strdup (sections[2]);
 	}
 	/* ITS4: ignore, not used for allocation */
-	if (strlen (sections[3]) > 0) {
+	if (pk_strzero (sections[3]) == FALSE) {
 		ident->data = g_strdup (sections[3]);
 	}
 	g_strfreev (sections);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 75b80de..a76f155 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -546,8 +546,7 @@ pk_engine_finished_cb (PkBackend *backend, PkExitEnum exit, PkEngine *engine)
 
 	/* add to the database */
 	packages = pk_package_list_get_string (item->package_list);
-	/* ITS4: ignore, GString is always NULL terminated */
-	if (strlen (packages) > 0) {
+	if (pk_strzero (packages) == FALSE) {
 		pk_transaction_db_set_data (engine->priv->transaction_db, item->tid, packages);
 	}
 	g_free (packages);
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index b5ad306..6ced0ba 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -42,6 +42,7 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include <pk-enum.h>
+#include <pk-common.h>
 
 #include "pk-debug.h"
 #include "pk-spawn.h"
@@ -110,7 +111,7 @@ pk_spawn_emit_whole_lines (PkSpawn *spawn, GString *string, gboolean is_stdout)
 	guint bytes_processed;
 
 	/* ITS4: ignore, GString is always NULL terminated */
-	if (strlen (string->str) == 0) {
+	if (pk_strzero (string->str) == TRUE) {
 		return FALSE;
 	}
 
commit e94c404db65ec0cffe935cbd73c9627f7566beb5
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 18:29:45 2007 +0000

    add some more string checking functions

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index d67bc4a..f208a49 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -158,6 +158,47 @@ pk_strsafe (const gchar *text)
 }
 
 /**
+ * pk_strzero:
+ *
+ * This function is a much safer way of doing "if (strlen (text) == 0))"
+ * as it does not rely on text being NULL terminated. It's also much
+ * quicker as it only checks the first byte rather than scanning the whole
+ * string just to verify it's not zero length.
+ **/
+gboolean
+pk_strzero (const gchar *text)
+{
+	if (text == NULL) {
+		return TRUE;
+	}
+	if (text[0] == '\0') {
+		return TRUE;
+	}
+	return FALSE;
+}
+
+/**
+ * pk_strlen:
+ *
+ * This function is a much safer way of doing strlen as it checks for NULL and
+ * a stupidly long string.
+ * This also modifies the string in place if it is over-range by inserting
+ * a NULL at the max_length.
+ **/
+guint
+pk_strlen (gchar *text, guint max_length)
+{
+	guint length;
+	/* ITS4: ignore, not used for allocation and checked */
+	length = strlen (text);
+	if (length > max_length) {
+		text[max_length] = '\0';
+		return max_length;
+	}
+	return length;
+}
+
+/**
  * pk_strvalidate:
  **/
 gboolean
@@ -222,10 +263,13 @@ out:
 }
 
 /**
- * pk_string_id_strcmp:
+ * pk_strequal:
+ *
+ * This function is a much safer way of doing strcmp as it checks for
+ * stupidly long strings, and returns boolean TRUE, not zero for success
  **/
 gboolean
-pk_string_id_strcmp (const gchar *id1, const gchar *id2)
+pk_strequal (const gchar *id1, const gchar *id2)
 {
 	if (id1 == NULL || id2 == NULL) {
 		pk_warning ("string id compare invalid '%s' and '%s'", id1, id2);
@@ -256,7 +300,7 @@ pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint compa
 	}
 	if (compare == parts) {
 		pk_debug ("optimise to strcmp");
-		return pk_string_id_strcmp (id1, id2);
+		return pk_strequal (id1, id2);
 	}
 
 	/* split, NULL will be returned if error */
@@ -300,6 +344,7 @@ libst_common (LibSelfTest *test)
 	gchar **array;
 	gchar *text_safe;
 	const gchar *temp;
+	guint length;
 
 	if (libst_start (test, "PkCommon", CLASS_AUTO) == FALSE) {
 		return;
@@ -353,7 +398,37 @@ libst_common (LibSelfTest *test)
 	}
 
 	/************************************************************
-	 ****************          string_id         ****************
+	 ****************          Zero            ******************
+	 ************************************************************/
+	temp = NULL;
+	libst_title (test, "test strzero (null)");
+	ret = pk_strzero (NULL);
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed null");
+	}
+
+	/************************************************************/
+	libst_title (test, "test strzero (null first char)");
+	ret = pk_strzero ("");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed null");
+	}
+
+	/************************************************************/
+	libst_title (test, "test strzero (long string)");
+	ret = pk_strzero ("Richard");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "zero length word!");
+	}
+
+	/************************************************************
+	 ****************          splitting         ****************
 	 ************************************************************/
 	libst_title (test, "test pass 1");
 	array = pk_strsplit ("foo", 1);
@@ -447,7 +522,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "id strcmp pass");
-	ret = pk_string_id_strcmp ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora");
+	ret = pk_strequal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora");
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -456,7 +531,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "id strcmp fail");
-	ret = pk_string_id_strcmp ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora");
+	ret = pk_strequal ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora");
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -622,6 +697,32 @@ libst_common (LibSelfTest *test)
 	}
 
 	/************************************************************
+	 ****************          strlen          ******************
+	 ************************************************************/
+	libst_title (test, "strlen bigger");
+	text_safe = g_strdup ("123456789");
+	length = pk_strlen (text_safe, 20);
+	if (length == 9 && strcmp (text_safe, "123456789") == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the strlen %i,'%s'", length, text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+	libst_title (test, "strlen smaller");
+	text_safe = g_strdup ("123456789");
+	length = pk_strlen (text_safe, 5);
+	if (length == 5 && strcmp (text_safe, "12345") == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "failed the strlen %i,'%s'", length, text_safe);
+	}
+	g_free (text_safe);
+
+	/************************************************************/
+
+	/************************************************************
 	 ****************       REPLACE CHARS      ******************
 	 ************************************************************/
 	libst_title (test, "test replace unsafe (okay)");
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 0af5dc8..179ff92 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -30,17 +30,20 @@ G_BEGIN_DECLS
 #define	PK_DBUS_PATH			"/org/freedesktop/PackageKit"
 #define	PK_DBUS_INTERFACE		"org.freedesktop.PackageKit"
 
-gboolean	 pk_strvalidate			(const gchar	*text);
-gboolean	 pk_filter_check			(const gchar	*filter);
-gchar		*pk_strsafe		(const gchar	*text);
-gchar		**pk_strsplit			(const gchar	*id,
-							 guint		 parts);
-gboolean	 pk_string_id_strcmp			(const gchar	*id1,
+guint		 pk_strlen				(gchar		*text,
+							 guint		 max_length);
+gboolean	 pk_strzero				(const gchar	*text);
+gboolean	 pk_strvalidate				(const gchar	*text);
+gboolean	 pk_strequal				(const gchar	*id1,
 							 const gchar	*id2);
+gchar		*pk_strsafe				(const gchar	*text);
+gchar		**pk_strsplit				(const gchar	*id,
+							 guint		 parts);
 gboolean	 pk_strcmp_sections			(const gchar	*id1,
 							 const gchar	*id2,
 							 guint		 parts,
 							 guint		 match);
+gboolean	 pk_filter_check			(const gchar	*filter);
 
 G_END_DECLS
 
commit d92856ecabe267cacde08054114cce59580d56da
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 17:55:47 2007 +0000

    rename some string functions in prep for other security changes

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 3bd71e3..d67bc4a 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -114,10 +114,10 @@ out:
 }
 
 /**
- * pk_validate_input_char:
+ * pk_strvalidate_char:
  **/
 static gboolean
-pk_validate_input_char (gchar item)
+pk_strvalidate_char (gchar item)
 {
 	switch (item) {
 	case ' ':
@@ -142,10 +142,10 @@ pk_validate_input_char (gchar item)
 }
 
 /**
- * pk_string_replace_unsafe:
+ * pk_strsafe:
  **/
 gchar *
-pk_string_replace_unsafe (const gchar *text)
+pk_strsafe (const gchar *text)
 {
 	gchar *text_safe;
 	const gchar *delimiters;
@@ -158,10 +158,10 @@ pk_string_replace_unsafe (const gchar *text)
 }
 
 /**
- * pk_validate_input:
+ * pk_strvalidate:
  **/
 gboolean
-pk_validate_input (const gchar *text)
+pk_strvalidate (const gchar *text)
 {
 	guint i;
 	guint length;
@@ -173,7 +173,7 @@ pk_validate_input (const gchar *text)
 			pk_debug ("input too long!");
 			return FALSE;
 		}
-		if (pk_validate_input_char (text[i]) == FALSE) {
+		if (pk_strvalidate_char (text[i]) == FALSE) {
 			pk_debug ("invalid char in text!");
 			return FALSE;
 		}
@@ -182,12 +182,12 @@ pk_validate_input (const gchar *text)
 }
 
 /**
- * pk_string_id_split:
+ * pk_strsplit:
  *
  * You need to use g_strfreev on the returned value
  **/
 gchar **
-pk_string_id_split (const gchar *id, guint parts)
+pk_strsplit (const gchar *id, guint parts)
 {
 	gchar **sections = NULL;
 
@@ -235,11 +235,11 @@ pk_string_id_strcmp (const gchar *id1, const gchar *id2)
 }
 
 /**
- * pk_string_id_equal:
+ * pk_strcmp_sections:
  * only compare first sections, not all the data
  **/
 gboolean
-pk_string_id_equal (const gchar *id1, const gchar *id2, guint parts, guint compare)
+pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint compare)
 {
 	gchar **sections1;
 	gchar **sections2;
@@ -260,8 +260,8 @@ pk_string_id_equal (const gchar *id1, const gchar *id2, guint parts, guint compa
 	}
 
 	/* split, NULL will be returned if error */
-	sections1 = pk_string_id_split (id1, parts);
-	sections2 = pk_string_id_split (id2, parts);
+	sections1 = pk_strsplit (id1, parts);
+	sections2 = pk_strsplit (id2, parts);
 
 	/* check we split okay */
 	if (sections1 == NULL) {
@@ -309,7 +309,7 @@ libst_common (LibSelfTest *test)
 	 ****************        validate text         **************
 	 ************************************************************/
 	libst_title (test, "validate correct char 1");
-	ret = pk_validate_input_char ('a');
+	ret = pk_strvalidate_char ('a');
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -318,7 +318,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "validate correct char 2");
-	ret = pk_validate_input_char ('~');
+	ret = pk_strvalidate_char ('~');
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -327,7 +327,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "validate incorrect char");
-	ret = pk_validate_input_char ('$');
+	ret = pk_strvalidate_char ('$');
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -336,7 +336,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "validate incorrect text");
-	ret = pk_validate_input ("richard$hughes");
+	ret = pk_strvalidate ("richard$hughes");
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -345,7 +345,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "validate correct text");
-	ret = pk_validate_input ("richardhughes");
+	ret = pk_strvalidate ("richardhughes");
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -356,7 +356,7 @@ libst_common (LibSelfTest *test)
 	 ****************          string_id         ****************
 	 ************************************************************/
 	libst_title (test, "test pass 1");
-	array = pk_string_id_split ("foo", 1);
+	array = pk_strsplit ("foo", 1);
 	if (array != NULL &&
 	    strcmp(array[0], "foo") == 0) {
 		libst_success (test, NULL);
@@ -367,7 +367,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test pass 2");
-	array = pk_string_id_split ("foo;moo", 2);
+	array = pk_strsplit ("foo;moo", 2);
 	if (array != NULL &&
 	    strcmp(array[0], "foo") == 0 &&
 	    strcmp(array[1], "moo") == 0) {
@@ -379,7 +379,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test pass 3");
-	array = pk_string_id_split ("foo;moo;bar", 3);
+	array = pk_strsplit ("foo;moo;bar", 3);
 	if (array != NULL &&
 	    strcmp(array[0], "foo") == 0 &&
 	    strcmp(array[1], "moo") == 0 &&
@@ -392,7 +392,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test on real packageid");
-	array = pk_string_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;", 4);
+	array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;", 4);
 	if (array != NULL &&
 	    strcmp(array[0], "kde-i18n-csb") == 0 &&
 	    strcmp(array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
@@ -406,7 +406,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test on short packageid");
-	array = pk_string_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;", 4);
+	array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;", 4);
 	if (array != NULL &&
 	    strcmp(array[0], "kde-i18n-csb") == 0 &&
 	    strcmp(array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
@@ -420,7 +420,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test fail under");
-	array = pk_string_id_split ("foo;moo", 1);
+	array = pk_strsplit ("foo;moo", 1);
 	if (array == NULL) {
 		libst_success (test, NULL);
 	} else {
@@ -429,7 +429,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test fail over");
-	array = pk_string_id_split ("foo;moo", 3);
+	array = pk_strsplit ("foo;moo", 3);
 	if (array == NULL) {
 		libst_success (test, NULL);
 	} else {
@@ -438,7 +438,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test fail missing first");
-	array = pk_string_id_split (";moo", 2);
+	array = pk_strsplit (";moo", 2);
 	if (array == NULL) {
 		libst_success (test, NULL);
 	} else {
@@ -464,7 +464,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal pass (same)");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 3);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 3);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -472,7 +472,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal pass (parts==match)");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 4);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 4);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -480,7 +480,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal pass (different)");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data", 4, 3);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data", 4, 3);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -488,7 +488,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal fail1");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.2;x64;fedora", 4, 3);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.2;x64;fedora", 4, 3);
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -496,7 +496,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal fail2");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "gnome;0.0.2;i386;fedora", 4, 3);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "gnome;0.0.2;i386;fedora", 4, 3);
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -504,7 +504,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal fail3");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 3);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 3);
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -512,7 +512,7 @@ libst_common (LibSelfTest *test)
 	}
 
 	libst_title (test, "id equal fail (match too high)");
-	ret = pk_string_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 5);
+	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 5);
 	if (ret == FALSE) {
 		libst_success (test, NULL);
 	} else {
@@ -625,7 +625,7 @@ libst_common (LibSelfTest *test)
 	 ****************       REPLACE CHARS      ******************
 	 ************************************************************/
 	libst_title (test, "test replace unsafe (okay)");
-	text_safe = pk_string_replace_unsafe ("Richard Hughes");
+	text_safe = pk_strsafe ("Richard Hughes");
 	if (text_safe != NULL && strcmp (text_safe, "Richard Hughes") == 0) {
 		libst_success (test, NULL);
 	} else {
@@ -635,7 +635,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test replace unsafe (one invalid)");
-	text_safe = pk_string_replace_unsafe ("Richard\tHughes");
+	text_safe = pk_strsafe ("Richard\tHughes");
 	if (text_safe != NULL && strcmp (text_safe, "Richard Hughes") == 0) {
 		libst_success (test, NULL);
 	} else {
@@ -645,7 +645,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test replace unsafe (one invalid 2)");
-	text_safe = pk_string_replace_unsafe ("Richard\"Hughes\"");
+	text_safe = pk_strsafe ("Richard\"Hughes\"");
 	if (text_safe != NULL && strcmp (text_safe, "Richard Hughes ") == 0) {
 		libst_success (test, NULL);
 	} else {
@@ -655,7 +655,7 @@ libst_common (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "test replace unsafe (multiple invalid)");
-	text_safe = pk_string_replace_unsafe ("'Richard\"Hughes\"");
+	text_safe = pk_strsafe ("'Richard\"Hughes\"");
 	if (text_safe != NULL && strcmp (text_safe, " Richard Hughes ") == 0) {
 		libst_success (test, NULL);
 	} else {
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 192c17d..0af5dc8 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -30,14 +30,14 @@ G_BEGIN_DECLS
 #define	PK_DBUS_PATH			"/org/freedesktop/PackageKit"
 #define	PK_DBUS_INTERFACE		"org.freedesktop.PackageKit"
 
-gboolean	 pk_validate_input			(const gchar	*text);
+gboolean	 pk_strvalidate			(const gchar	*text);
 gboolean	 pk_filter_check			(const gchar	*filter);
-gchar		*pk_string_replace_unsafe		(const gchar	*text);
-gchar		**pk_string_id_split			(const gchar	*id,
+gchar		*pk_strsafe		(const gchar	*text);
+gchar		**pk_strsplit			(const gchar	*id,
 							 guint		 parts);
 gboolean	 pk_string_id_strcmp			(const gchar	*id1,
 							 const gchar	*id2);
-gboolean	 pk_string_id_equal			(const gchar	*id1,
+gboolean	 pk_strcmp_sections			(const gchar	*id1,
 							 const gchar	*id2,
 							 guint		 parts,
 							 guint		 match);
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
index 83e9c8c..57f8e01 100644
--- a/libpackagekit/pk-package-id.c
+++ b/libpackagekit/pk-package-id.c
@@ -53,7 +53,7 @@ gboolean
 pk_package_id_check (const gchar *package_id)
 {
 	gchar **sections;
-	sections = pk_string_id_split (package_id, 4);
+	sections = pk_strsplit (package_id, 4);
 	if (sections != NULL) {
 		g_strfreev (sections);
 		return TRUE;
@@ -70,7 +70,7 @@ pk_package_id_new_from_string (const gchar *package_id)
 	gchar **sections;
 	PkPackageId *ident = NULL;
 
-	sections = pk_string_id_split (package_id, 4);
+	sections = pk_strsplit (package_id, 4);
 	if (sections == NULL) {
 		return NULL;
 	}
@@ -154,12 +154,12 @@ pk_package_id_free (PkPackageId *ident)
 }
 
 /**
- * pk_string_id_equal:
+ * pk_strcmp_sections:
  **/
 gboolean
 pk_package_id_equal (const gchar *pid1, const gchar *pid2)
 {
-	return pk_string_id_equal (pid1, pid2, 4, 3);
+	return pk_strcmp_sections (pid1, pid2, 4, 3);
 }
 
 /***************************************************************************
diff --git a/src/pk-backend.c b/src/pk-backend.c
index a4c841c..5f0cbf1 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -757,7 +757,7 @@ pk_backend_package (PkBackend *backend, PkInfoEnum info, const gchar *package, c
 	backend->priv->last_package = g_strdup (package);
 
 	/* replace unsafe chars */
-	summary_safe = pk_string_replace_unsafe (summary);
+	summary_safe = pk_strsafe (summary);
 
 	pk_debug ("emit package %i, %s, %s", info, package, summary_safe);
 	g_signal_emit (backend, signals [PK_BACKEND_PACKAGE], 0, info, package, summary_safe);
@@ -779,7 +779,7 @@ pk_backend_update_detail (PkBackend *backend, const gchar *package_id,
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
 	/* replace unsafe chars */
-	update_text_safe = pk_string_replace_unsafe (update_text);
+	update_text_safe = pk_strsafe (update_text);
 
 	pk_debug ("emit update-detail %s, %s, %s, %s, %s, %s",
 		  package_id, updates, obsoletes, url, restart, update_text_safe);
@@ -866,7 +866,7 @@ pk_backend_description (PkBackend *backend, const gchar *package_id,
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
 	/* replace unsafe chars */
-	description_safe = pk_string_replace_unsafe (description);
+	description_safe = pk_strsafe (description);
 
 	pk_debug ("emit description %s, %s, %i, %s, %s, %ld",
 		  package_id, licence, group, description_safe, url,
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 30df52c..75b80de 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -955,7 +955,7 @@ pk_engine_search_check (const gchar *search, GError **error)
 			     "Invalid search containing '?'");
 		return FALSE;
 	}
-	ret = pk_validate_input (search);
+	ret = pk_strvalidate (search);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 			     "Invalid search term");
@@ -973,7 +973,7 @@ pk_engine_filter_check (const gchar *filter, GError **error)
 	gboolean ret;
 
 	/* check for invalid input */
-	ret = pk_validate_input (filter);
+	ret = pk_strvalidate (filter);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 			     "Invalid filter term");
@@ -1231,7 +1231,7 @@ pk_engine_resolve (PkEngine *engine, const gchar *tid, const gchar *filter, cons
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package);
+	ret = pk_strvalidate (package);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 			     "Invalid input passed to daemon");
@@ -1280,7 +1280,7 @@ pk_engine_get_depends (PkEngine *engine, const gchar *tid, const gchar *package_
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				      "Invalid input passed to daemon");
@@ -1337,7 +1337,7 @@ pk_engine_get_requires (PkEngine *engine, const gchar *tid, const gchar *package
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				      "Invalid input passed to daemon");
@@ -1394,7 +1394,7 @@ pk_engine_get_update_detail (PkEngine *engine, const gchar *tid, const gchar *pa
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				      "Invalid input passed to daemon");
@@ -1451,7 +1451,7 @@ pk_engine_get_description (PkEngine *engine, const gchar *tid, const gchar *pack
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				      "Invalid input passed to daemon");
@@ -1508,7 +1508,7 @@ pk_engine_get_files (PkEngine *engine, const gchar *tid, const gchar *package_id
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				      "Invalid input passed to daemon");
@@ -1628,7 +1628,7 @@ pk_engine_remove_package (PkEngine *engine, const gchar *tid, const gchar *packa
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
@@ -1701,7 +1701,7 @@ pk_engine_install_package (PkEngine *engine, const gchar *tid, const gchar *pack
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
@@ -1838,7 +1838,7 @@ pk_engine_rollback (PkEngine *engine, const gchar *tid, const gchar *transaction
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (transaction_id);
+	ret = pk_strvalidate (transaction_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
@@ -1902,7 +1902,7 @@ pk_engine_update_package (PkEngine *engine, const gchar *tid, const gchar *packa
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (package_id);
+	ret = pk_strvalidate (package_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
@@ -2016,7 +2016,7 @@ pk_engine_repo_enable (PkEngine *engine, const gchar *tid, const gchar *repo_id,
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (repo_id);
+	ret = pk_strvalidate (repo_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
@@ -2081,7 +2081,7 @@ pk_engine_repo_set_data (PkEngine *engine, const gchar *tid, const gchar *repo_i
 	}
 
 	/* check for sanity */
-	ret = pk_validate_input (repo_id);
+	ret = pk_strvalidate (repo_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
 				     "Invalid input passed to daemon");
diff --git a/src/pk-transaction-id.c b/src/pk-transaction-id.c
index 0b7d285..00ec6f1 100644
--- a/src/pk-transaction-id.c
+++ b/src/pk-transaction-id.c
@@ -111,7 +111,7 @@ pk_transaction_id_save_job_count (guint job_count)
 gboolean
 pk_transaction_id_equal (const gchar *tid1, const gchar *tid2)
 {
-	return pk_string_id_equal (tid1, tid2, 3, 2);
+	return pk_strcmp_sections (tid1, tid2, 3, 2);
 }
 
 /**
commit 26d69ac6757dd14742ad51ce70dd0649db033d8f
Author: S.Çağlar Onur <caglar at pardus.org.tr>
Date:   Wed Oct 31 17:13:45 2007 +0200

    export GROUP_UNKNOWN to backends

diff --git a/python/packagekit/backend.py b/python/packagekit/backend.py
index f2e8ae5..6495f63 100644
--- a/python/packagekit/backend.py
+++ b/python/packagekit/backend.py
@@ -97,6 +97,7 @@ GROUP_FONTS             = "fonts"
 GROUP_ADMIN_TOOLS       = "admin-tools"
 GROUP_LEGACY            = "legacy"
 GROUP_LOCALIZATION      = "localization"
+GROUP_UNKNOWN           = "unknown"
 
 # Classes
 
commit dbda49162cf5c366481bb80b3f0d818b0f942450
Author: S.Çağlar Onur <caglar at pardus.org.tr>
Date:   Wed Oct 31 16:22:27 2007 +0200

    PiSi: Connect cancel support to backend

diff --git a/backends/pisi/pk-backend-pisi.c b/backends/pisi/pk-backend-pisi.c
index 356939c..0aa410e 100644
--- a/backends/pisi/pk-backend-pisi.c
+++ b/backends/pisi/pk-backend-pisi.c
@@ -44,7 +44,7 @@ PK_BACKEND_OPTIONS (
 	NULL,						/* destroy */
 	NULL,						/* get_groups */
 	backend_get_filters,				/* get_filters */
-	NULL,						/* cancel */
+	pk_backend_python_cancel,			/* cancel */
 	pk_backend_python_get_depends,			/* get_depends */
 	pk_backend_python_get_description,		/* get_description */
 	pk_backend_python_get_files,				/* get_files */
commit 3f82c4c52001a815b8830e2723ef21a6d575c962
Author: Tim Lauridsen <tla at rasmil.dk>
Date:   Wed Oct 31 09:20:58 2007 +0100

    python backend: Added utf-8 convertion to package & description signal to handle summaries & descriptions with on ASCII chars

diff --git a/python/packagekit/backend.py b/python/packagekit/backend.py
index 09b7b3b..f2e8ae5 100644
--- a/python/packagekit/backend.py
+++ b/python/packagekit/backend.py
@@ -22,6 +22,8 @@
 
 # imports
 import sys
+import types
+
 
 # Constants
 
@@ -152,6 +154,7 @@ class PackageKitBaseBackend:
         @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
         @param summary: The package Summary
         '''
+        summary = self._toUTF(summary)
         print >> sys.stdout,"package\t%s\t%s\t%s" % (status,id,summary)
 
     def status(self,state):
@@ -187,6 +190,7 @@ class PackageKitBaseBackend:
         @param bytes: The size of the package, in bytes
         @param file_list: List of the files in the package, separated by ';'
         '''
+        desc = self._toUTF(desc)
         print >> sys.stdout,"description\t%s\t%s\t%s\t%s\t%s\t%ld\t%s" % (id,licence,group,desc,url,bytes,file_list)
 
     def files(self, id, file_list):
@@ -250,6 +254,19 @@ class PackageKitBaseBackend:
             containing (name,ver,arch,data)
         '''
         return tuple(id.split(';', 4))
+        
+
+    def _toUTF( self, txt ):
+        rc=""
+        if isinstance(txt,types.UnicodeType):
+            return txt
+        else:
+            try:
+                rc = unicode( txt, 'utf-8' )
+            except UnicodeDecodeError, e:
+                rc = unicode( txt, 'iso-8859-1' )
+            return rc
+        
 #
 # Backend Action Methods
 #
commit 3d43e2a2fe86b0063da2207ce898b2915e454477
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 08:15:20 2007 +0000

    add some more unit tests to pk_package_id_new_from_string

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 6bf4eb3..3bd71e3 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -405,6 +405,20 @@ libst_common (LibSelfTest *test)
 	g_strfreev (array);
 
 	/************************************************************/
+	libst_title (test, "test on short packageid");
+	array = pk_string_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;", 4);
+	if (array != NULL &&
+	    strcmp(array[0], "kde-i18n-csb") == 0 &&
+	    strcmp(array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
+	    strcmp(array[2], "") == 0 &&
+	    strcmp(array[3], "") == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
+	}
+	g_strfreev (array);
+
+	/************************************************************/
 	libst_title (test, "test fail under");
 	array = pk_string_id_split ("foo;moo", 1);
 	if (array == NULL) {
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
index 8996cd4..83e9c8c 100644
--- a/libpackagekit/pk-package-id.c
+++ b/libpackagekit/pk-package-id.c
@@ -252,7 +252,8 @@ libst_package_id (LibSelfTest *test)
 	/************************************************************/
 	libst_title (test, "parse package_id from string");
 	ident = pk_package_id_new_from_string ("moo;0.0.1;i386;fedora");
-	if (strcmp (ident->name, "moo") == 0 &&
+	if (ident != NULL &&
+	    strcmp (ident->name, "moo") == 0 &&
 	    strcmp (ident->arch, "i386") == 0 &&
 	    strcmp (ident->data, "fedora") == 0 &&
 	    strcmp (ident->version, "0.0.1") == 0) {
@@ -272,6 +273,20 @@ libst_package_id (LibSelfTest *test)
 	g_free (text);
 	pk_package_id_free (ident);
 
+	/************************************************************/
+	libst_title (test, "parse short package_id from string");
+	ident = pk_package_id_new_from_string ("moo;0.0.1;;");
+	if (ident != NULL &&
+	    strcmp (ident->name, "moo") == 0 &&
+	    strcmp (ident->version, "0.0.1") == 0 &&
+	    ident->data == NULL &&
+	    ident->arch == NULL) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+	pk_package_id_free (ident);
+
 	libst_end (test);
 }
 #endif
commit 376cf25feff3bad17b7528c63d28eca9eb776124
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 31 08:05:41 2007 +0000

    add some more unit tests to pk_string_id_split

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 6d73f1c..6bf4eb3 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -357,30 +357,50 @@ libst_common (LibSelfTest *test)
 	 ************************************************************/
 	libst_title (test, "test pass 1");
 	array = pk_string_id_split ("foo", 1);
-	if (array != NULL) {
+	if (array != NULL &&
+	    strcmp(array[0], "foo") == 0) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, NULL);
+		libst_failed (test, "got %s", array[0]);
 	}
 	g_strfreev (array);
 
 	/************************************************************/
 	libst_title (test, "test pass 2");
 	array = pk_string_id_split ("foo;moo", 2);
-	if (array != NULL) {
+	if (array != NULL &&
+	    strcmp(array[0], "foo") == 0 &&
+	    strcmp(array[1], "moo") == 0) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, NULL);
+		libst_failed (test, "got %s, %s", array[0], array[1]);
 	}
 	g_strfreev (array);
 
 	/************************************************************/
 	libst_title (test, "test pass 3");
 	array = pk_string_id_split ("foo;moo;bar", 3);
-	if (array != NULL) {
+	if (array != NULL &&
+	    strcmp(array[0], "foo") == 0 &&
+	    strcmp(array[1], "moo") == 0 &&
+	    strcmp(array[2], "bar") == 0) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, NULL);
+		libst_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
+	}
+	g_strfreev (array);
+
+	/************************************************************/
+	libst_title (test, "test on real packageid");
+	array = pk_string_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;", 4);
+	if (array != NULL &&
+	    strcmp(array[0], "kde-i18n-csb") == 0 &&
+	    strcmp(array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
+	    strcmp(array[2], "all") == 0 &&
+	    strcmp(array[3], "") == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
 	}
 	g_strfreev (array);
 



More information about the PackageKit mailing list