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