[Pkg-cups-devel] r619 - in cupsys/branches/cups-1.2-ubuntu: . debian debian/local/backends

Martin Pitt mpitt at alioth.debian.org
Mon Nov 26 09:10:40 UTC 2007


Author: mpitt
Date: Mon Nov 26 09:10:40 2007
New Revision: 619

Log:
* debian/local/backends/dnssd, debian/rules, debian/cupsys.install,
  debian/cupsys.postinst, debian/cupsys.prerm, debian/cupsys.templates,
  debian/control:
  Added printer discovery backend "dnssd". Several cheaper printers, like
  the HP Color LaserJet 2600n, are not discovered by the "snmp" backend.
  In addition, this backend extracts more info from the printers than the
  "snmp" backend, like for example available page description languages.
  This leads to better driver choises for unknown printer models.

Added:
   cupsys/branches/cups-1.2-ubuntu/debian/local/backends/
   cupsys/branches/cups-1.2-ubuntu/debian/local/backends/dnssd
Modified:
   cupsys/branches/cups-1.2-ubuntu/   (props changed)
   cupsys/branches/cups-1.2-ubuntu/debian/changelog
   cupsys/branches/cups-1.2-ubuntu/debian/control
   cupsys/branches/cups-1.2-ubuntu/debian/cupsys.install
   cupsys/branches/cups-1.2-ubuntu/debian/cupsys.postinst
   cupsys/branches/cups-1.2-ubuntu/debian/cupsys.prerm
   cupsys/branches/cups-1.2-ubuntu/debian/cupsys.templates
   cupsys/branches/cups-1.2-ubuntu/debian/rules

Modified: cupsys/branches/cups-1.2-ubuntu/debian/changelog
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/changelog	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/changelog	Mon Nov 26 09:10:40 2007
@@ -1,3 +1,16 @@
+cupsys (1.3.4-1ubuntu2) UNRELEASED; urgency=low
+
+  * debian/local/backends/dnssd, debian/rules, debian/cupsys.install,
+    debian/cupsys.postinst, debian/cupsys.prerm, debian/cupsys.templates,
+    debian/control:
+    Added printer discovery backend "dnssd". Several cheaper printers, like
+    the HP Color LaserJet 2600n, are not discovered by the "snmp" backend.
+    In addition, this backend extracts more info from the printers than the
+    "snmp" backend, like for example available page description languages.
+    This leads to better driver choises for unknown printer models.
+
+ -- Till Kamppeter <till.kamppeter at gmail.com>  Fri, 23 Nov 2007 12:01:06 +0000
+
 cupsys (1.3.4-1ubuntu1) hardy; urgency=low
 
   * Merge new upstream version from Debian.

Modified: cupsys/branches/cups-1.2-ubuntu/debian/control
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/control	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/control	Mon Nov 26 09:10:40 2007
@@ -54,7 +54,7 @@
 Depends: ${shlibs:Depends}, debconf (>= 1.2.9) | debconf-2.0, poppler-utils | xpdf-utils, perl-modules, procps, ghostscript, lsb-base (>= 3), cupsys-common, ssl-cert (>= 1.0.11), adduser, sysv-rc (>= 2.86.ds1-14.1ubuntu2)
 Replaces: cupsys-pstoraster
 Conflicts: cupsys-pstoraster (<< 2)
-Recommends: cupsys-client, smbclient (>= 3.0.9), foomatic-filters
+Recommends: cupsys-client, smbclient (>= 3.0.9), foomatic-filters, avahi-utils
 Suggests: cupsys-bsd, cupsys-driver-gutenprint | cupsys-driver-gimpprint, foomatic-filters-ppds, xpdf-korean | xpdf-japanese | xpdf-chinese-traditional | xpdf-chinese-simplified, cups-pdf, hplip
 Description: Common UNIX Printing System(tm) - server
  The Common UNIX Printing System (or CUPS(tm)) is a printing system and 

Modified: cupsys/branches/cups-1.2-ubuntu/debian/cupsys.install
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/cupsys.install	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/cupsys.install	Mon Nov 26 09:10:40 2007
@@ -34,6 +34,7 @@
 usr/share/man/man8/cups-driverd.8.gz
 usr/share/man/man8/cupsfilter.8.gz
 ../presubj usr/share/bug/cupsys/
