]>
Commit | Line | Data |
---|---|---|
fa73b229 | 1 | /* |
503b54c9 | 2 | * Notification routines for CUPS. |
fa73b229 | 3 | * |
503b54c9 MS |
4 | * Copyright 2007-2013 by Apple Inc. |
5 | * Copyright 2005-2006 by Easy Software Products. | |
fa73b229 | 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/". |
fa73b229 | 12 | * |
503b54c9 | 13 | * This file is subject to the Apple OS-Developed Software exception. |
fa73b229 | 14 | */ |
15 | ||
16 | /* | |
17 | * Include necessary headers... | |
18 | */ | |
19 | ||
71e16022 | 20 | #include "cups-private.h" |
fa73b229 | 21 | |
22 | ||
23 | /* | |
24 | * 'cupsNotifySubject()' - Return the subject for the given notification message. | |
25 | * | |
568fa3fa | 26 | * The returned string must be freed by the caller using @code free@. |
fa73b229 | 27 | * |
8072030b | 28 | * @since CUPS 1.2/macOS 10.5@ |
fa73b229 | 29 | */ |
30 | ||
5a738aea | 31 | char * /* O - Subject string or @code NULL@ */ |
fa73b229 | 32 | cupsNotifySubject(cups_lang_t *lang, /* I - Language data */ |
33 | ipp_t *event) /* I - Event data */ | |
34 | { | |
35 | char buffer[1024]; /* Subject buffer */ | |
36 | const char *prefix, /* Prefix on subject */ | |
37 | *state; /* Printer/job state string */ | |
38 | ipp_attribute_t *job_id, /* notify-job-id */ | |
39 | *job_name, /* job-name */ | |
40 | *job_state, /* job-state */ | |
41 | *printer_name, /* printer-name */ | |
42 | *printer_state, /* printer-state */ | |
43 | *printer_uri, /* notify-printer-uri */ | |
44 | *subscribed; /* notify-subscribed-event */ | |
45 | ||
46 | ||
47 | /* | |
48 | * Range check input... | |
49 | */ | |
50 | ||
51 | if (!event || !lang) | |
52 | return (NULL); | |
53 | ||
54 | /* | |
55 | * Get the required attributes... | |
56 | */ | |
57 | ||
58 | job_id = ippFindAttribute(event, "notify-job-id", IPP_TAG_INTEGER); | |
59 | job_name = ippFindAttribute(event, "job-name", IPP_TAG_NAME); | |
60 | job_state = ippFindAttribute(event, "job-state", IPP_TAG_ENUM); | |
61 | printer_name = ippFindAttribute(event, "printer-name", IPP_TAG_NAME); | |
62 | printer_state = ippFindAttribute(event, "printer-state", IPP_TAG_ENUM); | |
63 | printer_uri = ippFindAttribute(event, "notify-printer-uri", IPP_TAG_URI); | |
64 | subscribed = ippFindAttribute(event, "notify-subscribed-event", | |
65 | IPP_TAG_KEYWORD); | |
66 | ||
67 | ||
68 | if (job_id && printer_name && printer_uri && job_state) | |
69 | { | |
70 | /* | |
71 | * Job event... | |
72 | */ | |
73 | ||
74 | prefix = _cupsLangString(lang, _("Print Job:")); | |
75 | ||
76 | switch (job_state->values[0].integer) | |
77 | { | |
cb7f98ee | 78 | case IPP_JSTATE_PENDING : |
fa73b229 | 79 | state = _cupsLangString(lang, _("pending")); |
80 | break; | |
cb7f98ee | 81 | case IPP_JSTATE_HELD : |
fa73b229 | 82 | state = _cupsLangString(lang, _("held")); |
83 | break; | |
cb7f98ee | 84 | case IPP_JSTATE_PROCESSING : |
fa73b229 | 85 | state = _cupsLangString(lang, _("processing")); |
86 | break; | |
cb7f98ee | 87 | case IPP_JSTATE_STOPPED : |
fa73b229 | 88 | state = _cupsLangString(lang, _("stopped")); |
89 | break; | |
cb7f98ee | 90 | case IPP_JSTATE_CANCELED : |
fa73b229 | 91 | state = _cupsLangString(lang, _("canceled")); |
92 | break; | |
cb7f98ee | 93 | case IPP_JSTATE_ABORTED : |
fa73b229 | 94 | state = _cupsLangString(lang, _("aborted")); |
95 | break; | |
cb7f98ee | 96 | case IPP_JSTATE_COMPLETED : |
fa73b229 | 97 | state = _cupsLangString(lang, _("completed")); |
98 | break; | |
99 | default : | |
100 | state = _cupsLangString(lang, _("unknown")); | |
101 | break; | |
102 | } | |
103 | ||
104 | snprintf(buffer, sizeof(buffer), "%s %s-%d (%s) %s", | |
105 | prefix, | |
106 | printer_name->values[0].string.text, | |
107 | job_id->values[0].integer, | |
108 | job_name ? job_name->values[0].string.text : | |
109 | _cupsLangString(lang, _("untitled")), | |
110 | state); | |
111 | } | |
112 | else if (printer_uri && printer_name && printer_state) | |
113 | { | |
114 | /* | |
115 | * Printer event... | |
116 | */ | |
117 | ||
118 | prefix = _cupsLangString(lang, _("Printer:")); | |
119 | ||
120 | switch (printer_state->values[0].integer) | |
121 | { | |
cb7f98ee | 122 | case IPP_PSTATE_IDLE : |
fa73b229 | 123 | state = _cupsLangString(lang, _("idle")); |
124 | break; | |
cb7f98ee | 125 | case IPP_PSTATE_PROCESSING : |
fa73b229 | 126 | state = _cupsLangString(lang, _("processing")); |
127 | break; | |
cb7f98ee | 128 | case IPP_PSTATE_STOPPED : |
fa73b229 | 129 | state = _cupsLangString(lang, _("stopped")); |
130 | break; | |
131 | default : | |
132 | state = _cupsLangString(lang, _("unknown")); | |
133 | break; | |
134 | } | |
135 | ||
136 | snprintf(buffer, sizeof(buffer), "%s %s %s", | |
137 | prefix, | |
138 | printer_name->values[0].string.text, | |
139 | state); | |
140 | } | |
141 | else if (subscribed) | |
142 | strlcpy(buffer, subscribed->values[0].string.text, sizeof(buffer)); | |
143 | else | |
144 | return (NULL); | |
145 | ||
146 | /* | |
147 | * Duplicate and return the subject string... | |
148 | */ | |
149 | ||
150 | return (strdup(buffer)); | |
151 | } | |
152 | ||
153 | ||
154 | /* | |
155 | * 'cupsNotifyText()' - Return the text for the given notification message. | |
156 | * | |
5a738aea | 157 | * The returned string must be freed by the caller using @code free@. |
fa73b229 | 158 | * |
8072030b | 159 | * @since CUPS 1.2/macOS 10.5@ |
fa73b229 | 160 | */ |
161 | ||
5a738aea | 162 | char * /* O - Message text or @code NULL@ */ |
fa73b229 | 163 | cupsNotifyText(cups_lang_t *lang, /* I - Language data */ |
164 | ipp_t *event) /* I - Event data */ | |
165 | { | |
166 | ipp_attribute_t *notify_text; /* notify-text */ | |
167 | ||
168 | ||
169 | /* | |
170 | * Range check input... | |
171 | */ | |
172 | ||
173 | if (!event || !lang) | |
174 | return (NULL); | |
175 | ||
176 | /* | |
177 | * Get the notify-text attribute from the server... | |
178 | */ | |
179 | ||
180 | if ((notify_text = ippFindAttribute(event, "notify-text", | |
181 | IPP_TAG_TEXT)) == NULL) | |
182 | return (NULL); | |
183 | ||
184 | /* | |
185 | * Return a copy... | |
186 | */ | |
187 | ||
188 | return (strdup(notify_text->values[0].string.text)); | |
189 | } |