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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//!
//! Base IPP definitions and tags
//!
use std::fmt;

use enum_primitive_derive::Primitive;

/// IPP protocol version
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum IppVersion {
    Ipp10 = 0x0100,
    Ipp11 = 0x0101,
    Ipp20 = 0x0200,
    Ipp21 = 0x0201,
    Ipp22 = 0x0202,
}

/// IPP operation constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum Operation {
    PrintJob = 0x0002,
    PrintUri = 0x0003,
    ValidateJob = 0x0004,
    CreateJob = 0x0005,
    SendDocument = 0x0006,
    SendUri = 0x0007,
    CancelJob = 0x0008,
    GetJobAttributes = 0x0009,
    GetJobs = 0x000A,
    GetPrinterAttributes = 0x000B,
    HoldJob = 0x000C,
    ReleaseJob = 0x000D,
    RestartJob = 0x000E,
    PausePrinter = 0x0010,
    ResumePrinter = 0x0011,
    PurgeJobs = 0x0012,

    CupsGetDefault = 0x4001,
    CupsGetPrinters = 0x4002,
    CupsAddModifyPrinter = 0x4003,
    CupsDeletePrinter = 0x4004,
    CupsGetClasses = 0x4005,
    CupsAddModifyClass = 0x4006,
    CupsDeleteClass = 0x4007,
    CupsAcceptJobs = 0x4008,
    CupsRejectJobs = 0x4009,
    CupsSetDefault = 0x400A,
    CupsGetDevices = 0x400B,
    CupsGetPPDs = 0x400C,
    CupsMoveJob = 0x400D,
    CupsAuthenticateJob = 0x400E,
    CupsGetPPD = 0x400F,
    CupsGetDocument = 0x4027,
    CupsCreateLocalPrinter = 0x4028,
}

/// printer-state constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum PrinterState {
    Idle = 3,
    Processing = 4,
    Stopped = 5,
}

/// paper orientation constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum Orientation {
    Portrait = 3,
    Landscape = 4,
    ReverseLandscape = 5,
    ReversePortrait = 6,
}

/// print-quality constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum PrintQuality {
    Draft = 3,
    Normal = 4,
    High = 5,
}

/// finishings constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum Finishings {
    None = 3,
    Staple = 4,
    Punch = 5,
    Cover = 6,
    Bind = 7,
    SaddleStitch = 8,
    EdgeStitch = 9,
}

/// job-state constants
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum JobState {
    Pending = 3,
    PendingHeld = 4,
    Processing = 5,
    ProcessingStopped = 6,
    Canceled = 7,
    Aborted = 8,
    Completed = 9,
}

/// group delimiter tags
#[derive(Primitive, Debug, Copy, Clone, PartialEq, Hash, Eq)]
pub enum DelimiterTag {
    OperationAttributes = 0x01,
    JobAttributes = 0x02,
    EndOfAttributes = 0x03,
    PrinterAttributes = 0x04,
    UnsupportedAttributes = 0x05,
}

/// IPP value tags
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum ValueTag {
    Unsupported = 0x10,
    Unknown = 0x12,
    NoValue = 0x13,
    Integer = 0x21,
    Boolean = 0x22,
    Enum = 0x23,
    OctetStringUnspecified = 0x30,
    DateTime = 0x31,
    Resolution = 0x32,
    RangeOfInteger = 0x33,
    BegCollection = 0x34,
    TextWithLanguage = 0x35,
    NameWithLanguage = 0x36,
    EndCollection = 0x37,
    TextWithoutLanguage = 0x41,
    NameWithoutLanguage = 0x42,
    Keyword = 0x44,
    Uri = 0x45,
    UriScheme = 0x46,
    Charset = 0x47,
    NaturalLanguage = 0x48,
    MimeMediaType = 0x49,
    MemberAttrName = 0x4a,
}