+../local/backends/* usr/lib/cups/backend-available/
 ../local/filters/* usr/lib/cups/filter/
 ../local/*.ppd usr/share/ppd/cups-included/
 ../local/*.types usr/share/cups/mime/

Modified: cupsys/branches/cups-1.2-ubuntu/debian/cupsys.postinst
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/cupsys.postinst	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/cupsys.postinst	Mon Nov 26 09:10:40 2007
@@ -94,7 +94,7 @@
 	list=`echo $SELECTED | sed -e 's/, /,/g'`
 	save_IFS=$IFS
 	IFS=,
-	(cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp)
+	(cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd)
 	for module in $list; do
 	  ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
 	  if [ "$module" = "ipp" ]; then
@@ -103,7 +103,7 @@
 	done
 	IFS=$save_IFS
         db_fset cupsys/backend changed false
-        
+
         # In cupsys 1.2.8-0ubuntu3 the defaults for the active backends
         # changed. snmp, scsi, and serial got added. So activate these
         # backends.
@@ -113,9 +113,17 @@
                 ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
             done
         fi
-        
+
+	# In cupsys 1.3.4-1ubuntu2 the "dnssd" backend got added
+	if dpkg --compare-versions "$2" lt-nl "1.3.4-1ubuntu2"; then
+	    for module in dnssd; do
+		[ -e /usr/lib/cups/backend/$module ] || \
+		ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
+	    done
+	fi
+
         # Resync Debconf database with real state
-        list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
+        list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp dnssd; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
         db_set cupsys/backend $list;
 
 	if [ -f /etc/cups/classes.conf ]; then

Modified: cupsys/branches/cups-1.2-ubuntu/debian/cupsys.prerm
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/cupsys.prerm	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/cupsys.prerm	Mon Nov 26 09:10:40 2007
@@ -19,7 +19,7 @@
 
 case "$1" in
     remove)
-	(cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp)
+	(cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd)
         if [ -L /usr/lib/cups/backend/smb ]; then
             rm -f /usr/lib/cups/backend/smb 2>/dev/null || true
         fi

Modified: cupsys/branches/cups-1.2-ubuntu/debian/cupsys.templates
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/cupsys.templates	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/cupsys.templates	Mon Nov 26 09:10:40 2007
@@ -19,8 +19,8 @@
 
 Template: cupsys/backend
 Type: multiselect
-__Choices: ipp, lpd, parallel, scsi, serial, socket, usb, snmp
-Default: ipp, lpd, parallel, scsi, serial, socket, usb, snmp
+__Choices: ipp, lpd, parallel, scsi, serial, socket, usb, snmp, dnssd
+Default: ipp, lpd, parallel, scsi, serial, socket, usb, snmp, dnssd
 _Description: Printer communication backends:
  CUPS uses backend programs to communicate with the printer device or port.
  .

Added: cupsys/branches/cups-1.2-ubuntu/debian/local/backends/dnssd
==============================================================================
--- (empty file)
+++ cupsys/branches/cups-1.2-ubuntu/debian/local/backends/dnssd	Mon Nov 26 09:10:40 2007
@@ -0,0 +1,207 @@
+#!/usr/bin/perl
+# The above Perl path may vary on your system; fix it!!! -*- perl -*-
+
+# dnssd - Search for network printers with the avahi-browse command
+#         (Zeroconf, DNS-SD)
+
+# Printer discovery CUPS backend (like the SNMP backend)
+# See also http://qa.mandriva.com/show_bug.cgi?id=21812
+
+# Copyright 2007 Till Kamppeter <till.kamppeter at gmail.com>
+#
+#  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+#  USA.
+
+# Usage: 
+#
+# cp dnssd /usr/lib/cups/backend/
+# chmod 755 /usr/lib/cups/backend/dnssd
+# killall -HUP cupsd (or "/etc/init.d/cups restart", CUPS 1.1.x only)
+# lpinfo -v (or use any printer setup tool)
+
+#use strict;
+
+$0 =~ m!^(.*)/([^/]+)\s*$!;
+my $progname = ($2 || $0 || "dnssd");
+my $progpath = ($1 || "/usr/lib/cups/backend");
+
+if ($ARGV[0]){
+    die "This backend is only for printer discovery, not for actual printing.\n";
+}
+
+my $avahicmd = "avahi-browse -k -t -v -r -a 2> /dev/null";
+
+# IPs which are for computers, consider their printer entries as queues
+# set up with the local printing system (CUPS, LPD, Windows/Samba SMB, ...)
+my @ipblacklist = ();
+my $output;
+my ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri);
+
+open (AVAHI, "$avahicmd |") or exit 0;
+while (my $line = <AVAHI>) {
+    chomp ($line);
+    if ($line =~ /^\s*=\s+(\S+)\s+(\S+)\s+(.*?)\s+(\S+)\s+(\S+)\s*$/) {
+	# New item
+	$interface = $1;
+	$nettype = $2;
+	my $itemname = $3;
+	my $protocolinfo = $4;
+        if ($protocolinfo =~ /_workstation/) {
+	    $protocol = "computer";
+	} elsif ($protocolinfo =~ /_pdl-datastream/) {
+	    $protocol = "socket";
+	} elsif ($protocolinfo =~ /_printer/) {
+	    $protocol = "lpd";
+	#} elsif ($protocolinfo =~ /_ipp/) {
+	#    $protocol = "ipp";
+	}
+    } elsif ($line =~ /^\s*hostname\s*=\s*\[([^\]]+)\]\s*$/) {
+	$host = $1;
+	$host =~ s/\.local\.?$//;
+    } elsif ($line =~ /^\s*address\s*=\s*\[([^\]]+)\]\s*$/) {
+	$ip = $1;
+	if ($protocol eq "computer") {
+	    push (@ipblacklist, $ip);
+	    $protocol = "";
+	}
+    } elsif ($line =~ /^\s*port\s*=\s*\[([^\]]+)\]\s*$/) {
+	$port = $1;
+    } elsif ($line =~ /^\s*txt\s*=\s*\[(.+)\]\s*$/) {
+	my $info = $1;
+	if ($protocol) {
+	    my ($ty, $product, $pdls, $usb_MFG, $usb_MDL, $usb_DES, $usb_CMD) = 
+		("", "", "", "", "", "", "");
+	    while ($info =~ s/^\s*\"([^\"]+)\"\s*//) {
+		my $infoitem = $1;
+		if ($infoitem =~ /^([^=]*)=(.*)$/) {
+		    my $field = $1;
+		    my $content = $2;
+		    if ($field eq "ty") {
+			$ty = $content;
+		    } elsif ($field eq "product") {
+			$product = $content;
+			$product =~ s/^\((.*)\)$/$1/;
+		    } elsif ($field eq "usb_MFG") {
+			$usb_MFG = $content;
+		    } elsif ($field eq "usb_MDL") {
+			$usb_MDL = $content;
+		    } elsif ($field eq "usb_DES") {
+			$usb_DES = $content;
+		    } elsif ($field eq "usb_CMD") {
+			$usb_CMD = $content;
+		    } elsif ($field eq "rp") {
+			$uriext = $content;
+		    } elsif ($field eq "pdl") {
+			while ($content =~ s/^\s*([^\,]+?)\s*\,\s*//) {
+			    my $i = $1;
+			    if ($i =~ m!\b(postscript|ps)\b!i) {
+				$pdls .= "POSTSCRIPT,";
+			    } elsif ($i =~ m!\b(pdf)\b!i) {
+				$pdls .= "PDF,";
+			    } elsif ($i =~ m!\b(pcl6|pclxl|pxl)\b!i) {
+				$pdls .= "PCLXL,";
+			    } elsif ($i =~ m!\b(pcl[345][ce]?|pcl)\b!i) {
+				$pdls .= "PCL,";
+			    }
+			}
+			$pdls =~ s/\,$//;
+		    }
+		}
+	    }
+	    $usb_MDL ||= $ty;
+	    $usb_DES ||= $product;
+	    if ($usb_MFG) {
+		$make = $usb_MFG;
+	    } elsif ($usb_DES =~ /^KONICA\s+MINOLTA\b/i) { 
+		$make = "KONICA MINOLTA";
+	    } elsif ($usb_DES) {
+		$usb_DES =~ /^\s*(\S*)\b/;
+		$make = $1;
+	    }
+	    $model = $usb_MDL;
+	    if (!$model) {
+		$usb_DES =~ /^\s*\S*\s*(.*)$/;
+		$model = $1;
+	    }
+	    $usb_CMD ||= $pdls;
+	    my $extra;
+	    if ($protocol eq "socket") {
+		$uri = "socket://$ip:$port";
+		$extra = "Port $port";
+	    } elsif ($protocol eq "lpd") {
+		$uri = "lpd://$ip" . ($uriext ? "/$uriext" : "");
+		$extra = ($uriext ? "Queue: $uriext" : "Default queue");
+	    } elsif ($protocol eq "ipp") {
+		$uri = "ipp://$ip:$port" . ($uriext ? "/$uriext" : "");
+		$extra = ($uriext ? "Queue: $uriext" : "Default queue");
+	    }
+	    if ($make && $model) {
+		$make =~ s/Hewlett.?Packard/HP/i;
+		$make =~ s/Lexmark.?International/Lexmark/i;
+		$model =~ s/Hewlett.?Packard/HP/i;
+		$model =~ s/Lexmark.?International/Lexmark/i;
+		while ($model =~ s/^\s*$make\s*//i) {};
+		$makemodel = "$make $model";
+	    } elsif ($usb_DES) {
+		$makemodel = $usb_DES;
+	    } else {
+		$makemodel = "Unknown";
+	    }
+	    $deviceid = ($usb_MFG ? "MFG:$usb_MFG;" : "") .
+		($usb_MDL ? "MDL:$usb_MDL;" : "") .
+		($usb_DES ? "DES:$usb_DES;" : "") .
+		($usb_CMD ? "CMD:$usb_CMD;" : "");
+	    $deviceid .= "CLS:PRINTER;" if $deviceid;
+	    $output->{$ip}{$protocol}{$extra} =
+		"network $uri \"$makemodel\" \"$makemodel $ip ($extra)\" \"$deviceid\"\n";
+	    ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri) =
+		("", "", "", "", "", "", "", "", "", "", "", "", "", "");
+	}
+    }
+}
+
+foreach my $ip (keys(%{$output})) {
+    next if member($ip, @ipblacklist);
+    if ($output->{$ip}{"socket"}) {
+	foreach my $extra (keys(%{$output->{$ip}{"socket"}})) {
+	    if (keys(%{$output->{$ip}{"socket"}}) = 1) {
+		$output->{$ip}{"socket"}{$extra} =~
+		    s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
+	    }
+	    print $output->{$ip}{"socket"}{$extra};
+	}
+    } elsif ($output->{$ip}{"lpd"}) {
+	foreach my $extra (keys(%{$output->{$ip}{"lpd"}})) {
+	    if (keys(%{$output->{$ip}{"lpd"}}) = 1) {
+		$output->{$ip}{"lpd"}{$extra} =~
+		    s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
+	    }
+	    print $output->{$ip}{"lpd"}{$extra};
+	}
+    } elsif ($output->{$ip}{"ipp"}) {
+	foreach my $extra (keys(%{$output->{$ip}{"ipp"}})) {
+	    if (keys(%{$output->{$ip}{"ipp"}}) == 1) {
+		$output->{$ip}{"ipp"}{$extra} =~
+		    s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/;
+	    }
+	    print $output->{$ip}{"ipp"}{$extra};
+	}
+    }
+}
+
+exit 0;
+
+# member( $a, @b ) returns 1 if $a is in @b, 0 otherwise.
+sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 };

Modified: cupsys/branches/cups-1.2-ubuntu/debian/rules
==============================================================================
--- cupsys/branches/cups-1.2-ubuntu/debian/rules	(original)
+++ cupsys/branches/cups-1.2-ubuntu/debian/rules	Mon Nov 26 09:10:40 2007
@@ -62,8 +62,9 @@
 	# the system-config-printer applet
 	install -D -m 644 packaging/cups-dbus.conf $(DEB_DESTDIR)/../cupsys/etc/dbus-1/system.d/cups.conf
 
-	# Fix permissions of filters installed from debian/local/
+	# Fix permissions of filters/backends installed from debian/local/
 	chmod 755 debian/cupsys/usr/lib/cups/filter/*
+	chmod 755 debian/cupsys/usr/lib/cups/backend*/*
 
 	# install AppArmor profile
 	install -D -m 644 debian/local/apparmor-profile $(DEB_DESTDIR)/../cupsys/etc/apparmor.d/usr.sbin.cupsd



More information about the Pkg-cups-devel mailing list