summaryrefslogtreecommitdiffstats
path: root/perl-install/printer/cups.pm
blob: 1de54edf225caf029ff68707d7b28c72d0917254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package printer::cups;

use strict;
use printer::data;

sub get_remote_queues {
    my ($printer) = $_[0];
    # The following code reads in a list of all remote printers which the
    # local CUPS daemon knows due to broadcasting of remote servers or 
    # "BrowsePoll" entries in the local /etc/cups/cupsd.conf
    local *F;
    open F, ($::testing ? $::prefix : "chroot $::prefix/ ") . 
	"lpstat -v |" or return ();
    my @printerlist;
    my $line;
    while ($line = <F>) {
	if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) {
	    my $queuename = $1;
	    if (($2 =~ m!^ipp://([^/:]+)[:/]!) &&
		(!$printer->{configured}{$queuename})) {
		my $server = $1;
		push (@printerlist, "$queuename|$server");
	    }
	}
    }
    close F;
    return @printerlist;
}

1;