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