]> git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
Load cups into easysw/current.
[thirdparty/cups.git] / notifier / testnotify.c
1 /*
2 * "$Id: testnotify.c 4829 2005-11-12 03:15:10Z 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
88
89 /*
90 * 'print_attributes()' - Print the attributes in a request...
91 */
92
93 void
94 print_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 /*
284 * End of "$Id: testnotify.c 4829 2005-11-12 03:15:10Z mike $".
285 */