[packagekit] packagekit: Branch 'master' - 2 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Thu Aug 30 18:54:43 PDT 2007
libpackagekit/pk-task-utils.c | 126 +++++++++++++++++++++++++++++++++++++++++-
src/pk-engine.c | 102 ++++++++++++++++++++++++++++++++++
src/pk-engine.h | 2
3 files changed, 229 insertions(+), 1 deletion(-)
New commits:
diff-tree c70412f1408a1f70fec835e27e0828c143363721 (from 370de0ba7100f466e7dd7bec5f2c6ea8f9d5d34e)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 02:53:18 2007 +0100
fix a direction error spotted by ray. add a boat load of unit tests and fix up the other issues
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 3362460..b547e56 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -277,6 +277,9 @@ pk_task_filter_check_part (const gchar *
if (strlen (filter) == 0) {
return FALSE;
}
+ if (strcmp (filter, "none") == 0) {
+ return TRUE;
+ }
if (strcmp (filter, "installed") == 0) {
return TRUE;
}
@@ -309,12 +312,24 @@ pk_task_filter_check (const gchar *filte
guint length;
gboolean ret;
+ if (filter == NULL) {
+ pk_warning ("filter null");
+ return FALSE;
+ }
+ if (strlen (filter) == 0) {
+ pk_warning ("filter zero length");
+ return FALSE;
+ }
+
/* split by delimeter ';' */
sections = g_strsplit (filter, ";", 0);
length = g_strv_length (sections);
ret = FALSE;
- for (i=0; i>length; i++) {
+ for (i=0; i<length; i++) {
/* only one wrong part is enough to fail the filter */
+ if (strlen (sections[i]) == 0) {
+ goto out;
+ }
if (pk_task_filter_check_part (sections[i]) == FALSE) {
goto out;
}
@@ -365,6 +380,11 @@ pk_task_action_contains (const gchar *ac
guint i;
guint ret = FALSE;
+ if (actions == NULL) {
+ pk_warning ("actions null");
+ return FALSE;
+ }
+
/* split by delimeter ';' */
sections = g_strsplit (actions, ";", 0);
@@ -389,11 +409,115 @@ libst_task_utils (LibSelfTest *test)
{
gboolean ret;
gchar *text;
+ const gchar *temp;
if (libst_start (test, "PkTaskUtils", CLASS_AUTO) == FALSE) {
return;
}
+
+ /************************************************************
+ **************** FILTERS ******************
+ ************************************************************/
+ temp = NULL;
+ libst_title (test, "test a fail filter (null)");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "";
+ libst_title (test, "test a fail filter ()");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = ";";
+ libst_title (test, "test a fail filter (;)");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "moo";
+ libst_title (test, "test a fail filter (invalid)");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "moo;foo";
+ libst_title (test, "test a fail filter (invalid, multiple)");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "gui;;";
+ libst_title (test, "test a fail filter (valid then zero length)");
+ ret = pk_task_filter_check (temp);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "none";
+ libst_title (test, "test a pass filter (none)");
+ ret = pk_task_filter_check (temp);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "failed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "gui";
+ libst_title (test, "test a pass filter (single)");
+ ret = pk_task_filter_check (temp);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "failed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "devel;~gui";
+ libst_title (test, "test a pass filter (multiple)");
+ ret = pk_task_filter_check (temp);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "failed the filter '%s'", temp);
+ }
+
+ /************************************************************/
+ temp = "~gui;~installed";
+ libst_title (test, "test a pass filter (multiple2)");
+ ret = pk_task_filter_check (temp);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "failed the filter '%s'", temp);
+ }
+
/************************************************************
**************** ACTIONS ******************
************************************************************/
diff-tree 370de0ba7100f466e7dd7bec5f2c6ea8f9d5d34e (from 45bc9b322e2791e554be18c99dc0be8f1fe3b7cd)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 02:30:12 2007 +0100
add code to check the search term and the filter into the engine
diff --git a/src/pk-engine.c b/src/pk-engine.c
index a50c9ce..92d5623 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -111,6 +111,8 @@ pk_engine_error_get_type (void)
ENUM_ENTRY (PK_ENGINE_ERROR_NO_SUCH_JOB, "NoSuchJob"),
ENUM_ENTRY (PK_ENGINE_ERROR_REFUSED_BY_POLICY, "RefusedByPolicy"),
ENUM_ENTRY (PK_ENGINE_ERROR_PACKAGE_ID_INVALID, "PackageIdInvalid"),
+ ENUM_ENTRY (PK_ENGINE_ERROR_SEARCH_INVALID, "SearchInvalid"),
+ ENUM_ENTRY (PK_ENGINE_ERROR_FILTER_INVALID, "FilterInvalid"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("PkEngineError", values);
@@ -580,6 +582,58 @@ pk_engine_get_updates (PkEngine *engine,
}
/**
+ * pk_task_search_check:
+ **/
+gboolean
+pk_engine_search_check (const gchar *search, GError **error)
+{
+ if (search == NULL) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
+ "Search is null. This isn't supposed to happen...");
+ return FALSE;
+ }
+ if (strlen (search) == 0) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
+ "Search string zero length");
+ return FALSE;
+ }
+ if (strlen (search) < 2) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
+ "The search string length is too small");
+ return FALSE;
+ }
+ if (strstr (search, "*") != NULL) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
+ "Invalid search containing '*'");
+ return FALSE;
+ }
+ if (strstr (search, "?") != NULL) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
+ "Invalid search containing '?'");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * pk_task_filter_check:
+ **/
+gboolean
+pk_engine_filter_check (const gchar *filter, GError **error)
+{
+ gboolean ret;
+
+ /* check for invalid filter */
+ ret = pk_task_filter_check (filter);
+ if (ret == FALSE) {
+ g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_FILTER_INVALID,
+ "Filter '%s' is invalid", filter);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* pk_engine_search_name:
**/
gboolean
@@ -592,6 +646,18 @@ pk_engine_search_name (PkEngine *engine,
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+ /* check the search term */
+ ret = pk_engine_search_check (search, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
+ /* check the filter */
+ ret = pk_engine_filter_check (filter, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
/* create a new task and start it */
task = pk_engine_new_task (engine);
ret = pk_task_search_name (task, filter, search);
@@ -620,6 +686,18 @@ pk_engine_search_details (PkEngine *engi
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+ /* check the search term */
+ ret = pk_engine_search_check (search, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
+ /* check the filter */
+ ret = pk_engine_filter_check (filter, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
/* create a new task and start it */
task = pk_engine_new_task (engine);
ret = pk_task_search_details (task, filter, search);
@@ -648,6 +726,18 @@ pk_engine_search_group (PkEngine *engine
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+ /* check the search term */
+ ret = pk_engine_search_check (search, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
+ /* check the filter */
+ ret = pk_engine_filter_check (filter, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
/* create a new task and start it */
task = pk_engine_new_task (engine);
ret = pk_task_search_group (task, filter, search);
@@ -676,6 +766,18 @@ pk_engine_search_file (PkEngine *engine,
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+ /* check the search term */
+ ret = pk_engine_search_check (search, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
+ /* check the filter */
+ ret = pk_engine_filter_check (filter, error);
+ if (ret == FALSE) {
+ return FALSE;
+ }
+
/* create a new task and start it */
task = pk_engine_new_task (engine);
ret = pk_task_search_file (task, filter, search);
diff --git a/src/pk-engine.h b/src/pk-engine.h
index 0c6ca3e..93072ac 100644
--- a/src/pk-engine.h
+++ b/src/pk-engine.h
@@ -60,6 +60,8 @@ typedef enum
PK_ENGINE_ERROR_NO_SUCH_JOB,
PK_ENGINE_ERROR_REFUSED_BY_POLICY,
PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
+ PK_ENGINE_ERROR_SEARCH_INVALID,
+ PK_ENGINE_ERROR_FILTER_INVALID,
PK_ENGINE_ERROR_LAST
} PkEngineError;
More information about the PackageKit
mailing list