Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jun 2013 00:08:26 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r253461 - in soc2013/mattbw: backend dummy tests tests/licence
Message-ID:  <201306250008.r5P08Qog089650@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Tue Jun 25 00:08:26 2013
New Revision: 253461
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253461

Log:
  get rid of dummy; add in testing for the licence part of get-details

Added:
  soc2013/mattbw/tests/
  soc2013/mattbw/tests/licence/
  soc2013/mattbw/tests/licence/Makefile
  soc2013/mattbw/tests/licence/lictest.c
Deleted:
  soc2013/mattbw/dummy/
Modified:
  soc2013/mattbw/backend/get-details.c
  soc2013/mattbw/backend/groups.c

Modified: soc2013/mattbw/backend/get-details.c
==============================================================================
--- soc2013/mattbw/backend/get-details.c	Mon Jun 24 23:41:16 2013	(r253460)
+++ soc2013/mattbw/backend/get-details.c	Tue Jun 25 00:08:26 2013	(r253461)
@@ -29,6 +29,7 @@
 #include "get-details.h"	/* get_details_thread prototype */
 
 /* TODO: move out of get-details? */
+const char     *null_if_empty(const char *in);
 gboolean	string_match(const char *left, const char *right);
 static gboolean
 get_details_query(const gchar *name,
@@ -190,6 +191,18 @@
 	return success;
 }
 
+/*
+ * 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;
+}
+
 gboolean
 get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db)
 {
@@ -205,28 +218,19 @@
 				      "invalid package id");
 	else {
 		/* Parts of the package ID */
-		gchar          *name;
-		gchar          *version;
-		gchar          *arch;
-		gchar          *data;
-
-		name = parts[PK_PACKAGE_ID_NAME];
-		if (name != NULL && strlen(name) == 0)
-			name = NULL;
-
-		version = parts[PK_PACKAGE_ID_VERSION];
-		if (version != NULL && strlen(version) == 0)
-			version = NULL;
-
-		arch = parts[PK_PACKAGE_ID_ARCH];
-		if (arch != NULL && strlen(arch) == 0)
-			arch = NULL;
-
-		data = parts[PK_PACKAGE_ID_DATA];
-		if (data != NULL && strlen(data) == 0)
-			data = NULL;
-
+		const gchar    *name;
+		const gchar    *version;
+		const gchar    *arch;
+		const gchar    *data;
 
+		/*
+		 * Make really really REALLY sure that the PackageID fields
+		 * either have sensible data in them, or are NULL.
+		 */
+		name = null_if_empty(parts[PK_PACKAGE_ID_NAME]);
+		version = null_if_empty(parts[PK_PACKAGE_ID_VERSION]);
+		arch = null_if_empty(parts[PK_PACKAGE_ID_ARCH]);
+		data = null_if_empty(parts[PK_PACKAGE_ID_DATA]);
 
 		/*
 		 * If the PackageID has a repository specified (even if it's

Modified: soc2013/mattbw/backend/groups.c
==============================================================================
--- soc2013/mattbw/backend/groups.c	Mon Jun 24 23:41:16 2013	(r253460)
+++ soc2013/mattbw/backend/groups.c	Tue Jun 25 00:08:26 2013	(r253461)
@@ -26,7 +26,7 @@
 
 #include "groups.h"		/* prototypes */
 
