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_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printer_supported() - Get printer supported values.
73 * get_printers() - Get a list of printers or classes.
74 * get_subscription_attrs() - Get subscription attributes.
75 * get_subscriptions() - Get subscriptions.
76 * get_username() - Get the username associated with a request.
77 * hold_job() - Hold a print job.
78 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
79 * move_job() - Move a job to a new destination.
80 * ppd_parse_line() - Parse a PPD default line.
81 * print_job() - Print a file to a printer or class.
82 * read_job_ticket() - Read a job ticket embedded in a print file.
83 * reject_jobs() - Reject print jobs to a printer.
84 * release_held_new_jobs() - Release pending/new jobs on a printer or
86 * release_job() - Release a held print job.
87 * renew_subscription() - Renew an existing subscription...
88 * restart_job() - Restart an old print job.
89 * save_auth_info() - Save authentication information for a job.
90 * send_document() - Send a file to a printer or class.
91 * send_http_error() - Send a HTTP error back to the IPP client.
92 * send_ipp_status() - Send a status back to the IPP client.
93 * set_default() - Set the default destination...
94 * set_job_attrs() - Set job attributes.
95 * set_printer_attrs() - Set printer attributes.
96 * set_printer_defaults() - Set printer default options from a request.
97 * start_printer() - Start a printer.
98 * stop_printer() - Stop a printer.
99 * url_encode_attr() - URL-encode a string attribute.
100 * url_encode_string() - URL-encode a string.
101 * user_allowed() - See if a user is allowed to print to a queue.
102 * validate_job() - Validate printer options and destination.
103 * validate_name() - Make sure the printer name only contains
105 * validate_user() - Validate the user for the request.
109 * Include necessary headers...
113 #include <cups/ppd-private.h>
116 # include <ApplicationServices/ApplicationServices.h>
117 # ifdef HAVE_COLORSYNCREGISTERDEVICE
118 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
119 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
120 # include <CoreFoundation/CoreFoundation.h>
121 # ifdef HAVE_MEMBERSHIP_H
122 # include <membership.h>
123 # endif /* HAVE_MEMBERSHIP_H */
124 # ifdef HAVE_MEMBERSHIPPRIV_H
125 # include <membershipPriv.h>
127 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
128 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
129 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
130 # endif /* HAVE_MEMBERSHIPPRIV_H */
131 #endif /* __APPLE__ */
138 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
140 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
141 mime_type_t
*filetype
, int compression
);
142 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
143 mime_type_t
*filetype
);
144 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
145 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_job_uuid(cupsd_job_t
*job
);
147 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
148 static void add_printer_state_reasons(cupsd_client_t
*con
,
150 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
152 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
153 # ifdef HAVE_COLORSYNCREGISTERDEVICE
154 CFMutableDictionaryRef profile
,
156 CMDeviceProfileInfo
*profile
,
157 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
158 unsigned id
, const char *name
,
159 const char *text
, const char *iccfile
);
160 static void apple_register_profiles(cupsd_printer_t
*p
);
161 static void apple_unregister_profiles(cupsd_printer_t
*p
);
162 #endif /* __APPLE__ */
163 static void apply_printer_defaults(cupsd_printer_t
*printer
,
165 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
166 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_subscription(cupsd_client_t
*con
, int id
);
169 static int check_rss_recipient(const char *recipient
);
170 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
171 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
173 ipp_tag_t group
, int quickcopy
,
174 cups_array_t
*exclude
);
175 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
177 static int copy_file(const char *from
, const char *to
);
178 static int copy_model(cupsd_client_t
*con
, const char *from
,
180 static void copy_job_attrs(cupsd_client_t
*con
,
182 cups_array_t
*ra
, cups_array_t
*exclude
);
183 static void copy_printer_attrs(cupsd_client_t
*con
,
184 cupsd_printer_t
*printer
,
186 static void copy_subscription_attrs(cupsd_client_t
*con
,
187 cupsd_subscription_t
*sub
,
189 cups_array_t
*exclude
);
190 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static cups_array_t
*create_requested_array(ipp_t
*request
);
192 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_default(cupsd_client_t
*con
);
195 static void get_devices(cupsd_client_t
*con
);
196 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
199 static void get_notifications(cupsd_client_t
*con
);
200 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_ppds(cupsd_client_t
*con
);
202 static void get_printers(cupsd_client_t
*con
, int type
);
203 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
206 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static const char *get_username(cupsd_client_t
*con
);
208 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static int ppd_parse_line(const char *line
, char *option
, int olen
,
212 char *choice
, int clen
);
213 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void read_job_ticket(cupsd_client_t
*con
);
215 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void release_held_new_jobs(cupsd_client_t
*con
,
217 ipp_attribute_t
*uri
);
218 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
219 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
220 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
221 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
222 ipp_attribute_t
*auth_info
);
223 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
225 cupsd_printer_t
*printer
);
226 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
227 const char *message
, ...)
228 __attribute__((__format__(__printf__
, 3, 4)));
229 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
232 static void set_printer_defaults(cupsd_client_t
*con
,
233 cupsd_printer_t
*printer
);
234 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
238 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
239 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
240 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
241 static int validate_name(const char *name
);
242 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
243 const char *owner
, char *username
,
248 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
251 int /* O - 1 on success, 0 on failure */
252 cupsdProcessIPPRequest(
253 cupsd_client_t
*con
) /* I - Client connection */
255 ipp_tag_t group
; /* Current group tag */
256 ipp_attribute_t
*attr
; /* Current attribute */
257 ipp_attribute_t
*charset
; /* Character set attribute */
258 ipp_attribute_t
*language
; /* Language attribute */
259 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
260 ipp_attribute_t
*username
; /* requesting-user-name attr */
261 int sub_id
; /* Subscription ID */
264 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
265 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
266 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
269 * First build an empty response message for this request...
272 con
->response
= ippNew();
274 con
->response
->request
.status
.version
[0] =
275 con
->request
->request
.op
.version
[0];
276 con
->response
->request
.status
.version
[1] =
277 con
->request
->request
.op
.version
[1];
278 con
->response
->request
.status
.request_id
=
279 con
->request
->request
.op
.request_id
;
282 * Then validate the request header and required attributes...
285 if (con
->request
->request
.any
.version
[0] != 1 &&
286 con
->request
->request
.any
.version
[0] != 2)
289 * Return an error, since we only support IPP 1.x and 2.x.
292 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
293 "%04X %s Bad request version number %d.%d",
294 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
295 con
->request
->request
.any
.version
[0],
296 con
->request
->request
.any
.version
[1]);
298 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
299 _("Bad request version number %d.%d."),
300 con
->request
->request
.any
.version
[0],
301 con
->request
->request
.any
.version
[1]);
303 else if (con
->request
->request
.any
.request_id
< 1)
306 * Return an error, since request IDs must be between 1 and 2^31-1
309 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
310 "%04X %s Bad request ID %d",
311 IPP_BAD_REQUEST
, con
->http
.hostname
,
312 con
->request
->request
.any
.request_id
);
314 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
315 con
->request
->request
.any
.request_id
);
317 else if (!con
->request
->attrs
)
319 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
320 "%04X %s No attributes in request",
321 IPP_BAD_REQUEST
, con
->http
.hostname
);
323 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
328 * Make sure that the attributes are provided in the correct order and
329 * don't repeat groups...
332 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
335 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
338 * Out of order; return an error...
341 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
342 "%04X %s Attribute groups are out of order",
343 IPP_BAD_REQUEST
, con
->http
.hostname
);
345 send_ipp_status(con
, IPP_BAD_REQUEST
,
346 _("Attribute groups are out of order (%x < %x)."),
347 attr
->group_tag
, group
);
351 group
= attr
->group_tag
;
356 * Then make sure that the first three attributes are:
359 * attributes-natural-language
360 * printer-uri/job-uri
363 attr
= con
->request
->attrs
;
364 if (attr
&& attr
->name
&&
365 !strcmp(attr
->name
, "attributes-charset") &&
366 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
374 if (attr
&& attr
->name
&&
375 !strcmp(attr
->name
, "attributes-natural-language") &&
376 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
381 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
382 IPP_TAG_URI
)) != NULL
)
384 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
385 IPP_TAG_URI
)) != NULL
)
387 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
388 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
393 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
394 "attributes-charset", NULL
,
395 charset
->values
[0].string
.text
);
397 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
398 "attributes-charset", NULL
, "utf-8");
401 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
402 "attributes-natural-language", NULL
,
403 language
->values
[0].string
.text
);
405 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
406 "attributes-natural-language", NULL
, DefaultLanguage
);
409 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
410 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
413 * Bad character set...
416 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
417 charset
->values
[0].string
.text
);
418 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
419 "%04X %s Unsupported attributes-charset value \"%s\"",
420 IPP_CHARSET
, con
->http
.hostname
,
421 charset
->values
[0].string
.text
);
422 send_ipp_status(con
, IPP_BAD_REQUEST
,
423 _("Unsupported character set \"%s\"."),
424 charset
->values
[0].string
.text
);
426 else if (!charset
|| !language
||
428 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
429 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
430 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
432 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
435 * Return an error, since attributes-charset,
436 * attributes-natural-language, and printer-uri/job-uri are required
437 * for all operations.
442 cupsdLogMessage(CUPSD_LOG_ERROR
,
443 "Missing attributes-charset attribute");
445 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
446 "%04X %s Missing attributes-charset attribute",
447 IPP_BAD_REQUEST
, con
->http
.hostname
);
452 cupsdLogMessage(CUPSD_LOG_ERROR
,
453 "Missing attributes-natural-language attribute");
455 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
456 "%04X %s Missing attributes-natural-language attribute",
457 IPP_BAD_REQUEST
, con
->http
.hostname
);
462 cupsdLogMessage(CUPSD_LOG_ERROR
,
463 "Missing printer-uri, job-uri, or ppd-name "
466 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
467 "%04X %s Missing printer-uri, job-uri, or ppd-name "
468 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
471 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
473 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
474 cupsdLogMessage(CUPSD_LOG_DEBUG
,
475 "attr \"%s\": group_tag = %x, value_tag = %x",
476 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
479 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
481 send_ipp_status(con
, IPP_BAD_REQUEST
,
482 _("Missing required attributes."));
487 * OK, all the checks pass so far; make sure requesting-user-name is
488 * not "root" from a remote host...
491 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
492 IPP_TAG_NAME
)) != NULL
)
495 * Check for root user...
498 if (!strcmp(username
->values
[0].string
.text
, "root") &&
499 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
500 strcmp(con
->username
, "root"))
503 * Remote unauthenticated user masquerading as local root...
506 _cupsStrFree(username
->values
[0].string
.text
);
507 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
511 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
512 IPP_TAG_INTEGER
)) != NULL
)
513 sub_id
= attr
->values
[0].integer
;
518 * Then try processing the operation...
522 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
523 ippOpString(con
->request
->request
.op
.operation_id
),
524 uri
->values
[0].string
.text
);
526 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
527 ippOpString(con
->request
->request
.op
.operation_id
));
529 switch (con
->request
->request
.op
.operation_id
)
535 case IPP_VALIDATE_JOB
:
536 validate_job(con
, uri
);
539 case IPP_CREATE_JOB
:
540 create_job(con
, uri
);
543 case IPP_SEND_DOCUMENT
:
544 send_document(con
, uri
);
547 case IPP_CANCEL_JOB
:
548 cancel_job(con
, uri
);
551 case IPP_GET_JOB_ATTRIBUTES
:
552 get_job_attrs(con
, uri
);
559 case IPP_GET_PRINTER_ATTRIBUTES
:
560 get_printer_attrs(con
, uri
);
563 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
564 get_printer_supported(con
, uri
);
571 case IPP_RELEASE_JOB
:
572 release_job(con
, uri
);
575 case IPP_RESTART_JOB
:
576 restart_job(con
, uri
);
579 case IPP_PAUSE_PRINTER
:
580 stop_printer(con
, uri
);
583 case IPP_RESUME_PRINTER
:
584 start_printer(con
, uri
);
587 case IPP_PURGE_JOBS
:
588 case IPP_CANCEL_JOBS
:
589 case IPP_CANCEL_MY_JOBS
:
590 cancel_all_jobs(con
, uri
);
593 case IPP_SET_JOB_ATTRIBUTES
:
594 set_job_attrs(con
, uri
);
597 case IPP_SET_PRINTER_ATTRIBUTES
:
598 set_printer_attrs(con
, uri
);
601 case IPP_HOLD_NEW_JOBS
:
602 hold_new_jobs(con
, uri
);
605 case IPP_RELEASE_HELD_NEW_JOBS
:
606 release_held_new_jobs(con
, uri
);
613 case CUPS_GET_DEFAULT
:
617 case CUPS_GET_PRINTERS
:
618 get_printers(con
, 0);
621 case CUPS_GET_CLASSES
:
622 get_printers(con
, CUPS_PRINTER_CLASS
);
625 case CUPS_ADD_PRINTER
:
626 add_printer(con
, uri
);
629 case CUPS_DELETE_PRINTER
:
630 delete_printer(con
, uri
);
633 case CUPS_ADD_CLASS
:
637 case CUPS_DELETE_CLASS
:
638 delete_printer(con
, uri
);
641 case CUPS_ACCEPT_JOBS
:
642 case IPP_ENABLE_PRINTER
:
643 accept_jobs(con
, uri
);
646 case CUPS_REJECT_JOBS
:
647 case IPP_DISABLE_PRINTER
:
648 reject_jobs(con
, uri
);
651 case CUPS_SET_DEFAULT
:
652 set_default(con
, uri
);
655 case CUPS_GET_DEVICES
:
659 case CUPS_GET_DOCUMENT
:
660 get_document(con
, uri
);
675 case CUPS_AUTHENTICATE_JOB
:
676 authenticate_job(con
, uri
);
679 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
680 case IPP_CREATE_JOB_SUBSCRIPTION
:
681 create_subscription(con
, uri
);
684 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
685 get_subscription_attrs(con
, sub_id
);
688 case IPP_GET_SUBSCRIPTIONS
:
689 get_subscriptions(con
, uri
);
692 case IPP_RENEW_SUBSCRIPTION
:
693 renew_subscription(con
, sub_id
);
696 case IPP_CANCEL_SUBSCRIPTION
:
697 cancel_subscription(con
, sub_id
);
700 case IPP_GET_NOTIFICATIONS
:
701 get_notifications(con
);
705 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
706 "%04X %s Operation %04X (%s) not supported",
707 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
708 con
->request
->request
.op
.operation_id
,
709 ippOpString(con
->request
->request
.op
.operation_id
));
711 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
712 _("%s not supported."),
714 con
->request
->request
.op
.operation_id
));
724 * Sending data from the scheduler...
727 cupsdLogMessage(con
->response
->request
.status
.status_code
728 >= IPP_BAD_REQUEST
&&
729 con
->response
->request
.status
.status_code
730 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
731 "Returning IPP %s for %s (%s) from %s",
732 ippErrorString(con
->response
->request
.status
.status_code
),
733 ippOpString(con
->request
->request
.op
.operation_id
),
734 uri
? uri
->values
[0].string
.text
: "no URI",
737 if (LogLevel
== CUPSD_LOG_DEBUG2
)
738 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
739 "cupsdProcessIPPRequest: ippLength(response)=%ld",
740 (long)ippLength(con
->response
));
742 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
744 #ifdef CUPSD_USE_CHUNKING
746 * Because older versions of CUPS (1.1.17 and older) and some IPP
747 * clients do not implement chunking properly, we cannot use
748 * chunking by default. This may become the default in future
749 * CUPS releases, or we might add a configuration directive for
753 if (con
->http
.version
== HTTP_1_1
)
755 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
758 if (cupsdFlushHeader(con
) < 0)
761 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
764 #endif /* CUPSD_USE_CHUNKING */
766 size_t length
; /* Length of response */
769 length
= ippLength(con
->response
);
771 if (con
->file
>= 0 && !con
->pipe_pid
)
773 struct stat fileinfo
; /* File information */
776 if (!fstat(con
->file
, &fileinfo
))
777 length
+= fileinfo
.st_size
;
780 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
781 CUPS_LLCAST length
) < 0)
784 if (cupsdFlushHeader(con
) < 0)
787 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
788 con
->http
.data_remaining
= length
;
790 if (con
->http
.data_remaining
<= INT_MAX
)
791 con
->http
._data_remaining
= con
->http
.data_remaining
;
793 con
->http
._data_remaining
= INT_MAX
;
796 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
797 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
800 * Tell the caller the response header was sent successfully...
808 * Tell the caller the response header could not be sent...
817 * Sending data from a subprocess like cups-deviced; tell the caller
818 * everything is A-OK so far...
827 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
830 int /* O - 0 on success, -1 on error */
831 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
833 cupsd_printer_t
*printer
; /* Destination printer or class */
834 ipp_attribute_t
*attr
; /* job-sheets attribute */
835 int kbytes
; /* Kilobytes in banner */
838 job
->pending_timeout
= 0;
841 * See if we need to add the ending sheet...
844 if (!cupsdLoadJob(job
))
847 printer
= cupsdFindDest(job
->dest
);
848 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
850 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
851 attr
&& attr
->num_values
> 1)
857 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
858 attr
->values
[1].string
.text
);
860 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
863 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
871 * 'accept_jobs()' - Accept print jobs to a printer.
875 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
876 ipp_attribute_t
*uri
) /* I - Printer or class URI */
878 http_status_t status
; /* Policy status */
879 cups_ptype_t dtype
; /* Destination type (printer/class) */
880 cupsd_printer_t
*printer
; /* Printer data */
883 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
884 con
->http
.fd
, uri
->values
[0].string
.text
);
887 * Is the destination valid?
890 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
896 send_ipp_status(con
, IPP_NOT_FOUND
,
897 _("The printer or class does not exist."));
905 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
907 send_http_error(con
, status
, printer
);
912 * Accept jobs sent to the printer...
915 printer
->accepting
= 1;
916 printer
->state_message
[0] = '\0';
918 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
919 "Now accepting jobs.");
921 if (dtype
& CUPS_PRINTER_CLASS
)
923 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
925 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
926 printer
->name
, get_username(con
));
930 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
932 cupsdLogMessage(CUPSD_LOG_INFO
,
933 "Printer \"%s\" now accepting jobs (\"%s\").",
934 printer
->name
, get_username(con
));
938 * Everything was ok, so return OK status...
941 con
->response
->request
.status
.status_code
= IPP_OK
;
946 * 'add_class()' - Add a class to the system.
950 add_class(cupsd_client_t
*con
, /* I - Client connection */
951 ipp_attribute_t
*uri
) /* I - URI of class */
953 http_status_t status
; /* Policy status */
954 int i
; /* Looping var */
955 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
956 username
[HTTP_MAX_URI
], /* Username portion of URI */
957 host
[HTTP_MAX_URI
], /* Host portion of URI */
958 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
959 int port
; /* Port portion of URI */
960 cupsd_printer_t
*pclass
, /* Class */
961 *member
; /* Member printer/class */
962 cups_ptype_t dtype
; /* Destination type */
963 ipp_attribute_t
*attr
; /* Printer attribute */
964 int modify
; /* Non-zero if we just modified */
965 int need_restart_job
; /* Need to restart job? */
968 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
969 con
->http
.fd
, uri
->values
[0].string
.text
);
972 * Do we have a valid URI?
975 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
976 sizeof(scheme
), username
, sizeof(username
), host
,
977 sizeof(host
), &port
, resource
, sizeof(resource
));
980 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
983 * No, return an error...
986 send_ipp_status(con
, IPP_BAD_REQUEST
,
987 _("The printer-uri must be of the form "
988 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
993 * Do we have a valid printer name?
996 if (!validate_name(resource
+ 9))
999 * No, return an error...
1002 send_ipp_status(con
, IPP_BAD_REQUEST
,
1003 _("The printer-uri \"%s\" contains invalid characters."),
1004 uri
->values
[0].string
.text
);
1009 * See if the class already exists; if not, create a new class...
1012 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1015 * Class doesn't exist; see if we have a printer of the same name...
1018 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
1021 * Yes, return an error...
1024 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1025 _("A printer named \"%s\" already exists."),
1031 * No, check the default policy and then add the class...
1034 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1036 send_http_error(con
, status
, NULL
);
1040 pclass
= cupsdAddClass(resource
+ 9);
1043 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1046 send_http_error(con
, status
, pclass
);
1053 * Look for attributes and copy them over as needed...
1056 need_restart_job
= 0;
1058 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1059 IPP_TAG_TEXT
)) != NULL
)
1060 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1062 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1063 IPP_TAG_TEXT
)) != NULL
)
1064 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1066 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1067 IPP_TAG_BOOLEAN
)) != NULL
&&
1068 attr
->values
[0].boolean
!= pclass
->accepting
)
1070 cupsdLogMessage(CUPSD_LOG_INFO
,
1071 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1072 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1074 pclass
->accepting
= attr
->values
[0].boolean
;
1076 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1077 pclass
->accepting
? "Now" : "No longer");
1080 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1081 IPP_TAG_BOOLEAN
)) != NULL
)
1083 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1084 cupsdDeregisterPrinter(pclass
, 1);
1086 cupsdLogMessage(CUPSD_LOG_INFO
,
1087 "Setting %s printer-is-shared to %d (was %d.)",
1088 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1090 pclass
->shared
= attr
->values
[0].boolean
;
1093 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1094 IPP_TAG_ENUM
)) != NULL
)
1096 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1097 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1099 send_ipp_status(con
, IPP_BAD_REQUEST
,
1100 _("Attempt to set %s printer-state to bad value %d."),
1101 pclass
->name
, attr
->values
[0].integer
);
1105 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1106 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1108 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1109 cupsdStopPrinter(pclass
, 0);
1112 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1113 need_restart_job
= 1;
1116 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1117 IPP_TAG_TEXT
)) != NULL
)
1119 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1120 sizeof(pclass
->state_message
));
1122 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1123 pclass
->state_message
);
1125 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1126 IPP_TAG_URI
)) != NULL
)
1129 * Clear the printer array as needed...
1132 need_restart_job
= 1;
1134 if (pclass
->num_printers
> 0)
1136 free(pclass
->printers
);
1137 pclass
->num_printers
= 0;
1141 * Add each printer or class that is listed...
1144 for (i
= 0; i
< attr
->num_values
; i
++)
1147 * Search for the printer or class URI...
1150 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1156 send_ipp_status(con
, IPP_NOT_FOUND
,
1157 _("The printer or class does not exist."));
1160 else if (dtype
& CUPS_PRINTER_CLASS
)
1162 send_ipp_status(con
, IPP_BAD_REQUEST
,
1163 _("Nested classes are not allowed."));
1168 * Add it to the class...
1171 cupsdAddPrinterToClass(pclass
, member
);
1175 set_printer_defaults(con
, pclass
);
1177 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1178 IPP_TAG_KEYWORD
)) != NULL
)
1179 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1182 * Update the printer class attributes and return...
1185 cupsdSetPrinterAttrs(pclass
);
1186 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1188 if (need_restart_job
&& pclass
->job
)
1191 * Reset the current job to a "pending" status...
1194 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1195 "Job restarted because the class was modified.");
1198 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1202 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1203 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1204 pclass
->name
, get_username(con
));
1206 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1207 pclass
->name
, get_username(con
));
1211 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1212 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1213 pclass
->name
, get_username(con
));
1215 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1216 pclass
->name
, get_username(con
));
1219 con
->response
->request
.status
.status_code
= IPP_OK
;
1224 * 'add_file()' - Add a file to a job.
1227 static int /* O - 0 on success, -1 on error */
1228 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1229 cupsd_job_t
*job
, /* I - Job to add to */
1230 mime_type_t
*filetype
, /* I - Type of file */
1231 int compression
) /* I - Compression */
1233 mime_type_t
**filetypes
; /* New filetypes array... */
1234 int *compressions
; /* New compressions array... */
1237 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1238 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1239 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1240 filetype
->super
, filetype
->type
, compression
);
1243 * Add the file to the job...
1246 if (job
->num_files
== 0)
1248 compressions
= (int *)malloc(sizeof(int));
1249 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1253 compressions
= (int *)realloc(job
->compressions
,
1254 (job
->num_files
+ 1) * sizeof(int));
1255 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1256 (job
->num_files
+ 1) *
1257 sizeof(mime_type_t
*));
1260 if (!compressions
|| !filetypes
)
1262 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1263 "Job aborted because the scheduler ran out of memory.");
1266 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1267 _("Unable to allocate memory for file types."));
1272 job
->compressions
= compressions
;
1273 job
->compressions
[job
->num_files
] = compression
;
1274 job
->filetypes
= filetypes
;
1275 job
->filetypes
[job
->num_files
] = filetype
;
1280 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1287 * 'add_job()' - Add a job to a print queue.
1290 static cupsd_job_t
* /* O - Job object */
1291 add_job(cupsd_client_t
*con
, /* I - Client connection */
1292 cupsd_printer_t
*printer
, /* I - Destination printer */
1293 mime_type_t
*filetype
) /* I - First print file type, if any */
1295 http_status_t status
; /* Policy status */
1296 ipp_attribute_t
*attr
, /* Current attribute */
1297 *auth_info
; /* auth-info attribute */
1298 const char *val
; /* Default option value */
1299 int priority
; /* Job priority */
1300 cupsd_job_t
*job
; /* Current job */
1301 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1302 int kbytes
; /* Size of print file */
1303 int i
; /* Looping var */
1304 int lowerpagerange
; /* Page range bound */
1305 int exact
; /* Did we have an exact match? */
1306 ipp_attribute_t
*media_col
, /* media-col attribute */
1307 *media_margin
; /* media-*-margin attribute */
1308 ipp_t
*unsup_col
; /* media-col in unsupported response */
1311 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1312 con
, con
->http
.fd
, printer
, printer
->name
,
1313 filetype
, filetype
? filetype
->super
: "none",
1314 filetype
? filetype
->type
: "none");
1317 * Check remote printing to non-shared printer...
1320 if (!printer
->shared
&&
1321 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1322 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1324 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1325 _("The printer or class is not shared."));
1333 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1335 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1337 send_http_error(con
, status
, printer
);
1340 else if (printer
->num_auth_info_required
== 1 &&
1341 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1344 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1348 else if (auth_info
&& !con
->http
.tls
&&
1349 !httpAddrLocalhost(con
->http
.hostaddr
))
1352 * Require encryption of auth-info over non-local connections...
1355 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1358 #endif /* HAVE_SSL */
1361 * See if the printer is accepting jobs...
1364 if (!printer
->accepting
)
1366 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1367 _("Destination \"%s\" is not accepting jobs."),
1373 * Validate job template attributes; for now just document-format,
1374 * copies, number-up, and page-ranges...
1377 if (filetype
&& printer
->filetypes
&&
1378 !cupsArrayFind(printer
->filetypes
, filetype
))
1380 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1381 /* MIME media type string */
1384 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1387 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1388 _("Unsupported format \"%s\"."), mimetype
);
1390 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1391 "document-format", NULL
, mimetype
);
1396 if ((attr
= ippFindAttribute(con
->request
, "copies",
1397 IPP_TAG_INTEGER
)) != NULL
)
1399 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1401 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1402 attr
->values
[0].integer
);
1403 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1404 "copies", attr
->values
[0].integer
);
1409 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1410 IPP_TAG_ZERO
)) != NULL
)
1412 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1413 attr
->value_tag
!= IPP_TAG_NAME
)
1415 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1419 if (attr
->num_values
> 2)
1421 send_ipp_status(con
, IPP_BAD_REQUEST
,
1422 _("Too many job-sheets values (%d > 2)."),
1427 for (i
= 0; i
< attr
->num_values
; i
++)
1428 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1429 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1431 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1432 attr
->values
[i
].string
.text
);
1437 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1438 IPP_TAG_INTEGER
)) != NULL
)
1440 if (attr
->values
[0].integer
!= 1 &&
1441 attr
->values
[0].integer
!= 2 &&
1442 attr
->values
[0].integer
!= 4 &&
1443 attr
->values
[0].integer
!= 6 &&
1444 attr
->values
[0].integer
!= 9 &&
1445 attr
->values
[0].integer
!= 16)
1447 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1448 attr
->values
[0].integer
);
1449 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1450 "number-up", attr
->values
[0].integer
);
1455 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1456 IPP_TAG_RANGE
)) != NULL
)
1458 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1460 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1461 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1463 send_ipp_status(con
, IPP_BAD_REQUEST
,
1464 _("Bad page-ranges values %d-%d."),
1465 attr
->values
[i
].range
.lower
,
1466 attr
->values
[i
].range
.upper
);
1470 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1475 * Do media selection as needed...
1478 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1479 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1480 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1483 (media_col
= ippFindAttribute(con
->request
, "media-col",
1484 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1486 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1488 unsup_col
= ippNew();
1489 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1490 "media-bottom-margin",
1491 IPP_TAG_INTEGER
)) != NULL
)
1492 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1493 "media-bottom-margin", media_margin
->values
[0].integer
);
1495 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1496 "media-left-margin",
1497 IPP_TAG_INTEGER
)) != NULL
)
1498 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1499 "media-left-margin", media_margin
->values
[0].integer
);
1501 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1502 "media-right-margin",
1503 IPP_TAG_INTEGER
)) != NULL
)
1504 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1505 "media-right-margin", media_margin
->values
[0].integer
);
1507 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1509 IPP_TAG_INTEGER
)) != NULL
)
1510 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1511 "media-top-margin", media_margin
->values
[0].integer
);
1513 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1515 ippDelete(unsup_col
);
1520 * Make sure we aren't over our limit...
1523 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1526 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1528 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1532 if ((i
= check_quotas(con
, printer
)) < 0)
1534 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1539 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1544 * Create the job and set things up...
1547 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1548 IPP_TAG_INTEGER
)) != NULL
)
1549 priority
= attr
->values
[0].integer
;
1552 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1553 printer
->options
)) != NULL
)
1554 priority
= atoi(val
);
1558 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1562 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1563 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1566 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1568 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1569 _("Unable to add job for destination \"%s\"."),
1574 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1575 job
->attrs
= con
->request
;
1577 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1579 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1582 apply_printer_defaults(printer
, job
);
1584 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1586 if (con
->username
[0])
1588 cupsdSetString(&job
->username
, con
->username
);
1591 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1595 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1596 "add_job: requesting-user-name=\"%s\"",
1597 attr
->values
[0].string
.text
);
1599 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1602 cupsdSetString(&job
->username
, "anonymous");
1605 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1606 "job-originating-user-name", NULL
, job
->username
);
1609 attr
->group_tag
= IPP_TAG_JOB
;
1610 _cupsStrFree(attr
->name
);
1611 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1614 if (con
->username
[0] || auth_info
)
1616 save_auth_info(con
, job
, auth_info
);
1619 * Remove the auth-info attribute from the attribute data...
1623 ippDeleteAttribute(job
->attrs
, auth_info
);
1626 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1627 IPP_TAG_ZERO
)) != NULL
)
1630 * Request contains a job-originating-host-name attribute; validate it...
1633 if (attr
->value_tag
!= IPP_TAG_NAME
||
1634 attr
->num_values
!= 1 ||
1635 strcmp(con
->http
.hostname
, "localhost"))
1638 * Can't override the value if we aren't connected via localhost.
1639 * Also, we can only have 1 value and it must be a name value.
1642 switch (attr
->value_tag
)
1644 case IPP_TAG_STRING
:
1645 case IPP_TAG_TEXTLANG
:
1646 case IPP_TAG_NAMELANG
:
1649 case IPP_TAG_KEYWORD
:
1651 case IPP_TAG_URISCHEME
:
1652 case IPP_TAG_CHARSET
:
1653 case IPP_TAG_LANGUAGE
:
1654 case IPP_TAG_MIMETYPE
:
1656 * Free old strings...
1659 for (i
= 0; i
< attr
->num_values
; i
++)
1661 _cupsStrFree(attr
->values
[i
].string
.text
);
1662 attr
->values
[i
].string
.text
= NULL
;
1663 if (attr
->values
[i
].string
.language
)
1665 _cupsStrFree(attr
->values
[i
].string
.language
);
1666 attr
->values
[i
].string
.language
= NULL
;
1675 * Use the default connection hostname instead...
1678 attr
->value_tag
= IPP_TAG_NAME
;
1679 attr
->num_values
= 1;
1680 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1683 attr
->group_tag
= IPP_TAG_JOB
;
1688 * No job-originating-host-name attribute, so use the hostname from
1692 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1693 "job-originating-host-name", NULL
, con
->http
.hostname
);
1696 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1698 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1699 "time-at-processing", 0);
1700 attr
->value_tag
= IPP_TAG_NOVALUE
;
1701 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1702 "time-at-completed", 0);
1703 attr
->value_tag
= IPP_TAG_NOVALUE
;
1706 * Add remaining job attributes...
1709 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1710 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1711 "job-state", IPP_JOB_STOPPED
);
1712 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1713 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1714 "job-media-sheets-completed", 0);
1715 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1718 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1719 IPP_TAG_INTEGER
)) != NULL
)
1720 attr
->values
[0].integer
= 0;
1722 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1724 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1725 IPP_TAG_KEYWORD
)) == NULL
)
1726 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1729 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1730 printer
->options
)) == NULL
)
1733 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1734 "job-hold-until", NULL
, val
);
1736 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1739 * Hold job until specified time...
1742 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1744 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1745 job
->state_value
= IPP_JOB_HELD
;
1747 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1749 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1750 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1751 job
->state_value
= IPP_JOB_HELD
;
1755 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1756 job
->state_value
= IPP_JOB_PENDING
;
1759 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1762 * Add job sheets options...
1765 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1766 IPP_TAG_ZERO
)) == NULL
)
1768 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1769 "Adding default job-sheets values \"%s,%s\"...",
1770 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1772 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1774 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1775 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1778 job
->job_sheets
= attr
;
1781 * Enforce classification level if set...
1786 cupsdLogMessage(CUPSD_LOG_INFO
,
1787 "Classification=\"%s\", ClassifyOverride=%d",
1788 Classification
? Classification
: "(null)",
1791 if (ClassifyOverride
)
1793 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1794 (attr
->num_values
== 1 ||
1795 !strcmp(attr
->values
[1].string
.text
, "none")))
1798 * Force the leading banner to have the classification on it...
1801 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1803 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1804 "job-sheets=\"%s,none\", "
1805 "job-originating-user-name=\"%s\"",
1806 Classification
, job
->username
);
1808 else if (attr
->num_values
== 2 &&
1809 strcmp(attr
->values
[0].string
.text
,
1810 attr
->values
[1].string
.text
) &&
1811 strcmp(attr
->values
[0].string
.text
, "none") &&
1812 strcmp(attr
->values
[1].string
.text
, "none"))
1815 * Can't put two different security markings on the same document!
1818 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1820 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1821 "job-sheets=\"%s,%s\", "
1822 "job-originating-user-name=\"%s\"",
1823 attr
->values
[0].string
.text
,
1824 attr
->values
[1].string
.text
, job
->username
);
1826 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1827 strcmp(attr
->values
[0].string
.text
, "none") &&
1828 (attr
->num_values
== 1 ||
1829 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1830 strcmp(attr
->values
[1].string
.text
, "none"))))
1832 if (attr
->num_values
== 1)
1833 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1834 "CLASSIFICATION OVERRIDDEN "
1835 "job-sheets=\"%s\", "
1836 "job-originating-user-name=\"%s\"",
1837 attr
->values
[0].string
.text
, job
->username
);
1839 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1840 "CLASSIFICATION OVERRIDDEN "
1841 "job-sheets=\"%s,%s\",fffff "
1842 "job-originating-user-name=\"%s\"",
1843 attr
->values
[0].string
.text
,
1844 attr
->values
[1].string
.text
, job
->username
);
1847 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1848 (attr
->num_values
== 1 ||
1849 strcmp(attr
->values
[1].string
.text
, Classification
)))
1852 * Force the banner to have the classification on it...
1855 if (attr
->num_values
> 1 &&
1856 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1858 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1859 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1863 if (attr
->num_values
== 1 ||
1864 strcmp(attr
->values
[0].string
.text
, "none"))
1865 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1867 if (attr
->num_values
> 1 &&
1868 strcmp(attr
->values
[1].string
.text
, "none"))
1869 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1872 if (attr
->num_values
> 1)
1873 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1874 "CLASSIFICATION FORCED "
1875 "job-sheets=\"%s,%s\", "
1876 "job-originating-user-name=\"%s\"",
1877 attr
->values
[0].string
.text
,
1878 attr
->values
[1].string
.text
, job
->username
);
1880 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1881 "CLASSIFICATION FORCED "
1882 "job-sheets=\"%s\", "
1883 "job-originating-user-name=\"%s\"",
1884 Classification
, job
->username
);
1889 * See if we need to add the starting sheet...
1892 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1894 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1895 attr
->values
[0].string
.text
);
1897 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1899 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1900 "Aborting job because the start banner could not be "
1905 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1908 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1909 IPP_TAG_ZERO
)) != NULL
)
1910 job
->job_sheets
= attr
;
1913 * Fill in the response info...
1916 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1917 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1918 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1921 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1923 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1925 add_job_state_reasons(con
, job
);
1927 con
->response
->request
.status
.status_code
= IPP_OK
;
1930 * Add any job subscriptions...
1933 add_job_subscriptions(con
, job
);
1936 * Set all but the first two attributes to the job attributes group...
1939 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1940 attr
->group_tag
= IPP_TAG_JOB
;
1943 * Fire the "job created" event...
1946 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1949 * Return the new job...
1957 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1958 * upon the job and printer state...
1962 add_job_state_reasons(
1963 cupsd_client_t
*con
, /* I - Client connection */
1964 cupsd_job_t
*job
) /* I - Job info */
1966 cupsd_printer_t
*dest
; /* Destination printer */
1967 ipp_attribute_t
*attr
; /* job-hold attribute */
1969 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1970 con
, con
->http
.fd
, job
? job
->id
: 0);
1972 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1974 case IPP_JOB_PENDING
:
1975 dest
= cupsdFindDest(job
->dest
);
1977 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1979 "job-state-reasons", NULL
, "printer-stopped");
1981 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1982 "job-state-reasons", NULL
, "none");
1986 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1987 IPP_TAG_KEYWORD
)) == NULL
)
1988 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1990 if (!attr
|| strcmp(attr
->values
[0].string
.text
, "no-hold"))
1991 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1992 "job-state-reasons", NULL
, "job-hold-until-specified");
1994 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1995 "job-state-reasons", NULL
, "job-incoming");
1998 case IPP_JOB_PROCESSING
:
1999 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2000 "job-state-reasons", NULL
, "job-printing");
2003 case IPP_JOB_STOPPED
:
2004 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2005 "job-state-reasons", NULL
, "job-stopped");
2008 case IPP_JOB_CANCELED
:
2009 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2010 "job-state-reasons", NULL
, "job-canceled-by-user");
2013 case IPP_JOB_ABORTED
:
2014 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2015 "job-state-reasons", NULL
, "aborted-by-system");
2018 case IPP_JOB_COMPLETED
:
2019 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2020 "job-state-reasons", NULL
, "job-completed-successfully");
2027 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2031 add_job_subscriptions(
2032 cupsd_client_t
*con
, /* I - Client connection */
2033 cupsd_job_t
*job
) /* I - Newly created job */
2035 int i
; /* Looping var */
2036 ipp_attribute_t
*prev
, /* Previous attribute */
2037 *next
, /* Next attribute */
2038 *attr
; /* Current attribute */
2039 cupsd_subscription_t
*sub
; /* Subscription object */
2040 const char *recipient
, /* notify-recipient-uri */
2041 *pullmethod
; /* notify-pull-method */
2042 ipp_attribute_t
*user_data
; /* notify-user-data */
2043 int interval
; /* notify-time-interval */
2044 unsigned mask
; /* notify-events */
2048 * Find the first subscription group attribute; return if we have
2052 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2053 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2060 * Process the subscription attributes in the request...
2069 mask
= CUPSD_EVENT_NONE
;
2071 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2073 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2074 attr
->value_tag
== IPP_TAG_URI
)
2077 * Validate the recipient scheme against the ServerBin/notifier
2081 char notifier
[1024], /* Notifier filename */
2082 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2083 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2084 host
[HTTP_MAX_URI
], /* Host portion of URI */
2085 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2086 int port
; /* Port portion of URI */
2089 recipient
= attr
->values
[0].string
.text
;
2091 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2092 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2093 host
, sizeof(host
), &port
,
2094 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2096 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2097 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2098 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2099 "notify-status-code", IPP_URI_SCHEME
);
2103 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2105 if (access(notifier
, X_OK
))
2107 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2108 _("notify-recipient-uri URI \"%s\" uses unknown "
2109 "scheme."), recipient
);
2110 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2111 "notify-status-code", IPP_URI_SCHEME
);
2115 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2117 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2118 _("notify-recipient-uri URI \"%s\" is already used."),
2120 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2121 "notify-status-code", IPP_ATTRIBUTES
);
2125 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2126 attr
->value_tag
== IPP_TAG_KEYWORD
)
2128 pullmethod
= attr
->values
[0].string
.text
;
2130 if (strcmp(pullmethod
, "ippget"))
2132 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2133 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2134 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2135 "notify-status-code", IPP_ATTRIBUTES
);
2139 else if (!strcmp(attr
->name
, "notify-charset") &&
2140 attr
->value_tag
== IPP_TAG_CHARSET
&&
2141 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2142 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2144 send_ipp_status(con
, IPP_CHARSET
,
2145 _("Character set \"%s\" not supported."),
2146 attr
->values
[0].string
.text
);
2149 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2150 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2151 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2153 send_ipp_status(con
, IPP_CHARSET
,
2154 _("Language \"%s\" not supported."),
2155 attr
->values
[0].string
.text
);
2158 else if (!strcmp(attr
->name
, "notify-user-data") &&
2159 attr
->value_tag
== IPP_TAG_STRING
)
2161 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2163 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2164 _("The notify-user-data value is too large "
2165 "(%d > 63 octets)."),
2166 attr
->values
[0].unknown
.length
);
2172 else if (!strcmp(attr
->name
, "notify-events") &&
2173 attr
->value_tag
== IPP_TAG_KEYWORD
)
2175 for (i
= 0; i
< attr
->num_values
; i
++)
2176 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2178 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2180 send_ipp_status(con
, IPP_BAD_REQUEST
,
2181 _("The notify-lease-duration attribute cannot be "
2182 "used with job subscriptions."));
2185 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2186 attr
->value_tag
== IPP_TAG_INTEGER
)
2187 interval
= attr
->values
[0].integer
;
2192 if (!recipient
&& !pullmethod
)
2195 if (mask
== CUPSD_EVENT_NONE
)
2196 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2198 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2199 recipient
, 0)) != NULL
)
2201 sub
->interval
= interval
;
2203 cupsdSetString(&sub
->owner
, job
->username
);
2207 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2208 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2209 sub
->user_data_len
);
2212 ippAddSeparator(con
->response
);
2213 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2214 "notify-subscription-id", sub
->id
);
2216 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2224 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2227 * Remove all of the subscription attributes from the job request...
2229 * TODO: Optimize this since subscription groups have to come at the
2230 * end of the request...
2233 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2237 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2238 attr
->group_tag
== IPP_TAG_ZERO
)
2241 * Free and remove this attribute...
2244 ippDeleteAttribute(NULL
, attr
);
2249 job
->attrs
->attrs
= next
;
2255 job
->attrs
->last
= prev
;
2256 job
->attrs
->current
= prev
;
2261 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2263 * See RFC 4122 for the definition of UUIDs and the format.
2267 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2269 char uuid
[64]; /* job-uuid string */
2273 * Add a job-uuid attribute if none exists...
2276 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2277 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2278 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2279 uuid
, sizeof(uuid
)));
2284 * 'add_printer()' - Add a printer to the system.
2288 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2289 ipp_attribute_t
*uri
) /* I - URI of printer */
2291 http_status_t status
; /* Policy status */
2292 int i
; /* Looping var */
2293 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2294 username
[HTTP_MAX_URI
], /* Username portion of URI */
2295 host
[HTTP_MAX_URI
], /* Host portion of URI */
2296 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2297 int port
; /* Port portion of URI */
2298 cupsd_printer_t
*printer
; /* Printer/class */
2299 ipp_attribute_t
*attr
; /* Printer attribute */
2300 cups_file_t
*fp
; /* Script/PPD file */
2301 char line
[1024]; /* Line from file... */
2302 char srcfile
[1024], /* Source Script/PPD file */
2303 dstfile
[1024]; /* Destination Script/PPD file */
2304 int modify
; /* Non-zero if we are modifying */
2305 int changed_driver
, /* Changed the PPD/interface script? */
2306 need_restart_job
, /* Need to restart job? */
2307 set_device_uri
, /* Did we set the device URI? */
2308 set_port_monitor
; /* Did we set the port monitor? */
2311 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2312 con
->http
.fd
, uri
->values
[0].string
.text
);
2315 * Do we have a valid URI?
2318 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2319 sizeof(scheme
), username
, sizeof(username
), host
,
2320 sizeof(host
), &port
, resource
, sizeof(resource
));
2322 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2325 * No, return an error...
2328 send_ipp_status(con
, IPP_BAD_REQUEST
,
2329 _("The printer-uri must be of the form "
2330 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2335 * Do we have a valid printer name?
2338 if (!validate_name(resource
+ 10))
2341 * No, return an error...
2344 send_ipp_status(con
, IPP_BAD_REQUEST
,
2345 _("The printer-uri \"%s\" contains invalid characters."),
2346 uri
->values
[0].string
.text
);
2351 * See if the printer already exists; if not, create a new printer...
2354 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2357 * Printer doesn't exist; see if we have a class of the same name...
2360 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2363 * Yes, return an error...
2366 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2367 _("A class named \"%s\" already exists."),
2373 * No, check the default policy then add the printer...
2376 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2378 send_http_error(con
, status
, NULL
);
2382 printer
= cupsdAddPrinter(resource
+ 10);
2385 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2388 send_http_error(con
, status
, printer
);
2395 * Look for attributes and copy them over as needed...
2399 need_restart_job
= 0;
2401 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2402 IPP_TAG_TEXT
)) != NULL
)
2403 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2405 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2406 IPP_TAG_TEXT
)) != NULL
)
2407 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2411 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2412 IPP_TAG_URI
)) != NULL
)
2415 * Do we have a valid device URI?
2418 http_uri_status_t uri_status
; /* URI separation status */
2419 char old_device_uri
[1024];
2420 /* Old device URI */
2423 need_restart_job
= 1;
2425 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2426 attr
->values
[0].string
.text
,
2427 scheme
, sizeof(scheme
),
2428 username
, sizeof(username
),
2429 host
, sizeof(host
), &port
,
2430 resource
, sizeof(resource
));
2432 if (uri_status
< HTTP_URI_OK
)
2434 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2435 attr
->values
[0].string
.text
);
2436 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2437 "add_printer: httpSeparateURI returned %d", uri_status
);
2441 if (!strcmp(scheme
, "file"))
2444 * See if the administrator has enabled file devices...
2447 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2450 * File devices are disabled and the URL is not file:/dev/null...
2453 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2454 _("File device URIs have been disabled. "
2455 "To enable, see the FileDevice directive in "
2456 "\"%s/cupsd.conf\"."),
2464 * See if the backend exists and is executable...
2467 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2468 if (access(srcfile
, X_OK
))
2471 * Could not find device in list!
2474 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2475 _("Bad device-uri scheme \"%s\"."), scheme
);
2480 if (printer
->sanitized_device_uri
)
2481 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2482 sizeof(old_device_uri
));
2484 old_device_uri
[0] = '\0';
2486 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2488 cupsdLogMessage(CUPSD_LOG_INFO
,
2489 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2490 printer
->name
, printer
->sanitized_device_uri
,
2496 set_port_monitor
= 0;
2498 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2499 IPP_TAG_NAME
)) != NULL
)
2501 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2504 need_restart_job
= 1;
2506 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2510 for (i
= 0; i
< supported
->num_values
; i
++)
2511 if (!strcmp(supported
->values
[i
].string
.text
,
2512 attr
->values
[0].string
.text
))
2516 if (!supported
|| i
>= supported
->num_values
)
2518 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2519 attr
->values
[0].string
.text
);
2523 cupsdLogMessage(CUPSD_LOG_INFO
,
2524 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2525 printer
->name
, attr
->values
[0].string
.text
,
2526 printer
->port_monitor
? printer
->port_monitor
: "none");
2528 if (strcmp(attr
->values
[0].string
.text
, "none"))
2529 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2531 cupsdClearString(&printer
->port_monitor
);
2533 set_port_monitor
= 1;
2536 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2537 IPP_TAG_BOOLEAN
)) != NULL
&&
2538 attr
->values
[0].boolean
!= printer
->accepting
)
2540 cupsdLogMessage(CUPSD_LOG_INFO
,
2541 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2542 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2544 printer
->accepting
= attr
->values
[0].boolean
;
2546 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2547 "%s accepting jobs.",
2548 printer
->accepting
? "Now" : "No longer");
2551 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2552 IPP_TAG_BOOLEAN
)) != NULL
)
2554 if (attr
->values
[0].boolean
&&
2555 printer
->num_auth_info_required
== 1 &&
2556 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2558 send_ipp_status(con
, IPP_BAD_REQUEST
,
2559 _("Cannot share a remote Kerberized printer."));
2563 if (printer
->shared
&& !attr
->values
[0].boolean
)
2564 cupsdDeregisterPrinter(printer
, 1);
2566 cupsdLogMessage(CUPSD_LOG_INFO
,
2567 "Setting %s printer-is-shared to %d (was %d.)",
2568 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2570 printer
->shared
= attr
->values
[0].boolean
;
2573 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2574 IPP_TAG_ENUM
)) != NULL
)
2576 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2577 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2579 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2580 attr
->values
[0].integer
);
2584 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2585 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2587 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2588 cupsdStopPrinter(printer
, 0);
2591 need_restart_job
= 1;
2592 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2596 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2597 IPP_TAG_TEXT
)) != NULL
)
2599 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2600 sizeof(printer
->state_message
));
2602 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2603 printer
->state_message
);
2606 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2607 IPP_TAG_KEYWORD
)) != NULL
)
2609 if (attr
->num_values
>
2610 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2612 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2613 _("Too many printer-state-reasons values (%d > %d)."),
2615 (int)(sizeof(printer
->reasons
) /
2616 sizeof(printer
->reasons
[0])));
2620 for (i
= 0; i
< printer
->num_reasons
; i
++)
2621 _cupsStrFree(printer
->reasons
[i
]);
2623 printer
->num_reasons
= 0;
2624 for (i
= 0; i
< attr
->num_values
; i
++)
2626 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2629 printer
->reasons
[printer
->num_reasons
] =
2630 _cupsStrRetain(attr
->values
[i
].string
.text
);
2631 printer
->num_reasons
++;
2633 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2634 printer
->state
!= IPP_PRINTER_STOPPED
)
2636 cupsdLogMessage(CUPSD_LOG_INFO
,
2637 "Setting %s printer-state to %d (was %d.)",
2638 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2639 cupsdStopPrinter(printer
, 0);
2643 if (PrintcapFormat
== PRINTCAP_PLIST
)
2644 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2646 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2647 "Printer \"%s\" state changed.", printer
->name
);
2650 set_printer_defaults(con
, printer
);
2652 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2653 IPP_TAG_KEYWORD
)) != NULL
)
2654 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2657 * See if we have all required attributes...
2660 if (!printer
->device_uri
)
2661 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2664 * See if we have an interface script or PPD file attached to the request...
2669 need_restart_job
= 1;
2672 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2674 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2677 * Yes; get the first line from it...
2681 cupsFileGets(fp
, line
, sizeof(line
));
2685 * Then see what kind of file it is...
2688 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2691 if (!strncmp(line
, "*PPD-Adobe", 10))
2694 * The new file is a PPD file, so remove any old interface script
2695 * that might be lying around...
2703 * This must be an interface script, so move the file over to the
2704 * interfaces directory and make it executable...
2707 if (copy_file(srcfile
, dstfile
))
2709 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2710 _("Unable to copy interface script - %s"),
2715 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2716 "Copied interface script successfully");
2717 chmod(dstfile
, 0755);
2720 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2723 if (!strncmp(line
, "*PPD-Adobe", 10))
2726 * The new file is a PPD file, so move the file over to the
2727 * ppd directory and make it readable by all...
2730 if (copy_file(srcfile
, dstfile
))
2732 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2733 _("Unable to copy PPD file - %s"),
2738 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2739 "Copied PPD file successfully");
2740 chmod(dstfile
, 0644);
2745 * This must be an interface script, so remove any old PPD file that
2746 * may be lying around...
2753 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2754 IPP_TAG_NAME
)) != NULL
)
2756 need_restart_job
= 1;
2759 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2762 * Raw driver, remove any existing PPD or interface script files.
2765 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2769 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2779 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2783 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2786 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2788 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2792 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2793 "Copied PPD file successfully");
2794 chmod(dstfile
, 0644);
2801 * If we changed the PPD/interface script, then remove the printer's cache
2802 * file and clear the printer-state-reasons...
2805 char cache_name
[1024]; /* Cache filename for printer attrs */
2807 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2811 cupsdSetPrinterReasons(printer
, "none");
2815 * (Re)register color profiles...
2820 apple_unregister_profiles(printer
);
2821 apple_register_profiles(printer
);
2823 #endif /* __APPLE__ */
2827 * If we set the device URI but not the port monitor, check which port
2828 * monitor to use by default...
2831 if (set_device_uri
&& !set_port_monitor
)
2833 ppd_file_t
*ppd
; /* PPD file */
2834 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2837 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2838 sizeof(scheme
), username
, sizeof(username
), host
,
2839 sizeof(host
), &port
, resource
, sizeof(resource
));
2841 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2843 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2845 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2847 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2848 if (!strcmp(scheme
, ppdattr
->spec
))
2850 cupsdLogMessage(CUPSD_LOG_INFO
,
2851 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2852 printer
->name
, ppdattr
->value
,
2853 printer
->port_monitor
? printer
->port_monitor
2856 if (strcmp(ppdattr
->value
, "none"))
2857 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2859 cupsdClearString(&printer
->port_monitor
);
2869 * Update the printer attributes and return...
2872 cupsdSetPrinterAttrs(printer
);
2873 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2875 if (need_restart_job
&& printer
->job
)
2878 * Restart the current job...
2881 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2882 "Job restarted because the printer was modified.");
2885 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2889 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2890 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2891 printer
->name
, get_username(con
));
2893 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2894 printer
->name
, get_username(con
));
2898 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2899 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2900 printer
->name
, get_username(con
));
2902 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2903 printer
->name
, get_username(con
));
2906 con
->response
->request
.status
.status_code
= IPP_OK
;
2911 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2912 * based upon the printer state...
2916 add_printer_state_reasons(
2917 cupsd_client_t
*con
, /* I - Client connection */
2918 cupsd_printer_t
*p
) /* I - Printer info */
2920 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2921 "add_printer_state_reasons(%p[%d], %p[%s])",
2922 con
, con
->http
.fd
, p
, p
->name
);
2924 if (p
->num_reasons
== 0)
2925 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2926 "printer-state-reasons", NULL
, "none");
2928 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2929 "printer-state-reasons", p
->num_reasons
, NULL
,
2930 (const char * const *)p
->reasons
);
2935 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2936 * the specified printer or class.
2940 add_queued_job_count(
2941 cupsd_client_t
*con
, /* I - Client connection */
2942 cupsd_printer_t
*p
) /* I - Printer or class */
2944 int count
; /* Number of jobs on destination */
2947 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2948 con
, con
->http
.fd
, p
, p
->name
);
2950 count
= cupsdGetPrinterJobCount(p
->name
);
2952 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2953 "queued-job-count", count
);
2959 * 'apple_init_profile()' - Initialize a color profile.
2964 ppd_file_t
*ppd
, /* I - PPD file */
2965 cups_array_t
*languages
, /* I - Languages in the PPD file */
2966 # ifdef HAVE_COLORSYNCREGISTERDEVICE
2967 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
2969 CMDeviceProfileInfo
*profile
, /* I - Profile record */
2970 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
2971 unsigned id
, /* I - Profile ID */
2972 const char *name
, /* I - Profile name */
2973 const char *text
, /* I - Profile UI text */
2974 const char *iccfile
) /* I - ICC filename */
2976 # ifdef HAVE_COLORSYNCREGISTERDEVICE
2977 CFURLRef url
; /* URL for profile filename */
2978 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
2979 CFMutableDictionaryRef dict
; /* Dictionary for name */
2980 char *language
; /* Current language */
2981 ppd_attr_t
*attr
; /* Profile attribute */
2982 CFStringRef cflang
, /* Language string */
2983 cftext
; /* Localized text */
2989 * Build the profile name dictionary...
2992 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2993 &kCFTypeDictionaryKeyCallBacks
,
2994 &kCFTypeDictionaryValueCallBacks
);
2997 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize profile \"%s\".",
3002 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3003 kCFStringEncodingUTF8
);
3007 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3014 * Find localized names for the color profiles...
3017 cupsArraySave(ppd
->sorted_attrs
);
3019 for (language
= (char *)cupsArrayFirst(languages
);
3021 language
= (char *)cupsArrayNext(languages
))
3025 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3027 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3030 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3032 if (attr
&& attr
->text
[0])
3034 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3035 kCFStringEncodingUTF8
);
3036 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3037 kCFStringEncodingUTF8
);
3039 if (cflang
&& cftext
)
3040 CFDictionarySetValue(dict
, cflang
, cftext
);
3050 cupsArrayRestore(ppd
->sorted_attrs
);
3054 * Fill in the profile data...
3057 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3060 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3061 (const UInt8
*)iccfile
,
3062 strlen(iccfile
), false);
3066 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3071 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3075 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3076 profile
->profileID
= id
;
3077 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3078 profile
->profileName
= dict
;
3081 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3082 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3083 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3088 * 'apple_register_profiles()' - Register color profiles for a printer.
3092 apple_register_profiles(
3093 cupsd_printer_t
*p
) /* I - Printer */
3095 int i
; /* Looping var */
3096 char ppdfile
[1024], /* PPD filename */
3097 iccfile
[1024], /* ICC filename */
3098 selector
[PPD_MAX_NAME
];
3099 /* Profile selection string */
3100 ppd_file_t
*ppd
; /* PPD file */
3101 ppd_attr_t
*attr
, /* Profile attributes */
3102 *profileid_attr
,/* cupsProfileID attribute */
3103 *q1_attr
, /* ColorModel (or other) qualifier */
3104 *q2_attr
, /* MediaType (or other) qualifier */
3105 *q3_attr
; /* Resolution (or other) qualifier */
3106 char q_keyword
[PPD_MAX_NAME
];
3107 /* Qualifier keyword */
3108 const char *q1_choice
, /* ColorModel (or other) choice */
3109 *q2_choice
, /* MediaType (or other) choice */
3110 *q3_choice
; /* Resolution (or other) choice */
3111 const char *profile_key
; /* Profile keyword */
3112 ppd_option_t
*cm_option
; /* Color model option */
3113 ppd_choice_t
*cm_choice
; /* Color model choice */
3114 int num_profiles
; /* Number of profiles */
3115 OSStatus error
= 0; /* Last error */
3116 unsigned device_id
, /* Printer device ID */
3117 profile_id
= 0, /* Profile ID */
3118 default_profile_id
= 0;
3119 /* Default profile ID */
3120 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3121 CFStringRef printer_name
; /* Printer name string */
3122 cups_array_t
*languages
; /* Languages array */
3123 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3124 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3125 profile
; /* Current profile info dictionary */
3126 CFStringRef dict_key
; /* Key in factory profile dictionary */
3128 CMDeviceScope scope
= /* Scope of the registration */
3130 kCFPreferencesAnyUser
,
3131 kCFPreferencesCurrentHost
3133 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3134 CMDeviceProfileInfo
*profile
; /* Current profile */
3135 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3139 * Make sure ColorSync is available...
3142 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3143 if (ColorSyncRegisterDevice
== NULL
)
3147 if (CMRegisterColorDevice
== NULL
)
3149 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3152 * Try opening the PPD file for this printer...
3155 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3156 if ((ppd
= _ppdOpenFile(ppdfile
, _PPD_LOCALIZATION_ICC_PROFILES
)) == NULL
)
3160 * See if we have any profiles...
3163 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3164 profile_key
= "APTiogaProfile";
3167 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3168 profile_key
= "cupsICCProfile";
3171 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3172 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3174 if (attr
->value
[0] != '/')
3175 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3178 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3180 if (access(iccfile
, 0))
3182 cupsdLogMessage(CUPSD_LOG_ERROR
,
3183 "%s: ICC Profile \"%s\" does not exist.", p
->name
,
3191 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3193 * Create a dictionary for the factory profiles...
3196 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3197 &kCFTypeDictionaryKeyCallBacks
,
3198 &kCFTypeDictionaryValueCallBacks
);
3201 cupsdLogMessage(CUPSD_LOG_ERROR
,
3202 "Unable to allocate memory for factory profiles.");
3206 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3209 * If we have profiles, add them...
3212 if (num_profiles
> 0)
3214 if (profile_key
[0] == 'A')
3217 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3221 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3223 default_profile_id
= atoi(attr
->value
);
3225 q1_choice
= q2_choice
= q3_choice
= NULL
;
3230 * For CUPS PPDs, figure out the default profile selector values...
3233 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3234 attr
->value
&& attr
->value
[0])
3236 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3237 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3239 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3240 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3242 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3243 q1_choice
= q1_attr
->value
;
3247 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3248 attr
->value
&& attr
->value
[0])
3250 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3251 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3254 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3256 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3257 q2_choice
= q2_attr
->value
;
3261 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3262 attr
->value
&& attr
->value
[0])
3264 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3265 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3268 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3270 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3271 q3_choice
= q3_attr
->value
;
3276 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3278 * Build the array of profiles...
3280 * Note: This calloc actually requests slightly more memory than needed.
3283 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3285 cupsdLogMessage(CUPSD_LOG_ERROR
,
3286 "Unable to allocate memory for factory profiles.");
3291 profiles
->profileCount
= num_profiles
;
3292 profile
= profiles
->profiles
;
3293 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3296 * Loop through the profiles listed in the PPD...
3299 languages
= _ppdGetLanguages(ppd
);
3301 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3303 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3304 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3307 * Add this profile...
3310 if (attr
->value
[0] != '/')
3311 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3314 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3316 if (_cupsFileCheck(iccfile
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
3317 cupsdLogFCMessage
, p
))
3320 if (profile_key
[0] == 'c')
3322 cupsArraySave(ppd
->sorted_attrs
);
3324 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3325 attr
->spec
)) != NULL
&&
3326 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3327 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3329 profile_id
= _ppdHashName(attr
->spec
);
3331 cupsArrayRestore(ppd
->sorted_attrs
);
3334 profile_id
= atoi(attr
->spec
);
3336 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3337 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3338 &kCFTypeDictionaryKeyCallBacks
,
3339 &kCFTypeDictionaryValueCallBacks
);
3342 cupsdLogMessage(CUPSD_LOG_ERROR
,
3343 "Unable to allocate memory for color profile.");
3344 CFRelease(profiles
);
3349 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3350 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3352 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3353 CFSTR("%u"), profile_id
);
3356 CFDictionarySetValue(profiles
, dict_key
, profile
);
3357 CFRelease(dict_key
);
3363 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3364 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3367 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3370 * See if this is the default profile...
3373 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3375 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3377 if (!strcmp(selector
, attr
->spec
))
3378 default_profile_id
= profile_id
;
3381 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3383 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3384 if (!strcmp(selector
, attr
->spec
))
3385 default_profile_id
= profile_id
;
3388 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3390 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3391 if (!strcmp(selector
, attr
->spec
))
3392 default_profile_id
= profile_id
;
3395 if (!default_profile_id
&& q1_choice
)
3397 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3398 if (!strcmp(selector
, attr
->spec
))
3399 default_profile_id
= profile_id
;
3402 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3404 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3405 if (!strcmp(selector
, attr
->spec
))
3406 default_profile_id
= profile_id
;
3409 if (!default_profile_id
&& q2_choice
)
3411 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3412 if (!strcmp(selector
, attr
->spec
))
3413 default_profile_id
= profile_id
;
3416 if (!default_profile_id
&& q3_choice
)
3418 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3419 if (!strcmp(selector
, attr
->spec
))
3420 default_profile_id
= profile_id
;
3424 _ppdFreeLanguages(languages
);
3426 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3429 * Extract profiles from ColorModel option...
3432 const char *profile_name
; /* Name of generic profile */
3435 num_profiles
= cm_option
->num_choices
;
3437 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3439 * Create an array for the factory profiles...
3442 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3444 cupsdLogMessage(CUPSD_LOG_ERROR
,
3445 "Unable to allocate memory for factory profiles.");
3450 profiles
->profileCount
= num_profiles
;
3451 profile
= profiles
->profiles
;
3452 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3454 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3458 if (!strcmp(cm_choice
->choice
, "Gray") ||
3459 !strcmp(cm_choice
->choice
, "Black"))
3460 profile_name
= "Gray";
3461 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3462 !strcmp(cm_choice
->choice
, "CMY"))
3463 profile_name
= "RGB";
3464 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3465 !strcmp(cm_choice
->choice
, "KCMY"))
3466 profile_name
= "CMYK";
3468 profile_name
= "DeviceN";
3470 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3471 profile_id
= _ppdHashName(selector
);
3473 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3474 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3475 &kCFTypeDictionaryKeyCallBacks
,
3476 &kCFTypeDictionaryValueCallBacks
);
3479 cupsdLogMessage(CUPSD_LOG_ERROR
,
3480 "Unable to allocate memory for color profile.");
3481 CFRelease(profiles
);
3486 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3487 cm_choice
->text
, NULL
);
3489 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3490 CFSTR("%u"), profile_id
);
3493 CFDictionarySetValue(profiles
, dict_key
, profile
);
3494 CFRelease(dict_key
);
3500 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3501 cm_choice
->text
, NULL
);
3503 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3505 if (cm_choice
->marked
)
3506 default_profile_id
= profile_id
;
3512 * Use the default colorspace...
3515 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3517 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3519 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3521 * Add the grayscale profile first. We always have a grayscale profile.
3524 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3525 &kCFTypeDictionaryKeyCallBacks
,
3526 &kCFTypeDictionaryValueCallBacks
);
3530 cupsdLogMessage(CUPSD_LOG_ERROR
,
3531 "Unable to allocate memory for color profile.");
3532 CFRelease(profiles
);
3537 profile_id
= _ppdHashName("Gray..");
3538 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3540 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3544 CFDictionarySetValue(profiles
, dict_key
, profile
);
3545 CFRelease(dict_key
);
3551 * Then add the RGB/CMYK/DeviceN color profile...
3554 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3555 &kCFTypeDictionaryKeyCallBacks
,
3556 &kCFTypeDictionaryValueCallBacks
);
3560 cupsdLogMessage(CUPSD_LOG_ERROR
,
3561 "Unable to allocate memory for color profile.");
3562 CFRelease(profiles
);
3567 switch (ppd
->colorspace
)
3572 profile_id
= _ppdHashName("RGB..");
3573 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3579 profile_id
= _ppdHashName("CMYK..");
3580 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3589 profile_id
= _ppdHashName("DeviceN..");
3590 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3595 if (CFDictionaryGetCount(profile
) > 0)
3597 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3598 CFSTR("%u"), profile_id
);
3601 CFDictionarySetValue(profiles
, dict_key
, profile
);
3602 CFRelease(dict_key
);
3610 * Create an array for the factory profiles...
3613 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3615 cupsdLogMessage(CUPSD_LOG_ERROR
,
3616 "Unable to allocate memory for factory profiles.");
3621 profiles
->profileCount
= num_profiles
;
3624 * Add the grayscale profile first. We always have a grayscale profile.
3627 profile_id
= _ppdHashName("Gray..");
3628 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3632 * Then add the RGB/CMYK/DeviceN color profile...
3635 switch (ppd
->colorspace
)
3640 profile_id
= _ppdHashName("RGB..");
3641 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3642 "RGB", "RGB", NULL
);
3646 profile_id
= _ppdHashName("CMYK..");
3647 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3648 "CMYK", "CMYK", NULL
);
3656 profile_id
= _ppdHashName("DeviceN..");
3657 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3658 "DeviceN", "DeviceN", NULL
);
3661 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3664 if (num_profiles
> 0)
3667 * Make sure we have a default profile ID...
3670 if (!default_profile_id
)
3671 default_profile_id
= profile_id
; /* Last profile */
3673 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3674 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3675 default_profile_id
);
3678 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3680 CFRelease(dict_key
);
3682 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3685 * Get the device ID hash and pathelogical name dictionary.
3688 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3691 device_id
= _ppdHashName(p
->name
);
3692 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3693 &kCFTypeDictionaryKeyCallBacks
,
3694 &kCFTypeDictionaryValueCallBacks
);
3695 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3696 p
->name
, kCFStringEncodingUTF8
);
3698 if (device_name
&& printer_name
)
3700 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3703 * Register the device with ColorSync...
3706 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3707 CFTypeRef deviceDictKeys
[] =
3709 kColorSyncDeviceDescriptions
,
3710 kColorSyncFactoryProfiles
,
3711 kColorSyncDeviceUserScope
,
3712 kColorSyncDeviceHostScope
3714 CFTypeRef deviceDictVals
[] =
3715 { /* Device values */
3718 kCFPreferencesAnyUser
,
3719 kCFPreferencesCurrentHost
3721 CFDictionaryRef deviceDict
; /* Device dictionary */
3722 CFUUIDRef deviceUUID
; /* Device UUID */
3724 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3725 (const void **)deviceDictKeys
,
3726 (const void **)deviceDictVals
,
3727 sizeof(deviceDictKeys
) /
3728 sizeof(deviceDictKeys
[0]),
3729 &kCFTypeDictionaryKeyCallBacks
,
3730 &kCFTypeDictionaryValueCallBacks
);
3731 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3733 if (!deviceDict
|| !deviceUUID
||
3734 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3739 CFRelease(deviceUUID
);
3742 CFRelease(deviceDict
);
3745 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3746 device_name
, &scope
);
3749 * Register the profiles...
3753 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3754 default_profile_id
, profiles
);
3755 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3765 cupsdLogMessage(CUPSD_LOG_ERROR
,
3766 "Unable to register ICC color profiles for \"%s\": %d",
3767 p
->name
, (int)error
);
3770 CFRelease(printer_name
);
3773 CFRelease(device_name
);
3777 * Free any memory we used...
3780 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3781 CFRelease(profiles
);
3784 if (num_profiles
> 0)
3786 for (profile
= profiles
->profiles
;
3788 profile
++, num_profiles
--)
3789 CFRelease(profile
->profileName
);
3793 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3800 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3805 apple_unregister_profiles(
3806 cupsd_printer_t
*p
) /* I - Printer */
3809 * Make sure ColorSync is available...
3812 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3813 if (ColorSyncUnregisterDevice
!= NULL
)
3816 * Because we may have registered the printer profiles using a prior device
3817 * ID-based UUID, remove both the old style UUID and current UUID for the
3821 CFUUIDRef deviceUUID
; /* Device UUID */
3823 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3826 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3827 CFRelease(deviceUUID
);
3832 if (CMUnregisterColorDevice
!= NULL
)
3833 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3834 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3836 #endif /* __APPLE__ */
3840 * 'apply_printer_defaults()' - Apply printer default options to a job.
3844 apply_printer_defaults(
3845 cupsd_printer_t
*printer
, /* I - Printer */
3846 cupsd_job_t
*job
) /* I - Job */
3848 int i
, /* Looping var */
3849 num_options
; /* Number of default options */
3850 cups_option_t
*options
, /* Default options */
3851 *option
; /* Current option */
3855 * Collect all of the default options and add the missing ones to the
3859 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3860 option
= printer
->options
;
3863 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3865 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3870 * Encode these options as attributes in the job object...
3873 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3874 cupsFreeOptions(num_options
, options
);
3879 * 'authenticate_job()' - Set job authentication info.
3883 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3884 ipp_attribute_t
*uri
) /* I - Job URI */
3886 ipp_attribute_t
*attr
, /* job-id attribute */
3887 *auth_info
; /* auth-info attribute */
3888 int jobid
; /* Job ID */
3889 cupsd_job_t
*job
; /* Current job */
3890 char scheme
[HTTP_MAX_URI
],
3891 /* Method portion of URI */
3892 username
[HTTP_MAX_URI
],
3893 /* Username portion of URI */
3895 /* Host portion of URI */
3896 resource
[HTTP_MAX_URI
];
3897 /* Resource portion of URI */
3898 int port
; /* Port portion of URI */
3901 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3902 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3905 * Start with "everything is OK" status...
3908 con
->response
->request
.status
.status_code
= IPP_OK
;
3911 * See if we have a job URI or a printer URI...
3914 if (!strcmp(uri
->name
, "printer-uri"))
3917 * Got a printer URI; see if we also have a job-id attribute...
3920 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3921 IPP_TAG_INTEGER
)) == NULL
)
3923 send_ipp_status(con
, IPP_BAD_REQUEST
,
3924 _("Got a printer-uri attribute but no job-id."));
3928 jobid
= attr
->values
[0].integer
;
3933 * Got a job URI; parse it to get the job ID...
3936 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3937 sizeof(scheme
), username
, sizeof(username
), host
,
3938 sizeof(host
), &port
, resource
, sizeof(resource
));
3940 if (strncmp(resource
, "/jobs/", 6))
3946 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3947 uri
->values
[0].string
.text
);
3951 jobid
= atoi(resource
+ 6);
3955 * See if the job exists...
3958 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3961 * Nope - return a "not found" error...
3964 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3969 * See if the job has been completed...
3972 if (job
->state_value
!= IPP_JOB_HELD
)
3975 * Return a "not-possible" error...
3978 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3979 _("Job #%d is not held for authentication."),
3985 * See if we have already authenticated...
3988 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3990 if (!con
->username
[0] && !auth_info
)
3992 cupsd_printer_t
*printer
; /* Job destination */
3995 * No auth data. If we need to authenticate via Kerberos, send a
3996 * HTTP auth challenge, otherwise just return an IPP error...
3999 printer
= cupsdFindDest(job
->dest
);
4001 if (printer
&& printer
->num_auth_info_required
> 0 &&
4002 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4003 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4005 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4006 _("No authentication information provided."));
4011 * See if the job is owned by the requesting user...
4014 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4016 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4017 cupsdFindDest(job
->dest
));
4022 * Save the authentication information for this job...
4025 save_auth_info(con
, job
, auth_info
);
4028 * Reset the job-hold-until value to "no-hold"...
4031 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4032 IPP_TAG_KEYWORD
)) == NULL
)
4033 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4037 attr
->value_tag
= IPP_TAG_KEYWORD
;
4038 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4042 * Release the job and return...
4045 cupsdReleaseJob(job
);
4047 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4049 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4056 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4060 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4061 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4063 int i
; /* Looping var */
4064 http_status_t status
; /* Policy status */
4065 cups_ptype_t dtype
; /* Destination type */
4066 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4067 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4068 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4069 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4070 int port
; /* Port portion of URI */
4071 ipp_attribute_t
*attr
; /* Attribute in request */
4072 const char *username
= NULL
; /* Username */
4073 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4075 cupsd_printer_t
*printer
; /* Printer */
4076 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4077 cupsd_job_t
*job
; /* Job */
4080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4081 con
->http
.fd
, uri
->values
[0].string
.text
);
4084 * Get the jobs to cancel/purge...
4087 switch (con
->request
->request
.op
.operation_id
)
4089 case IPP_PURGE_JOBS
:
4091 * Get the username (if any) for the jobs we want to cancel (only if
4092 * "my-jobs" is specified...
4095 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4096 IPP_TAG_BOOLEAN
)) != NULL
&&
4097 attr
->values
[0].boolean
)
4099 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4100 IPP_TAG_NAME
)) != NULL
)
4101 username
= attr
->values
[0].string
.text
;
4104 send_ipp_status(con
, IPP_BAD_REQUEST
,
4105 _("Missing requesting-user-name attribute."));
4111 * Look for the "purge-jobs" attribute...
4114 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4115 IPP_TAG_BOOLEAN
)) != NULL
)
4116 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4118 purge
= CUPSD_JOB_PURGE
;
4121 case IPP_CANCEL_MY_JOBS
:
4122 if (con
->username
[0])
4123 username
= con
->username
;
4124 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4125 IPP_TAG_NAME
)) != NULL
)
4126 username
= attr
->values
[0].string
.text
;
4129 send_ipp_status(con
, IPP_BAD_REQUEST
,
4130 _("Missing requesting-user-name attribute."));
4138 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4141 * See if we have a printer URI...
4144 if (strcmp(uri
->name
, "printer-uri"))
4146 send_ipp_status(con
, IPP_BAD_REQUEST
,
4147 _("The printer-uri attribute is required."));
4152 * And if the destination is valid...
4155 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4161 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4162 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4163 hostname
, sizeof(hostname
), &port
,
4164 resource
, sizeof(resource
));
4166 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4167 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4169 send_ipp_status(con
, IPP_NOT_FOUND
,
4170 _("The printer or class does not exist."));
4178 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4180 send_http_error(con
, status
, NULL
);
4186 for (i
= 0; i
< job_ids
->num_values
; i
++)
4188 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4192 if (i
< job_ids
->num_values
)
4194 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4195 job_ids
->values
[i
].integer
);
4199 for (i
= 0; i
< job_ids
->num_values
; i
++)
4201 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4203 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4204 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4205 "Job canceled by user.");
4208 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4209 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4215 * Cancel all jobs on all printers...
4218 cupsdCancelJobs(NULL
, username
, purge
);
4220 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4221 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4231 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4234 send_http_error(con
, status
, printer
);
4240 for (i
= 0; i
< job_ids
->num_values
; i
++)
4242 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4243 _cups_strcasecmp(job
->dest
, printer
->name
))
4247 if (i
< job_ids
->num_values
)
4249 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4250 job_ids
->values
[i
].integer
);
4254 for (i
= 0; i
< job_ids
->num_values
; i
++)
4256 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4258 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4259 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4260 "Job canceled by user.");
4263 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4264 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4270 * Cancel all of the jobs on the named printer...
4273 cupsdCancelJobs(printer
->name
, username
, purge
);
4275 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4277 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4282 con
->response
->request
.status
.status_code
= IPP_OK
;
4287 * 'cancel_job()' - Cancel a print job.
4291 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4292 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4294 ipp_attribute_t
*attr
; /* Current attribute */
4295 int jobid
; /* Job ID */
4296 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4297 username
[HTTP_MAX_URI
], /* Username portion of URI */
4298 host
[HTTP_MAX_URI
], /* Host portion of URI */
4299 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4300 int port
; /* Port portion of URI */
4301 cupsd_job_t
*job
; /* Job information */
4302 cups_ptype_t dtype
; /* Destination type (printer/class) */
4303 cupsd_printer_t
*printer
; /* Printer data */
4304 cupsd_jobaction_t purge
; /* Purge the job? */
4307 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4308 con
->http
.fd
, uri
->values
[0].string
.text
);
4311 * See if we have a job URI or a printer URI...
4314 if (!strcmp(uri
->name
, "printer-uri"))
4317 * Got a printer URI; see if we also have a job-id attribute...
4320 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4321 IPP_TAG_INTEGER
)) == NULL
)
4323 send_ipp_status(con
, IPP_BAD_REQUEST
,
4324 _("Got a printer-uri attribute but no job-id."));
4328 if ((jobid
= attr
->values
[0].integer
) == 0)
4331 * Find the current job on the specified printer...
4334 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4340 send_ipp_status(con
, IPP_NOT_FOUND
,
4341 _("The printer or class does not exist."));
4346 * See if there are any pending jobs...
4349 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4351 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4352 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4353 !_cups_strcasecmp(job
->dest
, printer
->name
))
4361 * No, try stopped jobs...
4364 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4366 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4367 if (job
->state_value
== IPP_JOB_STOPPED
&&
4368 !_cups_strcasecmp(job
->dest
, printer
->name
))
4375 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4385 * Got a job URI; parse it to get the job ID...
4388 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4389 sizeof(scheme
), username
, sizeof(username
), host
,
4390 sizeof(host
), &port
, resource
, sizeof(resource
));
4392 if (strncmp(resource
, "/jobs/", 6))
4398 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4399 uri
->values
[0].string
.text
);
4403 jobid
= atoi(resource
+ 6);
4407 * Look for the "purge-job" attribute...
4410 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4411 IPP_TAG_BOOLEAN
)) != NULL
)
4412 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4414 purge
= CUPSD_JOB_DEFAULT
;
4417 * See if the job exists...
4420 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4423 * Nope - return a "not found" error...
4426 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4431 * See if the job is owned by the requesting user...
4434 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4436 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4437 cupsdFindDest(job
->dest
));
4442 * See if the job is already completed, canceled, or aborted; if so,
4443 * we can't cancel...
4446 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4448 switch (job
->state_value
)
4450 case IPP_JOB_CANCELED
:
4451 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4452 _("Job #%d is already canceled - can\'t cancel."),
4456 case IPP_JOB_ABORTED
:
4457 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4458 _("Job #%d is already aborted - can\'t cancel."),
4463 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4464 _("Job #%d is already completed - can\'t cancel."),
4473 * Cancel the job and return...
4476 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4477 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4478 "Job canceled by \"%s\"",
4482 if (purge
== CUPSD_JOB_PURGE
)
4483 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4486 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4489 con
->response
->request
.status
.status_code
= IPP_OK
;
4494 * 'cancel_subscription()' - Cancel a subscription.
4498 cancel_subscription(
4499 cupsd_client_t
*con
, /* I - Client connection */
4500 int sub_id
) /* I - Subscription ID */
4502 http_status_t status
; /* Policy status */
4503 cupsd_subscription_t
*sub
; /* Subscription */
4506 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4507 "cancel_subscription(con=%p[%d], sub_id=%d)",
4508 con
, con
->http
.fd
, sub_id
);
4511 * Is the subscription ID valid?
4514 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4517 * Bad subscription ID...
4520 send_ipp_status(con
, IPP_NOT_FOUND
,
4521 _("Subscription #%d does not exist."), sub_id
);
4529 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4531 con
, sub
->owner
)) != HTTP_OK
)
4533 send_http_error(con
, status
, sub
->dest
);
4538 * Cancel the subscription...
4541 cupsdDeleteSubscription(sub
, 1);
4543 con
->response
->request
.status
.status_code
= IPP_OK
;
4548 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4551 static int /* O - 1 if OK, 0 if not */
4552 check_rss_recipient(
4553 const char *recipient
) /* I - Recipient URI */
4555 cupsd_subscription_t
*sub
; /* Current subscription */
4558 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4560 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4564 * Compare the URIs up to the first ?...
4567 const char *r1
, *r2
;
4569 for (r1
= recipient
, r2
= sub
->recipient
;
4570 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4582 * 'check_quotas()' - Check quotas for a printer and user.
4585 static int /* O - 1 if OK, 0 if forbidden,
4586 -1 if limit reached */
4587 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4588 cupsd_printer_t
*p
) /* I - Printer or class */
4590 char username
[33], /* Username */
4591 *name
; /* Current user name */
4592 cupsd_quota_t
*q
; /* Quota data */
4593 #ifdef HAVE_MBR_UID_TO_UUID
4595 * Use Apple membership APIs which require that all names represent
4596 * valid user account or group records accessible by the server.
4599 uuid_t usr_uuid
; /* UUID for job requesting user */
4600 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4601 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4602 int mbr_err
; /* Error from membership function */
4603 int is_member
; /* Is this user a member? */
4606 * Use standard POSIX APIs for checking users and groups...
4609 struct passwd
*pw
; /* User password data */
4610 #endif /* HAVE_MBR_UID_TO_UUID */
4613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4614 con
, con
->http
.fd
, p
, p
->name
);
4617 * Figure out who is printing...
4620 strlcpy(username
, get_username(con
), sizeof(username
));
4622 if ((name
= strchr(username
, '@')) != NULL
)
4623 *name
= '\0'; /* Strip @REALM */
4626 * Check global active job limits for printers and users...
4629 if (MaxJobsPerPrinter
)
4632 * Check if there are too many pending jobs on this printer...
4635 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4637 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4646 * Check if there are too many pending jobs for this user...
4649 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4651 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4658 * Check against users...
4661 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4664 if (cupsArrayCount(p
->users
))
4666 #ifdef HAVE_MBR_UID_TO_UUID
4668 * Get UUID for job requesting user...
4671 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4677 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4678 "check_quotas: UUID lookup failed for user \"%s\"",
4680 cupsdLogMessage(CUPSD_LOG_INFO
,
4681 "Denying user \"%s\" access to printer \"%s\" "
4682 "(unknown user)...",
4688 * Get UID and GID of requesting user...
4691 pw
= getpwnam(username
);
4693 #endif /* HAVE_MBR_UID_TO_UUID */
4695 for (name
= (char *)cupsArrayFirst(p
->users
);
4697 name
= (char *)cupsArrayNext(p
->users
))
4701 * Check group membership...
4704 #ifdef HAVE_MBR_UID_TO_UUID
4707 if (uuid_parse(name
+ 2, grp_uuid
))
4708 uuid_clear(grp_uuid
);
4710 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4713 * Invalid ACL entries are ignored for matching; just record a
4714 * warning in the log...
4717 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4718 "check_quotas: UUID lookup failed for ACL entry "
4719 "\"%s\" (err=%d)", name
, mbr_err
);
4720 cupsdLogMessage(CUPSD_LOG_WARN
,
4721 "Access control entry \"%s\" not a valid group name; "
4722 "entry ignored", name
);
4725 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4729 * At this point, there should be no errors, but check anyways...
4732 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4733 "check_quotas: group \"%s\" membership check "
4734 "failed (err=%d)", name
+ 1, mbr_err
);
4739 * Stop if we found a match...
4746 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4748 #endif /* HAVE_MBR_UID_TO_UUID */
4750 #ifdef HAVE_MBR_UID_TO_UUID
4755 if (uuid_parse(name
+ 1, usr2_uuid
))
4756 uuid_clear(usr2_uuid
);
4758 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4761 * Invalid ACL entries are ignored for matching; just record a
4762 * warning in the log...
4765 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4766 "check_quotas: UUID lookup failed for ACL entry "
4767 "\"%s\" (err=%d)", name
, mbr_err
);
4768 cupsdLogMessage(CUPSD_LOG_WARN
,
4769 "Access control entry \"%s\" not a valid user name; "
4770 "entry ignored", name
);
4773 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4777 else if (!_cups_strcasecmp(username
, name
))
4779 #endif /* HAVE_MBR_UID_TO_UUID */
4781 if ((name
!= NULL
) == p
->deny_users
)
4783 cupsdLogMessage(CUPSD_LOG_INFO
,
4784 "Denying user \"%s\" access to printer \"%s\"...",
4794 if (p
->k_limit
|| p
->page_limit
)
4796 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4798 cupsdLogMessage(CUPSD_LOG_ERROR
,
4799 "Unable to allocate quota data for user \"%s\"",
4804 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4805 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4807 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4814 * If we have gotten this far, we're done!
4822 * 'close_job()' - Close a multi-file job.
4826 close_job(cupsd_client_t
*con
, /* I - Client connection */
4827 ipp_attribute_t
*uri
) /* I - Printer URI */
4829 cupsd_job_t
*job
; /* Job */
4830 ipp_attribute_t
*attr
; /* Attribute */
4831 char job_uri
[HTTP_MAX_URI
],
4833 username
[256]; /* User name */
4836 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4837 con
->http
.fd
, uri
->values
[0].string
.text
);
4840 * See if we have a job URI or a printer URI...
4843 if (strcmp(uri
->name
, "printer-uri"))
4846 * job-uri is not supported by Close-Job!
4849 send_ipp_status(con
, IPP_BAD_REQUEST
,
4850 _("Close-Job doesn't support the job-uri attribute."));
4855 * Got a printer URI; see if we also have a job-id attribute...
4858 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4859 IPP_TAG_INTEGER
)) == NULL
)
4861 send_ipp_status(con
, IPP_BAD_REQUEST
,
4862 _("Got a printer-uri attribute but no job-id."));
4866 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4869 * Nope - return a "not found" error...
4872 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4873 attr
->values
[0].integer
);
4878 * See if the job is owned by the requesting user...
4881 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4883 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4884 cupsdFindDest(job
->dest
));
4889 * Add any ending sheet...
4892 if (cupsdTimeoutJob(job
))
4895 if (job
->state_value
== IPP_JOB_STOPPED
)
4897 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4898 job
->state_value
= IPP_JOB_PENDING
;
4900 else if (job
->state_value
== IPP_JOB_HELD
)
4902 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4903 IPP_TAG_KEYWORD
)) == NULL
)
4904 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4906 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4908 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4909 job
->state_value
= IPP_JOB_PENDING
;
4914 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4917 * Fill in the response info...
4920 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4921 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
4922 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4925 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4927 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4930 add_job_state_reasons(con
, job
);
4932 con
->response
->request
.status
.status_code
= IPP_OK
;
4935 * Start the job if necessary...
4943 * 'copy_attrs()' - Copy attributes from one request to another.
4947 copy_attrs(ipp_t
*to
, /* I - Destination request */
4948 ipp_t
*from
, /* I - Source request */
4949 cups_array_t
*ra
, /* I - Requested attributes */
4950 ipp_tag_t group
, /* I - Group to copy */
4951 int quickcopy
, /* I - Do a quick copy? */
4952 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4954 ipp_attribute_t
*fromattr
; /* Source attribute */
4957 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4958 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4959 to
, from
, ra
, group
, quickcopy
);
4964 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4967 * Filter attributes as needed...
4970 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4971 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4974 if (!strcmp(fromattr
->name
, "job-printer-uri"))
4978 (cupsArrayFind(exclude
, fromattr
->name
) ||
4979 cupsArrayFind(exclude
, "all")))
4982 * We need to exclude this attribute for security reasons; we require the
4983 * job-id attribute regardless of the security settings for IPP
4986 * The job-printer-uri attribute is handled by copy_job_attrs().
4988 * Subscription attribute security is handled by copy_subscription_attrs().
4991 if (strcmp(fromattr
->name
, "job-id"))
4995 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4998 * Don't send collection attributes by default to IPP/1.x clients
4999 * since many do not support collections. Also don't send
5000 * media-col-database unless specifically requested by the client.
5003 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5005 (to
->request
.status
.version
[0] == 1 ||
5006 !strcmp(fromattr
->name
, "media-col-database")))
5009 ippCopyAttribute(to
, fromattr
, quickcopy
);
5016 * 'copy_banner()' - Copy a banner file to the requests directory for the
5020 static int /* O - Size of banner file in kbytes */
5021 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5022 cupsd_job_t
*job
, /* I - Job information */
5023 const char *name
) /* I - Name of banner */
5025 int i
; /* Looping var */
5026 int kbytes
; /* Size of banner file in kbytes */
5027 char filename
[1024]; /* Job filename */
5028 cupsd_banner_t
*banner
; /* Pointer to banner */
5029 cups_file_t
*in
; /* Input file */
5030 cups_file_t
*out
; /* Output file */
5031 int ch
; /* Character from file */
5032 char attrname
[255], /* Name of attribute */
5033 *s
; /* Pointer into name */
5034 ipp_attribute_t
*attr
; /* Attribute */
5037 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5038 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5039 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5040 name
? name
: "(null)");
5043 * Find the banner; return if not found or "none"...
5046 if (!name
|| !strcmp(name
, "none") ||
5047 (banner
= cupsdFindBanner(name
)) == NULL
)
5051 * Open the banner and job files...
5054 if (add_file(con
, job
, banner
->filetype
, 0))
5057 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5059 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5061 cupsdLogMessage(CUPSD_LOG_ERROR
,
5062 "Unable to create banner job file %s - %s",
5063 filename
, strerror(errno
));
5068 fchmod(cupsFileNumber(out
), 0640);
5069 fchown(cupsFileNumber(out
), RunUser
, Group
);
5072 * Try the localized banner file under the subdirectory...
5075 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5077 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5080 * Convert ll-cc to ll_CC...
5084 attrname
[3] = toupper(attrname
[3] & 255);
5085 attrname
[4] = toupper(attrname
[4] & 255);
5088 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5091 if (access(filename
, 0) && strlen(attrname
) > 2)
5094 * Wasn't able to find "ll_CC" locale file; try the non-national
5095 * localization banner directory.
5100 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5104 if (access(filename
, 0))
5107 * Use the non-localized banner file.
5110 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5113 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5117 cupsdLogMessage(CUPSD_LOG_ERROR
,
5118 "Unable to open banner template file %s - %s",
5119 filename
, strerror(errno
));
5125 * Parse the file to the end...
5128 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5132 * Get an attribute name...
5135 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5136 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5138 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5148 * Ignore { followed by stuff that is not an attribute name...
5151 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5156 * See if it is defined...
5159 if (attrname
[0] == '?')
5164 if (!strcmp(s
, "printer-name"))
5166 cupsFilePuts(out
, job
->dest
);
5169 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5172 * See if we have a leading question mark...
5175 if (attrname
[0] != '?')
5178 * Nope, write to file as-is; probably a PostScript procedure...
5181 cupsFilePrintf(out
, "{%s}", attrname
);
5188 * Output value(s)...
5191 for (i
= 0; i
< attr
->num_values
; i
++)
5194 cupsFilePutChar(out
, ',');
5196 switch (attr
->value_tag
)
5198 case IPP_TAG_INTEGER
:
5200 if (!strncmp(s
, "time-at-", 8))
5202 struct timeval tv
; /* Time value */
5204 tv
.tv_sec
= attr
->values
[i
].integer
;
5207 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5210 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5213 case IPP_TAG_BOOLEAN
:
5214 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5217 case IPP_TAG_NOVALUE
:
5218 cupsFilePuts(out
, "novalue");
5221 case IPP_TAG_RANGE
:
5222 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5223 attr
->values
[i
].range
.upper
);
5226 case IPP_TAG_RESOLUTION
:
5227 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5228 attr
->values
[i
].resolution
.yres
,
5229 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5234 case IPP_TAG_STRING
:
5237 case IPP_TAG_KEYWORD
:
5238 case IPP_TAG_CHARSET
:
5239 case IPP_TAG_LANGUAGE
:
5240 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
5243 * Need to quote strings for PS banners...
5248 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5250 if (*p
== '(' || *p
== ')' || *p
== '\\')
5252 cupsFilePutChar(out
, '\\');
5253 cupsFilePutChar(out
, *p
);
5255 else if (*p
< 32 || *p
> 126)
5256 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5258 cupsFilePutChar(out
, *p
);
5262 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5266 break; /* anti-compiler-warning-code */
5270 else if (ch
== '\\') /* Quoted char */
5272 ch
= cupsFileGetChar(in
);
5274 if (ch
!= '{') /* Only do special handling for \{ */
5275 cupsFilePutChar(out
, '\\');
5277 cupsFilePutChar(out
, ch
);
5280 cupsFilePutChar(out
, ch
);
5284 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5286 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5287 IPP_TAG_INTEGER
)) != NULL
)
5288 attr
->values
[0].integer
+= kbytes
;
5297 * 'copy_file()' - Copy a PPD file or interface script...
5300 static int /* O - 0 = success, -1 = error */
5301 copy_file(const char *from
, /* I - Source file */
5302 const char *to
) /* I - Destination file */
5304 cups_file_t
*src
, /* Source file */
5305 *dst
; /* Destination file */
5306 int bytes
; /* Bytes to read/write */
5307 char buffer
[2048]; /* Copy buffer */
5310 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5313 * Open the source and destination file for a copy...
5316 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5319 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5326 * Copy the source file to the destination...
5329 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5330 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5338 * Close both files and return...
5343 return (cupsFileClose(dst
));
5348 * 'copy_model()' - Copy a PPD model file, substituting default values
5352 static int /* O - 0 = success, -1 = error */
5353 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5354 const char *from
, /* I - Source file */
5355 const char *to
) /* I - Destination file */
5357 fd_set input
; /* select() input set */
5358 struct timeval timeout
; /* select() timeout */
5359 int maxfd
; /* Max file descriptor for select() */
5360 char tempfile
[1024]; /* Temporary PPD file */
5361 int tempfd
; /* Temporary PPD file descriptor */
5362 int temppid
; /* Process ID of cups-driverd */
5363 int temppipe
[2]; /* Temporary pipes */
5364 char *argv
[4], /* Command-line arguments */
5365 *envp
[MAX_ENV
]; /* Environment */
5366 cups_file_t
*src
, /* Source file */
5367 *dst
; /* Destination file */
5368 ppd_file_t
*ppd
; /* PPD file */
5369 int bytes
, /* Bytes from pipe */
5370 total
; /* Total bytes from pipe */
5371 char buffer
[2048]; /* Copy buffer */
5372 int i
; /* Looping var */
5373 char option
[PPD_MAX_NAME
], /* Option name */
5374 choice
[PPD_MAX_NAME
]; /* Choice name */
5375 ppd_size_t
*size
; /* Default size */
5376 int num_defaults
; /* Number of default options */
5377 cups_option_t
*defaults
; /* Default options */
5378 char cups_protocol
[PPD_MAX_LINE
];
5379 /* cupsProtocol attribute */
5382 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5383 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5387 * Run cups-driverd to get the PPD file...
5390 argv
[0] = "cups-driverd";
5392 argv
[2] = (char *)from
;
5395 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5397 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5398 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5399 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5400 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
5403 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5404 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5406 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5407 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5418 * Wait up to 30 seconds for the PPD file to be copied...
5423 if (temppipe
[0] > CGIPipes
[0])
5424 maxfd
= temppipe
[0] + 1;
5426 maxfd
= CGIPipes
[0] + 1;
5431 * See if we have data ready...
5435 FD_SET(temppipe
[0], &input
);
5436 FD_SET(CGIPipes
[0], &input
);
5438 timeout
.tv_sec
= 30;
5439 timeout
.tv_usec
= 0;
5441 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5451 * We have timed out...
5457 if (FD_ISSET(temppipe
[0], &input
))
5460 * Read the PPD file from the pipe, and write it to the PPD file.
5463 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5465 if (write(tempfd
, buffer
, bytes
) < bytes
)
5474 if (FD_ISSET(CGIPipes
[0], &input
))
5484 * No data from cups-deviced...
5487 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5493 * Open the source file for a copy...
5496 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5503 * Read the source file and see what page sizes are supported...
5506 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
5514 * Open the destination (if possible) and set the default options...
5519 cups_protocol
[0] = '\0';
5521 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5524 * Read all of the default lines from the old PPD...
5527 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5528 if (!strncmp(buffer
, "*Default", 8))
5531 * Add the default option...
5534 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5535 choice
, sizeof(choice
)))
5537 ppd_option_t
*ppdo
; /* PPD option */
5541 * Only add the default if the default hasn't already been
5542 * set and the choice exists in the new PPD...
5545 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5546 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5547 ppdFindChoice(ppdo
, choice
))
5548 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5552 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5553 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5557 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5560 * Add the default media sizes...
5563 num_defaults
= cupsAddOption("PageSize", size
->name
,
5564 num_defaults
, &defaults
);
5565 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5566 num_defaults
, &defaults
);
5567 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5568 num_defaults
, &defaults
);
5569 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5570 num_defaults
, &defaults
);
5576 * Open the destination file for a copy...
5579 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5581 cupsFreeOptions(num_defaults
, defaults
);
5588 * Copy the source file to the destination...
5591 cupsFileRewind(src
);
5593 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5595 if (!strncmp(buffer
, "*Default", 8))
5598 * Check for an previous default option choice...
5601 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5602 choice
, sizeof(choice
)))
5604 const char *val
; /* Default option value */
5607 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5610 * Substitute the previous choice...
5613 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5618 cupsFilePrintf(dst
, "%s\n", buffer
);
5621 if (cups_protocol
[0])
5622 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5624 cupsFreeOptions(num_defaults
, defaults
);
5627 * Close both files and return...
5634 return (cupsFileClose(dst
));
5639 * 'copy_job_attrs()' - Copy job attributes.
5643 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5644 cupsd_job_t
*job
, /* I - Job */
5645 cups_array_t
*ra
, /* I - Requested attributes array */
5646 cups_array_t
*exclude
) /* I - Private attributes array */
5648 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5652 * Send the requested attributes for each job...
5655 if (!cupsArrayFind(exclude
, "all"))
5657 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5658 (!ra
|| cupsArrayFind(ra
, "document-count")))
5659 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5660 "document-count", job
->num_files
);
5662 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5663 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5664 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5665 "job-media-progress", job
->progress
);
5667 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5668 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5670 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
5671 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
5673 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5674 "job-more-info", NULL
, job_uri
);
5677 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5678 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5679 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5680 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5681 job
->num_files
> 0);
5683 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5684 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5685 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5686 "job-printer-up-time", time(NULL
));
5689 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
5691 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5692 con
->servername
, con
->serverport
,
5693 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
5696 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5697 "job-printer-uri", NULL
, job_uri
);
5700 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5701 add_job_state_reasons(con
, job
);
5703 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5705 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5706 con
->servername
, con
->serverport
, "/jobs/%d",
5708 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5709 "job-uri", NULL
, job_uri
);
5712 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
5717 * 'copy_printer_attrs()' - Copy printer attributes.
5722 cupsd_client_t
*con
, /* I - Client connection */
5723 cupsd_printer_t
*printer
, /* I - Printer */
5724 cups_array_t
*ra
) /* I - Requested attributes array */
5726 char printer_uri
[HTTP_MAX_URI
];
5728 char printer_icons
[HTTP_MAX_URI
];
5730 time_t curtime
; /* Current time */
5731 int i
; /* Looping var */
5735 * Copy the printer attributes to the response using requested-attributes
5736 * and document-format attributes that may be provided by the client.
5739 curtime
= time(NULL
);
5741 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5742 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5743 "marker-change-time", printer
->marker_time
);
5745 if (printer
->num_printers
> 0 &&
5746 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5748 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5749 cupsd_printer_t
*p2
; /* Printer in class */
5750 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5753 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5754 IPP_TAG_URI
, "member-uris",
5755 printer
->num_printers
, NULL
,
5758 for (i
= 0; i
< printer
->num_printers
; i
++)
5760 p2
= printer
->printers
[i
];
5762 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5763 IPP_TAG_URI
)) != NULL
)
5764 member_uris
->values
[i
].string
.text
=
5765 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5768 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5769 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5771 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5772 "/classes/%s" : "/printers/%s", p2
->name
);
5773 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5779 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5780 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5781 "printer-alert", NULL
, printer
->alert
);
5783 if (printer
->alert_description
&&
5784 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5785 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5786 "printer-alert-description", NULL
,
5787 printer
->alert_description
);
5789 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5790 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5791 ippTimeToDate(curtime
));
5794 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5796 if (printer
->reg_name
)
5797 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5798 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5800 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5801 "printer-dns-sd-name", 0);
5803 #endif /* HAVE_DNSSD */
5805 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5806 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5807 "printer-error-policy", NULL
, printer
->error_policy
);
5809 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5811 static const char * const errors
[] =/* printer-error-policy-supported values */
5814 "retry-current-job",
5819 if (printer
->type
& CUPS_PRINTER_CLASS
)
5820 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5821 "printer-error-policy-supported", NULL
, "retry-current-job");
5823 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5824 "printer-error-policy-supported",
5825 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5828 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
5830 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
5831 "http", NULL
, con
->servername
, con
->serverport
,
5832 "/icons/%s.png", printer
->name
);
5833 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5834 NULL
, printer_icons
);
5835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5838 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5839 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5840 printer
->accepting
);
5842 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5843 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5846 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
5848 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5849 "http", NULL
, con
->servername
, con
->serverport
,
5850 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5851 "/classes/%s" : "/printers/%s", printer
->name
);
5852 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5853 "printer-more-info", NULL
, printer_uri
);
5856 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5857 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5858 "printer-op-policy", NULL
, printer
->op_policy
);
5860 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5861 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5864 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5865 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5866 "printer-state-change-time", printer
->state_time
);
5868 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5869 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5870 "printer-state-message", NULL
, printer
->state_message
);
5872 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5873 add_printer_state_reasons(con
, printer
);
5875 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5877 int type
; /* printer-type value */
5880 * Add the CUPS-specific printer-type attribute...
5883 type
= printer
->type
;
5885 if (printer
== DefaultPrinter
)
5886 type
|= CUPS_PRINTER_DEFAULT
;
5888 if (!printer
->accepting
)
5889 type
|= CUPS_PRINTER_REJECTING
;
5891 if (!printer
->shared
)
5892 type
|= CUPS_PRINTER_NOT_SHARED
;
5894 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5898 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5899 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5900 "printer-up-time", curtime
);
5902 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5904 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5905 "ipp", NULL
, con
->servername
, con
->serverport
,
5906 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5907 "/classes/%s" : "/printers/%s", printer
->name
);
5908 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5909 "printer-uri-supported", NULL
, printer_uri
);
5910 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5914 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5915 add_queued_job_count(con
, printer
);
5917 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5918 if (printer
->ppd_attrs
)
5919 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5920 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5925 * 'copy_subscription_attrs()' - Copy subscription attributes.
5929 copy_subscription_attrs(
5930 cupsd_client_t
*con
, /* I - Client connection */
5931 cupsd_subscription_t
*sub
, /* I - Subscription */
5932 cups_array_t
*ra
, /* I - Requested attributes array */
5933 cups_array_t
*exclude
) /* I - Private attributes array */
5935 ipp_attribute_t
*attr
; /* Current attribute */
5936 char printer_uri
[HTTP_MAX_URI
];
5938 int count
; /* Number of events */
5939 unsigned mask
; /* Current event mask */
5940 const char *name
; /* Current event name */
5943 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5944 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5945 con
, sub
, ra
, exclude
);
5948 * Copy the subscription attributes to the response using the
5949 * requested-attributes attribute that may be provided by the client.
5952 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5954 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5955 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5957 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5959 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5962 * Simple event list...
5965 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5966 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5967 "notify-events", NULL
, name
);
5972 * Complex event list...
5975 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5976 if (sub
->mask
& mask
)
5979 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5980 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5981 "notify-events", count
, NULL
, NULL
);
5983 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5984 if (sub
->mask
& mask
)
5986 attr
->values
[count
].string
.text
=
5987 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5994 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5995 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5996 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5997 "notify-lease-duration", sub
->lease
);
5999 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6000 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6001 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6002 "notify-recipient-uri", NULL
, sub
->recipient
);
6003 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6004 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6005 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6006 "notify-pull-method", NULL
, "ippget");
6008 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6009 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6010 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6011 "notify-subscriber-user-name", NULL
, sub
->owner
);
6013 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6014 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6015 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6016 "notify-time-interval", sub
->interval
);
6018 if (sub
->user_data_len
> 0 &&
6019 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6020 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6021 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6022 sub
->user_data
, sub
->user_data_len
);
6025 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6026 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6027 "notify-job-id", sub
->job
->id
);
6029 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6031 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6032 "ipp", NULL
, con
->servername
, con
->serverport
,
6033 "/printers/%s", sub
->dest
->name
);
6034 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6035 "notify-printer-uri", NULL
, printer_uri
);
6038 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6039 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6040 "notify-subscription-id", sub
->id
);
6045 * 'create_job()' - Print a file to a printer or class.
6049 create_job(cupsd_client_t
*con
, /* I - Client connection */
6050 ipp_attribute_t
*uri
) /* I - Printer URI */
6052 cupsd_printer_t
*printer
; /* Printer */
6053 cupsd_job_t
*job
; /* New job */
6056 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6057 con
->http
.fd
, uri
->values
[0].string
.text
);
6060 * Is the destination valid?
6063 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6069 send_ipp_status(con
, IPP_NOT_FOUND
,
6070 _("The printer or class does not exist."));
6075 * Create the job object...
6078 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6081 job
->pending_timeout
= 1;
6084 * Save and log the job...
6087 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6088 job
->dest
, job
->username
);
6093 * 'create_requested_array()' - Create an array for the requested-attributes.
6096 static cups_array_t
* /* O - Array of attributes or NULL */
6097 create_requested_array(ipp_t
*request
) /* I - IPP request */
6099 int i
; /* Looping var */
6100 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6101 cups_array_t
*ra
; /* Requested attributes array */
6102 char *value
; /* Current value */
6106 * Get the requested-attributes attribute, and return NULL if we don't
6110 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6111 IPP_TAG_KEYWORD
)) == NULL
)
6115 * If the attribute contains a single "all" keyword, return NULL...
6118 if (requested
->num_values
== 1 &&
6119 !strcmp(requested
->values
[0].string
.text
, "all"))
6123 * Create an array using "strcmp" as the comparison function...
6126 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6128 for (i
= 0; i
< requested
->num_values
; i
++)
6130 value
= requested
->values
[i
].string
.text
;
6132 if (!strcmp(value
, "job-template"))
6134 /* Only includes the set of Job Template attributes supported by CUPS */
6135 cupsArrayAdd(ra
, "copies");
6136 cupsArrayAdd(ra
, "copies-default");
6137 cupsArrayAdd(ra
, "copies-supported");
6138 cupsArrayAdd(ra
, "finishings");
6139 cupsArrayAdd(ra
, "finishings-default");
6140 cupsArrayAdd(ra
, "finishings-supported");
6141 cupsArrayAdd(ra
, "job-hold-until");
6142 cupsArrayAdd(ra
, "job-hold-until-default");
6143 cupsArrayAdd(ra
, "job-hold-until-supported");
6144 cupsArrayAdd(ra
, "job-priority");
6145 cupsArrayAdd(ra
, "job-priority-default");
6146 cupsArrayAdd(ra
, "job-priority-supported");
6147 cupsArrayAdd(ra
, "job-sheets");
6148 cupsArrayAdd(ra
, "job-sheets-default");
6149 cupsArrayAdd(ra
, "job-sheets-supported");
6150 cupsArrayAdd(ra
, "media");
6151 cupsArrayAdd(ra
, "media-col");
6152 cupsArrayAdd(ra
, "media-col-default");
6153 cupsArrayAdd(ra
, "media-default");
6154 cupsArrayAdd(ra
, "media-supported");
6155 cupsArrayAdd(ra
, "multiple-document-handling");
6156 cupsArrayAdd(ra
, "multiple-document-handling-default");
6157 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6158 cupsArrayAdd(ra
, "number-up");
6159 cupsArrayAdd(ra
, "number-up-default");
6160 cupsArrayAdd(ra
, "number-up-layout");
6161 cupsArrayAdd(ra
, "number-up-layout-default");
6162 cupsArrayAdd(ra
, "number-up-layout-supported");
6163 cupsArrayAdd(ra
, "number-up-supported");
6164 cupsArrayAdd(ra
, "orientation-requested");
6165 cupsArrayAdd(ra
, "orientation-requested-default");
6166 cupsArrayAdd(ra
, "orientation-requested-supported");
6167 cupsArrayAdd(ra
, "output-bin");
6168 cupsArrayAdd(ra
, "output-bin-default");
6169 cupsArrayAdd(ra
, "output-bin-supported");
6170 cupsArrayAdd(ra
, "page-delivery");
6171 cupsArrayAdd(ra
, "page-delivery-default");
6172 cupsArrayAdd(ra
, "page-delivery-supported");
6173 cupsArrayAdd(ra
, "page-order-received");
6174 cupsArrayAdd(ra
, "page-order-received-default");
6175 cupsArrayAdd(ra
, "page-order-received-supported");
6176 cupsArrayAdd(ra
, "page-ranges");
6177 cupsArrayAdd(ra
, "page-ranges-supported");
6178 cupsArrayAdd(ra
, "presentation-direction-number-up");
6179 cupsArrayAdd(ra
, "presentation-direction-number-up-default");
6180 cupsArrayAdd(ra
, "presentation-direction-number-up-supported");
6181 cupsArrayAdd(ra
, "print-color-mode");
6182 cupsArrayAdd(ra
, "print-color-mode-default");
6183 cupsArrayAdd(ra
, "print-color-mode-supported");
6184 cupsArrayAdd(ra
, "print-content-optimize");
6185 cupsArrayAdd(ra
, "print-content-optimize-default");
6186 cupsArrayAdd(ra
, "print-content-optimize-supported");
6187 cupsArrayAdd(ra
, "print-quality");
6188 cupsArrayAdd(ra
, "print-quality-default");
6189 cupsArrayAdd(ra
, "print-quality-supported");
6190 cupsArrayAdd(ra
, "printer-resolution");
6191 cupsArrayAdd(ra
, "printer-resolution-default");
6192 cupsArrayAdd(ra
, "printer-resolution-supported");
6193 cupsArrayAdd(ra
, "sheet-collate");
6194 cupsArrayAdd(ra
, "sheet-collate-default");
6195 cupsArrayAdd(ra
, "sheet-collate-supported");
6196 cupsArrayAdd(ra
, "sides");
6197 cupsArrayAdd(ra
, "sides-default");
6198 cupsArrayAdd(ra
, "sides-supported");
6200 else if (!strcmp(value
, "job-description"))
6202 /* Only includes the set of Job Description attributes supported by CUPS */
6203 cupsArrayAdd(ra
, "date-time-at-completed");
6204 cupsArrayAdd(ra
, "date-time-at-creation");
6205 cupsArrayAdd(ra
, "date-time-at-processing");
6206 cupsArrayAdd(ra
, "job-detailed-status-message");
6207 cupsArrayAdd(ra
, "job-document-access-errors");
6208 cupsArrayAdd(ra
, "job-id");
6209 cupsArrayAdd(ra
, "job-impressions");
6210 cupsArrayAdd(ra
, "job-impressions-completed");
6211 cupsArrayAdd(ra
, "job-k-octets");
6212 cupsArrayAdd(ra
, "job-k-octets-processed");
6213 cupsArrayAdd(ra
, "job-mandatory-attributes");
6214 cupsArrayAdd(ra
, "job-media-progress");
6215 cupsArrayAdd(ra
, "job-media-sheets");
6216 cupsArrayAdd(ra
, "job-media-sheets-completed");
6217 cupsArrayAdd(ra
, "job-message-from-operator");
6218 cupsArrayAdd(ra
, "job-more-info");
6219 cupsArrayAdd(ra
, "job-name");
6220 cupsArrayAdd(ra
, "job-originating-user-name");
6221 cupsArrayAdd(ra
, "job-printer-up-time");
6222 cupsArrayAdd(ra
, "job-printer-uri");
6223 cupsArrayAdd(ra
, "job-state");
6224 cupsArrayAdd(ra
, "job-state-message");
6225 cupsArrayAdd(ra
, "job-state-reasons");
6226 cupsArrayAdd(ra
, "job-uri");
6227 cupsArrayAdd(ra
, "number-of-documents");
6228 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6229 cupsArrayAdd(ra
, "output-device-assigned");
6230 cupsArrayAdd(ra
, "time-at-completed");
6231 cupsArrayAdd(ra
, "time-at-creation");
6232 cupsArrayAdd(ra
, "time-at-processing");
6234 else if (!strcmp(value
, "printer-description"))
6236 /* Only includes the set of Printer Description attributes supported by CUPS */
6237 cupsArrayAdd(ra
, "charset-configured");
6238 cupsArrayAdd(ra
, "charset-supported");
6239 cupsArrayAdd(ra
, "color-supported");
6240 cupsArrayAdd(ra
, "compression-supported");
6241 cupsArrayAdd(ra
, "document-format-default");
6242 cupsArrayAdd(ra
, "document-format-supported");
6243 cupsArrayAdd(ra
, "generated-natural-language-supported");
6244 cupsArrayAdd(ra
, "ipp-versions-supported");
6245 cupsArrayAdd(ra
, "job-creation-attributes-supported");
6246 cupsArrayAdd(ra
, "job-ids-supported");
6247 cupsArrayAdd(ra
, "job-impressions-supported");
6248 cupsArrayAdd(ra
, "job-k-octets-supported");
6249 cupsArrayAdd(ra
, "job-media-sheets-supported");
6250 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6251 cupsArrayAdd(ra
, "jpeg-k-octets-supported");
6252 cupsArrayAdd(ra
, "jpeg-x-dimension-supported");
6253 cupsArrayAdd(ra
, "jpeg-y-dimension-supported");
6254 cupsArrayAdd(ra
, "media-bottom-margin-supported");
6255 cupsArrayAdd(ra
, "media-col-supported");
6256 cupsArrayAdd(ra
, "media-key-supported");
6257 cupsArrayAdd(ra
, "media-left-margin-supported");
6258 cupsArrayAdd(ra
, "media-right-margin-supported");
6259 cupsArrayAdd(ra
, "media-size-supported");
6260 cupsArrayAdd(ra
, "media-source-supported");
6261 cupsArrayAdd(ra
, "media-top-margin-supported");
6262 cupsArrayAdd(ra
, "media-type-supported");
6263 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6264 cupsArrayAdd(ra
, "multiple-operation-time-out");
6265 cupsArrayAdd(ra
, "natural-language-configured");
6266 cupsArrayAdd(ra
, "notify-max-events-supported");
6267 cupsArrayAdd(ra
, "notify-schemes-supported");
6268 cupsArrayAdd(ra
, "operations-supported");
6269 cupsArrayAdd(ra
, "pages-per-minute");
6270 cupsArrayAdd(ra
, "pages-per-minute-color");
6271 cupsArrayAdd(ra
, "pdf-k-octets-supported");
6272 cupsArrayAdd(ra
, "pdl-override-supported");
6273 cupsArrayAdd(ra
, "printer-alert");
6274 cupsArrayAdd(ra
, "printer-alert-description");
6275 cupsArrayAdd(ra
, "printer-commands");
6276 cupsArrayAdd(ra
, "printer-current-time");
6277 cupsArrayAdd(ra
, "printer-dns-sd-name");
6278 cupsArrayAdd(ra
, "printer-info");
6279 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6280 cupsArrayAdd(ra
, "printer-is-shared");
6281 cupsArrayAdd(ra
, "printer-location");
6282 cupsArrayAdd(ra
, "printer-make-and-model");
6283 cupsArrayAdd(ra
, "printer-message-from-operator");
6284 cupsArrayAdd(ra
, "printer-more-info");
6285 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6286 cupsArrayAdd(ra
, "printer-name");
6287 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6288 cupsArrayAdd(ra
, "printer-state");
6289 cupsArrayAdd(ra
, "printer-state-change-date-time");
6290 cupsArrayAdd(ra
, "printer-state-change-time");
6291 cupsArrayAdd(ra
, "printer-state-message");
6292 cupsArrayAdd(ra
, "printer-state-reasons");
6293 cupsArrayAdd(ra
, "printer-type");
6294 cupsArrayAdd(ra
, "printer-up-time");
6295 cupsArrayAdd(ra
, "printer-uri-supported");
6296 cupsArrayAdd(ra
, "queued-job-count");
6297 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6298 cupsArrayAdd(ra
, "uri-authentication-supported");
6299 cupsArrayAdd(ra
, "uri-security-supported");
6300 cupsArrayAdd(ra
, "which-jobs-supported");
6302 else if (!strcmp(value
, "printer-defaults"))
6304 char *name
; /* Option name */
6307 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6309 name
= (char *)cupsArrayNext(CommonDefaults
))
6310 cupsArrayAdd(ra
, name
);
6312 else if (!strcmp(value
, "subscription-description"))
6314 /* Only includes the set of Subscription Description attributes supported by CUPS */
6315 cupsArrayAdd(ra
, "notify-job-id");
6316 cupsArrayAdd(ra
, "notify-lease-expiration-time");
6317 cupsArrayAdd(ra
, "notify-printer-up-time");
6318 cupsArrayAdd(ra
, "notify-printer-uri");
6319 cupsArrayAdd(ra
, "notify-sequence-number");
6320 cupsArrayAdd(ra
, "notify-subscriber-user-name");
6321 cupsArrayAdd(ra
, "notify-subscription-id");
6323 else if (!strcmp(value
, "subscription-template"))
6325 /* Only includes the set of Subscription Template attributes supported by CUPS */
6326 cupsArrayAdd(ra
, "notify-attributes");
6327 cupsArrayAdd(ra
, "notify-attributes-supported");
6328 cupsArrayAdd(ra
, "notify-charset");
6329 cupsArrayAdd(ra
, "notify-events");
6330 cupsArrayAdd(ra
, "notify-events-default");
6331 cupsArrayAdd(ra
, "notify-events-supported");
6332 cupsArrayAdd(ra
, "notify-lease-duration");
6333 cupsArrayAdd(ra
, "notify-lease-duration-default");
6334 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6335 cupsArrayAdd(ra
, "notify-natural-language");
6336 cupsArrayAdd(ra
, "notify-pull-method");
6337 cupsArrayAdd(ra
, "notify-pull-method-supported");
6338 cupsArrayAdd(ra
, "notify-recipient-uri");
6339 cupsArrayAdd(ra
, "notify-time-interval");
6340 cupsArrayAdd(ra
, "notify-user-data");
6343 cupsArrayAdd(ra
, value
);
6351 * 'create_subscription()' - Create a notification subscription.
6355 create_subscription(
6356 cupsd_client_t
*con
, /* I - Client connection */
6357 ipp_attribute_t
*uri
) /* I - Printer URI */
6359 http_status_t status
; /* Policy status */
6360 int i
; /* Looping var */
6361 ipp_attribute_t
*attr
; /* Current attribute */
6362 cups_ptype_t dtype
; /* Destination type (printer/class) */
6363 char scheme
[HTTP_MAX_URI
],
6364 /* Scheme portion of URI */
6365 userpass
[HTTP_MAX_URI
],
6366 /* Username portion of URI */
6368 /* Host portion of URI */
6369 resource
[HTTP_MAX_URI
];
6370 /* Resource portion of URI */
6371 int port
; /* Port portion of URI */
6372 cupsd_printer_t
*printer
; /* Printer/class */
6373 cupsd_job_t
*job
; /* Job */
6374 int jobid
; /* Job ID */
6375 cupsd_subscription_t
*sub
; /* Subscription object */
6376 const char *username
, /* requesting-user-name or
6377 authenticated username */
6378 *recipient
, /* notify-recipient-uri */
6379 *pullmethod
; /* notify-pull-method */
6380 ipp_attribute_t
*user_data
; /* notify-user-data */
6381 int interval
, /* notify-time-interval */
6382 lease
; /* notify-lease-duration */
6383 unsigned mask
; /* notify-events */
6384 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6385 *notify_lease
; /* notify-lease-duration(-default) */
6389 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6391 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6393 attr
->value_tag
, attr
->name
);
6395 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6400 * Is the destination valid?
6403 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6404 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6405 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6407 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6408 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6409 sizeof(host
), &port
, resource
, sizeof(resource
));
6411 if (!strcmp(resource
, "/"))
6413 dtype
= (cups_ptype_t
)0;
6416 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6418 dtype
= (cups_ptype_t
)0;
6421 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6423 dtype
= CUPS_PRINTER_CLASS
;
6426 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6432 send_ipp_status(con
, IPP_NOT_FOUND
,
6433 _("The printer or class does not exist."));
6443 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6446 send_http_error(con
, status
, printer
);
6450 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6452 send_http_error(con
, status
, NULL
);
6457 * Get the user that is requesting the subscription...
6460 username
= get_username(con
);
6463 * Find the first subscription group attribute; return if we have
6467 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6468 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6473 send_ipp_status(con
, IPP_BAD_REQUEST
,
6474 _("No subscription attributes in request."));
6479 * Process the subscription attributes in the request...
6482 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6490 lease
= DefaultLeaseDuration
;
6492 mask
= CUPSD_EVENT_NONE
;
6496 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6498 notify_lease
= ippFindAttribute(printer
->attrs
,
6499 "notify-lease-duration-default",
6503 lease
= notify_lease
->values
[0].integer
;
6507 notify_events
= NULL
;
6508 notify_lease
= NULL
;
6511 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6513 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6514 attr
->value_tag
== IPP_TAG_URI
)
6517 * Validate the recipient scheme against the ServerBin/notifier
6521 char notifier
[1024]; /* Notifier filename */
6524 recipient
= attr
->values
[0].string
.text
;
6526 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6527 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6528 host
, sizeof(host
), &port
,
6529 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6531 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6532 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6533 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6534 "notify-status-code", IPP_URI_SCHEME
);
6538 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6540 if (access(notifier
, X_OK
))
6542 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6543 _("notify-recipient-uri URI \"%s\" uses unknown "
6544 "scheme."), recipient
);
6545 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6546 "notify-status-code", IPP_URI_SCHEME
);
6550 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6552 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6553 _("notify-recipient-uri URI \"%s\" is already used."),
6555 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6556 "notify-status-code", IPP_ATTRIBUTES
);
6560 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6561 attr
->value_tag
== IPP_TAG_KEYWORD
)
6563 pullmethod
= attr
->values
[0].string
.text
;
6565 if (strcmp(pullmethod
, "ippget"))
6567 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6568 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6569 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6570 "notify-status-code", IPP_ATTRIBUTES
);
6574 else if (!strcmp(attr
->name
, "notify-charset") &&
6575 attr
->value_tag
== IPP_TAG_CHARSET
&&
6576 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6577 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6579 send_ipp_status(con
, IPP_CHARSET
,
6580 _("Character set \"%s\" not supported."),
6581 attr
->values
[0].string
.text
);
6584 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6585 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6586 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6588 send_ipp_status(con
, IPP_CHARSET
,
6589 _("Language \"%s\" not supported."),
6590 attr
->values
[0].string
.text
);
6593 else if (!strcmp(attr
->name
, "notify-user-data") &&
6594 attr
->value_tag
== IPP_TAG_STRING
)
6596 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6598 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6599 _("The notify-user-data value is too large "
6600 "(%d > 63 octets)."),
6601 attr
->values
[0].unknown
.length
);
6607 else if (!strcmp(attr
->name
, "notify-events") &&
6608 attr
->value_tag
== IPP_TAG_KEYWORD
)
6609 notify_events
= attr
;
6610 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6611 attr
->value_tag
== IPP_TAG_INTEGER
)
6612 lease
= attr
->values
[0].integer
;
6613 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6614 attr
->value_tag
== IPP_TAG_INTEGER
)
6615 interval
= attr
->values
[0].integer
;
6616 else if (!strcmp(attr
->name
, "notify-job-id") &&
6617 attr
->value_tag
== IPP_TAG_INTEGER
)
6618 jobid
= attr
->values
[0].integer
;
6625 for (i
= 0; i
< notify_events
->num_values
; i
++)
6626 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6630 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6632 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6633 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6634 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6636 if (!recipient
&& !pullmethod
)
6639 if (mask
== CUPSD_EVENT_NONE
)
6642 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6644 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6647 send_ipp_status(con
, IPP_BAD_REQUEST
,
6648 _("notify-events not specified."));
6653 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6655 cupsdLogMessage(CUPSD_LOG_INFO
,
6656 "create_subscription: Limiting notify-lease-duration to "
6659 lease
= MaxLeaseDuration
;
6664 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6666 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6674 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6676 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6677 _("There are too many subscriptions."));
6682 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6685 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6686 "Added subscription #%d for printer \"%s\".",
6687 sub
->id
, printer
->name
);
6689 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6692 sub
->interval
= interval
;
6694 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6696 cupsdSetString(&sub
->owner
, username
);
6700 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6701 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6702 sub
->user_data_len
);
6705 ippAddSeparator(con
->response
);
6706 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6707 "notify-subscription-id", sub
->id
);
6709 con
->response
->request
.status
.status_code
= IPP_OK
;
6715 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6720 * 'delete_printer()' - Remove a printer or class from the system.
6724 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6725 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6727 http_status_t status
; /* Policy status */
6728 cups_ptype_t dtype
; /* Destination type (printer/class) */
6729 cupsd_printer_t
*printer
; /* Printer/class */
6730 char filename
[1024]; /* Script/PPD filename */
6733 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6734 con
->http
.fd
, uri
->values
[0].string
.text
);
6737 * Do we have a valid URI?
6740 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6746 send_ipp_status(con
, IPP_NOT_FOUND
,
6747 _("The printer or class does not exist."));
6755 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6757 send_http_error(con
, status
, NULL
);
6762 * Remove old jobs...
6765 cupsdCancelJobs(printer
->name
, NULL
, 1);
6768 * Remove old subscriptions and send a "deleted printer" event...
6771 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6772 "%s \"%s\" deleted by \"%s\".",
6773 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6774 printer
->name
, get_username(con
));
6776 cupsdExpireSubscriptions(printer
, NULL
);
6779 * Remove any old PPD or script files...
6782 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6786 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6790 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6793 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6798 * Unregister color profiles...
6801 apple_unregister_profiles(printer
);
6802 #endif /* __APPLE__ */
6804 if (dtype
& CUPS_PRINTER_CLASS
)
6806 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6807 printer
->name
, get_username(con
));
6809 cupsdDeletePrinter(printer
, 0);
6810 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6814 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6815 printer
->name
, get_username(con
));
6817 if (cupsdDeletePrinter(printer
, 0))
6818 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6820 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6823 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6826 * Return with no errors...
6829 con
->response
->request
.status
.status_code
= IPP_OK
;
6834 * 'get_default()' - Get the default destination.
6838 get_default(cupsd_client_t
*con
) /* I - Client connection */
6840 http_status_t status
; /* Policy status */
6841 cups_array_t
*ra
; /* Requested attributes array */
6844 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6850 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6852 send_http_error(con
, status
, NULL
);
6858 ra
= create_requested_array(con
->request
);
6860 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6862 cupsArrayDelete(ra
);
6864 con
->response
->request
.status
.status_code
= IPP_OK
;
6867 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6872 * 'get_devices()' - Get the list of available devices on the local system.
6876 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6878 http_status_t status
; /* Policy status */
6879 ipp_attribute_t
*limit
, /* limit attribute */
6880 *timeout
, /* timeout attribute */
6881 *requested
, /* requested-attributes attribute */
6882 *exclude
, /* exclude-schemes attribute */
6883 *include
; /* include-schemes attribute */
6884 char command
[1024], /* cups-deviced command */
6885 options
[2048], /* Options to pass to command */
6887 /* String for requested attributes */
6889 /* String for excluded schemes */
6891 /* String for included schemes */
6894 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6900 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6902 send_http_error(con
, status
, NULL
);
6907 * Run cups-deviced command with the given options...
6910 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6911 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6912 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6914 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6915 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6918 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6920 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6923 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6925 exclude_str
[0] = '\0';
6928 url_encode_attr(include
, include_str
, sizeof(include_str
));
6930 include_str
[0] = '\0';
6932 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6933 snprintf(options
, sizeof(options
),
6934 "%d+%d+%d+%d+%s%s%s%s%s",
6935 con
->request
->request
.op
.request_id
,
6936 limit
? limit
->values
[0].integer
: 0,
6937 timeout
? timeout
->values
[0].integer
: 15,
6940 exclude_str
[0] ? "%20" : "", exclude_str
,
6941 include_str
[0] ? "%20" : "", include_str
);
6943 if (cupsdSendCommand(con
, command
, options
, 1))
6946 * Command started successfully, don't send an IPP response here...
6949 ippDelete(con
->response
);
6950 con
->response
= NULL
;
6955 * Command failed, return "internal error" so the user knows something
6959 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6960 _("cups-deviced failed to execute."));
6966 * 'get_document()' - Get a copy of a job file.
6970 get_document(cupsd_client_t
*con
, /* I - Client connection */
6971 ipp_attribute_t
*uri
) /* I - Job URI */
6973 http_status_t status
; /* Policy status */
6974 ipp_attribute_t
*attr
; /* Current attribute */
6975 int jobid
; /* Job ID */
6976 int docnum
; /* Document number */
6977 cupsd_job_t
*job
; /* Current job */
6978 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6979 username
[HTTP_MAX_URI
], /* Username portion of URI */
6980 host
[HTTP_MAX_URI
], /* Host portion of URI */
6981 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6982 int port
; /* Port portion of URI */
6983 char filename
[1024], /* Filename for document */
6984 format
[1024]; /* Format for document */
6987 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6988 con
->http
.fd
, uri
->values
[0].string
.text
);
6991 * See if we have a job URI or a printer URI...
6994 if (!strcmp(uri
->name
, "printer-uri"))
6997 * Got a printer URI; see if we also have a job-id attribute...
7000 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7001 IPP_TAG_INTEGER
)) == NULL
)
7003 send_ipp_status(con
, IPP_BAD_REQUEST
,
7004 _("Got a printer-uri attribute but no job-id."));
7008 jobid
= attr
->values
[0].integer
;
7013 * Got a job URI; parse it to get the job ID...
7016 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7017 sizeof(scheme
), username
, sizeof(username
), host
,
7018 sizeof(host
), &port
, resource
, sizeof(resource
));
7020 if (strncmp(resource
, "/jobs/", 6))
7026 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7027 uri
->values
[0].string
.text
);
7031 jobid
= atoi(resource
+ 6);
7035 * See if the job exists...
7038 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7041 * Nope - return a "not found" error...
7044 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7052 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7053 job
->username
)) != HTTP_OK
)
7055 send_http_error(con
, status
, NULL
);
7060 * Get the document number...
7063 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7064 IPP_TAG_INTEGER
)) == NULL
)
7066 send_ipp_status(con
, IPP_BAD_REQUEST
,
7067 _("Missing document-number attribute."));
7071 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7072 attr
->num_values
> 1)
7074 send_ipp_status(con
, IPP_NOT_FOUND
,
7075 _("Document #%d does not exist in job #%d."), docnum
,
7080 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7082 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7084 cupsdLogMessage(CUPSD_LOG_ERROR
,
7085 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7087 send_ipp_status(con
, IPP_NOT_FOUND
,
7088 _("Unable to open document #%d in job #%d."), docnum
,
7093 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7097 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7098 job
->filetypes
[docnum
- 1]->type
);
7100 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7102 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7104 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7105 IPP_TAG_NAME
)) != NULL
)
7106 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7107 NULL
, attr
->values
[0].string
.text
);
7112 * 'get_job_attrs()' - Get job attributes.
7116 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7117 ipp_attribute_t
*uri
) /* I - Job URI */
7119 http_status_t status
; /* Policy status */
7120 ipp_attribute_t
*attr
; /* Current attribute */
7121 int jobid
; /* Job ID */
7122 cupsd_job_t
*job
; /* Current job */
7123 cupsd_printer_t
*printer
; /* Current printer */
7124 cupsd_policy_t
*policy
; /* Current security policy */
7125 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7126 username
[HTTP_MAX_URI
], /* Username portion of URI */
7127 host
[HTTP_MAX_URI
], /* Host portion of URI */
7128 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7129 int port
; /* Port portion of URI */
7130 cups_array_t
*ra
, /* Requested attributes array */
7131 *exclude
; /* Private attributes array */
7134 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7135 con
->http
.fd
, uri
->values
[0].string
.text
);
7138 * See if we have a job URI or a printer URI...
7141 if (!strcmp(uri
->name
, "printer-uri"))
7144 * Got a printer URI; see if we also have a job-id attribute...
7147 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7148 IPP_TAG_INTEGER
)) == NULL
)
7150 send_ipp_status(con
, IPP_BAD_REQUEST
,
7151 _("Got a printer-uri attribute but no job-id."));
7155 jobid
= attr
->values
[0].integer
;
7160 * Got a job URI; parse it to get the job ID...
7163 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7164 sizeof(scheme
), username
, sizeof(username
), host
,
7165 sizeof(host
), &port
, resource
, sizeof(resource
));
7167 if (strncmp(resource
, "/jobs/", 6))
7173 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7174 uri
->values
[0].string
.text
);
7178 jobid
= atoi(resource
+ 6);
7182 * See if the job exists...
7185 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7188 * Nope - return a "not found" error...
7191 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7199 if ((printer
= job
->printer
) == NULL
)
7200 printer
= cupsdFindDest(job
->dest
);
7203 policy
= printer
->op_policy_ptr
;
7205 policy
= DefaultPolicyPtr
;
7207 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7209 send_http_error(con
, status
, NULL
);
7213 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7216 * Copy attributes...
7221 ra
= create_requested_array(con
->request
);
7222 copy_job_attrs(con
, job
, ra
, exclude
);
7223 cupsArrayDelete(ra
);
7225 con
->response
->request
.status
.status_code
= IPP_OK
;
7230 * 'get_jobs()' - Get a list of jobs for the specified printer.
7234 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7235 ipp_attribute_t
*uri
) /* I - Printer URI */
7237 http_status_t status
; /* Policy status */
7238 ipp_attribute_t
*attr
; /* Current attribute */
7239 const char *dest
; /* Destination */
7240 cups_ptype_t dtype
; /* Destination type (printer/class) */
7241 cups_ptype_t dmask
; /* Destination type mask */
7242 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7243 username
[HTTP_MAX_URI
], /* Username portion of URI */
7244 host
[HTTP_MAX_URI
], /* Host portion of URI */
7245 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7246 int port
; /* Port portion of URI */
7247 int job_comparison
; /* Job comparison */
7248 ipp_jstate_t job_state
; /* job-state value */
7249 int first_job_id
; /* First job ID */
7250 int limit
; /* Maximum number of jobs to return */
7251 int count
; /* Number of jobs that match */
7252 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7253 cupsd_job_t
*job
; /* Current job pointer */
7254 cupsd_printer_t
*printer
; /* Printer */
7255 cups_array_t
*list
; /* Which job list... */
7256 cups_array_t
*ra
, /* Requested attributes array */
7257 *exclude
; /* Private attributes array */
7258 cupsd_policy_t
*policy
; /* Current policy */
7261 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7262 uri
->values
[0].string
.text
);
7265 * Is the destination valid?
7268 if (strcmp(uri
->name
, "printer-uri"))
7270 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7274 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7275 sizeof(scheme
), username
, sizeof(username
), host
,
7276 sizeof(host
), &port
, resource
, sizeof(resource
));
7278 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7281 dtype
= (cups_ptype_t
)0;
7282 dmask
= (cups_ptype_t
)0;
7285 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7288 dtype
= (cups_ptype_t
)0;
7289 dmask
= CUPS_PRINTER_CLASS
;
7292 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7295 dtype
= CUPS_PRINTER_CLASS
;
7296 dmask
= CUPS_PRINTER_CLASS
;
7299 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7306 send_ipp_status(con
, IPP_NOT_FOUND
,
7307 _("The printer or class does not exist."));
7312 dtype
&= CUPS_PRINTER_CLASS
;
7313 dmask
= CUPS_PRINTER_CLASS
;
7321 policy
= printer
->op_policy_ptr
;
7323 policy
= DefaultPolicyPtr
;
7325 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7327 send_http_error(con
, status
, NULL
);
7331 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7334 * See if the "which-jobs" attribute have been specified...
7337 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7338 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7340 send_ipp_status(con
, IPP_CONFLICT
,
7341 _("The %s attribute cannot be provided with job-ids."),
7345 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7347 job_comparison
= -1;
7348 job_state
= IPP_JOB_STOPPED
;
7351 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7354 job_state
= IPP_JOB_CANCELED
;
7357 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7360 job_state
= IPP_JOB_ABORTED
;
7363 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7366 job_state
= IPP_JOB_PENDING
;
7369 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7372 job_state
= IPP_JOB_CANCELED
;
7375 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7378 job_state
= IPP_JOB_PENDING
;
7381 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7384 job_state
= IPP_JOB_HELD
;
7387 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7390 job_state
= IPP_JOB_PROCESSING
;
7391 list
= PrintingJobs
;
7393 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7396 job_state
= IPP_JOB_STOPPED
;
7401 send_ipp_status(con
, IPP_ATTRIBUTES
,
7402 _("The which-jobs value \"%s\" is not supported."),
7403 attr
->values
[0].string
.text
);
7404 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7405 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7410 * See if they want to limit the number of jobs reported...
7413 if ((attr
= ippFindAttribute(con
->request
, "limit",
7414 IPP_TAG_INTEGER
)) != NULL
)
7418 send_ipp_status(con
, IPP_CONFLICT
,
7419 _("The %s attribute cannot be provided with job-ids."),
7424 limit
= attr
->values
[0].integer
;
7429 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7430 IPP_TAG_INTEGER
)) != NULL
)
7434 send_ipp_status(con
, IPP_CONFLICT
,
7435 _("The %s attribute cannot be provided with job-ids."),
7440 first_job_id
= attr
->values
[0].integer
;
7446 * See if we only want to see jobs for a specific user...
7449 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7450 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7452 send_ipp_status(con
, IPP_CONFLICT
,
7453 _("The %s attribute cannot be provided with job-ids."),
7457 else if (attr
&& attr
->values
[0].boolean
)
7458 strlcpy(username
, get_username(con
), sizeof(username
));
7462 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7463 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7466 * IPP conformance - Get-Jobs has a default requested-attributes value of
7467 * "job-id" and "job-uri".
7470 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7471 cupsArrayAdd(ra
, "job-id");
7472 cupsArrayAdd(ra
, "job-uri");
7476 * OK, build a list of jobs for this printer...
7481 int i
; /* Looping var */
7483 for (i
= 0; i
< job_ids
->num_values
; i
++)
7485 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7489 if (i
< job_ids
->num_values
)
7491 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7492 job_ids
->values
[i
].integer
);
7496 for (i
= 0; i
< job_ids
->num_values
; i
++)
7498 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7504 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7510 ippAddSeparator(con
->response
);
7512 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7513 job
->printer
->op_policy_ptr
:
7514 policy
, con
, job
->printer
,
7517 copy_job_attrs(con
, job
, ra
, exclude
);
7522 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7523 (limit
<= 0 || count
< limit
) && job
;
7524 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7527 * Filter out jobs that don't match...
7530 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7531 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7532 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7533 job
->username
, job
->state_value
, job
->attrs
);
7535 if (!job
->dest
|| !job
->username
)
7538 if (!job
->dest
|| !job
->username
)
7541 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7542 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7544 if ((job
->dtype
& dmask
) != dtype
&&
7545 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7548 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7549 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7550 (job_comparison
> 0 && job
->state_value
< job_state
))
7553 if (job
->id
< first_job_id
)
7560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7565 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
7569 ippAddSeparator(con
->response
);
7573 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7574 job
->printer
->op_policy_ptr
:
7575 policy
, con
, job
->printer
,
7578 copy_job_attrs(con
, job
, ra
, exclude
);
7581 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7584 cupsArrayDelete(ra
);
7586 con
->response
->request
.status
.status_code
= IPP_OK
;
7591 * 'get_notifications()' - Get events for a subscription.
7595 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7597 int i
, j
; /* Looping vars */
7598 http_status_t status
; /* Policy status */
7599 cupsd_subscription_t
*sub
; /* Subscription */
7600 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7601 *sequences
; /* notify-sequence-numbers */
7602 int min_seq
; /* Minimum sequence number */
7603 int interval
; /* Poll interval */
7606 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7610 * Get subscription attributes...
7613 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7615 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7620 send_ipp_status(con
, IPP_BAD_REQUEST
,
7621 _("Missing notify-subscription-ids attribute."));
7626 * Are the subscription IDs valid?
7629 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7631 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7634 * Bad subscription ID...
7637 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7638 ids
->values
[i
].integer
);
7646 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7648 con
, sub
->owner
)) != HTTP_OK
)
7650 send_http_error(con
, status
, sub
->dest
);
7655 * Check the subscription type and update the interval accordingly.
7658 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7661 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7663 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7669 * Tell the client to poll again in N seconds...
7673 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7674 "notify-get-interval", interval
);
7676 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7677 "printer-up-time", time(NULL
));
7680 * Copy the subscription event attributes to the response.
7683 con
->response
->request
.status
.status_code
=
7684 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7686 for (i
= 0; i
< ids
->num_values
; i
++)
7689 * Get the subscription and sequence number...
7692 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7694 if (sequences
&& i
< sequences
->num_values
)
7695 min_seq
= sequences
->values
[i
].integer
;
7700 * If we don't have any new events, nothing to do here...
7703 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7707 * Otherwise copy all of the new events...
7710 if (sub
->first_event_id
> min_seq
)
7713 j
= min_seq
- sub
->first_event_id
;
7715 for (; j
< cupsArrayCount(sub
->events
); j
++)
7717 ippAddSeparator(con
->response
);
7719 copy_attrs(con
->response
,
7720 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7721 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7728 * 'get_ppd()' - Get a named PPD from the local system.
7732 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7733 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7735 http_status_t status
; /* Policy status */
7736 cupsd_printer_t
*dest
; /* Destination */
7737 cups_ptype_t dtype
; /* Destination type */
7740 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7741 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7743 if (!strcmp(uri
->name
, "ppd-name"))
7746 * Return a PPD file from cups-driverd...
7749 char command
[1024], /* cups-driverd command */
7750 options
[1024], /* Options to pass to command */
7751 ppd_name
[1024]; /* ppd-name */
7758 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7760 send_http_error(con
, status
, NULL
);
7765 * Run cups-driverd command with the given options...
7768 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7769 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7770 snprintf(options
, sizeof(options
), "get+%d+%s",
7771 con
->request
->request
.op
.request_id
, ppd_name
);
7773 if (cupsdSendCommand(con
, command
, options
, 0))
7776 * Command started successfully, don't send an IPP response here...
7779 ippDelete(con
->response
);
7780 con
->response
= NULL
;
7785 * Command failed, return "internal error" so the user knows something
7789 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7790 _("cups-driverd failed to execute."));
7793 else if (!strcmp(uri
->name
, "printer-uri") &&
7794 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7796 int i
; /* Looping var */
7797 char filename
[1024]; /* PPD filename */
7804 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7806 send_http_error(con
, status
, dest
);
7811 * See if we need the PPD for a class or remote printer...
7814 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7817 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7819 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7820 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7821 "printer-uri", NULL
, dest
->uri
);
7824 else if (dtype
& CUPS_PRINTER_CLASS
)
7826 for (i
= 0; i
< dest
->num_printers
; i
++)
7827 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7829 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7830 dest
->printers
[i
]->name
);
7832 if (!access(filename
, 0))
7836 if (i
< dest
->num_printers
)
7837 dest
= dest
->printers
[i
];
7840 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7841 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7842 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7848 * Found the printer with the PPD file, now see if there is one...
7851 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7853 send_ipp_status(con
, IPP_NOT_FOUND
,
7854 _("The PPD file \"%s\" could not be opened: %s"),
7855 uri
->values
[0].string
.text
, strerror(errno
));
7859 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7863 con
->response
->request
.status
.status_code
= IPP_OK
;
7866 send_ipp_status(con
, IPP_NOT_FOUND
,
7867 _("The PPD file \"%s\" could not be found."),
7868 uri
->values
[0].string
.text
);
7873 * 'get_ppds()' - Get the list of PPD files on the local system.
7877 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7879 http_status_t status
; /* Policy status */
7880 ipp_attribute_t
*limit
, /* Limit attribute */
7881 *device
, /* ppd-device-id attribute */
7882 *language
, /* ppd-natural-language attribute */
7883 *make
, /* ppd-make attribute */
7884 *model
, /* ppd-make-and-model attribute */
7885 *model_number
, /* ppd-model-number attribute */
7886 *product
, /* ppd-product attribute */
7887 *psversion
, /* ppd-psverion attribute */
7888 *type
, /* ppd-type attribute */
7889 *requested
, /* requested-attributes attribute */
7890 *exclude
, /* exclude-schemes attribute */
7891 *include
; /* include-schemes attribute */
7892 char command
[1024], /* cups-driverd command */
7893 options
[4096], /* Options to pass to command */
7894 device_str
[256],/* Escaped ppd-device-id string */
7896 /* Escaped ppd-natural-language */
7897 make_str
[256], /* Escaped ppd-make string */
7898 model_str
[256], /* Escaped ppd-make-and-model string */
7899 model_number_str
[256],
7900 /* ppd-model-number string */
7902 /* Escaped ppd-product string */
7904 /* Escaped ppd-psversion string */
7905 type_str
[256], /* Escaped ppd-type string */
7907 /* String for requested attributes */
7909 /* String for excluded schemes */
7911 /* String for included schemes */
7914 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7920 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7922 send_http_error(con
, status
, NULL
);
7927 * Run cups-driverd command with the given options...
7930 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7931 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7932 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7934 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7935 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7937 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7939 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7940 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7941 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7942 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7944 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7946 include
= ippFindAttribute(con
->request
, "include-schemes",
7950 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7952 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7955 url_encode_attr(device
, device_str
, sizeof(device_str
));
7957 device_str
[0] = '\0';
7960 url_encode_attr(language
, language_str
, sizeof(language_str
));
7962 language_str
[0] = '\0';
7965 url_encode_attr(make
, make_str
, sizeof(make_str
));
7970 url_encode_attr(model
, model_str
, sizeof(model_str
));
7972 model_str
[0] = '\0';
7975 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7976 model_number
->values
[0].integer
);
7978 model_number_str
[0] = '\0';
7981 url_encode_attr(product
, product_str
, sizeof(product_str
));
7983 product_str
[0] = '\0';
7986 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7988 psversion_str
[0] = '\0';
7991 url_encode_attr(type
, type_str
, sizeof(type_str
));
7996 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7998 exclude_str
[0] = '\0';
8001 url_encode_attr(include
, include_str
, sizeof(include_str
));
8003 include_str
[0] = '\0';
8005 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8006 snprintf(options
, sizeof(options
),
8007 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8008 con
->request
->request
.op
.request_id
,
8009 limit
? limit
->values
[0].integer
: 0,
8011 device
? "%20" : "", device_str
,
8012 language
? "%20" : "", language_str
,
8013 make
? "%20" : "", make_str
,
8014 model
? "%20" : "", model_str
,
8015 model_number
? "%20" : "", model_number_str
,
8016 product
? "%20" : "", product_str
,
8017 psversion
? "%20" : "", psversion_str
,
8018 type
? "%20" : "", type_str
,
8019 exclude_str
[0] ? "%20" : "", exclude_str
,
8020 include_str
[0] ? "%20" : "", include_str
);
8022 if (cupsdSendCommand(con
, command
, options
, 0))
8025 * Command started successfully, don't send an IPP response here...
8028 ippDelete(con
->response
);
8029 con
->response
= NULL
;
8034 * Command failed, return "internal error" so the user knows something
8038 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8039 _("cups-driverd failed to execute."));
8045 * 'get_printer_attrs()' - Get printer attributes.
8049 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8050 ipp_attribute_t
*uri
) /* I - Printer URI */
8052 http_status_t status
; /* Policy status */
8053 cups_ptype_t dtype
; /* Destination type (printer/class) */
8054 cupsd_printer_t
*printer
; /* Printer/class */
8055 cups_array_t
*ra
; /* Requested attributes array */
8058 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8059 con
->http
.fd
, uri
->values
[0].string
.text
);
8062 * Is the destination valid?
8065 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8071 send_ipp_status(con
, IPP_NOT_FOUND
,
8072 _("The printer or class does not exist."));
8080 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8082 send_http_error(con
, status
, printer
);
8087 * Send the attributes...
8090 ra
= create_requested_array(con
->request
);
8092 copy_printer_attrs(con
, printer
, ra
);
8094 cupsArrayDelete(ra
);
8096 con
->response
->request
.status
.status_code
= IPP_OK
;
8101 * 'get_printer_supported()' - Get printer supported values.
8105 get_printer_supported(
8106 cupsd_client_t
*con
, /* I - Client connection */
8107 ipp_attribute_t
*uri
) /* I - Printer URI */
8109 http_status_t status
; /* Policy status */
8110 cups_ptype_t dtype
; /* Destination type (printer/class) */
8111 cupsd_printer_t
*printer
; /* Printer/class */
8114 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8115 con
->http
.fd
, uri
->values
[0].string
.text
);
8118 * Is the destination valid?
8121 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8127 send_ipp_status(con
, IPP_NOT_FOUND
,
8128 _("The printer or class does not exist."));
8136 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8138 send_http_error(con
, status
, printer
);
8143 * Return a list of attributes that can be set via Set-Printer-Attributes.
8146 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8148 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8149 "printer-location", 0);
8151 con
->response
->request
.status
.status_code
= IPP_OK
;
8156 * 'get_printers()' - Get a list of printers or classes.
8160 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8161 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8163 http_status_t status
; /* Policy status */
8164 ipp_attribute_t
*attr
; /* Current attribute */
8165 int limit
; /* Max number of printers to return */
8166 int count
; /* Number of printers that match */
8167 cupsd_printer_t
*printer
; /* Current printer pointer */
8168 int printer_type
, /* printer-type attribute */
8169 printer_mask
; /* printer-type-mask attribute */
8170 char *location
; /* Location string */
8171 const char *username
; /* Current user */
8172 char *first_printer_name
; /* first-printer-name attribute */
8173 cups_array_t
*ra
; /* Requested attributes array */
8174 int local
; /* Local connection? */
8177 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8178 con
->http
.fd
, type
);
8184 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8186 send_http_error(con
, status
, NULL
);
8191 * Check for printers...
8194 if (!Printers
|| !cupsArrayCount(Printers
))
8196 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8201 * See if they want to limit the number of printers reported...
8204 if ((attr
= ippFindAttribute(con
->request
, "limit",
8205 IPP_TAG_INTEGER
)) != NULL
)
8206 limit
= attr
->values
[0].integer
;
8210 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8211 IPP_TAG_NAME
)) != NULL
)
8212 first_printer_name
= attr
->values
[0].string
.text
;
8214 first_printer_name
= NULL
;
8217 * Support filtering...
8220 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8221 IPP_TAG_ENUM
)) != NULL
)
8222 printer_type
= attr
->values
[0].integer
;
8226 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8227 IPP_TAG_ENUM
)) != NULL
)
8228 printer_mask
= attr
->values
[0].integer
;
8232 local
= httpAddrLocalhost(&(con
->clientaddr
));
8234 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8235 IPP_TAG_TEXT
)) != NULL
)
8236 location
= attr
->values
[0].string
.text
;
8240 if (con
->username
[0])
8241 username
= con
->username
;
8242 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8243 IPP_TAG_NAME
)) != NULL
)
8244 username
= attr
->values
[0].string
.text
;
8248 ra
= create_requested_array(con
->request
);
8251 * OK, build a list of printers for this printer...
8254 if (first_printer_name
)
8256 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8257 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8260 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8263 count
< limit
&& printer
;
8264 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8266 if (!local
&& !printer
->shared
)
8269 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8270 (printer
->type
& printer_mask
) == printer_type
&&
8272 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
8275 * If a username is specified, see if it is allowed or denied
8279 if (cupsArrayCount(printer
->users
) && username
&&
8280 !user_allowed(printer
, username
))
8284 * Add the group separator as needed...
8288 ippAddSeparator(con
->response
);
8293 * Send the attributes...
8296 copy_printer_attrs(con
, printer
, ra
);
8300 cupsArrayDelete(ra
);
8302 con
->response
->request
.status
.status_code
= IPP_OK
;
8307 * 'get_subscription_attrs()' - Get subscription attributes.
8311 get_subscription_attrs(
8312 cupsd_client_t
*con
, /* I - Client connection */
8313 int sub_id
) /* I - Subscription ID */
8315 http_status_t status
; /* Policy status */
8316 cupsd_subscription_t
*sub
; /* Subscription */
8317 cupsd_policy_t
*policy
; /* Current security policy */
8318 cups_array_t
*ra
, /* Requested attributes array */
8319 *exclude
; /* Private attributes array */
8322 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8323 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8324 con
, con
->http
.fd
, sub_id
);
8327 * Is the subscription ID valid?
8330 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8333 * Bad subscription ID...
8336 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8346 policy
= sub
->dest
->op_policy_ptr
;
8348 policy
= DefaultPolicyPtr
;
8350 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8352 send_http_error(con
, status
, sub
->dest
);
8356 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8359 * Copy the subscription attributes to the response using the
8360 * requested-attributes attribute that may be provided by the client.
8363 ra
= create_requested_array(con
->request
);
8365 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8367 cupsArrayDelete(ra
);
8369 con
->response
->request
.status
.status_code
= IPP_OK
;
8374 * 'get_subscriptions()' - Get subscriptions.
8378 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8379 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8381 http_status_t status
; /* Policy status */
8382 int count
; /* Number of subscriptions */
8383 int limit
; /* Limit */
8384 cupsd_subscription_t
*sub
; /* Subscription */
8385 cups_array_t
*ra
; /* Requested attributes array */
8386 ipp_attribute_t
*attr
; /* Attribute */
8387 cups_ptype_t dtype
; /* Destination type (printer/class) */
8388 char scheme
[HTTP_MAX_URI
],
8389 /* Scheme portion of URI */
8390 username
[HTTP_MAX_URI
],
8391 /* Username portion of URI */
8393 /* Host portion of URI */
8394 resource
[HTTP_MAX_URI
];
8395 /* Resource portion of URI */
8396 int port
; /* Port portion of URI */
8397 cupsd_job_t
*job
; /* Job pointer */
8398 cupsd_printer_t
*printer
; /* Printer */
8399 cupsd_policy_t
*policy
; /* Policy */
8400 cups_array_t
*exclude
; /* Private attributes array */
8403 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8404 "get_subscriptions(con=%p[%d], uri=%s)",
8405 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8408 * Is the destination valid?
8411 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8412 sizeof(scheme
), username
, sizeof(username
), host
,
8413 sizeof(host
), &port
, resource
, sizeof(resource
));
8415 if (!strcmp(resource
, "/") ||
8416 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8417 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8418 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8423 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8426 job
= cupsdFindJob(atoi(resource
+ 6));
8430 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8431 atoi(resource
+ 6));
8435 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8441 send_ipp_status(con
, IPP_NOT_FOUND
,
8442 _("The printer or class does not exist."));
8445 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8446 IPP_TAG_INTEGER
)) != NULL
)
8448 job
= cupsdFindJob(attr
->values
[0].integer
);
8452 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8453 attr
->values
[0].integer
);
8465 policy
= printer
->op_policy_ptr
;
8467 policy
= DefaultPolicyPtr
;
8469 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8471 send_http_error(con
, status
, printer
);
8476 * Copy the subscription attributes to the response using the
8477 * requested-attributes attribute that may be provided by the client.
8480 ra
= create_requested_array(con
->request
);
8482 if ((attr
= ippFindAttribute(con
->request
, "limit",
8483 IPP_TAG_INTEGER
)) != NULL
)
8484 limit
= attr
->values
[0].integer
;
8489 * See if we only want to see subscriptions for a specific user...
8492 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8493 IPP_TAG_BOOLEAN
)) != NULL
&&
8494 attr
->values
[0].boolean
)
8495 strlcpy(username
, get_username(con
), sizeof(username
));
8499 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8501 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8502 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8503 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
8505 ippAddSeparator(con
->response
);
8507 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8508 policy
, con
, sub
->dest
,
8511 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8514 if (limit
&& count
>= limit
)
8518 cupsArrayDelete(ra
);
8521 con
->response
->request
.status
.status_code
= IPP_OK
;
8523 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8528 * 'get_username()' - Get the username associated with a request.
8531 static const char * /* O - Username */
8532 get_username(cupsd_client_t
*con
) /* I - Connection */
8534 ipp_attribute_t
*attr
; /* Attribute */
8537 if (con
->username
[0])
8538 return (con
->username
);
8539 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8540 IPP_TAG_NAME
)) != NULL
)
8541 return (attr
->values
[0].string
.text
);
8543 return ("anonymous");
8548 * 'hold_job()' - Hold a print job.
8552 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8553 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8555 ipp_attribute_t
*attr
; /* Current job-hold-until */
8556 const char *when
; /* New value */
8557 int jobid
; /* Job ID */
8558 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8559 username
[HTTP_MAX_URI
], /* Username portion of URI */
8560 host
[HTTP_MAX_URI
], /* Host portion of URI */
8561 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8562 int port
; /* Port portion of URI */
8563 cupsd_job_t
*job
; /* Job information */
8566 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8567 uri
->values
[0].string
.text
);
8570 * See if we have a job URI or a printer URI...
8573 if (!strcmp(uri
->name
, "printer-uri"))
8576 * Got a printer URI; see if we also have a job-id attribute...
8579 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8580 IPP_TAG_INTEGER
)) == NULL
)
8582 send_ipp_status(con
, IPP_BAD_REQUEST
,
8583 _("Got a printer-uri attribute but no job-id."));
8587 jobid
= attr
->values
[0].integer
;
8592 * Got a job URI; parse it to get the job ID...
8595 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8596 sizeof(scheme
), username
, sizeof(username
), host
,
8597 sizeof(host
), &port
, resource
, sizeof(resource
));
8599 if (strncmp(resource
, "/jobs/", 6))
8605 send_ipp_status(con
, IPP_BAD_REQUEST
,
8606 _("Bad job-uri \"%s\"."),
8607 uri
->values
[0].string
.text
);
8611 jobid
= atoi(resource
+ 6);
8615 * See if the job exists...
8618 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8621 * Nope - return a "not found" error...
8624 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8629 * See if the job is owned by the requesting user...
8632 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8634 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8635 cupsdFindDest(job
->dest
));
8640 * See if the job is in a state that allows holding...
8643 if (job
->state_value
> IPP_JOB_STOPPED
)
8646 * Return a "not-possible" error...
8649 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8650 _("Job #%d is finished and cannot be altered."),
8656 * Hold the job and return...
8659 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8660 IPP_TAG_KEYWORD
)) == NULL
)
8661 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8665 when
= attr
->values
[0].string
.text
;
8667 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8668 "Job job-hold-until value changed by user.");
8671 when
= "indefinite";
8673 cupsdSetJobHoldUntil(job
, when
, 1);
8674 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8677 con
->response
->request
.status
.status_code
= IPP_OK
;
8682 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8686 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8687 ipp_attribute_t
*uri
) /* I - Printer URI */
8689 http_status_t status
; /* Policy status */
8690 cups_ptype_t dtype
; /* Destination type (printer/class) */
8691 cupsd_printer_t
*printer
; /* Printer data */
8694 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8695 con
->http
.fd
, uri
->values
[0].string
.text
);
8698 * Is the destination valid?
8701 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8707 send_ipp_status(con
, IPP_NOT_FOUND
,
8708 _("The printer or class does not exist."));
8716 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8718 send_http_error(con
, status
, printer
);
8723 * Hold pending/new jobs sent to the printer...
8726 printer
->holding_new_jobs
= 1;
8728 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8730 if (dtype
& CUPS_PRINTER_CLASS
)
8731 cupsdLogMessage(CUPSD_LOG_INFO
,
8732 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8733 printer
->name
, get_username(con
));
8735 cupsdLogMessage(CUPSD_LOG_INFO
,
8736 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8737 printer
->name
, get_username(con
));
8740 * Everything was ok, so return OK status...
8743 con
->response
->request
.status
.status_code
= IPP_OK
;
8748 * 'move_job()' - Move a job to a new destination.
8752 move_job(cupsd_client_t
*con
, /* I - Client connection */
8753 ipp_attribute_t
*uri
) /* I - Job URI */
8755 http_status_t status
; /* Policy status */
8756 ipp_attribute_t
*attr
; /* Current attribute */
8757 int jobid
; /* Job ID */
8758 cupsd_job_t
*job
; /* Current job */
8759 const char *src
; /* Source printer/class */
8760 cups_ptype_t stype
, /* Source type (printer or class) */
8761 dtype
; /* Destination type (printer/class) */
8762 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8763 username
[HTTP_MAX_URI
], /* Username portion of URI */
8764 host
[HTTP_MAX_URI
], /* Host portion of URI */
8765 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8766 int port
; /* Port portion of URI */
8767 cupsd_printer_t
*sprinter
, /* Source printer */
8768 *dprinter
; /* Destination printer */
8771 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8772 uri
->values
[0].string
.text
);
8775 * Get the new printer or class...
8778 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8779 IPP_TAG_URI
)) == NULL
)
8782 * Need job-printer-uri...
8785 send_ipp_status(con
, IPP_BAD_REQUEST
,
8786 _("job-printer-uri attribute missing."));
8790 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8796 send_ipp_status(con
, IPP_NOT_FOUND
,
8797 _("The printer or class does not exist."));
8802 * See if we have a job URI or a printer URI...
8805 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8806 sizeof(scheme
), username
, sizeof(username
), host
,
8807 sizeof(host
), &port
, resource
, sizeof(resource
));
8809 if (!strcmp(uri
->name
, "printer-uri"))
8812 * Got a printer URI; see if we also have a job-id attribute...
8815 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8816 IPP_TAG_INTEGER
)) == NULL
)
8822 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8823 &sprinter
)) == NULL
)
8829 send_ipp_status(con
, IPP_NOT_FOUND
,
8830 _("The printer or class does not exist."));
8839 * Otherwise, just move a single job...
8842 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8845 * Nope - return a "not found" error...
8848 send_ipp_status(con
, IPP_NOT_FOUND
,
8849 _("Job #%d does not exist."), attr
->values
[0].integer
);
8855 * Job found, initialize source pointers...
8866 * Got a job URI; parse it to get the job ID...
8869 if (strncmp(resource
, "/jobs/", 6))
8875 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8876 uri
->values
[0].string
.text
);
8881 * See if the job exists...
8884 jobid
= atoi(resource
+ 6);
8886 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8889 * Nope - return a "not found" error...
8892 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8898 * Job found, initialize source pointers...
8907 * Check the policy of the destination printer...
8910 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8911 job
? job
->username
: NULL
)) != HTTP_OK
)
8913 send_http_error(con
, status
, dprinter
);
8918 * Now move the job or jobs...
8924 * See if the job has been completed...
8927 if (job
->state_value
> IPP_JOB_STOPPED
)
8930 * Return a "not-possible" error...
8933 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8934 _("Job #%d is finished and cannot be altered."),
8940 * See if the job is owned by the requesting user...
8943 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8945 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8946 cupsdFindDest(job
->dest
));
8951 * Move the job to a different printer or class...
8954 cupsdMoveJob(job
, dprinter
);
8959 * Got the source printer, now look through the jobs...
8962 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8964 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8967 * See if the job is pointing at the source printer or has not been
8971 if (_cups_strcasecmp(job
->dest
, src
) ||
8972 job
->state_value
> IPP_JOB_STOPPED
)
8976 * See if the job can be moved by the requesting user...
8979 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8983 * Move the job to a different printer or class...
8986 cupsdMoveJob(job
, dprinter
);
8991 * Start jobs if possible...
8997 * Return with "everything is OK" status...
9000 con
->response
->request
.status
.status_code
= IPP_OK
;
9005 * 'ppd_parse_line()' - Parse a PPD default line.
9008 static int /* O - 0 on success, -1 on failure */
9009 ppd_parse_line(const char *line
, /* I - Line */
9010 char *option
, /* O - Option name */
9011 int olen
, /* I - Size of option name */
9012 char *choice
, /* O - Choice name */
9013 int clen
) /* I - Size of choice name */
9016 * Verify this is a default option line...
9019 if (strncmp(line
, "*Default", 8))
9023 * Read the option name...
9026 for (line
+= 8, olen
--;
9027 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9038 * Skip everything else up to the colon (:)...
9041 while (*line
&& *line
!= ':')
9050 * Now grab the option choice, skipping leading whitespace...
9053 while (isspace(*line
& 255))
9057 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9068 * Return with no errors...
9076 * 'print_job()' - Print a file to a printer or class.
9080 print_job(cupsd_client_t
*con
, /* I - Client connection */
9081 ipp_attribute_t
*uri
) /* I - Printer URI */
9083 ipp_attribute_t
*attr
; /* Current attribute */
9084 ipp_attribute_t
*format
; /* Document-format attribute */
9085 const char *default_format
; /* document-format-default value */
9086 cupsd_job_t
*job
; /* New job */
9087 char filename
[1024]; /* Job filename */
9088 mime_type_t
*filetype
; /* Type of file */
9089 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9090 type
[MIME_MAX_TYPE
], /* Subtype of file */
9091 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9092 /* Textual name of mime type */
9093 cupsd_printer_t
*printer
; /* Printer data */
9094 struct stat fileinfo
; /* File information */
9095 int kbytes
; /* Size of file */
9096 int compression
; /* Document compression */
9099 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9100 uri
->values
[0].string
.text
);
9103 * Validate print file attributes, for now just document-format and
9104 * compression (CUPS only supports "none" and "gzip")...
9107 compression
= CUPS_FILE_NONE
;
9109 if ((attr
= ippFindAttribute(con
->request
, "compression",
9110 IPP_TAG_KEYWORD
)) != NULL
)
9112 if (strcmp(attr
->values
[0].string
.text
, "none")
9114 && strcmp(attr
->values
[0].string
.text
, "gzip")
9115 #endif /* HAVE_LIBZ */
9118 send_ipp_status(con
, IPP_ATTRIBUTES
,
9119 _("Unsupported compression \"%s\"."),
9120 attr
->values
[0].string
.text
);
9121 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9122 "compression", NULL
, attr
->values
[0].string
.text
);
9127 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9128 compression
= CUPS_FILE_GZIP
;
9129 #endif /* HAVE_LIBZ */
9133 * Do we have a file to print?
9138 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9143 * Is the destination valid?
9146 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9152 send_ipp_status(con
, IPP_NOT_FOUND
,
9153 _("The printer or class does not exist."));
9158 * Is it a format we support?
9161 if ((format
= ippFindAttribute(con
->request
, "document-format",
9162 IPP_TAG_MIMETYPE
)) != NULL
)
9165 * Grab format from client...
9168 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9171 send_ipp_status(con
, IPP_BAD_REQUEST
,
9172 _("Bad document-format \"%s\"."),
9173 format
->values
[0].string
.text
);
9177 else if ((default_format
= cupsGetOption("document-format",
9178 printer
->num_options
,
9179 printer
->options
)) != NULL
)
9182 * Use default document format...
9185 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9187 send_ipp_status(con
, IPP_BAD_REQUEST
,
9188 _("Bad document-format \"%s\"."),
9199 strcpy(super
, "application");
9200 strcpy(type
, "octet-stream");
9203 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9206 * Auto-type the file...
9209 ipp_attribute_t
*doc_name
; /* document-name attribute */
9212 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9214 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9215 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9216 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9220 filetype
= mimeType(MimeDatabase
, super
, type
);
9222 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9223 filetype
->super
, filetype
->type
);
9226 filetype
= mimeType(MimeDatabase
, super
, type
);
9230 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9233 * Replace the document-format attribute value with the auto-typed or
9237 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9242 _cupsStrFree(format
->values
[0].string
.text
);
9244 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9247 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9248 "document-format", NULL
, mimetype
);
9252 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9253 _("Unsupported document-format \"%s\"."),
9254 format
? format
->values
[0].string
.text
:
9255 "application/octet-stream");
9256 cupsdLogMessage(CUPSD_LOG_INFO
,
9257 "Hint: Do you have the raw file printing rules enabled?");
9260 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9261 "document-format", NULL
, format
->values
[0].string
.text
);
9267 * Read any embedded job ticket info from PS files...
9270 if (!_cups_strcasecmp(filetype
->super
, "application") &&
9271 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
9272 !_cups_strcasecmp(filetype
->type
, "pdf")))
9273 read_job_ticket(con
);
9276 * Create the job object...
9279 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9283 * Update quota data...
9286 if (stat(con
->filename
, &fileinfo
))
9289 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9291 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9293 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9294 IPP_TAG_INTEGER
)) != NULL
)
9295 attr
->values
[0].integer
+= kbytes
;
9298 * Add the job file...
9301 if (add_file(con
, job
, filetype
, compression
))
9304 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9306 rename(con
->filename
, filename
);
9307 cupsdClearString(&con
->filename
);
9310 * See if we need to add the ending sheet...
9313 if (cupsdTimeoutJob(job
))
9317 * Log and save the job...
9320 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9321 "File of type %s/%s queued by \"%s\".",
9322 filetype
->super
, filetype
->type
, job
->username
);
9323 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9324 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9325 job
->dest
, job
->username
);
9328 * Start the job if possible...
9336 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9338 * This function only gets called when printing a single PDF or PostScript
9339 * file using the Print-Job operation. It doesn't work for Create-Job +
9340 * Send-File, since the job attributes need to be set at job creation
9341 * time for banners to work. The embedded job ticket stuff is here
9342 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9343 * options and IPP attributes which otherwise would be lost.
9345 * The format of a job ticket is simple:
9347 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9349 * %cupsJobTicket: attr1=value1
9350 * %cupsJobTicket: attr2=value2
9352 * %cupsJobTicket: attrN=valueN
9354 * Job ticket lines must appear immediately after the first line that
9355 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9356 * stops looking for job ticket info when it finds a line that does not begin
9357 * with "%cupsJobTicket:".
9359 * The maximum length of a job ticket line, including the prefix, is
9360 * 255 characters to conform with the Adobe DSC.
9362 * Read-only attributes are rejected with a notice to the error log in
9363 * case a malicious user tries anything. Since the job ticket is read
9364 * prior to attribute validation in print_job(), job ticket attributes
9365 * will go through the same validation as IPP attributes...
9369 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9371 cups_file_t
*fp
; /* File to read from */
9372 char line
[256]; /* Line data */
9373 int num_options
; /* Number of options */
9374 cups_option_t
*options
; /* Options */
9375 ipp_t
*ticket
; /* New attributes */
9376 ipp_attribute_t
*attr
, /* Current attribute */
9377 *attr2
, /* Job attribute */
9378 *prev2
; /* Previous job attribute */
9382 * First open the print file...
9385 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9387 cupsdLogMessage(CUPSD_LOG_ERROR
,
9388 "Unable to open print file for job ticket - %s",
9394 * Skip the first line...
9397 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9399 cupsdLogMessage(CUPSD_LOG_ERROR
,
9400 "Unable to read from print file for job ticket - %s",
9406 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9409 * Not a DSC-compliant file, so no job ticket info will be available...
9417 * Read job ticket info from the file...
9423 while (cupsFileGets(fp
, line
, sizeof(line
)))
9426 * Stop at the first non-ticket line...
9429 if (strncmp(line
, "%cupsJobTicket:", 15))
9433 * Add the options to the option array...
9436 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9440 * Done with the file; see if we have any options...
9445 if (num_options
== 0)
9449 * OK, convert the options to an attribute list, and apply them to
9454 cupsEncodeOptions(ticket
, num_options
, options
);
9457 * See what the user wants to change.
9460 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9462 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9465 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9466 !strcmp(attr
->name
, "job-originating-user-name") ||
9467 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9468 !strcmp(attr
->name
, "job-k-octets") ||
9469 !strcmp(attr
->name
, "job-id") ||
9470 !strncmp(attr
->name
, "job-state", 9) ||
9471 !strncmp(attr
->name
, "time-at-", 8))
9472 continue; /* Read-only attrs */
9474 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9475 IPP_TAG_ZERO
)) != NULL
)
9478 * Some other value; first free the old value...
9481 if (con
->request
->attrs
== attr2
)
9483 con
->request
->attrs
= attr2
->next
;
9488 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9489 if (prev2
->next
== attr2
)
9491 prev2
->next
= attr2
->next
;
9496 if (con
->request
->last
== attr2
)
9497 con
->request
->last
= prev2
;
9499 ippDeleteAttribute(NULL
, attr2
);
9503 * Add new option by copying it...
9506 ippCopyAttribute(con
->request
, attr
, 0);
9510 * Then free the attribute list and option array...
9514 cupsFreeOptions(num_options
, options
);
9519 * 'reject_jobs()' - Reject print jobs to a printer.
9523 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9524 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9526 http_status_t status
; /* Policy status */
9527 cups_ptype_t dtype
; /* Destination type (printer/class) */
9528 cupsd_printer_t
*printer
; /* Printer data */
9529 ipp_attribute_t
*attr
; /* printer-state-message text */
9532 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9533 con
->http
.fd
, uri
->values
[0].string
.text
);
9536 * Is the destination valid?
9539 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9545 send_ipp_status(con
, IPP_NOT_FOUND
,
9546 _("The printer or class does not exist."));
9554 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9556 send_http_error(con
, status
, printer
);
9561 * Reject jobs sent to the printer...
9564 printer
->accepting
= 0;
9566 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9567 IPP_TAG_TEXT
)) == NULL
)
9568 strcpy(printer
->state_message
, "Rejecting Jobs");
9570 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9571 sizeof(printer
->state_message
));
9573 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9574 "No longer accepting jobs.");
9576 if (dtype
& CUPS_PRINTER_CLASS
)
9578 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9580 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9581 printer
->name
, get_username(con
));
9585 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9587 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9588 printer
->name
, get_username(con
));
9592 * Everything was ok, so return OK status...
9595 con
->response
->request
.status
.status_code
= IPP_OK
;
9600 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9604 release_held_new_jobs(
9605 cupsd_client_t
*con
, /* I - Connection */
9606 ipp_attribute_t
*uri
) /* I - Printer URI */
9608 http_status_t status
; /* Policy status */
9609 cups_ptype_t dtype
; /* Destination type (printer/class) */
9610 cupsd_printer_t
*printer
; /* Printer data */
9613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9614 con
->http
.fd
, uri
->values
[0].string
.text
);
9617 * Is the destination valid?
9620 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9626 send_ipp_status(con
, IPP_NOT_FOUND
,
9627 _("The printer or class does not exist."));
9635 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9637 send_http_error(con
, status
, printer
);
9642 * Hold pending/new jobs sent to the printer...
9645 printer
->holding_new_jobs
= 0;
9647 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9649 if (dtype
& CUPS_PRINTER_CLASS
)
9650 cupsdLogMessage(CUPSD_LOG_INFO
,
9651 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9652 printer
->name
, get_username(con
));
9654 cupsdLogMessage(CUPSD_LOG_INFO
,
9655 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9656 printer
->name
, get_username(con
));
9659 * Everything was ok, so return OK status...
9662 con
->response
->request
.status
.status_code
= IPP_OK
;
9667 * 'release_job()' - Release a held print job.
9671 release_job(cupsd_client_t
*con
, /* I - Client connection */
9672 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9674 ipp_attribute_t
*attr
; /* Current attribute */
9675 int jobid
; /* Job ID */
9676 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9677 username
[HTTP_MAX_URI
], /* Username portion of URI */
9678 host
[HTTP_MAX_URI
], /* Host portion of URI */
9679 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9680 int port
; /* Port portion of URI */
9681 cupsd_job_t
*job
; /* Job information */
9684 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9685 con
->http
.fd
, uri
->values
[0].string
.text
);
9688 * See if we have a job URI or a printer URI...
9691 if (!strcmp(uri
->name
, "printer-uri"))
9694 * Got a printer URI; see if we also have a job-id attribute...
9697 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9698 IPP_TAG_INTEGER
)) == NULL
)
9700 send_ipp_status(con
, IPP_BAD_REQUEST
,
9701 _("Got a printer-uri attribute but no job-id."));
9705 jobid
= attr
->values
[0].integer
;
9710 * Got a job URI; parse it to get the job ID...
9713 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9714 sizeof(scheme
), username
, sizeof(username
), host
,
9715 sizeof(host
), &port
, resource
, sizeof(resource
));
9717 if (strncmp(resource
, "/jobs/", 6))
9723 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9724 uri
->values
[0].string
.text
);
9728 jobid
= atoi(resource
+ 6);
9732 * See if the job exists...
9735 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9738 * Nope - return a "not found" error...
9741 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9746 * See if job is "held"...
9749 if (job
->state_value
!= IPP_JOB_HELD
)
9752 * Nope - return a "not possible" error...
9755 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9760 * See if the job is owned by the requesting user...
9763 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9765 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9766 cupsdFindDest(job
->dest
));
9771 * Reset the job-hold-until value to "no-hold"...
9774 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9775 IPP_TAG_KEYWORD
)) == NULL
)
9776 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9780 _cupsStrFree(attr
->values
[0].string
.text
);
9782 attr
->value_tag
= IPP_TAG_KEYWORD
;
9783 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9785 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9786 "Job job-hold-until value changed by user.");
9790 * Release the job and return...
9793 cupsdReleaseJob(job
);
9795 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9796 "Job released by user.");
9798 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9800 con
->response
->request
.status
.status_code
= IPP_OK
;
9807 * 'renew_subscription()' - Renew an existing subscription...
9812 cupsd_client_t
*con
, /* I - Client connection */
9813 int sub_id
) /* I - Subscription ID */
9815 http_status_t status
; /* Policy status */
9816 cupsd_subscription_t
*sub
; /* Subscription */
9817 ipp_attribute_t
*lease
; /* notify-lease-duration */
9820 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9821 "renew_subscription(con=%p[%d], sub_id=%d)",
9822 con
, con
->http
.fd
, sub_id
);
9825 * Is the subscription ID valid?
9828 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9831 * Bad subscription ID...
9834 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9842 * Job subscriptions cannot be renewed...
9845 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9846 _("Job subscriptions cannot be renewed."));
9854 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9856 con
, sub
->owner
)) != HTTP_OK
)
9858 send_http_error(con
, status
, sub
->dest
);
9863 * Renew the subscription...
9866 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9869 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9871 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9873 cupsdLogMessage(CUPSD_LOG_INFO
,
9874 "renew_subscription: Limiting notify-lease-duration to "
9877 sub
->lease
= MaxLeaseDuration
;
9880 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9882 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9884 con
->response
->request
.status
.status_code
= IPP_OK
;
9886 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9887 "notify-lease-duration", sub
->lease
);
9892 * 'restart_job()' - Restart an old print job.
9896 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9897 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9899 ipp_attribute_t
*attr
; /* Current attribute */
9900 int jobid
; /* Job ID */
9901 cupsd_job_t
*job
; /* Job information */
9902 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9903 username
[HTTP_MAX_URI
], /* Username portion of URI */
9904 host
[HTTP_MAX_URI
], /* Host portion of URI */
9905 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9906 int port
; /* Port portion of URI */
9909 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9910 con
->http
.fd
, uri
->values
[0].string
.text
);
9913 * See if we have a job URI or a printer URI...
9916 if (!strcmp(uri
->name
, "printer-uri"))
9919 * Got a printer URI; see if we also have a job-id attribute...
9922 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9923 IPP_TAG_INTEGER
)) == NULL
)
9925 send_ipp_status(con
, IPP_BAD_REQUEST
,
9926 _("Got a printer-uri attribute but no job-id."));
9930 jobid
= attr
->values
[0].integer
;
9935 * Got a job URI; parse it to get the job ID...
9938 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9939 sizeof(scheme
), username
, sizeof(username
), host
,
9940 sizeof(host
), &port
, resource
, sizeof(resource
));
9942 if (strncmp(resource
, "/jobs/", 6))
9948 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9949 uri
->values
[0].string
.text
);
9953 jobid
= atoi(resource
+ 6);
9957 * See if the job exists...
9960 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9963 * Nope - return a "not found" error...
9966 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9971 * See if job is in any of the "completed" states...
9974 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9977 * Nope - return a "not possible" error...
9980 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9986 * See if we have retained the job files...
9991 if (!job
->attrs
|| job
->num_files
== 0)
9994 * Nope - return a "not possible" error...
9997 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9998 _("Job #%d cannot be restarted - no files."), jobid
);
10003 * See if the job is owned by the requesting user...
10006 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10008 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10009 cupsdFindDest(job
->dest
));
10014 * See if the job-hold-until attribute is specified...
10017 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10018 IPP_TAG_KEYWORD
)) == NULL
)
10019 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10021 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10024 * Return the job to a held state...
10027 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10028 "Restarted by \"%s\" with job-hold-until=%s.",
10029 username
, attr
->values
[0].string
.text
);
10030 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10032 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10033 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10034 attr
->values
[0].string
.text
);
10039 * Restart the job...
10042 cupsdRestartJob(job
);
10046 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10048 con
->response
->request
.status
.status_code
= IPP_OK
;
10053 * 'save_auth_info()' - Save authentication information for a job.
10058 cupsd_client_t
*con
, /* I - Client connection */
10059 cupsd_job_t
*job
, /* I - Job */
10060 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10062 int i
; /* Looping var */
10063 char filename
[1024]; /* Job authentication filename */
10064 cups_file_t
*fp
; /* Job authentication file */
10065 char line
[65536]; /* Line for file */
10066 cupsd_printer_t
*dest
; /* Destination printer/class */
10070 * This function saves the in-memory authentication information for
10071 * a job so that it can be used to authenticate with a remote host.
10072 * The information is stored in a file that is readable only by the
10073 * root user. The fields are Base-64 encoded, each on a separate line,
10074 * followed by random number (up to 1024) of newlines to limit the
10075 * amount of information that is exposed.
10077 * Because of the potential for exposing of authentication information,
10078 * this functionality is only enabled when running cupsd as root.
10080 * This caching only works for the Basic and BasicDigest authentication
10081 * types. Digest authentication cannot be cached this way, and in
10082 * the future Kerberos authentication may make all of this obsolete.
10084 * Authentication information is saved whenever an authenticated
10085 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10088 * This information is deleted after a job is completed or canceled,
10089 * so reprints may require subsequent re-authentication.
10095 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10099 * Create the authentication file and change permissions...
10102 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10103 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10105 cupsdLogMessage(CUPSD_LOG_ERROR
,
10106 "Unable to save authentication info to \"%s\" - %s",
10107 filename
, strerror(errno
));
10111 fchown(cupsFileNumber(fp
), 0, 0);
10112 fchmod(cupsFileNumber(fp
), 0400);
10114 cupsFilePuts(fp
, "CUPSD-AUTH-V2\n");
10117 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10119 cupsdClearString(job
->auth_env
+ i
);
10121 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10124 * Write 1 to 3 auth values...
10128 i
< auth_info
->num_values
&&
10129 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10132 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10133 strlen(auth_info
->values
[i
].string
.text
));
10134 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
10136 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10137 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
10138 auth_info
->values
[i
].string
.text
);
10139 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10140 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
10141 auth_info
->values
[i
].string
.text
);
10142 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10143 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
10144 auth_info
->values
[i
].string
.text
);
10145 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
10146 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
10147 auth_info
->values
[i
].string
.text
);
10152 else if (auth_info
&& auth_info
->num_values
== 2 &&
10153 dest
->num_auth_info_required
== 1 &&
10154 !strcmp(dest
->auth_info_required
[0], "negotiate"))
10157 * Allow fallback to username+password for Kerberized queues...
10160 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
10161 strlen(auth_info
->values
[0].string
.text
));
10162 cupsFilePutConf(fp
, "username", line
);
10164 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
10165 auth_info
->values
[0].string
.text
);
10167 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
10168 strlen(auth_info
->values
[1].string
.text
));
10169 cupsFilePutConf(fp
, "password", line
);
10171 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
10172 auth_info
->values
[1].string
.text
);
10174 else if (con
->username
[0])
10177 * Write the authenticated username...
10180 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10181 cupsFilePutConf(fp
, "username", line
);
10183 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
10186 * Write the authenticated password...
10189 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10190 cupsFilePutConf(fp
, "password", line
);
10192 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
10196 if (con
->gss_uid
> 0)
10198 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
10199 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
10201 #endif /* HAVE_GSSAPI */
10204 * Write a random number of newlines to the end of the file...
10207 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10208 cupsFilePutChar(fp
, '\n');
10211 * Close the file and return...
10219 * 'send_document()' - Send a file to a printer or class.
10223 send_document(cupsd_client_t
*con
, /* I - Client connection */
10224 ipp_attribute_t
*uri
) /* I - Printer URI */
10226 ipp_attribute_t
*attr
; /* Current attribute */
10227 ipp_attribute_t
*format
; /* Request's document-format attribute */
10228 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10229 const char *default_format
;/* document-format-default value */
10230 int jobid
; /* Job ID number */
10231 cupsd_job_t
*job
; /* Current job */
10232 char job_uri
[HTTP_MAX_URI
],
10234 scheme
[HTTP_MAX_URI
],
10235 /* Method portion of URI */
10236 username
[HTTP_MAX_URI
],
10237 /* Username portion of URI */
10238 host
[HTTP_MAX_URI
],
10239 /* Host portion of URI */
10240 resource
[HTTP_MAX_URI
];
10241 /* Resource portion of URI */
10242 int port
; /* Port portion of URI */
10243 mime_type_t
*filetype
; /* Type of file */
10244 char super
[MIME_MAX_SUPER
],
10245 /* Supertype of file */
10246 type
[MIME_MAX_TYPE
],
10247 /* Subtype of file */
10248 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10249 /* Textual name of mime type */
10250 char filename
[1024]; /* Job filename */
10251 cupsd_printer_t
*printer
; /* Current printer */
10252 struct stat fileinfo
; /* File information */
10253 int kbytes
; /* Size of file */
10254 int compression
; /* Type of compression */
10255 int start_job
; /* Start the job? */
10258 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10259 con
->http
.fd
, uri
->values
[0].string
.text
);
10262 * See if we have a job URI or a printer URI...
10265 if (!strcmp(uri
->name
, "printer-uri"))
10268 * Got a printer URI; see if we also have a job-id attribute...
10271 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10272 IPP_TAG_INTEGER
)) == NULL
)
10274 send_ipp_status(con
, IPP_BAD_REQUEST
,
10275 _("Got a printer-uri attribute but no job-id."));
10279 jobid
= attr
->values
[0].integer
;
10284 * Got a job URI; parse it to get the job ID...
10287 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10288 sizeof(scheme
), username
, sizeof(username
), host
,
10289 sizeof(host
), &port
, resource
, sizeof(resource
));
10291 if (strncmp(resource
, "/jobs/", 6))
10297 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10298 uri
->values
[0].string
.text
);
10302 jobid
= atoi(resource
+ 6);
10306 * See if the job exists...
10309 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10312 * Nope - return a "not found" error...
10315 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10319 printer
= cupsdFindDest(job
->dest
);
10322 * See if the job is owned by the requesting user...
10325 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10327 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10328 cupsdFindDest(job
->dest
));
10333 * OK, see if the client is sending the document compressed - CUPS
10334 * only supports "none" and "gzip".
10337 compression
= CUPS_FILE_NONE
;
10339 if ((attr
= ippFindAttribute(con
->request
, "compression",
10340 IPP_TAG_KEYWORD
)) != NULL
)
10342 if (strcmp(attr
->values
[0].string
.text
, "none")
10344 && strcmp(attr
->values
[0].string
.text
, "gzip")
10345 #endif /* HAVE_LIBZ */
10348 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10349 attr
->values
[0].string
.text
);
10350 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10351 "compression", NULL
, attr
->values
[0].string
.text
);
10356 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10357 compression
= CUPS_FILE_GZIP
;
10358 #endif /* HAVE_LIBZ */
10362 * Do we have a file to print?
10365 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10366 IPP_TAG_BOOLEAN
)) == NULL
)
10368 send_ipp_status(con
, IPP_BAD_REQUEST
,
10369 _("Missing last-document attribute in request."));
10373 if (!con
->filename
)
10376 * Check for an empty request with "last-document" set to true, which is
10377 * used to close an "open" job by RFC 2911, section 3.3.2.
10380 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
10381 goto last_document
;
10383 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10388 * Is it a format we support?
10391 if ((format
= ippFindAttribute(con
->request
, "document-format",
10392 IPP_TAG_MIMETYPE
)) != NULL
)
10395 * Grab format from client...
10398 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10401 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10402 format
->values
[0].string
.text
);
10406 else if ((default_format
= cupsGetOption("document-format",
10407 printer
->num_options
,
10408 printer
->options
)) != NULL
)
10411 * Use default document format...
10414 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10416 send_ipp_status(con
, IPP_BAD_REQUEST
,
10417 _("Bad document-format-default \"%s\"."), default_format
);
10424 * No document format attribute? Auto-type it!
10427 strcpy(super
, "application");
10428 strcpy(type
, "octet-stream");
10431 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10434 * Auto-type the file...
10437 ipp_attribute_t
*doc_name
; /* document-name attribute */
10440 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10442 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10443 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10444 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10448 filetype
= mimeType(MimeDatabase
, super
, type
);
10451 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10452 filetype
->super
, filetype
->type
);
10455 filetype
= mimeType(MimeDatabase
, super
, type
);
10460 * Replace the document-format attribute value with the auto-typed or
10464 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10467 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10468 IPP_TAG_MIMETYPE
)) != NULL
)
10470 _cupsStrFree(jformat
->values
[0].string
.text
);
10472 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10475 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10476 "document-format", NULL
, mimetype
);
10478 else if (!filetype
)
10480 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10481 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10482 cupsdLogMessage(CUPSD_LOG_INFO
,
10483 "Hint: Do you have the raw file printing rules enabled?");
10486 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10487 "document-format", NULL
, format
->values
[0].string
.text
);
10492 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10494 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10497 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10498 _("Unsupported document-format \"%s\"."), mimetype
);
10500 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10501 "document-format", NULL
, mimetype
);
10507 * Add the file to the job...
10512 if (add_file(con
, job
, filetype
, compression
))
10515 if (stat(con
->filename
, &fileinfo
))
10518 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10520 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10522 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10523 IPP_TAG_INTEGER
)) != NULL
)
10524 attr
->values
[0].integer
+= kbytes
;
10526 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10528 rename(con
->filename
, filename
);
10530 cupsdClearString(&con
->filename
);
10532 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10533 filetype
->super
, filetype
->type
, job
->username
);
10536 * Start the job if this is the last document...
10541 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10542 IPP_TAG_BOOLEAN
)) != NULL
&&
10543 attr
->values
[0].boolean
)
10546 * See if we need to add the ending sheet...
10549 if (cupsdTimeoutJob(job
))
10552 if (job
->state_value
== IPP_JOB_STOPPED
)
10554 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10555 job
->state_value
= IPP_JOB_PENDING
;
10557 else if (job
->state_value
== IPP_JOB_HELD
)
10559 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10560 IPP_TAG_KEYWORD
)) == NULL
)
10561 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10563 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10565 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10566 job
->state_value
= IPP_JOB_PENDING
;
10571 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10577 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10578 IPP_TAG_KEYWORD
)) == NULL
)
10579 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10581 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10583 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10584 job
->state_value
= IPP_JOB_HELD
;
10585 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10588 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10595 * Fill in the response info...
10598 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
10599 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
10600 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10603 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10605 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10607 add_job_state_reasons(con
, job
);
10609 con
->response
->request
.status
.status_code
= IPP_OK
;
10612 * Start the job if necessary...
10621 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10626 cupsd_client_t
*con
, /* I - Client connection */
10627 http_status_t status
, /* I - HTTP status code */
10628 cupsd_printer_t
*printer
) /* I - Printer, if any */
10630 ipp_attribute_t
*uri
; /* Request URI, if any */
10633 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10634 IPP_TAG_URI
)) == NULL
)
10635 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10637 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10638 "Returning HTTP %s for %s (%s) from %s",
10639 httpStatus(status
),
10641 ippOpString(con
->request
->request
.op
.operation_id
) :
10643 uri
? uri
->values
[0].string
.text
: "no URI",
10644 con
->http
.hostname
);
10648 int auth_type
; /* Type of authentication required */
10651 auth_type
= CUPSD_AUTH_NONE
;
10653 if (status
== HTTP_UNAUTHORIZED
&&
10654 printer
->num_auth_info_required
> 0 &&
10655 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10657 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10658 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10659 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10662 * Creating and authenticating jobs requires Kerberos...
10665 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10670 * Use policy/location-defined authentication requirements...
10673 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10674 cupsd_location_t
*auth
; /* Pointer to authentication element */
10677 if (printer
->type
& CUPS_PRINTER_CLASS
)
10678 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10680 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10682 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10683 auth
->type
== CUPSD_AUTH_NONE
)
10684 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10686 con
->request
->request
.op
.operation_id
:
10691 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10692 auth_type
= cupsdDefaultAuthType();
10694 auth_type
= auth
->type
;
10698 cupsdSendError(con
, status
, auth_type
);
10701 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10703 ippDelete(con
->response
);
10704 con
->response
= NULL
;
10711 * 'send_ipp_status()' - Send a status back to the IPP client.
10715 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10716 ipp_status_t status
, /* I - IPP status code */
10717 const char *message
,/* I - Status message */
10718 ...) /* I - Additional args as needed */
10720 va_list ap
; /* Pointer to additional args */
10721 char formatted
[1024]; /* Formatted errror message */
10724 va_start(ap
, message
);
10725 vsnprintf(formatted
, sizeof(formatted
),
10726 _cupsLangString(con
->language
, message
), ap
);
10729 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10730 ippOpString(con
->request
->request
.op
.operation_id
),
10731 ippErrorString(status
), formatted
);
10733 con
->response
->request
.status
.status_code
= status
;
10735 if (ippFindAttribute(con
->response
, "attributes-charset",
10736 IPP_TAG_ZERO
) == NULL
)
10737 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10738 "attributes-charset", NULL
, "utf-8");
10740 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10741 IPP_TAG_ZERO
) == NULL
)
10742 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10743 "attributes-natural-language", NULL
, DefaultLanguage
);
10745 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10746 "status-message", NULL
, formatted
);
10751 * 'set_default()' - Set the default destination...
10755 set_default(cupsd_client_t
*con
, /* I - Client connection */
10756 ipp_attribute_t
*uri
) /* I - Printer URI */
10758 http_status_t status
; /* Policy status */
10759 cups_ptype_t dtype
; /* Destination type (printer/class) */
10760 cupsd_printer_t
*printer
, /* Printer */
10761 *oldprinter
; /* Old default printer */
10764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10765 con
->http
.fd
, uri
->values
[0].string
.text
);
10768 * Is the destination valid?
10771 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10777 send_ipp_status(con
, IPP_NOT_FOUND
,
10778 _("The printer or class does not exist."));
10786 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10788 send_http_error(con
, status
, NULL
);
10793 * Set it as the default...
10796 oldprinter
= DefaultPrinter
;
10797 DefaultPrinter
= printer
;
10800 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10801 "%s is no longer the default printer.", oldprinter
->name
);
10803 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10804 "%s is now the default printer.", printer
->name
);
10806 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10807 CUPSD_DIRTY_PRINTCAP
);
10809 cupsdLogMessage(CUPSD_LOG_INFO
,
10810 "Default destination set to \"%s\" by \"%s\".",
10811 printer
->name
, get_username(con
));
10814 * Everything was ok, so return OK status...
10817 con
->response
->request
.status
.status_code
= IPP_OK
;
10822 * 'set_job_attrs()' - Set job attributes.
10826 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10827 ipp_attribute_t
*uri
) /* I - Job URI */
10829 ipp_attribute_t
*attr
, /* Current attribute */
10830 *attr2
; /* Job attribute */
10831 int jobid
; /* Job ID */
10832 cupsd_job_t
*job
; /* Current job */
10833 char scheme
[HTTP_MAX_URI
],
10834 /* Method portion of URI */
10835 username
[HTTP_MAX_URI
],
10836 /* Username portion of URI */
10837 host
[HTTP_MAX_URI
],
10838 /* Host portion of URI */
10839 resource
[HTTP_MAX_URI
];
10840 /* Resource portion of URI */
10841 int port
; /* Port portion of URI */
10842 int event
; /* Events? */
10843 int check_jobs
; /* Check jobs? */
10846 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10847 con
->http
.fd
, uri
->values
[0].string
.text
);
10850 * Start with "everything is OK" status...
10853 con
->response
->request
.status
.status_code
= IPP_OK
;
10856 * See if we have a job URI or a printer URI...
10859 if (!strcmp(uri
->name
, "printer-uri"))
10862 * Got a printer URI; see if we also have a job-id attribute...
10865 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10866 IPP_TAG_INTEGER
)) == NULL
)
10868 send_ipp_status(con
, IPP_BAD_REQUEST
,
10869 _("Got a printer-uri attribute but no job-id."));
10873 jobid
= attr
->values
[0].integer
;
10878 * Got a job URI; parse it to get the job ID...
10881 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10882 sizeof(scheme
), username
, sizeof(username
), host
,
10883 sizeof(host
), &port
, resource
, sizeof(resource
));
10885 if (strncmp(resource
, "/jobs/", 6))
10891 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10892 uri
->values
[0].string
.text
);
10896 jobid
= atoi(resource
+ 6);
10900 * See if the job exists...
10903 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10906 * Nope - return a "not found" error...
10909 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10914 * See if the job has been completed...
10917 if (job
->state_value
> IPP_JOB_STOPPED
)
10920 * Return a "not-possible" error...
10923 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10924 _("Job #%d is finished and cannot be altered."), jobid
);
10929 * See if the job is owned by the requesting user...
10932 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10934 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10935 cupsdFindDest(job
->dest
));
10940 * See what the user wants to change.
10948 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10950 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10953 if (!strcmp(attr
->name
, "attributes-charset") ||
10954 !strcmp(attr
->name
, "attributes-natural-language") ||
10955 !strcmp(attr
->name
, "document-compression") ||
10956 !strcmp(attr
->name
, "document-format") ||
10957 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10958 !strcmp(attr
->name
, "job-document-access-errors") ||
10959 !strcmp(attr
->name
, "job-id") ||
10960 !strcmp(attr
->name
, "job-impressions-completed") ||
10961 !strcmp(attr
->name
, "job-k-octets") ||
10962 !strcmp(attr
->name
, "job-originating-host-name") ||
10963 !strcmp(attr
->name
, "job-originating-user-name") ||
10964 !strcmp(attr
->name
, "job-printer-up-time") ||
10965 !strcmp(attr
->name
, "job-printer-uri") ||
10966 !strcmp(attr
->name
, "job-sheets") ||
10967 !strcmp(attr
->name
, "job-state-message") ||
10968 !strcmp(attr
->name
, "job-state-reasons") ||
10969 !strcmp(attr
->name
, "job-uri") ||
10970 !strcmp(attr
->name
, "number-of-documents") ||
10971 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10972 !strcmp(attr
->name
, "output-device-assigned") ||
10973 !strncmp(attr
->name
, "date-time-at-", 13) ||
10974 !strncmp(attr
->name
, "job-k-octets", 12) ||
10975 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10976 !strncmp(attr
->name
, "time-at-", 8))
10982 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10983 _("%s cannot be changed."), attr
->name
);
10985 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10986 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10990 if (!strcmp(attr
->name
, "job-priority"))
10993 * Change the job priority...
10996 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10998 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
11000 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
11001 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
11003 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11005 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11006 _("Job is completed and cannot be changed."));
11009 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11011 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11012 attr
->values
[0].integer
);
11013 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11016 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11017 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11020 else if (!strcmp(attr
->name
, "job-state"))
11023 * Change the job state...
11026 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11028 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
11030 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
11031 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
11035 switch (attr
->values
[0].integer
)
11037 case IPP_JOB_PENDING
:
11038 case IPP_JOB_HELD
:
11039 if (job
->state_value
> IPP_JOB_HELD
)
11041 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11042 _("Job state cannot be changed."));
11045 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11047 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11048 attr
->values
[0].integer
);
11049 cupsdSetJobState(job
, attr
->values
[0].integer
,
11051 "Job state changed by \"%s\"", username
);
11056 case IPP_JOB_PROCESSING
:
11057 case IPP_JOB_STOPPED
:
11058 if (job
->state_value
!= attr
->values
[0].integer
)
11060 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11061 _("Job state cannot be changed."));
11066 case IPP_JOB_CANCELED
:
11067 case IPP_JOB_ABORTED
:
11068 case IPP_JOB_COMPLETED
:
11069 if (job
->state_value
> IPP_JOB_PROCESSING
)
11071 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11072 _("Job state cannot be changed."));
11075 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11077 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11078 attr
->values
[0].integer
);
11079 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11081 "Job state changed by \"%s\"", username
);
11088 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11090 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11091 IPP_TAG_ZERO
)) != NULL
)
11094 * Some other value; first free the old value...
11097 if (job
->attrs
->prev
)
11098 job
->attrs
->prev
->next
= attr2
->next
;
11100 job
->attrs
->attrs
= attr2
->next
;
11102 if (job
->attrs
->last
== attr2
)
11103 job
->attrs
->last
= job
->attrs
->prev
;
11105 ippDeleteAttribute(NULL
, attr2
);
11108 * Then copy the attribute...
11111 ippCopyAttribute(job
->attrs
, attr
, 0);
11114 * See if the job-name or job-hold-until is being changed.
11117 if (!strcmp(attr
->name
, "job-hold-until"))
11119 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11120 attr
->values
[0].string
.text
);
11121 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11123 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11125 cupsdReleaseJob(job
);
11129 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11130 "Job held by \"%s\".", username
);
11132 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11135 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11138 * Delete the attribute...
11141 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11142 IPP_TAG_ZERO
)) != NULL
)
11144 if (job
->attrs
->prev
)
11145 job
->attrs
->prev
->next
= attr2
->next
;
11147 job
->attrs
->attrs
= attr2
->next
;
11149 if (attr2
== job
->attrs
->last
)
11150 job
->attrs
->last
= job
->attrs
->prev
;
11152 ippDeleteAttribute(NULL
, attr2
);
11154 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11160 * Add new option by copying it...
11163 ippCopyAttribute(job
->attrs
, attr
, 0);
11165 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11174 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11177 * Send events as needed...
11180 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11181 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11182 cupsdFindDest(job
->dest
), job
,
11183 "Job priority changed by user.");
11185 if (event
& CUPSD_EVENT_JOB_STATE
)
11186 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11187 job
->state_value
== IPP_JOB_HELD
?
11188 "Job held by user." : "Job restarted by user.");
11190 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11191 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11192 "Job options changed by user.");
11195 * Start jobs if possible...
11204 * 'set_printer_attrs()' - Set printer attributes.
11208 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11209 ipp_attribute_t
*uri
) /* I - Printer */
11211 http_status_t status
; /* Policy status */
11212 cups_ptype_t dtype
; /* Destination type (printer/class) */
11213 cupsd_printer_t
*printer
; /* Printer/class */
11214 ipp_attribute_t
*attr
; /* Printer attribute */
11215 int changed
= 0; /* Was anything changed? */
11218 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11219 con
->http
.fd
, uri
->values
[0].string
.text
);
11222 * Is the destination valid?
11225 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11231 send_ipp_status(con
, IPP_NOT_FOUND
,
11232 _("The printer or class does not exist."));
11240 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11242 send_http_error(con
, status
, printer
);
11247 * Return a list of attributes that can be set via Set-Printer-Attributes.
11250 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11251 IPP_TAG_TEXT
)) != NULL
)
11253 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11257 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11258 IPP_TAG_TEXT
)) != NULL
)
11260 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11265 * Update the printer attributes and return...
11270 cupsdSetPrinterAttrs(printer
);
11271 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11273 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11274 "Printer \"%s\" description or location changed by \"%s\".",
11275 printer
->name
, get_username(con
));
11277 cupsdLogMessage(CUPSD_LOG_INFO
,
11278 "Printer \"%s\" description or location changed by \"%s\".",
11279 printer
->name
, get_username(con
));
11282 con
->response
->request
.status
.status_code
= IPP_OK
;
11287 * 'set_printer_defaults()' - Set printer default options from a request.
11291 set_printer_defaults(
11292 cupsd_client_t
*con
, /* I - Client connection */
11293 cupsd_printer_t
*printer
) /* I - Printer */
11295 int i
; /* Looping var */
11296 ipp_attribute_t
*attr
; /* Current attribute */
11297 int namelen
; /* Length of attribute name */
11298 char name
[256], /* New attribute name */
11299 value
[256]; /* String version of integer attrs */
11302 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11305 * Skip non-printer attributes...
11308 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11311 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11313 if (!strcmp(attr
->name
, "job-sheets-default"))
11316 * Only allow keywords and names...
11319 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11323 * Only allow job-sheets-default to be set when running without a
11324 * system high classification level...
11327 if (Classification
)
11330 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11332 if (attr
->num_values
> 1)
11333 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11335 cupsdSetString(&printer
->job_sheets
[1], "none");
11337 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11339 cupsdFreeStrings(&(printer
->users
));
11341 printer
->deny_users
= 0;
11343 if (attr
->value_tag
== IPP_TAG_NAME
&&
11344 (attr
->num_values
> 1 ||
11345 strcmp(attr
->values
[0].string
.text
, "all")))
11347 for (i
= 0; i
< attr
->num_values
; i
++)
11348 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11351 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11353 cupsdFreeStrings(&(printer
->users
));
11355 printer
->deny_users
= 1;
11357 if (attr
->value_tag
== IPP_TAG_NAME
&&
11358 (attr
->num_values
> 1 ||
11359 strcmp(attr
->values
[0].string
.text
, "none")))
11361 for (i
= 0; i
< attr
->num_values
; i
++)
11362 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11365 else if (!strcmp(attr
->name
, "job-quota-period"))
11367 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11370 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11371 attr
->values
[0].integer
);
11372 cupsdFreeQuotas(printer
);
11374 printer
->quota_period
= attr
->values
[0].integer
;
11376 else if (!strcmp(attr
->name
, "job-k-limit"))
11378 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11381 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11382 attr
->values
[0].integer
);
11383 cupsdFreeQuotas(printer
);
11385 printer
->k_limit
= attr
->values
[0].integer
;
11387 else if (!strcmp(attr
->name
, "job-page-limit"))
11389 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11392 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11393 attr
->values
[0].integer
);
11394 cupsdFreeQuotas(printer
);
11396 printer
->page_limit
= attr
->values
[0].integer
;
11398 else if (!strcmp(attr
->name
, "printer-op-policy"))
11400 cupsd_policy_t
*p
; /* Policy */
11403 if (attr
->value_tag
!= IPP_TAG_NAME
)
11406 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11408 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11409 "Setting printer-op-policy to \"%s\"...",
11410 attr
->values
[0].string
.text
);
11411 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11412 printer
->op_policy_ptr
= p
;
11416 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11417 _("Unknown printer-op-policy \"%s\"."),
11418 attr
->values
[0].string
.text
);
11422 else if (!strcmp(attr
->name
, "printer-error-policy"))
11424 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11427 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11428 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
11429 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11430 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11431 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11433 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11434 _("Unknown printer-error-policy \"%s\"."),
11435 attr
->values
[0].string
.text
);
11439 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11440 "Setting printer-error-policy to \"%s\"...",
11441 attr
->values
[0].string
.text
);
11442 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11446 * Skip any other non-default attributes...
11449 namelen
= strlen(attr
->name
);
11450 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11451 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11455 * OK, anything else must be a user-defined default...
11458 strlcpy(name
, attr
->name
, sizeof(name
));
11459 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11461 switch (attr
->value_tag
)
11463 case IPP_TAG_DELETEATTR
:
11464 printer
->num_options
= cupsRemoveOption(name
,
11465 printer
->num_options
,
11466 &(printer
->options
));
11467 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11468 "Deleting %s", attr
->name
);
11471 case IPP_TAG_NAME
:
11472 case IPP_TAG_KEYWORD
:
11474 printer
->num_options
= cupsAddOption(name
,
11475 attr
->values
[0].string
.text
,
11476 printer
->num_options
,
11477 &(printer
->options
));
11478 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11479 "Setting %s to \"%s\"...", attr
->name
,
11480 attr
->values
[0].string
.text
);
11483 case IPP_TAG_BOOLEAN
:
11484 printer
->num_options
= cupsAddOption(name
,
11485 attr
->values
[0].boolean
?
11487 printer
->num_options
,
11488 &(printer
->options
));
11489 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11490 "Setting %s to %s...", attr
->name
,
11491 attr
->values
[0].boolean
? "true" : "false");
11494 case IPP_TAG_INTEGER
:
11495 case IPP_TAG_ENUM
:
11496 sprintf(value
, "%d", attr
->values
[0].integer
);
11497 printer
->num_options
= cupsAddOption(name
, value
,
11498 printer
->num_options
,
11499 &(printer
->options
));
11500 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11501 "Setting %s to %s...", attr
->name
, value
);
11504 case IPP_TAG_RANGE
:
11505 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11506 attr
->values
[0].range
.upper
);
11507 printer
->num_options
= cupsAddOption(name
, value
,
11508 printer
->num_options
,
11509 &(printer
->options
));
11510 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11511 "Setting %s to %s...", attr
->name
, value
);
11514 case IPP_TAG_RESOLUTION
:
11515 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11516 attr
->values
[0].resolution
.yres
,
11517 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11519 printer
->num_options
= cupsAddOption(name
, value
,
11520 printer
->num_options
,
11521 &(printer
->options
));
11522 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11523 "Setting %s to %s...", attr
->name
, value
);
11527 /* Do nothing for other values */
11535 * 'start_printer()' - Start a printer.
11539 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11540 ipp_attribute_t
*uri
) /* I - Printer URI */
11542 int i
; /* Temporary variable */
11543 http_status_t status
; /* Policy status */
11544 cups_ptype_t dtype
; /* Destination type (printer/class) */
11545 cupsd_printer_t
*printer
; /* Printer data */
11548 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11549 con
->http
.fd
, uri
->values
[0].string
.text
);
11552 * Is the destination valid?
11555 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11561 send_ipp_status(con
, IPP_NOT_FOUND
,
11562 _("The printer or class does not exist."));
11570 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11572 send_http_error(con
, status
, printer
);
11577 * Start the printer...
11580 printer
->state_message
[0] = '\0';
11582 cupsdStartPrinter(printer
, 1);
11584 if (dtype
& CUPS_PRINTER_CLASS
)
11585 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11586 printer
->name
, get_username(con
));
11588 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11589 printer
->name
, get_username(con
));
11597 if ((i
= check_quotas(con
, printer
)) < 0)
11599 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11604 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11609 * Everything was ok, so return OK status...
11612 con
->response
->request
.status
.status_code
= IPP_OK
;
11617 * 'stop_printer()' - Stop a printer.
11621 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11622 ipp_attribute_t
*uri
) /* I - Printer URI */
11624 http_status_t status
; /* Policy status */
11625 cups_ptype_t dtype
; /* Destination type (printer/class) */
11626 cupsd_printer_t
*printer
; /* Printer data */
11627 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11630 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11631 con
->http
.fd
, uri
->values
[0].string
.text
);
11634 * Is the destination valid?
11637 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11643 send_ipp_status(con
, IPP_NOT_FOUND
,
11644 _("The printer or class does not exist."));
11652 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11654 send_http_error(con
, status
, printer
);
11659 * Stop the printer...
11662 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11663 IPP_TAG_TEXT
)) == NULL
)
11664 strcpy(printer
->state_message
, "Paused");
11667 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11668 sizeof(printer
->state_message
));
11671 cupsdStopPrinter(printer
, 1);
11673 if (dtype
& CUPS_PRINTER_CLASS
)
11674 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11675 printer
->name
, get_username(con
));
11677 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11678 printer
->name
, get_username(con
));
11681 * Everything was ok, so return OK status...
11684 con
->response
->request
.status
.status_code
= IPP_OK
;
11689 * 'url_encode_attr()' - URL-encode a string attribute.
11693 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11694 char *buffer
,/* I - String buffer */
11695 int bufsize
)/* I - Size of buffer */
11697 int i
; /* Looping var */
11698 char *bufptr
, /* Pointer into buffer */
11699 *bufend
; /* End of buffer */
11702 strlcpy(buffer
, attr
->name
, bufsize
);
11703 bufptr
= buffer
+ strlen(buffer
);
11704 bufend
= buffer
+ bufsize
- 1;
11706 for (i
= 0; i
< attr
->num_values
; i
++)
11708 if (bufptr
>= bufend
)
11716 if (bufptr
>= bufend
)
11721 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11722 bufptr
, bufend
- bufptr
+ 1);
11724 if (bufptr
>= bufend
)
11735 * 'url_encode_string()' - URL-encode a string.
11738 static char * /* O - End of string */
11739 url_encode_string(const char *s
, /* I - String */
11740 char *buffer
, /* I - String buffer */
11741 int bufsize
) /* I - Size of buffer */
11743 char *bufptr
, /* Pointer into buffer */
11744 *bufend
; /* End of buffer */
11745 static const char *hex
= "0123456789ABCDEF";
11750 bufend
= buffer
+ bufsize
- 1;
11752 while (*s
&& bufptr
< bufend
)
11754 if (*s
== ' ' || *s
== '%' || *s
== '+')
11756 if (bufptr
>= (bufend
- 2))
11760 *bufptr
++ = hex
[(*s
>> 4) & 15];
11761 *bufptr
++ = hex
[*s
& 15];
11765 else if (*s
== '\'' || *s
== '\\')
11767 if (bufptr
>= (bufend
- 1))
11784 * 'user_allowed()' - See if a user is allowed to print to a queue.
11787 static int /* O - 0 if not allowed, 1 if allowed */
11788 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11789 const char *username
) /* I - Username */
11791 struct passwd
*pw
; /* User password data */
11792 char baseuser
[256], /* Base username */
11793 *baseptr
, /* Pointer to "@" in base username */
11794 *name
; /* Current user name */
11797 if (cupsArrayCount(p
->users
) == 0)
11800 if (!strcmp(username
, "root"))
11803 if (strchr(username
, '@'))
11806 * Strip @REALM for username check...
11809 strlcpy(baseuser
, username
, sizeof(baseuser
));
11811 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11814 username
= baseuser
;
11817 pw
= getpwnam(username
);
11820 for (name
= (char *)cupsArrayFirst(p
->users
);
11822 name
= (char *)cupsArrayNext(p
->users
))
11824 if (name
[0] == '@')
11827 * Check group membership...
11830 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11833 else if (name
[0] == '#')
11839 if (cupsdCheckGroup(username
, pw
, name
))
11842 else if (!_cups_strcasecmp(username
, name
))
11846 return ((name
!= NULL
) != p
->deny_users
);
11851 * 'validate_job()' - Validate printer options and destination.
11855 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11856 ipp_attribute_t
*uri
) /* I - Printer URI */
11858 http_status_t status
; /* Policy status */
11859 ipp_attribute_t
*attr
, /* Current attribute */
11860 *auth_info
; /* auth-info attribute */
11861 ipp_attribute_t
*format
; /* Document-format attribute */
11862 cups_ptype_t dtype
; /* Destination type (printer/class) */
11863 char super
[MIME_MAX_SUPER
],
11864 /* Supertype of file */
11865 type
[MIME_MAX_TYPE
];
11866 /* Subtype of file */
11867 cupsd_printer_t
*printer
; /* Printer */
11870 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11871 con
->http
.fd
, uri
->values
[0].string
.text
);
11874 * OK, see if the client is sending the document compressed - CUPS
11875 * doesn't support compression yet...
11878 if ((attr
= ippFindAttribute(con
->request
, "compression",
11879 IPP_TAG_KEYWORD
)) != NULL
)
11881 if (strcmp(attr
->values
[0].string
.text
, "none")
11883 && strcmp(attr
->values
[0].string
.text
, "gzip")
11884 #endif /* HAVE_LIBZ */
11887 send_ipp_status(con
, IPP_ATTRIBUTES
,
11888 _("Unsupported compression \"%s\"."),
11889 attr
->values
[0].string
.text
);
11890 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11891 "compression", NULL
, attr
->values
[0].string
.text
);
11897 * Is it a format we support?
11900 if ((format
= ippFindAttribute(con
->request
, "document-format",
11901 IPP_TAG_MIMETYPE
)) != NULL
)
11903 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11906 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
11907 format
->values
[0].string
.text
);
11911 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11912 !mimeType(MimeDatabase
, super
, type
))
11914 cupsdLogMessage(CUPSD_LOG_INFO
,
11915 "Hint: Do you have the raw file printing rules enabled?");
11916 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11917 _("Unsupported document-format \"%s\"."),
11918 format
->values
[0].string
.text
);
11919 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11920 "document-format", NULL
, format
->values
[0].string
.text
);
11926 * Is the destination valid?
11929 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11935 send_ipp_status(con
, IPP_NOT_FOUND
,
11936 _("The printer or class does not exist."));
11944 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11946 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11948 send_http_error(con
, status
, printer
);
11951 else if (printer
->num_auth_info_required
== 1 &&
11952 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11955 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11959 else if (auth_info
&& !con
->http
.tls
&&
11960 !httpAddrLocalhost(con
->http
.hostaddr
))
11963 * Require encryption of auth-info over non-local connections...
11966 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11969 #endif /* HAVE_SSL */
11972 * Everything was ok, so return OK status...
11975 con
->response
->request
.status
.status_code
= IPP_OK
;
11980 * 'validate_name()' - Make sure the printer name only contains valid chars.
11983 static int /* O - 0 if name is no good, 1 if good */
11984 validate_name(const char *name
) /* I - Name to check */
11986 const char *ptr
; /* Pointer into name */
11990 * Scan the whole name...
11993 for (ptr
= name
; *ptr
; ptr
++)
11994 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11998 * All the characters are good; validate the length, too...
12001 return ((ptr
- name
) < 128);
12006 * 'validate_user()' - Validate the user for the request.
12009 static int /* O - 1 if permitted, 0 otherwise */
12010 validate_user(cupsd_job_t
*job
, /* I - Job */
12011 cupsd_client_t
*con
, /* I - Client connection */
12012 const char *owner
, /* I - Owner of job/resource */
12013 char *username
, /* O - Authenticated username */
12014 int userlen
) /* I - Length of username */
12016 cupsd_printer_t
*printer
; /* Printer for job */
12019 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12020 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12022 job
->id
, con
? con
->http
.fd
: 0,
12023 owner
? owner
: "(null)", username
, userlen
);
12026 * Validate input...
12029 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12033 * Get the best authenticated username that is available.
12036 strlcpy(username
, get_username(con
), userlen
);
12039 * Check the username against the owner...
12042 printer
= cupsdFindDest(job
->dest
);
12044 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12045 con
, owner
) == HTTP_OK
);
12050 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".