]>
git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
915746893ec1a1a8d94a1b6806e01d88d86fe9b6
4 * Test notifier 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
26 * main() - Main entry for the test notifier.
27 * print_attributes() - Print the attributes in a request...
31 * Include necessary headers...
34 #include <cups/cups.h>
35 #include <cups/language.h>
36 #include <cups/string.h>
43 void print_attributes(ipp_t
*ipp
, int indent
);
47 * 'main()' - Main entry for the test notifier.
50 int /* O - Exit status */
51 main(int argc
, /* I - Number of command-line arguments */
52 char *argv
[]) /* I - Command-line arguments */
54 int i
; /* Looping var */
55 ipp_t
*event
; /* Event from scheduler */
56 ipp_state_t state
; /* IPP event state */
61 fprintf(stderr
, "DEBUG: argc=%d\n", argc
);
62 for (i
= 0; i
< argc
; i
++)
63 fprintf(stderr
, "DEBUG: argv[%d]=\"%s\"\n", i
, argv
[i
]);
68 while ((state
= ippReadFile(0, event
)) != IPP_DATA
)
70 if (state
<= IPP_IDLE
)
74 if (state
== IPP_ERROR
)
75 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr
);
77 if (state
<= IPP_IDLE
)
83 print_attributes(event
, 4);
90 * 'print_attributes()' - Print the attributes in a request...
94 print_attributes(ipp_t
*ipp
, /* I - IPP request */
95 int indent
) /* I - Indentation */
97 int i
; /* Looping var */
98 ipp_tag_t group
; /* Current group */
99 ipp_attribute_t
*attr
; /* Current attribute */
100 ipp_value_t
*val
; /* Current value */
101 static const char * const tags
[] = /* Value/group tag strings */
104 "operation-attributes-tag",
105 "job-attributes-tag",
106 "end-of-attributes-tag",
107 "printer-attributes-tag",
108 "unsupported-attributes-tag",
109 "subscription-attributes-tag",
110 "event-attributes-tag",
168 "textWithoutLanguage",
169 "nameWithoutLanguage",
181 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
183 if ((attr
->group_tag
== IPP_TAG_ZERO
&& indent
<= 8) || !attr
->name
)
185 group
= IPP_TAG_ZERO
;
190 if (group
!= attr
->group_tag
)
192 group
= attr
->group_tag
;
194 fprintf(stderr
, "DEBUG: %*s%s:\n\n", indent
- 4, "", tags
[group
]);
197 fprintf(stderr
, "DEBUG: %*s%s (", indent
, "", attr
->name
);
198 if (attr
->num_values
> 1)
199 fputs("1setOf ", stderr
);
200 fprintf(stderr
, "%s):", tags
[attr
->value_tag
]);
202 switch (attr
->value_tag
)
205 case IPP_TAG_INTEGER
:
206 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
207 fprintf(stderr
, " %d", val
->integer
);
211 case IPP_TAG_BOOLEAN
:
212 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
213 fprintf(stderr
, " %s", val
->boolean
? "true" : "false");
218 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
219 fprintf(stderr
, " %d-%d", val
->range
.lower
, val
->range
.upper
);
225 time_t vtime
; /* Date/Time value */
226 struct tm
*vdate
; /* Date info */
227 char vstring
[256]; /* Formatted time */
229 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
231 vtime
= ippDateToTime(val
->date
);
232 vdate
= localtime(&vtime
);
233 strftime(vstring
, sizeof(vstring
), "%c", vdate
);
234 fprintf(stderr
, " (%s)", vstring
);
240 case IPP_TAG_RESOLUTION
:
241 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
242 fprintf(stderr
, " %dx%d%s", val
->resolution
.xres
,
243 val
->resolution
.yres
,
244 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpc");
248 case IPP_TAG_STRING
:
249 case IPP_TAG_TEXTLANG
:
250 case IPP_TAG_NAMELANG
:
253 case IPP_TAG_KEYWORD
:
255 case IPP_TAG_URISCHEME
:
256 case IPP_TAG_CHARSET
:
257 case IPP_TAG_LANGUAGE
:
258 case IPP_TAG_MIMETYPE
:
259 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
260 fprintf(stderr
, " \"%s\"", val
->string
.text
);
264 case IPP_TAG_BEGIN_COLLECTION
:
267 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
271 print_attributes(val
->collection
, indent
+ 4);
276 fprintf(stderr
, "UNKNOWN (%d values)\n", attr
->num_values
);