socsvn commit: r254445 - in soc2013/mattbw/backend: . query
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Tue Jul 9 05:35:36 UTC 2013
Author: mattbw
Date: Tue Jul 9 05:35:36 2013
New Revision: 254445
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254445
Log:
even more static analysis cleanup
Modified:
soc2013/mattbw/backend/db.h
soc2013/mattbw/backend/query/core.c
soc2013/mattbw/backend/query/core.h
soc2013/mattbw/backend/query/do.c
soc2013/mattbw/backend/utils.c
soc2013/mattbw/backend/utils.h
Modified: soc2013/mattbw/backend/db.h
==============================================================================
--- soc2013/mattbw/backend/db.h Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/db.h Tue Jul 9 05:35:36 2013 (r254445)
@@ -25,6 +25,6 @@
#include "pk-backend.h" /* PkBackend */
#include "pkg.h" /* struct pkgdb */
-struct pkgdb* db_open_remote(PkBackend *backend);
+struct pkgdb *db_open_remote(PkBackend *backend);
#endif /* !_PKGNG_BACKEND_DB_H_ */
Modified: soc2013/mattbw/backend/query/core.c
==============================================================================
--- soc2013/mattbw/backend/query/core.c Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/query/core.c Tue Jul 9 05:35:36 2013 (r254445)
@@ -49,68 +49,16 @@
struct query_target *t;
};
-static enum repo_type type_of_repo_name(const char *name);
static bool can_remote_iterate(struct query *q);
-static gchar *match_pkg(struct pkg *pkg, struct query *q);
+static bool emit_to_job(struct pkg *pkg, struct query *q);
static const gchar *query_repo(struct query *q);
+static enum repo_type type_of_repo_name(const char *name);
+static gchar *match_pkg(struct pkg *pkg, struct query *q);
static gchar **init_unpack_source(PkBackend *backend, struct query_source *s);
static int jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg);
static int jobs_repo_from_query(struct pkg_jobs *jobs, struct query *q);
static struct pkg *match_iterator(struct pkgdb_it *it, struct query *q, gchar **match_id_p);
-/* Returns the backend stored inside the struct query. */
-PkBackend *
-query_backend(struct query *q)
-{
-
- return (q == NULL ? NULL : q->backend);
-}
-
-/*
- * For adapting an emitter function into one that solves and applies a job.
- */
-bool
-query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q)
-{
- bool success;
- struct pkg_jobs *jobs;
- PkBackend *backend;
-
- INTENTIONALLY_IGNORE(id);
-
- success = false;
- jobs = NULL;
-
- if (q == NULL)
- goto cleanup;
-
- backend = query_backend(q);
-
- if (pkg_jobs_new(&jobs, q->t->data.job.type, q->db) != EPKG_OK) {
- ERR(backend,
- PK_ERROR_ENUM_INTERNAL_ERROR,
- "could not init pkg_jobs");
- goto cleanup;
- }
- if (jobs_repo_from_query(jobs, q) != EPKG_OK) {
- ERR(backend,
- PK_ERROR_ENUM_REPO_NOT_FOUND,
- "could not set repo");
- goto cleanup;
- }
- if (jobs_add_pkg(jobs, MATCH_EXACT, pkg) != EPKG_OK) {
- ERR(backend,
- PK_ERROR_ENUM_INTERNAL_ERROR,
- "could not add to job");
- goto cleanup;
- }
- success = q->t->data.job.f(jobs, q);
-
-cleanup:
- pkg_jobs_free(jobs);
- return success;
-}
-
/*
* Runs an assembled query.
*/
@@ -176,7 +124,7 @@
if (q->t->type == QUERY_EMIT)
success = q->t->data.emit.f(pkg, match_id, q);
else if (q->t->type == QUERY_JOB)
- success = query_emit_to_job(pkg, match_id, q);
+ success = emit_to_job(pkg, q);
}
pkg_free(pkg);
@@ -185,6 +133,14 @@
return success;
}
+/* Returns the backend stored inside the struct query. */
+PkBackend *
+query_backend(struct query *q)
+{
+
+ return (q == NULL ? NULL : q->backend);
+}
+
/*
* Creates a struct query for the given backend, database, source and target.
*
@@ -274,30 +230,12 @@
(void)pk_backend_set_percentage(q->backend, scaled_percent);
}
-/* Finds the type of the given PackageKit repository name. */
-static enum repo_type
-type_of_repo_name(const char *name)
-{
- enum repo_type rtype;
-
- /* Null or empty implies no specific repository */
- if (name == NULL || name[0] == '\0')
- rtype = REPO_ANY;
- else if (strcmp(name, "installed") == 0)
- rtype = REPO_LOCAL;
- else if (pkg_repo_find_ident(name) != NULL)
- rtype = REPO_REMOTE;
- else
- rtype = REPO_INVALID;
-
- return rtype;
-}
/*
* Checks to see if trying to do a remote package iteration with this query
* could spell disaster.
*/
-static bool
+static bool
can_remote_iterate(struct query *q)
{
bool sane;
@@ -320,6 +258,68 @@
}
/*
+ * For adapting an emitter function into one that solves and applies a job.
+ */
+static bool
+emit_to_job(struct pkg *pkg, struct query *q)
+{
+ bool success;
+ struct pkg_jobs *jobs;
+ PkBackend *backend;
+
+ success = false;
+ jobs = NULL;
+
+ if (q == NULL)
+ goto cleanup;
+
+ backend = query_backend(q);
+
+ if (pkg_jobs_new(&jobs, q->t->data.job.type, q->db) != EPKG_OK) {
+ ERR(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "could not init pkg_jobs");
+ goto cleanup;
+ }
+ if (jobs_repo_from_query(jobs, q) != EPKG_OK) {
+ ERR(backend,
+ PK_ERROR_ENUM_REPO_NOT_FOUND,
+ "could not set repo");
+ goto cleanup;
+ }
+ if (jobs_add_pkg(jobs, MATCH_EXACT, pkg) != EPKG_OK) {
+ ERR(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "could not add to job");
+ goto cleanup;
+ }
+ success = q->t->data.job.f(jobs, q);
+
+cleanup:
+ pkg_jobs_free(jobs);
+ return success;
+}
+
+/* Finds the type of the given PackageKit repository name. */
+static enum repo_type
+type_of_repo_name(const char *name)
+{
+ enum repo_type rtype;
+
+ /* Null or empty implies no specific repository */
+ if (name == NULL || name[0] == '\0')
+ rtype = REPO_ANY;
+ else if (strcmp(name, "installed") == 0)
+ rtype = REPO_LOCAL;
+ else if (pkg_repo_find_ident(name) != NULL)
+ rtype = REPO_REMOTE;
+ else
+ rtype = REPO_INVALID;
+
+ return rtype;
+}
+
+/*
* Checks whether a candidate package matches any constraints provided by the
* query and, if so, returns its full PackageID; otherwise NULL.
*/
@@ -347,7 +347,7 @@
* instead of normal strcmp or even g_strcmp0.
*/
for (matches = true, i = PK_PACKAGE_ID_NAME;
- matches == true && i <= PK_PACKAGE_ID_DATA;
+ matches && i <= PK_PACKAGE_ID_DATA;
i++)
matches = string_match((q->id_strv)[i],
pkg_id_bits[i]);
@@ -447,7 +447,7 @@
* checking against it so it doesn't matter that the version
* might be in the name column etc.
*/
- id_strv = g_malloc0_n(5, (gsize)sizeof(gchar *));
+ id_strv = g_malloc0_n(5, (gsize) sizeof(gchar *));
id_strv[PK_PACKAGE_ID_NAME] = g_strdup(s->data.single);
id_strv[PK_PACKAGE_ID_VERSION] = g_strdup("");
Modified: soc2013/mattbw/backend/query/core.h
==============================================================================
--- soc2013/mattbw/backend/query/core.h Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/query/core.h Tue Jul 9 05:35:36 2013 (r254445)
@@ -72,7 +72,6 @@
};
PkBackend *query_backend(struct query *q);
-bool query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q);
bool query_run (struct query *q);
struct query *query_init(PkBackend *backend, struct pkgdb *db, struct query_source *s, struct query_target *t);
void query_free(struct query **q_p);
Modified: soc2013/mattbw/backend/query/do.c
==============================================================================
--- soc2013/mattbw/backend/query/do.c Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/query/do.c Tue Jul 9 05:35:36 2013 (r254445)
@@ -60,8 +60,10 @@
success = false;
break;
}
+
+ pkgdb_close(db);
}
- pkgdb_close(db);
+
return success;
}
Modified: soc2013/mattbw/backend/utils.c
==============================================================================
--- soc2013/mattbw/backend/utils.c Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/utils.c Tue Jul 9 05:35:36 2013 (r254445)
@@ -1,5 +1,4 @@
/*-
- *
* Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
*
* Licensed under the GNU General Public License Version 2
@@ -29,69 +28,21 @@
#include "utils.h" /* prototypes */
/*
- * If the input pointer points to a string that is empty, return the null
- * pointer; else pass through the pointer unmolested.
- *
- * This does NOT free anything!
- */
-const char *
-null_if_empty(const char *in)
-{
- return (in != NULL && strlen(in) == 0) ? NULL : in;
-}
-
-/*
- * Splits a PackageID into its constituent parts, and returns both the split
- * string vector (to be freed with g_strfreev later) and four pointers to its
- * constituents (or NULL where they are empty strings).
- *
- * Returns FALSE on failure.
- */
-gboolean
-split_id(const char *id,
- char ***strv_p,
- const char **name_p,
- const char **version_p,
- const char **arch_p,
- const char **data_p)
-{
- int success;
- char **strv;
-
- success = FALSE;
- strv = pk_package_id_split(id);
- if (strv != NULL) {
- /*
- * Make really really REALLY sure that the PackageID fields
- * either have sensible data in them, or are NULL.
- */
- *name_p = null_if_empty(strv[PK_PACKAGE_ID_NAME]);
- *version_p = null_if_empty(strv[PK_PACKAGE_ID_VERSION]);
- *arch_p = null_if_empty(strv[PK_PACKAGE_ID_ARCH]);
- *data_p = null_if_empty(strv[PK_PACKAGE_ID_DATA]);
-
- *strv_p = strv;
- success = TRUE;
- }
- return success;
-}
-
-/*
* Checks two strings with strcmp and emits TRUE if they match. If either
* string is NULL or empty, emit TRUE as well (this is so that missing
* PackageID elements trigger matches).
*/
-gboolean
+bool
string_match(const char *left, const char *right)
{
- int result;
+ bool result;
if (left == NULL || right == NULL)
- result = TRUE;
+ result = true;
else if (*left == '\0' || *right == '\0')
- result = TRUE;
+ result = true;
else
- result = (strcmp(left, right) == 0 ? TRUE : FALSE);
+ result = (strcmp(left, right) == 0);
return result;
}
Modified: soc2013/mattbw/backend/utils.h
==============================================================================
--- soc2013/mattbw/backend/utils.h Tue Jul 9 05:19:57 2013 (r254444)
+++ soc2013/mattbw/backend/utils.h Tue Jul 9 05:35:36 2013 (r254445)
@@ -1,5 +1,4 @@
/*-
- *
* Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
*
* Licensed under the GNU General Public License Version 2
@@ -22,20 +21,12 @@
#ifndef _PKGNG_BACKEND_UTILS_H_
#define _PKGNG_BACKEND_UTILS_H_
-#include <glib.h> /* gboolean */
+#include <stdbool.h> /* bool */
#define INTENTIONALLY_IGNORE(x) (void)(x)
#define ERR(backend, type, msg) \
(void) pk_backend_error_code((backend), (type), (msg))
-const char *null_if_empty(const char *in);
-gboolean
-split_id(const char *id,
- char ***strv_p,
- const char **name_p,
- const char **version_p,
- const char **arch_p,
- const char **data_p);
-gboolean string_match(const char *left, const char *right);
+bool string_match(const char *left, const char *right);
#endif /* !_PKGNG_BACKEND_DETAILS_H_ */
More information about the svn-soc-all
mailing list