]> git.ipfire.org Git - thirdparty/cups.git/blame - notifier/testnotify.c
Merge changes from CUPS 1.5svn-r9041.
[thirdparty/cups.git] / notifier / testnotify.c
CommitLineData
ef416fc2 1/*
bc44d920 2 * "$Id: testnotify.c 6649 2007-07-11 21:46:42Z mike $"
ef416fc2 3 *
4 * Test notifier for the Common UNIX Printing System (CUPS).
5 *
bc44d920 6 * Copyright 2007 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 * Contents:
16 *
17 * main() - Main entry for the test notifier.
18 * print_attributes() - Print the attributes in a request...
19 */
20
21/*
22 * Include necessary headers...
23 */
24
25#include <cups/cups.h>
26#include <cups/language.h>
27#include <cups/string.h>
28
29
30/*
31 * Local functions...
32 */
33
34void print_attributes(ipp_t *ipp, int indent);
35
36
37/*
38 * 'main()' - Main entry for the test notifier.
39 */
40
41int /* O - Exit status */
42main(int argc, /* I - Number of command-line arguments */
43 char *argv[]) /* I - Command-line arguments */
44{
45 int i; /* Looping var */
46 ipp_t *event; /* Event from scheduler */
47 ipp_state_t state; /* IPP event state */
48
49
50 setbuf(stderr, NULL);
51
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]);
cda47a96 55 fprintf(stderr, "DEBUG: TMPDIR=\"%s\"\n", getenv("TMPDIR"));
ef416fc2 56
57 for (;;)
58 {
59 event = ippNew();
60 while ((state = ippReadFile(0, event)) != IPP_DATA)
61 {
62 if (state <= IPP_IDLE)
63 break;
64 }
65
66 if (state == IPP_ERROR)
67 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr);
68
69 if (state <= IPP_IDLE)
70 {
71 ippDelete(event);
72 return (0);
73 }
74
75 print_attributes(event, 4);
76 ippDelete(event);
8ca02f3c 77
78 /*
79 * If the recipient URI is "testnotify://nowait", then we exit after each
80 * event...
81 */
82
83 if (!strcmp(argv[1], "testnotify://nowait"))
84 return (0);
ef416fc2 85 }
86}
87
88
89/*
90 * 'print_attributes()' - Print the attributes in a request...
91 */
92
93void
94print_attributes(ipp_t *ipp, /* I - IPP request */
95 int indent) /* I - Indentation */
96{
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 */
102 {
103 "reserved-00",
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",
111 "reserved-08",
112 "reserved-09",
113 "reserved-0A",
114 "reserved-0B",
115 "reserved-0C",
116 "reserved-0D",
117 "reserved-0E",
118 "reserved-0F",
119 "unsupported",
120 "default",
121 "unknown",
122 "no-value",
123 "reserved-14",
124 "not-settable",
125 "delete-attr",
126 "admin-define",
127 "reserved-18",
128 "reserved-19",
129 "reserved-1A",
130 "reserved-1B",
131 "reserved-1C",
132 "reserved-1D",
133 "reserved-1E",
134 "reserved-1F",
135 "reserved-20",
136 "integer",
137 "boolean",
138 "enum",
139 "reserved-24",
140 "reserved-25",
141 "reserved-26",
142 "reserved-27",
143 "reserved-28",
144 "reserved-29",
145 "reserved-2a",
146 "reserved-2b",
147 "reserved-2c",
148 "reserved-2d",
149 "reserved-2e",
150 "reserved-2f",
151 "octetString",
152 "dateTime",
153 "resolution",
154 "rangeOfInteger",
155 "begCollection",
156 "textWithLanguage",
157 "nameWithLanguage",
158 "endCollection",
159 "reserved-38",
160 "reserved-39",
161 "reserved-3a",
162 "reserved-3b",
163 "reserved-3c",
164 "reserved-3d",
165 "reserved-3e",
166 "reserved-3f",
167 "reserved-40",
168 "textWithoutLanguage",
169 "nameWithoutLanguage",
170 "reserved-43",
171 "keyword",
172 "uri",
173 "uriScheme",
174 "charset",
175 "naturalLanguage",
176 "mimeMediaType",
177 "memberName"
178 };
179
180
181 for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
182 {
183 if ((attr->group_tag == IPP_TAG_ZERO && indent <= 8) || !attr->name)
184 {
185 group = IPP_TAG_ZERO;
186 fputc('\n', stderr);
187 continue;
188 }
189
190 if (group != attr->group_tag)
191 {
192 group = attr->group_tag;
193
194 fprintf(stderr, "DEBUG: %*s%s:\n\n", indent - 4, "", tags[group]);
195 }
196
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]);
201
202 switch (attr->value_tag)
203 {
204 case IPP_TAG_ENUM :
205 case IPP_TAG_INTEGER :
206 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
207 fprintf(stderr, " %d", val->integer);
208 fputc('\n', stderr);
209 break;
210
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");
214 fputc('\n', stderr);
215 break;
216
217 case IPP_TAG_RANGE :
218 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
219 fprintf(stderr, " %d-%d", val->range.lower, val->range.upper);
220 fputc('\n', stderr);
221 break;
222
223 case IPP_TAG_DATE :
224 {
225 time_t vtime; /* Date/Time value */
226 struct tm *vdate; /* Date info */
227 char vstring[256]; /* Formatted time */
228
229 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
230 {
231 vtime = ippDateToTime(val->date);
232 vdate = localtime(&vtime);
233 strftime(vstring, sizeof(vstring), "%c", vdate);
234 fprintf(stderr, " (%s)", vstring);
235 }
236 }
237 fputc('\n', stderr);
238 break;
239
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");
245 fputc('\n', stderr);
246 break;
247
248 case IPP_TAG_STRING :
249 case IPP_TAG_TEXTLANG :
250 case IPP_TAG_NAMELANG :
251 case IPP_TAG_TEXT :
252 case IPP_TAG_NAME :
253 case IPP_TAG_KEYWORD :
254 case IPP_TAG_URI :
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);
261 fputc('\n', stderr);
262 break;
263
264 case IPP_TAG_BEGIN_COLLECTION :
265 fputc('\n', stderr);
266
267 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
268 {
269 if (i)
270 fputc('\n', stderr);
271 print_attributes(val->collection, indent + 4);
272 }
273 break;
274
275 default :
276 fprintf(stderr, "UNKNOWN (%d values)\n", attr->num_values);
277 break;
278 }
279 }
280}
281
282
283/*
bc44d920 284 * End of "$Id: testnotify.c 6649 2007-07-11 21:46:42Z mike $".
ef416fc2 285 */