From owner-svn-soc-all@FreeBSD.ORG Fri Jun 21 18:04:38 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 6207D7A0 for ; Fri, 21 Jun 2013 18:04:38 +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 538DC1D3B for ; Fri, 21 Jun 2013 18:04:38 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5LI4bXX083359 for ; Fri, 21 Jun 2013 18:04:37 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5LI4bYr083348 for svn-soc-all@FreeBSD.org; Fri, 21 Jun 2013 18:04:37 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 21 Jun 2013 18:04:37 GMT Message-Id: <201306211804.r5LI4bYr083348@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: r253322 - 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: Fri, 21 Jun 2013 18:04:38 -0000 Author: mattbw Date: Fri Jun 21 18:04:37 2013 New Revision: 253322 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253322 Log: some indent-ing, added flatsize, have not compiled yet, may not work. Will fix up later Added: soc2013/mattbw/dummy/.indent.pro Modified: soc2013/mattbw/dummy/get-details.c Added: soc2013/mattbw/dummy/.indent.pro ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/dummy/.indent.pro Fri Jun 21 18:04:37 2013 (r253322) @@ -0,0 +1,3 @@ +-TPkBackend +-Tgchar +-Tgboolean Modified: soc2013/mattbw/dummy/get-details.c ============================================================================== --- soc2013/mattbw/dummy/get-details.c Fri Jun 21 17:36:33 2013 (r253321) +++ soc2013/mattbw/dummy/get-details.c Fri Jun 21 18:04:37 2013 (r253322) @@ -24,36 +24,65 @@ #include "pk-backend.h" #include "pkg.h" +/* + * Checks two strings with strcmp and emits TRUE if they match. If either + * string is NULL, emit TRUE as well (this is so that missing PackageID + * elements trigger matches). + */ gboolean -get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend) +string_match(const char *left, const char *right) +{ + int result; + + if (left == NULL || right == NULL) + result = TRUE; + else + result = (strcmp(left, right) == 0 ? TRUE : FALSE); + + return result; +} + +/* + * Go through a database iterator of possible package matches and emit any + * that match the split PackageID. + */ +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; + struct pkg *match; found = FALSE; match = NULL; 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; + const char *arch; + const char *data; + const char *description; + const char *name; + const char *reponame; + const char *version; + const char *www; + pkg_t type; + int64_t flatsize; pkg_get(match, - PKG_NAME, &name, - PKG_VERSION, &version, - PKG_DESC, &description, - PKG_ARCH, &arch, - PKG_REPONAME, &reponame, - PKG_WWW, &www); + PKG_ARCH, &arch, + PKG_DESC, &description, + PKG_NAME, &name, + PKG_REPONAME, &reponame, + PKG_VERSION, &version, + PKG_WWW, &www, + PKG_FLATSIZE, &size); - switch(pkg_type(match)) { + switch (pkg_type(match)) { case PKG_FILE: data = "local"; break; @@ -65,24 +94,29 @@ break; } - 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; + /* + * Emit if this package's PackageID fields match the + * original PackageID. Of course, the original ID + * might have missing fields (NULLs), so we treat a + * comparison involving one as a success. + */ + if (string_match(name, id_name) && + string_match(version, id_version) && + string_match(arch, id_arch) && + string_match(data, id_data)) { + 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 - ); + new_id, + NULL, + PK_GROUP_ENUM_PROGRAMMING, + description, + www, + flatsize); g_free(new_id); } @@ -92,12 +126,13 @@ return found; } +/* Looks the split PackageID up in the local database. */ gboolean get_local_details(gchar *name, - gchar *version, - gchar *arch, - PkBackend *backend, - struct pkgdb *db) + gchar *version, + gchar *arch, + PkBackend *backend, + struct pkgdb *db) { struct pkgdb_it *it; gboolean success; @@ -106,22 +141,23 @@ it = pkgdb_query(db, name, MATCH_EXACT); if (it) success = get_details_check_matches( - it, - name, - version, - arch, - "installed", - backend); + it, + name, + version, + arch, + "installed", + backend); return success; } +/* Looks the split PackageID up in the remote database. */ gboolean get_remote_details(gchar *name, - gchar *version, - gchar *arch, - gchar *reponame, - PkBackend *backend, - struct pkgdb *db) + gchar *version, + gchar *arch, + gchar *reponame, + PkBackend *backend, + struct pkgdb *db) { struct pkgdb_it *it; gboolean success; @@ -130,35 +166,35 @@ it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); if (it) success = get_details_check_matches( - it, - name, - version, - arch, - reponame, - backend); + it, + name, + version, + arch, + reponame, + backend); return success; } gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) { - gchar **parts; + gchar **parts; gboolean success; success = FALSE; parts = pk_package_id_split(package_id); - if (parts == NULL) + if (parts == NULL) pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_ID_INVALID, - "invalid package id"); + PK_ERROR_ENUM_PACKAGE_ID_INVALID, + "invalid package id"); else { struct pkgdb_it *packages; /* Parts of the package ID */ - gchar *name; - gchar *version; - gchar *arch; - gchar *data; + gchar *name; + gchar *version; + gchar *arch; + gchar *data; name = parts[PK_PACKAGE_ID_NAME]; if (name != NULL && strlen(name) == 0) @@ -178,15 +214,16 @@ - /* If the PackageID is for an installed package, do a local query. - * If it is for a specific repo, do a remote query on it. - * And if the PackageID has no repository information at all, - * check both local and repo-generic remote. - * (TODO: local packages?) + /* + * If the PackageID is for an installed package, do a local + * query. If it is for a specific repo, do a remote query on + * it. And if the PackageID has no repository information at + * all, check both local and repo-generic remote. (TODO: + * local packages?) */ if (g_strcmp0(data, "installed") == 0) success = get_local_details(name, version, arch, backend, db); - else if (data != NULL) /* FIXME: treats 'local' as repo */ + else if (data != NULL) /* FIXME: treats 'local' as repo */ success = get_remote_details(name, version, arch, data, backend, db); else { /* TODO: ensure this is correct behaviour */ @@ -194,15 +231,16 @@ if (success == FALSE) success = get_remote_details(name, version, arch, data, backend, db); } - /* Assume any error is due to not finding packages. - * At time of writing this is true, but may change. + /* + * Assume any error is due to not finding packages. At time + * of writing this is true, but may change. */ if (success == FALSE) pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_NOT_FOUND, - "package not found"); + PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "package not found"); g_strfreev(parts); } - + return success; }