2 * Notification routines for CUPS.
4 * Copyright 2007-2013 by Apple Inc.
5 * Copyright 2005-2006 by Easy Software Products.
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
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
24 * 'cupsNotifySubject()' - Return the subject for the given notification message.
26 * The returned string must be freed by the caller using @code free@.
28 * @since CUPS 1.2/macOS 10.5@
31 char * /* O - Subject string or @code NULL@ */
32 cupsNotifySubject(cups_lang_t *lang, /* I - Language data */
33 ipp_t *event) /* I - Event data */
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 */
48 * Range check input...
55 * Get the required attributes...
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",
68 if (job_id && printer_name && printer_uri && job_state)
74 prefix = _cupsLangString(lang, _("Print Job:"));
76 switch (job_state->values[0].integer)
78 case IPP_JSTATE_PENDING :
79 state = _cupsLangString(lang, _("pending"));
81 case IPP_JSTATE_HELD :
82 state = _cupsLangString(lang, _("held"));
84 case IPP_JSTATE_PROCESSING :
85 state = _cupsLangString(lang, _("processing"));
87 case IPP_JSTATE_STOPPED :
88 state = _cupsLangString(lang, _("stopped"));
90 case IPP_JSTATE_CANCELED :
91 state = _cupsLangString(lang, _("canceled"));
93 case IPP_JSTATE_ABORTED :
94 state = _cupsLangString(lang, _("aborted"));
96 case IPP_JSTATE_COMPLETED :
97 state = _cupsLangString(lang, _("completed"));
100 state = _cupsLangString(lang, _("unknown"));
104 snprintf(buffer, sizeof(buffer), "%s %s-%d (%s) %s",
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")),
112 else if (printer_uri && printer_name && printer_state)
118 prefix = _cupsLangString(lang, _("Printer:"));
120 switch (printer_state->values[0].integer)
122 case IPP_PSTATE_IDLE :
123 state = _cupsLangString(lang, _("idle"));
125 case IPP_PSTATE_PROCESSING :
126 state = _cupsLangString(lang, _("processing"));
128 case IPP_PSTATE_STOPPED :
129 state = _cupsLangString(lang, _("stopped"));
132 state = _cupsLangString(lang, _("unknown"));
136 snprintf(buffer, sizeof(buffer), "%s %s %s",
138 printer_name->values[0].string.text,
142 strlcpy(buffer, subscribed->values[0].string.text, sizeof(buffer));
147 * Duplicate and return the subject string...
150 return (strdup(buffer));
155 * 'cupsNotifyText()' - Return the text for the given notification message.
157 * The returned string must be freed by the caller using @code free@.
159 * @since CUPS 1.2/macOS 10.5@
162 char * /* O - Message text or @code NULL@ */
163 cupsNotifyText(cups_lang_t *lang, /* I - Language data */
164 ipp_t *event) /* I - Event data */
166 ipp_attribute_t *notify_text; /* notify-text */
170 * Range check input...
177 * Get the notify-text attribute from the server...
180 if ((notify_text = ippFindAttribute(event, "notify-text",
181 IPP_TAG_TEXT)) == NULL)
188 return (strdup(notify_text->values[0].string.text));