]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/notify.c
2 * "$Id: notify.c 7337 2008-02-22 04:44:04Z mike $"
4 * Notification routines for CUPS.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 2005-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * cupsNotifySubject() - Return the subject for the given notification
21 * cupsNotifyText() - Return the text for the given notification message.
25 * Include necessary headers...
28 #include "cups-private.h"
32 * 'cupsNotifySubject()' - Return the subject for the given notification message.
34 * The returned string must be freed by the caller using @code free@.
36 * @since CUPS 1.2/Mac OS X 10.5@
39 char * /* O - Subject string or @code NULL@ */
40 cupsNotifySubject(cups_lang_t
*lang
, /* I - Language data */
41 ipp_t
*event
) /* I - Event data */
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 */
56 * Range check input...
63 * Get the required attributes...
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",
76 if (job_id
&& printer_name
&& printer_uri
&& job_state
)
82 prefix
= _cupsLangString(lang
, _("Print Job:"));
84 switch (job_state
->values
[0].integer
)
86 case IPP_JOB_PENDING
:
87 state
= _cupsLangString(lang
, _("pending"));
90 state
= _cupsLangString(lang
, _("held"));
92 case IPP_JOB_PROCESSING
:
93 state
= _cupsLangString(lang
, _("processing"));
95 case IPP_JOB_STOPPED
:
96 state
= _cupsLangString(lang
, _("stopped"));
98 case IPP_JOB_CANCELED
:
99 state
= _cupsLangString(lang
, _("canceled"));
101 case IPP_JOB_ABORTED
:
102 state
= _cupsLangString(lang
, _("aborted"));
104 case IPP_JOB_COMPLETED
:
105 state
= _cupsLangString(lang
, _("completed"));
108 state
= _cupsLangString(lang
, _("unknown"));
112 snprintf(buffer
, sizeof(buffer
), "%s %s-%d (%s) %s",
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")),
120 else if (printer_uri
&& printer_name
&& printer_state
)
126 prefix
= _cupsLangString(lang
, _("Printer:"));
128 switch (printer_state
->values
[0].integer
)
130 case IPP_PRINTER_IDLE
:
131 state
= _cupsLangString(lang
, _("idle"));
133 case IPP_PRINTER_PROCESSING
:
134 state
= _cupsLangString(lang
, _("processing"));
136 case IPP_PRINTER_STOPPED
:
137 state
= _cupsLangString(lang
, _("stopped"));
140 state
= _cupsLangString(lang
, _("unknown"));
144 snprintf(buffer
, sizeof(buffer
), "%s %s %s",
146 printer_name
->values
[0].string
.text
,
150 strlcpy(buffer
, subscribed
->values
[0].string
.text
, sizeof(buffer
));
155 * Duplicate and return the subject string...
158 return (strdup(buffer
));
163 * 'cupsNotifyText()' - Return the text for the given notification message.
165 * The returned string must be freed by the caller using @code free@.
167 * @since CUPS 1.2/Mac OS X 10.5@
170 char * /* O - Message text or @code NULL@ */
171 cupsNotifyText(cups_lang_t
*lang
, /* I - Language data */
172 ipp_t
*event
) /* I - Event data */
174 ipp_attribute_t
*notify_text
; /* notify-text */
178 * Range check input...
185 * Get the notify-text attribute from the server...
188 if ((notify_text
= ippFindAttribute(event
, "notify-text",
189 IPP_TAG_TEXT
)) == NULL
)
196 return (strdup(notify_text
->values
[0].string
.text
));
201 * End of "$Id: notify.c 7337 2008-02-22 04:44:04Z mike $".