From owner-svn-soc-all@FreeBSD.ORG Thu Jun 20 19:29:26 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 347609F1 for ; Thu, 20 Jun 2013 19:29:26 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::16:124]) by mx1.freebsd.org (Postfix) with ESMTP id 17E3F1144 for ; Thu, 20 Jun 2013 19:29:26 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5KJTPfL035390 for ; Thu, 20 Jun 2013 19:29:25 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5KJTP3E035385 for svn-soc-all@FreeBSD.org; Thu, 20 Jun 2013 19:29:25 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 20 Jun 2013 19:29:25 GMT Message-Id: <201306201929.r5KJTP3E035385@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253294 - soc2013/mattbw/dummy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Jun 2013 19:29:26 -0000 Author: mattbw Date: Thu Jun 20 19:29:25 2013 New Revision: 253294 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253294 Log: Split off get-details implementation details to their own file. Temporarily force clang in Makefile. Added: soc2013/mattbw/dummy/get-details.c soc2013/mattbw/dummy/get-details.h Modified: soc2013/mattbw/dummy/Makefile soc2013/mattbw/dummy/pk-backend-pkgng.c Modified: soc2013/mattbw/dummy/Makefile ============================================================================== --- soc2013/mattbw/dummy/Makefile Thu Jun 20 18:25:10 2013 (r253293) +++ soc2013/mattbw/dummy/Makefile Thu Jun 20 19:29:25 2013 (r253294) @@ -1,8 +1,11 @@ # $FreeBSD$ +# Temporary +CC= clang + LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c +SRCS= pk-backend-pkgng.c get-details.c USE_PK_PKGCONF= 0 Added: soc2013/mattbw/dummy/get-details.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/dummy/get-details.c Thu Jun 20 19:29:25 2013 (r253294) @@ -0,0 +1,122 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "pk-backend.h" +#include "pkg.h" + +gboolean +get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend) +{ + gboolean found; + int err; + struct pkg *match; + + found = FALSE; + do { + err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC); + if (err == EPKG_OK) { + const char *name; + const char *version; + const char *description; + const char *arch; + const char *reponame; + const char *data; + const char *www; + pkg_t type; + + pkg_get2(match, + PKG_NAME, &name, + PKG_VERSION, &version, + PKG_DESC, &description, + PKG_ARCH, &arch, + PKG_REPONAME, &reponame, + PKG_WWW, &www); + + if (type == PKG_FILE) + data = "local"; + else if (type == PKG_INSTALLED) + data = "installed"; + else + data = reponame; + + if ((id_name == NULL || g_strcmp0(name, id_name) == 0) && + (id_version == NULL || g_strcmp0(version, id_version) == 0) && + (id_arch == NULL || g_strcmp0(arch, id_arch) == 0) && + (id_data == NULL || g_strcmp0(data, id_data) == 0)) { + gchar *new_id; + + found = TRUE; + new_id = pk_package_id_build(name, version, arch, data); + + /* TODO: implement category, size and licence */ + pk_backend_details(backend, + new_id, + NULL, + PK_GROUP_ENUM_PROGRAMMING, + description, + www, + 0 + ); + + g_free(new_id); + } + } + } while (err == EPKG_OK && found == FALSE); + + if (found == FALSE) + pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL); + + return found; +} + +gboolean +get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) +{ + gchar **parts; + gboolean success; + + success = FALSE; + + parts = pk_package_id_split(package_id); + if (parts == NULL) { + pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); + } else { + struct pkgdb_it *packages; + + packages = pkgdb_search(db, parts[PK_PACKAGE_ID_NAME], MATCH_EXACT, FIELD_NAME, NULL); + + if (packages) { + success = get_details_check_matches(packages, + parts[PK_PACKAGE_ID_NAME], + parts[PK_PACKAGE_ID_VERSION], + parts[PK_PACKAGE_ID_ARCH], + parts[PK_PACKAGE_ID_DATA], + backend); + + pkgdb_it_free(packages); + } else + pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL); + + g_strfreev(parts); + } + + return success; +} Added: soc2013/mattbw/dummy/get-details.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/dummy/get-details.h Thu Jun 20 19:29:25 2013 (r253294) @@ -0,0 +1,26 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _GET_DETAILS_H_ +#define _GET_DETAILS_H_ + +gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); + +#endif /* !_GET_DETAILS_H_ */ Modified: soc2013/mattbw/dummy/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/dummy/pk-backend-pkgng.c Thu Jun 20 18:25:10 2013 (r253293) +++ soc2013/mattbw/dummy/pk-backend-pkgng.c Thu Jun 20 19:29:25 2013 (r253294) @@ -30,6 +30,8 @@ #include "pk-backend.h" #include "pkg.h" +#include "get-details.h" + /* static bodges */ static guint _progress_percentage = 0; static gulong _signal_timeout = 0; @@ -171,106 +173,6 @@ pk_backend_finished(backend); } - -gboolean -get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend) -{ - gboolean found; - int err; - struct pkg *match; - - found = FALSE; - do { - err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC); - if (err == EPKG_OK) { - const char *name; - const char *version; - const char *description; - const char *arch; - const char *reponame; - const char *data; - const char *www; - pkg_t type; - - pkg_get2(match, - PKG_NAME, &name, - PKG_VERSION, &version, - PKG_DESC, &description, - PKG_ARCH, &arch, - PKG_REPONAME, &reponame, - PKG_WWW, &www); - - if (type == PKG_FILE) - data = "local"; - else if (type == PKG_INSTALLED) - data = "installed"; - else - data = reponame; - - if ((id_name == NULL || g_strcmp0(name, id_name) == 0) && - (id_version == NULL || g_strcmp0(version, id_version) == 0) && - (id_arch == NULL || g_strcmp0(arch, id_arch) == 0) && - (id_data == NULL || g_strcmp0(data, id_data) == 0)) { - gchar *new_id; - - found = TRUE; - new_id = pk_package_id_build(name, version, arch, data); - - /* TODO: implement category, size and licence */ - pk_backend_details(backend, - new_id, - NULL, - PK_GROUP_ENUM_PROGRAMMING, - description, - www, - 0 - ); - - g_free(new_id); - } - } - } while (err == EPKG_OK && found == FALSE); - - if (found == FALSE) - pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL); - - return found; -} - -gboolean -get_details_for(gchar *package_id, PkBackend *backend) -{ - gchar **parts; - gboolean success; - - success = FALSE; - - parts = pk_package_id_split(package_id); - if (parts == NULL) { - pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); - } else { - struct pkgdb_it *packages; - - packages = pkgdb_search(priv.db, parts[PK_PACKAGE_ID_NAME], MATCH_EXACT, FIELD_NAME, NULL); - - if (packages) { - success = get_details_check_matches(packages, - parts[PK_PACKAGE_ID_NAME], - parts[PK_PACKAGE_ID_VERSION], - parts[PK_PACKAGE_ID_ARCH], - parts[PK_PACKAGE_ID_DATA], - backend); - - pkgdb_it_free(packages); - } else - pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL); - - g_strfreev(parts); - } - - return success; -} - gboolean backend_get_details_thread(PkBackend *backend) { @@ -285,8 +187,8 @@ len = g_strv_length(package_ids); pk_backend_set_percentage(backend, 0); - for (i = 0, no_error_yet = TRUE; i < len, no_error_yet; i++) { - no_error_yet = get_details_for(package_ids[0], backend); + for (i = 0, no_error_yet = TRUE; i < len && no_error_yet; i++) { + no_error_yet = get_details_for(package_ids[0], backend, priv.db); pk_backend_set_percentage(backend, ((i * 100) / len)); }