]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/notify.c
2 * "$Id: notify.c 5878 2006-08-24 15:55:42Z mike $"
4 * Notification routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2005-2006 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * cupsNotifySubject() - Return the subject for the given notification
30 * cupsNotifyText() - Return the text for the given notification message.
34 * Include necessary headers...
41 * 'cupsNotifySubject()' - Return the subject for the given notification message.
43 * The returned string must be freed by the caller using free().
48 char * /* O - Subject string or NULL */
49 cupsNotifySubject(cups_lang_t
*lang
, /* I - Language data */
50 ipp_t
*event
) /* I - Event data */
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 */
65 * Range check input...
72 * Get the required attributes...
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",
85 if (job_id
&& printer_name
&& printer_uri
&& job_state
)
91 prefix
= _cupsLangString(lang
, _("Print Job:"));
93 switch (job_state
->values
[0].integer
)
95 case IPP_JOB_PENDING
:
96 state
= _cupsLangString(lang
, _("pending"));
99 state
= _cupsLangString(lang
, _("held"));
101 case IPP_JOB_PROCESSING
:
102 state
= _cupsLangString(lang
, _("processing"));
104 case IPP_JOB_STOPPED
:
105 state
= _cupsLangString(lang
, _("stopped"));
107 case IPP_JOB_CANCELED
:
108 state
= _cupsLangString(lang
, _("canceled"));
110 case IPP_JOB_ABORTED
:
111 state
= _cupsLangString(lang
, _("aborted"));
113 case IPP_JOB_COMPLETED
:
114 state
= _cupsLangString(lang
, _("completed"));
117 state
= _cupsLangString(lang
, _("unknown"));
121 snprintf(buffer
, sizeof(buffer
), "%s %s-%d (%s) %s",
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")),
129 else if (printer_uri
&& printer_name
&& printer_state
)
135 prefix
= _cupsLangString(lang
, _("Printer:"));
137 switch (printer_state
->values
[0].integer
)
139 case IPP_PRINTER_IDLE
:
140 state
= _cupsLangString(lang
, _("idle"));
142 case IPP_PRINTER_PROCESSING
:
143 state
= _cupsLangString(lang
, _("processing"));
145 case IPP_PRINTER_STOPPED
:
146 state
= _cupsLangString(lang
, _("stopped"));
149 state
= _cupsLangString(lang
, _("unknown"));
153 snprintf(buffer
, sizeof(buffer
), "%s %s %s",
155 printer_name
->values
[0].string
.text
,
159 strlcpy(buffer
, subscribed
->values
[0].string
.text
, sizeof(buffer
));
164 * Duplicate and return the subject string...
167 return (strdup(buffer
));
172 * 'cupsNotifyText()' - Return the text for the given notification message.
174 * The returned string must be freed by the caller using free().
179 char * /* O - Message text or NULL */
180 cupsNotifyText(cups_lang_t
*lang
, /* I - Language data */
181 ipp_t
*event
) /* I - Event data */
183 ipp_attribute_t
*notify_text
; /* notify-text */
187 * Range check input...
194 * Get the notify-text attribute from the server...
197 if ((notify_text
= ippFindAttribute(event
, "notify-text",
198 IPP_TAG_TEXT
)) == NULL
)
205 return (strdup(notify_text
->values
[0].string
.text
));
210 * End of "$Id: notify.c 5878 2006-08-24 15:55:42Z mike $".