]> git.ipfire.org Git - thirdparty/cups.git/blob - notifier/testnotify.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / notifier / testnotify.c
1 /*
2 * Test notifier for CUPS.
3 *
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2005 by Easy Software Products.
6 *
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
12 */
13
14 /*
15 * Include necessary headers...
16 */
17
18 #include <cups/cups-private.h>
19
20
21 /*
22 * Local functions...
23 */
24
25 void print_attributes(ipp_t *ipp, int indent);
26
27
28 /*
29 * 'main()' - Main entry for the test notifier.
30 */
31
32 int /* O - Exit status */
33 main(int argc, /* I - Number of command-line arguments */
34 char *argv[]) /* I - Command-line arguments */
35 {
36 int i; /* Looping var */
37 ipp_t *event; /* Event from scheduler */
38 ipp_state_t state; /* IPP event state */
39
40
41 setbuf(stderr, NULL);
42
43 fprintf(stderr, "DEBUG: argc=%d\n", argc);
44 for (i = 0; i < argc; i ++)
45 fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);
46 fprintf(stderr, "DEBUG: TMPDIR=\"%s\"\n", getenv("TMPDIR"));
47
48 for (;;)
49 {
50 event = ippNew();
51 while ((state = ippReadFile(0, event)) != IPP_DATA)
52 {
53 if (state <= IPP_IDLE)
54 break;
55 }
56
57 if (state == IPP_ERROR)
58 fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr);
59
60 if (state <= IPP_IDLE)
61 {
62 ippDelete(event);
63 return (0);
64 }
65
66 print_attributes(event, 4);
67 ippDelete(event);
68
69 /*
70 * If the recipient URI is "testnotify://nowait", then we exit after each
71 * event...
72 */
73
74 if (!strcmp(argv[1], "testnotify://nowait"))
75 return (0);
76 }
77 }
78
79
80 /*
81 * 'print_attributes()' - Print the attributes in a request...
82 */
83
84 void
85 print_attributes(ipp_t *ipp, /* I - IPP request */
86 int indent) /* I - Indentation */
87 {
88 ipp_tag_t group; /* Current group */
89 ipp_attribute_t *attr; /* Current attribute */
90 char buffer[1024]; /* Value buffer */
91
92
93 for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
94 {
95 if ((attr->group_tag == IPP_TAG_ZERO && indent <= 8) || !attr->name)
96 {
97 group = IPP_TAG_ZERO;
98 fputc('\n', stderr);
99 continue;
100 }
101
102 if (group != attr->group_tag)
103 {
104 group = attr->group_tag;
105
106 fprintf(stderr, "DEBUG: %*s%s:\n\n", indent - 4, "", ippTagString(group));
107 }
108
109 ippAttributeString(attr, buffer, sizeof(buffer));
110
111 fprintf(stderr, "DEBUG: %*s%s (%s%s) %s\n", indent, "", attr->name,
112 attr->num_values > 1 ? "1setOf " : "",
113 ippTagString(attr->value_tag), buffer);
114 }
115 }