]>
git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
664ddb018e605793a1062a5f505776197ce22a51
2 * "$Id: testnotify.c 6649 2007-07-11 21:46:42Z mike $"
4 * Test notifier for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
17 * main() - Main entry for the test notifier.
18 * print_attributes() - Print the attributes in a request...
22 * Include necessary headers...
25 #include <cups/cups.h>
26 #include <cups/language.h>
27 #include <cups/string.h>
34 void print_attributes(ipp_t
*ipp
, int indent
);
38 * 'main()' - Main entry for the test notifier.
41 int /* O - Exit status */
42 main(int argc
, /* I - Number of command-line arguments */
43 char *argv
[]) /* I - Command-line arguments */
45 int i
; /* Looping var */
46 ipp_t
*event
; /* Event from scheduler */
47 ipp_state_t state
; /* IPP event state */
52 fprintf(stderr
, "DEBUG: argc=%d\n", argc
);
53 for (i
= 0; i
< argc
; i
++)
54 fprintf(stderr
, "DEBUG: argv[%d]=\"%s\"\n", i
, argv
[i
]);
59 while ((state
= ippReadFile(0, event
)) != IPP_DATA
)
61 if (state
<= IPP_IDLE
)
65 if (state
== IPP_ERROR
)
66 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr
);
68 if (state
<= IPP_IDLE
)
74 print_attributes(event
, 4);
78 * If the recipient URI is "testnotify://nowait", then we exit after each
82 if (!strcmp(argv
[1], "testnotify://nowait"))
89 * 'print_attributes()' - Print the attributes in a request...
93 print_attributes(ipp_t
*ipp
, /* I - IPP request */
94 int indent
) /* I - Indentation */
96 int i
; /* Looping var */
97 ipp_tag_t group
; /* Current group */
98 ipp_attribute_t
*attr
; /* Current attribute */
99 ipp_value_t
*val
; /* Current value */
100 static const char * const tags
[] = /* Value/group tag strings */
103 "operation-attributes-tag",
104 "job-attributes-tag",
105 "end-of-attributes-tag",
106 "printer-attributes-tag",
107 "unsupported-attributes-tag",
108 "subscription-attributes-tag",
109 "event-attributes-tag",
167 "textWithoutLanguage",
168 "nameWithoutLanguage",
180 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
182 if ((attr
->group_tag
== IPP_TAG_ZERO
&& indent
<= 8) || !attr
->name
)
184 group
= IPP_TAG_ZERO
;
189 if (group
!= attr
->group_tag
)
191 group
= attr
->group_tag
;
193 fprintf(stderr
, "DEBUG: %*s%s:\n\n", indent
- 4, "", tags
[group
]);
196 fprintf(stderr
, "DEBUG: %*s%s (", indent
, "", attr
->name
);
197 if (attr
->num_values
> 1)
198 fputs("1setOf ", stderr
);
199 fprintf(stderr
, "%s):", tags
[attr
->value_tag
]);
201 switch (attr
->value_tag
)
204 case IPP_TAG_INTEGER
:
205 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
206 fprintf(stderr
, " %d", val
->integer
);
210 case IPP_TAG_BOOLEAN
:
211 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
212 fprintf(stderr
, " %s", val
->boolean
? "true" : "false");
217 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
218 fprintf(stderr
, " %d-%d", val
->range
.lower
, val
->range
.upper
);
224 time_t vtime
; /* Date/Time value */
225 struct tm
*vdate
; /* Date info */
226 char vstring
[256]; /* Formatted time */
228 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
230 vtime
= ippDateToTime(val
->date
);
231 vdate
= localtime(&vtime
);
232 strftime(vstring
, sizeof(vstring
), "%c", vdate
);
233 fprintf(stderr
, " (%s)", vstring
);
239 case IPP_TAG_RESOLUTION
:
240 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
241 fprintf(stderr
, " %dx%d%s", val
->resolution
.xres
,
242 val
->resolution
.yres
,
243 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpc");
247 case IPP_TAG_STRING
:
248 case IPP_TAG_TEXTLANG
:
249 case IPP_TAG_NAMELANG
:
252 case IPP_TAG_KEYWORD
:
254 case IPP_TAG_URISCHEME
:
255 case IPP_TAG_CHARSET
:
256 case IPP_TAG_LANGUAGE
:
257 case IPP_TAG_MIMETYPE
:
258 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
259 fprintf(stderr
, " \"%s\"", val
->string
.text
);
263 case IPP_TAG_BEGIN_COLLECTION
:
266 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
270 print_attributes(val
->collection
, indent
+ 4);
275 fprintf(stderr
, "UNKNOWN (%d values)\n", attr
->num_values
);
283 * End of "$Id: testnotify.c 6649 2007-07-11 21:46:42Z mike $".