| 1 | ### | ||
| 2 | # Copyright (c) 2004 Matthias Hilbig <bighil@cpan.org> | ||
| 3 | # All rights reserved. | ||
| 4 | # | ||
| 5 | # This program is free software; you may redistribute it and/or modify it | ||
| 6 | # under the same terms as Perl itself. | ||
| 7 | # | ||
| 8 | |||
| 9 | package Net::IPP::IPPMethods; | ||
| 10 | |||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use Net::IPP::IPP qw(:all); | ||
| 15 | use Net::IPP::IPPRequest qw(:all); | ||
| 16 | |||
| 17 | require Exporter; | ||
| 18 | our @ISA = ("Exporter"); | ||
| 19 | our @EXPORT_OK = qw(setRequestedAttributes getPrinterAttributes getJobs getJobAttributes); | ||
| 20 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | ||
| 21 | |||
| 22 | our $request_id = 0; | ||
| 23 | our $requestedAttributes = ["all"]; | ||
| 24 | |||
| 25 | ### | ||
| 26 | # Set requested attributes to use in IPP Requests. | ||
| 27 | # | ||
| 28 | # Parameter: $attribs - scalar or reference to array with requested attributes | ||
| 29 | # use setRequestedAttributes("all") to get every attribute | ||
| 30 | # | ||
| 31 | sub setRequestedAttributes($) { | ||
| 32 | my $attribs = shift; | ||
| 33 | |||
| 34 | if (ref($attribs) eq 'SCALAR') { | ||
| 35 | $requestedAttributes = [$attribs]; | ||
| 36 | } elsif(ref($attribs) eq 'ARRAY') { | ||
| 37 | $requestedAttributes = $attribs; | ||
| 38 | } else { | ||
| 39 | confess ("Expected scalar or reference to array"); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | ### | ||
| 44 | # Get Printer Attributes | ||
| 45 | # | ||
| 46 | # Parameter: $url - URL of printer object | ||
| 47 | # | ||
| 48 | # return: response to IPP request | ||
| 49 | # | ||
| 50 | sub getPrinterAttributes($) { | ||
| 51 | my $url = shift; | ||
| 52 | |||
| 53 | my $request = { | ||
| 54 | &URL => $url, | ||
| 55 | &REQUEST_ID => $request_id++, | ||
| 56 | &OPERATION => &IPP_GET_PRINTER_ATTRIBUTES, | ||
| 57 | &GROUPS => [ | ||
| 58 | { | ||
| 59 | &TYPE => &OPERATION_ATTRIBUTES, | ||
| 60 | "attributes-charset" => "utf-8", | ||
| 61 | "attributes-natural-language" => "en", | ||
| 62 | "printer-uri" => $url, | ||
| 63 | "requested-attributes" => $requestedAttributes, | ||
| 64 | } | ||
| 65 | ] | ||
| 66 | }; | ||
| 67 | |||
| 68 | return ippRequest($request); | ||
| 69 | } | ||
| 70 | |||
| 71 | ### | ||
| 72 | # Get Jobs | ||
| 73 | # | ||
| 74 | # Parameter: $url - URL of printer object | ||
| 75 | # $completed - 1 return completed jobs, 0 return only uncompleted jobs | ||
| 76 | # | ||
| 77 | # return: response to IPP request | ||
| 78 | # | ||
| 79 | sub getJobs($$) { | ||
| 80 | my $url = shift; | ||
| 81 | my $completed = shift; | ||
| 82 | |||
| 83 | if ($completed) { | ||
| 84 | $completed = "completed"; | ||
| 85 | } else { | ||
| 86 | $completed = "not-completed"; | ||
| 87 | } | ||
| 88 | |||
| 89 | my $request = { | ||
| 90 | &URL => $url, | ||
| 91 | &REQUEST_ID => $request_id++, | ||
| 92 | &OPERATION => &IPP_GET_JOBS, | ||
| 93 | &GROUPS => [ | ||
| 94 | { | ||
| 95 | &TYPE => &OPERATION_ATTRIBUTES, | ||
| 96 | "attributes-charset" => "utf-8", | ||
| 97 | "attributes-natural-language" => "en", | ||
| 98 | "printer-uri" => $url, | ||
| 99 | "which-jobs" => $completed, | ||
| 100 | "requested-attributes" => $requestedAttributes, | ||
| 101 | } | ||
| 102 | ] | ||
| 103 | }; | ||
| 104 | |||
| 105 | return ippRequest($request); | ||
| 106 | } | ||
| 107 | |||
| 108 | ### | ||
| 109 | # Get Job Attributes | ||
| 110 | # | ||
| 111 | # Parameter: $url - URL of printer object | ||
| 112 | # $jobId - ID of job | ||
| 113 | # | ||
| 114 | # return: response to IPP request | ||
| 115 | # | ||
| 116 | sub getJobAttributes($$) { | ||
| 117 | my $url = shift; | ||
| 118 | my $jobId = shift; | ||
| 119 | |||
| 120 | my $request = { | ||
| 121 | &URL => $url, | ||
| 122 | &REQUEST_ID => $request_id++, | ||
| 123 | &OPERATION => &IPP_GET_JOB_ATTRIBUTES, | ||
| 124 | &GROUPS => [ | ||
| 125 | { | ||
| 126 | &TYPE => &OPERATION_ATTRIBUTES, | ||
| 127 | "attributes-charset" => "utf-8", | ||
| 128 | "attributes-natural-language" => "en", | ||
| 129 | "printer-uri" => $url, | ||
| 130 | "job-id" => $jobId, | ||
| 131 | "requested-attributes" => $requestedAttributes, | ||
| 132 | } | ||
| 133 | ] | ||
| 134 | }; | ||
| 135 | |||
| 136 | return ippRequest($request); | ||
| 137 | } | ||
| 138 | |||
| 139 | ### | ||
| 140 | # Print Job | ||
| 141 | # | ||
| 142 | # Parameter: $url - URL of printer object | ||
| 143 | # $name - Name of print job | ||
| 144 | # $user - User who submitted the print job | ||
| 145 | # $format - Document format of print job (f.e. application/postscript) | ||
| 146 | # $data - Data of print job | ||
| 147 | # | ||
| 148 | # return: response to IPP request | ||
| 149 | # | ||
| 150 | sub printJob($$$$$) { | ||
| 151 | my $url = shift; | ||
| 152 | my $name = shift; | ||
| 153 | my $user = shift; | ||
| 154 | my $format = shift; | ||
| 155 | my $data = shift; | ||
| 156 | |||
| 157 | my $request = { | ||
| 158 | &URL => $url, | ||
| 159 | &REQUEST_ID => $request_id++, | ||
| 160 | &OPERATION => &IPP_PRINT_JOB, | ||
| 161 | &DATA => $data, | ||
| 162 | &GROUPS => [ | ||
| 163 | { | ||
| 164 | &TYPE => &OPERATION_ATTRIBUTES, | ||
| 165 | "attributes-charset" => "utf-8", | ||
| 166 | "attributes-natural-language" => "en", | ||
| 167 | "printer-uri" => $url, | ||
| 168 | "requesting-user-name" => $user, | ||
| 169 | "document-format" => $format, | ||
| 170 | "document-name" => $name, | ||
| 171 | "requested-attributes" => $requestedAttributes, | ||
| 172 | } | ||
| 173 | ] | ||
| 174 | }; | ||
| 175 | |||
| 176 | return ippRequest($request); | ||
| 177 | } | ||
| 178 | |||
| 179 | 1; | ||
| 180 | __END__ |