linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Piter PUNK <piterpunk@unitednerds.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] Add compressed ID database support to (usb|pci)-db
Date: Tue, 22 Sep 2009 02:42:33 +0000	[thread overview]
Message-ID: <4AB83999.1060004@unitednerds.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 490 bytes --]

Hi

usbutils and pciutils have support to gzip'ed ID databases. But, if I 
use usb.ids.gz
or pci.ids.gz, usb-db and pci-db can't  show anything, giving only an 
error of
file not found. Looking in the code, they didn't have any support to 
compressed
ID files.

This patch add support to gzip'ed database files to usb-db.c and add the 
option
--disable-zlib to configure.ac. Most of code here come from usbutils names.c
file with little modifications to work with udev.

Bye,

Piter PUNK



[-- Attachment #2: udev-zlib-support.patch --]
[-- Type: text/plain, Size: 3111 bytes --]

diff --git a/configure.ac b/configure.ac
index 3afb94a..5a273e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AC_DISABLE_STATIC
 AC_USE_SYSTEM_EXTENSIONS
 AC_SYS_LARGEFILE
 AC_CONFIG_MACRO_DIR([m4])
-LT_INIT
+m4_ifdef([LT_INIT],[LT_INIT],[AC_PROG_LIBTOOL])
 AC_PROG_AWK
 GTK_DOC_CHECK(1.10)
 AC_PREFIX_DEFAULT([/usr])
@@ -69,6 +69,22 @@ if test "x$enable_extras" = xyes; then
 	PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82)
 	AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)])
 
+	USE_ZLIB=yes
+	AC_ARG_ENABLE(zlib,
+		AS_HELP_STRING(--disable-zlib,disable support for zlib),
+		[
+			if eval "test x$enable_zlib = xno"; then
+				USE_ZLIB=
+			fi
+		])
+	if test "$USE_ZLIB" = "yes" ; then
+		AC_CHECK_LIB(z, inflateEnd)
+		if test "${ac_cv_lib_z_inflateEnd}" = "yes" ; then
+			HAVE_ZLIB="yes"
+		fi
+	fi
+	AM_CONDITIONAL(HAVE_ZLIB, test x$HAVE_ZLIB = xyes)
+
 	AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids])
 	AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids])
 	AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids])
diff --git a/extras/usb-db/usb-db.c b/extras/usb-db/usb-db.c
index db1f843..1381c3c 100644
--- a/extras/usb-db/usb-db.c
+++ b/extras/usb-db/usb-db.c
@@ -39,6 +39,19 @@
 # error "Are you havin' a laugh?"
 #endif
 
+#ifdef HAVE_LIBZ
+#include <zlib.h>
+#define         data_file                        gzFile
+#define         data_fopen(path, mode)           gzopen(path, mode)
+#define         data_fgets(s, size, stream)      gzgets(stream, s, size)
+#define         data_close(f)                    gzclose(f)
+#else
+#define         data_file                        FILE*
+#define         data_fopen(path, mode)           fopen(path, mode)
+#define         data_fgets(s, size, stream)      fgets(s, size, stream)
+#define         data_close(f)                    fclose(f)
+#endif
+
 static int get_id_attr(
 	struct udev_device *parent,
 	const char *name,
@@ -98,29 +111,36 @@ static int lookup_vid_pid(
 	char **vendor,
 	char **product) {
 
-	FILE *f;
+	data_file f;
 	int ret = -1;
 	int found_vendor = 0;
-	char *line = NULL;
+	char buf[512], *line;
+	char *filename = DATABASE ;
 
 	*vendor = *product = NULL;
 
-	if (!(f = fopen(DATABASE, "r"))) {
+#ifdef HAVE_LIBZ
+	filename = DATABASE".gz";
+	if (!(f = data_fopen(filename, "r"))) {
+		filename = DATABASE;
+		if (!(f = data_fopen(filename, "r"))) {
+			fprintf(stderr, "Failed to open database file "DATABASE": %s\n", strerror(errno));
+			return -1;
+		}
+	}		
+#else
+	if (!(f = data_fopen(filename, "r"))) {
 		fprintf(stderr, "Failed to open database file "DATABASE": %s\n", strerror(errno));
 		return -1;
 	}
+#endif
 
 	for (;;) {
 		size_t n;
 
-		if (line) {
-			free(line);
-			line = NULL;
-		}
-
-		if (getline(&line, &n, f) < 0)
+		if (data_fgets(buf, sizeof(buf), f) < 0)
 			break;
-
+		line = buf;
 		rstrip(line);
 
 		if (line[0] == '#' || line[0] == 0)
@@ -171,8 +191,7 @@ static int lookup_vid_pid(
 	ret = 0;
 
 finish:
-	free(line);
-	fclose(f);
+	data_close(f);
 
 	if (ret < 0) {
 		free(*product);

             reply	other threads:[~2009-09-22  2:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-22  2:42 Piter PUNK [this message]
2009-09-22 22:28 ` [PATCH] Add compressed ID database support to (usb|pci)-db Ozan Çağlayan
2009-09-23  4:33 ` Piter PUNK
2009-09-29 22:48 ` Lennart Poettering
2009-09-29 23:04 ` David Zeuthen
2009-09-29 23:31 ` Lennart Poettering
2009-09-29 23:41 ` Piter PUNK
2009-09-29 23:43 ` Piter PUNK
2009-09-30  0:03 ` Lennart Poettering
2009-09-30  0:08 ` Lennart Poettering
2009-09-30  1:16 ` Piter PUNK
2009-09-30  1:56 ` Greg KH
2009-09-30  2:50 ` Piter PUNK
2009-09-30  9:10 ` Frederic Crozat
2009-09-30 14:39 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AB83999.1060004@unitednerds.org \
    --to=piterpunk@unitednerds.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).