2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_document() - Get a copy of a job file.
66 * get_job_attrs() - Get job attributes.
67 * get_jobs() - Get a list of jobs for the specified printer.
68 * get_notifications() - Get events for a subscription.
69 * get_ppd() - Get a named PPD from the local system.
70 * get_ppds() - Get the list of PPD files on the local
72 * get_printer_attrs() - Get printer attributes.
73 * get_printer_supported() - Get printer supported values.
74 * get_printers() - Get a list of printers or classes.
75 * get_subscription_attrs() - Get subscription attributes.
76 * get_subscriptions() - Get subscriptions.
77 * get_username() - Get the username associated with a request.
78 * hold_job() - Hold a print job.
79 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
80 * move_job() - Move a job to a new destination.
81 * ppd_parse_line() - Parse a PPD default line.
82 * print_job() - Print a file to a printer or class.
83 * read_job_ticket() - Read a job ticket embedded in a print file.
84 * reject_jobs() - Reject print jobs to a printer.
85 * release_held_new_jobs() - Release pending/new jobs on a printer or
87 * release_job() - Release a held print job.
88 * renew_subscription() - Renew an existing subscription...
89 * restart_job() - Restart an old print job.
90 * save_auth_info() - Save authentication information for a job.
91 * send_document() - Send a file to a printer or class.
92 * send_http_error() - Send a HTTP error back to the IPP client.
93 * send_ipp_status() - Send a status back to the IPP client.
94 * set_default() - Set the default destination...
95 * set_job_attrs() - Set job attributes.
96 * set_printer_attrs() - Set printer attributes.
97 * set_printer_defaults() - Set printer default options from a request.
98 * start_printer() - Start a printer.
99 * stop_printer() - Stop a printer.
100 * url_encode_attr() - URL-encode a string attribute.
101 * url_encode_string() - URL-encode a string.
102 * user_allowed() - See if a user is allowed to print to a queue.
103 * validate_job() - Validate printer options and destination.
104 * validate_name() - Make sure the printer name only contains
106 * validate_user() - Validate the user for the request.
110 * Include necessary headers...
114 #include <cups/ppd-private.h>
117 # include <ApplicationServices/ApplicationServices.h>
118 # ifdef HAVE_COLORSYNCREGISTERDEVICE
119 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
120 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
121 # include <CoreFoundation/CoreFoundation.h>
122 # ifdef HAVE_MEMBERSHIP_H
123 # include <membership.h>
124 # endif /* HAVE_MEMBERSHIP_H */
125 # ifdef HAVE_MEMBERSHIPPRIV_H
126 # include <membershipPriv.h>
128 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
129 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
130 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
131 # endif /* HAVE_MEMBERSHIPPRIV_H */
132 #endif /* __APPLE__ */
139 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
140 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
141 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
142 mime_type_t
*filetype
, int compression
);
143 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
144 mime_type_t
*filetype
);
145 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
147 static void add_job_uuid(cupsd_job_t
*job
);
148 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
149 static void add_printer_state_reasons(cupsd_client_t
*con
,
151 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
153 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
154 # ifdef HAVE_COLORSYNCREGISTERDEVICE
155 CFMutableDictionaryRef profile
,
157 CMDeviceProfileInfo
*profile
,
158 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
159 unsigned id
, const char *name
,
160 const char *text
, const char *iccfile
);
161 static void apple_register_profiles(cupsd_printer_t
*p
);
162 static void apple_unregister_profiles(cupsd_printer_t
*p
);
163 #endif /* __APPLE__ */
164 static void apply_printer_defaults(cupsd_printer_t
*printer
,
166 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void cancel_subscription(cupsd_client_t
*con
, int id
);
170 static int check_rss_recipient(const char *recipient
);
171 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
172 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
174 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
175 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
176 ipp_tag_t group
, int quickcopy
,
177 cups_array_t
*exclude
);
178 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
180 static int copy_file(const char *from
, const char *to
);
181 static int copy_model(cupsd_client_t
*con
, const char *from
,
183 static void copy_job_attrs(cupsd_client_t
*con
,
185 cups_array_t
*ra
, cups_array_t
*exclude
);
186 static void copy_printer_attrs(cupsd_client_t
*con
,
187 cupsd_printer_t
*printer
,
189 static void copy_subscription_attrs(cupsd_client_t
*con
,
190 cupsd_subscription_t
*sub
,
192 cups_array_t
*exclude
);
193 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static cups_array_t
*create_requested_array(ipp_t
*request
);
195 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_default(cupsd_client_t
*con
);
198 static void get_devices(cupsd_client_t
*con
);
199 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_notifications(cupsd_client_t
*con
);
203 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void get_ppds(cupsd_client_t
*con
);
205 static void get_printers(cupsd_client_t
*con
, int type
);
206 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
209 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static const char *get_username(cupsd_client_t
*con
);
211 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static int ppd_parse_line(const char *line
, char *option
, int olen
,
215 char *choice
, int clen
);
216 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
217 static void read_job_ticket(cupsd_client_t
*con
);
218 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
219 static void release_held_new_jobs(cupsd_client_t
*con
,
220 ipp_attribute_t
*uri
);
221 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
222 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
223 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
225 ipp_attribute_t
*auth_info
);
226 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
228 cupsd_printer_t
*printer
);
229 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
230 const char *message
, ...)
231 __attribute__((__format__(__printf__
, 3, 4)));
232 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
233 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void set_printer_defaults(cupsd_client_t
*con
,
236 cupsd_printer_t
*printer
);
237 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
238 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
239 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
241 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
242 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
243 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
244 static int validate_name(const char *name
);
245 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
246 const char *owner
, char *username
,
251 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
254 int /* O - 1 on success, 0 on failure */
255 cupsdProcessIPPRequest(
256 cupsd_client_t
*con
) /* I - Client connection */
258 ipp_tag_t group
; /* Current group tag */
259 ipp_attribute_t
*attr
; /* Current attribute */
260 ipp_attribute_t
*charset
; /* Character set attribute */
261 ipp_attribute_t
*language
; /* Language attribute */
262 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
263 ipp_attribute_t
*username
; /* requesting-user-name attr */
264 int sub_id
; /* Subscription ID */
267 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
268 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
269 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
272 * First build an empty response message for this request...
275 con
->response
= ippNew();
277 con
->response
->request
.status
.version
[0] =
278 con
->request
->request
.op
.version
[0];
279 con
->response
->request
.status
.version
[1] =
280 con
->request
->request
.op
.version
[1];
281 con
->response
->request
.status
.request_id
=
282 con
->request
->request
.op
.request_id
;
285 * Then validate the request header and required attributes...
288 if (con
->request
->request
.any
.version
[0] != 1 &&
289 con
->request
->request
.any
.version
[0] != 2)
292 * Return an error, since we only support IPP 1.x and 2.x.
295 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
296 "%04X %s Bad request version number %d.%d",
297 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
298 con
->request
->request
.any
.version
[0],
299 con
->request
->request
.any
.version
[1]);
301 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
302 _("Bad request version number %d.%d."),
303 con
->request
->request
.any
.version
[0],
304 con
->request
->request
.any
.version
[1]);
306 else if (con
->request
->request
.any
.request_id
< 1)
309 * Return an error, since request IDs must be between 1 and 2^31-1
312 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
313 "%04X %s Bad request ID %d",
314 IPP_BAD_REQUEST
, con
->http
.hostname
,
315 con
->request
->request
.any
.request_id
);
317 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
318 con
->request
->request
.any
.request_id
);
320 else if (!con
->request
->attrs
)
322 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
323 "%04X %s No attributes in request",
324 IPP_BAD_REQUEST
, con
->http
.hostname
);
326 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
331 * Make sure that the attributes are provided in the correct order and
332 * don't repeat groups...
335 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
338 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
341 * Out of order; return an error...
344 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
345 "%04X %s Attribute groups are out of order",
346 IPP_BAD_REQUEST
, con
->http
.hostname
);
348 send_ipp_status(con
, IPP_BAD_REQUEST
,
349 _("Attribute groups are out of order (%x < %x)."),
350 attr
->group_tag
, group
);
354 group
= attr
->group_tag
;
359 * Then make sure that the first three attributes are:
362 * attributes-natural-language
363 * printer-uri/job-uri
366 attr
= con
->request
->attrs
;
367 if (attr
&& attr
->name
&&
368 !strcmp(attr
->name
, "attributes-charset") &&
369 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
377 if (attr
&& attr
->name
&&
378 !strcmp(attr
->name
, "attributes-natural-language") &&
379 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
384 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
385 IPP_TAG_URI
)) != NULL
)
387 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
388 IPP_TAG_URI
)) != NULL
)
390 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
391 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
397 "attributes-charset", NULL
,
398 charset
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
401 "attributes-charset", NULL
, "utf-8");
404 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
405 "attributes-natural-language", NULL
,
406 language
->values
[0].string
.text
);
408 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
409 "attributes-natural-language", NULL
, DefaultLanguage
);
412 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
413 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
416 * Bad character set...
419 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
420 charset
->values
[0].string
.text
);
421 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
422 "%04X %s Unsupported attributes-charset value \"%s\"",
423 IPP_CHARSET
, con
->http
.hostname
,
424 charset
->values
[0].string
.text
);
425 send_ipp_status(con
, IPP_BAD_REQUEST
,
426 _("Unsupported character set \"%s\"."),
427 charset
->values
[0].string
.text
);
429 else if (!charset
|| !language
||
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
432 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
433 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
434 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
435 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
438 * Return an error, since attributes-charset,
439 * attributes-natural-language, and printer-uri/job-uri are required
440 * for all operations.
445 cupsdLogMessage(CUPSD_LOG_ERROR
,
446 "Missing attributes-charset attribute");
448 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
449 "%04X %s Missing attributes-charset attribute",
450 IPP_BAD_REQUEST
, con
->http
.hostname
);
455 cupsdLogMessage(CUPSD_LOG_ERROR
,
456 "Missing attributes-natural-language attribute");
458 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
459 "%04X %s Missing attributes-natural-language attribute",
460 IPP_BAD_REQUEST
, con
->http
.hostname
);
465 cupsdLogMessage(CUPSD_LOG_ERROR
,
466 "Missing printer-uri, job-uri, or ppd-name "
469 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
470 "%04X %s Missing printer-uri, job-uri, or ppd-name "
471 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
476 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
478 "attr \"%s\": group_tag = %x, value_tag = %x",
479 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
482 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
484 send_ipp_status(con
, IPP_BAD_REQUEST
,
485 _("Missing required attributes."));
490 * OK, all the checks pass so far; make sure requesting-user-name is
491 * not "root" from a remote host...
494 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
495 IPP_TAG_NAME
)) != NULL
)
498 * Check for root user...
501 if (!strcmp(username
->values
[0].string
.text
, "root") &&
502 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
503 strcmp(con
->username
, "root"))
506 * Remote unauthenticated user masquerading as local root...
509 _cupsStrFree(username
->values
[0].string
.text
);
510 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
514 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
515 IPP_TAG_INTEGER
)) != NULL
)
516 sub_id
= attr
->values
[0].integer
;
521 * Then try processing the operation...
525 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
526 ippOpString(con
->request
->request
.op
.operation_id
),
527 uri
->values
[0].string
.text
);
529 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
530 ippOpString(con
->request
->request
.op
.operation_id
));
532 switch (con
->request
->request
.op
.operation_id
)
538 case IPP_VALIDATE_JOB
:
539 validate_job(con
, uri
);
542 case IPP_CREATE_JOB
:
543 create_job(con
, uri
);
546 case IPP_SEND_DOCUMENT
:
547 send_document(con
, uri
);
550 case IPP_CANCEL_JOB
:
551 cancel_job(con
, uri
);
554 case IPP_GET_JOB_ATTRIBUTES
:
555 get_job_attrs(con
, uri
);
562 case IPP_GET_PRINTER_ATTRIBUTES
:
563 get_printer_attrs(con
, uri
);
566 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
567 get_printer_supported(con
, uri
);
574 case IPP_RELEASE_JOB
:
575 release_job(con
, uri
);
578 case IPP_RESTART_JOB
:
579 restart_job(con
, uri
);
582 case IPP_PAUSE_PRINTER
:
583 stop_printer(con
, uri
);
586 case IPP_RESUME_PRINTER
:
587 start_printer(con
, uri
);
590 case IPP_PURGE_JOBS
:
591 case IPP_CANCEL_JOBS
:
592 case IPP_CANCEL_MY_JOBS
:
593 cancel_all_jobs(con
, uri
);
596 case IPP_SET_JOB_ATTRIBUTES
:
597 set_job_attrs(con
, uri
);
600 case IPP_SET_PRINTER_ATTRIBUTES
:
601 set_printer_attrs(con
, uri
);
604 case IPP_HOLD_NEW_JOBS
:
605 hold_new_jobs(con
, uri
);
608 case IPP_RELEASE_HELD_NEW_JOBS
:
609 release_held_new_jobs(con
, uri
);
616 case CUPS_GET_DEFAULT
:
620 case CUPS_GET_PRINTERS
:
621 get_printers(con
, 0);
624 case CUPS_GET_CLASSES
:
625 get_printers(con
, CUPS_PRINTER_CLASS
);
628 case CUPS_ADD_PRINTER
:
629 add_printer(con
, uri
);
632 case CUPS_DELETE_PRINTER
:
633 delete_printer(con
, uri
);
636 case CUPS_ADD_CLASS
:
640 case CUPS_DELETE_CLASS
:
641 delete_printer(con
, uri
);
644 case CUPS_ACCEPT_JOBS
:
645 case IPP_ENABLE_PRINTER
:
646 accept_jobs(con
, uri
);
649 case CUPS_REJECT_JOBS
:
650 case IPP_DISABLE_PRINTER
:
651 reject_jobs(con
, uri
);
654 case CUPS_SET_DEFAULT
:
655 set_default(con
, uri
);
658 case CUPS_GET_DEVICES
:
662 case CUPS_GET_DOCUMENT
:
663 get_document(con
, uri
);
678 case CUPS_AUTHENTICATE_JOB
:
679 authenticate_job(con
, uri
);
682 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
683 case IPP_CREATE_JOB_SUBSCRIPTION
:
684 create_subscription(con
, uri
);
687 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
688 get_subscription_attrs(con
, sub_id
);
691 case IPP_GET_SUBSCRIPTIONS
:
692 get_subscriptions(con
, uri
);
695 case IPP_RENEW_SUBSCRIPTION
:
696 renew_subscription(con
, sub_id
);
699 case IPP_CANCEL_SUBSCRIPTION
:
700 cancel_subscription(con
, sub_id
);
703 case IPP_GET_NOTIFICATIONS
:
704 get_notifications(con
);
708 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
709 "%04X %s Operation %04X (%s) not supported",
710 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
711 con
->request
->request
.op
.operation_id
,
712 ippOpString(con
->request
->request
.op
.operation_id
));
714 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
715 _("%s not supported."),
717 con
->request
->request
.op
.operation_id
));
727 * Sending data from the scheduler...
730 cupsdLogMessage(con
->response
->request
.status
.status_code
731 >= IPP_BAD_REQUEST
&&
732 con
->response
->request
.status
.status_code
733 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
734 "Returning IPP %s for %s (%s) from %s",
735 ippErrorString(con
->response
->request
.status
.status_code
),
736 ippOpString(con
->request
->request
.op
.operation_id
),
737 uri
? uri
->values
[0].string
.text
: "no URI",
740 if (LogLevel
== CUPSD_LOG_DEBUG2
)
741 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
742 "cupsdProcessIPPRequest: ippLength(response)=%ld",
743 (long)ippLength(con
->response
));
745 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
747 #ifdef CUPSD_USE_CHUNKING
749 * Because older versions of CUPS (1.1.17 and older) and some IPP
750 * clients do not implement chunking properly, we cannot use
751 * chunking by default. This may become the default in future
752 * CUPS releases, or we might add a configuration directive for
756 if (con
->http
.version
== HTTP_1_1
)
758 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
761 if (cupsdFlushHeader(con
) < 0)
764 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
767 #endif /* CUPSD_USE_CHUNKING */
769 size_t length
; /* Length of response */
772 length
= ippLength(con
->response
);
774 if (con
->file
>= 0 && !con
->pipe_pid
)
776 struct stat fileinfo
; /* File information */
779 if (!fstat(con
->file
, &fileinfo
))
780 length
+= fileinfo
.st_size
;
783 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
784 CUPS_LLCAST length
) < 0)
787 if (cupsdFlushHeader(con
) < 0)
790 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
791 con
->http
.data_remaining
= length
;
793 if (con
->http
.data_remaining
<= INT_MAX
)
794 con
->http
._data_remaining
= con
->http
.data_remaining
;
796 con
->http
._data_remaining
= INT_MAX
;
799 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
800 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
803 * Tell the caller the response header was sent successfully...
811 * Tell the caller the response header could not be sent...
820 * Sending data from a subprocess like cups-deviced; tell the caller
821 * everything is A-OK so far...
830 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
833 int /* O - 0 on success, -1 on error */
834 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
836 cupsd_printer_t
*printer
; /* Destination printer or class */
837 ipp_attribute_t
*attr
; /* job-sheets attribute */
838 int kbytes
; /* Kilobytes in banner */
841 job
->pending_timeout
= 0;
844 * See if we need to add the ending sheet...
847 if (!cupsdLoadJob(job
))
850 printer
= cupsdFindDest(job
->dest
);
851 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
854 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
855 attr
&& attr
->num_values
> 1)
861 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
862 attr
->values
[1].string
.text
);
864 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
867 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
875 * 'accept_jobs()' - Accept print jobs to a printer.
879 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
880 ipp_attribute_t
*uri
) /* I - Printer or class URI */
882 http_status_t status
; /* Policy status */
883 cups_ptype_t dtype
; /* Destination type (printer/class) */
884 cupsd_printer_t
*printer
; /* Printer data */
887 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
888 con
->http
.fd
, uri
->values
[0].string
.text
);
891 * Is the destination valid?
894 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
900 send_ipp_status(con
, IPP_NOT_FOUND
,
901 _("The printer or class does not exist."));
909 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
911 send_http_error(con
, status
, printer
);
916 * Accept jobs sent to the printer...
919 printer
->accepting
= 1;
920 printer
->state_message
[0] = '\0';
922 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
923 "Now accepting jobs.");
925 if (dtype
& CUPS_PRINTER_CLASS
)
927 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
929 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
930 printer
->name
, get_username(con
));
934 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
936 cupsdLogMessage(CUPSD_LOG_INFO
,
937 "Printer \"%s\" now accepting jobs (\"%s\").",
938 printer
->name
, get_username(con
));
942 * Everything was ok, so return OK status...
945 con
->response
->request
.status
.status_code
= IPP_OK
;
950 * 'add_class()' - Add a class to the system.
954 add_class(cupsd_client_t
*con
, /* I - Client connection */
955 ipp_attribute_t
*uri
) /* I - URI of class */
957 http_status_t status
; /* Policy status */
958 int i
; /* Looping var */
959 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
960 username
[HTTP_MAX_URI
], /* Username portion of URI */
961 host
[HTTP_MAX_URI
], /* Host portion of URI */
962 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
963 int port
; /* Port portion of URI */
964 cupsd_printer_t
*pclass
, /* Class */
965 *member
; /* Member printer/class */
966 cups_ptype_t dtype
; /* Destination type */
967 ipp_attribute_t
*attr
; /* Printer attribute */
968 int modify
; /* Non-zero if we just modified */
969 char newname
[IPP_MAX_NAME
]; /* New class name */
970 int need_restart_job
; /* Need to restart job? */
973 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
974 con
->http
.fd
, uri
->values
[0].string
.text
);
977 * Do we have a valid URI?
980 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
981 sizeof(scheme
), username
, sizeof(username
), host
,
982 sizeof(host
), &port
, resource
, sizeof(resource
));
985 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
988 * No, return an error...
991 send_ipp_status(con
, IPP_BAD_REQUEST
,
992 _("The printer-uri must be of the form "
993 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
998 * Do we have a valid printer name?
1001 if (!validate_name(resource
+ 9))
1004 * No, return an error...
1007 send_ipp_status(con
, IPP_BAD_REQUEST
,
1008 _("The printer-uri \"%s\" contains invalid characters."),
1009 uri
->values
[0].string
.text
);
1014 * See if the class already exists; if not, create a new class...
1017 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1020 * Class doesn't exist; see if we have a printer of the same name...
1023 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1024 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1027 * Yes, return an error...
1030 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1031 _("A printer named \"%s\" already exists."),
1037 * No, check the default policy and then add the class...
1040 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1042 send_http_error(con
, status
, NULL
);
1046 pclass
= cupsdAddClass(resource
+ 9);
1049 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1052 * Check the default policy, then rename the implicit class to "AnyClass"
1056 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1058 send_http_error(con
, status
, NULL
);
1062 if (ImplicitAnyClasses
)
1064 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1065 cupsdRenamePrinter(pclass
, newname
);
1068 cupsdDeletePrinter(pclass
, 1);
1071 * Add the class as a new local class...
1074 pclass
= cupsdAddClass(resource
+ 9);
1077 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1080 * Check the default policy, then rename the remote class to "Class"...
1083 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1085 send_http_error(con
, status
, NULL
);
1089 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1090 cupsdRenamePrinter(pclass
, newname
);
1093 * Add the class as a new local class...
1096 pclass
= cupsdAddClass(resource
+ 9);
1099 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1102 send_http_error(con
, status
, pclass
);
1109 * Look for attributes and copy them over as needed...
1112 need_restart_job
= 0;
1114 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1115 IPP_TAG_TEXT
)) != NULL
)
1116 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1118 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1119 IPP_TAG_TEXT
)) != NULL
)
1120 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1122 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1123 IPP_TAG_BOOLEAN
)) != NULL
&&
1124 attr
->values
[0].boolean
!= pclass
->accepting
)
1126 cupsdLogMessage(CUPSD_LOG_INFO
,
1127 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1128 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1130 pclass
->accepting
= attr
->values
[0].boolean
;
1132 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1133 pclass
->accepting
? "Now" : "No longer");
1136 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1137 IPP_TAG_BOOLEAN
)) != NULL
)
1139 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1140 cupsdDeregisterPrinter(pclass
, 1);
1142 cupsdLogMessage(CUPSD_LOG_INFO
,
1143 "Setting %s printer-is-shared to %d (was %d.)",
1144 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1146 pclass
->shared
= attr
->values
[0].boolean
;
1149 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1150 IPP_TAG_ENUM
)) != NULL
)
1152 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1153 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1155 send_ipp_status(con
, IPP_BAD_REQUEST
,
1156 _("Attempt to set %s printer-state to bad value %d."),
1157 pclass
->name
, attr
->values
[0].integer
);
1161 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1162 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1164 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1165 cupsdStopPrinter(pclass
, 0);
1168 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1169 need_restart_job
= 1;
1172 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1173 IPP_TAG_TEXT
)) != NULL
)
1175 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1176 sizeof(pclass
->state_message
));
1178 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1179 pclass
->state_message
);
1181 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1182 IPP_TAG_URI
)) != NULL
)
1185 * Clear the printer array as needed...
1188 need_restart_job
= 1;
1190 if (pclass
->num_printers
> 0)
1192 free(pclass
->printers
);
1193 pclass
->num_printers
= 0;
1197 * Add each printer or class that is listed...
1200 for (i
= 0; i
< attr
->num_values
; i
++)
1203 * Search for the printer or class URI...
1206 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1212 send_ipp_status(con
, IPP_NOT_FOUND
,
1213 _("The printer or class does not exist."));
1216 else if (dtype
& CUPS_PRINTER_CLASS
)
1218 send_ipp_status(con
, IPP_BAD_REQUEST
,
1219 _("Nested classes are not allowed."));
1224 * Add it to the class...
1227 cupsdAddPrinterToClass(pclass
, member
);
1231 set_printer_defaults(con
, pclass
);
1233 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1234 IPP_TAG_KEYWORD
)) != NULL
)
1235 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1238 * Update the printer class attributes and return...
1241 cupsdSetPrinterAttrs(pclass
);
1242 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1244 if (need_restart_job
&& pclass
->job
)
1247 * Reset the current job to a "pending" status...
1250 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1251 "Job restarted because the class was modified.");
1254 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1258 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1259 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1260 pclass
->name
, get_username(con
));
1262 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1263 pclass
->name
, get_username(con
));
1267 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1268 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1269 pclass
->name
, get_username(con
));
1271 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1272 pclass
->name
, get_username(con
));
1275 con
->response
->request
.status
.status_code
= IPP_OK
;
1280 * 'add_file()' - Add a file to a job.
1283 static int /* O - 0 on success, -1 on error */
1284 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1285 cupsd_job_t
*job
, /* I - Job to add to */
1286 mime_type_t
*filetype
, /* I - Type of file */
1287 int compression
) /* I - Compression */
1289 mime_type_t
**filetypes
; /* New filetypes array... */
1290 int *compressions
; /* New compressions array... */
1293 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1294 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1295 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1296 filetype
->super
, filetype
->type
, compression
);
1299 * Add the file to the job...
1302 if (job
->num_files
== 0)
1304 compressions
= (int *)malloc(sizeof(int));
1305 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1309 compressions
= (int *)realloc(job
->compressions
,
1310 (job
->num_files
+ 1) * sizeof(int));
1311 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1312 (job
->num_files
+ 1) *
1313 sizeof(mime_type_t
*));
1316 if (!compressions
|| !filetypes
)
1318 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1319 "Job aborted because the scheduler ran out of memory.");
1322 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1323 _("Unable to allocate memory for file types."));
1328 job
->compressions
= compressions
;
1329 job
->compressions
[job
->num_files
] = compression
;
1330 job
->filetypes
= filetypes
;
1331 job
->filetypes
[job
->num_files
] = filetype
;
1336 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1343 * 'add_job()' - Add a job to a print queue.
1346 static cupsd_job_t
* /* O - Job object */
1347 add_job(cupsd_client_t
*con
, /* I - Client connection */
1348 cupsd_printer_t
*printer
, /* I - Destination printer */
1349 mime_type_t
*filetype
) /* I - First print file type, if any */
1351 http_status_t status
; /* Policy status */
1352 ipp_attribute_t
*attr
, /* Current attribute */
1353 *auth_info
; /* auth-info attribute */
1354 const char *val
; /* Default option value */
1355 int priority
; /* Job priority */
1356 cupsd_job_t
*job
; /* Current job */
1357 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1358 int kbytes
; /* Size of print file */
1359 int i
; /* Looping var */
1360 int lowerpagerange
; /* Page range bound */
1361 int exact
; /* Did we have an exact match? */
1362 ipp_attribute_t
*media_col
, /* media-col attribute */
1363 *media_margin
; /* media-*-margin attribute */
1364 ipp_t
*unsup_col
; /* media-col in unsupported response */
1367 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1368 con
, con
->http
.fd
, printer
, printer
->name
,
1369 filetype
, filetype
? filetype
->super
: "none",
1370 filetype
? filetype
->type
: "none");
1373 * Check remote printing to non-shared printer...
1376 if (!printer
->shared
&&
1377 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1378 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1380 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1381 _("The printer or class is not shared."));
1389 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1391 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1393 send_http_error(con
, status
, printer
);
1396 else if (printer
->num_auth_info_required
== 1 &&
1397 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1400 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1404 else if (auth_info
&& !con
->http
.tls
&&
1405 !httpAddrLocalhost(con
->http
.hostaddr
))
1408 * Require encryption of auth-info over non-local connections...
1411 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1414 #endif /* HAVE_SSL */
1417 * See if the printer is accepting jobs...
1420 if (!printer
->accepting
)
1422 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1423 _("Destination \"%s\" is not accepting jobs."),
1429 * Validate job template attributes; for now just document-format,
1430 * copies, number-up, and page-ranges...
1433 if (filetype
&& printer
->filetypes
&&
1434 !cupsArrayFind(printer
->filetypes
, filetype
))
1436 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1437 /* MIME media type string */
1440 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1443 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1444 _("Unsupported format \"%s\"."), mimetype
);
1446 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1447 "document-format", NULL
, mimetype
);
1452 if ((attr
= ippFindAttribute(con
->request
, "copies",
1453 IPP_TAG_INTEGER
)) != NULL
)
1455 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1457 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1458 attr
->values
[0].integer
);
1459 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1460 "copies", attr
->values
[0].integer
);
1465 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1466 IPP_TAG_ZERO
)) != NULL
)
1468 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1469 attr
->value_tag
!= IPP_TAG_NAME
)
1471 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1475 if (attr
->num_values
> 2)
1477 send_ipp_status(con
, IPP_BAD_REQUEST
,
1478 _("Too many job-sheets values (%d > 2)."),
1483 for (i
= 0; i
< attr
->num_values
; i
++)
1484 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1485 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1487 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1488 attr
->values
[i
].string
.text
);
1493 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1494 IPP_TAG_INTEGER
)) != NULL
)
1496 if (attr
->values
[0].integer
!= 1 &&
1497 attr
->values
[0].integer
!= 2 &&
1498 attr
->values
[0].integer
!= 4 &&
1499 attr
->values
[0].integer
!= 6 &&
1500 attr
->values
[0].integer
!= 9 &&
1501 attr
->values
[0].integer
!= 16)
1503 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1504 attr
->values
[0].integer
);
1505 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1506 "number-up", attr
->values
[0].integer
);
1511 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1512 IPP_TAG_RANGE
)) != NULL
)
1514 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1516 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1517 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1519 send_ipp_status(con
, IPP_BAD_REQUEST
,
1520 _("Bad page-ranges values %d-%d."),
1521 attr
->values
[i
].range
.lower
,
1522 attr
->values
[i
].range
.upper
);
1526 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1531 * Do media selection as needed...
1534 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1535 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1536 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1539 (media_col
= ippFindAttribute(con
->request
, "media-col",
1540 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1542 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1544 unsup_col
= ippNew();
1545 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1546 "media-bottom-margin",
1547 IPP_TAG_INTEGER
)) != NULL
)
1548 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1549 "media-bottom-margin", media_margin
->values
[0].integer
);
1551 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1552 "media-left-margin",
1553 IPP_TAG_INTEGER
)) != NULL
)
1554 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1555 "media-left-margin", media_margin
->values
[0].integer
);
1557 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1558 "media-right-margin",
1559 IPP_TAG_INTEGER
)) != NULL
)
1560 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1561 "media-right-margin", media_margin
->values
[0].integer
);
1563 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 IPP_TAG_INTEGER
)) != NULL
)
1566 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1567 "media-top-margin", media_margin
->values
[0].integer
);
1569 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1571 ippDelete(unsup_col
);
1576 * Make sure we aren't over our limit...
1579 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1582 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1584 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1588 if ((i
= check_quotas(con
, printer
)) < 0)
1590 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1595 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1600 * Create the job and set things up...
1603 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1604 IPP_TAG_INTEGER
)) != NULL
)
1605 priority
= attr
->values
[0].integer
;
1608 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1609 printer
->options
)) != NULL
)
1610 priority
= atoi(val
);
1614 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1618 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1619 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1622 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1624 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1625 _("Unable to add job for destination \"%s\"."),
1630 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1631 CUPS_PRINTER_REMOTE
);
1632 job
->attrs
= con
->request
;
1634 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1636 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1639 apply_printer_defaults(printer
, job
);
1641 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1643 if (con
->username
[0])
1645 cupsdSetString(&job
->username
, con
->username
);
1648 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1652 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1653 "add_job: requesting-user-name=\"%s\"",
1654 attr
->values
[0].string
.text
);
1656 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1659 cupsdSetString(&job
->username
, "anonymous");
1662 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1663 "job-originating-user-name", NULL
, job
->username
);
1666 attr
->group_tag
= IPP_TAG_JOB
;
1667 _cupsStrFree(attr
->name
);
1668 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1671 if (con
->username
[0] || auth_info
)
1673 save_auth_info(con
, job
, auth_info
);
1676 * Remove the auth-info attribute from the attribute data...
1680 ippDeleteAttribute(job
->attrs
, auth_info
);
1683 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1684 IPP_TAG_ZERO
)) != NULL
)
1687 * Request contains a job-originating-host-name attribute; validate it...
1690 if (attr
->value_tag
!= IPP_TAG_NAME
||
1691 attr
->num_values
!= 1 ||
1692 strcmp(con
->http
.hostname
, "localhost"))
1695 * Can't override the value if we aren't connected via localhost.
1696 * Also, we can only have 1 value and it must be a name value.
1699 switch (attr
->value_tag
)
1701 case IPP_TAG_STRING
:
1702 case IPP_TAG_TEXTLANG
:
1703 case IPP_TAG_NAMELANG
:
1706 case IPP_TAG_KEYWORD
:
1708 case IPP_TAG_URISCHEME
:
1709 case IPP_TAG_CHARSET
:
1710 case IPP_TAG_LANGUAGE
:
1711 case IPP_TAG_MIMETYPE
:
1713 * Free old strings...
1716 for (i
= 0; i
< attr
->num_values
; i
++)
1718 _cupsStrFree(attr
->values
[i
].string
.text
);
1719 attr
->values
[i
].string
.text
= NULL
;
1720 if (attr
->values
[i
].string
.charset
)
1722 _cupsStrFree(attr
->values
[i
].string
.charset
);
1723 attr
->values
[i
].string
.charset
= NULL
;
1732 * Use the default connection hostname instead...
1735 attr
->value_tag
= IPP_TAG_NAME
;
1736 attr
->num_values
= 1;
1737 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1740 attr
->group_tag
= IPP_TAG_JOB
;
1745 * No job-originating-host-name attribute, so use the hostname from
1749 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1750 "job-originating-host-name", NULL
, con
->http
.hostname
);
1753 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1755 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1756 "time-at-processing", 0);
1757 attr
->value_tag
= IPP_TAG_NOVALUE
;
1758 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1759 "time-at-completed", 0);
1760 attr
->value_tag
= IPP_TAG_NOVALUE
;
1763 * Add remaining job attributes...
1766 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1767 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1768 "job-state", IPP_JOB_STOPPED
);
1769 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1770 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1771 "job-media-sheets-completed", 0);
1772 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1775 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1776 IPP_TAG_INTEGER
)) != NULL
)
1777 attr
->values
[0].integer
= 0;
1779 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1781 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1782 IPP_TAG_KEYWORD
)) == NULL
)
1783 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1786 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1787 printer
->options
)) == NULL
)
1790 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1791 "job-hold-until", NULL
, val
);
1793 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1796 * Hold job until specified time...
1799 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1801 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1802 job
->state_value
= IPP_JOB_HELD
;
1804 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1806 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1807 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1808 job
->state_value
= IPP_JOB_HELD
;
1812 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1813 job
->state_value
= IPP_JOB_PENDING
;
1816 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1820 * Add job sheets options...
1823 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1824 IPP_TAG_ZERO
)) == NULL
)
1826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1827 "Adding default job-sheets values \"%s,%s\"...",
1828 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1830 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1832 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1833 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1836 job
->job_sheets
= attr
;
1839 * Enforce classification level if set...
1844 cupsdLogMessage(CUPSD_LOG_INFO
,
1845 "Classification=\"%s\", ClassifyOverride=%d",
1846 Classification
? Classification
: "(null)",
1849 if (ClassifyOverride
)
1851 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1852 (attr
->num_values
== 1 ||
1853 !strcmp(attr
->values
[1].string
.text
, "none")))
1856 * Force the leading banner to have the classification on it...
1859 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1861 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1862 "job-sheets=\"%s,none\", "
1863 "job-originating-user-name=\"%s\"",
1864 Classification
, job
->username
);
1866 else if (attr
->num_values
== 2 &&
1867 strcmp(attr
->values
[0].string
.text
,
1868 attr
->values
[1].string
.text
) &&
1869 strcmp(attr
->values
[0].string
.text
, "none") &&
1870 strcmp(attr
->values
[1].string
.text
, "none"))
1873 * Can't put two different security markings on the same document!
1876 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1878 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1879 "job-sheets=\"%s,%s\", "
1880 "job-originating-user-name=\"%s\"",
1881 attr
->values
[0].string
.text
,
1882 attr
->values
[1].string
.text
, job
->username
);
1884 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1885 strcmp(attr
->values
[0].string
.text
, "none") &&
1886 (attr
->num_values
== 1 ||
1887 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1888 strcmp(attr
->values
[1].string
.text
, "none"))))
1890 if (attr
->num_values
== 1)
1891 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1892 "CLASSIFICATION OVERRIDDEN "
1893 "job-sheets=\"%s\", "
1894 "job-originating-user-name=\"%s\"",
1895 attr
->values
[0].string
.text
, job
->username
);
1897 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1898 "CLASSIFICATION OVERRIDDEN "
1899 "job-sheets=\"%s,%s\",fffff "
1900 "job-originating-user-name=\"%s\"",
1901 attr
->values
[0].string
.text
,
1902 attr
->values
[1].string
.text
, job
->username
);
1905 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1906 (attr
->num_values
== 1 ||
1907 strcmp(attr
->values
[1].string
.text
, Classification
)))
1910 * Force the banner to have the classification on it...
1913 if (attr
->num_values
> 1 &&
1914 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1916 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1917 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1921 if (attr
->num_values
== 1 ||
1922 strcmp(attr
->values
[0].string
.text
, "none"))
1923 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1925 if (attr
->num_values
> 1 &&
1926 strcmp(attr
->values
[1].string
.text
, "none"))
1927 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1930 if (attr
->num_values
> 1)
1931 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1932 "CLASSIFICATION FORCED "
1933 "job-sheets=\"%s,%s\", "
1934 "job-originating-user-name=\"%s\"",
1935 attr
->values
[0].string
.text
,
1936 attr
->values
[1].string
.text
, job
->username
);
1938 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1939 "CLASSIFICATION FORCED "
1940 "job-sheets=\"%s\", "
1941 "job-originating-user-name=\"%s\"",
1942 Classification
, job
->username
);
1947 * See if we need to add the starting sheet...
1950 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1952 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1953 attr
->values
[0].string
.text
);
1955 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1957 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1958 "Aborting job because the start banner could not be "
1963 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1966 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1967 IPP_TAG_ZERO
)) != NULL
)
1968 job
->job_sheets
= attr
;
1971 * Fill in the response info...
1974 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1975 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1976 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1979 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1981 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1983 add_job_state_reasons(con
, job
);
1985 con
->response
->request
.status
.status_code
= IPP_OK
;
1988 * Add any job subscriptions...
1991 add_job_subscriptions(con
, job
);
1994 * Set all but the first two attributes to the job attributes group...
1997 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1998 attr
->group_tag
= IPP_TAG_JOB
;
2001 * Fire the "job created" event...
2004 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2007 * Return the new job...
2015 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2016 * upon the job and printer state...
2020 add_job_state_reasons(
2021 cupsd_client_t
*con
, /* I - Client connection */
2022 cupsd_job_t
*job
) /* I - Job info */
2024 cupsd_printer_t
*dest
; /* Destination printer */
2027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2028 con
, con
->http
.fd
, job
? job
->id
: 0);
2030 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2032 case IPP_JOB_PENDING
:
2033 dest
= cupsdFindDest(job
->dest
);
2035 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2036 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2037 "job-state-reasons", NULL
, "printer-stopped");
2039 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2040 "job-state-reasons", NULL
, "none");
2044 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2045 IPP_TAG_KEYWORD
) != NULL
||
2046 ippFindAttribute(job
->attrs
, "job-hold-until",
2047 IPP_TAG_NAME
) != NULL
)
2048 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2049 "job-state-reasons", NULL
, "job-hold-until-specified");
2051 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2052 "job-state-reasons", NULL
, "job-incoming");
2055 case IPP_JOB_PROCESSING
:
2056 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2057 "job-state-reasons", NULL
, "job-printing");
2060 case IPP_JOB_STOPPED
:
2061 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2062 "job-state-reasons", NULL
, "job-stopped");
2065 case IPP_JOB_CANCELED
:
2066 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2067 "job-state-reasons", NULL
, "job-canceled-by-user");
2070 case IPP_JOB_ABORTED
:
2071 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2072 "job-state-reasons", NULL
, "aborted-by-system");
2075 case IPP_JOB_COMPLETED
:
2076 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2077 "job-state-reasons", NULL
, "job-completed-successfully");
2084 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2088 add_job_subscriptions(
2089 cupsd_client_t
*con
, /* I - Client connection */
2090 cupsd_job_t
*job
) /* I - Newly created job */
2092 int i
; /* Looping var */
2093 ipp_attribute_t
*prev
, /* Previous attribute */
2094 *next
, /* Next attribute */
2095 *attr
; /* Current attribute */
2096 cupsd_subscription_t
*sub
; /* Subscription object */
2097 const char *recipient
, /* notify-recipient-uri */
2098 *pullmethod
; /* notify-pull-method */
2099 ipp_attribute_t
*user_data
; /* notify-user-data */
2100 int interval
; /* notify-time-interval */
2101 unsigned mask
; /* notify-events */
2105 * Find the first subscription group attribute; return if we have
2109 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2110 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2117 * Process the subscription attributes in the request...
2126 mask
= CUPSD_EVENT_NONE
;
2128 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2130 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2131 attr
->value_tag
== IPP_TAG_URI
)
2134 * Validate the recipient scheme against the ServerBin/notifier
2138 char notifier
[1024], /* Notifier filename */
2139 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2140 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2141 host
[HTTP_MAX_URI
], /* Host portion of URI */
2142 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2143 int port
; /* Port portion of URI */
2146 recipient
= attr
->values
[0].string
.text
;
2148 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2149 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2150 host
, sizeof(host
), &port
,
2151 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2153 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2154 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2155 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2156 "notify-status-code", IPP_URI_SCHEME
);
2160 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2162 if (access(notifier
, X_OK
))
2164 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2165 _("notify-recipient-uri URI \"%s\" uses unknown "
2166 "scheme."), recipient
);
2167 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2168 "notify-status-code", IPP_URI_SCHEME
);
2172 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2174 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2175 _("notify-recipient-uri URI \"%s\" is already used."),
2177 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2178 "notify-status-code", IPP_ATTRIBUTES
);
2182 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2183 attr
->value_tag
== IPP_TAG_KEYWORD
)
2185 pullmethod
= attr
->values
[0].string
.text
;
2187 if (strcmp(pullmethod
, "ippget"))
2189 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2190 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2191 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2192 "notify-status-code", IPP_ATTRIBUTES
);
2196 else if (!strcmp(attr
->name
, "notify-charset") &&
2197 attr
->value_tag
== IPP_TAG_CHARSET
&&
2198 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2199 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2201 send_ipp_status(con
, IPP_CHARSET
,
2202 _("Character set \"%s\" not supported."),
2203 attr
->values
[0].string
.text
);
2206 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2207 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2208 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2210 send_ipp_status(con
, IPP_CHARSET
,
2211 _("Language \"%s\" not supported."),
2212 attr
->values
[0].string
.text
);
2215 else if (!strcmp(attr
->name
, "notify-user-data") &&
2216 attr
->value_tag
== IPP_TAG_STRING
)
2218 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2220 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2221 _("The notify-user-data value is too large "
2222 "(%d > 63 octets)."),
2223 attr
->values
[0].unknown
.length
);
2229 else if (!strcmp(attr
->name
, "notify-events") &&
2230 attr
->value_tag
== IPP_TAG_KEYWORD
)
2232 for (i
= 0; i
< attr
->num_values
; i
++)
2233 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2235 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2237 send_ipp_status(con
, IPP_BAD_REQUEST
,
2238 _("The notify-lease-duration attribute cannot be "
2239 "used with job subscriptions."));
2242 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2243 attr
->value_tag
== IPP_TAG_INTEGER
)
2244 interval
= attr
->values
[0].integer
;
2249 if (!recipient
&& !pullmethod
)
2252 if (mask
== CUPSD_EVENT_NONE
)
2253 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2255 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2256 recipient
, 0)) != NULL
)
2258 sub
->interval
= interval
;
2260 cupsdSetString(&sub
->owner
, job
->username
);
2264 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2265 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2266 sub
->user_data_len
);
2269 ippAddSeparator(con
->response
);
2270 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2271 "notify-subscription-id", sub
->id
);
2273 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2281 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2284 * Remove all of the subscription attributes from the job request...
2286 * TODO: Optimize this since subscription groups have to come at the
2287 * end of the request...
2290 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2294 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2295 attr
->group_tag
== IPP_TAG_ZERO
)
2298 * Free and remove this attribute...
2306 job
->attrs
->attrs
= next
;
2312 job
->attrs
->last
= prev
;
2313 job
->attrs
->current
= prev
;
2318 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2320 * See RFC 4122 for the definition of UUIDs and the format.
2324 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2326 char uuid
[64]; /* job-uuid string */
2330 * Add a job-uuid attribute if none exists...
2333 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2334 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2335 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2336 uuid
, sizeof(uuid
)));
2341 * 'add_printer()' - Add a printer to the system.
2345 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2346 ipp_attribute_t
*uri
) /* I - URI of printer */
2348 http_status_t status
; /* Policy status */
2349 int i
; /* Looping var */
2350 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2351 username
[HTTP_MAX_URI
], /* Username portion of URI */
2352 host
[HTTP_MAX_URI
], /* Host portion of URI */
2353 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2354 int port
; /* Port portion of URI */
2355 cupsd_printer_t
*printer
; /* Printer/class */
2356 ipp_attribute_t
*attr
; /* Printer attribute */
2357 cups_file_t
*fp
; /* Script/PPD file */
2358 char line
[1024]; /* Line from file... */
2359 char srcfile
[1024], /* Source Script/PPD file */
2360 dstfile
[1024]; /* Destination Script/PPD file */
2361 int modify
; /* Non-zero if we are modifying */
2362 char newname
[IPP_MAX_NAME
]; /* New printer name */
2363 int changed_driver
, /* Changed the PPD/interface script? */
2364 need_restart_job
, /* Need to restart job? */
2365 set_device_uri
, /* Did we set the device URI? */
2366 set_port_monitor
; /* Did we set the port monitor? */
2369 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2370 con
->http
.fd
, uri
->values
[0].string
.text
);
2373 * Do we have a valid URI?
2376 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2377 sizeof(scheme
), username
, sizeof(username
), host
,
2378 sizeof(host
), &port
, resource
, sizeof(resource
));
2380 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2383 * No, return an error...
2386 send_ipp_status(con
, IPP_BAD_REQUEST
,
2387 _("The printer-uri must be of the form "
2388 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2393 * Do we have a valid printer name?
2396 if (!validate_name(resource
+ 10))
2399 * No, return an error...
2402 send_ipp_status(con
, IPP_BAD_REQUEST
,
2403 _("The printer-uri \"%s\" contains invalid characters."),
2404 uri
->values
[0].string
.text
);
2409 * See if the printer already exists; if not, create a new printer...
2412 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2415 * Printer doesn't exist; see if we have a class of the same name...
2418 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2419 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2422 * Yes, return an error...
2425 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2426 _("A class named \"%s\" already exists."),
2432 * No, check the default policy then add the printer...
2435 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2437 send_http_error(con
, status
, NULL
);
2441 printer
= cupsdAddPrinter(resource
+ 10);
2444 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2447 * Check the default policy, then rename the implicit printer to
2448 * "AnyPrinter" or delete it...
2451 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2453 send_http_error(con
, status
, NULL
);
2457 if (ImplicitAnyClasses
)
2459 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2460 cupsdRenamePrinter(printer
, newname
);
2463 cupsdDeletePrinter(printer
, 1);
2466 * Add the printer as a new local printer...
2469 printer
= cupsdAddPrinter(resource
+ 10);
2472 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2475 * Check the default policy, then rename the remote printer to
2476 * "Printer@server"...
2479 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2481 send_http_error(con
, status
, NULL
);
2485 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2487 cupsdRenamePrinter(printer
, newname
);
2490 * Add the printer as a new local printer...
2493 printer
= cupsdAddPrinter(resource
+ 10);
2496 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2499 send_http_error(con
, status
, printer
);
2506 * Look for attributes and copy them over as needed...
2510 need_restart_job
= 0;
2512 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2513 IPP_TAG_TEXT
)) != NULL
)
2514 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2516 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2517 IPP_TAG_TEXT
)) != NULL
)
2518 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2522 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2523 IPP_TAG_URI
)) != NULL
)
2526 * Do we have a valid device URI?
2529 http_uri_status_t uri_status
; /* URI separation status */
2530 char old_device_uri
[1024];
2531 /* Old device URI */
2534 need_restart_job
= 1;
2536 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2537 attr
->values
[0].string
.text
,
2538 scheme
, sizeof(scheme
),
2539 username
, sizeof(username
),
2540 host
, sizeof(host
), &port
,
2541 resource
, sizeof(resource
));
2543 if (uri_status
< HTTP_URI_OK
)
2545 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2546 attr
->values
[0].string
.text
);
2547 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2548 "add_printer: httpSeparateURI returned %d", uri_status
);
2552 if (!strcmp(scheme
, "file"))
2555 * See if the administrator has enabled file devices...
2558 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2561 * File devices are disabled and the URL is not file:/dev/null...
2564 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2565 _("File device URIs have been disabled. "
2566 "To enable, see the FileDevice directive in "
2567 "\"%s/cupsd.conf\"."),
2575 * See if the backend exists and is executable...
2578 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2579 if (access(srcfile
, X_OK
))
2582 * Could not find device in list!
2585 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2586 _("Bad device-uri scheme \"%s\"."), scheme
);
2591 if (printer
->sanitized_device_uri
)
2592 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2593 sizeof(old_device_uri
));
2595 old_device_uri
[0] = '\0';
2597 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2599 cupsdLogMessage(CUPSD_LOG_INFO
,
2600 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2601 printer
->name
, printer
->sanitized_device_uri
,
2607 set_port_monitor
= 0;
2609 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2610 IPP_TAG_NAME
)) != NULL
)
2612 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2615 need_restart_job
= 1;
2617 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2621 for (i
= 0; i
< supported
->num_values
; i
++)
2622 if (!strcmp(supported
->values
[i
].string
.text
,
2623 attr
->values
[0].string
.text
))
2627 if (!supported
|| i
>= supported
->num_values
)
2629 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2630 attr
->values
[0].string
.text
);
2634 cupsdLogMessage(CUPSD_LOG_INFO
,
2635 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2636 printer
->name
, attr
->values
[0].string
.text
,
2637 printer
->port_monitor
? printer
->port_monitor
: "none");
2639 if (strcmp(attr
->values
[0].string
.text
, "none"))
2640 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2642 cupsdClearString(&printer
->port_monitor
);
2644 set_port_monitor
= 1;
2647 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2648 IPP_TAG_BOOLEAN
)) != NULL
&&
2649 attr
->values
[0].boolean
!= printer
->accepting
)
2651 cupsdLogMessage(CUPSD_LOG_INFO
,
2652 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2653 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2655 printer
->accepting
= attr
->values
[0].boolean
;
2657 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2658 "%s accepting jobs.",
2659 printer
->accepting
? "Now" : "No longer");
2662 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2663 IPP_TAG_BOOLEAN
)) != NULL
)
2665 if (attr
->values
[0].boolean
&&
2666 printer
->num_auth_info_required
== 1 &&
2667 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2669 send_ipp_status(con
, IPP_BAD_REQUEST
,
2670 _("Cannot share a remote Kerberized printer."));
2674 if (printer
->shared
&& !attr
->values
[0].boolean
)
2675 cupsdDeregisterPrinter(printer
, 1);
2677 cupsdLogMessage(CUPSD_LOG_INFO
,
2678 "Setting %s printer-is-shared to %d (was %d.)",
2679 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2681 printer
->shared
= attr
->values
[0].boolean
;
2684 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2685 IPP_TAG_ENUM
)) != NULL
)
2687 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2688 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2690 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2691 attr
->values
[0].integer
);
2695 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2696 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2698 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2699 cupsdStopPrinter(printer
, 0);
2702 need_restart_job
= 1;
2703 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2707 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2708 IPP_TAG_TEXT
)) != NULL
)
2710 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2711 sizeof(printer
->state_message
));
2713 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2714 printer
->state_message
);
2717 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2718 IPP_TAG_KEYWORD
)) != NULL
)
2720 if (attr
->num_values
>
2721 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2723 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2724 _("Too many printer-state-reasons values (%d > %d)."),
2726 (int)(sizeof(printer
->reasons
) /
2727 sizeof(printer
->reasons
[0])));
2731 for (i
= 0; i
< printer
->num_reasons
; i
++)
2732 _cupsStrFree(printer
->reasons
[i
]);
2734 printer
->num_reasons
= 0;
2735 for (i
= 0; i
< attr
->num_values
; i
++)
2737 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2740 printer
->reasons
[printer
->num_reasons
] =
2741 _cupsStrRetain(attr
->values
[i
].string
.text
);
2742 printer
->num_reasons
++;
2744 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2745 printer
->state
!= IPP_PRINTER_STOPPED
)
2747 cupsdLogMessage(CUPSD_LOG_INFO
,
2748 "Setting %s printer-state to %d (was %d.)",
2749 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2750 cupsdStopPrinter(printer
, 0);
2754 if (PrintcapFormat
== PRINTCAP_PLIST
)
2755 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2757 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2758 "Printer \"%s\" state changed.", printer
->name
);
2761 set_printer_defaults(con
, printer
);
2763 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2764 IPP_TAG_KEYWORD
)) != NULL
)
2765 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2768 * See if we have all required attributes...
2771 if (!printer
->device_uri
)
2772 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2775 * See if we have an interface script or PPD file attached to the request...
2780 need_restart_job
= 1;
2783 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2785 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2788 * Yes; get the first line from it...
2792 cupsFileGets(fp
, line
, sizeof(line
));
2796 * Then see what kind of file it is...
2799 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2802 if (!strncmp(line
, "*PPD-Adobe", 10))
2805 * The new file is a PPD file, so remove any old interface script
2806 * that might be lying around...
2814 * This must be an interface script, so move the file over to the
2815 * interfaces directory and make it executable...
2818 if (copy_file(srcfile
, dstfile
))
2820 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2821 _("Unable to copy interface script - %s"),
2826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2827 "Copied interface script successfully");
2828 chmod(dstfile
, 0755);
2831 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2834 if (!strncmp(line
, "*PPD-Adobe", 10))
2837 * The new file is a PPD file, so move the file over to the
2838 * ppd directory and make it readable by all...
2841 if (copy_file(srcfile
, dstfile
))
2843 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2844 _("Unable to copy PPD file - %s"),
2849 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2850 "Copied PPD file successfully");
2851 chmod(dstfile
, 0644);
2856 * This must be an interface script, so remove any old PPD file that
2857 * may be lying around...
2864 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2865 IPP_TAG_NAME
)) != NULL
)
2867 need_restart_job
= 1;
2870 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2873 * Raw driver, remove any existing PPD or interface script files.
2876 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2880 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2890 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2894 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2897 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2899 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2903 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2904 "Copied PPD file successfully");
2905 chmod(dstfile
, 0644);
2912 * If we changed the PPD/interface script, then remove the printer's cache
2913 * file and clear the printer-state-reasons...
2916 char cache_name
[1024]; /* Cache filename for printer attrs */
2918 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2922 cupsdSetPrinterReasons(printer
, "none");
2926 * (Re)register color profiles...
2931 apple_unregister_profiles(printer
);
2932 apple_register_profiles(printer
);
2934 #endif /* __APPLE__ */
2938 * If we set the device URI but not the port monitor, check which port
2939 * monitor to use by default...
2942 if (set_device_uri
&& !set_port_monitor
)
2944 ppd_file_t
*ppd
; /* PPD file */
2945 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2948 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2949 sizeof(scheme
), username
, sizeof(username
), host
,
2950 sizeof(host
), &port
, resource
, sizeof(resource
));
2952 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2954 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2956 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2958 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2959 if (!strcmp(scheme
, ppdattr
->spec
))
2961 cupsdLogMessage(CUPSD_LOG_INFO
,
2962 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2963 printer
->name
, ppdattr
->value
,
2964 printer
->port_monitor
? printer
->port_monitor
2967 if (strcmp(ppdattr
->value
, "none"))
2968 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2970 cupsdClearString(&printer
->port_monitor
);
2980 * Update the printer attributes and return...
2983 cupsdSetPrinterAttrs(printer
);
2984 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2986 if (need_restart_job
&& printer
->job
)
2989 * Restart the current job...
2992 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2993 "Job restarted because the printer was modified.");
2996 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3000 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3001 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3002 printer
->name
, get_username(con
));
3004 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3005 printer
->name
, get_username(con
));
3009 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3010 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3011 printer
->name
, get_username(con
));
3013 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3014 printer
->name
, get_username(con
));
3017 con
->response
->request
.status
.status_code
= IPP_OK
;
3022 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3023 * based upon the printer state...
3027 add_printer_state_reasons(
3028 cupsd_client_t
*con
, /* I - Client connection */
3029 cupsd_printer_t
*p
) /* I - Printer info */
3031 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3032 "add_printer_state_reasons(%p[%d], %p[%s])",
3033 con
, con
->http
.fd
, p
, p
->name
);
3035 if (p
->num_reasons
== 0)
3036 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3037 "printer-state-reasons", NULL
, "none");
3039 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3040 "printer-state-reasons", p
->num_reasons
, NULL
,
3041 (const char * const *)p
->reasons
);
3046 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3047 * the specified printer or class.
3051 add_queued_job_count(
3052 cupsd_client_t
*con
, /* I - Client connection */
3053 cupsd_printer_t
*p
) /* I - Printer or class */
3055 int count
; /* Number of jobs on destination */
3058 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3059 con
, con
->http
.fd
, p
, p
->name
);
3061 count
= cupsdGetPrinterJobCount(p
->name
);
3063 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3064 "queued-job-count", count
);
3070 * 'apple_init_profile()' - Initialize a color profile.
3075 ppd_file_t
*ppd
, /* I - PPD file */
3076 cups_array_t
*languages
, /* I - Languages in the PPD file */
3077 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3078 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3080 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3081 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3082 unsigned id
, /* I - Profile ID */
3083 const char *name
, /* I - Profile name */
3084 const char *text
, /* I - Profile UI text */
3085 const char *iccfile
) /* I - ICC filename */
3087 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3088 CFURLRef url
; /* URL for profile filename */
3089 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3090 CFMutableDictionaryRef dict
; /* Dictionary for name */
3091 char *language
; /* Current language */
3092 ppd_attr_t
*attr
; /* Profile attribute */
3093 CFStringRef cflang
, /* Language string */
3094 cftext
; /* Localized text */
3100 * Build the profile name dictionary...
3103 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3104 &kCFTypeDictionaryKeyCallBacks
,
3105 &kCFTypeDictionaryValueCallBacks
);
3108 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize profile \"%s\".",
3113 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3114 kCFStringEncodingUTF8
);
3118 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3125 * Find localized names for the color profiles...
3128 cupsArraySave(ppd
->sorted_attrs
);
3130 for (language
= (char *)cupsArrayFirst(languages
);
3132 language
= (char *)cupsArrayNext(languages
))
3136 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3138 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3141 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3143 if (attr
&& attr
->text
[0])
3145 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3146 kCFStringEncodingUTF8
);
3147 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3148 kCFStringEncodingUTF8
);
3150 if (cflang
&& cftext
)
3151 CFDictionarySetValue(dict
, cflang
, cftext
);
3161 cupsArrayRestore(ppd
->sorted_attrs
);
3165 * Fill in the profile data...
3168 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3171 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3172 (const UInt8
*)iccfile
,
3173 strlen(iccfile
), false);
3177 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3182 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3186 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3187 profile
->profileID
= id
;
3188 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3189 profile
->profileName
= dict
;
3192 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3193 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3194 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3199 * 'apple_register_profiles()' - Register color profiles for a printer.
3203 apple_register_profiles(
3204 cupsd_printer_t
*p
) /* I - Printer */
3206 int i
; /* Looping var */
3207 char ppdfile
[1024], /* PPD filename */
3208 iccfile
[1024], /* ICC filename */
3209 selector
[PPD_MAX_NAME
];
3210 /* Profile selection string */
3211 ppd_file_t
*ppd
; /* PPD file */
3212 ppd_attr_t
*attr
, /* Profile attributes */
3213 *profileid_attr
,/* cupsProfileID attribute */
3214 *q1_attr
, /* ColorModel (or other) qualifier */
3215 *q2_attr
, /* MediaType (or other) qualifier */
3216 *q3_attr
; /* Resolution (or other) qualifier */
3217 char q_keyword
[PPD_MAX_NAME
];
3218 /* Qualifier keyword */
3219 const char *q1_choice
, /* ColorModel (or other) choice */
3220 *q2_choice
, /* MediaType (or other) choice */
3221 *q3_choice
; /* Resolution (or other) choice */
3222 const char *profile_key
; /* Profile keyword */
3223 ppd_option_t
*cm_option
; /* Color model option */
3224 ppd_choice_t
*cm_choice
; /* Color model choice */
3225 int num_profiles
; /* Number of profiles */
3226 OSStatus error
= 0; /* Last error */
3227 unsigned device_id
, /* Printer device ID */
3228 profile_id
= 0, /* Profile ID */
3229 default_profile_id
= 0;
3230 /* Default profile ID */
3231 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3232 CFStringRef printer_name
; /* Printer name string */
3233 cups_array_t
*languages
; /* Languages array */
3234 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3235 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3236 profile
; /* Current profile info dictionary */
3237 CFStringRef dict_key
; /* Key in factory profile dictionary */
3239 CMDeviceScope scope
= /* Scope of the registration */
3241 kCFPreferencesAnyUser
,
3242 kCFPreferencesCurrentHost
3244 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3245 CMDeviceProfileInfo
*profile
; /* Current profile */
3246 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3250 * Make sure ColorSync is available...
3253 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3254 if (ColorSyncRegisterDevice
== NULL
)
3258 if (CMRegisterColorDevice
== NULL
)
3260 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3263 * Try opening the PPD file for this printer...
3266 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3267 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3271 * See if we have any profiles...
3274 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3275 profile_key
= "APTiogaProfile";
3278 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3279 profile_key
= "cupsICCProfile";
3282 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3283 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3285 if (attr
->value
[0] != '/')
3286 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3289 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3291 if (access(iccfile
, 0))
3293 cupsdLogMessage(CUPSD_LOG_ERROR
,
3294 "%s: ICC Profile \"%s\" does not exist.", p
->name
,
3302 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3304 * Create a dictionary for the factory profiles...
3307 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3308 &kCFTypeDictionaryKeyCallBacks
,
3309 &kCFTypeDictionaryValueCallBacks
);
3312 cupsdLogMessage(CUPSD_LOG_ERROR
,
3313 "Unable to allocate memory for factory profiles.");
3317 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3320 * If we have profiles, add them...
3323 if (num_profiles
> 0)
3325 if (profile_key
[0] == 'A')
3328 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3332 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3334 default_profile_id
= atoi(attr
->value
);
3336 q1_choice
= q2_choice
= q3_choice
= NULL
;
3341 * For CUPS PPDs, figure out the default profile selector values...
3344 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3345 attr
->value
&& attr
->value
[0])
3347 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3348 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3350 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3351 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3353 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3354 q1_choice
= q1_attr
->value
;
3358 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3359 attr
->value
&& attr
->value
[0])
3361 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3362 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3365 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3367 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3368 q2_choice
= q2_attr
->value
;
3372 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3373 attr
->value
&& attr
->value
[0])
3375 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3376 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3379 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3381 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3382 q3_choice
= q3_attr
->value
;
3387 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3389 * Build the array of profiles...
3391 * Note: This calloc actually requests slightly more memory than needed.
3394 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3396 cupsdLogMessage(CUPSD_LOG_ERROR
,
3397 "Unable to allocate memory for factory profiles.");
3402 profiles
->profileCount
= num_profiles
;
3403 profile
= profiles
->profiles
;
3404 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3407 * Loop through the profiles listed in the PPD...
3410 languages
= _ppdGetLanguages(ppd
);
3412 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3414 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3415 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3418 * Add this profile...
3421 if (attr
->value
[0] != '/')
3422 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3425 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3427 if (_cupsFileCheck(iccfile
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
3428 cupsdLogFCMessage
, p
))
3431 if (profile_key
[0] == 'c')
3433 cupsArraySave(ppd
->sorted_attrs
);
3435 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3436 attr
->spec
)) != NULL
&&
3437 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3438 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3440 profile_id
= _ppdHashName(attr
->spec
);
3442 cupsArrayRestore(ppd
->sorted_attrs
);
3445 profile_id
= atoi(attr
->spec
);
3447 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3448 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3449 &kCFTypeDictionaryKeyCallBacks
,
3450 &kCFTypeDictionaryValueCallBacks
);
3453 cupsdLogMessage(CUPSD_LOG_ERROR
,
3454 "Unable to allocate memory for color profile.");
3455 CFRelease(profiles
);
3460 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3461 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3463 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3464 CFSTR("%u"), profile_id
);
3467 CFDictionarySetValue(profiles
, dict_key
, profile
);
3468 CFRelease(dict_key
);
3474 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3475 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3478 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3481 * See if this is the default profile...
3484 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3486 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3488 if (!strcmp(selector
, attr
->spec
))
3489 default_profile_id
= profile_id
;
3492 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3494 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3495 if (!strcmp(selector
, attr
->spec
))
3496 default_profile_id
= profile_id
;
3499 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3501 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3502 if (!strcmp(selector
, attr
->spec
))
3503 default_profile_id
= profile_id
;
3506 if (!default_profile_id
&& q1_choice
)
3508 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3509 if (!strcmp(selector
, attr
->spec
))
3510 default_profile_id
= profile_id
;
3513 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3515 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3516 if (!strcmp(selector
, attr
->spec
))
3517 default_profile_id
= profile_id
;
3520 if (!default_profile_id
&& q2_choice
)
3522 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3523 if (!strcmp(selector
, attr
->spec
))
3524 default_profile_id
= profile_id
;
3527 if (!default_profile_id
&& q3_choice
)
3529 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3530 if (!strcmp(selector
, attr
->spec
))
3531 default_profile_id
= profile_id
;
3535 _ppdFreeLanguages(languages
);
3537 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3540 * Extract profiles from ColorModel option...
3543 const char *profile_name
; /* Name of generic profile */
3546 num_profiles
= cm_option
->num_choices
;
3548 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3550 * Create an array for the factory profiles...
3553 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3555 cupsdLogMessage(CUPSD_LOG_ERROR
,
3556 "Unable to allocate memory for factory profiles.");
3561 profiles
->profileCount
= num_profiles
;
3562 profile
= profiles
->profiles
;
3563 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3565 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3569 if (!strcmp(cm_choice
->choice
, "Gray") ||
3570 !strcmp(cm_choice
->choice
, "Black"))
3571 profile_name
= "Gray";
3572 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3573 !strcmp(cm_choice
->choice
, "CMY"))
3574 profile_name
= "RGB";
3575 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3576 !strcmp(cm_choice
->choice
, "KCMY"))
3577 profile_name
= "CMYK";
3579 profile_name
= "DeviceN";
3581 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3582 profile_id
= _ppdHashName(selector
);
3584 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3585 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3586 &kCFTypeDictionaryKeyCallBacks
,
3587 &kCFTypeDictionaryValueCallBacks
);
3590 cupsdLogMessage(CUPSD_LOG_ERROR
,
3591 "Unable to allocate memory for color profile.");
3592 CFRelease(profiles
);
3597 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3598 cm_choice
->text
, NULL
);
3600 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3601 CFSTR("%u"), profile_id
);
3604 CFDictionarySetValue(profiles
, dict_key
, profile
);
3605 CFRelease(dict_key
);
3611 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3612 cm_choice
->text
, NULL
);
3614 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3616 if (cm_choice
->marked
)
3617 default_profile_id
= profile_id
;
3623 * Use the default colorspace...
3626 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3628 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3630 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3632 * Add the grayscale profile first. We always have a grayscale profile.
3635 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3636 &kCFTypeDictionaryKeyCallBacks
,
3637 &kCFTypeDictionaryValueCallBacks
);
3641 cupsdLogMessage(CUPSD_LOG_ERROR
,
3642 "Unable to allocate memory for color profile.");
3643 CFRelease(profiles
);
3648 profile_id
= _ppdHashName("Gray..");
3649 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3651 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3655 CFDictionarySetValue(profiles
, dict_key
, profile
);
3656 CFRelease(dict_key
);
3662 * Then add the RGB/CMYK/DeviceN color profile...
3665 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3666 &kCFTypeDictionaryKeyCallBacks
,
3667 &kCFTypeDictionaryValueCallBacks
);
3671 cupsdLogMessage(CUPSD_LOG_ERROR
,
3672 "Unable to allocate memory for color profile.");
3673 CFRelease(profiles
);
3678 switch (ppd
->colorspace
)
3683 profile_id
= _ppdHashName("RGB..");
3684 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3690 profile_id
= _ppdHashName("CMYK..");
3691 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3700 profile_id
= _ppdHashName("DeviceN..");
3701 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3706 if (CFDictionaryGetCount(profile
) > 0)
3708 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3709 CFSTR("%u"), profile_id
);
3712 CFDictionarySetValue(profiles
, dict_key
, profile
);
3713 CFRelease(dict_key
);
3721 * Create an array for the factory profiles...
3724 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3726 cupsdLogMessage(CUPSD_LOG_ERROR
,
3727 "Unable to allocate memory for factory profiles.");
3732 profiles
->profileCount
= num_profiles
;
3735 * Add the grayscale profile first. We always have a grayscale profile.
3738 profile_id
= _ppdHashName("Gray..");
3739 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3743 * Then add the RGB/CMYK/DeviceN color profile...
3746 switch (ppd
->colorspace
)
3751 profile_id
= _ppdHashName("RGB..");
3752 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3753 "RGB", "RGB", NULL
);
3757 profile_id
= _ppdHashName("CMYK..");
3758 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3759 "CMYK", "CMYK", NULL
);
3767 profile_id
= _ppdHashName("DeviceN..");
3768 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3769 "DeviceN", "DeviceN", NULL
);
3772 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3775 if (num_profiles
> 0)
3778 * Make sure we have a default profile ID...
3781 if (!default_profile_id
)
3782 default_profile_id
= profile_id
; /* Last profile */
3784 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3785 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3786 default_profile_id
);
3789 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3791 CFRelease(dict_key
);
3793 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3796 * Get the device ID hash and pathelogical name dictionary.
3799 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3802 device_id
= _ppdHashName(p
->name
);
3803 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3804 &kCFTypeDictionaryKeyCallBacks
,
3805 &kCFTypeDictionaryValueCallBacks
);
3806 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3807 p
->name
, kCFStringEncodingUTF8
);
3809 if (device_name
&& printer_name
)
3811 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3814 * Register the device with ColorSync...
3817 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3818 CFTypeRef deviceDictKeys
[] =
3820 kColorSyncDeviceDescriptions
,
3821 kColorSyncFactoryProfiles
,
3822 kColorSyncDeviceUserScope
,
3823 kColorSyncDeviceHostScope
3825 CFTypeRef deviceDictVals
[] =
3826 { /* Device values */
3829 kCFPreferencesAnyUser
,
3830 kCFPreferencesCurrentHost
3832 CFDictionaryRef deviceDict
; /* Device dictionary */
3833 CFUUIDRef deviceUUID
; /* Device UUID */
3835 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3836 (const void **)deviceDictKeys
,
3837 (const void **)deviceDictVals
,
3838 sizeof(deviceDictKeys
) /
3839 sizeof(deviceDictKeys
[0]),
3840 &kCFTypeDictionaryKeyCallBacks
,
3841 &kCFTypeDictionaryValueCallBacks
);
3842 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3844 if (!deviceDict
|| !deviceUUID
||
3845 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3850 CFRelease(deviceUUID
);
3853 CFRelease(deviceDict
);
3856 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3857 device_name
, &scope
);
3860 * Register the profiles...
3864 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3865 default_profile_id
, profiles
);
3866 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3876 cupsdLogMessage(CUPSD_LOG_ERROR
,
3877 "Unable to register ICC color profiles for \"%s\": %d",
3878 p
->name
, (int)error
);
3881 CFRelease(printer_name
);
3884 CFRelease(device_name
);
3888 * Free any memory we used...
3891 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3892 CFRelease(profiles
);
3895 if (num_profiles
> 0)
3897 for (profile
= profiles
->profiles
;
3899 profile
++, num_profiles
--)
3900 CFRelease(profile
->profileName
);
3904 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3911 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3916 apple_unregister_profiles(
3917 cupsd_printer_t
*p
) /* I - Printer */
3920 * Make sure ColorSync is available...
3923 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3924 if (ColorSyncUnregisterDevice
!= NULL
)
3927 * Because we may have registered the printer profiles using a prior device
3928 * ID-based UUID, remove both the old style UUID and current UUID for the
3932 CFUUIDRef deviceUUID
; /* Device UUID */
3934 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3937 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3938 CFRelease(deviceUUID
);
3943 if (CMUnregisterColorDevice
!= NULL
)
3944 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3945 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3947 #endif /* __APPLE__ */
3951 * 'apply_printer_defaults()' - Apply printer default options to a job.
3955 apply_printer_defaults(
3956 cupsd_printer_t
*printer
, /* I - Printer */
3957 cupsd_job_t
*job
) /* I - Job */
3959 int i
, /* Looping var */
3960 num_options
; /* Number of default options */
3961 cups_option_t
*options
, /* Default options */
3962 *option
; /* Current option */
3966 * Collect all of the default options and add the missing ones to the
3970 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3971 option
= printer
->options
;
3974 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3976 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3981 * Encode these options as attributes in the job object...
3984 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3985 cupsFreeOptions(num_options
, options
);
3990 * 'authenticate_job()' - Set job authentication info.
3994 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3995 ipp_attribute_t
*uri
) /* I - Job URI */
3997 ipp_attribute_t
*attr
, /* job-id attribute */
3998 *auth_info
; /* auth-info attribute */
3999 int jobid
; /* Job ID */
4000 cupsd_job_t
*job
; /* Current job */
4001 char scheme
[HTTP_MAX_URI
],
4002 /* Method portion of URI */
4003 username
[HTTP_MAX_URI
],
4004 /* Username portion of URI */
4006 /* Host portion of URI */
4007 resource
[HTTP_MAX_URI
];
4008 /* Resource portion of URI */
4009 int port
; /* Port portion of URI */
4012 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4013 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4016 * Start with "everything is OK" status...
4019 con
->response
->request
.status
.status_code
= IPP_OK
;
4022 * See if we have a job URI or a printer URI...
4025 if (!strcmp(uri
->name
, "printer-uri"))
4028 * Got a printer URI; see if we also have a job-id attribute...
4031 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4032 IPP_TAG_INTEGER
)) == NULL
)
4034 send_ipp_status(con
, IPP_BAD_REQUEST
,
4035 _("Got a printer-uri attribute but no job-id."));
4039 jobid
= attr
->values
[0].integer
;
4044 * Got a job URI; parse it to get the job ID...
4047 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4048 sizeof(scheme
), username
, sizeof(username
), host
,
4049 sizeof(host
), &port
, resource
, sizeof(resource
));
4051 if (strncmp(resource
, "/jobs/", 6))
4057 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4058 uri
->values
[0].string
.text
);
4062 jobid
= atoi(resource
+ 6);
4066 * See if the job exists...
4069 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4072 * Nope - return a "not found" error...
4075 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4080 * See if the job has been completed...
4083 if (job
->state_value
!= IPP_JOB_HELD
)
4086 * Return a "not-possible" error...
4089 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4090 _("Job #%d is not held for authentication."),
4096 * See if we have already authenticated...
4099 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4101 if (!con
->username
[0] && !auth_info
)
4103 cupsd_printer_t
*printer
; /* Job destination */
4107 * No auth data. If we need to authenticate via Kerberos, send a
4108 * HTTP auth challenge, otherwise just return an IPP error...
4111 printer
= cupsdFindDest(job
->dest
);
4113 if (printer
&& printer
->num_auth_info_required
> 0 &&
4114 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4115 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4117 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4118 _("No authentication information provided."));
4123 * See if the job is owned by the requesting user...
4126 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4128 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4129 cupsdFindDest(job
->dest
));
4134 * Save the authentication information for this job...
4137 save_auth_info(con
, job
, auth_info
);
4140 * Reset the job-hold-until value to "no-hold"...
4143 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4144 IPP_TAG_KEYWORD
)) == NULL
)
4145 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4149 attr
->value_tag
= IPP_TAG_KEYWORD
;
4150 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4154 * Release the job and return...
4157 cupsdReleaseJob(job
);
4159 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4161 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4168 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4172 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4173 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4175 int i
; /* Looping var */
4176 http_status_t status
; /* Policy status */
4177 cups_ptype_t dtype
; /* Destination type */
4178 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4179 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4180 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4181 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4182 int port
; /* Port portion of URI */
4183 ipp_attribute_t
*attr
; /* Attribute in request */
4184 const char *username
= NULL
; /* Username */
4185 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4187 cupsd_printer_t
*printer
; /* Printer */
4188 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4189 cupsd_job_t
*job
; /* Job */
4192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4193 con
->http
.fd
, uri
->values
[0].string
.text
);
4196 * Get the jobs to cancel/purge...
4199 switch (con
->request
->request
.op
.operation_id
)
4201 case IPP_PURGE_JOBS
:
4203 * Get the username (if any) for the jobs we want to cancel (only if
4204 * "my-jobs" is specified...
4207 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4208 IPP_TAG_BOOLEAN
)) != NULL
&&
4209 attr
->values
[0].boolean
)
4211 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4212 IPP_TAG_NAME
)) != NULL
)
4213 username
= attr
->values
[0].string
.text
;
4216 send_ipp_status(con
, IPP_BAD_REQUEST
,
4217 _("Missing requesting-user-name attribute."));
4223 * Look for the "purge-jobs" attribute...
4226 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4227 IPP_TAG_BOOLEAN
)) != NULL
)
4228 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4230 purge
= CUPSD_JOB_PURGE
;
4233 case IPP_CANCEL_MY_JOBS
:
4234 if (con
->username
[0])
4235 username
= con
->username
;
4236 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4237 IPP_TAG_NAME
)) != NULL
)
4238 username
= attr
->values
[0].string
.text
;
4241 send_ipp_status(con
, IPP_BAD_REQUEST
,
4242 _("Missing requesting-user-name attribute."));
4250 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4253 * See if we have a printer URI...
4256 if (strcmp(uri
->name
, "printer-uri"))
4258 send_ipp_status(con
, IPP_BAD_REQUEST
,
4259 _("The printer-uri attribute is required."));
4264 * And if the destination is valid...
4267 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4273 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4274 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4275 hostname
, sizeof(hostname
), &port
,
4276 resource
, sizeof(resource
));
4278 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4279 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4281 send_ipp_status(con
, IPP_NOT_FOUND
,
4282 _("The printer or class does not exist."));
4290 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4292 send_http_error(con
, status
, NULL
);
4298 for (i
= 0; i
< job_ids
->num_values
; i
++)
4300 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4304 if (i
< job_ids
->num_values
)
4306 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4307 job_ids
->values
[i
].integer
);
4311 for (i
= 0; i
< job_ids
->num_values
; i
++)
4313 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4315 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4316 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4317 "Job canceled by user.");
4320 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4321 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4327 * Cancel all jobs on all printers...
4330 cupsdCancelJobs(NULL
, username
, purge
);
4332 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4333 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4343 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4346 send_http_error(con
, status
, printer
);
4352 for (i
= 0; i
< job_ids
->num_values
; i
++)
4354 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4355 _cups_strcasecmp(job
->dest
, printer
->name
))
4359 if (i
< job_ids
->num_values
)
4361 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4362 job_ids
->values
[i
].integer
);
4366 for (i
= 0; i
< job_ids
->num_values
; i
++)
4368 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4370 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4371 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4372 "Job canceled by user.");
4375 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4376 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4382 * Cancel all of the jobs on the named printer...
4385 cupsdCancelJobs(printer
->name
, username
, purge
);
4387 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4389 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4394 con
->response
->request
.status
.status_code
= IPP_OK
;
4399 * 'cancel_job()' - Cancel a print job.
4403 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4404 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4406 ipp_attribute_t
*attr
; /* Current attribute */
4407 int jobid
; /* Job ID */
4408 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4409 username
[HTTP_MAX_URI
], /* Username portion of URI */
4410 host
[HTTP_MAX_URI
], /* Host portion of URI */
4411 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4412 int port
; /* Port portion of URI */
4413 cupsd_job_t
*job
; /* Job information */
4414 cups_ptype_t dtype
; /* Destination type (printer/class) */
4415 cupsd_printer_t
*printer
; /* Printer data */
4416 cupsd_jobaction_t purge
; /* Purge the job? */
4419 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4420 con
->http
.fd
, uri
->values
[0].string
.text
);
4423 * See if we have a job URI or a printer URI...
4426 if (!strcmp(uri
->name
, "printer-uri"))
4429 * Got a printer URI; see if we also have a job-id attribute...
4432 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4433 IPP_TAG_INTEGER
)) == NULL
)
4435 send_ipp_status(con
, IPP_BAD_REQUEST
,
4436 _("Got a printer-uri attribute but no job-id."));
4440 if ((jobid
= attr
->values
[0].integer
) == 0)
4443 * Find the current job on the specified printer...
4446 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4452 send_ipp_status(con
, IPP_NOT_FOUND
,
4453 _("The printer or class does not exist."));
4458 * See if there are any pending jobs...
4461 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4463 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4464 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4465 !_cups_strcasecmp(job
->dest
, printer
->name
))
4473 * No, try stopped jobs...
4476 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4478 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4479 if (job
->state_value
== IPP_JOB_STOPPED
&&
4480 !_cups_strcasecmp(job
->dest
, printer
->name
))
4487 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4497 * Got a job URI; parse it to get the job ID...
4500 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4501 sizeof(scheme
), username
, sizeof(username
), host
,
4502 sizeof(host
), &port
, resource
, sizeof(resource
));
4504 if (strncmp(resource
, "/jobs/", 6))
4510 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4511 uri
->values
[0].string
.text
);
4515 jobid
= atoi(resource
+ 6);
4519 * Look for the "purge-job" attribute...
4522 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4523 IPP_TAG_BOOLEAN
)) != NULL
)
4524 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4526 purge
= CUPSD_JOB_DEFAULT
;
4529 * See if the job exists...
4532 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4535 * Nope - return a "not found" error...
4538 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4543 * See if the job is owned by the requesting user...
4546 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4548 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4549 cupsdFindDest(job
->dest
));
4554 * See if the job is already completed, canceled, or aborted; if so,
4555 * we can't cancel...
4558 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4560 switch (job
->state_value
)
4562 case IPP_JOB_CANCELED
:
4563 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4564 _("Job #%d is already canceled - can\'t cancel."),
4568 case IPP_JOB_ABORTED
:
4569 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4570 _("Job #%d is already aborted - can\'t cancel."),
4575 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4576 _("Job #%d is already completed - can\'t cancel."),
4585 * Cancel the job and return...
4588 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4589 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4590 "Job canceled by \"%s\"",
4594 if (purge
== CUPSD_JOB_PURGE
)
4595 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4598 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4601 con
->response
->request
.status
.status_code
= IPP_OK
;
4606 * 'cancel_subscription()' - Cancel a subscription.
4610 cancel_subscription(
4611 cupsd_client_t
*con
, /* I - Client connection */
4612 int sub_id
) /* I - Subscription ID */
4614 http_status_t status
; /* Policy status */
4615 cupsd_subscription_t
*sub
; /* Subscription */
4618 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4619 "cancel_subscription(con=%p[%d], sub_id=%d)",
4620 con
, con
->http
.fd
, sub_id
);
4623 * Is the subscription ID valid?
4626 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4629 * Bad subscription ID...
4632 send_ipp_status(con
, IPP_NOT_FOUND
,
4633 _("Subscription #%d does not exist."), sub_id
);
4641 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4643 con
, sub
->owner
)) != HTTP_OK
)
4645 send_http_error(con
, status
, sub
->dest
);
4650 * Cancel the subscription...
4653 cupsdDeleteSubscription(sub
, 1);
4655 con
->response
->request
.status
.status_code
= IPP_OK
;
4660 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4663 static int /* O - 1 if OK, 0 if not */
4664 check_rss_recipient(
4665 const char *recipient
) /* I - Recipient URI */
4667 cupsd_subscription_t
*sub
; /* Current subscription */
4670 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4672 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4676 * Compare the URIs up to the first ?...
4679 const char *r1
, *r2
;
4681 for (r1
= recipient
, r2
= sub
->recipient
;
4682 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4694 * 'check_quotas()' - Check quotas for a printer and user.
4697 static int /* O - 1 if OK, 0 if forbidden,
4698 -1 if limit reached */
4699 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4700 cupsd_printer_t
*p
) /* I - Printer or class */
4702 char username
[33], /* Username */
4703 *name
; /* Current user name */
4704 cupsd_quota_t
*q
; /* Quota data */
4705 #ifdef HAVE_MBR_UID_TO_UUID
4707 * Use Apple membership APIs which require that all names represent
4708 * valid user account or group records accessible by the server.
4711 uuid_t usr_uuid
; /* UUID for job requesting user */
4712 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4713 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4714 int mbr_err
; /* Error from membership function */
4715 int is_member
; /* Is this user a member? */
4718 * Use standard POSIX APIs for checking users and groups...
4721 struct passwd
*pw
; /* User password data */
4722 #endif /* HAVE_MBR_UID_TO_UUID */
4725 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4726 con
, con
->http
.fd
, p
, p
->name
);
4729 * Figure out who is printing...
4732 strlcpy(username
, get_username(con
), sizeof(username
));
4735 * Check global active job limits for printers and users...
4738 if (MaxJobsPerPrinter
)
4741 * Check if there are too many pending jobs on this printer...
4744 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4746 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4755 * Check if there are too many pending jobs for this user...
4758 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4760 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4767 * Check against users...
4770 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4773 if (cupsArrayCount(p
->users
))
4775 #ifdef HAVE_MBR_UID_TO_UUID
4777 * Get UUID for job requesting user...
4780 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4786 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4787 "check_quotas: UUID lookup failed for user \"%s\"",
4789 cupsdLogMessage(CUPSD_LOG_INFO
,
4790 "Denying user \"%s\" access to printer \"%s\" "
4791 "(unknown user)...",
4797 * Get UID and GID of requesting user...
4800 pw
= getpwnam(username
);
4802 #endif /* HAVE_MBR_UID_TO_UUID */
4804 for (name
= (char *)cupsArrayFirst(p
->users
);
4806 name
= (char *)cupsArrayNext(p
->users
))
4810 * Check group membership...
4813 #ifdef HAVE_MBR_UID_TO_UUID
4816 if (uuid_parse(name
+ 2, grp_uuid
))
4817 uuid_clear(grp_uuid
);
4819 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4822 * Invalid ACL entries are ignored for matching; just record a
4823 * warning in the log...
4826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4827 "check_quotas: UUID lookup failed for ACL entry "
4828 "\"%s\" (err=%d)", name
, mbr_err
);
4829 cupsdLogMessage(CUPSD_LOG_WARN
,
4830 "Access control entry \"%s\" not a valid group name; "
4831 "entry ignored", name
);
4834 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4838 * At this point, there should be no errors, but check anyways...
4841 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4842 "check_quotas: group \"%s\" membership check "
4843 "failed (err=%d)", name
+ 1, mbr_err
);
4848 * Stop if we found a match...
4855 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4857 #endif /* HAVE_MBR_UID_TO_UUID */
4859 #ifdef HAVE_MBR_UID_TO_UUID
4864 if (uuid_parse(name
+ 1, usr2_uuid
))
4865 uuid_clear(usr2_uuid
);
4867 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4870 * Invalid ACL entries are ignored for matching; just record a
4871 * warning in the log...
4874 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4875 "check_quotas: UUID lookup failed for ACL entry "
4876 "\"%s\" (err=%d)", name
, mbr_err
);
4877 cupsdLogMessage(CUPSD_LOG_WARN
,
4878 "Access control entry \"%s\" not a valid user name; "
4879 "entry ignored", name
);
4882 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4886 else if (!_cups_strcasecmp(username
, name
))
4888 #endif /* HAVE_MBR_UID_TO_UUID */
4890 if ((name
!= NULL
) == p
->deny_users
)
4892 cupsdLogMessage(CUPSD_LOG_INFO
,
4893 "Denying user \"%s\" access to printer \"%s\"...",
4903 if (p
->k_limit
|| p
->page_limit
)
4905 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4907 cupsdLogMessage(CUPSD_LOG_ERROR
,
4908 "Unable to allocate quota data for user \"%s\"",
4913 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4914 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4916 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4923 * If we have gotten this far, we're done!
4931 * 'close_job()' - Close a multi-file job.
4935 close_job(cupsd_client_t
*con
, /* I - Client connection */
4936 ipp_attribute_t
*uri
) /* I - Printer URI */
4938 cupsd_job_t
*job
; /* Job */
4939 ipp_attribute_t
*attr
; /* Attribute */
4940 char job_uri
[HTTP_MAX_URI
],
4942 username
[256]; /* User name */
4945 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4946 con
->http
.fd
, uri
->values
[0].string
.text
);
4949 * See if we have a job URI or a printer URI...
4952 if (strcmp(uri
->name
, "printer-uri"))
4955 * job-uri is not supported by Close-Job!
4958 send_ipp_status(con
, IPP_BAD_REQUEST
,
4959 _("Close-Job doesn't support the job-uri attribute."));
4964 * Got a printer URI; see if we also have a job-id attribute...
4967 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4968 IPP_TAG_INTEGER
)) == NULL
)
4970 send_ipp_status(con
, IPP_BAD_REQUEST
,
4971 _("Got a printer-uri attribute but no job-id."));
4975 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4978 * Nope - return a "not found" error...
4981 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4982 attr
->values
[0].integer
);
4987 * See if the job is owned by the requesting user...
4990 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4992 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4993 cupsdFindDest(job
->dest
));
4998 * Add any ending sheet...
5001 if (cupsdTimeoutJob(job
))
5004 if (job
->state_value
== IPP_JOB_STOPPED
)
5006 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5007 job
->state_value
= IPP_JOB_PENDING
;
5009 else if (job
->state_value
== IPP_JOB_HELD
)
5011 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5012 IPP_TAG_KEYWORD
)) == NULL
)
5013 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5015 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5017 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5018 job
->state_value
= IPP_JOB_PENDING
;
5023 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5026 * Fill in the response info...
5029 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5030 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
5031 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5034 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5036 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5039 add_job_state_reasons(con
, job
);
5041 con
->response
->request
.status
.status_code
= IPP_OK
;
5044 * Start the job if necessary...
5052 * 'copy_attribute()' - Copy a single attribute.
5055 static ipp_attribute_t
* /* O - New attribute */
5057 ipp_t
*to
, /* O - Destination request/response */
5058 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5059 int quickcopy
) /* I - Do a quick copy? */
5061 int i
; /* Looping var */
5062 ipp_attribute_t
*toattr
; /* Destination attribute */
5065 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5066 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5067 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5070 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5073 toattr
= ippAddSeparator(to
);
5076 case IPP_TAG_INTEGER
:
5078 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5079 attr
->name
, attr
->num_values
, NULL
);
5081 for (i
= 0; i
< attr
->num_values
; i
++)
5082 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5085 case IPP_TAG_BOOLEAN
:
5086 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5087 attr
->num_values
, NULL
);
5089 for (i
= 0; i
< attr
->num_values
; i
++)
5090 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5093 case IPP_TAG_STRING
:
5096 case IPP_TAG_KEYWORD
:
5098 case IPP_TAG_URISCHEME
:
5099 case IPP_TAG_CHARSET
:
5100 case IPP_TAG_LANGUAGE
:
5101 case IPP_TAG_MIMETYPE
:
5102 toattr
= ippAddStrings(to
, attr
->group_tag
,
5103 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5104 attr
->name
, attr
->num_values
, NULL
, NULL
);
5108 for (i
= 0; i
< attr
->num_values
; i
++)
5109 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5111 else if (attr
->value_tag
& IPP_TAG_COPY
)
5113 for (i
= 0; i
< attr
->num_values
; i
++)
5114 toattr
->values
[i
].string
.text
=
5115 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5119 for (i
= 0; i
< attr
->num_values
; i
++)
5120 toattr
->values
[i
].string
.text
=
5121 _cupsStrRetain(attr
->values
[i
].string
.text
);
5126 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5127 attr
->values
[0].date
);
5130 case IPP_TAG_RESOLUTION
:
5131 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5132 attr
->num_values
, IPP_RES_PER_INCH
,
5135 for (i
= 0; i
< attr
->num_values
; i
++)
5137 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5138 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5139 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5143 case IPP_TAG_RANGE
:
5144 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5145 attr
->num_values
, NULL
, NULL
);
5147 for (i
= 0; i
< attr
->num_values
; i
++)
5149 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5150 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5154 case IPP_TAG_TEXTLANG
:
5155 case IPP_TAG_NAMELANG
:
5156 toattr
= ippAddStrings(to
, attr
->group_tag
,
5157 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5158 attr
->name
, attr
->num_values
, NULL
, NULL
);
5162 for (i
= 0; i
< attr
->num_values
; i
++)
5164 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5165 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5168 else if (attr
->value_tag
& IPP_TAG_COPY
)
5170 for (i
= 0; i
< attr
->num_values
; i
++)
5173 toattr
->values
[i
].string
.charset
=
5174 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5176 toattr
->values
[i
].string
.charset
=
5177 toattr
->values
[0].string
.charset
;
5179 toattr
->values
[i
].string
.text
=
5180 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5185 for (i
= 0; i
< attr
->num_values
; i
++)
5188 toattr
->values
[i
].string
.charset
=
5189 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5191 toattr
->values
[i
].string
.charset
=
5192 toattr
->values
[0].string
.charset
;
5194 toattr
->values
[i
].string
.text
=
5195 _cupsStrRetain(attr
->values
[i
].string
.text
);
5200 case IPP_TAG_BEGIN_COLLECTION
:
5201 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5202 attr
->num_values
, NULL
);
5204 for (i
= 0; i
< attr
->num_values
; i
++)
5206 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5207 attr
->values
[i
].collection
->use
++;
5212 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5213 attr
->name
, attr
->num_values
, NULL
);
5215 for (i
= 0; i
< attr
->num_values
; i
++)
5217 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5219 if (toattr
->values
[i
].unknown
.length
> 0)
5221 if ((toattr
->values
[i
].unknown
.data
=
5222 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5223 toattr
->values
[i
].unknown
.length
= 0;
5225 memcpy(toattr
->values
[i
].unknown
.data
,
5226 attr
->values
[i
].unknown
.data
,
5227 toattr
->values
[i
].unknown
.length
);
5230 break; /* anti-compiler-warning-code */
5238 * 'copy_attrs()' - Copy attributes from one request to another.
5242 copy_attrs(ipp_t
*to
, /* I - Destination request */
5243 ipp_t
*from
, /* I - Source request */
5244 cups_array_t
*ra
, /* I - Requested attributes */
5245 ipp_tag_t group
, /* I - Group to copy */
5246 int quickcopy
, /* I - Do a quick copy? */
5247 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5249 ipp_attribute_t
*fromattr
; /* Source attribute */
5252 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5253 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5254 to
, from
, ra
, group
, quickcopy
);
5259 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5262 * Filter attributes as needed...
5265 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5266 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5269 if (!strcmp(fromattr
->name
, "job-printer-uri"))
5273 (cupsArrayFind(exclude
, fromattr
->name
) ||
5274 cupsArrayFind(exclude
, "all")))
5277 * We need to exclude this attribute for security reasons; we require the
5278 * job-id attribute regardless of the security settings for IPP
5281 * The job-printer-uri attribute is handled by copy_job_attrs().
5283 * Subscription attribute security is handled by copy_subscription_attrs().
5286 if (strcmp(fromattr
->name
, "job-id"))
5290 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5293 * Don't send collection attributes by default to IPP/1.x clients
5294 * since many do not support collections. Also don't send
5295 * media-col-database unless specifically requested by the client.
5298 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5300 (to
->request
.status
.version
[0] == 1 ||
5301 !strcmp(fromattr
->name
, "media-col-database")))
5304 copy_attribute(to
, fromattr
, quickcopy
);
5311 * 'copy_banner()' - Copy a banner file to the requests directory for the
5315 static int /* O - Size of banner file in kbytes */
5316 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5317 cupsd_job_t
*job
, /* I - Job information */
5318 const char *name
) /* I - Name of banner */
5320 int i
; /* Looping var */
5321 int kbytes
; /* Size of banner file in kbytes */
5322 char filename
[1024]; /* Job filename */
5323 cupsd_banner_t
*banner
; /* Pointer to banner */
5324 cups_file_t
*in
; /* Input file */
5325 cups_file_t
*out
; /* Output file */
5326 int ch
; /* Character from file */
5327 char attrname
[255], /* Name of attribute */
5328 *s
; /* Pointer into name */
5329 ipp_attribute_t
*attr
; /* Attribute */
5332 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5333 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5334 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5335 name
? name
: "(null)");
5338 * Find the banner; return if not found or "none"...
5341 if (!name
|| !strcmp(name
, "none") ||
5342 (banner
= cupsdFindBanner(name
)) == NULL
)
5346 * Open the banner and job files...
5349 if (add_file(con
, job
, banner
->filetype
, 0))
5352 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5354 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5356 cupsdLogMessage(CUPSD_LOG_ERROR
,
5357 "Unable to create banner job file %s - %s",
5358 filename
, strerror(errno
));
5363 fchmod(cupsFileNumber(out
), 0640);
5364 fchown(cupsFileNumber(out
), RunUser
, Group
);
5367 * Try the localized banner file under the subdirectory...
5370 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5372 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5375 * Convert ll-cc to ll_CC...
5379 attrname
[3] = toupper(attrname
[3] & 255);
5380 attrname
[4] = toupper(attrname
[4] & 255);
5383 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5386 if (access(filename
, 0) && strlen(attrname
) > 2)
5389 * Wasn't able to find "ll_CC" locale file; try the non-national
5390 * localization banner directory.
5395 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5399 if (access(filename
, 0))
5402 * Use the non-localized banner file.
5405 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5408 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5412 cupsdLogMessage(CUPSD_LOG_ERROR
,
5413 "Unable to open banner template file %s - %s",
5414 filename
, strerror(errno
));
5420 * Parse the file to the end...
5423 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5427 * Get an attribute name...
5430 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5431 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5433 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5443 * Ignore { followed by stuff that is not an attribute name...
5446 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5451 * See if it is defined...
5454 if (attrname
[0] == '?')
5459 if (!strcmp(s
, "printer-name"))
5461 cupsFilePuts(out
, job
->dest
);
5464 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5467 * See if we have a leading question mark...
5470 if (attrname
[0] != '?')
5473 * Nope, write to file as-is; probably a PostScript procedure...
5476 cupsFilePrintf(out
, "{%s}", attrname
);
5483 * Output value(s)...
5486 for (i
= 0; i
< attr
->num_values
; i
++)
5489 cupsFilePutChar(out
, ',');
5491 switch (attr
->value_tag
)
5493 case IPP_TAG_INTEGER
:
5495 if (!strncmp(s
, "time-at-", 8))
5497 struct timeval tv
; /* Time value */
5499 tv
.tv_sec
= attr
->values
[i
].integer
;
5502 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5505 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5508 case IPP_TAG_BOOLEAN
:
5509 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5512 case IPP_TAG_NOVALUE
:
5513 cupsFilePuts(out
, "novalue");
5516 case IPP_TAG_RANGE
:
5517 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5518 attr
->values
[i
].range
.upper
);
5521 case IPP_TAG_RESOLUTION
:
5522 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5523 attr
->values
[i
].resolution
.yres
,
5524 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5529 case IPP_TAG_STRING
:
5532 case IPP_TAG_KEYWORD
:
5533 case IPP_TAG_CHARSET
:
5534 case IPP_TAG_LANGUAGE
:
5535 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
5538 * Need to quote strings for PS banners...
5543 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5545 if (*p
== '(' || *p
== ')' || *p
== '\\')
5547 cupsFilePutChar(out
, '\\');
5548 cupsFilePutChar(out
, *p
);
5550 else if (*p
< 32 || *p
> 126)
5551 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5553 cupsFilePutChar(out
, *p
);
5557 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5561 break; /* anti-compiler-warning-code */
5565 else if (ch
== '\\') /* Quoted char */
5567 ch
= cupsFileGetChar(in
);
5569 if (ch
!= '{') /* Only do special handling for \{ */
5570 cupsFilePutChar(out
, '\\');
5572 cupsFilePutChar(out
, ch
);
5575 cupsFilePutChar(out
, ch
);
5579 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5581 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5582 IPP_TAG_INTEGER
)) != NULL
)
5583 attr
->values
[0].integer
+= kbytes
;
5592 * 'copy_file()' - Copy a PPD file or interface script...
5595 static int /* O - 0 = success, -1 = error */
5596 copy_file(const char *from
, /* I - Source file */
5597 const char *to
) /* I - Destination file */
5599 cups_file_t
*src
, /* Source file */
5600 *dst
; /* Destination file */
5601 int bytes
; /* Bytes to read/write */
5602 char buffer
[2048]; /* Copy buffer */
5605 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5608 * Open the source and destination file for a copy...
5611 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5614 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5621 * Copy the source file to the destination...
5624 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5625 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5633 * Close both files and return...
5638 return (cupsFileClose(dst
));
5643 * 'copy_model()' - Copy a PPD model file, substituting default values
5647 static int /* O - 0 = success, -1 = error */
5648 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5649 const char *from
, /* I - Source file */
5650 const char *to
) /* I - Destination file */
5652 fd_set input
; /* select() input set */
5653 struct timeval timeout
; /* select() timeout */
5654 int maxfd
; /* Max file descriptor for select() */
5655 char tempfile
[1024]; /* Temporary PPD file */
5656 int tempfd
; /* Temporary PPD file descriptor */
5657 int temppid
; /* Process ID of cups-driverd */
5658 int temppipe
[2]; /* Temporary pipes */
5659 char *argv
[4], /* Command-line arguments */
5660 *envp
[MAX_ENV
]; /* Environment */
5661 cups_file_t
*src
, /* Source file */
5662 *dst
; /* Destination file */
5663 ppd_file_t
*ppd
; /* PPD file */
5664 int bytes
, /* Bytes from pipe */
5665 total
; /* Total bytes from pipe */
5666 char buffer
[2048]; /* Copy buffer */
5667 int i
; /* Looping var */
5668 char option
[PPD_MAX_NAME
], /* Option name */
5669 choice
[PPD_MAX_NAME
]; /* Choice name */
5670 ppd_size_t
*size
; /* Default size */
5671 int num_defaults
; /* Number of default options */
5672 cups_option_t
*defaults
; /* Default options */
5673 char cups_protocol
[PPD_MAX_LINE
];
5674 /* cupsProtocol attribute */
5677 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5678 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5682 * Run cups-driverd to get the PPD file...
5685 argv
[0] = "cups-driverd";
5687 argv
[2] = (char *)from
;
5690 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5692 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5693 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5694 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5695 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
5698 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5699 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5701 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5702 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5713 * Wait up to 30 seconds for the PPD file to be copied...
5718 if (temppipe
[0] > CGIPipes
[0])
5719 maxfd
= temppipe
[0] + 1;
5721 maxfd
= CGIPipes
[0] + 1;
5726 * See if we have data ready...
5730 FD_SET(temppipe
[0], &input
);
5731 FD_SET(CGIPipes
[0], &input
);
5733 timeout
.tv_sec
= 30;
5734 timeout
.tv_usec
= 0;
5736 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5746 * We have timed out...
5752 if (FD_ISSET(temppipe
[0], &input
))
5755 * Read the PPD file from the pipe, and write it to the PPD file.
5758 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5760 if (write(tempfd
, buffer
, bytes
) < bytes
)
5769 if (FD_ISSET(CGIPipes
[0], &input
))
5779 * No data from cups-deviced...
5782 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5788 * Read the source file and see what page sizes are supported...
5791 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5798 * Open the destination (if possible) and set the default options...
5803 cups_protocol
[0] = '\0';
5805 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5808 * Read all of the default lines from the old PPD...
5811 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5812 if (!strncmp(buffer
, "*Default", 8))
5815 * Add the default option...
5818 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5819 choice
, sizeof(choice
)))
5821 ppd_option_t
*ppdo
; /* PPD option */
5825 * Only add the default if the default hasn't already been
5826 * set and the choice exists in the new PPD...
5829 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5830 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5831 ppdFindChoice(ppdo
, choice
))
5832 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5836 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5837 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5841 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5844 * Add the default media sizes...
5847 num_defaults
= cupsAddOption("PageSize", size
->name
,
5848 num_defaults
, &defaults
);
5849 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5850 num_defaults
, &defaults
);
5851 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5852 num_defaults
, &defaults
);
5853 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5854 num_defaults
, &defaults
);
5860 * Open the source file for a copy...
5863 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5865 cupsFreeOptions(num_defaults
, defaults
);
5871 * Open the destination file for a copy...
5874 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5876 cupsFreeOptions(num_defaults
, defaults
);
5883 * Copy the source file to the destination...
5886 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5888 if (!strncmp(buffer
, "*Default", 8))
5891 * Check for an previous default option choice...
5894 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5895 choice
, sizeof(choice
)))
5897 const char *val
; /* Default option value */
5900 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5903 * Substitute the previous choice...
5906 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5911 cupsFilePrintf(dst
, "%s\n", buffer
);
5914 if (cups_protocol
[0])
5915 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5917 cupsFreeOptions(num_defaults
, defaults
);
5920 * Close both files and return...
5927 return (cupsFileClose(dst
));
5932 * 'copy_job_attrs()' - Copy job attributes.
5936 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5937 cupsd_job_t
*job
, /* I - Job */
5938 cups_array_t
*ra
, /* I - Requested attributes array */
5939 cups_array_t
*exclude
) /* I - Private attributes array */
5941 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5945 * Send the requested attributes for each job...
5948 if (!cupsArrayFind(exclude
, "all"))
5950 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5951 (!ra
|| cupsArrayFind(ra
, "document-count")))
5952 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5953 "document-count", job
->num_files
);
5955 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5956 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5957 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5958 "job-media-progress", job
->progress
);
5960 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5961 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5963 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
5964 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
5966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5967 "job-more-info", NULL
, job_uri
);
5970 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5971 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5972 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5973 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5974 job
->num_files
> 0);
5976 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5977 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5978 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5979 "job-printer-up-time", time(NULL
));
5982 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
5984 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5985 con
->servername
, con
->serverport
,
5986 job
->dtype
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
) ?
5987 "/classes/%s" : "/printers/%s",
5989 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5990 "job-printer-uri", NULL
, job_uri
);
5993 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5994 add_job_state_reasons(con
, job
);
5996 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5998 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5999 con
->servername
, con
->serverport
, "/jobs/%d",
6001 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
6002 "job-uri", NULL
, job_uri
);
6005 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
6010 * 'copy_printer_attrs()' - Copy printer attributes.
6015 cupsd_client_t
*con
, /* I - Client connection */
6016 cupsd_printer_t
*printer
, /* I - Printer */
6017 cups_array_t
*ra
) /* I - Requested attributes array */
6019 char printer_uri
[HTTP_MAX_URI
];
6021 char printer_icons
[HTTP_MAX_URI
];
6023 time_t curtime
; /* Current time */
6024 int i
; /* Looping var */
6028 * Copy the printer attributes to the response using requested-attributes
6029 * and document-format attributes that may be provided by the client.
6032 curtime
= time(NULL
);
6034 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6035 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6036 "marker-change-time", printer
->marker_time
);
6038 if (printer
->num_printers
> 0 &&
6039 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6041 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6042 cupsd_printer_t
*p2
; /* Printer in class */
6043 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6046 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6047 IPP_TAG_URI
, "member-uris",
6048 printer
->num_printers
, NULL
,
6051 for (i
= 0; i
< printer
->num_printers
; i
++)
6053 p2
= printer
->printers
[i
];
6055 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6056 IPP_TAG_URI
)) != NULL
)
6057 member_uris
->values
[i
].string
.text
=
6058 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6061 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6062 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6064 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6065 "/classes/%s" : "/printers/%s", p2
->name
);
6066 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6072 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6073 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6074 "printer-alert", NULL
, printer
->alert
);
6076 if (printer
->alert_description
&&
6077 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6078 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6079 "printer-alert-description", NULL
,
6080 printer
->alert_description
);
6082 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6083 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6084 ippTimeToDate(curtime
));
6087 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6089 if (printer
->reg_name
)
6090 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6091 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6093 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6094 "printer-dns-sd-name", 0);
6096 #endif /* HAVE_DNSSD */
6098 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6099 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6100 "printer-error-policy", NULL
, printer
->error_policy
);
6102 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6104 static const char * const errors
[] =/* printer-error-policy-supported values */
6107 "retry-current-job",
6112 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6113 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6114 "printer-error-policy-supported", NULL
, "retry-current-job");
6116 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6117 "printer-error-policy-supported",
6118 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6121 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6123 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6124 "http", NULL
, con
->servername
, con
->serverport
,
6125 "/icons/%s.png", printer
->name
);
6126 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6127 NULL
, printer_icons
);
6128 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6131 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6132 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6133 printer
->accepting
);
6135 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6136 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6139 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6140 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6142 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6143 "http", NULL
, con
->servername
, con
->serverport
,
6144 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6145 "/classes/%s" : "/printers/%s", printer
->name
);
6146 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6147 "printer-more-info", NULL
, printer_uri
);
6150 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6151 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6152 "printer-op-policy", NULL
, printer
->op_policy
);
6154 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6155 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6158 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6159 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6160 "printer-state-change-time", printer
->state_time
);
6162 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6163 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6164 "printer-state-message", NULL
, printer
->state_message
);
6166 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6167 add_printer_state_reasons(con
, printer
);
6169 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6171 int type
; /* printer-type value */
6174 * Add the CUPS-specific printer-type attribute...
6177 type
= printer
->type
;
6179 if (printer
== DefaultPrinter
)
6180 type
|= CUPS_PRINTER_DEFAULT
;
6182 if (!printer
->accepting
)
6183 type
|= CUPS_PRINTER_REJECTING
;
6185 if (!printer
->shared
)
6186 type
|= CUPS_PRINTER_NOT_SHARED
;
6188 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6192 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6193 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6194 "printer-up-time", curtime
);
6196 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6197 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6199 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6200 "ipp", NULL
, con
->servername
, con
->serverport
,
6201 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6202 "/classes/%s" : "/printers/%s", printer
->name
);
6203 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6204 "printer-uri-supported", NULL
, printer_uri
);
6205 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6209 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6210 add_queued_job_count(con
, printer
);
6212 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6213 if (printer
->ppd_attrs
)
6214 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6215 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6220 * 'copy_subscription_attrs()' - Copy subscription attributes.
6224 copy_subscription_attrs(
6225 cupsd_client_t
*con
, /* I - Client connection */
6226 cupsd_subscription_t
*sub
, /* I - Subscription */
6227 cups_array_t
*ra
, /* I - Requested attributes array */
6228 cups_array_t
*exclude
) /* I - Private attributes array */
6230 ipp_attribute_t
*attr
; /* Current attribute */
6231 char printer_uri
[HTTP_MAX_URI
];
6233 int count
; /* Number of events */
6234 unsigned mask
; /* Current event mask */
6235 const char *name
; /* Current event name */
6238 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6239 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6240 con
, sub
, ra
, exclude
);
6243 * Copy the subscription attributes to the response using the
6244 * requested-attributes attribute that may be provided by the client.
6247 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6249 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6250 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6252 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6254 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6257 * Simple event list...
6260 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6261 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6262 "notify-events", NULL
, name
);
6267 * Complex event list...
6270 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6271 if (sub
->mask
& mask
)
6274 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6275 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6276 "notify-events", count
, NULL
, NULL
);
6278 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6279 if (sub
->mask
& mask
)
6281 attr
->values
[count
].string
.text
=
6282 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6289 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6290 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6291 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6292 "notify-lease-duration", sub
->lease
);
6294 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6295 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6296 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6297 "notify-recipient-uri", NULL
, sub
->recipient
);
6298 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6299 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6300 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6301 "notify-pull-method", NULL
, "ippget");
6303 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6304 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6305 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6306 "notify-subscriber-user-name", NULL
, sub
->owner
);
6308 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6309 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6310 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6311 "notify-time-interval", sub
->interval
);
6313 if (sub
->user_data_len
> 0 &&
6314 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6315 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6316 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6317 sub
->user_data
, sub
->user_data_len
);
6320 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6321 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6322 "notify-job-id", sub
->job
->id
);
6324 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6326 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6327 "ipp", NULL
, con
->servername
, con
->serverport
,
6328 "/printers/%s", sub
->dest
->name
);
6329 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6330 "notify-printer-uri", NULL
, printer_uri
);
6333 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6334 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6335 "notify-subscription-id", sub
->id
);
6340 * 'create_job()' - Print a file to a printer or class.
6344 create_job(cupsd_client_t
*con
, /* I - Client connection */
6345 ipp_attribute_t
*uri
) /* I - Printer URI */
6347 cupsd_printer_t
*printer
; /* Printer */
6348 cupsd_job_t
*job
; /* New job */
6351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6352 con
->http
.fd
, uri
->values
[0].string
.text
);
6355 * Is the destination valid?
6358 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6364 send_ipp_status(con
, IPP_NOT_FOUND
,
6365 _("The printer or class does not exist."));
6370 * Create the job object...
6373 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6376 job
->pending_timeout
= 1;
6379 * Save and log the job...
6382 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6383 job
->dest
, job
->username
);
6388 * 'create_requested_array()' - Create an array for the requested-attributes.
6391 static cups_array_t
* /* O - Array of attributes or NULL */
6392 create_requested_array(ipp_t
*request
) /* I - IPP request */
6394 int i
; /* Looping var */
6395 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6396 cups_array_t
*ra
; /* Requested attributes array */
6397 char *value
; /* Current value */
6401 * Get the requested-attributes attribute, and return NULL if we don't
6405 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6406 IPP_TAG_KEYWORD
)) == NULL
)
6410 * If the attribute contains a single "all" keyword, return NULL...
6413 if (requested
->num_values
== 1 &&
6414 !strcmp(requested
->values
[0].string
.text
, "all"))
6418 * Create an array using "strcmp" as the comparison function...
6421 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6423 for (i
= 0; i
< requested
->num_values
; i
++)
6425 value
= requested
->values
[i
].string
.text
;
6427 if (!strcmp(value
, "job-template"))
6429 cupsArrayAdd(ra
, "copies");
6430 cupsArrayAdd(ra
, "copies-default");
6431 cupsArrayAdd(ra
, "copies-supported");
6432 cupsArrayAdd(ra
, "finishings");
6433 cupsArrayAdd(ra
, "finishings-default");
6434 cupsArrayAdd(ra
, "finishings-supported");
6435 cupsArrayAdd(ra
, "job-hold-until");
6436 cupsArrayAdd(ra
, "job-hold-until-default");
6437 cupsArrayAdd(ra
, "job-hold-until-supported");
6438 cupsArrayAdd(ra
, "job-priority");
6439 cupsArrayAdd(ra
, "job-priority-default");
6440 cupsArrayAdd(ra
, "job-priority-supported");
6441 cupsArrayAdd(ra
, "job-sheets");
6442 cupsArrayAdd(ra
, "job-sheets-default");
6443 cupsArrayAdd(ra
, "job-sheets-supported");
6444 cupsArrayAdd(ra
, "media");
6445 cupsArrayAdd(ra
, "media-default");
6446 cupsArrayAdd(ra
, "media-supported");
6447 cupsArrayAdd(ra
, "multiple-document-handling");
6448 cupsArrayAdd(ra
, "multiple-document-handling-default");
6449 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6450 cupsArrayAdd(ra
, "number-up");
6451 cupsArrayAdd(ra
, "number-up-default");
6452 cupsArrayAdd(ra
, "number-up-supported");
6453 cupsArrayAdd(ra
, "orientation-requested");
6454 cupsArrayAdd(ra
, "orientation-requested-default");
6455 cupsArrayAdd(ra
, "orientation-requested-supported");
6456 cupsArrayAdd(ra
, "page-ranges");
6457 cupsArrayAdd(ra
, "page-ranges-supported");
6458 cupsArrayAdd(ra
, "printer-resolution");
6459 cupsArrayAdd(ra
, "printer-resolution-default");
6460 cupsArrayAdd(ra
, "printer-resolution-supported");
6461 cupsArrayAdd(ra
, "print-quality");
6462 cupsArrayAdd(ra
, "print-quality-default");
6463 cupsArrayAdd(ra
, "print-quality-supported");
6464 cupsArrayAdd(ra
, "sides");
6465 cupsArrayAdd(ra
, "sides-default");
6466 cupsArrayAdd(ra
, "sides-supported");
6468 else if (!strcmp(value
, "job-description"))
6470 cupsArrayAdd(ra
, "date-time-at-completed");
6471 cupsArrayAdd(ra
, "date-time-at-creation");
6472 cupsArrayAdd(ra
, "date-time-at-processing");
6473 cupsArrayAdd(ra
, "job-detailed-status-message");
6474 cupsArrayAdd(ra
, "job-document-access-errors");
6475 cupsArrayAdd(ra
, "job-id");
6476 cupsArrayAdd(ra
, "job-impressions");
6477 cupsArrayAdd(ra
, "job-impressions-completed");
6478 cupsArrayAdd(ra
, "job-k-octets");
6479 cupsArrayAdd(ra
, "job-k-octets-processed");
6480 cupsArrayAdd(ra
, "job-media-progress");
6481 cupsArrayAdd(ra
, "job-media-sheets");
6482 cupsArrayAdd(ra
, "job-media-sheets-completed");
6483 cupsArrayAdd(ra
, "job-message-from-operator");
6484 cupsArrayAdd(ra
, "job-more-info");
6485 cupsArrayAdd(ra
, "job-name");
6486 cupsArrayAdd(ra
, "job-originating-user-name");
6487 cupsArrayAdd(ra
, "job-printer-up-time");
6488 cupsArrayAdd(ra
, "job-printer-uri");
6489 cupsArrayAdd(ra
, "job-state");
6490 cupsArrayAdd(ra
, "job-state-message");
6491 cupsArrayAdd(ra
, "job-state-reasons");
6492 cupsArrayAdd(ra
, "job-uri");
6493 cupsArrayAdd(ra
, "number-of-documents");
6494 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6495 cupsArrayAdd(ra
, "output-device-assigned");
6496 cupsArrayAdd(ra
, "time-at-completed");
6497 cupsArrayAdd(ra
, "time-at-creation");
6498 cupsArrayAdd(ra
, "time-at-processing");
6500 else if (!strcmp(value
, "printer-description"))
6502 cupsArrayAdd(ra
, "charset-configured");
6503 cupsArrayAdd(ra
, "charset-supported");
6504 cupsArrayAdd(ra
, "color-supported");
6505 cupsArrayAdd(ra
, "compression-supported");
6506 cupsArrayAdd(ra
, "document-format-default");
6507 cupsArrayAdd(ra
, "document-format-supported");
6508 cupsArrayAdd(ra
, "generated-natural-language-supported");
6509 cupsArrayAdd(ra
, "ipp-versions-supported");
6510 cupsArrayAdd(ra
, "job-impressions-supported");
6511 cupsArrayAdd(ra
, "job-k-octets-supported");
6512 cupsArrayAdd(ra
, "job-media-sheets-supported");
6513 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6514 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6515 cupsArrayAdd(ra
, "multiple-operation-time-out");
6516 cupsArrayAdd(ra
, "natural-language-configured");
6517 cupsArrayAdd(ra
, "notify-attributes-supported");
6518 cupsArrayAdd(ra
, "notify-lease-duration-default");
6519 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6520 cupsArrayAdd(ra
, "notify-max-events-supported");
6521 cupsArrayAdd(ra
, "notify-events-default");
6522 cupsArrayAdd(ra
, "notify-events-supported");
6523 cupsArrayAdd(ra
, "notify-pull-method-supported");
6524 cupsArrayAdd(ra
, "notify-schemes-supported");
6525 cupsArrayAdd(ra
, "operations-supported");
6526 cupsArrayAdd(ra
, "pages-per-minute");
6527 cupsArrayAdd(ra
, "pages-per-minute-color");
6528 cupsArrayAdd(ra
, "pdl-override-supported");
6529 cupsArrayAdd(ra
, "printer-alert");
6530 cupsArrayAdd(ra
, "printer-alert-description");
6531 cupsArrayAdd(ra
, "printer-commands");
6532 cupsArrayAdd(ra
, "printer-current-time");
6533 cupsArrayAdd(ra
, "printer-driver-installer");
6534 cupsArrayAdd(ra
, "printer-dns-sd-name");
6535 cupsArrayAdd(ra
, "printer-info");
6536 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6537 cupsArrayAdd(ra
, "printer-location");
6538 cupsArrayAdd(ra
, "printer-make-and-model");
6539 cupsArrayAdd(ra
, "printer-message-from-operator");
6540 cupsArrayAdd(ra
, "printer-more-info");
6541 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6542 cupsArrayAdd(ra
, "printer-name");
6543 cupsArrayAdd(ra
, "printer-state");
6544 cupsArrayAdd(ra
, "printer-state-message");
6545 cupsArrayAdd(ra
, "printer-state-reasons");
6546 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6547 cupsArrayAdd(ra
, "printer-type");
6548 cupsArrayAdd(ra
, "printer-up-time");
6549 cupsArrayAdd(ra
, "printer-uri-supported");
6550 cupsArrayAdd(ra
, "queued-job-count");
6551 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6552 cupsArrayAdd(ra
, "uri-authentication-supported");
6553 cupsArrayAdd(ra
, "uri-security-supported");
6555 else if (!strcmp(value
, "printer-defaults"))
6557 char *name
; /* Option name */
6560 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6562 name
= (char *)cupsArrayNext(CommonDefaults
))
6563 cupsArrayAdd(ra
, name
);
6565 else if (!strcmp(value
, "subscription-template"))
6567 cupsArrayAdd(ra
, "notify-attributes");
6568 cupsArrayAdd(ra
, "notify-charset");
6569 cupsArrayAdd(ra
, "notify-events");
6570 cupsArrayAdd(ra
, "notify-lease-duration");
6571 cupsArrayAdd(ra
, "notify-natural-language");
6572 cupsArrayAdd(ra
, "notify-pull-method");
6573 cupsArrayAdd(ra
, "notify-recipient-uri");
6574 cupsArrayAdd(ra
, "notify-time-interval");
6575 cupsArrayAdd(ra
, "notify-user-data");
6578 cupsArrayAdd(ra
, value
);
6586 * 'create_subscription()' - Create a notification subscription.
6590 create_subscription(
6591 cupsd_client_t
*con
, /* I - Client connection */
6592 ipp_attribute_t
*uri
) /* I - Printer URI */
6594 http_status_t status
; /* Policy status */
6595 int i
; /* Looping var */
6596 ipp_attribute_t
*attr
; /* Current attribute */
6597 cups_ptype_t dtype
; /* Destination type (printer/class) */
6598 char scheme
[HTTP_MAX_URI
],
6599 /* Scheme portion of URI */
6600 userpass
[HTTP_MAX_URI
],
6601 /* Username portion of URI */
6603 /* Host portion of URI */
6604 resource
[HTTP_MAX_URI
];
6605 /* Resource portion of URI */
6606 int port
; /* Port portion of URI */
6607 cupsd_printer_t
*printer
; /* Printer/class */
6608 cupsd_job_t
*job
; /* Job */
6609 int jobid
; /* Job ID */
6610 cupsd_subscription_t
*sub
; /* Subscription object */
6611 const char *username
, /* requesting-user-name or
6612 authenticated username */
6613 *recipient
, /* notify-recipient-uri */
6614 *pullmethod
; /* notify-pull-method */
6615 ipp_attribute_t
*user_data
; /* notify-user-data */
6616 int interval
, /* notify-time-interval */
6617 lease
; /* notify-lease-duration */
6618 unsigned mask
; /* notify-events */
6619 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6620 *notify_lease
; /* notify-lease-duration(-default) */
6624 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6626 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6627 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6628 attr
->value_tag
, attr
->name
);
6630 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6635 * Is the destination valid?
6638 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6639 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6640 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6642 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6643 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6644 sizeof(host
), &port
, resource
, sizeof(resource
));
6646 if (!strcmp(resource
, "/"))
6648 dtype
= (cups_ptype_t
)0;
6651 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6653 dtype
= (cups_ptype_t
)0;
6656 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6658 dtype
= CUPS_PRINTER_CLASS
;
6661 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6667 send_ipp_status(con
, IPP_NOT_FOUND
,
6668 _("The printer or class does not exist."));
6678 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6681 send_http_error(con
, status
, printer
);
6685 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6687 send_http_error(con
, status
, NULL
);
6692 * Get the user that is requesting the subscription...
6695 username
= get_username(con
);
6698 * Find the first subscription group attribute; return if we have
6702 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6703 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6708 send_ipp_status(con
, IPP_BAD_REQUEST
,
6709 _("No subscription attributes in request."));
6714 * Process the subscription attributes in the request...
6717 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6725 lease
= DefaultLeaseDuration
;
6727 mask
= CUPSD_EVENT_NONE
;
6731 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6733 notify_lease
= ippFindAttribute(printer
->attrs
,
6734 "notify-lease-duration-default",
6738 lease
= notify_lease
->values
[0].integer
;
6742 notify_events
= NULL
;
6743 notify_lease
= NULL
;
6746 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6748 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6749 attr
->value_tag
== IPP_TAG_URI
)
6752 * Validate the recipient scheme against the ServerBin/notifier
6756 char notifier
[1024]; /* Notifier filename */
6759 recipient
= attr
->values
[0].string
.text
;
6761 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6762 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6763 host
, sizeof(host
), &port
,
6764 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6766 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6767 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6768 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6769 "notify-status-code", IPP_URI_SCHEME
);
6773 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6775 if (access(notifier
, X_OK
))
6777 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6778 _("notify-recipient-uri URI \"%s\" uses unknown "
6779 "scheme."), recipient
);
6780 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6781 "notify-status-code", IPP_URI_SCHEME
);
6785 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6787 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6788 _("notify-recipient-uri URI \"%s\" is already used."),
6790 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6791 "notify-status-code", IPP_ATTRIBUTES
);
6795 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6796 attr
->value_tag
== IPP_TAG_KEYWORD
)
6798 pullmethod
= attr
->values
[0].string
.text
;
6800 if (strcmp(pullmethod
, "ippget"))
6802 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6803 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6804 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6805 "notify-status-code", IPP_ATTRIBUTES
);
6809 else if (!strcmp(attr
->name
, "notify-charset") &&
6810 attr
->value_tag
== IPP_TAG_CHARSET
&&
6811 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6812 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6814 send_ipp_status(con
, IPP_CHARSET
,
6815 _("Character set \"%s\" not supported."),
6816 attr
->values
[0].string
.text
);
6819 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6820 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6821 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6823 send_ipp_status(con
, IPP_CHARSET
,
6824 _("Language \"%s\" not supported."),
6825 attr
->values
[0].string
.text
);
6828 else if (!strcmp(attr
->name
, "notify-user-data") &&
6829 attr
->value_tag
== IPP_TAG_STRING
)
6831 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6833 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6834 _("The notify-user-data value is too large "
6835 "(%d > 63 octets)."),
6836 attr
->values
[0].unknown
.length
);
6842 else if (!strcmp(attr
->name
, "notify-events") &&
6843 attr
->value_tag
== IPP_TAG_KEYWORD
)
6844 notify_events
= attr
;
6845 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6846 attr
->value_tag
== IPP_TAG_INTEGER
)
6847 lease
= attr
->values
[0].integer
;
6848 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6849 attr
->value_tag
== IPP_TAG_INTEGER
)
6850 interval
= attr
->values
[0].integer
;
6851 else if (!strcmp(attr
->name
, "notify-job-id") &&
6852 attr
->value_tag
== IPP_TAG_INTEGER
)
6853 jobid
= attr
->values
[0].integer
;
6860 for (i
= 0; i
< notify_events
->num_values
; i
++)
6861 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6865 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6868 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6871 if (!recipient
&& !pullmethod
)
6874 if (mask
== CUPSD_EVENT_NONE
)
6877 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6879 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6882 send_ipp_status(con
, IPP_BAD_REQUEST
,
6883 _("notify-events not specified."));
6888 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6890 cupsdLogMessage(CUPSD_LOG_INFO
,
6891 "create_subscription: Limiting notify-lease-duration to "
6894 lease
= MaxLeaseDuration
;
6899 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6901 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6909 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6911 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6912 _("There are too many subscriptions."));
6917 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6920 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6921 "Added subscription #%d for printer \"%s\".",
6922 sub
->id
, printer
->name
);
6924 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6927 sub
->interval
= interval
;
6929 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6931 cupsdSetString(&sub
->owner
, username
);
6935 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6936 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6937 sub
->user_data_len
);
6940 ippAddSeparator(con
->response
);
6941 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6942 "notify-subscription-id", sub
->id
);
6944 con
->response
->request
.status
.status_code
= IPP_OK
;
6950 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6955 * 'delete_printer()' - Remove a printer or class from the system.
6959 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6960 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6962 http_status_t status
; /* Policy status */
6963 cups_ptype_t dtype
; /* Destination type (printer/class) */
6964 cupsd_printer_t
*printer
; /* Printer/class */
6965 char filename
[1024]; /* Script/PPD filename */
6968 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6969 con
->http
.fd
, uri
->values
[0].string
.text
);
6972 * Do we have a valid URI?
6975 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6981 send_ipp_status(con
, IPP_NOT_FOUND
,
6982 _("The printer or class does not exist."));
6990 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6992 send_http_error(con
, status
, NULL
);
6997 * Remove old jobs...
7000 cupsdCancelJobs(printer
->name
, NULL
, 1);
7003 * Remove old subscriptions and send a "deleted printer" event...
7006 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
7007 "%s \"%s\" deleted by \"%s\".",
7008 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
7009 printer
->name
, get_username(con
));
7011 cupsdExpireSubscriptions(printer
, NULL
);
7014 * Remove any old PPD or script files...
7017 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7021 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7025 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7028 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
7033 * Unregister color profiles...
7036 apple_unregister_profiles(printer
);
7037 #endif /* __APPLE__ */
7039 if (dtype
& CUPS_PRINTER_CLASS
)
7041 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7042 printer
->name
, get_username(con
));
7044 cupsdDeletePrinter(printer
, 0);
7045 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7049 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7050 printer
->name
, get_username(con
));
7052 if (cupsdDeletePrinter(printer
, 0))
7053 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7055 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7058 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7061 * Return with no errors...
7064 con
->response
->request
.status
.status_code
= IPP_OK
;
7069 * 'get_default()' - Get the default destination.
7073 get_default(cupsd_client_t
*con
) /* I - Client connection */
7075 http_status_t status
; /* Policy status */
7076 cups_array_t
*ra
; /* Requested attributes array */
7079 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7085 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7087 send_http_error(con
, status
, NULL
);
7093 ra
= create_requested_array(con
->request
);
7095 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7097 cupsArrayDelete(ra
);
7099 con
->response
->request
.status
.status_code
= IPP_OK
;
7102 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
7107 * 'get_devices()' - Get the list of available devices on the local system.
7111 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7113 http_status_t status
; /* Policy status */
7114 ipp_attribute_t
*limit
, /* limit attribute */
7115 *timeout
, /* timeout attribute */
7116 *requested
, /* requested-attributes attribute */
7117 *exclude
, /* exclude-schemes attribute */
7118 *include
; /* include-schemes attribute */
7119 char command
[1024], /* cups-deviced command */
7120 options
[2048], /* Options to pass to command */
7122 /* String for requested attributes */
7124 /* String for excluded schemes */
7126 /* String for included schemes */
7129 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7135 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7137 send_http_error(con
, status
, NULL
);
7142 * Run cups-deviced command with the given options...
7145 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7146 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7147 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7149 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7150 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7153 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7155 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7158 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7160 exclude_str
[0] = '\0';
7163 url_encode_attr(include
, include_str
, sizeof(include_str
));
7165 include_str
[0] = '\0';
7167 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7168 snprintf(options
, sizeof(options
),
7169 "%d+%d+%d+%d+%s%s%s%s%s",
7170 con
->request
->request
.op
.request_id
,
7171 limit
? limit
->values
[0].integer
: 0,
7172 timeout
? timeout
->values
[0].integer
: 15,
7175 exclude_str
[0] ? "%20" : "", exclude_str
,
7176 include_str
[0] ? "%20" : "", include_str
);
7178 if (cupsdSendCommand(con
, command
, options
, 1))
7181 * Command started successfully, don't send an IPP response here...
7184 ippDelete(con
->response
);
7185 con
->response
= NULL
;
7190 * Command failed, return "internal error" so the user knows something
7194 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7195 _("cups-deviced failed to execute."));
7201 * 'get_document()' - Get a copy of a job file.
7205 get_document(cupsd_client_t
*con
, /* I - Client connection */
7206 ipp_attribute_t
*uri
) /* I - Job URI */
7208 http_status_t status
; /* Policy status */
7209 ipp_attribute_t
*attr
; /* Current attribute */
7210 int jobid
; /* Job ID */
7211 int docnum
; /* Document number */
7212 cupsd_job_t
*job
; /* Current job */
7213 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7214 username
[HTTP_MAX_URI
], /* Username portion of URI */
7215 host
[HTTP_MAX_URI
], /* Host portion of URI */
7216 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7217 int port
; /* Port portion of URI */
7218 char filename
[1024], /* Filename for document */
7219 format
[1024]; /* Format for document */
7222 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7223 con
->http
.fd
, uri
->values
[0].string
.text
);
7226 * See if we have a job URI or a printer URI...
7229 if (!strcmp(uri
->name
, "printer-uri"))
7232 * Got a printer URI; see if we also have a job-id attribute...
7235 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7236 IPP_TAG_INTEGER
)) == NULL
)
7238 send_ipp_status(con
, IPP_BAD_REQUEST
,
7239 _("Got a printer-uri attribute but no job-id."));
7243 jobid
= attr
->values
[0].integer
;
7248 * Got a job URI; parse it to get the job ID...
7251 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7252 sizeof(scheme
), username
, sizeof(username
), host
,
7253 sizeof(host
), &port
, resource
, sizeof(resource
));
7255 if (strncmp(resource
, "/jobs/", 6))
7261 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7262 uri
->values
[0].string
.text
);
7266 jobid
= atoi(resource
+ 6);
7270 * See if the job exists...
7273 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7276 * Nope - return a "not found" error...
7279 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7287 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7288 job
->username
)) != HTTP_OK
)
7290 send_http_error(con
, status
, NULL
);
7295 * Get the document number...
7298 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7299 IPP_TAG_INTEGER
)) == NULL
)
7301 send_ipp_status(con
, IPP_BAD_REQUEST
,
7302 _("Missing document-number attribute."));
7306 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7307 attr
->num_values
> 1)
7309 send_ipp_status(con
, IPP_NOT_FOUND
,
7310 _("Document #%d does not exist in job #%d."), docnum
,
7315 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7317 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7319 cupsdLogMessage(CUPSD_LOG_ERROR
,
7320 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7322 send_ipp_status(con
, IPP_NOT_FOUND
,
7323 _("Unable to open document #%d in job #%d."), docnum
,
7328 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7332 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7333 job
->filetypes
[docnum
- 1]->type
);
7335 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7337 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7339 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7340 IPP_TAG_NAME
)) != NULL
)
7341 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7342 NULL
, attr
->values
[0].string
.text
);
7347 * 'get_job_attrs()' - Get job attributes.
7351 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7352 ipp_attribute_t
*uri
) /* I - Job URI */
7354 http_status_t status
; /* Policy status */
7355 ipp_attribute_t
*attr
; /* Current attribute */
7356 int jobid
; /* Job ID */
7357 cupsd_job_t
*job
; /* Current job */
7358 cupsd_printer_t
*printer
; /* Current printer */
7359 cupsd_policy_t
*policy
; /* Current security policy */
7360 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7361 username
[HTTP_MAX_URI
], /* Username portion of URI */
7362 host
[HTTP_MAX_URI
], /* Host portion of URI */
7363 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7364 int port
; /* Port portion of URI */
7365 cups_array_t
*ra
, /* Requested attributes array */
7366 *exclude
; /* Private attributes array */
7369 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7370 con
->http
.fd
, uri
->values
[0].string
.text
);
7373 * See if we have a job URI or a printer URI...
7376 if (!strcmp(uri
->name
, "printer-uri"))
7379 * Got a printer URI; see if we also have a job-id attribute...
7382 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7383 IPP_TAG_INTEGER
)) == NULL
)
7385 send_ipp_status(con
, IPP_BAD_REQUEST
,
7386 _("Got a printer-uri attribute but no job-id."));
7390 jobid
= attr
->values
[0].integer
;
7395 * Got a job URI; parse it to get the job ID...
7398 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7399 sizeof(scheme
), username
, sizeof(username
), host
,
7400 sizeof(host
), &port
, resource
, sizeof(resource
));
7402 if (strncmp(resource
, "/jobs/", 6))
7408 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7409 uri
->values
[0].string
.text
);
7413 jobid
= atoi(resource
+ 6);
7417 * See if the job exists...
7420 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7423 * Nope - return a "not found" error...
7426 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7434 if ((printer
= job
->printer
) == NULL
)
7435 printer
= cupsdFindDest(job
->dest
);
7438 policy
= printer
->op_policy_ptr
;
7440 policy
= DefaultPolicyPtr
;
7442 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7444 send_http_error(con
, status
, NULL
);
7448 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7451 * Copy attributes...
7456 ra
= create_requested_array(con
->request
);
7457 copy_job_attrs(con
, job
, ra
, exclude
);
7458 cupsArrayDelete(ra
);
7460 con
->response
->request
.status
.status_code
= IPP_OK
;
7465 * 'get_jobs()' - Get a list of jobs for the specified printer.
7469 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7470 ipp_attribute_t
*uri
) /* I - Printer URI */
7472 http_status_t status
; /* Policy status */
7473 ipp_attribute_t
*attr
; /* Current attribute */
7474 const char *dest
; /* Destination */
7475 cups_ptype_t dtype
; /* Destination type (printer/class) */
7476 cups_ptype_t dmask
; /* Destination type mask */
7477 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7478 username
[HTTP_MAX_URI
], /* Username portion of URI */
7479 host
[HTTP_MAX_URI
], /* Host portion of URI */
7480 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7481 int port
; /* Port portion of URI */
7482 int job_comparison
; /* Job comparison */
7483 ipp_jstate_t job_state
; /* job-state value */
7484 int first_job_id
; /* First job ID */
7485 int limit
; /* Maximum number of jobs to return */
7486 int count
; /* Number of jobs that match */
7487 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7488 cupsd_job_t
*job
; /* Current job pointer */
7489 cupsd_printer_t
*printer
; /* Printer */
7490 cups_array_t
*list
; /* Which job list... */
7491 cups_array_t
*ra
, /* Requested attributes array */
7492 *exclude
; /* Private attributes array */
7493 cupsd_policy_t
*policy
; /* Current policy */
7496 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7497 uri
->values
[0].string
.text
);
7500 * Is the destination valid?
7503 if (strcmp(uri
->name
, "printer-uri"))
7505 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7509 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7510 sizeof(scheme
), username
, sizeof(username
), host
,
7511 sizeof(host
), &port
, resource
, sizeof(resource
));
7513 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7516 dtype
= (cups_ptype_t
)0;
7517 dmask
= (cups_ptype_t
)0;
7520 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7523 dtype
= (cups_ptype_t
)0;
7524 dmask
= CUPS_PRINTER_CLASS
;
7527 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7530 dtype
= CUPS_PRINTER_CLASS
;
7531 dmask
= CUPS_PRINTER_CLASS
;
7534 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7541 send_ipp_status(con
, IPP_NOT_FOUND
,
7542 _("The printer or class does not exist."));
7547 dtype
&= CUPS_PRINTER_CLASS
;
7548 dmask
= CUPS_PRINTER_CLASS
;
7556 policy
= printer
->op_policy_ptr
;
7558 policy
= DefaultPolicyPtr
;
7560 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7562 send_http_error(con
, status
, NULL
);
7566 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7569 * See if the "which-jobs" attribute have been specified...
7572 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7573 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7575 send_ipp_status(con
, IPP_CONFLICT
,
7576 _("The %s attribute cannot be provided with job-ids."),
7580 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7582 job_comparison
= -1;
7583 job_state
= IPP_JOB_STOPPED
;
7586 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7589 job_state
= IPP_JOB_CANCELED
;
7592 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7595 job_state
= IPP_JOB_ABORTED
;
7598 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7601 job_state
= IPP_JOB_PENDING
;
7604 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7607 job_state
= IPP_JOB_CANCELED
;
7610 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7613 job_state
= IPP_JOB_PENDING
;
7616 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7619 job_state
= IPP_JOB_HELD
;
7622 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7625 job_state
= IPP_JOB_PROCESSING
;
7626 list
= PrintingJobs
;
7628 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7631 job_state
= IPP_JOB_STOPPED
;
7636 send_ipp_status(con
, IPP_ATTRIBUTES
,
7637 _("The which-jobs value \"%s\" is not supported."),
7638 attr
->values
[0].string
.text
);
7639 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7640 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7645 * See if they want to limit the number of jobs reported...
7648 if ((attr
= ippFindAttribute(con
->request
, "limit",
7649 IPP_TAG_INTEGER
)) != NULL
)
7653 send_ipp_status(con
, IPP_CONFLICT
,
7654 _("The %s attribute cannot be provided with job-ids."),
7659 limit
= attr
->values
[0].integer
;
7664 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7665 IPP_TAG_INTEGER
)) != NULL
)
7669 send_ipp_status(con
, IPP_CONFLICT
,
7670 _("The %s attribute cannot be provided with job-ids."),
7675 first_job_id
= attr
->values
[0].integer
;
7681 * See if we only want to see jobs for a specific user...
7684 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7685 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7687 send_ipp_status(con
, IPP_CONFLICT
,
7688 _("The %s attribute cannot be provided with job-ids."),
7692 else if (attr
&& attr
->values
[0].boolean
)
7693 strlcpy(username
, get_username(con
), sizeof(username
));
7697 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7698 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7701 * IPP conformance - Get-Jobs has a default requested-attributes value of
7702 * "job-id" and "job-uri".
7705 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7706 cupsArrayAdd(ra
, "job-id");
7707 cupsArrayAdd(ra
, "job-uri");
7711 * OK, build a list of jobs for this printer...
7716 int i
; /* Looping var */
7718 for (i
= 0; i
< job_ids
->num_values
; i
++)
7720 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7724 if (i
< job_ids
->num_values
)
7726 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7727 job_ids
->values
[i
].integer
);
7731 for (i
= 0; i
< job_ids
->num_values
; i
++)
7733 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7739 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7745 ippAddSeparator(con
->response
);
7747 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7748 job
->printer
->op_policy_ptr
:
7749 policy
, con
, job
->printer
,
7752 copy_job_attrs(con
, job
, ra
, exclude
);
7757 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7758 (limit
<= 0 || count
< limit
) && job
;
7759 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7762 * Filter out jobs that don't match...
7765 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7766 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7767 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7768 job
->username
, job
->state_value
, job
->attrs
);
7770 if (!job
->dest
|| !job
->username
)
7773 if (!job
->dest
|| !job
->username
)
7776 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7777 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7779 if ((job
->dtype
& dmask
) != dtype
&&
7780 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7783 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7784 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7785 (job_comparison
> 0 && job
->state_value
< job_state
))
7788 if (job
->id
< first_job_id
)
7795 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7800 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
7804 ippAddSeparator(con
->response
);
7808 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7809 job
->printer
->op_policy_ptr
:
7810 policy
, con
, job
->printer
,
7813 copy_job_attrs(con
, job
, ra
, exclude
);
7816 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7819 cupsArrayDelete(ra
);
7821 con
->response
->request
.status
.status_code
= IPP_OK
;
7826 * 'get_notifications()' - Get events for a subscription.
7830 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7832 int i
, j
; /* Looping vars */
7833 http_status_t status
; /* Policy status */
7834 cupsd_subscription_t
*sub
; /* Subscription */
7835 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7836 *sequences
; /* notify-sequence-numbers */
7837 int min_seq
; /* Minimum sequence number */
7838 int interval
; /* Poll interval */
7841 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7845 * Get subscription attributes...
7848 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7850 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7855 send_ipp_status(con
, IPP_BAD_REQUEST
,
7856 _("Missing notify-subscription-ids attribute."));
7861 * Are the subscription IDs valid?
7864 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7866 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7869 * Bad subscription ID...
7872 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7873 ids
->values
[i
].integer
);
7881 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7883 con
, sub
->owner
)) != HTTP_OK
)
7885 send_http_error(con
, status
, sub
->dest
);
7890 * Check the subscription type and update the interval accordingly.
7893 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7896 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7898 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7904 * Tell the client to poll again in N seconds...
7908 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7909 "notify-get-interval", interval
);
7911 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7912 "printer-up-time", time(NULL
));
7915 * Copy the subscription event attributes to the response.
7918 con
->response
->request
.status
.status_code
=
7919 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7921 for (i
= 0; i
< ids
->num_values
; i
++)
7924 * Get the subscription and sequence number...
7927 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7929 if (sequences
&& i
< sequences
->num_values
)
7930 min_seq
= sequences
->values
[i
].integer
;
7935 * If we don't have any new events, nothing to do here...
7938 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7942 * Otherwise copy all of the new events...
7945 if (sub
->first_event_id
> min_seq
)
7948 j
= min_seq
- sub
->first_event_id
;
7950 for (; j
< cupsArrayCount(sub
->events
); j
++)
7952 ippAddSeparator(con
->response
);
7954 copy_attrs(con
->response
,
7955 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7956 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7963 * 'get_ppd()' - Get a named PPD from the local system.
7967 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7968 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7970 http_status_t status
; /* Policy status */
7971 cupsd_printer_t
*dest
; /* Destination */
7972 cups_ptype_t dtype
; /* Destination type */
7975 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7976 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7978 if (!strcmp(uri
->name
, "ppd-name"))
7981 * Return a PPD file from cups-driverd...
7984 char command
[1024], /* cups-driverd command */
7985 options
[1024], /* Options to pass to command */
7986 ppd_name
[1024]; /* ppd-name */
7993 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7995 send_http_error(con
, status
, NULL
);
8000 * Run cups-driverd command with the given options...
8003 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8004 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
8005 snprintf(options
, sizeof(options
), "get+%d+%s",
8006 con
->request
->request
.op
.request_id
, ppd_name
);
8008 if (cupsdSendCommand(con
, command
, options
, 0))
8011 * Command started successfully, don't send an IPP response here...
8014 ippDelete(con
->response
);
8015 con
->response
= NULL
;
8020 * Command failed, return "internal error" so the user knows something
8024 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8025 _("cups-driverd failed to execute."));
8028 else if (!strcmp(uri
->name
, "printer-uri") &&
8029 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8031 int i
; /* Looping var */
8032 char filename
[1024]; /* PPD filename */
8039 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8041 send_http_error(con
, status
, dest
);
8046 * See if we need the PPD for a class or remote printer...
8049 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8052 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8054 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8055 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8056 "printer-uri", NULL
, dest
->uri
);
8059 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8061 for (i
= 0; i
< dest
->num_printers
; i
++)
8062 if (!(dest
->printers
[i
]->type
&
8063 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8065 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8066 dest
->printers
[i
]->name
);
8068 if (!access(filename
, 0))
8072 if (i
< dest
->num_printers
)
8073 dest
= dest
->printers
[i
];
8076 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8077 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8078 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8084 * Found the printer with the PPD file, now see if there is one...
8087 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8089 send_ipp_status(con
, IPP_NOT_FOUND
,
8090 _("The PPD file \"%s\" could not be opened: %s"),
8091 uri
->values
[0].string
.text
, strerror(errno
));
8095 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8099 con
->response
->request
.status
.status_code
= IPP_OK
;
8102 send_ipp_status(con
, IPP_NOT_FOUND
,
8103 _("The PPD file \"%s\" could not be found."),
8104 uri
->values
[0].string
.text
);
8109 * 'get_ppds()' - Get the list of PPD files on the local system.
8113 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8115 http_status_t status
; /* Policy status */
8116 ipp_attribute_t
*limit
, /* Limit attribute */
8117 *device
, /* ppd-device-id attribute */
8118 *language
, /* ppd-natural-language attribute */
8119 *make
, /* ppd-make attribute */
8120 *model
, /* ppd-make-and-model attribute */
8121 *model_number
, /* ppd-model-number attribute */
8122 *product
, /* ppd-product attribute */
8123 *psversion
, /* ppd-psverion attribute */
8124 *type
, /* ppd-type attribute */
8125 *requested
, /* requested-attributes attribute */
8126 *exclude
, /* exclude-schemes attribute */
8127 *include
; /* include-schemes attribute */
8128 char command
[1024], /* cups-driverd command */
8129 options
[4096], /* Options to pass to command */
8130 device_str
[256],/* Escaped ppd-device-id string */
8132 /* Escaped ppd-natural-language */
8133 make_str
[256], /* Escaped ppd-make string */
8134 model_str
[256], /* Escaped ppd-make-and-model string */
8135 model_number_str
[256],
8136 /* ppd-model-number string */
8138 /* Escaped ppd-product string */
8140 /* Escaped ppd-psversion string */
8141 type_str
[256], /* Escaped ppd-type string */
8143 /* String for requested attributes */
8145 /* String for excluded schemes */
8147 /* String for included schemes */
8150 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8156 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8158 send_http_error(con
, status
, NULL
);
8163 * Run cups-driverd command with the given options...
8166 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8167 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8168 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8170 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8171 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8173 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8175 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8176 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8177 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8178 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8180 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8182 include
= ippFindAttribute(con
->request
, "include-schemes",
8186 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8188 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8191 url_encode_attr(device
, device_str
, sizeof(device_str
));
8193 device_str
[0] = '\0';
8196 url_encode_attr(language
, language_str
, sizeof(language_str
));
8198 language_str
[0] = '\0';
8201 url_encode_attr(make
, make_str
, sizeof(make_str
));
8206 url_encode_attr(model
, model_str
, sizeof(model_str
));
8208 model_str
[0] = '\0';
8211 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8212 model_number
->values
[0].integer
);
8214 model_number_str
[0] = '\0';
8217 url_encode_attr(product
, product_str
, sizeof(product_str
));
8219 product_str
[0] = '\0';
8222 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8224 psversion_str
[0] = '\0';
8227 url_encode_attr(type
, type_str
, sizeof(type_str
));
8232 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8234 exclude_str
[0] = '\0';
8237 url_encode_attr(include
, include_str
, sizeof(include_str
));
8239 include_str
[0] = '\0';
8241 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8242 snprintf(options
, sizeof(options
),
8243 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8244 con
->request
->request
.op
.request_id
,
8245 limit
? limit
->values
[0].integer
: 0,
8247 device
? "%20" : "", device_str
,
8248 language
? "%20" : "", language_str
,
8249 make
? "%20" : "", make_str
,
8250 model
? "%20" : "", model_str
,
8251 model_number
? "%20" : "", model_number_str
,
8252 product
? "%20" : "", product_str
,
8253 psversion
? "%20" : "", psversion_str
,
8254 type
? "%20" : "", type_str
,
8255 exclude_str
[0] ? "%20" : "", exclude_str
,
8256 include_str
[0] ? "%20" : "", include_str
);
8258 if (cupsdSendCommand(con
, command
, options
, 0))
8261 * Command started successfully, don't send an IPP response here...
8264 ippDelete(con
->response
);
8265 con
->response
= NULL
;
8270 * Command failed, return "internal error" so the user knows something
8274 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8275 _("cups-driverd failed to execute."));
8281 * 'get_printer_attrs()' - Get printer attributes.
8285 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8286 ipp_attribute_t
*uri
) /* I - Printer URI */
8288 http_status_t status
; /* Policy status */
8289 cups_ptype_t dtype
; /* Destination type (printer/class) */
8290 cupsd_printer_t
*printer
; /* Printer/class */
8291 cups_array_t
*ra
; /* Requested attributes array */
8294 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8295 con
->http
.fd
, uri
->values
[0].string
.text
);
8298 * Is the destination valid?
8301 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8307 send_ipp_status(con
, IPP_NOT_FOUND
,
8308 _("The printer or class does not exist."));
8316 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8318 send_http_error(con
, status
, printer
);
8323 * Send the attributes...
8326 ra
= create_requested_array(con
->request
);
8328 copy_printer_attrs(con
, printer
, ra
);
8330 cupsArrayDelete(ra
);
8332 con
->response
->request
.status
.status_code
= IPP_OK
;
8337 * 'get_printer_supported()' - Get printer supported values.
8341 get_printer_supported(
8342 cupsd_client_t
*con
, /* I - Client connection */
8343 ipp_attribute_t
*uri
) /* I - Printer URI */
8345 http_status_t status
; /* Policy status */
8346 cups_ptype_t dtype
; /* Destination type (printer/class) */
8347 cupsd_printer_t
*printer
; /* Printer/class */
8350 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8351 con
->http
.fd
, uri
->values
[0].string
.text
);
8354 * Is the destination valid?
8357 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8363 send_ipp_status(con
, IPP_NOT_FOUND
,
8364 _("The printer or class does not exist."));
8372 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8374 send_http_error(con
, status
, printer
);
8379 * Return a list of attributes that can be set via Set-Printer-Attributes.
8382 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8384 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8385 "printer-location", 0);
8387 con
->response
->request
.status
.status_code
= IPP_OK
;
8392 * 'get_printers()' - Get a list of printers or classes.
8396 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8397 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8399 http_status_t status
; /* Policy status */
8400 ipp_attribute_t
*attr
; /* Current attribute */
8401 int limit
; /* Max number of printers to return */
8402 int count
; /* Number of printers that match */
8403 cupsd_printer_t
*printer
; /* Current printer pointer */
8404 int printer_type
, /* printer-type attribute */
8405 printer_mask
; /* printer-type-mask attribute */
8406 char *location
; /* Location string */
8407 const char *username
; /* Current user */
8408 char *first_printer_name
; /* first-printer-name attribute */
8409 cups_array_t
*ra
; /* Requested attributes array */
8410 int local
; /* Local connection? */
8413 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8414 con
->http
.fd
, type
);
8420 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8422 send_http_error(con
, status
, NULL
);
8427 * Check for printers...
8430 if (!Printers
|| !cupsArrayCount(Printers
))
8432 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8437 * See if they want to limit the number of printers reported...
8440 if ((attr
= ippFindAttribute(con
->request
, "limit",
8441 IPP_TAG_INTEGER
)) != NULL
)
8442 limit
= attr
->values
[0].integer
;
8446 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8447 IPP_TAG_NAME
)) != NULL
)
8448 first_printer_name
= attr
->values
[0].string
.text
;
8450 first_printer_name
= NULL
;
8453 * Support filtering...
8456 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8457 IPP_TAG_ENUM
)) != NULL
)
8458 printer_type
= attr
->values
[0].integer
;
8462 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8463 IPP_TAG_ENUM
)) != NULL
)
8464 printer_mask
= attr
->values
[0].integer
;
8468 local
= httpAddrLocalhost(&(con
->clientaddr
));
8470 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8471 IPP_TAG_TEXT
)) != NULL
)
8472 location
= attr
->values
[0].string
.text
;
8476 if (con
->username
[0])
8477 username
= con
->username
;
8478 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8479 IPP_TAG_NAME
)) != NULL
)
8480 username
= attr
->values
[0].string
.text
;
8484 ra
= create_requested_array(con
->request
);
8487 * OK, build a list of printers for this printer...
8490 if (first_printer_name
)
8492 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8493 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8496 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8499 count
< limit
&& printer
;
8500 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8502 if (!local
&& !printer
->shared
)
8505 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8506 (printer
->type
& printer_mask
) == printer_type
&&
8508 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
8511 * If HideImplicitMembers is enabled, see if this printer or class
8512 * is a member of an implicit class...
8515 if (ImplicitClasses
&& HideImplicitMembers
&&
8516 printer
->in_implicit_class
)
8520 * If a username is specified, see if it is allowed or denied
8524 if (cupsArrayCount(printer
->users
) && username
&&
8525 !user_allowed(printer
, username
))
8529 * Add the group separator as needed...
8533 ippAddSeparator(con
->response
);
8538 * Send the attributes...
8541 copy_printer_attrs(con
, printer
, ra
);
8545 cupsArrayDelete(ra
);
8547 con
->response
->request
.status
.status_code
= IPP_OK
;
8552 * 'get_subscription_attrs()' - Get subscription attributes.
8556 get_subscription_attrs(
8557 cupsd_client_t
*con
, /* I - Client connection */
8558 int sub_id
) /* I - Subscription ID */
8560 http_status_t status
; /* Policy status */
8561 cupsd_subscription_t
*sub
; /* Subscription */
8562 cupsd_policy_t
*policy
; /* Current security policy */
8563 cups_array_t
*ra
, /* Requested attributes array */
8564 *exclude
; /* Private attributes array */
8567 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8568 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8569 con
, con
->http
.fd
, sub_id
);
8572 * Is the subscription ID valid?
8575 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8578 * Bad subscription ID...
8581 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8591 policy
= sub
->dest
->op_policy_ptr
;
8593 policy
= DefaultPolicyPtr
;
8595 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8597 send_http_error(con
, status
, sub
->dest
);
8601 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8604 * Copy the subscription attributes to the response using the
8605 * requested-attributes attribute that may be provided by the client.
8608 ra
= create_requested_array(con
->request
);
8610 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8612 cupsArrayDelete(ra
);
8614 con
->response
->request
.status
.status_code
= IPP_OK
;
8619 * 'get_subscriptions()' - Get subscriptions.
8623 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8624 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8626 http_status_t status
; /* Policy status */
8627 int count
; /* Number of subscriptions */
8628 int limit
; /* Limit */
8629 cupsd_subscription_t
*sub
; /* Subscription */
8630 cups_array_t
*ra
; /* Requested attributes array */
8631 ipp_attribute_t
*attr
; /* Attribute */
8632 cups_ptype_t dtype
; /* Destination type (printer/class) */
8633 char scheme
[HTTP_MAX_URI
],
8634 /* Scheme portion of URI */
8635 username
[HTTP_MAX_URI
],
8636 /* Username portion of URI */
8638 /* Host portion of URI */
8639 resource
[HTTP_MAX_URI
];
8640 /* Resource portion of URI */
8641 int port
; /* Port portion of URI */
8642 cupsd_job_t
*job
; /* Job pointer */
8643 cupsd_printer_t
*printer
; /* Printer */
8644 cupsd_policy_t
*policy
; /* Policy */
8645 cups_array_t
*exclude
; /* Private attributes array */
8648 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8649 "get_subscriptions(con=%p[%d], uri=%s)",
8650 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8653 * Is the destination valid?
8656 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8657 sizeof(scheme
), username
, sizeof(username
), host
,
8658 sizeof(host
), &port
, resource
, sizeof(resource
));
8660 if (!strcmp(resource
, "/") ||
8661 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8662 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8663 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8668 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8671 job
= cupsdFindJob(atoi(resource
+ 6));
8675 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8676 atoi(resource
+ 6));
8680 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8686 send_ipp_status(con
, IPP_NOT_FOUND
,
8687 _("The printer or class does not exist."));
8690 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8691 IPP_TAG_INTEGER
)) != NULL
)
8693 job
= cupsdFindJob(attr
->values
[0].integer
);
8697 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8698 attr
->values
[0].integer
);
8710 policy
= printer
->op_policy_ptr
;
8712 policy
= DefaultPolicyPtr
;
8714 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8716 send_http_error(con
, status
, printer
);
8721 * Copy the subscription attributes to the response using the
8722 * requested-attributes attribute that may be provided by the client.
8725 ra
= create_requested_array(con
->request
);
8727 if ((attr
= ippFindAttribute(con
->request
, "limit",
8728 IPP_TAG_INTEGER
)) != NULL
)
8729 limit
= attr
->values
[0].integer
;
8734 * See if we only want to see subscriptions for a specific user...
8737 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8738 IPP_TAG_BOOLEAN
)) != NULL
&&
8739 attr
->values
[0].boolean
)
8740 strlcpy(username
, get_username(con
), sizeof(username
));
8744 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8746 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8747 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8748 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
8750 ippAddSeparator(con
->response
);
8752 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8753 policy
, con
, sub
->dest
,
8756 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8759 if (limit
&& count
>= limit
)
8763 cupsArrayDelete(ra
);
8766 con
->response
->request
.status
.status_code
= IPP_OK
;
8768 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8773 * 'get_username()' - Get the username associated with a request.
8776 static const char * /* O - Username */
8777 get_username(cupsd_client_t
*con
) /* I - Connection */
8779 ipp_attribute_t
*attr
; /* Attribute */
8782 if (con
->username
[0])
8783 return (con
->username
);
8784 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8785 IPP_TAG_NAME
)) != NULL
)
8786 return (attr
->values
[0].string
.text
);
8788 return ("anonymous");
8793 * 'hold_job()' - Hold a print job.
8797 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8798 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8800 ipp_attribute_t
*attr
; /* Current job-hold-until */
8801 const char *when
; /* New value */
8802 int jobid
; /* Job ID */
8803 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8804 username
[HTTP_MAX_URI
], /* Username portion of URI */
8805 host
[HTTP_MAX_URI
], /* Host portion of URI */
8806 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8807 int port
; /* Port portion of URI */
8808 cupsd_job_t
*job
; /* Job information */
8811 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8812 uri
->values
[0].string
.text
);
8815 * See if we have a job URI or a printer URI...
8818 if (!strcmp(uri
->name
, "printer-uri"))
8821 * Got a printer URI; see if we also have a job-id attribute...
8824 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8825 IPP_TAG_INTEGER
)) == NULL
)
8827 send_ipp_status(con
, IPP_BAD_REQUEST
,
8828 _("Got a printer-uri attribute but no job-id."));
8832 jobid
= attr
->values
[0].integer
;
8837 * Got a job URI; parse it to get the job ID...
8840 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8841 sizeof(scheme
), username
, sizeof(username
), host
,
8842 sizeof(host
), &port
, resource
, sizeof(resource
));
8844 if (strncmp(resource
, "/jobs/", 6))
8850 send_ipp_status(con
, IPP_BAD_REQUEST
,
8851 _("Bad job-uri \"%s\"."),
8852 uri
->values
[0].string
.text
);
8856 jobid
= atoi(resource
+ 6);
8860 * See if the job exists...
8863 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8866 * Nope - return a "not found" error...
8869 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8874 * See if the job is owned by the requesting user...
8877 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8879 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8880 cupsdFindDest(job
->dest
));
8885 * See if the job is in a state that allows holding...
8888 if (job
->state_value
> IPP_JOB_STOPPED
)
8891 * Return a "not-possible" error...
8894 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8895 _("Job #%d is finished and cannot be altered."),
8901 * Hold the job and return...
8904 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8905 IPP_TAG_KEYWORD
)) == NULL
)
8906 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8910 when
= attr
->values
[0].string
.text
;
8912 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8913 "Job job-hold-until value changed by user.");
8916 when
= "indefinite";
8918 cupsdSetJobHoldUntil(job
, when
, 1);
8919 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8922 con
->response
->request
.status
.status_code
= IPP_OK
;
8927 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8931 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8932 ipp_attribute_t
*uri
) /* I - Printer URI */
8934 http_status_t status
; /* Policy status */
8935 cups_ptype_t dtype
; /* Destination type (printer/class) */
8936 cupsd_printer_t
*printer
; /* Printer data */
8939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8940 con
->http
.fd
, uri
->values
[0].string
.text
);
8943 * Is the destination valid?
8946 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8952 send_ipp_status(con
, IPP_NOT_FOUND
,
8953 _("The printer or class does not exist."));
8961 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8963 send_http_error(con
, status
, printer
);
8968 * Hold pending/new jobs sent to the printer...
8971 printer
->holding_new_jobs
= 1;
8973 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8975 if (dtype
& CUPS_PRINTER_CLASS
)
8976 cupsdLogMessage(CUPSD_LOG_INFO
,
8977 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8978 printer
->name
, get_username(con
));
8980 cupsdLogMessage(CUPSD_LOG_INFO
,
8981 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8982 printer
->name
, get_username(con
));
8985 * Everything was ok, so return OK status...
8988 con
->response
->request
.status
.status_code
= IPP_OK
;
8993 * 'move_job()' - Move a job to a new destination.
8997 move_job(cupsd_client_t
*con
, /* I - Client connection */
8998 ipp_attribute_t
*uri
) /* I - Job URI */
9000 http_status_t status
; /* Policy status */
9001 ipp_attribute_t
*attr
; /* Current attribute */
9002 int jobid
; /* Job ID */
9003 cupsd_job_t
*job
; /* Current job */
9004 const char *src
; /* Source printer/class */
9005 cups_ptype_t stype
, /* Source type (printer or class) */
9006 dtype
; /* Destination type (printer/class) */
9007 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
9008 username
[HTTP_MAX_URI
], /* Username portion of URI */
9009 host
[HTTP_MAX_URI
], /* Host portion of URI */
9010 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9011 int port
; /* Port portion of URI */
9012 cupsd_printer_t
*sprinter
, /* Source printer */
9013 *dprinter
; /* Destination printer */
9016 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
9017 uri
->values
[0].string
.text
);
9020 * Get the new printer or class...
9023 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
9024 IPP_TAG_URI
)) == NULL
)
9027 * Need job-printer-uri...
9030 send_ipp_status(con
, IPP_BAD_REQUEST
,
9031 _("job-printer-uri attribute missing."));
9035 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9041 send_ipp_status(con
, IPP_NOT_FOUND
,
9042 _("The printer or class does not exist."));
9047 * See if we have a job URI or a printer URI...
9050 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9051 sizeof(scheme
), username
, sizeof(username
), host
,
9052 sizeof(host
), &port
, resource
, sizeof(resource
));
9054 if (!strcmp(uri
->name
, "printer-uri"))
9057 * Got a printer URI; see if we also have a job-id attribute...
9060 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9061 IPP_TAG_INTEGER
)) == NULL
)
9067 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9068 &sprinter
)) == NULL
)
9074 send_ipp_status(con
, IPP_NOT_FOUND
,
9075 _("The printer or class does not exist."));
9084 * Otherwise, just move a single job...
9087 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9090 * Nope - return a "not found" error...
9093 send_ipp_status(con
, IPP_NOT_FOUND
,
9094 _("Job #%d does not exist."), attr
->values
[0].integer
);
9100 * Job found, initialize source pointers...
9111 * Got a job URI; parse it to get the job ID...
9114 if (strncmp(resource
, "/jobs/", 6))
9120 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9121 uri
->values
[0].string
.text
);
9126 * See if the job exists...
9129 jobid
= atoi(resource
+ 6);
9131 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9134 * Nope - return a "not found" error...
9137 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9143 * Job found, initialize source pointers...
9152 * Check the policy of the destination printer...
9155 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9156 job
? job
->username
: NULL
)) != HTTP_OK
)
9158 send_http_error(con
, status
, dprinter
);
9163 * Now move the job or jobs...
9169 * See if the job has been completed...
9172 if (job
->state_value
> IPP_JOB_STOPPED
)
9175 * Return a "not-possible" error...
9178 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9179 _("Job #%d is finished and cannot be altered."),
9185 * See if the job is owned by the requesting user...
9188 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9190 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9191 cupsdFindDest(job
->dest
));
9196 * Move the job to a different printer or class...
9199 cupsdMoveJob(job
, dprinter
);
9204 * Got the source printer, now look through the jobs...
9207 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9209 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9212 * See if the job is pointing at the source printer or has not been
9216 if (_cups_strcasecmp(job
->dest
, src
) ||
9217 job
->state_value
> IPP_JOB_STOPPED
)
9221 * See if the job can be moved by the requesting user...
9224 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9228 * Move the job to a different printer or class...
9231 cupsdMoveJob(job
, dprinter
);
9236 * Start jobs if possible...
9242 * Return with "everything is OK" status...
9245 con
->response
->request
.status
.status_code
= IPP_OK
;
9250 * 'ppd_parse_line()' - Parse a PPD default line.
9253 static int /* O - 0 on success, -1 on failure */
9254 ppd_parse_line(const char *line
, /* I - Line */
9255 char *option
, /* O - Option name */
9256 int olen
, /* I - Size of option name */
9257 char *choice
, /* O - Choice name */
9258 int clen
) /* I - Size of choice name */
9261 * Verify this is a default option line...
9264 if (strncmp(line
, "*Default", 8))
9268 * Read the option name...
9271 for (line
+= 8, olen
--;
9272 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9283 * Skip everything else up to the colon (:)...
9286 while (*line
&& *line
!= ':')
9295 * Now grab the option choice, skipping leading whitespace...
9298 while (isspace(*line
& 255))
9302 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9313 * Return with no errors...
9321 * 'print_job()' - Print a file to a printer or class.
9325 print_job(cupsd_client_t
*con
, /* I - Client connection */
9326 ipp_attribute_t
*uri
) /* I - Printer URI */
9328 ipp_attribute_t
*attr
; /* Current attribute */
9329 ipp_attribute_t
*format
; /* Document-format attribute */
9330 const char *default_format
; /* document-format-default value */
9331 cupsd_job_t
*job
; /* New job */
9332 char filename
[1024]; /* Job filename */
9333 mime_type_t
*filetype
; /* Type of file */
9334 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9335 type
[MIME_MAX_TYPE
], /* Subtype of file */
9336 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9337 /* Textual name of mime type */
9338 cupsd_printer_t
*printer
; /* Printer data */
9339 struct stat fileinfo
; /* File information */
9340 int kbytes
; /* Size of file */
9341 int compression
; /* Document compression */
9344 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9345 uri
->values
[0].string
.text
);
9348 * Validate print file attributes, for now just document-format and
9349 * compression (CUPS only supports "none" and "gzip")...
9352 compression
= CUPS_FILE_NONE
;
9354 if ((attr
= ippFindAttribute(con
->request
, "compression",
9355 IPP_TAG_KEYWORD
)) != NULL
)
9357 if (strcmp(attr
->values
[0].string
.text
, "none")
9359 && strcmp(attr
->values
[0].string
.text
, "gzip")
9360 #endif /* HAVE_LIBZ */
9363 send_ipp_status(con
, IPP_ATTRIBUTES
,
9364 _("Unsupported compression \"%s\"."),
9365 attr
->values
[0].string
.text
);
9366 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9367 "compression", NULL
, attr
->values
[0].string
.text
);
9372 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9373 compression
= CUPS_FILE_GZIP
;
9374 #endif /* HAVE_LIBZ */
9378 * Do we have a file to print?
9383 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9388 * Is the destination valid?
9391 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9397 send_ipp_status(con
, IPP_NOT_FOUND
,
9398 _("The printer or class does not exist."));
9403 * Is it a format we support?
9406 if ((format
= ippFindAttribute(con
->request
, "document-format",
9407 IPP_TAG_MIMETYPE
)) != NULL
)
9410 * Grab format from client...
9413 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9416 send_ipp_status(con
, IPP_BAD_REQUEST
,
9417 _("Bad document-format \"%s\"."),
9418 format
->values
[0].string
.text
);
9422 else if ((default_format
= cupsGetOption("document-format",
9423 printer
->num_options
,
9424 printer
->options
)) != NULL
)
9427 * Use default document format...
9430 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9432 send_ipp_status(con
, IPP_BAD_REQUEST
,
9433 _("Bad document-format \"%s\"."),
9444 strcpy(super
, "application");
9445 strcpy(type
, "octet-stream");
9448 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9451 * Auto-type the file...
9454 ipp_attribute_t
*doc_name
; /* document-name attribute */
9457 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9459 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9460 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9461 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9465 filetype
= mimeType(MimeDatabase
, super
, type
);
9467 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9468 filetype
->super
, filetype
->type
);
9471 filetype
= mimeType(MimeDatabase
, super
, type
);
9475 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9478 * Replace the document-format attribute value with the auto-typed or
9482 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9487 _cupsStrFree(format
->values
[0].string
.text
);
9489 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9492 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9493 "document-format", NULL
, mimetype
);
9497 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9498 _("Unsupported document-format \"%s\"."),
9499 format
? format
->values
[0].string
.text
:
9500 "application/octet-stream");
9501 cupsdLogMessage(CUPSD_LOG_INFO
,
9502 "Hint: Do you have the raw file printing rules enabled?");
9505 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9506 "document-format", NULL
, format
->values
[0].string
.text
);
9512 * Read any embedded job ticket info from PS files...
9515 if (!_cups_strcasecmp(filetype
->super
, "application") &&
9516 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
9517 !_cups_strcasecmp(filetype
->type
, "pdf")))
9518 read_job_ticket(con
);
9521 * Create the job object...
9524 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9528 * Update quota data...
9531 if (stat(con
->filename
, &fileinfo
))
9534 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9536 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9538 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9539 IPP_TAG_INTEGER
)) != NULL
)
9540 attr
->values
[0].integer
+= kbytes
;
9543 * Add the job file...
9546 if (add_file(con
, job
, filetype
, compression
))
9549 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9551 rename(con
->filename
, filename
);
9552 cupsdClearString(&con
->filename
);
9555 * See if we need to add the ending sheet...
9558 if (cupsdTimeoutJob(job
))
9562 * Log and save the job...
9565 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9566 "File of type %s/%s queued by \"%s\".",
9567 filetype
->super
, filetype
->type
, job
->username
);
9568 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9569 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9570 job
->dest
, job
->username
);
9573 * Start the job if possible...
9581 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9583 * This function only gets called when printing a single PDF or PostScript
9584 * file using the Print-Job operation. It doesn't work for Create-Job +
9585 * Send-File, since the job attributes need to be set at job creation
9586 * time for banners to work. The embedded job ticket stuff is here
9587 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9588 * options and IPP attributes which otherwise would be lost.
9590 * The format of a job ticket is simple:
9592 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9594 * %cupsJobTicket: attr1=value1
9595 * %cupsJobTicket: attr2=value2
9597 * %cupsJobTicket: attrN=valueN
9599 * Job ticket lines must appear immediately after the first line that
9600 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9601 * stops looking for job ticket info when it finds a line that does not begin
9602 * with "%cupsJobTicket:".
9604 * The maximum length of a job ticket line, including the prefix, is
9605 * 255 characters to conform with the Adobe DSC.
9607 * Read-only attributes are rejected with a notice to the error log in
9608 * case a malicious user tries anything. Since the job ticket is read
9609 * prior to attribute validation in print_job(), job ticket attributes
9610 * will go through the same validation as IPP attributes...
9614 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9616 cups_file_t
*fp
; /* File to read from */
9617 char line
[256]; /* Line data */
9618 int num_options
; /* Number of options */
9619 cups_option_t
*options
; /* Options */
9620 ipp_t
*ticket
; /* New attributes */
9621 ipp_attribute_t
*attr
, /* Current attribute */
9622 *attr2
, /* Job attribute */
9623 *prev2
; /* Previous job attribute */
9627 * First open the print file...
9630 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9632 cupsdLogMessage(CUPSD_LOG_ERROR
,
9633 "Unable to open print file for job ticket - %s",
9639 * Skip the first line...
9642 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9644 cupsdLogMessage(CUPSD_LOG_ERROR
,
9645 "Unable to read from print file for job ticket - %s",
9651 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9654 * Not a DSC-compliant file, so no job ticket info will be available...
9662 * Read job ticket info from the file...
9668 while (cupsFileGets(fp
, line
, sizeof(line
)))
9671 * Stop at the first non-ticket line...
9674 if (strncmp(line
, "%cupsJobTicket:", 15))
9678 * Add the options to the option array...
9681 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9685 * Done with the file; see if we have any options...
9690 if (num_options
== 0)
9694 * OK, convert the options to an attribute list, and apply them to
9699 cupsEncodeOptions(ticket
, num_options
, options
);
9702 * See what the user wants to change.
9705 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9707 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9710 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9711 !strcmp(attr
->name
, "job-originating-user-name") ||
9712 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9713 !strcmp(attr
->name
, "job-k-octets") ||
9714 !strcmp(attr
->name
, "job-id") ||
9715 !strncmp(attr
->name
, "job-state", 9) ||
9716 !strncmp(attr
->name
, "time-at-", 8))
9717 continue; /* Read-only attrs */
9719 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9720 IPP_TAG_ZERO
)) != NULL
)
9723 * Some other value; first free the old value...
9726 if (con
->request
->attrs
== attr2
)
9728 con
->request
->attrs
= attr2
->next
;
9733 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9734 if (prev2
->next
== attr2
)
9736 prev2
->next
= attr2
->next
;
9741 if (con
->request
->last
== attr2
)
9742 con
->request
->last
= prev2
;
9744 _ippFreeAttr(attr2
);
9748 * Add new option by copying it...
9751 copy_attribute(con
->request
, attr
, 0);
9755 * Then free the attribute list and option array...
9759 cupsFreeOptions(num_options
, options
);
9764 * 'reject_jobs()' - Reject print jobs to a printer.
9768 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9769 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9771 http_status_t status
; /* Policy status */
9772 cups_ptype_t dtype
; /* Destination type (printer/class) */
9773 cupsd_printer_t
*printer
; /* Printer data */
9774 ipp_attribute_t
*attr
; /* printer-state-message text */
9777 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9778 con
->http
.fd
, uri
->values
[0].string
.text
);
9781 * Is the destination valid?
9784 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9790 send_ipp_status(con
, IPP_NOT_FOUND
,
9791 _("The printer or class does not exist."));
9799 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9801 send_http_error(con
, status
, printer
);
9806 * Reject jobs sent to the printer...
9809 printer
->accepting
= 0;
9811 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9812 IPP_TAG_TEXT
)) == NULL
)
9813 strcpy(printer
->state_message
, "Rejecting Jobs");
9815 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9816 sizeof(printer
->state_message
));
9818 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9819 "No longer accepting jobs.");
9821 if (dtype
& CUPS_PRINTER_CLASS
)
9823 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9825 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9826 printer
->name
, get_username(con
));
9830 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9832 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9833 printer
->name
, get_username(con
));
9837 * Everything was ok, so return OK status...
9840 con
->response
->request
.status
.status_code
= IPP_OK
;
9845 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9849 release_held_new_jobs(
9850 cupsd_client_t
*con
, /* I - Connection */
9851 ipp_attribute_t
*uri
) /* I - Printer URI */
9853 http_status_t status
; /* Policy status */
9854 cups_ptype_t dtype
; /* Destination type (printer/class) */
9855 cupsd_printer_t
*printer
; /* Printer data */
9858 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9859 con
->http
.fd
, uri
->values
[0].string
.text
);
9862 * Is the destination valid?
9865 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9871 send_ipp_status(con
, IPP_NOT_FOUND
,
9872 _("The printer or class does not exist."));
9880 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9882 send_http_error(con
, status
, printer
);
9887 * Hold pending/new jobs sent to the printer...
9890 printer
->holding_new_jobs
= 0;
9892 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9894 if (dtype
& CUPS_PRINTER_CLASS
)
9895 cupsdLogMessage(CUPSD_LOG_INFO
,
9896 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9897 printer
->name
, get_username(con
));
9899 cupsdLogMessage(CUPSD_LOG_INFO
,
9900 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9901 printer
->name
, get_username(con
));
9904 * Everything was ok, so return OK status...
9907 con
->response
->request
.status
.status_code
= IPP_OK
;
9912 * 'release_job()' - Release a held print job.
9916 release_job(cupsd_client_t
*con
, /* I - Client connection */
9917 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9919 ipp_attribute_t
*attr
; /* Current attribute */
9920 int jobid
; /* Job ID */
9921 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9922 username
[HTTP_MAX_URI
], /* Username portion of URI */
9923 host
[HTTP_MAX_URI
], /* Host portion of URI */
9924 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9925 int port
; /* Port portion of URI */
9926 cupsd_job_t
*job
; /* Job information */
9929 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9930 con
->http
.fd
, uri
->values
[0].string
.text
);
9933 * See if we have a job URI or a printer URI...
9936 if (!strcmp(uri
->name
, "printer-uri"))
9939 * Got a printer URI; see if we also have a job-id attribute...
9942 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9943 IPP_TAG_INTEGER
)) == NULL
)
9945 send_ipp_status(con
, IPP_BAD_REQUEST
,
9946 _("Got a printer-uri attribute but no job-id."));
9950 jobid
= attr
->values
[0].integer
;
9955 * Got a job URI; parse it to get the job ID...
9958 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9959 sizeof(scheme
), username
, sizeof(username
), host
,
9960 sizeof(host
), &port
, resource
, sizeof(resource
));
9962 if (strncmp(resource
, "/jobs/", 6))
9968 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9969 uri
->values
[0].string
.text
);
9973 jobid
= atoi(resource
+ 6);
9977 * See if the job exists...
9980 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9983 * Nope - return a "not found" error...
9986 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9991 * See if job is "held"...
9994 if (job
->state_value
!= IPP_JOB_HELD
)
9997 * Nope - return a "not possible" error...
10000 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
10005 * See if the job is owned by the requesting user...
10008 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10010 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10011 cupsdFindDest(job
->dest
));
10016 * Reset the job-hold-until value to "no-hold"...
10019 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10020 IPP_TAG_KEYWORD
)) == NULL
)
10021 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10025 _cupsStrFree(attr
->values
[0].string
.text
);
10027 attr
->value_tag
= IPP_TAG_KEYWORD
;
10028 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10030 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10031 "Job job-hold-until value changed by user.");
10035 * Release the job and return...
10038 cupsdReleaseJob(job
);
10040 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10041 "Job released by user.");
10043 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10045 con
->response
->request
.status
.status_code
= IPP_OK
;
10052 * 'renew_subscription()' - Renew an existing subscription...
10056 renew_subscription(
10057 cupsd_client_t
*con
, /* I - Client connection */
10058 int sub_id
) /* I - Subscription ID */
10060 http_status_t status
; /* Policy status */
10061 cupsd_subscription_t
*sub
; /* Subscription */
10062 ipp_attribute_t
*lease
; /* notify-lease-duration */
10065 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10066 "renew_subscription(con=%p[%d], sub_id=%d)",
10067 con
, con
->http
.fd
, sub_id
);
10070 * Is the subscription ID valid?
10073 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10076 * Bad subscription ID...
10079 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
10087 * Job subscriptions cannot be renewed...
10090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10091 _("Job subscriptions cannot be renewed."));
10099 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10101 con
, sub
->owner
)) != HTTP_OK
)
10103 send_http_error(con
, status
, sub
->dest
);
10108 * Renew the subscription...
10111 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10114 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10116 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10118 cupsdLogMessage(CUPSD_LOG_INFO
,
10119 "renew_subscription: Limiting notify-lease-duration to "
10122 sub
->lease
= MaxLeaseDuration
;
10125 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10127 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10129 con
->response
->request
.status
.status_code
= IPP_OK
;
10131 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10132 "notify-lease-duration", sub
->lease
);
10137 * 'restart_job()' - Restart an old print job.
10141 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10142 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10144 ipp_attribute_t
*attr
; /* Current attribute */
10145 int jobid
; /* Job ID */
10146 cupsd_job_t
*job
; /* Job information */
10147 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10148 username
[HTTP_MAX_URI
], /* Username portion of URI */
10149 host
[HTTP_MAX_URI
], /* Host portion of URI */
10150 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10151 int port
; /* Port portion of URI */
10154 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10155 con
->http
.fd
, uri
->values
[0].string
.text
);
10158 * See if we have a job URI or a printer URI...
10161 if (!strcmp(uri
->name
, "printer-uri"))
10164 * Got a printer URI; see if we also have a job-id attribute...
10167 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10168 IPP_TAG_INTEGER
)) == NULL
)
10170 send_ipp_status(con
, IPP_BAD_REQUEST
,
10171 _("Got a printer-uri attribute but no job-id."));
10175 jobid
= attr
->values
[0].integer
;
10180 * Got a job URI; parse it to get the job ID...
10183 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10184 sizeof(scheme
), username
, sizeof(username
), host
,
10185 sizeof(host
), &port
, resource
, sizeof(resource
));
10187 if (strncmp(resource
, "/jobs/", 6))
10193 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10194 uri
->values
[0].string
.text
);
10198 jobid
= atoi(resource
+ 6);
10202 * See if the job exists...
10205 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10208 * Nope - return a "not found" error...
10211 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10216 * See if job is in any of the "completed" states...
10219 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10222 * Nope - return a "not possible" error...
10225 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
10231 * See if we have retained the job files...
10236 if (!job
->attrs
|| job
->num_files
== 0)
10239 * Nope - return a "not possible" error...
10242 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10243 _("Job #%d cannot be restarted - no files."), jobid
);
10248 * See if the job is owned by the requesting user...
10251 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10253 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10254 cupsdFindDest(job
->dest
));
10259 * See if the job-hold-until attribute is specified...
10262 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10263 IPP_TAG_KEYWORD
)) == NULL
)
10264 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10266 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10269 * Return the job to a held state...
10272 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10273 "Restarted by \"%s\" with job-hold-until=%s.",
10274 username
, attr
->values
[0].string
.text
);
10275 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10277 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10278 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10279 attr
->values
[0].string
.text
);
10284 * Restart the job...
10287 cupsdRestartJob(job
);
10291 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10293 con
->response
->request
.status
.status_code
= IPP_OK
;
10298 * 'save_auth_info()' - Save authentication information for a job.
10303 cupsd_client_t
*con
, /* I - Client connection */
10304 cupsd_job_t
*job
, /* I - Job */
10305 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10307 int i
; /* Looping var */
10308 char filename
[1024]; /* Job authentication filename */
10309 cups_file_t
*fp
; /* Job authentication file */
10310 char line
[65536]; /* Line for file */
10311 cupsd_printer_t
*dest
; /* Destination printer/class */
10315 * This function saves the in-memory authentication information for
10316 * a job so that it can be used to authenticate with a remote host.
10317 * The information is stored in a file that is readable only by the
10318 * root user. The fields are Base-64 encoded, each on a separate line,
10319 * followed by random number (up to 1024) of newlines to limit the
10320 * amount of information that is exposed.
10322 * Because of the potential for exposing of authentication information,
10323 * this functionality is only enabled when running cupsd as root.
10325 * This caching only works for the Basic and BasicDigest authentication
10326 * types. Digest authentication cannot be cached this way, and in
10327 * the future Kerberos authentication may make all of this obsolete.
10329 * Authentication information is saved whenever an authenticated
10330 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10333 * This information is deleted after a job is completed or canceled,
10334 * so reprints may require subsequent re-authentication.
10340 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10344 * Create the authentication file and change permissions...
10347 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10348 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10350 cupsdLogMessage(CUPSD_LOG_ERROR
,
10351 "Unable to save authentication info to \"%s\" - %s",
10352 filename
, strerror(errno
));
10356 fchown(cupsFileNumber(fp
), 0, 0);
10357 fchmod(cupsFileNumber(fp
), 0400);
10360 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10362 cupsdClearString(job
->auth_env
+ i
);
10364 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10367 * Write 1 to 3 auth values...
10371 i
< auth_info
->num_values
&&
10372 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10375 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10376 strlen(auth_info
->values
[i
].string
.text
));
10377 cupsFilePrintf(fp
, "%s\n", line
);
10379 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10380 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
10381 auth_info
->values
[i
].string
.text
);
10382 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10383 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
10384 auth_info
->values
[i
].string
.text
);
10385 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10386 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
10387 auth_info
->values
[i
].string
.text
);
10388 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
10389 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
10390 auth_info
->values
[i
].string
.text
);
10392 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_%s=%s",
10393 dest
->auth_info_required
[i
],
10394 auth_info
->values
[i
].string
.text
);
10397 else if (con
->username
[0])
10400 * Write the authenticated username...
10403 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10404 cupsFilePrintf(fp
, "%s\n", line
);
10406 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
10409 * Write the authenticated password...
10412 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10413 cupsFilePrintf(fp
, "%s\n", line
);
10415 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
10419 if (con
->gss_uid
> 0)
10421 cupsFilePrintf(fp
, "%d\n", (int)con
->gss_uid
);
10422 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
10424 #endif /* HAVE_GSSAPI */
10427 * Write a random number of newlines to the end of the file...
10430 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10431 cupsFilePutChar(fp
, '\n');
10434 * Close the file and return...
10442 * 'send_document()' - Send a file to a printer or class.
10446 send_document(cupsd_client_t
*con
, /* I - Client connection */
10447 ipp_attribute_t
*uri
) /* I - Printer URI */
10449 ipp_attribute_t
*attr
; /* Current attribute */
10450 ipp_attribute_t
*format
; /* Request's document-format attribute */
10451 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10452 const char *default_format
;/* document-format-default value */
10453 int jobid
; /* Job ID number */
10454 cupsd_job_t
*job
; /* Current job */
10455 char job_uri
[HTTP_MAX_URI
],
10457 scheme
[HTTP_MAX_URI
],
10458 /* Method portion of URI */
10459 username
[HTTP_MAX_URI
],
10460 /* Username portion of URI */
10461 host
[HTTP_MAX_URI
],
10462 /* Host portion of URI */
10463 resource
[HTTP_MAX_URI
];
10464 /* Resource portion of URI */
10465 int port
; /* Port portion of URI */
10466 mime_type_t
*filetype
; /* Type of file */
10467 char super
[MIME_MAX_SUPER
],
10468 /* Supertype of file */
10469 type
[MIME_MAX_TYPE
],
10470 /* Subtype of file */
10471 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10472 /* Textual name of mime type */
10473 char filename
[1024]; /* Job filename */
10474 cupsd_printer_t
*printer
; /* Current printer */
10475 struct stat fileinfo
; /* File information */
10476 int kbytes
; /* Size of file */
10477 int compression
; /* Type of compression */
10478 int start_job
; /* Start the job? */
10481 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10482 con
->http
.fd
, uri
->values
[0].string
.text
);
10485 * See if we have a job URI or a printer URI...
10488 if (!strcmp(uri
->name
, "printer-uri"))
10491 * Got a printer URI; see if we also have a job-id attribute...
10494 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10495 IPP_TAG_INTEGER
)) == NULL
)
10497 send_ipp_status(con
, IPP_BAD_REQUEST
,
10498 _("Got a printer-uri attribute but no job-id."));
10502 jobid
= attr
->values
[0].integer
;
10507 * Got a job URI; parse it to get the job ID...
10510 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10511 sizeof(scheme
), username
, sizeof(username
), host
,
10512 sizeof(host
), &port
, resource
, sizeof(resource
));
10514 if (strncmp(resource
, "/jobs/", 6))
10520 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10521 uri
->values
[0].string
.text
);
10525 jobid
= atoi(resource
+ 6);
10529 * See if the job exists...
10532 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10535 * Nope - return a "not found" error...
10538 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10542 printer
= cupsdFindDest(job
->dest
);
10545 * See if the job is owned by the requesting user...
10548 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10550 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10551 cupsdFindDest(job
->dest
));
10556 * OK, see if the client is sending the document compressed - CUPS
10557 * only supports "none" and "gzip".
10560 compression
= CUPS_FILE_NONE
;
10562 if ((attr
= ippFindAttribute(con
->request
, "compression",
10563 IPP_TAG_KEYWORD
)) != NULL
)
10565 if (strcmp(attr
->values
[0].string
.text
, "none")
10567 && strcmp(attr
->values
[0].string
.text
, "gzip")
10568 #endif /* HAVE_LIBZ */
10571 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10572 attr
->values
[0].string
.text
);
10573 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10574 "compression", NULL
, attr
->values
[0].string
.text
);
10579 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10580 compression
= CUPS_FILE_GZIP
;
10581 #endif /* HAVE_LIBZ */
10585 * Do we have a file to print?
10588 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10589 IPP_TAG_BOOLEAN
)) == NULL
)
10591 send_ipp_status(con
, IPP_BAD_REQUEST
,
10592 _("Missing last-document attribute in request."));
10596 if (!con
->filename
)
10599 * Check for an empty request with "last-document" set to true, which is
10600 * used to close an "open" job by RFC 2911, section 3.3.2.
10603 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
10604 goto last_document
;
10606 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10611 * Is it a format we support?
10614 if ((format
= ippFindAttribute(con
->request
, "document-format",
10615 IPP_TAG_MIMETYPE
)) != NULL
)
10618 * Grab format from client...
10621 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10624 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10625 format
->values
[0].string
.text
);
10629 else if ((default_format
= cupsGetOption("document-format",
10630 printer
->num_options
,
10631 printer
->options
)) != NULL
)
10634 * Use default document format...
10637 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10639 send_ipp_status(con
, IPP_BAD_REQUEST
,
10640 _("Bad document-format-default \"%s\"."), default_format
);
10647 * No document format attribute? Auto-type it!
10650 strcpy(super
, "application");
10651 strcpy(type
, "octet-stream");
10654 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10657 * Auto-type the file...
10660 ipp_attribute_t
*doc_name
; /* document-name attribute */
10663 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10665 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10666 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10667 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10671 filetype
= mimeType(MimeDatabase
, super
, type
);
10674 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10675 filetype
->super
, filetype
->type
);
10678 filetype
= mimeType(MimeDatabase
, super
, type
);
10683 * Replace the document-format attribute value with the auto-typed or
10687 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10690 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10691 IPP_TAG_MIMETYPE
)) != NULL
)
10693 _cupsStrFree(jformat
->values
[0].string
.text
);
10695 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10698 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10699 "document-format", NULL
, mimetype
);
10701 else if (!filetype
)
10703 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10704 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10705 cupsdLogMessage(CUPSD_LOG_INFO
,
10706 "Hint: Do you have the raw file printing rules enabled?");
10709 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10710 "document-format", NULL
, format
->values
[0].string
.text
);
10715 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10717 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10720 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10721 _("Unsupported document-format \"%s\"."), mimetype
);
10723 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10724 "document-format", NULL
, mimetype
);
10730 * Add the file to the job...
10735 if (add_file(con
, job
, filetype
, compression
))
10738 if (stat(con
->filename
, &fileinfo
))
10741 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10743 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10745 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10746 IPP_TAG_INTEGER
)) != NULL
)
10747 attr
->values
[0].integer
+= kbytes
;
10749 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10751 rename(con
->filename
, filename
);
10753 cupsdClearString(&con
->filename
);
10755 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10756 filetype
->super
, filetype
->type
, job
->username
);
10759 * Start the job if this is the last document...
10764 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10765 IPP_TAG_BOOLEAN
)) != NULL
&&
10766 attr
->values
[0].boolean
)
10769 * See if we need to add the ending sheet...
10772 if (cupsdTimeoutJob(job
))
10775 if (job
->state_value
== IPP_JOB_STOPPED
)
10777 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10778 job
->state_value
= IPP_JOB_PENDING
;
10780 else if (job
->state_value
== IPP_JOB_HELD
)
10782 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10783 IPP_TAG_KEYWORD
)) == NULL
)
10784 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10786 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10788 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10789 job
->state_value
= IPP_JOB_PENDING
;
10794 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10800 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10801 IPP_TAG_KEYWORD
)) == NULL
)
10802 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10804 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10806 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10807 job
->state_value
= IPP_JOB_HELD
;
10808 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10811 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10818 * Fill in the response info...
10821 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
10822 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
10823 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10826 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10828 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10830 add_job_state_reasons(con
, job
);
10832 con
->response
->request
.status
.status_code
= IPP_OK
;
10835 * Start the job if necessary...
10844 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10849 cupsd_client_t
*con
, /* I - Client connection */
10850 http_status_t status
, /* I - HTTP status code */
10851 cupsd_printer_t
*printer
) /* I - Printer, if any */
10853 ipp_attribute_t
*uri
; /* Request URI, if any */
10856 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10857 IPP_TAG_URI
)) == NULL
)
10858 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10860 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10861 "Returning HTTP %s for %s (%s) from %s",
10862 httpStatus(status
),
10864 ippOpString(con
->request
->request
.op
.operation_id
) :
10866 uri
? uri
->values
[0].string
.text
: "no URI",
10867 con
->http
.hostname
);
10871 int auth_type
; /* Type of authentication required */
10874 auth_type
= CUPSD_AUTH_NONE
;
10876 if (status
== HTTP_UNAUTHORIZED
&&
10877 printer
->num_auth_info_required
> 0 &&
10878 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10880 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10881 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10882 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10885 * Creating and authenticating jobs requires Kerberos...
10888 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10893 * Use policy/location-defined authentication requirements...
10896 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10897 cupsd_location_t
*auth
; /* Pointer to authentication element */
10900 if (printer
->type
& CUPS_PRINTER_CLASS
)
10901 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10903 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10905 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10906 auth
->type
== CUPSD_AUTH_NONE
)
10907 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10909 con
->request
->request
.op
.operation_id
:
10914 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10915 auth_type
= DefaultAuthType
;
10917 auth_type
= auth
->type
;
10921 cupsdSendError(con
, status
, auth_type
);
10924 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10926 ippDelete(con
->response
);
10927 con
->response
= NULL
;
10934 * 'send_ipp_status()' - Send a status back to the IPP client.
10938 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10939 ipp_status_t status
, /* I - IPP status code */
10940 const char *message
,/* I - Status message */
10941 ...) /* I - Additional args as needed */
10943 va_list ap
; /* Pointer to additional args */
10944 char formatted
[1024]; /* Formatted errror message */
10947 va_start(ap
, message
);
10948 vsnprintf(formatted
, sizeof(formatted
),
10949 _cupsLangString(con
->language
, message
), ap
);
10952 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10953 ippOpString(con
->request
->request
.op
.operation_id
),
10954 ippErrorString(status
), formatted
);
10956 con
->response
->request
.status
.status_code
= status
;
10958 if (ippFindAttribute(con
->response
, "attributes-charset",
10959 IPP_TAG_ZERO
) == NULL
)
10960 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10961 "attributes-charset", NULL
, "utf-8");
10963 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10964 IPP_TAG_ZERO
) == NULL
)
10965 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10966 "attributes-natural-language", NULL
, DefaultLanguage
);
10968 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10969 "status-message", NULL
, formatted
);
10974 * 'set_default()' - Set the default destination...
10978 set_default(cupsd_client_t
*con
, /* I - Client connection */
10979 ipp_attribute_t
*uri
) /* I - Printer URI */
10981 http_status_t status
; /* Policy status */
10982 cups_ptype_t dtype
; /* Destination type (printer/class) */
10983 cupsd_printer_t
*printer
, /* Printer */
10984 *oldprinter
; /* Old default printer */
10987 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10988 con
->http
.fd
, uri
->values
[0].string
.text
);
10991 * Is the destination valid?
10994 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11000 send_ipp_status(con
, IPP_NOT_FOUND
,
11001 _("The printer or class does not exist."));
11009 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11011 send_http_error(con
, status
, NULL
);
11016 * Set it as the default...
11019 oldprinter
= DefaultPrinter
;
11020 DefaultPrinter
= printer
;
11023 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11024 "%s is no longer the default printer.", oldprinter
->name
);
11026 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11027 "%s is now the default printer.", printer
->name
);
11029 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11030 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11032 cupsdLogMessage(CUPSD_LOG_INFO
,
11033 "Default destination set to \"%s\" by \"%s\".",
11034 printer
->name
, get_username(con
));
11037 * Everything was ok, so return OK status...
11040 con
->response
->request
.status
.status_code
= IPP_OK
;
11045 * 'set_job_attrs()' - Set job attributes.
11049 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11050 ipp_attribute_t
*uri
) /* I - Job URI */
11052 ipp_attribute_t
*attr
, /* Current attribute */
11053 *attr2
; /* Job attribute */
11054 int jobid
; /* Job ID */
11055 cupsd_job_t
*job
; /* Current job */
11056 char scheme
[HTTP_MAX_URI
],
11057 /* Method portion of URI */
11058 username
[HTTP_MAX_URI
],
11059 /* Username portion of URI */
11060 host
[HTTP_MAX_URI
],
11061 /* Host portion of URI */
11062 resource
[HTTP_MAX_URI
];
11063 /* Resource portion of URI */
11064 int port
; /* Port portion of URI */
11065 int event
; /* Events? */
11066 int check_jobs
; /* Check jobs? */
11069 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11070 con
->http
.fd
, uri
->values
[0].string
.text
);
11073 * Start with "everything is OK" status...
11076 con
->response
->request
.status
.status_code
= IPP_OK
;
11079 * See if we have a job URI or a printer URI...
11082 if (!strcmp(uri
->name
, "printer-uri"))
11085 * Got a printer URI; see if we also have a job-id attribute...
11088 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11089 IPP_TAG_INTEGER
)) == NULL
)
11091 send_ipp_status(con
, IPP_BAD_REQUEST
,
11092 _("Got a printer-uri attribute but no job-id."));
11096 jobid
= attr
->values
[0].integer
;
11101 * Got a job URI; parse it to get the job ID...
11104 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11105 sizeof(scheme
), username
, sizeof(username
), host
,
11106 sizeof(host
), &port
, resource
, sizeof(resource
));
11108 if (strncmp(resource
, "/jobs/", 6))
11114 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
11115 uri
->values
[0].string
.text
);
11119 jobid
= atoi(resource
+ 6);
11123 * See if the job exists...
11126 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11129 * Nope - return a "not found" error...
11132 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
11137 * See if the job has been completed...
11140 if (job
->state_value
> IPP_JOB_STOPPED
)
11143 * Return a "not-possible" error...
11146 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11147 _("Job #%d is finished and cannot be altered."), jobid
);
11152 * See if the job is owned by the requesting user...
11155 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11157 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11158 cupsdFindDest(job
->dest
));
11163 * See what the user wants to change.
11171 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11173 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11176 if (!strcmp(attr
->name
, "attributes-charset") ||
11177 !strcmp(attr
->name
, "attributes-natural-language") ||
11178 !strcmp(attr
->name
, "document-compression") ||
11179 !strcmp(attr
->name
, "document-format") ||
11180 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11181 !strcmp(attr
->name
, "job-document-access-errors") ||
11182 !strcmp(attr
->name
, "job-id") ||
11183 !strcmp(attr
->name
, "job-impressions-completed") ||
11184 !strcmp(attr
->name
, "job-k-octets") ||
11185 !strcmp(attr
->name
, "job-originating-host-name") ||
11186 !strcmp(attr
->name
, "job-originating-user-name") ||
11187 !strcmp(attr
->name
, "job-printer-up-time") ||
11188 !strcmp(attr
->name
, "job-printer-uri") ||
11189 !strcmp(attr
->name
, "job-sheets") ||
11190 !strcmp(attr
->name
, "job-state-message") ||
11191 !strcmp(attr
->name
, "job-state-reasons") ||
11192 !strcmp(attr
->name
, "job-uri") ||
11193 !strcmp(attr
->name
, "number-of-documents") ||
11194 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11195 !strcmp(attr
->name
, "output-device-assigned") ||
11196 !strncmp(attr
->name
, "date-time-at-", 13) ||
11197 !strncmp(attr
->name
, "job-k-octets", 12) ||
11198 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11199 !strncmp(attr
->name
, "time-at-", 8))
11205 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11206 _("%s cannot be changed."), attr
->name
);
11208 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11209 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11214 if (!strcmp(attr
->name
, "job-priority"))
11217 * Change the job priority...
11220 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11222 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
11224 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11225 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11227 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11229 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11230 _("Job is completed and cannot be changed."));
11233 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11235 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11236 attr
->values
[0].integer
);
11237 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11240 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11241 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11244 else if (!strcmp(attr
->name
, "job-state"))
11247 * Change the job state...
11250 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11252 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
11254 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11255 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11259 switch (attr
->values
[0].integer
)
11261 case IPP_JOB_PENDING
:
11262 case IPP_JOB_HELD
:
11263 if (job
->state_value
> IPP_JOB_HELD
)
11265 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11266 _("Job state cannot be changed."));
11269 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11271 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11272 attr
->values
[0].integer
);
11273 cupsdSetJobState(job
, attr
->values
[0].integer
,
11275 "Job state changed by \"%s\"", username
);
11280 case IPP_JOB_PROCESSING
:
11281 case IPP_JOB_STOPPED
:
11282 if (job
->state_value
!= attr
->values
[0].integer
)
11284 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11285 _("Job state cannot be changed."));
11290 case IPP_JOB_CANCELED
:
11291 case IPP_JOB_ABORTED
:
11292 case IPP_JOB_COMPLETED
:
11293 if (job
->state_value
> IPP_JOB_PROCESSING
)
11295 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11296 _("Job state cannot be changed."));
11299 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11301 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11302 attr
->values
[0].integer
);
11303 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11305 "Job state changed by \"%s\"", username
);
11312 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11314 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11315 IPP_TAG_ZERO
)) != NULL
)
11318 * Some other value; first free the old value...
11321 if (job
->attrs
->prev
)
11322 job
->attrs
->prev
->next
= attr2
->next
;
11324 job
->attrs
->attrs
= attr2
->next
;
11326 if (job
->attrs
->last
== attr2
)
11327 job
->attrs
->last
= job
->attrs
->prev
;
11329 _ippFreeAttr(attr2
);
11332 * Then copy the attribute...
11335 copy_attribute(job
->attrs
, attr
, 0);
11338 * See if the job-name or job-hold-until is being changed.
11341 if (!strcmp(attr
->name
, "job-hold-until"))
11343 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11344 attr
->values
[0].string
.text
);
11345 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11347 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11349 cupsdReleaseJob(job
);
11353 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11354 "Job held by \"%s\".", username
);
11356 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11359 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11362 * Delete the attribute...
11365 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11366 IPP_TAG_ZERO
)) != NULL
)
11368 if (job
->attrs
->prev
)
11369 job
->attrs
->prev
->next
= attr2
->next
;
11371 job
->attrs
->attrs
= attr2
->next
;
11373 if (attr2
== job
->attrs
->last
)
11374 job
->attrs
->last
= job
->attrs
->prev
;
11376 _ippFreeAttr(attr2
);
11378 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11384 * Add new option by copying it...
11387 copy_attribute(job
->attrs
, attr
, 0);
11389 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11398 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11401 * Send events as needed...
11404 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11405 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11406 cupsdFindDest(job
->dest
), job
,
11407 "Job priority changed by user.");
11409 if (event
& CUPSD_EVENT_JOB_STATE
)
11410 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11411 job
->state_value
== IPP_JOB_HELD
?
11412 "Job held by user." : "Job restarted by user.");
11414 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11415 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11416 "Job options changed by user.");
11419 * Start jobs if possible...
11428 * 'set_printer_attrs()' - Set printer attributes.
11432 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11433 ipp_attribute_t
*uri
) /* I - Printer */
11435 http_status_t status
; /* Policy status */
11436 cups_ptype_t dtype
; /* Destination type (printer/class) */
11437 cupsd_printer_t
*printer
; /* Printer/class */
11438 ipp_attribute_t
*attr
; /* Printer attribute */
11439 int changed
= 0; /* Was anything changed? */
11442 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11443 con
->http
.fd
, uri
->values
[0].string
.text
);
11446 * Is the destination valid?
11449 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11455 send_ipp_status(con
, IPP_NOT_FOUND
,
11456 _("The printer or class does not exist."));
11464 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11466 send_http_error(con
, status
, printer
);
11471 * Return a list of attributes that can be set via Set-Printer-Attributes.
11474 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11475 IPP_TAG_TEXT
)) != NULL
)
11477 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11481 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11482 IPP_TAG_TEXT
)) != NULL
)
11484 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11489 * Update the printer attributes and return...
11494 cupsdSetPrinterAttrs(printer
);
11495 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11497 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11498 "Printer \"%s\" description or location changed by \"%s\".",
11499 printer
->name
, get_username(con
));
11501 cupsdLogMessage(CUPSD_LOG_INFO
,
11502 "Printer \"%s\" description or location changed by \"%s\".",
11503 printer
->name
, get_username(con
));
11506 con
->response
->request
.status
.status_code
= IPP_OK
;
11511 * 'set_printer_defaults()' - Set printer default options from a request.
11515 set_printer_defaults(
11516 cupsd_client_t
*con
, /* I - Client connection */
11517 cupsd_printer_t
*printer
) /* I - Printer */
11519 int i
; /* Looping var */
11520 ipp_attribute_t
*attr
; /* Current attribute */
11521 int namelen
; /* Length of attribute name */
11522 char name
[256], /* New attribute name */
11523 value
[256]; /* String version of integer attrs */
11526 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11529 * Skip non-printer attributes...
11532 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11537 if (!strcmp(attr
->name
, "job-sheets-default"))
11540 * Only allow keywords and names...
11543 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11547 * Only allow job-sheets-default to be set when running without a
11548 * system high classification level...
11551 if (Classification
)
11554 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11556 if (attr
->num_values
> 1)
11557 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11559 cupsdSetString(&printer
->job_sheets
[1], "none");
11561 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11563 cupsdFreeStrings(&(printer
->users
));
11565 printer
->deny_users
= 0;
11567 if (attr
->value_tag
== IPP_TAG_NAME
&&
11568 (attr
->num_values
> 1 ||
11569 strcmp(attr
->values
[0].string
.text
, "all")))
11571 for (i
= 0; i
< attr
->num_values
; i
++)
11572 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11575 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11577 cupsdFreeStrings(&(printer
->users
));
11579 printer
->deny_users
= 1;
11581 if (attr
->value_tag
== IPP_TAG_NAME
&&
11582 (attr
->num_values
> 1 ||
11583 strcmp(attr
->values
[0].string
.text
, "none")))
11585 for (i
= 0; i
< attr
->num_values
; i
++)
11586 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11589 else if (!strcmp(attr
->name
, "job-quota-period"))
11591 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11594 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11595 attr
->values
[0].integer
);
11596 cupsdFreeQuotas(printer
);
11598 printer
->quota_period
= attr
->values
[0].integer
;
11600 else if (!strcmp(attr
->name
, "job-k-limit"))
11602 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11605 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11606 attr
->values
[0].integer
);
11607 cupsdFreeQuotas(printer
);
11609 printer
->k_limit
= attr
->values
[0].integer
;
11611 else if (!strcmp(attr
->name
, "job-page-limit"))
11613 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11616 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11617 attr
->values
[0].integer
);
11618 cupsdFreeQuotas(printer
);
11620 printer
->page_limit
= attr
->values
[0].integer
;
11622 else if (!strcmp(attr
->name
, "printer-op-policy"))
11624 cupsd_policy_t
*p
; /* Policy */
11627 if (attr
->value_tag
!= IPP_TAG_NAME
)
11630 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11632 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11633 "Setting printer-op-policy to \"%s\"...",
11634 attr
->values
[0].string
.text
);
11635 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11636 printer
->op_policy_ptr
= p
;
11640 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11641 _("Unknown printer-op-policy \"%s\"."),
11642 attr
->values
[0].string
.text
);
11646 else if (!strcmp(attr
->name
, "printer-error-policy"))
11648 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11651 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11652 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11653 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11654 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11655 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11657 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11658 _("Unknown printer-error-policy \"%s\"."),
11659 attr
->values
[0].string
.text
);
11663 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11664 "Setting printer-error-policy to \"%s\"...",
11665 attr
->values
[0].string
.text
);
11666 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11670 * Skip any other non-default attributes...
11673 namelen
= strlen(attr
->name
);
11674 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11675 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11679 * OK, anything else must be a user-defined default...
11682 strlcpy(name
, attr
->name
, sizeof(name
));
11683 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11685 switch (attr
->value_tag
)
11687 case IPP_TAG_DELETEATTR
:
11688 printer
->num_options
= cupsRemoveOption(name
,
11689 printer
->num_options
,
11690 &(printer
->options
));
11691 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11692 "Deleting %s", attr
->name
);
11695 case IPP_TAG_NAME
:
11696 case IPP_TAG_KEYWORD
:
11698 printer
->num_options
= cupsAddOption(name
,
11699 attr
->values
[0].string
.text
,
11700 printer
->num_options
,
11701 &(printer
->options
));
11702 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11703 "Setting %s to \"%s\"...", attr
->name
,
11704 attr
->values
[0].string
.text
);
11707 case IPP_TAG_BOOLEAN
:
11708 printer
->num_options
= cupsAddOption(name
,
11709 attr
->values
[0].boolean
?
11711 printer
->num_options
,
11712 &(printer
->options
));
11713 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11714 "Setting %s to %s...", attr
->name
,
11715 attr
->values
[0].boolean
? "true" : "false");
11718 case IPP_TAG_INTEGER
:
11719 case IPP_TAG_ENUM
:
11720 sprintf(value
, "%d", attr
->values
[0].integer
);
11721 printer
->num_options
= cupsAddOption(name
, value
,
11722 printer
->num_options
,
11723 &(printer
->options
));
11724 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11725 "Setting %s to %s...", attr
->name
, value
);
11728 case IPP_TAG_RANGE
:
11729 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11730 attr
->values
[0].range
.upper
);
11731 printer
->num_options
= cupsAddOption(name
, value
,
11732 printer
->num_options
,
11733 &(printer
->options
));
11734 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11735 "Setting %s to %s...", attr
->name
, value
);
11738 case IPP_TAG_RESOLUTION
:
11739 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11740 attr
->values
[0].resolution
.yres
,
11741 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11743 printer
->num_options
= cupsAddOption(name
, value
,
11744 printer
->num_options
,
11745 &(printer
->options
));
11746 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11747 "Setting %s to %s...", attr
->name
, value
);
11751 /* Do nothing for other values */
11759 * 'start_printer()' - Start a printer.
11763 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11764 ipp_attribute_t
*uri
) /* I - Printer URI */
11766 int i
; /* Temporary variable */
11767 http_status_t status
; /* Policy status */
11768 cups_ptype_t dtype
; /* Destination type (printer/class) */
11769 cupsd_printer_t
*printer
; /* Printer data */
11772 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11773 con
->http
.fd
, uri
->values
[0].string
.text
);
11776 * Is the destination valid?
11779 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11785 send_ipp_status(con
, IPP_NOT_FOUND
,
11786 _("The printer or class does not exist."));
11794 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11796 send_http_error(con
, status
, printer
);
11801 * Start the printer...
11804 printer
->state_message
[0] = '\0';
11806 cupsdStartPrinter(printer
, 1);
11808 if (dtype
& CUPS_PRINTER_CLASS
)
11809 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11810 printer
->name
, get_username(con
));
11812 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11813 printer
->name
, get_username(con
));
11821 if ((i
= check_quotas(con
, printer
)) < 0)
11823 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11828 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11833 * Everything was ok, so return OK status...
11836 con
->response
->request
.status
.status_code
= IPP_OK
;
11841 * 'stop_printer()' - Stop a printer.
11845 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11846 ipp_attribute_t
*uri
) /* I - Printer URI */
11848 http_status_t status
; /* Policy status */
11849 cups_ptype_t dtype
; /* Destination type (printer/class) */
11850 cupsd_printer_t
*printer
; /* Printer data */
11851 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11854 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11855 con
->http
.fd
, uri
->values
[0].string
.text
);
11858 * Is the destination valid?
11861 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11867 send_ipp_status(con
, IPP_NOT_FOUND
,
11868 _("The printer or class does not exist."));
11876 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11878 send_http_error(con
, status
, printer
);
11883 * Stop the printer...
11886 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11887 IPP_TAG_TEXT
)) == NULL
)
11888 strcpy(printer
->state_message
, "Paused");
11891 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11892 sizeof(printer
->state_message
));
11895 cupsdStopPrinter(printer
, 1);
11897 if (dtype
& CUPS_PRINTER_CLASS
)
11898 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11899 printer
->name
, get_username(con
));
11901 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11902 printer
->name
, get_username(con
));
11905 * Everything was ok, so return OK status...
11908 con
->response
->request
.status
.status_code
= IPP_OK
;
11913 * 'url_encode_attr()' - URL-encode a string attribute.
11917 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11918 char *buffer
,/* I - String buffer */
11919 int bufsize
)/* I - Size of buffer */
11921 int i
; /* Looping var */
11922 char *bufptr
, /* Pointer into buffer */
11923 *bufend
; /* End of buffer */
11926 strlcpy(buffer
, attr
->name
, bufsize
);
11927 bufptr
= buffer
+ strlen(buffer
);
11928 bufend
= buffer
+ bufsize
- 1;
11930 for (i
= 0; i
< attr
->num_values
; i
++)
11932 if (bufptr
>= bufend
)
11940 if (bufptr
>= bufend
)
11945 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11946 bufptr
, bufend
- bufptr
+ 1);
11948 if (bufptr
>= bufend
)
11959 * 'url_encode_string()' - URL-encode a string.
11962 static char * /* O - End of string */
11963 url_encode_string(const char *s
, /* I - String */
11964 char *buffer
, /* I - String buffer */
11965 int bufsize
) /* I - Size of buffer */
11967 char *bufptr
, /* Pointer into buffer */
11968 *bufend
; /* End of buffer */
11969 static const char *hex
= "0123456789ABCDEF";
11974 bufend
= buffer
+ bufsize
- 1;
11976 while (*s
&& bufptr
< bufend
)
11978 if (*s
== ' ' || *s
== '%' || *s
== '+')
11980 if (bufptr
>= (bufend
- 2))
11984 *bufptr
++ = hex
[(*s
>> 4) & 15];
11985 *bufptr
++ = hex
[*s
& 15];
11989 else if (*s
== '\'' || *s
== '\\')
11991 if (bufptr
>= (bufend
- 1))
12008 * 'user_allowed()' - See if a user is allowed to print to a queue.
12011 static int /* O - 0 if not allowed, 1 if allowed */
12012 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12013 const char *username
) /* I - Username */
12015 struct passwd
*pw
; /* User password data */
12016 char baseuser
[256], /* Base username */
12017 *baseptr
, /* Pointer to "@" in base username */
12018 *name
; /* Current user name */
12021 if (cupsArrayCount(p
->users
) == 0)
12024 if (!strcmp(username
, "root"))
12027 if (strchr(username
, '@'))
12030 * Strip @REALM for username check...
12033 strlcpy(baseuser
, username
, sizeof(baseuser
));
12035 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12038 username
= baseuser
;
12041 pw
= getpwnam(username
);
12044 for (name
= (char *)cupsArrayFirst(p
->users
);
12046 name
= (char *)cupsArrayNext(p
->users
))
12048 if (name
[0] == '@')
12051 * Check group membership...
12054 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12057 else if (name
[0] == '#')
12063 if (cupsdCheckGroup(username
, pw
, name
))
12066 else if (!_cups_strcasecmp(username
, name
))
12070 return ((name
!= NULL
) != p
->deny_users
);
12075 * 'validate_job()' - Validate printer options and destination.
12079 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12080 ipp_attribute_t
*uri
) /* I - Printer URI */
12082 http_status_t status
; /* Policy status */
12083 ipp_attribute_t
*attr
, /* Current attribute */
12084 *auth_info
; /* auth-info attribute */
12085 ipp_attribute_t
*format
; /* Document-format attribute */
12086 cups_ptype_t dtype
; /* Destination type (printer/class) */
12087 char super
[MIME_MAX_SUPER
],
12088 /* Supertype of file */
12089 type
[MIME_MAX_TYPE
];
12090 /* Subtype of file */
12091 cupsd_printer_t
*printer
; /* Printer */
12094 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12095 con
->http
.fd
, uri
->values
[0].string
.text
);
12098 * OK, see if the client is sending the document compressed - CUPS
12099 * doesn't support compression yet...
12102 if ((attr
= ippFindAttribute(con
->request
, "compression",
12103 IPP_TAG_KEYWORD
)) != NULL
)
12105 if (strcmp(attr
->values
[0].string
.text
, "none")
12107 && strcmp(attr
->values
[0].string
.text
, "gzip")
12108 #endif /* HAVE_LIBZ */
12111 send_ipp_status(con
, IPP_ATTRIBUTES
,
12112 _("Unsupported compression \"%s\"."),
12113 attr
->values
[0].string
.text
);
12114 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12115 "compression", NULL
, attr
->values
[0].string
.text
);
12121 * Is it a format we support?
12124 if ((format
= ippFindAttribute(con
->request
, "document-format",
12125 IPP_TAG_MIMETYPE
)) != NULL
)
12127 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12130 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
12131 format
->values
[0].string
.text
);
12135 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12136 !mimeType(MimeDatabase
, super
, type
))
12138 cupsdLogMessage(CUPSD_LOG_INFO
,
12139 "Hint: Do you have the raw file printing rules enabled?");
12140 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12141 _("Unsupported document-format \"%s\"."),
12142 format
->values
[0].string
.text
);
12143 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12144 "document-format", NULL
, format
->values
[0].string
.text
);
12150 * Is the destination valid?
12153 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12159 send_ipp_status(con
, IPP_NOT_FOUND
,
12160 _("The printer or class does not exist."));
12168 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12170 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12172 send_http_error(con
, status
, printer
);
12175 else if (printer
->num_auth_info_required
== 1 &&
12176 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12179 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12183 else if (auth_info
&& !con
->http
.tls
&&
12184 !httpAddrLocalhost(con
->http
.hostaddr
))
12187 * Require encryption of auth-info over non-local connections...
12190 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12193 #endif /* HAVE_SSL */
12196 * Everything was ok, so return OK status...
12199 con
->response
->request
.status
.status_code
= IPP_OK
;
12204 * 'validate_name()' - Make sure the printer name only contains valid chars.
12207 static int /* O - 0 if name is no good, 1 if good */
12208 validate_name(const char *name
) /* I - Name to check */
12210 const char *ptr
; /* Pointer into name */
12214 * Scan the whole name...
12217 for (ptr
= name
; *ptr
; ptr
++)
12218 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12222 * All the characters are good; validate the length, too...
12225 return ((ptr
- name
) < 128);
12230 * 'validate_user()' - Validate the user for the request.
12233 static int /* O - 1 if permitted, 0 otherwise */
12234 validate_user(cupsd_job_t
*job
, /* I - Job */
12235 cupsd_client_t
*con
, /* I - Client connection */
12236 const char *owner
, /* I - Owner of job/resource */
12237 char *username
, /* O - Authenticated username */
12238 int userlen
) /* I - Length of username */
12240 cupsd_printer_t
*printer
; /* Printer for job */
12243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12244 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12246 job
->id
, con
? con
->http
.fd
: 0,
12247 owner
? owner
: "(null)", username
, userlen
);
12250 * Validate input...
12253 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12257 * Get the best authenticated username that is available.
12260 strlcpy(username
, get_username(con
), userlen
);
12263 * Check the username against the owner...
12266 printer
= cupsdFindDest(job
->dest
);
12268 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12269 con
, owner
) == HTTP_OK
);
12274 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".