]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/notify.c
2 * Notification routines for CUPS.
4 * Copyright 2007-2013 by Apple Inc.
5 * Copyright 2005-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cups-private.h"
15 #include "debug-internal.h"
19 * 'cupsNotifySubject()' - Return the subject for the given notification message.
21 * The returned string must be freed by the caller using @code free@.
23 * @since CUPS 1.2/macOS 10.5@
26 char * /* O - Subject string or @code NULL@ */
27 cupsNotifySubject(cups_lang_t
*lang
, /* I - Language data */
28 ipp_t
*event
) /* I - Event data */
30 char buffer
[1024]; /* Subject buffer */
31 const char *prefix
, /* Prefix on subject */
32 *state
; /* Printer/job state string */
33 ipp_attribute_t
*job_id
, /* notify-job-id */
34 *job_name
, /* job-name */
35 *job_state
, /* job-state */
36 *printer_name
, /* printer-name */
37 *printer_state
, /* printer-state */
38 *printer_uri
, /* notify-printer-uri */
39 *subscribed
; /* notify-subscribed-event */
43 * Range check input...
50 * Get the required attributes...
53 job_id
= ippFindAttribute(event
, "notify-job-id", IPP_TAG_INTEGER
);
54 job_name
= ippFindAttribute(event
, "job-name", IPP_TAG_NAME
);
55 job_state
= ippFindAttribute(event
, "job-state", IPP_TAG_ENUM
);
56 printer_name
= ippFindAttribute(event
, "printer-name", IPP_TAG_NAME
);
57 printer_state
= ippFindAttribute(event
, "printer-state", IPP_TAG_ENUM
);
58 printer_uri
= ippFindAttribute(event
, "notify-printer-uri", IPP_TAG_URI
);
59 subscribed
= ippFindAttribute(event
, "notify-subscribed-event",
63 if (job_id
&& printer_name
&& printer_uri
&& job_state
)
69 prefix
= _cupsLangString(lang
, _("Print Job:"));
71 switch (job_state
->values
[0].integer
)
73 case IPP_JSTATE_PENDING
:
74 state
= _cupsLangString(lang
, _("pending"));
76 case IPP_JSTATE_HELD
:
77 state
= _cupsLangString(lang
, _("held"));
79 case IPP_JSTATE_PROCESSING
:
80 state
= _cupsLangString(lang
, _("processing"));
82 case IPP_JSTATE_STOPPED
:
83 state
= _cupsLangString(lang
, _("stopped"));
85 case IPP_JSTATE_CANCELED
:
86 state
= _cupsLangString(lang
, _("canceled"));
88 case IPP_JSTATE_ABORTED
:
89 state
= _cupsLangString(lang
, _("aborted"));
91 case IPP_JSTATE_COMPLETED
:
92 state
= _cupsLangString(lang
, _("completed"));
95 state
= _cupsLangString(lang
, _("unknown"));
99 snprintf(buffer
, sizeof(buffer
), "%s %s-%d (%s) %s",
101 printer_name
->values
[0].string
.text
,
102 job_id
->values
[0].integer
,
103 job_name
? job_name
->values
[0].string
.text
:
104 _cupsLangString(lang
, _("untitled")),
107 else if (printer_uri
&& printer_name
&& printer_state
)
113 prefix
= _cupsLangString(lang
, _("Printer:"));
115 switch (printer_state
->values
[0].integer
)
117 case IPP_PSTATE_IDLE
:
118 state
= _cupsLangString(lang
, _("idle"));
120 case IPP_PSTATE_PROCESSING
:
121 state
= _cupsLangString(lang
, _("processing"));
123 case IPP_PSTATE_STOPPED
:
124 state
= _cupsLangString(lang
, _("stopped"));
127 state
= _cupsLangString(lang
, _("unknown"));
131 snprintf(buffer
, sizeof(buffer
), "%s %s %s",
133 printer_name
->values
[0].string
.text
,
137 strlcpy(buffer
, subscribed
->values
[0].string
.text
, sizeof(buffer
));
142 * Duplicate and return the subject string...
145 return (strdup(buffer
));
150 * 'cupsNotifyText()' - Return the text for the given notification message.
152 * The returned string must be freed by the caller using @code free@.
154 * @since CUPS 1.2/macOS 10.5@
157 char * /* O - Message text or @code NULL@ */
158 cupsNotifyText(cups_lang_t
*lang
, /* I - Language data */
159 ipp_t
*event
) /* I - Event data */
161 ipp_attribute_t
*notify_text
; /* notify-text */
165 * Range check input...
172 * Get the notify-text attribute from the server...
175 if ((notify_text
= ippFindAttribute(event
, "notify-text",
176 IPP_TAG_TEXT
)) == NULL
)
183 return (strdup(notify_text
->values
[0].string
.text
));