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