Coverage Report

Created: 2026-09-14 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cups/cups/notify.c
Line
Count
Source
1
/*
2
 * Notification routines for CUPS.
3
 *
4
 * Copyright 2007-2013 by Apple Inc.
5
 * Copyright 2005-2006 by Easy Software Products.
6
 *
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/".
12
 *
13
 * This file is subject to the Apple OS-Developed Software exception.
14
 */
15
16
/*
17
 * Include necessary headers...
18
 */
19
20
#include "cups-private.h"
21
22
23
/*
24
 * 'cupsNotifySubject()' - Return the subject for the given notification message.
25
 *
26
 * The returned string must be freed by the caller using @code free@.
27
 *
28
 * @since CUPS 1.2/macOS 10.5@
29
 */
30
31
char *          /* O - Subject string or @code NULL@ */
32
cupsNotifySubject(cups_lang_t *lang,  /* I - Language data */
33
                  ipp_t       *event) /* I - Event data */
34
0
{
35
0
  char      buffer[1024]; /* Subject buffer */
36
0
  const char    *prefix,  /* Prefix on subject */
37
0
      *state;   /* Printer/job state string */
38
0
  ipp_attribute_t *job_id,  /* notify-job-id */
39
0
      *job_name,  /* job-name */
40
0
      *job_state, /* job-state */
41
0
      *printer_name,  /* printer-name */
42
0
      *printer_state, /* printer-state */
43
0
      *printer_uri, /* notify-printer-uri */
44
0
      *subscribed;  /* notify-subscribed-event */
45
46
47
 /*
48
  * Range check input...
49
  */
50
51
0
  if (!event || !lang)
52
0
    return (NULL);
53
54
 /*
55
  * Get the required attributes...
56
  */
57
58
0
  job_id        = ippFindAttribute(event, "notify-job-id", IPP_TAG_INTEGER);
59
0
  job_name      = ippFindAttribute(event, "job-name", IPP_TAG_NAME);
60
0
  job_state     = ippFindAttribute(event, "job-state", IPP_TAG_ENUM);
61
0
  printer_name  = ippFindAttribute(event, "printer-name", IPP_TAG_NAME);
62
0
  printer_state = ippFindAttribute(event, "printer-state", IPP_TAG_ENUM);
63
0
  printer_uri   = ippFindAttribute(event, "notify-printer-uri", IPP_TAG_URI);
64
0
  subscribed    = ippFindAttribute(event, "notify-subscribed-event",
65
0
                                   IPP_TAG_KEYWORD);
66
67
68
0
  if (job_id && printer_name && printer_uri && job_state)
69
0
  {
70
   /*
71
    * Job event...
72
    */
73
74
0
    prefix = _cupsLangString(lang, _("Print Job:"));
75
76
0
    switch (job_state->values[0].integer)
77
0
    {
78
0
      case IPP_JSTATE_PENDING :
79
0
          state = _cupsLangString(lang, _("pending"));
80
0
    break;
81
0
      case IPP_JSTATE_HELD :
82
0
          state = _cupsLangString(lang, _("held"));
83
0
    break;
84
0
      case IPP_JSTATE_PROCESSING :
85
0
          state = _cupsLangString(lang, _("processing"));
86
0
    break;
87
0
      case IPP_JSTATE_STOPPED :
88
0
          state = _cupsLangString(lang, _("stopped"));
89
0
    break;
90
0
      case IPP_JSTATE_CANCELED :
91
0
          state = _cupsLangString(lang, _("canceled"));
92
0
    break;
93
0
      case IPP_JSTATE_ABORTED :
94
0
          state = _cupsLangString(lang, _("aborted"));
95
0
    break;
96
0
      case IPP_JSTATE_COMPLETED :
97
0
          state = _cupsLangString(lang, _("completed"));
98
0
    break;
99
0
      default :
100
0
          state = _cupsLangString(lang, _("unknown"));
101
0
    break;
102
0
    }
103
104
0
    snprintf(buffer, sizeof(buffer), "%s %s-%d (%s) %s",
105
0
             prefix,
106
0
       printer_name->values[0].string.text,
107
0
       job_id->values[0].integer,
108
0
       job_name ? job_name->values[0].string.text :
109
0
           _cupsLangString(lang, _("untitled")),
110
0
       state);
111
0
  }
112
0
  else if (printer_uri && printer_name && printer_state)
113
0
  {
114
   /*
115
    * Printer event...
116
    */
117
118
0
    prefix = _cupsLangString(lang, _("Printer:"));
119
120
0
    switch (printer_state->values[0].integer)
121
0
    {
122
0
      case IPP_PSTATE_IDLE :
123
0
          state = _cupsLangString(lang, _("idle"));
124
0
    break;
125
0
      case IPP_PSTATE_PROCESSING :
126
0
          state = _cupsLangString(lang, _("processing"));
127
0
    break;
128
0
      case IPP_PSTATE_STOPPED :
129
0
          state = _cupsLangString(lang, _("stopped"));
130
0
    break;
131
0
      default :
132
0
          state = _cupsLangString(lang, _("unknown"));
133
0
    break;
134
0
    }
135
136
0
    snprintf(buffer, sizeof(buffer), "%s %s %s",
137
0
             prefix,
138
0
       printer_name->values[0].string.text,
139
0
       state);
140
0
  }
141
0
  else if (subscribed)
142
0
    strlcpy(buffer, subscribed->values[0].string.text, sizeof(buffer));
143
0
  else
144
0
    return (NULL);
145
146
 /*
147
  * Duplicate and return the subject string...
148
  */
149
150
0
  return (strdup(buffer));
151
0
}
152
153
154
/*
155
 * 'cupsNotifyText()' - Return the text for the given notification message.
156
 *
157
 * The returned string must be freed by the caller using @code free@.
158
 *
159
 * @since CUPS 1.2/macOS 10.5@
160
 */
161
162
char *          /* O - Message text or @code NULL@ */
163
cupsNotifyText(cups_lang_t *lang, /* I - Language data */
164
               ipp_t       *event)  /* I - Event data */
165
0
{
166
0
  ipp_attribute_t *notify_text; /* notify-text */
167
168
169
 /*
170
  * Range check input...
171
  */
172
173
0
  if (!event || !lang)
174
0
    return (NULL);
175
176
 /*
177
  * Get the notify-text attribute from the server...
178
  */
179
180
0
  if ((notify_text = ippFindAttribute(event, "notify-text",
181
0
                                      IPP_TAG_TEXT)) == NULL)
182
0
    return (NULL);
183
184
 /*
185
  * Return a copy...
186
  */
187
188
0
  return (strdup(notify_text->values[0].string.text));
189
0
}