-const char ORIGIN_SEPARATOR = '/';
+const char	ORIGIN_SEPARATOR = '/';
 
 struct group_mapping {
 	const char     *dir;
@@ -39,6 +39,10 @@
  * 
  * Some of these mappings are a bit iffy, peer review would be greatly
  * appreciated.
+ * 
+ * These should ALWAYS be in alphabetical order of ports directories.  This is
+ * in case anything relies on this property when searching this list (for
+ * example binary searching)
  */
 static struct group_mapping group_mappings[] = {
 	{"accessibility", PK_GROUP_ENUM_ACCESSIBILITY},
@@ -142,16 +146,17 @@
 group_from_origin(const char *origin)
 {
 	char           *dir;
-	char	       *sep;
+	char           *sep;
 	PkGroupEnum	group;
 
 	/* Find the separation between dir and port name */
 	sep = strchr(origin, ORIGIN_SEPARATOR);
 
-	/* Is this a valid origin (did it have a separator)?
-	 * If not, we want the default group.
-	 * If so, then the number of chars between the origin start and the
-	 * separator mark the port directory name we want to use.
+	/*
+	 * Is this a valid origin (did it have a separator)? If not, we want
+	 * the default group. If so, then the number of chars between the
+	 * origin start and the separator mark the port directory name we
+	 * want to use.
 	 */
 	dir = (sep == NULL ? NULL : strndup(origin, sep - origin));
 	group = group_from_port_dir(dir);

Added: soc2013/mattbw/tests/licence/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/tests/licence/Makefile	Tue Jun 25 00:08:26 2013	(r253461)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+PROG=		lictest
+CFLAGS+=	`pkgconf --cflags pkg`
+LDFLAGS+=	`pkgconf --libs pkg`
+
+.include <bsd.prog.mk>

Added: soc2013/mattbw/tests/licence/lictest.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/tests/licence/lictest.c	Tue Jun 25 00:08:26 2013	(r253461)
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "pkg.h"
+
+void handle_it(struct pkgdb_it *it);
+int getdb(struct pkgdb **db);
+
+int
+getdb(struct pkgdb **db)
+{
+	int err;
+
+	/* err = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_REPO);
+
+	if (err == EPKG_ENOACCESS)
+		fprintf(stderr, "check your privilege\n", err);
+	else if (err != EPKG_OK)
+		fprintf(stderr, "access error: %i\n", err);
+	else */{
+		err = pkgdb_open(db, PKGDB_REMOTE);
+		if (err != EPKG_OK)
+			fprintf(stderr, "open error: %i\n", err);
+	}
+	return err;
+}
+
+int
+main(int argc, char **argv)
+{
+	struct pkgdb *db;
+	int err;
+
+	db = NULL;
+
+	err = (argc == 2 ? EPKG_OK : EPKG_FATAL);
+	if (err == EPKG_OK) {
+		err = pkg_init(NULL);
+		if (err != EPKG_OK)
+			fprintf(stderr, "could not parse config file\n");
+	} else
+		fprintf(stderr, "usage: %s name\n", argv[0]);
+
+	if (err == EPKG_OK)
+		err = getdb(&db);
+
+	if (err == EPKG_OK) {
+		struct pkgdb_it *it;
+
+		it = pkgdb_query(db, argv[1], MATCH_EXACT);
+		if (it == NULL)
+			printf("no local matches!\n");
+		else handle_it(it);
+
+		it = pkgdb_rquery(db, argv[1], MATCH_EXACT, NULL);
+		if (it == NULL)
+			printf("no remote matches!\n");
+		else handle_it(it);
+
+		printf("shutting down\n");
+		pkgdb_it_free(it);
+		pkgdb_close(db);
+		pkg_shutdown();
+		printf("shutdown\n");
+	}
+}
+
+
+void
+handle_it(struct pkgdb_it *it)
+{
+	int err;
+	struct pkg *match;
+
+	match = NULL;
+	do {
+		err = pkgdb_it_next(it, &match, PKG_LOAD_BASIC | PKG_LOAD_LICENSES);
+		if (err == EPKG_OK) {
+			const char *name;
+			struct pkg_license *lic;
+			int err2;
+
+			lic = NULL;
+
+			pkg_get(match, PKG_NAME, &name);
+			printf("name: %s\n", name);
+
+			do {
+				err2 = pkg_licenses(match, &lic);
+				if (err2 == EPKG_OK)
+					printf("  licence: %s\n", pkg_license_name(lic));
+			} while (err2 == EPKG_OK);
+		}
+
+	} while (err == EPKG_OK);
+
+	pkg_free(match);
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306250008.r5P08Qog089650>