]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
bc44d920 | 2 | * "$Id: testipp.c 6649 2007-07-11 21:46:42Z mike $" |
ef416fc2 | 3 | * |
71e16022 | 4 | * IPP test program for CUPS. |
ef416fc2 | 5 | * |
54afec33 | 6 | * Copyright 2007-2010 by Apple Inc. |
ef416fc2 | 7 | * Copyright 1997-2005 by Easy Software Products. |
8 | * | |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 10 | * property of Apple Inc. and are protected by Federal copyright |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | * |
15 | * This file is subject to the Apple OS-Developed Software exception. | |
16 | * | |
17 | * Contents: | |
18 | * | |
19 | * main() - Main entry. | |
20 | */ | |
21 | ||
22 | /* | |
23 | * Include necessary headers... | |
24 | */ | |
25 | ||
ef416fc2 | 26 | #include <stdlib.h> |
54afec33 | 27 | #include <cups/file.h> |
71e16022 | 28 | #include "string-private.h" |
8ca02f3c | 29 | #include "ipp-private.h" |
ef416fc2 | 30 | #ifdef WIN32 |
31 | # include <io.h> | |
32 | #else | |
33 | # include <unistd.h> | |
34 | # include <fcntl.h> | |
35 | #endif /* WIN32 */ | |
36 | ||
37 | ||
38 | /* | |
39 | * Local globals... | |
40 | */ | |
41 | ||
42 | int rpos; /* Current position in buffer */ | |
43 | ipp_uchar_t wbuffer[8192]; /* Write buffer */ | |
44 | int wused; /* Number of bytes in buffer */ | |
45 | ipp_uchar_t collection[] = /* Collection buffer */ | |
46 | { | |
47 | 0x01, 0x01, /* IPP version */ | |
48 | 0x00, 0x02, /* Print-Job operation */ | |
49 | 0x00, 0x00, 0x00, 0x01, /* Request ID */ | |
50 | ||
51 | IPP_TAG_OPERATION, | |
52 | ||
53 | IPP_TAG_CHARSET, | |
54 | 0x00, 0x12, /* Name length + name */ | |
55 | 'a','t','t','r','i','b','u','t','e','s','-', | |
56 | 'c','h','a','r','s','e','t', | |
57 | 0x00, 0x05, /* Value length + value */ | |
58 | 'u','t','f','-','8', | |
59 | ||
60 | IPP_TAG_LANGUAGE, | |
61 | 0x00, 0x1b, /* Name length + name */ | |
62 | 'a','t','t','r','i','b','u','t','e','s','-', | |
63 | 'n','a','t','u','r','a','l','-','l','a','n', | |
64 | 'g','u','a','g','e', | |
65 | 0x00, 0x02, /* Value length + value */ | |
66 | 'e','n', | |
67 | ||
68 | IPP_TAG_URI, | |
69 | 0x00, 0x0b, /* Name length + name */ | |
70 | 'p','r','i','n','t','e','r','-','u','r','i', | |
71 | 0x00, 0x1c, /* Value length + value */ | |
72 | 'i','p','p',':','/','/','l','o','c','a','l', | |
73 | 'h','o','s','t','/','p','r','i','n','t','e', | |
74 | 'r','s','/','f','o','o', | |
75 | ||
76 | IPP_TAG_JOB, /* job group tag */ | |
77 | ||
78 | IPP_TAG_BEGIN_COLLECTION, /* begCollection tag */ | |
79 | 0x00, 0x09, /* Name length + name */ | |
80 | 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', | |
81 | 0x00, 0x00, /* No value */ | |
54afec33 MS |
82 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ |
83 | 0x00, 0x00, /* No name */ | |
84 | 0x00, 0x0a, /* Value length + value */ | |
85 | 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e', | |
86 | IPP_TAG_BEGIN_COLLECTION, /* begCollection tag */ | |
87 | 0x00, 0x00, /* Name length + name */ | |
88 | 0x00, 0x00, /* No value */ | |
89 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
90 | 0x00, 0x00, /* No name */ | |
91 | 0x00, 0x0b, /* Value length + value */ | |
92 | 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', | |
93 | IPP_TAG_INTEGER, /* integer tag */ | |
94 | 0x00, 0x00, /* No name */ | |
95 | 0x00, 0x04, /* Value length + value */ | |
96 | 0x00, 0x00, 0x54, 0x56, | |
97 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
98 | 0x00, 0x00, /* No name */ | |
99 | 0x00, 0x0b, /* Value length + value */ | |
100 | 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', | |
101 | IPP_TAG_INTEGER, /* integer tag */ | |
102 | 0x00, 0x00, /* No name */ | |
103 | 0x00, 0x04, /* Value length + value */ | |
104 | 0x00, 0x00, 0x6d, 0x24, | |
105 | IPP_TAG_END_COLLECTION, /* endCollection tag */ | |
106 | 0x00, 0x00, /* No name */ | |
107 | 0x00, 0x00, /* No value */ | |
ef416fc2 | 108 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ |
109 | 0x00, 0x00, /* No name */ | |
110 | 0x00, 0x0b, /* Value length + value */ | |
111 | 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r', | |
112 | IPP_TAG_KEYWORD, /* keyword tag */ | |
113 | 0x00, 0x00, /* No name */ | |
114 | 0x00, 0x04, /* Value length + value */ | |
115 | 'b', 'l', 'u', 'e', | |
116 | ||
117 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
118 | 0x00, 0x00, /* No name */ | |
119 | 0x00, 0x0a, /* Value length + value */ | |
120 | 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e', | |
121 | IPP_TAG_KEYWORD, /* keyword tag */ | |
122 | 0x00, 0x00, /* No name */ | |
123 | 0x00, 0x05, /* Value length + value */ | |
124 | 'p', 'l', 'a', 'i', 'n', | |
125 | IPP_TAG_END_COLLECTION, /* endCollection tag */ | |
126 | 0x00, 0x00, /* No name */ | |
127 | 0x00, 0x00, /* No value */ | |
128 | ||
129 | IPP_TAG_BEGIN_COLLECTION, /* begCollection tag */ | |
130 | 0x00, 0x00, /* No name */ | |
131 | 0x00, 0x00, /* No value */ | |
54afec33 MS |
132 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ |
133 | 0x00, 0x00, /* No name */ | |
134 | 0x00, 0x0a, /* Value length + value */ | |
135 | 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e', | |
136 | IPP_TAG_BEGIN_COLLECTION, /* begCollection tag */ | |
137 | 0x00, 0x00, /* Name length + name */ | |
138 | 0x00, 0x00, /* No value */ | |
139 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
140 | 0x00, 0x00, /* No name */ | |
141 | 0x00, 0x0b, /* Value length + value */ | |
142 | 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', | |
143 | IPP_TAG_INTEGER, /* integer tag */ | |
144 | 0x00, 0x00, /* No name */ | |
145 | 0x00, 0x04, /* Value length + value */ | |
146 | 0x00, 0x00, 0x52, 0x08, | |
147 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
148 | 0x00, 0x00, /* No name */ | |
149 | 0x00, 0x0b, /* Value length + value */ | |
150 | 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', | |
151 | IPP_TAG_INTEGER, /* integer tag */ | |
152 | 0x00, 0x00, /* No name */ | |
153 | 0x00, 0x04, /* Value length + value */ | |
154 | 0x00, 0x00, 0x74, 0x04, | |
155 | IPP_TAG_END_COLLECTION, /* endCollection tag */ | |
156 | 0x00, 0x00, /* No name */ | |
157 | 0x00, 0x00, /* No value */ | |
ef416fc2 | 158 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ |
159 | 0x00, 0x00, /* No name */ | |
160 | 0x00, 0x0b, /* Value length + value */ | |
161 | 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r', | |
162 | IPP_TAG_KEYWORD, /* keyword tag */ | |
163 | 0x00, 0x00, /* No name */ | |
164 | 0x00, 0x05, /* Value length + value */ | |
165 | 'p', 'l', 'a', 'i', 'd', | |
166 | ||
167 | IPP_TAG_MEMBERNAME, /* memberAttrName tag */ | |
168 | 0x00, 0x00, /* No name */ | |
169 | 0x00, 0x0a, /* Value length + value */ | |
170 | 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e', | |
171 | IPP_TAG_KEYWORD, /* keyword tag */ | |
172 | 0x00, 0x00, /* No name */ | |
173 | 0x00, 0x06, /* Value length + value */ | |
174 | 'g', 'l', 'o', 's', 's', 'y', | |
175 | IPP_TAG_END_COLLECTION, /* endCollection tag */ | |
176 | 0x00, 0x00, /* No name */ | |
177 | 0x00, 0x00, /* No value */ | |
178 | ||
179 | IPP_TAG_END /* end tag */ | |
180 | }; | |
181 | ||
182 | ||
183 | /* | |
184 | * Local functions... | |
185 | */ | |
186 | ||
187 | void hex_dump(const char *title, ipp_uchar_t *buffer, int bytes); | |
188 | void print_attributes(ipp_t *ipp, int indent); | |
a4d04587 | 189 | ssize_t read_cb(void *data, ipp_uchar_t *buffer, size_t bytes); |
190 | ssize_t write_cb(void *data, ipp_uchar_t *buffer, size_t bytes); | |
ef416fc2 | 191 | |
192 | ||
193 | /* | |
194 | * 'main()' - Main entry. | |
195 | */ | |
196 | ||
197 | int /* O - Exit status */ | |
198 | main(int argc, /* I - Number of command-line arguments */ | |
199 | char *argv[]) /* I - Command-line arguments */ | |
200 | { | |
54afec33 MS |
201 | ipp_t *cols[2], /* Collections */ |
202 | *size; /* media-size collection */ | |
ef416fc2 | 203 | ipp_t *request; /* Request */ |
54afec33 MS |
204 | ipp_attribute_t *media_col, /* media-col attribute */ |
205 | *media_size, /* media-size attribute */ | |
206 | *attr; /* Other attribute */ | |
ef416fc2 | 207 | ipp_state_t state; /* State */ |
208 | int length; /* Length of data */ | |
54afec33 | 209 | cups_file_t *fp; /* File pointer */ |
ef416fc2 | 210 | int i; /* Looping var */ |
211 | int status; /* Status of tests (0 = success, 1 = fail) */ | |
212 | ||
213 | ||
214 | status = 0; | |
215 | ||
216 | if (argc == 1) | |
217 | { | |
218 | /* | |
219 | * Test request generation code... | |
220 | */ | |
221 | ||
222 | printf("Create Sample Request: "); | |
223 | ||
224 | request = ippNew(); | |
225 | request->request.op.version[0] = 0x01; | |
226 | request->request.op.version[1] = 0x01; | |
227 | request->request.op.operation_id = IPP_PRINT_JOB; | |
228 | request->request.op.request_id = 1; | |
229 | ||
230 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, | |
231 | "attributes-charset", NULL, "utf-8"); | |
232 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
233 | "attributes-natural-language", NULL, "en"); | |
234 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | |
235 | "printer-uri", NULL, "ipp://localhost/printers/foo"); | |
236 | ||
237 | cols[0] = ippNew(); | |
54afec33 MS |
238 | size = ippNew(); |
239 | ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "x-dimension", 21590); | |
240 | ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "y-dimension", 27940); | |
241 | ippAddCollection(cols[0], IPP_TAG_JOB, "media-size", size); | |
242 | ippAddString(cols[0], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-color", NULL, | |
243 | "blue"); | |
244 | ippAddString(cols[0], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-type", NULL, | |
245 | "plain"); | |
ef416fc2 | 246 | |
247 | cols[1] = ippNew(); | |
54afec33 MS |
248 | size = ippNew(); |
249 | ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "x-dimension", 21000); | |
250 | ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "y-dimension", 29700); | |
251 | ippAddCollection(cols[1], IPP_TAG_JOB, "media-size", size); | |
252 | ippAddString(cols[1], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-color", NULL, | |
253 | "plaid"); | |
254 | ippAddString(cols[1], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-type", NULL, | |
255 | "glossy"); | |
256 | ||
257 | ippAddCollections(request, IPP_TAG_JOB, "media-col", 2, | |
258 | (const ipp_t **)cols); | |
ef416fc2 | 259 | |
260 | length = ippLength(request); | |
261 | if (length != sizeof(collection)) | |
262 | { | |
263 | printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n", | |
264 | length, (int)sizeof(collection)); | |
265 | status = 1; | |
266 | } | |
267 | else | |
268 | puts("PASS"); | |
269 | ||
270 | /* | |
271 | * Write test #1... | |
272 | */ | |
273 | ||
274 | printf("Write Sample to Memory: "); | |
275 | ||
276 | wused = 0; | |
277 | while ((state = ippWriteIO(wbuffer, write_cb, 1, NULL, request)) != IPP_DATA) | |
278 | if (state == IPP_ERROR) | |
279 | break; | |
280 | ||
281 | if (state != IPP_DATA) | |
282 | { | |
283 | printf("FAIL - %d bytes written.\n", wused); | |
284 | status = 1; | |
285 | } | |
286 | else if (wused != sizeof(collection)) | |
287 | { | |
288 | printf("FAIL - wrote %d bytes, expected %d bytes!\n", wused, | |
289 | (int)sizeof(collection)); | |
290 | hex_dump("Bytes Written", wbuffer, wused); | |
291 | hex_dump("Baseline", collection, sizeof(collection)); | |
292 | status = 1; | |
293 | } | |
294 | else if (memcmp(wbuffer, collection, wused)) | |
295 | { | |
54afec33 MS |
296 | for (i = 0; i < wused; i ++) |
297 | if (wbuffer[i] != collection[i]) | |
298 | break; | |
299 | ||
300 | printf("FAIL - output does not match baseline at 0x%04x!\n", i); | |
ef416fc2 | 301 | hex_dump("Bytes Written", wbuffer, wused); |
302 | hex_dump("Baseline", collection, sizeof(collection)); | |
303 | status = 1; | |
304 | } | |
305 | else | |
306 | puts("PASS"); | |
307 | ||
308 | ippDelete(request); | |
309 | ||
310 | /* | |
311 | * Read the data back in and confirm... | |
312 | */ | |
313 | ||
314 | printf("Read Sample from Memory: "); | |
315 | ||
316 | request = ippNew(); | |
317 | rpos = 0; | |
318 | ||
319 | while ((state = ippReadIO(wbuffer, read_cb, 1, NULL, request)) != IPP_DATA) | |
320 | if (state == IPP_ERROR) | |
321 | break; | |
322 | ||
323 | length = ippLength(request); | |
324 | ||
325 | if (state != IPP_DATA) | |
326 | { | |
327 | printf("FAIL - %d bytes read.\n", rpos); | |
328 | status = 1; | |
329 | } | |
330 | else if (rpos != wused) | |
331 | { | |
332 | printf("FAIL - read %d bytes, expected %d bytes!\n", rpos, wused); | |
333 | print_attributes(request, 8); | |
334 | status = 1; | |
335 | } | |
336 | else if (length != sizeof(collection)) | |
337 | { | |
338 | printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n", | |
339 | length, (int)sizeof(collection)); | |
340 | print_attributes(request, 8); | |
341 | status = 1; | |
342 | } | |
343 | else | |
344 | puts("PASS"); | |
345 | ||
54afec33 MS |
346 | fputs("ippFindAttribute(media-col): ", stdout); |
347 | if ((media_col = ippFindAttribute(request, "media-col", | |
348 | IPP_TAG_BEGIN_COLLECTION)) == NULL) | |
349 | { | |
350 | if ((media_col = ippFindAttribute(request, "media-col", | |
351 | IPP_TAG_ZERO)) == NULL) | |
352 | puts("FAIL (not found)"); | |
353 | else | |
354 | printf("FAIL (wrong type - %s)\n", ippTagString(media_col->value_tag)); | |
355 | ||
356 | status = 1; | |
357 | } | |
358 | else if (media_col->num_values != 2) | |
359 | { | |
360 | printf("FAIL (wrong count - %d)\n", media_col->num_values); | |
361 | status = 1; | |
362 | } | |
363 | else | |
364 | puts("PASS"); | |
365 | ||
366 | fputs("ippFindAttribute(media-size 1): ", stdout); | |
367 | if ((media_size = ippFindAttribute(media_col->values[0].collection, | |
368 | "media-size", | |
369 | IPP_TAG_BEGIN_COLLECTION)) == NULL) | |
370 | { | |
371 | if ((media_size = ippFindAttribute(media_col->values[0].collection, | |
372 | "media-col", | |
373 | IPP_TAG_ZERO)) == NULL) | |
374 | puts("FAIL (not found)"); | |
375 | else | |
376 | printf("FAIL (wrong type - %s)\n", ippTagString(media_size->value_tag)); | |
377 | ||
378 | status = 1; | |
379 | } | |
380 | else | |
381 | { | |
382 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
383 | "x-dimension", IPP_TAG_INTEGER)) == NULL) | |
384 | { | |
385 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
386 | "x-dimension", IPP_TAG_ZERO)) == NULL) | |
387 | puts("FAIL (missing x-dimension)"); | |
388 | else | |
389 | printf("FAIL (wrong type for x-dimension - %s)\n", | |
390 | ippTagString(attr->value_tag)); | |
391 | ||
392 | status = 1; | |
393 | } | |
394 | else if (attr->values[0].integer != 21590) | |
395 | { | |
396 | printf("FAIL (wrong value for x-dimension - %d)\n", | |
397 | attr->values[0].integer); | |
398 | status = 1; | |
399 | } | |
400 | else if ((attr = ippFindAttribute(media_size->values[0].collection, | |
401 | "y-dimension", | |
402 | IPP_TAG_INTEGER)) == NULL) | |
403 | { | |
404 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
405 | "y-dimension", IPP_TAG_ZERO)) == NULL) | |
406 | puts("FAIL (missing y-dimension)"); | |
407 | else | |
408 | printf("FAIL (wrong type for y-dimension - %s)\n", | |
409 | ippTagString(attr->value_tag)); | |
410 | ||
411 | status = 1; | |
412 | } | |
413 | else if (attr->values[0].integer != 27940) | |
414 | { | |
415 | printf("FAIL (wrong value for y-dimension - %d)\n", | |
416 | attr->values[0].integer); | |
417 | status = 1; | |
418 | } | |
419 | else | |
420 | puts("PASS"); | |
421 | } | |
422 | ||
423 | fputs("ippFindAttribute(media-size 2): ", stdout); | |
424 | if ((media_size = ippFindAttribute(media_col->values[1].collection, | |
425 | "media-size", | |
426 | IPP_TAG_BEGIN_COLLECTION)) == NULL) | |
427 | { | |
428 | if ((media_size = ippFindAttribute(media_col->values[1].collection, | |
429 | "media-col", | |
430 | IPP_TAG_ZERO)) == NULL) | |
431 | puts("FAIL (not found)"); | |
432 | else | |
433 | printf("FAIL (wrong type - %s)\n", ippTagString(media_size->value_tag)); | |
434 | ||
435 | status = 1; | |
436 | } | |
437 | else | |
438 | { | |
439 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
440 | "x-dimension", | |
441 | IPP_TAG_INTEGER)) == NULL) | |
442 | { | |
443 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
444 | "x-dimension", IPP_TAG_ZERO)) == NULL) | |
445 | puts("FAIL (missing x-dimension)"); | |
446 | else | |
447 | printf("FAIL (wrong type for x-dimension - %s)\n", | |
448 | ippTagString(attr->value_tag)); | |
449 | ||
450 | status = 1; | |
451 | } | |
452 | else if (attr->values[0].integer != 21000) | |
453 | { | |
454 | printf("FAIL (wrong value for x-dimension - %d)\n", | |
455 | attr->values[0].integer); | |
456 | status = 1; | |
457 | } | |
458 | else if ((attr = ippFindAttribute(media_size->values[0].collection, | |
459 | "y-dimension", | |
460 | IPP_TAG_INTEGER)) == NULL) | |
461 | { | |
462 | if ((attr = ippFindAttribute(media_size->values[0].collection, | |
463 | "y-dimension", IPP_TAG_ZERO)) == NULL) | |
464 | puts("FAIL (missing y-dimension)"); | |
465 | else | |
466 | printf("FAIL (wrong type for y-dimension - %s)\n", | |
467 | ippTagString(attr->value_tag)); | |
468 | ||
469 | status = 1; | |
470 | } | |
471 | else if (attr->values[0].integer != 29700) | |
472 | { | |
473 | printf("FAIL (wrong value for y-dimension - %d)\n", | |
474 | attr->values[0].integer); | |
475 | status = 1; | |
476 | } | |
477 | else | |
478 | puts("PASS"); | |
479 | } | |
480 | ||
ef416fc2 | 481 | ippDelete(request); |
482 | ||
8ca02f3c | 483 | /* |
484 | * Test _ippFindOption() private API... | |
485 | */ | |
486 | ||
54afec33 | 487 | fputs("_ippFindOption(printer-type): ", stdout); |
8ca02f3c | 488 | if (_ippFindOption("printer-type")) |
489 | puts("PASS"); | |
490 | else | |
491 | { | |
492 | puts("FAIL"); | |
493 | status = 1; | |
494 | } | |
495 | ||
ef416fc2 | 496 | /* |
497 | * Summarize... | |
498 | */ | |
499 | ||
500 | putchar('\n'); | |
501 | ||
502 | if (status) | |
503 | puts("Core IPP tests failed."); | |
504 | else | |
505 | puts("Core IPP tests passed."); | |
506 | } | |
507 | else | |
508 | { | |
509 | /* | |
510 | * Read IPP files... | |
511 | */ | |
512 | ||
513 | for (i = 1; i < argc; i ++) | |
514 | { | |
54afec33 | 515 | if ((fp = cupsFileOpen(argv[i], "r")) == NULL) |
ef416fc2 | 516 | { |
517 | printf("Unable to open \"%s\" - %s\n", argv[i], strerror(errno)); | |
518 | status = 1; | |
519 | continue; | |
520 | } | |
521 | ||
522 | request = ippNew(); | |
54afec33 MS |
523 | while ((state = ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, |
524 | request)) == IPP_ATTRIBUTE); | |
ef416fc2 | 525 | |
526 | if (state != IPP_DATA) | |
527 | { | |
528 | printf("Error reading IPP message from \"%s\"!\n", argv[i]); | |
529 | status = 1; | |
530 | } | |
531 | else | |
532 | { | |
533 | printf("\n%s:\n", argv[i]); | |
534 | print_attributes(request, 4); | |
535 | } | |
536 | ||
537 | ippDelete(request); | |
54afec33 | 538 | cupsFileClose(fp); |
ef416fc2 | 539 | } |
540 | } | |
541 | ||
542 | return (status); | |
543 | } | |
544 | ||
545 | ||
546 | /* | |
547 | * 'hex_dump()' - Produce a hex dump of a buffer. | |
548 | */ | |
549 | ||
550 | void | |
551 | hex_dump(const char *title, /* I - Title */ | |
552 | ipp_uchar_t *buffer, /* I - Buffer to dump */ | |
553 | int bytes) /* I - Number of bytes */ | |
554 | { | |
555 | int i, j; /* Looping vars */ | |
556 | int ch; /* Current ASCII char */ | |
557 | ||
558 | ||
559 | /* | |
560 | * Show lines of 16 bytes at a time... | |
561 | */ | |
562 | ||
563 | printf(" %s:\n", title); | |
564 | ||
565 | for (i = 0; i < bytes; i += 16) | |
566 | { | |
567 | /* | |
568 | * Show the offset... | |
569 | */ | |
570 | ||
571 | printf(" %04x ", i); | |
572 | ||
573 | /* | |
574 | * Then up to 16 bytes in hex... | |
575 | */ | |
576 | ||
577 | for (j = 0; j < 16; j ++) | |
578 | if ((i + j) < bytes) | |
579 | printf(" %02x", buffer[i + j]); | |
580 | else | |
581 | printf(" "); | |
582 | ||
583 | /* | |
584 | * Then the ASCII representation of the bytes... | |
585 | */ | |
586 | ||
587 | putchar(' '); | |
588 | putchar(' '); | |
589 | ||
590 | for (j = 0; j < 16 && (i + j) < bytes; j ++) | |
591 | { | |
592 | ch = buffer[i + j] & 127; | |
593 | ||
594 | if (ch < ' ' || ch == 127) | |
595 | putchar('.'); | |
596 | else | |
597 | putchar(ch); | |
598 | } | |
599 | ||
600 | putchar('\n'); | |
601 | } | |
602 | } | |
603 | ||
604 | ||
605 | /* | |
606 | * 'print_attributes()' - Print the attributes in a request... | |
607 | */ | |
608 | ||
609 | void | |
610 | print_attributes(ipp_t *ipp, /* I - IPP request */ | |
611 | int indent) /* I - Indentation */ | |
612 | { | |
613 | int i; /* Looping var */ | |
614 | ipp_tag_t group; /* Current group */ | |
615 | ipp_attribute_t *attr; /* Current attribute */ | |
616 | ipp_value_t *val; /* Current value */ | |
617 | static const char * const tags[] = /* Value/group tag strings */ | |
618 | { | |
619 | "reserved-00", | |
620 | "operation-attributes-tag", | |
621 | "job-attributes-tag", | |
622 | "end-of-attributes-tag", | |
623 | "printer-attributes-tag", | |
624 | "unsupported-attributes-tag", | |
625 | "subscription-attributes-tag", | |
626 | "event-attributes-tag", | |
627 | "reserved-08", | |
628 | "reserved-09", | |
629 | "reserved-0A", | |
630 | "reserved-0B", | |
631 | "reserved-0C", | |
632 | "reserved-0D", | |
633 | "reserved-0E", | |
634 | "reserved-0F", | |
635 | "unsupported", | |
636 | "default", | |
637 | "unknown", | |
638 | "no-value", | |
639 | "reserved-14", | |
640 | "not-settable", | |
641 | "delete-attr", | |
642 | "admin-define", | |
643 | "reserved-18", | |
644 | "reserved-19", | |
645 | "reserved-1A", | |
646 | "reserved-1B", | |
647 | "reserved-1C", | |
648 | "reserved-1D", | |
649 | "reserved-1E", | |
650 | "reserved-1F", | |
651 | "reserved-20", | |
652 | "integer", | |
653 | "boolean", | |
654 | "enum", | |
655 | "reserved-24", | |
656 | "reserved-25", | |
657 | "reserved-26", | |
658 | "reserved-27", | |
659 | "reserved-28", | |
660 | "reserved-29", | |
661 | "reserved-2a", | |
662 | "reserved-2b", | |
663 | "reserved-2c", | |
664 | "reserved-2d", | |
665 | "reserved-2e", | |
666 | "reserved-2f", | |
667 | "octetString", | |
668 | "dateTime", | |
669 | "resolution", | |
670 | "rangeOfInteger", | |
671 | "begCollection", | |
672 | "textWithLanguage", | |
673 | "nameWithLanguage", | |
674 | "endCollection", | |
675 | "reserved-38", | |
676 | "reserved-39", | |
677 | "reserved-3a", | |
678 | "reserved-3b", | |
679 | "reserved-3c", | |
680 | "reserved-3d", | |
681 | "reserved-3e", | |
682 | "reserved-3f", | |
683 | "reserved-40", | |
684 | "textWithoutLanguage", | |
685 | "nameWithoutLanguage", | |
686 | "reserved-43", | |
687 | "keyword", | |
688 | "uri", | |
689 | "uriScheme", | |
690 | "charset", | |
691 | "naturalLanguage", | |
692 | "mimeMediaType", | |
693 | "memberName" | |
694 | }; | |
695 | ||
696 | ||
697 | for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next) | |
698 | { | |
d2354e63 | 699 | if (!attr->name && indent == 4) |
ef416fc2 | 700 | { |
701 | group = IPP_TAG_ZERO; | |
702 | putchar('\n'); | |
703 | continue; | |
704 | } | |
705 | ||
706 | if (group != attr->group_tag) | |
707 | { | |
708 | group = attr->group_tag; | |
709 | ||
d2354e63 | 710 | printf("\n%*s%s:\n\n", indent - 4, "", tags[group]); |
ef416fc2 | 711 | } |
712 | ||
d2354e63 | 713 | printf("%*s%s (", indent, "", attr->name ? attr->name : "(null)"); |
ef416fc2 | 714 | if (attr->num_values > 1) |
715 | printf("1setOf "); | |
716 | printf("%s):", tags[attr->value_tag]); | |
717 | ||
718 | switch (attr->value_tag) | |
719 | { | |
720 | case IPP_TAG_ENUM : | |
721 | case IPP_TAG_INTEGER : | |
722 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
723 | printf(" %d", val->integer); | |
724 | putchar('\n'); | |
725 | break; | |
726 | ||
727 | case IPP_TAG_BOOLEAN : | |
728 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
729 | printf(" %s", val->boolean ? "true" : "false"); | |
730 | putchar('\n'); | |
731 | break; | |
732 | ||
733 | case IPP_TAG_RANGE : | |
734 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
735 | printf(" %d-%d", val->range.lower, val->range.upper); | |
736 | putchar('\n'); | |
737 | break; | |
738 | ||
739 | case IPP_TAG_DATE : | |
740 | { | |
741 | time_t vtime; /* Date/Time value */ | |
742 | struct tm *vdate; /* Date info */ | |
743 | char vstring[256]; /* Formatted time */ | |
744 | ||
745 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
746 | { | |
747 | vtime = ippDateToTime(val->date); | |
748 | vdate = localtime(&vtime); | |
749 | strftime(vstring, sizeof(vstring), "%c", vdate); | |
750 | printf(" (%s)", vstring); | |
751 | } | |
752 | } | |
753 | putchar('\n'); | |
754 | break; | |
755 | ||
756 | case IPP_TAG_RESOLUTION : | |
757 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
758 | printf(" %dx%d%s", val->resolution.xres, val->resolution.yres, | |
759 | val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpc"); | |
760 | putchar('\n'); | |
761 | break; | |
762 | ||
763 | case IPP_TAG_STRING : | |
764 | case IPP_TAG_TEXTLANG : | |
765 | case IPP_TAG_NAMELANG : | |
766 | case IPP_TAG_TEXT : | |
767 | case IPP_TAG_NAME : | |
768 | case IPP_TAG_KEYWORD : | |
769 | case IPP_TAG_URI : | |
770 | case IPP_TAG_URISCHEME : | |
771 | case IPP_TAG_CHARSET : | |
772 | case IPP_TAG_LANGUAGE : | |
773 | case IPP_TAG_MIMETYPE : | |
774 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
775 | printf(" \"%s\"", val->string.text); | |
776 | putchar('\n'); | |
777 | break; | |
778 | ||
779 | case IPP_TAG_BEGIN_COLLECTION : | |
780 | putchar('\n'); | |
781 | ||
782 | for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++) | |
783 | { | |
784 | if (i) | |
785 | putchar('\n'); | |
786 | print_attributes(val->collection, indent + 4); | |
787 | } | |
788 | break; | |
789 | ||
790 | default : | |
791 | printf("UNKNOWN (%d values)\n", attr->num_values); | |
792 | break; | |
793 | } | |
794 | } | |
795 | } | |
796 | ||
797 | ||
798 | /* | |
799 | * 'read_cb()' - Read data from a buffer. | |
800 | */ | |
801 | ||
a4d04587 | 802 | ssize_t /* O - Number of bytes read */ |
ef416fc2 | 803 | read_cb(void *data, /* I - Data */ |
804 | ipp_uchar_t *buffer, /* O - Buffer to read */ | |
a4d04587 | 805 | size_t bytes) /* I - Number of bytes to read */ |
ef416fc2 | 806 | { |
807 | int count; /* Number of bytes */ | |
808 | ||
809 | ||
810 | /* | |
811 | * Copy bytes from the data buffer to the read buffer... | |
812 | */ | |
813 | ||
814 | for (count = bytes; count > 0 && rpos < wused; count --, rpos ++) | |
815 | *buffer++ = wbuffer[rpos]; | |
816 | ||
817 | /* | |
818 | * Return the number of bytes read... | |
819 | */ | |
820 | ||
821 | return (bytes - count); | |
822 | } | |
823 | ||
824 | ||
825 | /* | |
826 | * 'write_cb()' - Write data into a buffer. | |
827 | */ | |
828 | ||
a4d04587 | 829 | ssize_t /* O - Number of bytes written */ |
ef416fc2 | 830 | write_cb(void *data, /* I - Data */ |
831 | ipp_uchar_t *buffer, /* I - Buffer to write */ | |
a4d04587 | 832 | size_t bytes) /* I - Number of bytes to write */ |
ef416fc2 | 833 | { |
834 | int count; /* Number of bytes */ | |
835 | ||
836 | ||
837 | /* | |
838 | * Loop until all bytes are written... | |
839 | */ | |
840 | ||
841 | for (count = bytes; count > 0 && wused < sizeof(wbuffer); count --, wused ++) | |
842 | wbuffer[wused] = *buffer++; | |
843 | ||
844 | /* | |
845 | * Return the number of bytes written... | |
846 | */ | |
847 | ||
848 | return (bytes - count); | |
849 | } | |
850 | ||
851 | ||
852 | /* | |
bc44d920 | 853 | * End of "$Id: testipp.c 6649 2007-07-11 21:46:42Z mike $". |
ef416fc2 | 854 | */ |