]>
Commit | Line | Data |
---|---|---|
fa73b229 | 1 | /* |
c07d5b2d | 2 | * "$Id: notify.c 177 2006-06-21 00:20:03Z jlovell $" |
fa73b229 | 3 | * |
4 | * Notification routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 2005-2006 by Easy Software Products. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * This file is subject to the Apple OS-Developed Software exception. | |
25 | * | |
26 | * Contents: | |
27 | * | |
28 | * cupsNotifySubject() - Return the subject for the given notification | |
29 | * message. | |
30 | * cupsNotifyText() - Return the text for the given notification message. | |
31 | */ | |
32 | ||
33 | /* | |
34 | * Include necessary headers... | |
35 | */ | |
36 | ||
37 | #include "globals.h" | |
38 | ||
39 | ||
40 | /* | |
41 | * 'cupsNotifySubject()' - Return the subject for the given notification message. | |
42 | * | |
43 | * The returned string must be freed by the caller using free(). | |
44 | * | |
45 | * @since CUPS 1.2@ | |
46 | */ | |
47 | ||
48 | char * /* O - Subject string or NULL */ | |
49 | cupsNotifySubject(cups_lang_t *lang, /* I - Language data */ | |
50 | ipp_t *event) /* I - Event data */ | |
51 | { | |
52 | char buffer[1024]; /* Subject buffer */ | |
53 | const char *prefix, /* Prefix on subject */ | |
54 | *state; /* Printer/job state string */ | |
55 | ipp_attribute_t *job_id, /* notify-job-id */ | |
56 | *job_name, /* job-name */ | |
57 | *job_state, /* job-state */ | |
58 | *printer_name, /* printer-name */ | |
59 | *printer_state, /* printer-state */ | |
60 | *printer_uri, /* notify-printer-uri */ | |
61 | *subscribed; /* notify-subscribed-event */ | |
62 | ||
63 | ||
64 | /* | |
65 | * Range check input... | |
66 | */ | |
67 | ||
68 | if (!event || !lang) | |
69 | return (NULL); | |
70 | ||
71 | /* | |
72 | * Get the required attributes... | |
73 | */ | |
74 | ||
75 | job_id = ippFindAttribute(event, "notify-job-id", IPP_TAG_INTEGER); | |
76 | job_name = ippFindAttribute(event, "job-name", IPP_TAG_NAME); | |
77 | job_state = ippFindAttribute(event, "job-state", IPP_TAG_ENUM); | |
78 | printer_name = ippFindAttribute(event, "printer-name", IPP_TAG_NAME); | |
79 | printer_state = ippFindAttribute(event, "printer-state", IPP_TAG_ENUM); | |
80 | printer_uri = ippFindAttribute(event, "notify-printer-uri", IPP_TAG_URI); | |
81 | subscribed = ippFindAttribute(event, "notify-subscribed-event", | |
82 | IPP_TAG_KEYWORD); | |
83 | ||
84 | ||
85 | if (job_id && printer_name && printer_uri && job_state) | |
86 | { | |
87 | /* | |
88 | * Job event... | |
89 | */ | |
90 | ||
91 | prefix = _cupsLangString(lang, _("Print Job:")); | |
92 | ||
93 | switch (job_state->values[0].integer) | |
94 | { | |
95 | case IPP_JOB_PENDING : | |
96 | state = _cupsLangString(lang, _("pending")); | |
97 | break; | |
98 | case IPP_JOB_HELD : | |
99 | state = _cupsLangString(lang, _("held")); | |
100 | break; | |
101 | case IPP_JOB_PROCESSING : | |
102 | state = _cupsLangString(lang, _("processing")); | |
103 | break; | |
104 | case IPP_JOB_STOPPED : | |
105 | state = _cupsLangString(lang, _("stopped")); | |
106 | break; | |
107 | case IPP_JOB_CANCELLED : | |
108 | state = _cupsLangString(lang, _("canceled")); | |
109 | break; | |
110 | case IPP_JOB_ABORTED : | |
111 | state = _cupsLangString(lang, _("aborted")); | |
112 | break; | |
113 | case IPP_JOB_COMPLETED : | |
114 | state = _cupsLangString(lang, _("completed")); | |
115 | break; | |
116 | default : | |
117 | state = _cupsLangString(lang, _("unknown")); | |
118 | break; | |
119 | } | |
120 | ||
121 | snprintf(buffer, sizeof(buffer), "%s %s-%d (%s) %s", | |
122 | prefix, | |
123 | printer_name->values[0].string.text, | |
124 | job_id->values[0].integer, | |
125 | job_name ? job_name->values[0].string.text : | |
126 | _cupsLangString(lang, _("untitled")), | |
127 | state); | |
128 | } | |
129 | else if (printer_uri && printer_name && printer_state) | |
130 | { | |
131 | /* | |
132 | * Printer event... | |
133 | */ | |
134 | ||
135 | prefix = _cupsLangString(lang, _("Printer:")); | |
136 | ||
137 | switch (printer_state->values[0].integer) | |
138 | { | |
139 | case IPP_PRINTER_IDLE : | |
140 | state = _cupsLangString(lang, _("idle")); | |
141 | break; | |
142 | case IPP_PRINTER_PROCESSING : | |
143 | state = _cupsLangString(lang, _("processing")); | |
144 | break; | |
145 | case IPP_PRINTER_STOPPED : | |
146 | state = _cupsLangString(lang, _("stopped")); | |
147 | break; | |
148 | default : | |
149 | state = _cupsLangString(lang, _("unknown")); | |
150 | break; | |
151 | } | |
152 | ||
153 | snprintf(buffer, sizeof(buffer), "%s %s %s", | |
154 | prefix, | |
155 | printer_name->values[0].string.text, | |
156 | state); | |
157 | } | |
158 | else if (subscribed) | |
159 | strlcpy(buffer, subscribed->values[0].string.text, sizeof(buffer)); | |
160 | else | |
161 | return (NULL); | |
162 | ||
163 | /* | |
164 | * Duplicate and return the subject string... | |
165 | */ | |
166 | ||
167 | return (strdup(buffer)); | |
168 | } | |
169 | ||
170 | ||
171 | /* | |
172 | * 'cupsNotifyText()' - Return the text for the given notification message. | |
173 | * | |
174 | * The returned string must be freed by the caller using free(). | |
175 | * | |
176 | * @since CUPS 1.2@ | |
177 | */ | |
178 | ||
179 | char * /* O - Message text or NULL */ | |
180 | cupsNotifyText(cups_lang_t *lang, /* I - Language data */ | |
181 | ipp_t *event) /* I - Event data */ | |
182 | { | |
183 | ipp_attribute_t *notify_text; /* notify-text */ | |
184 | ||
185 | ||
186 | /* | |
187 | * Range check input... | |
188 | */ | |
189 | ||
190 | if (!event || !lang) | |
191 | return (NULL); | |
192 | ||
193 | /* | |
194 | * Get the notify-text attribute from the server... | |
195 | */ | |
196 | ||
197 | if ((notify_text = ippFindAttribute(event, "notify-text", | |
198 | IPP_TAG_TEXT)) == NULL) | |
199 | return (NULL); | |
200 | ||
201 | /* | |
202 | * Return a copy... | |
203 | */ | |
204 | ||
205 | return (strdup(notify_text->values[0].string.text)); | |
206 | } | |
207 | ||
208 | ||
209 | /* | |
c07d5b2d | 210 | * End of "$Id: notify.c 177 2006-06-21 00:20:03Z jlovell $". |
fa73b229 | 211 | */ |