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