]>
git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
e9fec26c0cc6a2daae8a9e2a0c22829ffa0c761a
2 * "$Id: testnotify.c 5715 2006-07-11 17:56:13Z mike $"
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);
87 * If the recipient URI is "testnotify://nowait", then we exit after each
91 if (!strcmp(argv
[1], "testnotify://nowait"))
98 * 'print_attributes()' - Print the attributes in a request...
102 print_attributes(ipp_t
*ipp
, /* I - IPP request */
103 int indent
) /* I - Indentation */
105 int i
; /* Looping var */
106 ipp_tag_t group
; /* Current group */
107 ipp_attribute_t
*attr
; /* Current attribute */
108 ipp_value_t
*val
; /* Current value */
109 static const char * const tags
[] = /* Value/group tag strings */
112 "operation-attributes-tag",
113 "job-attributes-tag",
114 "end-of-attributes-tag",
115 "printer-attributes-tag",
116 "unsupported-attributes-tag",
117 "subscription-attributes-tag",
118 "event-attributes-tag",
176 "textWithoutLanguage",
177 "nameWithoutLanguage",
189 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
191 if ((attr
->group_tag
== IPP_TAG_ZERO
&& indent
<= 8) || !attr
->name
)
193 group
= IPP_TAG_ZERO
;
198 if (group
!= attr
->group_tag
)
200 group
= attr
->group_tag
;
202 fprintf(stderr
, "DEBUG: %*s%s:\n\n", indent
- 4, "", tags
[group
]);
205 fprintf(stderr
, "DEBUG: %*s%s (", indent
, "", attr
->name
);
206 if (attr
->num_values
> 1)
207 fputs("1setOf ", stderr
);
208 fprintf(stderr
, "%s):", tags
[attr
->value_tag
]);
210 switch (attr
->value_tag
)
213 case IPP_TAG_INTEGER
:
214 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
215 fprintf(stderr
, " %d", val
->integer
);
219 case IPP_TAG_BOOLEAN
:
220 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
221 fprintf(stderr
, " %s", val
->boolean
? "true" : "false");
226 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
227 fprintf(stderr
, " %d-%d", val
->range
.lower
, val
->range
.upper
);
233 time_t vtime
; /* Date/Time value */
234 struct tm
*vdate
; /* Date info */
235 char vstring
[256]; /* Formatted time */
237 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
239 vtime
= ippDateToTime(val
->date
);
240 vdate
= localtime(&vtime
);
241 strftime(vstring
, sizeof(vstring
), "%c", vdate
);
242 fprintf(stderr
, " (%s)", vstring
);
248 case IPP_TAG_RESOLUTION
:
249 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
250 fprintf(stderr
, " %dx%d%s", val
->resolution
.xres
,
251 val
->resolution
.yres
,
252 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpc");
256 case IPP_TAG_STRING
:
257 case IPP_TAG_TEXTLANG
:
258 case IPP_TAG_NAMELANG
:
261 case IPP_TAG_KEYWORD
:
263 case IPP_TAG_URISCHEME
:
264 case IPP_TAG_CHARSET
:
265 case IPP_TAG_LANGUAGE
:
266 case IPP_TAG_MIMETYPE
:
267 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
268 fprintf(stderr
, " \"%s\"", val
->string
.text
);
272 case IPP_TAG_BEGIN_COLLECTION
:
275 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
279 print_attributes(val
->collection
, indent
+ 4);
284 fprintf(stderr
, "UNKNOWN (%d values)\n", attr
->num_values
);
292 * End of "$Id: testnotify.c 5715 2006-07-11 17:56:13Z mike $".