2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2012 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_subscriptions() - Add any subscriptions for a job.
27 * add_job_uuid() - Add job-uuid attribute to a job.
28 * add_printer() - Add a printer to the system.
29 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
30 * based upon the printer state...
31 * add_queued_job_count() - Add the "queued-job-count" attribute for the
32 * specified printer or class.
33 * apple_init_profile() - Initialize a color profile.
34 * apple_register_profiles() - Register color profiles for a printer.
35 * apple_unregister_profiles() - Remove color profiles for the specified
37 * apply_printer_defaults() - Apply printer default options to a job.
38 * authenticate_job() - Set job authentication info.
39 * cancel_all_jobs() - Cancel all or selected print jobs.
40 * cancel_job() - Cancel a print job.
41 * cancel_subscription() - Cancel a subscription.
42 * check_rss_recipient() - Check that we do not have a duplicate RSS
44 * check_quotas() - Check quotas for a printer and user.
45 * close_job() - Close a multi-file job.
46 * copy_attrs() - Copy attributes from one request to another.
47 * copy_banner() - Copy a banner file to the requests directory
48 * for the specified job.
49 * copy_file() - Copy a PPD file or interface script...
50 * copy_model() - Copy a PPD model file, substituting default
52 * copy_job_attrs() - Copy job attributes.
53 * copy_printer_attrs() - Copy printer attributes.
54 * copy_subscription_attrs() - Copy subscription attributes.
55 * create_job() - Print a file to a printer or class.
56 * create_requested_array() - Create an array for the requested-attributes.
57 * create_subscription() - Create a notification subscription.
58 * delete_printer() - Remove a printer or class from the system.
59 * get_default() - Get the default destination.
60 * get_devices() - Get the list of available devices on the
62 * get_document() - Get a copy of a job file.
63 * get_job_attrs() - Get job attributes.
64 * get_jobs() - Get a list of jobs for the specified printer.
65 * get_notifications() - Get events for a subscription.
66 * get_ppd() - Get a named PPD from the local system.
67 * get_ppds() - Get the list of PPD files on the local
69 * get_printer_attrs() - Get printer attributes.
70 * get_printer_supported() - Get printer supported values.
71 * get_printers() - Get a list of printers or classes.
72 * get_subscription_attrs() - Get subscription attributes.
73 * get_subscriptions() - Get subscriptions.
74 * get_username() - Get the username associated with a request.
75 * hold_job() - Hold a print job.
76 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_held_new_jobs() - Release pending/new jobs on a printer or
84 * release_job() - Release a held print job.
85 * renew_subscription() - Renew an existing subscription...
86 * restart_job() - Restart an old print job.
87 * save_auth_info() - Save authentication information for a job.
88 * send_document() - Send a file to a printer or class.
89 * send_http_error() - Send a HTTP error back to the IPP client.
90 * send_ipp_status() - Send a status back to the IPP client.
91 * set_default() - Set the default destination...
92 * set_job_attrs() - Set job attributes.
93 * set_printer_attrs() - Set printer attributes.
94 * set_printer_defaults() - Set printer default options from a request.
95 * start_printer() - Start a printer.
96 * stop_printer() - Stop a printer.
97 * url_encode_attr() - URL-encode a string attribute.
98 * url_encode_string() - URL-encode a string.
99 * user_allowed() - See if a user is allowed to print to a queue.
100 * validate_job() - Validate printer options and destination.
101 * validate_name() - Make sure the printer name only contains
103 * validate_user() - Validate the user for the request.
107 * Include necessary headers...
111 #include <cups/ppd-private.h>
114 # include <ApplicationServices/ApplicationServices.h>
115 # ifdef HAVE_COLORSYNCREGISTERDEVICE
116 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
117 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
118 # include <CoreFoundation/CoreFoundation.h>
119 # ifdef HAVE_MEMBERSHIP_H
120 # include <membership.h>
121 # endif /* HAVE_MEMBERSHIP_H */
122 # ifdef HAVE_MEMBERSHIPPRIV_H
123 # include <membershipPriv.h>
125 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
126 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
127 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
128 # endif /* HAVE_MEMBERSHIPPRIV_H */
129 #endif /* __APPLE__ */
136 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
138 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
139 mime_type_t
*filetype
, int compression
);
140 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
141 mime_type_t
*filetype
);
142 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
143 static void add_job_uuid(cupsd_job_t
*job
);
144 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
145 static void add_printer_state_reasons(cupsd_client_t
*con
,
147 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
149 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
150 # ifdef HAVE_COLORSYNCREGISTERDEVICE
151 CFMutableDictionaryRef profile
,
153 CMDeviceProfileInfo
*profile
,
154 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
155 unsigned id
, const char *name
,
156 const char *text
, const char *iccfile
);
157 static void apple_register_profiles(cupsd_printer_t
*p
);
158 static void apple_unregister_profiles(cupsd_printer_t
*p
);
159 #endif /* __APPLE__ */
160 static void apply_printer_defaults(cupsd_printer_t
*printer
,
162 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
163 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
164 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
165 static void cancel_subscription(cupsd_client_t
*con
, int id
);
166 static int check_rss_recipient(const char *recipient
);
167 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
168 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
170 ipp_tag_t group
, int quickcopy
,
171 cups_array_t
*exclude
);
172 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
174 static int copy_file(const char *from
, const char *to
);
175 static int copy_model(cupsd_client_t
*con
, const char *from
,
177 static void copy_job_attrs(cupsd_client_t
*con
,
179 cups_array_t
*ra
, cups_array_t
*exclude
);
180 static void copy_printer_attrs(cupsd_client_t
*con
,
181 cupsd_printer_t
*printer
,
183 static void copy_subscription_attrs(cupsd_client_t
*con
,
184 cupsd_subscription_t
*sub
,
186 cups_array_t
*exclude
);
187 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static cups_array_t
*create_requested_array(ipp_t
*request
);
189 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void get_default(cupsd_client_t
*con
);
192 static void get_devices(cupsd_client_t
*con
);
193 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void get_notifications(cupsd_client_t
*con
);
197 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_ppds(cupsd_client_t
*con
);
199 static void get_printers(cupsd_client_t
*con
, int type
);
200 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
203 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static const char *get_username(cupsd_client_t
*con
);
205 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static int ppd_parse_line(const char *line
, char *option
, int olen
,
209 char *choice
, int clen
);
210 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void read_job_ticket(cupsd_client_t
*con
);
212 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void release_held_new_jobs(cupsd_client_t
*con
,
214 ipp_attribute_t
*uri
);
215 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
217 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
219 ipp_attribute_t
*auth_info
);
220 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
221 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
222 cupsd_printer_t
*printer
);
223 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
224 const char *message
, ...)
225 __attribute__((__format__(__printf__
, 3, 4)));
226 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
228 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
229 static void set_printer_defaults(cupsd_client_t
*con
,
230 cupsd_printer_t
*printer
);
231 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
232 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
233 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
235 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
236 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
237 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
238 static int validate_name(const char *name
);
239 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
240 const char *owner
, char *username
,
245 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
248 int /* O - 1 on success, 0 on failure */
249 cupsdProcessIPPRequest(
250 cupsd_client_t
*con
) /* I - Client connection */
252 ipp_tag_t group
; /* Current group tag */
253 ipp_attribute_t
*attr
; /* Current attribute */
254 ipp_attribute_t
*charset
; /* Character set attribute */
255 ipp_attribute_t
*language
; /* Language attribute */
256 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
257 ipp_attribute_t
*username
; /* requesting-user-name attr */
258 int sub_id
; /* Subscription ID */
261 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
262 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
263 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
266 * First build an empty response message for this request...
269 con
->response
= ippNew();
271 con
->response
->request
.status
.version
[0] =
272 con
->request
->request
.op
.version
[0];
273 con
->response
->request
.status
.version
[1] =
274 con
->request
->request
.op
.version
[1];
275 con
->response
->request
.status
.request_id
=
276 con
->request
->request
.op
.request_id
;
279 * Then validate the request header and required attributes...
282 if (con
->request
->request
.any
.version
[0] != 1 &&
283 con
->request
->request
.any
.version
[0] != 2)
286 * Return an error, since we only support IPP 1.x and 2.x.
289 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
290 "%04X %s Bad request version number %d.%d",
291 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
292 con
->request
->request
.any
.version
[0],
293 con
->request
->request
.any
.version
[1]);
295 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
296 _("Bad request version number %d.%d."),
297 con
->request
->request
.any
.version
[0],
298 con
->request
->request
.any
.version
[1]);
300 else if (con
->request
->request
.any
.request_id
< 1)
303 * Return an error, since request IDs must be between 1 and 2^31-1
306 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
307 "%04X %s Bad request ID %d",
308 IPP_BAD_REQUEST
, con
->http
.hostname
,
309 con
->request
->request
.any
.request_id
);
311 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
312 con
->request
->request
.any
.request_id
);
314 else if (!con
->request
->attrs
)
316 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
317 "%04X %s No attributes in request",
318 IPP_BAD_REQUEST
, con
->http
.hostname
);
320 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
325 * Make sure that the attributes are provided in the correct order and
326 * don't repeat groups...
329 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
332 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
335 * Out of order; return an error...
338 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
339 "%04X %s Attribute groups are out of order",
340 IPP_BAD_REQUEST
, con
->http
.hostname
);
342 send_ipp_status(con
, IPP_BAD_REQUEST
,
343 _("Attribute groups are out of order (%x < %x)."),
344 attr
->group_tag
, group
);
348 group
= attr
->group_tag
;
353 * Then make sure that the first three attributes are:
356 * attributes-natural-language
357 * printer-uri/job-uri
360 attr
= con
->request
->attrs
;
361 if (attr
&& attr
->name
&&
362 !strcmp(attr
->name
, "attributes-charset") &&
363 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
371 if (attr
&& attr
->name
&&
372 !strcmp(attr
->name
, "attributes-natural-language") &&
373 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
378 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
379 IPP_TAG_URI
)) != NULL
)
381 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
382 IPP_TAG_URI
)) != NULL
)
384 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
385 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
390 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
391 "attributes-charset", NULL
,
392 charset
->values
[0].string
.text
);
394 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
395 "attributes-charset", NULL
, "utf-8");
398 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
399 "attributes-natural-language", NULL
,
400 language
->values
[0].string
.text
);
402 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
403 "attributes-natural-language", NULL
, DefaultLanguage
);
406 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
407 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
410 * Bad character set...
413 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
414 charset
->values
[0].string
.text
);
415 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
416 "%04X %s Unsupported attributes-charset value \"%s\"",
417 IPP_CHARSET
, con
->http
.hostname
,
418 charset
->values
[0].string
.text
);
419 send_ipp_status(con
, IPP_BAD_REQUEST
,
420 _("Unsupported character set \"%s\"."),
421 charset
->values
[0].string
.text
);
423 else if (!charset
|| !language
||
425 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
426 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
427 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
428 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
429 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
432 * Return an error, since attributes-charset,
433 * attributes-natural-language, and printer-uri/job-uri are required
434 * for all operations.
439 cupsdLogMessage(CUPSD_LOG_ERROR
,
440 "Missing attributes-charset attribute");
442 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
443 "%04X %s Missing attributes-charset attribute",
444 IPP_BAD_REQUEST
, con
->http
.hostname
);
449 cupsdLogMessage(CUPSD_LOG_ERROR
,
450 "Missing attributes-natural-language attribute");
452 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
453 "%04X %s Missing attributes-natural-language attribute",
454 IPP_BAD_REQUEST
, con
->http
.hostname
);
459 cupsdLogMessage(CUPSD_LOG_ERROR
,
460 "Missing printer-uri, job-uri, or ppd-name "
463 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
464 "%04X %s Missing printer-uri, job-uri, or ppd-name "
465 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
468 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
470 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
471 cupsdLogMessage(CUPSD_LOG_DEBUG
,
472 "attr \"%s\": group_tag = %x, value_tag = %x",
473 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
476 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
478 send_ipp_status(con
, IPP_BAD_REQUEST
,
479 _("Missing required attributes."));
484 * OK, all the checks pass so far; make sure requesting-user-name is
485 * not "root" from a remote host...
488 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
489 IPP_TAG_NAME
)) != NULL
)
492 * Check for root user...
495 if (!strcmp(username
->values
[0].string
.text
, "root") &&
496 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
497 strcmp(con
->username
, "root"))
500 * Remote unauthenticated user masquerading as local root...
503 _cupsStrFree(username
->values
[0].string
.text
);
504 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
508 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
509 IPP_TAG_INTEGER
)) != NULL
)
510 sub_id
= attr
->values
[0].integer
;
515 * Then try processing the operation...
519 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
520 ippOpString(con
->request
->request
.op
.operation_id
),
521 uri
->values
[0].string
.text
);
523 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
524 ippOpString(con
->request
->request
.op
.operation_id
));
526 switch (con
->request
->request
.op
.operation_id
)
532 case IPP_VALIDATE_JOB
:
533 validate_job(con
, uri
);
536 case IPP_CREATE_JOB
:
537 create_job(con
, uri
);
540 case IPP_SEND_DOCUMENT
:
541 send_document(con
, uri
);
544 case IPP_CANCEL_JOB
:
545 cancel_job(con
, uri
);
548 case IPP_GET_JOB_ATTRIBUTES
:
549 get_job_attrs(con
, uri
);
556 case IPP_GET_PRINTER_ATTRIBUTES
:
557 get_printer_attrs(con
, uri
);
560 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
561 get_printer_supported(con
, uri
);
568 case IPP_RELEASE_JOB
:
569 release_job(con
, uri
);
572 case IPP_RESTART_JOB
:
573 restart_job(con
, uri
);
576 case IPP_PAUSE_PRINTER
:
577 stop_printer(con
, uri
);
580 case IPP_RESUME_PRINTER
:
581 start_printer(con
, uri
);
584 case IPP_PURGE_JOBS
:
585 case IPP_CANCEL_JOBS
:
586 case IPP_CANCEL_MY_JOBS
:
587 cancel_all_jobs(con
, uri
);
590 case IPP_SET_JOB_ATTRIBUTES
:
591 set_job_attrs(con
, uri
);
594 case IPP_SET_PRINTER_ATTRIBUTES
:
595 set_printer_attrs(con
, uri
);
598 case IPP_HOLD_NEW_JOBS
:
599 hold_new_jobs(con
, uri
);
602 case IPP_RELEASE_HELD_NEW_JOBS
:
603 release_held_new_jobs(con
, uri
);
610 case CUPS_GET_DEFAULT
:
614 case CUPS_GET_PRINTERS
:
615 get_printers(con
, 0);
618 case CUPS_GET_CLASSES
:
619 get_printers(con
, CUPS_PRINTER_CLASS
);
622 case CUPS_ADD_PRINTER
:
623 add_printer(con
, uri
);
626 case CUPS_DELETE_PRINTER
:
627 delete_printer(con
, uri
);
630 case CUPS_ADD_CLASS
:
634 case CUPS_DELETE_CLASS
:
635 delete_printer(con
, uri
);
638 case CUPS_ACCEPT_JOBS
:
639 case IPP_ENABLE_PRINTER
:
640 accept_jobs(con
, uri
);
643 case CUPS_REJECT_JOBS
:
644 case IPP_DISABLE_PRINTER
:
645 reject_jobs(con
, uri
);
648 case CUPS_SET_DEFAULT
:
649 set_default(con
, uri
);
652 case CUPS_GET_DEVICES
:
656 case CUPS_GET_DOCUMENT
:
657 get_document(con
, uri
);
672 case CUPS_AUTHENTICATE_JOB
:
673 authenticate_job(con
, uri
);
676 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
677 case IPP_CREATE_JOB_SUBSCRIPTION
:
678 create_subscription(con
, uri
);
681 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
682 get_subscription_attrs(con
, sub_id
);
685 case IPP_GET_SUBSCRIPTIONS
:
686 get_subscriptions(con
, uri
);
689 case IPP_RENEW_SUBSCRIPTION
:
690 renew_subscription(con
, sub_id
);
693 case IPP_CANCEL_SUBSCRIPTION
:
694 cancel_subscription(con
, sub_id
);
697 case IPP_GET_NOTIFICATIONS
:
698 get_notifications(con
);
702 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
703 "%04X %s Operation %04X (%s) not supported",
704 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
705 con
->request
->request
.op
.operation_id
,
706 ippOpString(con
->request
->request
.op
.operation_id
));
708 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
709 _("%s not supported."),
711 con
->request
->request
.op
.operation_id
));
721 * Sending data from the scheduler...
724 cupsdLogMessage(con
->response
->request
.status
.status_code
725 >= IPP_BAD_REQUEST
&&
726 con
->response
->request
.status
.status_code
727 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
728 "Returning IPP %s for %s (%s) from %s",
729 ippErrorString(con
->response
->request
.status
.status_code
),
730 ippOpString(con
->request
->request
.op
.operation_id
),
731 uri
? uri
->values
[0].string
.text
: "no URI",
734 if (LogLevel
== CUPSD_LOG_DEBUG2
)
735 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
736 "cupsdProcessIPPRequest: ippLength(response)=%ld",
737 (long)ippLength(con
->response
));
739 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
741 #ifdef CUPSD_USE_CHUNKING
743 * Because older versions of CUPS (1.1.17 and older) and some IPP
744 * clients do not implement chunking properly, we cannot use
745 * chunking by default. This may become the default in future
746 * CUPS releases, or we might add a configuration directive for
750 if (con
->http
.version
== HTTP_1_1
)
752 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
755 if (cupsdFlushHeader(con
) < 0)
758 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
761 #endif /* CUPSD_USE_CHUNKING */
763 size_t length
; /* Length of response */
766 length
= ippLength(con
->response
);
768 if (con
->file
>= 0 && !con
->pipe_pid
)
770 struct stat fileinfo
; /* File information */
773 if (!fstat(con
->file
, &fileinfo
))
774 length
+= fileinfo
.st_size
;
777 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
778 CUPS_LLCAST length
) < 0)
781 if (cupsdFlushHeader(con
) < 0)
784 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
785 con
->http
.data_remaining
= length
;
787 if (con
->http
.data_remaining
<= INT_MAX
)
788 con
->http
._data_remaining
= con
->http
.data_remaining
;
790 con
->http
._data_remaining
= INT_MAX
;
793 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
794 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
797 * Tell the caller the response header was sent successfully...
805 * Tell the caller the response header could not be sent...
814 * Sending data from a subprocess like cups-deviced; tell the caller
815 * everything is A-OK so far...
824 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
827 int /* O - 0 on success, -1 on error */
828 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
830 cupsd_printer_t
*printer
; /* Destination printer or class */
831 ipp_attribute_t
*attr
; /* job-sheets attribute */
832 int kbytes
; /* Kilobytes in banner */
835 job
->pending_timeout
= 0;
838 * See if we need to add the ending sheet...
841 if (!cupsdLoadJob(job
))
844 printer
= cupsdFindDest(job
->dest
);
845 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
847 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
848 attr
&& attr
->num_values
> 1)
854 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
855 attr
->values
[1].string
.text
);
857 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
860 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
868 * 'accept_jobs()' - Accept print jobs to a printer.
872 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
873 ipp_attribute_t
*uri
) /* I - Printer or class URI */
875 http_status_t status
; /* Policy status */
876 cups_ptype_t dtype
; /* Destination type (printer/class) */
877 cupsd_printer_t
*printer
; /* Printer data */
880 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
881 con
->http
.fd
, uri
->values
[0].string
.text
);
884 * Is the destination valid?
887 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
893 send_ipp_status(con
, IPP_NOT_FOUND
,
894 _("The printer or class does not exist."));
902 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
904 send_http_error(con
, status
, printer
);
909 * Accept jobs sent to the printer...
912 printer
->accepting
= 1;
913 printer
->state_message
[0] = '\0';
915 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
916 "Now accepting jobs.");
918 if (dtype
& CUPS_PRINTER_CLASS
)
920 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
922 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
923 printer
->name
, get_username(con
));
927 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
929 cupsdLogMessage(CUPSD_LOG_INFO
,
930 "Printer \"%s\" now accepting jobs (\"%s\").",
931 printer
->name
, get_username(con
));
935 * Everything was ok, so return OK status...
938 con
->response
->request
.status
.status_code
= IPP_OK
;
943 * 'add_class()' - Add a class to the system.
947 add_class(cupsd_client_t
*con
, /* I - Client connection */
948 ipp_attribute_t
*uri
) /* I - URI of class */
950 http_status_t status
; /* Policy status */
951 int i
; /* Looping var */
952 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
953 username
[HTTP_MAX_URI
], /* Username portion of URI */
954 host
[HTTP_MAX_URI
], /* Host portion of URI */
955 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
956 int port
; /* Port portion of URI */
957 cupsd_printer_t
*pclass
, /* Class */
958 *member
; /* Member printer/class */
959 cups_ptype_t dtype
; /* Destination type */
960 ipp_attribute_t
*attr
; /* Printer attribute */
961 int modify
; /* Non-zero if we just modified */
962 int need_restart_job
; /* Need to restart job? */
965 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
966 con
->http
.fd
, uri
->values
[0].string
.text
);
969 * Do we have a valid URI?
972 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
973 sizeof(scheme
), username
, sizeof(username
), host
,
974 sizeof(host
), &port
, resource
, sizeof(resource
));
977 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
980 * No, return an error...
983 send_ipp_status(con
, IPP_BAD_REQUEST
,
984 _("The printer-uri must be of the form "
985 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
990 * Do we have a valid printer name?
993 if (!validate_name(resource
+ 9))
996 * No, return an error...
999 send_ipp_status(con
, IPP_BAD_REQUEST
,
1000 _("The printer-uri \"%s\" contains invalid characters."),
1001 uri
->values
[0].string
.text
);
1006 * See if the class already exists; if not, create a new class...
1009 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1012 * Class doesn't exist; see if we have a printer of the same name...
1015 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
1018 * Yes, return an error...
1021 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1022 _("A printer named \"%s\" already exists."),
1028 * No, check the default policy and then add the class...
1031 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1033 send_http_error(con
, status
, NULL
);
1037 pclass
= cupsdAddClass(resource
+ 9);
1040 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1043 send_http_error(con
, status
, pclass
);
1050 * Look for attributes and copy them over as needed...
1053 need_restart_job
= 0;
1055 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1056 IPP_TAG_TEXT
)) != NULL
)
1057 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1059 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1060 IPP_TAG_TEXT
)) != NULL
)
1061 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1063 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1064 IPP_TAG_BOOLEAN
)) != NULL
&&
1065 attr
->values
[0].boolean
!= pclass
->accepting
)
1067 cupsdLogMessage(CUPSD_LOG_INFO
,
1068 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1069 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1071 pclass
->accepting
= attr
->values
[0].boolean
;
1073 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1074 pclass
->accepting
? "Now" : "No longer");
1077 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1078 IPP_TAG_BOOLEAN
)) != NULL
)
1080 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1081 cupsdDeregisterPrinter(pclass
, 1);
1083 cupsdLogMessage(CUPSD_LOG_INFO
,
1084 "Setting %s printer-is-shared to %d (was %d.)",
1085 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1087 pclass
->shared
= attr
->values
[0].boolean
;
1090 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1091 IPP_TAG_ENUM
)) != NULL
)
1093 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1094 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1096 send_ipp_status(con
, IPP_BAD_REQUEST
,
1097 _("Attempt to set %s printer-state to bad value %d."),
1098 pclass
->name
, attr
->values
[0].integer
);
1102 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1103 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1105 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1106 cupsdStopPrinter(pclass
, 0);
1109 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1110 need_restart_job
= 1;
1113 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1114 IPP_TAG_TEXT
)) != NULL
)
1116 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1117 sizeof(pclass
->state_message
));
1119 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1120 pclass
->state_message
);
1122 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1123 IPP_TAG_URI
)) != NULL
)
1126 * Clear the printer array as needed...
1129 need_restart_job
= 1;
1131 if (pclass
->num_printers
> 0)
1133 free(pclass
->printers
);
1134 pclass
->num_printers
= 0;
1138 * Add each printer or class that is listed...
1141 for (i
= 0; i
< attr
->num_values
; i
++)
1144 * Search for the printer or class URI...
1147 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1153 send_ipp_status(con
, IPP_NOT_FOUND
,
1154 _("The printer or class does not exist."));
1157 else if (dtype
& CUPS_PRINTER_CLASS
)
1159 send_ipp_status(con
, IPP_BAD_REQUEST
,
1160 _("Nested classes are not allowed."));
1165 * Add it to the class...
1168 cupsdAddPrinterToClass(pclass
, member
);
1172 set_printer_defaults(con
, pclass
);
1174 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1175 IPP_TAG_KEYWORD
)) != NULL
)
1176 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1179 * Update the printer class attributes and return...
1182 cupsdSetPrinterAttrs(pclass
);
1183 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1185 if (need_restart_job
&& pclass
->job
)
1188 * Reset the current job to a "pending" status...
1191 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1192 "Job restarted because the class was modified.");
1195 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1199 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1200 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1201 pclass
->name
, get_username(con
));
1203 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1204 pclass
->name
, get_username(con
));
1208 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1209 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1210 pclass
->name
, get_username(con
));
1212 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1213 pclass
->name
, get_username(con
));
1216 con
->response
->request
.status
.status_code
= IPP_OK
;
1221 * 'add_file()' - Add a file to a job.
1224 static int /* O - 0 on success, -1 on error */
1225 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1226 cupsd_job_t
*job
, /* I - Job to add to */
1227 mime_type_t
*filetype
, /* I - Type of file */
1228 int compression
) /* I - Compression */
1230 mime_type_t
**filetypes
; /* New filetypes array... */
1231 int *compressions
; /* New compressions array... */
1234 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1235 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1236 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1237 filetype
->super
, filetype
->type
, compression
);
1240 * Add the file to the job...
1243 if (job
->num_files
== 0)
1245 compressions
= (int *)malloc(sizeof(int));
1246 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1250 compressions
= (int *)realloc(job
->compressions
,
1251 (job
->num_files
+ 1) * sizeof(int));
1252 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1253 (job
->num_files
+ 1) *
1254 sizeof(mime_type_t
*));
1257 if (!compressions
|| !filetypes
)
1259 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1260 "Job aborted because the scheduler ran out of memory.");
1263 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1264 _("Unable to allocate memory for file types."));
1269 job
->compressions
= compressions
;
1270 job
->compressions
[job
->num_files
] = compression
;
1271 job
->filetypes
= filetypes
;
1272 job
->filetypes
[job
->num_files
] = filetype
;
1277 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1284 * 'add_job()' - Add a job to a print queue.
1287 static cupsd_job_t
* /* O - Job object */
1288 add_job(cupsd_client_t
*con
, /* I - Client connection */
1289 cupsd_printer_t
*printer
, /* I - Destination printer */
1290 mime_type_t
*filetype
) /* I - First print file type, if any */
1292 http_status_t status
; /* Policy status */
1293 ipp_attribute_t
*attr
, /* Current attribute */
1294 *auth_info
; /* auth-info attribute */
1295 const char *val
; /* Default option value */
1296 int priority
; /* Job priority */
1297 cupsd_job_t
*job
; /* Current job */
1298 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1299 int kbytes
; /* Size of print file */
1300 int i
; /* Looping var */
1301 int lowerpagerange
; /* Page range bound */
1302 int exact
; /* Did we have an exact match? */
1303 ipp_attribute_t
*media_col
, /* media-col attribute */
1304 *media_margin
; /* media-*-margin attribute */
1305 ipp_t
*unsup_col
; /* media-col in unsupported response */
1308 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1309 con
, con
->http
.fd
, printer
, printer
->name
,
1310 filetype
, filetype
? filetype
->super
: "none",
1311 filetype
? filetype
->type
: "none");
1314 * Check remote printing to non-shared printer...
1317 if (!printer
->shared
&&
1318 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1319 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1321 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1322 _("The printer or class is not shared."));
1330 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1332 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1334 send_http_error(con
, status
, printer
);
1337 else if (printer
->num_auth_info_required
== 1 &&
1338 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1341 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1345 else if (auth_info
&& !con
->http
.tls
&&
1346 !httpAddrLocalhost(con
->http
.hostaddr
))
1349 * Require encryption of auth-info over non-local connections...
1352 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1355 #endif /* HAVE_SSL */
1358 * See if the printer is accepting jobs...
1361 if (!printer
->accepting
)
1363 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1364 _("Destination \"%s\" is not accepting jobs."),
1370 * Validate job template attributes; for now just document-format,
1371 * copies, number-up, and page-ranges...
1374 if (filetype
&& printer
->filetypes
&&
1375 !cupsArrayFind(printer
->filetypes
, filetype
))
1377 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1378 /* MIME media type string */
1381 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1384 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1385 _("Unsupported format \"%s\"."), mimetype
);
1387 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1388 "document-format", NULL
, mimetype
);
1393 if ((attr
= ippFindAttribute(con
->request
, "copies",
1394 IPP_TAG_INTEGER
)) != NULL
)
1396 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1398 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1399 attr
->values
[0].integer
);
1400 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1401 "copies", attr
->values
[0].integer
);
1406 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1407 IPP_TAG_ZERO
)) != NULL
)
1409 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1410 attr
->value_tag
!= IPP_TAG_NAME
)
1412 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1416 if (attr
->num_values
> 2)
1418 send_ipp_status(con
, IPP_BAD_REQUEST
,
1419 _("Too many job-sheets values (%d > 2)."),
1424 for (i
= 0; i
< attr
->num_values
; i
++)
1425 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1426 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1428 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1429 attr
->values
[i
].string
.text
);
1434 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1435 IPP_TAG_INTEGER
)) != NULL
)
1437 if (attr
->values
[0].integer
!= 1 &&
1438 attr
->values
[0].integer
!= 2 &&
1439 attr
->values
[0].integer
!= 4 &&
1440 attr
->values
[0].integer
!= 6 &&
1441 attr
->values
[0].integer
!= 9 &&
1442 attr
->values
[0].integer
!= 16)
1444 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1445 attr
->values
[0].integer
);
1446 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1447 "number-up", attr
->values
[0].integer
);
1452 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1453 IPP_TAG_RANGE
)) != NULL
)
1455 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1457 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1458 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1460 send_ipp_status(con
, IPP_BAD_REQUEST
,
1461 _("Bad page-ranges values %d-%d."),
1462 attr
->values
[i
].range
.lower
,
1463 attr
->values
[i
].range
.upper
);
1467 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1472 * Do media selection as needed...
1475 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1476 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1477 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1480 (media_col
= ippFindAttribute(con
->request
, "media-col",
1481 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1483 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1485 unsup_col
= ippNew();
1486 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1487 "media-bottom-margin",
1488 IPP_TAG_INTEGER
)) != NULL
)
1489 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1490 "media-bottom-margin", media_margin
->values
[0].integer
);
1492 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1493 "media-left-margin",
1494 IPP_TAG_INTEGER
)) != NULL
)
1495 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1496 "media-left-margin", media_margin
->values
[0].integer
);
1498 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1499 "media-right-margin",
1500 IPP_TAG_INTEGER
)) != NULL
)
1501 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1502 "media-right-margin", media_margin
->values
[0].integer
);
1504 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1506 IPP_TAG_INTEGER
)) != NULL
)
1507 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1508 "media-top-margin", media_margin
->values
[0].integer
);
1510 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1512 ippDelete(unsup_col
);
1517 * Make sure we aren't over our limit...
1520 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1523 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1525 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1529 if ((i
= check_quotas(con
, printer
)) < 0)
1531 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1536 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1541 * Create the job and set things up...
1544 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1545 IPP_TAG_INTEGER
)) != NULL
)
1546 priority
= attr
->values
[0].integer
;
1549 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1550 printer
->options
)) != NULL
)
1551 priority
= atoi(val
);
1555 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1559 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1560 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1563 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1565 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1566 _("Unable to add job for destination \"%s\"."),
1571 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1572 job
->attrs
= con
->request
;
1574 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1576 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1579 apply_printer_defaults(printer
, job
);
1581 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1583 if (con
->username
[0])
1585 cupsdSetString(&job
->username
, con
->username
);
1588 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1592 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1593 "add_job: requesting-user-name=\"%s\"",
1594 attr
->values
[0].string
.text
);
1596 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1599 cupsdSetString(&job
->username
, "anonymous");
1602 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1603 "job-originating-user-name", NULL
, job
->username
);
1606 attr
->group_tag
= IPP_TAG_JOB
;
1607 _cupsStrFree(attr
->name
);
1608 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1611 if (con
->username
[0] || auth_info
)
1613 save_auth_info(con
, job
, auth_info
);
1616 * Remove the auth-info attribute from the attribute data...
1620 ippDeleteAttribute(job
->attrs
, auth_info
);
1623 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1624 IPP_TAG_ZERO
)) != NULL
)
1627 * Request contains a job-originating-host-name attribute; validate it...
1630 if (attr
->value_tag
!= IPP_TAG_NAME
||
1631 attr
->num_values
!= 1 ||
1632 strcmp(con
->http
.hostname
, "localhost"))
1635 * Can't override the value if we aren't connected via localhost.
1636 * Also, we can only have 1 value and it must be a name value.
1639 switch (attr
->value_tag
)
1641 case IPP_TAG_STRING
:
1642 case IPP_TAG_TEXTLANG
:
1643 case IPP_TAG_NAMELANG
:
1646 case IPP_TAG_KEYWORD
:
1648 case IPP_TAG_URISCHEME
:
1649 case IPP_TAG_CHARSET
:
1650 case IPP_TAG_LANGUAGE
:
1651 case IPP_TAG_MIMETYPE
:
1653 * Free old strings...
1656 for (i
= 0; i
< attr
->num_values
; i
++)
1658 _cupsStrFree(attr
->values
[i
].string
.text
);
1659 attr
->values
[i
].string
.text
= NULL
;
1660 if (attr
->values
[i
].string
.language
)
1662 _cupsStrFree(attr
->values
[i
].string
.language
);
1663 attr
->values
[i
].string
.language
= NULL
;
1672 * Use the default connection hostname instead...
1675 attr
->value_tag
= IPP_TAG_NAME
;
1676 attr
->num_values
= 1;
1677 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1680 attr
->group_tag
= IPP_TAG_JOB
;
1685 * No job-originating-host-name attribute, so use the hostname from
1689 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1690 "job-originating-host-name", NULL
, con
->http
.hostname
);
1693 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1695 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1696 "time-at-processing", 0);
1697 attr
->value_tag
= IPP_TAG_NOVALUE
;
1698 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1699 "time-at-completed", 0);
1700 attr
->value_tag
= IPP_TAG_NOVALUE
;
1703 * Add remaining job attributes...
1706 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1707 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1708 "job-state", IPP_JOB_STOPPED
);
1709 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1710 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1711 "job-state-reasons", NULL
, "job-incoming");
1712 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1713 "job-media-sheets-completed", 0);
1714 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1717 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1718 IPP_TAG_INTEGER
)) != NULL
)
1719 attr
->values
[0].integer
= 0;
1721 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1723 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1724 IPP_TAG_KEYWORD
)) == NULL
)
1725 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1728 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1729 printer
->options
)) == NULL
)
1732 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1733 "job-hold-until", NULL
, val
);
1735 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1738 * Hold job until specified time...
1741 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1743 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1744 job
->state_value
= IPP_JOB_HELD
;
1746 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1748 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1750 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1751 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1752 job
->state_value
= IPP_JOB_HELD
;
1756 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1757 job
->state_value
= IPP_JOB_PENDING
;
1759 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1762 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1765 * Add job sheets options...
1768 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1769 IPP_TAG_ZERO
)) == NULL
)
1771 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1772 "Adding default job-sheets values \"%s,%s\"...",
1773 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1775 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1777 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1778 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1781 job
->job_sheets
= attr
;
1784 * Enforce classification level if set...
1789 cupsdLogMessage(CUPSD_LOG_INFO
,
1790 "Classification=\"%s\", ClassifyOverride=%d",
1791 Classification
? Classification
: "(null)",
1794 if (ClassifyOverride
)
1796 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1797 (attr
->num_values
== 1 ||
1798 !strcmp(attr
->values
[1].string
.text
, "none")))
1801 * Force the leading banner to have the classification on it...
1804 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1806 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1807 "job-sheets=\"%s,none\", "
1808 "job-originating-user-name=\"%s\"",
1809 Classification
, job
->username
);
1811 else if (attr
->num_values
== 2 &&
1812 strcmp(attr
->values
[0].string
.text
,
1813 attr
->values
[1].string
.text
) &&
1814 strcmp(attr
->values
[0].string
.text
, "none") &&
1815 strcmp(attr
->values
[1].string
.text
, "none"))
1818 * Can't put two different security markings on the same document!
1821 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1823 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1824 "job-sheets=\"%s,%s\", "
1825 "job-originating-user-name=\"%s\"",
1826 attr
->values
[0].string
.text
,
1827 attr
->values
[1].string
.text
, job
->username
);
1829 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1830 strcmp(attr
->values
[0].string
.text
, "none") &&
1831 (attr
->num_values
== 1 ||
1832 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1833 strcmp(attr
->values
[1].string
.text
, "none"))))
1835 if (attr
->num_values
== 1)
1836 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1837 "CLASSIFICATION OVERRIDDEN "
1838 "job-sheets=\"%s\", "
1839 "job-originating-user-name=\"%s\"",
1840 attr
->values
[0].string
.text
, job
->username
);
1842 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1843 "CLASSIFICATION OVERRIDDEN "
1844 "job-sheets=\"%s,%s\",fffff "
1845 "job-originating-user-name=\"%s\"",
1846 attr
->values
[0].string
.text
,
1847 attr
->values
[1].string
.text
, job
->username
);
1850 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1851 (attr
->num_values
== 1 ||
1852 strcmp(attr
->values
[1].string
.text
, Classification
)))
1855 * Force the banner to have the classification on it...
1858 if (attr
->num_values
> 1 &&
1859 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1861 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1862 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1866 if (attr
->num_values
== 1 ||
1867 strcmp(attr
->values
[0].string
.text
, "none"))
1868 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1870 if (attr
->num_values
> 1 &&
1871 strcmp(attr
->values
[1].string
.text
, "none"))
1872 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1875 if (attr
->num_values
> 1)
1876 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1877 "CLASSIFICATION FORCED "
1878 "job-sheets=\"%s,%s\", "
1879 "job-originating-user-name=\"%s\"",
1880 attr
->values
[0].string
.text
,
1881 attr
->values
[1].string
.text
, job
->username
);
1883 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1884 "CLASSIFICATION FORCED "
1885 "job-sheets=\"%s\", "
1886 "job-originating-user-name=\"%s\"",
1887 Classification
, job
->username
);
1892 * See if we need to add the starting sheet...
1895 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1897 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1898 attr
->values
[0].string
.text
);
1900 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1902 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1903 "Aborting job because the start banner could not be "
1908 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1911 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1912 IPP_TAG_ZERO
)) != NULL
)
1913 job
->job_sheets
= attr
;
1916 * Fill in the response info...
1919 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1920 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1921 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1924 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1926 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1928 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1929 NULL
, job
->reasons
->values
[0].string
.text
);
1931 con
->response
->request
.status
.status_code
= IPP_OK
;
1934 * Add any job subscriptions...
1937 add_job_subscriptions(con
, job
);
1940 * Set all but the first two attributes to the job attributes group...
1943 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1944 attr
->group_tag
= IPP_TAG_JOB
;
1947 * Fire the "job created" event...
1950 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1953 * Return the new job...
1961 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1965 add_job_subscriptions(
1966 cupsd_client_t
*con
, /* I - Client connection */
1967 cupsd_job_t
*job
) /* I - Newly created job */
1969 int i
; /* Looping var */
1970 ipp_attribute_t
*prev
, /* Previous attribute */
1971 *next
, /* Next attribute */
1972 *attr
; /* Current attribute */
1973 cupsd_subscription_t
*sub
; /* Subscription object */
1974 const char *recipient
, /* notify-recipient-uri */
1975 *pullmethod
; /* notify-pull-method */
1976 ipp_attribute_t
*user_data
; /* notify-user-data */
1977 int interval
; /* notify-time-interval */
1978 unsigned mask
; /* notify-events */
1982 * Find the first subscription group attribute; return if we have
1986 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1987 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1994 * Process the subscription attributes in the request...
2003 mask
= CUPSD_EVENT_NONE
;
2005 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2007 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2008 attr
->value_tag
== IPP_TAG_URI
)
2011 * Validate the recipient scheme against the ServerBin/notifier
2015 char notifier
[1024], /* Notifier filename */
2016 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2017 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2018 host
[HTTP_MAX_URI
], /* Host portion of URI */
2019 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2020 int port
; /* Port portion of URI */
2023 recipient
= attr
->values
[0].string
.text
;
2025 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2026 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2027 host
, sizeof(host
), &port
,
2028 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2030 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2031 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2032 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2033 "notify-status-code", IPP_URI_SCHEME
);
2037 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2039 if (access(notifier
, X_OK
))
2041 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2042 _("notify-recipient-uri URI \"%s\" uses unknown "
2043 "scheme."), recipient
);
2044 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2045 "notify-status-code", IPP_URI_SCHEME
);
2049 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2051 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2052 _("notify-recipient-uri URI \"%s\" is already used."),
2054 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2055 "notify-status-code", IPP_ATTRIBUTES
);
2059 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2060 attr
->value_tag
== IPP_TAG_KEYWORD
)
2062 pullmethod
= attr
->values
[0].string
.text
;
2064 if (strcmp(pullmethod
, "ippget"))
2066 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2067 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2068 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2069 "notify-status-code", IPP_ATTRIBUTES
);
2073 else if (!strcmp(attr
->name
, "notify-charset") &&
2074 attr
->value_tag
== IPP_TAG_CHARSET
&&
2075 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2076 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2078 send_ipp_status(con
, IPP_CHARSET
,
2079 _("Character set \"%s\" not supported."),
2080 attr
->values
[0].string
.text
);
2083 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2084 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2085 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2087 send_ipp_status(con
, IPP_CHARSET
,
2088 _("Language \"%s\" not supported."),
2089 attr
->values
[0].string
.text
);
2092 else if (!strcmp(attr
->name
, "notify-user-data") &&
2093 attr
->value_tag
== IPP_TAG_STRING
)
2095 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2097 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2098 _("The notify-user-data value is too large "
2099 "(%d > 63 octets)."),
2100 attr
->values
[0].unknown
.length
);
2106 else if (!strcmp(attr
->name
, "notify-events") &&
2107 attr
->value_tag
== IPP_TAG_KEYWORD
)
2109 for (i
= 0; i
< attr
->num_values
; i
++)
2110 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2112 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2114 send_ipp_status(con
, IPP_BAD_REQUEST
,
2115 _("The notify-lease-duration attribute cannot be "
2116 "used with job subscriptions."));
2119 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2120 attr
->value_tag
== IPP_TAG_INTEGER
)
2121 interval
= attr
->values
[0].integer
;
2126 if (!recipient
&& !pullmethod
)
2129 if (mask
== CUPSD_EVENT_NONE
)
2130 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2132 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2133 recipient
, 0)) != NULL
)
2135 sub
->interval
= interval
;
2137 cupsdSetString(&sub
->owner
, job
->username
);
2141 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2142 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2143 sub
->user_data_len
);
2146 ippAddSeparator(con
->response
);
2147 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2148 "notify-subscription-id", sub
->id
);
2150 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2158 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2161 * Remove all of the subscription attributes from the job request...
2163 * TODO: Optimize this since subscription groups have to come at the
2164 * end of the request...
2167 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2171 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2172 attr
->group_tag
== IPP_TAG_ZERO
)
2175 * Free and remove this attribute...
2178 ippDeleteAttribute(NULL
, attr
);
2183 job
->attrs
->attrs
= next
;
2189 job
->attrs
->last
= prev
;
2190 job
->attrs
->current
= prev
;
2195 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2197 * See RFC 4122 for the definition of UUIDs and the format.
2201 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2203 char uuid
[64]; /* job-uuid string */
2207 * Add a job-uuid attribute if none exists...
2210 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2211 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2212 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2213 uuid
, sizeof(uuid
)));
2218 * 'add_printer()' - Add a printer to the system.
2222 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2223 ipp_attribute_t
*uri
) /* I - URI of printer */
2225 http_status_t status
; /* Policy status */
2226 int i
; /* Looping var */
2227 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2228 username
[HTTP_MAX_URI
], /* Username portion of URI */
2229 host
[HTTP_MAX_URI
], /* Host portion of URI */
2230 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2231 int port
; /* Port portion of URI */
2232 cupsd_printer_t
*printer
; /* Printer/class */
2233 ipp_attribute_t
*attr
; /* Printer attribute */
2234 cups_file_t
*fp
; /* Script/PPD file */
2235 char line
[1024]; /* Line from file... */
2236 char srcfile
[1024], /* Source Script/PPD file */
2237 dstfile
[1024]; /* Destination Script/PPD file */
2238 int modify
; /* Non-zero if we are modifying */
2239 int changed_driver
, /* Changed the PPD/interface script? */
2240 need_restart_job
, /* Need to restart job? */
2241 set_device_uri
, /* Did we set the device URI? */
2242 set_port_monitor
; /* Did we set the port monitor? */
2245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2246 con
->http
.fd
, uri
->values
[0].string
.text
);
2249 * Do we have a valid URI?
2252 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2253 sizeof(scheme
), username
, sizeof(username
), host
,
2254 sizeof(host
), &port
, resource
, sizeof(resource
));
2256 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2259 * No, return an error...
2262 send_ipp_status(con
, IPP_BAD_REQUEST
,
2263 _("The printer-uri must be of the form "
2264 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2269 * Do we have a valid printer name?
2272 if (!validate_name(resource
+ 10))
2275 * No, return an error...
2278 send_ipp_status(con
, IPP_BAD_REQUEST
,
2279 _("The printer-uri \"%s\" contains invalid characters."),
2280 uri
->values
[0].string
.text
);
2285 * See if the printer already exists; if not, create a new printer...
2288 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2291 * Printer doesn't exist; see if we have a class of the same name...
2294 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2297 * Yes, return an error...
2300 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2301 _("A class named \"%s\" already exists."),
2307 * No, check the default policy then add the printer...
2310 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2312 send_http_error(con
, status
, NULL
);
2316 printer
= cupsdAddPrinter(resource
+ 10);
2319 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2322 send_http_error(con
, status
, printer
);
2329 * Look for attributes and copy them over as needed...
2333 need_restart_job
= 0;
2335 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2336 IPP_TAG_TEXT
)) != NULL
)
2337 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2340 IPP_TAG_TEXT
)) != NULL
)
2341 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2345 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2346 IPP_TAG_URI
)) != NULL
)
2349 * Do we have a valid device URI?
2352 http_uri_status_t uri_status
; /* URI separation status */
2353 char old_device_uri
[1024];
2354 /* Old device URI */
2357 need_restart_job
= 1;
2359 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2360 attr
->values
[0].string
.text
,
2361 scheme
, sizeof(scheme
),
2362 username
, sizeof(username
),
2363 host
, sizeof(host
), &port
,
2364 resource
, sizeof(resource
));
2366 if (uri_status
< HTTP_URI_OK
)
2368 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2369 attr
->values
[0].string
.text
);
2370 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2371 "add_printer: httpSeparateURI returned %d", uri_status
);
2375 if (!strcmp(scheme
, "file"))
2378 * See if the administrator has enabled file devices...
2381 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2384 * File devices are disabled and the URL is not file:/dev/null...
2387 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2388 _("File device URIs have been disabled. "
2389 "To enable, see the FileDevice directive in "
2390 "\"%s/cupsd.conf\"."),
2398 * See if the backend exists and is executable...
2401 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2402 if (access(srcfile
, X_OK
))
2405 * Could not find device in list!
2408 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2409 _("Bad device-uri scheme \"%s\"."), scheme
);
2414 if (printer
->sanitized_device_uri
)
2415 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2416 sizeof(old_device_uri
));
2418 old_device_uri
[0] = '\0';
2420 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2422 cupsdLogMessage(CUPSD_LOG_INFO
,
2423 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2424 printer
->name
, printer
->sanitized_device_uri
,
2430 set_port_monitor
= 0;
2432 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2433 IPP_TAG_NAME
)) != NULL
)
2435 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2438 need_restart_job
= 1;
2440 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2444 for (i
= 0; i
< supported
->num_values
; i
++)
2445 if (!strcmp(supported
->values
[i
].string
.text
,
2446 attr
->values
[0].string
.text
))
2450 if (!supported
|| i
>= supported
->num_values
)
2452 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2453 attr
->values
[0].string
.text
);
2457 cupsdLogMessage(CUPSD_LOG_INFO
,
2458 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2459 printer
->name
, attr
->values
[0].string
.text
,
2460 printer
->port_monitor
? printer
->port_monitor
: "none");
2462 if (strcmp(attr
->values
[0].string
.text
, "none"))
2463 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2465 cupsdClearString(&printer
->port_monitor
);
2467 set_port_monitor
= 1;
2470 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2471 IPP_TAG_BOOLEAN
)) != NULL
&&
2472 attr
->values
[0].boolean
!= printer
->accepting
)
2474 cupsdLogMessage(CUPSD_LOG_INFO
,
2475 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2476 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2478 printer
->accepting
= attr
->values
[0].boolean
;
2480 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2481 "%s accepting jobs.",
2482 printer
->accepting
? "Now" : "No longer");
2485 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2486 IPP_TAG_BOOLEAN
)) != NULL
)
2488 if (attr
->values
[0].boolean
&&
2489 printer
->num_auth_info_required
== 1 &&
2490 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2492 send_ipp_status(con
, IPP_BAD_REQUEST
,
2493 _("Cannot share a remote Kerberized printer."));
2497 if (printer
->shared
&& !attr
->values
[0].boolean
)
2498 cupsdDeregisterPrinter(printer
, 1);
2500 cupsdLogMessage(CUPSD_LOG_INFO
,
2501 "Setting %s printer-is-shared to %d (was %d.)",
2502 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2504 printer
->shared
= attr
->values
[0].boolean
;
2507 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2508 IPP_TAG_ENUM
)) != NULL
)
2510 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2511 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2513 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2514 attr
->values
[0].integer
);
2518 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2519 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2521 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2522 cupsdStopPrinter(printer
, 0);
2525 need_restart_job
= 1;
2526 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2530 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2531 IPP_TAG_TEXT
)) != NULL
)
2533 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2534 sizeof(printer
->state_message
));
2536 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2537 printer
->state_message
);
2540 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2541 IPP_TAG_KEYWORD
)) != NULL
)
2543 if (attr
->num_values
>
2544 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2546 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2547 _("Too many printer-state-reasons values (%d > %d)."),
2549 (int)(sizeof(printer
->reasons
) /
2550 sizeof(printer
->reasons
[0])));
2554 for (i
= 0; i
< printer
->num_reasons
; i
++)
2555 _cupsStrFree(printer
->reasons
[i
]);
2557 printer
->num_reasons
= 0;
2558 for (i
= 0; i
< attr
->num_values
; i
++)
2560 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2563 printer
->reasons
[printer
->num_reasons
] =
2564 _cupsStrRetain(attr
->values
[i
].string
.text
);
2565 printer
->num_reasons
++;
2567 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2568 printer
->state
!= IPP_PRINTER_STOPPED
)
2570 cupsdLogMessage(CUPSD_LOG_INFO
,
2571 "Setting %s printer-state to %d (was %d.)",
2572 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2573 cupsdStopPrinter(printer
, 0);
2577 if (PrintcapFormat
== PRINTCAP_PLIST
)
2578 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2580 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2581 "Printer \"%s\" state changed.", printer
->name
);
2584 set_printer_defaults(con
, printer
);
2586 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2587 IPP_TAG_KEYWORD
)) != NULL
)
2588 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2591 * See if we have all required attributes...
2594 if (!printer
->device_uri
)
2595 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2598 * See if we have an interface script or PPD file attached to the request...
2603 need_restart_job
= 1;
2606 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2608 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2611 * Yes; get the first line from it...
2615 cupsFileGets(fp
, line
, sizeof(line
));
2619 * Then see what kind of file it is...
2622 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2625 if (!strncmp(line
, "*PPD-Adobe", 10))
2628 * The new file is a PPD file, so remove any old interface script
2629 * that might be lying around...
2637 * This must be an interface script, so move the file over to the
2638 * interfaces directory and make it executable...
2641 if (copy_file(srcfile
, dstfile
))
2643 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2644 _("Unable to copy interface script - %s"),
2649 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2650 "Copied interface script successfully");
2651 chmod(dstfile
, 0755);
2654 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2657 if (!strncmp(line
, "*PPD-Adobe", 10))
2660 * The new file is a PPD file, so move the file over to the
2661 * ppd directory and make it readable by all...
2664 if (copy_file(srcfile
, dstfile
))
2666 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2667 _("Unable to copy PPD file - %s"),
2672 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2673 "Copied PPD file successfully");
2674 chmod(dstfile
, 0644);
2679 * This must be an interface script, so remove any old PPD file that
2680 * may be lying around...
2687 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2688 IPP_TAG_NAME
)) != NULL
)
2690 need_restart_job
= 1;
2693 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2696 * Raw driver, remove any existing PPD or interface script files.
2699 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2703 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2713 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2717 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2720 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2722 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2726 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2727 "Copied PPD file successfully");
2728 chmod(dstfile
, 0644);
2735 * If we changed the PPD/interface script, then remove the printer's cache
2736 * file and clear the printer-state-reasons...
2739 char cache_name
[1024]; /* Cache filename for printer attrs */
2741 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2745 cupsdSetPrinterReasons(printer
, "none");
2749 * (Re)register color profiles...
2754 apple_unregister_profiles(printer
);
2755 apple_register_profiles(printer
);
2757 #endif /* __APPLE__ */
2761 * If we set the device URI but not the port monitor, check which port
2762 * monitor to use by default...
2765 if (set_device_uri
&& !set_port_monitor
)
2767 ppd_file_t
*ppd
; /* PPD file */
2768 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2771 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2772 sizeof(scheme
), username
, sizeof(username
), host
,
2773 sizeof(host
), &port
, resource
, sizeof(resource
));
2775 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2777 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2779 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2781 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2782 if (!strcmp(scheme
, ppdattr
->spec
))
2784 cupsdLogMessage(CUPSD_LOG_INFO
,
2785 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2786 printer
->name
, ppdattr
->value
,
2787 printer
->port_monitor
? printer
->port_monitor
2790 if (strcmp(ppdattr
->value
, "none"))
2791 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2793 cupsdClearString(&printer
->port_monitor
);
2803 * Update the printer attributes and return...
2806 cupsdSetPrinterAttrs(printer
);
2807 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2809 if (need_restart_job
&& printer
->job
)
2812 * Restart the current job...
2815 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2816 "Job restarted because the printer was modified.");
2819 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2823 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2824 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2825 printer
->name
, get_username(con
));
2827 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2828 printer
->name
, get_username(con
));
2832 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2833 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2834 printer
->name
, get_username(con
));
2836 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2837 printer
->name
, get_username(con
));
2840 con
->response
->request
.status
.status_code
= IPP_OK
;
2845 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2846 * based upon the printer state...
2850 add_printer_state_reasons(
2851 cupsd_client_t
*con
, /* I - Client connection */
2852 cupsd_printer_t
*p
) /* I - Printer info */
2854 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2855 "add_printer_state_reasons(%p[%d], %p[%s])",
2856 con
, con
->http
.fd
, p
, p
->name
);
2858 if (p
->num_reasons
== 0)
2859 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2860 "printer-state-reasons", NULL
, "none");
2862 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2863 "printer-state-reasons", p
->num_reasons
, NULL
,
2864 (const char * const *)p
->reasons
);
2869 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2870 * the specified printer or class.
2874 add_queued_job_count(
2875 cupsd_client_t
*con
, /* I - Client connection */
2876 cupsd_printer_t
*p
) /* I - Printer or class */
2878 int count
; /* Number of jobs on destination */
2881 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2882 con
, con
->http
.fd
, p
, p
->name
);
2884 count
= cupsdGetPrinterJobCount(p
->name
);
2886 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2887 "queued-job-count", count
);
2893 * 'apple_init_profile()' - Initialize a color profile.
2898 ppd_file_t
*ppd
, /* I - PPD file */
2899 cups_array_t
*languages
, /* I - Languages in the PPD file */
2900 # ifdef HAVE_COLORSYNCREGISTERDEVICE
2901 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
2903 CMDeviceProfileInfo
*profile
, /* I - Profile record */
2904 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
2905 unsigned id
, /* I - Profile ID */
2906 const char *name
, /* I - Profile name */
2907 const char *text
, /* I - Profile UI text */
2908 const char *iccfile
) /* I - ICC filename */
2910 # ifdef HAVE_COLORSYNCREGISTERDEVICE
2911 CFURLRef url
; /* URL for profile filename */
2912 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
2913 CFMutableDictionaryRef dict
; /* Dictionary for name */
2914 char *language
; /* Current language */
2915 ppd_attr_t
*attr
; /* Profile attribute */
2916 CFStringRef cflang
, /* Language string */
2917 cftext
; /* Localized text */
2923 * Build the profile name dictionary...
2926 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2927 &kCFTypeDictionaryKeyCallBacks
,
2928 &kCFTypeDictionaryValueCallBacks
);
2931 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize profile \"%s\".",
2936 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
2937 kCFStringEncodingUTF8
);
2941 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
2948 * Find localized names for the color profiles...
2951 cupsArraySave(ppd
->sorted_attrs
);
2953 for (language
= (char *)cupsArrayFirst(languages
);
2955 language
= (char *)cupsArrayNext(languages
))
2959 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
2961 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
2964 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
2966 if (attr
&& attr
->text
[0])
2968 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
2969 kCFStringEncodingUTF8
);
2970 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
2971 kCFStringEncodingUTF8
);
2973 if (cflang
&& cftext
)
2974 CFDictionarySetValue(dict
, cflang
, cftext
);
2984 cupsArrayRestore(ppd
->sorted_attrs
);
2988 * Fill in the profile data...
2991 # ifdef HAVE_COLORSYNCREGISTERDEVICE
2994 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
2995 (const UInt8
*)iccfile
,
2996 strlen(iccfile
), false);
3000 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3005 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3009 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3010 profile
->profileID
= id
;
3011 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3012 profile
->profileName
= dict
;
3015 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3016 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3017 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3022 * 'apple_register_profiles()' - Register color profiles for a printer.
3026 apple_register_profiles(
3027 cupsd_printer_t
*p
) /* I - Printer */
3029 int i
; /* Looping var */
3030 char ppdfile
[1024], /* PPD filename */
3031 iccfile
[1024], /* ICC filename */
3032 selector
[PPD_MAX_NAME
];
3033 /* Profile selection string */
3034 ppd_file_t
*ppd
; /* PPD file */
3035 ppd_attr_t
*attr
, /* Profile attributes */
3036 *profileid_attr
,/* cupsProfileID attribute */
3037 *q1_attr
, /* ColorModel (or other) qualifier */
3038 *q2_attr
, /* MediaType (or other) qualifier */
3039 *q3_attr
; /* Resolution (or other) qualifier */
3040 char q_keyword
[PPD_MAX_NAME
];
3041 /* Qualifier keyword */
3042 const char *q1_choice
, /* ColorModel (or other) choice */
3043 *q2_choice
, /* MediaType (or other) choice */
3044 *q3_choice
; /* Resolution (or other) choice */
3045 const char *profile_key
; /* Profile keyword */
3046 ppd_option_t
*cm_option
; /* Color model option */
3047 ppd_choice_t
*cm_choice
; /* Color model choice */
3048 int num_profiles
; /* Number of profiles */
3049 OSStatus error
= 0; /* Last error */
3050 unsigned device_id
, /* Printer device ID */
3051 profile_id
= 0, /* Profile ID */
3052 default_profile_id
= 0;
3053 /* Default profile ID */
3054 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3055 CFStringRef printer_name
; /* Printer name string */
3056 cups_array_t
*languages
; /* Languages array */
3057 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3058 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3059 profile
; /* Current profile info dictionary */
3060 CFStringRef dict_key
; /* Key in factory profile dictionary */
3062 CMDeviceScope scope
= /* Scope of the registration */
3064 kCFPreferencesAnyUser
,
3065 kCFPreferencesCurrentHost
3067 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3068 CMDeviceProfileInfo
*profile
; /* Current profile */
3069 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3073 * Make sure ColorSync is available...
3076 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3077 if (ColorSyncRegisterDevice
== NULL
)
3081 if (CMRegisterColorDevice
== NULL
)
3083 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3086 * Try opening the PPD file for this printer...
3089 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3090 if ((ppd
= _ppdOpenFile(ppdfile
, _PPD_LOCALIZATION_ICC_PROFILES
)) == NULL
)
3094 * See if we have any profiles...
3097 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3098 profile_key
= "APTiogaProfile";
3101 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3102 profile_key
= "cupsICCProfile";
3105 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3106 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3108 if (attr
->value
[0] != '/')
3109 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3112 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3114 if (access(iccfile
, 0))
3116 cupsdLogMessage(CUPSD_LOG_ERROR
,
3117 "%s: ICC Profile \"%s\" does not exist.", p
->name
,
3125 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3127 * Create a dictionary for the factory profiles...
3130 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3131 &kCFTypeDictionaryKeyCallBacks
,
3132 &kCFTypeDictionaryValueCallBacks
);
3135 cupsdLogMessage(CUPSD_LOG_ERROR
,
3136 "Unable to allocate memory for factory profiles.");
3140 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3143 * If we have profiles, add them...
3146 if (num_profiles
> 0)
3148 if (profile_key
[0] == 'A')
3151 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3155 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3157 default_profile_id
= atoi(attr
->value
);
3159 q1_choice
= q2_choice
= q3_choice
= NULL
;
3164 * For CUPS PPDs, figure out the default profile selector values...
3167 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3168 attr
->value
&& attr
->value
[0])
3170 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3171 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3173 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3174 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3176 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3177 q1_choice
= q1_attr
->value
;
3181 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3182 attr
->value
&& attr
->value
[0])
3184 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3185 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3188 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3190 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3191 q2_choice
= q2_attr
->value
;
3195 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3196 attr
->value
&& attr
->value
[0])
3198 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3199 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3202 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3204 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3205 q3_choice
= q3_attr
->value
;
3210 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3212 * Build the array of profiles...
3214 * Note: This calloc actually requests slightly more memory than needed.
3217 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3219 cupsdLogMessage(CUPSD_LOG_ERROR
,
3220 "Unable to allocate memory for factory profiles.");
3225 profiles
->profileCount
= num_profiles
;
3226 profile
= profiles
->profiles
;
3227 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3230 * Loop through the profiles listed in the PPD...
3233 languages
= _ppdGetLanguages(ppd
);
3235 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3237 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3238 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3241 * Add this profile...
3244 if (attr
->value
[0] != '/')
3245 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3248 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3250 if (_cupsFileCheck(iccfile
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
3251 cupsdLogFCMessage
, p
))
3254 if (profile_key
[0] == 'c')
3256 cupsArraySave(ppd
->sorted_attrs
);
3258 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3259 attr
->spec
)) != NULL
&&
3260 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3261 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3263 profile_id
= _ppdHashName(attr
->spec
);
3265 cupsArrayRestore(ppd
->sorted_attrs
);
3268 profile_id
= atoi(attr
->spec
);
3270 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3271 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3272 &kCFTypeDictionaryKeyCallBacks
,
3273 &kCFTypeDictionaryValueCallBacks
);
3276 cupsdLogMessage(CUPSD_LOG_ERROR
,
3277 "Unable to allocate memory for color profile.");
3278 CFRelease(profiles
);
3283 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3284 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3286 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3287 CFSTR("%u"), profile_id
);
3290 CFDictionarySetValue(profiles
, dict_key
, profile
);
3291 CFRelease(dict_key
);
3297 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3298 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3301 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3304 * See if this is the default profile...
3307 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3309 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3311 if (!strcmp(selector
, attr
->spec
))
3312 default_profile_id
= profile_id
;
3315 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3317 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3318 if (!strcmp(selector
, attr
->spec
))
3319 default_profile_id
= profile_id
;
3322 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3324 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3325 if (!strcmp(selector
, attr
->spec
))
3326 default_profile_id
= profile_id
;
3329 if (!default_profile_id
&& q1_choice
)
3331 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3332 if (!strcmp(selector
, attr
->spec
))
3333 default_profile_id
= profile_id
;
3336 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3338 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3339 if (!strcmp(selector
, attr
->spec
))
3340 default_profile_id
= profile_id
;
3343 if (!default_profile_id
&& q2_choice
)
3345 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3346 if (!strcmp(selector
, attr
->spec
))
3347 default_profile_id
= profile_id
;
3350 if (!default_profile_id
&& q3_choice
)
3352 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3353 if (!strcmp(selector
, attr
->spec
))
3354 default_profile_id
= profile_id
;
3358 _ppdFreeLanguages(languages
);
3360 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3363 * Extract profiles from ColorModel option...
3366 const char *profile_name
; /* Name of generic profile */
3369 num_profiles
= cm_option
->num_choices
;
3371 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3373 * Create an array for the factory profiles...
3376 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3378 cupsdLogMessage(CUPSD_LOG_ERROR
,
3379 "Unable to allocate memory for factory profiles.");
3384 profiles
->profileCount
= num_profiles
;
3385 profile
= profiles
->profiles
;
3386 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3388 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3392 if (!strcmp(cm_choice
->choice
, "Gray") ||
3393 !strcmp(cm_choice
->choice
, "Black"))
3394 profile_name
= "Gray";
3395 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3396 !strcmp(cm_choice
->choice
, "CMY"))
3397 profile_name
= "RGB";
3398 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3399 !strcmp(cm_choice
->choice
, "KCMY"))
3400 profile_name
= "CMYK";
3402 profile_name
= "DeviceN";
3404 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3405 profile_id
= _ppdHashName(selector
);
3407 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3408 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3409 &kCFTypeDictionaryKeyCallBacks
,
3410 &kCFTypeDictionaryValueCallBacks
);
3413 cupsdLogMessage(CUPSD_LOG_ERROR
,
3414 "Unable to allocate memory for color profile.");
3415 CFRelease(profiles
);
3420 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3421 cm_choice
->text
, NULL
);
3423 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3424 CFSTR("%u"), profile_id
);
3427 CFDictionarySetValue(profiles
, dict_key
, profile
);
3428 CFRelease(dict_key
);
3434 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3435 cm_choice
->text
, NULL
);
3437 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3439 if (cm_choice
->marked
)
3440 default_profile_id
= profile_id
;
3446 * Use the default colorspace...
3449 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3451 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3453 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3455 * Add the grayscale profile first. We always have a grayscale profile.
3458 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3459 &kCFTypeDictionaryKeyCallBacks
,
3460 &kCFTypeDictionaryValueCallBacks
);
3464 cupsdLogMessage(CUPSD_LOG_ERROR
,
3465 "Unable to allocate memory for color profile.");
3466 CFRelease(profiles
);
3471 profile_id
= _ppdHashName("Gray..");
3472 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3474 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3478 CFDictionarySetValue(profiles
, dict_key
, profile
);
3479 CFRelease(dict_key
);
3485 * Then add the RGB/CMYK/DeviceN color profile...
3488 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3489 &kCFTypeDictionaryKeyCallBacks
,
3490 &kCFTypeDictionaryValueCallBacks
);
3494 cupsdLogMessage(CUPSD_LOG_ERROR
,
3495 "Unable to allocate memory for color profile.");
3496 CFRelease(profiles
);
3501 switch (ppd
->colorspace
)
3506 profile_id
= _ppdHashName("RGB..");
3507 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3513 profile_id
= _ppdHashName("CMYK..");
3514 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3523 profile_id
= _ppdHashName("DeviceN..");
3524 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3529 if (CFDictionaryGetCount(profile
) > 0)
3531 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3532 CFSTR("%u"), profile_id
);
3535 CFDictionarySetValue(profiles
, dict_key
, profile
);
3536 CFRelease(dict_key
);
3544 * Create an array for the factory profiles...
3547 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3549 cupsdLogMessage(CUPSD_LOG_ERROR
,
3550 "Unable to allocate memory for factory profiles.");
3555 profiles
->profileCount
= num_profiles
;
3558 * Add the grayscale profile first. We always have a grayscale profile.
3561 profile_id
= _ppdHashName("Gray..");
3562 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3566 * Then add the RGB/CMYK/DeviceN color profile...
3569 switch (ppd
->colorspace
)
3574 profile_id
= _ppdHashName("RGB..");
3575 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3576 "RGB", "RGB", NULL
);
3580 profile_id
= _ppdHashName("CMYK..");
3581 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3582 "CMYK", "CMYK", NULL
);
3590 profile_id
= _ppdHashName("DeviceN..");
3591 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3592 "DeviceN", "DeviceN", NULL
);
3595 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3598 if (num_profiles
> 0)
3601 * Make sure we have a default profile ID...
3604 if (!default_profile_id
)
3605 default_profile_id
= profile_id
; /* Last profile */
3607 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3608 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3609 default_profile_id
);
3612 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3614 CFRelease(dict_key
);
3616 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3619 * Get the device ID hash and pathelogical name dictionary.
3622 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3625 device_id
= _ppdHashName(p
->name
);
3626 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3627 &kCFTypeDictionaryKeyCallBacks
,
3628 &kCFTypeDictionaryValueCallBacks
);
3629 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3630 p
->name
, kCFStringEncodingUTF8
);
3632 if (device_name
&& printer_name
)
3634 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3637 * Register the device with ColorSync...
3640 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3641 CFTypeRef deviceDictKeys
[] =
3643 kColorSyncDeviceDescriptions
,
3644 kColorSyncFactoryProfiles
,
3645 kColorSyncDeviceUserScope
,
3646 kColorSyncDeviceHostScope
3648 CFTypeRef deviceDictVals
[] =
3649 { /* Device values */
3652 kCFPreferencesAnyUser
,
3653 kCFPreferencesCurrentHost
3655 CFDictionaryRef deviceDict
; /* Device dictionary */
3656 CFUUIDRef deviceUUID
; /* Device UUID */
3658 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3659 (const void **)deviceDictKeys
,
3660 (const void **)deviceDictVals
,
3661 sizeof(deviceDictKeys
) /
3662 sizeof(deviceDictKeys
[0]),
3663 &kCFTypeDictionaryKeyCallBacks
,
3664 &kCFTypeDictionaryValueCallBacks
);
3665 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3667 if (!deviceDict
|| !deviceUUID
||
3668 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3673 CFRelease(deviceUUID
);
3676 CFRelease(deviceDict
);
3679 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3680 device_name
, &scope
);
3683 * Register the profiles...
3687 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3688 default_profile_id
, profiles
);
3689 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3699 cupsdLogMessage(CUPSD_LOG_ERROR
,
3700 "Unable to register ICC color profiles for \"%s\": %d",
3701 p
->name
, (int)error
);
3704 CFRelease(printer_name
);
3707 CFRelease(device_name
);
3711 * Free any memory we used...
3714 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3715 CFRelease(profiles
);
3718 if (num_profiles
> 0)
3720 for (profile
= profiles
->profiles
;
3722 profile
++, num_profiles
--)
3723 CFRelease(profile
->profileName
);
3727 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3734 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3739 apple_unregister_profiles(
3740 cupsd_printer_t
*p
) /* I - Printer */
3743 * Make sure ColorSync is available...
3746 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3747 if (ColorSyncUnregisterDevice
!= NULL
)
3750 * Because we may have registered the printer profiles using a prior device
3751 * ID-based UUID, remove both the old style UUID and current UUID for the
3755 CFUUIDRef deviceUUID
; /* Device UUID */
3757 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3760 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3761 CFRelease(deviceUUID
);
3766 if (CMUnregisterColorDevice
!= NULL
)
3767 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3768 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3770 #endif /* __APPLE__ */
3774 * 'apply_printer_defaults()' - Apply printer default options to a job.
3778 apply_printer_defaults(
3779 cupsd_printer_t
*printer
, /* I - Printer */
3780 cupsd_job_t
*job
) /* I - Job */
3782 int i
, /* Looping var */
3783 num_options
; /* Number of default options */
3784 cups_option_t
*options
, /* Default options */
3785 *option
; /* Current option */
3789 * Collect all of the default options and add the missing ones to the
3793 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3794 option
= printer
->options
;
3797 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3799 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3804 * Encode these options as attributes in the job object...
3807 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3808 cupsFreeOptions(num_options
, options
);
3813 * 'authenticate_job()' - Set job authentication info.
3817 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3818 ipp_attribute_t
*uri
) /* I - Job URI */
3820 ipp_attribute_t
*attr
, /* job-id attribute */
3821 *auth_info
; /* auth-info attribute */
3822 int jobid
; /* Job ID */
3823 cupsd_job_t
*job
; /* Current job */
3824 char scheme
[HTTP_MAX_URI
],
3825 /* Method portion of URI */
3826 username
[HTTP_MAX_URI
],
3827 /* Username portion of URI */
3829 /* Host portion of URI */
3830 resource
[HTTP_MAX_URI
];
3831 /* Resource portion of URI */
3832 int port
; /* Port portion of URI */
3835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3836 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3839 * Start with "everything is OK" status...
3842 con
->response
->request
.status
.status_code
= IPP_OK
;
3845 * See if we have a job URI or a printer URI...
3848 if (!strcmp(uri
->name
, "printer-uri"))
3851 * Got a printer URI; see if we also have a job-id attribute...
3854 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3855 IPP_TAG_INTEGER
)) == NULL
)
3857 send_ipp_status(con
, IPP_BAD_REQUEST
,
3858 _("Got a printer-uri attribute but no job-id."));
3862 jobid
= attr
->values
[0].integer
;
3867 * Got a job URI; parse it to get the job ID...
3870 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3871 sizeof(scheme
), username
, sizeof(username
), host
,
3872 sizeof(host
), &port
, resource
, sizeof(resource
));
3874 if (strncmp(resource
, "/jobs/", 6))
3880 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3881 uri
->values
[0].string
.text
);
3885 jobid
= atoi(resource
+ 6);
3889 * See if the job exists...
3892 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3895 * Nope - return a "not found" error...
3898 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3903 * See if the job has been completed...
3906 if (job
->state_value
!= IPP_JOB_HELD
)
3909 * Return a "not-possible" error...
3912 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3913 _("Job #%d is not held for authentication."),
3919 * See if we have already authenticated...
3922 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3924 if (!con
->username
[0] && !auth_info
)
3926 cupsd_printer_t
*printer
; /* Job destination */
3929 * No auth data. If we need to authenticate via Kerberos, send a
3930 * HTTP auth challenge, otherwise just return an IPP error...
3933 printer
= cupsdFindDest(job
->dest
);
3935 if (printer
&& printer
->num_auth_info_required
> 0 &&
3936 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3937 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3939 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3940 _("No authentication information provided."));
3945 * See if the job is owned by the requesting user...
3948 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3950 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3951 cupsdFindDest(job
->dest
));
3956 * Save the authentication information for this job...
3959 save_auth_info(con
, job
, auth_info
);
3962 * Reset the job-hold-until value to "no-hold"...
3965 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3966 IPP_TAG_KEYWORD
)) == NULL
)
3967 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3971 attr
->value_tag
= IPP_TAG_KEYWORD
;
3972 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3976 * Release the job and return...
3979 cupsdReleaseJob(job
);
3981 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3983 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3990 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3994 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3995 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3997 int i
; /* Looping var */
3998 http_status_t status
; /* Policy status */
3999 cups_ptype_t dtype
; /* Destination type */
4000 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4001 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4002 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4003 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4004 int port
; /* Port portion of URI */
4005 ipp_attribute_t
*attr
; /* Attribute in request */
4006 const char *username
= NULL
; /* Username */
4007 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4009 cupsd_printer_t
*printer
; /* Printer */
4010 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4011 cupsd_job_t
*job
; /* Job */
4014 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4015 con
->http
.fd
, uri
->values
[0].string
.text
);
4018 * Get the jobs to cancel/purge...
4021 switch (con
->request
->request
.op
.operation_id
)
4023 case IPP_PURGE_JOBS
:
4025 * Get the username (if any) for the jobs we want to cancel (only if
4026 * "my-jobs" is specified...
4029 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4030 IPP_TAG_BOOLEAN
)) != NULL
&&
4031 attr
->values
[0].boolean
)
4033 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4034 IPP_TAG_NAME
)) != NULL
)
4035 username
= attr
->values
[0].string
.text
;
4038 send_ipp_status(con
, IPP_BAD_REQUEST
,
4039 _("Missing requesting-user-name attribute."));
4045 * Look for the "purge-jobs" attribute...
4048 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4049 IPP_TAG_BOOLEAN
)) != NULL
)
4050 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4052 purge
= CUPSD_JOB_PURGE
;
4055 case IPP_CANCEL_MY_JOBS
:
4056 if (con
->username
[0])
4057 username
= con
->username
;
4058 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4059 IPP_TAG_NAME
)) != NULL
)
4060 username
= attr
->values
[0].string
.text
;
4063 send_ipp_status(con
, IPP_BAD_REQUEST
,
4064 _("Missing requesting-user-name attribute."));
4072 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4075 * See if we have a printer URI...
4078 if (strcmp(uri
->name
, "printer-uri"))
4080 send_ipp_status(con
, IPP_BAD_REQUEST
,
4081 _("The printer-uri attribute is required."));
4086 * And if the destination is valid...
4089 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4095 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4096 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4097 hostname
, sizeof(hostname
), &port
,
4098 resource
, sizeof(resource
));
4100 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4101 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4103 send_ipp_status(con
, IPP_NOT_FOUND
,
4104 _("The printer or class does not exist."));
4112 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4114 send_http_error(con
, status
, NULL
);
4120 for (i
= 0; i
< job_ids
->num_values
; i
++)
4122 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4126 if (i
< job_ids
->num_values
)
4128 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4129 job_ids
->values
[i
].integer
);
4133 for (i
= 0; i
< job_ids
->num_values
; i
++)
4135 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4137 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4138 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4139 "Job canceled by user.");
4142 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4143 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4149 * Cancel all jobs on all printers...
4152 cupsdCancelJobs(NULL
, username
, purge
);
4154 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4155 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4165 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4168 send_http_error(con
, status
, printer
);
4174 for (i
= 0; i
< job_ids
->num_values
; i
++)
4176 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4177 _cups_strcasecmp(job
->dest
, printer
->name
))
4181 if (i
< job_ids
->num_values
)
4183 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4184 job_ids
->values
[i
].integer
);
4188 for (i
= 0; i
< job_ids
->num_values
; i
++)
4190 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4192 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4193 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4194 "Job canceled by user.");
4197 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4198 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4204 * Cancel all of the jobs on the named printer...
4207 cupsdCancelJobs(printer
->name
, username
, purge
);
4209 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4211 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4216 con
->response
->request
.status
.status_code
= IPP_OK
;
4221 * 'cancel_job()' - Cancel a print job.
4225 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4226 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4228 ipp_attribute_t
*attr
; /* Current attribute */
4229 int jobid
; /* Job ID */
4230 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4231 username
[HTTP_MAX_URI
], /* Username portion of URI */
4232 host
[HTTP_MAX_URI
], /* Host portion of URI */
4233 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4234 int port
; /* Port portion of URI */
4235 cupsd_job_t
*job
; /* Job information */
4236 cups_ptype_t dtype
; /* Destination type (printer/class) */
4237 cupsd_printer_t
*printer
; /* Printer data */
4238 cupsd_jobaction_t purge
; /* Purge the job? */
4241 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4242 con
->http
.fd
, uri
->values
[0].string
.text
);
4245 * See if we have a job URI or a printer URI...
4248 if (!strcmp(uri
->name
, "printer-uri"))
4251 * Got a printer URI; see if we also have a job-id attribute...
4254 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4255 IPP_TAG_INTEGER
)) == NULL
)
4257 send_ipp_status(con
, IPP_BAD_REQUEST
,
4258 _("Got a printer-uri attribute but no job-id."));
4262 if ((jobid
= attr
->values
[0].integer
) == 0)
4265 * Find the current job on the specified printer...
4268 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4274 send_ipp_status(con
, IPP_NOT_FOUND
,
4275 _("The printer or class does not exist."));
4280 * See if there are any pending jobs...
4283 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4285 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4286 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4287 !_cups_strcasecmp(job
->dest
, printer
->name
))
4295 * No, try stopped jobs...
4298 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4300 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4301 if (job
->state_value
== IPP_JOB_STOPPED
&&
4302 !_cups_strcasecmp(job
->dest
, printer
->name
))
4309 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4319 * Got a job URI; parse it to get the job ID...
4322 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4323 sizeof(scheme
), username
, sizeof(username
), host
,
4324 sizeof(host
), &port
, resource
, sizeof(resource
));
4326 if (strncmp(resource
, "/jobs/", 6))
4332 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4333 uri
->values
[0].string
.text
);
4337 jobid
= atoi(resource
+ 6);
4341 * Look for the "purge-job" attribute...
4344 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4345 IPP_TAG_BOOLEAN
)) != NULL
)
4346 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4348 purge
= CUPSD_JOB_DEFAULT
;
4351 * See if the job exists...
4354 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4357 * Nope - return a "not found" error...
4360 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4365 * See if the job is owned by the requesting user...
4368 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4370 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4371 cupsdFindDest(job
->dest
));
4376 * See if the job is already completed, canceled, or aborted; if so,
4377 * we can't cancel...
4380 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4382 switch (job
->state_value
)
4384 case IPP_JOB_CANCELED
:
4385 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4386 _("Job #%d is already canceled - can\'t cancel."),
4390 case IPP_JOB_ABORTED
:
4391 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4392 _("Job #%d is already aborted - can\'t cancel."),
4397 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4398 _("Job #%d is already completed - can\'t cancel."),
4407 * Cancel the job and return...
4410 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4411 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4412 "Job canceled by \"%s\"",
4416 if (purge
== CUPSD_JOB_PURGE
)
4417 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4420 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4423 con
->response
->request
.status
.status_code
= IPP_OK
;
4428 * 'cancel_subscription()' - Cancel a subscription.
4432 cancel_subscription(
4433 cupsd_client_t
*con
, /* I - Client connection */
4434 int sub_id
) /* I - Subscription ID */
4436 http_status_t status
; /* Policy status */
4437 cupsd_subscription_t
*sub
; /* Subscription */
4440 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4441 "cancel_subscription(con=%p[%d], sub_id=%d)",
4442 con
, con
->http
.fd
, sub_id
);
4445 * Is the subscription ID valid?
4448 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4451 * Bad subscription ID...
4454 send_ipp_status(con
, IPP_NOT_FOUND
,
4455 _("Subscription #%d does not exist."), sub_id
);
4463 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4465 con
, sub
->owner
)) != HTTP_OK
)
4467 send_http_error(con
, status
, sub
->dest
);
4472 * Cancel the subscription...
4475 cupsdDeleteSubscription(sub
, 1);
4477 con
->response
->request
.status
.status_code
= IPP_OK
;
4482 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4485 static int /* O - 1 if OK, 0 if not */
4486 check_rss_recipient(
4487 const char *recipient
) /* I - Recipient URI */
4489 cupsd_subscription_t
*sub
; /* Current subscription */
4492 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4494 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4498 * Compare the URIs up to the first ?...
4501 const char *r1
, *r2
;
4503 for (r1
= recipient
, r2
= sub
->recipient
;
4504 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4516 * 'check_quotas()' - Check quotas for a printer and user.
4519 static int /* O - 1 if OK, 0 if forbidden,
4520 -1 if limit reached */
4521 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4522 cupsd_printer_t
*p
) /* I - Printer or class */
4524 char username
[33], /* Username */
4525 *name
; /* Current user name */
4526 cupsd_quota_t
*q
; /* Quota data */
4527 #ifdef HAVE_MBR_UID_TO_UUID
4529 * Use Apple membership APIs which require that all names represent
4530 * valid user account or group records accessible by the server.
4533 uuid_t usr_uuid
; /* UUID for job requesting user */
4534 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4535 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4536 int mbr_err
; /* Error from membership function */
4537 int is_member
; /* Is this user a member? */
4540 * Use standard POSIX APIs for checking users and groups...
4543 struct passwd
*pw
; /* User password data */
4544 #endif /* HAVE_MBR_UID_TO_UUID */
4547 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4548 con
, con
->http
.fd
, p
, p
->name
);
4551 * Figure out who is printing...
4554 strlcpy(username
, get_username(con
), sizeof(username
));
4556 if ((name
= strchr(username
, '@')) != NULL
)
4557 *name
= '\0'; /* Strip @REALM */
4560 * Check global active job limits for printers and users...
4563 if (MaxJobsPerPrinter
)
4566 * Check if there are too many pending jobs on this printer...
4569 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4571 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4580 * Check if there are too many pending jobs for this user...
4583 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4585 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4592 * Check against users...
4595 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4598 if (cupsArrayCount(p
->users
))
4600 #ifdef HAVE_MBR_UID_TO_UUID
4602 * Get UUID for job requesting user...
4605 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4611 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4612 "check_quotas: UUID lookup failed for user \"%s\"",
4614 cupsdLogMessage(CUPSD_LOG_INFO
,
4615 "Denying user \"%s\" access to printer \"%s\" "
4616 "(unknown user)...",
4622 * Get UID and GID of requesting user...
4625 pw
= getpwnam(username
);
4627 #endif /* HAVE_MBR_UID_TO_UUID */
4629 for (name
= (char *)cupsArrayFirst(p
->users
);
4631 name
= (char *)cupsArrayNext(p
->users
))
4635 * Check group membership...
4638 #ifdef HAVE_MBR_UID_TO_UUID
4641 if (uuid_parse(name
+ 2, grp_uuid
))
4642 uuid_clear(grp_uuid
);
4644 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4647 * Invalid ACL entries are ignored for matching; just record a
4648 * warning in the log...
4651 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4652 "check_quotas: UUID lookup failed for ACL entry "
4653 "\"%s\" (err=%d)", name
, mbr_err
);
4654 cupsdLogMessage(CUPSD_LOG_WARN
,
4655 "Access control entry \"%s\" not a valid group name; "
4656 "entry ignored", name
);
4659 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4663 * At this point, there should be no errors, but check anyways...
4666 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4667 "check_quotas: group \"%s\" membership check "
4668 "failed (err=%d)", name
+ 1, mbr_err
);
4673 * Stop if we found a match...
4680 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4682 #endif /* HAVE_MBR_UID_TO_UUID */
4684 #ifdef HAVE_MBR_UID_TO_UUID
4689 if (uuid_parse(name
+ 1, usr2_uuid
))
4690 uuid_clear(usr2_uuid
);
4692 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4695 * Invalid ACL entries are ignored for matching; just record a
4696 * warning in the log...
4699 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4700 "check_quotas: UUID lookup failed for ACL entry "
4701 "\"%s\" (err=%d)", name
, mbr_err
);
4702 cupsdLogMessage(CUPSD_LOG_WARN
,
4703 "Access control entry \"%s\" not a valid user name; "
4704 "entry ignored", name
);
4707 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4711 else if (!_cups_strcasecmp(username
, name
))
4713 #endif /* HAVE_MBR_UID_TO_UUID */
4715 if ((name
!= NULL
) == p
->deny_users
)
4717 cupsdLogMessage(CUPSD_LOG_INFO
,
4718 "Denying user \"%s\" access to printer \"%s\"...",
4728 if (p
->k_limit
|| p
->page_limit
)
4730 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4732 cupsdLogMessage(CUPSD_LOG_ERROR
,
4733 "Unable to allocate quota data for user \"%s\"",
4738 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4739 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4741 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4748 * If we have gotten this far, we're done!
4756 * 'close_job()' - Close a multi-file job.
4760 close_job(cupsd_client_t
*con
, /* I - Client connection */
4761 ipp_attribute_t
*uri
) /* I - Printer URI */
4763 cupsd_job_t
*job
; /* Job */
4764 ipp_attribute_t
*attr
; /* Attribute */
4765 char job_uri
[HTTP_MAX_URI
],
4767 username
[256]; /* User name */
4770 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4771 con
->http
.fd
, uri
->values
[0].string
.text
);
4774 * See if we have a job URI or a printer URI...
4777 if (strcmp(uri
->name
, "printer-uri"))
4780 * job-uri is not supported by Close-Job!
4783 send_ipp_status(con
, IPP_BAD_REQUEST
,
4784 _("Close-Job doesn't support the job-uri attribute."));
4789 * Got a printer URI; see if we also have a job-id attribute...
4792 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4793 IPP_TAG_INTEGER
)) == NULL
)
4795 send_ipp_status(con
, IPP_BAD_REQUEST
,
4796 _("Got a printer-uri attribute but no job-id."));
4800 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4803 * Nope - return a "not found" error...
4806 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4807 attr
->values
[0].integer
);
4812 * See if the job is owned by the requesting user...
4815 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4817 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4818 cupsdFindDest(job
->dest
));
4823 * Add any ending sheet...
4826 if (cupsdTimeoutJob(job
))
4829 if (job
->state_value
== IPP_JOB_STOPPED
)
4831 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4832 job
->state_value
= IPP_JOB_PENDING
;
4834 else if (job
->state_value
== IPP_JOB_HELD
)
4836 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4837 IPP_TAG_KEYWORD
)) == NULL
)
4838 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4840 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4842 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4843 job
->state_value
= IPP_JOB_PENDING
;
4848 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4851 * Fill in the response info...
4854 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4855 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
4856 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4859 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4861 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4864 con
->response
->request
.status
.status_code
= IPP_OK
;
4867 * Start the job if necessary...
4875 * 'copy_attrs()' - Copy attributes from one request to another.
4879 copy_attrs(ipp_t
*to
, /* I - Destination request */
4880 ipp_t
*from
, /* I - Source request */
4881 cups_array_t
*ra
, /* I - Requested attributes */
4882 ipp_tag_t group
, /* I - Group to copy */
4883 int quickcopy
, /* I - Do a quick copy? */
4884 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4886 ipp_attribute_t
*fromattr
; /* Source attribute */
4889 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4890 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4891 to
, from
, ra
, group
, quickcopy
);
4896 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4899 * Filter attributes as needed...
4902 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4903 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4906 if (!strcmp(fromattr
->name
, "job-printer-uri"))
4910 (cupsArrayFind(exclude
, fromattr
->name
) ||
4911 cupsArrayFind(exclude
, "all")))
4914 * We need to exclude this attribute for security reasons; we require the
4915 * job-id attribute regardless of the security settings for IPP
4918 * The job-printer-uri attribute is handled by copy_job_attrs().
4920 * Subscription attribute security is handled by copy_subscription_attrs().
4923 if (strcmp(fromattr
->name
, "job-id"))
4927 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4930 * Don't send collection attributes by default to IPP/1.x clients
4931 * since many do not support collections. Also don't send
4932 * media-col-database unless specifically requested by the client.
4935 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4937 (to
->request
.status
.version
[0] == 1 ||
4938 !strcmp(fromattr
->name
, "media-col-database")))
4941 ippCopyAttribute(to
, fromattr
, quickcopy
);
4948 * 'copy_banner()' - Copy a banner file to the requests directory for the
4952 static int /* O - Size of banner file in kbytes */
4953 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4954 cupsd_job_t
*job
, /* I - Job information */
4955 const char *name
) /* I - Name of banner */
4957 int i
; /* Looping var */
4958 int kbytes
; /* Size of banner file in kbytes */
4959 char filename
[1024]; /* Job filename */
4960 cupsd_banner_t
*banner
; /* Pointer to banner */
4961 cups_file_t
*in
; /* Input file */
4962 cups_file_t
*out
; /* Output file */
4963 int ch
; /* Character from file */
4964 char attrname
[255], /* Name of attribute */
4965 *s
; /* Pointer into name */
4966 ipp_attribute_t
*attr
; /* Attribute */
4969 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4970 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4971 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4972 name
? name
: "(null)");
4975 * Find the banner; return if not found or "none"...
4978 if (!name
|| !strcmp(name
, "none") ||
4979 (banner
= cupsdFindBanner(name
)) == NULL
)
4983 * Open the banner and job files...
4986 if (add_file(con
, job
, banner
->filetype
, 0))
4989 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4991 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4993 cupsdLogMessage(CUPSD_LOG_ERROR
,
4994 "Unable to create banner job file %s - %s",
4995 filename
, strerror(errno
));
5000 fchmod(cupsFileNumber(out
), 0640);
5001 fchown(cupsFileNumber(out
), RunUser
, Group
);
5004 * Try the localized banner file under the subdirectory...
5007 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5009 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5012 * Convert ll-cc to ll_CC...
5016 attrname
[3] = toupper(attrname
[3] & 255);
5017 attrname
[4] = toupper(attrname
[4] & 255);
5020 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5023 if (access(filename
, 0) && strlen(attrname
) > 2)
5026 * Wasn't able to find "ll_CC" locale file; try the non-national
5027 * localization banner directory.
5032 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5036 if (access(filename
, 0))
5039 * Use the non-localized banner file.
5042 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5045 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5049 cupsdLogMessage(CUPSD_LOG_ERROR
,
5050 "Unable to open banner template file %s - %s",
5051 filename
, strerror(errno
));
5057 * Parse the file to the end...
5060 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5064 * Get an attribute name...
5067 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5068 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5070 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5080 * Ignore { followed by stuff that is not an attribute name...
5083 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5088 * See if it is defined...
5091 if (attrname
[0] == '?')
5096 if (!strcmp(s
, "printer-name"))
5098 cupsFilePuts(out
, job
->dest
);
5101 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5104 * See if we have a leading question mark...
5107 if (attrname
[0] != '?')
5110 * Nope, write to file as-is; probably a PostScript procedure...
5113 cupsFilePrintf(out
, "{%s}", attrname
);
5120 * Output value(s)...
5123 for (i
= 0; i
< attr
->num_values
; i
++)
5126 cupsFilePutChar(out
, ',');
5128 switch (attr
->value_tag
)
5130 case IPP_TAG_INTEGER
:
5132 if (!strncmp(s
, "time-at-", 8))
5134 struct timeval tv
; /* Time value */
5136 tv
.tv_sec
= attr
->values
[i
].integer
;
5139 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5142 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5145 case IPP_TAG_BOOLEAN
:
5146 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5149 case IPP_TAG_NOVALUE
:
5150 cupsFilePuts(out
, "novalue");
5153 case IPP_TAG_RANGE
:
5154 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5155 attr
->values
[i
].range
.upper
);
5158 case IPP_TAG_RESOLUTION
:
5159 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5160 attr
->values
[i
].resolution
.yres
,
5161 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5166 case IPP_TAG_STRING
:
5169 case IPP_TAG_KEYWORD
:
5170 case IPP_TAG_CHARSET
:
5171 case IPP_TAG_LANGUAGE
:
5172 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
5175 * Need to quote strings for PS banners...
5180 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5182 if (*p
== '(' || *p
== ')' || *p
== '\\')
5184 cupsFilePutChar(out
, '\\');
5185 cupsFilePutChar(out
, *p
);
5187 else if (*p
< 32 || *p
> 126)
5188 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5190 cupsFilePutChar(out
, *p
);
5194 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5198 break; /* anti-compiler-warning-code */
5202 else if (ch
== '\\') /* Quoted char */
5204 ch
= cupsFileGetChar(in
);
5206 if (ch
!= '{') /* Only do special handling for \{ */
5207 cupsFilePutChar(out
, '\\');
5209 cupsFilePutChar(out
, ch
);
5212 cupsFilePutChar(out
, ch
);
5216 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5218 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5219 IPP_TAG_INTEGER
)) != NULL
)
5220 attr
->values
[0].integer
+= kbytes
;
5229 * 'copy_file()' - Copy a PPD file or interface script...
5232 static int /* O - 0 = success, -1 = error */
5233 copy_file(const char *from
, /* I - Source file */
5234 const char *to
) /* I - Destination file */
5236 cups_file_t
*src
, /* Source file */
5237 *dst
; /* Destination file */
5238 int bytes
; /* Bytes to read/write */
5239 char buffer
[2048]; /* Copy buffer */
5242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5245 * Open the source and destination file for a copy...
5248 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5251 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5258 * Copy the source file to the destination...
5261 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5262 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5270 * Close both files and return...
5275 return (cupsFileClose(dst
));
5280 * 'copy_model()' - Copy a PPD model file, substituting default values
5284 static int /* O - 0 = success, -1 = error */
5285 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5286 const char *from
, /* I - Source file */
5287 const char *to
) /* I - Destination file */
5289 fd_set input
; /* select() input set */
5290 struct timeval timeout
; /* select() timeout */
5291 int maxfd
; /* Max file descriptor for select() */
5292 char tempfile
[1024]; /* Temporary PPD file */
5293 int tempfd
; /* Temporary PPD file descriptor */
5294 int temppid
; /* Process ID of cups-driverd */
5295 int temppipe
[2]; /* Temporary pipes */
5296 char *argv
[4], /* Command-line arguments */
5297 *envp
[MAX_ENV
]; /* Environment */
5298 cups_file_t
*src
, /* Source file */
5299 *dst
; /* Destination file */
5300 ppd_file_t
*ppd
; /* PPD file */
5301 int bytes
, /* Bytes from pipe */
5302 total
; /* Total bytes from pipe */
5303 char buffer
[2048]; /* Copy buffer */
5304 int i
; /* Looping var */
5305 char option
[PPD_MAX_NAME
], /* Option name */
5306 choice
[PPD_MAX_NAME
]; /* Choice name */
5307 ppd_size_t
*size
; /* Default size */
5308 int num_defaults
; /* Number of default options */
5309 cups_option_t
*defaults
; /* Default options */
5310 char cups_protocol
[PPD_MAX_LINE
];
5311 /* cupsProtocol attribute */
5314 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5315 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5319 * Run cups-driverd to get the PPD file...
5322 argv
[0] = "cups-driverd";
5324 argv
[2] = (char *)from
;
5327 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5329 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5330 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5331 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5332 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
5335 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5336 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5338 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5339 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5350 * Wait up to 30 seconds for the PPD file to be copied...
5355 if (temppipe
[0] > CGIPipes
[0])
5356 maxfd
= temppipe
[0] + 1;
5358 maxfd
= CGIPipes
[0] + 1;
5363 * See if we have data ready...
5367 FD_SET(temppipe
[0], &input
);
5368 FD_SET(CGIPipes
[0], &input
);
5370 timeout
.tv_sec
= 30;
5371 timeout
.tv_usec
= 0;
5373 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5383 * We have timed out...
5389 if (FD_ISSET(temppipe
[0], &input
))
5392 * Read the PPD file from the pipe, and write it to the PPD file.
5395 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5397 if (write(tempfd
, buffer
, bytes
) < bytes
)
5406 if (FD_ISSET(CGIPipes
[0], &input
))
5416 * No data from cups-deviced...
5419 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5425 * Open the source file for a copy...
5428 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5435 * Read the source file and see what page sizes are supported...
5438 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
5446 * Open the destination (if possible) and set the default options...
5451 cups_protocol
[0] = '\0';
5453 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5456 * Read all of the default lines from the old PPD...
5459 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5460 if (!strncmp(buffer
, "*Default", 8))
5463 * Add the default option...
5466 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5467 choice
, sizeof(choice
)))
5469 ppd_option_t
*ppdo
; /* PPD option */
5473 * Only add the default if the default hasn't already been
5474 * set and the choice exists in the new PPD...
5477 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5478 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5479 ppdFindChoice(ppdo
, choice
))
5480 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5484 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5485 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5489 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5492 * Add the default media sizes...
5495 num_defaults
= cupsAddOption("PageSize", size
->name
,
5496 num_defaults
, &defaults
);
5497 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5498 num_defaults
, &defaults
);
5499 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5500 num_defaults
, &defaults
);
5501 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5502 num_defaults
, &defaults
);
5508 * Open the destination file for a copy...
5511 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5513 cupsFreeOptions(num_defaults
, defaults
);
5520 * Copy the source file to the destination...
5523 cupsFileRewind(src
);
5525 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5527 if (!strncmp(buffer
, "*Default", 8))
5530 * Check for an previous default option choice...
5533 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5534 choice
, sizeof(choice
)))
5536 const char *val
; /* Default option value */
5539 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5542 * Substitute the previous choice...
5545 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5550 cupsFilePrintf(dst
, "%s\n", buffer
);
5553 if (cups_protocol
[0])
5554 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5556 cupsFreeOptions(num_defaults
, defaults
);
5559 * Close both files and return...
5566 return (cupsFileClose(dst
));
5571 * 'copy_job_attrs()' - Copy job attributes.
5575 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5576 cupsd_job_t
*job
, /* I - Job */
5577 cups_array_t
*ra
, /* I - Requested attributes array */
5578 cups_array_t
*exclude
) /* I - Private attributes array */
5580 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5584 * Send the requested attributes for each job...
5587 if (!cupsArrayFind(exclude
, "all"))
5589 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
5590 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
5591 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5592 "number-of-documents", job
->num_files
);
5594 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5595 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5596 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5597 "job-media-progress", job
->progress
);
5599 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5600 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5602 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
5603 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
5605 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5606 "job-more-info", NULL
, job_uri
);
5609 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5610 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5611 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5612 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5613 job
->num_files
> 0);
5615 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5616 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5617 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5618 "job-printer-up-time", time(NULL
));
5621 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
5623 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5624 con
->servername
, con
->serverport
,
5625 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
5628 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5629 "job-printer-uri", NULL
, job_uri
);
5632 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5634 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5635 con
->servername
, con
->serverport
, "/jobs/%d",
5637 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5638 "job-uri", NULL
, job_uri
);
5641 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
5646 * 'copy_printer_attrs()' - Copy printer attributes.
5651 cupsd_client_t
*con
, /* I - Client connection */
5652 cupsd_printer_t
*printer
, /* I - Printer */
5653 cups_array_t
*ra
) /* I - Requested attributes array */
5655 char printer_uri
[HTTP_MAX_URI
];
5657 char printer_icons
[HTTP_MAX_URI
];
5659 time_t curtime
; /* Current time */
5660 int i
; /* Looping var */
5664 * Copy the printer attributes to the response using requested-attributes
5665 * and document-format attributes that may be provided by the client.
5668 curtime
= time(NULL
);
5670 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5671 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5672 "marker-change-time", printer
->marker_time
);
5674 if (printer
->num_printers
> 0 &&
5675 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5677 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5678 cupsd_printer_t
*p2
; /* Printer in class */
5679 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5682 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5683 IPP_TAG_URI
, "member-uris",
5684 printer
->num_printers
, NULL
,
5687 for (i
= 0; i
< printer
->num_printers
; i
++)
5689 p2
= printer
->printers
[i
];
5691 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5692 IPP_TAG_URI
)) != NULL
)
5693 member_uris
->values
[i
].string
.text
=
5694 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5697 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5698 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5700 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5701 "/classes/%s" : "/printers/%s", p2
->name
);
5702 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5708 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5709 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5710 "printer-alert", NULL
, printer
->alert
);
5712 if (printer
->alert_description
&&
5713 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5714 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5715 "printer-alert-description", NULL
,
5716 printer
->alert_description
);
5718 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5719 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5720 ippTimeToDate(curtime
));
5723 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5725 if (printer
->reg_name
)
5726 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5727 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5729 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5730 "printer-dns-sd-name", 0);
5732 #endif /* HAVE_DNSSD */
5734 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5735 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5736 "printer-error-policy", NULL
, printer
->error_policy
);
5738 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5740 static const char * const errors
[] =/* printer-error-policy-supported values */
5743 "retry-current-job",
5748 if (printer
->type
& CUPS_PRINTER_CLASS
)
5749 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5750 "printer-error-policy-supported", NULL
, "retry-current-job");
5752 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5753 "printer-error-policy-supported",
5754 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5757 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
5759 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
5760 "http", NULL
, con
->servername
, con
->serverport
,
5761 "/icons/%s.png", printer
->name
);
5762 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5763 NULL
, printer_icons
);
5764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5767 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5768 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5769 printer
->accepting
);
5771 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5772 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5775 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
5777 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5778 "http", NULL
, con
->servername
, con
->serverport
,
5779 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5780 "/classes/%s" : "/printers/%s", printer
->name
);
5781 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5782 "printer-more-info", NULL
, printer_uri
);
5785 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5786 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5787 "printer-op-policy", NULL
, printer
->op_policy
);
5789 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5790 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5793 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5794 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5795 "printer-state-change-time", printer
->state_time
);
5797 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5798 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5799 "printer-state-message", NULL
, printer
->state_message
);
5801 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5802 add_printer_state_reasons(con
, printer
);
5804 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5806 int type
; /* printer-type value */
5809 * Add the CUPS-specific printer-type attribute...
5812 type
= printer
->type
;
5814 if (printer
== DefaultPrinter
)
5815 type
|= CUPS_PRINTER_DEFAULT
;
5817 if (!printer
->accepting
)
5818 type
|= CUPS_PRINTER_REJECTING
;
5820 if (!printer
->shared
)
5821 type
|= CUPS_PRINTER_NOT_SHARED
;
5823 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5827 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5828 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5829 "printer-up-time", curtime
);
5831 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5833 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5834 "ipp", NULL
, con
->servername
, con
->serverport
,
5835 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5836 "/classes/%s" : "/printers/%s", printer
->name
);
5837 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5838 "printer-uri-supported", NULL
, printer_uri
);
5839 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5843 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5844 add_queued_job_count(con
, printer
);
5846 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5847 if (printer
->ppd_attrs
)
5848 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5849 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5854 * 'copy_subscription_attrs()' - Copy subscription attributes.
5858 copy_subscription_attrs(
5859 cupsd_client_t
*con
, /* I - Client connection */
5860 cupsd_subscription_t
*sub
, /* I - Subscription */
5861 cups_array_t
*ra
, /* I - Requested attributes array */
5862 cups_array_t
*exclude
) /* I - Private attributes array */
5864 ipp_attribute_t
*attr
; /* Current attribute */
5865 char printer_uri
[HTTP_MAX_URI
];
5867 int count
; /* Number of events */
5868 unsigned mask
; /* Current event mask */
5869 const char *name
; /* Current event name */
5872 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5873 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5874 con
, sub
, ra
, exclude
);
5877 * Copy the subscription attributes to the response using the
5878 * requested-attributes attribute that may be provided by the client.
5881 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5883 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5884 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5886 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5888 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5891 * Simple event list...
5894 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5895 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5896 "notify-events", NULL
, name
);
5901 * Complex event list...
5904 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5905 if (sub
->mask
& mask
)
5908 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5909 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5910 "notify-events", count
, NULL
, NULL
);
5912 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5913 if (sub
->mask
& mask
)
5915 attr
->values
[count
].string
.text
=
5916 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5923 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5924 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5925 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5926 "notify-lease-duration", sub
->lease
);
5928 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5929 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5930 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5931 "notify-recipient-uri", NULL
, sub
->recipient
);
5932 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5933 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5934 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5935 "notify-pull-method", NULL
, "ippget");
5937 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5938 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5939 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5940 "notify-subscriber-user-name", NULL
, sub
->owner
);
5942 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5943 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5944 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5945 "notify-time-interval", sub
->interval
);
5947 if (sub
->user_data_len
> 0 &&
5948 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5949 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5950 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5951 sub
->user_data
, sub
->user_data_len
);
5954 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5955 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5956 "notify-job-id", sub
->job
->id
);
5958 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5960 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5961 "ipp", NULL
, con
->servername
, con
->serverport
,
5962 "/printers/%s", sub
->dest
->name
);
5963 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5964 "notify-printer-uri", NULL
, printer_uri
);
5967 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5968 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5969 "notify-subscription-id", sub
->id
);
5974 * 'create_job()' - Print a file to a printer or class.
5978 create_job(cupsd_client_t
*con
, /* I - Client connection */
5979 ipp_attribute_t
*uri
) /* I - Printer URI */
5981 cupsd_printer_t
*printer
; /* Printer */
5982 cupsd_job_t
*job
; /* New job */
5985 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5986 con
->http
.fd
, uri
->values
[0].string
.text
);
5989 * Is the destination valid?
5992 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5998 send_ipp_status(con
, IPP_NOT_FOUND
,
5999 _("The printer or class does not exist."));
6004 * Create the job object...
6007 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6010 job
->pending_timeout
= 1;
6013 * Save and log the job...
6016 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6017 job
->dest
, job
->username
);
6022 * 'create_requested_array()' - Create an array for the requested-attributes.
6025 static cups_array_t
* /* O - Array of attributes or NULL */
6026 create_requested_array(ipp_t
*request
) /* I - IPP request */
6028 int i
; /* Looping var */
6029 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6030 cups_array_t
*ra
; /* Requested attributes array */
6031 char *value
; /* Current value */
6035 * Get the requested-attributes attribute, and return NULL if we don't
6039 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6040 IPP_TAG_KEYWORD
)) == NULL
)
6044 * If the attribute contains a single "all" keyword, return NULL...
6047 if (requested
->num_values
== 1 &&
6048 !strcmp(requested
->values
[0].string
.text
, "all"))
6052 * Create an array using "strcmp" as the comparison function...
6055 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6057 for (i
= 0; i
< requested
->num_values
; i
++)
6059 value
= requested
->values
[i
].string
.text
;
6061 if (!strcmp(value
, "job-template"))
6063 /* Only includes the set of Job Template attributes supported by CUPS */
6064 cupsArrayAdd(ra
, "copies");
6065 cupsArrayAdd(ra
, "copies-default");
6066 cupsArrayAdd(ra
, "copies-supported");
6067 cupsArrayAdd(ra
, "finishings");
6068 cupsArrayAdd(ra
, "finishings-default");
6069 cupsArrayAdd(ra
, "finishings-supported");
6070 cupsArrayAdd(ra
, "job-hold-until");
6071 cupsArrayAdd(ra
, "job-hold-until-default");
6072 cupsArrayAdd(ra
, "job-hold-until-supported");
6073 cupsArrayAdd(ra
, "job-priority");
6074 cupsArrayAdd(ra
, "job-priority-default");
6075 cupsArrayAdd(ra
, "job-priority-supported");
6076 cupsArrayAdd(ra
, "job-sheets");
6077 cupsArrayAdd(ra
, "job-sheets-default");
6078 cupsArrayAdd(ra
, "job-sheets-supported");
6079 cupsArrayAdd(ra
, "media");
6080 cupsArrayAdd(ra
, "media-col");
6081 cupsArrayAdd(ra
, "media-col-default");
6082 cupsArrayAdd(ra
, "media-default");
6083 cupsArrayAdd(ra
, "media-supported");
6084 cupsArrayAdd(ra
, "multiple-document-handling");
6085 cupsArrayAdd(ra
, "multiple-document-handling-default");
6086 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6087 cupsArrayAdd(ra
, "number-up");
6088 cupsArrayAdd(ra
, "number-up-default");
6089 cupsArrayAdd(ra
, "number-up-layout");
6090 cupsArrayAdd(ra
, "number-up-layout-default");
6091 cupsArrayAdd(ra
, "number-up-layout-supported");
6092 cupsArrayAdd(ra
, "number-up-supported");
6093 cupsArrayAdd(ra
, "orientation-requested");
6094 cupsArrayAdd(ra
, "orientation-requested-default");
6095 cupsArrayAdd(ra
, "orientation-requested-supported");
6096 cupsArrayAdd(ra
, "output-bin");
6097 cupsArrayAdd(ra
, "output-bin-default");
6098 cupsArrayAdd(ra
, "output-bin-supported");
6099 cupsArrayAdd(ra
, "page-delivery");
6100 cupsArrayAdd(ra
, "page-delivery-default");
6101 cupsArrayAdd(ra
, "page-delivery-supported");
6102 cupsArrayAdd(ra
, "page-order-received");
6103 cupsArrayAdd(ra
, "page-order-received-default");
6104 cupsArrayAdd(ra
, "page-order-received-supported");
6105 cupsArrayAdd(ra
, "page-ranges");
6106 cupsArrayAdd(ra
, "page-ranges-supported");
6107 cupsArrayAdd(ra
, "presentation-direction-number-up");
6108 cupsArrayAdd(ra
, "presentation-direction-number-up-default");
6109 cupsArrayAdd(ra
, "presentation-direction-number-up-supported");
6110 cupsArrayAdd(ra
, "print-color-mode");
6111 cupsArrayAdd(ra
, "print-color-mode-default");
6112 cupsArrayAdd(ra
, "print-color-mode-supported");
6113 cupsArrayAdd(ra
, "print-content-optimize");
6114 cupsArrayAdd(ra
, "print-content-optimize-default");
6115 cupsArrayAdd(ra
, "print-content-optimize-supported");
6116 cupsArrayAdd(ra
, "print-quality");
6117 cupsArrayAdd(ra
, "print-quality-default");
6118 cupsArrayAdd(ra
, "print-quality-supported");
6119 cupsArrayAdd(ra
, "printer-resolution");
6120 cupsArrayAdd(ra
, "printer-resolution-default");
6121 cupsArrayAdd(ra
, "printer-resolution-supported");
6122 cupsArrayAdd(ra
, "sheet-collate");
6123 cupsArrayAdd(ra
, "sheet-collate-default");
6124 cupsArrayAdd(ra
, "sheet-collate-supported");
6125 cupsArrayAdd(ra
, "sides");
6126 cupsArrayAdd(ra
, "sides-default");
6127 cupsArrayAdd(ra
, "sides-supported");
6129 else if (!strcmp(value
, "job-description"))
6131 /* Only includes the set of Job Description attributes supported by CUPS */
6132 cupsArrayAdd(ra
, "date-time-at-completed");
6133 cupsArrayAdd(ra
, "date-time-at-creation");
6134 cupsArrayAdd(ra
, "date-time-at-processing");
6135 cupsArrayAdd(ra
, "job-detailed-status-message");
6136 cupsArrayAdd(ra
, "job-document-access-errors");
6137 cupsArrayAdd(ra
, "job-id");
6138 cupsArrayAdd(ra
, "job-impressions");
6139 cupsArrayAdd(ra
, "job-impressions-completed");
6140 cupsArrayAdd(ra
, "job-k-octets");
6141 cupsArrayAdd(ra
, "job-k-octets-processed");
6142 cupsArrayAdd(ra
, "job-mandatory-attributes");
6143 cupsArrayAdd(ra
, "job-media-progress");
6144 cupsArrayAdd(ra
, "job-media-sheets");
6145 cupsArrayAdd(ra
, "job-media-sheets-completed");
6146 cupsArrayAdd(ra
, "job-message-from-operator");
6147 cupsArrayAdd(ra
, "job-more-info");
6148 cupsArrayAdd(ra
, "job-name");
6149 cupsArrayAdd(ra
, "job-originating-user-name");
6150 cupsArrayAdd(ra
, "job-printer-up-time");
6151 cupsArrayAdd(ra
, "job-printer-uri");
6152 cupsArrayAdd(ra
, "job-state");
6153 cupsArrayAdd(ra
, "job-state-message");
6154 cupsArrayAdd(ra
, "job-state-reasons");
6155 cupsArrayAdd(ra
, "job-uri");
6156 cupsArrayAdd(ra
, "number-of-documents");
6157 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6158 cupsArrayAdd(ra
, "output-device-assigned");
6159 cupsArrayAdd(ra
, "time-at-completed");
6160 cupsArrayAdd(ra
, "time-at-creation");
6161 cupsArrayAdd(ra
, "time-at-processing");
6163 else if (!strcmp(value
, "printer-description"))
6165 /* Only includes the set of Printer Description attributes supported by CUPS */
6166 cupsArrayAdd(ra
, "charset-configured");
6167 cupsArrayAdd(ra
, "charset-supported");
6168 cupsArrayAdd(ra
, "color-supported");
6169 cupsArrayAdd(ra
, "compression-supported");
6170 cupsArrayAdd(ra
, "document-format-default");
6171 cupsArrayAdd(ra
, "document-format-supported");
6172 cupsArrayAdd(ra
, "generated-natural-language-supported");
6173 cupsArrayAdd(ra
, "ipp-versions-supported");
6174 cupsArrayAdd(ra
, "job-creation-attributes-supported");
6175 cupsArrayAdd(ra
, "job-ids-supported");
6176 cupsArrayAdd(ra
, "job-impressions-supported");
6177 cupsArrayAdd(ra
, "job-k-octets-supported");
6178 cupsArrayAdd(ra
, "job-media-sheets-supported");
6179 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6180 cupsArrayAdd(ra
, "jpeg-k-octets-supported");
6181 cupsArrayAdd(ra
, "jpeg-x-dimension-supported");
6182 cupsArrayAdd(ra
, "jpeg-y-dimension-supported");
6183 cupsArrayAdd(ra
, "media-bottom-margin-supported");
6184 cupsArrayAdd(ra
, "media-col-supported");
6185 cupsArrayAdd(ra
, "media-key-supported");
6186 cupsArrayAdd(ra
, "media-left-margin-supported");
6187 cupsArrayAdd(ra
, "media-right-margin-supported");
6188 cupsArrayAdd(ra
, "media-size-supported");
6189 cupsArrayAdd(ra
, "media-source-supported");
6190 cupsArrayAdd(ra
, "media-top-margin-supported");
6191 cupsArrayAdd(ra
, "media-type-supported");
6192 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6193 cupsArrayAdd(ra
, "multiple-operation-time-out");
6194 cupsArrayAdd(ra
, "natural-language-configured");
6195 cupsArrayAdd(ra
, "notify-max-events-supported");
6196 cupsArrayAdd(ra
, "notify-schemes-supported");
6197 cupsArrayAdd(ra
, "operations-supported");
6198 cupsArrayAdd(ra
, "pages-per-minute");
6199 cupsArrayAdd(ra
, "pages-per-minute-color");
6200 cupsArrayAdd(ra
, "pdf-k-octets-supported");
6201 cupsArrayAdd(ra
, "pdl-override-supported");
6202 cupsArrayAdd(ra
, "printer-alert");
6203 cupsArrayAdd(ra
, "printer-alert-description");
6204 cupsArrayAdd(ra
, "printer-commands");
6205 cupsArrayAdd(ra
, "printer-current-time");
6206 cupsArrayAdd(ra
, "printer-dns-sd-name");
6207 cupsArrayAdd(ra
, "printer-info");
6208 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6209 cupsArrayAdd(ra
, "printer-is-shared");
6210 cupsArrayAdd(ra
, "printer-location");
6211 cupsArrayAdd(ra
, "printer-make-and-model");
6212 cupsArrayAdd(ra
, "printer-message-from-operator");
6213 cupsArrayAdd(ra
, "printer-more-info");
6214 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6215 cupsArrayAdd(ra
, "printer-name");
6216 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6217 cupsArrayAdd(ra
, "printer-state");
6218 cupsArrayAdd(ra
, "printer-state-change-date-time");
6219 cupsArrayAdd(ra
, "printer-state-change-time");
6220 cupsArrayAdd(ra
, "printer-state-message");
6221 cupsArrayAdd(ra
, "printer-state-reasons");
6222 cupsArrayAdd(ra
, "printer-type");
6223 cupsArrayAdd(ra
, "printer-up-time");
6224 cupsArrayAdd(ra
, "printer-uri-supported");
6225 cupsArrayAdd(ra
, "queued-job-count");
6226 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6227 cupsArrayAdd(ra
, "uri-authentication-supported");
6228 cupsArrayAdd(ra
, "uri-security-supported");
6229 cupsArrayAdd(ra
, "which-jobs-supported");
6231 else if (!strcmp(value
, "printer-defaults"))
6233 char *name
; /* Option name */
6236 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6238 name
= (char *)cupsArrayNext(CommonDefaults
))
6239 cupsArrayAdd(ra
, name
);
6241 else if (!strcmp(value
, "subscription-description"))
6243 /* Only includes the set of Subscription Description attributes supported by CUPS */
6244 cupsArrayAdd(ra
, "notify-job-id");
6245 cupsArrayAdd(ra
, "notify-lease-expiration-time");
6246 cupsArrayAdd(ra
, "notify-printer-up-time");
6247 cupsArrayAdd(ra
, "notify-printer-uri");
6248 cupsArrayAdd(ra
, "notify-sequence-number");
6249 cupsArrayAdd(ra
, "notify-subscriber-user-name");
6250 cupsArrayAdd(ra
, "notify-subscription-id");
6252 else if (!strcmp(value
, "subscription-template"))
6254 /* Only includes the set of Subscription Template attributes supported by CUPS */
6255 cupsArrayAdd(ra
, "notify-attributes");
6256 cupsArrayAdd(ra
, "notify-attributes-supported");
6257 cupsArrayAdd(ra
, "notify-charset");
6258 cupsArrayAdd(ra
, "notify-events");
6259 cupsArrayAdd(ra
, "notify-events-default");
6260 cupsArrayAdd(ra
, "notify-events-supported");
6261 cupsArrayAdd(ra
, "notify-lease-duration");
6262 cupsArrayAdd(ra
, "notify-lease-duration-default");
6263 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6264 cupsArrayAdd(ra
, "notify-natural-language");
6265 cupsArrayAdd(ra
, "notify-pull-method");
6266 cupsArrayAdd(ra
, "notify-pull-method-supported");
6267 cupsArrayAdd(ra
, "notify-recipient-uri");
6268 cupsArrayAdd(ra
, "notify-time-interval");
6269 cupsArrayAdd(ra
, "notify-user-data");
6272 cupsArrayAdd(ra
, value
);
6280 * 'create_subscription()' - Create a notification subscription.
6284 create_subscription(
6285 cupsd_client_t
*con
, /* I - Client connection */
6286 ipp_attribute_t
*uri
) /* I - Printer URI */
6288 http_status_t status
; /* Policy status */
6289 int i
; /* Looping var */
6290 ipp_attribute_t
*attr
; /* Current attribute */
6291 cups_ptype_t dtype
; /* Destination type (printer/class) */
6292 char scheme
[HTTP_MAX_URI
],
6293 /* Scheme portion of URI */
6294 userpass
[HTTP_MAX_URI
],
6295 /* Username portion of URI */
6297 /* Host portion of URI */
6298 resource
[HTTP_MAX_URI
];
6299 /* Resource portion of URI */
6300 int port
; /* Port portion of URI */
6301 cupsd_printer_t
*printer
; /* Printer/class */
6302 cupsd_job_t
*job
; /* Job */
6303 int jobid
; /* Job ID */
6304 cupsd_subscription_t
*sub
; /* Subscription object */
6305 const char *username
, /* requesting-user-name or
6306 authenticated username */
6307 *recipient
, /* notify-recipient-uri */
6308 *pullmethod
; /* notify-pull-method */
6309 ipp_attribute_t
*user_data
; /* notify-user-data */
6310 int interval
, /* notify-time-interval */
6311 lease
; /* notify-lease-duration */
6312 unsigned mask
; /* notify-events */
6313 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6314 *notify_lease
; /* notify-lease-duration(-default) */
6318 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6320 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6321 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6322 attr
->value_tag
, attr
->name
);
6324 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6329 * Is the destination valid?
6332 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6333 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6334 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6336 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6337 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6338 sizeof(host
), &port
, resource
, sizeof(resource
));
6340 if (!strcmp(resource
, "/"))
6342 dtype
= (cups_ptype_t
)0;
6345 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6347 dtype
= (cups_ptype_t
)0;
6350 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6352 dtype
= CUPS_PRINTER_CLASS
;
6355 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6361 send_ipp_status(con
, IPP_NOT_FOUND
,
6362 _("The printer or class does not exist."));
6372 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6375 send_http_error(con
, status
, printer
);
6379 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6381 send_http_error(con
, status
, NULL
);
6386 * Get the user that is requesting the subscription...
6389 username
= get_username(con
);
6392 * Find the first subscription group attribute; return if we have
6396 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6397 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6402 send_ipp_status(con
, IPP_BAD_REQUEST
,
6403 _("No subscription attributes in request."));
6408 * Process the subscription attributes in the request...
6411 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6419 lease
= DefaultLeaseDuration
;
6421 mask
= CUPSD_EVENT_NONE
;
6425 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6427 notify_lease
= ippFindAttribute(printer
->attrs
,
6428 "notify-lease-duration-default",
6432 lease
= notify_lease
->values
[0].integer
;
6436 notify_events
= NULL
;
6437 notify_lease
= NULL
;
6440 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6442 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6443 attr
->value_tag
== IPP_TAG_URI
)
6446 * Validate the recipient scheme against the ServerBin/notifier
6450 char notifier
[1024]; /* Notifier filename */
6453 recipient
= attr
->values
[0].string
.text
;
6455 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6456 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6457 host
, sizeof(host
), &port
,
6458 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6460 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6461 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6462 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6463 "notify-status-code", IPP_URI_SCHEME
);
6467 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6469 if (access(notifier
, X_OK
))
6471 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6472 _("notify-recipient-uri URI \"%s\" uses unknown "
6473 "scheme."), recipient
);
6474 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6475 "notify-status-code", IPP_URI_SCHEME
);
6479 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6481 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6482 _("notify-recipient-uri URI \"%s\" is already used."),
6484 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6485 "notify-status-code", IPP_ATTRIBUTES
);
6489 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6490 attr
->value_tag
== IPP_TAG_KEYWORD
)
6492 pullmethod
= attr
->values
[0].string
.text
;
6494 if (strcmp(pullmethod
, "ippget"))
6496 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6497 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6498 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6499 "notify-status-code", IPP_ATTRIBUTES
);
6503 else if (!strcmp(attr
->name
, "notify-charset") &&
6504 attr
->value_tag
== IPP_TAG_CHARSET
&&
6505 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6506 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6508 send_ipp_status(con
, IPP_CHARSET
,
6509 _("Character set \"%s\" not supported."),
6510 attr
->values
[0].string
.text
);
6513 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6514 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6515 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6517 send_ipp_status(con
, IPP_CHARSET
,
6518 _("Language \"%s\" not supported."),
6519 attr
->values
[0].string
.text
);
6522 else if (!strcmp(attr
->name
, "notify-user-data") &&
6523 attr
->value_tag
== IPP_TAG_STRING
)
6525 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6527 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6528 _("The notify-user-data value is too large "
6529 "(%d > 63 octets)."),
6530 attr
->values
[0].unknown
.length
);
6536 else if (!strcmp(attr
->name
, "notify-events") &&
6537 attr
->value_tag
== IPP_TAG_KEYWORD
)
6538 notify_events
= attr
;
6539 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6540 attr
->value_tag
== IPP_TAG_INTEGER
)
6541 lease
= attr
->values
[0].integer
;
6542 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6543 attr
->value_tag
== IPP_TAG_INTEGER
)
6544 interval
= attr
->values
[0].integer
;
6545 else if (!strcmp(attr
->name
, "notify-job-id") &&
6546 attr
->value_tag
== IPP_TAG_INTEGER
)
6547 jobid
= attr
->values
[0].integer
;
6554 for (i
= 0; i
< notify_events
->num_values
; i
++)
6555 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6559 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6561 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6562 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6563 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6565 if (!recipient
&& !pullmethod
)
6568 if (mask
== CUPSD_EVENT_NONE
)
6571 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6573 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6576 send_ipp_status(con
, IPP_BAD_REQUEST
,
6577 _("notify-events not specified."));
6582 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6584 cupsdLogMessage(CUPSD_LOG_INFO
,
6585 "create_subscription: Limiting notify-lease-duration to "
6588 lease
= MaxLeaseDuration
;
6593 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6595 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6603 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6605 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6606 _("There are too many subscriptions."));
6611 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6614 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6615 "Added subscription #%d for printer \"%s\".",
6616 sub
->id
, printer
->name
);
6618 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6621 sub
->interval
= interval
;
6623 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6625 cupsdSetString(&sub
->owner
, username
);
6629 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6630 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6631 sub
->user_data_len
);
6634 ippAddSeparator(con
->response
);
6635 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6636 "notify-subscription-id", sub
->id
);
6638 con
->response
->request
.status
.status_code
= IPP_OK
;
6644 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6649 * 'delete_printer()' - Remove a printer or class from the system.
6653 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6654 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6656 http_status_t status
; /* Policy status */
6657 cups_ptype_t dtype
; /* Destination type (printer/class) */
6658 cupsd_printer_t
*printer
; /* Printer/class */
6659 char filename
[1024]; /* Script/PPD filename */
6662 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6663 con
->http
.fd
, uri
->values
[0].string
.text
);
6666 * Do we have a valid URI?
6669 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6675 send_ipp_status(con
, IPP_NOT_FOUND
,
6676 _("The printer or class does not exist."));
6684 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6686 send_http_error(con
, status
, NULL
);
6691 * Remove old jobs...
6694 cupsdCancelJobs(printer
->name
, NULL
, 1);
6697 * Remove old subscriptions and send a "deleted printer" event...
6700 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6701 "%s \"%s\" deleted by \"%s\".",
6702 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6703 printer
->name
, get_username(con
));
6705 cupsdExpireSubscriptions(printer
, NULL
);
6708 * Remove any old PPD or script files...
6711 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6715 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6719 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6722 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6727 * Unregister color profiles...
6730 apple_unregister_profiles(printer
);
6731 #endif /* __APPLE__ */
6733 if (dtype
& CUPS_PRINTER_CLASS
)
6735 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6736 printer
->name
, get_username(con
));
6738 cupsdDeletePrinter(printer
, 0);
6739 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6743 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6744 printer
->name
, get_username(con
));
6746 if (cupsdDeletePrinter(printer
, 0))
6747 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6749 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6752 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6755 * Return with no errors...
6758 con
->response
->request
.status
.status_code
= IPP_OK
;
6763 * 'get_default()' - Get the default destination.
6767 get_default(cupsd_client_t
*con
) /* I - Client connection */
6769 http_status_t status
; /* Policy status */
6770 cups_array_t
*ra
; /* Requested attributes array */
6773 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6779 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6781 send_http_error(con
, status
, NULL
);
6787 ra
= create_requested_array(con
->request
);
6789 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6791 cupsArrayDelete(ra
);
6793 con
->response
->request
.status
.status_code
= IPP_OK
;
6796 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6801 * 'get_devices()' - Get the list of available devices on the local system.
6805 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6807 http_status_t status
; /* Policy status */
6808 ipp_attribute_t
*limit
, /* limit attribute */
6809 *timeout
, /* timeout attribute */
6810 *requested
, /* requested-attributes attribute */
6811 *exclude
, /* exclude-schemes attribute */
6812 *include
; /* include-schemes attribute */
6813 char command
[1024], /* cups-deviced command */
6814 options
[2048], /* Options to pass to command */
6816 /* String for requested attributes */
6818 /* String for excluded schemes */
6820 /* String for included schemes */
6823 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6829 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6831 send_http_error(con
, status
, NULL
);
6836 * Run cups-deviced command with the given options...
6839 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6840 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6841 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6843 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6844 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6847 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6849 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6852 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6854 exclude_str
[0] = '\0';
6857 url_encode_attr(include
, include_str
, sizeof(include_str
));
6859 include_str
[0] = '\0';
6861 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6862 snprintf(options
, sizeof(options
),
6863 "%d+%d+%d+%d+%s%s%s%s%s",
6864 con
->request
->request
.op
.request_id
,
6865 limit
? limit
->values
[0].integer
: 0,
6866 timeout
? timeout
->values
[0].integer
: 15,
6869 exclude_str
[0] ? "%20" : "", exclude_str
,
6870 include_str
[0] ? "%20" : "", include_str
);
6872 if (cupsdSendCommand(con
, command
, options
, 1))
6875 * Command started successfully, don't send an IPP response here...
6878 ippDelete(con
->response
);
6879 con
->response
= NULL
;
6884 * Command failed, return "internal error" so the user knows something
6888 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6889 _("cups-deviced failed to execute."));
6895 * 'get_document()' - Get a copy of a job file.
6899 get_document(cupsd_client_t
*con
, /* I - Client connection */
6900 ipp_attribute_t
*uri
) /* I - Job URI */
6902 http_status_t status
; /* Policy status */
6903 ipp_attribute_t
*attr
; /* Current attribute */
6904 int jobid
; /* Job ID */
6905 int docnum
; /* Document number */
6906 cupsd_job_t
*job
; /* Current job */
6907 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6908 username
[HTTP_MAX_URI
], /* Username portion of URI */
6909 host
[HTTP_MAX_URI
], /* Host portion of URI */
6910 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6911 int port
; /* Port portion of URI */
6912 char filename
[1024], /* Filename for document */
6913 format
[1024]; /* Format for document */
6916 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6917 con
->http
.fd
, uri
->values
[0].string
.text
);
6920 * See if we have a job URI or a printer URI...
6923 if (!strcmp(uri
->name
, "printer-uri"))
6926 * Got a printer URI; see if we also have a job-id attribute...
6929 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6930 IPP_TAG_INTEGER
)) == NULL
)
6932 send_ipp_status(con
, IPP_BAD_REQUEST
,
6933 _("Got a printer-uri attribute but no job-id."));
6937 jobid
= attr
->values
[0].integer
;
6942 * Got a job URI; parse it to get the job ID...
6945 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6946 sizeof(scheme
), username
, sizeof(username
), host
,
6947 sizeof(host
), &port
, resource
, sizeof(resource
));
6949 if (strncmp(resource
, "/jobs/", 6))
6955 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6956 uri
->values
[0].string
.text
);
6960 jobid
= atoi(resource
+ 6);
6964 * See if the job exists...
6967 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6970 * Nope - return a "not found" error...
6973 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6981 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6982 job
->username
)) != HTTP_OK
)
6984 send_http_error(con
, status
, NULL
);
6989 * Get the document number...
6992 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6993 IPP_TAG_INTEGER
)) == NULL
)
6995 send_ipp_status(con
, IPP_BAD_REQUEST
,
6996 _("Missing document-number attribute."));
7000 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7001 attr
->num_values
> 1)
7003 send_ipp_status(con
, IPP_NOT_FOUND
,
7004 _("Document #%d does not exist in job #%d."), docnum
,
7009 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7011 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7013 cupsdLogMessage(CUPSD_LOG_ERROR
,
7014 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7016 send_ipp_status(con
, IPP_NOT_FOUND
,
7017 _("Unable to open document #%d in job #%d."), docnum
,
7022 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7026 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7027 job
->filetypes
[docnum
- 1]->type
);
7029 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7031 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7033 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7034 IPP_TAG_NAME
)) != NULL
)
7035 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7036 NULL
, attr
->values
[0].string
.text
);
7041 * 'get_job_attrs()' - Get job attributes.
7045 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7046 ipp_attribute_t
*uri
) /* I - Job URI */
7048 http_status_t status
; /* Policy status */
7049 ipp_attribute_t
*attr
; /* Current attribute */
7050 int jobid
; /* Job ID */
7051 cupsd_job_t
*job
; /* Current job */
7052 cupsd_printer_t
*printer
; /* Current printer */
7053 cupsd_policy_t
*policy
; /* Current security policy */
7054 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7055 username
[HTTP_MAX_URI
], /* Username portion of URI */
7056 host
[HTTP_MAX_URI
], /* Host portion of URI */
7057 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7058 int port
; /* Port portion of URI */
7059 cups_array_t
*ra
, /* Requested attributes array */
7060 *exclude
; /* Private attributes array */
7063 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7064 con
->http
.fd
, uri
->values
[0].string
.text
);
7067 * See if we have a job URI or a printer URI...
7070 if (!strcmp(uri
->name
, "printer-uri"))
7073 * Got a printer URI; see if we also have a job-id attribute...
7076 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7077 IPP_TAG_INTEGER
)) == NULL
)
7079 send_ipp_status(con
, IPP_BAD_REQUEST
,
7080 _("Got a printer-uri attribute but no job-id."));
7084 jobid
= attr
->values
[0].integer
;
7089 * Got a job URI; parse it to get the job ID...
7092 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7093 sizeof(scheme
), username
, sizeof(username
), host
,
7094 sizeof(host
), &port
, resource
, sizeof(resource
));
7096 if (strncmp(resource
, "/jobs/", 6))
7102 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7103 uri
->values
[0].string
.text
);
7107 jobid
= atoi(resource
+ 6);
7111 * See if the job exists...
7114 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7117 * Nope - return a "not found" error...
7120 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7128 if ((printer
= job
->printer
) == NULL
)
7129 printer
= cupsdFindDest(job
->dest
);
7132 policy
= printer
->op_policy_ptr
;
7134 policy
= DefaultPolicyPtr
;
7136 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7138 send_http_error(con
, status
, NULL
);
7142 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7145 * Copy attributes...
7150 ra
= create_requested_array(con
->request
);
7151 copy_job_attrs(con
, job
, ra
, exclude
);
7152 cupsArrayDelete(ra
);
7154 con
->response
->request
.status
.status_code
= IPP_OK
;
7159 * 'get_jobs()' - Get a list of jobs for the specified printer.
7163 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7164 ipp_attribute_t
*uri
) /* I - Printer URI */
7166 http_status_t status
; /* Policy status */
7167 ipp_attribute_t
*attr
; /* Current attribute */
7168 const char *dest
; /* Destination */
7169 cups_ptype_t dtype
; /* Destination type (printer/class) */
7170 cups_ptype_t dmask
; /* Destination type mask */
7171 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7172 username
[HTTP_MAX_URI
], /* Username portion of URI */
7173 host
[HTTP_MAX_URI
], /* Host portion of URI */
7174 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7175 int port
; /* Port portion of URI */
7176 int job_comparison
; /* Job comparison */
7177 ipp_jstate_t job_state
; /* job-state value */
7178 int first_job_id
; /* First job ID */
7179 int limit
; /* Maximum number of jobs to return */
7180 int count
; /* Number of jobs that match */
7181 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7182 cupsd_job_t
*job
; /* Current job pointer */
7183 cupsd_printer_t
*printer
; /* Printer */
7184 cups_array_t
*list
; /* Which job list... */
7185 cups_array_t
*ra
, /* Requested attributes array */
7186 *exclude
; /* Private attributes array */
7187 cupsd_policy_t
*policy
; /* Current policy */
7190 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7191 uri
->values
[0].string
.text
);
7194 * Is the destination valid?
7197 if (strcmp(uri
->name
, "printer-uri"))
7199 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7203 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7204 sizeof(scheme
), username
, sizeof(username
), host
,
7205 sizeof(host
), &port
, resource
, sizeof(resource
));
7207 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7210 dtype
= (cups_ptype_t
)0;
7211 dmask
= (cups_ptype_t
)0;
7214 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7217 dtype
= (cups_ptype_t
)0;
7218 dmask
= CUPS_PRINTER_CLASS
;
7221 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7224 dtype
= CUPS_PRINTER_CLASS
;
7225 dmask
= CUPS_PRINTER_CLASS
;
7228 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7235 send_ipp_status(con
, IPP_NOT_FOUND
,
7236 _("The printer or class does not exist."));
7241 dtype
&= CUPS_PRINTER_CLASS
;
7242 dmask
= CUPS_PRINTER_CLASS
;
7250 policy
= printer
->op_policy_ptr
;
7252 policy
= DefaultPolicyPtr
;
7254 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7256 send_http_error(con
, status
, NULL
);
7260 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7263 * See if the "which-jobs" attribute have been specified...
7266 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7267 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7269 send_ipp_status(con
, IPP_CONFLICT
,
7270 _("The %s attribute cannot be provided with job-ids."),
7274 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7276 job_comparison
= -1;
7277 job_state
= IPP_JOB_STOPPED
;
7280 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7283 job_state
= IPP_JOB_CANCELED
;
7286 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7289 job_state
= IPP_JOB_ABORTED
;
7292 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7295 job_state
= IPP_JOB_PENDING
;
7298 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7301 job_state
= IPP_JOB_CANCELED
;
7304 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7307 job_state
= IPP_JOB_PENDING
;
7310 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7313 job_state
= IPP_JOB_HELD
;
7316 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7319 job_state
= IPP_JOB_PROCESSING
;
7320 list
= PrintingJobs
;
7322 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7325 job_state
= IPP_JOB_STOPPED
;
7330 send_ipp_status(con
, IPP_ATTRIBUTES
,
7331 _("The which-jobs value \"%s\" is not supported."),
7332 attr
->values
[0].string
.text
);
7333 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7334 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7339 * See if they want to limit the number of jobs reported...
7342 if ((attr
= ippFindAttribute(con
->request
, "limit",
7343 IPP_TAG_INTEGER
)) != NULL
)
7347 send_ipp_status(con
, IPP_CONFLICT
,
7348 _("The %s attribute cannot be provided with job-ids."),
7353 limit
= attr
->values
[0].integer
;
7358 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7359 IPP_TAG_INTEGER
)) != NULL
)
7363 send_ipp_status(con
, IPP_CONFLICT
,
7364 _("The %s attribute cannot be provided with job-ids."),
7369 first_job_id
= attr
->values
[0].integer
;
7375 * See if we only want to see jobs for a specific user...
7378 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7379 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7381 send_ipp_status(con
, IPP_CONFLICT
,
7382 _("The %s attribute cannot be provided with job-ids."),
7386 else if (attr
&& attr
->values
[0].boolean
)
7387 strlcpy(username
, get_username(con
), sizeof(username
));
7391 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7392 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7395 * IPP conformance - Get-Jobs has a default requested-attributes value of
7396 * "job-id" and "job-uri".
7399 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7400 cupsArrayAdd(ra
, "job-id");
7401 cupsArrayAdd(ra
, "job-uri");
7405 * OK, build a list of jobs for this printer...
7410 int i
; /* Looping var */
7412 for (i
= 0; i
< job_ids
->num_values
; i
++)
7414 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7418 if (i
< job_ids
->num_values
)
7420 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7421 job_ids
->values
[i
].integer
);
7425 for (i
= 0; i
< job_ids
->num_values
; i
++)
7427 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7433 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7439 ippAddSeparator(con
->response
);
7441 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7442 job
->printer
->op_policy_ptr
:
7443 policy
, con
, job
->printer
,
7446 copy_job_attrs(con
, job
, ra
, exclude
);
7451 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7452 (limit
<= 0 || count
< limit
) && job
;
7453 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7456 * Filter out jobs that don't match...
7459 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7460 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7461 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7462 job
->username
, job
->state_value
, job
->attrs
);
7464 if (!job
->dest
|| !job
->username
)
7467 if (!job
->dest
|| !job
->username
)
7470 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7471 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7473 if ((job
->dtype
& dmask
) != dtype
&&
7474 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7477 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7478 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7479 (job_comparison
> 0 && job
->state_value
< job_state
))
7482 if (job
->id
< first_job_id
)
7489 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7494 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
7498 ippAddSeparator(con
->response
);
7502 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7503 job
->printer
->op_policy_ptr
:
7504 policy
, con
, job
->printer
,
7507 copy_job_attrs(con
, job
, ra
, exclude
);
7510 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7513 cupsArrayDelete(ra
);
7515 con
->response
->request
.status
.status_code
= IPP_OK
;
7520 * 'get_notifications()' - Get events for a subscription.
7524 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7526 int i
, j
; /* Looping vars */
7527 http_status_t status
; /* Policy status */
7528 cupsd_subscription_t
*sub
; /* Subscription */
7529 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7530 *sequences
; /* notify-sequence-numbers */
7531 int min_seq
; /* Minimum sequence number */
7532 int interval
; /* Poll interval */
7535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7539 * Get subscription attributes...
7542 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7544 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7549 send_ipp_status(con
, IPP_BAD_REQUEST
,
7550 _("Missing notify-subscription-ids attribute."));
7555 * Are the subscription IDs valid?
7558 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7560 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7563 * Bad subscription ID...
7566 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7567 ids
->values
[i
].integer
);
7575 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7577 con
, sub
->owner
)) != HTTP_OK
)
7579 send_http_error(con
, status
, sub
->dest
);
7584 * Check the subscription type and update the interval accordingly.
7587 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7590 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7592 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7598 * Tell the client to poll again in N seconds...
7602 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7603 "notify-get-interval", interval
);
7605 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7606 "printer-up-time", time(NULL
));
7609 * Copy the subscription event attributes to the response.
7612 con
->response
->request
.status
.status_code
=
7613 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7615 for (i
= 0; i
< ids
->num_values
; i
++)
7618 * Get the subscription and sequence number...
7621 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7623 if (sequences
&& i
< sequences
->num_values
)
7624 min_seq
= sequences
->values
[i
].integer
;
7629 * If we don't have any new events, nothing to do here...
7632 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7636 * Otherwise copy all of the new events...
7639 if (sub
->first_event_id
> min_seq
)
7642 j
= min_seq
- sub
->first_event_id
;
7644 for (; j
< cupsArrayCount(sub
->events
); j
++)
7646 ippAddSeparator(con
->response
);
7648 copy_attrs(con
->response
,
7649 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7650 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7657 * 'get_ppd()' - Get a named PPD from the local system.
7661 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7662 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7664 http_status_t status
; /* Policy status */
7665 cupsd_printer_t
*dest
; /* Destination */
7666 cups_ptype_t dtype
; /* Destination type */
7669 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7670 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7672 if (!strcmp(uri
->name
, "ppd-name"))
7675 * Return a PPD file from cups-driverd...
7678 char command
[1024], /* cups-driverd command */
7679 options
[1024], /* Options to pass to command */
7680 ppd_name
[1024]; /* ppd-name */
7687 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7689 send_http_error(con
, status
, NULL
);
7694 * Run cups-driverd command with the given options...
7697 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7698 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7699 snprintf(options
, sizeof(options
), "get+%d+%s",
7700 con
->request
->request
.op
.request_id
, ppd_name
);
7702 if (cupsdSendCommand(con
, command
, options
, 0))
7705 * Command started successfully, don't send an IPP response here...
7708 ippDelete(con
->response
);
7709 con
->response
= NULL
;
7714 * Command failed, return "internal error" so the user knows something
7718 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7719 _("cups-driverd failed to execute."));
7722 else if (!strcmp(uri
->name
, "printer-uri") &&
7723 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7725 int i
; /* Looping var */
7726 char filename
[1024]; /* PPD filename */
7733 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7735 send_http_error(con
, status
, dest
);
7740 * See if we need the PPD for a class or remote printer...
7743 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7746 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7748 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7749 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7750 "printer-uri", NULL
, dest
->uri
);
7753 else if (dtype
& CUPS_PRINTER_CLASS
)
7755 for (i
= 0; i
< dest
->num_printers
; i
++)
7756 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7758 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7759 dest
->printers
[i
]->name
);
7761 if (!access(filename
, 0))
7765 if (i
< dest
->num_printers
)
7766 dest
= dest
->printers
[i
];
7769 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7770 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7771 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7777 * Found the printer with the PPD file, now see if there is one...
7780 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7782 send_ipp_status(con
, IPP_NOT_FOUND
,
7783 _("The PPD file \"%s\" could not be opened: %s"),
7784 uri
->values
[0].string
.text
, strerror(errno
));
7788 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7792 con
->response
->request
.status
.status_code
= IPP_OK
;
7795 send_ipp_status(con
, IPP_NOT_FOUND
,
7796 _("The PPD file \"%s\" could not be found."),
7797 uri
->values
[0].string
.text
);
7802 * 'get_ppds()' - Get the list of PPD files on the local system.
7806 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7808 http_status_t status
; /* Policy status */
7809 ipp_attribute_t
*limit
, /* Limit attribute */
7810 *device
, /* ppd-device-id attribute */
7811 *language
, /* ppd-natural-language attribute */
7812 *make
, /* ppd-make attribute */
7813 *model
, /* ppd-make-and-model attribute */
7814 *model_number
, /* ppd-model-number attribute */
7815 *product
, /* ppd-product attribute */
7816 *psversion
, /* ppd-psverion attribute */
7817 *type
, /* ppd-type attribute */
7818 *requested
, /* requested-attributes attribute */
7819 *exclude
, /* exclude-schemes attribute */
7820 *include
; /* include-schemes attribute */
7821 char command
[1024], /* cups-driverd command */
7822 options
[4096], /* Options to pass to command */
7823 device_str
[256],/* Escaped ppd-device-id string */
7825 /* Escaped ppd-natural-language */
7826 make_str
[256], /* Escaped ppd-make string */
7827 model_str
[256], /* Escaped ppd-make-and-model string */
7828 model_number_str
[256],
7829 /* ppd-model-number string */
7831 /* Escaped ppd-product string */
7833 /* Escaped ppd-psversion string */
7834 type_str
[256], /* Escaped ppd-type string */
7836 /* String for requested attributes */
7838 /* String for excluded schemes */
7840 /* String for included schemes */
7843 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7849 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7851 send_http_error(con
, status
, NULL
);
7856 * Run cups-driverd command with the given options...
7859 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7860 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7861 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7863 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7864 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7866 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7868 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7869 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7870 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7871 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7873 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7875 include
= ippFindAttribute(con
->request
, "include-schemes",
7879 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7881 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7884 url_encode_attr(device
, device_str
, sizeof(device_str
));
7886 device_str
[0] = '\0';
7889 url_encode_attr(language
, language_str
, sizeof(language_str
));
7891 language_str
[0] = '\0';
7894 url_encode_attr(make
, make_str
, sizeof(make_str
));
7899 url_encode_attr(model
, model_str
, sizeof(model_str
));
7901 model_str
[0] = '\0';
7904 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7905 model_number
->values
[0].integer
);
7907 model_number_str
[0] = '\0';
7910 url_encode_attr(product
, product_str
, sizeof(product_str
));
7912 product_str
[0] = '\0';
7915 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7917 psversion_str
[0] = '\0';
7920 url_encode_attr(type
, type_str
, sizeof(type_str
));
7925 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7927 exclude_str
[0] = '\0';
7930 url_encode_attr(include
, include_str
, sizeof(include_str
));
7932 include_str
[0] = '\0';
7934 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7935 snprintf(options
, sizeof(options
),
7936 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7937 con
->request
->request
.op
.request_id
,
7938 limit
? limit
->values
[0].integer
: 0,
7940 device
? "%20" : "", device_str
,
7941 language
? "%20" : "", language_str
,
7942 make
? "%20" : "", make_str
,
7943 model
? "%20" : "", model_str
,
7944 model_number
? "%20" : "", model_number_str
,
7945 product
? "%20" : "", product_str
,
7946 psversion
? "%20" : "", psversion_str
,
7947 type
? "%20" : "", type_str
,
7948 exclude_str
[0] ? "%20" : "", exclude_str
,
7949 include_str
[0] ? "%20" : "", include_str
);
7951 if (cupsdSendCommand(con
, command
, options
, 0))
7954 * Command started successfully, don't send an IPP response here...
7957 ippDelete(con
->response
);
7958 con
->response
= NULL
;
7963 * Command failed, return "internal error" so the user knows something
7967 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7968 _("cups-driverd failed to execute."));
7974 * 'get_printer_attrs()' - Get printer attributes.
7978 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7979 ipp_attribute_t
*uri
) /* I - Printer URI */
7981 http_status_t status
; /* Policy status */
7982 cups_ptype_t dtype
; /* Destination type (printer/class) */
7983 cupsd_printer_t
*printer
; /* Printer/class */
7984 cups_array_t
*ra
; /* Requested attributes array */
7987 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7988 con
->http
.fd
, uri
->values
[0].string
.text
);
7991 * Is the destination valid?
7994 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8000 send_ipp_status(con
, IPP_NOT_FOUND
,
8001 _("The printer or class does not exist."));
8009 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8011 send_http_error(con
, status
, printer
);
8016 * Send the attributes...
8019 ra
= create_requested_array(con
->request
);
8021 copy_printer_attrs(con
, printer
, ra
);
8023 cupsArrayDelete(ra
);
8025 con
->response
->request
.status
.status_code
= IPP_OK
;
8030 * 'get_printer_supported()' - Get printer supported values.
8034 get_printer_supported(
8035 cupsd_client_t
*con
, /* I - Client connection */
8036 ipp_attribute_t
*uri
) /* I - Printer URI */
8038 http_status_t status
; /* Policy status */
8039 cups_ptype_t dtype
; /* Destination type (printer/class) */
8040 cupsd_printer_t
*printer
; /* Printer/class */
8043 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8044 con
->http
.fd
, uri
->values
[0].string
.text
);
8047 * Is the destination valid?
8050 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8056 send_ipp_status(con
, IPP_NOT_FOUND
,
8057 _("The printer or class does not exist."));
8065 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8067 send_http_error(con
, status
, printer
);
8072 * Return a list of attributes that can be set via Set-Printer-Attributes.
8075 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8077 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8078 "printer-location", 0);
8080 con
->response
->request
.status
.status_code
= IPP_OK
;
8085 * 'get_printers()' - Get a list of printers or classes.
8089 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8090 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8092 http_status_t status
; /* Policy status */
8093 ipp_attribute_t
*attr
; /* Current attribute */
8094 int limit
; /* Max number of printers to return */
8095 int count
; /* Number of printers that match */
8096 cupsd_printer_t
*printer
; /* Current printer pointer */
8097 int printer_type
, /* printer-type attribute */
8098 printer_mask
; /* printer-type-mask attribute */
8099 char *location
; /* Location string */
8100 const char *username
; /* Current user */
8101 char *first_printer_name
; /* first-printer-name attribute */
8102 cups_array_t
*ra
; /* Requested attributes array */
8103 int local
; /* Local connection? */
8106 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8107 con
->http
.fd
, type
);
8113 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8115 send_http_error(con
, status
, NULL
);
8120 * Check for printers...
8123 if (!Printers
|| !cupsArrayCount(Printers
))
8125 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8130 * See if they want to limit the number of printers reported...
8133 if ((attr
= ippFindAttribute(con
->request
, "limit",
8134 IPP_TAG_INTEGER
)) != NULL
)
8135 limit
= attr
->values
[0].integer
;
8139 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8140 IPP_TAG_NAME
)) != NULL
)
8141 first_printer_name
= attr
->values
[0].string
.text
;
8143 first_printer_name
= NULL
;
8146 * Support filtering...
8149 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8150 IPP_TAG_ENUM
)) != NULL
)
8151 printer_type
= attr
->values
[0].integer
;
8155 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8156 IPP_TAG_ENUM
)) != NULL
)
8157 printer_mask
= attr
->values
[0].integer
;
8161 local
= httpAddrLocalhost(&(con
->clientaddr
));
8163 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8164 IPP_TAG_TEXT
)) != NULL
)
8165 location
= attr
->values
[0].string
.text
;
8169 if (con
->username
[0])
8170 username
= con
->username
;
8171 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8172 IPP_TAG_NAME
)) != NULL
)
8173 username
= attr
->values
[0].string
.text
;
8177 ra
= create_requested_array(con
->request
);
8180 * OK, build a list of printers for this printer...
8183 if (first_printer_name
)
8185 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8186 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8189 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8192 count
< limit
&& printer
;
8193 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8195 if (!local
&& !printer
->shared
)
8198 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8199 (printer
->type
& printer_mask
) == printer_type
&&
8201 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
8204 * If a username is specified, see if it is allowed or denied
8208 if (cupsArrayCount(printer
->users
) && username
&&
8209 !user_allowed(printer
, username
))
8213 * Add the group separator as needed...
8217 ippAddSeparator(con
->response
);
8222 * Send the attributes...
8225 copy_printer_attrs(con
, printer
, ra
);
8229 cupsArrayDelete(ra
);
8231 con
->response
->request
.status
.status_code
= IPP_OK
;
8236 * 'get_subscription_attrs()' - Get subscription attributes.
8240 get_subscription_attrs(
8241 cupsd_client_t
*con
, /* I - Client connection */
8242 int sub_id
) /* I - Subscription ID */
8244 http_status_t status
; /* Policy status */
8245 cupsd_subscription_t
*sub
; /* Subscription */
8246 cupsd_policy_t
*policy
; /* Current security policy */
8247 cups_array_t
*ra
, /* Requested attributes array */
8248 *exclude
; /* Private attributes array */
8251 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8252 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8253 con
, con
->http
.fd
, sub_id
);
8256 * Is the subscription ID valid?
8259 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8262 * Bad subscription ID...
8265 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8275 policy
= sub
->dest
->op_policy_ptr
;
8277 policy
= DefaultPolicyPtr
;
8279 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8281 send_http_error(con
, status
, sub
->dest
);
8285 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8288 * Copy the subscription attributes to the response using the
8289 * requested-attributes attribute that may be provided by the client.
8292 ra
= create_requested_array(con
->request
);
8294 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8296 cupsArrayDelete(ra
);
8298 con
->response
->request
.status
.status_code
= IPP_OK
;
8303 * 'get_subscriptions()' - Get subscriptions.
8307 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8308 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8310 http_status_t status
; /* Policy status */
8311 int count
; /* Number of subscriptions */
8312 int limit
; /* Limit */
8313 cupsd_subscription_t
*sub
; /* Subscription */
8314 cups_array_t
*ra
; /* Requested attributes array */
8315 ipp_attribute_t
*attr
; /* Attribute */
8316 cups_ptype_t dtype
; /* Destination type (printer/class) */
8317 char scheme
[HTTP_MAX_URI
],
8318 /* Scheme portion of URI */
8319 username
[HTTP_MAX_URI
],
8320 /* Username portion of URI */
8322 /* Host portion of URI */
8323 resource
[HTTP_MAX_URI
];
8324 /* Resource portion of URI */
8325 int port
; /* Port portion of URI */
8326 cupsd_job_t
*job
; /* Job pointer */
8327 cupsd_printer_t
*printer
; /* Printer */
8328 cupsd_policy_t
*policy
; /* Policy */
8329 cups_array_t
*exclude
; /* Private attributes array */
8332 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8333 "get_subscriptions(con=%p[%d], uri=%s)",
8334 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8337 * Is the destination valid?
8340 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8341 sizeof(scheme
), username
, sizeof(username
), host
,
8342 sizeof(host
), &port
, resource
, sizeof(resource
));
8344 if (!strcmp(resource
, "/") ||
8345 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8346 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8347 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8352 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8355 job
= cupsdFindJob(atoi(resource
+ 6));
8359 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8360 atoi(resource
+ 6));
8364 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8370 send_ipp_status(con
, IPP_NOT_FOUND
,
8371 _("The printer or class does not exist."));
8374 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8375 IPP_TAG_INTEGER
)) != NULL
)
8377 job
= cupsdFindJob(attr
->values
[0].integer
);
8381 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8382 attr
->values
[0].integer
);
8394 policy
= printer
->op_policy_ptr
;
8396 policy
= DefaultPolicyPtr
;
8398 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8400 send_http_error(con
, status
, printer
);
8405 * Copy the subscription attributes to the response using the
8406 * requested-attributes attribute that may be provided by the client.
8409 ra
= create_requested_array(con
->request
);
8411 if ((attr
= ippFindAttribute(con
->request
, "limit",
8412 IPP_TAG_INTEGER
)) != NULL
)
8413 limit
= attr
->values
[0].integer
;
8418 * See if we only want to see subscriptions for a specific user...
8421 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8422 IPP_TAG_BOOLEAN
)) != NULL
&&
8423 attr
->values
[0].boolean
)
8424 strlcpy(username
, get_username(con
), sizeof(username
));
8428 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8430 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8431 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8432 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
8434 ippAddSeparator(con
->response
);
8436 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8437 policy
, con
, sub
->dest
,
8440 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8443 if (limit
&& count
>= limit
)
8447 cupsArrayDelete(ra
);
8450 con
->response
->request
.status
.status_code
= IPP_OK
;
8452 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8457 * 'get_username()' - Get the username associated with a request.
8460 static const char * /* O - Username */
8461 get_username(cupsd_client_t
*con
) /* I - Connection */
8463 ipp_attribute_t
*attr
; /* Attribute */
8466 if (con
->username
[0])
8467 return (con
->username
);
8468 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8469 IPP_TAG_NAME
)) != NULL
)
8470 return (attr
->values
[0].string
.text
);
8472 return ("anonymous");
8477 * 'hold_job()' - Hold a print job.
8481 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8482 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8484 ipp_attribute_t
*attr
; /* Current job-hold-until */
8485 const char *when
; /* New value */
8486 int jobid
; /* Job ID */
8487 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8488 username
[HTTP_MAX_URI
], /* Username portion of URI */
8489 host
[HTTP_MAX_URI
], /* Host portion of URI */
8490 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8491 int port
; /* Port portion of URI */
8492 cupsd_job_t
*job
; /* Job information */
8495 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8496 uri
->values
[0].string
.text
);
8499 * See if we have a job URI or a printer URI...
8502 if (!strcmp(uri
->name
, "printer-uri"))
8505 * Got a printer URI; see if we also have a job-id attribute...
8508 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8509 IPP_TAG_INTEGER
)) == NULL
)
8511 send_ipp_status(con
, IPP_BAD_REQUEST
,
8512 _("Got a printer-uri attribute but no job-id."));
8516 jobid
= attr
->values
[0].integer
;
8521 * Got a job URI; parse it to get the job ID...
8524 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8525 sizeof(scheme
), username
, sizeof(username
), host
,
8526 sizeof(host
), &port
, resource
, sizeof(resource
));
8528 if (strncmp(resource
, "/jobs/", 6))
8534 send_ipp_status(con
, IPP_BAD_REQUEST
,
8535 _("Bad job-uri \"%s\"."),
8536 uri
->values
[0].string
.text
);
8540 jobid
= atoi(resource
+ 6);
8544 * See if the job exists...
8547 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8550 * Nope - return a "not found" error...
8553 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8558 * See if the job is owned by the requesting user...
8561 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8563 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8564 cupsdFindDest(job
->dest
));
8569 * See if the job is in a state that allows holding...
8572 if (job
->state_value
> IPP_JOB_STOPPED
)
8575 * Return a "not-possible" error...
8578 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8579 _("Job #%d is finished and cannot be altered."),
8585 * Hold the job and return...
8588 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8589 IPP_TAG_KEYWORD
)) == NULL
)
8590 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8594 when
= attr
->values
[0].string
.text
;
8596 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8597 "Job job-hold-until value changed by user.");
8600 when
= "indefinite";
8602 cupsdSetJobHoldUntil(job
, when
, 1);
8603 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8606 con
->response
->request
.status
.status_code
= IPP_OK
;
8611 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8615 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8616 ipp_attribute_t
*uri
) /* I - Printer URI */
8618 http_status_t status
; /* Policy status */
8619 cups_ptype_t dtype
; /* Destination type (printer/class) */
8620 cupsd_printer_t
*printer
; /* Printer data */
8623 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8624 con
->http
.fd
, uri
->values
[0].string
.text
);
8627 * Is the destination valid?
8630 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8636 send_ipp_status(con
, IPP_NOT_FOUND
,
8637 _("The printer or class does not exist."));
8645 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8647 send_http_error(con
, status
, printer
);
8652 * Hold pending/new jobs sent to the printer...
8655 printer
->holding_new_jobs
= 1;
8657 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8659 if (dtype
& CUPS_PRINTER_CLASS
)
8660 cupsdLogMessage(CUPSD_LOG_INFO
,
8661 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8662 printer
->name
, get_username(con
));
8664 cupsdLogMessage(CUPSD_LOG_INFO
,
8665 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8666 printer
->name
, get_username(con
));
8669 * Everything was ok, so return OK status...
8672 con
->response
->request
.status
.status_code
= IPP_OK
;
8677 * 'move_job()' - Move a job to a new destination.
8681 move_job(cupsd_client_t
*con
, /* I - Client connection */
8682 ipp_attribute_t
*uri
) /* I - Job URI */
8684 http_status_t status
; /* Policy status */
8685 ipp_attribute_t
*attr
; /* Current attribute */
8686 int jobid
; /* Job ID */
8687 cupsd_job_t
*job
; /* Current job */
8688 const char *src
; /* Source printer/class */
8689 cups_ptype_t stype
, /* Source type (printer or class) */
8690 dtype
; /* Destination type (printer/class) */
8691 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8692 username
[HTTP_MAX_URI
], /* Username portion of URI */
8693 host
[HTTP_MAX_URI
], /* Host portion of URI */
8694 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8695 int port
; /* Port portion of URI */
8696 cupsd_printer_t
*sprinter
, /* Source printer */
8697 *dprinter
; /* Destination printer */
8700 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8701 uri
->values
[0].string
.text
);
8704 * Get the new printer or class...
8707 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8708 IPP_TAG_URI
)) == NULL
)
8711 * Need job-printer-uri...
8714 send_ipp_status(con
, IPP_BAD_REQUEST
,
8715 _("job-printer-uri attribute missing."));
8719 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8725 send_ipp_status(con
, IPP_NOT_FOUND
,
8726 _("The printer or class does not exist."));
8731 * See if we have a job URI or a printer URI...
8734 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8735 sizeof(scheme
), username
, sizeof(username
), host
,
8736 sizeof(host
), &port
, resource
, sizeof(resource
));
8738 if (!strcmp(uri
->name
, "printer-uri"))
8741 * Got a printer URI; see if we also have a job-id attribute...
8744 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8745 IPP_TAG_INTEGER
)) == NULL
)
8751 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8752 &sprinter
)) == NULL
)
8758 send_ipp_status(con
, IPP_NOT_FOUND
,
8759 _("The printer or class does not exist."));
8768 * Otherwise, just move a single job...
8771 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8774 * Nope - return a "not found" error...
8777 send_ipp_status(con
, IPP_NOT_FOUND
,
8778 _("Job #%d does not exist."), attr
->values
[0].integer
);
8784 * Job found, initialize source pointers...
8795 * Got a job URI; parse it to get the job ID...
8798 if (strncmp(resource
, "/jobs/", 6))
8804 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8805 uri
->values
[0].string
.text
);
8810 * See if the job exists...
8813 jobid
= atoi(resource
+ 6);
8815 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8818 * Nope - return a "not found" error...
8821 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8827 * Job found, initialize source pointers...
8836 * Check the policy of the destination printer...
8839 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8840 job
? job
->username
: NULL
)) != HTTP_OK
)
8842 send_http_error(con
, status
, dprinter
);
8847 * Now move the job or jobs...
8853 * See if the job has been completed...
8856 if (job
->state_value
> IPP_JOB_STOPPED
)
8859 * Return a "not-possible" error...
8862 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8863 _("Job #%d is finished and cannot be altered."),
8869 * See if the job is owned by the requesting user...
8872 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8874 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8875 cupsdFindDest(job
->dest
));
8880 * Move the job to a different printer or class...
8883 cupsdMoveJob(job
, dprinter
);
8888 * Got the source printer, now look through the jobs...
8891 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8893 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8896 * See if the job is pointing at the source printer or has not been
8900 if (_cups_strcasecmp(job
->dest
, src
) ||
8901 job
->state_value
> IPP_JOB_STOPPED
)
8905 * See if the job can be moved by the requesting user...
8908 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8912 * Move the job to a different printer or class...
8915 cupsdMoveJob(job
, dprinter
);
8920 * Start jobs if possible...
8926 * Return with "everything is OK" status...
8929 con
->response
->request
.status
.status_code
= IPP_OK
;
8934 * 'ppd_parse_line()' - Parse a PPD default line.
8937 static int /* O - 0 on success, -1 on failure */
8938 ppd_parse_line(const char *line
, /* I - Line */
8939 char *option
, /* O - Option name */
8940 int olen
, /* I - Size of option name */
8941 char *choice
, /* O - Choice name */
8942 int clen
) /* I - Size of choice name */
8945 * Verify this is a default option line...
8948 if (strncmp(line
, "*Default", 8))
8952 * Read the option name...
8955 for (line
+= 8, olen
--;
8956 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8967 * Skip everything else up to the colon (:)...
8970 while (*line
&& *line
!= ':')
8979 * Now grab the option choice, skipping leading whitespace...
8982 while (isspace(*line
& 255))
8986 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8997 * Return with no errors...
9005 * 'print_job()' - Print a file to a printer or class.
9009 print_job(cupsd_client_t
*con
, /* I - Client connection */
9010 ipp_attribute_t
*uri
) /* I - Printer URI */
9012 ipp_attribute_t
*attr
; /* Current attribute */
9013 ipp_attribute_t
*format
; /* Document-format attribute */
9014 const char *default_format
; /* document-format-default value */
9015 cupsd_job_t
*job
; /* New job */
9016 char filename
[1024]; /* Job filename */
9017 mime_type_t
*filetype
; /* Type of file */
9018 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9019 type
[MIME_MAX_TYPE
], /* Subtype of file */
9020 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9021 /* Textual name of mime type */
9022 cupsd_printer_t
*printer
; /* Printer data */
9023 struct stat fileinfo
; /* File information */
9024 int kbytes
; /* Size of file */
9025 int compression
; /* Document compression */
9028 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9029 uri
->values
[0].string
.text
);
9032 * Validate print file attributes, for now just document-format and
9033 * compression (CUPS only supports "none" and "gzip")...
9036 compression
= CUPS_FILE_NONE
;
9038 if ((attr
= ippFindAttribute(con
->request
, "compression",
9039 IPP_TAG_KEYWORD
)) != NULL
)
9041 if (strcmp(attr
->values
[0].string
.text
, "none")
9043 && strcmp(attr
->values
[0].string
.text
, "gzip")
9044 #endif /* HAVE_LIBZ */
9047 send_ipp_status(con
, IPP_ATTRIBUTES
,
9048 _("Unsupported compression \"%s\"."),
9049 attr
->values
[0].string
.text
);
9050 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9051 "compression", NULL
, attr
->values
[0].string
.text
);
9056 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9057 compression
= CUPS_FILE_GZIP
;
9058 #endif /* HAVE_LIBZ */
9062 * Do we have a file to print?
9067 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9072 * Is the destination valid?
9075 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9081 send_ipp_status(con
, IPP_NOT_FOUND
,
9082 _("The printer or class does not exist."));
9087 * Is it a format we support?
9090 if ((format
= ippFindAttribute(con
->request
, "document-format",
9091 IPP_TAG_MIMETYPE
)) != NULL
)
9094 * Grab format from client...
9097 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9100 send_ipp_status(con
, IPP_BAD_REQUEST
,
9101 _("Bad document-format \"%s\"."),
9102 format
->values
[0].string
.text
);
9106 else if ((default_format
= cupsGetOption("document-format",
9107 printer
->num_options
,
9108 printer
->options
)) != NULL
)
9111 * Use default document format...
9114 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9116 send_ipp_status(con
, IPP_BAD_REQUEST
,
9117 _("Bad document-format \"%s\"."),
9128 strcpy(super
, "application");
9129 strcpy(type
, "octet-stream");
9132 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9135 * Auto-type the file...
9138 ipp_attribute_t
*doc_name
; /* document-name attribute */
9141 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9143 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9144 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9145 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9149 filetype
= mimeType(MimeDatabase
, super
, type
);
9151 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9152 filetype
->super
, filetype
->type
);
9155 filetype
= mimeType(MimeDatabase
, super
, type
);
9159 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9162 * Replace the document-format attribute value with the auto-typed or
9166 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9171 _cupsStrFree(format
->values
[0].string
.text
);
9173 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9176 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9177 "document-format", NULL
, mimetype
);
9181 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9182 _("Unsupported document-format \"%s\"."),
9183 format
? format
->values
[0].string
.text
:
9184 "application/octet-stream");
9185 cupsdLogMessage(CUPSD_LOG_INFO
,
9186 "Hint: Do you have the raw file printing rules enabled?");
9189 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9190 "document-format", NULL
, format
->values
[0].string
.text
);
9196 * Read any embedded job ticket info from PS files...
9199 if (!_cups_strcasecmp(filetype
->super
, "application") &&
9200 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
9201 !_cups_strcasecmp(filetype
->type
, "pdf")))
9202 read_job_ticket(con
);
9205 * Create the job object...
9208 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9212 * Update quota data...
9215 if (stat(con
->filename
, &fileinfo
))
9218 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9220 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9222 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9223 IPP_TAG_INTEGER
)) != NULL
)
9224 attr
->values
[0].integer
+= kbytes
;
9227 * Add the job file...
9230 if (add_file(con
, job
, filetype
, compression
))
9233 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9235 rename(con
->filename
, filename
);
9236 cupsdClearString(&con
->filename
);
9239 * See if we need to add the ending sheet...
9242 if (cupsdTimeoutJob(job
))
9246 * Log and save the job...
9249 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9250 "File of type %s/%s queued by \"%s\".",
9251 filetype
->super
, filetype
->type
, job
->username
);
9252 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9253 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9254 job
->dest
, job
->username
);
9257 * Start the job if possible...
9265 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9267 * This function only gets called when printing a single PDF or PostScript
9268 * file using the Print-Job operation. It doesn't work for Create-Job +
9269 * Send-File, since the job attributes need to be set at job creation
9270 * time for banners to work. The embedded job ticket stuff is here
9271 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9272 * options and IPP attributes which otherwise would be lost.
9274 * The format of a job ticket is simple:
9276 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9278 * %cupsJobTicket: attr1=value1
9279 * %cupsJobTicket: attr2=value2
9281 * %cupsJobTicket: attrN=valueN
9283 * Job ticket lines must appear immediately after the first line that
9284 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9285 * stops looking for job ticket info when it finds a line that does not begin
9286 * with "%cupsJobTicket:".
9288 * The maximum length of a job ticket line, including the prefix, is
9289 * 255 characters to conform with the Adobe DSC.
9291 * Read-only attributes are rejected with a notice to the error log in
9292 * case a malicious user tries anything. Since the job ticket is read
9293 * prior to attribute validation in print_job(), job ticket attributes
9294 * will go through the same validation as IPP attributes...
9298 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9300 cups_file_t
*fp
; /* File to read from */
9301 char line
[256]; /* Line data */
9302 int num_options
; /* Number of options */
9303 cups_option_t
*options
; /* Options */
9304 ipp_t
*ticket
; /* New attributes */
9305 ipp_attribute_t
*attr
, /* Current attribute */
9306 *attr2
, /* Job attribute */
9307 *prev2
; /* Previous job attribute */
9311 * First open the print file...
9314 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9316 cupsdLogMessage(CUPSD_LOG_ERROR
,
9317 "Unable to open print file for job ticket - %s",
9323 * Skip the first line...
9326 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9328 cupsdLogMessage(CUPSD_LOG_ERROR
,
9329 "Unable to read from print file for job ticket - %s",
9335 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9338 * Not a DSC-compliant file, so no job ticket info will be available...
9346 * Read job ticket info from the file...
9352 while (cupsFileGets(fp
, line
, sizeof(line
)))
9355 * Stop at the first non-ticket line...
9358 if (strncmp(line
, "%cupsJobTicket:", 15))
9362 * Add the options to the option array...
9365 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9369 * Done with the file; see if we have any options...
9374 if (num_options
== 0)
9378 * OK, convert the options to an attribute list, and apply them to
9383 cupsEncodeOptions(ticket
, num_options
, options
);
9386 * See what the user wants to change.
9389 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9391 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9394 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9395 !strcmp(attr
->name
, "job-originating-user-name") ||
9396 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9397 !strcmp(attr
->name
, "job-k-octets") ||
9398 !strcmp(attr
->name
, "job-id") ||
9399 !strncmp(attr
->name
, "job-state", 9) ||
9400 !strncmp(attr
->name
, "time-at-", 8))
9401 continue; /* Read-only attrs */
9403 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9404 IPP_TAG_ZERO
)) != NULL
)
9407 * Some other value; first free the old value...
9410 if (con
->request
->attrs
== attr2
)
9412 con
->request
->attrs
= attr2
->next
;
9417 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9418 if (prev2
->next
== attr2
)
9420 prev2
->next
= attr2
->next
;
9425 if (con
->request
->last
== attr2
)
9426 con
->request
->last
= prev2
;
9428 ippDeleteAttribute(NULL
, attr2
);
9432 * Add new option by copying it...
9435 ippCopyAttribute(con
->request
, attr
, 0);
9439 * Then free the attribute list and option array...
9443 cupsFreeOptions(num_options
, options
);
9448 * 'reject_jobs()' - Reject print jobs to a printer.
9452 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9453 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9455 http_status_t status
; /* Policy status */
9456 cups_ptype_t dtype
; /* Destination type (printer/class) */
9457 cupsd_printer_t
*printer
; /* Printer data */
9458 ipp_attribute_t
*attr
; /* printer-state-message text */
9461 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9462 con
->http
.fd
, uri
->values
[0].string
.text
);
9465 * Is the destination valid?
9468 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9474 send_ipp_status(con
, IPP_NOT_FOUND
,
9475 _("The printer or class does not exist."));
9483 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9485 send_http_error(con
, status
, printer
);
9490 * Reject jobs sent to the printer...
9493 printer
->accepting
= 0;
9495 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9496 IPP_TAG_TEXT
)) == NULL
)
9497 strcpy(printer
->state_message
, "Rejecting Jobs");
9499 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9500 sizeof(printer
->state_message
));
9502 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9503 "No longer accepting jobs.");
9505 if (dtype
& CUPS_PRINTER_CLASS
)
9507 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9509 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9510 printer
->name
, get_username(con
));
9514 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9516 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9517 printer
->name
, get_username(con
));
9521 * Everything was ok, so return OK status...
9524 con
->response
->request
.status
.status_code
= IPP_OK
;
9529 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9533 release_held_new_jobs(
9534 cupsd_client_t
*con
, /* I - Connection */
9535 ipp_attribute_t
*uri
) /* I - Printer URI */
9537 http_status_t status
; /* Policy status */
9538 cups_ptype_t dtype
; /* Destination type (printer/class) */
9539 cupsd_printer_t
*printer
; /* Printer data */
9542 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9543 con
->http
.fd
, uri
->values
[0].string
.text
);
9546 * Is the destination valid?
9549 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9555 send_ipp_status(con
, IPP_NOT_FOUND
,
9556 _("The printer or class does not exist."));
9564 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9566 send_http_error(con
, status
, printer
);
9571 * Hold pending/new jobs sent to the printer...
9574 printer
->holding_new_jobs
= 0;
9576 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9578 if (dtype
& CUPS_PRINTER_CLASS
)
9579 cupsdLogMessage(CUPSD_LOG_INFO
,
9580 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9581 printer
->name
, get_username(con
));
9583 cupsdLogMessage(CUPSD_LOG_INFO
,
9584 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9585 printer
->name
, get_username(con
));
9588 * Everything was ok, so return OK status...
9591 con
->response
->request
.status
.status_code
= IPP_OK
;
9596 * 'release_job()' - Release a held print job.
9600 release_job(cupsd_client_t
*con
, /* I - Client connection */
9601 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9603 ipp_attribute_t
*attr
; /* Current attribute */
9604 int jobid
; /* Job ID */
9605 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9606 username
[HTTP_MAX_URI
], /* Username portion of URI */
9607 host
[HTTP_MAX_URI
], /* Host portion of URI */
9608 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9609 int port
; /* Port portion of URI */
9610 cupsd_job_t
*job
; /* Job information */
9613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9614 con
->http
.fd
, uri
->values
[0].string
.text
);
9617 * See if we have a job URI or a printer URI...
9620 if (!strcmp(uri
->name
, "printer-uri"))
9623 * Got a printer URI; see if we also have a job-id attribute...
9626 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9627 IPP_TAG_INTEGER
)) == NULL
)
9629 send_ipp_status(con
, IPP_BAD_REQUEST
,
9630 _("Got a printer-uri attribute but no job-id."));
9634 jobid
= attr
->values
[0].integer
;
9639 * Got a job URI; parse it to get the job ID...
9642 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9643 sizeof(scheme
), username
, sizeof(username
), host
,
9644 sizeof(host
), &port
, resource
, sizeof(resource
));
9646 if (strncmp(resource
, "/jobs/", 6))
9652 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9653 uri
->values
[0].string
.text
);
9657 jobid
= atoi(resource
+ 6);
9661 * See if the job exists...
9664 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9667 * Nope - return a "not found" error...
9670 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9675 * See if job is "held"...
9678 if (job
->state_value
!= IPP_JOB_HELD
)
9681 * Nope - return a "not possible" error...
9684 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9689 * See if the job is owned by the requesting user...
9692 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9694 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9695 cupsdFindDest(job
->dest
));
9700 * Reset the job-hold-until value to "no-hold"...
9703 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9704 IPP_TAG_KEYWORD
)) == NULL
)
9705 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9709 _cupsStrFree(attr
->values
[0].string
.text
);
9711 attr
->value_tag
= IPP_TAG_KEYWORD
;
9712 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9714 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9715 "Job job-hold-until value changed by user.");
9719 * Release the job and return...
9722 cupsdReleaseJob(job
);
9724 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9725 "Job released by user.");
9727 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9729 con
->response
->request
.status
.status_code
= IPP_OK
;
9736 * 'renew_subscription()' - Renew an existing subscription...
9741 cupsd_client_t
*con
, /* I - Client connection */
9742 int sub_id
) /* I - Subscription ID */
9744 http_status_t status
; /* Policy status */
9745 cupsd_subscription_t
*sub
; /* Subscription */
9746 ipp_attribute_t
*lease
; /* notify-lease-duration */
9749 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9750 "renew_subscription(con=%p[%d], sub_id=%d)",
9751 con
, con
->http
.fd
, sub_id
);
9754 * Is the subscription ID valid?
9757 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9760 * Bad subscription ID...
9763 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9771 * Job subscriptions cannot be renewed...
9774 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9775 _("Job subscriptions cannot be renewed."));
9783 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9785 con
, sub
->owner
)) != HTTP_OK
)
9787 send_http_error(con
, status
, sub
->dest
);
9792 * Renew the subscription...
9795 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9798 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9800 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9802 cupsdLogMessage(CUPSD_LOG_INFO
,
9803 "renew_subscription: Limiting notify-lease-duration to "
9806 sub
->lease
= MaxLeaseDuration
;
9809 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9811 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9813 con
->response
->request
.status
.status_code
= IPP_OK
;
9815 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9816 "notify-lease-duration", sub
->lease
);
9821 * 'restart_job()' - Restart an old print job.
9825 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9826 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9828 ipp_attribute_t
*attr
; /* Current attribute */
9829 int jobid
; /* Job ID */
9830 cupsd_job_t
*job
; /* Job information */
9831 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9832 username
[HTTP_MAX_URI
], /* Username portion of URI */
9833 host
[HTTP_MAX_URI
], /* Host portion of URI */
9834 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9835 int port
; /* Port portion of URI */
9838 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9839 con
->http
.fd
, uri
->values
[0].string
.text
);
9842 * See if we have a job URI or a printer URI...
9845 if (!strcmp(uri
->name
, "printer-uri"))
9848 * Got a printer URI; see if we also have a job-id attribute...
9851 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9852 IPP_TAG_INTEGER
)) == NULL
)
9854 send_ipp_status(con
, IPP_BAD_REQUEST
,
9855 _("Got a printer-uri attribute but no job-id."));
9859 jobid
= attr
->values
[0].integer
;
9864 * Got a job URI; parse it to get the job ID...
9867 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9868 sizeof(scheme
), username
, sizeof(username
), host
,
9869 sizeof(host
), &port
, resource
, sizeof(resource
));
9871 if (strncmp(resource
, "/jobs/", 6))
9877 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9878 uri
->values
[0].string
.text
);
9882 jobid
= atoi(resource
+ 6);
9886 * See if the job exists...
9889 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9892 * Nope - return a "not found" error...
9895 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9900 * See if job is in any of the "completed" states...
9903 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9906 * Nope - return a "not possible" error...
9909 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9915 * See if we have retained the job files...
9920 if (!job
->attrs
|| job
->num_files
== 0)
9923 * Nope - return a "not possible" error...
9926 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9927 _("Job #%d cannot be restarted - no files."), jobid
);
9932 * See if the job is owned by the requesting user...
9935 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9937 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9938 cupsdFindDest(job
->dest
));
9943 * See if the job-hold-until attribute is specified...
9946 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9947 IPP_TAG_KEYWORD
)) == NULL
)
9948 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9950 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9953 * Return the job to a held state...
9956 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9957 "Restarted by \"%s\" with job-hold-until=%s.",
9958 username
, attr
->values
[0].string
.text
);
9959 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9961 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9962 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9963 attr
->values
[0].string
.text
);
9968 * Restart the job...
9971 cupsdRestartJob(job
);
9975 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9977 con
->response
->request
.status
.status_code
= IPP_OK
;
9982 * 'save_auth_info()' - Save authentication information for a job.
9987 cupsd_client_t
*con
, /* I - Client connection */
9988 cupsd_job_t
*job
, /* I - Job */
9989 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9991 int i
; /* Looping var */
9992 char filename
[1024]; /* Job authentication filename */
9993 cups_file_t
*fp
; /* Job authentication file */
9994 char line
[65536]; /* Line for file */
9995 cupsd_printer_t
*dest
; /* Destination printer/class */
9999 * This function saves the in-memory authentication information for
10000 * a job so that it can be used to authenticate with a remote host.
10001 * The information is stored in a file that is readable only by the
10002 * root user. The fields are Base-64 encoded, each on a separate line,
10003 * followed by random number (up to 1024) of newlines to limit the
10004 * amount of information that is exposed.
10006 * Because of the potential for exposing of authentication information,
10007 * this functionality is only enabled when running cupsd as root.
10009 * This caching only works for the Basic and BasicDigest authentication
10010 * types. Digest authentication cannot be cached this way, and in
10011 * the future Kerberos authentication may make all of this obsolete.
10013 * Authentication information is saved whenever an authenticated
10014 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10017 * This information is deleted after a job is completed or canceled,
10018 * so reprints may require subsequent re-authentication.
10024 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10028 * Create the authentication file and change permissions...
10031 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10032 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10034 cupsdLogMessage(CUPSD_LOG_ERROR
,
10035 "Unable to save authentication info to \"%s\" - %s",
10036 filename
, strerror(errno
));
10040 fchown(cupsFileNumber(fp
), 0, 0);
10041 fchmod(cupsFileNumber(fp
), 0400);
10043 cupsFilePuts(fp
, "CUPSD-AUTH-V2\n");
10046 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10048 cupsdClearString(job
->auth_env
+ i
);
10050 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10053 * Write 1 to 3 auth values...
10057 i
< auth_info
->num_values
&&
10058 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10061 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10062 strlen(auth_info
->values
[i
].string
.text
));
10063 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
10065 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10066 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
10067 auth_info
->values
[i
].string
.text
);
10068 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10069 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
10070 auth_info
->values
[i
].string
.text
);
10071 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10072 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
10073 auth_info
->values
[i
].string
.text
);
10074 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
10075 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
10076 auth_info
->values
[i
].string
.text
);
10081 else if (auth_info
&& auth_info
->num_values
== 2 &&
10082 dest
->num_auth_info_required
== 1 &&
10083 !strcmp(dest
->auth_info_required
[0], "negotiate"))
10086 * Allow fallback to username+password for Kerberized queues...
10089 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
10090 strlen(auth_info
->values
[0].string
.text
));
10091 cupsFilePutConf(fp
, "username", line
);
10093 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
10094 auth_info
->values
[0].string
.text
);
10096 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
10097 strlen(auth_info
->values
[1].string
.text
));
10098 cupsFilePutConf(fp
, "password", line
);
10100 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
10101 auth_info
->values
[1].string
.text
);
10103 else if (con
->username
[0])
10106 * Write the authenticated username...
10109 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10110 cupsFilePutConf(fp
, "username", line
);
10112 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
10115 * Write the authenticated password...
10118 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10119 cupsFilePutConf(fp
, "password", line
);
10121 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
10125 if (con
->gss_uid
> 0)
10127 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
10128 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
10130 #endif /* HAVE_GSSAPI */
10133 * Write a random number of newlines to the end of the file...
10136 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10137 cupsFilePutChar(fp
, '\n');
10140 * Close the file and return...
10148 * 'send_document()' - Send a file to a printer or class.
10152 send_document(cupsd_client_t
*con
, /* I - Client connection */
10153 ipp_attribute_t
*uri
) /* I - Printer URI */
10155 ipp_attribute_t
*attr
; /* Current attribute */
10156 ipp_attribute_t
*format
; /* Request's document-format attribute */
10157 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10158 const char *default_format
;/* document-format-default value */
10159 int jobid
; /* Job ID number */
10160 cupsd_job_t
*job
; /* Current job */
10161 char job_uri
[HTTP_MAX_URI
],
10163 scheme
[HTTP_MAX_URI
],
10164 /* Method portion of URI */
10165 username
[HTTP_MAX_URI
],
10166 /* Username portion of URI */
10167 host
[HTTP_MAX_URI
],
10168 /* Host portion of URI */
10169 resource
[HTTP_MAX_URI
];
10170 /* Resource portion of URI */
10171 int port
; /* Port portion of URI */
10172 mime_type_t
*filetype
; /* Type of file */
10173 char super
[MIME_MAX_SUPER
],
10174 /* Supertype of file */
10175 type
[MIME_MAX_TYPE
],
10176 /* Subtype of file */
10177 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10178 /* Textual name of mime type */
10179 char filename
[1024]; /* Job filename */
10180 cupsd_printer_t
*printer
; /* Current printer */
10181 struct stat fileinfo
; /* File information */
10182 int kbytes
; /* Size of file */
10183 int compression
; /* Type of compression */
10184 int start_job
; /* Start the job? */
10187 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10188 con
->http
.fd
, uri
->values
[0].string
.text
);
10191 * See if we have a job URI or a printer URI...
10194 if (!strcmp(uri
->name
, "printer-uri"))
10197 * Got a printer URI; see if we also have a job-id attribute...
10200 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10201 IPP_TAG_INTEGER
)) == NULL
)
10203 send_ipp_status(con
, IPP_BAD_REQUEST
,
10204 _("Got a printer-uri attribute but no job-id."));
10208 jobid
= attr
->values
[0].integer
;
10213 * Got a job URI; parse it to get the job ID...
10216 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10217 sizeof(scheme
), username
, sizeof(username
), host
,
10218 sizeof(host
), &port
, resource
, sizeof(resource
));
10220 if (strncmp(resource
, "/jobs/", 6))
10226 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10227 uri
->values
[0].string
.text
);
10231 jobid
= atoi(resource
+ 6);
10235 * See if the job exists...
10238 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10241 * Nope - return a "not found" error...
10244 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10248 printer
= cupsdFindDest(job
->dest
);
10251 * See if the job is owned by the requesting user...
10254 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10256 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10257 cupsdFindDest(job
->dest
));
10262 * OK, see if the client is sending the document compressed - CUPS
10263 * only supports "none" and "gzip".
10266 compression
= CUPS_FILE_NONE
;
10268 if ((attr
= ippFindAttribute(con
->request
, "compression",
10269 IPP_TAG_KEYWORD
)) != NULL
)
10271 if (strcmp(attr
->values
[0].string
.text
, "none")
10273 && strcmp(attr
->values
[0].string
.text
, "gzip")
10274 #endif /* HAVE_LIBZ */
10277 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10278 attr
->values
[0].string
.text
);
10279 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10280 "compression", NULL
, attr
->values
[0].string
.text
);
10285 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10286 compression
= CUPS_FILE_GZIP
;
10287 #endif /* HAVE_LIBZ */
10291 * Do we have a file to print?
10294 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10295 IPP_TAG_BOOLEAN
)) == NULL
)
10297 send_ipp_status(con
, IPP_BAD_REQUEST
,
10298 _("Missing last-document attribute in request."));
10302 if (!con
->filename
)
10305 * Check for an empty request with "last-document" set to true, which is
10306 * used to close an "open" job by RFC 2911, section 3.3.2.
10309 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
10310 goto last_document
;
10312 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10317 * Is it a format we support?
10320 if ((format
= ippFindAttribute(con
->request
, "document-format",
10321 IPP_TAG_MIMETYPE
)) != NULL
)
10324 * Grab format from client...
10327 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10330 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10331 format
->values
[0].string
.text
);
10335 else if ((default_format
= cupsGetOption("document-format",
10336 printer
->num_options
,
10337 printer
->options
)) != NULL
)
10340 * Use default document format...
10343 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10345 send_ipp_status(con
, IPP_BAD_REQUEST
,
10346 _("Bad document-format-default \"%s\"."), default_format
);
10353 * No document format attribute? Auto-type it!
10356 strcpy(super
, "application");
10357 strcpy(type
, "octet-stream");
10360 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10363 * Auto-type the file...
10366 ipp_attribute_t
*doc_name
; /* document-name attribute */
10369 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10371 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10372 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10373 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10377 filetype
= mimeType(MimeDatabase
, super
, type
);
10380 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10381 filetype
->super
, filetype
->type
);
10384 filetype
= mimeType(MimeDatabase
, super
, type
);
10389 * Replace the document-format attribute value with the auto-typed or
10393 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10396 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10397 IPP_TAG_MIMETYPE
)) != NULL
)
10399 _cupsStrFree(jformat
->values
[0].string
.text
);
10401 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10404 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10405 "document-format", NULL
, mimetype
);
10407 else if (!filetype
)
10409 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10410 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10411 cupsdLogMessage(CUPSD_LOG_INFO
,
10412 "Hint: Do you have the raw file printing rules enabled?");
10415 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10416 "document-format", NULL
, format
->values
[0].string
.text
);
10421 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10423 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10426 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10427 _("Unsupported document-format \"%s\"."), mimetype
);
10429 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10430 "document-format", NULL
, mimetype
);
10436 * Add the file to the job...
10441 if (add_file(con
, job
, filetype
, compression
))
10444 if (stat(con
->filename
, &fileinfo
))
10447 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10449 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10451 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10452 IPP_TAG_INTEGER
)) != NULL
)
10453 attr
->values
[0].integer
+= kbytes
;
10455 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10457 rename(con
->filename
, filename
);
10459 cupsdClearString(&con
->filename
);
10461 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10462 filetype
->super
, filetype
->type
, job
->username
);
10465 * Start the job if this is the last document...
10470 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10471 IPP_TAG_BOOLEAN
)) != NULL
&&
10472 attr
->values
[0].boolean
)
10475 * See if we need to add the ending sheet...
10478 if (cupsdTimeoutJob(job
))
10481 if (job
->state_value
== IPP_JOB_STOPPED
)
10483 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10484 job
->state_value
= IPP_JOB_PENDING
;
10486 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
10488 else if (job
->state_value
== IPP_JOB_HELD
)
10490 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10491 IPP_TAG_KEYWORD
)) == NULL
)
10492 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10494 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10496 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10497 job
->state_value
= IPP_JOB_PENDING
;
10499 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
10502 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
10506 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10512 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10513 IPP_TAG_KEYWORD
)) == NULL
)
10514 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10516 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10518 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10519 job
->state_value
= IPP_JOB_HELD
;
10520 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10522 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
10525 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10532 * Fill in the response info...
10535 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
10536 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
10537 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10540 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10542 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10544 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
10545 NULL
, job
->reasons
->values
[0].string
.text
);
10547 con
->response
->request
.status
.status_code
= IPP_OK
;
10550 * Start the job if necessary...
10559 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10564 cupsd_client_t
*con
, /* I - Client connection */
10565 http_status_t status
, /* I - HTTP status code */
10566 cupsd_printer_t
*printer
) /* I - Printer, if any */
10568 ipp_attribute_t
*uri
; /* Request URI, if any */
10571 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10572 IPP_TAG_URI
)) == NULL
)
10573 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10575 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10576 "Returning HTTP %s for %s (%s) from %s",
10577 httpStatus(status
),
10579 ippOpString(con
->request
->request
.op
.operation_id
) :
10581 uri
? uri
->values
[0].string
.text
: "no URI",
10582 con
->http
.hostname
);
10586 int auth_type
; /* Type of authentication required */
10589 auth_type
= CUPSD_AUTH_NONE
;
10591 if (status
== HTTP_UNAUTHORIZED
&&
10592 printer
->num_auth_info_required
> 0 &&
10593 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10595 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10596 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10597 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10600 * Creating and authenticating jobs requires Kerberos...
10603 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10608 * Use policy/location-defined authentication requirements...
10611 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10612 cupsd_location_t
*auth
; /* Pointer to authentication element */
10615 if (printer
->type
& CUPS_PRINTER_CLASS
)
10616 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10618 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10620 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10621 auth
->type
== CUPSD_AUTH_NONE
)
10622 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10624 con
->request
->request
.op
.operation_id
:
10629 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10630 auth_type
= cupsdDefaultAuthType();
10632 auth_type
= auth
->type
;
10636 cupsdSendError(con
, status
, auth_type
);
10639 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10641 ippDelete(con
->response
);
10642 con
->response
= NULL
;
10649 * 'send_ipp_status()' - Send a status back to the IPP client.
10653 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10654 ipp_status_t status
, /* I - IPP status code */
10655 const char *message
,/* I - Status message */
10656 ...) /* I - Additional args as needed */
10658 va_list ap
; /* Pointer to additional args */
10659 char formatted
[1024]; /* Formatted errror message */
10662 va_start(ap
, message
);
10663 vsnprintf(formatted
, sizeof(formatted
),
10664 _cupsLangString(con
->language
, message
), ap
);
10667 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10668 ippOpString(con
->request
->request
.op
.operation_id
),
10669 ippErrorString(status
), formatted
);
10671 con
->response
->request
.status
.status_code
= status
;
10673 if (ippFindAttribute(con
->response
, "attributes-charset",
10674 IPP_TAG_ZERO
) == NULL
)
10675 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10676 "attributes-charset", NULL
, "utf-8");
10678 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10679 IPP_TAG_ZERO
) == NULL
)
10680 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10681 "attributes-natural-language", NULL
, DefaultLanguage
);
10683 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10684 "status-message", NULL
, formatted
);
10689 * 'set_default()' - Set the default destination...
10693 set_default(cupsd_client_t
*con
, /* I - Client connection */
10694 ipp_attribute_t
*uri
) /* I - Printer URI */
10696 http_status_t status
; /* Policy status */
10697 cups_ptype_t dtype
; /* Destination type (printer/class) */
10698 cupsd_printer_t
*printer
, /* Printer */
10699 *oldprinter
; /* Old default printer */
10702 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10703 con
->http
.fd
, uri
->values
[0].string
.text
);
10706 * Is the destination valid?
10709 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10715 send_ipp_status(con
, IPP_NOT_FOUND
,
10716 _("The printer or class does not exist."));
10724 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10726 send_http_error(con
, status
, NULL
);
10731 * Set it as the default...
10734 oldprinter
= DefaultPrinter
;
10735 DefaultPrinter
= printer
;
10738 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10739 "%s is no longer the default printer.", oldprinter
->name
);
10741 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10742 "%s is now the default printer.", printer
->name
);
10744 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10745 CUPSD_DIRTY_PRINTCAP
);
10747 cupsdLogMessage(CUPSD_LOG_INFO
,
10748 "Default destination set to \"%s\" by \"%s\".",
10749 printer
->name
, get_username(con
));
10752 * Everything was ok, so return OK status...
10755 con
->response
->request
.status
.status_code
= IPP_OK
;
10760 * 'set_job_attrs()' - Set job attributes.
10764 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10765 ipp_attribute_t
*uri
) /* I - Job URI */
10767 ipp_attribute_t
*attr
, /* Current attribute */
10768 *attr2
; /* Job attribute */
10769 int jobid
; /* Job ID */
10770 cupsd_job_t
*job
; /* Current job */
10771 char scheme
[HTTP_MAX_URI
],
10772 /* Method portion of URI */
10773 username
[HTTP_MAX_URI
],
10774 /* Username portion of URI */
10775 host
[HTTP_MAX_URI
],
10776 /* Host portion of URI */
10777 resource
[HTTP_MAX_URI
];
10778 /* Resource portion of URI */
10779 int port
; /* Port portion of URI */
10780 int event
; /* Events? */
10781 int check_jobs
; /* Check jobs? */
10784 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10785 con
->http
.fd
, uri
->values
[0].string
.text
);
10788 * Start with "everything is OK" status...
10791 con
->response
->request
.status
.status_code
= IPP_OK
;
10794 * See if we have a job URI or a printer URI...
10797 if (!strcmp(uri
->name
, "printer-uri"))
10800 * Got a printer URI; see if we also have a job-id attribute...
10803 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10804 IPP_TAG_INTEGER
)) == NULL
)
10806 send_ipp_status(con
, IPP_BAD_REQUEST
,
10807 _("Got a printer-uri attribute but no job-id."));
10811 jobid
= attr
->values
[0].integer
;
10816 * Got a job URI; parse it to get the job ID...
10819 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10820 sizeof(scheme
), username
, sizeof(username
), host
,
10821 sizeof(host
), &port
, resource
, sizeof(resource
));
10823 if (strncmp(resource
, "/jobs/", 6))
10829 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10830 uri
->values
[0].string
.text
);
10834 jobid
= atoi(resource
+ 6);
10838 * See if the job exists...
10841 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10844 * Nope - return a "not found" error...
10847 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10852 * See if the job has been completed...
10855 if (job
->state_value
> IPP_JOB_STOPPED
)
10858 * Return a "not-possible" error...
10861 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10862 _("Job #%d is finished and cannot be altered."), jobid
);
10867 * See if the job is owned by the requesting user...
10870 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10872 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10873 cupsdFindDest(job
->dest
));
10878 * See what the user wants to change.
10886 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10888 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10891 if (!strcmp(attr
->name
, "attributes-charset") ||
10892 !strcmp(attr
->name
, "attributes-natural-language") ||
10893 !strcmp(attr
->name
, "document-compression") ||
10894 !strcmp(attr
->name
, "document-format") ||
10895 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10896 !strcmp(attr
->name
, "job-document-access-errors") ||
10897 !strcmp(attr
->name
, "job-id") ||
10898 !strcmp(attr
->name
, "job-impressions-completed") ||
10899 !strcmp(attr
->name
, "job-k-octets") ||
10900 !strcmp(attr
->name
, "job-originating-host-name") ||
10901 !strcmp(attr
->name
, "job-originating-user-name") ||
10902 !strcmp(attr
->name
, "job-printer-up-time") ||
10903 !strcmp(attr
->name
, "job-printer-uri") ||
10904 !strcmp(attr
->name
, "job-sheets") ||
10905 !strcmp(attr
->name
, "job-state-message") ||
10906 !strcmp(attr
->name
, "job-state-reasons") ||
10907 !strcmp(attr
->name
, "job-uri") ||
10908 !strcmp(attr
->name
, "number-of-documents") ||
10909 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10910 !strcmp(attr
->name
, "output-device-assigned") ||
10911 !strncmp(attr
->name
, "date-time-at-", 13) ||
10912 !strncmp(attr
->name
, "job-k-octets", 12) ||
10913 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10914 !strncmp(attr
->name
, "time-at-", 8))
10920 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10921 _("%s cannot be changed."), attr
->name
);
10923 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10924 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10928 if (!strcmp(attr
->name
, "job-priority"))
10931 * Change the job priority...
10934 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10936 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10938 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10939 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10941 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10943 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10944 _("Job is completed and cannot be changed."));
10947 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10949 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10950 attr
->values
[0].integer
);
10951 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10954 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10955 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10958 else if (!strcmp(attr
->name
, "job-state"))
10961 * Change the job state...
10964 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10966 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10968 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10969 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10973 switch (attr
->values
[0].integer
)
10975 case IPP_JOB_PENDING
:
10976 case IPP_JOB_HELD
:
10977 if (job
->state_value
> IPP_JOB_HELD
)
10979 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10980 _("Job state cannot be changed."));
10983 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10985 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10986 attr
->values
[0].integer
);
10987 cupsdSetJobState(job
, attr
->values
[0].integer
,
10989 "Job state changed by \"%s\"", username
);
10994 case IPP_JOB_PROCESSING
:
10995 case IPP_JOB_STOPPED
:
10996 if (job
->state_value
!= attr
->values
[0].integer
)
10998 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10999 _("Job state cannot be changed."));
11004 case IPP_JOB_CANCELED
:
11005 case IPP_JOB_ABORTED
:
11006 case IPP_JOB_COMPLETED
:
11007 if (job
->state_value
> IPP_JOB_PROCESSING
)
11009 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11010 _("Job state cannot be changed."));
11013 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11015 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11016 attr
->values
[0].integer
);
11017 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11019 "Job state changed by \"%s\"", username
);
11026 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11028 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11029 IPP_TAG_ZERO
)) != NULL
)
11032 * Some other value; first free the old value...
11035 if (job
->attrs
->prev
)
11036 job
->attrs
->prev
->next
= attr2
->next
;
11038 job
->attrs
->attrs
= attr2
->next
;
11040 if (job
->attrs
->last
== attr2
)
11041 job
->attrs
->last
= job
->attrs
->prev
;
11043 ippDeleteAttribute(NULL
, attr2
);
11046 * Then copy the attribute...
11049 ippCopyAttribute(job
->attrs
, attr
, 0);
11052 * See if the job-name or job-hold-until is being changed.
11055 if (!strcmp(attr
->name
, "job-hold-until"))
11057 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11058 attr
->values
[0].string
.text
);
11059 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11061 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11063 cupsdReleaseJob(job
);
11067 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11068 "Job held by \"%s\".", username
);
11070 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11073 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11076 * Delete the attribute...
11079 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11080 IPP_TAG_ZERO
)) != NULL
)
11082 if (job
->attrs
->prev
)
11083 job
->attrs
->prev
->next
= attr2
->next
;
11085 job
->attrs
->attrs
= attr2
->next
;
11087 if (attr2
== job
->attrs
->last
)
11088 job
->attrs
->last
= job
->attrs
->prev
;
11090 ippDeleteAttribute(NULL
, attr2
);
11092 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11098 * Add new option by copying it...
11101 ippCopyAttribute(job
->attrs
, attr
, 0);
11103 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11112 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11115 * Send events as needed...
11118 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11119 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11120 cupsdFindDest(job
->dest
), job
,
11121 "Job priority changed by user.");
11123 if (event
& CUPSD_EVENT_JOB_STATE
)
11124 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11125 job
->state_value
== IPP_JOB_HELD
?
11126 "Job held by user." : "Job restarted by user.");
11128 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11129 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11130 "Job options changed by user.");
11133 * Start jobs if possible...
11142 * 'set_printer_attrs()' - Set printer attributes.
11146 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11147 ipp_attribute_t
*uri
) /* I - Printer */
11149 http_status_t status
; /* Policy status */
11150 cups_ptype_t dtype
; /* Destination type (printer/class) */
11151 cupsd_printer_t
*printer
; /* Printer/class */
11152 ipp_attribute_t
*attr
; /* Printer attribute */
11153 int changed
= 0; /* Was anything changed? */
11156 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11157 con
->http
.fd
, uri
->values
[0].string
.text
);
11160 * Is the destination valid?
11163 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11169 send_ipp_status(con
, IPP_NOT_FOUND
,
11170 _("The printer or class does not exist."));
11178 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11180 send_http_error(con
, status
, printer
);
11185 * Return a list of attributes that can be set via Set-Printer-Attributes.
11188 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11189 IPP_TAG_TEXT
)) != NULL
)
11191 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11195 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11196 IPP_TAG_TEXT
)) != NULL
)
11198 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11203 * Update the printer attributes and return...
11208 cupsdSetPrinterAttrs(printer
);
11209 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11211 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11212 "Printer \"%s\" description or location changed by \"%s\".",
11213 printer
->name
, get_username(con
));
11215 cupsdLogMessage(CUPSD_LOG_INFO
,
11216 "Printer \"%s\" description or location changed by \"%s\".",
11217 printer
->name
, get_username(con
));
11220 con
->response
->request
.status
.status_code
= IPP_OK
;
11225 * 'set_printer_defaults()' - Set printer default options from a request.
11229 set_printer_defaults(
11230 cupsd_client_t
*con
, /* I - Client connection */
11231 cupsd_printer_t
*printer
) /* I - Printer */
11233 int i
; /* Looping var */
11234 ipp_attribute_t
*attr
; /* Current attribute */
11235 int namelen
; /* Length of attribute name */
11236 char name
[256], /* New attribute name */
11237 value
[256]; /* String version of integer attrs */
11240 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11243 * Skip non-printer attributes...
11246 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11249 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11251 if (!strcmp(attr
->name
, "job-sheets-default"))
11254 * Only allow keywords and names...
11257 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11261 * Only allow job-sheets-default to be set when running without a
11262 * system high classification level...
11265 if (Classification
)
11268 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11270 if (attr
->num_values
> 1)
11271 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11273 cupsdSetString(&printer
->job_sheets
[1], "none");
11275 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11277 cupsdFreeStrings(&(printer
->users
));
11279 printer
->deny_users
= 0;
11281 if (attr
->value_tag
== IPP_TAG_NAME
&&
11282 (attr
->num_values
> 1 ||
11283 strcmp(attr
->values
[0].string
.text
, "all")))
11285 for (i
= 0; i
< attr
->num_values
; i
++)
11286 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11289 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11291 cupsdFreeStrings(&(printer
->users
));
11293 printer
->deny_users
= 1;
11295 if (attr
->value_tag
== IPP_TAG_NAME
&&
11296 (attr
->num_values
> 1 ||
11297 strcmp(attr
->values
[0].string
.text
, "none")))
11299 for (i
= 0; i
< attr
->num_values
; i
++)
11300 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11303 else if (!strcmp(attr
->name
, "job-quota-period"))
11305 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11308 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11309 attr
->values
[0].integer
);
11310 cupsdFreeQuotas(printer
);
11312 printer
->quota_period
= attr
->values
[0].integer
;
11314 else if (!strcmp(attr
->name
, "job-k-limit"))
11316 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11319 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11320 attr
->values
[0].integer
);
11321 cupsdFreeQuotas(printer
);
11323 printer
->k_limit
= attr
->values
[0].integer
;
11325 else if (!strcmp(attr
->name
, "job-page-limit"))
11327 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11330 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11331 attr
->values
[0].integer
);
11332 cupsdFreeQuotas(printer
);
11334 printer
->page_limit
= attr
->values
[0].integer
;
11336 else if (!strcmp(attr
->name
, "printer-op-policy"))
11338 cupsd_policy_t
*p
; /* Policy */
11341 if (attr
->value_tag
!= IPP_TAG_NAME
)
11344 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11347 "Setting printer-op-policy to \"%s\"...",
11348 attr
->values
[0].string
.text
);
11349 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11350 printer
->op_policy_ptr
= p
;
11354 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11355 _("Unknown printer-op-policy \"%s\"."),
11356 attr
->values
[0].string
.text
);
11360 else if (!strcmp(attr
->name
, "printer-error-policy"))
11362 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11365 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11366 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
11367 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11368 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11369 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11371 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11372 _("Unknown printer-error-policy \"%s\"."),
11373 attr
->values
[0].string
.text
);
11377 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11378 "Setting printer-error-policy to \"%s\"...",
11379 attr
->values
[0].string
.text
);
11380 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11384 * Skip any other non-default attributes...
11387 namelen
= strlen(attr
->name
);
11388 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11389 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11393 * OK, anything else must be a user-defined default...
11396 strlcpy(name
, attr
->name
, sizeof(name
));
11397 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11399 switch (attr
->value_tag
)
11401 case IPP_TAG_DELETEATTR
:
11402 printer
->num_options
= cupsRemoveOption(name
,
11403 printer
->num_options
,
11404 &(printer
->options
));
11405 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11406 "Deleting %s", attr
->name
);
11409 case IPP_TAG_NAME
:
11410 case IPP_TAG_KEYWORD
:
11412 printer
->num_options
= cupsAddOption(name
,
11413 attr
->values
[0].string
.text
,
11414 printer
->num_options
,
11415 &(printer
->options
));
11416 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11417 "Setting %s to \"%s\"...", attr
->name
,
11418 attr
->values
[0].string
.text
);
11421 case IPP_TAG_BOOLEAN
:
11422 printer
->num_options
= cupsAddOption(name
,
11423 attr
->values
[0].boolean
?
11425 printer
->num_options
,
11426 &(printer
->options
));
11427 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11428 "Setting %s to %s...", attr
->name
,
11429 attr
->values
[0].boolean
? "true" : "false");
11432 case IPP_TAG_INTEGER
:
11433 case IPP_TAG_ENUM
:
11434 sprintf(value
, "%d", attr
->values
[0].integer
);
11435 printer
->num_options
= cupsAddOption(name
, value
,
11436 printer
->num_options
,
11437 &(printer
->options
));
11438 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11439 "Setting %s to %s...", attr
->name
, value
);
11442 case IPP_TAG_RANGE
:
11443 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11444 attr
->values
[0].range
.upper
);
11445 printer
->num_options
= cupsAddOption(name
, value
,
11446 printer
->num_options
,
11447 &(printer
->options
));
11448 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11449 "Setting %s to %s...", attr
->name
, value
);
11452 case IPP_TAG_RESOLUTION
:
11453 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11454 attr
->values
[0].resolution
.yres
,
11455 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11457 printer
->num_options
= cupsAddOption(name
, value
,
11458 printer
->num_options
,
11459 &(printer
->options
));
11460 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11461 "Setting %s to %s...", attr
->name
, value
);
11465 /* Do nothing for other values */
11473 * 'start_printer()' - Start a printer.
11477 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11478 ipp_attribute_t
*uri
) /* I - Printer URI */
11480 int i
; /* Temporary variable */
11481 http_status_t status
; /* Policy status */
11482 cups_ptype_t dtype
; /* Destination type (printer/class) */
11483 cupsd_printer_t
*printer
; /* Printer data */
11486 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11487 con
->http
.fd
, uri
->values
[0].string
.text
);
11490 * Is the destination valid?
11493 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11499 send_ipp_status(con
, IPP_NOT_FOUND
,
11500 _("The printer or class does not exist."));
11508 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11510 send_http_error(con
, status
, printer
);
11515 * Start the printer...
11518 printer
->state_message
[0] = '\0';
11520 cupsdStartPrinter(printer
, 1);
11522 if (dtype
& CUPS_PRINTER_CLASS
)
11523 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11524 printer
->name
, get_username(con
));
11526 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11527 printer
->name
, get_username(con
));
11535 if ((i
= check_quotas(con
, printer
)) < 0)
11537 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11542 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11547 * Everything was ok, so return OK status...
11550 con
->response
->request
.status
.status_code
= IPP_OK
;
11555 * 'stop_printer()' - Stop a printer.
11559 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11560 ipp_attribute_t
*uri
) /* I - Printer URI */
11562 http_status_t status
; /* Policy status */
11563 cups_ptype_t dtype
; /* Destination type (printer/class) */
11564 cupsd_printer_t
*printer
; /* Printer data */
11565 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11568 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11569 con
->http
.fd
, uri
->values
[0].string
.text
);
11572 * Is the destination valid?
11575 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11581 send_ipp_status(con
, IPP_NOT_FOUND
,
11582 _("The printer or class does not exist."));
11590 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11592 send_http_error(con
, status
, printer
);
11597 * Stop the printer...
11600 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11601 IPP_TAG_TEXT
)) == NULL
)
11602 strcpy(printer
->state_message
, "Paused");
11605 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11606 sizeof(printer
->state_message
));
11609 cupsdStopPrinter(printer
, 1);
11611 if (dtype
& CUPS_PRINTER_CLASS
)
11612 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11613 printer
->name
, get_username(con
));
11615 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11616 printer
->name
, get_username(con
));
11619 * Everything was ok, so return OK status...
11622 con
->response
->request
.status
.status_code
= IPP_OK
;
11627 * 'url_encode_attr()' - URL-encode a string attribute.
11631 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11632 char *buffer
,/* I - String buffer */
11633 int bufsize
)/* I - Size of buffer */
11635 int i
; /* Looping var */
11636 char *bufptr
, /* Pointer into buffer */
11637 *bufend
; /* End of buffer */
11640 strlcpy(buffer
, attr
->name
, bufsize
);
11641 bufptr
= buffer
+ strlen(buffer
);
11642 bufend
= buffer
+ bufsize
- 1;
11644 for (i
= 0; i
< attr
->num_values
; i
++)
11646 if (bufptr
>= bufend
)
11654 if (bufptr
>= bufend
)
11659 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11660 bufptr
, bufend
- bufptr
+ 1);
11662 if (bufptr
>= bufend
)
11673 * 'url_encode_string()' - URL-encode a string.
11676 static char * /* O - End of string */
11677 url_encode_string(const char *s
, /* I - String */
11678 char *buffer
, /* I - String buffer */
11679 int bufsize
) /* I - Size of buffer */
11681 char *bufptr
, /* Pointer into buffer */
11682 *bufend
; /* End of buffer */
11683 static const char *hex
= "0123456789ABCDEF";
11688 bufend
= buffer
+ bufsize
- 1;
11690 while (*s
&& bufptr
< bufend
)
11692 if (*s
== ' ' || *s
== '%' || *s
== '+')
11694 if (bufptr
>= (bufend
- 2))
11698 *bufptr
++ = hex
[(*s
>> 4) & 15];
11699 *bufptr
++ = hex
[*s
& 15];
11703 else if (*s
== '\'' || *s
== '\\')
11705 if (bufptr
>= (bufend
- 1))
11722 * 'user_allowed()' - See if a user is allowed to print to a queue.
11725 static int /* O - 0 if not allowed, 1 if allowed */
11726 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11727 const char *username
) /* I - Username */
11729 struct passwd
*pw
; /* User password data */
11730 char baseuser
[256], /* Base username */
11731 *baseptr
, /* Pointer to "@" in base username */
11732 *name
; /* Current user name */
11735 if (cupsArrayCount(p
->users
) == 0)
11738 if (!strcmp(username
, "root"))
11741 if (strchr(username
, '@'))
11744 * Strip @REALM for username check...
11747 strlcpy(baseuser
, username
, sizeof(baseuser
));
11749 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11752 username
= baseuser
;
11755 pw
= getpwnam(username
);
11758 for (name
= (char *)cupsArrayFirst(p
->users
);
11760 name
= (char *)cupsArrayNext(p
->users
))
11762 if (name
[0] == '@')
11765 * Check group membership...
11768 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11771 else if (name
[0] == '#')
11777 if (cupsdCheckGroup(username
, pw
, name
))
11780 else if (!_cups_strcasecmp(username
, name
))
11784 return ((name
!= NULL
) != p
->deny_users
);
11789 * 'validate_job()' - Validate printer options and destination.
11793 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11794 ipp_attribute_t
*uri
) /* I - Printer URI */
11796 http_status_t status
; /* Policy status */
11797 ipp_attribute_t
*attr
, /* Current attribute */
11798 *auth_info
; /* auth-info attribute */
11799 ipp_attribute_t
*format
; /* Document-format attribute */
11800 cups_ptype_t dtype
; /* Destination type (printer/class) */
11801 char super
[MIME_MAX_SUPER
],
11802 /* Supertype of file */
11803 type
[MIME_MAX_TYPE
];
11804 /* Subtype of file */
11805 cupsd_printer_t
*printer
; /* Printer */
11808 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11809 con
->http
.fd
, uri
->values
[0].string
.text
);
11812 * OK, see if the client is sending the document compressed - CUPS
11813 * doesn't support compression yet...
11816 if ((attr
= ippFindAttribute(con
->request
, "compression",
11817 IPP_TAG_KEYWORD
)) != NULL
)
11819 if (strcmp(attr
->values
[0].string
.text
, "none")
11821 && strcmp(attr
->values
[0].string
.text
, "gzip")
11822 #endif /* HAVE_LIBZ */
11825 send_ipp_status(con
, IPP_ATTRIBUTES
,
11826 _("Unsupported compression \"%s\"."),
11827 attr
->values
[0].string
.text
);
11828 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11829 "compression", NULL
, attr
->values
[0].string
.text
);
11835 * Is it a format we support?
11838 if ((format
= ippFindAttribute(con
->request
, "document-format",
11839 IPP_TAG_MIMETYPE
)) != NULL
)
11841 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11844 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
11845 format
->values
[0].string
.text
);
11849 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11850 !mimeType(MimeDatabase
, super
, type
))
11852 cupsdLogMessage(CUPSD_LOG_INFO
,
11853 "Hint: Do you have the raw file printing rules enabled?");
11854 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11855 _("Unsupported document-format \"%s\"."),
11856 format
->values
[0].string
.text
);
11857 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11858 "document-format", NULL
, format
->values
[0].string
.text
);
11864 * Is the destination valid?
11867 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11873 send_ipp_status(con
, IPP_NOT_FOUND
,
11874 _("The printer or class does not exist."));
11882 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11884 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11886 send_http_error(con
, status
, printer
);
11889 else if (printer
->num_auth_info_required
== 1 &&
11890 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11893 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11897 else if (auth_info
&& !con
->http
.tls
&&
11898 !httpAddrLocalhost(con
->http
.hostaddr
))
11901 * Require encryption of auth-info over non-local connections...
11904 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11907 #endif /* HAVE_SSL */
11910 * Everything was ok, so return OK status...
11913 con
->response
->request
.status
.status_code
= IPP_OK
;
11918 * 'validate_name()' - Make sure the printer name only contains valid chars.
11921 static int /* O - 0 if name is no good, 1 if good */
11922 validate_name(const char *name
) /* I - Name to check */
11924 const char *ptr
; /* Pointer into name */
11928 * Scan the whole name...
11931 for (ptr
= name
; *ptr
; ptr
++)
11932 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11936 * All the characters are good; validate the length, too...
11939 return ((ptr
- name
) < 128);
11944 * 'validate_user()' - Validate the user for the request.
11947 static int /* O - 1 if permitted, 0 otherwise */
11948 validate_user(cupsd_job_t
*job
, /* I - Job */
11949 cupsd_client_t
*con
, /* I - Client connection */
11950 const char *owner
, /* I - Owner of job/resource */
11951 char *username
, /* O - Authenticated username */
11952 int userlen
) /* I - Length of username */
11954 cupsd_printer_t
*printer
; /* Printer for job */
11957 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11958 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11960 job
->id
, con
? con
->http
.fd
: 0,
11961 owner
? owner
: "(null)", username
, userlen
);
11964 * Validate input...
11967 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11971 * Get the best authenticated username that is available.
11974 strlcpy(username
, get_username(con
), userlen
);
11977 * Check the username against the owner...
11980 printer
= cupsdFindDest(job
->dest
);
11982 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11983 con
, owner
) == HTTP_OK
);
11988 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".