]> git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
d0a502b20c51ee339081ad6d3dc44cf8109b0547
[thirdparty/cups.git] / notifier / testnotify.c
1 /*
2 * "$Id: testnotify.c 5716 2006-07-11 17:56:57Z mike $"
3 *
4 * Test notifier for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2005 by Easy Software Products.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * main() - Main entry for the test notifier.
27 * print_attributes() - Print the attributes in a request...
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 #include <cups/cups.h>
35 #include <cups/language.h>
36 #include <cups/string.h>
37
38
39 /*
40 * Local functions...
41 */
42
43 void print_attributes(ipp_t *ipp, int indent);
44
45
46 /*
47 * 'main()' - Main entry for the test notifier.
48 */
49
50 int /* O - Exit status */
51 main(int argc, /* I - Number of command-line arguments */
52 char *argv[]) /* I - Command-line arguments */
53 {
54 int i; /* Looping var */
55 ipp_t *event; /* Event from scheduler */
56 ipp_state_t state; /* IPP event state */
57
58
59 setbuf(stderr, NULL);
60
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]);
64
65 for (;;)
66 {
67 event = ippNew();
68 while ((state = ippReadFile(0, event)) != IPP_DATA)
69 {
70 if (state <= IPP_IDLE)
71 break;
72 }
73
74 if (state == IPP_ERROR)
75 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr);
76
77 if (state <= IPP_IDLE)
78 {
79 ippDelete(event);
80 return (0);
81 }
82
83 print_attributes(event, 4);
84 ippDelete(event);
85
86 /*
87 * If the recipient URI is "testnotify://nowait", then we exit after each
88 * event...
89 */
90
91 if (!strcmp(argv[1], "testnotify://nowait"))
92 return (0);
93 }
94 }
95
96
97 /*
98 * 'print_attributes()' - Print the attributes in a request...
99 */
100
101 void
102 print_attributes(ipp_t *ipp, /* I - IPP request */
103 int indent) /* I - Indentation */
104 {
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 */
110 {
111 "reserved-00",
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",
119 "reserved-08",
120 "reserved-09",
121 "reserved-0A",
122 "reserved-0B",
123 "reserved-0C",
124 "reserved-0D",
125 "reserved-0E",
126 "reserved-0F",
127 "unsupported",
128 "default",
129 "unknown",
130 "no-value",
131 "reserved-14",
132 "not-settable",
133 "delete-attr",
134 "admin-define",
135 "reserved-18",
136 "reserved-19",
137 "reserved-1A",
138 "reserved-1B",
139 "reserved-1C",
140 "reserved-1D",
141 "reserved-1E",
142 "reserved-1F",
143 "reserved-20",
144 "integer",
145 "boolean",
146 "enum",
147 "reserved-24",
148 "reserved-25",
149 "reserved-26",
150 "reserved-27",
151 "reserved-28",
152 "reserved-29",
153 "reserved-2a",
154 "reserved-2b",
155 "reserved-2c",
156 "reserved-2d",
157 "reserved-2e",
158 "reserved-2f",
159 "octetString",
160 "dateTime",
161 "resolution",
162 "rangeOfInteger",
163 "begCollection",
164 "textWithLanguage",
165 "nameWithLanguage",
166 "endCollection",
167 "reserved-38",
168 "reserved-39",
169 "reserved-3a",
170 "reserved-3b",
171 "reserved-3c",
172 "reserved-3d",
173 "reserved-3e",
174 "reserved-3f",
175 "reserved-40",
176 "textWithoutLanguage",
177 "nameWithoutLanguage",
178 "reserved-43",
179 "keyword",
180 "uri",
181 "uriScheme",
182 "charset",
183 "naturalLanguage",
184 "mimeMediaType",
185 "memberName"
186 };
187
188
189 for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
190 {
191 if ((attr->group_tag == IPP_TAG_ZERO && indent <= 8) || !attr->name)
192 {
193 group = IPP_TAG_ZERO;
194 fputc('\n', stderr);
195 continue;
196 }
197
198 if (group != attr->group_tag)
199 {
200 group = attr->group_tag;
201
202 fprintf(stderr, "DEBUG: %*s%s:\n\n", indent - 4, "", tags[group]);
203 }
204
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]);
209
210 switch (attr->value_tag)
211 {
212 case IPP_TAG_ENUM :
213 case IPP_TAG_INTEGER :
214 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
215 fprintf(stderr, " %d", val->integer);
216 fputc('\n', stderr);
217 break;
218
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");
222 fputc('\n', stderr);
223 break;
224
225 case IPP_TAG_RANGE :
226 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
227 fprintf(stderr, " %d-%d", val->range.lower, val->range.upper);
228 fputc('\n', stderr);
229 break;
230
231 case IPP_TAG_DATE :
232 {
233 time_t vtime; /* Date/Time value */
234 struct tm *vdate; /* Date info */
235 char vstring[256]; /* Formatted time */
236
237 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
238 {
239 vtime = ippDateToTime(val->date);
240 vdate = localtime(&vtime);
241 strftime(vstring, sizeof(vstring), "%c", vdate);
242 fprintf(stderr, " (%s)", vstring);
243 }
244 }
245 fputc('\n', stderr);
246 break;
247
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");
253 fputc('\n', stderr);
254 break;
255
256 case IPP_TAG_STRING :
257 case IPP_TAG_TEXTLANG :
258 case IPP_TAG_NAMELANG :
259 case IPP_TAG_TEXT :
260 case IPP_TAG_NAME :
261 case IPP_TAG_KEYWORD :
262 case IPP_TAG_URI :
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);
269 fputc('\n', stderr);
270 break;
271
272 case IPP_TAG_BEGIN_COLLECTION :
273 fputc('\n', stderr);
274
275 for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
276 {
277 if (i)
278 fputc('\n', stderr);
279 print_attributes(val->collection, indent + 4);
280 }
281 break;
282
283 default :
284 fprintf(stderr, "UNKNOWN (%d values)\n", attr->num_values);
285 break;
286 }
287 }
288 }
289
290
291 /*
292 * End of "$Id: testnotify.c 5716 2006-07-11 17:56:57Z mike $".
293 */