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