1 // Sun, 18 Jun 2000 2 // Y.Takagi 3 4 #ifndef __IppContent_H 5 #define __IppContent_H 6 7 #ifdef WIN32 8 #include <istream> 9 #include <ostream> 10 #else 11 #include <istream.h> 12 #include <ostream.h> 13 #endif 14 #include <list> 15 #include <string> 16 17 #if (!__MWERKS__ || defined(WIN32)) 18 using namespace std; 19 #else 20 #define std 21 #endif 22 23 enum IPP_OPERATION_ID { 24 25 /* reserved, not used: 0x0000 */ 26 /* reserved, not used: 0x0001 */ 27 28 IPP_PRINT_JOB = 0x0002, // printer operation 29 IPP_PRINT_URI = 0x0003, // printer operation 30 IPP_VALIDATE_JOB = 0x0004, // printer operation 31 IPP_CREATE_JOB = 0x0005, // printer operation 32 33 IPP_SEND_DOCUMENT = 0x0006, // job operation 34 IPP_SEND_URI = 0x0007, // job operation 35 IPP_CANCEL_JOB = 0x0008, // job operation 36 IPP_GET_JOB_ATTRIBUTES = 0x0009, // job operation 37 38 IPP_GET_JOBS = 0x000A, // printer operation 39 IPP_GET_PRINTER_ATTRIBUTES = 0x000B // printer operation 40 41 /* reserved for future operations: 0x000C-0x3FFF */ 42 /* reserved for private extensions: 0x4000-0x8FFF */ 43 }; 44 45 enum IPP_STATUS_CODE { 46 47 IPP_SUCCESSFUL_OK_S = 0x0000, // successful 48 IPP_SUCCESSFUL_OK = 0x0000, // successful 49 IPP_SUCCESSFUL_OK_IGNORED_OR_SUBSTITUTED_ATTRIBUTES = 0x0001, // successful 50 IPP_SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES = 0x0002, // successful 51 IPP_SUCCESSFUL_OK_E = 0x00FF, // successful 52 53 IPP_INFORMATIONAL_S = 0x0100, // informational 54 IPP_INFORMATIONAL_E = 0x01FF, // informational 55 56 IPP_REDIRECTION_S = 0x0200, // redirection 57 IPP_REDIRECTION_SE = 0x02FF, // redirection 58 59 IPP_CLIENT_ERROR_S = 0x0400, // client-error 60 IPP_CLIENT_ERROR_BAD_REQUEST = 0x0400, // client-error 61 IPP_CLIENT_ERROR_FORBIDDEN = 0x0401, // client-error 62 IPP_CLIENT_ERROR_NOT_AUTHENTICATED = 0x0402, // client-error 63 IPP_CLIENT_ERROR_NOT_AUTHORIZED = 0x0403, // client-error 64 IPP_CLIENT_ERROR_NOT_POSSIBLE = 0x0404, // client-error 65 IPP_CLIENT_ERROR_TIMEOUT = 0x0405, // client-error 66 IPP_CLIENT_ERROR_NOT_FOUND = 0x0406, // client-error 67 IPP_CLIENT_ERROR_GONE = 0x0407, // client-error 68 IPP_CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = 0x0408, // client-error 69 IPP_CLIENT_ERROR_REQUEST_VALUE_TOO_LONG = 0x0409, // client-error 70 IPP_CLIENT_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED = 0x040A, // client-error 71 IPP_CLIENT_ERROR_ATTRIBUTES_OR_VALUES_NOT_SUPPORTED = 0x040B, // client-error 72 IPP_CLIENT_ERROR_URI_SCHEME_NOT_SUPPORTED = 0x040C, // client-error 73 IPP_CLIENT_ERROR_CHARSET_NOT_SUPPORTED = 0x040D, // client-error 74 IPP_CLIENT_ERROR_CONFLICTING_ATTRIBUTES = 0x040E, // client-error 75 IPP_CLIENT_ERROR_E = 0x04FF, // client-error 76 77 IPP_SERVER_ERROR_S = 0x0500, // server-error 78 IPP_SERVER_ERROR_INTERNAL_ERROR = 0x0500, // server-error 79 IPP_SERVER_ERROR_OPERATION_NOT_SUPPORTED = 0x0501, // server-error 80 IPP_SERVER_ERROR_SERVICE_UNAVAILABLE = 0x0502, // server-error 81 IPP_SERVER_ERROR_VERSION_NOT_SUPPORTED = 0x0503, // server-error 82 IPP_SERVER_ERROR_DEVICE_ERROR = 0x0504, // server-error 83 IPP_SERVER_ERROR_TEMPORARY_ERROR = 0x0505, // server-error 84 IPP_SERVER_ERROR_NOT_ACCEPTING_JOBS = 0x0506, // server-error 85 IPP_SERVER_ERROR_BUSY = 0x0507, // server-error 86 IPP_SERVER_ERROR_JOB_CANCELED = 0x0508, // server-error 87 IPP_SERVER_ERROR_E = 0x05FF // server-error 88 }; 89 90 enum IPP_TAG { 91 /* reserved: 0x00 */ 92 IPP_OPERATION_ATTRIBUTES_TAG = 0x01, 93 IPP_JOB_ATTRIBUTES_TAG = 0x02, 94 IPP_END_OF_ATTRIBUTES_TAG = 0x03, 95 IPP_PRINTER_ATTRIBUTES_TAG = 0x04, 96 IPP_UNSUPPORTED_ATTRIBUTES_TAG = 0x05, 97 /* reserved for future delimiters: 0x06-0x0e */ 98 /* reserved for future chunking-end-of-attributes-tag: 0x0F */ 99 100 IPP_UNSUPPORTED = 0x10, 101 /* reserved for future 'default': 0x11 */ 102 IPP_UNKNOWN = 0x12, 103 IPP_NO_VALUE = 0x13, 104 /* reserved for future "out-of-band" values: 0x14-0x1F */ 105 /* reserved: 0x20 */ 106 IPP_INTEGER = 0x21, 107 IPP_BOOLEAN = 0x22, 108 IPP_ENUM = 0x23, 109 /* reserved for future integer types: 0x24-0x2F */ 110 IPP_STRING = 0x30, 111 IPP_DATETIME = 0x31, 112 IPP_RESOLUTION = 0x32, 113 IPP_RANGE_OF_INTEGER = 0x33, 114 /* reserved for collection (in the future): 0x34 */ 115 IPP_TEXT_WITH_LANGUAGE = 0x35, 116 IPP_NAME_WITH_LANGUAGE = 0x36, 117 /* reserved for future octetString types: 0x37-0x3F */ 118 /* reserved: 0x40 */ 119 IPP_TEXT_WITHOUT_LANGUAGE = 0x41, 120 IPP_NAME_WITHOUT_LANGUAGE = 0x42, 121 /* reserved: 0x43 */ 122 IPP_KEYWORD = 0x44, 123 IPP_URI = 0x45, 124 IPP_URISCHEME = 0x46, 125 IPP_CHARSET = 0x47, 126 IPP_NATURAL_LANGUAGE = 0x48, 127 IPP_MIME_MEDIA_TYPE = 0x49 128 /* reserved for future character string types: 0x4A-0x5F */ 129 }; 130 131 enum IPP_RESOLUTION_UNITS { 132 IPP_DOTS_PER_INCH = 3, 133 IPP_DOTS_PER_CENTIMETER = 4 134 }; 135 136 enum IPP_FINISHINGS { 137 IPP_NONE = 3, 138 IPP_STAPLE = 4, 139 IPP_PUNCH = 5, 140 IPP_COVER = 6, 141 IPP_BIND = 7 142 }; 143 144 enum IPP_ORIENTATION_REQUESTED { 145 IPP_PORTRAIT = 3, 146 IPP_LANDSCAPE = 4, 147 IPP_REVERSE_LANDSCAPE = 5, 148 IPP_REVERSE_PORTRAIT = 6 149 }; 150 151 enum IPP_PRINT_QUALITY { 152 IPP_DRAFT = 3, 153 IPP_NORMAL = 4, 154 IPP_HIGH = 5 155 }; 156 157 enum IPP_JOB_STATE { 158 IPP_JOB_STATE_PENDING = 3, 159 IPP_JOB_STATE_PENDING_HELD = 4, 160 IPP_JOB_STATE_PROCESSING = 5, 161 IPP_JOB_STATE_PROCESSING_STOPPED= 6, 162 IPP_JOB_STATE_CANCELED = 7, 163 IPP_JOB_STATE_ABORTED = 8, 164 IPP_JOB_STATE_COMPLETED = 9 165 }; 166 167 enum IPP_PRINTER_STATE { 168 IPP_PRINTER_STATEIDLE = 3, 169 IPP_PRINTER_STATEPROCESSING = 4, 170 IPP_PRINTER_STATESTOPPED = 5 171 }; 172 173 174 class IppAttribute { 175 public: 176 IppAttribute(IPP_TAG); 177 virtual ~IppAttribute() {} 178 virtual int length() const; 179 virtual istream &input(istream &is); 180 virtual ostream &output(ostream &os) const; 181 virtual ostream &print(ostream &) const; 182 friend istream& operator >> (istream &is, IppAttribute &attr) 183 { 184 return attr.input(is); 185 } 186 friend ostream& operator << (ostream &os, const IppAttribute &attr) 187 { 188 return attr.output(os); 189 } 190 191 IPP_TAG tag; 192 }; 193 194 class IppNamedAttribute : public IppAttribute { 195 public: 196 IppNamedAttribute(IPP_TAG t); 197 IppNamedAttribute(IPP_TAG t, const char *n); 198 virtual ~IppNamedAttribute() {} 199 virtual int length() const; 200 virtual istream &input(istream &is); 201 virtual ostream &output(ostream &os) const; 202 string name; 203 friend istream& operator >> (istream &is, IppNamedAttribute &attr) 204 { 205 return attr.input(is); 206 } 207 friend ostream& operator << (ostream &os, const IppNamedAttribute &attr) 208 { 209 return attr.output(os); 210 } 211 virtual ostream &print(ostream &) const; 212 }; 213 214 class IppNoValueAttribute : public IppNamedAttribute { 215 public: 216 IppNoValueAttribute(IPP_TAG t); 217 IppNoValueAttribute(IPP_TAG t, const char *n); 218 virtual ~IppNoValueAttribute() {} 219 virtual int length() const; 220 virtual istream &input(istream &is); 221 virtual ostream &output(ostream &os) const; 222 virtual ostream &print(ostream &) const; 223 friend istream& operator >> (istream &is, IppNoValueAttribute &attr) 224 { 225 return attr.input(is); 226 } 227 friend ostream& operator << (ostream &os, const IppNoValueAttribute &attr) 228 { 229 return attr.output(os); 230 } 231 }; 232 233 class IppBooleanAttribute : public IppNamedAttribute { 234 public: 235 IppBooleanAttribute(IPP_TAG t); 236 IppBooleanAttribute(IPP_TAG t, const char *n, bool f); 237 virtual ~IppBooleanAttribute() {} 238 virtual int length() const; 239 virtual istream &input(istream &is); 240 virtual ostream &output(ostream &os) const; 241 virtual ostream &print(ostream &) const; 242 friend istream& operator >> (istream &is, IppBooleanAttribute &attr) 243 { 244 return attr.input(is); 245 } 246 friend ostream& operator << (ostream &os, const IppBooleanAttribute &attr) 247 { 248 return attr.output(os); 249 } 250 251 bool value; 252 }; 253 254 class IppIntegerAttribute : public IppNamedAttribute { 255 public: 256 IppIntegerAttribute(IPP_TAG t); 257 IppIntegerAttribute(IPP_TAG t, const char *n, int v); 258 virtual ~IppIntegerAttribute() {} 259 virtual int length() const; 260 virtual istream &input(istream &is); 261 virtual ostream &output(ostream &os) const; 262 virtual ostream &print(ostream &) const; 263 friend istream& operator >> (istream &is, IppIntegerAttribute &attr) 264 { 265 return attr.input(is); 266 } 267 friend ostream& operator << (ostream &os, const IppIntegerAttribute &attr) 268 { 269 return attr.output(os); 270 } 271 272 long value; 273 }; 274 275 class DATETIME { 276 public: 277 DATETIME(); 278 DATETIME(const DATETIME &); 279 DATETIME & operator = (const DATETIME &); 280 friend istream& operator >> (istream &is, DATETIME &attr); 281 friend ostream& operator << (ostream &os, const DATETIME &attr); 282 283 unsigned char datetime[11]; 284 }; 285 286 class IppDatetimeAttribute : public IppNamedAttribute { 287 public: 288 IppDatetimeAttribute(IPP_TAG t); 289 IppDatetimeAttribute(IPP_TAG t, const char *n, const DATETIME *dt); 290 virtual ~IppDatetimeAttribute() {} 291 virtual int length() const; 292 virtual istream &input(istream &is); 293 virtual ostream &output(ostream &os) const; 294 virtual ostream &print(ostream &) const; 295 friend istream& operator >> (istream &is, IppDatetimeAttribute &attr) 296 { 297 return attr.input(is); 298 } 299 friend ostream& operator << (ostream &os, const IppDatetimeAttribute &attr) 300 { 301 return attr.output(os); 302 } 303 304 DATETIME datetime; 305 }; 306 307 class IppStringAttribute : public IppNamedAttribute { 308 public: 309 IppStringAttribute(IPP_TAG t); 310 IppStringAttribute(IPP_TAG t, const char *s, const char *s1); 311 virtual ~IppStringAttribute() {} 312 virtual int length() const; 313 virtual istream &input(istream &is); 314 virtual ostream &output(ostream &os) const; 315 virtual ostream &print(ostream &) const; 316 friend istream& operator >> (istream &is, IppStringAttribute &attr) 317 { 318 return attr.input(is); 319 } 320 friend ostream& operator << (ostream &os, const IppStringAttribute &attr) 321 { 322 return attr.output(os); 323 } 324 325 string text; 326 }; 327 328 class IppDoubleStringAttribute : public IppNamedAttribute { 329 public: 330 IppDoubleStringAttribute(IPP_TAG t); 331 IppDoubleStringAttribute(IPP_TAG t, const char *n, const char *s1, const char *s2); 332 virtual ~IppDoubleStringAttribute() {} 333 virtual int length() const; 334 virtual istream &input(istream &is); 335 virtual ostream &output(ostream &os) const; 336 friend istream& operator >> (istream &is, IppDoubleStringAttribute &attr) 337 { 338 return attr.input(is); 339 } 340 friend ostream& operator << (ostream &os, const IppDoubleStringAttribute &attr) 341 { 342 return attr.output(os); 343 } 344 virtual ostream &print(ostream &) const; 345 346 string text1; 347 string text2; 348 }; 349 350 class IppResolutionAttribute : public IppNamedAttribute { 351 public: 352 IppResolutionAttribute(IPP_TAG t); 353 IppResolutionAttribute(IPP_TAG t, const char *n, int, int, IPP_RESOLUTION_UNITS); 354 virtual ~IppResolutionAttribute() {} 355 virtual int length() const; 356 virtual istream &input(istream &is); 357 virtual ostream &output(ostream &os) const; 358 virtual ostream &print(ostream &) const; 359 friend istream& operator >> (istream &is, IppResolutionAttribute &attr) 360 { 361 return attr.input(is); 362 } 363 friend ostream& operator << (ostream &os, const IppResolutionAttribute &attr) 364 { 365 return attr.output(os); 366 } 367 368 int xres; 369 int yres; 370 IPP_RESOLUTION_UNITS resolution_units; 371 }; 372 373 class IppRangeOfIntegerAttribute : public IppNamedAttribute { 374 public: 375 IppRangeOfIntegerAttribute(IPP_TAG t); 376 IppRangeOfIntegerAttribute(IPP_TAG t, const char *n, int, int); 377 virtual ~IppRangeOfIntegerAttribute() {} 378 virtual int length() const; 379 virtual istream &input(istream &is); 380 virtual ostream &output(ostream &os) const; 381 virtual ostream &print(ostream &) const; 382 friend istream& operator >> (istream &is, IppRangeOfIntegerAttribute &attr) 383 { 384 return attr.input(is); 385 } 386 friend ostream& operator << (ostream &os, const IppRangeOfIntegerAttribute &attr) 387 { 388 return attr.output(os); 389 } 390 391 long lower; 392 long upper; 393 }; 394 395 class IppContent { 396 public: 397 IppContent(); 398 ~IppContent(); 399 int length() const; 400 istream &input(istream &); 401 ostream &output(ostream &) const; 402 friend istream& operator >> (istream &is, IppContent &ic) 403 { 404 return ic.input(is); 405 } 406 friend ostream& operator << (ostream &os, const IppContent &ic) 407 { 408 return ic.output(os); 409 } 410 void setVersion(unsigned short); 411 unsigned short getVersion() const; 412 void setOperationId(IPP_OPERATION_ID); 413 IPP_OPERATION_ID getOperationId() const; 414 void setRequestId(unsigned long); 415 unsigned long getRequestId() const; 416 IPP_STATUS_CODE getStatusCode() const; 417 const char *getStatusMessage() const; 418 419 void setDelimiter(IPP_TAG tag); 420 void setInteger(const char *name, int value); 421 void setBoolean(const char *name, bool value); 422 void setString(const char *name, const char *value); 423 void setDateTime(const char *name, const DATETIME *dt); 424 void setResolution(const char *name, int x, int y, IPP_RESOLUTION_UNITS u); 425 void setRangeOfInteger(const char *name, int lower, int upper); 426 void setTextWithLanguage(const char *name, const char *s1, const char *s2); 427 void setNameWithLanguage(const char *name, const char *s1, const char *s2); 428 void setTextWithoutLanguage(const char *name, const char *value); 429 void setNameWithoutLanguage(const char *name, const char *value); 430 void setKeyword(const char *name, const char *value); 431 void setURI(const char *name, const char *value); 432 void setURIScheme(const char *name, const char *value); 433 void setCharset(const char *name, const char *value); 434 void setNaturalLanguage(const char *name, const char *value); 435 void setMimeMediaType(const char *name, const char *value); 436 437 void setRawData(const char *file, int size = -1); 438 void setRawData(istream &is, int size = -1); 439 ostream &print(ostream &) const; 440 441 bool operator !() const; 442 bool good() const; 443 bool fail() const; 444 445 private: 446 list<IppAttribute *> attrs; 447 unsigned short version; 448 unsigned short operation_id; 449 unsigned long request_id; 450 string file_path; 451 istream *is; 452 int size; 453 }; 454 455 #endif // __IppContent_H 456