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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use num_traits::FromPrimitive;
use consts::operation::Operation;
use consts::statuscode::StatusCode;
use request::{IppRequestResponse, IppRequestTrait};
pub type IppServerResult = Result<IppRequestResponse, StatusCode>;
pub trait IppServer<'b, 'c> {
type IppRequest: IppRequestTrait;
fn print_job(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn print_uri(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn validate_job(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn create_job(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn send_document(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn send_uri(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn cancel_job(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn get_job_attributes(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn get_jobs(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn get_printer_attributes(&self, _req: &mut Self::IppRequest) -> IppServerResult;
fn hold_job(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn release_job(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn restart_job(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn pause_printer(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn resume_printer(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn purge_jobs(&self, _req: &mut Self::IppRequest) -> IppServerResult {
Err(StatusCode::ServerErrorOperationNotSupported)
}
fn get_version(&self) -> u16 {
0x0101
}
fn ipp_handle_request(&self, req: &mut Self::IppRequest) -> IppServerResult {
if req.header().version != self.get_version() {
return Err(StatusCode::ServerErrorVersionNotSupported);
}
let operation = Operation::from_u16(req.header().operation_status)
.ok_or(StatusCode::ServerErrorOperationNotSupported)?;
match operation {
Operation::PrintJob => self.print_job(req),
Operation::PrintUri => self.print_uri(req),
Operation::ValidateJob => self.validate_job(req),
Operation::CreateJob => self.create_job(req),
Operation::SendDocument => self.send_document(req),
Operation::SendUri => self.send_uri(req),
Operation::CancelJob => self.cancel_job(req),
Operation::GetJobAttributes => self.get_job_attributes(req),
Operation::GetJobs => self.get_jobs(req),
Operation::GetPrinterAttributes => self.get_printer_attributes(req),
Operation::HoldJob => self.hold_job(req),
Operation::ReleaseJob => self.release_job(req),
Operation::RestartJob => self.restart_job(req),
Operation::PausePrinter => self.pause_printer(req),
Operation::ResumePrinter => self.resume_printer(req),
Operation::PurgeJobs => self.purge_jobs(req),
}
}
}