/// IPP status codes
#[derive(Primitive, Debug, Copy, Clone, PartialEq)]
pub enum StatusCode {
    SuccessfulOK = 0x0000,
    SuccessfulOKIgnoredOrSubstitutedAttributes = 0x0001,
    SuccessfulOKConflictingAttributes = 0x0002,
    ClientErrorBadRequest = 0x0400,
    ClientErrorForbidden = 0x0401,
    ClientErrorNotAuthenticated = 0x0402,
    ClientErrorNotAuthorized = 0x0403,
    ClientErrorNotPossible = 0x0404,
    ClientErrorTimeout = 0x0405,
    ClientErrorNotFound = 0x0406,
    ClientErrorGone = 0x0407,
    ClientErrorRequestEntityTooLong = 0x0408,
    ClientErrorRequestValueTooLong = 0x0409,
    ClientErrorDocumentFormatNotSupported = 0x040A,
    ClientErrorAttributesOrValuesNotSupported = 0x040B,
    ClientErrorUriSchemeNotSupported = 0x040C,
    ClientErrorCharsetNotSupported = 0x040D,
    ClientErrorConflictingAttributes = 0x040E,
    ClientErrorCompressionNotSupported = 0x040F,
    ClientErrorCompressionError = 0x0410,
    ClientErrorDocumentFormatError = 0x0411,
    ClientErrorDocumentAccessError = 0x0412,
    ServerErrorInternalError = 0x0500,
    ServerErrorOperationNotSupported = 0x0501,
    ServerErrorServiceUnavailable = 0x0502,
    ServerErrorVersionNotSupported = 0x0503,
    ServerErrorDeviceError = 0x0504,
    ServerErrorTemporaryError = 0x0505,
    ServerErrorNotAcceptingJobs = 0x0506,
    ServerErrorBusy = 0x0507,
    ServerErrorJobCanceled = 0x0508,
    ServerErrorMultipleDocumentJobsNotSupported = 0x0509,
}

impl fmt::Display for StatusCode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            StatusCode::SuccessfulOK => write!(f, "No error"),
            StatusCode::SuccessfulOKIgnoredOrSubstitutedAttributes => write!(f, "Ignored or substituted attributes"),
            StatusCode::SuccessfulOKConflictingAttributes => write!(f, "Conflicting attributes"),
            StatusCode::ClientErrorBadRequest => write!(f, "Bad request"),
            StatusCode::ClientErrorForbidden => write!(f, "Forbidden"),
            StatusCode::ClientErrorNotAuthenticated => write!(f, "Not authenticated"),
            StatusCode::ClientErrorNotAuthorized => write!(f, "Not authorized"),
            StatusCode::ClientErrorNotPossible => write!(f, "Not possible"),
            StatusCode::ClientErrorTimeout => write!(f, "Timeout"),
            StatusCode::ClientErrorNotFound => write!(f, "Not found"),
            StatusCode::ClientErrorGone => write!(f, "Gone"),
            StatusCode::ClientErrorRequestEntityTooLong => write!(f, "Entity too long"),
            StatusCode::ClientErrorRequestValueTooLong => write!(f, "Request value too long"),
            StatusCode::ClientErrorDocumentFormatNotSupported => write!(f, "Document format not supported"),
            StatusCode::ClientErrorAttributesOrValuesNotSupported => write!(f, "Attributes or values not supported"),
            StatusCode::ClientErrorUriSchemeNotSupported => write!(f, "Uri scheme not supported"),
            StatusCode::ClientErrorCharsetNotSupported => write!(f, "Charset not supported"),
            StatusCode::ClientErrorConflictingAttributes => write!(f, "Conflicting attributes"),
            StatusCode::ClientErrorCompressionNotSupported => write!(f, "Compression not supported"),
            StatusCode::ClientErrorCompressionError => write!(f, "Compression error"),
            StatusCode::ClientErrorDocumentFormatError => write!(f, "Document format error"),
            StatusCode::ClientErrorDocumentAccessError => write!(f, "Document access error"),
            StatusCode::ServerErrorInternalError => write!(f, "Internal error"),
            StatusCode::ServerErrorOperationNotSupported => write!(f, "Operation not supported"),
            StatusCode::ServerErrorServiceUnavailable => write!(f, "Service unavailable"),
            StatusCode::ServerErrorVersionNotSupported => write!(f, "Version not supported"),
            StatusCode::ServerErrorDeviceError => write!(f, "Device error"),
            StatusCode::ServerErrorTemporaryError => write!(f, "Temporary error"),
            StatusCode::ServerErrorNotAcceptingJobs => write!(f, "Not accepting jobs"),
            StatusCode::ServerErrorBusy => write!(f, "Busy"),
            StatusCode::ServerErrorJobCanceled => write!(f, "Job canceled"),
            StatusCode::ServerErrorMultipleDocumentJobsNotSupported => {
                write!(f, "Multiple document jobs not supported")
            }
        }
    }
}