]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testipp.c
4 * IPP test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry.
32 * Include necessary headers...
37 #include <cups/string.h>
52 int rpos
; /* Current position in buffer */
53 ipp_uchar_t wbuffer
[8192]; /* Write buffer */
54 int wused
; /* Number of bytes in buffer */
55 ipp_uchar_t collection
[] = /* Collection buffer */
57 0x01, 0x01, /* IPP version */
58 0x00, 0x02, /* Print-Job operation */
59 0x00, 0x00, 0x00, 0x01, /* Request ID */
64 0x00, 0x12, /* Name length + name */
65 'a','t','t','r','i','b','u','t','e','s','-',
66 'c','h','a','r','s','e','t',
67 0x00, 0x05, /* Value length + value */
71 0x00, 0x1b, /* Name length + name */
72 'a','t','t','r','i','b','u','t','e','s','-',
73 'n','a','t','u','r','a','l','-','l','a','n',
75 0x00, 0x02, /* Value length + value */
79 0x00, 0x0b, /* Name length + name */
80 'p','r','i','n','t','e','r','-','u','r','i',
81 0x00, 0x1c, /* Value length + value */
82 'i','p','p',':','/','/','l','o','c','a','l',
83 'h','o','s','t','/','p','r','i','n','t','e',
84 'r','s','/','f','o','o',
86 IPP_TAG_JOB
, /* job group tag */
88 IPP_TAG_BEGIN_COLLECTION
, /* begCollection tag */
89 0x00, 0x09, /* Name length + name */
90 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
91 0x00, 0x00, /* No value */
92 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
93 0x00, 0x00, /* No name */
94 0x00, 0x0b, /* Value length + value */
95 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
96 IPP_TAG_KEYWORD
, /* keyword tag */
97 0x00, 0x00, /* No name */
98 0x00, 0x04, /* Value length + value */
101 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
102 0x00, 0x00, /* No name */
103 0x00, 0x0a, /* Value length + value */
104 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
105 IPP_TAG_KEYWORD
, /* keyword tag */
106 0x00, 0x00, /* No name */
107 0x00, 0x05, /* Value length + value */
108 'p', 'l', 'a', 'i', 'n',
109 IPP_TAG_END_COLLECTION
, /* endCollection tag */
110 0x00, 0x00, /* No name */
111 0x00, 0x00, /* No value */
113 IPP_TAG_BEGIN_COLLECTION
, /* begCollection tag */
114 0x00, 0x00, /* No name */
115 0x00, 0x00, /* No value */
116 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
117 0x00, 0x00, /* No name */
118 0x00, 0x0b, /* Value length + value */
119 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
120 IPP_TAG_KEYWORD
, /* keyword tag */
121 0x00, 0x00, /* No name */
122 0x00, 0x05, /* Value length + value */
123 'p', 'l', 'a', 'i', 'd',
125 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
126 0x00, 0x00, /* No name */
127 0x00, 0x0a, /* Value length + value */
128 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
129 IPP_TAG_KEYWORD
, /* keyword tag */
130 0x00, 0x00, /* No name */
131 0x00, 0x06, /* Value length + value */
132 'g', 'l', 'o', 's', 's', 'y',
133 IPP_TAG_END_COLLECTION
, /* endCollection tag */
134 0x00, 0x00, /* No name */
135 0x00, 0x00, /* No value */
137 IPP_TAG_END
/* end tag */
145 void hex_dump(const char *title
, ipp_uchar_t
*buffer
, int bytes
);
146 void print_attributes(ipp_t
*ipp
, int indent
);
147 ssize_t
read_cb(void *data
, ipp_uchar_t
*buffer
, size_t bytes
);
148 ssize_t
write_cb(void *data
, ipp_uchar_t
*buffer
, size_t bytes
);
152 * 'main()' - Main entry.
155 int /* O - Exit status */
156 main(int argc
, /* I - Number of command-line arguments */
157 char *argv
[]) /* I - Command-line arguments */
159 ipp_t
*cols
[2]; /* Collections */
160 ipp_t
*request
; /* Request */
161 ipp_state_t state
; /* State */
162 int length
; /* Length of data */
163 int fd
; /* File descriptor */
164 int i
; /* Looping var */
165 int status
; /* Status of tests (0 = success, 1 = fail) */
173 * Test request generation code...
176 printf("Create Sample Request: ");
179 request
->request
.op
.version
[0] = 0x01;
180 request
->request
.op
.version
[1] = 0x01;
181 request
->request
.op
.operation_id
= IPP_PRINT_JOB
;
182 request
->request
.op
.request_id
= 1;
184 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
185 "attributes-charset", NULL
, "utf-8");
186 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
187 "attributes-natural-language", NULL
, "en");
188 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
189 "printer-uri", NULL
, "ipp://localhost/printers/foo");
192 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
, "blue");
193 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
, "plain");
196 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
, "plaid");
197 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
, "glossy");
199 ippAddCollections(request
, IPP_TAG_JOB
, "media-col", 2, (const ipp_t
**)cols
);
201 length
= ippLength(request
);
202 if (length
!= sizeof(collection
))
204 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
205 length
, (int)sizeof(collection
));
215 printf("Write Sample to Memory: ");
218 while ((state
= ippWriteIO(wbuffer
, write_cb
, 1, NULL
, request
)) != IPP_DATA
)
219 if (state
== IPP_ERROR
)
222 if (state
!= IPP_DATA
)
224 printf("FAIL - %d bytes written.\n", wused
);
227 else if (wused
!= sizeof(collection
))
229 printf("FAIL - wrote %d bytes, expected %d bytes!\n", wused
,
230 (int)sizeof(collection
));
231 hex_dump("Bytes Written", wbuffer
, wused
);
232 hex_dump("Baseline", collection
, sizeof(collection
));
235 else if (memcmp(wbuffer
, collection
, wused
))
237 puts("FAIL - output does not match baseline!");
238 hex_dump("Bytes Written", wbuffer
, wused
);
239 hex_dump("Baseline", collection
, sizeof(collection
));
248 * Read the data back in and confirm...
251 printf("Read Sample from Memory: ");
256 while ((state
= ippReadIO(wbuffer
, read_cb
, 1, NULL
, request
)) != IPP_DATA
)
257 if (state
== IPP_ERROR
)
260 length
= ippLength(request
);
262 if (state
!= IPP_DATA
)
264 printf("FAIL - %d bytes read.\n", rpos
);
267 else if (rpos
!= wused
)
269 printf("FAIL - read %d bytes, expected %d bytes!\n", rpos
, wused
);
270 print_attributes(request
, 8);
273 else if (length
!= sizeof(collection
))
275 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
276 length
, (int)sizeof(collection
));
277 print_attributes(request
, 8);
292 puts("Core IPP tests failed.");
294 puts("Core IPP tests passed.");
302 for (i
= 1; i
< argc
; i
++)
304 if ((fd
= open(argv
[i
], O_RDONLY
)) < 0)
306 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
312 while ((state
= ippReadFile(fd
, request
)) == IPP_ATTRIBUTE
);
314 if (state
!= IPP_DATA
)
316 printf("Error reading IPP message from \"%s\"!\n", argv
[i
]);
321 printf("\n%s:\n", argv
[i
]);
322 print_attributes(request
, 4);
335 * 'hex_dump()' - Produce a hex dump of a buffer.
339 hex_dump(const char *title
, /* I - Title */
340 ipp_uchar_t
*buffer
, /* I - Buffer to dump */
341 int bytes
) /* I - Number of bytes */
343 int i
, j
; /* Looping vars */
344 int ch
; /* Current ASCII char */
348 * Show lines of 16 bytes at a time...
351 printf(" %s:\n", title
);
353 for (i
= 0; i
< bytes
; i
+= 16)
362 * Then up to 16 bytes in hex...
365 for (j
= 0; j
< 16; j
++)
367 printf(" %02x", buffer
[i
+ j
]);
372 * Then the ASCII representation of the bytes...
378 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
380 ch
= buffer
[i
+ j
] & 127;
382 if (ch
< ' ' || ch
== 127)
394 * 'print_attributes()' - Print the attributes in a request...
398 print_attributes(ipp_t
*ipp
, /* I - IPP request */
399 int indent
) /* I - Indentation */
401 int i
; /* Looping var */
402 ipp_tag_t group
; /* Current group */
403 ipp_attribute_t
*attr
; /* Current attribute */
404 ipp_value_t
*val
; /* Current value */
405 static const char * const tags
[] = /* Value/group tag strings */
408 "operation-attributes-tag",
409 "job-attributes-tag",
410 "end-of-attributes-tag",
411 "printer-attributes-tag",
412 "unsupported-attributes-tag",
413 "subscription-attributes-tag",
414 "event-attributes-tag",
472 "textWithoutLanguage",
473 "nameWithoutLanguage",
485 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
487 if ((attr
->group_tag
== IPP_TAG_ZERO
&& indent
<= 8) || !attr
->name
)
489 group
= IPP_TAG_ZERO
;
494 if (group
!= attr
->group_tag
)
496 group
= attr
->group_tag
;
499 for (i
= 4; i
< indent
; i
++)
502 printf("%s:\n\n", tags
[group
]);
505 for (i
= 0; i
< indent
; i
++)
508 printf("%s (", attr
->name
);
509 if (attr
->num_values
> 1)
511 printf("%s):", tags
[attr
->value_tag
]);
513 switch (attr
->value_tag
)
516 case IPP_TAG_INTEGER
:
517 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
518 printf(" %d", val
->integer
);
522 case IPP_TAG_BOOLEAN
:
523 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
524 printf(" %s", val
->boolean
? "true" : "false");
529 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
530 printf(" %d-%d", val
->range
.lower
, val
->range
.upper
);
536 time_t vtime
; /* Date/Time value */
537 struct tm
*vdate
; /* Date info */
538 char vstring
[256]; /* Formatted time */
540 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
542 vtime
= ippDateToTime(val
->date
);
543 vdate
= localtime(&vtime
);
544 strftime(vstring
, sizeof(vstring
), "%c", vdate
);
545 printf(" (%s)", vstring
);
551 case IPP_TAG_RESOLUTION
:
552 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
553 printf(" %dx%d%s", val
->resolution
.xres
, val
->resolution
.yres
,
554 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpc");
558 case IPP_TAG_STRING
:
559 case IPP_TAG_TEXTLANG
:
560 case IPP_TAG_NAMELANG
:
563 case IPP_TAG_KEYWORD
:
565 case IPP_TAG_URISCHEME
:
566 case IPP_TAG_CHARSET
:
567 case IPP_TAG_LANGUAGE
:
568 case IPP_TAG_MIMETYPE
:
569 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
570 printf(" \"%s\"", val
->string
.text
);
574 case IPP_TAG_BEGIN_COLLECTION
:
577 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
581 print_attributes(val
->collection
, indent
+ 4);
586 printf("UNKNOWN (%d values)\n", attr
->num_values
);
594 * 'read_cb()' - Read data from a buffer.
597 ssize_t
/* O - Number of bytes read */
598 read_cb(void *data
, /* I - Data */
599 ipp_uchar_t
*buffer
, /* O - Buffer to read */
600 size_t bytes
) /* I - Number of bytes to read */
602 int count
; /* Number of bytes */
606 * Copy bytes from the data buffer to the read buffer...
609 for (count
= bytes
; count
> 0 && rpos
< wused
; count
--, rpos
++)
610 *buffer
++ = wbuffer
[rpos
];
613 * Return the number of bytes read...
616 return (bytes
- count
);
621 * 'write_cb()' - Write data into a buffer.
624 ssize_t
/* O - Number of bytes written */
625 write_cb(void *data
, /* I - Data */
626 ipp_uchar_t
*buffer
, /* I - Buffer to write */
627 size_t bytes
) /* I - Number of bytes to write */
629 int count
; /* Number of bytes */
633 * Loop until all bytes are written...
636 for (count
= bytes
; count
> 0 && wused
< sizeof(wbuffer
); count
--, wused
++)
637 wbuffer
[wused
] = *buffer
++;
640 * Return the number of bytes written...
643 return (bytes
- count
);