]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
503b54c9 | 2 | * Test notifier for CUPS. |
ef416fc2 | 3 | * |
503b54c9 MS |
4 | * Copyright 2007-2016 by Apple Inc. |
5 | * Copyright 1997-2005 by Easy Software Products. | |
ef416fc2 | 6 | * |
503b54c9 MS |
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 | |
57b7b66b | 11 | * missing or damaged, see the license at "http://www.cups.org/". |
ef416fc2 | 12 | */ |
13 | ||
14 | /* | |
15 | * Include necessary headers... | |
16 | */ | |
17 | ||
e60ec91f | 18 | #include <cups/cups-private.h> |
ef416fc2 | 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]); | |
cda47a96 | 46 | fprintf(stderr, "DEBUG: TMPDIR=\"%s\"\n", getenv("TMPDIR")); |
ef416fc2 | 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); | |
8ca02f3c | 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); | |
ef416fc2 | 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 | { | |
ef416fc2 | 88 | ipp_tag_t group; /* Current group */ |
89 | ipp_attribute_t *attr; /* Current attribute */ | |
e60ec91f | 90 | char buffer[1024]; /* Value buffer */ |
ef416fc2 | 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 | ||
e60ec91f | 106 | fprintf(stderr, "DEBUG: %*s%s:\n\n", indent - 4, "", ippTagString(group)); |
ef416fc2 | 107 | } |
108 | ||
a2326b5b | 109 | ippAttributeString(attr, buffer, sizeof(buffer)); |
ef416fc2 | 110 | |
79d3cd17 | 111 | fprintf(stderr, "DEBUG: %*s%s (%s%s) %s\n", indent, "", attr->name, |
e60ec91f MS |
112 | attr->num_values > 1 ? "1setOf " : "", |
113 | ippTagString(attr->value_tag), buffer); | |
ef416fc2 | 114 | } |
115 | } |