From ac0b4ec2f0fdf95a2b26dcf91a540cf92448ee91 Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Thu, 19 Feb 2009 18:30:52 +0000 Subject: [PATCH] - Prevent cups-deviced missing devices (STR #3108). - Actually drop the perl implementation of the dnssd backend and use the avahi-aware one. --- cups-missing-devices.patch | 27 ++++ cups.spec | 21 ++- dnssd | 269 ------------------------------------- 3 files changed, 41 insertions(+), 276 deletions(-) create mode 100644 cups-missing-devices.patch delete mode 100644 dnssd diff --git a/cups-missing-devices.patch b/cups-missing-devices.patch new file mode 100644 index 0000000..6ad1160 --- /dev/null +++ b/cups-missing-devices.patch @@ -0,0 +1,27 @@ +diff -up cups-1.4b2/backend/dnssd.c.missing-devices cups-1.4b2/backend/dnssd.c +--- cups-1.4b2/backend/dnssd.c.missing-devices 2009-02-19 18:24:07.000000000 +0000 ++++ cups-1.4b2/backend/dnssd.c 2009-02-19 18:25:06.000000000 +0000 +@@ -437,6 +437,11 @@ main(int argc, /* I - Number of comm + best->name, NULL, NULL); + best->sent = 1; + best = device; ++ ++#ifdef HAVE_AVAHI ++ /* Hack so that cups-deviced doesn't miss anything (STR #3108). */ ++ sleep (1); ++#endif + } + else if (best->priority > device->priority || + (best->priority == device->priority && +@@ -458,6 +463,11 @@ main(int argc, /* I - Number of comm + cupsBackendReport("network", device_uri, best->make_and_model, + best->name, NULL, NULL); + best->sent = 1; ++ ++#ifdef HAVE_AVAHI ++ /* Hack so that cups-deviced doesn't miss anything (STR #3108). */ ++ sleep (1); ++#endif + } + } + } diff --git a/cups.spec b/cups.spec index 66ee699..b45ff3a 100644 --- a/cups.spec +++ b/cups.spec @@ -7,13 +7,12 @@ Summary: Common Unix Printing System Name: cups Version: 1.4 -Release: 0.%{pre}.6%{?dist} +Release: 0.%{pre}.7%{?dist} License: GPLv2 Group: System Environment/Daemons Source: ftp://ftp.easysw.com/pub/cups/test//cups-%{version}%{?pre}-source.tar.bz2 Source1: cups.init Source2: cupsprinter.png -Source3: http://www.openprinting.org/download/printing/dnssd Source4: pstopdf Source5: cups-lpd Source6: pstoraster @@ -50,6 +49,7 @@ Patch23: cups-str3077.patch Patch24: cups-str3078.patch Patch25: cups-str3059.patch Patch26: cups-avahi.patch +Patch27: cups-missing-devices.patch Patch100: cups-lspp.patch Epoch: 1 Url: http://www.cups.org/ @@ -83,7 +83,7 @@ BuildRequires: libjpeg-devel BuildRequires: libpng-devel BuildRequires: libtiff-devel BuildRequires: krb5-devel -BuildRequires: avahi-compat-libdns_sd-devel +BuildRequires: avahi-devel BuildRequires: poppler-utils %if %lspp @@ -193,6 +193,7 @@ module. %patch24 -p1 -b .str3078 %patch25 -p1 -b .str3059 %patch26 -p1 -b .avahi +%patch27 -p1 -b .missing-devices %if %lspp %patch100 -p1 -b .lspp @@ -206,6 +207,10 @@ perl -pi -e "s,\@LIBDIR\@,%{_libdir},g" cups-lpd.real # Let's look at the compilation command lines. perl -pi -e "s,^.SILENT:,," Makedefs.in +# Rebuild configure script for --enable-avahi. +aclocal -I config-scripts +autoconf -I config-scripts + %build export CFLAGS="-DLDAP_DEPRECATED=1" %configure --with-docdir=%{_datadir}/%{name}/www \ @@ -215,7 +220,7 @@ export CFLAGS="-DLDAP_DEPRECATED=1" %endif --with-log-file-perm=0600 --enable-pie --enable-relro \ --enable-pdftops --with-dbusdir=%{_sysconfdir}/dbus-1 \ - --with-php=/usr/bin/php-cgi \ + --with-php=/usr/bin/php-cgi --enable-avahi \ localedir=%{_datadir}/locale # If we got this far, all prerequisite libraries must be here. @@ -226,9 +231,6 @@ rm -rf $RPM_BUILD_ROOT make BUILDROOT=$RPM_BUILD_ROOT install -# Include Till Kamppeter's dnssd backend. -install -m 755 %{SOURCE3} $RPM_BUILD_ROOT%{cups_serverbin}/backend/dnssd - # Serial backend needs to run as root (bug #212577). chmod 700 $RPM_BUILD_ROOT%{cups_serverbin}/backend/serial @@ -459,6 +461,11 @@ rm -rf $RPM_BUILD_ROOT %{_libdir}/php/modules/*.so %changelog +* Thu Feb 19 2009 Tim Waugh 1:1.4-0.b2.7 +- Prevent cups-deviced missing devices (STR #3108). +- Actually drop the perl implementation of the dnssd backend and use + the avahi-aware one. + * Thu Feb 12 2009 Tim Waugh 1:1.4-0.b2.6 - Beginnings of avahi support. The dnssd backend should now work, but the scheduler will not yet advertise DNS-SD services. diff --git a/dnssd b/dnssd deleted file mode 100644 index 864db32..0000000 --- a/dnssd +++ /dev/null @@ -1,269 +0,0 @@ -#!/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 -# -# 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 @computerips = (); -my $output; -my $hosts; -my ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri); - -open (AVAHI, "$avahicmd |") or exit 0; -while (my $line = ) { - 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 (@computerips, $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") { - if ($port eq "9100") { - $uri = "socket://$ip"; - } else { - $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; - $hosts->{$ip} = $hostname if ($hostname); - $output->{$ip}{$protocol}{$uriext} = - "network $uri \"$makemodel\" \"$makemodel $ip ($extra)\" \"$deviceid\"\n"; - ($interface, $nettype, $ip, $host, $make, $model, $description, $cmd, $makemodel, $deviceid, $protocol, $port, $uriext, $uri) = - ("", "", "", "", "", "", "", "", "", "", "", "", "", ""); - } - } -} - -my $localqueues = {}; -my $queue = undef; -if (open LPSTAT, "LC_ALL=C lpstat -l -p -v |") { - while (my $line = ) { - chomp $line; - if ($line =~ /^printer\s+(\S+)/i) { - $queue = $1; - $localqueues->{$queue} = {}; - } elsif ($queue) { - if ($line =~ /^\s+Connection:\s+remote/i) { - $localqueues->{$queue}{remote} = 1; - } elsif ($line =~ /^\s+Interface:\s+(\S+)/i) { - $localqueues->{$queue}{interface} = $1; - } elsif ($line =~ /^device\s+for\s+(\S+)\s*:\s*(\S+)/i) { - $localqueues->{$1}{uri} = $2; - } - } - } - close LPSTAT -} - -my @localips = (); -if (open IFCONFIG, "LC_ALL=C /sbin/ifconfig |") { - while (my $line = ) { - chomp $line; - if ($line =~ /^\s*inet\s+addr:\s*(\S+)/i) { - push (@localips, $1); - } - } - close IFCONFIG; -} - -foreach my $ip (keys(%{$output})) { - # Do not list print queues of the local machine - next if member($ip, @localips); - if ($output->{$ip}{"socket"}) { - foreach my $uriext (keys(%{$output->{$ip}{"socket"}})) { - if (keys(%{$output->{$ip}{"socket"}}) == 1) { - $output->{$ip}{"socket"}{$uriext} =~ - s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/; - } - print $output->{$ip}{"socket"}{$uriext}; - } - } elsif ($output->{$ip}{"lpd"}) { - foreach my $uriext (keys(%{$output->{$ip}{"lpd"}})) { - if (keys(%{$output->{$ip}{"lpd"}}) == 1) { - $output->{$ip}{"lpd"}{$uriext} =~ - s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"\(]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/; - } - print $output->{$ip}{"lpd"}{$uriext}; - } - } elsif ($output->{$ip}{"ipp"}) { - foreach my $uriext (keys(%{$output->{$ip}{"ipp"}})) { - if ($uriext =~ /^(printers|classes)\/(\S+)$/) { - # Queue from a CUPS server. We should suppress it if it - # is a queue received via CUPS broadcast - $queue=$2; - if (defined($localqueues->{"$queue\@$ip"})) { - $queue = "$queue\@$ip"; - } elsif (defined($localqueues->{"$queue\@$hosts->{$ip}"})) { - $queue = "$queue\@$hosts->{$ip}"; - } - if (defined($localqueues->{$queue})) { - if ($localqueues->{$queue}{remote} && - ($localqueues->{$queue}{uri} =~ - /^ipp:\/\/([^\/:]+)(:\d+|)\/(\S+)/)) { - my $host = $1; - my $ue = $3; - if ($host !~ /\d+\.\d+\.\d+\.\d+/) { - $host = - join(".", unpack("C4", gethostbyname($host))); - } - next if ($host eq $ip) && ($ue eq $uriext); - } - } - } - if (keys(%{$output->{$ip}{"ipp"}}) == 1) { - $output->{$ip}{"ipp"}{$uriext} =~ - s/^(\s*\S*\s*\S*\s*\"[^\"]*\"\s*\"[^\"]*?)\s*\([^\)]*\)\s*(\"\s*.*)$/$1$2/; - } - print $output->{$ip}{"ipp"}{$uriext}; - } - } -} - -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 };