]> git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
Update svn:keyword properties.
[thirdparty/cups.git] / notifier / testnotify.c
1 /*
2 * "$Id$"
3 *
4 * Test notifier for CUPS.
5 *
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
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/".
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-private.h>
26
27
28 /*
29 * Local functions...
30 */
31
32 void print_attributes(ipp_t *ipp, int indent);
33
34
35 /*
36 * 'main()' - Main entry for the test notifier.
37 */
38
39 int /* O - Exit status */
40 main(int argc, /* I - Number of command-line arguments */
41 char *argv[]) /* I - Command-line arguments */
42 {
43 int i; /* Looping var */
44 ipp_t *event; /* Event from scheduler */
45 ipp_state_t state; /* IPP event state */
46
47
48 setbuf(stderr, NULL);
49
50 fprintf(stderr, "DEBUG: argc=%d\n", argc);
51 for (i = 0; i < argc; i ++)
52 fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);
53 fprintf(stderr, "DEBUG: TMPDIR=\"%s\"\n", getenv("TMPDIR"));
54
55 for (;;)
56 {
57 event = ippNew();
58 while ((state = ippReadFile(0, event)) != IPP_DATA)
59 {
60 if (state <= IPP_IDLE)
61 break;
62 }
63
64 if (state == IPP_ERROR)
65 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr);
66
67 if (state <= IPP_IDLE)
68 {
69 ippDelete(event);
70 return (0);
71 }
72
73 print_attributes(event, 4);
74 ippDelete(event);
75
76 /*
77 * If the recipient URI is "testnotify://nowait", then we exit after each
78 * event...
79 */
80
81 if (!strcmp(argv[1], "testnotify://nowait"))
82 return (0);
83 }
84 }
85
86
87 /*
88 * 'print_attributes()' - Print the attributes in a request...
89 */
90
91 void
92 print_attributes(ipp_t *ipp, /* I - IPP request */
93 int indent) /* I - Indentation */
94 {
95 ipp_tag_t group; /* Current group */
96 ipp_attribute_t *attr; /* Current attribute */
97 char buffer[1024]; /* Value buffer */
98
99
100 for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
101 {
102 if ((attr->group_tag == IPP_TAG_ZERO && indent <= 8) || !attr->name)
103 {
104 group = IPP_TAG_ZERO;
105 fputc('\n', stderr);
106 continue;
107 }
108
109 if (group != attr->group_tag)
110 {
111 group = attr->group_tag;
112
113 fprintf(stderr, "DEBUG: %*s%s:\n\n", indent - 4, "", ippTagString(group));
114 }
115
116 ippAttributeString(attr, buffer, sizeof(buffer));
117
118 fprintf(stderr, "DEBUG: %*s%s (%s%s) %s", indent, "", attr->name,
119 attr->num_values > 1 ? "1setOf " : "",
120 ippTagString(attr->value_tag), buffer);
121 }
122 }
123
124
125 /*
126 * End of "$Id$".
127 */